diff --git a/.gitignore b/.gitignore index 50ab47ece0..df04587784 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ Thumbs.db *.pdb *.aps *.vcproj.*.user +*.vcxproj.user *.vspscc *_i.c *.i @@ -32,6 +33,11 @@ _ReSharper*/ [Tt]est[Rr]esult* ipch/ *.opensdf +Generated Files +AppPackages + +# Ignore zip file created by download-deps.py if saved by user +*-deps-*.zip # Ignore files build by ndk and eclipse libs/ @@ -104,3 +110,5 @@ frameworks/js-bindings/bindings/proj.ios_mac/build/ # Ignore files copied in compilation samples/*/project/proj.android/src + +*.jsc diff --git a/AUTHORS b/AUTHORS index e4f2b9368f..9af4441312 100644 --- a/AUTHORS +++ b/AUTHORS @@ -31,6 +31,8 @@ Name GithubID Main contribution seobyeongky @seobyeongky XMLHTTPRequest bug fixes GLProgram_setUniformLocationWith4f bug fixed Corrent value of cc.REPEAT_FOREVER + Improved JavaScriptObjCBridge's import order + Added some useful callbacks to XMLHttpRequest Liang Wu @akira-cn No default font Arial on android bug fix @@ -59,17 +61,33 @@ Minh Quy @MQuy Fix url matching regex issue Park Hyun Chen @sincntx Fix cc.ScrollView constructor issue in JSB Added cc.rectOverlapsRect function in JSB + Fix issue that string value with line break character will cause cc.plistParser fail to parse Vincent Chou @go3k Update README.md, add submodule update command suggestion Fix bug: Runtime.cpp protobuf object parseFromString may result in an incomplete protobuf object Fix bug: PrebuiltRuntime ios version can't support portrait orientation. Igor Mats @IgorMats Added outline shader sample + Add SkeletonAnimation and GLProgram to the list of extendable classes G17hao @G17hao Fixed an typo issue in jsb_boot.js Simon de Lang @simondel Fixed use of deprecated cc, ccs and ccui create functions. +Craig P Jolicoeur @cpjolicoeur Fix typos in setup.py + +Dale Stammen @Stammen Add Windows Phone 8 support + Add Windows Universal app support + +Jeff Oh @redsim Fixed http response header parsing bug + +Thomas Jablonski @thomas-jablonski + Add cocos attr to the script element in templates + +James Chen @dumganhar Support to set custom scheduler & actionmanager for node + +小马哥 @andot Patch xhr.send for ArrayBuffer & ArrayBufferView. + Cocos2d-JS can not grow so fast without the active community. Thanks to all developers who report & trace bugs, discuss the engine usage in forum & QQ groups! Special thanks to Ricardo Quesada for giving us lots of guidances & suggestions. diff --git a/CHANGELOG b/CHANGELOG index ccbc22db7c..ec5098315b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,230 @@ ChangeLog: +Cocos2d-JS v3.5 @ April 1 2015 + +* Supported Windows Universal application publish which includes Windows, Windows RT, Windows Phone 8.1 platforms. +* Updated Cocos2d-x v3.5. +* Upgraded Cocos Studio parser to support Cocos Studio v2.2. +* Supported Cocos Studio 3D scene editing. +* Upgraded runtime tempalte to support Cocos Code IDE 1.2.0. +* Upgraded Spine support to v2.1, added spine test case with FFD. FFD is supported in native but not in web, both engine can parse the new version file correctly, but the web engine will ignore FFD informations. +* Replaced '==' with '===' for better performance. +* Added `path` parameter in `ccs.load` to support modifying cocostudio project resource path. +* Added animationList to Cocostudio ActionTimeline to support playing animation by name. +* Made ParticleSystem support creation from an map object. +* Added missing functions to `cc.Grid3D` and `cc.PageTurn3D`. +* Added tip message functions to `cc.TextFieldTTF` for mobile browser. +* Added a function `cc.sys.openURL`. +* Disabled retina display by default for better performance. +* Added Bower support. +* Updated `cc.sys.OS_XXX` informations for supported systems. +* [JSB] Moved 3D modules to `jsb` namespace. +* [JSB] Bound `ParticleSystem3D` and `PUParticleSystem3D` which support Particle Universe editor. +* [JSB] Improved bindings registration code. +* [JSB] Supported setting custom scheduler or action manager for node. +* [JSB] Added `enableStroke`, `setBoundingWidth`, `setBoundingHeight` to `cc.Label` to fit web engine API. +* [JSB] Supported ArrayBuffer and ArrayBufferView in `XMLHTTPRequest`'s `send` function. +* [JSB] Made remote image loading fully asynchonous. +* [JSB] Made `cc.Camera`'s `unproject` function support one argument. + +* Bug fixes: + 1. Fixed a bug of chipmunk.js that it doesn't work under closure compiler advanced mode. + 2. Fixed a bug of Cocos Studio parser that widget didn't set its layout component. + 3. Fixed grammatical mistakes in cocostudio parser logs. + 4. Fixed memory leak issue in `cc.LabelBMFont`. + 5. Fixed a bug of `cc.Scale9Sprite` that its `updateDisplayColor` doesn't take effect. + 6. Fixed a bug of Cocos Studio parser that `cc.Scale9Sprite` doesn't display correctly if its texture isn't preloaded. + 7. Fixed a bug of `cc.MenuItemSprite` that the construction will fail when parameter `selectedSprite` is a Scale9Sprite instance. + 8. Fixed a bug of Cocos Studio parser that the background color of `ccui.Layout` can't be parsed correctly. + 9. Fixed a bug of `cc.ClippingNode` that it doesn't work when set `inverted` to true in Canvas Mode. + 10. Fixed a bug of `ccs.Armature` that its name was modified to animation name when loading from json files. + 11. Fixed a bug of `ccui.PageView` that it cancel child touch during movment of page view. + 12. Fixed a bug of `cc.Scheduler` that its parameter `repeat` is invalid in schedule function. + 13. Fixed a bug of `cc.Scheduler` that `unschedule` function may fail. + 14. [JSB] Fixed a crash issue that `ccui.Checkbox` will crash due to conflict usage of `setUserObject`. + 15. [JSB] Fixed an issue that `cc.Node`'s `init` function is empty implemented and can't be overrided. + 16. [JSB] Fixed `cc.ClippingNode`'s `init` function issue that it didn't support arguments. + 17. [JSB] Fixed an issue that TTF Cocos Studio parser can not correctly set TTF font for widgets. + 18. [JSB] Fixed relocation overflow compilation issue by adding `LOCAL_ARM_MODE := arm`. + +Cocos2d-JS v3.4 Beta0 @ March 19 2015 + +* Added Windows Phone 8.0 platform support. +* Upgraded SpiderMonkey to v33, greatly improved JS object garbage collection and performance. +* Bound 3D modules including camera, light, sprite 3d, animation 3d, billboard, etc. +* Improved `cc.FontDefinition` & `ccui.RichText` in the web engine. +* Added gradient stops feature to `cc.LayerGradient` [Web exclusive]. +* Upgraded `cc.Scheduler` in the web engine with Cocos2d-x v3.4 implementation. +* Added a loading screen when scripts are loading. +* Improved performance by replacing `Object.defineProperties` with `cc.defineGetterSetter`. +* Supported loading sprite frames from json object. +* Refactored math library to improve web engine performance. +* Removed some variables from `cc` namespace to improve web engine performance. +* Added the Firefox OS Web manifest to support Firefox OS apps. +* Added `cocos` attr to the script element in templates. +* Moved loading.js to res folder for Cocos Console release mode. +* [JSB] Defined properties for TextureData. +* [JSB] Upgrade auto and manual bindings to SpiderMonkey v33. +* [JSB] Added 3D object conversions. +* [JSB] Added full featured 3D test cases including: camera, light, sprite 3d, animation 3d, billboard, effect. +* [JSB] Improved auto and manual bindings rooting code for creating objects. +* [JSB] Added 3d transform getter functions to `cc.Node`. +* [JSB] Added some useful callbacks to XMLHttpRequest. + +* Bug fixes: + 1. Added `getSpriteFrame` to `cc.Sprite` to fix API inconsistency. + 2. Added `getObejct` to `cc.TMXObjectGroup` to fix API inconsistency. + 3. Added `addImageAsync` to `cc.textureCache` to fix API inconsistency. + 4. Fixed a bug of `cc.text` that its default font name is incorrect. + 5. Fixed a bug of `ccui.PageView` that its `getPage` doesn't work. + 6. Fixed a bug of `ccui.ImageView` that its `loadTexture` doesn't work while it's invoked multiple times at the same frame. + 7. Fixed a bug of `ccui` that its load event callbacks have some mistakes. + 8. Fixed a bug of `cc.Layer` that its bake function doesn't work when the layer has a parent node. + 9. Fixed typos in `cc.ClippingNode.WebGLRenderCmd` and `cc.ParticleSystem.WebGLRenderCmd` creation. + 10. Fixed a bug of `cc.Sprite` in `setTextureRect`. + 11. Fixed a bug of `cc.Screen`. + 12. Fixed a bug of `cc.view` that it doesn't work on iOS 8.1.2. + 13. Fixed a bug of cc.DrawNode that its lineWidth is always to default value when set linewidth to zero. + 14. Fixed a bug in hack for particles performance on canvas. + 15. Fixed a bug of `cc.audioEngine` that it doesn't work after minified/compiled. + 16. Fixed a bug in `CCBoot.js` that WebGL is not activated in web view of iOS 8. + 17. Fixed a bug of `cc.CheckBox` that its position is incorrect when its texture isn't preloaded. + 18. Fixed a bug of `cc.TMXLayer` that it stops to work after `setTileGID` called. + 19. Fixed a bug of Cocos parser 2.x that it doesn't set widget's LayoutComponent. + 20. Fixed a bug of `cc.isObject` that it considered function as an object. + 21. [JSB] Fixed runScript error on win32 platform. + 22. [JSB] Fixed issues of generated binding codes for spine and ccs. + 23. [JSB] Fixed char16_t redefinition issue for wp8. + 24. [JSB] Fixed an issue that string value with line break characters will cause cc.plistParser fail to parse. + 25. [JSB] Refactored `cc.textureCache.addImageAsync` to support fully asynchronoused remote image loading. + 26. [JSB] Fixed an issue of `GLProgramState::setVertexAttribPointer` function binding. + 27. [JSB] Fixed a bug in `GLProgram`'s constructor. + 28. [JSB] Fixed http response header parsing issue. + 29. [JSB] Fixed jsc file check issue on windows. + 30. [JSB] Fixed `jsval_to_long_long` conversion issue. + 31. [JSB] Fixed `strtoll` undefined error in visual studio. + 32. [JSB] Fixed an issue that `cc.MenuItem`'s `setCallback` function invoked with wrong this object. + 33. [JSB] Fixed parameter issue for constructor of `cc.MenuItemImage`. + 34. [JSB] Fixed `ccs.Armature`'s `setBlendFunc` parameter inconsistency issue. + 35. [JSB] Fixed `JSStringWrapper` issue on windows platform. + 36. [JSB] Fixed a chinese character issue on WP8. + 37. [JSB] Fixed new object failed issue on windows. + 38. [JSB] Fixed an issue that `cc.Label.createWithTTF` is undefined. + 39. [JSB] Fixed audio loader absent issue. + 40. [JSB] Fixed a test case issue of native feature usage. + + +Cocos2d-JS v3.3 @ Feb.9, 2015 + +* Upgraded spine runtime to support the latest version and updated its test case. +* Added an option "noCache" for debugging on browsers. +* Set the default value of `cc.ParticleSystem`'s draw mode to texture mode. +* Added message to `ccs.load` when loading armature json file. +* Improved particle system test case. +* [JSB] Bound `cc.Image` and `cc.GLProgram`. +* [JSB] Supported extending `sp.SkeletonAnimation`. + +* Bug fixes: + 1. Fixed a bug of `cc.Sprite` that its `setSpriteFrame` doesn't work when sprite frame's `rotated` property is true. + 2. Fixed a bug of `cc.ClippingNode` when its stencil is `cc.Node` object in canvas mode. + 3. Fixed a ccui bug that the position of widgets is incorrect after loaded v2.x json file with `ccs.load`. + 4. Fixed a bug of `cc.PhysicsSprite` that `setIgnoreBodyRotation` function doesn't work. + 5. Fixed a bug of `ccui.Button` that setting pressed texture doesn't work when scale9 enabled. + 6. Fixed a bug of `ccui.ScrollView` that its `dir` property is null when passing `DIR_NONE` as `direction` in `_endRecordSlidAction` function. + 7. [JSB] Fixed spine animation listener binding issues. + 8. [JSB] Fixed `cc.MenuItemToggle`'s `setCallback` issue. + +Cocos2d-JS v3.3 RC0 @ Feb.1, 2015 + +* Added web exclusive functions: `_getFontStyle`, `_setFontStyle`, `_getFontWeight` and `_setFontWeight` APIs to `cc.LabelTTF`. +* Observed orientation change event on mobile for resolution policy adaptation. +* [JSB] Added bindings for `ccs.TextureData` and `ccs.ContourData`. + +* Bug fixes: + 1. Fixed Cocos Studio JSON parser's issues for parsing nested animation. + 2. Fixed Cocos Studio JSON parser's parameters parsing issues. + 3. Fixed Cocos Studio JSON parser's issue for parsing layer. + 4. Fixed Cocos Studio JSON action parser's issues. + 5. Fixed Cocos Studio JSON parser's issue for parsing Scale9Sprite. + 6. Fixed Cocos Studio JSON parser's issues caused by parsing process order. + 7. Fixed Cocos Studio JSON parser's issue for parsing loading bar's direction. + 8. Fixed UI layout system issues. + 9. Fixed `cc.EditBox`'s position issue under certain resolution policies. + 10. Fixed `ccui.ListView`'s issue for setting direction. + 11. Fixed an issue of `cc.Tween` that its `_currentPercent` is incorrect in `updateHandler` function. + 12. Fixed an issue of `ccui.Button` that its state is incorrect in `_onPressStateChangedToNormal`. + 13. Fixed an issue of `cc.ArmatureAnimation`'s `setMovementEventCallFunc`. + 14. Fixed an issue of `cc.Sequence` action when it's repeated. + 15. Fixed `_anchorPointInPoints` usage issue. + 16. Fixed an issue of `cc.GLProgram` that it doesn't work on some devices which didn't support highp float precision. + 17. Fixed an issue of fade actions that they don't work when duration is 0. + 18. Fixed `onended` callback issue of audio engine on iOS. + 19. Fixed Cocos Builder's parser issue for auto playing animations. + 20. Added a message to `ccs.Armature` that it doesn't support adding widget as its child. + 21. Improved test cases for stability. + 22. [JSB]Fixed `setBackGroundColorVector` parameter issue. + 23. [JSB]Fixed `animationInfo` manual conversion issue. + 24. [JSB]Added `ccs.AnimationInfo` struct. + 25. [JSB]Improved JavaScriptObjCBridge's import order. + 26. [JSB]Fixed `cc.SpriteBatchNode.DEFAULT_CAPACITY` inconsistency issue. + 27. [JSB]Fixed `cc.MenuItemImage`'s children class's callback issue. + 28. [JSB]Enhanced `executeJSFunctionFromReservedSpot` function. + 29. [JSB]Fixed `cc.LabelTTF`'s `setDimensions` API inconsistency issue. + +Cocos2d-JS v3.3 Beta @ Jan.24, 2015 + +* Added Cocos Studio v2.x parser and refactored 1.x parser. +* Upgraded new flow layout UI system in web engine. +* Refactored `load` events of texture2d, sprite and so on to be more intuitive. +* Added JavaScript file loader. +* Allowed set texture to null in `cc.Sprite`. +* Added full test cases for Cocos Studio v2.x parser and the new flow layout UI system. +* Upgraded MoonWarriors sample's UI and graphic design. +* [JSB] Upgraded Cocos2d-x to v3.4 RC1. +* [JSB] Unified keycode between web engine and native engine to web standard values. +* [JSB] Added animation info's manual conversion for bindings. +* [JSB] Made local IP address url pass the url check of `cc.loader.loadImg` function. +* [JSB] Bound `ccs.AlphaFrame` for Cocos Studio animations. +* [JSB] Moved manual conversions of chipmunk to its own manual bindings file for better module support. + +* Bug fixes: + 1. Fixed a bug of Cocos2d UI, their focus event has been supported. + 2. Fixed a buf of `ccui.Widget` that its percent position doesn't work. + 3. Fixed a bug of `ccs.Armature` that its position doesn't update in visit on WebGL render mode. + 4. Fixed a bug of `cc.Sprite` that its `setTextureRect` function doesn't work when `setColor` invoked. + 5. Fixed a bug of `cc.PhysicsSprite` that its position is incorrect. + 6. Fixed a bug of `ccs.Bone` that its `setOpacity` and `setColor` doesn't work. + 7. Fixed a bug of `cc.LabelBMFont` that its word wrap doesn't work. + 8. Fixed a bug of `cc.sys` that it gets the incorrect OS type when system is Linux. + 9. Fixed a bug of `cc.audioEngine` that its loading path is incorrect. + 10. Fixed a bug of `ccui.Widget` that it can't touch when it's reused. + 11. Fixed a bug of UI system that the `setNormalizedPosition` doesn't work. + 12. Fixed a bug of `cc.ActionInterval` that its `_times` conflict with `cc.Blink`. + 13. Fixed release texture issue in canvas mode. + 14. Fixed a bug of `ccs.actionManager` that its `getActionByName` doesn't work. + 15. Fixed a bug of `cc.Sprite` that it can't draw without texture on WebGL mode. + 16. Fixed a bug of `cc.audioEngine` that it doesn't work on baidu browser. + 17. Fixed a bug of `cc.EditBox` that its position is incorrect on Canvas Mode and its string value is wrong when PlaceHolder is showing. + 18. Fixed a bug of `cc.loader` that its `loadImg` function doesn't work when image is accessed cross origin. + 19. Fixed a bug of `ccui.TextField` that its `contentSize` is incorrect in text field event. + 20. [JSB] Fixed restart game feature issue that action manager is not rescheduled after restarting game. + 21. [JSB] Fixed `jsb.AssetsManager`'s issue that manifest files progression is inversed. + 22. [JSB] Fixed `jsb.AssetsManager`'s issue that asset id isn't dispatched with progression event. + 23. [JSB] Fixed `Vec3` conversion issue. + 24. [JSB] Added missed `cc.AnimationFrame`'s `_ctor` function. + 25. [JSB] Added `cc.MenuItemToggle`'s `selectedItem` function to fix API inconsistence. + 26. [JSB] Fixed `LayoutParameter`'s `setMargin` function's API inconsistence with web engine. + 27. [JSB] Fixed `ccui.Button`'s constructor issue. + 28. [JSB] Fixed `ccui.Button`'s `setNormalizedPosition` function's API inconsistence with web engine. + 29. [JSB] Fixed `ccui.CheckBox`'s intialization issue. + 30. [JSB] Fixed `ccui.ImageView`'s constructor issue. + 31. [JSB] Fixed JSON parse issue in `XMLHTTPRequest`. + 32. [JSB] Fixed a wired compilation issue which reports `JSVAL_TO_IMPL` is not a function on win32. + 33. [JSB] Fixed image view test's implementation bug. + 34. [JSB] Fixed an UI button test's implementation bug. + 35. [JSB] Fixed list view test case's bug. + 36. [JSB] Fixed issues of `ccui.TextField`'s test cases. + Cocos2d-JS v3.2 @ Dec.29, 2014 * Replaced `transform` function with `setTransform` function under canvas render mode for better performance. diff --git a/CMakeLists.txt b/CMakeLists.txt index baf38af98c..99ac98e54f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -233,28 +233,16 @@ cocos_find_package(TIFF TIFF REQUIRED) cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED) cocos_find_package(CURL CURL REQUIRED) -# protobuf-lite (not prebuilded, exists as source) -# TODO: for now we can't use upstream protobuf because these files: -# cocos/editor-support/cocostudio/CSParseBinary.pb.h -# cocos/editor-support/cocostudio/CSParseBinary.pb.cc -# was generated by concrete version of protobuf compiler -# and source file not provided. So these files can be -# compiled only with our in-source version of protobuf-lite -## if(USE_PREBUILT_LIBS) - add_subdirectory(frameworks/js-bindings/cocos2d-x/external/protobuf-lite) - set(PROTOBUF_LITE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/js-bindings/cocos2d-x/external/protobuf-lite/src) - set(PROTOBUF_LITE_LIBRARIES protobuf) -## else() -## cocos_find_package(Protobuf REQUIRED PROTOBUF_LITE_LIBRARIES) -## set(PROTOBUF_LITE_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS}) -## endif() -message(STATUS "Protobuf lite libs: ${PROTOBUF_LITE_LIBRARIES}") -message(STATUS "Protobuf include dirs: ${PROTOBUF_LITE_INCLUDE_DIRS}") - -# build for 3rd party libraries -if(LINUX OR APPLE) + +add_subdirectory(frameworks/js-bindings/cocos2d-x/external/flatbuffers) +set(FLATBUFFERS_INCLUDE_DIRS frameworks/js-bindings/cocos2d-x/external) +message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}") + + +# build xxhash add_subdirectory(frameworks/js-bindings/cocos2d-x/external/xxhash) -endif() +include_directories(frameworks/js-bindings/cocos2d-x/external/xxhash) + # cocos2d library add_subdirectory(frameworks/js-bindings/cocos2d-x/cocos) diff --git a/README.md b/README.md index e486c5321d..54f2ff6b46 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - + Cocos2d-JS =========== @@ -33,7 +33,6 @@ Furthermore, JavaScript friendly APIs make your game development experience a br - [Getting Started with Cocos2d-JS](http://www.cocos2d-x.org/docs/manual/framework/html5/en) - [Cocos2d-JS release notes](http://www.cocos2d-x.org/docs/manual/framework/html5/release-notes/en) -- [Cocos2d-JS v3.0 upgrade guide](http://www.cocos2d-x.org/docs/manual/framework/html5/release-notes/v3.0rc0/upgrade-guide/en) ## About Cocos2d family @@ -73,8 +72,8 @@ Example: * Compile and run project in Cocos2d-JSB : ``` - cocos compile -p ios|mac|android|web - cocos run -p ios|mac|android|web + cocos compile -p ios|mac|android|win32|web + cocos run -p ios|mac|android|win32|web ``` You may need to provide your Android NDK, Android SDK and ANT's paths during the setup. Note that this tool is developed with python, so you will need python (32bit) 2.7.5 or later installed on your machine (but it doesn't support Python3). Please refer to [Cocos Console document](http://www.cocos2d-x.org/docs/manual/framework/html5/v2/cocos-console/en). @@ -103,16 +102,18 @@ There are two prebuilt projects in Cocos2d-JS repo: - Test cases, located in `samples/js-tests` - ``` - cd samples/js-tests - run -p ios|mac|android|web - ``` +``` +cd samples/js-tests +run -p ios|mac|android|win32|web +``` + - Game sample : Moon Warriors, located in `samples/js-moonwarriors` ``` cd samples/js-moonwarriors -run -p ios|mac|android|web +run -p ios|mac|android|win32|web ``` + And they share the same project files which are located in `build` folder, there are Xcode and Visual Studio projects. ##Main features @@ -153,7 +154,7 @@ And they share the same project files which are located in `build` folder, there For JSB build, there are some restrictions : -- [Android build] NDK version must be r9d +- [Android build] NDK version must be r10c - [iOS build] Xcode version must be 5.1.1 + ##Github note @@ -165,12 +166,3 @@ If you fork our github repository or download the package from github, you will - Run `tools/cocos2d-console/download-bin.py` to download bin files for some cocos2d-console plugins like Google Closure Compiler and JSC Compiler. Otherwise, you will fail to compile your JSB projects. - -## Roadmap - -Cocos2d-JS have greatly simplified cross platform development. For the next step, we will focus on improving performance on mobile web, toolchain enhancement and completing documentation. Here is a list of main tasks we consider to accomplish in v3.1 : - -- The research for performance improvement on Web engine have already made great progress, the new renderer for canvas render mode is ready and will be merged in v3.1. The performance is upto 50% better than v3.0 based on various tests. -- Facebook SDK for Cocos2d-JS will be released with v3.1, developers can use all Facebook features on iOS/Android/Web with the same JavaScript code. -- Continue the research of memory model in JSB, improve the stability and simplify the usage. -- Complete the Cocos2d-JS Programming Guide document to cover all important aspects about Cocos2d-JS development. diff --git a/build/cocos2d-jsb-samples-win8.1-universal.sln b/build/cocos2d-jsb-samples-win8.1-universal.sln new file mode 100644 index 0000000000..587f85ed1c --- /dev/null +++ b/build/cocos2d-jsb-samples-win8.1-universal.sln @@ -0,0 +1,264 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libcocos2d", "libcocos2d", "{B3F299D4-B4CA-4F0B-8BE2-FB328483BC13}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "External", "External", "{85630454-74EA-4B5B-9B62-0E459B4476CB}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libbox2d", "libbox2d", "{B3D1A3D5-9F54-43AF-9322-230B53242B78}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libSpine", "libSpine", "{6FEB795C-C98C-4C8C-A88B-A35DEE205348}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d_8_1.Shared", "..\frameworks\js-bindings\cocos2d-x\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Shared\libcocos2d_8_1.Shared.vcxitems", "{5D6F020F-7E72-4494-90A0-2DF11D235DF9}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d_8_1.Windows", "..\frameworks\js-bindings\cocos2d-x\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Windows\libcocos2d_8_1.Windows.vcxproj", "{9335005F-678E-4E8E-9B84-50037216AEC8}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d_8_1.WindowsPhone", "..\frameworks\js-bindings\cocos2d-x\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.WindowsPhone\libcocos2d_8_1.WindowsPhone.vcxproj", "{22F3B9DF-1209-4574-8331-003966F562BF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbox2d.Shared", "..\frameworks\js-bindings\cocos2d-x\external\Box2D\proj.win8.1-universal\libbox2d.Shared\libbox2d.Shared.vcxitems", "{4A3C6BA8-C227-498B-AA21-40BDA27B461F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbox2d.Windows", "..\frameworks\js-bindings\cocos2d-x\external\Box2D\proj.win8.1-universal\libbox2d.Windows\libbox2d.Windows.vcxproj", "{3B26A12D-3A44-47EA-82D2-282660FC844D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbox2d.WindowsPhone", "..\frameworks\js-bindings\cocos2d-x\external\Box2D\proj.win8.1-universal\libbox2d.WindowsPhone\libbox2d.WindowsPhone.vcxproj", "{22F798D8-BFFF-4754-996F-A5395343D5EC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine.Shared", "..\frameworks\js-bindings\cocos2d-x\cocos\editor-support\spine\proj.win8.1-universal\libSpine.Shared\libSpine.Shared.vcxitems", "{ADAFD00D-A0D6-46EF-9F0B-EA2880BFE1DE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine.Windows", "..\frameworks\js-bindings\cocos2d-x\cocos\editor-support\spine\proj.win8.1-universal\libSpine.Windows\libSpine.Windows.vcxproj", "{F3550FE0-C795-44F6-8FEB-093EB68143AE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine.WindowsPhone", "..\frameworks\js-bindings\cocos2d-x\cocos\editor-support\spine\proj.win8.1-universal\libSpine.WindowsPhone\libSpine.WindowsPhone.vcxproj", "{CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libJSBinding", "libJSBinding", "{A826A599-D986-4743-9DAA-B0C4505521C8}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libJSBinding.Shared", "..\frameworks\js-bindings\bindings\proj.win8.1-universal\libJSBinding\libJSBinding.Shared\libJSBinding.Shared.vcxitems", "{BEA66276-51DD-4C53-92A8-F3D1FEA50892}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libJSBinding.Windows", "..\frameworks\js-bindings\bindings\proj.win8.1-universal\libJSBinding\libJSBinding.Windows\libJSBinding.Windows.vcxproj", "{BCF5546D-66A0-4998-AFD6-C5514F618930}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libJSBinding.WindowsPhone", "..\frameworks\js-bindings\bindings\proj.win8.1-universal\libJSBinding\libJSBinding.WindowsPhone\libJSBinding.WindowsPhone.vcxproj", "{CA082EC4-17CE-430B-8207-D1E947A5D1E9}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "js-moonwarriors", "js-moonwarriors", "{1211CA2E-A0F7-45D7-874A-C87218D3EC9C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "js-tests", "js-tests", "{7B5C0FC9-D570-481A-B8D8-5FDF307C477E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "js-tests.Shared", "..\samples\js-tests\project\proj.win8.1-universal\App.Shared\js-tests.Shared.vcxitems", "{AE6763F6-1549-441E-AFB5-377BE1C776DC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "js-tests.Windows", "..\samples\js-tests\project\proj.win8.1-universal\App.Windows\js-tests.Windows.vcxproj", "{70914FC8-7709-4CD6-B86B-C63FDE5478DB}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "js-tests.WindowsPhone", "..\samples\js-tests\project\proj.win8.1-universal\App.WindowsPhone\js-tests.WindowsPhone.vcxproj", "{94874B5B-398F-448A-A366-35A35DC1DB9C}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "js-moonwarriors.Shared", "..\samples\js-moonwarriors\project\proj.win8.1-universal\App.Shared\js-moonwarriors.Shared.vcxitems", "{A3AD93E4-0B2F-4C58-9181-69BED2E42E3E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "js-moonwarriors.Windows", "..\samples\js-moonwarriors\project\proj.win8.1-universal\App.Windows\js-moonwarriors.Windows.vcxproj", "{79A8FCDA-4B12-4DD1-B676-FF148D651638}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "js-moonwarriors.WindowsPhone", "..\samples\js-moonwarriors\project\proj.win8.1-universal\App.WindowsPhone\js-moonwarriors.WindowsPhone.vcxproj", "{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}" +EndProject +Global + GlobalSection(SharedMSBuildProjectFiles) = preSolution + ..\samples\js-tests\project\proj.win8.1-universal\App.Shared\js-tests.Shared.vcxitems*{ae6763f6-1549-441e-afb5-377be1c776dc}*SharedItemsImports = 9 + ..\samples\js-tests\project\proj.win8.1-universal\App.Shared\js-tests.Shared.vcxitems*{94874b5b-398f-448a-a366-35a35dc1db9c}*SharedItemsImports = 4 + ..\frameworks\js-bindings\cocos2d-x\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Shared\libcocos2d_8_1.Shared.vcxitems*{9335005f-678e-4e8e-9b84-50037216aec8}*SharedItemsImports = 4 + ..\samples\js-moonwarriors\project\proj.win8.1-universal\App.Shared\js-moonwarriors.Shared.vcxitems*{a3ad93e4-0b2f-4c58-9181-69bed2e42e3e}*SharedItemsImports = 9 + ..\samples\js-tests\project\proj.win8.1-universal\App.Shared\js-tests.Shared.vcxitems*{70914fc8-7709-4cd6-b86b-c63fde5478db}*SharedItemsImports = 4 + ..\frameworks\js-bindings\cocos2d-x\cocos\editor-support\spine\proj.win8.1-universal\libSpine.Shared\libSpine.Shared.vcxitems*{cc1da216-a80d-4be4-b309-acb6af313aff}*SharedItemsImports = 4 + ..\frameworks\js-bindings\cocos2d-x\external\Box2D\proj.win8.1-universal\libbox2d.Shared\libbox2d.Shared.vcxitems*{4a3c6ba8-c227-498b-aa21-40bda27b461f}*SharedItemsImports = 9 + ..\samples\js-moonwarriors\project\proj.win8.1-universal\App.Shared\js-moonwarriors.Shared.vcxitems*{79a8fcda-4b12-4dd1-b676-ff148d651638}*SharedItemsImports = 4 + ..\frameworks\js-bindings\cocos2d-x\cocos\editor-support\spine\proj.win8.1-universal\libSpine.Shared\libSpine.Shared.vcxitems*{adafd00d-a0d6-46ef-9f0b-ea2880bfe1de}*SharedItemsImports = 9 + ..\frameworks\js-bindings\bindings\proj.win8.1-universal\libJSBinding\libJSBinding.Shared\libJSBinding.Shared.vcxitems*{ca082ec4-17ce-430b-8207-d1e947a5d1e9}*SharedItemsImports = 4 + ..\frameworks\js-bindings\cocos2d-x\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Shared\libcocos2d_8_1.Shared.vcxitems*{5d6f020f-7e72-4494-90a0-2df11d235df9}*SharedItemsImports = 9 + ..\frameworks\js-bindings\bindings\proj.win8.1-universal\libJSBinding\libJSBinding.Shared\libJSBinding.Shared.vcxitems*{bea66276-51dd-4c53-92a8-f3d1fea50892}*SharedItemsImports = 9 + ..\frameworks\js-bindings\bindings\proj.win8.1-universal\libJSBinding\libJSBinding.Shared\libJSBinding.Shared.vcxitems*{bcf5546d-66a0-4998-afd6-c5514f618930}*SharedItemsImports = 4 + ..\frameworks\js-bindings\cocos2d-x\external\Box2D\proj.win8.1-universal\libbox2d.Shared\libbox2d.Shared.vcxitems*{3b26a12d-3a44-47ea-82d2-282660fc844d}*SharedItemsImports = 4 + ..\frameworks\js-bindings\cocos2d-x\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Shared\libcocos2d_8_1.Shared.vcxitems*{22f3b9df-1209-4574-8331-003966f562bf}*SharedItemsImports = 4 + ..\frameworks\js-bindings\cocos2d-x\external\Box2D\proj.win8.1-universal\libbox2d.Shared\libbox2d.Shared.vcxitems*{22f798d8-bfff-4754-996f-a5395343d5ec}*SharedItemsImports = 4 + ..\frameworks\js-bindings\cocos2d-x\cocos\editor-support\spine\proj.win8.1-universal\libSpine.Shared\libSpine.Shared.vcxitems*{f3550fe0-c795-44f6-8feb-093eb68143ae}*SharedItemsImports = 4 + ..\samples\js-moonwarriors\project\proj.win8.1-universal\App.Shared\js-moonwarriors.Shared.vcxitems*{396fe85e-bb05-4b92-bccb-f89aed4ea41a}*SharedItemsImports = 4 + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM = Debug|ARM + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|ARM = Release|ARM + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9335005F-678E-4E8E-9B84-50037216AEC8}.Debug|ARM.ActiveCfg = Debug|ARM + {9335005F-678E-4E8E-9B84-50037216AEC8}.Debug|ARM.Build.0 = Debug|ARM + {9335005F-678E-4E8E-9B84-50037216AEC8}.Debug|Win32.ActiveCfg = Debug|Win32 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Debug|Win32.Build.0 = Debug|Win32 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Debug|x64.ActiveCfg = Debug|x64 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Debug|x64.Build.0 = Debug|x64 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Release|ARM.ActiveCfg = Release|ARM + {9335005F-678E-4E8E-9B84-50037216AEC8}.Release|ARM.Build.0 = Release|ARM + {9335005F-678E-4E8E-9B84-50037216AEC8}.Release|Win32.ActiveCfg = Release|Win32 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Release|Win32.Build.0 = Release|Win32 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Release|x64.ActiveCfg = Release|x64 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Release|x64.Build.0 = Release|x64 + {22F3B9DF-1209-4574-8331-003966F562BF}.Debug|ARM.ActiveCfg = Debug|ARM + {22F3B9DF-1209-4574-8331-003966F562BF}.Debug|ARM.Build.0 = Debug|ARM + {22F3B9DF-1209-4574-8331-003966F562BF}.Debug|Win32.ActiveCfg = Debug|Win32 + {22F3B9DF-1209-4574-8331-003966F562BF}.Debug|Win32.Build.0 = Debug|Win32 + {22F3B9DF-1209-4574-8331-003966F562BF}.Debug|x64.ActiveCfg = Debug|Win32 + {22F3B9DF-1209-4574-8331-003966F562BF}.Release|ARM.ActiveCfg = Release|ARM + {22F3B9DF-1209-4574-8331-003966F562BF}.Release|ARM.Build.0 = Release|ARM + {22F3B9DF-1209-4574-8331-003966F562BF}.Release|Win32.ActiveCfg = Release|Win32 + {22F3B9DF-1209-4574-8331-003966F562BF}.Release|Win32.Build.0 = Release|Win32 + {22F3B9DF-1209-4574-8331-003966F562BF}.Release|x64.ActiveCfg = Release|Win32 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|ARM.ActiveCfg = Debug|ARM + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|ARM.Build.0 = Debug|ARM + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|Win32.ActiveCfg = Debug|Win32 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|Win32.Build.0 = Debug|Win32 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|x64.ActiveCfg = Debug|x64 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|x64.Build.0 = Debug|x64 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Release|ARM.ActiveCfg = Release|ARM + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Release|ARM.Build.0 = Release|ARM + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Release|Win32.ActiveCfg = Release|Win32 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Release|Win32.Build.0 = Release|Win32 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Release|x64.ActiveCfg = Release|x64 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Release|x64.Build.0 = Release|x64 + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Debug|ARM.ActiveCfg = Debug|ARM + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Debug|ARM.Build.0 = Debug|ARM + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Debug|Win32.ActiveCfg = Debug|Win32 + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Debug|Win32.Build.0 = Debug|Win32 + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Debug|x64.ActiveCfg = Debug|Win32 + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Release|ARM.ActiveCfg = Release|ARM + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Release|ARM.Build.0 = Release|ARM + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Release|Win32.ActiveCfg = Release|Win32 + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Release|Win32.Build.0 = Release|Win32 + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Release|x64.ActiveCfg = Release|Win32 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Debug|ARM.ActiveCfg = Debug|ARM + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Debug|ARM.Build.0 = Debug|ARM + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Debug|Win32.ActiveCfg = Debug|Win32 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Debug|Win32.Build.0 = Debug|Win32 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Debug|x64.ActiveCfg = Debug|x64 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Debug|x64.Build.0 = Debug|x64 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Release|ARM.ActiveCfg = Release|ARM + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Release|ARM.Build.0 = Release|ARM + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Release|Win32.ActiveCfg = Release|Win32 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Release|Win32.Build.0 = Release|Win32 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Release|x64.ActiveCfg = Release|x64 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Release|x64.Build.0 = Release|x64 + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Debug|ARM.ActiveCfg = Debug|ARM + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Debug|ARM.Build.0 = Debug|ARM + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Debug|Win32.ActiveCfg = Debug|Win32 + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Debug|Win32.Build.0 = Debug|Win32 + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Debug|x64.ActiveCfg = Debug|Win32 + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Release|ARM.ActiveCfg = Release|ARM + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Release|ARM.Build.0 = Release|ARM + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Release|Win32.ActiveCfg = Release|Win32 + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Release|Win32.Build.0 = Release|Win32 + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Release|x64.ActiveCfg = Release|Win32 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|ARM.ActiveCfg = Debug|ARM + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|ARM.Build.0 = Debug|ARM + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|Win32.ActiveCfg = Debug|Win32 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|Win32.Build.0 = Debug|Win32 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|x64.ActiveCfg = Debug|x64 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|x64.Build.0 = Debug|x64 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|ARM.ActiveCfg = Release|ARM + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|ARM.Build.0 = Release|ARM + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|Win32.ActiveCfg = Release|Win32 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|Win32.Build.0 = Release|Win32 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|x64.ActiveCfg = Release|x64 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|x64.Build.0 = Release|x64 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|ARM.ActiveCfg = Debug|ARM + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|ARM.Build.0 = Debug|ARM + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|Win32.ActiveCfg = Debug|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|Win32.Build.0 = Debug|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|x64.ActiveCfg = Debug|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|ARM.ActiveCfg = Release|ARM + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|ARM.Build.0 = Release|ARM + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|Win32.ActiveCfg = Release|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|Win32.Build.0 = Release|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|x64.ActiveCfg = Release|Win32 + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Debug|ARM.ActiveCfg = Debug|ARM + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Debug|ARM.Build.0 = Debug|ARM + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Debug|ARM.Deploy.0 = Debug|ARM + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Debug|Win32.ActiveCfg = Debug|Win32 + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Debug|Win32.Build.0 = Debug|Win32 + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Debug|Win32.Deploy.0 = Debug|Win32 + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Debug|x64.ActiveCfg = Debug|x64 + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Debug|x64.Build.0 = Debug|x64 + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Debug|x64.Deploy.0 = Debug|x64 + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Release|ARM.ActiveCfg = Release|ARM + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Release|ARM.Build.0 = Release|ARM + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Release|ARM.Deploy.0 = Release|ARM + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Release|Win32.ActiveCfg = Release|Win32 + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Release|Win32.Build.0 = Release|Win32 + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Release|Win32.Deploy.0 = Release|Win32 + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Release|x64.ActiveCfg = Release|x64 + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Release|x64.Build.0 = Release|x64 + {70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Release|x64.Deploy.0 = Release|x64 + {94874B5B-398F-448A-A366-35A35DC1DB9C}.Debug|ARM.ActiveCfg = Debug|ARM + {94874B5B-398F-448A-A366-35A35DC1DB9C}.Debug|ARM.Build.0 = Debug|ARM + {94874B5B-398F-448A-A366-35A35DC1DB9C}.Debug|ARM.Deploy.0 = Debug|ARM + {94874B5B-398F-448A-A366-35A35DC1DB9C}.Debug|Win32.ActiveCfg = Debug|Win32 + {94874B5B-398F-448A-A366-35A35DC1DB9C}.Debug|Win32.Build.0 = Debug|Win32 + {94874B5B-398F-448A-A366-35A35DC1DB9C}.Debug|Win32.Deploy.0 = Debug|Win32 + {94874B5B-398F-448A-A366-35A35DC1DB9C}.Debug|x64.ActiveCfg = Debug|Win32 + {94874B5B-398F-448A-A366-35A35DC1DB9C}.Release|ARM.ActiveCfg = Release|ARM + {94874B5B-398F-448A-A366-35A35DC1DB9C}.Release|ARM.Build.0 = Release|ARM + {94874B5B-398F-448A-A366-35A35DC1DB9C}.Release|ARM.Deploy.0 = Release|ARM + {94874B5B-398F-448A-A366-35A35DC1DB9C}.Release|Win32.ActiveCfg = Release|Win32 + {94874B5B-398F-448A-A366-35A35DC1DB9C}.Release|Win32.Build.0 = Release|Win32 + {94874B5B-398F-448A-A366-35A35DC1DB9C}.Release|Win32.Deploy.0 = Release|Win32 + {94874B5B-398F-448A-A366-35A35DC1DB9C}.Release|x64.ActiveCfg = Release|Win32 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|ARM.ActiveCfg = Debug|ARM + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|ARM.Build.0 = Debug|ARM + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|ARM.Deploy.0 = Debug|ARM + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|Win32.ActiveCfg = Debug|Win32 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|Win32.Build.0 = Debug|Win32 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|Win32.Deploy.0 = Debug|Win32 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|x64.ActiveCfg = Debug|x64 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|x64.Build.0 = Debug|x64 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|x64.Deploy.0 = Debug|x64 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|ARM.ActiveCfg = Release|ARM + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|ARM.Build.0 = Release|ARM + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|ARM.Deploy.0 = Release|ARM + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|Win32.ActiveCfg = Release|Win32 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|Win32.Build.0 = Release|Win32 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|Win32.Deploy.0 = Release|Win32 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|x64.ActiveCfg = Release|x64 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|x64.Build.0 = Release|x64 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|x64.Deploy.0 = Release|x64 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|ARM.ActiveCfg = Debug|ARM + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|ARM.Build.0 = Debug|ARM + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|ARM.Deploy.0 = Debug|ARM + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|Win32.ActiveCfg = Debug|Win32 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|Win32.Build.0 = Debug|Win32 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|Win32.Deploy.0 = Debug|Win32 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|x64.ActiveCfg = Debug|Win32 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|ARM.ActiveCfg = Release|ARM + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|ARM.Build.0 = Release|ARM + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|ARM.Deploy.0 = Release|ARM + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|Win32.ActiveCfg = Release|Win32 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|Win32.Build.0 = Release|Win32 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|Win32.Deploy.0 = Release|Win32 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|x64.ActiveCfg = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {B3D1A3D5-9F54-43AF-9322-230B53242B78} = {85630454-74EA-4B5B-9B62-0E459B4476CB} + {6FEB795C-C98C-4C8C-A88B-A35DEE205348} = {85630454-74EA-4B5B-9B62-0E459B4476CB} + {5D6F020F-7E72-4494-90A0-2DF11D235DF9} = {B3F299D4-B4CA-4F0B-8BE2-FB328483BC13} + {9335005F-678E-4E8E-9B84-50037216AEC8} = {B3F299D4-B4CA-4F0B-8BE2-FB328483BC13} + {22F3B9DF-1209-4574-8331-003966F562BF} = {B3F299D4-B4CA-4F0B-8BE2-FB328483BC13} + {4A3C6BA8-C227-498B-AA21-40BDA27B461F} = {B3D1A3D5-9F54-43AF-9322-230B53242B78} + {3B26A12D-3A44-47EA-82D2-282660FC844D} = {B3D1A3D5-9F54-43AF-9322-230B53242B78} + {22F798D8-BFFF-4754-996F-A5395343D5EC} = {B3D1A3D5-9F54-43AF-9322-230B53242B78} + {ADAFD00D-A0D6-46EF-9F0B-EA2880BFE1DE} = {6FEB795C-C98C-4C8C-A88B-A35DEE205348} + {F3550FE0-C795-44F6-8FEB-093EB68143AE} = {6FEB795C-C98C-4C8C-A88B-A35DEE205348} + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF} = {6FEB795C-C98C-4C8C-A88B-A35DEE205348} + {BEA66276-51DD-4C53-92A8-F3D1FEA50892} = {A826A599-D986-4743-9DAA-B0C4505521C8} + {BCF5546D-66A0-4998-AFD6-C5514F618930} = {A826A599-D986-4743-9DAA-B0C4505521C8} + {CA082EC4-17CE-430B-8207-D1E947A5D1E9} = {A826A599-D986-4743-9DAA-B0C4505521C8} + {AE6763F6-1549-441E-AFB5-377BE1C776DC} = {7B5C0FC9-D570-481A-B8D8-5FDF307C477E} + {70914FC8-7709-4CD6-B86B-C63FDE5478DB} = {7B5C0FC9-D570-481A-B8D8-5FDF307C477E} + {94874B5B-398F-448A-A366-35A35DC1DB9C} = {7B5C0FC9-D570-481A-B8D8-5FDF307C477E} + {A3AD93E4-0B2F-4C58-9181-69BED2E42E3E} = {1211CA2E-A0F7-45D7-874A-C87218D3EC9C} + {79A8FCDA-4B12-4DD1-B676-FF148D651638} = {1211CA2E-A0F7-45D7-874A-C87218D3EC9C} + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A} = {1211CA2E-A0F7-45D7-874A-C87218D3EC9C} + EndGlobalSection +EndGlobal diff --git a/build/cocos2d-jsb-samples.wp8.sln b/build/cocos2d-jsb-samples.wp8.sln new file mode 100644 index 0000000000..f8cc297563 --- /dev/null +++ b/build/cocos2d-jsb-samples.wp8.sln @@ -0,0 +1,235 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine", "..\frameworks\js-bindings\cocos2d-x\cocos\editor-support\spine\proj.wp8\libSpine.vcxproj", "{7D4FC6EB-9497-4804-98F3-3EAEDC896154}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Box2D", "..\frameworks\js-bindings\cocos2d-x\external\Box2D\proj.wp8\Box2D.vcxproj", "{C55734A3-702C-4FA1-B950-32C8E169302F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d_wp8", "..\frameworks\js-bindings\cocos2d-x\cocos\2d\libcocos2d_wp8.vcxproj", "{7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libJSBinding", "..\frameworks\js-bindings\bindings\proj.wp8\libJSBinding.vcxproj", "{DD11890A-006E-4D4B-BBE6-A577601288A2}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "js-moonwarriors-wp8-xaml", "js-moonwarriors-wp8-xaml", "{A5EDCD95-9C67-4438-A3AE-9F29AE2BD775}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "js-moonwarriorsComponent", "..\samples\js-moonwarriors\project\proj.wp8-xaml\js-moonwarriorsComponent\js-moonwarriorsComponent.vcxproj", "{F5D665F8-AE19-4F3F-99A7-230A1E8305D2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "js-moonwarriors", "..\samples\js-moonwarriors\project\proj.wp8-xaml\js-moonwarriors\js-moonwarriors.csproj", "{5921FE12-7EF3-4847-8453-42EF286DDBE7}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "js-tests-wp8-xaml", "js-tests-wp8-xaml", "{43CCF70A-4690-4153-8C03-BE593E34B99A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "js-testsComponent", "..\samples\js-tests\project\proj.wp8-xaml\js-testsComponent\js-testsComponent.vcxproj", "{878A2939-C627-4E6E-907D-38381FF35E5A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "js-tests", "..\samples\js-tests\project\proj.wp8-xaml\js-tests\js-tests.csproj", "{8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|ARM = Debug|ARM + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM + Release|Mixed Platforms = Release|Mixed Platforms + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Debug|ARM.ActiveCfg = Debug|ARM + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Debug|ARM.Build.0 = Debug|ARM + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Debug|Win32.ActiveCfg = Debug|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Debug|Win32.Build.0 = Debug|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Debug|x64.ActiveCfg = Debug|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Debug|x86.ActiveCfg = Debug|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Debug|x86.Build.0 = Debug|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Release|Any CPU.ActiveCfg = Release|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Release|ARM.ActiveCfg = Release|ARM + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Release|ARM.Build.0 = Release|ARM + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Release|Mixed Platforms.Build.0 = Release|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Release|Win32.ActiveCfg = Release|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Release|Win32.Build.0 = Release|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Release|x64.ActiveCfg = Release|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Release|x86.ActiveCfg = Release|Win32 + {7D4FC6EB-9497-4804-98F3-3EAEDC896154}.Release|x86.Build.0 = Release|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Debug|ARM.ActiveCfg = Debug|ARM + {C55734A3-702C-4FA1-B950-32C8E169302F}.Debug|ARM.Build.0 = Debug|ARM + {C55734A3-702C-4FA1-B950-32C8E169302F}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Debug|Win32.ActiveCfg = Debug|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Debug|Win32.Build.0 = Debug|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Debug|x64.ActiveCfg = Debug|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Debug|x86.ActiveCfg = Debug|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Debug|x86.Build.0 = Debug|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Release|Any CPU.ActiveCfg = Release|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Release|ARM.ActiveCfg = Release|ARM + {C55734A3-702C-4FA1-B950-32C8E169302F}.Release|ARM.Build.0 = Release|ARM + {C55734A3-702C-4FA1-B950-32C8E169302F}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Release|Mixed Platforms.Build.0 = Release|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Release|Win32.ActiveCfg = Release|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Release|Win32.Build.0 = Release|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Release|x64.ActiveCfg = Release|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Release|x86.ActiveCfg = Release|Win32 + {C55734A3-702C-4FA1-B950-32C8E169302F}.Release|x86.Build.0 = Release|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Debug|ARM.ActiveCfg = Debug|ARM + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Debug|ARM.Build.0 = Debug|ARM + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Debug|Win32.ActiveCfg = Debug|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Debug|Win32.Build.0 = Debug|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Debug|x64.ActiveCfg = Debug|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Debug|x86.ActiveCfg = Debug|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Debug|x86.Build.0 = Debug|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Release|Any CPU.ActiveCfg = Release|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Release|ARM.ActiveCfg = Release|ARM + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Release|ARM.Build.0 = Release|ARM + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Release|Mixed Platforms.Build.0 = Release|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Release|Win32.ActiveCfg = Release|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Release|Win32.Build.0 = Release|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Release|x64.ActiveCfg = Release|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Release|x86.ActiveCfg = Release|Win32 + {7C5DBC42-27F6-4978-AABC-02BA77E2A7F0}.Release|x86.Build.0 = Release|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Debug|ARM.ActiveCfg = Debug|ARM + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Debug|ARM.Build.0 = Debug|ARM + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Debug|Win32.ActiveCfg = Debug|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Debug|Win32.Build.0 = Debug|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Debug|x64.ActiveCfg = Debug|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Debug|x86.ActiveCfg = Debug|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Debug|x86.Build.0 = Debug|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Release|Any CPU.ActiveCfg = Release|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Release|ARM.ActiveCfg = Release|ARM + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Release|ARM.Build.0 = Release|ARM + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Release|Mixed Platforms.Build.0 = Release|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Release|Win32.ActiveCfg = Release|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Release|Win32.Build.0 = Release|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Release|x64.ActiveCfg = Release|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Release|x86.ActiveCfg = Release|Win32 + {DD11890A-006E-4D4B-BBE6-A577601288A2}.Release|x86.Build.0 = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|ARM.ActiveCfg = Debug|ARM + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|ARM.Build.0 = Debug|ARM + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Win32.ActiveCfg = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Win32.Build.0 = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|x64.ActiveCfg = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|x86.ActiveCfg = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|x86.Build.0 = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Any CPU.ActiveCfg = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|ARM.ActiveCfg = Release|ARM + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|ARM.Build.0 = Release|ARM + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Mixed Platforms.Build.0 = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Win32.ActiveCfg = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Win32.Build.0 = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|x64.ActiveCfg = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|x86.ActiveCfg = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|x86.Build.0 = Release|Win32 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|ARM.ActiveCfg = Debug|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|ARM.Build.0 = Debug|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|ARM.Deploy.0 = Debug|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Mixed Platforms.Deploy.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Win32.ActiveCfg = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Win32.Build.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Win32.Deploy.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|x64.ActiveCfg = Debug|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|x86.ActiveCfg = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|x86.Build.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|x86.Deploy.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Any CPU.Build.0 = Release|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Any CPU.Deploy.0 = Release|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|ARM.ActiveCfg = Release|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|ARM.Build.0 = Release|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|ARM.Deploy.0 = Release|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Mixed Platforms.Build.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Mixed Platforms.Deploy.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Win32.ActiveCfg = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Win32.Build.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Win32.Deploy.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|x64.ActiveCfg = Release|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|x86.ActiveCfg = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|x86.Build.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|x86.Deploy.0 = Release|x86 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Debug|ARM.ActiveCfg = Debug|ARM + {878A2939-C627-4E6E-907D-38381FF35E5A}.Debug|ARM.Build.0 = Debug|ARM + {878A2939-C627-4E6E-907D-38381FF35E5A}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Debug|Win32.ActiveCfg = Debug|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Debug|Win32.Build.0 = Debug|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Debug|x64.ActiveCfg = Debug|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Debug|x86.ActiveCfg = Debug|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Debug|x86.Build.0 = Debug|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Release|Any CPU.ActiveCfg = Release|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Release|ARM.ActiveCfg = Release|ARM + {878A2939-C627-4E6E-907D-38381FF35E5A}.Release|ARM.Build.0 = Release|ARM + {878A2939-C627-4E6E-907D-38381FF35E5A}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Release|Mixed Platforms.Build.0 = Release|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Release|Win32.ActiveCfg = Release|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Release|Win32.Build.0 = Release|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Release|x64.ActiveCfg = Release|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Release|x86.ActiveCfg = Release|Win32 + {878A2939-C627-4E6E-907D-38381FF35E5A}.Release|x86.Build.0 = Release|Win32 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|ARM.ActiveCfg = Debug|ARM + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|ARM.Build.0 = Debug|ARM + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|ARM.Deploy.0 = Debug|ARM + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|Mixed Platforms.Deploy.0 = Debug|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|Win32.ActiveCfg = Debug|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|Win32.Build.0 = Debug|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|Win32.Deploy.0 = Debug|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|x64.ActiveCfg = Debug|Any CPU + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|x86.ActiveCfg = Debug|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|x86.Build.0 = Debug|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Debug|x86.Deploy.0 = Debug|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|Any CPU.Build.0 = Release|Any CPU + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|Any CPU.Deploy.0 = Release|Any CPU + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|ARM.ActiveCfg = Release|ARM + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|ARM.Build.0 = Release|ARM + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|ARM.Deploy.0 = Release|ARM + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|Mixed Platforms.Build.0 = Release|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|Mixed Platforms.Deploy.0 = Release|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|Win32.ActiveCfg = Release|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|Win32.Build.0 = Release|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|Win32.Deploy.0 = Release|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|x64.ActiveCfg = Release|Any CPU + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|x86.ActiveCfg = Release|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|x86.Build.0 = Release|x86 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E}.Release|x86.Deploy.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2} = {A5EDCD95-9C67-4438-A3AE-9F29AE2BD775} + {5921FE12-7EF3-4847-8453-42EF286DDBE7} = {A5EDCD95-9C67-4438-A3AE-9F29AE2BD775} + {878A2939-C627-4E6E-907D-38381FF35E5A} = {43CCF70A-4690-4153-8C03-BE593E34B99A} + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E} = {43CCF70A-4690-4153-8C03-BE593E34B99A} + EndGlobalSection +EndGlobal diff --git a/build/cocos2d_jsb_samples.xcodeproj/project.pbxproj b/build/cocos2d_jsb_samples.xcodeproj/project.pbxproj index 67750e8852..a8284e4be1 100644 --- a/build/cocos2d_jsb_samples.xcodeproj/project.pbxproj +++ b/build/cocos2d_jsb_samples.xcodeproj/project.pbxproj @@ -13,7 +13,6 @@ 05F48C13192C9178008FB408 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 05F48C12192C9178008FB408 /* Security.framework */; }; 05F48C15192C9180008FB408 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 05F48C14192C9180008FB408 /* CoreTelephony.framework */; }; 05FBD794195C0910006CC37F /* libPluginFacebook.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BAC904F7195ADA7600307000 /* libPluginFacebook.a */; }; - 05FBD796195C1835006CC37F /* FacebookSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 05FBD795195C1835006CC37F /* FacebookSDK.framework */; }; 1A2B735118D2952200ED9E74 /* libcocos2d Mac.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A604F1218BF1D1D00CC9A93 /* libcocos2d Mac.a */; }; 1A2B735418D2952200ED9E74 /* libjsbindings Mac.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A604F2B18BF1D2000CC9A93 /* libjsbindings Mac.a */; }; 1A2B735518D2952200ED9E74 /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A035A71117822E9E00987F6C /* libsqlite3.dylib */; }; @@ -97,6 +96,10 @@ 1A604FB518BF1EE900CC9A93 /* libjsbindings Mac.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A604F2B18BF1D2000CC9A93 /* libjsbindings Mac.a */; }; 1A604FC118BF1EFC00CC9A93 /* libcocos2d iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A604F1C18BF1D1D00CC9A93 /* libcocos2d iOS.a */; }; 1A604FC418BF1EFC00CC9A93 /* libjsbindings iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A604F2D18BF1D2000CC9A93 /* libjsbindings iOS.a */; }; + 420BBD111AA8840E00493976 /* js_DrawNode3D_bindings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 420BBD0F1AA8840E00493976 /* js_DrawNode3D_bindings.cpp */; }; + 420BBD121AA8840E00493976 /* js_DrawNode3D_bindings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 420BBD0F1AA8840E00493976 /* js_DrawNode3D_bindings.cpp */; }; + 42BCD4A31AAF3BF500D035E5 /* js_Effect3D_bindings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 42BCD4A11AAF3BF500D035E5 /* js_Effect3D_bindings.cpp */; }; + 42BCD4A41AAF3BF500D035E5 /* js_Effect3D_bindings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 42BCD4A11AAF3BF500D035E5 /* js_Effect3D_bindings.cpp */; }; A01E17661784C06E00B0CA4A /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C6482E165F399D007D4F18 /* libz.dylib */; }; A01E17671784C06E00B0CA4A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64832165F3AFD007D4F18 /* Foundation.framework */; }; A01E17681784C06E00B0CA4A /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C6482C165F3988007D4F18 /* AudioToolbox.framework */; }; @@ -117,6 +120,8 @@ A035A5E71782290400987F6C /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64824165F3934007D4F18 /* OpenGL.framework */; }; A035A5E81782290400987F6C /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64822165F391E007D4F18 /* Cocoa.framework */; }; A035A71217822E9E00987F6C /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A035A71117822E9E00987F6C /* libsqlite3.dylib */; }; + BA0613B51AC23B2D003118D6 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BA0613B41AC23B2D003118D6 /* Security.framework */; }; + BA0613CB1AC23EC4003118D6 /* FacebookSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BA0613CA1AC23EC4003118D6 /* FacebookSDK.framework */; }; BA1BF912195AA72900B47F4E /* libPluginIAP.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BA1BF81D195A6A7400B47F4E /* libPluginIAP.a */; }; BA2350551948262700E17B2A /* script in Resources */ = {isa = PBXBuildFile; fileRef = BA2350541948262700E17B2A /* script */; }; BA2350561948262700E17B2A /* script in Resources */ = {isa = PBXBuildFile; fileRef = BA2350541948262700E17B2A /* script */; }; @@ -420,6 +425,10 @@ 1A604F6218BF1D6600CC9A93 /* Test_Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Test_Info.plist; sourceTree = ""; }; 1A604F6318BF1D6600CC9A93 /* Test_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Test_Prefix.pch; sourceTree = ""; }; 1A9F808C177E98A600D9A1CB /* libcurl.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcurl.dylib; path = usr/lib/libcurl.dylib; sourceTree = SDKROOT; }; + 420BBD0F1AA8840E00493976 /* js_DrawNode3D_bindings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = js_DrawNode3D_bindings.cpp; sourceTree = ""; }; + 420BBD101AA8840E00493976 /* js_DrawNode3D_bindings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_DrawNode3D_bindings.h; sourceTree = ""; }; + 42BCD4A11AAF3BF500D035E5 /* js_Effect3D_bindings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = js_Effect3D_bindings.cpp; sourceTree = ""; }; + 42BCD4A21AAF3BF500D035E5 /* js_Effect3D_bindings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_Effect3D_bindings.h; sourceTree = ""; }; A01E17721784C06E00B0CA4A /* js-tests iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "js-tests iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; A035A5EC1782290400987F6C /* js-tests Mac.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "js-tests Mac.app"; sourceTree = BUILT_PRODUCTS_DIR; }; A035A71117822E9E00987F6C /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; }; @@ -427,6 +436,8 @@ A07A52B91783AE900073F6A7 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/OpenGLES.framework; sourceTree = DEVELOPER_DIR; }; A07A52BB1783AEB80073F6A7 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/CoreGraphics.framework; sourceTree = DEVELOPER_DIR; }; A07A52C11783B01F0073F6A7 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/AVFoundation.framework; sourceTree = DEVELOPER_DIR; }; + BA0613B41AC23B2D003118D6 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; + BA0613CA1AC23EC4003118D6 /* FacebookSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FacebookSDK.framework; path = "../frameworks/js-bindings/cocos2d-x/plugin/plugins/facebook/proj.ios/FacebookSDK.framework"; sourceTree = ""; }; BA2350541948262700E17B2A /* script */ = {isa = PBXFileReference; lastKnownFileType = folder; name = script; path = ../../../../bindings/script; sourceTree = ""; }; BA34A78F195AA8DA002D0ECD /* PluginFacebook.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = PluginFacebook.xcodeproj; path = "../frameworks/js-bindings/cocos2d-x/plugin/plugins/facebook/proj.ios/PluginFacebook.xcodeproj"; sourceTree = ""; }; BA623DD1191A13DB00761F37 /* PluginAdmob.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = PluginAdmob.xcodeproj; path = "../frameworks/js-bindings/cocos2d-x/plugin/plugins/admob/proj.ios/PluginAdmob.xcodeproj"; sourceTree = ""; }; @@ -508,7 +519,7 @@ BA623DEF191A14EB00761F37 /* libPluginAdmob.a in Frameworks */, BA623DF0191A14EB00761F37 /* libPluginFlurry.a in Frameworks */, BA623DF1191A14EB00761F37 /* libPluginTwitter.a in Frameworks */, - 05FBD796195C1835006CC37F /* FacebookSDK.framework in Frameworks */, + BA0613CB1AC23EC4003118D6 /* FacebookSDK.framework in Frameworks */, BA623DF2191A14EB00761F37 /* libPluginUmeng.a in Frameworks */, BA623DF3191A14EB00761F37 /* libPluginWeibo.a in Frameworks */, 1A604FC118BF1EFC00CC9A93 /* libcocos2d iOS.a in Frameworks */, @@ -531,6 +542,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + BA0613B51AC23B2D003118D6 /* Security.framework in Frameworks */, 0541A77A19750F7A00E45470 /* AppKit.framework in Frameworks */, 1A604FB218BF1EE800CC9A93 /* libcocos2d Mac.a in Frameworks */, 1A604FB518BF1EE900CC9A93 /* libjsbindings Mac.a in Frameworks */, @@ -678,6 +690,10 @@ 1A604F3618BF1D5600CC9A93 /* Classes */ = { isa = PBXGroup; children = ( + 42BCD4A11AAF3BF500D035E5 /* js_Effect3D_bindings.cpp */, + 42BCD4A21AAF3BF500D035E5 /* js_Effect3D_bindings.h */, + 420BBD0F1AA8840E00493976 /* js_DrawNode3D_bindings.cpp */, + 420BBD101AA8840E00493976 /* js_DrawNode3D_bindings.h */, 0541A75C19738D5A00E45470 /* NativeOcClass.h */, 0541A75D19738D5A00E45470 /* NativeOcClass.m */, 1A604F3718BF1D5600CC9A93 /* AppDelegate.cpp */, @@ -744,6 +760,8 @@ 29B97323FDCFA39411CA2CEA /* Frameworks */ = { isa = PBXGroup; children = ( + BA0613CA1AC23EC4003118D6 /* FacebookSDK.framework */, + BA0613B41AC23B2D003118D6 /* Security.framework */, BAB1575019F041BB00BDF3AD /* GameController.framework */, 0541A77919750F7A00E45470 /* AppKit.framework */, 05FBD795195C1835006CC37F /* FacebookSDK.framework */, @@ -1226,6 +1244,8 @@ files = ( 0541A76319738D8C00E45470 /* NativeOcClass.m in Sources */, 1A604F5A18BF1D6000CC9A93 /* RootViewController.mm in Sources */, + 42BCD4A41AAF3BF500D035E5 /* js_Effect3D_bindings.cpp in Sources */, + 420BBD121AA8840E00493976 /* js_DrawNode3D_bindings.cpp in Sources */, 1A604F3A18BF1D5600CC9A93 /* AppDelegate.cpp in Sources */, 1A604F5918BF1D6000CC9A93 /* main.m in Sources */, 1A604F4D18BF1D6000CC9A93 /* AppController.mm in Sources */, @@ -1238,6 +1258,8 @@ files = ( 0541A77819750DE700E45470 /* NativeOcClass.m in Sources */, 1A604F6718BF1D6600CC9A93 /* main.cpp in Sources */, + 42BCD4A31AAF3BF500D035E5 /* js_Effect3D_bindings.cpp in Sources */, + 420BBD111AA8840E00493976 /* js_DrawNode3D_bindings.cpp in Sources */, 1A604F3918BF1D5600CC9A93 /* AppDelegate.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1475,8 +1497,7 @@ COPY_PHASE_STRIP = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", - "$(SRCROOT)/../frameworks/js-bindings/cocos2d-x/plugin/plugins/facebook/proj.ios/sdk", - "$(DEVELOPER_DIR)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk/System/Library/Frameworks", + "$(SRCROOT)/../frameworks/js-bindings/cocos2d-x/plugin/plugins/facebook/proj.ios", ); GCC_DYNAMIC_NO_PIC = NO; GCC_INLINES_ARE_PRIVATE_EXTERN = NO; @@ -1509,8 +1530,7 @@ COMPRESS_PNG_FILES = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", - "$(SRCROOT)/../frameworks/js-bindings/cocos2d-x/plugin/plugins/facebook/proj.ios/sdk", - "$(DEVELOPER_DIR)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk/System/Library/Frameworks", + "$(SRCROOT)/../frameworks/js-bindings/cocos2d-x/plugin/plugins/facebook/proj.ios", ); GCC_GENERATE_DEBUGGING_SYMBOLS = NO; GCC_INLINES_ARE_PRIVATE_EXTERN = NO; diff --git a/docs/gradient-color-stop.jpg b/docs/gradient-color-stop.jpg new file mode 100644 index 0000000000..d71c151460 Binary files /dev/null and b/docs/gradient-color-stop.jpg differ diff --git a/docs/release-note-v3.3.md b/docs/release-note-v3.3.md new file mode 100644 index 0000000000..a0f86a8891 --- /dev/null +++ b/docs/release-note-v3.3.md @@ -0,0 +1,78 @@ +# Cocos2d-JS v3.3 release note + + + +Cocos2d-JS is Cocos2d-x engine's JavaScript version that includes Cocos2d-html5 and Cocos2d-x JavaScript Bindings. It equips your game with cross-browser and cross-platform abilities, accompanied by full Cocos2d-x features and simplified JavaScript friendly APIs. + +Cocos2d-JS reinvented workflows for all platforms in v3.x, it provides a consistent development experience for whichever platform you want to distribute to, no matter web and native. "Code once, run everywhere" is incredibly easy and natural in Cocos2d-JS. With one single JavaScript code base, you can run your game on all web browsers and native platforms including Mac OS, Windows, iOS and Android. This will bring your game great opportunities in almost all channels of distribution. On the other hand, if you are only interested in casual games on the web, you can embed directly in your web page the Cocos2d-JS Lite Version which is extremely easy to use and light as a feather. + +In addition, Cocos2d-JS v3.x is super powerful along with all these cool new features: Editors Support, Assets Manager, Object Pool, JS to Objective-C/JAVA reflection, etc. + +One more thing, Facebook Integration for Cocos2d-JS have brought a huge opportunity for game developers who want to integrate Facebook functionality into their games. With a single code base, they can release fully cross-platform games across Facebook Canvas, iOS and Android. + +## Highlights + +* Supported [Cocos Studio 2.x](http://cocos2d-x.org/download) with its JSON format export, the web engine and native engine share exactly the same parser, so that its result's consistency will be guaranteed for all platforms. +* Supported latest versioin of [Spine animation editor](http://esotericsoftware.com/). +* Upgraded UI system with the new flow layout system and added full featured test cases. +* Provided [Cocos Dev Tool](http://h5.cocoachina.com/static/cocos-devtools/index-en.html) beta version. It's a web based playground for manipulating all coocs nodes in runtime. It will greatly improve your developement and debug experience. + +![](../../res/devtool.jpg) + +## Notice + +For JSB build, there are some restrictions : + +- [Android build] Suggested NDK version is r10c, if you don't need Android 5.0 compatibility, you can also use r9d, other NDKs are not supported. +- [iOS build] Xcode version must be 5.1.1 + +- [Web code obfuscation] JRE or JDK version must be 1.6+ + +## Download + +- [Cocos2d-JS v3.3](http://www.cocos2d-x.org/filedown/cocos2d-js-v3.3.zip) +- [Cocos2d-JS Lite Version](http://cocos2d-x.org/filecenter/jsbuilder/) +- [Cocos Dev Tool](http://h5.cocos.com/static/cocos-devtools/index-en.html) +- [Online API reference](http://www.cocos2d-x.org/wiki/reference/) +- [Downloadable API Reference](http://www.cocos2d-x.org/filedown/Cocos2d-JS-v3.3-API.zip) +- [Online test cases](http://cocos2d-x.org/js-tests/) + +## The roadmap + +We are very glad to share some plans for the future versions of Cocos2d-JS: + +- Upgrade SpiderMonkey to v33, this will improve native engine performance and stability. +- Support Windows Phone 8 for the native engine. +- Add 3D module bindings for the native engine. +- Add Box2d engine with a emscripten version in both web and native engine. +- Upgrade Spine runtime's API. +- Improve Web engine UI system performance. + +## More information + +Read more about all the features and bug fixes + +- [Cocos2d-JS v3.3 changelog](http://www.cocos2d-x.org/docs/manual/framework/html5/release-notes/v3.3/changelog/en) +- [Cocos2d-JS v3.3 upgrade guide](http://www.cocos2d-x.org/docs/manual/framework/html5/release-notes/v3.3b/upgrade-guide/en) + +## Upgrade your project from previous versions + +If you want to upgrade your game based on v3.0 previous version to the v3.3, you should follow these steps: + +1. Download the Cocos2d-JS v3.3 package. +2. Upgrade cocos command with `setup.py`. +3. Create a new project with `cocos new` command. +4. Replace the "src", "res", "index.html", "project.json", "main.js" etc with your old project. +5. Then you may need to refer to the upgrade guide to solve some API change issues. + +## About Cocos2d family + +- Cocos2d-JS v3.3 uses Cocos2d-x v3.4 as base of JSB solution +- Cocos2d-JS v3.3 is compatible with Cocos Code IDE v1.1.0 +- Cocos2d-JS v3.3 is compatible with Cocos Studio v1.2 - v1.6 and Cocos Studio 2.1+. Cocos Studio 2.x support need JSON export file, and Cocos2d-JS won't support flatbuffer files. + +With any problems you might have, our communities are happy to help: + +- [Online forum](http://discuss.cocos2d-x.org/category/cocos2d-x/javascript) +- [Document root](http://cocos2d-x.org/wiki/Cocos2d-JS) +- [Github repository](https://github.com/cocos2d/cocos2d-js) +- [Issue tracker](https://github.com/cocos2d/cocos2d-js/issues) \ No newline at end of file diff --git a/docs/release-note-v3.5.md b/docs/release-note-v3.5.md new file mode 100644 index 0000000000..9af976adfc --- /dev/null +++ b/docs/release-note-v3.5.md @@ -0,0 +1,72 @@ +# Cocos2d-JS v3.5 release note + + + +Cocos2d-JS is Cocos2d-x engine's JavaScript version that includes Cocos2d-html5 and Cocos2d-x JavaScript Bindings. It equips your game with cross-browser and cross-platform abilities, accompanied by full Cocos2d-x features and simplified JavaScript friendly APIs. + +Cocos2d-JS reinvented workflows for all platforms in v3.x, it provides a consistent development experience for whichever platform you want to distribute to, no matter web and native. "Code once, run everywhere" is incredibly easy and natural in Cocos2d-JS. With one single JavaScript code base, you can run your game on all web browsers and native platforms including Mac OS, Windows, iOS and Android. This will bring your game great opportunities in almost all channels of distribution. On the other hand, if you are only interested in casual games on the web, you can embed directly in your web page the Cocos2d-JS Lite Version which is extremely easy to use and light as a feather. + +In addition, Cocos2d-JS v3.x is super powerful along with all these cool new features: Editors Support, Assets Manager, Object Pool, JS to Objective-C/JAVA reflection, etc. + +One more thing, Facebook Integration for Cocos2d-JS have brought a huge opportunity for game developers who want to integrate Facebook functionality into their games. With a single code base, they can release fully cross-platform games across Facebook Canvas, iOS and Android. + +## Version notice + +The version v3.4 is renamed to v3.5, because we have upgraded the internal Cocos2d-x to v3.5 and we don't want our user to get confused about the version mapping between Cocos2d-JS and Cocos2d-x. + +## Highlights + +* 3D feature ready! Bound 3D modules including camera, light, sprite 3d, animation 3d, billboard, 3D particle system with Particle Universe etc. +* Supported Cocos Studio 2.2 3D scene editing. +* Windows Phone 8.0 and Windows Universal support are finally ready! Thanks to the contribution from Microsoft. +* Upgraded SpiderMonkey to v33, greatly improved JavaScript memory management and performance. +* Supported latest version of Spine editor. +* Continuously improved web engine performance. + +## Notice + +For JSB build, there are some restrictions : + +- [Android build] Suggested NDK version is r10c +, if you don't need Android 5.0 compatibility, you can also use r9d, other NDKs are not supported. +- [iOS build] Xcode version must be 5.1.1 + +- [Web code obfuscation] JRE or JDK version must be 1.6+ + +## Download + +- [Cocos2d-JS v3.5](http://www.cocos2d-x.org/filedown/cocos2d-js-v3.5.zip) +- [Cocos2d-JS Lite Version](http://cocos2d-x.org/filecenter/jsbuilder/) +- [Cocos Dev Tool](http://h5.cocos.com/static/cocos-devtools/index-en.html) +- [Online API reference](http://www.cocos2d-x.org/wiki/reference/) +- [Downloadable API Reference](http://www.cocos2d-x.org/filedown/Cocos2d-JS-v3.5-API.zip) +- [Online test cases](http://cocos2d-x.org/js-tests/) + +## More information + +Read more about all the features and bug fixes + +- [Cocos2d-JS v3.5 changelog](http://www.cocos2d-x.org/docs/manual/framework/html5/release-notes/v3.5/changelog/en) +- [Cocos2d-JS v3.5 upgrade guide](http://www.cocos2d-x.org/docs/manual/framework/html5/release-notes/v3.5/upgrade-guide/en) + +## Upgrade your project from previous versions + +If you want to upgrade your game based on v3.0 previous version to the v3.5, you should follow these steps: + +1. Download the Cocos2d-JS v3.5 package. +2. Upgrade cocos command with `setup.py`. +3. Create a new project with `cocos new` command. +4. Replace the "src", "res", "index.html", "project.json", "main.js" etc with your old project. +5. Then you may need to refer to the upgrade guide to solve some API change issues. + +## About Cocos2d family + +- Cocos2d-JS v3.5 uses Cocos2d-x v3.5 as base of JSB solution. +- Cocos2d-JS v3.5 uses SpiderMonkey v33 as builtin JavaScript engine. +- Cocos2d-JS v3.5 is compatible with Cocos Code IDE v1.2.0. +- Cocos2d-JS v3.5 is compatible with Cocos Studio v1.2 - v1.6 and Cocos Studio 2.1+.. + +With any problems you might have, our communities are happy to help: + +- [Online forum](http://discuss.cocos2d-x.org/category/cocos2d-x/javascript) +- [Document root](http://cocos2d-x.org/wiki/Cocos2d-JS) +- [Github repository](https://github.com/cocos2d/cocos2d-js) +- [Issue tracker](https://github.com/cocos2d/cocos2d-js/issues) \ No newline at end of file diff --git a/docs/upgrade-guide-from-3.2-to-3.3.md b/docs/upgrade-guide-from-3.2-to-3.3.md new file mode 100644 index 0000000000..0d1afa5d55 --- /dev/null +++ b/docs/upgrade-guide-from-3.2-to-3.3.md @@ -0,0 +1,46 @@ +#Upgrade guide from Cocos2d-JS v3.2 to Cocos2d-JS v3.3 + +## 0. Upgrade to Cocos2d-JS v3.2 + +If you are still using Cocos2d-html5 or previous version of Cocos2d-JS, you may need to read the previous upgrade guide first : [Upgrade guide to Cocos2d-JS v3.2](../../v3.2rc0/upgrade-guide/en.md) + +## 1. New Cocos Studio JSON parser + +In Cocos2d-JS v3.3 we have introduced one new API for all versions of Cocos Studio JSON export files. + +``` +// nodeAndAction is something like: {node: cc.Node, action: cc.Action} +var nodeAndAction = ccs.load(file); +``` + +This API covers Cocos Studio 1.* versions for the JSON export files, including UI parser, Node parser, Action parser and Scene parser. This API also covers Cocos Studio 2.1 + for the JSON export files, including Node parser and Action parser. + +Again, please be noted that this new API **only** support JSON files, if you are using Cocos Studio 2.1 +, please export your project to JSON, the flatbuffer format is **not** supported in Cocos2d-JS, neither for the web engine nor for the native engine. + +1. Parameter + + `ccs.load` accept the JSON file path as its only parameter. + +2. Return value + + The return value is an object which is composed of two properties: `node` and `action`. `node` value is absolutly included in the result, but depends on the project itself, `action` may be `null` in the result when no action is presented in the project. When the parser process failed, the result will be: + + ``` + {node: null, action: null} + ``` + +3. Preload resources obligated in web engine + + As we all know, in the web engine, you must preload all related resources before entering the scene and using them, it applies to the Cocos Studio resources too. What you need to preload is not only the JSON file, but also all its dependencies, that means all related image files, plist files, json files, audio files, and so on. In the web engine, you must add all these files into the preload list and preload them before entering the scene. Otherwise you will receive a warning in the console like this one: + + ``` + res/cocosui/UIEditorTest/2.0.5/res/Default/SliderNode_Disable.png need to be preloaded + ``` + + If you find such warning when debugging, you need to add the reported resources into the preload list. + + But in the native engine, this won't be necessary, you can just ignore the preload phase for all local resources because they are loaded with the application itself. + +4. 1.* parser API + + The Cocos Studio 1.* parser API still works as before. \ No newline at end of file diff --git a/docs/upgrade-guide-from-3.3-to-3.5.md b/docs/upgrade-guide-from-3.3-to-3.5.md new file mode 100644 index 0000000000..52b05132f3 --- /dev/null +++ b/docs/upgrade-guide-from-3.3-to-3.5.md @@ -0,0 +1,114 @@ +#Upgrade guide from Cocos2d-JS v3.3 to Cocos2d-JS v3.4 + +## 0. Upgrade to Cocos2d-JS v3.3 + +If you are still using Cocos2d-html5 or previous version of Cocos2d-JS, you may need to read the previous upgrade guides first : [Historic upgrade guides](../../en.md) + +## 1. Pulish to Windows Phone 8 (Windows Phone 8.1 is not supported yet) + +Follow these steps can help you upgrade to v3.4, then create a project and at last working for Windows Phone 8. + +1. You need to upgrade cocos console with the `setup.py` in Cocos2d-JS v3.4 package: + + ``` + $ cd cocos2d-js-v3.4 + $ ./setup.py + ``` + +2. Create a Cocos2d-JS v3.4 project: + + ``` + $ cocos new -l js WinPhone8Game + ``` + +3. Open the Windows Phone 8 project in `WinPhone8Game/frameworks/runtime-src/proj.wp8-xaml/WinPhone8Game.sln`. Note that you need Visual Studio 2012 to open it. + +4. Now you can start to compile or publish the Cocos2d-JS project for Windows Phone 8. + +## 2. [Native Exclusive] Create 3D games + +The biggest feature in Cocos2d-JS v3.4 is the 3D modules. We have bound Cocos2d-x's 3D modules to JSB, so that you can now code 3D games using JavaScript. Please note that it's a native engine exclusive feature, you can not use 3D classes in the web engine. We are not planning to support 3D for the web in the near future. + +All bound 3D classes or objects are listed here: + +``` +jsb.Animate3D +jsb.Animation3D +jsb.Sprite3D +jsb.Skeleton3D +jsb.Mesh +jsb.AttachNode +jsb.BillBoard +jsb.sprite3DCache +jsb.ParticleSystem3D +jsb.PUParticleSystem3D +jsb.BaseLight +jsb.DirectionLight +jsb.PointLight +jsb.SpotLight +jsb.AmbientLight +``` + +Sorry that we don't have a complete JavaScript document for 3D modules, we will add them as soon as possible. + +To know how to use the new 3D modules, please refer to the following documents: + +- Cocos [3d module's API reference](http://www.cocos2d-x.org/reference/native-cpp/V3.4/dir_0cec398151724e9e1c180a4e8f99801b.html) +- Cocos [Camera API reference](http://www.cocos2d-x.org/reference/native-cpp/V3.4/d6/d2b/classcocos2d_1_1_camera.html) +- Cocos [Light API reference](http://www.cocos2d-x.org/reference/native-cpp/V3.4/d2/d85/classcocos2d_1_1_base_light.html) +- Test cases in the Cocos2d-JS v3.4 package, run it with projects in `build` folder or using `cocos run` command under `samples/js-tests` folder. You can refer to the following test cases: + - BillBoardTest: source code in `samples/js-tests/src/BillBoardTest`. + - Camera3DTest: source code in `samples/js-tests/src/Camera3DTest`. + - LightTest: source code in `samples/js-tests/src/LightTest`. + - Sprite3DTest: source code in `samples/js-tests/src/Sprite3DTest`. + +## 3. [Web Exclusive] cc.LayerGradient with color stops + +In the web engine of Cocos2d-JS v3.4, you can now define color stops for a layer gradient. It's a web exclusive feature but it's safe to use the same code in native engine. + +API: + +``` +new cc.LayerGradient(beginColor, endColor, positionInPercent, colorStops); +``` + +Sample code: + +``` +// Color stops is represented by an array, where each entry is an object composed by positionInPercent and the color. +var colorStops = [ + {p: 0.25, color: cc.color(0, 0, 255, 128)}, + {p: 0.5, color: cc.color(128, 128, 128, 128)}, + {p: 0.75, color: cc.color(255, 255, 0, 128)} + ]; + +var gradient = new cc.LayerGradient(cc.color(255, 0, 0, 255), cc.color(0, 255, 0, 255), cc.p(0, 1), colorStops); +this.addChild(gradient, 10); +``` + +Result: + +![](../../res/gradient-color-stop.jpg) + +## 4. cc.sys.OpenURL + +You can now use `cc.sys.OpenURL(url)` to open the targeted url in web browser. +In case of web engine, it will open another page in the current browser. +In case of native engine, it will open the url in an external web browser. + +## 5. [Web Exclusive] Tip message in cc.TextFieldTTF + +We have added a tip message getter/setter for `cc.TextFieldTTF`. APIs are: + +``` +textFieldTTF.setTipMessage(tipMessage); +var message = textFieldTTF.getTipMessage(); +``` + +## 6. Load cocos studio resources within a relative path + +You can now pass a `path` parameter to `ccs.load` to specify a relative path for resources linked by the targeted json file. + +``` +ccs.load(jsonFile, path); +``` \ No newline at end of file diff --git a/frameworks/cocos2d-html5 b/frameworks/cocos2d-html5 index a0cee92a3f..d47f061c0a 160000 --- a/frameworks/cocos2d-html5 +++ b/frameworks/cocos2d-html5 @@ -1 +1 @@ -Subproject commit a0cee92a3f345aefb5f973074a9222eabc941ea4 +Subproject commit d47f061c0ae13078e08c637fa69e629a54177ffe diff --git a/frameworks/js-bindings/bindings/Android.mk b/frameworks/js-bindings/bindings/Android.mk index 6ea045a576..c0819bbb7e 100644 --- a/frameworks/js-bindings/bindings/Android.mk +++ b/frameworks/js-bindings/bindings/Android.mk @@ -6,12 +6,16 @@ LOCAL_MODULE := cocos_jsb_static LOCAL_MODULE_FILENAME := libcocos2dxjsb +LOCAL_ARM_MODE := arm + LOCAL_SRC_FILES := auto/jsb_cocos2dx_auto.cpp \ auto/jsb_cocos2dx_builder_auto.cpp \ auto/jsb_cocos2dx_extension_auto.cpp \ auto/jsb_cocos2dx_spine_auto.cpp \ auto/jsb_cocos2dx_studio_auto.cpp \ auto/jsb_cocos2dx_ui_auto.cpp \ + auto/jsb_cocos2dx_3d_auto.cpp \ + auto/jsb_cocos2dx_3d_extension_auto.cpp \ manual/ScriptingCore.cpp \ manual/cocos2d_specifics.cpp \ manual/js_manual_conversions.cpp \ @@ -27,6 +31,7 @@ LOCAL_SRC_FILES := auto/jsb_cocos2dx_auto.cpp \ manual/chipmunk/js_bindings_chipmunk_manual.cpp \ manual/chipmunk/js_bindings_chipmunk_registration.cpp \ manual/cocosbuilder/js_bindings_ccbreader.cpp \ + manual/cocostudio/jsb_cocos2dx_studio_conversions.cpp \ manual/cocostudio/jsb_cocos2dx_studio_manual.cpp \ manual/extension/jsb_cocos2dx_extension_manual.cpp \ manual/localstorage/js_bindings_system_functions.cpp \ @@ -35,7 +40,8 @@ LOCAL_SRC_FILES := auto/jsb_cocos2dx_auto.cpp \ manual/network/jsb_websocket.cpp \ manual/network/XMLHTTPRequest.cpp \ manual/spine/jsb_cocos2dx_spine_manual.cpp \ - manual/ui/jsb_cocos2dx_ui_manual.cpp + manual/ui/jsb_cocos2dx_ui_manual.cpp \ + manual/3d/jsb_cocos2dx_3d_manual.cpp LOCAL_CFLAGS := -DCOCOS2D_JAVASCRIPT @@ -43,6 +49,8 @@ LOCAL_CFLAGS := -DCOCOS2D_JAVASCRIPT LOCAL_EXPORT_CFLAGS := -DCOCOS2D_JAVASCRIPT LOCAL_C_INCLUDES := $(LOCAL_PATH)/manual \ + $(LOCAL_PATH)/manual/cocostudio \ + $(LOCAL_PATH)/manual/spine \ $(LOCAL_PATH)/auto \ $(LOCAL_PATH)/../cocos2d-x/cocos/2d \ $(LOCAL_PATH)/../cocos2d-x/cocos/base \ diff --git a/frameworks/js-bindings/bindings/CMakeLists.txt b/frameworks/js-bindings/bindings/CMakeLists.txt index a0f55deab4..7b56b7535d 100644 --- a/frameworks/js-bindings/bindings/CMakeLists.txt +++ b/frameworks/js-bindings/bindings/CMakeLists.txt @@ -38,6 +38,8 @@ set(JSBINDING_SRC auto/jsb_cocos2dx_spine_auto.cpp auto/jsb_cocos2dx_studio_auto.cpp auto/jsb_cocos2dx_ui_auto.cpp + auto/jsb_cocos2dx_3d_auto.cpp + auto/jsb_cocos2dx_3d_extension_auto.cpp manual/ScriptingCore.cpp manual/cocos2d_specifics.cpp manual/js_manual_conversions.cpp @@ -53,6 +55,7 @@ set(JSBINDING_SRC manual/chipmunk/js_bindings_chipmunk_registration.cpp manual/cocosbuilder/js_bindings_ccbreader.cpp manual/cocostudio/jsb_cocos2dx_studio_manual.cpp + manual/cocostudio/jsb_cocos2dx_studio_conversions.cpp manual/extension/jsb_cocos2dx_extension_manual.cpp manual/localstorage/js_bindings_system_functions.cpp manual/localstorage/js_bindings_system_registration.cpp @@ -61,12 +64,15 @@ set(JSBINDING_SRC manual/network/jsb_socketio.cpp manual/spine/jsb_cocos2dx_spine_manual.cpp manual/ui/jsb_cocos2dx_ui_manual.cpp + manual/3d/jsb_cocos2dx_3d_manual.cpp ../cocos2d-x/cocos/storage/local-storage/LocalStorage.cpp ) include_directories( auto manual + manual/cocostudio + manual/spine ../external/spidermonkey/include/${PLATFORM_FOLDER} ../cocos2d-x/cocos/base ../cocos2d-x/cocos/2d @@ -91,6 +97,7 @@ add_library(jsbindings STATIC target_link_libraries(jsbindings sqlite3 js_static + xxhash ) set_target_properties(jsbindings diff --git a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_3d_auto_api.js b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_3d_auto_api.js new file mode 100644 index 0000000000..bdfedfa5a9 --- /dev/null +++ b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_3d_auto_api.js @@ -0,0 +1,1109 @@ +/** + * @module cocos2dx_3d + */ +var jsb = jsb || {}; + +/** + * @class Skeleton3D + */ +jsb.Skeleton3D = { + +/** + * @method removeAllBones + */ +removeAllBones : function ( +) +{ +}, + +/** + * @method addBone + * @param {cc.Bone3D} arg0 + */ +addBone : function ( +bone3d +) +{ +}, + +/** + * @method getBoneByName + * @param {String} arg0 + * @return {cc.Bone3D} + */ +getBoneByName : function ( +str +) +{ + return cc.Bone3D; +}, + +/** + * @method getRootBone + * @param {int} arg0 + * @return {cc.Bone3D} + */ +getRootBone : function ( +int +) +{ + return cc.Bone3D; +}, + +/** + * @method updateBoneMatrix + */ +updateBoneMatrix : function ( +) +{ +}, + +/** + * @method getBoneByIndex + * @param {unsigned int} arg0 + * @return {cc.Bone3D} + */ +getBoneByIndex : function ( +int +) +{ + return cc.Bone3D; +}, + +/** + * @method getRootCount + * @return {long} + */ +getRootCount : function ( +) +{ + return 0; +}, + +/** + * @method getBoneIndex + * @param {cc.Bone3D} arg0 + * @return {int} + */ +getBoneIndex : function ( +bone3d +) +{ + return 0; +}, + +/** + * @method getBoneCount + * @return {long} + */ +getBoneCount : function ( +) +{ + return 0; +}, + +/** + * @method Skeleton3D + * @constructor + */ +Skeleton3D : function ( +) +{ +}, + +}; + +/** + * @class Sprite3D + */ +jsb.Sprite3D = { + +/** + * @method setCullFaceEnabled + * @param {bool} arg0 + */ +setCullFaceEnabled : function ( +bool +) +{ +}, + +/** + * @method setTexture +* @param {cc.Texture2D|String} texture2d +*/ +setTexture : function( +str +) +{ +}, + +/** + * @method getLightMask + * @return {unsigned int} + */ +getLightMask : function ( +) +{ + return 0; +}, + +/** + * @method createAttachSprite3DNode + * @param {cc.NodeData} arg0 + * @param {cc.MaterialDatas} arg1 + */ +createAttachSprite3DNode : function ( +nodedata, +materialdatas +) +{ +}, + +/** + * @method loadFromFile + * @param {String} arg0 + * @param {cc.NodeDatas} arg1 + * @param {cc.MeshDatas} arg2 + * @param {cc.MaterialDatas} arg3 + * @return {bool} + */ +loadFromFile : function ( +str, +nodedatas, +meshdatas, +materialdatas +) +{ + return false; +}, + +/** + * @method setCullFace + * @param {unsigned int} arg0 + */ +setCullFace : function ( +int +) +{ +}, + +/** + * @method addMesh + * @param {cc.Mesh} arg0 + */ +addMesh : function ( +mesh +) +{ +}, + +/** + * @method removeAllAttachNode + */ +removeAllAttachNode : function ( +) +{ +}, + +/** + * @method genGLProgramState + */ +genGLProgramState : function ( +) +{ +}, + +/** + * @method getMesh + * @return {cc.Mesh} + */ +getMesh : function ( +) +{ + return cc.Mesh; +}, + +/** + * @method createSprite3DNode + * @param {cc.NodeData} arg0 + * @param {cc.ModelData} arg1 + * @param {cc.MaterialDatas} arg2 + * @return {cc.Sprite3D} + */ +createSprite3DNode : function ( +nodedata, +modeldata, +materialdatas +) +{ + return cc.Sprite3D; +}, + +/** + * @method getMeshCount + * @return {long} + */ +getMeshCount : function ( +) +{ + return 0; +}, + +/** + * @method onAABBDirty + */ +onAABBDirty : function ( +) +{ +}, + +/** + * @method getMeshByIndex + * @param {int} arg0 + * @return {cc.Mesh} + */ +getMeshByIndex : function ( +int +) +{ + return cc.Mesh; +}, + +/** + * @method createNode + * @param {cc.NodeData} arg0 + * @param {cc.Node} arg1 + * @param {cc.MaterialDatas} arg2 + * @param {bool} arg3 + */ +createNode : function ( +nodedata, +node, +materialdatas, +bool +) +{ +}, + +/** + * @method isForceDepthWrite + * @return {bool} + */ +isForceDepthWrite : function ( +) +{ + return false; +}, + +/** + * @method getBlendFunc + * @return {cc.BlendFunc} + */ +getBlendFunc : function ( +) +{ + return cc.BlendFunc; +}, + +/** + * @method getMeshIndexData + * @param {String} arg0 + * @return {cc.MeshIndexData} + */ +getMeshIndexData : function ( +str +) +{ + return cc.MeshIndexData; +}, + +/** + * @method removeAttachNode + * @param {String} arg0 + */ +removeAttachNode : function ( +str +) +{ +}, + +/** + * @method setLightMask + * @param {unsigned int} arg0 + */ +setLightMask : function ( +int +) +{ +}, + +/** + * @method afterAsyncLoad + * @param {void} arg0 + */ +afterAsyncLoad : function ( +void +) +{ +}, + +/** + * @method loadFromCache + * @param {String} arg0 + * @return {bool} + */ +loadFromCache : function ( +str +) +{ + return false; +}, + +/** + * @method initFrom + * @param {cc.NodeDatas} arg0 + * @param {cc.MeshDatas} arg1 + * @param {cc.MaterialDatas} arg2 + * @return {bool} + */ +initFrom : function ( +nodedatas, +meshdatas, +materialdatas +) +{ + return false; +}, + +/** + * @method getAttachNode + * @param {String} arg0 + * @return {cc.AttachNode} + */ +getAttachNode : function ( +str +) +{ + return cc.AttachNode; +}, + +/** + * @method initWithFile + * @param {String} arg0 + * @return {bool} + */ +initWithFile : function ( +str +) +{ + return false; +}, + +/** + * @method setBlendFunc + * @param {cc.BlendFunc} arg0 + */ +setBlendFunc : function ( +blendfunc +) +{ +}, + +/** + * @method getSkeleton + * @return {cc.Skeleton3D} + */ +getSkeleton : function ( +) +{ + return cc.Skeleton3D; +}, + +/** + * @method setForceDepthWrite + * @param {bool} arg0 + */ +setForceDepthWrite : function ( +bool +) +{ +}, + +/** + * @method getMeshByName + * @param {String} arg0 + * @return {cc.Mesh} + */ +getMeshByName : function ( +str +) +{ + return cc.Mesh; +}, + +/** + * @method create +* @param {String|String} str +* @param {String} str +* @return {cc.Sprite3D|cc.Sprite3D|cc.Sprite3D} +*/ +create : function( +str, +str +) +{ + return cc.Sprite3D; +}, + +/** + * @method Sprite3D + * @constructor + */ +Sprite3D : function ( +) +{ +}, + +}; + +/** + * @class Sprite3DCache + */ +jsb.Sprite3DCache = { + +/** + * @method removeSprite3DData + * @param {String} arg0 + */ +removeSprite3DData : function ( +str +) +{ +}, + +/** + * @method removeAllSprite3DData + */ +removeAllSprite3DData : function ( +) +{ +}, + +/** + * @method destroyInstance + */ +destroyInstance : function ( +) +{ +}, + +/** + * @method getInstance + * @return {cc.Sprite3DCache} + */ +getInstance : function ( +) +{ + return cc.Sprite3DCache; +}, + +}; + +/** + * @class Mesh + */ +jsb.Mesh = { + +/** + * @method setTexture +* @param {cc.Texture2D|String} texture2d +*/ +setTexture : function( +str +) +{ +}, + +/** + * @method getTexture + * @return {cc.Texture2D} + */ +getTexture : function ( +) +{ + return cc.Texture2D; +}, + +/** + * @method getSkin + * @return {cc.MeshSkin} + */ +getSkin : function ( +) +{ + return cc.MeshSkin; +}, + +/** + * @method getVertexSizeInBytes + * @return {int} + */ +getVertexSizeInBytes : function ( +) +{ + return 0; +}, + +/** + * @method getName + * @return {String} + */ +getName : function ( +) +{ + return ; +}, + +/** + * @method getIndexFormat + * @return {unsigned int} + */ +getIndexFormat : function ( +) +{ + return 0; +}, + +/** + * @method getGLProgramState + * @return {cc.GLProgramState} + */ +getGLProgramState : function ( +) +{ + return cc.GLProgramState; +}, + +/** + * @method getVertexBuffer + * @return {unsigned int} + */ +getVertexBuffer : function ( +) +{ + return 0; +}, + +/** + * @method calculateAABB + */ +calculateAABB : function ( +) +{ +}, + +/** + * @method hasVertexAttrib + * @param {int} arg0 + * @return {bool} + */ +hasVertexAttrib : function ( +int +) +{ + return false; +}, + +/** + * @method getBlendFunc + * @return {cc.BlendFunc} + */ +getBlendFunc : function ( +) +{ + return cc.BlendFunc; +}, + +/** + * @method getMeshIndexData + * @return {cc.MeshIndexData} + */ +getMeshIndexData : function ( +) +{ + return cc.MeshIndexData; +}, + +/** + * @method setName + * @param {String} arg0 + */ +setName : function ( +str +) +{ +}, + +/** + * @method isVisible + * @return {bool} + */ +isVisible : function ( +) +{ + return false; +}, + +/** + * @method getIndexCount + * @return {long} + */ +getIndexCount : function ( +) +{ + return 0; +}, + +/** + * @method bindMeshCommand + */ +bindMeshCommand : function ( +) +{ +}, + +/** + * @method setMeshIndexData + * @param {cc.MeshIndexData} arg0 + */ +setMeshIndexData : function ( +meshindexdata +) +{ +}, + +/** + * @method getMeshVertexAttribCount + * @return {long} + */ +getMeshVertexAttribCount : function ( +) +{ + return 0; +}, + +/** + * @method setBlendFunc + * @param {cc.BlendFunc} arg0 + */ +setBlendFunc : function ( +blendfunc +) +{ +}, + +/** + * @method getPrimitiveType + * @return {unsigned int} + */ +getPrimitiveType : function ( +) +{ + return 0; +}, + +/** + * @method setSkin + * @param {cc.MeshSkin} arg0 + */ +setSkin : function ( +meshskin +) +{ +}, + +/** + * @method getIndexBuffer + * @return {unsigned int} + */ +getIndexBuffer : function ( +) +{ + return 0; +}, + +/** + * @method setGLProgramState + * @param {cc.GLProgramState} arg0 + */ +setGLProgramState : function ( +glprogramstate +) +{ +}, + +/** + * @method setVisible + * @param {bool} arg0 + */ +setVisible : function ( +bool +) +{ +}, + +/** + * @method Mesh + * @constructor + */ +Mesh : function ( +) +{ +}, + +}; + +/** + * @class Animation3D + */ +jsb.Animation3D = { + +/** + * @method initWithFile + * @param {String} arg0 + * @param {String} arg1 + * @return {bool} + */ +initWithFile : function ( +str, +str +) +{ + return false; +}, + +/** + * @method init + * @param {cc.Animation3DData} arg0 + * @return {bool} + */ +init : function ( +animation3ddata +) +{ + return false; +}, + +/** + * @method getBoneCurveByName + * @param {String} arg0 + * @return {cc.Animation3D::Curve} + */ +getBoneCurveByName : function ( +str +) +{ + return cc.Animation3D::Curve; +}, + +/** + * @method getDuration + * @return {float} + */ +getDuration : function ( +) +{ + return 0; +}, + +/** + * @method create + * @param {String} arg0 + * @param {String} arg1 + * @return {cc.Animation3D} + */ +create : function ( +str, +str +) +{ + return cc.Animation3D; +}, + +/** + * @method Animation3D + * @constructor + */ +Animation3D : function ( +) +{ +}, + +}; + +/** + * @class Animate3D + */ +jsb.Animate3D = { + +/** + * @method getSpeed + * @return {float} + */ +getSpeed : function ( +) +{ + return 0; +}, + +/** + * @method removeFromMap + */ +removeFromMap : function ( +) +{ +}, + +/** + * @method setWeight + * @param {float} arg0 + */ +setWeight : function ( +float +) +{ +}, + +/** + * @method initWithFrames + * @param {cc.Animation3D} arg0 + * @param {int} arg1 + * @param {int} arg2 + * @param {float} arg3 + * @return {bool} + */ +initWithFrames : function ( +animation3d, +int, +int, +float +) +{ + return false; +}, + +/** + * @method getOriginInterval + * @return {float} + */ +getOriginInterval : function ( +) +{ + return 0; +}, + +/** + * @method setSpeed + * @param {float} arg0 + */ +setSpeed : function ( +float +) +{ +}, + +/** + * @method init +* @param {cc.Animation3D|cc.Animation3D} animation3d +* @param {float} float +* @param {float} float +* @return {bool|bool} +*/ +init : function( +animation3d, +float, +float +) +{ + return false; +}, + +/** + * @method setOriginInterval + * @param {float} arg0 + */ +setOriginInterval : function ( +float +) +{ +}, + +/** + * @method getWeight + * @return {float} + */ +getWeight : function ( +) +{ + return 0; +}, + +/** + * @method create +* @param {cc.Animation3D|cc.Animation3D} animation3d +* @param {float} float +* @param {float} float +* @return {cc.Animate3D|cc.Animate3D} +*/ +create : function( +animation3d, +float, +float +) +{ + return cc.Animate3D; +}, + +/** + * @method getTransitionTime + * @return {float} + */ +getTransitionTime : function ( +) +{ + return 0; +}, + +/** + * @method createWithFrames + * @param {cc.Animation3D} arg0 + * @param {int} arg1 + * @param {int} arg2 + * @param {float} arg3 + * @return {cc.Animate3D} + */ +createWithFrames : function ( +animation3d, +int, +int, +float +) +{ + return cc.Animate3D; +}, + +/** + * @method setTransitionTime + * @param {float} arg0 + */ +setTransitionTime : function ( +float +) +{ +}, + +/** + * @method Animate3D + * @constructor + */ +Animate3D : function ( +) +{ +}, + +}; + +/** + * @class AttachNode + */ +jsb.AttachNode = { + +/** + * @method create + * @param {cc.Bone3D} arg0 + * @return {cc.AttachNode} + */ +create : function ( +bone3d +) +{ + return cc.AttachNode; +}, + +/** + * @method AttachNode + * @constructor + */ +AttachNode : function ( +) +{ +}, + +}; + +/** + * @class BillBoard + */ +jsb.BillBoard = { + +/** + * @method getMode + * @return {cc.BillBoard::Mode} + */ +getMode : function ( +) +{ + return 0; +}, + +/** + * @method setMode + * @param {cc.BillBoard::Mode} arg0 + */ +setMode : function ( +mode +) +{ +}, + +/** + * @method create +* @param {String|cc.BillBoard::Mode|String} str +* @param {cc.BillBoard::Mode|rect_object} mode +* @param {cc.BillBoard::Mode} mode +* @return {cc.BillBoard|cc.BillBoard|cc.BillBoard} +*/ +create : function( +str, +rect, +mode +) +{ + return cc.BillBoard; +}, + +/** + * @method createWithTexture + * @param {cc.Texture2D} arg0 + * @param {cc.BillBoard::Mode} arg1 + * @return {cc.BillBoard} + */ +createWithTexture : function ( +texture2d, +mode +) +{ + return cc.BillBoard; +}, + +/** + * @method BillBoard + * @constructor + */ +BillBoard : function ( +) +{ +}, + +}; diff --git a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_3d_extension_auto_api.js b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_3d_extension_auto_api.js new file mode 100644 index 0000000000..a10423dfbd --- /dev/null +++ b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_3d_extension_auto_api.js @@ -0,0 +1,496 @@ +/** + * @module cocos2dx_3d_extension + */ +var jsb = jsb || {}; + +/** + * @class ParticleSystem3D + */ +jsb.ParticleSystem3D = { + +/** + * @method resumeParticleSystem + */ +resumeParticleSystem : function ( +) +{ +}, + +/** + * @method startParticleSystem + */ +startParticleSystem : function ( +) +{ +}, + +/** + * @method isEnabled + * @return {bool} + */ +isEnabled : function ( +) +{ + return false; +}, + +/** + * @method isKeepLocal + * @return {bool} + */ +isKeepLocal : function ( +) +{ + return false; +}, + +/** + * @method setEnabled + * @param {bool} arg0 + */ +setEnabled : function ( +bool +) +{ +}, + +/** + * @method getParticleQuota + * @return {unsigned int} + */ +getParticleQuota : function ( +) +{ + return 0; +}, + +/** + * @method getBlendFunc + * @return {cc.BlendFunc} + */ +getBlendFunc : function ( +) +{ + return cc.BlendFunc; +}, + +/** + * @method pauseParticleSystem + */ +pauseParticleSystem : function ( +) +{ +}, + +/** + * @method getState + * @return {cc.ParticleSystem3D::State} + */ +getState : function ( +) +{ + return 0; +}, + +/** + * @method getAliveParticleCount + * @return {int} + */ +getAliveParticleCount : function ( +) +{ + return 0; +}, + +/** + * @method setParticleQuota + * @param {unsigned int} arg0 + */ +setParticleQuota : function ( +int +) +{ +}, + +/** + * @method setBlendFunc + * @param {cc.BlendFunc} arg0 + */ +setBlendFunc : function ( +blendfunc +) +{ +}, + +/** + * @method stopParticleSystem + */ +stopParticleSystem : function ( +) +{ +}, + +/** + * @method setKeepLocal + * @param {bool} arg0 + */ +setKeepLocal : function ( +bool +) +{ +}, + +/** + * @method ParticleSystem3D + * @constructor + */ +ParticleSystem3D : function ( +) +{ +}, + +}; + +/** + * @class PUParticleSystem3D + */ +jsb.PUParticleSystem3D = { + +/** + * @method getParticleSystemScaleVelocity + * @return {float} + */ +getParticleSystemScaleVelocity : function ( +) +{ + return 0; +}, + +/** + * @method setEmittedSystemQuota + * @param {unsigned int} arg0 + */ +setEmittedSystemQuota : function ( +int +) +{ +}, + +/** + * @method getDefaultDepth + * @return {float} + */ +getDefaultDepth : function ( +) +{ + return 0; +}, + +/** + * @method getEmittedSystemQuota + * @return {unsigned int} + */ +getEmittedSystemQuota : function ( +) +{ + return 0; +}, + +/** + * @method clearAllParticles + */ +clearAllParticles : function ( +) +{ +}, + +/** + * @method getMaterialName + * @return {String} + */ +getMaterialName : function ( +) +{ + return ; +}, + +/** + * @method calulateRotationOffset + */ +calulateRotationOffset : function ( +) +{ +}, + +/** + * @method getMaxVelocity + * @return {float} + */ +getMaxVelocity : function ( +) +{ + return 0; +}, + +/** + * @method forceUpdate + * @param {float} arg0 + */ +forceUpdate : function ( +float +) +{ +}, + +/** + * @method getTimeElapsedSinceStart + * @return {float} + */ +getTimeElapsedSinceStart : function ( +) +{ + return 0; +}, + +/** + * @method getEmittedEmitterQuota + * @return {unsigned int} + */ +getEmittedEmitterQuota : function ( +) +{ + return 0; +}, + +/** + * @method isMarkedForEmission + * @return {bool} + */ +isMarkedForEmission : function ( +) +{ + return false; +}, + +/** + * @method getDefaultWidth + * @return {float} + */ +getDefaultWidth : function ( +) +{ + return 0; +}, + +/** + * @method setEmittedEmitterQuota + * @param {unsigned int} arg0 + */ +setEmittedEmitterQuota : function ( +int +) +{ +}, + +/** + * @method setMarkedForEmission + * @param {bool} arg0 + */ +setMarkedForEmission : function ( +bool +) +{ +}, + +/** + * @method clone + * @return {cc.PUParticleSystem3D} + */ +clone : function ( +) +{ + return cc.PUParticleSystem3D; +}, + +/** + * @method setDefaultWidth + * @param {float} arg0 + */ +setDefaultWidth : function ( +float +) +{ +}, + +/** + * @method copyAttributesTo + * @param {cc.PUParticleSystem3D} arg0 + */ +copyAttributesTo : function ( +puparticlesystem3d +) +{ +}, + +/** + * @method setMaterialName + * @param {String} arg0 + */ +setMaterialName : function ( +str +) +{ +}, + +/** + * @method getParentParticleSystem + * @return {cc.PUParticleSystem3D} + */ +getParentParticleSystem : function ( +) +{ + return cc.PUParticleSystem3D; +}, + +/** + * @method setMaxVelocity + * @param {float} arg0 + */ +setMaxVelocity : function ( +float +) +{ +}, + +/** + * @method getDefaultHeight + * @return {float} + */ +getDefaultHeight : function ( +) +{ + return 0; +}, + +/** + * @method getDerivedPosition + * @return {vec3_object} + */ +getDerivedPosition : function ( +) +{ + return cc.Vec3; +}, + +/** + * @method rotationOffset + * @param {vec3_object} arg0 + */ +rotationOffset : function ( +vec3 +) +{ +}, + +/** + * @method getDerivedOrientation + * @return {cc.Quaternion} + */ +getDerivedOrientation : function ( +) +{ + return cc.Quaternion; +}, + +/** + * @method removeAllEmitter + */ +removeAllEmitter : function ( +) +{ +}, + +/** + * @method setParticleSystemScaleVelocity + * @param {float} arg0 + */ +setParticleSystemScaleVelocity : function ( +float +) +{ +}, + +/** + * @method getDerivedScale + * @return {vec3_object} + */ +getDerivedScale : function ( +) +{ + return cc.Vec3; +}, + +/** + * @method setDefaultHeight + * @param {float} arg0 + */ +setDefaultHeight : function ( +float +) +{ +}, + +/** + * @method removeAllListener + */ +removeAllListener : function ( +) +{ +}, + +/** + * @method initSystem + * @param {String} arg0 + * @return {bool} + */ +initSystem : function ( +str +) +{ + return false; +}, + +/** + * @method setDefaultDepth + * @param {float} arg0 + */ +setDefaultDepth : function ( +float +) +{ +}, + +/** + * @method create +* @param {String|String} str +* @param {String} str +* @return {cc.PUParticleSystem3D|cc.PUParticleSystem3D|cc.PUParticleSystem3D} +*/ +create : function( +str, +str +) +{ + return cc.PUParticleSystem3D; +}, + +/** + * @method PUParticleSystem3D + * @constructor + */ +PUParticleSystem3D : function ( +) +{ +}, + +}; diff --git a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_auto_api.js b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_auto_api.js index 4a7777384b..ea91717974 100644 --- a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_auto_api.js +++ b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_auto_api.js @@ -762,26 +762,6 @@ EventTouch : function ( }; -/** - * @class EventKeyboard - */ -cc.EventKeyboard = { - -/** - * @method EventKeyboard - * @constructor - * @param {cc.EventKeyboard::KeyCode} arg0 - * @param {bool} arg1 - */ -EventKeyboard : function ( -keycode, -bool -) -{ -}, - -}; - /** * @class Node */ @@ -833,6 +813,18 @@ getGLProgram : function ( return cc.GLProgram; }, +/** + * @method updateTransformFromPhysics + * @param {mat4_object} arg0 + * @param {unsigned int} arg1 + */ +updateTransformFromPhysics : function ( +mat4, +int +) +{ +}, + /** * @method getDescription * @return {String} @@ -1066,23 +1058,23 @@ getonEnterTransitionDidFinishCallback : function ( }, /** - * @method getNodeToWorldAffineTransform - * @return {cc.AffineTransform} + * @method isOpacityModifyRGB + * @return {bool} */ -getNodeToWorldAffineTransform : function ( +isOpacityModifyRGB : function ( ) { - return cc.AffineTransform; + return false; }, /** - * @method getNodeToWorldTransform - * @return {mat4_object} + * @method getNodeToWorldAffineTransform + * @return {cc.AffineTransform} */ -getNodeToWorldTransform : function ( +getNodeToWorldAffineTransform : function ( ) { - return cc.Mat4; + return cc.AffineTransform; }, /** @@ -1232,13 +1224,13 @@ getRotationSkewY : function ( }, /** - * @method getNodeToParentAffineTransform - * @return {cc.AffineTransform} + * @method getNodeToWorldTransform + * @return {mat4_object} */ -getNodeToParentAffineTransform : function ( +getNodeToWorldTransform : function ( ) { - return cc.AffineTransform; + return cc.Mat4; }, /** @@ -1282,13 +1274,13 @@ getRotation3D : function ( }, /** - * @method getNodeToParentTransform - * @return {mat4_object} + * @method getNodeToParentAffineTransform + * @return {cc.AffineTransform} */ -getNodeToParentTransform : function ( +getNodeToParentAffineTransform : function ( ) { - return cc.Mat4; + return cc.AffineTransform; }, /** @@ -1443,6 +1435,16 @@ getChildrenCount : function ( return 0; }, +/** + * @method getNodeToParentTransform + * @return {mat4_object} + */ +getNodeToParentTransform : function ( +) +{ + return cc.Mat4; +}, + /** * @method convertToNodeSpaceAR * @param {vec2_object} arg0 @@ -1479,6 +1481,20 @@ action return cc.Action; }, +/** + * @method visit +* @param {cc.Renderer} renderer +* @param {mat4_object} mat4 +* @param {unsigned int} int +*/ +visit : function( +renderer, +mat4, +int +) +{ +}, + /** * @method setGLProgram * @param {cc.GLProgram} arg0 @@ -1510,17 +1526,13 @@ getAnchorPointInPoints : function ( }, /** - * @method visit -* @param {cc.Renderer} renderer -* @param {mat4_object} mat4 -* @param {unsigned int} int -*/ -visit : function( -renderer, -mat4, -int + * @method getRotationQuat + * @return {cc.Quaternion} + */ +getRotationQuat : function ( ) { + return cc.Quaternion; }, /** @@ -1658,11 +1670,17 @@ str }, /** - * @method setAdditionalTransform -* @param {cc.AffineTransform|mat4_object} affinetransform -*/ -setAdditionalTransform : function( -mat4 + * @method updatePhysicsBodyTransform + * @param {mat4_object} arg0 + * @param {unsigned int} arg1 + * @param {float} arg2 + * @param {float} arg3 + */ +updatePhysicsBodyTransform : function ( +mat4, +int, +float, +float ) { }, @@ -1697,16 +1715,6 @@ getScheduler : function( return cc.Scheduler; }, -/** - * @method getParentToNodeAffineTransform - * @return {cc.AffineTransform} - */ -getParentToNodeAffineTransform : function ( -) -{ - return cc.AffineTransform; -}, - /** * @method getOrderOfArrival * @return {int} @@ -1760,6 +1768,16 @@ getParent : function( return cc.Node; }, +/** + * @method getWorldToNodeTransform + * @return {mat4_object} + */ +getWorldToNodeTransform : function ( +) +{ + return cc.Mat4; +}, + /** * @method getPositionY * @return {float} @@ -1823,13 +1841,13 @@ bool }, /** - * @method getParentToNodeTransform - * @return {mat4_object} + * @method getParentToNodeAffineTransform + * @return {cc.AffineTransform} */ -getParentToNodeTransform : function ( +getParentToNodeAffineTransform : function ( ) { - return cc.Mat4; + return cc.AffineTransform; }, /** @@ -1936,16 +1954,6 @@ int { }, -/** - * @method getWorldToNodeAffineTransform - * @return {cc.AffineTransform} - */ -getWorldToNodeAffineTransform : function ( -) -{ - return cc.AffineTransform; -}, - /** * @method setCascadeColorEnabled * @param {bool} arg0 @@ -2121,13 +2129,13 @@ sortAllChildren : function ( }, /** - * @method getWorldToNodeTransform - * @return {mat4_object} + * @method getWorldToNodeAffineTransform + * @return {cc.AffineTransform} */ -getWorldToNodeTransform : function ( +getWorldToNodeAffineTransform : function ( ) { - return cc.Mat4; + return cc.AffineTransform; }, /** @@ -2150,6 +2158,16 @@ getNormalizedPosition : function ( return cc.Vec2; }, +/** + * @method getParentToNodeTransform + * @return {mat4_object} + */ +getParentToNodeTransform : function ( +) +{ + return cc.Mat4; +}, + /** * @method convertToNodeSpace * @param {vec2_object} arg0 @@ -2183,13 +2201,13 @@ isCascadeColorEnabled : function ( }, /** - * @method isOpacityModifyRGB - * @return {bool} + * @method setRotationQuat + * @param {cc.Quaternion} arg0 */ -isOpacityModifyRGB : function ( +setRotationQuat : function ( +quaternion ) { - return false; }, /** @@ -2264,6 +2282,14 @@ initWithPhysics : function ( return false; }, +/** + * @method setCameraOrderDirty + */ +setCameraOrderDirty : function ( +) +{ +}, + /** * @method render * @param {cc.Renderer} arg0 @@ -2284,16 +2310,6 @@ eventcustom { }, -/** - * @method init - * @return {bool} - */ -init : function ( -) -{ - return false; -}, - /** * @method getPhysicsWorld * @return {cc.PhysicsWorld} @@ -2316,6 +2332,16 @@ size return false; }, +/** + * @method getDefaultCamera + * @return {cc.Camera} + */ +getDefaultCamera : function ( +) +{ + return cc.Camera; +}, + /** * @method createWithSize * @param {size_object} arg0 @@ -2454,6 +2480,16 @@ isOpenGLReady : function ( return false; }, +/** + * @method setCursorVisible + * @param {bool} arg0 + */ +setCursorVisible : function ( +bool +) +{ +}, + /** * @method getScaleY * @return {float} @@ -3023,6 +3059,16 @@ isNextDeltaTimeZero : function ( return false; }, +/** + * @method setClearColor + * @param {color4f_object} arg0 + */ +setClearColor : function ( +color4f +) +{ +}, + /** * @method setOpenGLView * @param {cc.GLView} arg0 @@ -3306,6 +3352,16 @@ float { }, +/** + * @method update + * @param {float} arg0 + */ +update : function ( +float +) +{ +}, + /** * @method performFunctionInCocosThread * @param {function} arg0 @@ -3590,6 +3646,16 @@ str return ; }, +/** + * @method setWritablePath + * @param {String} arg0 + */ +setWritablePath : function ( +str +) +{ +}, + /** * @method setPopupNotify * @param {bool} arg0 @@ -3612,6 +3678,16 @@ str return false; }, +/** + * @method setDefaultResourceRootPath + * @param {String} arg0 + */ +setDefaultResourceRootPath : function ( +str +) +{ +}, + /** * @method getSearchResolutionsOrder * @return {Array} @@ -3644,6 +3720,16 @@ getWritablePath : function ( return ; }, +/** + * @method setDelegate + * @param {cc.FileUtils} arg0 + */ +setDelegate : function ( +fileutils +) +{ +}, + /** * @method getInstance * @return {cc.FileUtils} @@ -4310,16 +4396,6 @@ init : function ( return false; }, -/** - * @method create - * @return {cc.EventListenerFocus} - */ -create : function ( -) -{ - return cc.EventListenerFocus; -}, - /** * @method EventListenerFocus * @constructor @@ -5593,12 +5669,12 @@ cc.MoveBy = { /** * @method initWithDuration - * @param {float} arg0 - * @param {vec2_object} arg1 - * @return {bool} - */ -initWithDuration : function ( -float, +* @param {float|float} float +* @param {vec3_object|vec2_object} vec3 +* @return {bool|bool} +*/ +initWithDuration : function( +float, vec2 ) { @@ -5607,12 +5683,12 @@ vec2 /** * @method create - * @param {float} arg0 - * @param {vec2_object} arg1 - * @return {cc.MoveBy} - */ -create : function ( -float, +* @param {float|float} float +* @param {vec3_object|vec2_object} vec3 +* @return {cc.MoveBy|cc.MoveBy} +*/ +create : function( +float, vec2 ) { @@ -5637,12 +5713,12 @@ cc.MoveTo = { /** * @method initWithDuration - * @param {float} arg0 - * @param {vec2_object} arg1 - * @return {bool} - */ -initWithDuration : function ( -float, +* @param {float|float} float +* @param {vec3_object|vec2_object} vec3 +* @return {bool|bool} +*/ +initWithDuration : function( +float, vec2 ) { @@ -5651,12 +5727,12 @@ vec2 /** * @method create - * @param {float} arg0 - * @param {vec2_object} arg1 - * @return {cc.MoveTo} - */ -create : function ( -float, +* @param {float|float} float +* @param {vec3_object|vec2_object} vec3 +* @return {cc.MoveTo|cc.MoveTo} +*/ +create : function( +float, vec2 ) { @@ -5827,6 +5903,24 @@ JumpBy : function ( */ cc.JumpTo = { +/** + * @method initWithDuration + * @param {float} arg0 + * @param {vec2_object} arg1 + * @param {float} arg2 + * @param {int} arg3 + * @return {bool} + */ +initWithDuration : function ( +float, +vec2, +float, +int +) +{ + return false; +}, + /** * @method create * @param {float} arg0 @@ -6163,16 +6257,16 @@ char /** * @method create - * @param {float} arg0 - * @param {unsigned char} arg1 - * @param {unsigned char} arg2 - * @param {unsigned char} arg3 - * @return {cc.TintTo} - */ -create : function ( -float, -char, -char, +* @param {float|float} float +* @param {color3b_object|unsigned char} color3b +* @param {unsigned char} char +* @param {unsigned char} char +* @return {cc.TintTo|cc.TintTo} +*/ +create : function( +float, +char, +char, char ) { @@ -8167,16 +8261,6 @@ size */ cc.Grid3DAction = { -/** - * @method getGrid - * @return {cc.GridBase} - */ -getGrid : function ( -) -{ - return cc.GridBase; -}, - }; /** @@ -8184,16 +8268,6 @@ getGrid : function ( */ cc.TiledGrid3DAction = { -/** - * @method getGrid - * @return {cc.GridBase} - */ -getGrid : function ( -) -{ - return cc.GridBase; -}, - }; /** @@ -9023,16 +9097,6 @@ Twirl : function ( */ cc.PageTurn3D = { -/** - * @method getGrid - * @return {cc.GridBase} - */ -getGrid : function ( -) -{ - return cc.GridBase; -}, - /** * @method create * @param {float} arg0 @@ -9440,18 +9504,6 @@ FadeOutBLTiles : function ( */ cc.FadeOutUpTiles = { -/** - * @method transformTile - * @param {vec2_object} arg0 - * @param {float} arg1 - */ -transformTile : function ( -vec2, -float -) -{ -}, - /** * @method create * @param {float} arg0 @@ -10275,26 +10327,6 @@ mat4 { }, -/** - * @method setVertexAttribPointer - * @param {String} arg0 - * @param {int} arg1 - * @param {unsigned int} arg2 - * @param {unsigned char} arg3 - * @param {int} arg4 - * @param {void} arg5 - */ -setVertexAttribPointer : function ( -str, -int, -int, -char, -int, -void -) -{ -}, - /** * @method getGLProgram * @return {cc.GLProgram} @@ -10522,13 +10554,15 @@ color4f /** * @method drawPoints - * @param {vec2_object} arg0 - * @param {unsigned int} arg1 - * @param {color4f_object} arg2 - */ -drawPoints : function ( -vec2, -int, +* @param {vec2_object|vec2_object} vec2 +* @param {unsigned int|unsigned int} int +* @param {float|color4f_object} float +* @param {color4f_object} color4f +*/ +drawPoints : function( +vec2, +int, +float, color4f ) { @@ -10586,16 +10620,6 @@ int { }, -/** - * @method init - * @return {bool} - */ -init : function ( -) -{ - return false; -}, - /** * @method drawDot * @param {vec2_object} arg0 @@ -10900,14 +10924,6 @@ int return false; }, -/** - * @method updateAtlasValues - */ -updateAtlasValues : function ( -) -{ -}, - /** * @method getString * @return {String} @@ -11291,71 +11307,65 @@ sprite }, /** - * @method reorderBatch - * @param {bool} arg0 + * @method addSpriteWithoutQuad + * @param {cc.Sprite} arg0 + * @param {int} arg1 + * @param {int} arg2 + * @return {cc.SpriteBatchNode} */ -reorderBatch : function ( -bool +addSpriteWithoutQuad : function ( +sprite, +int, +int ) { + return cc.SpriteBatchNode; }, /** - * @method getTexture - * @return {cc.Texture2D} + * @method reorderBatch + * @param {bool} arg0 */ -getTexture : function ( +reorderBatch : function ( +bool ) { - return cc.Texture2D; }, /** - * @method setTexture + * @method initWithTexture * @param {cc.Texture2D} arg0 + * @param {long} arg1 + * @return {bool} */ -setTexture : function ( -texture2d +initWithTexture : function ( +texture2d, +long ) { + return false; }, /** - * @method removeChildAtIndex - * @param {long} arg0 - * @param {bool} arg1 + * @method getBlendFunc + * @return {cc.BlendFunc} */ -removeChildAtIndex : function ( -long, -bool +getBlendFunc : function ( ) { + return cc.BlendFunc; }, /** - * @method removeSpriteFromAtlas + * @method lowestAtlasIndexInChild * @param {cc.Sprite} arg0 + * @return {long} */ -removeSpriteFromAtlas : function ( +lowestAtlasIndexInChild : function ( sprite ) { -}, - -/** - * @method addSpriteWithoutQuad - * @param {cc.Sprite} arg0 - * @param {int} arg1 - * @param {int} arg2 - * @return {cc.SpriteBatchNode} - */ -addSpriteWithoutQuad : function ( -sprite, -int, -int -) -{ - return cc.SpriteBatchNode; + return 0; }, /** @@ -11373,67 +11383,55 @@ int }, /** - * @method increaseAtlasCapacity + * @method setTextureAtlas + * @param {cc.TextureAtlas} arg0 */ -increaseAtlasCapacity : function ( +setTextureAtlas : function ( +textureatlas ) { }, /** - * @method init + * @method initWithFile + * @param {String} arg0 + * @param {long} arg1 * @return {bool} */ -init : function ( +initWithFile : function ( +str, +long ) { return false; }, /** - * @method lowestAtlasIndexInChild - * @param {cc.Sprite} arg0 - * @return {long} + * @method getTexture + * @return {cc.Texture2D} */ -lowestAtlasIndexInChild : function ( -sprite +getTexture : function ( ) { - return 0; + return cc.Texture2D; }, /** - * @method getBlendFunc - * @return {cc.BlendFunc} + * @method increaseAtlasCapacity */ -getBlendFunc : function ( +increaseAtlasCapacity : function ( ) { - return cc.BlendFunc; }, /** - * @method initWithTexture - * @param {cc.Texture2D} arg0 - * @param {long} arg1 - * @return {bool} + * @method getTextureAtlas + * @return {cc.TextureAtlas} */ -initWithTexture : function ( -texture2d, -long -) -{ - return false; -}, - -/** - * @method setTextureAtlas - * @param {cc.TextureAtlas} arg0 - */ -setTextureAtlas : function ( -textureatlas +getTextureAtlas : function ( ) { + return cc.TextureAtlas; }, /** @@ -11449,63 +11447,71 @@ long }, /** - * @method initWithFile - * @param {String} arg0 - * @param {long} arg1 - * @return {bool} + * @method setTexture + * @param {cc.Texture2D} arg0 */ -initWithFile : function ( -str, -long +setTexture : function ( +texture2d ) { - return false; }, /** - * @method setBlendFunc - * @param {cc.BlendFunc} arg0 + * @method rebuildIndexInOrder + * @param {cc.Sprite} arg0 + * @param {long} arg1 + * @return {long} */ -setBlendFunc : function ( -blendfunc +rebuildIndexInOrder : function ( +sprite, +long ) { + return 0; }, /** - * @method rebuildIndexInOrder + * @method highestAtlasIndexInChild * @param {cc.Sprite} arg0 - * @param {long} arg1 * @return {long} */ -rebuildIndexInOrder : function ( -sprite, -long +highestAtlasIndexInChild : function ( +sprite ) { return 0; }, /** - * @method getTextureAtlas - * @return {cc.TextureAtlas} + * @method removeChildAtIndex + * @param {long} arg0 + * @param {bool} arg1 */ -getTextureAtlas : function ( +removeChildAtIndex : function ( +long, +bool ) { - return cc.TextureAtlas; }, /** - * @method highestAtlasIndexInChild + * @method removeSpriteFromAtlas * @param {cc.Sprite} arg0 - * @return {long} */ -highestAtlasIndexInChild : function ( +removeSpriteFromAtlas : function ( sprite ) { - return 0; +}, + +/** + * @method setBlendFunc + * @param {cc.BlendFunc} arg0 + */ +setBlendFunc : function ( +blendfunc +) +{ }, /** @@ -11572,12 +11578,12 @@ enableShadow : function ( /** * @method setDimensions - * @param {unsigned int} arg0 - * @param {unsigned int} arg1 + * @param {float} arg0 + * @param {float} arg1 */ setDimensions : function ( -int, -int +float, +float ) { }, @@ -11594,7 +11600,7 @@ getString : function ( /** * @method getHeight - * @return {unsigned int} + * @return {float} */ getHeight : function ( ) @@ -11622,17 +11628,17 @@ getTextColor : function ( /** * @method setWidth - * @param {unsigned int} arg0 + * @param {float} arg0 */ setWidth : function ( -int +float ) { }, /** * @method getMaxLineWidth - * @return {unsigned int} + * @return {float} */ getMaxLineWidth : function ( ) @@ -11804,10 +11810,10 @@ getDimensions : function ( /** * @method setMaxLineWidth - * @param {unsigned int} arg0 + * @param {float} arg0 */ setMaxLineWidth : function ( -int +float ) { }, @@ -11874,17 +11880,17 @@ color4b /** * @method setHeight - * @param {unsigned int} arg0 + * @param {float} arg0 */ setHeight : function ( -int +float ) { }, /** * @method getWidth - * @return {unsigned int} + * @return {float} */ getWidth : function ( ) @@ -12090,16 +12096,6 @@ getBlendFunc : function ( return cc.BlendFunc; }, -/** - * @method isOpacityModifyRGB - * @return {bool} - */ -isOpacityModifyRGB : function ( -) -{ - return false; -}, - /** * @method getLetter * @param {int} arg0 @@ -12162,16 +12158,6 @@ vec2 return false; }, -/** - * @method setOpacityModifyRGB - * @param {bool} arg0 - */ -setOpacityModifyRGB : function ( -bool -) -{ -}, - /** * @method getFntFile * @return {String} @@ -12349,7 +12335,7 @@ float * @param {color4b_object|color4b_object} color4b * @param {float} float * @param {float} float -* @return {bool|bool|bool} +* @return {bool|bool} */ initWithColor : function( color4b, @@ -12482,16 +12468,6 @@ getVector : function ( return cc.Vec2; }, -/** - * @method init - * @return {bool} - */ -init : function ( -) -{ - return false; -}, - /** * @method setEndColor * @param {color3b_object} arg0 @@ -12592,16 +12568,6 @@ array return false; }, -/** - * @method init - * @return {bool} - */ -init : function ( -) -{ - return false; -}, - /** * @method switchToAndReleaseMe * @param {int} arg0 @@ -13029,16 +12995,6 @@ TransitionSlideInL : function ( */ cc.TransitionSlideInR = { -/** - * @method action - * @return {cc.ActionInterval} - */ -action : function ( -) -{ - return cc.ActionInterval; -}, - /** * @method create * @param {float} arg0 @@ -13069,16 +13025,6 @@ TransitionSlideInR : function ( */ cc.TransitionSlideInB = { -/** - * @method action - * @return {cc.ActionInterval} - */ -action : function ( -) -{ - return cc.ActionInterval; -}, - /** * @method create * @param {float} arg0 @@ -13109,16 +13055,6 @@ TransitionSlideInB : function ( */ cc.TransitionSlideInT = { -/** - * @method action - * @return {cc.ActionInterval} - */ -action : function ( -) -{ - return cc.ActionInterval; -}, - /** * @method create * @param {float} arg0 @@ -14631,16 +14567,6 @@ isEnabled : function ( return false; }, -/** - * @method init - * @return {bool} - */ -init : function ( -) -{ - return false; -}, - /** * @method alignItemsHorizontallyWithPadding * @param {float} arg0 @@ -14725,18 +14651,6 @@ getAlphaThreshold : function ( return 0; }, -/** - * @method init -* @param {cc.Node} node -* @return {bool|bool} -*/ -init : function( -node -) -{ - return false; -}, - /** * @method getStencil * @return {cc.Node} @@ -15179,18 +15093,6 @@ float { }, -/** - * @method initWithSpriteFrameName - * @param {String} arg0 - * @return {bool} - */ -initWithSpriteFrameName : function ( -str -) -{ - return false; -}, - /** * @method initWithTexture * @param {cc.Texture2D|cc.Texture2D|cc.Texture2D} texture2d @@ -15237,14 +15139,6 @@ bool { }, -/** - * @method updateTransform - */ -updateTransform : function ( -) -{ -}, - /** * @method setTextureRect * @param {rect_object|rect_object} rect @@ -15260,10 +15154,12 @@ size }, /** - * @method init + * @method initWithSpriteFrameName + * @param {String} arg0 * @return {bool} */ -init : function ( +initWithSpriteFrameName : function ( +str ) { return false; @@ -15535,65 +15431,259 @@ Sprite : function ( }; /** - * @class RenderTexture + * @class Image */ -cc.RenderTexture = { +cc.Image = { /** - * @method setVirtualViewport - * @param {vec2_object} arg0 - * @param {rect_object} arg1 - * @param {rect_object} arg2 + * @method hasPremultipliedAlpha + * @return {bool} */ -setVirtualViewport : function ( -vec2, -rect, -rect +hasPremultipliedAlpha : function ( ) { + return false; }, /** - * @method clearStencil - * @param {int} arg0 + * @method getDataLen + * @return {long} */ -clearStencil : function ( -int +getDataLen : function ( ) { + return 0; }, /** - * @method getClearDepth - * @return {float} + * @method saveToFile + * @param {String} arg0 + * @param {bool} arg1 + * @return {bool} */ -getClearDepth : function ( +saveToFile : function ( +str, +bool ) { - return 0; + return false; }, /** - * @method getClearStencil - * @return {int} + * @method hasAlpha + * @return {bool} */ -getClearStencil : function ( +hasAlpha : function ( ) { - return 0; + return false; }, /** - * @method end + * @method isCompressed + * @return {bool} */ -end : function ( +isCompressed : function ( ) { + return false; }, /** - * @method setClearStencil - * @param {int} arg0 + * @method getHeight + * @return {int} + */ +getHeight : function ( +) +{ + return 0; +}, + +/** + * @method initWithImageFile + * @param {String} arg0 + * @return {bool} + */ +initWithImageFile : function ( +str +) +{ + return false; +}, + +/** + * @method getWidth + * @return {int} + */ +getWidth : function ( +) +{ + return 0; +}, + +/** + * @method getBitPerPixel + * @return {int} + */ +getBitPerPixel : function ( +) +{ + return 0; +}, + +/** + * @method getFileType + * @return {cc.Image::Format} + */ +getFileType : function ( +) +{ + return 0; +}, + +/** + * @method getNumberOfMipmaps + * @return {int} + */ +getNumberOfMipmaps : function ( +) +{ + return 0; +}, + +/** + * @method getRenderFormat + * @return {cc.Texture2D::PixelFormat} + */ +getRenderFormat : function ( +) +{ + return 0; +}, + +/** + * @method getData + * @return {unsigned char} + */ +getData : function ( +) +{ + return 0; +}, + +/** + * @method getMipmaps + * @return {cc._MipmapInfo} + */ +getMipmaps : function ( +) +{ + return cc._MipmapInfo; +}, + +/** + * @method initWithRawData + * @param {unsigned char} arg0 + * @param {long} arg1 + * @param {int} arg2 + * @param {int} arg3 + * @param {int} arg4 + * @param {bool} arg5 + * @return {bool} + */ +initWithRawData : function ( +char, +long, +int, +int, +int, +bool +) +{ + return false; +}, + +/** + * @method setPVRImagesHavePremultipliedAlpha + * @param {bool} arg0 + */ +setPVRImagesHavePremultipliedAlpha : function ( +bool +) +{ +}, + +/** + * @method Image + * @constructor + */ +Image : function ( +) +{ +}, + +}; + +/** + * @class RenderTexture + */ +cc.RenderTexture = { + +/** + * @method setVirtualViewport + * @param {vec2_object} arg0 + * @param {rect_object} arg1 + * @param {rect_object} arg2 + */ +setVirtualViewport : function ( +vec2, +rect, +rect +) +{ +}, + +/** + * @method clearStencil + * @param {int} arg0 + */ +clearStencil : function ( +int +) +{ +}, + +/** + * @method getClearDepth + * @return {float} + */ +getClearDepth : function ( +) +{ + return 0; +}, + +/** + * @method getClearStencil + * @return {int} + */ +getClearStencil : function ( +) +{ + return 0; +}, + +/** + * @method end + */ +end : function ( +) +{ +}, + +/** + * @method setClearStencil + * @param {int} arg0 */ setClearStencil : function ( int @@ -16157,16 +16247,6 @@ getRadialAccelVar : function ( return 0; }, -/** - * @method init - * @return {bool} - */ -init : function ( -) -{ - return false; -}, - /** * @method getEndSizeVar * @return {float} @@ -16177,16 +16257,6 @@ getEndSizeVar : function ( return 0; }, -/** - * @method setRotation - * @param {float} arg0 - */ -setRotation : function ( -float -) -{ -}, - /** * @method setTangentialAccel * @param {float} arg0 @@ -16197,26 +16267,6 @@ float { }, -/** - * @method setScaleY - * @param {float} arg0 - */ -setScaleY : function ( -float -) -{ -}, - -/** - * @method setScaleX - * @param {float} arg0 - */ -setScaleX : function ( -float -) -{ -}, - /** * @method getRadialAccel * @return {float} @@ -16545,16 +16595,6 @@ getEndRadius : function ( return 0; }, -/** - * @method isOpacityModifyRGB - * @return {bool} - */ -isOpacityModifyRGB : function ( -) -{ - return false; -}, - /** * @method isActive * @return {bool} @@ -16895,16 +16935,6 @@ getRotationIsDir : function ( return false; }, -/** - * @method setScale - * @param {float} arg0 - */ -setScale : function ( -float -) -{ -}, - /** * @method getEmissionRate * @return {float} @@ -16945,16 +16975,6 @@ float { }, -/** - * @method setOpacityModifyRGB - * @param {bool} arg0 - */ -setOpacityModifyRGB : function ( -bool -) -{ -}, - /** * @method addParticle * @return {bool} @@ -17221,16 +17241,6 @@ ParticleSystemQuad : function ( */ cc.ParticleFire = { -/** - * @method init - * @return {bool} - */ -init : function ( -) -{ - return false; -}, - /** * @method create * @return {cc.ParticleFire} @@ -18034,87 +18044,520 @@ int }, /** - * @method isActive - * @return {bool} + * @method isActive + * @return {bool} + */ +isActive : function ( +) +{ + return false; +}, + +/** + * @method reuse + */ +reuse : function ( +) +{ +}, + +/** + * @method create +* @param {size_object|size_object} size +* @param {cc.Texture2D} texture2d +* @param {bool} bool +* @return {cc.GridBase|cc.GridBase} +*/ +create : function( +size, +texture2d, +bool +) +{ + return cc.GridBase; +}, + +}; + +/** + * @class Grid3D + */ +cc.Grid3D = { + +/** + * @method getNeedDepthTestForBlit + * @return {bool} + */ +getNeedDepthTestForBlit : function ( +) +{ + return false; +}, + +/** + * @method setNeedDepthTestForBlit + * @param {bool} arg0 + */ +setNeedDepthTestForBlit : function ( +bool +) +{ +}, + +/** + * @method create +* @param {size_object|size_object} size +* @param {cc.Texture2D} texture2d +* @param {bool} bool +* @return {cc.Grid3D|cc.Grid3D} +*/ +create : function( +size, +texture2d, +bool +) +{ + return cc.Grid3D; +}, + +/** + * @method Grid3D + * @constructor + */ +Grid3D : function ( +) +{ +}, + +}; + +/** + * @class TiledGrid3D + */ +cc.TiledGrid3D = { + +/** + * @method create +* @param {size_object|size_object} size +* @param {cc.Texture2D} texture2d +* @param {bool} bool +* @return {cc.TiledGrid3D|cc.TiledGrid3D} +*/ +create : function( +size, +texture2d, +bool +) +{ + return cc.TiledGrid3D; +}, + +/** + * @method TiledGrid3D + * @constructor + */ +TiledGrid3D : function ( +) +{ +}, + +}; + +/** + * @class Camera + */ +cc.Camera = { + +/** + * @method setScene + * @param {cc.Scene} arg0 + */ +setScene : function ( +scene +) +{ +}, + +/** + * @method initPerspective + * @param {float} arg0 + * @param {float} arg1 + * @param {float} arg2 + * @param {float} arg3 + * @return {bool} + */ +initPerspective : function ( +float, +float, +float, +float +) +{ + return false; +}, + +/** + * @method getProjectionMatrix + * @return {mat4_object} + */ +getProjectionMatrix : function ( +) +{ + return cc.Mat4; +}, + +/** + * @method getViewProjectionMatrix + * @return {mat4_object} + */ +getViewProjectionMatrix : function ( +) +{ + return cc.Mat4; +}, + +/** + * @method getViewMatrix + * @return {mat4_object} + */ +getViewMatrix : function ( +) +{ + return cc.Mat4; +}, + +/** + * @method getCameraFlag + * @return {cc.CameraFlag} + */ +getCameraFlag : function ( +) +{ + return 0; +}, + +/** + * @method getType + * @return {cc.Camera::Type} + */ +getType : function ( +) +{ + return 0; +}, + +/** + * @method initDefault + * @return {bool} + */ +initDefault : function ( +) +{ + return false; +}, + +/** + * @method project + * @param {vec3_object} arg0 + * @return {vec2_object} + */ +project : function ( +vec3 +) +{ + return cc.Vec2; +}, + +/** + * @method getDepthInView + * @param {mat4_object} arg0 + * @return {float} + */ +getDepthInView : function ( +mat4 +) +{ + return 0; +}, + +/** + * @method lookAt + * @param {vec3_object} arg0 + * @param {vec3_object} arg1 + */ +lookAt : function ( +vec3, +vec3 +) +{ +}, + +/** + * @method setCameraFlag + * @param {cc.CameraFlag} arg0 + */ +setCameraFlag : function ( +cameraflag +) +{ +}, + +/** + * @method initOrthographic + * @param {float} arg0 + * @param {float} arg1 + * @param {float} arg2 + * @param {float} arg3 + * @return {bool} + */ +initOrthographic : function ( +float, +float, +float, +float +) +{ + return false; +}, + +/** + * @method setAdditionalProjection + * @param {mat4_object} arg0 + */ +setAdditionalProjection : function ( +mat4 +) +{ +}, + +/** + * @method getDepth + * @return {int} + */ +getDepth : function ( +) +{ + return 0; +}, + +/** + * @method setDepth + * @param {int} arg0 + */ +setDepth : function ( +int +) +{ +}, + +/** + * @method create + * @return {cc.Camera} + */ +create : function ( +) +{ + return cc.Camera; +}, + +/** + * @method createPerspective + * @param {float} arg0 + * @param {float} arg1 + * @param {float} arg2 + * @param {float} arg3 + * @return {cc.Camera} + */ +createPerspective : function ( +float, +float, +float, +float +) +{ + return cc.Camera; +}, + +/** + * @method createOrthographic + * @param {float} arg0 + * @param {float} arg1 + * @param {float} arg2 + * @param {float} arg3 + * @return {cc.Camera} + */ +createOrthographic : function ( +float, +float, +float, +float +) +{ + return cc.Camera; +}, + +/** + * @method getDefaultCamera + * @return {cc.Camera} + */ +getDefaultCamera : function ( +) +{ + return cc.Camera; +}, + +/** + * @method getVisitingCamera + * @return {cc.Camera} + */ +getVisitingCamera : function ( +) +{ + return cc.Camera; +}, + +/** + * @method Camera + * @constructor + */ +Camera : function ( +) +{ +}, + +}; + +/** + * @class BaseLight + */ +cc.BaseLight = { + +/** + * @method setEnabled + * @param {bool} arg0 + */ +setEnabled : function ( +bool +) +{ +}, + +/** + * @method getIntensity + * @return {float} + */ +getIntensity : function ( +) +{ + return 0; +}, + +/** + * @method isEnabled + * @return {bool} + */ +isEnabled : function ( +) +{ + return false; +}, + +/** + * @method getLightType + * @return {cc.LightType} + */ +getLightType : function ( +) +{ + return 0; +}, + +/** + * @method setLightFlag + * @param {cc.LightFlag} arg0 */ -isActive : function ( +setLightFlag : function ( +lightflag ) { - return false; }, /** - * @method reuse + * @method setIntensity + * @param {float} arg0 */ -reuse : function ( +setIntensity : function ( +float ) { }, /** - * @method create -* @param {size_object|size_object} size -* @param {cc.Texture2D} texture2d -* @param {bool} bool -* @return {cc.GridBase|cc.GridBase} -*/ -create : function( -size, -texture2d, -bool + * @method getLightFlag + * @return {cc.LightFlag} + */ +getLightFlag : function ( ) { - return cc.GridBase; + return 0; }, }; /** - * @class Grid3D + * @class DirectionLight */ -cc.Grid3D = { +cc.DirectionLight = { /** - * @method getNeedDepthTestForBlit - * @return {bool} + * @method getDirection + * @return {vec3_object} */ -getNeedDepthTestForBlit : function ( +getDirection : function ( ) { - return false; + return cc.Vec3; }, /** - * @method setNeedDepthTestForBlit - * @param {bool} arg0 + * @method getDirectionInWorld + * @return {vec3_object} */ -setNeedDepthTestForBlit : function ( -bool +getDirectionInWorld : function ( +) +{ + return cc.Vec3; +}, + +/** + * @method setDirection + * @param {vec3_object} arg0 + */ +setDirection : function ( +vec3 ) { }, /** * @method create -* @param {size_object|size_object} size -* @param {cc.Texture2D} texture2d -* @param {bool} bool -* @return {cc.Grid3D|cc.Grid3D} -*/ -create : function( -size, -texture2d, -bool + * @param {vec3_object} arg0 + * @param {color3b_object} arg1 + * @return {cc.DirectionLight} + */ +create : function ( +vec3, +color3b ) { - return cc.Grid3D; + return cc.DirectionLight; }, /** - * @method Grid3D + * @method DirectionLight * @constructor */ -Grid3D : function ( +DirectionLight : function ( ) { }, @@ -18122,241 +18565,227 @@ Grid3D : function ( }; /** - * @class TiledGrid3D + * @class PointLight */ -cc.TiledGrid3D = { +cc.PointLight = { /** - * @method create -* @param {size_object|size_object} size -* @param {cc.Texture2D} texture2d -* @param {bool} bool -* @return {cc.TiledGrid3D|cc.TiledGrid3D} -*/ -create : function( -size, -texture2d, -bool + * @method getRange + * @return {float} + */ +getRange : function ( ) { - return cc.TiledGrid3D; + return 0; }, /** - * @method TiledGrid3D - * @constructor + * @method setRange + * @param {float} arg0 */ -TiledGrid3D : function ( +setRange : function ( +float ) { }, -}; - -/** - * @class Camera - */ -cc.Camera = { - /** - * @method setScene - * @param {cc.Scene} arg0 + * @method create + * @param {vec3_object} arg0 + * @param {color3b_object} arg1 + * @param {float} arg2 + * @return {point_object} */ -setScene : function ( -scene +create : function ( +vec3, +color3b, +float ) { + return cc.PointLight; }, /** - * @method getProjectionMatrix - * @return {mat4_object} + * @method PointLight + * @constructor */ -getProjectionMatrix : function ( +PointLight : function ( ) { - return cc.Mat4; }, +}; + /** - * @method getViewProjectionMatrix - * @return {mat4_object} + * @class SpotLight */ -getViewProjectionMatrix : function ( +cc.SpotLight = { + +/** + * @method getRange + * @return {float} + */ +getRange : function ( ) { - return cc.Mat4; + return 0; }, /** - * @method getViewMatrix - * @return {mat4_object} + * @method setDirection + * @param {vec3_object} arg0 */ -getViewMatrix : function ( +setDirection : function ( +vec3 ) { - return cc.Mat4; }, /** - * @method getCameraFlag - * @return {cc.CameraFlag} + * @method getCosInnerAngle + * @return {float} */ -getCameraFlag : function ( +getCosInnerAngle : function ( ) { return 0; }, /** - * @method getType - * @return {cc.Camera::Type} + * @method getOuterAngle + * @return {float} */ -getType : function ( +getOuterAngle : function ( ) { return 0; }, /** - * @method lookAt - * @param {vec3_object} arg0 - * @param {vec3_object} arg1 + * @method getInnerAngle + * @return {float} */ -lookAt : function ( -vec3, -vec3 +getInnerAngle : function ( ) { + return 0; }, /** - * @method setCameraFlag - * @param {cc.CameraFlag} arg0 + * @method getDirection + * @return {vec3_object} */ -setCameraFlag : function ( -cameraflag +getDirection : function ( ) { + return cc.Vec3; }, /** - * @method initOrthographic - * @param {float} arg0 - * @param {float} arg1 - * @param {float} arg2 - * @param {float} arg3 - * @return {bool} + * @method getCosOuterAngle + * @return {float} */ -initOrthographic : function ( -float, -float, -float, -float +getCosOuterAngle : function ( ) { - return false; + return 0; }, /** - * @method initPerspective + * @method setOuterAngle * @param {float} arg0 - * @param {float} arg1 - * @param {float} arg2 - * @param {float} arg3 - * @return {bool} */ -initPerspective : function ( -float, -float, -float, +setOuterAngle : function ( float ) { - return false; }, /** - * @method initDefault - * @return {bool} + * @method setInnerAngle + * @param {float} arg0 */ -initDefault : function ( +setInnerAngle : function ( +float ) { - return false; }, /** - * @method setAdditionalProjection - * @param {mat4_object} arg0 + * @method getDirectionInWorld + * @return {vec3_object} */ -setAdditionalProjection : function ( -mat4 +getDirectionInWorld : function ( ) { + return cc.Vec3; }, /** - * @method create - * @return {cc.Camera} + * @method setRange + * @param {float} arg0 */ -create : function ( +setRange : function ( +float ) { - return cc.Camera; }, /** - * @method createPerspective - * @param {float} arg0 - * @param {float} arg1 - * @param {float} arg2 + * @method create + * @param {vec3_object} arg0 + * @param {vec3_object} arg1 + * @param {color3b_object} arg2 * @param {float} arg3 - * @return {cc.Camera} + * @param {float} arg4 + * @param {float} arg5 + * @return {cc.SpotLight} */ -createPerspective : function ( -float, +create : function ( +vec3, +vec3, +color3b, float, float, float ) { - return cc.Camera; + return cc.SpotLight; }, /** - * @method createOrthographic - * @param {float} arg0 - * @param {float} arg1 - * @param {float} arg2 - * @param {float} arg3 - * @return {cc.Camera} + * @method SpotLight + * @constructor */ -createOrthographic : function ( -float, -float, -float, -float +SpotLight : function ( ) { - return cc.Camera; }, +}; + /** - * @method getVisitingCamera - * @return {cc.Camera} + * @class AmbientLight */ -getVisitingCamera : function ( +cc.AmbientLight = { + +/** + * @method create + * @param {color3b_object} arg0 + * @return {cc.AmbientLight} + */ +create : function ( +color3b ) { - return cc.Camera; + return cc.AmbientLight; }, /** - * @method Camera + * @method AmbientLight * @constructor */ -Camera : function ( +AmbientLight : function ( ) { }, @@ -21040,3 +21469,38 @@ getInstance : function ( }, }; + +/** + * @class AsyncTaskPool + */ +cc.AsyncTaskPool = { + +/** + * @method stopTasks + * @param {cc.AsyncTaskPool::TaskType} arg0 + */ +stopTasks : function ( +tasktype +) +{ +}, + +/** + * @method destoryInstance + */ +destoryInstance : function ( +) +{ +}, + +/** + * @method getInstance + * @return {cc.AsyncTaskPool} + */ +getInstance : function ( +) +{ + return cc.AsyncTaskPool; +}, + +}; diff --git a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_extension_auto_api.js b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_extension_auto_api.js index c0cdf69eb5..89a1e3796d 100644 --- a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_extension_auto_api.js +++ b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_extension_auto_api.js @@ -166,16 +166,6 @@ isPushed : function ( return false; }, -/** - * @method setSelected - * @param {bool} arg0 - */ -setSelected : function ( -bool -) -{ -}, - /** * @method setTitleLabelForState * @param {cc.Node} arg0 @@ -198,26 +188,6 @@ bool { }, -/** - * @method setHighlighted - * @param {bool} arg0 - */ -setHighlighted : function ( -bool -) -{ -}, - -/** - * @method setZoomOnTouchDown - * @param {bool} arg0 - */ -setZoomOnTouchDown : function ( -bool -) -{ -}, - /** * @method setTitleForState * @param {String} arg0 @@ -329,10 +299,10 @@ getCurrentTitleColor : function ( }, /** - * @method setEnabled + * @method setZoomOnTouchDown * @param {bool} arg0 */ -setEnabled : function ( +setZoomOnTouchDown : function ( bool ) { @@ -370,14 +340,6 @@ getHorizontalOrigin : function ( return 0; }, -/** - * @method needsLayout - */ -needsLayout : function ( -) -{ -}, - /** * @method initWithTitleAndFontNameAndFontSize * @param {String} arg0 @@ -395,13 +357,15 @@ float }, /** - * @method getCurrentTitle -* @return {String|String} -*/ -getCurrentTitle : function( + * @method setTitleBMFontForState + * @param {String} arg0 + * @param {cc.Control::State} arg1 + */ +setTitleBMFontForState : function ( +str, +state ) { - return ; }, /** @@ -505,17 +469,15 @@ float }, /** - * @method initWithLabelAndBackgroundSprite - * @param {cc.Node} arg0 - * @param {ccui.Scale9Sprite} arg1 - * @return {bool} + * @method getTitleBMFontForState + * @param {cc.Control::State} arg0 + * @return {String} */ -initWithLabelAndBackgroundSprite : function ( -node, -scale9sprite +getTitleBMFontForState : function ( +state ) { - return false; + return ; }, /** @@ -573,27 +535,27 @@ int }, /** - * @method setTitleBMFontForState - * @param {String} arg0 - * @param {cc.Control::State} arg1 - */ -setTitleBMFontForState : function ( -str, -state + * @method getCurrentTitle +* @return {String|String} +*/ +getCurrentTitle : function( ) { + return ; }, /** - * @method getTitleBMFontForState - * @param {cc.Control::State} arg0 - * @return {String} + * @method initWithLabelAndBackgroundSprite + * @param {cc.Node} arg0 + * @param {ccui.Scale9Sprite} arg1 + * @return {bool} */ -getTitleBMFontForState : function ( -state +initWithLabelAndBackgroundSprite : function ( +node, +scale9sprite ) { - return ; + return false; }, /** @@ -650,16 +612,6 @@ ControlButton : function ( */ cc.ControlHuePicker = { -/** - * @method setEnabled - * @param {bool} arg0 - */ -setEnabled : function ( -bool -) -{ -}, - /** * @method initWithTargetAndPos * @param {cc.Node} arg0 @@ -838,16 +790,6 @@ getOverlay : function ( return cc.Sprite; }, -/** - * @method setEnabled - * @param {bool} arg0 - */ -setEnabled : function ( -bool -) -{ -}, - /** * @method getSlider * @return {cc.Sprite} @@ -919,11 +861,13 @@ ControlSaturationBrightnessPicker : function ( cc.ControlColourPicker = { /** - * @method setEnabled - * @param {bool} arg0 + * @method hueSliderValueChanged + * @param {cc.Ref} arg0 + * @param {cc.Control::EventType} arg1 */ -setEnabled : function ( -bool +hueSliderValueChanged : function ( +ref, +eventtype ) { }, @@ -938,28 +882,6 @@ getHuePicker : function ( return cc.ControlHuePicker; }, -/** - * @method setColor - * @param {color3b_object} arg0 - */ -setColor : function ( -color3b -) -{ -}, - -/** - * @method hueSliderValueChanged - * @param {cc.Ref} arg0 - * @param {cc.Control::EventType} arg1 - */ -hueSliderValueChanged : function ( -ref, -eventtype -) -{ -}, - /** * @method getcolourPicker * @return {cc.ControlSaturationBrightnessPicker} @@ -1279,55 +1201,41 @@ ControlPotentiometer : function ( cc.ControlSlider = { /** - * @method getSelectedThumbSprite - * @return {cc.Sprite} - */ -getSelectedThumbSprite : function ( -) -{ - return cc.Sprite; -}, - -/** - * @method locationFromTouch - * @param {cc.Touch} arg0 - * @return {vec2_object} - */ -locationFromTouch : function ( -touch -) -{ - return cc.Vec2; -}, - -/** - * @method setSelectedThumbSprite + * @method setBackgroundSprite * @param {cc.Sprite} arg0 */ -setSelectedThumbSprite : function ( +setBackgroundSprite : function ( sprite ) { }, /** - * @method setProgressSprite - * @param {cc.Sprite} arg0 + * @method getMaximumAllowedValue + * @return {float} */ -setProgressSprite : function ( -sprite +getMaximumAllowedValue : function ( ) { + return 0; }, /** - * @method getMaximumAllowedValue - * @return {float} - */ -getMaximumAllowedValue : function ( + * @method initWithSprites +* @param {cc.Sprite|cc.Sprite} sprite +* @param {cc.Sprite|cc.Sprite} sprite +* @param {cc.Sprite|cc.Sprite} sprite +* @param {cc.Sprite} sprite +* @return {bool|bool} +*/ +initWithSprites : function( +sprite, +sprite, +sprite, +sprite ) { - return 0; + return false; }, /** @@ -1341,81 +1249,73 @@ getMinimumAllowedValue : function ( }, /** - * @method getMinimumValue + * @method getMaximumValue * @return {float} */ -getMinimumValue : function ( +getMaximumValue : function ( ) { return 0; }, /** - * @method setThumbSprite - * @param {cc.Sprite} arg0 + * @method getSelectedThumbSprite + * @return {cc.Sprite} */ -setThumbSprite : function ( -sprite +getSelectedThumbSprite : function ( ) { + return cc.Sprite; }, /** - * @method setMinimumValue - * @param {float} arg0 + * @method setProgressSprite + * @param {cc.Sprite} arg0 */ -setMinimumValue : function ( -float +setProgressSprite : function ( +sprite ) { }, /** - * @method setMinimumAllowedValue + * @method setMaximumValue * @param {float} arg0 */ -setMinimumAllowedValue : function ( +setMaximumValue : function ( float ) { }, /** - * @method setEnabled - * @param {bool} arg0 - */ -setEnabled : function ( -bool -) -{ -}, - -/** - * @method setValue - * @param {float} arg0 + * @method getMinimumValue + * @return {float} */ -setValue : function ( -float +getMinimumValue : function ( ) { + return 0; }, /** - * @method setMaximumValue - * @param {float} arg0 + * @method setThumbSprite + * @param {cc.Sprite} arg0 */ -setMaximumValue : function ( -float +setThumbSprite : function ( +sprite ) { }, /** - * @method needsLayout + * @method getValue + * @return {float} */ -needsLayout : function ( +getValue : function ( ) { + return 0; }, /** @@ -1429,63 +1329,55 @@ getBackgroundSprite : function ( }, /** - * @method initWithSprites -* @param {cc.Sprite|cc.Sprite} sprite -* @param {cc.Sprite|cc.Sprite} sprite -* @param {cc.Sprite|cc.Sprite} sprite -* @param {cc.Sprite} sprite -* @return {bool|bool} -*/ -initWithSprites : function( -sprite, -sprite, -sprite, -sprite + * @method getThumbSprite + * @return {cc.Sprite} + */ +getThumbSprite : function ( ) { - return false; + return cc.Sprite; }, /** - * @method getMaximumValue - * @return {float} + * @method setValue + * @param {float} arg0 */ -getMaximumValue : function ( +setValue : function ( +float ) { - return 0; }, /** - * @method isTouchInside + * @method locationFromTouch * @param {cc.Touch} arg0 - * @return {bool} + * @return {vec2_object} */ -isTouchInside : function ( +locationFromTouch : function ( touch ) { - return false; + return cc.Vec2; }, /** - * @method getValue - * @return {float} + * @method setMinimumValue + * @param {float} arg0 */ -getValue : function ( +setMinimumValue : function ( +float ) { - return 0; }, /** - * @method getThumbSprite - * @return {cc.Sprite} + * @method setMinimumAllowedValue + * @param {float} arg0 */ -getThumbSprite : function ( +setMinimumAllowedValue : function ( +float ) { - return cc.Sprite; }, /** @@ -1499,10 +1391,10 @@ getProgressSprite : function ( }, /** - * @method setBackgroundSprite + * @method setSelectedThumbSprite * @param {cc.Sprite} arg0 */ -setBackgroundSprite : function ( +setSelectedThumbSprite : function ( sprite ) { @@ -1553,75 +1445,79 @@ ControlSlider : function ( cc.ControlStepper = { /** - * @method setMinusSprite - * @param {cc.Sprite} arg0 + * @method getMinusSprite + * @return {cc.Sprite} */ -setMinusSprite : function ( -sprite +getMinusSprite : function ( ) { + return cc.Sprite; }, /** - * @method getMinusLabel - * @return {cc.Label} + * @method setValue + * @param {double} arg0 */ -getMinusLabel : function ( +setValue : function ( +double ) { - return cc.Label; }, /** - * @method setWraps - * @param {bool} arg0 + * @method setStepValue + * @param {double} arg0 */ -setWraps : function ( -bool +setStepValue : function ( +double ) { }, /** - * @method isContinuous + * @method initWithMinusSpriteAndPlusSprite + * @param {cc.Sprite} arg0 + * @param {cc.Sprite} arg1 * @return {bool} */ -isContinuous : function ( +initWithMinusSpriteAndPlusSprite : function ( +sprite, +sprite ) { return false; }, /** - * @method getMinusSprite - * @return {cc.Sprite} + * @method setValueWithSendingEvent + * @param {double} arg0 + * @param {bool} arg1 */ -getMinusSprite : function ( +setValueWithSendingEvent : function ( +double, +bool ) { - return cc.Sprite; }, /** - * @method updateLayoutUsingTouchLocation - * @param {vec2_object} arg0 + * @method setMaximumValue + * @param {double} arg0 */ -updateLayoutUsingTouchLocation : function ( -vec2 +setMaximumValue : function ( +double ) { }, /** - * @method setValueWithSendingEvent - * @param {double} arg0 - * @param {bool} arg1 + * @method getMinusLabel + * @return {cc.Label} */ -setValueWithSendingEvent : function ( -double, -bool +getMinusLabel : function ( ) { + return cc.Label; }, /** @@ -1635,131 +1531,117 @@ getPlusLabel : function ( }, /** - * @method stopAutorepeat + * @method setWraps + * @param {bool} arg0 */ -stopAutorepeat : function ( +setWraps : function ( +bool ) { }, /** - * @method setMinimumValue - * @param {double} arg0 + * @method setMinusLabel + * @param {cc.Label} arg0 */ -setMinimumValue : function ( -double +setMinusLabel : function ( +label ) { }, /** - * @method getPlusSprite - * @return {cc.Sprite} + * @method startAutorepeat */ -getPlusSprite : function ( +startAutorepeat : function ( ) { - return cc.Sprite; }, /** - * @method setPlusSprite - * @param {cc.Sprite} arg0 + * @method updateLayoutUsingTouchLocation + * @param {vec2_object} arg0 */ -setPlusSprite : function ( -sprite +updateLayoutUsingTouchLocation : function ( +vec2 ) { }, /** - * @method setMinusLabel - * @param {cc.Label} arg0 + * @method isContinuous + * @return {bool} */ -setMinusLabel : function ( -label +isContinuous : function ( ) { + return false; }, /** - * @method setValue - * @param {double} arg0 + * @method stopAutorepeat */ -setValue : function ( -double +stopAutorepeat : function ( ) { }, /** - * @method setStepValue + * @method setMinimumValue * @param {double} arg0 */ -setStepValue : function ( +setMinimumValue : function ( double ) { }, /** - * @method setMaximumValue - * @param {double} arg0 + * @method setPlusLabel + * @param {cc.Label} arg0 */ -setMaximumValue : function ( -double +setPlusLabel : function ( +label ) { }, /** - * @method update - * @param {float} arg0 + * @method getValue + * @return {double} */ -update : function ( -float +getValue : function ( ) { + return 0; }, /** - * @method startAutorepeat + * @method getPlusSprite + * @return {cc.Sprite} */ -startAutorepeat : function ( +getPlusSprite : function ( ) { + return cc.Sprite; }, /** - * @method initWithMinusSpriteAndPlusSprite + * @method setPlusSprite * @param {cc.Sprite} arg0 - * @param {cc.Sprite} arg1 - * @return {bool} */ -initWithMinusSpriteAndPlusSprite : function ( -sprite, +setPlusSprite : function ( sprite ) { - return false; }, /** - * @method getValue - * @return {double} - */ -getValue : function ( -) -{ - return 0; -}, - -/** - * @method setPlusLabel - * @param {cc.Label} arg0 + * @method setMinusSprite + * @param {cc.Sprite} arg0 */ -setPlusLabel : function ( -label +setMinusSprite : function ( +sprite ) { }, @@ -1794,16 +1676,6 @@ ControlStepper : function ( */ cc.ControlSwitch = { -/** - * @method setEnabled - * @param {bool} arg0 - */ -setEnabled : function ( -bool -) -{ -}, - /** * @method setOn * @param {bool|bool} bool @@ -1816,6 +1688,18 @@ bool { }, +/** + * @method locationFromTouch + * @param {cc.Touch} arg0 + * @return {vec2_object} + */ +locationFromTouch : function ( +touch +) +{ + return cc.Vec2; +}, + /** * @method isOn * @return {bool} @@ -1858,18 +1742,6 @@ hasMoved : function ( return false; }, -/** - * @method locationFromTouch - * @param {cc.Touch} arg0 - * @return {vec2_object} - */ -locationFromTouch : function ( -touch -) -{ - return cc.Vec2; -}, - /** * @method create * @param {cc.Sprite|cc.Sprite} sprite @@ -2067,13 +1939,13 @@ direction }, /** - * @method init - * @return {bool} + * @method setBounceable + * @param {bool} arg0 */ -init : function ( +setBounceable : function ( +bool ) { - return false; }, /** @@ -2188,16 +2060,6 @@ maxContainerOffset : function ( return cc.Vec2; }, -/** - * @method setBounceable - * @param {bool} arg0 - */ -setBounceable : function ( -bool -) -{ -}, - /** * @method isTouchMoved * @return {bool} diff --git a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_spine_auto_api.js b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_spine_auto_api.js index 664f1adfe5..04f48ea510 100644 --- a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_spine_auto_api.js +++ b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_spine_auto_api.js @@ -19,51 +19,65 @@ float }, /** - * @method isOpacityModifyRGB + * @method getDebugSlotsEnabled * @return {bool} */ -isOpacityModifyRGB : function ( +getDebugSlotsEnabled : function ( ) { return false; }, /** - * @method drawSkeleton - * @param {mat4_object} arg0 - * @param {unsigned int} arg1 + * @method setAttachment + * @param {String} arg0 + * @param {String} arg1 + * @return {bool} */ -drawSkeleton : function ( -mat4, -int +setAttachment : function ( +str, +str ) { + return false; }, /** - * @method setDebugSlotsEnabled - * @param {bool} arg0 + * @method setBonesToSetupPose */ -setDebugSlotsEnabled : function ( -bool +setBonesToSetupPose : function ( ) { }, /** - * @method getDebugSlotsEnabled + * @method isOpacityModifyRGB * @return {bool} */ -getDebugSlotsEnabled : function ( +isOpacityModifyRGB : function ( ) { return false; }, /** - * @method setBonesToSetupPose + * @method initWithData + * @param {spSkeletonData} arg0 + * @param {bool} arg1 */ -setBonesToSetupPose : function ( +initWithData : function ( +spskeletondata, +bool +) +{ +}, + +/** + * @method setDebugSlotsEnabled + * @param {bool} arg0 + */ +setDebugSlotsEnabled : function ( +bool ) { }, @@ -77,45 +91,41 @@ setSlotsToSetupPose : function ( }, /** - * @method setAttachment - * @param {String} arg0 - * @param {String} arg1 - * @return {bool} + * @method setOpacityModifyRGB + * @param {bool} arg0 */ -setAttachment : function ( -str, -str +setOpacityModifyRGB : function ( +bool ) { - return false; }, /** - * @method getBlendFunc - * @return {cc.BlendFunc} + * @method setToSetupPose */ -getBlendFunc : function ( +setToSetupPose : function ( ) { - return cc.BlendFunc; }, /** - * @method setSkin - * @param {String} arg0 - * @return {bool} + * @method getBlendFunc + * @return {cc.BlendFunc} */ -setSkin : function ( -str +getBlendFunc : function ( ) { - return false; + return cc.BlendFunc; }, /** - * @method setToSetupPose + * @method drawSkeleton + * @param {mat4_object} arg0 + * @param {unsigned int} arg1 */ -setToSetupPose : function ( +drawSkeleton : function ( +mat4, +int ) { }, @@ -129,11 +139,9 @@ updateWorldTransform : function ( }, /** - * @method setOpacityModifyRGB - * @param {bool} arg0 + * @method initialize */ -setOpacityModifyRGB : function ( -bool +initialize : function ( ) { }, @@ -149,23 +157,37 @@ bool }, /** - * @method getSkeleton - * @return {spSkeleton} + * @method getDebugBonesEnabled + * @return {bool} */ -getSkeleton : function ( +getDebugBonesEnabled : function ( ) { - return spSkeleton; + return false; }, /** - * @method getDebugBonesEnabled - * @return {bool} + * @method getTimeScale + * @return {float} */ -getDebugBonesEnabled : function ( +getTimeScale : function ( +) +{ + return 0; +}, + +/** + * @method initWithFile +* @param {String|String} str +* @param {String|spAtlas} str +* @param {float|float} float +*/ +initWithFile : function( +str, +spatlas, +float ) { - return false; }, /** @@ -179,13 +201,25 @@ blendfunc }, /** - * @method getTimeScale - * @return {float} + * @method setSkin + * @param {String} arg0 + * @return {bool} */ -getTimeScale : function ( +setSkin : function ( +str ) { - return 0; + return false; +}, + +/** + * @method getSkeleton + * @return {spSkeleton} + */ +getSkeleton : function ( +) +{ + return spSkeleton; }, /** @@ -204,6 +238,21 @@ float return sp.SkeletonRenderer; }, +/** + * @method SkeletonRenderer + * @constructor +* @param {spSkeletonData|String|String} spskeletondata +* @param {bool|spAtlas|String} bool +* @param {float|float} float +*/ +SkeletonRenderer : function( +str, +str, +float +) +{ +}, + }; /** @@ -349,6 +398,14 @@ func { }, +/** + * @method initialize + */ +initialize : function ( +) +{ +}, + /** * @method clearTracks */ @@ -397,4 +454,19 @@ float return sp.SkeletonAnimation; }, +/** + * @method SkeletonAnimation + * @constructor +* @param {spSkeletonData|String|String} spskeletondata +* @param {spAtlas|String} spatlas +* @param {float|float} float +*/ +SkeletonAnimation : function( +str, +str, +float +) +{ +}, + }; diff --git a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_studio_auto_api.js b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_studio_auto_api.js index eb7d72428b..8ef5dca4aa 100644 --- a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_studio_auto_api.js +++ b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_studio_auto_api.js @@ -444,6 +444,110 @@ AnimationData : function ( }; +/** + * @class ContourData + */ +ccs.ContourData = { + +/** + * @method init + * @return {bool} + */ +init : function ( +) +{ + return false; +}, + +/** + * @method addVertex + * @param {vec2_object} arg0 + */ +addVertex : function ( +vec2 +) +{ +}, + +/** + * @method create + * @return {ccs.ContourData} + */ +create : function ( +) +{ + return ccs.ContourData; +}, + +/** + * @method ContourData + * @constructor + */ +ContourData : function ( +) +{ +}, + +}; + +/** + * @class TextureData + */ +ccs.TextureData = { + +/** + * @method getContourData + * @param {int} arg0 + * @return {ccs.ContourData} + */ +getContourData : function ( +int +) +{ + return ccs.ContourData; +}, + +/** + * @method init + * @return {bool} + */ +init : function ( +) +{ + return false; +}, + +/** + * @method addContourData + * @param {ccs.ContourData} arg0 + */ +addContourData : function ( +contourdata +) +{ +}, + +/** + * @method create + * @return {ccs.TextureData} + */ +create : function ( +) +{ + return ccs.TextureData; +}, + +/** + * @method TextureData + * @constructor + */ +TextureData : function ( +) +{ +}, + +}; + /** * @class ProcessBase */ @@ -1566,50 +1670,6 @@ getSpeedScale : function ( return 0; }, -/** - * @method pause - */ -pause : function ( -) -{ -}, - -/** - * @method setSpeedScale - * @param {float} arg0 - */ -setSpeedScale : function ( -float -) -{ -}, - -/** - * @method init - * @param {ccs.Armature} arg0 - * @return {bool} - */ -init : function ( -armature -) -{ - return false; -}, - -/** - * @method playWithIndexes - * @param {Array} arg0 - * @param {int} arg1 - * @param {bool} arg2 - */ -playWithIndexes : function ( -array, -int, -bool -) -{ -}, - /** * @method play * @param {String} arg0 @@ -1635,26 +1695,34 @@ int }, /** - * @method resume + * @method playWithIndexes + * @param {Array} arg0 + * @param {int} arg1 + * @param {bool} arg2 */ -resume : function ( +playWithIndexes : function ( +array, +int, +bool ) { }, /** - * @method stop + * @method setAnimationData + * @param {ccs.AnimationData} arg0 */ -stop : function ( +setAnimationData : function ( +animationdata ) { }, /** - * @method update + * @method setSpeedScale * @param {float} arg0 */ -update : function ( +setSpeedScale : function ( float ) { @@ -1671,71 +1739,73 @@ getAnimationData : function ( }, /** - * @method playWithIndex + * @method gotoAndPlay * @param {int} arg0 - * @param {int} arg1 - * @param {int} arg2 */ -playWithIndex : function ( -int, -int, +gotoAndPlay : function ( int ) { }, /** - * @method getCurrentMovementID - * @return {String} + * @method init + * @param {ccs.Armature} arg0 + * @return {bool} */ -getCurrentMovementID : function ( +init : function ( +armature ) { - return ; + return false; }, /** - * @method setAnimationData - * @param {ccs.AnimationData} arg0 + * @method playWithNames + * @param {Array} arg0 + * @param {int} arg1 + * @param {bool} arg2 */ -setAnimationData : function ( -animationdata +playWithNames : function ( +array, +int, +bool ) { }, /** - * @method gotoAndPlay - * @param {int} arg0 + * @method getMovementCount + * @return {long} */ -gotoAndPlay : function ( -int +getMovementCount : function ( ) { + return 0; }, /** - * @method playWithNames - * @param {Array} arg0 + * @method playWithIndex + * @param {int} arg0 * @param {int} arg1 - * @param {bool} arg2 + * @param {int} arg2 */ -playWithNames : function ( -array, +playWithIndex : function ( int, -bool +int, +int ) { }, /** - * @method getMovementCount - * @return {long} + * @method getCurrentMovementID + * @return {String} */ -getMovementCount : function ( +getCurrentMovementID : function ( ) { - return 0; + return ; }, /** @@ -2353,6 +2423,20 @@ float return 0; }, +/** + * @method getBool + * @param {String} arg0 + * @param {bool} arg1 + * @return {bool} + */ +getBool : function ( +str, +bool +) +{ + return false; +}, + /** * @method getString * @param {String} arg0 @@ -2391,20 +2475,6 @@ str { }, -/** - * @method getBool - * @param {String} arg0 - * @param {bool} arg1 - * @return {bool} - */ -getBool : function ( -str, -bool -) -{ - return false; -}, - /** * @method setInt * @param {String} arg0 @@ -2465,6 +2535,15 @@ create : function ( return ccs.ComAttribute; }, +/** + * @method ComAttribute + * @constructor + */ +ComAttribute : function ( +) +{ +}, + }; /** @@ -2734,6 +2813,15 @@ create : function ( return ccs.ComAudio; }, +/** + * @method ComAudio + * @constructor + */ +ComAudio : function ( +) +{ +}, + }; /** @@ -2875,23 +2963,23 @@ ComController : function ( ccs.ComRender = { /** - * @method setNode - * @param {cc.Node} arg0 + * @method getNode + * @return {cc.Node} */ -setNode : function ( -node +getNode : function ( ) { + return cc.Node; }, /** - * @method getNode - * @return {cc.Node} + * @method setNode + * @param {cc.Node} arg0 */ -getNode : function ( +setNode : function ( +node ) { - return cc.Node; }, /** @@ -2908,257 +2996,17 @@ char return ccs.ComRender; }, -}; - -/** - * @class GUIReader - */ -ccs.GUIReader = { - -/** - * @method setFilePath - * @param {String} arg0 - */ -setFilePath : function ( -str -) -{ -}, - -/** - * @method widgetFromJsonFile - * @param {char} arg0 - * @return {ccui.Widget} - */ -widgetFromJsonFile : function ( -char -) -{ - return ccui.Widget; -}, - -/** - * @method getFilePath - * @return {String} - */ -getFilePath : function ( -) -{ - return ; -}, - -/** - * @method widgetFromBinaryFile - * @param {char} arg0 - * @return {ccui.Widget} - */ -widgetFromBinaryFile : function ( -char -) -{ - return ccui.Widget; -}, - /** - * @method getVersionInteger - * @param {char} arg0 - * @return {int} - */ -getVersionInteger : function ( + * @method ComRender + * @constructor +* @param {cc.Node} node +* @param {char} char +*/ +ComRender : function( +node, char ) { - return 0; -}, - -/** - * @method destroyInstance - */ -destroyInstance : function ( -) -{ -}, - -/** - * @method getInstance - * @return {ccs.GUIReader} - */ -getInstance : function ( -) -{ - return ccs.GUIReader; -}, - -}; - -/** - * @class SceneReader - */ -ccs.SceneReader = { - -/** - * @method createNodeWithSceneFile - * @param {String} arg0 - * @param {ccs.SceneReader::AttachComponentType} arg1 - * @return {cc.Node} - */ -createNodeWithSceneFile : function ( -str, -attachcomponenttype -) -{ - return cc.Node; -}, - -/** - * @method getAttachComponentType - * @return {ccs.SceneReader::AttachComponentType} - */ -getAttachComponentType : function ( -) -{ - return 0; -}, - -/** - * @method getNodeByTag - * @param {int} arg0 - * @return {cc.Node} - */ -getNodeByTag : function ( -int -) -{ - return cc.Node; -}, - -/** - * @method destroyInstance - */ -destroyInstance : function ( -) -{ -}, - -/** - * @method sceneReaderVersion - * @return {char} - */ -sceneReaderVersion : function ( -) -{ - return 0; -}, - -/** - * @method getInstance - * @return {ccs.SceneReader} - */ -getInstance : function ( -) -{ - return ccs.SceneReader; -}, - -}; - -/** - * @class ActionTimelineCache - */ -ccs.ActionTimelineCache = { - -/** - * @method createActionFromJson - * @param {String} arg0 - * @return {ccs.timeline::ActionTimeline} - */ -createActionFromJson : function ( -str -) -{ - return ccs.timeline::ActionTimeline; -}, - -/** - * @method purge - */ -purge : function ( -) -{ -}, - -/** - * @method init - */ -init : function ( -) -{ -}, - -/** - * @method loadAnimationActionWithFile - * @param {String} arg0 - * @return {ccs.timeline::ActionTimeline} - */ -loadAnimationActionWithFile : function ( -str -) -{ - return ccs.timeline::ActionTimeline; -}, - -/** - * @method loadAnimationActionWithContent - * @param {String} arg0 - * @param {String} arg1 - * @return {ccs.timeline::ActionTimeline} - */ -loadAnimationActionWithContent : function ( -str, -str -) -{ - return ccs.timeline::ActionTimeline; -}, - -/** - * @method removeAction - * @param {String} arg0 - */ -removeAction : function ( -str -) -{ -}, - -/** - * @method destroyInstance - */ -destroyInstance : function ( -) -{ -}, - -/** - * @method createAction - * @param {String} arg0 - * @return {ccs.timeline::ActionTimeline} - */ -createAction : function ( -str -) -{ - return ccs.timeline::ActionTimeline; -}, - -/** - * @method getInstance - * @return {ccs.timeline::ActionTimelineCache} - */ -getInstance : function ( -) -{ - return ccs.timeline::ActionTimelineCache; }, }; @@ -3341,16 +3189,6 @@ getTextureName : function ( return ; }, -/** - * @method setNode - * @param {cc.Node} arg0 - */ -setNode : function ( -node -) -{ -}, - /** * @method setTextureName * @param {String} arg0 @@ -3733,6 +3571,26 @@ AnchorPointFrame : function ( */ ccs.InnerActionFrame = { +/** + * @method getEndFrameIndex + * @return {int} + */ +getEndFrameIndex : function ( +) +{ + return 0; +}, + +/** + * @method getStartFrameIndex + * @return {int} + */ +getStartFrameIndex : function ( +) +{ + return 0; +}, + /** * @method getInnerActionType * @return {ccs.timeline::InnerActionType} @@ -3743,6 +3601,36 @@ getInnerActionType : function ( return 0; }, +/** + * @method setEndFrameIndex + * @param {int} arg0 + */ +setEndFrameIndex : function ( +int +) +{ +}, + +/** + * @method setEnterWithName + * @param {bool} arg0 + */ +setEnterWithName : function ( +bool +) +{ +}, + +/** + * @method setSingleFrameIndex + * @param {int} arg0 + */ +setSingleFrameIndex : function ( +int +) +{ +}, + /** * @method setStartFrameIndex * @param {int} arg0 @@ -3753,6 +3641,16 @@ int { }, +/** + * @method getSingleFrameIndex + * @return {int} + */ +getSingleFrameIndex : function ( +) +{ + return 0; +}, + /** * @method setInnerActionType * @param {ccs.timeline::InnerActionType} arg0 @@ -3764,13 +3662,13 @@ inneractiontype }, /** - * @method getStartFrameIndex - * @return {int} + * @method setAnimationName + * @param {String} arg0 */ -getStartFrameIndex : function ( +setAnimationName : function ( +str ) { - return 0; }, /** @@ -3799,16 +3697,6 @@ InnerActionFrame : function ( */ ccs.ColorFrame = { -/** - * @method getAlpha - * @return {unsigned char} - */ -getAlpha : function ( -) -{ - return 0; -}, - /** * @method getColor * @return {color3b_object} @@ -3819,16 +3707,6 @@ getColor : function ( return cc.Color3B; }, -/** - * @method setAlpha - * @param {unsigned char} arg0 - */ -setAlpha : function ( -char -) -{ -}, - /** * @method setColor * @param {color3b_object} arg0 @@ -3860,6 +3738,52 @@ ColorFrame : function ( }; +/** + * @class AlphaFrame + */ +ccs.AlphaFrame = { + +/** + * @method getAlpha + * @return {unsigned char} + */ +getAlpha : function ( +) +{ + return 0; +}, + +/** + * @method setAlpha + * @param {unsigned char} arg0 + */ +setAlpha : function ( +char +) +{ +}, + +/** + * @method create + * @return {ccs.timeline::AlphaFrame} + */ +create : function ( +) +{ + return ccs.timeline::AlphaFrame; +}, + +/** + * @method AlphaFrame + * @constructor + */ +AlphaFrame : function ( +) +{ +}, + +}; + /** * @class EventFrame */ @@ -4133,6 +4057,18 @@ int { }, +/** + * @method init + * @param {int} arg0 + * @return {bool} + */ +init : function ( +int +) +{ + return false; +}, + /** * @method getActionTag * @return {int} @@ -4155,6 +4091,15 @@ int return ccs.timeline::ActionTimelineData; }, +/** + * @method ActionTimelineData + * @constructor + */ +ActionTimelineData : function ( +) +{ +}, + }; /** @@ -4230,6 +4175,14 @@ timeline { }, +/** + * @method clearFrameEventCallFunc + */ +clearFrameEventCallFunc : function ( +) +{ +}, + /** * @method setLastFrameCallFunc * @param {function} arg0 @@ -4250,6 +4203,30 @@ getTimelines : function ( return new Array(); }, +/** + * @method play + * @param {String} arg0 + * @param {bool} arg1 + */ +play : function ( +str, +bool +) +{ +}, + +/** + * @method getAnimationInfo + * @param {String} arg0 + * @return {ccs.timeline::AnimationInfo} + */ +getAnimationInfo : function ( +str +) +{ + return ccs.timeline::AnimationInfo; +}, + /** * @method resume */ @@ -4258,6 +4235,16 @@ resume : function ( { }, +/** + * @method removeAnimationInfo + * @param {String} arg0 + */ +removeAnimationInfo : function ( +str +) +{ +}, + /** * @method getTimeSpeed * @return {float} @@ -4268,6 +4255,16 @@ getTimeSpeed : function ( return 0; }, +/** + * @method addAnimationInfo + * @param {ccs.timeline::AnimationInfo} arg0 + */ +addAnimationInfo : function ( +animationinfo +) +{ +}, + /** * @method getDuration * @return {int} @@ -4315,11 +4312,15 @@ bool }, /** - * @method clearFrameEventCallFunc + * @method IsAnimationInfoExists + * @param {String} arg0 + * @return {bool} */ -clearFrameEventCallFunc : function ( +IsAnimationInfoExists : function ( +str ) { + return false; }, /** @@ -4392,160 +4393,77 @@ ActionTimeline : function ( }; /** - * @class CSLoader - */ -ccs.CSLoader = { - -/** - * @method setJsonPath - * @param {String} arg0 + * @class ObjectExtensionData */ -setJsonPath : function ( -str -) -{ -}, +ccs.ObjectExtensionData = { /** - * @method createNodeFromJson - * @param {String} arg0 - * @return {cc.Node} + * @method setActionTag + * @param {int} arg0 */ -createNodeFromJson : function ( -str +setActionTag : function ( +int ) { - return cc.Node; }, /** - * @method loadNodeWithFile + * @method setCustomProperty * @param {String} arg0 - * @return {cc.Node} */ -loadNodeWithFile : function ( +setCustomProperty : function ( str ) -{ - return cc.Node; -}, - -/** - * @method bindCallback - * @param {String} arg0 - * @param {String} arg1 - * @param {ccui.Widget} arg2 - * @param {cc.Node} arg3 - * @return {bool} - */ -bindCallback : function ( -str, -str, -widget, -node -) -{ - return false; -}, - -/** - * @method purge - */ -purge : function ( -) { }, /** * @method init - */ -init : function ( -) -{ -}, - -/** - * @method loadNodeWithContent - * @param {String} arg0 - * @return {cc.Node} - */ -loadNodeWithContent : function ( -str -) -{ - return cc.Node; -}, - -/** - * @method isRecordJsonPath * @return {bool} */ -isRecordJsonPath : function ( +init : function ( ) { return false; }, /** - * @method getJsonPath + * @method getCustomProperty * @return {String} */ -getJsonPath : function ( +getCustomProperty : function ( ) { return ; }, /** - * @method setRecordJsonPath - * @param {bool} arg0 - */ -setRecordJsonPath : function ( -bool -) -{ -}, - -/** - * @method destroyInstance - */ -destroyInstance : function ( -) -{ -}, - -/** - * @method createNode - * @param {String} arg0 - * @return {cc.Node} + * @method getActionTag + * @return {int} */ -createNode : function ( -str +getActionTag : function ( ) { - return cc.Node; + return 0; }, /** - * @method createTimeline - * @param {String} arg0 - * @return {ccs.timeline::ActionTimeline} + * @method create + * @return {ccs.ObjectExtensionData} */ -createTimeline : function ( -str +create : function ( ) { - return ccs.timeline::ActionTimeline; + return ccs.ObjectExtensionData; }, /** - * @method getInstance - * @return {cc.CSLoader} + * @method ObjectExtensionData + * @constructor */ -getInstance : function ( +ObjectExtensionData : function ( ) { - return cc.CSLoader; }, }; diff --git a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_ui_auto_api.js b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_ui_auto_api.js index cf4a7f39d5..68377648e1 100644 --- a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_ui_auto_api.js +++ b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_ui_auto_api.js @@ -206,6 +206,16 @@ RelativeLayoutParameter : function ( */ ccui.Widget = { +/** + * @method setLayoutComponentEnabled + * @param {bool} arg0 + */ +setLayoutComponentEnabled : function ( +bool +) +{ +}, + /** * @method setSizePercent * @param {vec2_object} arg0 @@ -704,6 +714,16 @@ vec2 return false; }, +/** + * @method isLayoutComponentEnabled + * @return {bool} + */ +isLayoutComponentEnabled : function ( +) +{ + return false; +}, + /** * @method requestFocus */ @@ -1294,6 +1314,16 @@ Layout : function ( */ ccui.Button = { +/** + * @method getNormalTextureSize + * @return {size_object} + */ +getNormalTextureSize : function ( +) +{ + return cc.Size; +}, + /** * @method getTitleText * @return {String} @@ -1716,6 +1746,16 @@ texturerestype { }, +/** + * @method getZoomScale + * @return {float} + */ +getZoomScale : function ( +) +{ + return 0; +}, + /** * @method loadTextureBackGround * @param {String} arg0 @@ -1728,6 +1768,16 @@ texturerestype { }, +/** + * @method setZoomScale + * @param {float} arg0 + */ +setZoomScale : function ( +float +) +{ +}, + /** * @method loadTextureFrontCrossDisabled * @param {String} arg0 @@ -1742,13 +1792,13 @@ texturerestype /** * @method create -* @param {String} str -* @param {String} str -* @param {String} str +* @param {String|String} str +* @param {String|String} str +* @param {String|ccui.Widget::TextureResType} str * @param {String} str * @param {String} str * @param {ccui.Widget::TextureResType} texturerestype -* @return {ccui.CheckBox|ccui.CheckBox} +* @return {ccui.CheckBox|ccui.CheckBox|ccui.CheckBox} */ create : function( str, @@ -2046,6 +2096,16 @@ getStringLength : function ( return 0; }, +/** + * @method getAutoRenderSize + * @return {size_object} + */ +getAutoRenderSize : function ( +) +{ + return cc.Size; +}, + /** * @method enableOutline * @param {color4b_object} arg0 @@ -2376,12 +2436,14 @@ getPercent : function ( /** * @method create -* @param {String} str +* @param {String|String} str +* @param {float|ccui.Widget::TextureResType} float * @param {float} float -* @return {ccui.LoadingBar|ccui.LoadingBar} +* @return {ccui.LoadingBar|ccui.LoadingBar|ccui.LoadingBar} */ create : function( str, +texturerestype, float ) { @@ -3096,6 +3158,16 @@ bool { }, +/** + * @method setZoomScale + * @param {float} arg0 + */ +setZoomScale : function ( +float +) +{ +}, + /** * @method setCapInsets * @param {rect_object} arg0 @@ -3106,6 +3178,16 @@ rect { }, +/** + * @method getZoomScale + * @return {float} + */ +getZoomScale : function ( +) +{ + return 0; +}, + /** * @method loadSlidBallTexturePressed * @param {String} arg0 @@ -3150,9 +3232,15 @@ getPercent : function ( /** * @method create - * @return {ccui.Slider} - */ -create : function ( +* @param {String} str +* @param {String} str +* @param {ccui.Widget::TextureResType} texturerestype +* @return {ccui.Slider|ccui.Slider} +*/ +create : function( +str, +str, +texturerestype ) { return ccui.Slider; @@ -3180,46 +3268,38 @@ Slider : function ( }; /** - * @class TextField - */ -ccui.TextField = { - -/** - * @method setAttachWithIME - * @param {bool} arg0 + * @class UICCTextField */ -setAttachWithIME : function ( -bool -) -{ -}, +ccui.UICCTextField = { /** - * @method getFontSize - * @return {int} + * @method onTextFieldAttachWithIME + * @param {cc.TextFieldTTF} arg0 + * @return {bool} */ -getFontSize : function ( +onTextFieldAttachWithIME : function ( +textfieldttf ) { - return 0; + return false; }, /** - * @method getString - * @return {String} + * @method setPasswordText + * @param {String} arg0 */ -getString : function ( +setPasswordText : function ( +str ) { - return ; }, /** - * @method setPasswordStyleText - * @param {char} arg0 + * @method setAttachWithIME + * @param {bool} arg0 */ -setPasswordStyleText : function ( -char +setAttachWithIME : function ( +bool ) { }, @@ -3234,16 +3314,6 @@ getDeleteBackward : function ( return false; }, -/** - * @method getPlaceHolder - * @return {String} - */ -getPlaceHolder : function ( -) -{ - return ; -}, - /** * @method getAttachWithIME * @return {bool} @@ -3255,13 +3325,19 @@ getAttachWithIME : function ( }, /** - * @method setFontName - * @param {String} arg0 + * @method onTextFieldDeleteBackward + * @param {cc.TextFieldTTF} arg0 + * @param {char} arg1 + * @param {unsigned long} arg2 + * @return {bool} */ -setFontName : function ( -str +onTextFieldDeleteBackward : function ( +textfieldttf, +char, +long ) { + return false; }, /** @@ -3275,21 +3351,19 @@ getInsertText : function ( }, /** - * @method setInsertText - * @param {bool} arg0 + * @method deleteBackward */ -setInsertText : function ( -bool +deleteBackward : function ( ) { }, /** - * @method setString - * @param {String} arg0 + * @method setInsertText + * @param {bool} arg0 */ -setString : function ( -str +setInsertText : function ( +bool ) { }, @@ -3305,631 +3379,590 @@ getDetachWithIME : function ( }, /** - * @method setTextVerticalAlignment - * @param {cc.TextVAlignment} arg0 + * @method getCharCount + * @return {int} */ -setTextVerticalAlignment : function ( -textvalignment +getCharCount : function ( ) { + return 0; }, /** - * @method didNotSelectSelf + * @method closeIME */ -didNotSelectSelf : function ( +closeIME : function ( ) { }, /** - * @method getFontName - * @return {String} + * @method setPasswordEnabled + * @param {bool} arg0 */ -getFontName : function ( +setPasswordEnabled : function ( +bool ) { - return ; }, /** - * @method setTextAreaSize - * @param {size_object} arg0 + * @method setMaxLengthEnabled + * @param {bool} arg0 */ -setTextAreaSize : function ( -size +setMaxLengthEnabled : function ( +bool ) { }, /** - * @method attachWithIME + * @method isPasswordEnabled + * @return {bool} */ -attachWithIME : function ( +isPasswordEnabled : function ( ) { + return false; }, /** - * @method getStringLength - * @return {int} + * @method insertText + * @param {char} arg0 + * @param {unsigned long} arg1 */ -getStringLength : function ( +insertText : function ( +char, +long ) { - return 0; }, /** - * @method setPasswordEnabled - * @param {bool} arg0 + * @method setPasswordStyleText + * @param {String} arg0 */ -setPasswordEnabled : function ( -bool +setPasswordStyleText : function ( +str ) { }, /** - * @method getPlaceHolderColor - * @return {color4b_object} + * @method onTextFieldInsertText + * @param {cc.TextFieldTTF} arg0 + * @param {char} arg1 + * @param {unsigned long} arg2 + * @return {bool} */ -getPlaceHolderColor : function ( +onTextFieldInsertText : function ( +textfieldttf, +char, +long ) { - return cc.Color4B; + return false; }, /** - * @method getPasswordStyleText - * @return {char} + * @method onTextFieldDetachWithIME + * @param {cc.TextFieldTTF} arg0 + * @return {bool} */ -getPasswordStyleText : function ( +onTextFieldDetachWithIME : function ( +textfieldttf ) { - return 0; + return false; }, /** - * @method setMaxLengthEnabled - * @param {bool} arg0 + * @method getMaxLength + * @return {int} */ -setMaxLengthEnabled : function ( -bool +getMaxLength : function ( ) { + return 0; }, /** - * @method isPasswordEnabled + * @method isMaxLengthEnabled * @return {bool} */ -isPasswordEnabled : function ( +isMaxLengthEnabled : function ( ) { return false; }, /** - * @method setDeleteBackward - * @param {bool} arg0 + * @method openIME */ -setDeleteBackward : function ( -bool +openIME : function ( ) { }, /** - * @method setFontSize - * @param {int} arg0 + * @method setDetachWithIME + * @param {bool} arg0 */ -setFontSize : function ( -int +setDetachWithIME : function ( +bool ) { }, /** - * @method setPlaceHolder - * @param {String} arg0 + * @method setMaxLength + * @param {int} arg0 */ -setPlaceHolder : function ( -str +setMaxLength : function ( +int ) { }, /** - * @method setPlaceHolderColor -* @param {color4b_object|color3b_object} color4b -*/ -setPlaceHolderColor : function( -color3b + * @method setDeleteBackward + * @param {bool} arg0 + */ +setDeleteBackward : function ( +bool ) { }, /** - * @method setTextHorizontalAlignment - * @param {cc.TextHAlignment} arg0 + * @method create + * @param {String} arg0 + * @param {String} arg1 + * @param {float} arg2 + * @return {ccui.UICCTextField} */ -setTextHorizontalAlignment : function ( -texthalignment +create : function ( +str, +str, +float ) { + return ccui.UICCTextField; }, /** - * @method setTextColor - * @param {color4b_object} arg0 + * @method UICCTextField + * @constructor */ -setTextColor : function ( -color4b +UICCTextField : function ( ) { }, +}; + /** - * @method getMaxLength - * @return {int} + * @class TextField */ -getMaxLength : function ( +ccui.TextField = { + +/** + * @method setAttachWithIME + * @param {bool} arg0 + */ +setAttachWithIME : function ( +bool ) { - return 0; }, /** - * @method isMaxLengthEnabled - * @return {bool} + * @method getFontSize + * @return {int} */ -isMaxLengthEnabled : function ( +getFontSize : function ( ) { - return false; + return 0; }, /** - * @method setDetachWithIME - * @param {bool} arg0 + * @method getString + * @return {String} */ -setDetachWithIME : function ( -bool +getString : function ( ) { + return ; }, /** - * @method setTouchAreaEnabled - * @param {bool} arg0 + * @method setPasswordStyleText + * @param {char} arg0 */ -setTouchAreaEnabled : function ( -bool +setPasswordStyleText : function ( +char ) { }, /** - * @method hitTest - * @param {vec2_object} arg0 + * @method getDeleteBackward * @return {bool} */ -hitTest : function ( -vec2 +getDeleteBackward : function ( ) { return false; }, /** - * @method setMaxLength - * @param {int} arg0 + * @method getPlaceHolder + * @return {String} */ -setMaxLength : function ( -int +getPlaceHolder : function ( ) { + return ; }, /** - * @method setTouchSize - * @param {size_object} arg0 + * @method getAttachWithIME + * @return {bool} */ -setTouchSize : function ( -size +getAttachWithIME : function ( ) { + return false; }, /** - * @method getTouchSize - * @return {size_object} + * @method setFontName + * @param {String} arg0 */ -getTouchSize : function ( +setFontName : function ( +str ) { - return cc.Size; }, /** - * @method create -* @param {String} str -* @param {String} str -* @param {int} int -* @return {ccui.TextField|ccui.TextField} -*/ -create : function( -str, -str, -int + * @method getInsertText + * @return {bool} + */ +getInsertText : function ( ) { - return ccui.TextField; + return false; }, /** - * @method createInstance - * @return {cc.Ref} + * @method setInsertText + * @param {bool} arg0 */ -createInstance : function ( +setInsertText : function ( +bool ) { - return cc.Ref; }, /** - * @method TextField - * @constructor + * @method setString + * @param {String} arg0 */ -TextField : function ( +setString : function ( +str ) { }, -}; - -/** - * @class TextBMFont - */ -ccui.TextBMFont = { - /** - * @method setFntFile - * @param {String} arg0 + * @method getDetachWithIME + * @return {bool} */ -setFntFile : function ( -str +getDetachWithIME : function ( ) { + return false; }, /** - * @method getStringLength - * @return {long} + * @method setTextVerticalAlignment + * @param {cc.TextVAlignment} arg0 */ -getStringLength : function ( +setTextVerticalAlignment : function ( +textvalignment ) { - return 0; }, /** - * @method setString - * @param {String} arg0 + * @method didNotSelectSelf */ -setString : function ( -str +didNotSelectSelf : function ( ) { }, /** - * @method getString + * @method getFontName * @return {String} */ -getString : function ( +getFontName : function ( ) { return ; }, /** - * @method create -* @param {String} str -* @param {String} str -* @return {ccui.TextBMFont|ccui.TextBMFont} -*/ -create : function( -str, -str + * @method setTextAreaSize + * @param {size_object} arg0 + */ +setTextAreaSize : function ( +size ) { - return ccui.TextBMFont; }, /** - * @method createInstance - * @return {cc.Ref} + * @method attachWithIME */ -createInstance : function ( +attachWithIME : function ( ) { - return cc.Ref; }, /** - * @method TextBMFont - * @constructor + * @method getStringLength + * @return {int} */ -TextBMFont : function ( +getStringLength : function ( ) { + return 0; }, -}; - -/** - * @class PageView - */ -ccui.PageView = { - /** - * @method getCustomScrollThreshold - * @return {float} + * @method getAutoRenderSize + * @return {size_object} */ -getCustomScrollThreshold : function ( +getAutoRenderSize : function ( ) { - return 0; + return cc.Size; }, /** - * @method getCurPageIndex - * @return {long} + * @method setPasswordEnabled + * @param {bool} arg0 */ -getCurPageIndex : function ( +setPasswordEnabled : function ( +bool ) { - return 0; }, /** - * @method addWidgetToPage - * @param {ccui.Widget} arg0 - * @param {long} arg1 - * @param {bool} arg2 + * @method getPlaceHolderColor + * @return {color4b_object} */ -addWidgetToPage : function ( -widget, -long, -bool +getPlaceHolderColor : function ( ) { + return cc.Color4B; }, /** - * @method isUsingCustomScrollThreshold - * @return {bool} + * @method getPasswordStyleText + * @return {char} */ -isUsingCustomScrollThreshold : function ( +getPasswordStyleText : function ( ) { - return false; + return 0; }, /** - * @method getPage - * @param {long} arg0 - * @return {ccui.Layout} + * @method setMaxLengthEnabled + * @param {bool} arg0 */ -getPage : function ( -long +setMaxLengthEnabled : function ( +bool ) { - return ccui.Layout; }, /** - * @method removePage - * @param {ccui.Layout} arg0 + * @method isPasswordEnabled + * @return {bool} */ -removePage : function ( -layout +isPasswordEnabled : function ( ) { + return false; }, /** - * @method setUsingCustomScrollThreshold + * @method setDeleteBackward * @param {bool} arg0 */ -setUsingCustomScrollThreshold : function ( +setDeleteBackward : function ( bool ) { }, /** - * @method setCustomScrollThreshold - * @param {float} arg0 + * @method setFontSize + * @param {int} arg0 */ -setCustomScrollThreshold : function ( -float +setFontSize : function ( +int ) { }, /** - * @method insertPage - * @param {ccui.Layout} arg0 - * @param {int} arg1 + * @method setPlaceHolder + * @param {String} arg0 */ -insertPage : function ( -layout, -int +setPlaceHolder : function ( +str ) { }, /** - * @method scrollToPage - * @param {long} arg0 - */ -scrollToPage : function ( -long + * @method setPlaceHolderColor +* @param {color4b_object|color3b_object} color4b +*/ +setPlaceHolderColor : function( +color3b ) { }, /** - * @method removePageAtIndex - * @param {long} arg0 + * @method setTextHorizontalAlignment + * @param {cc.TextHAlignment} arg0 */ -removePageAtIndex : function ( -long +setTextHorizontalAlignment : function ( +texthalignment ) { }, /** - * @method getPages - * @return {Array} + * @method setTextColor + * @param {color4b_object} arg0 */ -getPages : function ( +setTextColor : function ( +color4b ) { - return new Array(); }, /** - * @method removeAllPages + * @method getMaxLength + * @return {int} */ -removeAllPages : function ( +getMaxLength : function ( ) { + return 0; }, /** - * @method addPage - * @param {ccui.Layout} arg0 + * @method isMaxLengthEnabled + * @return {bool} */ -addPage : function ( -layout +isMaxLengthEnabled : function ( ) { + return false; }, /** - * @method create - * @return {ccui.PageView} + * @method setDetachWithIME + * @param {bool} arg0 */ -create : function ( +setDetachWithIME : function ( +bool ) { - return ccui.PageView; }, /** - * @method createInstance - * @return {cc.Ref} + * @method setTouchAreaEnabled + * @param {bool} arg0 */ -createInstance : function ( +setTouchAreaEnabled : function ( +bool ) { - return cc.Ref; }, /** - * @method PageView - * @constructor + * @method setMaxLength + * @param {int} arg0 */ -PageView : function ( +setMaxLength : function ( +int ) { }, -}; - -/** - * @class Helper - */ -ccui.Helper = { - /** - * @method getSubStringOfUTF8String - * @param {String} arg0 - * @param {unsigned long} arg1 - * @param {unsigned long} arg2 - * @return {String} + * @method setTouchSize + * @param {size_object} arg0 */ -getSubStringOfUTF8String : function ( -str, -long, -long +setTouchSize : function ( +size ) { - return ; }, /** - * @method changeLayoutSystemActiveState - * @param {bool} arg0 + * @method getTouchSize + * @return {size_object} */ -changeLayoutSystemActiveState : function ( -bool +getTouchSize : function ( ) { + return cc.Size; }, /** - * @method seekActionWidgetByActionTag - * @param {ccui.Widget} arg0 - * @param {int} arg1 - * @return {ccui.Widget} - */ -seekActionWidgetByActionTag : function ( -widget, + * @method create +* @param {String} str +* @param {String} str +* @param {int} int +* @return {ccui.TextField|ccui.TextField} +*/ +create : function( +str, +str, int ) { - return ccui.Widget; -}, - -/** - * @method seekWidgetByName - * @param {ccui.Widget} arg0 - * @param {String} arg1 - * @return {ccui.Widget} - */ -seekWidgetByName : function ( -widget, -str -) -{ - return ccui.Widget; + return ccui.TextField; }, /** - * @method seekWidgetByTag - * @param {ccui.Widget} arg0 - * @param {int} arg1 - * @return {ccui.Widget} + * @method createInstance + * @return {cc.Ref} */ -seekWidgetByTag : function ( -widget, -int +createInstance : function ( ) { - return ccui.Widget; + return cc.Ref; }, /** - * @method doLayout - * @param {cc.Node} arg0 + * @method TextField + * @constructor */ -doLayout : function ( -node +TextField : function ( ) { }, @@ -3937,91 +3970,79 @@ node }; /** - * @class RichElement + * @class TextBMFont */ -ccui.RichElement = { +ccui.TextBMFont = { /** - * @method init - * @param {int} arg0 - * @param {color3b_object} arg1 - * @param {unsigned char} arg2 - * @return {bool} + * @method setFntFile + * @param {String} arg0 */ -init : function ( -int, -color3b, -char +setFntFile : function ( +str ) { - return false; }, /** - * @method RichElement - * @constructor + * @method getStringLength + * @return {long} */ -RichElement : function ( +getStringLength : function ( ) { + return 0; }, -}; - /** - * @class RichElementText + * @method setString + * @param {String} arg0 */ -ccui.RichElementText = { +setString : function ( +str +) +{ +}, /** - * @method init - * @param {int} arg0 - * @param {color3b_object} arg1 - * @param {unsigned char} arg2 - * @param {String} arg3 - * @param {String} arg4 - * @param {float} arg5 - * @return {bool} + * @method getString + * @return {String} */ -init : function ( -int, -color3b, -char, -str, -str, -float +getString : function ( ) { - return false; + return ; }, /** * @method create - * @param {int} arg0 - * @param {color3b_object} arg1 - * @param {unsigned char} arg2 - * @param {String} arg3 - * @param {String} arg4 - * @param {float} arg5 - * @return {ccui.RichElementText} +* @param {String} str +* @param {String} str +* @return {ccui.TextBMFont|ccui.TextBMFont} +*/ +create : function( +str, +str +) +{ + return ccui.TextBMFont; +}, + +/** + * @method createInstance + * @return {cc.Ref} */ -create : function ( -int, -color3b, -char, -str, -str, -float +createInstance : function ( ) { - return ccui.RichElementText; + return cc.Ref; }, /** - * @method RichElementText + * @method TextBMFont * @constructor */ -RichElementText : function ( +TextBMFont : function ( ) { }, @@ -4029,103 +4050,1090 @@ RichElementText : function ( }; /** - * @class RichElementImage + * @class PageView */ -ccui.RichElementImage = { +ccui.PageView = { /** - * @method init - * @param {int} arg0 - * @param {color3b_object} arg1 - * @param {unsigned char} arg2 - * @param {String} arg3 - * @return {bool} + * @method getCustomScrollThreshold + * @return {float} */ -init : function ( -int, -color3b, -char, -str +getCustomScrollThreshold : function ( ) { - return false; + return 0; }, /** - * @method create + * @method getCurPageIndex + * @return {long} + */ +getCurPageIndex : function ( +) +{ + return 0; +}, + +/** + * @method addWidgetToPage + * @param {ccui.Widget} arg0 + * @param {long} arg1 + * @param {bool} arg2 + */ +addWidgetToPage : function ( +widget, +long, +bool +) +{ +}, + +/** + * @method isUsingCustomScrollThreshold + * @return {bool} + */ +isUsingCustomScrollThreshold : function ( +) +{ + return false; +}, + +/** + * @method getPage + * @param {long} arg0 + * @return {ccui.Layout} + */ +getPage : function ( +long +) +{ + return ccui.Layout; +}, + +/** + * @method removePage + * @param {ccui.Layout} arg0 + */ +removePage : function ( +layout +) +{ +}, + +/** + * @method setUsingCustomScrollThreshold + * @param {bool} arg0 + */ +setUsingCustomScrollThreshold : function ( +bool +) +{ +}, + +/** + * @method setCustomScrollThreshold + * @param {float} arg0 + */ +setCustomScrollThreshold : function ( +float +) +{ +}, + +/** + * @method insertPage + * @param {ccui.Layout} arg0 + * @param {int} arg1 + */ +insertPage : function ( +layout, +int +) +{ +}, + +/** + * @method scrollToPage + * @param {long} arg0 + */ +scrollToPage : function ( +long +) +{ +}, + +/** + * @method removePageAtIndex + * @param {long} arg0 + */ +removePageAtIndex : function ( +long +) +{ +}, + +/** + * @method getPages + * @return {Array} + */ +getPages : function ( +) +{ + return new Array(); +}, + +/** + * @method removeAllPages + */ +removeAllPages : function ( +) +{ +}, + +/** + * @method addPage + * @param {ccui.Layout} arg0 + */ +addPage : function ( +layout +) +{ +}, + +/** + * @method create + * @return {ccui.PageView} + */ +create : function ( +) +{ + return ccui.PageView; +}, + +/** + * @method createInstance + * @return {cc.Ref} + */ +createInstance : function ( +) +{ + return cc.Ref; +}, + +/** + * @method PageView + * @constructor + */ +PageView : function ( +) +{ +}, + +}; + +/** + * @class Helper + */ +ccui.Helper = { + +/** + * @method getSubStringOfUTF8String + * @param {String} arg0 + * @param {unsigned long} arg1 + * @param {unsigned long} arg2 + * @return {String} + */ +getSubStringOfUTF8String : function ( +str, +long, +long +) +{ + return ; +}, + +/** + * @method changeLayoutSystemActiveState + * @param {bool} arg0 + */ +changeLayoutSystemActiveState : function ( +bool +) +{ +}, + +/** + * @method seekActionWidgetByActionTag + * @param {ccui.Widget} arg0 + * @param {int} arg1 + * @return {ccui.Widget} + */ +seekActionWidgetByActionTag : function ( +widget, +int +) +{ + return ccui.Widget; +}, + +/** + * @method seekWidgetByName + * @param {ccui.Widget} arg0 + * @param {String} arg1 + * @return {ccui.Widget} + */ +seekWidgetByName : function ( +widget, +str +) +{ + return ccui.Widget; +}, + +/** + * @method seekWidgetByTag + * @param {ccui.Widget} arg0 + * @param {int} arg1 + * @return {ccui.Widget} + */ +seekWidgetByTag : function ( +widget, +int +) +{ + return ccui.Widget; +}, + +/** + * @method restrictCapInsetRect + * @param {rect_object} arg0 + * @param {size_object} arg1 + * @return {rect_object} + */ +restrictCapInsetRect : function ( +rect, +size +) +{ + return cc.Rect; +}, + +/** + * @method doLayout + * @param {cc.Node} arg0 + */ +doLayout : function ( +node +) +{ +}, + +}; + +/** + * @class RichElement + */ +ccui.RichElement = { + +/** + * @method init + * @param {int} arg0 + * @param {color3b_object} arg1 + * @param {unsigned char} arg2 + * @return {bool} + */ +init : function ( +int, +color3b, +char +) +{ + return false; +}, + +/** + * @method RichElement + * @constructor + */ +RichElement : function ( +) +{ +}, + +}; + +/** + * @class RichElementText + */ +ccui.RichElementText = { + +/** + * @method init + * @param {int} arg0 + * @param {color3b_object} arg1 + * @param {unsigned char} arg2 + * @param {String} arg3 + * @param {String} arg4 + * @param {float} arg5 + * @return {bool} + */ +init : function ( +int, +color3b, +char, +str, +str, +float +) +{ + return false; +}, + +/** + * @method create + * @param {int} arg0 + * @param {color3b_object} arg1 + * @param {unsigned char} arg2 + * @param {String} arg3 + * @param {String} arg4 + * @param {float} arg5 + * @return {ccui.RichElementText} + */ +create : function ( +int, +color3b, +char, +str, +str, +float +) +{ + return ccui.RichElementText; +}, + +/** + * @method RichElementText + * @constructor + */ +RichElementText : function ( +) +{ +}, + +}; + +/** + * @class RichElementImage + */ +ccui.RichElementImage = { + +/** + * @method init + * @param {int} arg0 + * @param {color3b_object} arg1 + * @param {unsigned char} arg2 + * @param {String} arg3 + * @return {bool} + */ +init : function ( +int, +color3b, +char, +str +) +{ + return false; +}, + +/** + * @method create * @param {int} arg0 * @param {color3b_object} arg1 * @param {unsigned char} arg2 * @param {String} arg3 * @return {ccui.RichElementImage} */ -create : function ( -int, -color3b, -char, -str +create : function ( +int, +color3b, +char, +str +) +{ + return ccui.RichElementImage; +}, + +/** + * @method RichElementImage + * @constructor + */ +RichElementImage : function ( +) +{ +}, + +}; + +/** + * @class RichElementCustomNode + */ +ccui.RichElementCustomNode = { + +/** + * @method init + * @param {int} arg0 + * @param {color3b_object} arg1 + * @param {unsigned char} arg2 + * @param {cc.Node} arg3 + * @return {bool} + */ +init : function ( +int, +color3b, +char, +node +) +{ + return false; +}, + +/** + * @method create + * @param {int} arg0 + * @param {color3b_object} arg1 + * @param {unsigned char} arg2 + * @param {cc.Node} arg3 + * @return {ccui.RichElementCustomNode} + */ +create : function ( +int, +color3b, +char, +node +) +{ + return ccui.RichElementCustomNode; +}, + +/** + * @method RichElementCustomNode + * @constructor + */ +RichElementCustomNode : function ( +) +{ +}, + +}; + +/** + * @class RichText + */ +ccui.RichText = { + +/** + * @method insertElement + * @param {ccui.RichElement} arg0 + * @param {int} arg1 + */ +insertElement : function ( +richelement, +int +) +{ +}, + +/** + * @method pushBackElement + * @param {ccui.RichElement} arg0 + */ +pushBackElement : function ( +richelement +) +{ +}, + +/** + * @method setVerticalSpace + * @param {float} arg0 + */ +setVerticalSpace : function ( +float +) +{ +}, + +/** + * @method formatText + */ +formatText : function ( +) +{ +}, + +/** + * @method removeElement +* @param {ccui.RichElement|int} richelement +*/ +removeElement : function( +int +) +{ +}, + +/** + * @method create + * @return {ccui.RichText} + */ +create : function ( +) +{ + return ccui.RichText; +}, + +/** + * @method RichText + * @constructor + */ +RichText : function ( +) +{ +}, + +}; + +/** + * @class HBox + */ +ccui.HBox = { + +/** + * @method initWithSize + * @param {size_object} arg0 + * @return {bool} + */ +initWithSize : function ( +size +) +{ + return false; +}, + +/** + * @method create +* @param {size_object} size +* @return {ccui.HBox|ccui.HBox} +*/ +create : function( +size +) +{ + return ccui.HBox; +}, + +/** + * @method HBox + * @constructor + */ +HBox : function ( +) +{ +}, + +}; + +/** + * @class VBox + */ +ccui.VBox = { + +/** + * @method initWithSize + * @param {size_object} arg0 + * @return {bool} + */ +initWithSize : function ( +size +) +{ + return false; +}, + +/** + * @method create +* @param {size_object} size +* @return {ccui.VBox|ccui.VBox} +*/ +create : function( +size +) +{ + return ccui.VBox; +}, + +/** + * @method VBox + * @constructor + */ +VBox : function ( +) +{ +}, + +}; + +/** + * @class RelativeBox + */ +ccui.RelativeBox = { + +/** + * @method initWithSize + * @param {size_object} arg0 + * @return {bool} + */ +initWithSize : function ( +size +) +{ + return false; +}, + +/** + * @method create +* @param {size_object} size +* @return {ccui.RelativeBox|ccui.RelativeBox} +*/ +create : function( +size +) +{ + return ccui.RelativeBox; +}, + +/** + * @method RelativeBox + * @constructor + */ +RelativeBox : function ( +) +{ +}, + +}; + +/** + * @class Scale9Sprite + */ +ccui.Scale9Sprite = { + +/** + * @method disableCascadeColor + */ +disableCascadeColor : function ( +) +{ +}, + +/** + * @method updateWithSprite +* @param {cc.Sprite|cc.Sprite} sprite +* @param {rect_object|rect_object} rect +* @param {bool|bool} bool +* @param {vec2_object|rect_object} vec2 +* @param {size_object} size +* @param {rect_object} rect +* @return {bool|bool} +*/ +updateWithSprite : function( +sprite, +rect, +bool, +vec2, +size, +rect +) +{ + return false; +}, + +/** + * @method isFlippedX + * @return {bool} + */ +isFlippedX : function ( +) +{ + return false; +}, + +/** + * @method setScale9Enabled + * @param {bool} arg0 + */ +setScale9Enabled : function ( +bool +) +{ +}, + +/** + * @method setFlippedY + * @param {bool} arg0 + */ +setFlippedY : function ( +bool +) +{ +}, + +/** + * @method setFlippedX + * @param {bool} arg0 + */ +setFlippedX : function ( +bool +) +{ +}, + +/** + * @method resizableSpriteWithCapInsets + * @param {rect_object} arg0 + * @return {ccui.Scale9Sprite} + */ +resizableSpriteWithCapInsets : function ( +rect +) +{ + return ccui.Scale9Sprite; +}, + +/** + * @method disableCascadeOpacity + */ +disableCascadeOpacity : function ( +) +{ +}, + +/** + * @method setState + * @param {ccui.Scale9Sprite::State} arg0 + */ +setState : function ( +state +) +{ +}, + +/** + * @method setInsetBottom + * @param {float} arg0 + */ +setInsetBottom : function ( +float +) +{ +}, + +/** + * @method initWithSpriteFrameName +* @param {String|String} str +* @param {rect_object} rect +* @return {bool|bool} +*/ +initWithSpriteFrameName : function( +str, +rect +) +{ + return false; +}, + +/** + * @method getSprite + * @return {cc.Sprite} + */ +getSprite : function ( +) +{ + return cc.Sprite; +}, + +/** + * @method setInsetTop + * @param {float} arg0 + */ +setInsetTop : function ( +float +) +{ +}, + +/** + * @method init +* @param {cc.Sprite|cc.Sprite|cc.Sprite} sprite +* @param {rect_object|rect_object|rect_object} rect +* @param {rect_object|bool|bool} rect +* @param {rect_object|vec2_object} rect +* @param {size_object} size +* @param {rect_object} rect +* @return {bool|bool|bool} +*/ +init : function( +sprite, +rect, +bool, +vec2, +size, +rect +) +{ + return false; +}, + +/** + * @method setPreferredSize + * @param {size_object} arg0 + */ +setPreferredSize : function ( +size +) +{ +}, + +/** + * @method setSpriteFrame + * @param {cc.SpriteFrame} arg0 + * @param {rect_object} arg1 + */ +setSpriteFrame : function ( +spriteframe, +rect +) +{ +}, + +/** + * @method getBlendFunc + * @return {cc.BlendFunc} + */ +getBlendFunc : function ( +) +{ + return cc.BlendFunc; +}, + +/** + * @method getInsetBottom + * @return {float} + */ +getInsetBottom : function ( +) +{ + return 0; +}, + +/** + * @method getCapInsets + * @return {rect_object} + */ +getCapInsets : function ( ) { - return ccui.RichElementImage; + return cc.Rect; }, /** - * @method RichElementImage - * @constructor + * @method isScale9Enabled + * @return {bool} */ -RichElementImage : function ( +isScale9Enabled : function ( ) { + return false; }, -}; +/** + * @method getInsetRight + * @return {float} + */ +getInsetRight : function ( +) +{ + return 0; +}, /** - * @class RichElementCustomNode + * @method getOriginalSize + * @return {size_object} */ -ccui.RichElementCustomNode = { +getOriginalSize : function ( +) +{ + return cc.Size; +}, /** - * @method init - * @param {int} arg0 - * @param {color3b_object} arg1 - * @param {unsigned char} arg2 - * @param {cc.Node} arg3 + * @method initWithFile +* @param {String|String|rect_object|String} str +* @param {rect_object|rect_object|String} rect +* @param {rect_object} rect +* @return {bool|bool|bool|bool} +*/ +initWithFile : function( +str, +rect, +rect +) +{ + return false; +}, + +/** + * @method setBlendFunc + * @param {cc.BlendFunc} arg0 + */ +setBlendFunc : function ( +blendfunc +) +{ +}, + +/** + * @method getInsetTop + * @return {float} + */ +getInsetTop : function ( +) +{ + return 0; +}, + +/** + * @method setInsetLeft + * @param {float} arg0 + */ +setInsetLeft : function ( +float +) +{ +}, + +/** + * @method initWithSpriteFrame +* @param {cc.SpriteFrame|cc.SpriteFrame} spriteframe +* @param {rect_object} rect +* @return {bool|bool} +*/ +initWithSpriteFrame : function( +spriteframe, +rect +) +{ + return false; +}, + +/** + * @method getPreferredSize + * @return {size_object} + */ +getPreferredSize : function ( +) +{ + return cc.Size; +}, + +/** + * @method setCapInsets + * @param {rect_object} arg0 + */ +setCapInsets : function ( +rect +) +{ +}, + +/** + * @method isFlippedY * @return {bool} */ -init : function ( -int, -color3b, -char, -node +isFlippedY : function ( ) { return false; }, /** - * @method create - * @param {int} arg0 - * @param {color3b_object} arg1 - * @param {unsigned char} arg2 - * @param {cc.Node} arg3 - * @return {ccui.RichElementCustomNode} + * @method getInsetLeft + * @return {float} */ -create : function ( -int, -color3b, -char, -node +getInsetLeft : function ( ) { - return ccui.RichElementCustomNode; + return 0; }, /** - * @method RichElementCustomNode + * @method setInsetRight + * @param {float} arg0 + */ +setInsetRight : function ( +float +) +{ +}, + +/** + * @method create +* @param {String|rect_object|String|String} str +* @param {rect_object|String|rect_object} rect +* @param {rect_object} rect +* @return {ccui.Scale9Sprite|ccui.Scale9Sprite|ccui.Scale9Sprite|ccui.Scale9Sprite|ccui.Scale9Sprite} +*/ +create : function( +str, +rect, +rect +) +{ + return ccui.Scale9Sprite; +}, + +/** + * @method createWithSpriteFrameName +* @param {String|String} str +* @param {rect_object} rect +* @return {ccui.Scale9Sprite|ccui.Scale9Sprite} +*/ +createWithSpriteFrameName : function( +str, +rect +) +{ + return ccui.Scale9Sprite; +}, + +/** + * @method createWithSpriteFrame +* @param {cc.SpriteFrame|cc.SpriteFrame} spriteframe +* @param {rect_object} rect +* @return {ccui.Scale9Sprite|ccui.Scale9Sprite} +*/ +createWithSpriteFrame : function( +spriteframe, +rect +) +{ + return ccui.Scale9Sprite; +}, + +/** + * @method Scale9Sprite * @constructor */ -RichElementCustomNode : function ( +Scale9Sprite : function ( ) { }, @@ -4133,215 +5141,223 @@ RichElementCustomNode : function ( }; /** - * @class RichText + * @class EditBox */ -ccui.RichText = { +ccui.EditBox = { /** - * @method insertElement - * @param {ccui.RichElement} arg0 - * @param {int} arg1 + * @method getText + * @return {char} */ -insertElement : function ( -richelement, -int +getText : function ( ) { + return 0; }, /** - * @method setAnchorPoint - * @param {vec2_object} arg0 + * @method setFontSize + * @param {int} arg0 */ -setAnchorPoint : function ( -vec2 +setFontSize : function ( +int ) { }, /** - * @method pushBackElement - * @param {ccui.RichElement} arg0 + * @method setPlaceholderFontName + * @param {char} arg0 */ -pushBackElement : function ( -richelement +setPlaceholderFontName : function ( +char ) { }, /** - * @method ignoreContentAdaptWithSize - * @param {bool} arg0 + * @method getPlaceHolder + * @return {char} */ -ignoreContentAdaptWithSize : function ( -bool +getPlaceHolder : function ( ) { + return 0; }, /** - * @method setVerticalSpace - * @param {float} arg0 + * @method setFontName + * @param {char} arg0 */ -setVerticalSpace : function ( -float +setFontName : function ( +char ) { }, /** - * @method formatText + * @method setText + * @param {char} arg0 */ -formatText : function ( +setText : function ( +char ) { }, /** - * @method removeElement -* @param {ccui.RichElement|int} richelement -*/ -removeElement : function( + * @method setPlaceholderFontSize + * @param {int} arg0 + */ +setPlaceholderFontSize : function ( int ) { }, /** - * @method create - * @return {ccui.RichText} + * @method setInputMode + * @param {ccui.EditBox::InputMode} arg0 */ -create : function ( +setInputMode : function ( +inputmode ) { - return ccui.RichText; }, /** - * @method RichText - * @constructor - */ -RichText : function ( + * @method setPlaceholderFontColor +* @param {color4b_object|color3b_object} color4b +*/ +setPlaceholderFontColor : function( +color3b ) { }, -}; - /** - * @class HBox - */ -ccui.HBox = { + * @method setFontColor +* @param {color4b_object|color3b_object} color4b +*/ +setFontColor : function( +color3b +) +{ +}, /** - * @method initWithSize - * @param {size_object} arg0 - * @return {bool} + * @method setPlaceholderFont + * @param {char} arg0 + * @param {int} arg1 */ -initWithSize : function ( -size +setPlaceholderFont : function ( +char, +int ) { - return false; }, /** - * @method create -* @param {size_object} size -* @return {ccui.HBox|ccui.HBox} + * @method initWithSizeAndBackgroundSprite +* @param {size_object|size_object} size +* @param {ccui.Scale9Sprite|String} scale9sprite +* @param {ccui.Widget::TextureResType} texturerestype +* @return {bool|bool} */ -create : function( -size +initWithSizeAndBackgroundSprite : function( +size, +str, +texturerestype ) { - return ccui.HBox; + return false; }, /** - * @method HBox - * @constructor + * @method setPlaceHolder + * @param {char} arg0 */ -HBox : function ( +setPlaceHolder : function ( +char ) { }, -}; - -/** - * @class VBox - */ -ccui.VBox = { - /** - * @method initWithSize - * @param {size_object} arg0 - * @return {bool} + * @method setReturnType + * @param {ccui.EditBox::KeyboardReturnType} arg0 */ -initWithSize : function ( -size +setReturnType : function ( +keyboardreturntype ) { - return false; }, /** - * @method create -* @param {size_object} size -* @return {ccui.VBox|ccui.VBox} -*/ -create : function( -size + * @method setInputFlag + * @param {ccui.EditBox::InputFlag} arg0 + */ +setInputFlag : function ( +inputflag ) { - return ccui.VBox; }, /** - * @method VBox - * @constructor + * @method getMaxLength + * @return {int} */ -VBox : function ( +getMaxLength : function ( ) { + return 0; }, -}; - /** - * @class RelativeBox + * @method setMaxLength + * @param {int} arg0 */ -ccui.RelativeBox = { +setMaxLength : function ( +int +) +{ +}, /** - * @method initWithSize - * @param {size_object} arg0 - * @return {bool} + * @method setFont + * @param {char} arg0 + * @param {int} arg1 */ -initWithSize : function ( -size +setFont : function ( +char, +int ) { - return false; }, /** * @method create -* @param {size_object} size -* @return {ccui.RelativeBox|ccui.RelativeBox} +* @param {size_object|size_object} size +* @param {String|ccui.Scale9Sprite} str +* @param {ccui.Widget::TextureResType|ccui.Scale9Sprite} texturerestype +* @param {ccui.Scale9Sprite} scale9sprite +* @return {ccui.EditBox|ccui.EditBox} */ create : function( -size +size, +scale9sprite, +scale9sprite, +scale9sprite ) { - return ccui.RelativeBox; + return ccui.EditBox; }, /** - * @method RelativeBox + * @method EditBox * @constructor */ -RelativeBox : function ( +EditBox : function ( ) { }, @@ -4349,611 +5365,525 @@ RelativeBox : function ( }; /** - * @class Scale9Sprite + * @class LayoutComponent */ -ccui.Scale9Sprite = { +ccui.LayoutComponent = { /** - * @method disableCascadeColor + * @method setStretchWidthEnabled + * @param {bool} arg0 */ -disableCascadeColor : function ( +setStretchWidthEnabled : function ( +bool ) { }, /** - * @method updateWithSprite -* @param {cc.Sprite|cc.Sprite} sprite -* @param {rect_object|rect_object} rect -* @param {bool|bool} bool -* @param {vec2_object|rect_object} vec2 -* @param {size_object} size -* @param {rect_object} rect -* @return {bool|bool} -*/ -updateWithSprite : function( -sprite, -rect, -bool, -vec2, -size, -rect + * @method setPercentWidth + * @param {float} arg0 + */ +setPercentWidth : function ( +float ) { - return false; }, /** - * @method isFlippedX - * @return {bool} + * @method getAnchorPosition + * @return {vec2_object} */ -isFlippedX : function ( +getAnchorPosition : function ( ) { - return false; + return cc.Vec2; }, /** - * @method setFlippedY + * @method setPositionPercentXEnabled * @param {bool} arg0 */ -setFlippedY : function ( +setPositionPercentXEnabled : function ( bool ) { }, /** - * @method setFlippedX + * @method setStretchHeightEnabled * @param {bool} arg0 */ -setFlippedX : function ( +setStretchHeightEnabled : function ( bool ) { }, /** - * @method setScale9Enabled + * @method setActiveEnabled * @param {bool} arg0 */ -setScale9Enabled : function ( +setActiveEnabled : function ( bool ) { }, /** - * @method disableCascadeOpacity + * @method getRightMargin + * @return {float} */ -disableCascadeOpacity : function ( +getRightMargin : function ( ) { + return 0; }, /** - * @method setInsetBottom - * @param {float} arg0 + * @method getSize + * @return {size_object} */ -setInsetBottom : function ( -float +getSize : function ( ) { + return cc.Size; }, /** - * @method initWithSpriteFrameName -* @param {String|String} str -* @param {rect_object} rect -* @return {bool|bool} -*/ -initWithSpriteFrameName : function( -str, -rect + * @method setAnchorPosition + * @param {vec2_object} arg0 + */ +setAnchorPosition : function ( +vec2 ) { - return false; }, /** - * @method getSprite - * @return {cc.Sprite} + * @method refreshLayout */ -getSprite : function ( +refreshLayout : function ( ) { - return cc.Sprite; }, /** - * @method setInsetTop - * @param {float} arg0 + * @method isPercentWidthEnabled + * @return {bool} */ -setInsetTop : function ( -float +isPercentWidthEnabled : function ( ) { + return false; }, /** - * @method init -* @param {cc.Sprite|cc.Sprite|cc.Sprite} sprite -* @param {rect_object|rect_object|rect_object} rect -* @param {bool|rect_object|bool} bool -* @param {rect_object|vec2_object} rect -* @param {size_object} size -* @param {rect_object} rect -* @return {bool|bool|bool|bool} -*/ -init : function( -sprite, -rect, -bool, -vec2, -size, -rect + * @method setVerticalEdge + * @param {ccui.LayoutComponent::VerticalEdge} arg0 + */ +setVerticalEdge : function ( +verticaledge ) { - return false; }, /** - * @method setPreferredSize - * @param {size_object} arg0 + * @method getTopMargin + * @return {float} */ -setPreferredSize : function ( -size +getTopMargin : function ( ) { + return 0; }, /** - * @method getInsetRight - * @return {float} + * @method setSizeWidth + * @param {float} arg0 */ -getInsetRight : function ( +setSizeWidth : function ( +float ) { - return 0; }, /** - * @method setSpriteFrame - * @param {cc.SpriteFrame} arg0 - * @param {rect_object} arg1 + * @method getPercentContentSize + * @return {vec2_object} */ -setSpriteFrame : function ( -spriteframe, -rect +getPercentContentSize : function ( ) { + return cc.Vec2; }, /** - * @method getInsetBottom - * @return {float} + * @method getVerticalEdge + * @return {ccui.LayoutComponent::VerticalEdge} */ -getInsetBottom : function ( +getVerticalEdge : function ( ) { return 0; }, /** - * @method resizableSpriteWithCapInsets - * @param {rect_object} arg0 - * @return {ccui.Scale9Sprite} + * @method setPercentWidthEnabled + * @param {bool} arg0 */ -resizableSpriteWithCapInsets : function ( -rect +setPercentWidthEnabled : function ( +bool ) { - return ccui.Scale9Sprite; }, /** - * @method isScale9Enabled + * @method isStretchWidthEnabled * @return {bool} */ -isScale9Enabled : function ( +isStretchWidthEnabled : function ( ) { return false; }, /** - * @method getCapInsets - * @return {rect_object} + * @method setLeftMargin + * @param {float} arg0 */ -getCapInsets : function ( +setLeftMargin : function ( +float ) { - return cc.Rect; }, /** - * @method getOriginalSize - * @return {size_object} + * @method getSizeWidth + * @return {float} */ -getOriginalSize : function ( +getSizeWidth : function ( ) { - return cc.Size; + return 0; }, /** - * @method initWithFile -* @param {String|String|rect_object|String} str -* @param {rect_object|rect_object|String} rect -* @param {rect_object} rect -* @return {bool|bool|bool|bool} -*/ -initWithFile : function( -str, -rect, -rect + * @method setPositionPercentYEnabled + * @param {bool} arg0 + */ +setPositionPercentYEnabled : function ( +bool ) { - return false; }, /** - * @method getInsetTop + * @method getSizeHeight * @return {float} */ -getInsetTop : function ( +getSizeHeight : function ( ) { return 0; }, /** - * @method setInsetLeft - * @param {float} arg0 + * @method getPositionPercentY + * @return {float} */ -setInsetLeft : function ( -float +getPositionPercentY : function ( ) { + return 0; }, /** - * @method initWithSpriteFrame -* @param {cc.SpriteFrame|cc.SpriteFrame} spriteframe -* @param {rect_object} rect -* @return {bool|bool} -*/ -initWithSpriteFrame : function( -spriteframe, -rect + * @method getPositionPercentX + * @return {float} + */ +getPositionPercentX : function ( ) { - return false; + return 0; }, /** - * @method getPreferredSize - * @return {size_object} + * @method setTopMargin + * @param {float} arg0 */ -getPreferredSize : function ( +setTopMargin : function ( +float ) { - return cc.Size; }, /** - * @method setCapInsets - * @param {rect_object} arg0 + * @method getPercentHeight + * @return {float} */ -setCapInsets : function ( -rect +getPercentHeight : function ( ) { + return 0; }, /** - * @method isFlippedY + * @method getUsingPercentContentSize * @return {bool} */ -isFlippedY : function ( +getUsingPercentContentSize : function ( ) { return false; }, /** - * @method getInsetLeft - * @return {float} + * @method setPositionPercentY + * @param {float} arg0 */ -getInsetLeft : function ( +setPositionPercentY : function ( +float ) { - return 0; }, /** - * @method setInsetRight + * @method setPositionPercentX * @param {float} arg0 */ -setInsetRight : function ( +setPositionPercentX : function ( float ) { }, /** - * @method create -* @param {String|rect_object|String|String} str -* @param {rect_object|String|rect_object} rect -* @param {rect_object} rect -* @return {ccui.Scale9Sprite|ccui.Scale9Sprite|ccui.Scale9Sprite|ccui.Scale9Sprite|ccui.Scale9Sprite} -*/ -create : function( -str, -rect, -rect + * @method setRightMargin + * @param {float} arg0 + */ +setRightMargin : function ( +float ) { - return ccui.Scale9Sprite; }, /** - * @method createWithSpriteFrameName -* @param {String|String} str -* @param {rect_object} rect -* @return {ccui.Scale9Sprite|ccui.Scale9Sprite} -*/ -createWithSpriteFrameName : function( -str, -rect + * @method isPositionPercentYEnabled + * @return {bool} + */ +isPositionPercentYEnabled : function ( ) { - return ccui.Scale9Sprite; + return false; }, /** - * @method createWithSpriteFrame -* @param {cc.SpriteFrame|cc.SpriteFrame} spriteframe -* @param {rect_object} rect -* @return {ccui.Scale9Sprite|ccui.Scale9Sprite} -*/ -createWithSpriteFrame : function( -spriteframe, -rect + * @method setPercentHeight + * @param {float} arg0 + */ +setPercentHeight : function ( +float ) { - return ccui.Scale9Sprite; }, /** - * @method Scale9Sprite - * @constructor + * @method setPercentOnlyEnabled + * @param {bool} arg0 */ -Scale9Sprite : function ( +setPercentOnlyEnabled : function ( +bool ) { }, -}; - /** - * @class EditBox - */ -ccui.EditBox = { - -/** - * @method getText - * @return {char} + * @method setHorizontalEdge + * @param {ccui.LayoutComponent::HorizontalEdge} arg0 */ -getText : function ( +setHorizontalEdge : function ( +horizontaledge ) { - return 0; }, /** - * @method setFontSize - * @param {int} arg0 + * @method setPosition + * @param {vec2_object} arg0 */ -setFontSize : function ( -int +setPosition : function ( +vec2 ) { }, /** - * @method setPlaceholderFontName - * @param {char} arg0 + * @method setUsingPercentContentSize + * @param {bool} arg0 */ -setPlaceholderFontName : function ( -char +setUsingPercentContentSize : function ( +bool ) { }, /** - * @method getPlaceHolder - * @return {char} + * @method getLeftMargin + * @return {float} */ -getPlaceHolder : function ( +getLeftMargin : function ( ) { return 0; }, /** - * @method setFontName - * @param {char} arg0 + * @method getPosition + * @return {vec2_object} */ -setFontName : function ( -char +getPosition : function ( ) { + return cc.Vec2; }, /** - * @method setText - * @param {char} arg0 + * @method setSizeHeight + * @param {float} arg0 */ -setText : function ( -char +setSizeHeight : function ( +float ) { }, /** - * @method setPlaceholderFontSize - * @param {int} arg0 + * @method isPositionPercentXEnabled + * @return {bool} */ -setPlaceholderFontSize : function ( -int +isPositionPercentXEnabled : function ( ) { + return false; }, /** - * @method setInputMode - * @param {ccui.EditBox::InputMode} arg0 + * @method getBottomMargin + * @return {float} */ -setInputMode : function ( -inputmode +getBottomMargin : function ( ) { + return 0; }, /** - * @method setPlaceholderFontColor - * @param {color3b_object} arg0 + * @method setPercentHeightEnabled + * @param {bool} arg0 */ -setPlaceholderFontColor : function ( -color3b +setPercentHeightEnabled : function ( +bool ) { }, /** - * @method setFontColor - * @param {color3b_object} arg0 + * @method setPercentContentSize + * @param {vec2_object} arg0 */ -setFontColor : function ( -color3b +setPercentContentSize : function ( +vec2 ) { }, /** - * @method setPlaceholderFont - * @param {char} arg0 - * @param {int} arg1 + * @method isPercentHeightEnabled + * @return {bool} */ -setPlaceholderFont : function ( -char, -int -) -{ -}, - -/** - * @method initWithSizeAndBackgroundSprite -* @param {size_object|size_object} size -* @param {ccui.Scale9Sprite|String} scale9sprite -* @param {ccui.Widget::TextureResType} texturerestype -* @return {bool|bool} -*/ -initWithSizeAndBackgroundSprite : function( -size, -str, -texturerestype +isPercentHeightEnabled : function ( ) { return false; }, /** - * @method setPlaceHolder - * @param {char} arg0 + * @method getPercentWidth + * @return {float} */ -setPlaceHolder : function ( -char +getPercentWidth : function ( ) { + return 0; }, /** - * @method setReturnType - * @param {ccui.EditBox::KeyboardReturnType} arg0 + * @method getHorizontalEdge + * @return {ccui.LayoutComponent::HorizontalEdge} */ -setReturnType : function ( -keyboardreturntype +getHorizontalEdge : function ( ) { + return 0; }, /** - * @method setInputFlag - * @param {ccui.EditBox::InputFlag} arg0 + * @method isStretchHeightEnabled + * @return {bool} */ -setInputFlag : function ( -inputflag +isStretchHeightEnabled : function ( ) { + return false; }, /** - * @method getMaxLength - * @return {int} + * @method setBottomMargin + * @param {float} arg0 */ -getMaxLength : function ( +setBottomMargin : function ( +float ) { - return 0; }, /** - * @method setMaxLength - * @param {int} arg0 + * @method setSize + * @param {size_object} arg0 */ -setMaxLength : function ( -int +setSize : function ( +size ) { }, /** - * @method setFont - * @param {char} arg0 - * @param {int} arg1 + * @method create + * @return {ccui.LayoutComponent} */ -setFont : function ( -char, -int +create : function ( ) { + return ccui.LayoutComponent; }, /** - * @method create -* @param {size_object|size_object} size -* @param {String|ccui.Scale9Sprite} str -* @param {ccui.Widget::TextureResType|ccui.Scale9Sprite} texturerestype -* @param {ccui.Scale9Sprite} scale9sprite -* @return {ccui.EditBox|ccui.EditBox} -*/ -create : function( -size, -scale9sprite, -scale9sprite, -scale9sprite + * @method bindLayoutComponent + * @param {cc.Node} arg0 + * @return {ccui.LayoutComponent} + */ +bindLayoutComponent : function ( +node ) { - return ccui.EditBox; + return ccui.LayoutComponent; }, /** - * @method EditBox + * @method LayoutComponent * @constructor */ -EditBox : function ( +LayoutComponent : function ( ) { }, diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_auto.cpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_auto.cpp new file mode 100644 index 0000000000..4ca9eedcc6 --- /dev/null +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_auto.cpp @@ -0,0 +1,3229 @@ +#include "jsb_cocos2dx_3d_auto.hpp" +#include "cocos2d_specifics.hpp" +#include "cocos2d.h" + +template +static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedValue initializing(cx); + bool isNewValid = true; + JS::RootedObject global(cx, ScriptingCore::getInstance()->getGlobalObject()); + isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && initializing.toBoolean(); + if (isNewValid) + { + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject _tmp(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + + args.rval().set(OBJECT_TO_JSVAL(_tmp)); + return true; + } + + JS_ReportError(cx, "Constructor for the requested class is not available, please refer to the API reference."); + return false; +} + +static bool empty_constructor(JSContext *cx, uint32_t argc, jsval *vp) { + return false; +} + +static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setBoolean(true); + return true; +} +JSClass *jsb_cocos2d_Skeleton3D_class; +JSObject *jsb_cocos2d_Skeleton3D_prototype; + +bool js_cocos2dx_3d_Skeleton3D_removeAllBones(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Skeleton3D* cobj = (cocos2d::Skeleton3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Skeleton3D_removeAllBones : Invalid Native Object"); + if (argc == 0) { + cobj->removeAllBones(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Skeleton3D_removeAllBones : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Skeleton3D_addBone(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Skeleton3D* cobj = (cocos2d::Skeleton3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Skeleton3D_addBone : Invalid Native Object"); + if (argc == 1) { + cocos2d::Bone3D* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Bone3D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Skeleton3D_addBone : Error processing arguments"); + cobj->addBone(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Skeleton3D_addBone : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Skeleton3D_getBoneByName(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Skeleton3D* cobj = (cocos2d::Skeleton3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Skeleton3D_getBoneByName : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Skeleton3D_getBoneByName : Error processing arguments"); + cocos2d::Bone3D* ret = cobj->getBoneByName(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Bone3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Skeleton3D_getBoneByName : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Skeleton3D_getRootBone(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Skeleton3D* cobj = (cocos2d::Skeleton3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Skeleton3D_getRootBone : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Skeleton3D_getRootBone : Error processing arguments"); + cocos2d::Bone3D* ret = cobj->getRootBone(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Bone3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Skeleton3D_getRootBone : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Skeleton3D_updateBoneMatrix(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Skeleton3D* cobj = (cocos2d::Skeleton3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Skeleton3D_updateBoneMatrix : Invalid Native Object"); + if (argc == 0) { + cobj->updateBoneMatrix(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Skeleton3D_updateBoneMatrix : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Skeleton3D_getBoneByIndex(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Skeleton3D* cobj = (cocos2d::Skeleton3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Skeleton3D_getBoneByIndex : Invalid Native Object"); + if (argc == 1) { + unsigned int arg0; + ok &= jsval_to_uint32(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Skeleton3D_getBoneByIndex : Error processing arguments"); + cocos2d::Bone3D* ret = cobj->getBoneByIndex(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Bone3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Skeleton3D_getBoneByIndex : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Skeleton3D_getRootCount(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Skeleton3D* cobj = (cocos2d::Skeleton3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Skeleton3D_getRootCount : Invalid Native Object"); + if (argc == 0) { + ssize_t ret = cobj->getRootCount(); + jsval jsret = JSVAL_NULL; + jsret = ssize_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Skeleton3D_getRootCount : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Skeleton3D_getBoneIndex(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Skeleton3D* cobj = (cocos2d::Skeleton3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Skeleton3D_getBoneIndex : Invalid Native Object"); + if (argc == 1) { + cocos2d::Bone3D* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Bone3D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Skeleton3D_getBoneIndex : Error processing arguments"); + int ret = cobj->getBoneIndex(arg0); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Skeleton3D_getBoneIndex : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Skeleton3D_getBoneCount(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Skeleton3D* cobj = (cocos2d::Skeleton3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Skeleton3D_getBoneCount : Invalid Native Object"); + if (argc == 0) { + ssize_t ret = cobj->getBoneCount(); + jsval jsret = JSVAL_NULL; + jsret = ssize_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Skeleton3D_getBoneCount : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Skeleton3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::Skeleton3D* cobj = new (std::nothrow) cocos2d::Skeleton3D(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Skeleton3D"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + + +void js_cocos2d_Skeleton3D_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (Skeleton3D)", obj); +} + +void js_register_cocos2dx_3d_Skeleton3D(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_Skeleton3D_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_Skeleton3D_class->name = "Skeleton3D"; + jsb_cocos2d_Skeleton3D_class->addProperty = JS_PropertyStub; + jsb_cocos2d_Skeleton3D_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_Skeleton3D_class->getProperty = JS_PropertyStub; + jsb_cocos2d_Skeleton3D_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_Skeleton3D_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_Skeleton3D_class->resolve = JS_ResolveStub; + jsb_cocos2d_Skeleton3D_class->convert = JS_ConvertStub; + jsb_cocos2d_Skeleton3D_class->finalize = js_cocos2d_Skeleton3D_finalize; + jsb_cocos2d_Skeleton3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("removeAllBones", js_cocos2dx_3d_Skeleton3D_removeAllBones, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("addBone", js_cocos2dx_3d_Skeleton3D_addBone, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getBoneByName", js_cocos2dx_3d_Skeleton3D_getBoneByName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getRootBone", js_cocos2dx_3d_Skeleton3D_getRootBone, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("updateBoneMatrix", js_cocos2dx_3d_Skeleton3D_updateBoneMatrix, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getBoneByIndex", js_cocos2dx_3d_Skeleton3D_getBoneByIndex, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getRootCount", js_cocos2dx_3d_Skeleton3D_getRootCount, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getBoneIndex", js_cocos2dx_3d_Skeleton3D_getBoneIndex, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getBoneCount", js_cocos2dx_3d_Skeleton3D_getBoneCount, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + JSFunctionSpec *st_funcs = NULL; + + jsb_cocos2d_Skeleton3D_prototype = JS_InitClass( + cx, global, + JS::NullPtr(), // parent proto + jsb_cocos2d_Skeleton3D_class, + js_cocos2dx_3d_Skeleton3D_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "Skeleton3D", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_Skeleton3D_class; + p->proto = jsb_cocos2d_Skeleton3D_prototype; + p->parentProto = NULL; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_Sprite3D_class; +JSObject *jsb_cocos2d_Sprite3D_prototype; + +bool js_cocos2dx_3d_Sprite3D_setCullFaceEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_setCullFaceEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_setCullFaceEnabled : Error processing arguments"); + cobj->setCullFaceEnabled(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_setCullFaceEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3D_setTexture(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + JS::RootedObject obj(cx); + cocos2d::Sprite3D* cobj = NULL; + obj = args.thisv().toObjectOrNull(); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_setTexture : Invalid Native Object"); + do { + if (argc == 1) { + cocos2d::Texture2D* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cobj->setTexture(arg0); + args.rval().setUndefined(); + return true; + } + } while(0); + + do { + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cobj->setTexture(arg0); + args.rval().setUndefined(); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_setTexture : wrong number of arguments"); + return false; +} +bool js_cocos2dx_3d_Sprite3D_getLightMask(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_getLightMask : Invalid Native Object"); + if (argc == 0) { + unsigned int ret = cobj->getLightMask(); + jsval jsret = JSVAL_NULL; + jsret = uint32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_getLightMask : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Sprite3D_createAttachSprite3DNode(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_createAttachSprite3DNode : Invalid Native Object"); + if (argc == 2) { + cocos2d::NodeData* arg0; + cocos2d::MaterialDatas arg1; + #pragma warning NO CONVERSION TO NATIVE FOR NodeData* + ok = false; + #pragma warning NO CONVERSION TO NATIVE FOR MaterialDatas + ok = false; + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_createAttachSprite3DNode : Error processing arguments"); + cobj->createAttachSprite3DNode(arg0, arg1); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_createAttachSprite3DNode : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} +bool js_cocos2dx_3d_Sprite3D_loadFromFile(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_loadFromFile : Invalid Native Object"); + if (argc == 4) { + std::string arg0; + cocos2d::NodeDatas* arg1; + cocos2d::MeshDatas* arg2; + cocos2d::MaterialDatas* arg3; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + #pragma warning NO CONVERSION TO NATIVE FOR NodeDatas* + ok = false; + #pragma warning NO CONVERSION TO NATIVE FOR MeshDatas* + ok = false; + #pragma warning NO CONVERSION TO NATIVE FOR MaterialDatas* + ok = false; + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_loadFromFile : Error processing arguments"); + bool ret = cobj->loadFromFile(arg0, arg1, arg2, arg3); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_loadFromFile : wrong number of arguments: %d, was expecting %d", argc, 4); + return false; +} +bool js_cocos2dx_3d_Sprite3D_setCullFace(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_setCullFace : Invalid Native Object"); + if (argc == 1) { + unsigned int arg0; + ok &= jsval_to_uint32(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_setCullFace : Error processing arguments"); + cobj->setCullFace(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_setCullFace : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3D_addMesh(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_addMesh : Invalid Native Object"); + if (argc == 1) { + cocos2d::Mesh* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Mesh*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_addMesh : Error processing arguments"); + cobj->addMesh(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_addMesh : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3D_removeAllAttachNode(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_removeAllAttachNode : Invalid Native Object"); + if (argc == 0) { + cobj->removeAllAttachNode(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_removeAllAttachNode : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Sprite3D_genGLProgramState(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_genGLProgramState : Invalid Native Object"); + if (argc == 0) { + cobj->genGLProgramState(); + args.rval().setUndefined(); + return true; + } + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_genGLProgramState : Error processing arguments"); + cobj->genGLProgramState(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_genGLProgramState : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Sprite3D_getMesh(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_getMesh : Invalid Native Object"); + if (argc == 0) { + cocos2d::Mesh* ret = cobj->getMesh(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Mesh*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_getMesh : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Sprite3D_createSprite3DNode(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_createSprite3DNode : Invalid Native Object"); + if (argc == 3) { + cocos2d::NodeData* arg0; + cocos2d::ModelData* arg1; + cocos2d::MaterialDatas arg2; + #pragma warning NO CONVERSION TO NATIVE FOR NodeData* + ok = false; + #pragma warning NO CONVERSION TO NATIVE FOR ModelData* + ok = false; + #pragma warning NO CONVERSION TO NATIVE FOR MaterialDatas + ok = false; + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_createSprite3DNode : Error processing arguments"); + cocos2d::Sprite3D* ret = cobj->createSprite3DNode(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_createSprite3DNode : wrong number of arguments: %d, was expecting %d", argc, 3); + return false; +} +bool js_cocos2dx_3d_Sprite3D_getMeshCount(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_getMeshCount : Invalid Native Object"); + if (argc == 0) { + ssize_t ret = cobj->getMeshCount(); + jsval jsret = JSVAL_NULL; + jsret = ssize_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_getMeshCount : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Sprite3D_onAABBDirty(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_onAABBDirty : Invalid Native Object"); + if (argc == 0) { + cobj->onAABBDirty(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_onAABBDirty : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Sprite3D_getMeshByIndex(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_getMeshByIndex : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_getMeshByIndex : Error processing arguments"); + cocos2d::Mesh* ret = cobj->getMeshByIndex(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Mesh*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_getMeshByIndex : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3D_createNode(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_createNode : Invalid Native Object"); + if (argc == 4) { + cocos2d::NodeData* arg0; + cocos2d::Node* arg1; + cocos2d::MaterialDatas arg2; + bool arg3; + #pragma warning NO CONVERSION TO NATIVE FOR NodeData* + ok = false; + do { + if (!args.get(1).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(1).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg1 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); + } while (0); + #pragma warning NO CONVERSION TO NATIVE FOR MaterialDatas + ok = false; + arg3 = JS::ToBoolean(args.get(3)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_createNode : Error processing arguments"); + cobj->createNode(arg0, arg1, arg2, arg3); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_createNode : wrong number of arguments: %d, was expecting %d", argc, 4); + return false; +} +bool js_cocos2dx_3d_Sprite3D_isForceDepthWrite(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_isForceDepthWrite : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isForceDepthWrite(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_isForceDepthWrite : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Sprite3D_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_getBlendFunc : Invalid Native Object"); + if (argc == 0) { + const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); + jsval jsret = JSVAL_NULL; + jsret = blendfunc_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_getBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Sprite3D_getMeshIndexData(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_getMeshIndexData : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_getMeshIndexData : Error processing arguments"); + cocos2d::MeshIndexData* ret = cobj->getMeshIndexData(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::MeshIndexData*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_getMeshIndexData : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3D_removeAttachNode(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_removeAttachNode : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_removeAttachNode : Error processing arguments"); + cobj->removeAttachNode(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_removeAttachNode : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3D_setLightMask(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_setLightMask : Invalid Native Object"); + if (argc == 1) { + unsigned int arg0; + ok &= jsval_to_uint32(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_setLightMask : Error processing arguments"); + cobj->setLightMask(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_setLightMask : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3D_afterAsyncLoad(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_afterAsyncLoad : Invalid Native Object"); + if (argc == 1) { + void* arg0; + #pragma warning NO CONVERSION TO NATIVE FOR void* + ok = false; + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_afterAsyncLoad : Error processing arguments"); + cobj->afterAsyncLoad(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_afterAsyncLoad : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3D_loadFromCache(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_loadFromCache : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_loadFromCache : Error processing arguments"); + bool ret = cobj->loadFromCache(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_loadFromCache : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3D_initFrom(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_initFrom : Invalid Native Object"); + if (argc == 3) { + cocos2d::NodeDatas arg0; + cocos2d::MeshDatas arg1; + cocos2d::MaterialDatas arg2; + #pragma warning NO CONVERSION TO NATIVE FOR NodeDatas + ok = false; + #pragma warning NO CONVERSION TO NATIVE FOR MeshDatas + ok = false; + #pragma warning NO CONVERSION TO NATIVE FOR MaterialDatas + ok = false; + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_initFrom : Error processing arguments"); + bool ret = cobj->initFrom(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_initFrom : wrong number of arguments: %d, was expecting %d", argc, 3); + return false; +} +bool js_cocos2dx_3d_Sprite3D_getAttachNode(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_getAttachNode : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_getAttachNode : Error processing arguments"); + cocos2d::AttachNode* ret = cobj->getAttachNode(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::AttachNode*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_getAttachNode : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3D_initWithFile(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_initWithFile : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_initWithFile : Error processing arguments"); + bool ret = cobj->initWithFile(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_initWithFile : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3D_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_setBlendFunc : Invalid Native Object"); + if (argc == 1) { + cocos2d::BlendFunc arg0; + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_setBlendFunc : Error processing arguments"); + cobj->setBlendFunc(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_setBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3D_getSkeleton(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_getSkeleton : Invalid Native Object"); + if (argc == 0) { + cocos2d::Skeleton3D* ret = cobj->getSkeleton(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Skeleton3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_getSkeleton : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Sprite3D_setForceDepthWrite(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_setForceDepthWrite : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_setForceDepthWrite : Error processing arguments"); + cobj->setForceDepthWrite(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_setForceDepthWrite : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3D_getMeshByName(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_getMeshByName : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_getMeshByName : Error processing arguments"); + cocos2d::Mesh* ret = cobj->getMeshByName(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Mesh*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_getMeshByName : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3D_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + do { + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::Sprite3D* ret = cocos2d::Sprite3D::create(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 0) { + cocos2d::Sprite3D* ret = cocos2d::Sprite3D::create(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::Sprite3D* ret = cocos2d::Sprite3D::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3D_create : wrong number of arguments"); + return false; +} +bool js_cocos2dx_3d_Sprite3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::Sprite3D* cobj = new (std::nothrow) cocos2d::Sprite3D(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Sprite3D"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocos2d_Node_prototype; + +void js_cocos2d_Sprite3D_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (Sprite3D)", obj); +} + +static bool js_cocos2d_Sprite3D_ctor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::Sprite3D *nobj = new (std::nothrow) cocos2d::Sprite3D(); + if (nobj) { + nobj->autorelease(); + } + js_proxy_t* p = jsb_new_proxy(nobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Sprite3D"); + bool isFound = false; + if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); + return true; +} +void js_register_cocos2dx_3d_Sprite3D(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_Sprite3D_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_Sprite3D_class->name = "Sprite3D"; + jsb_cocos2d_Sprite3D_class->addProperty = JS_PropertyStub; + jsb_cocos2d_Sprite3D_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_Sprite3D_class->getProperty = JS_PropertyStub; + jsb_cocos2d_Sprite3D_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_Sprite3D_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_Sprite3D_class->resolve = JS_ResolveStub; + jsb_cocos2d_Sprite3D_class->convert = JS_ConvertStub; + jsb_cocos2d_Sprite3D_class->finalize = js_cocos2d_Sprite3D_finalize; + jsb_cocos2d_Sprite3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("setCullFaceEnabled", js_cocos2dx_3d_Sprite3D_setCullFaceEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setTexture", js_cocos2dx_3d_Sprite3D_setTexture, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getLightMask", js_cocos2dx_3d_Sprite3D_getLightMask, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("createAttachSprite3DNode", js_cocos2dx_3d_Sprite3D_createAttachSprite3DNode, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("loadFromFile", js_cocos2dx_3d_Sprite3D_loadFromFile, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setCullFace", js_cocos2dx_3d_Sprite3D_setCullFace, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("addMesh", js_cocos2dx_3d_Sprite3D_addMesh, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("removeAllAttachNode", js_cocos2dx_3d_Sprite3D_removeAllAttachNode, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("genGLProgramState", js_cocos2dx_3d_Sprite3D_genGLProgramState, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMesh", js_cocos2dx_3d_Sprite3D_getMesh, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("createSprite3DNode", js_cocos2dx_3d_Sprite3D_createSprite3DNode, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMeshCount", js_cocos2dx_3d_Sprite3D_getMeshCount, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("onAABBDirty", js_cocos2dx_3d_Sprite3D_onAABBDirty, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMeshByIndex", js_cocos2dx_3d_Sprite3D_getMeshByIndex, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("createNode", js_cocos2dx_3d_Sprite3D_createNode, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isForceDepthWrite", js_cocos2dx_3d_Sprite3D_isForceDepthWrite, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getBlendFunc", js_cocos2dx_3d_Sprite3D_getBlendFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMeshIndexData", js_cocos2dx_3d_Sprite3D_getMeshIndexData, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("removeAttachNode", js_cocos2dx_3d_Sprite3D_removeAttachNode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setLightMask", js_cocos2dx_3d_Sprite3D_setLightMask, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("afterAsyncLoad", js_cocos2dx_3d_Sprite3D_afterAsyncLoad, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("loadFromCache", js_cocos2dx_3d_Sprite3D_loadFromCache, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initFrom", js_cocos2dx_3d_Sprite3D_initFrom, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getAttachNode", js_cocos2dx_3d_Sprite3D_getAttachNode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithFile", js_cocos2dx_3d_Sprite3D_initWithFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setBlendFunc", js_cocos2dx_3d_Sprite3D_setBlendFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getSkeleton", js_cocos2dx_3d_Sprite3D_getSkeleton, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setForceDepthWrite", js_cocos2dx_3d_Sprite3D_setForceDepthWrite, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMeshByName", js_cocos2dx_3d_Sprite3D_getMeshByName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_Sprite3D_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_3d_Sprite3D_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_Sprite3D_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), + jsb_cocos2d_Sprite3D_class, + js_cocos2dx_3d_Sprite3D_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "Sprite3D", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_Sprite3D_class; + p->proto = jsb_cocos2d_Sprite3D_prototype; + p->parentProto = jsb_cocos2d_Node_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_Sprite3DCache_class; +JSObject *jsb_cocos2d_Sprite3DCache_prototype; + +bool js_cocos2dx_3d_Sprite3DCache_removeSprite3DData(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3DCache* cobj = (cocos2d::Sprite3DCache *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3DCache_removeSprite3DData : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3DCache_removeSprite3DData : Error processing arguments"); + cobj->removeSprite3DData(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3DCache_removeSprite3DData : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Sprite3DCache_removeAllSprite3DData(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3DCache* cobj = (cocos2d::Sprite3DCache *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3DCache_removeAllSprite3DData : Invalid Native Object"); + if (argc == 0) { + cobj->removeAllSprite3DData(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3DCache_removeAllSprite3DData : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Sprite3DCache_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (argc == 0) { + cocos2d::Sprite3DCache::destroyInstance(); + args.rval().setUndefined(); + return true; + } + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3DCache_destroyInstance : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_3d_Sprite3DCache_getInstance(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (argc == 0) { + cocos2d::Sprite3DCache* ret = cocos2d::Sprite3DCache::getInstance(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite3DCache*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_3d_Sprite3DCache_getInstance : wrong number of arguments"); + return false; +} + + + +void js_cocos2d_Sprite3DCache_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (Sprite3DCache)", obj); +} + +void js_register_cocos2dx_3d_Sprite3DCache(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_Sprite3DCache_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_Sprite3DCache_class->name = "Sprite3DCache"; + jsb_cocos2d_Sprite3DCache_class->addProperty = JS_PropertyStub; + jsb_cocos2d_Sprite3DCache_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_Sprite3DCache_class->getProperty = JS_PropertyStub; + jsb_cocos2d_Sprite3DCache_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_Sprite3DCache_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_Sprite3DCache_class->resolve = JS_ResolveStub; + jsb_cocos2d_Sprite3DCache_class->convert = JS_ConvertStub; + jsb_cocos2d_Sprite3DCache_class->finalize = js_cocos2d_Sprite3DCache_finalize; + jsb_cocos2d_Sprite3DCache_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("removeSprite3DData", js_cocos2dx_3d_Sprite3DCache_removeSprite3DData, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("removeAllSprite3DData", js_cocos2dx_3d_Sprite3DCache_removeAllSprite3DData, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("destroyInstance", js_cocos2dx_3d_Sprite3DCache_destroyInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getInstance", js_cocos2dx_3d_Sprite3DCache_getInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_Sprite3DCache_prototype = JS_InitClass( + cx, global, + JS::NullPtr(), // parent proto + jsb_cocos2d_Sprite3DCache_class, + empty_constructor, 0, + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "Sprite3DCache", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_Sprite3DCache_class; + p->proto = jsb_cocos2d_Sprite3DCache_prototype; + p->parentProto = NULL; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_Mesh_class; +JSObject *jsb_cocos2d_Mesh_prototype; + +bool js_cocos2dx_3d_Mesh_setTexture(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + JS::RootedObject obj(cx); + cocos2d::Mesh* cobj = NULL; + obj = args.thisv().toObjectOrNull(); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_setTexture : Invalid Native Object"); + do { + if (argc == 1) { + cocos2d::Texture2D* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cobj->setTexture(arg0); + args.rval().setUndefined(); + return true; + } + } while(0); + + do { + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cobj->setTexture(arg0); + args.rval().setUndefined(); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_setTexture : wrong number of arguments"); + return false; +} +bool js_cocos2dx_3d_Mesh_getTexture(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_getTexture : Invalid Native Object"); + if (argc == 0) { + cocos2d::Texture2D* ret = cobj->getTexture(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Texture2D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_getTexture : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_getSkin(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_getSkin : Invalid Native Object"); + if (argc == 0) { + cocos2d::MeshSkin* ret = cobj->getSkin(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::MeshSkin*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_getSkin : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_getVertexSizeInBytes(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_getVertexSizeInBytes : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getVertexSizeInBytes(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_getVertexSizeInBytes : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_getName(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_getName : Invalid Native Object"); + if (argc == 0) { + const std::string& ret = cobj->getName(); + jsval jsret = JSVAL_NULL; + jsret = std_string_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_getName : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_getIndexFormat(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_getIndexFormat : Invalid Native Object"); + if (argc == 0) { + unsigned int ret = cobj->getIndexFormat(); + jsval jsret = JSVAL_NULL; + jsret = uint32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_getIndexFormat : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_getGLProgramState(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_getGLProgramState : Invalid Native Object"); + if (argc == 0) { + cocos2d::GLProgramState* ret = cobj->getGLProgramState(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::GLProgramState*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_getGLProgramState : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_getVertexBuffer(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_getVertexBuffer : Invalid Native Object"); + if (argc == 0) { + unsigned int ret = cobj->getVertexBuffer(); + jsval jsret = JSVAL_NULL; + jsret = uint32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_getVertexBuffer : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_calculateAABB(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_calculateAABB : Invalid Native Object"); + if (argc == 0) { + cobj->calculateAABB(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_calculateAABB : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_hasVertexAttrib(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_hasVertexAttrib : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Mesh_hasVertexAttrib : Error processing arguments"); + bool ret = cobj->hasVertexAttrib(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_hasVertexAttrib : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Mesh_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_getBlendFunc : Invalid Native Object"); + if (argc == 0) { + const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); + jsval jsret = JSVAL_NULL; + jsret = blendfunc_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_getBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_getMeshIndexData(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_getMeshIndexData : Invalid Native Object"); + if (argc == 0) { + cocos2d::MeshIndexData* ret = cobj->getMeshIndexData(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::MeshIndexData*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_getMeshIndexData : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_setName(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_setName : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Mesh_setName : Error processing arguments"); + cobj->setName(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_setName : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Mesh_isVisible(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_isVisible : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isVisible(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_isVisible : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_getIndexCount(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_getIndexCount : Invalid Native Object"); + if (argc == 0) { + ssize_t ret = cobj->getIndexCount(); + jsval jsret = JSVAL_NULL; + jsret = ssize_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_getIndexCount : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_bindMeshCommand(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_bindMeshCommand : Invalid Native Object"); + if (argc == 0) { + cobj->bindMeshCommand(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_bindMeshCommand : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_setMeshIndexData(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_setMeshIndexData : Invalid Native Object"); + if (argc == 1) { + cocos2d::MeshIndexData* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::MeshIndexData*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Mesh_setMeshIndexData : Error processing arguments"); + cobj->setMeshIndexData(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_setMeshIndexData : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Mesh_getMeshVertexAttribCount(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_getMeshVertexAttribCount : Invalid Native Object"); + if (argc == 0) { + ssize_t ret = cobj->getMeshVertexAttribCount(); + jsval jsret = JSVAL_NULL; + jsret = ssize_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_getMeshVertexAttribCount : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_setBlendFunc : Invalid Native Object"); + if (argc == 1) { + cocos2d::BlendFunc arg0; + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Mesh_setBlendFunc : Error processing arguments"); + cobj->setBlendFunc(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_setBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Mesh_getPrimitiveType(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_getPrimitiveType : Invalid Native Object"); + if (argc == 0) { + unsigned int ret = cobj->getPrimitiveType(); + jsval jsret = JSVAL_NULL; + jsret = uint32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_getPrimitiveType : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_setSkin(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_setSkin : Invalid Native Object"); + if (argc == 1) { + cocos2d::MeshSkin* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::MeshSkin*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Mesh_setSkin : Error processing arguments"); + cobj->setSkin(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_setSkin : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Mesh_getIndexBuffer(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_getIndexBuffer : Invalid Native Object"); + if (argc == 0) { + unsigned int ret = cobj->getIndexBuffer(); + jsval jsret = JSVAL_NULL; + jsret = uint32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_getIndexBuffer : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Mesh_setGLProgramState(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_setGLProgramState : Invalid Native Object"); + if (argc == 1) { + cocos2d::GLProgramState* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::GLProgramState*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Mesh_setGLProgramState : Error processing arguments"); + cobj->setGLProgramState(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_setGLProgramState : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Mesh_setVisible(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_setVisible : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Mesh_setVisible : Error processing arguments"); + cobj->setVisible(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_setVisible : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Mesh_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::Mesh* cobj = new (std::nothrow) cocos2d::Mesh(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Mesh"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + + +void js_cocos2d_Mesh_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (Mesh)", obj); +} + +void js_register_cocos2dx_3d_Mesh(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_Mesh_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_Mesh_class->name = "Mesh"; + jsb_cocos2d_Mesh_class->addProperty = JS_PropertyStub; + jsb_cocos2d_Mesh_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_Mesh_class->getProperty = JS_PropertyStub; + jsb_cocos2d_Mesh_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_Mesh_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_Mesh_class->resolve = JS_ResolveStub; + jsb_cocos2d_Mesh_class->convert = JS_ConvertStub; + jsb_cocos2d_Mesh_class->finalize = js_cocos2d_Mesh_finalize; + jsb_cocos2d_Mesh_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("setTexture", js_cocos2dx_3d_Mesh_setTexture, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getTexture", js_cocos2dx_3d_Mesh_getTexture, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getSkin", js_cocos2dx_3d_Mesh_getSkin, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getVertexSizeInBytes", js_cocos2dx_3d_Mesh_getVertexSizeInBytes, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getName", js_cocos2dx_3d_Mesh_getName, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getIndexFormat", js_cocos2dx_3d_Mesh_getIndexFormat, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getGLProgramState", js_cocos2dx_3d_Mesh_getGLProgramState, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getVertexBuffer", js_cocos2dx_3d_Mesh_getVertexBuffer, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("calculateAABB", js_cocos2dx_3d_Mesh_calculateAABB, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("hasVertexAttrib", js_cocos2dx_3d_Mesh_hasVertexAttrib, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getBlendFunc", js_cocos2dx_3d_Mesh_getBlendFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMeshIndexData", js_cocos2dx_3d_Mesh_getMeshIndexData, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setName", js_cocos2dx_3d_Mesh_setName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isVisible", js_cocos2dx_3d_Mesh_isVisible, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getIndexCount", js_cocos2dx_3d_Mesh_getIndexCount, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("bindMeshCommand", js_cocos2dx_3d_Mesh_bindMeshCommand, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMeshIndexData", js_cocos2dx_3d_Mesh_setMeshIndexData, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMeshVertexAttribCount", js_cocos2dx_3d_Mesh_getMeshVertexAttribCount, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setBlendFunc", js_cocos2dx_3d_Mesh_setBlendFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getPrimitiveType", js_cocos2dx_3d_Mesh_getPrimitiveType, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setSkin", js_cocos2dx_3d_Mesh_setSkin, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getIndexBuffer", js_cocos2dx_3d_Mesh_getIndexBuffer, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setGLProgramState", js_cocos2dx_3d_Mesh_setGLProgramState, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setVisible", js_cocos2dx_3d_Mesh_setVisible, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + JSFunctionSpec *st_funcs = NULL; + + jsb_cocos2d_Mesh_prototype = JS_InitClass( + cx, global, + JS::NullPtr(), // parent proto + jsb_cocos2d_Mesh_class, + js_cocos2dx_3d_Mesh_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "Mesh", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_Mesh_class; + p->proto = jsb_cocos2d_Mesh_prototype; + p->parentProto = NULL; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_Animation3D_class; +JSObject *jsb_cocos2d_Animation3D_prototype; + +bool js_cocos2dx_3d_Animation3D_initWithFile(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Animation3D* cobj = (cocos2d::Animation3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Animation3D_initWithFile : Invalid Native Object"); + if (argc == 2) { + std::string arg0; + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_initWithFile : Error processing arguments"); + bool ret = cobj->initWithFile(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_initWithFile : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} +bool js_cocos2dx_3d_Animation3D_init(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Animation3D* cobj = (cocos2d::Animation3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Animation3D_init : Invalid Native Object"); + if (argc == 1) { + cocos2d::Animation3DData arg0; + #pragma warning NO CONVERSION TO NATIVE FOR Animation3DData + ok = false; + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_init : Error processing arguments"); + bool ret = cobj->init(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_init : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Animation3D_getBoneCurveByName(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Animation3D* cobj = (cocos2d::Animation3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Animation3D_getBoneCurveByName : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_getBoneCurveByName : Error processing arguments"); + cocos2d::Animation3D::Curve* ret = cobj->getBoneCurveByName(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Animation3D::Curve*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_getBoneCurveByName : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Animation3D_getDuration(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Animation3D* cobj = (cocos2d::Animation3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Animation3D_getDuration : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getDuration(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_getDuration : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Animation3D_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_create : Error processing arguments"); + cocos2d::Animation3D* ret = cocos2d::Animation3D::create(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Animation3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + if (argc == 2) { + std::string arg0; + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_create : Error processing arguments"); + cocos2d::Animation3D* ret = cocos2d::Animation3D::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Animation3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_create : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_3d_Animation3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::Animation3D* cobj = new (std::nothrow) cocos2d::Animation3D(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Animation3D"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + + +void js_cocos2d_Animation3D_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (Animation3D)", obj); +} + +void js_register_cocos2dx_3d_Animation3D(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_Animation3D_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_Animation3D_class->name = "Animation3D"; + jsb_cocos2d_Animation3D_class->addProperty = JS_PropertyStub; + jsb_cocos2d_Animation3D_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_Animation3D_class->getProperty = JS_PropertyStub; + jsb_cocos2d_Animation3D_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_Animation3D_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_Animation3D_class->resolve = JS_ResolveStub; + jsb_cocos2d_Animation3D_class->convert = JS_ConvertStub; + jsb_cocos2d_Animation3D_class->finalize = js_cocos2d_Animation3D_finalize; + jsb_cocos2d_Animation3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("initWithFile", js_cocos2dx_3d_Animation3D_initWithFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("init", js_cocos2dx_3d_Animation3D_init, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getBoneCurveByName", js_cocos2dx_3d_Animation3D_getBoneCurveByName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDuration", js_cocos2dx_3d_Animation3D_getDuration, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_3d_Animation3D_create, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_Animation3D_prototype = JS_InitClass( + cx, global, + JS::NullPtr(), // parent proto + jsb_cocos2d_Animation3D_class, + js_cocos2dx_3d_Animation3D_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "Animation3D", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_Animation3D_class; + p->proto = jsb_cocos2d_Animation3D_prototype; + p->parentProto = NULL; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_Animate3D_class; +JSObject *jsb_cocos2d_Animate3D_prototype; + +bool js_cocos2dx_3d_Animate3D_getSpeed(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Animate3D* cobj = (cocos2d::Animate3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Animate3D_getSpeed : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getSpeed(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Animate3D_getSpeed : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Animate3D_removeFromMap(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Animate3D* cobj = (cocos2d::Animate3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Animate3D_removeFromMap : Invalid Native Object"); + if (argc == 0) { + cobj->removeFromMap(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Animate3D_removeFromMap : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Animate3D_setWeight(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Animate3D* cobj = (cocos2d::Animate3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Animate3D_setWeight : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animate3D_setWeight : Error processing arguments"); + cobj->setWeight(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Animate3D_setWeight : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Animate3D_initWithFrames(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Animate3D* cobj = (cocos2d::Animate3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Animate3D_initWithFrames : Invalid Native Object"); + if (argc == 4) { + cocos2d::Animation3D* arg0; + int arg1; + int arg2; + double arg3; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Animation3D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animate3D_initWithFrames : Error processing arguments"); + bool ret = cobj->initWithFrames(arg0, arg1, arg2, arg3); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Animate3D_initWithFrames : wrong number of arguments: %d, was expecting %d", argc, 4); + return false; +} +bool js_cocos2dx_3d_Animate3D_getOriginInterval(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Animate3D* cobj = (cocos2d::Animate3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Animate3D_getOriginInterval : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getOriginInterval(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Animate3D_getOriginInterval : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Animate3D_setSpeed(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Animate3D* cobj = (cocos2d::Animate3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Animate3D_setSpeed : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animate3D_setSpeed : Error processing arguments"); + cobj->setSpeed(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Animate3D_setSpeed : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Animate3D_init(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + JS::RootedObject obj(cx); + cocos2d::Animate3D* cobj = NULL; + obj = args.thisv().toObjectOrNull(); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cobj = (cocos2d::Animate3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Animate3D_init : Invalid Native Object"); + do { + if (argc == 3) { + cocos2d::Animation3D* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Animation3D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + double arg1; + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + if (!ok) { ok = true; break; } + double arg2; + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + if (!ok) { ok = true; break; } + bool ret = cobj->init(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + do { + if (argc == 1) { + cocos2d::Animation3D* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Animation3D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + bool ret = cobj->init(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_3d_Animate3D_init : wrong number of arguments"); + return false; +} +bool js_cocos2dx_3d_Animate3D_setOriginInterval(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Animate3D* cobj = (cocos2d::Animate3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Animate3D_setOriginInterval : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animate3D_setOriginInterval : Error processing arguments"); + cobj->setOriginInterval(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Animate3D_setOriginInterval : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_Animate3D_getWeight(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Animate3D* cobj = (cocos2d::Animate3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Animate3D_getWeight : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getWeight(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Animate3D_getWeight : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_Animate3D_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + do { + if (argc == 3) { + cocos2d::Animation3D* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Animation3D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + double arg1; + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + if (!ok) { ok = true; break; } + double arg2; + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + if (!ok) { ok = true; break; } + cocos2d::Animate3D* ret = cocos2d::Animate3D::create(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Animate3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 1) { + cocos2d::Animation3D* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Animation3D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cocos2d::Animate3D* ret = cocos2d::Animate3D::create(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Animate3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + JS_ReportError(cx, "js_cocos2dx_3d_Animate3D_create : wrong number of arguments"); + return false; +} +bool js_cocos2dx_3d_Animate3D_getTransitionTime(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (argc == 0) { + double ret = cocos2d::Animate3D::getTransitionTime(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_3d_Animate3D_getTransitionTime : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_3d_Animate3D_createWithFrames(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 3) { + cocos2d::Animation3D* arg0; + int arg1; + int arg2; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Animation3D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animate3D_createWithFrames : Error processing arguments"); + cocos2d::Animate3D* ret = cocos2d::Animate3D::createWithFrames(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Animate3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + if (argc == 4) { + cocos2d::Animation3D* arg0; + int arg1; + int arg2; + double arg3; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Animation3D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animate3D_createWithFrames : Error processing arguments"); + cocos2d::Animate3D* ret = cocos2d::Animate3D::createWithFrames(arg0, arg1, arg2, arg3); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Animate3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_3d_Animate3D_createWithFrames : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_3d_Animate3D_setTransitionTime(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animate3D_setTransitionTime : Error processing arguments"); + cocos2d::Animate3D::setTransitionTime(arg0); + args.rval().setUndefined(); + return true; + } + JS_ReportError(cx, "js_cocos2dx_3d_Animate3D_setTransitionTime : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_3d_Animate3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::Animate3D* cobj = new (std::nothrow) cocos2d::Animate3D(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Animate3D"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocos2d_ActionInterval_prototype; + +void js_cocos2d_Animate3D_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (Animate3D)", obj); +} + +void js_register_cocos2dx_3d_Animate3D(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_Animate3D_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_Animate3D_class->name = "Animate3D"; + jsb_cocos2d_Animate3D_class->addProperty = JS_PropertyStub; + jsb_cocos2d_Animate3D_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_Animate3D_class->getProperty = JS_PropertyStub; + jsb_cocos2d_Animate3D_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_Animate3D_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_Animate3D_class->resolve = JS_ResolveStub; + jsb_cocos2d_Animate3D_class->convert = JS_ConvertStub; + jsb_cocos2d_Animate3D_class->finalize = js_cocos2d_Animate3D_finalize; + jsb_cocos2d_Animate3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("getSpeed", js_cocos2dx_3d_Animate3D_getSpeed, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("removeFromMap", js_cocos2dx_3d_Animate3D_removeFromMap, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setWeight", js_cocos2dx_3d_Animate3D_setWeight, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithFrames", js_cocos2dx_3d_Animate3D_initWithFrames, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getOriginInterval", js_cocos2dx_3d_Animate3D_getOriginInterval, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setSpeed", js_cocos2dx_3d_Animate3D_setSpeed, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("init", js_cocos2dx_3d_Animate3D_init, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setOriginInterval", js_cocos2dx_3d_Animate3D_setOriginInterval, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getWeight", js_cocos2dx_3d_Animate3D_getWeight, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_3d_Animate3D_create, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getTransitionTime", js_cocos2dx_3d_Animate3D_getTransitionTime, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("createWithFrames", js_cocos2dx_3d_Animate3D_createWithFrames, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setTransitionTime", js_cocos2dx_3d_Animate3D_setTransitionTime, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_Animate3D_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), + jsb_cocos2d_Animate3D_class, + js_cocos2dx_3d_Animate3D_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "Animate3D", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_Animate3D_class; + p->proto = jsb_cocos2d_Animate3D_prototype; + p->parentProto = jsb_cocos2d_ActionInterval_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_AttachNode_class; +JSObject *jsb_cocos2d_AttachNode_prototype; + +bool js_cocos2dx_3d_AttachNode_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + cocos2d::Bone3D* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Bone3D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_AttachNode_create : Error processing arguments"); + cocos2d::AttachNode* ret = cocos2d::AttachNode::create(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::AttachNode*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_3d_AttachNode_create : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_3d_AttachNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::AttachNode* cobj = new (std::nothrow) cocos2d::AttachNode(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::AttachNode"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocos2d_Node_prototype; + +void js_cocos2d_AttachNode_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (AttachNode)", obj); +} + +void js_register_cocos2dx_3d_AttachNode(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_AttachNode_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_AttachNode_class->name = "AttachNode"; + jsb_cocos2d_AttachNode_class->addProperty = JS_PropertyStub; + jsb_cocos2d_AttachNode_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_AttachNode_class->getProperty = JS_PropertyStub; + jsb_cocos2d_AttachNode_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_AttachNode_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_AttachNode_class->resolve = JS_ResolveStub; + jsb_cocos2d_AttachNode_class->convert = JS_ConvertStub; + jsb_cocos2d_AttachNode_class->finalize = js_cocos2d_AttachNode_finalize; + jsb_cocos2d_AttachNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_3d_AttachNode_create, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_AttachNode_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), + jsb_cocos2d_AttachNode_class, + js_cocos2dx_3d_AttachNode_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "AttachNode", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_AttachNode_class; + p->proto = jsb_cocos2d_AttachNode_prototype; + p->parentProto = jsb_cocos2d_Node_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_BillBoard_class; +JSObject *jsb_cocos2d_BillBoard_prototype; + +bool js_cocos2dx_3d_BillBoard_getMode(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::BillBoard* cobj = (cocos2d::BillBoard *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_BillBoard_getMode : Invalid Native Object"); + if (argc == 0) { + int ret = (int)cobj->getMode(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_BillBoard_getMode : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_BillBoard_setMode(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::BillBoard* cobj = (cocos2d::BillBoard *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_BillBoard_setMode : Invalid Native Object"); + if (argc == 1) { + cocos2d::BillBoard::Mode arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_BillBoard_setMode : Error processing arguments"); + cobj->setMode(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_BillBoard_setMode : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_BillBoard_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + do { + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::BillBoard* ret = cocos2d::BillBoard::create(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::BillBoard*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::BillBoard::Mode arg1; + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + if (!ok) { ok = true; break; } + cocos2d::BillBoard* ret = cocos2d::BillBoard::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::BillBoard*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 0) { + cocos2d::BillBoard* ret = cocos2d::BillBoard::create(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::BillBoard*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + do { + if (argc == 1) { + cocos2d::BillBoard::Mode arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + if (!ok) { ok = true; break; } + cocos2d::BillBoard* ret = cocos2d::BillBoard::create(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::BillBoard*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::Rect arg1; + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::BillBoard* ret = cocos2d::BillBoard::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::BillBoard*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + do { + if (argc == 3) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::Rect arg1; + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::BillBoard::Mode arg2; + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + if (!ok) { ok = true; break; } + cocos2d::BillBoard* ret = cocos2d::BillBoard::create(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::BillBoard*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + JS_ReportError(cx, "js_cocos2dx_3d_BillBoard_create : wrong number of arguments"); + return false; +} +bool js_cocos2dx_3d_BillBoard_createWithTexture(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + cocos2d::Texture2D* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_BillBoard_createWithTexture : Error processing arguments"); + cocos2d::BillBoard* ret = cocos2d::BillBoard::createWithTexture(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::BillBoard*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + if (argc == 2) { + cocos2d::Texture2D* arg0; + cocos2d::BillBoard::Mode arg1; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_BillBoard_createWithTexture : Error processing arguments"); + cocos2d::BillBoard* ret = cocos2d::BillBoard::createWithTexture(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::BillBoard*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_3d_BillBoard_createWithTexture : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_3d_BillBoard_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::BillBoard* cobj = new (std::nothrow) cocos2d::BillBoard(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::BillBoard"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocos2d_Sprite_prototype; + +void js_cocos2d_BillBoard_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (BillBoard)", obj); +} + +void js_register_cocos2dx_3d_BillBoard(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_BillBoard_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_BillBoard_class->name = "BillBoard"; + jsb_cocos2d_BillBoard_class->addProperty = JS_PropertyStub; + jsb_cocos2d_BillBoard_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_BillBoard_class->getProperty = JS_PropertyStub; + jsb_cocos2d_BillBoard_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_BillBoard_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_BillBoard_class->resolve = JS_ResolveStub; + jsb_cocos2d_BillBoard_class->convert = JS_ConvertStub; + jsb_cocos2d_BillBoard_class->finalize = js_cocos2d_BillBoard_finalize; + jsb_cocos2d_BillBoard_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("getMode", js_cocos2dx_3d_BillBoard_getMode, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMode", js_cocos2dx_3d_BillBoard_setMode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_3d_BillBoard_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("createWithTexture", js_cocos2dx_3d_BillBoard_createWithTexture, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_BillBoard_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_Sprite_prototype), + jsb_cocos2d_BillBoard_class, + js_cocos2dx_3d_BillBoard_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "BillBoard", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_BillBoard_class; + p->proto = jsb_cocos2d_BillBoard_prototype; + p->parentProto = jsb_cocos2d_Sprite_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +void register_all_cocos2dx_3d(JSContext* cx, JS::HandleObject obj) { + // Get the ns + JS::RootedObject ns(cx); + get_or_create_js_obj(cx, obj, "jsb", &ns); + + js_register_cocos2dx_3d_Animate3D(cx, ns); + js_register_cocos2dx_3d_Sprite3D(cx, ns); + js_register_cocos2dx_3d_AttachNode(cx, ns); + js_register_cocos2dx_3d_Sprite3DCache(cx, ns); + js_register_cocos2dx_3d_BillBoard(cx, ns); + js_register_cocos2dx_3d_Animation3D(cx, ns); + js_register_cocos2dx_3d_Skeleton3D(cx, ns); + js_register_cocos2dx_3d_Mesh(cx, ns); +} + diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_auto.hpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_auto.hpp new file mode 100644 index 0000000000..08d6b225d8 --- /dev/null +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_auto.hpp @@ -0,0 +1,169 @@ +#ifndef __cocos2dx_3d_h__ +#define __cocos2dx_3d_h__ + +#include "jsapi.h" +#include "jsfriendapi.h" + + +extern JSClass *jsb_cocos2d_Skeleton3D_class; +extern JSObject *jsb_cocos2d_Skeleton3D_prototype; + +bool js_cocos2dx_3d_Skeleton3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_3d_Skeleton3D_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_3d_Skeleton3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_3d(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_3d_Skeleton3D_removeAllBones(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Skeleton3D_addBone(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Skeleton3D_getBoneByName(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Skeleton3D_getRootBone(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Skeleton3D_updateBoneMatrix(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Skeleton3D_getBoneByIndex(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Skeleton3D_getRootCount(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Skeleton3D_getBoneIndex(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Skeleton3D_getBoneCount(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Skeleton3D_Skeleton3D(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocos2d_Sprite3D_class; +extern JSObject *jsb_cocos2d_Sprite3D_prototype; + +bool js_cocos2dx_3d_Sprite3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_3d_Sprite3D_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_3d_Sprite3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_3d(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_3d_Sprite3D_setCullFaceEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_setTexture(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_getLightMask(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_createAttachSprite3DNode(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_loadFromFile(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_setCullFace(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_addMesh(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_removeAllAttachNode(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_genGLProgramState(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_getMesh(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_createSprite3DNode(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_getMeshCount(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_onAABBDirty(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_getMeshByIndex(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_createNode(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_isForceDepthWrite(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_getMeshIndexData(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_removeAttachNode(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_setLightMask(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_afterAsyncLoad(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_loadFromCache(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_initFrom(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_getAttachNode(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_initWithFile(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_getSkeleton(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_setForceDepthWrite(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_getMeshByName(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3D_Sprite3D(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocos2d_Sprite3DCache_class; +extern JSObject *jsb_cocos2d_Sprite3DCache_prototype; + +bool js_cocos2dx_3d_Sprite3DCache_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_3d_Sprite3DCache_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_3d_Sprite3DCache(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_3d(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_3d_Sprite3DCache_removeSprite3DData(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3DCache_removeAllSprite3DData(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3DCache_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Sprite3DCache_getInstance(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocos2d_Mesh_class; +extern JSObject *jsb_cocos2d_Mesh_prototype; + +bool js_cocos2dx_3d_Mesh_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_3d_Mesh_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_3d_Mesh(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_3d(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_3d_Mesh_setTexture(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_getTexture(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_getSkin(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_getVertexSizeInBytes(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_getName(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_getIndexFormat(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_getGLProgramState(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_getVertexBuffer(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_calculateAABB(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_hasVertexAttrib(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_getMeshIndexData(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_setName(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_isVisible(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_getIndexCount(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_bindMeshCommand(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_setMeshIndexData(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_getMeshVertexAttribCount(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_getPrimitiveType(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_setSkin(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_getIndexBuffer(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_setGLProgramState(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_setVisible(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Mesh_Mesh(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocos2d_Animation3D_class; +extern JSObject *jsb_cocos2d_Animation3D_prototype; + +bool js_cocos2dx_3d_Animation3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_3d_Animation3D_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_3d_Animation3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_3d(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_3d_Animation3D_initWithFile(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animation3D_init(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animation3D_getBoneCurveByName(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animation3D_getDuration(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animation3D_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animation3D_Animation3D(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocos2d_Animate3D_class; +extern JSObject *jsb_cocos2d_Animate3D_prototype; + +bool js_cocos2dx_3d_Animate3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_3d_Animate3D_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_3d_Animate3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_3d(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_3d_Animate3D_getSpeed(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animate3D_removeFromMap(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animate3D_setWeight(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animate3D_initWithFrames(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animate3D_getOriginInterval(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animate3D_setSpeed(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animate3D_init(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animate3D_setOriginInterval(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animate3D_getWeight(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animate3D_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animate3D_getTransitionTime(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animate3D_createWithFrames(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animate3D_setTransitionTime(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animate3D_Animate3D(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocos2d_AttachNode_class; +extern JSObject *jsb_cocos2d_AttachNode_prototype; + +bool js_cocos2dx_3d_AttachNode_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_3d_AttachNode_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_3d_AttachNode(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_3d(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_3d_AttachNode_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_AttachNode_AttachNode(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocos2d_BillBoard_class; +extern JSObject *jsb_cocos2d_BillBoard_prototype; + +bool js_cocos2dx_3d_BillBoard_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_3d_BillBoard_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_3d_BillBoard(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_3d(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_3d_BillBoard_getMode(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_BillBoard_setMode(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_BillBoard_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_BillBoard_createWithTexture(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_BillBoard_BillBoard(JSContext *cx, uint32_t argc, jsval *vp); +#endif + diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_extension_auto.cpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_extension_auto.cpp new file mode 100644 index 0000000000..44e3b01f4f --- /dev/null +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_extension_auto.cpp @@ -0,0 +1,1219 @@ +#include "jsb_cocos2dx_3d_extension_auto.hpp" +#include "cocos2d_specifics.hpp" +#include "cocos-ext.h" + +template +static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedValue initializing(cx); + bool isNewValid = true; + JS::RootedObject global(cx, ScriptingCore::getInstance()->getGlobalObject()); + isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && initializing.toBoolean(); + if (isNewValid) + { + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject _tmp(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + + args.rval().set(OBJECT_TO_JSVAL(_tmp)); + return true; + } + + JS_ReportError(cx, "Constructor for the requested class is not available, please refer to the API reference."); + return false; +} + +static bool empty_constructor(JSContext *cx, uint32_t argc, jsval *vp) { + return false; +} + +static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setBoolean(true); + return true; +} +JSClass *jsb_cocos2d_ParticleSystem3D_class; +JSObject *jsb_cocos2d_ParticleSystem3D_prototype; + +bool js_cocos2dx_3d_extension_ParticleSystem3D_resumeParticleSystem(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ParticleSystem3D* cobj = (cocos2d::ParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_resumeParticleSystem : Invalid Native Object"); + if (argc == 0) { + cobj->resumeParticleSystem(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_ParticleSystem3D_resumeParticleSystem : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_ParticleSystem3D_startParticleSystem(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ParticleSystem3D* cobj = (cocos2d::ParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_startParticleSystem : Invalid Native Object"); + if (argc == 0) { + cobj->startParticleSystem(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_ParticleSystem3D_startParticleSystem : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_ParticleSystem3D_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ParticleSystem3D* cobj = (cocos2d::ParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_isEnabled : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isEnabled(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_ParticleSystem3D_isEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_ParticleSystem3D_isKeepLocal(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ParticleSystem3D* cobj = (cocos2d::ParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_isKeepLocal : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isKeepLocal(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_ParticleSystem3D_isKeepLocal : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_ParticleSystem3D_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ParticleSystem3D* cobj = (cocos2d::ParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_setEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_setEnabled : Error processing arguments"); + cobj->setEnabled(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_ParticleSystem3D_setEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_ParticleSystem3D_getParticleQuota(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ParticleSystem3D* cobj = (cocos2d::ParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_getParticleQuota : Invalid Native Object"); + if (argc == 0) { + unsigned int ret = cobj->getParticleQuota(); + jsval jsret = JSVAL_NULL; + jsret = uint32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_ParticleSystem3D_getParticleQuota : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_ParticleSystem3D_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ParticleSystem3D* cobj = (cocos2d::ParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_getBlendFunc : Invalid Native Object"); + if (argc == 0) { + const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); + jsval jsret = JSVAL_NULL; + jsret = blendfunc_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_ParticleSystem3D_getBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_ParticleSystem3D_pauseParticleSystem(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ParticleSystem3D* cobj = (cocos2d::ParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_pauseParticleSystem : Invalid Native Object"); + if (argc == 0) { + cobj->pauseParticleSystem(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_ParticleSystem3D_pauseParticleSystem : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_ParticleSystem3D_getState(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ParticleSystem3D* cobj = (cocos2d::ParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_getState : Invalid Native Object"); + if (argc == 0) { + int ret = (int)cobj->getState(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_ParticleSystem3D_getState : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_ParticleSystem3D_getAliveParticleCount(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ParticleSystem3D* cobj = (cocos2d::ParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_getAliveParticleCount : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getAliveParticleCount(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_ParticleSystem3D_getAliveParticleCount : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_ParticleSystem3D_setParticleQuota(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ParticleSystem3D* cobj = (cocos2d::ParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_setParticleQuota : Invalid Native Object"); + if (argc == 1) { + unsigned int arg0; + ok &= jsval_to_uint32(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_setParticleQuota : Error processing arguments"); + cobj->setParticleQuota(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_ParticleSystem3D_setParticleQuota : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_ParticleSystem3D_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ParticleSystem3D* cobj = (cocos2d::ParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_setBlendFunc : Invalid Native Object"); + if (argc == 1) { + cocos2d::BlendFunc arg0; + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_setBlendFunc : Error processing arguments"); + cobj->setBlendFunc(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_ParticleSystem3D_setBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_ParticleSystem3D_stopParticleSystem(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ParticleSystem3D* cobj = (cocos2d::ParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_stopParticleSystem : Invalid Native Object"); + if (argc == 0) { + cobj->stopParticleSystem(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_ParticleSystem3D_stopParticleSystem : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_ParticleSystem3D_setKeepLocal(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ParticleSystem3D* cobj = (cocos2d::ParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_setKeepLocal : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_ParticleSystem3D_setKeepLocal : Error processing arguments"); + cobj->setKeepLocal(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_ParticleSystem3D_setKeepLocal : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_ParticleSystem3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::ParticleSystem3D* cobj = new (std::nothrow) cocos2d::ParticleSystem3D(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSystem3D"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocos2d_Node_prototype; + +void js_cocos2d_ParticleSystem3D_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (ParticleSystem3D)", obj); +} + +void js_register_cocos2dx_3d_extension_ParticleSystem3D(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ParticleSystem3D_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ParticleSystem3D_class->name = "ParticleSystem3D"; + jsb_cocos2d_ParticleSystem3D_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ParticleSystem3D_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ParticleSystem3D_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ParticleSystem3D_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ParticleSystem3D_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ParticleSystem3D_class->resolve = JS_ResolveStub; + jsb_cocos2d_ParticleSystem3D_class->convert = JS_ConvertStub; + jsb_cocos2d_ParticleSystem3D_class->finalize = js_cocos2d_ParticleSystem3D_finalize; + jsb_cocos2d_ParticleSystem3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("resumeParticleSystem", js_cocos2dx_3d_extension_ParticleSystem3D_resumeParticleSystem, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("startParticleSystem", js_cocos2dx_3d_extension_ParticleSystem3D_startParticleSystem, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isEnabled", js_cocos2dx_3d_extension_ParticleSystem3D_isEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isKeepLocal", js_cocos2dx_3d_extension_ParticleSystem3D_isKeepLocal, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setEnabled", js_cocos2dx_3d_extension_ParticleSystem3D_setEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getParticleQuota", js_cocos2dx_3d_extension_ParticleSystem3D_getParticleQuota, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getBlendFunc", js_cocos2dx_3d_extension_ParticleSystem3D_getBlendFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("pauseParticleSystem", js_cocos2dx_3d_extension_ParticleSystem3D_pauseParticleSystem, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getState", js_cocos2dx_3d_extension_ParticleSystem3D_getState, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getAliveParticleCount", js_cocos2dx_3d_extension_ParticleSystem3D_getAliveParticleCount, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setParticleQuota", js_cocos2dx_3d_extension_ParticleSystem3D_setParticleQuota, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setBlendFunc", js_cocos2dx_3d_extension_ParticleSystem3D_setBlendFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("stopParticleSystem", js_cocos2dx_3d_extension_ParticleSystem3D_stopParticleSystem, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setKeepLocal", js_cocos2dx_3d_extension_ParticleSystem3D_setKeepLocal, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + JSFunctionSpec *st_funcs = NULL; + + jsb_cocos2d_ParticleSystem3D_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), + jsb_cocos2d_ParticleSystem3D_class, + js_cocos2dx_3d_extension_ParticleSystem3D_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "ParticleSystem3D", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_ParticleSystem3D_class; + p->proto = jsb_cocos2d_ParticleSystem3D_prototype; + p->parentProto = jsb_cocos2d_Node_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_PUParticleSystem3D_class; +JSObject *jsb_cocos2d_PUParticleSystem3D_prototype; + +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getParticleSystemScaleVelocity(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_getParticleSystemScaleVelocity : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getParticleSystemScaleVelocity(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_getParticleSystemScaleVelocity : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setEmittedSystemQuota(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setEmittedSystemQuota : Invalid Native Object"); + if (argc == 1) { + unsigned int arg0; + ok &= jsval_to_uint32(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setEmittedSystemQuota : Error processing arguments"); + cobj->setEmittedSystemQuota(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_setEmittedSystemQuota : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultDepth(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultDepth : Invalid Native Object"); + if (argc == 0) { + const float ret = cobj->getDefaultDepth(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultDepth : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getEmittedSystemQuota(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_getEmittedSystemQuota : Invalid Native Object"); + if (argc == 0) { + unsigned int ret = cobj->getEmittedSystemQuota(); + jsval jsret = JSVAL_NULL; + jsret = uint32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_getEmittedSystemQuota : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_clearAllParticles(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_clearAllParticles : Invalid Native Object"); + if (argc == 0) { + cobj->clearAllParticles(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_clearAllParticles : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getMaterialName(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_getMaterialName : Invalid Native Object"); + if (argc == 0) { + const std::string ret = cobj->getMaterialName(); + jsval jsret = JSVAL_NULL; + jsret = std_string_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_getMaterialName : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_calulateRotationOffset(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_calulateRotationOffset : Invalid Native Object"); + if (argc == 0) { + cobj->calulateRotationOffset(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_calulateRotationOffset : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getMaxVelocity(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_getMaxVelocity : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getMaxVelocity(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_getMaxVelocity : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_forceUpdate(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_forceUpdate : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_forceUpdate : Error processing arguments"); + cobj->forceUpdate(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_forceUpdate : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getTimeElapsedSinceStart(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_getTimeElapsedSinceStart : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getTimeElapsedSinceStart(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_getTimeElapsedSinceStart : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getEmittedEmitterQuota(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_getEmittedEmitterQuota : Invalid Native Object"); + if (argc == 0) { + unsigned int ret = cobj->getEmittedEmitterQuota(); + jsval jsret = JSVAL_NULL; + jsret = uint32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_getEmittedEmitterQuota : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_isMarkedForEmission(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_isMarkedForEmission : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isMarkedForEmission(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_isMarkedForEmission : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultWidth(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultWidth : Invalid Native Object"); + if (argc == 0) { + const float ret = cobj->getDefaultWidth(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultWidth : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setEmittedEmitterQuota(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setEmittedEmitterQuota : Invalid Native Object"); + if (argc == 1) { + unsigned int arg0; + ok &= jsval_to_uint32(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setEmittedEmitterQuota : Error processing arguments"); + cobj->setEmittedEmitterQuota(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_setEmittedEmitterQuota : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setMarkedForEmission(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setMarkedForEmission : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setMarkedForEmission : Error processing arguments"); + cobj->setMarkedForEmission(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_setMarkedForEmission : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_clone(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_clone : Invalid Native Object"); + if (argc == 0) { + cocos2d::PUParticleSystem3D* ret = cobj->clone(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::PUParticleSystem3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_clone : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultWidth(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultWidth : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultWidth : Error processing arguments"); + cobj->setDefaultWidth(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultWidth : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_copyAttributesTo(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_copyAttributesTo : Invalid Native Object"); + if (argc == 1) { + cocos2d::PUParticleSystem3D* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::PUParticleSystem3D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_copyAttributesTo : Error processing arguments"); + cobj->copyAttributesTo(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_copyAttributesTo : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setMaterialName(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setMaterialName : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setMaterialName : Error processing arguments"); + cobj->setMaterialName(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_setMaterialName : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getParentParticleSystem(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_getParentParticleSystem : Invalid Native Object"); + if (argc == 0) { + cocos2d::PUParticleSystem3D* ret = cobj->getParentParticleSystem(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::PUParticleSystem3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_getParentParticleSystem : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setMaxVelocity(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setMaxVelocity : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setMaxVelocity : Error processing arguments"); + cobj->setMaxVelocity(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_setMaxVelocity : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultHeight(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultHeight : Invalid Native Object"); + if (argc == 0) { + const float ret = cobj->getDefaultHeight(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultHeight : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedPosition(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedPosition : Invalid Native Object"); + if (argc == 0) { + cocos2d::Vec3 ret = cobj->getDerivedPosition(); + jsval jsret = JSVAL_NULL; + jsret = vector3_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedPosition : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_rotationOffset(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_rotationOffset : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vec3 arg0; + ok &= jsval_to_vector3(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_rotationOffset : Error processing arguments"); + cobj->rotationOffset(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_rotationOffset : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedOrientation(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedOrientation : Invalid Native Object"); + if (argc == 0) { + cocos2d::Quaternion ret = cobj->getDerivedOrientation(); + jsval jsret = JSVAL_NULL; + jsret = quaternion_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedOrientation : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_removeAllEmitter(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_removeAllEmitter : Invalid Native Object"); + if (argc == 0) { + cobj->removeAllEmitter(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_removeAllEmitter : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setParticleSystemScaleVelocity(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setParticleSystemScaleVelocity : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setParticleSystemScaleVelocity : Error processing arguments"); + cobj->setParticleSystemScaleVelocity(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_setParticleSystemScaleVelocity : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedScale(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedScale : Invalid Native Object"); + if (argc == 0) { + cocos2d::Vec3 ret = cobj->getDerivedScale(); + jsval jsret = JSVAL_NULL; + jsret = vector3_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedScale : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultHeight(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultHeight : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultHeight : Error processing arguments"); + cobj->setDefaultHeight(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultHeight : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_removeAllListener(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_removeAllListener : Invalid Native Object"); + if (argc == 0) { + cobj->removeAllListener(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_removeAllListener : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_initSystem(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_initSystem : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_initSystem : Error processing arguments"); + bool ret = cobj->initSystem(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_initSystem : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultDepth(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PUParticleSystem3D* cobj = (cocos2d::PUParticleSystem3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultDepth : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultDepth : Error processing arguments"); + cobj->setDefaultDepth(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultDepth : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + do { + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::PUParticleSystem3D* ret = cocos2d::PUParticleSystem3D::create(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::PUParticleSystem3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 0) { + cocos2d::PUParticleSystem3D* ret = cocos2d::PUParticleSystem3D::create(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::PUParticleSystem3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::PUParticleSystem3D* ret = cocos2d::PUParticleSystem3D::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::PUParticleSystem3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + JS_ReportError(cx, "js_cocos2dx_3d_extension_PUParticleSystem3D_create : wrong number of arguments"); + return false; +} +bool js_cocos2dx_3d_extension_PUParticleSystem3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::PUParticleSystem3D* cobj = new (std::nothrow) cocos2d::PUParticleSystem3D(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::PUParticleSystem3D"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocos2d_ParticleSystem3D_prototype; + +void js_cocos2d_PUParticleSystem3D_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (PUParticleSystem3D)", obj); +} + +void js_register_cocos2dx_3d_extension_PUParticleSystem3D(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_PUParticleSystem3D_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_PUParticleSystem3D_class->name = "PUParticleSystem3D"; + jsb_cocos2d_PUParticleSystem3D_class->addProperty = JS_PropertyStub; + jsb_cocos2d_PUParticleSystem3D_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_PUParticleSystem3D_class->getProperty = JS_PropertyStub; + jsb_cocos2d_PUParticleSystem3D_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_PUParticleSystem3D_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_PUParticleSystem3D_class->resolve = JS_ResolveStub; + jsb_cocos2d_PUParticleSystem3D_class->convert = JS_ConvertStub; + jsb_cocos2d_PUParticleSystem3D_class->finalize = js_cocos2d_PUParticleSystem3D_finalize; + jsb_cocos2d_PUParticleSystem3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("getParticleSystemScaleVelocity", js_cocos2dx_3d_extension_PUParticleSystem3D_getParticleSystemScaleVelocity, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setEmittedSystemQuota", js_cocos2dx_3d_extension_PUParticleSystem3D_setEmittedSystemQuota, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDefaultDepth", js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultDepth, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getEmittedSystemQuota", js_cocos2dx_3d_extension_PUParticleSystem3D_getEmittedSystemQuota, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("clearAllParticles", js_cocos2dx_3d_extension_PUParticleSystem3D_clearAllParticles, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMaterialName", js_cocos2dx_3d_extension_PUParticleSystem3D_getMaterialName, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("calulateRotationOffset", js_cocos2dx_3d_extension_PUParticleSystem3D_calulateRotationOffset, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMaxVelocity", js_cocos2dx_3d_extension_PUParticleSystem3D_getMaxVelocity, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("forceUpdate", js_cocos2dx_3d_extension_PUParticleSystem3D_forceUpdate, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getTimeElapsedSinceStart", js_cocos2dx_3d_extension_PUParticleSystem3D_getTimeElapsedSinceStart, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getEmittedEmitterQuota", js_cocos2dx_3d_extension_PUParticleSystem3D_getEmittedEmitterQuota, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isMarkedForEmission", js_cocos2dx_3d_extension_PUParticleSystem3D_isMarkedForEmission, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDefaultWidth", js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultWidth, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setEmittedEmitterQuota", js_cocos2dx_3d_extension_PUParticleSystem3D_setEmittedEmitterQuota, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMarkedForEmission", js_cocos2dx_3d_extension_PUParticleSystem3D_setMarkedForEmission, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("clone", js_cocos2dx_3d_extension_PUParticleSystem3D_clone, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setDefaultWidth", js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultWidth, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("copyAttributesTo", js_cocos2dx_3d_extension_PUParticleSystem3D_copyAttributesTo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMaterialName", js_cocos2dx_3d_extension_PUParticleSystem3D_setMaterialName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getParentParticleSystem", js_cocos2dx_3d_extension_PUParticleSystem3D_getParentParticleSystem, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMaxVelocity", js_cocos2dx_3d_extension_PUParticleSystem3D_setMaxVelocity, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDefaultHeight", js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultHeight, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDerivedPosition", js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedPosition, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("rotationOffset", js_cocos2dx_3d_extension_PUParticleSystem3D_rotationOffset, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDerivedOrientation", js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedOrientation, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("removeAllEmitter", js_cocos2dx_3d_extension_PUParticleSystem3D_removeAllEmitter, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setParticleSystemScaleVelocity", js_cocos2dx_3d_extension_PUParticleSystem3D_setParticleSystemScaleVelocity, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDerivedScale", js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedScale, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setDefaultHeight", js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultHeight, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("removeAllListener", js_cocos2dx_3d_extension_PUParticleSystem3D_removeAllListener, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initSystem", js_cocos2dx_3d_extension_PUParticleSystem3D_initSystem, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setDefaultDepth", js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultDepth, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_3d_extension_PUParticleSystem3D_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_PUParticleSystem3D_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_ParticleSystem3D_prototype), + jsb_cocos2d_PUParticleSystem3D_class, + js_cocos2dx_3d_extension_PUParticleSystem3D_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "PUParticleSystem3D", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_PUParticleSystem3D_class; + p->proto = jsb_cocos2d_PUParticleSystem3D_prototype; + p->parentProto = jsb_cocos2d_ParticleSystem3D_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +void register_all_cocos2dx_3d_extension(JSContext* cx, JS::HandleObject obj) { + // Get the ns + JS::RootedObject ns(cx); + get_or_create_js_obj(cx, obj, "jsb", &ns); + + js_register_cocos2dx_3d_extension_ParticleSystem3D(cx, ns); + js_register_cocos2dx_3d_extension_PUParticleSystem3D(cx, ns); +} + diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_extension_auto.hpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_extension_auto.hpp new file mode 100644 index 0000000000..e299d97b2f --- /dev/null +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_extension_auto.hpp @@ -0,0 +1,73 @@ +#ifndef __cocos2dx_3d_extension_h__ +#define __cocos2dx_3d_extension_h__ + +#include "jsapi.h" +#include "jsfriendapi.h" + + +extern JSClass *jsb_cocos2d_ParticleSystem3D_class; +extern JSObject *jsb_cocos2d_ParticleSystem3D_prototype; + +bool js_cocos2dx_3d_extension_ParticleSystem3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_3d_extension_ParticleSystem3D_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_3d_extension_ParticleSystem3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_3d_extension(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_3d_extension_ParticleSystem3D_resumeParticleSystem(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_ParticleSystem3D_startParticleSystem(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_ParticleSystem3D_isEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_ParticleSystem3D_isKeepLocal(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_ParticleSystem3D_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_ParticleSystem3D_getParticleQuota(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_ParticleSystem3D_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_ParticleSystem3D_pauseParticleSystem(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_ParticleSystem3D_getState(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_ParticleSystem3D_getAliveParticleCount(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_ParticleSystem3D_setParticleQuota(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_ParticleSystem3D_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_ParticleSystem3D_stopParticleSystem(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_ParticleSystem3D_setKeepLocal(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_ParticleSystem3D_ParticleSystem3D(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocos2d_PUParticleSystem3D_class; +extern JSObject *jsb_cocos2d_PUParticleSystem3D_prototype; + +bool js_cocos2dx_3d_extension_PUParticleSystem3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_3d_extension_PUParticleSystem3D_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_3d_extension_PUParticleSystem3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_3d_extension(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getParticleSystemScaleVelocity(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setEmittedSystemQuota(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultDepth(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getEmittedSystemQuota(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_clearAllParticles(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getMaterialName(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_calulateRotationOffset(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getMaxVelocity(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_forceUpdate(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getTimeElapsedSinceStart(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getEmittedEmitterQuota(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_isMarkedForEmission(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultWidth(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setEmittedEmitterQuota(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setMarkedForEmission(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_clone(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultWidth(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_copyAttributesTo(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setMaterialName(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getParentParticleSystem(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setMaxVelocity(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultHeight(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedPosition(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_rotationOffset(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedOrientation(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_removeAllEmitter(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setParticleSystemScaleVelocity(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedScale(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultHeight(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_removeAllListener(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_initSystem(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultDepth(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_extension_PUParticleSystem3D_PUParticleSystem3D(JSContext *cx, uint32_t argc, jsval *vp); +#endif + diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp index b77e207551..d24a9359b6 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp @@ -3,13 +3,15 @@ #include "cocos2d.h" #include "SimpleAudioEngine.h" #include "CCProtectedNode.h" +#include "CCAsyncTaskPool.h" template static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedValue initializing(cx); bool isNewValid = true; - JSObject* global = ScriptingCore::getInstance()->getGlobalObject(); - isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && JSVAL_TO_BOOLEAN(initializing); + JS::RootedObject global(cx, ScriptingCore::getInstance()->getGlobalObject()); + isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && initializing.toBoolean(); if (isNewValid) { TypeTest t; @@ -20,8 +22,11 @@ static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *_tmp = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp)); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject _tmp(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + + args.rval().set(OBJECT_TO_JSVAL(_tmp)); return true; } @@ -33,9 +38,10 @@ static bool empty_constructor(JSContext *cx, uint32_t argc, jsval *vp) { return false; } -static bool js_is_native_obj(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) { - vp.set(BOOLEAN_TO_JSVAL(true)); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setBoolean(true); return true; } JSClass *jsb_cocos2d_Configuration_class; @@ -43,20 +49,20 @@ JSObject *jsb_cocos2d_Configuration_prototype; bool js_cocos2dx_Configuration_checkForGLExtension(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_checkForGLExtension : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Configuration_checkForGLExtension : Error processing arguments"); bool ret = cobj->checkForGLExtension(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -65,7 +71,8 @@ bool js_cocos2dx_Configuration_checkForGLExtension(JSContext *cx, uint32_t argc, } bool js_cocos2dx_Configuration_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_init : Invalid Native Object"); @@ -73,7 +80,7 @@ bool js_cocos2dx_Configuration_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -82,7 +89,8 @@ bool js_cocos2dx_Configuration_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Configuration_supportsS3TC(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_supportsS3TC : Invalid Native Object"); @@ -90,7 +98,7 @@ bool js_cocos2dx_Configuration_supportsS3TC(JSContext *cx, uint32_t argc, jsval bool ret = cobj->supportsS3TC(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -99,7 +107,8 @@ bool js_cocos2dx_Configuration_supportsS3TC(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Configuration_supportsPVRTC(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_supportsPVRTC : Invalid Native Object"); @@ -107,7 +116,7 @@ bool js_cocos2dx_Configuration_supportsPVRTC(JSContext *cx, uint32_t argc, jsval bool ret = cobj->supportsPVRTC(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -116,7 +125,8 @@ bool js_cocos2dx_Configuration_supportsPVRTC(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Configuration_supportsShareableVAO(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_supportsShareableVAO : Invalid Native Object"); @@ -124,7 +134,7 @@ bool js_cocos2dx_Configuration_supportsShareableVAO(JSContext *cx, uint32_t argc bool ret = cobj->supportsShareableVAO(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -133,7 +143,8 @@ bool js_cocos2dx_Configuration_supportsShareableVAO(JSContext *cx, uint32_t argc } bool js_cocos2dx_Configuration_getInfo(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_getInfo : Invalid Native Object"); @@ -141,7 +152,7 @@ bool js_cocos2dx_Configuration_getInfo(JSContext *cx, uint32_t argc, jsval *vp) std::string ret = cobj->getInfo(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -150,7 +161,8 @@ bool js_cocos2dx_Configuration_getInfo(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Configuration_getMaxSupportSpotLightInShader(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_getMaxSupportSpotLightInShader : Invalid Native Object"); @@ -158,7 +170,7 @@ bool js_cocos2dx_Configuration_getMaxSupportSpotLightInShader(JSContext *cx, uin int ret = cobj->getMaxSupportSpotLightInShader(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -167,7 +179,8 @@ bool js_cocos2dx_Configuration_getMaxSupportSpotLightInShader(JSContext *cx, uin } bool js_cocos2dx_Configuration_getMaxTextureUnits(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_getMaxTextureUnits : Invalid Native Object"); @@ -175,7 +188,7 @@ bool js_cocos2dx_Configuration_getMaxTextureUnits(JSContext *cx, uint32_t argc, int ret = cobj->getMaxTextureUnits(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -184,7 +197,8 @@ bool js_cocos2dx_Configuration_getMaxTextureUnits(JSContext *cx, uint32_t argc, } bool js_cocos2dx_Configuration_supportsNPOT(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_supportsNPOT : Invalid Native Object"); @@ -192,7 +206,7 @@ bool js_cocos2dx_Configuration_supportsNPOT(JSContext *cx, uint32_t argc, jsval bool ret = cobj->supportsNPOT(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -201,7 +215,8 @@ bool js_cocos2dx_Configuration_supportsNPOT(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Configuration_getMaxModelviewStackDepth(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_getMaxModelviewStackDepth : Invalid Native Object"); @@ -209,7 +224,7 @@ bool js_cocos2dx_Configuration_getMaxModelviewStackDepth(JSContext *cx, uint32_t int ret = cobj->getMaxModelviewStackDepth(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -218,7 +233,8 @@ bool js_cocos2dx_Configuration_getMaxModelviewStackDepth(JSContext *cx, uint32_t } bool js_cocos2dx_Configuration_supportsDiscardFramebuffer(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_supportsDiscardFramebuffer : Invalid Native Object"); @@ -226,7 +242,7 @@ bool js_cocos2dx_Configuration_supportsDiscardFramebuffer(JSContext *cx, uint32_ bool ret = cobj->supportsDiscardFramebuffer(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -235,7 +251,8 @@ bool js_cocos2dx_Configuration_supportsDiscardFramebuffer(JSContext *cx, uint32_ } bool js_cocos2dx_Configuration_supportsATITC(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_supportsATITC : Invalid Native Object"); @@ -243,7 +260,7 @@ bool js_cocos2dx_Configuration_supportsATITC(JSContext *cx, uint32_t argc, jsval bool ret = cobj->supportsATITC(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -252,20 +269,20 @@ bool js_cocos2dx_Configuration_supportsATITC(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Configuration_setValue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_setValue : Invalid Native Object"); if (argc == 2) { std::string arg0; cocos2d::Value arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_ccvalue(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_ccvalue(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Configuration_setValue : Error processing arguments"); cobj->setValue(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -274,13 +291,14 @@ bool js_cocos2dx_Configuration_setValue(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Configuration_gatherGPUInfo(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_gatherGPUInfo : Invalid Native Object"); if (argc == 0) { cobj->gatherGPUInfo(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -289,7 +307,8 @@ bool js_cocos2dx_Configuration_gatherGPUInfo(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Configuration_supportsETC(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_supportsETC : Invalid Native Object"); @@ -297,7 +316,7 @@ bool js_cocos2dx_Configuration_supportsETC(JSContext *cx, uint32_t argc, jsval * bool ret = cobj->supportsETC(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -306,7 +325,8 @@ bool js_cocos2dx_Configuration_supportsETC(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Configuration_getMaxSupportDirLightInShader(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_getMaxSupportDirLightInShader : Invalid Native Object"); @@ -314,7 +334,7 @@ bool js_cocos2dx_Configuration_getMaxSupportDirLightInShader(JSContext *cx, uint int ret = cobj->getMaxSupportDirLightInShader(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -323,7 +343,8 @@ bool js_cocos2dx_Configuration_getMaxSupportDirLightInShader(JSContext *cx, uint } bool js_cocos2dx_Configuration_getMaxSupportPointLightInShader(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_getMaxSupportPointLightInShader : Invalid Native Object"); @@ -331,7 +352,7 @@ bool js_cocos2dx_Configuration_getMaxSupportPointLightInShader(JSContext *cx, ui int ret = cobj->getMaxSupportPointLightInShader(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -340,18 +361,18 @@ bool js_cocos2dx_Configuration_getMaxSupportPointLightInShader(JSContext *cx, ui } bool js_cocos2dx_Configuration_loadConfigFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_loadConfigFile : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Configuration_loadConfigFile : Error processing arguments"); cobj->loadConfigFile(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -360,32 +381,32 @@ bool js_cocos2dx_Configuration_loadConfigFile(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_Configuration_getValue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_getValue : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Configuration_getValue : Error processing arguments"); const cocos2d::Value& ret = cobj->getValue(arg0); jsval jsret = JSVAL_NULL; jsret = ccvalue_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { std::string arg0; cocos2d::Value arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_ccvalue(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_ccvalue(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Configuration_getValue : Error processing arguments"); const cocos2d::Value& ret = cobj->getValue(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = ccvalue_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -394,7 +415,8 @@ bool js_cocos2dx_Configuration_getValue(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Configuration_getMaxTextureSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_getMaxTextureSize : Invalid Native Object"); @@ -402,7 +424,7 @@ bool js_cocos2dx_Configuration_getMaxTextureSize(JSContext *cx, uint32_t argc, j int ret = cobj->getMaxTextureSize(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -411,7 +433,8 @@ bool js_cocos2dx_Configuration_getMaxTextureSize(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_Configuration_supportsBGRA8888(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Configuration* cobj = (cocos2d::Configuration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Configuration_supportsBGRA8888 : Invalid Native Object"); @@ -419,7 +442,7 @@ bool js_cocos2dx_Configuration_supportsBGRA8888(JSContext *cx, uint32_t argc, js bool ret = cobj->supportsBGRA8888(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -428,9 +451,10 @@ bool js_cocos2dx_Configuration_supportsBGRA8888(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_Configuration_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Configuration::destroyInstance(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Configuration_destroyInstance : wrong number of arguments"); @@ -439,6 +463,7 @@ bool js_cocos2dx_Configuration_destroyInstance(JSContext *cx, uint32_t argc, jsv bool js_cocos2dx_Configuration_getInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Configuration* ret = cocos2d::Configuration::getInstance(); jsval jsret = JSVAL_NULL; @@ -450,7 +475,7 @@ bool js_cocos2dx_Configuration_getInstance(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Configuration_getInstance : wrong number of arguments"); @@ -463,7 +488,7 @@ void js_cocos2d_Configuration_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Configuration)", obj); } -void js_register_cocos2dx_Configuration(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Configuration(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Configuration_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Configuration_class->name = "Configuration"; jsb_cocos2d_Configuration_class->addProperty = JS_PropertyStub; @@ -477,8 +502,8 @@ void js_register_cocos2dx_Configuration(JSContext *cx, JSObject *global) { jsb_cocos2d_Configuration_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -514,7 +539,7 @@ void js_register_cocos2dx_Configuration(JSContext *cx, JSObject *global) { jsb_cocos2d_Configuration_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_Configuration_class, empty_constructor, 0, properties, @@ -545,7 +570,8 @@ JSObject *jsb_cocos2d_Texture2D_prototype; bool js_cocos2dx_Texture2D_getGLProgram(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_getGLProgram : Invalid Native Object"); @@ -560,7 +586,7 @@ bool js_cocos2dx_Texture2D_getGLProgram(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -569,7 +595,8 @@ bool js_cocos2dx_Texture2D_getGLProgram(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Texture2D_getMaxT(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_getMaxT : Invalid Native Object"); @@ -577,7 +604,7 @@ bool js_cocos2dx_Texture2D_getMaxT(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getMaxT(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -586,7 +613,8 @@ bool js_cocos2dx_Texture2D_getMaxT(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Texture2D_getStringForFormat(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_getStringForFormat : Invalid Native Object"); @@ -594,7 +622,7 @@ bool js_cocos2dx_Texture2D_getStringForFormat(JSContext *cx, uint32_t argc, jsva const char* ret = cobj->getStringForFormat(); jsval jsret = JSVAL_NULL; jsret = c_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -603,12 +631,12 @@ bool js_cocos2dx_Texture2D_getStringForFormat(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_Texture2D_initWithImage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Texture2D* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_initWithImage : Invalid Native Object"); @@ -616,21 +644,21 @@ bool js_cocos2dx_Texture2D_initWithImage(JSContext *cx, uint32_t argc, jsval *vp if (argc == 2) { cocos2d::Image* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Image*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::Texture2D::PixelFormat arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } bool ret = cobj->initWithImage(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -639,9 +667,9 @@ bool js_cocos2dx_Texture2D_initWithImage(JSContext *cx, uint32_t argc, jsval *vp if (argc == 1) { cocos2d::Image* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Image*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -650,7 +678,7 @@ bool js_cocos2dx_Texture2D_initWithImage(JSContext *cx, uint32_t argc, jsval *vp bool ret = cobj->initWithImage(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -660,25 +688,25 @@ bool js_cocos2dx_Texture2D_initWithImage(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Texture2D_setGLProgram(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_setGLProgram : Invalid Native Object"); if (argc == 1) { cocos2d::GLProgram* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::GLProgram*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Texture2D_setGLProgram : Error processing arguments"); cobj->setGLProgram(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -687,7 +715,8 @@ bool js_cocos2dx_Texture2D_setGLProgram(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Texture2D_getMaxS(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_getMaxS : Invalid Native Object"); @@ -695,7 +724,7 @@ bool js_cocos2dx_Texture2D_getMaxS(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getMaxS(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -704,13 +733,14 @@ bool js_cocos2dx_Texture2D_getMaxS(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Texture2D_releaseGLTexture(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_releaseGLTexture : Invalid Native Object"); if (argc == 0) { cobj->releaseGLTexture(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -719,7 +749,8 @@ bool js_cocos2dx_Texture2D_releaseGLTexture(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Texture2D_hasPremultipliedAlpha(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_hasPremultipliedAlpha : Invalid Native Object"); @@ -727,7 +758,7 @@ bool js_cocos2dx_Texture2D_hasPremultipliedAlpha(JSContext *cx, uint32_t argc, j bool ret = cobj->hasPremultipliedAlpha(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -736,9 +767,9 @@ bool js_cocos2dx_Texture2D_hasPremultipliedAlpha(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_Texture2D_initWithMipmaps(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_initWithMipmaps : Invalid Native Object"); @@ -750,15 +781,15 @@ bool js_cocos2dx_Texture2D_initWithMipmaps(JSContext *cx, uint32_t argc, jsval * int arg4; #pragma warning NO CONVERSION TO NATIVE FOR _MipmapInfo* ok = false; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Texture2D_initWithMipmaps : Error processing arguments"); bool ret = cobj->initWithMipmaps(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -767,7 +798,8 @@ bool js_cocos2dx_Texture2D_initWithMipmaps(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Texture2D_getPixelsHigh(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_getPixelsHigh : Invalid Native Object"); @@ -775,7 +807,7 @@ bool js_cocos2dx_Texture2D_getPixelsHigh(JSContext *cx, uint32_t argc, jsval *vp int ret = cobj->getPixelsHigh(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -784,24 +816,24 @@ bool js_cocos2dx_Texture2D_getPixelsHigh(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Texture2D_getBitsPerPixelForFormat(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Texture2D* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_getBitsPerPixelForFormat : Invalid Native Object"); do { if (argc == 1) { cocos2d::Texture2D::PixelFormat arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } unsigned int ret = cobj->getBitsPerPixelForFormat(arg0); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -811,7 +843,7 @@ bool js_cocos2dx_Texture2D_getBitsPerPixelForFormat(JSContext *cx, uint32_t argc unsigned int ret = cobj->getBitsPerPixelForFormat(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -821,7 +853,8 @@ bool js_cocos2dx_Texture2D_getBitsPerPixelForFormat(JSContext *cx, uint32_t argc } bool js_cocos2dx_Texture2D_getName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_getName : Invalid Native Object"); @@ -829,7 +862,7 @@ bool js_cocos2dx_Texture2D_getName(JSContext *cx, uint32_t argc, jsval *vp) unsigned int ret = cobj->getName(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -838,27 +871,27 @@ bool js_cocos2dx_Texture2D_getName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Texture2D_initWithString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Texture2D* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_initWithString : Invalid Native Object"); do { if (argc == 2) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } cocos2d::FontDefinition arg1; - ok &= jsval_to_FontDefinition(cx, argv[1], &arg1); + ok &= jsval_to_FontDefinition(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool ret = cobj->initWithString(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -866,18 +899,18 @@ bool js_cocos2dx_Texture2D_initWithString(JSContext *cx, uint32_t argc, jsval *v do { if (argc == 3) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } bool ret = cobj->initWithString(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -885,21 +918,21 @@ bool js_cocos2dx_Texture2D_initWithString(JSContext *cx, uint32_t argc, jsval *v do { if (argc == 4) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::Size arg3; - ok &= jsval_to_ccsize(cx, argv[3], &arg3); + ok &= jsval_to_ccsize(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } bool ret = cobj->initWithString(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -907,24 +940,24 @@ bool js_cocos2dx_Texture2D_initWithString(JSContext *cx, uint32_t argc, jsval *v do { if (argc == 5) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::Size arg3; - ok &= jsval_to_ccsize(cx, argv[3], &arg3); + ok &= jsval_to_ccsize(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cocos2d::TextHAlignment arg4; - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); if (!ok) { ok = true; break; } bool ret = cobj->initWithString(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -932,27 +965,27 @@ bool js_cocos2dx_Texture2D_initWithString(JSContext *cx, uint32_t argc, jsval *v do { if (argc == 6) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::Size arg3; - ok &= jsval_to_ccsize(cx, argv[3], &arg3); + ok &= jsval_to_ccsize(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cocos2d::TextHAlignment arg4; - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); if (!ok) { ok = true; break; } cocos2d::TextVAlignment arg5; - ok &= jsval_to_int32(cx, argv[5], (int32_t *)&arg5); + ok &= jsval_to_int32(cx, args.get(5), (int32_t *)&arg5); if (!ok) { ok = true; break; } bool ret = cobj->initWithString(arg0, arg1, arg2, arg3, arg4, arg5); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -962,18 +995,18 @@ bool js_cocos2dx_Texture2D_initWithString(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Texture2D_setMaxT(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_setMaxT : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Texture2D_setMaxT : Error processing arguments"); cobj->setMaxT(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -982,18 +1015,18 @@ bool js_cocos2dx_Texture2D_setMaxT(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Texture2D_drawInRect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_drawInRect : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Texture2D_drawInRect : Error processing arguments"); cobj->drawInRect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1002,7 +1035,8 @@ bool js_cocos2dx_Texture2D_drawInRect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Texture2D_getContentSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_getContentSize : Invalid Native Object"); @@ -1010,7 +1044,7 @@ bool js_cocos2dx_Texture2D_getContentSize(JSContext *cx, uint32_t argc, jsval *v cocos2d::Size ret = cobj->getContentSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1019,13 +1053,14 @@ bool js_cocos2dx_Texture2D_getContentSize(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Texture2D_setAliasTexParameters(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_setAliasTexParameters : Invalid Native Object"); if (argc == 0) { cobj->setAliasTexParameters(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1034,13 +1069,14 @@ bool js_cocos2dx_Texture2D_setAliasTexParameters(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_Texture2D_setAntiAliasTexParameters(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_setAntiAliasTexParameters : Invalid Native Object"); if (argc == 0) { cobj->setAntiAliasTexParameters(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1049,13 +1085,14 @@ bool js_cocos2dx_Texture2D_setAntiAliasTexParameters(JSContext *cx, uint32_t arg } bool js_cocos2dx_Texture2D_generateMipmap(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_generateMipmap : Invalid Native Object"); if (argc == 0) { cobj->generateMipmap(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1064,7 +1101,8 @@ bool js_cocos2dx_Texture2D_generateMipmap(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Texture2D_getDescription(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_getDescription : Invalid Native Object"); @@ -1072,7 +1110,7 @@ bool js_cocos2dx_Texture2D_getDescription(JSContext *cx, uint32_t argc, jsval *v std::string ret = cobj->getDescription(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1081,7 +1119,8 @@ bool js_cocos2dx_Texture2D_getDescription(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Texture2D_getPixelFormat(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_getPixelFormat : Invalid Native Object"); @@ -1089,7 +1128,7 @@ bool js_cocos2dx_Texture2D_getPixelFormat(JSContext *cx, uint32_t argc, jsval *v int ret = (int)cobj->getPixelFormat(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1098,7 +1137,8 @@ bool js_cocos2dx_Texture2D_getPixelFormat(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Texture2D_getContentSizeInPixels(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_getContentSizeInPixels : Invalid Native Object"); @@ -1106,7 +1146,7 @@ bool js_cocos2dx_Texture2D_getContentSizeInPixels(JSContext *cx, uint32_t argc, const cocos2d::Size& ret = cobj->getContentSizeInPixels(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1115,7 +1155,8 @@ bool js_cocos2dx_Texture2D_getContentSizeInPixels(JSContext *cx, uint32_t argc, } bool js_cocos2dx_Texture2D_getPixelsWide(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_getPixelsWide : Invalid Native Object"); @@ -1123,7 +1164,7 @@ bool js_cocos2dx_Texture2D_getPixelsWide(JSContext *cx, uint32_t argc, jsval *vp int ret = cobj->getPixelsWide(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1132,18 +1173,18 @@ bool js_cocos2dx_Texture2D_getPixelsWide(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Texture2D_drawAtPoint(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_drawAtPoint : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Texture2D_drawAtPoint : Error processing arguments"); cobj->drawAtPoint(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1152,7 +1193,8 @@ bool js_cocos2dx_Texture2D_drawAtPoint(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Texture2D_hasMipmaps(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_hasMipmaps : Invalid Native Object"); @@ -1160,7 +1202,7 @@ bool js_cocos2dx_Texture2D_hasMipmaps(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->hasMipmaps(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1169,18 +1211,18 @@ bool js_cocos2dx_Texture2D_hasMipmaps(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Texture2D_setMaxS(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Texture2D* cobj = (cocos2d::Texture2D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Texture2D_setMaxS : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Texture2D_setMaxS : Error processing arguments"); cobj->setMaxS(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1189,14 +1231,14 @@ bool js_cocos2dx_Texture2D_setMaxS(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Texture2D_setDefaultAlphaPixelFormat(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Texture2D::PixelFormat arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Texture2D_setDefaultAlphaPixelFormat : Error processing arguments"); cocos2d::Texture2D::setDefaultAlphaPixelFormat(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Texture2D_setDefaultAlphaPixelFormat : wrong number of arguments"); @@ -1205,11 +1247,12 @@ bool js_cocos2dx_Texture2D_setDefaultAlphaPixelFormat(JSContext *cx, uint32_t ar bool js_cocos2dx_Texture2D_getDefaultAlphaPixelFormat(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { int ret = (int)cocos2d::Texture2D::getDefaultAlphaPixelFormat(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Texture2D_getDefaultAlphaPixelFormat : wrong number of arguments"); @@ -1218,7 +1261,7 @@ bool js_cocos2dx_Texture2D_getDefaultAlphaPixelFormat(JSContext *cx, uint32_t ar bool js_cocos2dx_Texture2D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Texture2D* cobj = new (std::nothrow) cocos2d::Texture2D(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1232,13 +1275,16 @@ bool js_cocos2dx_Texture2D_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Texture2D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Texture2D"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -1248,7 +1294,7 @@ void js_cocos2d_Texture2D_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Texture2D)", obj); } -void js_register_cocos2dx_Texture2D(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Texture2D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Texture2D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Texture2D_class->name = "Texture2D"; jsb_cocos2d_Texture2D_class->addProperty = JS_PropertyStub; @@ -1262,8 +1308,8 @@ void js_register_cocos2dx_Texture2D(JSContext *cx, JSObject *global) { jsb_cocos2d_Texture2D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1304,7 +1350,7 @@ void js_register_cocos2dx_Texture2D(JSContext *cx, JSObject *global) { jsb_cocos2d_Texture2D_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_Texture2D_class, js_cocos2dx_Texture2D_constructor, 0, // constructor properties, @@ -1335,7 +1381,8 @@ JSObject *jsb_cocos2d_Touch_prototype; bool js_cocos2dx_Touch_getPreviousLocationInView(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Touch* cobj = (cocos2d::Touch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Touch_getPreviousLocationInView : Invalid Native Object"); @@ -1343,7 +1390,7 @@ bool js_cocos2dx_Touch_getPreviousLocationInView(JSContext *cx, uint32_t argc, j cocos2d::Vec2 ret = cobj->getPreviousLocationInView(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1352,7 +1399,8 @@ bool js_cocos2dx_Touch_getPreviousLocationInView(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_Touch_getLocation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Touch* cobj = (cocos2d::Touch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Touch_getLocation : Invalid Native Object"); @@ -1360,7 +1408,7 @@ bool js_cocos2dx_Touch_getLocation(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec2 ret = cobj->getLocation(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1369,7 +1417,8 @@ bool js_cocos2dx_Touch_getLocation(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Touch_getDelta(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Touch* cobj = (cocos2d::Touch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Touch_getDelta : Invalid Native Object"); @@ -1377,7 +1426,7 @@ bool js_cocos2dx_Touch_getDelta(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec2 ret = cobj->getDelta(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1386,7 +1435,8 @@ bool js_cocos2dx_Touch_getDelta(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Touch_getStartLocationInView(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Touch* cobj = (cocos2d::Touch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Touch_getStartLocationInView : Invalid Native Object"); @@ -1394,7 +1444,7 @@ bool js_cocos2dx_Touch_getStartLocationInView(JSContext *cx, uint32_t argc, jsva cocos2d::Vec2 ret = cobj->getStartLocationInView(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1403,7 +1453,8 @@ bool js_cocos2dx_Touch_getStartLocationInView(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_Touch_getStartLocation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Touch* cobj = (cocos2d::Touch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Touch_getStartLocation : Invalid Native Object"); @@ -1411,7 +1462,7 @@ bool js_cocos2dx_Touch_getStartLocation(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec2 ret = cobj->getStartLocation(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1420,7 +1471,8 @@ bool js_cocos2dx_Touch_getStartLocation(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Touch_getID(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Touch* cobj = (cocos2d::Touch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Touch_getID : Invalid Native Object"); @@ -1428,7 +1480,7 @@ bool js_cocos2dx_Touch_getID(JSContext *cx, uint32_t argc, jsval *vp) int ret = cobj->getID(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1437,9 +1489,9 @@ bool js_cocos2dx_Touch_getID(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Touch_setTouchInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Touch* cobj = (cocos2d::Touch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Touch_setTouchInfo : Invalid Native Object"); @@ -1447,12 +1499,12 @@ bool js_cocos2dx_Touch_setTouchInfo(JSContext *cx, uint32_t argc, jsval *vp) int arg0; double arg1; double arg2; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Touch_setTouchInfo : Error processing arguments"); cobj->setTouchInfo(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1461,7 +1513,8 @@ bool js_cocos2dx_Touch_setTouchInfo(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Touch_getLocationInView(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Touch* cobj = (cocos2d::Touch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Touch_getLocationInView : Invalid Native Object"); @@ -1469,7 +1522,7 @@ bool js_cocos2dx_Touch_getLocationInView(JSContext *cx, uint32_t argc, jsval *vp cocos2d::Vec2 ret = cobj->getLocationInView(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1478,7 +1531,8 @@ bool js_cocos2dx_Touch_getLocationInView(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Touch_getPreviousLocation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Touch* cobj = (cocos2d::Touch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Touch_getPreviousLocation : Invalid Native Object"); @@ -1486,7 +1540,7 @@ bool js_cocos2dx_Touch_getPreviousLocation(JSContext *cx, uint32_t argc, jsval * cocos2d::Vec2 ret = cobj->getPreviousLocation(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1495,7 +1549,7 @@ bool js_cocos2dx_Touch_getPreviousLocation(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Touch_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Touch* cobj = new (std::nothrow) cocos2d::Touch(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1509,13 +1563,16 @@ bool js_cocos2dx_Touch_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Touch"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Touch"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -1525,7 +1582,7 @@ void js_cocos2d_Touch_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Touch)", obj); } -void js_register_cocos2dx_Touch(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Touch(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Touch_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Touch_class->name = "Touch"; jsb_cocos2d_Touch_class->addProperty = JS_PropertyStub; @@ -1539,8 +1596,8 @@ void js_register_cocos2dx_Touch(JSContext *cx, JSObject *global) { jsb_cocos2d_Touch_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1560,7 +1617,7 @@ void js_register_cocos2dx_Touch(JSContext *cx, JSObject *global) { jsb_cocos2d_Touch_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_Touch_class, js_cocos2dx_Touch_constructor, 0, // constructor properties, @@ -1591,7 +1648,8 @@ JSObject *jsb_cocos2d_Event_prototype; bool js_cocos2dx_Event_isStopped(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Event* cobj = (cocos2d::Event *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Event_isStopped : Invalid Native Object"); @@ -1599,7 +1657,7 @@ bool js_cocos2dx_Event_isStopped(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isStopped(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1608,7 +1666,8 @@ bool js_cocos2dx_Event_isStopped(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Event_getType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Event* cobj = (cocos2d::Event *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Event_getType : Invalid Native Object"); @@ -1616,7 +1675,7 @@ bool js_cocos2dx_Event_getType(JSContext *cx, uint32_t argc, jsval *vp) int ret = (int)cobj->getType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1625,7 +1684,8 @@ bool js_cocos2dx_Event_getType(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Event_getCurrentTarget(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Event* cobj = (cocos2d::Event *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Event_getCurrentTarget : Invalid Native Object"); @@ -1640,7 +1700,7 @@ bool js_cocos2dx_Event_getCurrentTarget(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1649,13 +1709,14 @@ bool js_cocos2dx_Event_getCurrentTarget(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Event_stopPropagation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Event* cobj = (cocos2d::Event *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Event_stopPropagation : Invalid Native Object"); if (argc == 0) { cobj->stopPropagation(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1664,10 +1725,10 @@ bool js_cocos2dx_Event_stopPropagation(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Event_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Event::Type arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Event_constructor : Error processing arguments"); cocos2d::Event* cobj = new (std::nothrow) cocos2d::Event(arg0); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1681,13 +1742,16 @@ bool js_cocos2dx_Event_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Event"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Event"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -1697,7 +1761,7 @@ void js_cocos2d_Event_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Event)", obj); } -void js_register_cocos2dx_Event(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Event(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Event_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Event_class->name = "Event"; jsb_cocos2d_Event_class->addProperty = JS_PropertyStub; @@ -1711,8 +1775,8 @@ void js_register_cocos2dx_Event(JSContext *cx, JSObject *global) { jsb_cocos2d_Event_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1727,7 +1791,7 @@ void js_register_cocos2dx_Event(JSContext *cx, JSObject *global) { jsb_cocos2d_Event_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_Event_class, js_cocos2dx_Event_constructor, 0, // constructor properties, @@ -1758,7 +1822,8 @@ JSObject *jsb_cocos2d_EventTouch_prototype; bool js_cocos2dx_EventTouch_getEventCode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventTouch* cobj = (cocos2d::EventTouch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventTouch_getEventCode : Invalid Native Object"); @@ -1766,7 +1831,7 @@ bool js_cocos2dx_EventTouch_getEventCode(JSContext *cx, uint32_t argc, jsval *vp int ret = (int)cobj->getEventCode(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1775,18 +1840,18 @@ bool js_cocos2dx_EventTouch_getEventCode(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_EventTouch_setEventCode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventTouch* cobj = (cocos2d::EventTouch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventTouch_setEventCode : Invalid Native Object"); if (argc == 1) { cocos2d::EventTouch::EventCode arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventTouch_setEventCode : Error processing arguments"); cobj->setEventCode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1795,7 +1860,7 @@ bool js_cocos2dx_EventTouch_setEventCode(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_EventTouch_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EventTouch* cobj = new (std::nothrow) cocos2d::EventTouch(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1809,13 +1874,16 @@ bool js_cocos2dx_EventTouch_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventTouch"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventTouch"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -1826,7 +1894,7 @@ void js_cocos2d_EventTouch_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EventTouch)", obj); } -void js_register_cocos2dx_EventTouch(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EventTouch(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EventTouch_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EventTouch_class->name = "EventTouch"; jsb_cocos2d_EventTouch_class->addProperty = JS_PropertyStub; @@ -1840,8 +1908,8 @@ void js_register_cocos2dx_EventTouch(JSContext *cx, JSObject *global) { jsb_cocos2d_EventTouch_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1854,7 +1922,7 @@ void js_register_cocos2dx_EventTouch(JSContext *cx, JSObject *global) { jsb_cocos2d_EventTouch_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Event_prototype, + JS::RootedObject(cx, jsb_cocos2d_Event_prototype), jsb_cocos2d_EventTouch_class, js_cocos2dx_EventTouch_constructor, 0, // constructor properties, @@ -1880,110 +1948,17 @@ void js_register_cocos2dx_EventTouch(JSContext *cx, JSObject *global) { } } -JSClass *jsb_cocos2d_EventKeyboard_class; -JSObject *jsb_cocos2d_EventKeyboard_prototype; - -bool js_cocos2dx_EventKeyboard_constructor(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - cocos2d::EventKeyboard::KeyCode arg0; - bool arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventKeyboard_constructor : Error processing arguments"); - cocos2d::EventKeyboard* cobj = new (std::nothrow) cocos2d::EventKeyboard(arg0, arg1); - cocos2d::Ref *_ccobj = dynamic_cast(cobj); - if (_ccobj) { - _ccobj->autorelease(); - } - TypeTest t; - js_type_class_t *typeClass = nullptr; - std::string typeName = t.s_name(); - auto typeMapIter = _js_global_type_map.find(typeName); - CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); - typeClass = typeMapIter->second; - CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); - // link the native object with the javascript object - js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventKeyboard"); - if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - return true; -} - - -extern JSObject *jsb_cocos2d_Event_prototype; - -void js_cocos2d_EventKeyboard_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (EventKeyboard)", obj); -} - -void js_register_cocos2dx_EventKeyboard(JSContext *cx, JSObject *global) { - jsb_cocos2d_EventKeyboard_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_EventKeyboard_class->name = "EventKeyboard"; - jsb_cocos2d_EventKeyboard_class->addProperty = JS_PropertyStub; - jsb_cocos2d_EventKeyboard_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_EventKeyboard_class->getProperty = JS_PropertyStub; - jsb_cocos2d_EventKeyboard_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_EventKeyboard_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_EventKeyboard_class->resolve = JS_ResolveStub; - jsb_cocos2d_EventKeyboard_class->convert = JS_ConvertStub; - jsb_cocos2d_EventKeyboard_class->finalize = js_cocos2d_EventKeyboard_finalize; - jsb_cocos2d_EventKeyboard_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); - - static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} - }; - - static JSFunctionSpec funcs[] = { - JS_FS_END - }; - - JSFunctionSpec *st_funcs = NULL; - - jsb_cocos2d_EventKeyboard_prototype = JS_InitClass( - cx, global, - jsb_cocos2d_Event_prototype, - jsb_cocos2d_EventKeyboard_class, - js_cocos2dx_EventKeyboard_constructor, 0, // constructor - properties, - funcs, - NULL, // no static properties - st_funcs); - // make the class enumerable in the registered namespace -// bool found; -//FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "EventKeyboard", JSPROP_ENUMERATE | JSPROP_READONLY, &found); - - // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_EventKeyboard_class; - p->proto = jsb_cocos2d_EventKeyboard_prototype; - p->parentProto = jsb_cocos2d_Event_prototype; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } -} - JSClass *jsb_cocos2d_Node_class; JSObject *jsb_cocos2d_Node_prototype; bool js_cocos2dx_Node_addChild(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Node* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_addChild : Invalid Native Object"); @@ -1991,19 +1966,19 @@ bool js_cocos2dx_Node_addChild(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 2) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cobj->addChild(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -2012,16 +1987,16 @@ bool js_cocos2dx_Node_addChild(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cobj->addChild(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -2030,22 +2005,22 @@ bool js_cocos2dx_Node_addChild(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 3) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } int arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } cobj->addChild(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -2054,22 +2029,22 @@ bool js_cocos2dx_Node_addChild(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 3) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } std::string arg2; - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } cobj->addChild(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -2079,12 +2054,12 @@ bool js_cocos2dx_Node_addChild(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_removeComponent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Node* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_removeComponent : Invalid Native Object"); @@ -2092,9 +2067,9 @@ bool js_cocos2dx_Node_removeComponent(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1) { cocos2d::Component* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Component*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -2103,7 +2078,7 @@ bool js_cocos2dx_Node_removeComponent(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->removeComponent(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -2111,12 +2086,12 @@ bool js_cocos2dx_Node_removeComponent(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } bool ret = cobj->removeComponent(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -2126,25 +2101,25 @@ bool js_cocos2dx_Node_removeComponent(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setPhysicsBody(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setPhysicsBody : Invalid Native Object"); if (argc == 1) { cocos2d::PhysicsBody* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::PhysicsBody*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setPhysicsBody : Error processing arguments"); cobj->setPhysicsBody(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2153,7 +2128,8 @@ bool js_cocos2dx_Node_setPhysicsBody(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getGLProgram(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getGLProgram : Invalid Native Object"); @@ -2168,16 +2144,39 @@ bool js_cocos2dx_Node_getGLProgram(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Node_getGLProgram : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_Node_updateTransformFromPhysics(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_updateTransformFromPhysics : Invalid Native Object"); + if (argc == 2) { + cocos2d::Mat4 arg0; + unsigned int arg1; + ok &= jsval_to_matrix(cx, args.get(0), &arg0); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_updateTransformFromPhysics : Error processing arguments"); + cobj->updateTransformFromPhysics(arg0, arg1); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Node_updateTransformFromPhysics : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} bool js_cocos2dx_Node_getDescription(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getDescription : Invalid Native Object"); @@ -2185,7 +2184,7 @@ bool js_cocos2dx_Node_getDescription(JSContext *cx, uint32_t argc, jsval *vp) std::string ret = cobj->getDescription(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2194,18 +2193,18 @@ bool js_cocos2dx_Node_getDescription(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setOpacityModifyRGB : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setOpacityModifyRGB : Error processing arguments"); cobj->setOpacityModifyRGB(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2214,18 +2213,18 @@ bool js_cocos2dx_Node_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Node_setCascadeOpacityEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setCascadeOpacityEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setCascadeOpacityEnabled : Error processing arguments"); cobj->setCascadeOpacityEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2234,12 +2233,12 @@ bool js_cocos2dx_Node_setCascadeOpacityEnabled(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_Node_getChildren(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Node* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getChildren : Invalid Native Object"); @@ -2248,7 +2247,7 @@ bool js_cocos2dx_Node_getChildren(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Vector& ret = cobj->getChildren(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -2258,7 +2257,7 @@ bool js_cocos2dx_Node_getChildren(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vector& ret = cobj->getChildren(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -2268,21 +2267,22 @@ bool js_cocos2dx_Node_getChildren(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setOnExitCallback(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setOnExitCallback : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=]() -> void { - jsval rval; - bool ok = func->invoke(0, nullptr, rval); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + JS::RootedValue rval(cx); + bool ok = func->invoke(0, nullptr, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -2297,7 +2297,7 @@ bool js_cocos2dx_Node_setOnExitCallback(JSContext *cx, uint32_t argc, jsval *vp) ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setOnExitCallback : Error processing arguments"); cobj->setOnExitCallback(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2306,20 +2306,20 @@ bool js_cocos2dx_Node_setOnExitCallback(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_convertToWorldSpaceAR(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_convertToWorldSpaceAR : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_convertToWorldSpaceAR : Error processing arguments"); cocos2d::Vec2 ret = cobj->convertToWorldSpaceAR(arg0); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2328,7 +2328,8 @@ bool js_cocos2dx_Node_convertToWorldSpaceAR(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Node_isIgnoreAnchorPointForPosition(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_isIgnoreAnchorPointForPosition : Invalid Native Object"); @@ -2336,7 +2337,7 @@ bool js_cocos2dx_Node_isIgnoreAnchorPointForPosition(JSContext *cx, uint32_t arg bool ret = cobj->isIgnoreAnchorPointForPosition(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2345,15 +2346,15 @@ bool js_cocos2dx_Node_isIgnoreAnchorPointForPosition(JSContext *cx, uint32_t arg } bool js_cocos2dx_Node_getChildByName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getChildByName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_getChildByName : Error processing arguments"); cocos2d::Node* ret = cobj->getChildByName(arg0); jsval jsret = JSVAL_NULL; @@ -2365,7 +2366,7 @@ bool js_cocos2dx_Node_getChildByName(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2374,18 +2375,18 @@ bool js_cocos2dx_Node_getChildByName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_updateDisplayedOpacity(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_updateDisplayedOpacity : Invalid Native Object"); if (argc == 1) { uint16_t arg0; - ok &= jsval_to_uint16(cx, argv[0], &arg0); + ok &= jsval_to_uint16(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_updateDisplayedOpacity : Error processing arguments"); cobj->updateDisplayedOpacity(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2394,7 +2395,8 @@ bool js_cocos2dx_Node_updateDisplayedOpacity(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Node_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_init : Invalid Native Object"); @@ -2402,7 +2404,7 @@ bool js_cocos2dx_Node_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2411,7 +2413,8 @@ bool js_cocos2dx_Node_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getCameraMask(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getCameraMask : Invalid Native Object"); @@ -2419,7 +2422,7 @@ bool js_cocos2dx_Node_getCameraMask(JSContext *cx, uint32_t argc, jsval *vp) unsigned short ret = cobj->getCameraMask(); jsval jsret = JSVAL_NULL; jsret = ushort_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2428,18 +2431,18 @@ bool js_cocos2dx_Node_getCameraMask(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setRotation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setRotation : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setRotation : Error processing arguments"); cobj->setRotation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2448,18 +2451,18 @@ bool js_cocos2dx_Node_setRotation(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setScaleZ(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setScaleZ : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setScaleZ : Error processing arguments"); cobj->setScaleZ(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2468,18 +2471,18 @@ bool js_cocos2dx_Node_setScaleZ(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setScaleY(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setScaleY : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setScaleY : Error processing arguments"); cobj->setScaleY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2488,18 +2491,18 @@ bool js_cocos2dx_Node_setScaleY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setScaleX(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setScaleX : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setScaleX : Error processing arguments"); cobj->setScaleX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2508,7 +2511,8 @@ bool js_cocos2dx_Node_setScaleX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getColor : Invalid Native Object"); @@ -2516,7 +2520,7 @@ bool js_cocos2dx_Node_getColor(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Color3B& ret = cobj->getColor(); jsval jsret = JSVAL_NULL; jsret = cccolor3b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2525,21 +2529,22 @@ bool js_cocos2dx_Node_getColor(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setonEnterTransitionDidFinishCallback(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setonEnterTransitionDidFinishCallback : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=]() -> void { - jsval rval; - bool ok = func->invoke(0, nullptr, rval); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + JS::RootedValue rval(cx); + bool ok = func->invoke(0, nullptr, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -2554,7 +2559,7 @@ bool js_cocos2dx_Node_setonEnterTransitionDidFinishCallback(JSContext *cx, uint3 ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setonEnterTransitionDidFinishCallback : Error processing arguments"); cobj->setonEnterTransitionDidFinishCallback(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2563,13 +2568,14 @@ bool js_cocos2dx_Node_setonEnterTransitionDidFinishCallback(JSContext *cx, uint3 } bool js_cocos2dx_Node_removeFromPhysicsWorld(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_removeFromPhysicsWorld : Invalid Native Object"); if (argc == 0) { cobj->removeFromPhysicsWorld(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2578,13 +2584,14 @@ bool js_cocos2dx_Node_removeFromPhysicsWorld(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Node_removeAllComponents(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_removeAllComponents : Invalid Native Object"); if (argc == 0) { cobj->removeAllComponents(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2593,7 +2600,8 @@ bool js_cocos2dx_Node_removeAllComponents(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Node_getOpacity(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getOpacity : Invalid Native Object"); @@ -2601,7 +2609,7 @@ bool js_cocos2dx_Node_getOpacity(JSContext *cx, uint32_t argc, jsval *vp) uint16_t ret = cobj->getOpacity(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2610,28 +2618,28 @@ bool js_cocos2dx_Node_getOpacity(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setCameraMask(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setCameraMask : Invalid Native Object"); if (argc == 1) { unsigned short arg0; - ok &= jsval_to_ushort(cx, argv[0], &arg0); + ok &= jsval_to_ushort(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setCameraMask : Error processing arguments"); cobj->setCameraMask(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { unsigned short arg0; bool arg1; - ok &= jsval_to_ushort(cx, argv[0], &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= jsval_to_ushort(cx, args.get(0), &arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setCameraMask : Error processing arguments"); cobj->setCameraMask(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2640,7 +2648,8 @@ bool js_cocos2dx_Node_setCameraMask(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getTag(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getTag : Invalid Native Object"); @@ -2648,7 +2657,7 @@ bool js_cocos2dx_Node_getTag(JSContext *cx, uint32_t argc, jsval *vp) int ret = cobj->getTag(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2657,7 +2666,8 @@ bool js_cocos2dx_Node_getTag(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getonEnterTransitionDidFinishCallback(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getonEnterTransitionDidFinishCallback : Invalid Native Object"); @@ -2665,50 +2675,53 @@ bool js_cocos2dx_Node_getonEnterTransitionDidFinishCallback(JSContext *cx, uint3 const std::function& ret = cobj->getonEnterTransitionDidFinishCallback(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR std::function; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Node_getonEnterTransitionDidFinishCallback : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_Node_getNodeToWorldAffineTransform(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_Node_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getNodeToWorldAffineTransform : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_isOpacityModifyRGB : Invalid Native Object"); if (argc == 0) { - cocos2d::AffineTransform ret = cobj->getNodeToWorldAffineTransform(); + bool ret = cobj->isOpacityModifyRGB(); jsval jsret = JSVAL_NULL; - jsret = ccaffinetransform_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_Node_getNodeToWorldAffineTransform : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_Node_isOpacityModifyRGB : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_Node_getNodeToWorldTransform(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_Node_getNodeToWorldAffineTransform(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getNodeToWorldTransform : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getNodeToWorldAffineTransform : Invalid Native Object"); if (argc == 0) { - cocos2d::Mat4 ret = cobj->getNodeToWorldTransform(); + cocos2d::AffineTransform ret = cobj->getNodeToWorldAffineTransform(); jsval jsret = JSVAL_NULL; - jsret = matrix_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = ccaffinetransform_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_Node_getNodeToWorldTransform : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_Node_getNodeToWorldAffineTransform : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } bool js_cocos2dx_Node_getPosition3D(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getPosition3D : Invalid Native Object"); @@ -2716,7 +2729,7 @@ bool js_cocos2dx_Node_getPosition3D(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec3 ret = cobj->getPosition3D(); jsval jsret = JSVAL_NULL; jsret = vector3_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2725,42 +2738,42 @@ bool js_cocos2dx_Node_getPosition3D(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_removeChild(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_removeChild : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_removeChild : Error processing arguments"); cobj->removeChild(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { cocos2d::Node* arg0; bool arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_removeChild : Error processing arguments"); cobj->removeChild(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2769,20 +2782,20 @@ bool js_cocos2dx_Node_removeChild(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_convertToWorldSpace(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_convertToWorldSpace : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_convertToWorldSpace : Error processing arguments"); cocos2d::Vec2 ret = cobj->convertToWorldSpace(arg0); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2791,7 +2804,8 @@ bool js_cocos2dx_Node_convertToWorldSpace(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Node_getScene(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getScene : Invalid Native Object"); @@ -2806,7 +2820,7 @@ bool js_cocos2dx_Node_getScene(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2815,7 +2829,8 @@ bool js_cocos2dx_Node_getScene(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getEventDispatcher(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getEventDispatcher : Invalid Native Object"); @@ -2830,7 +2845,7 @@ bool js_cocos2dx_Node_getEventDispatcher(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2839,18 +2854,18 @@ bool js_cocos2dx_Node_getEventDispatcher(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Node_setSkewX(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setSkewX : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setSkewX : Error processing arguments"); cobj->setSkewX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2859,25 +2874,25 @@ bool js_cocos2dx_Node_setSkewX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setGLProgramState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setGLProgramState : Invalid Native Object"); if (argc == 1) { cocos2d::GLProgramState* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::GLProgramState*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setGLProgramState : Error processing arguments"); cobj->setGLProgramState(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2886,21 +2901,22 @@ bool js_cocos2dx_Node_setGLProgramState(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setOnEnterCallback(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setOnEnterCallback : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=]() -> void { - jsval rval; - bool ok = func->invoke(0, nullptr, rval); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + JS::RootedValue rval(cx); + bool ok = func->invoke(0, nullptr, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -2915,7 +2931,7 @@ bool js_cocos2dx_Node_setOnEnterCallback(JSContext *cx, uint32_t argc, jsval *vp ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setOnEnterCallback : Error processing arguments"); cobj->setOnEnterCallback(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2924,18 +2940,18 @@ bool js_cocos2dx_Node_setOnEnterCallback(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Node_setNormalizedPosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setNormalizedPosition : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setNormalizedPosition : Error processing arguments"); cobj->setNormalizedPosition(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2944,21 +2960,22 @@ bool js_cocos2dx_Node_setNormalizedPosition(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Node_setonExitTransitionDidStartCallback(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setonExitTransitionDidStartCallback : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=]() -> void { - jsval rval; - bool ok = func->invoke(0, nullptr, rval); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + JS::RootedValue rval(cx); + bool ok = func->invoke(0, nullptr, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -2973,7 +2990,7 @@ bool js_cocos2dx_Node_setonExitTransitionDidStartCallback(JSContext *cx, uint32_ ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setonExitTransitionDidStartCallback : Error processing arguments"); cobj->setonExitTransitionDidStartCallback(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2982,18 +2999,18 @@ bool js_cocos2dx_Node_setonExitTransitionDidStartCallback(JSContext *cx, uint32_ } bool js_cocos2dx_Node_convertTouchToNodeSpace(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_convertTouchToNodeSpace : Invalid Native Object"); if (argc == 1) { cocos2d::Touch* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Touch*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -3002,7 +3019,7 @@ bool js_cocos2dx_Node_convertTouchToNodeSpace(JSContext *cx, uint32_t argc, jsva cocos2d::Vec2 ret = cobj->convertTouchToNodeSpace(arg0); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3011,21 +3028,21 @@ bool js_cocos2dx_Node_convertTouchToNodeSpace(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_Node_removeAllChildrenWithCleanup(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Node* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_removeAllChildrenWithCleanup : Invalid Native Object"); do { if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); cobj->removeAllChildrenWithCleanup(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -3033,7 +3050,7 @@ bool js_cocos2dx_Node_removeAllChildrenWithCleanup(JSContext *cx, uint32_t argc, do { if (argc == 0) { cobj->removeAllChildren(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -3043,7 +3060,8 @@ bool js_cocos2dx_Node_removeAllChildrenWithCleanup(JSContext *cx, uint32_t argc, } bool js_cocos2dx_Node_getRotationSkewX(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getRotationSkewX : Invalid Native Object"); @@ -3051,7 +3069,7 @@ bool js_cocos2dx_Node_getRotationSkewX(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getRotationSkewX(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3060,7 +3078,8 @@ bool js_cocos2dx_Node_getRotationSkewX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getRotationSkewY(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getRotationSkewY : Invalid Native Object"); @@ -3068,33 +3087,35 @@ bool js_cocos2dx_Node_getRotationSkewY(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getRotationSkewY(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Node_getRotationSkewY : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_Node_getNodeToParentAffineTransform(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_Node_getNodeToWorldTransform(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getNodeToParentAffineTransform : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getNodeToWorldTransform : Invalid Native Object"); if (argc == 0) { - cocos2d::AffineTransform ret = cobj->getNodeToParentAffineTransform(); + cocos2d::Mat4 ret = cobj->getNodeToWorldTransform(); jsval jsret = JSVAL_NULL; - jsret = ccaffinetransform_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = matrix_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_Node_getNodeToParentAffineTransform : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_Node_getNodeToWorldTransform : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } bool js_cocos2dx_Node_isCascadeOpacityEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_isCascadeOpacityEnabled : Invalid Native Object"); @@ -3102,7 +3123,7 @@ bool js_cocos2dx_Node_isCascadeOpacityEnabled(JSContext *cx, uint32_t argc, jsva bool ret = cobj->isCascadeOpacityEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3111,25 +3132,25 @@ bool js_cocos2dx_Node_isCascadeOpacityEnabled(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_Node_setParent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setParent : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setParent : Error processing arguments"); cobj->setParent(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3138,7 +3159,8 @@ bool js_cocos2dx_Node_setParent(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getName : Invalid Native Object"); @@ -3146,7 +3168,7 @@ bool js_cocos2dx_Node_getName(JSContext *cx, uint32_t argc, jsval *vp) std::string ret = cobj->getName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3155,7 +3177,8 @@ bool js_cocos2dx_Node_getName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getRotation3D(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getRotation3D : Invalid Native Object"); @@ -3163,44 +3186,45 @@ bool js_cocos2dx_Node_getRotation3D(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec3 ret = cobj->getRotation3D(); jsval jsret = JSVAL_NULL; jsret = vector3_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Node_getRotation3D : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_Node_getNodeToParentTransform(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_Node_getNodeToParentAffineTransform(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getNodeToParentTransform : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getNodeToParentAffineTransform : Invalid Native Object"); if (argc == 0) { - const cocos2d::Mat4& ret = cobj->getNodeToParentTransform(); + cocos2d::AffineTransform ret = cobj->getNodeToParentAffineTransform(); jsval jsret = JSVAL_NULL; - jsret = matrix_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = ccaffinetransform_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_Node_getNodeToParentTransform : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_Node_getNodeToParentAffineTransform : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } bool js_cocos2dx_Node_convertTouchToNodeSpaceAR(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_convertTouchToNodeSpaceAR : Invalid Native Object"); if (argc == 1) { cocos2d::Touch* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Touch*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -3209,7 +3233,7 @@ bool js_cocos2dx_Node_convertTouchToNodeSpaceAR(JSContext *cx, uint32_t argc, js cocos2d::Vec2 ret = cobj->convertTouchToNodeSpaceAR(arg0); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3218,7 +3242,8 @@ bool js_cocos2dx_Node_convertTouchToNodeSpaceAR(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_Node_getOnEnterCallback(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getOnEnterCallback : Invalid Native Object"); @@ -3226,7 +3251,7 @@ bool js_cocos2dx_Node_getOnEnterCallback(JSContext *cx, uint32_t argc, jsval *vp const std::function& ret = cobj->getOnEnterCallback(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR std::function; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3235,7 +3260,8 @@ bool js_cocos2dx_Node_getOnEnterCallback(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Node_getPhysicsBody(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getPhysicsBody : Invalid Native Object"); @@ -3250,7 +3276,7 @@ bool js_cocos2dx_Node_getPhysicsBody(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3259,18 +3285,18 @@ bool js_cocos2dx_Node_getPhysicsBody(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_stopActionByTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_stopActionByTag : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_stopActionByTag : Error processing arguments"); cobj->stopActionByTag(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3279,9 +3305,9 @@ bool js_cocos2dx_Node_stopActionByTag(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_reorderChild(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_reorderChild : Invalid Native Object"); @@ -3289,17 +3315,17 @@ bool js_cocos2dx_Node_reorderChild(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Node* arg0; int arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_reorderChild : Error processing arguments"); cobj->reorderChild(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3308,18 +3334,18 @@ bool js_cocos2dx_Node_reorderChild(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_ignoreAnchorPointForPosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_ignoreAnchorPointForPosition : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_ignoreAnchorPointForPosition : Error processing arguments"); cobj->ignoreAnchorPointForPosition(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3328,18 +3354,18 @@ bool js_cocos2dx_Node_ignoreAnchorPointForPosition(JSContext *cx, uint32_t argc, } bool js_cocos2dx_Node_setSkewY(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setSkewY : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setSkewY : Error processing arguments"); cobj->setSkewY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3348,18 +3374,18 @@ bool js_cocos2dx_Node_setSkewY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setRotation3D(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setRotation3D : Invalid Native Object"); if (argc == 1) { cocos2d::Vec3 arg0; - ok &= jsval_to_vector3(cx, argv[0], &arg0); + ok &= jsval_to_vector3(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setRotation3D : Error processing arguments"); cobj->setRotation3D(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3368,18 +3394,18 @@ bool js_cocos2dx_Node_setRotation3D(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setPositionX(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setPositionX : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setPositionX : Error processing arguments"); cobj->setPositionX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3388,18 +3414,18 @@ bool js_cocos2dx_Node_setPositionX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setNodeToParentTransform(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setNodeToParentTransform : Invalid Native Object"); if (argc == 1) { cocos2d::Mat4 arg0; - ok &= jsval_to_matrix(cx, argv[0], &arg0); + ok &= jsval_to_matrix(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setNodeToParentTransform : Error processing arguments"); cobj->setNodeToParentTransform(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3408,7 +3434,8 @@ bool js_cocos2dx_Node_setNodeToParentTransform(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_Node_getAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getAnchorPoint : Invalid Native Object"); @@ -3416,7 +3443,7 @@ bool js_cocos2dx_Node_getAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Vec2& ret = cobj->getAnchorPoint(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3425,7 +3452,8 @@ bool js_cocos2dx_Node_getAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getNumberOfRunningActions(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getNumberOfRunningActions : Invalid Native Object"); @@ -3433,7 +3461,7 @@ bool js_cocos2dx_Node_getNumberOfRunningActions(JSContext *cx, uint32_t argc, js ssize_t ret = cobj->getNumberOfRunningActions(); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3442,13 +3470,14 @@ bool js_cocos2dx_Node_getNumberOfRunningActions(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_Node_updateTransform(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_updateTransform : Invalid Native Object"); if (argc == 0) { cobj->updateTransform(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3457,7 +3486,8 @@ bool js_cocos2dx_Node_updateTransform(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_isVisible(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_isVisible : Invalid Native Object"); @@ -3465,7 +3495,7 @@ bool js_cocos2dx_Node_isVisible(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isVisible(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3474,7 +3504,8 @@ bool js_cocos2dx_Node_isVisible(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getChildrenCount(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getChildrenCount : Invalid Native Object"); @@ -3482,29 +3513,47 @@ bool js_cocos2dx_Node_getChildrenCount(JSContext *cx, uint32_t argc, jsval *vp) ssize_t ret = cobj->getChildrenCount(); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Node_getChildrenCount : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_Node_getNodeToParentTransform(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getNodeToParentTransform : Invalid Native Object"); + if (argc == 0) { + const cocos2d::Mat4& ret = cobj->getNodeToParentTransform(); + jsval jsret = JSVAL_NULL; + jsret = matrix_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Node_getNodeToParentTransform : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_Node_convertToNodeSpaceAR(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_convertToNodeSpaceAR : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_convertToNodeSpaceAR : Error processing arguments"); cocos2d::Vec2 ret = cobj->convertToNodeSpaceAR(arg0); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3513,18 +3562,18 @@ bool js_cocos2dx_Node_convertToNodeSpaceAR(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Node_addComponent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_addComponent : Invalid Native Object"); if (argc == 1) { cocos2d::Component* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Component*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -3533,7 +3582,7 @@ bool js_cocos2dx_Node_addComponent(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->addComponent(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3542,18 +3591,18 @@ bool js_cocos2dx_Node_addComponent(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_runAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_runAction : Invalid Native Object"); if (argc == 1) { cocos2d::Action* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Action*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -3569,34 +3618,80 @@ bool js_cocos2dx_Node_runAction(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Node_runAction : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_Node_visit(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + JS::RootedObject obj(cx); + cocos2d::Node* cobj = NULL; + obj = args.thisv().toObjectOrNull(); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_visit : Invalid Native Object"); + do { + if (argc == 0) { + cobj->visit(); + args.rval().setUndefined(); + return true; + } + } while(0); + + do { + if (argc == 3) { + cocos2d::Renderer* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Renderer*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cocos2d::Mat4 arg1; + ok &= jsval_to_matrix(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + unsigned int arg2; + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + if (!ok) { ok = true; break; } + cobj->visit(arg0, arg1, arg2); + args.rval().setUndefined(); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_Node_visit : wrong number of arguments"); + return false; +} bool js_cocos2dx_Node_setGLProgram(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setGLProgram : Invalid Native Object"); if (argc == 1) { cocos2d::GLProgram* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::GLProgram*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setGLProgram : Error processing arguments"); cobj->setGLProgram(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3605,7 +3700,8 @@ bool js_cocos2dx_Node_setGLProgram(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getRotation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getRotation : Invalid Native Object"); @@ -3613,7 +3709,7 @@ bool js_cocos2dx_Node_getRotation(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getRotation(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3622,7 +3718,8 @@ bool js_cocos2dx_Node_getRotation(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getAnchorPointInPoints(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getAnchorPointInPoints : Invalid Native Object"); @@ -3630,83 +3727,55 @@ bool js_cocos2dx_Node_getAnchorPointInPoints(JSContext *cx, uint32_t argc, jsval const cocos2d::Vec2& ret = cobj->getAnchorPointInPoints(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Node_getAnchorPointInPoints : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_Node_visit(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_Node_getRotationQuat(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - - JSObject *obj = NULL; - cocos2d::Node* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_visit : Invalid Native Object"); - do { - if (argc == 0) { - cobj->visit(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - } while(0); - - do { - if (argc == 3) { - cocos2d::Renderer* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Renderer*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cocos2d::Mat4 arg1; - ok &= jsval_to_matrix(cx, argv[1], &arg1); - if (!ok) { ok = true; break; } - unsigned int arg2; - ok &= jsval_to_uint32(cx, argv[2], &arg2); - if (!ok) { ok = true; break; } - cobj->visit(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - } while(0); + cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getRotationQuat : Invalid Native Object"); + if (argc == 0) { + cocos2d::Quaternion ret = cobj->getRotationQuat(); + jsval jsret = JSVAL_NULL; + jsret = quaternion_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } - JS_ReportError(cx, "js_cocos2dx_Node_visit : wrong number of arguments"); + JS_ReportError(cx, "js_cocos2dx_Node_getRotationQuat : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } bool js_cocos2dx_Node_removeChildByName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_removeChildByName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_removeChildByName : Error processing arguments"); cobj->removeChildByName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; bool arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_removeChildByName : Error processing arguments"); cobj->removeChildByName(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3715,18 +3784,18 @@ bool js_cocos2dx_Node_removeChildByName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setPositionZ(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setPositionZ : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setPositionZ : Error processing arguments"); cobj->setPositionZ(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3735,7 +3804,8 @@ bool js_cocos2dx_Node_setPositionZ(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getGLProgramState(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getGLProgramState : Invalid Native Object"); @@ -3750,7 +3820,7 @@ bool js_cocos2dx_Node_getGLProgramState(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3759,25 +3829,25 @@ bool js_cocos2dx_Node_getGLProgramState(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setScheduler(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setScheduler : Invalid Native Object"); if (argc == 1) { cocos2d::Scheduler* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Scheduler*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setScheduler : Error processing arguments"); cobj->setScheduler(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3786,13 +3856,14 @@ bool js_cocos2dx_Node_setScheduler(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_stopAllActions(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_stopAllActions : Invalid Native Object"); if (argc == 0) { cobj->stopAllActions(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3801,7 +3872,8 @@ bool js_cocos2dx_Node_stopAllActions(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getSkewX(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getSkewX : Invalid Native Object"); @@ -3809,7 +3881,7 @@ bool js_cocos2dx_Node_getSkewX(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getSkewX(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3818,7 +3890,8 @@ bool js_cocos2dx_Node_getSkewX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getSkewY(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getSkewY : Invalid Native Object"); @@ -3826,7 +3899,7 @@ bool js_cocos2dx_Node_getSkewY(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getSkewY(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3835,20 +3908,20 @@ bool js_cocos2dx_Node_getSkewY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_isScheduled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_isScheduled : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_isScheduled : Error processing arguments"); bool ret = cobj->isScheduled(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3857,7 +3930,8 @@ bool js_cocos2dx_Node_isScheduled(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getDisplayedColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getDisplayedColor : Invalid Native Object"); @@ -3865,7 +3939,7 @@ bool js_cocos2dx_Node_getDisplayedColor(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Color3B& ret = cobj->getDisplayedColor(); jsval jsret = JSVAL_NULL; jsret = cccolor3b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3874,15 +3948,15 @@ bool js_cocos2dx_Node_getDisplayedColor(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getActionByTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getActionByTag : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_getActionByTag : Error processing arguments"); cocos2d::Action* ret = cobj->getActionByTag(arg0); jsval jsret = JSVAL_NULL; @@ -3894,7 +3968,7 @@ bool js_cocos2dx_Node_getActionByTag(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3903,18 +3977,18 @@ bool js_cocos2dx_Node_getActionByTag(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setRotationSkewX(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setRotationSkewX : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setRotationSkewX : Error processing arguments"); cobj->setRotationSkewX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3923,18 +3997,18 @@ bool js_cocos2dx_Node_setRotationSkewX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setRotationSkewY(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setRotationSkewY : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setRotationSkewY : Error processing arguments"); cobj->setRotationSkewY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3943,70 +4017,54 @@ bool js_cocos2dx_Node_setRotationSkewY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setName : Error processing arguments"); cobj->setName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Node_setName : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_Node_setAdditionalTransform(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_Node_updatePhysicsBodyTransform(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - - JSObject *obj = NULL; - cocos2d::Node* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setAdditionalTransform : Invalid Native Object"); - do { - if (argc == 1) { - cocos2d::AffineTransform arg0; - ok &= jsval_to_ccaffinetransform(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cobj->setAdditionalTransform(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - } while(0); - - do { - if (argc == 1) { - cocos2d::Mat4* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Mat4*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cobj->setAdditionalTransform(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - } while(0); + cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_updatePhysicsBodyTransform : Invalid Native Object"); + if (argc == 4) { + cocos2d::Mat4 arg0; + unsigned int arg1; + double arg2; + double arg3; + ok &= jsval_to_matrix(cx, args.get(0), &arg0); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_updatePhysicsBodyTransform : Error processing arguments"); + cobj->updatePhysicsBodyTransform(arg0, arg1, arg2, arg3); + args.rval().setUndefined(); + return true; + } - JS_ReportError(cx, "js_cocos2dx_Node_setAdditionalTransform : wrong number of arguments"); + JS_ReportError(cx, "js_cocos2dx_Node_updatePhysicsBodyTransform : wrong number of arguments: %d, was expecting %d", argc, 4); return false; } bool js_cocos2dx_Node_getDisplayedOpacity(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getDisplayedOpacity : Invalid Native Object"); @@ -4014,7 +4072,7 @@ bool js_cocos2dx_Node_getDisplayedOpacity(JSContext *cx, uint32_t argc, jsval *v uint16_t ret = cobj->getDisplayedOpacity(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4023,7 +4081,8 @@ bool js_cocos2dx_Node_getDisplayedOpacity(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Node_getLocalZOrder(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getLocalZOrder : Invalid Native Object"); @@ -4031,7 +4090,7 @@ bool js_cocos2dx_Node_getLocalZOrder(JSContext *cx, uint32_t argc, jsval *vp) int ret = cobj->getLocalZOrder(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4040,12 +4099,12 @@ bool js_cocos2dx_Node_getLocalZOrder(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getScheduler(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Node* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getScheduler : Invalid Native Object"); @@ -4061,7 +4120,7 @@ bool js_cocos2dx_Node_getScheduler(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -4078,7 +4137,7 @@ bool js_cocos2dx_Node_getScheduler(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -4086,26 +4145,10 @@ bool js_cocos2dx_Node_getScheduler(JSContext *cx, uint32_t argc, jsval *vp) JS_ReportError(cx, "js_cocos2dx_Node_getScheduler : wrong number of arguments"); return false; } -bool js_cocos2dx_Node_getParentToNodeAffineTransform(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getParentToNodeAffineTransform : Invalid Native Object"); - if (argc == 0) { - cocos2d::AffineTransform ret = cobj->getParentToNodeAffineTransform(); - jsval jsret = JSVAL_NULL; - jsret = ccaffinetransform_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_Node_getParentToNodeAffineTransform : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_Node_getOrderOfArrival(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getOrderOfArrival : Invalid Native Object"); @@ -4113,7 +4156,7 @@ bool js_cocos2dx_Node_getOrderOfArrival(JSContext *cx, uint32_t argc, jsval *vp) int ret = cobj->getOrderOfArrival(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4122,25 +4165,25 @@ bool js_cocos2dx_Node_getOrderOfArrival(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setActionManager(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setActionManager : Invalid Native Object"); if (argc == 1) { cocos2d::ActionManager* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionManager*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setActionManager : Error processing arguments"); cobj->setActionManager(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4149,12 +4192,12 @@ bool js_cocos2dx_Node_setActionManager(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getPosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Node* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getPosition : Invalid Native Object"); @@ -4169,7 +4212,7 @@ bool js_cocos2dx_Node_getPosition(JSContext *cx, uint32_t argc, jsval *vp) ok = false; if (!ok) { ok = true; break; } cobj->getPosition(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -4179,7 +4222,7 @@ bool js_cocos2dx_Node_getPosition(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Vec2& ret = cobj->getPosition(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -4189,7 +4232,8 @@ bool js_cocos2dx_Node_getPosition(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_isRunning(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_isRunning : Invalid Native Object"); @@ -4197,7 +4241,7 @@ bool js_cocos2dx_Node_isRunning(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isRunning(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4206,12 +4250,12 @@ bool js_cocos2dx_Node_isRunning(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getParent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Node* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getParent : Invalid Native Object"); @@ -4227,7 +4271,7 @@ bool js_cocos2dx_Node_getParent(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -4244,7 +4288,7 @@ bool js_cocos2dx_Node_getParent(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -4252,9 +4296,28 @@ bool js_cocos2dx_Node_getParent(JSContext *cx, uint32_t argc, jsval *vp) JS_ReportError(cx, "js_cocos2dx_Node_getParent : wrong number of arguments"); return false; } +bool js_cocos2dx_Node_getWorldToNodeTransform(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getWorldToNodeTransform : Invalid Native Object"); + if (argc == 0) { + cocos2d::Mat4 ret = cobj->getWorldToNodeTransform(); + jsval jsret = JSVAL_NULL; + jsret = matrix_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Node_getWorldToNodeTransform : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_Node_getPositionY(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getPositionY : Invalid Native Object"); @@ -4262,7 +4325,7 @@ bool js_cocos2dx_Node_getPositionY(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getPositionY(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4271,7 +4334,8 @@ bool js_cocos2dx_Node_getPositionY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getPositionX(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getPositionX : Invalid Native Object"); @@ -4279,7 +4343,7 @@ bool js_cocos2dx_Node_getPositionX(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getPositionX(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4288,28 +4352,28 @@ bool js_cocos2dx_Node_getPositionX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_removeChildByTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_removeChildByTag : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_removeChildByTag : Error processing arguments"); cobj->removeChildByTag(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { int arg0; bool arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_removeChildByTag : Error processing arguments"); cobj->removeChildByTag(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4318,18 +4382,18 @@ bool js_cocos2dx_Node_removeChildByTag(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setPositionY(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setPositionY : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setPositionY : Error processing arguments"); cobj->setPositionY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4338,18 +4402,18 @@ bool js_cocos2dx_Node_setPositionY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_updateDisplayedColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_updateDisplayedColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_updateDisplayedColor : Error processing arguments"); cobj->updateDisplayedColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4358,44 +4422,46 @@ bool js_cocos2dx_Node_updateDisplayedColor(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Node_setVisible(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setVisible : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setVisible : Error processing arguments"); cobj->setVisible(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Node_setVisible : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_Node_getParentToNodeTransform(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_Node_getParentToNodeAffineTransform(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getParentToNodeTransform : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getParentToNodeAffineTransform : Invalid Native Object"); if (argc == 0) { - const cocos2d::Mat4& ret = cobj->getParentToNodeTransform(); + cocos2d::AffineTransform ret = cobj->getParentToNodeAffineTransform(); jsval jsret = JSVAL_NULL; - jsret = matrix_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = ccaffinetransform_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_Node_getParentToNodeTransform : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_Node_getParentToNodeAffineTransform : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } bool js_cocos2dx_Node_getPositionZ(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getPositionZ : Invalid Native Object"); @@ -4403,7 +4469,7 @@ bool js_cocos2dx_Node_getPositionZ(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getPositionZ(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4412,18 +4478,18 @@ bool js_cocos2dx_Node_getPositionZ(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setGlobalZOrder(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setGlobalZOrder : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setGlobalZOrder : Error processing arguments"); cobj->setGlobalZOrder(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4432,25 +4498,25 @@ bool js_cocos2dx_Node_setGlobalZOrder(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setScale(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Node* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setScale : Invalid Native Object"); do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } cobj->setScale(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -4458,10 +4524,10 @@ bool js_cocos2dx_Node_setScale(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cobj->setScale(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -4471,7 +4537,8 @@ bool js_cocos2dx_Node_setScale(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getOnExitCallback(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getOnExitCallback : Invalid Native Object"); @@ -4479,7 +4546,7 @@ bool js_cocos2dx_Node_getOnExitCallback(JSContext *cx, uint32_t argc, jsval *vp) const std::function& ret = cobj->getOnExitCallback(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR std::function; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4488,15 +4555,15 @@ bool js_cocos2dx_Node_getOnExitCallback(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getChildByTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getChildByTag : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_getChildByTag : Error processing arguments"); cocos2d::Node* ret = cobj->getChildByTag(arg0); jsval jsret = JSVAL_NULL; @@ -4508,7 +4575,7 @@ bool js_cocos2dx_Node_getChildByTag(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4517,18 +4584,18 @@ bool js_cocos2dx_Node_getChildByTag(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setOrderOfArrival(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setOrderOfArrival : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setOrderOfArrival : Error processing arguments"); cobj->setOrderOfArrival(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4537,7 +4604,8 @@ bool js_cocos2dx_Node_setOrderOfArrival(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getScaleZ(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getScaleZ : Invalid Native Object"); @@ -4545,7 +4613,7 @@ bool js_cocos2dx_Node_getScaleZ(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getScaleZ(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4554,7 +4622,8 @@ bool js_cocos2dx_Node_getScaleZ(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getScaleY(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getScaleY : Invalid Native Object"); @@ -4562,7 +4631,7 @@ bool js_cocos2dx_Node_getScaleY(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getScaleY(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4571,7 +4640,8 @@ bool js_cocos2dx_Node_getScaleY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getScaleX(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getScaleX : Invalid Native Object"); @@ -4579,7 +4649,7 @@ bool js_cocos2dx_Node_getScaleX(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getScaleX(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4588,55 +4658,38 @@ bool js_cocos2dx_Node_getScaleX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setLocalZOrder(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setLocalZOrder : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setLocalZOrder : Error processing arguments"); cobj->setLocalZOrder(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Node_setLocalZOrder : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_Node_getWorldToNodeAffineTransform(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getWorldToNodeAffineTransform : Invalid Native Object"); - if (argc == 0) { - cocos2d::AffineTransform ret = cobj->getWorldToNodeAffineTransform(); - jsval jsret = JSVAL_NULL; - jsret = ccaffinetransform_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_Node_getWorldToNodeAffineTransform : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_Node_setCascadeColorEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setCascadeColorEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setCascadeColorEnabled : Error processing arguments"); cobj->setCascadeColorEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4645,18 +4698,18 @@ bool js_cocos2dx_Node_setCascadeColorEnabled(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Node_setOpacity(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setOpacity : Invalid Native Object"); if (argc == 1) { uint16_t arg0; - ok &= jsval_to_uint16(cx, argv[0], &arg0); + ok &= jsval_to_uint16(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setOpacity : Error processing arguments"); cobj->setOpacity(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4665,13 +4718,14 @@ bool js_cocos2dx_Node_setOpacity(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_cleanup(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_cleanup : Invalid Native Object"); if (argc == 0) { cobj->cleanup(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4680,15 +4734,15 @@ bool js_cocos2dx_Node_cleanup(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getComponent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getComponent : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_getComponent : Error processing arguments"); cocos2d::Component* ret = cobj->getComponent(arg0); jsval jsret = JSVAL_NULL; @@ -4700,7 +4754,7 @@ bool js_cocos2dx_Node_getComponent(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4709,7 +4763,8 @@ bool js_cocos2dx_Node_getComponent(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getContentSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getContentSize : Invalid Native Object"); @@ -4717,7 +4772,7 @@ bool js_cocos2dx_Node_getContentSize(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Size& ret = cobj->getContentSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4726,18 +4781,18 @@ bool js_cocos2dx_Node_getContentSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_stopAllActionsByTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_stopAllActionsByTag : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_stopAllActionsByTag : Error processing arguments"); cobj->stopAllActionsByTag(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4746,7 +4801,8 @@ bool js_cocos2dx_Node_stopAllActionsByTag(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Node_getBoundingBox(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getBoundingBox : Invalid Native Object"); @@ -4754,7 +4810,7 @@ bool js_cocos2dx_Node_getBoundingBox(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Rect ret = cobj->getBoundingBox(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4763,25 +4819,25 @@ bool js_cocos2dx_Node_getBoundingBox(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setEventDispatcher(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setEventDispatcher : Invalid Native Object"); if (argc == 1) { cocos2d::EventDispatcher* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::EventDispatcher*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setEventDispatcher : Error processing arguments"); cobj->setEventDispatcher(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4790,7 +4846,8 @@ bool js_cocos2dx_Node_setEventDispatcher(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Node_getGlobalZOrder(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getGlobalZOrder : Invalid Native Object"); @@ -4798,7 +4855,7 @@ bool js_cocos2dx_Node_getGlobalZOrder(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getGlobalZOrder(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4807,19 +4864,19 @@ bool js_cocos2dx_Node_getGlobalZOrder(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_draw(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Node* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_draw : Invalid Native Object"); do { if (argc == 0) { cobj->draw(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -4828,22 +4885,22 @@ bool js_cocos2dx_Node_draw(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 3) { cocos2d::Renderer* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Renderer*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::Mat4 arg1; - ok &= jsval_to_matrix(cx, argv[1], &arg1); + ok &= jsval_to_matrix(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } unsigned int arg2; - ok &= jsval_to_uint32(cx, argv[2], &arg2); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } cobj->draw(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -4853,25 +4910,25 @@ bool js_cocos2dx_Node_draw(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_setUserObject(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setUserObject : Invalid Native Object"); if (argc == 1) { cocos2d::Ref* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Ref*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setUserObject : Error processing arguments"); cobj->setUserObject(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4880,21 +4937,22 @@ bool js_cocos2dx_Node_setUserObject(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_enumerateChildren(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_enumerateChildren : Invalid Native Object"); if (argc == 2) { std::string arg0; std::function arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](cocos2d::Node* larg0) -> bool { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -4904,13 +4962,13 @@ bool js_cocos2dx_Node_enumerateChildren(JSContext *cx, uint32_t argc, jsval *vp) largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } bool ret; - ret = JS::ToBoolean(JS::RootedValue(cx, rval)); + ret = JS::ToBoolean(rval); return ret; }; arg1 = lambda; @@ -4923,7 +4981,7 @@ bool js_cocos2dx_Node_enumerateChildren(JSContext *cx, uint32_t argc, jsval *vp) ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_enumerateChildren : Error processing arguments"); cobj->enumerateChildren(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4932,7 +4990,8 @@ bool js_cocos2dx_Node_enumerateChildren(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getonExitTransitionDidStartCallback(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getonExitTransitionDidStartCallback : Invalid Native Object"); @@ -4940,7 +4999,7 @@ bool js_cocos2dx_Node_getonExitTransitionDidStartCallback(JSContext *cx, uint32_ const std::function& ret = cobj->getonExitTransitionDidStartCallback(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR std::function; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4949,21 +5008,21 @@ bool js_cocos2dx_Node_getonExitTransitionDidStartCallback(JSContext *cx, uint32_ } bool js_cocos2dx_Node_removeFromParentAndCleanup(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Node* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_removeFromParentAndCleanup : Invalid Native Object"); do { if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); cobj->removeFromParentAndCleanup(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -4971,7 +5030,7 @@ bool js_cocos2dx_Node_removeFromParentAndCleanup(JSContext *cx, uint32_t argc, j do { if (argc == 0) { cobj->removeFromParent(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -4981,18 +5040,18 @@ bool js_cocos2dx_Node_removeFromParentAndCleanup(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_Node_setPosition3D(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setPosition3D : Invalid Native Object"); if (argc == 1) { cocos2d::Vec3 arg0; - ok &= jsval_to_vector3(cx, argv[0], &arg0); + ok &= jsval_to_vector3(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setPosition3D : Error processing arguments"); cobj->setPosition3D(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5001,18 +5060,18 @@ bool js_cocos2dx_Node_setPosition3D(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_update(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_update : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_update : Error processing arguments"); cobj->update(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5021,39 +5080,42 @@ bool js_cocos2dx_Node_update(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_sortAllChildren(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_sortAllChildren : Invalid Native Object"); if (argc == 0) { cobj->sortAllChildren(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Node_sortAllChildren : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_Node_getWorldToNodeTransform(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_Node_getWorldToNodeAffineTransform(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getWorldToNodeTransform : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getWorldToNodeAffineTransform : Invalid Native Object"); if (argc == 0) { - cocos2d::Mat4 ret = cobj->getWorldToNodeTransform(); + cocos2d::AffineTransform ret = cobj->getWorldToNodeAffineTransform(); jsval jsret = JSVAL_NULL; - jsret = matrix_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = ccaffinetransform_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_Node_getWorldToNodeTransform : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_Node_getWorldToNodeAffineTransform : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } bool js_cocos2dx_Node_getScale(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getScale : Invalid Native Object"); @@ -5061,7 +5123,7 @@ bool js_cocos2dx_Node_getScale(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getScale(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5070,7 +5132,8 @@ bool js_cocos2dx_Node_getScale(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getNormalizedPosition(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getNormalizedPosition : Invalid Native Object"); @@ -5078,29 +5141,47 @@ bool js_cocos2dx_Node_getNormalizedPosition(JSContext *cx, uint32_t argc, jsval const cocos2d::Vec2& ret = cobj->getNormalizedPosition(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Node_getNormalizedPosition : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_Node_getParentToNodeTransform(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getParentToNodeTransform : Invalid Native Object"); + if (argc == 0) { + const cocos2d::Mat4& ret = cobj->getParentToNodeTransform(); + jsval jsret = JSVAL_NULL; + jsret = matrix_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Node_getParentToNodeTransform : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_Node_convertToNodeSpace(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_convertToNodeSpace : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_convertToNodeSpace : Error processing arguments"); cocos2d::Vec2 ret = cobj->convertToNodeSpace(arg0); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5109,18 +5190,18 @@ bool js_cocos2dx_Node_convertToNodeSpace(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Node_setTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setTag : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setTag : Error processing arguments"); cobj->setTag(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5129,7 +5210,8 @@ bool js_cocos2dx_Node_setTag(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_isCascadeColorEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_isCascadeColorEnabled : Invalid Native Object"); @@ -5137,51 +5219,54 @@ bool js_cocos2dx_Node_isCascadeColorEnabled(JSContext *cx, uint32_t argc, jsval bool ret = cobj->isCascadeColorEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Node_isCascadeColorEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_Node_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_Node_setRotationQuat(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_isOpacityModifyRGB : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->isOpacityModifyRGB(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setRotationQuat : Invalid Native Object"); + if (argc == 1) { + cocos2d::Quaternion arg0; + ok &= jsval_to_quaternion(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setRotationQuat : Error processing arguments"); + cobj->setRotationQuat(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_Node_isOpacityModifyRGB : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_Node_setRotationQuat : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_Node_stopAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_stopAction : Invalid Native Object"); if (argc == 1) { cocos2d::Action* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Action*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_stopAction : Error processing arguments"); cobj->stopAction(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5190,12 +5275,12 @@ bool js_cocos2dx_Node_stopAction(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_getActionManager(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Node* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_getActionManager : Invalid Native Object"); @@ -5211,7 +5296,7 @@ bool js_cocos2dx_Node_getActionManager(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -5228,7 +5313,7 @@ bool js_cocos2dx_Node_getActionManager(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -5238,6 +5323,7 @@ bool js_cocos2dx_Node_getActionManager(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Node* ret = cocos2d::Node::create(); jsval jsret = JSVAL_NULL; @@ -5249,7 +5335,7 @@ bool js_cocos2dx_Node_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Node_create : wrong number of arguments"); @@ -5258,7 +5344,7 @@ bool js_cocos2dx_Node_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Node_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Node* cobj = new (std::nothrow) cocos2d::Node(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -5272,13 +5358,16 @@ bool js_cocos2dx_Node_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Node"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Node"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -5290,21 +5379,21 @@ void js_cocos2d_Node_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_Node_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::Node *nobj = new (std::nothrow) cocos2d::Node(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Node"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Node"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_Node(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Node(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Node_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Node_class->name = "Node"; jsb_cocos2d_Node_class->addProperty = JS_PropertyStub; @@ -5318,8 +5407,8 @@ void js_register_cocos2dx_Node(JSContext *cx, JSObject *global) { jsb_cocos2d_Node_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -5327,6 +5416,7 @@ void js_register_cocos2dx_Node(JSContext *cx, JSObject *global) { JS_FN("removeComponent", js_cocos2dx_Node_removeComponent, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setPhysicsBody", js_cocos2dx_Node_setPhysicsBody, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getShaderProgram", js_cocos2dx_Node_getGLProgram, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("updateTransformFromPhysics", js_cocos2dx_Node_updateTransformFromPhysics, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getDescription", js_cocos2dx_Node_getDescription, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setOpacityModifyRGB", js_cocos2dx_Node_setOpacityModifyRGB, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setCascadeOpacityEnabled", js_cocos2dx_Node_setCascadeOpacityEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -5350,8 +5440,8 @@ void js_register_cocos2dx_Node(JSContext *cx, JSObject *global) { JS_FN("setCameraMask", js_cocos2dx_Node_setCameraMask, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getTag", js_cocos2dx_Node_getTag, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getonEnterTransitionDidFinishCallback", js_cocos2dx_Node_getonEnterTransitionDidFinishCallback, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getNodeToWorldAffineTransform", js_cocos2dx_Node_getNodeToWorldAffineTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getNodeToWorldTransform", js_cocos2dx_Node_getNodeToWorldTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isOpacityModifyRGB", js_cocos2dx_Node_isOpacityModifyRGB, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getNodeToWorldTransform", js_cocos2dx_Node_getNodeToWorldAffineTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getPosition3D", js_cocos2dx_Node_getPosition3D, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("removeChild", js_cocos2dx_Node_removeChild, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("convertToWorldSpace", js_cocos2dx_Node_convertToWorldSpace, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -5366,12 +5456,12 @@ void js_register_cocos2dx_Node(JSContext *cx, JSObject *global) { JS_FN("removeAllChildren", js_cocos2dx_Node_removeAllChildrenWithCleanup, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getRotationX", js_cocos2dx_Node_getRotationSkewX, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getRotationY", js_cocos2dx_Node_getRotationSkewY, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getNodeToParentAffineTransform", js_cocos2dx_Node_getNodeToParentAffineTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getNodeToWorldTransform3D", js_cocos2dx_Node_getNodeToWorldTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isCascadeOpacityEnabled", js_cocos2dx_Node_isCascadeOpacityEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setParent", js_cocos2dx_Node_setParent, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getName", js_cocos2dx_Node_getName, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getRotation3D", js_cocos2dx_Node_getRotation3D, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getNodeToParentTransform", js_cocos2dx_Node_getNodeToParentTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getNodeToParentTransform", js_cocos2dx_Node_getNodeToParentAffineTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("convertTouchToNodeSpaceAR", js_cocos2dx_Node_convertTouchToNodeSpaceAR, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getOnEnterCallback", js_cocos2dx_Node_getOnEnterCallback, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getPhysicsBody", js_cocos2dx_Node_getPhysicsBody, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -5387,13 +5477,15 @@ void js_register_cocos2dx_Node(JSContext *cx, JSObject *global) { JS_FN("updateTransform", js_cocos2dx_Node_updateTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isVisible", js_cocos2dx_Node_isVisible, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getChildrenCount", js_cocos2dx_Node_getChildrenCount, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getNodeToParentTransform3D", js_cocos2dx_Node_getNodeToParentTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("convertToNodeSpaceAR", js_cocos2dx_Node_convertToNodeSpaceAR, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("addComponent", js_cocos2dx_Node_addComponent, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("runAction", js_cocos2dx_Node_runAction, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("visit", js_cocos2dx_Node_visit, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setShaderProgram", js_cocos2dx_Node_setGLProgram, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getRotation", js_cocos2dx_Node_getRotation, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getAnchorPointInPoints", js_cocos2dx_Node_getAnchorPointInPoints, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("visit", js_cocos2dx_Node_visit, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getRotationQuat", js_cocos2dx_Node_getRotationQuat, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("removeChildByName", js_cocos2dx_Node_removeChildByName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setVertexZ", js_cocos2dx_Node_setPositionZ, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getGLProgramState", js_cocos2dx_Node_getGLProgramState, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -5407,23 +5499,23 @@ void js_register_cocos2dx_Node(JSContext *cx, JSObject *global) { JS_FN("setRotationX", js_cocos2dx_Node_setRotationSkewX, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRotationY", js_cocos2dx_Node_setRotationSkewY, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setName", js_cocos2dx_Node_setName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setAdditionalTransform", js_cocos2dx_Node_setAdditionalTransform, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("updatePhysicsBodyTransform", js_cocos2dx_Node_updatePhysicsBodyTransform, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getDisplayedOpacity", js_cocos2dx_Node_getDisplayedOpacity, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getLocalZOrder", js_cocos2dx_Node_getLocalZOrder, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getScheduler", js_cocos2dx_Node_getScheduler, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getParentToNodeAffineTransform", js_cocos2dx_Node_getParentToNodeAffineTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getOrderOfArrival", js_cocos2dx_Node_getOrderOfArrival, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setActionManager", js_cocos2dx_Node_setActionManager, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getPosition", js_cocos2dx_Node_getPosition, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isRunning", js_cocos2dx_Node_isRunning, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getParent", js_cocos2dx_Node_getParent, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getWorldToNodeTransform3D", js_cocos2dx_Node_getWorldToNodeTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getPositionY", js_cocos2dx_Node_getPositionY, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getPositionX", js_cocos2dx_Node_getPositionX, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("removeChildByTag", js_cocos2dx_Node_removeChildByTag, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setPositionY", js_cocos2dx_Node_setPositionY, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("updateDisplayedColor", js_cocos2dx_Node_updateDisplayedColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setVisible", js_cocos2dx_Node_setVisible, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getParentToNodeTransform", js_cocos2dx_Node_getParentToNodeTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getParentToNodeTransform", js_cocos2dx_Node_getParentToNodeAffineTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getVertexZ", js_cocos2dx_Node_getPositionZ, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setGlobalZOrder", js_cocos2dx_Node_setGlobalZOrder, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setScale", js_cocos2dx_Node_setScale, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -5434,7 +5526,6 @@ void js_register_cocos2dx_Node(JSContext *cx, JSObject *global) { JS_FN("getScaleY", js_cocos2dx_Node_getScaleY, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getScaleX", js_cocos2dx_Node_getScaleX, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setLocalZOrder", js_cocos2dx_Node_setLocalZOrder, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getWorldToNodeAffineTransform", js_cocos2dx_Node_getWorldToNodeAffineTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setCascadeColorEnabled", js_cocos2dx_Node_setCascadeColorEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setOpacity", js_cocos2dx_Node_setOpacity, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("cleanup", js_cocos2dx_Node_cleanup, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -5452,13 +5543,14 @@ void js_register_cocos2dx_Node(JSContext *cx, JSObject *global) { JS_FN("setPosition3D", js_cocos2dx_Node_setPosition3D, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("update", js_cocos2dx_Node_update, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("sortAllChildren", js_cocos2dx_Node_sortAllChildren, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getWorldToNodeTransform", js_cocos2dx_Node_getWorldToNodeTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getWorldToNodeTransform", js_cocos2dx_Node_getWorldToNodeAffineTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getScale", js_cocos2dx_Node_getScale, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getNormalizedPosition", js_cocos2dx_Node_getNormalizedPosition, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getParentToNodeTransform3D", js_cocos2dx_Node_getParentToNodeTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("convertToNodeSpace", js_cocos2dx_Node_convertToNodeSpace, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setTag", js_cocos2dx_Node_setTag, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isCascadeColorEnabled", js_cocos2dx_Node_isCascadeColorEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("isOpacityModifyRGB", js_cocos2dx_Node_isOpacityModifyRGB, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setRotationQuat", js_cocos2dx_Node_setRotationQuat, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("stopAction", js_cocos2dx_Node_stopAction, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getActionManager", js_cocos2dx_Node_getActionManager, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2d_Node_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -5472,7 +5564,7 @@ void js_register_cocos2dx_Node(JSContext *cx, JSObject *global) { jsb_cocos2d_Node_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_Node_class, js_cocos2dx_Node_constructor, 0, // constructor properties, @@ -5503,7 +5595,7 @@ JSObject *jsb_cocos2d___NodeRGBA_prototype; bool js_cocos2dx___NodeRGBA_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::__NodeRGBA* cobj = new (std::nothrow) cocos2d::__NodeRGBA(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -5517,13 +5609,16 @@ bool js_cocos2dx___NodeRGBA_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::__NodeRGBA"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::__NodeRGBA"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -5536,21 +5631,21 @@ void js_cocos2d___NodeRGBA_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d___NodeRGBA_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::__NodeRGBA *nobj = new (std::nothrow) cocos2d::__NodeRGBA(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::__NodeRGBA"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::__NodeRGBA"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx___NodeRGBA(JSContext *cx, JSObject *global) { +void js_register_cocos2dx___NodeRGBA(JSContext *cx, JS::HandleObject global) { jsb_cocos2d___NodeRGBA_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d___NodeRGBA_class->name = "NodeRGBA"; jsb_cocos2d___NodeRGBA_class->addProperty = JS_PropertyStub; @@ -5564,8 +5659,8 @@ void js_register_cocos2dx___NodeRGBA(JSContext *cx, JSObject *global) { jsb_cocos2d___NodeRGBA_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -5577,7 +5672,7 @@ void js_register_cocos2dx___NodeRGBA(JSContext *cx, JSObject *global) { jsb_cocos2d___NodeRGBA_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d___NodeRGBA_class, js_cocos2dx___NodeRGBA_constructor, 0, // constructor properties, @@ -5608,7 +5703,8 @@ JSObject *jsb_cocos2d_Scene_prototype; bool js_cocos2dx_Scene_initWithPhysics(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scene* cobj = (cocos2d::Scene *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Scene_initWithPhysics : Invalid Native Object"); @@ -5616,34 +5712,50 @@ bool js_cocos2dx_Scene_initWithPhysics(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->initWithPhysics(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Scene_initWithPhysics : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_Scene_setCameraOrderDirty(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Scene* cobj = (cocos2d::Scene *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Scene_setCameraOrderDirty : Invalid Native Object"); + if (argc == 0) { + cobj->setCameraOrderDirty(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Scene_setCameraOrderDirty : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_Scene_render(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scene* cobj = (cocos2d::Scene *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Scene_render : Invalid Native Object"); if (argc == 1) { cocos2d::Renderer* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Renderer*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Scene_render : Error processing arguments"); cobj->render(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5652,51 +5764,35 @@ bool js_cocos2dx_Scene_render(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Scene_onProjectionChanged(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scene* cobj = (cocos2d::Scene *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Scene_onProjectionChanged : Invalid Native Object"); if (argc == 1) { cocos2d::EventCustom* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::EventCustom*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Scene_onProjectionChanged : Error processing arguments"); cobj->onProjectionChanged(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Scene_onProjectionChanged : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_Scene_init(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::Scene* cobj = (cocos2d::Scene *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Scene_init : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->init(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_Scene_init : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_Scene_getPhysicsWorld(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scene* cobj = (cocos2d::Scene *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Scene_getPhysicsWorld : Invalid Native Object"); @@ -5711,7 +5807,7 @@ bool js_cocos2dx_Scene_getPhysicsWorld(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5720,33 +5816,58 @@ bool js_cocos2dx_Scene_getPhysicsWorld(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Scene_initWithSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scene* cobj = (cocos2d::Scene *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Scene_initWithSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Scene_initWithSize : Error processing arguments"); bool ret = cobj->initWithSize(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Scene_initWithSize : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_Scene_getDefaultCamera(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Scene* cobj = (cocos2d::Scene *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Scene_getDefaultCamera : Invalid Native Object"); + if (argc == 0) { + cocos2d::Camera* ret = cobj->getDefaultCamera(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Camera*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Scene_getDefaultCamera : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_Scene_createWithSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Scene_createWithSize : Error processing arguments"); cocos2d::Scene* ret = cocos2d::Scene::createWithSize(arg0); jsval jsret = JSVAL_NULL; @@ -5758,7 +5879,7 @@ bool js_cocos2dx_Scene_createWithSize(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Scene_createWithSize : wrong number of arguments"); @@ -5767,6 +5888,7 @@ bool js_cocos2dx_Scene_createWithSize(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Scene_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Scene* ret = cocos2d::Scene::create(); jsval jsret = JSVAL_NULL; @@ -5778,7 +5900,7 @@ bool js_cocos2dx_Scene_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Scene_create : wrong number of arguments"); @@ -5787,6 +5909,7 @@ bool js_cocos2dx_Scene_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Scene_createWithPhysics(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Scene* ret = cocos2d::Scene::createWithPhysics(); jsval jsret = JSVAL_NULL; @@ -5798,7 +5921,7 @@ bool js_cocos2dx_Scene_createWithPhysics(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Scene_createWithPhysics : wrong number of arguments"); @@ -5807,7 +5930,7 @@ bool js_cocos2dx_Scene_createWithPhysics(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_Scene_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Scene* cobj = new (std::nothrow) cocos2d::Scene(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -5821,13 +5944,16 @@ bool js_cocos2dx_Scene_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Scene"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Scene"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -5840,21 +5966,21 @@ void js_cocos2d_Scene_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_Scene_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::Scene *nobj = new (std::nothrow) cocos2d::Scene(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Scene"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Scene"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_Scene(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Scene(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Scene_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Scene_class->name = "Scene"; jsb_cocos2d_Scene_class->addProperty = JS_PropertyStub; @@ -5868,17 +5994,18 @@ void js_register_cocos2dx_Scene(JSContext *cx, JSObject *global) { jsb_cocos2d_Scene_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("initWithPhysics", js_cocos2dx_Scene_initWithPhysics, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setCameraOrderDirty", js_cocos2dx_Scene_setCameraOrderDirty, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("render", js_cocos2dx_Scene_render, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("onProjectionChanged", js_cocos2dx_Scene_onProjectionChanged, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_Scene_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getPhysicsWorld", js_cocos2dx_Scene_getPhysicsWorld, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("initWithSize", js_cocos2dx_Scene_initWithSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDefaultCamera", js_cocos2dx_Scene_getDefaultCamera, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2d_Scene_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -5892,7 +6019,7 @@ void js_register_cocos2dx_Scene(JSContext *cx, JSObject *global) { jsb_cocos2d_Scene_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_Scene_class, js_cocos2dx_Scene_constructor, 0, // constructor properties, @@ -5923,20 +6050,20 @@ JSObject *jsb_cocos2d_GLView_prototype; bool js_cocos2dx_GLView_setFrameSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_setFrameSize : Invalid Native Object"); if (argc == 2) { double arg0; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLView_setFrameSize : Error processing arguments"); cobj->setFrameSize(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5945,7 +6072,8 @@ bool js_cocos2dx_GLView_setFrameSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLView_getViewPortRect(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_getViewPortRect : Invalid Native Object"); @@ -5953,7 +6081,7 @@ bool js_cocos2dx_GLView_getViewPortRect(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Rect& ret = cobj->getViewPortRect(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5962,20 +6090,20 @@ bool js_cocos2dx_GLView_getViewPortRect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLView_setContentScaleFactor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_setContentScaleFactor : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLView_setContentScaleFactor : Error processing arguments"); bool ret = cobj->setContentScaleFactor(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5984,7 +6112,8 @@ bool js_cocos2dx_GLView_setContentScaleFactor(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_GLView_getContentScaleFactor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_getContentScaleFactor : Invalid Native Object"); @@ -5992,7 +6121,7 @@ bool js_cocos2dx_GLView_getContentScaleFactor(JSContext *cx, uint32_t argc, jsva double ret = cobj->getContentScaleFactor(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6001,18 +6130,18 @@ bool js_cocos2dx_GLView_getContentScaleFactor(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_GLView_setIMEKeyboardState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_setIMEKeyboardState : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLView_setIMEKeyboardState : Error processing arguments"); cobj->setIMEKeyboardState(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6021,9 +6150,9 @@ bool js_cocos2dx_GLView_setIMEKeyboardState(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_GLView_setScissorInPoints(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_setScissorInPoints : Invalid Native Object"); @@ -6032,13 +6161,13 @@ bool js_cocos2dx_GLView_setScissorInPoints(JSContext *cx, uint32_t argc, jsval * double arg1; double arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLView_setScissorInPoints : Error processing arguments"); cobj->setScissorInPoints(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6047,7 +6176,8 @@ bool js_cocos2dx_GLView_setScissorInPoints(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_GLView_getViewName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_getViewName : Invalid Native Object"); @@ -6055,7 +6185,7 @@ bool js_cocos2dx_GLView_getViewName(JSContext *cx, uint32_t argc, jsval *vp) const std::string& ret = cobj->getViewName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6064,7 +6194,8 @@ bool js_cocos2dx_GLView_getViewName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLView_isOpenGLReady(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_isOpenGLReady : Invalid Native Object"); @@ -6072,16 +6203,37 @@ bool js_cocos2dx_GLView_isOpenGLReady(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isOpenGLReady(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_GLView_isOpenGLReady : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_GLView_setCursorVisible(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_setCursorVisible : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLView_setCursorVisible : Error processing arguments"); + cobj->setCursorVisible(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_GLView_setCursorVisible : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_GLView_getScaleY(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_getScaleY : Invalid Native Object"); @@ -6089,7 +6241,7 @@ bool js_cocos2dx_GLView_getScaleY(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getScaleY(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6098,7 +6250,8 @@ bool js_cocos2dx_GLView_getScaleY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLView_getScaleX(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_getScaleX : Invalid Native Object"); @@ -6106,7 +6259,7 @@ bool js_cocos2dx_GLView_getScaleX(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getScaleX(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6115,7 +6268,8 @@ bool js_cocos2dx_GLView_getScaleX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLView_getVisibleOrigin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_getVisibleOrigin : Invalid Native Object"); @@ -6123,7 +6277,7 @@ bool js_cocos2dx_GLView_getVisibleOrigin(JSContext *cx, uint32_t argc, jsval *vp cocos2d::Vec2 ret = cobj->getVisibleOrigin(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6132,7 +6286,8 @@ bool js_cocos2dx_GLView_getVisibleOrigin(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_GLView_getFrameSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_getFrameSize : Invalid Native Object"); @@ -6140,7 +6295,7 @@ bool js_cocos2dx_GLView_getFrameSize(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Size& ret = cobj->getFrameSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6149,18 +6304,18 @@ bool js_cocos2dx_GLView_getFrameSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLView_setFrameZoomFactor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_setFrameZoomFactor : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLView_setFrameZoomFactor : Error processing arguments"); cobj->setFrameZoomFactor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6169,7 +6324,8 @@ bool js_cocos2dx_GLView_setFrameZoomFactor(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_GLView_getFrameZoomFactor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_getFrameZoomFactor : Invalid Native Object"); @@ -6177,7 +6333,7 @@ bool js_cocos2dx_GLView_getFrameZoomFactor(JSContext *cx, uint32_t argc, jsval * double ret = cobj->getFrameZoomFactor(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6186,7 +6342,8 @@ bool js_cocos2dx_GLView_getFrameZoomFactor(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_GLView_getDesignResolutionSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_getDesignResolutionSize : Invalid Native Object"); @@ -6194,7 +6351,7 @@ bool js_cocos2dx_GLView_getDesignResolutionSize(JSContext *cx, uint32_t argc, js const cocos2d::Size& ret = cobj->getDesignResolutionSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6203,7 +6360,8 @@ bool js_cocos2dx_GLView_getDesignResolutionSize(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_GLView_windowShouldClose(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_windowShouldClose : Invalid Native Object"); @@ -6211,7 +6369,7 @@ bool js_cocos2dx_GLView_windowShouldClose(JSContext *cx, uint32_t argc, jsval *v bool ret = cobj->windowShouldClose(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6220,9 +6378,9 @@ bool js_cocos2dx_GLView_windowShouldClose(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_GLView_setDesignResolutionSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_setDesignResolutionSize : Invalid Native Object"); @@ -6230,12 +6388,12 @@ bool js_cocos2dx_GLView_setDesignResolutionSize(JSContext *cx, uint32_t argc, js double arg0; double arg1; ResolutionPolicy arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLView_setDesignResolutionSize : Error processing arguments"); cobj->setDesignResolutionSize(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6244,7 +6402,8 @@ bool js_cocos2dx_GLView_setDesignResolutionSize(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_GLView_getResolutionPolicy(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_getResolutionPolicy : Invalid Native Object"); @@ -6252,7 +6411,7 @@ bool js_cocos2dx_GLView_getResolutionPolicy(JSContext *cx, uint32_t argc, jsval int ret = (int)cobj->getResolutionPolicy(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6261,7 +6420,8 @@ bool js_cocos2dx_GLView_getResolutionPolicy(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_GLView_isRetinaDisplay(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_isRetinaDisplay : Invalid Native Object"); @@ -6269,7 +6429,7 @@ bool js_cocos2dx_GLView_isRetinaDisplay(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isRetinaDisplay(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6278,9 +6438,9 @@ bool js_cocos2dx_GLView_isRetinaDisplay(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLView_setViewPortInPoints(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_setViewPortInPoints : Invalid Native Object"); @@ -6289,13 +6449,13 @@ bool js_cocos2dx_GLView_setViewPortInPoints(JSContext *cx, uint32_t argc, jsval double arg1; double arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLView_setViewPortInPoints : Error processing arguments"); cobj->setViewPortInPoints(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6304,7 +6464,8 @@ bool js_cocos2dx_GLView_setViewPortInPoints(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_GLView_getScissorRect(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_getScissorRect : Invalid Native Object"); @@ -6312,7 +6473,7 @@ bool js_cocos2dx_GLView_getScissorRect(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Rect ret = cobj->getScissorRect(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6321,7 +6482,8 @@ bool js_cocos2dx_GLView_getScissorRect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLView_getRetinaFactor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_getRetinaFactor : Invalid Native Object"); @@ -6329,7 +6491,7 @@ bool js_cocos2dx_GLView_getRetinaFactor(JSContext *cx, uint32_t argc, jsval *vp) int ret = cobj->getRetinaFactor(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6338,18 +6500,18 @@ bool js_cocos2dx_GLView_getRetinaFactor(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLView_setViewName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_setViewName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLView_setViewName : Error processing arguments"); cobj->setViewName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6358,7 +6520,8 @@ bool js_cocos2dx_GLView_setViewName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLView_getVisibleRect(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_getVisibleRect : Invalid Native Object"); @@ -6366,7 +6529,7 @@ bool js_cocos2dx_GLView_getVisibleRect(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Rect ret = cobj->getVisibleRect(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6375,7 +6538,8 @@ bool js_cocos2dx_GLView_getVisibleRect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLView_getVisibleSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_getVisibleSize : Invalid Native Object"); @@ -6383,7 +6547,7 @@ bool js_cocos2dx_GLView_getVisibleSize(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Size ret = cobj->getVisibleSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6392,7 +6556,8 @@ bool js_cocos2dx_GLView_getVisibleSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLView_isScissorEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_isScissorEnabled : Invalid Native Object"); @@ -6400,7 +6565,7 @@ bool js_cocos2dx_GLView_isScissorEnabled(JSContext *cx, uint32_t argc, jsval *vp bool ret = cobj->isScissorEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6409,13 +6574,14 @@ bool js_cocos2dx_GLView_isScissorEnabled(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_GLView_pollEvents(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLView* cobj = (cocos2d::GLView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLView_pollEvents : Invalid Native Object"); if (argc == 0) { cobj->pollEvents(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6424,7 +6590,7 @@ bool js_cocos2dx_GLView_pollEvents(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLView_setGLContextAttrs(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { GLContextAttrs arg0; @@ -6432,7 +6598,7 @@ bool js_cocos2dx_GLView_setGLContextAttrs(JSContext *cx, uint32_t argc, jsval *v ok = false; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLView_setGLContextAttrs : Error processing arguments"); cocos2d::GLView::setGLContextAttrs(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_GLView_setGLContextAttrs : wrong number of arguments"); @@ -6441,11 +6607,12 @@ bool js_cocos2dx_GLView_setGLContextAttrs(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_GLView_getGLContextAttrs(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { GLContextAttrs ret = cocos2d::GLView::getGLContextAttrs(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR GLContextAttrs; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_GLView_getGLContextAttrs : wrong number of arguments"); @@ -6458,7 +6625,7 @@ void js_cocos2d_GLView_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (GLView)", obj); } -void js_register_cocos2dx_GLView(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_GLView(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_GLView_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_GLView_class->name = "GLView"; jsb_cocos2d_GLView_class->addProperty = JS_PropertyStub; @@ -6472,8 +6639,8 @@ void js_register_cocos2dx_GLView(JSContext *cx, JSObject *global) { jsb_cocos2d_GLView_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -6485,6 +6652,7 @@ void js_register_cocos2dx_GLView(JSContext *cx, JSObject *global) { JS_FN("setScissorInPoints", js_cocos2dx_GLView_setScissorInPoints, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getViewName", js_cocos2dx_GLView_getViewName, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isOpenGLReady", js_cocos2dx_GLView_isOpenGLReady, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setCursorVisible", js_cocos2dx_GLView_setCursorVisible, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getScaleY", js_cocos2dx_GLView_getScaleY, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getScaleX", js_cocos2dx_GLView_getScaleX, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getVisibleOrigin", js_cocos2dx_GLView_getVisibleOrigin, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -6515,7 +6683,7 @@ void js_register_cocos2dx_GLView(JSContext *cx, JSObject *global) { jsb_cocos2d_GLView_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_GLView_class, empty_constructor, 0, properties, @@ -6546,13 +6714,14 @@ JSObject *jsb_cocos2d_Director_prototype; bool js_cocos2dx_Director_pause(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_pause : Invalid Native Object"); if (argc == 0) { cobj->pause(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6561,25 +6730,25 @@ bool js_cocos2dx_Director_pause(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_setEventDispatcher(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setEventDispatcher : Invalid Native Object"); if (argc == 1) { cocos2d::EventDispatcher* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::EventDispatcher*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_setEventDispatcher : Error processing arguments"); cobj->setEventDispatcher(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6588,18 +6757,18 @@ bool js_cocos2dx_Director_setEventDispatcher(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Director_setContentScaleFactor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setContentScaleFactor : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_setContentScaleFactor : Error processing arguments"); cobj->setContentScaleFactor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6608,7 +6777,8 @@ bool js_cocos2dx_Director_setContentScaleFactor(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_Director_getContentScaleFactor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getContentScaleFactor : Invalid Native Object"); @@ -6616,7 +6786,7 @@ bool js_cocos2dx_Director_getContentScaleFactor(JSContext *cx, uint32_t argc, js double ret = cobj->getContentScaleFactor(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6625,7 +6795,8 @@ bool js_cocos2dx_Director_getContentScaleFactor(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_Director_getWinSizeInPixels(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getWinSizeInPixels : Invalid Native Object"); @@ -6633,7 +6804,7 @@ bool js_cocos2dx_Director_getWinSizeInPixels(JSContext *cx, uint32_t argc, jsval cocos2d::Size ret = cobj->getWinSizeInPixels(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6642,7 +6813,8 @@ bool js_cocos2dx_Director_getWinSizeInPixels(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Director_getDeltaTime(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getDeltaTime : Invalid Native Object"); @@ -6650,7 +6822,7 @@ bool js_cocos2dx_Director_getDeltaTime(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getDeltaTime(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6659,13 +6831,14 @@ bool js_cocos2dx_Director_getDeltaTime(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_setGLDefaultValues(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setGLDefaultValues : Invalid Native Object"); if (argc == 0) { cobj->setGLDefaultValues(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6674,25 +6847,25 @@ bool js_cocos2dx_Director_setGLDefaultValues(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Director_setActionManager(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setActionManager : Invalid Native Object"); if (argc == 1) { cocos2d::ActionManager* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionManager*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_setActionManager : Error processing arguments"); cobj->setActionManager(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6701,18 +6874,18 @@ bool js_cocos2dx_Director_setActionManager(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Director_setAlphaBlending(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setAlphaBlending : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_setAlphaBlending : Error processing arguments"); cobj->setAlphaBlending(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6721,13 +6894,14 @@ bool js_cocos2dx_Director_setAlphaBlending(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Director_popToRootScene(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_popToRootScene : Invalid Native Object"); if (argc == 0) { cobj->popToRootScene(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6736,20 +6910,20 @@ bool js_cocos2dx_Director_popToRootScene(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Director_loadMatrix(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_loadMatrix : Invalid Native Object"); if (argc == 2) { cocos2d::MATRIX_STACK_TYPE arg0; cocos2d::Mat4 arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_matrix(cx, argv[1], &arg1); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_matrix(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_loadMatrix : Error processing arguments"); cobj->loadMatrix(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6758,7 +6932,8 @@ bool js_cocos2dx_Director_loadMatrix(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_getNotificationNode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getNotificationNode : Invalid Native Object"); @@ -6773,7 +6948,7 @@ bool js_cocos2dx_Director_getNotificationNode(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6782,7 +6957,8 @@ bool js_cocos2dx_Director_getNotificationNode(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_Director_getWinSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getWinSize : Invalid Native Object"); @@ -6790,7 +6966,7 @@ bool js_cocos2dx_Director_getWinSize(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Size& ret = cobj->getWinSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6799,13 +6975,14 @@ bool js_cocos2dx_Director_getWinSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_end(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_end : Invalid Native Object"); if (argc == 0) { cobj->end(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6814,7 +6991,8 @@ bool js_cocos2dx_Director_end(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_getTextureCache(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getTextureCache : Invalid Native Object"); @@ -6829,7 +7007,7 @@ bool js_cocos2dx_Director_getTextureCache(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6838,7 +7016,8 @@ bool js_cocos2dx_Director_getTextureCache(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Director_isSendCleanupToScene(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_isSendCleanupToScene : Invalid Native Object"); @@ -6846,7 +7025,7 @@ bool js_cocos2dx_Director_isSendCleanupToScene(JSContext *cx, uint32_t argc, jsv bool ret = cobj->isSendCleanupToScene(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6855,7 +7034,8 @@ bool js_cocos2dx_Director_isSendCleanupToScene(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_Director_getVisibleOrigin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getVisibleOrigin : Invalid Native Object"); @@ -6863,7 +7043,7 @@ bool js_cocos2dx_Director_getVisibleOrigin(JSContext *cx, uint32_t argc, jsval * cocos2d::Vec2 ret = cobj->getVisibleOrigin(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6872,13 +7052,14 @@ bool js_cocos2dx_Director_getVisibleOrigin(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Director_mainLoop(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_mainLoop : Invalid Native Object"); if (argc == 0) { cobj->mainLoop(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6887,18 +7068,18 @@ bool js_cocos2dx_Director_mainLoop(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_setDepthTest(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setDepthTest : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_setDepthTest : Error processing arguments"); cobj->setDepthTest(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6907,7 +7088,8 @@ bool js_cocos2dx_Director_setDepthTest(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_getFrameRate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getFrameRate : Invalid Native Object"); @@ -6915,7 +7097,7 @@ bool js_cocos2dx_Director_getFrameRate(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getFrameRate(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6924,7 +7106,8 @@ bool js_cocos2dx_Director_getFrameRate(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_getSecondsPerFrame(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getSecondsPerFrame : Invalid Native Object"); @@ -6932,7 +7115,7 @@ bool js_cocos2dx_Director_getSecondsPerFrame(JSContext *cx, uint32_t argc, jsval double ret = cobj->getSecondsPerFrame(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6941,13 +7124,14 @@ bool js_cocos2dx_Director_getSecondsPerFrame(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Director_resetMatrixStack(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_resetMatrixStack : Invalid Native Object"); if (argc == 0) { cobj->resetMatrixStack(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6956,20 +7140,20 @@ bool js_cocos2dx_Director_resetMatrixStack(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Director_convertToUI(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_convertToUI : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_convertToUI : Error processing arguments"); cocos2d::Vec2 ret = cobj->convertToUI(arg0); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6978,18 +7162,18 @@ bool js_cocos2dx_Director_convertToUI(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_pushMatrix(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_pushMatrix : Invalid Native Object"); if (argc == 1) { cocos2d::MATRIX_STACK_TYPE arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_pushMatrix : Error processing arguments"); cobj->pushMatrix(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6998,13 +7182,14 @@ bool js_cocos2dx_Director_pushMatrix(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_setDefaultValues(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setDefaultValues : Invalid Native Object"); if (argc == 0) { cobj->setDefaultValues(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7013,7 +7198,8 @@ bool js_cocos2dx_Director_setDefaultValues(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Director_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_init : Invalid Native Object"); @@ -7021,7 +7207,7 @@ bool js_cocos2dx_Director_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7030,25 +7216,25 @@ bool js_cocos2dx_Director_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_setScheduler(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setScheduler : Invalid Native Object"); if (argc == 1) { cocos2d::Scheduler* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Scheduler*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_setScheduler : Error processing arguments"); cobj->setScheduler(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7057,20 +7243,20 @@ bool js_cocos2dx_Director_setScheduler(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_getMatrix(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getMatrix : Invalid Native Object"); if (argc == 1) { cocos2d::MATRIX_STACK_TYPE arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_getMatrix : Error processing arguments"); const cocos2d::Mat4& ret = cobj->getMatrix(arg0); jsval jsret = JSVAL_NULL; jsret = matrix_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7079,13 +7265,14 @@ bool js_cocos2dx_Director_getMatrix(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_startAnimation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_startAnimation : Invalid Native Object"); if (argc == 0) { cobj->startAnimation(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7094,7 +7281,8 @@ bool js_cocos2dx_Director_startAnimation(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Director_getOpenGLView(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getOpenGLView : Invalid Native Object"); @@ -7109,7 +7297,7 @@ bool js_cocos2dx_Director_getOpenGLView(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7118,7 +7306,8 @@ bool js_cocos2dx_Director_getOpenGLView(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_getRunningScene(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getRunningScene : Invalid Native Object"); @@ -7133,7 +7322,7 @@ bool js_cocos2dx_Director_getRunningScene(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7142,13 +7331,14 @@ bool js_cocos2dx_Director_getRunningScene(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Director_setViewport(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setViewport : Invalid Native Object"); if (argc == 0) { cobj->setViewport(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7157,13 +7347,14 @@ bool js_cocos2dx_Director_setViewport(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_stopAnimation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_stopAnimation : Invalid Native Object"); if (argc == 0) { cobj->stopAnimation(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7172,18 +7363,18 @@ bool js_cocos2dx_Director_stopAnimation(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_popToSceneStackLevel(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_popToSceneStackLevel : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_popToSceneStackLevel : Error processing arguments"); cobj->popToSceneStackLevel(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7192,13 +7383,14 @@ bool js_cocos2dx_Director_popToSceneStackLevel(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_Director_resume(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_resume : Invalid Native Object"); if (argc == 0) { cobj->resume(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7207,7 +7399,8 @@ bool js_cocos2dx_Director_resume(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_isNextDeltaTimeZero(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_isNextDeltaTimeZero : Invalid Native Object"); @@ -7215,34 +7408,54 @@ bool js_cocos2dx_Director_isNextDeltaTimeZero(JSContext *cx, uint32_t argc, jsva bool ret = cobj->isNextDeltaTimeZero(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Director_isNextDeltaTimeZero : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_Director_setClearColor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setClearColor : Invalid Native Object"); + if (argc == 1) { + cocos2d::Color4F arg0; + ok &= jsval_to_cccolor4f(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_setClearColor : Error processing arguments"); + cobj->setClearColor(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Director_setClearColor : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_Director_setOpenGLView(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setOpenGLView : Invalid Native Object"); if (argc == 1) { cocos2d::GLView* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::GLView*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_setOpenGLView : Error processing arguments"); cobj->setOpenGLView(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7251,20 +7464,20 @@ bool js_cocos2dx_Director_setOpenGLView(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_convertToGL(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_convertToGL : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_convertToGL : Error processing arguments"); cocos2d::Vec2 ret = cobj->convertToGL(arg0); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7273,13 +7486,14 @@ bool js_cocos2dx_Director_convertToGL(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_purgeCachedData(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_purgeCachedData : Invalid Native Object"); if (argc == 0) { cobj->purgeCachedData(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7288,7 +7502,8 @@ bool js_cocos2dx_Director_purgeCachedData(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Director_getTotalFrames(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getTotalFrames : Invalid Native Object"); @@ -7296,7 +7511,7 @@ bool js_cocos2dx_Director_getTotalFrames(JSContext *cx, uint32_t argc, jsval *vp unsigned int ret = cobj->getTotalFrames(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7305,25 +7520,25 @@ bool js_cocos2dx_Director_getTotalFrames(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Director_runWithScene(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_runWithScene : Invalid Native Object"); if (argc == 1) { cocos2d::Scene* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_runWithScene : Error processing arguments"); cobj->runWithScene(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7332,25 +7547,25 @@ bool js_cocos2dx_Director_runWithScene(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_setNotificationNode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setNotificationNode : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_setNotificationNode : Error processing arguments"); cobj->setNotificationNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7359,13 +7574,14 @@ bool js_cocos2dx_Director_setNotificationNode(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_Director_drawScene(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_drawScene : Invalid Native Object"); if (argc == 0) { cobj->drawScene(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7374,13 +7590,14 @@ bool js_cocos2dx_Director_drawScene(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_restart(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_restart : Invalid Native Object"); if (argc == 0) { cobj->restart(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7389,13 +7606,14 @@ bool js_cocos2dx_Director_restart(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_popScene(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_popScene : Invalid Native Object"); if (argc == 0) { cobj->popScene(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7404,18 +7622,18 @@ bool js_cocos2dx_Director_popScene(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_loadIdentityMatrix(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_loadIdentityMatrix : Invalid Native Object"); if (argc == 1) { cocos2d::MATRIX_STACK_TYPE arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_loadIdentityMatrix : Error processing arguments"); cobj->loadIdentityMatrix(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7424,7 +7642,8 @@ bool js_cocos2dx_Director_loadIdentityMatrix(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Director_isDisplayStats(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_isDisplayStats : Invalid Native Object"); @@ -7432,7 +7651,7 @@ bool js_cocos2dx_Director_isDisplayStats(JSContext *cx, uint32_t argc, jsval *vp bool ret = cobj->isDisplayStats(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7441,18 +7660,18 @@ bool js_cocos2dx_Director_isDisplayStats(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Director_setProjection(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setProjection : Invalid Native Object"); if (argc == 1) { cocos2d::Director::Projection arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_setProjection : Error processing arguments"); cobj->setProjection(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7461,20 +7680,20 @@ bool js_cocos2dx_Director_setProjection(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_multiplyMatrix(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_multiplyMatrix : Invalid Native Object"); if (argc == 2) { cocos2d::MATRIX_STACK_TYPE arg0; cocos2d::Mat4 arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_matrix(cx, argv[1], &arg1); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_matrix(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_multiplyMatrix : Error processing arguments"); cobj->multiplyMatrix(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7483,7 +7702,8 @@ bool js_cocos2dx_Director_multiplyMatrix(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Director_getZEye(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getZEye : Invalid Native Object"); @@ -7491,7 +7711,7 @@ bool js_cocos2dx_Director_getZEye(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getZEye(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7500,18 +7720,18 @@ bool js_cocos2dx_Director_getZEye(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_setNextDeltaTimeZero(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setNextDeltaTimeZero : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_setNextDeltaTimeZero : Error processing arguments"); cobj->setNextDeltaTimeZero(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7520,18 +7740,18 @@ bool js_cocos2dx_Director_setNextDeltaTimeZero(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_Director_popMatrix(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_popMatrix : Invalid Native Object"); if (argc == 1) { cocos2d::MATRIX_STACK_TYPE arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_popMatrix : Error processing arguments"); cobj->popMatrix(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7540,7 +7760,8 @@ bool js_cocos2dx_Director_popMatrix(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_getVisibleSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getVisibleSize : Invalid Native Object"); @@ -7548,7 +7769,7 @@ bool js_cocos2dx_Director_getVisibleSize(JSContext *cx, uint32_t argc, jsval *vp cocos2d::Size ret = cobj->getVisibleSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7557,7 +7778,8 @@ bool js_cocos2dx_Director_getVisibleSize(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Director_getScheduler(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getScheduler : Invalid Native Object"); @@ -7572,7 +7794,7 @@ bool js_cocos2dx_Director_getScheduler(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7581,25 +7803,25 @@ bool js_cocos2dx_Director_getScheduler(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_pushScene(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_pushScene : Invalid Native Object"); if (argc == 1) { cocos2d::Scene* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_pushScene : Error processing arguments"); cobj->pushScene(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7608,7 +7830,8 @@ bool js_cocos2dx_Director_pushScene(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_getAnimationInterval(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getAnimationInterval : Invalid Native Object"); @@ -7616,7 +7839,7 @@ bool js_cocos2dx_Director_getAnimationInterval(JSContext *cx, uint32_t argc, jsv double ret = cobj->getAnimationInterval(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7625,7 +7848,8 @@ bool js_cocos2dx_Director_getAnimationInterval(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_Director_isPaused(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_isPaused : Invalid Native Object"); @@ -7633,7 +7857,7 @@ bool js_cocos2dx_Director_isPaused(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isPaused(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7642,18 +7866,18 @@ bool js_cocos2dx_Director_isPaused(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_setDisplayStats(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setDisplayStats : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_setDisplayStats : Error processing arguments"); cobj->setDisplayStats(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7662,7 +7886,8 @@ bool js_cocos2dx_Director_setDisplayStats(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Director_getEventDispatcher(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getEventDispatcher : Invalid Native Object"); @@ -7677,7 +7902,7 @@ bool js_cocos2dx_Director_getEventDispatcher(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7686,25 +7911,25 @@ bool js_cocos2dx_Director_getEventDispatcher(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Director_replaceScene(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_replaceScene : Invalid Native Object"); if (argc == 1) { cocos2d::Scene* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_replaceScene : Error processing arguments"); cobj->replaceScene(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7713,18 +7938,18 @@ bool js_cocos2dx_Director_replaceScene(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Director_setAnimationInterval(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_setAnimationInterval : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Director_setAnimationInterval : Error processing arguments"); cobj->setAnimationInterval(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7733,7 +7958,8 @@ bool js_cocos2dx_Director_setAnimationInterval(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_Director_getActionManager(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Director* cobj = (cocos2d::Director *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Director_getActionManager : Invalid Native Object"); @@ -7748,7 +7974,7 @@ bool js_cocos2dx_Director_getActionManager(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7757,6 +7983,7 @@ bool js_cocos2dx_Director_getActionManager(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Director_getInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Director* ret = cocos2d::Director::getInstance(); jsval jsret = JSVAL_NULL; @@ -7768,7 +7995,7 @@ bool js_cocos2dx_Director_getInstance(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Director_getInstance : wrong number of arguments"); @@ -7781,7 +8008,7 @@ void js_cocos2d_Director_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Director)", obj); } -void js_register_cocos2dx_Director(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Director(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Director_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Director_class->name = "Director"; jsb_cocos2d_Director_class->addProperty = JS_PropertyStub; @@ -7795,8 +8022,8 @@ void js_register_cocos2dx_Director(JSContext *cx, JSObject *global) { jsb_cocos2d_Director_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -7836,6 +8063,7 @@ void js_register_cocos2dx_Director(JSContext *cx, JSObject *global) { JS_FN("popToSceneStackLevel", js_cocos2dx_Director_popToSceneStackLevel, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("resume", js_cocos2dx_Director_resume, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isNextDeltaTimeZero", js_cocos2dx_Director_isNextDeltaTimeZero, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setClearColor", js_cocos2dx_Director_setClearColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setOpenGLView", js_cocos2dx_Director_setOpenGLView, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("convertToGL", js_cocos2dx_Director_convertToGL, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("purgeCachedData", js_cocos2dx_Director_purgeCachedData, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -7872,7 +8100,7 @@ void js_register_cocos2dx_Director(JSContext *cx, JSObject *global) { jsb_cocos2d_Director_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_Director_class, empty_constructor, 0, properties, @@ -7903,41 +8131,62 @@ JSObject *jsb_cocos2d_Scheduler_prototype; bool js_cocos2dx_Scheduler_setTimeScale(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scheduler* cobj = (cocos2d::Scheduler *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Scheduler_setTimeScale : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Scheduler_setTimeScale : Error processing arguments"); cobj->setTimeScale(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Scheduler_setTimeScale : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_Scheduler_update(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Scheduler* cobj = (cocos2d::Scheduler *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Scheduler_update : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Scheduler_update : Error processing arguments"); + cobj->update(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Scheduler_update : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_Scheduler_performFunctionInCocosThread(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scheduler* cobj = (cocos2d::Scheduler *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Scheduler_performFunctionInCocosThread : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=]() -> void { - jsval rval; - bool ok = func->invoke(0, nullptr, rval); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + JS::RootedValue rval(cx); + bool ok = func->invoke(0, nullptr, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -7952,7 +8201,7 @@ bool js_cocos2dx_Scheduler_performFunctionInCocosThread(JSContext *cx, uint32_t ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Scheduler_performFunctionInCocosThread : Error processing arguments"); cobj->performFunctionInCocosThread(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7961,7 +8210,8 @@ bool js_cocos2dx_Scheduler_performFunctionInCocosThread(JSContext *cx, uint32_t } bool js_cocos2dx_Scheduler_getTimeScale(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scheduler* cobj = (cocos2d::Scheduler *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Scheduler_getTimeScale : Invalid Native Object"); @@ -7969,7 +8219,7 @@ bool js_cocos2dx_Scheduler_getTimeScale(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getTimeScale(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7978,7 +8228,7 @@ bool js_cocos2dx_Scheduler_getTimeScale(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Scheduler_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Scheduler* cobj = new (std::nothrow) cocos2d::Scheduler(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -7992,13 +8242,16 @@ bool js_cocos2dx_Scheduler_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Scheduler"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Scheduler"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -8008,7 +8261,7 @@ void js_cocos2d_Scheduler_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Scheduler)", obj); } -void js_register_cocos2dx_Scheduler(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Scheduler(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Scheduler_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Scheduler_class->name = "Scheduler"; jsb_cocos2d_Scheduler_class->addProperty = JS_PropertyStub; @@ -8022,12 +8275,13 @@ void js_register_cocos2dx_Scheduler(JSContext *cx, JSObject *global) { jsb_cocos2d_Scheduler_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("setTimeScale", js_cocos2dx_Scheduler_setTimeScale, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("update", js_cocos2dx_Scheduler_update, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("performFunctionInCocosThread", js_cocos2dx_Scheduler_performFunctionInCocosThread, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getTimeScale", js_cocos2dx_Scheduler_getTimeScale, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END @@ -8037,7 +8291,7 @@ void js_register_cocos2dx_Scheduler(JSContext *cx, JSObject *global) { jsb_cocos2d_Scheduler_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_Scheduler_class, js_cocos2dx_Scheduler_constructor, 0, // constructor properties, @@ -8068,20 +8322,20 @@ JSObject *jsb_cocos2d_FileUtils_prototype; bool js_cocos2dx_FileUtils_fullPathForFilename(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_fullPathForFilename : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_fullPathForFilename : Error processing arguments"); std::string ret = cobj->fullPathForFilename(arg0); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8090,20 +8344,20 @@ bool js_cocos2dx_FileUtils_fullPathForFilename(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_FileUtils_getStringFromFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_getStringFromFile : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_getStringFromFile : Error processing arguments"); std::string ret = cobj->getStringFromFile(arg0); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8112,20 +8366,20 @@ bool js_cocos2dx_FileUtils_getStringFromFile(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_FileUtils_removeFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_removeFile : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_removeFile : Error processing arguments"); bool ret = cobj->removeFile(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8134,20 +8388,20 @@ bool js_cocos2dx_FileUtils_removeFile(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_FileUtils_isAbsolutePath(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_isAbsolutePath : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_isAbsolutePath : Error processing arguments"); bool ret = cobj->isAbsolutePath(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8156,9 +8410,9 @@ bool js_cocos2dx_FileUtils_isAbsolutePath(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_FileUtils_renameFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_renameFile : Invalid Native Object"); @@ -8166,14 +8420,14 @@ bool js_cocos2dx_FileUtils_renameFile(JSContext *cx, uint32_t argc, jsval *vp) std::string arg0; std::string arg1; std::string arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_renameFile : Error processing arguments"); bool ret = cobj->renameFile(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8182,18 +8436,18 @@ bool js_cocos2dx_FileUtils_renameFile(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_FileUtils_loadFilenameLookupDictionaryFromFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_loadFilenameLookupDictionaryFromFile : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_loadFilenameLookupDictionaryFromFile : Error processing arguments"); cobj->loadFilenameLookupDictionaryFromFile(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8202,7 +8456,8 @@ bool js_cocos2dx_FileUtils_loadFilenameLookupDictionaryFromFile(JSContext *cx, u } bool js_cocos2dx_FileUtils_isPopupNotify(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_isPopupNotify : Invalid Native Object"); @@ -8210,7 +8465,7 @@ bool js_cocos2dx_FileUtils_isPopupNotify(JSContext *cx, uint32_t argc, jsval *vp bool ret = cobj->isPopupNotify(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8219,20 +8474,20 @@ bool js_cocos2dx_FileUtils_isPopupNotify(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_FileUtils_getValueVectorFromFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_getValueVectorFromFile : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_getValueVectorFromFile : Error processing arguments"); cocos2d::ValueVector ret = cobj->getValueVectorFromFile(arg0); jsval jsret = JSVAL_NULL; jsret = ccvaluevector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8241,7 +8496,8 @@ bool js_cocos2dx_FileUtils_getValueVectorFromFile(JSContext *cx, uint32_t argc, } bool js_cocos2dx_FileUtils_getSearchPaths(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_getSearchPaths : Invalid Native Object"); @@ -8249,7 +8505,7 @@ bool js_cocos2dx_FileUtils_getSearchPaths(JSContext *cx, uint32_t argc, jsval *v const std::vector& ret = cobj->getSearchPaths(); jsval jsret = JSVAL_NULL; jsret = std_vector_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8258,22 +8514,22 @@ bool js_cocos2dx_FileUtils_getSearchPaths(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_FileUtils_writeToFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_writeToFile : Invalid Native Object"); if (argc == 2) { cocos2d::ValueMap arg0; std::string arg1; - ok &= jsval_to_ccvaluemap(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_ccvaluemap(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_writeToFile : Error processing arguments"); bool ret = cobj->writeToFile(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8282,20 +8538,20 @@ bool js_cocos2dx_FileUtils_writeToFile(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_FileUtils_getValueMapFromFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_getValueMapFromFile : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_getValueMapFromFile : Error processing arguments"); cocos2d::ValueMap ret = cobj->getValueMapFromFile(arg0); jsval jsret = JSVAL_NULL; jsret = ccvaluemap_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8304,22 +8560,22 @@ bool js_cocos2dx_FileUtils_getValueMapFromFile(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_FileUtils_getValueMapFromData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_getValueMapFromData : Invalid Native Object"); if (argc == 2) { const char* arg0; int arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_getValueMapFromData : Error processing arguments"); cocos2d::ValueMap ret = cobj->getValueMapFromData(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = ccvaluemap_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8328,20 +8584,20 @@ bool js_cocos2dx_FileUtils_getValueMapFromData(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_FileUtils_removeDirectory(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_removeDirectory : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_removeDirectory : Error processing arguments"); bool ret = cobj->removeDirectory(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8350,18 +8606,18 @@ bool js_cocos2dx_FileUtils_removeDirectory(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_FileUtils_setSearchPaths(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_setSearchPaths : Invalid Native Object"); if (argc == 1) { std::vector arg0; - ok &= jsval_to_std_vector_string(cx, argv[0], &arg0); + ok &= jsval_to_std_vector_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_setSearchPaths : Error processing arguments"); cobj->setSearchPaths(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8370,20 +8626,20 @@ bool js_cocos2dx_FileUtils_setSearchPaths(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_FileUtils_getFileSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_getFileSize : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_getFileSize : Error processing arguments"); long ret = cobj->getFileSize(arg0); jsval jsret = JSVAL_NULL; jsret = long_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8392,18 +8648,18 @@ bool js_cocos2dx_FileUtils_getFileSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_FileUtils_setSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_setSearchResolutionsOrder : Invalid Native Object"); if (argc == 1) { std::vector arg0; - ok &= jsval_to_std_vector_string(cx, argv[0], &arg0); + ok &= jsval_to_std_vector_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_setSearchResolutionsOrder : Error processing arguments"); cobj->setSearchResolutionsOrder(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8412,28 +8668,28 @@ bool js_cocos2dx_FileUtils_setSearchResolutionsOrder(JSContext *cx, uint32_t arg } bool js_cocos2dx_FileUtils_addSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_addSearchResolutionsOrder : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_addSearchResolutionsOrder : Error processing arguments"); cobj->addSearchResolutionsOrder(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; bool arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_addSearchResolutionsOrder : Error processing arguments"); cobj->addSearchResolutionsOrder(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8442,28 +8698,28 @@ bool js_cocos2dx_FileUtils_addSearchResolutionsOrder(JSContext *cx, uint32_t arg } bool js_cocos2dx_FileUtils_addSearchPath(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_addSearchPath : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_addSearchPath : Error processing arguments"); cobj->addSearchPath(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; bool arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_addSearchPath : Error processing arguments"); cobj->addSearchPath(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8472,20 +8728,20 @@ bool js_cocos2dx_FileUtils_addSearchPath(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_FileUtils_isFileExist(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_isFileExist : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_isFileExist : Error processing arguments"); bool ret = cobj->isFileExist(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8494,13 +8750,14 @@ bool js_cocos2dx_FileUtils_isFileExist(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_FileUtils_purgeCachedEntries(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_purgeCachedEntries : Invalid Native Object"); if (argc == 0) { cobj->purgeCachedEntries(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8509,42 +8766,62 @@ bool js_cocos2dx_FileUtils_purgeCachedEntries(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_FileUtils_fullPathFromRelativeFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_fullPathFromRelativeFile : Invalid Native Object"); if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_fullPathFromRelativeFile : Error processing arguments"); std::string ret = cobj->fullPathFromRelativeFile(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FileUtils_fullPathFromRelativeFile : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } +bool js_cocos2dx_FileUtils_setWritablePath(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_setWritablePath : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_setWritablePath : Error processing arguments"); + cobj->setWritablePath(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_FileUtils_setWritablePath : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_FileUtils_setPopupNotify(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_setPopupNotify : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_setPopupNotify : Error processing arguments"); cobj->setPopupNotify(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8553,29 +8830,50 @@ bool js_cocos2dx_FileUtils_setPopupNotify(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_FileUtils_isDirectoryExist(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_isDirectoryExist : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_isDirectoryExist : Error processing arguments"); bool ret = cobj->isDirectoryExist(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FileUtils_isDirectoryExist : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_FileUtils_setDefaultResourceRootPath(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_setDefaultResourceRootPath : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_setDefaultResourceRootPath : Error processing arguments"); + cobj->setDefaultResourceRootPath(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_FileUtils_setDefaultResourceRootPath : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_FileUtils_getSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_getSearchResolutionsOrder : Invalid Native Object"); @@ -8583,7 +8881,7 @@ bool js_cocos2dx_FileUtils_getSearchResolutionsOrder(JSContext *cx, uint32_t arg const std::vector& ret = cobj->getSearchResolutionsOrder(); jsval jsret = JSVAL_NULL; jsret = std_vector_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8592,20 +8890,20 @@ bool js_cocos2dx_FileUtils_getSearchResolutionsOrder(JSContext *cx, uint32_t arg } bool js_cocos2dx_FileUtils_createDirectory(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_createDirectory : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_createDirectory : Error processing arguments"); bool ret = cobj->createDirectory(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8614,7 +8912,8 @@ bool js_cocos2dx_FileUtils_createDirectory(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_FileUtils_getWritablePath(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_getWritablePath : Invalid Native Object"); @@ -8622,15 +8921,39 @@ bool js_cocos2dx_FileUtils_getWritablePath(JSContext *cx, uint32_t argc, jsval * std::string ret = cobj->getWritablePath(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FileUtils_getWritablePath : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_FileUtils_setDelegate(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + cocos2d::FileUtils* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::FileUtils*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_setDelegate : Error processing arguments"); + cocos2d::FileUtils::setDelegate(arg0); + args.rval().setUndefined(); + return true; + } + JS_ReportError(cx, "js_cocos2dx_FileUtils_setDelegate : wrong number of arguments"); + return false; +} + bool js_cocos2dx_FileUtils_getInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::FileUtils* ret = cocos2d::FileUtils::getInstance(); jsval jsret = JSVAL_NULL; @@ -8642,7 +8965,7 @@ bool js_cocos2dx_FileUtils_getInstance(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FileUtils_getInstance : wrong number of arguments"); @@ -8655,7 +8978,7 @@ void js_cocos2d_FileUtils_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (FileUtils)", obj); } -void js_register_cocos2dx_FileUtils(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_FileUtils(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_FileUtils_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_FileUtils_class->name = "FileUtils"; jsb_cocos2d_FileUtils_class->addProperty = JS_PropertyStub; @@ -8669,8 +8992,8 @@ void js_register_cocos2dx_FileUtils(JSContext *cx, JSObject *global) { jsb_cocos2d_FileUtils_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -8695,8 +9018,10 @@ void js_register_cocos2dx_FileUtils(JSContext *cx, JSObject *global) { JS_FN("isFileExist", js_cocos2dx_FileUtils_isFileExist, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("purgeCachedEntries", js_cocos2dx_FileUtils_purgeCachedEntries, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("fullPathFromRelativeFile", js_cocos2dx_FileUtils_fullPathFromRelativeFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setWritablePath", js_cocos2dx_FileUtils_setWritablePath, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setPopupNotify", js_cocos2dx_FileUtils_setPopupNotify, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isDirectoryExist", js_cocos2dx_FileUtils_isDirectoryExist, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setDefaultResourceRootPath", js_cocos2dx_FileUtils_setDefaultResourceRootPath, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getSearchResolutionsOrder", js_cocos2dx_FileUtils_getSearchResolutionsOrder, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("createDirectory", js_cocos2dx_FileUtils_createDirectory, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getWritablePath", js_cocos2dx_FileUtils_getWritablePath, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -8704,13 +9029,14 @@ void js_register_cocos2dx_FileUtils(JSContext *cx, JSObject *global) { }; static JSFunctionSpec st_funcs[] = { + JS_FN("setDelegate", js_cocos2dx_FileUtils_setDelegate, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getInstance", js_cocos2dx_FileUtils_getInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; jsb_cocos2d_FileUtils_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_FileUtils_class, empty_constructor, 0, properties, @@ -8741,18 +9067,18 @@ JSObject *jsb_cocos2d_EventListener_prototype; bool js_cocos2dx_EventListener_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventListener* cobj = (cocos2d::EventListener *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventListener_setEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventListener_setEnabled : Error processing arguments"); cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8761,7 +9087,8 @@ bool js_cocos2dx_EventListener_setEnabled(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_EventListener_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventListener* cobj = (cocos2d::EventListener *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventListener_isEnabled : Invalid Native Object"); @@ -8769,7 +9096,7 @@ bool js_cocos2dx_EventListener_isEnabled(JSContext *cx, uint32_t argc, jsval *vp bool ret = cobj->isEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8778,7 +9105,8 @@ bool js_cocos2dx_EventListener_isEnabled(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_EventListener_clone(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventListener* cobj = (cocos2d::EventListener *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventListener_clone : Invalid Native Object"); @@ -8793,7 +9121,7 @@ bool js_cocos2dx_EventListener_clone(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8802,7 +9130,8 @@ bool js_cocos2dx_EventListener_clone(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_EventListener_checkAvailable(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventListener* cobj = (cocos2d::EventListener *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventListener_checkAvailable : Invalid Native Object"); @@ -8810,7 +9139,7 @@ bool js_cocos2dx_EventListener_checkAvailable(JSContext *cx, uint32_t argc, jsva bool ret = cobj->checkAvailable(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8823,7 +9152,7 @@ void js_cocos2d_EventListener_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EventListener)", obj); } -void js_register_cocos2dx_EventListener(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EventListener(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EventListener_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EventListener_class->name = "EventListener"; jsb_cocos2d_EventListener_class->addProperty = JS_PropertyStub; @@ -8837,8 +9166,8 @@ void js_register_cocos2dx_EventListener(JSContext *cx, JSObject *global) { jsb_cocos2d_EventListener_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -8853,7 +9182,7 @@ void js_register_cocos2dx_EventListener(JSContext *cx, JSObject *global) { jsb_cocos2d_EventListener_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_EventListener_class, empty_constructor, 0, properties, @@ -8884,18 +9213,18 @@ JSObject *jsb_cocos2d_EventDispatcher_prototype; bool js_cocos2dx_EventDispatcher_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_setEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_setEnabled : Error processing arguments"); cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8904,13 +9233,14 @@ bool js_cocos2dx_EventDispatcher_setEnabled(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_EventDispatcher_removeAllEventListeners(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_removeAllEventListeners : Invalid Native Object"); if (argc == 0) { cobj->removeAllEventListeners(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8919,9 +9249,9 @@ bool js_cocos2dx_EventDispatcher_removeAllEventListeners(JSContext *cx, uint32_t } bool js_cocos2dx_EventDispatcher_addEventListenerWithSceneGraphPriority(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_addEventListenerWithSceneGraphPriority : Invalid Native Object"); @@ -8929,24 +9259,24 @@ bool js_cocos2dx_EventDispatcher_addEventListenerWithSceneGraphPriority(JSContex cocos2d::EventListener* arg0; cocos2d::Node* arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::EventListener*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_addEventListenerWithSceneGraphPriority : Error processing arguments"); cobj->addEventListenerWithSceneGraphPriority(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8955,21 +9285,22 @@ bool js_cocos2dx_EventDispatcher_addEventListenerWithSceneGraphPriority(JSContex } bool js_cocos2dx_EventDispatcher_addCustomEventListener(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_addCustomEventListener : Invalid Native Object"); if (argc == 2) { std::string arg0; std::function arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](cocos2d::EventCustom* larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -8979,8 +9310,8 @@ bool js_cocos2dx_EventDispatcher_addCustomEventListener(JSContext *cx, uint32_t largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -9004,7 +9335,7 @@ bool js_cocos2dx_EventDispatcher_addCustomEventListener(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9013,9 +9344,9 @@ bool js_cocos2dx_EventDispatcher_addCustomEventListener(JSContext *cx, uint32_t } bool js_cocos2dx_EventDispatcher_addEventListenerWithFixedPriority(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_addEventListenerWithFixedPriority : Invalid Native Object"); @@ -9023,17 +9354,17 @@ bool js_cocos2dx_EventDispatcher_addEventListenerWithFixedPriority(JSContext *cx cocos2d::EventListener* arg0; int arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::EventListener*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_addEventListenerWithFixedPriority : Error processing arguments"); cobj->addEventListenerWithFixedPriority(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9042,12 +9373,12 @@ bool js_cocos2dx_EventDispatcher_addEventListenerWithFixedPriority(JSContext *cx } bool js_cocos2dx_EventDispatcher_removeEventListenersForTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::EventDispatcher* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_removeEventListenersForTarget : Invalid Native Object"); @@ -9055,16 +9386,16 @@ bool js_cocos2dx_EventDispatcher_removeEventListenersForTarget(JSContext *cx, ui if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cobj->removeEventListenersForTarget(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -9073,18 +9404,18 @@ bool js_cocos2dx_EventDispatcher_removeEventListenersForTarget(JSContext *cx, ui if (argc == 2) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } bool arg1; - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); cobj->removeEventListenersForTarget(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -9092,10 +9423,10 @@ bool js_cocos2dx_EventDispatcher_removeEventListenersForTarget(JSContext *cx, ui do { if (argc == 1) { cocos2d::EventListener::Type arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } cobj->removeEventListenersForType(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -9105,42 +9436,42 @@ bool js_cocos2dx_EventDispatcher_removeEventListenersForTarget(JSContext *cx, ui } bool js_cocos2dx_EventDispatcher_resumeEventListenersForTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_resumeEventListenersForTarget : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_resumeEventListenersForTarget : Error processing arguments"); cobj->resumeEventListenersForTarget(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { cocos2d::Node* arg0; bool arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_resumeEventListenersForTarget : Error processing arguments"); cobj->resumeEventListenersForTarget(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9149,9 +9480,9 @@ bool js_cocos2dx_EventDispatcher_resumeEventListenersForTarget(JSContext *cx, ui } bool js_cocos2dx_EventDispatcher_setPriority(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_setPriority : Invalid Native Object"); @@ -9159,17 +9490,17 @@ bool js_cocos2dx_EventDispatcher_setPriority(JSContext *cx, uint32_t argc, jsval cocos2d::EventListener* arg0; int arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::EventListener*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_setPriority : Error processing arguments"); cobj->setPriority(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9178,25 +9509,25 @@ bool js_cocos2dx_EventDispatcher_setPriority(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_EventDispatcher_dispatchEvent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_dispatchEvent : Invalid Native Object"); if (argc == 1) { cocos2d::Event* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Event*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_dispatchEvent : Error processing arguments"); cobj->dispatchEvent(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9205,42 +9536,42 @@ bool js_cocos2dx_EventDispatcher_dispatchEvent(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_EventDispatcher_pauseEventListenersForTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_pauseEventListenersForTarget : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_pauseEventListenersForTarget : Error processing arguments"); cobj->pauseEventListenersForTarget(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { cocos2d::Node* arg0; bool arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_pauseEventListenersForTarget : Error processing arguments"); cobj->pauseEventListenersForTarget(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9249,18 +9580,18 @@ bool js_cocos2dx_EventDispatcher_pauseEventListenersForTarget(JSContext *cx, uin } bool js_cocos2dx_EventDispatcher_removeCustomEventListeners(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_removeCustomEventListeners : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_removeCustomEventListeners : Error processing arguments"); cobj->removeCustomEventListeners(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9269,25 +9600,25 @@ bool js_cocos2dx_EventDispatcher_removeCustomEventListeners(JSContext *cx, uint3 } bool js_cocos2dx_EventDispatcher_removeEventListener(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_removeEventListener : Invalid Native Object"); if (argc == 1) { cocos2d::EventListener* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::EventListener*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_removeEventListener : Error processing arguments"); cobj->removeEventListener(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9296,7 +9627,8 @@ bool js_cocos2dx_EventDispatcher_removeEventListener(JSContext *cx, uint32_t arg } bool js_cocos2dx_EventDispatcher_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_isEnabled : Invalid Native Object"); @@ -9304,7 +9636,7 @@ bool js_cocos2dx_EventDispatcher_isEnabled(JSContext *cx, uint32_t argc, jsval * bool ret = cobj->isEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9313,7 +9645,7 @@ bool js_cocos2dx_EventDispatcher_isEnabled(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_EventDispatcher_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EventDispatcher* cobj = new (std::nothrow) cocos2d::EventDispatcher(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -9327,13 +9659,16 @@ bool js_cocos2dx_EventDispatcher_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventDispatcher"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventDispatcher"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -9343,7 +9678,7 @@ void js_cocos2d_EventDispatcher_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EventDispatcher)", obj); } -void js_register_cocos2dx_EventDispatcher(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EventDispatcher(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EventDispatcher_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EventDispatcher_class->name = "EventDispatcher"; jsb_cocos2d_EventDispatcher_class->addProperty = JS_PropertyStub; @@ -9357,8 +9692,8 @@ void js_register_cocos2dx_EventDispatcher(JSContext *cx, JSObject *global) { jsb_cocos2d_EventDispatcher_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -9382,7 +9717,7 @@ void js_register_cocos2dx_EventDispatcher(JSContext *cx, JSObject *global) { jsb_cocos2d_EventDispatcher_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_EventDispatcher_class, js_cocos2dx_EventDispatcher_constructor, 0, // constructor properties, @@ -9413,7 +9748,8 @@ JSObject *jsb_cocos2d_EventListenerTouchOneByOne_prototype; bool js_cocos2dx_EventListenerTouchOneByOne_isSwallowTouches(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventListenerTouchOneByOne* cobj = (cocos2d::EventListenerTouchOneByOne *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventListenerTouchOneByOne_isSwallowTouches : Invalid Native Object"); @@ -9421,7 +9757,7 @@ bool js_cocos2dx_EventListenerTouchOneByOne_isSwallowTouches(JSContext *cx, uint bool ret = cobj->isSwallowTouches(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9430,18 +9766,18 @@ bool js_cocos2dx_EventListenerTouchOneByOne_isSwallowTouches(JSContext *cx, uint } bool js_cocos2dx_EventListenerTouchOneByOne_setSwallowTouches(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventListenerTouchOneByOne* cobj = (cocos2d::EventListenerTouchOneByOne *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventListenerTouchOneByOne_setSwallowTouches : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventListenerTouchOneByOne_setSwallowTouches : Error processing arguments"); cobj->setSwallowTouches(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9450,7 +9786,8 @@ bool js_cocos2dx_EventListenerTouchOneByOne_setSwallowTouches(JSContext *cx, uin } bool js_cocos2dx_EventListenerTouchOneByOne_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventListenerTouchOneByOne* cobj = (cocos2d::EventListenerTouchOneByOne *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventListenerTouchOneByOne_init : Invalid Native Object"); @@ -9458,7 +9795,7 @@ bool js_cocos2dx_EventListenerTouchOneByOne_init(JSContext *cx, uint32_t argc, j bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9467,7 +9804,7 @@ bool js_cocos2dx_EventListenerTouchOneByOne_init(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_EventListenerTouchOneByOne_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EventListenerTouchOneByOne* cobj = new (std::nothrow) cocos2d::EventListenerTouchOneByOne(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -9481,13 +9818,16 @@ bool js_cocos2dx_EventListenerTouchOneByOne_constructor(JSContext *cx, uint32_t CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventListenerTouchOneByOne"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventListenerTouchOneByOne"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -9498,7 +9838,7 @@ void js_cocos2d_EventListenerTouchOneByOne_finalize(JSFreeOp *fop, JSObject *obj CCLOGINFO("jsbindings: finalizing JS object %p (EventListenerTouchOneByOne)", obj); } -void js_register_cocos2dx_EventListenerTouchOneByOne(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EventListenerTouchOneByOne(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EventListenerTouchOneByOne_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EventListenerTouchOneByOne_class->name = "EventListenerTouchOneByOne"; jsb_cocos2d_EventListenerTouchOneByOne_class->addProperty = JS_PropertyStub; @@ -9512,8 +9852,8 @@ void js_register_cocos2dx_EventListenerTouchOneByOne(JSContext *cx, JSObject *gl jsb_cocos2d_EventListenerTouchOneByOne_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -9527,7 +9867,7 @@ void js_register_cocos2dx_EventListenerTouchOneByOne(JSContext *cx, JSObject *gl jsb_cocos2d_EventListenerTouchOneByOne_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EventListener_prototype, + JS::RootedObject(cx, jsb_cocos2d_EventListener_prototype), jsb_cocos2d_EventListenerTouchOneByOne_class, js_cocos2dx_EventListenerTouchOneByOne_constructor, 0, // constructor properties, @@ -9558,7 +9898,8 @@ JSObject *jsb_cocos2d_EventListenerTouchAllAtOnce_prototype; bool js_cocos2dx_EventListenerTouchAllAtOnce_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventListenerTouchAllAtOnce* cobj = (cocos2d::EventListenerTouchAllAtOnce *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventListenerTouchAllAtOnce_init : Invalid Native Object"); @@ -9566,7 +9907,7 @@ bool js_cocos2dx_EventListenerTouchAllAtOnce_init(JSContext *cx, uint32_t argc, bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9575,7 +9916,7 @@ bool js_cocos2dx_EventListenerTouchAllAtOnce_init(JSContext *cx, uint32_t argc, } bool js_cocos2dx_EventListenerTouchAllAtOnce_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EventListenerTouchAllAtOnce* cobj = new (std::nothrow) cocos2d::EventListenerTouchAllAtOnce(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -9589,13 +9930,16 @@ bool js_cocos2dx_EventListenerTouchAllAtOnce_constructor(JSContext *cx, uint32_t CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventListenerTouchAllAtOnce"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventListenerTouchAllAtOnce"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -9606,7 +9950,7 @@ void js_cocos2d_EventListenerTouchAllAtOnce_finalize(JSFreeOp *fop, JSObject *ob CCLOGINFO("jsbindings: finalizing JS object %p (EventListenerTouchAllAtOnce)", obj); } -void js_register_cocos2dx_EventListenerTouchAllAtOnce(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EventListenerTouchAllAtOnce(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EventListenerTouchAllAtOnce_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EventListenerTouchAllAtOnce_class->name = "EventListenerTouchAllAtOnce"; jsb_cocos2d_EventListenerTouchAllAtOnce_class->addProperty = JS_PropertyStub; @@ -9620,8 +9964,8 @@ void js_register_cocos2dx_EventListenerTouchAllAtOnce(JSContext *cx, JSObject *g jsb_cocos2d_EventListenerTouchAllAtOnce_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -9633,7 +9977,7 @@ void js_register_cocos2dx_EventListenerTouchAllAtOnce(JSContext *cx, JSObject *g jsb_cocos2d_EventListenerTouchAllAtOnce_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EventListener_prototype, + JS::RootedObject(cx, jsb_cocos2d_EventListener_prototype), jsb_cocos2d_EventListenerTouchAllAtOnce_class, js_cocos2dx_EventListenerTouchAllAtOnce_constructor, 0, // constructor properties, @@ -9664,7 +10008,8 @@ JSObject *jsb_cocos2d_EventListenerKeyboard_prototype; bool js_cocos2dx_EventListenerKeyboard_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventListenerKeyboard* cobj = (cocos2d::EventListenerKeyboard *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventListenerKeyboard_init : Invalid Native Object"); @@ -9672,7 +10017,7 @@ bool js_cocos2dx_EventListenerKeyboard_init(JSContext *cx, uint32_t argc, jsval bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9681,7 +10026,7 @@ bool js_cocos2dx_EventListenerKeyboard_init(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_EventListenerKeyboard_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EventListenerKeyboard* cobj = new (std::nothrow) cocos2d::EventListenerKeyboard(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -9695,13 +10040,16 @@ bool js_cocos2dx_EventListenerKeyboard_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventListenerKeyboard"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventListenerKeyboard"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -9712,7 +10060,7 @@ void js_cocos2d_EventListenerKeyboard_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EventListenerKeyboard)", obj); } -void js_register_cocos2dx_EventListenerKeyboard(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EventListenerKeyboard(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EventListenerKeyboard_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EventListenerKeyboard_class->name = "EventListenerKeyboard"; jsb_cocos2d_EventListenerKeyboard_class->addProperty = JS_PropertyStub; @@ -9726,8 +10074,8 @@ void js_register_cocos2dx_EventListenerKeyboard(JSContext *cx, JSObject *global) jsb_cocos2d_EventListenerKeyboard_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -9739,7 +10087,7 @@ void js_register_cocos2dx_EventListenerKeyboard(JSContext *cx, JSObject *global) jsb_cocos2d_EventListenerKeyboard_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EventListener_prototype, + JS::RootedObject(cx, jsb_cocos2d_EventListener_prototype), jsb_cocos2d_EventListenerKeyboard_class, js_cocos2dx_EventListenerKeyboard_constructor, 0, // constructor properties, @@ -9770,7 +10118,8 @@ JSObject *jsb_cocos2d_EventMouse_prototype; bool js_cocos2dx_EventMouse_getMouseButton(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getMouseButton : Invalid Native Object"); @@ -9778,7 +10127,7 @@ bool js_cocos2dx_EventMouse_getMouseButton(JSContext *cx, uint32_t argc, jsval * int ret = cobj->getMouseButton(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9787,7 +10136,8 @@ bool js_cocos2dx_EventMouse_getMouseButton(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_EventMouse_getLocation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getLocation : Invalid Native Object"); @@ -9795,7 +10145,7 @@ bool js_cocos2dx_EventMouse_getLocation(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec2 ret = cobj->getLocation(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9804,18 +10154,18 @@ bool js_cocos2dx_EventMouse_getLocation(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_EventMouse_setMouseButton(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_setMouseButton : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventMouse_setMouseButton : Error processing arguments"); cobj->setMouseButton(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9824,20 +10174,20 @@ bool js_cocos2dx_EventMouse_setMouseButton(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_EventMouse_setScrollData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_setScrollData : Invalid Native Object"); if (argc == 2) { double arg0; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventMouse_setScrollData : Error processing arguments"); cobj->setScrollData(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9846,7 +10196,8 @@ bool js_cocos2dx_EventMouse_setScrollData(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_EventMouse_getPreviousLocationInView(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getPreviousLocationInView : Invalid Native Object"); @@ -9854,7 +10205,7 @@ bool js_cocos2dx_EventMouse_getPreviousLocationInView(JSContext *cx, uint32_t ar cocos2d::Vec2 ret = cobj->getPreviousLocationInView(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9863,7 +10214,8 @@ bool js_cocos2dx_EventMouse_getPreviousLocationInView(JSContext *cx, uint32_t ar } bool js_cocos2dx_EventMouse_getDelta(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getDelta : Invalid Native Object"); @@ -9871,7 +10223,7 @@ bool js_cocos2dx_EventMouse_getDelta(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec2 ret = cobj->getDelta(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9880,7 +10232,8 @@ bool js_cocos2dx_EventMouse_getDelta(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_EventMouse_getStartLocation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getStartLocation : Invalid Native Object"); @@ -9888,7 +10241,7 @@ bool js_cocos2dx_EventMouse_getStartLocation(JSContext *cx, uint32_t argc, jsval cocos2d::Vec2 ret = cobj->getStartLocation(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9897,7 +10250,8 @@ bool js_cocos2dx_EventMouse_getStartLocation(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_EventMouse_getCursorY(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getCursorY : Invalid Native Object"); @@ -9905,7 +10259,7 @@ bool js_cocos2dx_EventMouse_getCursorY(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getCursorY(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9914,7 +10268,8 @@ bool js_cocos2dx_EventMouse_getCursorY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_EventMouse_getCursorX(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getCursorX : Invalid Native Object"); @@ -9922,7 +10277,7 @@ bool js_cocos2dx_EventMouse_getCursorX(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getCursorX(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9931,7 +10286,8 @@ bool js_cocos2dx_EventMouse_getCursorX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_EventMouse_getLocationInView(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getLocationInView : Invalid Native Object"); @@ -9939,7 +10295,7 @@ bool js_cocos2dx_EventMouse_getLocationInView(JSContext *cx, uint32_t argc, jsva cocos2d::Vec2 ret = cobj->getLocationInView(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9948,7 +10304,8 @@ bool js_cocos2dx_EventMouse_getLocationInView(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_EventMouse_getScrollY(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getScrollY : Invalid Native Object"); @@ -9956,7 +10313,7 @@ bool js_cocos2dx_EventMouse_getScrollY(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getScrollY(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9965,20 +10322,20 @@ bool js_cocos2dx_EventMouse_getScrollY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_EventMouse_setCursorPosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_setCursorPosition : Invalid Native Object"); if (argc == 2) { double arg0; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventMouse_setCursorPosition : Error processing arguments"); cobj->setCursorPosition(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9987,7 +10344,8 @@ bool js_cocos2dx_EventMouse_setCursorPosition(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_EventMouse_getScrollX(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getScrollX : Invalid Native Object"); @@ -9995,7 +10353,7 @@ bool js_cocos2dx_EventMouse_getScrollX(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getScrollX(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10004,7 +10362,8 @@ bool js_cocos2dx_EventMouse_getScrollX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_EventMouse_getPreviousLocation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getPreviousLocation : Invalid Native Object"); @@ -10012,7 +10371,7 @@ bool js_cocos2dx_EventMouse_getPreviousLocation(JSContext *cx, uint32_t argc, js cocos2d::Vec2 ret = cobj->getPreviousLocation(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10021,7 +10380,8 @@ bool js_cocos2dx_EventMouse_getPreviousLocation(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_EventMouse_getStartLocationInView(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getStartLocationInView : Invalid Native Object"); @@ -10029,7 +10389,7 @@ bool js_cocos2dx_EventMouse_getStartLocationInView(JSContext *cx, uint32_t argc, cocos2d::Vec2 ret = cobj->getStartLocationInView(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10038,10 +10398,10 @@ bool js_cocos2dx_EventMouse_getStartLocationInView(JSContext *cx, uint32_t argc, } bool js_cocos2dx_EventMouse_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EventMouse::MouseEventType arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventMouse_constructor : Error processing arguments"); cocos2d::EventMouse* cobj = new (std::nothrow) cocos2d::EventMouse(arg0); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10055,13 +10415,16 @@ bool js_cocos2dx_EventMouse_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventMouse"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventMouse"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -10072,7 +10435,7 @@ void js_cocos2d_EventMouse_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EventMouse)", obj); } -void js_register_cocos2dx_EventMouse(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EventMouse(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EventMouse_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EventMouse_class->name = "EventMouse"; jsb_cocos2d_EventMouse_class->addProperty = JS_PropertyStub; @@ -10086,8 +10449,8 @@ void js_register_cocos2dx_EventMouse(JSContext *cx, JSObject *global) { jsb_cocos2d_EventMouse_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -10113,7 +10476,7 @@ void js_register_cocos2dx_EventMouse(JSContext *cx, JSObject *global) { jsb_cocos2d_EventMouse_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Event_prototype, + JS::RootedObject(cx, jsb_cocos2d_Event_prototype), jsb_cocos2d_EventMouse_class, js_cocos2dx_EventMouse_constructor, 0, // constructor properties, @@ -10144,7 +10507,8 @@ JSObject *jsb_cocos2d_EventListenerMouse_prototype; bool js_cocos2dx_EventListenerMouse_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventListenerMouse* cobj = (cocos2d::EventListenerMouse *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventListenerMouse_init : Invalid Native Object"); @@ -10152,7 +10516,7 @@ bool js_cocos2dx_EventListenerMouse_init(JSContext *cx, uint32_t argc, jsval *vp bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10161,7 +10525,7 @@ bool js_cocos2dx_EventListenerMouse_init(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_EventListenerMouse_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EventListenerMouse* cobj = new (std::nothrow) cocos2d::EventListenerMouse(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10175,13 +10539,16 @@ bool js_cocos2dx_EventListenerMouse_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventListenerMouse"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventListenerMouse"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -10192,7 +10559,7 @@ void js_cocos2d_EventListenerMouse_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EventListenerMouse)", obj); } -void js_register_cocos2dx_EventListenerMouse(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EventListenerMouse(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EventListenerMouse_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EventListenerMouse_class->name = "EventListenerMouse"; jsb_cocos2d_EventListenerMouse_class->addProperty = JS_PropertyStub; @@ -10206,8 +10573,8 @@ void js_register_cocos2dx_EventListenerMouse(JSContext *cx, JSObject *global) { jsb_cocos2d_EventListenerMouse_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -10219,7 +10586,7 @@ void js_register_cocos2dx_EventListenerMouse(JSContext *cx, JSObject *global) { jsb_cocos2d_EventListenerMouse_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EventListener_prototype, + JS::RootedObject(cx, jsb_cocos2d_EventListener_prototype), jsb_cocos2d_EventListenerMouse_class, js_cocos2dx_EventListenerMouse_constructor, 0, // constructor properties, @@ -10250,10 +10617,10 @@ JSObject *jsb_cocos2d_EventAcceleration_prototype; bool js_cocos2dx_EventAcceleration_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Acceleration arg0; - ok &= jsval_to_ccacceleration(cx, argv[0], &arg0); + ok &= jsval_to_ccacceleration(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventAcceleration_constructor : Error processing arguments"); cocos2d::EventAcceleration* cobj = new (std::nothrow) cocos2d::EventAcceleration(arg0); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10267,13 +10634,16 @@ bool js_cocos2dx_EventAcceleration_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventAcceleration"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventAcceleration"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -10284,7 +10654,7 @@ void js_cocos2d_EventAcceleration_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EventAcceleration)", obj); } -void js_register_cocos2dx_EventAcceleration(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EventAcceleration(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EventAcceleration_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EventAcceleration_class->name = "EventAcceleration"; jsb_cocos2d_EventAcceleration_class->addProperty = JS_PropertyStub; @@ -10298,8 +10668,8 @@ void js_register_cocos2dx_EventAcceleration(JSContext *cx, JSObject *global) { jsb_cocos2d_EventAcceleration_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -10310,7 +10680,7 @@ void js_register_cocos2dx_EventAcceleration(JSContext *cx, JSObject *global) { jsb_cocos2d_EventAcceleration_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Event_prototype, + JS::RootedObject(cx, jsb_cocos2d_Event_prototype), jsb_cocos2d_EventAcceleration_class, js_cocos2dx_EventAcceleration_constructor, 0, // constructor properties, @@ -10341,19 +10711,20 @@ JSObject *jsb_cocos2d_EventListenerAcceleration_prototype; bool js_cocos2dx_EventListenerAcceleration_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventListenerAcceleration* cobj = (cocos2d::EventListenerAcceleration *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventListenerAcceleration_init : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=](cocos2d::Acceleration* larg0, cocos2d::Event* larg1) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[2]; largv[0] = ccacceleration_to_jsval(cx, *larg0); do { @@ -10364,8 +10735,8 @@ bool js_cocos2dx_EventListenerAcceleration_init(JSContext *cx, uint32_t argc, js largv[1] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(2, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -10382,7 +10753,7 @@ bool js_cocos2dx_EventListenerAcceleration_init(JSContext *cx, uint32_t argc, js bool ret = cobj->init(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10391,15 +10762,16 @@ bool js_cocos2dx_EventListenerAcceleration_init(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_EventListenerAcceleration_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=](cocos2d::Acceleration* larg0, cocos2d::Event* larg1) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[2]; largv[0] = ccacceleration_to_jsval(cx, *larg0); do { @@ -10410,8 +10782,8 @@ bool js_cocos2dx_EventListenerAcceleration_create(JSContext *cx, uint32_t argc, largv[1] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(2, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -10435,7 +10807,7 @@ bool js_cocos2dx_EventListenerAcceleration_create(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EventListenerAcceleration_create : wrong number of arguments"); @@ -10444,7 +10816,7 @@ bool js_cocos2dx_EventListenerAcceleration_create(JSContext *cx, uint32_t argc, bool js_cocos2dx_EventListenerAcceleration_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EventListenerAcceleration* cobj = new (std::nothrow) cocos2d::EventListenerAcceleration(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10458,13 +10830,16 @@ bool js_cocos2dx_EventListenerAcceleration_constructor(JSContext *cx, uint32_t a CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventListenerAcceleration"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventListenerAcceleration"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -10475,7 +10850,7 @@ void js_cocos2d_EventListenerAcceleration_finalize(JSFreeOp *fop, JSObject *obj) CCLOGINFO("jsbindings: finalizing JS object %p (EventListenerAcceleration)", obj); } -void js_register_cocos2dx_EventListenerAcceleration(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EventListenerAcceleration(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EventListenerAcceleration_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EventListenerAcceleration_class->name = "EventListenerAcceleration"; jsb_cocos2d_EventListenerAcceleration_class->addProperty = JS_PropertyStub; @@ -10489,8 +10864,8 @@ void js_register_cocos2dx_EventListenerAcceleration(JSContext *cx, JSObject *glo jsb_cocos2d_EventListenerAcceleration_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -10505,7 +10880,7 @@ void js_register_cocos2dx_EventListenerAcceleration(JSContext *cx, JSObject *glo jsb_cocos2d_EventListenerAcceleration_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EventListener_prototype, + JS::RootedObject(cx, jsb_cocos2d_EventListener_prototype), jsb_cocos2d_EventListenerAcceleration_class, js_cocos2dx_EventListenerAcceleration_constructor, 0, // constructor properties, @@ -10536,7 +10911,8 @@ JSObject *jsb_cocos2d_EventCustom_prototype; bool js_cocos2dx_EventCustom_getEventName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventCustom* cobj = (cocos2d::EventCustom *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventCustom_getEventName : Invalid Native Object"); @@ -10544,7 +10920,7 @@ bool js_cocos2dx_EventCustom_getEventName(JSContext *cx, uint32_t argc, jsval *v const std::string& ret = cobj->getEventName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10553,10 +10929,10 @@ bool js_cocos2dx_EventCustom_getEventName(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_EventCustom_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventCustom_constructor : Error processing arguments"); cocos2d::EventCustom* cobj = new (std::nothrow) cocos2d::EventCustom(arg0); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10570,13 +10946,16 @@ bool js_cocos2dx_EventCustom_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventCustom"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventCustom"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -10587,7 +10966,7 @@ void js_cocos2d_EventCustom_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EventCustom)", obj); } -void js_register_cocos2dx_EventCustom(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EventCustom(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EventCustom_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EventCustom_class->name = "EventCustom"; jsb_cocos2d_EventCustom_class->addProperty = JS_PropertyStub; @@ -10601,8 +10980,8 @@ void js_register_cocos2dx_EventCustom(JSContext *cx, JSObject *global) { jsb_cocos2d_EventCustom_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -10614,7 +10993,7 @@ void js_register_cocos2dx_EventCustom(JSContext *cx, JSObject *global) { jsb_cocos2d_EventCustom_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Event_prototype, + JS::RootedObject(cx, jsb_cocos2d_Event_prototype), jsb_cocos2d_EventCustom_class, js_cocos2dx_EventCustom_constructor, 0, // constructor properties, @@ -10645,17 +11024,18 @@ JSObject *jsb_cocos2d_EventListenerCustom_prototype; bool js_cocos2dx_EventListenerCustom_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { std::string arg0; std::function arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](cocos2d::EventCustom* larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -10665,8 +11045,8 @@ bool js_cocos2dx_EventListenerCustom_create(JSContext *cx, uint32_t argc, jsval largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -10690,7 +11070,7 @@ bool js_cocos2dx_EventListenerCustom_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EventListenerCustom_create : wrong number of arguments"); @@ -10699,7 +11079,7 @@ bool js_cocos2dx_EventListenerCustom_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_EventListenerCustom_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EventListenerCustom* cobj = new (std::nothrow) cocos2d::EventListenerCustom(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10713,13 +11093,16 @@ bool js_cocos2dx_EventListenerCustom_constructor(JSContext *cx, uint32_t argc, j CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventListenerCustom"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventListenerCustom"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -10730,7 +11113,7 @@ void js_cocos2d_EventListenerCustom_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EventListenerCustom)", obj); } -void js_register_cocos2dx_EventListenerCustom(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EventListenerCustom(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EventListenerCustom_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EventListenerCustom_class->name = "EventListenerCustom"; jsb_cocos2d_EventListenerCustom_class->addProperty = JS_PropertyStub; @@ -10744,8 +11127,8 @@ void js_register_cocos2dx_EventListenerCustom(JSContext *cx, JSObject *global) { jsb_cocos2d_EventListenerCustom_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -10759,7 +11142,7 @@ void js_register_cocos2dx_EventListenerCustom(JSContext *cx, JSObject *global) { jsb_cocos2d_EventListenerCustom_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EventListener_prototype, + JS::RootedObject(cx, jsb_cocos2d_EventListener_prototype), jsb_cocos2d_EventListenerCustom_class, js_cocos2dx_EventListenerCustom_constructor, 0, // constructor properties, @@ -10790,22 +11173,22 @@ JSObject *jsb_cocos2d_EventFocus_prototype; bool js_cocos2dx_EventFocus_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::Widget* arg0; cocos2d::ui::Widget* arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -10823,13 +11206,16 @@ bool js_cocos2dx_EventFocus_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventFocus"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventFocus"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -10840,7 +11226,7 @@ void js_cocos2d_EventFocus_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EventFocus)", obj); } -void js_register_cocos2dx_EventFocus(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EventFocus(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EventFocus_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EventFocus_class->name = "EventFocus"; jsb_cocos2d_EventFocus_class->addProperty = JS_PropertyStub; @@ -10854,8 +11240,8 @@ void js_register_cocos2dx_EventFocus(JSContext *cx, JSObject *global) { jsb_cocos2d_EventFocus_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -10866,7 +11252,7 @@ void js_register_cocos2dx_EventFocus(JSContext *cx, JSObject *global) { jsb_cocos2d_EventFocus_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Event_prototype, + JS::RootedObject(cx, jsb_cocos2d_Event_prototype), jsb_cocos2d_EventFocus_class, js_cocos2dx_EventFocus_constructor, 0, // constructor properties, @@ -10897,7 +11283,8 @@ JSObject *jsb_cocos2d_EventListenerFocus_prototype; bool js_cocos2dx_EventListenerFocus_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventListenerFocus* cobj = (cocos2d::EventListenerFocus *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventListenerFocus_init : Invalid Native Object"); @@ -10905,36 +11292,16 @@ bool js_cocos2dx_EventListenerFocus_init(JSContext *cx, uint32_t argc, jsval *vp bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EventListenerFocus_init : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_EventListenerFocus_create(JSContext *cx, uint32_t argc, jsval *vp) -{ - if (argc == 0) { - cocos2d::EventListenerFocus* ret = cocos2d::EventListenerFocus::create(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::EventListenerFocus*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - JS_ReportError(cx, "js_cocos2dx_EventListenerFocus_create : wrong number of arguments"); - return false; -} - bool js_cocos2dx_EventListenerFocus_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EventListenerFocus* cobj = new (std::nothrow) cocos2d::EventListenerFocus(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10948,13 +11315,16 @@ bool js_cocos2dx_EventListenerFocus_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventListenerFocus"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventListenerFocus"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -10965,7 +11335,7 @@ void js_cocos2d_EventListenerFocus_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EventListenerFocus)", obj); } -void js_register_cocos2dx_EventListenerFocus(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EventListenerFocus(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EventListenerFocus_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EventListenerFocus_class->name = "EventListenerFocus"; jsb_cocos2d_EventListenerFocus_class->addProperty = JS_PropertyStub; @@ -10979,8 +11349,8 @@ void js_register_cocos2dx_EventListenerFocus(JSContext *cx, JSObject *global) { jsb_cocos2d_EventListenerFocus_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -10988,14 +11358,11 @@ void js_register_cocos2dx_EventListenerFocus(JSContext *cx, JSObject *global) { JS_FS_END }; - static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_EventListenerFocus_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; + JSFunctionSpec *st_funcs = NULL; jsb_cocos2d_EventListenerFocus_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EventListener_prototype, + JS::RootedObject(cx, jsb_cocos2d_EventListener_prototype), jsb_cocos2d_EventListenerFocus_class, js_cocos2dx_EventListenerFocus_constructor, 0, // constructor properties, @@ -11026,25 +11393,25 @@ JSObject *jsb_cocos2d_Action_prototype; bool js_cocos2dx_Action_startWithTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_startWithTarget : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Action_startWithTarget : Error processing arguments"); cobj->startWithTarget(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11053,25 +11420,25 @@ bool js_cocos2dx_Action_startWithTarget(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Action_setOriginalTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_setOriginalTarget : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Action_setOriginalTarget : Error processing arguments"); cobj->setOriginalTarget(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11080,7 +11447,8 @@ bool js_cocos2dx_Action_setOriginalTarget(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Action_clone(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_clone : Invalid Native Object"); @@ -11095,7 +11463,7 @@ bool js_cocos2dx_Action_clone(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11104,7 +11472,8 @@ bool js_cocos2dx_Action_clone(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Action_getOriginalTarget(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_getOriginalTarget : Invalid Native Object"); @@ -11119,7 +11488,7 @@ bool js_cocos2dx_Action_getOriginalTarget(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11128,13 +11497,14 @@ bool js_cocos2dx_Action_getOriginalTarget(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Action_stop(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_stop : Invalid Native Object"); if (argc == 0) { cobj->stop(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11143,18 +11513,18 @@ bool js_cocos2dx_Action_stop(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Action_update(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_update : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Action_update : Error processing arguments"); cobj->update(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11163,7 +11533,8 @@ bool js_cocos2dx_Action_update(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Action_getTarget(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_getTarget : Invalid Native Object"); @@ -11178,7 +11549,7 @@ bool js_cocos2dx_Action_getTarget(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11187,18 +11558,18 @@ bool js_cocos2dx_Action_getTarget(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Action_step(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_step : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Action_step : Error processing arguments"); cobj->step(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11207,18 +11578,18 @@ bool js_cocos2dx_Action_step(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Action_setTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_setTag : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Action_setTag : Error processing arguments"); cobj->setTag(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11227,7 +11598,8 @@ bool js_cocos2dx_Action_setTag(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Action_getTag(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_getTag : Invalid Native Object"); @@ -11235,7 +11607,7 @@ bool js_cocos2dx_Action_getTag(JSContext *cx, uint32_t argc, jsval *vp) int ret = cobj->getTag(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11244,25 +11616,25 @@ bool js_cocos2dx_Action_getTag(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Action_setTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_setTarget : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Action_setTarget : Error processing arguments"); cobj->setTarget(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11271,7 +11643,8 @@ bool js_cocos2dx_Action_setTarget(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Action_isDone(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_isDone : Invalid Native Object"); @@ -11279,7 +11652,7 @@ bool js_cocos2dx_Action_isDone(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isDone(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11288,7 +11661,8 @@ bool js_cocos2dx_Action_isDone(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Action_reverse(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_reverse : Invalid Native Object"); @@ -11303,7 +11677,7 @@ bool js_cocos2dx_Action_reverse(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11316,7 +11690,7 @@ void js_cocos2d_Action_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Action)", obj); } -void js_register_cocos2dx_Action(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Action(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Action_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Action_class->name = "Action"; jsb_cocos2d_Action_class->addProperty = JS_PropertyStub; @@ -11330,8 +11704,8 @@ void js_register_cocos2dx_Action(JSContext *cx, JSObject *global) { jsb_cocos2d_Action_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -11355,7 +11729,7 @@ void js_register_cocos2dx_Action(JSContext *cx, JSObject *global) { jsb_cocos2d_Action_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_Action_class, empty_constructor, 0, properties, @@ -11386,18 +11760,18 @@ JSObject *jsb_cocos2d_FiniteTimeAction_prototype; bool js_cocos2dx_FiniteTimeAction_setDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FiniteTimeAction* cobj = (cocos2d::FiniteTimeAction *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FiniteTimeAction_setDuration : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FiniteTimeAction_setDuration : Error processing arguments"); cobj->setDuration(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11406,7 +11780,8 @@ bool js_cocos2dx_FiniteTimeAction_setDuration(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_FiniteTimeAction_getDuration(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FiniteTimeAction* cobj = (cocos2d::FiniteTimeAction *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FiniteTimeAction_getDuration : Invalid Native Object"); @@ -11414,7 +11789,7 @@ bool js_cocos2dx_FiniteTimeAction_getDuration(JSContext *cx, uint32_t argc, jsva double ret = cobj->getDuration(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11428,7 +11803,7 @@ void js_cocos2d_FiniteTimeAction_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (FiniteTimeAction)", obj); } -void js_register_cocos2dx_FiniteTimeAction(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_FiniteTimeAction(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_FiniteTimeAction_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_FiniteTimeAction_class->name = "FiniteTimeAction"; jsb_cocos2d_FiniteTimeAction_class->addProperty = JS_PropertyStub; @@ -11442,8 +11817,8 @@ void js_register_cocos2dx_FiniteTimeAction(JSContext *cx, JSObject *global) { jsb_cocos2d_FiniteTimeAction_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -11456,7 +11831,7 @@ void js_register_cocos2dx_FiniteTimeAction(JSContext *cx, JSObject *global) { jsb_cocos2d_FiniteTimeAction_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Action_prototype, + JS::RootedObject(cx, jsb_cocos2d_Action_prototype), jsb_cocos2d_FiniteTimeAction_class, empty_constructor, 0, properties, @@ -11487,25 +11862,25 @@ JSObject *jsb_cocos2d_Speed_prototype; bool js_cocos2dx_Speed_setInnerAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Speed* cobj = (cocos2d::Speed *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Speed_setInnerAction : Invalid Native Object"); if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Speed_setInnerAction : Error processing arguments"); cobj->setInnerAction(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11514,7 +11889,8 @@ bool js_cocos2dx_Speed_setInnerAction(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Speed_getSpeed(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Speed* cobj = (cocos2d::Speed *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Speed_getSpeed : Invalid Native Object"); @@ -11522,7 +11898,7 @@ bool js_cocos2dx_Speed_getSpeed(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getSpeed(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11531,18 +11907,18 @@ bool js_cocos2dx_Speed_getSpeed(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Speed_setSpeed(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Speed* cobj = (cocos2d::Speed *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Speed_setSpeed : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Speed_setSpeed : Error processing arguments"); cobj->setSpeed(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11551,9 +11927,9 @@ bool js_cocos2dx_Speed_setSpeed(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Speed_initWithAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Speed* cobj = (cocos2d::Speed *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Speed_initWithAction : Invalid Native Object"); @@ -11561,19 +11937,19 @@ bool js_cocos2dx_Speed_initWithAction(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::ActionInterval* arg0; double arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Speed_initWithAction : Error processing arguments"); bool ret = cobj->initWithAction(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11582,7 +11958,8 @@ bool js_cocos2dx_Speed_initWithAction(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Speed_getInnerAction(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Speed* cobj = (cocos2d::Speed *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Speed_getInnerAction : Invalid Native Object"); @@ -11597,7 +11974,7 @@ bool js_cocos2dx_Speed_getInnerAction(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11606,20 +11983,20 @@ bool js_cocos2dx_Speed_getInnerAction(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Speed_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::ActionInterval* arg0; double arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Speed_create : Error processing arguments"); cocos2d::Speed* ret = cocos2d::Speed::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -11631,7 +12008,7 @@ bool js_cocos2dx_Speed_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Speed_create : wrong number of arguments"); @@ -11640,7 +12017,7 @@ bool js_cocos2dx_Speed_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Speed_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Speed* cobj = new (std::nothrow) cocos2d::Speed(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -11654,13 +12031,16 @@ bool js_cocos2dx_Speed_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Speed"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Speed"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -11671,7 +12051,7 @@ void js_cocos2d_Speed_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Speed)", obj); } -void js_register_cocos2dx_Speed(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Speed(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Speed_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Speed_class->name = "Speed"; jsb_cocos2d_Speed_class->addProperty = JS_PropertyStub; @@ -11685,8 +12065,8 @@ void js_register_cocos2dx_Speed(JSContext *cx, JSObject *global) { jsb_cocos2d_Speed_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -11705,7 +12085,7 @@ void js_register_cocos2dx_Speed(JSContext *cx, JSObject *global) { jsb_cocos2d_Speed_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Action_prototype, + JS::RootedObject(cx, jsb_cocos2d_Action_prototype), jsb_cocos2d_Speed_class, js_cocos2dx_Speed_constructor, 0, // constructor properties, @@ -11736,18 +12116,18 @@ JSObject *jsb_cocos2d_Follow_prototype; bool js_cocos2dx_Follow_setBoundarySet(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Follow* cobj = (cocos2d::Follow *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Follow_setBoundarySet : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Follow_setBoundarySet : Error processing arguments"); cobj->setBoundarySet(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11756,18 +12136,18 @@ bool js_cocos2dx_Follow_setBoundarySet(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Follow_initWithTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Follow* cobj = (cocos2d::Follow *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Follow_initWithTarget : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -11776,26 +12156,26 @@ bool js_cocos2dx_Follow_initWithTarget(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->initWithTarget(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { cocos2d::Node* arg0; cocos2d::Rect arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Follow_initWithTarget : Error processing arguments"); bool ret = cobj->initWithTarget(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11804,7 +12184,8 @@ bool js_cocos2dx_Follow_initWithTarget(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Follow_isBoundarySet(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Follow* cobj = (cocos2d::Follow *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Follow_isBoundarySet : Invalid Native Object"); @@ -11812,7 +12193,7 @@ bool js_cocos2dx_Follow_isBoundarySet(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isBoundarySet(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11821,14 +12202,14 @@ bool js_cocos2dx_Follow_isBoundarySet(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Follow_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -11844,21 +12225,21 @@ bool js_cocos2dx_Follow_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { cocos2d::Node* arg0; cocos2d::Rect arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Follow_create : Error processing arguments"); cocos2d::Follow* ret = cocos2d::Follow::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -11870,7 +12251,7 @@ bool js_cocos2dx_Follow_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Follow_create : wrong number of arguments"); @@ -11879,7 +12260,7 @@ bool js_cocos2dx_Follow_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Follow_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Follow* cobj = new (std::nothrow) cocos2d::Follow(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -11893,13 +12274,16 @@ bool js_cocos2dx_Follow_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Follow"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Follow"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -11910,7 +12294,7 @@ void js_cocos2d_Follow_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Follow)", obj); } -void js_register_cocos2dx_Follow(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Follow(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Follow_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Follow_class->name = "Follow"; jsb_cocos2d_Follow_class->addProperty = JS_PropertyStub; @@ -11924,8 +12308,8 @@ void js_register_cocos2dx_Follow(JSContext *cx, JSObject *global) { jsb_cocos2d_Follow_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -11942,7 +12326,7 @@ void js_register_cocos2dx_Follow(JSContext *cx, JSObject *global) { jsb_cocos2d_Follow_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Action_prototype, + JS::RootedObject(cx, jsb_cocos2d_Action_prototype), jsb_cocos2d_Follow_class, js_cocos2dx_Follow_constructor, 0, // constructor properties, @@ -11973,7 +12357,8 @@ JSObject *jsb_cocos2d_SpriteFrame_prototype; bool js_cocos2dx_SpriteFrame_clone(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_clone : Invalid Native Object"); @@ -11988,7 +12373,7 @@ bool js_cocos2dx_SpriteFrame_clone(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11997,18 +12382,18 @@ bool js_cocos2dx_SpriteFrame_clone(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_SpriteFrame_setRotated(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_setRotated : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrame_setRotated : Error processing arguments"); cobj->setRotated(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12017,25 +12402,25 @@ bool js_cocos2dx_SpriteFrame_setRotated(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_SpriteFrame_setTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_setTexture : Invalid Native Object"); if (argc == 1) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrame_setTexture : Error processing arguments"); cobj->setTexture(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12044,7 +12429,8 @@ bool js_cocos2dx_SpriteFrame_setTexture(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_SpriteFrame_getOffset(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_getOffset : Invalid Native Object"); @@ -12052,7 +12438,7 @@ bool js_cocos2dx_SpriteFrame_getOffset(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Vec2& ret = cobj->getOffset(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12061,18 +12447,18 @@ bool js_cocos2dx_SpriteFrame_getOffset(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_SpriteFrame_setRectInPixels(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_setRectInPixels : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrame_setRectInPixels : Error processing arguments"); cobj->setRectInPixels(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12081,7 +12467,8 @@ bool js_cocos2dx_SpriteFrame_setRectInPixels(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_SpriteFrame_getTexture(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_getTexture : Invalid Native Object"); @@ -12096,7 +12483,7 @@ bool js_cocos2dx_SpriteFrame_getTexture(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12105,7 +12492,8 @@ bool js_cocos2dx_SpriteFrame_getTexture(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_SpriteFrame_getRect(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_getRect : Invalid Native Object"); @@ -12113,7 +12501,7 @@ bool js_cocos2dx_SpriteFrame_getRect(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Rect& ret = cobj->getRect(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12122,18 +12510,18 @@ bool js_cocos2dx_SpriteFrame_getRect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_SpriteFrame_setOffsetInPixels(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_setOffsetInPixels : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrame_setOffsetInPixels : Error processing arguments"); cobj->setOffsetInPixels(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12142,7 +12530,8 @@ bool js_cocos2dx_SpriteFrame_setOffsetInPixels(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_SpriteFrame_getRectInPixels(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_getRectInPixels : Invalid Native Object"); @@ -12150,7 +12539,7 @@ bool js_cocos2dx_SpriteFrame_getRectInPixels(JSContext *cx, uint32_t argc, jsval const cocos2d::Rect& ret = cobj->getRectInPixels(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12159,18 +12548,18 @@ bool js_cocos2dx_SpriteFrame_getRectInPixels(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_SpriteFrame_setOriginalSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_setOriginalSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrame_setOriginalSize : Error processing arguments"); cobj->setOriginalSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12179,7 +12568,8 @@ bool js_cocos2dx_SpriteFrame_setOriginalSize(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_SpriteFrame_getOriginalSizeInPixels(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_getOriginalSizeInPixels : Invalid Native Object"); @@ -12187,7 +12577,7 @@ bool js_cocos2dx_SpriteFrame_getOriginalSizeInPixels(JSContext *cx, uint32_t arg const cocos2d::Size& ret = cobj->getOriginalSizeInPixels(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12196,18 +12586,18 @@ bool js_cocos2dx_SpriteFrame_getOriginalSizeInPixels(JSContext *cx, uint32_t arg } bool js_cocos2dx_SpriteFrame_setOriginalSizeInPixels(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_setOriginalSizeInPixels : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrame_setOriginalSizeInPixels : Error processing arguments"); cobj->setOriginalSizeInPixels(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12216,18 +12606,18 @@ bool js_cocos2dx_SpriteFrame_setOriginalSizeInPixels(JSContext *cx, uint32_t arg } bool js_cocos2dx_SpriteFrame_setOffset(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_setOffset : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrame_setOffset : Error processing arguments"); cobj->setOffset(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12236,12 +12626,12 @@ bool js_cocos2dx_SpriteFrame_setOffset(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_SpriteFrame_initWithTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::SpriteFrame* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_initWithTexture : Invalid Native Object"); @@ -12249,29 +12639,29 @@ bool js_cocos2dx_SpriteFrame_initWithTexture(JSContext *cx, uint32_t argc, jsval if (argc == 5) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(args.get(2)); cocos2d::Vec2 arg3; - ok &= jsval_to_vector2(cx, argv[3], &arg3); + ok &= jsval_to_vector2(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cocos2d::Size arg4; - ok &= jsval_to_ccsize(cx, argv[4], &arg4); + ok &= jsval_to_ccsize(cx, args.get(4), &arg4); if (!ok) { ok = true; break; } bool ret = cobj->initWithTexture(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -12280,21 +12670,21 @@ bool js_cocos2dx_SpriteFrame_initWithTexture(JSContext *cx, uint32_t argc, jsval if (argc == 2) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool ret = cobj->initWithTexture(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -12304,7 +12694,8 @@ bool js_cocos2dx_SpriteFrame_initWithTexture(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_SpriteFrame_isRotated(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_isRotated : Invalid Native Object"); @@ -12312,7 +12703,7 @@ bool js_cocos2dx_SpriteFrame_isRotated(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isRotated(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12321,35 +12712,35 @@ bool js_cocos2dx_SpriteFrame_isRotated(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_SpriteFrame_initWithTextureFilename(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::SpriteFrame* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_initWithTextureFilename : Invalid Native Object"); do { if (argc == 5) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(args.get(2)); cocos2d::Vec2 arg3; - ok &= jsval_to_vector2(cx, argv[3], &arg3); + ok &= jsval_to_vector2(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cocos2d::Size arg4; - ok &= jsval_to_ccsize(cx, argv[4], &arg4); + ok &= jsval_to_ccsize(cx, args.get(4), &arg4); if (!ok) { ok = true; break; } bool ret = cobj->initWithTextureFilename(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -12357,15 +12748,15 @@ bool js_cocos2dx_SpriteFrame_initWithTextureFilename(JSContext *cx, uint32_t arg do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool ret = cobj->initWithTextureFilename(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -12375,18 +12766,18 @@ bool js_cocos2dx_SpriteFrame_initWithTextureFilename(JSContext *cx, uint32_t arg } bool js_cocos2dx_SpriteFrame_setRect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_setRect : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrame_setRect : Error processing arguments"); cobj->setRect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12395,7 +12786,8 @@ bool js_cocos2dx_SpriteFrame_setRect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_SpriteFrame_getOffsetInPixels(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_getOffsetInPixels : Invalid Native Object"); @@ -12403,7 +12795,7 @@ bool js_cocos2dx_SpriteFrame_getOffsetInPixels(JSContext *cx, uint32_t argc, jsv const cocos2d::Vec2& ret = cobj->getOffsetInPixels(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12412,7 +12804,8 @@ bool js_cocos2dx_SpriteFrame_getOffsetInPixels(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_SpriteFrame_getOriginalSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrame* cobj = (cocos2d::SpriteFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrame_getOriginalSize : Invalid Native Object"); @@ -12420,7 +12813,7 @@ bool js_cocos2dx_SpriteFrame_getOriginalSize(JSContext *cx, uint32_t argc, jsval const cocos2d::Size& ret = cobj->getOriginalSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12429,25 +12822,25 @@ bool js_cocos2dx_SpriteFrame_getOriginalSize(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_SpriteFrame_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 5) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(args.get(2)); if (!ok) { ok = true; break; } cocos2d::Vec2 arg3; - ok &= jsval_to_vector2(cx, argv[3], &arg3); + ok &= jsval_to_vector2(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cocos2d::Size arg4; - ok &= jsval_to_ccsize(cx, argv[4], &arg4); + ok &= jsval_to_ccsize(cx, args.get(4), &arg4); if (!ok) { ok = true; break; } cocos2d::SpriteFrame* ret = cocos2d::SpriteFrame::create(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; @@ -12459,7 +12852,7 @@ bool js_cocos2dx_SpriteFrame_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -12467,10 +12860,10 @@ bool js_cocos2dx_SpriteFrame_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::SpriteFrame* ret = cocos2d::SpriteFrame::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -12482,7 +12875,7 @@ bool js_cocos2dx_SpriteFrame_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -12491,32 +12884,32 @@ bool js_cocos2dx_SpriteFrame_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_SpriteFrame_createWithTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 5) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(args.get(2)); if (!ok) { ok = true; break; } cocos2d::Vec2 arg3; - ok &= jsval_to_vector2(cx, argv[3], &arg3); + ok &= jsval_to_vector2(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cocos2d::Size arg4; - ok &= jsval_to_ccsize(cx, argv[4], &arg4); + ok &= jsval_to_ccsize(cx, args.get(4), &arg4); if (!ok) { ok = true; break; } cocos2d::SpriteFrame* ret = cocos2d::SpriteFrame::createWithTexture(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; @@ -12528,7 +12921,7 @@ bool js_cocos2dx_SpriteFrame_createWithTexture(JSContext *cx, uint32_t argc, jsv jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -12537,16 +12930,16 @@ bool js_cocos2dx_SpriteFrame_createWithTexture(JSContext *cx, uint32_t argc, jsv if (argc == 2) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::SpriteFrame* ret = cocos2d::SpriteFrame::createWithTexture(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -12558,7 +12951,7 @@ bool js_cocos2dx_SpriteFrame_createWithTexture(JSContext *cx, uint32_t argc, jsv jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -12567,7 +12960,7 @@ bool js_cocos2dx_SpriteFrame_createWithTexture(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_SpriteFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::SpriteFrame* cobj = new (std::nothrow) cocos2d::SpriteFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -12581,13 +12974,16 @@ bool js_cocos2dx_SpriteFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::SpriteFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::SpriteFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -12599,21 +12995,21 @@ void js_cocos2d_SpriteFrame_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_SpriteFrame_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::SpriteFrame *nobj = new (std::nothrow) cocos2d::SpriteFrame(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::SpriteFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::SpriteFrame"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_SpriteFrame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_SpriteFrame(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_SpriteFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_SpriteFrame_class->name = "SpriteFrame"; jsb_cocos2d_SpriteFrame_class->addProperty = JS_PropertyStub; @@ -12627,8 +13023,8 @@ void js_register_cocos2dx_SpriteFrame(JSContext *cx, JSObject *global) { jsb_cocos2d_SpriteFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -12663,7 +13059,7 @@ void js_register_cocos2dx_SpriteFrame(JSContext *cx, JSObject *global) { jsb_cocos2d_SpriteFrame_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_SpriteFrame_class, js_cocos2dx_SpriteFrame_constructor, 0, // constructor properties, @@ -12694,25 +13090,25 @@ JSObject *jsb_cocos2d_AnimationFrame_prototype; bool js_cocos2dx_AnimationFrame_setSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AnimationFrame* cobj = (cocos2d::AnimationFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AnimationFrame_setSpriteFrame : Invalid Native Object"); if (argc == 1) { cocos2d::SpriteFrame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AnimationFrame_setSpriteFrame : Error processing arguments"); cobj->setSpriteFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12721,12 +13117,12 @@ bool js_cocos2dx_AnimationFrame_setSpriteFrame(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_AnimationFrame_getUserInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::AnimationFrame* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::AnimationFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AnimationFrame_getUserInfo : Invalid Native Object"); @@ -12735,7 +13131,7 @@ bool js_cocos2dx_AnimationFrame_getUserInfo(JSContext *cx, uint32_t argc, jsval cocos2d::ValueMap& ret = cobj->getUserInfo(); jsval jsret = JSVAL_NULL; jsret = ccvaluemap_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -12745,7 +13141,7 @@ bool js_cocos2dx_AnimationFrame_getUserInfo(JSContext *cx, uint32_t argc, jsval const cocos2d::ValueMap& ret = cobj->getUserInfo(); jsval jsret = JSVAL_NULL; jsret = ccvaluemap_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -12755,18 +13151,18 @@ bool js_cocos2dx_AnimationFrame_getUserInfo(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_AnimationFrame_setDelayUnits(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AnimationFrame* cobj = (cocos2d::AnimationFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AnimationFrame_setDelayUnits : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AnimationFrame_setDelayUnits : Error processing arguments"); cobj->setDelayUnits(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12775,7 +13171,8 @@ bool js_cocos2dx_AnimationFrame_setDelayUnits(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_AnimationFrame_clone(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AnimationFrame* cobj = (cocos2d::AnimationFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AnimationFrame_clone : Invalid Native Object"); @@ -12790,7 +13187,7 @@ bool js_cocos2dx_AnimationFrame_clone(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12799,7 +13196,8 @@ bool js_cocos2dx_AnimationFrame_clone(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_AnimationFrame_getSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AnimationFrame* cobj = (cocos2d::AnimationFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AnimationFrame_getSpriteFrame : Invalid Native Object"); @@ -12814,7 +13212,7 @@ bool js_cocos2dx_AnimationFrame_getSpriteFrame(JSContext *cx, uint32_t argc, jsv jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12823,7 +13221,8 @@ bool js_cocos2dx_AnimationFrame_getSpriteFrame(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_AnimationFrame_getDelayUnits(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AnimationFrame* cobj = (cocos2d::AnimationFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AnimationFrame_getDelayUnits : Invalid Native Object"); @@ -12831,7 +13230,7 @@ bool js_cocos2dx_AnimationFrame_getDelayUnits(JSContext *cx, uint32_t argc, jsva double ret = cobj->getDelayUnits(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12840,18 +13239,18 @@ bool js_cocos2dx_AnimationFrame_getDelayUnits(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_AnimationFrame_setUserInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AnimationFrame* cobj = (cocos2d::AnimationFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AnimationFrame_setUserInfo : Invalid Native Object"); if (argc == 1) { cocos2d::ValueMap arg0; - ok &= jsval_to_ccvaluemap(cx, argv[0], &arg0); + ok &= jsval_to_ccvaluemap(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AnimationFrame_setUserInfo : Error processing arguments"); cobj->setUserInfo(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12860,9 +13259,9 @@ bool js_cocos2dx_AnimationFrame_setUserInfo(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_AnimationFrame_initWithSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AnimationFrame* cobj = (cocos2d::AnimationFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AnimationFrame_initWithSpriteFrame : Invalid Native Object"); @@ -12871,20 +13270,20 @@ bool js_cocos2dx_AnimationFrame_initWithSpriteFrame(JSContext *cx, uint32_t argc double arg1; cocos2d::ValueMap arg2; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= jsval_to_ccvaluemap(cx, argv[2], &arg2); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= jsval_to_ccvaluemap(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AnimationFrame_initWithSpriteFrame : Error processing arguments"); bool ret = cobj->initWithSpriteFrame(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12893,22 +13292,22 @@ bool js_cocos2dx_AnimationFrame_initWithSpriteFrame(JSContext *cx, uint32_t argc } bool js_cocos2dx_AnimationFrame_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 3) { cocos2d::SpriteFrame* arg0; double arg1; cocos2d::ValueMap arg2; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= jsval_to_ccvaluemap(cx, argv[2], &arg2); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= jsval_to_ccvaluemap(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AnimationFrame_create : Error processing arguments"); cocos2d::AnimationFrame* ret = cocos2d::AnimationFrame::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -12920,7 +13319,7 @@ bool js_cocos2dx_AnimationFrame_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_AnimationFrame_create : wrong number of arguments"); @@ -12929,7 +13328,7 @@ bool js_cocos2dx_AnimationFrame_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_AnimationFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::AnimationFrame* cobj = new (std::nothrow) cocos2d::AnimationFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -12943,13 +13342,16 @@ bool js_cocos2dx_AnimationFrame_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::AnimationFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::AnimationFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -12959,7 +13361,7 @@ void js_cocos2d_AnimationFrame_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (AnimationFrame)", obj); } -void js_register_cocos2dx_AnimationFrame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_AnimationFrame(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_AnimationFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_AnimationFrame_class->name = "AnimationFrame"; jsb_cocos2d_AnimationFrame_class->addProperty = JS_PropertyStub; @@ -12973,8 +13375,8 @@ void js_register_cocos2dx_AnimationFrame(JSContext *cx, JSObject *global) { jsb_cocos2d_AnimationFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -12996,7 +13398,7 @@ void js_register_cocos2dx_AnimationFrame(JSContext *cx, JSObject *global) { jsb_cocos2d_AnimationFrame_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_AnimationFrame_class, js_cocos2dx_AnimationFrame_constructor, 0, // constructor properties, @@ -13027,7 +13429,8 @@ JSObject *jsb_cocos2d_Animation_prototype; bool js_cocos2dx_Animation_getLoops(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_getLoops : Invalid Native Object"); @@ -13035,7 +13438,7 @@ bool js_cocos2dx_Animation_getLoops(JSContext *cx, uint32_t argc, jsval *vp) unsigned int ret = cobj->getLoops(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13044,25 +13447,25 @@ bool js_cocos2dx_Animation_getLoops(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Animation_addSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_addSpriteFrame : Invalid Native Object"); if (argc == 1) { cocos2d::SpriteFrame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animation_addSpriteFrame : Error processing arguments"); cobj->addSpriteFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13071,18 +13474,18 @@ bool js_cocos2dx_Animation_addSpriteFrame(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Animation_setRestoreOriginalFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_setRestoreOriginalFrame : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animation_setRestoreOriginalFrame : Error processing arguments"); cobj->setRestoreOriginalFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13091,7 +13494,8 @@ bool js_cocos2dx_Animation_setRestoreOriginalFrame(JSContext *cx, uint32_t argc, } bool js_cocos2dx_Animation_clone(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_clone : Invalid Native Object"); @@ -13106,7 +13510,7 @@ bool js_cocos2dx_Animation_clone(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13115,7 +13519,8 @@ bool js_cocos2dx_Animation_clone(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Animation_getDuration(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_getDuration : Invalid Native Object"); @@ -13123,7 +13528,7 @@ bool js_cocos2dx_Animation_getDuration(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getDuration(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13132,9 +13537,9 @@ bool js_cocos2dx_Animation_getDuration(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Animation_initWithAnimationFrames(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_initWithAnimationFrames : Invalid Native Object"); @@ -13142,14 +13547,14 @@ bool js_cocos2dx_Animation_initWithAnimationFrames(JSContext *cx, uint32_t argc, cocos2d::Vector arg0; double arg1; unsigned int arg2; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animation_initWithAnimationFrames : Error processing arguments"); bool ret = cobj->initWithAnimationFrames(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13158,7 +13563,8 @@ bool js_cocos2dx_Animation_initWithAnimationFrames(JSContext *cx, uint32_t argc, } bool js_cocos2dx_Animation_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_init : Invalid Native Object"); @@ -13166,7 +13572,7 @@ bool js_cocos2dx_Animation_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13175,18 +13581,18 @@ bool js_cocos2dx_Animation_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Animation_setFrames(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_setFrames : Invalid Native Object"); if (argc == 1) { cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animation_setFrames : Error processing arguments"); cobj->setFrames(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13195,7 +13601,8 @@ bool js_cocos2dx_Animation_setFrames(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Animation_getFrames(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_getFrames : Invalid Native Object"); @@ -13203,7 +13610,7 @@ bool js_cocos2dx_Animation_getFrames(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Vector& ret = cobj->getFrames(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13212,18 +13619,18 @@ bool js_cocos2dx_Animation_getFrames(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Animation_setLoops(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_setLoops : Invalid Native Object"); if (argc == 1) { unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animation_setLoops : Error processing arguments"); cobj->setLoops(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13232,18 +13639,18 @@ bool js_cocos2dx_Animation_setLoops(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Animation_setDelayPerUnit(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_setDelayPerUnit : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animation_setDelayPerUnit : Error processing arguments"); cobj->setDelayPerUnit(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13252,18 +13659,18 @@ bool js_cocos2dx_Animation_setDelayPerUnit(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Animation_addSpriteFrameWithFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_addSpriteFrameWithFile : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animation_addSpriteFrameWithFile : Error processing arguments"); cobj->addSpriteFrameWithFile(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13272,7 +13679,8 @@ bool js_cocos2dx_Animation_addSpriteFrameWithFile(JSContext *cx, uint32_t argc, } bool js_cocos2dx_Animation_getTotalDelayUnits(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_getTotalDelayUnits : Invalid Native Object"); @@ -13280,7 +13688,7 @@ bool js_cocos2dx_Animation_getTotalDelayUnits(JSContext *cx, uint32_t argc, jsva double ret = cobj->getTotalDelayUnits(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13289,7 +13697,8 @@ bool js_cocos2dx_Animation_getTotalDelayUnits(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_Animation_getDelayPerUnit(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_getDelayPerUnit : Invalid Native Object"); @@ -13297,7 +13706,7 @@ bool js_cocos2dx_Animation_getDelayPerUnit(JSContext *cx, uint32_t argc, jsval * double ret = cobj->getDelayPerUnit(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13306,46 +13715,46 @@ bool js_cocos2dx_Animation_getDelayPerUnit(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Animation_initWithSpriteFrames(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_initWithSpriteFrames : Invalid Native Object"); if (argc == 1) { cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animation_initWithSpriteFrames : Error processing arguments"); bool ret = cobj->initWithSpriteFrames(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { cocos2d::Vector arg0; double arg1; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animation_initWithSpriteFrames : Error processing arguments"); bool ret = cobj->initWithSpriteFrames(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 3) { cocos2d::Vector arg0; double arg1; unsigned int arg2; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animation_initWithSpriteFrames : Error processing arguments"); bool ret = cobj->initWithSpriteFrames(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13354,7 +13763,8 @@ bool js_cocos2dx_Animation_initWithSpriteFrames(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_Animation_getRestoreOriginalFrame(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_getRestoreOriginalFrame : Invalid Native Object"); @@ -13362,7 +13772,7 @@ bool js_cocos2dx_Animation_getRestoreOriginalFrame(JSContext *cx, uint32_t argc, bool ret = cobj->getRestoreOriginalFrame(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13371,9 +13781,9 @@ bool js_cocos2dx_Animation_getRestoreOriginalFrame(JSContext *cx, uint32_t argc, } bool js_cocos2dx_Animation_addSpriteFrameWithTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animation* cobj = (cocos2d::Animation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animation_addSpriteFrameWithTexture : Invalid Native Object"); @@ -13381,17 +13791,17 @@ bool js_cocos2dx_Animation_addSpriteFrameWithTexture(JSContext *cx, uint32_t arg cocos2d::Texture2D* arg0; cocos2d::Rect arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animation_addSpriteFrameWithTexture : Error processing arguments"); cobj->addSpriteFrameWithTexture(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13400,16 +13810,16 @@ bool js_cocos2dx_Animation_addSpriteFrameWithTexture(JSContext *cx, uint32_t arg } bool js_cocos2dx_Animation_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 2) { cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } cocos2d::Animation* ret = cocos2d::Animation::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -13421,20 +13831,20 @@ bool js_cocos2dx_Animation_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 3) { cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } unsigned int arg2; - ok &= jsval_to_uint32(cx, argv[2], &arg2); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } cocos2d::Animation* ret = cocos2d::Animation::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -13446,7 +13856,7 @@ bool js_cocos2dx_Animation_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -13463,7 +13873,7 @@ bool js_cocos2dx_Animation_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -13472,11 +13882,11 @@ bool js_cocos2dx_Animation_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Animation_createWithSpriteFrames(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animation_createWithSpriteFrames : Error processing arguments"); cocos2d::Animation* ret = cocos2d::Animation::createWithSpriteFrames(arg0); jsval jsret = JSVAL_NULL; @@ -13488,14 +13898,14 @@ bool js_cocos2dx_Animation_createWithSpriteFrames(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { cocos2d::Vector arg0; double arg1; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animation_createWithSpriteFrames : Error processing arguments"); cocos2d::Animation* ret = cocos2d::Animation::createWithSpriteFrames(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -13507,16 +13917,16 @@ bool js_cocos2dx_Animation_createWithSpriteFrames(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 3) { cocos2d::Vector arg0; double arg1; unsigned int arg2; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animation_createWithSpriteFrames : Error processing arguments"); cocos2d::Animation* ret = cocos2d::Animation::createWithSpriteFrames(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -13528,7 +13938,7 @@ bool js_cocos2dx_Animation_createWithSpriteFrames(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Animation_createWithSpriteFrames : wrong number of arguments"); @@ -13537,7 +13947,7 @@ bool js_cocos2dx_Animation_createWithSpriteFrames(JSContext *cx, uint32_t argc, bool js_cocos2dx_Animation_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Animation* cobj = new (std::nothrow) cocos2d::Animation(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -13551,13 +13961,16 @@ bool js_cocos2dx_Animation_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Animation"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Animation"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -13567,7 +13980,7 @@ void js_cocos2d_Animation_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Animation)", obj); } -void js_register_cocos2dx_Animation(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Animation(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Animation_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Animation_class->name = "Animation"; jsb_cocos2d_Animation_class->addProperty = JS_PropertyStub; @@ -13581,8 +13994,8 @@ void js_register_cocos2dx_Animation(JSContext *cx, JSObject *global) { jsb_cocos2d_Animation_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -13614,7 +14027,7 @@ void js_register_cocos2dx_Animation(JSContext *cx, JSObject *global) { jsb_cocos2d_Animation_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_Animation_class, js_cocos2dx_Animation_constructor, 0, // constructor properties, @@ -13645,7 +14058,8 @@ JSObject *jsb_cocos2d_ActionInterval_prototype; bool js_cocos2dx_ActionInterval_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionInterval* cobj = (cocos2d::ActionInterval *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionInterval_getAmplitudeRate : Invalid Native Object"); @@ -13653,7 +14067,7 @@ bool js_cocos2dx_ActionInterval_getAmplitudeRate(JSContext *cx, uint32_t argc, j double ret = cobj->getAmplitudeRate(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13662,20 +14076,20 @@ bool js_cocos2dx_ActionInterval_getAmplitudeRate(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ActionInterval_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionInterval* cobj = (cocos2d::ActionInterval *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionInterval_initWithDuration : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionInterval_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13684,18 +14098,18 @@ bool js_cocos2dx_ActionInterval_initWithDuration(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ActionInterval_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionInterval* cobj = (cocos2d::ActionInterval *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionInterval_setAmplitudeRate : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionInterval_setAmplitudeRate : Error processing arguments"); cobj->setAmplitudeRate(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13704,7 +14118,8 @@ bool js_cocos2dx_ActionInterval_setAmplitudeRate(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ActionInterval_getElapsed(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionInterval* cobj = (cocos2d::ActionInterval *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionInterval_getElapsed : Invalid Native Object"); @@ -13712,7 +14127,7 @@ bool js_cocos2dx_ActionInterval_getElapsed(JSContext *cx, uint32_t argc, jsval * double ret = cobj->getElapsed(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13726,7 +14141,7 @@ void js_cocos2d_ActionInterval_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ActionInterval)", obj); } -void js_register_cocos2dx_ActionInterval(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ActionInterval(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ActionInterval_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ActionInterval_class->name = "ActionInterval"; jsb_cocos2d_ActionInterval_class->addProperty = JS_PropertyStub; @@ -13740,8 +14155,8 @@ void js_register_cocos2dx_ActionInterval(JSContext *cx, JSObject *global) { jsb_cocos2d_ActionInterval_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -13756,7 +14171,7 @@ void js_register_cocos2dx_ActionInterval(JSContext *cx, JSObject *global) { jsb_cocos2d_ActionInterval_prototype = JS_InitClass( cx, global, - jsb_cocos2d_FiniteTimeAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_FiniteTimeAction_prototype), jsb_cocos2d_ActionInterval_class, empty_constructor, 0, properties, @@ -13787,9 +14202,9 @@ JSObject *jsb_cocos2d_Sequence_prototype; bool js_cocos2dx_Sequence_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sequence* cobj = (cocos2d::Sequence *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sequence_initWithTwoActions : Invalid Native Object"); @@ -13797,17 +14212,17 @@ bool js_cocos2dx_Sequence_initWithTwoActions(JSContext *cx, uint32_t argc, jsval cocos2d::FiniteTimeAction* arg0; cocos2d::FiniteTimeAction* arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -13816,7 +14231,7 @@ bool js_cocos2dx_Sequence_initWithTwoActions(JSContext *cx, uint32_t argc, jsval bool ret = cobj->initWithTwoActions(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13825,7 +14240,7 @@ bool js_cocos2dx_Sequence_initWithTwoActions(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Sequence_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Sequence* cobj = new (std::nothrow) cocos2d::Sequence(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -13839,13 +14254,16 @@ bool js_cocos2dx_Sequence_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Sequence"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Sequence"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -13856,7 +14274,7 @@ void js_cocos2d_Sequence_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Sequence)", obj); } -void js_register_cocos2dx_Sequence(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Sequence(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Sequence_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Sequence_class->name = "Sequence"; jsb_cocos2d_Sequence_class->addProperty = JS_PropertyStub; @@ -13870,8 +14288,8 @@ void js_register_cocos2dx_Sequence(JSContext *cx, JSObject *global) { jsb_cocos2d_Sequence_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -13883,7 +14301,7 @@ void js_register_cocos2dx_Sequence(JSContext *cx, JSObject *global) { jsb_cocos2d_Sequence_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_Sequence_class, js_cocos2dx_Sequence_constructor, 0, // constructor properties, @@ -13914,25 +14332,25 @@ JSObject *jsb_cocos2d_Repeat_prototype; bool js_cocos2dx_Repeat_setInnerAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Repeat* cobj = (cocos2d::Repeat *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Repeat_setInnerAction : Invalid Native Object"); if (argc == 1) { cocos2d::FiniteTimeAction* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Repeat_setInnerAction : Error processing arguments"); cobj->setInnerAction(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13941,9 +14359,9 @@ bool js_cocos2dx_Repeat_setInnerAction(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Repeat_initWithAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Repeat* cobj = (cocos2d::Repeat *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Repeat_initWithAction : Invalid Native Object"); @@ -13951,19 +14369,19 @@ bool js_cocos2dx_Repeat_initWithAction(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::FiniteTimeAction* arg0; unsigned int arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Repeat_initWithAction : Error processing arguments"); bool ret = cobj->initWithAction(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13972,7 +14390,8 @@ bool js_cocos2dx_Repeat_initWithAction(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Repeat_getInnerAction(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Repeat* cobj = (cocos2d::Repeat *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Repeat_getInnerAction : Invalid Native Object"); @@ -13987,7 +14406,7 @@ bool js_cocos2dx_Repeat_getInnerAction(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13996,20 +14415,20 @@ bool js_cocos2dx_Repeat_getInnerAction(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Repeat_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::FiniteTimeAction* arg0; unsigned int arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Repeat_create : Error processing arguments"); cocos2d::Repeat* ret = cocos2d::Repeat::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -14021,7 +14440,7 @@ bool js_cocos2dx_Repeat_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Repeat_create : wrong number of arguments"); @@ -14030,7 +14449,7 @@ bool js_cocos2dx_Repeat_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Repeat_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Repeat* cobj = new (std::nothrow) cocos2d::Repeat(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -14044,13 +14463,16 @@ bool js_cocos2dx_Repeat_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Repeat"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Repeat"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -14061,7 +14483,7 @@ void js_cocos2d_Repeat_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Repeat)", obj); } -void js_register_cocos2dx_Repeat(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Repeat(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Repeat_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Repeat_class->name = "Repeat"; jsb_cocos2d_Repeat_class->addProperty = JS_PropertyStub; @@ -14075,8 +14497,8 @@ void js_register_cocos2dx_Repeat(JSContext *cx, JSObject *global) { jsb_cocos2d_Repeat_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -14093,7 +14515,7 @@ void js_register_cocos2dx_Repeat(JSContext *cx, JSObject *global) { jsb_cocos2d_Repeat_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_Repeat_class, js_cocos2dx_Repeat_constructor, 0, // constructor properties, @@ -14124,25 +14546,25 @@ JSObject *jsb_cocos2d_RepeatForever_prototype; bool js_cocos2dx_RepeatForever_setInnerAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RepeatForever* cobj = (cocos2d::RepeatForever *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RepeatForever_setInnerAction : Invalid Native Object"); if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RepeatForever_setInnerAction : Error processing arguments"); cobj->setInnerAction(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14151,18 +14573,18 @@ bool js_cocos2dx_RepeatForever_setInnerAction(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_RepeatForever_initWithAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RepeatForever* cobj = (cocos2d::RepeatForever *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RepeatForever_initWithAction : Invalid Native Object"); if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -14171,7 +14593,7 @@ bool js_cocos2dx_RepeatForever_initWithAction(JSContext *cx, uint32_t argc, jsva bool ret = cobj->initWithAction(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14180,7 +14602,8 @@ bool js_cocos2dx_RepeatForever_initWithAction(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_RepeatForever_getInnerAction(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RepeatForever* cobj = (cocos2d::RepeatForever *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RepeatForever_getInnerAction : Invalid Native Object"); @@ -14195,7 +14618,7 @@ bool js_cocos2dx_RepeatForever_getInnerAction(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14204,14 +14627,14 @@ bool js_cocos2dx_RepeatForever_getInnerAction(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_RepeatForever_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -14227,7 +14650,7 @@ bool js_cocos2dx_RepeatForever_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_RepeatForever_create : wrong number of arguments"); @@ -14236,7 +14659,7 @@ bool js_cocos2dx_RepeatForever_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_RepeatForever_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::RepeatForever* cobj = new (std::nothrow) cocos2d::RepeatForever(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -14250,13 +14673,16 @@ bool js_cocos2dx_RepeatForever_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::RepeatForever"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::RepeatForever"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -14267,7 +14693,7 @@ void js_cocos2d_RepeatForever_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (RepeatForever)", obj); } -void js_register_cocos2dx_RepeatForever(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_RepeatForever(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_RepeatForever_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_RepeatForever_class->name = "RepeatForever"; jsb_cocos2d_RepeatForever_class->addProperty = JS_PropertyStub; @@ -14281,8 +14707,8 @@ void js_register_cocos2dx_RepeatForever(JSContext *cx, JSObject *global) { jsb_cocos2d_RepeatForever_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -14299,7 +14725,7 @@ void js_register_cocos2dx_RepeatForever(JSContext *cx, JSObject *global) { jsb_cocos2d_RepeatForever_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_RepeatForever_class, js_cocos2dx_RepeatForever_constructor, 0, // constructor properties, @@ -14330,9 +14756,9 @@ JSObject *jsb_cocos2d_Spawn_prototype; bool js_cocos2dx_Spawn_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Spawn* cobj = (cocos2d::Spawn *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Spawn_initWithTwoActions : Invalid Native Object"); @@ -14340,17 +14766,17 @@ bool js_cocos2dx_Spawn_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *v cocos2d::FiniteTimeAction* arg0; cocos2d::FiniteTimeAction* arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -14359,7 +14785,7 @@ bool js_cocos2dx_Spawn_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *v bool ret = cobj->initWithTwoActions(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14368,7 +14794,7 @@ bool js_cocos2dx_Spawn_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Spawn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Spawn* cobj = new (std::nothrow) cocos2d::Spawn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -14382,13 +14808,16 @@ bool js_cocos2dx_Spawn_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Spawn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Spawn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -14399,7 +14828,7 @@ void js_cocos2d_Spawn_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Spawn)", obj); } -void js_register_cocos2dx_Spawn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Spawn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Spawn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Spawn_class->name = "Spawn"; jsb_cocos2d_Spawn_class->addProperty = JS_PropertyStub; @@ -14413,8 +14842,8 @@ void js_register_cocos2dx_Spawn(JSContext *cx, JSObject *global) { jsb_cocos2d_Spawn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -14426,7 +14855,7 @@ void js_register_cocos2dx_Spawn(JSContext *cx, JSObject *global) { jsb_cocos2d_Spawn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_Spawn_class, js_cocos2dx_Spawn_constructor, 0, // constructor properties, @@ -14457,27 +14886,27 @@ JSObject *jsb_cocos2d_RotateTo_prototype; bool js_cocos2dx_RotateTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::RotateTo* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::RotateTo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RotateTo_initWithDuration : Invalid Native Object"); do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Vec3 arg1; - ok &= jsval_to_vector3(cx, argv[1], &arg1); + ok &= jsval_to_vector3(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool ret = cobj->initWithDuration(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -14485,18 +14914,18 @@ bool js_cocos2dx_RotateTo_initWithDuration(JSContext *cx, uint32_t argc, jsval * do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } bool ret = cobj->initWithDuration(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -14506,16 +14935,16 @@ bool js_cocos2dx_RotateTo_initWithDuration(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_RotateTo_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } cocos2d::RotateTo* ret = cocos2d::RotateTo::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -14527,7 +14956,7 @@ bool js_cocos2dx_RotateTo_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -14535,13 +14964,13 @@ bool js_cocos2dx_RotateTo_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::RotateTo* ret = cocos2d::RotateTo::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -14553,7 +14982,7 @@ bool js_cocos2dx_RotateTo_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -14561,10 +14990,10 @@ bool js_cocos2dx_RotateTo_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Vec3 arg1; - ok &= jsval_to_vector3(cx, argv[1], &arg1); + ok &= jsval_to_vector3(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::RotateTo* ret = cocos2d::RotateTo::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -14576,7 +15005,7 @@ bool js_cocos2dx_RotateTo_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -14585,7 +15014,7 @@ bool js_cocos2dx_RotateTo_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_RotateTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::RotateTo* cobj = new (std::nothrow) cocos2d::RotateTo(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -14599,13 +15028,16 @@ bool js_cocos2dx_RotateTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::RotateTo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::RotateTo"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -14616,7 +15048,7 @@ void js_cocos2d_RotateTo_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (RotateTo)", obj); } -void js_register_cocos2dx_RotateTo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_RotateTo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_RotateTo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_RotateTo_class->name = "RotateTo"; jsb_cocos2d_RotateTo_class->addProperty = JS_PropertyStub; @@ -14630,8 +15062,8 @@ void js_register_cocos2dx_RotateTo(JSContext *cx, JSObject *global) { jsb_cocos2d_RotateTo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -14646,7 +15078,7 @@ void js_register_cocos2dx_RotateTo(JSContext *cx, JSObject *global) { jsb_cocos2d_RotateTo_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_RotateTo_class, js_cocos2dx_RotateTo_constructor, 0, // constructor properties, @@ -14677,30 +15109,30 @@ JSObject *jsb_cocos2d_RotateBy_prototype; bool js_cocos2dx_RotateBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::RotateBy* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::RotateBy *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RotateBy_initWithDuration : Invalid Native Object"); do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } bool ret = cobj->initWithDuration(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -14708,15 +15140,15 @@ bool js_cocos2dx_RotateBy_initWithDuration(JSContext *cx, uint32_t argc, jsval * do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } bool ret = cobj->initWithDuration(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -14724,15 +15156,15 @@ bool js_cocos2dx_RotateBy_initWithDuration(JSContext *cx, uint32_t argc, jsval * do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Vec3 arg1; - ok &= jsval_to_vector3(cx, argv[1], &arg1); + ok &= jsval_to_vector3(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool ret = cobj->initWithDuration(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -14742,19 +15174,19 @@ bool js_cocos2dx_RotateBy_initWithDuration(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_RotateBy_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::RotateBy* ret = cocos2d::RotateBy::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -14766,7 +15198,7 @@ bool js_cocos2dx_RotateBy_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -14774,10 +15206,10 @@ bool js_cocos2dx_RotateBy_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } cocos2d::RotateBy* ret = cocos2d::RotateBy::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -14789,7 +15221,7 @@ bool js_cocos2dx_RotateBy_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -14797,10 +15229,10 @@ bool js_cocos2dx_RotateBy_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Vec3 arg1; - ok &= jsval_to_vector3(cx, argv[1], &arg1); + ok &= jsval_to_vector3(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::RotateBy* ret = cocos2d::RotateBy::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -14812,7 +15244,7 @@ bool js_cocos2dx_RotateBy_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -14821,7 +15253,7 @@ bool js_cocos2dx_RotateBy_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_RotateBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::RotateBy* cobj = new (std::nothrow) cocos2d::RotateBy(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -14835,13 +15267,16 @@ bool js_cocos2dx_RotateBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::RotateBy"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::RotateBy"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -14852,7 +15287,7 @@ void js_cocos2d_RotateBy_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (RotateBy)", obj); } -void js_register_cocos2dx_RotateBy(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_RotateBy(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_RotateBy_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_RotateBy_class->name = "RotateBy"; jsb_cocos2d_RotateBy_class->addProperty = JS_PropertyStub; @@ -14866,8 +15301,8 @@ void js_register_cocos2dx_RotateBy(JSContext *cx, JSObject *global) { jsb_cocos2d_RotateBy_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -14882,7 +15317,7 @@ void js_register_cocos2dx_RotateBy(JSContext *cx, JSObject *global) { jsb_cocos2d_RotateBy_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_RotateBy_class, js_cocos2dx_RotateBy_constructor, 0, // constructor properties, @@ -14913,58 +15348,106 @@ JSObject *jsb_cocos2d_MoveBy_prototype; bool js_cocos2dx_MoveBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + + JS::RootedObject obj(cx); + cocos2d::MoveBy* cobj = NULL; + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::MoveBy* cobj = (cocos2d::MoveBy *)(proxy ? proxy->ptr : NULL); + cobj = (cocos2d::MoveBy *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MoveBy_initWithDuration : Invalid Native Object"); - if (argc == 2) { - double arg0; - cocos2d::Vec2 arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MoveBy_initWithDuration : Error processing arguments"); - bool ret = cobj->initWithDuration(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } + do { + if (argc == 2) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + if (!ok) { ok = true; break; } + cocos2d::Vec3 arg1; + ok &= jsval_to_vector3(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithDuration(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); - JS_ReportError(cx, "js_cocos2dx_MoveBy_initWithDuration : wrong number of arguments: %d, was expecting %d", argc, 2); + do { + if (argc == 2) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + if (!ok) { ok = true; break; } + cocos2d::Vec2 arg1; + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithDuration(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_MoveBy_initWithDuration : wrong number of arguments"); return false; } bool js_cocos2dx_MoveBy_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - if (argc == 2) { - double arg0; - cocos2d::Vec2 arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MoveBy_create : Error processing arguments"); - cocos2d::MoveBy* ret = cocos2d::MoveBy::create(arg0, arg1); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::MoveBy*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; + + do { + if (argc == 2) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + if (!ok) { ok = true; break; } + cocos2d::Vec3 arg1; + ok &= jsval_to_vector3(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::MoveBy* ret = cocos2d::MoveBy::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::MoveBy*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 2) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + if (!ok) { ok = true; break; } + cocos2d::Vec2 arg1; + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::MoveBy* ret = cocos2d::MoveBy::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::MoveBy*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; } } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } JS_ReportError(cx, "js_cocos2dx_MoveBy_create : wrong number of arguments"); return false; } - bool js_cocos2dx_MoveBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::MoveBy* cobj = new (std::nothrow) cocos2d::MoveBy(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -14978,13 +15461,16 @@ bool js_cocos2dx_MoveBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MoveBy"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MoveBy"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -14995,7 +15481,7 @@ void js_cocos2d_MoveBy_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (MoveBy)", obj); } -void js_register_cocos2dx_MoveBy(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_MoveBy(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_MoveBy_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_MoveBy_class->name = "MoveBy"; jsb_cocos2d_MoveBy_class->addProperty = JS_PropertyStub; @@ -15009,8 +15495,8 @@ void js_register_cocos2dx_MoveBy(JSContext *cx, JSObject *global) { jsb_cocos2d_MoveBy_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -15025,7 +15511,7 @@ void js_register_cocos2dx_MoveBy(JSContext *cx, JSObject *global) { jsb_cocos2d_MoveBy_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_MoveBy_class, js_cocos2dx_MoveBy_constructor, 0, // constructor properties, @@ -15056,58 +15542,106 @@ JSObject *jsb_cocos2d_MoveTo_prototype; bool js_cocos2dx_MoveTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + + JS::RootedObject obj(cx); + cocos2d::MoveTo* cobj = NULL; + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::MoveTo* cobj = (cocos2d::MoveTo *)(proxy ? proxy->ptr : NULL); + cobj = (cocos2d::MoveTo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MoveTo_initWithDuration : Invalid Native Object"); - if (argc == 2) { - double arg0; - cocos2d::Vec2 arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MoveTo_initWithDuration : Error processing arguments"); - bool ret = cobj->initWithDuration(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } + do { + if (argc == 2) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + if (!ok) { ok = true; break; } + cocos2d::Vec3 arg1; + ok &= jsval_to_vector3(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithDuration(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); - JS_ReportError(cx, "js_cocos2dx_MoveTo_initWithDuration : wrong number of arguments: %d, was expecting %d", argc, 2); + do { + if (argc == 2) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + if (!ok) { ok = true; break; } + cocos2d::Vec2 arg1; + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithDuration(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_MoveTo_initWithDuration : wrong number of arguments"); return false; } bool js_cocos2dx_MoveTo_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - if (argc == 2) { - double arg0; - cocos2d::Vec2 arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MoveTo_create : Error processing arguments"); - cocos2d::MoveTo* ret = cocos2d::MoveTo::create(arg0, arg1); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::MoveTo*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; + + do { + if (argc == 2) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + if (!ok) { ok = true; break; } + cocos2d::Vec3 arg1; + ok &= jsval_to_vector3(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::MoveTo* ret = cocos2d::MoveTo::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::MoveTo*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 2) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + if (!ok) { ok = true; break; } + cocos2d::Vec2 arg1; + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::MoveTo* ret = cocos2d::MoveTo::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::MoveTo*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; } } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } JS_ReportError(cx, "js_cocos2dx_MoveTo_create : wrong number of arguments"); return false; } - bool js_cocos2dx_MoveTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::MoveTo* cobj = new (std::nothrow) cocos2d::MoveTo(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -15121,13 +15655,16 @@ bool js_cocos2dx_MoveTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MoveTo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MoveTo"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -15138,7 +15675,7 @@ void js_cocos2d_MoveTo_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (MoveTo)", obj); } -void js_register_cocos2dx_MoveTo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_MoveTo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_MoveTo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_MoveTo_class->name = "MoveTo"; jsb_cocos2d_MoveTo_class->addProperty = JS_PropertyStub; @@ -15152,8 +15689,8 @@ void js_register_cocos2dx_MoveTo(JSContext *cx, JSObject *global) { jsb_cocos2d_MoveTo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -15168,7 +15705,7 @@ void js_register_cocos2dx_MoveTo(JSContext *cx, JSObject *global) { jsb_cocos2d_MoveTo_prototype = JS_InitClass( cx, global, - jsb_cocos2d_MoveBy_prototype, + JS::RootedObject(cx, jsb_cocos2d_MoveBy_prototype), jsb_cocos2d_MoveTo_class, js_cocos2dx_MoveTo_constructor, 0, // constructor properties, @@ -15199,9 +15736,9 @@ JSObject *jsb_cocos2d_SkewTo_prototype; bool js_cocos2dx_SkewTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SkewTo* cobj = (cocos2d::SkewTo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SkewTo_initWithDuration : Invalid Native Object"); @@ -15209,14 +15746,14 @@ bool js_cocos2dx_SkewTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp double arg0; double arg1; double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SkewTo_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -15225,15 +15762,15 @@ bool js_cocos2dx_SkewTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_SkewTo_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 3) { double arg0; double arg1; double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SkewTo_create : Error processing arguments"); cocos2d::SkewTo* ret = cocos2d::SkewTo::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -15245,7 +15782,7 @@ bool js_cocos2dx_SkewTo_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_SkewTo_create : wrong number of arguments"); @@ -15254,7 +15791,7 @@ bool js_cocos2dx_SkewTo_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_SkewTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::SkewTo* cobj = new (std::nothrow) cocos2d::SkewTo(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -15268,13 +15805,16 @@ bool js_cocos2dx_SkewTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::SkewTo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::SkewTo"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -15285,7 +15825,7 @@ void js_cocos2d_SkewTo_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (SkewTo)", obj); } -void js_register_cocos2dx_SkewTo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_SkewTo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_SkewTo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_SkewTo_class->name = "SkewTo"; jsb_cocos2d_SkewTo_class->addProperty = JS_PropertyStub; @@ -15299,8 +15839,8 @@ void js_register_cocos2dx_SkewTo(JSContext *cx, JSObject *global) { jsb_cocos2d_SkewTo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -15315,7 +15855,7 @@ void js_register_cocos2dx_SkewTo(JSContext *cx, JSObject *global) { jsb_cocos2d_SkewTo_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_SkewTo_class, js_cocos2dx_SkewTo_constructor, 0, // constructor properties, @@ -15346,9 +15886,9 @@ JSObject *jsb_cocos2d_SkewBy_prototype; bool js_cocos2dx_SkewBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SkewBy* cobj = (cocos2d::SkewBy *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SkewBy_initWithDuration : Invalid Native Object"); @@ -15356,14 +15896,14 @@ bool js_cocos2dx_SkewBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp double arg0; double arg1; double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SkewBy_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -15372,15 +15912,15 @@ bool js_cocos2dx_SkewBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_SkewBy_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 3) { double arg0; double arg1; double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SkewBy_create : Error processing arguments"); cocos2d::SkewBy* ret = cocos2d::SkewBy::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -15392,7 +15932,7 @@ bool js_cocos2dx_SkewBy_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_SkewBy_create : wrong number of arguments"); @@ -15401,7 +15941,7 @@ bool js_cocos2dx_SkewBy_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_SkewBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::SkewBy* cobj = new (std::nothrow) cocos2d::SkewBy(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -15415,13 +15955,16 @@ bool js_cocos2dx_SkewBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::SkewBy"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::SkewBy"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -15432,7 +15975,7 @@ void js_cocos2d_SkewBy_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (SkewBy)", obj); } -void js_register_cocos2dx_SkewBy(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_SkewBy(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_SkewBy_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_SkewBy_class->name = "SkewBy"; jsb_cocos2d_SkewBy_class->addProperty = JS_PropertyStub; @@ -15446,8 +15989,8 @@ void js_register_cocos2dx_SkewBy(JSContext *cx, JSObject *global) { jsb_cocos2d_SkewBy_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -15462,7 +16005,7 @@ void js_register_cocos2dx_SkewBy(JSContext *cx, JSObject *global) { jsb_cocos2d_SkewBy_prototype = JS_InitClass( cx, global, - jsb_cocos2d_SkewTo_prototype, + JS::RootedObject(cx, jsb_cocos2d_SkewTo_prototype), jsb_cocos2d_SkewBy_class, js_cocos2dx_SkewBy_constructor, 0, // constructor properties, @@ -15493,9 +16036,9 @@ JSObject *jsb_cocos2d_JumpBy_prototype; bool js_cocos2dx_JumpBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::JumpBy* cobj = (cocos2d::JumpBy *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_JumpBy_initWithDuration : Invalid Native Object"); @@ -15504,15 +16047,15 @@ bool js_cocos2dx_JumpBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp cocos2d::Vec2 arg1; double arg2; int arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_JumpBy_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -15521,17 +16064,17 @@ bool js_cocos2dx_JumpBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_JumpBy_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { double arg0; cocos2d::Vec2 arg1; double arg2; int arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_JumpBy_create : Error processing arguments"); cocos2d::JumpBy* ret = cocos2d::JumpBy::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -15543,7 +16086,7 @@ bool js_cocos2dx_JumpBy_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_JumpBy_create : wrong number of arguments"); @@ -15552,7 +16095,7 @@ bool js_cocos2dx_JumpBy_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_JumpBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::JumpBy* cobj = new (std::nothrow) cocos2d::JumpBy(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -15566,13 +16109,16 @@ bool js_cocos2dx_JumpBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::JumpBy"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::JumpBy"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -15583,7 +16129,7 @@ void js_cocos2d_JumpBy_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (JumpBy)", obj); } -void js_register_cocos2dx_JumpBy(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_JumpBy(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_JumpBy_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_JumpBy_class->name = "JumpBy"; jsb_cocos2d_JumpBy_class->addProperty = JS_PropertyStub; @@ -15597,8 +16143,8 @@ void js_register_cocos2dx_JumpBy(JSContext *cx, JSObject *global) { jsb_cocos2d_JumpBy_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -15613,7 +16159,7 @@ void js_register_cocos2dx_JumpBy(JSContext *cx, JSObject *global) { jsb_cocos2d_JumpBy_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_JumpBy_class, js_cocos2dx_JumpBy_constructor, 0, // constructor properties, @@ -15642,19 +16188,47 @@ void js_register_cocos2dx_JumpBy(JSContext *cx, JSObject *global) { JSClass *jsb_cocos2d_JumpTo_class; JSObject *jsb_cocos2d_JumpTo_prototype; +bool js_cocos2dx_JumpTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::JumpTo* cobj = (cocos2d::JumpTo *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_JumpTo_initWithDuration : Invalid Native Object"); + if (argc == 4) { + double arg0; + cocos2d::Vec2 arg1; + double arg2; + int arg3; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_JumpTo_initWithDuration : Error processing arguments"); + bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_JumpTo_initWithDuration : wrong number of arguments: %d, was expecting %d", argc, 4); + return false; +} bool js_cocos2dx_JumpTo_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { double arg0; cocos2d::Vec2 arg1; double arg2; int arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_JumpTo_create : Error processing arguments"); cocos2d::JumpTo* ret = cocos2d::JumpTo::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -15666,7 +16240,7 @@ bool js_cocos2dx_JumpTo_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_JumpTo_create : wrong number of arguments"); @@ -15675,7 +16249,7 @@ bool js_cocos2dx_JumpTo_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_JumpTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::JumpTo* cobj = new (std::nothrow) cocos2d::JumpTo(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -15689,13 +16263,16 @@ bool js_cocos2dx_JumpTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::JumpTo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::JumpTo"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -15706,7 +16283,7 @@ void js_cocos2d_JumpTo_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (JumpTo)", obj); } -void js_register_cocos2dx_JumpTo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_JumpTo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_JumpTo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_JumpTo_class->name = "JumpTo"; jsb_cocos2d_JumpTo_class->addProperty = JS_PropertyStub; @@ -15720,11 +16297,12 @@ void js_register_cocos2dx_JumpTo(JSContext *cx, JSObject *global) { jsb_cocos2d_JumpTo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { + JS_FN("initWithDuration", js_cocos2dx_JumpTo_initWithDuration, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -15735,7 +16313,7 @@ void js_register_cocos2dx_JumpTo(JSContext *cx, JSObject *global) { jsb_cocos2d_JumpTo_prototype = JS_InitClass( cx, global, - jsb_cocos2d_JumpBy_prototype, + JS::RootedObject(cx, jsb_cocos2d_JumpBy_prototype), jsb_cocos2d_JumpTo_class, js_cocos2dx_JumpTo_constructor, 0, // constructor properties, @@ -15766,7 +16344,7 @@ JSObject *jsb_cocos2d_BezierBy_prototype; bool js_cocos2dx_BezierBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::BezierBy* cobj = new (std::nothrow) cocos2d::BezierBy(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -15780,13 +16358,16 @@ bool js_cocos2dx_BezierBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::BezierBy"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::BezierBy"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -15797,7 +16378,7 @@ void js_cocos2d_BezierBy_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (BezierBy)", obj); } -void js_register_cocos2dx_BezierBy(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_BezierBy(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_BezierBy_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_BezierBy_class->name = "BezierBy"; jsb_cocos2d_BezierBy_class->addProperty = JS_PropertyStub; @@ -15811,8 +16392,8 @@ void js_register_cocos2dx_BezierBy(JSContext *cx, JSObject *global) { jsb_cocos2d_BezierBy_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -15823,7 +16404,7 @@ void js_register_cocos2dx_BezierBy(JSContext *cx, JSObject *global) { jsb_cocos2d_BezierBy_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_BezierBy_class, js_cocos2dx_BezierBy_constructor, 0, // constructor properties, @@ -15854,7 +16435,7 @@ JSObject *jsb_cocos2d_BezierTo_prototype; bool js_cocos2dx_BezierTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::BezierTo* cobj = new (std::nothrow) cocos2d::BezierTo(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -15868,13 +16449,16 @@ bool js_cocos2dx_BezierTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::BezierTo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::BezierTo"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -15885,7 +16469,7 @@ void js_cocos2d_BezierTo_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (BezierTo)", obj); } -void js_register_cocos2dx_BezierTo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_BezierTo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_BezierTo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_BezierTo_class->name = "BezierTo"; jsb_cocos2d_BezierTo_class->addProperty = JS_PropertyStub; @@ -15899,8 +16483,8 @@ void js_register_cocos2dx_BezierTo(JSContext *cx, JSObject *global) { jsb_cocos2d_BezierTo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -15911,7 +16495,7 @@ void js_register_cocos2dx_BezierTo(JSContext *cx, JSObject *global) { jsb_cocos2d_BezierTo_prototype = JS_InitClass( cx, global, - jsb_cocos2d_BezierBy_prototype, + JS::RootedObject(cx, jsb_cocos2d_BezierBy_prototype), jsb_cocos2d_BezierTo_class, js_cocos2dx_BezierTo_constructor, 0, // constructor properties, @@ -15942,30 +16526,30 @@ JSObject *jsb_cocos2d_ScaleTo_prototype; bool js_cocos2dx_ScaleTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::ScaleTo* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::ScaleTo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ScaleTo_initWithDuration : Invalid Native Object"); do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } bool ret = cobj->initWithDuration(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -15973,15 +16557,15 @@ bool js_cocos2dx_ScaleTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *v do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } bool ret = cobj->initWithDuration(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -15989,21 +16573,21 @@ bool js_cocos2dx_ScaleTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *v do { if (argc == 4) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); if (!ok) { ok = true; break; } bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -16013,19 +16597,19 @@ bool js_cocos2dx_ScaleTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ScaleTo_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::ScaleTo* ret = cocos2d::ScaleTo::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -16037,7 +16621,7 @@ bool js_cocos2dx_ScaleTo_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -16045,10 +16629,10 @@ bool js_cocos2dx_ScaleTo_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } cocos2d::ScaleTo* ret = cocos2d::ScaleTo::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -16060,7 +16644,7 @@ bool js_cocos2dx_ScaleTo_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -16068,16 +16652,16 @@ bool js_cocos2dx_ScaleTo_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 4) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); if (!ok) { ok = true; break; } cocos2d::ScaleTo* ret = cocos2d::ScaleTo::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -16089,7 +16673,7 @@ bool js_cocos2dx_ScaleTo_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -16098,7 +16682,7 @@ bool js_cocos2dx_ScaleTo_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ScaleTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ScaleTo* cobj = new (std::nothrow) cocos2d::ScaleTo(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -16112,13 +16696,16 @@ bool js_cocos2dx_ScaleTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ScaleTo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ScaleTo"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -16129,7 +16716,7 @@ void js_cocos2d_ScaleTo_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ScaleTo)", obj); } -void js_register_cocos2dx_ScaleTo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ScaleTo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ScaleTo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ScaleTo_class->name = "ScaleTo"; jsb_cocos2d_ScaleTo_class->addProperty = JS_PropertyStub; @@ -16143,8 +16730,8 @@ void js_register_cocos2dx_ScaleTo(JSContext *cx, JSObject *global) { jsb_cocos2d_ScaleTo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -16159,7 +16746,7 @@ void js_register_cocos2dx_ScaleTo(JSContext *cx, JSObject *global) { jsb_cocos2d_ScaleTo_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_ScaleTo_class, js_cocos2dx_ScaleTo_constructor, 0, // constructor properties, @@ -16190,19 +16777,19 @@ JSObject *jsb_cocos2d_ScaleBy_prototype; bool js_cocos2dx_ScaleBy_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::ScaleBy* ret = cocos2d::ScaleBy::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -16214,7 +16801,7 @@ bool js_cocos2dx_ScaleBy_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -16222,10 +16809,10 @@ bool js_cocos2dx_ScaleBy_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } cocos2d::ScaleBy* ret = cocos2d::ScaleBy::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -16237,7 +16824,7 @@ bool js_cocos2dx_ScaleBy_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -16245,16 +16832,16 @@ bool js_cocos2dx_ScaleBy_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 4) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); if (!ok) { ok = true; break; } cocos2d::ScaleBy* ret = cocos2d::ScaleBy::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -16266,7 +16853,7 @@ bool js_cocos2dx_ScaleBy_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -16275,7 +16862,7 @@ bool js_cocos2dx_ScaleBy_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ScaleBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ScaleBy* cobj = new (std::nothrow) cocos2d::ScaleBy(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -16289,13 +16876,16 @@ bool js_cocos2dx_ScaleBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ScaleBy"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ScaleBy"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -16306,7 +16896,7 @@ void js_cocos2d_ScaleBy_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ScaleBy)", obj); } -void js_register_cocos2dx_ScaleBy(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ScaleBy(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ScaleBy_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ScaleBy_class->name = "ScaleBy"; jsb_cocos2d_ScaleBy_class->addProperty = JS_PropertyStub; @@ -16320,8 +16910,8 @@ void js_register_cocos2dx_ScaleBy(JSContext *cx, JSObject *global) { jsb_cocos2d_ScaleBy_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -16335,7 +16925,7 @@ void js_register_cocos2dx_ScaleBy(JSContext *cx, JSObject *global) { jsb_cocos2d_ScaleBy_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ScaleTo_prototype, + JS::RootedObject(cx, jsb_cocos2d_ScaleTo_prototype), jsb_cocos2d_ScaleBy_class, js_cocos2dx_ScaleBy_constructor, 0, // constructor properties, @@ -16366,22 +16956,22 @@ JSObject *jsb_cocos2d_Blink_prototype; bool js_cocos2dx_Blink_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Blink* cobj = (cocos2d::Blink *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Blink_initWithDuration : Invalid Native Object"); if (argc == 2) { double arg0; int arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Blink_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -16390,13 +16980,13 @@ bool js_cocos2dx_Blink_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Blink_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; int arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Blink_create : Error processing arguments"); cocos2d::Blink* ret = cocos2d::Blink::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -16408,7 +16998,7 @@ bool js_cocos2dx_Blink_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Blink_create : wrong number of arguments"); @@ -16417,7 +17007,7 @@ bool js_cocos2dx_Blink_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Blink_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Blink* cobj = new (std::nothrow) cocos2d::Blink(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -16431,13 +17021,16 @@ bool js_cocos2dx_Blink_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Blink"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Blink"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -16448,7 +17041,7 @@ void js_cocos2d_Blink_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Blink)", obj); } -void js_register_cocos2dx_Blink(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Blink(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Blink_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Blink_class->name = "Blink"; jsb_cocos2d_Blink_class->addProperty = JS_PropertyStub; @@ -16462,8 +17055,8 @@ void js_register_cocos2dx_Blink(JSContext *cx, JSObject *global) { jsb_cocos2d_Blink_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -16478,7 +17071,7 @@ void js_register_cocos2dx_Blink(JSContext *cx, JSObject *global) { jsb_cocos2d_Blink_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_Blink_class, js_cocos2dx_Blink_constructor, 0, // constructor properties, @@ -16509,22 +17102,22 @@ JSObject *jsb_cocos2d_FadeTo_prototype; bool js_cocos2dx_FadeTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FadeTo* cobj = (cocos2d::FadeTo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FadeTo_initWithDuration : Invalid Native Object"); if (argc == 2) { double arg0; uint16_t arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_uint16(cx, argv[1], &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_uint16(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeTo_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -16533,13 +17126,13 @@ bool js_cocos2dx_FadeTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_FadeTo_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; uint16_t arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_uint16(cx, argv[1], &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_uint16(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeTo_create : Error processing arguments"); cocos2d::FadeTo* ret = cocos2d::FadeTo::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -16551,7 +17144,7 @@ bool js_cocos2dx_FadeTo_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FadeTo_create : wrong number of arguments"); @@ -16560,7 +17153,7 @@ bool js_cocos2dx_FadeTo_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_FadeTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::FadeTo* cobj = new (std::nothrow) cocos2d::FadeTo(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -16574,13 +17167,16 @@ bool js_cocos2dx_FadeTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::FadeTo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::FadeTo"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -16591,7 +17187,7 @@ void js_cocos2d_FadeTo_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (FadeTo)", obj); } -void js_register_cocos2dx_FadeTo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_FadeTo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_FadeTo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_FadeTo_class->name = "FadeTo"; jsb_cocos2d_FadeTo_class->addProperty = JS_PropertyStub; @@ -16605,8 +17201,8 @@ void js_register_cocos2dx_FadeTo(JSContext *cx, JSObject *global) { jsb_cocos2d_FadeTo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -16621,7 +17217,7 @@ void js_register_cocos2dx_FadeTo(JSContext *cx, JSObject *global) { jsb_cocos2d_FadeTo_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_FadeTo_class, js_cocos2dx_FadeTo_constructor, 0, // constructor properties, @@ -16652,25 +17248,25 @@ JSObject *jsb_cocos2d_FadeIn_prototype; bool js_cocos2dx_FadeIn_setReverseAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FadeIn* cobj = (cocos2d::FadeIn *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FadeIn_setReverseAction : Invalid Native Object"); if (argc == 1) { cocos2d::FadeTo* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::FadeTo*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeIn_setReverseAction : Error processing arguments"); cobj->setReverseAction(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -16679,11 +17275,11 @@ bool js_cocos2dx_FadeIn_setReverseAction(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_FadeIn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeIn_create : Error processing arguments"); cocos2d::FadeIn* ret = cocos2d::FadeIn::create(arg0); jsval jsret = JSVAL_NULL; @@ -16695,7 +17291,7 @@ bool js_cocos2dx_FadeIn_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FadeIn_create : wrong number of arguments"); @@ -16704,7 +17300,7 @@ bool js_cocos2dx_FadeIn_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_FadeIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::FadeIn* cobj = new (std::nothrow) cocos2d::FadeIn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -16718,13 +17314,16 @@ bool js_cocos2dx_FadeIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::FadeIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::FadeIn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -16735,7 +17334,7 @@ void js_cocos2d_FadeIn_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (FadeIn)", obj); } -void js_register_cocos2dx_FadeIn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_FadeIn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_FadeIn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_FadeIn_class->name = "FadeIn"; jsb_cocos2d_FadeIn_class->addProperty = JS_PropertyStub; @@ -16749,8 +17348,8 @@ void js_register_cocos2dx_FadeIn(JSContext *cx, JSObject *global) { jsb_cocos2d_FadeIn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -16765,7 +17364,7 @@ void js_register_cocos2dx_FadeIn(JSContext *cx, JSObject *global) { jsb_cocos2d_FadeIn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_FadeTo_prototype, + JS::RootedObject(cx, jsb_cocos2d_FadeTo_prototype), jsb_cocos2d_FadeIn_class, js_cocos2dx_FadeIn_constructor, 0, // constructor properties, @@ -16796,25 +17395,25 @@ JSObject *jsb_cocos2d_FadeOut_prototype; bool js_cocos2dx_FadeOut_setReverseAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FadeOut* cobj = (cocos2d::FadeOut *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FadeOut_setReverseAction : Invalid Native Object"); if (argc == 1) { cocos2d::FadeTo* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::FadeTo*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeOut_setReverseAction : Error processing arguments"); cobj->setReverseAction(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -16823,11 +17422,11 @@ bool js_cocos2dx_FadeOut_setReverseAction(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_FadeOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeOut_create : Error processing arguments"); cocos2d::FadeOut* ret = cocos2d::FadeOut::create(arg0); jsval jsret = JSVAL_NULL; @@ -16839,7 +17438,7 @@ bool js_cocos2dx_FadeOut_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FadeOut_create : wrong number of arguments"); @@ -16848,7 +17447,7 @@ bool js_cocos2dx_FadeOut_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_FadeOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::FadeOut* cobj = new (std::nothrow) cocos2d::FadeOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -16862,13 +17461,16 @@ bool js_cocos2dx_FadeOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::FadeOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::FadeOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -16879,7 +17481,7 @@ void js_cocos2d_FadeOut_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (FadeOut)", obj); } -void js_register_cocos2dx_FadeOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_FadeOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_FadeOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_FadeOut_class->name = "FadeOut"; jsb_cocos2d_FadeOut_class->addProperty = JS_PropertyStub; @@ -16893,8 +17495,8 @@ void js_register_cocos2dx_FadeOut(JSContext *cx, JSObject *global) { jsb_cocos2d_FadeOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -16909,7 +17511,7 @@ void js_register_cocos2dx_FadeOut(JSContext *cx, JSObject *global) { jsb_cocos2d_FadeOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_FadeTo_prototype, + JS::RootedObject(cx, jsb_cocos2d_FadeTo_prototype), jsb_cocos2d_FadeOut_class, js_cocos2dx_FadeOut_constructor, 0, // constructor properties, @@ -16940,9 +17542,9 @@ JSObject *jsb_cocos2d_TintTo_prototype; bool js_cocos2dx_TintTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TintTo* cobj = (cocos2d::TintTo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TintTo_initWithDuration : Invalid Native Object"); @@ -16951,15 +17553,15 @@ bool js_cocos2dx_TintTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp uint16_t arg1; uint16_t arg2; uint16_t arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_uint16(cx, argv[1], &arg1); - ok &= jsval_to_uint16(cx, argv[2], &arg2); - ok &= jsval_to_uint16(cx, argv[3], &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_uint16(cx, args.get(1), &arg1); + ok &= jsval_to_uint16(cx, args.get(2), &arg2); + ok &= jsval_to_uint16(cx, args.get(3), &arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TintTo_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -16968,38 +17570,66 @@ bool js_cocos2dx_TintTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TintTo_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - if (argc == 4) { - double arg0; - uint16_t arg1; - uint16_t arg2; - uint16_t arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_uint16(cx, argv[1], &arg1); - ok &= jsval_to_uint16(cx, argv[2], &arg2); - ok &= jsval_to_uint16(cx, argv[3], &arg3); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TintTo_create : Error processing arguments"); - cocos2d::TintTo* ret = cocos2d::TintTo::create(arg0, arg1, arg2, arg3); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::TintTo*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; + + do { + if (argc == 2) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + if (!ok) { ok = true; break; } + cocos2d::Color3B arg1; + ok &= jsval_to_cccolor3b(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::TintTo* ret = cocos2d::TintTo::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::TintTo*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 4) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + if (!ok) { ok = true; break; } + uint16_t arg1; + ok &= jsval_to_uint16(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + uint16_t arg2; + ok &= jsval_to_uint16(cx, args.get(2), &arg2); + if (!ok) { ok = true; break; } + uint16_t arg3; + ok &= jsval_to_uint16(cx, args.get(3), &arg3); + if (!ok) { ok = true; break; } + cocos2d::TintTo* ret = cocos2d::TintTo::create(arg0, arg1, arg2, arg3); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::TintTo*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; } } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } JS_ReportError(cx, "js_cocos2dx_TintTo_create : wrong number of arguments"); return false; } - bool js_cocos2dx_TintTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TintTo* cobj = new (std::nothrow) cocos2d::TintTo(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -17013,13 +17643,16 @@ bool js_cocos2dx_TintTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TintTo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TintTo"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -17030,7 +17663,7 @@ void js_cocos2d_TintTo_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TintTo)", obj); } -void js_register_cocos2dx_TintTo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TintTo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TintTo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TintTo_class->name = "TintTo"; jsb_cocos2d_TintTo_class->addProperty = JS_PropertyStub; @@ -17044,8 +17677,8 @@ void js_register_cocos2dx_TintTo(JSContext *cx, JSObject *global) { jsb_cocos2d_TintTo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -17054,13 +17687,13 @@ void js_register_cocos2dx_TintTo(JSContext *cx, JSObject *global) { }; static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_TintTo_create, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("create", js_cocos2dx_TintTo_create, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; jsb_cocos2d_TintTo_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_TintTo_class, js_cocos2dx_TintTo_constructor, 0, // constructor properties, @@ -17091,9 +17724,9 @@ JSObject *jsb_cocos2d_TintBy_prototype; bool js_cocos2dx_TintBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TintBy* cobj = (cocos2d::TintBy *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TintBy_initWithDuration : Invalid Native Object"); @@ -17102,15 +17735,15 @@ bool js_cocos2dx_TintBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp int32_t arg1; int32_t arg2; int32_t arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_int32(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], &arg2); - ok &= jsval_to_int32(cx, argv[3], &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_int32(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), &arg2); + ok &= jsval_to_int32(cx, args.get(3), &arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TintBy_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -17119,17 +17752,17 @@ bool js_cocos2dx_TintBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TintBy_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { double arg0; int32_t arg1; int32_t arg2; int32_t arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_int32(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], &arg2); - ok &= jsval_to_int32(cx, argv[3], &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_int32(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), &arg2); + ok &= jsval_to_int32(cx, args.get(3), &arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TintBy_create : Error processing arguments"); cocos2d::TintBy* ret = cocos2d::TintBy::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -17141,7 +17774,7 @@ bool js_cocos2dx_TintBy_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TintBy_create : wrong number of arguments"); @@ -17150,7 +17783,7 @@ bool js_cocos2dx_TintBy_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_TintBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TintBy* cobj = new (std::nothrow) cocos2d::TintBy(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -17164,13 +17797,16 @@ bool js_cocos2dx_TintBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TintBy"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TintBy"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -17181,7 +17817,7 @@ void js_cocos2d_TintBy_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TintBy)", obj); } -void js_register_cocos2dx_TintBy(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TintBy(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TintBy_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TintBy_class->name = "TintBy"; jsb_cocos2d_TintBy_class->addProperty = JS_PropertyStub; @@ -17195,8 +17831,8 @@ void js_register_cocos2dx_TintBy(JSContext *cx, JSObject *global) { jsb_cocos2d_TintBy_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -17211,7 +17847,7 @@ void js_register_cocos2dx_TintBy(JSContext *cx, JSObject *global) { jsb_cocos2d_TintBy_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_TintBy_class, js_cocos2dx_TintBy_constructor, 0, // constructor properties, @@ -17242,11 +17878,11 @@ JSObject *jsb_cocos2d_DelayTime_prototype; bool js_cocos2dx_DelayTime_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DelayTime_create : Error processing arguments"); cocos2d::DelayTime* ret = cocos2d::DelayTime::create(arg0); jsval jsret = JSVAL_NULL; @@ -17258,7 +17894,7 @@ bool js_cocos2dx_DelayTime_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_DelayTime_create : wrong number of arguments"); @@ -17267,7 +17903,7 @@ bool js_cocos2dx_DelayTime_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_DelayTime_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::DelayTime* cobj = new (std::nothrow) cocos2d::DelayTime(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -17281,13 +17917,16 @@ bool js_cocos2dx_DelayTime_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::DelayTime"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::DelayTime"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -17298,7 +17937,7 @@ void js_cocos2d_DelayTime_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (DelayTime)", obj); } -void js_register_cocos2dx_DelayTime(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_DelayTime(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_DelayTime_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_DelayTime_class->name = "DelayTime"; jsb_cocos2d_DelayTime_class->addProperty = JS_PropertyStub; @@ -17312,8 +17951,8 @@ void js_register_cocos2dx_DelayTime(JSContext *cx, JSObject *global) { jsb_cocos2d_DelayTime_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -17327,7 +17966,7 @@ void js_register_cocos2dx_DelayTime(JSContext *cx, JSObject *global) { jsb_cocos2d_DelayTime_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_DelayTime_class, js_cocos2dx_DelayTime_constructor, 0, // constructor properties, @@ -17358,18 +17997,18 @@ JSObject *jsb_cocos2d_ReverseTime_prototype; bool js_cocos2dx_ReverseTime_initWithAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ReverseTime* cobj = (cocos2d::ReverseTime *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ReverseTime_initWithAction : Invalid Native Object"); if (argc == 1) { cocos2d::FiniteTimeAction* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -17378,7 +18017,7 @@ bool js_cocos2dx_ReverseTime_initWithAction(JSContext *cx, uint32_t argc, jsval bool ret = cobj->initWithAction(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -17387,14 +18026,14 @@ bool js_cocos2dx_ReverseTime_initWithAction(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ReverseTime_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::FiniteTimeAction* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -17410,7 +18049,7 @@ bool js_cocos2dx_ReverseTime_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ReverseTime_create : wrong number of arguments"); @@ -17419,7 +18058,7 @@ bool js_cocos2dx_ReverseTime_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ReverseTime_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ReverseTime* cobj = new (std::nothrow) cocos2d::ReverseTime(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -17433,13 +18072,16 @@ bool js_cocos2dx_ReverseTime_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ReverseTime"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ReverseTime"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -17450,7 +18092,7 @@ void js_cocos2d_ReverseTime_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ReverseTime)", obj); } -void js_register_cocos2dx_ReverseTime(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ReverseTime(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ReverseTime_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ReverseTime_class->name = "ReverseTime"; jsb_cocos2d_ReverseTime_class->addProperty = JS_PropertyStub; @@ -17464,8 +18106,8 @@ void js_register_cocos2dx_ReverseTime(JSContext *cx, JSObject *global) { jsb_cocos2d_ReverseTime_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -17480,7 +18122,7 @@ void js_register_cocos2dx_ReverseTime(JSContext *cx, JSObject *global) { jsb_cocos2d_ReverseTime_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_ReverseTime_class, js_cocos2dx_ReverseTime_constructor, 0, // constructor properties, @@ -17511,12 +18153,12 @@ JSObject *jsb_cocos2d_Animate_prototype; bool js_cocos2dx_Animate_getAnimation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Animate* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Animate *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animate_getAnimation : Invalid Native Object"); @@ -17532,7 +18174,7 @@ bool js_cocos2dx_Animate_getAnimation(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -17549,7 +18191,7 @@ bool js_cocos2dx_Animate_getAnimation(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -17559,18 +18201,18 @@ bool js_cocos2dx_Animate_getAnimation(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Animate_initWithAnimation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animate* cobj = (cocos2d::Animate *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animate_initWithAnimation : Invalid Native Object"); if (argc == 1) { cocos2d::Animation* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Animation*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -17579,7 +18221,7 @@ bool js_cocos2dx_Animate_initWithAnimation(JSContext *cx, uint32_t argc, jsval * bool ret = cobj->initWithAnimation(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -17588,25 +18230,25 @@ bool js_cocos2dx_Animate_initWithAnimation(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Animate_setAnimation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Animate* cobj = (cocos2d::Animate *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animate_setAnimation : Invalid Native Object"); if (argc == 1) { cocos2d::Animation* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Animation*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animate_setAnimation : Error processing arguments"); cobj->setAnimation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -17615,14 +18257,14 @@ bool js_cocos2dx_Animate_setAnimation(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Animate_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Animation* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Animation*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -17638,7 +18280,7 @@ bool js_cocos2dx_Animate_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Animate_create : wrong number of arguments"); @@ -17647,7 +18289,7 @@ bool js_cocos2dx_Animate_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Animate_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Animate* cobj = new (std::nothrow) cocos2d::Animate(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -17661,13 +18303,16 @@ bool js_cocos2dx_Animate_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Animate"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Animate"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -17678,7 +18323,7 @@ void js_cocos2d_Animate_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Animate)", obj); } -void js_register_cocos2dx_Animate(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Animate(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Animate_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Animate_class->name = "Animate"; jsb_cocos2d_Animate_class->addProperty = JS_PropertyStub; @@ -17692,8 +18337,8 @@ void js_register_cocos2dx_Animate(JSContext *cx, JSObject *global) { jsb_cocos2d_Animate_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -17710,7 +18355,7 @@ void js_register_cocos2dx_Animate(JSContext *cx, JSObject *global) { jsb_cocos2d_Animate_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_Animate_class, js_cocos2dx_Animate_constructor, 0, // constructor properties, @@ -17741,12 +18386,12 @@ JSObject *jsb_cocos2d_TargetedAction_prototype; bool js_cocos2dx_TargetedAction_getForcedTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TargetedAction* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TargetedAction *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TargetedAction_getForcedTarget : Invalid Native Object"); @@ -17762,7 +18407,7 @@ bool js_cocos2dx_TargetedAction_getForcedTarget(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -17779,7 +18424,7 @@ bool js_cocos2dx_TargetedAction_getForcedTarget(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -17789,9 +18434,9 @@ bool js_cocos2dx_TargetedAction_getForcedTarget(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_TargetedAction_initWithTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TargetedAction* cobj = (cocos2d::TargetedAction *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TargetedAction_initWithTarget : Invalid Native Object"); @@ -17799,17 +18444,17 @@ bool js_cocos2dx_TargetedAction_initWithTarget(JSContext *cx, uint32_t argc, jsv cocos2d::Node* arg0; cocos2d::FiniteTimeAction* arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -17818,7 +18463,7 @@ bool js_cocos2dx_TargetedAction_initWithTarget(JSContext *cx, uint32_t argc, jsv bool ret = cobj->initWithTarget(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -17827,25 +18472,25 @@ bool js_cocos2dx_TargetedAction_initWithTarget(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_TargetedAction_setForcedTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TargetedAction* cobj = (cocos2d::TargetedAction *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TargetedAction_setForcedTarget : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TargetedAction_setForcedTarget : Error processing arguments"); cobj->setForcedTarget(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -17854,23 +18499,23 @@ bool js_cocos2dx_TargetedAction_setForcedTarget(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_TargetedAction_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::Node* arg0; cocos2d::FiniteTimeAction* arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -17886,7 +18531,7 @@ bool js_cocos2dx_TargetedAction_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TargetedAction_create : wrong number of arguments"); @@ -17895,7 +18540,7 @@ bool js_cocos2dx_TargetedAction_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_TargetedAction_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TargetedAction* cobj = new (std::nothrow) cocos2d::TargetedAction(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -17909,13 +18554,16 @@ bool js_cocos2dx_TargetedAction_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TargetedAction"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TargetedAction"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -17928,21 +18576,21 @@ void js_cocos2d_TargetedAction_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_TargetedAction_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::TargetedAction *nobj = new (std::nothrow) cocos2d::TargetedAction(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TargetedAction"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TargetedAction"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_TargetedAction(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TargetedAction(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TargetedAction_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TargetedAction_class->name = "TargetedAction"; jsb_cocos2d_TargetedAction_class->addProperty = JS_PropertyStub; @@ -17956,8 +18604,8 @@ void js_register_cocos2dx_TargetedAction(JSContext *cx, JSObject *global) { jsb_cocos2d_TargetedAction_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -17975,7 +18623,7 @@ void js_register_cocos2dx_TargetedAction(JSContext *cx, JSObject *global) { jsb_cocos2d_TargetedAction_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_TargetedAction_class, js_cocos2dx_TargetedAction_constructor, 0, // constructor properties, @@ -18006,28 +18654,28 @@ JSObject *jsb_cocos2d_ActionCamera_prototype; bool js_cocos2dx_ActionCamera_setEye(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::ActionCamera* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::ActionCamera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionCamera_setEye : Invalid Native Object"); do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cobj->setEye(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -18035,10 +18683,10 @@ bool js_cocos2dx_ActionCamera_setEye(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 1) { cocos2d::Vec3 arg0; - ok &= jsval_to_vector3(cx, argv[0], &arg0); + ok &= jsval_to_vector3(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cobj->setEye(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -18048,7 +18696,8 @@ bool js_cocos2dx_ActionCamera_setEye(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ActionCamera_getEye(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionCamera* cobj = (cocos2d::ActionCamera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionCamera_getEye : Invalid Native Object"); @@ -18056,7 +18705,7 @@ bool js_cocos2dx_ActionCamera_getEye(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Vec3& ret = cobj->getEye(); jsval jsret = JSVAL_NULL; jsret = vector3_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -18065,18 +18714,18 @@ bool js_cocos2dx_ActionCamera_getEye(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ActionCamera_setUp(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionCamera* cobj = (cocos2d::ActionCamera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionCamera_setUp : Invalid Native Object"); if (argc == 1) { cocos2d::Vec3 arg0; - ok &= jsval_to_vector3(cx, argv[0], &arg0); + ok &= jsval_to_vector3(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionCamera_setUp : Error processing arguments"); cobj->setUp(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -18085,7 +18734,8 @@ bool js_cocos2dx_ActionCamera_setUp(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ActionCamera_getCenter(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionCamera* cobj = (cocos2d::ActionCamera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionCamera_getCenter : Invalid Native Object"); @@ -18093,7 +18743,7 @@ bool js_cocos2dx_ActionCamera_getCenter(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Vec3& ret = cobj->getCenter(); jsval jsret = JSVAL_NULL; jsret = vector3_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -18102,18 +18752,18 @@ bool js_cocos2dx_ActionCamera_getCenter(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ActionCamera_setCenter(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionCamera* cobj = (cocos2d::ActionCamera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionCamera_setCenter : Invalid Native Object"); if (argc == 1) { cocos2d::Vec3 arg0; - ok &= jsval_to_vector3(cx, argv[0], &arg0); + ok &= jsval_to_vector3(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionCamera_setCenter : Error processing arguments"); cobj->setCenter(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -18122,7 +18772,8 @@ bool js_cocos2dx_ActionCamera_setCenter(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ActionCamera_getUp(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionCamera* cobj = (cocos2d::ActionCamera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionCamera_getUp : Invalid Native Object"); @@ -18130,7 +18781,7 @@ bool js_cocos2dx_ActionCamera_getUp(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Vec3& ret = cobj->getUp(); jsval jsret = JSVAL_NULL; jsret = vector3_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -18139,7 +18790,7 @@ bool js_cocos2dx_ActionCamera_getUp(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ActionCamera_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ActionCamera* cobj = new (std::nothrow) cocos2d::ActionCamera(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -18153,13 +18804,16 @@ bool js_cocos2dx_ActionCamera_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ActionCamera"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ActionCamera"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -18172,21 +18826,21 @@ void js_cocos2d_ActionCamera_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ActionCamera_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ActionCamera *nobj = new (std::nothrow) cocos2d::ActionCamera(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ActionCamera"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ActionCamera"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ActionCamera(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ActionCamera(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ActionCamera_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ActionCamera_class->name = "ActionCamera"; jsb_cocos2d_ActionCamera_class->addProperty = JS_PropertyStub; @@ -18200,8 +18854,8 @@ void js_register_cocos2dx_ActionCamera(JSContext *cx, JSObject *global) { jsb_cocos2d_ActionCamera_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -18219,7 +18873,7 @@ void js_register_cocos2dx_ActionCamera(JSContext *cx, JSObject *global) { jsb_cocos2d_ActionCamera_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_ActionCamera_class, js_cocos2dx_ActionCamera_constructor, 0, // constructor properties, @@ -18250,9 +18904,9 @@ JSObject *jsb_cocos2d_OrbitCamera_prototype; bool js_cocos2dx_OrbitCamera_sphericalRadius(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::OrbitCamera* cobj = (cocos2d::OrbitCamera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_OrbitCamera_sphericalRadius : Invalid Native Object"); @@ -18268,7 +18922,7 @@ bool js_cocos2dx_OrbitCamera_sphericalRadius(JSContext *cx, uint32_t argc, jsval ok = false; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_OrbitCamera_sphericalRadius : Error processing arguments"); cobj->sphericalRadius(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -18277,9 +18931,9 @@ bool js_cocos2dx_OrbitCamera_sphericalRadius(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_OrbitCamera_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::OrbitCamera* cobj = (cocos2d::OrbitCamera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_OrbitCamera_initWithDuration : Invalid Native Object"); @@ -18291,18 +18945,18 @@ bool js_cocos2dx_OrbitCamera_initWithDuration(JSContext *cx, uint32_t argc, jsva double arg4; double arg5; double arg6; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[4]), &arg4); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[5]), &arg5); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[6]), &arg6); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); + ok &= JS::ToNumber( cx, args.get(4), &arg4) && !isnan(arg4); + ok &= JS::ToNumber( cx, args.get(5), &arg5) && !isnan(arg5); + ok &= JS::ToNumber( cx, args.get(6), &arg6) && !isnan(arg6); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_OrbitCamera_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3, arg4, arg5, arg6); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -18311,7 +18965,7 @@ bool js_cocos2dx_OrbitCamera_initWithDuration(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_OrbitCamera_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 7) { double arg0; @@ -18321,13 +18975,13 @@ bool js_cocos2dx_OrbitCamera_create(JSContext *cx, uint32_t argc, jsval *vp) double arg4; double arg5; double arg6; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[4]), &arg4); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[5]), &arg5); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[6]), &arg6); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); + ok &= JS::ToNumber( cx, args.get(4), &arg4) && !isnan(arg4); + ok &= JS::ToNumber( cx, args.get(5), &arg5) && !isnan(arg5); + ok &= JS::ToNumber( cx, args.get(6), &arg6) && !isnan(arg6); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_OrbitCamera_create : Error processing arguments"); cocos2d::OrbitCamera* ret = cocos2d::OrbitCamera::create(arg0, arg1, arg2, arg3, arg4, arg5, arg6); jsval jsret = JSVAL_NULL; @@ -18339,7 +18993,7 @@ bool js_cocos2dx_OrbitCamera_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_OrbitCamera_create : wrong number of arguments"); @@ -18348,7 +19002,7 @@ bool js_cocos2dx_OrbitCamera_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_OrbitCamera_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::OrbitCamera* cobj = new (std::nothrow) cocos2d::OrbitCamera(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -18362,13 +19016,16 @@ bool js_cocos2dx_OrbitCamera_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::OrbitCamera"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::OrbitCamera"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -18379,7 +19036,7 @@ void js_cocos2d_OrbitCamera_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (OrbitCamera)", obj); } -void js_register_cocos2dx_OrbitCamera(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_OrbitCamera(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_OrbitCamera_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_OrbitCamera_class->name = "OrbitCamera"; jsb_cocos2d_OrbitCamera_class->addProperty = JS_PropertyStub; @@ -18393,8 +19050,8 @@ void js_register_cocos2dx_OrbitCamera(JSContext *cx, JSObject *global) { jsb_cocos2d_OrbitCamera_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -18410,7 +19067,7 @@ void js_register_cocos2dx_OrbitCamera(JSContext *cx, JSObject *global) { jsb_cocos2d_OrbitCamera_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionCamera_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionCamera_prototype), jsb_cocos2d_OrbitCamera_class, js_cocos2dx_OrbitCamera_constructor, 0, // constructor properties, @@ -18441,20 +19098,20 @@ JSObject *jsb_cocos2d_ActionManager_prototype; bool js_cocos2dx_ActionManager_getActionByTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionManager* cobj = (cocos2d::ActionManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionManager_getActionByTag : Invalid Native Object"); if (argc == 2) { int arg0; const cocos2d::Node* arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (const cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -18470,7 +19127,7 @@ bool js_cocos2dx_ActionManager_getActionByTag(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -18479,27 +19136,27 @@ bool js_cocos2dx_ActionManager_getActionByTag(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ActionManager_removeActionByTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionManager* cobj = (cocos2d::ActionManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionManager_removeActionByTag : Invalid Native Object"); if (argc == 2) { int arg0; cocos2d::Node* arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionManager_removeActionByTag : Error processing arguments"); cobj->removeActionByTag(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -18508,13 +19165,14 @@ bool js_cocos2dx_ActionManager_removeActionByTag(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ActionManager_removeAllActions(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionManager* cobj = (cocos2d::ActionManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionManager_removeAllActions : Invalid Native Object"); if (argc == 0) { cobj->removeAllActions(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -18523,9 +19181,9 @@ bool js_cocos2dx_ActionManager_removeAllActions(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ActionManager_addAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionManager* cobj = (cocos2d::ActionManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionManager_addAction : Invalid Native Object"); @@ -18534,25 +19192,25 @@ bool js_cocos2dx_ActionManager_addAction(JSContext *cx, uint32_t argc, jsval *vp cocos2d::Node* arg1; bool arg2; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Action*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(args.get(2)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionManager_addAction : Error processing arguments"); cobj->addAction(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -18561,25 +19219,25 @@ bool js_cocos2dx_ActionManager_addAction(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ActionManager_resumeTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionManager* cobj = (cocos2d::ActionManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionManager_resumeTarget : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionManager_resumeTarget : Error processing arguments"); cobj->resumeTarget(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -18588,18 +19246,18 @@ bool js_cocos2dx_ActionManager_resumeTarget(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ActionManager_update(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionManager* cobj = (cocos2d::ActionManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionManager_update : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionManager_update : Error processing arguments"); cobj->update(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -18608,25 +19266,25 @@ bool js_cocos2dx_ActionManager_update(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ActionManager_pauseTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionManager* cobj = (cocos2d::ActionManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionManager_pauseTarget : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionManager_pauseTarget : Error processing arguments"); cobj->pauseTarget(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -18635,18 +19293,18 @@ bool js_cocos2dx_ActionManager_pauseTarget(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ActionManager_getNumberOfRunningActionsInTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionManager* cobj = (cocos2d::ActionManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionManager_getNumberOfRunningActionsInTarget : Invalid Native Object"); if (argc == 1) { const cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (const cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -18655,7 +19313,7 @@ bool js_cocos2dx_ActionManager_getNumberOfRunningActionsInTarget(JSContext *cx, ssize_t ret = cobj->getNumberOfRunningActionsInTarget(arg0); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -18664,25 +19322,25 @@ bool js_cocos2dx_ActionManager_getNumberOfRunningActionsInTarget(JSContext *cx, } bool js_cocos2dx_ActionManager_removeAllActionsFromTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionManager* cobj = (cocos2d::ActionManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionManager_removeAllActionsFromTarget : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionManager_removeAllActionsFromTarget : Error processing arguments"); cobj->removeAllActionsFromTarget(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -18691,18 +19349,18 @@ bool js_cocos2dx_ActionManager_removeAllActionsFromTarget(JSContext *cx, uint32_ } bool js_cocos2dx_ActionManager_resumeTargets(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionManager* cobj = (cocos2d::ActionManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionManager_resumeTargets : Invalid Native Object"); if (argc == 1) { cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionManager_resumeTargets : Error processing arguments"); cobj->resumeTargets(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -18711,25 +19369,25 @@ bool js_cocos2dx_ActionManager_resumeTargets(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ActionManager_removeAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionManager* cobj = (cocos2d::ActionManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionManager_removeAction : Invalid Native Object"); if (argc == 1) { cocos2d::Action* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Action*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionManager_removeAction : Error processing arguments"); cobj->removeAction(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -18738,27 +19396,27 @@ bool js_cocos2dx_ActionManager_removeAction(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ActionManager_removeAllActionsByTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionManager* cobj = (cocos2d::ActionManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionManager_removeAllActionsByTag : Invalid Native Object"); if (argc == 2) { int arg0; cocos2d::Node* arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionManager_removeAllActionsByTag : Error processing arguments"); cobj->removeAllActionsByTag(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -18767,7 +19425,8 @@ bool js_cocos2dx_ActionManager_removeAllActionsByTag(JSContext *cx, uint32_t arg } bool js_cocos2dx_ActionManager_pauseAllRunningActions(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionManager* cobj = (cocos2d::ActionManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionManager_pauseAllRunningActions : Invalid Native Object"); @@ -18775,7 +19434,7 @@ bool js_cocos2dx_ActionManager_pauseAllRunningActions(JSContext *cx, uint32_t ar cocos2d::Vector ret = cobj->pauseAllRunningActions(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -18784,7 +19443,7 @@ bool js_cocos2dx_ActionManager_pauseAllRunningActions(JSContext *cx, uint32_t ar } bool js_cocos2dx_ActionManager_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ActionManager* cobj = new (std::nothrow) cocos2d::ActionManager(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -18798,13 +19457,16 @@ bool js_cocos2dx_ActionManager_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ActionManager"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ActionManager"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -18816,21 +19478,21 @@ void js_cocos2d_ActionManager_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ActionManager_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ActionManager *nobj = new (std::nothrow) cocos2d::ActionManager(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ActionManager"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ActionManager"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ActionManager(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ActionManager(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ActionManager_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ActionManager_class->name = "ActionManager"; jsb_cocos2d_ActionManager_class->addProperty = JS_PropertyStub; @@ -18844,8 +19506,8 @@ void js_register_cocos2dx_ActionManager(JSContext *cx, JSObject *global) { jsb_cocos2d_ActionManager_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -18870,7 +19532,7 @@ void js_register_cocos2dx_ActionManager(JSContext *cx, JSObject *global) { jsb_cocos2d_ActionManager_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_ActionManager_class, js_cocos2dx_ActionManager_constructor, 0, // constructor properties, @@ -18901,18 +19563,18 @@ JSObject *jsb_cocos2d_ActionEase_prototype; bool js_cocos2dx_ActionEase_initWithAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionEase* cobj = (cocos2d::ActionEase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionEase_initWithAction : Invalid Native Object"); if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -18921,7 +19583,7 @@ bool js_cocos2dx_ActionEase_initWithAction(JSContext *cx, uint32_t argc, jsval * bool ret = cobj->initWithAction(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -18930,7 +19592,8 @@ bool js_cocos2dx_ActionEase_initWithAction(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ActionEase_getInnerAction(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionEase* cobj = (cocos2d::ActionEase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionEase_getInnerAction : Invalid Native Object"); @@ -18945,7 +19608,7 @@ bool js_cocos2dx_ActionEase_getInnerAction(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -18959,7 +19622,7 @@ void js_cocos2d_ActionEase_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ActionEase)", obj); } -void js_register_cocos2dx_ActionEase(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ActionEase(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ActionEase_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ActionEase_class->name = "ActionEase"; jsb_cocos2d_ActionEase_class->addProperty = JS_PropertyStub; @@ -18973,8 +19636,8 @@ void js_register_cocos2dx_ActionEase(JSContext *cx, JSObject *global) { jsb_cocos2d_ActionEase_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -18987,7 +19650,7 @@ void js_register_cocos2dx_ActionEase(JSContext *cx, JSObject *global) { jsb_cocos2d_ActionEase_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_ActionEase_class, empty_constructor, 0, properties, @@ -19018,18 +19681,18 @@ JSObject *jsb_cocos2d_EaseRateAction_prototype; bool js_cocos2dx_EaseRateAction_setRate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EaseRateAction* cobj = (cocos2d::EaseRateAction *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EaseRateAction_setRate : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EaseRateAction_setRate : Error processing arguments"); cobj->setRate(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -19038,9 +19701,9 @@ bool js_cocos2dx_EaseRateAction_setRate(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_EaseRateAction_initWithAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EaseRateAction* cobj = (cocos2d::EaseRateAction *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EaseRateAction_initWithAction : Invalid Native Object"); @@ -19048,19 +19711,19 @@ bool js_cocos2dx_EaseRateAction_initWithAction(JSContext *cx, uint32_t argc, jsv cocos2d::ActionInterval* arg0; double arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EaseRateAction_initWithAction : Error processing arguments"); bool ret = cobj->initWithAction(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -19069,7 +19732,8 @@ bool js_cocos2dx_EaseRateAction_initWithAction(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_EaseRateAction_getRate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EaseRateAction* cobj = (cocos2d::EaseRateAction *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EaseRateAction_getRate : Invalid Native Object"); @@ -19077,7 +19741,7 @@ bool js_cocos2dx_EaseRateAction_getRate(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getRate(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -19091,7 +19755,7 @@ void js_cocos2d_EaseRateAction_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseRateAction)", obj); } -void js_register_cocos2dx_EaseRateAction(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseRateAction(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseRateAction_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseRateAction_class->name = "EaseRateAction"; jsb_cocos2d_EaseRateAction_class->addProperty = JS_PropertyStub; @@ -19105,8 +19769,8 @@ void js_register_cocos2dx_EaseRateAction(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseRateAction_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -19120,7 +19784,7 @@ void js_register_cocos2dx_EaseRateAction(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseRateAction_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseRateAction_class, empty_constructor, 0, properties, @@ -19151,20 +19815,20 @@ JSObject *jsb_cocos2d_EaseIn_prototype; bool js_cocos2dx_EaseIn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::ActionInterval* arg0; double arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EaseIn_create : Error processing arguments"); cocos2d::EaseIn* ret = cocos2d::EaseIn::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -19176,7 +19840,7 @@ bool js_cocos2dx_EaseIn_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseIn_create : wrong number of arguments"); @@ -19185,7 +19849,7 @@ bool js_cocos2dx_EaseIn_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_EaseIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseIn* cobj = new (std::nothrow) cocos2d::EaseIn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -19199,13 +19863,16 @@ bool js_cocos2dx_EaseIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseIn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -19216,7 +19883,7 @@ void js_cocos2d_EaseIn_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseIn)", obj); } -void js_register_cocos2dx_EaseIn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseIn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseIn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseIn_class->name = "EaseIn"; jsb_cocos2d_EaseIn_class->addProperty = JS_PropertyStub; @@ -19230,8 +19897,8 @@ void js_register_cocos2dx_EaseIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseIn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -19245,7 +19912,7 @@ void js_register_cocos2dx_EaseIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseIn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EaseRateAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_EaseRateAction_prototype), jsb_cocos2d_EaseIn_class, js_cocos2dx_EaseIn_constructor, 0, // constructor properties, @@ -19276,20 +19943,20 @@ JSObject *jsb_cocos2d_EaseOut_prototype; bool js_cocos2dx_EaseOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::ActionInterval* arg0; double arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EaseOut_create : Error processing arguments"); cocos2d::EaseOut* ret = cocos2d::EaseOut::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -19301,7 +19968,7 @@ bool js_cocos2dx_EaseOut_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseOut_create : wrong number of arguments"); @@ -19310,7 +19977,7 @@ bool js_cocos2dx_EaseOut_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_EaseOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseOut* cobj = new (std::nothrow) cocos2d::EaseOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -19324,13 +19991,16 @@ bool js_cocos2dx_EaseOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -19341,7 +20011,7 @@ void js_cocos2d_EaseOut_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseOut)", obj); } -void js_register_cocos2dx_EaseOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseOut_class->name = "EaseOut"; jsb_cocos2d_EaseOut_class->addProperty = JS_PropertyStub; @@ -19355,8 +20025,8 @@ void js_register_cocos2dx_EaseOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -19370,7 +20040,7 @@ void js_register_cocos2dx_EaseOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EaseRateAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_EaseRateAction_prototype), jsb_cocos2d_EaseOut_class, js_cocos2dx_EaseOut_constructor, 0, // constructor properties, @@ -19401,20 +20071,20 @@ JSObject *jsb_cocos2d_EaseInOut_prototype; bool js_cocos2dx_EaseInOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::ActionInterval* arg0; double arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EaseInOut_create : Error processing arguments"); cocos2d::EaseInOut* ret = cocos2d::EaseInOut::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -19426,7 +20096,7 @@ bool js_cocos2dx_EaseInOut_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseInOut_create : wrong number of arguments"); @@ -19435,7 +20105,7 @@ bool js_cocos2dx_EaseInOut_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_EaseInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseInOut* cobj = new (std::nothrow) cocos2d::EaseInOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -19449,13 +20119,16 @@ bool js_cocos2dx_EaseInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseInOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -19466,7 +20139,7 @@ void js_cocos2d_EaseInOut_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseInOut)", obj); } -void js_register_cocos2dx_EaseInOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseInOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseInOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseInOut_class->name = "EaseInOut"; jsb_cocos2d_EaseInOut_class->addProperty = JS_PropertyStub; @@ -19480,8 +20153,8 @@ void js_register_cocos2dx_EaseInOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseInOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -19495,7 +20168,7 @@ void js_register_cocos2dx_EaseInOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseInOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EaseRateAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_EaseRateAction_prototype), jsb_cocos2d_EaseInOut_class, js_cocos2dx_EaseInOut_constructor, 0, // constructor properties, @@ -19526,14 +20199,14 @@ JSObject *jsb_cocos2d_EaseExponentialIn_prototype; bool js_cocos2dx_EaseExponentialIn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -19549,7 +20222,7 @@ bool js_cocos2dx_EaseExponentialIn_create(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseExponentialIn_create : wrong number of arguments"); @@ -19558,7 +20231,7 @@ bool js_cocos2dx_EaseExponentialIn_create(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_EaseExponentialIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseExponentialIn* cobj = new (std::nothrow) cocos2d::EaseExponentialIn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -19572,13 +20245,16 @@ bool js_cocos2dx_EaseExponentialIn_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseExponentialIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseExponentialIn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -19589,7 +20265,7 @@ void js_cocos2d_EaseExponentialIn_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseExponentialIn)", obj); } -void js_register_cocos2dx_EaseExponentialIn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseExponentialIn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseExponentialIn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseExponentialIn_class->name = "EaseExponentialIn"; jsb_cocos2d_EaseExponentialIn_class->addProperty = JS_PropertyStub; @@ -19603,8 +20279,8 @@ void js_register_cocos2dx_EaseExponentialIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseExponentialIn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -19618,7 +20294,7 @@ void js_register_cocos2dx_EaseExponentialIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseExponentialIn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseExponentialIn_class, js_cocos2dx_EaseExponentialIn_constructor, 0, // constructor properties, @@ -19649,14 +20325,14 @@ JSObject *jsb_cocos2d_EaseExponentialOut_prototype; bool js_cocos2dx_EaseExponentialOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -19672,7 +20348,7 @@ bool js_cocos2dx_EaseExponentialOut_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseExponentialOut_create : wrong number of arguments"); @@ -19681,7 +20357,7 @@ bool js_cocos2dx_EaseExponentialOut_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_EaseExponentialOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseExponentialOut* cobj = new (std::nothrow) cocos2d::EaseExponentialOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -19695,13 +20371,16 @@ bool js_cocos2dx_EaseExponentialOut_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseExponentialOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseExponentialOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -19712,7 +20391,7 @@ void js_cocos2d_EaseExponentialOut_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseExponentialOut)", obj); } -void js_register_cocos2dx_EaseExponentialOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseExponentialOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseExponentialOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseExponentialOut_class->name = "EaseExponentialOut"; jsb_cocos2d_EaseExponentialOut_class->addProperty = JS_PropertyStub; @@ -19726,8 +20405,8 @@ void js_register_cocos2dx_EaseExponentialOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseExponentialOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -19741,7 +20420,7 @@ void js_register_cocos2dx_EaseExponentialOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseExponentialOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseExponentialOut_class, js_cocos2dx_EaseExponentialOut_constructor, 0, // constructor properties, @@ -19772,14 +20451,14 @@ JSObject *jsb_cocos2d_EaseExponentialInOut_prototype; bool js_cocos2dx_EaseExponentialInOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -19795,7 +20474,7 @@ bool js_cocos2dx_EaseExponentialInOut_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseExponentialInOut_create : wrong number of arguments"); @@ -19804,7 +20483,7 @@ bool js_cocos2dx_EaseExponentialInOut_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_EaseExponentialInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseExponentialInOut* cobj = new (std::nothrow) cocos2d::EaseExponentialInOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -19818,13 +20497,16 @@ bool js_cocos2dx_EaseExponentialInOut_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseExponentialInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseExponentialInOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -19835,7 +20517,7 @@ void js_cocos2d_EaseExponentialInOut_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseExponentialInOut)", obj); } -void js_register_cocos2dx_EaseExponentialInOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseExponentialInOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseExponentialInOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseExponentialInOut_class->name = "EaseExponentialInOut"; jsb_cocos2d_EaseExponentialInOut_class->addProperty = JS_PropertyStub; @@ -19849,8 +20531,8 @@ void js_register_cocos2dx_EaseExponentialInOut(JSContext *cx, JSObject *global) jsb_cocos2d_EaseExponentialInOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -19864,7 +20546,7 @@ void js_register_cocos2dx_EaseExponentialInOut(JSContext *cx, JSObject *global) jsb_cocos2d_EaseExponentialInOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseExponentialInOut_class, js_cocos2dx_EaseExponentialInOut_constructor, 0, // constructor properties, @@ -19895,14 +20577,14 @@ JSObject *jsb_cocos2d_EaseSineIn_prototype; bool js_cocos2dx_EaseSineIn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -19918,7 +20600,7 @@ bool js_cocos2dx_EaseSineIn_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseSineIn_create : wrong number of arguments"); @@ -19927,7 +20609,7 @@ bool js_cocos2dx_EaseSineIn_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_EaseSineIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseSineIn* cobj = new (std::nothrow) cocos2d::EaseSineIn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -19941,13 +20623,16 @@ bool js_cocos2dx_EaseSineIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseSineIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseSineIn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -19958,7 +20643,7 @@ void js_cocos2d_EaseSineIn_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseSineIn)", obj); } -void js_register_cocos2dx_EaseSineIn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseSineIn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseSineIn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseSineIn_class->name = "EaseSineIn"; jsb_cocos2d_EaseSineIn_class->addProperty = JS_PropertyStub; @@ -19972,8 +20657,8 @@ void js_register_cocos2dx_EaseSineIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseSineIn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -19987,7 +20672,7 @@ void js_register_cocos2dx_EaseSineIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseSineIn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseSineIn_class, js_cocos2dx_EaseSineIn_constructor, 0, // constructor properties, @@ -20018,14 +20703,14 @@ JSObject *jsb_cocos2d_EaseSineOut_prototype; bool js_cocos2dx_EaseSineOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -20041,7 +20726,7 @@ bool js_cocos2dx_EaseSineOut_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseSineOut_create : wrong number of arguments"); @@ -20050,7 +20735,7 @@ bool js_cocos2dx_EaseSineOut_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_EaseSineOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseSineOut* cobj = new (std::nothrow) cocos2d::EaseSineOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -20064,13 +20749,16 @@ bool js_cocos2dx_EaseSineOut_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseSineOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseSineOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -20081,7 +20769,7 @@ void js_cocos2d_EaseSineOut_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseSineOut)", obj); } -void js_register_cocos2dx_EaseSineOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseSineOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseSineOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseSineOut_class->name = "EaseSineOut"; jsb_cocos2d_EaseSineOut_class->addProperty = JS_PropertyStub; @@ -20095,8 +20783,8 @@ void js_register_cocos2dx_EaseSineOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseSineOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -20110,7 +20798,7 @@ void js_register_cocos2dx_EaseSineOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseSineOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseSineOut_class, js_cocos2dx_EaseSineOut_constructor, 0, // constructor properties, @@ -20141,14 +20829,14 @@ JSObject *jsb_cocos2d_EaseSineInOut_prototype; bool js_cocos2dx_EaseSineInOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -20164,7 +20852,7 @@ bool js_cocos2dx_EaseSineInOut_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseSineInOut_create : wrong number of arguments"); @@ -20173,7 +20861,7 @@ bool js_cocos2dx_EaseSineInOut_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_EaseSineInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseSineInOut* cobj = new (std::nothrow) cocos2d::EaseSineInOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -20187,13 +20875,16 @@ bool js_cocos2dx_EaseSineInOut_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseSineInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseSineInOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -20204,7 +20895,7 @@ void js_cocos2d_EaseSineInOut_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseSineInOut)", obj); } -void js_register_cocos2dx_EaseSineInOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseSineInOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseSineInOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseSineInOut_class->name = "EaseSineInOut"; jsb_cocos2d_EaseSineInOut_class->addProperty = JS_PropertyStub; @@ -20218,8 +20909,8 @@ void js_register_cocos2dx_EaseSineInOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseSineInOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -20233,7 +20924,7 @@ void js_register_cocos2dx_EaseSineInOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseSineInOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseSineInOut_class, js_cocos2dx_EaseSineInOut_constructor, 0, // constructor properties, @@ -20264,18 +20955,18 @@ JSObject *jsb_cocos2d_EaseElastic_prototype; bool js_cocos2dx_EaseElastic_setPeriod(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EaseElastic* cobj = (cocos2d::EaseElastic *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EaseElastic_setPeriod : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EaseElastic_setPeriod : Error processing arguments"); cobj->setPeriod(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -20284,18 +20975,18 @@ bool js_cocos2dx_EaseElastic_setPeriod(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_EaseElastic_initWithAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EaseElastic* cobj = (cocos2d::EaseElastic *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EaseElastic_initWithAction : Invalid Native Object"); if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -20304,26 +20995,26 @@ bool js_cocos2dx_EaseElastic_initWithAction(JSContext *cx, uint32_t argc, jsval bool ret = cobj->initWithAction(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { cocos2d::ActionInterval* arg0; double arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EaseElastic_initWithAction : Error processing arguments"); bool ret = cobj->initWithAction(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -20332,7 +21023,8 @@ bool js_cocos2dx_EaseElastic_initWithAction(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_EaseElastic_getPeriod(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EaseElastic* cobj = (cocos2d::EaseElastic *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EaseElastic_getPeriod : Invalid Native Object"); @@ -20340,7 +21032,7 @@ bool js_cocos2dx_EaseElastic_getPeriod(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getPeriod(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -20354,7 +21046,7 @@ void js_cocos2d_EaseElastic_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseElastic)", obj); } -void js_register_cocos2dx_EaseElastic(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseElastic(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseElastic_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseElastic_class->name = "EaseElastic"; jsb_cocos2d_EaseElastic_class->addProperty = JS_PropertyStub; @@ -20368,8 +21060,8 @@ void js_register_cocos2dx_EaseElastic(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseElastic_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -20383,7 +21075,7 @@ void js_register_cocos2dx_EaseElastic(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseElastic_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseElastic_class, empty_constructor, 0, properties, @@ -20414,16 +21106,16 @@ JSObject *jsb_cocos2d_EaseElasticIn_prototype; bool js_cocos2dx_EaseElasticIn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -20439,7 +21131,7 @@ bool js_cocos2dx_EaseElasticIn_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -20448,16 +21140,16 @@ bool js_cocos2dx_EaseElasticIn_create(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 2) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } cocos2d::EaseElasticIn* ret = cocos2d::EaseElasticIn::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -20469,7 +21161,7 @@ bool js_cocos2dx_EaseElasticIn_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -20478,7 +21170,7 @@ bool js_cocos2dx_EaseElasticIn_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_EaseElasticIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseElasticIn* cobj = new (std::nothrow) cocos2d::EaseElasticIn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -20492,13 +21184,16 @@ bool js_cocos2dx_EaseElasticIn_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseElasticIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseElasticIn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -20509,7 +21204,7 @@ void js_cocos2d_EaseElasticIn_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseElasticIn)", obj); } -void js_register_cocos2dx_EaseElasticIn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseElasticIn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseElasticIn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseElasticIn_class->name = "EaseElasticIn"; jsb_cocos2d_EaseElasticIn_class->addProperty = JS_PropertyStub; @@ -20523,8 +21218,8 @@ void js_register_cocos2dx_EaseElasticIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseElasticIn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -20538,7 +21233,7 @@ void js_register_cocos2dx_EaseElasticIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseElasticIn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EaseElastic_prototype, + JS::RootedObject(cx, jsb_cocos2d_EaseElastic_prototype), jsb_cocos2d_EaseElasticIn_class, js_cocos2dx_EaseElasticIn_constructor, 0, // constructor properties, @@ -20569,16 +21264,16 @@ JSObject *jsb_cocos2d_EaseElasticOut_prototype; bool js_cocos2dx_EaseElasticOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -20594,7 +21289,7 @@ bool js_cocos2dx_EaseElasticOut_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -20603,16 +21298,16 @@ bool js_cocos2dx_EaseElasticOut_create(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 2) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } cocos2d::EaseElasticOut* ret = cocos2d::EaseElasticOut::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -20624,7 +21319,7 @@ bool js_cocos2dx_EaseElasticOut_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -20633,7 +21328,7 @@ bool js_cocos2dx_EaseElasticOut_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_EaseElasticOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseElasticOut* cobj = new (std::nothrow) cocos2d::EaseElasticOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -20647,13 +21342,16 @@ bool js_cocos2dx_EaseElasticOut_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseElasticOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseElasticOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -20664,7 +21362,7 @@ void js_cocos2d_EaseElasticOut_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseElasticOut)", obj); } -void js_register_cocos2dx_EaseElasticOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseElasticOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseElasticOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseElasticOut_class->name = "EaseElasticOut"; jsb_cocos2d_EaseElasticOut_class->addProperty = JS_PropertyStub; @@ -20678,8 +21376,8 @@ void js_register_cocos2dx_EaseElasticOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseElasticOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -20693,7 +21391,7 @@ void js_register_cocos2dx_EaseElasticOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseElasticOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EaseElastic_prototype, + JS::RootedObject(cx, jsb_cocos2d_EaseElastic_prototype), jsb_cocos2d_EaseElasticOut_class, js_cocos2dx_EaseElasticOut_constructor, 0, // constructor properties, @@ -20724,16 +21422,16 @@ JSObject *jsb_cocos2d_EaseElasticInOut_prototype; bool js_cocos2dx_EaseElasticInOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -20749,7 +21447,7 @@ bool js_cocos2dx_EaseElasticInOut_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -20758,16 +21456,16 @@ bool js_cocos2dx_EaseElasticInOut_create(JSContext *cx, uint32_t argc, jsval *vp if (argc == 2) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } cocos2d::EaseElasticInOut* ret = cocos2d::EaseElasticInOut::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -20779,7 +21477,7 @@ bool js_cocos2dx_EaseElasticInOut_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -20788,7 +21486,7 @@ bool js_cocos2dx_EaseElasticInOut_create(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_EaseElasticInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseElasticInOut* cobj = new (std::nothrow) cocos2d::EaseElasticInOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -20802,13 +21500,16 @@ bool js_cocos2dx_EaseElasticInOut_constructor(JSContext *cx, uint32_t argc, jsva CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseElasticInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseElasticInOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -20819,7 +21520,7 @@ void js_cocos2d_EaseElasticInOut_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseElasticInOut)", obj); } -void js_register_cocos2dx_EaseElasticInOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseElasticInOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseElasticInOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseElasticInOut_class->name = "EaseElasticInOut"; jsb_cocos2d_EaseElasticInOut_class->addProperty = JS_PropertyStub; @@ -20833,8 +21534,8 @@ void js_register_cocos2dx_EaseElasticInOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseElasticInOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -20848,7 +21549,7 @@ void js_register_cocos2dx_EaseElasticInOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseElasticInOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EaseElastic_prototype, + JS::RootedObject(cx, jsb_cocos2d_EaseElastic_prototype), jsb_cocos2d_EaseElasticInOut_class, js_cocos2dx_EaseElasticInOut_constructor, 0, // constructor properties, @@ -20884,7 +21585,7 @@ void js_cocos2d_EaseBounce_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseBounce)", obj); } -void js_register_cocos2dx_EaseBounce(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseBounce(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseBounce_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseBounce_class->name = "EaseBounce"; jsb_cocos2d_EaseBounce_class->addProperty = JS_PropertyStub; @@ -20898,8 +21599,8 @@ void js_register_cocos2dx_EaseBounce(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBounce_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -20910,7 +21611,7 @@ void js_register_cocos2dx_EaseBounce(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBounce_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseBounce_class, empty_constructor, 0, properties, @@ -20941,14 +21642,14 @@ JSObject *jsb_cocos2d_EaseBounceIn_prototype; bool js_cocos2dx_EaseBounceIn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -20964,7 +21665,7 @@ bool js_cocos2dx_EaseBounceIn_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseBounceIn_create : wrong number of arguments"); @@ -20973,7 +21674,7 @@ bool js_cocos2dx_EaseBounceIn_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_EaseBounceIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseBounceIn* cobj = new (std::nothrow) cocos2d::EaseBounceIn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -20987,13 +21688,16 @@ bool js_cocos2dx_EaseBounceIn_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBounceIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBounceIn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -21004,7 +21708,7 @@ void js_cocos2d_EaseBounceIn_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseBounceIn)", obj); } -void js_register_cocos2dx_EaseBounceIn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseBounceIn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseBounceIn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseBounceIn_class->name = "EaseBounceIn"; jsb_cocos2d_EaseBounceIn_class->addProperty = JS_PropertyStub; @@ -21018,8 +21722,8 @@ void js_register_cocos2dx_EaseBounceIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBounceIn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -21033,7 +21737,7 @@ void js_register_cocos2dx_EaseBounceIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBounceIn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EaseBounce_prototype, + JS::RootedObject(cx, jsb_cocos2d_EaseBounce_prototype), jsb_cocos2d_EaseBounceIn_class, js_cocos2dx_EaseBounceIn_constructor, 0, // constructor properties, @@ -21064,14 +21768,14 @@ JSObject *jsb_cocos2d_EaseBounceOut_prototype; bool js_cocos2dx_EaseBounceOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -21087,7 +21791,7 @@ bool js_cocos2dx_EaseBounceOut_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseBounceOut_create : wrong number of arguments"); @@ -21096,7 +21800,7 @@ bool js_cocos2dx_EaseBounceOut_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_EaseBounceOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseBounceOut* cobj = new (std::nothrow) cocos2d::EaseBounceOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -21110,13 +21814,16 @@ bool js_cocos2dx_EaseBounceOut_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBounceOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBounceOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -21127,7 +21834,7 @@ void js_cocos2d_EaseBounceOut_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseBounceOut)", obj); } -void js_register_cocos2dx_EaseBounceOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseBounceOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseBounceOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseBounceOut_class->name = "EaseBounceOut"; jsb_cocos2d_EaseBounceOut_class->addProperty = JS_PropertyStub; @@ -21141,8 +21848,8 @@ void js_register_cocos2dx_EaseBounceOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBounceOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -21156,7 +21863,7 @@ void js_register_cocos2dx_EaseBounceOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBounceOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EaseBounce_prototype, + JS::RootedObject(cx, jsb_cocos2d_EaseBounce_prototype), jsb_cocos2d_EaseBounceOut_class, js_cocos2dx_EaseBounceOut_constructor, 0, // constructor properties, @@ -21187,14 +21894,14 @@ JSObject *jsb_cocos2d_EaseBounceInOut_prototype; bool js_cocos2dx_EaseBounceInOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -21210,7 +21917,7 @@ bool js_cocos2dx_EaseBounceInOut_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseBounceInOut_create : wrong number of arguments"); @@ -21219,7 +21926,7 @@ bool js_cocos2dx_EaseBounceInOut_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_EaseBounceInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseBounceInOut* cobj = new (std::nothrow) cocos2d::EaseBounceInOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -21233,13 +21940,16 @@ bool js_cocos2dx_EaseBounceInOut_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBounceInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBounceInOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -21250,7 +21960,7 @@ void js_cocos2d_EaseBounceInOut_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseBounceInOut)", obj); } -void js_register_cocos2dx_EaseBounceInOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseBounceInOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseBounceInOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseBounceInOut_class->name = "EaseBounceInOut"; jsb_cocos2d_EaseBounceInOut_class->addProperty = JS_PropertyStub; @@ -21264,8 +21974,8 @@ void js_register_cocos2dx_EaseBounceInOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBounceInOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -21279,7 +21989,7 @@ void js_register_cocos2dx_EaseBounceInOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBounceInOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EaseBounce_prototype, + JS::RootedObject(cx, jsb_cocos2d_EaseBounce_prototype), jsb_cocos2d_EaseBounceInOut_class, js_cocos2dx_EaseBounceInOut_constructor, 0, // constructor properties, @@ -21310,14 +22020,14 @@ JSObject *jsb_cocos2d_EaseBackIn_prototype; bool js_cocos2dx_EaseBackIn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -21333,7 +22043,7 @@ bool js_cocos2dx_EaseBackIn_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseBackIn_create : wrong number of arguments"); @@ -21342,7 +22052,7 @@ bool js_cocos2dx_EaseBackIn_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_EaseBackIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseBackIn* cobj = new (std::nothrow) cocos2d::EaseBackIn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -21356,13 +22066,16 @@ bool js_cocos2dx_EaseBackIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBackIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBackIn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -21373,7 +22086,7 @@ void js_cocos2d_EaseBackIn_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseBackIn)", obj); } -void js_register_cocos2dx_EaseBackIn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseBackIn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseBackIn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseBackIn_class->name = "EaseBackIn"; jsb_cocos2d_EaseBackIn_class->addProperty = JS_PropertyStub; @@ -21387,8 +22100,8 @@ void js_register_cocos2dx_EaseBackIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBackIn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -21402,7 +22115,7 @@ void js_register_cocos2dx_EaseBackIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBackIn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseBackIn_class, js_cocos2dx_EaseBackIn_constructor, 0, // constructor properties, @@ -21433,14 +22146,14 @@ JSObject *jsb_cocos2d_EaseBackOut_prototype; bool js_cocos2dx_EaseBackOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -21456,7 +22169,7 @@ bool js_cocos2dx_EaseBackOut_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseBackOut_create : wrong number of arguments"); @@ -21465,7 +22178,7 @@ bool js_cocos2dx_EaseBackOut_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_EaseBackOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseBackOut* cobj = new (std::nothrow) cocos2d::EaseBackOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -21479,13 +22192,16 @@ bool js_cocos2dx_EaseBackOut_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBackOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBackOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -21496,7 +22212,7 @@ void js_cocos2d_EaseBackOut_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseBackOut)", obj); } -void js_register_cocos2dx_EaseBackOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseBackOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseBackOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseBackOut_class->name = "EaseBackOut"; jsb_cocos2d_EaseBackOut_class->addProperty = JS_PropertyStub; @@ -21510,8 +22226,8 @@ void js_register_cocos2dx_EaseBackOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBackOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -21525,7 +22241,7 @@ void js_register_cocos2dx_EaseBackOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBackOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseBackOut_class, js_cocos2dx_EaseBackOut_constructor, 0, // constructor properties, @@ -21556,14 +22272,14 @@ JSObject *jsb_cocos2d_EaseBackInOut_prototype; bool js_cocos2dx_EaseBackInOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -21579,7 +22295,7 @@ bool js_cocos2dx_EaseBackInOut_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseBackInOut_create : wrong number of arguments"); @@ -21588,7 +22304,7 @@ bool js_cocos2dx_EaseBackInOut_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_EaseBackInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseBackInOut* cobj = new (std::nothrow) cocos2d::EaseBackInOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -21602,13 +22318,16 @@ bool js_cocos2dx_EaseBackInOut_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBackInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBackInOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -21619,7 +22338,7 @@ void js_cocos2d_EaseBackInOut_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EaseBackInOut)", obj); } -void js_register_cocos2dx_EaseBackInOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseBackInOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseBackInOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseBackInOut_class->name = "EaseBackInOut"; jsb_cocos2d_EaseBackInOut_class->addProperty = JS_PropertyStub; @@ -21633,8 +22352,8 @@ void js_register_cocos2dx_EaseBackInOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBackInOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -21648,7 +22367,7 @@ void js_register_cocos2dx_EaseBackInOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBackInOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseBackInOut_class, js_cocos2dx_EaseBackInOut_constructor, 0, // constructor properties, @@ -21679,9 +22398,9 @@ JSObject *jsb_cocos2d_EaseBezierAction_prototype; bool js_cocos2dx_EaseBezierAction_setBezierParamer(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EaseBezierAction* cobj = (cocos2d::EaseBezierAction *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EaseBezierAction_setBezierParamer : Invalid Native Object"); @@ -21690,13 +22409,13 @@ bool js_cocos2dx_EaseBezierAction_setBezierParamer(JSContext *cx, uint32_t argc, double arg1; double arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EaseBezierAction_setBezierParamer : Error processing arguments"); cobj->setBezierParamer(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -21705,14 +22424,14 @@ bool js_cocos2dx_EaseBezierAction_setBezierParamer(JSContext *cx, uint32_t argc, } bool js_cocos2dx_EaseBezierAction_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -21728,7 +22447,7 @@ bool js_cocos2dx_EaseBezierAction_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseBezierAction_create : wrong number of arguments"); @@ -21737,7 +22456,7 @@ bool js_cocos2dx_EaseBezierAction_create(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_EaseBezierAction_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseBezierAction* cobj = new (std::nothrow) cocos2d::EaseBezierAction(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -21751,13 +22470,16 @@ bool js_cocos2dx_EaseBezierAction_constructor(JSContext *cx, uint32_t argc, jsva CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBezierAction"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBezierAction"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -21770,21 +22492,21 @@ void js_cocos2d_EaseBezierAction_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseBezierAction_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseBezierAction *nobj = new (std::nothrow) cocos2d::EaseBezierAction(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBezierAction"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseBezierAction"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseBezierAction(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseBezierAction(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseBezierAction_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseBezierAction_class->name = "EaseBezierAction"; jsb_cocos2d_EaseBezierAction_class->addProperty = JS_PropertyStub; @@ -21798,8 +22520,8 @@ void js_register_cocos2dx_EaseBezierAction(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBezierAction_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -21815,7 +22537,7 @@ void js_register_cocos2dx_EaseBezierAction(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseBezierAction_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseBezierAction_class, js_cocos2dx_EaseBezierAction_constructor, 0, // constructor properties, @@ -21846,14 +22568,14 @@ JSObject *jsb_cocos2d_EaseQuadraticActionIn_prototype; bool js_cocos2dx_EaseQuadraticActionIn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -21869,7 +22591,7 @@ bool js_cocos2dx_EaseQuadraticActionIn_create(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseQuadraticActionIn_create : wrong number of arguments"); @@ -21878,7 +22600,7 @@ bool js_cocos2dx_EaseQuadraticActionIn_create(JSContext *cx, uint32_t argc, jsva bool js_cocos2dx_EaseQuadraticActionIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseQuadraticActionIn* cobj = new (std::nothrow) cocos2d::EaseQuadraticActionIn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -21892,13 +22614,16 @@ bool js_cocos2dx_EaseQuadraticActionIn_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuadraticActionIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuadraticActionIn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -21911,21 +22636,21 @@ void js_cocos2d_EaseQuadraticActionIn_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseQuadraticActionIn_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseQuadraticActionIn *nobj = new (std::nothrow) cocos2d::EaseQuadraticActionIn(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuadraticActionIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuadraticActionIn"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseQuadraticActionIn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseQuadraticActionIn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseQuadraticActionIn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseQuadraticActionIn_class->name = "EaseQuadraticActionIn"; jsb_cocos2d_EaseQuadraticActionIn_class->addProperty = JS_PropertyStub; @@ -21939,8 +22664,8 @@ void js_register_cocos2dx_EaseQuadraticActionIn(JSContext *cx, JSObject *global) jsb_cocos2d_EaseQuadraticActionIn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -21955,7 +22680,7 @@ void js_register_cocos2dx_EaseQuadraticActionIn(JSContext *cx, JSObject *global) jsb_cocos2d_EaseQuadraticActionIn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseQuadraticActionIn_class, js_cocos2dx_EaseQuadraticActionIn_constructor, 0, // constructor properties, @@ -21986,14 +22711,14 @@ JSObject *jsb_cocos2d_EaseQuadraticActionOut_prototype; bool js_cocos2dx_EaseQuadraticActionOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -22009,7 +22734,7 @@ bool js_cocos2dx_EaseQuadraticActionOut_create(JSContext *cx, uint32_t argc, jsv jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseQuadraticActionOut_create : wrong number of arguments"); @@ -22018,7 +22743,7 @@ bool js_cocos2dx_EaseQuadraticActionOut_create(JSContext *cx, uint32_t argc, jsv bool js_cocos2dx_EaseQuadraticActionOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseQuadraticActionOut* cobj = new (std::nothrow) cocos2d::EaseQuadraticActionOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -22032,13 +22757,16 @@ bool js_cocos2dx_EaseQuadraticActionOut_constructor(JSContext *cx, uint32_t argc CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuadraticActionOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuadraticActionOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -22051,21 +22779,21 @@ void js_cocos2d_EaseQuadraticActionOut_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseQuadraticActionOut_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseQuadraticActionOut *nobj = new (std::nothrow) cocos2d::EaseQuadraticActionOut(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuadraticActionOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuadraticActionOut"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseQuadraticActionOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseQuadraticActionOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseQuadraticActionOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseQuadraticActionOut_class->name = "EaseQuadraticActionOut"; jsb_cocos2d_EaseQuadraticActionOut_class->addProperty = JS_PropertyStub; @@ -22079,8 +22807,8 @@ void js_register_cocos2dx_EaseQuadraticActionOut(JSContext *cx, JSObject *global jsb_cocos2d_EaseQuadraticActionOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -22095,7 +22823,7 @@ void js_register_cocos2dx_EaseQuadraticActionOut(JSContext *cx, JSObject *global jsb_cocos2d_EaseQuadraticActionOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseQuadraticActionOut_class, js_cocos2dx_EaseQuadraticActionOut_constructor, 0, // constructor properties, @@ -22126,14 +22854,14 @@ JSObject *jsb_cocos2d_EaseQuadraticActionInOut_prototype; bool js_cocos2dx_EaseQuadraticActionInOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -22149,7 +22877,7 @@ bool js_cocos2dx_EaseQuadraticActionInOut_create(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseQuadraticActionInOut_create : wrong number of arguments"); @@ -22158,7 +22886,7 @@ bool js_cocos2dx_EaseQuadraticActionInOut_create(JSContext *cx, uint32_t argc, j bool js_cocos2dx_EaseQuadraticActionInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseQuadraticActionInOut* cobj = new (std::nothrow) cocos2d::EaseQuadraticActionInOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -22172,13 +22900,16 @@ bool js_cocos2dx_EaseQuadraticActionInOut_constructor(JSContext *cx, uint32_t ar CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuadraticActionInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuadraticActionInOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -22191,21 +22922,21 @@ void js_cocos2d_EaseQuadraticActionInOut_finalize(JSFreeOp *fop, JSObject *obj) static bool js_cocos2d_EaseQuadraticActionInOut_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseQuadraticActionInOut *nobj = new (std::nothrow) cocos2d::EaseQuadraticActionInOut(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuadraticActionInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuadraticActionInOut"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseQuadraticActionInOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseQuadraticActionInOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseQuadraticActionInOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseQuadraticActionInOut_class->name = "EaseQuadraticActionInOut"; jsb_cocos2d_EaseQuadraticActionInOut_class->addProperty = JS_PropertyStub; @@ -22219,8 +22950,8 @@ void js_register_cocos2dx_EaseQuadraticActionInOut(JSContext *cx, JSObject *glob jsb_cocos2d_EaseQuadraticActionInOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -22235,7 +22966,7 @@ void js_register_cocos2dx_EaseQuadraticActionInOut(JSContext *cx, JSObject *glob jsb_cocos2d_EaseQuadraticActionInOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseQuadraticActionInOut_class, js_cocos2dx_EaseQuadraticActionInOut_constructor, 0, // constructor properties, @@ -22266,14 +22997,14 @@ JSObject *jsb_cocos2d_EaseQuarticActionIn_prototype; bool js_cocos2dx_EaseQuarticActionIn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -22289,7 +23020,7 @@ bool js_cocos2dx_EaseQuarticActionIn_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseQuarticActionIn_create : wrong number of arguments"); @@ -22298,7 +23029,7 @@ bool js_cocos2dx_EaseQuarticActionIn_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_EaseQuarticActionIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseQuarticActionIn* cobj = new (std::nothrow) cocos2d::EaseQuarticActionIn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -22312,13 +23043,16 @@ bool js_cocos2dx_EaseQuarticActionIn_constructor(JSContext *cx, uint32_t argc, j CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuarticActionIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuarticActionIn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -22331,21 +23065,21 @@ void js_cocos2d_EaseQuarticActionIn_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseQuarticActionIn_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseQuarticActionIn *nobj = new (std::nothrow) cocos2d::EaseQuarticActionIn(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuarticActionIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuarticActionIn"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseQuarticActionIn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseQuarticActionIn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseQuarticActionIn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseQuarticActionIn_class->name = "EaseQuarticActionIn"; jsb_cocos2d_EaseQuarticActionIn_class->addProperty = JS_PropertyStub; @@ -22359,8 +23093,8 @@ void js_register_cocos2dx_EaseQuarticActionIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseQuarticActionIn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -22375,7 +23109,7 @@ void js_register_cocos2dx_EaseQuarticActionIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseQuarticActionIn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseQuarticActionIn_class, js_cocos2dx_EaseQuarticActionIn_constructor, 0, // constructor properties, @@ -22406,14 +23140,14 @@ JSObject *jsb_cocos2d_EaseQuarticActionOut_prototype; bool js_cocos2dx_EaseQuarticActionOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -22429,7 +23163,7 @@ bool js_cocos2dx_EaseQuarticActionOut_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseQuarticActionOut_create : wrong number of arguments"); @@ -22438,7 +23172,7 @@ bool js_cocos2dx_EaseQuarticActionOut_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_EaseQuarticActionOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseQuarticActionOut* cobj = new (std::nothrow) cocos2d::EaseQuarticActionOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -22452,13 +23186,16 @@ bool js_cocos2dx_EaseQuarticActionOut_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuarticActionOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuarticActionOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -22471,21 +23208,21 @@ void js_cocos2d_EaseQuarticActionOut_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseQuarticActionOut_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseQuarticActionOut *nobj = new (std::nothrow) cocos2d::EaseQuarticActionOut(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuarticActionOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuarticActionOut"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseQuarticActionOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseQuarticActionOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseQuarticActionOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseQuarticActionOut_class->name = "EaseQuarticActionOut"; jsb_cocos2d_EaseQuarticActionOut_class->addProperty = JS_PropertyStub; @@ -22499,8 +23236,8 @@ void js_register_cocos2dx_EaseQuarticActionOut(JSContext *cx, JSObject *global) jsb_cocos2d_EaseQuarticActionOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -22515,7 +23252,7 @@ void js_register_cocos2dx_EaseQuarticActionOut(JSContext *cx, JSObject *global) jsb_cocos2d_EaseQuarticActionOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseQuarticActionOut_class, js_cocos2dx_EaseQuarticActionOut_constructor, 0, // constructor properties, @@ -22546,14 +23283,14 @@ JSObject *jsb_cocos2d_EaseQuarticActionInOut_prototype; bool js_cocos2dx_EaseQuarticActionInOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -22569,7 +23306,7 @@ bool js_cocos2dx_EaseQuarticActionInOut_create(JSContext *cx, uint32_t argc, jsv jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseQuarticActionInOut_create : wrong number of arguments"); @@ -22578,7 +23315,7 @@ bool js_cocos2dx_EaseQuarticActionInOut_create(JSContext *cx, uint32_t argc, jsv bool js_cocos2dx_EaseQuarticActionInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseQuarticActionInOut* cobj = new (std::nothrow) cocos2d::EaseQuarticActionInOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -22592,13 +23329,16 @@ bool js_cocos2dx_EaseQuarticActionInOut_constructor(JSContext *cx, uint32_t argc CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuarticActionInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuarticActionInOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -22611,21 +23351,21 @@ void js_cocos2d_EaseQuarticActionInOut_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseQuarticActionInOut_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseQuarticActionInOut *nobj = new (std::nothrow) cocos2d::EaseQuarticActionInOut(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuarticActionInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuarticActionInOut"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseQuarticActionInOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseQuarticActionInOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseQuarticActionInOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseQuarticActionInOut_class->name = "EaseQuarticActionInOut"; jsb_cocos2d_EaseQuarticActionInOut_class->addProperty = JS_PropertyStub; @@ -22639,8 +23379,8 @@ void js_register_cocos2dx_EaseQuarticActionInOut(JSContext *cx, JSObject *global jsb_cocos2d_EaseQuarticActionInOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -22655,7 +23395,7 @@ void js_register_cocos2dx_EaseQuarticActionInOut(JSContext *cx, JSObject *global jsb_cocos2d_EaseQuarticActionInOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseQuarticActionInOut_class, js_cocos2dx_EaseQuarticActionInOut_constructor, 0, // constructor properties, @@ -22686,14 +23426,14 @@ JSObject *jsb_cocos2d_EaseQuinticActionIn_prototype; bool js_cocos2dx_EaseQuinticActionIn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -22709,7 +23449,7 @@ bool js_cocos2dx_EaseQuinticActionIn_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseQuinticActionIn_create : wrong number of arguments"); @@ -22718,7 +23458,7 @@ bool js_cocos2dx_EaseQuinticActionIn_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_EaseQuinticActionIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseQuinticActionIn* cobj = new (std::nothrow) cocos2d::EaseQuinticActionIn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -22732,13 +23472,16 @@ bool js_cocos2dx_EaseQuinticActionIn_constructor(JSContext *cx, uint32_t argc, j CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuinticActionIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuinticActionIn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -22751,21 +23494,21 @@ void js_cocos2d_EaseQuinticActionIn_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseQuinticActionIn_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseQuinticActionIn *nobj = new (std::nothrow) cocos2d::EaseQuinticActionIn(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuinticActionIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuinticActionIn"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseQuinticActionIn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseQuinticActionIn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseQuinticActionIn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseQuinticActionIn_class->name = "EaseQuinticActionIn"; jsb_cocos2d_EaseQuinticActionIn_class->addProperty = JS_PropertyStub; @@ -22779,8 +23522,8 @@ void js_register_cocos2dx_EaseQuinticActionIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseQuinticActionIn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -22795,7 +23538,7 @@ void js_register_cocos2dx_EaseQuinticActionIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseQuinticActionIn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseQuinticActionIn_class, js_cocos2dx_EaseQuinticActionIn_constructor, 0, // constructor properties, @@ -22826,14 +23569,14 @@ JSObject *jsb_cocos2d_EaseQuinticActionOut_prototype; bool js_cocos2dx_EaseQuinticActionOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -22849,7 +23592,7 @@ bool js_cocos2dx_EaseQuinticActionOut_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseQuinticActionOut_create : wrong number of arguments"); @@ -22858,7 +23601,7 @@ bool js_cocos2dx_EaseQuinticActionOut_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_EaseQuinticActionOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseQuinticActionOut* cobj = new (std::nothrow) cocos2d::EaseQuinticActionOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -22872,13 +23615,16 @@ bool js_cocos2dx_EaseQuinticActionOut_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuinticActionOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuinticActionOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -22891,21 +23637,21 @@ void js_cocos2d_EaseQuinticActionOut_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseQuinticActionOut_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseQuinticActionOut *nobj = new (std::nothrow) cocos2d::EaseQuinticActionOut(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuinticActionOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuinticActionOut"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseQuinticActionOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseQuinticActionOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseQuinticActionOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseQuinticActionOut_class->name = "EaseQuinticActionOut"; jsb_cocos2d_EaseQuinticActionOut_class->addProperty = JS_PropertyStub; @@ -22919,8 +23665,8 @@ void js_register_cocos2dx_EaseQuinticActionOut(JSContext *cx, JSObject *global) jsb_cocos2d_EaseQuinticActionOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -22935,7 +23681,7 @@ void js_register_cocos2dx_EaseQuinticActionOut(JSContext *cx, JSObject *global) jsb_cocos2d_EaseQuinticActionOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseQuinticActionOut_class, js_cocos2dx_EaseQuinticActionOut_constructor, 0, // constructor properties, @@ -22966,14 +23712,14 @@ JSObject *jsb_cocos2d_EaseQuinticActionInOut_prototype; bool js_cocos2dx_EaseQuinticActionInOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -22989,7 +23735,7 @@ bool js_cocos2dx_EaseQuinticActionInOut_create(JSContext *cx, uint32_t argc, jsv jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseQuinticActionInOut_create : wrong number of arguments"); @@ -22998,7 +23744,7 @@ bool js_cocos2dx_EaseQuinticActionInOut_create(JSContext *cx, uint32_t argc, jsv bool js_cocos2dx_EaseQuinticActionInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseQuinticActionInOut* cobj = new (std::nothrow) cocos2d::EaseQuinticActionInOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -23012,13 +23758,16 @@ bool js_cocos2dx_EaseQuinticActionInOut_constructor(JSContext *cx, uint32_t argc CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuinticActionInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuinticActionInOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -23031,21 +23780,21 @@ void js_cocos2d_EaseQuinticActionInOut_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseQuinticActionInOut_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseQuinticActionInOut *nobj = new (std::nothrow) cocos2d::EaseQuinticActionInOut(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuinticActionInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseQuinticActionInOut"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseQuinticActionInOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseQuinticActionInOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseQuinticActionInOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseQuinticActionInOut_class->name = "EaseQuinticActionInOut"; jsb_cocos2d_EaseQuinticActionInOut_class->addProperty = JS_PropertyStub; @@ -23059,8 +23808,8 @@ void js_register_cocos2dx_EaseQuinticActionInOut(JSContext *cx, JSObject *global jsb_cocos2d_EaseQuinticActionInOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -23075,7 +23824,7 @@ void js_register_cocos2dx_EaseQuinticActionInOut(JSContext *cx, JSObject *global jsb_cocos2d_EaseQuinticActionInOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseQuinticActionInOut_class, js_cocos2dx_EaseQuinticActionInOut_constructor, 0, // constructor properties, @@ -23106,14 +23855,14 @@ JSObject *jsb_cocos2d_EaseCircleActionIn_prototype; bool js_cocos2dx_EaseCircleActionIn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -23129,7 +23878,7 @@ bool js_cocos2dx_EaseCircleActionIn_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseCircleActionIn_create : wrong number of arguments"); @@ -23138,7 +23887,7 @@ bool js_cocos2dx_EaseCircleActionIn_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_EaseCircleActionIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseCircleActionIn* cobj = new (std::nothrow) cocos2d::EaseCircleActionIn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -23152,13 +23901,16 @@ bool js_cocos2dx_EaseCircleActionIn_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCircleActionIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCircleActionIn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -23171,21 +23923,21 @@ void js_cocos2d_EaseCircleActionIn_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseCircleActionIn_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseCircleActionIn *nobj = new (std::nothrow) cocos2d::EaseCircleActionIn(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCircleActionIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCircleActionIn"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseCircleActionIn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseCircleActionIn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseCircleActionIn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseCircleActionIn_class->name = "EaseCircleActionIn"; jsb_cocos2d_EaseCircleActionIn_class->addProperty = JS_PropertyStub; @@ -23199,8 +23951,8 @@ void js_register_cocos2dx_EaseCircleActionIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseCircleActionIn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -23215,7 +23967,7 @@ void js_register_cocos2dx_EaseCircleActionIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseCircleActionIn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseCircleActionIn_class, js_cocos2dx_EaseCircleActionIn_constructor, 0, // constructor properties, @@ -23246,14 +23998,14 @@ JSObject *jsb_cocos2d_EaseCircleActionOut_prototype; bool js_cocos2dx_EaseCircleActionOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -23269,7 +24021,7 @@ bool js_cocos2dx_EaseCircleActionOut_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseCircleActionOut_create : wrong number of arguments"); @@ -23278,7 +24030,7 @@ bool js_cocos2dx_EaseCircleActionOut_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_EaseCircleActionOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseCircleActionOut* cobj = new (std::nothrow) cocos2d::EaseCircleActionOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -23292,13 +24044,16 @@ bool js_cocos2dx_EaseCircleActionOut_constructor(JSContext *cx, uint32_t argc, j CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCircleActionOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCircleActionOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -23311,21 +24066,21 @@ void js_cocos2d_EaseCircleActionOut_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseCircleActionOut_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseCircleActionOut *nobj = new (std::nothrow) cocos2d::EaseCircleActionOut(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCircleActionOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCircleActionOut"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseCircleActionOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseCircleActionOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseCircleActionOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseCircleActionOut_class->name = "EaseCircleActionOut"; jsb_cocos2d_EaseCircleActionOut_class->addProperty = JS_PropertyStub; @@ -23339,8 +24094,8 @@ void js_register_cocos2dx_EaseCircleActionOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseCircleActionOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -23355,7 +24110,7 @@ void js_register_cocos2dx_EaseCircleActionOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseCircleActionOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseCircleActionOut_class, js_cocos2dx_EaseCircleActionOut_constructor, 0, // constructor properties, @@ -23386,14 +24141,14 @@ JSObject *jsb_cocos2d_EaseCircleActionInOut_prototype; bool js_cocos2dx_EaseCircleActionInOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -23409,7 +24164,7 @@ bool js_cocos2dx_EaseCircleActionInOut_create(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseCircleActionInOut_create : wrong number of arguments"); @@ -23418,7 +24173,7 @@ bool js_cocos2dx_EaseCircleActionInOut_create(JSContext *cx, uint32_t argc, jsva bool js_cocos2dx_EaseCircleActionInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseCircleActionInOut* cobj = new (std::nothrow) cocos2d::EaseCircleActionInOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -23432,13 +24187,16 @@ bool js_cocos2dx_EaseCircleActionInOut_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCircleActionInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCircleActionInOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -23451,21 +24209,21 @@ void js_cocos2d_EaseCircleActionInOut_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseCircleActionInOut_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseCircleActionInOut *nobj = new (std::nothrow) cocos2d::EaseCircleActionInOut(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCircleActionInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCircleActionInOut"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseCircleActionInOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseCircleActionInOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseCircleActionInOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseCircleActionInOut_class->name = "EaseCircleActionInOut"; jsb_cocos2d_EaseCircleActionInOut_class->addProperty = JS_PropertyStub; @@ -23479,8 +24237,8 @@ void js_register_cocos2dx_EaseCircleActionInOut(JSContext *cx, JSObject *global) jsb_cocos2d_EaseCircleActionInOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -23495,7 +24253,7 @@ void js_register_cocos2dx_EaseCircleActionInOut(JSContext *cx, JSObject *global) jsb_cocos2d_EaseCircleActionInOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseCircleActionInOut_class, js_cocos2dx_EaseCircleActionInOut_constructor, 0, // constructor properties, @@ -23526,14 +24284,14 @@ JSObject *jsb_cocos2d_EaseCubicActionIn_prototype; bool js_cocos2dx_EaseCubicActionIn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -23549,7 +24307,7 @@ bool js_cocos2dx_EaseCubicActionIn_create(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseCubicActionIn_create : wrong number of arguments"); @@ -23558,7 +24316,7 @@ bool js_cocos2dx_EaseCubicActionIn_create(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_EaseCubicActionIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseCubicActionIn* cobj = new (std::nothrow) cocos2d::EaseCubicActionIn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -23572,13 +24330,16 @@ bool js_cocos2dx_EaseCubicActionIn_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCubicActionIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCubicActionIn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -23591,21 +24352,21 @@ void js_cocos2d_EaseCubicActionIn_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseCubicActionIn_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseCubicActionIn *nobj = new (std::nothrow) cocos2d::EaseCubicActionIn(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCubicActionIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCubicActionIn"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseCubicActionIn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseCubicActionIn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseCubicActionIn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseCubicActionIn_class->name = "EaseCubicActionIn"; jsb_cocos2d_EaseCubicActionIn_class->addProperty = JS_PropertyStub; @@ -23619,8 +24380,8 @@ void js_register_cocos2dx_EaseCubicActionIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseCubicActionIn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -23635,7 +24396,7 @@ void js_register_cocos2dx_EaseCubicActionIn(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseCubicActionIn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseCubicActionIn_class, js_cocos2dx_EaseCubicActionIn_constructor, 0, // constructor properties, @@ -23666,14 +24427,14 @@ JSObject *jsb_cocos2d_EaseCubicActionOut_prototype; bool js_cocos2dx_EaseCubicActionOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -23689,7 +24450,7 @@ bool js_cocos2dx_EaseCubicActionOut_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseCubicActionOut_create : wrong number of arguments"); @@ -23698,7 +24459,7 @@ bool js_cocos2dx_EaseCubicActionOut_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_EaseCubicActionOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseCubicActionOut* cobj = new (std::nothrow) cocos2d::EaseCubicActionOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -23712,13 +24473,16 @@ bool js_cocos2dx_EaseCubicActionOut_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCubicActionOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCubicActionOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -23731,21 +24495,21 @@ void js_cocos2d_EaseCubicActionOut_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseCubicActionOut_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseCubicActionOut *nobj = new (std::nothrow) cocos2d::EaseCubicActionOut(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCubicActionOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCubicActionOut"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseCubicActionOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseCubicActionOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseCubicActionOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseCubicActionOut_class->name = "EaseCubicActionOut"; jsb_cocos2d_EaseCubicActionOut_class->addProperty = JS_PropertyStub; @@ -23759,8 +24523,8 @@ void js_register_cocos2dx_EaseCubicActionOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseCubicActionOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -23775,7 +24539,7 @@ void js_register_cocos2dx_EaseCubicActionOut(JSContext *cx, JSObject *global) { jsb_cocos2d_EaseCubicActionOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseCubicActionOut_class, js_cocos2dx_EaseCubicActionOut_constructor, 0, // constructor properties, @@ -23806,14 +24570,14 @@ JSObject *jsb_cocos2d_EaseCubicActionInOut_prototype; bool js_cocos2dx_EaseCubicActionInOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -23829,7 +24593,7 @@ bool js_cocos2dx_EaseCubicActionInOut_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_EaseCubicActionInOut_create : wrong number of arguments"); @@ -23838,7 +24602,7 @@ bool js_cocos2dx_EaseCubicActionInOut_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_EaseCubicActionInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::EaseCubicActionInOut* cobj = new (std::nothrow) cocos2d::EaseCubicActionInOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -23852,13 +24616,16 @@ bool js_cocos2dx_EaseCubicActionInOut_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCubicActionInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCubicActionInOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -23871,21 +24638,21 @@ void js_cocos2d_EaseCubicActionInOut_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_EaseCubicActionInOut_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::EaseCubicActionInOut *nobj = new (std::nothrow) cocos2d::EaseCubicActionInOut(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCubicActionInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EaseCubicActionInOut"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_EaseCubicActionInOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_EaseCubicActionInOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_EaseCubicActionInOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_EaseCubicActionInOut_class->name = "EaseCubicActionInOut"; jsb_cocos2d_EaseCubicActionInOut_class->addProperty = JS_PropertyStub; @@ -23899,8 +24666,8 @@ void js_register_cocos2dx_EaseCubicActionInOut(JSContext *cx, JSObject *global) jsb_cocos2d_EaseCubicActionInOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -23915,7 +24682,7 @@ void js_register_cocos2dx_EaseCubicActionInOut(JSContext *cx, JSObject *global) jsb_cocos2d_EaseCubicActionInOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionEase_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionEase_prototype), jsb_cocos2d_EaseCubicActionInOut_class, js_cocos2dx_EaseCubicActionInOut_constructor, 0, // constructor properties, @@ -23951,7 +24718,7 @@ void js_cocos2d_ActionInstant_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ActionInstant)", obj); } -void js_register_cocos2dx_ActionInstant(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ActionInstant(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ActionInstant_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ActionInstant_class->name = "ActionInstant"; jsb_cocos2d_ActionInstant_class->addProperty = JS_PropertyStub; @@ -23965,8 +24732,8 @@ void js_register_cocos2dx_ActionInstant(JSContext *cx, JSObject *global) { jsb_cocos2d_ActionInstant_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -23977,7 +24744,7 @@ void js_register_cocos2dx_ActionInstant(JSContext *cx, JSObject *global) { jsb_cocos2d_ActionInstant_prototype = JS_InitClass( cx, global, - jsb_cocos2d_FiniteTimeAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_FiniteTimeAction_prototype), jsb_cocos2d_ActionInstant_class, empty_constructor, 0, properties, @@ -24008,6 +24775,7 @@ JSObject *jsb_cocos2d_Show_prototype; bool js_cocos2dx_Show_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Show* ret = cocos2d::Show::create(); jsval jsret = JSVAL_NULL; @@ -24019,7 +24787,7 @@ bool js_cocos2dx_Show_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Show_create : wrong number of arguments"); @@ -24028,7 +24796,7 @@ bool js_cocos2dx_Show_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Show_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Show* cobj = new (std::nothrow) cocos2d::Show(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -24042,13 +24810,16 @@ bool js_cocos2dx_Show_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Show"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Show"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -24059,7 +24830,7 @@ void js_cocos2d_Show_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Show)", obj); } -void js_register_cocos2dx_Show(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Show(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Show_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Show_class->name = "Show"; jsb_cocos2d_Show_class->addProperty = JS_PropertyStub; @@ -24073,8 +24844,8 @@ void js_register_cocos2dx_Show(JSContext *cx, JSObject *global) { jsb_cocos2d_Show_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -24088,7 +24859,7 @@ void js_register_cocos2dx_Show(JSContext *cx, JSObject *global) { jsb_cocos2d_Show_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInstant_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInstant_prototype), jsb_cocos2d_Show_class, js_cocos2dx_Show_constructor, 0, // constructor properties, @@ -24119,6 +24890,7 @@ JSObject *jsb_cocos2d_Hide_prototype; bool js_cocos2dx_Hide_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Hide* ret = cocos2d::Hide::create(); jsval jsret = JSVAL_NULL; @@ -24130,7 +24902,7 @@ bool js_cocos2dx_Hide_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Hide_create : wrong number of arguments"); @@ -24139,7 +24911,7 @@ bool js_cocos2dx_Hide_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Hide_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Hide* cobj = new (std::nothrow) cocos2d::Hide(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -24153,13 +24925,16 @@ bool js_cocos2dx_Hide_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Hide"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Hide"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -24170,7 +24945,7 @@ void js_cocos2d_Hide_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Hide)", obj); } -void js_register_cocos2dx_Hide(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Hide(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Hide_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Hide_class->name = "Hide"; jsb_cocos2d_Hide_class->addProperty = JS_PropertyStub; @@ -24184,8 +24959,8 @@ void js_register_cocos2dx_Hide(JSContext *cx, JSObject *global) { jsb_cocos2d_Hide_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -24199,7 +24974,7 @@ void js_register_cocos2dx_Hide(JSContext *cx, JSObject *global) { jsb_cocos2d_Hide_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInstant_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInstant_prototype), jsb_cocos2d_Hide_class, js_cocos2dx_Hide_constructor, 0, // constructor properties, @@ -24230,6 +25005,7 @@ JSObject *jsb_cocos2d_ToggleVisibility_prototype; bool js_cocos2dx_ToggleVisibility_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ToggleVisibility* ret = cocos2d::ToggleVisibility::create(); jsval jsret = JSVAL_NULL; @@ -24241,7 +25017,7 @@ bool js_cocos2dx_ToggleVisibility_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ToggleVisibility_create : wrong number of arguments"); @@ -24250,7 +25026,7 @@ bool js_cocos2dx_ToggleVisibility_create(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_ToggleVisibility_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ToggleVisibility* cobj = new (std::nothrow) cocos2d::ToggleVisibility(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -24264,13 +25040,16 @@ bool js_cocos2dx_ToggleVisibility_constructor(JSContext *cx, uint32_t argc, jsva CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ToggleVisibility"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ToggleVisibility"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -24281,7 +25060,7 @@ void js_cocos2d_ToggleVisibility_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ToggleVisibility)", obj); } -void js_register_cocos2dx_ToggleVisibility(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ToggleVisibility(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ToggleVisibility_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ToggleVisibility_class->name = "ToggleVisibility"; jsb_cocos2d_ToggleVisibility_class->addProperty = JS_PropertyStub; @@ -24295,8 +25074,8 @@ void js_register_cocos2dx_ToggleVisibility(JSContext *cx, JSObject *global) { jsb_cocos2d_ToggleVisibility_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -24310,7 +25089,7 @@ void js_register_cocos2dx_ToggleVisibility(JSContext *cx, JSObject *global) { jsb_cocos2d_ToggleVisibility_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInstant_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInstant_prototype), jsb_cocos2d_ToggleVisibility_class, js_cocos2dx_ToggleVisibility_constructor, 0, // constructor properties, @@ -24341,20 +25120,20 @@ JSObject *jsb_cocos2d_RemoveSelf_prototype; bool js_cocos2dx_RemoveSelf_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RemoveSelf* cobj = (cocos2d::RemoveSelf *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RemoveSelf_init : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RemoveSelf_init : Error processing arguments"); bool ret = cobj->init(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -24363,7 +25142,7 @@ bool js_cocos2dx_RemoveSelf_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_RemoveSelf_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 0) { cocos2d::RemoveSelf* ret = cocos2d::RemoveSelf::create(); @@ -24376,12 +25155,12 @@ bool js_cocos2dx_RemoveSelf_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RemoveSelf_create : Error processing arguments"); cocos2d::RemoveSelf* ret = cocos2d::RemoveSelf::create(arg0); jsval jsret = JSVAL_NULL; @@ -24393,7 +25172,7 @@ bool js_cocos2dx_RemoveSelf_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_RemoveSelf_create : wrong number of arguments"); @@ -24402,7 +25181,7 @@ bool js_cocos2dx_RemoveSelf_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_RemoveSelf_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::RemoveSelf* cobj = new (std::nothrow) cocos2d::RemoveSelf(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -24416,13 +25195,16 @@ bool js_cocos2dx_RemoveSelf_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::RemoveSelf"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::RemoveSelf"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -24433,7 +25215,7 @@ void js_cocos2d_RemoveSelf_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (RemoveSelf)", obj); } -void js_register_cocos2dx_RemoveSelf(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_RemoveSelf(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_RemoveSelf_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_RemoveSelf_class->name = "RemoveSelf"; jsb_cocos2d_RemoveSelf_class->addProperty = JS_PropertyStub; @@ -24447,8 +25229,8 @@ void js_register_cocos2dx_RemoveSelf(JSContext *cx, JSObject *global) { jsb_cocos2d_RemoveSelf_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -24463,7 +25245,7 @@ void js_register_cocos2dx_RemoveSelf(JSContext *cx, JSObject *global) { jsb_cocos2d_RemoveSelf_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInstant_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInstant_prototype), jsb_cocos2d_RemoveSelf_class, js_cocos2dx_RemoveSelf_constructor, 0, // constructor properties, @@ -24494,20 +25276,20 @@ JSObject *jsb_cocos2d_FlipX_prototype; bool js_cocos2dx_FlipX_initWithFlipX(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FlipX* cobj = (cocos2d::FlipX *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FlipX_initWithFlipX : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FlipX_initWithFlipX : Error processing arguments"); bool ret = cobj->initWithFlipX(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -24516,11 +25298,11 @@ bool js_cocos2dx_FlipX_initWithFlipX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_FlipX_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FlipX_create : Error processing arguments"); cocos2d::FlipX* ret = cocos2d::FlipX::create(arg0); jsval jsret = JSVAL_NULL; @@ -24532,7 +25314,7 @@ bool js_cocos2dx_FlipX_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FlipX_create : wrong number of arguments"); @@ -24541,7 +25323,7 @@ bool js_cocos2dx_FlipX_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_FlipX_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::FlipX* cobj = new (std::nothrow) cocos2d::FlipX(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -24555,13 +25337,16 @@ bool js_cocos2dx_FlipX_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::FlipX"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::FlipX"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -24572,7 +25357,7 @@ void js_cocos2d_FlipX_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (FlipX)", obj); } -void js_register_cocos2dx_FlipX(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_FlipX(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_FlipX_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_FlipX_class->name = "FlipX"; jsb_cocos2d_FlipX_class->addProperty = JS_PropertyStub; @@ -24586,8 +25371,8 @@ void js_register_cocos2dx_FlipX(JSContext *cx, JSObject *global) { jsb_cocos2d_FlipX_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -24602,7 +25387,7 @@ void js_register_cocos2dx_FlipX(JSContext *cx, JSObject *global) { jsb_cocos2d_FlipX_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInstant_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInstant_prototype), jsb_cocos2d_FlipX_class, js_cocos2dx_FlipX_constructor, 0, // constructor properties, @@ -24633,20 +25418,20 @@ JSObject *jsb_cocos2d_FlipY_prototype; bool js_cocos2dx_FlipY_initWithFlipY(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FlipY* cobj = (cocos2d::FlipY *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FlipY_initWithFlipY : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FlipY_initWithFlipY : Error processing arguments"); bool ret = cobj->initWithFlipY(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -24655,11 +25440,11 @@ bool js_cocos2dx_FlipY_initWithFlipY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_FlipY_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FlipY_create : Error processing arguments"); cocos2d::FlipY* ret = cocos2d::FlipY::create(arg0); jsval jsret = JSVAL_NULL; @@ -24671,7 +25456,7 @@ bool js_cocos2dx_FlipY_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FlipY_create : wrong number of arguments"); @@ -24680,7 +25465,7 @@ bool js_cocos2dx_FlipY_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_FlipY_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::FlipY* cobj = new (std::nothrow) cocos2d::FlipY(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -24694,13 +25479,16 @@ bool js_cocos2dx_FlipY_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::FlipY"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::FlipY"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -24711,7 +25499,7 @@ void js_cocos2d_FlipY_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (FlipY)", obj); } -void js_register_cocos2dx_FlipY(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_FlipY(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_FlipY_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_FlipY_class->name = "FlipY"; jsb_cocos2d_FlipY_class->addProperty = JS_PropertyStub; @@ -24725,8 +25513,8 @@ void js_register_cocos2dx_FlipY(JSContext *cx, JSObject *global) { jsb_cocos2d_FlipY_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -24741,7 +25529,7 @@ void js_register_cocos2dx_FlipY(JSContext *cx, JSObject *global) { jsb_cocos2d_FlipY_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInstant_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInstant_prototype), jsb_cocos2d_FlipY_class, js_cocos2dx_FlipY_constructor, 0, // constructor properties, @@ -24772,20 +25560,20 @@ JSObject *jsb_cocos2d_Place_prototype; bool js_cocos2dx_Place_initWithPosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Place* cobj = (cocos2d::Place *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Place_initWithPosition : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Place_initWithPosition : Error processing arguments"); bool ret = cobj->initWithPosition(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -24794,11 +25582,11 @@ bool js_cocos2dx_Place_initWithPosition(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Place_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Place_create : Error processing arguments"); cocos2d::Place* ret = cocos2d::Place::create(arg0); jsval jsret = JSVAL_NULL; @@ -24810,7 +25598,7 @@ bool js_cocos2dx_Place_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Place_create : wrong number of arguments"); @@ -24819,7 +25607,7 @@ bool js_cocos2dx_Place_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Place_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Place* cobj = new (std::nothrow) cocos2d::Place(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -24833,13 +25621,16 @@ bool js_cocos2dx_Place_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Place"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Place"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -24850,7 +25641,7 @@ void js_cocos2d_Place_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Place)", obj); } -void js_register_cocos2dx_Place(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Place(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Place_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Place_class->name = "Place"; jsb_cocos2d_Place_class->addProperty = JS_PropertyStub; @@ -24864,8 +25655,8 @@ void js_register_cocos2dx_Place(JSContext *cx, JSObject *global) { jsb_cocos2d_Place_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -24880,7 +25671,7 @@ void js_register_cocos2dx_Place(JSContext *cx, JSObject *global) { jsb_cocos2d_Place_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInstant_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInstant_prototype), jsb_cocos2d_Place_class, js_cocos2dx_Place_constructor, 0, // constructor properties, @@ -24911,13 +25702,14 @@ JSObject *jsb_cocos2d_CallFunc_prototype; bool js_cocos2dx_CallFunc_execute(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::CallFunc* cobj = (cocos2d::CallFunc *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_CallFunc_execute : Invalid Native Object"); if (argc == 0) { cobj->execute(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -24926,7 +25718,7 @@ bool js_cocos2dx_CallFunc_execute(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_CallFunc_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::CallFunc* cobj = new (std::nothrow) cocos2d::CallFunc(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -24940,13 +25732,16 @@ bool js_cocos2dx_CallFunc_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::CallFunc"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::CallFunc"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -24957,7 +25752,7 @@ void js_cocos2d_CallFunc_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (CallFunc)", obj); } -void js_register_cocos2dx_CallFunc(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_CallFunc(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_CallFunc_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_CallFunc_class->name = "_CallFunc"; jsb_cocos2d_CallFunc_class->addProperty = JS_PropertyStub; @@ -24971,8 +25766,8 @@ void js_register_cocos2dx_CallFunc(JSContext *cx, JSObject *global) { jsb_cocos2d_CallFunc_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -24984,7 +25779,7 @@ void js_register_cocos2dx_CallFunc(JSContext *cx, JSObject *global) { jsb_cocos2d_CallFunc_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInstant_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInstant_prototype), jsb_cocos2d_CallFunc_class, js_cocos2dx_CallFunc_constructor, 0, // constructor properties, @@ -25015,7 +25810,7 @@ JSObject *jsb_cocos2d_CallFuncN_prototype; bool js_cocos2dx_CallFuncN_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::CallFuncN* cobj = new (std::nothrow) cocos2d::CallFuncN(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -25029,13 +25824,16 @@ bool js_cocos2dx_CallFuncN_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::CallFuncN"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::CallFuncN"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -25046,7 +25844,7 @@ void js_cocos2d_CallFuncN_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (CallFuncN)", obj); } -void js_register_cocos2dx_CallFuncN(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_CallFuncN(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_CallFuncN_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_CallFuncN_class->name = "CallFunc"; jsb_cocos2d_CallFuncN_class->addProperty = JS_PropertyStub; @@ -25060,8 +25858,8 @@ void js_register_cocos2dx_CallFuncN(JSContext *cx, JSObject *global) { jsb_cocos2d_CallFuncN_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -25072,7 +25870,7 @@ void js_register_cocos2dx_CallFuncN(JSContext *cx, JSObject *global) { jsb_cocos2d_CallFuncN_prototype = JS_InitClass( cx, global, - jsb_cocos2d_CallFunc_prototype, + JS::RootedObject(cx, jsb_cocos2d_CallFunc_prototype), jsb_cocos2d_CallFuncN_class, js_cocos2dx_CallFuncN_constructor, 0, // constructor properties, @@ -25103,7 +25901,8 @@ JSObject *jsb_cocos2d_GridAction_prototype; bool js_cocos2dx_GridAction_getGrid(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridAction* cobj = (cocos2d::GridAction *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridAction_getGrid : Invalid Native Object"); @@ -25118,7 +25917,7 @@ bool js_cocos2dx_GridAction_getGrid(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -25127,22 +25926,22 @@ bool js_cocos2dx_GridAction_getGrid(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridAction_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridAction* cobj = (cocos2d::GridAction *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridAction_initWithDuration : Invalid Native Object"); if (argc == 2) { double arg0; cocos2d::Size arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GridAction_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -25156,7 +25955,7 @@ void js_cocos2d_GridAction_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (GridAction)", obj); } -void js_register_cocos2dx_GridAction(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_GridAction(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_GridAction_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_GridAction_class->name = "GridAction"; jsb_cocos2d_GridAction_class->addProperty = JS_PropertyStub; @@ -25170,8 +25969,8 @@ void js_register_cocos2dx_GridAction(JSContext *cx, JSObject *global) { jsb_cocos2d_GridAction_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -25184,7 +25983,7 @@ void js_register_cocos2dx_GridAction(JSContext *cx, JSObject *global) { jsb_cocos2d_GridAction_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_GridAction_class, empty_constructor, 0, properties, @@ -25213,30 +26012,6 @@ void js_register_cocos2dx_GridAction(JSContext *cx, JSObject *global) { JSClass *jsb_cocos2d_Grid3DAction_class; JSObject *jsb_cocos2d_Grid3DAction_prototype; -bool js_cocos2dx_Grid3DAction_getGrid(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::Grid3DAction* cobj = (cocos2d::Grid3DAction *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Grid3DAction_getGrid : Invalid Native Object"); - if (argc == 0) { - cocos2d::GridBase* ret = cobj->getGrid(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::GridBase*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_Grid3DAction_getGrid : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} extern JSObject *jsb_cocos2d_GridAction_prototype; @@ -25244,7 +26019,7 @@ void js_cocos2d_Grid3DAction_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Grid3DAction)", obj); } -void js_register_cocos2dx_Grid3DAction(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Grid3DAction(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Grid3DAction_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Grid3DAction_class->name = "Grid3DAction"; jsb_cocos2d_Grid3DAction_class->addProperty = JS_PropertyStub; @@ -25258,12 +26033,11 @@ void js_register_cocos2dx_Grid3DAction(JSContext *cx, JSObject *global) { jsb_cocos2d_Grid3DAction_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("getGrid", js_cocos2dx_Grid3DAction_getGrid, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -25271,7 +26045,7 @@ void js_register_cocos2dx_Grid3DAction(JSContext *cx, JSObject *global) { jsb_cocos2d_Grid3DAction_prototype = JS_InitClass( cx, global, - jsb_cocos2d_GridAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_GridAction_prototype), jsb_cocos2d_Grid3DAction_class, empty_constructor, 0, properties, @@ -25300,30 +26074,6 @@ void js_register_cocos2dx_Grid3DAction(JSContext *cx, JSObject *global) { JSClass *jsb_cocos2d_TiledGrid3DAction_class; JSObject *jsb_cocos2d_TiledGrid3DAction_prototype; -bool js_cocos2dx_TiledGrid3DAction_getGrid(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::TiledGrid3DAction* cobj = (cocos2d::TiledGrid3DAction *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TiledGrid3DAction_getGrid : Invalid Native Object"); - if (argc == 0) { - cocos2d::GridBase* ret = cobj->getGrid(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::GridBase*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_TiledGrid3DAction_getGrid : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} extern JSObject *jsb_cocos2d_GridAction_prototype; @@ -25331,7 +26081,7 @@ void js_cocos2d_TiledGrid3DAction_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TiledGrid3DAction)", obj); } -void js_register_cocos2dx_TiledGrid3DAction(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TiledGrid3DAction(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TiledGrid3DAction_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TiledGrid3DAction_class->name = "TiledGrid3DAction"; jsb_cocos2d_TiledGrid3DAction_class->addProperty = JS_PropertyStub; @@ -25345,12 +26095,11 @@ void js_register_cocos2dx_TiledGrid3DAction(JSContext *cx, JSObject *global) { jsb_cocos2d_TiledGrid3DAction_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("getGrid", js_cocos2dx_TiledGrid3DAction_getGrid, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -25358,7 +26107,7 @@ void js_register_cocos2dx_TiledGrid3DAction(JSContext *cx, JSObject *global) { jsb_cocos2d_TiledGrid3DAction_prototype = JS_InitClass( cx, global, - jsb_cocos2d_GridAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_GridAction_prototype), jsb_cocos2d_TiledGrid3DAction_class, empty_constructor, 0, properties, @@ -25389,6 +26138,7 @@ JSObject *jsb_cocos2d_StopGrid_prototype; bool js_cocos2dx_StopGrid_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::StopGrid* ret = cocos2d::StopGrid::create(); jsval jsret = JSVAL_NULL; @@ -25400,7 +26150,7 @@ bool js_cocos2dx_StopGrid_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_StopGrid_create : wrong number of arguments"); @@ -25409,7 +26159,7 @@ bool js_cocos2dx_StopGrid_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_StopGrid_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::StopGrid* cobj = new (std::nothrow) cocos2d::StopGrid(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -25423,13 +26173,16 @@ bool js_cocos2dx_StopGrid_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::StopGrid"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::StopGrid"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -25440,7 +26193,7 @@ void js_cocos2d_StopGrid_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (StopGrid)", obj); } -void js_register_cocos2dx_StopGrid(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_StopGrid(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_StopGrid_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_StopGrid_class->name = "StopGrid"; jsb_cocos2d_StopGrid_class->addProperty = JS_PropertyStub; @@ -25454,8 +26207,8 @@ void js_register_cocos2dx_StopGrid(JSContext *cx, JSObject *global) { jsb_cocos2d_StopGrid_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -25469,7 +26222,7 @@ void js_register_cocos2dx_StopGrid(JSContext *cx, JSObject *global) { jsb_cocos2d_StopGrid_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInstant_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInstant_prototype), jsb_cocos2d_StopGrid_class, js_cocos2dx_StopGrid_constructor, 0, // constructor properties, @@ -25500,20 +26253,20 @@ JSObject *jsb_cocos2d_ReuseGrid_prototype; bool js_cocos2dx_ReuseGrid_initWithTimes(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ReuseGrid* cobj = (cocos2d::ReuseGrid *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ReuseGrid_initWithTimes : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ReuseGrid_initWithTimes : Error processing arguments"); bool ret = cobj->initWithTimes(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -25522,11 +26275,11 @@ bool js_cocos2dx_ReuseGrid_initWithTimes(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ReuseGrid_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ReuseGrid_create : Error processing arguments"); cocos2d::ReuseGrid* ret = cocos2d::ReuseGrid::create(arg0); jsval jsret = JSVAL_NULL; @@ -25538,7 +26291,7 @@ bool js_cocos2dx_ReuseGrid_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ReuseGrid_create : wrong number of arguments"); @@ -25547,7 +26300,7 @@ bool js_cocos2dx_ReuseGrid_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ReuseGrid_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ReuseGrid* cobj = new (std::nothrow) cocos2d::ReuseGrid(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -25561,13 +26314,16 @@ bool js_cocos2dx_ReuseGrid_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ReuseGrid"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ReuseGrid"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -25578,7 +26334,7 @@ void js_cocos2d_ReuseGrid_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ReuseGrid)", obj); } -void js_register_cocos2dx_ReuseGrid(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ReuseGrid(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ReuseGrid_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ReuseGrid_class->name = "ReuseGrid"; jsb_cocos2d_ReuseGrid_class->addProperty = JS_PropertyStub; @@ -25592,8 +26348,8 @@ void js_register_cocos2dx_ReuseGrid(JSContext *cx, JSObject *global) { jsb_cocos2d_ReuseGrid_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -25608,7 +26364,7 @@ void js_register_cocos2dx_ReuseGrid(JSContext *cx, JSObject *global) { jsb_cocos2d_ReuseGrid_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInstant_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInstant_prototype), jsb_cocos2d_ReuseGrid_class, js_cocos2dx_ReuseGrid_constructor, 0, // constructor properties, @@ -25639,18 +26395,18 @@ JSObject *jsb_cocos2d_Waves3D_prototype; bool js_cocos2dx_Waves3D_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Waves3D* cobj = (cocos2d::Waves3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Waves3D_setAmplitudeRate : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Waves3D_setAmplitudeRate : Error processing arguments"); cobj->setAmplitudeRate(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -25659,9 +26415,9 @@ bool js_cocos2dx_Waves3D_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Waves3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Waves3D* cobj = (cocos2d::Waves3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Waves3D_initWithDuration : Invalid Native Object"); @@ -25670,15 +26426,15 @@ bool js_cocos2dx_Waves3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *v cocos2d::Size arg1; unsigned int arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Waves3D_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -25687,7 +26443,8 @@ bool js_cocos2dx_Waves3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Waves3D_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Waves3D* cobj = (cocos2d::Waves3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Waves3D_getAmplitude : Invalid Native Object"); @@ -25695,7 +26452,7 @@ bool js_cocos2dx_Waves3D_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getAmplitude(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -25704,7 +26461,8 @@ bool js_cocos2dx_Waves3D_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Waves3D_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Waves3D* cobj = (cocos2d::Waves3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Waves3D_getAmplitudeRate : Invalid Native Object"); @@ -25712,7 +26470,7 @@ bool js_cocos2dx_Waves3D_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *v double ret = cobj->getAmplitudeRate(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -25721,18 +26479,18 @@ bool js_cocos2dx_Waves3D_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Waves3D_setAmplitude(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Waves3D* cobj = (cocos2d::Waves3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Waves3D_setAmplitude : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Waves3D_setAmplitude : Error processing arguments"); cobj->setAmplitude(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -25741,17 +26499,17 @@ bool js_cocos2dx_Waves3D_setAmplitude(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Waves3D_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { double arg0; cocos2d::Size arg1; unsigned int arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Waves3D_create : Error processing arguments"); cocos2d::Waves3D* ret = cocos2d::Waves3D::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -25763,7 +26521,7 @@ bool js_cocos2dx_Waves3D_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Waves3D_create : wrong number of arguments"); @@ -25772,7 +26530,7 @@ bool js_cocos2dx_Waves3D_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Waves3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Waves3D* cobj = new (std::nothrow) cocos2d::Waves3D(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -25786,13 +26544,16 @@ bool js_cocos2dx_Waves3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Waves3D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Waves3D"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -25803,7 +26564,7 @@ void js_cocos2d_Waves3D_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Waves3D)", obj); } -void js_register_cocos2dx_Waves3D(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Waves3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Waves3D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Waves3D_class->name = "Waves3D"; jsb_cocos2d_Waves3D_class->addProperty = JS_PropertyStub; @@ -25817,8 +26578,8 @@ void js_register_cocos2dx_Waves3D(JSContext *cx, JSObject *global) { jsb_cocos2d_Waves3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -25837,7 +26598,7 @@ void js_register_cocos2dx_Waves3D(JSContext *cx, JSObject *global) { jsb_cocos2d_Waves3D_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Grid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_Grid3DAction_prototype), jsb_cocos2d_Waves3D_class, js_cocos2dx_Waves3D_constructor, 0, // constructor properties, @@ -25868,22 +26629,22 @@ JSObject *jsb_cocos2d_FlipX3D_prototype; bool js_cocos2dx_FlipX3D_initWithSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FlipX3D* cobj = (cocos2d::FlipX3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FlipX3D_initWithSize : Invalid Native Object"); if (argc == 2) { cocos2d::Size arg0; double arg1; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FlipX3D_initWithSize : Error processing arguments"); bool ret = cobj->initWithSize(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -25892,20 +26653,20 @@ bool js_cocos2dx_FlipX3D_initWithSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_FlipX3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FlipX3D* cobj = (cocos2d::FlipX3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FlipX3D_initWithDuration : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FlipX3D_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -25914,11 +26675,11 @@ bool js_cocos2dx_FlipX3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_FlipX3D_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FlipX3D_create : Error processing arguments"); cocos2d::FlipX3D* ret = cocos2d::FlipX3D::create(arg0); jsval jsret = JSVAL_NULL; @@ -25930,7 +26691,7 @@ bool js_cocos2dx_FlipX3D_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FlipX3D_create : wrong number of arguments"); @@ -25939,7 +26700,7 @@ bool js_cocos2dx_FlipX3D_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_FlipX3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::FlipX3D* cobj = new (std::nothrow) cocos2d::FlipX3D(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -25953,13 +26714,16 @@ bool js_cocos2dx_FlipX3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::FlipX3D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::FlipX3D"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -25970,7 +26734,7 @@ void js_cocos2d_FlipX3D_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (FlipX3D)", obj); } -void js_register_cocos2dx_FlipX3D(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_FlipX3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_FlipX3D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_FlipX3D_class->name = "FlipX3D"; jsb_cocos2d_FlipX3D_class->addProperty = JS_PropertyStub; @@ -25984,8 +26748,8 @@ void js_register_cocos2dx_FlipX3D(JSContext *cx, JSObject *global) { jsb_cocos2d_FlipX3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -26001,7 +26765,7 @@ void js_register_cocos2dx_FlipX3D(JSContext *cx, JSObject *global) { jsb_cocos2d_FlipX3D_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Grid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_Grid3DAction_prototype), jsb_cocos2d_FlipX3D_class, js_cocos2dx_FlipX3D_constructor, 0, // constructor properties, @@ -26032,11 +26796,11 @@ JSObject *jsb_cocos2d_FlipY3D_prototype; bool js_cocos2dx_FlipY3D_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FlipY3D_create : Error processing arguments"); cocos2d::FlipY3D* ret = cocos2d::FlipY3D::create(arg0); jsval jsret = JSVAL_NULL; @@ -26048,7 +26812,7 @@ bool js_cocos2dx_FlipY3D_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FlipY3D_create : wrong number of arguments"); @@ -26057,7 +26821,7 @@ bool js_cocos2dx_FlipY3D_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_FlipY3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::FlipY3D* cobj = new (std::nothrow) cocos2d::FlipY3D(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -26071,13 +26835,16 @@ bool js_cocos2dx_FlipY3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::FlipY3D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::FlipY3D"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -26088,7 +26855,7 @@ void js_cocos2d_FlipY3D_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (FlipY3D)", obj); } -void js_register_cocos2dx_FlipY3D(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_FlipY3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_FlipY3D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_FlipY3D_class->name = "FlipY3D"; jsb_cocos2d_FlipY3D_class->addProperty = JS_PropertyStub; @@ -26102,8 +26869,8 @@ void js_register_cocos2dx_FlipY3D(JSContext *cx, JSObject *global) { jsb_cocos2d_FlipY3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -26117,7 +26884,7 @@ void js_register_cocos2dx_FlipY3D(JSContext *cx, JSObject *global) { jsb_cocos2d_FlipY3D_prototype = JS_InitClass( cx, global, - jsb_cocos2d_FlipX3D_prototype, + JS::RootedObject(cx, jsb_cocos2d_FlipX3D_prototype), jsb_cocos2d_FlipY3D_class, js_cocos2dx_FlipY3D_constructor, 0, // constructor properties, @@ -26148,18 +26915,18 @@ JSObject *jsb_cocos2d_Lens3D_prototype; bool js_cocos2dx_Lens3D_setConcave(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Lens3D* cobj = (cocos2d::Lens3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Lens3D_setConcave : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Lens3D_setConcave : Error processing arguments"); cobj->setConcave(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -26168,9 +26935,9 @@ bool js_cocos2dx_Lens3D_setConcave(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Lens3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Lens3D* cobj = (cocos2d::Lens3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Lens3D_initWithDuration : Invalid Native Object"); @@ -26179,15 +26946,15 @@ bool js_cocos2dx_Lens3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp cocos2d::Size arg1; cocos2d::Vec2 arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_vector2(cx, argv[2], &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_vector2(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Lens3D_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -26196,18 +26963,18 @@ bool js_cocos2dx_Lens3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Lens3D_setLensEffect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Lens3D* cobj = (cocos2d::Lens3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Lens3D_setLensEffect : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Lens3D_setLensEffect : Error processing arguments"); cobj->setLensEffect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -26216,7 +26983,8 @@ bool js_cocos2dx_Lens3D_setLensEffect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Lens3D_getLensEffect(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Lens3D* cobj = (cocos2d::Lens3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Lens3D_getLensEffect : Invalid Native Object"); @@ -26224,7 +26992,7 @@ bool js_cocos2dx_Lens3D_getLensEffect(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getLensEffect(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -26233,18 +27001,18 @@ bool js_cocos2dx_Lens3D_getLensEffect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Lens3D_setPosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Lens3D* cobj = (cocos2d::Lens3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Lens3D_setPosition : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Lens3D_setPosition : Error processing arguments"); cobj->setPosition(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -26253,7 +27021,8 @@ bool js_cocos2dx_Lens3D_setPosition(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Lens3D_getPosition(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Lens3D* cobj = (cocos2d::Lens3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Lens3D_getPosition : Invalid Native Object"); @@ -26261,7 +27030,7 @@ bool js_cocos2dx_Lens3D_getPosition(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Vec2& ret = cobj->getPosition(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -26270,17 +27039,17 @@ bool js_cocos2dx_Lens3D_getPosition(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Lens3D_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { double arg0; cocos2d::Size arg1; cocos2d::Vec2 arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_vector2(cx, argv[2], &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_vector2(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Lens3D_create : Error processing arguments"); cocos2d::Lens3D* ret = cocos2d::Lens3D::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -26292,7 +27061,7 @@ bool js_cocos2dx_Lens3D_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Lens3D_create : wrong number of arguments"); @@ -26301,7 +27070,7 @@ bool js_cocos2dx_Lens3D_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Lens3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Lens3D* cobj = new (std::nothrow) cocos2d::Lens3D(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -26315,13 +27084,16 @@ bool js_cocos2dx_Lens3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Lens3D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Lens3D"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -26332,7 +27104,7 @@ void js_cocos2d_Lens3D_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Lens3D)", obj); } -void js_register_cocos2dx_Lens3D(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Lens3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Lens3D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Lens3D_class->name = "Lens3D"; jsb_cocos2d_Lens3D_class->addProperty = JS_PropertyStub; @@ -26346,8 +27118,8 @@ void js_register_cocos2dx_Lens3D(JSContext *cx, JSObject *global) { jsb_cocos2d_Lens3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -26367,7 +27139,7 @@ void js_register_cocos2dx_Lens3D(JSContext *cx, JSObject *global) { jsb_cocos2d_Lens3D_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Grid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_Grid3DAction_prototype), jsb_cocos2d_Lens3D_class, js_cocos2dx_Lens3D_constructor, 0, // constructor properties, @@ -26398,18 +27170,18 @@ JSObject *jsb_cocos2d_Ripple3D_prototype; bool js_cocos2dx_Ripple3D_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Ripple3D* cobj = (cocos2d::Ripple3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Ripple3D_setAmplitudeRate : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Ripple3D_setAmplitudeRate : Error processing arguments"); cobj->setAmplitudeRate(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -26418,9 +27190,9 @@ bool js_cocos2dx_Ripple3D_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Ripple3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Ripple3D* cobj = (cocos2d::Ripple3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Ripple3D_initWithDuration : Invalid Native Object"); @@ -26431,17 +27203,17 @@ bool js_cocos2dx_Ripple3D_initWithDuration(JSContext *cx, uint32_t argc, jsval * double arg3; unsigned int arg4; double arg5; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_vector2(cx, argv[2], &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); - ok &= jsval_to_uint32(cx, argv[4], &arg4); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[5]), &arg5); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_vector2(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); + ok &= jsval_to_uint32(cx, args.get(4), &arg4); + ok &= JS::ToNumber( cx, args.get(5), &arg5) && !isnan(arg5); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Ripple3D_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3, arg4, arg5); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -26450,7 +27222,8 @@ bool js_cocos2dx_Ripple3D_initWithDuration(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Ripple3D_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Ripple3D* cobj = (cocos2d::Ripple3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Ripple3D_getAmplitudeRate : Invalid Native Object"); @@ -26458,7 +27231,7 @@ bool js_cocos2dx_Ripple3D_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval * double ret = cobj->getAmplitudeRate(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -26467,18 +27240,18 @@ bool js_cocos2dx_Ripple3D_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Ripple3D_setAmplitude(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Ripple3D* cobj = (cocos2d::Ripple3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Ripple3D_setAmplitude : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Ripple3D_setAmplitude : Error processing arguments"); cobj->setAmplitude(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -26487,7 +27260,8 @@ bool js_cocos2dx_Ripple3D_setAmplitude(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Ripple3D_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Ripple3D* cobj = (cocos2d::Ripple3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Ripple3D_getAmplitude : Invalid Native Object"); @@ -26495,7 +27269,7 @@ bool js_cocos2dx_Ripple3D_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getAmplitude(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -26504,18 +27278,18 @@ bool js_cocos2dx_Ripple3D_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Ripple3D_setPosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Ripple3D* cobj = (cocos2d::Ripple3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Ripple3D_setPosition : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Ripple3D_setPosition : Error processing arguments"); cobj->setPosition(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -26524,7 +27298,8 @@ bool js_cocos2dx_Ripple3D_setPosition(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Ripple3D_getPosition(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Ripple3D* cobj = (cocos2d::Ripple3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Ripple3D_getPosition : Invalid Native Object"); @@ -26532,7 +27307,7 @@ bool js_cocos2dx_Ripple3D_getPosition(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Vec2& ret = cobj->getPosition(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -26541,7 +27316,7 @@ bool js_cocos2dx_Ripple3D_getPosition(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Ripple3D_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 6) { double arg0; @@ -26550,12 +27325,12 @@ bool js_cocos2dx_Ripple3D_create(JSContext *cx, uint32_t argc, jsval *vp) double arg3; unsigned int arg4; double arg5; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_vector2(cx, argv[2], &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); - ok &= jsval_to_uint32(cx, argv[4], &arg4); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[5]), &arg5); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_vector2(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); + ok &= jsval_to_uint32(cx, args.get(4), &arg4); + ok &= JS::ToNumber( cx, args.get(5), &arg5) && !isnan(arg5); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Ripple3D_create : Error processing arguments"); cocos2d::Ripple3D* ret = cocos2d::Ripple3D::create(arg0, arg1, arg2, arg3, arg4, arg5); jsval jsret = JSVAL_NULL; @@ -26567,7 +27342,7 @@ bool js_cocos2dx_Ripple3D_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Ripple3D_create : wrong number of arguments"); @@ -26576,7 +27351,7 @@ bool js_cocos2dx_Ripple3D_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Ripple3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Ripple3D* cobj = new (std::nothrow) cocos2d::Ripple3D(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -26590,13 +27365,16 @@ bool js_cocos2dx_Ripple3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Ripple3D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Ripple3D"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -26607,7 +27385,7 @@ void js_cocos2d_Ripple3D_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Ripple3D)", obj); } -void js_register_cocos2dx_Ripple3D(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Ripple3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Ripple3D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Ripple3D_class->name = "Ripple3D"; jsb_cocos2d_Ripple3D_class->addProperty = JS_PropertyStub; @@ -26621,8 +27399,8 @@ void js_register_cocos2dx_Ripple3D(JSContext *cx, JSObject *global) { jsb_cocos2d_Ripple3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -26643,7 +27421,7 @@ void js_register_cocos2dx_Ripple3D(JSContext *cx, JSObject *global) { jsb_cocos2d_Ripple3D_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Grid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_Grid3DAction_prototype), jsb_cocos2d_Ripple3D_class, js_cocos2dx_Ripple3D_constructor, 0, // constructor properties, @@ -26674,9 +27452,9 @@ JSObject *jsb_cocos2d_Shaky3D_prototype; bool js_cocos2dx_Shaky3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Shaky3D* cobj = (cocos2d::Shaky3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Shaky3D_initWithDuration : Invalid Native Object"); @@ -26685,15 +27463,15 @@ bool js_cocos2dx_Shaky3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *v cocos2d::Size arg1; int arg2; bool arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - arg3 = JS::ToBoolean(JS::RootedValue(cx, argv[3])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + arg3 = JS::ToBoolean(args.get(3)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Shaky3D_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -26702,17 +27480,17 @@ bool js_cocos2dx_Shaky3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Shaky3D_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { double arg0; cocos2d::Size arg1; int arg2; bool arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - arg3 = JS::ToBoolean(JS::RootedValue(cx, argv[3])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + arg3 = JS::ToBoolean(args.get(3)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Shaky3D_create : Error processing arguments"); cocos2d::Shaky3D* ret = cocos2d::Shaky3D::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -26724,7 +27502,7 @@ bool js_cocos2dx_Shaky3D_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Shaky3D_create : wrong number of arguments"); @@ -26733,7 +27511,7 @@ bool js_cocos2dx_Shaky3D_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Shaky3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Shaky3D* cobj = new (std::nothrow) cocos2d::Shaky3D(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -26747,13 +27525,16 @@ bool js_cocos2dx_Shaky3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Shaky3D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Shaky3D"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -26764,7 +27545,7 @@ void js_cocos2d_Shaky3D_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Shaky3D)", obj); } -void js_register_cocos2dx_Shaky3D(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Shaky3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Shaky3D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Shaky3D_class->name = "Shaky3D"; jsb_cocos2d_Shaky3D_class->addProperty = JS_PropertyStub; @@ -26778,8 +27559,8 @@ void js_register_cocos2dx_Shaky3D(JSContext *cx, JSObject *global) { jsb_cocos2d_Shaky3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -26794,7 +27575,7 @@ void js_register_cocos2dx_Shaky3D(JSContext *cx, JSObject *global) { jsb_cocos2d_Shaky3D_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Grid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_Grid3DAction_prototype), jsb_cocos2d_Shaky3D_class, js_cocos2dx_Shaky3D_constructor, 0, // constructor properties, @@ -26825,18 +27606,18 @@ JSObject *jsb_cocos2d_Liquid_prototype; bool js_cocos2dx_Liquid_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Liquid* cobj = (cocos2d::Liquid *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Liquid_setAmplitudeRate : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Liquid_setAmplitudeRate : Error processing arguments"); cobj->setAmplitudeRate(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -26845,9 +27626,9 @@ bool js_cocos2dx_Liquid_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Liquid_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Liquid* cobj = (cocos2d::Liquid *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Liquid_initWithDuration : Invalid Native Object"); @@ -26856,15 +27637,15 @@ bool js_cocos2dx_Liquid_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp cocos2d::Size arg1; unsigned int arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Liquid_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -26873,7 +27654,8 @@ bool js_cocos2dx_Liquid_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Liquid_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Liquid* cobj = (cocos2d::Liquid *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Liquid_getAmplitude : Invalid Native Object"); @@ -26881,7 +27663,7 @@ bool js_cocos2dx_Liquid_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getAmplitude(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -26890,7 +27672,8 @@ bool js_cocos2dx_Liquid_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Liquid_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Liquid* cobj = (cocos2d::Liquid *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Liquid_getAmplitudeRate : Invalid Native Object"); @@ -26898,7 +27681,7 @@ bool js_cocos2dx_Liquid_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp double ret = cobj->getAmplitudeRate(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -26907,18 +27690,18 @@ bool js_cocos2dx_Liquid_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Liquid_setAmplitude(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Liquid* cobj = (cocos2d::Liquid *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Liquid_setAmplitude : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Liquid_setAmplitude : Error processing arguments"); cobj->setAmplitude(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -26927,17 +27710,17 @@ bool js_cocos2dx_Liquid_setAmplitude(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Liquid_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { double arg0; cocos2d::Size arg1; unsigned int arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Liquid_create : Error processing arguments"); cocos2d::Liquid* ret = cocos2d::Liquid::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -26949,7 +27732,7 @@ bool js_cocos2dx_Liquid_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Liquid_create : wrong number of arguments"); @@ -26958,7 +27741,7 @@ bool js_cocos2dx_Liquid_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Liquid_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Liquid* cobj = new (std::nothrow) cocos2d::Liquid(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -26972,13 +27755,16 @@ bool js_cocos2dx_Liquid_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Liquid"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Liquid"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -26989,7 +27775,7 @@ void js_cocos2d_Liquid_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Liquid)", obj); } -void js_register_cocos2dx_Liquid(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Liquid(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Liquid_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Liquid_class->name = "Liquid"; jsb_cocos2d_Liquid_class->addProperty = JS_PropertyStub; @@ -27003,8 +27789,8 @@ void js_register_cocos2dx_Liquid(JSContext *cx, JSObject *global) { jsb_cocos2d_Liquid_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -27023,7 +27809,7 @@ void js_register_cocos2dx_Liquid(JSContext *cx, JSObject *global) { jsb_cocos2d_Liquid_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Grid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_Grid3DAction_prototype), jsb_cocos2d_Liquid_class, js_cocos2dx_Liquid_constructor, 0, // constructor properties, @@ -27054,18 +27840,18 @@ JSObject *jsb_cocos2d_Waves_prototype; bool js_cocos2dx_Waves_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Waves* cobj = (cocos2d::Waves *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Waves_setAmplitudeRate : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Waves_setAmplitudeRate : Error processing arguments"); cobj->setAmplitudeRate(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -27074,9 +27860,9 @@ bool js_cocos2dx_Waves_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Waves_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Waves* cobj = (cocos2d::Waves *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Waves_initWithDuration : Invalid Native Object"); @@ -27087,17 +27873,17 @@ bool js_cocos2dx_Waves_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) double arg3; bool arg4; bool arg5; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); - arg4 = JS::ToBoolean(JS::RootedValue(cx, argv[4])); - arg5 = JS::ToBoolean(JS::RootedValue(cx, argv[5])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); + arg4 = JS::ToBoolean(args.get(4)); + arg5 = JS::ToBoolean(args.get(5)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Waves_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3, arg4, arg5); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -27106,7 +27892,8 @@ bool js_cocos2dx_Waves_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Waves_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Waves* cobj = (cocos2d::Waves *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Waves_getAmplitude : Invalid Native Object"); @@ -27114,7 +27901,7 @@ bool js_cocos2dx_Waves_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getAmplitude(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -27123,7 +27910,8 @@ bool js_cocos2dx_Waves_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Waves_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Waves* cobj = (cocos2d::Waves *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Waves_getAmplitudeRate : Invalid Native Object"); @@ -27131,7 +27919,7 @@ bool js_cocos2dx_Waves_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getAmplitudeRate(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -27140,18 +27928,18 @@ bool js_cocos2dx_Waves_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Waves_setAmplitude(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Waves* cobj = (cocos2d::Waves *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Waves_setAmplitude : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Waves_setAmplitude : Error processing arguments"); cobj->setAmplitude(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -27160,7 +27948,7 @@ bool js_cocos2dx_Waves_setAmplitude(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Waves_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 6) { double arg0; @@ -27169,12 +27957,12 @@ bool js_cocos2dx_Waves_create(JSContext *cx, uint32_t argc, jsval *vp) double arg3; bool arg4; bool arg5; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); - arg4 = JS::ToBoolean(JS::RootedValue(cx, argv[4])); - arg5 = JS::ToBoolean(JS::RootedValue(cx, argv[5])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); + arg4 = JS::ToBoolean(args.get(4)); + arg5 = JS::ToBoolean(args.get(5)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Waves_create : Error processing arguments"); cocos2d::Waves* ret = cocos2d::Waves::create(arg0, arg1, arg2, arg3, arg4, arg5); jsval jsret = JSVAL_NULL; @@ -27186,7 +27974,7 @@ bool js_cocos2dx_Waves_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Waves_create : wrong number of arguments"); @@ -27195,7 +27983,7 @@ bool js_cocos2dx_Waves_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Waves_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Waves* cobj = new (std::nothrow) cocos2d::Waves(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -27209,13 +27997,16 @@ bool js_cocos2dx_Waves_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Waves"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Waves"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -27226,7 +28017,7 @@ void js_cocos2d_Waves_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Waves)", obj); } -void js_register_cocos2dx_Waves(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Waves(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Waves_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Waves_class->name = "Waves"; jsb_cocos2d_Waves_class->addProperty = JS_PropertyStub; @@ -27240,8 +28031,8 @@ void js_register_cocos2dx_Waves(JSContext *cx, JSObject *global) { jsb_cocos2d_Waves_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -27260,7 +28051,7 @@ void js_register_cocos2dx_Waves(JSContext *cx, JSObject *global) { jsb_cocos2d_Waves_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Grid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_Grid3DAction_prototype), jsb_cocos2d_Waves_class, js_cocos2dx_Waves_constructor, 0, // constructor properties, @@ -27291,18 +28082,18 @@ JSObject *jsb_cocos2d_Twirl_prototype; bool js_cocos2dx_Twirl_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Twirl* cobj = (cocos2d::Twirl *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Twirl_setAmplitudeRate : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Twirl_setAmplitudeRate : Error processing arguments"); cobj->setAmplitudeRate(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -27311,9 +28102,9 @@ bool js_cocos2dx_Twirl_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Twirl_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Twirl* cobj = (cocos2d::Twirl *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Twirl_initWithDuration : Invalid Native Object"); @@ -27323,16 +28114,16 @@ bool js_cocos2dx_Twirl_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec2 arg2; unsigned int arg3; double arg4; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_vector2(cx, argv[2], &arg2); - ok &= jsval_to_uint32(cx, argv[3], &arg3); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[4]), &arg4); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_vector2(cx, args.get(2), &arg2); + ok &= jsval_to_uint32(cx, args.get(3), &arg3); + ok &= JS::ToNumber( cx, args.get(4), &arg4) && !isnan(arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Twirl_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -27341,7 +28132,8 @@ bool js_cocos2dx_Twirl_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Twirl_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Twirl* cobj = (cocos2d::Twirl *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Twirl_getAmplitudeRate : Invalid Native Object"); @@ -27349,7 +28141,7 @@ bool js_cocos2dx_Twirl_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getAmplitudeRate(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -27358,18 +28150,18 @@ bool js_cocos2dx_Twirl_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Twirl_setAmplitude(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Twirl* cobj = (cocos2d::Twirl *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Twirl_setAmplitude : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Twirl_setAmplitude : Error processing arguments"); cobj->setAmplitude(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -27378,7 +28170,8 @@ bool js_cocos2dx_Twirl_setAmplitude(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Twirl_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Twirl* cobj = (cocos2d::Twirl *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Twirl_getAmplitude : Invalid Native Object"); @@ -27386,7 +28179,7 @@ bool js_cocos2dx_Twirl_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getAmplitude(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -27395,18 +28188,18 @@ bool js_cocos2dx_Twirl_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Twirl_setPosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Twirl* cobj = (cocos2d::Twirl *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Twirl_setPosition : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Twirl_setPosition : Error processing arguments"); cobj->setPosition(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -27415,7 +28208,8 @@ bool js_cocos2dx_Twirl_setPosition(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Twirl_getPosition(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Twirl* cobj = (cocos2d::Twirl *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Twirl_getPosition : Invalid Native Object"); @@ -27423,7 +28217,7 @@ bool js_cocos2dx_Twirl_getPosition(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Vec2& ret = cobj->getPosition(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -27432,7 +28226,7 @@ bool js_cocos2dx_Twirl_getPosition(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Twirl_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 5) { double arg0; @@ -27440,11 +28234,11 @@ bool js_cocos2dx_Twirl_create(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec2 arg2; unsigned int arg3; double arg4; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_vector2(cx, argv[2], &arg2); - ok &= jsval_to_uint32(cx, argv[3], &arg3); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[4]), &arg4); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_vector2(cx, args.get(2), &arg2); + ok &= jsval_to_uint32(cx, args.get(3), &arg3); + ok &= JS::ToNumber( cx, args.get(4), &arg4) && !isnan(arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Twirl_create : Error processing arguments"); cocos2d::Twirl* ret = cocos2d::Twirl::create(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; @@ -27456,7 +28250,7 @@ bool js_cocos2dx_Twirl_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Twirl_create : wrong number of arguments"); @@ -27465,7 +28259,7 @@ bool js_cocos2dx_Twirl_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Twirl_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Twirl* cobj = new (std::nothrow) cocos2d::Twirl(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -27479,13 +28273,16 @@ bool js_cocos2dx_Twirl_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Twirl"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Twirl"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -27496,7 +28293,7 @@ void js_cocos2d_Twirl_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Twirl)", obj); } -void js_register_cocos2dx_Twirl(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Twirl(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Twirl_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Twirl_class->name = "Twirl"; jsb_cocos2d_Twirl_class->addProperty = JS_PropertyStub; @@ -27510,8 +28307,8 @@ void js_register_cocos2dx_Twirl(JSContext *cx, JSObject *global) { jsb_cocos2d_Twirl_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -27532,7 +28329,7 @@ void js_register_cocos2dx_Twirl(JSContext *cx, JSObject *global) { jsb_cocos2d_Twirl_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Grid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_Grid3DAction_prototype), jsb_cocos2d_Twirl_class, js_cocos2dx_Twirl_constructor, 0, // constructor properties, @@ -27561,39 +28358,15 @@ void js_register_cocos2dx_Twirl(JSContext *cx, JSObject *global) { JSClass *jsb_cocos2d_PageTurn3D_class; JSObject *jsb_cocos2d_PageTurn3D_prototype; -bool js_cocos2dx_PageTurn3D_getGrid(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::PageTurn3D* cobj = (cocos2d::PageTurn3D *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_PageTurn3D_getGrid : Invalid Native Object"); - if (argc == 0) { - cocos2d::GridBase* ret = cobj->getGrid(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::GridBase*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_PageTurn3D_getGrid : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_PageTurn3D_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Size arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_PageTurn3D_create : Error processing arguments"); cocos2d::PageTurn3D* ret = cocos2d::PageTurn3D::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -27605,7 +28378,7 @@ bool js_cocos2dx_PageTurn3D_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_PageTurn3D_create : wrong number of arguments"); @@ -27619,7 +28392,7 @@ void js_cocos2d_PageTurn3D_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (PageTurn3D)", obj); } -void js_register_cocos2dx_PageTurn3D(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_PageTurn3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_PageTurn3D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_PageTurn3D_class->name = "PageTurn3D"; jsb_cocos2d_PageTurn3D_class->addProperty = JS_PropertyStub; @@ -27633,12 +28406,11 @@ void js_register_cocos2dx_PageTurn3D(JSContext *cx, JSObject *global) { jsb_cocos2d_PageTurn3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("getGrid", js_cocos2dx_PageTurn3D_getGrid, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -27649,7 +28421,7 @@ void js_register_cocos2dx_PageTurn3D(JSContext *cx, JSObject *global) { jsb_cocos2d_PageTurn3D_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Grid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_Grid3DAction_prototype), jsb_cocos2d_PageTurn3D_class, dummy_constructor, 0, // no constructor properties, @@ -27680,22 +28452,22 @@ JSObject *jsb_cocos2d_ProgressTo_prototype; bool js_cocos2dx_ProgressTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProgressTo* cobj = (cocos2d::ProgressTo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressTo_initWithDuration : Invalid Native Object"); if (argc == 2) { double arg0; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProgressTo_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -27704,13 +28476,13 @@ bool js_cocos2dx_ProgressTo_initWithDuration(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ProgressTo_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProgressTo_create : Error processing arguments"); cocos2d::ProgressTo* ret = cocos2d::ProgressTo::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -27722,7 +28494,7 @@ bool js_cocos2dx_ProgressTo_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ProgressTo_create : wrong number of arguments"); @@ -27731,7 +28503,7 @@ bool js_cocos2dx_ProgressTo_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ProgressTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ProgressTo* cobj = new (std::nothrow) cocos2d::ProgressTo(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -27745,13 +28517,16 @@ bool js_cocos2dx_ProgressTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ProgressTo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ProgressTo"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -27762,7 +28537,7 @@ void js_cocos2d_ProgressTo_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ProgressTo)", obj); } -void js_register_cocos2dx_ProgressTo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ProgressTo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ProgressTo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ProgressTo_class->name = "ProgressTo"; jsb_cocos2d_ProgressTo_class->addProperty = JS_PropertyStub; @@ -27776,8 +28551,8 @@ void js_register_cocos2dx_ProgressTo(JSContext *cx, JSObject *global) { jsb_cocos2d_ProgressTo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -27792,7 +28567,7 @@ void js_register_cocos2dx_ProgressTo(JSContext *cx, JSObject *global) { jsb_cocos2d_ProgressTo_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_ProgressTo_class, js_cocos2dx_ProgressTo_constructor, 0, // constructor properties, @@ -27823,9 +28598,9 @@ JSObject *jsb_cocos2d_ProgressFromTo_prototype; bool js_cocos2dx_ProgressFromTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProgressFromTo* cobj = (cocos2d::ProgressFromTo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressFromTo_initWithDuration : Invalid Native Object"); @@ -27833,14 +28608,14 @@ bool js_cocos2dx_ProgressFromTo_initWithDuration(JSContext *cx, uint32_t argc, j double arg0; double arg1; double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProgressFromTo_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -27849,15 +28624,15 @@ bool js_cocos2dx_ProgressFromTo_initWithDuration(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ProgressFromTo_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 3) { double arg0; double arg1; double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProgressFromTo_create : Error processing arguments"); cocos2d::ProgressFromTo* ret = cocos2d::ProgressFromTo::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -27869,7 +28644,7 @@ bool js_cocos2dx_ProgressFromTo_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ProgressFromTo_create : wrong number of arguments"); @@ -27878,7 +28653,7 @@ bool js_cocos2dx_ProgressFromTo_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ProgressFromTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ProgressFromTo* cobj = new (std::nothrow) cocos2d::ProgressFromTo(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -27892,13 +28667,16 @@ bool js_cocos2dx_ProgressFromTo_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ProgressFromTo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ProgressFromTo"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -27909,7 +28687,7 @@ void js_cocos2d_ProgressFromTo_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ProgressFromTo)", obj); } -void js_register_cocos2dx_ProgressFromTo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ProgressFromTo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ProgressFromTo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ProgressFromTo_class->name = "ProgressFromTo"; jsb_cocos2d_ProgressFromTo_class->addProperty = JS_PropertyStub; @@ -27923,8 +28701,8 @@ void js_register_cocos2dx_ProgressFromTo(JSContext *cx, JSObject *global) { jsb_cocos2d_ProgressFromTo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -27939,7 +28717,7 @@ void js_register_cocos2dx_ProgressFromTo(JSContext *cx, JSObject *global) { jsb_cocos2d_ProgressFromTo_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_ProgressFromTo_class, js_cocos2dx_ProgressFromTo_constructor, 0, // constructor properties, @@ -27970,9 +28748,9 @@ JSObject *jsb_cocos2d_ShakyTiles3D_prototype; bool js_cocos2dx_ShakyTiles3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ShakyTiles3D* cobj = (cocos2d::ShakyTiles3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ShakyTiles3D_initWithDuration : Invalid Native Object"); @@ -27981,15 +28759,15 @@ bool js_cocos2dx_ShakyTiles3D_initWithDuration(JSContext *cx, uint32_t argc, jsv cocos2d::Size arg1; int arg2; bool arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - arg3 = JS::ToBoolean(JS::RootedValue(cx, argv[3])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + arg3 = JS::ToBoolean(args.get(3)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ShakyTiles3D_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -27998,17 +28776,17 @@ bool js_cocos2dx_ShakyTiles3D_initWithDuration(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ShakyTiles3D_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { double arg0; cocos2d::Size arg1; int arg2; bool arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - arg3 = JS::ToBoolean(JS::RootedValue(cx, argv[3])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + arg3 = JS::ToBoolean(args.get(3)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ShakyTiles3D_create : Error processing arguments"); cocos2d::ShakyTiles3D* ret = cocos2d::ShakyTiles3D::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -28020,7 +28798,7 @@ bool js_cocos2dx_ShakyTiles3D_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ShakyTiles3D_create : wrong number of arguments"); @@ -28029,7 +28807,7 @@ bool js_cocos2dx_ShakyTiles3D_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ShakyTiles3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ShakyTiles3D* cobj = new (std::nothrow) cocos2d::ShakyTiles3D(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -28043,13 +28821,16 @@ bool js_cocos2dx_ShakyTiles3D_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ShakyTiles3D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ShakyTiles3D"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -28060,7 +28841,7 @@ void js_cocos2d_ShakyTiles3D_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ShakyTiles3D)", obj); } -void js_register_cocos2dx_ShakyTiles3D(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ShakyTiles3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ShakyTiles3D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ShakyTiles3D_class->name = "ShakyTiles3D"; jsb_cocos2d_ShakyTiles3D_class->addProperty = JS_PropertyStub; @@ -28074,8 +28855,8 @@ void js_register_cocos2dx_ShakyTiles3D(JSContext *cx, JSObject *global) { jsb_cocos2d_ShakyTiles3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -28090,7 +28871,7 @@ void js_register_cocos2dx_ShakyTiles3D(JSContext *cx, JSObject *global) { jsb_cocos2d_ShakyTiles3D_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TiledGrid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_TiledGrid3DAction_prototype), jsb_cocos2d_ShakyTiles3D_class, js_cocos2dx_ShakyTiles3D_constructor, 0, // constructor properties, @@ -28121,9 +28902,9 @@ JSObject *jsb_cocos2d_ShatteredTiles3D_prototype; bool js_cocos2dx_ShatteredTiles3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ShatteredTiles3D* cobj = (cocos2d::ShatteredTiles3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ShatteredTiles3D_initWithDuration : Invalid Native Object"); @@ -28132,15 +28913,15 @@ bool js_cocos2dx_ShatteredTiles3D_initWithDuration(JSContext *cx, uint32_t argc, cocos2d::Size arg1; int arg2; bool arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - arg3 = JS::ToBoolean(JS::RootedValue(cx, argv[3])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + arg3 = JS::ToBoolean(args.get(3)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ShatteredTiles3D_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -28149,17 +28930,17 @@ bool js_cocos2dx_ShatteredTiles3D_initWithDuration(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ShatteredTiles3D_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { double arg0; cocos2d::Size arg1; int arg2; bool arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - arg3 = JS::ToBoolean(JS::RootedValue(cx, argv[3])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + arg3 = JS::ToBoolean(args.get(3)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ShatteredTiles3D_create : Error processing arguments"); cocos2d::ShatteredTiles3D* ret = cocos2d::ShatteredTiles3D::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -28171,7 +28952,7 @@ bool js_cocos2dx_ShatteredTiles3D_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ShatteredTiles3D_create : wrong number of arguments"); @@ -28180,7 +28961,7 @@ bool js_cocos2dx_ShatteredTiles3D_create(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_ShatteredTiles3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ShatteredTiles3D* cobj = new (std::nothrow) cocos2d::ShatteredTiles3D(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -28194,13 +28975,16 @@ bool js_cocos2dx_ShatteredTiles3D_constructor(JSContext *cx, uint32_t argc, jsva CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ShatteredTiles3D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ShatteredTiles3D"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -28211,7 +28995,7 @@ void js_cocos2d_ShatteredTiles3D_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ShatteredTiles3D)", obj); } -void js_register_cocos2dx_ShatteredTiles3D(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ShatteredTiles3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ShatteredTiles3D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ShatteredTiles3D_class->name = "ShatteredTiles3D"; jsb_cocos2d_ShatteredTiles3D_class->addProperty = JS_PropertyStub; @@ -28225,8 +29009,8 @@ void js_register_cocos2dx_ShatteredTiles3D(JSContext *cx, JSObject *global) { jsb_cocos2d_ShatteredTiles3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -28241,7 +29025,7 @@ void js_register_cocos2dx_ShatteredTiles3D(JSContext *cx, JSObject *global) { jsb_cocos2d_ShatteredTiles3D_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TiledGrid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_TiledGrid3DAction_prototype), jsb_cocos2d_ShatteredTiles3D_class, js_cocos2dx_ShatteredTiles3D_constructor, 0, // constructor properties, @@ -28272,21 +29056,21 @@ JSObject *jsb_cocos2d_ShuffleTiles_prototype; bool js_cocos2dx_ShuffleTiles_placeTile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ShuffleTiles* cobj = (cocos2d::ShuffleTiles *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ShuffleTiles_placeTile : Invalid Native Object"); if (argc == 2) { cocos2d::Vec2 arg0; cocos2d::Tile* arg1; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); #pragma warning NO CONVERSION TO NATIVE FOR Tile* ok = false; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ShuffleTiles_placeTile : Error processing arguments"); cobj->placeTile(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -28295,9 +29079,9 @@ bool js_cocos2dx_ShuffleTiles_placeTile(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ShuffleTiles_shuffle(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ShuffleTiles* cobj = (cocos2d::ShuffleTiles *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ShuffleTiles_shuffle : Invalid Native Object"); @@ -28306,10 +29090,10 @@ bool js_cocos2dx_ShuffleTiles_shuffle(JSContext *cx, uint32_t argc, jsval *vp) unsigned int arg1; #pragma warning NO CONVERSION TO NATIVE FOR unsigned int* ok = false; - ok &= jsval_to_uint32(cx, argv[1], &arg1); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ShuffleTiles_shuffle : Error processing arguments"); cobj->shuffle(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -28318,9 +29102,9 @@ bool js_cocos2dx_ShuffleTiles_shuffle(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ShuffleTiles_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ShuffleTiles* cobj = (cocos2d::ShuffleTiles *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ShuffleTiles_initWithDuration : Invalid Native Object"); @@ -28328,14 +29112,14 @@ bool js_cocos2dx_ShuffleTiles_initWithDuration(JSContext *cx, uint32_t argc, jsv double arg0; cocos2d::Size arg1; unsigned int arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ShuffleTiles_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -28344,20 +29128,20 @@ bool js_cocos2dx_ShuffleTiles_initWithDuration(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ShuffleTiles_getDelta(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ShuffleTiles* cobj = (cocos2d::ShuffleTiles *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ShuffleTiles_getDelta : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ShuffleTiles_getDelta : Error processing arguments"); cocos2d::Size ret = cobj->getDelta(arg0); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -28366,15 +29150,15 @@ bool js_cocos2dx_ShuffleTiles_getDelta(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ShuffleTiles_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 3) { double arg0; cocos2d::Size arg1; unsigned int arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ShuffleTiles_create : Error processing arguments"); cocos2d::ShuffleTiles* ret = cocos2d::ShuffleTiles::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -28386,7 +29170,7 @@ bool js_cocos2dx_ShuffleTiles_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ShuffleTiles_create : wrong number of arguments"); @@ -28395,7 +29179,7 @@ bool js_cocos2dx_ShuffleTiles_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ShuffleTiles_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ShuffleTiles* cobj = new (std::nothrow) cocos2d::ShuffleTiles(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -28409,13 +29193,16 @@ bool js_cocos2dx_ShuffleTiles_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ShuffleTiles"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ShuffleTiles"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -28426,7 +29213,7 @@ void js_cocos2d_ShuffleTiles_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ShuffleTiles)", obj); } -void js_register_cocos2dx_ShuffleTiles(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ShuffleTiles(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ShuffleTiles_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ShuffleTiles_class->name = "ShuffleTiles"; jsb_cocos2d_ShuffleTiles_class->addProperty = JS_PropertyStub; @@ -28440,8 +29227,8 @@ void js_register_cocos2dx_ShuffleTiles(JSContext *cx, JSObject *global) { jsb_cocos2d_ShuffleTiles_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -28459,7 +29246,7 @@ void js_register_cocos2dx_ShuffleTiles(JSContext *cx, JSObject *global) { jsb_cocos2d_ShuffleTiles_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TiledGrid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_TiledGrid3DAction_prototype), jsb_cocos2d_ShuffleTiles_class, js_cocos2dx_ShuffleTiles_constructor, 0, // constructor properties, @@ -28490,18 +29277,18 @@ JSObject *jsb_cocos2d_FadeOutTRTiles_prototype; bool js_cocos2dx_FadeOutTRTiles_turnOnTile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FadeOutTRTiles* cobj = (cocos2d::FadeOutTRTiles *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FadeOutTRTiles_turnOnTile : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeOutTRTiles_turnOnTile : Error processing arguments"); cobj->turnOnTile(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -28510,18 +29297,18 @@ bool js_cocos2dx_FadeOutTRTiles_turnOnTile(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_FadeOutTRTiles_turnOffTile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FadeOutTRTiles* cobj = (cocos2d::FadeOutTRTiles *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FadeOutTRTiles_turnOffTile : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeOutTRTiles_turnOffTile : Error processing arguments"); cobj->turnOffTile(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -28530,20 +29317,20 @@ bool js_cocos2dx_FadeOutTRTiles_turnOffTile(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_FadeOutTRTiles_transformTile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FadeOutTRTiles* cobj = (cocos2d::FadeOutTRTiles *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FadeOutTRTiles_transformTile : Invalid Native Object"); if (argc == 2) { cocos2d::Vec2 arg0; double arg1; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeOutTRTiles_transformTile : Error processing arguments"); cobj->transformTile(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -28552,22 +29339,22 @@ bool js_cocos2dx_FadeOutTRTiles_transformTile(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_FadeOutTRTiles_testFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FadeOutTRTiles* cobj = (cocos2d::FadeOutTRTiles *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FadeOutTRTiles_testFunc : Invalid Native Object"); if (argc == 2) { cocos2d::Size arg0; double arg1; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeOutTRTiles_testFunc : Error processing arguments"); double ret = cobj->testFunc(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -28576,13 +29363,13 @@ bool js_cocos2dx_FadeOutTRTiles_testFunc(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_FadeOutTRTiles_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Size arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeOutTRTiles_create : Error processing arguments"); cocos2d::FadeOutTRTiles* ret = cocos2d::FadeOutTRTiles::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -28594,7 +29381,7 @@ bool js_cocos2dx_FadeOutTRTiles_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FadeOutTRTiles_create : wrong number of arguments"); @@ -28603,7 +29390,7 @@ bool js_cocos2dx_FadeOutTRTiles_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_FadeOutTRTiles_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::FadeOutTRTiles* cobj = new (std::nothrow) cocos2d::FadeOutTRTiles(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -28617,13 +29404,16 @@ bool js_cocos2dx_FadeOutTRTiles_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::FadeOutTRTiles"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::FadeOutTRTiles"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -28634,7 +29424,7 @@ void js_cocos2d_FadeOutTRTiles_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (FadeOutTRTiles)", obj); } -void js_register_cocos2dx_FadeOutTRTiles(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_FadeOutTRTiles(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_FadeOutTRTiles_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_FadeOutTRTiles_class->name = "FadeOutTRTiles"; jsb_cocos2d_FadeOutTRTiles_class->addProperty = JS_PropertyStub; @@ -28648,8 +29438,8 @@ void js_register_cocos2dx_FadeOutTRTiles(JSContext *cx, JSObject *global) { jsb_cocos2d_FadeOutTRTiles_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -28667,7 +29457,7 @@ void js_register_cocos2dx_FadeOutTRTiles(JSContext *cx, JSObject *global) { jsb_cocos2d_FadeOutTRTiles_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TiledGrid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_TiledGrid3DAction_prototype), jsb_cocos2d_FadeOutTRTiles_class, js_cocos2dx_FadeOutTRTiles_constructor, 0, // constructor properties, @@ -28698,13 +29488,13 @@ JSObject *jsb_cocos2d_FadeOutBLTiles_prototype; bool js_cocos2dx_FadeOutBLTiles_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Size arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeOutBLTiles_create : Error processing arguments"); cocos2d::FadeOutBLTiles* ret = cocos2d::FadeOutBLTiles::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -28716,7 +29506,7 @@ bool js_cocos2dx_FadeOutBLTiles_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FadeOutBLTiles_create : wrong number of arguments"); @@ -28725,7 +29515,7 @@ bool js_cocos2dx_FadeOutBLTiles_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_FadeOutBLTiles_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::FadeOutBLTiles* cobj = new (std::nothrow) cocos2d::FadeOutBLTiles(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -28739,13 +29529,16 @@ bool js_cocos2dx_FadeOutBLTiles_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::FadeOutBLTiles"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::FadeOutBLTiles"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -28756,7 +29549,7 @@ void js_cocos2d_FadeOutBLTiles_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (FadeOutBLTiles)", obj); } -void js_register_cocos2dx_FadeOutBLTiles(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_FadeOutBLTiles(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_FadeOutBLTiles_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_FadeOutBLTiles_class->name = "FadeOutBLTiles"; jsb_cocos2d_FadeOutBLTiles_class->addProperty = JS_PropertyStub; @@ -28770,8 +29563,8 @@ void js_register_cocos2dx_FadeOutBLTiles(JSContext *cx, JSObject *global) { jsb_cocos2d_FadeOutBLTiles_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -28785,7 +29578,7 @@ void js_register_cocos2dx_FadeOutBLTiles(JSContext *cx, JSObject *global) { jsb_cocos2d_FadeOutBLTiles_prototype = JS_InitClass( cx, global, - jsb_cocos2d_FadeOutTRTiles_prototype, + JS::RootedObject(cx, jsb_cocos2d_FadeOutTRTiles_prototype), jsb_cocos2d_FadeOutBLTiles_class, js_cocos2dx_FadeOutBLTiles_constructor, 0, // constructor properties, @@ -28814,37 +29607,15 @@ void js_register_cocos2dx_FadeOutBLTiles(JSContext *cx, JSObject *global) { JSClass *jsb_cocos2d_FadeOutUpTiles_class; JSObject *jsb_cocos2d_FadeOutUpTiles_prototype; -bool js_cocos2dx_FadeOutUpTiles_transformTile(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::FadeOutUpTiles* cobj = (cocos2d::FadeOutUpTiles *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FadeOutUpTiles_transformTile : Invalid Native Object"); - if (argc == 2) { - cocos2d::Vec2 arg0; - double arg1; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeOutUpTiles_transformTile : Error processing arguments"); - cobj->transformTile(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_FadeOutUpTiles_transformTile : wrong number of arguments: %d, was expecting %d", argc, 2); - return false; -} bool js_cocos2dx_FadeOutUpTiles_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Size arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeOutUpTiles_create : Error processing arguments"); cocos2d::FadeOutUpTiles* ret = cocos2d::FadeOutUpTiles::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -28856,7 +29627,7 @@ bool js_cocos2dx_FadeOutUpTiles_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FadeOutUpTiles_create : wrong number of arguments"); @@ -28865,7 +29636,7 @@ bool js_cocos2dx_FadeOutUpTiles_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_FadeOutUpTiles_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::FadeOutUpTiles* cobj = new (std::nothrow) cocos2d::FadeOutUpTiles(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -28879,13 +29650,16 @@ bool js_cocos2dx_FadeOutUpTiles_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::FadeOutUpTiles"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::FadeOutUpTiles"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -28896,7 +29670,7 @@ void js_cocos2d_FadeOutUpTiles_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (FadeOutUpTiles)", obj); } -void js_register_cocos2dx_FadeOutUpTiles(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_FadeOutUpTiles(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_FadeOutUpTiles_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_FadeOutUpTiles_class->name = "FadeOutUpTiles"; jsb_cocos2d_FadeOutUpTiles_class->addProperty = JS_PropertyStub; @@ -28910,12 +29684,11 @@ void js_register_cocos2dx_FadeOutUpTiles(JSContext *cx, JSObject *global) { jsb_cocos2d_FadeOutUpTiles_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("transformTile", js_cocos2dx_FadeOutUpTiles_transformTile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -28926,7 +29699,7 @@ void js_register_cocos2dx_FadeOutUpTiles(JSContext *cx, JSObject *global) { jsb_cocos2d_FadeOutUpTiles_prototype = JS_InitClass( cx, global, - jsb_cocos2d_FadeOutTRTiles_prototype, + JS::RootedObject(cx, jsb_cocos2d_FadeOutTRTiles_prototype), jsb_cocos2d_FadeOutUpTiles_class, js_cocos2dx_FadeOutUpTiles_constructor, 0, // constructor properties, @@ -28957,13 +29730,13 @@ JSObject *jsb_cocos2d_FadeOutDownTiles_prototype; bool js_cocos2dx_FadeOutDownTiles_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Size arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FadeOutDownTiles_create : Error processing arguments"); cocos2d::FadeOutDownTiles* ret = cocos2d::FadeOutDownTiles::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -28975,7 +29748,7 @@ bool js_cocos2dx_FadeOutDownTiles_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_FadeOutDownTiles_create : wrong number of arguments"); @@ -28984,7 +29757,7 @@ bool js_cocos2dx_FadeOutDownTiles_create(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_FadeOutDownTiles_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::FadeOutDownTiles* cobj = new (std::nothrow) cocos2d::FadeOutDownTiles(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -28998,13 +29771,16 @@ bool js_cocos2dx_FadeOutDownTiles_constructor(JSContext *cx, uint32_t argc, jsva CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::FadeOutDownTiles"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::FadeOutDownTiles"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -29015,7 +29791,7 @@ void js_cocos2d_FadeOutDownTiles_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (FadeOutDownTiles)", obj); } -void js_register_cocos2dx_FadeOutDownTiles(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_FadeOutDownTiles(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_FadeOutDownTiles_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_FadeOutDownTiles_class->name = "FadeOutDownTiles"; jsb_cocos2d_FadeOutDownTiles_class->addProperty = JS_PropertyStub; @@ -29029,8 +29805,8 @@ void js_register_cocos2dx_FadeOutDownTiles(JSContext *cx, JSObject *global) { jsb_cocos2d_FadeOutDownTiles_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -29044,7 +29820,7 @@ void js_register_cocos2dx_FadeOutDownTiles(JSContext *cx, JSObject *global) { jsb_cocos2d_FadeOutDownTiles_prototype = JS_InitClass( cx, global, - jsb_cocos2d_FadeOutUpTiles_prototype, + JS::RootedObject(cx, jsb_cocos2d_FadeOutUpTiles_prototype), jsb_cocos2d_FadeOutDownTiles_class, js_cocos2dx_FadeOutDownTiles_constructor, 0, // constructor properties, @@ -29075,18 +29851,18 @@ JSObject *jsb_cocos2d_TurnOffTiles_prototype; bool js_cocos2dx_TurnOffTiles_turnOnTile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TurnOffTiles* cobj = (cocos2d::TurnOffTiles *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TurnOffTiles_turnOnTile : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TurnOffTiles_turnOnTile : Error processing arguments"); cobj->turnOnTile(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -29095,18 +29871,18 @@ bool js_cocos2dx_TurnOffTiles_turnOnTile(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TurnOffTiles_turnOffTile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TurnOffTiles* cobj = (cocos2d::TurnOffTiles *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TurnOffTiles_turnOffTile : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TurnOffTiles_turnOffTile : Error processing arguments"); cobj->turnOffTile(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -29115,9 +29891,9 @@ bool js_cocos2dx_TurnOffTiles_turnOffTile(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_TurnOffTiles_shuffle(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TurnOffTiles* cobj = (cocos2d::TurnOffTiles *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TurnOffTiles_shuffle : Invalid Native Object"); @@ -29126,10 +29902,10 @@ bool js_cocos2dx_TurnOffTiles_shuffle(JSContext *cx, uint32_t argc, jsval *vp) unsigned int arg1; #pragma warning NO CONVERSION TO NATIVE FOR unsigned int* ok = false; - ok &= jsval_to_uint32(cx, argv[1], &arg1); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TurnOffTiles_shuffle : Error processing arguments"); cobj->shuffle(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -29138,9 +29914,9 @@ bool js_cocos2dx_TurnOffTiles_shuffle(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TurnOffTiles_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TurnOffTiles* cobj = (cocos2d::TurnOffTiles *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TurnOffTiles_initWithDuration : Invalid Native Object"); @@ -29148,14 +29924,14 @@ bool js_cocos2dx_TurnOffTiles_initWithDuration(JSContext *cx, uint32_t argc, jsv double arg0; cocos2d::Size arg1; unsigned int arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TurnOffTiles_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -29164,19 +29940,19 @@ bool js_cocos2dx_TurnOffTiles_initWithDuration(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_TurnOffTiles_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Size arg1; - ok &= jsval_to_ccsize(cx, argv[1], &arg1); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } unsigned int arg2; - ok &= jsval_to_uint32(cx, argv[2], &arg2); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } cocos2d::TurnOffTiles* ret = cocos2d::TurnOffTiles::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -29188,7 +29964,7 @@ bool js_cocos2dx_TurnOffTiles_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -29196,10 +29972,10 @@ bool js_cocos2dx_TurnOffTiles_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Size arg1; - ok &= jsval_to_ccsize(cx, argv[1], &arg1); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::TurnOffTiles* ret = cocos2d::TurnOffTiles::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -29211,7 +29987,7 @@ bool js_cocos2dx_TurnOffTiles_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -29220,7 +29996,7 @@ bool js_cocos2dx_TurnOffTiles_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TurnOffTiles_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TurnOffTiles* cobj = new (std::nothrow) cocos2d::TurnOffTiles(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -29234,13 +30010,16 @@ bool js_cocos2dx_TurnOffTiles_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TurnOffTiles"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TurnOffTiles"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -29251,7 +30030,7 @@ void js_cocos2d_TurnOffTiles_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TurnOffTiles)", obj); } -void js_register_cocos2dx_TurnOffTiles(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TurnOffTiles(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TurnOffTiles_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TurnOffTiles_class->name = "TurnOffTiles"; jsb_cocos2d_TurnOffTiles_class->addProperty = JS_PropertyStub; @@ -29265,8 +30044,8 @@ void js_register_cocos2dx_TurnOffTiles(JSContext *cx, JSObject *global) { jsb_cocos2d_TurnOffTiles_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -29284,7 +30063,7 @@ void js_register_cocos2dx_TurnOffTiles(JSContext *cx, JSObject *global) { jsb_cocos2d_TurnOffTiles_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TiledGrid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_TiledGrid3DAction_prototype), jsb_cocos2d_TurnOffTiles_class, js_cocos2dx_TurnOffTiles_constructor, 0, // constructor properties, @@ -29315,18 +30094,18 @@ JSObject *jsb_cocos2d_WavesTiles3D_prototype; bool js_cocos2dx_WavesTiles3D_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::WavesTiles3D* cobj = (cocos2d::WavesTiles3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_WavesTiles3D_setAmplitudeRate : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_WavesTiles3D_setAmplitudeRate : Error processing arguments"); cobj->setAmplitudeRate(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -29335,9 +30114,9 @@ bool js_cocos2dx_WavesTiles3D_setAmplitudeRate(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_WavesTiles3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::WavesTiles3D* cobj = (cocos2d::WavesTiles3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_WavesTiles3D_initWithDuration : Invalid Native Object"); @@ -29346,15 +30125,15 @@ bool js_cocos2dx_WavesTiles3D_initWithDuration(JSContext *cx, uint32_t argc, jsv cocos2d::Size arg1; unsigned int arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_WavesTiles3D_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -29363,7 +30142,8 @@ bool js_cocos2dx_WavesTiles3D_initWithDuration(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_WavesTiles3D_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::WavesTiles3D* cobj = (cocos2d::WavesTiles3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_WavesTiles3D_getAmplitude : Invalid Native Object"); @@ -29371,7 +30151,7 @@ bool js_cocos2dx_WavesTiles3D_getAmplitude(JSContext *cx, uint32_t argc, jsval * double ret = cobj->getAmplitude(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -29380,7 +30160,8 @@ bool js_cocos2dx_WavesTiles3D_getAmplitude(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_WavesTiles3D_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::WavesTiles3D* cobj = (cocos2d::WavesTiles3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_WavesTiles3D_getAmplitudeRate : Invalid Native Object"); @@ -29388,7 +30169,7 @@ bool js_cocos2dx_WavesTiles3D_getAmplitudeRate(JSContext *cx, uint32_t argc, jsv double ret = cobj->getAmplitudeRate(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -29397,18 +30178,18 @@ bool js_cocos2dx_WavesTiles3D_getAmplitudeRate(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_WavesTiles3D_setAmplitude(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::WavesTiles3D* cobj = (cocos2d::WavesTiles3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_WavesTiles3D_setAmplitude : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_WavesTiles3D_setAmplitude : Error processing arguments"); cobj->setAmplitude(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -29417,17 +30198,17 @@ bool js_cocos2dx_WavesTiles3D_setAmplitude(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_WavesTiles3D_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { double arg0; cocos2d::Size arg1; unsigned int arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_WavesTiles3D_create : Error processing arguments"); cocos2d::WavesTiles3D* ret = cocos2d::WavesTiles3D::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -29439,7 +30220,7 @@ bool js_cocos2dx_WavesTiles3D_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_WavesTiles3D_create : wrong number of arguments"); @@ -29448,7 +30229,7 @@ bool js_cocos2dx_WavesTiles3D_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_WavesTiles3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::WavesTiles3D* cobj = new (std::nothrow) cocos2d::WavesTiles3D(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -29462,13 +30243,16 @@ bool js_cocos2dx_WavesTiles3D_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::WavesTiles3D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::WavesTiles3D"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -29479,7 +30263,7 @@ void js_cocos2d_WavesTiles3D_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (WavesTiles3D)", obj); } -void js_register_cocos2dx_WavesTiles3D(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_WavesTiles3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_WavesTiles3D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_WavesTiles3D_class->name = "WavesTiles3D"; jsb_cocos2d_WavesTiles3D_class->addProperty = JS_PropertyStub; @@ -29493,8 +30277,8 @@ void js_register_cocos2dx_WavesTiles3D(JSContext *cx, JSObject *global) { jsb_cocos2d_WavesTiles3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -29513,7 +30297,7 @@ void js_register_cocos2dx_WavesTiles3D(JSContext *cx, JSObject *global) { jsb_cocos2d_WavesTiles3D_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TiledGrid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_TiledGrid3DAction_prototype), jsb_cocos2d_WavesTiles3D_class, js_cocos2dx_WavesTiles3D_constructor, 0, // constructor properties, @@ -29544,18 +30328,18 @@ JSObject *jsb_cocos2d_JumpTiles3D_prototype; bool js_cocos2dx_JumpTiles3D_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::JumpTiles3D* cobj = (cocos2d::JumpTiles3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_JumpTiles3D_setAmplitudeRate : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_JumpTiles3D_setAmplitudeRate : Error processing arguments"); cobj->setAmplitudeRate(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -29564,9 +30348,9 @@ bool js_cocos2dx_JumpTiles3D_setAmplitudeRate(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_JumpTiles3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::JumpTiles3D* cobj = (cocos2d::JumpTiles3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_JumpTiles3D_initWithDuration : Invalid Native Object"); @@ -29575,15 +30359,15 @@ bool js_cocos2dx_JumpTiles3D_initWithDuration(JSContext *cx, uint32_t argc, jsva cocos2d::Size arg1; unsigned int arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_JumpTiles3D_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -29592,7 +30376,8 @@ bool js_cocos2dx_JumpTiles3D_initWithDuration(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_JumpTiles3D_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::JumpTiles3D* cobj = (cocos2d::JumpTiles3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_JumpTiles3D_getAmplitude : Invalid Native Object"); @@ -29600,7 +30385,7 @@ bool js_cocos2dx_JumpTiles3D_getAmplitude(JSContext *cx, uint32_t argc, jsval *v double ret = cobj->getAmplitude(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -29609,7 +30394,8 @@ bool js_cocos2dx_JumpTiles3D_getAmplitude(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_JumpTiles3D_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::JumpTiles3D* cobj = (cocos2d::JumpTiles3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_JumpTiles3D_getAmplitudeRate : Invalid Native Object"); @@ -29617,7 +30403,7 @@ bool js_cocos2dx_JumpTiles3D_getAmplitudeRate(JSContext *cx, uint32_t argc, jsva double ret = cobj->getAmplitudeRate(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -29626,18 +30412,18 @@ bool js_cocos2dx_JumpTiles3D_getAmplitudeRate(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_JumpTiles3D_setAmplitude(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::JumpTiles3D* cobj = (cocos2d::JumpTiles3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_JumpTiles3D_setAmplitude : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_JumpTiles3D_setAmplitude : Error processing arguments"); cobj->setAmplitude(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -29646,17 +30432,17 @@ bool js_cocos2dx_JumpTiles3D_setAmplitude(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_JumpTiles3D_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { double arg0; cocos2d::Size arg1; unsigned int arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_JumpTiles3D_create : Error processing arguments"); cocos2d::JumpTiles3D* ret = cocos2d::JumpTiles3D::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -29668,7 +30454,7 @@ bool js_cocos2dx_JumpTiles3D_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_JumpTiles3D_create : wrong number of arguments"); @@ -29677,7 +30463,7 @@ bool js_cocos2dx_JumpTiles3D_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_JumpTiles3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::JumpTiles3D* cobj = new (std::nothrow) cocos2d::JumpTiles3D(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -29691,13 +30477,16 @@ bool js_cocos2dx_JumpTiles3D_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::JumpTiles3D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::JumpTiles3D"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -29708,7 +30497,7 @@ void js_cocos2d_JumpTiles3D_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (JumpTiles3D)", obj); } -void js_register_cocos2dx_JumpTiles3D(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_JumpTiles3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_JumpTiles3D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_JumpTiles3D_class->name = "JumpTiles3D"; jsb_cocos2d_JumpTiles3D_class->addProperty = JS_PropertyStub; @@ -29722,8 +30511,8 @@ void js_register_cocos2dx_JumpTiles3D(JSContext *cx, JSObject *global) { jsb_cocos2d_JumpTiles3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -29742,7 +30531,7 @@ void js_register_cocos2dx_JumpTiles3D(JSContext *cx, JSObject *global) { jsb_cocos2d_JumpTiles3D_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TiledGrid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_TiledGrid3DAction_prototype), jsb_cocos2d_JumpTiles3D_class, js_cocos2dx_JumpTiles3D_constructor, 0, // constructor properties, @@ -29773,22 +30562,22 @@ JSObject *jsb_cocos2d_SplitRows_prototype; bool js_cocos2dx_SplitRows_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SplitRows* cobj = (cocos2d::SplitRows *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SplitRows_initWithDuration : Invalid Native Object"); if (argc == 2) { double arg0; unsigned int arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SplitRows_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -29797,13 +30586,13 @@ bool js_cocos2dx_SplitRows_initWithDuration(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_SplitRows_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; unsigned int arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SplitRows_create : Error processing arguments"); cocos2d::SplitRows* ret = cocos2d::SplitRows::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -29815,7 +30604,7 @@ bool js_cocos2dx_SplitRows_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_SplitRows_create : wrong number of arguments"); @@ -29824,7 +30613,7 @@ bool js_cocos2dx_SplitRows_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_SplitRows_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::SplitRows* cobj = new (std::nothrow) cocos2d::SplitRows(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -29838,13 +30627,16 @@ bool js_cocos2dx_SplitRows_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::SplitRows"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::SplitRows"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -29855,7 +30647,7 @@ void js_cocos2d_SplitRows_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (SplitRows)", obj); } -void js_register_cocos2dx_SplitRows(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_SplitRows(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_SplitRows_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_SplitRows_class->name = "SplitRows"; jsb_cocos2d_SplitRows_class->addProperty = JS_PropertyStub; @@ -29869,8 +30661,8 @@ void js_register_cocos2dx_SplitRows(JSContext *cx, JSObject *global) { jsb_cocos2d_SplitRows_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -29885,7 +30677,7 @@ void js_register_cocos2dx_SplitRows(JSContext *cx, JSObject *global) { jsb_cocos2d_SplitRows_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TiledGrid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_TiledGrid3DAction_prototype), jsb_cocos2d_SplitRows_class, js_cocos2dx_SplitRows_constructor, 0, // constructor properties, @@ -29916,22 +30708,22 @@ JSObject *jsb_cocos2d_SplitCols_prototype; bool js_cocos2dx_SplitCols_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SplitCols* cobj = (cocos2d::SplitCols *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SplitCols_initWithDuration : Invalid Native Object"); if (argc == 2) { double arg0; unsigned int arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SplitCols_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -29940,13 +30732,13 @@ bool js_cocos2dx_SplitCols_initWithDuration(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_SplitCols_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; unsigned int arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SplitCols_create : Error processing arguments"); cocos2d::SplitCols* ret = cocos2d::SplitCols::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -29958,7 +30750,7 @@ bool js_cocos2dx_SplitCols_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_SplitCols_create : wrong number of arguments"); @@ -29967,7 +30759,7 @@ bool js_cocos2dx_SplitCols_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_SplitCols_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::SplitCols* cobj = new (std::nothrow) cocos2d::SplitCols(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -29981,13 +30773,16 @@ bool js_cocos2dx_SplitCols_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::SplitCols"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::SplitCols"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -29998,7 +30793,7 @@ void js_cocos2d_SplitCols_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (SplitCols)", obj); } -void js_register_cocos2dx_SplitCols(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_SplitCols(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_SplitCols_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_SplitCols_class->name = "SplitCols"; jsb_cocos2d_SplitCols_class->addProperty = JS_PropertyStub; @@ -30012,8 +30807,8 @@ void js_register_cocos2dx_SplitCols(JSContext *cx, JSObject *global) { jsb_cocos2d_SplitCols_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -30028,7 +30823,7 @@ void js_register_cocos2dx_SplitCols(JSContext *cx, JSObject *global) { jsb_cocos2d_SplitCols_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TiledGrid3DAction_prototype, + JS::RootedObject(cx, jsb_cocos2d_TiledGrid3DAction_prototype), jsb_cocos2d_SplitCols_class, js_cocos2dx_SplitCols_constructor, 0, // constructor properties, @@ -30059,9 +30854,9 @@ JSObject *jsb_cocos2d_ActionTween_prototype; bool js_cocos2dx_ActionTween_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionTween* cobj = (cocos2d::ActionTween *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionTween_initWithDuration : Invalid Native Object"); @@ -30070,15 +30865,15 @@ bool js_cocos2dx_ActionTween_initWithDuration(JSContext *cx, uint32_t argc, jsva std::string arg1; double arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionTween_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -30087,17 +30882,17 @@ bool js_cocos2dx_ActionTween_initWithDuration(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ActionTween_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { double arg0; std::string arg1; double arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionTween_create : Error processing arguments"); cocos2d::ActionTween* ret = cocos2d::ActionTween::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -30109,7 +30904,7 @@ bool js_cocos2dx_ActionTween_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ActionTween_create : wrong number of arguments"); @@ -30125,21 +30920,21 @@ void js_cocos2d_ActionTween_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ActionTween_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ActionTween *nobj = new (std::nothrow) cocos2d::ActionTween(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ActionTween"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ActionTween"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ActionTween(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ActionTween(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ActionTween_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ActionTween_class->name = "ActionTween"; jsb_cocos2d_ActionTween_class->addProperty = JS_PropertyStub; @@ -30153,8 +30948,8 @@ void js_register_cocos2dx_ActionTween(JSContext *cx, JSObject *global) { jsb_cocos2d_ActionTween_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -30170,7 +30965,7 @@ void js_register_cocos2dx_ActionTween(JSContext *cx, JSObject *global) { jsb_cocos2d_ActionTween_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_ActionTween_class, dummy_constructor, 0, // no constructor properties, @@ -30201,7 +30996,8 @@ JSObject *jsb_cocos2d_CardinalSplineTo_prototype; bool js_cocos2dx_CardinalSplineTo_getPoints(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::CardinalSplineTo* cobj = (cocos2d::CardinalSplineTo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_CardinalSplineTo_getPoints : Invalid Native Object"); @@ -30216,7 +31012,7 @@ bool js_cocos2dx_CardinalSplineTo_getPoints(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -30225,18 +31021,18 @@ bool js_cocos2dx_CardinalSplineTo_getPoints(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_CardinalSplineTo_updatePosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::CardinalSplineTo* cobj = (cocos2d::CardinalSplineTo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_CardinalSplineTo_updatePosition : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_CardinalSplineTo_updatePosition : Error processing arguments"); cobj->updatePosition(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -30245,7 +31041,7 @@ bool js_cocos2dx_CardinalSplineTo_updatePosition(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_CardinalSplineTo_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::CardinalSplineTo* cobj = new (std::nothrow) cocos2d::CardinalSplineTo(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -30259,13 +31055,16 @@ bool js_cocos2dx_CardinalSplineTo_constructor(JSContext *cx, uint32_t argc, jsva CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::CardinalSplineTo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::CardinalSplineTo"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -30276,7 +31075,7 @@ void js_cocos2d_CardinalSplineTo_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (CardinalSplineTo)", obj); } -void js_register_cocos2dx_CardinalSplineTo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_CardinalSplineTo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_CardinalSplineTo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_CardinalSplineTo_class->name = "CardinalSplineTo"; jsb_cocos2d_CardinalSplineTo_class->addProperty = JS_PropertyStub; @@ -30290,8 +31089,8 @@ void js_register_cocos2dx_CardinalSplineTo(JSContext *cx, JSObject *global) { jsb_cocos2d_CardinalSplineTo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -30304,7 +31103,7 @@ void js_register_cocos2dx_CardinalSplineTo(JSContext *cx, JSObject *global) { jsb_cocos2d_CardinalSplineTo_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ActionInterval_prototype, + JS::RootedObject(cx, jsb_cocos2d_ActionInterval_prototype), jsb_cocos2d_CardinalSplineTo_class, js_cocos2dx_CardinalSplineTo_constructor, 0, // constructor properties, @@ -30335,7 +31134,7 @@ JSObject *jsb_cocos2d_CardinalSplineBy_prototype; bool js_cocos2dx_CardinalSplineBy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::CardinalSplineBy* cobj = new (std::nothrow) cocos2d::CardinalSplineBy(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -30349,13 +31148,16 @@ bool js_cocos2dx_CardinalSplineBy_constructor(JSContext *cx, uint32_t argc, jsva CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::CardinalSplineBy"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::CardinalSplineBy"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -30366,7 +31168,7 @@ void js_cocos2d_CardinalSplineBy_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (CardinalSplineBy)", obj); } -void js_register_cocos2dx_CardinalSplineBy(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_CardinalSplineBy(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_CardinalSplineBy_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_CardinalSplineBy_class->name = "CardinalSplineBy"; jsb_cocos2d_CardinalSplineBy_class->addProperty = JS_PropertyStub; @@ -30380,8 +31182,8 @@ void js_register_cocos2dx_CardinalSplineBy(JSContext *cx, JSObject *global) { jsb_cocos2d_CardinalSplineBy_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -30392,7 +31194,7 @@ void js_register_cocos2dx_CardinalSplineBy(JSContext *cx, JSObject *global) { jsb_cocos2d_CardinalSplineBy_prototype = JS_InitClass( cx, global, - jsb_cocos2d_CardinalSplineTo_prototype, + JS::RootedObject(cx, jsb_cocos2d_CardinalSplineTo_prototype), jsb_cocos2d_CardinalSplineBy_class, js_cocos2dx_CardinalSplineBy_constructor, 0, // constructor properties, @@ -30428,7 +31230,7 @@ void js_cocos2d_CatmullRomTo_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (CatmullRomTo)", obj); } -void js_register_cocos2dx_CatmullRomTo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_CatmullRomTo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_CatmullRomTo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_CatmullRomTo_class->name = "CatmullRomTo"; jsb_cocos2d_CatmullRomTo_class->addProperty = JS_PropertyStub; @@ -30442,8 +31244,8 @@ void js_register_cocos2dx_CatmullRomTo(JSContext *cx, JSObject *global) { jsb_cocos2d_CatmullRomTo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -30454,7 +31256,7 @@ void js_register_cocos2dx_CatmullRomTo(JSContext *cx, JSObject *global) { jsb_cocos2d_CatmullRomTo_prototype = JS_InitClass( cx, global, - jsb_cocos2d_CardinalSplineTo_prototype, + JS::RootedObject(cx, jsb_cocos2d_CardinalSplineTo_prototype), jsb_cocos2d_CatmullRomTo_class, dummy_constructor, 0, // no constructor properties, @@ -30490,7 +31292,7 @@ void js_cocos2d_CatmullRomBy_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (CatmullRomBy)", obj); } -void js_register_cocos2dx_CatmullRomBy(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_CatmullRomBy(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_CatmullRomBy_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_CatmullRomBy_class->name = "CatmullRomBy"; jsb_cocos2d_CatmullRomBy_class->addProperty = JS_PropertyStub; @@ -30504,8 +31306,8 @@ void js_register_cocos2dx_CatmullRomBy(JSContext *cx, JSObject *global) { jsb_cocos2d_CatmullRomBy_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -30516,7 +31318,7 @@ void js_register_cocos2dx_CatmullRomBy(JSContext *cx, JSObject *global) { jsb_cocos2d_CatmullRomBy_prototype = JS_InitClass( cx, global, - jsb_cocos2d_CardinalSplineBy_prototype, + JS::RootedObject(cx, jsb_cocos2d_CardinalSplineBy_prototype), jsb_cocos2d_CatmullRomBy_class, dummy_constructor, 0, // no constructor properties, @@ -30547,12 +31349,12 @@ JSObject *jsb_cocos2d_ProtectedNode_prototype; bool js_cocos2dx_ProtectedNode_addProtectedChild(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::ProtectedNode* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::ProtectedNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProtectedNode_addProtectedChild : Invalid Native Object"); @@ -30560,19 +31362,19 @@ bool js_cocos2dx_ProtectedNode_addProtectedChild(JSContext *cx, uint32_t argc, j if (argc == 2) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cobj->addProtectedChild(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -30581,16 +31383,16 @@ bool js_cocos2dx_ProtectedNode_addProtectedChild(JSContext *cx, uint32_t argc, j if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cobj->addProtectedChild(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -30599,22 +31401,22 @@ bool js_cocos2dx_ProtectedNode_addProtectedChild(JSContext *cx, uint32_t argc, j if (argc == 3) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } int arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } cobj->addProtectedChild(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -30624,13 +31426,14 @@ bool js_cocos2dx_ProtectedNode_addProtectedChild(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ProtectedNode_disableCascadeColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProtectedNode* cobj = (cocos2d::ProtectedNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProtectedNode_disableCascadeColor : Invalid Native Object"); if (argc == 0) { cobj->disableCascadeColor(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -30639,28 +31442,28 @@ bool js_cocos2dx_ProtectedNode_disableCascadeColor(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ProtectedNode_removeProtectedChildByTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProtectedNode* cobj = (cocos2d::ProtectedNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProtectedNode_removeProtectedChildByTag : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProtectedNode_removeProtectedChildByTag : Error processing arguments"); cobj->removeProtectedChildByTag(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { int arg0; bool arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProtectedNode_removeProtectedChildByTag : Error processing arguments"); cobj->removeProtectedChildByTag(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -30669,9 +31472,9 @@ bool js_cocos2dx_ProtectedNode_removeProtectedChildByTag(JSContext *cx, uint32_t } bool js_cocos2dx_ProtectedNode_reorderProtectedChild(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProtectedNode* cobj = (cocos2d::ProtectedNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProtectedNode_reorderProtectedChild : Invalid Native Object"); @@ -30679,17 +31482,17 @@ bool js_cocos2dx_ProtectedNode_reorderProtectedChild(JSContext *cx, uint32_t arg cocos2d::Node* arg0; int arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProtectedNode_reorderProtectedChild : Error processing arguments"); cobj->reorderProtectedChild(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -30698,18 +31501,18 @@ bool js_cocos2dx_ProtectedNode_reorderProtectedChild(JSContext *cx, uint32_t arg } bool js_cocos2dx_ProtectedNode_removeAllProtectedChildrenWithCleanup(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProtectedNode* cobj = (cocos2d::ProtectedNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProtectedNode_removeAllProtectedChildrenWithCleanup : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProtectedNode_removeAllProtectedChildrenWithCleanup : Error processing arguments"); cobj->removeAllProtectedChildrenWithCleanup(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -30718,13 +31521,14 @@ bool js_cocos2dx_ProtectedNode_removeAllProtectedChildrenWithCleanup(JSContext * } bool js_cocos2dx_ProtectedNode_disableCascadeOpacity(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProtectedNode* cobj = (cocos2d::ProtectedNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProtectedNode_disableCascadeOpacity : Invalid Native Object"); if (argc == 0) { cobj->disableCascadeOpacity(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -30733,13 +31537,14 @@ bool js_cocos2dx_ProtectedNode_disableCascadeOpacity(JSContext *cx, uint32_t arg } bool js_cocos2dx_ProtectedNode_sortAllProtectedChildren(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProtectedNode* cobj = (cocos2d::ProtectedNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProtectedNode_sortAllProtectedChildren : Invalid Native Object"); if (argc == 0) { cobj->sortAllProtectedChildren(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -30748,15 +31553,15 @@ bool js_cocos2dx_ProtectedNode_sortAllProtectedChildren(JSContext *cx, uint32_t } bool js_cocos2dx_ProtectedNode_getProtectedChildByTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProtectedNode* cobj = (cocos2d::ProtectedNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProtectedNode_getProtectedChildByTag : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProtectedNode_getProtectedChildByTag : Error processing arguments"); cocos2d::Node* ret = cobj->getProtectedChildByTag(arg0); jsval jsret = JSVAL_NULL; @@ -30768,7 +31573,7 @@ bool js_cocos2dx_ProtectedNode_getProtectedChildByTag(JSContext *cx, uint32_t ar jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -30777,42 +31582,42 @@ bool js_cocos2dx_ProtectedNode_getProtectedChildByTag(JSContext *cx, uint32_t ar } bool js_cocos2dx_ProtectedNode_removeProtectedChild(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProtectedNode* cobj = (cocos2d::ProtectedNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProtectedNode_removeProtectedChild : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProtectedNode_removeProtectedChild : Error processing arguments"); cobj->removeProtectedChild(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { cocos2d::Node* arg0; bool arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProtectedNode_removeProtectedChild : Error processing arguments"); cobj->removeProtectedChild(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -30821,13 +31626,14 @@ bool js_cocos2dx_ProtectedNode_removeProtectedChild(JSContext *cx, uint32_t argc } bool js_cocos2dx_ProtectedNode_removeAllProtectedChildren(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProtectedNode* cobj = (cocos2d::ProtectedNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProtectedNode_removeAllProtectedChildren : Invalid Native Object"); if (argc == 0) { cobj->removeAllProtectedChildren(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -30836,6 +31642,7 @@ bool js_cocos2dx_ProtectedNode_removeAllProtectedChildren(JSContext *cx, uint32_ } bool js_cocos2dx_ProtectedNode_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ProtectedNode* ret = cocos2d::ProtectedNode::create(); jsval jsret = JSVAL_NULL; @@ -30847,7 +31654,7 @@ bool js_cocos2dx_ProtectedNode_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ProtectedNode_create : wrong number of arguments"); @@ -30856,7 +31663,7 @@ bool js_cocos2dx_ProtectedNode_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ProtectedNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ProtectedNode* cobj = new (std::nothrow) cocos2d::ProtectedNode(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -30870,13 +31677,16 @@ bool js_cocos2dx_ProtectedNode_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ProtectedNode"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ProtectedNode"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -30887,7 +31697,7 @@ void js_cocos2d_ProtectedNode_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ProtectedNode)", obj); } -void js_register_cocos2dx_ProtectedNode(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ProtectedNode(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ProtectedNode_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ProtectedNode_class->name = "ProtectedNode"; jsb_cocos2d_ProtectedNode_class->addProperty = JS_PropertyStub; @@ -30901,8 +31711,8 @@ void js_register_cocos2dx_ProtectedNode(JSContext *cx, JSObject *global) { jsb_cocos2d_ProtectedNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -30926,7 +31736,7 @@ void js_register_cocos2dx_ProtectedNode(JSContext *cx, JSObject *global) { jsb_cocos2d_ProtectedNode_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_ProtectedNode_class, js_cocos2dx_ProtectedNode_constructor, 0, // constructor properties, @@ -30957,25 +31767,25 @@ JSObject *jsb_cocos2d_GLProgramState_prototype; bool js_cocos2dx_GLProgramState_setUniformTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::GLProgramState* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_setUniformTexture : Invalid Native Object"); do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } unsigned int arg1; - ok &= jsval_to_uint32(cx, argv[1], &arg1); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cobj->setUniformTexture(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -30983,20 +31793,20 @@ bool js_cocos2dx_GLProgramState_setUniformTexture(JSContext *cx, uint32_t argc, do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Texture2D* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cobj->setUniformTexture(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31004,20 +31814,20 @@ bool js_cocos2dx_GLProgramState_setUniformTexture(JSContext *cx, uint32_t argc, do { if (argc == 2) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } cocos2d::Texture2D* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cobj->setUniformTexture(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31025,13 +31835,13 @@ bool js_cocos2dx_GLProgramState_setUniformTexture(JSContext *cx, uint32_t argc, do { if (argc == 2) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } unsigned int arg1; - ok &= jsval_to_uint32(cx, argv[1], &arg1); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cobj->setUniformTexture(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31041,25 +31851,25 @@ bool js_cocos2dx_GLProgramState_setUniformTexture(JSContext *cx, uint32_t argc, } bool js_cocos2dx_GLProgramState_setUniformMat4(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::GLProgramState* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_setUniformMat4 : Invalid Native Object"); do { if (argc == 2) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } cocos2d::Mat4 arg1; - ok &= jsval_to_matrix(cx, argv[1], &arg1); + ok &= jsval_to_matrix(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cobj->setUniformMat4(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31067,13 +31877,13 @@ bool js_cocos2dx_GLProgramState_setUniformMat4(JSContext *cx, uint32_t argc, jsv do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Mat4 arg1; - ok &= jsval_to_matrix(cx, argv[1], &arg1); + ok &= jsval_to_matrix(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cobj->setUniformMat4(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31083,13 +31893,14 @@ bool js_cocos2dx_GLProgramState_setUniformMat4(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_GLProgramState_applyUniforms(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgramState* cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_applyUniforms : Invalid Native Object"); if (argc == 0) { cobj->applyUniforms(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -31098,26 +31909,27 @@ bool js_cocos2dx_GLProgramState_applyUniforms(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_GLProgramState_setUniformCallback(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::GLProgramState* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_setUniformCallback : Invalid Native Object"); do { if (argc == 2) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } std::function arg1; do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](cocos2d::GLProgram* larg0, cocos2d::Uniform* larg1) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[2]; do { if (larg0) { @@ -31135,8 +31947,8 @@ bool js_cocos2dx_GLProgramState_setUniformCallback(JSContext *cx, uint32_t argc, largv[1] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(2, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -31151,7 +31963,7 @@ bool js_cocos2dx_GLProgramState_setUniformCallback(JSContext *cx, uint32_t argc, ; if (!ok) { ok = true; break; } cobj->setUniformCallback(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31159,14 +31971,15 @@ bool js_cocos2dx_GLProgramState_setUniformCallback(JSContext *cx, uint32_t argc, do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::function arg1; do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](cocos2d::GLProgram* larg0, cocos2d::Uniform* larg1) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[2]; do { if (larg0) { @@ -31184,8 +31997,8 @@ bool js_cocos2dx_GLProgramState_setUniformCallback(JSContext *cx, uint32_t argc, largv[1] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(2, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -31200,7 +32013,7 @@ bool js_cocos2dx_GLProgramState_setUniformCallback(JSContext *cx, uint32_t argc, ; if (!ok) { ok = true; break; } cobj->setUniformCallback(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31210,18 +32023,18 @@ bool js_cocos2dx_GLProgramState_setUniformCallback(JSContext *cx, uint32_t argc, } bool js_cocos2dx_GLProgramState_applyGLProgram(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgramState* cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_applyGLProgram : Invalid Native Object"); if (argc == 1) { cocos2d::Mat4 arg0; - ok &= jsval_to_matrix(cx, argv[0], &arg0); + ok &= jsval_to_matrix(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgramState_applyGLProgram : Error processing arguments"); cobj->applyGLProgram(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -31230,7 +32043,8 @@ bool js_cocos2dx_GLProgramState_applyGLProgram(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_GLProgramState_getUniformCount(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgramState* cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_getUniformCount : Invalid Native Object"); @@ -31238,7 +32052,7 @@ bool js_cocos2dx_GLProgramState_getUniformCount(JSContext *cx, uint32_t argc, js ssize_t ret = cobj->getUniformCount(); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -31247,23 +32061,23 @@ bool js_cocos2dx_GLProgramState_getUniformCount(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_GLProgramState_applyAttributes(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgramState* cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_applyAttributes : Invalid Native Object"); if (argc == 0) { cobj->applyAttributes(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgramState_applyAttributes : Error processing arguments"); cobj->applyAttributes(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -31272,25 +32086,25 @@ bool js_cocos2dx_GLProgramState_applyAttributes(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_GLProgramState_setUniformFloat(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::GLProgramState* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_setUniformFloat : Invalid Native Object"); do { if (argc == 2) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } cobj->setUniformFloat(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31298,13 +32112,13 @@ bool js_cocos2dx_GLProgramState_setUniformFloat(JSContext *cx, uint32_t argc, js do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } cobj->setUniformFloat(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31314,25 +32128,25 @@ bool js_cocos2dx_GLProgramState_setUniformFloat(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_GLProgramState_setUniformVec3(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::GLProgramState* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_setUniformVec3 : Invalid Native Object"); do { if (argc == 2) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } cocos2d::Vec3 arg1; - ok &= jsval_to_vector3(cx, argv[1], &arg1); + ok &= jsval_to_vector3(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cobj->setUniformVec3(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31340,13 +32154,13 @@ bool js_cocos2dx_GLProgramState_setUniformVec3(JSContext *cx, uint32_t argc, jsv do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Vec3 arg1; - ok &= jsval_to_vector3(cx, argv[1], &arg1); + ok &= jsval_to_vector3(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cobj->setUniformVec3(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31356,25 +32170,25 @@ bool js_cocos2dx_GLProgramState_setUniformVec3(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_GLProgramState_setUniformInt(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::GLProgramState* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_setUniformInt : Invalid Native Object"); do { if (argc == 2) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cobj->setUniformInt(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31382,13 +32196,13 @@ bool js_cocos2dx_GLProgramState_setUniformInt(JSContext *cx, uint32_t argc, jsva do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cobj->setUniformInt(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31398,7 +32212,8 @@ bool js_cocos2dx_GLProgramState_setUniformInt(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_GLProgramState_getVertexAttribCount(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgramState* cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_getVertexAttribCount : Invalid Native Object"); @@ -31406,7 +32221,7 @@ bool js_cocos2dx_GLProgramState_getVertexAttribCount(JSContext *cx, uint32_t arg ssize_t ret = cobj->getVertexAttribCount(); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -31415,25 +32230,25 @@ bool js_cocos2dx_GLProgramState_getVertexAttribCount(JSContext *cx, uint32_t arg } bool js_cocos2dx_GLProgramState_setGLProgram(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgramState* cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_setGLProgram : Invalid Native Object"); if (argc == 1) { cocos2d::GLProgram* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::GLProgram*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgramState_setGLProgram : Error processing arguments"); cobj->setGLProgram(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -31442,25 +32257,25 @@ bool js_cocos2dx_GLProgramState_setGLProgram(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_GLProgramState_setUniformVec2(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::GLProgramState* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_setUniformVec2 : Invalid Native Object"); do { if (argc == 2) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } cocos2d::Vec2 arg1; - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cobj->setUniformVec2(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31468,13 +32283,13 @@ bool js_cocos2dx_GLProgramState_setUniformVec2(JSContext *cx, uint32_t argc, jsv do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Vec2 arg1; - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cobj->setUniformVec2(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -31484,7 +32299,8 @@ bool js_cocos2dx_GLProgramState_setUniformVec2(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_GLProgramState_getVertexAttribsFlags(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgramState* cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_getVertexAttribsFlags : Invalid Native Object"); @@ -31492,7 +32308,7 @@ bool js_cocos2dx_GLProgramState_getVertexAttribsFlags(JSContext *cx, uint32_t ar unsigned int ret = cobj->getVertexAttribsFlags(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -31501,21 +32317,22 @@ bool js_cocos2dx_GLProgramState_getVertexAttribsFlags(JSContext *cx, uint32_t ar } bool js_cocos2dx_GLProgramState_setVertexAttribCallback(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgramState* cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_setVertexAttribCallback : Invalid Native Object"); if (argc == 2) { std::string arg0; std::function arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](cocos2d::VertexAttrib* larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -31525,8 +32342,8 @@ bool js_cocos2dx_GLProgramState_setVertexAttribCallback(JSContext *cx, uint32_t largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -31541,7 +32358,7 @@ bool js_cocos2dx_GLProgramState_setVertexAttribCallback(JSContext *cx, uint32_t ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgramState_setVertexAttribCallback : Error processing arguments"); cobj->setVertexAttribCallback(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -31550,58 +32367,28 @@ bool js_cocos2dx_GLProgramState_setVertexAttribCallback(JSContext *cx, uint32_t } bool js_cocos2dx_GLProgramState_apply(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgramState* cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_apply : Invalid Native Object"); if (argc == 1) { cocos2d::Mat4 arg0; - ok &= jsval_to_matrix(cx, argv[0], &arg0); + ok &= jsval_to_matrix(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgramState_apply : Error processing arguments"); cobj->apply(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_GLProgramState_apply : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_GLProgramState_setVertexAttribPointer(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::GLProgramState* cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_setVertexAttribPointer : Invalid Native Object"); - if (argc == 6) { - std::string arg0; - int arg1; - unsigned int arg2; - uint16_t arg3; - int arg4; - void* arg5; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); - ok &= jsval_to_uint16(cx, argv[3], &arg3); - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); - #pragma warning NO CONVERSION TO NATIVE FOR void* - ok = false; - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgramState_setVertexAttribPointer : Error processing arguments"); - cobj->setVertexAttribPointer(arg0, arg1, arg2, arg3, arg4, arg5); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_GLProgramState_setVertexAttribPointer : wrong number of arguments: %d, was expecting %d", argc, 6); - return false; -} bool js_cocos2dx_GLProgramState_getGLProgram(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgramState* cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_getGLProgram : Invalid Native Object"); @@ -31616,7 +32403,7 @@ bool js_cocos2dx_GLProgramState_getGLProgram(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -31625,14 +32412,14 @@ bool js_cocos2dx_GLProgramState_getGLProgram(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_GLProgramState_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::GLProgram* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::GLProgram*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -31648,7 +32435,7 @@ bool js_cocos2dx_GLProgramState_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_GLProgramState_create : wrong number of arguments"); @@ -31657,11 +32444,11 @@ bool js_cocos2dx_GLProgramState_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_GLProgramState_getOrCreateWithGLProgramName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgramState_getOrCreateWithGLProgramName : Error processing arguments"); cocos2d::GLProgramState* ret = cocos2d::GLProgramState::getOrCreateWithGLProgramName(arg0); jsval jsret = JSVAL_NULL; @@ -31673,7 +32460,7 @@ bool js_cocos2dx_GLProgramState_getOrCreateWithGLProgramName(JSContext *cx, uint jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_GLProgramState_getOrCreateWithGLProgramName : wrong number of arguments"); @@ -31682,14 +32469,14 @@ bool js_cocos2dx_GLProgramState_getOrCreateWithGLProgramName(JSContext *cx, uint bool js_cocos2dx_GLProgramState_getOrCreateWithGLProgram(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::GLProgram* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::GLProgram*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -31705,7 +32492,7 @@ bool js_cocos2dx_GLProgramState_getOrCreateWithGLProgram(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_GLProgramState_getOrCreateWithGLProgram : wrong number of arguments"); @@ -31718,7 +32505,7 @@ void js_cocos2d_GLProgramState_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (GLProgramState)", obj); } -void js_register_cocos2dx_GLProgramState(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_GLProgramState(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_GLProgramState_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_GLProgramState_class->name = "GLProgramState"; jsb_cocos2d_GLProgramState_class->addProperty = JS_PropertyStub; @@ -31732,8 +32519,8 @@ void js_register_cocos2dx_GLProgramState(JSContext *cx, JSObject *global) { jsb_cocos2d_GLProgramState_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -31753,7 +32540,6 @@ void js_register_cocos2dx_GLProgramState(JSContext *cx, JSObject *global) { JS_FN("getVertexAttribsFlags", js_cocos2dx_GLProgramState_getVertexAttribsFlags, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setVertexAttribCallback", js_cocos2dx_GLProgramState_setVertexAttribCallback, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("apply", js_cocos2dx_GLProgramState_apply, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setVertexAttribPointer", js_cocos2dx_GLProgramState_setVertexAttribPointer, 6, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getGLProgram", js_cocos2dx_GLProgramState_getGLProgram, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -31767,7 +32553,7 @@ void js_register_cocos2dx_GLProgramState(JSContext *cx, JSObject *global) { jsb_cocos2d_GLProgramState_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_GLProgramState_class, dummy_constructor, 0, // no constructor properties, @@ -31798,13 +32584,14 @@ JSObject *jsb_cocos2d_AtlasNode_prototype; bool js_cocos2dx_AtlasNode_updateAtlasValues(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AtlasNode* cobj = (cocos2d::AtlasNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AtlasNode_updateAtlasValues : Invalid Native Object"); if (argc == 0) { cobj->updateAtlasValues(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -31813,9 +32600,9 @@ bool js_cocos2dx_AtlasNode_updateAtlasValues(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_AtlasNode_initWithTileFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AtlasNode* cobj = (cocos2d::AtlasNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AtlasNode_initWithTileFile : Invalid Native Object"); @@ -31824,15 +32611,15 @@ bool js_cocos2dx_AtlasNode_initWithTileFile(JSContext *cx, uint32_t argc, jsval int arg1; int arg2; int arg3; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AtlasNode_initWithTileFile : Error processing arguments"); bool ret = cobj->initWithTileFile(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -31841,7 +32628,8 @@ bool js_cocos2dx_AtlasNode_initWithTileFile(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_AtlasNode_getTexture(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AtlasNode* cobj = (cocos2d::AtlasNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AtlasNode_getTexture : Invalid Native Object"); @@ -31856,7 +32644,7 @@ bool js_cocos2dx_AtlasNode_getTexture(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -31865,25 +32653,25 @@ bool js_cocos2dx_AtlasNode_getTexture(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_AtlasNode_setTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AtlasNode* cobj = (cocos2d::AtlasNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AtlasNode_setTextureAtlas : Invalid Native Object"); if (argc == 1) { cocos2d::TextureAtlas* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::TextureAtlas*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AtlasNode_setTextureAtlas : Error processing arguments"); cobj->setTextureAtlas(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -31892,18 +32680,18 @@ bool js_cocos2dx_AtlasNode_setTextureAtlas(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_AtlasNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AtlasNode* cobj = (cocos2d::AtlasNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AtlasNode_setBlendFunc : Invalid Native Object"); if (argc == 1) { cocos2d::BlendFunc arg0; - ok &= jsval_to_blendfunc(cx, argv[0], &arg0); + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AtlasNode_setBlendFunc : Error processing arguments"); cobj->setBlendFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -31912,7 +32700,8 @@ bool js_cocos2dx_AtlasNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_AtlasNode_getTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AtlasNode* cobj = (cocos2d::AtlasNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AtlasNode_getTextureAtlas : Invalid Native Object"); @@ -31927,7 +32716,7 @@ bool js_cocos2dx_AtlasNode_getTextureAtlas(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -31936,7 +32725,8 @@ bool js_cocos2dx_AtlasNode_getTextureAtlas(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_AtlasNode_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AtlasNode* cobj = (cocos2d::AtlasNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AtlasNode_getBlendFunc : Invalid Native Object"); @@ -31944,7 +32734,7 @@ bool js_cocos2dx_AtlasNode_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); jsval jsret = JSVAL_NULL; jsret = blendfunc_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -31953,7 +32743,8 @@ bool js_cocos2dx_AtlasNode_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_AtlasNode_getQuadsToDraw(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AtlasNode* cobj = (cocos2d::AtlasNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AtlasNode_getQuadsToDraw : Invalid Native Object"); @@ -31961,7 +32752,7 @@ bool js_cocos2dx_AtlasNode_getQuadsToDraw(JSContext *cx, uint32_t argc, jsval *v ssize_t ret = cobj->getQuadsToDraw(); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -31970,25 +32761,25 @@ bool js_cocos2dx_AtlasNode_getQuadsToDraw(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_AtlasNode_setTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AtlasNode* cobj = (cocos2d::AtlasNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AtlasNode_setTexture : Invalid Native Object"); if (argc == 1) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AtlasNode_setTexture : Error processing arguments"); cobj->setTexture(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -31997,9 +32788,9 @@ bool js_cocos2dx_AtlasNode_setTexture(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_AtlasNode_initWithTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AtlasNode* cobj = (cocos2d::AtlasNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AtlasNode_initWithTexture : Invalid Native Object"); @@ -32009,21 +32800,21 @@ bool js_cocos2dx_AtlasNode_initWithTexture(JSContext *cx, uint32_t argc, jsval * int arg2; int arg3; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AtlasNode_initWithTexture : Error processing arguments"); bool ret = cobj->initWithTexture(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -32032,18 +32823,18 @@ bool js_cocos2dx_AtlasNode_initWithTexture(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_AtlasNode_setQuadsToDraw(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AtlasNode* cobj = (cocos2d::AtlasNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AtlasNode_setQuadsToDraw : Invalid Native Object"); if (argc == 1) { ssize_t arg0; - ok &= jsval_to_ssize(cx, argv[0], &arg0); + ok &= jsval_to_ssize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AtlasNode_setQuadsToDraw : Error processing arguments"); cobj->setQuadsToDraw(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32052,17 +32843,17 @@ bool js_cocos2dx_AtlasNode_setQuadsToDraw(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_AtlasNode_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { std::string arg0; int arg1; int arg2; int arg3; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AtlasNode_create : Error processing arguments"); cocos2d::AtlasNode* ret = cocos2d::AtlasNode::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -32074,7 +32865,7 @@ bool js_cocos2dx_AtlasNode_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_AtlasNode_create : wrong number of arguments"); @@ -32083,7 +32874,7 @@ bool js_cocos2dx_AtlasNode_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_AtlasNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::AtlasNode* cobj = new (std::nothrow) cocos2d::AtlasNode(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -32097,13 +32888,16 @@ bool js_cocos2dx_AtlasNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::AtlasNode"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::AtlasNode"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -32114,7 +32908,7 @@ void js_cocos2d_AtlasNode_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (AtlasNode)", obj); } -void js_register_cocos2dx_AtlasNode(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_AtlasNode(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_AtlasNode_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_AtlasNode_class->name = "AtlasNode"; jsb_cocos2d_AtlasNode_class->addProperty = JS_PropertyStub; @@ -32128,8 +32922,8 @@ void js_register_cocos2dx_AtlasNode(JSContext *cx, JSObject *global) { jsb_cocos2d_AtlasNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -32154,7 +32948,7 @@ void js_register_cocos2dx_AtlasNode(JSContext *cx, JSObject *global) { jsb_cocos2d_AtlasNode_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_AtlasNode_class, js_cocos2dx_AtlasNode_constructor, 0, // constructor properties, @@ -32185,9 +32979,9 @@ JSObject *jsb_cocos2d_DrawNode_prototype; bool js_cocos2dx_DrawNode_drawLine(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawLine : Invalid Native Object"); @@ -32195,12 +32989,12 @@ bool js_cocos2dx_DrawNode_drawLine(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec2 arg0; cocos2d::Vec2 arg1; cocos2d::Color4F arg2; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); - ok &= jsval_to_cccolor4f(cx, argv[2], &arg2); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + ok &= jsval_to_cccolor4f(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_drawLine : Error processing arguments"); cobj->drawLine(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32209,65 +33003,99 @@ bool js_cocos2dx_DrawNode_drawLine(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_drawPoints(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + + JS::RootedObject obj(cx); + cocos2d::DrawNode* cobj = NULL; + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); + cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawPoints : Invalid Native Object"); - if (argc == 3) { - const cocos2d::Vec2* arg0; - unsigned int arg1; - cocos2d::Color4F arg2; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (const cocos2d::Vec2*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); - ok &= jsval_to_cccolor4f(cx, argv[2], &arg2); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_drawPoints : Error processing arguments"); - cobj->drawPoints(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } + do { + if (argc == 4) { + const cocos2d::Vec2* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (const cocos2d::Vec2*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + unsigned int arg1; + ok &= jsval_to_uint32(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + double arg2; + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + if (!ok) { ok = true; break; } + cocos2d::Color4F arg3; + ok &= jsval_to_cccolor4f(cx, args.get(3), &arg3); + if (!ok) { ok = true; break; } + cobj->drawPoints(arg0, arg1, arg2, arg3); + args.rval().setUndefined(); + return true; + } + } while(0); + + do { + if (argc == 3) { + const cocos2d::Vec2* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (const cocos2d::Vec2*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + unsigned int arg1; + ok &= jsval_to_uint32(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::Color4F arg2; + ok &= jsval_to_cccolor4f(cx, args.get(2), &arg2); + if (!ok) { ok = true; break; } + cobj->drawPoints(arg0, arg1, arg2); + args.rval().setUndefined(); + return true; + } + } while(0); - JS_ReportError(cx, "js_cocos2dx_DrawNode_drawPoints : wrong number of arguments: %d, was expecting %d", argc, 3); + JS_ReportError(cx, "js_cocos2dx_DrawNode_drawPoints : wrong number of arguments"); return false; } bool js_cocos2dx_DrawNode_drawRect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::DrawNode* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawRect : Invalid Native Object"); do { if (argc == 5) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Vec2 arg1; - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::Vec2 arg2; - ok &= jsval_to_vector2(cx, argv[2], &arg2); + ok &= jsval_to_vector2(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } cocos2d::Vec2 arg3; - ok &= jsval_to_vector2(cx, argv[3], &arg3); + ok &= jsval_to_vector2(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cocos2d::Color4F arg4; - ok &= jsval_to_cccolor4f(cx, argv[4], &arg4); + ok &= jsval_to_cccolor4f(cx, args.get(4), &arg4); if (!ok) { ok = true; break; } cobj->drawRect(arg0, arg1, arg2, arg3, arg4); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -32275,16 +33103,16 @@ bool js_cocos2dx_DrawNode_drawRect(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 3) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Vec2 arg1; - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::Color4F arg2; - ok &= jsval_to_cccolor4f(cx, argv[2], &arg2); + ok &= jsval_to_cccolor4f(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } cobj->drawRect(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -32294,34 +33122,34 @@ bool js_cocos2dx_DrawNode_drawRect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_drawSolidCircle(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::DrawNode* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawSolidCircle : Invalid Native Object"); do { if (argc == 5) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } unsigned int arg3; - ok &= jsval_to_uint32(cx, argv[3], &arg3); + ok &= jsval_to_uint32(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cocos2d::Color4F arg4; - ok &= jsval_to_cccolor4f(cx, argv[4], &arg4); + ok &= jsval_to_cccolor4f(cx, args.get(4), &arg4); if (!ok) { ok = true; break; } cobj->drawSolidCircle(arg0, arg1, arg2, arg3, arg4); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -32329,28 +33157,28 @@ bool js_cocos2dx_DrawNode_drawSolidCircle(JSContext *cx, uint32_t argc, jsval *v do { if (argc == 7) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } unsigned int arg3; - ok &= jsval_to_uint32(cx, argv[3], &arg3); + ok &= jsval_to_uint32(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } double arg4; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[4]), &arg4); + ok &= JS::ToNumber( cx, args.get(4), &arg4) && !isnan(arg4); if (!ok) { ok = true; break; } double arg5; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[5]), &arg5); + ok &= JS::ToNumber( cx, args.get(5), &arg5) && !isnan(arg5); if (!ok) { ok = true; break; } cocos2d::Color4F arg6; - ok &= jsval_to_cccolor4f(cx, argv[6], &arg6); + ok &= jsval_to_cccolor4f(cx, args.get(6), &arg6); if (!ok) { ok = true; break; } cobj->drawSolidCircle(arg0, arg1, arg2, arg3, arg4, arg5, arg6); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -32360,48 +33188,31 @@ bool js_cocos2dx_DrawNode_drawSolidCircle(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_DrawNode_onDrawGLPoint(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_onDrawGLPoint : Invalid Native Object"); if (argc == 2) { cocos2d::Mat4 arg0; unsigned int arg1; - ok &= jsval_to_matrix(cx, argv[0], &arg0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); + ok &= jsval_to_matrix(cx, args.get(0), &arg0); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_onDrawGLPoint : Error processing arguments"); cobj->onDrawGLPoint(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_DrawNode_onDrawGLPoint : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_DrawNode_init(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_init : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->init(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_DrawNode_init : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_DrawNode_drawDot(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawDot : Invalid Native Object"); @@ -32409,12 +33220,12 @@ bool js_cocos2dx_DrawNode_drawDot(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec2 arg0; double arg1; cocos2d::Color4F arg2; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= jsval_to_cccolor4f(cx, argv[2], &arg2); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= jsval_to_cccolor4f(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_drawDot : Error processing arguments"); cobj->drawDot(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32423,9 +33234,9 @@ bool js_cocos2dx_DrawNode_drawDot(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_drawCatmullRom(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawCatmullRom : Invalid Native Object"); @@ -32434,18 +33245,18 @@ bool js_cocos2dx_DrawNode_drawCatmullRom(JSContext *cx, uint32_t argc, jsval *vp unsigned int arg1; cocos2d::Color4F arg2; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::PointArray*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); - ok &= jsval_to_cccolor4f(cx, argv[2], &arg2); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); + ok &= jsval_to_cccolor4f(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_drawCatmullRom : Error processing arguments"); cobj->drawCatmullRom(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32454,9 +33265,9 @@ bool js_cocos2dx_DrawNode_drawCatmullRom(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_DrawNode_drawSegment(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawSegment : Invalid Native Object"); @@ -32465,13 +33276,13 @@ bool js_cocos2dx_DrawNode_drawSegment(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec2 arg1; double arg2; cocos2d::Color4F arg3; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= jsval_to_cccolor4f(cx, argv[3], &arg3); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= jsval_to_cccolor4f(cx, args.get(3), &arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_drawSegment : Error processing arguments"); cobj->drawSegment(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32480,7 +33291,8 @@ bool js_cocos2dx_DrawNode_drawSegment(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_getBlendFunc : Invalid Native Object"); @@ -32488,7 +33300,7 @@ bool js_cocos2dx_DrawNode_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); jsval jsret = JSVAL_NULL; jsret = blendfunc_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -32497,20 +33309,20 @@ bool js_cocos2dx_DrawNode_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_onDraw(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_onDraw : Invalid Native Object"); if (argc == 2) { cocos2d::Mat4 arg0; unsigned int arg1; - ok &= jsval_to_matrix(cx, argv[0], &arg0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); + ok &= jsval_to_matrix(cx, args.get(0), &arg0); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_onDraw : Error processing arguments"); cobj->onDraw(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32519,36 +33331,36 @@ bool js_cocos2dx_DrawNode_onDraw(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_drawCircle(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::DrawNode* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawCircle : Invalid Native Object"); do { if (argc == 6) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } unsigned int arg3; - ok &= jsval_to_uint32(cx, argv[3], &arg3); + ok &= jsval_to_uint32(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } bool arg4; - arg4 = JS::ToBoolean(JS::RootedValue(cx, argv[4])); + arg4 = JS::ToBoolean(args.get(4)); cocos2d::Color4F arg5; - ok &= jsval_to_cccolor4f(cx, argv[5], &arg5); + ok &= jsval_to_cccolor4f(cx, args.get(5), &arg5); if (!ok) { ok = true; break; } cobj->drawCircle(arg0, arg1, arg2, arg3, arg4, arg5); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -32556,30 +33368,30 @@ bool js_cocos2dx_DrawNode_drawCircle(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 8) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } unsigned int arg3; - ok &= jsval_to_uint32(cx, argv[3], &arg3); + ok &= jsval_to_uint32(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } bool arg4; - arg4 = JS::ToBoolean(JS::RootedValue(cx, argv[4])); + arg4 = JS::ToBoolean(args.get(4)); double arg5; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[5]), &arg5); + ok &= JS::ToNumber( cx, args.get(5), &arg5) && !isnan(arg5); if (!ok) { ok = true; break; } double arg6; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[6]), &arg6); + ok &= JS::ToNumber( cx, args.get(6), &arg6) && !isnan(arg6); if (!ok) { ok = true; break; } cocos2d::Color4F arg7; - ok &= jsval_to_cccolor4f(cx, argv[7], &arg7); + ok &= jsval_to_cccolor4f(cx, args.get(7), &arg7); if (!ok) { ok = true; break; } cobj->drawCircle(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -32589,9 +33401,9 @@ bool js_cocos2dx_DrawNode_drawCircle(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_drawQuadBezier(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawQuadBezier : Invalid Native Object"); @@ -32601,14 +33413,14 @@ bool js_cocos2dx_DrawNode_drawQuadBezier(JSContext *cx, uint32_t argc, jsval *vp cocos2d::Vec2 arg2; unsigned int arg3; cocos2d::Color4F arg4; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); - ok &= jsval_to_vector2(cx, argv[2], &arg2); - ok &= jsval_to_uint32(cx, argv[3], &arg3); - ok &= jsval_to_cccolor4f(cx, argv[4], &arg4); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + ok &= jsval_to_vector2(cx, args.get(2), &arg2); + ok &= jsval_to_uint32(cx, args.get(3), &arg3); + ok &= jsval_to_cccolor4f(cx, args.get(4), &arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_drawQuadBezier : Error processing arguments"); cobj->drawQuadBezier(arg0, arg1, arg2, arg3, arg4); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32617,20 +33429,20 @@ bool js_cocos2dx_DrawNode_drawQuadBezier(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_DrawNode_onDrawGLLine(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_onDrawGLLine : Invalid Native Object"); if (argc == 2) { cocos2d::Mat4 arg0; unsigned int arg1; - ok &= jsval_to_matrix(cx, argv[0], &arg0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); + ok &= jsval_to_matrix(cx, args.get(0), &arg0); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_onDrawGLLine : Error processing arguments"); cobj->onDrawGLLine(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32639,9 +33451,9 @@ bool js_cocos2dx_DrawNode_onDrawGLLine(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_drawSolidPoly(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawSolidPoly : Invalid Native Object"); @@ -32650,18 +33462,18 @@ bool js_cocos2dx_DrawNode_drawSolidPoly(JSContext *cx, uint32_t argc, jsval *vp) unsigned int arg1; cocos2d::Color4F arg2; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (const cocos2d::Vec2*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); - ok &= jsval_to_cccolor4f(cx, argv[2], &arg2); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); + ok &= jsval_to_cccolor4f(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_drawSolidPoly : Error processing arguments"); cobj->drawSolidPoly(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32670,9 +33482,9 @@ bool js_cocos2dx_DrawNode_drawSolidPoly(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_drawTriangle(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawTriangle : Invalid Native Object"); @@ -32681,13 +33493,13 @@ bool js_cocos2dx_DrawNode_drawTriangle(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec2 arg1; cocos2d::Vec2 arg2; cocos2d::Color4F arg3; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); - ok &= jsval_to_vector2(cx, argv[2], &arg2); - ok &= jsval_to_cccolor4f(cx, argv[3], &arg3); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + ok &= jsval_to_vector2(cx, args.get(2), &arg2); + ok &= jsval_to_cccolor4f(cx, args.get(3), &arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_drawTriangle : Error processing arguments"); cobj->drawTriangle(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32696,18 +33508,18 @@ bool js_cocos2dx_DrawNode_drawTriangle(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_setBlendFunc : Invalid Native Object"); if (argc == 1) { cocos2d::BlendFunc arg0; - ok &= jsval_to_blendfunc(cx, argv[0], &arg0); + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_setBlendFunc : Error processing arguments"); cobj->setBlendFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32716,13 +33528,14 @@ bool js_cocos2dx_DrawNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_clear(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_clear : Invalid Native Object"); if (argc == 0) { cobj->clear(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32731,9 +33544,9 @@ bool js_cocos2dx_DrawNode_clear(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_drawCardinalSpline(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawCardinalSpline : Invalid Native Object"); @@ -32743,19 +33556,19 @@ bool js_cocos2dx_DrawNode_drawCardinalSpline(JSContext *cx, uint32_t argc, jsval unsigned int arg2; cocos2d::Color4F arg3; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::PointArray*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= jsval_to_uint32(cx, argv[2], &arg2); - ok &= jsval_to_cccolor4f(cx, argv[3], &arg3); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + ok &= jsval_to_cccolor4f(cx, args.get(3), &arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_drawCardinalSpline : Error processing arguments"); cobj->drawCardinalSpline(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32764,9 +33577,9 @@ bool js_cocos2dx_DrawNode_drawCardinalSpline(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_DrawNode_drawSolidRect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawSolidRect : Invalid Native Object"); @@ -32774,12 +33587,12 @@ bool js_cocos2dx_DrawNode_drawSolidRect(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec2 arg0; cocos2d::Vec2 arg1; cocos2d::Color4F arg2; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); - ok &= jsval_to_cccolor4f(cx, argv[2], &arg2); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + ok &= jsval_to_cccolor4f(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_drawSolidRect : Error processing arguments"); cobj->drawSolidRect(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32788,9 +33601,9 @@ bool js_cocos2dx_DrawNode_drawSolidRect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_drawPoly(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawPoly : Invalid Native Object"); @@ -32800,19 +33613,19 @@ bool js_cocos2dx_DrawNode_drawPoly(JSContext *cx, uint32_t argc, jsval *vp) bool arg2; cocos2d::Color4F arg3; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (const cocos2d::Vec2*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); - ok &= jsval_to_cccolor4f(cx, argv[3], &arg3); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); + arg2 = JS::ToBoolean(args.get(2)); + ok &= jsval_to_cccolor4f(cx, args.get(3), &arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_drawPoly : Error processing arguments"); cobj->drawPoly(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32821,9 +33634,9 @@ bool js_cocos2dx_DrawNode_drawPoly(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_drawPoint(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawPoint : Invalid Native Object"); @@ -32831,12 +33644,12 @@ bool js_cocos2dx_DrawNode_drawPoint(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec2 arg0; double arg1; cocos2d::Color4F arg2; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= jsval_to_cccolor4f(cx, argv[2], &arg2); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= jsval_to_cccolor4f(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_drawPoint : Error processing arguments"); cobj->drawPoint(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32845,9 +33658,9 @@ bool js_cocos2dx_DrawNode_drawPoint(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_drawCubicBezier(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_drawCubicBezier : Invalid Native Object"); @@ -32858,15 +33671,15 @@ bool js_cocos2dx_DrawNode_drawCubicBezier(JSContext *cx, uint32_t argc, jsval *v cocos2d::Vec2 arg3; unsigned int arg4; cocos2d::Color4F arg5; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); - ok &= jsval_to_vector2(cx, argv[2], &arg2); - ok &= jsval_to_vector2(cx, argv[3], &arg3); - ok &= jsval_to_uint32(cx, argv[4], &arg4); - ok &= jsval_to_cccolor4f(cx, argv[5], &arg5); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + ok &= jsval_to_vector2(cx, args.get(2), &arg2); + ok &= jsval_to_vector2(cx, args.get(3), &arg3); + ok &= jsval_to_uint32(cx, args.get(4), &arg4); + ok &= jsval_to_cccolor4f(cx, args.get(5), &arg5); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_drawCubicBezier : Error processing arguments"); cobj->drawCubicBezier(arg0, arg1, arg2, arg3, arg4, arg5); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -32875,6 +33688,7 @@ bool js_cocos2dx_DrawNode_drawCubicBezier(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_DrawNode_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::DrawNode* ret = cocos2d::DrawNode::create(); jsval jsret = JSVAL_NULL; @@ -32886,7 +33700,7 @@ bool js_cocos2dx_DrawNode_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_DrawNode_create : wrong number of arguments"); @@ -32895,7 +33709,7 @@ bool js_cocos2dx_DrawNode_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_DrawNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::DrawNode* cobj = new (std::nothrow) cocos2d::DrawNode(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -32909,13 +33723,16 @@ bool js_cocos2dx_DrawNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::DrawNode"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::DrawNode"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -32928,21 +33745,21 @@ void js_cocos2d_DrawNode_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_DrawNode_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::DrawNode *nobj = new (std::nothrow) cocos2d::DrawNode(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::DrawNode"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::DrawNode"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_DrawNode(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_DrawNode(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_DrawNode_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_DrawNode_class->name = "DrawNode"; jsb_cocos2d_DrawNode_class->addProperty = JS_PropertyStub; @@ -32956,8 +33773,8 @@ void js_register_cocos2dx_DrawNode(JSContext *cx, JSObject *global) { jsb_cocos2d_DrawNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -32966,7 +33783,6 @@ void js_register_cocos2dx_DrawNode(JSContext *cx, JSObject *global) { JS_FN("drawRect", js_cocos2dx_DrawNode_drawRect, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("drawSolidCircle", js_cocos2dx_DrawNode_drawSolidCircle, 5, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("onDrawGLPoint", js_cocos2dx_DrawNode_onDrawGLPoint, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_DrawNode_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("drawDot", js_cocos2dx_DrawNode_drawDot, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("drawCatmullRom", js_cocos2dx_DrawNode_drawCatmullRom, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("drawSegment", js_cocos2dx_DrawNode_drawSegment, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -32995,7 +33811,7 @@ void js_register_cocos2dx_DrawNode(JSContext *cx, JSObject *global) { jsb_cocos2d_DrawNode_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_DrawNode_class, js_cocos2dx_DrawNode_constructor, 0, // constructor properties, @@ -33026,18 +33842,18 @@ JSObject *jsb_cocos2d_LabelAtlas_prototype; bool js_cocos2dx_LabelAtlas_setString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelAtlas* cobj = (cocos2d::LabelAtlas *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelAtlas_setString : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelAtlas_setString : Error processing arguments"); cobj->setString(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33046,27 +33862,27 @@ bool js_cocos2dx_LabelAtlas_setString(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelAtlas_initWithString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::LabelAtlas* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::LabelAtlas *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelAtlas_initWithString : Invalid Native Object"); do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool ret = cobj->initWithString(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -33074,24 +33890,24 @@ bool js_cocos2dx_LabelAtlas_initWithString(JSContext *cx, uint32_t argc, jsval * do { if (argc == 5) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } int arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } int arg3; - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); if (!ok) { ok = true; break; } int arg4; - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); if (!ok) { ok = true; break; } bool ret = cobj->initWithString(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -33099,31 +33915,31 @@ bool js_cocos2dx_LabelAtlas_initWithString(JSContext *cx, uint32_t argc, jsval * do { if (argc == 5) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Texture2D* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } int arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } int arg3; - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); if (!ok) { ok = true; break; } int arg4; - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); if (!ok) { ok = true; break; } bool ret = cobj->initWithString(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -33131,24 +33947,10 @@ bool js_cocos2dx_LabelAtlas_initWithString(JSContext *cx, uint32_t argc, jsval * JS_ReportError(cx, "js_cocos2dx_LabelAtlas_initWithString : wrong number of arguments"); return false; } -bool js_cocos2dx_LabelAtlas_updateAtlasValues(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::LabelAtlas* cobj = (cocos2d::LabelAtlas *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelAtlas_updateAtlasValues : Invalid Native Object"); - if (argc == 0) { - cobj->updateAtlasValues(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_LabelAtlas_updateAtlasValues : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_LabelAtlas_getString(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelAtlas* cobj = (cocos2d::LabelAtlas *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelAtlas_getString : Invalid Native Object"); @@ -33156,7 +33958,7 @@ bool js_cocos2dx_LabelAtlas_getString(JSContext *cx, uint32_t argc, jsval *vp) const std::string& ret = cobj->getString(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -33165,25 +33967,25 @@ bool js_cocos2dx_LabelAtlas_getString(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelAtlas_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 5) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } int arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } int arg3; - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); if (!ok) { ok = true; break; } int arg4; - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); if (!ok) { ok = true; break; } cocos2d::LabelAtlas* ret = cocos2d::LabelAtlas::create(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; @@ -33195,7 +33997,7 @@ bool js_cocos2dx_LabelAtlas_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -33212,7 +34014,7 @@ bool js_cocos2dx_LabelAtlas_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -33220,10 +34022,10 @@ bool js_cocos2dx_LabelAtlas_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::LabelAtlas* ret = cocos2d::LabelAtlas::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -33235,7 +34037,7 @@ bool js_cocos2dx_LabelAtlas_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -33244,7 +34046,7 @@ bool js_cocos2dx_LabelAtlas_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelAtlas_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::LabelAtlas* cobj = new (std::nothrow) cocos2d::LabelAtlas(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -33258,13 +34060,16 @@ bool js_cocos2dx_LabelAtlas_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::LabelAtlas"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::LabelAtlas"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -33277,21 +34082,21 @@ void js_cocos2d_LabelAtlas_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_LabelAtlas_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::LabelAtlas *nobj = new (std::nothrow) cocos2d::LabelAtlas(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::LabelAtlas"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::LabelAtlas"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_LabelAtlas(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_LabelAtlas(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_LabelAtlas_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_LabelAtlas_class->name = "LabelAtlas"; jsb_cocos2d_LabelAtlas_class->addProperty = JS_PropertyStub; @@ -33305,14 +34110,13 @@ void js_register_cocos2dx_LabelAtlas(JSContext *cx, JSObject *global) { jsb_cocos2d_LabelAtlas_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("setString", js_cocos2dx_LabelAtlas_setString, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("initWithString", js_cocos2dx_LabelAtlas_initWithString, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("updateAtlasValues", js_cocos2dx_LabelAtlas_updateAtlasValues, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getString", js_cocos2dx_LabelAtlas_getString, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2d_LabelAtlas_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END @@ -33325,7 +34129,7 @@ void js_register_cocos2dx_LabelAtlas(JSContext *cx, JSObject *global) { jsb_cocos2d_LabelAtlas_prototype = JS_InitClass( cx, global, - jsb_cocos2d_AtlasNode_prototype, + JS::RootedObject(cx, jsb_cocos2d_AtlasNode_prototype), jsb_cocos2d_LabelAtlas_class, js_cocos2dx_LabelAtlas_constructor, 0, // constructor properties, @@ -33356,9 +34160,9 @@ JSObject *jsb_cocos2d_LabelTTF_prototype; bool js_cocos2dx_LabelTTF_enableShadow(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_enableShadow : Invalid Native Object"); @@ -33366,12 +34170,12 @@ bool js_cocos2dx_LabelTTF_enableShadow(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Size arg0; double arg1; double arg2; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_enableShadow : Error processing arguments"); cobj->enableShadow(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 4) { @@ -33379,13 +34183,13 @@ bool js_cocos2dx_LabelTTF_enableShadow(JSContext *cx, uint32_t argc, jsval *vp) double arg1; double arg2; bool arg3; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - arg3 = JS::ToBoolean(JS::RootedValue(cx, argv[3])); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + arg3 = JS::ToBoolean(args.get(3)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_enableShadow : Error processing arguments"); cobj->enableShadow(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33394,18 +34198,18 @@ bool js_cocos2dx_LabelTTF_enableShadow(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_setDimensions(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_setDimensions : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_setDimensions : Error processing arguments"); cobj->setDimensions(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33414,7 +34218,8 @@ bool js_cocos2dx_LabelTTF_setDimensions(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_getFontSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_getFontSize : Invalid Native Object"); @@ -33422,7 +34227,7 @@ bool js_cocos2dx_LabelTTF_getFontSize(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getFontSize(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -33431,7 +34236,8 @@ bool js_cocos2dx_LabelTTF_getFontSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_getString(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_getString : Invalid Native Object"); @@ -33439,7 +34245,7 @@ bool js_cocos2dx_LabelTTF_getString(JSContext *cx, uint32_t argc, jsval *vp) const std::string& ret = cobj->getString(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -33448,18 +34254,18 @@ bool js_cocos2dx_LabelTTF_getString(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_setFlippedY(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_setFlippedY : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_setFlippedY : Error processing arguments"); cobj->setFlippedY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33468,18 +34274,18 @@ bool js_cocos2dx_LabelTTF_setFlippedY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_setFlippedX(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_setFlippedX : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_setFlippedX : Error processing arguments"); cobj->setFlippedX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33488,18 +34294,18 @@ bool js_cocos2dx_LabelTTF_setFlippedX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_setTextDefinition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_setTextDefinition : Invalid Native Object"); if (argc == 1) { cocos2d::FontDefinition arg0; - ok &= jsval_to_FontDefinition(cx, argv[0], &arg0); + ok &= jsval_to_FontDefinition(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_setTextDefinition : Error processing arguments"); cobj->setTextDefinition(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33508,18 +34314,18 @@ bool js_cocos2dx_LabelTTF_setTextDefinition(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_LabelTTF_setFontName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_setFontName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_setFontName : Error processing arguments"); cobj->setFontName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33528,7 +34334,8 @@ bool js_cocos2dx_LabelTTF_setFontName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_getHorizontalAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_getHorizontalAlignment : Invalid Native Object"); @@ -33536,7 +34343,7 @@ bool js_cocos2dx_LabelTTF_getHorizontalAlignment(JSContext *cx, uint32_t argc, j int ret = (int)cobj->getHorizontalAlignment(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -33545,22 +34352,22 @@ bool js_cocos2dx_LabelTTF_getHorizontalAlignment(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_LabelTTF_initWithStringAndTextDefinition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_initWithStringAndTextDefinition : Invalid Native Object"); if (argc == 2) { std::string arg0; cocos2d::FontDefinition arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_FontDefinition(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_FontDefinition(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_initWithStringAndTextDefinition : Error processing arguments"); bool ret = cobj->initWithStringAndTextDefinition(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -33569,18 +34376,18 @@ bool js_cocos2dx_LabelTTF_initWithStringAndTextDefinition(JSContext *cx, uint32_ } bool js_cocos2dx_LabelTTF_setString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_setString : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_setString : Error processing arguments"); cobj->setString(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33589,9 +34396,9 @@ bool js_cocos2dx_LabelTTF_setString(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_initWithString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_initWithString : Invalid Native Object"); @@ -33599,14 +34406,14 @@ bool js_cocos2dx_LabelTTF_initWithString(JSContext *cx, uint32_t argc, jsval *vp std::string arg0; std::string arg1; double arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_initWithString : Error processing arguments"); bool ret = cobj->initWithString(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 4) { @@ -33614,15 +34421,15 @@ bool js_cocos2dx_LabelTTF_initWithString(JSContext *cx, uint32_t argc, jsval *vp std::string arg1; double arg2; cocos2d::Size arg3; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= jsval_to_ccsize(cx, argv[3], &arg3); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= jsval_to_ccsize(cx, args.get(3), &arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_initWithString : Error processing arguments"); bool ret = cobj->initWithString(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 5) { @@ -33631,16 +34438,16 @@ bool js_cocos2dx_LabelTTF_initWithString(JSContext *cx, uint32_t argc, jsval *vp double arg2; cocos2d::Size arg3; cocos2d::TextHAlignment arg4; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= jsval_to_ccsize(cx, argv[3], &arg3); - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= jsval_to_ccsize(cx, args.get(3), &arg3); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_initWithString : Error processing arguments"); bool ret = cobj->initWithString(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 6) { @@ -33650,17 +34457,17 @@ bool js_cocos2dx_LabelTTF_initWithString(JSContext *cx, uint32_t argc, jsval *vp cocos2d::Size arg3; cocos2d::TextHAlignment arg4; cocos2d::TextVAlignment arg5; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= jsval_to_ccsize(cx, argv[3], &arg3); - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); - ok &= jsval_to_int32(cx, argv[5], (int32_t *)&arg5); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= jsval_to_ccsize(cx, args.get(3), &arg3); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); + ok &= jsval_to_int32(cx, args.get(5), (int32_t *)&arg5); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_initWithString : Error processing arguments"); bool ret = cobj->initWithString(arg0, arg1, arg2, arg3, arg4, arg5); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -33669,28 +34476,28 @@ bool js_cocos2dx_LabelTTF_initWithString(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_LabelTTF_setFontFillColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_setFontFillColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_setFontFillColor : Error processing arguments"); cobj->setFontFillColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { cocos2d::Color3B arg0; bool arg1; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_setFontFillColor : Error processing arguments"); cobj->setFontFillColor(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33699,7 +34506,8 @@ bool js_cocos2dx_LabelTTF_setFontFillColor(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_LabelTTF_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_getBlendFunc : Invalid Native Object"); @@ -33707,7 +34515,7 @@ bool js_cocos2dx_LabelTTF_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); jsval jsret = JSVAL_NULL; jsret = blendfunc_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -33716,32 +34524,32 @@ bool js_cocos2dx_LabelTTF_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_enableStroke(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_enableStroke : Invalid Native Object"); if (argc == 2) { cocos2d::Color3B arg0; double arg1; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_enableStroke : Error processing arguments"); cobj->enableStroke(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 3) { cocos2d::Color3B arg0; double arg1; bool arg2; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + arg2 = JS::ToBoolean(args.get(2)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_enableStroke : Error processing arguments"); cobj->enableStroke(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33750,7 +34558,8 @@ bool js_cocos2dx_LabelTTF_enableStroke(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_getDimensions(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_getDimensions : Invalid Native Object"); @@ -33758,7 +34567,7 @@ bool js_cocos2dx_LabelTTF_getDimensions(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Size& ret = cobj->getDimensions(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -33767,18 +34576,18 @@ bool js_cocos2dx_LabelTTF_getDimensions(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_setVerticalAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_setVerticalAlignment : Invalid Native Object"); if (argc == 1) { cocos2d::TextVAlignment arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_setVerticalAlignment : Error processing arguments"); cobj->setVerticalAlignment(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33787,18 +34596,18 @@ bool js_cocos2dx_LabelTTF_setVerticalAlignment(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_LabelTTF_setFontSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_setFontSize : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_setFontSize : Error processing arguments"); cobj->setFontSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33807,7 +34616,8 @@ bool js_cocos2dx_LabelTTF_setFontSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_getVerticalAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_getVerticalAlignment : Invalid Native Object"); @@ -33815,7 +34625,7 @@ bool js_cocos2dx_LabelTTF_getVerticalAlignment(JSContext *cx, uint32_t argc, jsv int ret = (int)cobj->getVerticalAlignment(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -33824,7 +34634,8 @@ bool js_cocos2dx_LabelTTF_getVerticalAlignment(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_LabelTTF_getTextDefinition(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_getTextDefinition : Invalid Native Object"); @@ -33832,7 +34643,7 @@ bool js_cocos2dx_LabelTTF_getTextDefinition(JSContext *cx, uint32_t argc, jsval const cocos2d::FontDefinition& ret = cobj->getTextDefinition(); jsval jsret = JSVAL_NULL; jsret = FontDefinition_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -33841,18 +34652,18 @@ bool js_cocos2dx_LabelTTF_getTextDefinition(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_LabelTTF_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_setBlendFunc : Invalid Native Object"); if (argc == 1) { cocos2d::BlendFunc arg0; - ok &= jsval_to_blendfunc(cx, argv[0], &arg0); + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_setBlendFunc : Error processing arguments"); cobj->setBlendFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33861,7 +34672,8 @@ bool js_cocos2dx_LabelTTF_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_getFontName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_getFontName : Invalid Native Object"); @@ -33869,7 +34681,7 @@ bool js_cocos2dx_LabelTTF_getFontName(JSContext *cx, uint32_t argc, jsval *vp) const std::string& ret = cobj->getFontName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -33878,18 +34690,18 @@ bool js_cocos2dx_LabelTTF_getFontName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_setHorizontalAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_setHorizontalAlignment : Invalid Native Object"); if (argc == 1) { cocos2d::TextHAlignment arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_setHorizontalAlignment : Error processing arguments"); cobj->setHorizontalAlignment(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33898,23 +34710,23 @@ bool js_cocos2dx_LabelTTF_setHorizontalAlignment(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_LabelTTF_disableShadow(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_disableShadow : Invalid Native Object"); if (argc == 0) { cobj->disableShadow(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_disableShadow : Error processing arguments"); cobj->disableShadow(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33923,23 +34735,23 @@ bool js_cocos2dx_LabelTTF_disableShadow(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_disableStroke(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelTTF* cobj = (cocos2d::LabelTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelTTF_disableStroke : Invalid Native Object"); if (argc == 0) { cobj->disableStroke(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_disableStroke : Error processing arguments"); cobj->disableStroke(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -33948,7 +34760,7 @@ bool js_cocos2dx_LabelTTF_disableStroke(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { @@ -33963,7 +34775,7 @@ bool js_cocos2dx_LabelTTF_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -33971,13 +34783,13 @@ bool js_cocos2dx_LabelTTF_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::LabelTTF* ret = cocos2d::LabelTTF::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -33989,23 +34801,23 @@ bool js_cocos2dx_LabelTTF_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 4) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::Size arg3; - ok &= jsval_to_ccsize(cx, argv[3], &arg3); + ok &= jsval_to_ccsize(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cocos2d::LabelTTF* ret = cocos2d::LabelTTF::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -34017,26 +34829,26 @@ bool js_cocos2dx_LabelTTF_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 5) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::Size arg3; - ok &= jsval_to_ccsize(cx, argv[3], &arg3); + ok &= jsval_to_ccsize(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cocos2d::TextHAlignment arg4; - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); if (!ok) { ok = true; break; } cocos2d::LabelTTF* ret = cocos2d::LabelTTF::create(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; @@ -34048,29 +34860,29 @@ bool js_cocos2dx_LabelTTF_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 6) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::Size arg3; - ok &= jsval_to_ccsize(cx, argv[3], &arg3); + ok &= jsval_to_ccsize(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cocos2d::TextHAlignment arg4; - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); if (!ok) { ok = true; break; } cocos2d::TextVAlignment arg5; - ok &= jsval_to_int32(cx, argv[5], (int32_t *)&arg5); + ok &= jsval_to_int32(cx, args.get(5), (int32_t *)&arg5); if (!ok) { ok = true; break; } cocos2d::LabelTTF* ret = cocos2d::LabelTTF::create(arg0, arg1, arg2, arg3, arg4, arg5); jsval jsret = JSVAL_NULL; @@ -34082,7 +34894,7 @@ bool js_cocos2dx_LabelTTF_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -34091,13 +34903,13 @@ bool js_cocos2dx_LabelTTF_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelTTF_createWithFontDefinition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { std::string arg0; cocos2d::FontDefinition arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_FontDefinition(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_FontDefinition(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelTTF_createWithFontDefinition : Error processing arguments"); cocos2d::LabelTTF* ret = cocos2d::LabelTTF::createWithFontDefinition(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -34109,7 +34921,7 @@ bool js_cocos2dx_LabelTTF_createWithFontDefinition(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_LabelTTF_createWithFontDefinition : wrong number of arguments"); @@ -34118,7 +34930,7 @@ bool js_cocos2dx_LabelTTF_createWithFontDefinition(JSContext *cx, uint32_t argc, bool js_cocos2dx_LabelTTF_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::LabelTTF* cobj = new (std::nothrow) cocos2d::LabelTTF(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -34132,13 +34944,16 @@ bool js_cocos2dx_LabelTTF_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::LabelTTF"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::LabelTTF"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -34151,21 +34966,21 @@ void js_cocos2d_LabelTTF_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_LabelTTF_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::LabelTTF *nobj = new (std::nothrow) cocos2d::LabelTTF(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::LabelTTF"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::LabelTTF"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_LabelTTF(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_LabelTTF(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_LabelTTF_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_LabelTTF_class->name = "LabelTTF"; jsb_cocos2d_LabelTTF_class->addProperty = JS_PropertyStub; @@ -34179,8 +34994,8 @@ void js_register_cocos2dx_LabelTTF(JSContext *cx, JSObject *global) { jsb_cocos2d_LabelTTF_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -34221,7 +35036,7 @@ void js_register_cocos2dx_LabelTTF(JSContext *cx, JSObject *global) { jsb_cocos2d_LabelTTF_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_LabelTTF_class, js_cocos2dx_LabelTTF_constructor, 0, // constructor properties, @@ -34252,54 +35067,282 @@ JSObject *jsb_cocos2d_SpriteBatchNode_prototype; bool js_cocos2dx_SpriteBatchNode_appendChild(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_appendChild : Invalid Native Object"); if (argc == 1) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_appendChild : Error processing arguments"); cobj->appendChild(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_appendChild : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_SpriteBatchNode_addSpriteWithoutQuad(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_addSpriteWithoutQuad : Invalid Native Object"); + if (argc == 3) { + cocos2d::Sprite* arg0; + int arg1; + int arg2; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_addSpriteWithoutQuad : Error processing arguments"); + cocos2d::SpriteBatchNode* ret = cobj->addSpriteWithoutQuad(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::SpriteBatchNode*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_addSpriteWithoutQuad : wrong number of arguments: %d, was expecting %d", argc, 3); + return false; +} bool js_cocos2dx_SpriteBatchNode_reorderBatch(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_reorderBatch : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_reorderBatch : Error processing arguments"); cobj->reorderBatch(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_reorderBatch : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_SpriteBatchNode_initWithTexture(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_initWithTexture : Invalid Native Object"); + if (argc == 1) { + cocos2d::Texture2D* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_initWithTexture : Error processing arguments"); + bool ret = cobj->initWithTexture(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + if (argc == 2) { + cocos2d::Texture2D* arg0; + ssize_t arg1; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_ssize(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_initWithTexture : Error processing arguments"); + bool ret = cobj->initWithTexture(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_initWithTexture : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_SpriteBatchNode_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_getBlendFunc : Invalid Native Object"); + if (argc == 0) { + const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); + jsval jsret = JSVAL_NULL; + jsret = blendfunc_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_getBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild : Invalid Native Object"); + if (argc == 1) { + cocos2d::Sprite* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild : Error processing arguments"); + ssize_t ret = cobj->lowestAtlasIndexInChild(arg0); + jsval jsret = JSVAL_NULL; + jsret = ssize_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_SpriteBatchNode_atlasIndexForChild(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_atlasIndexForChild : Invalid Native Object"); + if (argc == 2) { + cocos2d::Sprite* arg0; + int arg1; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_atlasIndexForChild : Error processing arguments"); + ssize_t ret = cobj->atlasIndexForChild(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = ssize_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_atlasIndexForChild : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} +bool js_cocos2dx_SpriteBatchNode_setTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_setTextureAtlas : Invalid Native Object"); + if (argc == 1) { + cocos2d::TextureAtlas* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::TextureAtlas*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_setTextureAtlas : Error processing arguments"); + cobj->setTextureAtlas(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_setTextureAtlas : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_SpriteBatchNode_initWithFile(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_initWithFile : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_initWithFile : Error processing arguments"); + bool ret = cobj->initWithFile(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + if (argc == 2) { + std::string arg0; + ssize_t arg1; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_ssize(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_initWithFile : Error processing arguments"); + bool ret = cobj->initWithFile(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_initWithFile : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_SpriteBatchNode_getTexture(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_getTexture : Invalid Native Object"); @@ -34314,460 +35357,246 @@ bool js_cocos2dx_SpriteBatchNode_getTexture(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_getTexture : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_SpriteBatchNode_increaseAtlasCapacity(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_increaseAtlasCapacity : Invalid Native Object"); + if (argc == 0) { + cobj->increaseAtlasCapacity(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_increaseAtlasCapacity : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_SpriteBatchNode_getTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_getTextureAtlas : Invalid Native Object"); + if (argc == 0) { + cocos2d::TextureAtlas* ret = cobj->getTextureAtlas(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::TextureAtlas*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_getTextureAtlas : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_SpriteBatchNode_insertQuadFromSprite(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_insertQuadFromSprite : Invalid Native Object"); + if (argc == 2) { + cocos2d::Sprite* arg0; + ssize_t arg1; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_ssize(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_insertQuadFromSprite : Error processing arguments"); + cobj->insertQuadFromSprite(arg0, arg1); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_insertQuadFromSprite : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} bool js_cocos2dx_SpriteBatchNode_setTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_setTexture : Invalid Native Object"); if (argc == 1) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_setTexture : Error processing arguments"); cobj->setTexture(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_setTexture : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_SpriteBatchNode_removeChildAtIndex(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_removeChildAtIndex : Invalid Native Object"); - if (argc == 2) { - ssize_t arg0; - bool arg1; - ok &= jsval_to_ssize(cx, argv[0], &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_removeChildAtIndex : Error processing arguments"); - cobj->removeChildAtIndex(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_removeChildAtIndex : wrong number of arguments: %d, was expecting %d", argc, 2); - return false; -} -bool js_cocos2dx_SpriteBatchNode_removeSpriteFromAtlas(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_removeSpriteFromAtlas : Invalid Native Object"); - if (argc == 1) { - cocos2d::Sprite* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_removeSpriteFromAtlas : Error processing arguments"); - cobj->removeSpriteFromAtlas(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_removeSpriteFromAtlas : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_SpriteBatchNode_addSpriteWithoutQuad(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_addSpriteWithoutQuad : Invalid Native Object"); - if (argc == 3) { - cocos2d::Sprite* arg0; - int arg1; - int arg2; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_addSpriteWithoutQuad : Error processing arguments"); - cocos2d::SpriteBatchNode* ret = cobj->addSpriteWithoutQuad(arg0, arg1, arg2); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::SpriteBatchNode*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_addSpriteWithoutQuad : wrong number of arguments: %d, was expecting %d", argc, 3); - return false; -} -bool js_cocos2dx_SpriteBatchNode_atlasIndexForChild(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_SpriteBatchNode_rebuildIndexInOrder(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_atlasIndexForChild : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_rebuildIndexInOrder : Invalid Native Object"); if (argc == 2) { cocos2d::Sprite* arg0; - int arg1; + ssize_t arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_atlasIndexForChild : Error processing arguments"); - ssize_t ret = cobj->atlasIndexForChild(arg0, arg1); + ok &= jsval_to_ssize(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_rebuildIndexInOrder : Error processing arguments"); + ssize_t ret = cobj->rebuildIndexInOrder(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_atlasIndexForChild : wrong number of arguments: %d, was expecting %d", argc, 2); - return false; -} -bool js_cocos2dx_SpriteBatchNode_increaseAtlasCapacity(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_increaseAtlasCapacity : Invalid Native Object"); - if (argc == 0) { - cobj->increaseAtlasCapacity(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_increaseAtlasCapacity : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} -bool js_cocos2dx_SpriteBatchNode_init(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_init : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->init(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_init : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_rebuildIndexInOrder : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_SpriteBatchNode_highestAtlasIndexInChild(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_highestAtlasIndexInChild : Invalid Native Object"); if (argc == 1) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild : Error processing arguments"); - ssize_t ret = cobj->lowestAtlasIndexInChild(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_highestAtlasIndexInChild : Error processing arguments"); + ssize_t ret = cobj->highestAtlasIndexInChild(arg0); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_SpriteBatchNode_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_getBlendFunc : Invalid Native Object"); - if (argc == 0) { - const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); - jsval jsret = JSVAL_NULL; - jsret = blendfunc_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_getBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_highestAtlasIndexInChild : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_SpriteBatchNode_initWithTexture(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_SpriteBatchNode_removeChildAtIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_initWithTexture : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_removeChildAtIndex : Invalid Native Object"); if (argc == 2) { - cocos2d::Texture2D* arg0; - ssize_t arg1; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - ok &= jsval_to_ssize(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_initWithTexture : Error processing arguments"); - bool ret = cobj->initWithTexture(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + ssize_t arg0; + bool arg1; + ok &= jsval_to_ssize(cx, args.get(0), &arg0); + arg1 = JS::ToBoolean(args.get(1)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_removeChildAtIndex : Error processing arguments"); + cobj->removeChildAtIndex(arg0, arg1); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_initWithTexture : wrong number of arguments: %d, was expecting %d", argc, 2); + JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_removeChildAtIndex : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_SpriteBatchNode_setTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_SpriteBatchNode_removeSpriteFromAtlas(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_setTextureAtlas : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_removeSpriteFromAtlas : Invalid Native Object"); if (argc == 1) { - cocos2d::TextureAtlas* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::TextureAtlas*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_setTextureAtlas : Error processing arguments"); - cobj->setTextureAtlas(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_setTextureAtlas : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_SpriteBatchNode_insertQuadFromSprite(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_insertQuadFromSprite : Invalid Native Object"); - if (argc == 2) { cocos2d::Sprite* arg0; - ssize_t arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_ssize(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_insertQuadFromSprite : Error processing arguments"); - cobj->insertQuadFromSprite(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_insertQuadFromSprite : wrong number of arguments: %d, was expecting %d", argc, 2); - return false; -} -bool js_cocos2dx_SpriteBatchNode_initWithFile(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_initWithFile : Invalid Native Object"); - if (argc == 2) { - std::string arg0; - ssize_t arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_ssize(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_initWithFile : Error processing arguments"); - bool ret = cobj->initWithFile(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_removeSpriteFromAtlas : Error processing arguments"); + cobj->removeSpriteFromAtlas(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_initWithFile : wrong number of arguments: %d, was expecting %d", argc, 2); + JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_removeSpriteFromAtlas : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_SpriteBatchNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_setBlendFunc : Invalid Native Object"); if (argc == 1) { cocos2d::BlendFunc arg0; - ok &= jsval_to_blendfunc(cx, argv[0], &arg0); + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_setBlendFunc : Error processing arguments"); cobj->setBlendFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_setBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_SpriteBatchNode_rebuildIndexInOrder(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_rebuildIndexInOrder : Invalid Native Object"); - if (argc == 2) { - cocos2d::Sprite* arg0; - ssize_t arg1; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - ok &= jsval_to_ssize(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_rebuildIndexInOrder : Error processing arguments"); - ssize_t ret = cobj->rebuildIndexInOrder(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_rebuildIndexInOrder : wrong number of arguments: %d, was expecting %d", argc, 2); - return false; -} -bool js_cocos2dx_SpriteBatchNode_getTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_getTextureAtlas : Invalid Native Object"); - if (argc == 0) { - cocos2d::TextureAtlas* ret = cobj->getTextureAtlas(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::TextureAtlas*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_getTextureAtlas : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} -bool js_cocos2dx_SpriteBatchNode_highestAtlasIndexInChild(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_highestAtlasIndexInChild : Invalid Native Object"); - if (argc == 1) { - cocos2d::Sprite* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_highestAtlasIndexInChild : Error processing arguments"); - ssize_t ret = cobj->highestAtlasIndexInChild(arg0); - jsval jsret = JSVAL_NULL; - jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_highestAtlasIndexInChild : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_SpriteBatchNode_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_create : Error processing arguments"); cocos2d::SpriteBatchNode* ret = cocos2d::SpriteBatchNode::create(arg0); jsval jsret = JSVAL_NULL; @@ -34779,14 +35608,14 @@ bool js_cocos2dx_SpriteBatchNode_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { std::string arg0; ssize_t arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_ssize(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_ssize(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_create : Error processing arguments"); cocos2d::SpriteBatchNode* ret = cocos2d::SpriteBatchNode::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -34798,7 +35627,7 @@ bool js_cocos2dx_SpriteBatchNode_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_create : wrong number of arguments"); @@ -34807,14 +35636,14 @@ bool js_cocos2dx_SpriteBatchNode_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_SpriteBatchNode_createWithTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -34830,21 +35659,21 @@ bool js_cocos2dx_SpriteBatchNode_createWithTexture(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { cocos2d::Texture2D* arg0; ssize_t arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_ssize(cx, argv[1], &arg1); + ok &= jsval_to_ssize(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteBatchNode_createWithTexture : Error processing arguments"); cocos2d::SpriteBatchNode* ret = cocos2d::SpriteBatchNode::createWithTexture(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -34856,7 +35685,7 @@ bool js_cocos2dx_SpriteBatchNode_createWithTexture(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_SpriteBatchNode_createWithTexture : wrong number of arguments"); @@ -34865,7 +35694,7 @@ bool js_cocos2dx_SpriteBatchNode_createWithTexture(JSContext *cx, uint32_t argc, bool js_cocos2dx_SpriteBatchNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::SpriteBatchNode* cobj = new (std::nothrow) cocos2d::SpriteBatchNode(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -34879,13 +35708,16 @@ bool js_cocos2dx_SpriteBatchNode_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::SpriteBatchNode"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::SpriteBatchNode"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -34898,21 +35730,21 @@ void js_cocos2d_SpriteBatchNode_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_SpriteBatchNode_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::SpriteBatchNode *nobj = new (std::nothrow) cocos2d::SpriteBatchNode(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::SpriteBatchNode"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::SpriteBatchNode"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_SpriteBatchNode(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_SpriteBatchNode(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_SpriteBatchNode_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_SpriteBatchNode_class->name = "SpriteBatchNode"; jsb_cocos2d_SpriteBatchNode_class->addProperty = JS_PropertyStub; @@ -34926,31 +35758,30 @@ void js_register_cocos2dx_SpriteBatchNode(JSContext *cx, JSObject *global) { jsb_cocos2d_SpriteBatchNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("appendChild", js_cocos2dx_SpriteBatchNode_appendChild, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("reorderBatch", js_cocos2dx_SpriteBatchNode_reorderBatch, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getTexture", js_cocos2dx_SpriteBatchNode_getTexture, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setTexture", js_cocos2dx_SpriteBatchNode_setTexture, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("removeChildAtIndex", js_cocos2dx_SpriteBatchNode_removeChildAtIndex, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("removeSpriteFromAtlas", js_cocos2dx_SpriteBatchNode_removeSpriteFromAtlas, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("addSpriteWithoutQuad", js_cocos2dx_SpriteBatchNode_addSpriteWithoutQuad, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("atlasIndexForChild", js_cocos2dx_SpriteBatchNode_atlasIndexForChild, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("increaseAtlasCapacity", js_cocos2dx_SpriteBatchNode_increaseAtlasCapacity, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_SpriteBatchNode_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("lowestAtlasIndexInChild", js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("reorderBatch", js_cocos2dx_SpriteBatchNode_reorderBatch, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithTexture", js_cocos2dx_SpriteBatchNode_initWithTexture, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getBlendFunc", js_cocos2dx_SpriteBatchNode_getBlendFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("initWithTexture", js_cocos2dx_SpriteBatchNode_initWithTexture, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("lowestAtlasIndexInChild", js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("atlasIndexForChild", js_cocos2dx_SpriteBatchNode_atlasIndexForChild, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setTextureAtlas", js_cocos2dx_SpriteBatchNode_setTextureAtlas, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithFile", js_cocos2dx_SpriteBatchNode_initWithFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getTexture", js_cocos2dx_SpriteBatchNode_getTexture, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("increaseAtlasCapacity", js_cocos2dx_SpriteBatchNode_increaseAtlasCapacity, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getTextureAtlas", js_cocos2dx_SpriteBatchNode_getTextureAtlas, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("insertQuadFromSprite", js_cocos2dx_SpriteBatchNode_insertQuadFromSprite, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("initWithFile", js_cocos2dx_SpriteBatchNode_initWithFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setBlendFunc", js_cocos2dx_SpriteBatchNode_setBlendFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setTexture", js_cocos2dx_SpriteBatchNode_setTexture, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("rebuildIndexInOrder", js_cocos2dx_SpriteBatchNode_rebuildIndexInOrder, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getTextureAtlas", js_cocos2dx_SpriteBatchNode_getTextureAtlas, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("highestAtlasIndexInChild", js_cocos2dx_SpriteBatchNode_highestAtlasIndexInChild, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("removeChildAtIndex", js_cocos2dx_SpriteBatchNode_removeChildAtIndex, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("removeSpriteFromAtlas", js_cocos2dx_SpriteBatchNode_removeSpriteFromAtlas, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setBlendFunc", js_cocos2dx_SpriteBatchNode_setBlendFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2d_SpriteBatchNode_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -34963,7 +35794,7 @@ void js_register_cocos2dx_SpriteBatchNode(JSContext *cx, JSObject *global) { jsb_cocos2d_SpriteBatchNode_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_SpriteBatchNode_class, js_cocos2dx_SpriteBatchNode_constructor, 0, // constructor properties, @@ -34994,7 +35825,8 @@ JSObject *jsb_cocos2d_Label_prototype; bool js_cocos2dx_Label_isClipMarginEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_isClipMarginEnabled : Invalid Native Object"); @@ -35002,7 +35834,7 @@ bool js_cocos2dx_Label_isClipMarginEnabled(JSContext *cx, uint32_t argc, jsval * bool ret = cobj->isClipMarginEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35011,45 +35843,45 @@ bool js_cocos2dx_Label_isClipMarginEnabled(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Label_enableShadow(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_enableShadow : Invalid Native Object"); if (argc == 0) { cobj->enableShadow(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 1) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_enableShadow : Error processing arguments"); cobj->enableShadow(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { cocos2d::Color4B arg0; cocos2d::Size arg1; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_enableShadow : Error processing arguments"); cobj->enableShadow(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 3) { cocos2d::Color4B arg0; cocos2d::Size arg1; int arg2; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_enableShadow : Error processing arguments"); cobj->enableShadow(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35058,20 +35890,20 @@ bool js_cocos2dx_Label_enableShadow(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_setDimensions(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setDimensions : Invalid Native Object"); if (argc == 2) { - unsigned int arg0; - unsigned int arg1; - ok &= jsval_to_uint32(cx, argv[0], &arg0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); + double arg0; + double arg1; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setDimensions : Error processing arguments"); cobj->setDimensions(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35080,7 +35912,8 @@ bool js_cocos2dx_Label_setDimensions(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_getString(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getString : Invalid Native Object"); @@ -35088,7 +35921,7 @@ bool js_cocos2dx_Label_getString(JSContext *cx, uint32_t argc, jsval *vp) const std::string& ret = cobj->getString(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35097,15 +35930,16 @@ bool js_cocos2dx_Label_getString(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_getHeight(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getHeight : Invalid Native Object"); if (argc == 0) { - unsigned int ret = cobj->getHeight(); + double ret = cobj->getHeight(); jsval jsret = JSVAL_NULL; - jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); return true; } @@ -35114,13 +35948,14 @@ bool js_cocos2dx_Label_getHeight(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_disableEffect(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_disableEffect : Invalid Native Object"); if (argc == 0) { cobj->disableEffect(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35129,7 +35964,8 @@ bool js_cocos2dx_Label_disableEffect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_getTextColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getTextColor : Invalid Native Object"); @@ -35137,7 +35973,7 @@ bool js_cocos2dx_Label_getTextColor(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Color4B& ret = cobj->getTextColor(); jsval jsret = JSVAL_NULL; jsret = cccolor4b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35146,18 +35982,18 @@ bool js_cocos2dx_Label_getTextColor(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_setWidth(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setWidth : Invalid Native Object"); if (argc == 1) { - unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setWidth : Error processing arguments"); cobj->setWidth(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35166,15 +36002,16 @@ bool js_cocos2dx_Label_setWidth(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_getMaxLineWidth(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getMaxLineWidth : Invalid Native Object"); if (argc == 0) { - unsigned int ret = cobj->getMaxLineWidth(); + double ret = cobj->getMaxLineWidth(); jsval jsret = JSVAL_NULL; - jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); return true; } @@ -35183,7 +36020,8 @@ bool js_cocos2dx_Label_getMaxLineWidth(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_getHorizontalAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getHorizontalAlignment : Invalid Native Object"); @@ -35191,7 +36029,7 @@ bool js_cocos2dx_Label_getHorizontalAlignment(JSContext *cx, uint32_t argc, jsva int ret = (int)cobj->getHorizontalAlignment(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35200,18 +36038,18 @@ bool js_cocos2dx_Label_getHorizontalAlignment(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_Label_setClipMarginEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setClipMarginEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setClipMarginEnabled : Error processing arguments"); cobj->setClipMarginEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35220,18 +36058,18 @@ bool js_cocos2dx_Label_setClipMarginEnabled(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Label_setString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setString : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setString : Error processing arguments"); cobj->setString(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35240,18 +36078,18 @@ bool js_cocos2dx_Label_setString(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_setSystemFontName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setSystemFontName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setSystemFontName : Error processing arguments"); cobj->setSystemFontName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35260,32 +36098,32 @@ bool js_cocos2dx_Label_setSystemFontName(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Label_setBMFontFilePath(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setBMFontFilePath : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setBMFontFilePath : Error processing arguments"); bool ret = cobj->setBMFontFilePath(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { std::string arg0; cocos2d::Vec2 arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setBMFontFilePath : Error processing arguments"); bool ret = cobj->setBMFontFilePath(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35294,18 +36132,18 @@ bool js_cocos2dx_Label_setBMFontFilePath(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Label_setLineHeight(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setLineHeight : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setLineHeight : Error processing arguments"); cobj->setLineHeight(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35314,18 +36152,18 @@ bool js_cocos2dx_Label_setLineHeight(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_setSystemFontSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setSystemFontSize : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setSystemFontSize : Error processing arguments"); cobj->setSystemFontSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35334,13 +36172,14 @@ bool js_cocos2dx_Label_setSystemFontSize(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Label_updateContent(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_updateContent : Invalid Native Object"); if (argc == 0) { cobj->updateContent(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35349,7 +36188,8 @@ bool js_cocos2dx_Label_updateContent(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_getStringLength(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getStringLength : Invalid Native Object"); @@ -35357,7 +36197,7 @@ bool js_cocos2dx_Label_getStringLength(JSContext *cx, uint32_t argc, jsval *vp) int ret = cobj->getStringLength(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35366,18 +36206,18 @@ bool js_cocos2dx_Label_getStringLength(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_setLineBreakWithoutSpace(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setLineBreakWithoutSpace : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setLineBreakWithoutSpace : Error processing arguments"); cobj->setLineBreakWithoutSpace(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35386,7 +36226,8 @@ bool js_cocos2dx_Label_setLineBreakWithoutSpace(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_Label_getStringNumLines(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getStringNumLines : Invalid Native Object"); @@ -35394,7 +36235,7 @@ bool js_cocos2dx_Label_getStringNumLines(JSContext *cx, uint32_t argc, jsval *vp int ret = cobj->getStringNumLines(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35403,28 +36244,28 @@ bool js_cocos2dx_Label_getStringNumLines(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Label_enableOutline(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_enableOutline : Invalid Native Object"); if (argc == 1) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_enableOutline : Error processing arguments"); cobj->enableOutline(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { cocos2d::Color4B arg0; int arg1; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_enableOutline : Error processing arguments"); cobj->enableOutline(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35433,7 +36274,8 @@ bool js_cocos2dx_Label_enableOutline(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_getAdditionalKerning(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getAdditionalKerning : Invalid Native Object"); @@ -35441,7 +36283,7 @@ bool js_cocos2dx_Label_getAdditionalKerning(JSContext *cx, uint32_t argc, jsval double ret = cobj->getAdditionalKerning(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35450,12 +36292,12 @@ bool js_cocos2dx_Label_getAdditionalKerning(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Label_setCharMap(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Label* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setCharMap : Invalid Native Object"); @@ -35463,27 +36305,27 @@ bool js_cocos2dx_Label_setCharMap(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 4) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } int arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } int arg3; - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); if (!ok) { ok = true; break; } bool ret = cobj->setCharMap(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -35491,21 +36333,21 @@ bool js_cocos2dx_Label_setCharMap(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 4) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } int arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } int arg3; - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); if (!ok) { ok = true; break; } bool ret = cobj->setCharMap(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -35513,12 +36355,12 @@ bool js_cocos2dx_Label_setCharMap(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } bool ret = cobj->setCharMap(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -35528,7 +36370,8 @@ bool js_cocos2dx_Label_setCharMap(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_getDimensions(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getDimensions : Invalid Native Object"); @@ -35536,7 +36379,7 @@ bool js_cocos2dx_Label_getDimensions(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Size& ret = cobj->getDimensions(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35545,18 +36388,18 @@ bool js_cocos2dx_Label_getDimensions(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_setMaxLineWidth(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setMaxLineWidth : Invalid Native Object"); if (argc == 1) { - unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setMaxLineWidth : Error processing arguments"); cobj->setMaxLineWidth(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35565,7 +36408,8 @@ bool js_cocos2dx_Label_setMaxLineWidth(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_getSystemFontName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getSystemFontName : Invalid Native Object"); @@ -35573,7 +36417,7 @@ bool js_cocos2dx_Label_getSystemFontName(JSContext *cx, uint32_t argc, jsval *vp const std::string& ret = cobj->getSystemFontName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35582,18 +36426,18 @@ bool js_cocos2dx_Label_getSystemFontName(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Label_setVerticalAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setVerticalAlignment : Invalid Native Object"); if (argc == 1) { cocos2d::TextVAlignment arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setVerticalAlignment : Error processing arguments"); cobj->setVerticalAlignment(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35602,7 +36446,8 @@ bool js_cocos2dx_Label_setVerticalAlignment(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Label_getLineHeight(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getLineHeight : Invalid Native Object"); @@ -35610,7 +36455,7 @@ bool js_cocos2dx_Label_getLineHeight(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getLineHeight(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35619,7 +36464,8 @@ bool js_cocos2dx_Label_getLineHeight(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_getTTFConfig(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getTTFConfig : Invalid Native Object"); @@ -35627,7 +36473,7 @@ bool js_cocos2dx_Label_getTTFConfig(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::_ttfConfig& ret = cobj->getTTFConfig(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR _ttfConfig; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35636,7 +36482,8 @@ bool js_cocos2dx_Label_getTTFConfig(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_getVerticalAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getVerticalAlignment : Invalid Native Object"); @@ -35644,7 +36491,7 @@ bool js_cocos2dx_Label_getVerticalAlignment(JSContext *cx, uint32_t argc, jsval int ret = (int)cobj->getVerticalAlignment(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35653,18 +36500,18 @@ bool js_cocos2dx_Label_getVerticalAlignment(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Label_setTextColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setTextColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setTextColor : Error processing arguments"); cobj->setTextColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35673,18 +36520,18 @@ bool js_cocos2dx_Label_setTextColor(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_setHeight(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setHeight : Invalid Native Object"); if (argc == 1) { - unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setHeight : Error processing arguments"); cobj->setHeight(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35693,15 +36540,16 @@ bool js_cocos2dx_Label_setHeight(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_getWidth(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getWidth : Invalid Native Object"); if (argc == 0) { - unsigned int ret = cobj->getWidth(); + double ret = cobj->getWidth(); jsval jsret = JSVAL_NULL; - jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); return true; } @@ -35710,18 +36558,18 @@ bool js_cocos2dx_Label_getWidth(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_enableGlow(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_enableGlow : Invalid Native Object"); if (argc == 1) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_enableGlow : Error processing arguments"); cobj->enableGlow(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35730,15 +36578,15 @@ bool js_cocos2dx_Label_enableGlow(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_getLetter(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getLetter : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_getLetter : Error processing arguments"); cocos2d::Sprite* ret = cobj->getLetter(arg0); jsval jsret = JSVAL_NULL; @@ -35750,7 +36598,7 @@ bool js_cocos2dx_Label_getLetter(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35759,18 +36607,18 @@ bool js_cocos2dx_Label_getLetter(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_setAdditionalKerning(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setAdditionalKerning : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setAdditionalKerning : Error processing arguments"); cobj->setAdditionalKerning(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35779,7 +36627,8 @@ bool js_cocos2dx_Label_setAdditionalKerning(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Label_getSystemFontSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getSystemFontSize : Invalid Native Object"); @@ -35787,7 +36636,7 @@ bool js_cocos2dx_Label_getSystemFontSize(JSContext *cx, uint32_t argc, jsval *vp double ret = cobj->getSystemFontSize(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35796,7 +36645,8 @@ bool js_cocos2dx_Label_getSystemFontSize(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Label_getTextAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getTextAlignment : Invalid Native Object"); @@ -35804,7 +36654,7 @@ bool js_cocos2dx_Label_getTextAlignment(JSContext *cx, uint32_t argc, jsval *vp) int ret = (int)cobj->getTextAlignment(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35813,7 +36663,8 @@ bool js_cocos2dx_Label_getTextAlignment(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_getBMFontFilePath(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_getBMFontFilePath : Invalid Native Object"); @@ -35821,7 +36672,7 @@ bool js_cocos2dx_Label_getBMFontFilePath(JSContext *cx, uint32_t argc, jsval *vp const std::string& ret = cobj->getBMFontFilePath(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35830,18 +36681,18 @@ bool js_cocos2dx_Label_getBMFontFilePath(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Label_setHorizontalAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setHorizontalAlignment : Invalid Native Object"); if (argc == 1) { cocos2d::TextHAlignment arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setHorizontalAlignment : Error processing arguments"); cobj->setHorizontalAlignment(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35850,25 +36701,25 @@ bool js_cocos2dx_Label_setHorizontalAlignment(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_Label_setAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Label* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_setAlignment : Invalid Native Object"); do { if (argc == 2) { cocos2d::TextHAlignment arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } cocos2d::TextVAlignment arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cobj->setAlignment(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -35876,10 +36727,10 @@ bool js_cocos2dx_Label_setAlignment(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 1) { cocos2d::TextHAlignment arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } cobj->setAlignment(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -35889,13 +36740,14 @@ bool js_cocos2dx_Label_setAlignment(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Label_requestSystemFontRefresh(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Label* cobj = (cocos2d::Label *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Label_requestSystemFontRefresh : Invalid Native Object"); if (argc == 0) { cobj->requestSystemFontRefresh(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35904,13 +36756,13 @@ bool js_cocos2dx_Label_requestSystemFontRefresh(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_Label_createWithBMFont(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_createWithBMFont : Error processing arguments"); cocos2d::Label* ret = cocos2d::Label::createWithBMFont(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -35922,16 +36774,16 @@ bool js_cocos2dx_Label_createWithBMFont(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 3) { std::string arg0; std::string arg1; cocos2d::TextHAlignment arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_createWithBMFont : Error processing arguments"); cocos2d::Label* ret = cocos2d::Label::createWithBMFont(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -35943,7 +36795,7 @@ bool js_cocos2dx_Label_createWithBMFont(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 4) { @@ -35951,10 +36803,10 @@ bool js_cocos2dx_Label_createWithBMFont(JSContext *cx, uint32_t argc, jsval *vp) std::string arg1; cocos2d::TextHAlignment arg2; int arg3; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_createWithBMFont : Error processing arguments"); cocos2d::Label* ret = cocos2d::Label::createWithBMFont(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -35966,7 +36818,7 @@ bool js_cocos2dx_Label_createWithBMFont(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 5) { @@ -35975,11 +36827,11 @@ bool js_cocos2dx_Label_createWithBMFont(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::TextHAlignment arg2; int arg3; cocos2d::Vec2 arg4; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); - ok &= jsval_to_vector2(cx, argv[4], &arg4); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); + ok &= jsval_to_vector2(cx, args.get(4), &arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_createWithBMFont : Error processing arguments"); cocos2d::Label* ret = cocos2d::Label::createWithBMFont(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; @@ -35991,7 +36843,7 @@ bool js_cocos2dx_Label_createWithBMFont(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Label_createWithBMFont : wrong number of arguments"); @@ -36000,6 +36852,7 @@ bool js_cocos2dx_Label_createWithBMFont(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Label_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Label* ret = cocos2d::Label::create(); jsval jsret = JSVAL_NULL; @@ -36011,7 +36864,7 @@ bool js_cocos2dx_Label_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Label_create : wrong number of arguments"); @@ -36020,29 +36873,29 @@ bool js_cocos2dx_Label_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Label_createWithCharMap(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 4) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } int arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } int arg3; - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); if (!ok) { ok = true; break; } cocos2d::Label* ret = cocos2d::Label::createWithCharMap(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -36054,7 +36907,7 @@ bool js_cocos2dx_Label_createWithCharMap(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -36062,16 +36915,16 @@ bool js_cocos2dx_Label_createWithCharMap(JSContext *cx, uint32_t argc, jsval *vp do { if (argc == 4) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } int arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } int arg3; - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); if (!ok) { ok = true; break; } cocos2d::Label* ret = cocos2d::Label::createWithCharMap(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -36083,7 +36936,7 @@ bool js_cocos2dx_Label_createWithCharMap(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -36091,7 +36944,7 @@ bool js_cocos2dx_Label_createWithCharMap(JSContext *cx, uint32_t argc, jsval *vp do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Label* ret = cocos2d::Label::createWithCharMap(arg0); jsval jsret = JSVAL_NULL; @@ -36103,7 +36956,7 @@ bool js_cocos2dx_Label_createWithCharMap(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -36112,15 +36965,15 @@ bool js_cocos2dx_Label_createWithCharMap(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Label_createWithSystemFont(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 3) { std::string arg0; std::string arg1; double arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_createWithSystemFont : Error processing arguments"); cocos2d::Label* ret = cocos2d::Label::createWithSystemFont(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -36132,7 +36985,7 @@ bool js_cocos2dx_Label_createWithSystemFont(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 4) { @@ -36140,10 +36993,10 @@ bool js_cocos2dx_Label_createWithSystemFont(JSContext *cx, uint32_t argc, jsval std::string arg1; double arg2; cocos2d::Size arg3; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= jsval_to_ccsize(cx, argv[3], &arg3); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= jsval_to_ccsize(cx, args.get(3), &arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_createWithSystemFont : Error processing arguments"); cocos2d::Label* ret = cocos2d::Label::createWithSystemFont(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -36155,7 +37008,7 @@ bool js_cocos2dx_Label_createWithSystemFont(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 5) { @@ -36164,11 +37017,11 @@ bool js_cocos2dx_Label_createWithSystemFont(JSContext *cx, uint32_t argc, jsval double arg2; cocos2d::Size arg3; cocos2d::TextHAlignment arg4; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= jsval_to_ccsize(cx, argv[3], &arg3); - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= jsval_to_ccsize(cx, args.get(3), &arg3); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_createWithSystemFont : Error processing arguments"); cocos2d::Label* ret = cocos2d::Label::createWithSystemFont(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; @@ -36180,7 +37033,7 @@ bool js_cocos2dx_Label_createWithSystemFont(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 6) { @@ -36190,12 +37043,12 @@ bool js_cocos2dx_Label_createWithSystemFont(JSContext *cx, uint32_t argc, jsval cocos2d::Size arg3; cocos2d::TextHAlignment arg4; cocos2d::TextVAlignment arg5; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= jsval_to_ccsize(cx, argv[3], &arg3); - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); - ok &= jsval_to_int32(cx, argv[5], (int32_t *)&arg5); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= jsval_to_ccsize(cx, args.get(3), &arg3); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); + ok &= jsval_to_int32(cx, args.get(5), (int32_t *)&arg5); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_createWithSystemFont : Error processing arguments"); cocos2d::Label* ret = cocos2d::Label::createWithSystemFont(arg0, arg1, arg2, arg3, arg4, arg5); jsval jsret = JSVAL_NULL; @@ -36207,7 +37060,7 @@ bool js_cocos2dx_Label_createWithSystemFont(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Label_createWithSystemFont : wrong number of arguments"); @@ -36216,7 +37069,7 @@ bool js_cocos2dx_Label_createWithSystemFont(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_Label_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Label* cobj = new (std::nothrow) cocos2d::Label(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -36230,13 +37083,16 @@ bool js_cocos2dx_Label_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Label"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Label"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -36249,21 +37105,21 @@ void js_cocos2d_Label_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_Label_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::Label *nobj = new (std::nothrow) cocos2d::Label(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Label"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Label"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_Label(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Label(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Label_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Label_class->name = "Label"; jsb_cocos2d_Label_class->addProperty = JS_PropertyStub; @@ -36277,8 +37133,8 @@ void js_register_cocos2dx_Label(JSContext *cx, JSObject *global) { jsb_cocos2d_Label_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -36338,7 +37194,7 @@ void js_register_cocos2dx_Label(JSContext *cx, JSObject *global) { jsb_cocos2d_Label_prototype = JS_InitClass( cx, global, - jsb_cocos2d_SpriteBatchNode_prototype, + JS::RootedObject(cx, jsb_cocos2d_SpriteBatchNode_prototype), jsb_cocos2d_Label_class, js_cocos2dx_Label_constructor, 0, // constructor properties, @@ -36369,18 +37225,18 @@ JSObject *jsb_cocos2d_LabelBMFont_prototype; bool js_cocos2dx_LabelBMFont_setLineBreakWithoutSpace(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelBMFont* cobj = (cocos2d::LabelBMFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelBMFont_setLineBreakWithoutSpace : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelBMFont_setLineBreakWithoutSpace : Error processing arguments"); cobj->setLineBreakWithoutSpace(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -36389,7 +37245,8 @@ bool js_cocos2dx_LabelBMFont_setLineBreakWithoutSpace(JSContext *cx, uint32_t ar } bool js_cocos2dx_LabelBMFont_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelBMFont* cobj = (cocos2d::LabelBMFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelBMFont_getBlendFunc : Invalid Native Object"); @@ -36397,41 +37254,24 @@ bool js_cocos2dx_LabelBMFont_getBlendFunc(JSContext *cx, uint32_t argc, jsval *v const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); jsval jsret = JSVAL_NULL; jsret = blendfunc_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_LabelBMFont_getBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_LabelBMFont_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::LabelBMFont* cobj = (cocos2d::LabelBMFont *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelBMFont_isOpacityModifyRGB : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->isOpacityModifyRGB(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_LabelBMFont_isOpacityModifyRGB : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_LabelBMFont_getLetter(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelBMFont* cobj = (cocos2d::LabelBMFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelBMFont_getLetter : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelBMFont_getLetter : Error processing arguments"); cocos2d::Sprite* ret = cobj->getLetter(arg0); jsval jsret = JSVAL_NULL; @@ -36443,7 +37283,7 @@ bool js_cocos2dx_LabelBMFont_getLetter(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -36452,7 +37292,8 @@ bool js_cocos2dx_LabelBMFont_getLetter(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelBMFont_getString(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelBMFont* cobj = (cocos2d::LabelBMFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelBMFont_getString : Invalid Native Object"); @@ -36460,7 +37301,7 @@ bool js_cocos2dx_LabelBMFont_getString(JSContext *cx, uint32_t argc, jsval *vp) const std::string& ret = cobj->getString(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -36469,18 +37310,18 @@ bool js_cocos2dx_LabelBMFont_getString(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelBMFont_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelBMFont* cobj = (cocos2d::LabelBMFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelBMFont_setBlendFunc : Invalid Native Object"); if (argc == 1) { cocos2d::BlendFunc arg0; - ok &= jsval_to_blendfunc(cx, argv[0], &arg0); + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelBMFont_setBlendFunc : Error processing arguments"); cobj->setBlendFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -36489,18 +37330,18 @@ bool js_cocos2dx_LabelBMFont_setBlendFunc(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_LabelBMFont_setString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelBMFont* cobj = (cocos2d::LabelBMFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelBMFont_setString : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelBMFont_setString : Error processing arguments"); cobj->setString(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -36509,36 +37350,36 @@ bool js_cocos2dx_LabelBMFont_setString(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelBMFont_initWithString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelBMFont* cobj = (cocos2d::LabelBMFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelBMFont_initWithString : Invalid Native Object"); if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelBMFont_initWithString : Error processing arguments"); bool ret = cobj->initWithString(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 3) { std::string arg0; std::string arg1; double arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelBMFont_initWithString : Error processing arguments"); bool ret = cobj->initWithString(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 4) { @@ -36546,15 +37387,15 @@ bool js_cocos2dx_LabelBMFont_initWithString(JSContext *cx, uint32_t argc, jsval std::string arg1; double arg2; cocos2d::TextHAlignment arg3; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelBMFont_initWithString : Error processing arguments"); bool ret = cobj->initWithString(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 5) { @@ -36563,45 +37404,26 @@ bool js_cocos2dx_LabelBMFont_initWithString(JSContext *cx, uint32_t argc, jsval double arg2; cocos2d::TextHAlignment arg3; cocos2d::Vec2 arg4; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); - ok &= jsval_to_vector2(cx, argv[4], &arg4); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); + ok &= jsval_to_vector2(cx, args.get(4), &arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelBMFont_initWithString : Error processing arguments"); bool ret = cobj->initWithString(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_LabelBMFont_initWithString : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_LabelBMFont_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::LabelBMFont* cobj = (cocos2d::LabelBMFont *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelBMFont_setOpacityModifyRGB : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelBMFont_setOpacityModifyRGB : Error processing arguments"); - cobj->setOpacityModifyRGB(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_LabelBMFont_setOpacityModifyRGB : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_LabelBMFont_getFntFile(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelBMFont* cobj = (cocos2d::LabelBMFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelBMFont_getFntFile : Invalid Native Object"); @@ -36609,7 +37431,7 @@ bool js_cocos2dx_LabelBMFont_getFntFile(JSContext *cx, uint32_t argc, jsval *vp) const std::string& ret = cobj->getFntFile(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -36618,28 +37440,28 @@ bool js_cocos2dx_LabelBMFont_getFntFile(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelBMFont_setFntFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelBMFont* cobj = (cocos2d::LabelBMFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelBMFont_setFntFile : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelBMFont_setFntFile : Error processing arguments"); cobj->setFntFile(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::Vec2 arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelBMFont_setFntFile : Error processing arguments"); cobj->setFntFile(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -36648,18 +37470,18 @@ bool js_cocos2dx_LabelBMFont_setFntFile(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelBMFont_setAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelBMFont* cobj = (cocos2d::LabelBMFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelBMFont_setAlignment : Invalid Native Object"); if (argc == 1) { cocos2d::TextHAlignment arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelBMFont_setAlignment : Error processing arguments"); cobj->setAlignment(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -36668,18 +37490,18 @@ bool js_cocos2dx_LabelBMFont_setAlignment(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_LabelBMFont_setWidth(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LabelBMFont* cobj = (cocos2d::LabelBMFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelBMFont_setWidth : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelBMFont_setWidth : Error processing arguments"); cobj->setWidth(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -36688,7 +37510,7 @@ bool js_cocos2dx_LabelBMFont_setWidth(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelBMFont_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { @@ -36703,7 +37525,7 @@ bool js_cocos2dx_LabelBMFont_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -36711,10 +37533,10 @@ bool js_cocos2dx_LabelBMFont_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::LabelBMFont* ret = cocos2d::LabelBMFont::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -36726,20 +37548,20 @@ bool js_cocos2dx_LabelBMFont_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::LabelBMFont* ret = cocos2d::LabelBMFont::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -36751,23 +37573,23 @@ bool js_cocos2dx_LabelBMFont_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 4) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::TextHAlignment arg3; - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); if (!ok) { ok = true; break; } cocos2d::LabelBMFont* ret = cocos2d::LabelBMFont::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -36779,26 +37601,26 @@ bool js_cocos2dx_LabelBMFont_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 5) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::TextHAlignment arg3; - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); if (!ok) { ok = true; break; } cocos2d::Vec2 arg4; - ok &= jsval_to_vector2(cx, argv[4], &arg4); + ok &= jsval_to_vector2(cx, args.get(4), &arg4); if (!ok) { ok = true; break; } cocos2d::LabelBMFont* ret = cocos2d::LabelBMFont::create(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; @@ -36810,7 +37632,7 @@ bool js_cocos2dx_LabelBMFont_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -36819,7 +37641,7 @@ bool js_cocos2dx_LabelBMFont_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LabelBMFont_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::LabelBMFont* cobj = new (std::nothrow) cocos2d::LabelBMFont(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -36833,13 +37655,16 @@ bool js_cocos2dx_LabelBMFont_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::LabelBMFont"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::LabelBMFont"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -36852,21 +37677,21 @@ void js_cocos2d_LabelBMFont_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_LabelBMFont_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::LabelBMFont *nobj = new (std::nothrow) cocos2d::LabelBMFont(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::LabelBMFont"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::LabelBMFont"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_LabelBMFont(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_LabelBMFont(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_LabelBMFont_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_LabelBMFont_class->name = "LabelBMFont"; jsb_cocos2d_LabelBMFont_class->addProperty = JS_PropertyStub; @@ -36880,20 +37705,18 @@ void js_register_cocos2dx_LabelBMFont(JSContext *cx, JSObject *global) { jsb_cocos2d_LabelBMFont_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("setLineBreakWithoutSpace", js_cocos2dx_LabelBMFont_setLineBreakWithoutSpace, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getBlendFunc", js_cocos2dx_LabelBMFont_getBlendFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("isOpacityModifyRGB", js_cocos2dx_LabelBMFont_isOpacityModifyRGB, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getLetter", js_cocos2dx_LabelBMFont_getLetter, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getString", js_cocos2dx_LabelBMFont_getString, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setBlendFunc", js_cocos2dx_LabelBMFont_setBlendFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setString", js_cocos2dx_LabelBMFont_setString, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("initWithString", js_cocos2dx_LabelBMFont_initWithString, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setOpacityModifyRGB", js_cocos2dx_LabelBMFont_setOpacityModifyRGB, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getFntFile", js_cocos2dx_LabelBMFont_getFntFile, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setFntFile", js_cocos2dx_LabelBMFont_setFntFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setAlignment", js_cocos2dx_LabelBMFont_setAlignment, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -36909,7 +37732,7 @@ void js_register_cocos2dx_LabelBMFont(JSContext *cx, JSObject *global) { jsb_cocos2d_LabelBMFont_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_LabelBMFont_class, js_cocos2dx_LabelBMFont_constructor, 0, // constructor properties, @@ -36940,6 +37763,7 @@ JSObject *jsb_cocos2d_Layer_prototype; bool js_cocos2dx_Layer_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Layer* ret = cocos2d::Layer::create(); jsval jsret = JSVAL_NULL; @@ -36951,7 +37775,7 @@ bool js_cocos2dx_Layer_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Layer_create : wrong number of arguments"); @@ -36960,7 +37784,7 @@ bool js_cocos2dx_Layer_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Layer_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Layer* cobj = new (std::nothrow) cocos2d::Layer(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -36974,13 +37798,16 @@ bool js_cocos2dx_Layer_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Layer"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Layer"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -36993,21 +37820,21 @@ void js_cocos2d_Layer_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_Layer_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::Layer *nobj = new (std::nothrow) cocos2d::Layer(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Layer"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Layer"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_Layer(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Layer(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Layer_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Layer_class->name = "Layer"; jsb_cocos2d_Layer_class->addProperty = JS_PropertyStub; @@ -37021,8 +37848,8 @@ void js_register_cocos2dx_Layer(JSContext *cx, JSObject *global) { jsb_cocos2d_Layer_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -37037,7 +37864,7 @@ void js_register_cocos2dx_Layer(JSContext *cx, JSObject *global) { jsb_cocos2d_Layer_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_Layer_class, js_cocos2dx_Layer_constructor, 0, // constructor properties, @@ -37068,6 +37895,7 @@ JSObject *jsb_cocos2d___LayerRGBA_prototype; bool js_cocos2dx___LayerRGBA_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::__LayerRGBA* ret = cocos2d::__LayerRGBA::create(); jsval jsret = JSVAL_NULL; @@ -37079,7 +37907,7 @@ bool js_cocos2dx___LayerRGBA_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx___LayerRGBA_create : wrong number of arguments"); @@ -37088,7 +37916,7 @@ bool js_cocos2dx___LayerRGBA_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx___LayerRGBA_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::__LayerRGBA* cobj = new (std::nothrow) cocos2d::__LayerRGBA(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -37102,13 +37930,16 @@ bool js_cocos2dx___LayerRGBA_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::__LayerRGBA"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::__LayerRGBA"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -37119,7 +37950,7 @@ void js_cocos2d___LayerRGBA_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (__LayerRGBA)", obj); } -void js_register_cocos2dx___LayerRGBA(JSContext *cx, JSObject *global) { +void js_register_cocos2dx___LayerRGBA(JSContext *cx, JS::HandleObject global) { jsb_cocos2d___LayerRGBA_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d___LayerRGBA_class->name = "LayerRGBA"; jsb_cocos2d___LayerRGBA_class->addProperty = JS_PropertyStub; @@ -37133,8 +37964,8 @@ void js_register_cocos2dx___LayerRGBA(JSContext *cx, JSObject *global) { jsb_cocos2d___LayerRGBA_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -37148,7 +37979,7 @@ void js_register_cocos2dx___LayerRGBA(JSContext *cx, JSObject *global) { jsb_cocos2d___LayerRGBA_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Layer_prototype, + JS::RootedObject(cx, jsb_cocos2d_Layer_prototype), jsb_cocos2d___LayerRGBA_class, js_cocos2dx___LayerRGBA_constructor, 0, // constructor properties, @@ -37179,20 +38010,20 @@ JSObject *jsb_cocos2d_LayerColor_prototype; bool js_cocos2dx_LayerColor_changeWidthAndHeight(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerColor* cobj = (cocos2d::LayerColor *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerColor_changeWidthAndHeight : Invalid Native Object"); if (argc == 2) { double arg0; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LayerColor_changeWidthAndHeight : Error processing arguments"); cobj->changeWidthAndHeight(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -37201,7 +38032,8 @@ bool js_cocos2dx_LayerColor_changeWidthAndHeight(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_LayerColor_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerColor* cobj = (cocos2d::LayerColor *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerColor_getBlendFunc : Invalid Native Object"); @@ -37209,7 +38041,7 @@ bool js_cocos2dx_LayerColor_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); jsval jsret = JSVAL_NULL; jsret = blendfunc_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -37218,18 +38050,18 @@ bool js_cocos2dx_LayerColor_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_LayerColor_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerColor* cobj = (cocos2d::LayerColor *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerColor_setBlendFunc : Invalid Native Object"); if (argc == 1) { cocos2d::BlendFunc arg0; - ok &= jsval_to_blendfunc(cx, argv[0], &arg0); + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LayerColor_setBlendFunc : Error processing arguments"); cobj->setBlendFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -37238,18 +38070,18 @@ bool js_cocos2dx_LayerColor_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_LayerColor_changeWidth(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerColor* cobj = (cocos2d::LayerColor *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerColor_changeWidth : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LayerColor_changeWidth : Error processing arguments"); cobj->changeWidth(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -37258,53 +38090,43 @@ bool js_cocos2dx_LayerColor_changeWidth(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LayerColor_initWithColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::LayerColor* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::LayerColor *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerColor_initWithColor : Invalid Native Object"); do { - if (argc == 3) { + if (argc == 1) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - if (!ok) { ok = true; break; } - double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } - bool ret = cobj->initWithColor(arg0, arg1, arg2); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while(0); - - do { - if (argc == 0) { - bool ret = cobj->init(); + bool ret = cobj->initWithColor(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); do { - if (argc == 1) { + if (argc == 3) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } - bool ret = cobj->initWithColor(arg0); + double arg1; + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + if (!ok) { ok = true; break; } + double arg2; + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithColor(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -37314,18 +38136,18 @@ bool js_cocos2dx_LayerColor_initWithColor(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_LayerColor_changeHeight(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerColor* cobj = (cocos2d::LayerColor *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerColor_changeHeight : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LayerColor_changeHeight : Error processing arguments"); cobj->changeHeight(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -37334,19 +38156,19 @@ bool js_cocos2dx_LayerColor_changeHeight(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_LayerColor_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 3) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::LayerColor* ret = cocos2d::LayerColor::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -37358,7 +38180,7 @@ bool js_cocos2dx_LayerColor_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -37375,7 +38197,7 @@ bool js_cocos2dx_LayerColor_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -37383,7 +38205,7 @@ bool js_cocos2dx_LayerColor_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 1) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::LayerColor* ret = cocos2d::LayerColor::create(arg0); jsval jsret = JSVAL_NULL; @@ -37395,7 +38217,7 @@ bool js_cocos2dx_LayerColor_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -37404,7 +38226,7 @@ bool js_cocos2dx_LayerColor_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LayerColor_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::LayerColor* cobj = new (std::nothrow) cocos2d::LayerColor(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -37418,13 +38240,16 @@ bool js_cocos2dx_LayerColor_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::LayerColor"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::LayerColor"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -37437,21 +38262,21 @@ void js_cocos2d_LayerColor_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_LayerColor_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::LayerColor *nobj = new (std::nothrow) cocos2d::LayerColor(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::LayerColor"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::LayerColor"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_LayerColor(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_LayerColor(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_LayerColor_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_LayerColor_class->name = "LayerColor"; jsb_cocos2d_LayerColor_class->addProperty = JS_PropertyStub; @@ -37465,8 +38290,8 @@ void js_register_cocos2dx_LayerColor(JSContext *cx, JSObject *global) { jsb_cocos2d_LayerColor_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -37474,7 +38299,7 @@ void js_register_cocos2dx_LayerColor(JSContext *cx, JSObject *global) { JS_FN("getBlendFunc", js_cocos2dx_LayerColor_getBlendFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setBlendFunc", js_cocos2dx_LayerColor_setBlendFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("changeWidth", js_cocos2dx_LayerColor_changeWidth, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_LayerColor_initWithColor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("init", js_cocos2dx_LayerColor_initWithColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("changeHeight", js_cocos2dx_LayerColor_changeHeight, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2d_LayerColor_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END @@ -37487,7 +38312,7 @@ void js_register_cocos2dx_LayerColor(JSContext *cx, JSObject *global) { jsb_cocos2d_LayerColor_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Layer_prototype, + JS::RootedObject(cx, jsb_cocos2d_Layer_prototype), jsb_cocos2d_LayerColor_class, js_cocos2dx_LayerColor_constructor, 0, // constructor properties, @@ -37518,7 +38343,8 @@ JSObject *jsb_cocos2d_LayerGradient_prototype; bool js_cocos2dx_LayerGradient_getStartColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerGradient* cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_getStartColor : Invalid Native Object"); @@ -37526,7 +38352,7 @@ bool js_cocos2dx_LayerGradient_getStartColor(JSContext *cx, uint32_t argc, jsval const cocos2d::Color3B& ret = cobj->getStartColor(); jsval jsret = JSVAL_NULL; jsret = cccolor3b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -37535,7 +38361,8 @@ bool js_cocos2dx_LayerGradient_getStartColor(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_LayerGradient_isCompressedInterpolation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerGradient* cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_isCompressedInterpolation : Invalid Native Object"); @@ -37543,7 +38370,7 @@ bool js_cocos2dx_LayerGradient_isCompressedInterpolation(JSContext *cx, uint32_t bool ret = cobj->isCompressedInterpolation(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -37552,7 +38379,8 @@ bool js_cocos2dx_LayerGradient_isCompressedInterpolation(JSContext *cx, uint32_t } bool js_cocos2dx_LayerGradient_getStartOpacity(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerGradient* cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_getStartOpacity : Invalid Native Object"); @@ -37560,7 +38388,7 @@ bool js_cocos2dx_LayerGradient_getStartOpacity(JSContext *cx, uint32_t argc, jsv uint16_t ret = cobj->getStartOpacity(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -37569,18 +38397,18 @@ bool js_cocos2dx_LayerGradient_getStartOpacity(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_LayerGradient_setVector(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerGradient* cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_setVector : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LayerGradient_setVector : Error processing arguments"); cobj->setVector(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -37589,18 +38417,18 @@ bool js_cocos2dx_LayerGradient_setVector(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_LayerGradient_setStartOpacity(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerGradient* cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_setStartOpacity : Invalid Native Object"); if (argc == 1) { uint16_t arg0; - ok &= jsval_to_uint16(cx, argv[0], &arg0); + ok &= jsval_to_uint16(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LayerGradient_setStartOpacity : Error processing arguments"); cobj->setStartOpacity(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -37609,18 +38437,18 @@ bool js_cocos2dx_LayerGradient_setStartOpacity(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_LayerGradient_setCompressedInterpolation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerGradient* cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_setCompressedInterpolation : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LayerGradient_setCompressedInterpolation : Error processing arguments"); cobj->setCompressedInterpolation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -37629,18 +38457,18 @@ bool js_cocos2dx_LayerGradient_setCompressedInterpolation(JSContext *cx, uint32_ } bool js_cocos2dx_LayerGradient_setEndOpacity(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerGradient* cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_setEndOpacity : Invalid Native Object"); if (argc == 1) { uint16_t arg0; - ok &= jsval_to_uint16(cx, argv[0], &arg0); + ok &= jsval_to_uint16(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LayerGradient_setEndOpacity : Error processing arguments"); cobj->setEndOpacity(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -37649,7 +38477,8 @@ bool js_cocos2dx_LayerGradient_setEndOpacity(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_LayerGradient_getVector(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerGradient* cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_getVector : Invalid Native Object"); @@ -37657,44 +38486,27 @@ bool js_cocos2dx_LayerGradient_getVector(JSContext *cx, uint32_t argc, jsval *vp const cocos2d::Vec2& ret = cobj->getVector(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_LayerGradient_getVector : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_LayerGradient_init(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::LayerGradient* cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_init : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->init(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_LayerGradient_init : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_LayerGradient_setEndColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerGradient* cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_setEndColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LayerGradient_setEndColor : Error processing arguments"); cobj->setEndColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -37703,30 +38515,30 @@ bool js_cocos2dx_LayerGradient_setEndColor(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_LayerGradient_initWithColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::LayerGradient* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_initWithColor : Invalid Native Object"); do { if (argc == 3) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Color4B arg1; - ok &= jsval_to_cccolor4b(cx, argv[1], &arg1); + ok &= jsval_to_cccolor4b(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::Vec2 arg2; - ok &= jsval_to_vector2(cx, argv[2], &arg2); + ok &= jsval_to_vector2(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } bool ret = cobj->initWithColor(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -37734,15 +38546,15 @@ bool js_cocos2dx_LayerGradient_initWithColor(JSContext *cx, uint32_t argc, jsval do { if (argc == 2) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Color4B arg1; - ok &= jsval_to_cccolor4b(cx, argv[1], &arg1); + ok &= jsval_to_cccolor4b(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool ret = cobj->initWithColor(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -37752,7 +38564,8 @@ bool js_cocos2dx_LayerGradient_initWithColor(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_LayerGradient_getEndColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerGradient* cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_getEndColor : Invalid Native Object"); @@ -37760,7 +38573,7 @@ bool js_cocos2dx_LayerGradient_getEndColor(JSContext *cx, uint32_t argc, jsval * const cocos2d::Color3B& ret = cobj->getEndColor(); jsval jsret = JSVAL_NULL; jsret = cccolor3b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -37769,7 +38582,8 @@ bool js_cocos2dx_LayerGradient_getEndColor(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_LayerGradient_getEndOpacity(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerGradient* cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_getEndOpacity : Invalid Native Object"); @@ -37777,7 +38591,7 @@ bool js_cocos2dx_LayerGradient_getEndOpacity(JSContext *cx, uint32_t argc, jsval uint16_t ret = cobj->getEndOpacity(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -37786,18 +38600,18 @@ bool js_cocos2dx_LayerGradient_getEndOpacity(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_LayerGradient_setStartColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerGradient* cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_setStartColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LayerGradient_setStartColor : Error processing arguments"); cobj->setStartColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -37806,16 +38620,16 @@ bool js_cocos2dx_LayerGradient_setStartColor(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_LayerGradient_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 2) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Color4B arg1; - ok &= jsval_to_cccolor4b(cx, argv[1], &arg1); + ok &= jsval_to_cccolor4b(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::LayerGradient* ret = cocos2d::LayerGradient::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -37827,7 +38641,7 @@ bool js_cocos2dx_LayerGradient_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -37844,7 +38658,7 @@ bool js_cocos2dx_LayerGradient_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -37852,13 +38666,13 @@ bool js_cocos2dx_LayerGradient_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 3) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Color4B arg1; - ok &= jsval_to_cccolor4b(cx, argv[1], &arg1); + ok &= jsval_to_cccolor4b(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::Vec2 arg2; - ok &= jsval_to_vector2(cx, argv[2], &arg2); + ok &= jsval_to_vector2(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } cocos2d::LayerGradient* ret = cocos2d::LayerGradient::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -37870,7 +38684,7 @@ bool js_cocos2dx_LayerGradient_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -37879,7 +38693,7 @@ bool js_cocos2dx_LayerGradient_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_LayerGradient_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::LayerGradient* cobj = new (std::nothrow) cocos2d::LayerGradient(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -37893,13 +38707,16 @@ bool js_cocos2dx_LayerGradient_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::LayerGradient"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::LayerGradient"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -37912,21 +38729,21 @@ void js_cocos2d_LayerGradient_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_LayerGradient_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::LayerGradient *nobj = new (std::nothrow) cocos2d::LayerGradient(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::LayerGradient"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::LayerGradient"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_LayerGradient(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_LayerGradient(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_LayerGradient_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_LayerGradient_class->name = "LayerGradient"; jsb_cocos2d_LayerGradient_class->addProperty = JS_PropertyStub; @@ -37940,8 +38757,8 @@ void js_register_cocos2dx_LayerGradient(JSContext *cx, JSObject *global) { jsb_cocos2d_LayerGradient_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -37953,7 +38770,6 @@ void js_register_cocos2dx_LayerGradient(JSContext *cx, JSObject *global) { JS_FN("setCompressedInterpolation", js_cocos2dx_LayerGradient_setCompressedInterpolation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setEndOpacity", js_cocos2dx_LayerGradient_setEndOpacity, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getVector", js_cocos2dx_LayerGradient_getVector, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_LayerGradient_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setEndColor", js_cocos2dx_LayerGradient_setEndColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("initWithColor", js_cocos2dx_LayerGradient_initWithColor, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getEndColor", js_cocos2dx_LayerGradient_getEndColor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -37970,7 +38786,7 @@ void js_register_cocos2dx_LayerGradient(JSContext *cx, JSObject *global) { jsb_cocos2d_LayerGradient_prototype = JS_InitClass( cx, global, - jsb_cocos2d_LayerColor_prototype, + JS::RootedObject(cx, jsb_cocos2d_LayerColor_prototype), jsb_cocos2d_LayerGradient_class, js_cocos2dx_LayerGradient_constructor, 0, // constructor properties, @@ -38001,57 +38817,40 @@ JSObject *jsb_cocos2d_LayerMultiplex_prototype; bool js_cocos2dx_LayerMultiplex_initWithArray(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerMultiplex* cobj = (cocos2d::LayerMultiplex *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerMultiplex_initWithArray : Invalid Native Object"); if (argc == 1) { cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LayerMultiplex_initWithArray : Error processing arguments"); bool ret = cobj->initWithArray(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_LayerMultiplex_initWithArray : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_LayerMultiplex_init(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::LayerMultiplex* cobj = (cocos2d::LayerMultiplex *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerMultiplex_init : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->init(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_LayerMultiplex_init : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_LayerMultiplex_switchToAndReleaseMe(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerMultiplex* cobj = (cocos2d::LayerMultiplex *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerMultiplex_switchToAndReleaseMe : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LayerMultiplex_switchToAndReleaseMe : Error processing arguments"); cobj->switchToAndReleaseMe(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -38060,25 +38859,25 @@ bool js_cocos2dx_LayerMultiplex_switchToAndReleaseMe(JSContext *cx, uint32_t arg } bool js_cocos2dx_LayerMultiplex_addLayer(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerMultiplex* cobj = (cocos2d::LayerMultiplex *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerMultiplex_addLayer : Invalid Native Object"); if (argc == 1) { cocos2d::Layer* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Layer*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LayerMultiplex_addLayer : Error processing arguments"); cobj->addLayer(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -38087,18 +38886,18 @@ bool js_cocos2dx_LayerMultiplex_addLayer(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_LayerMultiplex_switchTo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::LayerMultiplex* cobj = (cocos2d::LayerMultiplex *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerMultiplex_switchTo : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LayerMultiplex_switchTo : Error processing arguments"); cobj->switchTo(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -38107,7 +38906,7 @@ bool js_cocos2dx_LayerMultiplex_switchTo(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_LayerMultiplex_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::LayerMultiplex* cobj = new (std::nothrow) cocos2d::LayerMultiplex(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -38121,13 +38920,16 @@ bool js_cocos2dx_LayerMultiplex_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::LayerMultiplex"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::LayerMultiplex"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -38140,21 +38942,21 @@ void js_cocos2d_LayerMultiplex_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_LayerMultiplex_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::LayerMultiplex *nobj = new (std::nothrow) cocos2d::LayerMultiplex(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::LayerMultiplex"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::LayerMultiplex"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_LayerMultiplex(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_LayerMultiplex(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_LayerMultiplex_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_LayerMultiplex_class->name = "LayerMultiplex"; jsb_cocos2d_LayerMultiplex_class->addProperty = JS_PropertyStub; @@ -38168,13 +38970,12 @@ void js_register_cocos2dx_LayerMultiplex(JSContext *cx, JSObject *global) { jsb_cocos2d_LayerMultiplex_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("initWithArray", js_cocos2dx_LayerMultiplex_initWithArray, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_LayerMultiplex_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("switchToAndReleaseMe", js_cocos2dx_LayerMultiplex_switchToAndReleaseMe, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("addLayer", js_cocos2dx_LayerMultiplex_addLayer, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("switchTo", js_cocos2dx_LayerMultiplex_switchTo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -38186,7 +38987,7 @@ void js_register_cocos2dx_LayerMultiplex(JSContext *cx, JSObject *global) { jsb_cocos2d_LayerMultiplex_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Layer_prototype, + JS::RootedObject(cx, jsb_cocos2d_Layer_prototype), jsb_cocos2d_LayerMultiplex_class, js_cocos2dx_LayerMultiplex_constructor, 0, // constructor properties, @@ -38217,18 +39018,18 @@ JSObject *jsb_cocos2d_TransitionEaseScene_prototype; bool js_cocos2dx_TransitionEaseScene_easeActionWithAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionEaseScene* cobj = (cocos2d::TransitionEaseScene *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionEaseScene_easeActionWithAction : Invalid Native Object"); if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -38244,7 +39045,7 @@ bool js_cocos2dx_TransitionEaseScene_easeActionWithAction(JSContext *cx, uint32_ jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -38257,7 +39058,7 @@ void js_cocos2d_TransitionEaseScene_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionEaseScene)", obj); } -void js_register_cocos2dx_TransitionEaseScene(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionEaseScene(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionEaseScene_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionEaseScene_class->name = "TransitionEaseScene"; jsb_cocos2d_TransitionEaseScene_class->addProperty = JS_PropertyStub; @@ -38271,8 +39072,8 @@ void js_register_cocos2dx_TransitionEaseScene(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionEaseScene_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -38284,7 +39085,7 @@ void js_register_cocos2dx_TransitionEaseScene(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionEaseScene_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_TransitionEaseScene_class, empty_constructor, 0, properties, @@ -38315,13 +39116,14 @@ JSObject *jsb_cocos2d_TransitionScene_prototype; bool js_cocos2dx_TransitionScene_finish(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionScene* cobj = (cocos2d::TransitionScene *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionScene_finish : Invalid Native Object"); if (argc == 0) { cobj->finish(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -38330,20 +39132,20 @@ bool js_cocos2dx_TransitionScene_finish(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TransitionScene_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionScene* cobj = (cocos2d::TransitionScene *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionScene_initWithDuration : Invalid Native Object"); if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -38352,7 +39154,7 @@ bool js_cocos2dx_TransitionScene_initWithDuration(JSContext *cx, uint32_t argc, bool ret = cobj->initWithDuration(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -38361,13 +39163,14 @@ bool js_cocos2dx_TransitionScene_initWithDuration(JSContext *cx, uint32_t argc, } bool js_cocos2dx_TransitionScene_hideOutShowIn(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionScene* cobj = (cocos2d::TransitionScene *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionScene_hideOutShowIn : Invalid Native Object"); if (argc == 0) { cobj->hideOutShowIn(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -38376,16 +39179,16 @@ bool js_cocos2dx_TransitionScene_hideOutShowIn(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_TransitionScene_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -38401,7 +39204,7 @@ bool js_cocos2dx_TransitionScene_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionScene_create : wrong number of arguments"); @@ -38410,7 +39213,7 @@ bool js_cocos2dx_TransitionScene_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_TransitionScene_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionScene* cobj = new (std::nothrow) cocos2d::TransitionScene(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -38424,13 +39227,16 @@ bool js_cocos2dx_TransitionScene_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionScene"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionScene"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -38443,21 +39249,21 @@ void js_cocos2d_TransitionScene_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_TransitionScene_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::TransitionScene *nobj = new (std::nothrow) cocos2d::TransitionScene(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionScene"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionScene"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_TransitionScene(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionScene(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionScene_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionScene_class->name = "TransitionScene"; jsb_cocos2d_TransitionScene_class->addProperty = JS_PropertyStub; @@ -38471,8 +39277,8 @@ void js_register_cocos2dx_TransitionScene(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionScene_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -38490,7 +39296,7 @@ void js_register_cocos2dx_TransitionScene(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionScene_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Scene_prototype, + JS::RootedObject(cx, jsb_cocos2d_Scene_prototype), jsb_cocos2d_TransitionScene_class, js_cocos2dx_TransitionScene_constructor, 0, // constructor properties, @@ -38521,9 +39327,9 @@ JSObject *jsb_cocos2d_TransitionSceneOriented_prototype; bool js_cocos2dx_TransitionSceneOriented_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionSceneOriented* cobj = (cocos2d::TransitionSceneOriented *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionSceneOriented_initWithDuration : Invalid Native Object"); @@ -38531,21 +39337,21 @@ bool js_cocos2dx_TransitionSceneOriented_initWithDuration(JSContext *cx, uint32_ double arg0; cocos2d::Scene* arg1; cocos2d::TransitionScene::Orientation arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TransitionSceneOriented_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -38554,22 +39360,22 @@ bool js_cocos2dx_TransitionSceneOriented_initWithDuration(JSContext *cx, uint32_ } bool js_cocos2dx_TransitionSceneOriented_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 3) { double arg0; cocos2d::Scene* arg1; cocos2d::TransitionScene::Orientation arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TransitionSceneOriented_create : Error processing arguments"); cocos2d::TransitionSceneOriented* ret = cocos2d::TransitionSceneOriented::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -38581,7 +39387,7 @@ bool js_cocos2dx_TransitionSceneOriented_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionSceneOriented_create : wrong number of arguments"); @@ -38590,7 +39396,7 @@ bool js_cocos2dx_TransitionSceneOriented_create(JSContext *cx, uint32_t argc, js bool js_cocos2dx_TransitionSceneOriented_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionSceneOriented* cobj = new (std::nothrow) cocos2d::TransitionSceneOriented(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -38604,13 +39410,16 @@ bool js_cocos2dx_TransitionSceneOriented_constructor(JSContext *cx, uint32_t arg CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionSceneOriented"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionSceneOriented"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -38621,7 +39430,7 @@ void js_cocos2d_TransitionSceneOriented_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionSceneOriented)", obj); } -void js_register_cocos2dx_TransitionSceneOriented(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionSceneOriented(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionSceneOriented_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionSceneOriented_class->name = "TransitionSceneOriented"; jsb_cocos2d_TransitionSceneOriented_class->addProperty = JS_PropertyStub; @@ -38635,8 +39444,8 @@ void js_register_cocos2dx_TransitionSceneOriented(JSContext *cx, JSObject *globa jsb_cocos2d_TransitionSceneOriented_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -38651,7 +39460,7 @@ void js_register_cocos2dx_TransitionSceneOriented(JSContext *cx, JSObject *globa jsb_cocos2d_TransitionSceneOriented_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionScene_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionScene_prototype), jsb_cocos2d_TransitionSceneOriented_class, js_cocos2dx_TransitionSceneOriented_constructor, 0, // constructor properties, @@ -38682,16 +39491,16 @@ JSObject *jsb_cocos2d_TransitionRotoZoom_prototype; bool js_cocos2dx_TransitionRotoZoom_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -38707,7 +39516,7 @@ bool js_cocos2dx_TransitionRotoZoom_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionRotoZoom_create : wrong number of arguments"); @@ -38716,7 +39525,7 @@ bool js_cocos2dx_TransitionRotoZoom_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_TransitionRotoZoom_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionRotoZoom* cobj = new (std::nothrow) cocos2d::TransitionRotoZoom(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -38730,13 +39539,16 @@ bool js_cocos2dx_TransitionRotoZoom_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionRotoZoom"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionRotoZoom"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -38747,7 +39559,7 @@ void js_cocos2d_TransitionRotoZoom_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionRotoZoom)", obj); } -void js_register_cocos2dx_TransitionRotoZoom(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionRotoZoom(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionRotoZoom_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionRotoZoom_class->name = "TransitionRotoZoom"; jsb_cocos2d_TransitionRotoZoom_class->addProperty = JS_PropertyStub; @@ -38761,8 +39573,8 @@ void js_register_cocos2dx_TransitionRotoZoom(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionRotoZoom_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -38776,7 +39588,7 @@ void js_register_cocos2dx_TransitionRotoZoom(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionRotoZoom_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionScene_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionScene_prototype), jsb_cocos2d_TransitionRotoZoom_class, js_cocos2dx_TransitionRotoZoom_constructor, 0, // constructor properties, @@ -38807,16 +39619,16 @@ JSObject *jsb_cocos2d_TransitionJumpZoom_prototype; bool js_cocos2dx_TransitionJumpZoom_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -38832,7 +39644,7 @@ bool js_cocos2dx_TransitionJumpZoom_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionJumpZoom_create : wrong number of arguments"); @@ -38841,7 +39653,7 @@ bool js_cocos2dx_TransitionJumpZoom_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_TransitionJumpZoom_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionJumpZoom* cobj = new (std::nothrow) cocos2d::TransitionJumpZoom(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -38855,13 +39667,16 @@ bool js_cocos2dx_TransitionJumpZoom_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionJumpZoom"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionJumpZoom"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -38872,7 +39687,7 @@ void js_cocos2d_TransitionJumpZoom_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionJumpZoom)", obj); } -void js_register_cocos2dx_TransitionJumpZoom(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionJumpZoom(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionJumpZoom_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionJumpZoom_class->name = "TransitionJumpZoom"; jsb_cocos2d_TransitionJumpZoom_class->addProperty = JS_PropertyStub; @@ -38886,8 +39701,8 @@ void js_register_cocos2dx_TransitionJumpZoom(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionJumpZoom_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -38901,7 +39716,7 @@ void js_register_cocos2dx_TransitionJumpZoom(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionJumpZoom_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionScene_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionScene_prototype), jsb_cocos2d_TransitionJumpZoom_class, js_cocos2dx_TransitionJumpZoom_constructor, 0, // constructor properties, @@ -38932,7 +39747,8 @@ JSObject *jsb_cocos2d_TransitionMoveInL_prototype; bool js_cocos2dx_TransitionMoveInL_action(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionMoveInL* cobj = (cocos2d::TransitionMoveInL *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionMoveInL_action : Invalid Native Object"); @@ -38947,7 +39763,7 @@ bool js_cocos2dx_TransitionMoveInL_action(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -38956,18 +39772,18 @@ bool js_cocos2dx_TransitionMoveInL_action(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_TransitionMoveInL_easeActionWithAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionMoveInL* cobj = (cocos2d::TransitionMoveInL *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionMoveInL_easeActionWithAction : Invalid Native Object"); if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -38983,7 +39799,7 @@ bool js_cocos2dx_TransitionMoveInL_easeActionWithAction(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -38992,16 +39808,16 @@ bool js_cocos2dx_TransitionMoveInL_easeActionWithAction(JSContext *cx, uint32_t } bool js_cocos2dx_TransitionMoveInL_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -39017,7 +39833,7 @@ bool js_cocos2dx_TransitionMoveInL_create(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionMoveInL_create : wrong number of arguments"); @@ -39026,7 +39842,7 @@ bool js_cocos2dx_TransitionMoveInL_create(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_TransitionMoveInL_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionMoveInL* cobj = new (std::nothrow) cocos2d::TransitionMoveInL(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -39040,13 +39856,16 @@ bool js_cocos2dx_TransitionMoveInL_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionMoveInL"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionMoveInL"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -39057,7 +39876,7 @@ void js_cocos2d_TransitionMoveInL_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionMoveInL)", obj); } -void js_register_cocos2dx_TransitionMoveInL(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionMoveInL(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionMoveInL_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionMoveInL_class->name = "TransitionMoveInL"; jsb_cocos2d_TransitionMoveInL_class->addProperty = JS_PropertyStub; @@ -39071,8 +39890,8 @@ void js_register_cocos2dx_TransitionMoveInL(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionMoveInL_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -39088,7 +39907,7 @@ void js_register_cocos2dx_TransitionMoveInL(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionMoveInL_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionScene_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionScene_prototype), jsb_cocos2d_TransitionMoveInL_class, js_cocos2dx_TransitionMoveInL_constructor, 0, // constructor properties, @@ -39119,16 +39938,16 @@ JSObject *jsb_cocos2d_TransitionMoveInR_prototype; bool js_cocos2dx_TransitionMoveInR_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -39144,7 +39963,7 @@ bool js_cocos2dx_TransitionMoveInR_create(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionMoveInR_create : wrong number of arguments"); @@ -39153,7 +39972,7 @@ bool js_cocos2dx_TransitionMoveInR_create(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_TransitionMoveInR_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionMoveInR* cobj = new (std::nothrow) cocos2d::TransitionMoveInR(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -39167,13 +39986,16 @@ bool js_cocos2dx_TransitionMoveInR_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionMoveInR"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionMoveInR"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -39184,7 +40006,7 @@ void js_cocos2d_TransitionMoveInR_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionMoveInR)", obj); } -void js_register_cocos2dx_TransitionMoveInR(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionMoveInR(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionMoveInR_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionMoveInR_class->name = "TransitionMoveInR"; jsb_cocos2d_TransitionMoveInR_class->addProperty = JS_PropertyStub; @@ -39198,8 +40020,8 @@ void js_register_cocos2dx_TransitionMoveInR(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionMoveInR_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -39213,7 +40035,7 @@ void js_register_cocos2dx_TransitionMoveInR(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionMoveInR_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionMoveInL_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionMoveInL_prototype), jsb_cocos2d_TransitionMoveInR_class, js_cocos2dx_TransitionMoveInR_constructor, 0, // constructor properties, @@ -39244,16 +40066,16 @@ JSObject *jsb_cocos2d_TransitionMoveInT_prototype; bool js_cocos2dx_TransitionMoveInT_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -39269,7 +40091,7 @@ bool js_cocos2dx_TransitionMoveInT_create(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionMoveInT_create : wrong number of arguments"); @@ -39278,7 +40100,7 @@ bool js_cocos2dx_TransitionMoveInT_create(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_TransitionMoveInT_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionMoveInT* cobj = new (std::nothrow) cocos2d::TransitionMoveInT(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -39292,13 +40114,16 @@ bool js_cocos2dx_TransitionMoveInT_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionMoveInT"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionMoveInT"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -39309,7 +40134,7 @@ void js_cocos2d_TransitionMoveInT_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionMoveInT)", obj); } -void js_register_cocos2dx_TransitionMoveInT(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionMoveInT(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionMoveInT_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionMoveInT_class->name = "TransitionMoveInT"; jsb_cocos2d_TransitionMoveInT_class->addProperty = JS_PropertyStub; @@ -39323,8 +40148,8 @@ void js_register_cocos2dx_TransitionMoveInT(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionMoveInT_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -39338,7 +40163,7 @@ void js_register_cocos2dx_TransitionMoveInT(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionMoveInT_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionMoveInL_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionMoveInL_prototype), jsb_cocos2d_TransitionMoveInT_class, js_cocos2dx_TransitionMoveInT_constructor, 0, // constructor properties, @@ -39369,16 +40194,16 @@ JSObject *jsb_cocos2d_TransitionMoveInB_prototype; bool js_cocos2dx_TransitionMoveInB_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -39394,7 +40219,7 @@ bool js_cocos2dx_TransitionMoveInB_create(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionMoveInB_create : wrong number of arguments"); @@ -39403,7 +40228,7 @@ bool js_cocos2dx_TransitionMoveInB_create(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_TransitionMoveInB_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionMoveInB* cobj = new (std::nothrow) cocos2d::TransitionMoveInB(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -39417,13 +40242,16 @@ bool js_cocos2dx_TransitionMoveInB_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionMoveInB"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionMoveInB"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -39434,7 +40262,7 @@ void js_cocos2d_TransitionMoveInB_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionMoveInB)", obj); } -void js_register_cocos2dx_TransitionMoveInB(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionMoveInB(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionMoveInB_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionMoveInB_class->name = "TransitionMoveInB"; jsb_cocos2d_TransitionMoveInB_class->addProperty = JS_PropertyStub; @@ -39448,8 +40276,8 @@ void js_register_cocos2dx_TransitionMoveInB(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionMoveInB_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -39463,7 +40291,7 @@ void js_register_cocos2dx_TransitionMoveInB(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionMoveInB_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionMoveInL_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionMoveInL_prototype), jsb_cocos2d_TransitionMoveInB_class, js_cocos2dx_TransitionMoveInB_constructor, 0, // constructor properties, @@ -39494,7 +40322,8 @@ JSObject *jsb_cocos2d_TransitionSlideInL_prototype; bool js_cocos2dx_TransitionSlideInL_action(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionSlideInL* cobj = (cocos2d::TransitionSlideInL *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionSlideInL_action : Invalid Native Object"); @@ -39509,7 +40338,7 @@ bool js_cocos2dx_TransitionSlideInL_action(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -39518,18 +40347,18 @@ bool js_cocos2dx_TransitionSlideInL_action(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_TransitionSlideInL_easeActionWithAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionSlideInL* cobj = (cocos2d::TransitionSlideInL *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionSlideInL_easeActionWithAction : Invalid Native Object"); if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -39545,7 +40374,7 @@ bool js_cocos2dx_TransitionSlideInL_easeActionWithAction(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -39554,16 +40383,16 @@ bool js_cocos2dx_TransitionSlideInL_easeActionWithAction(JSContext *cx, uint32_t } bool js_cocos2dx_TransitionSlideInL_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -39579,7 +40408,7 @@ bool js_cocos2dx_TransitionSlideInL_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionSlideInL_create : wrong number of arguments"); @@ -39588,7 +40417,7 @@ bool js_cocos2dx_TransitionSlideInL_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_TransitionSlideInL_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionSlideInL* cobj = new (std::nothrow) cocos2d::TransitionSlideInL(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -39602,13 +40431,16 @@ bool js_cocos2dx_TransitionSlideInL_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionSlideInL"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionSlideInL"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -39619,7 +40451,7 @@ void js_cocos2d_TransitionSlideInL_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionSlideInL)", obj); } -void js_register_cocos2dx_TransitionSlideInL(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionSlideInL(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionSlideInL_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionSlideInL_class->name = "TransitionSlideInL"; jsb_cocos2d_TransitionSlideInL_class->addProperty = JS_PropertyStub; @@ -39633,8 +40465,8 @@ void js_register_cocos2dx_TransitionSlideInL(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionSlideInL_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -39650,7 +40482,7 @@ void js_register_cocos2dx_TransitionSlideInL(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionSlideInL_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionScene_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionScene_prototype), jsb_cocos2d_TransitionSlideInL_class, js_cocos2dx_TransitionSlideInL_constructor, 0, // constructor properties, @@ -39679,42 +40511,18 @@ void js_register_cocos2dx_TransitionSlideInL(JSContext *cx, JSObject *global) { JSClass *jsb_cocos2d_TransitionSlideInR_class; JSObject *jsb_cocos2d_TransitionSlideInR_prototype; -bool js_cocos2dx_TransitionSlideInR_action(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::TransitionSlideInR* cobj = (cocos2d::TransitionSlideInR *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionSlideInR_action : Invalid Native Object"); - if (argc == 0) { - cocos2d::ActionInterval* ret = cobj->action(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ActionInterval*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_TransitionSlideInR_action : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_TransitionSlideInR_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -39730,7 +40538,7 @@ bool js_cocos2dx_TransitionSlideInR_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionSlideInR_create : wrong number of arguments"); @@ -39739,7 +40547,7 @@ bool js_cocos2dx_TransitionSlideInR_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_TransitionSlideInR_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionSlideInR* cobj = new (std::nothrow) cocos2d::TransitionSlideInR(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -39753,13 +40561,16 @@ bool js_cocos2dx_TransitionSlideInR_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionSlideInR"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionSlideInR"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -39770,7 +40581,7 @@ void js_cocos2d_TransitionSlideInR_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionSlideInR)", obj); } -void js_register_cocos2dx_TransitionSlideInR(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionSlideInR(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionSlideInR_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionSlideInR_class->name = "TransitionSlideInR"; jsb_cocos2d_TransitionSlideInR_class->addProperty = JS_PropertyStub; @@ -39784,12 +40595,11 @@ void js_register_cocos2dx_TransitionSlideInR(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionSlideInR_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("action", js_cocos2dx_TransitionSlideInR_action, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -39800,7 +40610,7 @@ void js_register_cocos2dx_TransitionSlideInR(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionSlideInR_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionSlideInL_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionSlideInL_prototype), jsb_cocos2d_TransitionSlideInR_class, js_cocos2dx_TransitionSlideInR_constructor, 0, // constructor properties, @@ -39829,42 +40639,18 @@ void js_register_cocos2dx_TransitionSlideInR(JSContext *cx, JSObject *global) { JSClass *jsb_cocos2d_TransitionSlideInB_class; JSObject *jsb_cocos2d_TransitionSlideInB_prototype; -bool js_cocos2dx_TransitionSlideInB_action(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::TransitionSlideInB* cobj = (cocos2d::TransitionSlideInB *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionSlideInB_action : Invalid Native Object"); - if (argc == 0) { - cocos2d::ActionInterval* ret = cobj->action(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ActionInterval*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_TransitionSlideInB_action : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_TransitionSlideInB_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -39880,7 +40666,7 @@ bool js_cocos2dx_TransitionSlideInB_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionSlideInB_create : wrong number of arguments"); @@ -39889,7 +40675,7 @@ bool js_cocos2dx_TransitionSlideInB_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_TransitionSlideInB_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionSlideInB* cobj = new (std::nothrow) cocos2d::TransitionSlideInB(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -39903,13 +40689,16 @@ bool js_cocos2dx_TransitionSlideInB_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionSlideInB"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionSlideInB"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -39920,7 +40709,7 @@ void js_cocos2d_TransitionSlideInB_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionSlideInB)", obj); } -void js_register_cocos2dx_TransitionSlideInB(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionSlideInB(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionSlideInB_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionSlideInB_class->name = "TransitionSlideInB"; jsb_cocos2d_TransitionSlideInB_class->addProperty = JS_PropertyStub; @@ -39934,12 +40723,11 @@ void js_register_cocos2dx_TransitionSlideInB(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionSlideInB_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("action", js_cocos2dx_TransitionSlideInB_action, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -39950,7 +40738,7 @@ void js_register_cocos2dx_TransitionSlideInB(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionSlideInB_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionSlideInL_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionSlideInL_prototype), jsb_cocos2d_TransitionSlideInB_class, js_cocos2dx_TransitionSlideInB_constructor, 0, // constructor properties, @@ -39979,42 +40767,18 @@ void js_register_cocos2dx_TransitionSlideInB(JSContext *cx, JSObject *global) { JSClass *jsb_cocos2d_TransitionSlideInT_class; JSObject *jsb_cocos2d_TransitionSlideInT_prototype; -bool js_cocos2dx_TransitionSlideInT_action(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::TransitionSlideInT* cobj = (cocos2d::TransitionSlideInT *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionSlideInT_action : Invalid Native Object"); - if (argc == 0) { - cocos2d::ActionInterval* ret = cobj->action(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ActionInterval*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_TransitionSlideInT_action : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_TransitionSlideInT_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -40030,7 +40794,7 @@ bool js_cocos2dx_TransitionSlideInT_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionSlideInT_create : wrong number of arguments"); @@ -40039,7 +40803,7 @@ bool js_cocos2dx_TransitionSlideInT_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_TransitionSlideInT_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionSlideInT* cobj = new (std::nothrow) cocos2d::TransitionSlideInT(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -40053,13 +40817,16 @@ bool js_cocos2dx_TransitionSlideInT_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionSlideInT"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionSlideInT"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -40070,7 +40837,7 @@ void js_cocos2d_TransitionSlideInT_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionSlideInT)", obj); } -void js_register_cocos2dx_TransitionSlideInT(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionSlideInT(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionSlideInT_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionSlideInT_class->name = "TransitionSlideInT"; jsb_cocos2d_TransitionSlideInT_class->addProperty = JS_PropertyStub; @@ -40084,12 +40851,11 @@ void js_register_cocos2dx_TransitionSlideInT(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionSlideInT_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("action", js_cocos2dx_TransitionSlideInT_action, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -40100,7 +40866,7 @@ void js_register_cocos2dx_TransitionSlideInT(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionSlideInT_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionSlideInL_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionSlideInL_prototype), jsb_cocos2d_TransitionSlideInT_class, js_cocos2dx_TransitionSlideInT_constructor, 0, // constructor properties, @@ -40131,18 +40897,18 @@ JSObject *jsb_cocos2d_TransitionShrinkGrow_prototype; bool js_cocos2dx_TransitionShrinkGrow_easeActionWithAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionShrinkGrow* cobj = (cocos2d::TransitionShrinkGrow *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionShrinkGrow_easeActionWithAction : Invalid Native Object"); if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -40158,7 +40924,7 @@ bool js_cocos2dx_TransitionShrinkGrow_easeActionWithAction(JSContext *cx, uint32 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -40167,16 +40933,16 @@ bool js_cocos2dx_TransitionShrinkGrow_easeActionWithAction(JSContext *cx, uint32 } bool js_cocos2dx_TransitionShrinkGrow_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -40192,7 +40958,7 @@ bool js_cocos2dx_TransitionShrinkGrow_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionShrinkGrow_create : wrong number of arguments"); @@ -40201,7 +40967,7 @@ bool js_cocos2dx_TransitionShrinkGrow_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_TransitionShrinkGrow_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionShrinkGrow* cobj = new (std::nothrow) cocos2d::TransitionShrinkGrow(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -40215,13 +40981,16 @@ bool js_cocos2dx_TransitionShrinkGrow_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionShrinkGrow"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionShrinkGrow"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -40232,7 +41001,7 @@ void js_cocos2d_TransitionShrinkGrow_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionShrinkGrow)", obj); } -void js_register_cocos2dx_TransitionShrinkGrow(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionShrinkGrow(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionShrinkGrow_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionShrinkGrow_class->name = "TransitionShrinkGrow"; jsb_cocos2d_TransitionShrinkGrow_class->addProperty = JS_PropertyStub; @@ -40246,8 +41015,8 @@ void js_register_cocos2dx_TransitionShrinkGrow(JSContext *cx, JSObject *global) jsb_cocos2d_TransitionShrinkGrow_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -40262,7 +41031,7 @@ void js_register_cocos2dx_TransitionShrinkGrow(JSContext *cx, JSObject *global) jsb_cocos2d_TransitionShrinkGrow_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionScene_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionScene_prototype), jsb_cocos2d_TransitionShrinkGrow_class, js_cocos2dx_TransitionShrinkGrow_constructor, 0, // constructor properties, @@ -40293,19 +41062,19 @@ JSObject *jsb_cocos2d_TransitionFlipX_prototype; bool js_cocos2dx_TransitionFlipX_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -40321,7 +41090,7 @@ bool js_cocos2dx_TransitionFlipX_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -40329,20 +41098,20 @@ bool js_cocos2dx_TransitionFlipX_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::TransitionScene::Orientation arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } cocos2d::TransitionFlipX* ret = cocos2d::TransitionFlipX::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -40354,7 +41123,7 @@ bool js_cocos2dx_TransitionFlipX_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -40363,7 +41132,7 @@ bool js_cocos2dx_TransitionFlipX_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TransitionFlipX_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionFlipX* cobj = new (std::nothrow) cocos2d::TransitionFlipX(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -40377,13 +41146,16 @@ bool js_cocos2dx_TransitionFlipX_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFlipX"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFlipX"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -40394,7 +41166,7 @@ void js_cocos2d_TransitionFlipX_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionFlipX)", obj); } -void js_register_cocos2dx_TransitionFlipX(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionFlipX(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionFlipX_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionFlipX_class->name = "TransitionFlipX"; jsb_cocos2d_TransitionFlipX_class->addProperty = JS_PropertyStub; @@ -40408,8 +41180,8 @@ void js_register_cocos2dx_TransitionFlipX(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionFlipX_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -40423,7 +41195,7 @@ void js_register_cocos2dx_TransitionFlipX(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionFlipX_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionSceneOriented_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionSceneOriented_prototype), jsb_cocos2d_TransitionFlipX_class, js_cocos2dx_TransitionFlipX_constructor, 0, // constructor properties, @@ -40454,19 +41226,19 @@ JSObject *jsb_cocos2d_TransitionFlipY_prototype; bool js_cocos2dx_TransitionFlipY_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -40482,7 +41254,7 @@ bool js_cocos2dx_TransitionFlipY_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -40490,20 +41262,20 @@ bool js_cocos2dx_TransitionFlipY_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::TransitionScene::Orientation arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } cocos2d::TransitionFlipY* ret = cocos2d::TransitionFlipY::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -40515,7 +41287,7 @@ bool js_cocos2dx_TransitionFlipY_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -40524,7 +41296,7 @@ bool js_cocos2dx_TransitionFlipY_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TransitionFlipY_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionFlipY* cobj = new (std::nothrow) cocos2d::TransitionFlipY(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -40538,13 +41310,16 @@ bool js_cocos2dx_TransitionFlipY_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFlipY"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFlipY"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -40555,7 +41330,7 @@ void js_cocos2d_TransitionFlipY_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionFlipY)", obj); } -void js_register_cocos2dx_TransitionFlipY(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionFlipY(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionFlipY_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionFlipY_class->name = "TransitionFlipY"; jsb_cocos2d_TransitionFlipY_class->addProperty = JS_PropertyStub; @@ -40569,8 +41344,8 @@ void js_register_cocos2dx_TransitionFlipY(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionFlipY_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -40584,7 +41359,7 @@ void js_register_cocos2dx_TransitionFlipY(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionFlipY_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionSceneOriented_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionSceneOriented_prototype), jsb_cocos2d_TransitionFlipY_class, js_cocos2dx_TransitionFlipY_constructor, 0, // constructor properties, @@ -40615,19 +41390,19 @@ JSObject *jsb_cocos2d_TransitionFlipAngular_prototype; bool js_cocos2dx_TransitionFlipAngular_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -40643,7 +41418,7 @@ bool js_cocos2dx_TransitionFlipAngular_create(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -40651,20 +41426,20 @@ bool js_cocos2dx_TransitionFlipAngular_create(JSContext *cx, uint32_t argc, jsva do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::TransitionScene::Orientation arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } cocos2d::TransitionFlipAngular* ret = cocos2d::TransitionFlipAngular::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -40676,7 +41451,7 @@ bool js_cocos2dx_TransitionFlipAngular_create(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -40685,7 +41460,7 @@ bool js_cocos2dx_TransitionFlipAngular_create(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_TransitionFlipAngular_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionFlipAngular* cobj = new (std::nothrow) cocos2d::TransitionFlipAngular(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -40699,13 +41474,16 @@ bool js_cocos2dx_TransitionFlipAngular_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFlipAngular"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFlipAngular"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -40716,7 +41494,7 @@ void js_cocos2d_TransitionFlipAngular_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionFlipAngular)", obj); } -void js_register_cocos2dx_TransitionFlipAngular(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionFlipAngular(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionFlipAngular_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionFlipAngular_class->name = "TransitionFlipAngular"; jsb_cocos2d_TransitionFlipAngular_class->addProperty = JS_PropertyStub; @@ -40730,8 +41508,8 @@ void js_register_cocos2dx_TransitionFlipAngular(JSContext *cx, JSObject *global) jsb_cocos2d_TransitionFlipAngular_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -40745,7 +41523,7 @@ void js_register_cocos2dx_TransitionFlipAngular(JSContext *cx, JSObject *global) jsb_cocos2d_TransitionFlipAngular_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionSceneOriented_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionSceneOriented_prototype), jsb_cocos2d_TransitionFlipAngular_class, js_cocos2dx_TransitionFlipAngular_constructor, 0, // constructor properties, @@ -40776,19 +41554,19 @@ JSObject *jsb_cocos2d_TransitionZoomFlipX_prototype; bool js_cocos2dx_TransitionZoomFlipX_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -40804,7 +41582,7 @@ bool js_cocos2dx_TransitionZoomFlipX_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -40812,20 +41590,20 @@ bool js_cocos2dx_TransitionZoomFlipX_create(JSContext *cx, uint32_t argc, jsval do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::TransitionScene::Orientation arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } cocos2d::TransitionZoomFlipX* ret = cocos2d::TransitionZoomFlipX::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -40837,7 +41615,7 @@ bool js_cocos2dx_TransitionZoomFlipX_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -40846,7 +41624,7 @@ bool js_cocos2dx_TransitionZoomFlipX_create(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TransitionZoomFlipX_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionZoomFlipX* cobj = new (std::nothrow) cocos2d::TransitionZoomFlipX(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -40860,13 +41638,16 @@ bool js_cocos2dx_TransitionZoomFlipX_constructor(JSContext *cx, uint32_t argc, j CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionZoomFlipX"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionZoomFlipX"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -40877,7 +41658,7 @@ void js_cocos2d_TransitionZoomFlipX_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionZoomFlipX)", obj); } -void js_register_cocos2dx_TransitionZoomFlipX(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionZoomFlipX(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionZoomFlipX_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionZoomFlipX_class->name = "TransitionZoomFlipX"; jsb_cocos2d_TransitionZoomFlipX_class->addProperty = JS_PropertyStub; @@ -40891,8 +41672,8 @@ void js_register_cocos2dx_TransitionZoomFlipX(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionZoomFlipX_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -40906,7 +41687,7 @@ void js_register_cocos2dx_TransitionZoomFlipX(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionZoomFlipX_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionSceneOriented_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionSceneOriented_prototype), jsb_cocos2d_TransitionZoomFlipX_class, js_cocos2dx_TransitionZoomFlipX_constructor, 0, // constructor properties, @@ -40937,19 +41718,19 @@ JSObject *jsb_cocos2d_TransitionZoomFlipY_prototype; bool js_cocos2dx_TransitionZoomFlipY_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -40965,7 +41746,7 @@ bool js_cocos2dx_TransitionZoomFlipY_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -40973,20 +41754,20 @@ bool js_cocos2dx_TransitionZoomFlipY_create(JSContext *cx, uint32_t argc, jsval do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::TransitionScene::Orientation arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } cocos2d::TransitionZoomFlipY* ret = cocos2d::TransitionZoomFlipY::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -40998,7 +41779,7 @@ bool js_cocos2dx_TransitionZoomFlipY_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -41007,7 +41788,7 @@ bool js_cocos2dx_TransitionZoomFlipY_create(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TransitionZoomFlipY_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionZoomFlipY* cobj = new (std::nothrow) cocos2d::TransitionZoomFlipY(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -41021,13 +41802,16 @@ bool js_cocos2dx_TransitionZoomFlipY_constructor(JSContext *cx, uint32_t argc, j CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionZoomFlipY"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionZoomFlipY"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -41038,7 +41822,7 @@ void js_cocos2d_TransitionZoomFlipY_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionZoomFlipY)", obj); } -void js_register_cocos2dx_TransitionZoomFlipY(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionZoomFlipY(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionZoomFlipY_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionZoomFlipY_class->name = "TransitionZoomFlipY"; jsb_cocos2d_TransitionZoomFlipY_class->addProperty = JS_PropertyStub; @@ -41052,8 +41836,8 @@ void js_register_cocos2dx_TransitionZoomFlipY(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionZoomFlipY_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -41067,7 +41851,7 @@ void js_register_cocos2dx_TransitionZoomFlipY(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionZoomFlipY_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionSceneOriented_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionSceneOriented_prototype), jsb_cocos2d_TransitionZoomFlipY_class, js_cocos2dx_TransitionZoomFlipY_constructor, 0, // constructor properties, @@ -41098,19 +41882,19 @@ JSObject *jsb_cocos2d_TransitionZoomFlipAngular_prototype; bool js_cocos2dx_TransitionZoomFlipAngular_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -41126,7 +41910,7 @@ bool js_cocos2dx_TransitionZoomFlipAngular_create(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -41134,20 +41918,20 @@ bool js_cocos2dx_TransitionZoomFlipAngular_create(JSContext *cx, uint32_t argc, do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::TransitionScene::Orientation arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } cocos2d::TransitionZoomFlipAngular* ret = cocos2d::TransitionZoomFlipAngular::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -41159,7 +41943,7 @@ bool js_cocos2dx_TransitionZoomFlipAngular_create(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -41168,7 +41952,7 @@ bool js_cocos2dx_TransitionZoomFlipAngular_create(JSContext *cx, uint32_t argc, } bool js_cocos2dx_TransitionZoomFlipAngular_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionZoomFlipAngular* cobj = new (std::nothrow) cocos2d::TransitionZoomFlipAngular(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -41182,13 +41966,16 @@ bool js_cocos2dx_TransitionZoomFlipAngular_constructor(JSContext *cx, uint32_t a CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionZoomFlipAngular"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionZoomFlipAngular"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -41199,7 +41986,7 @@ void js_cocos2d_TransitionZoomFlipAngular_finalize(JSFreeOp *fop, JSObject *obj) CCLOGINFO("jsbindings: finalizing JS object %p (TransitionZoomFlipAngular)", obj); } -void js_register_cocos2dx_TransitionZoomFlipAngular(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionZoomFlipAngular(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionZoomFlipAngular_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionZoomFlipAngular_class->name = "TransitionZoomFlipAngular"; jsb_cocos2d_TransitionZoomFlipAngular_class->addProperty = JS_PropertyStub; @@ -41213,8 +42000,8 @@ void js_register_cocos2dx_TransitionZoomFlipAngular(JSContext *cx, JSObject *glo jsb_cocos2d_TransitionZoomFlipAngular_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -41228,7 +42015,7 @@ void js_register_cocos2dx_TransitionZoomFlipAngular(JSContext *cx, JSObject *glo jsb_cocos2d_TransitionZoomFlipAngular_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionSceneOriented_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionSceneOriented_prototype), jsb_cocos2d_TransitionZoomFlipAngular_class, js_cocos2dx_TransitionZoomFlipAngular_constructor, 0, // constructor properties, @@ -41259,25 +42046,25 @@ JSObject *jsb_cocos2d_TransitionFade_prototype; bool js_cocos2dx_TransitionFade_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TransitionFade* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TransitionFade *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionFade_initWithDuration : Invalid Native Object"); do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -41286,7 +42073,7 @@ bool js_cocos2dx_TransitionFade_initWithDuration(JSContext *cx, uint32_t argc, j bool ret = cobj->initWithDuration(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -41294,25 +42081,25 @@ bool js_cocos2dx_TransitionFade_initWithDuration(JSContext *cx, uint32_t argc, j do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::Color3B arg2; - ok &= jsval_to_cccolor3b(cx, argv[2], &arg2); + ok &= jsval_to_cccolor3b(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } bool ret = cobj->initWithDuration(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -41322,19 +42109,19 @@ bool js_cocos2dx_TransitionFade_initWithDuration(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_TransitionFade_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -41350,7 +42137,7 @@ bool js_cocos2dx_TransitionFade_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -41358,20 +42145,20 @@ bool js_cocos2dx_TransitionFade_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cocos2d::Scene* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::Color3B arg2; - ok &= jsval_to_cccolor3b(cx, argv[2], &arg2); + ok &= jsval_to_cccolor3b(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } cocos2d::TransitionFade* ret = cocos2d::TransitionFade::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -41383,7 +42170,7 @@ bool js_cocos2dx_TransitionFade_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -41392,7 +42179,7 @@ bool js_cocos2dx_TransitionFade_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TransitionFade_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionFade* cobj = new (std::nothrow) cocos2d::TransitionFade(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -41406,13 +42193,16 @@ bool js_cocos2dx_TransitionFade_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFade"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFade"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -41423,7 +42213,7 @@ void js_cocos2d_TransitionFade_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionFade)", obj); } -void js_register_cocos2dx_TransitionFade(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionFade(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionFade_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionFade_class->name = "TransitionFade"; jsb_cocos2d_TransitionFade_class->addProperty = JS_PropertyStub; @@ -41437,8 +42227,8 @@ void js_register_cocos2dx_TransitionFade(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionFade_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -41453,7 +42243,7 @@ void js_register_cocos2dx_TransitionFade(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionFade_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionScene_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionScene_prototype), jsb_cocos2d_TransitionFade_class, js_cocos2dx_TransitionFade_constructor, 0, // constructor properties, @@ -41484,16 +42274,16 @@ JSObject *jsb_cocos2d_TransitionCrossFade_prototype; bool js_cocos2dx_TransitionCrossFade_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -41509,7 +42299,7 @@ bool js_cocos2dx_TransitionCrossFade_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionCrossFade_create : wrong number of arguments"); @@ -41518,7 +42308,7 @@ bool js_cocos2dx_TransitionCrossFade_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_TransitionCrossFade_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionCrossFade* cobj = new (std::nothrow) cocos2d::TransitionCrossFade(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -41532,13 +42322,16 @@ bool js_cocos2dx_TransitionCrossFade_constructor(JSContext *cx, uint32_t argc, j CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionCrossFade"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionCrossFade"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -41549,7 +42342,7 @@ void js_cocos2d_TransitionCrossFade_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionCrossFade)", obj); } -void js_register_cocos2dx_TransitionCrossFade(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionCrossFade(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionCrossFade_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionCrossFade_class->name = "TransitionCrossFade"; jsb_cocos2d_TransitionCrossFade_class->addProperty = JS_PropertyStub; @@ -41563,8 +42356,8 @@ void js_register_cocos2dx_TransitionCrossFade(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionCrossFade_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -41578,7 +42371,7 @@ void js_register_cocos2dx_TransitionCrossFade(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionCrossFade_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionScene_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionScene_prototype), jsb_cocos2d_TransitionCrossFade_class, js_cocos2dx_TransitionCrossFade_constructor, 0, // constructor properties, @@ -41609,18 +42402,18 @@ JSObject *jsb_cocos2d_TransitionTurnOffTiles_prototype; bool js_cocos2dx_TransitionTurnOffTiles_easeActionWithAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionTurnOffTiles* cobj = (cocos2d::TransitionTurnOffTiles *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionTurnOffTiles_easeActionWithAction : Invalid Native Object"); if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -41636,7 +42429,7 @@ bool js_cocos2dx_TransitionTurnOffTiles_easeActionWithAction(JSContext *cx, uint jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -41645,16 +42438,16 @@ bool js_cocos2dx_TransitionTurnOffTiles_easeActionWithAction(JSContext *cx, uint } bool js_cocos2dx_TransitionTurnOffTiles_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -41670,7 +42463,7 @@ bool js_cocos2dx_TransitionTurnOffTiles_create(JSContext *cx, uint32_t argc, jsv jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionTurnOffTiles_create : wrong number of arguments"); @@ -41679,7 +42472,7 @@ bool js_cocos2dx_TransitionTurnOffTiles_create(JSContext *cx, uint32_t argc, jsv bool js_cocos2dx_TransitionTurnOffTiles_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionTurnOffTiles* cobj = new (std::nothrow) cocos2d::TransitionTurnOffTiles(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -41693,13 +42486,16 @@ bool js_cocos2dx_TransitionTurnOffTiles_constructor(JSContext *cx, uint32_t argc CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionTurnOffTiles"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionTurnOffTiles"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -41710,7 +42506,7 @@ void js_cocos2d_TransitionTurnOffTiles_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionTurnOffTiles)", obj); } -void js_register_cocos2dx_TransitionTurnOffTiles(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionTurnOffTiles(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionTurnOffTiles_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionTurnOffTiles_class->name = "TransitionTurnOffTiles"; jsb_cocos2d_TransitionTurnOffTiles_class->addProperty = JS_PropertyStub; @@ -41724,8 +42520,8 @@ void js_register_cocos2dx_TransitionTurnOffTiles(JSContext *cx, JSObject *global jsb_cocos2d_TransitionTurnOffTiles_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -41740,7 +42536,7 @@ void js_register_cocos2dx_TransitionTurnOffTiles(JSContext *cx, JSObject *global jsb_cocos2d_TransitionTurnOffTiles_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionScene_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionScene_prototype), jsb_cocos2d_TransitionTurnOffTiles_class, js_cocos2dx_TransitionTurnOffTiles_constructor, 0, // constructor properties, @@ -41771,7 +42567,8 @@ JSObject *jsb_cocos2d_TransitionSplitCols_prototype; bool js_cocos2dx_TransitionSplitCols_action(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionSplitCols* cobj = (cocos2d::TransitionSplitCols *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionSplitCols_action : Invalid Native Object"); @@ -41786,7 +42583,7 @@ bool js_cocos2dx_TransitionSplitCols_action(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -41795,18 +42592,18 @@ bool js_cocos2dx_TransitionSplitCols_action(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TransitionSplitCols_easeActionWithAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionSplitCols* cobj = (cocos2d::TransitionSplitCols *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionSplitCols_easeActionWithAction : Invalid Native Object"); if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -41822,7 +42619,7 @@ bool js_cocos2dx_TransitionSplitCols_easeActionWithAction(JSContext *cx, uint32_ jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -41831,16 +42628,16 @@ bool js_cocos2dx_TransitionSplitCols_easeActionWithAction(JSContext *cx, uint32_ } bool js_cocos2dx_TransitionSplitCols_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -41856,7 +42653,7 @@ bool js_cocos2dx_TransitionSplitCols_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionSplitCols_create : wrong number of arguments"); @@ -41865,7 +42662,7 @@ bool js_cocos2dx_TransitionSplitCols_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_TransitionSplitCols_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionSplitCols* cobj = new (std::nothrow) cocos2d::TransitionSplitCols(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -41879,13 +42676,16 @@ bool js_cocos2dx_TransitionSplitCols_constructor(JSContext *cx, uint32_t argc, j CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionSplitCols"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionSplitCols"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -41896,7 +42696,7 @@ void js_cocos2d_TransitionSplitCols_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionSplitCols)", obj); } -void js_register_cocos2dx_TransitionSplitCols(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionSplitCols(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionSplitCols_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionSplitCols_class->name = "TransitionSplitCols"; jsb_cocos2d_TransitionSplitCols_class->addProperty = JS_PropertyStub; @@ -41910,8 +42710,8 @@ void js_register_cocos2dx_TransitionSplitCols(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionSplitCols_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -41927,7 +42727,7 @@ void js_register_cocos2dx_TransitionSplitCols(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionSplitCols_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionScene_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionScene_prototype), jsb_cocos2d_TransitionSplitCols_class, js_cocos2dx_TransitionSplitCols_constructor, 0, // constructor properties, @@ -41958,16 +42758,16 @@ JSObject *jsb_cocos2d_TransitionSplitRows_prototype; bool js_cocos2dx_TransitionSplitRows_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -41983,7 +42783,7 @@ bool js_cocos2dx_TransitionSplitRows_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionSplitRows_create : wrong number of arguments"); @@ -41992,7 +42792,7 @@ bool js_cocos2dx_TransitionSplitRows_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_TransitionSplitRows_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionSplitRows* cobj = new (std::nothrow) cocos2d::TransitionSplitRows(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -42006,13 +42806,16 @@ bool js_cocos2dx_TransitionSplitRows_constructor(JSContext *cx, uint32_t argc, j CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionSplitRows"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionSplitRows"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -42023,7 +42826,7 @@ void js_cocos2d_TransitionSplitRows_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionSplitRows)", obj); } -void js_register_cocos2dx_TransitionSplitRows(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionSplitRows(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionSplitRows_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionSplitRows_class->name = "TransitionSplitRows"; jsb_cocos2d_TransitionSplitRows_class->addProperty = JS_PropertyStub; @@ -42037,8 +42840,8 @@ void js_register_cocos2dx_TransitionSplitRows(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionSplitRows_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -42052,7 +42855,7 @@ void js_register_cocos2dx_TransitionSplitRows(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionSplitRows_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionSplitCols_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionSplitCols_prototype), jsb_cocos2d_TransitionSplitRows_class, js_cocos2dx_TransitionSplitRows_constructor, 0, // constructor properties, @@ -42083,18 +42886,18 @@ JSObject *jsb_cocos2d_TransitionFadeTR_prototype; bool js_cocos2dx_TransitionFadeTR_easeActionWithAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionFadeTR* cobj = (cocos2d::TransitionFadeTR *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionFadeTR_easeActionWithAction : Invalid Native Object"); if (argc == 1) { cocos2d::ActionInterval* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ActionInterval*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -42110,7 +42913,7 @@ bool js_cocos2dx_TransitionFadeTR_easeActionWithAction(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -42119,15 +42922,15 @@ bool js_cocos2dx_TransitionFadeTR_easeActionWithAction(JSContext *cx, uint32_t a } bool js_cocos2dx_TransitionFadeTR_actionWithSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionFadeTR* cobj = (cocos2d::TransitionFadeTR *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionFadeTR_actionWithSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TransitionFadeTR_actionWithSize : Error processing arguments"); cocos2d::ActionInterval* ret = cobj->actionWithSize(arg0); jsval jsret = JSVAL_NULL; @@ -42139,7 +42942,7 @@ bool js_cocos2dx_TransitionFadeTR_actionWithSize(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -42148,16 +42951,16 @@ bool js_cocos2dx_TransitionFadeTR_actionWithSize(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_TransitionFadeTR_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -42173,7 +42976,7 @@ bool js_cocos2dx_TransitionFadeTR_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionFadeTR_create : wrong number of arguments"); @@ -42182,7 +42985,7 @@ bool js_cocos2dx_TransitionFadeTR_create(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_TransitionFadeTR_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionFadeTR* cobj = new (std::nothrow) cocos2d::TransitionFadeTR(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -42196,13 +42999,16 @@ bool js_cocos2dx_TransitionFadeTR_constructor(JSContext *cx, uint32_t argc, jsva CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFadeTR"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFadeTR"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -42213,7 +43019,7 @@ void js_cocos2d_TransitionFadeTR_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionFadeTR)", obj); } -void js_register_cocos2dx_TransitionFadeTR(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionFadeTR(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionFadeTR_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionFadeTR_class->name = "TransitionFadeTR"; jsb_cocos2d_TransitionFadeTR_class->addProperty = JS_PropertyStub; @@ -42227,8 +43033,8 @@ void js_register_cocos2dx_TransitionFadeTR(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionFadeTR_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -42244,7 +43050,7 @@ void js_register_cocos2dx_TransitionFadeTR(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionFadeTR_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionScene_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionScene_prototype), jsb_cocos2d_TransitionFadeTR_class, js_cocos2dx_TransitionFadeTR_constructor, 0, // constructor properties, @@ -42275,16 +43081,16 @@ JSObject *jsb_cocos2d_TransitionFadeBL_prototype; bool js_cocos2dx_TransitionFadeBL_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -42300,7 +43106,7 @@ bool js_cocos2dx_TransitionFadeBL_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionFadeBL_create : wrong number of arguments"); @@ -42309,7 +43115,7 @@ bool js_cocos2dx_TransitionFadeBL_create(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_TransitionFadeBL_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionFadeBL* cobj = new (std::nothrow) cocos2d::TransitionFadeBL(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -42323,13 +43129,16 @@ bool js_cocos2dx_TransitionFadeBL_constructor(JSContext *cx, uint32_t argc, jsva CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFadeBL"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFadeBL"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -42340,7 +43149,7 @@ void js_cocos2d_TransitionFadeBL_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionFadeBL)", obj); } -void js_register_cocos2dx_TransitionFadeBL(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionFadeBL(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionFadeBL_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionFadeBL_class->name = "TransitionFadeBL"; jsb_cocos2d_TransitionFadeBL_class->addProperty = JS_PropertyStub; @@ -42354,8 +43163,8 @@ void js_register_cocos2dx_TransitionFadeBL(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionFadeBL_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -42369,7 +43178,7 @@ void js_register_cocos2dx_TransitionFadeBL(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionFadeBL_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionFadeTR_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionFadeTR_prototype), jsb_cocos2d_TransitionFadeBL_class, js_cocos2dx_TransitionFadeBL_constructor, 0, // constructor properties, @@ -42400,16 +43209,16 @@ JSObject *jsb_cocos2d_TransitionFadeUp_prototype; bool js_cocos2dx_TransitionFadeUp_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -42425,7 +43234,7 @@ bool js_cocos2dx_TransitionFadeUp_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionFadeUp_create : wrong number of arguments"); @@ -42434,7 +43243,7 @@ bool js_cocos2dx_TransitionFadeUp_create(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_TransitionFadeUp_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionFadeUp* cobj = new (std::nothrow) cocos2d::TransitionFadeUp(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -42448,13 +43257,16 @@ bool js_cocos2dx_TransitionFadeUp_constructor(JSContext *cx, uint32_t argc, jsva CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFadeUp"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFadeUp"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -42465,7 +43277,7 @@ void js_cocos2d_TransitionFadeUp_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionFadeUp)", obj); } -void js_register_cocos2dx_TransitionFadeUp(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionFadeUp(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionFadeUp_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionFadeUp_class->name = "TransitionFadeUp"; jsb_cocos2d_TransitionFadeUp_class->addProperty = JS_PropertyStub; @@ -42479,8 +43291,8 @@ void js_register_cocos2dx_TransitionFadeUp(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionFadeUp_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -42494,7 +43306,7 @@ void js_register_cocos2dx_TransitionFadeUp(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionFadeUp_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionFadeTR_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionFadeTR_prototype), jsb_cocos2d_TransitionFadeUp_class, js_cocos2dx_TransitionFadeUp_constructor, 0, // constructor properties, @@ -42525,16 +43337,16 @@ JSObject *jsb_cocos2d_TransitionFadeDown_prototype; bool js_cocos2dx_TransitionFadeDown_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -42550,7 +43362,7 @@ bool js_cocos2dx_TransitionFadeDown_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionFadeDown_create : wrong number of arguments"); @@ -42559,7 +43371,7 @@ bool js_cocos2dx_TransitionFadeDown_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_TransitionFadeDown_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionFadeDown* cobj = new (std::nothrow) cocos2d::TransitionFadeDown(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -42573,13 +43385,16 @@ bool js_cocos2dx_TransitionFadeDown_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFadeDown"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionFadeDown"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -42590,7 +43405,7 @@ void js_cocos2d_TransitionFadeDown_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionFadeDown)", obj); } -void js_register_cocos2dx_TransitionFadeDown(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionFadeDown(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionFadeDown_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionFadeDown_class->name = "TransitionFadeDown"; jsb_cocos2d_TransitionFadeDown_class->addProperty = JS_PropertyStub; @@ -42604,8 +43419,8 @@ void js_register_cocos2dx_TransitionFadeDown(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionFadeDown_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -42619,7 +43434,7 @@ void js_register_cocos2dx_TransitionFadeDown(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionFadeDown_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionFadeTR_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionFadeTR_prototype), jsb_cocos2d_TransitionFadeDown_class, js_cocos2dx_TransitionFadeDown_constructor, 0, // constructor properties, @@ -42650,15 +43465,15 @@ JSObject *jsb_cocos2d_TransitionPageTurn_prototype; bool js_cocos2dx_TransitionPageTurn_actionWithSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionPageTurn* cobj = (cocos2d::TransitionPageTurn *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionPageTurn_actionWithSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TransitionPageTurn_actionWithSize : Error processing arguments"); cocos2d::ActionInterval* ret = cobj->actionWithSize(arg0); jsval jsret = JSVAL_NULL; @@ -42670,7 +43485,7 @@ bool js_cocos2dx_TransitionPageTurn_actionWithSize(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -42679,9 +43494,9 @@ bool js_cocos2dx_TransitionPageTurn_actionWithSize(JSContext *cx, uint32_t argc, } bool js_cocos2dx_TransitionPageTurn_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TransitionPageTurn* cobj = (cocos2d::TransitionPageTurn *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TransitionPageTurn_initWithDuration : Invalid Native Object"); @@ -42689,21 +43504,21 @@ bool js_cocos2dx_TransitionPageTurn_initWithDuration(JSContext *cx, uint32_t arg double arg0; cocos2d::Scene* arg1; bool arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(args.get(2)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TransitionPageTurn_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -42712,22 +43527,22 @@ bool js_cocos2dx_TransitionPageTurn_initWithDuration(JSContext *cx, uint32_t arg } bool js_cocos2dx_TransitionPageTurn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 3) { double arg0; cocos2d::Scene* arg1; bool arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(args.get(2)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TransitionPageTurn_create : Error processing arguments"); cocos2d::TransitionPageTurn* ret = cocos2d::TransitionPageTurn::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -42739,7 +43554,7 @@ bool js_cocos2dx_TransitionPageTurn_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionPageTurn_create : wrong number of arguments"); @@ -42748,7 +43563,7 @@ bool js_cocos2dx_TransitionPageTurn_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_TransitionPageTurn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionPageTurn* cobj = new (std::nothrow) cocos2d::TransitionPageTurn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -42762,13 +43577,16 @@ bool js_cocos2dx_TransitionPageTurn_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionPageTurn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionPageTurn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -42779,7 +43597,7 @@ void js_cocos2d_TransitionPageTurn_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionPageTurn)", obj); } -void js_register_cocos2dx_TransitionPageTurn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionPageTurn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionPageTurn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionPageTurn_class->name = "TransitionPageTurn"; jsb_cocos2d_TransitionPageTurn_class->addProperty = JS_PropertyStub; @@ -42793,8 +43611,8 @@ void js_register_cocos2dx_TransitionPageTurn(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionPageTurn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -42810,7 +43628,7 @@ void js_register_cocos2dx_TransitionPageTurn(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionPageTurn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionScene_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionScene_prototype), jsb_cocos2d_TransitionPageTurn_class, js_cocos2dx_TransitionPageTurn_constructor, 0, // constructor properties, @@ -42841,16 +43659,16 @@ JSObject *jsb_cocos2d_TransitionProgress_prototype; bool js_cocos2dx_TransitionProgress_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -42866,7 +43684,7 @@ bool js_cocos2dx_TransitionProgress_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionProgress_create : wrong number of arguments"); @@ -42875,7 +43693,7 @@ bool js_cocos2dx_TransitionProgress_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_TransitionProgress_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionProgress* cobj = new (std::nothrow) cocos2d::TransitionProgress(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -42889,13 +43707,16 @@ bool js_cocos2dx_TransitionProgress_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionProgress"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionProgress"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -42906,7 +43727,7 @@ void js_cocos2d_TransitionProgress_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionProgress)", obj); } -void js_register_cocos2dx_TransitionProgress(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionProgress(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionProgress_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionProgress_class->name = "TransitionProgress"; jsb_cocos2d_TransitionProgress_class->addProperty = JS_PropertyStub; @@ -42920,8 +43741,8 @@ void js_register_cocos2dx_TransitionProgress(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionProgress_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -42935,7 +43756,7 @@ void js_register_cocos2dx_TransitionProgress(JSContext *cx, JSObject *global) { jsb_cocos2d_TransitionProgress_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionScene_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionScene_prototype), jsb_cocos2d_TransitionProgress_class, js_cocos2dx_TransitionProgress_constructor, 0, // constructor properties, @@ -42966,16 +43787,16 @@ JSObject *jsb_cocos2d_TransitionProgressRadialCCW_prototype; bool js_cocos2dx_TransitionProgressRadialCCW_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -42991,7 +43812,7 @@ bool js_cocos2dx_TransitionProgressRadialCCW_create(JSContext *cx, uint32_t argc jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionProgressRadialCCW_create : wrong number of arguments"); @@ -43000,7 +43821,7 @@ bool js_cocos2dx_TransitionProgressRadialCCW_create(JSContext *cx, uint32_t argc bool js_cocos2dx_TransitionProgressRadialCCW_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionProgressRadialCCW* cobj = new (std::nothrow) cocos2d::TransitionProgressRadialCCW(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -43014,13 +43835,16 @@ bool js_cocos2dx_TransitionProgressRadialCCW_constructor(JSContext *cx, uint32_t CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionProgressRadialCCW"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionProgressRadialCCW"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -43031,7 +43855,7 @@ void js_cocos2d_TransitionProgressRadialCCW_finalize(JSFreeOp *fop, JSObject *ob CCLOGINFO("jsbindings: finalizing JS object %p (TransitionProgressRadialCCW)", obj); } -void js_register_cocos2dx_TransitionProgressRadialCCW(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionProgressRadialCCW(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionProgressRadialCCW_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionProgressRadialCCW_class->name = "TransitionProgressRadialCCW"; jsb_cocos2d_TransitionProgressRadialCCW_class->addProperty = JS_PropertyStub; @@ -43045,8 +43869,8 @@ void js_register_cocos2dx_TransitionProgressRadialCCW(JSContext *cx, JSObject *g jsb_cocos2d_TransitionProgressRadialCCW_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -43060,7 +43884,7 @@ void js_register_cocos2dx_TransitionProgressRadialCCW(JSContext *cx, JSObject *g jsb_cocos2d_TransitionProgressRadialCCW_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionProgress_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionProgress_prototype), jsb_cocos2d_TransitionProgressRadialCCW_class, js_cocos2dx_TransitionProgressRadialCCW_constructor, 0, // constructor properties, @@ -43091,16 +43915,16 @@ JSObject *jsb_cocos2d_TransitionProgressRadialCW_prototype; bool js_cocos2dx_TransitionProgressRadialCW_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -43116,7 +43940,7 @@ bool js_cocos2dx_TransitionProgressRadialCW_create(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionProgressRadialCW_create : wrong number of arguments"); @@ -43125,7 +43949,7 @@ bool js_cocos2dx_TransitionProgressRadialCW_create(JSContext *cx, uint32_t argc, bool js_cocos2dx_TransitionProgressRadialCW_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionProgressRadialCW* cobj = new (std::nothrow) cocos2d::TransitionProgressRadialCW(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -43139,13 +43963,16 @@ bool js_cocos2dx_TransitionProgressRadialCW_constructor(JSContext *cx, uint32_t CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionProgressRadialCW"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionProgressRadialCW"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -43156,7 +43983,7 @@ void js_cocos2d_TransitionProgressRadialCW_finalize(JSFreeOp *fop, JSObject *obj CCLOGINFO("jsbindings: finalizing JS object %p (TransitionProgressRadialCW)", obj); } -void js_register_cocos2dx_TransitionProgressRadialCW(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionProgressRadialCW(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionProgressRadialCW_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionProgressRadialCW_class->name = "TransitionProgressRadialCW"; jsb_cocos2d_TransitionProgressRadialCW_class->addProperty = JS_PropertyStub; @@ -43170,8 +43997,8 @@ void js_register_cocos2dx_TransitionProgressRadialCW(JSContext *cx, JSObject *gl jsb_cocos2d_TransitionProgressRadialCW_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -43185,7 +44012,7 @@ void js_register_cocos2dx_TransitionProgressRadialCW(JSContext *cx, JSObject *gl jsb_cocos2d_TransitionProgressRadialCW_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionProgress_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionProgress_prototype), jsb_cocos2d_TransitionProgressRadialCW_class, js_cocos2dx_TransitionProgressRadialCW_constructor, 0, // constructor properties, @@ -43216,16 +44043,16 @@ JSObject *jsb_cocos2d_TransitionProgressHorizontal_prototype; bool js_cocos2dx_TransitionProgressHorizontal_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -43241,7 +44068,7 @@ bool js_cocos2dx_TransitionProgressHorizontal_create(JSContext *cx, uint32_t arg jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionProgressHorizontal_create : wrong number of arguments"); @@ -43250,7 +44077,7 @@ bool js_cocos2dx_TransitionProgressHorizontal_create(JSContext *cx, uint32_t arg bool js_cocos2dx_TransitionProgressHorizontal_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionProgressHorizontal* cobj = new (std::nothrow) cocos2d::TransitionProgressHorizontal(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -43264,13 +44091,16 @@ bool js_cocos2dx_TransitionProgressHorizontal_constructor(JSContext *cx, uint32_ CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionProgressHorizontal"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionProgressHorizontal"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -43281,7 +44111,7 @@ void js_cocos2d_TransitionProgressHorizontal_finalize(JSFreeOp *fop, JSObject *o CCLOGINFO("jsbindings: finalizing JS object %p (TransitionProgressHorizontal)", obj); } -void js_register_cocos2dx_TransitionProgressHorizontal(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionProgressHorizontal(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionProgressHorizontal_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionProgressHorizontal_class->name = "TransitionProgressHorizontal"; jsb_cocos2d_TransitionProgressHorizontal_class->addProperty = JS_PropertyStub; @@ -43295,8 +44125,8 @@ void js_register_cocos2dx_TransitionProgressHorizontal(JSContext *cx, JSObject * jsb_cocos2d_TransitionProgressHorizontal_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -43310,7 +44140,7 @@ void js_register_cocos2dx_TransitionProgressHorizontal(JSContext *cx, JSObject * jsb_cocos2d_TransitionProgressHorizontal_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionProgress_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionProgress_prototype), jsb_cocos2d_TransitionProgressHorizontal_class, js_cocos2dx_TransitionProgressHorizontal_constructor, 0, // constructor properties, @@ -43341,16 +44171,16 @@ JSObject *jsb_cocos2d_TransitionProgressVertical_prototype; bool js_cocos2dx_TransitionProgressVertical_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -43366,7 +44196,7 @@ bool js_cocos2dx_TransitionProgressVertical_create(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionProgressVertical_create : wrong number of arguments"); @@ -43375,7 +44205,7 @@ bool js_cocos2dx_TransitionProgressVertical_create(JSContext *cx, uint32_t argc, bool js_cocos2dx_TransitionProgressVertical_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionProgressVertical* cobj = new (std::nothrow) cocos2d::TransitionProgressVertical(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -43389,13 +44219,16 @@ bool js_cocos2dx_TransitionProgressVertical_constructor(JSContext *cx, uint32_t CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionProgressVertical"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionProgressVertical"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -43406,7 +44239,7 @@ void js_cocos2d_TransitionProgressVertical_finalize(JSFreeOp *fop, JSObject *obj CCLOGINFO("jsbindings: finalizing JS object %p (TransitionProgressVertical)", obj); } -void js_register_cocos2dx_TransitionProgressVertical(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionProgressVertical(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionProgressVertical_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionProgressVertical_class->name = "TransitionProgressVertical"; jsb_cocos2d_TransitionProgressVertical_class->addProperty = JS_PropertyStub; @@ -43420,8 +44253,8 @@ void js_register_cocos2dx_TransitionProgressVertical(JSContext *cx, JSObject *gl jsb_cocos2d_TransitionProgressVertical_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -43435,7 +44268,7 @@ void js_register_cocos2dx_TransitionProgressVertical(JSContext *cx, JSObject *gl jsb_cocos2d_TransitionProgressVertical_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionProgress_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionProgress_prototype), jsb_cocos2d_TransitionProgressVertical_class, js_cocos2dx_TransitionProgressVertical_constructor, 0, // constructor properties, @@ -43466,16 +44299,16 @@ JSObject *jsb_cocos2d_TransitionProgressInOut_prototype; bool js_cocos2dx_TransitionProgressInOut_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -43491,7 +44324,7 @@ bool js_cocos2dx_TransitionProgressInOut_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionProgressInOut_create : wrong number of arguments"); @@ -43500,7 +44333,7 @@ bool js_cocos2dx_TransitionProgressInOut_create(JSContext *cx, uint32_t argc, js bool js_cocos2dx_TransitionProgressInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionProgressInOut* cobj = new (std::nothrow) cocos2d::TransitionProgressInOut(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -43514,13 +44347,16 @@ bool js_cocos2dx_TransitionProgressInOut_constructor(JSContext *cx, uint32_t arg CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionProgressInOut"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionProgressInOut"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -43531,7 +44367,7 @@ void js_cocos2d_TransitionProgressInOut_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionProgressInOut)", obj); } -void js_register_cocos2dx_TransitionProgressInOut(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionProgressInOut(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionProgressInOut_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionProgressInOut_class->name = "TransitionProgressInOut"; jsb_cocos2d_TransitionProgressInOut_class->addProperty = JS_PropertyStub; @@ -43545,8 +44381,8 @@ void js_register_cocos2dx_TransitionProgressInOut(JSContext *cx, JSObject *globa jsb_cocos2d_TransitionProgressInOut_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -43560,7 +44396,7 @@ void js_register_cocos2dx_TransitionProgressInOut(JSContext *cx, JSObject *globa jsb_cocos2d_TransitionProgressInOut_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionProgress_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionProgress_prototype), jsb_cocos2d_TransitionProgressInOut_class, js_cocos2dx_TransitionProgressInOut_constructor, 0, // constructor properties, @@ -43591,16 +44427,16 @@ JSObject *jsb_cocos2d_TransitionProgressOutIn_prototype; bool js_cocos2dx_TransitionProgressOutIn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double arg0; cocos2d::Scene* arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -43616,7 +44452,7 @@ bool js_cocos2dx_TransitionProgressOutIn_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TransitionProgressOutIn_create : wrong number of arguments"); @@ -43625,7 +44461,7 @@ bool js_cocos2dx_TransitionProgressOutIn_create(JSContext *cx, uint32_t argc, js bool js_cocos2dx_TransitionProgressOutIn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TransitionProgressOutIn* cobj = new (std::nothrow) cocos2d::TransitionProgressOutIn(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -43639,13 +44475,16 @@ bool js_cocos2dx_TransitionProgressOutIn_constructor(JSContext *cx, uint32_t arg CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionProgressOutIn"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TransitionProgressOutIn"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -43656,7 +44495,7 @@ void js_cocos2d_TransitionProgressOutIn_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TransitionProgressOutIn)", obj); } -void js_register_cocos2dx_TransitionProgressOutIn(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TransitionProgressOutIn(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TransitionProgressOutIn_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TransitionProgressOutIn_class->name = "TransitionProgressOutIn"; jsb_cocos2d_TransitionProgressOutIn_class->addProperty = JS_PropertyStub; @@ -43670,8 +44509,8 @@ void js_register_cocos2dx_TransitionProgressOutIn(JSContext *cx, JSObject *globa jsb_cocos2d_TransitionProgressOutIn_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -43685,7 +44524,7 @@ void js_register_cocos2dx_TransitionProgressOutIn(JSContext *cx, JSObject *globa jsb_cocos2d_TransitionProgressOutIn_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TransitionProgress_prototype, + JS::RootedObject(cx, jsb_cocos2d_TransitionProgress_prototype), jsb_cocos2d_TransitionProgressOutIn_class, js_cocos2dx_TransitionProgressOutIn_constructor, 0, // constructor properties, @@ -43716,18 +44555,18 @@ JSObject *jsb_cocos2d_MenuItem_prototype; bool js_cocos2dx_MenuItem_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItem* cobj = (cocos2d::MenuItem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItem_setEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItem_setEnabled : Error processing arguments"); cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -43736,13 +44575,14 @@ bool js_cocos2dx_MenuItem_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_MenuItem_activate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItem* cobj = (cocos2d::MenuItem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItem_activate : Invalid Native Object"); if (argc == 0) { cobj->activate(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -43751,19 +44591,20 @@ bool js_cocos2dx_MenuItem_activate(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_MenuItem_initWithCallback(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItem* cobj = (cocos2d::MenuItem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItem_initWithCallback : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=](cocos2d::Ref* larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -43773,8 +44614,8 @@ bool js_cocos2dx_MenuItem_initWithCallback(JSContext *cx, uint32_t argc, jsval * largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -43791,7 +44632,7 @@ bool js_cocos2dx_MenuItem_initWithCallback(JSContext *cx, uint32_t argc, jsval * bool ret = cobj->initWithCallback(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -43800,7 +44641,8 @@ bool js_cocos2dx_MenuItem_initWithCallback(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_MenuItem_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItem* cobj = (cocos2d::MenuItem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItem_isEnabled : Invalid Native Object"); @@ -43808,7 +44650,7 @@ bool js_cocos2dx_MenuItem_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -43817,13 +44659,14 @@ bool js_cocos2dx_MenuItem_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_MenuItem_selected(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItem* cobj = (cocos2d::MenuItem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItem_selected : Invalid Native Object"); if (argc == 0) { cobj->selected(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -43832,7 +44675,8 @@ bool js_cocos2dx_MenuItem_selected(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_MenuItem_isSelected(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItem* cobj = (cocos2d::MenuItem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItem_isSelected : Invalid Native Object"); @@ -43840,7 +44684,7 @@ bool js_cocos2dx_MenuItem_isSelected(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isSelected(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -43849,13 +44693,14 @@ bool js_cocos2dx_MenuItem_isSelected(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_MenuItem_unselected(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItem* cobj = (cocos2d::MenuItem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItem_unselected : Invalid Native Object"); if (argc == 0) { cobj->unselected(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -43864,7 +44709,8 @@ bool js_cocos2dx_MenuItem_unselected(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_MenuItem_rect(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItem* cobj = (cocos2d::MenuItem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItem_rect : Invalid Native Object"); @@ -43872,7 +44718,7 @@ bool js_cocos2dx_MenuItem_rect(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Rect ret = cobj->rect(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -43881,7 +44727,7 @@ bool js_cocos2dx_MenuItem_rect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_MenuItem_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::MenuItem* cobj = new (std::nothrow) cocos2d::MenuItem(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -43895,13 +44741,16 @@ bool js_cocos2dx_MenuItem_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItem"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItem"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -43914,21 +44763,21 @@ void js_cocos2d_MenuItem_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_MenuItem_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::MenuItem *nobj = new (std::nothrow) cocos2d::MenuItem(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItem"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItem"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_MenuItem(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_MenuItem(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_MenuItem_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_MenuItem_class->name = "MenuItem"; jsb_cocos2d_MenuItem_class->addProperty = JS_PropertyStub; @@ -43942,8 +44791,8 @@ void js_register_cocos2dx_MenuItem(JSContext *cx, JSObject *global) { jsb_cocos2d_MenuItem_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -43963,7 +44812,7 @@ void js_register_cocos2dx_MenuItem(JSContext *cx, JSObject *global) { jsb_cocos2d_MenuItem_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_MenuItem_class, js_cocos2dx_MenuItem_constructor, 0, // constructor properties, @@ -43994,25 +44843,25 @@ JSObject *jsb_cocos2d_MenuItemLabel_prototype; bool js_cocos2dx_MenuItemLabel_setLabel(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemLabel* cobj = (cocos2d::MenuItemLabel *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemLabel_setLabel : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemLabel_setLabel : Error processing arguments"); cobj->setLabel(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -44021,7 +44870,8 @@ bool js_cocos2dx_MenuItemLabel_setLabel(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_MenuItemLabel_getDisabledColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemLabel* cobj = (cocos2d::MenuItemLabel *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemLabel_getDisabledColor : Invalid Native Object"); @@ -44029,7 +44879,7 @@ bool js_cocos2dx_MenuItemLabel_getDisabledColor(JSContext *cx, uint32_t argc, js const cocos2d::Color3B& ret = cobj->getDisabledColor(); jsval jsret = JSVAL_NULL; jsret = cccolor3b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -44038,18 +44888,18 @@ bool js_cocos2dx_MenuItemLabel_getDisabledColor(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_MenuItemLabel_setString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemLabel* cobj = (cocos2d::MenuItemLabel *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemLabel_setString : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemLabel_setString : Error processing arguments"); cobj->setString(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -44058,9 +44908,9 @@ bool js_cocos2dx_MenuItemLabel_setString(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_MenuItemLabel_initWithLabel(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemLabel* cobj = (cocos2d::MenuItemLabel *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemLabel_initWithLabel : Invalid Native Object"); @@ -44068,18 +44918,19 @@ bool js_cocos2dx_MenuItemLabel_initWithLabel(JSContext *cx, uint32_t argc, jsval cocos2d::Node* arg0; std::function arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](cocos2d::Ref* larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -44089,8 +44940,8 @@ bool js_cocos2dx_MenuItemLabel_initWithLabel(JSContext *cx, uint32_t argc, jsval largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -44107,7 +44958,7 @@ bool js_cocos2dx_MenuItemLabel_initWithLabel(JSContext *cx, uint32_t argc, jsval bool ret = cobj->initWithLabel(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -44116,18 +44967,18 @@ bool js_cocos2dx_MenuItemLabel_initWithLabel(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_MenuItemLabel_setDisabledColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemLabel* cobj = (cocos2d::MenuItemLabel *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemLabel_setDisabledColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemLabel_setDisabledColor : Error processing arguments"); cobj->setDisabledColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -44136,7 +44987,8 @@ bool js_cocos2dx_MenuItemLabel_setDisabledColor(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_MenuItemLabel_getLabel(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemLabel* cobj = (cocos2d::MenuItemLabel *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemLabel_getLabel : Invalid Native Object"); @@ -44151,7 +45003,7 @@ bool js_cocos2dx_MenuItemLabel_getLabel(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -44160,7 +45012,7 @@ bool js_cocos2dx_MenuItemLabel_getLabel(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_MenuItemLabel_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::MenuItemLabel* cobj = new (std::nothrow) cocos2d::MenuItemLabel(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -44174,13 +45026,16 @@ bool js_cocos2dx_MenuItemLabel_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemLabel"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemLabel"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -44193,21 +45048,21 @@ void js_cocos2d_MenuItemLabel_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_MenuItemLabel_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::MenuItemLabel *nobj = new (std::nothrow) cocos2d::MenuItemLabel(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemLabel"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemLabel"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_MenuItemLabel(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_MenuItemLabel(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_MenuItemLabel_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_MenuItemLabel_class->name = "MenuItemLabel"; jsb_cocos2d_MenuItemLabel_class->addProperty = JS_PropertyStub; @@ -44221,8 +45076,8 @@ void js_register_cocos2dx_MenuItemLabel(JSContext *cx, JSObject *global) { jsb_cocos2d_MenuItemLabel_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -44240,7 +45095,7 @@ void js_register_cocos2dx_MenuItemLabel(JSContext *cx, JSObject *global) { jsb_cocos2d_MenuItemLabel_prototype = JS_InitClass( cx, global, - jsb_cocos2d_MenuItem_prototype, + JS::RootedObject(cx, jsb_cocos2d_MenuItem_prototype), jsb_cocos2d_MenuItemLabel_class, js_cocos2dx_MenuItemLabel_constructor, 0, // constructor properties, @@ -44271,9 +45126,9 @@ JSObject *jsb_cocos2d_MenuItemAtlasFont_prototype; bool js_cocos2dx_MenuItemAtlasFont_initWithString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemAtlasFont* cobj = (cocos2d::MenuItemAtlasFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemAtlasFont_initWithString : Invalid Native Object"); @@ -44284,16 +45139,17 @@ bool js_cocos2dx_MenuItemAtlasFont_initWithString(JSContext *cx, uint32_t argc, int arg3; int32_t arg4; std::function arg5; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); - ok &= jsval_to_int32(cx, argv[4], &arg4); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(4), &arg4); do { - if(JS_TypeOfValue(cx, argv[5]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(5)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[5])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(5))); auto lambda = [=](cocos2d::Ref* larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -44303,8 +45159,8 @@ bool js_cocos2dx_MenuItemAtlasFont_initWithString(JSContext *cx, uint32_t argc, largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -44321,7 +45177,7 @@ bool js_cocos2dx_MenuItemAtlasFont_initWithString(JSContext *cx, uint32_t argc, bool ret = cobj->initWithString(arg0, arg1, arg2, arg3, arg4, arg5); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -44330,7 +45186,7 @@ bool js_cocos2dx_MenuItemAtlasFont_initWithString(JSContext *cx, uint32_t argc, } bool js_cocos2dx_MenuItemAtlasFont_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::MenuItemAtlasFont* cobj = new (std::nothrow) cocos2d::MenuItemAtlasFont(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -44344,13 +45200,16 @@ bool js_cocos2dx_MenuItemAtlasFont_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemAtlasFont"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemAtlasFont"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -44363,21 +45222,21 @@ void js_cocos2d_MenuItemAtlasFont_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_MenuItemAtlasFont_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::MenuItemAtlasFont *nobj = new (std::nothrow) cocos2d::MenuItemAtlasFont(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemAtlasFont"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemAtlasFont"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_MenuItemAtlasFont(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_MenuItemAtlasFont(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_MenuItemAtlasFont_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_MenuItemAtlasFont_class->name = "MenuItemAtlasFont"; jsb_cocos2d_MenuItemAtlasFont_class->addProperty = JS_PropertyStub; @@ -44391,8 +45250,8 @@ void js_register_cocos2dx_MenuItemAtlasFont(JSContext *cx, JSObject *global) { jsb_cocos2d_MenuItemAtlasFont_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -44405,7 +45264,7 @@ void js_register_cocos2dx_MenuItemAtlasFont(JSContext *cx, JSObject *global) { jsb_cocos2d_MenuItemAtlasFont_prototype = JS_InitClass( cx, global, - jsb_cocos2d_MenuItemLabel_prototype, + JS::RootedObject(cx, jsb_cocos2d_MenuItemLabel_prototype), jsb_cocos2d_MenuItemAtlasFont_class, js_cocos2dx_MenuItemAtlasFont_constructor, 0, // constructor properties, @@ -44436,18 +45295,18 @@ JSObject *jsb_cocos2d_MenuItemFont_prototype; bool js_cocos2dx_MenuItemFont_setFontNameObj(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemFont* cobj = (cocos2d::MenuItemFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemFont_setFontNameObj : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemFont_setFontNameObj : Error processing arguments"); cobj->setFontNameObj(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -44456,7 +45315,8 @@ bool js_cocos2dx_MenuItemFont_setFontNameObj(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_MenuItemFont_getFontSizeObj(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemFont* cobj = (cocos2d::MenuItemFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemFont_getFontSizeObj : Invalid Native Object"); @@ -44464,7 +45324,7 @@ bool js_cocos2dx_MenuItemFont_getFontSizeObj(JSContext *cx, uint32_t argc, jsval int ret = cobj->getFontSizeObj(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -44473,18 +45333,18 @@ bool js_cocos2dx_MenuItemFont_getFontSizeObj(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_MenuItemFont_setFontSizeObj(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemFont* cobj = (cocos2d::MenuItemFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemFont_setFontSizeObj : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemFont_setFontSizeObj : Error processing arguments"); cobj->setFontSizeObj(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -44493,21 +45353,22 @@ bool js_cocos2dx_MenuItemFont_setFontSizeObj(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_MenuItemFont_initWithString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemFont* cobj = (cocos2d::MenuItemFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemFont_initWithString : Invalid Native Object"); if (argc == 2) { std::string arg0; std::function arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](cocos2d::Ref* larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -44517,8 +45378,8 @@ bool js_cocos2dx_MenuItemFont_initWithString(JSContext *cx, uint32_t argc, jsval largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -44535,7 +45396,7 @@ bool js_cocos2dx_MenuItemFont_initWithString(JSContext *cx, uint32_t argc, jsval bool ret = cobj->initWithString(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -44544,7 +45405,8 @@ bool js_cocos2dx_MenuItemFont_initWithString(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_MenuItemFont_getFontNameObj(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemFont* cobj = (cocos2d::MenuItemFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemFont_getFontNameObj : Invalid Native Object"); @@ -44552,7 +45414,7 @@ bool js_cocos2dx_MenuItemFont_getFontNameObj(JSContext *cx, uint32_t argc, jsval const std::string& ret = cobj->getFontNameObj(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -44561,14 +45423,14 @@ bool js_cocos2dx_MenuItemFont_getFontNameObj(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_MenuItemFont_setFontName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemFont_setFontName : Error processing arguments"); cocos2d::MenuItemFont::setFontName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_MenuItemFont_setFontName : wrong number of arguments"); @@ -44577,11 +45439,12 @@ bool js_cocos2dx_MenuItemFont_setFontName(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_MenuItemFont_getFontSize(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { int ret = cocos2d::MenuItemFont::getFontSize(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_MenuItemFont_getFontSize : wrong number of arguments"); @@ -44590,11 +45453,12 @@ bool js_cocos2dx_MenuItemFont_getFontSize(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_MenuItemFont_getFontName(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { const std::string& ret = cocos2d::MenuItemFont::getFontName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_MenuItemFont_getFontName : wrong number of arguments"); @@ -44603,14 +45467,14 @@ bool js_cocos2dx_MenuItemFont_getFontName(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_MenuItemFont_setFontSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemFont_setFontSize : Error processing arguments"); cocos2d::MenuItemFont::setFontSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_MenuItemFont_setFontSize : wrong number of arguments"); @@ -44619,7 +45483,7 @@ bool js_cocos2dx_MenuItemFont_setFontSize(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_MenuItemFont_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::MenuItemFont* cobj = new (std::nothrow) cocos2d::MenuItemFont(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -44633,13 +45497,16 @@ bool js_cocos2dx_MenuItemFont_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemFont"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemFont"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -44652,21 +45519,21 @@ void js_cocos2d_MenuItemFont_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_MenuItemFont_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::MenuItemFont *nobj = new (std::nothrow) cocos2d::MenuItemFont(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemFont"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemFont"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_MenuItemFont(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_MenuItemFont(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_MenuItemFont_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_MenuItemFont_class->name = "MenuItemFont"; jsb_cocos2d_MenuItemFont_class->addProperty = JS_PropertyStub; @@ -44680,8 +45547,8 @@ void js_register_cocos2dx_MenuItemFont(JSContext *cx, JSObject *global) { jsb_cocos2d_MenuItemFont_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -44704,7 +45571,7 @@ void js_register_cocos2dx_MenuItemFont(JSContext *cx, JSObject *global) { jsb_cocos2d_MenuItemFont_prototype = JS_InitClass( cx, global, - jsb_cocos2d_MenuItemLabel_prototype, + JS::RootedObject(cx, jsb_cocos2d_MenuItemLabel_prototype), jsb_cocos2d_MenuItemFont_class, js_cocos2dx_MenuItemFont_constructor, 0, // constructor properties, @@ -44735,18 +45602,18 @@ JSObject *jsb_cocos2d_MenuItemSprite_prototype; bool js_cocos2dx_MenuItemSprite_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemSprite* cobj = (cocos2d::MenuItemSprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemSprite_setEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemSprite_setEnabled : Error processing arguments"); cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -44755,13 +45622,14 @@ bool js_cocos2dx_MenuItemSprite_setEnabled(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_MenuItemSprite_selected(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemSprite* cobj = (cocos2d::MenuItemSprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemSprite_selected : Invalid Native Object"); if (argc == 0) { cobj->selected(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -44770,25 +45638,25 @@ bool js_cocos2dx_MenuItemSprite_selected(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_MenuItemSprite_setNormalImage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemSprite* cobj = (cocos2d::MenuItemSprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemSprite_setNormalImage : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemSprite_setNormalImage : Error processing arguments"); cobj->setNormalImage(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -44797,25 +45665,25 @@ bool js_cocos2dx_MenuItemSprite_setNormalImage(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_MenuItemSprite_setDisabledImage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemSprite* cobj = (cocos2d::MenuItemSprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemSprite_setDisabledImage : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemSprite_setDisabledImage : Error processing arguments"); cobj->setDisabledImage(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -44824,9 +45692,9 @@ bool js_cocos2dx_MenuItemSprite_setDisabledImage(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_MenuItemSprite_initWithNormalSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemSprite* cobj = (cocos2d::MenuItemSprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemSprite_initWithNormalSprite : Invalid Native Object"); @@ -44836,34 +45704,35 @@ bool js_cocos2dx_MenuItemSprite_initWithNormalSprite(JSContext *cx, uint32_t arg cocos2d::Node* arg2; std::function arg3; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); } while (0); do { - if(JS_TypeOfValue(cx, argv[3]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(3)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[3])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(3))); auto lambda = [=](cocos2d::Ref* larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -44873,8 +45742,8 @@ bool js_cocos2dx_MenuItemSprite_initWithNormalSprite(JSContext *cx, uint32_t arg largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -44891,7 +45760,7 @@ bool js_cocos2dx_MenuItemSprite_initWithNormalSprite(JSContext *cx, uint32_t arg bool ret = cobj->initWithNormalSprite(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -44900,25 +45769,25 @@ bool js_cocos2dx_MenuItemSprite_initWithNormalSprite(JSContext *cx, uint32_t arg } bool js_cocos2dx_MenuItemSprite_setSelectedImage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemSprite* cobj = (cocos2d::MenuItemSprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemSprite_setSelectedImage : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemSprite_setSelectedImage : Error processing arguments"); cobj->setSelectedImage(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -44927,7 +45796,8 @@ bool js_cocos2dx_MenuItemSprite_setSelectedImage(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_MenuItemSprite_getDisabledImage(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemSprite* cobj = (cocos2d::MenuItemSprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemSprite_getDisabledImage : Invalid Native Object"); @@ -44942,7 +45812,7 @@ bool js_cocos2dx_MenuItemSprite_getDisabledImage(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -44951,7 +45821,8 @@ bool js_cocos2dx_MenuItemSprite_getDisabledImage(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_MenuItemSprite_getSelectedImage(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemSprite* cobj = (cocos2d::MenuItemSprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemSprite_getSelectedImage : Invalid Native Object"); @@ -44966,7 +45837,7 @@ bool js_cocos2dx_MenuItemSprite_getSelectedImage(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -44975,7 +45846,8 @@ bool js_cocos2dx_MenuItemSprite_getSelectedImage(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_MenuItemSprite_getNormalImage(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemSprite* cobj = (cocos2d::MenuItemSprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemSprite_getNormalImage : Invalid Native Object"); @@ -44990,7 +45862,7 @@ bool js_cocos2dx_MenuItemSprite_getNormalImage(JSContext *cx, uint32_t argc, jsv jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -44999,13 +45871,14 @@ bool js_cocos2dx_MenuItemSprite_getNormalImage(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_MenuItemSprite_unselected(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemSprite* cobj = (cocos2d::MenuItemSprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemSprite_unselected : Invalid Native Object"); if (argc == 0) { cobj->unselected(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -45014,7 +45887,7 @@ bool js_cocos2dx_MenuItemSprite_unselected(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_MenuItemSprite_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::MenuItemSprite* cobj = new (std::nothrow) cocos2d::MenuItemSprite(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -45028,13 +45901,16 @@ bool js_cocos2dx_MenuItemSprite_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemSprite"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemSprite"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -45047,21 +45923,21 @@ void js_cocos2d_MenuItemSprite_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_MenuItemSprite_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::MenuItemSprite *nobj = new (std::nothrow) cocos2d::MenuItemSprite(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemSprite"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemSprite"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_MenuItemSprite(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_MenuItemSprite(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_MenuItemSprite_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_MenuItemSprite_class->name = "MenuItemSprite"; jsb_cocos2d_MenuItemSprite_class->addProperty = JS_PropertyStub; @@ -45075,8 +45951,8 @@ void js_register_cocos2dx_MenuItemSprite(JSContext *cx, JSObject *global) { jsb_cocos2d_MenuItemSprite_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -45098,7 +45974,7 @@ void js_register_cocos2dx_MenuItemSprite(JSContext *cx, JSObject *global) { jsb_cocos2d_MenuItemSprite_prototype = JS_InitClass( cx, global, - jsb_cocos2d_MenuItem_prototype, + JS::RootedObject(cx, jsb_cocos2d_MenuItem_prototype), jsb_cocos2d_MenuItemSprite_class, js_cocos2dx_MenuItemSprite_constructor, 0, // constructor properties, @@ -45129,25 +46005,25 @@ JSObject *jsb_cocos2d_MenuItemImage_prototype; bool js_cocos2dx_MenuItemImage_setDisabledSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemImage* cobj = (cocos2d::MenuItemImage *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemImage_setDisabledSpriteFrame : Invalid Native Object"); if (argc == 1) { cocos2d::SpriteFrame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemImage_setDisabledSpriteFrame : Error processing arguments"); cobj->setDisabledSpriteFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -45156,25 +46032,25 @@ bool js_cocos2dx_MenuItemImage_setDisabledSpriteFrame(JSContext *cx, uint32_t ar } bool js_cocos2dx_MenuItemImage_setSelectedSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemImage* cobj = (cocos2d::MenuItemImage *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemImage_setSelectedSpriteFrame : Invalid Native Object"); if (argc == 1) { cocos2d::SpriteFrame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemImage_setSelectedSpriteFrame : Error processing arguments"); cobj->setSelectedSpriteFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -45183,25 +46059,25 @@ bool js_cocos2dx_MenuItemImage_setSelectedSpriteFrame(JSContext *cx, uint32_t ar } bool js_cocos2dx_MenuItemImage_setNormalSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemImage* cobj = (cocos2d::MenuItemImage *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemImage_setNormalSpriteFrame : Invalid Native Object"); if (argc == 1) { cocos2d::SpriteFrame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemImage_setNormalSpriteFrame : Error processing arguments"); cobj->setNormalSpriteFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -45210,7 +46086,8 @@ bool js_cocos2dx_MenuItemImage_setNormalSpriteFrame(JSContext *cx, uint32_t argc } bool js_cocos2dx_MenuItemImage_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemImage* cobj = (cocos2d::MenuItemImage *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemImage_init : Invalid Native Object"); @@ -45218,7 +46095,7 @@ bool js_cocos2dx_MenuItemImage_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -45227,9 +46104,9 @@ bool js_cocos2dx_MenuItemImage_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_MenuItemImage_initWithNormalImage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemImage* cobj = (cocos2d::MenuItemImage *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemImage_initWithNormalImage : Invalid Native Object"); @@ -45238,14 +46115,15 @@ bool js_cocos2dx_MenuItemImage_initWithNormalImage(JSContext *cx, uint32_t argc, std::string arg1; std::string arg2; std::function arg3; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); do { - if(JS_TypeOfValue(cx, argv[3]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(3)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[3])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(3))); auto lambda = [=](cocos2d::Ref* larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -45255,8 +46133,8 @@ bool js_cocos2dx_MenuItemImage_initWithNormalImage(JSContext *cx, uint32_t argc, largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -45273,7 +46151,7 @@ bool js_cocos2dx_MenuItemImage_initWithNormalImage(JSContext *cx, uint32_t argc, bool ret = cobj->initWithNormalImage(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -45282,7 +46160,7 @@ bool js_cocos2dx_MenuItemImage_initWithNormalImage(JSContext *cx, uint32_t argc, } bool js_cocos2dx_MenuItemImage_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::MenuItemImage* cobj = new (std::nothrow) cocos2d::MenuItemImage(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -45296,13 +46174,16 @@ bool js_cocos2dx_MenuItemImage_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemImage"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemImage"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -45315,21 +46196,21 @@ void js_cocos2d_MenuItemImage_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_MenuItemImage_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::MenuItemImage *nobj = new (std::nothrow) cocos2d::MenuItemImage(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemImage"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemImage"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_MenuItemImage(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_MenuItemImage(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_MenuItemImage_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_MenuItemImage_class->name = "MenuItemImage"; jsb_cocos2d_MenuItemImage_class->addProperty = JS_PropertyStub; @@ -45343,8 +46224,8 @@ void js_register_cocos2dx_MenuItemImage(JSContext *cx, JSObject *global) { jsb_cocos2d_MenuItemImage_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -45361,7 +46242,7 @@ void js_register_cocos2dx_MenuItemImage(JSContext *cx, JSObject *global) { jsb_cocos2d_MenuItemImage_prototype = JS_InitClass( cx, global, - jsb_cocos2d_MenuItemSprite_prototype, + JS::RootedObject(cx, jsb_cocos2d_MenuItemSprite_prototype), jsb_cocos2d_MenuItemImage_class, js_cocos2dx_MenuItemImage_constructor, 0, // constructor properties, @@ -45392,18 +46273,18 @@ JSObject *jsb_cocos2d_MenuItemToggle_prototype; bool js_cocos2dx_MenuItemToggle_setSubItems(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemToggle* cobj = (cocos2d::MenuItemToggle *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemToggle_setSubItems : Invalid Native Object"); if (argc == 1) { cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemToggle_setSubItems : Error processing arguments"); cobj->setSubItems(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -45412,18 +46293,18 @@ bool js_cocos2dx_MenuItemToggle_setSubItems(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_MenuItemToggle_initWithItem(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemToggle* cobj = (cocos2d::MenuItemToggle *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemToggle_initWithItem : Invalid Native Object"); if (argc == 1) { cocos2d::MenuItem* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::MenuItem*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -45432,7 +46313,7 @@ bool js_cocos2dx_MenuItemToggle_initWithItem(JSContext *cx, uint32_t argc, jsval bool ret = cobj->initWithItem(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -45441,7 +46322,8 @@ bool js_cocos2dx_MenuItemToggle_initWithItem(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_MenuItemToggle_getSelectedIndex(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemToggle* cobj = (cocos2d::MenuItemToggle *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemToggle_getSelectedIndex : Invalid Native Object"); @@ -45449,7 +46331,7 @@ bool js_cocos2dx_MenuItemToggle_getSelectedIndex(JSContext *cx, uint32_t argc, j unsigned int ret = cobj->getSelectedIndex(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -45458,25 +46340,25 @@ bool js_cocos2dx_MenuItemToggle_getSelectedIndex(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_MenuItemToggle_addSubItem(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemToggle* cobj = (cocos2d::MenuItemToggle *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemToggle_addSubItem : Invalid Native Object"); if (argc == 1) { cocos2d::MenuItem* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::MenuItem*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemToggle_addSubItem : Error processing arguments"); cobj->addSubItem(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -45485,7 +46367,8 @@ bool js_cocos2dx_MenuItemToggle_addSubItem(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_MenuItemToggle_getSelectedItem(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemToggle* cobj = (cocos2d::MenuItemToggle *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemToggle_getSelectedItem : Invalid Native Object"); @@ -45500,7 +46383,7 @@ bool js_cocos2dx_MenuItemToggle_getSelectedItem(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -45509,18 +46392,18 @@ bool js_cocos2dx_MenuItemToggle_getSelectedItem(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_MenuItemToggle_setSelectedIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MenuItemToggle* cobj = (cocos2d::MenuItemToggle *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItemToggle_setSelectedIndex : Invalid Native Object"); if (argc == 1) { unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItemToggle_setSelectedIndex : Error processing arguments"); cobj->setSelectedIndex(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -45529,7 +46412,7 @@ bool js_cocos2dx_MenuItemToggle_setSelectedIndex(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_MenuItemToggle_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::MenuItemToggle* cobj = new (std::nothrow) cocos2d::MenuItemToggle(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -45543,13 +46426,16 @@ bool js_cocos2dx_MenuItemToggle_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemToggle"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemToggle"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -45562,21 +46448,21 @@ void js_cocos2d_MenuItemToggle_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_MenuItemToggle_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::MenuItemToggle *nobj = new (std::nothrow) cocos2d::MenuItemToggle(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemToggle"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MenuItemToggle"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_MenuItemToggle(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_MenuItemToggle(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_MenuItemToggle_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_MenuItemToggle_class->name = "MenuItemToggle"; jsb_cocos2d_MenuItemToggle_class->addProperty = JS_PropertyStub; @@ -45590,8 +46476,8 @@ void js_register_cocos2dx_MenuItemToggle(JSContext *cx, JSObject *global) { jsb_cocos2d_MenuItemToggle_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -45609,7 +46495,7 @@ void js_register_cocos2dx_MenuItemToggle(JSContext *cx, JSObject *global) { jsb_cocos2d_MenuItemToggle_prototype = JS_InitClass( cx, global, - jsb_cocos2d_MenuItem_prototype, + JS::RootedObject(cx, jsb_cocos2d_MenuItem_prototype), jsb_cocos2d_MenuItemToggle_class, js_cocos2dx_MenuItemToggle_constructor, 0, // constructor properties, @@ -45640,20 +46526,20 @@ JSObject *jsb_cocos2d_Menu_prototype; bool js_cocos2dx_Menu_initWithArray(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Menu* cobj = (cocos2d::Menu *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Menu_initWithArray : Invalid Native Object"); if (argc == 1) { cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Menu_initWithArray : Error processing arguments"); bool ret = cobj->initWithArray(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -45662,18 +46548,18 @@ bool js_cocos2dx_Menu_initWithArray(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Menu_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Menu* cobj = (cocos2d::Menu *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Menu_setEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Menu_setEnabled : Error processing arguments"); cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -45682,13 +46568,14 @@ bool js_cocos2dx_Menu_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Menu_alignItemsVertically(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Menu* cobj = (cocos2d::Menu *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Menu_alignItemsVertically : Invalid Native Object"); if (argc == 0) { cobj->alignItemsVertically(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -45697,7 +46584,8 @@ bool js_cocos2dx_Menu_alignItemsVertically(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Menu_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Menu* cobj = (cocos2d::Menu *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Menu_isEnabled : Invalid Native Object"); @@ -45705,44 +46593,27 @@ bool js_cocos2dx_Menu_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Menu_isEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_Menu_init(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::Menu* cobj = (cocos2d::Menu *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Menu_init : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->init(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_Menu_init : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_Menu_alignItemsHorizontallyWithPadding(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Menu* cobj = (cocos2d::Menu *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Menu_alignItemsHorizontallyWithPadding : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Menu_alignItemsHorizontallyWithPadding : Error processing arguments"); cobj->alignItemsHorizontallyWithPadding(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -45751,18 +46622,18 @@ bool js_cocos2dx_Menu_alignItemsHorizontallyWithPadding(JSContext *cx, uint32_t } bool js_cocos2dx_Menu_alignItemsVerticallyWithPadding(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Menu* cobj = (cocos2d::Menu *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Menu_alignItemsVerticallyWithPadding : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Menu_alignItemsVerticallyWithPadding : Error processing arguments"); cobj->alignItemsVerticallyWithPadding(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -45771,13 +46642,14 @@ bool js_cocos2dx_Menu_alignItemsVerticallyWithPadding(JSContext *cx, uint32_t ar } bool js_cocos2dx_Menu_alignItemsHorizontally(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Menu* cobj = (cocos2d::Menu *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Menu_alignItemsHorizontally : Invalid Native Object"); if (argc == 0) { cobj->alignItemsHorizontally(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -45786,7 +46658,7 @@ bool js_cocos2dx_Menu_alignItemsHorizontally(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Menu_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Menu* cobj = new (std::nothrow) cocos2d::Menu(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -45800,13 +46672,16 @@ bool js_cocos2dx_Menu_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Menu"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Menu"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -45819,21 +46694,21 @@ void js_cocos2d_Menu_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_Menu_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::Menu *nobj = new (std::nothrow) cocos2d::Menu(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Menu"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Menu"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_Menu(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Menu(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Menu_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Menu_class->name = "Menu"; jsb_cocos2d_Menu_class->addProperty = JS_PropertyStub; @@ -45847,8 +46722,8 @@ void js_register_cocos2dx_Menu(JSContext *cx, JSObject *global) { jsb_cocos2d_Menu_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -45856,7 +46731,6 @@ void js_register_cocos2dx_Menu(JSContext *cx, JSObject *global) { JS_FN("setEnabled", js_cocos2dx_Menu_setEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("alignItemsVertically", js_cocos2dx_Menu_alignItemsVertically, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isEnabled", js_cocos2dx_Menu_isEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_Menu_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("alignItemsHorizontallyWithPadding", js_cocos2dx_Menu_alignItemsHorizontallyWithPadding, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("alignItemsVerticallyWithPadding", js_cocos2dx_Menu_alignItemsVerticallyWithPadding, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("alignItemsHorizontally", js_cocos2dx_Menu_alignItemsHorizontally, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -45868,7 +46742,7 @@ void js_register_cocos2dx_Menu(JSContext *cx, JSObject *global) { jsb_cocos2d_Menu_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Layer_prototype, + JS::RootedObject(cx, jsb_cocos2d_Layer_prototype), jsb_cocos2d_Menu_class, js_cocos2dx_Menu_constructor, 0, // constructor properties, @@ -45899,7 +46773,8 @@ JSObject *jsb_cocos2d_ClippingNode_prototype; bool js_cocos2dx_ClippingNode_hasContent(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ClippingNode* cobj = (cocos2d::ClippingNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ClippingNode_hasContent : Invalid Native Object"); @@ -45907,7 +46782,7 @@ bool js_cocos2dx_ClippingNode_hasContent(JSContext *cx, uint32_t argc, jsval *vp bool ret = cobj->hasContent(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -45916,18 +46791,18 @@ bool js_cocos2dx_ClippingNode_hasContent(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ClippingNode_setInverted(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ClippingNode* cobj = (cocos2d::ClippingNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ClippingNode_setInverted : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ClippingNode_setInverted : Error processing arguments"); cobj->setInverted(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -45936,25 +46811,25 @@ bool js_cocos2dx_ClippingNode_setInverted(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ClippingNode_setStencil(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ClippingNode* cobj = (cocos2d::ClippingNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ClippingNode_setStencil : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ClippingNode_setStencil : Error processing arguments"); cobj->setStencil(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -45963,7 +46838,8 @@ bool js_cocos2dx_ClippingNode_setStencil(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ClippingNode_getAlphaThreshold(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ClippingNode* cobj = (cocos2d::ClippingNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ClippingNode_getAlphaThreshold : Invalid Native Object"); @@ -45971,60 +46847,17 @@ bool js_cocos2dx_ClippingNode_getAlphaThreshold(JSContext *cx, uint32_t argc, js double ret = cobj->getAlphaThreshold(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ClippingNode_getAlphaThreshold : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ClippingNode_init(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - - JSObject *obj = NULL; - cocos2d::ClippingNode* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (cocos2d::ClippingNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ClippingNode_init : Invalid Native Object"); - do { - if (argc == 1) { - cocos2d::Node* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - bool ret = cobj->init(arg0); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while(0); - - do { - if (argc == 0) { - bool ret = cobj->init(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while(0); - - JS_ReportError(cx, "js_cocos2dx_ClippingNode_init : wrong number of arguments"); - return false; -} bool js_cocos2dx_ClippingNode_getStencil(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ClippingNode* cobj = (cocos2d::ClippingNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ClippingNode_getStencil : Invalid Native Object"); @@ -46039,7 +46872,7 @@ bool js_cocos2dx_ClippingNode_getStencil(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -46048,18 +46881,18 @@ bool js_cocos2dx_ClippingNode_getStencil(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ClippingNode_setAlphaThreshold(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ClippingNode* cobj = (cocos2d::ClippingNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ClippingNode_setAlphaThreshold : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ClippingNode_setAlphaThreshold : Error processing arguments"); cobj->setAlphaThreshold(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -46068,7 +46901,8 @@ bool js_cocos2dx_ClippingNode_setAlphaThreshold(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ClippingNode_isInverted(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ClippingNode* cobj = (cocos2d::ClippingNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ClippingNode_isInverted : Invalid Native Object"); @@ -46076,7 +46910,7 @@ bool js_cocos2dx_ClippingNode_isInverted(JSContext *cx, uint32_t argc, jsval *vp bool ret = cobj->isInverted(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -46085,16 +46919,16 @@ bool js_cocos2dx_ClippingNode_isInverted(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ClippingNode_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -46110,7 +46944,7 @@ bool js_cocos2dx_ClippingNode_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -46127,7 +46961,7 @@ bool js_cocos2dx_ClippingNode_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -46136,7 +46970,7 @@ bool js_cocos2dx_ClippingNode_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ClippingNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ClippingNode* cobj = new (std::nothrow) cocos2d::ClippingNode(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -46150,13 +46984,16 @@ bool js_cocos2dx_ClippingNode_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ClippingNode"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ClippingNode"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -46167,7 +47004,7 @@ void js_cocos2d_ClippingNode_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ClippingNode)", obj); } -void js_register_cocos2dx_ClippingNode(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ClippingNode(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ClippingNode_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ClippingNode_class->name = "ClippingNode"; jsb_cocos2d_ClippingNode_class->addProperty = JS_PropertyStub; @@ -46181,8 +47018,8 @@ void js_register_cocos2dx_ClippingNode(JSContext *cx, JSObject *global) { jsb_cocos2d_ClippingNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -46190,7 +47027,6 @@ void js_register_cocos2dx_ClippingNode(JSContext *cx, JSObject *global) { JS_FN("setInverted", js_cocos2dx_ClippingNode_setInverted, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setStencil", js_cocos2dx_ClippingNode_setStencil, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getAlphaThreshold", js_cocos2dx_ClippingNode_getAlphaThreshold, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_ClippingNode_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getStencil", js_cocos2dx_ClippingNode_getStencil, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setAlphaThreshold", js_cocos2dx_ClippingNode_setAlphaThreshold, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isInverted", js_cocos2dx_ClippingNode_isInverted, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -46204,7 +47040,7 @@ void js_register_cocos2dx_ClippingNode(JSContext *cx, JSObject *global) { jsb_cocos2d_ClippingNode_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_ClippingNode_class, js_cocos2dx_ClippingNode_constructor, 0, // constructor properties, @@ -46235,13 +47071,14 @@ JSObject *jsb_cocos2d_MotionStreak_prototype; bool js_cocos2dx_MotionStreak_reset(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MotionStreak* cobj = (cocos2d::MotionStreak *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MotionStreak_reset : Invalid Native Object"); if (argc == 0) { cobj->reset(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -46250,25 +47087,25 @@ bool js_cocos2dx_MotionStreak_reset(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_MotionStreak_setTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MotionStreak* cobj = (cocos2d::MotionStreak *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MotionStreak_setTexture : Invalid Native Object"); if (argc == 1) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MotionStreak_setTexture : Error processing arguments"); cobj->setTexture(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -46277,7 +47114,8 @@ bool js_cocos2dx_MotionStreak_setTexture(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_MotionStreak_getTexture(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MotionStreak* cobj = (cocos2d::MotionStreak *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MotionStreak_getTexture : Invalid Native Object"); @@ -46292,7 +47130,7 @@ bool js_cocos2dx_MotionStreak_getTexture(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -46301,18 +47139,18 @@ bool js_cocos2dx_MotionStreak_getTexture(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_MotionStreak_tintWithColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MotionStreak* cobj = (cocos2d::MotionStreak *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MotionStreak_tintWithColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MotionStreak_tintWithColor : Error processing arguments"); cobj->tintWithColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -46321,18 +47159,18 @@ bool js_cocos2dx_MotionStreak_tintWithColor(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_MotionStreak_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MotionStreak* cobj = (cocos2d::MotionStreak *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MotionStreak_setBlendFunc : Invalid Native Object"); if (argc == 1) { cocos2d::BlendFunc arg0; - ok &= jsval_to_blendfunc(cx, argv[0], &arg0); + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MotionStreak_setBlendFunc : Error processing arguments"); cobj->setBlendFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -46341,18 +47179,18 @@ bool js_cocos2dx_MotionStreak_setBlendFunc(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_MotionStreak_setStartingPositionInitialized(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MotionStreak* cobj = (cocos2d::MotionStreak *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MotionStreak_setStartingPositionInitialized : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MotionStreak_setStartingPositionInitialized : Error processing arguments"); cobj->setStartingPositionInitialized(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -46361,7 +47199,8 @@ bool js_cocos2dx_MotionStreak_setStartingPositionInitialized(JSContext *cx, uint } bool js_cocos2dx_MotionStreak_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MotionStreak* cobj = (cocos2d::MotionStreak *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MotionStreak_getBlendFunc : Invalid Native Object"); @@ -46369,7 +47208,7 @@ bool js_cocos2dx_MotionStreak_getBlendFunc(JSContext *cx, uint32_t argc, jsval * const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); jsval jsret = JSVAL_NULL; jsret = blendfunc_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -46378,7 +47217,8 @@ bool js_cocos2dx_MotionStreak_getBlendFunc(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_MotionStreak_isStartingPositionInitialized(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MotionStreak* cobj = (cocos2d::MotionStreak *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MotionStreak_isStartingPositionInitialized : Invalid Native Object"); @@ -46386,7 +47226,7 @@ bool js_cocos2dx_MotionStreak_isStartingPositionInitialized(JSContext *cx, uint3 bool ret = cobj->isStartingPositionInitialized(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -46395,7 +47235,8 @@ bool js_cocos2dx_MotionStreak_isStartingPositionInitialized(JSContext *cx, uint3 } bool js_cocos2dx_MotionStreak_isFastMode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MotionStreak* cobj = (cocos2d::MotionStreak *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MotionStreak_isFastMode : Invalid Native Object"); @@ -46403,7 +47244,7 @@ bool js_cocos2dx_MotionStreak_isFastMode(JSContext *cx, uint32_t argc, jsval *vp bool ret = cobj->isFastMode(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -46412,34 +47253,34 @@ bool js_cocos2dx_MotionStreak_isFastMode(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_MotionStreak_initWithFade(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::MotionStreak* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::MotionStreak *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MotionStreak_initWithFade : Invalid Native Object"); do { if (argc == 5) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::Color3B arg3; - ok &= jsval_to_cccolor3b(cx, argv[3], &arg3); + ok &= jsval_to_cccolor3b(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cocos2d::Texture2D* arg4; do { - if (!argv[4].isObject()) { ok = false; break; } + if (!args.get(4).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[4]); + JSObject *tmpObj = args.get(4).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg4 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg4, cx, false, "Invalid Native Object"); @@ -46448,7 +47289,7 @@ bool js_cocos2dx_MotionStreak_initWithFade(JSContext *cx, uint32_t argc, jsval * bool ret = cobj->initWithFade(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -46456,24 +47297,24 @@ bool js_cocos2dx_MotionStreak_initWithFade(JSContext *cx, uint32_t argc, jsval * do { if (argc == 5) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::Color3B arg3; - ok &= jsval_to_cccolor3b(cx, argv[3], &arg3); + ok &= jsval_to_cccolor3b(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } std::string arg4; - ok &= jsval_to_std_string(cx, argv[4], &arg4); + ok &= jsval_to_std_string(cx, args.get(4), &arg4); if (!ok) { ok = true; break; } bool ret = cobj->initWithFade(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -46483,18 +47324,18 @@ bool js_cocos2dx_MotionStreak_initWithFade(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_MotionStreak_setFastMode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::MotionStreak* cobj = (cocos2d::MotionStreak *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MotionStreak_setFastMode : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MotionStreak_setFastMode : Error processing arguments"); cobj->setFastMode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -46503,28 +47344,28 @@ bool js_cocos2dx_MotionStreak_setFastMode(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_MotionStreak_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 5) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::Color3B arg3; - ok &= jsval_to_cccolor3b(cx, argv[3], &arg3); + ok &= jsval_to_cccolor3b(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cocos2d::Texture2D* arg4; do { - if (!argv[4].isObject()) { ok = false; break; } + if (!args.get(4).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[4]); + JSObject *tmpObj = args.get(4).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg4 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg4, cx, false, "Invalid Native Object"); @@ -46540,7 +47381,7 @@ bool js_cocos2dx_MotionStreak_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -46548,19 +47389,19 @@ bool js_cocos2dx_MotionStreak_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 5) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::Color3B arg3; - ok &= jsval_to_cccolor3b(cx, argv[3], &arg3); + ok &= jsval_to_cccolor3b(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } std::string arg4; - ok &= jsval_to_std_string(cx, argv[4], &arg4); + ok &= jsval_to_std_string(cx, args.get(4), &arg4); if (!ok) { ok = true; break; } cocos2d::MotionStreak* ret = cocos2d::MotionStreak::create(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; @@ -46572,7 +47413,7 @@ bool js_cocos2dx_MotionStreak_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -46581,7 +47422,7 @@ bool js_cocos2dx_MotionStreak_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_MotionStreak_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::MotionStreak* cobj = new (std::nothrow) cocos2d::MotionStreak(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -46595,13 +47436,16 @@ bool js_cocos2dx_MotionStreak_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MotionStreak"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MotionStreak"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -46614,21 +47458,21 @@ void js_cocos2d_MotionStreak_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_MotionStreak_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::MotionStreak *nobj = new (std::nothrow) cocos2d::MotionStreak(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::MotionStreak"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::MotionStreak"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_MotionStreak(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_MotionStreak(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_MotionStreak_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_MotionStreak_class->name = "MotionStreak"; jsb_cocos2d_MotionStreak_class->addProperty = JS_PropertyStub; @@ -46642,8 +47486,8 @@ void js_register_cocos2dx_MotionStreak(JSContext *cx, JSObject *global) { jsb_cocos2d_MotionStreak_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -46669,7 +47513,7 @@ void js_register_cocos2dx_MotionStreak(JSContext *cx, JSObject *global) { jsb_cocos2d_MotionStreak_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_MotionStreak_class, js_cocos2dx_MotionStreak_constructor, 0, // constructor properties, @@ -46700,18 +47544,18 @@ JSObject *jsb_cocos2d_ProgressTimer_prototype; bool js_cocos2dx_ProgressTimer_initWithSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProgressTimer* cobj = (cocos2d::ProgressTimer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressTimer_initWithSprite : Invalid Native Object"); if (argc == 1) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -46720,7 +47564,7 @@ bool js_cocos2dx_ProgressTimer_initWithSprite(JSContext *cx, uint32_t argc, jsva bool ret = cobj->initWithSprite(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -46729,7 +47573,8 @@ bool js_cocos2dx_ProgressTimer_initWithSprite(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ProgressTimer_isReverseDirection(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProgressTimer* cobj = (cocos2d::ProgressTimer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressTimer_isReverseDirection : Invalid Native Object"); @@ -46737,7 +47582,7 @@ bool js_cocos2dx_ProgressTimer_isReverseDirection(JSContext *cx, uint32_t argc, bool ret = cobj->isReverseDirection(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -46746,18 +47591,18 @@ bool js_cocos2dx_ProgressTimer_isReverseDirection(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ProgressTimer_setBarChangeRate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProgressTimer* cobj = (cocos2d::ProgressTimer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressTimer_setBarChangeRate : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProgressTimer_setBarChangeRate : Error processing arguments"); cobj->setBarChangeRate(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -46766,7 +47611,8 @@ bool js_cocos2dx_ProgressTimer_setBarChangeRate(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ProgressTimer_getPercentage(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProgressTimer* cobj = (cocos2d::ProgressTimer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressTimer_getPercentage : Invalid Native Object"); @@ -46774,7 +47620,7 @@ bool js_cocos2dx_ProgressTimer_getPercentage(JSContext *cx, uint32_t argc, jsval double ret = cobj->getPercentage(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -46783,25 +47629,25 @@ bool js_cocos2dx_ProgressTimer_getPercentage(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ProgressTimer_setSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProgressTimer* cobj = (cocos2d::ProgressTimer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressTimer_setSprite : Invalid Native Object"); if (argc == 1) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProgressTimer_setSprite : Error processing arguments"); cobj->setSprite(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -46810,7 +47656,8 @@ bool js_cocos2dx_ProgressTimer_setSprite(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ProgressTimer_getType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProgressTimer* cobj = (cocos2d::ProgressTimer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressTimer_getType : Invalid Native Object"); @@ -46818,7 +47665,7 @@ bool js_cocos2dx_ProgressTimer_getType(JSContext *cx, uint32_t argc, jsval *vp) int ret = (int)cobj->getType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -46827,7 +47674,8 @@ bool js_cocos2dx_ProgressTimer_getType(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ProgressTimer_getSprite(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProgressTimer* cobj = (cocos2d::ProgressTimer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressTimer_getSprite : Invalid Native Object"); @@ -46842,7 +47690,7 @@ bool js_cocos2dx_ProgressTimer_getSprite(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -46851,18 +47699,18 @@ bool js_cocos2dx_ProgressTimer_getSprite(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ProgressTimer_setMidpoint(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProgressTimer* cobj = (cocos2d::ProgressTimer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressTimer_setMidpoint : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProgressTimer_setMidpoint : Error processing arguments"); cobj->setMidpoint(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -46871,7 +47719,8 @@ bool js_cocos2dx_ProgressTimer_setMidpoint(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ProgressTimer_getBarChangeRate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProgressTimer* cobj = (cocos2d::ProgressTimer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressTimer_getBarChangeRate : Invalid Native Object"); @@ -46879,7 +47728,7 @@ bool js_cocos2dx_ProgressTimer_getBarChangeRate(JSContext *cx, uint32_t argc, js cocos2d::Vec2 ret = cobj->getBarChangeRate(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -46888,21 +47737,21 @@ bool js_cocos2dx_ProgressTimer_getBarChangeRate(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ProgressTimer_setReverseDirection(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::ProgressTimer* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::ProgressTimer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressTimer_setReverseDirection : Invalid Native Object"); do { if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); cobj->setReverseDirection(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -46910,9 +47759,9 @@ bool js_cocos2dx_ProgressTimer_setReverseDirection(JSContext *cx, uint32_t argc, do { if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); cobj->setReverseProgress(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -46922,7 +47771,8 @@ bool js_cocos2dx_ProgressTimer_setReverseDirection(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ProgressTimer_getMidpoint(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProgressTimer* cobj = (cocos2d::ProgressTimer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressTimer_getMidpoint : Invalid Native Object"); @@ -46930,7 +47780,7 @@ bool js_cocos2dx_ProgressTimer_getMidpoint(JSContext *cx, uint32_t argc, jsval * cocos2d::Vec2 ret = cobj->getMidpoint(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -46939,18 +47789,18 @@ bool js_cocos2dx_ProgressTimer_getMidpoint(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ProgressTimer_setPercentage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProgressTimer* cobj = (cocos2d::ProgressTimer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressTimer_setPercentage : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProgressTimer_setPercentage : Error processing arguments"); cobj->setPercentage(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -46959,18 +47809,18 @@ bool js_cocos2dx_ProgressTimer_setPercentage(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ProgressTimer_setType(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ProgressTimer* cobj = (cocos2d::ProgressTimer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ProgressTimer_setType : Invalid Native Object"); if (argc == 1) { cocos2d::ProgressTimer::Type arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ProgressTimer_setType : Error processing arguments"); cobj->setType(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -46979,14 +47829,14 @@ bool js_cocos2dx_ProgressTimer_setType(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ProgressTimer_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -47002,7 +47852,7 @@ bool js_cocos2dx_ProgressTimer_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ProgressTimer_create : wrong number of arguments"); @@ -47011,7 +47861,7 @@ bool js_cocos2dx_ProgressTimer_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ProgressTimer_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ProgressTimer* cobj = new (std::nothrow) cocos2d::ProgressTimer(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -47025,13 +47875,16 @@ bool js_cocos2dx_ProgressTimer_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ProgressTimer"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ProgressTimer"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -47044,21 +47897,21 @@ void js_cocos2d_ProgressTimer_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ProgressTimer_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ProgressTimer *nobj = new (std::nothrow) cocos2d::ProgressTimer(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ProgressTimer"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ProgressTimer"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ProgressTimer(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ProgressTimer(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ProgressTimer_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ProgressTimer_class->name = "ProgressTimer"; jsb_cocos2d_ProgressTimer_class->addProperty = JS_PropertyStub; @@ -47072,8 +47925,8 @@ void js_register_cocos2dx_ProgressTimer(JSContext *cx, JSObject *global) { jsb_cocos2d_ProgressTimer_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -47101,7 +47954,7 @@ void js_register_cocos2dx_ProgressTimer(JSContext *cx, JSObject *global) { jsb_cocos2d_ProgressTimer_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_ProgressTimer_class, js_cocos2dx_ProgressTimer_constructor, 0, // constructor properties, @@ -47132,12 +47985,12 @@ JSObject *jsb_cocos2d_Sprite_prototype; bool js_cocos2dx_Sprite_setSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_setSpriteFrame : Invalid Native Object"); @@ -47145,16 +47998,16 @@ bool js_cocos2dx_Sprite_setSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1) { cocos2d::SpriteFrame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cobj->setSpriteFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -47162,10 +48015,10 @@ bool js_cocos2dx_Sprite_setSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cobj->setSpriteFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -47175,12 +48028,12 @@ bool js_cocos2dx_Sprite_setSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_setTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_setTexture : Invalid Native Object"); @@ -47188,16 +48041,16 @@ bool js_cocos2dx_Sprite_setTexture(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cobj->setTexture(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -47205,10 +48058,10 @@ bool js_cocos2dx_Sprite_setTexture(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cobj->setTexture(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -47218,7 +48071,8 @@ bool js_cocos2dx_Sprite_setTexture(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_getTexture(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_getTexture : Invalid Native Object"); @@ -47233,7 +48087,7 @@ bool js_cocos2dx_Sprite_getTexture(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -47242,18 +48096,18 @@ bool js_cocos2dx_Sprite_getTexture(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_setFlippedY(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_setFlippedY : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_setFlippedY : Error processing arguments"); cobj->setFlippedY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -47262,18 +48116,18 @@ bool js_cocos2dx_Sprite_setFlippedY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_setFlippedX(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_setFlippedX : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_setFlippedX : Error processing arguments"); cobj->setFlippedX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -47282,18 +48136,18 @@ bool js_cocos2dx_Sprite_setFlippedX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_setRotationSkewX(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_setRotationSkewX : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_setRotationSkewX : Error processing arguments"); cobj->setRotationSkewX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -47302,54 +48156,32 @@ bool js_cocos2dx_Sprite_setRotationSkewX(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Sprite_setRotationSkewY(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_setRotationSkewY : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_setRotationSkewY : Error processing arguments"); cobj->setRotationSkewY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Sprite_setRotationSkewY : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_Sprite_initWithSpriteFrameName(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_initWithSpriteFrameName : Invalid Native Object"); - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_initWithSpriteFrameName : Error processing arguments"); - bool ret = cobj->initWithSpriteFrameName(arg0); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_Sprite_initWithSpriteFrameName : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_Sprite_initWithTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_initWithTexture : Invalid Native Object"); @@ -47357,21 +48189,21 @@ bool js_cocos2dx_Sprite_initWithTexture(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 2) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool ret = cobj->initWithTexture(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -47380,9 +48212,9 @@ bool js_cocos2dx_Sprite_initWithTexture(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -47391,7 +48223,7 @@ bool js_cocos2dx_Sprite_initWithTexture(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->initWithTexture(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -47400,23 +48232,23 @@ bool js_cocos2dx_Sprite_initWithTexture(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 3) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(args.get(2)); bool ret = cobj->initWithTexture(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -47426,7 +48258,8 @@ bool js_cocos2dx_Sprite_initWithTexture(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_getBatchNode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_getBatchNode : Invalid Native Object"); @@ -47441,7 +48274,7 @@ bool js_cocos2dx_Sprite_getBatchNode(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -47450,7 +48283,8 @@ bool js_cocos2dx_Sprite_getBatchNode(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_getOffsetPosition(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_getOffsetPosition : Invalid Native Object"); @@ -47458,7 +48292,7 @@ bool js_cocos2dx_Sprite_getOffsetPosition(JSContext *cx, uint32_t argc, jsval *v const cocos2d::Vec2& ret = cobj->getOffsetPosition(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -47467,62 +48301,47 @@ bool js_cocos2dx_Sprite_getOffsetPosition(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Sprite_removeAllChildrenWithCleanup(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_removeAllChildrenWithCleanup : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_removeAllChildrenWithCleanup : Error processing arguments"); cobj->removeAllChildrenWithCleanup(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Sprite_removeAllChildrenWithCleanup : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_Sprite_updateTransform(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_updateTransform : Invalid Native Object"); - if (argc == 0) { - cobj->updateTransform(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_Sprite_updateTransform : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_Sprite_setTextureRect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_setTextureRect : Invalid Native Object"); do { if (argc == 3) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } bool arg1; - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); cocos2d::Size arg2; - ok &= jsval_to_ccsize(cx, argv[2], &arg2); + ok &= jsval_to_ccsize(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } cobj->setTextureRect(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -47530,10 +48349,10 @@ bool js_cocos2dx_Sprite_setTextureRect(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cobj->setTextureRect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -47541,37 +48360,42 @@ bool js_cocos2dx_Sprite_setTextureRect(JSContext *cx, uint32_t argc, jsval *vp) JS_ReportError(cx, "js_cocos2dx_Sprite_setTextureRect : wrong number of arguments"); return false; } -bool js_cocos2dx_Sprite_init(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_Sprite_initWithSpriteFrameName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_init : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->init(); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_initWithSpriteFrameName : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_initWithSpriteFrameName : Error processing arguments"); + bool ret = cobj->initWithSpriteFrameName(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_Sprite_init : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_Sprite_initWithSpriteFrameName : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_Sprite_isFrameDisplayed(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_isFrameDisplayed : Invalid Native Object"); if (argc == 1) { cocos2d::SpriteFrame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -47580,7 +48404,7 @@ bool js_cocos2dx_Sprite_isFrameDisplayed(JSContext *cx, uint32_t argc, jsval *vp bool ret = cobj->isFrameDisplayed(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -47589,7 +48413,8 @@ bool js_cocos2dx_Sprite_isFrameDisplayed(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Sprite_getAtlasIndex(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_getAtlasIndex : Invalid Native Object"); @@ -47597,7 +48422,7 @@ bool js_cocos2dx_Sprite_getAtlasIndex(JSContext *cx, uint32_t argc, jsval *vp) ssize_t ret = cobj->getAtlasIndex(); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -47606,25 +48431,25 @@ bool js_cocos2dx_Sprite_getAtlasIndex(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_setBatchNode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_setBatchNode : Invalid Native Object"); if (argc == 1) { cocos2d::SpriteBatchNode* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteBatchNode*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_setBatchNode : Error processing arguments"); cobj->setBatchNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -47633,7 +48458,8 @@ bool js_cocos2dx_Sprite_setBatchNode(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_getBlendFunc : Invalid Native Object"); @@ -47641,7 +48467,7 @@ bool js_cocos2dx_Sprite_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); jsval jsret = JSVAL_NULL; jsret = blendfunc_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -47650,20 +48476,20 @@ bool js_cocos2dx_Sprite_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_setDisplayFrameWithAnimationName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_setDisplayFrameWithAnimationName : Invalid Native Object"); if (argc == 2) { std::string arg0; ssize_t arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_ssize(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_ssize(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_setDisplayFrameWithAnimationName : Error processing arguments"); cobj->setDisplayFrameWithAnimationName(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -47672,25 +48498,25 @@ bool js_cocos2dx_Sprite_setDisplayFrameWithAnimationName(JSContext *cx, uint32_t } bool js_cocos2dx_Sprite_setTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_setTextureAtlas : Invalid Native Object"); if (argc == 1) { cocos2d::TextureAtlas* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::TextureAtlas*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_setTextureAtlas : Error processing arguments"); cobj->setTextureAtlas(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -47699,7 +48525,8 @@ bool js_cocos2dx_Sprite_setTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_getSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_getSpriteFrame : Invalid Native Object"); @@ -47714,7 +48541,7 @@ bool js_cocos2dx_Sprite_getSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -47723,7 +48550,8 @@ bool js_cocos2dx_Sprite_getSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_isDirty(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_isDirty : Invalid Native Object"); @@ -47731,7 +48559,7 @@ bool js_cocos2dx_Sprite_isDirty(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isDirty(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -47740,18 +48568,18 @@ bool js_cocos2dx_Sprite_isDirty(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_setAtlasIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_setAtlasIndex : Invalid Native Object"); if (argc == 1) { ssize_t arg0; - ok &= jsval_to_ssize(cx, argv[0], &arg0); + ok &= jsval_to_ssize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_setAtlasIndex : Error processing arguments"); cobj->setAtlasIndex(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -47760,18 +48588,18 @@ bool js_cocos2dx_Sprite_setAtlasIndex(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_setDirty(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_setDirty : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_setDirty : Error processing arguments"); cobj->setDirty(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -47780,7 +48608,8 @@ bool js_cocos2dx_Sprite_setDirty(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_isTextureRectRotated(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_isTextureRectRotated : Invalid Native Object"); @@ -47788,7 +48617,7 @@ bool js_cocos2dx_Sprite_isTextureRectRotated(JSContext *cx, uint32_t argc, jsval bool ret = cobj->isTextureRectRotated(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -47797,7 +48626,8 @@ bool js_cocos2dx_Sprite_isTextureRectRotated(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Sprite_getTextureRect(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_getTextureRect : Invalid Native Object"); @@ -47805,7 +48635,7 @@ bool js_cocos2dx_Sprite_getTextureRect(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Rect& ret = cobj->getTextureRect(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -47814,27 +48644,27 @@ bool js_cocos2dx_Sprite_getTextureRect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_initWithFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_initWithFile : Invalid Native Object"); do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool ret = cobj->initWithFile(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -47842,12 +48672,12 @@ bool js_cocos2dx_Sprite_initWithFile(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } bool ret = cobj->initWithFile(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -47857,18 +48687,18 @@ bool js_cocos2dx_Sprite_initWithFile(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_setBlendFunc : Invalid Native Object"); if (argc == 1) { cocos2d::BlendFunc arg0; - ok &= jsval_to_blendfunc(cx, argv[0], &arg0); + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_setBlendFunc : Error processing arguments"); cobj->setBlendFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -47877,7 +48707,8 @@ bool js_cocos2dx_Sprite_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_getTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_getTextureAtlas : Invalid Native Object"); @@ -47892,7 +48723,7 @@ bool js_cocos2dx_Sprite_getTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -47901,18 +48732,18 @@ bool js_cocos2dx_Sprite_getTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_initWithSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_initWithSpriteFrame : Invalid Native Object"); if (argc == 1) { cocos2d::SpriteFrame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -47921,7 +48752,7 @@ bool js_cocos2dx_Sprite_initWithSpriteFrame(JSContext *cx, uint32_t argc, jsval bool ret = cobj->initWithSpriteFrame(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -47930,7 +48761,8 @@ bool js_cocos2dx_Sprite_initWithSpriteFrame(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Sprite_isFlippedX(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_isFlippedX : Invalid Native Object"); @@ -47938,7 +48770,7 @@ bool js_cocos2dx_Sprite_isFlippedX(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isFlippedX(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -47947,7 +48779,8 @@ bool js_cocos2dx_Sprite_isFlippedX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_isFlippedY(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_isFlippedY : Invalid Native Object"); @@ -47955,7 +48788,7 @@ bool js_cocos2dx_Sprite_isFlippedY(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isFlippedY(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -47964,18 +48797,18 @@ bool js_cocos2dx_Sprite_isFlippedY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_setVertexRect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_setVertexRect : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_setVertexRect : Error processing arguments"); cobj->setVertexRect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -47984,13 +48817,13 @@ bool js_cocos2dx_Sprite_setVertexRect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Sprite* ret = cocos2d::Sprite::create(arg0); jsval jsret = JSVAL_NULL; @@ -48002,7 +48835,7 @@ bool js_cocos2dx_Sprite_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -48019,7 +48852,7 @@ bool js_cocos2dx_Sprite_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -48027,10 +48860,10 @@ bool js_cocos2dx_Sprite_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::Sprite* ret = cocos2d::Sprite::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -48042,7 +48875,7 @@ bool js_cocos2dx_Sprite_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -48051,23 +48884,23 @@ bool js_cocos2dx_Sprite_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_createWithTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 2) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::Sprite* ret = cocos2d::Sprite::createWithTexture(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -48079,7 +48912,7 @@ bool js_cocos2dx_Sprite_createWithTexture(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -48087,19 +48920,19 @@ bool js_cocos2dx_Sprite_createWithTexture(JSContext *cx, uint32_t argc, jsval *v if (argc == 3) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(args.get(2)); if (!ok) { ok = true; break; } cocos2d::Sprite* ret = cocos2d::Sprite::createWithTexture(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -48111,7 +48944,7 @@ bool js_cocos2dx_Sprite_createWithTexture(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -48120,9 +48953,9 @@ bool js_cocos2dx_Sprite_createWithTexture(JSContext *cx, uint32_t argc, jsval *v if (argc == 1) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -48138,7 +48971,7 @@ bool js_cocos2dx_Sprite_createWithTexture(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -48147,11 +48980,11 @@ bool js_cocos2dx_Sprite_createWithTexture(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Sprite_createWithSpriteFrameName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sprite_createWithSpriteFrameName : Error processing arguments"); cocos2d::Sprite* ret = cocos2d::Sprite::createWithSpriteFrameName(arg0); jsval jsret = JSVAL_NULL; @@ -48163,7 +48996,7 @@ bool js_cocos2dx_Sprite_createWithSpriteFrameName(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Sprite_createWithSpriteFrameName : wrong number of arguments"); @@ -48172,14 +49005,14 @@ bool js_cocos2dx_Sprite_createWithSpriteFrameName(JSContext *cx, uint32_t argc, bool js_cocos2dx_Sprite_createWithSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::SpriteFrame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -48195,7 +49028,7 @@ bool js_cocos2dx_Sprite_createWithSpriteFrame(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Sprite_createWithSpriteFrame : wrong number of arguments"); @@ -48204,7 +49037,7 @@ bool js_cocos2dx_Sprite_createWithSpriteFrame(JSContext *cx, uint32_t argc, jsva bool js_cocos2dx_Sprite_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Sprite* cobj = new (std::nothrow) cocos2d::Sprite(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -48218,13 +49051,16 @@ bool js_cocos2dx_Sprite_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Sprite"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Sprite"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -48237,21 +49073,21 @@ void js_cocos2d_Sprite_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_Sprite_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::Sprite *nobj = new (std::nothrow) cocos2d::Sprite(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Sprite"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Sprite"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_Sprite(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Sprite(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Sprite_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Sprite_class->name = "Sprite"; jsb_cocos2d_Sprite_class->addProperty = JS_PropertyStub; @@ -48265,8 +49101,8 @@ void js_register_cocos2dx_Sprite(JSContext *cx, JSObject *global) { jsb_cocos2d_Sprite_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -48277,14 +49113,12 @@ void js_register_cocos2dx_Sprite(JSContext *cx, JSObject *global) { JS_FN("setFlippedX", js_cocos2dx_Sprite_setFlippedX, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRotationSkewX", js_cocos2dx_Sprite_setRotationSkewX, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRotationSkewY", js_cocos2dx_Sprite_setRotationSkewY, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("initWithSpriteFrameName", js_cocos2dx_Sprite_initWithSpriteFrameName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("initWithTexture", js_cocos2dx_Sprite_initWithTexture, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getBatchNode", js_cocos2dx_Sprite_getBatchNode, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getOffsetPosition", js_cocos2dx_Sprite_getOffsetPosition, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("removeAllChildrenWithCleanup", js_cocos2dx_Sprite_removeAllChildrenWithCleanup, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("updateTransform", js_cocos2dx_Sprite_updateTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setTextureRect", js_cocos2dx_Sprite_setTextureRect, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_Sprite_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithSpriteFrameName", js_cocos2dx_Sprite_initWithSpriteFrameName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isFrameDisplayed", js_cocos2dx_Sprite_isFrameDisplayed, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getAtlasIndex", js_cocos2dx_Sprite_getAtlasIndex, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setBatchNode", js_cocos2dx_Sprite_setBatchNode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -48318,7 +49152,7 @@ void js_register_cocos2dx_Sprite(JSContext *cx, JSObject *global) { jsb_cocos2d_Sprite_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_Sprite_class, js_cocos2dx_Sprite_constructor, 0, // constructor properties, @@ -48344,14 +49178,462 @@ void js_register_cocos2dx_Sprite(JSContext *cx, JSObject *global) { } } +JSClass *jsb_cocos2d_Image_class; +JSObject *jsb_cocos2d_Image_prototype; + +bool js_cocos2dx_Image_hasPremultipliedAlpha(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_hasPremultipliedAlpha : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->hasPremultipliedAlpha(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_hasPremultipliedAlpha : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_Image_getDataLen(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_getDataLen : Invalid Native Object"); + if (argc == 0) { + ssize_t ret = cobj->getDataLen(); + jsval jsret = JSVAL_NULL; + jsret = ssize_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_getDataLen : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_Image_saveToFile(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_saveToFile : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Image_saveToFile : Error processing arguments"); + bool ret = cobj->saveToFile(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + if (argc == 2) { + std::string arg0; + bool arg1; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + arg1 = JS::ToBoolean(args.get(1)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Image_saveToFile : Error processing arguments"); + bool ret = cobj->saveToFile(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_saveToFile : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_Image_hasAlpha(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_hasAlpha : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->hasAlpha(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_hasAlpha : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_Image_isCompressed(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_isCompressed : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isCompressed(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_isCompressed : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_Image_getHeight(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_getHeight : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getHeight(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_getHeight : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_Image_initWithImageFile(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_initWithImageFile : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Image_initWithImageFile : Error processing arguments"); + bool ret = cobj->initWithImageFile(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_initWithImageFile : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_Image_getWidth(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_getWidth : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getWidth(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_getWidth : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_Image_getBitPerPixel(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_getBitPerPixel : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getBitPerPixel(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_getBitPerPixel : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_Image_getFileType(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_getFileType : Invalid Native Object"); + if (argc == 0) { + int ret = (int)cobj->getFileType(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_getFileType : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_Image_getNumberOfMipmaps(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_getNumberOfMipmaps : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getNumberOfMipmaps(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_getNumberOfMipmaps : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_Image_getRenderFormat(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_getRenderFormat : Invalid Native Object"); + if (argc == 0) { + int ret = (int)cobj->getRenderFormat(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_getRenderFormat : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_Image_getData(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_getData : Invalid Native Object"); + if (argc == 0) { + unsigned char* ret = cobj->getData(); + jsval jsret = JSVAL_NULL; + #pragma warning NO CONVERSION FROM NATIVE FOR unsigned char*; + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_getData : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_Image_getMipmaps(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_getMipmaps : Invalid Native Object"); + if (argc == 0) { + cocos2d::_MipmapInfo* ret = cobj->getMipmaps(); + jsval jsret = JSVAL_NULL; + #pragma warning NO CONVERSION FROM NATIVE FOR _MipmapInfo*; + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_getMipmaps : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_Image_initWithRawData(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_initWithRawData : Invalid Native Object"); + if (argc == 5) { + const unsigned char* arg0; + ssize_t arg1; + int arg2; + int arg3; + int arg4; + #pragma warning NO CONVERSION TO NATIVE FOR unsigned char* + ok = false; + ok &= jsval_to_ssize(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Image_initWithRawData : Error processing arguments"); + bool ret = cobj->initWithRawData(arg0, arg1, arg2, arg3, arg4); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + if (argc == 6) { + const unsigned char* arg0; + ssize_t arg1; + int arg2; + int arg3; + int arg4; + bool arg5; + #pragma warning NO CONVERSION TO NATIVE FOR unsigned char* + ok = false; + ok &= jsval_to_ssize(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); + arg5 = JS::ToBoolean(args.get(5)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Image_initWithRawData : Error processing arguments"); + bool ret = cobj->initWithRawData(arg0, arg1, arg2, arg3, arg4, arg5); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_initWithRawData : wrong number of arguments: %d, was expecting %d", argc, 5); + return false; +} +bool js_cocos2dx_Image_setPVRImagesHavePremultipliedAlpha(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Image_setPVRImagesHavePremultipliedAlpha : Error processing arguments"); + cocos2d::Image::setPVRImagesHavePremultipliedAlpha(arg0); + args.rval().setUndefined(); + return true; + } + JS_ReportError(cx, "js_cocos2dx_Image_setPVRImagesHavePremultipliedAlpha : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_Image_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::Image* cobj = new (std::nothrow) cocos2d::Image(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Image"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + + +void js_cocos2d_Image_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (Image)", obj); +} + +void js_register_cocos2dx_Image(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_Image_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_Image_class->name = "Image"; + jsb_cocos2d_Image_class->addProperty = JS_PropertyStub; + jsb_cocos2d_Image_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_Image_class->getProperty = JS_PropertyStub; + jsb_cocos2d_Image_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_Image_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_Image_class->resolve = JS_ResolveStub; + jsb_cocos2d_Image_class->convert = JS_ConvertStub; + jsb_cocos2d_Image_class->finalize = js_cocos2d_Image_finalize; + jsb_cocos2d_Image_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("hasPremultipliedAlpha", js_cocos2dx_Image_hasPremultipliedAlpha, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDataLen", js_cocos2dx_Image_getDataLen, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("saveToFile", js_cocos2dx_Image_saveToFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("hasAlpha", js_cocos2dx_Image_hasAlpha, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isCompressed", js_cocos2dx_Image_isCompressed, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getHeight", js_cocos2dx_Image_getHeight, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithImageFile", js_cocos2dx_Image_initWithImageFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getWidth", js_cocos2dx_Image_getWidth, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getBitPerPixel", js_cocos2dx_Image_getBitPerPixel, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getFileType", js_cocos2dx_Image_getFileType, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getNumberOfMipmaps", js_cocos2dx_Image_getNumberOfMipmaps, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getRenderFormat", js_cocos2dx_Image_getRenderFormat, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getData", js_cocos2dx_Image_getData, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMipmaps", js_cocos2dx_Image_getMipmaps, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithRawData", js_cocos2dx_Image_initWithRawData, 5, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("setPVRImagesHavePremultipliedAlpha", js_cocos2dx_Image_setPVRImagesHavePremultipliedAlpha, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_Image_prototype = JS_InitClass( + cx, global, + JS::NullPtr(), // parent proto + jsb_cocos2d_Image_class, + js_cocos2dx_Image_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "Image", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_Image_class; + p->proto = jsb_cocos2d_Image_prototype; + p->parentProto = NULL; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + JSClass *jsb_cocos2d_RenderTexture_class; JSObject *jsb_cocos2d_RenderTexture_prototype; bool js_cocos2dx_RenderTexture_setVirtualViewport(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_setVirtualViewport : Invalid Native Object"); @@ -48359,12 +49641,12 @@ bool js_cocos2dx_RenderTexture_setVirtualViewport(JSContext *cx, uint32_t argc, cocos2d::Vec2 arg0; cocos2d::Rect arg1; cocos2d::Rect arg2; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= jsval_to_ccrect(cx, argv[1], &arg1); - ok &= jsval_to_ccrect(cx, argv[2], &arg2); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + ok &= jsval_to_ccrect(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RenderTexture_setVirtualViewport : Error processing arguments"); cobj->setVirtualViewport(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -48373,18 +49655,18 @@ bool js_cocos2dx_RenderTexture_setVirtualViewport(JSContext *cx, uint32_t argc, } bool js_cocos2dx_RenderTexture_clearStencil(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_clearStencil : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RenderTexture_clearStencil : Error processing arguments"); cobj->clearStencil(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -48393,7 +49675,8 @@ bool js_cocos2dx_RenderTexture_clearStencil(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_RenderTexture_getClearDepth(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_getClearDepth : Invalid Native Object"); @@ -48401,7 +49684,7 @@ bool js_cocos2dx_RenderTexture_getClearDepth(JSContext *cx, uint32_t argc, jsval double ret = cobj->getClearDepth(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48410,7 +49693,8 @@ bool js_cocos2dx_RenderTexture_getClearDepth(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_RenderTexture_getClearStencil(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_getClearStencil : Invalid Native Object"); @@ -48418,7 +49702,7 @@ bool js_cocos2dx_RenderTexture_getClearStencil(JSContext *cx, uint32_t argc, jsv int ret = cobj->getClearStencil(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48427,13 +49711,14 @@ bool js_cocos2dx_RenderTexture_getClearStencil(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_RenderTexture_end(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_end : Invalid Native Object"); if (argc == 0) { cobj->end(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -48442,18 +49727,18 @@ bool js_cocos2dx_RenderTexture_end(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_RenderTexture_setClearStencil(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_setClearStencil : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RenderTexture_setClearStencil : Error processing arguments"); cobj->setClearStencil(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -48462,25 +49747,25 @@ bool js_cocos2dx_RenderTexture_setClearStencil(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_RenderTexture_setSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_setSprite : Invalid Native Object"); if (argc == 1) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RenderTexture_setSprite : Error processing arguments"); cobj->setSprite(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -48489,7 +49774,8 @@ bool js_cocos2dx_RenderTexture_setSprite(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_RenderTexture_getSprite(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_getSprite : Invalid Native Object"); @@ -48504,7 +49790,7 @@ bool js_cocos2dx_RenderTexture_getSprite(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48513,7 +49799,8 @@ bool js_cocos2dx_RenderTexture_getSprite(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_RenderTexture_isAutoDraw(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_isAutoDraw : Invalid Native Object"); @@ -48521,7 +49808,7 @@ bool js_cocos2dx_RenderTexture_isAutoDraw(JSContext *cx, uint32_t argc, jsval *v bool ret = cobj->isAutoDraw(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48530,18 +49817,18 @@ bool js_cocos2dx_RenderTexture_isAutoDraw(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_RenderTexture_setKeepMatrix(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_setKeepMatrix : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RenderTexture_setKeepMatrix : Error processing arguments"); cobj->setKeepMatrix(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -48550,18 +49837,18 @@ bool js_cocos2dx_RenderTexture_setKeepMatrix(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_RenderTexture_setClearFlags(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_setClearFlags : Invalid Native Object"); if (argc == 1) { unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RenderTexture_setClearFlags : Error processing arguments"); cobj->setClearFlags(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -48570,13 +49857,14 @@ bool js_cocos2dx_RenderTexture_setClearFlags(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_RenderTexture_begin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_begin : Invalid Native Object"); if (argc == 0) { cobj->begin(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -48585,18 +49873,18 @@ bool js_cocos2dx_RenderTexture_begin(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_RenderTexture_setAutoDraw(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_setAutoDraw : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RenderTexture_setAutoDraw : Error processing arguments"); cobj->setAutoDraw(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -48605,18 +49893,18 @@ bool js_cocos2dx_RenderTexture_setAutoDraw(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_RenderTexture_setClearColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_setClearColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color4F arg0; - ok &= jsval_to_cccolor4f(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4f(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RenderTexture_setClearColor : Error processing arguments"); cobj->setClearColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -48625,13 +49913,14 @@ bool js_cocos2dx_RenderTexture_setClearColor(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_RenderTexture_endToLua(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_endToLua : Invalid Native Object"); if (argc == 0) { cobj->endToLua(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -48640,34 +49929,34 @@ bool js_cocos2dx_RenderTexture_endToLua(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_RenderTexture_beginWithClear(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::RenderTexture* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_beginWithClear : Invalid Native Object"); do { if (argc == 5) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); if (!ok) { ok = true; break; } double arg4; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[4]), &arg4); + ok &= JS::ToNumber( cx, args.get(4), &arg4) && !isnan(arg4); if (!ok) { ok = true; break; } cobj->beginWithClear(arg0, arg1, arg2, arg3, arg4); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -48675,19 +49964,19 @@ bool js_cocos2dx_RenderTexture_beginWithClear(JSContext *cx, uint32_t argc, jsva do { if (argc == 4) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); if (!ok) { ok = true; break; } cobj->beginWithClear(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -48695,25 +49984,25 @@ bool js_cocos2dx_RenderTexture_beginWithClear(JSContext *cx, uint32_t argc, jsva do { if (argc == 6) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); if (!ok) { ok = true; break; } double arg4; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[4]), &arg4); + ok &= JS::ToNumber( cx, args.get(4), &arg4) && !isnan(arg4); if (!ok) { ok = true; break; } int arg5; - ok &= jsval_to_int32(cx, argv[5], (int32_t *)&arg5); + ok &= jsval_to_int32(cx, args.get(5), (int32_t *)&arg5); if (!ok) { ok = true; break; } cobj->beginWithClear(arg0, arg1, arg2, arg3, arg4, arg5); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -48723,18 +50012,18 @@ bool js_cocos2dx_RenderTexture_beginWithClear(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_RenderTexture_clearDepth(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_clearDepth : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RenderTexture_clearDepth : Error processing arguments"); cobj->clearDepth(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -48743,7 +50032,8 @@ bool js_cocos2dx_RenderTexture_clearDepth(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_RenderTexture_getClearColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_getClearColor : Invalid Native Object"); @@ -48751,7 +50041,7 @@ bool js_cocos2dx_RenderTexture_getClearColor(JSContext *cx, uint32_t argc, jsval const cocos2d::Color4F& ret = cobj->getClearColor(); jsval jsret = JSVAL_NULL; jsret = cccolor4f_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48760,9 +50050,9 @@ bool js_cocos2dx_RenderTexture_getClearColor(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_RenderTexture_clear(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_clear : Invalid Native Object"); @@ -48771,13 +50061,13 @@ bool js_cocos2dx_RenderTexture_clear(JSContext *cx, uint32_t argc, jsval *vp) double arg1; double arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RenderTexture_clear : Error processing arguments"); cobj->clear(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -48786,7 +50076,8 @@ bool js_cocos2dx_RenderTexture_clear(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_RenderTexture_getClearFlags(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_getClearFlags : Invalid Native Object"); @@ -48794,7 +50085,7 @@ bool js_cocos2dx_RenderTexture_getClearFlags(JSContext *cx, uint32_t argc, jsval unsigned int ret = cobj->getClearFlags(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48803,9 +50094,9 @@ bool js_cocos2dx_RenderTexture_getClearFlags(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_RenderTexture_newImage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_newImage : Invalid Native Object"); @@ -48820,12 +50111,12 @@ bool js_cocos2dx_RenderTexture_newImage(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RenderTexture_newImage : Error processing arguments"); cocos2d::Image* ret = cobj->newImage(arg0); jsval jsret = JSVAL_NULL; @@ -48837,7 +50128,7 @@ bool js_cocos2dx_RenderTexture_newImage(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48846,18 +50137,18 @@ bool js_cocos2dx_RenderTexture_newImage(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_RenderTexture_setClearDepth(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::RenderTexture* cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_setClearDepth : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_RenderTexture_setClearDepth : Error processing arguments"); cobj->setClearDepth(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -48866,33 +50157,33 @@ bool js_cocos2dx_RenderTexture_setClearDepth(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_RenderTexture_initWithWidthAndHeight(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::RenderTexture* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::RenderTexture *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_RenderTexture_initWithWidthAndHeight : Invalid Native Object"); do { if (argc == 4) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cocos2d::Texture2D::PixelFormat arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } unsigned int arg3; - ok &= jsval_to_uint32(cx, argv[3], &arg3); + ok &= jsval_to_uint32(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } bool ret = cobj->initWithWidthAndHeight(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -48900,18 +50191,18 @@ bool js_cocos2dx_RenderTexture_initWithWidthAndHeight(JSContext *cx, uint32_t ar do { if (argc == 3) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cocos2d::Texture2D::PixelFormat arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } bool ret = cobj->initWithWidthAndHeight(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -48921,19 +50212,19 @@ bool js_cocos2dx_RenderTexture_initWithWidthAndHeight(JSContext *cx, uint32_t ar } bool js_cocos2dx_RenderTexture_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 3) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cocos2d::Texture2D::PixelFormat arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } cocos2d::RenderTexture* ret = cocos2d::RenderTexture::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -48945,7 +50236,7 @@ bool js_cocos2dx_RenderTexture_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -48953,16 +50244,16 @@ bool js_cocos2dx_RenderTexture_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 4) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cocos2d::Texture2D::PixelFormat arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } unsigned int arg3; - ok &= jsval_to_uint32(cx, argv[3], &arg3); + ok &= jsval_to_uint32(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cocos2d::RenderTexture* ret = cocos2d::RenderTexture::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -48974,7 +50265,7 @@ bool js_cocos2dx_RenderTexture_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -48982,10 +50273,10 @@ bool js_cocos2dx_RenderTexture_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cocos2d::RenderTexture* ret = cocos2d::RenderTexture::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -48997,7 +50288,7 @@ bool js_cocos2dx_RenderTexture_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -49006,7 +50297,7 @@ bool js_cocos2dx_RenderTexture_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_RenderTexture_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::RenderTexture* cobj = new (std::nothrow) cocos2d::RenderTexture(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -49020,13 +50311,16 @@ bool js_cocos2dx_RenderTexture_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::RenderTexture"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::RenderTexture"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -49039,21 +50333,21 @@ void js_cocos2d_RenderTexture_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_RenderTexture_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::RenderTexture *nobj = new (std::nothrow) cocos2d::RenderTexture(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::RenderTexture"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::RenderTexture"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_RenderTexture(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_RenderTexture(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_RenderTexture_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_RenderTexture_class->name = "RenderTexture"; jsb_cocos2d_RenderTexture_class->addProperty = JS_PropertyStub; @@ -49067,8 +50361,8 @@ void js_register_cocos2dx_RenderTexture(JSContext *cx, JSObject *global) { jsb_cocos2d_RenderTexture_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -49106,7 +50400,7 @@ void js_register_cocos2dx_RenderTexture(JSContext *cx, JSObject *global) { jsb_cocos2d_RenderTexture_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_RenderTexture_class, js_cocos2dx_RenderTexture_constructor, 0, // constructor properties, @@ -49137,25 +50431,25 @@ JSObject *jsb_cocos2d_NodeGrid_prototype; bool js_cocos2dx_NodeGrid_setTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::NodeGrid* cobj = (cocos2d::NodeGrid *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_NodeGrid_setTarget : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_NodeGrid_setTarget : Error processing arguments"); cobj->setTarget(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -49164,12 +50458,12 @@ bool js_cocos2dx_NodeGrid_setTarget(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_NodeGrid_getGrid(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::NodeGrid* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::NodeGrid *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_NodeGrid_getGrid : Invalid Native Object"); @@ -49185,7 +50479,7 @@ bool js_cocos2dx_NodeGrid_getGrid(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -49202,7 +50496,7 @@ bool js_cocos2dx_NodeGrid_getGrid(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -49212,6 +50506,7 @@ bool js_cocos2dx_NodeGrid_getGrid(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_NodeGrid_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::NodeGrid* ret = cocos2d::NodeGrid::create(); jsval jsret = JSVAL_NULL; @@ -49223,7 +50518,7 @@ bool js_cocos2dx_NodeGrid_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_NodeGrid_create : wrong number of arguments"); @@ -49232,7 +50527,7 @@ bool js_cocos2dx_NodeGrid_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_NodeGrid_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::NodeGrid* cobj = new (std::nothrow) cocos2d::NodeGrid(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -49246,13 +50541,16 @@ bool js_cocos2dx_NodeGrid_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::NodeGrid"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::NodeGrid"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -49263,7 +50561,7 @@ void js_cocos2d_NodeGrid_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (NodeGrid)", obj); } -void js_register_cocos2dx_NodeGrid(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_NodeGrid(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_NodeGrid_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_NodeGrid_class->name = "NodeGrid"; jsb_cocos2d_NodeGrid_class->addProperty = JS_PropertyStub; @@ -49277,8 +50575,8 @@ void js_register_cocos2dx_NodeGrid(JSContext *cx, JSObject *global) { jsb_cocos2d_NodeGrid_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -49294,7 +50592,7 @@ void js_register_cocos2dx_NodeGrid(JSContext *cx, JSObject *global) { jsb_cocos2d_NodeGrid_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_NodeGrid_class, js_cocos2dx_NodeGrid_constructor, 0, // constructor properties, @@ -49325,25 +50623,25 @@ JSObject *jsb_cocos2d_ParticleBatchNode_prototype; bool js_cocos2dx_ParticleBatchNode_setTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleBatchNode* cobj = (cocos2d::ParticleBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleBatchNode_setTexture : Invalid Native Object"); if (argc == 1) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleBatchNode_setTexture : Error processing arguments"); cobj->setTexture(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -49352,9 +50650,9 @@ bool js_cocos2dx_ParticleBatchNode_setTexture(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ParticleBatchNode_initWithTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleBatchNode* cobj = (cocos2d::ParticleBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleBatchNode_initWithTexture : Invalid Native Object"); @@ -49362,19 +50660,19 @@ bool js_cocos2dx_ParticleBatchNode_initWithTexture(JSContext *cx, uint32_t argc, cocos2d::Texture2D* arg0; int arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleBatchNode_initWithTexture : Error processing arguments"); bool ret = cobj->initWithTexture(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -49383,18 +50681,18 @@ bool js_cocos2dx_ParticleBatchNode_initWithTexture(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleBatchNode_disableParticle(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleBatchNode* cobj = (cocos2d::ParticleBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleBatchNode_disableParticle : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleBatchNode_disableParticle : Error processing arguments"); cobj->disableParticle(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -49403,7 +50701,8 @@ bool js_cocos2dx_ParticleBatchNode_disableParticle(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleBatchNode_getTexture(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleBatchNode* cobj = (cocos2d::ParticleBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleBatchNode_getTexture : Invalid Native Object"); @@ -49418,7 +50717,7 @@ bool js_cocos2dx_ParticleBatchNode_getTexture(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -49427,25 +50726,25 @@ bool js_cocos2dx_ParticleBatchNode_getTexture(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ParticleBatchNode_setTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleBatchNode* cobj = (cocos2d::ParticleBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleBatchNode_setTextureAtlas : Invalid Native Object"); if (argc == 1) { cocos2d::TextureAtlas* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::TextureAtlas*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleBatchNode_setTextureAtlas : Error processing arguments"); cobj->setTextureAtlas(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -49454,22 +50753,22 @@ bool js_cocos2dx_ParticleBatchNode_setTextureAtlas(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleBatchNode_initWithFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleBatchNode* cobj = (cocos2d::ParticleBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleBatchNode_initWithFile : Invalid Native Object"); if (argc == 2) { std::string arg0; int arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleBatchNode_initWithFile : Error processing arguments"); bool ret = cobj->initWithFile(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -49478,18 +50777,18 @@ bool js_cocos2dx_ParticleBatchNode_initWithFile(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ParticleBatchNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleBatchNode* cobj = (cocos2d::ParticleBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleBatchNode_setBlendFunc : Invalid Native Object"); if (argc == 1) { cocos2d::BlendFunc arg0; - ok &= jsval_to_blendfunc(cx, argv[0], &arg0); + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleBatchNode_setBlendFunc : Error processing arguments"); cobj->setBlendFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -49498,18 +50797,18 @@ bool js_cocos2dx_ParticleBatchNode_setBlendFunc(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ParticleBatchNode_removeAllChildrenWithCleanup(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleBatchNode* cobj = (cocos2d::ParticleBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleBatchNode_removeAllChildrenWithCleanup : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleBatchNode_removeAllChildrenWithCleanup : Error processing arguments"); cobj->removeAllChildrenWithCleanup(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -49518,7 +50817,8 @@ bool js_cocos2dx_ParticleBatchNode_removeAllChildrenWithCleanup(JSContext *cx, u } bool js_cocos2dx_ParticleBatchNode_getTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleBatchNode* cobj = (cocos2d::ParticleBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleBatchNode_getTextureAtlas : Invalid Native Object"); @@ -49533,7 +50833,7 @@ bool js_cocos2dx_ParticleBatchNode_getTextureAtlas(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -49542,7 +50842,8 @@ bool js_cocos2dx_ParticleBatchNode_getTextureAtlas(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleBatchNode_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleBatchNode* cobj = (cocos2d::ParticleBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleBatchNode_getBlendFunc : Invalid Native Object"); @@ -49550,7 +50851,7 @@ bool js_cocos2dx_ParticleBatchNode_getBlendFunc(JSContext *cx, uint32_t argc, js const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); jsval jsret = JSVAL_NULL; jsret = blendfunc_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -49559,9 +50860,9 @@ bool js_cocos2dx_ParticleBatchNode_getBlendFunc(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ParticleBatchNode_insertChild(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleBatchNode* cobj = (cocos2d::ParticleBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleBatchNode_insertChild : Invalid Native Object"); @@ -49569,17 +50870,17 @@ bool js_cocos2dx_ParticleBatchNode_insertChild(JSContext *cx, uint32_t argc, jsv cocos2d::ParticleSystem* arg0; int arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ParticleSystem*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleBatchNode_insertChild : Error processing arguments"); cobj->insertChild(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -49588,20 +50889,20 @@ bool js_cocos2dx_ParticleBatchNode_insertChild(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ParticleBatchNode_removeChildAtIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleBatchNode* cobj = (cocos2d::ParticleBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleBatchNode_removeChildAtIndex : Invalid Native Object"); if (argc == 2) { int arg0; bool arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleBatchNode_removeChildAtIndex : Error processing arguments"); cobj->removeChildAtIndex(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -49610,11 +50911,11 @@ bool js_cocos2dx_ParticleBatchNode_removeChildAtIndex(JSContext *cx, uint32_t ar } bool js_cocos2dx_ParticleBatchNode_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleBatchNode_create : Error processing arguments"); cocos2d::ParticleBatchNode* ret = cocos2d::ParticleBatchNode::create(arg0); jsval jsret = JSVAL_NULL; @@ -49626,14 +50927,14 @@ bool js_cocos2dx_ParticleBatchNode_create(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { std::string arg0; int arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleBatchNode_create : Error processing arguments"); cocos2d::ParticleBatchNode* ret = cocos2d::ParticleBatchNode::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -49645,7 +50946,7 @@ bool js_cocos2dx_ParticleBatchNode_create(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleBatchNode_create : wrong number of arguments"); @@ -49654,14 +50955,14 @@ bool js_cocos2dx_ParticleBatchNode_create(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_ParticleBatchNode_createWithTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -49677,21 +50978,21 @@ bool js_cocos2dx_ParticleBatchNode_createWithTexture(JSContext *cx, uint32_t arg jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { cocos2d::Texture2D* arg0; int arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleBatchNode_createWithTexture : Error processing arguments"); cocos2d::ParticleBatchNode* ret = cocos2d::ParticleBatchNode::createWithTexture(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -49703,7 +51004,7 @@ bool js_cocos2dx_ParticleBatchNode_createWithTexture(JSContext *cx, uint32_t arg jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleBatchNode_createWithTexture : wrong number of arguments"); @@ -49712,7 +51013,7 @@ bool js_cocos2dx_ParticleBatchNode_createWithTexture(JSContext *cx, uint32_t arg bool js_cocos2dx_ParticleBatchNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParticleBatchNode* cobj = new (std::nothrow) cocos2d::ParticleBatchNode(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -49726,13 +51027,16 @@ bool js_cocos2dx_ParticleBatchNode_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleBatchNode"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleBatchNode"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -49745,21 +51049,21 @@ void js_cocos2d_ParticleBatchNode_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ParticleBatchNode_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ParticleBatchNode *nobj = new (std::nothrow) cocos2d::ParticleBatchNode(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleBatchNode"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleBatchNode"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ParticleBatchNode(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParticleBatchNode(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParticleBatchNode_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParticleBatchNode_class->name = "ParticleBatchNode"; jsb_cocos2d_ParticleBatchNode_class->addProperty = JS_PropertyStub; @@ -49773,8 +51077,8 @@ void js_register_cocos2dx_ParticleBatchNode(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleBatchNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -49802,7 +51106,7 @@ void js_register_cocos2dx_ParticleBatchNode(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleBatchNode_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_ParticleBatchNode_class, js_cocos2dx_ParticleBatchNode_constructor, 0, // constructor properties, @@ -49833,7 +51137,8 @@ JSObject *jsb_cocos2d_ParticleSystem_prototype; bool js_cocos2dx_ParticleSystem_getStartSizeVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getStartSizeVar : Invalid Native Object"); @@ -49841,7 +51146,7 @@ bool js_cocos2dx_ParticleSystem_getStartSizeVar(JSContext *cx, uint32_t argc, js double ret = cobj->getStartSizeVar(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -49850,7 +51155,8 @@ bool js_cocos2dx_ParticleSystem_getStartSizeVar(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ParticleSystem_getTexture(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getTexture : Invalid Native Object"); @@ -49865,7 +51171,7 @@ bool js_cocos2dx_ParticleSystem_getTexture(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -49874,7 +51180,8 @@ bool js_cocos2dx_ParticleSystem_getTexture(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ParticleSystem_isFull(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_isFull : Invalid Native Object"); @@ -49882,7 +51189,7 @@ bool js_cocos2dx_ParticleSystem_isFull(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isFull(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -49891,7 +51198,8 @@ bool js_cocos2dx_ParticleSystem_isFull(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ParticleSystem_getBatchNode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getBatchNode : Invalid Native Object"); @@ -49906,7 +51214,7 @@ bool js_cocos2dx_ParticleSystem_getBatchNode(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -49915,7 +51223,8 @@ bool js_cocos2dx_ParticleSystem_getBatchNode(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_getStartColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getStartColor : Invalid Native Object"); @@ -49923,7 +51232,7 @@ bool js_cocos2dx_ParticleSystem_getStartColor(JSContext *cx, uint32_t argc, jsva const cocos2d::Color4F& ret = cobj->getStartColor(); jsval jsret = JSVAL_NULL; jsret = cccolor4f_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -49932,7 +51241,8 @@ bool js_cocos2dx_ParticleSystem_getStartColor(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ParticleSystem_getPositionType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getPositionType : Invalid Native Object"); @@ -49940,7 +51250,7 @@ bool js_cocos2dx_ParticleSystem_getPositionType(JSContext *cx, uint32_t argc, js int ret = (int)cobj->getPositionType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -49949,18 +51259,18 @@ bool js_cocos2dx_ParticleSystem_getPositionType(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ParticleSystem_setPosVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setPosVar : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setPosVar : Error processing arguments"); cobj->setPosVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -49969,7 +51279,8 @@ bool js_cocos2dx_ParticleSystem_setPosVar(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ParticleSystem_getEndSpin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getEndSpin : Invalid Native Object"); @@ -49977,7 +51288,7 @@ bool js_cocos2dx_ParticleSystem_getEndSpin(JSContext *cx, uint32_t argc, jsval * double ret = cobj->getEndSpin(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -49986,18 +51297,18 @@ bool js_cocos2dx_ParticleSystem_getEndSpin(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ParticleSystem_setRotatePerSecondVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setRotatePerSecondVar : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setRotatePerSecondVar : Error processing arguments"); cobj->setRotatePerSecondVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50006,7 +51317,8 @@ bool js_cocos2dx_ParticleSystem_setRotatePerSecondVar(JSContext *cx, uint32_t ar } bool js_cocos2dx_ParticleSystem_getStartSpinVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getStartSpinVar : Invalid Native Object"); @@ -50014,7 +51326,7 @@ bool js_cocos2dx_ParticleSystem_getStartSpinVar(JSContext *cx, uint32_t argc, js double ret = cobj->getStartSpinVar(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50023,7 +51335,8 @@ bool js_cocos2dx_ParticleSystem_getStartSpinVar(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ParticleSystem_getRadialAccelVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getRadialAccelVar : Invalid Native Object"); @@ -50031,33 +51344,17 @@ bool js_cocos2dx_ParticleSystem_getRadialAccelVar(JSContext *cx, uint32_t argc, double ret = cobj->getRadialAccelVar(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSystem_getRadialAccelVar : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ParticleSystem_init(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_init : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->init(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_ParticleSystem_init : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_ParticleSystem_getEndSizeVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getEndSizeVar : Invalid Native Object"); @@ -50065,96 +51362,37 @@ bool js_cocos2dx_ParticleSystem_getEndSizeVar(JSContext *cx, uint32_t argc, jsva double ret = cobj->getEndSizeVar(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSystem_getEndSizeVar : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ParticleSystem_setRotation(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setRotation : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setRotation : Error processing arguments"); - cobj->setRotation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_ParticleSystem_setRotation : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_ParticleSystem_setTangentialAccel(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setTangentialAccel : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setTangentialAccel : Error processing arguments"); cobj->setTangentialAccel(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSystem_setTangentialAccel : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ParticleSystem_setScaleY(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setScaleY : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setScaleY : Error processing arguments"); - cobj->setScaleY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_ParticleSystem_setScaleY : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_ParticleSystem_setScaleX(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setScaleX : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setScaleX : Error processing arguments"); - cobj->setScaleX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_ParticleSystem_setScaleX : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_ParticleSystem_getRadialAccel(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getRadialAccel : Invalid Native Object"); @@ -50162,7 +51400,7 @@ bool js_cocos2dx_ParticleSystem_getRadialAccel(JSContext *cx, uint32_t argc, jsv double ret = cobj->getRadialAccel(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50171,18 +51409,18 @@ bool js_cocos2dx_ParticleSystem_getRadialAccel(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ParticleSystem_setStartRadius(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setStartRadius : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setStartRadius : Error processing arguments"); cobj->setStartRadius(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50191,18 +51429,18 @@ bool js_cocos2dx_ParticleSystem_setStartRadius(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ParticleSystem_setRotatePerSecond(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setRotatePerSecond : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setRotatePerSecond : Error processing arguments"); cobj->setRotatePerSecond(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50211,18 +51449,18 @@ bool js_cocos2dx_ParticleSystem_setRotatePerSecond(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleSystem_setEndSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setEndSize : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setEndSize : Error processing arguments"); cobj->setEndSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50231,7 +51469,8 @@ bool js_cocos2dx_ParticleSystem_setEndSize(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ParticleSystem_getGravity(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getGravity : Invalid Native Object"); @@ -50239,7 +51478,7 @@ bool js_cocos2dx_ParticleSystem_getGravity(JSContext *cx, uint32_t argc, jsval * const cocos2d::Vec2& ret = cobj->getGravity(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50248,7 +51487,8 @@ bool js_cocos2dx_ParticleSystem_getGravity(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ParticleSystem_getTangentialAccel(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getTangentialAccel : Invalid Native Object"); @@ -50256,7 +51496,7 @@ bool js_cocos2dx_ParticleSystem_getTangentialAccel(JSContext *cx, uint32_t argc, double ret = cobj->getTangentialAccel(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50265,18 +51505,18 @@ bool js_cocos2dx_ParticleSystem_getTangentialAccel(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleSystem_setEndRadius(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setEndRadius : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setEndRadius : Error processing arguments"); cobj->setEndRadius(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50285,7 +51525,8 @@ bool js_cocos2dx_ParticleSystem_setEndRadius(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_getSpeed(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getSpeed : Invalid Native Object"); @@ -50293,7 +51534,7 @@ bool js_cocos2dx_ParticleSystem_getSpeed(JSContext *cx, uint32_t argc, jsval *vp double ret = cobj->getSpeed(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50302,7 +51543,8 @@ bool js_cocos2dx_ParticleSystem_getSpeed(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ParticleSystem_getAngle(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getAngle : Invalid Native Object"); @@ -50310,7 +51552,7 @@ bool js_cocos2dx_ParticleSystem_getAngle(JSContext *cx, uint32_t argc, jsval *vp double ret = cobj->getAngle(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50319,18 +51561,18 @@ bool js_cocos2dx_ParticleSystem_getAngle(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ParticleSystem_setEndColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setEndColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color4F arg0; - ok &= jsval_to_cccolor4f(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4f(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setEndColor : Error processing arguments"); cobj->setEndColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50339,18 +51581,18 @@ bool js_cocos2dx_ParticleSystem_setEndColor(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_setStartSpin(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setStartSpin : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setStartSpin : Error processing arguments"); cobj->setStartSpin(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50359,18 +51601,18 @@ bool js_cocos2dx_ParticleSystem_setStartSpin(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_setDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setDuration : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setDuration : Error processing arguments"); cobj->setDuration(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50379,20 +51621,20 @@ bool js_cocos2dx_ParticleSystem_setDuration(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_initWithTotalParticles : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_initWithTotalParticles : Error processing arguments"); bool ret = cobj->initWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50401,25 +51643,25 @@ bool js_cocos2dx_ParticleSystem_initWithTotalParticles(JSContext *cx, uint32_t a } bool js_cocos2dx_ParticleSystem_setTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setTexture : Invalid Native Object"); if (argc == 1) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setTexture : Error processing arguments"); cobj->setTexture(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50428,7 +51670,8 @@ bool js_cocos2dx_ParticleSystem_setTexture(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ParticleSystem_getPosVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getPosVar : Invalid Native Object"); @@ -50436,7 +51679,7 @@ bool js_cocos2dx_ParticleSystem_getPosVar(JSContext *cx, uint32_t argc, jsval *v const cocos2d::Vec2& ret = cobj->getPosVar(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50445,13 +51688,14 @@ bool js_cocos2dx_ParticleSystem_getPosVar(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ParticleSystem_updateWithNoTime(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_updateWithNoTime : Invalid Native Object"); if (argc == 0) { cobj->updateWithNoTime(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50460,7 +51704,8 @@ bool js_cocos2dx_ParticleSystem_updateWithNoTime(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ParticleSystem_isBlendAdditive(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_isBlendAdditive : Invalid Native Object"); @@ -50468,7 +51713,7 @@ bool js_cocos2dx_ParticleSystem_isBlendAdditive(JSContext *cx, uint32_t argc, js bool ret = cobj->isBlendAdditive(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50477,7 +51722,8 @@ bool js_cocos2dx_ParticleSystem_isBlendAdditive(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ParticleSystem_getSpeedVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getSpeedVar : Invalid Native Object"); @@ -50485,7 +51731,7 @@ bool js_cocos2dx_ParticleSystem_getSpeedVar(JSContext *cx, uint32_t argc, jsval double ret = cobj->getSpeedVar(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50494,18 +51740,18 @@ bool js_cocos2dx_ParticleSystem_getSpeedVar(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_setPositionType(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setPositionType : Invalid Native Object"); if (argc == 1) { cocos2d::ParticleSystem::PositionType arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setPositionType : Error processing arguments"); cobj->setPositionType(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50514,13 +51760,14 @@ bool js_cocos2dx_ParticleSystem_setPositionType(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ParticleSystem_stopSystem(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_stopSystem : Invalid Native Object"); if (argc == 0) { cobj->stopSystem(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50529,7 +51776,8 @@ bool js_cocos2dx_ParticleSystem_stopSystem(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ParticleSystem_getSourcePosition(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getSourcePosition : Invalid Native Object"); @@ -50537,7 +51785,7 @@ bool js_cocos2dx_ParticleSystem_getSourcePosition(JSContext *cx, uint32_t argc, const cocos2d::Vec2& ret = cobj->getSourcePosition(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50546,18 +51794,18 @@ bool js_cocos2dx_ParticleSystem_getSourcePosition(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleSystem_setLifeVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setLifeVar : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setLifeVar : Error processing arguments"); cobj->setLifeVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50566,18 +51814,18 @@ bool js_cocos2dx_ParticleSystem_setLifeVar(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ParticleSystem_setTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setTotalParticles : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setTotalParticles : Error processing arguments"); cobj->setTotalParticles(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50586,18 +51834,18 @@ bool js_cocos2dx_ParticleSystem_setTotalParticles(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleSystem_setEndColorVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setEndColorVar : Invalid Native Object"); if (argc == 1) { cocos2d::Color4F arg0; - ok &= jsval_to_cccolor4f(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4f(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setEndColorVar : Error processing arguments"); cobj->setEndColorVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50606,9 +51854,9 @@ bool js_cocos2dx_ParticleSystem_setEndColorVar(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ParticleSystem_updateQuadWithParticle(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_updateQuadWithParticle : Invalid Native Object"); @@ -50617,10 +51865,10 @@ bool js_cocos2dx_ParticleSystem_updateQuadWithParticle(JSContext *cx, uint32_t a cocos2d::Vec2 arg1; #pragma warning NO CONVERSION TO NATIVE FOR sParticle* ok = false; - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_updateQuadWithParticle : Error processing arguments"); cobj->updateQuadWithParticle(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50629,7 +51877,8 @@ bool js_cocos2dx_ParticleSystem_updateQuadWithParticle(JSContext *cx, uint32_t a } bool js_cocos2dx_ParticleSystem_getAtlasIndex(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getAtlasIndex : Invalid Native Object"); @@ -50637,7 +51886,7 @@ bool js_cocos2dx_ParticleSystem_getAtlasIndex(JSContext *cx, uint32_t argc, jsva int ret = cobj->getAtlasIndex(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50646,7 +51895,8 @@ bool js_cocos2dx_ParticleSystem_getAtlasIndex(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ParticleSystem_getStartSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getStartSize : Invalid Native Object"); @@ -50654,7 +51904,7 @@ bool js_cocos2dx_ParticleSystem_getStartSize(JSContext *cx, uint32_t argc, jsval double ret = cobj->getStartSize(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50663,18 +51913,18 @@ bool js_cocos2dx_ParticleSystem_getStartSize(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_setStartSpinVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setStartSpinVar : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setStartSpinVar : Error processing arguments"); cobj->setStartSpinVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50683,13 +51933,14 @@ bool js_cocos2dx_ParticleSystem_setStartSpinVar(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ParticleSystem_resetSystem(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_resetSystem : Invalid Native Object"); if (argc == 0) { cobj->resetSystem(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50698,18 +51949,18 @@ bool js_cocos2dx_ParticleSystem_resetSystem(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_setAtlasIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setAtlasIndex : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setAtlasIndex : Error processing arguments"); cobj->setAtlasIndex(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50718,18 +51969,18 @@ bool js_cocos2dx_ParticleSystem_setAtlasIndex(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ParticleSystem_setTangentialAccelVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setTangentialAccelVar : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setTangentialAccelVar : Error processing arguments"); cobj->setTangentialAccelVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50738,18 +51989,18 @@ bool js_cocos2dx_ParticleSystem_setTangentialAccelVar(JSContext *cx, uint32_t ar } bool js_cocos2dx_ParticleSystem_setEndRadiusVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setEndRadiusVar : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setEndRadiusVar : Error processing arguments"); cobj->setEndRadiusVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50758,7 +52009,8 @@ bool js_cocos2dx_ParticleSystem_setEndRadiusVar(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ParticleSystem_getEndRadius(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getEndRadius : Invalid Native Object"); @@ -50766,33 +52018,17 @@ bool js_cocos2dx_ParticleSystem_getEndRadius(JSContext *cx, uint32_t argc, jsval double ret = cobj->getEndRadius(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSystem_getEndRadius : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ParticleSystem_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_isOpacityModifyRGB : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->isOpacityModifyRGB(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_ParticleSystem_isOpacityModifyRGB : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_ParticleSystem_isActive(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_isActive : Invalid Native Object"); @@ -50800,7 +52036,7 @@ bool js_cocos2dx_ParticleSystem_isActive(JSContext *cx, uint32_t argc, jsval *vp bool ret = cobj->isActive(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50809,18 +52045,18 @@ bool js_cocos2dx_ParticleSystem_isActive(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ParticleSystem_setRadialAccelVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setRadialAccelVar : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setRadialAccelVar : Error processing arguments"); cobj->setRadialAccelVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50829,18 +52065,18 @@ bool js_cocos2dx_ParticleSystem_setRadialAccelVar(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleSystem_setStartSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setStartSize : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setStartSize : Error processing arguments"); cobj->setStartSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50849,18 +52085,18 @@ bool js_cocos2dx_ParticleSystem_setStartSize(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_setSpeed(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setSpeed : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setSpeed : Error processing arguments"); cobj->setSpeed(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50869,7 +52105,8 @@ bool js_cocos2dx_ParticleSystem_setSpeed(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ParticleSystem_getStartSpin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getStartSpin : Invalid Native Object"); @@ -50877,7 +52114,7 @@ bool js_cocos2dx_ParticleSystem_getStartSpin(JSContext *cx, uint32_t argc, jsval double ret = cobj->getStartSpin(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50886,7 +52123,8 @@ bool js_cocos2dx_ParticleSystem_getStartSpin(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_getRotatePerSecond(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getRotatePerSecond : Invalid Native Object"); @@ -50894,7 +52132,7 @@ bool js_cocos2dx_ParticleSystem_getRotatePerSecond(JSContext *cx, uint32_t argc, double ret = cobj->getRotatePerSecond(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50903,9 +52141,9 @@ bool js_cocos2dx_ParticleSystem_getRotatePerSecond(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleSystem_initParticle(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_initParticle : Invalid Native Object"); @@ -50915,7 +52153,7 @@ bool js_cocos2dx_ParticleSystem_initParticle(JSContext *cx, uint32_t argc, jsval ok = false; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_initParticle : Error processing arguments"); cobj->initParticle(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50924,18 +52162,18 @@ bool js_cocos2dx_ParticleSystem_initParticle(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_setEmitterMode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setEmitterMode : Invalid Native Object"); if (argc == 1) { cocos2d::ParticleSystem::Mode arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setEmitterMode : Error processing arguments"); cobj->setEmitterMode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50944,7 +52182,8 @@ bool js_cocos2dx_ParticleSystem_setEmitterMode(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ParticleSystem_getDuration(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getDuration : Invalid Native Object"); @@ -50952,7 +52191,7 @@ bool js_cocos2dx_ParticleSystem_getDuration(JSContext *cx, uint32_t argc, jsval double ret = cobj->getDuration(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50961,18 +52200,18 @@ bool js_cocos2dx_ParticleSystem_getDuration(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_setSourcePosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setSourcePosition : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setSourcePosition : Error processing arguments"); cobj->setSourcePosition(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50981,7 +52220,8 @@ bool js_cocos2dx_ParticleSystem_setSourcePosition(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleSystem_getEndSpinVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getEndSpinVar : Invalid Native Object"); @@ -50989,7 +52229,7 @@ bool js_cocos2dx_ParticleSystem_getEndSpinVar(JSContext *cx, uint32_t argc, jsva double ret = cobj->getEndSpinVar(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -50998,18 +52238,18 @@ bool js_cocos2dx_ParticleSystem_getEndSpinVar(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ParticleSystem_setBlendAdditive(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setBlendAdditive : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setBlendAdditive : Error processing arguments"); cobj->setBlendAdditive(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51018,18 +52258,18 @@ bool js_cocos2dx_ParticleSystem_setBlendAdditive(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ParticleSystem_setLife(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setLife : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setLife : Error processing arguments"); cobj->setLife(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51038,18 +52278,18 @@ bool js_cocos2dx_ParticleSystem_setLife(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ParticleSystem_setAngleVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setAngleVar : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setAngleVar : Error processing arguments"); cobj->setAngleVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51058,18 +52298,18 @@ bool js_cocos2dx_ParticleSystem_setAngleVar(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_setRotationIsDir(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setRotationIsDir : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setRotationIsDir : Error processing arguments"); cobj->setRotationIsDir(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51078,18 +52318,18 @@ bool js_cocos2dx_ParticleSystem_setRotationIsDir(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ParticleSystem_setEndSizeVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setEndSizeVar : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setEndSizeVar : Error processing arguments"); cobj->setEndSizeVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51098,18 +52338,18 @@ bool js_cocos2dx_ParticleSystem_setEndSizeVar(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ParticleSystem_setAngle(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setAngle : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setAngle : Error processing arguments"); cobj->setAngle(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51118,25 +52358,25 @@ bool js_cocos2dx_ParticleSystem_setAngle(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ParticleSystem_setBatchNode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setBatchNode : Invalid Native Object"); if (argc == 1) { cocos2d::ParticleBatchNode* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ParticleBatchNode*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setBatchNode : Error processing arguments"); cobj->setBatchNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51145,7 +52385,8 @@ bool js_cocos2dx_ParticleSystem_setBatchNode(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_getTangentialAccelVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getTangentialAccelVar : Invalid Native Object"); @@ -51153,7 +52394,7 @@ bool js_cocos2dx_ParticleSystem_getTangentialAccelVar(JSContext *cx, uint32_t ar double ret = cobj->getTangentialAccelVar(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51162,7 +52403,8 @@ bool js_cocos2dx_ParticleSystem_getTangentialAccelVar(JSContext *cx, uint32_t ar } bool js_cocos2dx_ParticleSystem_getEmitterMode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getEmitterMode : Invalid Native Object"); @@ -51170,7 +52412,7 @@ bool js_cocos2dx_ParticleSystem_getEmitterMode(JSContext *cx, uint32_t argc, jsv int ret = (int)cobj->getEmitterMode(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51179,18 +52421,18 @@ bool js_cocos2dx_ParticleSystem_getEmitterMode(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ParticleSystem_setEndSpinVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setEndSpinVar : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setEndSpinVar : Error processing arguments"); cobj->setEndSpinVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51199,20 +52441,20 @@ bool js_cocos2dx_ParticleSystem_setEndSpinVar(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ParticleSystem_initWithFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_initWithFile : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_initWithFile : Error processing arguments"); bool ret = cobj->initWithFile(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51221,7 +52463,8 @@ bool js_cocos2dx_ParticleSystem_initWithFile(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_getAngleVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getAngleVar : Invalid Native Object"); @@ -51229,7 +52472,7 @@ bool js_cocos2dx_ParticleSystem_getAngleVar(JSContext *cx, uint32_t argc, jsval double ret = cobj->getAngleVar(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51238,18 +52481,18 @@ bool js_cocos2dx_ParticleSystem_getAngleVar(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_setStartColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setStartColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color4F arg0; - ok &= jsval_to_cccolor4f(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4f(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setStartColor : Error processing arguments"); cobj->setStartColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51258,7 +52501,8 @@ bool js_cocos2dx_ParticleSystem_setStartColor(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ParticleSystem_getRotatePerSecondVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getRotatePerSecondVar : Invalid Native Object"); @@ -51266,7 +52510,7 @@ bool js_cocos2dx_ParticleSystem_getRotatePerSecondVar(JSContext *cx, uint32_t ar double ret = cobj->getRotatePerSecondVar(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51275,7 +52519,8 @@ bool js_cocos2dx_ParticleSystem_getRotatePerSecondVar(JSContext *cx, uint32_t ar } bool js_cocos2dx_ParticleSystem_getEndSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getEndSize : Invalid Native Object"); @@ -51283,7 +52528,7 @@ bool js_cocos2dx_ParticleSystem_getEndSize(JSContext *cx, uint32_t argc, jsval * double ret = cobj->getEndSize(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51292,7 +52537,8 @@ bool js_cocos2dx_ParticleSystem_getEndSize(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ParticleSystem_getLife(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getLife : Invalid Native Object"); @@ -51300,7 +52546,7 @@ bool js_cocos2dx_ParticleSystem_getLife(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getLife(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51309,18 +52555,18 @@ bool js_cocos2dx_ParticleSystem_getLife(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ParticleSystem_setSpeedVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setSpeedVar : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setSpeedVar : Error processing arguments"); cobj->setSpeedVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51329,18 +52575,18 @@ bool js_cocos2dx_ParticleSystem_setSpeedVar(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_setAutoRemoveOnFinish(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setAutoRemoveOnFinish : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setAutoRemoveOnFinish : Error processing arguments"); cobj->setAutoRemoveOnFinish(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51349,18 +52595,18 @@ bool js_cocos2dx_ParticleSystem_setAutoRemoveOnFinish(JSContext *cx, uint32_t ar } bool js_cocos2dx_ParticleSystem_setGravity(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setGravity : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setGravity : Error processing arguments"); cobj->setGravity(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51369,13 +52615,14 @@ bool js_cocos2dx_ParticleSystem_setGravity(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ParticleSystem_postStep(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_postStep : Invalid Native Object"); if (argc == 0) { cobj->postStep(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51384,18 +52631,18 @@ bool js_cocos2dx_ParticleSystem_postStep(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ParticleSystem_setEmissionRate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setEmissionRate : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setEmissionRate : Error processing arguments"); cobj->setEmissionRate(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51404,7 +52651,8 @@ bool js_cocos2dx_ParticleSystem_setEmissionRate(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ParticleSystem_getEndColorVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getEndColorVar : Invalid Native Object"); @@ -51412,7 +52660,7 @@ bool js_cocos2dx_ParticleSystem_getEndColorVar(JSContext *cx, uint32_t argc, jsv const cocos2d::Color4F& ret = cobj->getEndColorVar(); jsval jsret = JSVAL_NULL; jsret = cccolor4f_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51421,7 +52669,8 @@ bool js_cocos2dx_ParticleSystem_getEndColorVar(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ParticleSystem_getRotationIsDir(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getRotationIsDir : Invalid Native Object"); @@ -51429,36 +52678,17 @@ bool js_cocos2dx_ParticleSystem_getRotationIsDir(JSContext *cx, uint32_t argc, j bool ret = cobj->getRotationIsDir(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSystem_getRotationIsDir : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ParticleSystem_setScale(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setScale : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setScale : Error processing arguments"); - cobj->setScale(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_ParticleSystem_setScale : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_ParticleSystem_getEmissionRate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getEmissionRate : Invalid Native Object"); @@ -51466,7 +52696,7 @@ bool js_cocos2dx_ParticleSystem_getEmissionRate(JSContext *cx, uint32_t argc, js double ret = cobj->getEmissionRate(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51475,7 +52705,8 @@ bool js_cocos2dx_ParticleSystem_getEmissionRate(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ParticleSystem_getEndColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getEndColor : Invalid Native Object"); @@ -51483,7 +52714,7 @@ bool js_cocos2dx_ParticleSystem_getEndColor(JSContext *cx, uint32_t argc, jsval const cocos2d::Color4F& ret = cobj->getEndColor(); jsval jsret = JSVAL_NULL; jsret = cccolor4f_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51492,7 +52723,8 @@ bool js_cocos2dx_ParticleSystem_getEndColor(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_getLifeVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getLifeVar : Invalid Native Object"); @@ -51500,7 +52732,7 @@ bool js_cocos2dx_ParticleSystem_getLifeVar(JSContext *cx, uint32_t argc, jsval * double ret = cobj->getLifeVar(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51509,47 +52741,28 @@ bool js_cocos2dx_ParticleSystem_getLifeVar(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ParticleSystem_setStartSizeVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setStartSizeVar : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setStartSizeVar : Error processing arguments"); cobj->setStartSizeVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSystem_setStartSizeVar : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ParticleSystem_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setOpacityModifyRGB : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setOpacityModifyRGB : Error processing arguments"); - cobj->setOpacityModifyRGB(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_ParticleSystem_setOpacityModifyRGB : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_ParticleSystem_addParticle(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_addParticle : Invalid Native Object"); @@ -51557,7 +52770,7 @@ bool js_cocos2dx_ParticleSystem_addParticle(JSContext *cx, uint32_t argc, jsval bool ret = cobj->addParticle(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51566,7 +52779,8 @@ bool js_cocos2dx_ParticleSystem_addParticle(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_getStartRadius(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getStartRadius : Invalid Native Object"); @@ -51574,7 +52788,7 @@ bool js_cocos2dx_ParticleSystem_getStartRadius(JSContext *cx, uint32_t argc, jsv double ret = cobj->getStartRadius(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51583,7 +52797,8 @@ bool js_cocos2dx_ParticleSystem_getStartRadius(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ParticleSystem_getParticleCount(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getParticleCount : Invalid Native Object"); @@ -51591,7 +52806,7 @@ bool js_cocos2dx_ParticleSystem_getParticleCount(JSContext *cx, uint32_t argc, j unsigned int ret = cobj->getParticleCount(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51600,7 +52815,8 @@ bool js_cocos2dx_ParticleSystem_getParticleCount(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ParticleSystem_getStartRadiusVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getStartRadiusVar : Invalid Native Object"); @@ -51608,7 +52824,7 @@ bool js_cocos2dx_ParticleSystem_getStartRadiusVar(JSContext *cx, uint32_t argc, double ret = cobj->getStartRadiusVar(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51617,7 +52833,8 @@ bool js_cocos2dx_ParticleSystem_getStartRadiusVar(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleSystem_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getBlendFunc : Invalid Native Object"); @@ -51625,7 +52842,7 @@ bool js_cocos2dx_ParticleSystem_getBlendFunc(JSContext *cx, uint32_t argc, jsval const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); jsval jsret = JSVAL_NULL; jsret = blendfunc_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51634,18 +52851,18 @@ bool js_cocos2dx_ParticleSystem_getBlendFunc(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_setStartColorVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setStartColorVar : Invalid Native Object"); if (argc == 1) { cocos2d::Color4F arg0; - ok &= jsval_to_cccolor4f(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4f(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setStartColorVar : Error processing arguments"); cobj->setStartColorVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51654,18 +52871,18 @@ bool js_cocos2dx_ParticleSystem_setStartColorVar(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ParticleSystem_setEndSpin(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setEndSpin : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setEndSpin : Error processing arguments"); cobj->setEndSpin(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51674,18 +52891,18 @@ bool js_cocos2dx_ParticleSystem_setEndSpin(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ParticleSystem_setRadialAccel(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setRadialAccel : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setRadialAccel : Error processing arguments"); cobj->setRadialAccel(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51694,27 +52911,27 @@ bool js_cocos2dx_ParticleSystem_setRadialAccel(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ParticleSystem_initWithDictionary(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::ParticleSystem* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_initWithDictionary : Invalid Native Object"); do { if (argc == 2) { cocos2d::ValueMap arg0; - ok &= jsval_to_ccvaluemap(cx, argv[0], &arg0); + ok &= jsval_to_ccvaluemap(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } bool ret = cobj->initWithDictionary(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -51722,12 +52939,12 @@ bool js_cocos2dx_ParticleSystem_initWithDictionary(JSContext *cx, uint32_t argc, do { if (argc == 1) { cocos2d::ValueMap arg0; - ok &= jsval_to_ccvaluemap(cx, argv[0], &arg0); + ok &= jsval_to_ccvaluemap(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } bool ret = cobj->initWithDictionary(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -51737,7 +52954,8 @@ bool js_cocos2dx_ParticleSystem_initWithDictionary(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleSystem_isAutoRemoveOnFinish(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_isAutoRemoveOnFinish : Invalid Native Object"); @@ -51745,7 +52963,7 @@ bool js_cocos2dx_ParticleSystem_isAutoRemoveOnFinish(JSContext *cx, uint32_t arg bool ret = cobj->isAutoRemoveOnFinish(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51754,7 +52972,8 @@ bool js_cocos2dx_ParticleSystem_isAutoRemoveOnFinish(JSContext *cx, uint32_t arg } bool js_cocos2dx_ParticleSystem_getTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getTotalParticles : Invalid Native Object"); @@ -51762,7 +52981,7 @@ bool js_cocos2dx_ParticleSystem_getTotalParticles(JSContext *cx, uint32_t argc, int ret = cobj->getTotalParticles(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51771,18 +52990,18 @@ bool js_cocos2dx_ParticleSystem_getTotalParticles(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleSystem_setStartRadiusVar(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setStartRadiusVar : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setStartRadiusVar : Error processing arguments"); cobj->setStartRadiusVar(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51791,18 +53010,18 @@ bool js_cocos2dx_ParticleSystem_setStartRadiusVar(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleSystem_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_setBlendFunc : Invalid Native Object"); if (argc == 1) { cocos2d::BlendFunc arg0; - ok &= jsval_to_blendfunc(cx, argv[0], &arg0); + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setBlendFunc : Error processing arguments"); cobj->setBlendFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -51811,7 +53030,8 @@ bool js_cocos2dx_ParticleSystem_setBlendFunc(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_getEndRadiusVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getEndRadiusVar : Invalid Native Object"); @@ -51819,7 +53039,7 @@ bool js_cocos2dx_ParticleSystem_getEndRadiusVar(JSContext *cx, uint32_t argc, js double ret = cobj->getEndRadiusVar(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51828,7 +53048,8 @@ bool js_cocos2dx_ParticleSystem_getEndRadiusVar(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ParticleSystem_getStartColorVar(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_getStartColorVar : Invalid Native Object"); @@ -51836,7 +53057,7 @@ bool js_cocos2dx_ParticleSystem_getStartColorVar(JSContext *cx, uint32_t argc, j const cocos2d::Color4F& ret = cobj->getStartColorVar(); jsval jsret = JSVAL_NULL; jsret = cccolor4f_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -51845,11 +53066,11 @@ bool js_cocos2dx_ParticleSystem_getStartColorVar(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ParticleSystem_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_create : Error processing arguments"); cocos2d::ParticleSystem* ret = cocos2d::ParticleSystem::create(arg0); jsval jsret = JSVAL_NULL; @@ -51861,7 +53082,7 @@ bool js_cocos2dx_ParticleSystem_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSystem_create : wrong number of arguments"); @@ -51870,11 +53091,11 @@ bool js_cocos2dx_ParticleSystem_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ParticleSystem_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_createWithTotalParticles : Error processing arguments"); cocos2d::ParticleSystem* ret = cocos2d::ParticleSystem::createWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; @@ -51886,7 +53107,7 @@ bool js_cocos2dx_ParticleSystem_createWithTotalParticles(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSystem_createWithTotalParticles : wrong number of arguments"); @@ -51895,7 +53116,7 @@ bool js_cocos2dx_ParticleSystem_createWithTotalParticles(JSContext *cx, uint32_t bool js_cocos2dx_ParticleSystem_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParticleSystem* cobj = new (std::nothrow) cocos2d::ParticleSystem(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -51909,13 +53130,16 @@ bool js_cocos2dx_ParticleSystem_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSystem"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSystem"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -51928,21 +53152,21 @@ void js_cocos2d_ParticleSystem_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ParticleSystem_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ParticleSystem *nobj = new (std::nothrow) cocos2d::ParticleSystem(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSystem"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSystem"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ParticleSystem(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParticleSystem(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParticleSystem_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParticleSystem_class->name = "ParticleSystem"; jsb_cocos2d_ParticleSystem_class->addProperty = JS_PropertyStub; @@ -51956,8 +53180,8 @@ void js_register_cocos2dx_ParticleSystem(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleSystem_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -51972,12 +53196,8 @@ void js_register_cocos2dx_ParticleSystem(JSContext *cx, JSObject *global) { JS_FN("setRotatePerSecondVar", js_cocos2dx_ParticleSystem_setRotatePerSecondVar, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getStartSpinVar", js_cocos2dx_ParticleSystem_getStartSpinVar, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getRadialAccelVar", js_cocos2dx_ParticleSystem_getRadialAccelVar, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_ParticleSystem_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getEndSizeVar", js_cocos2dx_ParticleSystem_getEndSizeVar, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setRotation", js_cocos2dx_ParticleSystem_setRotation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setTangentialAccel", js_cocos2dx_ParticleSystem_setTangentialAccel, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setScaleY", js_cocos2dx_ParticleSystem_setScaleY, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setScaleX", js_cocos2dx_ParticleSystem_setScaleX, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getRadialAccel", js_cocos2dx_ParticleSystem_getRadialAccel, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setStartRadius", js_cocos2dx_ParticleSystem_setStartRadius, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRotatePerSecond", js_cocos2dx_ParticleSystem_setRotatePerSecond, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -52011,7 +53231,6 @@ void js_register_cocos2dx_ParticleSystem(JSContext *cx, JSObject *global) { JS_FN("setTangentialAccelVar", js_cocos2dx_ParticleSystem_setTangentialAccelVar, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setEndRadiusVar", js_cocos2dx_ParticleSystem_setEndRadiusVar, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getEndRadius", js_cocos2dx_ParticleSystem_getEndRadius, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("isOpacityModifyRGB", js_cocos2dx_ParticleSystem_isOpacityModifyRGB, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isActive", js_cocos2dx_ParticleSystem_isActive, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setRadialAccelVar", js_cocos2dx_ParticleSystem_setRadialAccelVar, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setStartSize", js_cocos2dx_ParticleSystem_setStartSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -52046,12 +53265,10 @@ void js_register_cocos2dx_ParticleSystem(JSContext *cx, JSObject *global) { JS_FN("setEmissionRate", js_cocos2dx_ParticleSystem_setEmissionRate, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getEndColorVar", js_cocos2dx_ParticleSystem_getEndColorVar, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getRotationIsDir", js_cocos2dx_ParticleSystem_getRotationIsDir, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setScale", js_cocos2dx_ParticleSystem_setScale, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getEmissionRate", js_cocos2dx_ParticleSystem_getEmissionRate, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getEndColor", js_cocos2dx_ParticleSystem_getEndColor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getLifeVar", js_cocos2dx_ParticleSystem_getLifeVar, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setStartSizeVar", js_cocos2dx_ParticleSystem_setStartSizeVar, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setOpacityModifyRGB", js_cocos2dx_ParticleSystem_setOpacityModifyRGB, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("addParticle", js_cocos2dx_ParticleSystem_addParticle, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getStartRadius", js_cocos2dx_ParticleSystem_getStartRadius, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getParticleCount", js_cocos2dx_ParticleSystem_getParticleCount, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -52079,7 +53296,7 @@ void js_register_cocos2dx_ParticleSystem(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleSystem_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_ParticleSystem_class, js_cocos2dx_ParticleSystem_constructor, 0, // constructor properties, @@ -52110,25 +53327,25 @@ JSObject *jsb_cocos2d_ParticleSystemQuad_prototype; bool js_cocos2dx_ParticleSystemQuad_setDisplayFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystemQuad* cobj = (cocos2d::ParticleSystemQuad *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystemQuad_setDisplayFrame : Invalid Native Object"); if (argc == 1) { cocos2d::SpriteFrame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystemQuad_setDisplayFrame : Error processing arguments"); cobj->setDisplayFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -52137,9 +53354,9 @@ bool js_cocos2dx_ParticleSystemQuad_setDisplayFrame(JSContext *cx, uint32_t argc } bool js_cocos2dx_ParticleSystemQuad_setTextureWithRect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystemQuad* cobj = (cocos2d::ParticleSystemQuad *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystemQuad_setTextureWithRect : Invalid Native Object"); @@ -52147,17 +53364,17 @@ bool js_cocos2dx_ParticleSystemQuad_setTextureWithRect(JSContext *cx, uint32_t a cocos2d::Texture2D* arg0; cocos2d::Rect arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystemQuad_setTextureWithRect : Error processing arguments"); cobj->setTextureWithRect(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -52166,25 +53383,25 @@ bool js_cocos2dx_ParticleSystemQuad_setTextureWithRect(JSContext *cx, uint32_t a } bool js_cocos2dx_ParticleSystemQuad_listenRendererRecreated(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSystemQuad* cobj = (cocos2d::ParticleSystemQuad *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystemQuad_listenRendererRecreated : Invalid Native Object"); if (argc == 1) { cocos2d::EventCustom* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::EventCustom*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystemQuad_listenRendererRecreated : Error processing arguments"); cobj->listenRendererRecreated(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -52193,13 +53410,13 @@ bool js_cocos2dx_ParticleSystemQuad_listenRendererRecreated(JSContext *cx, uint3 } bool js_cocos2dx_ParticleSystemQuad_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::ParticleSystemQuad* ret = cocos2d::ParticleSystemQuad::create(arg0); jsval jsret = JSVAL_NULL; @@ -52211,7 +53428,7 @@ bool js_cocos2dx_ParticleSystemQuad_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -52228,7 +53445,7 @@ bool js_cocos2dx_ParticleSystemQuad_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -52236,7 +53453,7 @@ bool js_cocos2dx_ParticleSystemQuad_create(JSContext *cx, uint32_t argc, jsval * do { if (argc == 1) { cocos2d::ValueMap arg0; - ok &= jsval_to_ccvaluemap(cx, argv[0], &arg0); + ok &= jsval_to_ccvaluemap(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::ParticleSystemQuad* ret = cocos2d::ParticleSystemQuad::create(arg0); jsval jsret = JSVAL_NULL; @@ -52248,7 +53465,7 @@ bool js_cocos2dx_ParticleSystemQuad_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -52257,11 +53474,11 @@ bool js_cocos2dx_ParticleSystemQuad_create(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ParticleSystemQuad_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystemQuad_createWithTotalParticles : Error processing arguments"); cocos2d::ParticleSystemQuad* ret = cocos2d::ParticleSystemQuad::createWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; @@ -52273,7 +53490,7 @@ bool js_cocos2dx_ParticleSystemQuad_createWithTotalParticles(JSContext *cx, uint jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSystemQuad_createWithTotalParticles : wrong number of arguments"); @@ -52282,7 +53499,7 @@ bool js_cocos2dx_ParticleSystemQuad_createWithTotalParticles(JSContext *cx, uint bool js_cocos2dx_ParticleSystemQuad_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParticleSystemQuad* cobj = new (std::nothrow) cocos2d::ParticleSystemQuad(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -52296,13 +53513,16 @@ bool js_cocos2dx_ParticleSystemQuad_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSystemQuad"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSystemQuad"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -52313,7 +53533,7 @@ void js_cocos2d_ParticleSystemQuad_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ParticleSystemQuad)", obj); } -void js_register_cocos2dx_ParticleSystemQuad(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParticleSystemQuad(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParticleSystemQuad_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParticleSystemQuad_class->name = "ParticleSystem"; jsb_cocos2d_ParticleSystemQuad_class->addProperty = JS_PropertyStub; @@ -52327,8 +53547,8 @@ void js_register_cocos2dx_ParticleSystemQuad(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleSystemQuad_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -52346,7 +53566,7 @@ void js_register_cocos2dx_ParticleSystemQuad(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleSystemQuad_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ParticleSystem_prototype, + JS::RootedObject(cx, jsb_cocos2d_ParticleSystem_prototype), jsb_cocos2d_ParticleSystemQuad_class, js_cocos2dx_ParticleSystemQuad_constructor, 0, // constructor properties, @@ -52375,25 +53595,9 @@ void js_register_cocos2dx_ParticleSystemQuad(JSContext *cx, JSObject *global) { JSClass *jsb_cocos2d_ParticleFire_class; JSObject *jsb_cocos2d_ParticleFire_prototype; -bool js_cocos2dx_ParticleFire_init(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ParticleFire* cobj = (cocos2d::ParticleFire *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleFire_init : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->init(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_ParticleFire_init : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_ParticleFire_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ParticleFire* ret = cocos2d::ParticleFire::create(); jsval jsret = JSVAL_NULL; @@ -52405,7 +53609,7 @@ bool js_cocos2dx_ParticleFire_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleFire_create : wrong number of arguments"); @@ -52414,11 +53618,11 @@ bool js_cocos2dx_ParticleFire_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ParticleFire_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleFire_createWithTotalParticles : Error processing arguments"); cocos2d::ParticleFire* ret = cocos2d::ParticleFire::createWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; @@ -52430,7 +53634,7 @@ bool js_cocos2dx_ParticleFire_createWithTotalParticles(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleFire_createWithTotalParticles : wrong number of arguments"); @@ -52439,7 +53643,7 @@ bool js_cocos2dx_ParticleFire_createWithTotalParticles(JSContext *cx, uint32_t a bool js_cocos2dx_ParticleFire_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParticleFire* cobj = new (std::nothrow) cocos2d::ParticleFire(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -52453,13 +53657,16 @@ bool js_cocos2dx_ParticleFire_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleFire"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleFire"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -52470,7 +53677,7 @@ void js_cocos2d_ParticleFire_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ParticleFire)", obj); } -void js_register_cocos2dx_ParticleFire(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParticleFire(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParticleFire_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParticleFire_class->name = "ParticleFire"; jsb_cocos2d_ParticleFire_class->addProperty = JS_PropertyStub; @@ -52484,12 +53691,11 @@ void js_register_cocos2dx_ParticleFire(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleFire_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("init", js_cocos2dx_ParticleFire_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -52501,7 +53707,7 @@ void js_register_cocos2dx_ParticleFire(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleFire_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ParticleSystemQuad_prototype, + JS::RootedObject(cx, jsb_cocos2d_ParticleSystemQuad_prototype), jsb_cocos2d_ParticleFire_class, js_cocos2dx_ParticleFire_constructor, 0, // constructor properties, @@ -52532,7 +53738,8 @@ JSObject *jsb_cocos2d_ParticleFireworks_prototype; bool js_cocos2dx_ParticleFireworks_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleFireworks* cobj = (cocos2d::ParticleFireworks *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleFireworks_init : Invalid Native Object"); @@ -52540,7 +53747,7 @@ bool js_cocos2dx_ParticleFireworks_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -52549,20 +53756,20 @@ bool js_cocos2dx_ParticleFireworks_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ParticleFireworks_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleFireworks* cobj = (cocos2d::ParticleFireworks *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleFireworks_initWithTotalParticles : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleFireworks_initWithTotalParticles : Error processing arguments"); bool ret = cobj->initWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -52571,6 +53778,7 @@ bool js_cocos2dx_ParticleFireworks_initWithTotalParticles(JSContext *cx, uint32_ } bool js_cocos2dx_ParticleFireworks_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ParticleFireworks* ret = cocos2d::ParticleFireworks::create(); jsval jsret = JSVAL_NULL; @@ -52582,7 +53790,7 @@ bool js_cocos2dx_ParticleFireworks_create(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleFireworks_create : wrong number of arguments"); @@ -52591,11 +53799,11 @@ bool js_cocos2dx_ParticleFireworks_create(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_ParticleFireworks_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleFireworks_createWithTotalParticles : Error processing arguments"); cocos2d::ParticleFireworks* ret = cocos2d::ParticleFireworks::createWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; @@ -52607,7 +53815,7 @@ bool js_cocos2dx_ParticleFireworks_createWithTotalParticles(JSContext *cx, uint3 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleFireworks_createWithTotalParticles : wrong number of arguments"); @@ -52616,7 +53824,7 @@ bool js_cocos2dx_ParticleFireworks_createWithTotalParticles(JSContext *cx, uint3 bool js_cocos2dx_ParticleFireworks_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParticleFireworks* cobj = new (std::nothrow) cocos2d::ParticleFireworks(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -52630,13 +53838,16 @@ bool js_cocos2dx_ParticleFireworks_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleFireworks"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleFireworks"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -52647,7 +53858,7 @@ void js_cocos2d_ParticleFireworks_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ParticleFireworks)", obj); } -void js_register_cocos2dx_ParticleFireworks(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParticleFireworks(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParticleFireworks_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParticleFireworks_class->name = "ParticleFireworks"; jsb_cocos2d_ParticleFireworks_class->addProperty = JS_PropertyStub; @@ -52661,8 +53872,8 @@ void js_register_cocos2dx_ParticleFireworks(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleFireworks_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -52679,7 +53890,7 @@ void js_register_cocos2dx_ParticleFireworks(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleFireworks_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ParticleSystemQuad_prototype, + JS::RootedObject(cx, jsb_cocos2d_ParticleSystemQuad_prototype), jsb_cocos2d_ParticleFireworks_class, js_cocos2dx_ParticleFireworks_constructor, 0, // constructor properties, @@ -52710,7 +53921,8 @@ JSObject *jsb_cocos2d_ParticleSun_prototype; bool js_cocos2dx_ParticleSun_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSun* cobj = (cocos2d::ParticleSun *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSun_init : Invalid Native Object"); @@ -52718,7 +53930,7 @@ bool js_cocos2dx_ParticleSun_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -52727,20 +53939,20 @@ bool js_cocos2dx_ParticleSun_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ParticleSun_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSun* cobj = (cocos2d::ParticleSun *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSun_initWithTotalParticles : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSun_initWithTotalParticles : Error processing arguments"); bool ret = cobj->initWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -52749,6 +53961,7 @@ bool js_cocos2dx_ParticleSun_initWithTotalParticles(JSContext *cx, uint32_t argc } bool js_cocos2dx_ParticleSun_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ParticleSun* ret = cocos2d::ParticleSun::create(); jsval jsret = JSVAL_NULL; @@ -52760,7 +53973,7 @@ bool js_cocos2dx_ParticleSun_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSun_create : wrong number of arguments"); @@ -52769,11 +53982,11 @@ bool js_cocos2dx_ParticleSun_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ParticleSun_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSun_createWithTotalParticles : Error processing arguments"); cocos2d::ParticleSun* ret = cocos2d::ParticleSun::createWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; @@ -52785,7 +53998,7 @@ bool js_cocos2dx_ParticleSun_createWithTotalParticles(JSContext *cx, uint32_t ar jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSun_createWithTotalParticles : wrong number of arguments"); @@ -52794,7 +54007,7 @@ bool js_cocos2dx_ParticleSun_createWithTotalParticles(JSContext *cx, uint32_t ar bool js_cocos2dx_ParticleSun_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParticleSun* cobj = new (std::nothrow) cocos2d::ParticleSun(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -52808,13 +54021,16 @@ bool js_cocos2dx_ParticleSun_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSun"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSun"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -52825,7 +54041,7 @@ void js_cocos2d_ParticleSun_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ParticleSun)", obj); } -void js_register_cocos2dx_ParticleSun(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParticleSun(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParticleSun_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParticleSun_class->name = "ParticleSun"; jsb_cocos2d_ParticleSun_class->addProperty = JS_PropertyStub; @@ -52839,8 +54055,8 @@ void js_register_cocos2dx_ParticleSun(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleSun_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -52857,7 +54073,7 @@ void js_register_cocos2dx_ParticleSun(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleSun_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ParticleSystemQuad_prototype, + JS::RootedObject(cx, jsb_cocos2d_ParticleSystemQuad_prototype), jsb_cocos2d_ParticleSun_class, js_cocos2dx_ParticleSun_constructor, 0, // constructor properties, @@ -52888,7 +54104,8 @@ JSObject *jsb_cocos2d_ParticleGalaxy_prototype; bool js_cocos2dx_ParticleGalaxy_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleGalaxy* cobj = (cocos2d::ParticleGalaxy *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleGalaxy_init : Invalid Native Object"); @@ -52896,7 +54113,7 @@ bool js_cocos2dx_ParticleGalaxy_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -52905,20 +54122,20 @@ bool js_cocos2dx_ParticleGalaxy_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ParticleGalaxy_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleGalaxy* cobj = (cocos2d::ParticleGalaxy *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleGalaxy_initWithTotalParticles : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleGalaxy_initWithTotalParticles : Error processing arguments"); bool ret = cobj->initWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -52927,6 +54144,7 @@ bool js_cocos2dx_ParticleGalaxy_initWithTotalParticles(JSContext *cx, uint32_t a } bool js_cocos2dx_ParticleGalaxy_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ParticleGalaxy* ret = cocos2d::ParticleGalaxy::create(); jsval jsret = JSVAL_NULL; @@ -52938,7 +54156,7 @@ bool js_cocos2dx_ParticleGalaxy_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleGalaxy_create : wrong number of arguments"); @@ -52947,11 +54165,11 @@ bool js_cocos2dx_ParticleGalaxy_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ParticleGalaxy_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleGalaxy_createWithTotalParticles : Error processing arguments"); cocos2d::ParticleGalaxy* ret = cocos2d::ParticleGalaxy::createWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; @@ -52963,7 +54181,7 @@ bool js_cocos2dx_ParticleGalaxy_createWithTotalParticles(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleGalaxy_createWithTotalParticles : wrong number of arguments"); @@ -52972,7 +54190,7 @@ bool js_cocos2dx_ParticleGalaxy_createWithTotalParticles(JSContext *cx, uint32_t bool js_cocos2dx_ParticleGalaxy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParticleGalaxy* cobj = new (std::nothrow) cocos2d::ParticleGalaxy(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -52986,13 +54204,16 @@ bool js_cocos2dx_ParticleGalaxy_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleGalaxy"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleGalaxy"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -53003,7 +54224,7 @@ void js_cocos2d_ParticleGalaxy_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ParticleGalaxy)", obj); } -void js_register_cocos2dx_ParticleGalaxy(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParticleGalaxy(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParticleGalaxy_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParticleGalaxy_class->name = "ParticleGalaxy"; jsb_cocos2d_ParticleGalaxy_class->addProperty = JS_PropertyStub; @@ -53017,8 +54238,8 @@ void js_register_cocos2dx_ParticleGalaxy(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleGalaxy_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -53035,7 +54256,7 @@ void js_register_cocos2dx_ParticleGalaxy(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleGalaxy_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ParticleSystemQuad_prototype, + JS::RootedObject(cx, jsb_cocos2d_ParticleSystemQuad_prototype), jsb_cocos2d_ParticleGalaxy_class, js_cocos2dx_ParticleGalaxy_constructor, 0, // constructor properties, @@ -53066,7 +54287,8 @@ JSObject *jsb_cocos2d_ParticleFlower_prototype; bool js_cocos2dx_ParticleFlower_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleFlower* cobj = (cocos2d::ParticleFlower *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleFlower_init : Invalid Native Object"); @@ -53074,7 +54296,7 @@ bool js_cocos2dx_ParticleFlower_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -53083,20 +54305,20 @@ bool js_cocos2dx_ParticleFlower_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ParticleFlower_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleFlower* cobj = (cocos2d::ParticleFlower *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleFlower_initWithTotalParticles : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleFlower_initWithTotalParticles : Error processing arguments"); bool ret = cobj->initWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -53105,6 +54327,7 @@ bool js_cocos2dx_ParticleFlower_initWithTotalParticles(JSContext *cx, uint32_t a } bool js_cocos2dx_ParticleFlower_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ParticleFlower* ret = cocos2d::ParticleFlower::create(); jsval jsret = JSVAL_NULL; @@ -53116,7 +54339,7 @@ bool js_cocos2dx_ParticleFlower_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleFlower_create : wrong number of arguments"); @@ -53125,11 +54348,11 @@ bool js_cocos2dx_ParticleFlower_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ParticleFlower_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleFlower_createWithTotalParticles : Error processing arguments"); cocos2d::ParticleFlower* ret = cocos2d::ParticleFlower::createWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; @@ -53141,7 +54364,7 @@ bool js_cocos2dx_ParticleFlower_createWithTotalParticles(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleFlower_createWithTotalParticles : wrong number of arguments"); @@ -53150,7 +54373,7 @@ bool js_cocos2dx_ParticleFlower_createWithTotalParticles(JSContext *cx, uint32_t bool js_cocos2dx_ParticleFlower_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParticleFlower* cobj = new (std::nothrow) cocos2d::ParticleFlower(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -53164,13 +54387,16 @@ bool js_cocos2dx_ParticleFlower_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleFlower"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleFlower"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -53181,7 +54407,7 @@ void js_cocos2d_ParticleFlower_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ParticleFlower)", obj); } -void js_register_cocos2dx_ParticleFlower(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParticleFlower(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParticleFlower_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParticleFlower_class->name = "ParticleFlower"; jsb_cocos2d_ParticleFlower_class->addProperty = JS_PropertyStub; @@ -53195,8 +54421,8 @@ void js_register_cocos2dx_ParticleFlower(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleFlower_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -53213,7 +54439,7 @@ void js_register_cocos2dx_ParticleFlower(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleFlower_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ParticleSystemQuad_prototype, + JS::RootedObject(cx, jsb_cocos2d_ParticleSystemQuad_prototype), jsb_cocos2d_ParticleFlower_class, js_cocos2dx_ParticleFlower_constructor, 0, // constructor properties, @@ -53244,7 +54470,8 @@ JSObject *jsb_cocos2d_ParticleMeteor_prototype; bool js_cocos2dx_ParticleMeteor_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleMeteor* cobj = (cocos2d::ParticleMeteor *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleMeteor_init : Invalid Native Object"); @@ -53252,7 +54479,7 @@ bool js_cocos2dx_ParticleMeteor_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -53261,20 +54488,20 @@ bool js_cocos2dx_ParticleMeteor_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ParticleMeteor_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleMeteor* cobj = (cocos2d::ParticleMeteor *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleMeteor_initWithTotalParticles : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleMeteor_initWithTotalParticles : Error processing arguments"); bool ret = cobj->initWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -53283,6 +54510,7 @@ bool js_cocos2dx_ParticleMeteor_initWithTotalParticles(JSContext *cx, uint32_t a } bool js_cocos2dx_ParticleMeteor_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ParticleMeteor* ret = cocos2d::ParticleMeteor::create(); jsval jsret = JSVAL_NULL; @@ -53294,7 +54522,7 @@ bool js_cocos2dx_ParticleMeteor_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleMeteor_create : wrong number of arguments"); @@ -53303,11 +54531,11 @@ bool js_cocos2dx_ParticleMeteor_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ParticleMeteor_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleMeteor_createWithTotalParticles : Error processing arguments"); cocos2d::ParticleMeteor* ret = cocos2d::ParticleMeteor::createWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; @@ -53319,7 +54547,7 @@ bool js_cocos2dx_ParticleMeteor_createWithTotalParticles(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleMeteor_createWithTotalParticles : wrong number of arguments"); @@ -53328,7 +54556,7 @@ bool js_cocos2dx_ParticleMeteor_createWithTotalParticles(JSContext *cx, uint32_t bool js_cocos2dx_ParticleMeteor_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParticleMeteor* cobj = new (std::nothrow) cocos2d::ParticleMeteor(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -53342,13 +54570,16 @@ bool js_cocos2dx_ParticleMeteor_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleMeteor"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleMeteor"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -53359,7 +54590,7 @@ void js_cocos2d_ParticleMeteor_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ParticleMeteor)", obj); } -void js_register_cocos2dx_ParticleMeteor(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParticleMeteor(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParticleMeteor_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParticleMeteor_class->name = "ParticleMeteor"; jsb_cocos2d_ParticleMeteor_class->addProperty = JS_PropertyStub; @@ -53373,8 +54604,8 @@ void js_register_cocos2dx_ParticleMeteor(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleMeteor_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -53391,7 +54622,7 @@ void js_register_cocos2dx_ParticleMeteor(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleMeteor_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ParticleSystemQuad_prototype, + JS::RootedObject(cx, jsb_cocos2d_ParticleSystemQuad_prototype), jsb_cocos2d_ParticleMeteor_class, js_cocos2dx_ParticleMeteor_constructor, 0, // constructor properties, @@ -53422,7 +54653,8 @@ JSObject *jsb_cocos2d_ParticleSpiral_prototype; bool js_cocos2dx_ParticleSpiral_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSpiral* cobj = (cocos2d::ParticleSpiral *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSpiral_init : Invalid Native Object"); @@ -53430,7 +54662,7 @@ bool js_cocos2dx_ParticleSpiral_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -53439,20 +54671,20 @@ bool js_cocos2dx_ParticleSpiral_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ParticleSpiral_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSpiral* cobj = (cocos2d::ParticleSpiral *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSpiral_initWithTotalParticles : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSpiral_initWithTotalParticles : Error processing arguments"); bool ret = cobj->initWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -53461,6 +54693,7 @@ bool js_cocos2dx_ParticleSpiral_initWithTotalParticles(JSContext *cx, uint32_t a } bool js_cocos2dx_ParticleSpiral_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ParticleSpiral* ret = cocos2d::ParticleSpiral::create(); jsval jsret = JSVAL_NULL; @@ -53472,7 +54705,7 @@ bool js_cocos2dx_ParticleSpiral_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSpiral_create : wrong number of arguments"); @@ -53481,11 +54714,11 @@ bool js_cocos2dx_ParticleSpiral_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ParticleSpiral_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSpiral_createWithTotalParticles : Error processing arguments"); cocos2d::ParticleSpiral* ret = cocos2d::ParticleSpiral::createWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; @@ -53497,7 +54730,7 @@ bool js_cocos2dx_ParticleSpiral_createWithTotalParticles(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSpiral_createWithTotalParticles : wrong number of arguments"); @@ -53506,7 +54739,7 @@ bool js_cocos2dx_ParticleSpiral_createWithTotalParticles(JSContext *cx, uint32_t bool js_cocos2dx_ParticleSpiral_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParticleSpiral* cobj = new (std::nothrow) cocos2d::ParticleSpiral(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -53520,13 +54753,16 @@ bool js_cocos2dx_ParticleSpiral_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSpiral"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSpiral"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -53537,7 +54773,7 @@ void js_cocos2d_ParticleSpiral_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ParticleSpiral)", obj); } -void js_register_cocos2dx_ParticleSpiral(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParticleSpiral(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParticleSpiral_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParticleSpiral_class->name = "ParticleSpiral"; jsb_cocos2d_ParticleSpiral_class->addProperty = JS_PropertyStub; @@ -53551,8 +54787,8 @@ void js_register_cocos2dx_ParticleSpiral(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleSpiral_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -53569,7 +54805,7 @@ void js_register_cocos2dx_ParticleSpiral(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleSpiral_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ParticleSystemQuad_prototype, + JS::RootedObject(cx, jsb_cocos2d_ParticleSystemQuad_prototype), jsb_cocos2d_ParticleSpiral_class, js_cocos2dx_ParticleSpiral_constructor, 0, // constructor properties, @@ -53600,7 +54836,8 @@ JSObject *jsb_cocos2d_ParticleExplosion_prototype; bool js_cocos2dx_ParticleExplosion_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleExplosion* cobj = (cocos2d::ParticleExplosion *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleExplosion_init : Invalid Native Object"); @@ -53608,7 +54845,7 @@ bool js_cocos2dx_ParticleExplosion_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -53617,20 +54854,20 @@ bool js_cocos2dx_ParticleExplosion_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ParticleExplosion_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleExplosion* cobj = (cocos2d::ParticleExplosion *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleExplosion_initWithTotalParticles : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleExplosion_initWithTotalParticles : Error processing arguments"); bool ret = cobj->initWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -53639,6 +54876,7 @@ bool js_cocos2dx_ParticleExplosion_initWithTotalParticles(JSContext *cx, uint32_ } bool js_cocos2dx_ParticleExplosion_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ParticleExplosion* ret = cocos2d::ParticleExplosion::create(); jsval jsret = JSVAL_NULL; @@ -53650,7 +54888,7 @@ bool js_cocos2dx_ParticleExplosion_create(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleExplosion_create : wrong number of arguments"); @@ -53659,11 +54897,11 @@ bool js_cocos2dx_ParticleExplosion_create(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_ParticleExplosion_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleExplosion_createWithTotalParticles : Error processing arguments"); cocos2d::ParticleExplosion* ret = cocos2d::ParticleExplosion::createWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; @@ -53675,7 +54913,7 @@ bool js_cocos2dx_ParticleExplosion_createWithTotalParticles(JSContext *cx, uint3 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleExplosion_createWithTotalParticles : wrong number of arguments"); @@ -53684,7 +54922,7 @@ bool js_cocos2dx_ParticleExplosion_createWithTotalParticles(JSContext *cx, uint3 bool js_cocos2dx_ParticleExplosion_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParticleExplosion* cobj = new (std::nothrow) cocos2d::ParticleExplosion(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -53698,13 +54936,16 @@ bool js_cocos2dx_ParticleExplosion_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleExplosion"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleExplosion"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -53715,7 +54956,7 @@ void js_cocos2d_ParticleExplosion_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ParticleExplosion)", obj); } -void js_register_cocos2dx_ParticleExplosion(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParticleExplosion(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParticleExplosion_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParticleExplosion_class->name = "ParticleExplosion"; jsb_cocos2d_ParticleExplosion_class->addProperty = JS_PropertyStub; @@ -53729,8 +54970,8 @@ void js_register_cocos2dx_ParticleExplosion(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleExplosion_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -53747,7 +54988,7 @@ void js_register_cocos2dx_ParticleExplosion(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleExplosion_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ParticleSystemQuad_prototype, + JS::RootedObject(cx, jsb_cocos2d_ParticleSystemQuad_prototype), jsb_cocos2d_ParticleExplosion_class, js_cocos2dx_ParticleExplosion_constructor, 0, // constructor properties, @@ -53778,7 +55019,8 @@ JSObject *jsb_cocos2d_ParticleSmoke_prototype; bool js_cocos2dx_ParticleSmoke_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSmoke* cobj = (cocos2d::ParticleSmoke *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSmoke_init : Invalid Native Object"); @@ -53786,7 +55028,7 @@ bool js_cocos2dx_ParticleSmoke_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -53795,20 +55037,20 @@ bool js_cocos2dx_ParticleSmoke_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ParticleSmoke_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSmoke* cobj = (cocos2d::ParticleSmoke *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSmoke_initWithTotalParticles : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSmoke_initWithTotalParticles : Error processing arguments"); bool ret = cobj->initWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -53817,6 +55059,7 @@ bool js_cocos2dx_ParticleSmoke_initWithTotalParticles(JSContext *cx, uint32_t ar } bool js_cocos2dx_ParticleSmoke_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ParticleSmoke* ret = cocos2d::ParticleSmoke::create(); jsval jsret = JSVAL_NULL; @@ -53828,7 +55071,7 @@ bool js_cocos2dx_ParticleSmoke_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSmoke_create : wrong number of arguments"); @@ -53837,11 +55080,11 @@ bool js_cocos2dx_ParticleSmoke_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ParticleSmoke_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSmoke_createWithTotalParticles : Error processing arguments"); cocos2d::ParticleSmoke* ret = cocos2d::ParticleSmoke::createWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; @@ -53853,7 +55096,7 @@ bool js_cocos2dx_ParticleSmoke_createWithTotalParticles(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSmoke_createWithTotalParticles : wrong number of arguments"); @@ -53862,7 +55105,7 @@ bool js_cocos2dx_ParticleSmoke_createWithTotalParticles(JSContext *cx, uint32_t bool js_cocos2dx_ParticleSmoke_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParticleSmoke* cobj = new (std::nothrow) cocos2d::ParticleSmoke(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -53876,13 +55119,16 @@ bool js_cocos2dx_ParticleSmoke_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSmoke"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSmoke"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -53893,7 +55139,7 @@ void js_cocos2d_ParticleSmoke_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ParticleSmoke)", obj); } -void js_register_cocos2dx_ParticleSmoke(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParticleSmoke(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParticleSmoke_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParticleSmoke_class->name = "ParticleSmoke"; jsb_cocos2d_ParticleSmoke_class->addProperty = JS_PropertyStub; @@ -53907,8 +55153,8 @@ void js_register_cocos2dx_ParticleSmoke(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleSmoke_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -53925,7 +55171,7 @@ void js_register_cocos2dx_ParticleSmoke(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleSmoke_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ParticleSystemQuad_prototype, + JS::RootedObject(cx, jsb_cocos2d_ParticleSystemQuad_prototype), jsb_cocos2d_ParticleSmoke_class, js_cocos2dx_ParticleSmoke_constructor, 0, // constructor properties, @@ -53956,7 +55202,8 @@ JSObject *jsb_cocos2d_ParticleSnow_prototype; bool js_cocos2dx_ParticleSnow_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSnow* cobj = (cocos2d::ParticleSnow *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSnow_init : Invalid Native Object"); @@ -53964,7 +55211,7 @@ bool js_cocos2dx_ParticleSnow_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -53973,20 +55220,20 @@ bool js_cocos2dx_ParticleSnow_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ParticleSnow_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleSnow* cobj = (cocos2d::ParticleSnow *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSnow_initWithTotalParticles : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSnow_initWithTotalParticles : Error processing arguments"); bool ret = cobj->initWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -53995,6 +55242,7 @@ bool js_cocos2dx_ParticleSnow_initWithTotalParticles(JSContext *cx, uint32_t arg } bool js_cocos2dx_ParticleSnow_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ParticleSnow* ret = cocos2d::ParticleSnow::create(); jsval jsret = JSVAL_NULL; @@ -54006,7 +55254,7 @@ bool js_cocos2dx_ParticleSnow_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSnow_create : wrong number of arguments"); @@ -54015,11 +55263,11 @@ bool js_cocos2dx_ParticleSnow_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ParticleSnow_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSnow_createWithTotalParticles : Error processing arguments"); cocos2d::ParticleSnow* ret = cocos2d::ParticleSnow::createWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; @@ -54031,7 +55279,7 @@ bool js_cocos2dx_ParticleSnow_createWithTotalParticles(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleSnow_createWithTotalParticles : wrong number of arguments"); @@ -54040,7 +55288,7 @@ bool js_cocos2dx_ParticleSnow_createWithTotalParticles(JSContext *cx, uint32_t a bool js_cocos2dx_ParticleSnow_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParticleSnow* cobj = new (std::nothrow) cocos2d::ParticleSnow(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -54054,13 +55302,16 @@ bool js_cocos2dx_ParticleSnow_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSnow"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleSnow"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -54071,7 +55322,7 @@ void js_cocos2d_ParticleSnow_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ParticleSnow)", obj); } -void js_register_cocos2dx_ParticleSnow(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParticleSnow(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParticleSnow_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParticleSnow_class->name = "ParticleSnow"; jsb_cocos2d_ParticleSnow_class->addProperty = JS_PropertyStub; @@ -54085,8 +55336,8 @@ void js_register_cocos2dx_ParticleSnow(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleSnow_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -54103,7 +55354,7 @@ void js_register_cocos2dx_ParticleSnow(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleSnow_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ParticleSystemQuad_prototype, + JS::RootedObject(cx, jsb_cocos2d_ParticleSystemQuad_prototype), jsb_cocos2d_ParticleSnow_class, js_cocos2dx_ParticleSnow_constructor, 0, // constructor properties, @@ -54134,7 +55385,8 @@ JSObject *jsb_cocos2d_ParticleRain_prototype; bool js_cocos2dx_ParticleRain_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleRain* cobj = (cocos2d::ParticleRain *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleRain_init : Invalid Native Object"); @@ -54142,7 +55394,7 @@ bool js_cocos2dx_ParticleRain_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -54151,20 +55403,20 @@ bool js_cocos2dx_ParticleRain_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ParticleRain_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParticleRain* cobj = (cocos2d::ParticleRain *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleRain_initWithTotalParticles : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleRain_initWithTotalParticles : Error processing arguments"); bool ret = cobj->initWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -54173,6 +55425,7 @@ bool js_cocos2dx_ParticleRain_initWithTotalParticles(JSContext *cx, uint32_t arg } bool js_cocos2dx_ParticleRain_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ParticleRain* ret = cocos2d::ParticleRain::create(); jsval jsret = JSVAL_NULL; @@ -54184,7 +55437,7 @@ bool js_cocos2dx_ParticleRain_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleRain_create : wrong number of arguments"); @@ -54193,11 +55446,11 @@ bool js_cocos2dx_ParticleRain_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ParticleRain_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleRain_createWithTotalParticles : Error processing arguments"); cocos2d::ParticleRain* ret = cocos2d::ParticleRain::createWithTotalParticles(arg0); jsval jsret = JSVAL_NULL; @@ -54209,7 +55462,7 @@ bool js_cocos2dx_ParticleRain_createWithTotalParticles(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParticleRain_createWithTotalParticles : wrong number of arguments"); @@ -54218,7 +55471,7 @@ bool js_cocos2dx_ParticleRain_createWithTotalParticles(JSContext *cx, uint32_t a bool js_cocos2dx_ParticleRain_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParticleRain* cobj = new (std::nothrow) cocos2d::ParticleRain(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -54232,13 +55485,16 @@ bool js_cocos2dx_ParticleRain_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleRain"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParticleRain"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -54249,7 +55505,7 @@ void js_cocos2d_ParticleRain_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ParticleRain)", obj); } -void js_register_cocos2dx_ParticleRain(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParticleRain(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParticleRain_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParticleRain_class->name = "ParticleRain"; jsb_cocos2d_ParticleRain_class->addProperty = JS_PropertyStub; @@ -54263,8 +55519,8 @@ void js_register_cocos2dx_ParticleRain(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleRain_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -54281,7 +55537,7 @@ void js_register_cocos2dx_ParticleRain(JSContext *cx, JSObject *global) { jsb_cocos2d_ParticleRain_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ParticleSystemQuad_prototype, + JS::RootedObject(cx, jsb_cocos2d_ParticleSystemQuad_prototype), jsb_cocos2d_ParticleRain_class, js_cocos2dx_ParticleRain_constructor, 0, // constructor properties, @@ -54312,18 +55568,18 @@ JSObject *jsb_cocos2d_GridBase_prototype; bool js_cocos2dx_GridBase_setGridSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_setGridSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GridBase_setGridSize : Error processing arguments"); cobj->setGridSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -54332,13 +55588,14 @@ bool js_cocos2dx_GridBase_setGridSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_afterBlit(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_afterBlit : Invalid Native Object"); if (argc == 0) { cobj->afterBlit(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -54347,25 +55604,25 @@ bool js_cocos2dx_GridBase_afterBlit(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_afterDraw(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_afterDraw : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GridBase_afterDraw : Error processing arguments"); cobj->afterDraw(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -54374,13 +55631,14 @@ bool js_cocos2dx_GridBase_afterDraw(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_beforeDraw(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_beforeDraw : Invalid Native Object"); if (argc == 0) { cobj->beforeDraw(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -54389,13 +55647,14 @@ bool js_cocos2dx_GridBase_beforeDraw(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_calculateVertexPoints(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_calculateVertexPoints : Invalid Native Object"); if (argc == 0) { cobj->calculateVertexPoints(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -54404,7 +55663,8 @@ bool js_cocos2dx_GridBase_calculateVertexPoints(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_GridBase_isTextureFlipped(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_isTextureFlipped : Invalid Native Object"); @@ -54412,7 +55672,7 @@ bool js_cocos2dx_GridBase_isTextureFlipped(JSContext *cx, uint32_t argc, jsval * bool ret = cobj->isTextureFlipped(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -54421,7 +55681,8 @@ bool js_cocos2dx_GridBase_isTextureFlipped(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_GridBase_getGridSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_getGridSize : Invalid Native Object"); @@ -54429,7 +55690,7 @@ bool js_cocos2dx_GridBase_getGridSize(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Size& ret = cobj->getGridSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -54438,7 +55699,8 @@ bool js_cocos2dx_GridBase_getGridSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_getStep(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_getStep : Invalid Native Object"); @@ -54446,7 +55708,7 @@ bool js_cocos2dx_GridBase_getStep(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Vec2& ret = cobj->getStep(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -54455,13 +55717,14 @@ bool js_cocos2dx_GridBase_getStep(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_set2DProjection(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_set2DProjection : Invalid Native Object"); if (argc == 0) { cobj->set2DProjection(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -54470,18 +55733,18 @@ bool js_cocos2dx_GridBase_set2DProjection(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_GridBase_setStep(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_setStep : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GridBase_setStep : Error processing arguments"); cobj->setStep(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -54490,18 +55753,18 @@ bool js_cocos2dx_GridBase_setStep(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_setTextureFlipped(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_setTextureFlipped : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GridBase_setTextureFlipped : Error processing arguments"); cobj->setTextureFlipped(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -54510,13 +55773,14 @@ bool js_cocos2dx_GridBase_setTextureFlipped(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_GridBase_blit(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_blit : Invalid Native Object"); if (argc == 0) { cobj->blit(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -54525,18 +55789,18 @@ bool js_cocos2dx_GridBase_blit(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_setActive(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_setActive : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GridBase_setActive : Error processing arguments"); cobj->setActive(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -54545,7 +55809,8 @@ bool js_cocos2dx_GridBase_setActive(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_getReuseGrid(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_getReuseGrid : Invalid Native Object"); @@ -54553,7 +55818,7 @@ bool js_cocos2dx_GridBase_getReuseGrid(JSContext *cx, uint32_t argc, jsval *vp) int ret = cobj->getReuseGrid(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -54562,24 +55827,24 @@ bool js_cocos2dx_GridBase_getReuseGrid(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_initWithSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::GridBase* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_initWithSize : Invalid Native Object"); do { if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } bool ret = cobj->initWithSize(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -54587,24 +55852,24 @@ bool js_cocos2dx_GridBase_initWithSize(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 3) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Texture2D* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(args.get(2)); bool ret = cobj->initWithSize(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -54614,13 +55879,14 @@ bool js_cocos2dx_GridBase_initWithSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_beforeBlit(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_beforeBlit : Invalid Native Object"); if (argc == 0) { cobj->beforeBlit(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -54629,18 +55895,18 @@ bool js_cocos2dx_GridBase_beforeBlit(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_setReuseGrid(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_setReuseGrid : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GridBase_setReuseGrid : Error processing arguments"); cobj->setReuseGrid(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -54649,7 +55915,8 @@ bool js_cocos2dx_GridBase_setReuseGrid(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_isActive(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_isActive : Invalid Native Object"); @@ -54657,7 +55924,7 @@ bool js_cocos2dx_GridBase_isActive(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isActive(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -54666,13 +55933,14 @@ bool js_cocos2dx_GridBase_isActive(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_reuse(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GridBase* cobj = (cocos2d::GridBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GridBase_reuse : Invalid Native Object"); if (argc == 0) { cobj->reuse(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -54681,13 +55949,13 @@ bool js_cocos2dx_GridBase_reuse(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GridBase_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::GridBase* ret = cocos2d::GridBase::create(arg0); jsval jsret = JSVAL_NULL; @@ -54699,7 +55967,7 @@ bool js_cocos2dx_GridBase_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -54707,20 +55975,20 @@ bool js_cocos2dx_GridBase_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 3) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Texture2D* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(args.get(2)); if (!ok) { ok = true; break; } cocos2d::GridBase* ret = cocos2d::GridBase::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -54732,7 +56000,7 @@ bool js_cocos2dx_GridBase_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -54747,21 +56015,21 @@ void js_cocos2d_GridBase_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_GridBase_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::GridBase *nobj = new (std::nothrow) cocos2d::GridBase(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::GridBase"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::GridBase"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_GridBase(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_GridBase(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_GridBase_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_GridBase_class->name = "GridBase"; jsb_cocos2d_GridBase_class->addProperty = JS_PropertyStub; @@ -54775,8 +56043,8 @@ void js_register_cocos2dx_GridBase(JSContext *cx, JSObject *global) { jsb_cocos2d_GridBase_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -54810,7 +56078,7 @@ void js_register_cocos2dx_GridBase(JSContext *cx, JSObject *global) { jsb_cocos2d_GridBase_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_GridBase_class, dummy_constructor, 0, // no constructor properties, @@ -54841,7 +56109,8 @@ JSObject *jsb_cocos2d_Grid3D_prototype; bool js_cocos2dx_Grid3D_getNeedDepthTestForBlit(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Grid3D* cobj = (cocos2d::Grid3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Grid3D_getNeedDepthTestForBlit : Invalid Native Object"); @@ -54849,7 +56118,7 @@ bool js_cocos2dx_Grid3D_getNeedDepthTestForBlit(JSContext *cx, uint32_t argc, js bool ret = cobj->getNeedDepthTestForBlit(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -54858,18 +56127,18 @@ bool js_cocos2dx_Grid3D_getNeedDepthTestForBlit(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_Grid3D_setNeedDepthTestForBlit(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Grid3D* cobj = (cocos2d::Grid3D *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Grid3D_setNeedDepthTestForBlit : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Grid3D_setNeedDepthTestForBlit : Error processing arguments"); cobj->setNeedDepthTestForBlit(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -54878,13 +56147,13 @@ bool js_cocos2dx_Grid3D_setNeedDepthTestForBlit(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_Grid3D_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Grid3D* ret = cocos2d::Grid3D::create(arg0); jsval jsret = JSVAL_NULL; @@ -54896,7 +56165,7 @@ bool js_cocos2dx_Grid3D_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -54904,20 +56173,20 @@ bool js_cocos2dx_Grid3D_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 3) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Texture2D* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(args.get(2)); if (!ok) { ok = true; break; } cocos2d::Grid3D* ret = cocos2d::Grid3D::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -54929,7 +56198,7 @@ bool js_cocos2dx_Grid3D_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -54938,7 +56207,7 @@ bool js_cocos2dx_Grid3D_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Grid3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Grid3D* cobj = new (std::nothrow) cocos2d::Grid3D(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -54952,13 +56221,16 @@ bool js_cocos2dx_Grid3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Grid3D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Grid3D"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -54971,21 +56243,21 @@ void js_cocos2d_Grid3D_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_Grid3D_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::Grid3D *nobj = new (std::nothrow) cocos2d::Grid3D(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Grid3D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Grid3D"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_Grid3D(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Grid3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Grid3D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Grid3D_class->name = "Grid3D"; jsb_cocos2d_Grid3D_class->addProperty = JS_PropertyStub; @@ -54999,8 +56271,8 @@ void js_register_cocos2dx_Grid3D(JSContext *cx, JSObject *global) { jsb_cocos2d_Grid3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -55017,7 +56289,7 @@ void js_register_cocos2dx_Grid3D(JSContext *cx, JSObject *global) { jsb_cocos2d_Grid3D_prototype = JS_InitClass( cx, global, - jsb_cocos2d_GridBase_prototype, + JS::RootedObject(cx, jsb_cocos2d_GridBase_prototype), jsb_cocos2d_Grid3D_class, js_cocos2dx_Grid3D_constructor, 0, // constructor properties, @@ -55048,13 +56320,13 @@ JSObject *jsb_cocos2d_TiledGrid3D_prototype; bool js_cocos2dx_TiledGrid3D_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::TiledGrid3D* ret = cocos2d::TiledGrid3D::create(arg0); jsval jsret = JSVAL_NULL; @@ -55066,7 +56338,7 @@ bool js_cocos2dx_TiledGrid3D_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -55074,20 +56346,20 @@ bool js_cocos2dx_TiledGrid3D_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 3) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Texture2D* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(args.get(2)); if (!ok) { ok = true; break; } cocos2d::TiledGrid3D* ret = cocos2d::TiledGrid3D::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -55099,7 +56371,7 @@ bool js_cocos2dx_TiledGrid3D_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -55108,7 +56380,7 @@ bool js_cocos2dx_TiledGrid3D_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TiledGrid3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TiledGrid3D* cobj = new (std::nothrow) cocos2d::TiledGrid3D(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -55122,13 +56394,16 @@ bool js_cocos2dx_TiledGrid3D_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TiledGrid3D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TiledGrid3D"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -55141,21 +56416,21 @@ void js_cocos2d_TiledGrid3D_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_TiledGrid3D_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::TiledGrid3D *nobj = new (std::nothrow) cocos2d::TiledGrid3D(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TiledGrid3D"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TiledGrid3D"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_TiledGrid3D(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TiledGrid3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TiledGrid3D_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TiledGrid3D_class->name = "TiledGrid3D"; jsb_cocos2d_TiledGrid3D_class->addProperty = JS_PropertyStub; @@ -55169,8 +56444,8 @@ void js_register_cocos2dx_TiledGrid3D(JSContext *cx, JSObject *global) { jsb_cocos2d_TiledGrid3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -55185,7 +56460,7 @@ void js_register_cocos2dx_TiledGrid3D(JSContext *cx, JSObject *global) { jsb_cocos2d_TiledGrid3D_prototype = JS_InitClass( cx, global, - jsb_cocos2d_GridBase_prototype, + JS::RootedObject(cx, jsb_cocos2d_GridBase_prototype), jsb_cocos2d_TiledGrid3D_class, js_cocos2dx_TiledGrid3D_constructor, 0, // constructor properties, @@ -55216,34 +56491,63 @@ JSObject *jsb_cocos2d_Camera_prototype; bool js_cocos2dx_Camera_setScene(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_setScene : Invalid Native Object"); if (argc == 1) { cocos2d::Scene* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Scene*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_setScene : Error processing arguments"); cobj->setScene(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Camera_setScene : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_Camera_initPerspective(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_initPerspective : Invalid Native Object"); + if (argc == 4) { + double arg0; + double arg1; + double arg2; + double arg3; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_initPerspective : Error processing arguments"); + bool ret = cobj->initPerspective(arg0, arg1, arg2, arg3); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Camera_initPerspective : wrong number of arguments: %d, was expecting %d", argc, 4); + return false; +} bool js_cocos2dx_Camera_getProjectionMatrix(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_getProjectionMatrix : Invalid Native Object"); @@ -55251,7 +56555,7 @@ bool js_cocos2dx_Camera_getProjectionMatrix(JSContext *cx, uint32_t argc, jsval const cocos2d::Mat4& ret = cobj->getProjectionMatrix(); jsval jsret = JSVAL_NULL; jsret = matrix_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -55260,7 +56564,8 @@ bool js_cocos2dx_Camera_getProjectionMatrix(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Camera_getViewProjectionMatrix(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_getViewProjectionMatrix : Invalid Native Object"); @@ -55268,7 +56573,7 @@ bool js_cocos2dx_Camera_getViewProjectionMatrix(JSContext *cx, uint32_t argc, js const cocos2d::Mat4& ret = cobj->getViewProjectionMatrix(); jsval jsret = JSVAL_NULL; jsret = matrix_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -55277,7 +56582,8 @@ bool js_cocos2dx_Camera_getViewProjectionMatrix(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_Camera_getViewMatrix(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_getViewMatrix : Invalid Native Object"); @@ -55285,7 +56591,7 @@ bool js_cocos2dx_Camera_getViewMatrix(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Mat4& ret = cobj->getViewMatrix(); jsval jsret = JSVAL_NULL; jsret = matrix_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -55294,7 +56600,8 @@ bool js_cocos2dx_Camera_getViewMatrix(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Camera_getCameraFlag(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_getCameraFlag : Invalid Native Object"); @@ -55302,7 +56609,7 @@ bool js_cocos2dx_Camera_getCameraFlag(JSContext *cx, uint32_t argc, jsval *vp) int ret = (int)cobj->getCameraFlag(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -55311,7 +56618,8 @@ bool js_cocos2dx_Camera_getCameraFlag(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Camera_getType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_getType : Invalid Native Object"); @@ -55319,49 +56627,119 @@ bool js_cocos2dx_Camera_getType(JSContext *cx, uint32_t argc, jsval *vp) int ret = (int)cobj->getType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Camera_getType : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_Camera_initDefault(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_initDefault : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->initDefault(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Camera_initDefault : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_Camera_project(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_project : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vec3 arg0; + ok &= jsval_to_vector3(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_project : Error processing arguments"); + cocos2d::Vec2 ret = cobj->project(arg0); + jsval jsret = JSVAL_NULL; + jsret = vector2_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Camera_project : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_Camera_getDepthInView(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_getDepthInView : Invalid Native Object"); + if (argc == 1) { + cocos2d::Mat4 arg0; + ok &= jsval_to_matrix(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_getDepthInView : Error processing arguments"); + double ret = cobj->getDepthInView(arg0); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Camera_getDepthInView : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_Camera_lookAt(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_lookAt : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vec3 arg0; + ok &= jsval_to_vector3(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_lookAt : Error processing arguments"); + cobj->lookAt(arg0); + args.rval().setUndefined(); + return true; + } if (argc == 2) { cocos2d::Vec3 arg0; cocos2d::Vec3 arg1; - ok &= jsval_to_vector3(cx, argv[0], &arg0); - ok &= jsval_to_vector3(cx, argv[1], &arg1); + ok &= jsval_to_vector3(cx, args.get(0), &arg0); + ok &= jsval_to_vector3(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_lookAt : Error processing arguments"); cobj->lookAt(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_Camera_lookAt : wrong number of arguments: %d, was expecting %d", argc, 2); + JS_ReportError(cx, "js_cocos2dx_Camera_lookAt : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_Camera_setCameraFlag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_setCameraFlag : Invalid Native Object"); if (argc == 1) { cocos2d::CameraFlag arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_setCameraFlag : Error processing arguments"); cobj->setCameraFlag(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -55370,9 +56748,9 @@ bool js_cocos2dx_Camera_setCameraFlag(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Camera_initOrthographic(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_initOrthographic : Invalid Native Object"); @@ -55381,88 +56759,82 @@ bool js_cocos2dx_Camera_initOrthographic(JSContext *cx, uint32_t argc, jsval *vp double arg1; double arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_initOrthographic : Error processing arguments"); bool ret = cobj->initOrthographic(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Camera_initOrthographic : wrong number of arguments: %d, was expecting %d", argc, 4); return false; } -bool js_cocos2dx_Camera_initPerspective(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_Camera_setAdditionalProjection(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_initPerspective : Invalid Native Object"); - if (argc == 4) { - double arg0; - double arg1; - double arg2; - double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_initPerspective : Error processing arguments"); - bool ret = cobj->initPerspective(arg0, arg1, arg2, arg3); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_setAdditionalProjection : Invalid Native Object"); + if (argc == 1) { + cocos2d::Mat4 arg0; + ok &= jsval_to_matrix(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_setAdditionalProjection : Error processing arguments"); + cobj->setAdditionalProjection(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_Camera_initPerspective : wrong number of arguments: %d, was expecting %d", argc, 4); + JS_ReportError(cx, "js_cocos2dx_Camera_setAdditionalProjection : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_Camera_initDefault(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_Camera_getDepth(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_initDefault : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_getDepth : Invalid Native Object"); if (argc == 0) { - bool ret = cobj->initDefault(); + int ret = cobj->getDepth(); jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_Camera_initDefault : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_Camera_getDepth : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_Camera_setAdditionalProjection(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_Camera_setDepth(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_setAdditionalProjection : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_setDepth : Invalid Native Object"); if (argc == 1) { - cocos2d::Mat4 arg0; - ok &= jsval_to_matrix(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_setAdditionalProjection : Error processing arguments"); - cobj->setAdditionalProjection(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_setDepth : Error processing arguments"); + cobj->setDepth(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_Camera_setAdditionalProjection : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_Camera_setDepth : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_Camera_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Camera* ret = cocos2d::Camera::create(); jsval jsret = JSVAL_NULL; @@ -55474,7 +56846,7 @@ bool js_cocos2dx_Camera_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Camera_create : wrong number of arguments"); @@ -55483,17 +56855,17 @@ bool js_cocos2dx_Camera_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Camera_createPerspective(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { double arg0; double arg1; double arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_createPerspective : Error processing arguments"); cocos2d::Camera* ret = cocos2d::Camera::createPerspective(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -55505,7 +56877,7 @@ bool js_cocos2dx_Camera_createPerspective(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Camera_createPerspective : wrong number of arguments"); @@ -55514,17 +56886,17 @@ bool js_cocos2dx_Camera_createPerspective(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_Camera_createOrthographic(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { double arg0; double arg1; double arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_createOrthographic : Error processing arguments"); cocos2d::Camera* ret = cocos2d::Camera::createOrthographic(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -55536,15 +56908,37 @@ bool js_cocos2dx_Camera_createOrthographic(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Camera_createOrthographic : wrong number of arguments"); return false; } +bool js_cocos2dx_Camera_getDefaultCamera(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (argc == 0) { + cocos2d::Camera* ret = cocos2d::Camera::getDefaultCamera(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Camera*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_Camera_getDefaultCamera : wrong number of arguments"); + return false; +} + bool js_cocos2dx_Camera_getVisitingCamera(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { const cocos2d::Camera* ret = cocos2d::Camera::getVisitingCamera(); jsval jsret = JSVAL_NULL; @@ -55556,7 +56950,7 @@ bool js_cocos2dx_Camera_getVisitingCamera(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Camera_getVisitingCamera : wrong number of arguments"); @@ -55565,7 +56959,7 @@ bool js_cocos2dx_Camera_getVisitingCamera(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_Camera_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Camera* cobj = new (std::nothrow) cocos2d::Camera(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -55579,13 +56973,16 @@ bool js_cocos2dx_Camera_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Camera"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Camera"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -55596,7 +56993,7 @@ void js_cocos2d_Camera_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Camera)", obj); } -void js_register_cocos2dx_Camera(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Camera(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Camera_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Camera_class->name = "Camera"; jsb_cocos2d_Camera_class->addProperty = JS_PropertyStub; @@ -55610,23 +57007,27 @@ void js_register_cocos2dx_Camera(JSContext *cx, JSObject *global) { jsb_cocos2d_Camera_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("setScene", js_cocos2dx_Camera_setScene, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initPerspective", js_cocos2dx_Camera_initPerspective, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getProjectionMatrix", js_cocos2dx_Camera_getProjectionMatrix, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getViewProjectionMatrix", js_cocos2dx_Camera_getViewProjectionMatrix, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getViewMatrix", js_cocos2dx_Camera_getViewMatrix, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getCameraFlag", js_cocos2dx_Camera_getCameraFlag, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getType", js_cocos2dx_Camera_getType, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("lookAt", js_cocos2dx_Camera_lookAt, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initDefault", js_cocos2dx_Camera_initDefault, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("project", js_cocos2dx_Camera_project, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDepthInView", js_cocos2dx_Camera_getDepthInView, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("lookAt", js_cocos2dx_Camera_lookAt, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setCameraFlag", js_cocos2dx_Camera_setCameraFlag, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("initOrthographic", js_cocos2dx_Camera_initOrthographic, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("initPerspective", js_cocos2dx_Camera_initPerspective, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("initDefault", js_cocos2dx_Camera_initDefault, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setAdditionalProjection", js_cocos2dx_Camera_setAdditionalProjection, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDepth", js_cocos2dx_Camera_getDepth, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setDepth", js_cocos2dx_Camera_setDepth, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -55634,13 +57035,14 @@ void js_register_cocos2dx_Camera(JSContext *cx, JSObject *global) { JS_FN("create", js_cocos2dx_Camera_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("createPerspective", js_cocos2dx_Camera_createPerspective, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("createOrthographic", js_cocos2dx_Camera_createOrthographic, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDefaultCamera", js_cocos2dx_Camera_getDefaultCamera, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getVisitingCamera", js_cocos2dx_Camera_getVisitingCamera, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; jsb_cocos2d_Camera_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_Camera_class, js_cocos2dx_Camera_constructor, 0, // constructor properties, @@ -55666,12 +57068,1022 @@ void js_register_cocos2dx_Camera(JSContext *cx, JSObject *global) { } } +JSClass *jsb_cocos2d_BaseLight_class; +JSObject *jsb_cocos2d_BaseLight_prototype; + +bool js_cocos2dx_BaseLight_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::BaseLight* cobj = (cocos2d::BaseLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_BaseLight_setEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_BaseLight_setEnabled : Error processing arguments"); + cobj->setEnabled(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_BaseLight_setEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_BaseLight_getIntensity(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::BaseLight* cobj = (cocos2d::BaseLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_BaseLight_getIntensity : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getIntensity(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_BaseLight_getIntensity : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_BaseLight_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::BaseLight* cobj = (cocos2d::BaseLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_BaseLight_isEnabled : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isEnabled(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_BaseLight_isEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_BaseLight_getLightType(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::BaseLight* cobj = (cocos2d::BaseLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_BaseLight_getLightType : Invalid Native Object"); + if (argc == 0) { + int ret = (int)cobj->getLightType(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_BaseLight_getLightType : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_BaseLight_setLightFlag(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::BaseLight* cobj = (cocos2d::BaseLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_BaseLight_setLightFlag : Invalid Native Object"); + if (argc == 1) { + cocos2d::LightFlag arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_BaseLight_setLightFlag : Error processing arguments"); + cobj->setLightFlag(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_BaseLight_setLightFlag : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_BaseLight_setIntensity(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::BaseLight* cobj = (cocos2d::BaseLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_BaseLight_setIntensity : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_BaseLight_setIntensity : Error processing arguments"); + cobj->setIntensity(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_BaseLight_setIntensity : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_BaseLight_getLightFlag(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::BaseLight* cobj = (cocos2d::BaseLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_BaseLight_getLightFlag : Invalid Native Object"); + if (argc == 0) { + int ret = (int)cobj->getLightFlag(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_BaseLight_getLightFlag : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} + +extern JSObject *jsb_cocos2d_Node_prototype; + +void js_cocos2d_BaseLight_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (BaseLight)", obj); +} + +void js_register_cocos2dx_BaseLight(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_BaseLight_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_BaseLight_class->name = "BaseLight"; + jsb_cocos2d_BaseLight_class->addProperty = JS_PropertyStub; + jsb_cocos2d_BaseLight_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_BaseLight_class->getProperty = JS_PropertyStub; + jsb_cocos2d_BaseLight_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_BaseLight_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_BaseLight_class->resolve = JS_ResolveStub; + jsb_cocos2d_BaseLight_class->convert = JS_ConvertStub; + jsb_cocos2d_BaseLight_class->finalize = js_cocos2d_BaseLight_finalize; + jsb_cocos2d_BaseLight_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("setEnabled", js_cocos2dx_BaseLight_setEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getIntensity", js_cocos2dx_BaseLight_getIntensity, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isEnabled", js_cocos2dx_BaseLight_isEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getLightType", js_cocos2dx_BaseLight_getLightType, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setLightFlag", js_cocos2dx_BaseLight_setLightFlag, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setIntensity", js_cocos2dx_BaseLight_setIntensity, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getLightFlag", js_cocos2dx_BaseLight_getLightFlag, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + JSFunctionSpec *st_funcs = NULL; + + jsb_cocos2d_BaseLight_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), + jsb_cocos2d_BaseLight_class, + empty_constructor, 0, + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "BaseLight", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_BaseLight_class; + p->proto = jsb_cocos2d_BaseLight_prototype; + p->parentProto = jsb_cocos2d_Node_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_DirectionLight_class; +JSObject *jsb_cocos2d_DirectionLight_prototype; + +bool js_cocos2dx_DirectionLight_getDirection(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::DirectionLight* cobj = (cocos2d::DirectionLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DirectionLight_getDirection : Invalid Native Object"); + if (argc == 0) { + cocos2d::Vec3 ret = cobj->getDirection(); + jsval jsret = JSVAL_NULL; + jsret = vector3_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_DirectionLight_getDirection : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_DirectionLight_getDirectionInWorld(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::DirectionLight* cobj = (cocos2d::DirectionLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DirectionLight_getDirectionInWorld : Invalid Native Object"); + if (argc == 0) { + cocos2d::Vec3 ret = cobj->getDirectionInWorld(); + jsval jsret = JSVAL_NULL; + jsret = vector3_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_DirectionLight_getDirectionInWorld : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_DirectionLight_setDirection(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::DirectionLight* cobj = (cocos2d::DirectionLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DirectionLight_setDirection : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vec3 arg0; + ok &= jsval_to_vector3(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DirectionLight_setDirection : Error processing arguments"); + cobj->setDirection(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_DirectionLight_setDirection : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_DirectionLight_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 2) { + cocos2d::Vec3 arg0; + cocos2d::Color3B arg1; + ok &= jsval_to_vector3(cx, args.get(0), &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DirectionLight_create : Error processing arguments"); + cocos2d::DirectionLight* ret = cocos2d::DirectionLight::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::DirectionLight*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_DirectionLight_create : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_DirectionLight_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::DirectionLight* cobj = new (std::nothrow) cocos2d::DirectionLight(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::DirectionLight"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocos2d_BaseLight_prototype; + +void js_cocos2d_DirectionLight_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (DirectionLight)", obj); +} + +void js_register_cocos2dx_DirectionLight(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_DirectionLight_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_DirectionLight_class->name = "DirectionLight"; + jsb_cocos2d_DirectionLight_class->addProperty = JS_PropertyStub; + jsb_cocos2d_DirectionLight_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_DirectionLight_class->getProperty = JS_PropertyStub; + jsb_cocos2d_DirectionLight_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_DirectionLight_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_DirectionLight_class->resolve = JS_ResolveStub; + jsb_cocos2d_DirectionLight_class->convert = JS_ConvertStub; + jsb_cocos2d_DirectionLight_class->finalize = js_cocos2d_DirectionLight_finalize; + jsb_cocos2d_DirectionLight_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("getDirection", js_cocos2dx_DirectionLight_getDirection, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDirectionInWorld", js_cocos2dx_DirectionLight_getDirectionInWorld, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setDirection", js_cocos2dx_DirectionLight_setDirection, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_DirectionLight_create, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_DirectionLight_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_BaseLight_prototype), + jsb_cocos2d_DirectionLight_class, + js_cocos2dx_DirectionLight_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "DirectionLight", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_DirectionLight_class; + p->proto = jsb_cocos2d_DirectionLight_prototype; + p->parentProto = jsb_cocos2d_BaseLight_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_PointLight_class; +JSObject *jsb_cocos2d_PointLight_prototype; + +bool js_cocos2dx_PointLight_getRange(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PointLight* cobj = (cocos2d::PointLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_PointLight_getRange : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getRange(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_PointLight_getRange : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_PointLight_setRange(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::PointLight* cobj = (cocos2d::PointLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_PointLight_setRange : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_PointLight_setRange : Error processing arguments"); + cobj->setRange(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_PointLight_setRange : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_PointLight_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 3) { + cocos2d::Vec3 arg0; + cocos2d::Color3B arg1; + double arg2; + ok &= jsval_to_vector3(cx, args.get(0), &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_PointLight_create : Error processing arguments"); + cocos2d::PointLight* ret = cocos2d::PointLight::create(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::PointLight*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_PointLight_create : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_PointLight_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::PointLight* cobj = new (std::nothrow) cocos2d::PointLight(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::PointLight"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocos2d_BaseLight_prototype; + +void js_cocos2d_PointLight_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (PointLight)", obj); +} + +void js_register_cocos2dx_PointLight(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_PointLight_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_PointLight_class->name = "PointLight"; + jsb_cocos2d_PointLight_class->addProperty = JS_PropertyStub; + jsb_cocos2d_PointLight_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_PointLight_class->getProperty = JS_PropertyStub; + jsb_cocos2d_PointLight_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_PointLight_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_PointLight_class->resolve = JS_ResolveStub; + jsb_cocos2d_PointLight_class->convert = JS_ConvertStub; + jsb_cocos2d_PointLight_class->finalize = js_cocos2d_PointLight_finalize; + jsb_cocos2d_PointLight_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("getRange", js_cocos2dx_PointLight_getRange, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setRange", js_cocos2dx_PointLight_setRange, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_PointLight_create, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_PointLight_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_BaseLight_prototype), + jsb_cocos2d_PointLight_class, + js_cocos2dx_PointLight_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "PointLight", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_PointLight_class; + p->proto = jsb_cocos2d_PointLight_prototype; + p->parentProto = jsb_cocos2d_BaseLight_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_SpotLight_class; +JSObject *jsb_cocos2d_SpotLight_prototype; + +bool js_cocos2dx_SpotLight_getRange(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpotLight* cobj = (cocos2d::SpotLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpotLight_getRange : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getRange(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpotLight_getRange : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_SpotLight_setDirection(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpotLight* cobj = (cocos2d::SpotLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpotLight_setDirection : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vec3 arg0; + ok &= jsval_to_vector3(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpotLight_setDirection : Error processing arguments"); + cobj->setDirection(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpotLight_setDirection : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_SpotLight_getCosInnerAngle(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpotLight* cobj = (cocos2d::SpotLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpotLight_getCosInnerAngle : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getCosInnerAngle(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpotLight_getCosInnerAngle : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_SpotLight_getOuterAngle(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpotLight* cobj = (cocos2d::SpotLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpotLight_getOuterAngle : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getOuterAngle(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpotLight_getOuterAngle : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_SpotLight_getInnerAngle(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpotLight* cobj = (cocos2d::SpotLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpotLight_getInnerAngle : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getInnerAngle(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpotLight_getInnerAngle : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_SpotLight_getDirection(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpotLight* cobj = (cocos2d::SpotLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpotLight_getDirection : Invalid Native Object"); + if (argc == 0) { + cocos2d::Vec3 ret = cobj->getDirection(); + jsval jsret = JSVAL_NULL; + jsret = vector3_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpotLight_getDirection : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_SpotLight_getCosOuterAngle(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpotLight* cobj = (cocos2d::SpotLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpotLight_getCosOuterAngle : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getCosOuterAngle(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpotLight_getCosOuterAngle : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_SpotLight_setOuterAngle(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpotLight* cobj = (cocos2d::SpotLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpotLight_setOuterAngle : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpotLight_setOuterAngle : Error processing arguments"); + cobj->setOuterAngle(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpotLight_setOuterAngle : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_SpotLight_setInnerAngle(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpotLight* cobj = (cocos2d::SpotLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpotLight_setInnerAngle : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpotLight_setInnerAngle : Error processing arguments"); + cobj->setInnerAngle(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpotLight_setInnerAngle : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_SpotLight_getDirectionInWorld(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpotLight* cobj = (cocos2d::SpotLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpotLight_getDirectionInWorld : Invalid Native Object"); + if (argc == 0) { + cocos2d::Vec3 ret = cobj->getDirectionInWorld(); + jsval jsret = JSVAL_NULL; + jsret = vector3_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpotLight_getDirectionInWorld : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_SpotLight_setRange(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::SpotLight* cobj = (cocos2d::SpotLight *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpotLight_setRange : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpotLight_setRange : Error processing arguments"); + cobj->setRange(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_SpotLight_setRange : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_SpotLight_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 6) { + cocos2d::Vec3 arg0; + cocos2d::Vec3 arg1; + cocos2d::Color3B arg2; + double arg3; + double arg4; + double arg5; + ok &= jsval_to_vector3(cx, args.get(0), &arg0); + ok &= jsval_to_vector3(cx, args.get(1), &arg1); + ok &= jsval_to_cccolor3b(cx, args.get(2), &arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); + ok &= JS::ToNumber( cx, args.get(4), &arg4) && !isnan(arg4); + ok &= JS::ToNumber( cx, args.get(5), &arg5) && !isnan(arg5); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpotLight_create : Error processing arguments"); + cocos2d::SpotLight* ret = cocos2d::SpotLight::create(arg0, arg1, arg2, arg3, arg4, arg5); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::SpotLight*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_SpotLight_create : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_SpotLight_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::SpotLight* cobj = new (std::nothrow) cocos2d::SpotLight(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::SpotLight"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocos2d_BaseLight_prototype; + +void js_cocos2d_SpotLight_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (SpotLight)", obj); +} + +void js_register_cocos2dx_SpotLight(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_SpotLight_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_SpotLight_class->name = "SpotLight"; + jsb_cocos2d_SpotLight_class->addProperty = JS_PropertyStub; + jsb_cocos2d_SpotLight_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_SpotLight_class->getProperty = JS_PropertyStub; + jsb_cocos2d_SpotLight_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_SpotLight_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_SpotLight_class->resolve = JS_ResolveStub; + jsb_cocos2d_SpotLight_class->convert = JS_ConvertStub; + jsb_cocos2d_SpotLight_class->finalize = js_cocos2d_SpotLight_finalize; + jsb_cocos2d_SpotLight_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("getRange", js_cocos2dx_SpotLight_getRange, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setDirection", js_cocos2dx_SpotLight_setDirection, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getCosInnerAngle", js_cocos2dx_SpotLight_getCosInnerAngle, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getOuterAngle", js_cocos2dx_SpotLight_getOuterAngle, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getInnerAngle", js_cocos2dx_SpotLight_getInnerAngle, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDirection", js_cocos2dx_SpotLight_getDirection, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getCosOuterAngle", js_cocos2dx_SpotLight_getCosOuterAngle, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setOuterAngle", js_cocos2dx_SpotLight_setOuterAngle, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setInnerAngle", js_cocos2dx_SpotLight_setInnerAngle, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDirectionInWorld", js_cocos2dx_SpotLight_getDirectionInWorld, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setRange", js_cocos2dx_SpotLight_setRange, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_SpotLight_create, 6, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_SpotLight_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_BaseLight_prototype), + jsb_cocos2d_SpotLight_class, + js_cocos2dx_SpotLight_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "SpotLight", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_SpotLight_class; + p->proto = jsb_cocos2d_SpotLight_prototype; + p->parentProto = jsb_cocos2d_BaseLight_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_AmbientLight_class; +JSObject *jsb_cocos2d_AmbientLight_prototype; + +bool js_cocos2dx_AmbientLight_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + cocos2d::Color3B arg0; + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AmbientLight_create : Error processing arguments"); + cocos2d::AmbientLight* ret = cocos2d::AmbientLight::create(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::AmbientLight*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_AmbientLight_create : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_AmbientLight_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::AmbientLight* cobj = new (std::nothrow) cocos2d::AmbientLight(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::AmbientLight"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocos2d_BaseLight_prototype; + +void js_cocos2d_AmbientLight_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (AmbientLight)", obj); +} + +void js_register_cocos2dx_AmbientLight(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_AmbientLight_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_AmbientLight_class->name = "AmbientLight"; + jsb_cocos2d_AmbientLight_class->addProperty = JS_PropertyStub; + jsb_cocos2d_AmbientLight_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_AmbientLight_class->getProperty = JS_PropertyStub; + jsb_cocos2d_AmbientLight_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_AmbientLight_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_AmbientLight_class->resolve = JS_ResolveStub; + jsb_cocos2d_AmbientLight_class->convert = JS_ConvertStub; + jsb_cocos2d_AmbientLight_class->finalize = js_cocos2d_AmbientLight_finalize; + jsb_cocos2d_AmbientLight_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_AmbientLight_create, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_AmbientLight_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_BaseLight_prototype), + jsb_cocos2d_AmbientLight_class, + js_cocos2dx_AmbientLight_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "AmbientLight", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_AmbientLight_class; + p->proto = jsb_cocos2d_AmbientLight_prototype; + p->parentProto = jsb_cocos2d_BaseLight_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + JSClass *jsb_cocos2d_GLProgram_class; JSObject *jsb_cocos2d_GLProgram_prototype; bool js_cocos2dx_GLProgram_getFragmentShaderLog(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_getFragmentShaderLog : Invalid Native Object"); @@ -55679,7 +58091,7 @@ bool js_cocos2dx_GLProgram_getFragmentShaderLog(JSContext *cx, uint32_t argc, js std::string ret = cobj->getFragmentShaderLog(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -55688,20 +58100,20 @@ bool js_cocos2dx_GLProgram_getFragmentShaderLog(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_GLProgram_bindAttribLocation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_bindAttribLocation : Invalid Native Object"); if (argc == 2) { std::string arg0; unsigned int arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_bindAttribLocation : Error processing arguments"); cobj->bindAttribLocation(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -55710,20 +58122,20 @@ bool js_cocos2dx_GLProgram_bindAttribLocation(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_GLProgram_getUniformLocationForName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_getUniformLocationForName : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_getUniformLocationForName : Error processing arguments"); int ret = cobj->getUniformLocationForName(arg0); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -55732,13 +58144,14 @@ bool js_cocos2dx_GLProgram_getUniformLocationForName(JSContext *cx, uint32_t arg } bool js_cocos2dx_GLProgram_use(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_use : Invalid Native Object"); if (argc == 0) { cobj->use(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -55747,7 +58160,8 @@ bool js_cocos2dx_GLProgram_use(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLProgram_getVertexShaderLog(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_getVertexShaderLog : Invalid Native Object"); @@ -55755,7 +58169,7 @@ bool js_cocos2dx_GLProgram_getVertexShaderLog(JSContext *cx, uint32_t argc, jsva std::string ret = cobj->getVertexShaderLog(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -55764,20 +58178,20 @@ bool js_cocos2dx_GLProgram_getVertexShaderLog(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_GLProgram_getUniform(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_getUniform : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_getUniform : Error processing arguments"); cocos2d::Uniform* ret = cobj->getUniform(arg0); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR Uniform*; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -55786,22 +58200,22 @@ bool js_cocos2dx_GLProgram_getUniform(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLProgram_initWithByteArrays(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_initWithByteArrays : Invalid Native Object"); if (argc == 2) { const char* arg0; const char* arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_initWithByteArrays : Error processing arguments"); bool ret = cobj->initWithByteArrays(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -55810,20 +58224,20 @@ bool js_cocos2dx_GLProgram_initWithByteArrays(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_GLProgram_setUniformLocationWith1f(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith1f : Invalid Native Object"); if (argc == 2) { int arg0; double arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith1f : Error processing arguments"); cobj->setUniformLocationWith1f(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -55832,22 +58246,22 @@ bool js_cocos2dx_GLProgram_setUniformLocationWith1f(JSContext *cx, uint32_t argc } bool js_cocos2dx_GLProgram_initWithFilenames(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_initWithFilenames : Invalid Native Object"); if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_initWithFilenames : Error processing arguments"); bool ret = cobj->initWithFilenames(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -55856,9 +58270,9 @@ bool js_cocos2dx_GLProgram_initWithFilenames(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_GLProgram_setUniformLocationWith3f(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith3f : Invalid Native Object"); @@ -55867,13 +58281,13 @@ bool js_cocos2dx_GLProgram_setUniformLocationWith3f(JSContext *cx, uint32_t argc double arg1; double arg2; double arg3; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith3f : Error processing arguments"); cobj->setUniformLocationWith3f(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -55882,22 +58296,22 @@ bool js_cocos2dx_GLProgram_setUniformLocationWith3f(JSContext *cx, uint32_t argc } bool js_cocos2dx_GLProgram_setUniformsForBuiltins(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::GLProgram* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_setUniformsForBuiltins : Invalid Native Object"); do { if (argc == 1) { cocos2d::Mat4 arg0; - ok &= jsval_to_matrix(cx, argv[0], &arg0); + ok &= jsval_to_matrix(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cobj->setUniformsForBuiltins(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -55905,7 +58319,7 @@ bool js_cocos2dx_GLProgram_setUniformsForBuiltins(JSContext *cx, uint32_t argc, do { if (argc == 0) { cobj->setUniformsForBuiltins(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -55915,9 +58329,9 @@ bool js_cocos2dx_GLProgram_setUniformsForBuiltins(JSContext *cx, uint32_t argc, } bool js_cocos2dx_GLProgram_setUniformLocationWith3i(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith3i : Invalid Native Object"); @@ -55926,13 +58340,13 @@ bool js_cocos2dx_GLProgram_setUniformLocationWith3i(JSContext *cx, uint32_t argc int arg1; int arg2; int arg3; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith3i : Error processing arguments"); cobj->setUniformLocationWith3i(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -55941,9 +58355,9 @@ bool js_cocos2dx_GLProgram_setUniformLocationWith3i(JSContext *cx, uint32_t argc } bool js_cocos2dx_GLProgram_setUniformLocationWith4f(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith4f : Invalid Native Object"); @@ -55953,14 +58367,14 @@ bool js_cocos2dx_GLProgram_setUniformLocationWith4f(JSContext *cx, uint32_t argc double arg2; double arg3; double arg4; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[4]), &arg4); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); + ok &= JS::ToNumber( cx, args.get(4), &arg4) && !isnan(arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith4f : Error processing arguments"); cobj->setUniformLocationWith4f(arg0, arg1, arg2, arg3, arg4); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -55969,13 +58383,14 @@ bool js_cocos2dx_GLProgram_setUniformLocationWith4f(JSContext *cx, uint32_t argc } bool js_cocos2dx_GLProgram_updateUniforms(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_updateUniforms : Invalid Native Object"); if (argc == 0) { cobj->updateUniforms(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -55984,20 +58399,20 @@ bool js_cocos2dx_GLProgram_updateUniforms(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_GLProgram_getUniformLocation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_getUniformLocation : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_getUniformLocation : Error processing arguments"); int ret = cobj->getUniformLocation(arg0); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -56006,7 +58421,8 @@ bool js_cocos2dx_GLProgram_getUniformLocation(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_GLProgram_link(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_link : Invalid Native Object"); @@ -56014,7 +58430,7 @@ bool js_cocos2dx_GLProgram_link(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->link(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -56023,13 +58439,14 @@ bool js_cocos2dx_GLProgram_link(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLProgram_reset(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_reset : Invalid Native Object"); if (argc == 0) { cobj->reset(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56038,20 +58455,20 @@ bool js_cocos2dx_GLProgram_reset(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_GLProgram_getAttribLocation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_getAttribLocation : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_getAttribLocation : Error processing arguments"); int ret = cobj->getAttribLocation(arg0); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -56060,20 +58477,20 @@ bool js_cocos2dx_GLProgram_getAttribLocation(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_GLProgram_getVertexAttrib(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_getVertexAttrib : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_getVertexAttrib : Error processing arguments"); cocos2d::VertexAttrib* ret = cobj->getVertexAttrib(arg0); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR VertexAttrib*; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -56082,9 +58499,9 @@ bool js_cocos2dx_GLProgram_getVertexAttrib(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_GLProgram_setUniformLocationWith2f(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith2f : Invalid Native Object"); @@ -56092,12 +58509,12 @@ bool js_cocos2dx_GLProgram_setUniformLocationWith2f(JSContext *cx, uint32_t argc int arg0; double arg1; double arg2; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith2f : Error processing arguments"); cobj->setUniformLocationWith2f(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56106,9 +58523,9 @@ bool js_cocos2dx_GLProgram_setUniformLocationWith2f(JSContext *cx, uint32_t argc } bool js_cocos2dx_GLProgram_setUniformLocationWith4i(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith4i : Invalid Native Object"); @@ -56118,14 +58535,14 @@ bool js_cocos2dx_GLProgram_setUniformLocationWith4i(JSContext *cx, uint32_t argc int arg2; int arg3; int arg4; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith4i : Error processing arguments"); cobj->setUniformLocationWith4i(arg0, arg1, arg2, arg3, arg4); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56134,20 +58551,20 @@ bool js_cocos2dx_GLProgram_setUniformLocationWith4i(JSContext *cx, uint32_t argc } bool js_cocos2dx_GLProgram_setUniformLocationWith1i(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith1i : Invalid Native Object"); if (argc == 2) { int arg0; int arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith1i : Error processing arguments"); cobj->setUniformLocationWith1i(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56156,9 +58573,9 @@ bool js_cocos2dx_GLProgram_setUniformLocationWith1i(JSContext *cx, uint32_t argc } bool js_cocos2dx_GLProgram_setUniformLocationWith2i(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith2i : Invalid Native Object"); @@ -56166,12 +58583,12 @@ bool js_cocos2dx_GLProgram_setUniformLocationWith2i(JSContext *cx, uint32_t argc int arg0; int arg1; int arg2; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_setUniformLocationWith2i : Error processing arguments"); cobj->setUniformLocationWith2i(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56180,13 +58597,13 @@ bool js_cocos2dx_GLProgram_setUniformLocationWith2i(JSContext *cx, uint32_t argc } bool js_cocos2dx_GLProgram_createWithByteArrays(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { const char* arg0; const char* arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_createWithByteArrays : Error processing arguments"); cocos2d::GLProgram* ret = cocos2d::GLProgram::createWithByteArrays(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -56198,7 +58615,7 @@ bool js_cocos2dx_GLProgram_createWithByteArrays(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_GLProgram_createWithByteArrays : wrong number of arguments"); @@ -56207,13 +58624,13 @@ bool js_cocos2dx_GLProgram_createWithByteArrays(JSContext *cx, uint32_t argc, js bool js_cocos2dx_GLProgram_createWithFilenames(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgram_createWithFilenames : Error processing arguments"); cocos2d::GLProgram* ret = cocos2d::GLProgram::createWithFilenames(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -56225,7 +58642,7 @@ bool js_cocos2dx_GLProgram_createWithFilenames(JSContext *cx, uint32_t argc, jsv jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_GLProgram_createWithFilenames : wrong number of arguments"); @@ -56234,7 +58651,7 @@ bool js_cocos2dx_GLProgram_createWithFilenames(JSContext *cx, uint32_t argc, jsv bool js_cocos2dx_GLProgram_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::GLProgram* cobj = new (std::nothrow) cocos2d::GLProgram(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -56248,13 +58665,16 @@ bool js_cocos2dx_GLProgram_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::GLProgram"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::GLProgram"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -56264,7 +58684,23 @@ void js_cocos2d_GLProgram_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (GLProgram)", obj); } -void js_register_cocos2dx_GLProgram(JSContext *cx, JSObject *global) { +static bool js_cocos2d_GLProgram_ctor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::GLProgram *nobj = new (std::nothrow) cocos2d::GLProgram(); + if (nobj) { + nobj->autorelease(); + } + js_proxy_t* p = jsb_new_proxy(nobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::GLProgram"); + bool isFound = false; + if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); + return true; +} +void js_register_cocos2dx_GLProgram(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_GLProgram_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_GLProgram_class->name = "GLProgram"; jsb_cocos2d_GLProgram_class->addProperty = JS_PropertyStub; @@ -56278,8 +58714,8 @@ void js_register_cocos2dx_GLProgram(JSContext *cx, JSObject *global) { jsb_cocos2d_GLProgram_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -56306,6 +58742,7 @@ void js_register_cocos2dx_GLProgram(JSContext *cx, JSObject *global) { JS_FN("setUniformLocationWith4i", js_cocos2dx_GLProgram_setUniformLocationWith4i, 5, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setUniformLocationI32", js_cocos2dx_GLProgram_setUniformLocationWith1i, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setUniformLocationWith2i", js_cocos2dx_GLProgram_setUniformLocationWith2i, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_GLProgram_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -56317,7 +58754,7 @@ void js_register_cocos2dx_GLProgram(JSContext *cx, JSObject *global) { jsb_cocos2d_GLProgram_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_GLProgram_class, js_cocos2dx_GLProgram_constructor, 0, // constructor properties, @@ -56348,13 +58785,14 @@ JSObject *jsb_cocos2d_GLProgramCache_prototype; bool js_cocos2dx_GLProgramCache_reloadDefaultGLPrograms(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgramCache* cobj = (cocos2d::GLProgramCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramCache_reloadDefaultGLPrograms : Invalid Native Object"); if (argc == 0) { cobj->reloadDefaultGLPrograms(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56363,9 +58801,9 @@ bool js_cocos2dx_GLProgramCache_reloadDefaultGLPrograms(JSContext *cx, uint32_t } bool js_cocos2dx_GLProgramCache_addGLProgram(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgramCache* cobj = (cocos2d::GLProgramCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramCache_addGLProgram : Invalid Native Object"); @@ -56373,17 +58811,17 @@ bool js_cocos2dx_GLProgramCache_addGLProgram(JSContext *cx, uint32_t argc, jsval cocos2d::GLProgram* arg0; std::string arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::GLProgram*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgramCache_addGLProgram : Error processing arguments"); cobj->addGLProgram(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56392,15 +58830,15 @@ bool js_cocos2dx_GLProgramCache_addGLProgram(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_GLProgramCache_getGLProgram(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgramCache* cobj = (cocos2d::GLProgramCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramCache_getGLProgram : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgramCache_getGLProgram : Error processing arguments"); cocos2d::GLProgram* ret = cobj->getGLProgram(arg0); jsval jsret = JSVAL_NULL; @@ -56412,7 +58850,7 @@ bool js_cocos2dx_GLProgramCache_getGLProgram(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -56421,13 +58859,14 @@ bool js_cocos2dx_GLProgramCache_getGLProgram(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_GLProgramCache_loadDefaultGLPrograms(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgramCache* cobj = (cocos2d::GLProgramCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramCache_loadDefaultGLPrograms : Invalid Native Object"); if (argc == 0) { cobj->loadDefaultGLPrograms(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56436,9 +58875,10 @@ bool js_cocos2dx_GLProgramCache_loadDefaultGLPrograms(JSContext *cx, uint32_t ar } bool js_cocos2dx_GLProgramCache_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::GLProgramCache::destroyInstance(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_GLProgramCache_destroyInstance : wrong number of arguments"); @@ -56447,6 +58887,7 @@ bool js_cocos2dx_GLProgramCache_destroyInstance(JSContext *cx, uint32_t argc, js bool js_cocos2dx_GLProgramCache_getInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::GLProgramCache* ret = cocos2d::GLProgramCache::getInstance(); jsval jsret = JSVAL_NULL; @@ -56458,7 +58899,7 @@ bool js_cocos2dx_GLProgramCache_getInstance(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_GLProgramCache_getInstance : wrong number of arguments"); @@ -56467,7 +58908,7 @@ bool js_cocos2dx_GLProgramCache_getInstance(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_GLProgramCache_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::GLProgramCache* cobj = new (std::nothrow) cocos2d::GLProgramCache(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -56481,13 +58922,16 @@ bool js_cocos2dx_GLProgramCache_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::GLProgramCache"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::GLProgramCache"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -56497,7 +58941,7 @@ void js_cocos2d_GLProgramCache_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (GLProgramCache)", obj); } -void js_register_cocos2dx_GLProgramCache(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_GLProgramCache(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_GLProgramCache_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_GLProgramCache_class->name = "ShaderCache"; jsb_cocos2d_GLProgramCache_class->addProperty = JS_PropertyStub; @@ -56511,8 +58955,8 @@ void js_register_cocos2dx_GLProgramCache(JSContext *cx, JSObject *global) { jsb_cocos2d_GLProgramCache_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -56531,7 +58975,7 @@ void js_register_cocos2dx_GLProgramCache(JSContext *cx, JSObject *global) { jsb_cocos2d_GLProgramCache_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_GLProgramCache_class, js_cocos2dx_GLProgramCache_constructor, 0, // constructor properties, @@ -56562,20 +59006,20 @@ JSObject *jsb_cocos2d_TextureCache_prototype; bool js_cocos2dx_TextureCache_reloadTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextureCache* cobj = (cocos2d::TextureCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextureCache_reloadTexture : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TextureCache_reloadTexture : Error processing arguments"); bool ret = cobj->reloadTexture(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -56584,13 +59028,14 @@ bool js_cocos2dx_TextureCache_reloadTexture(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TextureCache_unbindAllImageAsync(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextureCache* cobj = (cocos2d::TextureCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextureCache_unbindAllImageAsync : Invalid Native Object"); if (argc == 0) { cobj->unbindAllImageAsync(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56599,18 +59044,18 @@ bool js_cocos2dx_TextureCache_unbindAllImageAsync(JSContext *cx, uint32_t argc, } bool js_cocos2dx_TextureCache_removeTextureForKey(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextureCache* cobj = (cocos2d::TextureCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextureCache_removeTextureForKey : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TextureCache_removeTextureForKey : Error processing arguments"); cobj->removeTextureForKey(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56619,13 +59064,14 @@ bool js_cocos2dx_TextureCache_removeTextureForKey(JSContext *cx, uint32_t argc, } bool js_cocos2dx_TextureCache_removeAllTextures(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextureCache* cobj = (cocos2d::TextureCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextureCache_removeAllTextures : Invalid Native Object"); if (argc == 0) { cobj->removeAllTextures(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56634,21 +59080,22 @@ bool js_cocos2dx_TextureCache_removeAllTextures(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_TextureCache_addImageAsync(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextureCache* cobj = (cocos2d::TextureCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextureCache_addImageAsync : Invalid Native Object"); if (argc == 2) { std::string arg0; std::function arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](cocos2d::Texture2D* larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -56658,8 +59105,8 @@ bool js_cocos2dx_TextureCache_addImageAsync(JSContext *cx, uint32_t argc, jsval largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -56674,7 +59121,7 @@ bool js_cocos2dx_TextureCache_addImageAsync(JSContext *cx, uint32_t argc, jsval ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TextureCache_addImageAsync : Error processing arguments"); cobj->addImageAsync(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56683,7 +59130,8 @@ bool js_cocos2dx_TextureCache_addImageAsync(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TextureCache_getDescription(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextureCache* cobj = (cocos2d::TextureCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextureCache_getDescription : Invalid Native Object"); @@ -56691,7 +59139,7 @@ bool js_cocos2dx_TextureCache_getDescription(JSContext *cx, uint32_t argc, jsval std::string ret = cobj->getDescription(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -56700,7 +59148,8 @@ bool js_cocos2dx_TextureCache_getDescription(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TextureCache_getCachedTextureInfo(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextureCache* cobj = (cocos2d::TextureCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextureCache_getCachedTextureInfo : Invalid Native Object"); @@ -56708,7 +59157,7 @@ bool js_cocos2dx_TextureCache_getCachedTextureInfo(JSContext *cx, uint32_t argc, std::string ret = cobj->getCachedTextureInfo(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -56717,12 +59166,12 @@ bool js_cocos2dx_TextureCache_getCachedTextureInfo(JSContext *cx, uint32_t argc, } bool js_cocos2dx_TextureCache_addImage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TextureCache* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TextureCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextureCache_addImage : Invalid Native Object"); @@ -56730,16 +59179,16 @@ bool js_cocos2dx_TextureCache_addImage(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 2) { cocos2d::Image* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Image*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::Texture2D* ret = cobj->addImage(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -56751,7 +59200,7 @@ bool js_cocos2dx_TextureCache_addImage(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -56759,7 +59208,7 @@ bool js_cocos2dx_TextureCache_addImage(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Texture2D* ret = cobj->addImage(arg0); jsval jsret = JSVAL_NULL; @@ -56771,7 +59220,7 @@ bool js_cocos2dx_TextureCache_addImage(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -56781,18 +59230,18 @@ bool js_cocos2dx_TextureCache_addImage(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TextureCache_unbindImageAsync(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextureCache* cobj = (cocos2d::TextureCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextureCache_unbindImageAsync : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TextureCache_unbindImageAsync : Error processing arguments"); cobj->unbindImageAsync(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56801,15 +59250,15 @@ bool js_cocos2dx_TextureCache_unbindImageAsync(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_TextureCache_getTextureForKey(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextureCache* cobj = (cocos2d::TextureCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextureCache_getTextureForKey : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TextureCache_getTextureForKey : Error processing arguments"); cocos2d::Texture2D* ret = cobj->getTextureForKey(arg0); jsval jsret = JSVAL_NULL; @@ -56821,7 +59270,7 @@ bool js_cocos2dx_TextureCache_getTextureForKey(JSContext *cx, uint32_t argc, jsv jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -56830,13 +59279,14 @@ bool js_cocos2dx_TextureCache_getTextureForKey(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_TextureCache_removeUnusedTextures(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextureCache* cobj = (cocos2d::TextureCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextureCache_removeUnusedTextures : Invalid Native Object"); if (argc == 0) { cobj->removeUnusedTextures(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56845,25 +59295,25 @@ bool js_cocos2dx_TextureCache_removeUnusedTextures(JSContext *cx, uint32_t argc, } bool js_cocos2dx_TextureCache_removeTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextureCache* cobj = (cocos2d::TextureCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextureCache_removeTexture : Invalid Native Object"); if (argc == 1) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TextureCache_removeTexture : Error processing arguments"); cobj->removeTexture(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56872,13 +59322,14 @@ bool js_cocos2dx_TextureCache_removeTexture(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TextureCache_waitForQuit(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextureCache* cobj = (cocos2d::TextureCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextureCache_waitForQuit : Invalid Native Object"); if (argc == 0) { cobj->waitForQuit(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56887,7 +59338,7 @@ bool js_cocos2dx_TextureCache_waitForQuit(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_TextureCache_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TextureCache* cobj = new (std::nothrow) cocos2d::TextureCache(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -56901,13 +59352,16 @@ bool js_cocos2dx_TextureCache_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TextureCache"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TextureCache"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -56917,7 +59371,7 @@ void js_cocos2d_TextureCache_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TextureCache)", obj); } -void js_register_cocos2dx_TextureCache(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TextureCache(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TextureCache_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TextureCache_class->name = "TextureCache"; jsb_cocos2d_TextureCache_class->addProperty = JS_PropertyStub; @@ -56931,8 +59385,8 @@ void js_register_cocos2dx_TextureCache(JSContext *cx, JSObject *global) { jsb_cocos2d_TextureCache_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -56956,7 +59410,7 @@ void js_register_cocos2dx_TextureCache(JSContext *cx, JSObject *global) { jsb_cocos2d_TextureCache_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_TextureCache_class, js_cocos2dx_TextureCache_constructor, 0, // constructor properties, @@ -56987,14 +59441,14 @@ JSObject *jsb_cocos2d_Device_prototype; bool js_cocos2dx_Device_setAccelerometerEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Device_setAccelerometerEnabled : Error processing arguments"); cocos2d::Device::setAccelerometerEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Device_setAccelerometerEnabled : wrong number of arguments"); @@ -57003,14 +59457,14 @@ bool js_cocos2dx_Device_setAccelerometerEnabled(JSContext *cx, uint32_t argc, js bool js_cocos2dx_Device_setKeepScreenOn(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Device_setKeepScreenOn : Error processing arguments"); cocos2d::Device::setKeepScreenOn(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Device_setKeepScreenOn : wrong number of arguments"); @@ -57019,14 +59473,14 @@ bool js_cocos2dx_Device_setKeepScreenOn(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Device_setAccelerometerInterval(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Device_setAccelerometerInterval : Error processing arguments"); cocos2d::Device::setAccelerometerInterval(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Device_setAccelerometerInterval : wrong number of arguments"); @@ -57035,11 +59489,12 @@ bool js_cocos2dx_Device_setAccelerometerInterval(JSContext *cx, uint32_t argc, j bool js_cocos2dx_Device_getDPI(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { int ret = cocos2d::Device::getDPI(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Device_getDPI : wrong number of arguments"); @@ -57052,7 +59507,7 @@ void js_cocos2d_Device_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Device)", obj); } -void js_register_cocos2dx_Device(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Device(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Device_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Device_class->name = "Device"; jsb_cocos2d_Device_class->addProperty = JS_PropertyStub; @@ -57066,8 +59521,8 @@ void js_register_cocos2dx_Device(JSContext *cx, JSObject *global) { jsb_cocos2d_Device_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -57084,7 +59539,7 @@ void js_register_cocos2dx_Device(JSContext *cx, JSObject *global) { jsb_cocos2d_Device_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_Device_class, dummy_constructor, 0, // no constructor properties, @@ -57115,20 +59570,20 @@ JSObject *jsb_cocos2d_SAXParser_prototype; bool js_cocos2dx_SAXParser_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SAXParser* cobj = (cocos2d::SAXParser *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SAXParser_init : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SAXParser_init : Error processing arguments"); bool ret = cobj->init(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -57141,7 +59596,7 @@ void js_cocos2d_SAXParser_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (SAXParser)", obj); } -void js_register_cocos2dx_SAXParser(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_SAXParser(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_SAXParser_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_SAXParser_class->name = "PlistParser"; jsb_cocos2d_SAXParser_class->addProperty = JS_PropertyStub; @@ -57155,8 +59610,8 @@ void js_register_cocos2dx_SAXParser(JSContext *cx, JSObject *global) { jsb_cocos2d_SAXParser_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -57168,7 +59623,7 @@ void js_register_cocos2dx_SAXParser(JSContext *cx, JSObject *global) { jsb_cocos2d_SAXParser_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_SAXParser_class, empty_constructor, 0, properties, @@ -57199,20 +59654,20 @@ JSObject *jsb_cocos2d_Application_prototype; bool js_cocos2dx_Application_openURL(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Application* cobj = (cocos2d::Application *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Application_openURL : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Application_openURL : Error processing arguments"); bool ret = cobj->openURL(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -57221,7 +59676,8 @@ bool js_cocos2dx_Application_openURL(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Application_getTargetPlatform(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Application* cobj = (cocos2d::Application *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Application_getTargetPlatform : Invalid Native Object"); @@ -57229,7 +59685,7 @@ bool js_cocos2dx_Application_getTargetPlatform(JSContext *cx, uint32_t argc, jsv int ret = (int)cobj->getTargetPlatform(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -57238,7 +59694,8 @@ bool js_cocos2dx_Application_getTargetPlatform(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_Application_getCurrentLanguage(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Application* cobj = (cocos2d::Application *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Application_getCurrentLanguage : Invalid Native Object"); @@ -57246,7 +59703,7 @@ bool js_cocos2dx_Application_getCurrentLanguage(JSContext *cx, uint32_t argc, js int ret = (int)cobj->getCurrentLanguage(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -57255,6 +59712,7 @@ bool js_cocos2dx_Application_getCurrentLanguage(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_Application_getInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Application* ret = cocos2d::Application::getInstance(); jsval jsret = JSVAL_NULL; @@ -57266,7 +59724,7 @@ bool js_cocos2dx_Application_getInstance(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Application_getInstance : wrong number of arguments"); @@ -57279,7 +59737,7 @@ void js_cocos2d_Application_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Application)", obj); } -void js_register_cocos2dx_Application(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Application(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Application_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Application_class->name = "Application"; jsb_cocos2d_Application_class->addProperty = JS_PropertyStub; @@ -57293,8 +59751,8 @@ void js_register_cocos2dx_Application(JSContext *cx, JSObject *global) { jsb_cocos2d_Application_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -57311,7 +59769,7 @@ void js_register_cocos2dx_Application(JSContext *cx, JSObject *global) { jsb_cocos2d_Application_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_Application_class, empty_constructor, 0, properties, @@ -57342,15 +59800,15 @@ JSObject *jsb_cocos2d_AnimationCache_prototype; bool js_cocos2dx_AnimationCache_getAnimation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AnimationCache* cobj = (cocos2d::AnimationCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AnimationCache_getAnimation : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AnimationCache_getAnimation : Error processing arguments"); cocos2d::Animation* ret = cobj->getAnimation(arg0); jsval jsret = JSVAL_NULL; @@ -57362,7 +59820,7 @@ bool js_cocos2dx_AnimationCache_getAnimation(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -57371,9 +59829,9 @@ bool js_cocos2dx_AnimationCache_getAnimation(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_AnimationCache_addAnimation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AnimationCache* cobj = (cocos2d::AnimationCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AnimationCache_addAnimation : Invalid Native Object"); @@ -57381,17 +59839,17 @@ bool js_cocos2dx_AnimationCache_addAnimation(JSContext *cx, uint32_t argc, jsval cocos2d::Animation* arg0; std::string arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Animation*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AnimationCache_addAnimation : Error processing arguments"); cobj->addAnimation(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -57400,7 +59858,8 @@ bool js_cocos2dx_AnimationCache_addAnimation(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_AnimationCache_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AnimationCache* cobj = (cocos2d::AnimationCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AnimationCache_init : Invalid Native Object"); @@ -57408,7 +59867,7 @@ bool js_cocos2dx_AnimationCache_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -57417,20 +59876,20 @@ bool js_cocos2dx_AnimationCache_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_AnimationCache_addAnimationsWithDictionary(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AnimationCache* cobj = (cocos2d::AnimationCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AnimationCache_addAnimationsWithDictionary : Invalid Native Object"); if (argc == 2) { cocos2d::ValueMap arg0; std::string arg1; - ok &= jsval_to_ccvaluemap(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_ccvaluemap(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AnimationCache_addAnimationsWithDictionary : Error processing arguments"); cobj->addAnimationsWithDictionary(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -57439,18 +59898,18 @@ bool js_cocos2dx_AnimationCache_addAnimationsWithDictionary(JSContext *cx, uint3 } bool js_cocos2dx_AnimationCache_removeAnimation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AnimationCache* cobj = (cocos2d::AnimationCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AnimationCache_removeAnimation : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AnimationCache_removeAnimation : Error processing arguments"); cobj->removeAnimation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -57459,18 +59918,18 @@ bool js_cocos2dx_AnimationCache_removeAnimation(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_AnimationCache_addAnimationsWithFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::AnimationCache* cobj = (cocos2d::AnimationCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AnimationCache_addAnimationsWithFile : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AnimationCache_addAnimationsWithFile : Error processing arguments"); cobj->addAnimationsWithFile(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -57479,9 +59938,10 @@ bool js_cocos2dx_AnimationCache_addAnimationsWithFile(JSContext *cx, uint32_t ar } bool js_cocos2dx_AnimationCache_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::AnimationCache::destroyInstance(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_AnimationCache_destroyInstance : wrong number of arguments"); @@ -57490,6 +59950,7 @@ bool js_cocos2dx_AnimationCache_destroyInstance(JSContext *cx, uint32_t argc, js bool js_cocos2dx_AnimationCache_getInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::AnimationCache* ret = cocos2d::AnimationCache::getInstance(); jsval jsret = JSVAL_NULL; @@ -57501,7 +59962,7 @@ bool js_cocos2dx_AnimationCache_getInstance(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_AnimationCache_getInstance : wrong number of arguments"); @@ -57510,7 +59971,7 @@ bool js_cocos2dx_AnimationCache_getInstance(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_AnimationCache_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::AnimationCache* cobj = new (std::nothrow) cocos2d::AnimationCache(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -57524,13 +59985,16 @@ bool js_cocos2dx_AnimationCache_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::AnimationCache"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::AnimationCache"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -57540,7 +60004,7 @@ void js_cocos2d_AnimationCache_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (AnimationCache)", obj); } -void js_register_cocos2dx_AnimationCache(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_AnimationCache(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_AnimationCache_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_AnimationCache_class->name = "AnimationCache"; jsb_cocos2d_AnimationCache_class->addProperty = JS_PropertyStub; @@ -57554,8 +60018,8 @@ void js_register_cocos2dx_AnimationCache(JSContext *cx, JSObject *global) { jsb_cocos2d_AnimationCache_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -57576,7 +60040,7 @@ void js_register_cocos2dx_AnimationCache(JSContext *cx, JSObject *global) { jsb_cocos2d_AnimationCache_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_AnimationCache_class, js_cocos2dx_AnimationCache_constructor, 0, // constructor properties, @@ -57607,27 +60071,27 @@ JSObject *jsb_cocos2d_SpriteFrameCache_prototype; bool js_cocos2dx_SpriteFrameCache_addSpriteFramesWithFileContent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrameCache* cobj = (cocos2d::SpriteFrameCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrameCache_addSpriteFramesWithFileContent : Invalid Native Object"); if (argc == 2) { std::string arg0; cocos2d::Texture2D* arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrameCache_addSpriteFramesWithFileContent : Error processing arguments"); cobj->addSpriteFramesWithFileContent(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -57636,25 +60100,25 @@ bool js_cocos2dx_SpriteFrameCache_addSpriteFramesWithFileContent(JSContext *cx, } bool js_cocos2dx_SpriteFrameCache_addSpriteFramesWithFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::SpriteFrameCache* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::SpriteFrameCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrameCache_addSpriteFramesWithFile : Invalid Native Object"); do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cobj->addSpriteFramesWithFile(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -57662,10 +60126,10 @@ bool js_cocos2dx_SpriteFrameCache_addSpriteFramesWithFile(JSContext *cx, uint32_ do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cobj->addSpriteFramesWithFile(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -57673,20 +60137,20 @@ bool js_cocos2dx_SpriteFrameCache_addSpriteFramesWithFile(JSContext *cx, uint32_ do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Texture2D* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cobj->addSpriteFramesWithFile(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -57696,9 +60160,9 @@ bool js_cocos2dx_SpriteFrameCache_addSpriteFramesWithFile(JSContext *cx, uint32_ } bool js_cocos2dx_SpriteFrameCache_addSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrameCache* cobj = (cocos2d::SpriteFrameCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrameCache_addSpriteFrame : Invalid Native Object"); @@ -57706,17 +60170,17 @@ bool js_cocos2dx_SpriteFrameCache_addSpriteFrame(JSContext *cx, uint32_t argc, j cocos2d::SpriteFrame* arg0; std::string arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrameCache_addSpriteFrame : Error processing arguments"); cobj->addSpriteFrame(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -57725,13 +60189,14 @@ bool js_cocos2dx_SpriteFrameCache_addSpriteFrame(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_SpriteFrameCache_removeUnusedSpriteFrames(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrameCache* cobj = (cocos2d::SpriteFrameCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrameCache_removeUnusedSpriteFrames : Invalid Native Object"); if (argc == 0) { cobj->removeUnusedSpriteFrames(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -57740,15 +60205,15 @@ bool js_cocos2dx_SpriteFrameCache_removeUnusedSpriteFrames(JSContext *cx, uint32 } bool js_cocos2dx_SpriteFrameCache_getSpriteFrameByName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrameCache* cobj = (cocos2d::SpriteFrameCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrameCache_getSpriteFrameByName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrameCache_getSpriteFrameByName : Error processing arguments"); cocos2d::SpriteFrame* ret = cobj->getSpriteFrameByName(arg0); jsval jsret = JSVAL_NULL; @@ -57760,7 +60225,7 @@ bool js_cocos2dx_SpriteFrameCache_getSpriteFrameByName(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -57769,18 +60234,18 @@ bool js_cocos2dx_SpriteFrameCache_getSpriteFrameByName(JSContext *cx, uint32_t a } bool js_cocos2dx_SpriteFrameCache_removeSpriteFramesFromFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrameCache* cobj = (cocos2d::SpriteFrameCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrameCache_removeSpriteFramesFromFile : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrameCache_removeSpriteFramesFromFile : Error processing arguments"); cobj->removeSpriteFramesFromFile(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -57789,7 +60254,8 @@ bool js_cocos2dx_SpriteFrameCache_removeSpriteFramesFromFile(JSContext *cx, uint } bool js_cocos2dx_SpriteFrameCache_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrameCache* cobj = (cocos2d::SpriteFrameCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrameCache_init : Invalid Native Object"); @@ -57797,7 +60263,7 @@ bool js_cocos2dx_SpriteFrameCache_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -57806,13 +60272,14 @@ bool js_cocos2dx_SpriteFrameCache_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_SpriteFrameCache_removeSpriteFrames(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrameCache* cobj = (cocos2d::SpriteFrameCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrameCache_removeSpriteFrames : Invalid Native Object"); if (argc == 0) { cobj->removeSpriteFrames(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -57821,25 +60288,25 @@ bool js_cocos2dx_SpriteFrameCache_removeSpriteFrames(JSContext *cx, uint32_t arg } bool js_cocos2dx_SpriteFrameCache_removeSpriteFramesFromTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrameCache* cobj = (cocos2d::SpriteFrameCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrameCache_removeSpriteFramesFromTexture : Invalid Native Object"); if (argc == 1) { cocos2d::Texture2D* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Texture2D*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrameCache_removeSpriteFramesFromTexture : Error processing arguments"); cobj->removeSpriteFramesFromTexture(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -57848,18 +60315,18 @@ bool js_cocos2dx_SpriteFrameCache_removeSpriteFramesFromTexture(JSContext *cx, u } bool js_cocos2dx_SpriteFrameCache_removeSpriteFramesFromFileContent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrameCache* cobj = (cocos2d::SpriteFrameCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrameCache_removeSpriteFramesFromFileContent : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrameCache_removeSpriteFramesFromFileContent : Error processing arguments"); cobj->removeSpriteFramesFromFileContent(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -57868,18 +60335,18 @@ bool js_cocos2dx_SpriteFrameCache_removeSpriteFramesFromFileContent(JSContext *c } bool js_cocos2dx_SpriteFrameCache_removeSpriteFrameByName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteFrameCache* cobj = (cocos2d::SpriteFrameCache *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteFrameCache_removeSpriteFrameByName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SpriteFrameCache_removeSpriteFrameByName : Error processing arguments"); cobj->removeSpriteFrameByName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -57888,9 +60355,10 @@ bool js_cocos2dx_SpriteFrameCache_removeSpriteFrameByName(JSContext *cx, uint32_ } bool js_cocos2dx_SpriteFrameCache_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::SpriteFrameCache::destroyInstance(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_SpriteFrameCache_destroyInstance : wrong number of arguments"); @@ -57899,6 +60367,7 @@ bool js_cocos2dx_SpriteFrameCache_destroyInstance(JSContext *cx, uint32_t argc, bool js_cocos2dx_SpriteFrameCache_getInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::SpriteFrameCache* ret = cocos2d::SpriteFrameCache::getInstance(); jsval jsret = JSVAL_NULL; @@ -57910,7 +60379,7 @@ bool js_cocos2dx_SpriteFrameCache_getInstance(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_SpriteFrameCache_getInstance : wrong number of arguments"); @@ -57923,7 +60392,7 @@ void js_cocos2d_SpriteFrameCache_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (SpriteFrameCache)", obj); } -void js_register_cocos2dx_SpriteFrameCache(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_SpriteFrameCache(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_SpriteFrameCache_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_SpriteFrameCache_class->name = "SpriteFrameCache"; jsb_cocos2d_SpriteFrameCache_class->addProperty = JS_PropertyStub; @@ -57937,8 +60406,8 @@ void js_register_cocos2dx_SpriteFrameCache(JSContext *cx, JSObject *global) { jsb_cocos2d_SpriteFrameCache_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -57964,7 +60433,7 @@ void js_register_cocos2dx_SpriteFrameCache(JSContext *cx, JSObject *global) { jsb_cocos2d_SpriteFrameCache_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_SpriteFrameCache_class, empty_constructor, 0, properties, @@ -57995,7 +60464,8 @@ JSObject *jsb_cocos2d_TextFieldTTF_prototype; bool js_cocos2dx_TextFieldTTF_getCharCount(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextFieldTTF* cobj = (cocos2d::TextFieldTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextFieldTTF_getCharCount : Invalid Native Object"); @@ -58003,7 +60473,7 @@ bool js_cocos2dx_TextFieldTTF_getCharCount(JSContext *cx, uint32_t argc, jsval * int ret = cobj->getCharCount(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -58012,18 +60482,18 @@ bool js_cocos2dx_TextFieldTTF_getCharCount(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_TextFieldTTF_setSecureTextEntry(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextFieldTTF* cobj = (cocos2d::TextFieldTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextFieldTTF_setSecureTextEntry : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TextFieldTTF_setSecureTextEntry : Error processing arguments"); cobj->setSecureTextEntry(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -58032,7 +60502,8 @@ bool js_cocos2dx_TextFieldTTF_setSecureTextEntry(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_TextFieldTTF_getColorSpaceHolder(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextFieldTTF* cobj = (cocos2d::TextFieldTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextFieldTTF_getColorSpaceHolder : Invalid Native Object"); @@ -58040,7 +60511,7 @@ bool js_cocos2dx_TextFieldTTF_getColorSpaceHolder(JSContext *cx, uint32_t argc, const cocos2d::Color4B& ret = cobj->getColorSpaceHolder(); jsval jsret = JSVAL_NULL; jsret = cccolor4b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -58049,30 +60520,30 @@ bool js_cocos2dx_TextFieldTTF_getColorSpaceHolder(JSContext *cx, uint32_t argc, } bool js_cocos2dx_TextFieldTTF_initWithPlaceHolder(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TextFieldTTF* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TextFieldTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextFieldTTF_initWithPlaceHolder : Invalid Native Object"); do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } bool ret = cobj->initWithPlaceHolder(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -58080,24 +60551,24 @@ bool js_cocos2dx_TextFieldTTF_initWithPlaceHolder(JSContext *cx, uint32_t argc, do { if (argc == 5) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Size arg1; - ok &= jsval_to_ccsize(cx, argv[1], &arg1); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::TextHAlignment arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } std::string arg3; - ok &= jsval_to_std_string(cx, argv[3], &arg3); + ok &= jsval_to_std_string(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } double arg4; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[4]), &arg4); + ok &= JS::ToNumber( cx, args.get(4), &arg4) && !isnan(arg4); if (!ok) { ok = true; break; } bool ret = cobj->initWithPlaceHolder(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -58107,22 +60578,22 @@ bool js_cocos2dx_TextFieldTTF_initWithPlaceHolder(JSContext *cx, uint32_t argc, } bool js_cocos2dx_TextFieldTTF_setColorSpaceHolder(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TextFieldTTF* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TextFieldTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextFieldTTF_setColorSpaceHolder : Invalid Native Object"); do { if (argc == 1) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cobj->setColorSpaceHolder(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -58130,10 +60601,10 @@ bool js_cocos2dx_TextFieldTTF_setColorSpaceHolder(JSContext *cx, uint32_t argc, do { if (argc == 1) { cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cobj->setColorSpaceHolder(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -58143,7 +60614,8 @@ bool js_cocos2dx_TextFieldTTF_setColorSpaceHolder(JSContext *cx, uint32_t argc, } bool js_cocos2dx_TextFieldTTF_detachWithIME(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextFieldTTF* cobj = (cocos2d::TextFieldTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextFieldTTF_detachWithIME : Invalid Native Object"); @@ -58151,7 +60623,7 @@ bool js_cocos2dx_TextFieldTTF_detachWithIME(JSContext *cx, uint32_t argc, jsval bool ret = cobj->detachWithIME(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -58160,18 +60632,18 @@ bool js_cocos2dx_TextFieldTTF_detachWithIME(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TextFieldTTF_setPlaceHolder(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextFieldTTF* cobj = (cocos2d::TextFieldTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextFieldTTF_setPlaceHolder : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TextFieldTTF_setPlaceHolder : Error processing arguments"); cobj->setPlaceHolder(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -58180,7 +60652,8 @@ bool js_cocos2dx_TextFieldTTF_setPlaceHolder(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TextFieldTTF_isSecureTextEntry(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextFieldTTF* cobj = (cocos2d::TextFieldTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextFieldTTF_isSecureTextEntry : Invalid Native Object"); @@ -58188,7 +60661,7 @@ bool js_cocos2dx_TextFieldTTF_isSecureTextEntry(JSContext *cx, uint32_t argc, js bool ret = cobj->isSecureTextEntry(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -58197,7 +60670,8 @@ bool js_cocos2dx_TextFieldTTF_isSecureTextEntry(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_TextFieldTTF_getPlaceHolder(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextFieldTTF* cobj = (cocos2d::TextFieldTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextFieldTTF_getPlaceHolder : Invalid Native Object"); @@ -58205,7 +60679,7 @@ bool js_cocos2dx_TextFieldTTF_getPlaceHolder(JSContext *cx, uint32_t argc, jsval const std::string& ret = cobj->getPlaceHolder(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -58214,7 +60688,8 @@ bool js_cocos2dx_TextFieldTTF_getPlaceHolder(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TextFieldTTF_attachWithIME(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TextFieldTTF* cobj = (cocos2d::TextFieldTTF *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TextFieldTTF_attachWithIME : Invalid Native Object"); @@ -58222,7 +60697,7 @@ bool js_cocos2dx_TextFieldTTF_attachWithIME(JSContext *cx, uint32_t argc, jsval bool ret = cobj->attachWithIME(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -58231,19 +60706,19 @@ bool js_cocos2dx_TextFieldTTF_attachWithIME(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TextFieldTTF_textFieldWithPlaceHolder(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::TextFieldTTF* ret = cocos2d::TextFieldTTF::textFieldWithPlaceHolder(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -58255,7 +60730,7 @@ bool js_cocos2dx_TextFieldTTF_textFieldWithPlaceHolder(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -58263,19 +60738,19 @@ bool js_cocos2dx_TextFieldTTF_textFieldWithPlaceHolder(JSContext *cx, uint32_t a do { if (argc == 5) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Size arg1; - ok &= jsval_to_ccsize(cx, argv[1], &arg1); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::TextHAlignment arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } std::string arg3; - ok &= jsval_to_std_string(cx, argv[3], &arg3); + ok &= jsval_to_std_string(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } double arg4; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[4]), &arg4); + ok &= JS::ToNumber( cx, args.get(4), &arg4) && !isnan(arg4); if (!ok) { ok = true; break; } cocos2d::TextFieldTTF* ret = cocos2d::TextFieldTTF::textFieldWithPlaceHolder(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; @@ -58287,7 +60762,7 @@ bool js_cocos2dx_TextFieldTTF_textFieldWithPlaceHolder(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -58296,7 +60771,7 @@ bool js_cocos2dx_TextFieldTTF_textFieldWithPlaceHolder(JSContext *cx, uint32_t a } bool js_cocos2dx_TextFieldTTF_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TextFieldTTF* cobj = new (std::nothrow) cocos2d::TextFieldTTF(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -58310,13 +60785,16 @@ bool js_cocos2dx_TextFieldTTF_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TextFieldTTF"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TextFieldTTF"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -58329,21 +60807,21 @@ void js_cocos2d_TextFieldTTF_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_TextFieldTTF_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::TextFieldTTF *nobj = new (std::nothrow) cocos2d::TextFieldTTF(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TextFieldTTF"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TextFieldTTF"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_TextFieldTTF(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TextFieldTTF(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TextFieldTTF_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TextFieldTTF_class->name = "TextFieldTTF"; jsb_cocos2d_TextFieldTTF_class->addProperty = JS_PropertyStub; @@ -58357,8 +60835,8 @@ void js_register_cocos2dx_TextFieldTTF(JSContext *cx, JSObject *global) { jsb_cocos2d_TextFieldTTF_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -58383,7 +60861,7 @@ void js_register_cocos2dx_TextFieldTTF(JSContext *cx, JSObject *global) { jsb_cocos2d_TextFieldTTF_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Label_prototype, + JS::RootedObject(cx, jsb_cocos2d_Label_prototype), jsb_cocos2d_TextFieldTTF_class, js_cocos2dx_TextFieldTTF_constructor, 0, // constructor properties, @@ -58414,12 +60892,12 @@ JSObject *jsb_cocos2d_ParallaxNode_prototype; bool js_cocos2dx_ParallaxNode_getParallaxArray(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::ParallaxNode* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::ParallaxNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParallaxNode_getParallaxArray : Invalid Native Object"); @@ -58428,7 +60906,7 @@ bool js_cocos2dx_ParallaxNode_getParallaxArray(JSContext *cx, uint32_t argc, jsv const cocos2d::_ccArray* ret = cobj->getParallaxArray(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR _ccArray*; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -58438,7 +60916,7 @@ bool js_cocos2dx_ParallaxNode_getParallaxArray(JSContext *cx, uint32_t argc, jsv cocos2d::_ccArray* ret = cobj->getParallaxArray(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR _ccArray*; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -58448,9 +60926,9 @@ bool js_cocos2dx_ParallaxNode_getParallaxArray(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ParallaxNode_addChild(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParallaxNode* cobj = (cocos2d::ParallaxNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParallaxNode_addChild : Invalid Native Object"); @@ -58460,19 +60938,19 @@ bool js_cocos2dx_ParallaxNode_addChild(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vec2 arg2; cocos2d::Vec2 arg3; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - ok &= jsval_to_vector2(cx, argv[2], &arg2); - ok &= jsval_to_vector2(cx, argv[3], &arg3); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_vector2(cx, args.get(2), &arg2); + ok &= jsval_to_vector2(cx, args.get(3), &arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParallaxNode_addChild : Error processing arguments"); cobj->addChild(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -58481,18 +60959,18 @@ bool js_cocos2dx_ParallaxNode_addChild(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ParallaxNode_removeAllChildrenWithCleanup(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParallaxNode* cobj = (cocos2d::ParallaxNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParallaxNode_removeAllChildrenWithCleanup : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParallaxNode_removeAllChildrenWithCleanup : Error processing arguments"); cobj->removeAllChildrenWithCleanup(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -58501,9 +60979,9 @@ bool js_cocos2dx_ParallaxNode_removeAllChildrenWithCleanup(JSContext *cx, uint32 } bool js_cocos2dx_ParallaxNode_setParallaxArray(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ParallaxNode* cobj = (cocos2d::ParallaxNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParallaxNode_setParallaxArray : Invalid Native Object"); @@ -58513,7 +60991,7 @@ bool js_cocos2dx_ParallaxNode_setParallaxArray(JSContext *cx, uint32_t argc, jsv ok = false; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParallaxNode_setParallaxArray : Error processing arguments"); cobj->setParallaxArray(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -58522,6 +61000,7 @@ bool js_cocos2dx_ParallaxNode_setParallaxArray(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ParallaxNode_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ParallaxNode* ret = cocos2d::ParallaxNode::create(); jsval jsret = JSVAL_NULL; @@ -58533,7 +61012,7 @@ bool js_cocos2dx_ParallaxNode_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ParallaxNode_create : wrong number of arguments"); @@ -58542,7 +61021,7 @@ bool js_cocos2dx_ParallaxNode_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ParallaxNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ParallaxNode* cobj = new (std::nothrow) cocos2d::ParallaxNode(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -58556,13 +61035,16 @@ bool js_cocos2dx_ParallaxNode_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParallaxNode"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParallaxNode"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -58575,21 +61057,21 @@ void js_cocos2d_ParallaxNode_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ParallaxNode_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ParallaxNode *nobj = new (std::nothrow) cocos2d::ParallaxNode(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParallaxNode"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ParallaxNode"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ParallaxNode(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ParallaxNode(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ParallaxNode_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ParallaxNode_class->name = "ParallaxNode"; jsb_cocos2d_ParallaxNode_class->addProperty = JS_PropertyStub; @@ -58603,8 +61085,8 @@ void js_register_cocos2dx_ParallaxNode(JSContext *cx, JSObject *global) { jsb_cocos2d_ParallaxNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -58623,7 +61105,7 @@ void js_register_cocos2dx_ParallaxNode(JSContext *cx, JSObject *global) { jsb_cocos2d_ParallaxNode_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_ParallaxNode_class, js_cocos2dx_ParallaxNode_constructor, 0, // constructor properties, @@ -58654,18 +61136,18 @@ JSObject *jsb_cocos2d_TMXObjectGroup_prototype; bool js_cocos2dx_TMXObjectGroup_setPositionOffset(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXObjectGroup* cobj = (cocos2d::TMXObjectGroup *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXObjectGroup_setPositionOffset : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXObjectGroup_setPositionOffset : Error processing arguments"); cobj->setPositionOffset(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -58674,20 +61156,20 @@ bool js_cocos2dx_TMXObjectGroup_setPositionOffset(JSContext *cx, uint32_t argc, } bool js_cocos2dx_TMXObjectGroup_getProperty(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXObjectGroup* cobj = (cocos2d::TMXObjectGroup *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXObjectGroup_getProperty : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXObjectGroup_getProperty : Error processing arguments"); cocos2d::Value ret = cobj->getProperty(arg0); jsval jsret = JSVAL_NULL; jsret = ccvalue_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -58696,7 +61178,8 @@ bool js_cocos2dx_TMXObjectGroup_getProperty(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXObjectGroup_getPositionOffset(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXObjectGroup* cobj = (cocos2d::TMXObjectGroup *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXObjectGroup_getPositionOffset : Invalid Native Object"); @@ -58704,7 +61187,7 @@ bool js_cocos2dx_TMXObjectGroup_getPositionOffset(JSContext *cx, uint32_t argc, const cocos2d::Vec2& ret = cobj->getPositionOffset(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -58713,20 +61196,20 @@ bool js_cocos2dx_TMXObjectGroup_getPositionOffset(JSContext *cx, uint32_t argc, } bool js_cocos2dx_TMXObjectGroup_getObject(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXObjectGroup* cobj = (cocos2d::TMXObjectGroup *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXObjectGroup_getObject : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXObjectGroup_getObject : Error processing arguments"); cocos2d::ValueMap ret = cobj->getObject(arg0); jsval jsret = JSVAL_NULL; jsret = ccvaluemap_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -58735,12 +61218,12 @@ bool js_cocos2dx_TMXObjectGroup_getObject(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_TMXObjectGroup_getObjects(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TMXObjectGroup* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TMXObjectGroup *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXObjectGroup_getObjects : Invalid Native Object"); @@ -58749,7 +61232,7 @@ bool js_cocos2dx_TMXObjectGroup_getObjects(JSContext *cx, uint32_t argc, jsval * cocos2d::ValueVector& ret = cobj->getObjects(); jsval jsret = JSVAL_NULL; jsret = ccvaluevector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -58759,7 +61242,7 @@ bool js_cocos2dx_TMXObjectGroup_getObjects(JSContext *cx, uint32_t argc, jsval * const cocos2d::ValueVector& ret = cobj->getObjects(); jsval jsret = JSVAL_NULL; jsret = ccvaluevector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -58769,18 +61252,18 @@ bool js_cocos2dx_TMXObjectGroup_getObjects(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_TMXObjectGroup_setGroupName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXObjectGroup* cobj = (cocos2d::TMXObjectGroup *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXObjectGroup_setGroupName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXObjectGroup_setGroupName : Error processing arguments"); cobj->setGroupName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -58789,12 +61272,12 @@ bool js_cocos2dx_TMXObjectGroup_setGroupName(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXObjectGroup_getProperties(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TMXObjectGroup* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TMXObjectGroup *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXObjectGroup_getProperties : Invalid Native Object"); @@ -58803,7 +61286,7 @@ bool js_cocos2dx_TMXObjectGroup_getProperties(JSContext *cx, uint32_t argc, jsva cocos2d::ValueMap& ret = cobj->getProperties(); jsval jsret = JSVAL_NULL; jsret = ccvaluemap_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -58813,7 +61296,7 @@ bool js_cocos2dx_TMXObjectGroup_getProperties(JSContext *cx, uint32_t argc, jsva const cocos2d::ValueMap& ret = cobj->getProperties(); jsval jsret = JSVAL_NULL; jsret = ccvaluemap_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -58823,7 +61306,8 @@ bool js_cocos2dx_TMXObjectGroup_getProperties(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_TMXObjectGroup_getGroupName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXObjectGroup* cobj = (cocos2d::TMXObjectGroup *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXObjectGroup_getGroupName : Invalid Native Object"); @@ -58831,7 +61315,7 @@ bool js_cocos2dx_TMXObjectGroup_getGroupName(JSContext *cx, uint32_t argc, jsval const std::string& ret = cobj->getGroupName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -58840,18 +61324,18 @@ bool js_cocos2dx_TMXObjectGroup_getGroupName(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXObjectGroup_setProperties(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXObjectGroup* cobj = (cocos2d::TMXObjectGroup *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXObjectGroup_setProperties : Invalid Native Object"); if (argc == 1) { cocos2d::ValueMap arg0; - ok &= jsval_to_ccvaluemap(cx, argv[0], &arg0); + ok &= jsval_to_ccvaluemap(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXObjectGroup_setProperties : Error processing arguments"); cobj->setProperties(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -58860,18 +61344,18 @@ bool js_cocos2dx_TMXObjectGroup_setProperties(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_TMXObjectGroup_setObjects(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXObjectGroup* cobj = (cocos2d::TMXObjectGroup *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXObjectGroup_setObjects : Invalid Native Object"); if (argc == 1) { cocos2d::ValueVector arg0; - ok &= jsval_to_ccvaluevector(cx, argv[0], &arg0); + ok &= jsval_to_ccvaluevector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXObjectGroup_setObjects : Error processing arguments"); cobj->setObjects(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -58880,7 +61364,7 @@ bool js_cocos2dx_TMXObjectGroup_setObjects(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_TMXObjectGroup_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TMXObjectGroup* cobj = new (std::nothrow) cocos2d::TMXObjectGroup(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -58894,13 +61378,16 @@ bool js_cocos2dx_TMXObjectGroup_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXObjectGroup"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXObjectGroup"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -58910,7 +61397,7 @@ void js_cocos2d_TMXObjectGroup_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TMXObjectGroup)", obj); } -void js_register_cocos2dx_TMXObjectGroup(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TMXObjectGroup(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TMXObjectGroup_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TMXObjectGroup_class->name = "TMXObjectGroup"; jsb_cocos2d_TMXObjectGroup_class->addProperty = JS_PropertyStub; @@ -58924,8 +61411,8 @@ void js_register_cocos2dx_TMXObjectGroup(JSContext *cx, JSObject *global) { jsb_cocos2d_TMXObjectGroup_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -58946,7 +61433,7 @@ void js_register_cocos2dx_TMXObjectGroup(JSContext *cx, JSObject *global) { jsb_cocos2d_TMXObjectGroup_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_TMXObjectGroup_class, js_cocos2dx_TMXObjectGroup_constructor, 0, // constructor properties, @@ -58977,18 +61464,18 @@ JSObject *jsb_cocos2d_TMXLayerInfo_prototype; bool js_cocos2dx_TMXLayerInfo_setProperties(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayerInfo* cobj = (cocos2d::TMXLayerInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayerInfo_setProperties : Invalid Native Object"); if (argc == 1) { cocos2d::ValueMap arg0; - ok &= jsval_to_ccvaluemap(cx, argv[0], &arg0); + ok &= jsval_to_ccvaluemap(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXLayerInfo_setProperties : Error processing arguments"); cobj->setProperties(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -58997,7 +61484,8 @@ bool js_cocos2dx_TMXLayerInfo_setProperties(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXLayerInfo_getProperties(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayerInfo* cobj = (cocos2d::TMXLayerInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayerInfo_getProperties : Invalid Native Object"); @@ -59005,7 +61493,7 @@ bool js_cocos2dx_TMXLayerInfo_getProperties(JSContext *cx, uint32_t argc, jsval cocos2d::ValueMap& ret = cobj->getProperties(); jsval jsret = JSVAL_NULL; jsret = ccvaluemap_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59014,7 +61502,7 @@ bool js_cocos2dx_TMXLayerInfo_getProperties(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXLayerInfo_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TMXLayerInfo* cobj = new (std::nothrow) cocos2d::TMXLayerInfo(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -59028,13 +61516,16 @@ bool js_cocos2dx_TMXLayerInfo_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXLayerInfo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXLayerInfo"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -59044,7 +61535,7 @@ void js_cocos2d_TMXLayerInfo_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TMXLayerInfo)", obj); } -void js_register_cocos2dx_TMXLayerInfo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TMXLayerInfo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TMXLayerInfo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TMXLayerInfo_class->name = "TMXLayerInfo"; jsb_cocos2d_TMXLayerInfo_class->addProperty = JS_PropertyStub; @@ -59058,8 +61549,8 @@ void js_register_cocos2dx_TMXLayerInfo(JSContext *cx, JSObject *global) { jsb_cocos2d_TMXLayerInfo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -59072,7 +61563,7 @@ void js_register_cocos2dx_TMXLayerInfo(JSContext *cx, JSObject *global) { jsb_cocos2d_TMXLayerInfo_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_TMXLayerInfo_class, js_cocos2dx_TMXLayerInfo_constructor, 0, // constructor properties, @@ -59103,20 +61594,20 @@ JSObject *jsb_cocos2d_TMXTilesetInfo_prototype; bool js_cocos2dx_TMXTilesetInfo_getRectForGID(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTilesetInfo* cobj = (cocos2d::TMXTilesetInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTilesetInfo_getRectForGID : Invalid Native Object"); if (argc == 1) { unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXTilesetInfo_getRectForGID : Error processing arguments"); cocos2d::Rect ret = cobj->getRectForGID(arg0); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59125,7 +61616,7 @@ bool js_cocos2dx_TMXTilesetInfo_getRectForGID(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_TMXTilesetInfo_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TMXTilesetInfo* cobj = new (std::nothrow) cocos2d::TMXTilesetInfo(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -59139,13 +61630,16 @@ bool js_cocos2dx_TMXTilesetInfo_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXTilesetInfo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXTilesetInfo"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -59155,7 +61649,7 @@ void js_cocos2d_TMXTilesetInfo_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (TMXTilesetInfo)", obj); } -void js_register_cocos2dx_TMXTilesetInfo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TMXTilesetInfo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TMXTilesetInfo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TMXTilesetInfo_class->name = "TMXTilesetInfo"; jsb_cocos2d_TMXTilesetInfo_class->addProperty = JS_PropertyStub; @@ -59169,8 +61663,8 @@ void js_register_cocos2dx_TMXTilesetInfo(JSContext *cx, JSObject *global) { jsb_cocos2d_TMXTilesetInfo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -59182,7 +61676,7 @@ void js_register_cocos2dx_TMXTilesetInfo(JSContext *cx, JSObject *global) { jsb_cocos2d_TMXTilesetInfo_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_TMXTilesetInfo_class, js_cocos2dx_TMXTilesetInfo_constructor, 0, // constructor properties, @@ -59213,18 +61707,18 @@ JSObject *jsb_cocos2d_TMXMapInfo_prototype; bool js_cocos2dx_TMXMapInfo_setObjectGroups(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_setObjectGroups : Invalid Native Object"); if (argc == 1) { cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_setObjectGroups : Error processing arguments"); cobj->setObjectGroups(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -59233,18 +61727,18 @@ bool js_cocos2dx_TMXMapInfo_setObjectGroups(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXMapInfo_setTileSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_setTileSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_setTileSize : Error processing arguments"); cobj->setTileSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -59253,20 +61747,20 @@ bool js_cocos2dx_TMXMapInfo_setTileSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXMapInfo_initWithTMXFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_initWithTMXFile : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_initWithTMXFile : Error processing arguments"); bool ret = cobj->initWithTMXFile(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59275,7 +61769,8 @@ bool js_cocos2dx_TMXMapInfo_initWithTMXFile(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXMapInfo_getOrientation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_getOrientation : Invalid Native Object"); @@ -59283,7 +61778,7 @@ bool js_cocos2dx_TMXMapInfo_getOrientation(JSContext *cx, uint32_t argc, jsval * int ret = cobj->getOrientation(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59292,7 +61787,8 @@ bool js_cocos2dx_TMXMapInfo_getOrientation(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_TMXMapInfo_isStoringCharacters(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_isStoringCharacters : Invalid Native Object"); @@ -59300,7 +61796,7 @@ bool js_cocos2dx_TMXMapInfo_isStoringCharacters(JSContext *cx, uint32_t argc, js bool ret = cobj->isStoringCharacters(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59309,18 +61805,18 @@ bool js_cocos2dx_TMXMapInfo_isStoringCharacters(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_TMXMapInfo_setLayers(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_setLayers : Invalid Native Object"); if (argc == 1) { cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_setLayers : Error processing arguments"); cobj->setLayers(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -59329,20 +61825,20 @@ bool js_cocos2dx_TMXMapInfo_setLayers(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXMapInfo_parseXMLFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_parseXMLFile : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_parseXMLFile : Error processing arguments"); bool ret = cobj->parseXMLFile(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59351,7 +61847,8 @@ bool js_cocos2dx_TMXMapInfo_parseXMLFile(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TMXMapInfo_getParentElement(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_getParentElement : Invalid Native Object"); @@ -59359,7 +61856,7 @@ bool js_cocos2dx_TMXMapInfo_getParentElement(JSContext *cx, uint32_t argc, jsval int ret = cobj->getParentElement(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59368,18 +61865,18 @@ bool js_cocos2dx_TMXMapInfo_getParentElement(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXMapInfo_setTMXFileName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_setTMXFileName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_setTMXFileName : Error processing arguments"); cobj->setTMXFileName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -59388,20 +61885,20 @@ bool js_cocos2dx_TMXMapInfo_setTMXFileName(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_TMXMapInfo_parseXMLString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_parseXMLString : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_parseXMLString : Error processing arguments"); bool ret = cobj->parseXMLString(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59410,12 +61907,12 @@ bool js_cocos2dx_TMXMapInfo_parseXMLString(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_TMXMapInfo_getLayers(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TMXMapInfo* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_getLayers : Invalid Native Object"); @@ -59424,7 +61921,7 @@ bool js_cocos2dx_TMXMapInfo_getLayers(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vector& ret = cobj->getLayers(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -59434,7 +61931,7 @@ bool js_cocos2dx_TMXMapInfo_getLayers(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Vector& ret = cobj->getLayers(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -59444,12 +61941,12 @@ bool js_cocos2dx_TMXMapInfo_getLayers(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXMapInfo_getTilesets(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TMXMapInfo* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_getTilesets : Invalid Native Object"); @@ -59458,7 +61955,7 @@ bool js_cocos2dx_TMXMapInfo_getTilesets(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vector& ret = cobj->getTilesets(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -59468,7 +61965,7 @@ bool js_cocos2dx_TMXMapInfo_getTilesets(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Vector& ret = cobj->getTilesets(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -59478,7 +61975,8 @@ bool js_cocos2dx_TMXMapInfo_getTilesets(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXMapInfo_getParentGID(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_getParentGID : Invalid Native Object"); @@ -59486,7 +61984,7 @@ bool js_cocos2dx_TMXMapInfo_getParentGID(JSContext *cx, uint32_t argc, jsval *vp int ret = cobj->getParentGID(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59495,18 +61993,18 @@ bool js_cocos2dx_TMXMapInfo_getParentGID(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TMXMapInfo_setParentElement(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_setParentElement : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_setParentElement : Error processing arguments"); cobj->setParentElement(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -59515,22 +62013,22 @@ bool js_cocos2dx_TMXMapInfo_setParentElement(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXMapInfo_initWithXML(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_initWithXML : Invalid Native Object"); if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_initWithXML : Error processing arguments"); bool ret = cobj->initWithXML(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59539,18 +62037,18 @@ bool js_cocos2dx_TMXMapInfo_initWithXML(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXMapInfo_setParentGID(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_setParentGID : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_setParentGID : Error processing arguments"); cobj->setParentGID(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -59559,7 +62057,8 @@ bool js_cocos2dx_TMXMapInfo_setParentGID(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TMXMapInfo_getLayerAttribs(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_getLayerAttribs : Invalid Native Object"); @@ -59567,7 +62066,7 @@ bool js_cocos2dx_TMXMapInfo_getLayerAttribs(JSContext *cx, uint32_t argc, jsval int ret = cobj->getLayerAttribs(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59576,7 +62075,8 @@ bool js_cocos2dx_TMXMapInfo_getLayerAttribs(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXMapInfo_getTileSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_getTileSize : Invalid Native Object"); @@ -59584,7 +62084,7 @@ bool js_cocos2dx_TMXMapInfo_getTileSize(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Size& ret = cobj->getTileSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59593,7 +62093,8 @@ bool js_cocos2dx_TMXMapInfo_getTileSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXMapInfo_getTileProperties(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_getTileProperties : Invalid Native Object"); @@ -59601,7 +62102,7 @@ bool js_cocos2dx_TMXMapInfo_getTileProperties(JSContext *cx, uint32_t argc, jsva cocos2d::ValueMapIntKey& ret = cobj->getTileProperties(); jsval jsret = JSVAL_NULL; jsret = ccvaluemapintkey_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59610,12 +62111,12 @@ bool js_cocos2dx_TMXMapInfo_getTileProperties(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_TMXMapInfo_getObjectGroups(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TMXMapInfo* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_getObjectGroups : Invalid Native Object"); @@ -59624,7 +62125,7 @@ bool js_cocos2dx_TMXMapInfo_getObjectGroups(JSContext *cx, uint32_t argc, jsval cocos2d::Vector& ret = cobj->getObjectGroups(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -59634,7 +62135,7 @@ bool js_cocos2dx_TMXMapInfo_getObjectGroups(JSContext *cx, uint32_t argc, jsval const cocos2d::Vector& ret = cobj->getObjectGroups(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -59644,7 +62145,8 @@ bool js_cocos2dx_TMXMapInfo_getObjectGroups(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXMapInfo_getTMXFileName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_getTMXFileName : Invalid Native Object"); @@ -59652,7 +62154,7 @@ bool js_cocos2dx_TMXMapInfo_getTMXFileName(JSContext *cx, uint32_t argc, jsval * const std::string& ret = cobj->getTMXFileName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59661,18 +62163,18 @@ bool js_cocos2dx_TMXMapInfo_getTMXFileName(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_TMXMapInfo_setCurrentString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_setCurrentString : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_setCurrentString : Error processing arguments"); cobj->setCurrentString(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -59681,18 +62183,18 @@ bool js_cocos2dx_TMXMapInfo_setCurrentString(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXMapInfo_setProperties(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_setProperties : Invalid Native Object"); if (argc == 1) { cocos2d::ValueMap arg0; - ok &= jsval_to_ccvaluemap(cx, argv[0], &arg0); + ok &= jsval_to_ccvaluemap(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_setProperties : Error processing arguments"); cobj->setProperties(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -59701,18 +62203,18 @@ bool js_cocos2dx_TMXMapInfo_setProperties(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_TMXMapInfo_setOrientation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_setOrientation : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_setOrientation : Error processing arguments"); cobj->setOrientation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -59721,18 +62223,18 @@ bool js_cocos2dx_TMXMapInfo_setOrientation(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_TMXMapInfo_setTileProperties(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_setTileProperties : Invalid Native Object"); if (argc == 1) { cocos2d::ValueMapIntKey arg0; - ok &= jsval_to_ccvaluemapintkey(cx, argv[0], &arg0); + ok &= jsval_to_ccvaluemapintkey(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_setTileProperties : Error processing arguments"); cobj->setTileProperties(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -59741,18 +62243,18 @@ bool js_cocos2dx_TMXMapInfo_setTileProperties(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_TMXMapInfo_setMapSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_setMapSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_setMapSize : Error processing arguments"); cobj->setMapSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -59761,18 +62263,18 @@ bool js_cocos2dx_TMXMapInfo_setMapSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXMapInfo_setStoringCharacters(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_setStoringCharacters : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_setStoringCharacters : Error processing arguments"); cobj->setStoringCharacters(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -59781,7 +62283,8 @@ bool js_cocos2dx_TMXMapInfo_setStoringCharacters(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_TMXMapInfo_getMapSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_getMapSize : Invalid Native Object"); @@ -59789,7 +62292,7 @@ bool js_cocos2dx_TMXMapInfo_getMapSize(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Size& ret = cobj->getMapSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59798,18 +62301,18 @@ bool js_cocos2dx_TMXMapInfo_getMapSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXMapInfo_setTilesets(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_setTilesets : Invalid Native Object"); if (argc == 1) { cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_setTilesets : Error processing arguments"); cobj->setTilesets(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -59818,12 +62321,12 @@ bool js_cocos2dx_TMXMapInfo_setTilesets(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXMapInfo_getProperties(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TMXMapInfo* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_getProperties : Invalid Native Object"); @@ -59832,7 +62335,7 @@ bool js_cocos2dx_TMXMapInfo_getProperties(JSContext *cx, uint32_t argc, jsval *v cocos2d::ValueMap& ret = cobj->getProperties(); jsval jsret = JSVAL_NULL; jsret = ccvaluemap_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -59842,7 +62345,7 @@ bool js_cocos2dx_TMXMapInfo_getProperties(JSContext *cx, uint32_t argc, jsval *v const cocos2d::ValueMap& ret = cobj->getProperties(); jsval jsret = JSVAL_NULL; jsret = ccvaluemap_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -59852,7 +62355,8 @@ bool js_cocos2dx_TMXMapInfo_getProperties(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_TMXMapInfo_getCurrentString(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_getCurrentString : Invalid Native Object"); @@ -59860,7 +62364,7 @@ bool js_cocos2dx_TMXMapInfo_getCurrentString(JSContext *cx, uint32_t argc, jsval const std::string& ret = cobj->getCurrentString(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -59869,18 +62373,18 @@ bool js_cocos2dx_TMXMapInfo_getCurrentString(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXMapInfo_setLayerAttribs(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXMapInfo* cobj = (cocos2d::TMXMapInfo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXMapInfo_setLayerAttribs : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_setLayerAttribs : Error processing arguments"); cobj->setLayerAttribs(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -59889,11 +62393,11 @@ bool js_cocos2dx_TMXMapInfo_setLayerAttribs(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXMapInfo_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_create : Error processing arguments"); cocos2d::TMXMapInfo* ret = cocos2d::TMXMapInfo::create(arg0); jsval jsret = JSVAL_NULL; @@ -59905,7 +62409,7 @@ bool js_cocos2dx_TMXMapInfo_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TMXMapInfo_create : wrong number of arguments"); @@ -59914,13 +62418,13 @@ bool js_cocos2dx_TMXMapInfo_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_TMXMapInfo_createWithXML(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXMapInfo_createWithXML : Error processing arguments"); cocos2d::TMXMapInfo* ret = cocos2d::TMXMapInfo::createWithXML(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -59932,7 +62436,7 @@ bool js_cocos2dx_TMXMapInfo_createWithXML(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TMXMapInfo_createWithXML : wrong number of arguments"); @@ -59941,7 +62445,7 @@ bool js_cocos2dx_TMXMapInfo_createWithXML(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_TMXMapInfo_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TMXMapInfo* cobj = new (std::nothrow) cocos2d::TMXMapInfo(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -59955,13 +62459,16 @@ bool js_cocos2dx_TMXMapInfo_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXMapInfo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXMapInfo"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -59973,21 +62480,21 @@ void js_cocos2d_TMXMapInfo_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_TMXMapInfo_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::TMXMapInfo *nobj = new (std::nothrow) cocos2d::TMXMapInfo(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXMapInfo"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXMapInfo"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_TMXMapInfo(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TMXMapInfo(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TMXMapInfo_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TMXMapInfo_class->name = "TMXMapInfo"; jsb_cocos2d_TMXMapInfo_class->addProperty = JS_PropertyStub; @@ -60001,8 +62508,8 @@ void js_register_cocos2dx_TMXMapInfo(JSContext *cx, JSObject *global) { jsb_cocos2d_TMXMapInfo_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -60050,7 +62557,7 @@ void js_register_cocos2dx_TMXMapInfo(JSContext *cx, JSObject *global) { jsb_cocos2d_TMXMapInfo_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_TMXMapInfo_class, js_cocos2dx_TMXMapInfo_constructor, 0, // constructor properties, @@ -60081,33 +62588,33 @@ JSObject *jsb_cocos2d_TMXLayer_prototype; bool js_cocos2dx_TMXLayer_getTileGIDAt(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_getTileGIDAt : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXLayer_getTileGIDAt : Error processing arguments"); unsigned int ret = cobj->getTileGIDAt(arg0); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { cocos2d::Vec2 arg0; cocos2d::TMXTileFlags_* arg1; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); #pragma warning NO CONVERSION TO NATIVE FOR TMXTileFlags_* ok = false; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXLayer_getTileGIDAt : Error processing arguments"); unsigned int ret = cobj->getTileGIDAt(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60116,20 +62623,20 @@ bool js_cocos2dx_TMXLayer_getTileGIDAt(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_getPositionAt(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_getPositionAt : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXLayer_getPositionAt : Error processing arguments"); cocos2d::Vec2 ret = cobj->getPositionAt(arg0); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60138,18 +62645,18 @@ bool js_cocos2dx_TMXLayer_getPositionAt(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_setLayerOrientation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_setLayerOrientation : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXLayer_setLayerOrientation : Error processing arguments"); cobj->setLayerOrientation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -60158,13 +62665,14 @@ bool js_cocos2dx_TMXLayer_setLayerOrientation(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_TMXLayer_releaseMap(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_releaseMap : Invalid Native Object"); if (argc == 0) { cobj->releaseMap(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -60173,9 +62681,9 @@ bool js_cocos2dx_TMXLayer_releaseMap(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_setTiles(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_setTiles : Invalid Native Object"); @@ -60185,7 +62693,7 @@ bool js_cocos2dx_TMXLayer_setTiles(JSContext *cx, uint32_t argc, jsval *vp) ok = false; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXLayer_setTiles : Error processing arguments"); cobj->setTiles(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -60194,7 +62702,8 @@ bool js_cocos2dx_TMXLayer_setTiles(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_getLayerSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_getLayerSize : Invalid Native Object"); @@ -60202,7 +62711,7 @@ bool js_cocos2dx_TMXLayer_getLayerSize(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Size& ret = cobj->getLayerSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60211,18 +62720,18 @@ bool js_cocos2dx_TMXLayer_getLayerSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_setMapTileSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_setMapTileSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXLayer_setMapTileSize : Error processing arguments"); cobj->setMapTileSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -60231,7 +62740,8 @@ bool js_cocos2dx_TMXLayer_setMapTileSize(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TMXLayer_getLayerOrientation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_getLayerOrientation : Invalid Native Object"); @@ -60239,7 +62749,7 @@ bool js_cocos2dx_TMXLayer_getLayerOrientation(JSContext *cx, uint32_t argc, jsva int ret = cobj->getLayerOrientation(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60248,18 +62758,18 @@ bool js_cocos2dx_TMXLayer_getLayerOrientation(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_TMXLayer_setProperties(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_setProperties : Invalid Native Object"); if (argc == 1) { cocos2d::ValueMap arg0; - ok &= jsval_to_ccvaluemap(cx, argv[0], &arg0); + ok &= jsval_to_ccvaluemap(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXLayer_setProperties : Error processing arguments"); cobj->setProperties(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -60268,18 +62778,18 @@ bool js_cocos2dx_TMXLayer_setProperties(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_setLayerName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_setLayerName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXLayer_setLayerName : Error processing arguments"); cobj->setLayerName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -60288,18 +62798,18 @@ bool js_cocos2dx_TMXLayer_setLayerName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_removeTileAt(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_removeTileAt : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXLayer_removeTileAt : Error processing arguments"); cobj->removeTileAt(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -60308,9 +62818,9 @@ bool js_cocos2dx_TMXLayer_removeTileAt(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_initWithTilesetInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_initWithTilesetInfo : Invalid Native Object"); @@ -60319,25 +62829,25 @@ bool js_cocos2dx_TMXLayer_initWithTilesetInfo(JSContext *cx, uint32_t argc, jsva cocos2d::TMXLayerInfo* arg1; cocos2d::TMXMapInfo* arg2; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::TMXTilesetInfo*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::TMXLayerInfo*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::TMXMapInfo*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -60346,7 +62856,7 @@ bool js_cocos2dx_TMXLayer_initWithTilesetInfo(JSContext *cx, uint32_t argc, jsva bool ret = cobj->initWithTilesetInfo(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60355,13 +62865,14 @@ bool js_cocos2dx_TMXLayer_initWithTilesetInfo(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_TMXLayer_setupTiles(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_setupTiles : Invalid Native Object"); if (argc == 0) { cobj->setupTiles(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -60370,28 +62881,28 @@ bool js_cocos2dx_TMXLayer_setupTiles(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_setTileGID(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TMXLayer* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_setTileGID : Invalid Native Object"); do { if (argc == 3) { unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Vec2 arg1; - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::TMXTileFlags_ arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } cobj->setTileGID(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -60399,13 +62910,13 @@ bool js_cocos2dx_TMXLayer_setTileGID(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Vec2 arg1; - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cobj->setTileGID(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -60415,7 +62926,8 @@ bool js_cocos2dx_TMXLayer_setTileGID(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_getMapTileSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_getMapTileSize : Invalid Native Object"); @@ -60423,7 +62935,7 @@ bool js_cocos2dx_TMXLayer_getMapTileSize(JSContext *cx, uint32_t argc, jsval *vp const cocos2d::Size& ret = cobj->getMapTileSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60432,20 +62944,20 @@ bool js_cocos2dx_TMXLayer_getMapTileSize(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TMXLayer_getProperty(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_getProperty : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXLayer_getProperty : Error processing arguments"); cocos2d::Value ret = cobj->getProperty(arg0); jsval jsret = JSVAL_NULL; jsret = ccvalue_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60454,18 +62966,18 @@ bool js_cocos2dx_TMXLayer_getProperty(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_setLayerSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_setLayerSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXLayer_setLayerSize : Error processing arguments"); cobj->setLayerSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -60474,7 +62986,8 @@ bool js_cocos2dx_TMXLayer_setLayerSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_getLayerName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_getLayerName : Invalid Native Object"); @@ -60482,7 +62995,7 @@ bool js_cocos2dx_TMXLayer_getLayerName(JSContext *cx, uint32_t argc, jsval *vp) const std::string& ret = cobj->getLayerName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60491,25 +63004,25 @@ bool js_cocos2dx_TMXLayer_getLayerName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_setTileSet(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_setTileSet : Invalid Native Object"); if (argc == 1) { cocos2d::TMXTilesetInfo* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::TMXTilesetInfo*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXLayer_setTileSet : Error processing arguments"); cobj->setTileSet(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -60518,7 +63031,8 @@ bool js_cocos2dx_TMXLayer_setTileSet(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_getTileSet(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_getTileSet : Invalid Native Object"); @@ -60533,7 +63047,7 @@ bool js_cocos2dx_TMXLayer_getTileSet(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60542,12 +63056,12 @@ bool js_cocos2dx_TMXLayer_getTileSet(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_getProperties(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TMXLayer* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_getProperties : Invalid Native Object"); @@ -60556,7 +63070,7 @@ bool js_cocos2dx_TMXLayer_getProperties(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::ValueMap& ret = cobj->getProperties(); jsval jsret = JSVAL_NULL; jsret = ccvaluemap_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -60566,7 +63080,7 @@ bool js_cocos2dx_TMXLayer_getProperties(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::ValueMap& ret = cobj->getProperties(); jsval jsret = JSVAL_NULL; jsret = ccvaluemap_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -60576,15 +63090,15 @@ bool js_cocos2dx_TMXLayer_getProperties(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_getTileAt(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXLayer_getTileAt : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXLayer_getTileAt : Error processing arguments"); cocos2d::Sprite* ret = cobj->getTileAt(arg0); jsval jsret = JSVAL_NULL; @@ -60596,7 +63110,7 @@ bool js_cocos2dx_TMXLayer_getTileAt(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60605,32 +63119,32 @@ bool js_cocos2dx_TMXLayer_getTileAt(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXLayer_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 3) { cocos2d::TMXTilesetInfo* arg0; cocos2d::TMXLayerInfo* arg1; cocos2d::TMXMapInfo* arg2; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::TMXTilesetInfo*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::TMXLayerInfo*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::TMXMapInfo*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -60646,7 +63160,7 @@ bool js_cocos2dx_TMXLayer_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TMXLayer_create : wrong number of arguments"); @@ -60655,7 +63169,7 @@ bool js_cocos2dx_TMXLayer_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_TMXLayer_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TMXLayer* cobj = new (std::nothrow) cocos2d::TMXLayer(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -60669,13 +63183,16 @@ bool js_cocos2dx_TMXLayer_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXLayer"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXLayer"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -60688,21 +63205,21 @@ void js_cocos2d_TMXLayer_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_TMXLayer_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::TMXLayer *nobj = new (std::nothrow) cocos2d::TMXLayer(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXLayer"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXLayer"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_TMXLayer(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TMXLayer(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TMXLayer_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TMXLayer_class->name = "TMXLayer"; jsb_cocos2d_TMXLayer_class->addProperty = JS_PropertyStub; @@ -60716,8 +63233,8 @@ void js_register_cocos2dx_TMXLayer(JSContext *cx, JSObject *global) { jsb_cocos2d_TMXLayer_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -60754,7 +63271,7 @@ void js_register_cocos2dx_TMXLayer(JSContext *cx, JSObject *global) { jsb_cocos2d_TMXLayer_prototype = JS_InitClass( cx, global, - jsb_cocos2d_SpriteBatchNode_prototype, + JS::RootedObject(cx, jsb_cocos2d_SpriteBatchNode_prototype), jsb_cocos2d_TMXLayer_class, js_cocos2dx_TMXLayer_constructor, 0, // constructor properties, @@ -60785,18 +63302,18 @@ JSObject *jsb_cocos2d_TMXTiledMap_prototype; bool js_cocos2dx_TMXTiledMap_setObjectGroups(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTiledMap* cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_setObjectGroups : Invalid Native Object"); if (argc == 1) { cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXTiledMap_setObjectGroups : Error processing arguments"); cobj->setObjectGroups(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -60805,20 +63322,20 @@ bool js_cocos2dx_TMXTiledMap_setObjectGroups(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXTiledMap_getProperty(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTiledMap* cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_getProperty : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXTiledMap_getProperty : Error processing arguments"); cocos2d::Value ret = cobj->getProperty(arg0); jsval jsret = JSVAL_NULL; jsret = ccvalue_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60827,18 +63344,18 @@ bool js_cocos2dx_TMXTiledMap_getProperty(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TMXTiledMap_setMapSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTiledMap* cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_setMapSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXTiledMap_setMapSize : Error processing arguments"); cobj->setMapSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -60847,15 +63364,15 @@ bool js_cocos2dx_TMXTiledMap_setMapSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXTiledMap_getObjectGroup(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTiledMap* cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_getObjectGroup : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXTiledMap_getObjectGroup : Error processing arguments"); cocos2d::TMXObjectGroup* ret = cobj->getObjectGroup(arg0); jsval jsret = JSVAL_NULL; @@ -60867,7 +63384,7 @@ bool js_cocos2dx_TMXTiledMap_getObjectGroup(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60876,12 +63393,12 @@ bool js_cocos2dx_TMXTiledMap_getObjectGroup(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXTiledMap_getObjectGroups(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TMXTiledMap* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_getObjectGroups : Invalid Native Object"); @@ -60890,7 +63407,7 @@ bool js_cocos2dx_TMXTiledMap_getObjectGroups(JSContext *cx, uint32_t argc, jsval cocos2d::Vector& ret = cobj->getObjectGroups(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -60900,7 +63417,7 @@ bool js_cocos2dx_TMXTiledMap_getObjectGroups(JSContext *cx, uint32_t argc, jsval const cocos2d::Vector& ret = cobj->getObjectGroups(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -60910,22 +63427,22 @@ bool js_cocos2dx_TMXTiledMap_getObjectGroups(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXTiledMap_initWithXML(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTiledMap* cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_initWithXML : Invalid Native Object"); if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXTiledMap_initWithXML : Error processing arguments"); bool ret = cobj->initWithXML(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60934,20 +63451,20 @@ bool js_cocos2dx_TMXTiledMap_initWithXML(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TMXTiledMap_initWithTMXFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTiledMap* cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_initWithTMXFile : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXTiledMap_initWithTMXFile : Error processing arguments"); bool ret = cobj->initWithTMXFile(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60956,7 +63473,8 @@ bool js_cocos2dx_TMXTiledMap_initWithTMXFile(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_TMXTiledMap_getTileSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTiledMap* cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_getTileSize : Invalid Native Object"); @@ -60964,7 +63482,7 @@ bool js_cocos2dx_TMXTiledMap_getTileSize(JSContext *cx, uint32_t argc, jsval *vp const cocos2d::Size& ret = cobj->getTileSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60973,7 +63491,8 @@ bool js_cocos2dx_TMXTiledMap_getTileSize(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TMXTiledMap_getMapSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTiledMap* cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_getMapSize : Invalid Native Object"); @@ -60981,7 +63500,7 @@ bool js_cocos2dx_TMXTiledMap_getMapSize(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Size& ret = cobj->getMapSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -60990,7 +63509,8 @@ bool js_cocos2dx_TMXTiledMap_getMapSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXTiledMap_getProperties(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTiledMap* cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_getProperties : Invalid Native Object"); @@ -60998,7 +63518,7 @@ bool js_cocos2dx_TMXTiledMap_getProperties(JSContext *cx, uint32_t argc, jsval * cocos2d::ValueMap& ret = cobj->getProperties(); jsval jsret = JSVAL_NULL; jsret = ccvaluemap_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -61007,25 +63527,25 @@ bool js_cocos2dx_TMXTiledMap_getProperties(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_TMXTiledMap_getPropertiesForGID(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::TMXTiledMap* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_getPropertiesForGID : Invalid Native Object"); do { if (argc == 2) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } cocos2d::Value** arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Value**)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -61034,7 +63554,7 @@ bool js_cocos2dx_TMXTiledMap_getPropertiesForGID(JSContext *cx, uint32_t argc, j bool ret = cobj->getPropertiesForGID(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -61042,12 +63562,12 @@ bool js_cocos2dx_TMXTiledMap_getPropertiesForGID(JSContext *cx, uint32_t argc, j do { if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } cocos2d::Value ret = cobj->getPropertiesForGID(arg0); jsval jsret = JSVAL_NULL; jsret = ccvalue_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -61057,18 +63577,18 @@ bool js_cocos2dx_TMXTiledMap_getPropertiesForGID(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_TMXTiledMap_setTileSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTiledMap* cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_setTileSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXTiledMap_setTileSize : Error processing arguments"); cobj->setTileSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -61077,18 +63597,18 @@ bool js_cocos2dx_TMXTiledMap_setTileSize(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TMXTiledMap_setProperties(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTiledMap* cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_setProperties : Invalid Native Object"); if (argc == 1) { cocos2d::ValueMap arg0; - ok &= jsval_to_ccvaluemap(cx, argv[0], &arg0); + ok &= jsval_to_ccvaluemap(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXTiledMap_setProperties : Error processing arguments"); cobj->setProperties(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -61097,15 +63617,15 @@ bool js_cocos2dx_TMXTiledMap_setProperties(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_TMXTiledMap_getLayer(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTiledMap* cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_getLayer : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXTiledMap_getLayer : Error processing arguments"); cocos2d::TMXLayer* ret = cobj->getLayer(arg0); jsval jsret = JSVAL_NULL; @@ -61117,7 +63637,7 @@ bool js_cocos2dx_TMXTiledMap_getLayer(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -61126,7 +63646,8 @@ bool js_cocos2dx_TMXTiledMap_getLayer(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TMXTiledMap_getMapOrientation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTiledMap* cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_getMapOrientation : Invalid Native Object"); @@ -61134,7 +63655,7 @@ bool js_cocos2dx_TMXTiledMap_getMapOrientation(JSContext *cx, uint32_t argc, jsv int ret = cobj->getMapOrientation(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -61143,18 +63664,18 @@ bool js_cocos2dx_TMXTiledMap_getMapOrientation(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_TMXTiledMap_setMapOrientation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXTiledMap* cobj = (cocos2d::TMXTiledMap *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TMXTiledMap_setMapOrientation : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXTiledMap_setMapOrientation : Error processing arguments"); cobj->setMapOrientation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -61163,11 +63684,11 @@ bool js_cocos2dx_TMXTiledMap_setMapOrientation(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_TMXTiledMap_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXTiledMap_create : Error processing arguments"); cocos2d::TMXTiledMap* ret = cocos2d::TMXTiledMap::create(arg0); jsval jsret = JSVAL_NULL; @@ -61179,7 +63700,7 @@ bool js_cocos2dx_TMXTiledMap_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TMXTiledMap_create : wrong number of arguments"); @@ -61188,13 +63709,13 @@ bool js_cocos2dx_TMXTiledMap_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_TMXTiledMap_createWithXML(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TMXTiledMap_createWithXML : Error processing arguments"); cocos2d::TMXTiledMap* ret = cocos2d::TMXTiledMap::createWithXML(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -61206,7 +63727,7 @@ bool js_cocos2dx_TMXTiledMap_createWithXML(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TMXTiledMap_createWithXML : wrong number of arguments"); @@ -61215,7 +63736,7 @@ bool js_cocos2dx_TMXTiledMap_createWithXML(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_TMXTiledMap_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TMXTiledMap* cobj = new (std::nothrow) cocos2d::TMXTiledMap(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -61229,13 +63750,16 @@ bool js_cocos2dx_TMXTiledMap_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXTiledMap"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXTiledMap"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -61248,21 +63772,21 @@ void js_cocos2d_TMXTiledMap_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_TMXTiledMap_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::TMXTiledMap *nobj = new (std::nothrow) cocos2d::TMXTiledMap(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXTiledMap"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TMXTiledMap"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_TMXTiledMap(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TMXTiledMap(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TMXTiledMap_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TMXTiledMap_class->name = "TMXTiledMap"; jsb_cocos2d_TMXTiledMap_class->addProperty = JS_PropertyStub; @@ -61276,8 +63800,8 @@ void js_register_cocos2dx_TMXTiledMap(JSContext *cx, JSObject *global) { jsb_cocos2d_TMXTiledMap_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -61309,7 +63833,7 @@ void js_register_cocos2dx_TMXTiledMap(JSContext *cx, JSObject *global) { jsb_cocos2d_TMXTiledMap_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_TMXTiledMap_class, js_cocos2dx_TMXTiledMap_constructor, 0, // constructor properties, @@ -61340,9 +63864,9 @@ JSObject *jsb_cocos2d_TileMapAtlas_prototype; bool js_cocos2dx_TileMapAtlas_initWithTileFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TileMapAtlas* cobj = (cocos2d::TileMapAtlas *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TileMapAtlas_initWithTileFile : Invalid Native Object"); @@ -61351,15 +63875,15 @@ bool js_cocos2dx_TileMapAtlas_initWithTileFile(JSContext *cx, uint32_t argc, jsv std::string arg1; int arg2; int arg3; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TileMapAtlas_initWithTileFile : Error processing arguments"); bool ret = cobj->initWithTileFile(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -61368,13 +63892,14 @@ bool js_cocos2dx_TileMapAtlas_initWithTileFile(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_TileMapAtlas_releaseMap(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TileMapAtlas* cobj = (cocos2d::TileMapAtlas *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TileMapAtlas_releaseMap : Invalid Native Object"); if (argc == 0) { cobj->releaseMap(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -61383,7 +63908,8 @@ bool js_cocos2dx_TileMapAtlas_releaseMap(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TileMapAtlas_getTGAInfo(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TileMapAtlas* cobj = (cocos2d::TileMapAtlas *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TileMapAtlas_getTGAInfo : Invalid Native Object"); @@ -61391,7 +63917,7 @@ bool js_cocos2dx_TileMapAtlas_getTGAInfo(JSContext *cx, uint32_t argc, jsval *vp cocos2d::sImageTGA* ret = cobj->getTGAInfo(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR sImageTGA*; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -61400,20 +63926,20 @@ bool js_cocos2dx_TileMapAtlas_getTGAInfo(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TileMapAtlas_getTileAt(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TileMapAtlas* cobj = (cocos2d::TileMapAtlas *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TileMapAtlas_getTileAt : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TileMapAtlas_getTileAt : Error processing arguments"); cocos2d::Color3B ret = cobj->getTileAt(arg0); jsval jsret = JSVAL_NULL; jsret = cccolor3b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -61422,20 +63948,20 @@ bool js_cocos2dx_TileMapAtlas_getTileAt(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TileMapAtlas_setTile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TileMapAtlas* cobj = (cocos2d::TileMapAtlas *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TileMapAtlas_setTile : Invalid Native Object"); if (argc == 2) { cocos2d::Color3B arg0; cocos2d::Vec2 arg1; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TileMapAtlas_setTile : Error processing arguments"); cobj->setTile(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -61444,9 +63970,9 @@ bool js_cocos2dx_TileMapAtlas_setTile(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_TileMapAtlas_setTGAInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TileMapAtlas* cobj = (cocos2d::TileMapAtlas *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_TileMapAtlas_setTGAInfo : Invalid Native Object"); @@ -61456,7 +63982,7 @@ bool js_cocos2dx_TileMapAtlas_setTGAInfo(JSContext *cx, uint32_t argc, jsval *vp ok = false; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TileMapAtlas_setTGAInfo : Error processing arguments"); cobj->setTGAInfo(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -61465,17 +63991,17 @@ bool js_cocos2dx_TileMapAtlas_setTGAInfo(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_TileMapAtlas_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 4) { std::string arg0; std::string arg1; int arg2; int arg3; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_TileMapAtlas_create : Error processing arguments"); cocos2d::TileMapAtlas* ret = cocos2d::TileMapAtlas::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -61487,7 +64013,7 @@ bool js_cocos2dx_TileMapAtlas_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_TileMapAtlas_create : wrong number of arguments"); @@ -61496,7 +64022,7 @@ bool js_cocos2dx_TileMapAtlas_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_TileMapAtlas_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::TileMapAtlas* cobj = new (std::nothrow) cocos2d::TileMapAtlas(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -61510,13 +64036,16 @@ bool js_cocos2dx_TileMapAtlas_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TileMapAtlas"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TileMapAtlas"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -61529,21 +64058,21 @@ void js_cocos2d_TileMapAtlas_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_TileMapAtlas_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::TileMapAtlas *nobj = new (std::nothrow) cocos2d::TileMapAtlas(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::TileMapAtlas"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::TileMapAtlas"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_TileMapAtlas(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_TileMapAtlas(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_TileMapAtlas_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_TileMapAtlas_class->name = "TileMapAtlas"; jsb_cocos2d_TileMapAtlas_class->addProperty = JS_PropertyStub; @@ -61557,8 +64086,8 @@ void js_register_cocos2dx_TileMapAtlas(JSContext *cx, JSObject *global) { jsb_cocos2d_TileMapAtlas_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -61579,7 +64108,7 @@ void js_register_cocos2dx_TileMapAtlas(JSContext *cx, JSObject *global) { jsb_cocos2d_TileMapAtlas_prototype = JS_InitClass( cx, global, - jsb_cocos2d_AtlasNode_prototype, + JS::RootedObject(cx, jsb_cocos2d_AtlasNode_prototype), jsb_cocos2d_TileMapAtlas_class, js_cocos2dx_TileMapAtlas_constructor, 0, // constructor properties, @@ -61610,18 +64139,18 @@ JSObject *jsb_cocos2d_Component_prototype; bool js_cocos2dx_Component_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Component* cobj = (cocos2d::Component *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Component_setEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Component_setEnabled : Error processing arguments"); cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -61630,18 +64159,18 @@ bool js_cocos2dx_Component_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Component_setName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Component* cobj = (cocos2d::Component *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Component_setName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Component_setName : Error processing arguments"); cobj->setName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -61650,7 +64179,8 @@ bool js_cocos2dx_Component_setName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Component_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Component* cobj = (cocos2d::Component *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Component_isEnabled : Invalid Native Object"); @@ -61658,7 +64188,7 @@ bool js_cocos2dx_Component_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -61667,18 +64197,18 @@ bool js_cocos2dx_Component_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Component_update(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Component* cobj = (cocos2d::Component *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Component_update : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Component_update : Error processing arguments"); cobj->update(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -61687,7 +64217,8 @@ bool js_cocos2dx_Component_update(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Component_getOwner(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Component* cobj = (cocos2d::Component *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Component_getOwner : Invalid Native Object"); @@ -61702,7 +64233,7 @@ bool js_cocos2dx_Component_getOwner(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -61711,7 +64242,8 @@ bool js_cocos2dx_Component_getOwner(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Component_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Component* cobj = (cocos2d::Component *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Component_init : Invalid Native Object"); @@ -61719,7 +64251,7 @@ bool js_cocos2dx_Component_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -61728,25 +64260,25 @@ bool js_cocos2dx_Component_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Component_setOwner(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Component* cobj = (cocos2d::Component *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Component_setOwner : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Component_setOwner : Error processing arguments"); cobj->setOwner(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -61755,7 +64287,8 @@ bool js_cocos2dx_Component_setOwner(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Component_getName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Component* cobj = (cocos2d::Component *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Component_getName : Invalid Native Object"); @@ -61763,7 +64296,7 @@ bool js_cocos2dx_Component_getName(JSContext *cx, uint32_t argc, jsval *vp) const std::string& ret = cobj->getName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -61772,6 +64305,7 @@ bool js_cocos2dx_Component_getName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Component_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Component* ret = cocos2d::Component::create(); jsval jsret = JSVAL_NULL; @@ -61783,7 +64317,7 @@ bool js_cocos2dx_Component_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_Component_create : wrong number of arguments"); @@ -61792,7 +64326,7 @@ bool js_cocos2dx_Component_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Component_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::Component* cobj = new (std::nothrow) cocos2d::Component(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -61806,13 +64340,16 @@ bool js_cocos2dx_Component_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Component"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Component"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -61824,21 +64361,21 @@ void js_cocos2d_Component_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_Component_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::Component *nobj = new (std::nothrow) cocos2d::Component(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Component"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Component"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_Component(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_Component(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_Component_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_Component_class->name = "Component"; jsb_cocos2d_Component_class->addProperty = JS_PropertyStub; @@ -61852,8 +64389,8 @@ void js_register_cocos2dx_Component(JSContext *cx, JSObject *global) { jsb_cocos2d_Component_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -61876,7 +64413,7 @@ void js_register_cocos2dx_Component(JSContext *cx, JSObject *global) { jsb_cocos2d_Component_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_Component_class, js_cocos2dx_Component_constructor, 0, // constructor properties, @@ -61907,18 +64444,18 @@ JSObject *jsb_cocos2d_ComponentContainer_prototype; bool js_cocos2dx_ComponentContainer_visit(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ComponentContainer* cobj = (cocos2d::ComponentContainer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ComponentContainer_visit : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ComponentContainer_visit : Error processing arguments"); cobj->visit(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -61927,12 +64464,12 @@ bool js_cocos2dx_ComponentContainer_visit(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ComponentContainer_remove(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::ComponentContainer* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::ComponentContainer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ComponentContainer_remove : Invalid Native Object"); @@ -61940,9 +64477,9 @@ bool js_cocos2dx_ComponentContainer_remove(JSContext *cx, uint32_t argc, jsval * if (argc == 1) { cocos2d::Component* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Component*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -61951,7 +64488,7 @@ bool js_cocos2dx_ComponentContainer_remove(JSContext *cx, uint32_t argc, jsval * bool ret = cobj->remove(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -61959,12 +64496,12 @@ bool js_cocos2dx_ComponentContainer_remove(JSContext *cx, uint32_t argc, jsval * do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } bool ret = cobj->remove(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -61974,13 +64511,14 @@ bool js_cocos2dx_ComponentContainer_remove(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ComponentContainer_removeAll(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ComponentContainer* cobj = (cocos2d::ComponentContainer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ComponentContainer_removeAll : Invalid Native Object"); if (argc == 0) { cobj->removeAll(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -61989,18 +64527,18 @@ bool js_cocos2dx_ComponentContainer_removeAll(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ComponentContainer_add(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ComponentContainer* cobj = (cocos2d::ComponentContainer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ComponentContainer_add : Invalid Native Object"); if (argc == 1) { cocos2d::Component* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Component*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -62009,7 +64547,7 @@ bool js_cocos2dx_ComponentContainer_add(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->add(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -62018,7 +64556,8 @@ bool js_cocos2dx_ComponentContainer_add(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ComponentContainer_isEmpty(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ComponentContainer* cobj = (cocos2d::ComponentContainer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ComponentContainer_isEmpty : Invalid Native Object"); @@ -62026,7 +64565,7 @@ bool js_cocos2dx_ComponentContainer_isEmpty(JSContext *cx, uint32_t argc, jsval bool ret = cobj->isEmpty(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -62035,15 +64574,15 @@ bool js_cocos2dx_ComponentContainer_isEmpty(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ComponentContainer_get(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ComponentContainer* cobj = (cocos2d::ComponentContainer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ComponentContainer_get : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ComponentContainer_get : Error processing arguments"); cocos2d::Component* ret = cobj->get(arg0); jsval jsret = JSVAL_NULL; @@ -62055,7 +64594,7 @@ bool js_cocos2dx_ComponentContainer_get(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -62068,7 +64607,7 @@ void js_cocos2d_ComponentContainer_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ComponentContainer)", obj); } -void js_register_cocos2dx_ComponentContainer(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ComponentContainer(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ComponentContainer_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ComponentContainer_class->name = "ComponentContainer"; jsb_cocos2d_ComponentContainer_class->addProperty = JS_PropertyStub; @@ -62082,8 +64621,8 @@ void js_register_cocos2dx_ComponentContainer(JSContext *cx, JSObject *global) { jsb_cocos2d_ComponentContainer_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -62100,7 +64639,7 @@ void js_register_cocos2dx_ComponentContainer(JSContext *cx, JSObject *global) { jsb_cocos2d_ComponentContainer_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_ComponentContainer_class, empty_constructor, 0, properties, @@ -62131,18 +64670,18 @@ JSObject *jsb_CocosDenshion_SimpleAudioEngine_prototype; bool js_cocos2dx_SimpleAudioEngine_preloadBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_preloadBackgroundMusic : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_preloadBackgroundMusic : Error processing arguments"); cobj->preloadBackgroundMusic(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62151,23 +64690,23 @@ bool js_cocos2dx_SimpleAudioEngine_preloadBackgroundMusic(JSContext *cx, uint32_ } bool js_cocos2dx_SimpleAudioEngine_stopBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_stopBackgroundMusic : Invalid Native Object"); if (argc == 0) { cobj->stopBackgroundMusic(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_stopBackgroundMusic : Error processing arguments"); cobj->stopBackgroundMusic(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62176,13 +64715,14 @@ bool js_cocos2dx_SimpleAudioEngine_stopBackgroundMusic(JSContext *cx, uint32_t a } bool js_cocos2dx_SimpleAudioEngine_stopAllEffects(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_stopAllEffects : Invalid Native Object"); if (argc == 0) { cobj->stopAllEffects(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62191,7 +64731,8 @@ bool js_cocos2dx_SimpleAudioEngine_stopAllEffects(JSContext *cx, uint32_t argc, } bool js_cocos2dx_SimpleAudioEngine_getBackgroundMusicVolume(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_getBackgroundMusicVolume : Invalid Native Object"); @@ -62199,7 +64740,7 @@ bool js_cocos2dx_SimpleAudioEngine_getBackgroundMusicVolume(JSContext *cx, uint3 double ret = cobj->getBackgroundMusicVolume(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -62208,13 +64749,14 @@ bool js_cocos2dx_SimpleAudioEngine_getBackgroundMusicVolume(JSContext *cx, uint3 } bool js_cocos2dx_SimpleAudioEngine_resumeBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_resumeBackgroundMusic : Invalid Native Object"); if (argc == 0) { cobj->resumeBackgroundMusic(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62223,18 +64765,18 @@ bool js_cocos2dx_SimpleAudioEngine_resumeBackgroundMusic(JSContext *cx, uint32_t } bool js_cocos2dx_SimpleAudioEngine_setBackgroundMusicVolume(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_setBackgroundMusicVolume : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_setBackgroundMusicVolume : Error processing arguments"); cobj->setBackgroundMusicVolume(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62243,18 +64785,18 @@ bool js_cocos2dx_SimpleAudioEngine_setBackgroundMusicVolume(JSContext *cx, uint3 } bool js_cocos2dx_SimpleAudioEngine_preloadEffect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_preloadEffect : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_preloadEffect : Error processing arguments"); cobj->preloadEffect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62263,7 +64805,8 @@ bool js_cocos2dx_SimpleAudioEngine_preloadEffect(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_SimpleAudioEngine_isBackgroundMusicPlaying(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_isBackgroundMusicPlaying : Invalid Native Object"); @@ -62271,7 +64814,7 @@ bool js_cocos2dx_SimpleAudioEngine_isBackgroundMusicPlaying(JSContext *cx, uint3 bool ret = cobj->isBackgroundMusicPlaying(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -62280,7 +64823,8 @@ bool js_cocos2dx_SimpleAudioEngine_isBackgroundMusicPlaying(JSContext *cx, uint3 } bool js_cocos2dx_SimpleAudioEngine_getEffectsVolume(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_getEffectsVolume : Invalid Native Object"); @@ -62288,7 +64832,7 @@ bool js_cocos2dx_SimpleAudioEngine_getEffectsVolume(JSContext *cx, uint32_t argc double ret = cobj->getEffectsVolume(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -62297,7 +64841,8 @@ bool js_cocos2dx_SimpleAudioEngine_getEffectsVolume(JSContext *cx, uint32_t argc } bool js_cocos2dx_SimpleAudioEngine_willPlayBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_willPlayBackgroundMusic : Invalid Native Object"); @@ -62305,7 +64850,7 @@ bool js_cocos2dx_SimpleAudioEngine_willPlayBackgroundMusic(JSContext *cx, uint32 bool ret = cobj->willPlayBackgroundMusic(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -62314,18 +64859,18 @@ bool js_cocos2dx_SimpleAudioEngine_willPlayBackgroundMusic(JSContext *cx, uint32 } bool js_cocos2dx_SimpleAudioEngine_pauseEffect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_pauseEffect : Invalid Native Object"); if (argc == 1) { unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_pauseEffect : Error processing arguments"); cobj->pauseEffect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62334,46 +64879,46 @@ bool js_cocos2dx_SimpleAudioEngine_pauseEffect(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_SimpleAudioEngine_playEffect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_playEffect : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_playEffect : Error processing arguments"); unsigned int ret = cobj->playEffect(arg0); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { const char* arg0; bool arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_playEffect : Error processing arguments"); unsigned int ret = cobj->playEffect(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 3) { const char* arg0; bool arg1; double arg2; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + arg1 = JS::ToBoolean(args.get(1)); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_playEffect : Error processing arguments"); unsigned int ret = cobj->playEffect(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 4) { @@ -62381,15 +64926,15 @@ bool js_cocos2dx_SimpleAudioEngine_playEffect(JSContext *cx, uint32_t argc, jsva bool arg1; double arg2; double arg3; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + arg1 = JS::ToBoolean(args.get(1)); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_playEffect : Error processing arguments"); unsigned int ret = cobj->playEffect(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 5) { @@ -62398,16 +64943,16 @@ bool js_cocos2dx_SimpleAudioEngine_playEffect(JSContext *cx, uint32_t argc, jsva double arg2; double arg3; double arg4; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &arg3); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[4]), &arg4); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + arg1 = JS::ToBoolean(args.get(1)); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); + ok &= JS::ToNumber( cx, args.get(4), &arg4) && !isnan(arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_playEffect : Error processing arguments"); unsigned int ret = cobj->playEffect(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -62416,13 +64961,14 @@ bool js_cocos2dx_SimpleAudioEngine_playEffect(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_SimpleAudioEngine_rewindBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_rewindBackgroundMusic : Invalid Native Object"); if (argc == 0) { cobj->rewindBackgroundMusic(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62431,28 +64977,28 @@ bool js_cocos2dx_SimpleAudioEngine_rewindBackgroundMusic(JSContext *cx, uint32_t } bool js_cocos2dx_SimpleAudioEngine_playBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_playBackgroundMusic : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_playBackgroundMusic : Error processing arguments"); cobj->playBackgroundMusic(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { const char* arg0; bool arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_playBackgroundMusic : Error processing arguments"); cobj->playBackgroundMusic(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62461,13 +65007,14 @@ bool js_cocos2dx_SimpleAudioEngine_playBackgroundMusic(JSContext *cx, uint32_t a } bool js_cocos2dx_SimpleAudioEngine_resumeAllEffects(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_resumeAllEffects : Invalid Native Object"); if (argc == 0) { cobj->resumeAllEffects(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62476,18 +65023,18 @@ bool js_cocos2dx_SimpleAudioEngine_resumeAllEffects(JSContext *cx, uint32_t argc } bool js_cocos2dx_SimpleAudioEngine_setEffectsVolume(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_setEffectsVolume : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_setEffectsVolume : Error processing arguments"); cobj->setEffectsVolume(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62496,18 +65043,18 @@ bool js_cocos2dx_SimpleAudioEngine_setEffectsVolume(JSContext *cx, uint32_t argc } bool js_cocos2dx_SimpleAudioEngine_stopEffect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_stopEffect : Invalid Native Object"); if (argc == 1) { unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_stopEffect : Error processing arguments"); cobj->stopEffect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62516,13 +65063,14 @@ bool js_cocos2dx_SimpleAudioEngine_stopEffect(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_SimpleAudioEngine_pauseBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_pauseBackgroundMusic : Invalid Native Object"); if (argc == 0) { cobj->pauseBackgroundMusic(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62531,13 +65079,14 @@ bool js_cocos2dx_SimpleAudioEngine_pauseBackgroundMusic(JSContext *cx, uint32_t } bool js_cocos2dx_SimpleAudioEngine_pauseAllEffects(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_pauseAllEffects : Invalid Native Object"); if (argc == 0) { cobj->pauseAllEffects(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62546,18 +65095,18 @@ bool js_cocos2dx_SimpleAudioEngine_pauseAllEffects(JSContext *cx, uint32_t argc, } bool js_cocos2dx_SimpleAudioEngine_unloadEffect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_unloadEffect : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_unloadEffect : Error processing arguments"); cobj->unloadEffect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62566,18 +65115,18 @@ bool js_cocos2dx_SimpleAudioEngine_unloadEffect(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_SimpleAudioEngine_resumeEffect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); CocosDenshion::SimpleAudioEngine* cobj = (CocosDenshion::SimpleAudioEngine *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SimpleAudioEngine_resumeEffect : Invalid Native Object"); if (argc == 1) { unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_SimpleAudioEngine_resumeEffect : Error processing arguments"); cobj->resumeEffect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -62586,9 +65135,10 @@ bool js_cocos2dx_SimpleAudioEngine_resumeEffect(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_SimpleAudioEngine_end(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { CocosDenshion::SimpleAudioEngine::end(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_SimpleAudioEngine_end : wrong number of arguments"); @@ -62597,6 +65147,7 @@ bool js_cocos2dx_SimpleAudioEngine_end(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_SimpleAudioEngine_getInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { CocosDenshion::SimpleAudioEngine* ret = CocosDenshion::SimpleAudioEngine::getInstance(); jsval jsret = JSVAL_NULL; @@ -62608,7 +65159,7 @@ bool js_cocos2dx_SimpleAudioEngine_getInstance(JSContext *cx, uint32_t argc, jsv jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_SimpleAudioEngine_getInstance : wrong number of arguments"); @@ -62621,7 +65172,7 @@ void js_CocosDenshion_SimpleAudioEngine_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (SimpleAudioEngine)", obj); } -void js_register_cocos2dx_SimpleAudioEngine(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_SimpleAudioEngine(JSContext *cx, JS::HandleObject global) { jsb_CocosDenshion_SimpleAudioEngine_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_CocosDenshion_SimpleAudioEngine_class->name = "AudioEngine"; jsb_CocosDenshion_SimpleAudioEngine_class->addProperty = JS_PropertyStub; @@ -62635,8 +65186,8 @@ void js_register_cocos2dx_SimpleAudioEngine(JSContext *cx, JSObject *global) { jsb_CocosDenshion_SimpleAudioEngine_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -62672,7 +65223,7 @@ void js_register_cocos2dx_SimpleAudioEngine(JSContext *cx, JSObject *global) { jsb_CocosDenshion_SimpleAudioEngine_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_CocosDenshion_SimpleAudioEngine_class, empty_constructor, 0, properties, @@ -62698,267 +65249,383 @@ void js_register_cocos2dx_SimpleAudioEngine(JSContext *cx, JSObject *global) { } } -void register_all_cocos2dx(JSContext* cx, JSObject* obj) { - // first, try to get the ns - JS::RootedValue nsval(cx); +JSClass *jsb_cocos2d_AsyncTaskPool_class; +JSObject *jsb_cocos2d_AsyncTaskPool_prototype; + +bool js_cocos2dx_AsyncTaskPool_stopTasks(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::AsyncTaskPool* cobj = (cocos2d::AsyncTaskPool *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_AsyncTaskPool_stopTasks : Invalid Native Object"); + if (argc == 1) { + cocos2d::AsyncTaskPool::TaskType arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AsyncTaskPool_stopTasks : Error processing arguments"); + cobj->stopTasks(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_AsyncTaskPool_stopTasks : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_AsyncTaskPool_destoryInstance(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (argc == 0) { + cocos2d::AsyncTaskPool::destoryInstance(); + args.rval().setUndefined(); + return true; + } + JS_ReportError(cx, "js_cocos2dx_AsyncTaskPool_destoryInstance : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_AsyncTaskPool_getInstance(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (argc == 0) { + cocos2d::AsyncTaskPool* ret = cocos2d::AsyncTaskPool::getInstance(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::AsyncTaskPool*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_AsyncTaskPool_getInstance : wrong number of arguments"); + return false; +} + + + +void js_cocos2d_AsyncTaskPool_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (AsyncTaskPool)", obj); +} + +void js_register_cocos2dx_AsyncTaskPool(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_AsyncTaskPool_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_AsyncTaskPool_class->name = "AsyncTaskPool"; + jsb_cocos2d_AsyncTaskPool_class->addProperty = JS_PropertyStub; + jsb_cocos2d_AsyncTaskPool_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_AsyncTaskPool_class->getProperty = JS_PropertyStub; + jsb_cocos2d_AsyncTaskPool_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_AsyncTaskPool_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_AsyncTaskPool_class->resolve = JS_ResolveStub; + jsb_cocos2d_AsyncTaskPool_class->convert = JS_ConvertStub; + jsb_cocos2d_AsyncTaskPool_class->finalize = js_cocos2d_AsyncTaskPool_finalize; + jsb_cocos2d_AsyncTaskPool_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("stopTasks", js_cocos2dx_AsyncTaskPool_stopTasks, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("destoryInstance", js_cocos2dx_AsyncTaskPool_destoryInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getInstance", js_cocos2dx_AsyncTaskPool_getInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_AsyncTaskPool_prototype = JS_InitClass( + cx, global, + JS::NullPtr(), // parent proto + jsb_cocos2d_AsyncTaskPool_class, + empty_constructor, 0, + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "AsyncTaskPool", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_AsyncTaskPool_class; + p->proto = jsb_cocos2d_AsyncTaskPool_prototype; + p->parentProto = NULL; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj) { + // Get the ns JS::RootedObject ns(cx); - JS_GetProperty(cx, obj, "cc", &nsval); - if (nsval == JSVAL_VOID) { - ns = JS_NewObject(cx, NULL, NULL, NULL); - nsval = OBJECT_TO_JSVAL(ns); - JS_SetProperty(cx, obj, "cc", nsval); - } else { - JS_ValueToObject(cx, nsval, &ns); - } - obj = ns; - - js_register_cocos2dx_Action(cx, obj); - js_register_cocos2dx_FiniteTimeAction(cx, obj); - js_register_cocos2dx_ActionInstant(cx, obj); - js_register_cocos2dx_Hide(cx, obj); - js_register_cocos2dx_Node(cx, obj); - js_register_cocos2dx_Scene(cx, obj); - js_register_cocos2dx_TransitionScene(cx, obj); - js_register_cocos2dx_TransitionEaseScene(cx, obj); - js_register_cocos2dx_TransitionMoveInL(cx, obj); - js_register_cocos2dx_TransitionMoveInB(cx, obj); - js_register_cocos2dx_Layer(cx, obj); - js_register_cocos2dx___LayerRGBA(cx, obj); - js_register_cocos2dx_AtlasNode(cx, obj); - js_register_cocos2dx_TileMapAtlas(cx, obj); - js_register_cocos2dx_TransitionMoveInT(cx, obj); - js_register_cocos2dx_TMXTilesetInfo(cx, obj); - js_register_cocos2dx_TransitionMoveInR(cx, obj); - js_register_cocos2dx_ParticleSystem(cx, obj); - js_register_cocos2dx_ParticleSystemQuad(cx, obj); - js_register_cocos2dx_ParticleSpiral(cx, obj); - js_register_cocos2dx_GridBase(cx, obj); - js_register_cocos2dx_AnimationCache(cx, obj); - js_register_cocos2dx_ActionInterval(cx, obj); - js_register_cocos2dx_ActionCamera(cx, obj); - js_register_cocos2dx_ProgressFromTo(cx, obj); - js_register_cocos2dx_MoveBy(cx, obj); - js_register_cocos2dx_MoveTo(cx, obj); - js_register_cocos2dx_JumpBy(cx, obj); - js_register_cocos2dx_EventListener(cx, obj); - js_register_cocos2dx_EventListenerKeyboard(cx, obj); - js_register_cocos2dx_EventListenerMouse(cx, obj); - js_register_cocos2dx_TransitionRotoZoom(cx, obj); - js_register_cocos2dx_Director(cx, obj); - js_register_cocos2dx_Scheduler(cx, obj); - js_register_cocos2dx_ActionEase(cx, obj); - js_register_cocos2dx_EaseElastic(cx, obj); - js_register_cocos2dx_EaseElasticOut(cx, obj); - js_register_cocos2dx_EaseQuadraticActionInOut(cx, obj); - js_register_cocos2dx_EaseBackOut(cx, obj); - js_register_cocos2dx_Texture2D(cx, obj); - js_register_cocos2dx_TransitionSceneOriented(cx, obj); - js_register_cocos2dx_TransitionFlipX(cx, obj); - js_register_cocos2dx_GridAction(cx, obj); - js_register_cocos2dx_TiledGrid3DAction(cx, obj); - js_register_cocos2dx_FadeOutTRTiles(cx, obj); - js_register_cocos2dx_FadeOutUpTiles(cx, obj); - js_register_cocos2dx_FadeOutDownTiles(cx, obj); - js_register_cocos2dx_StopGrid(cx, obj); - js_register_cocos2dx_SimpleAudioEngine(cx, obj); - js_register_cocos2dx_SkewTo(cx, obj); - js_register_cocos2dx_SkewBy(cx, obj); - js_register_cocos2dx_EaseQuadraticActionOut(cx, obj); - js_register_cocos2dx_TransitionProgress(cx, obj); - js_register_cocos2dx_TransitionProgressVertical(cx, obj); - js_register_cocos2dx_ComponentContainer(cx, obj); - js_register_cocos2dx_TMXTiledMap(cx, obj); - js_register_cocos2dx_Grid3DAction(cx, obj); - js_register_cocos2dx_FadeTo(cx, obj); - js_register_cocos2dx_FadeIn(cx, obj); - js_register_cocos2dx_GLProgramState(cx, obj); - js_register_cocos2dx_EventListenerCustom(cx, obj); - js_register_cocos2dx_FlipX3D(cx, obj); - js_register_cocos2dx_FlipY3D(cx, obj); - js_register_cocos2dx_EaseSineInOut(cx, obj); - js_register_cocos2dx_TransitionFlipAngular(cx, obj); - js_register_cocos2dx_EaseElasticInOut(cx, obj); - js_register_cocos2dx_EaseBounce(cx, obj); - js_register_cocos2dx_Show(cx, obj); - js_register_cocos2dx_FadeOut(cx, obj); - js_register_cocos2dx_CallFunc(cx, obj); - js_register_cocos2dx_Event(cx, obj); - js_register_cocos2dx_EventMouse(cx, obj); - js_register_cocos2dx_GLView(cx, obj); - js_register_cocos2dx_EaseBezierAction(cx, obj); - js_register_cocos2dx_ParticleFireworks(cx, obj); - js_register_cocos2dx_MenuItem(cx, obj); - js_register_cocos2dx_MenuItemSprite(cx, obj); - js_register_cocos2dx_MenuItemImage(cx, obj); - js_register_cocos2dx_ParticleFire(cx, obj); - js_register_cocos2dx_ProgressTo(cx, obj); - js_register_cocos2dx_TransitionZoomFlipAngular(cx, obj); - js_register_cocos2dx_EaseRateAction(cx, obj); - js_register_cocos2dx_EaseIn(cx, obj); - js_register_cocos2dx_EaseExponentialInOut(cx, obj); - js_register_cocos2dx_EaseBackInOut(cx, obj); - js_register_cocos2dx_Waves3D(cx, obj); - js_register_cocos2dx_EaseExponentialOut(cx, obj); - js_register_cocos2dx_SpriteBatchNode(cx, obj); - js_register_cocos2dx_Label(cx, obj); - js_register_cocos2dx_Application(cx, obj); - js_register_cocos2dx_DelayTime(cx, obj); - js_register_cocos2dx_LabelAtlas(cx, obj); - js_register_cocos2dx_LabelBMFont(cx, obj); - js_register_cocos2dx_ParticleSnow(cx, obj); - js_register_cocos2dx_EaseElasticIn(cx, obj); - js_register_cocos2dx_EaseCircleActionInOut(cx, obj); - js_register_cocos2dx_EaseQuarticActionOut(cx, obj); - js_register_cocos2dx_EventAcceleration(cx, obj); - js_register_cocos2dx_EaseCubicActionIn(cx, obj); - js_register_cocos2dx_TextureCache(cx, obj); - js_register_cocos2dx_Configuration(cx, obj); - js_register_cocos2dx_ActionTween(cx, obj); - js_register_cocos2dx_TransitionFadeTR(cx, obj); - js_register_cocos2dx_TransitionFadeDown(cx, obj); - js_register_cocos2dx_ParticleSun(cx, obj); - js_register_cocos2dx_TransitionProgressHorizontal(cx, obj); - js_register_cocos2dx_TMXObjectGroup(cx, obj); - js_register_cocos2dx_TMXLayer(cx, obj); - js_register_cocos2dx_FlipX(cx, obj); - js_register_cocos2dx_FlipY(cx, obj); - js_register_cocos2dx_EventKeyboard(cx, obj); - js_register_cocos2dx_TransitionSplitCols(cx, obj); - js_register_cocos2dx_RepeatForever(cx, obj); - js_register_cocos2dx_Place(cx, obj); - js_register_cocos2dx_EventListenerAcceleration(cx, obj); - js_register_cocos2dx_TiledGrid3D(cx, obj); - js_register_cocos2dx_EaseBounceOut(cx, obj); - js_register_cocos2dx_RenderTexture(cx, obj); - js_register_cocos2dx_TintBy(cx, obj); - js_register_cocos2dx_TransitionShrinkGrow(cx, obj); - js_register_cocos2dx_LabelTTF(cx, obj); - js_register_cocos2dx_ClippingNode(cx, obj); - js_register_cocos2dx_ParticleFlower(cx, obj); - js_register_cocos2dx_EaseCircleActionIn(cx, obj); - js_register_cocos2dx_ParticleSmoke(cx, obj); - js_register_cocos2dx_LayerMultiplex(cx, obj); - js_register_cocos2dx_Blink(cx, obj); - js_register_cocos2dx_JumpTo(cx, obj); - js_register_cocos2dx_ParticleExplosion(cx, obj); - js_register_cocos2dx_TransitionJumpZoom(cx, obj); - js_register_cocos2dx_Touch(cx, obj); - js_register_cocos2dx_SAXParser(cx, obj); - js_register_cocos2dx_AnimationFrame(cx, obj); - js_register_cocos2dx_NodeGrid(cx, obj); - js_register_cocos2dx_TMXLayerInfo(cx, obj); - js_register_cocos2dx_EaseSineIn(cx, obj); - js_register_cocos2dx_EaseBounceIn(cx, obj); - js_register_cocos2dx_Camera(cx, obj); - js_register_cocos2dx_GLProgram(cx, obj); - js_register_cocos2dx_ParticleGalaxy(cx, obj); - js_register_cocos2dx_Twirl(cx, obj); - js_register_cocos2dx_MenuItemLabel(cx, obj); - js_register_cocos2dx_EaseQuinticActionIn(cx, obj); - js_register_cocos2dx_LayerColor(cx, obj); - js_register_cocos2dx_FadeOutBLTiles(cx, obj); - js_register_cocos2dx_LayerGradient(cx, obj); - js_register_cocos2dx_EventListenerTouchAllAtOnce(cx, obj); - js_register_cocos2dx_ToggleVisibility(cx, obj); - js_register_cocos2dx_Repeat(cx, obj); - js_register_cocos2dx_CardinalSplineTo(cx, obj); - js_register_cocos2dx_CardinalSplineBy(cx, obj); - js_register_cocos2dx_TransitionFlipY(cx, obj); - js_register_cocos2dx_TurnOffTiles(cx, obj); - js_register_cocos2dx_TintTo(cx, obj); - js_register_cocos2dx_CatmullRomTo(cx, obj); - js_register_cocos2dx_TransitionFadeBL(cx, obj); - js_register_cocos2dx_TargetedAction(cx, obj); - js_register_cocos2dx_DrawNode(cx, obj); - js_register_cocos2dx_TransitionTurnOffTiles(cx, obj); - js_register_cocos2dx_RotateTo(cx, obj); - js_register_cocos2dx_TransitionSplitRows(cx, obj); - js_register_cocos2dx_Device(cx, obj); - js_register_cocos2dx_TransitionProgressRadialCCW(cx, obj); - js_register_cocos2dx_EventListenerFocus(cx, obj); - js_register_cocos2dx_TransitionPageTurn(cx, obj); - js_register_cocos2dx_BezierBy(cx, obj); - js_register_cocos2dx_BezierTo(cx, obj); - js_register_cocos2dx_Menu(cx, obj); - js_register_cocos2dx_SpriteFrame(cx, obj); - js_register_cocos2dx_ActionManager(cx, obj); - js_register_cocos2dx_TransitionFade(cx, obj); - js_register_cocos2dx_TransitionZoomFlipX(cx, obj); - js_register_cocos2dx_EventFocus(cx, obj); - js_register_cocos2dx_EaseQuinticActionInOut(cx, obj); - js_register_cocos2dx_SpriteFrameCache(cx, obj); - js_register_cocos2dx_TransitionCrossFade(cx, obj); - js_register_cocos2dx_Ripple3D(cx, obj); - js_register_cocos2dx_Lens3D(cx, obj); - js_register_cocos2dx_ScaleTo(cx, obj); - js_register_cocos2dx_Spawn(cx, obj); - js_register_cocos2dx_EaseQuarticActionInOut(cx, obj); - js_register_cocos2dx_ShakyTiles3D(cx, obj); - js_register_cocos2dx_PageTurn3D(cx, obj); - js_register_cocos2dx_TransitionSlideInL(cx, obj); - js_register_cocos2dx_TransitionSlideInT(cx, obj); - js_register_cocos2dx_Grid3D(cx, obj); - js_register_cocos2dx_EaseCircleActionOut(cx, obj); - js_register_cocos2dx_TransitionProgressInOut(cx, obj); - js_register_cocos2dx_EaseCubicActionInOut(cx, obj); - js_register_cocos2dx_EaseBackIn(cx, obj); - js_register_cocos2dx_SplitRows(cx, obj); - js_register_cocos2dx_Follow(cx, obj); - js_register_cocos2dx_Animate(cx, obj); - js_register_cocos2dx_ShuffleTiles(cx, obj); - js_register_cocos2dx_ReverseTime(cx, obj); - js_register_cocos2dx_ProgressTimer(cx, obj); - js_register_cocos2dx_ParticleMeteor(cx, obj); - js_register_cocos2dx_EaseQuarticActionIn(cx, obj); - js_register_cocos2dx_EaseInOut(cx, obj); - js_register_cocos2dx_TransitionZoomFlipY(cx, obj); - js_register_cocos2dx_ScaleBy(cx, obj); - js_register_cocos2dx_EventTouch(cx, obj); - js_register_cocos2dx_Animation(cx, obj); - js_register_cocos2dx_TMXMapInfo(cx, obj); - js_register_cocos2dx_EaseExponentialIn(cx, obj); - js_register_cocos2dx_ReuseGrid(cx, obj); - js_register_cocos2dx_EaseQuinticActionOut(cx, obj); - js_register_cocos2dx_EventDispatcher(cx, obj); - js_register_cocos2dx_MenuItemAtlasFont(cx, obj); - js_register_cocos2dx_Liquid(cx, obj); - js_register_cocos2dx_OrbitCamera(cx, obj); - js_register_cocos2dx_ParallaxNode(cx, obj); - js_register_cocos2dx_ParticleBatchNode(cx, obj); - js_register_cocos2dx_Component(cx, obj); - js_register_cocos2dx_EaseCubicActionOut(cx, obj); - js_register_cocos2dx_EventListenerTouchOneByOne(cx, obj); - js_register_cocos2dx_TextFieldTTF(cx, obj); - js_register_cocos2dx_ParticleRain(cx, obj); - js_register_cocos2dx_Waves(cx, obj); - js_register_cocos2dx_EaseOut(cx, obj); - js_register_cocos2dx_MenuItemFont(cx, obj); - js_register_cocos2dx_TransitionFadeUp(cx, obj); - js_register_cocos2dx_EaseSineOut(cx, obj); - js_register_cocos2dx_JumpTiles3D(cx, obj); - js_register_cocos2dx_MenuItemToggle(cx, obj); - js_register_cocos2dx_RemoveSelf(cx, obj); - js_register_cocos2dx_SplitCols(cx, obj); - js_register_cocos2dx_ProtectedNode(cx, obj); - js_register_cocos2dx_MotionStreak(cx, obj); - js_register_cocos2dx_RotateBy(cx, obj); - js_register_cocos2dx_FileUtils(cx, obj); - js_register_cocos2dx_Sprite(cx, obj); - js_register_cocos2dx_CallFuncN(cx, obj); - js_register_cocos2dx_TransitionProgressOutIn(cx, obj); - js_register_cocos2dx_CatmullRomBy(cx, obj); - js_register_cocos2dx_Sequence(cx, obj); - js_register_cocos2dx_Shaky3D(cx, obj); - js_register_cocos2dx_TransitionProgressRadialCW(cx, obj); - js_register_cocos2dx_EaseBounceInOut(cx, obj); - js_register_cocos2dx_TransitionSlideInR(cx, obj); - js_register_cocos2dx___NodeRGBA(cx, obj); - js_register_cocos2dx_GLProgramCache(cx, obj); - js_register_cocos2dx_EaseQuadraticActionIn(cx, obj); - js_register_cocos2dx_WavesTiles3D(cx, obj); - js_register_cocos2dx_TransitionSlideInB(cx, obj); - js_register_cocos2dx_Speed(cx, obj); - js_register_cocos2dx_EventCustom(cx, obj); - js_register_cocos2dx_ShatteredTiles3D(cx, obj); + get_or_create_js_obj(cx, obj, "cc", &ns); + + js_register_cocos2dx_Action(cx, ns); + js_register_cocos2dx_FiniteTimeAction(cx, ns); + js_register_cocos2dx_ActionInstant(cx, ns); + js_register_cocos2dx_Hide(cx, ns); + js_register_cocos2dx_Node(cx, ns); + js_register_cocos2dx_Scene(cx, ns); + js_register_cocos2dx_TransitionScene(cx, ns); + js_register_cocos2dx_TransitionEaseScene(cx, ns); + js_register_cocos2dx_TransitionMoveInL(cx, ns); + js_register_cocos2dx_TransitionMoveInB(cx, ns); + js_register_cocos2dx_Layer(cx, ns); + js_register_cocos2dx___LayerRGBA(cx, ns); + js_register_cocos2dx_AtlasNode(cx, ns); + js_register_cocos2dx_TileMapAtlas(cx, ns); + js_register_cocos2dx_TransitionMoveInT(cx, ns); + js_register_cocos2dx_TMXTilesetInfo(cx, ns); + js_register_cocos2dx_TransitionMoveInR(cx, ns); + js_register_cocos2dx_ParticleSystem(cx, ns); + js_register_cocos2dx_ParticleSystemQuad(cx, ns); + js_register_cocos2dx_ParticleSpiral(cx, ns); + js_register_cocos2dx_GridBase(cx, ns); + js_register_cocos2dx_AnimationCache(cx, ns); + js_register_cocos2dx_ActionInterval(cx, ns); + js_register_cocos2dx_ActionCamera(cx, ns); + js_register_cocos2dx_ProgressFromTo(cx, ns); + js_register_cocos2dx_MoveBy(cx, ns); + js_register_cocos2dx_MoveTo(cx, ns); + js_register_cocos2dx_JumpBy(cx, ns); + js_register_cocos2dx_EventListener(cx, ns); + js_register_cocos2dx_EventListenerKeyboard(cx, ns); + js_register_cocos2dx_EventListenerMouse(cx, ns); + js_register_cocos2dx_TransitionRotoZoom(cx, ns); + js_register_cocos2dx_Director(cx, ns); + js_register_cocos2dx_Scheduler(cx, ns); + js_register_cocos2dx_ActionEase(cx, ns); + js_register_cocos2dx_EaseElastic(cx, ns); + js_register_cocos2dx_EaseElasticOut(cx, ns); + js_register_cocos2dx_EaseQuadraticActionInOut(cx, ns); + js_register_cocos2dx_EaseBackOut(cx, ns); + js_register_cocos2dx_Texture2D(cx, ns); + js_register_cocos2dx_TransitionSceneOriented(cx, ns); + js_register_cocos2dx_TransitionFlipX(cx, ns); + js_register_cocos2dx_GridAction(cx, ns); + js_register_cocos2dx_TiledGrid3DAction(cx, ns); + js_register_cocos2dx_FadeOutTRTiles(cx, ns); + js_register_cocos2dx_FadeOutUpTiles(cx, ns); + js_register_cocos2dx_FadeOutDownTiles(cx, ns); + js_register_cocos2dx_StopGrid(cx, ns); + js_register_cocos2dx_SimpleAudioEngine(cx, ns); + js_register_cocos2dx_SkewTo(cx, ns); + js_register_cocos2dx_SkewBy(cx, ns); + js_register_cocos2dx_EaseQuadraticActionOut(cx, ns); + js_register_cocos2dx_TransitionProgress(cx, ns); + js_register_cocos2dx_TransitionProgressVertical(cx, ns); + js_register_cocos2dx_ComponentContainer(cx, ns); + js_register_cocos2dx_TMXTiledMap(cx, ns); + js_register_cocos2dx_Grid3DAction(cx, ns); + js_register_cocos2dx_BaseLight(cx, ns); + js_register_cocos2dx_SpotLight(cx, ns); + js_register_cocos2dx_FadeTo(cx, ns); + js_register_cocos2dx_FadeIn(cx, ns); + js_register_cocos2dx_DirectionLight(cx, ns); + js_register_cocos2dx_GLProgramState(cx, ns); + js_register_cocos2dx_EventListenerCustom(cx, ns); + js_register_cocos2dx_FlipX3D(cx, ns); + js_register_cocos2dx_FlipY3D(cx, ns); + js_register_cocos2dx_EaseSineInOut(cx, ns); + js_register_cocos2dx_TransitionFlipAngular(cx, ns); + js_register_cocos2dx_EaseElasticInOut(cx, ns); + js_register_cocos2dx_EaseBounce(cx, ns); + js_register_cocos2dx_Show(cx, ns); + js_register_cocos2dx_FadeOut(cx, ns); + js_register_cocos2dx_CallFunc(cx, ns); + js_register_cocos2dx_Event(cx, ns); + js_register_cocos2dx_EventMouse(cx, ns); + js_register_cocos2dx_GLView(cx, ns); + js_register_cocos2dx_EaseRateAction(cx, ns); + js_register_cocos2dx_EaseOut(cx, ns); + js_register_cocos2dx_ParticleFireworks(cx, ns); + js_register_cocos2dx_MenuItem(cx, ns); + js_register_cocos2dx_MenuItemSprite(cx, ns); + js_register_cocos2dx_MenuItemImage(cx, ns); + js_register_cocos2dx_ParticleFire(cx, ns); + js_register_cocos2dx_ProgressTo(cx, ns); + js_register_cocos2dx_TransitionZoomFlipAngular(cx, ns); + js_register_cocos2dx_EaseIn(cx, ns); + js_register_cocos2dx_EaseExponentialInOut(cx, ns); + js_register_cocos2dx_EaseBackInOut(cx, ns); + js_register_cocos2dx_Waves3D(cx, ns); + js_register_cocos2dx_EaseExponentialOut(cx, ns); + js_register_cocos2dx_SpriteBatchNode(cx, ns); + js_register_cocos2dx_Label(cx, ns); + js_register_cocos2dx_Application(cx, ns); + js_register_cocos2dx_DelayTime(cx, ns); + js_register_cocos2dx_LabelAtlas(cx, ns); + js_register_cocos2dx_LabelBMFont(cx, ns); + js_register_cocos2dx_AsyncTaskPool(cx, ns); + js_register_cocos2dx_ParticleSnow(cx, ns); + js_register_cocos2dx_EaseElasticIn(cx, ns); + js_register_cocos2dx_EaseCircleActionInOut(cx, ns); + js_register_cocos2dx_EaseQuarticActionOut(cx, ns); + js_register_cocos2dx_EventAcceleration(cx, ns); + js_register_cocos2dx_EaseCubicActionIn(cx, ns); + js_register_cocos2dx_TextureCache(cx, ns); + js_register_cocos2dx_Configuration(cx, ns); + js_register_cocos2dx_ActionTween(cx, ns); + js_register_cocos2dx_TransitionFadeTR(cx, ns); + js_register_cocos2dx_TransitionFadeDown(cx, ns); + js_register_cocos2dx_ParticleSun(cx, ns); + js_register_cocos2dx_TransitionProgressHorizontal(cx, ns); + js_register_cocos2dx_TMXObjectGroup(cx, ns); + js_register_cocos2dx_TMXLayer(cx, ns); + js_register_cocos2dx_FlipX(cx, ns); + js_register_cocos2dx_FlipY(cx, ns); + js_register_cocos2dx_TransitionSplitCols(cx, ns); + js_register_cocos2dx_RepeatForever(cx, ns); + js_register_cocos2dx_Place(cx, ns); + js_register_cocos2dx_EventListenerAcceleration(cx, ns); + js_register_cocos2dx_TiledGrid3D(cx, ns); + js_register_cocos2dx_EaseBounceOut(cx, ns); + js_register_cocos2dx_RenderTexture(cx, ns); + js_register_cocos2dx_TintBy(cx, ns); + js_register_cocos2dx_TransitionShrinkGrow(cx, ns); + js_register_cocos2dx_LabelTTF(cx, ns); + js_register_cocos2dx_ClippingNode(cx, ns); + js_register_cocos2dx_ParticleFlower(cx, ns); + js_register_cocos2dx_EaseCircleActionIn(cx, ns); + js_register_cocos2dx_ParticleSmoke(cx, ns); + js_register_cocos2dx_Image(cx, ns); + js_register_cocos2dx_LayerMultiplex(cx, ns); + js_register_cocos2dx_Blink(cx, ns); + js_register_cocos2dx_JumpTo(cx, ns); + js_register_cocos2dx_ParticleExplosion(cx, ns); + js_register_cocos2dx_TransitionJumpZoom(cx, ns); + js_register_cocos2dx_Touch(cx, ns); + js_register_cocos2dx_SAXParser(cx, ns); + js_register_cocos2dx_AnimationFrame(cx, ns); + js_register_cocos2dx_NodeGrid(cx, ns); + js_register_cocos2dx_TMXLayerInfo(cx, ns); + js_register_cocos2dx_EaseSineIn(cx, ns); + js_register_cocos2dx_EaseBounceIn(cx, ns); + js_register_cocos2dx_Camera(cx, ns); + js_register_cocos2dx_GLProgram(cx, ns); + js_register_cocos2dx_ParticleGalaxy(cx, ns); + js_register_cocos2dx_Twirl(cx, ns); + js_register_cocos2dx_MenuItemLabel(cx, ns); + js_register_cocos2dx_EaseQuinticActionIn(cx, ns); + js_register_cocos2dx_LayerColor(cx, ns); + js_register_cocos2dx_FadeOutBLTiles(cx, ns); + js_register_cocos2dx_LayerGradient(cx, ns); + js_register_cocos2dx_EventListenerTouchAllAtOnce(cx, ns); + js_register_cocos2dx_ToggleVisibility(cx, ns); + js_register_cocos2dx_Repeat(cx, ns); + js_register_cocos2dx_CardinalSplineTo(cx, ns); + js_register_cocos2dx_CardinalSplineBy(cx, ns); + js_register_cocos2dx_TransitionFlipY(cx, ns); + js_register_cocos2dx_TurnOffTiles(cx, ns); + js_register_cocos2dx_TintTo(cx, ns); + js_register_cocos2dx_CatmullRomTo(cx, ns); + js_register_cocos2dx_TransitionFadeBL(cx, ns); + js_register_cocos2dx_TargetedAction(cx, ns); + js_register_cocos2dx_DrawNode(cx, ns); + js_register_cocos2dx_TransitionTurnOffTiles(cx, ns); + js_register_cocos2dx_RotateTo(cx, ns); + js_register_cocos2dx_TransitionSplitRows(cx, ns); + js_register_cocos2dx_Device(cx, ns); + js_register_cocos2dx_TransitionProgressRadialCCW(cx, ns); + js_register_cocos2dx_EventListenerFocus(cx, ns); + js_register_cocos2dx_TransitionPageTurn(cx, ns); + js_register_cocos2dx_BezierBy(cx, ns); + js_register_cocos2dx_BezierTo(cx, ns); + js_register_cocos2dx_Menu(cx, ns); + js_register_cocos2dx_SpriteFrame(cx, ns); + js_register_cocos2dx_ActionManager(cx, ns); + js_register_cocos2dx_TransitionFade(cx, ns); + js_register_cocos2dx_TransitionZoomFlipX(cx, ns); + js_register_cocos2dx_EventFocus(cx, ns); + js_register_cocos2dx_EaseQuinticActionInOut(cx, ns); + js_register_cocos2dx_SpriteFrameCache(cx, ns); + js_register_cocos2dx_PointLight(cx, ns); + js_register_cocos2dx_TransitionCrossFade(cx, ns); + js_register_cocos2dx_Ripple3D(cx, ns); + js_register_cocos2dx_Lens3D(cx, ns); + js_register_cocos2dx_ScaleTo(cx, ns); + js_register_cocos2dx_Spawn(cx, ns); + js_register_cocos2dx_EaseQuarticActionInOut(cx, ns); + js_register_cocos2dx_ShakyTiles3D(cx, ns); + js_register_cocos2dx_PageTurn3D(cx, ns); + js_register_cocos2dx_TransitionSlideInL(cx, ns); + js_register_cocos2dx_TransitionSlideInT(cx, ns); + js_register_cocos2dx_Grid3D(cx, ns); + js_register_cocos2dx_EaseCircleActionOut(cx, ns); + js_register_cocos2dx_TransitionProgressInOut(cx, ns); + js_register_cocos2dx_EaseCubicActionInOut(cx, ns); + js_register_cocos2dx_EaseBackIn(cx, ns); + js_register_cocos2dx_SplitRows(cx, ns); + js_register_cocos2dx_Follow(cx, ns); + js_register_cocos2dx_Animate(cx, ns); + js_register_cocos2dx_ShuffleTiles(cx, ns); + js_register_cocos2dx_ReverseTime(cx, ns); + js_register_cocos2dx_ProgressTimer(cx, ns); + js_register_cocos2dx_ParticleMeteor(cx, ns); + js_register_cocos2dx_EaseQuarticActionIn(cx, ns); + js_register_cocos2dx_EaseInOut(cx, ns); + js_register_cocos2dx_TransitionZoomFlipY(cx, ns); + js_register_cocos2dx_ScaleBy(cx, ns); + js_register_cocos2dx_EventTouch(cx, ns); + js_register_cocos2dx_Animation(cx, ns); + js_register_cocos2dx_TMXMapInfo(cx, ns); + js_register_cocos2dx_EaseExponentialIn(cx, ns); + js_register_cocos2dx_ReuseGrid(cx, ns); + js_register_cocos2dx_EaseQuinticActionOut(cx, ns); + js_register_cocos2dx_EventDispatcher(cx, ns); + js_register_cocos2dx_MenuItemAtlasFont(cx, ns); + js_register_cocos2dx_Liquid(cx, ns); + js_register_cocos2dx_OrbitCamera(cx, ns); + js_register_cocos2dx_ParallaxNode(cx, ns); + js_register_cocos2dx_ParticleBatchNode(cx, ns); + js_register_cocos2dx_Component(cx, ns); + js_register_cocos2dx_EaseCubicActionOut(cx, ns); + js_register_cocos2dx_EventListenerTouchOneByOne(cx, ns); + js_register_cocos2dx_TextFieldTTF(cx, ns); + js_register_cocos2dx_ParticleRain(cx, ns); + js_register_cocos2dx_Waves(cx, ns); + js_register_cocos2dx_EaseBezierAction(cx, ns); + js_register_cocos2dx_MenuItemFont(cx, ns); + js_register_cocos2dx_TransitionFadeUp(cx, ns); + js_register_cocos2dx_EaseSineOut(cx, ns); + js_register_cocos2dx_JumpTiles3D(cx, ns); + js_register_cocos2dx_MenuItemToggle(cx, ns); + js_register_cocos2dx_RemoveSelf(cx, ns); + js_register_cocos2dx_SplitCols(cx, ns); + js_register_cocos2dx_ProtectedNode(cx, ns); + js_register_cocos2dx_MotionStreak(cx, ns); + js_register_cocos2dx_RotateBy(cx, ns); + js_register_cocos2dx_FileUtils(cx, ns); + js_register_cocos2dx_Sprite(cx, ns); + js_register_cocos2dx_CallFuncN(cx, ns); + js_register_cocos2dx_TransitionProgressOutIn(cx, ns); + js_register_cocos2dx_CatmullRomBy(cx, ns); + js_register_cocos2dx_Sequence(cx, ns); + js_register_cocos2dx_Shaky3D(cx, ns); + js_register_cocos2dx_TransitionProgressRadialCW(cx, ns); + js_register_cocos2dx_EaseBounceInOut(cx, ns); + js_register_cocos2dx_TransitionSlideInR(cx, ns); + js_register_cocos2dx___NodeRGBA(cx, ns); + js_register_cocos2dx_AmbientLight(cx, ns); + js_register_cocos2dx_GLProgramCache(cx, ns); + js_register_cocos2dx_EaseQuadraticActionIn(cx, ns); + js_register_cocos2dx_WavesTiles3D(cx, ns); + js_register_cocos2dx_TransitionSlideInB(cx, ns); + js_register_cocos2dx_Speed(cx, ns); + js_register_cocos2dx_EventCustom(cx, ns); + js_register_cocos2dx_ShatteredTiles3D(cx, ns); } diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.hpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.hpp index cff62c093f..9188203e7f 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.hpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.hpp @@ -10,8 +10,8 @@ extern JSObject *jsb_cocos2d_Configuration_prototype; bool js_cocos2dx_Configuration_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Configuration_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Configuration(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Configuration(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Configuration_checkForGLExtension(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Configuration_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Configuration_supportsS3TC(JSContext *cx, uint32_t argc, jsval *vp); @@ -41,8 +41,8 @@ extern JSObject *jsb_cocos2d_Texture2D_prototype; bool js_cocos2dx_Texture2D_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Texture2D_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Texture2D(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Texture2D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Texture2D_getGLProgram(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Texture2D_getMaxT(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Texture2D_getStringForFormat(JSContext *cx, uint32_t argc, jsval *vp); @@ -78,8 +78,8 @@ extern JSObject *jsb_cocos2d_Touch_prototype; bool js_cocos2dx_Touch_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Touch_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Touch(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Touch(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Touch_getPreviousLocationInView(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Touch_getLocation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Touch_getDelta(JSContext *cx, uint32_t argc, jsval *vp); @@ -96,8 +96,8 @@ extern JSObject *jsb_cocos2d_Event_prototype; bool js_cocos2dx_Event_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Event_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Event(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Event(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Event_isStopped(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Event_getType(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Event_getCurrentTarget(JSContext *cx, uint32_t argc, jsval *vp); @@ -109,32 +109,24 @@ extern JSObject *jsb_cocos2d_EventTouch_prototype; bool js_cocos2dx_EventTouch_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EventTouch_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventTouch(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EventTouch(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EventTouch_getEventCode(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventTouch_setEventCode(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventTouch_EventTouch(JSContext *cx, uint32_t argc, jsval *vp); -extern JSClass *jsb_cocos2d_EventKeyboard_class; -extern JSObject *jsb_cocos2d_EventKeyboard_prototype; - -bool js_cocos2dx_EventKeyboard_constructor(JSContext *cx, uint32_t argc, jsval *vp); -void js_cocos2dx_EventKeyboard_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventKeyboard(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); -bool js_cocos2dx_EventKeyboard_EventKeyboard(JSContext *cx, uint32_t argc, jsval *vp); - extern JSClass *jsb_cocos2d_Node_class; extern JSObject *jsb_cocos2d_Node_prototype; bool js_cocos2dx_Node_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Node_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Node(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Node(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Node_addChild(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_removeComponent(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setPhysicsBody(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getGLProgram(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Node_updateTransformFromPhysics(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getDescription(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setCascadeOpacityEnabled(JSContext *cx, uint32_t argc, jsval *vp); @@ -158,8 +150,8 @@ bool js_cocos2dx_Node_getOpacity(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setCameraMask(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getTag(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getonEnterTransitionDidFinishCallback(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Node_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getNodeToWorldAffineTransform(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Node_getNodeToWorldTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getPosition3D(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_removeChild(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_convertToWorldSpace(JSContext *cx, uint32_t argc, jsval *vp); @@ -174,12 +166,12 @@ bool js_cocos2dx_Node_convertTouchToNodeSpace(JSContext *cx, uint32_t argc, jsva bool js_cocos2dx_Node_removeAllChildrenWithCleanup(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getRotationSkewX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getRotationSkewY(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Node_getNodeToParentAffineTransform(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Node_getNodeToWorldTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_isCascadeOpacityEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setParent(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getRotation3D(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Node_getNodeToParentTransform(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Node_getNodeToParentAffineTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_convertTouchToNodeSpaceAR(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getOnEnterCallback(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getPhysicsBody(JSContext *cx, uint32_t argc, jsval *vp); @@ -195,13 +187,15 @@ bool js_cocos2dx_Node_getNumberOfRunningActions(JSContext *cx, uint32_t argc, js bool js_cocos2dx_Node_updateTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_isVisible(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getChildrenCount(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Node_getNodeToParentTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_convertToNodeSpaceAR(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_addComponent(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_runAction(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Node_visit(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setGLProgram(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getRotation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getAnchorPointInPoints(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Node_visit(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Node_getRotationQuat(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_removeChildByName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setPositionZ(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getGLProgramState(JSContext *cx, uint32_t argc, jsval *vp); @@ -215,23 +209,23 @@ bool js_cocos2dx_Node_getActionByTag(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setRotationSkewX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setRotationSkewY(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setName(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Node_setAdditionalTransform(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Node_updatePhysicsBodyTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getDisplayedOpacity(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getLocalZOrder(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getScheduler(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Node_getParentToNodeAffineTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getOrderOfArrival(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setActionManager(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getPosition(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_isRunning(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getParent(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Node_getWorldToNodeTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getPositionY(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getPositionX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_removeChildByTag(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setPositionY(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_updateDisplayedColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setVisible(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Node_getParentToNodeTransform(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Node_getParentToNodeAffineTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getPositionZ(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setGlobalZOrder(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setScale(JSContext *cx, uint32_t argc, jsval *vp); @@ -242,7 +236,6 @@ bool js_cocos2dx_Node_getScaleZ(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getScaleY(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getScaleX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setLocalZOrder(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Node_getWorldToNodeAffineTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setCascadeColorEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setOpacity(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_cleanup(JSContext *cx, uint32_t argc, jsval *vp); @@ -260,13 +253,14 @@ bool js_cocos2dx_Node_removeFromParentAndCleanup(JSContext *cx, uint32_t argc, j bool js_cocos2dx_Node_setPosition3D(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_update(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_sortAllChildren(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Node_getWorldToNodeTransform(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Node_getWorldToNodeAffineTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getScale(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getNormalizedPosition(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Node_getParentToNodeTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_convertToNodeSpace(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setTag(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_isCascadeColorEnabled(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Node_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Node_setRotationQuat(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_stopAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getActionManager(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -277,8 +271,8 @@ extern JSObject *jsb_cocos2d___NodeRGBA_prototype; bool js_cocos2dx___NodeRGBA_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx___NodeRGBA_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx___NodeRGBA(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx___NodeRGBA(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx___NodeRGBA___NodeRGBA(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_Scene_class; @@ -286,14 +280,15 @@ extern JSObject *jsb_cocos2d_Scene_prototype; bool js_cocos2dx_Scene_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Scene_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Scene(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Scene(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Scene_initWithPhysics(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Scene_setCameraOrderDirty(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scene_render(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scene_onProjectionChanged(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Scene_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scene_getPhysicsWorld(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scene_initWithSize(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Scene_getDefaultCamera(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scene_createWithSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scene_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scene_createWithPhysics(JSContext *cx, uint32_t argc, jsval *vp); @@ -304,8 +299,8 @@ extern JSObject *jsb_cocos2d_GLView_prototype; bool js_cocos2dx_GLView_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_GLView_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_GLView(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_GLView(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_GLView_setFrameSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLView_getViewPortRect(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLView_setContentScaleFactor(JSContext *cx, uint32_t argc, jsval *vp); @@ -314,6 +309,7 @@ bool js_cocos2dx_GLView_setIMEKeyboardState(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_GLView_setScissorInPoints(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLView_getViewName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLView_isOpenGLReady(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_GLView_setCursorVisible(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLView_getScaleY(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLView_getScaleX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLView_getVisibleOrigin(JSContext *cx, uint32_t argc, jsval *vp); @@ -341,8 +337,8 @@ extern JSObject *jsb_cocos2d_Director_prototype; bool js_cocos2dx_Director_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Director_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Director(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Director(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Director_pause(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Director_setEventDispatcher(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Director_setContentScaleFactor(JSContext *cx, uint32_t argc, jsval *vp); @@ -379,6 +375,7 @@ bool js_cocos2dx_Director_stopAnimation(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Director_popToSceneStackLevel(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Director_resume(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Director_isNextDeltaTimeZero(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Director_setClearColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Director_setOpenGLView(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Director_convertToGL(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Director_purgeCachedData(JSContext *cx, uint32_t argc, jsval *vp); @@ -412,9 +409,10 @@ extern JSObject *jsb_cocos2d_Scheduler_prototype; bool js_cocos2dx_Scheduler_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Scheduler_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Scheduler(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Scheduler(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Scheduler_setTimeScale(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Scheduler_update(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scheduler_performFunctionInCocosThread(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scheduler_getTimeScale(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scheduler_Scheduler(JSContext *cx, uint32_t argc, jsval *vp); @@ -424,8 +422,8 @@ extern JSObject *jsb_cocos2d_FileUtils_prototype; bool js_cocos2dx_FileUtils_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_FileUtils_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_FileUtils(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_FileUtils(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_FileUtils_fullPathForFilename(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_getStringFromFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_removeFile(JSContext *cx, uint32_t argc, jsval *vp); @@ -447,11 +445,14 @@ bool js_cocos2dx_FileUtils_addSearchPath(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_FileUtils_isFileExist(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_purgeCachedEntries(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_fullPathFromRelativeFile(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_FileUtils_setWritablePath(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_setPopupNotify(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_isDirectoryExist(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_FileUtils_setDefaultResourceRootPath(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_getSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_createDirectory(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_getWritablePath(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_FileUtils_setDelegate(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_getInstance(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_EventListener_class; @@ -459,8 +460,8 @@ extern JSObject *jsb_cocos2d_EventListener_prototype; bool js_cocos2dx_EventListener_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EventListener_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventListener(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EventListener(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EventListener_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventListener_isEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventListener_clone(JSContext *cx, uint32_t argc, jsval *vp); @@ -471,8 +472,8 @@ extern JSObject *jsb_cocos2d_EventDispatcher_prototype; bool js_cocos2dx_EventDispatcher_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EventDispatcher_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventDispatcher(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EventDispatcher(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EventDispatcher_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventDispatcher_removeAllEventListeners(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventDispatcher_addEventListenerWithSceneGraphPriority(JSContext *cx, uint32_t argc, jsval *vp); @@ -493,8 +494,8 @@ extern JSObject *jsb_cocos2d_EventListenerTouchOneByOne_prototype; bool js_cocos2dx_EventListenerTouchOneByOne_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EventListenerTouchOneByOne_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventListenerTouchOneByOne(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EventListenerTouchOneByOne(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EventListenerTouchOneByOne_isSwallowTouches(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventListenerTouchOneByOne_setSwallowTouches(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventListenerTouchOneByOne_init(JSContext *cx, uint32_t argc, jsval *vp); @@ -505,8 +506,8 @@ extern JSObject *jsb_cocos2d_EventListenerTouchAllAtOnce_prototype; bool js_cocos2dx_EventListenerTouchAllAtOnce_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EventListenerTouchAllAtOnce_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventListenerTouchAllAtOnce(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EventListenerTouchAllAtOnce(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EventListenerTouchAllAtOnce_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventListenerTouchAllAtOnce_EventListenerTouchAllAtOnce(JSContext *cx, uint32_t argc, jsval *vp); @@ -515,8 +516,8 @@ extern JSObject *jsb_cocos2d_EventListenerKeyboard_prototype; bool js_cocos2dx_EventListenerKeyboard_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EventListenerKeyboard_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventListenerKeyboard(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EventListenerKeyboard(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EventListenerKeyboard_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventListenerKeyboard_EventListenerKeyboard(JSContext *cx, uint32_t argc, jsval *vp); @@ -525,8 +526,8 @@ extern JSObject *jsb_cocos2d_EventMouse_prototype; bool js_cocos2dx_EventMouse_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EventMouse_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventMouse(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EventMouse(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EventMouse_getMouseButton(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventMouse_getLocation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventMouse_setMouseButton(JSContext *cx, uint32_t argc, jsval *vp); @@ -549,8 +550,8 @@ extern JSObject *jsb_cocos2d_EventListenerMouse_prototype; bool js_cocos2dx_EventListenerMouse_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EventListenerMouse_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventListenerMouse(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EventListenerMouse(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EventListenerMouse_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventListenerMouse_EventListenerMouse(JSContext *cx, uint32_t argc, jsval *vp); @@ -559,8 +560,8 @@ extern JSObject *jsb_cocos2d_EventAcceleration_prototype; bool js_cocos2dx_EventAcceleration_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EventAcceleration_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventAcceleration(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EventAcceleration(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EventAcceleration_EventAcceleration(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_EventListenerAcceleration_class; @@ -568,8 +569,8 @@ extern JSObject *jsb_cocos2d_EventListenerAcceleration_prototype; bool js_cocos2dx_EventListenerAcceleration_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EventListenerAcceleration_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventListenerAcceleration(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EventListenerAcceleration(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EventListenerAcceleration_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventListenerAcceleration_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventListenerAcceleration_EventListenerAcceleration(JSContext *cx, uint32_t argc, jsval *vp); @@ -579,8 +580,8 @@ extern JSObject *jsb_cocos2d_EventCustom_prototype; bool js_cocos2dx_EventCustom_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EventCustom_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventCustom(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EventCustom(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EventCustom_getEventName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventCustom_EventCustom(JSContext *cx, uint32_t argc, jsval *vp); @@ -589,8 +590,8 @@ extern JSObject *jsb_cocos2d_EventListenerCustom_prototype; bool js_cocos2dx_EventListenerCustom_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EventListenerCustom_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventListenerCustom(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EventListenerCustom(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EventListenerCustom_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventListenerCustom_EventListenerCustom(JSContext *cx, uint32_t argc, jsval *vp); @@ -599,8 +600,8 @@ extern JSObject *jsb_cocos2d_EventFocus_prototype; bool js_cocos2dx_EventFocus_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EventFocus_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventFocus(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EventFocus(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EventFocus_EventFocus(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_EventListenerFocus_class; @@ -608,10 +609,9 @@ extern JSObject *jsb_cocos2d_EventListenerFocus_prototype; bool js_cocos2dx_EventListenerFocus_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EventListenerFocus_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EventListenerFocus(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EventListenerFocus(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EventListenerFocus_init(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_EventListenerFocus_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventListenerFocus_EventListenerFocus(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_Action_class; @@ -619,8 +619,8 @@ extern JSObject *jsb_cocos2d_Action_prototype; bool js_cocos2dx_Action_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Action_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Action(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Action(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Action_startWithTarget(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Action_setOriginalTarget(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Action_clone(JSContext *cx, uint32_t argc, jsval *vp); @@ -640,8 +640,8 @@ extern JSObject *jsb_cocos2d_FiniteTimeAction_prototype; bool js_cocos2dx_FiniteTimeAction_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_FiniteTimeAction_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_FiniteTimeAction(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_FiniteTimeAction(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_FiniteTimeAction_setDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FiniteTimeAction_getDuration(JSContext *cx, uint32_t argc, jsval *vp); @@ -650,8 +650,8 @@ extern JSObject *jsb_cocos2d_Speed_prototype; bool js_cocos2dx_Speed_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Speed_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Speed(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Speed(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Speed_setInnerAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Speed_getSpeed(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Speed_setSpeed(JSContext *cx, uint32_t argc, jsval *vp); @@ -665,8 +665,8 @@ extern JSObject *jsb_cocos2d_Follow_prototype; bool js_cocos2dx_Follow_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Follow_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Follow(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Follow(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Follow_setBoundarySet(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Follow_initWithTarget(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Follow_isBoundarySet(JSContext *cx, uint32_t argc, jsval *vp); @@ -678,8 +678,8 @@ extern JSObject *jsb_cocos2d_SpriteFrame_prototype; bool js_cocos2dx_SpriteFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_SpriteFrame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_SpriteFrame(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_SpriteFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_SpriteFrame_clone(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SpriteFrame_setRotated(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SpriteFrame_setTexture(JSContext *cx, uint32_t argc, jsval *vp); @@ -708,8 +708,8 @@ extern JSObject *jsb_cocos2d_AnimationFrame_prototype; bool js_cocos2dx_AnimationFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_AnimationFrame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_AnimationFrame(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_AnimationFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_AnimationFrame_setSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_AnimationFrame_getUserInfo(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_AnimationFrame_setDelayUnits(JSContext *cx, uint32_t argc, jsval *vp); @@ -726,8 +726,8 @@ extern JSObject *jsb_cocos2d_Animation_prototype; bool js_cocos2dx_Animation_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Animation_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Animation(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Animation(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Animation_getLoops(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Animation_addSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Animation_setRestoreOriginalFrame(JSContext *cx, uint32_t argc, jsval *vp); @@ -754,8 +754,8 @@ extern JSObject *jsb_cocos2d_ActionInterval_prototype; bool js_cocos2dx_ActionInterval_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ActionInterval_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ActionInterval(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ActionInterval(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ActionInterval_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ActionInterval_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ActionInterval_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp); @@ -766,8 +766,8 @@ extern JSObject *jsb_cocos2d_Sequence_prototype; bool js_cocos2dx_Sequence_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Sequence_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Sequence(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Sequence(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Sequence_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sequence_Sequence(JSContext *cx, uint32_t argc, jsval *vp); @@ -776,8 +776,8 @@ extern JSObject *jsb_cocos2d_Repeat_prototype; bool js_cocos2dx_Repeat_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Repeat_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Repeat(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Repeat(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Repeat_setInnerAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Repeat_initWithAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Repeat_getInnerAction(JSContext *cx, uint32_t argc, jsval *vp); @@ -789,8 +789,8 @@ extern JSObject *jsb_cocos2d_RepeatForever_prototype; bool js_cocos2dx_RepeatForever_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_RepeatForever_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_RepeatForever(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_RepeatForever(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_RepeatForever_setInnerAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_RepeatForever_initWithAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_RepeatForever_getInnerAction(JSContext *cx, uint32_t argc, jsval *vp); @@ -802,8 +802,8 @@ extern JSObject *jsb_cocos2d_Spawn_prototype; bool js_cocos2dx_Spawn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Spawn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Spawn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Spawn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Spawn_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Spawn_Spawn(JSContext *cx, uint32_t argc, jsval *vp); @@ -812,8 +812,8 @@ extern JSObject *jsb_cocos2d_RotateTo_prototype; bool js_cocos2dx_RotateTo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_RotateTo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_RotateTo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_RotateTo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_RotateTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_RotateTo_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_RotateTo_RotateTo(JSContext *cx, uint32_t argc, jsval *vp); @@ -823,8 +823,8 @@ extern JSObject *jsb_cocos2d_RotateBy_prototype; bool js_cocos2dx_RotateBy_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_RotateBy_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_RotateBy(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_RotateBy(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_RotateBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_RotateBy_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_RotateBy_RotateBy(JSContext *cx, uint32_t argc, jsval *vp); @@ -834,8 +834,8 @@ extern JSObject *jsb_cocos2d_MoveBy_prototype; bool js_cocos2dx_MoveBy_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_MoveBy_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_MoveBy(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_MoveBy(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_MoveBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MoveBy_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MoveBy_MoveBy(JSContext *cx, uint32_t argc, jsval *vp); @@ -845,8 +845,8 @@ extern JSObject *jsb_cocos2d_MoveTo_prototype; bool js_cocos2dx_MoveTo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_MoveTo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_MoveTo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_MoveTo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_MoveTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MoveTo_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MoveTo_MoveTo(JSContext *cx, uint32_t argc, jsval *vp); @@ -856,8 +856,8 @@ extern JSObject *jsb_cocos2d_SkewTo_prototype; bool js_cocos2dx_SkewTo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_SkewTo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_SkewTo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_SkewTo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_SkewTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SkewTo_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SkewTo_SkewTo(JSContext *cx, uint32_t argc, jsval *vp); @@ -867,8 +867,8 @@ extern JSObject *jsb_cocos2d_SkewBy_prototype; bool js_cocos2dx_SkewBy_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_SkewBy_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_SkewBy(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_SkewBy(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_SkewBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SkewBy_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SkewBy_SkewBy(JSContext *cx, uint32_t argc, jsval *vp); @@ -878,8 +878,8 @@ extern JSObject *jsb_cocos2d_JumpBy_prototype; bool js_cocos2dx_JumpBy_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_JumpBy_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_JumpBy(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_JumpBy(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_JumpBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_JumpBy_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_JumpBy_JumpBy(JSContext *cx, uint32_t argc, jsval *vp); @@ -889,8 +889,9 @@ extern JSObject *jsb_cocos2d_JumpTo_prototype; bool js_cocos2dx_JumpTo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_JumpTo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_JumpTo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_JumpTo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_JumpTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_JumpTo_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_JumpTo_JumpTo(JSContext *cx, uint32_t argc, jsval *vp); @@ -899,8 +900,8 @@ extern JSObject *jsb_cocos2d_BezierBy_prototype; bool js_cocos2dx_BezierBy_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_BezierBy_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_BezierBy(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_BezierBy(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_BezierBy_BezierBy(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_BezierTo_class; @@ -908,8 +909,8 @@ extern JSObject *jsb_cocos2d_BezierTo_prototype; bool js_cocos2dx_BezierTo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_BezierTo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_BezierTo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_BezierTo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_BezierTo_BezierTo(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_ScaleTo_class; @@ -917,8 +918,8 @@ extern JSObject *jsb_cocos2d_ScaleTo_prototype; bool js_cocos2dx_ScaleTo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ScaleTo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ScaleTo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ScaleTo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ScaleTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ScaleTo_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ScaleTo_ScaleTo(JSContext *cx, uint32_t argc, jsval *vp); @@ -928,8 +929,8 @@ extern JSObject *jsb_cocos2d_ScaleBy_prototype; bool js_cocos2dx_ScaleBy_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ScaleBy_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ScaleBy(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ScaleBy(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ScaleBy_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ScaleBy_ScaleBy(JSContext *cx, uint32_t argc, jsval *vp); @@ -938,8 +939,8 @@ extern JSObject *jsb_cocos2d_Blink_prototype; bool js_cocos2dx_Blink_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Blink_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Blink(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Blink(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Blink_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Blink_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Blink_Blink(JSContext *cx, uint32_t argc, jsval *vp); @@ -949,8 +950,8 @@ extern JSObject *jsb_cocos2d_FadeTo_prototype; bool js_cocos2dx_FadeTo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_FadeTo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_FadeTo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_FadeTo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_FadeTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FadeTo_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FadeTo_FadeTo(JSContext *cx, uint32_t argc, jsval *vp); @@ -960,8 +961,8 @@ extern JSObject *jsb_cocos2d_FadeIn_prototype; bool js_cocos2dx_FadeIn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_FadeIn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_FadeIn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_FadeIn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_FadeIn_setReverseAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FadeIn_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FadeIn_FadeIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -971,8 +972,8 @@ extern JSObject *jsb_cocos2d_FadeOut_prototype; bool js_cocos2dx_FadeOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_FadeOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_FadeOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_FadeOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_FadeOut_setReverseAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FadeOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FadeOut_FadeOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -982,8 +983,8 @@ extern JSObject *jsb_cocos2d_TintTo_prototype; bool js_cocos2dx_TintTo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TintTo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TintTo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TintTo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TintTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TintTo_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TintTo_TintTo(JSContext *cx, uint32_t argc, jsval *vp); @@ -993,8 +994,8 @@ extern JSObject *jsb_cocos2d_TintBy_prototype; bool js_cocos2dx_TintBy_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TintBy_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TintBy(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TintBy(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TintBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TintBy_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TintBy_TintBy(JSContext *cx, uint32_t argc, jsval *vp); @@ -1004,8 +1005,8 @@ extern JSObject *jsb_cocos2d_DelayTime_prototype; bool js_cocos2dx_DelayTime_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_DelayTime_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_DelayTime(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_DelayTime(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_DelayTime_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_DelayTime_DelayTime(JSContext *cx, uint32_t argc, jsval *vp); @@ -1014,8 +1015,8 @@ extern JSObject *jsb_cocos2d_ReverseTime_prototype; bool js_cocos2dx_ReverseTime_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ReverseTime_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ReverseTime(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ReverseTime(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ReverseTime_initWithAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ReverseTime_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ReverseTime_ReverseTime(JSContext *cx, uint32_t argc, jsval *vp); @@ -1025,8 +1026,8 @@ extern JSObject *jsb_cocos2d_Animate_prototype; bool js_cocos2dx_Animate_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Animate_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Animate(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Animate(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Animate_getAnimation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Animate_initWithAnimation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Animate_setAnimation(JSContext *cx, uint32_t argc, jsval *vp); @@ -1038,8 +1039,8 @@ extern JSObject *jsb_cocos2d_TargetedAction_prototype; bool js_cocos2dx_TargetedAction_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TargetedAction_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TargetedAction(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TargetedAction(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TargetedAction_getForcedTarget(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TargetedAction_initWithTarget(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TargetedAction_setForcedTarget(JSContext *cx, uint32_t argc, jsval *vp); @@ -1051,8 +1052,8 @@ extern JSObject *jsb_cocos2d_ActionCamera_prototype; bool js_cocos2dx_ActionCamera_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ActionCamera_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ActionCamera(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ActionCamera(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ActionCamera_setEye(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ActionCamera_getEye(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ActionCamera_setUp(JSContext *cx, uint32_t argc, jsval *vp); @@ -1066,8 +1067,8 @@ extern JSObject *jsb_cocos2d_OrbitCamera_prototype; bool js_cocos2dx_OrbitCamera_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_OrbitCamera_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_OrbitCamera(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_OrbitCamera(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_OrbitCamera_sphericalRadius(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_OrbitCamera_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_OrbitCamera_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -1078,8 +1079,8 @@ extern JSObject *jsb_cocos2d_ActionManager_prototype; bool js_cocos2dx_ActionManager_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ActionManager_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ActionManager(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ActionManager(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ActionManager_getActionByTag(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ActionManager_removeActionByTag(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ActionManager_removeAllActions(JSContext *cx, uint32_t argc, jsval *vp); @@ -1100,8 +1101,8 @@ extern JSObject *jsb_cocos2d_ActionEase_prototype; bool js_cocos2dx_ActionEase_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ActionEase_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ActionEase(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ActionEase(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ActionEase_initWithAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ActionEase_getInnerAction(JSContext *cx, uint32_t argc, jsval *vp); @@ -1110,8 +1111,8 @@ extern JSObject *jsb_cocos2d_EaseRateAction_prototype; bool js_cocos2dx_EaseRateAction_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseRateAction_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseRateAction(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseRateAction(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseRateAction_setRate(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseRateAction_initWithAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseRateAction_getRate(JSContext *cx, uint32_t argc, jsval *vp); @@ -1121,8 +1122,8 @@ extern JSObject *jsb_cocos2d_EaseIn_prototype; bool js_cocos2dx_EaseIn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseIn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseIn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseIn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseIn_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseIn_EaseIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -1131,8 +1132,8 @@ extern JSObject *jsb_cocos2d_EaseOut_prototype; bool js_cocos2dx_EaseOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseOut_EaseOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1141,8 +1142,8 @@ extern JSObject *jsb_cocos2d_EaseInOut_prototype; bool js_cocos2dx_EaseInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseInOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseInOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseInOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseInOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseInOut_EaseInOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1151,8 +1152,8 @@ extern JSObject *jsb_cocos2d_EaseExponentialIn_prototype; bool js_cocos2dx_EaseExponentialIn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseExponentialIn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseExponentialIn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseExponentialIn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseExponentialIn_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseExponentialIn_EaseExponentialIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -1161,8 +1162,8 @@ extern JSObject *jsb_cocos2d_EaseExponentialOut_prototype; bool js_cocos2dx_EaseExponentialOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseExponentialOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseExponentialOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseExponentialOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseExponentialOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseExponentialOut_EaseExponentialOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1171,8 +1172,8 @@ extern JSObject *jsb_cocos2d_EaseExponentialInOut_prototype; bool js_cocos2dx_EaseExponentialInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseExponentialInOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseExponentialInOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseExponentialInOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseExponentialInOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseExponentialInOut_EaseExponentialInOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1181,8 +1182,8 @@ extern JSObject *jsb_cocos2d_EaseSineIn_prototype; bool js_cocos2dx_EaseSineIn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseSineIn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseSineIn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseSineIn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseSineIn_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseSineIn_EaseSineIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -1191,8 +1192,8 @@ extern JSObject *jsb_cocos2d_EaseSineOut_prototype; bool js_cocos2dx_EaseSineOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseSineOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseSineOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseSineOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseSineOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseSineOut_EaseSineOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1201,8 +1202,8 @@ extern JSObject *jsb_cocos2d_EaseSineInOut_prototype; bool js_cocos2dx_EaseSineInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseSineInOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseSineInOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseSineInOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseSineInOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseSineInOut_EaseSineInOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1211,8 +1212,8 @@ extern JSObject *jsb_cocos2d_EaseElastic_prototype; bool js_cocos2dx_EaseElastic_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseElastic_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseElastic(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseElastic(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseElastic_setPeriod(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseElastic_initWithAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseElastic_getPeriod(JSContext *cx, uint32_t argc, jsval *vp); @@ -1222,8 +1223,8 @@ extern JSObject *jsb_cocos2d_EaseElasticIn_prototype; bool js_cocos2dx_EaseElasticIn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseElasticIn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseElasticIn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseElasticIn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseElasticIn_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseElasticIn_EaseElasticIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -1232,8 +1233,8 @@ extern JSObject *jsb_cocos2d_EaseElasticOut_prototype; bool js_cocos2dx_EaseElasticOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseElasticOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseElasticOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseElasticOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseElasticOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseElasticOut_EaseElasticOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1242,8 +1243,8 @@ extern JSObject *jsb_cocos2d_EaseElasticInOut_prototype; bool js_cocos2dx_EaseElasticInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseElasticInOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseElasticInOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseElasticInOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseElasticInOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseElasticInOut_EaseElasticInOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1252,16 +1253,16 @@ extern JSObject *jsb_cocos2d_EaseBounce_prototype; bool js_cocos2dx_EaseBounce_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseBounce_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseBounce(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseBounce(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); extern JSClass *jsb_cocos2d_EaseBounceIn_class; extern JSObject *jsb_cocos2d_EaseBounceIn_prototype; bool js_cocos2dx_EaseBounceIn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseBounceIn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseBounceIn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseBounceIn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseBounceIn_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseBounceIn_EaseBounceIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -1270,8 +1271,8 @@ extern JSObject *jsb_cocos2d_EaseBounceOut_prototype; bool js_cocos2dx_EaseBounceOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseBounceOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseBounceOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseBounceOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseBounceOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseBounceOut_EaseBounceOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1280,8 +1281,8 @@ extern JSObject *jsb_cocos2d_EaseBounceInOut_prototype; bool js_cocos2dx_EaseBounceInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseBounceInOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseBounceInOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseBounceInOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseBounceInOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseBounceInOut_EaseBounceInOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1290,8 +1291,8 @@ extern JSObject *jsb_cocos2d_EaseBackIn_prototype; bool js_cocos2dx_EaseBackIn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseBackIn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseBackIn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseBackIn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseBackIn_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseBackIn_EaseBackIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -1300,8 +1301,8 @@ extern JSObject *jsb_cocos2d_EaseBackOut_prototype; bool js_cocos2dx_EaseBackOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseBackOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseBackOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseBackOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseBackOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseBackOut_EaseBackOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1310,8 +1311,8 @@ extern JSObject *jsb_cocos2d_EaseBackInOut_prototype; bool js_cocos2dx_EaseBackInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseBackInOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseBackInOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseBackInOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseBackInOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseBackInOut_EaseBackInOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1320,8 +1321,8 @@ extern JSObject *jsb_cocos2d_EaseBezierAction_prototype; bool js_cocos2dx_EaseBezierAction_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseBezierAction_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseBezierAction(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseBezierAction(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseBezierAction_setBezierParamer(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseBezierAction_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseBezierAction_EaseBezierAction(JSContext *cx, uint32_t argc, jsval *vp); @@ -1331,8 +1332,8 @@ extern JSObject *jsb_cocos2d_EaseQuadraticActionIn_prototype; bool js_cocos2dx_EaseQuadraticActionIn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseQuadraticActionIn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseQuadraticActionIn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseQuadraticActionIn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseQuadraticActionIn_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseQuadraticActionIn_EaseQuadraticActionIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -1341,8 +1342,8 @@ extern JSObject *jsb_cocos2d_EaseQuadraticActionOut_prototype; bool js_cocos2dx_EaseQuadraticActionOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseQuadraticActionOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseQuadraticActionOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseQuadraticActionOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseQuadraticActionOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseQuadraticActionOut_EaseQuadraticActionOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1351,8 +1352,8 @@ extern JSObject *jsb_cocos2d_EaseQuadraticActionInOut_prototype; bool js_cocos2dx_EaseQuadraticActionInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseQuadraticActionInOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseQuadraticActionInOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseQuadraticActionInOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseQuadraticActionInOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseQuadraticActionInOut_EaseQuadraticActionInOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1361,8 +1362,8 @@ extern JSObject *jsb_cocos2d_EaseQuarticActionIn_prototype; bool js_cocos2dx_EaseQuarticActionIn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseQuarticActionIn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseQuarticActionIn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseQuarticActionIn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseQuarticActionIn_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseQuarticActionIn_EaseQuarticActionIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -1371,8 +1372,8 @@ extern JSObject *jsb_cocos2d_EaseQuarticActionOut_prototype; bool js_cocos2dx_EaseQuarticActionOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseQuarticActionOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseQuarticActionOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseQuarticActionOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseQuarticActionOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseQuarticActionOut_EaseQuarticActionOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1381,8 +1382,8 @@ extern JSObject *jsb_cocos2d_EaseQuarticActionInOut_prototype; bool js_cocos2dx_EaseQuarticActionInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseQuarticActionInOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseQuarticActionInOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseQuarticActionInOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseQuarticActionInOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseQuarticActionInOut_EaseQuarticActionInOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1391,8 +1392,8 @@ extern JSObject *jsb_cocos2d_EaseQuinticActionIn_prototype; bool js_cocos2dx_EaseQuinticActionIn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseQuinticActionIn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseQuinticActionIn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseQuinticActionIn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseQuinticActionIn_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseQuinticActionIn_EaseQuinticActionIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -1401,8 +1402,8 @@ extern JSObject *jsb_cocos2d_EaseQuinticActionOut_prototype; bool js_cocos2dx_EaseQuinticActionOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseQuinticActionOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseQuinticActionOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseQuinticActionOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseQuinticActionOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseQuinticActionOut_EaseQuinticActionOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1411,8 +1412,8 @@ extern JSObject *jsb_cocos2d_EaseQuinticActionInOut_prototype; bool js_cocos2dx_EaseQuinticActionInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseQuinticActionInOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseQuinticActionInOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseQuinticActionInOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseQuinticActionInOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseQuinticActionInOut_EaseQuinticActionInOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1421,8 +1422,8 @@ extern JSObject *jsb_cocos2d_EaseCircleActionIn_prototype; bool js_cocos2dx_EaseCircleActionIn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseCircleActionIn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseCircleActionIn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseCircleActionIn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseCircleActionIn_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseCircleActionIn_EaseCircleActionIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -1431,8 +1432,8 @@ extern JSObject *jsb_cocos2d_EaseCircleActionOut_prototype; bool js_cocos2dx_EaseCircleActionOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseCircleActionOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseCircleActionOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseCircleActionOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseCircleActionOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseCircleActionOut_EaseCircleActionOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1441,8 +1442,8 @@ extern JSObject *jsb_cocos2d_EaseCircleActionInOut_prototype; bool js_cocos2dx_EaseCircleActionInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseCircleActionInOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseCircleActionInOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseCircleActionInOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseCircleActionInOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseCircleActionInOut_EaseCircleActionInOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1451,8 +1452,8 @@ extern JSObject *jsb_cocos2d_EaseCubicActionIn_prototype; bool js_cocos2dx_EaseCubicActionIn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseCubicActionIn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseCubicActionIn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseCubicActionIn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseCubicActionIn_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseCubicActionIn_EaseCubicActionIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -1461,8 +1462,8 @@ extern JSObject *jsb_cocos2d_EaseCubicActionOut_prototype; bool js_cocos2dx_EaseCubicActionOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseCubicActionOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseCubicActionOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseCubicActionOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseCubicActionOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseCubicActionOut_EaseCubicActionOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1471,8 +1472,8 @@ extern JSObject *jsb_cocos2d_EaseCubicActionInOut_prototype; bool js_cocos2dx_EaseCubicActionInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_EaseCubicActionInOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_EaseCubicActionInOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_EaseCubicActionInOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_EaseCubicActionInOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EaseCubicActionInOut_EaseCubicActionInOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -1481,16 +1482,16 @@ extern JSObject *jsb_cocos2d_ActionInstant_prototype; bool js_cocos2dx_ActionInstant_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ActionInstant_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ActionInstant(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ActionInstant(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); extern JSClass *jsb_cocos2d_Show_class; extern JSObject *jsb_cocos2d_Show_prototype; bool js_cocos2dx_Show_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Show_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Show(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Show(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Show_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Show_Show(JSContext *cx, uint32_t argc, jsval *vp); @@ -1499,8 +1500,8 @@ extern JSObject *jsb_cocos2d_Hide_prototype; bool js_cocos2dx_Hide_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Hide_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Hide(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Hide(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Hide_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Hide_Hide(JSContext *cx, uint32_t argc, jsval *vp); @@ -1509,8 +1510,8 @@ extern JSObject *jsb_cocos2d_ToggleVisibility_prototype; bool js_cocos2dx_ToggleVisibility_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ToggleVisibility_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ToggleVisibility(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ToggleVisibility(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ToggleVisibility_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ToggleVisibility_ToggleVisibility(JSContext *cx, uint32_t argc, jsval *vp); @@ -1519,8 +1520,8 @@ extern JSObject *jsb_cocos2d_RemoveSelf_prototype; bool js_cocos2dx_RemoveSelf_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_RemoveSelf_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_RemoveSelf(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_RemoveSelf(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_RemoveSelf_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_RemoveSelf_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_RemoveSelf_RemoveSelf(JSContext *cx, uint32_t argc, jsval *vp); @@ -1530,8 +1531,8 @@ extern JSObject *jsb_cocos2d_FlipX_prototype; bool js_cocos2dx_FlipX_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_FlipX_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_FlipX(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_FlipX(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_FlipX_initWithFlipX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FlipX_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FlipX_FlipX(JSContext *cx, uint32_t argc, jsval *vp); @@ -1541,8 +1542,8 @@ extern JSObject *jsb_cocos2d_FlipY_prototype; bool js_cocos2dx_FlipY_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_FlipY_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_FlipY(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_FlipY(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_FlipY_initWithFlipY(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FlipY_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FlipY_FlipY(JSContext *cx, uint32_t argc, jsval *vp); @@ -1552,8 +1553,8 @@ extern JSObject *jsb_cocos2d_Place_prototype; bool js_cocos2dx_Place_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Place_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Place(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Place(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Place_initWithPosition(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Place_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Place_Place(JSContext *cx, uint32_t argc, jsval *vp); @@ -1563,8 +1564,8 @@ extern JSObject *jsb_cocos2d_CallFunc_prototype; bool js_cocos2dx_CallFunc_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_CallFunc_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_CallFunc(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_CallFunc(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_CallFunc_execute(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_CallFunc_CallFunc(JSContext *cx, uint32_t argc, jsval *vp); @@ -1573,8 +1574,8 @@ extern JSObject *jsb_cocos2d_CallFuncN_prototype; bool js_cocos2dx_CallFuncN_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_CallFuncN_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_CallFuncN(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_CallFuncN(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_CallFuncN_CallFuncN(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_GridAction_class; @@ -1582,8 +1583,8 @@ extern JSObject *jsb_cocos2d_GridAction_prototype; bool js_cocos2dx_GridAction_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_GridAction_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_GridAction(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_GridAction(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_GridAction_getGrid(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GridAction_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); @@ -1592,26 +1593,24 @@ extern JSObject *jsb_cocos2d_Grid3DAction_prototype; bool js_cocos2dx_Grid3DAction_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Grid3DAction_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Grid3DAction(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); -bool js_cocos2dx_Grid3DAction_getGrid(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_Grid3DAction(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); extern JSClass *jsb_cocos2d_TiledGrid3DAction_class; extern JSObject *jsb_cocos2d_TiledGrid3DAction_prototype; bool js_cocos2dx_TiledGrid3DAction_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TiledGrid3DAction_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TiledGrid3DAction(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); -bool js_cocos2dx_TiledGrid3DAction_getGrid(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_TiledGrid3DAction(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); extern JSClass *jsb_cocos2d_StopGrid_class; extern JSObject *jsb_cocos2d_StopGrid_prototype; bool js_cocos2dx_StopGrid_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_StopGrid_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_StopGrid(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_StopGrid(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_StopGrid_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_StopGrid_StopGrid(JSContext *cx, uint32_t argc, jsval *vp); @@ -1620,8 +1619,8 @@ extern JSObject *jsb_cocos2d_ReuseGrid_prototype; bool js_cocos2dx_ReuseGrid_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ReuseGrid_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ReuseGrid(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ReuseGrid(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ReuseGrid_initWithTimes(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ReuseGrid_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ReuseGrid_ReuseGrid(JSContext *cx, uint32_t argc, jsval *vp); @@ -1631,8 +1630,8 @@ extern JSObject *jsb_cocos2d_Waves3D_prototype; bool js_cocos2dx_Waves3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Waves3D_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Waves3D(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Waves3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Waves3D_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Waves3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Waves3D_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp); @@ -1646,8 +1645,8 @@ extern JSObject *jsb_cocos2d_FlipX3D_prototype; bool js_cocos2dx_FlipX3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_FlipX3D_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_FlipX3D(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_FlipX3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_FlipX3D_initWithSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FlipX3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FlipX3D_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -1658,8 +1657,8 @@ extern JSObject *jsb_cocos2d_FlipY3D_prototype; bool js_cocos2dx_FlipY3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_FlipY3D_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_FlipY3D(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_FlipY3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_FlipY3D_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FlipY3D_FlipY3D(JSContext *cx, uint32_t argc, jsval *vp); @@ -1668,8 +1667,8 @@ extern JSObject *jsb_cocos2d_Lens3D_prototype; bool js_cocos2dx_Lens3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Lens3D_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Lens3D(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Lens3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Lens3D_setConcave(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Lens3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Lens3D_setLensEffect(JSContext *cx, uint32_t argc, jsval *vp); @@ -1684,8 +1683,8 @@ extern JSObject *jsb_cocos2d_Ripple3D_prototype; bool js_cocos2dx_Ripple3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Ripple3D_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Ripple3D(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Ripple3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Ripple3D_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Ripple3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Ripple3D_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp); @@ -1701,8 +1700,8 @@ extern JSObject *jsb_cocos2d_Shaky3D_prototype; bool js_cocos2dx_Shaky3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Shaky3D_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Shaky3D(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Shaky3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Shaky3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Shaky3D_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Shaky3D_Shaky3D(JSContext *cx, uint32_t argc, jsval *vp); @@ -1712,8 +1711,8 @@ extern JSObject *jsb_cocos2d_Liquid_prototype; bool js_cocos2dx_Liquid_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Liquid_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Liquid(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Liquid(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Liquid_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Liquid_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Liquid_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp); @@ -1727,8 +1726,8 @@ extern JSObject *jsb_cocos2d_Waves_prototype; bool js_cocos2dx_Waves_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Waves_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Waves(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Waves(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Waves_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Waves_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Waves_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp); @@ -1742,8 +1741,8 @@ extern JSObject *jsb_cocos2d_Twirl_prototype; bool js_cocos2dx_Twirl_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Twirl_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Twirl(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Twirl(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Twirl_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Twirl_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Twirl_getAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp); @@ -1759,9 +1758,8 @@ extern JSObject *jsb_cocos2d_PageTurn3D_prototype; bool js_cocos2dx_PageTurn3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_PageTurn3D_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_PageTurn3D(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); -bool js_cocos2dx_PageTurn3D_getGrid(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_PageTurn3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_PageTurn3D_create(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_ProgressTo_class; @@ -1769,8 +1767,8 @@ extern JSObject *jsb_cocos2d_ProgressTo_prototype; bool js_cocos2dx_ProgressTo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ProgressTo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ProgressTo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ProgressTo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ProgressTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ProgressTo_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ProgressTo_ProgressTo(JSContext *cx, uint32_t argc, jsval *vp); @@ -1780,8 +1778,8 @@ extern JSObject *jsb_cocos2d_ProgressFromTo_prototype; bool js_cocos2dx_ProgressFromTo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ProgressFromTo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ProgressFromTo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ProgressFromTo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ProgressFromTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ProgressFromTo_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ProgressFromTo_ProgressFromTo(JSContext *cx, uint32_t argc, jsval *vp); @@ -1791,8 +1789,8 @@ extern JSObject *jsb_cocos2d_ShakyTiles3D_prototype; bool js_cocos2dx_ShakyTiles3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ShakyTiles3D_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ShakyTiles3D(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ShakyTiles3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ShakyTiles3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ShakyTiles3D_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ShakyTiles3D_ShakyTiles3D(JSContext *cx, uint32_t argc, jsval *vp); @@ -1802,8 +1800,8 @@ extern JSObject *jsb_cocos2d_ShatteredTiles3D_prototype; bool js_cocos2dx_ShatteredTiles3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ShatteredTiles3D_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ShatteredTiles3D(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ShatteredTiles3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ShatteredTiles3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ShatteredTiles3D_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ShatteredTiles3D_ShatteredTiles3D(JSContext *cx, uint32_t argc, jsval *vp); @@ -1813,8 +1811,8 @@ extern JSObject *jsb_cocos2d_ShuffleTiles_prototype; bool js_cocos2dx_ShuffleTiles_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ShuffleTiles_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ShuffleTiles(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ShuffleTiles(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ShuffleTiles_placeTile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ShuffleTiles_shuffle(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ShuffleTiles_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); @@ -1827,8 +1825,8 @@ extern JSObject *jsb_cocos2d_FadeOutTRTiles_prototype; bool js_cocos2dx_FadeOutTRTiles_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_FadeOutTRTiles_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_FadeOutTRTiles(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_FadeOutTRTiles(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_FadeOutTRTiles_turnOnTile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FadeOutTRTiles_turnOffTile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FadeOutTRTiles_transformTile(JSContext *cx, uint32_t argc, jsval *vp); @@ -1841,8 +1839,8 @@ extern JSObject *jsb_cocos2d_FadeOutBLTiles_prototype; bool js_cocos2dx_FadeOutBLTiles_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_FadeOutBLTiles_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_FadeOutBLTiles(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_FadeOutBLTiles(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_FadeOutBLTiles_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FadeOutBLTiles_FadeOutBLTiles(JSContext *cx, uint32_t argc, jsval *vp); @@ -1851,9 +1849,8 @@ extern JSObject *jsb_cocos2d_FadeOutUpTiles_prototype; bool js_cocos2dx_FadeOutUpTiles_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_FadeOutUpTiles_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_FadeOutUpTiles(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); -bool js_cocos2dx_FadeOutUpTiles_transformTile(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_FadeOutUpTiles(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_FadeOutUpTiles_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FadeOutUpTiles_FadeOutUpTiles(JSContext *cx, uint32_t argc, jsval *vp); @@ -1862,8 +1859,8 @@ extern JSObject *jsb_cocos2d_FadeOutDownTiles_prototype; bool js_cocos2dx_FadeOutDownTiles_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_FadeOutDownTiles_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_FadeOutDownTiles(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_FadeOutDownTiles(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_FadeOutDownTiles_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FadeOutDownTiles_FadeOutDownTiles(JSContext *cx, uint32_t argc, jsval *vp); @@ -1872,8 +1869,8 @@ extern JSObject *jsb_cocos2d_TurnOffTiles_prototype; bool js_cocos2dx_TurnOffTiles_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TurnOffTiles_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TurnOffTiles(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TurnOffTiles(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TurnOffTiles_turnOnTile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TurnOffTiles_turnOffTile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TurnOffTiles_shuffle(JSContext *cx, uint32_t argc, jsval *vp); @@ -1886,8 +1883,8 @@ extern JSObject *jsb_cocos2d_WavesTiles3D_prototype; bool js_cocos2dx_WavesTiles3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_WavesTiles3D_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_WavesTiles3D(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_WavesTiles3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_WavesTiles3D_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_WavesTiles3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_WavesTiles3D_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp); @@ -1901,8 +1898,8 @@ extern JSObject *jsb_cocos2d_JumpTiles3D_prototype; bool js_cocos2dx_JumpTiles3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_JumpTiles3D_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_JumpTiles3D(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_JumpTiles3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_JumpTiles3D_setAmplitudeRate(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_JumpTiles3D_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_JumpTiles3D_getAmplitude(JSContext *cx, uint32_t argc, jsval *vp); @@ -1916,8 +1913,8 @@ extern JSObject *jsb_cocos2d_SplitRows_prototype; bool js_cocos2dx_SplitRows_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_SplitRows_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_SplitRows(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_SplitRows(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_SplitRows_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SplitRows_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SplitRows_SplitRows(JSContext *cx, uint32_t argc, jsval *vp); @@ -1927,8 +1924,8 @@ extern JSObject *jsb_cocos2d_SplitCols_prototype; bool js_cocos2dx_SplitCols_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_SplitCols_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_SplitCols(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_SplitCols(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_SplitCols_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SplitCols_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SplitCols_SplitCols(JSContext *cx, uint32_t argc, jsval *vp); @@ -1938,8 +1935,8 @@ extern JSObject *jsb_cocos2d_ActionTween_prototype; bool js_cocos2dx_ActionTween_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ActionTween_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ActionTween(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ActionTween(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ActionTween_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ActionTween_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -1948,8 +1945,8 @@ extern JSObject *jsb_cocos2d_CardinalSplineTo_prototype; bool js_cocos2dx_CardinalSplineTo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_CardinalSplineTo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_CardinalSplineTo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_CardinalSplineTo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_CardinalSplineTo_getPoints(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_CardinalSplineTo_updatePosition(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_CardinalSplineTo_CardinalSplineTo(JSContext *cx, uint32_t argc, jsval *vp); @@ -1959,8 +1956,8 @@ extern JSObject *jsb_cocos2d_CardinalSplineBy_prototype; bool js_cocos2dx_CardinalSplineBy_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_CardinalSplineBy_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_CardinalSplineBy(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_CardinalSplineBy(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_CardinalSplineBy_CardinalSplineBy(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_CatmullRomTo_class; @@ -1968,24 +1965,24 @@ extern JSObject *jsb_cocos2d_CatmullRomTo_prototype; bool js_cocos2dx_CatmullRomTo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_CatmullRomTo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_CatmullRomTo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_CatmullRomTo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); extern JSClass *jsb_cocos2d_CatmullRomBy_class; extern JSObject *jsb_cocos2d_CatmullRomBy_prototype; bool js_cocos2dx_CatmullRomBy_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_CatmullRomBy_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_CatmullRomBy(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_CatmullRomBy(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); extern JSClass *jsb_cocos2d_ProtectedNode_class; extern JSObject *jsb_cocos2d_ProtectedNode_prototype; bool js_cocos2dx_ProtectedNode_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ProtectedNode_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ProtectedNode(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ProtectedNode(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ProtectedNode_addProtectedChild(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ProtectedNode_disableCascadeColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ProtectedNode_removeProtectedChildByTag(JSContext *cx, uint32_t argc, jsval *vp); @@ -2004,8 +2001,8 @@ extern JSObject *jsb_cocos2d_GLProgramState_prototype; bool js_cocos2dx_GLProgramState_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_GLProgramState_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_GLProgramState(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_GLProgramState(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_GLProgramState_setUniformTexture(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLProgramState_setUniformMat4(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLProgramState_applyUniforms(JSContext *cx, uint32_t argc, jsval *vp); @@ -2022,7 +2019,6 @@ bool js_cocos2dx_GLProgramState_setUniformVec2(JSContext *cx, uint32_t argc, jsv bool js_cocos2dx_GLProgramState_getVertexAttribsFlags(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLProgramState_setVertexAttribCallback(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLProgramState_apply(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_GLProgramState_setVertexAttribPointer(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLProgramState_getGLProgram(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLProgramState_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLProgramState_getOrCreateWithGLProgramName(JSContext *cx, uint32_t argc, jsval *vp); @@ -2033,8 +2029,8 @@ extern JSObject *jsb_cocos2d_AtlasNode_prototype; bool js_cocos2dx_AtlasNode_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_AtlasNode_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_AtlasNode(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_AtlasNode(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_AtlasNode_updateAtlasValues(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_AtlasNode_initWithTileFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_AtlasNode_getTexture(JSContext *cx, uint32_t argc, jsval *vp); @@ -2054,14 +2050,13 @@ extern JSObject *jsb_cocos2d_DrawNode_prototype; bool js_cocos2dx_DrawNode_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_DrawNode_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_DrawNode(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_DrawNode(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_DrawNode_drawLine(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_DrawNode_drawPoints(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_DrawNode_drawRect(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_DrawNode_drawSolidCircle(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_DrawNode_onDrawGLPoint(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_DrawNode_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_DrawNode_drawDot(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_DrawNode_drawCatmullRom(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_DrawNode_drawSegment(JSContext *cx, uint32_t argc, jsval *vp); @@ -2087,11 +2082,10 @@ extern JSObject *jsb_cocos2d_LabelAtlas_prototype; bool js_cocos2dx_LabelAtlas_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_LabelAtlas_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_LabelAtlas(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_LabelAtlas(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_LabelAtlas_setString(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelAtlas_initWithString(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_LabelAtlas_updateAtlasValues(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelAtlas_getString(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelAtlas_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelAtlas_LabelAtlas(JSContext *cx, uint32_t argc, jsval *vp); @@ -2101,8 +2095,8 @@ extern JSObject *jsb_cocos2d_LabelTTF_prototype; bool js_cocos2dx_LabelTTF_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_LabelTTF_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_LabelTTF(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_LabelTTF(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_LabelTTF_enableShadow(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelTTF_setDimensions(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelTTF_getFontSize(JSContext *cx, uint32_t argc, jsval *vp); @@ -2137,28 +2131,27 @@ extern JSObject *jsb_cocos2d_SpriteBatchNode_prototype; bool js_cocos2dx_SpriteBatchNode_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_SpriteBatchNode_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_SpriteBatchNode(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_SpriteBatchNode(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_SpriteBatchNode_appendChild(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_SpriteBatchNode_reorderBatch(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_SpriteBatchNode_getTexture(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_SpriteBatchNode_setTexture(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_SpriteBatchNode_removeChildAtIndex(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_SpriteBatchNode_removeSpriteFromAtlas(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SpriteBatchNode_addSpriteWithoutQuad(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_SpriteBatchNode_atlasIndexForChild(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_SpriteBatchNode_increaseAtlasCapacity(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_SpriteBatchNode_init(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_SpriteBatchNode_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpriteBatchNode_reorderBatch(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SpriteBatchNode_initWithTexture(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpriteBatchNode_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpriteBatchNode_atlasIndexForChild(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SpriteBatchNode_setTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_SpriteBatchNode_insertQuadFromSprite(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SpriteBatchNode_initWithFile(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_SpriteBatchNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_SpriteBatchNode_rebuildIndexInOrder(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpriteBatchNode_getTexture(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpriteBatchNode_increaseAtlasCapacity(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SpriteBatchNode_getTextureAtlas(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpriteBatchNode_insertQuadFromSprite(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpriteBatchNode_setTexture(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpriteBatchNode_rebuildIndexInOrder(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SpriteBatchNode_highestAtlasIndexInChild(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpriteBatchNode_removeChildAtIndex(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpriteBatchNode_removeSpriteFromAtlas(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpriteBatchNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SpriteBatchNode_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SpriteBatchNode_createWithTexture(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SpriteBatchNode_SpriteBatchNode(JSContext *cx, uint32_t argc, jsval *vp); @@ -2168,8 +2161,8 @@ extern JSObject *jsb_cocos2d_Label_prototype; bool js_cocos2dx_Label_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Label_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Label(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Label(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Label_isClipMarginEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Label_enableShadow(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Label_setDimensions(JSContext *cx, uint32_t argc, jsval *vp); @@ -2223,17 +2216,15 @@ extern JSObject *jsb_cocos2d_LabelBMFont_prototype; bool js_cocos2dx_LabelBMFont_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_LabelBMFont_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_LabelBMFont(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_LabelBMFont(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_LabelBMFont_setLineBreakWithoutSpace(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelBMFont_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_LabelBMFont_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelBMFont_getLetter(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelBMFont_getString(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelBMFont_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelBMFont_setString(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelBMFont_initWithString(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_LabelBMFont_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelBMFont_getFntFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelBMFont_setFntFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LabelBMFont_setAlignment(JSContext *cx, uint32_t argc, jsval *vp); @@ -2246,8 +2237,8 @@ extern JSObject *jsb_cocos2d_Layer_prototype; bool js_cocos2dx_Layer_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Layer_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Layer(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Layer(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Layer_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Layer_Layer(JSContext *cx, uint32_t argc, jsval *vp); @@ -2256,8 +2247,8 @@ extern JSObject *jsb_cocos2d___LayerRGBA_prototype; bool js_cocos2dx___LayerRGBA_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx___LayerRGBA_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx___LayerRGBA(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx___LayerRGBA(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx___LayerRGBA_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx___LayerRGBA___LayerRGBA(JSContext *cx, uint32_t argc, jsval *vp); @@ -2266,8 +2257,8 @@ extern JSObject *jsb_cocos2d_LayerColor_prototype; bool js_cocos2dx_LayerColor_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_LayerColor_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_LayerColor(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_LayerColor(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_LayerColor_changeWidthAndHeight(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LayerColor_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LayerColor_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); @@ -2282,8 +2273,8 @@ extern JSObject *jsb_cocos2d_LayerGradient_prototype; bool js_cocos2dx_LayerGradient_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_LayerGradient_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_LayerGradient(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_LayerGradient(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_LayerGradient_getStartColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LayerGradient_isCompressedInterpolation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LayerGradient_getStartOpacity(JSContext *cx, uint32_t argc, jsval *vp); @@ -2292,7 +2283,6 @@ bool js_cocos2dx_LayerGradient_setStartOpacity(JSContext *cx, uint32_t argc, jsv bool js_cocos2dx_LayerGradient_setCompressedInterpolation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LayerGradient_setEndOpacity(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LayerGradient_getVector(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_LayerGradient_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LayerGradient_setEndColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LayerGradient_initWithColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LayerGradient_getEndColor(JSContext *cx, uint32_t argc, jsval *vp); @@ -2306,10 +2296,9 @@ extern JSObject *jsb_cocos2d_LayerMultiplex_prototype; bool js_cocos2dx_LayerMultiplex_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_LayerMultiplex_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_LayerMultiplex(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_LayerMultiplex(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_LayerMultiplex_initWithArray(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_LayerMultiplex_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LayerMultiplex_switchToAndReleaseMe(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LayerMultiplex_addLayer(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_LayerMultiplex_switchTo(JSContext *cx, uint32_t argc, jsval *vp); @@ -2320,8 +2309,8 @@ extern JSObject *jsb_cocos2d_TransitionEaseScene_prototype; bool js_cocos2dx_TransitionEaseScene_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionEaseScene_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionEaseScene(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionEaseScene(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionEaseScene_easeActionWithAction(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_TransitionScene_class; @@ -2329,8 +2318,8 @@ extern JSObject *jsb_cocos2d_TransitionScene_prototype; bool js_cocos2dx_TransitionScene_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionScene_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionScene(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionScene(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionScene_finish(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionScene_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionScene_hideOutShowIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -2342,8 +2331,8 @@ extern JSObject *jsb_cocos2d_TransitionSceneOriented_prototype; bool js_cocos2dx_TransitionSceneOriented_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionSceneOriented_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionSceneOriented(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionSceneOriented(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionSceneOriented_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSceneOriented_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSceneOriented_TransitionSceneOriented(JSContext *cx, uint32_t argc, jsval *vp); @@ -2353,8 +2342,8 @@ extern JSObject *jsb_cocos2d_TransitionRotoZoom_prototype; bool js_cocos2dx_TransitionRotoZoom_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionRotoZoom_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionRotoZoom(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionRotoZoom(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionRotoZoom_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionRotoZoom_TransitionRotoZoom(JSContext *cx, uint32_t argc, jsval *vp); @@ -2363,8 +2352,8 @@ extern JSObject *jsb_cocos2d_TransitionJumpZoom_prototype; bool js_cocos2dx_TransitionJumpZoom_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionJumpZoom_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionJumpZoom(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionJumpZoom(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionJumpZoom_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionJumpZoom_TransitionJumpZoom(JSContext *cx, uint32_t argc, jsval *vp); @@ -2373,8 +2362,8 @@ extern JSObject *jsb_cocos2d_TransitionMoveInL_prototype; bool js_cocos2dx_TransitionMoveInL_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionMoveInL_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionMoveInL(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionMoveInL(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionMoveInL_action(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionMoveInL_easeActionWithAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionMoveInL_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -2385,8 +2374,8 @@ extern JSObject *jsb_cocos2d_TransitionMoveInR_prototype; bool js_cocos2dx_TransitionMoveInR_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionMoveInR_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionMoveInR(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionMoveInR(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionMoveInR_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionMoveInR_TransitionMoveInR(JSContext *cx, uint32_t argc, jsval *vp); @@ -2395,8 +2384,8 @@ extern JSObject *jsb_cocos2d_TransitionMoveInT_prototype; bool js_cocos2dx_TransitionMoveInT_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionMoveInT_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionMoveInT(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionMoveInT(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionMoveInT_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionMoveInT_TransitionMoveInT(JSContext *cx, uint32_t argc, jsval *vp); @@ -2405,8 +2394,8 @@ extern JSObject *jsb_cocos2d_TransitionMoveInB_prototype; bool js_cocos2dx_TransitionMoveInB_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionMoveInB_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionMoveInB(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionMoveInB(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionMoveInB_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionMoveInB_TransitionMoveInB(JSContext *cx, uint32_t argc, jsval *vp); @@ -2415,8 +2404,8 @@ extern JSObject *jsb_cocos2d_TransitionSlideInL_prototype; bool js_cocos2dx_TransitionSlideInL_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionSlideInL_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionSlideInL(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionSlideInL(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionSlideInL_action(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSlideInL_easeActionWithAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSlideInL_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -2427,9 +2416,8 @@ extern JSObject *jsb_cocos2d_TransitionSlideInR_prototype; bool js_cocos2dx_TransitionSlideInR_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionSlideInR_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionSlideInR(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); -bool js_cocos2dx_TransitionSlideInR_action(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_TransitionSlideInR(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionSlideInR_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSlideInR_TransitionSlideInR(JSContext *cx, uint32_t argc, jsval *vp); @@ -2438,9 +2426,8 @@ extern JSObject *jsb_cocos2d_TransitionSlideInB_prototype; bool js_cocos2dx_TransitionSlideInB_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionSlideInB_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionSlideInB(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); -bool js_cocos2dx_TransitionSlideInB_action(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_TransitionSlideInB(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionSlideInB_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSlideInB_TransitionSlideInB(JSContext *cx, uint32_t argc, jsval *vp); @@ -2449,9 +2436,8 @@ extern JSObject *jsb_cocos2d_TransitionSlideInT_prototype; bool js_cocos2dx_TransitionSlideInT_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionSlideInT_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionSlideInT(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); -bool js_cocos2dx_TransitionSlideInT_action(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_TransitionSlideInT(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionSlideInT_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSlideInT_TransitionSlideInT(JSContext *cx, uint32_t argc, jsval *vp); @@ -2460,8 +2446,8 @@ extern JSObject *jsb_cocos2d_TransitionShrinkGrow_prototype; bool js_cocos2dx_TransitionShrinkGrow_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionShrinkGrow_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionShrinkGrow(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionShrinkGrow(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionShrinkGrow_easeActionWithAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionShrinkGrow_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionShrinkGrow_TransitionShrinkGrow(JSContext *cx, uint32_t argc, jsval *vp); @@ -2471,8 +2457,8 @@ extern JSObject *jsb_cocos2d_TransitionFlipX_prototype; bool js_cocos2dx_TransitionFlipX_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionFlipX_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionFlipX(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionFlipX(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionFlipX_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionFlipX_TransitionFlipX(JSContext *cx, uint32_t argc, jsval *vp); @@ -2481,8 +2467,8 @@ extern JSObject *jsb_cocos2d_TransitionFlipY_prototype; bool js_cocos2dx_TransitionFlipY_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionFlipY_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionFlipY(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionFlipY(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionFlipY_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionFlipY_TransitionFlipY(JSContext *cx, uint32_t argc, jsval *vp); @@ -2491,8 +2477,8 @@ extern JSObject *jsb_cocos2d_TransitionFlipAngular_prototype; bool js_cocos2dx_TransitionFlipAngular_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionFlipAngular_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionFlipAngular(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionFlipAngular(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionFlipAngular_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionFlipAngular_TransitionFlipAngular(JSContext *cx, uint32_t argc, jsval *vp); @@ -2501,8 +2487,8 @@ extern JSObject *jsb_cocos2d_TransitionZoomFlipX_prototype; bool js_cocos2dx_TransitionZoomFlipX_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionZoomFlipX_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionZoomFlipX(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionZoomFlipX(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionZoomFlipX_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionZoomFlipX_TransitionZoomFlipX(JSContext *cx, uint32_t argc, jsval *vp); @@ -2511,8 +2497,8 @@ extern JSObject *jsb_cocos2d_TransitionZoomFlipY_prototype; bool js_cocos2dx_TransitionZoomFlipY_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionZoomFlipY_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionZoomFlipY(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionZoomFlipY(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionZoomFlipY_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionZoomFlipY_TransitionZoomFlipY(JSContext *cx, uint32_t argc, jsval *vp); @@ -2521,8 +2507,8 @@ extern JSObject *jsb_cocos2d_TransitionZoomFlipAngular_prototype; bool js_cocos2dx_TransitionZoomFlipAngular_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionZoomFlipAngular_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionZoomFlipAngular(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionZoomFlipAngular(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionZoomFlipAngular_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionZoomFlipAngular_TransitionZoomFlipAngular(JSContext *cx, uint32_t argc, jsval *vp); @@ -2531,8 +2517,8 @@ extern JSObject *jsb_cocos2d_TransitionFade_prototype; bool js_cocos2dx_TransitionFade_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionFade_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionFade(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionFade(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionFade_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionFade_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionFade_TransitionFade(JSContext *cx, uint32_t argc, jsval *vp); @@ -2542,8 +2528,8 @@ extern JSObject *jsb_cocos2d_TransitionCrossFade_prototype; bool js_cocos2dx_TransitionCrossFade_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionCrossFade_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionCrossFade(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionCrossFade(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionCrossFade_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionCrossFade_TransitionCrossFade(JSContext *cx, uint32_t argc, jsval *vp); @@ -2552,8 +2538,8 @@ extern JSObject *jsb_cocos2d_TransitionTurnOffTiles_prototype; bool js_cocos2dx_TransitionTurnOffTiles_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionTurnOffTiles_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionTurnOffTiles(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionTurnOffTiles(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionTurnOffTiles_easeActionWithAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionTurnOffTiles_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionTurnOffTiles_TransitionTurnOffTiles(JSContext *cx, uint32_t argc, jsval *vp); @@ -2563,8 +2549,8 @@ extern JSObject *jsb_cocos2d_TransitionSplitCols_prototype; bool js_cocos2dx_TransitionSplitCols_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionSplitCols_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionSplitCols(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionSplitCols(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionSplitCols_action(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSplitCols_easeActionWithAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSplitCols_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -2575,8 +2561,8 @@ extern JSObject *jsb_cocos2d_TransitionSplitRows_prototype; bool js_cocos2dx_TransitionSplitRows_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionSplitRows_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionSplitRows(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionSplitRows(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionSplitRows_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSplitRows_TransitionSplitRows(JSContext *cx, uint32_t argc, jsval *vp); @@ -2585,8 +2571,8 @@ extern JSObject *jsb_cocos2d_TransitionFadeTR_prototype; bool js_cocos2dx_TransitionFadeTR_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionFadeTR_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionFadeTR(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionFadeTR(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionFadeTR_easeActionWithAction(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionFadeTR_actionWithSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionFadeTR_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -2597,8 +2583,8 @@ extern JSObject *jsb_cocos2d_TransitionFadeBL_prototype; bool js_cocos2dx_TransitionFadeBL_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionFadeBL_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionFadeBL(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionFadeBL(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionFadeBL_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionFadeBL_TransitionFadeBL(JSContext *cx, uint32_t argc, jsval *vp); @@ -2607,8 +2593,8 @@ extern JSObject *jsb_cocos2d_TransitionFadeUp_prototype; bool js_cocos2dx_TransitionFadeUp_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionFadeUp_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionFadeUp(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionFadeUp(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionFadeUp_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionFadeUp_TransitionFadeUp(JSContext *cx, uint32_t argc, jsval *vp); @@ -2617,8 +2603,8 @@ extern JSObject *jsb_cocos2d_TransitionFadeDown_prototype; bool js_cocos2dx_TransitionFadeDown_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionFadeDown_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionFadeDown(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionFadeDown(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionFadeDown_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionFadeDown_TransitionFadeDown(JSContext *cx, uint32_t argc, jsval *vp); @@ -2627,8 +2613,8 @@ extern JSObject *jsb_cocos2d_TransitionPageTurn_prototype; bool js_cocos2dx_TransitionPageTurn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionPageTurn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionPageTurn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionPageTurn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionPageTurn_actionWithSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionPageTurn_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionPageTurn_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -2639,8 +2625,8 @@ extern JSObject *jsb_cocos2d_TransitionProgress_prototype; bool js_cocos2dx_TransitionProgress_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionProgress_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionProgress(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionProgress(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionProgress_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionProgress_TransitionProgress(JSContext *cx, uint32_t argc, jsval *vp); @@ -2649,8 +2635,8 @@ extern JSObject *jsb_cocos2d_TransitionProgressRadialCCW_prototype; bool js_cocos2dx_TransitionProgressRadialCCW_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionProgressRadialCCW_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionProgressRadialCCW(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionProgressRadialCCW(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionProgressRadialCCW_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionProgressRadialCCW_TransitionProgressRadialCCW(JSContext *cx, uint32_t argc, jsval *vp); @@ -2659,8 +2645,8 @@ extern JSObject *jsb_cocos2d_TransitionProgressRadialCW_prototype; bool js_cocos2dx_TransitionProgressRadialCW_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionProgressRadialCW_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionProgressRadialCW(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionProgressRadialCW(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionProgressRadialCW_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionProgressRadialCW_TransitionProgressRadialCW(JSContext *cx, uint32_t argc, jsval *vp); @@ -2669,8 +2655,8 @@ extern JSObject *jsb_cocos2d_TransitionProgressHorizontal_prototype; bool js_cocos2dx_TransitionProgressHorizontal_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionProgressHorizontal_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionProgressHorizontal(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionProgressHorizontal(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionProgressHorizontal_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionProgressHorizontal_TransitionProgressHorizontal(JSContext *cx, uint32_t argc, jsval *vp); @@ -2679,8 +2665,8 @@ extern JSObject *jsb_cocos2d_TransitionProgressVertical_prototype; bool js_cocos2dx_TransitionProgressVertical_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionProgressVertical_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionProgressVertical(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionProgressVertical(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionProgressVertical_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionProgressVertical_TransitionProgressVertical(JSContext *cx, uint32_t argc, jsval *vp); @@ -2689,8 +2675,8 @@ extern JSObject *jsb_cocos2d_TransitionProgressInOut_prototype; bool js_cocos2dx_TransitionProgressInOut_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionProgressInOut_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionProgressInOut(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionProgressInOut(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionProgressInOut_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionProgressInOut_TransitionProgressInOut(JSContext *cx, uint32_t argc, jsval *vp); @@ -2699,8 +2685,8 @@ extern JSObject *jsb_cocos2d_TransitionProgressOutIn_prototype; bool js_cocos2dx_TransitionProgressOutIn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TransitionProgressOutIn_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TransitionProgressOutIn(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TransitionProgressOutIn(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionProgressOutIn_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionProgressOutIn_TransitionProgressOutIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -2709,8 +2695,8 @@ extern JSObject *jsb_cocos2d_MenuItem_prototype; bool js_cocos2dx_MenuItem_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_MenuItem_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_MenuItem(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_MenuItem(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_MenuItem_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MenuItem_activate(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MenuItem_initWithCallback(JSContext *cx, uint32_t argc, jsval *vp); @@ -2726,8 +2712,8 @@ extern JSObject *jsb_cocos2d_MenuItemLabel_prototype; bool js_cocos2dx_MenuItemLabel_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_MenuItemLabel_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_MenuItemLabel(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_MenuItemLabel(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_MenuItemLabel_setLabel(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MenuItemLabel_getDisabledColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MenuItemLabel_setString(JSContext *cx, uint32_t argc, jsval *vp); @@ -2741,8 +2727,8 @@ extern JSObject *jsb_cocos2d_MenuItemAtlasFont_prototype; bool js_cocos2dx_MenuItemAtlasFont_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_MenuItemAtlasFont_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_MenuItemAtlasFont(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_MenuItemAtlasFont(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_MenuItemAtlasFont_initWithString(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MenuItemAtlasFont_MenuItemAtlasFont(JSContext *cx, uint32_t argc, jsval *vp); @@ -2751,8 +2737,8 @@ extern JSObject *jsb_cocos2d_MenuItemFont_prototype; bool js_cocos2dx_MenuItemFont_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_MenuItemFont_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_MenuItemFont(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_MenuItemFont(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_MenuItemFont_setFontNameObj(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MenuItemFont_getFontSizeObj(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MenuItemFont_setFontSizeObj(JSContext *cx, uint32_t argc, jsval *vp); @@ -2769,8 +2755,8 @@ extern JSObject *jsb_cocos2d_MenuItemSprite_prototype; bool js_cocos2dx_MenuItemSprite_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_MenuItemSprite_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_MenuItemSprite(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_MenuItemSprite(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_MenuItemSprite_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MenuItemSprite_selected(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MenuItemSprite_setNormalImage(JSContext *cx, uint32_t argc, jsval *vp); @@ -2788,8 +2774,8 @@ extern JSObject *jsb_cocos2d_MenuItemImage_prototype; bool js_cocos2dx_MenuItemImage_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_MenuItemImage_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_MenuItemImage(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_MenuItemImage(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_MenuItemImage_setDisabledSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MenuItemImage_setSelectedSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MenuItemImage_setNormalSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp); @@ -2802,8 +2788,8 @@ extern JSObject *jsb_cocos2d_MenuItemToggle_prototype; bool js_cocos2dx_MenuItemToggle_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_MenuItemToggle_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_MenuItemToggle(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_MenuItemToggle(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_MenuItemToggle_setSubItems(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MenuItemToggle_initWithItem(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MenuItemToggle_getSelectedIndex(JSContext *cx, uint32_t argc, jsval *vp); @@ -2817,13 +2803,12 @@ extern JSObject *jsb_cocos2d_Menu_prototype; bool js_cocos2dx_Menu_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Menu_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Menu(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Menu(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Menu_initWithArray(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Menu_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Menu_alignItemsVertically(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Menu_isEnabled(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Menu_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Menu_alignItemsHorizontallyWithPadding(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Menu_alignItemsVerticallyWithPadding(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Menu_alignItemsHorizontally(JSContext *cx, uint32_t argc, jsval *vp); @@ -2834,13 +2819,12 @@ extern JSObject *jsb_cocos2d_ClippingNode_prototype; bool js_cocos2dx_ClippingNode_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ClippingNode_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ClippingNode(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ClippingNode(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ClippingNode_hasContent(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ClippingNode_setInverted(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ClippingNode_setStencil(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ClippingNode_getAlphaThreshold(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ClippingNode_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ClippingNode_getStencil(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ClippingNode_setAlphaThreshold(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ClippingNode_isInverted(JSContext *cx, uint32_t argc, jsval *vp); @@ -2852,8 +2836,8 @@ extern JSObject *jsb_cocos2d_MotionStreak_prototype; bool js_cocos2dx_MotionStreak_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_MotionStreak_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_MotionStreak(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_MotionStreak(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_MotionStreak_reset(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MotionStreak_setTexture(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_MotionStreak_getTexture(JSContext *cx, uint32_t argc, jsval *vp); @@ -2873,8 +2857,8 @@ extern JSObject *jsb_cocos2d_ProgressTimer_prototype; bool js_cocos2dx_ProgressTimer_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ProgressTimer_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ProgressTimer(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ProgressTimer(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ProgressTimer_initWithSprite(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ProgressTimer_isReverseDirection(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ProgressTimer_setBarChangeRate(JSContext *cx, uint32_t argc, jsval *vp); @@ -2896,8 +2880,8 @@ extern JSObject *jsb_cocos2d_Sprite_prototype; bool js_cocos2dx_Sprite_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Sprite_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Sprite(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Sprite(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Sprite_setSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sprite_setTexture(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sprite_getTexture(JSContext *cx, uint32_t argc, jsval *vp); @@ -2905,14 +2889,12 @@ bool js_cocos2dx_Sprite_setFlippedY(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sprite_setFlippedX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sprite_setRotationSkewX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sprite_setRotationSkewY(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Sprite_initWithSpriteFrameName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sprite_initWithTexture(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sprite_getBatchNode(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sprite_getOffsetPosition(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sprite_removeAllChildrenWithCleanup(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Sprite_updateTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sprite_setTextureRect(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Sprite_init(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Sprite_initWithSpriteFrameName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sprite_isFrameDisplayed(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sprite_getAtlasIndex(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sprite_setBatchNode(JSContext *cx, uint32_t argc, jsval *vp); @@ -2938,13 +2920,38 @@ bool js_cocos2dx_Sprite_createWithSpriteFrameName(JSContext *cx, uint32_t argc, bool js_cocos2dx_Sprite_createWithSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sprite_Sprite(JSContext *cx, uint32_t argc, jsval *vp); +extern JSClass *jsb_cocos2d_Image_class; +extern JSObject *jsb_cocos2d_Image_prototype; + +bool js_cocos2dx_Image_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_Image_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_Image(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_Image_hasPremultipliedAlpha(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_getDataLen(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_saveToFile(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_hasAlpha(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_isCompressed(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_getHeight(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_initWithImageFile(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_getWidth(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_getBitPerPixel(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_getFileType(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_getNumberOfMipmaps(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_getRenderFormat(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_getData(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_getMipmaps(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_initWithRawData(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_setPVRImagesHavePremultipliedAlpha(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_Image(JSContext *cx, uint32_t argc, jsval *vp); + extern JSClass *jsb_cocos2d_RenderTexture_class; extern JSObject *jsb_cocos2d_RenderTexture_prototype; bool js_cocos2dx_RenderTexture_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_RenderTexture_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_RenderTexture(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_RenderTexture(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_RenderTexture_setVirtualViewport(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_RenderTexture_clearStencil(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_RenderTexture_getClearDepth(JSContext *cx, uint32_t argc, jsval *vp); @@ -2976,8 +2983,8 @@ extern JSObject *jsb_cocos2d_NodeGrid_prototype; bool js_cocos2dx_NodeGrid_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_NodeGrid_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_NodeGrid(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_NodeGrid(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_NodeGrid_setTarget(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_NodeGrid_getGrid(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_NodeGrid_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -2988,8 +2995,8 @@ extern JSObject *jsb_cocos2d_ParticleBatchNode_prototype; bool js_cocos2dx_ParticleBatchNode_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParticleBatchNode_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParticleBatchNode(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ParticleBatchNode(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleBatchNode_setTexture(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleBatchNode_initWithTexture(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleBatchNode_disableParticle(JSContext *cx, uint32_t argc, jsval *vp); @@ -3011,8 +3018,8 @@ extern JSObject *jsb_cocos2d_ParticleSystem_prototype; bool js_cocos2dx_ParticleSystem_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParticleSystem_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParticleSystem(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ParticleSystem(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleSystem_getStartSizeVar(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_getTexture(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_isFull(JSContext *cx, uint32_t argc, jsval *vp); @@ -3024,12 +3031,8 @@ bool js_cocos2dx_ParticleSystem_getEndSpin(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_ParticleSystem_setRotatePerSecondVar(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_getStartSpinVar(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_getRadialAccelVar(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ParticleSystem_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_getEndSizeVar(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ParticleSystem_setRotation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_setTangentialAccel(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ParticleSystem_setScaleY(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ParticleSystem_setScaleX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_getRadialAccel(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_setStartRadius(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_setRotatePerSecond(JSContext *cx, uint32_t argc, jsval *vp); @@ -3063,7 +3066,6 @@ bool js_cocos2dx_ParticleSystem_setAtlasIndex(JSContext *cx, uint32_t argc, jsva bool js_cocos2dx_ParticleSystem_setTangentialAccelVar(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_setEndRadiusVar(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_getEndRadius(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ParticleSystem_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_isActive(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_setRadialAccelVar(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_setStartSize(JSContext *cx, uint32_t argc, jsval *vp); @@ -3098,12 +3100,10 @@ bool js_cocos2dx_ParticleSystem_postStep(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_ParticleSystem_setEmissionRate(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_getEndColorVar(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_getRotationIsDir(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ParticleSystem_setScale(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_getEmissionRate(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_getEndColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_getLifeVar(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_setStartSizeVar(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ParticleSystem_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_addParticle(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_getStartRadius(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystem_getParticleCount(JSContext *cx, uint32_t argc, jsval *vp); @@ -3128,8 +3128,8 @@ extern JSObject *jsb_cocos2d_ParticleSystemQuad_prototype; bool js_cocos2dx_ParticleSystemQuad_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParticleSystemQuad_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParticleSystemQuad(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ParticleSystemQuad(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleSystemQuad_setDisplayFrame(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystemQuad_setTextureWithRect(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSystemQuad_listenRendererRecreated(JSContext *cx, uint32_t argc, jsval *vp); @@ -3142,9 +3142,8 @@ extern JSObject *jsb_cocos2d_ParticleFire_prototype; bool js_cocos2dx_ParticleFire_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParticleFire_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParticleFire(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); -bool js_cocos2dx_ParticleFire_init(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_ParticleFire(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleFire_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleFire_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleFire_ParticleFire(JSContext *cx, uint32_t argc, jsval *vp); @@ -3154,8 +3153,8 @@ extern JSObject *jsb_cocos2d_ParticleFireworks_prototype; bool js_cocos2dx_ParticleFireworks_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParticleFireworks_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParticleFireworks(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ParticleFireworks(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleFireworks_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleFireworks_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleFireworks_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -3167,8 +3166,8 @@ extern JSObject *jsb_cocos2d_ParticleSun_prototype; bool js_cocos2dx_ParticleSun_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParticleSun_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParticleSun(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ParticleSun(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleSun_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSun_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSun_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -3180,8 +3179,8 @@ extern JSObject *jsb_cocos2d_ParticleGalaxy_prototype; bool js_cocos2dx_ParticleGalaxy_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParticleGalaxy_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParticleGalaxy(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ParticleGalaxy(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleGalaxy_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleGalaxy_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleGalaxy_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -3193,8 +3192,8 @@ extern JSObject *jsb_cocos2d_ParticleFlower_prototype; bool js_cocos2dx_ParticleFlower_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParticleFlower_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParticleFlower(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ParticleFlower(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleFlower_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleFlower_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleFlower_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -3206,8 +3205,8 @@ extern JSObject *jsb_cocos2d_ParticleMeteor_prototype; bool js_cocos2dx_ParticleMeteor_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParticleMeteor_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParticleMeteor(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ParticleMeteor(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleMeteor_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleMeteor_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleMeteor_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -3219,8 +3218,8 @@ extern JSObject *jsb_cocos2d_ParticleSpiral_prototype; bool js_cocos2dx_ParticleSpiral_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParticleSpiral_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParticleSpiral(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ParticleSpiral(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleSpiral_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSpiral_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSpiral_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -3232,8 +3231,8 @@ extern JSObject *jsb_cocos2d_ParticleExplosion_prototype; bool js_cocos2dx_ParticleExplosion_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParticleExplosion_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParticleExplosion(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ParticleExplosion(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleExplosion_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleExplosion_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleExplosion_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -3245,8 +3244,8 @@ extern JSObject *jsb_cocos2d_ParticleSmoke_prototype; bool js_cocos2dx_ParticleSmoke_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParticleSmoke_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParticleSmoke(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ParticleSmoke(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleSmoke_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSmoke_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSmoke_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -3258,8 +3257,8 @@ extern JSObject *jsb_cocos2d_ParticleSnow_prototype; bool js_cocos2dx_ParticleSnow_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParticleSnow_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParticleSnow(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ParticleSnow(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleSnow_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSnow_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleSnow_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -3271,8 +3270,8 @@ extern JSObject *jsb_cocos2d_ParticleRain_prototype; bool js_cocos2dx_ParticleRain_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParticleRain_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParticleRain(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ParticleRain(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleRain_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleRain_initWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleRain_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -3284,8 +3283,8 @@ extern JSObject *jsb_cocos2d_GridBase_prototype; bool js_cocos2dx_GridBase_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_GridBase_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_GridBase(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_GridBase(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_GridBase_setGridSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GridBase_afterBlit(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GridBase_afterDraw(JSContext *cx, uint32_t argc, jsval *vp); @@ -3312,8 +3311,8 @@ extern JSObject *jsb_cocos2d_Grid3D_prototype; bool js_cocos2dx_Grid3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Grid3D_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Grid3D(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Grid3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Grid3D_getNeedDepthTestForBlit(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Grid3D_setNeedDepthTestForBlit(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Grid3D_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -3324,8 +3323,8 @@ extern JSObject *jsb_cocos2d_TiledGrid3D_prototype; bool js_cocos2dx_TiledGrid3D_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TiledGrid3D_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TiledGrid3D(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TiledGrid3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TiledGrid3D_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TiledGrid3D_TiledGrid3D(JSContext *cx, uint32_t argc, jsval *vp); @@ -3334,33 +3333,109 @@ extern JSObject *jsb_cocos2d_Camera_prototype; bool js_cocos2dx_Camera_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Camera_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Camera(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Camera(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Camera_setScene(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Camera_initPerspective(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_getProjectionMatrix(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_getViewProjectionMatrix(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_getViewMatrix(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_getCameraFlag(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_getType(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Camera_initDefault(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Camera_project(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Camera_getDepthInView(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_lookAt(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_setCameraFlag(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_initOrthographic(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Camera_initPerspective(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Camera_initDefault(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_setAdditionalProjection(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Camera_getDepth(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Camera_setDepth(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_createPerspective(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_createOrthographic(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Camera_getDefaultCamera(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_getVisitingCamera(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_Camera(JSContext *cx, uint32_t argc, jsval *vp); +extern JSClass *jsb_cocos2d_BaseLight_class; +extern JSObject *jsb_cocos2d_BaseLight_prototype; + +bool js_cocos2dx_BaseLight_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_BaseLight_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_BaseLight(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_BaseLight_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_BaseLight_getIntensity(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_BaseLight_isEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_BaseLight_getLightType(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_BaseLight_setLightFlag(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_BaseLight_setIntensity(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_BaseLight_getLightFlag(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocos2d_DirectionLight_class; +extern JSObject *jsb_cocos2d_DirectionLight_prototype; + +bool js_cocos2dx_DirectionLight_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_DirectionLight_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_DirectionLight(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_DirectionLight_getDirection(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_DirectionLight_getDirectionInWorld(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_DirectionLight_setDirection(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_DirectionLight_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_DirectionLight_DirectionLight(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocos2d_PointLight_class; +extern JSObject *jsb_cocos2d_PointLight_prototype; + +bool js_cocos2dx_PointLight_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_PointLight_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_PointLight(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_PointLight_getRange(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_PointLight_setRange(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_PointLight_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_PointLight_PointLight(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocos2d_SpotLight_class; +extern JSObject *jsb_cocos2d_SpotLight_prototype; + +bool js_cocos2dx_SpotLight_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_SpotLight_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_SpotLight(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_SpotLight_getRange(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpotLight_setDirection(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpotLight_getCosInnerAngle(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpotLight_getOuterAngle(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpotLight_getInnerAngle(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpotLight_getDirection(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpotLight_getCosOuterAngle(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpotLight_setOuterAngle(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpotLight_setInnerAngle(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpotLight_getDirectionInWorld(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpotLight_setRange(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpotLight_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_SpotLight_SpotLight(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocos2d_AmbientLight_class; +extern JSObject *jsb_cocos2d_AmbientLight_prototype; + +bool js_cocos2dx_AmbientLight_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_AmbientLight_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_AmbientLight(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_AmbientLight_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_AmbientLight_AmbientLight(JSContext *cx, uint32_t argc, jsval *vp); + extern JSClass *jsb_cocos2d_GLProgram_class; extern JSObject *jsb_cocos2d_GLProgram_prototype; bool js_cocos2dx_GLProgram_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_GLProgram_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_GLProgram(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_GLProgram(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_GLProgram_getFragmentShaderLog(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLProgram_bindAttribLocation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLProgram_getUniformLocationForName(JSContext *cx, uint32_t argc, jsval *vp); @@ -3393,8 +3468,8 @@ extern JSObject *jsb_cocos2d_GLProgramCache_prototype; bool js_cocos2dx_GLProgramCache_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_GLProgramCache_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_GLProgramCache(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_GLProgramCache(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_GLProgramCache_reloadDefaultGLPrograms(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLProgramCache_addGLProgram(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_GLProgramCache_getGLProgram(JSContext *cx, uint32_t argc, jsval *vp); @@ -3408,8 +3483,8 @@ extern JSObject *jsb_cocos2d_TextureCache_prototype; bool js_cocos2dx_TextureCache_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TextureCache_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TextureCache(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TextureCache(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TextureCache_reloadTexture(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TextureCache_unbindAllImageAsync(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TextureCache_removeTextureForKey(JSContext *cx, uint32_t argc, jsval *vp); @@ -3430,8 +3505,8 @@ extern JSObject *jsb_cocos2d_Device_prototype; bool js_cocos2dx_Device_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Device_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Device(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Device(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Device_setAccelerometerEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Device_setKeepScreenOn(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Device_setAccelerometerInterval(JSContext *cx, uint32_t argc, jsval *vp); @@ -3442,8 +3517,8 @@ extern JSObject *jsb_cocos2d_SAXParser_prototype; bool js_cocos2dx_SAXParser_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_SAXParser_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_SAXParser(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_SAXParser(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_SAXParser_init(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_Application_class; @@ -3451,8 +3526,8 @@ extern JSObject *jsb_cocos2d_Application_prototype; bool js_cocos2dx_Application_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Application_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Application(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Application(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Application_openURL(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Application_getTargetPlatform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Application_getCurrentLanguage(JSContext *cx, uint32_t argc, jsval *vp); @@ -3463,8 +3538,8 @@ extern JSObject *jsb_cocos2d_AnimationCache_prototype; bool js_cocos2dx_AnimationCache_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_AnimationCache_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_AnimationCache(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_AnimationCache(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_AnimationCache_getAnimation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_AnimationCache_addAnimation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_AnimationCache_init(JSContext *cx, uint32_t argc, jsval *vp); @@ -3480,8 +3555,8 @@ extern JSObject *jsb_cocos2d_SpriteFrameCache_prototype; bool js_cocos2dx_SpriteFrameCache_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_SpriteFrameCache_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_SpriteFrameCache(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_SpriteFrameCache(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_SpriteFrameCache_addSpriteFramesWithFileContent(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SpriteFrameCache_addSpriteFramesWithFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SpriteFrameCache_addSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp); @@ -3501,8 +3576,8 @@ extern JSObject *jsb_cocos2d_TextFieldTTF_prototype; bool js_cocos2dx_TextFieldTTF_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TextFieldTTF_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TextFieldTTF(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TextFieldTTF(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TextFieldTTF_getCharCount(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TextFieldTTF_setSecureTextEntry(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TextFieldTTF_getColorSpaceHolder(JSContext *cx, uint32_t argc, jsval *vp); @@ -3521,8 +3596,8 @@ extern JSObject *jsb_cocos2d_ParallaxNode_prototype; bool js_cocos2dx_ParallaxNode_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ParallaxNode_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ParallaxNode(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ParallaxNode(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParallaxNode_getParallaxArray(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParallaxNode_addChild(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParallaxNode_removeAllChildrenWithCleanup(JSContext *cx, uint32_t argc, jsval *vp); @@ -3535,8 +3610,8 @@ extern JSObject *jsb_cocos2d_TMXObjectGroup_prototype; bool js_cocos2dx_TMXObjectGroup_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TMXObjectGroup_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TMXObjectGroup(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TMXObjectGroup(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TMXObjectGroup_setPositionOffset(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TMXObjectGroup_getProperty(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TMXObjectGroup_getPositionOffset(JSContext *cx, uint32_t argc, jsval *vp); @@ -3554,8 +3629,8 @@ extern JSObject *jsb_cocos2d_TMXLayerInfo_prototype; bool js_cocos2dx_TMXLayerInfo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TMXLayerInfo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TMXLayerInfo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TMXLayerInfo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TMXLayerInfo_setProperties(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TMXLayerInfo_getProperties(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TMXLayerInfo_TMXLayerInfo(JSContext *cx, uint32_t argc, jsval *vp); @@ -3565,8 +3640,8 @@ extern JSObject *jsb_cocos2d_TMXTilesetInfo_prototype; bool js_cocos2dx_TMXTilesetInfo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TMXTilesetInfo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TMXTilesetInfo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TMXTilesetInfo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TMXTilesetInfo_getRectForGID(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TMXTilesetInfo_TMXTilesetInfo(JSContext *cx, uint32_t argc, jsval *vp); @@ -3575,8 +3650,8 @@ extern JSObject *jsb_cocos2d_TMXMapInfo_prototype; bool js_cocos2dx_TMXMapInfo_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TMXMapInfo_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TMXMapInfo(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TMXMapInfo(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TMXMapInfo_setObjectGroups(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TMXMapInfo_setTileSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TMXMapInfo_initWithTMXFile(JSContext *cx, uint32_t argc, jsval *vp); @@ -3618,8 +3693,8 @@ extern JSObject *jsb_cocos2d_TMXLayer_prototype; bool js_cocos2dx_TMXLayer_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TMXLayer_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TMXLayer(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TMXLayer(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TMXLayer_getTileGIDAt(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TMXLayer_getPositionAt(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TMXLayer_setLayerOrientation(JSContext *cx, uint32_t argc, jsval *vp); @@ -3650,8 +3725,8 @@ extern JSObject *jsb_cocos2d_TMXTiledMap_prototype; bool js_cocos2dx_TMXTiledMap_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TMXTiledMap_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TMXTiledMap(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TMXTiledMap(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TMXTiledMap_setObjectGroups(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TMXTiledMap_getProperty(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TMXTiledMap_setMapSize(JSContext *cx, uint32_t argc, jsval *vp); @@ -3677,8 +3752,8 @@ extern JSObject *jsb_cocos2d_TileMapAtlas_prototype; bool js_cocos2dx_TileMapAtlas_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_TileMapAtlas_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_TileMapAtlas(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_TileMapAtlas(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TileMapAtlas_initWithTileFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TileMapAtlas_releaseMap(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TileMapAtlas_getTGAInfo(JSContext *cx, uint32_t argc, jsval *vp); @@ -3693,8 +3768,8 @@ extern JSObject *jsb_cocos2d_Component_prototype; bool js_cocos2dx_Component_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Component_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_Component(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_Component(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Component_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Component_setName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Component_isEnabled(JSContext *cx, uint32_t argc, jsval *vp); @@ -3711,8 +3786,8 @@ extern JSObject *jsb_cocos2d_ComponentContainer_prototype; bool js_cocos2dx_ComponentContainer_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ComponentContainer_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ComponentContainer(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ComponentContainer(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ComponentContainer_visit(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ComponentContainer_remove(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ComponentContainer_removeAll(JSContext *cx, uint32_t argc, jsval *vp); @@ -3725,8 +3800,8 @@ extern JSObject *jsb_CocosDenshion_SimpleAudioEngine_prototype; bool js_cocos2dx_SimpleAudioEngine_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_SimpleAudioEngine_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_SimpleAudioEngine(JSContext *cx, JSObject *global); -void register_all_cocos2dx(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_SimpleAudioEngine(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_SimpleAudioEngine_preloadBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SimpleAudioEngine_stopBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SimpleAudioEngine_stopAllEffects(JSContext *cx, uint32_t argc, jsval *vp); @@ -3750,5 +3825,16 @@ bool js_cocos2dx_SimpleAudioEngine_unloadEffect(JSContext *cx, uint32_t argc, js bool js_cocos2dx_SimpleAudioEngine_resumeEffect(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SimpleAudioEngine_end(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_SimpleAudioEngine_getInstance(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocos2d_AsyncTaskPool_class; +extern JSObject *jsb_cocos2d_AsyncTaskPool_prototype; + +bool js_cocos2dx_AsyncTaskPool_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_AsyncTaskPool_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_AsyncTaskPool(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_AsyncTaskPool_stopTasks(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_AsyncTaskPool_destoryInstance(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_AsyncTaskPool_getInstance(JSContext *cx, uint32_t argc, jsval *vp); #endif diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_builder_auto.cpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_builder_auto.cpp index 2a589231c2..eac168bf35 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_builder_auto.cpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_builder_auto.cpp @@ -4,10 +4,11 @@ template static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedValue initializing(cx); bool isNewValid = true; - JSObject* global = ScriptingCore::getInstance()->getGlobalObject(); - isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && JSVAL_TO_BOOLEAN(initializing); + JS::RootedObject global(cx, ScriptingCore::getInstance()->getGlobalObject()); + isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && initializing.toBoolean(); if (isNewValid) { TypeTest t; @@ -18,8 +19,11 @@ static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *_tmp = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp)); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject _tmp(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + + args.rval().set(OBJECT_TO_JSVAL(_tmp)); return true; } @@ -31,9 +35,10 @@ static bool empty_constructor(JSContext *cx, uint32_t argc, jsval *vp) { return false; } -static bool js_is_native_obj(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) { - vp.set(BOOLEAN_TO_JSVAL(true)); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setBoolean(true); return true; } JSClass *jsb_cocosbuilder_CCBAnimationManager_class; @@ -41,9 +46,9 @@ JSObject *jsb_cocosbuilder_CCBAnimationManager_prototype; bool js_cocos2dx_builder_CCBAnimationManager_moveAnimationsFromNode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_moveAnimationsFromNode : Invalid Native Object"); @@ -51,24 +56,24 @@ bool js_cocos2dx_builder_CCBAnimationManager_moveAnimationsFromNode(JSContext *c cocos2d::Node* arg0; cocos2d::Node* arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_moveAnimationsFromNode : Error processing arguments"); cobj->moveAnimationsFromNode(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -77,18 +82,18 @@ bool js_cocos2dx_builder_CCBAnimationManager_moveAnimationsFromNode(JSContext *c } bool js_cocos2dx_builder_CCBAnimationManager_setAutoPlaySequenceId(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setAutoPlaySequenceId : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setAutoPlaySequenceId : Error processing arguments"); cobj->setAutoPlaySequenceId(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -97,7 +102,8 @@ bool js_cocos2dx_builder_CCBAnimationManager_setAutoPlaySequenceId(JSContext *cx } bool js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackNames(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackNames : Invalid Native Object"); @@ -105,7 +111,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackNames(JSContext cocos2d::ValueVector& ret = cobj->getDocumentCallbackNames(); jsval jsret = JSVAL_NULL; jsret = ccvaluevector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -114,18 +120,18 @@ bool js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackNames(JSContext } bool js_cocos2dx_builder_CCBAnimationManager_actionForSoundChannel(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_actionForSoundChannel : Invalid Native Object"); if (argc == 1) { cocosbuilder::CCBSequenceProperty* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocosbuilder::CCBSequenceProperty*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -141,7 +147,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_actionForSoundChannel(JSContext *cx jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -150,9 +156,9 @@ bool js_cocos2dx_builder_CCBAnimationManager_actionForSoundChannel(JSContext *cx } bool js_cocos2dx_builder_CCBAnimationManager_setBaseValue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setBaseValue : Invalid Native Object"); @@ -160,19 +166,19 @@ bool js_cocos2dx_builder_CCBAnimationManager_setBaseValue(JSContext *cx, uint32_ cocos2d::Value arg0; cocos2d::Node* arg1; std::string arg2; - ok &= jsval_to_ccvalue(cx, argv[0], &arg0); + ok &= jsval_to_ccvalue(cx, args.get(0), &arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setBaseValue : Error processing arguments"); cobj->setBaseValue(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -181,7 +187,8 @@ bool js_cocos2dx_builder_CCBAnimationManager_setBaseValue(JSContext *cx, uint32_ } bool js_cocos2dx_builder_CCBAnimationManager_getDocumentOutletNodes(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getDocumentOutletNodes : Invalid Native Object"); @@ -189,7 +196,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_getDocumentOutletNodes(JSContext *c cocos2d::Vector& ret = cobj->getDocumentOutletNodes(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -198,7 +205,8 @@ bool js_cocos2dx_builder_CCBAnimationManager_getDocumentOutletNodes(JSContext *c } bool js_cocos2dx_builder_CCBAnimationManager_getLastCompletedSequenceName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getLastCompletedSequenceName : Invalid Native Object"); @@ -206,7 +214,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_getLastCompletedSequenceName(JSCont std::string ret = cobj->getLastCompletedSequenceName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -215,25 +223,25 @@ bool js_cocos2dx_builder_CCBAnimationManager_getLastCompletedSequenceName(JSCont } bool js_cocos2dx_builder_CCBAnimationManager_setRootNode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setRootNode : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setRootNode : Error processing arguments"); cobj->setRootNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -242,20 +250,20 @@ bool js_cocos2dx_builder_CCBAnimationManager_setRootNode(JSContext *cx, uint32_t } bool js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceNamedTweenDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceNamedTweenDuration : Invalid Native Object"); if (argc == 2) { const char* arg0; double arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceNamedTweenDuration : Error processing arguments"); cobj->runAnimationsForSequenceNamedTweenDuration(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -264,18 +272,18 @@ bool js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceNamedTweenD } bool js_cocos2dx_builder_CCBAnimationManager_addDocumentOutletName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_addDocumentOutletName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_addDocumentOutletName : Error processing arguments"); cobj->addDocumentOutletName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -284,7 +292,8 @@ bool js_cocos2dx_builder_CCBAnimationManager_addDocumentOutletName(JSContext *cx } bool js_cocos2dx_builder_CCBAnimationManager_getRootContainerSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getRootContainerSize : Invalid Native Object"); @@ -292,7 +301,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_getRootContainerSize(JSContext *cx, const cocos2d::Size& ret = cobj->getRootContainerSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -301,18 +310,18 @@ bool js_cocos2dx_builder_CCBAnimationManager_getRootContainerSize(JSContext *cx, } bool js_cocos2dx_builder_CCBAnimationManager_setDocumentControllerName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setDocumentControllerName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setDocumentControllerName : Error processing arguments"); cobj->setDocumentControllerName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -321,9 +330,9 @@ bool js_cocos2dx_builder_CCBAnimationManager_setDocumentControllerName(JSContext } bool js_cocos2dx_builder_CCBAnimationManager_setObject(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setObject : Invalid Native Object"); @@ -332,25 +341,25 @@ bool js_cocos2dx_builder_CCBAnimationManager_setObject(JSContext *cx, uint32_t a cocos2d::Node* arg1; std::string arg2; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Ref*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setObject : Error processing arguments"); cobj->setObject(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -359,18 +368,18 @@ bool js_cocos2dx_builder_CCBAnimationManager_setObject(JSContext *cx, uint32_t a } bool js_cocos2dx_builder_CCBAnimationManager_getContainerSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getContainerSize : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -379,7 +388,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_getContainerSize(JSContext *cx, uin const cocos2d::Size& ret = cobj->getContainerSize(arg0); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -388,18 +397,18 @@ bool js_cocos2dx_builder_CCBAnimationManager_getContainerSize(JSContext *cx, uin } bool js_cocos2dx_builder_CCBAnimationManager_actionForCallbackChannel(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_actionForCallbackChannel : Invalid Native Object"); if (argc == 1) { cocosbuilder::CCBSequenceProperty* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocosbuilder::CCBSequenceProperty*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -415,7 +424,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_actionForCallbackChannel(JSContext jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -424,7 +433,8 @@ bool js_cocos2dx_builder_CCBAnimationManager_actionForCallbackChannel(JSContext } bool js_cocos2dx_builder_CCBAnimationManager_getDocumentOutletNames(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getDocumentOutletNames : Invalid Native Object"); @@ -432,7 +442,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_getDocumentOutletNames(JSContext *c cocos2d::ValueVector& ret = cobj->getDocumentOutletNames(); jsval jsret = JSVAL_NULL; jsret = ccvaluevector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -441,18 +451,18 @@ bool js_cocos2dx_builder_CCBAnimationManager_getDocumentOutletNames(JSContext *c } bool js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackControlEvents(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackControlEvents : Invalid Native Object"); if (argc == 1) { cocos2d::extension::Control::EventType arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackControlEvents : Error processing arguments"); cobj->addDocumentCallbackControlEvents(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -461,7 +471,8 @@ bool js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackControlEvents(JS } bool js_cocos2dx_builder_CCBAnimationManager_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_init : Invalid Native Object"); @@ -469,7 +480,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_init(JSContext *cx, uint32_t argc, bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -478,7 +489,8 @@ bool js_cocos2dx_builder_CCBAnimationManager_init(JSContext *cx, uint32_t argc, } bool js_cocos2dx_builder_CCBAnimationManager_getKeyframeCallbacks(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getKeyframeCallbacks : Invalid Native Object"); @@ -486,7 +498,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_getKeyframeCallbacks(JSContext *cx, cocos2d::ValueVector& ret = cobj->getKeyframeCallbacks(); jsval jsret = JSVAL_NULL; jsret = ccvaluevector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -495,7 +507,8 @@ bool js_cocos2dx_builder_CCBAnimationManager_getKeyframeCallbacks(JSContext *cx, } bool js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackControlEvents(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackControlEvents : Invalid Native Object"); @@ -503,7 +516,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackControlEvents(JS cocos2d::ValueVector& ret = cobj->getDocumentCallbackControlEvents(); jsval jsret = JSVAL_NULL; jsret = ccvaluevector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -512,18 +525,18 @@ bool js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackControlEvents(JS } bool js_cocos2dx_builder_CCBAnimationManager_setRootContainerSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setRootContainerSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setRootContainerSize : Error processing arguments"); cobj->setRootContainerSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -532,20 +545,20 @@ bool js_cocos2dx_builder_CCBAnimationManager_setRootContainerSize(JSContext *cx, } bool js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceIdTweenDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceIdTweenDuration : Invalid Native Object"); if (argc == 2) { int arg0; double arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceIdTweenDuration : Error processing arguments"); cobj->runAnimationsForSequenceIdTweenDuration(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -554,7 +567,8 @@ bool js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceIdTweenDura } bool js_cocos2dx_builder_CCBAnimationManager_getRunningSequenceName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getRunningSequenceName : Invalid Native Object"); @@ -562,7 +576,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_getRunningSequenceName(JSContext *c const char* ret = cobj->getRunningSequenceName(); jsval jsret = JSVAL_NULL; jsret = c_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -571,7 +585,8 @@ bool js_cocos2dx_builder_CCBAnimationManager_getRunningSequenceName(JSContext *c } bool js_cocos2dx_builder_CCBAnimationManager_getAutoPlaySequenceId(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getAutoPlaySequenceId : Invalid Native Object"); @@ -579,7 +594,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_getAutoPlaySequenceId(JSContext *cx int ret = cobj->getAutoPlaySequenceId(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -588,18 +603,18 @@ bool js_cocos2dx_builder_CCBAnimationManager_getAutoPlaySequenceId(JSContext *cx } bool js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackName : Error processing arguments"); cobj->addDocumentCallbackName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -608,7 +623,8 @@ bool js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackName(JSContext * } bool js_cocos2dx_builder_CCBAnimationManager_getRootNode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getRootNode : Invalid Native Object"); @@ -623,7 +639,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_getRootNode(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -632,25 +648,25 @@ bool js_cocos2dx_builder_CCBAnimationManager_getRootNode(JSContext *cx, uint32_t } bool js_cocos2dx_builder_CCBAnimationManager_addDocumentOutletNode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_addDocumentOutletNode : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_addDocumentOutletNode : Error processing arguments"); cobj->addDocumentOutletNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -659,25 +675,25 @@ bool js_cocos2dx_builder_CCBAnimationManager_addDocumentOutletNode(JSContext *cx } bool js_cocos2dx_builder_CCBAnimationManager_setDelegate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setDelegate : Invalid Native Object"); if (argc == 1) { cocosbuilder::CCBAnimationManagerDelegate* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocosbuilder::CCBAnimationManagerDelegate*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setDelegate : Error processing arguments"); cobj->setDelegate(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -686,20 +702,20 @@ bool js_cocos2dx_builder_CCBAnimationManager_setDelegate(JSContext *cx, uint32_t } bool js_cocos2dx_builder_CCBAnimationManager_getSequenceDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getSequenceDuration : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getSequenceDuration : Error processing arguments"); double ret = cobj->getSequenceDuration(arg0); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -708,25 +724,25 @@ bool js_cocos2dx_builder_CCBAnimationManager_getSequenceDuration(JSContext *cx, } bool js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackNode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackNode : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackNode : Error processing arguments"); cobj->addDocumentCallbackNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -735,18 +751,18 @@ bool js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackNode(JSContext * } bool js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceNamed(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceNamed : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceNamed : Error processing arguments"); cobj->runAnimationsForSequenceNamed(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -755,20 +771,20 @@ bool js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceNamed(JSCon } bool js_cocos2dx_builder_CCBAnimationManager_getSequenceId(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getSequenceId : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getSequenceId : Error processing arguments"); int ret = cobj->getSequenceId(arg0); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -777,9 +793,9 @@ bool js_cocos2dx_builder_CCBAnimationManager_getSequenceId(JSContext *cx, uint32 } bool js_cocos2dx_builder_CCBAnimationManager_setCallFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setCallFunc : Invalid Native Object"); @@ -787,17 +803,17 @@ bool js_cocos2dx_builder_CCBAnimationManager_setCallFunc(JSContext *cx, uint32_t cocos2d::CallFunc* arg0; std::string arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::CallFunc*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setCallFunc : Error processing arguments"); cobj->setCallFunc(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -806,7 +822,8 @@ bool js_cocos2dx_builder_CCBAnimationManager_setCallFunc(JSContext *cx, uint32_t } bool js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackNodes(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackNodes : Invalid Native Object"); @@ -814,7 +831,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackNodes(JSContext cocos2d::Vector& ret = cobj->getDocumentCallbackNodes(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -823,18 +840,18 @@ bool js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackNodes(JSContext } bool js_cocos2dx_builder_CCBAnimationManager_setSequences(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setSequences : Invalid Native Object"); if (argc == 1) { cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBAnimationManager_setSequences : Error processing arguments"); cobj->setSequences(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -843,13 +860,14 @@ bool js_cocos2dx_builder_CCBAnimationManager_setSequences(JSContext *cx, uint32_ } bool js_cocos2dx_builder_CCBAnimationManager_debug(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_debug : Invalid Native Object"); if (argc == 0) { cobj->debug(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -858,7 +876,8 @@ bool js_cocos2dx_builder_CCBAnimationManager_debug(JSContext *cx, uint32_t argc, } bool js_cocos2dx_builder_CCBAnimationManager_getDocumentControllerName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager* cobj = (cocosbuilder::CCBAnimationManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBAnimationManager_getDocumentControllerName : Invalid Native Object"); @@ -866,7 +885,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_getDocumentControllerName(JSContext std::string ret = cobj->getDocumentControllerName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -875,7 +894,7 @@ bool js_cocos2dx_builder_CCBAnimationManager_getDocumentControllerName(JSContext } bool js_cocos2dx_builder_CCBAnimationManager_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocosbuilder::CCBAnimationManager* cobj = new (std::nothrow) cocosbuilder::CCBAnimationManager(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -889,13 +908,16 @@ bool js_cocos2dx_builder_CCBAnimationManager_constructor(JSContext *cx, uint32_t CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocosbuilder::CCBAnimationManager"); + AddNamedObjectRoot(cx, &p->obj, "cocosbuilder::CCBAnimationManager"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -905,7 +927,7 @@ void js_cocosbuilder_CCBAnimationManager_finalize(JSFreeOp *fop, JSObject *obj) CCLOGINFO("jsbindings: finalizing JS object %p (CCBAnimationManager)", obj); } -void js_register_cocos2dx_builder_CCBAnimationManager(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_builder_CCBAnimationManager(JSContext *cx, JS::HandleObject global) { jsb_cocosbuilder_CCBAnimationManager_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocosbuilder_CCBAnimationManager_class->name = "BuilderAnimationManager"; jsb_cocosbuilder_CCBAnimationManager_class->addProperty = JS_PropertyStub; @@ -919,8 +941,8 @@ void js_register_cocos2dx_builder_CCBAnimationManager(JSContext *cx, JSObject *g jsb_cocosbuilder_CCBAnimationManager_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -968,7 +990,7 @@ void js_register_cocos2dx_builder_CCBAnimationManager(JSContext *cx, JSObject *g jsb_cocosbuilder_CCBAnimationManager_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocosbuilder_CCBAnimationManager_class, js_cocos2dx_builder_CCBAnimationManager_constructor, 0, // constructor properties, @@ -999,7 +1021,8 @@ JSObject *jsb_cocosbuilder_CCBReader_prototype; bool js_cocos2dx_builder_CCBReader_getAnimationManager(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_getAnimationManager : Invalid Native Object"); @@ -1014,7 +1037,7 @@ bool js_cocos2dx_builder_CCBReader_getAnimationManager(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1023,25 +1046,25 @@ bool js_cocos2dx_builder_CCBReader_getAnimationManager(JSContext *cx, uint32_t a } bool js_cocos2dx_builder_CCBReader_setAnimationManager(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_setAnimationManager : Invalid Native Object"); if (argc == 1) { cocosbuilder::CCBAnimationManager* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocosbuilder::CCBAnimationManager*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBReader_setAnimationManager : Error processing arguments"); cobj->setAnimationManager(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1050,18 +1073,18 @@ bool js_cocos2dx_builder_CCBReader_setAnimationManager(JSContext *cx, uint32_t a } bool js_cocos2dx_builder_CCBReader_addOwnerOutletName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_addOwnerOutletName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBReader_addOwnerOutletName : Error processing arguments"); cobj->addOwnerOutletName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1070,7 +1093,8 @@ bool js_cocos2dx_builder_CCBReader_addOwnerOutletName(JSContext *cx, uint32_t ar } bool js_cocos2dx_builder_CCBReader_getOwnerCallbackNames(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_getOwnerCallbackNames : Invalid Native Object"); @@ -1078,7 +1102,7 @@ bool js_cocos2dx_builder_CCBReader_getOwnerCallbackNames(JSContext *cx, uint32_t cocos2d::ValueVector ret = cobj->getOwnerCallbackNames(); jsval jsret = JSVAL_NULL; jsret = ccvaluevector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1087,18 +1111,18 @@ bool js_cocos2dx_builder_CCBReader_getOwnerCallbackNames(JSContext *cx, uint32_t } bool js_cocos2dx_builder_CCBReader_addDocumentCallbackControlEvents(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_addDocumentCallbackControlEvents : Invalid Native Object"); if (argc == 1) { cocos2d::extension::Control::EventType arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBReader_addDocumentCallbackControlEvents : Error processing arguments"); cobj->addDocumentCallbackControlEvents(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1107,18 +1131,18 @@ bool js_cocos2dx_builder_CCBReader_addDocumentCallbackControlEvents(JSContext *c } bool js_cocos2dx_builder_CCBReader_setCCBRootPath(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_setCCBRootPath : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBReader_setCCBRootPath : Error processing arguments"); cobj->setCCBRootPath(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1127,25 +1151,25 @@ bool js_cocos2dx_builder_CCBReader_setCCBRootPath(JSContext *cx, uint32_t argc, } bool js_cocos2dx_builder_CCBReader_addOwnerOutletNode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_addOwnerOutletNode : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBReader_addOwnerOutletNode : Error processing arguments"); cobj->addOwnerOutletNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1154,7 +1178,8 @@ bool js_cocos2dx_builder_CCBReader_addOwnerOutletNode(JSContext *cx, uint32_t ar } bool js_cocos2dx_builder_CCBReader_getOwnerCallbackNodes(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_getOwnerCallbackNodes : Invalid Native Object"); @@ -1162,7 +1187,7 @@ bool js_cocos2dx_builder_CCBReader_getOwnerCallbackNodes(JSContext *cx, uint32_t cocos2d::Vector& ret = cobj->getOwnerCallbackNodes(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1171,18 +1196,18 @@ bool js_cocos2dx_builder_CCBReader_getOwnerCallbackNodes(JSContext *cx, uint32_t } bool js_cocos2dx_builder_CCBReader_readSoundKeyframesForSeq(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_readSoundKeyframesForSeq : Invalid Native Object"); if (argc == 1) { cocosbuilder::CCBSequence* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocosbuilder::CCBSequence*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -1191,7 +1216,7 @@ bool js_cocos2dx_builder_CCBReader_readSoundKeyframesForSeq(JSContext *cx, uint3 bool ret = cobj->readSoundKeyframesForSeq(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1200,7 +1225,8 @@ bool js_cocos2dx_builder_CCBReader_readSoundKeyframesForSeq(JSContext *cx, uint3 } bool js_cocos2dx_builder_CCBReader_getCCBRootPath(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_getCCBRootPath : Invalid Native Object"); @@ -1208,7 +1234,7 @@ bool js_cocos2dx_builder_CCBReader_getCCBRootPath(JSContext *cx, uint32_t argc, const std::string& ret = cobj->getCCBRootPath(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1217,7 +1243,8 @@ bool js_cocos2dx_builder_CCBReader_getCCBRootPath(JSContext *cx, uint32_t argc, } bool js_cocos2dx_builder_CCBReader_getOwnerCallbackControlEvents(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_getOwnerCallbackControlEvents : Invalid Native Object"); @@ -1225,7 +1252,7 @@ bool js_cocos2dx_builder_CCBReader_getOwnerCallbackControlEvents(JSContext *cx, cocos2d::ValueVector& ret = cobj->getOwnerCallbackControlEvents(); jsval jsret = JSVAL_NULL; jsret = ccvaluevector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1234,7 +1261,8 @@ bool js_cocos2dx_builder_CCBReader_getOwnerCallbackControlEvents(JSContext *cx, } bool js_cocos2dx_builder_CCBReader_getOwnerOutletNodes(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_getOwnerOutletNodes : Invalid Native Object"); @@ -1242,7 +1270,7 @@ bool js_cocos2dx_builder_CCBReader_getOwnerOutletNodes(JSContext *cx, uint32_t a cocos2d::Vector& ret = cobj->getOwnerOutletNodes(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1251,7 +1279,8 @@ bool js_cocos2dx_builder_CCBReader_getOwnerOutletNodes(JSContext *cx, uint32_t a } bool js_cocos2dx_builder_CCBReader_readUTF8(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_readUTF8 : Invalid Native Object"); @@ -1259,7 +1288,7 @@ bool js_cocos2dx_builder_CCBReader_readUTF8(JSContext *cx, uint32_t argc, jsval std::string ret = cobj->readUTF8(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1268,18 +1297,18 @@ bool js_cocos2dx_builder_CCBReader_readUTF8(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_builder_CCBReader_addOwnerCallbackControlEvents(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_addOwnerCallbackControlEvents : Invalid Native Object"); if (argc == 1) { cocos2d::extension::Control::EventType arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBReader_addOwnerCallbackControlEvents : Error processing arguments"); cobj->addOwnerCallbackControlEvents(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1288,7 +1317,8 @@ bool js_cocos2dx_builder_CCBReader_addOwnerCallbackControlEvents(JSContext *cx, } bool js_cocos2dx_builder_CCBReader_getOwnerOutletNames(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_getOwnerOutletNames : Invalid Native Object"); @@ -1296,7 +1326,7 @@ bool js_cocos2dx_builder_CCBReader_getOwnerOutletNames(JSContext *cx, uint32_t a cocos2d::ValueVector ret = cobj->getOwnerOutletNames(); jsval jsret = JSVAL_NULL; jsret = ccvaluevector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1305,18 +1335,18 @@ bool js_cocos2dx_builder_CCBReader_getOwnerOutletNames(JSContext *cx, uint32_t a } bool js_cocos2dx_builder_CCBReader_readCallbackKeyframesForSeq(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_readCallbackKeyframesForSeq : Invalid Native Object"); if (argc == 1) { cocosbuilder::CCBSequence* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocosbuilder::CCBSequence*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -1325,7 +1355,7 @@ bool js_cocos2dx_builder_CCBReader_readCallbackKeyframesForSeq(JSContext *cx, ui bool ret = cobj->readCallbackKeyframesForSeq(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1334,7 +1364,8 @@ bool js_cocos2dx_builder_CCBReader_readCallbackKeyframesForSeq(JSContext *cx, ui } bool js_cocos2dx_builder_CCBReader_getAnimationManagersForNodes(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_getAnimationManagersForNodes : Invalid Native Object"); @@ -1342,7 +1373,7 @@ bool js_cocos2dx_builder_CCBReader_getAnimationManagersForNodes(JSContext *cx, u cocos2d::Vector& ret = cobj->getAnimationManagersForNodes(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1351,7 +1382,8 @@ bool js_cocos2dx_builder_CCBReader_getAnimationManagersForNodes(JSContext *cx, u } bool js_cocos2dx_builder_CCBReader_getNodesWithAnimationManagers(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocosbuilder::CCBReader* cobj = (cocosbuilder::CCBReader *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_builder_CCBReader_getNodesWithAnimationManagers : Invalid Native Object"); @@ -1359,7 +1391,7 @@ bool js_cocos2dx_builder_CCBReader_getNodesWithAnimationManagers(JSContext *cx, cocos2d::Vector& ret = cobj->getNodesWithAnimationManagers(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1368,14 +1400,14 @@ bool js_cocos2dx_builder_CCBReader_getNodesWithAnimationManagers(JSContext *cx, } bool js_cocos2dx_builder_CCBReader_setResolutionScale(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_builder_CCBReader_setResolutionScale : Error processing arguments"); cocosbuilder::CCBReader::setResolutionScale(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_builder_CCBReader_setResolutionScale : wrong number of arguments"); @@ -1384,18 +1416,18 @@ bool js_cocos2dx_builder_CCBReader_setResolutionScale(JSContext *cx, uint32_t ar bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocosbuilder::CCBReader* cobj = NULL; do { if (argc == 1) { cocosbuilder::CCBReader* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocosbuilder::CCBReader*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -1413,9 +1445,13 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocosbuilder::CCBReader"); + AddNamedObjectRoot(cx, &p->obj, "cocosbuilder::CCBReader"); } } while(0); @@ -1423,9 +1459,9 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv if (argc == 1) { cocosbuilder::NodeLoaderLibrary* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocosbuilder::NodeLoaderLibrary*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -1443,9 +1479,13 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocosbuilder::CCBReader"); + AddNamedObjectRoot(cx, &p->obj, "cocosbuilder::CCBReader"); } } while(0); @@ -1453,9 +1493,9 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv if (argc == 2) { cocosbuilder::NodeLoaderLibrary* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocosbuilder::NodeLoaderLibrary*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -1463,9 +1503,9 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv if (!ok) { ok = true; break; } cocosbuilder::CCBMemberVariableAssigner* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocosbuilder::CCBMemberVariableAssigner*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -1483,9 +1523,13 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocosbuilder::CCBReader"); + AddNamedObjectRoot(cx, &p->obj, "cocosbuilder::CCBReader"); } } while(0); @@ -1493,9 +1537,9 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv if (argc == 3) { cocosbuilder::NodeLoaderLibrary* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocosbuilder::NodeLoaderLibrary*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -1503,9 +1547,9 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv if (!ok) { ok = true; break; } cocosbuilder::CCBMemberVariableAssigner* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocosbuilder::CCBMemberVariableAssigner*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -1513,9 +1557,9 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv if (!ok) { ok = true; break; } cocosbuilder::CCBSelectorResolver* arg2; do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocosbuilder::CCBSelectorResolver*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -1533,9 +1577,13 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocosbuilder::CCBReader"); + AddNamedObjectRoot(cx, &p->obj, "cocosbuilder::CCBReader"); } } while(0); @@ -1543,9 +1591,9 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv if (argc == 4) { cocosbuilder::NodeLoaderLibrary* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocosbuilder::NodeLoaderLibrary*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -1553,9 +1601,9 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv if (!ok) { ok = true; break; } cocosbuilder::CCBMemberVariableAssigner* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocosbuilder::CCBMemberVariableAssigner*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -1563,9 +1611,9 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv if (!ok) { ok = true; break; } cocosbuilder::CCBSelectorResolver* arg2; do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocosbuilder::CCBSelectorResolver*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -1573,9 +1621,9 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv if (!ok) { ok = true; break; } cocosbuilder::NodeLoaderListener* arg3; do { - if (!argv[3].isObject()) { ok = false; break; } + if (!args.get(3).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[3]); + JSObject *tmpObj = args.get(3).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg3 = (cocosbuilder::NodeLoaderListener*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); @@ -1593,9 +1641,13 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocosbuilder::CCBReader"); + AddNamedObjectRoot(cx, &p->obj, "cocosbuilder::CCBReader"); } } while(0); @@ -1613,17 +1665,21 @@ bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocosbuilder::CCBReader"); + AddNamedObjectRoot(cx, &p->obj, "cocosbuilder::CCBReader"); } } while(0); if (cobj) { if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + args.rval().set(OBJECT_TO_JSVAL(obj)); return true; } JS_ReportError(cx, "js_cocos2dx_builder_CCBReader_constructor : wrong number of arguments"); @@ -1636,7 +1692,7 @@ void js_cocosbuilder_CCBReader_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (CCBReader)", obj); } -void js_register_cocos2dx_builder_CCBReader(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_builder_CCBReader(JSContext *cx, JS::HandleObject global) { jsb_cocosbuilder_CCBReader_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocosbuilder_CCBReader_class->name = "_Reader"; jsb_cocosbuilder_CCBReader_class->addProperty = JS_PropertyStub; @@ -1650,8 +1706,8 @@ void js_register_cocos2dx_builder_CCBReader(JSContext *cx, JSObject *global) { jsb_cocosbuilder_CCBReader_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1683,7 +1739,7 @@ void js_register_cocos2dx_builder_CCBReader(JSContext *cx, JSObject *global) { jsb_cocosbuilder_CCBReader_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocosbuilder_CCBReader_class, js_cocos2dx_builder_CCBReader_constructor, 0, // constructor properties, @@ -1709,21 +1765,12 @@ void js_register_cocos2dx_builder_CCBReader(JSContext *cx, JSObject *global) { } } -void register_all_cocos2dx_builder(JSContext* cx, JSObject* obj) { - // first, try to get the ns - JS::RootedValue nsval(cx); +void register_all_cocos2dx_builder(JSContext* cx, JS::HandleObject obj) { + // Get the ns JS::RootedObject ns(cx); - JS_GetProperty(cx, obj, "cc", &nsval); - if (nsval == JSVAL_VOID) { - ns = JS_NewObject(cx, NULL, NULL, NULL); - nsval = OBJECT_TO_JSVAL(ns); - JS_SetProperty(cx, obj, "cc", nsval); - } else { - JS_ValueToObject(cx, nsval, &ns); - } - obj = ns; + get_or_create_js_obj(cx, obj, "cc", &ns); - js_register_cocos2dx_builder_CCBAnimationManager(cx, obj); - js_register_cocos2dx_builder_CCBReader(cx, obj); + js_register_cocos2dx_builder_CCBAnimationManager(cx, ns); + js_register_cocos2dx_builder_CCBReader(cx, ns); } diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_builder_auto.hpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_builder_auto.hpp index 949f5e9a89..d64e92d1bf 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_builder_auto.hpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_builder_auto.hpp @@ -10,8 +10,8 @@ extern JSObject *jsb_cocosbuilder_CCBAnimationManager_prototype; bool js_cocos2dx_builder_CCBAnimationManager_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_builder_CCBAnimationManager_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_builder_CCBAnimationManager(JSContext *cx, JSObject *global); -void register_all_cocos2dx_builder(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_builder_CCBAnimationManager(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_builder(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_builder_CCBAnimationManager_moveAnimationsFromNode(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_builder_CCBAnimationManager_setAutoPlaySequenceId(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackNames(JSContext *cx, uint32_t argc, jsval *vp); @@ -56,8 +56,8 @@ extern JSObject *jsb_cocosbuilder_CCBReader_prototype; bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_builder_CCBReader_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_builder_CCBReader(JSContext *cx, JSObject *global); -void register_all_cocos2dx_builder(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_builder_CCBReader(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_builder(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_builder_CCBReader_getAnimationManager(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_builder_CCBReader_setAnimationManager(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_builder_CCBReader_addOwnerOutletName(JSContext *cx, uint32_t argc, jsval *vp); diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_extension_auto.cpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_extension_auto.cpp index 53ad900ccb..1e78c64812 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_extension_auto.cpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_extension_auto.cpp @@ -4,10 +4,11 @@ template static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedValue initializing(cx); bool isNewValid = true; - JSObject* global = ScriptingCore::getInstance()->getGlobalObject(); - isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && JSVAL_TO_BOOLEAN(initializing); + JS::RootedObject global(cx, ScriptingCore::getInstance()->getGlobalObject()); + isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && initializing.toBoolean(); if (isNewValid) { TypeTest t; @@ -18,8 +19,11 @@ static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *_tmp = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp)); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject _tmp(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + + args.rval().set(OBJECT_TO_JSVAL(_tmp)); return true; } @@ -31,9 +35,10 @@ static bool empty_constructor(JSContext *cx, uint32_t argc, jsval *vp) { return false; } -static bool js_is_native_obj(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) { - vp.set(BOOLEAN_TO_JSVAL(true)); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setBoolean(true); return true; } JSClass *jsb_cocos2d_extension_Control_class; @@ -41,18 +46,18 @@ JSObject *jsb_cocos2d_extension_Control_prototype; bool js_cocos2dx_extension_Control_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Control_setEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_Control_setEnabled : Error processing arguments"); cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -61,7 +66,8 @@ bool js_cocos2dx_extension_Control_setEnabled(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_extension_Control_getState(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Control_getState : Invalid Native Object"); @@ -69,7 +75,7 @@ bool js_cocos2dx_extension_Control_getState(JSContext *cx, uint32_t argc, jsval int ret = (int)cobj->getState(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -78,18 +84,18 @@ bool js_cocos2dx_extension_Control_getState(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_extension_Control_sendActionsForControlEvents(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Control_sendActionsForControlEvents : Invalid Native Object"); if (argc == 1) { cocos2d::extension::Control::EventType arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_Control_sendActionsForControlEvents : Error processing arguments"); cobj->sendActionsForControlEvents(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -98,18 +104,18 @@ bool js_cocos2dx_extension_Control_sendActionsForControlEvents(JSContext *cx, ui } bool js_cocos2dx_extension_Control_setSelected(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Control_setSelected : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_Control_setSelected : Error processing arguments"); cobj->setSelected(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -118,7 +124,8 @@ bool js_cocos2dx_extension_Control_setSelected(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_extension_Control_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Control_isEnabled : Invalid Native Object"); @@ -126,7 +133,7 @@ bool js_cocos2dx_extension_Control_isEnabled(JSContext *cx, uint32_t argc, jsval bool ret = cobj->isEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -135,13 +142,14 @@ bool js_cocos2dx_extension_Control_isEnabled(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_extension_Control_needsLayout(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Control_needsLayout : Invalid Native Object"); if (argc == 0) { cobj->needsLayout(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -150,7 +158,8 @@ bool js_cocos2dx_extension_Control_needsLayout(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_extension_Control_hasVisibleParents(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Control_hasVisibleParents : Invalid Native Object"); @@ -158,7 +167,7 @@ bool js_cocos2dx_extension_Control_hasVisibleParents(JSContext *cx, uint32_t arg bool ret = cobj->hasVisibleParents(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -167,7 +176,8 @@ bool js_cocos2dx_extension_Control_hasVisibleParents(JSContext *cx, uint32_t arg } bool js_cocos2dx_extension_Control_isSelected(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Control_isSelected : Invalid Native Object"); @@ -175,7 +185,7 @@ bool js_cocos2dx_extension_Control_isSelected(JSContext *cx, uint32_t argc, jsva bool ret = cobj->isSelected(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -184,18 +194,18 @@ bool js_cocos2dx_extension_Control_isSelected(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_extension_Control_isTouchInside(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Control_isTouchInside : Invalid Native Object"); if (argc == 1) { cocos2d::Touch* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Touch*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -204,7 +214,7 @@ bool js_cocos2dx_extension_Control_isTouchInside(JSContext *cx, uint32_t argc, j bool ret = cobj->isTouchInside(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -213,18 +223,18 @@ bool js_cocos2dx_extension_Control_isTouchInside(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_extension_Control_setHighlighted(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Control_setHighlighted : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_Control_setHighlighted : Error processing arguments"); cobj->setHighlighted(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -233,18 +243,18 @@ bool js_cocos2dx_extension_Control_setHighlighted(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_Control_getTouchLocation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Control_getTouchLocation : Invalid Native Object"); if (argc == 1) { cocos2d::Touch* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Touch*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -253,7 +263,7 @@ bool js_cocos2dx_extension_Control_getTouchLocation(JSContext *cx, uint32_t argc cocos2d::Vec2 ret = cobj->getTouchLocation(arg0); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -262,7 +272,8 @@ bool js_cocos2dx_extension_Control_getTouchLocation(JSContext *cx, uint32_t argc } bool js_cocos2dx_extension_Control_isHighlighted(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Control_isHighlighted : Invalid Native Object"); @@ -270,7 +281,7 @@ bool js_cocos2dx_extension_Control_isHighlighted(JSContext *cx, uint32_t argc, j bool ret = cobj->isHighlighted(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -279,6 +290,7 @@ bool js_cocos2dx_extension_Control_isHighlighted(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_extension_Control_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::extension::Control* ret = cocos2d::extension::Control::create(); jsval jsret = JSVAL_NULL; @@ -290,7 +302,7 @@ bool js_cocos2dx_extension_Control_create(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_Control_create : wrong number of arguments"); @@ -299,7 +311,7 @@ bool js_cocos2dx_extension_Control_create(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_extension_Control_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::extension::Control* cobj = new (std::nothrow) cocos2d::extension::Control(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -313,13 +325,16 @@ bool js_cocos2dx_extension_Control_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::Control"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::Control"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -330,7 +345,7 @@ void js_cocos2d_extension_Control_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Control)", obj); } -void js_register_cocos2dx_extension_Control(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_Control(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_Control_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_Control_class->name = "Control"; jsb_cocos2d_extension_Control_class->addProperty = JS_PropertyStub; @@ -344,8 +359,8 @@ void js_register_cocos2dx_extension_Control(JSContext *cx, JSObject *global) { jsb_cocos2d_extension_Control_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -371,7 +386,7 @@ void js_register_cocos2dx_extension_Control(JSContext *cx, JSObject *global) { jsb_cocos2d_extension_Control_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Layer_prototype, + JS::RootedObject(cx, jsb_cocos2d_Layer_prototype), jsb_cocos2d_extension_Control_class, js_cocos2dx_extension_Control_constructor, 0, // constructor properties, @@ -402,7 +417,8 @@ JSObject *jsb_cocos2d_extension_ControlButton_prototype; bool js_cocos2dx_extension_ControlButton_isPushed(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_isPushed : Invalid Native Object"); @@ -410,38 +426,18 @@ bool js_cocos2dx_extension_ControlButton_isPushed(JSContext *cx, uint32_t argc, bool ret = cobj->isPushed(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_isPushed : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlButton_setSelected(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setSelected : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setSelected : Error processing arguments"); - cobj->setSelected(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_setSelected : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_extension_ControlButton_setTitleLabelForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setTitleLabelForState : Invalid Native Object"); @@ -449,17 +445,17 @@ bool js_cocos2dx_extension_ControlButton_setTitleLabelForState(JSContext *cx, ui cocos2d::Node* arg0; cocos2d::extension::Control::State arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setTitleLabelForState : Error processing arguments"); cobj->setTitleLabelForState(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -468,80 +464,40 @@ bool js_cocos2dx_extension_ControlButton_setTitleLabelForState(JSContext *cx, ui } bool js_cocos2dx_extension_ControlButton_setAdjustBackgroundImage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setAdjustBackgroundImage : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setAdjustBackgroundImage : Error processing arguments"); cobj->setAdjustBackgroundImage(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_setAdjustBackgroundImage : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlButton_setHighlighted(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setHighlighted : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setHighlighted : Error processing arguments"); - cobj->setHighlighted(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_setHighlighted : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_extension_ControlButton_setZoomOnTouchDown(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setZoomOnTouchDown : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setZoomOnTouchDown : Error processing arguments"); - cobj->setZoomOnTouchDown(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_setZoomOnTouchDown : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_extension_ControlButton_setTitleForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setTitleForState : Invalid Native Object"); if (argc == 2) { std::string arg0; cocos2d::extension::Control::State arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setTitleForState : Error processing arguments"); cobj->setTitleForState(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -550,18 +506,18 @@ bool js_cocos2dx_extension_ControlButton_setTitleForState(JSContext *cx, uint32_ } bool js_cocos2dx_extension_ControlButton_setLabelAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setLabelAnchorPoint : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setLabelAnchorPoint : Error processing arguments"); cobj->setLabelAnchorPoint(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -570,7 +526,8 @@ bool js_cocos2dx_extension_ControlButton_setLabelAnchorPoint(JSContext *cx, uint } bool js_cocos2dx_extension_ControlButton_getLabelAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getLabelAnchorPoint : Invalid Native Object"); @@ -578,7 +535,7 @@ bool js_cocos2dx_extension_ControlButton_getLabelAnchorPoint(JSContext *cx, uint const cocos2d::Vec2& ret = cobj->getLabelAnchorPoint(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -587,18 +544,18 @@ bool js_cocos2dx_extension_ControlButton_getLabelAnchorPoint(JSContext *cx, uint } bool js_cocos2dx_extension_ControlButton_initWithBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_initWithBackgroundSprite : Invalid Native Object"); if (argc == 1) { cocos2d::ui::Scale9Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -607,7 +564,7 @@ bool js_cocos2dx_extension_ControlButton_initWithBackgroundSprite(JSContext *cx, bool ret = cobj->initWithBackgroundSprite(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -616,20 +573,20 @@ bool js_cocos2dx_extension_ControlButton_initWithBackgroundSprite(JSContext *cx, } bool js_cocos2dx_extension_ControlButton_getTitleTTFSizeForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getTitleTTFSizeForState : Invalid Native Object"); if (argc == 1) { cocos2d::extension::Control::State arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_getTitleTTFSizeForState : Error processing arguments"); double ret = cobj->getTitleTTFSizeForState(arg0); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -638,20 +595,20 @@ bool js_cocos2dx_extension_ControlButton_getTitleTTFSizeForState(JSContext *cx, } bool js_cocos2dx_extension_ControlButton_setTitleTTFForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setTitleTTFForState : Invalid Native Object"); if (argc == 2) { std::string arg0; cocos2d::extension::Control::State arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setTitleTTFForState : Error processing arguments"); cobj->setTitleTTFForState(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -660,20 +617,20 @@ bool js_cocos2dx_extension_ControlButton_setTitleTTFForState(JSContext *cx, uint } bool js_cocos2dx_extension_ControlButton_setTitleTTFSizeForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setTitleTTFSizeForState : Invalid Native Object"); if (argc == 2) { double arg0; cocos2d::extension::Control::State arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setTitleTTFSizeForState : Error processing arguments"); cobj->setTitleTTFSizeForState(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -682,25 +639,25 @@ bool js_cocos2dx_extension_ControlButton_setTitleTTFSizeForState(JSContext *cx, } bool js_cocos2dx_extension_ControlButton_setTitleLabel(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setTitleLabel : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setTitleLabel : Error processing arguments"); cobj->setTitleLabel(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -709,18 +666,18 @@ bool js_cocos2dx_extension_ControlButton_setTitleLabel(JSContext *cx, uint32_t a } bool js_cocos2dx_extension_ControlButton_setPreferredSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setPreferredSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setPreferredSize : Error processing arguments"); cobj->setPreferredSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -729,7 +686,8 @@ bool js_cocos2dx_extension_ControlButton_setPreferredSize(JSContext *cx, uint32_ } bool js_cocos2dx_extension_ControlButton_getCurrentTitleColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getCurrentTitleColor : Invalid Native Object"); @@ -737,54 +695,54 @@ bool js_cocos2dx_extension_ControlButton_getCurrentTitleColor(JSContext *cx, uin const cocos2d::Color3B& ret = cobj->getCurrentTitleColor(); jsval jsret = JSVAL_NULL; jsret = cccolor3b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_getCurrentTitleColor : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlButton_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlButton_setZoomOnTouchDown(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setEnabled : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setZoomOnTouchDown : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setEnabled : Error processing arguments"); - cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setZoomOnTouchDown : Error processing arguments"); + cobj->setZoomOnTouchDown(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_setEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_setZoomOnTouchDown : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_extension_ControlButton_setBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setBackgroundSprite : Invalid Native Object"); if (argc == 1) { cocos2d::ui::Scale9Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setBackgroundSprite : Error processing arguments"); cobj->setBackgroundSprite(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -793,15 +751,15 @@ bool js_cocos2dx_extension_ControlButton_setBackgroundSprite(JSContext *cx, uint } bool js_cocos2dx_extension_ControlButton_getBackgroundSpriteForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getBackgroundSpriteForState : Invalid Native Object"); if (argc == 1) { cocos2d::extension::Control::State arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_getBackgroundSpriteForState : Error processing arguments"); cocos2d::ui::Scale9Sprite* ret = cobj->getBackgroundSpriteForState(arg0); jsval jsret = JSVAL_NULL; @@ -813,7 +771,7 @@ bool js_cocos2dx_extension_ControlButton_getBackgroundSpriteForState(JSContext * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -822,7 +780,8 @@ bool js_cocos2dx_extension_ControlButton_getBackgroundSpriteForState(JSContext * } bool js_cocos2dx_extension_ControlButton_getHorizontalOrigin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getHorizontalOrigin : Invalid Native Object"); @@ -830,33 +789,18 @@ bool js_cocos2dx_extension_ControlButton_getHorizontalOrigin(JSContext *cx, uint int ret = cobj->getHorizontalOrigin(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_getHorizontalOrigin : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlButton_needsLayout(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_needsLayout : Invalid Native Object"); - if (argc == 0) { - cobj->needsLayout(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_needsLayout : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_extension_ControlButton_initWithTitleAndFontNameAndFontSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_initWithTitleAndFontNameAndFontSize : Invalid Native Object"); @@ -864,57 +808,46 @@ bool js_cocos2dx_extension_ControlButton_initWithTitleAndFontNameAndFontSize(JSC std::string arg0; std::string arg1; double arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_initWithTitleAndFontNameAndFontSize : Error processing arguments"); bool ret = cobj->initWithTitleAndFontNameAndFontSize(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_initWithTitleAndFontNameAndFontSize : wrong number of arguments: %d, was expecting %d", argc, 3); return false; } -bool js_cocos2dx_extension_ControlButton_getCurrentTitle(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlButton_setTitleBMFontForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - - JSObject *obj = NULL; - cocos2d::extension::ControlButton* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getCurrentTitle : Invalid Native Object"); - do { - if (argc == 0) { - std::string ret = cobj->getCurrentTitle(); - jsval jsret = JSVAL_NULL; - jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while(0); - - do { - if (argc == 0) { - const std::string& ret = cobj->getCurrentTitle(); - jsval jsret = JSVAL_NULL; - jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while(0); + cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setTitleBMFontForState : Invalid Native Object"); + if (argc == 2) { + std::string arg0; + cocos2d::extension::Control::State arg1; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setTitleBMFontForState : Error processing arguments"); + cobj->setTitleBMFontForState(arg0, arg1); + args.rval().setUndefined(); + return true; + } - JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_getCurrentTitle : wrong number of arguments"); + JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_setTitleBMFontForState : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } bool js_cocos2dx_extension_ControlButton_getScaleRatio(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getScaleRatio : Invalid Native Object"); @@ -922,7 +855,7 @@ bool js_cocos2dx_extension_ControlButton_getScaleRatio(JSContext *cx, uint32_t a double ret = cobj->getScaleRatio(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -931,20 +864,20 @@ bool js_cocos2dx_extension_ControlButton_getScaleRatio(JSContext *cx, uint32_t a } bool js_cocos2dx_extension_ControlButton_getTitleTTFForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getTitleTTFForState : Invalid Native Object"); if (argc == 1) { cocos2d::extension::Control::State arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_getTitleTTFForState : Error processing arguments"); const std::string& ret = cobj->getTitleTTFForState(arg0); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -953,7 +886,8 @@ bool js_cocos2dx_extension_ControlButton_getTitleTTFForState(JSContext *cx, uint } bool js_cocos2dx_extension_ControlButton_getBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getBackgroundSprite : Invalid Native Object"); @@ -968,7 +902,7 @@ bool js_cocos2dx_extension_ControlButton_getBackgroundSprite(JSContext *cx, uint jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -977,20 +911,20 @@ bool js_cocos2dx_extension_ControlButton_getBackgroundSprite(JSContext *cx, uint } bool js_cocos2dx_extension_ControlButton_getTitleColorForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getTitleColorForState : Invalid Native Object"); if (argc == 1) { cocos2d::extension::Control::State arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_getTitleColorForState : Error processing arguments"); cocos2d::Color3B ret = cobj->getTitleColorForState(arg0); jsval jsret = JSVAL_NULL; jsret = cccolor3b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -999,20 +933,20 @@ bool js_cocos2dx_extension_ControlButton_getTitleColorForState(JSContext *cx, ui } bool js_cocos2dx_extension_ControlButton_setTitleColorForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setTitleColorForState : Invalid Native Object"); if (argc == 2) { cocos2d::Color3B arg0; cocos2d::extension::Control::State arg1; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setTitleColorForState : Error processing arguments"); cobj->setTitleColorForState(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1021,7 +955,8 @@ bool js_cocos2dx_extension_ControlButton_setTitleColorForState(JSContext *cx, ui } bool js_cocos2dx_extension_ControlButton_doesAdjustBackgroundImage(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_doesAdjustBackgroundImage : Invalid Native Object"); @@ -1029,7 +964,7 @@ bool js_cocos2dx_extension_ControlButton_doesAdjustBackgroundImage(JSContext *cx bool ret = cobj->doesAdjustBackgroundImage(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1038,9 +973,9 @@ bool js_cocos2dx_extension_ControlButton_doesAdjustBackgroundImage(JSContext *cx } bool js_cocos2dx_extension_ControlButton_setBackgroundSpriteFrameForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setBackgroundSpriteFrameForState : Invalid Native Object"); @@ -1048,17 +983,17 @@ bool js_cocos2dx_extension_ControlButton_setBackgroundSpriteFrameForState(JSCont cocos2d::SpriteFrame* arg0; cocos2d::extension::Control::State arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setBackgroundSpriteFrameForState : Error processing arguments"); cobj->setBackgroundSpriteFrameForState(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1067,9 +1002,9 @@ bool js_cocos2dx_extension_ControlButton_setBackgroundSpriteFrameForState(JSCont } bool js_cocos2dx_extension_ControlButton_setBackgroundSpriteForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setBackgroundSpriteForState : Invalid Native Object"); @@ -1077,17 +1012,17 @@ bool js_cocos2dx_extension_ControlButton_setBackgroundSpriteForState(JSContext * cocos2d::ui::Scale9Sprite* arg0; cocos2d::extension::Control::State arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setBackgroundSpriteForState : Error processing arguments"); cobj->setBackgroundSpriteForState(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1096,65 +1031,50 @@ bool js_cocos2dx_extension_ControlButton_setBackgroundSpriteForState(JSContext * } bool js_cocos2dx_extension_ControlButton_setScaleRatio(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setScaleRatio : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setScaleRatio : Error processing arguments"); cobj->setScaleRatio(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_setScaleRatio : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlButton_getTitleBMFontForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite : Invalid Native Object"); - if (argc == 2) { - cocos2d::Node* arg0; - cocos2d::ui::Scale9Sprite* arg1; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - do { - if (!argv[1].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg1 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite : Error processing arguments"); - bool ret = cobj->initWithLabelAndBackgroundSprite(arg0, arg1); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getTitleBMFontForState : Invalid Native Object"); + if (argc == 1) { + cocos2d::extension::Control::State arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_getTitleBMFontForState : Error processing arguments"); + const std::string& ret = cobj->getTitleBMFontForState(arg0); jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = std_string_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite : wrong number of arguments: %d, was expecting %d", argc, 2); + JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_getTitleBMFontForState : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_extension_ControlButton_getTitleLabel(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getTitleLabel : Invalid Native Object"); @@ -1169,7 +1089,7 @@ bool js_cocos2dx_extension_ControlButton_getTitleLabel(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1178,7 +1098,8 @@ bool js_cocos2dx_extension_ControlButton_getTitleLabel(JSContext *cx, uint32_t a } bool js_cocos2dx_extension_ControlButton_getPreferredSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getPreferredSize : Invalid Native Object"); @@ -1186,7 +1107,7 @@ bool js_cocos2dx_extension_ControlButton_getPreferredSize(JSContext *cx, uint32_ const cocos2d::Size& ret = cobj->getPreferredSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1195,7 +1116,8 @@ bool js_cocos2dx_extension_ControlButton_getPreferredSize(JSContext *cx, uint32_ } bool js_cocos2dx_extension_ControlButton_getVerticalMargin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getVerticalMargin : Invalid Native Object"); @@ -1203,7 +1125,7 @@ bool js_cocos2dx_extension_ControlButton_getVerticalMargin(JSContext *cx, uint32 int ret = cobj->getVerticalMargin(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1212,15 +1134,15 @@ bool js_cocos2dx_extension_ControlButton_getVerticalMargin(JSContext *cx, uint32 } bool js_cocos2dx_extension_ControlButton_getTitleLabelForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getTitleLabelForState : Invalid Native Object"); if (argc == 1) { cocos2d::extension::Control::State arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_getTitleLabelForState : Error processing arguments"); cocos2d::Node* ret = cobj->getTitleLabelForState(arg0); jsval jsret = JSVAL_NULL; @@ -1232,7 +1154,7 @@ bool js_cocos2dx_extension_ControlButton_getTitleLabelForState(JSContext *cx, ui jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1241,73 +1163,102 @@ bool js_cocos2dx_extension_ControlButton_getTitleLabelForState(JSContext *cx, ui } bool js_cocos2dx_extension_ControlButton_setMargins(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setMargins : Invalid Native Object"); if (argc == 2) { int arg0; int arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setMargins : Error processing arguments"); cobj->setMargins(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_setMargins : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_extension_ControlButton_setTitleBMFontForState(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlButton_getCurrentTitle(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + + JS::RootedObject obj(cx); + cocos2d::extension::ControlButton* cobj = NULL; + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_setTitleBMFontForState : Invalid Native Object"); - if (argc == 2) { - std::string arg0; - cocos2d::extension::Control::State arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setTitleBMFontForState : Error processing arguments"); - cobj->setTitleBMFontForState(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } + cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getCurrentTitle : Invalid Native Object"); + do { + if (argc == 0) { + std::string ret = cobj->getCurrentTitle(); + jsval jsret = JSVAL_NULL; + jsret = std_string_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + } while(0); - JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_setTitleBMFontForState : wrong number of arguments: %d, was expecting %d", argc, 2); + do { + if (argc == 0) { + const std::string& ret = cobj->getCurrentTitle(); + jsval jsret = JSVAL_NULL; + jsret = std_string_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_getCurrentTitle : wrong number of arguments"); return false; } -bool js_cocos2dx_extension_ControlButton_getTitleBMFontForState(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getTitleBMFontForState : Invalid Native Object"); - if (argc == 1) { - cocos2d::extension::Control::State arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_getTitleBMFontForState : Error processing arguments"); - const std::string& ret = cobj->getTitleBMFontForState(arg0); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite : Invalid Native Object"); + if (argc == 2) { + cocos2d::Node* arg0; + cocos2d::ui::Scale9Sprite* arg1; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + do { + if (!args.get(1).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(1).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg1 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite : Error processing arguments"); + bool ret = cobj->initWithLabelAndBackgroundSprite(arg0, arg1); jsval jsret = JSVAL_NULL; - jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_getTitleBMFontForState : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } bool js_cocos2dx_extension_ControlButton_getZoomOnTouchDown(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getZoomOnTouchDown : Invalid Native Object"); @@ -1315,7 +1266,7 @@ bool js_cocos2dx_extension_ControlButton_getZoomOnTouchDown(JSContext *cx, uint3 bool ret = cobj->getZoomOnTouchDown(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1324,20 +1275,20 @@ bool js_cocos2dx_extension_ControlButton_getZoomOnTouchDown(JSContext *cx, uint3 } bool js_cocos2dx_extension_ControlButton_getTitleForState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_getTitleForState : Invalid Native Object"); if (argc == 1) { cocos2d::extension::Control::State arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_getTitleForState : Error processing arguments"); std::string ret = cobj->getTitleForState(arg0); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1346,16 +1297,16 @@ bool js_cocos2dx_extension_ControlButton_getTitleForState(JSContext *cx, uint32_ } bool js_cocos2dx_extension_ControlButton_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { cocos2d::ui::Scale9Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -1371,7 +1322,7 @@ bool js_cocos2dx_extension_ControlButton_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -1388,7 +1339,7 @@ bool js_cocos2dx_extension_ControlButton_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -1397,9 +1348,9 @@ bool js_cocos2dx_extension_ControlButton_create(JSContext *cx, uint32_t argc, js if (argc == 2) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -1407,9 +1358,9 @@ bool js_cocos2dx_extension_ControlButton_create(JSContext *cx, uint32_t argc, js if (!ok) { ok = true; break; } cocos2d::ui::Scale9Sprite* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -1425,7 +1376,7 @@ bool js_cocos2dx_extension_ControlButton_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -1433,13 +1384,13 @@ bool js_cocos2dx_extension_ControlButton_create(JSContext *cx, uint32_t argc, js do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } cocos2d::extension::ControlButton* ret = cocos2d::extension::ControlButton::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -1451,7 +1402,7 @@ bool js_cocos2dx_extension_ControlButton_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -1460,7 +1411,7 @@ bool js_cocos2dx_extension_ControlButton_create(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_extension_ControlButton_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::extension::ControlButton* cobj = new (std::nothrow) cocos2d::extension::ControlButton(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1474,13 +1425,16 @@ bool js_cocos2dx_extension_ControlButton_constructor(JSContext *cx, uint32_t arg CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlButton"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlButton"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -1493,21 +1447,21 @@ void js_cocos2d_extension_ControlButton_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_extension_ControlButton_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::extension::ControlButton *nobj = new (std::nothrow) cocos2d::extension::ControlButton(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlButton"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlButton"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_extension_ControlButton(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_ControlButton(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_ControlButton_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_ControlButton_class->name = "ControlButton"; jsb_cocos2d_extension_ControlButton_class->addProperty = JS_PropertyStub; @@ -1521,17 +1475,14 @@ void js_register_cocos2dx_extension_ControlButton(JSContext *cx, JSObject *globa jsb_cocos2d_extension_ControlButton_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("isPushed", js_cocos2dx_extension_ControlButton_isPushed, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setSelected", js_cocos2dx_extension_ControlButton_setSelected, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setTitleLabelForState", js_cocos2dx_extension_ControlButton_setTitleLabelForState, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setAdjustBackgroundImage", js_cocos2dx_extension_ControlButton_setAdjustBackgroundImage, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setHighlighted", js_cocos2dx_extension_ControlButton_setHighlighted, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setZoomOnTouchDown", js_cocos2dx_extension_ControlButton_setZoomOnTouchDown, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setTitleForState", js_cocos2dx_extension_ControlButton_setTitleForState, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setLabelAnchorPoint", js_cocos2dx_extension_ControlButton_setLabelAnchorPoint, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getLabelAnchorPoint", js_cocos2dx_extension_ControlButton_getLabelAnchorPoint, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -1542,13 +1493,12 @@ void js_register_cocos2dx_extension_ControlButton(JSContext *cx, JSObject *globa JS_FN("setTitleLabel", js_cocos2dx_extension_ControlButton_setTitleLabel, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setPreferredSize", js_cocos2dx_extension_ControlButton_setPreferredSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getCurrentTitleColor", js_cocos2dx_extension_ControlButton_getCurrentTitleColor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setEnabled", js_cocos2dx_extension_ControlButton_setEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setZoomOnTouchDown", js_cocos2dx_extension_ControlButton_setZoomOnTouchDown, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setBackgroundSprite", js_cocos2dx_extension_ControlButton_setBackgroundSprite, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getBackgroundSpriteForState", js_cocos2dx_extension_ControlButton_getBackgroundSpriteForState, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getHorizontalOrigin", js_cocos2dx_extension_ControlButton_getHorizontalOrigin, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("needsLayout", js_cocos2dx_extension_ControlButton_needsLayout, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("initWithTitleAndFontNameAndFontSize", js_cocos2dx_extension_ControlButton_initWithTitleAndFontNameAndFontSize, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getCurrentTitle", js_cocos2dx_extension_ControlButton_getCurrentTitle, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setTitleBMFontForState", js_cocos2dx_extension_ControlButton_setTitleBMFontForState, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getScaleRatio", js_cocos2dx_extension_ControlButton_getScaleRatio, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getTitleTTFForState", js_cocos2dx_extension_ControlButton_getTitleTTFForState, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getBackgroundSprite", js_cocos2dx_extension_ControlButton_getBackgroundSprite, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -1558,14 +1508,14 @@ void js_register_cocos2dx_extension_ControlButton(JSContext *cx, JSObject *globa JS_FN("setBackgroundSpriteFrameForState", js_cocos2dx_extension_ControlButton_setBackgroundSpriteFrameForState, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setBackgroundSpriteForState", js_cocos2dx_extension_ControlButton_setBackgroundSpriteForState, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setScaleRatio", js_cocos2dx_extension_ControlButton_setScaleRatio, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("initWithLabelAndBackgroundSprite", js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getTitleBMFontForState", js_cocos2dx_extension_ControlButton_getTitleBMFontForState, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getTitleLabel", js_cocos2dx_extension_ControlButton_getTitleLabel, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getPreferredSize", js_cocos2dx_extension_ControlButton_getPreferredSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getVerticalMargin", js_cocos2dx_extension_ControlButton_getVerticalMargin, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getTitleLabelForState", js_cocos2dx_extension_ControlButton_getTitleLabelForState, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setMargins", js_cocos2dx_extension_ControlButton_setMargins, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setTitleBMFontForState", js_cocos2dx_extension_ControlButton_setTitleBMFontForState, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getTitleBMFontForState", js_cocos2dx_extension_ControlButton_getTitleBMFontForState, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getCurrentTitle", js_cocos2dx_extension_ControlButton_getCurrentTitle, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithLabelAndBackgroundSprite", js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getZoomOnTouchDown", js_cocos2dx_extension_ControlButton_getZoomOnTouchDown, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getTitleForState", js_cocos2dx_extension_ControlButton_getTitleForState, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2d_extension_ControlButton_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -1579,7 +1529,7 @@ void js_register_cocos2dx_extension_ControlButton(JSContext *cx, JSObject *globa jsb_cocos2d_extension_ControlButton_prototype = JS_InitClass( cx, global, - jsb_cocos2d_extension_Control_prototype, + JS::RootedObject(cx, jsb_cocos2d_extension_Control_prototype), jsb_cocos2d_extension_ControlButton_class, js_cocos2dx_extension_ControlButton_constructor, 0, // constructor properties, @@ -1608,31 +1558,11 @@ void js_register_cocos2dx_extension_ControlButton(JSContext *cx, JSObject *globa JSClass *jsb_cocos2d_extension_ControlHuePicker_class; JSObject *jsb_cocos2d_extension_ControlHuePicker_prototype; -bool js_cocos2dx_extension_ControlHuePicker_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlHuePicker* cobj = (cocos2d::extension::ControlHuePicker *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlHuePicker_setEnabled : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlHuePicker_setEnabled : Error processing arguments"); - cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlHuePicker_setEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_extension_ControlHuePicker_initWithTargetAndPos(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlHuePicker* cobj = (cocos2d::extension::ControlHuePicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlHuePicker_initWithTargetAndPos : Invalid Native Object"); @@ -1640,19 +1570,19 @@ bool js_cocos2dx_extension_ControlHuePicker_initWithTargetAndPos(JSContext *cx, cocos2d::Node* arg0; cocos2d::Vec2 arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlHuePicker_initWithTargetAndPos : Error processing arguments"); bool ret = cobj->initWithTargetAndPos(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1661,18 +1591,18 @@ bool js_cocos2dx_extension_ControlHuePicker_initWithTargetAndPos(JSContext *cx, } bool js_cocos2dx_extension_ControlHuePicker_setHue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlHuePicker* cobj = (cocos2d::extension::ControlHuePicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlHuePicker_setHue : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlHuePicker_setHue : Error processing arguments"); cobj->setHue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1681,7 +1611,8 @@ bool js_cocos2dx_extension_ControlHuePicker_setHue(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ControlHuePicker_getStartPos(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlHuePicker* cobj = (cocos2d::extension::ControlHuePicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlHuePicker_getStartPos : Invalid Native Object"); @@ -1689,7 +1620,7 @@ bool js_cocos2dx_extension_ControlHuePicker_getStartPos(JSContext *cx, uint32_t cocos2d::Vec2 ret = cobj->getStartPos(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1698,7 +1629,8 @@ bool js_cocos2dx_extension_ControlHuePicker_getStartPos(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ControlHuePicker_getHue(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlHuePicker* cobj = (cocos2d::extension::ControlHuePicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlHuePicker_getHue : Invalid Native Object"); @@ -1706,7 +1638,7 @@ bool js_cocos2dx_extension_ControlHuePicker_getHue(JSContext *cx, uint32_t argc, double ret = cobj->getHue(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1715,7 +1647,8 @@ bool js_cocos2dx_extension_ControlHuePicker_getHue(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ControlHuePicker_getSlider(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlHuePicker* cobj = (cocos2d::extension::ControlHuePicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlHuePicker_getSlider : Invalid Native Object"); @@ -1730,7 +1663,7 @@ bool js_cocos2dx_extension_ControlHuePicker_getSlider(JSContext *cx, uint32_t ar jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1739,25 +1672,25 @@ bool js_cocos2dx_extension_ControlHuePicker_getSlider(JSContext *cx, uint32_t ar } bool js_cocos2dx_extension_ControlHuePicker_setBackground(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlHuePicker* cobj = (cocos2d::extension::ControlHuePicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlHuePicker_setBackground : Invalid Native Object"); if (argc == 1) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlHuePicker_setBackground : Error processing arguments"); cobj->setBackground(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1766,18 +1699,18 @@ bool js_cocos2dx_extension_ControlHuePicker_setBackground(JSContext *cx, uint32_ } bool js_cocos2dx_extension_ControlHuePicker_setHuePercentage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlHuePicker* cobj = (cocos2d::extension::ControlHuePicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlHuePicker_setHuePercentage : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlHuePicker_setHuePercentage : Error processing arguments"); cobj->setHuePercentage(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1786,7 +1719,8 @@ bool js_cocos2dx_extension_ControlHuePicker_setHuePercentage(JSContext *cx, uint } bool js_cocos2dx_extension_ControlHuePicker_getBackground(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlHuePicker* cobj = (cocos2d::extension::ControlHuePicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlHuePicker_getBackground : Invalid Native Object"); @@ -1801,7 +1735,7 @@ bool js_cocos2dx_extension_ControlHuePicker_getBackground(JSContext *cx, uint32_ jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1810,7 +1744,8 @@ bool js_cocos2dx_extension_ControlHuePicker_getBackground(JSContext *cx, uint32_ } bool js_cocos2dx_extension_ControlHuePicker_getHuePercentage(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlHuePicker* cobj = (cocos2d::extension::ControlHuePicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlHuePicker_getHuePercentage : Invalid Native Object"); @@ -1818,7 +1753,7 @@ bool js_cocos2dx_extension_ControlHuePicker_getHuePercentage(JSContext *cx, uint double ret = cobj->getHuePercentage(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1827,25 +1762,25 @@ bool js_cocos2dx_extension_ControlHuePicker_getHuePercentage(JSContext *cx, uint } bool js_cocos2dx_extension_ControlHuePicker_setSlider(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlHuePicker* cobj = (cocos2d::extension::ControlHuePicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlHuePicker_setSlider : Invalid Native Object"); if (argc == 1) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlHuePicker_setSlider : Error processing arguments"); cobj->setSlider(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1854,20 +1789,20 @@ bool js_cocos2dx_extension_ControlHuePicker_setSlider(JSContext *cx, uint32_t ar } bool js_cocos2dx_extension_ControlHuePicker_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::Node* arg0; cocos2d::Vec2 arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlHuePicker_create : Error processing arguments"); cocos2d::extension::ControlHuePicker* ret = cocos2d::extension::ControlHuePicker::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -1879,7 +1814,7 @@ bool js_cocos2dx_extension_ControlHuePicker_create(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlHuePicker_create : wrong number of arguments"); @@ -1888,7 +1823,7 @@ bool js_cocos2dx_extension_ControlHuePicker_create(JSContext *cx, uint32_t argc, bool js_cocos2dx_extension_ControlHuePicker_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::extension::ControlHuePicker* cobj = new (std::nothrow) cocos2d::extension::ControlHuePicker(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1902,13 +1837,16 @@ bool js_cocos2dx_extension_ControlHuePicker_constructor(JSContext *cx, uint32_t CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlHuePicker"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlHuePicker"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -1919,7 +1857,7 @@ void js_cocos2d_extension_ControlHuePicker_finalize(JSFreeOp *fop, JSObject *obj CCLOGINFO("jsbindings: finalizing JS object %p (ControlHuePicker)", obj); } -void js_register_cocos2dx_extension_ControlHuePicker(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_ControlHuePicker(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_ControlHuePicker_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_ControlHuePicker_class->name = "ControlHuePicker"; jsb_cocos2d_extension_ControlHuePicker_class->addProperty = JS_PropertyStub; @@ -1933,12 +1871,11 @@ void js_register_cocos2dx_extension_ControlHuePicker(JSContext *cx, JSObject *gl jsb_cocos2d_extension_ControlHuePicker_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("setEnabled", js_cocos2dx_extension_ControlHuePicker_setEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("initWithTargetAndPos", js_cocos2dx_extension_ControlHuePicker_initWithTargetAndPos, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setHue", js_cocos2dx_extension_ControlHuePicker_setHue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getStartPos", js_cocos2dx_extension_ControlHuePicker_getStartPos, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -1959,7 +1896,7 @@ void js_register_cocos2dx_extension_ControlHuePicker(JSContext *cx, JSObject *gl jsb_cocos2d_extension_ControlHuePicker_prototype = JS_InitClass( cx, global, - jsb_cocos2d_extension_Control_prototype, + JS::RootedObject(cx, jsb_cocos2d_extension_Control_prototype), jsb_cocos2d_extension_ControlHuePicker_class, js_cocos2dx_extension_ControlHuePicker_constructor, 0, // constructor properties, @@ -1990,7 +1927,8 @@ JSObject *jsb_cocos2d_extension_ControlSaturationBrightnessPicker_prototype; bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getShadow(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSaturationBrightnessPicker* cobj = (cocos2d::extension::ControlSaturationBrightnessPicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_getShadow : Invalid Native Object"); @@ -2005,7 +1943,7 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getShadow(JSContext jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2014,9 +1952,9 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getShadow(JSContext } bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_initWithTargetAndPos(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSaturationBrightnessPicker* cobj = (cocos2d::extension::ControlSaturationBrightnessPicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_initWithTargetAndPos : Invalid Native Object"); @@ -2024,19 +1962,19 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_initWithTargetAndPo cocos2d::Node* arg0; cocos2d::Vec2 arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_initWithTargetAndPos : Error processing arguments"); bool ret = cobj->initWithTargetAndPos(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2045,7 +1983,8 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_initWithTargetAndPo } bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getStartPos(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSaturationBrightnessPicker* cobj = (cocos2d::extension::ControlSaturationBrightnessPicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_getStartPos : Invalid Native Object"); @@ -2053,7 +1992,7 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getStartPos(JSConte cocos2d::Vec2 ret = cobj->getStartPos(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2062,7 +2001,8 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getStartPos(JSConte } bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getOverlay(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSaturationBrightnessPicker* cobj = (cocos2d::extension::ControlSaturationBrightnessPicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_getOverlay : Invalid Native Object"); @@ -2077,36 +2017,17 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getOverlay(JSContex jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_getOverlay : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlSaturationBrightnessPicker* cobj = (cocos2d::extension::ControlSaturationBrightnessPicker *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_setEnabled : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_setEnabled : Error processing arguments"); - cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_setEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getSlider(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSaturationBrightnessPicker* cobj = (cocos2d::extension::ControlSaturationBrightnessPicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_getSlider : Invalid Native Object"); @@ -2121,7 +2042,7 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getSlider(JSContext jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2130,7 +2051,8 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getSlider(JSContext } bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getBackground(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSaturationBrightnessPicker* cobj = (cocos2d::extension::ControlSaturationBrightnessPicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_getBackground : Invalid Native Object"); @@ -2145,7 +2067,7 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getBackground(JSCon jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2154,7 +2076,8 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getBackground(JSCon } bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getSaturation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSaturationBrightnessPicker* cobj = (cocos2d::extension::ControlSaturationBrightnessPicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_getSaturation : Invalid Native Object"); @@ -2162,7 +2085,7 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getSaturation(JSCon double ret = cobj->getSaturation(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2171,7 +2094,8 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getSaturation(JSCon } bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getBrightness(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSaturationBrightnessPicker* cobj = (cocos2d::extension::ControlSaturationBrightnessPicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_getBrightness : Invalid Native Object"); @@ -2179,7 +2103,7 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getBrightness(JSCon double ret = cobj->getBrightness(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2188,20 +2112,20 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getBrightness(JSCon } bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::Node* arg0; cocos2d::Vec2 arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_create : Error processing arguments"); cocos2d::extension::ControlSaturationBrightnessPicker* ret = cocos2d::extension::ControlSaturationBrightnessPicker::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -2213,7 +2137,7 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_create(JSContext *c jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_create : wrong number of arguments"); @@ -2222,7 +2146,7 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_create(JSContext *c bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::extension::ControlSaturationBrightnessPicker* cobj = new (std::nothrow) cocos2d::extension::ControlSaturationBrightnessPicker(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -2236,13 +2160,16 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_constructor(JSConte CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlSaturationBrightnessPicker"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlSaturationBrightnessPicker"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -2253,7 +2180,7 @@ void js_cocos2d_extension_ControlSaturationBrightnessPicker_finalize(JSFreeOp *f CCLOGINFO("jsbindings: finalizing JS object %p (ControlSaturationBrightnessPicker)", obj); } -void js_register_cocos2dx_extension_ControlSaturationBrightnessPicker(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_ControlSaturationBrightnessPicker(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_ControlSaturationBrightnessPicker_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_ControlSaturationBrightnessPicker_class->name = "ControlSaturationBrightnessPicker"; jsb_cocos2d_extension_ControlSaturationBrightnessPicker_class->addProperty = JS_PropertyStub; @@ -2267,8 +2194,8 @@ void js_register_cocos2dx_extension_ControlSaturationBrightnessPicker(JSContext jsb_cocos2d_extension_ControlSaturationBrightnessPicker_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -2276,7 +2203,6 @@ void js_register_cocos2dx_extension_ControlSaturationBrightnessPicker(JSContext JS_FN("initWithTargetAndPos", js_cocos2dx_extension_ControlSaturationBrightnessPicker_initWithTargetAndPos, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getStartPos", js_cocos2dx_extension_ControlSaturationBrightnessPicker_getStartPos, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getOverlay", js_cocos2dx_extension_ControlSaturationBrightnessPicker_getOverlay, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setEnabled", js_cocos2dx_extension_ControlSaturationBrightnessPicker_setEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getSlider", js_cocos2dx_extension_ControlSaturationBrightnessPicker_getSlider, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getBackground", js_cocos2dx_extension_ControlSaturationBrightnessPicker_getBackground, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getSaturation", js_cocos2dx_extension_ControlSaturationBrightnessPicker_getSaturation, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -2291,7 +2217,7 @@ void js_register_cocos2dx_extension_ControlSaturationBrightnessPicker(JSContext jsb_cocos2d_extension_ControlSaturationBrightnessPicker_prototype = JS_InitClass( cx, global, - jsb_cocos2d_extension_Control_prototype, + JS::RootedObject(cx, jsb_cocos2d_extension_Control_prototype), jsb_cocos2d_extension_ControlSaturationBrightnessPicker_class, js_cocos2dx_extension_ControlSaturationBrightnessPicker_constructor, 0, // constructor properties, @@ -2320,29 +2246,39 @@ void js_register_cocos2dx_extension_ControlSaturationBrightnessPicker(JSContext JSClass *jsb_cocos2d_extension_ControlColourPicker_class; JSObject *jsb_cocos2d_extension_ControlColourPicker_prototype; -bool js_cocos2dx_extension_ControlColourPicker_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlColourPicker_hueSliderValueChanged(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlColourPicker* cobj = (cocos2d::extension::ControlColourPicker *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlColourPicker_setEnabled : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlColourPicker_setEnabled : Error processing arguments"); - cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlColourPicker_hueSliderValueChanged : Invalid Native Object"); + if (argc == 2) { + cocos2d::Ref* arg0; + cocos2d::extension::Control::EventType arg1; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Ref*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlColourPicker_hueSliderValueChanged : Error processing arguments"); + cobj->hueSliderValueChanged(arg0, arg1); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlColourPicker_setEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlColourPicker_hueSliderValueChanged : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } bool js_cocos2dx_extension_ControlColourPicker_getHuePicker(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlColourPicker* cobj = (cocos2d::extension::ControlColourPicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlColourPicker_getHuePicker : Invalid Native Object"); @@ -2357,107 +2293,59 @@ bool js_cocos2dx_extension_ControlColourPicker_getHuePicker(JSContext *cx, uint3 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlColourPicker_getHuePicker : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlColourPicker_setColor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlColourPicker_getcolourPicker(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlColourPicker* cobj = (cocos2d::extension::ControlColourPicker *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlColourPicker_setColor : Invalid Native Object"); - if (argc == 1) { - cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlColourPicker_setColor : Error processing arguments"); - cobj->setColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlColourPicker_getcolourPicker : Invalid Native Object"); + if (argc == 0) { + cocos2d::extension::ControlSaturationBrightnessPicker* ret = cobj->getcolourPicker(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::extension::ControlSaturationBrightnessPicker*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlColourPicker_setColor : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlColourPicker_getcolourPicker : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlColourPicker_hueSliderValueChanged(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlColourPicker_setBackground(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlColourPicker* cobj = (cocos2d::extension::ControlColourPicker *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlColourPicker_hueSliderValueChanged : Invalid Native Object"); - if (argc == 2) { - cocos2d::Ref* arg0; - cocos2d::extension::Control::EventType arg1; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Ref*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlColourPicker_hueSliderValueChanged : Error processing arguments"); - cobj->hueSliderValueChanged(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlColourPicker_hueSliderValueChanged : wrong number of arguments: %d, was expecting %d", argc, 2); - return false; -} -bool js_cocos2dx_extension_ControlColourPicker_getcolourPicker(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlColourPicker* cobj = (cocos2d::extension::ControlColourPicker *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlColourPicker_getcolourPicker : Invalid Native Object"); - if (argc == 0) { - cocos2d::extension::ControlSaturationBrightnessPicker* ret = cobj->getcolourPicker(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::extension::ControlSaturationBrightnessPicker*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlColourPicker_getcolourPicker : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} -bool js_cocos2dx_extension_ControlColourPicker_setBackground(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlColourPicker* cobj = (cocos2d::extension::ControlColourPicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlColourPicker_setBackground : Invalid Native Object"); if (argc == 1) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlColourPicker_setBackground : Error processing arguments"); cobj->setBackground(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2466,25 +2354,25 @@ bool js_cocos2dx_extension_ControlColourPicker_setBackground(JSContext *cx, uint } bool js_cocos2dx_extension_ControlColourPicker_setcolourPicker(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlColourPicker* cobj = (cocos2d::extension::ControlColourPicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlColourPicker_setcolourPicker : Invalid Native Object"); if (argc == 1) { cocos2d::extension::ControlSaturationBrightnessPicker* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::extension::ControlSaturationBrightnessPicker*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlColourPicker_setcolourPicker : Error processing arguments"); cobj->setcolourPicker(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2493,9 +2381,9 @@ bool js_cocos2dx_extension_ControlColourPicker_setcolourPicker(JSContext *cx, ui } bool js_cocos2dx_extension_ControlColourPicker_colourSliderValueChanged(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlColourPicker* cobj = (cocos2d::extension::ControlColourPicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlColourPicker_colourSliderValueChanged : Invalid Native Object"); @@ -2503,17 +2391,17 @@ bool js_cocos2dx_extension_ControlColourPicker_colourSliderValueChanged(JSContex cocos2d::Ref* arg0; cocos2d::extension::Control::EventType arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Ref*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlColourPicker_colourSliderValueChanged : Error processing arguments"); cobj->colourSliderValueChanged(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2522,25 +2410,25 @@ bool js_cocos2dx_extension_ControlColourPicker_colourSliderValueChanged(JSContex } bool js_cocos2dx_extension_ControlColourPicker_setHuePicker(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlColourPicker* cobj = (cocos2d::extension::ControlColourPicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlColourPicker_setHuePicker : Invalid Native Object"); if (argc == 1) { cocos2d::extension::ControlHuePicker* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::extension::ControlHuePicker*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlColourPicker_setHuePicker : Error processing arguments"); cobj->setHuePicker(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2549,7 +2437,8 @@ bool js_cocos2dx_extension_ControlColourPicker_setHuePicker(JSContext *cx, uint3 } bool js_cocos2dx_extension_ControlColourPicker_getBackground(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlColourPicker* cobj = (cocos2d::extension::ControlColourPicker *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlColourPicker_getBackground : Invalid Native Object"); @@ -2564,7 +2453,7 @@ bool js_cocos2dx_extension_ControlColourPicker_getBackground(JSContext *cx, uint jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2573,6 +2462,7 @@ bool js_cocos2dx_extension_ControlColourPicker_getBackground(JSContext *cx, uint } bool js_cocos2dx_extension_ControlColourPicker_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::extension::ControlColourPicker* ret = cocos2d::extension::ControlColourPicker::create(); jsval jsret = JSVAL_NULL; @@ -2584,7 +2474,7 @@ bool js_cocos2dx_extension_ControlColourPicker_create(JSContext *cx, uint32_t ar jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlColourPicker_create : wrong number of arguments"); @@ -2593,7 +2483,7 @@ bool js_cocos2dx_extension_ControlColourPicker_create(JSContext *cx, uint32_t ar bool js_cocos2dx_extension_ControlColourPicker_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::extension::ControlColourPicker* cobj = new (std::nothrow) cocos2d::extension::ControlColourPicker(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -2607,13 +2497,16 @@ bool js_cocos2dx_extension_ControlColourPicker_constructor(JSContext *cx, uint32 CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlColourPicker"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlColourPicker"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -2626,21 +2519,21 @@ void js_cocos2d_extension_ControlColourPicker_finalize(JSFreeOp *fop, JSObject * static bool js_cocos2d_extension_ControlColourPicker_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::extension::ControlColourPicker *nobj = new (std::nothrow) cocos2d::extension::ControlColourPicker(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlColourPicker"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlColourPicker"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_extension_ControlColourPicker(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_ControlColourPicker(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_ControlColourPicker_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_ControlColourPicker_class->name = "ControlColourPicker"; jsb_cocos2d_extension_ControlColourPicker_class->addProperty = JS_PropertyStub; @@ -2654,15 +2547,13 @@ void js_register_cocos2dx_extension_ControlColourPicker(JSContext *cx, JSObject jsb_cocos2d_extension_ControlColourPicker_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("setEnabled", js_cocos2dx_extension_ControlColourPicker_setEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getHuePicker", js_cocos2dx_extension_ControlColourPicker_getHuePicker, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setColor", js_cocos2dx_extension_ControlColourPicker_setColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("hueSliderValueChanged", js_cocos2dx_extension_ControlColourPicker_hueSliderValueChanged, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getHuePicker", js_cocos2dx_extension_ControlColourPicker_getHuePicker, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getcolourPicker", js_cocos2dx_extension_ControlColourPicker_getcolourPicker, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setBackground", js_cocos2dx_extension_ControlColourPicker_setBackground, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setcolourPicker", js_cocos2dx_extension_ControlColourPicker_setcolourPicker, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -2680,7 +2571,7 @@ void js_register_cocos2dx_extension_ControlColourPicker(JSContext *cx, JSObject jsb_cocos2d_extension_ControlColourPicker_prototype = JS_InitClass( cx, global, - jsb_cocos2d_extension_Control_prototype, + JS::RootedObject(cx, jsb_cocos2d_extension_Control_prototype), jsb_cocos2d_extension_ControlColourPicker_class, js_cocos2dx_extension_ControlColourPicker_constructor, 0, // constructor properties, @@ -2711,18 +2602,18 @@ JSObject *jsb_cocos2d_extension_ControlPotentiometer_prototype; bool js_cocos2dx_extension_ControlPotentiometer_setPreviousLocation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_setPreviousLocation : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlPotentiometer_setPreviousLocation : Error processing arguments"); cobj->setPreviousLocation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2731,18 +2622,18 @@ bool js_cocos2dx_extension_ControlPotentiometer_setPreviousLocation(JSContext *c } bool js_cocos2dx_extension_ControlPotentiometer_setValue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_setValue : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlPotentiometer_setValue : Error processing arguments"); cobj->setValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2751,7 +2642,8 @@ bool js_cocos2dx_extension_ControlPotentiometer_setValue(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ControlPotentiometer_getProgressTimer(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_getProgressTimer : Invalid Native Object"); @@ -2766,7 +2658,7 @@ bool js_cocos2dx_extension_ControlPotentiometer_getProgressTimer(JSContext *cx, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2775,7 +2667,8 @@ bool js_cocos2dx_extension_ControlPotentiometer_getProgressTimer(JSContext *cx, } bool js_cocos2dx_extension_ControlPotentiometer_getMaximumValue(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_getMaximumValue : Invalid Native Object"); @@ -2783,7 +2676,7 @@ bool js_cocos2dx_extension_ControlPotentiometer_getMaximumValue(JSContext *cx, u double ret = cobj->getMaximumValue(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2792,9 +2685,9 @@ bool js_cocos2dx_extension_ControlPotentiometer_getMaximumValue(JSContext *cx, u } bool js_cocos2dx_extension_ControlPotentiometer_angleInDegreesBetweenLineFromPoint_toPoint_toLineFromPoint_toPoint(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_angleInDegreesBetweenLineFromPoint_toPoint_toLineFromPoint_toPoint : Invalid Native Object"); @@ -2803,15 +2696,15 @@ bool js_cocos2dx_extension_ControlPotentiometer_angleInDegreesBetweenLineFromPoi cocos2d::Vec2 arg1; cocos2d::Vec2 arg2; cocos2d::Vec2 arg3; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); - ok &= jsval_to_vector2(cx, argv[2], &arg2); - ok &= jsval_to_vector2(cx, argv[3], &arg3); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); + ok &= jsval_to_vector2(cx, args.get(2), &arg2); + ok &= jsval_to_vector2(cx, args.get(3), &arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlPotentiometer_angleInDegreesBetweenLineFromPoint_toPoint_toLineFromPoint_toPoint : Error processing arguments"); double ret = cobj->angleInDegreesBetweenLineFromPoint_toPoint_toLineFromPoint_toPoint(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2820,18 +2713,18 @@ bool js_cocos2dx_extension_ControlPotentiometer_angleInDegreesBetweenLineFromPoi } bool js_cocos2dx_extension_ControlPotentiometer_potentiometerBegan(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_potentiometerBegan : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlPotentiometer_potentiometerBegan : Error processing arguments"); cobj->potentiometerBegan(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2840,18 +2733,18 @@ bool js_cocos2dx_extension_ControlPotentiometer_potentiometerBegan(JSContext *cx } bool js_cocos2dx_extension_ControlPotentiometer_setMaximumValue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_setMaximumValue : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlPotentiometer_setMaximumValue : Error processing arguments"); cobj->setMaximumValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2860,7 +2753,8 @@ bool js_cocos2dx_extension_ControlPotentiometer_setMaximumValue(JSContext *cx, u } bool js_cocos2dx_extension_ControlPotentiometer_getMinimumValue(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_getMinimumValue : Invalid Native Object"); @@ -2868,7 +2762,7 @@ bool js_cocos2dx_extension_ControlPotentiometer_getMinimumValue(JSContext *cx, u double ret = cobj->getMinimumValue(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2877,25 +2771,25 @@ bool js_cocos2dx_extension_ControlPotentiometer_getMinimumValue(JSContext *cx, u } bool js_cocos2dx_extension_ControlPotentiometer_setThumbSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_setThumbSprite : Invalid Native Object"); if (argc == 1) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlPotentiometer_setThumbSprite : Error processing arguments"); cobj->setThumbSprite(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2904,7 +2798,8 @@ bool js_cocos2dx_extension_ControlPotentiometer_setThumbSprite(JSContext *cx, ui } bool js_cocos2dx_extension_ControlPotentiometer_getValue(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_getValue : Invalid Native Object"); @@ -2912,7 +2807,7 @@ bool js_cocos2dx_extension_ControlPotentiometer_getValue(JSContext *cx, uint32_t double ret = cobj->getValue(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2921,7 +2816,8 @@ bool js_cocos2dx_extension_ControlPotentiometer_getValue(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ControlPotentiometer_getPreviousLocation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_getPreviousLocation : Invalid Native Object"); @@ -2929,7 +2825,7 @@ bool js_cocos2dx_extension_ControlPotentiometer_getPreviousLocation(JSContext *c cocos2d::Vec2 ret = cobj->getPreviousLocation(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2938,22 +2834,22 @@ bool js_cocos2dx_extension_ControlPotentiometer_getPreviousLocation(JSContext *c } bool js_cocos2dx_extension_ControlPotentiometer_distanceBetweenPointAndPoint(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_distanceBetweenPointAndPoint : Invalid Native Object"); if (argc == 2) { cocos2d::Vec2 arg0; cocos2d::Vec2 arg1; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= jsval_to_vector2(cx, argv[1], &arg1); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + ok &= jsval_to_vector2(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlPotentiometer_distanceBetweenPointAndPoint : Error processing arguments"); double ret = cobj->distanceBetweenPointAndPoint(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2962,18 +2858,18 @@ bool js_cocos2dx_extension_ControlPotentiometer_distanceBetweenPointAndPoint(JSC } bool js_cocos2dx_extension_ControlPotentiometer_potentiometerEnded(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_potentiometerEnded : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlPotentiometer_potentiometerEnded : Error processing arguments"); cobj->potentiometerEnded(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2982,25 +2878,25 @@ bool js_cocos2dx_extension_ControlPotentiometer_potentiometerEnded(JSContext *cx } bool js_cocos2dx_extension_ControlPotentiometer_setProgressTimer(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_setProgressTimer : Invalid Native Object"); if (argc == 1) { cocos2d::ProgressTimer* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ProgressTimer*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlPotentiometer_setProgressTimer : Error processing arguments"); cobj->setProgressTimer(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3009,18 +2905,18 @@ bool js_cocos2dx_extension_ControlPotentiometer_setProgressTimer(JSContext *cx, } bool js_cocos2dx_extension_ControlPotentiometer_setMinimumValue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_setMinimumValue : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlPotentiometer_setMinimumValue : Error processing arguments"); cobj->setMinimumValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3029,7 +2925,8 @@ bool js_cocos2dx_extension_ControlPotentiometer_setMinimumValue(JSContext *cx, u } bool js_cocos2dx_extension_ControlPotentiometer_getThumbSprite(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_getThumbSprite : Invalid Native Object"); @@ -3044,7 +2941,7 @@ bool js_cocos2dx_extension_ControlPotentiometer_getThumbSprite(JSContext *cx, ui jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3053,9 +2950,9 @@ bool js_cocos2dx_extension_ControlPotentiometer_getThumbSprite(JSContext *cx, ui } bool js_cocos2dx_extension_ControlPotentiometer_initWithTrackSprite_ProgressTimer_ThumbSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_initWithTrackSprite_ProgressTimer_ThumbSprite : Invalid Native Object"); @@ -3064,25 +2961,25 @@ bool js_cocos2dx_extension_ControlPotentiometer_initWithTrackSprite_ProgressTime cocos2d::ProgressTimer* arg1; cocos2d::Sprite* arg2; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::ProgressTimer*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -3091,7 +2988,7 @@ bool js_cocos2dx_extension_ControlPotentiometer_initWithTrackSprite_ProgressTime bool ret = cobj->initWithTrackSprite_ProgressTimer_ThumbSprite(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3100,18 +2997,18 @@ bool js_cocos2dx_extension_ControlPotentiometer_initWithTrackSprite_ProgressTime } bool js_cocos2dx_extension_ControlPotentiometer_potentiometerMoved(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlPotentiometer* cobj = (cocos2d::extension::ControlPotentiometer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlPotentiometer_potentiometerMoved : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlPotentiometer_potentiometerMoved : Error processing arguments"); cobj->potentiometerMoved(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3120,15 +3017,15 @@ bool js_cocos2dx_extension_ControlPotentiometer_potentiometerMoved(JSContext *cx } bool js_cocos2dx_extension_ControlPotentiometer_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 3) { const char* arg0; const char* arg1; const char* arg2; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); - std::string arg2_tmp; ok &= jsval_to_std_string(cx, argv[2], &arg2_tmp); arg2 = arg2_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg2_tmp; ok &= jsval_to_std_string(cx, args.get(2), &arg2_tmp); arg2 = arg2_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlPotentiometer_create : Error processing arguments"); cocos2d::extension::ControlPotentiometer* ret = cocos2d::extension::ControlPotentiometer::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -3140,7 +3037,7 @@ bool js_cocos2dx_extension_ControlPotentiometer_create(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlPotentiometer_create : wrong number of arguments"); @@ -3149,7 +3046,7 @@ bool js_cocos2dx_extension_ControlPotentiometer_create(JSContext *cx, uint32_t a bool js_cocos2dx_extension_ControlPotentiometer_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::extension::ControlPotentiometer* cobj = new (std::nothrow) cocos2d::extension::ControlPotentiometer(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -3163,13 +3060,16 @@ bool js_cocos2dx_extension_ControlPotentiometer_constructor(JSContext *cx, uint3 CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlPotentiometer"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlPotentiometer"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -3182,21 +3082,21 @@ void js_cocos2d_extension_ControlPotentiometer_finalize(JSFreeOp *fop, JSObject static bool js_cocos2d_extension_ControlPotentiometer_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::extension::ControlPotentiometer *nobj = new (std::nothrow) cocos2d::extension::ControlPotentiometer(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlPotentiometer"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlPotentiometer"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_extension_ControlPotentiometer(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_ControlPotentiometer(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_ControlPotentiometer_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_ControlPotentiometer_class->name = "ControlPotentiometer"; jsb_cocos2d_extension_ControlPotentiometer_class->addProperty = JS_PropertyStub; @@ -3210,8 +3110,8 @@ void js_register_cocos2dx_extension_ControlPotentiometer(JSContext *cx, JSObject jsb_cocos2d_extension_ControlPotentiometer_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -3244,7 +3144,7 @@ void js_register_cocos2dx_extension_ControlPotentiometer(JSContext *cx, JSObject jsb_cocos2d_extension_ControlPotentiometer_prototype = JS_InitClass( cx, global, - jsb_cocos2d_extension_Control_prototype, + JS::RootedObject(cx, jsb_cocos2d_extension_Control_prototype), jsb_cocos2d_extension_ControlPotentiometer_class, js_cocos2dx_extension_ControlPotentiometer_constructor, 0, // constructor properties, @@ -3273,150 +3173,267 @@ void js_register_cocos2dx_extension_ControlPotentiometer(JSContext *cx, JSObject JSClass *jsb_cocos2d_extension_ControlSlider_class; JSObject *jsb_cocos2d_extension_ControlSlider_prototype; -bool js_cocos2dx_extension_ControlSlider_getSelectedThumbSprite(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlSlider_setBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getSelectedThumbSprite : Invalid Native Object"); - if (argc == 0) { - cocos2d::Sprite* ret = cobj->getSelectedThumbSprite(); - jsval jsret = JSVAL_NULL; + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setBackgroundSprite : Invalid Native Object"); + if (argc == 1) { + cocos2d::Sprite* arg0; do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - JS_SET_RVAL(cx, vp, jsret); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setBackgroundSprite : Error processing arguments"); + cobj->setBackgroundSprite(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_getSelectedThumbSprite : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setBackgroundSprite : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlSlider_locationFromTouch(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlSlider_getMaximumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_locationFromTouch : Invalid Native Object"); - if (argc == 1) { - cocos2d::Touch* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Touch*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_locationFromTouch : Error processing arguments"); - cocos2d::Vec2 ret = cobj->locationFromTouch(arg0); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getMaximumAllowedValue : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getMaximumAllowedValue(); jsval jsret = JSVAL_NULL; - jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_locationFromTouch : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_getMaximumAllowedValue : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlSlider_setSelectedThumbSprite(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlSlider_initWithSprites(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + + JS::RootedObject obj(cx); + cocos2d::extension::ControlSlider* cobj = NULL; + obj = args.thisv().toObjectOrNull(); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_initWithSprites : Invalid Native Object"); + do { + if (argc == 4) { + cocos2d::Sprite* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cocos2d::Sprite* arg1; + do { + if (!args.get(1).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(1).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg1 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cocos2d::Sprite* arg2; + do { + if (!args.get(2).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(2).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg2 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cocos2d::Sprite* arg3; + do { + if (!args.get(3).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(3).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg3 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithSprites(arg0, arg1, arg2, arg3); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + do { + if (argc == 3) { + cocos2d::Sprite* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cocos2d::Sprite* arg1; + do { + if (!args.get(1).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(1).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg1 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cocos2d::Sprite* arg2; + do { + if (!args.get(2).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(2).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg2 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithSprites(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_initWithSprites : wrong number of arguments"); + return false; +} +bool js_cocos2dx_extension_ControlSlider_getMinimumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setSelectedThumbSprite : Invalid Native Object"); - if (argc == 1) { - cocos2d::Sprite* arg0; + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getMinimumAllowedValue : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getMinimumAllowedValue(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_getMinimumAllowedValue : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_extension_ControlSlider_getMaximumValue(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getMaximumValue : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getMaximumValue(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_getMaximumValue : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_extension_ControlSlider_getSelectedThumbSprite(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getSelectedThumbSprite : Invalid Native Object"); + if (argc == 0) { + cocos2d::Sprite* ret = cobj->getSelectedThumbSprite(); + jsval jsret = JSVAL_NULL; do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setSelectedThumbSprite : Error processing arguments"); - cobj->setSelectedThumbSprite(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setSelectedThumbSprite : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_getSelectedThumbSprite : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } bool js_cocos2dx_extension_ControlSlider_setProgressSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setProgressSprite : Invalid Native Object"); if (argc == 1) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setProgressSprite : Error processing arguments"); cobj->setProgressSprite(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setProgressSprite : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlSlider_getMaximumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getMaximumAllowedValue : Invalid Native Object"); - if (argc == 0) { - double ret = cobj->getMaximumAllowedValue(); - jsval jsret = JSVAL_NULL; - jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_getMaximumAllowedValue : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} -bool js_cocos2dx_extension_ControlSlider_getMinimumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlSlider_setMaximumValue(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getMinimumAllowedValue : Invalid Native Object"); - if (argc == 0) { - double ret = cobj->getMinimumAllowedValue(); - jsval jsret = JSVAL_NULL; - jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setMaximumValue : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setMaximumValue : Error processing arguments"); + cobj->setMaximumValue(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_getMinimumAllowedValue : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setMaximumValue : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_extension_ControlSlider_getMinimumValue(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getMinimumValue : Invalid Native Object"); @@ -3424,7 +3441,7 @@ bool js_cocos2dx_extension_ControlSlider_getMinimumValue(JSContext *cx, uint32_t double ret = cobj->getMinimumValue(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3433,149 +3450,53 @@ bool js_cocos2dx_extension_ControlSlider_getMinimumValue(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ControlSlider_setThumbSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setThumbSprite : Invalid Native Object"); if (argc == 1) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setThumbSprite : Error processing arguments"); cobj->setThumbSprite(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setThumbSprite : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlSlider_setMinimumValue(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setMinimumValue : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setMinimumValue : Error processing arguments"); - cobj->setMinimumValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setMinimumValue : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_extension_ControlSlider_setMinimumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setMinimumAllowedValue : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setMinimumAllowedValue : Error processing arguments"); - cobj->setMinimumAllowedValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setMinimumAllowedValue : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_extension_ControlSlider_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setEnabled : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setEnabled : Error processing arguments"); - cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_extension_ControlSlider_setValue(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setValue : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setValue : Error processing arguments"); - cobj->setValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setValue : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_extension_ControlSlider_setMaximumValue(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setMaximumValue : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setMaximumValue : Error processing arguments"); - cobj->setMaximumValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setMaximumValue : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_extension_ControlSlider_needsLayout(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlSlider_getValue(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_needsLayout : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getValue : Invalid Native Object"); if (argc == 0) { - cobj->needsLayout(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + double ret = cobj->getValue(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_needsLayout : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_getValue : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } bool js_cocos2dx_extension_ControlSlider_getBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getBackgroundSprite : Invalid Native Object"); @@ -3590,207 +3511,131 @@ bool js_cocos2dx_extension_ControlSlider_getBackgroundSprite(JSContext *cx, uint jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_getBackgroundSprite : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlSlider_initWithSprites(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlSlider_getThumbSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - - JSObject *obj = NULL; - cocos2d::extension::ControlSlider* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_initWithSprites : Invalid Native Object"); - do { - if (argc == 4) { - cocos2d::Sprite* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cocos2d::Sprite* arg1; - do { - if (!argv[1].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg1 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cocos2d::Sprite* arg2; - do { - if (!argv[2].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg2 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cocos2d::Sprite* arg3; - do { - if (!argv[3].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[3]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg3 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - bool ret = cobj->initWithSprites(arg0, arg1, arg2, arg3); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while(0); - - do { - if (argc == 3) { - cocos2d::Sprite* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cocos2d::Sprite* arg1; - do { - if (!argv[1].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg1 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cocos2d::Sprite* arg2; - do { - if (!argv[2].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg2 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - bool ret = cobj->initWithSprites(arg0, arg1, arg2); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while(0); + cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getThumbSprite : Invalid Native Object"); + if (argc == 0) { + cocos2d::Sprite* ret = cobj->getThumbSprite(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_initWithSprites : wrong number of arguments"); + JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_getThumbSprite : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlSlider_getMaximumValue(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlSlider_setValue(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getMaximumValue : Invalid Native Object"); - if (argc == 0) { - double ret = cobj->getMaximumValue(); - jsval jsret = JSVAL_NULL; - jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setValue : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setValue : Error processing arguments"); + cobj->setValue(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_getMaximumValue : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setValue : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlSlider_isTouchInside(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlSlider_locationFromTouch(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_isTouchInside : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_locationFromTouch : Invalid Native Object"); if (argc == 1) { cocos2d::Touch* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Touch*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_isTouchInside : Error processing arguments"); - bool ret = cobj->isTouchInside(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_locationFromTouch : Error processing arguments"); + cocos2d::Vec2 ret = cobj->locationFromTouch(arg0); jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = vector2_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_isTouchInside : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_locationFromTouch : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlSlider_getValue(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlSlider_setMinimumValue(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getValue : Invalid Native Object"); - if (argc == 0) { - double ret = cobj->getValue(); - jsval jsret = JSVAL_NULL; - jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setMinimumValue : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setMinimumValue : Error processing arguments"); + cobj->setMinimumValue(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_getValue : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setMinimumValue : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlSlider_getThumbSprite(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlSlider_setMinimumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getThumbSprite : Invalid Native Object"); - if (argc == 0) { - cocos2d::Sprite* ret = cobj->getThumbSprite(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setMinimumAllowedValue : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setMinimumAllowedValue : Error processing arguments"); + cobj->setMinimumAllowedValue(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_getThumbSprite : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setMinimumAllowedValue : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_extension_ControlSlider_getProgressSprite(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getProgressSprite : Invalid Native Object"); @@ -3805,54 +3650,54 @@ bool js_cocos2dx_extension_ControlSlider_getProgressSprite(JSContext *cx, uint32 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_getProgressSprite : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlSlider_setBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlSlider_setSelectedThumbSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setBackgroundSprite : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setSelectedThumbSprite : Invalid Native Object"); if (argc == 1) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setBackgroundSprite : Error processing arguments"); - cobj->setBackgroundSprite(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setSelectedThumbSprite : Error processing arguments"); + cobj->setSelectedThumbSprite(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setBackgroundSprite : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlSlider_setSelectedThumbSprite : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_extension_ControlSlider_setMaximumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setMaximumAllowedValue : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setMaximumAllowedValue : Error processing arguments"); cobj->setMaximumAllowedValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3861,16 +3706,16 @@ bool js_cocos2dx_extension_ControlSlider_setMaximumAllowedValue(JSContext *cx, u } bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 3) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -3878,9 +3723,9 @@ bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, js if (!ok) { ok = true; break; } cocos2d::Sprite* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -3888,9 +3733,9 @@ bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, js if (!ok) { ok = true; break; } cocos2d::Sprite* arg2; do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -3906,7 +3751,7 @@ bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -3914,13 +3759,13 @@ bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, js do { if (argc == 3) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } const char* arg1; - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); if (!ok) { ok = true; break; } const char* arg2; - std::string arg2_tmp; ok &= jsval_to_std_string(cx, argv[2], &arg2_tmp); arg2 = arg2_tmp.c_str(); + std::string arg2_tmp; ok &= jsval_to_std_string(cx, args.get(2), &arg2_tmp); arg2 = arg2_tmp.c_str(); if (!ok) { ok = true; break; } cocos2d::extension::ControlSlider* ret = cocos2d::extension::ControlSlider::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -3932,7 +3777,7 @@ bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -3940,16 +3785,16 @@ bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, js do { if (argc == 4) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } const char* arg1; - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); if (!ok) { ok = true; break; } const char* arg2; - std::string arg2_tmp; ok &= jsval_to_std_string(cx, argv[2], &arg2_tmp); arg2 = arg2_tmp.c_str(); + std::string arg2_tmp; ok &= jsval_to_std_string(cx, args.get(2), &arg2_tmp); arg2 = arg2_tmp.c_str(); if (!ok) { ok = true; break; } const char* arg3; - std::string arg3_tmp; ok &= jsval_to_std_string(cx, argv[3], &arg3_tmp); arg3 = arg3_tmp.c_str(); + std::string arg3_tmp; ok &= jsval_to_std_string(cx, args.get(3), &arg3_tmp); arg3 = arg3_tmp.c_str(); if (!ok) { ok = true; break; } cocos2d::extension::ControlSlider* ret = cocos2d::extension::ControlSlider::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -3961,7 +3806,7 @@ bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -3970,9 +3815,9 @@ bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, js if (argc == 4) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -3980,9 +3825,9 @@ bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, js if (!ok) { ok = true; break; } cocos2d::Sprite* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -3990,9 +3835,9 @@ bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, js if (!ok) { ok = true; break; } cocos2d::Sprite* arg2; do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -4000,9 +3845,9 @@ bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, js if (!ok) { ok = true; break; } cocos2d::Sprite* arg3; do { - if (!argv[3].isObject()) { ok = false; break; } + if (!args.get(3).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[3]); + JSObject *tmpObj = args.get(3).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg3 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); @@ -4018,7 +3863,7 @@ bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -4027,7 +3872,7 @@ bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_extension_ControlSlider_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::extension::ControlSlider* cobj = new (std::nothrow) cocos2d::extension::ControlSlider(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -4041,13 +3886,16 @@ bool js_cocos2dx_extension_ControlSlider_constructor(JSContext *cx, uint32_t arg CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlSlider"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlSlider"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -4060,21 +3908,21 @@ void js_cocos2d_extension_ControlSlider_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_extension_ControlSlider_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::extension::ControlSlider *nobj = new (std::nothrow) cocos2d::extension::ControlSlider(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlSlider"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlSlider"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_extension_ControlSlider(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_ControlSlider(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_ControlSlider_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_ControlSlider_class->name = "ControlSlider"; jsb_cocos2d_extension_ControlSlider_class->addProperty = JS_PropertyStub; @@ -4088,33 +3936,30 @@ void js_register_cocos2dx_extension_ControlSlider(JSContext *cx, JSObject *globa jsb_cocos2d_extension_ControlSlider_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("getSelectedThumbSprite", js_cocos2dx_extension_ControlSlider_getSelectedThumbSprite, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("locationFromTouch", js_cocos2dx_extension_ControlSlider_locationFromTouch, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setSelectedThumbSprite", js_cocos2dx_extension_ControlSlider_setSelectedThumbSprite, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setProgressSprite", js_cocos2dx_extension_ControlSlider_setProgressSprite, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setBackgroundSprite", js_cocos2dx_extension_ControlSlider_setBackgroundSprite, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getMaximumAllowedValue", js_cocos2dx_extension_ControlSlider_getMaximumAllowedValue, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithSprites", js_cocos2dx_extension_ControlSlider_initWithSprites, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getMinimumAllowedValue", js_cocos2dx_extension_ControlSlider_getMinimumAllowedValue, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMaximumValue", js_cocos2dx_extension_ControlSlider_getMaximumValue, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getSelectedThumbSprite", js_cocos2dx_extension_ControlSlider_getSelectedThumbSprite, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setProgressSprite", js_cocos2dx_extension_ControlSlider_setProgressSprite, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMaximumValue", js_cocos2dx_extension_ControlSlider_setMaximumValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getMinimumValue", js_cocos2dx_extension_ControlSlider_getMinimumValue, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setThumbSprite", js_cocos2dx_extension_ControlSlider_setThumbSprite, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setMinimumValue", js_cocos2dx_extension_ControlSlider_setMinimumValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setMinimumAllowedValue", js_cocos2dx_extension_ControlSlider_setMinimumAllowedValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setEnabled", js_cocos2dx_extension_ControlSlider_setEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setValue", js_cocos2dx_extension_ControlSlider_setValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setMaximumValue", js_cocos2dx_extension_ControlSlider_setMaximumValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("needsLayout", js_cocos2dx_extension_ControlSlider_needsLayout, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getBackgroundSprite", js_cocos2dx_extension_ControlSlider_getBackgroundSprite, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("initWithSprites", js_cocos2dx_extension_ControlSlider_initWithSprites, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getMaximumValue", js_cocos2dx_extension_ControlSlider_getMaximumValue, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("isTouchInside", js_cocos2dx_extension_ControlSlider_isTouchInside, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getValue", js_cocos2dx_extension_ControlSlider_getValue, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getBackgroundSprite", js_cocos2dx_extension_ControlSlider_getBackgroundSprite, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getThumbSprite", js_cocos2dx_extension_ControlSlider_getThumbSprite, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setValue", js_cocos2dx_extension_ControlSlider_setValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("locationFromTouch", js_cocos2dx_extension_ControlSlider_locationFromTouch, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMinimumValue", js_cocos2dx_extension_ControlSlider_setMinimumValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMinimumAllowedValue", js_cocos2dx_extension_ControlSlider_setMinimumAllowedValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getProgressSprite", js_cocos2dx_extension_ControlSlider_getProgressSprite, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setBackgroundSprite", js_cocos2dx_extension_ControlSlider_setBackgroundSprite, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setSelectedThumbSprite", js_cocos2dx_extension_ControlSlider_setSelectedThumbSprite, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setMaximumAllowedValue", js_cocos2dx_extension_ControlSlider_setMaximumAllowedValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2d_extension_ControlSlider_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END @@ -4127,7 +3972,7 @@ void js_register_cocos2dx_extension_ControlSlider(JSContext *cx, JSObject *globa jsb_cocos2d_extension_ControlSlider_prototype = JS_InitClass( cx, global, - jsb_cocos2d_extension_Control_prototype, + JS::RootedObject(cx, jsb_cocos2d_extension_Control_prototype), jsb_cocos2d_extension_ControlSlider_class, js_cocos2dx_extension_ControlSlider_constructor, 0, // constructor properties, @@ -4156,163 +4001,180 @@ void js_register_cocos2dx_extension_ControlSlider(JSContext *cx, JSObject *globa JSClass *jsb_cocos2d_extension_ControlStepper_class; JSObject *jsb_cocos2d_extension_ControlStepper_prototype; -bool js_cocos2dx_extension_ControlStepper_setMinusSprite(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setMinusSprite : Invalid Native Object"); - if (argc == 1) { - cocos2d::Sprite* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setMinusSprite : Error processing arguments"); - cobj->setMinusSprite(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setMinusSprite : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_extension_ControlStepper_getMinusLabel(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_getMinusSprite(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_getMinusLabel : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_getMinusSprite : Invalid Native Object"); if (argc == 0) { - cocos2d::Label* ret = cobj->getMinusLabel(); + cocos2d::Sprite* ret = cobj->getMinusSprite(); jsval jsret = JSVAL_NULL; do { if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Label*)ret); + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite*)ret); jsret = OBJECT_TO_JSVAL(jsProxy->obj); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_getMinusLabel : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_getMinusSprite : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlStepper_setWraps(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_setValue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setWraps : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setValue : Invalid Native Object"); if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setWraps : Error processing arguments"); - cobj->setWraps(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setValue : Error processing arguments"); + cobj->setValue(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setWraps : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setValue : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlStepper_isContinuous(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_setStepValue(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_isContinuous : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->isContinuous(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setStepValue : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setStepValue : Error processing arguments"); + cobj->setStepValue(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_isContinuous : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setStepValue : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlStepper_getMinusSprite(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_getMinusSprite : Invalid Native Object"); - if (argc == 0) { - cocos2d::Sprite* ret = cobj->getMinusSprite(); - jsval jsret = JSVAL_NULL; + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite : Invalid Native Object"); + if (argc == 2) { + cocos2d::Sprite* arg0; + cocos2d::Sprite* arg1; do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - JS_SET_RVAL(cx, vp, jsret); + do { + if (!args.get(1).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(1).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg1 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite : Error processing arguments"); + bool ret = cobj->initWithMinusSpriteAndPlusSprite(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_getMinusSprite : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_extension_ControlStepper_updateLayoutUsingTouchLocation(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_setValueWithSendingEvent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_updateLayoutUsingTouchLocation : Invalid Native Object"); - if (argc == 1) { - cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_updateLayoutUsingTouchLocation : Error processing arguments"); - cobj->updateLayoutUsingTouchLocation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setValueWithSendingEvent : Invalid Native Object"); + if (argc == 2) { + double arg0; + bool arg1; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + arg1 = JS::ToBoolean(args.get(1)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setValueWithSendingEvent : Error processing arguments"); + cobj->setValueWithSendingEvent(arg0, arg1); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_updateLayoutUsingTouchLocation : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setValueWithSendingEvent : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_extension_ControlStepper_setValueWithSendingEvent(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_setMaximumValue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setValueWithSendingEvent : Invalid Native Object"); - if (argc == 2) { + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setMaximumValue : Invalid Native Object"); + if (argc == 1) { double arg0; - bool arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setValueWithSendingEvent : Error processing arguments"); - cobj->setValueWithSendingEvent(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setMaximumValue : Error processing arguments"); + cobj->setMaximumValue(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setValueWithSendingEvent : wrong number of arguments: %d, was expecting %d", argc, 2); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setMaximumValue : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_extension_ControlStepper_getMinusLabel(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_getMinusLabel : Invalid Native Object"); + if (argc == 0) { + cocos2d::Label* ret = cobj->getMinusLabel(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Label*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_getMinusLabel : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } bool js_cocos2dx_extension_ControlStepper_getPlusLabel(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_getPlusLabel : Invalid Native Object"); @@ -4327,322 +4189,293 @@ bool js_cocos2dx_extension_ControlStepper_getPlusLabel(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_getPlusLabel : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlStepper_stopAutorepeat(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_setWraps(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_stopAutorepeat : Invalid Native Object"); - if (argc == 0) { - cobj->stopAutorepeat(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setWraps : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setWraps : Error processing arguments"); + cobj->setWraps(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_stopAutorepeat : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setWraps : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlStepper_setMinimumValue(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_setMinusLabel(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setMinimumValue : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setMinusLabel : Invalid Native Object"); if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setMinimumValue : Error processing arguments"); - cobj->setMinimumValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::Label* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Label*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setMinusLabel : Error processing arguments"); + cobj->setMinusLabel(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setMinimumValue : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setMinusLabel : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlStepper_getPlusSprite(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_startAutorepeat(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_getPlusSprite : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_startAutorepeat : Invalid Native Object"); if (argc == 0) { - cocos2d::Sprite* ret = cobj->getPlusSprite(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); + cobj->startAutorepeat(); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_getPlusSprite : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_startAutorepeat : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlStepper_setPlusSprite(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_updateLayoutUsingTouchLocation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setPlusSprite : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_updateLayoutUsingTouchLocation : Invalid Native Object"); if (argc == 1) { - cocos2d::Sprite* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setPlusSprite : Error processing arguments"); - cobj->setPlusSprite(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::Vec2 arg0; + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_updateLayoutUsingTouchLocation : Error processing arguments"); + cobj->updateLayoutUsingTouchLocation(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setPlusSprite : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_updateLayoutUsingTouchLocation : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlStepper_setMinusLabel(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_isContinuous(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setMinusLabel : Invalid Native Object"); - if (argc == 1) { - cocos2d::Label* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Label*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setMinusLabel : Error processing arguments"); - cobj->setMinusLabel(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_isContinuous : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isContinuous(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setMinusLabel : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_isContinuous : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlStepper_setValue(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_stopAutorepeat(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setValue : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setValue : Error processing arguments"); - cobj->setValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_stopAutorepeat : Invalid Native Object"); + if (argc == 0) { + cobj->stopAutorepeat(); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setValue : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_stopAutorepeat : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlStepper_setStepValue(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_setMinimumValue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setStepValue : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setMinimumValue : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setStepValue : Error processing arguments"); - cobj->setStepValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setMinimumValue : Error processing arguments"); + cobj->setMinimumValue(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setStepValue : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setMinimumValue : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlStepper_setMaximumValue(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_setPlusLabel(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setMaximumValue : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setPlusLabel : Invalid Native Object"); if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setMaximumValue : Error processing arguments"); - cobj->setMaximumValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::Label* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Label*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setPlusLabel : Error processing arguments"); + cobj->setPlusLabel(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setMaximumValue : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setPlusLabel : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlStepper_update(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_getValue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_update : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_update : Error processing arguments"); - cobj->update(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_getValue : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getValue(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_update : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_getValue : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlStepper_startAutorepeat(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_getPlusSprite(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_startAutorepeat : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_getPlusSprite : Invalid Native Object"); if (argc == 0) { - cobj->startAutorepeat(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::Sprite* ret = cobj->getPlusSprite(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_startAutorepeat : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_getPlusSprite : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_setPlusSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite : Invalid Native Object"); - if (argc == 2) { + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setPlusSprite : Invalid Native Object"); + if (argc == 1) { cocos2d::Sprite* arg0; - cocos2d::Sprite* arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - do { - if (!argv[1].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg1 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite : Error processing arguments"); - bool ret = cobj->initWithMinusSpriteAndPlusSprite(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite : wrong number of arguments: %d, was expecting %d", argc, 2); - return false; -} -bool js_cocos2dx_extension_ControlStepper_getValue(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_getValue : Invalid Native Object"); - if (argc == 0) { - double ret = cobj->getValue(); - jsval jsret = JSVAL_NULL; - jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setPlusSprite : Error processing arguments"); + cobj->setPlusSprite(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_getValue : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setPlusSprite : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ControlStepper_setPlusLabel(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ControlStepper_setMinusSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setPlusLabel : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_setMinusSprite : Invalid Native Object"); if (argc == 1) { - cocos2d::Label* arg0; + cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Label*)(jsProxy ? jsProxy->ptr : NULL); + arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setPlusLabel : Error processing arguments"); - cobj->setPlusLabel(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_setMinusSprite : Error processing arguments"); + cobj->setMinusSprite(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setPlusLabel : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_setMinusSprite : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_extension_ControlStepper_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::Sprite* arg0; cocos2d::Sprite* arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -4658,7 +4491,7 @@ bool js_cocos2dx_extension_ControlStepper_create(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlStepper_create : wrong number of arguments"); @@ -4667,7 +4500,7 @@ bool js_cocos2dx_extension_ControlStepper_create(JSContext *cx, uint32_t argc, j bool js_cocos2dx_extension_ControlStepper_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::extension::ControlStepper* cobj = new (std::nothrow) cocos2d::extension::ControlStepper(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -4681,13 +4514,16 @@ bool js_cocos2dx_extension_ControlStepper_constructor(JSContext *cx, uint32_t ar CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlStepper"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlStepper"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -4700,21 +4536,21 @@ void js_cocos2d_extension_ControlStepper_finalize(JSFreeOp *fop, JSObject *obj) static bool js_cocos2d_extension_ControlStepper_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::extension::ControlStepper *nobj = new (std::nothrow) cocos2d::extension::ControlStepper(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlStepper"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlStepper"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_extension_ControlStepper(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_ControlStepper(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_ControlStepper_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_ControlStepper_class->name = "ControlStepper"; jsb_cocos2d_extension_ControlStepper_class->addProperty = JS_PropertyStub; @@ -4728,32 +4564,31 @@ void js_register_cocos2dx_extension_ControlStepper(JSContext *cx, JSObject *glob jsb_cocos2d_extension_ControlStepper_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("setMinusSprite", js_cocos2dx_extension_ControlStepper_setMinusSprite, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getMinusLabel", js_cocos2dx_extension_ControlStepper_getMinusLabel, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setWraps", js_cocos2dx_extension_ControlStepper_setWraps, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("isContinuous", js_cocos2dx_extension_ControlStepper_isContinuous, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getMinusSprite", js_cocos2dx_extension_ControlStepper_getMinusSprite, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("updateLayoutUsingTouchLocation", js_cocos2dx_extension_ControlStepper_updateLayoutUsingTouchLocation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setValue", js_cocos2dx_extension_ControlStepper_setValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setStepValue", js_cocos2dx_extension_ControlStepper_setStepValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithMinusSpriteAndPlusSprite", js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setValueWithSendingEvent", js_cocos2dx_extension_ControlStepper_setValueWithSendingEvent, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMaximumValue", js_cocos2dx_extension_ControlStepper_setMaximumValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMinusLabel", js_cocos2dx_extension_ControlStepper_getMinusLabel, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getPlusLabel", js_cocos2dx_extension_ControlStepper_getPlusLabel, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setWraps", js_cocos2dx_extension_ControlStepper_setWraps, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMinusLabel", js_cocos2dx_extension_ControlStepper_setMinusLabel, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("startAutorepeat", js_cocos2dx_extension_ControlStepper_startAutorepeat, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("updateLayoutUsingTouchLocation", js_cocos2dx_extension_ControlStepper_updateLayoutUsingTouchLocation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isContinuous", js_cocos2dx_extension_ControlStepper_isContinuous, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("stopAutorepeat", js_cocos2dx_extension_ControlStepper_stopAutorepeat, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setMinimumValue", js_cocos2dx_extension_ControlStepper_setMinimumValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPlusLabel", js_cocos2dx_extension_ControlStepper_setPlusLabel, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getValue", js_cocos2dx_extension_ControlStepper_getValue, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getPlusSprite", js_cocos2dx_extension_ControlStepper_getPlusSprite, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setPlusSprite", js_cocos2dx_extension_ControlStepper_setPlusSprite, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setMinusLabel", js_cocos2dx_extension_ControlStepper_setMinusLabel, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setValue", js_cocos2dx_extension_ControlStepper_setValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setStepValue", js_cocos2dx_extension_ControlStepper_setStepValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setMaximumValue", js_cocos2dx_extension_ControlStepper_setMaximumValue, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("update", js_cocos2dx_extension_ControlStepper_update, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("startAutorepeat", js_cocos2dx_extension_ControlStepper_startAutorepeat, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("initWithMinusSpriteAndPlusSprite", js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getValue", js_cocos2dx_extension_ControlStepper_getValue, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setPlusLabel", js_cocos2dx_extension_ControlStepper_setPlusLabel, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMinusSprite", js_cocos2dx_extension_ControlStepper_setMinusSprite, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2d_extension_ControlStepper_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -4765,7 +4600,7 @@ void js_register_cocos2dx_extension_ControlStepper(JSContext *cx, JSObject *glob jsb_cocos2d_extension_ControlStepper_prototype = JS_InitClass( cx, global, - jsb_cocos2d_extension_Control_prototype, + JS::RootedObject(cx, jsb_cocos2d_extension_Control_prototype), jsb_cocos2d_extension_ControlStepper_class, js_cocos2dx_extension_ControlStepper_constructor, 0, // constructor properties, @@ -4794,43 +4629,23 @@ void js_register_cocos2dx_extension_ControlStepper(JSContext *cx, JSObject *glob JSClass *jsb_cocos2d_extension_ControlSwitch_class; JSObject *jsb_cocos2d_extension_ControlSwitch_prototype; -bool js_cocos2dx_extension_ControlSwitch_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlSwitch* cobj = (cocos2d::extension::ControlSwitch *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSwitch_setEnabled : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSwitch_setEnabled : Error processing arguments"); - cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlSwitch_setEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_extension_ControlSwitch_setOn(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::extension::ControlSwitch* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::extension::ControlSwitch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSwitch_setOn : Invalid Native Object"); do { if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); cobj->setOn(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -4838,11 +4653,11 @@ bool js_cocos2dx_extension_ControlSwitch_setOn(JSContext *cx, uint32_t argc, jsv do { if (argc == 2) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); bool arg1; - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); cobj->setOn(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -4850,9 +4665,39 @@ bool js_cocos2dx_extension_ControlSwitch_setOn(JSContext *cx, uint32_t argc, jsv JS_ReportError(cx, "js_cocos2dx_extension_ControlSwitch_setOn : wrong number of arguments"); return false; } +bool js_cocos2dx_extension_ControlSwitch_locationFromTouch(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::extension::ControlSwitch* cobj = (cocos2d::extension::ControlSwitch *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSwitch_locationFromTouch : Invalid Native Object"); + if (argc == 1) { + cocos2d::Touch* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Touch*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSwitch_locationFromTouch : Error processing arguments"); + cocos2d::Vec2 ret = cobj->locationFromTouch(arg0); + jsval jsret = JSVAL_NULL; + jsret = vector2_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_extension_ControlSwitch_locationFromTouch : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_extension_ControlSwitch_isOn(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSwitch* cobj = (cocos2d::extension::ControlSwitch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSwitch_isOn : Invalid Native Object"); @@ -4860,7 +4705,7 @@ bool js_cocos2dx_extension_ControlSwitch_isOn(JSContext *cx, uint32_t argc, jsva bool ret = cobj->isOn(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4869,12 +4714,12 @@ bool js_cocos2dx_extension_ControlSwitch_isOn(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::extension::ControlSwitch* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::extension::ControlSwitch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSwitch_initWithMaskSprite : Invalid Native Object"); @@ -4882,9 +4727,9 @@ bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint3 if (argc == 6) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -4892,9 +4737,9 @@ bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint3 if (!ok) { ok = true; break; } cocos2d::Sprite* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -4902,9 +4747,9 @@ bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint3 if (!ok) { ok = true; break; } cocos2d::Sprite* arg2; do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -4912,9 +4757,9 @@ bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint3 if (!ok) { ok = true; break; } cocos2d::Sprite* arg3; do { - if (!argv[3].isObject()) { ok = false; break; } + if (!args.get(3).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[3]); + JSObject *tmpObj = args.get(3).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg3 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); @@ -4922,9 +4767,9 @@ bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint3 if (!ok) { ok = true; break; } cocos2d::Label* arg4; do { - if (!argv[4].isObject()) { ok = false; break; } + if (!args.get(4).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[4]); + JSObject *tmpObj = args.get(4).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg4 = (cocos2d::Label*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg4, cx, false, "Invalid Native Object"); @@ -4932,9 +4777,9 @@ bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint3 if (!ok) { ok = true; break; } cocos2d::Label* arg5; do { - if (!argv[5].isObject()) { ok = false; break; } + if (!args.get(5).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[5]); + JSObject *tmpObj = args.get(5).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg5 = (cocos2d::Label*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg5, cx, false, "Invalid Native Object"); @@ -4943,7 +4788,7 @@ bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint3 bool ret = cobj->initWithMaskSprite(arg0, arg1, arg2, arg3, arg4, arg5); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -4952,9 +4797,9 @@ bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint3 if (argc == 4) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -4962,9 +4807,9 @@ bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint3 if (!ok) { ok = true; break; } cocos2d::Sprite* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -4972,9 +4817,9 @@ bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint3 if (!ok) { ok = true; break; } cocos2d::Sprite* arg2; do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -4982,9 +4827,9 @@ bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint3 if (!ok) { ok = true; break; } cocos2d::Sprite* arg3; do { - if (!argv[3].isObject()) { ok = false; break; } + if (!args.get(3).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[3]); + JSObject *tmpObj = args.get(3).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg3 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); @@ -4993,7 +4838,7 @@ bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint3 bool ret = cobj->initWithMaskSprite(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -5003,7 +4848,8 @@ bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint3 } bool js_cocos2dx_extension_ControlSwitch_hasMoved(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ControlSwitch* cobj = (cocos2d::extension::ControlSwitch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSwitch_hasMoved : Invalid Native Object"); @@ -5011,54 +4857,25 @@ bool js_cocos2dx_extension_ControlSwitch_hasMoved(JSContext *cx, uint32_t argc, bool ret = cobj->hasMoved(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ControlSwitch_hasMoved : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ControlSwitch_locationFromTouch(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ControlSwitch* cobj = (cocos2d::extension::ControlSwitch *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSwitch_locationFromTouch : Invalid Native Object"); - if (argc == 1) { - cocos2d::Touch* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Touch*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSwitch_locationFromTouch : Error processing arguments"); - cocos2d::Vec2 ret = cobj->locationFromTouch(arg0); - jsval jsret = JSVAL_NULL; - jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ControlSwitch_locationFromTouch : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_extension_ControlSwitch_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 4) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -5066,9 +4883,9 @@ bool js_cocos2dx_extension_ControlSwitch_create(JSContext *cx, uint32_t argc, js if (!ok) { ok = true; break; } cocos2d::Sprite* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -5076,9 +4893,9 @@ bool js_cocos2dx_extension_ControlSwitch_create(JSContext *cx, uint32_t argc, js if (!ok) { ok = true; break; } cocos2d::Sprite* arg2; do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -5086,9 +4903,9 @@ bool js_cocos2dx_extension_ControlSwitch_create(JSContext *cx, uint32_t argc, js if (!ok) { ok = true; break; } cocos2d::Sprite* arg3; do { - if (!argv[3].isObject()) { ok = false; break; } + if (!args.get(3).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[3]); + JSObject *tmpObj = args.get(3).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg3 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); @@ -5104,7 +4921,7 @@ bool js_cocos2dx_extension_ControlSwitch_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -5113,9 +4930,9 @@ bool js_cocos2dx_extension_ControlSwitch_create(JSContext *cx, uint32_t argc, js if (argc == 6) { cocos2d::Sprite* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -5123,9 +4940,9 @@ bool js_cocos2dx_extension_ControlSwitch_create(JSContext *cx, uint32_t argc, js if (!ok) { ok = true; break; } cocos2d::Sprite* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -5133,9 +4950,9 @@ bool js_cocos2dx_extension_ControlSwitch_create(JSContext *cx, uint32_t argc, js if (!ok) { ok = true; break; } cocos2d::Sprite* arg2; do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -5143,9 +4960,9 @@ bool js_cocos2dx_extension_ControlSwitch_create(JSContext *cx, uint32_t argc, js if (!ok) { ok = true; break; } cocos2d::Sprite* arg3; do { - if (!argv[3].isObject()) { ok = false; break; } + if (!args.get(3).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[3]); + JSObject *tmpObj = args.get(3).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg3 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); @@ -5153,9 +4970,9 @@ bool js_cocos2dx_extension_ControlSwitch_create(JSContext *cx, uint32_t argc, js if (!ok) { ok = true; break; } cocos2d::Label* arg4; do { - if (!argv[4].isObject()) { ok = false; break; } + if (!args.get(4).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[4]); + JSObject *tmpObj = args.get(4).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg4 = (cocos2d::Label*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg4, cx, false, "Invalid Native Object"); @@ -5163,9 +4980,9 @@ bool js_cocos2dx_extension_ControlSwitch_create(JSContext *cx, uint32_t argc, js if (!ok) { ok = true; break; } cocos2d::Label* arg5; do { - if (!argv[5].isObject()) { ok = false; break; } + if (!args.get(5).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[5]); + JSObject *tmpObj = args.get(5).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg5 = (cocos2d::Label*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg5, cx, false, "Invalid Native Object"); @@ -5181,7 +4998,7 @@ bool js_cocos2dx_extension_ControlSwitch_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -5190,7 +5007,7 @@ bool js_cocos2dx_extension_ControlSwitch_create(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_extension_ControlSwitch_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::extension::ControlSwitch* cobj = new (std::nothrow) cocos2d::extension::ControlSwitch(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -5204,13 +5021,16 @@ bool js_cocos2dx_extension_ControlSwitch_constructor(JSContext *cx, uint32_t arg CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlSwitch"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlSwitch"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -5223,21 +5043,21 @@ void js_cocos2d_extension_ControlSwitch_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_extension_ControlSwitch_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::extension::ControlSwitch *nobj = new (std::nothrow) cocos2d::extension::ControlSwitch(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlSwitch"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ControlSwitch"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_extension_ControlSwitch(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_ControlSwitch(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_ControlSwitch_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_ControlSwitch_class->name = "ControlSwitch"; jsb_cocos2d_extension_ControlSwitch_class->addProperty = JS_PropertyStub; @@ -5251,17 +5071,16 @@ void js_register_cocos2dx_extension_ControlSwitch(JSContext *cx, JSObject *globa jsb_cocos2d_extension_ControlSwitch_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("setEnabled", js_cocos2dx_extension_ControlSwitch_setEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setOn", js_cocos2dx_extension_ControlSwitch_setOn, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("locationFromTouch", js_cocos2dx_extension_ControlSwitch_locationFromTouch, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isOn", js_cocos2dx_extension_ControlSwitch_isOn, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("initWithMaskSprite", js_cocos2dx_extension_ControlSwitch_initWithMaskSprite, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("hasMoved", js_cocos2dx_extension_ControlSwitch_hasMoved, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("locationFromTouch", js_cocos2dx_extension_ControlSwitch_locationFromTouch, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2d_extension_ControlSwitch_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -5273,7 +5092,7 @@ void js_register_cocos2dx_extension_ControlSwitch(JSContext *cx, JSObject *globa jsb_cocos2d_extension_ControlSwitch_prototype = JS_InitClass( cx, global, - jsb_cocos2d_extension_Control_prototype, + JS::RootedObject(cx, jsb_cocos2d_extension_Control_prototype), jsb_cocos2d_extension_ControlSwitch_class, js_cocos2dx_extension_ControlSwitch_constructor, 0, // constructor properties, @@ -5304,7 +5123,8 @@ JSObject *jsb_cocos2d_extension_ScrollView_prototype; bool js_cocos2dx_extension_ScrollView_isClippingToBounds(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_isClippingToBounds : Invalid Native Object"); @@ -5312,7 +5132,7 @@ bool js_cocos2dx_extension_ScrollView_isClippingToBounds(JSContext *cx, uint32_t bool ret = cobj->isClippingToBounds(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5321,25 +5141,25 @@ bool js_cocos2dx_extension_ScrollView_isClippingToBounds(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ScrollView_setContainer(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_setContainer : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_setContainer : Error processing arguments"); cobj->setContainer(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5348,20 +5168,20 @@ bool js_cocos2dx_extension_ScrollView_setContainer(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ScrollView_setContentOffsetInDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_setContentOffsetInDuration : Invalid Native Object"); if (argc == 2) { cocos2d::Vec2 arg0; double arg1; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_setContentOffsetInDuration : Error processing arguments"); cobj->setContentOffsetInDuration(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5370,20 +5190,20 @@ bool js_cocos2dx_extension_ScrollView_setContentOffsetInDuration(JSContext *cx, } bool js_cocos2dx_extension_ScrollView_setZoomScaleInDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_setZoomScaleInDuration : Invalid Native Object"); if (argc == 2) { double arg0; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_setZoomScaleInDuration : Error processing arguments"); cobj->setZoomScaleInDuration(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5392,20 +5212,20 @@ bool js_cocos2dx_extension_ScrollView_setZoomScaleInDuration(JSContext *cx, uint } bool js_cocos2dx_extension_ScrollView_updateTweenAction(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_updateTweenAction : Invalid Native Object"); if (argc == 2) { double arg0; std::string arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_updateTweenAction : Error processing arguments"); cobj->updateTweenAction(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5414,18 +5234,18 @@ bool js_cocos2dx_extension_ScrollView_updateTweenAction(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ScrollView_setMaxScale(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_setMaxScale : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_setMaxScale : Error processing arguments"); cobj->setMaxScale(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5434,7 +5254,8 @@ bool js_cocos2dx_extension_ScrollView_setMaxScale(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ScrollView_hasVisibleParents(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_hasVisibleParents : Invalid Native Object"); @@ -5442,7 +5263,7 @@ bool js_cocos2dx_extension_ScrollView_hasVisibleParents(JSContext *cx, uint32_t bool ret = cobj->hasVisibleParents(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5451,7 +5272,8 @@ bool js_cocos2dx_extension_ScrollView_hasVisibleParents(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ScrollView_getDirection(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_getDirection : Invalid Native Object"); @@ -5459,7 +5281,7 @@ bool js_cocos2dx_extension_ScrollView_getDirection(JSContext *cx, uint32_t argc, int ret = (int)cobj->getDirection(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5468,7 +5290,8 @@ bool js_cocos2dx_extension_ScrollView_getDirection(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ScrollView_getContainer(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_getContainer : Invalid Native Object"); @@ -5483,7 +5306,7 @@ bool js_cocos2dx_extension_ScrollView_getContainer(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5492,18 +5315,18 @@ bool js_cocos2dx_extension_ScrollView_getContainer(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ScrollView_setMinScale(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_setMinScale : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_setMinScale : Error processing arguments"); cobj->setMinScale(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5512,7 +5335,8 @@ bool js_cocos2dx_extension_ScrollView_setMinScale(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ScrollView_getZoomScale(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_getZoomScale : Invalid Native Object"); @@ -5520,7 +5344,7 @@ bool js_cocos2dx_extension_ScrollView_getZoomScale(JSContext *cx, uint32_t argc, double ret = cobj->getZoomScale(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5529,13 +5353,14 @@ bool js_cocos2dx_extension_ScrollView_getZoomScale(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ScrollView_updateInset(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_updateInset : Invalid Native Object"); if (argc == 0) { cobj->updateInset(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5544,30 +5369,30 @@ bool js_cocos2dx_extension_ScrollView_updateInset(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ScrollView_initWithViewSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_initWithViewSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_initWithViewSize : Error processing arguments"); bool ret = cobj->initWithViewSize(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { cocos2d::Size arg0; cocos2d::Node* arg1; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -5576,7 +5401,7 @@ bool js_cocos2dx_extension_ScrollView_initWithViewSize(JSContext *cx, uint32_t a bool ret = cobj->initWithViewSize(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5585,25 +5410,25 @@ bool js_cocos2dx_extension_ScrollView_initWithViewSize(JSContext *cx, uint32_t a } bool js_cocos2dx_extension_ScrollView_pause(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_pause : Invalid Native Object"); if (argc == 1) { cocos2d::Ref* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Ref*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_pause : Error processing arguments"); cobj->pause(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5612,65 +5437,68 @@ bool js_cocos2dx_extension_ScrollView_pause(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_extension_ScrollView_setDirection(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_setDirection : Invalid Native Object"); if (argc == 1) { cocos2d::extension::ScrollView::Direction arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_setDirection : Error processing arguments"); cobj->setDirection(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ScrollView_setDirection : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_extension_ScrollView_init(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_extension_ScrollView_setBounceable(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_init : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->init(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_setBounceable : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_setBounceable : Error processing arguments"); + cobj->setBounceable(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_extension_ScrollView_init : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_extension_ScrollView_setBounceable : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_extension_ScrollView_setContentOffset(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_setContentOffset : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_setContentOffset : Error processing arguments"); cobj->setContentOffset(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { cocos2d::Vec2 arg0; bool arg1; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_setContentOffset : Error processing arguments"); cobj->setContentOffset(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5679,7 +5507,8 @@ bool js_cocos2dx_extension_ScrollView_setContentOffset(JSContext *cx, uint32_t a } bool js_cocos2dx_extension_ScrollView_isDragging(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_isDragging : Invalid Native Object"); @@ -5687,7 +5516,7 @@ bool js_cocos2dx_extension_ScrollView_isDragging(JSContext *cx, uint32_t argc, j bool ret = cobj->isDragging(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5696,7 +5525,8 @@ bool js_cocos2dx_extension_ScrollView_isDragging(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_extension_ScrollView_isTouchEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_isTouchEnabled : Invalid Native Object"); @@ -5704,7 +5534,7 @@ bool js_cocos2dx_extension_ScrollView_isTouchEnabled(JSContext *cx, uint32_t arg bool ret = cobj->isTouchEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5713,7 +5543,8 @@ bool js_cocos2dx_extension_ScrollView_isTouchEnabled(JSContext *cx, uint32_t arg } bool js_cocos2dx_extension_ScrollView_isBounceable(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_isBounceable : Invalid Native Object"); @@ -5721,7 +5552,7 @@ bool js_cocos2dx_extension_ScrollView_isBounceable(JSContext *cx, uint32_t argc, bool ret = cobj->isBounceable(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5730,18 +5561,18 @@ bool js_cocos2dx_extension_ScrollView_isBounceable(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ScrollView_setTouchEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_setTouchEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_setTouchEnabled : Error processing arguments"); cobj->setTouchEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5750,7 +5581,8 @@ bool js_cocos2dx_extension_ScrollView_setTouchEnabled(JSContext *cx, uint32_t ar } bool js_cocos2dx_extension_ScrollView_getContentOffset(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_getContentOffset : Invalid Native Object"); @@ -5758,7 +5590,7 @@ bool js_cocos2dx_extension_ScrollView_getContentOffset(JSContext *cx, uint32_t a cocos2d::Vec2 ret = cobj->getContentOffset(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5767,25 +5599,25 @@ bool js_cocos2dx_extension_ScrollView_getContentOffset(JSContext *cx, uint32_t a } bool js_cocos2dx_extension_ScrollView_resume(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_resume : Invalid Native Object"); if (argc == 1) { cocos2d::Ref* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Ref*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_resume : Error processing arguments"); cobj->resume(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5794,18 +5626,18 @@ bool js_cocos2dx_extension_ScrollView_resume(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_extension_ScrollView_setClippingToBounds(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_setClippingToBounds : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_setClippingToBounds : Error processing arguments"); cobj->setClippingToBounds(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5814,18 +5646,18 @@ bool js_cocos2dx_extension_ScrollView_setClippingToBounds(JSContext *cx, uint32_ } bool js_cocos2dx_extension_ScrollView_setViewSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_setViewSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_setViewSize : Error processing arguments"); cobj->setViewSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5834,7 +5666,8 @@ bool js_cocos2dx_extension_ScrollView_setViewSize(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ScrollView_getViewSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_getViewSize : Invalid Native Object"); @@ -5842,7 +5675,7 @@ bool js_cocos2dx_extension_ScrollView_getViewSize(JSContext *cx, uint32_t argc, cocos2d::Size ret = cobj->getViewSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5851,7 +5684,8 @@ bool js_cocos2dx_extension_ScrollView_getViewSize(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ScrollView_maxContainerOffset(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_maxContainerOffset : Invalid Native Object"); @@ -5859,36 +5693,17 @@ bool js_cocos2dx_extension_ScrollView_maxContainerOffset(JSContext *cx, uint32_t cocos2d::Vec2 ret = cobj->maxContainerOffset(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_ScrollView_maxContainerOffset : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_extension_ScrollView_setBounceable(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_setBounceable : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ScrollView_setBounceable : Error processing arguments"); - cobj->setBounceable(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_extension_ScrollView_setBounceable : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_extension_ScrollView_isTouchMoved(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_isTouchMoved : Invalid Native Object"); @@ -5896,7 +5711,7 @@ bool js_cocos2dx_extension_ScrollView_isTouchMoved(JSContext *cx, uint32_t argc, bool ret = cobj->isTouchMoved(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5905,18 +5720,18 @@ bool js_cocos2dx_extension_ScrollView_isTouchMoved(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ScrollView_isNodeVisible(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_isNodeVisible : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -5925,7 +5740,7 @@ bool js_cocos2dx_extension_ScrollView_isNodeVisible(JSContext *cx, uint32_t argc bool ret = cobj->isNodeVisible(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5934,7 +5749,8 @@ bool js_cocos2dx_extension_ScrollView_isNodeVisible(JSContext *cx, uint32_t argc } bool js_cocos2dx_extension_ScrollView_minContainerOffset(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_minContainerOffset : Invalid Native Object"); @@ -5942,7 +5758,7 @@ bool js_cocos2dx_extension_ScrollView_minContainerOffset(JSContext *cx, uint32_t cocos2d::Vec2 ret = cobj->minContainerOffset(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5951,24 +5767,24 @@ bool js_cocos2dx_extension_ScrollView_minContainerOffset(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ScrollView_setZoomScale(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::extension::ScrollView* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_setZoomScale : Invalid Native Object"); do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } bool arg1; - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); cobj->setZoomScale(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -5976,10 +5792,10 @@ bool js_cocos2dx_extension_ScrollView_setZoomScale(JSContext *cx, uint32_t argc, do { if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } cobj->setZoomScale(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -5989,7 +5805,7 @@ bool js_cocos2dx_extension_ScrollView_setZoomScale(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ScrollView_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { @@ -6004,7 +5820,7 @@ bool js_cocos2dx_extension_ScrollView_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -6012,7 +5828,7 @@ bool js_cocos2dx_extension_ScrollView_create(JSContext *cx, uint32_t argc, jsval do { if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::extension::ScrollView* ret = cocos2d::extension::ScrollView::create(arg0); jsval jsret = JSVAL_NULL; @@ -6024,20 +5840,20 @@ bool js_cocos2dx_extension_ScrollView_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 2) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Node* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -6053,7 +5869,7 @@ bool js_cocos2dx_extension_ScrollView_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -6062,7 +5878,7 @@ bool js_cocos2dx_extension_ScrollView_create(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_extension_ScrollView_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::extension::ScrollView* cobj = new (std::nothrow) cocos2d::extension::ScrollView(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -6076,13 +5892,16 @@ bool js_cocos2dx_extension_ScrollView_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ScrollView"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ScrollView"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -6095,21 +5914,21 @@ void js_cocos2d_extension_ScrollView_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_extension_ScrollView_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::extension::ScrollView *nobj = new (std::nothrow) cocos2d::extension::ScrollView(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ScrollView"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::ScrollView"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_extension_ScrollView(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_ScrollView(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_ScrollView_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_ScrollView_class->name = "ScrollView"; jsb_cocos2d_extension_ScrollView_class->addProperty = JS_PropertyStub; @@ -6123,8 +5942,8 @@ void js_register_cocos2dx_extension_ScrollView(JSContext *cx, JSObject *global) jsb_cocos2d_extension_ScrollView_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -6143,7 +5962,7 @@ void js_register_cocos2dx_extension_ScrollView(JSContext *cx, JSObject *global) JS_FN("initWithViewSize", js_cocos2dx_extension_ScrollView_initWithViewSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("pause", js_cocos2dx_extension_ScrollView_pause, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setDirection", js_cocos2dx_extension_ScrollView_setDirection, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_extension_ScrollView_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setBounceable", js_cocos2dx_extension_ScrollView_setBounceable, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setContentOffset", js_cocos2dx_extension_ScrollView_setContentOffset, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isDragging", js_cocos2dx_extension_ScrollView_isDragging, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isTouchEnabled", js_cocos2dx_extension_ScrollView_isTouchEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -6155,7 +5974,6 @@ void js_register_cocos2dx_extension_ScrollView(JSContext *cx, JSObject *global) JS_FN("setViewSize", js_cocos2dx_extension_ScrollView_setViewSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getViewSize", js_cocos2dx_extension_ScrollView_getViewSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("maxContainerOffset", js_cocos2dx_extension_ScrollView_maxContainerOffset, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setBounceable", js_cocos2dx_extension_ScrollView_setBounceable, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isTouchMoved", js_cocos2dx_extension_ScrollView_isTouchMoved, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isNodeVisible", js_cocos2dx_extension_ScrollView_isNodeVisible, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("minContainerOffset", js_cocos2dx_extension_ScrollView_minContainerOffset, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -6171,7 +5989,7 @@ void js_register_cocos2dx_extension_ScrollView(JSContext *cx, JSObject *global) jsb_cocos2d_extension_ScrollView_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Layer_prototype, + JS::RootedObject(cx, jsb_cocos2d_Layer_prototype), jsb_cocos2d_extension_ScrollView_class, js_cocos2dx_extension_ScrollView_constructor, 0, // constructor properties, @@ -6202,13 +6020,14 @@ JSObject *jsb_cocos2d_extension_TableViewCell_prototype; bool js_cocos2dx_extension_TableViewCell_reset(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableViewCell* cobj = (cocos2d::extension::TableViewCell *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableViewCell_reset : Invalid Native Object"); if (argc == 0) { cobj->reset(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6217,7 +6036,8 @@ bool js_cocos2dx_extension_TableViewCell_reset(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_extension_TableViewCell_getIdx(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableViewCell* cobj = (cocos2d::extension::TableViewCell *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableViewCell_getIdx : Invalid Native Object"); @@ -6225,7 +6045,7 @@ bool js_cocos2dx_extension_TableViewCell_getIdx(JSContext *cx, uint32_t argc, js ssize_t ret = cobj->getIdx(); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6234,18 +6054,18 @@ bool js_cocos2dx_extension_TableViewCell_getIdx(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_extension_TableViewCell_setIdx(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableViewCell* cobj = (cocos2d::extension::TableViewCell *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableViewCell_setIdx : Invalid Native Object"); if (argc == 1) { ssize_t arg0; - ok &= jsval_to_ssize(cx, argv[0], &arg0); + ok &= jsval_to_ssize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_TableViewCell_setIdx : Error processing arguments"); cobj->setIdx(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6254,6 +6074,7 @@ bool js_cocos2dx_extension_TableViewCell_setIdx(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_extension_TableViewCell_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::extension::TableViewCell* ret = cocos2d::extension::TableViewCell::create(); jsval jsret = JSVAL_NULL; @@ -6265,7 +6086,7 @@ bool js_cocos2dx_extension_TableViewCell_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_TableViewCell_create : wrong number of arguments"); @@ -6274,7 +6095,7 @@ bool js_cocos2dx_extension_TableViewCell_create(JSContext *cx, uint32_t argc, js bool js_cocos2dx_extension_TableViewCell_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::extension::TableViewCell* cobj = new (std::nothrow) cocos2d::extension::TableViewCell(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -6288,13 +6109,16 @@ bool js_cocos2dx_extension_TableViewCell_constructor(JSContext *cx, uint32_t arg CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::TableViewCell"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::TableViewCell"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -6307,21 +6131,21 @@ void js_cocos2d_extension_TableViewCell_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_extension_TableViewCell_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::extension::TableViewCell *nobj = new (std::nothrow) cocos2d::extension::TableViewCell(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::TableViewCell"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::TableViewCell"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_extension_TableViewCell(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_TableViewCell(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_TableViewCell_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_TableViewCell_class->name = "TableViewCell"; jsb_cocos2d_extension_TableViewCell_class->addProperty = JS_PropertyStub; @@ -6335,8 +6159,8 @@ void js_register_cocos2dx_extension_TableViewCell(JSContext *cx, JSObject *globa jsb_cocos2d_extension_TableViewCell_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -6354,7 +6178,7 @@ void js_register_cocos2dx_extension_TableViewCell(JSContext *cx, JSObject *globa jsb_cocos2d_extension_TableViewCell_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_extension_TableViewCell_class, js_cocos2dx_extension_TableViewCell_constructor, 0, // constructor properties, @@ -6385,18 +6209,18 @@ JSObject *jsb_cocos2d_extension_TableView_prototype; bool js_cocos2dx_extension_TableView_updateCellAtIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableView_updateCellAtIndex : Invalid Native Object"); if (argc == 1) { ssize_t arg0; - ok &= jsval_to_ssize(cx, argv[0], &arg0); + ok &= jsval_to_ssize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_TableView_updateCellAtIndex : Error processing arguments"); cobj->updateCellAtIndex(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6405,18 +6229,18 @@ bool js_cocos2dx_extension_TableView_updateCellAtIndex(JSContext *cx, uint32_t a } bool js_cocos2dx_extension_TableView_setVerticalFillOrder(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableView_setVerticalFillOrder : Invalid Native Object"); if (argc == 1) { cocos2d::extension::TableView::VerticalFillOrder arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_TableView_setVerticalFillOrder : Error processing arguments"); cobj->setVerticalFillOrder(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6425,25 +6249,25 @@ bool js_cocos2dx_extension_TableView_setVerticalFillOrder(JSContext *cx, uint32_ } bool js_cocos2dx_extension_TableView_scrollViewDidZoom(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableView_scrollViewDidZoom : Invalid Native Object"); if (argc == 1) { cocos2d::extension::ScrollView* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::extension::ScrollView*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_TableView_scrollViewDidZoom : Error processing arguments"); cobj->scrollViewDidZoom(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6452,13 +6276,14 @@ bool js_cocos2dx_extension_TableView_scrollViewDidZoom(JSContext *cx, uint32_t a } bool js_cocos2dx_extension_TableView__updateContentSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableView__updateContentSize : Invalid Native Object"); if (argc == 0) { cobj->_updateContentSize(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6467,7 +6292,8 @@ bool js_cocos2dx_extension_TableView__updateContentSize(JSContext *cx, uint32_t } bool js_cocos2dx_extension_TableView_getVerticalFillOrder(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableView_getVerticalFillOrder : Invalid Native Object"); @@ -6475,7 +6301,7 @@ bool js_cocos2dx_extension_TableView_getVerticalFillOrder(JSContext *cx, uint32_ int ret = (int)cobj->getVerticalFillOrder(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6484,18 +6310,18 @@ bool js_cocos2dx_extension_TableView_getVerticalFillOrder(JSContext *cx, uint32_ } bool js_cocos2dx_extension_TableView_removeCellAtIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableView_removeCellAtIndex : Invalid Native Object"); if (argc == 1) { ssize_t arg0; - ok &= jsval_to_ssize(cx, argv[0], &arg0); + ok &= jsval_to_ssize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_TableView_removeCellAtIndex : Error processing arguments"); cobj->removeCellAtIndex(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6504,30 +6330,30 @@ bool js_cocos2dx_extension_TableView_removeCellAtIndex(JSContext *cx, uint32_t a } bool js_cocos2dx_extension_TableView_initWithViewSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableView_initWithViewSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_TableView_initWithViewSize : Error processing arguments"); bool ret = cobj->initWithViewSize(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { cocos2d::Size arg0; cocos2d::Node* arg1; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -6536,7 +6362,7 @@ bool js_cocos2dx_extension_TableView_initWithViewSize(JSContext *cx, uint32_t ar bool ret = cobj->initWithViewSize(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6545,25 +6371,25 @@ bool js_cocos2dx_extension_TableView_initWithViewSize(JSContext *cx, uint32_t ar } bool js_cocos2dx_extension_TableView_scrollViewDidScroll(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableView_scrollViewDidScroll : Invalid Native Object"); if (argc == 1) { cocos2d::extension::ScrollView* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::extension::ScrollView*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_TableView_scrollViewDidScroll : Error processing arguments"); cobj->scrollViewDidScroll(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6572,13 +6398,14 @@ bool js_cocos2dx_extension_TableView_scrollViewDidScroll(JSContext *cx, uint32_t } bool js_cocos2dx_extension_TableView_reloadData(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableView_reloadData : Invalid Native Object"); if (argc == 0) { cobj->reloadData(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6587,18 +6414,18 @@ bool js_cocos2dx_extension_TableView_reloadData(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_extension_TableView_insertCellAtIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableView_insertCellAtIndex : Invalid Native Object"); if (argc == 1) { ssize_t arg0; - ok &= jsval_to_ssize(cx, argv[0], &arg0); + ok &= jsval_to_ssize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_TableView_insertCellAtIndex : Error processing arguments"); cobj->insertCellAtIndex(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6607,15 +6434,15 @@ bool js_cocos2dx_extension_TableView_insertCellAtIndex(JSContext *cx, uint32_t a } bool js_cocos2dx_extension_TableView_cellAtIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableView_cellAtIndex : Invalid Native Object"); if (argc == 1) { ssize_t arg0; - ok &= jsval_to_ssize(cx, argv[0], &arg0); + ok &= jsval_to_ssize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_TableView_cellAtIndex : Error processing arguments"); cocos2d::extension::TableViewCell* ret = cobj->cellAtIndex(arg0); jsval jsret = JSVAL_NULL; @@ -6627,7 +6454,7 @@ bool js_cocos2dx_extension_TableView_cellAtIndex(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6636,7 +6463,8 @@ bool js_cocos2dx_extension_TableView_cellAtIndex(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_extension_TableView_dequeueCell(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_TableView_dequeueCell : Invalid Native Object"); @@ -6651,7 +6479,7 @@ bool js_cocos2dx_extension_TableView_dequeueCell(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6660,7 +6488,7 @@ bool js_cocos2dx_extension_TableView_dequeueCell(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_extension_TableView_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::extension::TableView* cobj = new (std::nothrow) cocos2d::extension::TableView(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -6674,13 +6502,16 @@ bool js_cocos2dx_extension_TableView_constructor(JSContext *cx, uint32_t argc, j CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::TableView"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::TableView"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -6693,21 +6524,21 @@ void js_cocos2d_extension_TableView_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_extension_TableView_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::extension::TableView *nobj = new (std::nothrow) cocos2d::extension::TableView(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::TableView"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::TableView"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_extension_TableView(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_TableView(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_TableView_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_TableView_class->name = "TableView"; jsb_cocos2d_extension_TableView_class->addProperty = JS_PropertyStub; @@ -6721,8 +6552,8 @@ void js_register_cocos2dx_extension_TableView(JSContext *cx, JSObject *global) { jsb_cocos2d_extension_TableView_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -6746,7 +6577,7 @@ void js_register_cocos2dx_extension_TableView(JSContext *cx, JSObject *global) { jsb_cocos2d_extension_TableView_prototype = JS_InitClass( cx, global, - jsb_cocos2d_extension_ScrollView_prototype, + JS::RootedObject(cx, jsb_cocos2d_extension_ScrollView_prototype), jsb_cocos2d_extension_TableView_class, js_cocos2dx_extension_TableView_constructor, 0, // constructor properties, @@ -6777,7 +6608,8 @@ JSObject *jsb_cocos2d_extension_EventAssetsManagerEx_prototype; bool js_cocos2dx_extension_EventAssetsManagerEx_getAssetsManagerEx(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::EventAssetsManagerEx* cobj = (cocos2d::extension::EventAssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_EventAssetsManagerEx_getAssetsManagerEx : Invalid Native Object"); @@ -6792,7 +6624,7 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getAssetsManagerEx(JSContext *cx jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6801,7 +6633,8 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getAssetsManagerEx(JSContext *cx } bool js_cocos2dx_extension_EventAssetsManagerEx_getAssetId(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::EventAssetsManagerEx* cobj = (cocos2d::extension::EventAssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_EventAssetsManagerEx_getAssetId : Invalid Native Object"); @@ -6809,7 +6642,7 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getAssetId(JSContext *cx, uint32 std::string ret = cobj->getAssetId(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6818,7 +6651,8 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getAssetId(JSContext *cx, uint32 } bool js_cocos2dx_extension_EventAssetsManagerEx_getCURLECode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::EventAssetsManagerEx* cobj = (cocos2d::extension::EventAssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_EventAssetsManagerEx_getCURLECode : Invalid Native Object"); @@ -6826,7 +6660,7 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getCURLECode(JSContext *cx, uint int ret = cobj->getCURLECode(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6835,7 +6669,8 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getCURLECode(JSContext *cx, uint } bool js_cocos2dx_extension_EventAssetsManagerEx_getMessage(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::EventAssetsManagerEx* cobj = (cocos2d::extension::EventAssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_EventAssetsManagerEx_getMessage : Invalid Native Object"); @@ -6843,7 +6678,7 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getMessage(JSContext *cx, uint32 std::string ret = cobj->getMessage(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6852,7 +6687,8 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getMessage(JSContext *cx, uint32 } bool js_cocos2dx_extension_EventAssetsManagerEx_getCURLMCode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::EventAssetsManagerEx* cobj = (cocos2d::extension::EventAssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_EventAssetsManagerEx_getCURLMCode : Invalid Native Object"); @@ -6860,7 +6696,7 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getCURLMCode(JSContext *cx, uint int ret = cobj->getCURLMCode(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6869,7 +6705,8 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getCURLMCode(JSContext *cx, uint } bool js_cocos2dx_extension_EventAssetsManagerEx_getPercentByFile(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::EventAssetsManagerEx* cobj = (cocos2d::extension::EventAssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_EventAssetsManagerEx_getPercentByFile : Invalid Native Object"); @@ -6877,7 +6714,7 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getPercentByFile(JSContext *cx, double ret = cobj->getPercentByFile(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6886,7 +6723,8 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getPercentByFile(JSContext *cx, } bool js_cocos2dx_extension_EventAssetsManagerEx_getEventCode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::EventAssetsManagerEx* cobj = (cocos2d::extension::EventAssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_EventAssetsManagerEx_getEventCode : Invalid Native Object"); @@ -6894,7 +6732,7 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getEventCode(JSContext *cx, uint int ret = (int)cobj->getEventCode(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6903,7 +6741,8 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getEventCode(JSContext *cx, uint } bool js_cocos2dx_extension_EventAssetsManagerEx_getPercent(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::EventAssetsManagerEx* cobj = (cocos2d::extension::EventAssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_EventAssetsManagerEx_getPercent : Invalid Native Object"); @@ -6911,7 +6750,7 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getPercent(JSContext *cx, uint32 double ret = cobj->getPercent(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6920,21 +6759,21 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_getPercent(JSContext *cx, uint32 } bool js_cocos2dx_extension_EventAssetsManagerEx_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; std::string arg0; cocos2d::extension::AssetsManagerEx* arg1; cocos2d::extension::EventAssetsManagerEx::EventCode arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::extension::AssetsManagerEx*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_EventAssetsManagerEx_constructor : Error processing arguments"); cocos2d::extension::EventAssetsManagerEx* cobj = new (std::nothrow) cocos2d::extension::EventAssetsManagerEx(arg0, arg1, arg2); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -6948,13 +6787,16 @@ bool js_cocos2dx_extension_EventAssetsManagerEx_constructor(JSContext *cx, uint3 CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::EventAssetsManagerEx"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::EventAssetsManagerEx"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -6965,7 +6807,7 @@ void js_cocos2d_extension_EventAssetsManagerEx_finalize(JSFreeOp *fop, JSObject CCLOGINFO("jsbindings: finalizing JS object %p (EventAssetsManagerEx)", obj); } -void js_register_cocos2dx_extension_EventAssetsManagerEx(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_EventAssetsManagerEx(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_EventAssetsManagerEx_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_EventAssetsManagerEx_class->name = "EventAssetsManager"; jsb_cocos2d_extension_EventAssetsManagerEx_class->addProperty = JS_PropertyStub; @@ -6979,8 +6821,8 @@ void js_register_cocos2dx_extension_EventAssetsManagerEx(JSContext *cx, JSObject jsb_cocos2d_extension_EventAssetsManagerEx_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -6999,7 +6841,7 @@ void js_register_cocos2dx_extension_EventAssetsManagerEx(JSContext *cx, JSObject jsb_cocos2d_extension_EventAssetsManagerEx_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EventCustom_prototype, + JS::RootedObject(cx, jsb_cocos2d_EventCustom_prototype), jsb_cocos2d_extension_EventAssetsManagerEx_class, js_cocos2dx_extension_EventAssetsManagerEx_constructor, 0, // constructor properties, @@ -7030,7 +6872,8 @@ JSObject *jsb_cocos2d_extension_Manifest_prototype; bool js_cocos2dx_extension_Manifest_getManifestFileUrl(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Manifest* cobj = (cocos2d::extension::Manifest *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Manifest_getManifestFileUrl : Invalid Native Object"); @@ -7038,7 +6881,7 @@ bool js_cocos2dx_extension_Manifest_getManifestFileUrl(JSContext *cx, uint32_t a const std::string& ret = cobj->getManifestFileUrl(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7047,7 +6890,8 @@ bool js_cocos2dx_extension_Manifest_getManifestFileUrl(JSContext *cx, uint32_t a } bool js_cocos2dx_extension_Manifest_isVersionLoaded(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Manifest* cobj = (cocos2d::extension::Manifest *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Manifest_isVersionLoaded : Invalid Native Object"); @@ -7055,7 +6899,7 @@ bool js_cocos2dx_extension_Manifest_isVersionLoaded(JSContext *cx, uint32_t argc bool ret = cobj->isVersionLoaded(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7064,7 +6908,8 @@ bool js_cocos2dx_extension_Manifest_isVersionLoaded(JSContext *cx, uint32_t argc } bool js_cocos2dx_extension_Manifest_isLoaded(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Manifest* cobj = (cocos2d::extension::Manifest *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Manifest_isLoaded : Invalid Native Object"); @@ -7072,7 +6917,7 @@ bool js_cocos2dx_extension_Manifest_isLoaded(JSContext *cx, uint32_t argc, jsval bool ret = cobj->isLoaded(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7081,7 +6926,8 @@ bool js_cocos2dx_extension_Manifest_isLoaded(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_extension_Manifest_getPackageUrl(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Manifest* cobj = (cocos2d::extension::Manifest *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Manifest_getPackageUrl : Invalid Native Object"); @@ -7089,7 +6935,7 @@ bool js_cocos2dx_extension_Manifest_getPackageUrl(JSContext *cx, uint32_t argc, const std::string& ret = cobj->getPackageUrl(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7098,7 +6944,8 @@ bool js_cocos2dx_extension_Manifest_getPackageUrl(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_Manifest_getVersion(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Manifest* cobj = (cocos2d::extension::Manifest *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Manifest_getVersion : Invalid Native Object"); @@ -7106,7 +6953,7 @@ bool js_cocos2dx_extension_Manifest_getVersion(JSContext *cx, uint32_t argc, jsv const std::string& ret = cobj->getVersion(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7115,7 +6962,8 @@ bool js_cocos2dx_extension_Manifest_getVersion(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_extension_Manifest_getVersionFileUrl(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Manifest* cobj = (cocos2d::extension::Manifest *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Manifest_getVersionFileUrl : Invalid Native Object"); @@ -7123,7 +6971,7 @@ bool js_cocos2dx_extension_Manifest_getVersionFileUrl(JSContext *cx, uint32_t ar const std::string& ret = cobj->getVersionFileUrl(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7132,7 +6980,8 @@ bool js_cocos2dx_extension_Manifest_getVersionFileUrl(JSContext *cx, uint32_t ar } bool js_cocos2dx_extension_Manifest_getSearchPaths(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Manifest* cobj = (cocos2d::extension::Manifest *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_Manifest_getSearchPaths : Invalid Native Object"); @@ -7140,7 +6989,7 @@ bool js_cocos2dx_extension_Manifest_getSearchPaths(JSContext *cx, uint32_t argc, std::vector ret = cobj->getSearchPaths(); jsval jsret = JSVAL_NULL; jsret = std_vector_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7153,7 +7002,7 @@ void js_cocos2d_extension_Manifest_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Manifest)", obj); } -void js_register_cocos2dx_extension_Manifest(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_Manifest(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_Manifest_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_Manifest_class->name = "Manifest"; jsb_cocos2d_extension_Manifest_class->addProperty = JS_PropertyStub; @@ -7167,8 +7016,8 @@ void js_register_cocos2dx_extension_Manifest(JSContext *cx, JSObject *global) { jsb_cocos2d_extension_Manifest_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -7186,7 +7035,7 @@ void js_register_cocos2dx_extension_Manifest(JSContext *cx, JSObject *global) { jsb_cocos2d_extension_Manifest_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_extension_Manifest_class, empty_constructor, 0, properties, @@ -7217,7 +7066,8 @@ JSObject *jsb_cocos2d_extension_AssetsManagerEx_prototype; bool js_cocos2dx_extension_AssetsManagerEx_getState(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::AssetsManagerEx* cobj = (cocos2d::extension::AssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_AssetsManagerEx_getState : Invalid Native Object"); @@ -7225,7 +7075,7 @@ bool js_cocos2dx_extension_AssetsManagerEx_getState(JSContext *cx, uint32_t argc int ret = (int)cobj->getState(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7234,13 +7084,14 @@ bool js_cocos2dx_extension_AssetsManagerEx_getState(JSContext *cx, uint32_t argc } bool js_cocos2dx_extension_AssetsManagerEx_checkUpdate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::AssetsManagerEx* cobj = (cocos2d::extension::AssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_AssetsManagerEx_checkUpdate : Invalid Native Object"); if (argc == 0) { cobj->checkUpdate(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7249,7 +7100,8 @@ bool js_cocos2dx_extension_AssetsManagerEx_checkUpdate(JSContext *cx, uint32_t a } bool js_cocos2dx_extension_AssetsManagerEx_getStoragePath(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::AssetsManagerEx* cobj = (cocos2d::extension::AssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_AssetsManagerEx_getStoragePath : Invalid Native Object"); @@ -7257,7 +7109,7 @@ bool js_cocos2dx_extension_AssetsManagerEx_getStoragePath(JSContext *cx, uint32_ const std::string& ret = cobj->getStoragePath(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7266,13 +7118,14 @@ bool js_cocos2dx_extension_AssetsManagerEx_getStoragePath(JSContext *cx, uint32_ } bool js_cocos2dx_extension_AssetsManagerEx_update(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::AssetsManagerEx* cobj = (cocos2d::extension::AssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_AssetsManagerEx_update : Invalid Native Object"); if (argc == 0) { cobj->update(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7281,7 +7134,8 @@ bool js_cocos2dx_extension_AssetsManagerEx_update(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_AssetsManagerEx_getLocalManifest(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::AssetsManagerEx* cobj = (cocos2d::extension::AssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_AssetsManagerEx_getLocalManifest : Invalid Native Object"); @@ -7296,7 +7150,7 @@ bool js_cocos2dx_extension_AssetsManagerEx_getLocalManifest(JSContext *cx, uint3 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7305,7 +7159,8 @@ bool js_cocos2dx_extension_AssetsManagerEx_getLocalManifest(JSContext *cx, uint3 } bool js_cocos2dx_extension_AssetsManagerEx_getRemoteManifest(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::AssetsManagerEx* cobj = (cocos2d::extension::AssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_AssetsManagerEx_getRemoteManifest : Invalid Native Object"); @@ -7320,7 +7175,7 @@ bool js_cocos2dx_extension_AssetsManagerEx_getRemoteManifest(JSContext *cx, uint jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7329,13 +7184,14 @@ bool js_cocos2dx_extension_AssetsManagerEx_getRemoteManifest(JSContext *cx, uint } bool js_cocos2dx_extension_AssetsManagerEx_downloadFailedAssets(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::AssetsManagerEx* cobj = (cocos2d::extension::AssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_AssetsManagerEx_downloadFailedAssets : Invalid Native Object"); if (argc == 0) { cobj->downloadFailedAssets(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7344,13 +7200,13 @@ bool js_cocos2dx_extension_AssetsManagerEx_downloadFailedAssets(JSContext *cx, u } bool js_cocos2dx_extension_AssetsManagerEx_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_AssetsManagerEx_create : Error processing arguments"); cocos2d::extension::AssetsManagerEx* ret = cocos2d::extension::AssetsManagerEx::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -7362,7 +7218,7 @@ bool js_cocos2dx_extension_AssetsManagerEx_create(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_AssetsManagerEx_create : wrong number of arguments"); @@ -7371,12 +7227,12 @@ bool js_cocos2dx_extension_AssetsManagerEx_create(JSContext *cx, uint32_t argc, bool js_cocos2dx_extension_AssetsManagerEx_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_AssetsManagerEx_constructor : Error processing arguments"); cocos2d::extension::AssetsManagerEx* cobj = new (std::nothrow) cocos2d::extension::AssetsManagerEx(arg0, arg1); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -7390,13 +7246,16 @@ bool js_cocos2dx_extension_AssetsManagerEx_constructor(JSContext *cx, uint32_t a CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::AssetsManagerEx"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::AssetsManagerEx"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -7406,7 +7265,7 @@ void js_cocos2d_extension_AssetsManagerEx_finalize(JSFreeOp *fop, JSObject *obj) CCLOGINFO("jsbindings: finalizing JS object %p (AssetsManagerEx)", obj); } -void js_register_cocos2dx_extension_AssetsManagerEx(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_AssetsManagerEx(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_AssetsManagerEx_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_AssetsManagerEx_class->name = "AssetsManager"; jsb_cocos2d_extension_AssetsManagerEx_class->addProperty = JS_PropertyStub; @@ -7420,8 +7279,8 @@ void js_register_cocos2dx_extension_AssetsManagerEx(JSContext *cx, JSObject *glo jsb_cocos2d_extension_AssetsManagerEx_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -7442,7 +7301,7 @@ void js_register_cocos2dx_extension_AssetsManagerEx(JSContext *cx, JSObject *glo jsb_cocos2d_extension_AssetsManagerEx_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_extension_AssetsManagerEx_class, js_cocos2dx_extension_AssetsManagerEx_constructor, 0, // constructor properties, @@ -7473,9 +7332,9 @@ JSObject *jsb_cocos2d_extension_EventListenerAssetsManagerEx_prototype; bool js_cocos2dx_extension_EventListenerAssetsManagerEx_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::EventListenerAssetsManagerEx* cobj = (cocos2d::extension::EventListenerAssetsManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_EventListenerAssetsManagerEx_init : Invalid Native Object"); @@ -7483,18 +7342,19 @@ bool js_cocos2dx_extension_EventListenerAssetsManagerEx_init(JSContext *cx, uint const cocos2d::extension::AssetsManagerEx* arg0; std::function arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (const cocos2d::extension::AssetsManagerEx*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](cocos2d::extension::EventAssetsManagerEx* larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -7504,8 +7364,8 @@ bool js_cocos2dx_extension_EventListenerAssetsManagerEx_init(JSContext *cx, uint largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -7522,7 +7382,7 @@ bool js_cocos2dx_extension_EventListenerAssetsManagerEx_init(JSContext *cx, uint bool ret = cobj->init(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7531,24 +7391,25 @@ bool js_cocos2dx_extension_EventListenerAssetsManagerEx_init(JSContext *cx, uint } bool js_cocos2dx_extension_EventListenerAssetsManagerEx_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::extension::AssetsManagerEx* arg0; std::function arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::extension::AssetsManagerEx*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](cocos2d::extension::EventAssetsManagerEx* larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -7558,8 +7419,8 @@ bool js_cocos2dx_extension_EventListenerAssetsManagerEx_create(JSContext *cx, ui largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -7583,7 +7444,7 @@ bool js_cocos2dx_extension_EventListenerAssetsManagerEx_create(JSContext *cx, ui jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_extension_EventListenerAssetsManagerEx_create : wrong number of arguments"); @@ -7592,7 +7453,7 @@ bool js_cocos2dx_extension_EventListenerAssetsManagerEx_create(JSContext *cx, ui bool js_cocos2dx_extension_EventListenerAssetsManagerEx_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::extension::EventListenerAssetsManagerEx* cobj = new (std::nothrow) cocos2d::extension::EventListenerAssetsManagerEx(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -7606,13 +7467,16 @@ bool js_cocos2dx_extension_EventListenerAssetsManagerEx_constructor(JSContext *c CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::EventListenerAssetsManagerEx"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::EventListenerAssetsManagerEx"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -7623,7 +7487,7 @@ void js_cocos2d_extension_EventListenerAssetsManagerEx_finalize(JSFreeOp *fop, J CCLOGINFO("jsbindings: finalizing JS object %p (EventListenerAssetsManagerEx)", obj); } -void js_register_cocos2dx_extension_EventListenerAssetsManagerEx(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_extension_EventListenerAssetsManagerEx(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_extension_EventListenerAssetsManagerEx_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_extension_EventListenerAssetsManagerEx_class->name = "EventListenerAssetsManager"; jsb_cocos2d_extension_EventListenerAssetsManagerEx_class->addProperty = JS_PropertyStub; @@ -7637,8 +7501,8 @@ void js_register_cocos2dx_extension_EventListenerAssetsManagerEx(JSContext *cx, jsb_cocos2d_extension_EventListenerAssetsManagerEx_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -7653,7 +7517,7 @@ void js_register_cocos2dx_extension_EventListenerAssetsManagerEx(JSContext *cx, jsb_cocos2d_extension_EventListenerAssetsManagerEx_prototype = JS_InitClass( cx, global, - jsb_cocos2d_EventListenerCustom_prototype, + JS::RootedObject(cx, jsb_cocos2d_EventListenerCustom_prototype), jsb_cocos2d_extension_EventListenerAssetsManagerEx_class, js_cocos2dx_extension_EventListenerAssetsManagerEx_constructor, 0, // constructor properties, @@ -7679,35 +7543,26 @@ void js_register_cocos2dx_extension_EventListenerAssetsManagerEx(JSContext *cx, } } -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj) { - // first, try to get the ns - JS::RootedValue nsval(cx); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj) { + // Get the ns JS::RootedObject ns(cx); - JS_GetProperty(cx, obj, "cc", &nsval); - if (nsval == JSVAL_VOID) { - ns = JS_NewObject(cx, NULL, NULL, NULL); - nsval = OBJECT_TO_JSVAL(ns); - JS_SetProperty(cx, obj, "cc", nsval); - } else { - JS_ValueToObject(cx, nsval, &ns); - } - obj = ns; - - js_register_cocos2dx_extension_AssetsManagerEx(cx, obj); - js_register_cocos2dx_extension_Control(cx, obj); - js_register_cocos2dx_extension_ControlHuePicker(cx, obj); - js_register_cocos2dx_extension_TableViewCell(cx, obj); - js_register_cocos2dx_extension_ControlStepper(cx, obj); - js_register_cocos2dx_extension_ControlColourPicker(cx, obj); - js_register_cocos2dx_extension_ControlButton(cx, obj); - js_register_cocos2dx_extension_ControlSlider(cx, obj); - js_register_cocos2dx_extension_ControlSaturationBrightnessPicker(cx, obj); - js_register_cocos2dx_extension_ScrollView(cx, obj); - js_register_cocos2dx_extension_Manifest(cx, obj); - js_register_cocos2dx_extension_ControlPotentiometer(cx, obj); - js_register_cocos2dx_extension_EventAssetsManagerEx(cx, obj); - js_register_cocos2dx_extension_TableView(cx, obj); - js_register_cocos2dx_extension_EventListenerAssetsManagerEx(cx, obj); - js_register_cocos2dx_extension_ControlSwitch(cx, obj); + get_or_create_js_obj(cx, obj, "cc", &ns); + + js_register_cocos2dx_extension_AssetsManagerEx(cx, ns); + js_register_cocos2dx_extension_Control(cx, ns); + js_register_cocos2dx_extension_ControlHuePicker(cx, ns); + js_register_cocos2dx_extension_TableViewCell(cx, ns); + js_register_cocos2dx_extension_ControlStepper(cx, ns); + js_register_cocos2dx_extension_ControlColourPicker(cx, ns); + js_register_cocos2dx_extension_ControlButton(cx, ns); + js_register_cocos2dx_extension_ControlSlider(cx, ns); + js_register_cocos2dx_extension_ControlSaturationBrightnessPicker(cx, ns); + js_register_cocos2dx_extension_ScrollView(cx, ns); + js_register_cocos2dx_extension_Manifest(cx, ns); + js_register_cocos2dx_extension_ControlPotentiometer(cx, ns); + js_register_cocos2dx_extension_EventAssetsManagerEx(cx, ns); + js_register_cocos2dx_extension_TableView(cx, ns); + js_register_cocos2dx_extension_EventListenerAssetsManagerEx(cx, ns); + js_register_cocos2dx_extension_ControlSwitch(cx, ns); } diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_extension_auto.hpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_extension_auto.hpp index 9296ca4ba9..8700193dd0 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_extension_auto.hpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_extension_auto.hpp @@ -10,8 +10,8 @@ extern JSObject *jsb_cocos2d_extension_Control_prototype; bool js_cocos2dx_extension_Control_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_Control_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_Control(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_extension_Control(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_Control_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_Control_getState(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_Control_sendActionsForControlEvents(JSContext *cx, uint32_t argc, jsval *vp); @@ -32,14 +32,11 @@ extern JSObject *jsb_cocos2d_extension_ControlButton_prototype; bool js_cocos2dx_extension_ControlButton_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_ControlButton_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_ControlButton(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_extension_ControlButton(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_ControlButton_isPushed(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlButton_setSelected(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_setTitleLabelForState(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_setAdjustBackgroundImage(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlButton_setHighlighted(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlButton_setZoomOnTouchDown(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_setTitleForState(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_setLabelAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_getLabelAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp); @@ -50,13 +47,12 @@ bool js_cocos2dx_extension_ControlButton_setTitleTTFSizeForState(JSContext *cx, bool js_cocos2dx_extension_ControlButton_setTitleLabel(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_setPreferredSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_getCurrentTitleColor(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlButton_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlButton_setZoomOnTouchDown(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_setBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_getBackgroundSpriteForState(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_getHorizontalOrigin(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlButton_needsLayout(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_initWithTitleAndFontNameAndFontSize(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlButton_getCurrentTitle(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlButton_setTitleBMFontForState(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_getScaleRatio(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_getTitleTTFForState(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_getBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp); @@ -66,14 +62,14 @@ bool js_cocos2dx_extension_ControlButton_doesAdjustBackgroundImage(JSContext *cx bool js_cocos2dx_extension_ControlButton_setBackgroundSpriteFrameForState(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_setBackgroundSpriteForState(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_setScaleRatio(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlButton_getTitleBMFontForState(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_getTitleLabel(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_getPreferredSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_getVerticalMargin(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_getTitleLabelForState(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_setMargins(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlButton_setTitleBMFontForState(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlButton_getTitleBMFontForState(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlButton_getCurrentTitle(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_getZoomOnTouchDown(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_getTitleForState(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlButton_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -84,9 +80,8 @@ extern JSObject *jsb_cocos2d_extension_ControlHuePicker_prototype; bool js_cocos2dx_extension_ControlHuePicker_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_ControlHuePicker_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_ControlHuePicker(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); -bool js_cocos2dx_extension_ControlHuePicker_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_extension_ControlHuePicker(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_ControlHuePicker_initWithTargetAndPos(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlHuePicker_setHue(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlHuePicker_getStartPos(JSContext *cx, uint32_t argc, jsval *vp); @@ -105,13 +100,12 @@ extern JSObject *jsb_cocos2d_extension_ControlSaturationBrightnessPicker_prototy bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_ControlSaturationBrightnessPicker_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_ControlSaturationBrightnessPicker(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_extension_ControlSaturationBrightnessPicker(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getShadow(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_initWithTargetAndPos(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getStartPos(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getOverlay(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getSlider(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getBackground(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getSaturation(JSContext *cx, uint32_t argc, jsval *vp); @@ -124,12 +118,10 @@ extern JSObject *jsb_cocos2d_extension_ControlColourPicker_prototype; bool js_cocos2dx_extension_ControlColourPicker_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_ControlColourPicker_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_ControlColourPicker(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); -bool js_cocos2dx_extension_ControlColourPicker_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlColourPicker_getHuePicker(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlColourPicker_setColor(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_extension_ControlColourPicker(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_ControlColourPicker_hueSliderValueChanged(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlColourPicker_getHuePicker(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlColourPicker_getcolourPicker(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlColourPicker_setBackground(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlColourPicker_setcolourPicker(JSContext *cx, uint32_t argc, jsval *vp); @@ -144,8 +136,8 @@ extern JSObject *jsb_cocos2d_extension_ControlPotentiometer_prototype; bool js_cocos2dx_extension_ControlPotentiometer_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_ControlPotentiometer_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_ControlPotentiometer(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_extension_ControlPotentiometer(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_ControlPotentiometer_setPreviousLocation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlPotentiometer_setValue(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlPotentiometer_getProgressTimer(JSContext *cx, uint32_t argc, jsval *vp); @@ -172,30 +164,27 @@ extern JSObject *jsb_cocos2d_extension_ControlSlider_prototype; bool js_cocos2dx_extension_ControlSlider_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_ControlSlider_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_ControlSlider(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); -bool js_cocos2dx_extension_ControlSlider_getSelectedThumbSprite(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSlider_locationFromTouch(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSlider_setSelectedThumbSprite(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSlider_setProgressSprite(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_extension_ControlSlider(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_extension_ControlSlider_setBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSlider_getMaximumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlSlider_initWithSprites(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSlider_getMinimumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlSlider_getMaximumValue(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlSlider_getSelectedThumbSprite(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlSlider_setProgressSprite(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlSlider_setMaximumValue(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSlider_getMinimumValue(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSlider_setThumbSprite(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSlider_setMinimumValue(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSlider_setMinimumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSlider_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSlider_setValue(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSlider_setMaximumValue(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSlider_needsLayout(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSlider_getBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSlider_initWithSprites(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSlider_getMaximumValue(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSlider_isTouchInside(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSlider_getValue(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlSlider_getBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSlider_getThumbSprite(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlSlider_setValue(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlSlider_locationFromTouch(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlSlider_setMinimumValue(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlSlider_setMinimumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSlider_getProgressSprite(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSlider_setBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlSlider_setSelectedThumbSprite(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSlider_setMaximumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSlider_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSlider_ControlSlider(JSContext *cx, uint32_t argc, jsval *vp); @@ -205,29 +194,28 @@ extern JSObject *jsb_cocos2d_extension_ControlStepper_prototype; bool js_cocos2dx_extension_ControlStepper_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_ControlStepper_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_ControlStepper(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); -bool js_cocos2dx_extension_ControlStepper_setMinusSprite(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlStepper_getMinusLabel(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlStepper_setWraps(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlStepper_isContinuous(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_extension_ControlStepper(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_ControlStepper_getMinusSprite(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlStepper_updateLayoutUsingTouchLocation(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlStepper_setValue(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlStepper_setStepValue(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlStepper_setValueWithSendingEvent(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlStepper_setMaximumValue(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlStepper_getMinusLabel(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlStepper_getPlusLabel(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlStepper_setWraps(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlStepper_setMinusLabel(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlStepper_startAutorepeat(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlStepper_updateLayoutUsingTouchLocation(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlStepper_isContinuous(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlStepper_stopAutorepeat(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlStepper_setMinimumValue(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlStepper_setPlusLabel(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlStepper_getValue(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlStepper_getPlusSprite(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlStepper_setPlusSprite(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlStepper_setMinusLabel(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlStepper_setValue(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlStepper_setStepValue(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlStepper_setMaximumValue(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlStepper_update(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlStepper_startAutorepeat(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlStepper_getValue(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlStepper_setPlusLabel(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlStepper_setMinusSprite(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlStepper_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlStepper_ControlStepper(JSContext *cx, uint32_t argc, jsval *vp); @@ -236,14 +224,13 @@ extern JSObject *jsb_cocos2d_extension_ControlSwitch_prototype; bool js_cocos2dx_extension_ControlSwitch_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_ControlSwitch_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_ControlSwitch(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); -bool js_cocos2dx_extension_ControlSwitch_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_extension_ControlSwitch(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_ControlSwitch_setOn(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ControlSwitch_locationFromTouch(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSwitch_isOn(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSwitch_initWithMaskSprite(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSwitch_hasMoved(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ControlSwitch_locationFromTouch(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSwitch_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSwitch_ControlSwitch(JSContext *cx, uint32_t argc, jsval *vp); @@ -252,8 +239,8 @@ extern JSObject *jsb_cocos2d_extension_ScrollView_prototype; bool js_cocos2dx_extension_ScrollView_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_ScrollView_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_ScrollView(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_extension_ScrollView(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_ScrollView_isClippingToBounds(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ScrollView_setContainer(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ScrollView_setContentOffsetInDuration(JSContext *cx, uint32_t argc, jsval *vp); @@ -269,7 +256,7 @@ bool js_cocos2dx_extension_ScrollView_updateInset(JSContext *cx, uint32_t argc, bool js_cocos2dx_extension_ScrollView_initWithViewSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ScrollView_pause(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ScrollView_setDirection(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ScrollView_init(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_extension_ScrollView_setBounceable(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ScrollView_setContentOffset(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ScrollView_isDragging(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ScrollView_isTouchEnabled(JSContext *cx, uint32_t argc, jsval *vp); @@ -281,7 +268,6 @@ bool js_cocos2dx_extension_ScrollView_setClippingToBounds(JSContext *cx, uint32_ bool js_cocos2dx_extension_ScrollView_setViewSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ScrollView_getViewSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ScrollView_maxContainerOffset(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_extension_ScrollView_setBounceable(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ScrollView_isTouchMoved(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ScrollView_isNodeVisible(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ScrollView_minContainerOffset(JSContext *cx, uint32_t argc, jsval *vp); @@ -294,8 +280,8 @@ extern JSObject *jsb_cocos2d_extension_TableViewCell_prototype; bool js_cocos2dx_extension_TableViewCell_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_TableViewCell_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_TableViewCell(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_extension_TableViewCell(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_TableViewCell_reset(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_TableViewCell_getIdx(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_TableViewCell_setIdx(JSContext *cx, uint32_t argc, jsval *vp); @@ -307,8 +293,8 @@ extern JSObject *jsb_cocos2d_extension_TableView_prototype; bool js_cocos2dx_extension_TableView_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_TableView_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_TableView(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_extension_TableView(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_TableView_updateCellAtIndex(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_TableView_setVerticalFillOrder(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_TableView_scrollViewDidZoom(JSContext *cx, uint32_t argc, jsval *vp); @@ -328,8 +314,8 @@ extern JSObject *jsb_cocos2d_extension_EventAssetsManagerEx_prototype; bool js_cocos2dx_extension_EventAssetsManagerEx_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_EventAssetsManagerEx_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_EventAssetsManagerEx(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_extension_EventAssetsManagerEx(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_EventAssetsManagerEx_getAssetsManagerEx(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_EventAssetsManagerEx_getAssetId(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_EventAssetsManagerEx_getCURLECode(JSContext *cx, uint32_t argc, jsval *vp); @@ -345,8 +331,8 @@ extern JSObject *jsb_cocos2d_extension_Manifest_prototype; bool js_cocos2dx_extension_Manifest_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_Manifest_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_Manifest(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_extension_Manifest(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_Manifest_getManifestFileUrl(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_Manifest_isVersionLoaded(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_Manifest_isLoaded(JSContext *cx, uint32_t argc, jsval *vp); @@ -360,8 +346,8 @@ extern JSObject *jsb_cocos2d_extension_AssetsManagerEx_prototype; bool js_cocos2dx_extension_AssetsManagerEx_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_AssetsManagerEx_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_AssetsManagerEx(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_extension_AssetsManagerEx(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_AssetsManagerEx_getState(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_AssetsManagerEx_checkUpdate(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_AssetsManagerEx_getStoragePath(JSContext *cx, uint32_t argc, jsval *vp); @@ -377,8 +363,8 @@ extern JSObject *jsb_cocos2d_extension_EventListenerAssetsManagerEx_prototype; bool js_cocos2dx_extension_EventListenerAssetsManagerEx_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_extension_EventListenerAssetsManagerEx_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_extension_EventListenerAssetsManagerEx(JSContext *cx, JSObject *global); -void register_all_cocos2dx_extension(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_extension_EventListenerAssetsManagerEx(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_extension(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_extension_EventListenerAssetsManagerEx_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_EventListenerAssetsManagerEx_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_EventListenerAssetsManagerEx_EventListenerAssetsManagerEx(JSContext *cx, uint32_t argc, jsval *vp); diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_spine_auto.cpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_spine_auto.cpp index 3a9c260765..954d50b0f3 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_spine_auto.cpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_spine_auto.cpp @@ -1,13 +1,15 @@ #include "jsb_cocos2dx_spine_auto.hpp" #include "cocos2d_specifics.hpp" #include "spine-cocos2dx.h" +#include "jsb_cocos2dx_spine_manual.h" template static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedValue initializing(cx); bool isNewValid = true; - JSObject* global = ScriptingCore::getInstance()->getGlobalObject(); - isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && JSVAL_TO_BOOLEAN(initializing); + JS::RootedObject global(cx, ScriptingCore::getInstance()->getGlobalObject()); + isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && initializing.toBoolean(); if (isNewValid) { TypeTest t; @@ -18,8 +20,11 @@ static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *_tmp = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp)); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject _tmp(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + + args.rval().set(OBJECT_TO_JSVAL(_tmp)); return true; } @@ -31,9 +36,10 @@ static bool empty_constructor(JSContext *cx, uint32_t argc, jsval *vp) { return false; } -static bool js_is_native_obj(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) { - vp.set(BOOLEAN_TO_JSVAL(true)); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setBoolean(true); return true; } JSClass *jsb_spine_SkeletonRenderer_class; @@ -41,346 +47,482 @@ JSObject *jsb_spine_SkeletonRenderer_prototype; bool js_cocos2dx_spine_SkeletonRenderer_setTimeScale(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setTimeScale : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setTimeScale : Error processing arguments"); cobj->setTimeScale(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setTimeScale : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_spine_SkeletonRenderer_getDebugSlotsEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_getDebugSlotsEnabled : Invalid Native Object"); if (argc == 0) { - bool ret = cobj->isOpacityModifyRGB(); + bool ret = cobj->getDebugSlotsEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_getDebugSlotsEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_spine_SkeletonRenderer_drawSkeleton(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_spine_SkeletonRenderer_setAttachment(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_drawSkeleton : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setAttachment : Invalid Native Object"); if (argc == 2) { - cocos2d::Mat4 arg0; - unsigned int arg1; - ok &= jsval_to_matrix(cx, argv[0], &arg0); - ok &= jsval_to_uint32(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_drawSkeleton : Error processing arguments"); - cobj->drawSkeleton(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + std::string arg0; + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setAttachment : Error processing arguments"); + bool ret = cobj->setAttachment(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_drawSkeleton : wrong number of arguments: %d, was expecting %d", argc, 2); + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setAttachment : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled : Error processing arguments"); - cobj->setDebugSlotsEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose : Invalid Native Object"); + if (argc == 0) { + cobj->setBonesToSetupPose(); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_spine_SkeletonRenderer_getDebugSlotsEnabled(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_getDebugSlotsEnabled : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB : Invalid Native Object"); if (argc == 0) { - bool ret = cobj->getDebugSlotsEnabled(); + bool ret = cobj->isOpacityModifyRGB(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_getDebugSlotsEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_spine_SkeletonRenderer_initWithData(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose : Invalid Native Object"); - if (argc == 0) { - cobj->setBonesToSetupPose(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_initWithData : Invalid Native Object"); + if (argc == 1) { + spSkeletonData* arg0; + #pragma warning NO CONVERSION TO NATIVE FOR spSkeletonData* + ok = false; + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_initWithData : Error processing arguments"); + cobj->initWithData(arg0); + args.rval().setUndefined(); + return true; + } + if (argc == 2) { + spSkeletonData* arg0; + bool arg1; + #pragma warning NO CONVERSION TO NATIVE FOR spSkeletonData* + ok = false; + arg1 = JS::ToBoolean(args.get(1)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_initWithData : Error processing arguments"); + cobj->initWithData(arg0, arg1); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_initWithData : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled : Error processing arguments"); + cobj->setDebugSlotsEnabled(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_spine_SkeletonRenderer_setSlotsToSetupPose(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setSlotsToSetupPose : Invalid Native Object"); if (argc == 0) { cobj->setSlotsToSetupPose(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setSlotsToSetupPose : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_spine_SkeletonRenderer_setAttachment(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setAttachment : Invalid Native Object"); - if (argc == 2) { - std::string arg0; - std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setAttachment : Error processing arguments"); - bool ret = cobj->setAttachment(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB : Error processing arguments"); + cobj->setOpacityModifyRGB(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setAttachment : wrong number of arguments: %d, was expecting %d", argc, 2); + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_spine_SkeletonRenderer_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_spine_SkeletonRenderer_setToSetupPose(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_getBlendFunc : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setToSetupPose : Invalid Native Object"); if (argc == 0) { - const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); - jsval jsret = JSVAL_NULL; - jsret = blendfunc_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + cobj->setToSetupPose(); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_getBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setToSetupPose : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_spine_SkeletonRenderer_setSkin(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_spine_SkeletonRenderer_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setSkin : Invalid Native Object"); - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setSkin : Error processing arguments"); - bool ret = cobj->setSkin(arg0); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_getBlendFunc : Invalid Native Object"); + if (argc == 0) { + const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = blendfunc_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setSkin : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_getBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_spine_SkeletonRenderer_setToSetupPose(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_spine_SkeletonRenderer_drawSkeleton(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setToSetupPose : Invalid Native Object"); - if (argc == 0) { - cobj->setToSetupPose(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_drawSkeleton : Invalid Native Object"); + if (argc == 2) { + cocos2d::Mat4 arg0; + unsigned int arg1; + ok &= jsval_to_matrix(cx, args.get(0), &arg0); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_drawSkeleton : Error processing arguments"); + cobj->drawSkeleton(arg0, arg1); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setToSetupPose : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_drawSkeleton : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } bool js_cocos2dx_spine_SkeletonRenderer_updateWorldTransform(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_updateWorldTransform : Invalid Native Object"); if (argc == 0) { cobj->updateWorldTransform(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_updateWorldTransform : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_spine_SkeletonRenderer_initialize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB : Error processing arguments"); - cobj->setOpacityModifyRGB(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_initialize : Invalid Native Object"); + if (argc == 0) { + cobj->initialize(); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_initialize : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } bool js_cocos2dx_spine_SkeletonRenderer_setDebugBonesEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setDebugBonesEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setDebugBonesEnabled : Error processing arguments"); cobj->setDebugBonesEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setDebugBonesEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_spine_SkeletonRenderer_getSkeleton(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_spine_SkeletonRenderer_getDebugBonesEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_getSkeleton : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_getDebugBonesEnabled : Invalid Native Object"); if (argc == 0) { - spSkeleton* ret = cobj->getSkeleton(); + bool ret = cobj->getDebugBonesEnabled(); jsval jsret = JSVAL_NULL; - #pragma warning NO CONVERSION FROM NATIVE FOR spSkeleton*; - JS_SET_RVAL(cx, vp, jsret); + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_getSkeleton : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_getDebugBonesEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_spine_SkeletonRenderer_getDebugBonesEnabled(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_spine_SkeletonRenderer_getTimeScale(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_getDebugBonesEnabled : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_getTimeScale : Invalid Native Object"); if (argc == 0) { - bool ret = cobj->getDebugBonesEnabled(); + double ret = cobj->getTimeScale(); jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_getDebugBonesEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_getTimeScale : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_spine_SkeletonRenderer_initWithFile(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + JS::RootedObject obj(cx); + spine::SkeletonRenderer* cobj = NULL; + obj = args.thisv().toObjectOrNull(); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_initWithFile : Invalid Native Object"); + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cobj->initWithFile(arg0, arg1); + args.rval().setUndefined(); + return true; + } + } while(0); + + do { + if (argc == 3) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + double arg2; + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + if (!ok) { ok = true; break; } + cobj->initWithFile(arg0, arg1, arg2); + args.rval().setUndefined(); + return true; + } + } while(0); + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + spAtlas* arg1; + #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* + ok = false; + if (!ok) { ok = true; break; } + cobj->initWithFile(arg0, arg1); + args.rval().setUndefined(); + return true; + } + } while(0); + + do { + if (argc == 3) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + spAtlas* arg1; + #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* + ok = false; + if (!ok) { ok = true; break; } + double arg2; + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + if (!ok) { ok = true; break; } + cobj->initWithFile(arg0, arg1, arg2); + args.rval().setUndefined(); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_initWithFile : wrong number of arguments"); return false; } bool js_cocos2dx_spine_SkeletonRenderer_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setBlendFunc : Invalid Native Object"); if (argc == 1) { cocos2d::BlendFunc arg0; - ok &= jsval_to_blendfunc(cx, argv[0], &arg0); + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setBlendFunc : Error processing arguments"); cobj->setBlendFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_spine_SkeletonRenderer_getTimeScale(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_spine_SkeletonRenderer_setSkin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_getTimeScale : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setSkin : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_setSkin : Error processing arguments"); + bool ret = cobj->setSkin(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_setSkin : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_spine_SkeletonRenderer_getSkeleton(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_getSkeleton : Invalid Native Object"); if (argc == 0) { - double ret = cobj->getTimeScale(); + spSkeleton* ret = cobj->getSkeleton(); jsval jsret = JSVAL_NULL; - jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = spskeleton_to_jsval(cx, *ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_getTimeScale : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_getSkeleton : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } bool js_cocos2dx_spine_SkeletonRenderer_createWithFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } spine::SkeletonRenderer* ret = spine::SkeletonRenderer::createWithFile(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -392,20 +534,20 @@ bool js_cocos2dx_spine_SkeletonRenderer_createWithFile(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } spine::SkeletonRenderer* ret = spine::SkeletonRenderer::createWithFile(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -417,7 +559,7 @@ bool js_cocos2dx_spine_SkeletonRenderer_createWithFile(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -425,7 +567,7 @@ bool js_cocos2dx_spine_SkeletonRenderer_createWithFile(JSContext *cx, uint32_t a do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* @@ -441,21 +583,21 @@ bool js_cocos2dx_spine_SkeletonRenderer_createWithFile(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* ok = false; if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } spine::SkeletonRenderer* ret = spine::SkeletonRenderer::createWithFile(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -467,13 +609,241 @@ bool js_cocos2dx_spine_SkeletonRenderer_createWithFile(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_createWithFile : wrong number of arguments"); return false; } +bool js_cocos2dx_spine_SkeletonRenderer_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + JS::RootedObject obj(cx); + spine::SkeletonRenderer* cobj = NULL; + do { + if (argc == 1) { + spSkeletonData* arg0; + #pragma warning NO CONVERSION TO NATIVE FOR spSkeletonData* + ok = false; + if (!ok) { ok = true; break; } + cobj = new (std::nothrow) spine::SkeletonRenderer(arg0); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonRenderer"); + } + } while(0); + + do { + if (argc == 2) { + spSkeletonData* arg0; + #pragma warning NO CONVERSION TO NATIVE FOR spSkeletonData* + ok = false; + if (!ok) { ok = true; break; } + bool arg1; + arg1 = JS::ToBoolean(args.get(1)); + cobj = new (std::nothrow) spine::SkeletonRenderer(arg0, arg1); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonRenderer"); + } + } while(0); + + do { + if (argc == 0) { + cobj = new (std::nothrow) spine::SkeletonRenderer(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonRenderer"); + } + } while(0); + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + spAtlas* arg1; + #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* + ok = false; + if (!ok) { ok = true; break; } + cobj = new (std::nothrow) spine::SkeletonRenderer(arg0, arg1); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonRenderer"); + } + } while(0); + + do { + if (argc == 3) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + spAtlas* arg1; + #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* + ok = false; + if (!ok) { ok = true; break; } + double arg2; + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + if (!ok) { ok = true; break; } + cobj = new (std::nothrow) spine::SkeletonRenderer(arg0, arg1, arg2); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonRenderer"); + } + } while(0); + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cobj = new (std::nothrow) spine::SkeletonRenderer(arg0, arg1); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonRenderer"); + } + } while(0); + + do { + if (argc == 3) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + double arg2; + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + if (!ok) { ok = true; break; } + cobj = new (std::nothrow) spine::SkeletonRenderer(arg0, arg1, arg2); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonRenderer"); + } + } while(0); + + if (cobj) { + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + + args.rval().set(OBJECT_TO_JSVAL(obj)); + return true; + } + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonRenderer_constructor : wrong number of arguments"); + return false; +} + extern JSObject *jsb_cocos2d_Node_prototype; @@ -481,7 +851,7 @@ void js_spine_SkeletonRenderer_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (SkeletonRenderer)", obj); } -void js_register_cocos2dx_spine_SkeletonRenderer(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_spine_SkeletonRenderer(JSContext *cx, JS::HandleObject global) { jsb_spine_SkeletonRenderer_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_spine_SkeletonRenderer_class->name = "Skeleton"; jsb_spine_SkeletonRenderer_class->addProperty = JS_PropertyStub; @@ -495,29 +865,32 @@ void js_register_cocos2dx_spine_SkeletonRenderer(JSContext *cx, JSObject *global jsb_spine_SkeletonRenderer_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("setTimeScale", js_cocos2dx_spine_SkeletonRenderer_setTimeScale, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("isOpacityModifyRGB", js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("drawSkeleton", js_cocos2dx_spine_SkeletonRenderer_drawSkeleton, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setDebugSlotsEnabled", js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getDebugSlotsEnabled", js_cocos2dx_spine_SkeletonRenderer_getDebugSlotsEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setAttachment", js_cocos2dx_spine_SkeletonRenderer_setAttachment, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setBonesToSetupPose", js_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isOpacityModifyRGB", js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithData", js_cocos2dx_spine_SkeletonRenderer_initWithData, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setDebugSlotsEnabled", js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setSlotsToSetupPose", js_cocos2dx_spine_SkeletonRenderer_setSlotsToSetupPose, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setAttachment", js_cocos2dx_spine_SkeletonRenderer_setAttachment, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getBlendFunc", js_cocos2dx_spine_SkeletonRenderer_getBlendFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setSkin", js_cocos2dx_spine_SkeletonRenderer_setSkin, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setOpacityModifyRGB", js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setToSetupPose", js_cocos2dx_spine_SkeletonRenderer_setToSetupPose, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getBlendFunc", js_cocos2dx_spine_SkeletonRenderer_getBlendFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("drawSkeleton", js_cocos2dx_spine_SkeletonRenderer_drawSkeleton, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("updateWorldTransform", js_cocos2dx_spine_SkeletonRenderer_updateWorldTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setOpacityModifyRGB", js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initialize", js_cocos2dx_spine_SkeletonRenderer_initialize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setDebugBonesEnabled", js_cocos2dx_spine_SkeletonRenderer_setDebugBonesEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getSkeleton", js_cocos2dx_spine_SkeletonRenderer_getSkeleton, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getDebugBonesEnabled", js_cocos2dx_spine_SkeletonRenderer_getDebugBonesEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setBlendFunc", js_cocos2dx_spine_SkeletonRenderer_setBlendFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getTimeScale", js_cocos2dx_spine_SkeletonRenderer_getTimeScale, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithFile", js_cocos2dx_spine_SkeletonRenderer_initWithFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setBlendFunc", js_cocos2dx_spine_SkeletonRenderer_setBlendFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setSkin", js_cocos2dx_spine_SkeletonRenderer_setSkin, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getSkeleton", js_cocos2dx_spine_SkeletonRenderer_getSkeleton, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -528,9 +901,9 @@ void js_register_cocos2dx_spine_SkeletonRenderer(JSContext *cx, JSObject *global jsb_spine_SkeletonRenderer_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_spine_SkeletonRenderer_class, - dummy_constructor, 0, // no constructor + js_cocos2dx_spine_SkeletonRenderer_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -559,23 +932,24 @@ JSObject *jsb_spine_SkeletonAnimation_prototype; bool js_cocos2dx_spine_SkeletonAnimation_setStartListener(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setStartListener : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=](int larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; largv[0] = int32_to_jsval(cx, larg0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -590,7 +964,7 @@ bool js_cocos2dx_spine_SkeletonAnimation_setStartListener(JSContext *cx, uint32_ ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setStartListener : Error processing arguments"); cobj->setStartListener(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -599,9 +973,9 @@ bool js_cocos2dx_spine_SkeletonAnimation_setStartListener(JSContext *cx, uint32_ } bool js_cocos2dx_spine_SkeletonAnimation_setTrackEventListener(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setTrackEventListener : Invalid Native Object"); @@ -611,22 +985,16 @@ bool js_cocos2dx_spine_SkeletonAnimation_setTrackEventListener(JSContext *cx, ui #pragma warning NO CONVERSION TO NATIVE FOR spTrackEntry* ok = false; do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](int larg0, spEvent* larg1) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); - do { - if (larg1) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (spEvent*)larg1); - largv[1] = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - largv[1] = JSVAL_NULL; - } - } while (0); - jsval rval; - bool ok = func->invoke(2, &largv[0], rval); + largv[1] = spevent_to_jsval(cx, *larg1); + JS::RootedValue rval(cx); + bool ok = func->invoke(2, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -641,7 +1009,7 @@ bool js_cocos2dx_spine_SkeletonAnimation_setTrackEventListener(JSContext *cx, ui ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setTrackEventListener : Error processing arguments"); cobj->setTrackEventListener(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -650,15 +1018,16 @@ bool js_cocos2dx_spine_SkeletonAnimation_setTrackEventListener(JSContext *cx, ui } bool js_cocos2dx_spine_SkeletonAnimation_getState(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_getState : Invalid Native Object"); if (argc == 0) { spAnimationState* ret = cobj->getState(); jsval jsret = JSVAL_NULL; - #pragma warning NO CONVERSION FROM NATIVE FOR spAnimationState*; - JS_SET_RVAL(cx, vp, jsret); + jsret = spanimationstate_to_jsval(cx, *ret); + args.rval().set(jsret); return true; } @@ -667,9 +1036,9 @@ bool js_cocos2dx_spine_SkeletonAnimation_getState(JSContext *cx, uint32_t argc, } bool js_cocos2dx_spine_SkeletonAnimation_setTrackCompleteListener(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setTrackCompleteListener : Invalid Native Object"); @@ -679,15 +1048,16 @@ bool js_cocos2dx_spine_SkeletonAnimation_setTrackCompleteListener(JSContext *cx, #pragma warning NO CONVERSION TO NATIVE FOR spTrackEntry* ok = false; do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](int larg0, int larg1) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); largv[1] = int32_to_jsval(cx, larg1); - jsval rval; - bool ok = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(2, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -702,7 +1072,7 @@ bool js_cocos2dx_spine_SkeletonAnimation_setTrackCompleteListener(JSContext *cx, ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setTrackCompleteListener : Error processing arguments"); cobj->setTrackCompleteListener(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -711,9 +1081,9 @@ bool js_cocos2dx_spine_SkeletonAnimation_setTrackCompleteListener(JSContext *cx, } bool js_cocos2dx_spine_SkeletonAnimation_onTrackEntryEvent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_onTrackEntryEvent : Invalid Native Object"); @@ -722,14 +1092,14 @@ bool js_cocos2dx_spine_SkeletonAnimation_onTrackEntryEvent(JSContext *cx, uint32 spEventType arg1; spEvent* arg2; int arg3; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); #pragma warning NO CONVERSION TO NATIVE FOR spEvent* ok = false; - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonAnimation_onTrackEntryEvent : Error processing arguments"); cobj->onTrackEntryEvent(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -738,9 +1108,9 @@ bool js_cocos2dx_spine_SkeletonAnimation_onTrackEntryEvent(JSContext *cx, uint32 } bool js_cocos2dx_spine_SkeletonAnimation_setTrackStartListener(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setTrackStartListener : Invalid Native Object"); @@ -750,14 +1120,15 @@ bool js_cocos2dx_spine_SkeletonAnimation_setTrackStartListener(JSContext *cx, ui #pragma warning NO CONVERSION TO NATIVE FOR spTrackEntry* ok = false; do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](int larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; largv[0] = int32_to_jsval(cx, larg0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -772,7 +1143,7 @@ bool js_cocos2dx_spine_SkeletonAnimation_setTrackStartListener(JSContext *cx, ui ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setTrackStartListener : Error processing arguments"); cobj->setTrackStartListener(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -781,18 +1152,18 @@ bool js_cocos2dx_spine_SkeletonAnimation_setTrackStartListener(JSContext *cx, ui } bool js_cocos2dx_spine_SkeletonAnimation_update(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_update : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonAnimation_update : Error processing arguments"); cobj->update(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -801,24 +1172,25 @@ bool js_cocos2dx_spine_SkeletonAnimation_update(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_spine_SkeletonAnimation_setCompleteListener(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setCompleteListener : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=](int larg0, int larg1) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); largv[1] = int32_to_jsval(cx, larg1); - jsval rval; - bool ok = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(2, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -833,7 +1205,7 @@ bool js_cocos2dx_spine_SkeletonAnimation_setCompleteListener(JSContext *cx, uint ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setCompleteListener : Error processing arguments"); cobj->setCompleteListener(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -842,9 +1214,9 @@ bool js_cocos2dx_spine_SkeletonAnimation_setCompleteListener(JSContext *cx, uint } bool js_cocos2dx_spine_SkeletonAnimation_setTrackEndListener(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setTrackEndListener : Invalid Native Object"); @@ -854,14 +1226,15 @@ bool js_cocos2dx_spine_SkeletonAnimation_setTrackEndListener(JSContext *cx, uint #pragma warning NO CONVERSION TO NATIVE FOR spTrackEntry* ok = false; do { - if(JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(1)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(1))); auto lambda = [=](int larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; largv[0] = int32_to_jsval(cx, larg0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -876,7 +1249,7 @@ bool js_cocos2dx_spine_SkeletonAnimation_setTrackEndListener(JSContext *cx, uint ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setTrackEndListener : Error processing arguments"); cobj->setTrackEndListener(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -885,31 +1258,25 @@ bool js_cocos2dx_spine_SkeletonAnimation_setTrackEndListener(JSContext *cx, uint } bool js_cocos2dx_spine_SkeletonAnimation_setEventListener(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setEventListener : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=](int larg0, spEvent* larg1) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); - do { - if (larg1) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (spEvent*)larg1); - largv[1] = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - largv[1] = JSVAL_NULL; - } - } while (0); - jsval rval; - bool ok = func->invoke(2, &largv[0], rval); + largv[1] = spevent_to_jsval(cx, *larg1); + JS::RootedValue rval(cx); + bool ok = func->invoke(2, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -924,7 +1291,7 @@ bool js_cocos2dx_spine_SkeletonAnimation_setEventListener(JSContext *cx, uint32_ ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setEventListener : Error processing arguments"); cobj->setEventListener(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -933,9 +1300,9 @@ bool js_cocos2dx_spine_SkeletonAnimation_setEventListener(JSContext *cx, uint32_ } bool js_cocos2dx_spine_SkeletonAnimation_setMix(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setMix : Invalid Native Object"); @@ -943,12 +1310,12 @@ bool js_cocos2dx_spine_SkeletonAnimation_setMix(JSContext *cx, uint32_t argc, js std::string arg0; std::string arg1; double arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setMix : Error processing arguments"); cobj->setMix(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -957,23 +1324,24 @@ bool js_cocos2dx_spine_SkeletonAnimation_setMix(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_spine_SkeletonAnimation_setEndListener(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setEndListener : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=](int larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; largv[0] = int32_to_jsval(cx, larg0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -988,22 +1356,39 @@ bool js_cocos2dx_spine_SkeletonAnimation_setEndListener(JSContext *cx, uint32_t ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonAnimation_setEndListener : Error processing arguments"); cobj->setEndListener(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_spine_SkeletonAnimation_setEndListener : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_spine_SkeletonAnimation_initialize(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_initialize : Invalid Native Object"); + if (argc == 0) { + cobj->initialize(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonAnimation_initialize : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_spine_SkeletonAnimation_clearTracks(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_clearTracks : Invalid Native Object"); if (argc == 0) { cobj->clearTracks(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1012,23 +1397,23 @@ bool js_cocos2dx_spine_SkeletonAnimation_clearTracks(JSContext *cx, uint32_t arg } bool js_cocos2dx_spine_SkeletonAnimation_clearTrack(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_clearTrack : Invalid Native Object"); if (argc == 0) { cobj->clearTrack(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonAnimation_clearTrack : Error processing arguments"); cobj->clearTrack(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1037,9 +1422,9 @@ bool js_cocos2dx_spine_SkeletonAnimation_clearTrack(JSContext *cx, uint32_t argc } bool js_cocos2dx_spine_SkeletonAnimation_onAnimationStateEvent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonAnimation_onAnimationStateEvent : Invalid Native Object"); @@ -1048,14 +1433,14 @@ bool js_cocos2dx_spine_SkeletonAnimation_onAnimationStateEvent(JSContext *cx, ui spEventType arg1; spEvent* arg2; int arg3; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); #pragma warning NO CONVERSION TO NATIVE FOR spEvent* ok = false; - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonAnimation_onAnimationStateEvent : Error processing arguments"); cobj->onAnimationStateEvent(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1064,16 +1449,16 @@ bool js_cocos2dx_spine_SkeletonAnimation_onAnimationStateEvent(JSContext *cx, ui } bool js_cocos2dx_spine_SkeletonAnimation_createWithFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } spine::SkeletonAnimation* ret = spine::SkeletonAnimation::createWithFile(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -1085,20 +1470,20 @@ bool js_cocos2dx_spine_SkeletonAnimation_createWithFile(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } spine::SkeletonAnimation* ret = spine::SkeletonAnimation::createWithFile(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -1110,7 +1495,7 @@ bool js_cocos2dx_spine_SkeletonAnimation_createWithFile(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -1118,7 +1503,7 @@ bool js_cocos2dx_spine_SkeletonAnimation_createWithFile(JSContext *cx, uint32_t do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* @@ -1134,21 +1519,21 @@ bool js_cocos2dx_spine_SkeletonAnimation_createWithFile(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* ok = false; if (!ok) { ok = true; break; } double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); if (!ok) { ok = true; break; } spine::SkeletonAnimation* ret = spine::SkeletonAnimation::createWithFile(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -1160,13 +1545,211 @@ bool js_cocos2dx_spine_SkeletonAnimation_createWithFile(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); JS_ReportError(cx, "js_cocos2dx_spine_SkeletonAnimation_createWithFile : wrong number of arguments"); return false; } +bool js_cocos2dx_spine_SkeletonAnimation_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + JS::RootedObject obj(cx); + spine::SkeletonAnimation* cobj = NULL; + do { + if (argc == 1) { + spSkeletonData* arg0; + #pragma warning NO CONVERSION TO NATIVE FOR spSkeletonData* + ok = false; + if (!ok) { ok = true; break; } + cobj = new (std::nothrow) spine::SkeletonAnimation(arg0); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); + } + } while(0); + + do { + if (argc == 0) { + cobj = new (std::nothrow) spine::SkeletonAnimation(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); + } + } while(0); + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + spAtlas* arg1; + #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* + ok = false; + if (!ok) { ok = true; break; } + cobj = new (std::nothrow) spine::SkeletonAnimation(arg0, arg1); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); + } + } while(0); + + do { + if (argc == 3) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + spAtlas* arg1; + #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* + ok = false; + if (!ok) { ok = true; break; } + double arg2; + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + if (!ok) { ok = true; break; } + cobj = new (std::nothrow) spine::SkeletonAnimation(arg0, arg1, arg2); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); + } + } while(0); + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cobj = new (std::nothrow) spine::SkeletonAnimation(arg0, arg1); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); + } + } while(0); + + do { + if (argc == 3) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + double arg2; + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + if (!ok) { ok = true; break; } + cobj = new (std::nothrow) spine::SkeletonAnimation(arg0, arg1, arg2); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); + } + } while(0); + + if (cobj) { + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + + args.rval().set(OBJECT_TO_JSVAL(obj)); + return true; + } + JS_ReportError(cx, "js_cocos2dx_spine_SkeletonAnimation_constructor : wrong number of arguments"); + return false; +} + extern JSObject *jsb_spine_SkeletonRenderer_prototype; @@ -1174,7 +1757,23 @@ void js_spine_SkeletonAnimation_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (SkeletonAnimation)", obj); } -void js_register_cocos2dx_spine_SkeletonAnimation(JSContext *cx, JSObject *global) { +static bool js_spine_SkeletonAnimation_ctor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + spine::SkeletonAnimation *nobj = new (std::nothrow) spine::SkeletonAnimation(); + if (nobj) { + nobj->autorelease(); + } + js_proxy_t* p = jsb_new_proxy(nobj, obj); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); + bool isFound = false; + if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); + return true; +} +void js_register_cocos2dx_spine_SkeletonAnimation(JSContext *cx, JS::HandleObject global) { jsb_spine_SkeletonAnimation_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_spine_SkeletonAnimation_class->name = "SkeletonAnimation"; jsb_spine_SkeletonAnimation_class->addProperty = JS_PropertyStub; @@ -1188,8 +1787,8 @@ void js_register_cocos2dx_spine_SkeletonAnimation(JSContext *cx, JSObject *globa jsb_spine_SkeletonAnimation_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1205,9 +1804,11 @@ void js_register_cocos2dx_spine_SkeletonAnimation(JSContext *cx, JSObject *globa JS_FN("setEventListener", js_cocos2dx_spine_SkeletonAnimation_setEventListener, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setMix", js_cocos2dx_spine_SkeletonAnimation_setMix, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setEndListener", js_cocos2dx_spine_SkeletonAnimation_setEndListener, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initialize", js_cocos2dx_spine_SkeletonAnimation_initialize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("clearTracks", js_cocos2dx_spine_SkeletonAnimation_clearTracks, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("clearTrack", js_cocos2dx_spine_SkeletonAnimation_clearTrack, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("onAnimationStateEvent", js_cocos2dx_spine_SkeletonAnimation_onAnimationStateEvent, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_spine_SkeletonAnimation_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -1218,9 +1819,9 @@ void js_register_cocos2dx_spine_SkeletonAnimation(JSContext *cx, JSObject *globa jsb_spine_SkeletonAnimation_prototype = JS_InitClass( cx, global, - jsb_spine_SkeletonRenderer_prototype, + JS::RootedObject(cx, jsb_spine_SkeletonRenderer_prototype), jsb_spine_SkeletonAnimation_class, - dummy_constructor, 0, // no constructor + js_cocos2dx_spine_SkeletonAnimation_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -1244,21 +1845,12 @@ void js_register_cocos2dx_spine_SkeletonAnimation(JSContext *cx, JSObject *globa } } -void register_all_cocos2dx_spine(JSContext* cx, JSObject* obj) { - // first, try to get the ns - JS::RootedValue nsval(cx); +void register_all_cocos2dx_spine(JSContext* cx, JS::HandleObject obj) { + // Get the ns JS::RootedObject ns(cx); - JS_GetProperty(cx, obj, "sp", &nsval); - if (nsval == JSVAL_VOID) { - ns = JS_NewObject(cx, NULL, NULL, NULL); - nsval = OBJECT_TO_JSVAL(ns); - JS_SetProperty(cx, obj, "sp", nsval); - } else { - JS_ValueToObject(cx, nsval, &ns); - } - obj = ns; + get_or_create_js_obj(cx, obj, "sp", &ns); - js_register_cocos2dx_spine_SkeletonRenderer(cx, obj); - js_register_cocos2dx_spine_SkeletonAnimation(cx, obj); + js_register_cocos2dx_spine_SkeletonRenderer(cx, ns); + js_register_cocos2dx_spine_SkeletonAnimation(cx, ns); } diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_spine_auto.hpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_spine_auto.hpp index 7b3b15fa5e..60ea77c238 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_spine_auto.hpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_spine_auto.hpp @@ -10,35 +10,39 @@ extern JSObject *jsb_spine_SkeletonRenderer_prototype; bool js_cocos2dx_spine_SkeletonRenderer_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_spine_SkeletonRenderer_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_spine_SkeletonRenderer(JSContext *cx, JSObject *global); -void register_all_cocos2dx_spine(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_spine_SkeletonRenderer(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_spine(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_spine_SkeletonRenderer_setTimeScale(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_spine_SkeletonRenderer_drawSkeleton(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonRenderer_getDebugSlotsEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonRenderer_setAttachment(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonRenderer_initWithData(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonRenderer_setSlotsToSetupPose(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_spine_SkeletonRenderer_setAttachment(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_spine_SkeletonRenderer_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_spine_SkeletonRenderer_setSkin(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonRenderer_setToSetupPose(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonRenderer_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonRenderer_drawSkeleton(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonRenderer_updateWorldTransform(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonRenderer_initialize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonRenderer_setDebugBonesEnabled(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_spine_SkeletonRenderer_getSkeleton(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonRenderer_getDebugBonesEnabled(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_spine_SkeletonRenderer_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonRenderer_getTimeScale(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonRenderer_initWithFile(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonRenderer_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonRenderer_setSkin(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonRenderer_getSkeleton(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonRenderer_createWithFile(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonRenderer_SkeletonRenderer(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_spine_SkeletonAnimation_class; extern JSObject *jsb_spine_SkeletonAnimation_prototype; bool js_cocos2dx_spine_SkeletonAnimation_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_spine_SkeletonAnimation_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_spine_SkeletonAnimation(JSContext *cx, JSObject *global); -void register_all_cocos2dx_spine(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_spine_SkeletonAnimation(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_spine(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_spine_SkeletonAnimation_setStartListener(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonAnimation_setTrackEventListener(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonAnimation_getState(JSContext *cx, uint32_t argc, jsval *vp); @@ -51,9 +55,11 @@ bool js_cocos2dx_spine_SkeletonAnimation_setTrackEndListener(JSContext *cx, uint bool js_cocos2dx_spine_SkeletonAnimation_setEventListener(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonAnimation_setMix(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonAnimation_setEndListener(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonAnimation_initialize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonAnimation_clearTracks(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonAnimation_clearTrack(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonAnimation_onAnimationStateEvent(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonAnimation_createWithFile(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_spine_SkeletonAnimation_SkeletonAnimation(JSContext *cx, uint32_t argc, jsval *vp); #endif diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_studio_auto.cpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_studio_auto.cpp index ff873cd2b8..10acfe14f3 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_studio_auto.cpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_studio_auto.cpp @@ -1,13 +1,16 @@ #include "jsb_cocos2dx_studio_auto.hpp" #include "cocos2d_specifics.hpp" #include "CocoStudio.h" +#include "CCObjectExtensionData.h" +#include "jsb_cocos2dx_studio_conversions.h" template static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedValue initializing(cx); bool isNewValid = true; - JSObject* global = ScriptingCore::getInstance()->getGlobalObject(); - isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && JSVAL_TO_BOOLEAN(initializing); + JS::RootedObject global(cx, ScriptingCore::getInstance()->getGlobalObject()); + isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && initializing.toBoolean(); if (isNewValid) { TypeTest t; @@ -18,8 +21,11 @@ static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *_tmp = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp)); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject _tmp(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + + args.rval().set(OBJECT_TO_JSVAL(_tmp)); return true; } @@ -31,9 +37,10 @@ static bool empty_constructor(JSContext *cx, uint32_t argc, jsval *vp) { return false; } -static bool js_is_native_obj(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) { - vp.set(BOOLEAN_TO_JSVAL(true)); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setBoolean(true); return true; } JSClass *jsb_cocostudio_ActionObject_class; @@ -41,18 +48,18 @@ JSObject *jsb_cocostudio_ActionObject_prototype; bool js_cocos2dx_studio_ActionObject_setCurrentTime(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_setCurrentTime : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionObject_setCurrentTime : Error processing arguments"); cobj->setCurrentTime(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -61,13 +68,14 @@ bool js_cocos2dx_studio_ActionObject_setCurrentTime(JSContext *cx, uint32_t argc } bool js_cocos2dx_studio_ActionObject_pause(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_pause : Invalid Native Object"); if (argc == 0) { cobj->pause(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -76,18 +84,18 @@ bool js_cocos2dx_studio_ActionObject_pause(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_ActionObject_setName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_setName : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionObject_setName : Error processing arguments"); cobj->setName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -96,18 +104,18 @@ bool js_cocos2dx_studio_ActionObject_setName(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ActionObject_setUnitTime(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_setUnitTime : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionObject_setUnitTime : Error processing arguments"); cobj->setUnitTime(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -116,7 +124,8 @@ bool js_cocos2dx_studio_ActionObject_setUnitTime(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_studio_ActionObject_getTotalTime(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_getTotalTime : Invalid Native Object"); @@ -124,7 +133,7 @@ bool js_cocos2dx_studio_ActionObject_getTotalTime(JSContext *cx, uint32_t argc, double ret = cobj->getTotalTime(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -133,7 +142,8 @@ bool js_cocos2dx_studio_ActionObject_getTotalTime(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_ActionObject_getName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_getName : Invalid Native Object"); @@ -141,7 +151,7 @@ bool js_cocos2dx_studio_ActionObject_getName(JSContext *cx, uint32_t argc, jsval const char* ret = cobj->getName(); jsval jsret = JSVAL_NULL; jsret = c_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -150,13 +160,14 @@ bool js_cocos2dx_studio_ActionObject_getName(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ActionObject_stop(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_stop : Invalid Native Object"); if (argc == 0) { cobj->stop(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -165,12 +176,12 @@ bool js_cocos2dx_studio_ActionObject_stop(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_ActionObject_play(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocostudio::ActionObject* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_play : Invalid Native Object"); @@ -178,16 +189,16 @@ bool js_cocos2dx_studio_ActionObject_play(JSContext *cx, uint32_t argc, jsval *v if (argc == 1) { cocos2d::CallFunc* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::CallFunc*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cobj->play(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -195,7 +206,7 @@ bool js_cocos2dx_studio_ActionObject_play(JSContext *cx, uint32_t argc, jsval *v do { if (argc == 0) { cobj->play(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -205,7 +216,8 @@ bool js_cocos2dx_studio_ActionObject_play(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_ActionObject_getCurrentTime(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_getCurrentTime : Invalid Native Object"); @@ -213,7 +225,7 @@ bool js_cocos2dx_studio_ActionObject_getCurrentTime(JSContext *cx, uint32_t argc double ret = cobj->getCurrentTime(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -222,25 +234,25 @@ bool js_cocos2dx_studio_ActionObject_getCurrentTime(JSContext *cx, uint32_t argc } bool js_cocos2dx_studio_ActionObject_removeActionNode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_removeActionNode : Invalid Native Object"); if (argc == 1) { cocostudio::ActionNode* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::ActionNode*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionObject_removeActionNode : Error processing arguments"); cobj->removeActionNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -249,7 +261,8 @@ bool js_cocos2dx_studio_ActionObject_removeActionNode(JSContext *cx, uint32_t ar } bool js_cocos2dx_studio_ActionObject_getLoop(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_getLoop : Invalid Native Object"); @@ -257,7 +270,7 @@ bool js_cocos2dx_studio_ActionObject_getLoop(JSContext *cx, uint32_t argc, jsval bool ret = cobj->getLoop(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -266,9 +279,9 @@ bool js_cocos2dx_studio_ActionObject_getLoop(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ActionObject_initWithBinary(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_initWithBinary : Invalid Native Object"); @@ -277,9 +290,9 @@ bool js_cocos2dx_studio_ActionObject_initWithBinary(JSContext *cx, uint32_t argc cocostudio::stExpCocoNode* arg1; cocos2d::Ref* arg2; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::CocoLoader*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -287,16 +300,16 @@ bool js_cocos2dx_studio_ActionObject_initWithBinary(JSContext *cx, uint32_t argc #pragma warning NO CONVERSION TO NATIVE FOR stExpCocoNode* ok = false; do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::Ref*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionObject_initWithBinary : Error processing arguments"); cobj->initWithBinary(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -305,25 +318,25 @@ bool js_cocos2dx_studio_ActionObject_initWithBinary(JSContext *cx, uint32_t argc } bool js_cocos2dx_studio_ActionObject_addActionNode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_addActionNode : Invalid Native Object"); if (argc == 1) { cocostudio::ActionNode* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::ActionNode*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionObject_addActionNode : Error processing arguments"); cobj->addActionNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -332,7 +345,8 @@ bool js_cocos2dx_studio_ActionObject_addActionNode(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_ActionObject_getUnitTime(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_getUnitTime : Invalid Native Object"); @@ -340,7 +354,7 @@ bool js_cocos2dx_studio_ActionObject_getUnitTime(JSContext *cx, uint32_t argc, j double ret = cobj->getUnitTime(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -349,7 +363,8 @@ bool js_cocos2dx_studio_ActionObject_getUnitTime(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_studio_ActionObject_isPlaying(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_isPlaying : Invalid Native Object"); @@ -357,7 +372,7 @@ bool js_cocos2dx_studio_ActionObject_isPlaying(JSContext *cx, uint32_t argc, jsv bool ret = cobj->isPlaying(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -366,18 +381,18 @@ bool js_cocos2dx_studio_ActionObject_isPlaying(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_studio_ActionObject_updateToFrameByTime(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_updateToFrameByTime : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionObject_updateToFrameByTime : Error processing arguments"); cobj->updateToFrameByTime(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -386,18 +401,18 @@ bool js_cocos2dx_studio_ActionObject_updateToFrameByTime(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ActionObject_setLoop(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_setLoop : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionObject_setLoop : Error processing arguments"); cobj->setLoop(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -406,18 +421,18 @@ bool js_cocos2dx_studio_ActionObject_setLoop(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ActionObject_simulationActionUpdate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionObject* cobj = (cocostudio::ActionObject *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionObject_simulationActionUpdate : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionObject_simulationActionUpdate : Error processing arguments"); cobj->simulationActionUpdate(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -426,7 +441,7 @@ bool js_cocos2dx_studio_ActionObject_simulationActionUpdate(JSContext *cx, uint3 } bool js_cocos2dx_studio_ActionObject_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::ActionObject* cobj = new (std::nothrow) cocostudio::ActionObject(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -440,13 +455,16 @@ bool js_cocos2dx_studio_ActionObject_constructor(JSContext *cx, uint32_t argc, j CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::ActionObject"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ActionObject"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -456,7 +474,7 @@ void js_cocostudio_ActionObject_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ActionObject)", obj); } -void js_register_cocos2dx_studio_ActionObject(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ActionObject(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_ActionObject_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_ActionObject_class->name = "ActionObject"; jsb_cocostudio_ActionObject_class->addProperty = JS_PropertyStub; @@ -470,8 +488,8 @@ void js_register_cocos2dx_studio_ActionObject(JSContext *cx, JSObject *global) { jsb_cocostudio_ActionObject_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -500,7 +518,7 @@ void js_register_cocos2dx_studio_ActionObject(JSContext *cx, JSObject *global) { jsb_cocostudio_ActionObject_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_ActionObject_class, js_cocos2dx_studio_ActionObject_constructor, 0, // constructor properties, @@ -531,17 +549,17 @@ JSObject *jsb_cocostudio_ActionManagerEx_prototype; bool js_cocos2dx_studio_ActionManagerEx_stopActionByName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionManagerEx* cobj = (cocostudio::ActionManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionManagerEx_stopActionByName : Invalid Native Object"); if (argc == 2) { const char* arg0; const char* arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionManagerEx_stopActionByName : Error processing arguments"); cocostudio::ActionObject* ret = cobj->stopActionByName(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -553,7 +571,7 @@ bool js_cocos2dx_studio_ActionManagerEx_stopActionByName(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -562,17 +580,17 @@ bool js_cocos2dx_studio_ActionManagerEx_stopActionByName(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ActionManagerEx_getActionByName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionManagerEx* cobj = (cocostudio::ActionManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionManagerEx_getActionByName : Invalid Native Object"); if (argc == 2) { const char* arg0; const char* arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionManagerEx_getActionByName : Error processing arguments"); cocostudio::ActionObject* ret = cobj->getActionByName(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -584,7 +602,7 @@ bool js_cocos2dx_studio_ActionManagerEx_getActionByName(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -593,9 +611,9 @@ bool js_cocos2dx_studio_ActionManagerEx_getActionByName(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ActionManagerEx_initWithBinary(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionManagerEx* cobj = (cocostudio::ActionManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionManagerEx_initWithBinary : Invalid Native Object"); @@ -604,19 +622,19 @@ bool js_cocos2dx_studio_ActionManagerEx_initWithBinary(JSContext *cx, uint32_t a cocos2d::Ref* arg1; cocostudio::CocoLoader* arg2; cocostudio::stExpCocoNode* arg3; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Ref*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocostudio::CocoLoader*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -625,7 +643,7 @@ bool js_cocos2dx_studio_ActionManagerEx_initWithBinary(JSContext *cx, uint32_t a ok = false; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionManagerEx_initWithBinary : Error processing arguments"); cobj->initWithBinary(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -634,28 +652,28 @@ bool js_cocos2dx_studio_ActionManagerEx_initWithBinary(JSContext *cx, uint32_t a } bool js_cocos2dx_studio_ActionManagerEx_playActionByName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocostudio::ActionManagerEx* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocostudio::ActionManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionManagerEx_playActionByName : Invalid Native Object"); do { if (argc == 3) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } const char* arg1; - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); if (!ok) { ok = true; break; } cocos2d::CallFunc* arg2; do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::CallFunc*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -671,7 +689,7 @@ bool js_cocos2dx_studio_ActionManagerEx_playActionByName(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -679,10 +697,10 @@ bool js_cocos2dx_studio_ActionManagerEx_playActionByName(JSContext *cx, uint32_t do { if (argc == 2) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } const char* arg1; - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); if (!ok) { ok = true; break; } cocostudio::ActionObject* ret = cobj->playActionByName(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -694,7 +712,7 @@ bool js_cocos2dx_studio_ActionManagerEx_playActionByName(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -704,13 +722,14 @@ bool js_cocos2dx_studio_ActionManagerEx_playActionByName(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ActionManagerEx_releaseActions(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionManagerEx* cobj = (cocostudio::ActionManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionManagerEx_releaseActions : Invalid Native Object"); if (argc == 0) { cobj->releaseActions(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -719,9 +738,10 @@ bool js_cocos2dx_studio_ActionManagerEx_releaseActions(JSContext *cx, uint32_t a } bool js_cocos2dx_studio_ActionManagerEx_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::ActionManagerEx::destroyInstance(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ActionManagerEx_destroyInstance : wrong number of arguments"); @@ -730,6 +750,7 @@ bool js_cocos2dx_studio_ActionManagerEx_destroyInstance(JSContext *cx, uint32_t bool js_cocos2dx_studio_ActionManagerEx_getInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::ActionManagerEx* ret = cocostudio::ActionManagerEx::getInstance(); jsval jsret = JSVAL_NULL; @@ -741,7 +762,7 @@ bool js_cocos2dx_studio_ActionManagerEx_getInstance(JSContext *cx, uint32_t argc jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ActionManagerEx_getInstance : wrong number of arguments"); @@ -754,7 +775,7 @@ void js_cocostudio_ActionManagerEx_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ActionManagerEx)", obj); } -void js_register_cocos2dx_studio_ActionManagerEx(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ActionManagerEx(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_ActionManagerEx_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_ActionManagerEx_class->name = "ActionManager"; jsb_cocostudio_ActionManagerEx_class->addProperty = JS_PropertyStub; @@ -768,8 +789,8 @@ void js_register_cocos2dx_studio_ActionManagerEx(JSContext *cx, JSObject *global jsb_cocostudio_ActionManagerEx_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -789,7 +810,7 @@ void js_register_cocos2dx_studio_ActionManagerEx(JSContext *cx, JSObject *global jsb_cocostudio_ActionManagerEx_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_ActionManagerEx_class, empty_constructor, 0, properties, @@ -820,7 +841,8 @@ JSObject *jsb_cocostudio_BaseData_prototype; bool js_cocos2dx_studio_BaseData_getColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::BaseData* cobj = (cocostudio::BaseData *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_BaseData_getColor : Invalid Native Object"); @@ -828,7 +850,7 @@ bool js_cocos2dx_studio_BaseData_getColor(JSContext *cx, uint32_t argc, jsval *v cocos2d::Color4B ret = cobj->getColor(); jsval jsret = JSVAL_NULL; jsret = cccolor4b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -837,18 +859,18 @@ bool js_cocos2dx_studio_BaseData_getColor(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_BaseData_setColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::BaseData* cobj = (cocostudio::BaseData *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_BaseData_setColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_BaseData_setColor : Error processing arguments"); cobj->setColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -857,6 +879,7 @@ bool js_cocos2dx_studio_BaseData_setColor(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_BaseData_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::BaseData* ret = cocostudio::BaseData::create(); jsval jsret = JSVAL_NULL; @@ -868,7 +891,7 @@ bool js_cocos2dx_studio_BaseData_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_BaseData_create : wrong number of arguments"); @@ -877,7 +900,7 @@ bool js_cocos2dx_studio_BaseData_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_studio_BaseData_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::BaseData* cobj = new (std::nothrow) cocostudio::BaseData(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -891,13 +914,16 @@ bool js_cocos2dx_studio_BaseData_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::BaseData"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::BaseData"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -907,7 +933,7 @@ void js_cocostudio_BaseData_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (BaseData)", obj); } -void js_register_cocos2dx_studio_BaseData(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_BaseData(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_BaseData_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_BaseData_class->name = "BaseData"; jsb_cocostudio_BaseData_class->addProperty = JS_PropertyStub; @@ -921,8 +947,8 @@ void js_register_cocos2dx_studio_BaseData(JSContext *cx, JSObject *global) { jsb_cocostudio_BaseData_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -938,7 +964,7 @@ void js_register_cocos2dx_studio_BaseData(JSContext *cx, JSObject *global) { jsb_cocostudio_BaseData_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_BaseData_class, js_cocos2dx_studio_BaseData_constructor, 0, // constructor properties, @@ -969,15 +995,15 @@ JSObject *jsb_cocostudio_MovementData_prototype; bool js_cocos2dx_studio_MovementData_getMovementBoneData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::MovementData* cobj = (cocostudio::MovementData *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_MovementData_getMovementBoneData : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_MovementData_getMovementBoneData : Error processing arguments"); cocostudio::MovementBoneData* ret = cobj->getMovementBoneData(arg0); jsval jsret = JSVAL_NULL; @@ -989,7 +1015,7 @@ bool js_cocos2dx_studio_MovementData_getMovementBoneData(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -998,25 +1024,25 @@ bool js_cocos2dx_studio_MovementData_getMovementBoneData(JSContext *cx, uint32_t } bool js_cocos2dx_studio_MovementData_addMovementBoneData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::MovementData* cobj = (cocostudio::MovementData *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_MovementData_addMovementBoneData : Invalid Native Object"); if (argc == 1) { cocostudio::MovementBoneData* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::MovementBoneData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_MovementData_addMovementBoneData : Error processing arguments"); cobj->addMovementBoneData(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1025,6 +1051,7 @@ bool js_cocos2dx_studio_MovementData_addMovementBoneData(JSContext *cx, uint32_t } bool js_cocos2dx_studio_MovementData_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::MovementData* ret = cocostudio::MovementData::create(); jsval jsret = JSVAL_NULL; @@ -1036,7 +1063,7 @@ bool js_cocos2dx_studio_MovementData_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_MovementData_create : wrong number of arguments"); @@ -1045,7 +1072,7 @@ bool js_cocos2dx_studio_MovementData_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_studio_MovementData_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::MovementData* cobj = new (std::nothrow) cocostudio::MovementData(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1059,13 +1086,16 @@ bool js_cocos2dx_studio_MovementData_constructor(JSContext *cx, uint32_t argc, j CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::MovementData"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::MovementData"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -1075,7 +1105,7 @@ void js_cocostudio_MovementData_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (MovementData)", obj); } -void js_register_cocos2dx_studio_MovementData(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_MovementData(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_MovementData_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_MovementData_class->name = "MovementData"; jsb_cocostudio_MovementData_class->addProperty = JS_PropertyStub; @@ -1089,8 +1119,8 @@ void js_register_cocos2dx_studio_MovementData(JSContext *cx, JSObject *global) { jsb_cocostudio_MovementData_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1106,7 +1136,7 @@ void js_register_cocos2dx_studio_MovementData(JSContext *cx, JSObject *global) { jsb_cocostudio_MovementData_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_MovementData_class, js_cocos2dx_studio_MovementData_constructor, 0, // constructor properties, @@ -1137,15 +1167,15 @@ JSObject *jsb_cocostudio_AnimationData_prototype; bool js_cocos2dx_studio_AnimationData_getMovement(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::AnimationData* cobj = (cocostudio::AnimationData *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_AnimationData_getMovement : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_AnimationData_getMovement : Error processing arguments"); cocostudio::MovementData* ret = cobj->getMovement(arg0); jsval jsret = JSVAL_NULL; @@ -1157,7 +1187,7 @@ bool js_cocos2dx_studio_AnimationData_getMovement(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1166,7 +1196,8 @@ bool js_cocos2dx_studio_AnimationData_getMovement(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_AnimationData_getMovementCount(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::AnimationData* cobj = (cocostudio::AnimationData *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_AnimationData_getMovementCount : Invalid Native Object"); @@ -1174,7 +1205,7 @@ bool js_cocos2dx_studio_AnimationData_getMovementCount(JSContext *cx, uint32_t a ssize_t ret = cobj->getMovementCount(); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1183,25 +1214,25 @@ bool js_cocos2dx_studio_AnimationData_getMovementCount(JSContext *cx, uint32_t a } bool js_cocos2dx_studio_AnimationData_addMovement(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::AnimationData* cobj = (cocostudio::AnimationData *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_AnimationData_addMovement : Invalid Native Object"); if (argc == 1) { cocostudio::MovementData* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::MovementData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_AnimationData_addMovement : Error processing arguments"); cobj->addMovement(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1210,6 +1241,7 @@ bool js_cocos2dx_studio_AnimationData_addMovement(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_AnimationData_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::AnimationData* ret = cocostudio::AnimationData::create(); jsval jsret = JSVAL_NULL; @@ -1221,7 +1253,7 @@ bool js_cocos2dx_studio_AnimationData_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_AnimationData_create : wrong number of arguments"); @@ -1230,7 +1262,7 @@ bool js_cocos2dx_studio_AnimationData_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_studio_AnimationData_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::AnimationData* cobj = new (std::nothrow) cocostudio::AnimationData(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1244,13 +1276,16 @@ bool js_cocos2dx_studio_AnimationData_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::AnimationData"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::AnimationData"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -1260,7 +1295,7 @@ void js_cocostudio_AnimationData_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (AnimationData)", obj); } -void js_register_cocos2dx_studio_AnimationData(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_AnimationData(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_AnimationData_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_AnimationData_class->name = "AnimationData"; jsb_cocostudio_AnimationData_class->addProperty = JS_PropertyStub; @@ -1274,8 +1309,8 @@ void js_register_cocos2dx_studio_AnimationData(JSContext *cx, JSObject *global) jsb_cocostudio_AnimationData_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1292,7 +1327,7 @@ void js_register_cocos2dx_studio_AnimationData(JSContext *cx, JSObject *global) jsb_cocostudio_AnimationData_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_AnimationData_class, js_cocos2dx_studio_AnimationData_constructor, 0, // constructor properties, @@ -1318,14 +1353,359 @@ void js_register_cocos2dx_studio_AnimationData(JSContext *cx, JSObject *global) } } +JSClass *jsb_cocostudio_ContourData_class; +JSObject *jsb_cocostudio_ContourData_prototype; + +bool js_cocos2dx_studio_ContourData_init(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::ContourData* cobj = (cocostudio::ContourData *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ContourData_init : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->init(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_ContourData_init : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_studio_ContourData_addVertex(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::ContourData* cobj = (cocostudio::ContourData *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ContourData_addVertex : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vec2 arg0; + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ContourData_addVertex : Error processing arguments"); + cobj->addVertex(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_ContourData_addVertex : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_studio_ContourData_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (argc == 0) { + cocostudio::ContourData* ret = cocostudio::ContourData::create(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocostudio::ContourData*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_studio_ContourData_create : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_studio_ContourData_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocostudio::ContourData* cobj = new (std::nothrow) cocostudio::ContourData(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ContourData"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + + +void js_cocostudio_ContourData_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (ContourData)", obj); +} + +void js_register_cocos2dx_studio_ContourData(JSContext *cx, JS::HandleObject global) { + jsb_cocostudio_ContourData_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocostudio_ContourData_class->name = "ContourData"; + jsb_cocostudio_ContourData_class->addProperty = JS_PropertyStub; + jsb_cocostudio_ContourData_class->delProperty = JS_DeletePropertyStub; + jsb_cocostudio_ContourData_class->getProperty = JS_PropertyStub; + jsb_cocostudio_ContourData_class->setProperty = JS_StrictPropertyStub; + jsb_cocostudio_ContourData_class->enumerate = JS_EnumerateStub; + jsb_cocostudio_ContourData_class->resolve = JS_ResolveStub; + jsb_cocostudio_ContourData_class->convert = JS_ConvertStub; + jsb_cocostudio_ContourData_class->finalize = js_cocostudio_ContourData_finalize; + jsb_cocostudio_ContourData_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("init", js_cocos2dx_studio_ContourData_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("addVertex", js_cocos2dx_studio_ContourData_addVertex, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_studio_ContourData_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocostudio_ContourData_prototype = JS_InitClass( + cx, global, + JS::NullPtr(), // parent proto + jsb_cocostudio_ContourData_class, + js_cocos2dx_studio_ContourData_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "ContourData", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocostudio_ContourData_class; + p->proto = jsb_cocostudio_ContourData_prototype; + p->parentProto = NULL; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocostudio_TextureData_class; +JSObject *jsb_cocostudio_TextureData_prototype; + +bool js_cocos2dx_studio_TextureData_getContourData(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::TextureData* cobj = (cocostudio::TextureData *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_TextureData_getContourData : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_TextureData_getContourData : Error processing arguments"); + cocostudio::ContourData* ret = cobj->getContourData(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocostudio::ContourData*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_TextureData_getContourData : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_studio_TextureData_init(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::TextureData* cobj = (cocostudio::TextureData *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_TextureData_init : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->init(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_TextureData_init : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_studio_TextureData_addContourData(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::TextureData* cobj = (cocostudio::TextureData *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_TextureData_addContourData : Invalid Native Object"); + if (argc == 1) { + cocostudio::ContourData* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocostudio::ContourData*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_TextureData_addContourData : Error processing arguments"); + cobj->addContourData(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_TextureData_addContourData : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_studio_TextureData_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (argc == 0) { + cocostudio::TextureData* ret = cocostudio::TextureData::create(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocostudio::TextureData*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_studio_TextureData_create : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_studio_TextureData_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocostudio::TextureData* cobj = new (std::nothrow) cocostudio::TextureData(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::TextureData"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + + +void js_cocostudio_TextureData_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (TextureData)", obj); +} + +void js_register_cocos2dx_studio_TextureData(JSContext *cx, JS::HandleObject global) { + jsb_cocostudio_TextureData_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocostudio_TextureData_class->name = "TextureData"; + jsb_cocostudio_TextureData_class->addProperty = JS_PropertyStub; + jsb_cocostudio_TextureData_class->delProperty = JS_DeletePropertyStub; + jsb_cocostudio_TextureData_class->getProperty = JS_PropertyStub; + jsb_cocostudio_TextureData_class->setProperty = JS_StrictPropertyStub; + jsb_cocostudio_TextureData_class->enumerate = JS_EnumerateStub; + jsb_cocostudio_TextureData_class->resolve = JS_ResolveStub; + jsb_cocostudio_TextureData_class->convert = JS_ConvertStub; + jsb_cocostudio_TextureData_class->finalize = js_cocostudio_TextureData_finalize; + jsb_cocostudio_TextureData_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("getContourData", js_cocos2dx_studio_TextureData_getContourData, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("init", js_cocos2dx_studio_TextureData_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("addContourData", js_cocos2dx_studio_TextureData_addContourData, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_studio_TextureData_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocostudio_TextureData_prototype = JS_InitClass( + cx, global, + JS::NullPtr(), // parent proto + jsb_cocostudio_TextureData_class, + js_cocos2dx_studio_TextureData_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "TextureData", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocostudio_TextureData_class; + p->proto = jsb_cocostudio_TextureData_prototype; + p->parentProto = NULL; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + JSClass *jsb_cocostudio_ProcessBase_class; JSObject *jsb_cocostudio_ProcessBase_prototype; bool js_cocos2dx_studio_ProcessBase_play(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_play : Invalid Native Object"); @@ -1334,13 +1714,13 @@ bool js_cocos2dx_studio_ProcessBase_play(JSContext *cx, uint32_t argc, jsval *vp int arg1; int arg2; int arg3; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ProcessBase_play : Error processing arguments"); cobj->play(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1349,13 +1729,14 @@ bool js_cocos2dx_studio_ProcessBase_play(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_studio_ProcessBase_pause(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_pause : Invalid Native Object"); if (argc == 0) { cobj->pause(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1364,7 +1745,8 @@ bool js_cocos2dx_studio_ProcessBase_pause(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_ProcessBase_getRawDuration(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_getRawDuration : Invalid Native Object"); @@ -1372,7 +1754,7 @@ bool js_cocos2dx_studio_ProcessBase_getRawDuration(JSContext *cx, uint32_t argc, int ret = cobj->getRawDuration(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1381,13 +1763,14 @@ bool js_cocos2dx_studio_ProcessBase_getRawDuration(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_ProcessBase_resume(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_resume : Invalid Native Object"); if (argc == 0) { cobj->resume(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1396,18 +1779,18 @@ bool js_cocos2dx_studio_ProcessBase_resume(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_ProcessBase_setIsComplete(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_setIsComplete : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ProcessBase_setIsComplete : Error processing arguments"); cobj->setIsComplete(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1416,13 +1799,14 @@ bool js_cocos2dx_studio_ProcessBase_setIsComplete(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_ProcessBase_stop(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_stop : Invalid Native Object"); if (argc == 0) { cobj->stop(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1431,18 +1815,18 @@ bool js_cocos2dx_studio_ProcessBase_stop(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_studio_ProcessBase_update(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_update : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ProcessBase_update : Error processing arguments"); cobj->update(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1451,7 +1835,8 @@ bool js_cocos2dx_studio_ProcessBase_update(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_ProcessBase_getCurrentFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_getCurrentFrameIndex : Invalid Native Object"); @@ -1459,7 +1844,7 @@ bool js_cocos2dx_studio_ProcessBase_getCurrentFrameIndex(JSContext *cx, uint32_t int ret = cobj->getCurrentFrameIndex(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1468,7 +1853,8 @@ bool js_cocos2dx_studio_ProcessBase_getCurrentFrameIndex(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ProcessBase_isComplete(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_isComplete : Invalid Native Object"); @@ -1476,7 +1862,7 @@ bool js_cocos2dx_studio_ProcessBase_isComplete(JSContext *cx, uint32_t argc, jsv bool ret = cobj->isComplete(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1485,7 +1871,8 @@ bool js_cocos2dx_studio_ProcessBase_isComplete(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_studio_ProcessBase_getCurrentPercent(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_getCurrentPercent : Invalid Native Object"); @@ -1493,7 +1880,7 @@ bool js_cocos2dx_studio_ProcessBase_getCurrentPercent(JSContext *cx, uint32_t ar double ret = cobj->getCurrentPercent(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1502,18 +1889,18 @@ bool js_cocos2dx_studio_ProcessBase_getCurrentPercent(JSContext *cx, uint32_t ar } bool js_cocos2dx_studio_ProcessBase_setIsPause(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_setIsPause : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ProcessBase_setIsPause : Error processing arguments"); cobj->setIsPause(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1522,7 +1909,8 @@ bool js_cocos2dx_studio_ProcessBase_setIsPause(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_studio_ProcessBase_getProcessScale(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_getProcessScale : Invalid Native Object"); @@ -1530,7 +1918,7 @@ bool js_cocos2dx_studio_ProcessBase_getProcessScale(JSContext *cx, uint32_t argc double ret = cobj->getProcessScale(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1539,7 +1927,8 @@ bool js_cocos2dx_studio_ProcessBase_getProcessScale(JSContext *cx, uint32_t argc } bool js_cocos2dx_studio_ProcessBase_isPause(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_isPause : Invalid Native Object"); @@ -1547,7 +1936,7 @@ bool js_cocos2dx_studio_ProcessBase_isPause(JSContext *cx, uint32_t argc, jsval bool ret = cobj->isPause(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1556,7 +1945,8 @@ bool js_cocos2dx_studio_ProcessBase_isPause(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ProcessBase_isPlaying(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_isPlaying : Invalid Native Object"); @@ -1564,7 +1954,7 @@ bool js_cocos2dx_studio_ProcessBase_isPlaying(JSContext *cx, uint32_t argc, jsva bool ret = cobj->isPlaying(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1573,18 +1963,18 @@ bool js_cocos2dx_studio_ProcessBase_isPlaying(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_ProcessBase_setProcessScale(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_setProcessScale : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ProcessBase_setProcessScale : Error processing arguments"); cobj->setProcessScale(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1593,18 +1983,18 @@ bool js_cocos2dx_studio_ProcessBase_setProcessScale(JSContext *cx, uint32_t argc } bool js_cocos2dx_studio_ProcessBase_setIsPlaying(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ProcessBase* cobj = (cocostudio::ProcessBase *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ProcessBase_setIsPlaying : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ProcessBase_setIsPlaying : Error processing arguments"); cobj->setIsPlaying(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1613,7 +2003,7 @@ bool js_cocos2dx_studio_ProcessBase_setIsPlaying(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_studio_ProcessBase_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::ProcessBase* cobj = new (std::nothrow) cocostudio::ProcessBase(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1627,13 +2017,16 @@ bool js_cocos2dx_studio_ProcessBase_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::ProcessBase"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ProcessBase"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -1643,7 +2036,7 @@ void js_cocostudio_ProcessBase_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ProcessBase)", obj); } -void js_register_cocos2dx_studio_ProcessBase(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ProcessBase(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_ProcessBase_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_ProcessBase_class->name = "ProcessBase"; jsb_cocostudio_ProcessBase_class->addProperty = JS_PropertyStub; @@ -1657,8 +2050,8 @@ void js_register_cocos2dx_studio_ProcessBase(JSContext *cx, JSObject *global) { jsb_cocostudio_ProcessBase_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1685,7 +2078,7 @@ void js_register_cocos2dx_studio_ProcessBase(JSContext *cx, JSObject *global) { jsb_cocostudio_ProcessBase_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_ProcessBase_class, js_cocos2dx_studio_ProcessBase_constructor, 0, // constructor properties, @@ -1716,7 +2109,8 @@ JSObject *jsb_cocostudio_Tween_prototype; bool js_cocos2dx_studio_Tween_getAnimation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Tween* cobj = (cocostudio::Tween *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Tween_getAnimation : Invalid Native Object"); @@ -1731,7 +2125,7 @@ bool js_cocos2dx_studio_Tween_getAnimation(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1740,18 +2134,18 @@ bool js_cocos2dx_studio_Tween_getAnimation(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_Tween_gotoAndPause(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Tween* cobj = (cocostudio::Tween *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Tween_gotoAndPause : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Tween_gotoAndPause : Error processing arguments"); cobj->gotoAndPause(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1760,9 +2154,9 @@ bool js_cocos2dx_studio_Tween_gotoAndPause(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_Tween_play(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Tween* cobj = (cocostudio::Tween *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Tween_play : Invalid Native Object"); @@ -1773,20 +2167,20 @@ bool js_cocos2dx_studio_Tween_play(JSContext *cx, uint32_t argc, jsval *vp) int arg3; int arg4; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::MovementBoneData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); - ok &= jsval_to_int32(cx, argv[4], (int32_t *)&arg4); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Tween_play : Error processing arguments"); cobj->play(arg0, arg1, arg2, arg3, arg4); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1795,18 +2189,18 @@ bool js_cocos2dx_studio_Tween_play(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Tween_gotoAndPlay(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Tween* cobj = (cocostudio::Tween *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Tween_gotoAndPlay : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Tween_gotoAndPlay : Error processing arguments"); cobj->gotoAndPlay(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1815,18 +2209,18 @@ bool js_cocos2dx_studio_Tween_gotoAndPlay(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_Tween_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Tween* cobj = (cocostudio::Tween *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Tween_init : Invalid Native Object"); if (argc == 1) { cocostudio::Bone* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -1835,7 +2229,7 @@ bool js_cocos2dx_studio_Tween_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1844,25 +2238,25 @@ bool js_cocos2dx_studio_Tween_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Tween_setAnimation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Tween* cobj = (cocostudio::Tween *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Tween_setAnimation : Invalid Native Object"); if (argc == 1) { cocostudio::ArmatureAnimation* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::ArmatureAnimation*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Tween_setAnimation : Error processing arguments"); cobj->setAnimation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1871,14 +2265,14 @@ bool js_cocos2dx_studio_Tween_setAnimation(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_Tween_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocostudio::Bone* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -1894,7 +2288,7 @@ bool js_cocos2dx_studio_Tween_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_Tween_create : wrong number of arguments"); @@ -1903,7 +2297,7 @@ bool js_cocos2dx_studio_Tween_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_studio_Tween_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::Tween* cobj = new (std::nothrow) cocostudio::Tween(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1917,13 +2311,16 @@ bool js_cocos2dx_studio_Tween_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::Tween"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::Tween"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -1934,7 +2331,7 @@ void js_cocostudio_Tween_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Tween)", obj); } -void js_register_cocos2dx_studio_Tween(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_Tween(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_Tween_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_Tween_class->name = "Tween"; jsb_cocostudio_Tween_class->addProperty = JS_PropertyStub; @@ -1948,8 +2345,8 @@ void js_register_cocos2dx_studio_Tween(JSContext *cx, JSObject *global) { jsb_cocostudio_Tween_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1969,7 +2366,7 @@ void js_register_cocos2dx_studio_Tween(JSContext *cx, JSObject *global) { jsb_cocostudio_Tween_prototype = JS_InitClass( cx, global, - jsb_cocostudio_ProcessBase_prototype, + JS::RootedObject(cx, jsb_cocostudio_ProcessBase_prototype), jsb_cocostudio_Tween_class, js_cocos2dx_studio_Tween_constructor, 0, // constructor properties, @@ -2004,7 +2401,7 @@ void js_cocostudio_ColliderFilter_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ColliderFilter)", obj); } -void js_register_cocos2dx_studio_ColliderFilter(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ColliderFilter(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_ColliderFilter_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_ColliderFilter_class->name = "ColliderFilter"; jsb_cocostudio_ColliderFilter_class->addProperty = JS_PropertyStub; @@ -2018,8 +2415,8 @@ void js_register_cocos2dx_studio_ColliderFilter(JSContext *cx, JSObject *global) jsb_cocostudio_ColliderFilter_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -2030,7 +2427,7 @@ void js_register_cocos2dx_studio_ColliderFilter(JSContext *cx, JSObject *global) jsb_cocostudio_ColliderFilter_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_ColliderFilter_class, empty_constructor, 0, properties, @@ -2065,7 +2462,7 @@ void js_cocostudio_ColliderBody_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ColliderBody)", obj); } -void js_register_cocos2dx_studio_ColliderBody(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ColliderBody(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_ColliderBody_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_ColliderBody_class->name = "ColliderBody"; jsb_cocostudio_ColliderBody_class->addProperty = JS_PropertyStub; @@ -2079,8 +2476,8 @@ void js_register_cocos2dx_studio_ColliderBody(JSContext *cx, JSObject *global) { jsb_cocostudio_ColliderBody_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -2091,7 +2488,7 @@ void js_register_cocos2dx_studio_ColliderBody(JSContext *cx, JSObject *global) { jsb_cocostudio_ColliderBody_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_ColliderBody_class, empty_constructor, 0, properties, @@ -2122,7 +2519,8 @@ JSObject *jsb_cocostudio_ColliderDetector_prototype; bool js_cocos2dx_studio_ColliderDetector_getBone(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ColliderDetector* cobj = (cocostudio::ColliderDetector *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ColliderDetector_getBone : Invalid Native Object"); @@ -2137,7 +2535,7 @@ bool js_cocos2dx_studio_ColliderDetector_getBone(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2146,7 +2544,8 @@ bool js_cocos2dx_studio_ColliderDetector_getBone(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_studio_ColliderDetector_getActive(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ColliderDetector* cobj = (cocostudio::ColliderDetector *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ColliderDetector_getActive : Invalid Native Object"); @@ -2154,7 +2553,7 @@ bool js_cocos2dx_studio_ColliderDetector_getActive(JSContext *cx, uint32_t argc, bool ret = cobj->getActive(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2163,7 +2562,8 @@ bool js_cocos2dx_studio_ColliderDetector_getActive(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_ColliderDetector_getColliderBodyList(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ColliderDetector* cobj = (cocostudio::ColliderDetector *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ColliderDetector_getColliderBodyList : Invalid Native Object"); @@ -2171,7 +2571,7 @@ bool js_cocos2dx_studio_ColliderDetector_getColliderBodyList(JSContext *cx, uint const cocos2d::Vector& ret = cobj->getColliderBodyList(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2180,18 +2580,18 @@ bool js_cocos2dx_studio_ColliderDetector_getColliderBodyList(JSContext *cx, uint } bool js_cocos2dx_studio_ColliderDetector_updateTransform(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ColliderDetector* cobj = (cocostudio::ColliderDetector *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ColliderDetector_updateTransform : Invalid Native Object"); if (argc == 1) { cocos2d::Mat4 arg0; - ok &= jsval_to_matrix(cx, argv[0], &arg0); + ok &= jsval_to_matrix(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ColliderDetector_updateTransform : Error processing arguments"); cobj->updateTransform(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2200,13 +2600,14 @@ bool js_cocos2dx_studio_ColliderDetector_updateTransform(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ColliderDetector_removeAll(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ColliderDetector* cobj = (cocostudio::ColliderDetector *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ColliderDetector_removeAll : Invalid Native Object"); if (argc == 0) { cobj->removeAll(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2215,12 +2616,12 @@ bool js_cocos2dx_studio_ColliderDetector_removeAll(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_ColliderDetector_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocostudio::ColliderDetector* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocostudio::ColliderDetector *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ColliderDetector_init : Invalid Native Object"); @@ -2228,9 +2629,9 @@ bool js_cocos2dx_studio_ColliderDetector_init(JSContext *cx, uint32_t argc, jsva if (argc == 1) { cocostudio::Bone* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -2239,7 +2640,7 @@ bool js_cocos2dx_studio_ColliderDetector_init(JSContext *cx, uint32_t argc, jsva bool ret = cobj->init(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -2249,7 +2650,7 @@ bool js_cocos2dx_studio_ColliderDetector_init(JSContext *cx, uint32_t argc, jsva bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -2259,18 +2660,18 @@ bool js_cocos2dx_studio_ColliderDetector_init(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_ColliderDetector_setActive(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ColliderDetector* cobj = (cocostudio::ColliderDetector *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ColliderDetector_setActive : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ColliderDetector_setActive : Error processing arguments"); cobj->setActive(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2279,25 +2680,25 @@ bool js_cocos2dx_studio_ColliderDetector_setActive(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_ColliderDetector_setBone(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ColliderDetector* cobj = (cocostudio::ColliderDetector *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ColliderDetector_setBone : Invalid Native Object"); if (argc == 1) { cocostudio::Bone* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ColliderDetector_setBone : Error processing arguments"); cobj->setBone(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2306,16 +2707,16 @@ bool js_cocos2dx_studio_ColliderDetector_setBone(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_studio_ColliderDetector_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { cocostudio::Bone* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -2331,7 +2732,7 @@ bool js_cocos2dx_studio_ColliderDetector_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -2348,7 +2749,7 @@ bool js_cocos2dx_studio_ColliderDetector_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -2361,7 +2762,7 @@ void js_cocostudio_ColliderDetector_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ColliderDetector)", obj); } -void js_register_cocos2dx_studio_ColliderDetector(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ColliderDetector(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_ColliderDetector_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_ColliderDetector_class->name = "ColliderDetector"; jsb_cocostudio_ColliderDetector_class->addProperty = JS_PropertyStub; @@ -2375,8 +2776,8 @@ void js_register_cocos2dx_studio_ColliderDetector(JSContext *cx, JSObject *globa jsb_cocostudio_ColliderDetector_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -2398,7 +2799,7 @@ void js_register_cocos2dx_studio_ColliderDetector(JSContext *cx, JSObject *globa jsb_cocostudio_ColliderDetector_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_ColliderDetector_class, empty_constructor, 0, properties, @@ -2429,7 +2830,8 @@ JSObject *jsb_cocostudio_DecorativeDisplay_prototype; bool js_cocos2dx_studio_DecorativeDisplay_getColliderDetector(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DecorativeDisplay* cobj = (cocostudio::DecorativeDisplay *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DecorativeDisplay_getColliderDetector : Invalid Native Object"); @@ -2444,7 +2846,7 @@ bool js_cocos2dx_studio_DecorativeDisplay_getColliderDetector(JSContext *cx, uin jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2453,7 +2855,8 @@ bool js_cocos2dx_studio_DecorativeDisplay_getColliderDetector(JSContext *cx, uin } bool js_cocos2dx_studio_DecorativeDisplay_getDisplay(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DecorativeDisplay* cobj = (cocostudio::DecorativeDisplay *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DecorativeDisplay_getDisplay : Invalid Native Object"); @@ -2468,7 +2871,7 @@ bool js_cocos2dx_studio_DecorativeDisplay_getDisplay(JSContext *cx, uint32_t arg jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2477,25 +2880,25 @@ bool js_cocos2dx_studio_DecorativeDisplay_getDisplay(JSContext *cx, uint32_t arg } bool js_cocos2dx_studio_DecorativeDisplay_setDisplay(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DecorativeDisplay* cobj = (cocostudio::DecorativeDisplay *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DecorativeDisplay_setDisplay : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_DecorativeDisplay_setDisplay : Error processing arguments"); cobj->setDisplay(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2504,7 +2907,8 @@ bool js_cocos2dx_studio_DecorativeDisplay_setDisplay(JSContext *cx, uint32_t arg } bool js_cocos2dx_studio_DecorativeDisplay_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DecorativeDisplay* cobj = (cocostudio::DecorativeDisplay *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DecorativeDisplay_init : Invalid Native Object"); @@ -2512,7 +2916,7 @@ bool js_cocos2dx_studio_DecorativeDisplay_init(JSContext *cx, uint32_t argc, jsv bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2521,25 +2925,25 @@ bool js_cocos2dx_studio_DecorativeDisplay_init(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_studio_DecorativeDisplay_setDisplayData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DecorativeDisplay* cobj = (cocostudio::DecorativeDisplay *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DecorativeDisplay_setDisplayData : Invalid Native Object"); if (argc == 1) { cocostudio::DisplayData* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::DisplayData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_DecorativeDisplay_setDisplayData : Error processing arguments"); cobj->setDisplayData(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2548,7 +2952,8 @@ bool js_cocos2dx_studio_DecorativeDisplay_setDisplayData(JSContext *cx, uint32_t } bool js_cocos2dx_studio_DecorativeDisplay_getDisplayData(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DecorativeDisplay* cobj = (cocostudio::DecorativeDisplay *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DecorativeDisplay_getDisplayData : Invalid Native Object"); @@ -2563,7 +2968,7 @@ bool js_cocos2dx_studio_DecorativeDisplay_getDisplayData(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2572,25 +2977,25 @@ bool js_cocos2dx_studio_DecorativeDisplay_getDisplayData(JSContext *cx, uint32_t } bool js_cocos2dx_studio_DecorativeDisplay_setColliderDetector(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DecorativeDisplay* cobj = (cocostudio::DecorativeDisplay *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DecorativeDisplay_setColliderDetector : Invalid Native Object"); if (argc == 1) { cocostudio::ColliderDetector* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::ColliderDetector*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_DecorativeDisplay_setColliderDetector : Error processing arguments"); cobj->setColliderDetector(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2599,6 +3004,7 @@ bool js_cocos2dx_studio_DecorativeDisplay_setColliderDetector(JSContext *cx, uin } bool js_cocos2dx_studio_DecorativeDisplay_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::DecorativeDisplay* ret = cocostudio::DecorativeDisplay::create(); jsval jsret = JSVAL_NULL; @@ -2610,7 +3016,7 @@ bool js_cocos2dx_studio_DecorativeDisplay_create(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_DecorativeDisplay_create : wrong number of arguments"); @@ -2623,7 +3029,7 @@ void js_cocostudio_DecorativeDisplay_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (DecorativeDisplay)", obj); } -void js_register_cocos2dx_studio_DecorativeDisplay(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_DecorativeDisplay(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_DecorativeDisplay_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_DecorativeDisplay_class->name = "DecorativeDisplay"; jsb_cocostudio_DecorativeDisplay_class->addProperty = JS_PropertyStub; @@ -2637,8 +3043,8 @@ void js_register_cocos2dx_studio_DecorativeDisplay(JSContext *cx, JSObject *glob jsb_cocostudio_DecorativeDisplay_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -2659,7 +3065,7 @@ void js_register_cocos2dx_studio_DecorativeDisplay(JSContext *cx, JSObject *glob jsb_cocostudio_DecorativeDisplay_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_DecorativeDisplay_class, empty_constructor, 0, properties, @@ -2690,7 +3096,8 @@ JSObject *jsb_cocostudio_DisplayManager_prototype; bool js_cocos2dx_studio_DisplayManager_getCurrentDecorativeDisplay(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_getCurrentDecorativeDisplay : Invalid Native Object"); @@ -2705,7 +3112,7 @@ bool js_cocos2dx_studio_DisplayManager_getCurrentDecorativeDisplay(JSContext *cx jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2714,7 +3121,8 @@ bool js_cocos2dx_studio_DisplayManager_getCurrentDecorativeDisplay(JSContext *cx } bool js_cocos2dx_studio_DisplayManager_getDisplayRenderNode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_getDisplayRenderNode : Invalid Native Object"); @@ -2729,7 +3137,7 @@ bool js_cocos2dx_studio_DisplayManager_getDisplayRenderNode(JSContext *cx, uint3 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2738,7 +3146,8 @@ bool js_cocos2dx_studio_DisplayManager_getDisplayRenderNode(JSContext *cx, uint3 } bool js_cocos2dx_studio_DisplayManager_getAnchorPointInPoints(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_getAnchorPointInPoints : Invalid Native Object"); @@ -2746,7 +3155,7 @@ bool js_cocos2dx_studio_DisplayManager_getAnchorPointInPoints(JSContext *cx, uin cocos2d::Vec2 ret = cobj->getAnchorPointInPoints(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2755,25 +3164,25 @@ bool js_cocos2dx_studio_DisplayManager_getAnchorPointInPoints(JSContext *cx, uin } bool js_cocos2dx_studio_DisplayManager_setCurrentDecorativeDisplay(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_setCurrentDecorativeDisplay : Invalid Native Object"); if (argc == 1) { cocostudio::DecorativeDisplay* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::DecorativeDisplay*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_DisplayManager_setCurrentDecorativeDisplay : Error processing arguments"); cobj->setCurrentDecorativeDisplay(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2782,7 +3191,8 @@ bool js_cocos2dx_studio_DisplayManager_setCurrentDecorativeDisplay(JSContext *cx } bool js_cocos2dx_studio_DisplayManager_getDisplayRenderNodeType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_getDisplayRenderNodeType : Invalid Native Object"); @@ -2790,7 +3200,7 @@ bool js_cocos2dx_studio_DisplayManager_getDisplayRenderNodeType(JSContext *cx, u int ret = (int)cobj->getDisplayRenderNodeType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2799,18 +3209,18 @@ bool js_cocos2dx_studio_DisplayManager_getDisplayRenderNodeType(JSContext *cx, u } bool js_cocos2dx_studio_DisplayManager_removeDisplay(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_removeDisplay : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_DisplayManager_removeDisplay : Error processing arguments"); cobj->removeDisplay(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2819,18 +3229,18 @@ bool js_cocos2dx_studio_DisplayManager_removeDisplay(JSContext *cx, uint32_t arg } bool js_cocos2dx_studio_DisplayManager_setForceChangeDisplay(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_setForceChangeDisplay : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_DisplayManager_setForceChangeDisplay : Error processing arguments"); cobj->setForceChangeDisplay(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2839,18 +3249,18 @@ bool js_cocos2dx_studio_DisplayManager_setForceChangeDisplay(JSContext *cx, uint } bool js_cocos2dx_studio_DisplayManager_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_init : Invalid Native Object"); if (argc == 1) { cocostudio::Bone* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -2859,7 +3269,7 @@ bool js_cocos2dx_studio_DisplayManager_init(JSContext *cx, uint32_t argc, jsval bool ret = cobj->init(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2868,7 +3278,8 @@ bool js_cocos2dx_studio_DisplayManager_init(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_DisplayManager_getContentSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_getContentSize : Invalid Native Object"); @@ -2876,7 +3287,7 @@ bool js_cocos2dx_studio_DisplayManager_getContentSize(JSContext *cx, uint32_t ar cocos2d::Size ret = cobj->getContentSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2885,7 +3296,8 @@ bool js_cocos2dx_studio_DisplayManager_getContentSize(JSContext *cx, uint32_t ar } bool js_cocos2dx_studio_DisplayManager_getBoundingBox(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_getBoundingBox : Invalid Native Object"); @@ -2893,7 +3305,7 @@ bool js_cocos2dx_studio_DisplayManager_getBoundingBox(JSContext *cx, uint32_t ar cocos2d::Rect ret = cobj->getBoundingBox(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2902,12 +3314,12 @@ bool js_cocos2dx_studio_DisplayManager_getBoundingBox(JSContext *cx, uint32_t ar } bool js_cocos2dx_studio_DisplayManager_addDisplay(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocostudio::DisplayManager* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_addDisplay : Invalid Native Object"); @@ -2915,19 +3327,19 @@ bool js_cocos2dx_studio_DisplayManager_addDisplay(JSContext *cx, uint32_t argc, if (argc == 2) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cobj->addDisplay(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -2936,19 +3348,19 @@ bool js_cocos2dx_studio_DisplayManager_addDisplay(JSContext *cx, uint32_t argc, if (argc == 2) { cocostudio::DisplayData* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::DisplayData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cobj->addDisplay(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -2958,27 +3370,27 @@ bool js_cocos2dx_studio_DisplayManager_addDisplay(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_DisplayManager_containPoint(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocostudio::DisplayManager* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_containPoint : Invalid Native Object"); do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } bool ret = cobj->containPoint(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -2986,12 +3398,12 @@ bool js_cocos2dx_studio_DisplayManager_containPoint(JSContext *cx, uint32_t argc do { if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } bool ret = cobj->containPoint(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -3001,25 +3413,25 @@ bool js_cocos2dx_studio_DisplayManager_containPoint(JSContext *cx, uint32_t argc } bool js_cocos2dx_studio_DisplayManager_initDisplayList(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_initDisplayList : Invalid Native Object"); if (argc == 1) { cocostudio::BoneData* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::BoneData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_DisplayManager_initDisplayList : Error processing arguments"); cobj->initDisplayList(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3028,20 +3440,20 @@ bool js_cocos2dx_studio_DisplayManager_initDisplayList(JSContext *cx, uint32_t a } bool js_cocos2dx_studio_DisplayManager_changeDisplayWithIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_changeDisplayWithIndex : Invalid Native Object"); if (argc == 2) { int arg0; bool arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_DisplayManager_changeDisplayWithIndex : Error processing arguments"); cobj->changeDisplayWithIndex(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3050,20 +3462,20 @@ bool js_cocos2dx_studio_DisplayManager_changeDisplayWithIndex(JSContext *cx, uin } bool js_cocos2dx_studio_DisplayManager_changeDisplayWithName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_changeDisplayWithName : Invalid Native Object"); if (argc == 2) { std::string arg0; bool arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_DisplayManager_changeDisplayWithName : Error processing arguments"); cobj->changeDisplayWithName(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3072,7 +3484,8 @@ bool js_cocos2dx_studio_DisplayManager_changeDisplayWithName(JSContext *cx, uint } bool js_cocos2dx_studio_DisplayManager_isForceChangeDisplay(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_isForceChangeDisplay : Invalid Native Object"); @@ -3080,7 +3493,7 @@ bool js_cocos2dx_studio_DisplayManager_isForceChangeDisplay(JSContext *cx, uint3 bool ret = cobj->isForceChangeDisplay(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3089,15 +3502,15 @@ bool js_cocos2dx_studio_DisplayManager_isForceChangeDisplay(JSContext *cx, uint3 } bool js_cocos2dx_studio_DisplayManager_getDecorativeDisplayByIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_getDecorativeDisplayByIndex : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_DisplayManager_getDecorativeDisplayByIndex : Error processing arguments"); cocostudio::DecorativeDisplay* ret = cobj->getDecorativeDisplayByIndex(arg0); jsval jsret = JSVAL_NULL; @@ -3109,7 +3522,7 @@ bool js_cocos2dx_studio_DisplayManager_getDecorativeDisplayByIndex(JSContext *cx jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3118,7 +3531,8 @@ bool js_cocos2dx_studio_DisplayManager_getDecorativeDisplayByIndex(JSContext *cx } bool js_cocos2dx_studio_DisplayManager_getCurrentDisplayIndex(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_getCurrentDisplayIndex : Invalid Native Object"); @@ -3126,7 +3540,7 @@ bool js_cocos2dx_studio_DisplayManager_getCurrentDisplayIndex(JSContext *cx, uin int ret = cobj->getCurrentDisplayIndex(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3135,7 +3549,8 @@ bool js_cocos2dx_studio_DisplayManager_getCurrentDisplayIndex(JSContext *cx, uin } bool js_cocos2dx_studio_DisplayManager_getAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_getAnchorPoint : Invalid Native Object"); @@ -3143,7 +3558,7 @@ bool js_cocos2dx_studio_DisplayManager_getAnchorPoint(JSContext *cx, uint32_t ar cocos2d::Vec2 ret = cobj->getAnchorPoint(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3152,7 +3567,8 @@ bool js_cocos2dx_studio_DisplayManager_getAnchorPoint(JSContext *cx, uint32_t ar } bool js_cocos2dx_studio_DisplayManager_getDecorativeDisplayList(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_getDecorativeDisplayList : Invalid Native Object"); @@ -3160,7 +3576,7 @@ bool js_cocos2dx_studio_DisplayManager_getDecorativeDisplayList(JSContext *cx, u const cocos2d::Vector& ret = cobj->getDecorativeDisplayList(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3169,7 +3585,8 @@ bool js_cocos2dx_studio_DisplayManager_getDecorativeDisplayList(JSContext *cx, u } bool js_cocos2dx_studio_DisplayManager_isVisible(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_isVisible : Invalid Native Object"); @@ -3177,7 +3594,7 @@ bool js_cocos2dx_studio_DisplayManager_isVisible(JSContext *cx, uint32_t argc, j bool ret = cobj->isVisible(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3186,18 +3603,18 @@ bool js_cocos2dx_studio_DisplayManager_isVisible(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_studio_DisplayManager_setVisible(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::DisplayManager* cobj = (cocostudio::DisplayManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_DisplayManager_setVisible : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_DisplayManager_setVisible : Error processing arguments"); cobj->setVisible(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3206,14 +3623,14 @@ bool js_cocos2dx_studio_DisplayManager_setVisible(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_DisplayManager_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocostudio::Bone* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -3229,7 +3646,7 @@ bool js_cocos2dx_studio_DisplayManager_create(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_DisplayManager_create : wrong number of arguments"); @@ -3238,7 +3655,7 @@ bool js_cocos2dx_studio_DisplayManager_create(JSContext *cx, uint32_t argc, jsva bool js_cocos2dx_studio_DisplayManager_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::DisplayManager* cobj = new (std::nothrow) cocostudio::DisplayManager(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -3252,13 +3669,16 @@ bool js_cocos2dx_studio_DisplayManager_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::DisplayManager"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::DisplayManager"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -3268,7 +3688,7 @@ void js_cocostudio_DisplayManager_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (DisplayManager)", obj); } -void js_register_cocos2dx_studio_DisplayManager(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_DisplayManager(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_DisplayManager_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_DisplayManager_class->name = "DisplayManager"; jsb_cocostudio_DisplayManager_class->addProperty = JS_PropertyStub; @@ -3282,8 +3702,8 @@ void js_register_cocos2dx_studio_DisplayManager(JSContext *cx, JSObject *global) jsb_cocostudio_DisplayManager_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -3319,7 +3739,7 @@ void js_register_cocos2dx_studio_DisplayManager(JSContext *cx, JSObject *global) jsb_cocostudio_DisplayManager_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_DisplayManager_class, js_cocos2dx_studio_DisplayManager_constructor, 0, // constructor properties, @@ -3350,7 +3770,8 @@ JSObject *jsb_cocostudio_Bone_prototype; bool js_cocos2dx_studio_Bone_isTransformDirty(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_isTransformDirty : Invalid Native Object"); @@ -3358,7 +3779,7 @@ bool js_cocos2dx_studio_Bone_isTransformDirty(JSContext *cx, uint32_t argc, jsva bool ret = cobj->isTransformDirty(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3367,18 +3788,18 @@ bool js_cocos2dx_studio_Bone_isTransformDirty(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_Bone_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_setBlendFunc : Invalid Native Object"); if (argc == 1) { cocos2d::BlendFunc arg0; - ok &= jsval_to_blendfunc(cx, argv[0], &arg0); + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_setBlendFunc : Error processing arguments"); cobj->setBlendFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3387,7 +3808,8 @@ bool js_cocos2dx_studio_Bone_setBlendFunc(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_Bone_isIgnoreMovementBoneData(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_isIgnoreMovementBoneData : Invalid Native Object"); @@ -3395,7 +3817,7 @@ bool js_cocos2dx_studio_Bone_isIgnoreMovementBoneData(JSContext *cx, uint32_t ar bool ret = cobj->isIgnoreMovementBoneData(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3404,13 +3826,14 @@ bool js_cocos2dx_studio_Bone_isIgnoreMovementBoneData(JSContext *cx, uint32_t ar } bool js_cocos2dx_studio_Bone_updateZOrder(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_updateZOrder : Invalid Native Object"); if (argc == 0) { cobj->updateZOrder(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3419,7 +3842,8 @@ bool js_cocos2dx_studio_Bone_updateZOrder(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_Bone_getDisplayRenderNode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_getDisplayRenderNode : Invalid Native Object"); @@ -3434,7 +3858,7 @@ bool js_cocos2dx_studio_Bone_getDisplayRenderNode(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3443,7 +3867,8 @@ bool js_cocos2dx_studio_Bone_getDisplayRenderNode(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_Bone_isBlendDirty(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_isBlendDirty : Invalid Native Object"); @@ -3451,7 +3876,7 @@ bool js_cocos2dx_studio_Bone_isBlendDirty(JSContext *cx, uint32_t argc, jsval *v bool ret = cobj->isBlendDirty(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3460,25 +3885,25 @@ bool js_cocos2dx_studio_Bone_isBlendDirty(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_Bone_addChildBone(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_addChildBone : Invalid Native Object"); if (argc == 1) { cocostudio::Bone* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_addChildBone : Error processing arguments"); cobj->addChildBone(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3487,7 +3912,8 @@ bool js_cocos2dx_studio_Bone_addChildBone(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_Bone_getWorldInfo(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_getWorldInfo : Invalid Native Object"); @@ -3502,7 +3928,7 @@ bool js_cocos2dx_studio_Bone_getWorldInfo(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3511,7 +3937,8 @@ bool js_cocos2dx_studio_Bone_getWorldInfo(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_Bone_getTween(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_getTween : Invalid Native Object"); @@ -3526,7 +3953,7 @@ bool js_cocos2dx_studio_Bone_getTween(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3535,7 +3962,8 @@ bool js_cocos2dx_studio_Bone_getTween(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Bone_getParentBone(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_getParentBone : Invalid Native Object"); @@ -3550,7 +3978,7 @@ bool js_cocos2dx_studio_Bone_getParentBone(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3559,13 +3987,14 @@ bool js_cocos2dx_studio_Bone_getParentBone(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_Bone_updateColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_updateColor : Invalid Native Object"); if (argc == 0) { cobj->updateColor(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3574,18 +4003,18 @@ bool js_cocos2dx_studio_Bone_updateColor(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_studio_Bone_setTransformDirty(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_setTransformDirty : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_setTransformDirty : Error processing arguments"); cobj->setTransformDirty(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3594,7 +4023,8 @@ bool js_cocos2dx_studio_Bone_setTransformDirty(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_studio_Bone_getDisplayRenderNodeType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_getDisplayRenderNodeType : Invalid Native Object"); @@ -3602,7 +4032,7 @@ bool js_cocos2dx_studio_Bone_getDisplayRenderNodeType(JSContext *cx, uint32_t ar int ret = (int)cobj->getDisplayRenderNodeType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3611,18 +4041,18 @@ bool js_cocos2dx_studio_Bone_getDisplayRenderNodeType(JSContext *cx, uint32_t ar } bool js_cocos2dx_studio_Bone_removeDisplay(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_removeDisplay : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_removeDisplay : Error processing arguments"); cobj->removeDisplay(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3631,25 +4061,25 @@ bool js_cocos2dx_studio_Bone_removeDisplay(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_Bone_setBoneData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_setBoneData : Invalid Native Object"); if (argc == 1) { cocostudio::BoneData* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::BoneData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_setBoneData : Error processing arguments"); cobj->setBoneData(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3658,20 +4088,20 @@ bool js_cocos2dx_studio_Bone_setBoneData(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_studio_Bone_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_init : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_init : Error processing arguments"); bool ret = cobj->init(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3680,25 +4110,25 @@ bool js_cocos2dx_studio_Bone_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Bone_setParentBone(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_setParentBone : Invalid Native Object"); if (argc == 1) { cocostudio::Bone* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_setParentBone : Error processing arguments"); cobj->setParentBone(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3707,12 +4137,12 @@ bool js_cocos2dx_studio_Bone_setParentBone(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_Bone_addDisplay(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocostudio::Bone* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_addDisplay : Invalid Native Object"); @@ -3720,19 +4150,19 @@ bool js_cocos2dx_studio_Bone_addDisplay(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 2) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cobj->addDisplay(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -3741,19 +4171,19 @@ bool js_cocos2dx_studio_Bone_addDisplay(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 2) { cocostudio::DisplayData* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::DisplayData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cobj->addDisplay(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -3763,18 +4193,18 @@ bool js_cocos2dx_studio_Bone_addDisplay(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Bone_setIgnoreMovementBoneData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_setIgnoreMovementBoneData : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_setIgnoreMovementBoneData : Error processing arguments"); cobj->setIgnoreMovementBoneData(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3783,7 +4213,8 @@ bool js_cocos2dx_studio_Bone_setIgnoreMovementBoneData(JSContext *cx, uint32_t a } bool js_cocos2dx_studio_Bone_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_getBlendFunc : Invalid Native Object"); @@ -3791,7 +4222,7 @@ bool js_cocos2dx_studio_Bone_getBlendFunc(JSContext *cx, uint32_t argc, jsval *v cocos2d::BlendFunc ret = cobj->getBlendFunc(); jsval jsret = JSVAL_NULL; jsret = blendfunc_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3800,18 +4231,18 @@ bool js_cocos2dx_studio_Bone_getBlendFunc(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_Bone_removeFromParent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_removeFromParent : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_removeFromParent : Error processing arguments"); cobj->removeFromParent(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3820,7 +4251,8 @@ bool js_cocos2dx_studio_Bone_removeFromParent(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_Bone_getColliderDetector(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_getColliderDetector : Invalid Native Object"); @@ -3835,7 +4267,7 @@ bool js_cocos2dx_studio_Bone_getColliderDetector(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3844,7 +4276,8 @@ bool js_cocos2dx_studio_Bone_getColliderDetector(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_studio_Bone_getChildArmature(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_getChildArmature : Invalid Native Object"); @@ -3859,7 +4292,7 @@ bool js_cocos2dx_studio_Bone_getChildArmature(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3868,20 +4301,20 @@ bool js_cocos2dx_studio_Bone_getChildArmature(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_Bone_changeDisplayWithIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_changeDisplayWithIndex : Invalid Native Object"); if (argc == 2) { int arg0; bool arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_changeDisplayWithIndex : Error processing arguments"); cobj->changeDisplayWithIndex(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3890,20 +4323,20 @@ bool js_cocos2dx_studio_Bone_changeDisplayWithIndex(JSContext *cx, uint32_t argc } bool js_cocos2dx_studio_Bone_changeDisplayWithName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_changeDisplayWithName : Invalid Native Object"); if (argc == 2) { std::string arg0; bool arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_changeDisplayWithName : Error processing arguments"); cobj->changeDisplayWithName(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3912,25 +4345,25 @@ bool js_cocos2dx_studio_Bone_changeDisplayWithName(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_Bone_setArmature(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_setArmature : Invalid Native Object"); if (argc == 1) { cocostudio::Armature* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Armature*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_setArmature : Error processing arguments"); cobj->setArmature(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3939,18 +4372,18 @@ bool js_cocos2dx_studio_Bone_setArmature(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_studio_Bone_setBlendDirty(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_setBlendDirty : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_setBlendDirty : Error processing arguments"); cobj->setBlendDirty(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3959,9 +4392,9 @@ bool js_cocos2dx_studio_Bone_setBlendDirty(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_Bone_removeChildBone(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_removeChildBone : Invalid Native Object"); @@ -3969,17 +4402,17 @@ bool js_cocos2dx_studio_Bone_removeChildBone(JSContext *cx, uint32_t argc, jsval cocostudio::Bone* arg0; bool arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_removeChildBone : Error processing arguments"); cobj->removeChildBone(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3988,25 +4421,25 @@ bool js_cocos2dx_studio_Bone_removeChildBone(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_Bone_setChildArmature(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_setChildArmature : Invalid Native Object"); if (argc == 1) { cocostudio::Armature* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Armature*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Bone_setChildArmature : Error processing arguments"); cobj->setChildArmature(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4015,7 +4448,8 @@ bool js_cocos2dx_studio_Bone_setChildArmature(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_Bone_getNodeToArmatureTransform(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_getNodeToArmatureTransform : Invalid Native Object"); @@ -4023,7 +4457,7 @@ bool js_cocos2dx_studio_Bone_getNodeToArmatureTransform(JSContext *cx, uint32_t cocos2d::Mat4 ret = cobj->getNodeToArmatureTransform(); jsval jsret = JSVAL_NULL; jsret = matrix_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4032,7 +4466,8 @@ bool js_cocos2dx_studio_Bone_getNodeToArmatureTransform(JSContext *cx, uint32_t } bool js_cocos2dx_studio_Bone_getDisplayManager(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_getDisplayManager : Invalid Native Object"); @@ -4047,7 +4482,7 @@ bool js_cocos2dx_studio_Bone_getDisplayManager(JSContext *cx, uint32_t argc, jsv jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4056,7 +4491,8 @@ bool js_cocos2dx_studio_Bone_getDisplayManager(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_studio_Bone_getArmature(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Bone* cobj = (cocostudio::Bone *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Bone_getArmature : Invalid Native Object"); @@ -4071,7 +4507,7 @@ bool js_cocos2dx_studio_Bone_getArmature(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4080,13 +4516,13 @@ bool js_cocos2dx_studio_Bone_getArmature(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_studio_Bone_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocostudio::Bone* ret = cocostudio::Bone::create(arg0); jsval jsret = JSVAL_NULL; @@ -4098,7 +4534,7 @@ bool js_cocos2dx_studio_Bone_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -4115,7 +4551,7 @@ bool js_cocos2dx_studio_Bone_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -4124,7 +4560,7 @@ bool js_cocos2dx_studio_Bone_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Bone_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::Bone* cobj = new (std::nothrow) cocostudio::Bone(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -4138,13 +4574,16 @@ bool js_cocos2dx_studio_Bone_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::Bone"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::Bone"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -4155,7 +4594,7 @@ void js_cocostudio_Bone_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Bone)", obj); } -void js_register_cocos2dx_studio_Bone(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_Bone(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_Bone_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_Bone_class->name = "Bone"; jsb_cocostudio_Bone_class->addProperty = JS_PropertyStub; @@ -4169,8 +4608,8 @@ void js_register_cocos2dx_studio_Bone(JSContext *cx, JSObject *global) { jsb_cocostudio_Bone_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -4216,7 +4655,7 @@ void js_register_cocos2dx_studio_Bone(JSContext *cx, JSObject *global) { jsb_cocostudio_Bone_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocostudio_Bone_class, js_cocos2dx_studio_Bone_constructor, 0, // constructor properties, @@ -4247,6 +4686,7 @@ JSObject *jsb_cocostudio_BatchNode_prototype; bool js_cocos2dx_studio_BatchNode_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::BatchNode* ret = cocostudio::BatchNode::create(); jsval jsret = JSVAL_NULL; @@ -4258,7 +4698,7 @@ bool js_cocos2dx_studio_BatchNode_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_BatchNode_create : wrong number of arguments"); @@ -4272,7 +4712,7 @@ void js_cocostudio_BatchNode_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (BatchNode)", obj); } -void js_register_cocos2dx_studio_BatchNode(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_BatchNode(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_BatchNode_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_BatchNode_class->name = "BatchNode"; jsb_cocostudio_BatchNode_class->addProperty = JS_PropertyStub; @@ -4286,8 +4726,8 @@ void js_register_cocos2dx_studio_BatchNode(JSContext *cx, JSObject *global) { jsb_cocostudio_BatchNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -4301,7 +4741,7 @@ void js_register_cocos2dx_studio_BatchNode(JSContext *cx, JSObject *global) { jsb_cocostudio_BatchNode_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocostudio_BatchNode_class, empty_constructor, 0, properties, @@ -4332,7 +4772,8 @@ JSObject *jsb_cocostudio_ArmatureAnimation_prototype; bool js_cocos2dx_studio_ArmatureAnimation_getSpeedScale(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_getSpeedScale : Invalid Native Object"); @@ -4340,234 +4781,168 @@ bool js_cocos2dx_studio_ArmatureAnimation_getSpeedScale(JSContext *cx, uint32_t double ret = cobj->getSpeedScale(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_getSpeedScale : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_studio_ArmatureAnimation_pause(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ArmatureAnimation_play(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_pause : Invalid Native Object"); - if (argc == 0) { - cobj->pause(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_play : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_play : Error processing arguments"); + cobj->play(arg0); + args.rval().setUndefined(); + return true; + } + if (argc == 2) { + std::string arg0; + int arg1; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_play : Error processing arguments"); + cobj->play(arg0, arg1); + args.rval().setUndefined(); + return true; + } + if (argc == 3) { + std::string arg0; + int arg1; + int arg2; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_play : Error processing arguments"); + cobj->play(arg0, arg1, arg2); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_pause : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_play : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_studio_ArmatureAnimation_setSpeedScale(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ArmatureAnimation_gotoAndPause(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_setSpeedScale : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_gotoAndPause : Invalid Native Object"); if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_setSpeedScale : Error processing arguments"); - cobj->setSpeedScale(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_gotoAndPause : Error processing arguments"); + cobj->gotoAndPause(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_setSpeedScale : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_gotoAndPause : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_studio_ArmatureAnimation_init(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ArmatureAnimation_playWithIndexes(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_init : Invalid Native Object"); - if (argc == 1) { - cocostudio::Armature* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocostudio::Armature*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_init : Error processing arguments"); - bool ret = cobj->init(arg0); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_init : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_ArmatureAnimation_playWithIndexes(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithIndexes : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithIndexes : Invalid Native Object"); if (argc == 1) { std::vector arg0; - ok &= jsval_to_std_vector_int(cx, argv[0], &arg0); + ok &= jsval_to_std_vector_int(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithIndexes : Error processing arguments"); cobj->playWithIndexes(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::vector arg0; int arg1; - ok &= jsval_to_std_vector_int(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_vector_int(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithIndexes : Error processing arguments"); cobj->playWithIndexes(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 3) { std::vector arg0; int arg1; bool arg2; - ok &= jsval_to_std_vector_int(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + ok &= jsval_to_std_vector_int(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + arg2 = JS::ToBoolean(args.get(2)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithIndexes : Error processing arguments"); cobj->playWithIndexes(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_playWithIndexes : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_studio_ArmatureAnimation_play(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_play : Invalid Native Object"); - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_play : Error processing arguments"); - cobj->play(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - if (argc == 2) { - std::string arg0; - int arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_play : Error processing arguments"); - cobj->play(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - if (argc == 3) { - std::string arg0; - int arg1; - int arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_play : Error processing arguments"); - cobj->play(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_play : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_ArmatureAnimation_gotoAndPause(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ArmatureAnimation_setAnimationData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_gotoAndPause : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_setAnimationData : Invalid Native Object"); if (argc == 1) { - int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_gotoAndPause : Error processing arguments"); - cobj->gotoAndPause(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_gotoAndPause : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_ArmatureAnimation_resume(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_resume : Invalid Native Object"); - if (argc == 0) { - cobj->resume(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_resume : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} -bool js_cocos2dx_studio_ArmatureAnimation_stop(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_stop : Invalid Native Object"); - if (argc == 0) { - cobj->stop(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocostudio::AnimationData* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocostudio::AnimationData*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_setAnimationData : Error processing arguments"); + cobj->setAnimationData(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_stop : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_setAnimationData : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_studio_ArmatureAnimation_update(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ArmatureAnimation_setSpeedScale(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_update : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_setSpeedScale : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_update : Error processing arguments"); - cobj->update(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_setSpeedScale : Error processing arguments"); + cobj->setSpeedScale(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_update : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_setSpeedScale : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_studio_ArmatureAnimation_getAnimationData(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_getAnimationData : Invalid Native Object"); @@ -4582,155 +4957,98 @@ bool js_cocos2dx_studio_ArmatureAnimation_getAnimationData(JSContext *cx, uint32 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_getAnimationData : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_studio_ArmatureAnimation_playWithIndex(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ArmatureAnimation_gotoAndPlay(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithIndex : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_gotoAndPlay : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithIndex : Error processing arguments"); - cobj->playWithIndex(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - if (argc == 2) { - int arg0; - int arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithIndex : Error processing arguments"); - cobj->playWithIndex(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - if (argc == 3) { - int arg0; - int arg1; - int arg2; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithIndex : Error processing arguments"); - cobj->playWithIndex(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_playWithIndex : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_ArmatureAnimation_getCurrentMovementID(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_getCurrentMovementID : Invalid Native Object"); - if (argc == 0) { - std::string ret = cobj->getCurrentMovementID(); - jsval jsret = JSVAL_NULL; - jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_gotoAndPlay : Error processing arguments"); + cobj->gotoAndPlay(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_getCurrentMovementID : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_gotoAndPlay : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_studio_ArmatureAnimation_setAnimationData(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ArmatureAnimation_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_setAnimationData : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_init : Invalid Native Object"); if (argc == 1) { - cocostudio::AnimationData* arg0; + cocostudio::Armature* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocostudio::AnimationData*)(jsProxy ? jsProxy->ptr : NULL); + arg0 = (cocostudio::Armature*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_setAnimationData : Error processing arguments"); - cobj->setAnimationData(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_setAnimationData : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_ArmatureAnimation_gotoAndPlay(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_gotoAndPlay : Invalid Native Object"); - if (argc == 1) { - int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_gotoAndPlay : Error processing arguments"); - cobj->gotoAndPlay(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_init : Error processing arguments"); + bool ret = cobj->init(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_gotoAndPlay : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_init : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_studio_ArmatureAnimation_playWithNames(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithNames : Invalid Native Object"); if (argc == 1) { std::vector arg0; - ok &= jsval_to_std_vector_string(cx, argv[0], &arg0); + ok &= jsval_to_std_vector_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithNames : Error processing arguments"); cobj->playWithNames(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::vector arg0; int arg1; - ok &= jsval_to_std_vector_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_vector_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithNames : Error processing arguments"); cobj->playWithNames(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 3) { std::vector arg0; int arg1; bool arg2; - ok &= jsval_to_std_vector_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + ok &= jsval_to_std_vector_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + arg2 = JS::ToBoolean(args.get(2)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithNames : Error processing arguments"); cobj->playWithNames(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4739,7 +5057,8 @@ bool js_cocos2dx_studio_ArmatureAnimation_playWithNames(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ArmatureAnimation_getMovementCount(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_getMovementCount : Invalid Native Object"); @@ -4747,23 +5066,83 @@ bool js_cocos2dx_studio_ArmatureAnimation_getMovementCount(JSContext *cx, uint32 ssize_t ret = cobj->getMovementCount(); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_getMovementCount : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_studio_ArmatureAnimation_playWithIndex(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithIndex : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithIndex : Error processing arguments"); + cobj->playWithIndex(arg0); + args.rval().setUndefined(); + return true; + } + if (argc == 2) { + int arg0; + int arg1; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithIndex : Error processing arguments"); + cobj->playWithIndex(arg0, arg1); + args.rval().setUndefined(); + return true; + } + if (argc == 3) { + int arg0; + int arg1; + int arg2; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureAnimation_playWithIndex : Error processing arguments"); + cobj->playWithIndex(arg0, arg1, arg2); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_playWithIndex : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_studio_ArmatureAnimation_getCurrentMovementID(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_getCurrentMovementID : Invalid Native Object"); + if (argc == 0) { + std::string ret = cobj->getCurrentMovementID(); + jsval jsret = JSVAL_NULL; + jsret = std_string_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_getCurrentMovementID : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_studio_ArmatureAnimation_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocostudio::Armature* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Armature*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -4779,7 +5158,7 @@ bool js_cocos2dx_studio_ArmatureAnimation_create(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ArmatureAnimation_create : wrong number of arguments"); @@ -4788,7 +5167,7 @@ bool js_cocos2dx_studio_ArmatureAnimation_create(JSContext *cx, uint32_t argc, j bool js_cocos2dx_studio_ArmatureAnimation_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::ArmatureAnimation* cobj = new (std::nothrow) cocostudio::ArmatureAnimation(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -4802,13 +5181,16 @@ bool js_cocos2dx_studio_ArmatureAnimation_constructor(JSContext *cx, uint32_t ar CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::ArmatureAnimation"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ArmatureAnimation"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -4819,7 +5201,7 @@ void js_cocostudio_ArmatureAnimation_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ArmatureAnimation)", obj); } -void js_register_cocos2dx_studio_ArmatureAnimation(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ArmatureAnimation(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_ArmatureAnimation_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_ArmatureAnimation_class->name = "ArmatureAnimation"; jsb_cocostudio_ArmatureAnimation_class->addProperty = JS_PropertyStub; @@ -4833,28 +5215,24 @@ void js_register_cocos2dx_studio_ArmatureAnimation(JSContext *cx, JSObject *glob jsb_cocostudio_ArmatureAnimation_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getSpeedScale", js_cocos2dx_studio_ArmatureAnimation_getSpeedScale, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("pause", js_cocos2dx_studio_ArmatureAnimation_pause, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setSpeedScale", js_cocos2dx_studio_ArmatureAnimation_setSpeedScale, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_studio_ArmatureAnimation_init, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("playWithIndexes", js_cocos2dx_studio_ArmatureAnimation_playWithIndexes, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("play", js_cocos2dx_studio_ArmatureAnimation_play, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("gotoAndPause", js_cocos2dx_studio_ArmatureAnimation_gotoAndPause, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("resume", js_cocos2dx_studio_ArmatureAnimation_resume, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("stop", js_cocos2dx_studio_ArmatureAnimation_stop, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("update", js_cocos2dx_studio_ArmatureAnimation_update, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getAnimationData", js_cocos2dx_studio_ArmatureAnimation_getAnimationData, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("playWithIndex", js_cocos2dx_studio_ArmatureAnimation_playWithIndex, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getCurrentMovementID", js_cocos2dx_studio_ArmatureAnimation_getCurrentMovementID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("playWithIndexes", js_cocos2dx_studio_ArmatureAnimation_playWithIndexes, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setAnimationData", js_cocos2dx_studio_ArmatureAnimation_setAnimationData, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setSpeedScale", js_cocos2dx_studio_ArmatureAnimation_setSpeedScale, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getAnimationData", js_cocos2dx_studio_ArmatureAnimation_getAnimationData, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("gotoAndPlay", js_cocos2dx_studio_ArmatureAnimation_gotoAndPlay, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("init", js_cocos2dx_studio_ArmatureAnimation_init, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("playWithNames", js_cocos2dx_studio_ArmatureAnimation_playWithNames, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getMovementCount", js_cocos2dx_studio_ArmatureAnimation_getMovementCount, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("playWithIndex", js_cocos2dx_studio_ArmatureAnimation_playWithIndex, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getCurrentMovementID", js_cocos2dx_studio_ArmatureAnimation_getCurrentMovementID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -4865,7 +5243,7 @@ void js_register_cocos2dx_studio_ArmatureAnimation(JSContext *cx, JSObject *glob jsb_cocostudio_ArmatureAnimation_prototype = JS_InitClass( cx, global, - jsb_cocostudio_ProcessBase_prototype, + JS::RootedObject(cx, jsb_cocostudio_ProcessBase_prototype), jsb_cocostudio_ArmatureAnimation_class, js_cocos2dx_studio_ArmatureAnimation_constructor, 0, // constructor properties, @@ -4896,7 +5274,8 @@ JSObject *jsb_cocostudio_ArmatureDataManager_prototype; bool js_cocos2dx_studio_ArmatureDataManager_getAnimationDatas(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_getAnimationDatas : Invalid Native Object"); @@ -4904,7 +5283,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_getAnimationDatas(JSContext *cx, uin const cocos2d::Map& ret = cobj->getAnimationDatas(); jsval jsret = JSVAL_NULL; jsret = ccmap_string_key_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4913,18 +5292,18 @@ bool js_cocos2dx_studio_ArmatureDataManager_getAnimationDatas(JSContext *cx, uin } bool js_cocos2dx_studio_ArmatureDataManager_removeAnimationData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_removeAnimationData : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_removeAnimationData : Error processing arguments"); cobj->removeAnimationData(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4933,46 +5312,46 @@ bool js_cocos2dx_studio_ArmatureDataManager_removeAnimationData(JSContext *cx, u } bool js_cocos2dx_studio_ArmatureDataManager_addArmatureData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_addArmatureData : Invalid Native Object"); if (argc == 2) { std::string arg0; cocostudio::ArmatureData* arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocostudio::ArmatureData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_addArmatureData : Error processing arguments"); cobj->addArmatureData(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 3) { std::string arg0; cocostudio::ArmatureData* arg1; std::string arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocostudio::ArmatureData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_addArmatureData : Error processing arguments"); cobj->addArmatureData(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4981,28 +5360,28 @@ bool js_cocos2dx_studio_ArmatureDataManager_addArmatureData(JSContext *cx, uint3 } bool js_cocos2dx_studio_ArmatureDataManager_addArmatureFileInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocostudio::ArmatureDataManager* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_addArmatureFileInfo : Invalid Native Object"); do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } std::string arg2; - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } cobj->addArmatureFileInfo(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -5010,10 +5389,10 @@ bool js_cocos2dx_studio_ArmatureDataManager_addArmatureFileInfo(JSContext *cx, u do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cobj->addArmatureFileInfo(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -5023,18 +5402,18 @@ bool js_cocos2dx_studio_ArmatureDataManager_addArmatureFileInfo(JSContext *cx, u } bool js_cocos2dx_studio_ArmatureDataManager_removeArmatureFileInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_removeArmatureFileInfo : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_removeArmatureFileInfo : Error processing arguments"); cobj->removeArmatureFileInfo(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5043,15 +5422,15 @@ bool js_cocos2dx_studio_ArmatureDataManager_removeArmatureFileInfo(JSContext *cx } bool js_cocos2dx_studio_ArmatureDataManager_getTextureData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_getTextureData : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_getTextureData : Error processing arguments"); cocostudio::TextureData* ret = cobj->getTextureData(arg0); jsval jsret = JSVAL_NULL; @@ -5063,7 +5442,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_getTextureData(JSContext *cx, uint32 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5072,15 +5451,15 @@ bool js_cocos2dx_studio_ArmatureDataManager_getTextureData(JSContext *cx, uint32 } bool js_cocos2dx_studio_ArmatureDataManager_getArmatureData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_getArmatureData : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_getArmatureData : Error processing arguments"); cocostudio::ArmatureData* ret = cobj->getArmatureData(arg0); jsval jsret = JSVAL_NULL; @@ -5092,7 +5471,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_getArmatureData(JSContext *cx, uint3 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5101,15 +5480,15 @@ bool js_cocos2dx_studio_ArmatureDataManager_getArmatureData(JSContext *cx, uint3 } bool js_cocos2dx_studio_ArmatureDataManager_getAnimationData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_getAnimationData : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_getAnimationData : Error processing arguments"); cocostudio::AnimationData* ret = cobj->getAnimationData(arg0); jsval jsret = JSVAL_NULL; @@ -5121,7 +5500,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_getAnimationData(JSContext *cx, uint jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5130,46 +5509,46 @@ bool js_cocos2dx_studio_ArmatureDataManager_getAnimationData(JSContext *cx, uint } bool js_cocos2dx_studio_ArmatureDataManager_addAnimationData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_addAnimationData : Invalid Native Object"); if (argc == 2) { std::string arg0; cocostudio::AnimationData* arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocostudio::AnimationData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_addAnimationData : Error processing arguments"); cobj->addAnimationData(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 3) { std::string arg0; cocostudio::AnimationData* arg1; std::string arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocostudio::AnimationData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_addAnimationData : Error processing arguments"); cobj->addAnimationData(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5178,7 +5557,8 @@ bool js_cocos2dx_studio_ArmatureDataManager_addAnimationData(JSContext *cx, uint } bool js_cocos2dx_studio_ArmatureDataManager_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_init : Invalid Native Object"); @@ -5186,7 +5566,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_init(JSContext *cx, uint32_t argc, j bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5195,18 +5575,18 @@ bool js_cocos2dx_studio_ArmatureDataManager_init(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_studio_ArmatureDataManager_removeArmatureData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_removeArmatureData : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_removeArmatureData : Error processing arguments"); cobj->removeArmatureData(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5215,7 +5595,8 @@ bool js_cocos2dx_studio_ArmatureDataManager_removeArmatureData(JSContext *cx, ui } bool js_cocos2dx_studio_ArmatureDataManager_getArmatureDatas(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_getArmatureDatas : Invalid Native Object"); @@ -5223,7 +5604,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_getArmatureDatas(JSContext *cx, uint const cocos2d::Map& ret = cobj->getArmatureDatas(); jsval jsret = JSVAL_NULL; jsret = ccmap_string_key_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5232,18 +5613,18 @@ bool js_cocos2dx_studio_ArmatureDataManager_getArmatureDatas(JSContext *cx, uint } bool js_cocos2dx_studio_ArmatureDataManager_removeTextureData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_removeTextureData : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_removeTextureData : Error processing arguments"); cobj->removeTextureData(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5252,46 +5633,46 @@ bool js_cocos2dx_studio_ArmatureDataManager_removeTextureData(JSContext *cx, uin } bool js_cocos2dx_studio_ArmatureDataManager_addTextureData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_addTextureData : Invalid Native Object"); if (argc == 2) { std::string arg0; cocostudio::TextureData* arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocostudio::TextureData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_addTextureData : Error processing arguments"); cobj->addTextureData(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 3) { std::string arg0; cocostudio::TextureData* arg1; std::string arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocostudio::TextureData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_addTextureData : Error processing arguments"); cobj->addTextureData(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5300,7 +5681,8 @@ bool js_cocos2dx_studio_ArmatureDataManager_addTextureData(JSContext *cx, uint32 } bool js_cocos2dx_studio_ArmatureDataManager_isAutoLoadSpriteFile(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_isAutoLoadSpriteFile : Invalid Native Object"); @@ -5308,7 +5690,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_isAutoLoadSpriteFile(JSContext *cx, bool ret = cobj->isAutoLoadSpriteFile(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5317,32 +5699,32 @@ bool js_cocos2dx_studio_ArmatureDataManager_isAutoLoadSpriteFile(JSContext *cx, } bool js_cocos2dx_studio_ArmatureDataManager_addSpriteFrameFromFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ArmatureDataManager* cobj = (cocostudio::ArmatureDataManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureDataManager_addSpriteFrameFromFile : Invalid Native Object"); if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_addSpriteFrameFromFile : Error processing arguments"); cobj->addSpriteFrameFromFile(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 3) { std::string arg0; std::string arg1; std::string arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ArmatureDataManager_addSpriteFrameFromFile : Error processing arguments"); cobj->addSpriteFrameFromFile(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5351,9 +5733,10 @@ bool js_cocos2dx_studio_ArmatureDataManager_addSpriteFrameFromFile(JSContext *cx } bool js_cocos2dx_studio_ArmatureDataManager_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::ArmatureDataManager::destroyInstance(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ArmatureDataManager_destroyInstance : wrong number of arguments"); @@ -5362,6 +5745,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_destroyInstance(JSContext *cx, uint3 bool js_cocos2dx_studio_ArmatureDataManager_getInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::ArmatureDataManager* ret = cocostudio::ArmatureDataManager::getInstance(); jsval jsret = JSVAL_NULL; @@ -5373,7 +5757,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_getInstance(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ArmatureDataManager_getInstance : wrong number of arguments"); @@ -5386,7 +5770,7 @@ void js_cocostudio_ArmatureDataManager_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ArmatureDataManager)", obj); } -void js_register_cocos2dx_studio_ArmatureDataManager(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ArmatureDataManager(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_ArmatureDataManager_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_ArmatureDataManager_class->name = "ArmatureDataManager"; jsb_cocostudio_ArmatureDataManager_class->addProperty = JS_PropertyStub; @@ -5400,8 +5784,8 @@ void js_register_cocos2dx_studio_ArmatureDataManager(JSContext *cx, JSObject *gl jsb_cocostudio_ArmatureDataManager_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -5432,7 +5816,7 @@ void js_register_cocos2dx_studio_ArmatureDataManager(JSContext *cx, JSObject *gl jsb_cocostudio_ArmatureDataManager_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_ArmatureDataManager_class, empty_constructor, 0, properties, @@ -5463,15 +5847,15 @@ JSObject *jsb_cocostudio_Armature_prototype; bool js_cocos2dx_studio_Armature_getBone(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_getBone : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Armature_getBone : Error processing arguments"); cocostudio::Bone* ret = cobj->getBone(arg0); jsval jsret = JSVAL_NULL; @@ -5483,7 +5867,7 @@ bool js_cocos2dx_studio_Armature_getBone(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5492,9 +5876,9 @@ bool js_cocos2dx_studio_Armature_getBone(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_studio_Armature_changeBoneParent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_changeBoneParent : Invalid Native Object"); @@ -5502,17 +5886,17 @@ bool js_cocos2dx_studio_Armature_changeBoneParent(JSContext *cx, uint32_t argc, cocostudio::Bone* arg0; std::string arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Armature_changeBoneParent : Error processing arguments"); cobj->changeBoneParent(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5521,25 +5905,25 @@ bool js_cocos2dx_studio_Armature_changeBoneParent(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_Armature_setAnimation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_setAnimation : Invalid Native Object"); if (argc == 1) { cocostudio::ArmatureAnimation* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::ArmatureAnimation*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Armature_setAnimation : Error processing arguments"); cobj->setAnimation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5548,17 +5932,17 @@ bool js_cocos2dx_studio_Armature_setAnimation(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_Armature_getBoneAtPoint(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_getBoneAtPoint : Invalid Native Object"); if (argc == 2) { double arg0; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Armature_getBoneAtPoint : Error processing arguments"); cocostudio::Bone* ret = cobj->getBoneAtPoint(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -5570,7 +5954,7 @@ bool js_cocos2dx_studio_Armature_getBoneAtPoint(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5579,7 +5963,8 @@ bool js_cocos2dx_studio_Armature_getBoneAtPoint(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_studio_Armature_getArmatureTransformDirty(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_getArmatureTransformDirty : Invalid Native Object"); @@ -5587,7 +5972,7 @@ bool js_cocos2dx_studio_Armature_getArmatureTransformDirty(JSContext *cx, uint32 bool ret = cobj->getArmatureTransformDirty(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5596,18 +5981,18 @@ bool js_cocos2dx_studio_Armature_getArmatureTransformDirty(JSContext *cx, uint32 } bool js_cocos2dx_studio_Armature_setVersion(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_setVersion : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Armature_setVersion : Error processing arguments"); cobj->setVersion(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5616,13 +6001,14 @@ bool js_cocos2dx_studio_Armature_setVersion(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_Armature_updateOffsetPoint(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_updateOffsetPoint : Invalid Native Object"); if (argc == 0) { cobj->updateOffsetPoint(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5631,7 +6017,8 @@ bool js_cocos2dx_studio_Armature_updateOffsetPoint(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_Armature_getParentBone(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_getParentBone : Invalid Native Object"); @@ -5646,7 +6033,7 @@ bool js_cocos2dx_studio_Armature_getParentBone(JSContext *cx, uint32_t argc, jsv jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5655,9 +6042,9 @@ bool js_cocos2dx_studio_Armature_getParentBone(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_studio_Armature_removeBone(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_removeBone : Invalid Native Object"); @@ -5665,17 +6052,17 @@ bool js_cocos2dx_studio_Armature_removeBone(JSContext *cx, uint32_t argc, jsval cocostudio::Bone* arg0; bool arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Armature_removeBone : Error processing arguments"); cobj->removeBone(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5684,7 +6071,8 @@ bool js_cocos2dx_studio_Armature_removeBone(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_Armature_getBatchNode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_getBatchNode : Invalid Native Object"); @@ -5699,7 +6087,7 @@ bool js_cocos2dx_studio_Armature_getBatchNode(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5708,25 +6096,25 @@ bool js_cocos2dx_studio_Armature_getBatchNode(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_Armature_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocostudio::Armature* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_init : Invalid Native Object"); do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocostudio::Bone* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -5735,7 +6123,7 @@ bool js_cocos2dx_studio_Armature_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -5743,12 +6131,12 @@ bool js_cocos2dx_studio_Armature_init(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } bool ret = cobj->init(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -5758,25 +6146,25 @@ bool js_cocos2dx_studio_Armature_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Armature_setParentBone(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_setParentBone : Invalid Native Object"); if (argc == 1) { cocostudio::Bone* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Armature_setParentBone : Error processing arguments"); cobj->setParentBone(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5785,25 +6173,25 @@ bool js_cocos2dx_studio_Armature_setParentBone(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_studio_Armature_setBatchNode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_setBatchNode : Invalid Native Object"); if (argc == 1) { cocostudio::BatchNode* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::BatchNode*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Armature_setBatchNode : Error processing arguments"); cobj->setBatchNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5812,7 +6200,8 @@ bool js_cocos2dx_studio_Armature_setBatchNode(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_Armature_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_getBlendFunc : Invalid Native Object"); @@ -5820,7 +6209,7 @@ bool js_cocos2dx_studio_Armature_getBlendFunc(JSContext *cx, uint32_t argc, jsva const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); jsval jsret = JSVAL_NULL; jsret = blendfunc_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5829,25 +6218,25 @@ bool js_cocos2dx_studio_Armature_getBlendFunc(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_Armature_setArmatureData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_setArmatureData : Invalid Native Object"); if (argc == 1) { cocostudio::ArmatureData* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::ArmatureData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Armature_setArmatureData : Error processing arguments"); cobj->setArmatureData(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5856,9 +6245,9 @@ bool js_cocos2dx_studio_Armature_setArmatureData(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_studio_Armature_addBone(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_addBone : Invalid Native Object"); @@ -5866,17 +6255,17 @@ bool js_cocos2dx_studio_Armature_addBone(JSContext *cx, uint32_t argc, jsval *vp cocostudio::Bone* arg0; std::string arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Armature_addBone : Error processing arguments"); cobj->addBone(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5885,7 +6274,8 @@ bool js_cocos2dx_studio_Armature_addBone(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_studio_Armature_getArmatureData(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_getArmatureData : Invalid Native Object"); @@ -5900,7 +6290,7 @@ bool js_cocos2dx_studio_Armature_getArmatureData(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5909,7 +6299,8 @@ bool js_cocos2dx_studio_Armature_getArmatureData(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_studio_Armature_getBoundingBox(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_getBoundingBox : Invalid Native Object"); @@ -5917,7 +6308,7 @@ bool js_cocos2dx_studio_Armature_getBoundingBox(JSContext *cx, uint32_t argc, js cocos2d::Rect ret = cobj->getBoundingBox(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5926,7 +6317,8 @@ bool js_cocos2dx_studio_Armature_getBoundingBox(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_studio_Armature_getVersion(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_getVersion : Invalid Native Object"); @@ -5934,7 +6326,7 @@ bool js_cocos2dx_studio_Armature_getVersion(JSContext *cx, uint32_t argc, jsval double ret = cobj->getVersion(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5943,7 +6335,8 @@ bool js_cocos2dx_studio_Armature_getVersion(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_Armature_getAnimation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_getAnimation : Invalid Native Object"); @@ -5958,7 +6351,7 @@ bool js_cocos2dx_studio_Armature_getAnimation(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5967,7 +6360,8 @@ bool js_cocos2dx_studio_Armature_getAnimation(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_Armature_getOffsetPoints(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_getOffsetPoints : Invalid Native Object"); @@ -5975,7 +6369,7 @@ bool js_cocos2dx_studio_Armature_getOffsetPoints(JSContext *cx, uint32_t argc, j const cocos2d::Vec2& ret = cobj->getOffsetPoints(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5984,18 +6378,18 @@ bool js_cocos2dx_studio_Armature_getOffsetPoints(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_studio_Armature_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_setBlendFunc : Invalid Native Object"); if (argc == 1) { cocos2d::BlendFunc arg0; - ok &= jsval_to_blendfunc(cx, argv[0], &arg0); + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Armature_setBlendFunc : Error processing arguments"); cobj->setBlendFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6004,7 +6398,8 @@ bool js_cocos2dx_studio_Armature_setBlendFunc(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_Armature_getBoneDic(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Armature* cobj = (cocostudio::Armature *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Armature_getBoneDic : Invalid Native Object"); @@ -6012,7 +6407,7 @@ bool js_cocos2dx_studio_Armature_getBoneDic(JSContext *cx, uint32_t argc, jsval const cocos2d::Map& ret = cobj->getBoneDic(); jsval jsret = JSVAL_NULL; jsret = ccmap_string_key_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6021,13 +6416,13 @@ bool js_cocos2dx_studio_Armature_getBoneDic(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_Armature_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocostudio::Armature* ret = cocostudio::Armature::create(arg0); jsval jsret = JSVAL_NULL; @@ -6039,7 +6434,7 @@ bool js_cocos2dx_studio_Armature_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -6056,7 +6451,7 @@ bool js_cocos2dx_studio_Armature_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -6064,13 +6459,13 @@ bool js_cocos2dx_studio_Armature_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocostudio::Bone* arg1; do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -6086,7 +6481,7 @@ bool js_cocos2dx_studio_Armature_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -6095,7 +6490,7 @@ bool js_cocos2dx_studio_Armature_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Armature_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::Armature* cobj = new (std::nothrow) cocostudio::Armature(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -6109,13 +6504,16 @@ bool js_cocos2dx_studio_Armature_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::Armature"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::Armature"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -6128,21 +6526,21 @@ void js_cocostudio_Armature_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocostudio_Armature_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocostudio::Armature *nobj = new (std::nothrow) cocostudio::Armature(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::Armature"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::Armature"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_studio_Armature(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_Armature(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_Armature_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_Armature_class->name = "Armature"; jsb_cocostudio_Armature_class->addProperty = JS_PropertyStub; @@ -6156,8 +6554,8 @@ void js_register_cocos2dx_studio_Armature(JSContext *cx, JSObject *global) { jsb_cocostudio_Armature_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -6195,7 +6593,7 @@ void js_register_cocos2dx_studio_Armature(JSContext *cx, JSObject *global) { jsb_cocostudio_Armature_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocostudio_Armature_class, js_cocos2dx_studio_Armature_constructor, 0, // constructor properties, @@ -6226,7 +6624,8 @@ JSObject *jsb_cocostudio_Skin_prototype; bool js_cocos2dx_studio_Skin_getBone(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Skin* cobj = (cocostudio::Skin *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Skin_getBone : Invalid Native Object"); @@ -6241,7 +6640,7 @@ bool js_cocos2dx_studio_Skin_getBone(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6250,7 +6649,8 @@ bool js_cocos2dx_studio_Skin_getBone(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Skin_getNodeToWorldTransformAR(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Skin* cobj = (cocostudio::Skin *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Skin_getNodeToWorldTransformAR : Invalid Native Object"); @@ -6258,7 +6658,7 @@ bool js_cocos2dx_studio_Skin_getNodeToWorldTransformAR(JSContext *cx, uint32_t a cocos2d::Mat4 ret = cobj->getNodeToWorldTransformAR(); jsval jsret = JSVAL_NULL; jsret = matrix_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6267,7 +6667,8 @@ bool js_cocos2dx_studio_Skin_getNodeToWorldTransformAR(JSContext *cx, uint32_t a } bool js_cocos2dx_studio_Skin_getDisplayName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Skin* cobj = (cocostudio::Skin *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Skin_getDisplayName : Invalid Native Object"); @@ -6275,7 +6676,7 @@ bool js_cocos2dx_studio_Skin_getDisplayName(JSContext *cx, uint32_t argc, jsval const std::string& ret = cobj->getDisplayName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6284,13 +6685,14 @@ bool js_cocos2dx_studio_Skin_getDisplayName(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_Skin_updateArmatureTransform(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Skin* cobj = (cocostudio::Skin *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Skin_updateArmatureTransform : Invalid Native Object"); if (argc == 0) { cobj->updateArmatureTransform(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6299,25 +6701,25 @@ bool js_cocos2dx_studio_Skin_updateArmatureTransform(JSContext *cx, uint32_t arg } bool js_cocos2dx_studio_Skin_setBone(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::Skin* cobj = (cocostudio::Skin *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Skin_setBone : Invalid Native Object"); if (argc == 1) { cocostudio::Bone* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::Bone*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Skin_setBone : Error processing arguments"); cobj->setBone(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6326,13 +6728,13 @@ bool js_cocos2dx_studio_Skin_setBone(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Skin_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocostudio::Skin* ret = cocostudio::Skin::create(arg0); jsval jsret = JSVAL_NULL; @@ -6344,7 +6746,7 @@ bool js_cocos2dx_studio_Skin_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -6361,7 +6763,7 @@ bool js_cocos2dx_studio_Skin_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -6370,11 +6772,11 @@ bool js_cocos2dx_studio_Skin_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Skin_createWithSpriteFrameName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Skin_createWithSpriteFrameName : Error processing arguments"); cocostudio::Skin* ret = cocostudio::Skin::createWithSpriteFrameName(arg0); jsval jsret = JSVAL_NULL; @@ -6386,7 +6788,7 @@ bool js_cocos2dx_studio_Skin_createWithSpriteFrameName(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_Skin_createWithSpriteFrameName : wrong number of arguments"); @@ -6395,7 +6797,7 @@ bool js_cocos2dx_studio_Skin_createWithSpriteFrameName(JSContext *cx, uint32_t a bool js_cocos2dx_studio_Skin_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::Skin* cobj = new (std::nothrow) cocostudio::Skin(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -6409,13 +6811,16 @@ bool js_cocos2dx_studio_Skin_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::Skin"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::Skin"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -6426,7 +6831,7 @@ void js_cocostudio_Skin_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Skin)", obj); } -void js_register_cocos2dx_studio_Skin(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_Skin(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_Skin_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_Skin_class->name = "Skin"; jsb_cocostudio_Skin_class->addProperty = JS_PropertyStub; @@ -6440,8 +6845,8 @@ void js_register_cocos2dx_studio_Skin(JSContext *cx, JSObject *global) { jsb_cocostudio_Skin_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -6461,7 +6866,7 @@ void js_register_cocos2dx_studio_Skin(JSContext *cx, JSObject *global) { jsb_cocostudio_Skin_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Sprite_prototype, + JS::RootedObject(cx, jsb_cocos2d_Sprite_prototype), jsb_cocostudio_Skin_class, js_cocos2dx_studio_Skin_constructor, 0, // constructor properties, @@ -6492,66 +6897,100 @@ JSObject *jsb_cocostudio_ComAttribute_prototype; bool js_cocos2dx_studio_ComAttribute_getFloat(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAttribute* cobj = (cocostudio::ComAttribute *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAttribute_getFloat : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_getFloat : Error processing arguments"); double ret = cobj->getFloat(arg0); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { std::string arg0; double arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_getFloat : Error processing arguments"); double ret = cobj->getFloat(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ComAttribute_getFloat : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_studio_ComAttribute_getBool(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::ComAttribute* cobj = (cocostudio::ComAttribute *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAttribute_getBool : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_getBool : Error processing arguments"); + bool ret = cobj->getBool(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + if (argc == 2) { + std::string arg0; + bool arg1; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + arg1 = JS::ToBoolean(args.get(1)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_getBool : Error processing arguments"); + bool ret = cobj->getBool(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_ComAttribute_getBool : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_studio_ComAttribute_getString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAttribute* cobj = (cocostudio::ComAttribute *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAttribute_getString : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_getString : Error processing arguments"); std::string ret = cobj->getString(arg0); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_getString : Error processing arguments"); std::string ret = cobj->getString(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6560,20 +6999,20 @@ bool js_cocos2dx_studio_ComAttribute_getString(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_studio_ComAttribute_setFloat(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAttribute* cobj = (cocostudio::ComAttribute *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAttribute_setFloat : Invalid Native Object"); if (argc == 2) { std::string arg0; double arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_setFloat : Error processing arguments"); cobj->setFloat(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6582,76 +7021,42 @@ bool js_cocos2dx_studio_ComAttribute_setFloat(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_ComAttribute_setString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAttribute* cobj = (cocostudio::ComAttribute *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAttribute_setString : Invalid Native Object"); if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_setString : Error processing arguments"); cobj->setString(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ComAttribute_setString : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_studio_ComAttribute_getBool(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ComAttribute_setInt(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAttribute* cobj = (cocostudio::ComAttribute *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAttribute_getBool : Invalid Native Object"); - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_getBool : Error processing arguments"); - bool ret = cobj->getBool(arg0); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - if (argc == 2) { - std::string arg0; - bool arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_getBool : Error processing arguments"); - bool ret = cobj->getBool(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ComAttribute_getBool : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_ComAttribute_setInt(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::ComAttribute* cobj = (cocostudio::ComAttribute *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAttribute_setInt : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAttribute_setInt : Invalid Native Object"); if (argc == 2) { std::string arg0; int arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_setInt : Error processing arguments"); cobj->setInt(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6660,20 +7065,20 @@ bool js_cocos2dx_studio_ComAttribute_setInt(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ComAttribute_parse(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAttribute* cobj = (cocostudio::ComAttribute *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAttribute_parse : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_parse : Error processing arguments"); bool ret = cobj->parse(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6682,32 +7087,32 @@ bool js_cocos2dx_studio_ComAttribute_parse(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_ComAttribute_getInt(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAttribute* cobj = (cocostudio::ComAttribute *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAttribute_getInt : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_getInt : Error processing arguments"); int ret = cobj->getInt(arg0); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { std::string arg0; int arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_getInt : Error processing arguments"); int ret = cobj->getInt(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6716,20 +7121,20 @@ bool js_cocos2dx_studio_ComAttribute_getInt(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ComAttribute_setBool(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAttribute* cobj = (cocostudio::ComAttribute *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAttribute_setBool : Invalid Native Object"); if (argc == 2) { std::string arg0; bool arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAttribute_setBool : Error processing arguments"); cobj->setBool(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6738,6 +7143,7 @@ bool js_cocos2dx_studio_ComAttribute_setBool(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ComAttribute_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::ComAttribute* ret = cocostudio::ComAttribute::create(); jsval jsret = JSVAL_NULL; @@ -6749,13 +7155,42 @@ bool js_cocos2dx_studio_ComAttribute_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ComAttribute_create : wrong number of arguments"); return false; } +bool js_cocos2dx_studio_ComAttribute_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocostudio::ComAttribute* cobj = new (std::nothrow) cocostudio::ComAttribute(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ComAttribute"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + extern JSObject *jsb_cocos2d_Component_prototype; @@ -6763,7 +7198,7 @@ void js_cocostudio_ComAttribute_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ComAttribute)", obj); } -void js_register_cocos2dx_studio_ComAttribute(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ComAttribute(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_ComAttribute_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_ComAttribute_class->name = "ComAttribute"; jsb_cocostudio_ComAttribute_class->addProperty = JS_PropertyStub; @@ -6777,16 +7212,16 @@ void js_register_cocos2dx_studio_ComAttribute(JSContext *cx, JSObject *global) { jsb_cocostudio_ComAttribute_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getFloat", js_cocos2dx_studio_ComAttribute_getFloat, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getBool", js_cocos2dx_studio_ComAttribute_getBool, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getString", js_cocos2dx_studio_ComAttribute_getString, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setFloat", js_cocos2dx_studio_ComAttribute_setFloat, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setString", js_cocos2dx_studio_ComAttribute_setString, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getBool", js_cocos2dx_studio_ComAttribute_getBool, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setInt", js_cocos2dx_studio_ComAttribute_setInt, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("parse", js_cocos2dx_studio_ComAttribute_parse, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getInt", js_cocos2dx_studio_ComAttribute_getInt, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -6801,9 +7236,9 @@ void js_register_cocos2dx_studio_ComAttribute(JSContext *cx, JSObject *global) { jsb_cocostudio_ComAttribute_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Component_prototype, + JS::RootedObject(cx, jsb_cocos2d_Component_prototype), jsb_cocostudio_ComAttribute_class, - empty_constructor, 0, + js_cocos2dx_studio_ComAttribute_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -6832,13 +7267,14 @@ JSObject *jsb_cocostudio_ComAudio_prototype; bool js_cocos2dx_studio_ComAudio_stopAllEffects(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_stopAllEffects : Invalid Native Object"); if (argc == 0) { cobj->stopAllEffects(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6847,7 +7283,8 @@ bool js_cocos2dx_studio_ComAudio_stopAllEffects(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_studio_ComAudio_getEffectsVolume(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_getEffectsVolume : Invalid Native Object"); @@ -6855,7 +7292,7 @@ bool js_cocos2dx_studio_ComAudio_getEffectsVolume(JSContext *cx, uint32_t argc, double ret = cobj->getEffectsVolume(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6864,18 +7301,18 @@ bool js_cocos2dx_studio_ComAudio_getEffectsVolume(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_ComAudio_stopEffect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_stopEffect : Invalid Native Object"); if (argc == 1) { unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAudio_stopEffect : Error processing arguments"); cobj->stopEffect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6884,7 +7321,8 @@ bool js_cocos2dx_studio_ComAudio_stopEffect(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ComAudio_getBackgroundMusicVolume(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_getBackgroundMusicVolume : Invalid Native Object"); @@ -6892,7 +7330,7 @@ bool js_cocos2dx_studio_ComAudio_getBackgroundMusicVolume(JSContext *cx, uint32_ double ret = cobj->getBackgroundMusicVolume(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6901,7 +7339,8 @@ bool js_cocos2dx_studio_ComAudio_getBackgroundMusicVolume(JSContext *cx, uint32_ } bool js_cocos2dx_studio_ComAudio_willPlayBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_willPlayBackgroundMusic : Invalid Native Object"); @@ -6909,7 +7348,7 @@ bool js_cocos2dx_studio_ComAudio_willPlayBackgroundMusic(JSContext *cx, uint32_t bool ret = cobj->willPlayBackgroundMusic(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6918,18 +7357,18 @@ bool js_cocos2dx_studio_ComAudio_willPlayBackgroundMusic(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ComAudio_setBackgroundMusicVolume(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_setBackgroundMusicVolume : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAudio_setBackgroundMusicVolume : Error processing arguments"); cobj->setBackgroundMusicVolume(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6938,13 +7377,14 @@ bool js_cocos2dx_studio_ComAudio_setBackgroundMusicVolume(JSContext *cx, uint32_ } bool js_cocos2dx_studio_ComAudio_end(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_end : Invalid Native Object"); if (argc == 0) { cobj->end(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6953,19 +7393,19 @@ bool js_cocos2dx_studio_ComAudio_end(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_ComAudio_stopBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocostudio::ComAudio* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_stopBackgroundMusic : Invalid Native Object"); do { if (argc == 0) { cobj->stopBackgroundMusic(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -6973,9 +7413,9 @@ bool js_cocos2dx_studio_ComAudio_stopBackgroundMusic(JSContext *cx, uint32_t arg do { if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); cobj->stopBackgroundMusic(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -6985,13 +7425,14 @@ bool js_cocos2dx_studio_ComAudio_stopBackgroundMusic(JSContext *cx, uint32_t arg } bool js_cocos2dx_studio_ComAudio_pauseBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_pauseBackgroundMusic : Invalid Native Object"); if (argc == 0) { cobj->pauseBackgroundMusic(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7000,7 +7441,8 @@ bool js_cocos2dx_studio_ComAudio_pauseBackgroundMusic(JSContext *cx, uint32_t ar } bool js_cocos2dx_studio_ComAudio_isBackgroundMusicPlaying(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_isBackgroundMusicPlaying : Invalid Native Object"); @@ -7008,7 +7450,7 @@ bool js_cocos2dx_studio_ComAudio_isBackgroundMusicPlaying(JSContext *cx, uint32_ bool ret = cobj->isBackgroundMusicPlaying(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7017,7 +7459,8 @@ bool js_cocos2dx_studio_ComAudio_isBackgroundMusicPlaying(JSContext *cx, uint32_ } bool js_cocos2dx_studio_ComAudio_isLoop(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_isLoop : Invalid Native Object"); @@ -7025,7 +7468,7 @@ bool js_cocos2dx_studio_ComAudio_isLoop(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isLoop(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7034,13 +7477,14 @@ bool js_cocos2dx_studio_ComAudio_isLoop(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_ComAudio_resumeAllEffects(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_resumeAllEffects : Invalid Native Object"); if (argc == 0) { cobj->resumeAllEffects(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7049,13 +7493,14 @@ bool js_cocos2dx_studio_ComAudio_resumeAllEffects(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_ComAudio_pauseAllEffects(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_pauseAllEffects : Invalid Native Object"); if (argc == 0) { cobj->pauseAllEffects(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7064,18 +7509,18 @@ bool js_cocos2dx_studio_ComAudio_pauseAllEffects(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_studio_ComAudio_preloadBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_preloadBackgroundMusic : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAudio_preloadBackgroundMusic : Error processing arguments"); cobj->preloadBackgroundMusic(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7084,22 +7529,22 @@ bool js_cocos2dx_studio_ComAudio_preloadBackgroundMusic(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ComAudio_playBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocostudio::ComAudio* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_playBackgroundMusic : Invalid Native Object"); do { if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } cobj->playBackgroundMusic(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -7107,12 +7552,12 @@ bool js_cocos2dx_studio_ComAudio_playBackgroundMusic(JSContext *cx, uint32_t arg do { if (argc == 2) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } bool arg1; - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); cobj->playBackgroundMusic(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -7120,7 +7565,7 @@ bool js_cocos2dx_studio_ComAudio_playBackgroundMusic(JSContext *cx, uint32_t arg do { if (argc == 0) { cobj->playBackgroundMusic(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -7130,24 +7575,24 @@ bool js_cocos2dx_studio_ComAudio_playBackgroundMusic(JSContext *cx, uint32_t arg } bool js_cocos2dx_studio_ComAudio_playEffect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocostudio::ComAudio* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_playEffect : Invalid Native Object"); do { if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } unsigned int ret = cobj->playEffect(arg0); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -7155,14 +7600,14 @@ bool js_cocos2dx_studio_ComAudio_playEffect(JSContext *cx, uint32_t argc, jsval do { if (argc == 2) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } bool arg1; - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); unsigned int ret = cobj->playEffect(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -7172,7 +7617,7 @@ bool js_cocos2dx_studio_ComAudio_playEffect(JSContext *cx, uint32_t argc, jsval unsigned int ret = cobj->playEffect(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -7182,18 +7627,18 @@ bool js_cocos2dx_studio_ComAudio_playEffect(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ComAudio_preloadEffect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_preloadEffect : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAudio_preloadEffect : Error processing arguments"); cobj->preloadEffect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7202,18 +7647,18 @@ bool js_cocos2dx_studio_ComAudio_preloadEffect(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_studio_ComAudio_setLoop(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_setLoop : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAudio_setLoop : Error processing arguments"); cobj->setLoop(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7222,18 +7667,18 @@ bool js_cocos2dx_studio_ComAudio_setLoop(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_studio_ComAudio_unloadEffect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_unloadEffect : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAudio_unloadEffect : Error processing arguments"); cobj->unloadEffect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7242,13 +7687,14 @@ bool js_cocos2dx_studio_ComAudio_unloadEffect(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_ComAudio_rewindBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_rewindBackgroundMusic : Invalid Native Object"); if (argc == 0) { cobj->rewindBackgroundMusic(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7257,18 +7703,18 @@ bool js_cocos2dx_studio_ComAudio_rewindBackgroundMusic(JSContext *cx, uint32_t a } bool js_cocos2dx_studio_ComAudio_pauseEffect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_pauseEffect : Invalid Native Object"); if (argc == 1) { unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAudio_pauseEffect : Error processing arguments"); cobj->pauseEffect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7277,13 +7723,14 @@ bool js_cocos2dx_studio_ComAudio_pauseEffect(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ComAudio_resumeBackgroundMusic(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_resumeBackgroundMusic : Invalid Native Object"); if (argc == 0) { cobj->resumeBackgroundMusic(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7292,18 +7739,18 @@ bool js_cocos2dx_studio_ComAudio_resumeBackgroundMusic(JSContext *cx, uint32_t a } bool js_cocos2dx_studio_ComAudio_setFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_setFile : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAudio_setFile : Error processing arguments"); cobj->setFile(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7312,18 +7759,18 @@ bool js_cocos2dx_studio_ComAudio_setFile(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_studio_ComAudio_setEffectsVolume(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_setEffectsVolume : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAudio_setEffectsVolume : Error processing arguments"); cobj->setEffectsVolume(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7332,7 +7779,8 @@ bool js_cocos2dx_studio_ComAudio_setEffectsVolume(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_ComAudio_getFile(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_getFile : Invalid Native Object"); @@ -7340,7 +7788,7 @@ bool js_cocos2dx_studio_ComAudio_getFile(JSContext *cx, uint32_t argc, jsval *vp const char* ret = cobj->getFile(); jsval jsret = JSVAL_NULL; jsret = c_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7349,18 +7797,18 @@ bool js_cocos2dx_studio_ComAudio_getFile(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_studio_ComAudio_resumeEffect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComAudio* cobj = (cocostudio::ComAudio *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComAudio_resumeEffect : Invalid Native Object"); if (argc == 1) { unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComAudio_resumeEffect : Error processing arguments"); cobj->resumeEffect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7369,6 +7817,7 @@ bool js_cocos2dx_studio_ComAudio_resumeEffect(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_ComAudio_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::ComAudio* ret = cocostudio::ComAudio::create(); jsval jsret = JSVAL_NULL; @@ -7380,13 +7829,42 @@ bool js_cocos2dx_studio_ComAudio_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ComAudio_create : wrong number of arguments"); return false; } +bool js_cocos2dx_studio_ComAudio_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocostudio::ComAudio* cobj = new (std::nothrow) cocostudio::ComAudio(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ComAudio"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + extern JSObject *jsb_cocos2d_Component_prototype; @@ -7394,7 +7872,7 @@ void js_cocostudio_ComAudio_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ComAudio)", obj); } -void js_register_cocos2dx_studio_ComAudio(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ComAudio(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_ComAudio_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_ComAudio_class->name = "ComAudio"; jsb_cocostudio_ComAudio_class->addProperty = JS_PropertyStub; @@ -7408,8 +7886,8 @@ void js_register_cocos2dx_studio_ComAudio(JSContext *cx, JSObject *global) { jsb_cocostudio_ComAudio_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -7449,9 +7927,9 @@ void js_register_cocos2dx_studio_ComAudio(JSContext *cx, JSObject *global) { jsb_cocostudio_ComAudio_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Component_prototype, + JS::RootedObject(cx, jsb_cocos2d_Component_prototype), jsb_cocostudio_ComAudio_class, - empty_constructor, 0, + js_cocos2dx_studio_ComAudio_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -7480,7 +7958,8 @@ JSObject *jsb_cocostudio_InputDelegate_prototype; bool js_cocos2dx_studio_InputDelegate_isAccelerometerEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::InputDelegate* cobj = (cocostudio::InputDelegate *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InputDelegate_isAccelerometerEnabled : Invalid Native Object"); @@ -7488,7 +7967,7 @@ bool js_cocos2dx_studio_InputDelegate_isAccelerometerEnabled(JSContext *cx, uint bool ret = cobj->isAccelerometerEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7497,18 +7976,18 @@ bool js_cocos2dx_studio_InputDelegate_isAccelerometerEnabled(JSContext *cx, uint } bool js_cocos2dx_studio_InputDelegate_setKeypadEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::InputDelegate* cobj = (cocostudio::InputDelegate *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InputDelegate_setKeypadEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_InputDelegate_setKeypadEnabled : Error processing arguments"); cobj->setKeypadEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7517,7 +7996,8 @@ bool js_cocos2dx_studio_InputDelegate_setKeypadEnabled(JSContext *cx, uint32_t a } bool js_cocos2dx_studio_InputDelegate_getTouchMode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::InputDelegate* cobj = (cocostudio::InputDelegate *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InputDelegate_getTouchMode : Invalid Native Object"); @@ -7525,7 +8005,7 @@ bool js_cocos2dx_studio_InputDelegate_getTouchMode(JSContext *cx, uint32_t argc, int ret = (int)cobj->getTouchMode(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7534,18 +8014,18 @@ bool js_cocos2dx_studio_InputDelegate_getTouchMode(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_InputDelegate_setAccelerometerEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::InputDelegate* cobj = (cocostudio::InputDelegate *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InputDelegate_setAccelerometerEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_InputDelegate_setAccelerometerEnabled : Error processing arguments"); cobj->setAccelerometerEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7554,7 +8034,8 @@ bool js_cocos2dx_studio_InputDelegate_setAccelerometerEnabled(JSContext *cx, uin } bool js_cocos2dx_studio_InputDelegate_isKeypadEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::InputDelegate* cobj = (cocostudio::InputDelegate *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InputDelegate_isKeypadEnabled : Invalid Native Object"); @@ -7562,7 +8043,7 @@ bool js_cocos2dx_studio_InputDelegate_isKeypadEnabled(JSContext *cx, uint32_t ar bool ret = cobj->isKeypadEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7571,7 +8052,8 @@ bool js_cocos2dx_studio_InputDelegate_isKeypadEnabled(JSContext *cx, uint32_t ar } bool js_cocos2dx_studio_InputDelegate_isTouchEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::InputDelegate* cobj = (cocostudio::InputDelegate *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InputDelegate_isTouchEnabled : Invalid Native Object"); @@ -7579,7 +8061,7 @@ bool js_cocos2dx_studio_InputDelegate_isTouchEnabled(JSContext *cx, uint32_t arg bool ret = cobj->isTouchEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7588,18 +8070,18 @@ bool js_cocos2dx_studio_InputDelegate_isTouchEnabled(JSContext *cx, uint32_t arg } bool js_cocos2dx_studio_InputDelegate_setTouchPriority(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::InputDelegate* cobj = (cocostudio::InputDelegate *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InputDelegate_setTouchPriority : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_InputDelegate_setTouchPriority : Error processing arguments"); cobj->setTouchPriority(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7608,7 +8090,8 @@ bool js_cocos2dx_studio_InputDelegate_setTouchPriority(JSContext *cx, uint32_t a } bool js_cocos2dx_studio_InputDelegate_getTouchPriority(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::InputDelegate* cobj = (cocostudio::InputDelegate *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InputDelegate_getTouchPriority : Invalid Native Object"); @@ -7616,7 +8099,7 @@ bool js_cocos2dx_studio_InputDelegate_getTouchPriority(JSContext *cx, uint32_t a int ret = cobj->getTouchPriority(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7625,18 +8108,18 @@ bool js_cocos2dx_studio_InputDelegate_getTouchPriority(JSContext *cx, uint32_t a } bool js_cocos2dx_studio_InputDelegate_setTouchEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::InputDelegate* cobj = (cocostudio::InputDelegate *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InputDelegate_setTouchEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_InputDelegate_setTouchEnabled : Error processing arguments"); cobj->setTouchEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7645,18 +8128,18 @@ bool js_cocos2dx_studio_InputDelegate_setTouchEnabled(JSContext *cx, uint32_t ar } bool js_cocos2dx_studio_InputDelegate_setTouchMode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::InputDelegate* cobj = (cocostudio::InputDelegate *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InputDelegate_setTouchMode : Invalid Native Object"); if (argc == 1) { cocos2d::Touch::DispatchMode arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_InputDelegate_setTouchMode : Error processing arguments"); cobj->setTouchMode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7669,7 +8152,7 @@ void js_cocostudio_InputDelegate_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (InputDelegate)", obj); } -void js_register_cocos2dx_studio_InputDelegate(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_InputDelegate(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_InputDelegate_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_InputDelegate_class->name = "InputDelegate"; jsb_cocostudio_InputDelegate_class->addProperty = JS_PropertyStub; @@ -7683,8 +8166,8 @@ void js_register_cocos2dx_studio_InputDelegate(JSContext *cx, JSObject *global) jsb_cocostudio_InputDelegate_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -7705,7 +8188,7 @@ void js_register_cocos2dx_studio_InputDelegate(JSContext *cx, JSObject *global) jsb_cocostudio_InputDelegate_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_InputDelegate_class, empty_constructor, 0, properties, @@ -7736,6 +8219,7 @@ JSObject *jsb_cocostudio_ComController_prototype; bool js_cocos2dx_studio_ComController_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::ComController* ret = cocostudio::ComController::create(); jsval jsret = JSVAL_NULL; @@ -7747,7 +8231,7 @@ bool js_cocos2dx_studio_ComController_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ComController_create : wrong number of arguments"); @@ -7756,7 +8240,7 @@ bool js_cocos2dx_studio_ComController_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_studio_ComController_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::ComController* cobj = new (std::nothrow) cocostudio::ComController(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -7770,13 +8254,16 @@ bool js_cocos2dx_studio_ComController_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::ComController"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ComController"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -7789,21 +8276,21 @@ void js_cocostudio_ComController_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocostudio_ComController_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocostudio::ComController *nobj = new (std::nothrow) cocostudio::ComController(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::ComController"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ComController"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_studio_ComController(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ComController(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_ComController_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_ComController_class->name = "ComController"; jsb_cocostudio_ComController_class->addProperty = JS_PropertyStub; @@ -7817,8 +8304,8 @@ void js_register_cocos2dx_studio_ComController(JSContext *cx, JSObject *global) jsb_cocostudio_ComController_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -7833,7 +8320,7 @@ void js_register_cocos2dx_studio_ComController(JSContext *cx, JSObject *global) jsb_cocostudio_ComController_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Component_prototype, + JS::RootedObject(cx, jsb_cocos2d_Component_prototype), jsb_cocostudio_ComController_class, js_cocos2dx_studio_ComController_constructor, 0, // constructor properties, @@ -7862,36 +8349,10 @@ void js_register_cocos2dx_studio_ComController(JSContext *cx, JSObject *global) JSClass *jsb_cocostudio_ComRender_class; JSObject *jsb_cocostudio_ComRender_prototype; -bool js_cocos2dx_studio_ComRender_setNode(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::ComRender* cobj = (cocostudio::ComRender *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComRender_setNode : Invalid Native Object"); - if (argc == 1) { - cocos2d::Node* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComRender_setNode : Error processing arguments"); - cobj->setNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ComRender_setNode : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_studio_ComRender_getNode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ComRender* cobj = (cocostudio::ComRender *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComRender_getNode : Invalid Native Object"); @@ -7906,32 +8367,59 @@ bool js_cocos2dx_studio_ComRender_getNode(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ComRender_getNode : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_studio_ComRender_setNode(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::ComRender* cobj = (cocostudio::ComRender *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ComRender_setNode : Invalid Native Object"); + if (argc == 1) { + cocos2d::Node* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ComRender_setNode : Error processing arguments"); + cobj->setNode(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_ComRender_setNode : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_studio_ComRender_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 2) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } const char* arg1; - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); if (!ok) { ok = true; break; } cocostudio::ComRender* ret = cocostudio::ComRender::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -7943,7 +8431,7 @@ bool js_cocos2dx_studio_ComRender_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -7960,746 +8448,133 @@ bool js_cocos2dx_studio_ComRender_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); JS_ReportError(cx, "js_cocos2dx_studio_ComRender_create : wrong number of arguments"); return false; } - -extern JSObject *jsb_cocos2d_Component_prototype; - -void js_cocostudio_ComRender_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (ComRender)", obj); -} - -void js_register_cocos2dx_studio_ComRender(JSContext *cx, JSObject *global) { - jsb_cocostudio_ComRender_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocostudio_ComRender_class->name = "ComRender"; - jsb_cocostudio_ComRender_class->addProperty = JS_PropertyStub; - jsb_cocostudio_ComRender_class->delProperty = JS_DeletePropertyStub; - jsb_cocostudio_ComRender_class->getProperty = JS_PropertyStub; - jsb_cocostudio_ComRender_class->setProperty = JS_StrictPropertyStub; - jsb_cocostudio_ComRender_class->enumerate = JS_EnumerateStub; - jsb_cocostudio_ComRender_class->resolve = JS_ResolveStub; - jsb_cocostudio_ComRender_class->convert = JS_ConvertStub; - jsb_cocostudio_ComRender_class->finalize = js_cocostudio_ComRender_finalize; - jsb_cocostudio_ComRender_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); - - static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} - }; - - static JSFunctionSpec funcs[] = { - JS_FN("setNode", js_cocos2dx_studio_ComRender_setNode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getNode", js_cocos2dx_studio_ComRender_getNode, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_studio_ComRender_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - jsb_cocostudio_ComRender_prototype = JS_InitClass( - cx, global, - jsb_cocos2d_Component_prototype, - jsb_cocostudio_ComRender_class, - empty_constructor, 0, - properties, - funcs, - NULL, // no static properties - st_funcs); - // make the class enumerable in the registered namespace -// bool found; -//FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "ComRender", JSPROP_ENUMERATE | JSPROP_READONLY, &found); - - // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocostudio_ComRender_class; - p->proto = jsb_cocostudio_ComRender_prototype; - p->parentProto = jsb_cocos2d_Component_prototype; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } -} - -JSClass *jsb_cocostudio_GUIReader_class; -JSObject *jsb_cocostudio_GUIReader_prototype; - -bool js_cocos2dx_studio_GUIReader_setFilePath(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::GUIReader* cobj = (cocostudio::GUIReader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_GUIReader_setFilePath : Invalid Native Object"); - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_GUIReader_setFilePath : Error processing arguments"); - cobj->setFilePath(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_GUIReader_setFilePath : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_GUIReader_widgetFromJsonFile(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ComRender_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::GUIReader* cobj = (cocostudio::GUIReader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_GUIReader_widgetFromJsonFile : Invalid Native Object"); - if (argc == 1) { - const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_GUIReader_widgetFromJsonFile : Error processing arguments"); - cocos2d::ui::Widget* ret = cobj->widgetFromJsonFile(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Widget*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_GUIReader_widgetFromJsonFile : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_GUIReader_getFilePath(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::GUIReader* cobj = (cocostudio::GUIReader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_GUIReader_getFilePath : Invalid Native Object"); - if (argc == 0) { - const std::string& ret = cobj->getFilePath(); - jsval jsret = JSVAL_NULL; - jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - JS_ReportError(cx, "js_cocos2dx_studio_GUIReader_getFilePath : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} -bool js_cocos2dx_studio_GUIReader_widgetFromBinaryFile(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::GUIReader* cobj = (cocostudio::GUIReader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_GUIReader_widgetFromBinaryFile : Invalid Native Object"); - if (argc == 1) { - const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_GUIReader_widgetFromBinaryFile : Error processing arguments"); - cocos2d::ui::Widget* ret = cobj->widgetFromBinaryFile(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Widget*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; + JS::RootedObject obj(cx); + cocostudio::ComRender* cobj = NULL; + do { + if (argc == 2) { + cocos2d::Node* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + const char* arg1; + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); + if (!ok) { ok = true; break; } + cobj = new (std::nothrow) cocostudio::ComRender(arg0, arg1); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_GUIReader_widgetFromBinaryFile : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_GUIReader_getVersionInteger(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::GUIReader* cobj = (cocostudio::GUIReader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_GUIReader_getVersionInteger : Invalid Native Object"); - if (argc == 1) { - const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_GUIReader_getVersionInteger : Error processing arguments"); - int ret = cobj->getVersionInteger(arg0); - jsval jsret = JSVAL_NULL; - jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_GUIReader_getVersionInteger : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_GUIReader_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp) -{ - if (argc == 0) { - cocostudio::GUIReader::destroyInstance(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - JS_ReportError(cx, "js_cocos2dx_studio_GUIReader_destroyInstance : wrong number of arguments"); - return false; -} - -bool js_cocos2dx_studio_GUIReader_getInstance(JSContext *cx, uint32_t argc, jsval *vp) -{ - if (argc == 0) { - cocostudio::GUIReader* ret = cocostudio::GUIReader::getInstance(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocostudio::GUIReader*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - JS_ReportError(cx, "js_cocos2dx_studio_GUIReader_getInstance : wrong number of arguments"); - return false; -} - - - -void js_cocostudio_GUIReader_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (GUIReader)", obj); -} - -void js_register_cocos2dx_studio_GUIReader(JSContext *cx, JSObject *global) { - jsb_cocostudio_GUIReader_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocostudio_GUIReader_class->name = "GUIReader"; - jsb_cocostudio_GUIReader_class->addProperty = JS_PropertyStub; - jsb_cocostudio_GUIReader_class->delProperty = JS_DeletePropertyStub; - jsb_cocostudio_GUIReader_class->getProperty = JS_PropertyStub; - jsb_cocostudio_GUIReader_class->setProperty = JS_StrictPropertyStub; - jsb_cocostudio_GUIReader_class->enumerate = JS_EnumerateStub; - jsb_cocostudio_GUIReader_class->resolve = JS_ResolveStub; - jsb_cocostudio_GUIReader_class->convert = JS_ConvertStub; - jsb_cocostudio_GUIReader_class->finalize = js_cocostudio_GUIReader_finalize; - jsb_cocostudio_GUIReader_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); - - static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} - }; - - static JSFunctionSpec funcs[] = { - JS_FN("setFilePath", js_cocos2dx_studio_GUIReader_setFilePath, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("widgetFromJsonFile", js_cocos2dx_studio_GUIReader_widgetFromJsonFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getFilePath", js_cocos2dx_studio_GUIReader_getFilePath, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("widgetFromBinaryFile", js_cocos2dx_studio_GUIReader_widgetFromBinaryFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getVersionInteger", js_cocos2dx_studio_GUIReader_getVersionInteger, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - static JSFunctionSpec st_funcs[] = { - JS_FN("destroyInstance", js_cocos2dx_studio_GUIReader_destroyInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getInstance", js_cocos2dx_studio_GUIReader_getInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - jsb_cocostudio_GUIReader_prototype = JS_InitClass( - cx, global, - NULL, // parent proto - jsb_cocostudio_GUIReader_class, - empty_constructor, 0, - properties, - funcs, - NULL, // no static properties - st_funcs); - // make the class enumerable in the registered namespace -// bool found; -//FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "GUIReader", JSPROP_ENUMERATE | JSPROP_READONLY, &found); - - // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocostudio_GUIReader_class; - p->proto = jsb_cocostudio_GUIReader_prototype; - p->parentProto = NULL; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } -} - -JSClass *jsb_cocostudio_SceneReader_class; -JSObject *jsb_cocostudio_SceneReader_prototype; - -bool js_cocos2dx_studio_SceneReader_createNodeWithSceneFile(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::SceneReader* cobj = (cocostudio::SceneReader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_SceneReader_createNodeWithSceneFile : Invalid Native Object"); - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_SceneReader_createNodeWithSceneFile : Error processing arguments"); - cocos2d::Node* ret = cobj->createNodeWithSceneFile(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Node*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - if (argc == 2) { - std::string arg0; - cocostudio::SceneReader::AttachComponentType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_SceneReader_createNodeWithSceneFile : Error processing arguments"); - cocos2d::Node* ret = cobj->createNodeWithSceneFile(arg0, arg1); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Node*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_SceneReader_createNodeWithSceneFile : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_SceneReader_getAttachComponentType(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::SceneReader* cobj = (cocostudio::SceneReader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_SceneReader_getAttachComponentType : Invalid Native Object"); - if (argc == 0) { - int ret = (int)cobj->getAttachComponentType(); - jsval jsret = JSVAL_NULL; - jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_SceneReader_getAttachComponentType : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} -bool js_cocos2dx_studio_SceneReader_getNodeByTag(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::SceneReader* cobj = (cocostudio::SceneReader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_SceneReader_getNodeByTag : Invalid Native Object"); - if (argc == 1) { - int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_SceneReader_getNodeByTag : Error processing arguments"); - cocos2d::Node* ret = cobj->getNodeByTag(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Node*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_SceneReader_getNodeByTag : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_SceneReader_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp) -{ - if (argc == 0) { - cocostudio::SceneReader::destroyInstance(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - JS_ReportError(cx, "js_cocos2dx_studio_SceneReader_destroyInstance : wrong number of arguments"); - return false; -} - -bool js_cocos2dx_studio_SceneReader_sceneReaderVersion(JSContext *cx, uint32_t argc, jsval *vp) -{ - if (argc == 0) { - const char* ret = cocostudio::SceneReader::sceneReaderVersion(); - jsval jsret = JSVAL_NULL; - jsret = c_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - JS_ReportError(cx, "js_cocos2dx_studio_SceneReader_sceneReaderVersion : wrong number of arguments"); - return false; -} - -bool js_cocos2dx_studio_SceneReader_getInstance(JSContext *cx, uint32_t argc, jsval *vp) -{ - if (argc == 0) { - cocostudio::SceneReader* ret = cocostudio::SceneReader::getInstance(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocostudio::SceneReader*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - JS_ReportError(cx, "js_cocos2dx_studio_SceneReader_getInstance : wrong number of arguments"); - return false; -} - - - -void js_cocostudio_SceneReader_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (SceneReader)", obj); -} - -void js_register_cocos2dx_studio_SceneReader(JSContext *cx, JSObject *global) { - jsb_cocostudio_SceneReader_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocostudio_SceneReader_class->name = "SceneReader"; - jsb_cocostudio_SceneReader_class->addProperty = JS_PropertyStub; - jsb_cocostudio_SceneReader_class->delProperty = JS_DeletePropertyStub; - jsb_cocostudio_SceneReader_class->getProperty = JS_PropertyStub; - jsb_cocostudio_SceneReader_class->setProperty = JS_StrictPropertyStub; - jsb_cocostudio_SceneReader_class->enumerate = JS_EnumerateStub; - jsb_cocostudio_SceneReader_class->resolve = JS_ResolveStub; - jsb_cocostudio_SceneReader_class->convert = JS_ConvertStub; - jsb_cocostudio_SceneReader_class->finalize = js_cocostudio_SceneReader_finalize; - jsb_cocostudio_SceneReader_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); - - static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} - }; - - static JSFunctionSpec funcs[] = { - JS_FN("createNodeWithSceneFile", js_cocos2dx_studio_SceneReader_createNodeWithSceneFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getAttachComponentType", js_cocos2dx_studio_SceneReader_getAttachComponentType, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getNodeByTag", js_cocos2dx_studio_SceneReader_getNodeByTag, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - static JSFunctionSpec st_funcs[] = { - JS_FN("destroyInstance", js_cocos2dx_studio_SceneReader_destroyInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("sceneReaderVersion", js_cocos2dx_studio_SceneReader_sceneReaderVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getInstance", js_cocos2dx_studio_SceneReader_getInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - jsb_cocostudio_SceneReader_prototype = JS_InitClass( - cx, global, - NULL, // parent proto - jsb_cocostudio_SceneReader_class, - empty_constructor, 0, - properties, - funcs, - NULL, // no static properties - st_funcs); - // make the class enumerable in the registered namespace -// bool found; -//FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "SceneReader", JSPROP_ENUMERATE | JSPROP_READONLY, &found); - - // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocostudio_SceneReader_class; - p->proto = jsb_cocostudio_SceneReader_prototype; - p->parentProto = NULL; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } -} - -JSClass *jsb_cocostudio_timeline_ActionTimelineCache_class; -JSObject *jsb_cocostudio_timeline_ActionTimelineCache_prototype; - -bool js_cocos2dx_studio_ActionTimelineCache_createActionFromJson(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::timeline::ActionTimelineCache* cobj = (cocostudio::timeline::ActionTimelineCache *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimelineCache_createActionFromJson : Invalid Native Object"); - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimelineCache_createActionFromJson : Error processing arguments"); - cocostudio::timeline::ActionTimeline* ret = cobj->createActionFromJson(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocostudio::timeline::ActionTimeline*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ActionTimelineCache_createActionFromJson : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_ActionTimelineCache_purge(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::timeline::ActionTimelineCache* cobj = (cocostudio::timeline::ActionTimelineCache *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimelineCache_purge : Invalid Native Object"); - if (argc == 0) { - cobj->purge(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ActionTimelineCache_purge : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} -bool js_cocos2dx_studio_ActionTimelineCache_init(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::timeline::ActionTimelineCache* cobj = (cocostudio::timeline::ActionTimelineCache *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimelineCache_init : Invalid Native Object"); - if (argc == 0) { - cobj->init(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ActionTimelineCache_init : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} -bool js_cocos2dx_studio_ActionTimelineCache_loadAnimationActionWithFile(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::timeline::ActionTimelineCache* cobj = (cocostudio::timeline::ActionTimelineCache *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimelineCache_loadAnimationActionWithFile : Invalid Native Object"); - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimelineCache_loadAnimationActionWithFile : Error processing arguments"); - cocostudio::timeline::ActionTimeline* ret = cobj->loadAnimationActionWithFile(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocostudio::timeline::ActionTimeline*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ActionTimelineCache_loadAnimationActionWithFile : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_ActionTimelineCache_loadAnimationActionWithContent(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::timeline::ActionTimelineCache* cobj = (cocostudio::timeline::ActionTimelineCache *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimelineCache_loadAnimationActionWithContent : Invalid Native Object"); - if (argc == 2) { - std::string arg0; - std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimelineCache_loadAnimationActionWithContent : Error processing arguments"); - cocostudio::timeline::ActionTimeline* ret = cobj->loadAnimationActionWithContent(arg0, arg1); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocostudio::timeline::ActionTimeline*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ActionTimelineCache_loadAnimationActionWithContent : wrong number of arguments: %d, was expecting %d", argc, 2); - return false; -} -bool js_cocos2dx_studio_ActionTimelineCache_removeAction(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::timeline::ActionTimelineCache* cobj = (cocostudio::timeline::ActionTimelineCache *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimelineCache_removeAction : Invalid Native Object"); - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimelineCache_removeAction : Error processing arguments"); - cobj->removeAction(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ActionTimelineCache_removeAction : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_ActionTimelineCache_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp) -{ - if (argc == 0) { - cocostudio::timeline::ActionTimelineCache::destroyInstance(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - JS_ReportError(cx, "js_cocos2dx_studio_ActionTimelineCache_destroyInstance : wrong number of arguments"); - return false; -} - -bool js_cocos2dx_studio_ActionTimelineCache_createAction(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimelineCache_createAction : Error processing arguments"); - cocostudio::timeline::ActionTimeline* ret = cocostudio::timeline::ActionTimelineCache::createAction(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocostudio::timeline::ActionTimeline*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - JS_ReportError(cx, "js_cocos2dx_studio_ActionTimelineCache_createAction : wrong number of arguments"); - return false; -} - -bool js_cocos2dx_studio_ActionTimelineCache_getInstance(JSContext *cx, uint32_t argc, jsval *vp) -{ - if (argc == 0) { - cocostudio::timeline::ActionTimelineCache* ret = cocostudio::timeline::ActionTimelineCache::getInstance(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocostudio::timeline::ActionTimelineCache*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ComRender"); } - } while (0); - JS_SET_RVAL(cx, vp, jsret); + } while(0); + + do { + if (argc == 0) { + cobj = new (std::nothrow) cocostudio::ComRender(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + obj = JS_NewObject(cx, typeClass->jsclass, proto, parent); + + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ComRender"); + } + } while(0); + + if (cobj) { + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + + args.rval().set(OBJECT_TO_JSVAL(obj)); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_ActionTimelineCache_getInstance : wrong number of arguments"); + JS_ReportError(cx, "js_cocos2dx_studio_ComRender_constructor : wrong number of arguments"); return false; } +extern JSObject *jsb_cocos2d_Component_prototype; -void js_cocostudio_timeline_ActionTimelineCache_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (ActionTimelineCache)", obj); +void js_cocostudio_ComRender_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (ComRender)", obj); } -void js_register_cocos2dx_studio_ActionTimelineCache(JSContext *cx, JSObject *global) { - jsb_cocostudio_timeline_ActionTimelineCache_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocostudio_timeline_ActionTimelineCache_class->name = "ActionTimelineCache"; - jsb_cocostudio_timeline_ActionTimelineCache_class->addProperty = JS_PropertyStub; - jsb_cocostudio_timeline_ActionTimelineCache_class->delProperty = JS_DeletePropertyStub; - jsb_cocostudio_timeline_ActionTimelineCache_class->getProperty = JS_PropertyStub; - jsb_cocostudio_timeline_ActionTimelineCache_class->setProperty = JS_StrictPropertyStub; - jsb_cocostudio_timeline_ActionTimelineCache_class->enumerate = JS_EnumerateStub; - jsb_cocostudio_timeline_ActionTimelineCache_class->resolve = JS_ResolveStub; - jsb_cocostudio_timeline_ActionTimelineCache_class->convert = JS_ConvertStub; - jsb_cocostudio_timeline_ActionTimelineCache_class->finalize = js_cocostudio_timeline_ActionTimelineCache_finalize; - jsb_cocostudio_timeline_ActionTimelineCache_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); +void js_register_cocos2dx_studio_ComRender(JSContext *cx, JS::HandleObject global) { + jsb_cocostudio_ComRender_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocostudio_ComRender_class->name = "ComRender"; + jsb_cocostudio_ComRender_class->addProperty = JS_PropertyStub; + jsb_cocostudio_ComRender_class->delProperty = JS_DeletePropertyStub; + jsb_cocostudio_ComRender_class->getProperty = JS_PropertyStub; + jsb_cocostudio_ComRender_class->setProperty = JS_StrictPropertyStub; + jsb_cocostudio_ComRender_class->enumerate = JS_EnumerateStub; + jsb_cocostudio_ComRender_class->resolve = JS_ResolveStub; + jsb_cocostudio_ComRender_class->convert = JS_ConvertStub; + jsb_cocostudio_ComRender_class->finalize = js_cocostudio_ComRender_finalize; + jsb_cocostudio_ComRender_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("createActionFromJson", js_cocos2dx_studio_ActionTimelineCache_createActionFromJson, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("purge", js_cocos2dx_studio_ActionTimelineCache_purge, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_studio_ActionTimelineCache_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("loadAnimationActionWithFile", js_cocos2dx_studio_ActionTimelineCache_loadAnimationActionWithFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("loadAnimationActionWithContent", js_cocos2dx_studio_ActionTimelineCache_loadAnimationActionWithContent, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("removeAction", js_cocos2dx_studio_ActionTimelineCache_removeAction, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getNode", js_cocos2dx_studio_ComRender_getNode, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setNode", js_cocos2dx_studio_ComRender_setNode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { - JS_FN("destroyInstance", js_cocos2dx_studio_ActionTimelineCache_destroyInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("createAction", js_cocos2dx_studio_ActionTimelineCache_createAction, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getInstance", js_cocos2dx_studio_ActionTimelineCache_getInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("create", js_cocos2dx_studio_ComRender_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; - jsb_cocostudio_timeline_ActionTimelineCache_prototype = JS_InitClass( + jsb_cocostudio_ComRender_prototype = JS_InitClass( cx, global, - NULL, // parent proto - jsb_cocostudio_timeline_ActionTimelineCache_class, - empty_constructor, 0, + JS::RootedObject(cx, jsb_cocos2d_Component_prototype), + jsb_cocostudio_ComRender_class, + js_cocos2dx_studio_ComRender_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -8707,18 +8582,18 @@ void js_register_cocos2dx_studio_ActionTimelineCache(JSContext *cx, JSObject *gl // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "ActionTimelineCache", JSPROP_ENUMERATE | JSPROP_READONLY, &found); +// JS_SetPropertyAttributes(cx, global, "ComRender", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; + TypeTest t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocostudio_timeline_ActionTimelineCache_class; - p->proto = jsb_cocostudio_timeline_ActionTimelineCache_prototype; - p->parentProto = NULL; + p->jsclass = jsb_cocostudio_ComRender_class; + p->proto = jsb_cocostudio_ComRender_prototype; + p->parentProto = jsb_cocos2d_Component_prototype; _js_global_type_map.insert(std::make_pair(typeName, p)); } } @@ -8728,7 +8603,8 @@ JSObject *jsb_cocostudio_timeline_Frame_prototype; bool js_cocos2dx_studio_Frame_clone(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Frame* cobj = (cocostudio::timeline::Frame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Frame_clone : Invalid Native Object"); @@ -8743,7 +8619,7 @@ bool js_cocos2dx_studio_Frame_clone(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8752,25 +8628,25 @@ bool js_cocos2dx_studio_Frame_clone(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Frame_setNode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Frame* cobj = (cocostudio::timeline::Frame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Frame_setNode : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Frame_setNode : Error processing arguments"); cobj->setNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8779,25 +8655,25 @@ bool js_cocos2dx_studio_Frame_setNode(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Frame_setTimeline(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Frame* cobj = (cocostudio::timeline::Frame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Frame_setTimeline : Invalid Native Object"); if (argc == 1) { cocostudio::timeline::Timeline* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::timeline::Timeline*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Frame_setTimeline : Error processing arguments"); cobj->setTimeline(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8806,7 +8682,8 @@ bool js_cocos2dx_studio_Frame_setTimeline(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_Frame_isEnterWhenPassed(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Frame* cobj = (cocostudio::timeline::Frame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Frame_isEnterWhenPassed : Invalid Native Object"); @@ -8814,7 +8691,7 @@ bool js_cocos2dx_studio_Frame_isEnterWhenPassed(JSContext *cx, uint32_t argc, js bool ret = cobj->isEnterWhenPassed(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8823,7 +8700,8 @@ bool js_cocos2dx_studio_Frame_isEnterWhenPassed(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_studio_Frame_getFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Frame* cobj = (cocostudio::timeline::Frame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Frame_getFrameIndex : Invalid Native Object"); @@ -8831,7 +8709,7 @@ bool js_cocos2dx_studio_Frame_getFrameIndex(JSContext *cx, uint32_t argc, jsval unsigned int ret = cobj->getFrameIndex(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8840,18 +8718,18 @@ bool js_cocos2dx_studio_Frame_getFrameIndex(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_Frame_apply(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Frame* cobj = (cocostudio::timeline::Frame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Frame_apply : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Frame_apply : Error processing arguments"); cobj->apply(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8860,7 +8738,8 @@ bool js_cocos2dx_studio_Frame_apply(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Frame_isTween(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Frame* cobj = (cocostudio::timeline::Frame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Frame_isTween : Invalid Native Object"); @@ -8868,7 +8747,7 @@ bool js_cocos2dx_studio_Frame_isTween(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isTween(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8877,18 +8756,18 @@ bool js_cocos2dx_studio_Frame_isTween(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Frame_setFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Frame* cobj = (cocostudio::timeline::Frame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Frame_setFrameIndex : Invalid Native Object"); if (argc == 1) { unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Frame_setFrameIndex : Error processing arguments"); cobj->setFrameIndex(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8897,18 +8776,18 @@ bool js_cocos2dx_studio_Frame_setFrameIndex(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_Frame_setTween(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Frame* cobj = (cocostudio::timeline::Frame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Frame_setTween : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Frame_setTween : Error processing arguments"); cobj->setTween(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8917,7 +8796,8 @@ bool js_cocos2dx_studio_Frame_setTween(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Frame_getTimeline(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Frame* cobj = (cocostudio::timeline::Frame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Frame_getTimeline : Invalid Native Object"); @@ -8932,7 +8812,7 @@ bool js_cocos2dx_studio_Frame_getTimeline(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8941,7 +8821,8 @@ bool js_cocos2dx_studio_Frame_getTimeline(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_Frame_getNode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Frame* cobj = (cocostudio::timeline::Frame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Frame_getNode : Invalid Native Object"); @@ -8956,7 +8837,7 @@ bool js_cocos2dx_studio_Frame_getNode(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8969,7 +8850,7 @@ void js_cocostudio_timeline_Frame_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Frame)", obj); } -void js_register_cocos2dx_studio_Frame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_Frame(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_Frame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_Frame_class->name = "Frame"; jsb_cocostudio_timeline_Frame_class->addProperty = JS_PropertyStub; @@ -8983,8 +8864,8 @@ void js_register_cocos2dx_studio_Frame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_Frame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -9006,7 +8887,7 @@ void js_register_cocos2dx_studio_Frame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_Frame_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_timeline_Frame_class, dummy_constructor, 0, // no constructor properties, @@ -9037,7 +8918,8 @@ JSObject *jsb_cocostudio_timeline_VisibleFrame_prototype; bool js_cocos2dx_studio_VisibleFrame_isVisible(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::VisibleFrame* cobj = (cocostudio::timeline::VisibleFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_VisibleFrame_isVisible : Invalid Native Object"); @@ -9045,7 +8927,7 @@ bool js_cocos2dx_studio_VisibleFrame_isVisible(JSContext *cx, uint32_t argc, jsv bool ret = cobj->isVisible(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9054,18 +8936,18 @@ bool js_cocos2dx_studio_VisibleFrame_isVisible(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_studio_VisibleFrame_setVisible(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::VisibleFrame* cobj = (cocostudio::timeline::VisibleFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_VisibleFrame_setVisible : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_VisibleFrame_setVisible : Error processing arguments"); cobj->setVisible(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9074,6 +8956,7 @@ bool js_cocos2dx_studio_VisibleFrame_setVisible(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_studio_VisibleFrame_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::timeline::VisibleFrame* ret = cocostudio::timeline::VisibleFrame::create(); jsval jsret = JSVAL_NULL; @@ -9085,7 +8968,7 @@ bool js_cocos2dx_studio_VisibleFrame_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_VisibleFrame_create : wrong number of arguments"); @@ -9094,7 +8977,7 @@ bool js_cocos2dx_studio_VisibleFrame_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_studio_VisibleFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::timeline::VisibleFrame* cobj = new (std::nothrow) cocostudio::timeline::VisibleFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -9108,13 +8991,16 @@ bool js_cocos2dx_studio_VisibleFrame_constructor(JSContext *cx, uint32_t argc, j CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::VisibleFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::VisibleFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -9125,7 +9011,7 @@ void js_cocostudio_timeline_VisibleFrame_finalize(JSFreeOp *fop, JSObject *obj) CCLOGINFO("jsbindings: finalizing JS object %p (VisibleFrame)", obj); } -void js_register_cocos2dx_studio_VisibleFrame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_VisibleFrame(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_VisibleFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_VisibleFrame_class->name = "VisibleFrame"; jsb_cocostudio_timeline_VisibleFrame_class->addProperty = JS_PropertyStub; @@ -9139,8 +9025,8 @@ void js_register_cocos2dx_studio_VisibleFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_VisibleFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -9156,7 +9042,7 @@ void js_register_cocos2dx_studio_VisibleFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_VisibleFrame_prototype = JS_InitClass( cx, global, - jsb_cocostudio_timeline_Frame_prototype, + JS::RootedObject(cx, jsb_cocostudio_timeline_Frame_prototype), jsb_cocostudio_timeline_VisibleFrame_class, js_cocos2dx_studio_VisibleFrame_constructor, 0, // constructor properties, @@ -9187,7 +9073,8 @@ JSObject *jsb_cocostudio_timeline_TextureFrame_prototype; bool js_cocos2dx_studio_TextureFrame_getTextureName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::TextureFrame* cobj = (cocostudio::timeline::TextureFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_TextureFrame_getTextureName : Invalid Native Object"); @@ -9195,54 +9082,27 @@ bool js_cocos2dx_studio_TextureFrame_getTextureName(JSContext *cx, uint32_t argc std::string ret = cobj->getTextureName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_TextureFrame_getTextureName : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_studio_TextureFrame_setNode(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::timeline::TextureFrame* cobj = (cocostudio::timeline::TextureFrame *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_TextureFrame_setNode : Invalid Native Object"); - if (argc == 1) { - cocos2d::Node* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_TextureFrame_setNode : Error processing arguments"); - cobj->setNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_TextureFrame_setNode : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_studio_TextureFrame_setTextureName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::TextureFrame* cobj = (cocostudio::timeline::TextureFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_TextureFrame_setTextureName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_TextureFrame_setTextureName : Error processing arguments"); cobj->setTextureName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9251,6 +9111,7 @@ bool js_cocos2dx_studio_TextureFrame_setTextureName(JSContext *cx, uint32_t argc } bool js_cocos2dx_studio_TextureFrame_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::timeline::TextureFrame* ret = cocostudio::timeline::TextureFrame::create(); jsval jsret = JSVAL_NULL; @@ -9262,7 +9123,7 @@ bool js_cocos2dx_studio_TextureFrame_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_TextureFrame_create : wrong number of arguments"); @@ -9271,7 +9132,7 @@ bool js_cocos2dx_studio_TextureFrame_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_studio_TextureFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::timeline::TextureFrame* cobj = new (std::nothrow) cocostudio::timeline::TextureFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -9285,13 +9146,16 @@ bool js_cocos2dx_studio_TextureFrame_constructor(JSContext *cx, uint32_t argc, j CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::TextureFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::TextureFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -9302,7 +9166,7 @@ void js_cocostudio_timeline_TextureFrame_finalize(JSFreeOp *fop, JSObject *obj) CCLOGINFO("jsbindings: finalizing JS object %p (TextureFrame)", obj); } -void js_register_cocos2dx_studio_TextureFrame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_TextureFrame(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_TextureFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_TextureFrame_class->name = "TextureFrame"; jsb_cocostudio_timeline_TextureFrame_class->addProperty = JS_PropertyStub; @@ -9316,13 +9180,12 @@ void js_register_cocos2dx_studio_TextureFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_TextureFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getTextureName", js_cocos2dx_studio_TextureFrame_getTextureName, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setNode", js_cocos2dx_studio_TextureFrame_setNode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setTextureName", js_cocos2dx_studio_TextureFrame_setTextureName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -9334,7 +9197,7 @@ void js_register_cocos2dx_studio_TextureFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_TextureFrame_prototype = JS_InitClass( cx, global, - jsb_cocostudio_timeline_Frame_prototype, + JS::RootedObject(cx, jsb_cocostudio_timeline_Frame_prototype), jsb_cocostudio_timeline_TextureFrame_class, js_cocos2dx_studio_TextureFrame_constructor, 0, // constructor properties, @@ -9365,18 +9228,18 @@ JSObject *jsb_cocostudio_timeline_RotationFrame_prototype; bool js_cocos2dx_studio_RotationFrame_setRotation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::RotationFrame* cobj = (cocostudio::timeline::RotationFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_RotationFrame_setRotation : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_RotationFrame_setRotation : Error processing arguments"); cobj->setRotation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9385,7 +9248,8 @@ bool js_cocos2dx_studio_RotationFrame_setRotation(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_RotationFrame_getRotation(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::RotationFrame* cobj = (cocostudio::timeline::RotationFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_RotationFrame_getRotation : Invalid Native Object"); @@ -9393,7 +9257,7 @@ bool js_cocos2dx_studio_RotationFrame_getRotation(JSContext *cx, uint32_t argc, double ret = cobj->getRotation(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9402,6 +9266,7 @@ bool js_cocos2dx_studio_RotationFrame_getRotation(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_RotationFrame_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::timeline::RotationFrame* ret = cocostudio::timeline::RotationFrame::create(); jsval jsret = JSVAL_NULL; @@ -9413,7 +9278,7 @@ bool js_cocos2dx_studio_RotationFrame_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_RotationFrame_create : wrong number of arguments"); @@ -9422,7 +9287,7 @@ bool js_cocos2dx_studio_RotationFrame_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_studio_RotationFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::timeline::RotationFrame* cobj = new (std::nothrow) cocostudio::timeline::RotationFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -9436,13 +9301,16 @@ bool js_cocos2dx_studio_RotationFrame_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::RotationFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::RotationFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -9453,7 +9321,7 @@ void js_cocostudio_timeline_RotationFrame_finalize(JSFreeOp *fop, JSObject *obj) CCLOGINFO("jsbindings: finalizing JS object %p (RotationFrame)", obj); } -void js_register_cocos2dx_studio_RotationFrame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_RotationFrame(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_RotationFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_RotationFrame_class->name = "RotationFrame"; jsb_cocostudio_timeline_RotationFrame_class->addProperty = JS_PropertyStub; @@ -9467,8 +9335,8 @@ void js_register_cocos2dx_studio_RotationFrame(JSContext *cx, JSObject *global) jsb_cocostudio_timeline_RotationFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -9484,7 +9352,7 @@ void js_register_cocos2dx_studio_RotationFrame(JSContext *cx, JSObject *global) jsb_cocostudio_timeline_RotationFrame_prototype = JS_InitClass( cx, global, - jsb_cocostudio_timeline_Frame_prototype, + JS::RootedObject(cx, jsb_cocostudio_timeline_Frame_prototype), jsb_cocostudio_timeline_RotationFrame_class, js_cocos2dx_studio_RotationFrame_constructor, 0, // constructor properties, @@ -9515,7 +9383,8 @@ JSObject *jsb_cocostudio_timeline_SkewFrame_prototype; bool js_cocos2dx_studio_SkewFrame_getSkewY(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::SkewFrame* cobj = (cocostudio::timeline::SkewFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_SkewFrame_getSkewY : Invalid Native Object"); @@ -9523,7 +9392,7 @@ bool js_cocos2dx_studio_SkewFrame_getSkewY(JSContext *cx, uint32_t argc, jsval * double ret = cobj->getSkewY(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9532,18 +9401,18 @@ bool js_cocos2dx_studio_SkewFrame_getSkewY(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_SkewFrame_setSkewX(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::SkewFrame* cobj = (cocostudio::timeline::SkewFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_SkewFrame_setSkewX : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_SkewFrame_setSkewX : Error processing arguments"); cobj->setSkewX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9552,18 +9421,18 @@ bool js_cocos2dx_studio_SkewFrame_setSkewX(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_SkewFrame_setSkewY(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::SkewFrame* cobj = (cocostudio::timeline::SkewFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_SkewFrame_setSkewY : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_SkewFrame_setSkewY : Error processing arguments"); cobj->setSkewY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9572,7 +9441,8 @@ bool js_cocos2dx_studio_SkewFrame_setSkewY(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_SkewFrame_getSkewX(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::SkewFrame* cobj = (cocostudio::timeline::SkewFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_SkewFrame_getSkewX : Invalid Native Object"); @@ -9580,7 +9450,7 @@ bool js_cocos2dx_studio_SkewFrame_getSkewX(JSContext *cx, uint32_t argc, jsval * double ret = cobj->getSkewX(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9589,6 +9459,7 @@ bool js_cocos2dx_studio_SkewFrame_getSkewX(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_SkewFrame_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::timeline::SkewFrame* ret = cocostudio::timeline::SkewFrame::create(); jsval jsret = JSVAL_NULL; @@ -9600,7 +9471,7 @@ bool js_cocos2dx_studio_SkewFrame_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_SkewFrame_create : wrong number of arguments"); @@ -9609,7 +9480,7 @@ bool js_cocos2dx_studio_SkewFrame_create(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_studio_SkewFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::timeline::SkewFrame* cobj = new (std::nothrow) cocostudio::timeline::SkewFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -9623,13 +9494,16 @@ bool js_cocos2dx_studio_SkewFrame_constructor(JSContext *cx, uint32_t argc, jsva CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::SkewFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::SkewFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -9640,7 +9514,7 @@ void js_cocostudio_timeline_SkewFrame_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (SkewFrame)", obj); } -void js_register_cocos2dx_studio_SkewFrame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_SkewFrame(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_SkewFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_SkewFrame_class->name = "SkewFrame"; jsb_cocostudio_timeline_SkewFrame_class->addProperty = JS_PropertyStub; @@ -9654,8 +9528,8 @@ void js_register_cocos2dx_studio_SkewFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_SkewFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -9673,7 +9547,7 @@ void js_register_cocos2dx_studio_SkewFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_SkewFrame_prototype = JS_InitClass( cx, global, - jsb_cocostudio_timeline_Frame_prototype, + JS::RootedObject(cx, jsb_cocostudio_timeline_Frame_prototype), jsb_cocostudio_timeline_SkewFrame_class, js_cocos2dx_studio_SkewFrame_constructor, 0, // constructor properties, @@ -9704,6 +9578,7 @@ JSObject *jsb_cocostudio_timeline_RotationSkewFrame_prototype; bool js_cocos2dx_studio_RotationSkewFrame_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::timeline::RotationSkewFrame* ret = cocostudio::timeline::RotationSkewFrame::create(); jsval jsret = JSVAL_NULL; @@ -9715,7 +9590,7 @@ bool js_cocos2dx_studio_RotationSkewFrame_create(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_RotationSkewFrame_create : wrong number of arguments"); @@ -9724,7 +9599,7 @@ bool js_cocos2dx_studio_RotationSkewFrame_create(JSContext *cx, uint32_t argc, j bool js_cocos2dx_studio_RotationSkewFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::timeline::RotationSkewFrame* cobj = new (std::nothrow) cocostudio::timeline::RotationSkewFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -9738,13 +9613,16 @@ bool js_cocos2dx_studio_RotationSkewFrame_constructor(JSContext *cx, uint32_t ar CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::RotationSkewFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::RotationSkewFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -9755,7 +9633,7 @@ void js_cocostudio_timeline_RotationSkewFrame_finalize(JSFreeOp *fop, JSObject * CCLOGINFO("jsbindings: finalizing JS object %p (RotationSkewFrame)", obj); } -void js_register_cocos2dx_studio_RotationSkewFrame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_RotationSkewFrame(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_RotationSkewFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_RotationSkewFrame_class->name = "RotationSkewFrame"; jsb_cocostudio_timeline_RotationSkewFrame_class->addProperty = JS_PropertyStub; @@ -9769,8 +9647,8 @@ void js_register_cocos2dx_studio_RotationSkewFrame(JSContext *cx, JSObject *glob jsb_cocostudio_timeline_RotationSkewFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -9784,7 +9662,7 @@ void js_register_cocos2dx_studio_RotationSkewFrame(JSContext *cx, JSObject *glob jsb_cocostudio_timeline_RotationSkewFrame_prototype = JS_InitClass( cx, global, - jsb_cocostudio_timeline_SkewFrame_prototype, + JS::RootedObject(cx, jsb_cocostudio_timeline_SkewFrame_prototype), jsb_cocostudio_timeline_RotationSkewFrame_class, js_cocos2dx_studio_RotationSkewFrame_constructor, 0, // constructor properties, @@ -9815,7 +9693,8 @@ JSObject *jsb_cocostudio_timeline_PositionFrame_prototype; bool js_cocos2dx_studio_PositionFrame_getX(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::PositionFrame* cobj = (cocostudio::timeline::PositionFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_PositionFrame_getX : Invalid Native Object"); @@ -9823,7 +9702,7 @@ bool js_cocos2dx_studio_PositionFrame_getX(JSContext *cx, uint32_t argc, jsval * double ret = cobj->getX(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9832,7 +9711,8 @@ bool js_cocos2dx_studio_PositionFrame_getX(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_PositionFrame_getY(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::PositionFrame* cobj = (cocostudio::timeline::PositionFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_PositionFrame_getY : Invalid Native Object"); @@ -9840,7 +9720,7 @@ bool js_cocos2dx_studio_PositionFrame_getY(JSContext *cx, uint32_t argc, jsval * double ret = cobj->getY(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9849,18 +9729,18 @@ bool js_cocos2dx_studio_PositionFrame_getY(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_PositionFrame_setPosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::PositionFrame* cobj = (cocostudio::timeline::PositionFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_PositionFrame_setPosition : Invalid Native Object"); if (argc == 1) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_PositionFrame_setPosition : Error processing arguments"); cobj->setPosition(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9869,18 +9749,18 @@ bool js_cocos2dx_studio_PositionFrame_setPosition(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_PositionFrame_setX(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::PositionFrame* cobj = (cocostudio::timeline::PositionFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_PositionFrame_setX : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_PositionFrame_setX : Error processing arguments"); cobj->setX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9889,18 +9769,18 @@ bool js_cocos2dx_studio_PositionFrame_setX(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_PositionFrame_setY(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::PositionFrame* cobj = (cocostudio::timeline::PositionFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_PositionFrame_setY : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_PositionFrame_setY : Error processing arguments"); cobj->setY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9909,7 +9789,8 @@ bool js_cocos2dx_studio_PositionFrame_setY(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_PositionFrame_getPosition(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::PositionFrame* cobj = (cocostudio::timeline::PositionFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_PositionFrame_getPosition : Invalid Native Object"); @@ -9917,7 +9798,7 @@ bool js_cocos2dx_studio_PositionFrame_getPosition(JSContext *cx, uint32_t argc, cocos2d::Point ret = cobj->getPosition(); jsval jsret = JSVAL_NULL; jsret = ccpoint_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9926,6 +9807,7 @@ bool js_cocos2dx_studio_PositionFrame_getPosition(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_PositionFrame_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::timeline::PositionFrame* ret = cocostudio::timeline::PositionFrame::create(); jsval jsret = JSVAL_NULL; @@ -9937,7 +9819,7 @@ bool js_cocos2dx_studio_PositionFrame_create(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_PositionFrame_create : wrong number of arguments"); @@ -9946,7 +9828,7 @@ bool js_cocos2dx_studio_PositionFrame_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_studio_PositionFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::timeline::PositionFrame* cobj = new (std::nothrow) cocostudio::timeline::PositionFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -9960,13 +9842,16 @@ bool js_cocos2dx_studio_PositionFrame_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::PositionFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::PositionFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -9977,7 +9862,7 @@ void js_cocostudio_timeline_PositionFrame_finalize(JSFreeOp *fop, JSObject *obj) CCLOGINFO("jsbindings: finalizing JS object %p (PositionFrame)", obj); } -void js_register_cocos2dx_studio_PositionFrame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_PositionFrame(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_PositionFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_PositionFrame_class->name = "PositionFrame"; jsb_cocostudio_timeline_PositionFrame_class->addProperty = JS_PropertyStub; @@ -9991,8 +9876,8 @@ void js_register_cocos2dx_studio_PositionFrame(JSContext *cx, JSObject *global) jsb_cocostudio_timeline_PositionFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -10012,7 +9897,7 @@ void js_register_cocos2dx_studio_PositionFrame(JSContext *cx, JSObject *global) jsb_cocostudio_timeline_PositionFrame_prototype = JS_InitClass( cx, global, - jsb_cocostudio_timeline_Frame_prototype, + JS::RootedObject(cx, jsb_cocostudio_timeline_Frame_prototype), jsb_cocostudio_timeline_PositionFrame_class, js_cocos2dx_studio_PositionFrame_constructor, 0, // constructor properties, @@ -10043,18 +9928,18 @@ JSObject *jsb_cocostudio_timeline_ScaleFrame_prototype; bool js_cocos2dx_studio_ScaleFrame_setScaleY(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ScaleFrame* cobj = (cocostudio::timeline::ScaleFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ScaleFrame_setScaleY : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ScaleFrame_setScaleY : Error processing arguments"); cobj->setScaleY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10063,18 +9948,18 @@ bool js_cocos2dx_studio_ScaleFrame_setScaleY(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ScaleFrame_setScaleX(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ScaleFrame* cobj = (cocostudio::timeline::ScaleFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ScaleFrame_setScaleX : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ScaleFrame_setScaleX : Error processing arguments"); cobj->setScaleX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10083,7 +9968,8 @@ bool js_cocos2dx_studio_ScaleFrame_setScaleX(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ScaleFrame_getScaleY(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ScaleFrame* cobj = (cocostudio::timeline::ScaleFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ScaleFrame_getScaleY : Invalid Native Object"); @@ -10091,7 +9977,7 @@ bool js_cocos2dx_studio_ScaleFrame_getScaleY(JSContext *cx, uint32_t argc, jsval double ret = cobj->getScaleY(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10100,7 +9986,8 @@ bool js_cocos2dx_studio_ScaleFrame_getScaleY(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ScaleFrame_getScaleX(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ScaleFrame* cobj = (cocostudio::timeline::ScaleFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ScaleFrame_getScaleX : Invalid Native Object"); @@ -10108,7 +9995,7 @@ bool js_cocos2dx_studio_ScaleFrame_getScaleX(JSContext *cx, uint32_t argc, jsval double ret = cobj->getScaleX(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10117,18 +10004,18 @@ bool js_cocos2dx_studio_ScaleFrame_getScaleX(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ScaleFrame_setScale(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ScaleFrame* cobj = (cocostudio::timeline::ScaleFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ScaleFrame_setScale : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ScaleFrame_setScale : Error processing arguments"); cobj->setScale(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10137,6 +10024,7 @@ bool js_cocos2dx_studio_ScaleFrame_setScale(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ScaleFrame_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::timeline::ScaleFrame* ret = cocostudio::timeline::ScaleFrame::create(); jsval jsret = JSVAL_NULL; @@ -10148,7 +10036,7 @@ bool js_cocos2dx_studio_ScaleFrame_create(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ScaleFrame_create : wrong number of arguments"); @@ -10157,7 +10045,7 @@ bool js_cocos2dx_studio_ScaleFrame_create(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_studio_ScaleFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::timeline::ScaleFrame* cobj = new (std::nothrow) cocostudio::timeline::ScaleFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10171,13 +10059,16 @@ bool js_cocos2dx_studio_ScaleFrame_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::ScaleFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::ScaleFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -10188,7 +10079,7 @@ void js_cocostudio_timeline_ScaleFrame_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ScaleFrame)", obj); } -void js_register_cocos2dx_studio_ScaleFrame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ScaleFrame(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_ScaleFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_ScaleFrame_class->name = "ScaleFrame"; jsb_cocostudio_timeline_ScaleFrame_class->addProperty = JS_PropertyStub; @@ -10202,8 +10093,8 @@ void js_register_cocos2dx_studio_ScaleFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_ScaleFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -10222,7 +10113,7 @@ void js_register_cocos2dx_studio_ScaleFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_ScaleFrame_prototype = JS_InitClass( cx, global, - jsb_cocostudio_timeline_Frame_prototype, + JS::RootedObject(cx, jsb_cocostudio_timeline_Frame_prototype), jsb_cocostudio_timeline_ScaleFrame_class, js_cocos2dx_studio_ScaleFrame_constructor, 0, // constructor properties, @@ -10253,18 +10144,18 @@ JSObject *jsb_cocostudio_timeline_AnchorPointFrame_prototype; bool js_cocos2dx_studio_AnchorPointFrame_setAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::AnchorPointFrame* cobj = (cocostudio::timeline::AnchorPointFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_AnchorPointFrame_setAnchorPoint : Invalid Native Object"); if (argc == 1) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_AnchorPointFrame_setAnchorPoint : Error processing arguments"); cobj->setAnchorPoint(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10273,7 +10164,8 @@ bool js_cocos2dx_studio_AnchorPointFrame_setAnchorPoint(JSContext *cx, uint32_t } bool js_cocos2dx_studio_AnchorPointFrame_getAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::AnchorPointFrame* cobj = (cocostudio::timeline::AnchorPointFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_AnchorPointFrame_getAnchorPoint : Invalid Native Object"); @@ -10281,7 +10173,7 @@ bool js_cocos2dx_studio_AnchorPointFrame_getAnchorPoint(JSContext *cx, uint32_t cocos2d::Point ret = cobj->getAnchorPoint(); jsval jsret = JSVAL_NULL; jsret = ccpoint_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10290,6 +10182,7 @@ bool js_cocos2dx_studio_AnchorPointFrame_getAnchorPoint(JSContext *cx, uint32_t } bool js_cocos2dx_studio_AnchorPointFrame_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::timeline::AnchorPointFrame* ret = cocostudio::timeline::AnchorPointFrame::create(); jsval jsret = JSVAL_NULL; @@ -10301,7 +10194,7 @@ bool js_cocos2dx_studio_AnchorPointFrame_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_AnchorPointFrame_create : wrong number of arguments"); @@ -10310,7 +10203,7 @@ bool js_cocos2dx_studio_AnchorPointFrame_create(JSContext *cx, uint32_t argc, js bool js_cocos2dx_studio_AnchorPointFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::timeline::AnchorPointFrame* cobj = new (std::nothrow) cocostudio::timeline::AnchorPointFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10324,13 +10217,16 @@ bool js_cocos2dx_studio_AnchorPointFrame_constructor(JSContext *cx, uint32_t arg CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::AnchorPointFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::AnchorPointFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -10341,7 +10237,7 @@ void js_cocostudio_timeline_AnchorPointFrame_finalize(JSFreeOp *fop, JSObject *o CCLOGINFO("jsbindings: finalizing JS object %p (AnchorPointFrame)", obj); } -void js_register_cocos2dx_studio_AnchorPointFrame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_AnchorPointFrame(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_AnchorPointFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_AnchorPointFrame_class->name = "AnchorPointFrame"; jsb_cocostudio_timeline_AnchorPointFrame_class->addProperty = JS_PropertyStub; @@ -10355,8 +10251,8 @@ void js_register_cocos2dx_studio_AnchorPointFrame(JSContext *cx, JSObject *globa jsb_cocostudio_timeline_AnchorPointFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -10372,7 +10268,7 @@ void js_register_cocos2dx_studio_AnchorPointFrame(JSContext *cx, JSObject *globa jsb_cocostudio_timeline_AnchorPointFrame_prototype = JS_InitClass( cx, global, - jsb_cocostudio_timeline_Frame_prototype, + JS::RootedObject(cx, jsb_cocostudio_timeline_Frame_prototype), jsb_cocostudio_timeline_AnchorPointFrame_class, js_cocos2dx_studio_AnchorPointFrame_constructor, 0, // constructor properties, @@ -10401,9 +10297,46 @@ void js_register_cocos2dx_studio_AnchorPointFrame(JSContext *cx, JSObject *globa JSClass *jsb_cocostudio_timeline_InnerActionFrame_class; JSObject *jsb_cocostudio_timeline_InnerActionFrame_prototype; +bool js_cocos2dx_studio_InnerActionFrame_getEndFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::timeline::InnerActionFrame* cobj = (cocostudio::timeline::InnerActionFrame *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InnerActionFrame_getEndFrameIndex : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getEndFrameIndex(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_InnerActionFrame_getEndFrameIndex : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_studio_InnerActionFrame_getStartFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::timeline::InnerActionFrame* cobj = (cocostudio::timeline::InnerActionFrame *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InnerActionFrame_getStartFrameIndex : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getStartFrameIndex(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_InnerActionFrame_getStartFrameIndex : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_studio_InnerActionFrame_getInnerActionType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::InnerActionFrame* cobj = (cocostudio::timeline::InnerActionFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InnerActionFrame_getInnerActionType : Invalid Native Object"); @@ -10411,72 +10344,154 @@ bool js_cocos2dx_studio_InnerActionFrame_getInnerActionType(JSContext *cx, uint3 int ret = (int)cobj->getInnerActionType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_InnerActionFrame_getInnerActionType : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_studio_InnerActionFrame_setEndFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::timeline::InnerActionFrame* cobj = (cocostudio::timeline::InnerActionFrame *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InnerActionFrame_setEndFrameIndex : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_InnerActionFrame_setEndFrameIndex : Error processing arguments"); + cobj->setEndFrameIndex(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_InnerActionFrame_setEndFrameIndex : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_studio_InnerActionFrame_setEnterWithName(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::timeline::InnerActionFrame* cobj = (cocostudio::timeline::InnerActionFrame *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InnerActionFrame_setEnterWithName : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_InnerActionFrame_setEnterWithName : Error processing arguments"); + cobj->setEnterWithName(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_InnerActionFrame_setEnterWithName : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_studio_InnerActionFrame_setSingleFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::timeline::InnerActionFrame* cobj = (cocostudio::timeline::InnerActionFrame *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InnerActionFrame_setSingleFrameIndex : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_InnerActionFrame_setSingleFrameIndex : Error processing arguments"); + cobj->setSingleFrameIndex(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_InnerActionFrame_setSingleFrameIndex : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_studio_InnerActionFrame_setStartFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::InnerActionFrame* cobj = (cocostudio::timeline::InnerActionFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InnerActionFrame_setStartFrameIndex : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_InnerActionFrame_setStartFrameIndex : Error processing arguments"); cobj->setStartFrameIndex(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_studio_InnerActionFrame_setStartFrameIndex : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_studio_InnerActionFrame_getSingleFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::timeline::InnerActionFrame* cobj = (cocostudio::timeline::InnerActionFrame *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InnerActionFrame_getSingleFrameIndex : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getSingleFrameIndex(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_InnerActionFrame_getSingleFrameIndex : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_studio_InnerActionFrame_setInnerActionType(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::InnerActionFrame* cobj = (cocostudio::timeline::InnerActionFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InnerActionFrame_setInnerActionType : Invalid Native Object"); if (argc == 1) { cocostudio::timeline::InnerActionType arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_InnerActionFrame_setInnerActionType : Error processing arguments"); cobj->setInnerActionType(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_studio_InnerActionFrame_setInnerActionType : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_studio_InnerActionFrame_getStartFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_InnerActionFrame_setAnimationName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::InnerActionFrame* cobj = (cocostudio::timeline::InnerActionFrame *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InnerActionFrame_getStartFrameIndex : Invalid Native Object"); - if (argc == 0) { - int ret = cobj->getStartFrameIndex(); - jsval jsret = JSVAL_NULL; - jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_InnerActionFrame_setAnimationName : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_InnerActionFrame_setAnimationName : Error processing arguments"); + cobj->setAnimationName(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_InnerActionFrame_getStartFrameIndex : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_studio_InnerActionFrame_setAnimationName : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_studio_InnerActionFrame_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::timeline::InnerActionFrame* ret = cocostudio::timeline::InnerActionFrame::create(); jsval jsret = JSVAL_NULL; @@ -10488,7 +10503,7 @@ bool js_cocos2dx_studio_InnerActionFrame_create(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_InnerActionFrame_create : wrong number of arguments"); @@ -10497,7 +10512,7 @@ bool js_cocos2dx_studio_InnerActionFrame_create(JSContext *cx, uint32_t argc, js bool js_cocos2dx_studio_InnerActionFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::timeline::InnerActionFrame* cobj = new (std::nothrow) cocostudio::timeline::InnerActionFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10511,13 +10526,16 @@ bool js_cocos2dx_studio_InnerActionFrame_constructor(JSContext *cx, uint32_t arg CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::InnerActionFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::InnerActionFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -10528,7 +10546,7 @@ void js_cocostudio_timeline_InnerActionFrame_finalize(JSFreeOp *fop, JSObject *o CCLOGINFO("jsbindings: finalizing JS object %p (InnerActionFrame)", obj); } -void js_register_cocos2dx_studio_InnerActionFrame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_InnerActionFrame(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_InnerActionFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_InnerActionFrame_class->name = "InnerActionFrame"; jsb_cocostudio_timeline_InnerActionFrame_class->addProperty = JS_PropertyStub; @@ -10542,15 +10560,21 @@ void js_register_cocos2dx_studio_InnerActionFrame(JSContext *cx, JSObject *globa jsb_cocostudio_timeline_InnerActionFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { + JS_FN("getEndFrameIndex", js_cocos2dx_studio_InnerActionFrame_getEndFrameIndex, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getStartFrameIndex", js_cocos2dx_studio_InnerActionFrame_getStartFrameIndex, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getInnerActionType", js_cocos2dx_studio_InnerActionFrame_getInnerActionType, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setEndFrameIndex", js_cocos2dx_studio_InnerActionFrame_setEndFrameIndex, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setEnterWithName", js_cocos2dx_studio_InnerActionFrame_setEnterWithName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setSingleFrameIndex", js_cocos2dx_studio_InnerActionFrame_setSingleFrameIndex, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setStartFrameIndex", js_cocos2dx_studio_InnerActionFrame_setStartFrameIndex, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getSingleFrameIndex", js_cocos2dx_studio_InnerActionFrame_getSingleFrameIndex, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setInnerActionType", js_cocos2dx_studio_InnerActionFrame_setInnerActionType, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getStartFrameIndex", js_cocos2dx_studio_InnerActionFrame_getStartFrameIndex, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setAnimationName", js_cocos2dx_studio_InnerActionFrame_setAnimationName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -10561,7 +10585,7 @@ void js_register_cocos2dx_studio_InnerActionFrame(JSContext *cx, JSObject *globa jsb_cocostudio_timeline_InnerActionFrame_prototype = JS_InitClass( cx, global, - jsb_cocostudio_timeline_Frame_prototype, + JS::RootedObject(cx, jsb_cocostudio_timeline_Frame_prototype), jsb_cocostudio_timeline_InnerActionFrame_class, js_cocos2dx_studio_InnerActionFrame_constructor, 0, // constructor properties, @@ -10590,26 +10614,10 @@ void js_register_cocos2dx_studio_InnerActionFrame(JSContext *cx, JSObject *globa JSClass *jsb_cocostudio_timeline_ColorFrame_class; JSObject *jsb_cocostudio_timeline_ColorFrame_prototype; -bool js_cocos2dx_studio_ColorFrame_getAlpha(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::timeline::ColorFrame* cobj = (cocostudio::timeline::ColorFrame *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ColorFrame_getAlpha : Invalid Native Object"); - if (argc == 0) { - uint16_t ret = cobj->getAlpha(); - jsval jsret = JSVAL_NULL; - jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ColorFrame_getAlpha : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} bool js_cocos2dx_studio_ColorFrame_getColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ColorFrame* cobj = (cocostudio::timeline::ColorFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ColorFrame_getColor : Invalid Native Object"); @@ -10617,47 +10625,27 @@ bool js_cocos2dx_studio_ColorFrame_getColor(JSContext *cx, uint32_t argc, jsval cocos2d::Color3B ret = cobj->getColor(); jsval jsret = JSVAL_NULL; jsret = cccolor3b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ColorFrame_getColor : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_studio_ColorFrame_setAlpha(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocostudio::timeline::ColorFrame* cobj = (cocostudio::timeline::ColorFrame *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ColorFrame_setAlpha : Invalid Native Object"); - if (argc == 1) { - uint16_t arg0; - ok &= jsval_to_uint16(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ColorFrame_setAlpha : Error processing arguments"); - cobj->setAlpha(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_ColorFrame_setAlpha : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_studio_ColorFrame_setColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ColorFrame* cobj = (cocostudio::timeline::ColorFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ColorFrame_setColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ColorFrame_setColor : Error processing arguments"); cobj->setColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10666,6 +10654,7 @@ bool js_cocos2dx_studio_ColorFrame_setColor(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ColorFrame_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::timeline::ColorFrame* ret = cocostudio::timeline::ColorFrame::create(); jsval jsret = JSVAL_NULL; @@ -10677,7 +10666,7 @@ bool js_cocos2dx_studio_ColorFrame_create(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ColorFrame_create : wrong number of arguments"); @@ -10686,7 +10675,7 @@ bool js_cocos2dx_studio_ColorFrame_create(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_studio_ColorFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::timeline::ColorFrame* cobj = new (std::nothrow) cocostudio::timeline::ColorFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10700,13 +10689,16 @@ bool js_cocos2dx_studio_ColorFrame_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::ColorFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::ColorFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -10717,7 +10709,7 @@ void js_cocostudio_timeline_ColorFrame_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ColorFrame)", obj); } -void js_register_cocos2dx_studio_ColorFrame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ColorFrame(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_ColorFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_ColorFrame_class->name = "ColorFrame"; jsb_cocostudio_timeline_ColorFrame_class->addProperty = JS_PropertyStub; @@ -10731,14 +10723,12 @@ void js_register_cocos2dx_studio_ColorFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_ColorFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("getAlpha", js_cocos2dx_studio_ColorFrame_getAlpha, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getColor", js_cocos2dx_studio_ColorFrame_getColor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setAlpha", js_cocos2dx_studio_ColorFrame_setAlpha, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setColor", js_cocos2dx_studio_ColorFrame_setColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -10750,7 +10740,7 @@ void js_register_cocos2dx_studio_ColorFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_ColorFrame_prototype = JS_InitClass( cx, global, - jsb_cocostudio_timeline_Frame_prototype, + JS::RootedObject(cx, jsb_cocostudio_timeline_Frame_prototype), jsb_cocostudio_timeline_ColorFrame_class, js_cocos2dx_studio_ColorFrame_constructor, 0, // constructor properties, @@ -10760,17 +10750,172 @@ void js_register_cocos2dx_studio_ColorFrame(JSContext *cx, JSObject *global) { // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "ColorFrame", JSPROP_ENUMERATE | JSPROP_READONLY, &found); +// JS_SetPropertyAttributes(cx, global, "ColorFrame", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocostudio_timeline_ColorFrame_class; + p->proto = jsb_cocostudio_timeline_ColorFrame_prototype; + p->parentProto = jsb_cocostudio_timeline_Frame_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocostudio_timeline_AlphaFrame_class; +JSObject *jsb_cocostudio_timeline_AlphaFrame_prototype; + +bool js_cocos2dx_studio_AlphaFrame_getAlpha(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::timeline::AlphaFrame* cobj = (cocostudio::timeline::AlphaFrame *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_AlphaFrame_getAlpha : Invalid Native Object"); + if (argc == 0) { + uint16_t ret = cobj->getAlpha(); + jsval jsret = JSVAL_NULL; + jsret = uint32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_AlphaFrame_getAlpha : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_studio_AlphaFrame_setAlpha(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::timeline::AlphaFrame* cobj = (cocostudio::timeline::AlphaFrame *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_AlphaFrame_setAlpha : Invalid Native Object"); + if (argc == 1) { + uint16_t arg0; + ok &= jsval_to_uint16(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_AlphaFrame_setAlpha : Error processing arguments"); + cobj->setAlpha(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_AlphaFrame_setAlpha : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_studio_AlphaFrame_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (argc == 0) { + cocostudio::timeline::AlphaFrame* ret = cocostudio::timeline::AlphaFrame::create(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocostudio::timeline::AlphaFrame*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_studio_AlphaFrame_create : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_studio_AlphaFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocostudio::timeline::AlphaFrame* cobj = new (std::nothrow) cocostudio::timeline::AlphaFrame(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::AlphaFrame"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocostudio_timeline_Frame_prototype; + +void js_cocostudio_timeline_AlphaFrame_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (AlphaFrame)", obj); +} + +void js_register_cocos2dx_studio_AlphaFrame(JSContext *cx, JS::HandleObject global) { + jsb_cocostudio_timeline_AlphaFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocostudio_timeline_AlphaFrame_class->name = "AlphaFrame"; + jsb_cocostudio_timeline_AlphaFrame_class->addProperty = JS_PropertyStub; + jsb_cocostudio_timeline_AlphaFrame_class->delProperty = JS_DeletePropertyStub; + jsb_cocostudio_timeline_AlphaFrame_class->getProperty = JS_PropertyStub; + jsb_cocostudio_timeline_AlphaFrame_class->setProperty = JS_StrictPropertyStub; + jsb_cocostudio_timeline_AlphaFrame_class->enumerate = JS_EnumerateStub; + jsb_cocostudio_timeline_AlphaFrame_class->resolve = JS_ResolveStub; + jsb_cocostudio_timeline_AlphaFrame_class->convert = JS_ConvertStub; + jsb_cocostudio_timeline_AlphaFrame_class->finalize = js_cocostudio_timeline_AlphaFrame_finalize; + jsb_cocostudio_timeline_AlphaFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("getAlpha", js_cocos2dx_studio_AlphaFrame_getAlpha, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setAlpha", js_cocos2dx_studio_AlphaFrame_setAlpha, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_studio_AlphaFrame_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocostudio_timeline_AlphaFrame_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocostudio_timeline_Frame_prototype), + jsb_cocostudio_timeline_AlphaFrame_class, + js_cocos2dx_studio_AlphaFrame_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "AlphaFrame", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; + TypeTest t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocostudio_timeline_ColorFrame_class; - p->proto = jsb_cocostudio_timeline_ColorFrame_prototype; + p->jsclass = jsb_cocostudio_timeline_AlphaFrame_class; + p->proto = jsb_cocostudio_timeline_AlphaFrame_prototype; p->parentProto = jsb_cocostudio_timeline_Frame_prototype; _js_global_type_map.insert(std::make_pair(typeName, p)); } @@ -10781,18 +10926,18 @@ JSObject *jsb_cocostudio_timeline_EventFrame_prototype; bool js_cocos2dx_studio_EventFrame_setEvent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::EventFrame* cobj = (cocostudio::timeline::EventFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_EventFrame_setEvent : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_EventFrame_setEvent : Error processing arguments"); cobj->setEvent(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10801,13 +10946,14 @@ bool js_cocos2dx_studio_EventFrame_setEvent(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_EventFrame_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::EventFrame* cobj = (cocostudio::timeline::EventFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_EventFrame_init : Invalid Native Object"); if (argc == 0) { cobj->init(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10816,7 +10962,8 @@ bool js_cocos2dx_studio_EventFrame_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_EventFrame_getEvent(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::EventFrame* cobj = (cocostudio::timeline::EventFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_EventFrame_getEvent : Invalid Native Object"); @@ -10824,7 +10971,7 @@ bool js_cocos2dx_studio_EventFrame_getEvent(JSContext *cx, uint32_t argc, jsval std::string ret = cobj->getEvent(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10833,6 +10980,7 @@ bool js_cocos2dx_studio_EventFrame_getEvent(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_EventFrame_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::timeline::EventFrame* ret = cocostudio::timeline::EventFrame::create(); jsval jsret = JSVAL_NULL; @@ -10844,7 +10992,7 @@ bool js_cocos2dx_studio_EventFrame_create(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_EventFrame_create : wrong number of arguments"); @@ -10853,7 +11001,7 @@ bool js_cocos2dx_studio_EventFrame_create(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_studio_EventFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::timeline::EventFrame* cobj = new (std::nothrow) cocostudio::timeline::EventFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10867,13 +11015,16 @@ bool js_cocos2dx_studio_EventFrame_constructor(JSContext *cx, uint32_t argc, jsv CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::EventFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::EventFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -10884,7 +11035,7 @@ void js_cocostudio_timeline_EventFrame_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (EventFrame)", obj); } -void js_register_cocos2dx_studio_EventFrame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_EventFrame(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_EventFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_EventFrame_class->name = "EventFrame"; jsb_cocostudio_timeline_EventFrame_class->addProperty = JS_PropertyStub; @@ -10898,8 +11049,8 @@ void js_register_cocos2dx_studio_EventFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_EventFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -10916,7 +11067,7 @@ void js_register_cocos2dx_studio_EventFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_EventFrame_prototype = JS_InitClass( cx, global, - jsb_cocostudio_timeline_Frame_prototype, + JS::RootedObject(cx, jsb_cocostudio_timeline_Frame_prototype), jsb_cocostudio_timeline_EventFrame_class, js_cocos2dx_studio_EventFrame_constructor, 0, // constructor properties, @@ -10947,7 +11098,8 @@ JSObject *jsb_cocostudio_timeline_ZOrderFrame_prototype; bool js_cocos2dx_studio_ZOrderFrame_getZOrder(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ZOrderFrame* cobj = (cocostudio::timeline::ZOrderFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ZOrderFrame_getZOrder : Invalid Native Object"); @@ -10955,7 +11107,7 @@ bool js_cocos2dx_studio_ZOrderFrame_getZOrder(JSContext *cx, uint32_t argc, jsva int ret = cobj->getZOrder(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10964,18 +11116,18 @@ bool js_cocos2dx_studio_ZOrderFrame_getZOrder(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_ZOrderFrame_setZOrder(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ZOrderFrame* cobj = (cocostudio::timeline::ZOrderFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ZOrderFrame_setZOrder : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ZOrderFrame_setZOrder : Error processing arguments"); cobj->setZOrder(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10984,6 +11136,7 @@ bool js_cocos2dx_studio_ZOrderFrame_setZOrder(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_ZOrderFrame_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::timeline::ZOrderFrame* ret = cocostudio::timeline::ZOrderFrame::create(); jsval jsret = JSVAL_NULL; @@ -10995,7 +11148,7 @@ bool js_cocos2dx_studio_ZOrderFrame_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ZOrderFrame_create : wrong number of arguments"); @@ -11004,7 +11157,7 @@ bool js_cocos2dx_studio_ZOrderFrame_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_studio_ZOrderFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::timeline::ZOrderFrame* cobj = new (std::nothrow) cocostudio::timeline::ZOrderFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -11018,13 +11171,16 @@ bool js_cocos2dx_studio_ZOrderFrame_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::ZOrderFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::ZOrderFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -11035,7 +11191,7 @@ void js_cocostudio_timeline_ZOrderFrame_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ZOrderFrame)", obj); } -void js_register_cocos2dx_studio_ZOrderFrame(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ZOrderFrame(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_ZOrderFrame_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_ZOrderFrame_class->name = "ZOrderFrame"; jsb_cocostudio_timeline_ZOrderFrame_class->addProperty = JS_PropertyStub; @@ -11049,8 +11205,8 @@ void js_register_cocos2dx_studio_ZOrderFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_ZOrderFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -11066,7 +11222,7 @@ void js_register_cocos2dx_studio_ZOrderFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_ZOrderFrame_prototype = JS_InitClass( cx, global, - jsb_cocostudio_timeline_Frame_prototype, + JS::RootedObject(cx, jsb_cocostudio_timeline_Frame_prototype), jsb_cocostudio_timeline_ZOrderFrame_class, js_cocos2dx_studio_ZOrderFrame_constructor, 0, // constructor properties, @@ -11097,7 +11253,8 @@ JSObject *jsb_cocostudio_timeline_Timeline_prototype; bool js_cocos2dx_studio_Timeline_clone(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Timeline* cobj = (cocostudio::timeline::Timeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Timeline_clone : Invalid Native Object"); @@ -11112,7 +11269,7 @@ bool js_cocos2dx_studio_Timeline_clone(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11121,18 +11278,18 @@ bool js_cocos2dx_studio_Timeline_clone(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_Timeline_gotoFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Timeline* cobj = (cocostudio::timeline::Timeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Timeline_gotoFrame : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Timeline_gotoFrame : Error processing arguments"); cobj->gotoFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11141,25 +11298,25 @@ bool js_cocos2dx_studio_Timeline_gotoFrame(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_Timeline_setNode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Timeline* cobj = (cocostudio::timeline::Timeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Timeline_setNode : Invalid Native Object"); if (argc == 1) { cocos2d::Node* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Timeline_setNode : Error processing arguments"); cobj->setNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11168,7 +11325,8 @@ bool js_cocos2dx_studio_Timeline_setNode(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_studio_Timeline_getActionTimeline(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Timeline* cobj = (cocostudio::timeline::Timeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Timeline_getActionTimeline : Invalid Native Object"); @@ -11183,7 +11341,7 @@ bool js_cocos2dx_studio_Timeline_getActionTimeline(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11192,9 +11350,9 @@ bool js_cocos2dx_studio_Timeline_getActionTimeline(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_Timeline_insertFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Timeline* cobj = (cocostudio::timeline::Timeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Timeline_insertFrame : Invalid Native Object"); @@ -11202,17 +11360,17 @@ bool js_cocos2dx_studio_Timeline_insertFrame(JSContext *cx, uint32_t argc, jsval cocostudio::timeline::Frame* arg0; int arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::timeline::Frame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Timeline_insertFrame : Error processing arguments"); cobj->insertFrame(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11221,18 +11379,18 @@ bool js_cocos2dx_studio_Timeline_insertFrame(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_Timeline_setActionTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Timeline* cobj = (cocostudio::timeline::Timeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Timeline_setActionTag : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Timeline_setActionTag : Error processing arguments"); cobj->setActionTag(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11241,25 +11399,25 @@ bool js_cocos2dx_studio_Timeline_setActionTag(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_Timeline_addFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Timeline* cobj = (cocostudio::timeline::Timeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Timeline_addFrame : Invalid Native Object"); if (argc == 1) { cocostudio::timeline::Frame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::timeline::Frame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Timeline_addFrame : Error processing arguments"); cobj->addFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11268,7 +11426,8 @@ bool js_cocos2dx_studio_Timeline_addFrame(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_Timeline_getFrames(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Timeline* cobj = (cocostudio::timeline::Timeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Timeline_getFrames : Invalid Native Object"); @@ -11276,7 +11435,7 @@ bool js_cocos2dx_studio_Timeline_getFrames(JSContext *cx, uint32_t argc, jsval * const cocos2d::Vector& ret = cobj->getFrames(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11285,7 +11444,8 @@ bool js_cocos2dx_studio_Timeline_getFrames(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_studio_Timeline_getActionTag(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Timeline* cobj = (cocostudio::timeline::Timeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Timeline_getActionTag : Invalid Native Object"); @@ -11293,7 +11453,7 @@ bool js_cocos2dx_studio_Timeline_getActionTag(JSContext *cx, uint32_t argc, jsva int ret = cobj->getActionTag(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11302,7 +11462,8 @@ bool js_cocos2dx_studio_Timeline_getActionTag(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_Timeline_getNode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Timeline* cobj = (cocostudio::timeline::Timeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Timeline_getNode : Invalid Native Object"); @@ -11317,7 +11478,7 @@ bool js_cocos2dx_studio_Timeline_getNode(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11326,25 +11487,25 @@ bool js_cocos2dx_studio_Timeline_getNode(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_studio_Timeline_removeFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Timeline* cobj = (cocostudio::timeline::Timeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Timeline_removeFrame : Invalid Native Object"); if (argc == 1) { cocostudio::timeline::Frame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::timeline::Frame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Timeline_removeFrame : Error processing arguments"); cobj->removeFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11353,25 +11514,25 @@ bool js_cocos2dx_studio_Timeline_removeFrame(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_Timeline_setActionTimeline(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Timeline* cobj = (cocostudio::timeline::Timeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Timeline_setActionTimeline : Invalid Native Object"); if (argc == 1) { cocostudio::timeline::ActionTimeline* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::timeline::ActionTimeline*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Timeline_setActionTimeline : Error processing arguments"); cobj->setActionTimeline(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11380,18 +11541,18 @@ bool js_cocos2dx_studio_Timeline_setActionTimeline(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_Timeline_stepToFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::Timeline* cobj = (cocostudio::timeline::Timeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_Timeline_stepToFrame : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_Timeline_stepToFrame : Error processing arguments"); cobj->stepToFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11400,6 +11561,7 @@ bool js_cocos2dx_studio_Timeline_stepToFrame(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_Timeline_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::timeline::Timeline* ret = cocostudio::timeline::Timeline::create(); jsval jsret = JSVAL_NULL; @@ -11411,7 +11573,7 @@ bool js_cocos2dx_studio_Timeline_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_Timeline_create : wrong number of arguments"); @@ -11420,7 +11582,7 @@ bool js_cocos2dx_studio_Timeline_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_studio_Timeline_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::timeline::Timeline* cobj = new (std::nothrow) cocostudio::timeline::Timeline(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -11434,13 +11596,16 @@ bool js_cocos2dx_studio_Timeline_constructor(JSContext *cx, uint32_t argc, jsval CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::Timeline"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::Timeline"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -11450,7 +11615,7 @@ void js_cocostudio_timeline_Timeline_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Timeline)", obj); } -void js_register_cocos2dx_studio_Timeline(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_Timeline(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_Timeline_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_Timeline_class->name = "Timeline"; jsb_cocostudio_timeline_Timeline_class->addProperty = JS_PropertyStub; @@ -11464,8 +11629,8 @@ void js_register_cocos2dx_studio_Timeline(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_Timeline_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -11492,7 +11657,7 @@ void js_register_cocos2dx_studio_Timeline(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_Timeline_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_timeline_Timeline_class, js_cocos2dx_studio_Timeline_constructor, 0, // constructor properties, @@ -11523,27 +11688,50 @@ JSObject *jsb_cocostudio_timeline_ActionTimelineData_prototype; bool js_cocos2dx_studio_ActionTimelineData_setActionTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimelineData* cobj = (cocostudio::timeline::ActionTimelineData *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimelineData_setActionTag : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimelineData_setActionTag : Error processing arguments"); cobj->setActionTag(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ActionTimelineData_setActionTag : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_studio_ActionTimelineData_init(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::timeline::ActionTimelineData* cobj = (cocostudio::timeline::ActionTimelineData *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimelineData_init : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimelineData_init : Error processing arguments"); + bool ret = cobj->init(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_ActionTimelineData_init : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_studio_ActionTimelineData_getActionTag(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimelineData* cobj = (cocostudio::timeline::ActionTimelineData *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimelineData_getActionTag : Invalid Native Object"); @@ -11551,7 +11739,7 @@ bool js_cocos2dx_studio_ActionTimelineData_getActionTag(JSContext *cx, uint32_t int ret = cobj->getActionTag(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11560,11 +11748,11 @@ bool js_cocos2dx_studio_ActionTimelineData_getActionTag(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ActionTimelineData_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimelineData_create : Error processing arguments"); cocostudio::timeline::ActionTimelineData* ret = cocostudio::timeline::ActionTimelineData::create(arg0); jsval jsret = JSVAL_NULL; @@ -11576,20 +11764,49 @@ bool js_cocos2dx_studio_ActionTimelineData_create(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ActionTimelineData_create : wrong number of arguments"); return false; } +bool js_cocos2dx_studio_ActionTimelineData_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocostudio::timeline::ActionTimelineData* cobj = new (std::nothrow) cocostudio::timeline::ActionTimelineData(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::ActionTimelineData"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + void js_cocostudio_timeline_ActionTimelineData_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (ActionTimelineData)", obj); } -void js_register_cocos2dx_studio_ActionTimelineData(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ActionTimelineData(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_ActionTimelineData_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_ActionTimelineData_class->name = "ActionTimelineData"; jsb_cocostudio_timeline_ActionTimelineData_class->addProperty = JS_PropertyStub; @@ -11603,12 +11820,13 @@ void js_register_cocos2dx_studio_ActionTimelineData(JSContext *cx, JSObject *glo jsb_cocostudio_timeline_ActionTimelineData_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("setActionTag", js_cocos2dx_studio_ActionTimelineData_setActionTag, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("init", js_cocos2dx_studio_ActionTimelineData_init, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getActionTag", js_cocos2dx_studio_ActionTimelineData_getActionTag, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -11620,9 +11838,9 @@ void js_register_cocos2dx_studio_ActionTimelineData(JSContext *cx, JSObject *glo jsb_cocostudio_timeline_ActionTimelineData_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_timeline_ActionTimelineData_class, - dummy_constructor, 0, // no constructor + js_cocos2dx_studio_ActionTimelineData_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -11651,19 +11869,20 @@ JSObject *jsb_cocostudio_timeline_ActionTimeline_prototype; bool js_cocos2dx_studio_ActionTimeline_setFrameEventCallFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_setFrameEventCallFunc : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=](cocostudio::timeline::Frame* larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -11673,8 +11892,8 @@ bool js_cocos2dx_studio_ActionTimeline_setFrameEventCallFunc(JSContext *cx, uint largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -11689,7 +11908,7 @@ bool js_cocos2dx_studio_ActionTimeline_setFrameEventCallFunc(JSContext *cx, uint ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimeline_setFrameEventCallFunc : Error processing arguments"); cobj->setFrameEventCallFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11698,25 +11917,25 @@ bool js_cocos2dx_studio_ActionTimeline_setFrameEventCallFunc(JSContext *cx, uint } bool js_cocos2dx_studio_ActionTimeline_addTimeline(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_addTimeline : Invalid Native Object"); if (argc == 1) { cocostudio::timeline::Timeline* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::timeline::Timeline*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimeline_addTimeline : Error processing arguments"); cobj->addTimeline(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11725,7 +11944,8 @@ bool js_cocos2dx_studio_ActionTimeline_addTimeline(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_ActionTimeline_getCurrentFrame(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_getCurrentFrame : Invalid Native Object"); @@ -11733,7 +11953,7 @@ bool js_cocos2dx_studio_ActionTimeline_getCurrentFrame(JSContext *cx, uint32_t a int ret = cobj->getCurrentFrame(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11742,7 +11962,8 @@ bool js_cocos2dx_studio_ActionTimeline_getCurrentFrame(JSContext *cx, uint32_t a } bool js_cocos2dx_studio_ActionTimeline_getStartFrame(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_getStartFrame : Invalid Native Object"); @@ -11750,7 +11971,7 @@ bool js_cocos2dx_studio_ActionTimeline_getStartFrame(JSContext *cx, uint32_t arg int ret = cobj->getStartFrame(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11759,13 +11980,14 @@ bool js_cocos2dx_studio_ActionTimeline_getStartFrame(JSContext *cx, uint32_t arg } bool js_cocos2dx_studio_ActionTimeline_pause(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_pause : Invalid Native Object"); if (argc == 0) { cobj->pause(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11774,7 +11996,8 @@ bool js_cocos2dx_studio_ActionTimeline_pause(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ActionTimeline_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_init : Invalid Native Object"); @@ -11782,7 +12005,7 @@ bool js_cocos2dx_studio_ActionTimeline_init(JSContext *cx, uint32_t argc, jsval bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11791,48 +12014,65 @@ bool js_cocos2dx_studio_ActionTimeline_init(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ActionTimeline_removeTimeline(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_removeTimeline : Invalid Native Object"); if (argc == 1) { cocostudio::timeline::Timeline* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocostudio::timeline::Timeline*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimeline_removeTimeline : Error processing arguments"); cobj->removeTimeline(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ActionTimeline_removeTimeline : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_studio_ActionTimeline_clearFrameEventCallFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_clearFrameEventCallFunc : Invalid Native Object"); + if (argc == 0) { + cobj->clearFrameEventCallFunc(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_ActionTimeline_clearFrameEventCallFunc : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_studio_ActionTimeline_setLastFrameCallFunc(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_setLastFrameCallFunc : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=]() -> void { - jsval rval; - bool ok = func->invoke(0, nullptr, rval); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + JS::RootedValue rval(cx); + bool ok = func->invoke(0, nullptr, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -11847,7 +12087,7 @@ bool js_cocos2dx_studio_ActionTimeline_setLastFrameCallFunc(JSContext *cx, uint3 ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimeline_setLastFrameCallFunc : Error processing arguments"); cobj->setLastFrameCallFunc(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11856,7 +12096,8 @@ bool js_cocos2dx_studio_ActionTimeline_setLastFrameCallFunc(JSContext *cx, uint3 } bool js_cocos2dx_studio_ActionTimeline_getTimelines(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_getTimelines : Invalid Native Object"); @@ -11864,31 +12105,97 @@ bool js_cocos2dx_studio_ActionTimeline_getTimelines(JSContext *cx, uint32_t argc const cocos2d::Vector& ret = cobj->getTimelines(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ActionTimeline_getTimelines : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_studio_ActionTimeline_play(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_play : Invalid Native Object"); + if (argc == 2) { + std::string arg0; + bool arg1; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + arg1 = JS::ToBoolean(args.get(1)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimeline_play : Error processing arguments"); + cobj->play(arg0, arg1); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_ActionTimeline_play : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} +bool js_cocos2dx_studio_ActionTimeline_getAnimationInfo(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_getAnimationInfo : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimeline_getAnimationInfo : Error processing arguments"); + cocostudio::timeline::AnimationInfo ret = cobj->getAnimationInfo(arg0); + jsval jsret = JSVAL_NULL; + jsret = animationInfo_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_ActionTimeline_getAnimationInfo : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_studio_ActionTimeline_resume(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_resume : Invalid Native Object"); if (argc == 0) { cobj->resume(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ActionTimeline_resume : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_studio_ActionTimeline_removeAnimationInfo(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_removeAnimationInfo : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimeline_removeAnimationInfo : Error processing arguments"); + cobj->removeAnimationInfo(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_ActionTimeline_removeAnimationInfo : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_studio_ActionTimeline_getTimeSpeed(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_getTimeSpeed : Invalid Native Object"); @@ -11896,16 +12203,37 @@ bool js_cocos2dx_studio_ActionTimeline_getTimeSpeed(JSContext *cx, uint32_t argc double ret = cobj->getTimeSpeed(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ActionTimeline_getTimeSpeed : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_studio_ActionTimeline_addAnimationInfo(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_addAnimationInfo : Invalid Native Object"); + if (argc == 1) { + cocostudio::timeline::AnimationInfo arg0; + ok &= jsval_to_animationInfo(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimeline_addAnimationInfo : Error processing arguments"); + cobj->addAnimationInfo(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_ActionTimeline_addAnimationInfo : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_studio_ActionTimeline_getDuration(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_getDuration : Invalid Native Object"); @@ -11913,7 +12241,7 @@ bool js_cocos2dx_studio_ActionTimeline_getDuration(JSContext *cx, uint32_t argc, int ret = cobj->getDuration(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11922,18 +12250,18 @@ bool js_cocos2dx_studio_ActionTimeline_getDuration(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_ActionTimeline_gotoFrameAndPause(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_gotoFrameAndPause : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimeline_gotoFrameAndPause : Error processing arguments"); cobj->gotoFrameAndPause(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11942,7 +12270,8 @@ bool js_cocos2dx_studio_ActionTimeline_gotoFrameAndPause(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ActionTimeline_isPlaying(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_isPlaying : Invalid Native Object"); @@ -11950,7 +12279,7 @@ bool js_cocos2dx_studio_ActionTimeline_isPlaying(JSContext *cx, uint32_t argc, j bool ret = cobj->isPlaying(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11959,24 +12288,24 @@ bool js_cocos2dx_studio_ActionTimeline_isPlaying(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_studio_ActionTimeline_gotoFrameAndPlay(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocostudio::timeline::ActionTimeline* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_gotoFrameAndPlay : Invalid Native Object"); do { if (argc == 2) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } bool arg1; - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); cobj->gotoFrameAndPlay(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -11984,10 +12313,10 @@ bool js_cocos2dx_studio_ActionTimeline_gotoFrameAndPlay(JSContext *cx, uint32_t do { if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } cobj->gotoFrameAndPlay(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -11995,15 +12324,15 @@ bool js_cocos2dx_studio_ActionTimeline_gotoFrameAndPlay(JSContext *cx, uint32_t do { if (argc == 3) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(args.get(2)); cobj->gotoFrameAndPlay(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -12011,18 +12340,18 @@ bool js_cocos2dx_studio_ActionTimeline_gotoFrameAndPlay(JSContext *cx, uint32_t do { if (argc == 4) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } int arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } bool arg3; - arg3 = JS::ToBoolean(JS::RootedValue(cx, argv[3])); + arg3 = JS::ToBoolean(args.get(3)); cobj->gotoFrameAndPlay(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -12030,24 +12359,32 @@ bool js_cocos2dx_studio_ActionTimeline_gotoFrameAndPlay(JSContext *cx, uint32_t JS_ReportError(cx, "js_cocos2dx_studio_ActionTimeline_gotoFrameAndPlay : wrong number of arguments"); return false; } -bool js_cocos2dx_studio_ActionTimeline_clearFrameEventCallFunc(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ActionTimeline_IsAnimationInfoExists(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_clearFrameEventCallFunc : Invalid Native Object"); - if (argc == 0) { - cobj->clearFrameEventCallFunc(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_IsAnimationInfoExists : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimeline_IsAnimationInfoExists : Error processing arguments"); + bool ret = cobj->IsAnimationInfoExists(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_ActionTimeline_clearFrameEventCallFunc : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_studio_ActionTimeline_IsAnimationInfoExists : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_studio_ActionTimeline_getEndFrame(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_getEndFrame : Invalid Native Object"); @@ -12055,7 +12392,7 @@ bool js_cocos2dx_studio_ActionTimeline_getEndFrame(JSContext *cx, uint32_t argc, int ret = cobj->getEndFrame(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12064,18 +12401,18 @@ bool js_cocos2dx_studio_ActionTimeline_getEndFrame(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_ActionTimeline_setTimeSpeed(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_setTimeSpeed : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimeline_setTimeSpeed : Error processing arguments"); cobj->setTimeSpeed(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12084,13 +12421,14 @@ bool js_cocos2dx_studio_ActionTimeline_setTimeSpeed(JSContext *cx, uint32_t argc } bool js_cocos2dx_studio_ActionTimeline_clearLastFrameCallFunc(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_clearLastFrameCallFunc : Invalid Native Object"); if (argc == 0) { cobj->clearLastFrameCallFunc(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12099,18 +12437,18 @@ bool js_cocos2dx_studio_ActionTimeline_clearLastFrameCallFunc(JSContext *cx, uin } bool js_cocos2dx_studio_ActionTimeline_setDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_setDuration : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimeline_setDuration : Error processing arguments"); cobj->setDuration(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12119,18 +12457,18 @@ bool js_cocos2dx_studio_ActionTimeline_setDuration(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_ActionTimeline_setCurrentFrame(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::timeline::ActionTimeline* cobj = (cocostudio::timeline::ActionTimeline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionTimeline_setCurrentFrame : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionTimeline_setCurrentFrame : Error processing arguments"); cobj->setCurrentFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12139,6 +12477,7 @@ bool js_cocos2dx_studio_ActionTimeline_setCurrentFrame(JSContext *cx, uint32_t a } bool js_cocos2dx_studio_ActionTimeline_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocostudio::timeline::ActionTimeline* ret = cocostudio::timeline::ActionTimeline::create(); jsval jsret = JSVAL_NULL; @@ -12150,7 +12489,7 @@ bool js_cocos2dx_studio_ActionTimeline_create(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_studio_ActionTimeline_create : wrong number of arguments"); @@ -12159,7 +12498,7 @@ bool js_cocos2dx_studio_ActionTimeline_create(JSContext *cx, uint32_t argc, jsva bool js_cocos2dx_studio_ActionTimeline_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocostudio::timeline::ActionTimeline* cobj = new (std::nothrow) cocostudio::timeline::ActionTimeline(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -12173,13 +12512,16 @@ bool js_cocos2dx_studio_ActionTimeline_constructor(JSContext *cx, uint32_t argc, CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::ActionTimeline"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::ActionTimeline"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -12190,7 +12532,7 @@ void js_cocostudio_timeline_ActionTimeline_finalize(JSFreeOp *fop, JSObject *obj CCLOGINFO("jsbindings: finalizing JS object %p (ActionTimeline)", obj); } -void js_register_cocos2dx_studio_ActionTimeline(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_studio_ActionTimeline(JSContext *cx, JS::HandleObject global) { jsb_cocostudio_timeline_ActionTimeline_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocostudio_timeline_ActionTimeline_class->name = "ActionTimeline"; jsb_cocostudio_timeline_ActionTimeline_class->addProperty = JS_PropertyStub; @@ -12204,8 +12546,8 @@ void js_register_cocos2dx_studio_ActionTimeline(JSContext *cx, JSObject *global) jsb_cocostudio_timeline_ActionTimeline_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -12216,15 +12558,20 @@ void js_register_cocos2dx_studio_ActionTimeline(JSContext *cx, JSObject *global) JS_FN("pause", js_cocos2dx_studio_ActionTimeline_pause, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("init", js_cocos2dx_studio_ActionTimeline_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("removeTimeline", js_cocos2dx_studio_ActionTimeline_removeTimeline, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("clearFrameEventCallFunc", js_cocos2dx_studio_ActionTimeline_clearFrameEventCallFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setLastFrameCallFunc", js_cocos2dx_studio_ActionTimeline_setLastFrameCallFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getTimelines", js_cocos2dx_studio_ActionTimeline_getTimelines, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("play", js_cocos2dx_studio_ActionTimeline_play, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getAnimationInfo", js_cocos2dx_studio_ActionTimeline_getAnimationInfo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("resume", js_cocos2dx_studio_ActionTimeline_resume, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("removeAnimationInfo", js_cocos2dx_studio_ActionTimeline_removeAnimationInfo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getTimeSpeed", js_cocos2dx_studio_ActionTimeline_getTimeSpeed, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("addAnimationInfo", js_cocos2dx_studio_ActionTimeline_addAnimationInfo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getDuration", js_cocos2dx_studio_ActionTimeline_getDuration, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("gotoFrameAndPause", js_cocos2dx_studio_ActionTimeline_gotoFrameAndPause, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isPlaying", js_cocos2dx_studio_ActionTimeline_isPlaying, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("gotoFrameAndPlay", js_cocos2dx_studio_ActionTimeline_gotoFrameAndPlay, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("clearFrameEventCallFunc", js_cocos2dx_studio_ActionTimeline_clearFrameEventCallFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("IsAnimationInfoExists", js_cocos2dx_studio_ActionTimeline_IsAnimationInfoExists, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getEndFrame", js_cocos2dx_studio_ActionTimeline_getEndFrame, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setTimeSpeed", js_cocos2dx_studio_ActionTimeline_setTimeSpeed, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("clearLastFrameCallFunc", js_cocos2dx_studio_ActionTimeline_clearLastFrameCallFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -12240,7 +12587,7 @@ void js_register_cocos2dx_studio_ActionTimeline(JSContext *cx, JSObject *global) jsb_cocostudio_timeline_ActionTimeline_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Action_prototype, + JS::RootedObject(cx, jsb_cocos2d_Action_prototype), jsb_cocostudio_timeline_ActionTimeline_class, js_cocos2dx_studio_ActionTimeline_constructor, 0, // constructor properties, @@ -12266,374 +12613,196 @@ void js_register_cocos2dx_studio_ActionTimeline(JSContext *cx, JSObject *global) } } -JSClass *jsb_cocos2d_CSLoader_class; -JSObject *jsb_cocos2d_CSLoader_prototype; - -bool js_cocos2dx_studio_CSLoader_setJsonPath(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::CSLoader* cobj = (cocos2d::CSLoader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_CSLoader_setJsonPath : Invalid Native Object"); - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_CSLoader_setJsonPath : Error processing arguments"); - cobj->setJsonPath(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_CSLoader_setJsonPath : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_CSLoader_createNodeFromJson(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::CSLoader* cobj = (cocos2d::CSLoader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_CSLoader_createNodeFromJson : Invalid Native Object"); - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_CSLoader_createNodeFromJson : Error processing arguments"); - cocos2d::Node* ret = cobj->createNodeFromJson(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Node*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } +JSClass *jsb_cocostudio_ObjectExtensionData_class; +JSObject *jsb_cocostudio_ObjectExtensionData_prototype; - JS_ReportError(cx, "js_cocos2dx_studio_CSLoader_createNodeFromJson : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_CSLoader_loadNodeWithFile(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ObjectExtensionData_setActionTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::CSLoader* cobj = (cocos2d::CSLoader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_CSLoader_loadNodeWithFile : Invalid Native Object"); + cocostudio::ObjectExtensionData* cobj = (cocostudio::ObjectExtensionData *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ObjectExtensionData_setActionTag : Invalid Native Object"); if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_CSLoader_loadNodeWithFile : Error processing arguments"); - cocos2d::Node* ret = cobj->loadNodeWithFile(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Node*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_CSLoader_loadNodeWithFile : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_studio_CSLoader_bindCallback(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::CSLoader* cobj = (cocos2d::CSLoader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_CSLoader_bindCallback : Invalid Native Object"); - if (argc == 4) { - std::string arg0; - std::string arg1; - cocos2d::ui::Widget* arg2; - cocos2d::Node* arg3; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - do { - if (!argv[2].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg2 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); - } while (0); - do { - if (!argv[3].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[3]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg3 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_CSLoader_bindCallback : Error processing arguments"); - bool ret = cobj->bindCallback(arg0, arg1, arg2, arg3); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_CSLoader_bindCallback : wrong number of arguments: %d, was expecting %d", argc, 4); - return false; -} -bool js_cocos2dx_studio_CSLoader_purge(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::CSLoader* cobj = (cocos2d::CSLoader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_CSLoader_purge : Invalid Native Object"); - if (argc == 0) { - cobj->purge(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_studio_CSLoader_purge : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} -bool js_cocos2dx_studio_CSLoader_init(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::CSLoader* cobj = (cocos2d::CSLoader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_CSLoader_init : Invalid Native Object"); - if (argc == 0) { - cobj->init(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ObjectExtensionData_setActionTag : Error processing arguments"); + cobj->setActionTag(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_CSLoader_init : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_studio_ObjectExtensionData_setActionTag : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_studio_CSLoader_loadNodeWithContent(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ObjectExtensionData_setCustomProperty(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::CSLoader* cobj = (cocos2d::CSLoader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_CSLoader_loadNodeWithContent : Invalid Native Object"); + cocostudio::ObjectExtensionData* cobj = (cocostudio::ObjectExtensionData *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ObjectExtensionData_setCustomProperty : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_CSLoader_loadNodeWithContent : Error processing arguments"); - cocos2d::Node* ret = cobj->loadNodeWithContent(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Node*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ObjectExtensionData_setCustomProperty : Error processing arguments"); + cobj->setCustomProperty(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_CSLoader_loadNodeWithContent : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_studio_ObjectExtensionData_setCustomProperty : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_studio_CSLoader_isRecordJsonPath(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ObjectExtensionData_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::CSLoader* cobj = (cocos2d::CSLoader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_CSLoader_isRecordJsonPath : Invalid Native Object"); + cocostudio::ObjectExtensionData* cobj = (cocostudio::ObjectExtensionData *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ObjectExtensionData_init : Invalid Native Object"); if (argc == 0) { - bool ret = cobj->isRecordJsonPath(); + bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_CSLoader_isRecordJsonPath : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_studio_ObjectExtensionData_init : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_studio_CSLoader_getJsonPath(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ObjectExtensionData_getCustomProperty(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::CSLoader* cobj = (cocos2d::CSLoader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_CSLoader_getJsonPath : Invalid Native Object"); + cocostudio::ObjectExtensionData* cobj = (cocostudio::ObjectExtensionData *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ObjectExtensionData_getCustomProperty : Invalid Native Object"); if (argc == 0) { - std::string ret = cobj->getJsonPath(); + std::string ret = cobj->getCustomProperty(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_CSLoader_getJsonPath : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_studio_ObjectExtensionData_getCustomProperty : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_studio_CSLoader_setRecordJsonPath(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ObjectExtensionData_getActionTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::CSLoader* cobj = (cocos2d::CSLoader *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_CSLoader_setRecordJsonPath : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_CSLoader_setRecordJsonPath : Error processing arguments"); - cobj->setRecordJsonPath(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocostudio::ObjectExtensionData* cobj = (cocostudio::ObjectExtensionData *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ObjectExtensionData_getActionTag : Invalid Native Object"); + if (argc == 0) { + const int ret = cobj->getActionTag(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_CSLoader_setRecordJsonPath : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_studio_ObjectExtensionData_getActionTag : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_studio_CSLoader_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ObjectExtensionData_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { - cocos2d::CSLoader::destroyInstance(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - JS_ReportError(cx, "js_cocos2dx_studio_CSLoader_destroyInstance : wrong number of arguments"); - return false; -} - -bool js_cocos2dx_studio_CSLoader_createNode(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_CSLoader_createNode : Error processing arguments"); - cocos2d::Node* ret = cocos2d::CSLoader::createNode(arg0); + cocostudio::ObjectExtensionData* ret = cocostudio::ObjectExtensionData::create(); jsval jsret = JSVAL_NULL; do { if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Node*)ret); + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocostudio::ObjectExtensionData*)ret); jsret = OBJECT_TO_JSVAL(jsProxy->obj); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_studio_CSLoader_createNode : wrong number of arguments"); + JS_ReportError(cx, "js_cocos2dx_studio_ObjectExtensionData_create : wrong number of arguments"); return false; } -bool js_cocos2dx_studio_CSLoader_createTimeline(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_studio_ObjectExtensionData_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_CSLoader_createTimeline : Error processing arguments"); - cocostudio::timeline::ActionTimeline* ret = cocos2d::CSLoader::createTimeline(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocostudio::timeline::ActionTimeline*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - JS_ReportError(cx, "js_cocos2dx_studio_CSLoader_createTimeline : wrong number of arguments"); - return false; -} - -bool js_cocos2dx_studio_CSLoader_getInstance(JSContext *cx, uint32_t argc, jsval *vp) -{ - if (argc == 0) { - cocos2d::CSLoader* ret = cocos2d::CSLoader::getInstance(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::CSLoader*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; + cocostudio::ObjectExtensionData* cobj = new (std::nothrow) cocostudio::ObjectExtensionData(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); } - JS_ReportError(cx, "js_cocos2dx_studio_CSLoader_getInstance : wrong number of arguments"); - return false; + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ObjectExtensionData"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; } -void js_cocos2d_CSLoader_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (CSLoader)", obj); +void js_cocostudio_ObjectExtensionData_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (ObjectExtensionData)", obj); } -void js_register_cocos2dx_studio_CSLoader(JSContext *cx, JSObject *global) { - jsb_cocos2d_CSLoader_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_CSLoader_class->name = "CSLoader"; - jsb_cocos2d_CSLoader_class->addProperty = JS_PropertyStub; - jsb_cocos2d_CSLoader_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_CSLoader_class->getProperty = JS_PropertyStub; - jsb_cocos2d_CSLoader_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_CSLoader_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_CSLoader_class->resolve = JS_ResolveStub; - jsb_cocos2d_CSLoader_class->convert = JS_ConvertStub; - jsb_cocos2d_CSLoader_class->finalize = js_cocos2d_CSLoader_finalize; - jsb_cocos2d_CSLoader_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); +void js_register_cocos2dx_studio_ObjectExtensionData(JSContext *cx, JS::HandleObject global) { + jsb_cocostudio_ObjectExtensionData_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocostudio_ObjectExtensionData_class->name = "ObjectExtensionData"; + jsb_cocostudio_ObjectExtensionData_class->addProperty = JS_PropertyStub; + jsb_cocostudio_ObjectExtensionData_class->delProperty = JS_DeletePropertyStub; + jsb_cocostudio_ObjectExtensionData_class->getProperty = JS_PropertyStub; + jsb_cocostudio_ObjectExtensionData_class->setProperty = JS_StrictPropertyStub; + jsb_cocostudio_ObjectExtensionData_class->enumerate = JS_EnumerateStub; + jsb_cocostudio_ObjectExtensionData_class->resolve = JS_ResolveStub; + jsb_cocostudio_ObjectExtensionData_class->convert = JS_ConvertStub; + jsb_cocostudio_ObjectExtensionData_class->finalize = js_cocostudio_ObjectExtensionData_finalize; + jsb_cocostudio_ObjectExtensionData_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("setJsonPath", js_cocos2dx_studio_CSLoader_setJsonPath, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("createNodeFromJson", js_cocos2dx_studio_CSLoader_createNodeFromJson, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("loadNodeWithFile", js_cocos2dx_studio_CSLoader_loadNodeWithFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("bindCallback", js_cocos2dx_studio_CSLoader_bindCallback, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("purge", js_cocos2dx_studio_CSLoader_purge, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_studio_CSLoader_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("loadNodeWithContent", js_cocos2dx_studio_CSLoader_loadNodeWithContent, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("isRecordJsonPath", js_cocos2dx_studio_CSLoader_isRecordJsonPath, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getJsonPath", js_cocos2dx_studio_CSLoader_getJsonPath, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setRecordJsonPath", js_cocos2dx_studio_CSLoader_setRecordJsonPath, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setActionTag", js_cocos2dx_studio_ObjectExtensionData_setActionTag, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setCustomProperty", js_cocos2dx_studio_ObjectExtensionData_setCustomProperty, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("init", js_cocos2dx_studio_ObjectExtensionData_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getCustomProperty", js_cocos2dx_studio_ObjectExtensionData_getCustomProperty, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getActionTag", js_cocos2dx_studio_ObjectExtensionData_getActionTag, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { - JS_FN("destroyInstance", js_cocos2dx_studio_CSLoader_destroyInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("createNode", js_cocos2dx_studio_CSLoader_createNode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("createTimeline", js_cocos2dx_studio_CSLoader_createTimeline, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getInstance", js_cocos2dx_studio_CSLoader_getInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("create", js_cocos2dx_studio_ObjectExtensionData_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; - jsb_cocos2d_CSLoader_prototype = JS_InitClass( + jsb_cocostudio_ObjectExtensionData_prototype = JS_InitClass( cx, global, - NULL, // parent proto - jsb_cocos2d_CSLoader_class, - empty_constructor, 0, + JS::NullPtr(), // parent proto + jsb_cocostudio_ObjectExtensionData_class, + js_cocos2dx_studio_ObjectExtensionData_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -12641,78 +12810,69 @@ void js_register_cocos2dx_studio_CSLoader(JSContext *cx, JSObject *global) { // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "CSLoader", JSPROP_ENUMERATE | JSPROP_READONLY, &found); +// JS_SetPropertyAttributes(cx, global, "ObjectExtensionData", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; + TypeTest t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_CSLoader_class; - p->proto = jsb_cocos2d_CSLoader_prototype; + p->jsclass = jsb_cocostudio_ObjectExtensionData_class; + p->proto = jsb_cocostudio_ObjectExtensionData_prototype; p->parentProto = NULL; _js_global_type_map.insert(std::make_pair(typeName, p)); } } -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj) { - // first, try to get the ns - JS::RootedValue nsval(cx); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj) { + // Get the ns JS::RootedObject ns(cx); - JS_GetProperty(cx, obj, "ccs", &nsval); - if (nsval == JSVAL_VOID) { - ns = JS_NewObject(cx, NULL, NULL, NULL); - nsval = OBJECT_TO_JSVAL(ns); - JS_SetProperty(cx, obj, "ccs", nsval); - } else { - JS_ValueToObject(cx, nsval, &ns); - } - obj = ns; - - js_register_cocos2dx_studio_Frame(cx, obj); - js_register_cocos2dx_studio_ScaleFrame(cx, obj); - js_register_cocos2dx_studio_ProcessBase(cx, obj); - js_register_cocos2dx_studio_Tween(cx, obj); - js_register_cocos2dx_studio_ActionTimelineCache(cx, obj); - js_register_cocos2dx_studio_SceneReader(cx, obj); - js_register_cocos2dx_studio_ComAudio(cx, obj); - js_register_cocos2dx_studio_ActionTimeline(cx, obj); - js_register_cocos2dx_studio_InnerActionFrame(cx, obj); - js_register_cocos2dx_studio_ActionTimelineData(cx, obj); - js_register_cocos2dx_studio_MovementData(cx, obj); - js_register_cocos2dx_studio_ArmatureDataManager(cx, obj); - js_register_cocos2dx_studio_ColorFrame(cx, obj); - js_register_cocos2dx_studio_ZOrderFrame(cx, obj); - js_register_cocos2dx_studio_Timeline(cx, obj); - js_register_cocos2dx_studio_CSLoader(cx, obj); - js_register_cocos2dx_studio_ColliderBody(cx, obj); - js_register_cocos2dx_studio_InputDelegate(cx, obj); - js_register_cocos2dx_studio_ComController(cx, obj); - js_register_cocos2dx_studio_DecorativeDisplay(cx, obj); - js_register_cocos2dx_studio_SkewFrame(cx, obj); - js_register_cocos2dx_studio_RotationSkewFrame(cx, obj); - js_register_cocos2dx_studio_ColliderFilter(cx, obj); - js_register_cocos2dx_studio_VisibleFrame(cx, obj); - js_register_cocos2dx_studio_PositionFrame(cx, obj); - js_register_cocos2dx_studio_RotationFrame(cx, obj); - js_register_cocos2dx_studio_ColliderDetector(cx, obj); - js_register_cocos2dx_studio_BatchNode(cx, obj); - js_register_cocos2dx_studio_ActionObject(cx, obj); - js_register_cocos2dx_studio_AnimationData(cx, obj); - js_register_cocos2dx_studio_EventFrame(cx, obj); - js_register_cocos2dx_studio_ComRender(cx, obj); - js_register_cocos2dx_studio_DisplayManager(cx, obj); - js_register_cocos2dx_studio_GUIReader(cx, obj); - js_register_cocos2dx_studio_ArmatureAnimation(cx, obj); - js_register_cocos2dx_studio_Armature(cx, obj); - js_register_cocos2dx_studio_ActionManagerEx(cx, obj); - js_register_cocos2dx_studio_Bone(cx, obj); - js_register_cocos2dx_studio_ComAttribute(cx, obj); - js_register_cocos2dx_studio_Skin(cx, obj); - js_register_cocos2dx_studio_AnchorPointFrame(cx, obj); - js_register_cocos2dx_studio_TextureFrame(cx, obj); - js_register_cocos2dx_studio_BaseData(cx, obj); + get_or_create_js_obj(cx, obj, "ccs", &ns); + + js_register_cocos2dx_studio_ObjectExtensionData(cx, ns); + js_register_cocos2dx_studio_Frame(cx, ns); + js_register_cocos2dx_studio_ScaleFrame(cx, ns); + js_register_cocos2dx_studio_ProcessBase(cx, ns); + js_register_cocos2dx_studio_Tween(cx, ns); + js_register_cocos2dx_studio_ContourData(cx, ns); + js_register_cocos2dx_studio_ComAudio(cx, ns); + js_register_cocos2dx_studio_ActionTimeline(cx, ns); + js_register_cocos2dx_studio_InnerActionFrame(cx, ns); + js_register_cocos2dx_studio_ActionTimelineData(cx, ns); + js_register_cocos2dx_studio_MovementData(cx, ns); + js_register_cocos2dx_studio_ArmatureDataManager(cx, ns); + js_register_cocos2dx_studio_ColorFrame(cx, ns); + js_register_cocos2dx_studio_ZOrderFrame(cx, ns); + js_register_cocos2dx_studio_Timeline(cx, ns); + js_register_cocos2dx_studio_ColliderBody(cx, ns); + js_register_cocos2dx_studio_InputDelegate(cx, ns); + js_register_cocos2dx_studio_ComController(cx, ns); + js_register_cocos2dx_studio_DecorativeDisplay(cx, ns); + js_register_cocos2dx_studio_SkewFrame(cx, ns); + js_register_cocos2dx_studio_RotationSkewFrame(cx, ns); + js_register_cocos2dx_studio_ColliderFilter(cx, ns); + js_register_cocos2dx_studio_VisibleFrame(cx, ns); + js_register_cocos2dx_studio_PositionFrame(cx, ns); + js_register_cocos2dx_studio_RotationFrame(cx, ns); + js_register_cocos2dx_studio_ColliderDetector(cx, ns); + js_register_cocos2dx_studio_BatchNode(cx, ns); + js_register_cocos2dx_studio_ActionObject(cx, ns); + js_register_cocos2dx_studio_Skin(cx, ns); + js_register_cocos2dx_studio_EventFrame(cx, ns); + js_register_cocos2dx_studio_ComRender(cx, ns); + js_register_cocos2dx_studio_DisplayManager(cx, ns); + js_register_cocos2dx_studio_ArmatureAnimation(cx, ns); + js_register_cocos2dx_studio_Armature(cx, ns); + js_register_cocos2dx_studio_ActionManagerEx(cx, ns); + js_register_cocos2dx_studio_Bone(cx, ns); + js_register_cocos2dx_studio_ComAttribute(cx, ns); + js_register_cocos2dx_studio_TextureData(cx, ns); + js_register_cocos2dx_studio_AlphaFrame(cx, ns); + js_register_cocos2dx_studio_AnimationData(cx, ns); + js_register_cocos2dx_studio_AnchorPointFrame(cx, ns); + js_register_cocos2dx_studio_TextureFrame(cx, ns); + js_register_cocos2dx_studio_BaseData(cx, ns); } diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_studio_auto.hpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_studio_auto.hpp index edcec9c1e6..72846fce8e 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_studio_auto.hpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_studio_auto.hpp @@ -10,8 +10,8 @@ extern JSObject *jsb_cocostudio_ActionObject_prototype; bool js_cocos2dx_studio_ActionObject_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ActionObject_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ActionObject(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ActionObject(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ActionObject_setCurrentTime(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionObject_pause(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionObject_setName(JSContext *cx, uint32_t argc, jsval *vp); @@ -37,8 +37,8 @@ extern JSObject *jsb_cocostudio_ActionManagerEx_prototype; bool js_cocos2dx_studio_ActionManagerEx_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ActionManagerEx_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ActionManagerEx(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ActionManagerEx(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ActionManagerEx_stopActionByName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionManagerEx_getActionByName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionManagerEx_initWithBinary(JSContext *cx, uint32_t argc, jsval *vp); @@ -52,8 +52,8 @@ extern JSObject *jsb_cocostudio_BaseData_prototype; bool js_cocos2dx_studio_BaseData_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_BaseData_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_BaseData(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_BaseData(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_BaseData_getColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_BaseData_setColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_BaseData_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -64,8 +64,8 @@ extern JSObject *jsb_cocostudio_MovementData_prototype; bool js_cocos2dx_studio_MovementData_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_MovementData_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_MovementData(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_MovementData(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_MovementData_getMovementBoneData(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_MovementData_addMovementBoneData(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_MovementData_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -76,21 +76,46 @@ extern JSObject *jsb_cocostudio_AnimationData_prototype; bool js_cocos2dx_studio_AnimationData_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_AnimationData_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_AnimationData(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_AnimationData(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_AnimationData_getMovement(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_AnimationData_getMovementCount(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_AnimationData_addMovement(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_AnimationData_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_AnimationData_AnimationData(JSContext *cx, uint32_t argc, jsval *vp); +extern JSClass *jsb_cocostudio_ContourData_class; +extern JSObject *jsb_cocostudio_ContourData_prototype; + +bool js_cocos2dx_studio_ContourData_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_studio_ContourData_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_studio_ContourData(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_studio_ContourData_init(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ContourData_addVertex(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ContourData_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ContourData_ContourData(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocostudio_TextureData_class; +extern JSObject *jsb_cocostudio_TextureData_prototype; + +bool js_cocos2dx_studio_TextureData_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_studio_TextureData_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_studio_TextureData(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_studio_TextureData_getContourData(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_TextureData_init(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_TextureData_addContourData(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_TextureData_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_TextureData_TextureData(JSContext *cx, uint32_t argc, jsval *vp); + extern JSClass *jsb_cocostudio_ProcessBase_class; extern JSObject *jsb_cocostudio_ProcessBase_prototype; bool js_cocos2dx_studio_ProcessBase_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ProcessBase_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ProcessBase(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ProcessBase(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ProcessBase_play(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ProcessBase_pause(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ProcessBase_getRawDuration(JSContext *cx, uint32_t argc, jsval *vp); @@ -114,8 +139,8 @@ extern JSObject *jsb_cocostudio_Tween_prototype; bool js_cocos2dx_studio_Tween_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_Tween_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_Tween(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_Tween(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_Tween_getAnimation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_Tween_gotoAndPause(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_Tween_play(JSContext *cx, uint32_t argc, jsval *vp); @@ -130,24 +155,24 @@ extern JSObject *jsb_cocostudio_ColliderFilter_prototype; bool js_cocos2dx_studio_ColliderFilter_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ColliderFilter_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ColliderFilter(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ColliderFilter(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); extern JSClass *jsb_cocostudio_ColliderBody_class; extern JSObject *jsb_cocostudio_ColliderBody_prototype; bool js_cocos2dx_studio_ColliderBody_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ColliderBody_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ColliderBody(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ColliderBody(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); extern JSClass *jsb_cocostudio_ColliderDetector_class; extern JSObject *jsb_cocostudio_ColliderDetector_prototype; bool js_cocos2dx_studio_ColliderDetector_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ColliderDetector_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ColliderDetector(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ColliderDetector(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ColliderDetector_getBone(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ColliderDetector_getActive(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ColliderDetector_getColliderBodyList(JSContext *cx, uint32_t argc, jsval *vp); @@ -163,8 +188,8 @@ extern JSObject *jsb_cocostudio_DecorativeDisplay_prototype; bool js_cocos2dx_studio_DecorativeDisplay_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_DecorativeDisplay_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_DecorativeDisplay(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_DecorativeDisplay(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_DecorativeDisplay_getColliderDetector(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_DecorativeDisplay_getDisplay(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_DecorativeDisplay_setDisplay(JSContext *cx, uint32_t argc, jsval *vp); @@ -179,8 +204,8 @@ extern JSObject *jsb_cocostudio_DisplayManager_prototype; bool js_cocos2dx_studio_DisplayManager_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_DisplayManager_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_DisplayManager(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_DisplayManager(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_DisplayManager_getCurrentDecorativeDisplay(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_DisplayManager_getDisplayRenderNode(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_DisplayManager_getAnchorPointInPoints(JSContext *cx, uint32_t argc, jsval *vp); @@ -211,8 +236,8 @@ extern JSObject *jsb_cocostudio_Bone_prototype; bool js_cocos2dx_studio_Bone_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_Bone_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_Bone(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_Bone(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_Bone_isTransformDirty(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_Bone_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_Bone_isIgnoreMovementBoneData(JSContext *cx, uint32_t argc, jsval *vp); @@ -253,8 +278,8 @@ extern JSObject *jsb_cocostudio_BatchNode_prototype; bool js_cocos2dx_studio_BatchNode_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_BatchNode_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_BatchNode(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_BatchNode(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_BatchNode_create(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocostudio_ArmatureAnimation_class; @@ -262,25 +287,21 @@ extern JSObject *jsb_cocostudio_ArmatureAnimation_prototype; bool js_cocos2dx_studio_ArmatureAnimation_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ArmatureAnimation_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ArmatureAnimation(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ArmatureAnimation(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ArmatureAnimation_getSpeedScale(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ArmatureAnimation_pause(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ArmatureAnimation_setSpeedScale(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ArmatureAnimation_init(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ArmatureAnimation_playWithIndexes(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ArmatureAnimation_play(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ArmatureAnimation_gotoAndPause(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ArmatureAnimation_resume(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ArmatureAnimation_stop(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ArmatureAnimation_update(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ArmatureAnimation_getAnimationData(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ArmatureAnimation_playWithIndex(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ArmatureAnimation_getCurrentMovementID(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ArmatureAnimation_playWithIndexes(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ArmatureAnimation_setAnimationData(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ArmatureAnimation_setSpeedScale(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ArmatureAnimation_getAnimationData(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ArmatureAnimation_gotoAndPlay(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ArmatureAnimation_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ArmatureAnimation_playWithNames(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ArmatureAnimation_getMovementCount(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ArmatureAnimation_playWithIndex(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ArmatureAnimation_getCurrentMovementID(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ArmatureAnimation_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ArmatureAnimation_ArmatureAnimation(JSContext *cx, uint32_t argc, jsval *vp); @@ -289,8 +310,8 @@ extern JSObject *jsb_cocostudio_ArmatureDataManager_prototype; bool js_cocos2dx_studio_ArmatureDataManager_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ArmatureDataManager_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ArmatureDataManager(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ArmatureDataManager(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ArmatureDataManager_getAnimationDatas(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ArmatureDataManager_removeAnimationData(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ArmatureDataManager_addArmatureData(JSContext *cx, uint32_t argc, jsval *vp); @@ -315,8 +336,8 @@ extern JSObject *jsb_cocostudio_Armature_prototype; bool js_cocos2dx_studio_Armature_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_Armature_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_Armature(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_Armature(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_Armature_getBone(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_Armature_changeBoneParent(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_Armature_setAnimation(JSContext *cx, uint32_t argc, jsval *vp); @@ -348,8 +369,8 @@ extern JSObject *jsb_cocostudio_Skin_prototype; bool js_cocos2dx_studio_Skin_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_Skin_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_Skin(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_Skin(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_Skin_getBone(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_Skin_getNodeToWorldTransformAR(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_Skin_getDisplayName(JSContext *cx, uint32_t argc, jsval *vp); @@ -364,26 +385,27 @@ extern JSObject *jsb_cocostudio_ComAttribute_prototype; bool js_cocos2dx_studio_ComAttribute_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ComAttribute_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ComAttribute(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ComAttribute(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ComAttribute_getFloat(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ComAttribute_getBool(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ComAttribute_getString(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ComAttribute_setFloat(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ComAttribute_setString(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ComAttribute_getBool(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ComAttribute_setInt(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ComAttribute_parse(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ComAttribute_getInt(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ComAttribute_setBool(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ComAttribute_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ComAttribute_ComAttribute(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocostudio_ComAudio_class; extern JSObject *jsb_cocostudio_ComAudio_prototype; bool js_cocos2dx_studio_ComAudio_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ComAudio_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ComAudio(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ComAudio(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ComAudio_stopAllEffects(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ComAudio_getEffectsVolume(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ComAudio_stopEffect(JSContext *cx, uint32_t argc, jsval *vp); @@ -411,14 +433,15 @@ bool js_cocos2dx_studio_ComAudio_setEffectsVolume(JSContext *cx, uint32_t argc, bool js_cocos2dx_studio_ComAudio_getFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ComAudio_resumeEffect(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ComAudio_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ComAudio_ComAudio(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocostudio_InputDelegate_class; extern JSObject *jsb_cocostudio_InputDelegate_prototype; bool js_cocos2dx_studio_InputDelegate_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_InputDelegate_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_InputDelegate(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_InputDelegate(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_InputDelegate_isAccelerometerEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_InputDelegate_setKeypadEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_InputDelegate_getTouchMode(JSContext *cx, uint32_t argc, jsval *vp); @@ -435,8 +458,8 @@ extern JSObject *jsb_cocostudio_ComController_prototype; bool js_cocos2dx_studio_ComController_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ComController_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ComController(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ComController(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ComController_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ComController_ComController(JSContext *cx, uint32_t argc, jsval *vp); @@ -445,65 +468,20 @@ extern JSObject *jsb_cocostudio_ComRender_prototype; bool js_cocos2dx_studio_ComRender_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ComRender_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ComRender(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); -bool js_cocos2dx_studio_ComRender_setNode(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_studio_ComRender(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ComRender_getNode(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ComRender_setNode(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ComRender_create(JSContext *cx, uint32_t argc, jsval *vp); - -extern JSClass *jsb_cocostudio_GUIReader_class; -extern JSObject *jsb_cocostudio_GUIReader_prototype; - -bool js_cocos2dx_studio_GUIReader_constructor(JSContext *cx, uint32_t argc, jsval *vp); -void js_cocos2dx_studio_GUIReader_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_GUIReader(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); -bool js_cocos2dx_studio_GUIReader_setFilePath(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_GUIReader_widgetFromJsonFile(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_GUIReader_getFilePath(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_GUIReader_widgetFromBinaryFile(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_GUIReader_getVersionInteger(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_GUIReader_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_GUIReader_getInstance(JSContext *cx, uint32_t argc, jsval *vp); - -extern JSClass *jsb_cocostudio_SceneReader_class; -extern JSObject *jsb_cocostudio_SceneReader_prototype; - -bool js_cocos2dx_studio_SceneReader_constructor(JSContext *cx, uint32_t argc, jsval *vp); -void js_cocos2dx_studio_SceneReader_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_SceneReader(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); -bool js_cocos2dx_studio_SceneReader_createNodeWithSceneFile(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_SceneReader_getAttachComponentType(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_SceneReader_getNodeByTag(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_SceneReader_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_SceneReader_sceneReaderVersion(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_SceneReader_getInstance(JSContext *cx, uint32_t argc, jsval *vp); - -extern JSClass *jsb_cocostudio_timeline_ActionTimelineCache_class; -extern JSObject *jsb_cocostudio_timeline_ActionTimelineCache_prototype; - -bool js_cocos2dx_studio_ActionTimelineCache_constructor(JSContext *cx, uint32_t argc, jsval *vp); -void js_cocos2dx_studio_ActionTimelineCache_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ActionTimelineCache(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); -bool js_cocos2dx_studio_ActionTimelineCache_createActionFromJson(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ActionTimelineCache_purge(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ActionTimelineCache_init(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ActionTimelineCache_loadAnimationActionWithFile(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ActionTimelineCache_loadAnimationActionWithContent(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ActionTimelineCache_removeAction(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ActionTimelineCache_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ActionTimelineCache_createAction(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ActionTimelineCache_getInstance(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ComRender_ComRender(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocostudio_timeline_Frame_class; extern JSObject *jsb_cocostudio_timeline_Frame_prototype; bool js_cocos2dx_studio_Frame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_Frame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_Frame(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_Frame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_Frame_clone(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_Frame_setNode(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_Frame_setTimeline(JSContext *cx, uint32_t argc, jsval *vp); @@ -521,8 +499,8 @@ extern JSObject *jsb_cocostudio_timeline_VisibleFrame_prototype; bool js_cocos2dx_studio_VisibleFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_VisibleFrame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_VisibleFrame(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_VisibleFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_VisibleFrame_isVisible(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_VisibleFrame_setVisible(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_VisibleFrame_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -533,10 +511,9 @@ extern JSObject *jsb_cocostudio_timeline_TextureFrame_prototype; bool js_cocos2dx_studio_TextureFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_TextureFrame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_TextureFrame(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_TextureFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_TextureFrame_getTextureName(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_TextureFrame_setNode(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_TextureFrame_setTextureName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_TextureFrame_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_TextureFrame_TextureFrame(JSContext *cx, uint32_t argc, jsval *vp); @@ -546,8 +523,8 @@ extern JSObject *jsb_cocostudio_timeline_RotationFrame_prototype; bool js_cocos2dx_studio_RotationFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_RotationFrame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_RotationFrame(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_RotationFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_RotationFrame_setRotation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_RotationFrame_getRotation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_RotationFrame_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -558,8 +535,8 @@ extern JSObject *jsb_cocostudio_timeline_SkewFrame_prototype; bool js_cocos2dx_studio_SkewFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_SkewFrame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_SkewFrame(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_SkewFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_SkewFrame_getSkewY(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_SkewFrame_setSkewX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_SkewFrame_setSkewY(JSContext *cx, uint32_t argc, jsval *vp); @@ -572,8 +549,8 @@ extern JSObject *jsb_cocostudio_timeline_RotationSkewFrame_prototype; bool js_cocos2dx_studio_RotationSkewFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_RotationSkewFrame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_RotationSkewFrame(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_RotationSkewFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_RotationSkewFrame_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_RotationSkewFrame_RotationSkewFrame(JSContext *cx, uint32_t argc, jsval *vp); @@ -582,8 +559,8 @@ extern JSObject *jsb_cocostudio_timeline_PositionFrame_prototype; bool js_cocos2dx_studio_PositionFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_PositionFrame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_PositionFrame(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_PositionFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_PositionFrame_getX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_PositionFrame_getY(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_PositionFrame_setPosition(JSContext *cx, uint32_t argc, jsval *vp); @@ -598,8 +575,8 @@ extern JSObject *jsb_cocostudio_timeline_ScaleFrame_prototype; bool js_cocos2dx_studio_ScaleFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ScaleFrame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ScaleFrame(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ScaleFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ScaleFrame_setScaleY(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ScaleFrame_setScaleX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ScaleFrame_getScaleY(JSContext *cx, uint32_t argc, jsval *vp); @@ -613,8 +590,8 @@ extern JSObject *jsb_cocostudio_timeline_AnchorPointFrame_prototype; bool js_cocos2dx_studio_AnchorPointFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_AnchorPointFrame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_AnchorPointFrame(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_AnchorPointFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_AnchorPointFrame_setAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_AnchorPointFrame_getAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_AnchorPointFrame_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -625,12 +602,18 @@ extern JSObject *jsb_cocostudio_timeline_InnerActionFrame_prototype; bool js_cocos2dx_studio_InnerActionFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_InnerActionFrame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_InnerActionFrame(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_InnerActionFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_studio_InnerActionFrame_getEndFrameIndex(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_InnerActionFrame_getStartFrameIndex(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_InnerActionFrame_getInnerActionType(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_InnerActionFrame_setEndFrameIndex(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_InnerActionFrame_setEnterWithName(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_InnerActionFrame_setSingleFrameIndex(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_InnerActionFrame_setStartFrameIndex(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_InnerActionFrame_getSingleFrameIndex(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_InnerActionFrame_setInnerActionType(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_InnerActionFrame_getStartFrameIndex(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_InnerActionFrame_setAnimationName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_InnerActionFrame_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_InnerActionFrame_InnerActionFrame(JSContext *cx, uint32_t argc, jsval *vp); @@ -639,22 +622,32 @@ extern JSObject *jsb_cocostudio_timeline_ColorFrame_prototype; bool js_cocos2dx_studio_ColorFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ColorFrame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ColorFrame(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); -bool js_cocos2dx_studio_ColorFrame_getAlpha(JSContext *cx, uint32_t argc, jsval *vp); +void js_register_cocos2dx_studio_ColorFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ColorFrame_getColor(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ColorFrame_setAlpha(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ColorFrame_setColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ColorFrame_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ColorFrame_ColorFrame(JSContext *cx, uint32_t argc, jsval *vp); +extern JSClass *jsb_cocostudio_timeline_AlphaFrame_class; +extern JSObject *jsb_cocostudio_timeline_AlphaFrame_prototype; + +bool js_cocos2dx_studio_AlphaFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_studio_AlphaFrame_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_studio_AlphaFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_studio_AlphaFrame_getAlpha(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_AlphaFrame_setAlpha(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_AlphaFrame_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_AlphaFrame_AlphaFrame(JSContext *cx, uint32_t argc, jsval *vp); + extern JSClass *jsb_cocostudio_timeline_EventFrame_class; extern JSObject *jsb_cocostudio_timeline_EventFrame_prototype; bool js_cocos2dx_studio_EventFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_EventFrame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_EventFrame(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_EventFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_EventFrame_setEvent(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_EventFrame_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_EventFrame_getEvent(JSContext *cx, uint32_t argc, jsval *vp); @@ -666,8 +659,8 @@ extern JSObject *jsb_cocostudio_timeline_ZOrderFrame_prototype; bool js_cocos2dx_studio_ZOrderFrame_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ZOrderFrame_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ZOrderFrame(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ZOrderFrame(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ZOrderFrame_getZOrder(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ZOrderFrame_setZOrder(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ZOrderFrame_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -678,8 +671,8 @@ extern JSObject *jsb_cocostudio_timeline_Timeline_prototype; bool js_cocos2dx_studio_Timeline_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_Timeline_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_Timeline(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_Timeline(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_Timeline_clone(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_Timeline_gotoFrame(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_Timeline_setNode(JSContext *cx, uint32_t argc, jsval *vp); @@ -701,19 +694,21 @@ extern JSObject *jsb_cocostudio_timeline_ActionTimelineData_prototype; bool js_cocos2dx_studio_ActionTimelineData_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ActionTimelineData_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ActionTimelineData(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ActionTimelineData(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ActionTimelineData_setActionTag(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ActionTimelineData_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimelineData_getActionTag(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimelineData_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ActionTimelineData_ActionTimelineData(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocostudio_timeline_ActionTimeline_class; extern JSObject *jsb_cocostudio_timeline_ActionTimeline_prototype; bool js_cocos2dx_studio_ActionTimeline_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_studio_ActionTimeline_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_ActionTimeline(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_studio_ActionTimeline(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_studio_ActionTimeline_setFrameEventCallFunc(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_addTimeline(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_getCurrentFrame(JSContext *cx, uint32_t argc, jsval *vp); @@ -721,15 +716,20 @@ bool js_cocos2dx_studio_ActionTimeline_getStartFrame(JSContext *cx, uint32_t arg bool js_cocos2dx_studio_ActionTimeline_pause(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_removeTimeline(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ActionTimeline_clearFrameEventCallFunc(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_setLastFrameCallFunc(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_getTimelines(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ActionTimeline_play(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ActionTimeline_getAnimationInfo(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_resume(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ActionTimeline_removeAnimationInfo(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_getTimeSpeed(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ActionTimeline_addAnimationInfo(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_getDuration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_gotoFrameAndPause(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_isPlaying(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_gotoFrameAndPlay(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_ActionTimeline_clearFrameEventCallFunc(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ActionTimeline_IsAnimationInfoExists(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_getEndFrame(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_setTimeSpeed(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_clearLastFrameCallFunc(JSContext *cx, uint32_t argc, jsval *vp); @@ -738,26 +738,19 @@ bool js_cocos2dx_studio_ActionTimeline_setCurrentFrame(JSContext *cx, uint32_t a bool js_cocos2dx_studio_ActionTimeline_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_studio_ActionTimeline_ActionTimeline(JSContext *cx, uint32_t argc, jsval *vp); -extern JSClass *jsb_cocos2d_CSLoader_class; -extern JSObject *jsb_cocos2d_CSLoader_prototype; - -bool js_cocos2dx_studio_CSLoader_constructor(JSContext *cx, uint32_t argc, jsval *vp); -void js_cocos2dx_studio_CSLoader_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_studio_CSLoader(JSContext *cx, JSObject *global); -void register_all_cocos2dx_studio(JSContext* cx, JSObject* obj); -bool js_cocos2dx_studio_CSLoader_setJsonPath(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_CSLoader_createNodeFromJson(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_CSLoader_loadNodeWithFile(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_CSLoader_bindCallback(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_CSLoader_purge(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_CSLoader_init(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_CSLoader_loadNodeWithContent(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_CSLoader_isRecordJsonPath(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_CSLoader_getJsonPath(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_CSLoader_setRecordJsonPath(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_CSLoader_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_CSLoader_createNode(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_CSLoader_createTimeline(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_studio_CSLoader_getInstance(JSContext *cx, uint32_t argc, jsval *vp); +extern JSClass *jsb_cocostudio_ObjectExtensionData_class; +extern JSObject *jsb_cocostudio_ObjectExtensionData_prototype; + +bool js_cocos2dx_studio_ObjectExtensionData_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_studio_ObjectExtensionData_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_studio_ObjectExtensionData(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_studio(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_studio_ObjectExtensionData_setActionTag(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ObjectExtensionData_setCustomProperty(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ObjectExtensionData_init(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ObjectExtensionData_getCustomProperty(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ObjectExtensionData_getActionTag(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ObjectExtensionData_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_studio_ObjectExtensionData_ObjectExtensionData(JSContext *cx, uint32_t argc, jsval *vp); #endif diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_ui_auto.cpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_ui_auto.cpp index c05abcbaeb..6e441fbf38 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_ui_auto.cpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_ui_auto.cpp @@ -4,10 +4,11 @@ template static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedValue initializing(cx); bool isNewValid = true; - JSObject* global = ScriptingCore::getInstance()->getGlobalObject(); - isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && JSVAL_TO_BOOLEAN(initializing); + JS::RootedObject global(cx, ScriptingCore::getInstance()->getGlobalObject()); + isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && initializing.toBoolean(); if (isNewValid) { TypeTest t; @@ -18,8 +19,11 @@ static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *_tmp = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp)); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject _tmp(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + + args.rval().set(OBJECT_TO_JSVAL(_tmp)); return true; } @@ -31,9 +35,10 @@ static bool empty_constructor(JSContext *cx, uint32_t argc, jsval *vp) { return false; } -static bool js_is_native_obj(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) { - vp.set(BOOLEAN_TO_JSVAL(true)); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setBoolean(true); return true; } JSClass *jsb_cocos2d_ui_LayoutParameter_class; @@ -41,7 +46,8 @@ JSObject *jsb_cocos2d_ui_LayoutParameter_prototype; bool js_cocos2dx_ui_LayoutParameter_clone(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LayoutParameter* cobj = (cocos2d::ui::LayoutParameter *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutParameter_clone : Invalid Native Object"); @@ -56,7 +62,7 @@ bool js_cocos2dx_ui_LayoutParameter_clone(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -65,7 +71,8 @@ bool js_cocos2dx_ui_LayoutParameter_clone(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_LayoutParameter_getLayoutType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LayoutParameter* cobj = (cocos2d::ui::LayoutParameter *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutParameter_getLayoutType : Invalid Native Object"); @@ -73,7 +80,7 @@ bool js_cocos2dx_ui_LayoutParameter_getLayoutType(JSContext *cx, uint32_t argc, int ret = (int)cobj->getLayoutType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -82,7 +89,8 @@ bool js_cocos2dx_ui_LayoutParameter_getLayoutType(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_LayoutParameter_createCloneInstance(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LayoutParameter* cobj = (cocos2d::ui::LayoutParameter *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutParameter_createCloneInstance : Invalid Native Object"); @@ -97,7 +105,7 @@ bool js_cocos2dx_ui_LayoutParameter_createCloneInstance(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -106,25 +114,25 @@ bool js_cocos2dx_ui_LayoutParameter_createCloneInstance(JSContext *cx, uint32_t } bool js_cocos2dx_ui_LayoutParameter_copyProperties(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LayoutParameter* cobj = (cocos2d::ui::LayoutParameter *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutParameter_copyProperties : Invalid Native Object"); if (argc == 1) { cocos2d::ui::LayoutParameter* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ui::LayoutParameter*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutParameter_copyProperties : Error processing arguments"); cobj->copyProperties(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -133,6 +141,7 @@ bool js_cocos2dx_ui_LayoutParameter_copyProperties(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_LayoutParameter_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ui::LayoutParameter* ret = cocos2d::ui::LayoutParameter::create(); jsval jsret = JSVAL_NULL; @@ -144,7 +153,7 @@ bool js_cocos2dx_ui_LayoutParameter_create(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_LayoutParameter_create : wrong number of arguments"); @@ -153,7 +162,7 @@ bool js_cocos2dx_ui_LayoutParameter_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_ui_LayoutParameter_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::LayoutParameter* cobj = new (std::nothrow) cocos2d::ui::LayoutParameter(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -167,13 +176,16 @@ bool js_cocos2dx_ui_LayoutParameter_constructor(JSContext *cx, uint32_t argc, js CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::LayoutParameter"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::LayoutParameter"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -183,7 +195,7 @@ void js_cocos2d_ui_LayoutParameter_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (LayoutParameter)", obj); } -void js_register_cocos2dx_ui_LayoutParameter(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ui_LayoutParameter(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ui_LayoutParameter_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ui_LayoutParameter_class->name = "LayoutParameter"; jsb_cocos2d_ui_LayoutParameter_class->addProperty = JS_PropertyStub; @@ -197,8 +209,8 @@ void js_register_cocos2dx_ui_LayoutParameter(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_LayoutParameter_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -216,7 +228,7 @@ void js_register_cocos2dx_ui_LayoutParameter(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_LayoutParameter_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_ui_LayoutParameter_class, js_cocos2dx_ui_LayoutParameter_constructor, 0, // constructor properties, @@ -247,18 +259,18 @@ JSObject *jsb_cocos2d_ui_LinearLayoutParameter_prototype; bool js_cocos2dx_ui_LinearLayoutParameter_setGravity(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LinearLayoutParameter* cobj = (cocos2d::ui::LinearLayoutParameter *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LinearLayoutParameter_setGravity : Invalid Native Object"); if (argc == 1) { cocos2d::ui::LinearLayoutParameter::LinearGravity arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LinearLayoutParameter_setGravity : Error processing arguments"); cobj->setGravity(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -267,7 +279,8 @@ bool js_cocos2dx_ui_LinearLayoutParameter_setGravity(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_LinearLayoutParameter_getGravity(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LinearLayoutParameter* cobj = (cocos2d::ui::LinearLayoutParameter *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LinearLayoutParameter_getGravity : Invalid Native Object"); @@ -275,7 +288,7 @@ bool js_cocos2dx_ui_LinearLayoutParameter_getGravity(JSContext *cx, uint32_t arg int ret = (int)cobj->getGravity(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -284,6 +297,7 @@ bool js_cocos2dx_ui_LinearLayoutParameter_getGravity(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_LinearLayoutParameter_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ui::LinearLayoutParameter* ret = cocos2d::ui::LinearLayoutParameter::create(); jsval jsret = JSVAL_NULL; @@ -295,7 +309,7 @@ bool js_cocos2dx_ui_LinearLayoutParameter_create(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_LinearLayoutParameter_create : wrong number of arguments"); @@ -304,7 +318,7 @@ bool js_cocos2dx_ui_LinearLayoutParameter_create(JSContext *cx, uint32_t argc, j bool js_cocos2dx_ui_LinearLayoutParameter_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::LinearLayoutParameter* cobj = new (std::nothrow) cocos2d::ui::LinearLayoutParameter(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -318,13 +332,16 @@ bool js_cocos2dx_ui_LinearLayoutParameter_constructor(JSContext *cx, uint32_t ar CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::LinearLayoutParameter"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::LinearLayoutParameter"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -335,7 +352,7 @@ void js_cocos2d_ui_LinearLayoutParameter_finalize(JSFreeOp *fop, JSObject *obj) CCLOGINFO("jsbindings: finalizing JS object %p (LinearLayoutParameter)", obj); } -void js_register_cocos2dx_ui_LinearLayoutParameter(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ui_LinearLayoutParameter(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ui_LinearLayoutParameter_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ui_LinearLayoutParameter_class->name = "LinearLayoutParameter"; jsb_cocos2d_ui_LinearLayoutParameter_class->addProperty = JS_PropertyStub; @@ -349,8 +366,8 @@ void js_register_cocos2dx_ui_LinearLayoutParameter(JSContext *cx, JSObject *glob jsb_cocos2d_ui_LinearLayoutParameter_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -366,7 +383,7 @@ void js_register_cocos2dx_ui_LinearLayoutParameter(JSContext *cx, JSObject *glob jsb_cocos2d_ui_LinearLayoutParameter_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_LayoutParameter_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_LayoutParameter_prototype), jsb_cocos2d_ui_LinearLayoutParameter_class, js_cocos2dx_ui_LinearLayoutParameter_constructor, 0, // constructor properties, @@ -397,18 +414,18 @@ JSObject *jsb_cocos2d_ui_RelativeLayoutParameter_prototype; bool js_cocos2dx_ui_RelativeLayoutParameter_setAlign(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::RelativeLayoutParameter* cobj = (cocos2d::ui::RelativeLayoutParameter *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RelativeLayoutParameter_setAlign : Invalid Native Object"); if (argc == 1) { cocos2d::ui::RelativeLayoutParameter::RelativeAlign arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RelativeLayoutParameter_setAlign : Error processing arguments"); cobj->setAlign(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -417,18 +434,18 @@ bool js_cocos2dx_ui_RelativeLayoutParameter_setAlign(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_RelativeLayoutParameter_setRelativeToWidgetName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::RelativeLayoutParameter* cobj = (cocos2d::ui::RelativeLayoutParameter *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RelativeLayoutParameter_setRelativeToWidgetName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RelativeLayoutParameter_setRelativeToWidgetName : Error processing arguments"); cobj->setRelativeToWidgetName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -437,7 +454,8 @@ bool js_cocos2dx_ui_RelativeLayoutParameter_setRelativeToWidgetName(JSContext *c } bool js_cocos2dx_ui_RelativeLayoutParameter_getRelativeName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::RelativeLayoutParameter* cobj = (cocos2d::ui::RelativeLayoutParameter *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RelativeLayoutParameter_getRelativeName : Invalid Native Object"); @@ -445,7 +463,7 @@ bool js_cocos2dx_ui_RelativeLayoutParameter_getRelativeName(JSContext *cx, uint3 const std::string& ret = cobj->getRelativeName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -454,7 +472,8 @@ bool js_cocos2dx_ui_RelativeLayoutParameter_getRelativeName(JSContext *cx, uint3 } bool js_cocos2dx_ui_RelativeLayoutParameter_getRelativeToWidgetName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::RelativeLayoutParameter* cobj = (cocos2d::ui::RelativeLayoutParameter *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RelativeLayoutParameter_getRelativeToWidgetName : Invalid Native Object"); @@ -462,7 +481,7 @@ bool js_cocos2dx_ui_RelativeLayoutParameter_getRelativeToWidgetName(JSContext *c const std::string& ret = cobj->getRelativeToWidgetName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -471,18 +490,18 @@ bool js_cocos2dx_ui_RelativeLayoutParameter_getRelativeToWidgetName(JSContext *c } bool js_cocos2dx_ui_RelativeLayoutParameter_setRelativeName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::RelativeLayoutParameter* cobj = (cocos2d::ui::RelativeLayoutParameter *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RelativeLayoutParameter_setRelativeName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RelativeLayoutParameter_setRelativeName : Error processing arguments"); cobj->setRelativeName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -491,7 +510,8 @@ bool js_cocos2dx_ui_RelativeLayoutParameter_setRelativeName(JSContext *cx, uint3 } bool js_cocos2dx_ui_RelativeLayoutParameter_getAlign(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::RelativeLayoutParameter* cobj = (cocos2d::ui::RelativeLayoutParameter *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RelativeLayoutParameter_getAlign : Invalid Native Object"); @@ -499,7 +519,7 @@ bool js_cocos2dx_ui_RelativeLayoutParameter_getAlign(JSContext *cx, uint32_t arg int ret = (int)cobj->getAlign(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -508,6 +528,7 @@ bool js_cocos2dx_ui_RelativeLayoutParameter_getAlign(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_RelativeLayoutParameter_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ui::RelativeLayoutParameter* ret = cocos2d::ui::RelativeLayoutParameter::create(); jsval jsret = JSVAL_NULL; @@ -519,7 +540,7 @@ bool js_cocos2dx_ui_RelativeLayoutParameter_create(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_RelativeLayoutParameter_create : wrong number of arguments"); @@ -528,7 +549,7 @@ bool js_cocos2dx_ui_RelativeLayoutParameter_create(JSContext *cx, uint32_t argc, bool js_cocos2dx_ui_RelativeLayoutParameter_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::RelativeLayoutParameter* cobj = new (std::nothrow) cocos2d::ui::RelativeLayoutParameter(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -542,13 +563,16 @@ bool js_cocos2dx_ui_RelativeLayoutParameter_constructor(JSContext *cx, uint32_t CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RelativeLayoutParameter"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RelativeLayoutParameter"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -559,7 +583,7 @@ void js_cocos2d_ui_RelativeLayoutParameter_finalize(JSFreeOp *fop, JSObject *obj CCLOGINFO("jsbindings: finalizing JS object %p (RelativeLayoutParameter)", obj); } -void js_register_cocos2dx_ui_RelativeLayoutParameter(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ui_RelativeLayoutParameter(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ui_RelativeLayoutParameter_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ui_RelativeLayoutParameter_class->name = "RelativeLayoutParameter"; jsb_cocos2d_ui_RelativeLayoutParameter_class->addProperty = JS_PropertyStub; @@ -573,8 +597,8 @@ void js_register_cocos2dx_ui_RelativeLayoutParameter(JSContext *cx, JSObject *gl jsb_cocos2d_ui_RelativeLayoutParameter_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -594,7 +618,7 @@ void js_register_cocos2dx_ui_RelativeLayoutParameter(JSContext *cx, JSObject *gl jsb_cocos2d_ui_RelativeLayoutParameter_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_LayoutParameter_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_LayoutParameter_prototype), jsb_cocos2d_ui_RelativeLayoutParameter_class, js_cocos2dx_ui_RelativeLayoutParameter_constructor, 0, // constructor properties, @@ -623,20 +647,40 @@ void js_register_cocos2dx_ui_RelativeLayoutParameter(JSContext *cx, JSObject *gl JSClass *jsb_cocos2d_ui_Widget_class; JSObject *jsb_cocos2d_ui_Widget_prototype; +bool js_cocos2dx_ui_Widget_setLayoutComponentEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setLayoutComponentEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setLayoutComponentEnabled : Error processing arguments"); + cobj->setLayoutComponentEnabled(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Widget_setLayoutComponentEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_ui_Widget_setSizePercent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setSizePercent : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setSizePercent : Error processing arguments"); cobj->setSizePercent(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -645,7 +689,8 @@ bool js_cocos2dx_ui_Widget_setSizePercent(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_Widget_getCustomSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getCustomSize : Invalid Native Object"); @@ -653,7 +698,7 @@ bool js_cocos2dx_ui_Widget_getCustomSize(JSContext *cx, uint32_t argc, jsval *vp const cocos2d::Size& ret = cobj->getCustomSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -662,7 +707,8 @@ bool js_cocos2dx_ui_Widget_getCustomSize(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_Widget_getLeftBoundary(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getLeftBoundary : Invalid Native Object"); @@ -670,7 +716,7 @@ bool js_cocos2dx_ui_Widget_getLeftBoundary(JSContext *cx, uint32_t argc, jsval * double ret = cobj->getLeftBoundary(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -679,18 +725,18 @@ bool js_cocos2dx_ui_Widget_getLeftBoundary(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Widget_setFlippedX(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setFlippedX : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setFlippedX : Error processing arguments"); cobj->setFlippedX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -699,18 +745,18 @@ bool js_cocos2dx_ui_Widget_setFlippedX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_setCallbackName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setCallbackName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setCallbackName : Error processing arguments"); cobj->setCallbackName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -719,7 +765,8 @@ bool js_cocos2dx_ui_Widget_setCallbackName(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Widget_getVirtualRenderer(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getVirtualRenderer : Invalid Native Object"); @@ -734,7 +781,7 @@ bool js_cocos2dx_ui_Widget_getVirtualRenderer(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -743,18 +790,18 @@ bool js_cocos2dx_ui_Widget_getVirtualRenderer(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Widget_setPropagateTouchEvents(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setPropagateTouchEvents : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setPropagateTouchEvents : Error processing arguments"); cobj->setPropagateTouchEvents(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -763,7 +810,8 @@ bool js_cocos2dx_ui_Widget_setPropagateTouchEvents(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Widget_isUnifySizeEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_isUnifySizeEnabled : Invalid Native Object"); @@ -771,7 +819,7 @@ bool js_cocos2dx_ui_Widget_isUnifySizeEnabled(JSContext *cx, uint32_t argc, jsva bool ret = cobj->isUnifySizeEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -780,7 +828,8 @@ bool js_cocos2dx_ui_Widget_isUnifySizeEnabled(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Widget_getSizePercent(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getSizePercent : Invalid Native Object"); @@ -788,7 +837,7 @@ bool js_cocos2dx_ui_Widget_getSizePercent(JSContext *cx, uint32_t argc, jsval *v const cocos2d::Vec2& ret = cobj->getSizePercent(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -797,18 +846,18 @@ bool js_cocos2dx_ui_Widget_getSizePercent(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_Widget_setPositionPercent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setPositionPercent : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setPositionPercent : Error processing arguments"); cobj->setPositionPercent(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -817,18 +866,18 @@ bool js_cocos2dx_ui_Widget_setPositionPercent(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Widget_setSwallowTouches(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setSwallowTouches : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setSwallowTouches : Error processing arguments"); cobj->setSwallowTouches(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -837,7 +886,8 @@ bool js_cocos2dx_ui_Widget_setSwallowTouches(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Widget_getLayoutSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getLayoutSize : Invalid Native Object"); @@ -845,7 +895,7 @@ bool js_cocos2dx_ui_Widget_getLayoutSize(JSContext *cx, uint32_t argc, jsval *vp const cocos2d::Size& ret = cobj->getLayoutSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -854,18 +904,18 @@ bool js_cocos2dx_ui_Widget_getLayoutSize(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_Widget_setHighlighted(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setHighlighted : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setHighlighted : Error processing arguments"); cobj->setHighlighted(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -874,18 +924,18 @@ bool js_cocos2dx_ui_Widget_setHighlighted(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_Widget_setPositionType(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setPositionType : Invalid Native Object"); if (argc == 1) { cocos2d::ui::Widget::PositionType arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setPositionType : Error processing arguments"); cobj->setPositionType(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -894,7 +944,8 @@ bool js_cocos2dx_ui_Widget_setPositionType(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Widget_isIgnoreContentAdaptWithSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_isIgnoreContentAdaptWithSize : Invalid Native Object"); @@ -902,7 +953,7 @@ bool js_cocos2dx_ui_Widget_isIgnoreContentAdaptWithSize(JSContext *cx, uint32_t bool ret = cobj->isIgnoreContentAdaptWithSize(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -911,7 +962,8 @@ bool js_cocos2dx_ui_Widget_isIgnoreContentAdaptWithSize(JSContext *cx, uint32_t } bool js_cocos2dx_ui_Widget_getVirtualRendererSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getVirtualRendererSize : Invalid Native Object"); @@ -919,7 +971,7 @@ bool js_cocos2dx_ui_Widget_getVirtualRendererSize(JSContext *cx, uint32_t argc, cocos2d::Size ret = cobj->getVirtualRendererSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -928,7 +980,8 @@ bool js_cocos2dx_ui_Widget_getVirtualRendererSize(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Widget_isHighlighted(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_isHighlighted : Invalid Native Object"); @@ -936,7 +989,7 @@ bool js_cocos2dx_ui_Widget_isHighlighted(JSContext *cx, uint32_t argc, jsval *vp bool ret = cobj->isHighlighted(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -945,7 +998,8 @@ bool js_cocos2dx_ui_Widget_isHighlighted(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_Widget_getLayoutParameter(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getLayoutParameter : Invalid Native Object"); @@ -960,7 +1014,7 @@ bool js_cocos2dx_ui_Widget_getLayoutParameter(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -969,19 +1023,20 @@ bool js_cocos2dx_ui_Widget_getLayoutParameter(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Widget_addCCSEventListener(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_addCCSEventListener : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=](cocos2d::Ref* larg0, int larg1) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[2]; do { if (larg0) { @@ -992,8 +1047,8 @@ bool js_cocos2dx_ui_Widget_addCCSEventListener(JSContext *cx, uint32_t argc, jsv } } while (0); largv[1] = int32_to_jsval(cx, larg1); - jsval rval; - bool ok = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(2, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -1008,7 +1063,7 @@ bool js_cocos2dx_ui_Widget_addCCSEventListener(JSContext *cx, uint32_t argc, jsv ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_addCCSEventListener : Error processing arguments"); cobj->addCCSEventListener(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1017,7 +1072,8 @@ bool js_cocos2dx_ui_Widget_addCCSEventListener(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_Widget_getPositionType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getPositionType : Invalid Native Object"); @@ -1025,7 +1081,7 @@ bool js_cocos2dx_ui_Widget_getPositionType(JSContext *cx, uint32_t argc, jsval * int ret = (int)cobj->getPositionType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1034,7 +1090,8 @@ bool js_cocos2dx_ui_Widget_getPositionType(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Widget_getTopBoundary(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getTopBoundary : Invalid Native Object"); @@ -1042,7 +1099,7 @@ bool js_cocos2dx_ui_Widget_getTopBoundary(JSContext *cx, uint32_t argc, jsval *v double ret = cobj->getTopBoundary(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1051,18 +1108,18 @@ bool js_cocos2dx_ui_Widget_getTopBoundary(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_Widget_ignoreContentAdaptWithSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_ignoreContentAdaptWithSize : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_ignoreContentAdaptWithSize : Error processing arguments"); cobj->ignoreContentAdaptWithSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1071,20 +1128,20 @@ bool js_cocos2dx_ui_Widget_ignoreContentAdaptWithSize(JSContext *cx, uint32_t ar } bool js_cocos2dx_ui_Widget_findNextFocusedWidget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_findNextFocusedWidget : Invalid Native Object"); if (argc == 2) { cocos2d::ui::Widget::FocusDirection arg0; cocos2d::ui::Widget* arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -1100,7 +1157,7 @@ bool js_cocos2dx_ui_Widget_findNextFocusedWidget(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1109,7 +1166,8 @@ bool js_cocos2dx_ui_Widget_findNextFocusedWidget(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_Widget_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_isEnabled : Invalid Native Object"); @@ -1117,7 +1175,7 @@ bool js_cocos2dx_ui_Widget_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1126,7 +1184,8 @@ bool js_cocos2dx_ui_Widget_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_isFocused(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_isFocused : Invalid Native Object"); @@ -1134,7 +1193,7 @@ bool js_cocos2dx_ui_Widget_isFocused(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isFocused(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1143,7 +1202,8 @@ bool js_cocos2dx_ui_Widget_isFocused(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_getTouchBeganPosition(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getTouchBeganPosition : Invalid Native Object"); @@ -1151,7 +1211,7 @@ bool js_cocos2dx_ui_Widget_getTouchBeganPosition(JSContext *cx, uint32_t argc, j const cocos2d::Vec2& ret = cobj->getTouchBeganPosition(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1160,7 +1220,8 @@ bool js_cocos2dx_ui_Widget_getTouchBeganPosition(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_Widget_isTouchEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_isTouchEnabled : Invalid Native Object"); @@ -1168,7 +1229,7 @@ bool js_cocos2dx_ui_Widget_isTouchEnabled(JSContext *cx, uint32_t argc, jsval *v bool ret = cobj->isTouchEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1177,7 +1238,8 @@ bool js_cocos2dx_ui_Widget_isTouchEnabled(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_Widget_getCallbackName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getCallbackName : Invalid Native Object"); @@ -1185,7 +1247,7 @@ bool js_cocos2dx_ui_Widget_getCallbackName(JSContext *cx, uint32_t argc, jsval * const std::string& ret = cobj->getCallbackName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1194,7 +1256,8 @@ bool js_cocos2dx_ui_Widget_getCallbackName(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Widget_getActionTag(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getActionTag : Invalid Native Object"); @@ -1202,7 +1265,7 @@ bool js_cocos2dx_ui_Widget_getActionTag(JSContext *cx, uint32_t argc, jsval *vp) int ret = cobj->getActionTag(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1211,7 +1274,8 @@ bool js_cocos2dx_ui_Widget_getActionTag(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_getWorldPosition(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getWorldPosition : Invalid Native Object"); @@ -1219,7 +1283,7 @@ bool js_cocos2dx_ui_Widget_getWorldPosition(JSContext *cx, uint32_t argc, jsval cocos2d::Vec2 ret = cobj->getWorldPosition(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1228,7 +1292,8 @@ bool js_cocos2dx_ui_Widget_getWorldPosition(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Widget_isFocusEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_isFocusEnabled : Invalid Native Object"); @@ -1236,7 +1301,7 @@ bool js_cocos2dx_ui_Widget_isFocusEnabled(JSContext *cx, uint32_t argc, jsval *v bool ret = cobj->isFocusEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1245,18 +1310,18 @@ bool js_cocos2dx_ui_Widget_isFocusEnabled(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_Widget_setFocused(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setFocused : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setFocused : Error processing arguments"); cobj->setFocused(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1265,18 +1330,18 @@ bool js_cocos2dx_ui_Widget_setFocused(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_setActionTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setActionTag : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setActionTag : Error processing arguments"); cobj->setActionTag(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1285,18 +1350,18 @@ bool js_cocos2dx_ui_Widget_setActionTag(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_setTouchEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setTouchEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setTouchEnabled : Error processing arguments"); cobj->setTouchEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1305,18 +1370,18 @@ bool js_cocos2dx_ui_Widget_setTouchEnabled(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Widget_setFlippedY(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setFlippedY : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setFlippedY : Error processing arguments"); cobj->setFlippedY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1325,7 +1390,8 @@ bool js_cocos2dx_ui_Widget_setFlippedY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_init : Invalid Native Object"); @@ -1333,7 +1399,7 @@ bool js_cocos2dx_ui_Widget_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1342,18 +1408,18 @@ bool js_cocos2dx_ui_Widget_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setEnabled : Error processing arguments"); cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1362,7 +1428,8 @@ bool js_cocos2dx_ui_Widget_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_getRightBoundary(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getRightBoundary : Invalid Native Object"); @@ -1370,7 +1437,7 @@ bool js_cocos2dx_ui_Widget_getRightBoundary(JSContext *cx, uint32_t argc, jsval double ret = cobj->getRightBoundary(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1379,18 +1446,18 @@ bool js_cocos2dx_ui_Widget_getRightBoundary(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Widget_setBrightStyle(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setBrightStyle : Invalid Native Object"); if (argc == 1) { cocos2d::ui::Widget::BrightStyle arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setBrightStyle : Error processing arguments"); cobj->setBrightStyle(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1399,25 +1466,25 @@ bool js_cocos2dx_ui_Widget_setBrightStyle(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_Widget_setLayoutParameter(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setLayoutParameter : Invalid Native Object"); if (argc == 1) { cocos2d::ui::LayoutParameter* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ui::LayoutParameter*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setLayoutParameter : Error processing arguments"); cobj->setLayoutParameter(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1426,7 +1493,8 @@ bool js_cocos2dx_ui_Widget_setLayoutParameter(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Widget_clone(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_clone : Invalid Native Object"); @@ -1441,7 +1509,7 @@ bool js_cocos2dx_ui_Widget_clone(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1450,18 +1518,18 @@ bool js_cocos2dx_ui_Widget_clone(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_setFocusEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setFocusEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setFocusEnabled : Error processing arguments"); cobj->setFocusEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1470,7 +1538,8 @@ bool js_cocos2dx_ui_Widget_setFocusEnabled(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Widget_getBottomBoundary(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getBottomBoundary : Invalid Native Object"); @@ -1478,7 +1547,7 @@ bool js_cocos2dx_ui_Widget_getBottomBoundary(JSContext *cx, uint32_t argc, jsval double ret = cobj->getBottomBoundary(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1487,7 +1556,8 @@ bool js_cocos2dx_ui_Widget_getBottomBoundary(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Widget_isBright(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_isBright : Invalid Native Object"); @@ -1495,7 +1565,7 @@ bool js_cocos2dx_ui_Widget_isBright(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isBright(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1504,9 +1574,9 @@ bool js_cocos2dx_ui_Widget_isBright(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_dispatchFocusEvent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_dispatchFocusEvent : Invalid Native Object"); @@ -1514,24 +1584,24 @@ bool js_cocos2dx_ui_Widget_dispatchFocusEvent(JSContext *cx, uint32_t argc, jsva cocos2d::ui::Widget* arg0; cocos2d::ui::Widget* arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_dispatchFocusEvent : Error processing arguments"); cobj->dispatchFocusEvent(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1540,18 +1610,18 @@ bool js_cocos2dx_ui_Widget_dispatchFocusEvent(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Widget_setUnifySizeEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setUnifySizeEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setUnifySizeEnabled : Error processing arguments"); cobj->setUnifySizeEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1560,7 +1630,8 @@ bool js_cocos2dx_ui_Widget_setUnifySizeEnabled(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_Widget_isPropagateTouchEvents(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_isPropagateTouchEvents : Invalid Native Object"); @@ -1568,7 +1639,7 @@ bool js_cocos2dx_ui_Widget_isPropagateTouchEvents(JSContext *cx, uint32_t argc, bool ret = cobj->isPropagateTouchEvents(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1577,7 +1648,8 @@ bool js_cocos2dx_ui_Widget_isPropagateTouchEvents(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Widget_getCurrentFocusedWidget(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getCurrentFocusedWidget : Invalid Native Object"); @@ -1592,7 +1664,7 @@ bool js_cocos2dx_ui_Widget_getCurrentFocusedWidget(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1601,35 +1673,54 @@ bool js_cocos2dx_ui_Widget_getCurrentFocusedWidget(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Widget_hitTest(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_hitTest : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_hitTest : Error processing arguments"); bool ret = cobj->hitTest(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Widget_hitTest : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_ui_Widget_isLayoutComponentEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_isLayoutComponentEnabled : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isLayoutComponentEnabled(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Widget_isLayoutComponentEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_ui_Widget_requestFocus(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_requestFocus : Invalid Native Object"); if (argc == 0) { cobj->requestFocus(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1638,22 +1729,22 @@ bool js_cocos2dx_ui_Widget_requestFocus(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_updateSizeAndPosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::ui::Widget* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_updateSizeAndPosition : Invalid Native Object"); do { if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cobj->updateSizeAndPosition(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -1661,7 +1752,7 @@ bool js_cocos2dx_ui_Widget_updateSizeAndPosition(JSContext *cx, uint32_t argc, j do { if (argc == 0) { cobj->updateSizeAndPosition(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -1671,9 +1762,9 @@ bool js_cocos2dx_ui_Widget_updateSizeAndPosition(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_Widget_onFocusChange(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_onFocusChange : Invalid Native Object"); @@ -1681,24 +1772,24 @@ bool js_cocos2dx_ui_Widget_onFocusChange(JSContext *cx, uint32_t argc, jsval *vp cocos2d::ui::Widget* arg0; cocos2d::ui::Widget* arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_onFocusChange : Error processing arguments"); cobj->onFocusChange(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1707,7 +1798,8 @@ bool js_cocos2dx_ui_Widget_onFocusChange(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_Widget_getTouchMovePosition(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getTouchMovePosition : Invalid Native Object"); @@ -1715,7 +1807,7 @@ bool js_cocos2dx_ui_Widget_getTouchMovePosition(JSContext *cx, uint32_t argc, js const cocos2d::Vec2& ret = cobj->getTouchMovePosition(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1724,7 +1816,8 @@ bool js_cocos2dx_ui_Widget_getTouchMovePosition(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ui_Widget_getSizeType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getSizeType : Invalid Native Object"); @@ -1732,7 +1825,7 @@ bool js_cocos2dx_ui_Widget_getSizeType(JSContext *cx, uint32_t argc, jsval *vp) int ret = (int)cobj->getSizeType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1741,7 +1834,8 @@ bool js_cocos2dx_ui_Widget_getSizeType(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_getCallbackType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getCallbackType : Invalid Native Object"); @@ -1749,7 +1843,7 @@ bool js_cocos2dx_ui_Widget_getCallbackType(JSContext *cx, uint32_t argc, jsval * const std::string& ret = cobj->getCallbackType(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1758,7 +1852,8 @@ bool js_cocos2dx_ui_Widget_getCallbackType(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Widget_getTouchEndPosition(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getTouchEndPosition : Invalid Native Object"); @@ -1766,7 +1861,7 @@ bool js_cocos2dx_ui_Widget_getTouchEndPosition(JSContext *cx, uint32_t argc, jsv const cocos2d::Vec2& ret = cobj->getTouchEndPosition(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1775,7 +1870,8 @@ bool js_cocos2dx_ui_Widget_getTouchEndPosition(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_Widget_getPositionPercent(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_getPositionPercent : Invalid Native Object"); @@ -1783,7 +1879,7 @@ bool js_cocos2dx_ui_Widget_getPositionPercent(JSContext *cx, uint32_t argc, jsva const cocos2d::Vec2& ret = cobj->getPositionPercent(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1792,9 +1888,9 @@ bool js_cocos2dx_ui_Widget_getPositionPercent(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Widget_propagateTouchEvent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_propagateTouchEvent : Invalid Native Object"); @@ -1802,26 +1898,26 @@ bool js_cocos2dx_ui_Widget_propagateTouchEvent(JSContext *cx, uint32_t argc, jsv cocos2d::ui::Widget::TouchEventType arg0; cocos2d::ui::Widget* arg1; cocos2d::Touch* arg2; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::Touch*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_propagateTouchEvent : Error processing arguments"); cobj->propagateTouchEvent(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1830,19 +1926,20 @@ bool js_cocos2dx_ui_Widget_propagateTouchEvent(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_Widget_addClickEventListener(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_addClickEventListener : Invalid Native Object"); if (argc == 1) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, args.thisv().toObjectOrNull(), args.get(0))); auto lambda = [=](cocos2d::Ref* larg0) -> void { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; do { if (larg0) { @@ -1852,8 +1949,8 @@ bool js_cocos2dx_ui_Widget_addClickEventListener(JSContext *cx, uint32_t argc, j largv[0] = JSVAL_NULL; } } while (0); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -1868,7 +1965,7 @@ bool js_cocos2dx_ui_Widget_addClickEventListener(JSContext *cx, uint32_t argc, j ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_addClickEventListener : Error processing arguments"); cobj->addClickEventListener(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1877,7 +1974,8 @@ bool js_cocos2dx_ui_Widget_addClickEventListener(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_Widget_isFlippedX(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_isFlippedX : Invalid Native Object"); @@ -1885,7 +1983,7 @@ bool js_cocos2dx_ui_Widget_isFlippedX(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isFlippedX(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1894,7 +1992,8 @@ bool js_cocos2dx_ui_Widget_isFlippedX(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_isFlippedY(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_isFlippedY : Invalid Native Object"); @@ -1902,7 +2001,7 @@ bool js_cocos2dx_ui_Widget_isFlippedY(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isFlippedY(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1911,20 +2010,20 @@ bool js_cocos2dx_ui_Widget_isFlippedY(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_isClippingParentContainsPoint(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_isClippingParentContainsPoint : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_isClippingParentContainsPoint : Error processing arguments"); bool ret = cobj->isClippingParentContainsPoint(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1933,18 +2032,18 @@ bool js_cocos2dx_ui_Widget_isClippingParentContainsPoint(JSContext *cx, uint32_t } bool js_cocos2dx_ui_Widget_setSizeType(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setSizeType : Invalid Native Object"); if (argc == 1) { cocos2d::ui::Widget::SizeType arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setSizeType : Error processing arguments"); cobj->setSizeType(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1953,9 +2052,9 @@ bool js_cocos2dx_ui_Widget_setSizeType(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_interceptTouchEvent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_interceptTouchEvent : Invalid Native Object"); @@ -1963,26 +2062,26 @@ bool js_cocos2dx_ui_Widget_interceptTouchEvent(JSContext *cx, uint32_t argc, jsv cocos2d::ui::Widget::TouchEventType arg0; cocos2d::ui::Widget* arg1; cocos2d::Touch* arg2; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); do { - if (!argv[1].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); do { - if (!argv[2].isObject()) { ok = false; break; } + if (!args.get(2).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::Touch*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_interceptTouchEvent : Error processing arguments"); cobj->interceptTouchEvent(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1991,18 +2090,18 @@ bool js_cocos2dx_ui_Widget_interceptTouchEvent(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_Widget_setBright(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setBright : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setBright : Error processing arguments"); cobj->setBright(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2011,18 +2110,18 @@ bool js_cocos2dx_ui_Widget_setBright(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Widget_setCallbackType(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_setCallbackType : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_setCallbackType : Error processing arguments"); cobj->setCallbackType(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2031,7 +2130,8 @@ bool js_cocos2dx_ui_Widget_setCallbackType(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Widget_isSwallowTouches(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Widget_isSwallowTouches : Invalid Native Object"); @@ -2039,7 +2139,7 @@ bool js_cocos2dx_ui_Widget_isSwallowTouches(JSContext *cx, uint32_t argc, jsval bool ret = cobj->isSwallowTouches(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2048,14 +2148,14 @@ bool js_cocos2dx_ui_Widget_isSwallowTouches(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Widget_enableDpadNavigation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Widget_enableDpadNavigation : Error processing arguments"); cocos2d::ui::Widget::enableDpadNavigation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Widget_enableDpadNavigation : wrong number of arguments"); @@ -2064,6 +2164,7 @@ bool js_cocos2dx_ui_Widget_enableDpadNavigation(JSContext *cx, uint32_t argc, js bool js_cocos2dx_ui_Widget_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ui::Widget* ret = cocos2d::ui::Widget::create(); jsval jsret = JSVAL_NULL; @@ -2075,7 +2176,7 @@ bool js_cocos2dx_ui_Widget_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Widget_create : wrong number of arguments"); @@ -2084,7 +2185,7 @@ bool js_cocos2dx_ui_Widget_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ui_Widget_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::Widget* cobj = new (std::nothrow) cocos2d::ui::Widget(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -2098,13 +2199,16 @@ bool js_cocos2dx_ui_Widget_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Widget"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Widget"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -2117,21 +2221,21 @@ void js_cocos2d_ui_Widget_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_Widget_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ui::Widget *nobj = new (std::nothrow) cocos2d::ui::Widget(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Widget"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Widget"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_Widget(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ui_Widget(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ui_Widget_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ui_Widget_class->name = "Widget"; jsb_cocos2d_ui_Widget_class->addProperty = JS_PropertyStub; @@ -2145,11 +2249,12 @@ void js_register_cocos2dx_ui_Widget(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_Widget_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { + JS_FN("setLayoutComponentEnabled", js_cocos2dx_ui_Widget_setLayoutComponentEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setSizePercent", js_cocos2dx_ui_Widget_setSizePercent, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getCustomSize", js_cocos2dx_ui_Widget_getCustomSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getLeftBoundary", js_cocos2dx_ui_Widget_getLeftBoundary, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -2199,6 +2304,7 @@ void js_register_cocos2dx_ui_Widget(JSContext *cx, JSObject *global) { JS_FN("isPropagateTouchEvents", js_cocos2dx_ui_Widget_isPropagateTouchEvents, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getCurrentFocusedWidget", js_cocos2dx_ui_Widget_getCurrentFocusedWidget, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("hitTest", js_cocos2dx_ui_Widget_hitTest, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isLayoutComponentEnabled", js_cocos2dx_ui_Widget_isLayoutComponentEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("requestFocus", js_cocos2dx_ui_Widget_requestFocus, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("updateSizeAndPosition", js_cocos2dx_ui_Widget_updateSizeAndPosition, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("onFocusChange", js_cocos2dx_ui_Widget_onFocusChange, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -2229,7 +2335,7 @@ void js_register_cocos2dx_ui_Widget(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_Widget_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ProtectedNode_prototype, + JS::RootedObject(cx, jsb_cocos2d_ProtectedNode_prototype), jsb_cocos2d_ui_Widget_class, js_cocos2dx_ui_Widget_constructor, 0, // constructor properties, @@ -2260,18 +2366,18 @@ JSObject *jsb_cocos2d_ui_Layout_prototype; bool js_cocos2dx_ui_Layout_setBackGroundColorVector(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_setBackGroundColorVector : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Layout_setBackGroundColorVector : Error processing arguments"); cobj->setBackGroundColorVector(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2280,18 +2386,18 @@ bool js_cocos2dx_ui_Layout_setBackGroundColorVector(JSContext *cx, uint32_t argc } bool js_cocos2dx_ui_Layout_setClippingType(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_setClippingType : Invalid Native Object"); if (argc == 1) { cocos2d::ui::Layout::ClippingType arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Layout_setClippingType : Error processing arguments"); cobj->setClippingType(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2300,18 +2406,18 @@ bool js_cocos2dx_ui_Layout_setClippingType(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Layout_setBackGroundColorType(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_setBackGroundColorType : Invalid Native Object"); if (argc == 1) { cocos2d::ui::Layout::BackGroundColorType arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Layout_setBackGroundColorType : Error processing arguments"); cobj->setBackGroundColorType(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2320,18 +2426,18 @@ bool js_cocos2dx_ui_Layout_setBackGroundColorType(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Layout_setLoopFocus(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_setLoopFocus : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Layout_setLoopFocus : Error processing arguments"); cobj->setLoopFocus(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2340,18 +2446,18 @@ bool js_cocos2dx_ui_Layout_setLoopFocus(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Layout_setBackGroundImageColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_setBackGroundImageColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Layout_setBackGroundImageColor : Error processing arguments"); cobj->setBackGroundImageColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2360,7 +2466,8 @@ bool js_cocos2dx_ui_Layout_setBackGroundImageColor(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Layout_getBackGroundColorVector(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_getBackGroundColorVector : Invalid Native Object"); @@ -2368,7 +2475,7 @@ bool js_cocos2dx_ui_Layout_getBackGroundColorVector(JSContext *cx, uint32_t argc const cocos2d::Vec2& ret = cobj->getBackGroundColorVector(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2377,7 +2484,8 @@ bool js_cocos2dx_ui_Layout_getBackGroundColorVector(JSContext *cx, uint32_t argc } bool js_cocos2dx_ui_Layout_getClippingType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_getClippingType : Invalid Native Object"); @@ -2385,7 +2493,7 @@ bool js_cocos2dx_ui_Layout_getClippingType(JSContext *cx, uint32_t argc, jsval * int ret = (int)cobj->getClippingType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2394,7 +2502,8 @@ bool js_cocos2dx_ui_Layout_getClippingType(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Layout_isLoopFocus(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_isLoopFocus : Invalid Native Object"); @@ -2402,7 +2511,7 @@ bool js_cocos2dx_ui_Layout_isLoopFocus(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isLoopFocus(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2411,13 +2520,14 @@ bool js_cocos2dx_ui_Layout_isLoopFocus(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Layout_removeBackGroundImage(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_removeBackGroundImage : Invalid Native Object"); if (argc == 0) { cobj->removeBackGroundImage(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2426,7 +2536,8 @@ bool js_cocos2dx_ui_Layout_removeBackGroundImage(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_Layout_getBackGroundColorOpacity(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_getBackGroundColorOpacity : Invalid Native Object"); @@ -2434,7 +2545,7 @@ bool js_cocos2dx_ui_Layout_getBackGroundColorOpacity(JSContext *cx, uint32_t arg uint16_t ret = cobj->getBackGroundColorOpacity(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2443,7 +2554,8 @@ bool js_cocos2dx_ui_Layout_getBackGroundColorOpacity(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_Layout_isClippingEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_isClippingEnabled : Invalid Native Object"); @@ -2451,7 +2563,7 @@ bool js_cocos2dx_ui_Layout_isClippingEnabled(JSContext *cx, uint32_t argc, jsval bool ret = cobj->isClippingEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2460,18 +2572,18 @@ bool js_cocos2dx_ui_Layout_isClippingEnabled(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Layout_setBackGroundImageOpacity(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_setBackGroundImageOpacity : Invalid Native Object"); if (argc == 1) { uint16_t arg0; - ok &= jsval_to_uint16(cx, argv[0], &arg0); + ok &= jsval_to_uint16(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Layout_setBackGroundImageOpacity : Error processing arguments"); cobj->setBackGroundImageOpacity(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2480,28 +2592,28 @@ bool js_cocos2dx_ui_Layout_setBackGroundImageOpacity(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_Layout_setBackGroundImage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_setBackGroundImage : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Layout_setBackGroundImage : Error processing arguments"); cobj->setBackGroundImage(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Layout_setBackGroundImage : Error processing arguments"); cobj->setBackGroundImage(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2510,25 +2622,25 @@ bool js_cocos2dx_ui_Layout_setBackGroundImage(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Layout_setBackGroundColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::ui::Layout* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_setBackGroundColor : Invalid Native Object"); do { if (argc == 2) { cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Color3B arg1; - ok &= jsval_to_cccolor3b(cx, argv[1], &arg1); + ok &= jsval_to_cccolor3b(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cobj->setBackGroundColor(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -2536,10 +2648,10 @@ bool js_cocos2dx_ui_Layout_setBackGroundColor(JSContext *cx, uint32_t argc, jsva do { if (argc == 1) { cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cobj->setBackGroundColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -2549,13 +2661,14 @@ bool js_cocos2dx_ui_Layout_setBackGroundColor(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Layout_requestDoLayout(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_requestDoLayout : Invalid Native Object"); if (argc == 0) { cobj->requestDoLayout(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2564,7 +2677,8 @@ bool js_cocos2dx_ui_Layout_requestDoLayout(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Layout_getBackGroundImageCapInsets(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_getBackGroundImageCapInsets : Invalid Native Object"); @@ -2572,7 +2686,7 @@ bool js_cocos2dx_ui_Layout_getBackGroundImageCapInsets(JSContext *cx, uint32_t a const cocos2d::Rect& ret = cobj->getBackGroundImageCapInsets(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2581,7 +2695,8 @@ bool js_cocos2dx_ui_Layout_getBackGroundImageCapInsets(JSContext *cx, uint32_t a } bool js_cocos2dx_ui_Layout_getBackGroundColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_getBackGroundColor : Invalid Native Object"); @@ -2589,7 +2704,7 @@ bool js_cocos2dx_ui_Layout_getBackGroundColor(JSContext *cx, uint32_t argc, jsva const cocos2d::Color3B& ret = cobj->getBackGroundColor(); jsval jsret = JSVAL_NULL; jsret = cccolor3b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2598,18 +2713,18 @@ bool js_cocos2dx_ui_Layout_getBackGroundColor(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Layout_setClippingEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_setClippingEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Layout_setClippingEnabled : Error processing arguments"); cobj->setClippingEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2618,7 +2733,8 @@ bool js_cocos2dx_ui_Layout_setClippingEnabled(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Layout_getBackGroundImageColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_getBackGroundImageColor : Invalid Native Object"); @@ -2626,7 +2742,7 @@ bool js_cocos2dx_ui_Layout_getBackGroundImageColor(JSContext *cx, uint32_t argc, const cocos2d::Color3B& ret = cobj->getBackGroundImageColor(); jsval jsret = JSVAL_NULL; jsret = cccolor3b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2635,7 +2751,8 @@ bool js_cocos2dx_ui_Layout_getBackGroundImageColor(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Layout_isBackGroundImageScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_isBackGroundImageScale9Enabled : Invalid Native Object"); @@ -2643,7 +2760,7 @@ bool js_cocos2dx_ui_Layout_isBackGroundImageScale9Enabled(JSContext *cx, uint32_ bool ret = cobj->isBackGroundImageScale9Enabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2652,7 +2769,8 @@ bool js_cocos2dx_ui_Layout_isBackGroundImageScale9Enabled(JSContext *cx, uint32_ } bool js_cocos2dx_ui_Layout_getBackGroundColorType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_getBackGroundColorType : Invalid Native Object"); @@ -2660,7 +2778,7 @@ bool js_cocos2dx_ui_Layout_getBackGroundColorType(JSContext *cx, uint32_t argc, int ret = (int)cobj->getBackGroundColorType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2669,7 +2787,8 @@ bool js_cocos2dx_ui_Layout_getBackGroundColorType(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Layout_getBackGroundEndColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_getBackGroundEndColor : Invalid Native Object"); @@ -2677,7 +2796,7 @@ bool js_cocos2dx_ui_Layout_getBackGroundEndColor(JSContext *cx, uint32_t argc, j const cocos2d::Color3B& ret = cobj->getBackGroundEndColor(); jsval jsret = JSVAL_NULL; jsret = cccolor3b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2686,18 +2805,18 @@ bool js_cocos2dx_ui_Layout_getBackGroundEndColor(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_Layout_setBackGroundColorOpacity(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_setBackGroundColorOpacity : Invalid Native Object"); if (argc == 1) { uint16_t arg0; - ok &= jsval_to_uint16(cx, argv[0], &arg0); + ok &= jsval_to_uint16(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Layout_setBackGroundColorOpacity : Error processing arguments"); cobj->setBackGroundColorOpacity(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2706,7 +2825,8 @@ bool js_cocos2dx_ui_Layout_setBackGroundColorOpacity(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_Layout_getBackGroundImageOpacity(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_getBackGroundImageOpacity : Invalid Native Object"); @@ -2714,7 +2834,7 @@ bool js_cocos2dx_ui_Layout_getBackGroundImageOpacity(JSContext *cx, uint32_t arg uint16_t ret = cobj->getBackGroundImageOpacity(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2723,7 +2843,8 @@ bool js_cocos2dx_ui_Layout_getBackGroundImageOpacity(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_Layout_isPassFocusToChild(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_isPassFocusToChild : Invalid Native Object"); @@ -2731,7 +2852,7 @@ bool js_cocos2dx_ui_Layout_isPassFocusToChild(JSContext *cx, uint32_t argc, jsva bool ret = cobj->isPassFocusToChild(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2740,18 +2861,18 @@ bool js_cocos2dx_ui_Layout_isPassFocusToChild(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Layout_setBackGroundImageCapInsets(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_setBackGroundImageCapInsets : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Layout_setBackGroundImageCapInsets : Error processing arguments"); cobj->setBackGroundImageCapInsets(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2760,7 +2881,8 @@ bool js_cocos2dx_ui_Layout_setBackGroundImageCapInsets(JSContext *cx, uint32_t a } bool js_cocos2dx_ui_Layout_getBackGroundImageTextureSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_getBackGroundImageTextureSize : Invalid Native Object"); @@ -2768,7 +2890,7 @@ bool js_cocos2dx_ui_Layout_getBackGroundImageTextureSize(JSContext *cx, uint32_t const cocos2d::Size& ret = cobj->getBackGroundImageTextureSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2777,13 +2899,14 @@ bool js_cocos2dx_ui_Layout_getBackGroundImageTextureSize(JSContext *cx, uint32_t } bool js_cocos2dx_ui_Layout_forceDoLayout(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_forceDoLayout : Invalid Native Object"); if (argc == 0) { cobj->forceDoLayout(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2792,7 +2915,8 @@ bool js_cocos2dx_ui_Layout_forceDoLayout(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_Layout_getLayoutType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_getLayoutType : Invalid Native Object"); @@ -2800,7 +2924,7 @@ bool js_cocos2dx_ui_Layout_getLayoutType(JSContext *cx, uint32_t argc, jsval *vp int ret = (int)cobj->getLayoutType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2809,18 +2933,18 @@ bool js_cocos2dx_ui_Layout_getLayoutType(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_Layout_setPassFocusToChild(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_setPassFocusToChild : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Layout_setPassFocusToChild : Error processing arguments"); cobj->setPassFocusToChild(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2829,7 +2953,8 @@ bool js_cocos2dx_ui_Layout_setPassFocusToChild(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_Layout_getBackGroundStartColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_getBackGroundStartColor : Invalid Native Object"); @@ -2837,7 +2962,7 @@ bool js_cocos2dx_ui_Layout_getBackGroundStartColor(JSContext *cx, uint32_t argc, const cocos2d::Color3B& ret = cobj->getBackGroundStartColor(); jsval jsret = JSVAL_NULL; jsret = cccolor3b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2846,18 +2971,18 @@ bool js_cocos2dx_ui_Layout_getBackGroundStartColor(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Layout_setBackGroundImageScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_setBackGroundImageScale9Enabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Layout_setBackGroundImageScale9Enabled : Error processing arguments"); cobj->setBackGroundImageScale9Enabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2866,18 +2991,18 @@ bool js_cocos2dx_ui_Layout_setBackGroundImageScale9Enabled(JSContext *cx, uint32 } bool js_cocos2dx_ui_Layout_setLayoutType(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Layout* cobj = (cocos2d::ui::Layout *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Layout_setLayoutType : Invalid Native Object"); if (argc == 1) { cocos2d::ui::Layout::Type arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Layout_setLayoutType : Error processing arguments"); cobj->setLayoutType(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2886,6 +3011,7 @@ bool js_cocos2dx_ui_Layout_setLayoutType(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_Layout_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ui::Layout* ret = cocos2d::ui::Layout::create(); jsval jsret = JSVAL_NULL; @@ -2897,7 +3023,7 @@ bool js_cocos2dx_ui_Layout_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Layout_create : wrong number of arguments"); @@ -2906,6 +3032,7 @@ bool js_cocos2dx_ui_Layout_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ui_Layout_createInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Ref* ret = cocos2d::ui::Layout::createInstance(); jsval jsret = JSVAL_NULL; @@ -2917,7 +3044,7 @@ bool js_cocos2dx_ui_Layout_createInstance(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Layout_createInstance : wrong number of arguments"); @@ -2926,7 +3053,7 @@ bool js_cocos2dx_ui_Layout_createInstance(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_ui_Layout_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::Layout* cobj = new (std::nothrow) cocos2d::ui::Layout(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -2940,13 +3067,16 @@ bool js_cocos2dx_ui_Layout_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Layout"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Layout"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -2959,21 +3089,21 @@ void js_cocos2d_ui_Layout_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_Layout_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ui::Layout *nobj = new (std::nothrow) cocos2d::ui::Layout(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Layout"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Layout"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_Layout(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ui_Layout(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ui_Layout_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ui_Layout_class->name = "Layout"; jsb_cocos2d_ui_Layout_class->addProperty = JS_PropertyStub; @@ -2987,8 +3117,8 @@ void js_register_cocos2dx_ui_Layout(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_Layout_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -3037,7 +3167,7 @@ void js_register_cocos2dx_ui_Layout(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_Layout_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Widget_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), jsb_cocos2d_ui_Layout_class, js_cocos2dx_ui_Layout_constructor, 0, // constructor properties, @@ -3066,9 +3196,28 @@ void js_register_cocos2dx_ui_Layout(JSContext *cx, JSObject *global) { JSClass *jsb_cocos2d_ui_Button_class; JSObject *jsb_cocos2d_ui_Button_prototype; +bool js_cocos2dx_ui_Button_getNormalTextureSize(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_getNormalTextureSize : Invalid Native Object"); + if (argc == 0) { + cocos2d::Size ret = cobj->getNormalTextureSize(); + jsval jsret = JSVAL_NULL; + jsret = ccsize_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Button_getNormalTextureSize : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_ui_Button_getTitleText(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_getTitleText : Invalid Native Object"); @@ -3076,7 +3225,7 @@ bool js_cocos2dx_ui_Button_getTitleText(JSContext *cx, uint32_t argc, jsval *vp) const std::string& ret = cobj->getTitleText(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3085,18 +3234,18 @@ bool js_cocos2dx_ui_Button_getTitleText(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Button_setTitleFontSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_setTitleFontSize : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_setTitleFontSize : Error processing arguments"); cobj->setTitleFontSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3105,18 +3254,18 @@ bool js_cocos2dx_ui_Button_setTitleFontSize(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Button_setScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_setScale9Enabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_setScale9Enabled : Error processing arguments"); cobj->setScale9Enabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3125,7 +3274,8 @@ bool js_cocos2dx_ui_Button_setScale9Enabled(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Button_getTitleRenderer(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_getTitleRenderer : Invalid Native Object"); @@ -3140,7 +3290,7 @@ bool js_cocos2dx_ui_Button_getTitleRenderer(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3149,7 +3299,8 @@ bool js_cocos2dx_ui_Button_getTitleRenderer(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Button_getZoomScale(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_getZoomScale : Invalid Native Object"); @@ -3157,7 +3308,7 @@ bool js_cocos2dx_ui_Button_getZoomScale(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getZoomScale(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3166,7 +3317,8 @@ bool js_cocos2dx_ui_Button_getZoomScale(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Button_getCapInsetsDisabledRenderer(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_getCapInsetsDisabledRenderer : Invalid Native Object"); @@ -3174,7 +3326,7 @@ bool js_cocos2dx_ui_Button_getCapInsetsDisabledRenderer(JSContext *cx, uint32_t const cocos2d::Rect& ret = cobj->getCapInsetsDisabledRenderer(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3183,18 +3335,18 @@ bool js_cocos2dx_ui_Button_getCapInsetsDisabledRenderer(JSContext *cx, uint32_t } bool js_cocos2dx_ui_Button_setTitleColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_setTitleColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_setTitleColor : Error processing arguments"); cobj->setTitleColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3203,18 +3355,18 @@ bool js_cocos2dx_ui_Button_setTitleColor(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_Button_setCapInsetsDisabledRenderer(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_setCapInsetsDisabledRenderer : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_setCapInsetsDisabledRenderer : Error processing arguments"); cobj->setCapInsetsDisabledRenderer(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3223,18 +3375,18 @@ bool js_cocos2dx_ui_Button_setCapInsetsDisabledRenderer(JSContext *cx, uint32_t } bool js_cocos2dx_ui_Button_setCapInsets(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_setCapInsets : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_setCapInsets : Error processing arguments"); cobj->setCapInsets(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3243,28 +3395,28 @@ bool js_cocos2dx_ui_Button_setCapInsets(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Button_loadTextureDisabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_loadTextureDisabled : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_loadTextureDisabled : Error processing arguments"); cobj->loadTextureDisabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_loadTextureDisabled : Error processing arguments"); cobj->loadTextureDisabled(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3273,46 +3425,46 @@ bool js_cocos2dx_ui_Button_loadTextureDisabled(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_Button_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_init : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_init : Error processing arguments"); bool ret = cobj->init(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_init : Error processing arguments"); bool ret = cobj->init(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 3) { std::string arg0; std::string arg1; std::string arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_init : Error processing arguments"); bool ret = cobj->init(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 4) { @@ -3320,15 +3472,15 @@ bool js_cocos2dx_ui_Button_init(JSContext *cx, uint32_t argc, jsval *vp) std::string arg1; std::string arg2; cocos2d::ui::Widget::TextureResType arg3; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_std_string(cx, argv[2], &arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_init : Error processing arguments"); bool ret = cobj->init(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3337,18 +3489,18 @@ bool js_cocos2dx_ui_Button_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Button_setTitleText(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_setTitleText : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_setTitleText : Error processing arguments"); cobj->setTitleText(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3357,18 +3509,18 @@ bool js_cocos2dx_ui_Button_setTitleText(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Button_setCapInsetsNormalRenderer(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_setCapInsetsNormalRenderer : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_setCapInsetsNormalRenderer : Error processing arguments"); cobj->setCapInsetsNormalRenderer(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3377,28 +3529,28 @@ bool js_cocos2dx_ui_Button_setCapInsetsNormalRenderer(JSContext *cx, uint32_t ar } bool js_cocos2dx_ui_Button_loadTexturePressed(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_loadTexturePressed : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_loadTexturePressed : Error processing arguments"); cobj->loadTexturePressed(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_loadTexturePressed : Error processing arguments"); cobj->loadTexturePressed(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3407,18 +3559,18 @@ bool js_cocos2dx_ui_Button_loadTexturePressed(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Button_setTitleFontName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_setTitleFontName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_setTitleFontName : Error processing arguments"); cobj->setTitleFontName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3427,7 +3579,8 @@ bool js_cocos2dx_ui_Button_setTitleFontName(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Button_getCapInsetsNormalRenderer(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_getCapInsetsNormalRenderer : Invalid Native Object"); @@ -3435,7 +3588,7 @@ bool js_cocos2dx_ui_Button_getCapInsetsNormalRenderer(JSContext *cx, uint32_t ar const cocos2d::Rect& ret = cobj->getCapInsetsNormalRenderer(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3444,7 +3597,8 @@ bool js_cocos2dx_ui_Button_getCapInsetsNormalRenderer(JSContext *cx, uint32_t ar } bool js_cocos2dx_ui_Button_getCapInsetsPressedRenderer(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_getCapInsetsPressedRenderer : Invalid Native Object"); @@ -3452,7 +3606,7 @@ bool js_cocos2dx_ui_Button_getCapInsetsPressedRenderer(JSContext *cx, uint32_t a const cocos2d::Rect& ret = cobj->getCapInsetsPressedRenderer(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3461,32 +3615,32 @@ bool js_cocos2dx_ui_Button_getCapInsetsPressedRenderer(JSContext *cx, uint32_t a } bool js_cocos2dx_ui_Button_loadTextures(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_loadTextures : Invalid Native Object"); if (argc == 2) { std::string arg0; std::string arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_loadTextures : Error processing arguments"); cobj->loadTextures(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 3) { std::string arg0; std::string arg1; std::string arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_loadTextures : Error processing arguments"); cobj->loadTextures(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 4) { @@ -3494,13 +3648,13 @@ bool js_cocos2dx_ui_Button_loadTextures(JSContext *cx, uint32_t argc, jsval *vp) std::string arg1; std::string arg2; cocos2d::ui::Widget::TextureResType arg3; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_std_string(cx, argv[2], &arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_loadTextures : Error processing arguments"); cobj->loadTextures(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3509,7 +3663,8 @@ bool js_cocos2dx_ui_Button_loadTextures(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Button_isScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_isScale9Enabled : Invalid Native Object"); @@ -3517,7 +3672,7 @@ bool js_cocos2dx_ui_Button_isScale9Enabled(JSContext *cx, uint32_t argc, jsval * bool ret = cobj->isScale9Enabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3526,28 +3681,28 @@ bool js_cocos2dx_ui_Button_isScale9Enabled(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Button_loadTextureNormal(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_loadTextureNormal : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_loadTextureNormal : Error processing arguments"); cobj->loadTextureNormal(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_loadTextureNormal : Error processing arguments"); cobj->loadTextureNormal(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3556,18 +3711,18 @@ bool js_cocos2dx_ui_Button_loadTextureNormal(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Button_setCapInsetsPressedRenderer(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_setCapInsetsPressedRenderer : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_setCapInsetsPressedRenderer : Error processing arguments"); cobj->setCapInsetsPressedRenderer(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3576,7 +3731,8 @@ bool js_cocos2dx_ui_Button_setCapInsetsPressedRenderer(JSContext *cx, uint32_t a } bool js_cocos2dx_ui_Button_getTitleFontSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_getTitleFontSize : Invalid Native Object"); @@ -3584,7 +3740,7 @@ bool js_cocos2dx_ui_Button_getTitleFontSize(JSContext *cx, uint32_t argc, jsval double ret = cobj->getTitleFontSize(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3593,7 +3749,8 @@ bool js_cocos2dx_ui_Button_getTitleFontSize(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Button_getTitleFontName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_getTitleFontName : Invalid Native Object"); @@ -3601,7 +3758,7 @@ bool js_cocos2dx_ui_Button_getTitleFontName(JSContext *cx, uint32_t argc, jsval const std::string& ret = cobj->getTitleFontName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3610,15 +3767,16 @@ bool js_cocos2dx_ui_Button_getTitleFontName(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Button_getTitleColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_getTitleColor : Invalid Native Object"); if (argc == 0) { - const cocos2d::Color3B& ret = cobj->getTitleColor(); + cocos2d::Color3B ret = cobj->getTitleColor(); jsval jsret = JSVAL_NULL; jsret = cccolor3b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3627,18 +3785,18 @@ bool js_cocos2dx_ui_Button_getTitleColor(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_Button_setPressedActionEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_setPressedActionEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_setPressedActionEnabled : Error processing arguments"); cobj->setPressedActionEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3647,18 +3805,18 @@ bool js_cocos2dx_ui_Button_setPressedActionEnabled(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Button_setZoomScale(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Button* cobj = (cocos2d::ui::Button *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Button_setZoomScale : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Button_setZoomScale : Error processing arguments"); cobj->setZoomScale(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3667,13 +3825,13 @@ bool js_cocos2dx_ui_Button_setZoomScale(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Button_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::ui::Button* ret = cocos2d::ui::Button::create(arg0); jsval jsret = JSVAL_NULL; @@ -3685,17 +3843,17 @@ bool js_cocos2dx_ui_Button_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cocos2d::ui::Button* ret = cocos2d::ui::Button::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -3707,20 +3865,20 @@ bool js_cocos2dx_ui_Button_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } std::string arg2; - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } cocos2d::ui::Button* ret = cocos2d::ui::Button::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -3732,23 +3890,23 @@ bool js_cocos2dx_ui_Button_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 4) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } std::string arg2; - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } cocos2d::ui::Widget::TextureResType arg3; - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); if (!ok) { ok = true; break; } cocos2d::ui::Button* ret = cocos2d::ui::Button::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; @@ -3760,7 +3918,7 @@ bool js_cocos2dx_ui_Button_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -3777,7 +3935,7 @@ bool js_cocos2dx_ui_Button_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -3786,6 +3944,7 @@ bool js_cocos2dx_ui_Button_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Button_createInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Ref* ret = cocos2d::ui::Button::createInstance(); jsval jsret = JSVAL_NULL; @@ -3797,7 +3956,7 @@ bool js_cocos2dx_ui_Button_createInstance(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Button_createInstance : wrong number of arguments"); @@ -3806,7 +3965,7 @@ bool js_cocos2dx_ui_Button_createInstance(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_ui_Button_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::Button* cobj = new (std::nothrow) cocos2d::ui::Button(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -3820,13 +3979,16 @@ bool js_cocos2dx_ui_Button_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Button"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Button"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -3839,21 +4001,21 @@ void js_cocos2d_ui_Button_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_Button_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ui::Button *nobj = new (std::nothrow) cocos2d::ui::Button(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Button"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Button"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_Button(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ui_Button(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ui_Button_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ui_Button_class->name = "Button"; jsb_cocos2d_ui_Button_class->addProperty = JS_PropertyStub; @@ -3867,11 +4029,12 @@ void js_register_cocos2dx_ui_Button(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_Button_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { + JS_FN("getNormalTextureSize", js_cocos2dx_ui_Button_getNormalTextureSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getTitleText", js_cocos2dx_ui_Button_getTitleText, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setTitleFontSize", js_cocos2dx_ui_Button_setTitleFontSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setScale9Enabled", js_cocos2dx_ui_Button_setScale9Enabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -3910,7 +4073,7 @@ void js_register_cocos2dx_ui_Button(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_Button_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Widget_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), jsb_cocos2d_ui_Button_class, js_cocos2dx_ui_Button_constructor, 0, // constructor properties, @@ -3941,28 +4104,28 @@ JSObject *jsb_cocos2d_ui_CheckBox_prototype; bool js_cocos2dx_ui_CheckBox_loadTextureBackGroundSelected(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::CheckBox* cobj = (cocos2d::ui::CheckBox *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureBackGroundSelected : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureBackGroundSelected : Error processing arguments"); cobj->loadTextureBackGroundSelected(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureBackGroundSelected : Error processing arguments"); cobj->loadTextureBackGroundSelected(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3971,28 +4134,28 @@ bool js_cocos2dx_ui_CheckBox_loadTextureBackGroundSelected(JSContext *cx, uint32 } bool js_cocos2dx_ui_CheckBox_loadTextureBackGroundDisabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::CheckBox* cobj = (cocos2d::ui::CheckBox *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureBackGroundDisabled : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureBackGroundDisabled : Error processing arguments"); cobj->loadTextureBackGroundDisabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureBackGroundDisabled : Error processing arguments"); cobj->loadTextureBackGroundDisabled(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4001,18 +4164,18 @@ bool js_cocos2dx_ui_CheckBox_loadTextureBackGroundDisabled(JSContext *cx, uint32 } bool js_cocos2dx_ui_CheckBox_setSelected(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::CheckBox* cobj = (cocos2d::ui::CheckBox *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_CheckBox_setSelected : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_setSelected : Error processing arguments"); cobj->setSelected(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4021,28 +4184,28 @@ bool js_cocos2dx_ui_CheckBox_setSelected(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_CheckBox_loadTextureFrontCross(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::CheckBox* cobj = (cocos2d::ui::CheckBox *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureFrontCross : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureFrontCross : Error processing arguments"); cobj->loadTextureFrontCross(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureFrontCross : Error processing arguments"); cobj->loadTextureFrontCross(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4051,7 +4214,8 @@ bool js_cocos2dx_ui_CheckBox_loadTextureFrontCross(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_CheckBox_isSelected(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::CheckBox* cobj = (cocos2d::ui::CheckBox *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_CheckBox_isSelected : Invalid Native Object"); @@ -4059,7 +4223,7 @@ bool js_cocos2dx_ui_CheckBox_isSelected(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isSelected(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4068,9 +4232,9 @@ bool js_cocos2dx_ui_CheckBox_isSelected(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_CheckBox_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::CheckBox* cobj = (cocos2d::ui::CheckBox *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_CheckBox_init : Invalid Native Object"); @@ -4080,16 +4244,16 @@ bool js_cocos2dx_ui_CheckBox_init(JSContext *cx, uint32_t argc, jsval *vp) std::string arg2; std::string arg3; std::string arg4; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_std_string(cx, argv[2], &arg2); - ok &= jsval_to_std_string(cx, argv[3], &arg3); - ok &= jsval_to_std_string(cx, argv[4], &arg4); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); + ok &= jsval_to_std_string(cx, args.get(3), &arg3); + ok &= jsval_to_std_string(cx, args.get(4), &arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_init : Error processing arguments"); bool ret = cobj->init(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 6) { @@ -4099,17 +4263,17 @@ bool js_cocos2dx_ui_CheckBox_init(JSContext *cx, uint32_t argc, jsval *vp) std::string arg3; std::string arg4; cocos2d::ui::Widget::TextureResType arg5; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_std_string(cx, argv[2], &arg2); - ok &= jsval_to_std_string(cx, argv[3], &arg3); - ok &= jsval_to_std_string(cx, argv[4], &arg4); - ok &= jsval_to_int32(cx, argv[5], (int32_t *)&arg5); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); + ok &= jsval_to_std_string(cx, args.get(3), &arg3); + ok &= jsval_to_std_string(cx, args.get(4), &arg4); + ok &= jsval_to_int32(cx, args.get(5), (int32_t *)&arg5); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_init : Error processing arguments"); bool ret = cobj->init(arg0, arg1, arg2, arg3, arg4, arg5); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4118,9 +4282,9 @@ bool js_cocos2dx_ui_CheckBox_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_CheckBox_loadTextures(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::CheckBox* cobj = (cocos2d::ui::CheckBox *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_CheckBox_loadTextures : Invalid Native Object"); @@ -4130,14 +4294,14 @@ bool js_cocos2dx_ui_CheckBox_loadTextures(JSContext *cx, uint32_t argc, jsval *v std::string arg2; std::string arg3; std::string arg4; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_std_string(cx, argv[2], &arg2); - ok &= jsval_to_std_string(cx, argv[3], &arg3); - ok &= jsval_to_std_string(cx, argv[4], &arg4); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); + ok &= jsval_to_std_string(cx, args.get(3), &arg3); + ok &= jsval_to_std_string(cx, args.get(4), &arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_loadTextures : Error processing arguments"); cobj->loadTextures(arg0, arg1, arg2, arg3, arg4); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 6) { @@ -4147,75 +4311,113 @@ bool js_cocos2dx_ui_CheckBox_loadTextures(JSContext *cx, uint32_t argc, jsval *v std::string arg3; std::string arg4; cocos2d::ui::Widget::TextureResType arg5; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_std_string(cx, argv[2], &arg2); - ok &= jsval_to_std_string(cx, argv[3], &arg3); - ok &= jsval_to_std_string(cx, argv[4], &arg4); - ok &= jsval_to_int32(cx, argv[5], (int32_t *)&arg5); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); + ok &= jsval_to_std_string(cx, args.get(3), &arg3); + ok &= jsval_to_std_string(cx, args.get(4), &arg4); + ok &= jsval_to_int32(cx, args.get(5), (int32_t *)&arg5); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_loadTextures : Error processing arguments"); cobj->loadTextures(arg0, arg1, arg2, arg3, arg4, arg5); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_ui_CheckBox_loadTextures : wrong number of arguments: %d, was expecting %d", argc, 5); return false; } +bool js_cocos2dx_ui_CheckBox_getZoomScale(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::CheckBox* cobj = (cocos2d::ui::CheckBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_CheckBox_getZoomScale : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getZoomScale(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_CheckBox_getZoomScale : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_ui_CheckBox_loadTextureBackGround(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::CheckBox* cobj = (cocos2d::ui::CheckBox *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureBackGround : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureBackGround : Error processing arguments"); cobj->loadTextureBackGround(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureBackGround : Error processing arguments"); cobj->loadTextureBackGround(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_ui_CheckBox_loadTextureBackGround : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_ui_CheckBox_setZoomScale(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::CheckBox* cobj = (cocos2d::ui::CheckBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_CheckBox_setZoomScale : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_setZoomScale : Error processing arguments"); + cobj->setZoomScale(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_CheckBox_setZoomScale : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_ui_CheckBox_loadTextureFrontCrossDisabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::CheckBox* cobj = (cocos2d::ui::CheckBox *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureFrontCrossDisabled : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureFrontCrossDisabled : Error processing arguments"); cobj->loadTextureFrontCrossDisabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_CheckBox_loadTextureFrontCrossDisabled : Error processing arguments"); cobj->loadTextureFrontCrossDisabled(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4224,25 +4426,25 @@ bool js_cocos2dx_ui_CheckBox_loadTextureFrontCrossDisabled(JSContext *cx, uint32 } bool js_cocos2dx_ui_CheckBox_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 5) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } std::string arg2; - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } std::string arg3; - ok &= jsval_to_std_string(cx, argv[3], &arg3); + ok &= jsval_to_std_string(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } std::string arg4; - ok &= jsval_to_std_string(cx, argv[4], &arg4); + ok &= jsval_to_std_string(cx, args.get(4), &arg4); if (!ok) { ok = true; break; } cocos2d::ui::CheckBox* ret = cocos2d::ui::CheckBox::create(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; @@ -4254,29 +4456,29 @@ bool js_cocos2dx_ui_CheckBox_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 6) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } std::string arg2; - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } std::string arg3; - ok &= jsval_to_std_string(cx, argv[3], &arg3); + ok &= jsval_to_std_string(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } std::string arg4; - ok &= jsval_to_std_string(cx, argv[4], &arg4); + ok &= jsval_to_std_string(cx, args.get(4), &arg4); if (!ok) { ok = true; break; } cocos2d::ui::Widget::TextureResType arg5; - ok &= jsval_to_int32(cx, argv[5], (int32_t *)&arg5); + ok &= jsval_to_int32(cx, args.get(5), (int32_t *)&arg5); if (!ok) { ok = true; break; } cocos2d::ui::CheckBox* ret = cocos2d::ui::CheckBox::create(arg0, arg1, arg2, arg3, arg4, arg5); jsval jsret = JSVAL_NULL; @@ -4288,7 +4490,7 @@ bool js_cocos2dx_ui_CheckBox_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -4305,7 +4507,55 @@ bool js_cocos2dx_ui_CheckBox_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::ui::CheckBox* ret = cocos2d::ui::CheckBox::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::CheckBox*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + do { + if (argc == 3) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::ui::Widget::TextureResType arg2; + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + if (!ok) { ok = true; break; } + cocos2d::ui::CheckBox* ret = cocos2d::ui::CheckBox::create(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::CheckBox*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); return true; } } while (0); @@ -4314,6 +4564,7 @@ bool js_cocos2dx_ui_CheckBox_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_CheckBox_createInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Ref* ret = cocos2d::ui::CheckBox::createInstance(); jsval jsret = JSVAL_NULL; @@ -4325,7 +4576,7 @@ bool js_cocos2dx_ui_CheckBox_createInstance(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_CheckBox_createInstance : wrong number of arguments"); @@ -4334,7 +4585,7 @@ bool js_cocos2dx_ui_CheckBox_createInstance(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_ui_CheckBox_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::CheckBox* cobj = new (std::nothrow) cocos2d::ui::CheckBox(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -4348,13 +4599,16 @@ bool js_cocos2dx_ui_CheckBox_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::CheckBox"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::CheckBox"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -4367,21 +4621,21 @@ void js_cocos2d_ui_CheckBox_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_CheckBox_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ui::CheckBox *nobj = new (std::nothrow) cocos2d::ui::CheckBox(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::CheckBox"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::CheckBox"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_CheckBox(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ui_CheckBox(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ui_CheckBox_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ui_CheckBox_class->name = "CheckBox"; jsb_cocos2d_ui_CheckBox_class->addProperty = JS_PropertyStub; @@ -4395,8 +4649,8 @@ void js_register_cocos2dx_ui_CheckBox(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_CheckBox_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -4407,7 +4661,9 @@ void js_register_cocos2dx_ui_CheckBox(JSContext *cx, JSObject *global) { JS_FN("isSelected", js_cocos2dx_ui_CheckBox_isSelected, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("init", js_cocos2dx_ui_CheckBox_init, 5, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("loadTextures", js_cocos2dx_ui_CheckBox_loadTextures, 5, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getZoomScale", js_cocos2dx_ui_CheckBox_getZoomScale, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("loadTextureBackGround", js_cocos2dx_ui_CheckBox_loadTextureBackGround, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setZoomScale", js_cocos2dx_ui_CheckBox_setZoomScale, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("loadTextureFrontCrossDisabled", js_cocos2dx_ui_CheckBox_loadTextureFrontCrossDisabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2d_ui_CheckBox_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END @@ -4421,7 +4677,7 @@ void js_register_cocos2dx_ui_CheckBox(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_CheckBox_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Widget_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), jsb_cocos2d_ui_CheckBox_class, js_cocos2dx_ui_CheckBox_constructor, 0, // constructor properties, @@ -4452,28 +4708,28 @@ JSObject *jsb_cocos2d_ui_ImageView_prototype; bool js_cocos2dx_ui_ImageView_loadTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ImageView* cobj = (cocos2d::ui::ImageView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ImageView_loadTexture : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ImageView_loadTexture : Error processing arguments"); cobj->loadTexture(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ImageView_loadTexture : Error processing arguments"); cobj->loadTexture(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4482,32 +4738,32 @@ bool js_cocos2dx_ui_ImageView_loadTexture(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_ImageView_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ImageView* cobj = (cocos2d::ui::ImageView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ImageView_init : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ImageView_init : Error processing arguments"); bool ret = cobj->init(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ImageView_init : Error processing arguments"); bool ret = cobj->init(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4516,18 +4772,18 @@ bool js_cocos2dx_ui_ImageView_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_ImageView_setScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ImageView* cobj = (cocos2d::ui::ImageView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ImageView_setScale9Enabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ImageView_setScale9Enabled : Error processing arguments"); cobj->setScale9Enabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4536,18 +4792,18 @@ bool js_cocos2dx_ui_ImageView_setScale9Enabled(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_ImageView_setTextureRect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ImageView* cobj = (cocos2d::ui::ImageView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ImageView_setTextureRect : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ImageView_setTextureRect : Error processing arguments"); cobj->setTextureRect(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4556,18 +4812,18 @@ bool js_cocos2dx_ui_ImageView_setTextureRect(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_ImageView_setCapInsets(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ImageView* cobj = (cocos2d::ui::ImageView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ImageView_setCapInsets : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ImageView_setCapInsets : Error processing arguments"); cobj->setCapInsets(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4576,7 +4832,8 @@ bool js_cocos2dx_ui_ImageView_setCapInsets(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_ImageView_getCapInsets(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ImageView* cobj = (cocos2d::ui::ImageView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ImageView_getCapInsets : Invalid Native Object"); @@ -4584,7 +4841,7 @@ bool js_cocos2dx_ui_ImageView_getCapInsets(JSContext *cx, uint32_t argc, jsval * const cocos2d::Rect& ret = cobj->getCapInsets(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4593,7 +4850,8 @@ bool js_cocos2dx_ui_ImageView_getCapInsets(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_ImageView_isScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ImageView* cobj = (cocos2d::ui::ImageView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ImageView_isScale9Enabled : Invalid Native Object"); @@ -4601,7 +4859,7 @@ bool js_cocos2dx_ui_ImageView_isScale9Enabled(JSContext *cx, uint32_t argc, jsva bool ret = cobj->isScale9Enabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4610,13 +4868,13 @@ bool js_cocos2dx_ui_ImageView_isScale9Enabled(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_ImageView_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::ui::ImageView* ret = cocos2d::ui::ImageView::create(arg0); jsval jsret = JSVAL_NULL; @@ -4628,17 +4886,17 @@ bool js_cocos2dx_ui_ImageView_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cocos2d::ui::ImageView* ret = cocos2d::ui::ImageView::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -4650,7 +4908,7 @@ bool js_cocos2dx_ui_ImageView_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -4667,7 +4925,7 @@ bool js_cocos2dx_ui_ImageView_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -4676,6 +4934,7 @@ bool js_cocos2dx_ui_ImageView_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_ImageView_createInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Ref* ret = cocos2d::ui::ImageView::createInstance(); jsval jsret = JSVAL_NULL; @@ -4687,7 +4946,7 @@ bool js_cocos2dx_ui_ImageView_createInstance(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_ImageView_createInstance : wrong number of arguments"); @@ -4696,7 +4955,7 @@ bool js_cocos2dx_ui_ImageView_createInstance(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_ui_ImageView_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::ImageView* cobj = new (std::nothrow) cocos2d::ui::ImageView(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -4710,13 +4969,16 @@ bool js_cocos2dx_ui_ImageView_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::ImageView"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::ImageView"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -4729,21 +4991,21 @@ void js_cocos2d_ui_ImageView_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_ImageView_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ui::ImageView *nobj = new (std::nothrow) cocos2d::ui::ImageView(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::ImageView"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::ImageView"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_ImageView(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ui_ImageView(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ui_ImageView_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ui_ImageView_class->name = "ImageView"; jsb_cocos2d_ui_ImageView_class->addProperty = JS_PropertyStub; @@ -4757,8 +5019,8 @@ void js_register_cocos2dx_ui_ImageView(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_ImageView_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -4781,7 +5043,7 @@ void js_register_cocos2dx_ui_ImageView(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_ImageView_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Widget_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), jsb_cocos2d_ui_ImageView_class, js_cocos2dx_ui_ImageView_constructor, 0, // constructor properties, @@ -4812,45 +5074,45 @@ JSObject *jsb_cocos2d_ui_Text_prototype; bool js_cocos2dx_ui_Text_enableShadow(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_enableShadow : Invalid Native Object"); if (argc == 0) { cobj->enableShadow(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 1) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_enableShadow : Error processing arguments"); cobj->enableShadow(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { cocos2d::Color4B arg0; cocos2d::Size arg1; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_enableShadow : Error processing arguments"); cobj->enableShadow(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 3) { cocos2d::Color4B arg0; cocos2d::Size arg1; int arg2; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_enableShadow : Error processing arguments"); cobj->enableShadow(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4859,7 +5121,8 @@ bool js_cocos2dx_ui_Text_enableShadow(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_getFontSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_getFontSize : Invalid Native Object"); @@ -4867,7 +5130,7 @@ bool js_cocos2dx_ui_Text_getFontSize(JSContext *cx, uint32_t argc, jsval *vp) int ret = cobj->getFontSize(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4876,7 +5139,8 @@ bool js_cocos2dx_ui_Text_getFontSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_getString(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_getString : Invalid Native Object"); @@ -4884,7 +5148,7 @@ bool js_cocos2dx_ui_Text_getString(JSContext *cx, uint32_t argc, jsval *vp) const std::string& ret = cobj->getString(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4893,13 +5157,14 @@ bool js_cocos2dx_ui_Text_getString(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_disableEffect(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_disableEffect : Invalid Native Object"); if (argc == 0) { cobj->disableEffect(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4908,7 +5173,8 @@ bool js_cocos2dx_ui_Text_disableEffect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_getTextColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_getTextColor : Invalid Native Object"); @@ -4916,7 +5182,7 @@ bool js_cocos2dx_ui_Text_getTextColor(JSContext *cx, uint32_t argc, jsval *vp) const cocos2d::Color4B& ret = cobj->getTextColor(); jsval jsret = JSVAL_NULL; jsret = cccolor4b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4925,18 +5191,18 @@ bool js_cocos2dx_ui_Text_getTextColor(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_setTextVerticalAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_setTextVerticalAlignment : Invalid Native Object"); if (argc == 1) { cocos2d::TextVAlignment arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_setTextVerticalAlignment : Error processing arguments"); cobj->setTextVerticalAlignment(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4945,18 +5211,18 @@ bool js_cocos2dx_ui_Text_setTextVerticalAlignment(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Text_setFontName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_setFontName : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_setFontName : Error processing arguments"); cobj->setFontName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4965,18 +5231,18 @@ bool js_cocos2dx_ui_Text_setFontName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_setTouchScaleChangeEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_setTouchScaleChangeEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_setTouchScaleChangeEnabled : Error processing arguments"); cobj->setTouchScaleChangeEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4985,18 +5251,18 @@ bool js_cocos2dx_ui_Text_setTouchScaleChangeEnabled(JSContext *cx, uint32_t argc } bool js_cocos2dx_ui_Text_setString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_setString : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_setString : Error processing arguments"); cobj->setString(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5005,9 +5271,9 @@ bool js_cocos2dx_ui_Text_setString(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_init : Invalid Native Object"); @@ -5015,14 +5281,14 @@ bool js_cocos2dx_ui_Text_init(JSContext *cx, uint32_t argc, jsval *vp) std::string arg0; std::string arg1; int arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_init : Error processing arguments"); bool ret = cobj->init(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5031,7 +5297,8 @@ bool js_cocos2dx_ui_Text_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_isTouchScaleChangeEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_isTouchScaleChangeEnabled : Invalid Native Object"); @@ -5039,7 +5306,7 @@ bool js_cocos2dx_ui_Text_isTouchScaleChangeEnabled(JSContext *cx, uint32_t argc, bool ret = cobj->isTouchScaleChangeEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5048,7 +5315,8 @@ bool js_cocos2dx_ui_Text_isTouchScaleChangeEnabled(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Text_getFontName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_getFontName : Invalid Native Object"); @@ -5056,7 +5324,7 @@ bool js_cocos2dx_ui_Text_getFontName(JSContext *cx, uint32_t argc, jsval *vp) const std::string& ret = cobj->getFontName(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5065,18 +5333,18 @@ bool js_cocos2dx_ui_Text_getFontName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_setTextAreaSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_setTextAreaSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_setTextAreaSize : Error processing arguments"); cobj->setTextAreaSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5085,7 +5353,8 @@ bool js_cocos2dx_ui_Text_setTextAreaSize(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_Text_getStringLength(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_getStringLength : Invalid Native Object"); @@ -5093,37 +5362,55 @@ bool js_cocos2dx_ui_Text_getStringLength(JSContext *cx, uint32_t argc, jsval *vp ssize_t ret = cobj->getStringLength(); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Text_getStringLength : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_ui_Text_getAutoRenderSize(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_getAutoRenderSize : Invalid Native Object"); + if (argc == 0) { + cocos2d::Size ret = cobj->getAutoRenderSize(); + jsval jsret = JSVAL_NULL; + jsret = ccsize_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Text_getAutoRenderSize : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_ui_Text_enableOutline(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_enableOutline : Invalid Native Object"); if (argc == 1) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_enableOutline : Error processing arguments"); cobj->enableOutline(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { cocos2d::Color4B arg0; int arg1; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_enableOutline : Error processing arguments"); cobj->enableOutline(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5132,7 +5419,8 @@ bool js_cocos2dx_ui_Text_enableOutline(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_getType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_getType : Invalid Native Object"); @@ -5140,7 +5428,7 @@ bool js_cocos2dx_ui_Text_getType(JSContext *cx, uint32_t argc, jsval *vp) int ret = (int)cobj->getType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5149,7 +5437,8 @@ bool js_cocos2dx_ui_Text_getType(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_getTextHorizontalAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_getTextHorizontalAlignment : Invalid Native Object"); @@ -5157,7 +5446,7 @@ bool js_cocos2dx_ui_Text_getTextHorizontalAlignment(JSContext *cx, uint32_t argc int ret = (int)cobj->getTextHorizontalAlignment(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5166,18 +5455,18 @@ bool js_cocos2dx_ui_Text_getTextHorizontalAlignment(JSContext *cx, uint32_t argc } bool js_cocos2dx_ui_Text_setFontSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_setFontSize : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_setFontSize : Error processing arguments"); cobj->setFontSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5186,18 +5475,18 @@ bool js_cocos2dx_ui_Text_setFontSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_setTextColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_setTextColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_setTextColor : Error processing arguments"); cobj->setTextColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5206,18 +5495,18 @@ bool js_cocos2dx_ui_Text_setTextColor(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_enableGlow(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_enableGlow : Invalid Native Object"); if (argc == 1) { cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_enableGlow : Error processing arguments"); cobj->enableGlow(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5226,7 +5515,8 @@ bool js_cocos2dx_ui_Text_enableGlow(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_getTextVerticalAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_getTextVerticalAlignment : Invalid Native Object"); @@ -5234,7 +5524,7 @@ bool js_cocos2dx_ui_Text_getTextVerticalAlignment(JSContext *cx, uint32_t argc, int ret = (int)cobj->getTextVerticalAlignment(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5243,7 +5533,8 @@ bool js_cocos2dx_ui_Text_getTextVerticalAlignment(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Text_getTextAreaSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_getTextAreaSize : Invalid Native Object"); @@ -5251,7 +5542,7 @@ bool js_cocos2dx_ui_Text_getTextAreaSize(JSContext *cx, uint32_t argc, jsval *vp const cocos2d::Size& ret = cobj->getTextAreaSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5260,18 +5551,18 @@ bool js_cocos2dx_ui_Text_getTextAreaSize(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_Text_setTextHorizontalAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Text* cobj = (cocos2d::ui::Text *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Text_setTextHorizontalAlignment : Invalid Native Object"); if (argc == 1) { cocos2d::TextHAlignment arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Text_setTextHorizontalAlignment : Error processing arguments"); cobj->setTextHorizontalAlignment(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5280,19 +5571,19 @@ bool js_cocos2dx_ui_Text_setTextHorizontalAlignment(JSContext *cx, uint32_t argc } bool js_cocos2dx_ui_Text_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } int arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } cocos2d::ui::Text* ret = cocos2d::ui::Text::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -5304,7 +5595,7 @@ bool js_cocos2dx_ui_Text_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -5321,7 +5612,7 @@ bool js_cocos2dx_ui_Text_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -5330,6 +5621,7 @@ bool js_cocos2dx_ui_Text_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Text_createInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Ref* ret = cocos2d::ui::Text::createInstance(); jsval jsret = JSVAL_NULL; @@ -5341,7 +5633,7 @@ bool js_cocos2dx_ui_Text_createInstance(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Text_createInstance : wrong number of arguments"); @@ -5350,7 +5642,7 @@ bool js_cocos2dx_ui_Text_createInstance(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ui_Text_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::Text* cobj = new (std::nothrow) cocos2d::ui::Text(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -5364,13 +5656,16 @@ bool js_cocos2dx_ui_Text_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Text"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Text"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -5383,21 +5678,21 @@ void js_cocos2d_ui_Text_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_Text_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ui::Text *nobj = new (std::nothrow) cocos2d::ui::Text(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Text"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Text"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_Text(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ui_Text(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ui_Text_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ui_Text_class->name = "Text"; jsb_cocos2d_ui_Text_class->addProperty = JS_PropertyStub; @@ -5411,8 +5706,8 @@ void js_register_cocos2dx_ui_Text(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_Text_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -5430,6 +5725,7 @@ void js_register_cocos2dx_ui_Text(JSContext *cx, JSObject *global) { JS_FN("getFontName", js_cocos2dx_ui_Text_getFontName, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setTextAreaSize", js_cocos2dx_ui_Text_setTextAreaSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getStringLength", js_cocos2dx_ui_Text_getStringLength, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getAutoRenderSize", js_cocos2dx_ui_Text_getAutoRenderSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("enableOutline", js_cocos2dx_ui_Text_enableOutline, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getType", js_cocos2dx_ui_Text_getType, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getTextHorizontalAlignment", js_cocos2dx_ui_Text_getTextHorizontalAlignment, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -5451,7 +5747,7 @@ void js_register_cocos2dx_ui_Text(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_Text_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Widget_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), jsb_cocos2d_ui_Text_class, js_cocos2dx_ui_Text_constructor, 0, // constructor properties, @@ -5482,7 +5778,8 @@ JSObject *jsb_cocos2d_ui_TextAtlas_prototype; bool js_cocos2dx_ui_TextAtlas_getStringLength(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextAtlas* cobj = (cocos2d::ui::TextAtlas *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextAtlas_getStringLength : Invalid Native Object"); @@ -5490,7 +5787,7 @@ bool js_cocos2dx_ui_TextAtlas_getStringLength(JSContext *cx, uint32_t argc, jsva ssize_t ret = cobj->getStringLength(); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5499,7 +5796,8 @@ bool js_cocos2dx_ui_TextAtlas_getStringLength(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_TextAtlas_getString(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextAtlas* cobj = (cocos2d::ui::TextAtlas *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextAtlas_getString : Invalid Native Object"); @@ -5507,7 +5805,7 @@ bool js_cocos2dx_ui_TextAtlas_getString(JSContext *cx, uint32_t argc, jsval *vp) const std::string& ret = cobj->getString(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5516,18 +5814,18 @@ bool js_cocos2dx_ui_TextAtlas_getString(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_TextAtlas_setString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextAtlas* cobj = (cocos2d::ui::TextAtlas *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextAtlas_setString : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextAtlas_setString : Error processing arguments"); cobj->setString(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5536,9 +5834,9 @@ bool js_cocos2dx_ui_TextAtlas_setString(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_TextAtlas_setProperty(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextAtlas* cobj = (cocos2d::ui::TextAtlas *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextAtlas_setProperty : Invalid Native Object"); @@ -5548,14 +5846,14 @@ bool js_cocos2dx_ui_TextAtlas_setProperty(JSContext *cx, uint32_t argc, jsval *v int arg2; int arg3; std::string arg4; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); - ok &= jsval_to_std_string(cx, argv[4], &arg4); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); + ok &= jsval_to_std_string(cx, args.get(4), &arg4); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextAtlas_setProperty : Error processing arguments"); cobj->setProperty(arg0, arg1, arg2, arg3, arg4); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5564,13 +5862,14 @@ bool js_cocos2dx_ui_TextAtlas_setProperty(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_TextAtlas_adaptRenderers(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextAtlas* cobj = (cocos2d::ui::TextAtlas *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextAtlas_adaptRenderers : Invalid Native Object"); if (argc == 0) { cobj->adaptRenderers(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5579,25 +5878,25 @@ bool js_cocos2dx_ui_TextAtlas_adaptRenderers(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_TextAtlas_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 5) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } int arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); if (!ok) { ok = true; break; } int arg3; - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); if (!ok) { ok = true; break; } std::string arg4; - ok &= jsval_to_std_string(cx, argv[4], &arg4); + ok &= jsval_to_std_string(cx, args.get(4), &arg4); if (!ok) { ok = true; break; } cocos2d::ui::TextAtlas* ret = cocos2d::ui::TextAtlas::create(arg0, arg1, arg2, arg3, arg4); jsval jsret = JSVAL_NULL; @@ -5609,7 +5908,7 @@ bool js_cocos2dx_ui_TextAtlas_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -5626,7 +5925,7 @@ bool js_cocos2dx_ui_TextAtlas_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -5635,6 +5934,7 @@ bool js_cocos2dx_ui_TextAtlas_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_TextAtlas_createInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Ref* ret = cocos2d::ui::TextAtlas::createInstance(); jsval jsret = JSVAL_NULL; @@ -5646,7 +5946,7 @@ bool js_cocos2dx_ui_TextAtlas_createInstance(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_TextAtlas_createInstance : wrong number of arguments"); @@ -5655,7 +5955,7 @@ bool js_cocos2dx_ui_TextAtlas_createInstance(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_ui_TextAtlas_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::TextAtlas* cobj = new (std::nothrow) cocos2d::ui::TextAtlas(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -5669,13 +5969,16 @@ bool js_cocos2dx_ui_TextAtlas_constructor(JSContext *cx, uint32_t argc, jsval *v CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::TextAtlas"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::TextAtlas"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -5688,21 +5991,21 @@ void js_cocos2d_ui_TextAtlas_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_TextAtlas_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ui::TextAtlas *nobj = new (std::nothrow) cocos2d::ui::TextAtlas(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::TextAtlas"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::TextAtlas"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_TextAtlas(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ui_TextAtlas(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ui_TextAtlas_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ui_TextAtlas_class->name = "TextAtlas"; jsb_cocos2d_ui_TextAtlas_class->addProperty = JS_PropertyStub; @@ -5716,8 +6019,8 @@ void js_register_cocos2dx_ui_TextAtlas(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_TextAtlas_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -5738,7 +6041,7 @@ void js_register_cocos2dx_ui_TextAtlas(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_TextAtlas_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Widget_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), jsb_cocos2d_ui_TextAtlas_class, js_cocos2dx_ui_TextAtlas_constructor, 0, // constructor properties, @@ -5769,18 +6072,18 @@ JSObject *jsb_cocos2d_ui_LoadingBar_prototype; bool js_cocos2dx_ui_LoadingBar_setPercent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LoadingBar* cobj = (cocos2d::ui::LoadingBar *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LoadingBar_setPercent : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LoadingBar_setPercent : Error processing arguments"); cobj->setPercent(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5789,28 +6092,28 @@ bool js_cocos2dx_ui_LoadingBar_setPercent(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_LoadingBar_loadTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LoadingBar* cobj = (cocos2d::ui::LoadingBar *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LoadingBar_loadTexture : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LoadingBar_loadTexture : Error processing arguments"); cobj->loadTexture(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LoadingBar_loadTexture : Error processing arguments"); cobj->loadTexture(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5819,18 +6122,18 @@ bool js_cocos2dx_ui_LoadingBar_loadTexture(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_LoadingBar_setDirection(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LoadingBar* cobj = (cocos2d::ui::LoadingBar *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LoadingBar_setDirection : Invalid Native Object"); if (argc == 1) { cocos2d::ui::LoadingBar::Direction arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LoadingBar_setDirection : Error processing arguments"); cobj->setDirection(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5839,18 +6142,18 @@ bool js_cocos2dx_ui_LoadingBar_setDirection(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_LoadingBar_setScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LoadingBar* cobj = (cocos2d::ui::LoadingBar *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LoadingBar_setScale9Enabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LoadingBar_setScale9Enabled : Error processing arguments"); cobj->setScale9Enabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5859,18 +6162,18 @@ bool js_cocos2dx_ui_LoadingBar_setScale9Enabled(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ui_LoadingBar_setCapInsets(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LoadingBar* cobj = (cocos2d::ui::LoadingBar *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LoadingBar_setCapInsets : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LoadingBar_setCapInsets : Error processing arguments"); cobj->setCapInsets(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5879,7 +6182,8 @@ bool js_cocos2dx_ui_LoadingBar_setCapInsets(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_LoadingBar_getDirection(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LoadingBar* cobj = (cocos2d::ui::LoadingBar *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LoadingBar_getDirection : Invalid Native Object"); @@ -5887,7 +6191,7 @@ bool js_cocos2dx_ui_LoadingBar_getDirection(JSContext *cx, uint32_t argc, jsval int ret = (int)cobj->getDirection(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5896,7 +6200,8 @@ bool js_cocos2dx_ui_LoadingBar_getDirection(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_LoadingBar_getCapInsets(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LoadingBar* cobj = (cocos2d::ui::LoadingBar *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LoadingBar_getCapInsets : Invalid Native Object"); @@ -5904,7 +6209,7 @@ bool js_cocos2dx_ui_LoadingBar_getCapInsets(JSContext *cx, uint32_t argc, jsval const cocos2d::Rect& ret = cobj->getCapInsets(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5913,7 +6218,8 @@ bool js_cocos2dx_ui_LoadingBar_getCapInsets(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_LoadingBar_isScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LoadingBar* cobj = (cocos2d::ui::LoadingBar *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LoadingBar_isScale9Enabled : Invalid Native Object"); @@ -5921,7 +6227,7 @@ bool js_cocos2dx_ui_LoadingBar_isScale9Enabled(JSContext *cx, uint32_t argc, jsv bool ret = cobj->isScale9Enabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5930,7 +6236,8 @@ bool js_cocos2dx_ui_LoadingBar_isScale9Enabled(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_LoadingBar_getPercent(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::LoadingBar* cobj = (cocos2d::ui::LoadingBar *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LoadingBar_getPercent : Invalid Native Object"); @@ -5938,7 +6245,7 @@ bool js_cocos2dx_ui_LoadingBar_getPercent(JSContext *cx, uint32_t argc, jsval *v double ret = cobj->getPercent(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5947,13 +6254,13 @@ bool js_cocos2dx_ui_LoadingBar_getPercent(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_LoadingBar_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::ui::LoadingBar* ret = cocos2d::ui::LoadingBar::create(arg0); jsval jsret = JSVAL_NULL; @@ -5965,17 +6272,17 @@ bool js_cocos2dx_ui_LoadingBar_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); if (!ok) { ok = true; break; } cocos2d::ui::LoadingBar* ret = cocos2d::ui::LoadingBar::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -5987,7 +6294,7 @@ bool js_cocos2dx_ui_LoadingBar_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -6004,7 +6311,55 @@ bool js_cocos2dx_ui_LoadingBar_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::ui::Widget::TextureResType arg1; + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + if (!ok) { ok = true; break; } + cocos2d::ui::LoadingBar* ret = cocos2d::ui::LoadingBar::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::LoadingBar*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + do { + if (argc == 3) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::ui::Widget::TextureResType arg1; + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + if (!ok) { ok = true; break; } + double arg2; + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + if (!ok) { ok = true; break; } + cocos2d::ui::LoadingBar* ret = cocos2d::ui::LoadingBar::create(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::LoadingBar*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); return true; } } while (0); @@ -6013,6 +6368,7 @@ bool js_cocos2dx_ui_LoadingBar_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_LoadingBar_createInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Ref* ret = cocos2d::ui::LoadingBar::createInstance(); jsval jsret = JSVAL_NULL; @@ -6024,7 +6380,7 @@ bool js_cocos2dx_ui_LoadingBar_createInstance(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_LoadingBar_createInstance : wrong number of arguments"); @@ -6033,7 +6389,7 @@ bool js_cocos2dx_ui_LoadingBar_createInstance(JSContext *cx, uint32_t argc, jsva bool js_cocos2dx_ui_LoadingBar_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::LoadingBar* cobj = new (std::nothrow) cocos2d::ui::LoadingBar(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -6047,13 +6403,16 @@ bool js_cocos2dx_ui_LoadingBar_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::LoadingBar"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::LoadingBar"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -6066,21 +6425,21 @@ void js_cocos2d_ui_LoadingBar_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_LoadingBar_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ui::LoadingBar *nobj = new (std::nothrow) cocos2d::ui::LoadingBar(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::LoadingBar"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::LoadingBar"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_LoadingBar(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ui_LoadingBar(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ui_LoadingBar_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ui_LoadingBar_class->name = "LoadingBar"; jsb_cocos2d_ui_LoadingBar_class->addProperty = JS_PropertyStub; @@ -6094,8 +6453,8 @@ void js_register_cocos2dx_ui_LoadingBar(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_LoadingBar_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -6120,7 +6479,7 @@ void js_register_cocos2dx_ui_LoadingBar(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_LoadingBar_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Widget_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), jsb_cocos2d_ui_LoadingBar_class, js_cocos2dx_ui_LoadingBar_constructor, 0, // constructor properties, @@ -6151,20 +6510,20 @@ JSObject *jsb_cocos2d_ui_ScrollView_prototype; bool js_cocos2dx_ui_ScrollView_scrollToTop(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_scrollToTop : Invalid Native Object"); if (argc == 2) { double arg0; bool arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_scrollToTop : Error processing arguments"); cobj->scrollToTop(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6173,9 +6532,9 @@ bool js_cocos2dx_ui_ScrollView_scrollToTop(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_ScrollView_scrollToPercentHorizontal(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_scrollToPercentHorizontal : Invalid Native Object"); @@ -6183,12 +6542,12 @@ bool js_cocos2dx_ui_ScrollView_scrollToPercentHorizontal(JSContext *cx, uint32_t double arg0; double arg1; bool arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + arg2 = JS::ToBoolean(args.get(2)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_scrollToPercentHorizontal : Error processing arguments"); cobj->scrollToPercentHorizontal(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6197,7 +6556,8 @@ bool js_cocos2dx_ui_ScrollView_scrollToPercentHorizontal(JSContext *cx, uint32_t } bool js_cocos2dx_ui_ScrollView_isInertiaScrollEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_isInertiaScrollEnabled : Invalid Native Object"); @@ -6205,7 +6565,7 @@ bool js_cocos2dx_ui_ScrollView_isInertiaScrollEnabled(JSContext *cx, uint32_t ar bool ret = cobj->isInertiaScrollEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6214,9 +6574,9 @@ bool js_cocos2dx_ui_ScrollView_isInertiaScrollEnabled(JSContext *cx, uint32_t ar } bool js_cocos2dx_ui_ScrollView_scrollToPercentBothDirection(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_scrollToPercentBothDirection : Invalid Native Object"); @@ -6224,12 +6584,12 @@ bool js_cocos2dx_ui_ScrollView_scrollToPercentBothDirection(JSContext *cx, uint3 cocos2d::Vec2 arg0; double arg1; bool arg2; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + arg2 = JS::ToBoolean(args.get(2)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_scrollToPercentBothDirection : Error processing arguments"); cobj->scrollToPercentBothDirection(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6238,7 +6598,8 @@ bool js_cocos2dx_ui_ScrollView_scrollToPercentBothDirection(JSContext *cx, uint3 } bool js_cocos2dx_ui_ScrollView_getDirection(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_getDirection : Invalid Native Object"); @@ -6246,7 +6607,7 @@ bool js_cocos2dx_ui_ScrollView_getDirection(JSContext *cx, uint32_t argc, jsval int ret = (int)cobj->getDirection(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6255,20 +6616,20 @@ bool js_cocos2dx_ui_ScrollView_getDirection(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_ScrollView_scrollToBottomLeft(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_scrollToBottomLeft : Invalid Native Object"); if (argc == 2) { double arg0; bool arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_scrollToBottomLeft : Error processing arguments"); cobj->scrollToBottomLeft(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6277,7 +6638,8 @@ bool js_cocos2dx_ui_ScrollView_scrollToBottomLeft(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_ScrollView_getInnerContainer(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_getInnerContainer : Invalid Native Object"); @@ -6292,7 +6654,7 @@ bool js_cocos2dx_ui_ScrollView_getInnerContainer(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6301,13 +6663,14 @@ bool js_cocos2dx_ui_ScrollView_getInnerContainer(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_ScrollView_jumpToBottom(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_jumpToBottom : Invalid Native Object"); if (argc == 0) { cobj->jumpToBottom(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6316,18 +6679,18 @@ bool js_cocos2dx_ui_ScrollView_jumpToBottom(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_ScrollView_setDirection(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_setDirection : Invalid Native Object"); if (argc == 1) { cocos2d::ui::ScrollView::Direction arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_setDirection : Error processing arguments"); cobj->setDirection(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6336,20 +6699,20 @@ bool js_cocos2dx_ui_ScrollView_setDirection(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_ScrollView_scrollToTopLeft(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_scrollToTopLeft : Invalid Native Object"); if (argc == 2) { double arg0; bool arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_scrollToTopLeft : Error processing arguments"); cobj->scrollToTopLeft(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6358,13 +6721,14 @@ bool js_cocos2dx_ui_ScrollView_scrollToTopLeft(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_ScrollView_jumpToTopRight(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_jumpToTopRight : Invalid Native Object"); if (argc == 0) { cobj->jumpToTopRight(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6373,13 +6737,14 @@ bool js_cocos2dx_ui_ScrollView_jumpToTopRight(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_ScrollView_jumpToBottomLeft(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_jumpToBottomLeft : Invalid Native Object"); if (argc == 0) { cobj->jumpToBottomLeft(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6388,18 +6753,18 @@ bool js_cocos2dx_ui_ScrollView_jumpToBottomLeft(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ui_ScrollView_setInnerContainerSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_setInnerContainerSize : Invalid Native Object"); if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_setInnerContainerSize : Error processing arguments"); cobj->setInnerContainerSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6408,7 +6773,8 @@ bool js_cocos2dx_ui_ScrollView_setInnerContainerSize(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_ScrollView_getInnerContainerSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_getInnerContainerSize : Invalid Native Object"); @@ -6416,7 +6782,7 @@ bool js_cocos2dx_ui_ScrollView_getInnerContainerSize(JSContext *cx, uint32_t arg const cocos2d::Size& ret = cobj->getInnerContainerSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6425,7 +6791,8 @@ bool js_cocos2dx_ui_ScrollView_getInnerContainerSize(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_ScrollView_isBounceEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_isBounceEnabled : Invalid Native Object"); @@ -6433,7 +6800,7 @@ bool js_cocos2dx_ui_ScrollView_isBounceEnabled(JSContext *cx, uint32_t argc, jsv bool ret = cobj->isBounceEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6442,18 +6809,18 @@ bool js_cocos2dx_ui_ScrollView_isBounceEnabled(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_ScrollView_jumpToPercentVertical(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_jumpToPercentVertical : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_jumpToPercentVertical : Error processing arguments"); cobj->jumpToPercentVertical(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6462,18 +6829,18 @@ bool js_cocos2dx_ui_ScrollView_jumpToPercentVertical(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_ScrollView_setInertiaScrollEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_setInertiaScrollEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_setInertiaScrollEnabled : Error processing arguments"); cobj->setInertiaScrollEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6482,13 +6849,14 @@ bool js_cocos2dx_ui_ScrollView_setInertiaScrollEnabled(JSContext *cx, uint32_t a } bool js_cocos2dx_ui_ScrollView_jumpToTopLeft(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_jumpToTopLeft : Invalid Native Object"); if (argc == 0) { cobj->jumpToTopLeft(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6497,18 +6865,18 @@ bool js_cocos2dx_ui_ScrollView_jumpToTopLeft(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_ScrollView_jumpToPercentHorizontal(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_jumpToPercentHorizontal : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_jumpToPercentHorizontal : Error processing arguments"); cobj->jumpToPercentHorizontal(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6517,13 +6885,14 @@ bool js_cocos2dx_ui_ScrollView_jumpToPercentHorizontal(JSContext *cx, uint32_t a } bool js_cocos2dx_ui_ScrollView_jumpToBottomRight(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_jumpToBottomRight : Invalid Native Object"); if (argc == 0) { cobj->jumpToBottomRight(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6532,18 +6901,18 @@ bool js_cocos2dx_ui_ScrollView_jumpToBottomRight(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_ScrollView_setBounceEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_setBounceEnabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_setBounceEnabled : Error processing arguments"); cobj->setBounceEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6552,13 +6921,14 @@ bool js_cocos2dx_ui_ScrollView_setBounceEnabled(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ui_ScrollView_jumpToTop(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_jumpToTop : Invalid Native Object"); if (argc == 0) { cobj->jumpToTop(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6567,20 +6937,20 @@ bool js_cocos2dx_ui_ScrollView_jumpToTop(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_ScrollView_scrollToLeft(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_scrollToLeft : Invalid Native Object"); if (argc == 2) { double arg0; bool arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_scrollToLeft : Error processing arguments"); cobj->scrollToLeft(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6589,18 +6959,18 @@ bool js_cocos2dx_ui_ScrollView_scrollToLeft(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_ScrollView_jumpToPercentBothDirection(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_jumpToPercentBothDirection : Invalid Native Object"); if (argc == 1) { cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_jumpToPercentBothDirection : Error processing arguments"); cobj->jumpToPercentBothDirection(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6609,9 +6979,9 @@ bool js_cocos2dx_ui_ScrollView_jumpToPercentBothDirection(JSContext *cx, uint32_ } bool js_cocos2dx_ui_ScrollView_scrollToPercentVertical(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_scrollToPercentVertical : Invalid Native Object"); @@ -6619,12 +6989,12 @@ bool js_cocos2dx_ui_ScrollView_scrollToPercentVertical(JSContext *cx, uint32_t a double arg0; double arg1; bool arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + ok &= JS::ToNumber( cx, args.get(1), &arg1) && !isnan(arg1); + arg2 = JS::ToBoolean(args.get(2)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_scrollToPercentVertical : Error processing arguments"); cobj->scrollToPercentVertical(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6633,20 +7003,20 @@ bool js_cocos2dx_ui_ScrollView_scrollToPercentVertical(JSContext *cx, uint32_t a } bool js_cocos2dx_ui_ScrollView_scrollToBottom(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_scrollToBottom : Invalid Native Object"); if (argc == 2) { double arg0; bool arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_scrollToBottom : Error processing arguments"); cobj->scrollToBottom(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6655,20 +7025,20 @@ bool js_cocos2dx_ui_ScrollView_scrollToBottom(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_ScrollView_scrollToBottomRight(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_scrollToBottomRight : Invalid Native Object"); if (argc == 2) { double arg0; bool arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_scrollToBottomRight : Error processing arguments"); cobj->scrollToBottomRight(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6677,13 +7047,14 @@ bool js_cocos2dx_ui_ScrollView_scrollToBottomRight(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_ScrollView_jumpToLeft(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_jumpToLeft : Invalid Native Object"); if (argc == 0) { cobj->jumpToLeft(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6692,20 +7063,20 @@ bool js_cocos2dx_ui_ScrollView_jumpToLeft(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_ScrollView_scrollToRight(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_scrollToRight : Invalid Native Object"); if (argc == 2) { double arg0; bool arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_scrollToRight : Error processing arguments"); cobj->scrollToRight(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6714,13 +7085,14 @@ bool js_cocos2dx_ui_ScrollView_scrollToRight(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_ScrollView_jumpToRight(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_jumpToRight : Invalid Native Object"); if (argc == 0) { cobj->jumpToRight(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6729,20 +7101,20 @@ bool js_cocos2dx_ui_ScrollView_jumpToRight(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_ScrollView_scrollToTopRight(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_scrollToTopRight : Invalid Native Object"); if (argc == 2) { double arg0; bool arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_scrollToTopRight : Error processing arguments"); cobj->scrollToTopRight(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6751,6 +7123,7 @@ bool js_cocos2dx_ui_ScrollView_scrollToTopRight(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ui_ScrollView_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ui::ScrollView* ret = cocos2d::ui::ScrollView::create(); jsval jsret = JSVAL_NULL; @@ -6762,7 +7135,7 @@ bool js_cocos2dx_ui_ScrollView_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_create : wrong number of arguments"); @@ -6771,6 +7144,7 @@ bool js_cocos2dx_ui_ScrollView_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ui_ScrollView_createInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Ref* ret = cocos2d::ui::ScrollView::createInstance(); jsval jsret = JSVAL_NULL; @@ -6782,7 +7156,7 @@ bool js_cocos2dx_ui_ScrollView_createInstance(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_createInstance : wrong number of arguments"); @@ -6791,7 +7165,7 @@ bool js_cocos2dx_ui_ScrollView_createInstance(JSContext *cx, uint32_t argc, jsva bool js_cocos2dx_ui_ScrollView_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::ScrollView* cobj = new (std::nothrow) cocos2d::ui::ScrollView(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -6805,13 +7179,16 @@ bool js_cocos2dx_ui_ScrollView_constructor(JSContext *cx, uint32_t argc, jsval * CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::ScrollView"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::ScrollView"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -6824,21 +7201,21 @@ void js_cocos2d_ui_ScrollView_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_ScrollView_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ui::ScrollView *nobj = new (std::nothrow) cocos2d::ui::ScrollView(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::ScrollView"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::ScrollView"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_ScrollView(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ui_ScrollView(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ui_ScrollView_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ui_ScrollView_class->name = "ScrollView"; jsb_cocos2d_ui_ScrollView_class->addProperty = JS_PropertyStub; @@ -6852,8 +7229,8 @@ void js_register_cocos2dx_ui_ScrollView(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_ScrollView_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -6900,7 +7277,7 @@ void js_register_cocos2dx_ui_ScrollView(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_ScrollView_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Layout_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Layout_prototype), jsb_cocos2d_ui_ScrollView_class, js_cocos2dx_ui_ScrollView_constructor, 0, // constructor properties, @@ -6931,18 +7308,18 @@ JSObject *jsb_cocos2d_ui_ListView_prototype; bool js_cocos2dx_ui_ListView_getIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_getIndex : Invalid Native Object"); if (argc == 1) { cocos2d::ui::Widget* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); @@ -6951,7 +7328,7 @@ bool js_cocos2dx_ui_ListView_getIndex(JSContext *cx, uint32_t argc, jsval *vp) ssize_t ret = cobj->getIndex(arg0); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6960,13 +7337,14 @@ bool js_cocos2dx_ui_ListView_getIndex(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_ListView_removeAllItems(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_removeAllItems : Invalid Native Object"); if (argc == 0) { cobj->removeAllItems(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6975,18 +7353,18 @@ bool js_cocos2dx_ui_ListView_removeAllItems(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_ListView_setGravity(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_setGravity : Invalid Native Object"); if (argc == 1) { cocos2d::ui::ListView::Gravity arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ListView_setGravity : Error processing arguments"); cobj->setGravity(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -6995,25 +7373,25 @@ bool js_cocos2dx_ui_ListView_setGravity(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_ListView_pushBackCustomItem(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_pushBackCustomItem : Invalid Native Object"); if (argc == 1) { cocos2d::ui::Widget* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ListView_pushBackCustomItem : Error processing arguments"); cobj->pushBackCustomItem(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7022,7 +7400,8 @@ bool js_cocos2dx_ui_ListView_pushBackCustomItem(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ui_ListView_getItems(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_getItems : Invalid Native Object"); @@ -7030,7 +7409,7 @@ bool js_cocos2dx_ui_ListView_getItems(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vector& ret = cobj->getItems(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7039,18 +7418,18 @@ bool js_cocos2dx_ui_ListView_getItems(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_ListView_removeItem(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_removeItem : Invalid Native Object"); if (argc == 1) { ssize_t arg0; - ok &= jsval_to_ssize(cx, argv[0], &arg0); + ok &= jsval_to_ssize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ListView_removeItem : Error processing arguments"); cobj->removeItem(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7059,7 +7438,8 @@ bool js_cocos2dx_ui_ListView_removeItem(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_ListView_getCurSelectedIndex(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_getCurSelectedIndex : Invalid Native Object"); @@ -7067,7 +7447,7 @@ bool js_cocos2dx_ui_ListView_getCurSelectedIndex(JSContext *cx, uint32_t argc, j ssize_t ret = cobj->getCurSelectedIndex(); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7076,18 +7456,18 @@ bool js_cocos2dx_ui_ListView_getCurSelectedIndex(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_ListView_insertDefaultItem(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_insertDefaultItem : Invalid Native Object"); if (argc == 1) { ssize_t arg0; - ok &= jsval_to_ssize(cx, argv[0], &arg0); + ok &= jsval_to_ssize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ListView_insertDefaultItem : Error processing arguments"); cobj->insertDefaultItem(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7096,13 +7476,14 @@ bool js_cocos2dx_ui_ListView_insertDefaultItem(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_ListView_requestRefreshView(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_requestRefreshView : Invalid Native Object"); if (argc == 0) { cobj->requestRefreshView(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7111,18 +7492,18 @@ bool js_cocos2dx_ui_ListView_requestRefreshView(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ui_ListView_setItemsMargin(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_setItemsMargin : Invalid Native Object"); if (argc == 1) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ListView_setItemsMargin : Error processing arguments"); cobj->setItemsMargin(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7131,13 +7512,14 @@ bool js_cocos2dx_ui_ListView_setItemsMargin(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_ListView_refreshView(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_refreshView : Invalid Native Object"); if (argc == 0) { cobj->refreshView(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7146,13 +7528,14 @@ bool js_cocos2dx_ui_ListView_refreshView(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_ListView_removeLastItem(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_removeLastItem : Invalid Native Object"); if (argc == 0) { cobj->removeLastItem(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7161,7 +7544,8 @@ bool js_cocos2dx_ui_ListView_removeLastItem(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_ListView_getItemsMargin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_getItemsMargin : Invalid Native Object"); @@ -7169,7 +7553,7 @@ bool js_cocos2dx_ui_ListView_getItemsMargin(JSContext *cx, uint32_t argc, jsval double ret = cobj->getItemsMargin(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7178,15 +7562,15 @@ bool js_cocos2dx_ui_ListView_getItemsMargin(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_ListView_getItem(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_getItem : Invalid Native Object"); if (argc == 1) { ssize_t arg0; - ok &= jsval_to_ssize(cx, argv[0], &arg0); + ok &= jsval_to_ssize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ListView_getItem : Error processing arguments"); cocos2d::ui::Widget* ret = cobj->getItem(arg0); jsval jsret = JSVAL_NULL; @@ -7198,7 +7582,7 @@ bool js_cocos2dx_ui_ListView_getItem(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7207,25 +7591,25 @@ bool js_cocos2dx_ui_ListView_getItem(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_ListView_setItemModel(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_setItemModel : Invalid Native Object"); if (argc == 1) { cocos2d::ui::Widget* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ListView_setItemModel : Error processing arguments"); cobj->setItemModel(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7234,13 +7618,14 @@ bool js_cocos2dx_ui_ListView_setItemModel(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_ListView_doLayout(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_doLayout : Invalid Native Object"); if (argc == 0) { cobj->doLayout(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7249,13 +7634,14 @@ bool js_cocos2dx_ui_ListView_doLayout(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_ListView_pushBackDefaultItem(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_pushBackDefaultItem : Invalid Native Object"); if (argc == 0) { cobj->pushBackDefaultItem(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7264,9 +7650,9 @@ bool js_cocos2dx_ui_ListView_pushBackDefaultItem(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_ListView_insertCustomItem(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::ListView* cobj = (cocos2d::ui::ListView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ListView_insertCustomItem : Invalid Native Object"); @@ -7274,17 +7660,17 @@ bool js_cocos2dx_ui_ListView_insertCustomItem(JSContext *cx, uint32_t argc, jsva cocos2d::ui::Widget* arg0; ssize_t arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - ok &= jsval_to_ssize(cx, argv[1], &arg1); + ok &= jsval_to_ssize(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ListView_insertCustomItem : Error processing arguments"); cobj->insertCustomItem(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7293,6 +7679,7 @@ bool js_cocos2dx_ui_ListView_insertCustomItem(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_ListView_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ui::ListView* ret = cocos2d::ui::ListView::create(); jsval jsret = JSVAL_NULL; @@ -7304,7 +7691,7 @@ bool js_cocos2dx_ui_ListView_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_ListView_create : wrong number of arguments"); @@ -7313,6 +7700,7 @@ bool js_cocos2dx_ui_ListView_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ui_ListView_createInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Ref* ret = cocos2d::ui::ListView::createInstance(); jsval jsret = JSVAL_NULL; @@ -7324,7 +7712,7 @@ bool js_cocos2dx_ui_ListView_createInstance(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_ListView_createInstance : wrong number of arguments"); @@ -7333,7 +7721,7 @@ bool js_cocos2dx_ui_ListView_createInstance(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_ui_ListView_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::ListView* cobj = new (std::nothrow) cocos2d::ui::ListView(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -7347,13 +7735,16 @@ bool js_cocos2dx_ui_ListView_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::ListView"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::ListView"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -7366,21 +7757,21 @@ void js_cocos2d_ui_ListView_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_ListView_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ui::ListView *nobj = new (std::nothrow) cocos2d::ui::ListView(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::ListView"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::ListView"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_ListView(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ui_ListView(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ui_ListView_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ui_ListView_class->name = "ListView"; jsb_cocos2d_ui_ListView_class->addProperty = JS_PropertyStub; @@ -7394,8 +7785,8 @@ void js_register_cocos2dx_ui_ListView(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_ListView_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -7429,7 +7820,7 @@ void js_register_cocos2dx_ui_ListView(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_ListView_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_ScrollView_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_ScrollView_prototype), jsb_cocos2d_ui_ListView_class, js_cocos2dx_ui_ListView_constructor, 0, // constructor properties, @@ -7460,18 +7851,18 @@ JSObject *jsb_cocos2d_ui_Slider_prototype; bool js_cocos2dx_ui_Slider_setPercent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_setPercent : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_setPercent : Error processing arguments"); cobj->setPercent(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7480,28 +7871,28 @@ bool js_cocos2dx_ui_Slider_setPercent(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Slider_loadSlidBallTextureDisabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_loadSlidBallTextureDisabled : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_loadSlidBallTextureDisabled : Error processing arguments"); cobj->loadSlidBallTextureDisabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_loadSlidBallTextureDisabled : Error processing arguments"); cobj->loadSlidBallTextureDisabled(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7510,28 +7901,28 @@ bool js_cocos2dx_ui_Slider_loadSlidBallTextureDisabled(JSContext *cx, uint32_t a } bool js_cocos2dx_ui_Slider_loadSlidBallTextureNormal(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_loadSlidBallTextureNormal : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_loadSlidBallTextureNormal : Error processing arguments"); cobj->loadSlidBallTextureNormal(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_loadSlidBallTextureNormal : Error processing arguments"); cobj->loadSlidBallTextureNormal(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7540,28 +7931,28 @@ bool js_cocos2dx_ui_Slider_loadSlidBallTextureNormal(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_Slider_loadBarTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_loadBarTexture : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_loadBarTexture : Error processing arguments"); cobj->loadBarTexture(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_loadBarTexture : Error processing arguments"); cobj->loadBarTexture(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7570,28 +7961,28 @@ bool js_cocos2dx_ui_Slider_loadBarTexture(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_Slider_loadProgressBarTexture(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_loadProgressBarTexture : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_loadProgressBarTexture : Error processing arguments"); cobj->loadProgressBarTexture(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_loadProgressBarTexture : Error processing arguments"); cobj->loadProgressBarTexture(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7600,22 +7991,40 @@ bool js_cocos2dx_ui_Slider_loadProgressBarTexture(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Slider_loadSlidBallTextures(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_loadSlidBallTextures : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_loadSlidBallTextures : Error processing arguments"); + cobj->loadSlidBallTextures(arg0); + args.rval().setUndefined(); + return true; + } + if (argc == 2) { + std::string arg0; + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_loadSlidBallTextures : Error processing arguments"); + cobj->loadSlidBallTextures(arg0, arg1); + args.rval().setUndefined(); + return true; + } if (argc == 3) { std::string arg0; std::string arg1; std::string arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_std_string(cx, argv[2], &arg2); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_loadSlidBallTextures : Error processing arguments"); cobj->loadSlidBallTextures(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 4) { @@ -7623,33 +8032,33 @@ bool js_cocos2dx_ui_Slider_loadSlidBallTextures(JSContext *cx, uint32_t argc, js std::string arg1; std::string arg2; cocos2d::ui::Widget::TextureResType arg3; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - ok &= jsval_to_std_string(cx, argv[2], &arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= jsval_to_std_string(cx, args.get(2), &arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_loadSlidBallTextures : Error processing arguments"); cobj->loadSlidBallTextures(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Slider_loadSlidBallTextures : wrong number of arguments: %d, was expecting %d", argc, 3); + JS_ReportError(cx, "js_cocos2dx_ui_Slider_loadSlidBallTextures : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_ui_Slider_setCapInsetProgressBarRebderer(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_setCapInsetProgressBarRebderer : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_setCapInsetProgressBarRebderer : Error processing arguments"); cobj->setCapInsetProgressBarRebderer(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7658,18 +8067,18 @@ bool js_cocos2dx_ui_Slider_setCapInsetProgressBarRebderer(JSContext *cx, uint32_ } bool js_cocos2dx_ui_Slider_setCapInsetsBarRenderer(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_setCapInsetsBarRenderer : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_setCapInsetsBarRenderer : Error processing arguments"); cobj->setCapInsetsBarRenderer(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7678,7 +8087,8 @@ bool js_cocos2dx_ui_Slider_setCapInsetsBarRenderer(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Slider_getCapInsetsProgressBarRebderer(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_getCapInsetsProgressBarRebderer : Invalid Native Object"); @@ -7686,7 +8096,7 @@ bool js_cocos2dx_ui_Slider_getCapInsetsProgressBarRebderer(JSContext *cx, uint32 const cocos2d::Rect& ret = cobj->getCapInsetsProgressBarRebderer(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7695,68 +8105,106 @@ bool js_cocos2dx_ui_Slider_getCapInsetsProgressBarRebderer(JSContext *cx, uint32 } bool js_cocos2dx_ui_Slider_setScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_setScale9Enabled : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_setScale9Enabled : Error processing arguments"); cobj->setScale9Enabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Slider_setScale9Enabled : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_ui_Slider_setZoomScale(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_setZoomScale : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_setZoomScale : Error processing arguments"); + cobj->setZoomScale(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Slider_setZoomScale : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_ui_Slider_setCapInsets(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_setCapInsets : Invalid Native Object"); if (argc == 1) { cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_setCapInsets : Error processing arguments"); cobj->setCapInsets(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Slider_setCapInsets : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_ui_Slider_getZoomScale(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_getZoomScale : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getZoomScale(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Slider_getZoomScale : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_ui_Slider_loadSlidBallTexturePressed(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_loadSlidBallTexturePressed : Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_loadSlidBallTexturePressed : Error processing arguments"); cobj->loadSlidBallTexturePressed(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; cocos2d::ui::Widget::TextureResType arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Slider_loadSlidBallTexturePressed : Error processing arguments"); cobj->loadSlidBallTexturePressed(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7765,7 +8213,8 @@ bool js_cocos2dx_ui_Slider_loadSlidBallTexturePressed(JSContext *cx, uint32_t ar } bool js_cocos2dx_ui_Slider_isScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_isScale9Enabled : Invalid Native Object"); @@ -7773,7 +8222,7 @@ bool js_cocos2dx_ui_Slider_isScale9Enabled(JSContext *cx, uint32_t argc, jsval * bool ret = cobj->isScale9Enabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7782,7 +8231,8 @@ bool js_cocos2dx_ui_Slider_isScale9Enabled(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Slider_getCapInsetsBarRenderer(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_getCapInsetsBarRenderer : Invalid Native Object"); @@ -7790,7 +8240,7 @@ bool js_cocos2dx_ui_Slider_getCapInsetsBarRenderer(JSContext *cx, uint32_t argc, const cocos2d::Rect& ret = cobj->getCapInsetsBarRenderer(); jsval jsret = JSVAL_NULL; jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7799,7 +8249,8 @@ bool js_cocos2dx_ui_Slider_getCapInsetsBarRenderer(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Slider_getPercent(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::Slider* cobj = (cocos2d::ui::Slider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Slider_getPercent : Invalid Native Object"); @@ -7807,7 +8258,7 @@ bool js_cocos2dx_ui_Slider_getPercent(JSContext *cx, uint32_t argc, jsval *vp) int ret = cobj->getPercent(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -7816,26 +8267,79 @@ bool js_cocos2dx_ui_Slider_getPercent(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Slider_create(JSContext *cx, uint32_t argc, jsval *vp) { - if (argc == 0) { - cocos2d::ui::Slider* ret = cocos2d::ui::Slider::create(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Slider*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::ui::Slider* ret = cocos2d::ui::Slider::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Slider*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + do { + if (argc == 3) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::ui::Widget::TextureResType arg2; + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + if (!ok) { ok = true; break; } + cocos2d::ui::Slider* ret = cocos2d::ui::Slider::create(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Slider*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 0) { + cocos2d::ui::Slider* ret = cocos2d::ui::Slider::create(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Slider*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; } } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } JS_ReportError(cx, "js_cocos2dx_ui_Slider_create : wrong number of arguments"); return false; } - bool js_cocos2dx_ui_Slider_createInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Ref* ret = cocos2d::ui::Slider::createInstance(); jsval jsret = JSVAL_NULL; @@ -7847,7 +8351,7 @@ bool js_cocos2dx_ui_Slider_createInstance(JSContext *cx, uint32_t argc, jsval *v jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Slider_createInstance : wrong number of arguments"); @@ -7856,7 +8360,7 @@ bool js_cocos2dx_ui_Slider_createInstance(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_ui_Slider_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::ui::Slider* cobj = new (std::nothrow) cocos2d::ui::Slider(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -7870,13 +8374,16 @@ bool js_cocos2dx_ui_Slider_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Slider"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Slider"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -7889,21 +8396,21 @@ void js_cocos2d_ui_Slider_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_Slider_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); cocos2d::ui::Slider *nobj = new (std::nothrow) cocos2d::ui::Slider(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Slider"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Slider"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_Slider(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_ui_Slider(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_ui_Slider_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_ui_Slider_class->name = "Slider"; jsb_cocos2d_ui_Slider_class->addProperty = JS_PropertyStub; @@ -7917,8 +8424,8 @@ void js_register_cocos2dx_ui_Slider(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_Slider_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -7927,12 +8434,14 @@ void js_register_cocos2dx_ui_Slider(JSContext *cx, JSObject *global) { JS_FN("loadSlidBallTextureNormal", js_cocos2dx_ui_Slider_loadSlidBallTextureNormal, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("loadBarTexture", js_cocos2dx_ui_Slider_loadBarTexture, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("loadProgressBarTexture", js_cocos2dx_ui_Slider_loadProgressBarTexture, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("loadSlidBallTextures", js_cocos2dx_ui_Slider_loadSlidBallTextures, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("loadSlidBallTextures", js_cocos2dx_ui_Slider_loadSlidBallTextures, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setCapInsetProgressBarRebderer", js_cocos2dx_ui_Slider_setCapInsetProgressBarRebderer, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setCapInsetsBarRenderer", js_cocos2dx_ui_Slider_setCapInsetsBarRenderer, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getCapInsetsProgressBarRebderer", js_cocos2dx_ui_Slider_getCapInsetsProgressBarRebderer, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setScale9Enabled", js_cocos2dx_ui_Slider_setScale9Enabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setZoomScale", js_cocos2dx_ui_Slider_setZoomScale, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setCapInsets", js_cocos2dx_ui_Slider_setCapInsets, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getZoomScale", js_cocos2dx_ui_Slider_getZoomScale, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("loadSlidBallTexturePressed", js_cocos2dx_ui_Slider_loadSlidBallTexturePressed, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isScale9Enabled", js_cocos2dx_ui_Slider_isScale9Enabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getCapInsetsBarRenderer", js_cocos2dx_ui_Slider_getCapInsetsBarRenderer, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -7949,7 +8458,7 @@ void js_register_cocos2dx_ui_Slider(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_Slider_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Widget_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), jsb_cocos2d_ui_Slider_class, js_cocos2dx_ui_Slider_constructor, 0, // constructor properties, @@ -7975,1512 +8484,1446 @@ void js_register_cocos2dx_ui_Slider(JSContext *cx, JSObject *global) { } } -JSClass *jsb_cocos2d_ui_TextField_class; -JSObject *jsb_cocos2d_ui_TextField_prototype; +JSClass *jsb_cocos2d_ui_UICCTextField_class; +JSObject *jsb_cocos2d_ui_UICCTextField_prototype; -bool js_cocos2dx_ui_TextField_setAttachWithIME(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_onTextFieldAttachWithIME(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setAttachWithIME : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_onTextFieldAttachWithIME : Invalid Native Object"); if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setAttachWithIME : Error processing arguments"); - cobj->setAttachWithIME(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::TextFieldTTF* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::TextFieldTTF*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_onTextFieldAttachWithIME : Error processing arguments"); + bool ret = cobj->onTextFieldAttachWithIME(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setAttachWithIME : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_ui_TextField_getFontSize(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getFontSize : Invalid Native Object"); - if (argc == 0) { - int ret = cobj->getFontSize(); - jsval jsret = JSVAL_NULL; - jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_ui_TextField_getFontSize : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_onTextFieldAttachWithIME : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_getString(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_setPasswordText(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getString : Invalid Native Object"); - if (argc == 0) { - const std::string& ret = cobj->getString(); - jsval jsret = JSVAL_NULL; - jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_setPasswordText : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setPasswordText : Error processing arguments"); + cobj->setPasswordText(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_getString : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_setPasswordText : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_setPasswordStyleText(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_setAttachWithIME(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setPasswordStyleText : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_setAttachWithIME : Invalid Native Object"); if (argc == 1) { - const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setPasswordStyleText : Error processing arguments"); - cobj->setPasswordStyleText(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setAttachWithIME : Error processing arguments"); + cobj->setAttachWithIME(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setPasswordStyleText : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_setAttachWithIME : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_getDeleteBackward(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_getDeleteBackward(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getDeleteBackward : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_getDeleteBackward : Invalid Native Object"); if (argc == 0) { bool ret = cobj->getDeleteBackward(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_ui_TextField_getDeleteBackward : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} -bool js_cocos2dx_ui_TextField_getPlaceHolder(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getPlaceHolder : Invalid Native Object"); - if (argc == 0) { - const std::string& ret = cobj->getPlaceHolder(); - jsval jsret = JSVAL_NULL; - jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_getPlaceHolder : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_getDeleteBackward : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_getAttachWithIME(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_getAttachWithIME(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getAttachWithIME : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_getAttachWithIME : Invalid Native Object"); if (argc == 0) { bool ret = cobj->getAttachWithIME(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_getAttachWithIME : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_getAttachWithIME : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_setFontName(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_onTextFieldDeleteBackward(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setFontName : Invalid Native Object"); - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setFontName : Error processing arguments"); - cobj->setFontName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_onTextFieldDeleteBackward : Invalid Native Object"); + if (argc == 3) { + cocos2d::TextFieldTTF* arg0; + const char* arg1; + unsigned long arg2; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::TextFieldTTF*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); + ok &= jsval_to_ulong(cx, args.get(2), &arg2); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_onTextFieldDeleteBackward : Error processing arguments"); + bool ret = cobj->onTextFieldDeleteBackward(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setFontName : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_onTextFieldDeleteBackward : wrong number of arguments: %d, was expecting %d", argc, 3); return false; } -bool js_cocos2dx_ui_TextField_getInsertText(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_getInsertText(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getInsertText : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_getInsertText : Invalid Native Object"); if (argc == 0) { bool ret = cobj->getInsertText(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_getInsertText : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_getInsertText : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_setInsertText(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_deleteBackward(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setInsertText : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setInsertText : Error processing arguments"); - cobj->setInsertText(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_deleteBackward : Invalid Native Object"); + if (argc == 0) { + cobj->deleteBackward(); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setInsertText : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_deleteBackward : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_setString(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_setInsertText(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setString : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_setInsertText : Invalid Native Object"); if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setString : Error processing arguments"); - cobj->setString(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setInsertText : Error processing arguments"); + cobj->setInsertText(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setString : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_setInsertText : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_getDetachWithIME(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_getDetachWithIME(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getDetachWithIME : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_getDetachWithIME : Invalid Native Object"); if (argc == 0) { bool ret = cobj->getDetachWithIME(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_getDetachWithIME : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_getDetachWithIME : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_setTextVerticalAlignment(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_getCharCount(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setTextVerticalAlignment : Invalid Native Object"); - if (argc == 1) { - cocos2d::TextVAlignment arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setTextVerticalAlignment : Error processing arguments"); - cobj->setTextVerticalAlignment(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_getCharCount : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getCharCount(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setTextVerticalAlignment : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_getCharCount : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_didNotSelectSelf(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_closeIME(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_didNotSelectSelf : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_closeIME : Invalid Native Object"); if (argc == 0) { - cobj->didNotSelectSelf(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cobj->closeIME(); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_didNotSelectSelf : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_closeIME : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_getFontName(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_setPasswordEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getFontName : Invalid Native Object"); - if (argc == 0) { - const std::string& ret = cobj->getFontName(); - jsval jsret = JSVAL_NULL; - jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_setPasswordEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setPasswordEnabled : Error processing arguments"); + cobj->setPasswordEnabled(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_getFontName : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_setPasswordEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_setTextAreaSize(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_setMaxLengthEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setTextAreaSize : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_setMaxLengthEnabled : Invalid Native Object"); if (argc == 1) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setTextAreaSize : Error processing arguments"); - cobj->setTextAreaSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setMaxLengthEnabled : Error processing arguments"); + cobj->setMaxLengthEnabled(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setTextAreaSize : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_setMaxLengthEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_attachWithIME(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_isPasswordEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_attachWithIME : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_isPasswordEnabled : Invalid Native Object"); if (argc == 0) { - cobj->attachWithIME(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + bool ret = cobj->isPasswordEnabled(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_attachWithIME : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_isPasswordEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_getStringLength(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_insertText(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getStringLength : Invalid Native Object"); - if (argc == 0) { - int ret = cobj->getStringLength(); - jsval jsret = JSVAL_NULL; - jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_insertText : Invalid Native Object"); + if (argc == 2) { + const char* arg0; + unsigned long arg1; + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + ok &= jsval_to_ulong(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_insertText : Error processing arguments"); + cobj->insertText(arg0, arg1); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_getStringLength : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_insertText : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_ui_TextField_setPasswordEnabled(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_setPasswordStyleText(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setPasswordEnabled : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_setPasswordStyleText : Invalid Native Object"); if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setPasswordEnabled : Error processing arguments"); - cobj->setPasswordEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setPasswordStyleText : Error processing arguments"); + cobj->setPasswordStyleText(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setPasswordEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_setPasswordStyleText : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_getPlaceHolderColor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_onTextFieldInsertText(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getPlaceHolderColor : Invalid Native Object"); - if (argc == 0) { - const cocos2d::Color4B& ret = cobj->getPlaceHolderColor(); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_onTextFieldInsertText : Invalid Native Object"); + if (argc == 3) { + cocos2d::TextFieldTTF* arg0; + const char* arg1; + unsigned long arg2; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::TextFieldTTF*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); + ok &= jsval_to_ulong(cx, args.get(2), &arg2); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_onTextFieldInsertText : Error processing arguments"); + bool ret = cobj->onTextFieldInsertText(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; - jsret = cccolor4b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_getPlaceHolderColor : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_onTextFieldInsertText : wrong number of arguments: %d, was expecting %d", argc, 3); return false; } -bool js_cocos2dx_ui_TextField_getPasswordStyleText(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_onTextFieldDetachWithIME(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getPasswordStyleText : Invalid Native Object"); - if (argc == 0) { - const char* ret = cobj->getPasswordStyleText(); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_onTextFieldDetachWithIME : Invalid Native Object"); + if (argc == 1) { + cocos2d::TextFieldTTF* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::TextFieldTTF*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_onTextFieldDetachWithIME : Error processing arguments"); + bool ret = cobj->onTextFieldDetachWithIME(arg0); jsval jsret = JSVAL_NULL; - jsret = c_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_getPasswordStyleText : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_onTextFieldDetachWithIME : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_setMaxLengthEnabled(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_getMaxLength(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setMaxLengthEnabled : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setMaxLengthEnabled : Error processing arguments"); - cobj->setMaxLengthEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_getMaxLength : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getMaxLength(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setMaxLengthEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_getMaxLength : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_isPasswordEnabled(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_isMaxLengthEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_isPasswordEnabled : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_isMaxLengthEnabled : Invalid Native Object"); if (argc == 0) { - bool ret = cobj->isPasswordEnabled(); + bool ret = cobj->isMaxLengthEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_isPasswordEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_isMaxLengthEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_setDeleteBackward(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_openIME(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_openIME : Invalid Native Object"); + if (argc == 0) { + cobj->openIME(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_openIME : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_UICCTextField_setDetachWithIME(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setDeleteBackward : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_setDetachWithIME : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setDeleteBackward : Error processing arguments"); - cobj->setDeleteBackward(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setDetachWithIME : Error processing arguments"); + cobj->setDetachWithIME(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setDeleteBackward : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_setDetachWithIME : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_setFontSize(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_setMaxLength(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setFontSize : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_setMaxLength : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setFontSize : Error processing arguments"); - cobj->setFontSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setMaxLength : Error processing arguments"); + cobj->setMaxLength(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setFontSize : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_setMaxLength : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_setPlaceHolder(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_setDeleteBackward(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setPlaceHolder : Invalid Native Object"); + cocos2d::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_setDeleteBackward : Invalid Native Object"); if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setPlaceHolder : Error processing arguments"); - cobj->setPlaceHolder(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setDeleteBackward : Error processing arguments"); + cobj->setDeleteBackward(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setPlaceHolder : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_setDeleteBackward : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_setPlaceHolderColor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_UICCTextField_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - - JSObject *obj = NULL; - cocos2d::ui::TextField* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setPlaceHolderColor : Invalid Native Object"); - do { - if (argc == 1) { - cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cobj->setPlaceHolderColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; + if (argc == 3) { + std::string arg0; + std::string arg1; + double arg2; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_create : Error processing arguments"); + cocos2d::ui::UICCTextField* ret = cocos2d::ui::UICCTextField::create(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::UICCTextField*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; } - } while(0); + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_ui_UICCTextField_create : wrong number of arguments"); + return false; +} - do { - if (argc == 1) { - cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cobj->setPlaceHolderColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - } while(0); +bool js_cocos2dx_ui_UICCTextField_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::ui::UICCTextField* cobj = new (std::nothrow) cocos2d::ui::UICCTextField(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::UICCTextField"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setPlaceHolderColor : wrong number of arguments"); - return false; + +extern JSObject *jsb_cocos2d_TextFieldTTF_prototype; + +void js_cocos2d_ui_UICCTextField_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (UICCTextField)", obj); } -bool js_cocos2dx_ui_TextField_setTextHorizontalAlignment(JSContext *cx, uint32_t argc, jsval *vp) + +void js_register_cocos2dx_ui_UICCTextField(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_UICCTextField_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_UICCTextField_class->name = "UICCTextField"; + jsb_cocos2d_ui_UICCTextField_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_UICCTextField_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_UICCTextField_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_UICCTextField_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_UICCTextField_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_UICCTextField_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_UICCTextField_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_UICCTextField_class->finalize = js_cocos2d_ui_UICCTextField_finalize; + jsb_cocos2d_ui_UICCTextField_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("onTextFieldAttachWithIME", js_cocos2dx_ui_UICCTextField_onTextFieldAttachWithIME, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPasswordText", js_cocos2dx_ui_UICCTextField_setPasswordText, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setAttachWithIME", js_cocos2dx_ui_UICCTextField_setAttachWithIME, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDeleteBackward", js_cocos2dx_ui_UICCTextField_getDeleteBackward, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getAttachWithIME", js_cocos2dx_ui_UICCTextField_getAttachWithIME, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("onTextFieldDeleteBackward", js_cocos2dx_ui_UICCTextField_onTextFieldDeleteBackward, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getInsertText", js_cocos2dx_ui_UICCTextField_getInsertText, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("deleteBackward", js_cocos2dx_ui_UICCTextField_deleteBackward, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setInsertText", js_cocos2dx_ui_UICCTextField_setInsertText, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDetachWithIME", js_cocos2dx_ui_UICCTextField_getDetachWithIME, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getCharCount", js_cocos2dx_ui_UICCTextField_getCharCount, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("closeIME", js_cocos2dx_ui_UICCTextField_closeIME, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPasswordEnabled", js_cocos2dx_ui_UICCTextField_setPasswordEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMaxLengthEnabled", js_cocos2dx_ui_UICCTextField_setMaxLengthEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isPasswordEnabled", js_cocos2dx_ui_UICCTextField_isPasswordEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("insertText", js_cocos2dx_ui_UICCTextField_insertText, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPasswordStyleText", js_cocos2dx_ui_UICCTextField_setPasswordStyleText, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("onTextFieldInsertText", js_cocos2dx_ui_UICCTextField_onTextFieldInsertText, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("onTextFieldDetachWithIME", js_cocos2dx_ui_UICCTextField_onTextFieldDetachWithIME, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMaxLength", js_cocos2dx_ui_UICCTextField_getMaxLength, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isMaxLengthEnabled", js_cocos2dx_ui_UICCTextField_isMaxLengthEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("openIME", js_cocos2dx_ui_UICCTextField_openIME, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setDetachWithIME", js_cocos2dx_ui_UICCTextField_setDetachWithIME, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMaxLength", js_cocos2dx_ui_UICCTextField_setMaxLength, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setDeleteBackward", js_cocos2dx_ui_UICCTextField_setDeleteBackward, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_ui_UICCTextField_create, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_ui_UICCTextField_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_TextFieldTTF_prototype), + jsb_cocos2d_ui_UICCTextField_class, + js_cocos2dx_ui_UICCTextField_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "UICCTextField", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_ui_UICCTextField_class; + p->proto = jsb_cocos2d_ui_UICCTextField_prototype; + p->parentProto = jsb_cocos2d_TextFieldTTF_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_ui_TextField_class; +JSObject *jsb_cocos2d_ui_TextField_prototype; + +bool js_cocos2dx_ui_TextField_setAttachWithIME(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setTextHorizontalAlignment : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setAttachWithIME : Invalid Native Object"); if (argc == 1) { - cocos2d::TextHAlignment arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setTextHorizontalAlignment : Error processing arguments"); - cobj->setTextHorizontalAlignment(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setAttachWithIME : Error processing arguments"); + cobj->setAttachWithIME(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setTextHorizontalAlignment : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setAttachWithIME : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_setTextColor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_getFontSize(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getFontSize : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getFontSize(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_TextField_getFontSize : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_TextField_getString(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getString : Invalid Native Object"); + if (argc == 0) { + const std::string& ret = cobj->getString(); + jsval jsret = JSVAL_NULL; + jsret = std_string_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_TextField_getString : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_TextField_setPasswordStyleText(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setTextColor : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setPasswordStyleText : Invalid Native Object"); if (argc == 1) { - cocos2d::Color4B arg0; - ok &= jsval_to_cccolor4b(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setTextColor : Error processing arguments"); - cobj->setTextColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + const char* arg0; + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setPasswordStyleText : Error processing arguments"); + cobj->setPasswordStyleText(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setTextColor : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setPasswordStyleText : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_getMaxLength(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_getDeleteBackward(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getMaxLength : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getDeleteBackward : Invalid Native Object"); if (argc == 0) { - int ret = cobj->getMaxLength(); + bool ret = cobj->getDeleteBackward(); jsval jsret = JSVAL_NULL; - jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_getMaxLength : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_getDeleteBackward : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_isMaxLengthEnabled(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_getPlaceHolder(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_isMaxLengthEnabled : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getPlaceHolder : Invalid Native Object"); if (argc == 0) { - bool ret = cobj->isMaxLengthEnabled(); + const std::string& ret = cobj->getPlaceHolder(); jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = std_string_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_isMaxLengthEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_getPlaceHolder : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_setDetachWithIME(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_getAttachWithIME(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setDetachWithIME : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setDetachWithIME : Error processing arguments"); - cobj->setDetachWithIME(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getAttachWithIME : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->getAttachWithIME(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setDetachWithIME : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_getAttachWithIME : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_setTouchAreaEnabled(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setFontName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setTouchAreaEnabled : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setFontName : Invalid Native Object"); if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setTouchAreaEnabled : Error processing arguments"); - cobj->setTouchAreaEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setFontName : Error processing arguments"); + cobj->setFontName(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setTouchAreaEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setFontName : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_hitTest(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_getInsertText(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_hitTest : Invalid Native Object"); - if (argc == 1) { - cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_hitTest : Error processing arguments"); - bool ret = cobj->hitTest(arg0); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getInsertText : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->getInsertText(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_hitTest : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_getInsertText : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_setMaxLength(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setInsertText(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setMaxLength : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setInsertText : Invalid Native Object"); if (argc == 1) { - int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setMaxLength : Error processing arguments"); - cobj->setMaxLength(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setInsertText : Error processing arguments"); + cobj->setInsertText(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setMaxLength : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setInsertText : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_setTouchSize(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setTouchSize : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setString : Invalid Native Object"); if (argc == 1) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setTouchSize : Error processing arguments"); - cobj->setTouchSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setString : Error processing arguments"); + cobj->setString(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_setTouchSize : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setString : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_getTouchSize(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_getDetachWithIME(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getTouchSize : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getDetachWithIME : Invalid Native Object"); if (argc == 0) { - cocos2d::Size ret = cobj->getTouchSize(); + bool ret = cobj->getDetachWithIME(); jsval jsret = JSVAL_NULL; - jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_getTouchSize : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_getDetachWithIME : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextField_create(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setTextVerticalAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - - do { - if (argc == 3) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); - if (!ok) { ok = true; break; } - int arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - if (!ok) { ok = true; break; } - cocos2d::ui::TextField* ret = cocos2d::ui::TextField::create(arg0, arg1, arg2); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::TextField*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - - do { - if (argc == 0) { - cocos2d::ui::TextField* ret = cocos2d::ui::TextField::create(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::TextField*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - JS_ReportError(cx, "js_cocos2dx_ui_TextField_create : wrong number of arguments"); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setTextVerticalAlignment : Invalid Native Object"); + if (argc == 1) { + cocos2d::TextVAlignment arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setTextVerticalAlignment : Error processing arguments"); + cobj->setTextVerticalAlignment(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setTextVerticalAlignment : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextField_createInstance(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_didNotSelectSelf(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_didNotSelectSelf : Invalid Native Object"); if (argc == 0) { - cocos2d::Ref* ret = cocos2d::ui::TextField::createInstance(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Ref*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); + cobj->didNotSelectSelf(); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextField_createInstance : wrong number of arguments"); + + JS_ReportError(cx, "js_cocos2dx_ui_TextField_didNotSelectSelf : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_ui_TextField_getFontName(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getFontName : Invalid Native Object"); + if (argc == 0) { + const std::string& ret = cobj->getFontName(); + jsval jsret = JSVAL_NULL; + jsret = std_string_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } -bool js_cocos2dx_ui_TextField_constructor(JSContext *cx, uint32_t argc, jsval *vp) + JS_ReportError(cx, "js_cocos2dx_ui_TextField_getFontName : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_TextField_setTextAreaSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - cocos2d::ui::TextField* cobj = new (std::nothrow) cocos2d::ui::TextField(); - cocos2d::Ref *_ccobj = dynamic_cast(cobj); - if (_ccobj) { - _ccobj->autorelease(); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setTextAreaSize : Invalid Native Object"); + if (argc == 1) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setTextAreaSize : Error processing arguments"); + cobj->setTextAreaSize(arg0); + args.rval().setUndefined(); + return true; } - TypeTest t; - js_type_class_t *typeClass = nullptr; - std::string typeName = t.s_name(); - auto typeMapIter = _js_global_type_map.find(typeName); - CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); - typeClass = typeMapIter->second; - CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); - // link the native object with the javascript object - js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::TextField"); - if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - return true; -} - - -extern JSObject *jsb_cocos2d_ui_Widget_prototype; -void js_cocos2d_ui_TextField_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (TextField)", obj); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setTextAreaSize : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; } - -static bool js_cocos2d_ui_TextField_ctor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_attachWithIME(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); - cocos2d::ui::TextField *nobj = new (std::nothrow) cocos2d::ui::TextField(); - if (nobj) { - nobj->autorelease(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_attachWithIME : Invalid Native Object"); + if (argc == 0) { + cobj->attachWithIME(); + args.rval().setUndefined(); + return true; } - js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::TextField"); - bool isFound = false; - if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; -} -void js_register_cocos2dx_ui_TextField(JSContext *cx, JSObject *global) { - jsb_cocos2d_ui_TextField_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_ui_TextField_class->name = "TextField"; - jsb_cocos2d_ui_TextField_class->addProperty = JS_PropertyStub; - jsb_cocos2d_ui_TextField_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_ui_TextField_class->getProperty = JS_PropertyStub; - jsb_cocos2d_ui_TextField_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_ui_TextField_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_ui_TextField_class->resolve = JS_ResolveStub; - jsb_cocos2d_ui_TextField_class->convert = JS_ConvertStub; - jsb_cocos2d_ui_TextField_class->finalize = js_cocos2d_ui_TextField_finalize; - jsb_cocos2d_ui_TextField_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); - - static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} - }; - - static JSFunctionSpec funcs[] = { - JS_FN("setAttachWithIME", js_cocos2dx_ui_TextField_setAttachWithIME, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getFontSize", js_cocos2dx_ui_TextField_getFontSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getString", js_cocos2dx_ui_TextField_getString, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setPasswordStyleText", js_cocos2dx_ui_TextField_setPasswordStyleText, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getDeleteBackward", js_cocos2dx_ui_TextField_getDeleteBackward, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getPlaceHolder", js_cocos2dx_ui_TextField_getPlaceHolder, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getAttachWithIME", js_cocos2dx_ui_TextField_getAttachWithIME, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setFontName", js_cocos2dx_ui_TextField_setFontName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getInsertText", js_cocos2dx_ui_TextField_getInsertText, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setInsertText", js_cocos2dx_ui_TextField_setInsertText, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setString", js_cocos2dx_ui_TextField_setString, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getDetachWithIME", js_cocos2dx_ui_TextField_getDetachWithIME, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setTextVerticalAlignment", js_cocos2dx_ui_TextField_setTextVerticalAlignment, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("didNotSelectSelf", js_cocos2dx_ui_TextField_didNotSelectSelf, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getFontName", js_cocos2dx_ui_TextField_getFontName, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setTextAreaSize", js_cocos2dx_ui_TextField_setTextAreaSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("attachWithIME", js_cocos2dx_ui_TextField_attachWithIME, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getStringLength", js_cocos2dx_ui_TextField_getStringLength, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setPasswordEnabled", js_cocos2dx_ui_TextField_setPasswordEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getPlaceHolderColor", js_cocos2dx_ui_TextField_getPlaceHolderColor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getPasswordStyleText", js_cocos2dx_ui_TextField_getPasswordStyleText, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setMaxLengthEnabled", js_cocos2dx_ui_TextField_setMaxLengthEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("isPasswordEnabled", js_cocos2dx_ui_TextField_isPasswordEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setDeleteBackward", js_cocos2dx_ui_TextField_setDeleteBackward, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setFontSize", js_cocos2dx_ui_TextField_setFontSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setPlaceHolder", js_cocos2dx_ui_TextField_setPlaceHolder, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setPlaceHolderColor", js_cocos2dx_ui_TextField_setPlaceHolderColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setTextHorizontalAlignment", js_cocos2dx_ui_TextField_setTextHorizontalAlignment, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setTextColor", js_cocos2dx_ui_TextField_setTextColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getMaxLength", js_cocos2dx_ui_TextField_getMaxLength, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("isMaxLengthEnabled", js_cocos2dx_ui_TextField_isMaxLengthEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setDetachWithIME", js_cocos2dx_ui_TextField_setDetachWithIME, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setTouchAreaEnabled", js_cocos2dx_ui_TextField_setTouchAreaEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("hitTest", js_cocos2dx_ui_TextField_hitTest, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setMaxLength", js_cocos2dx_ui_TextField_setMaxLength, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setTouchSize", js_cocos2dx_ui_TextField_setTouchSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getTouchSize", js_cocos2dx_ui_TextField_getTouchSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("ctor", js_cocos2d_ui_TextField_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_ui_TextField_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("createInstance", js_cocos2dx_ui_TextField_createInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - jsb_cocos2d_ui_TextField_prototype = JS_InitClass( - cx, global, - jsb_cocos2d_ui_Widget_prototype, - jsb_cocos2d_ui_TextField_class, - js_cocos2dx_ui_TextField_constructor, 0, // constructor - properties, - funcs, - NULL, // no static properties - st_funcs); - // make the class enumerable in the registered namespace -// bool found; -//FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "TextField", JSPROP_ENUMERATE | JSPROP_READONLY, &found); - // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_ui_TextField_class; - p->proto = jsb_cocos2d_ui_TextField_prototype; - p->parentProto = jsb_cocos2d_ui_Widget_prototype; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } + JS_ReportError(cx, "js_cocos2dx_ui_TextField_attachWithIME : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; } - -JSClass *jsb_cocos2d_ui_TextBMFont_class; -JSObject *jsb_cocos2d_ui_TextBMFont_prototype; - -bool js_cocos2dx_ui_TextBMFont_setFntFile(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_getStringLength(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextBMFont* cobj = (cocos2d::ui::TextBMFont *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextBMFont_setFntFile : Invalid Native Object"); - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextBMFont_setFntFile : Error processing arguments"); - cobj->setFntFile(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getStringLength : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getStringLength(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextBMFont_setFntFile : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_getStringLength : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextBMFont_getStringLength(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_getAutoRenderSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextBMFont* cobj = (cocos2d::ui::TextBMFont *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextBMFont_getStringLength : Invalid Native Object"); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getAutoRenderSize : Invalid Native Object"); if (argc == 0) { - ssize_t ret = cobj->getStringLength(); + cocos2d::Size ret = cobj->getAutoRenderSize(); jsval jsret = JSVAL_NULL; - jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = ccsize_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextBMFont_getStringLength : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_getAutoRenderSize : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextBMFont_setString(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setPasswordEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextBMFont* cobj = (cocos2d::ui::TextBMFont *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextBMFont_setString : Invalid Native Object"); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setPasswordEnabled : Invalid Native Object"); if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextBMFont_setString : Error processing arguments"); - cobj->setString(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setPasswordEnabled : Error processing arguments"); + cobj->setPasswordEnabled(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextBMFont_setString : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setPasswordEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_TextBMFont_getString(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_getPlaceHolderColor(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::TextBMFont* cobj = (cocos2d::ui::TextBMFont *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextBMFont_getString : Invalid Native Object"); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getPlaceHolderColor : Invalid Native Object"); if (argc == 0) { - const std::string& ret = cobj->getString(); + const cocos2d::Color4B& ret = cobj->getPlaceHolderColor(); jsval jsret = JSVAL_NULL; - jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = cccolor4b_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextBMFont_getString : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_getPlaceHolderColor : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_TextBMFont_create(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - - do { - if (argc == 2) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); - if (!ok) { ok = true; break; } - cocos2d::ui::TextBMFont* ret = cocos2d::ui::TextBMFont::create(arg0, arg1); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::TextBMFont*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - - do { - if (argc == 0) { - cocos2d::ui::TextBMFont* ret = cocos2d::ui::TextBMFont::create(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::TextBMFont*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - JS_ReportError(cx, "js_cocos2dx_ui_TextBMFont_create : wrong number of arguments"); - return false; -} -bool js_cocos2dx_ui_TextBMFont_createInstance(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_getPasswordStyleText(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getPasswordStyleText : Invalid Native Object"); if (argc == 0) { - cocos2d::Ref* ret = cocos2d::ui::TextBMFont::createInstance(); + const char* ret = cobj->getPasswordStyleText(); jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Ref*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); + jsret = c_string_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_TextBMFont_createInstance : wrong number of arguments"); + + JS_ReportError(cx, "js_cocos2dx_ui_TextField_getPasswordStyleText : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } - -bool js_cocos2dx_ui_TextBMFont_constructor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setMaxLengthEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - cocos2d::ui::TextBMFont* cobj = new (std::nothrow) cocos2d::ui::TextBMFont(); - cocos2d::Ref *_ccobj = dynamic_cast(cobj); - if (_ccobj) { - _ccobj->autorelease(); - } - TypeTest t; - js_type_class_t *typeClass = nullptr; - std::string typeName = t.s_name(); - auto typeMapIter = _js_global_type_map.find(typeName); - CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); - typeClass = typeMapIter->second; - CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); - // link the native object with the javascript object - js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::TextBMFont"); - if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - return true; -} - - -extern JSObject *jsb_cocos2d_ui_Widget_prototype; - -void js_cocos2d_ui_TextBMFont_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (TextBMFont)", obj); -} - -static bool js_cocos2d_ui_TextBMFont_ctor(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); - cocos2d::ui::TextBMFont *nobj = new (std::nothrow) cocos2d::ui::TextBMFont(); - if (nobj) { - nobj->autorelease(); - } - js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::TextBMFont"); - bool isFound = false; - if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; -} -void js_register_cocos2dx_ui_TextBMFont(JSContext *cx, JSObject *global) { - jsb_cocos2d_ui_TextBMFont_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_ui_TextBMFont_class->name = "TextBMFont"; - jsb_cocos2d_ui_TextBMFont_class->addProperty = JS_PropertyStub; - jsb_cocos2d_ui_TextBMFont_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_ui_TextBMFont_class->getProperty = JS_PropertyStub; - jsb_cocos2d_ui_TextBMFont_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_ui_TextBMFont_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_ui_TextBMFont_class->resolve = JS_ResolveStub; - jsb_cocos2d_ui_TextBMFont_class->convert = JS_ConvertStub; - jsb_cocos2d_ui_TextBMFont_class->finalize = js_cocos2d_ui_TextBMFont_finalize; - jsb_cocos2d_ui_TextBMFont_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); - - static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} - }; - - static JSFunctionSpec funcs[] = { - JS_FN("setFntFile", js_cocos2dx_ui_TextBMFont_setFntFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getStringLength", js_cocos2dx_ui_TextBMFont_getStringLength, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setString", js_cocos2dx_ui_TextBMFont_setString, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getString", js_cocos2dx_ui_TextBMFont_getString, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("ctor", js_cocos2d_ui_TextBMFont_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_ui_TextBMFont_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("createInstance", js_cocos2dx_ui_TextBMFont_createInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - jsb_cocos2d_ui_TextBMFont_prototype = JS_InitClass( - cx, global, - jsb_cocos2d_ui_Widget_prototype, - jsb_cocos2d_ui_TextBMFont_class, - js_cocos2dx_ui_TextBMFont_constructor, 0, // constructor - properties, - funcs, - NULL, // no static properties - st_funcs); - // make the class enumerable in the registered namespace -// bool found; -//FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "TextBMFont", JSPROP_ENUMERATE | JSPROP_READONLY, &found); - - // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_ui_TextBMFont_class; - p->proto = jsb_cocos2d_ui_TextBMFont_prototype; - p->parentProto = jsb_cocos2d_ui_Widget_prototype; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } -} - -JSClass *jsb_cocos2d_ui_PageView_class; -JSObject *jsb_cocos2d_ui_PageView_prototype; - -bool js_cocos2dx_ui_PageView_getCustomScrollThreshold(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_getCustomScrollThreshold : Invalid Native Object"); - if (argc == 0) { - double ret = cobj->getCustomScrollThreshold(); - jsval jsret = JSVAL_NULL; - jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setMaxLengthEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setMaxLengthEnabled : Error processing arguments"); + cobj->setMaxLengthEnabled(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_getCustomScrollThreshold : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setMaxLengthEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_PageView_getCurPageIndex(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_isPasswordEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_getCurPageIndex : Invalid Native Object"); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_isPasswordEnabled : Invalid Native Object"); if (argc == 0) { - ssize_t ret = cobj->getCurPageIndex(); + bool ret = cobj->isPasswordEnabled(); jsval jsret = JSVAL_NULL; - jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_getCurPageIndex : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_isPasswordEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_PageView_addWidgetToPage(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setDeleteBackward(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_addWidgetToPage : Invalid Native Object"); - if (argc == 3) { - cocos2d::ui::Widget* arg0; - ssize_t arg1; - bool arg2; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - ok &= jsval_to_ssize(cx, argv[1], &arg1); - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_addWidgetToPage : Error processing arguments"); - cobj->addWidgetToPage(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setDeleteBackward : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setDeleteBackward : Error processing arguments"); + cobj->setDeleteBackward(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_addWidgetToPage : wrong number of arguments: %d, was expecting %d", argc, 3); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setDeleteBackward : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_PageView_isUsingCustomScrollThreshold(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setFontSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_isUsingCustomScrollThreshold : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->isUsingCustomScrollThreshold(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setFontSize : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setFontSize : Error processing arguments"); + cobj->setFontSize(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_isUsingCustomScrollThreshold : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setFontSize : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_PageView_getPage(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setPlaceHolder(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_getPage : Invalid Native Object"); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setPlaceHolder : Invalid Native Object"); if (argc == 1) { - ssize_t arg0; - ok &= jsval_to_ssize(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_getPage : Error processing arguments"); - cocos2d::ui::Layout* ret = cobj->getPage(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Layout*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setPlaceHolder : Error processing arguments"); + cobj->setPlaceHolder(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_getPage : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setPlaceHolder : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_PageView_removePage(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setPlaceHolderColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + + JS::RootedObject obj(cx); + cocos2d::ui::TextField* cobj = NULL; + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_removePage : Invalid Native Object"); - if (argc == 1) { - cocos2d::ui::Layout* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::ui::Layout*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_removePage : Error processing arguments"); - cobj->removePage(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } + cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setPlaceHolderColor : Invalid Native Object"); + do { + if (argc == 1) { + cocos2d::Color4B arg0; + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cobj->setPlaceHolderColor(arg0); + args.rval().setUndefined(); + return true; + } + } while(0); - JS_ReportError(cx, "js_cocos2dx_ui_PageView_removePage : wrong number of arguments: %d, was expecting %d", argc, 1); + do { + if (argc == 1) { + cocos2d::Color3B arg0; + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cobj->setPlaceHolderColor(arg0); + args.rval().setUndefined(); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setPlaceHolderColor : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_PageView_setUsingCustomScrollThreshold(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setTextHorizontalAlignment(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_setUsingCustomScrollThreshold : Invalid Native Object"); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setTextHorizontalAlignment : Invalid Native Object"); if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_setUsingCustomScrollThreshold : Error processing arguments"); - cobj->setUsingCustomScrollThreshold(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::TextHAlignment arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setTextHorizontalAlignment : Error processing arguments"); + cobj->setTextHorizontalAlignment(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_setUsingCustomScrollThreshold : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setTextHorizontalAlignment : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_PageView_setCustomScrollThreshold(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setTextColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_setCustomScrollThreshold : Invalid Native Object"); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setTextColor : Invalid Native Object"); if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_setCustomScrollThreshold : Error processing arguments"); - cobj->setCustomScrollThreshold(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::Color4B arg0; + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setTextColor : Error processing arguments"); + cobj->setTextColor(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_setCustomScrollThreshold : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setTextColor : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_PageView_insertPage(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_getMaxLength(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_insertPage : Invalid Native Object"); - if (argc == 2) { - cocos2d::ui::Layout* arg0; - int arg1; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::ui::Layout*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_insertPage : Error processing arguments"); - cobj->insertPage(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getMaxLength : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getMaxLength(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_insertPage : wrong number of arguments: %d, was expecting %d", argc, 2); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_getMaxLength : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_PageView_scrollToPage(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_isMaxLengthEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_scrollToPage : Invalid Native Object"); - if (argc == 1) { - ssize_t arg0; - ok &= jsval_to_ssize(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_scrollToPage : Error processing arguments"); - cobj->scrollToPage(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_isMaxLengthEnabled : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isMaxLengthEnabled(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_scrollToPage : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_isMaxLengthEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_PageView_removePageAtIndex(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setDetachWithIME(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_removePageAtIndex : Invalid Native Object"); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setDetachWithIME : Invalid Native Object"); if (argc == 1) { - ssize_t arg0; - ok &= jsval_to_ssize(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_removePageAtIndex : Error processing arguments"); - cobj->removePageAtIndex(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setDetachWithIME : Error processing arguments"); + cobj->setDetachWithIME(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_removePageAtIndex : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setDetachWithIME : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_PageView_getPages(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setTouchAreaEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_getPages : Invalid Native Object"); - if (argc == 0) { - cocos2d::Vector& ret = cobj->getPages(); - jsval jsret = JSVAL_NULL; - jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setTouchAreaEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setTouchAreaEnabled : Error processing arguments"); + cobj->setTouchAreaEnabled(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_getPages : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setTouchAreaEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_PageView_removeAllPages(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setMaxLength(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_removeAllPages : Invalid Native Object"); - if (argc == 0) { - cobj->removeAllPages(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setMaxLength : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setMaxLength : Error processing arguments"); + cobj->setMaxLength(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_removeAllPages : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setMaxLength : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_PageView_addPage(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_setTouchSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_addPage : Invalid Native Object"); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_setTouchSize : Invalid Native Object"); if (argc == 1) { - cocos2d::ui::Layout* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::ui::Layout*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_addPage : Error processing arguments"); - cobj->addPage(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setTouchSize : Error processing arguments"); + cobj->setTouchSize(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_addPage : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_setTouchSize : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_PageView_create(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_getTouchSize(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getTouchSize : Invalid Native Object"); if (argc == 0) { - cocos2d::ui::PageView* ret = cocos2d::ui::PageView::create(); + cocos2d::Size ret = cobj->getTouchSize(); jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::PageView*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); + jsret = ccsize_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_create : wrong number of arguments"); + + JS_ReportError(cx, "js_cocos2dx_ui_TextField_getTouchSize : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } - -bool js_cocos2dx_ui_PageView_createInstance(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + do { + if (argc == 3) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + int arg2; + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + if (!ok) { ok = true; break; } + cocos2d::ui::TextField* ret = cocos2d::ui::TextField::create(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::TextField*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 0) { + cocos2d::ui::TextField* ret = cocos2d::ui::TextField::create(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::TextField*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_create : wrong number of arguments"); + return false; +} +bool js_cocos2dx_ui_TextField_createInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { - cocos2d::Ref* ret = cocos2d::ui::PageView::createInstance(); + cocos2d::Ref* ret = cocos2d::ui::TextField::createInstance(); jsval jsret = JSVAL_NULL; do { if (ret) { @@ -9490,110 +9933,136 @@ bool js_cocos2dx_ui_PageView_createInstance(JSContext *cx, uint32_t argc, jsval jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_PageView_createInstance : wrong number of arguments"); + JS_ReportError(cx, "js_cocos2dx_ui_TextField_createInstance : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_PageView_constructor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextField_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - cocos2d::ui::PageView* cobj = new (std::nothrow) cocos2d::ui::PageView(); + cocos2d::ui::TextField* cobj = new (std::nothrow) cocos2d::ui::TextField(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); if (_ccobj) { _ccobj->autorelease(); } - TypeTest t; + TypeTest t; js_type_class_t *typeClass = nullptr; std::string typeName = t.s_name(); auto typeMapIter = _js_global_type_map.find(typeName); CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::PageView"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::TextField"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } -extern JSObject *jsb_cocos2d_ui_Layout_prototype; +extern JSObject *jsb_cocos2d_ui_Widget_prototype; -void js_cocos2d_ui_PageView_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (PageView)", obj); +void js_cocos2d_ui_TextField_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (TextField)", obj); } -static bool js_cocos2d_ui_PageView_ctor(JSContext *cx, uint32_t argc, jsval *vp) +static bool js_cocos2d_ui_TextField_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); - cocos2d::ui::PageView *nobj = new (std::nothrow) cocos2d::ui::PageView(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::ui::TextField *nobj = new (std::nothrow) cocos2d::ui::TextField(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::PageView"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::TextField"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_PageView(JSContext *cx, JSObject *global) { - jsb_cocos2d_ui_PageView_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_ui_PageView_class->name = "PageView"; - jsb_cocos2d_ui_PageView_class->addProperty = JS_PropertyStub; - jsb_cocos2d_ui_PageView_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_ui_PageView_class->getProperty = JS_PropertyStub; - jsb_cocos2d_ui_PageView_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_ui_PageView_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_ui_PageView_class->resolve = JS_ResolveStub; - jsb_cocos2d_ui_PageView_class->convert = JS_ConvertStub; - jsb_cocos2d_ui_PageView_class->finalize = js_cocos2d_ui_PageView_finalize; - jsb_cocos2d_ui_PageView_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); +void js_register_cocos2dx_ui_TextField(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_TextField_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_TextField_class->name = "TextField"; + jsb_cocos2d_ui_TextField_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_TextField_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_TextField_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_TextField_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_TextField_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_TextField_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_TextField_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_TextField_class->finalize = js_cocos2d_ui_TextField_finalize; + jsb_cocos2d_ui_TextField_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("getCustomScrollThreshold", js_cocos2dx_ui_PageView_getCustomScrollThreshold, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getCurPageIndex", js_cocos2dx_ui_PageView_getCurPageIndex, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("addWidgetToPage", js_cocos2dx_ui_PageView_addWidgetToPage, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("isUsingCustomScrollThreshold", js_cocos2dx_ui_PageView_isUsingCustomScrollThreshold, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getPage", js_cocos2dx_ui_PageView_getPage, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("removePage", js_cocos2dx_ui_PageView_removePage, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setUsingCustomScrollThreshold", js_cocos2dx_ui_PageView_setUsingCustomScrollThreshold, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setCustomScrollThreshold", js_cocos2dx_ui_PageView_setCustomScrollThreshold, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("insertPage", js_cocos2dx_ui_PageView_insertPage, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("scrollToPage", js_cocos2dx_ui_PageView_scrollToPage, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("removePageAtIndex", js_cocos2dx_ui_PageView_removePageAtIndex, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getPages", js_cocos2dx_ui_PageView_getPages, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("removeAllPages", js_cocos2dx_ui_PageView_removeAllPages, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("addPage", js_cocos2dx_ui_PageView_addPage, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("ctor", js_cocos2d_ui_PageView_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setAttachWithIME", js_cocos2dx_ui_TextField_setAttachWithIME, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getFontSize", js_cocos2dx_ui_TextField_getFontSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getString", js_cocos2dx_ui_TextField_getString, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPasswordStyleText", js_cocos2dx_ui_TextField_setPasswordStyleText, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDeleteBackward", js_cocos2dx_ui_TextField_getDeleteBackward, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getPlaceHolder", js_cocos2dx_ui_TextField_getPlaceHolder, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getAttachWithIME", js_cocos2dx_ui_TextField_getAttachWithIME, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setFontName", js_cocos2dx_ui_TextField_setFontName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getInsertText", js_cocos2dx_ui_TextField_getInsertText, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setInsertText", js_cocos2dx_ui_TextField_setInsertText, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setString", js_cocos2dx_ui_TextField_setString, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDetachWithIME", js_cocos2dx_ui_TextField_getDetachWithIME, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setTextVerticalAlignment", js_cocos2dx_ui_TextField_setTextVerticalAlignment, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("didNotSelectSelf", js_cocos2dx_ui_TextField_didNotSelectSelf, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getFontName", js_cocos2dx_ui_TextField_getFontName, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setTextAreaSize", js_cocos2dx_ui_TextField_setTextAreaSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("attachWithIME", js_cocos2dx_ui_TextField_attachWithIME, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getStringLength", js_cocos2dx_ui_TextField_getStringLength, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getAutoRenderSize", js_cocos2dx_ui_TextField_getAutoRenderSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPasswordEnabled", js_cocos2dx_ui_TextField_setPasswordEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getPlaceHolderColor", js_cocos2dx_ui_TextField_getPlaceHolderColor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getPasswordStyleText", js_cocos2dx_ui_TextField_getPasswordStyleText, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMaxLengthEnabled", js_cocos2dx_ui_TextField_setMaxLengthEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isPasswordEnabled", js_cocos2dx_ui_TextField_isPasswordEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setDeleteBackward", js_cocos2dx_ui_TextField_setDeleteBackward, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setFontSize", js_cocos2dx_ui_TextField_setFontSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPlaceHolder", js_cocos2dx_ui_TextField_setPlaceHolder, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPlaceHolderColor", js_cocos2dx_ui_TextField_setPlaceHolderColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setTextHorizontalAlignment", js_cocos2dx_ui_TextField_setTextHorizontalAlignment, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setTextColor", js_cocos2dx_ui_TextField_setTextColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMaxLength", js_cocos2dx_ui_TextField_getMaxLength, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isMaxLengthEnabled", js_cocos2dx_ui_TextField_isMaxLengthEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setDetachWithIME", js_cocos2dx_ui_TextField_setDetachWithIME, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setTouchAreaEnabled", js_cocos2dx_ui_TextField_setTouchAreaEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMaxLength", js_cocos2dx_ui_TextField_setMaxLength, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setTouchSize", js_cocos2dx_ui_TextField_setTouchSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getTouchSize", js_cocos2dx_ui_TextField_getTouchSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_ui_TextField_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_ui_PageView_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("createInstance", js_cocos2dx_ui_PageView_createInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("create", js_cocos2dx_ui_TextField_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("createInstance", js_cocos2dx_ui_TextField_createInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; - jsb_cocos2d_ui_PageView_prototype = JS_InitClass( + jsb_cocos2d_ui_TextField_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Layout_prototype, - jsb_cocos2d_ui_PageView_class, - js_cocos2dx_ui_PageView_constructor, 0, // constructor + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), + jsb_cocos2d_ui_TextField_class, + js_cocos2dx_ui_TextField_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -9601,362 +10070,259 @@ void js_register_cocos2dx_ui_PageView(JSContext *cx, JSObject *global) { // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "PageView", JSPROP_ENUMERATE | JSPROP_READONLY, &found); +// JS_SetPropertyAttributes(cx, global, "TextField", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; + TypeTest t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_ui_PageView_class; - p->proto = jsb_cocos2d_ui_PageView_prototype; - p->parentProto = jsb_cocos2d_ui_Layout_prototype; + p->jsclass = jsb_cocos2d_ui_TextField_class; + p->proto = jsb_cocos2d_ui_TextField_prototype; + p->parentProto = jsb_cocos2d_ui_Widget_prototype; _js_global_type_map.insert(std::make_pair(typeName, p)); } } -JSClass *jsb_cocos2d_ui_Helper_class; -JSObject *jsb_cocos2d_ui_Helper_prototype; +JSClass *jsb_cocos2d_ui_TextBMFont_class; +JSObject *jsb_cocos2d_ui_TextBMFont_prototype; -bool js_cocos2dx_ui_Helper_getSubStringOfUTF8String(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextBMFont_setFntFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - if (argc == 3) { + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::TextBMFont* cobj = (cocos2d::ui::TextBMFont *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextBMFont_setFntFile : Invalid Native Object"); + if (argc == 1) { std::string arg0; - unsigned long arg1; - unsigned long arg2; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - ok &= jsval_to_ulong(cx, argv[1], &arg1); - ok &= jsval_to_ulong(cx, argv[2], &arg2); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Helper_getSubStringOfUTF8String : Error processing arguments"); - std::string ret = cocos2d::ui::Helper::getSubStringOfUTF8String(arg0, arg1, arg2); - jsval jsret = JSVAL_NULL; - jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextBMFont_setFntFile : Error processing arguments"); + cobj->setFntFile(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Helper_getSubStringOfUTF8String : wrong number of arguments"); + + JS_ReportError(cx, "js_cocos2dx_ui_TextBMFont_setFntFile : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_ui_TextBMFont_getStringLength(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::TextBMFont* cobj = (cocos2d::ui::TextBMFont *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextBMFont_getStringLength : Invalid Native Object"); + if (argc == 0) { + ssize_t ret = cobj->getStringLength(); + jsval jsret = JSVAL_NULL; + jsret = ssize_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } -bool js_cocos2dx_ui_Helper_changeLayoutSystemActiveState(JSContext *cx, uint32_t argc, jsval *vp) + JS_ReportError(cx, "js_cocos2dx_ui_TextBMFont_getStringLength : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_TextBMFont_setString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::TextBMFont* cobj = (cocos2d::ui::TextBMFont *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextBMFont_setString : Invalid Native Object"); if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Helper_changeLayoutSystemActiveState : Error processing arguments"); - cocos2d::ui::Helper::changeLayoutSystemActiveState(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextBMFont_setString : Error processing arguments"); + cobj->setString(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Helper_changeLayoutSystemActiveState : wrong number of arguments"); + + JS_ReportError(cx, "js_cocos2dx_ui_TextBMFont_setString : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } - -bool js_cocos2dx_ui_Helper_seekActionWidgetByActionTag(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextBMFont_getString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - if (argc == 2) { - cocos2d::ui::Widget* arg0; - int arg1; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Helper_seekActionWidgetByActionTag : Error processing arguments"); - cocos2d::ui::Widget* ret = cocos2d::ui::Helper::seekActionWidgetByActionTag(arg0, arg1); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::TextBMFont* cobj = (cocos2d::ui::TextBMFont *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextBMFont_getString : Invalid Native Object"); + if (argc == 0) { + const std::string& ret = cobj->getString(); jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Widget*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); + jsret = std_string_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Helper_seekActionWidgetByActionTag : wrong number of arguments"); + + JS_ReportError(cx, "js_cocos2dx_ui_TextBMFont_getString : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } - -bool js_cocos2dx_ui_Helper_seekWidgetByName(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextBMFont_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - if (argc == 2) { - cocos2d::ui::Widget* arg0; - std::string arg1; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - ok &= jsval_to_std_string(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Helper_seekWidgetByName : Error processing arguments"); - cocos2d::ui::Widget* ret = cocos2d::ui::Helper::seekWidgetByName(arg0, arg1); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Widget*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::ui::TextBMFont* ret = cocos2d::ui::TextBMFont::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::TextBMFont*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; } } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - JS_ReportError(cx, "js_cocos2dx_ui_Helper_seekWidgetByName : wrong number of arguments"); + + do { + if (argc == 0) { + cocos2d::ui::TextBMFont* ret = cocos2d::ui::TextBMFont::create(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::TextBMFont*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + JS_ReportError(cx, "js_cocos2dx_ui_TextBMFont_create : wrong number of arguments"); return false; } - -bool js_cocos2dx_ui_Helper_seekWidgetByTag(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextBMFont_createInstance(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - if (argc == 2) { - cocos2d::ui::Widget* arg0; - int arg1; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Helper_seekWidgetByTag : Error processing arguments"); - cocos2d::ui::Widget* ret = cocos2d::ui::Helper::seekWidgetByTag(arg0, arg1); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (argc == 0) { + cocos2d::Ref* ret = cocos2d::ui::TextBMFont::createInstance(); jsval jsret = JSVAL_NULL; do { if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Widget*)ret); + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Ref*)ret); jsret = OBJECT_TO_JSVAL(jsProxy->obj); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Helper_seekWidgetByTag : wrong number of arguments"); + JS_ReportError(cx, "js_cocos2dx_ui_TextBMFont_createInstance : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_Helper_doLayout(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_TextBMFont_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - if (argc == 1) { - cocos2d::Node* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Helper_doLayout : Error processing arguments"); - cocos2d::ui::Helper::doLayout(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - JS_ReportError(cx, "js_cocos2dx_ui_Helper_doLayout : wrong number of arguments"); - return false; -} - - - -void js_cocos2d_ui_Helper_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (Helper)", obj); -} - -void js_register_cocos2dx_ui_Helper(JSContext *cx, JSObject *global) { - jsb_cocos2d_ui_Helper_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_ui_Helper_class->name = "Helper"; - jsb_cocos2d_ui_Helper_class->addProperty = JS_PropertyStub; - jsb_cocos2d_ui_Helper_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_ui_Helper_class->getProperty = JS_PropertyStub; - jsb_cocos2d_ui_Helper_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_ui_Helper_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_ui_Helper_class->resolve = JS_ResolveStub; - jsb_cocos2d_ui_Helper_class->convert = JS_ConvertStub; - jsb_cocos2d_ui_Helper_class->finalize = js_cocos2d_ui_Helper_finalize; - jsb_cocos2d_ui_Helper_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); - - static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} - }; - - static JSFunctionSpec funcs[] = { - JS_FS_END - }; - - static JSFunctionSpec st_funcs[] = { - JS_FN("getSubStringOfUTF8String", js_cocos2dx_ui_Helper_getSubStringOfUTF8String, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("changeLayoutSystemActiveState", js_cocos2dx_ui_Helper_changeLayoutSystemActiveState, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("seekActionWidgetByActionTag", js_cocos2dx_ui_Helper_seekActionWidgetByActionTag, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("seekWidgetByName", js_cocos2dx_ui_Helper_seekWidgetByName, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("seekWidgetByTag", js_cocos2dx_ui_Helper_seekWidgetByTag, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("doLayout", js_cocos2dx_ui_Helper_doLayout, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - jsb_cocos2d_ui_Helper_prototype = JS_InitClass( - cx, global, - NULL, // parent proto - jsb_cocos2d_ui_Helper_class, - empty_constructor, 0, - properties, - funcs, - NULL, // no static properties - st_funcs); - // make the class enumerable in the registered namespace -// bool found; -//FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "Helper", JSPROP_ENUMERATE | JSPROP_READONLY, &found); - - // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_ui_Helper_class; - p->proto = jsb_cocos2d_ui_Helper_prototype; - p->parentProto = NULL; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } -} - -JSClass *jsb_cocos2d_ui_RichElement_class; -JSObject *jsb_cocos2d_ui_RichElement_prototype; - -bool js_cocos2dx_ui_RichElement_init(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::RichElement* cobj = (cocos2d::ui::RichElement *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichElement_init : Invalid Native Object"); - if (argc == 3) { - int arg0; - cocos2d::Color3B arg1; - uint16_t arg2; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_cccolor3b(cx, argv[1], &arg1); - ok &= jsval_to_uint16(cx, argv[2], &arg2); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichElement_init : Error processing arguments"); - bool ret = cobj->init(arg0, arg1, arg2); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_ui_RichElement_init : wrong number of arguments: %d, was expecting %d", argc, 3); - return false; -} -bool js_cocos2dx_ui_RichElement_constructor(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - cocos2d::ui::RichElement* cobj = new (std::nothrow) cocos2d::ui::RichElement(); + cocos2d::ui::TextBMFont* cobj = new (std::nothrow) cocos2d::ui::TextBMFont(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); if (_ccobj) { _ccobj->autorelease(); } - TypeTest t; + TypeTest t; js_type_class_t *typeClass = nullptr; std::string typeName = t.s_name(); auto typeMapIter = _js_global_type_map.find(typeName); CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElement"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::TextBMFont"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } +extern JSObject *jsb_cocos2d_ui_Widget_prototype; -void js_cocos2d_ui_RichElement_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (RichElement)", obj); +void js_cocos2d_ui_TextBMFont_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (TextBMFont)", obj); } -static bool js_cocos2d_ui_RichElement_ctor(JSContext *cx, uint32_t argc, jsval *vp) +static bool js_cocos2d_ui_TextBMFont_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); - cocos2d::ui::RichElement *nobj = new (std::nothrow) cocos2d::ui::RichElement(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::ui::TextBMFont *nobj = new (std::nothrow) cocos2d::ui::TextBMFont(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElement"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::TextBMFont"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_RichElement(JSContext *cx, JSObject *global) { - jsb_cocos2d_ui_RichElement_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_ui_RichElement_class->name = "RichElement"; - jsb_cocos2d_ui_RichElement_class->addProperty = JS_PropertyStub; - jsb_cocos2d_ui_RichElement_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_ui_RichElement_class->getProperty = JS_PropertyStub; - jsb_cocos2d_ui_RichElement_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_ui_RichElement_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_ui_RichElement_class->resolve = JS_ResolveStub; - jsb_cocos2d_ui_RichElement_class->convert = JS_ConvertStub; - jsb_cocos2d_ui_RichElement_class->finalize = js_cocos2d_ui_RichElement_finalize; - jsb_cocos2d_ui_RichElement_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); +void js_register_cocos2dx_ui_TextBMFont(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_TextBMFont_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_TextBMFont_class->name = "TextBMFont"; + jsb_cocos2d_ui_TextBMFont_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_TextBMFont_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_TextBMFont_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_TextBMFont_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_TextBMFont_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_TextBMFont_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_TextBMFont_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_TextBMFont_class->finalize = js_cocos2d_ui_TextBMFont_finalize; + jsb_cocos2d_ui_TextBMFont_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("init", js_cocos2dx_ui_RichElement_init, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("ctor", js_cocos2d_ui_RichElement_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setFntFile", js_cocos2dx_ui_TextBMFont_setFntFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getStringLength", js_cocos2dx_ui_TextBMFont_getStringLength, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setString", js_cocos2dx_ui_TextBMFont_setString, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getString", js_cocos2dx_ui_TextBMFont_getString, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_ui_TextBMFont_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; - JSFunctionSpec *st_funcs = NULL; + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_ui_TextBMFont_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("createInstance", js_cocos2dx_ui_TextBMFont_createInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; - jsb_cocos2d_ui_RichElement_prototype = JS_InitClass( + jsb_cocos2d_ui_TextBMFont_prototype = JS_InitClass( cx, global, - NULL, // parent proto - jsb_cocos2d_ui_RichElement_class, - js_cocos2dx_ui_RichElement_constructor, 0, // constructor + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), + jsb_cocos2d_ui_TextBMFont_class, + js_cocos2dx_ui_TextBMFont_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -9964,525 +10330,478 @@ void js_register_cocos2dx_ui_RichElement(JSContext *cx, JSObject *global) { // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "RichElement", JSPROP_ENUMERATE | JSPROP_READONLY, &found); +// JS_SetPropertyAttributes(cx, global, "TextBMFont", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; + TypeTest t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_ui_RichElement_class; - p->proto = jsb_cocos2d_ui_RichElement_prototype; - p->parentProto = NULL; + p->jsclass = jsb_cocos2d_ui_TextBMFont_class; + p->proto = jsb_cocos2d_ui_TextBMFont_prototype; + p->parentProto = jsb_cocos2d_ui_Widget_prototype; _js_global_type_map.insert(std::make_pair(typeName, p)); } } -JSClass *jsb_cocos2d_ui_RichElementText_class; -JSObject *jsb_cocos2d_ui_RichElementText_prototype; +JSClass *jsb_cocos2d_ui_PageView_class; +JSObject *jsb_cocos2d_ui_PageView_prototype; -bool js_cocos2dx_ui_RichElementText_init(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_PageView_getCustomScrollThreshold(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::RichElementText* cobj = (cocos2d::ui::RichElementText *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichElementText_init : Invalid Native Object"); - if (argc == 6) { - int arg0; - cocos2d::Color3B arg1; - uint16_t arg2; - std::string arg3; - std::string arg4; - double arg5; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_cccolor3b(cx, argv[1], &arg1); - ok &= jsval_to_uint16(cx, argv[2], &arg2); - ok &= jsval_to_std_string(cx, argv[3], &arg3); - ok &= jsval_to_std_string(cx, argv[4], &arg4); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[5]), &arg5); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichElementText_init : Error processing arguments"); - bool ret = cobj->init(arg0, arg1, arg2, arg3, arg4, arg5); + cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_getCustomScrollThreshold : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getCustomScrollThreshold(); jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_RichElementText_init : wrong number of arguments: %d, was expecting %d", argc, 6); + JS_ReportError(cx, "js_cocos2dx_ui_PageView_getCustomScrollThreshold : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_RichElementText_create(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_PageView_getCurPageIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - if (argc == 6) { - int arg0; - cocos2d::Color3B arg1; - uint16_t arg2; - std::string arg3; - std::string arg4; - double arg5; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_cccolor3b(cx, argv[1], &arg1); - ok &= jsval_to_uint16(cx, argv[2], &arg2); - ok &= jsval_to_std_string(cx, argv[3], &arg3); - ok &= jsval_to_std_string(cx, argv[4], &arg4); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[5]), &arg5); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichElementText_create : Error processing arguments"); - cocos2d::ui::RichElementText* ret = cocos2d::ui::RichElementText::create(arg0, arg1, arg2, arg3, arg4, arg5); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_getCurPageIndex : Invalid Native Object"); + if (argc == 0) { + ssize_t ret = cobj->getCurPageIndex(); jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::RichElementText*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); + jsret = ssize_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_RichElementText_create : wrong number of arguments"); + + JS_ReportError(cx, "js_cocos2dx_ui_PageView_getCurPageIndex : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } - -bool js_cocos2dx_ui_RichElementText_constructor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_PageView_addWidgetToPage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - cocos2d::ui::RichElementText* cobj = new (std::nothrow) cocos2d::ui::RichElementText(); - cocos2d::Ref *_ccobj = dynamic_cast(cobj); - if (_ccobj) { - _ccobj->autorelease(); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_addWidgetToPage : Invalid Native Object"); + if (argc == 3) { + cocos2d::ui::Widget* arg0; + ssize_t arg1; + bool arg2; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_ssize(cx, args.get(1), &arg1); + arg2 = JS::ToBoolean(args.get(2)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_addWidgetToPage : Error processing arguments"); + cobj->addWidgetToPage(arg0, arg1, arg2); + args.rval().setUndefined(); + return true; } - TypeTest t; - js_type_class_t *typeClass = nullptr; - std::string typeName = t.s_name(); - auto typeMapIter = _js_global_type_map.find(typeName); - CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); - typeClass = typeMapIter->second; - CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); - // link the native object with the javascript object - js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElementText"); - if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - return true; -} - -extern JSObject *jsb_cocos2d_ui_RichElement_prototype; - -void js_cocos2d_ui_RichElementText_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (RichElementText)", obj); + JS_ReportError(cx, "js_cocos2dx_ui_PageView_addWidgetToPage : wrong number of arguments: %d, was expecting %d", argc, 3); + return false; } - -static bool js_cocos2d_ui_RichElementText_ctor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_PageView_isUsingCustomScrollThreshold(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); - cocos2d::ui::RichElementText *nobj = new (std::nothrow) cocos2d::ui::RichElementText(); - if (nobj) { - nobj->autorelease(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_isUsingCustomScrollThreshold : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isUsingCustomScrollThreshold(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; } - js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElementText"); - bool isFound = false; - if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; -} -void js_register_cocos2dx_ui_RichElementText(JSContext *cx, JSObject *global) { - jsb_cocos2d_ui_RichElementText_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_ui_RichElementText_class->name = "RichElementText"; - jsb_cocos2d_ui_RichElementText_class->addProperty = JS_PropertyStub; - jsb_cocos2d_ui_RichElementText_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_ui_RichElementText_class->getProperty = JS_PropertyStub; - jsb_cocos2d_ui_RichElementText_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_ui_RichElementText_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_ui_RichElementText_class->resolve = JS_ResolveStub; - jsb_cocos2d_ui_RichElementText_class->convert = JS_ConvertStub; - jsb_cocos2d_ui_RichElementText_class->finalize = js_cocos2d_ui_RichElementText_finalize; - jsb_cocos2d_ui_RichElementText_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); - - static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} - }; - - static JSFunctionSpec funcs[] = { - JS_FN("init", js_cocos2dx_ui_RichElementText_init, 6, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("ctor", js_cocos2d_ui_RichElementText_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_ui_RichElementText_create, 6, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - jsb_cocos2d_ui_RichElementText_prototype = JS_InitClass( - cx, global, - jsb_cocos2d_ui_RichElement_prototype, - jsb_cocos2d_ui_RichElementText_class, - js_cocos2dx_ui_RichElementText_constructor, 0, // constructor - properties, - funcs, - NULL, // no static properties - st_funcs); - // make the class enumerable in the registered namespace -// bool found; -//FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "RichElementText", JSPROP_ENUMERATE | JSPROP_READONLY, &found); - // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_ui_RichElementText_class; - p->proto = jsb_cocos2d_ui_RichElementText_prototype; - p->parentProto = jsb_cocos2d_ui_RichElement_prototype; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } + JS_ReportError(cx, "js_cocos2dx_ui_PageView_isUsingCustomScrollThreshold : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; } - -JSClass *jsb_cocos2d_ui_RichElementImage_class; -JSObject *jsb_cocos2d_ui_RichElementImage_prototype; - -bool js_cocos2dx_ui_RichElementImage_init(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_PageView_getPage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::RichElementImage* cobj = (cocos2d::ui::RichElementImage *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichElementImage_init : Invalid Native Object"); - if (argc == 4) { - int arg0; - cocos2d::Color3B arg1; - uint16_t arg2; - std::string arg3; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_cccolor3b(cx, argv[1], &arg1); - ok &= jsval_to_uint16(cx, argv[2], &arg2); - ok &= jsval_to_std_string(cx, argv[3], &arg3); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichElementImage_init : Error processing arguments"); - bool ret = cobj->init(arg0, arg1, arg2, arg3); + cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_getPage : Invalid Native Object"); + if (argc == 1) { + ssize_t arg0; + ok &= jsval_to_ssize(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_getPage : Error processing arguments"); + cocos2d::ui::Layout* ret = cobj->getPage(arg0); jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Layout*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_RichElementImage_init : wrong number of arguments: %d, was expecting %d", argc, 4); + JS_ReportError(cx, "js_cocos2dx_ui_PageView_getPage : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_RichElementImage_create(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_PageView_removePage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - if (argc == 4) { - int arg0; - cocos2d::Color3B arg1; - uint16_t arg2; - std::string arg3; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_cccolor3b(cx, argv[1], &arg1); - ok &= jsval_to_uint16(cx, argv[2], &arg2); - ok &= jsval_to_std_string(cx, argv[3], &arg3); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichElementImage_create : Error processing arguments"); - cocos2d::ui::RichElementImage* ret = cocos2d::ui::RichElementImage::create(arg0, arg1, arg2, arg3); - jsval jsret = JSVAL_NULL; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_removePage : Invalid Native Object"); + if (argc == 1) { + cocos2d::ui::Layout* arg0; do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::RichElementImage*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::ui::Layout*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_removePage : Error processing arguments"); + cobj->removePage(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_RichElementImage_create : wrong number of arguments"); + + JS_ReportError(cx, "js_cocos2dx_ui_PageView_removePage : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } - -bool js_cocos2dx_ui_RichElementImage_constructor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_PageView_setUsingCustomScrollThreshold(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - cocos2d::ui::RichElementImage* cobj = new (std::nothrow) cocos2d::ui::RichElementImage(); - cocos2d::Ref *_ccobj = dynamic_cast(cobj); - if (_ccobj) { - _ccobj->autorelease(); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_setUsingCustomScrollThreshold : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_setUsingCustomScrollThreshold : Error processing arguments"); + cobj->setUsingCustomScrollThreshold(arg0); + args.rval().setUndefined(); + return true; } - TypeTest t; - js_type_class_t *typeClass = nullptr; - std::string typeName = t.s_name(); - auto typeMapIter = _js_global_type_map.find(typeName); - CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); - typeClass = typeMapIter->second; - CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); - // link the native object with the javascript object - js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElementImage"); - if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - return true; -} - - -extern JSObject *jsb_cocos2d_ui_RichElement_prototype; -void js_cocos2d_ui_RichElementImage_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (RichElementImage)", obj); + JS_ReportError(cx, "js_cocos2dx_ui_PageView_setUsingCustomScrollThreshold : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; } - -static bool js_cocos2d_ui_RichElementImage_ctor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_PageView_setCustomScrollThreshold(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); - cocos2d::ui::RichElementImage *nobj = new (std::nothrow) cocos2d::ui::RichElementImage(); - if (nobj) { - nobj->autorelease(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_setCustomScrollThreshold : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_setCustomScrollThreshold : Error processing arguments"); + cobj->setCustomScrollThreshold(arg0); + args.rval().setUndefined(); + return true; } - js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElementImage"); - bool isFound = false; - if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; -} -void js_register_cocos2dx_ui_RichElementImage(JSContext *cx, JSObject *global) { - jsb_cocos2d_ui_RichElementImage_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_ui_RichElementImage_class->name = "RichElementImage"; - jsb_cocos2d_ui_RichElementImage_class->addProperty = JS_PropertyStub; - jsb_cocos2d_ui_RichElementImage_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_ui_RichElementImage_class->getProperty = JS_PropertyStub; - jsb_cocos2d_ui_RichElementImage_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_ui_RichElementImage_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_ui_RichElementImage_class->resolve = JS_ResolveStub; - jsb_cocos2d_ui_RichElementImage_class->convert = JS_ConvertStub; - jsb_cocos2d_ui_RichElementImage_class->finalize = js_cocos2d_ui_RichElementImage_finalize; - jsb_cocos2d_ui_RichElementImage_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); - - static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} - }; - - static JSFunctionSpec funcs[] = { - JS_FN("init", js_cocos2dx_ui_RichElementImage_init, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("ctor", js_cocos2d_ui_RichElementImage_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_ui_RichElementImage_create, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; - - jsb_cocos2d_ui_RichElementImage_prototype = JS_InitClass( - cx, global, - jsb_cocos2d_ui_RichElement_prototype, - jsb_cocos2d_ui_RichElementImage_class, - js_cocos2dx_ui_RichElementImage_constructor, 0, // constructor - properties, - funcs, - NULL, // no static properties - st_funcs); - // make the class enumerable in the registered namespace -// bool found; -//FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "RichElementImage", JSPROP_ENUMERATE | JSPROP_READONLY, &found); - // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_ui_RichElementImage_class; - p->proto = jsb_cocos2d_ui_RichElementImage_prototype; - p->parentProto = jsb_cocos2d_ui_RichElement_prototype; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } + JS_ReportError(cx, "js_cocos2dx_ui_PageView_setCustomScrollThreshold : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; } - -JSClass *jsb_cocos2d_ui_RichElementCustomNode_class; -JSObject *jsb_cocos2d_ui_RichElementCustomNode_prototype; - -bool js_cocos2dx_ui_RichElementCustomNode_init(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_PageView_insertPage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::RichElementCustomNode* cobj = (cocos2d::ui::RichElementCustomNode *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichElementCustomNode_init : Invalid Native Object"); - if (argc == 4) { - int arg0; - cocos2d::Color3B arg1; - uint16_t arg2; - cocos2d::Node* arg3; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_cccolor3b(cx, argv[1], &arg1); - ok &= jsval_to_uint16(cx, argv[2], &arg2); + cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_insertPage : Invalid Native Object"); + if (argc == 2) { + cocos2d::ui::Layout* arg0; + int arg1; do { - if (!argv[3].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[3]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); - arg3 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); + arg0 = (cocos2d::ui::Layout*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichElementCustomNode_init : Error processing arguments"); - bool ret = cobj->init(arg0, arg1, arg2, arg3); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_insertPage : Error processing arguments"); + cobj->insertPage(arg0, arg1); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_PageView_insertPage : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} +bool js_cocos2dx_ui_PageView_scrollToPage(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_scrollToPage : Invalid Native Object"); + if (argc == 1) { + ssize_t arg0; + ok &= jsval_to_ssize(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_scrollToPage : Error processing arguments"); + cobj->scrollToPage(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_PageView_scrollToPage : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_PageView_removePageAtIndex(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_removePageAtIndex : Invalid Native Object"); + if (argc == 1) { + ssize_t arg0; + ok &= jsval_to_ssize(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_removePageAtIndex : Error processing arguments"); + cobj->removePageAtIndex(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_PageView_removePageAtIndex : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_PageView_getPages(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_getPages : Invalid Native Object"); + if (argc == 0) { + cocos2d::Vector& ret = cobj->getPages(); jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = ccvector_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_RichElementCustomNode_init : wrong number of arguments: %d, was expecting %d", argc, 4); + JS_ReportError(cx, "js_cocos2dx_ui_PageView_getPages : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_RichElementCustomNode_create(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_PageView_removeAllPages(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_removeAllPages : Invalid Native Object"); + if (argc == 0) { + cobj->removeAllPages(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_PageView_removeAllPages : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_PageView_addPage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - if (argc == 4) { - int arg0; - cocos2d::Color3B arg1; - uint16_t arg2; - cocos2d::Node* arg3; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= jsval_to_cccolor3b(cx, argv[1], &arg1); - ok &= jsval_to_uint16(cx, argv[2], &arg2); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_addPage : Invalid Native Object"); + if (argc == 1) { + cocos2d::ui::Layout* arg0; do { - if (!argv[3].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[3]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); - arg3 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); + arg0 = (cocos2d::ui::Layout*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichElementCustomNode_create : Error processing arguments"); - cocos2d::ui::RichElementCustomNode* ret = cocos2d::ui::RichElementCustomNode::create(arg0, arg1, arg2, arg3); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_PageView_addPage : Error processing arguments"); + cobj->addPage(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_PageView_addPage : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_PageView_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (argc == 0) { + cocos2d::ui::PageView* ret = cocos2d::ui::PageView::create(); jsval jsret = JSVAL_NULL; do { if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::RichElementCustomNode*)ret); + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::PageView*)ret); jsret = OBJECT_TO_JSVAL(jsProxy->obj); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_RichElementCustomNode_create : wrong number of arguments"); + JS_ReportError(cx, "js_cocos2dx_ui_PageView_create : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_RichElementCustomNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_PageView_createInstance(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (argc == 0) { + cocos2d::Ref* ret = cocos2d::ui::PageView::createInstance(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Ref*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_ui_PageView_createInstance : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_ui_PageView_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - cocos2d::ui::RichElementCustomNode* cobj = new (std::nothrow) cocos2d::ui::RichElementCustomNode(); + cocos2d::ui::PageView* cobj = new (std::nothrow) cocos2d::ui::PageView(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); if (_ccobj) { _ccobj->autorelease(); } - TypeTest t; + TypeTest t; js_type_class_t *typeClass = nullptr; std::string typeName = t.s_name(); auto typeMapIter = _js_global_type_map.find(typeName); CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElementCustomNode"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::PageView"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } -extern JSObject *jsb_cocos2d_ui_RichElement_prototype; +extern JSObject *jsb_cocos2d_ui_Layout_prototype; -void js_cocos2d_ui_RichElementCustomNode_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (RichElementCustomNode)", obj); +void js_cocos2d_ui_PageView_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (PageView)", obj); } -static bool js_cocos2d_ui_RichElementCustomNode_ctor(JSContext *cx, uint32_t argc, jsval *vp) +static bool js_cocos2d_ui_PageView_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); - cocos2d::ui::RichElementCustomNode *nobj = new (std::nothrow) cocos2d::ui::RichElementCustomNode(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::ui::PageView *nobj = new (std::nothrow) cocos2d::ui::PageView(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElementCustomNode"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::PageView"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_RichElementCustomNode(JSContext *cx, JSObject *global) { - jsb_cocos2d_ui_RichElementCustomNode_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_ui_RichElementCustomNode_class->name = "RichElementCustomNode"; - jsb_cocos2d_ui_RichElementCustomNode_class->addProperty = JS_PropertyStub; - jsb_cocos2d_ui_RichElementCustomNode_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_ui_RichElementCustomNode_class->getProperty = JS_PropertyStub; - jsb_cocos2d_ui_RichElementCustomNode_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_ui_RichElementCustomNode_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_ui_RichElementCustomNode_class->resolve = JS_ResolveStub; - jsb_cocos2d_ui_RichElementCustomNode_class->convert = JS_ConvertStub; - jsb_cocos2d_ui_RichElementCustomNode_class->finalize = js_cocos2d_ui_RichElementCustomNode_finalize; - jsb_cocos2d_ui_RichElementCustomNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); +void js_register_cocos2dx_ui_PageView(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_PageView_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_PageView_class->name = "PageView"; + jsb_cocos2d_ui_PageView_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_PageView_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_PageView_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_PageView_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_PageView_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_PageView_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_PageView_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_PageView_class->finalize = js_cocos2d_ui_PageView_finalize; + jsb_cocos2d_ui_PageView_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("init", js_cocos2dx_ui_RichElementCustomNode_init, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("ctor", js_cocos2d_ui_RichElementCustomNode_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getCustomScrollThreshold", js_cocos2dx_ui_PageView_getCustomScrollThreshold, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getCurPageIndex", js_cocos2dx_ui_PageView_getCurPageIndex, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("addWidgetToPage", js_cocos2dx_ui_PageView_addWidgetToPage, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isUsingCustomScrollThreshold", js_cocos2dx_ui_PageView_isUsingCustomScrollThreshold, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getPage", js_cocos2dx_ui_PageView_getPage, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("removePage", js_cocos2dx_ui_PageView_removePage, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setUsingCustomScrollThreshold", js_cocos2dx_ui_PageView_setUsingCustomScrollThreshold, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setCustomScrollThreshold", js_cocos2dx_ui_PageView_setCustomScrollThreshold, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("insertPage", js_cocos2dx_ui_PageView_insertPage, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("scrollToPage", js_cocos2dx_ui_PageView_scrollToPage, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("removePageAtIndex", js_cocos2dx_ui_PageView_removePageAtIndex, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getPages", js_cocos2dx_ui_PageView_getPages, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("removeAllPages", js_cocos2dx_ui_PageView_removeAllPages, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("addPage", js_cocos2dx_ui_PageView_addPage, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_ui_PageView_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_ui_RichElementCustomNode_create, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("create", js_cocos2dx_ui_PageView_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("createInstance", js_cocos2dx_ui_PageView_createInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; - jsb_cocos2d_ui_RichElementCustomNode_prototype = JS_InitClass( + jsb_cocos2d_ui_PageView_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_RichElement_prototype, - jsb_cocos2d_ui_RichElementCustomNode_class, - js_cocos2dx_ui_RichElementCustomNode_constructor, 0, // constructor + JS::RootedObject(cx, jsb_cocos2d_ui_Layout_prototype), + jsb_cocos2d_ui_PageView_class, + js_cocos2dx_ui_PageView_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -10490,308 +10809,252 @@ void js_register_cocos2dx_ui_RichElementCustomNode(JSContext *cx, JSObject *glob // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "RichElementCustomNode", JSPROP_ENUMERATE | JSPROP_READONLY, &found); +// JS_SetPropertyAttributes(cx, global, "PageView", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; + TypeTest t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_ui_RichElementCustomNode_class; - p->proto = jsb_cocos2d_ui_RichElementCustomNode_prototype; - p->parentProto = jsb_cocos2d_ui_RichElement_prototype; + p->jsclass = jsb_cocos2d_ui_PageView_class; + p->proto = jsb_cocos2d_ui_PageView_prototype; + p->parentProto = jsb_cocos2d_ui_Layout_prototype; _js_global_type_map.insert(std::make_pair(typeName, p)); } } -JSClass *jsb_cocos2d_ui_RichText_class; -JSObject *jsb_cocos2d_ui_RichText_prototype; +JSClass *jsb_cocos2d_ui_Helper_class; +JSObject *jsb_cocos2d_ui_Helper_prototype; -bool js_cocos2dx_ui_RichText_insertElement(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_Helper_getSubStringOfUTF8String(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::RichText* cobj = (cocos2d::ui::RichText *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichText_insertElement : Invalid Native Object"); - if (argc == 2) { - cocos2d::ui::RichElement* arg0; - int arg1; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::ui::RichElement*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichText_insertElement : Error processing arguments"); - cobj->insertElement(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + if (argc == 3) { + std::string arg0; + unsigned long arg1; + unsigned long arg2; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_ulong(cx, args.get(1), &arg1); + ok &= jsval_to_ulong(cx, args.get(2), &arg2); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Helper_getSubStringOfUTF8String : Error processing arguments"); + std::string ret = cocos2d::ui::Helper::getSubStringOfUTF8String(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + jsret = std_string_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - - JS_ReportError(cx, "js_cocos2dx_ui_RichText_insertElement : wrong number of arguments: %d, was expecting %d", argc, 2); + JS_ReportError(cx, "js_cocos2dx_ui_Helper_getSubStringOfUTF8String : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_RichText_setAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp) + +bool js_cocos2dx_ui_Helper_changeLayoutSystemActiveState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::RichText* cobj = (cocos2d::ui::RichText *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichText_setAnchorPoint : Invalid Native Object"); if (argc == 1) { - cocos2d::Vec2 arg0; - ok &= jsval_to_vector2(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichText_setAnchorPoint : Error processing arguments"); - cobj->setAnchorPoint(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Helper_changeLayoutSystemActiveState : Error processing arguments"); + cocos2d::ui::Helper::changeLayoutSystemActiveState(arg0); + args.rval().setUndefined(); return true; } - - JS_ReportError(cx, "js_cocos2dx_ui_RichText_setAnchorPoint : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_Helper_changeLayoutSystemActiveState : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_RichText_pushBackElement(JSContext *cx, uint32_t argc, jsval *vp) + +bool js_cocos2dx_ui_Helper_seekActionWidgetByActionTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::RichText* cobj = (cocos2d::ui::RichText *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichText_pushBackElement : Invalid Native Object"); - if (argc == 1) { - cocos2d::ui::RichElement* arg0; + if (argc == 2) { + cocos2d::ui::Widget* arg0; + int arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::ui::RichElement*)(jsProxy ? jsProxy->ptr : NULL); + arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichText_pushBackElement : Error processing arguments"); - cobj->pushBackElement(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Helper_seekActionWidgetByActionTag : Error processing arguments"); + cocos2d::ui::Widget* ret = cocos2d::ui::Helper::seekActionWidgetByActionTag(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Widget*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); return true; } - - JS_ReportError(cx, "js_cocos2dx_ui_RichText_pushBackElement : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_Helper_seekActionWidgetByActionTag : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_RichText_ignoreContentAdaptWithSize(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::RichText* cobj = (cocos2d::ui::RichText *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichText_ignoreContentAdaptWithSize : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichText_ignoreContentAdaptWithSize : Error processing arguments"); - cobj->ignoreContentAdaptWithSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - JS_ReportError(cx, "js_cocos2dx_ui_RichText_ignoreContentAdaptWithSize : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_ui_RichText_setVerticalSpace(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_Helper_seekWidgetByName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::RichText* cobj = (cocos2d::ui::RichText *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichText_setVerticalSpace : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichText_setVerticalSpace : Error processing arguments"); - cobj->setVerticalSpace(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + if (argc == 2) { + cocos2d::ui::Widget* arg0; + std::string arg1; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Helper_seekWidgetByName : Error processing arguments"); + cocos2d::ui::Widget* ret = cocos2d::ui::Helper::seekWidgetByName(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Widget*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); return true; } - - JS_ReportError(cx, "js_cocos2dx_ui_RichText_setVerticalSpace : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_Helper_seekWidgetByName : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_RichText_formatText(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::RichText* cobj = (cocos2d::ui::RichText *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichText_formatText : Invalid Native Object"); - if (argc == 0) { - cobj->formatText(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - JS_ReportError(cx, "js_cocos2dx_ui_RichText_formatText : wrong number of arguments: %d, was expecting %d", argc, 0); - return false; -} -bool js_cocos2dx_ui_RichText_removeElement(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_Helper_seekWidgetByTag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - - JSObject *obj = NULL; - cocos2d::ui::RichText* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (cocos2d::ui::RichText *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichText_removeElement : Invalid Native Object"); - do { - if (argc == 1) { - cocos2d::ui::RichElement* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::ui::RichElement*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cobj->removeElement(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - } while(0); - - do { - if (argc == 1) { - int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - if (!ok) { ok = true; break; } - cobj->removeElement(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - } while(0); - - JS_ReportError(cx, "js_cocos2dx_ui_RichText_removeElement : wrong number of arguments"); - return false; -} -bool js_cocos2dx_ui_RichText_create(JSContext *cx, uint32_t argc, jsval *vp) -{ - if (argc == 0) { - cocos2d::ui::RichText* ret = cocos2d::ui::RichText::create(); + if (argc == 2) { + cocos2d::ui::Widget* arg0; + int arg1; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::ui::Widget*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Helper_seekWidgetByTag : Error processing arguments"); + cocos2d::ui::Widget* ret = cocos2d::ui::Helper::seekWidgetByTag(arg0, arg1); jsval jsret = JSVAL_NULL; do { if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::RichText*)ret); + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Widget*)ret); jsret = OBJECT_TO_JSVAL(jsProxy->obj); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_RichText_create : wrong number of arguments"); + JS_ReportError(cx, "js_cocos2dx_ui_Helper_seekWidgetByTag : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_RichText_constructor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_Helper_restrictCapInsetRect(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - cocos2d::ui::RichText* cobj = new (std::nothrow) cocos2d::ui::RichText(); - cocos2d::Ref *_ccobj = dynamic_cast(cobj); - if (_ccobj) { - _ccobj->autorelease(); + if (argc == 2) { + cocos2d::Rect arg0; + cocos2d::Size arg1; + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Helper_restrictCapInsetRect : Error processing arguments"); + cocos2d::Rect ret = cocos2d::ui::Helper::restrictCapInsetRect(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = ccrect_to_jsval(cx, ret); + args.rval().set(jsret); + return true; } - TypeTest t; - js_type_class_t *typeClass = nullptr; - std::string typeName = t.s_name(); - auto typeMapIter = _js_global_type_map.find(typeName); - CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); - typeClass = typeMapIter->second; - CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); - // link the native object with the javascript object - js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichText"); - if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - return true; + JS_ReportError(cx, "js_cocos2dx_ui_Helper_restrictCapInsetRect : wrong number of arguments"); + return false; } +bool js_cocos2dx_ui_Helper_doLayout(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + cocos2d::Node* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Helper_doLayout : Error processing arguments"); + cocos2d::ui::Helper::doLayout(arg0); + args.rval().setUndefined(); + return true; + } + JS_ReportError(cx, "js_cocos2dx_ui_Helper_doLayout : wrong number of arguments"); + return false; +} -extern JSObject *jsb_cocos2d_ui_Widget_prototype; -void js_cocos2d_ui_RichText_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (RichText)", obj); -} -static bool js_cocos2d_ui_RichText_ctor(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); - cocos2d::ui::RichText *nobj = new (std::nothrow) cocos2d::ui::RichText(); - if (nobj) { - nobj->autorelease(); - } - js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichText"); - bool isFound = false; - if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; +void js_cocos2d_ui_Helper_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (Helper)", obj); } -void js_register_cocos2dx_ui_RichText(JSContext *cx, JSObject *global) { - jsb_cocos2d_ui_RichText_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_ui_RichText_class->name = "RichText"; - jsb_cocos2d_ui_RichText_class->addProperty = JS_PropertyStub; - jsb_cocos2d_ui_RichText_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_ui_RichText_class->getProperty = JS_PropertyStub; - jsb_cocos2d_ui_RichText_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_ui_RichText_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_ui_RichText_class->resolve = JS_ResolveStub; - jsb_cocos2d_ui_RichText_class->convert = JS_ConvertStub; - jsb_cocos2d_ui_RichText_class->finalize = js_cocos2d_ui_RichText_finalize; - jsb_cocos2d_ui_RichText_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + +void js_register_cocos2dx_ui_Helper(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_Helper_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_Helper_class->name = "Helper"; + jsb_cocos2d_ui_Helper_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_Helper_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_Helper_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_Helper_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_Helper_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_Helper_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_Helper_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_Helper_class->finalize = js_cocos2d_ui_Helper_finalize; + jsb_cocos2d_ui_Helper_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("insertElement", js_cocos2dx_ui_RichText_insertElement, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setAnchorPoint", js_cocos2dx_ui_RichText_setAnchorPoint, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("pushBackElement", js_cocos2dx_ui_RichText_pushBackElement, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("ignoreContentAdaptWithSize", js_cocos2dx_ui_RichText_ignoreContentAdaptWithSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setVerticalSpace", js_cocos2dx_ui_RichText_setVerticalSpace, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("formatText", js_cocos2dx_ui_RichText_formatText, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("removeElement", js_cocos2dx_ui_RichText_removeElement, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("ctor", js_cocos2d_ui_RichText_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_ui_RichText_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getSubStringOfUTF8String", js_cocos2dx_ui_Helper_getSubStringOfUTF8String, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("changeLayoutSystemActiveState", js_cocos2dx_ui_Helper_changeLayoutSystemActiveState, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("seekActionWidgetByActionTag", js_cocos2dx_ui_Helper_seekActionWidgetByActionTag, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("seekWidgetByName", js_cocos2dx_ui_Helper_seekWidgetByName, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("seekWidgetByTag", js_cocos2dx_ui_Helper_seekWidgetByTag, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("restrictCapInsetRect", js_cocos2dx_ui_Helper_restrictCapInsetRect, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("doLayout", js_cocos2dx_ui_Helper_doLayout, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; - jsb_cocos2d_ui_RichText_prototype = JS_InitClass( + jsb_cocos2d_ui_Helper_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Widget_prototype, - jsb_cocos2d_ui_RichText_class, - js_cocos2dx_ui_RichText_constructor, 0, // constructor + JS::NullPtr(), // parent proto + jsb_cocos2d_ui_Helper_class, + empty_constructor, 0, properties, funcs, NULL, // no static properties @@ -10799,174 +11062,133 @@ void js_register_cocos2dx_ui_RichText(JSContext *cx, JSObject *global) { // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "RichText", JSPROP_ENUMERATE | JSPROP_READONLY, &found); +// JS_SetPropertyAttributes(cx, global, "Helper", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; + TypeTest t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_ui_RichText_class; - p->proto = jsb_cocos2d_ui_RichText_prototype; - p->parentProto = jsb_cocos2d_ui_Widget_prototype; + p->jsclass = jsb_cocos2d_ui_Helper_class; + p->proto = jsb_cocos2d_ui_Helper_prototype; + p->parentProto = NULL; _js_global_type_map.insert(std::make_pair(typeName, p)); } } -JSClass *jsb_cocos2d_ui_HBox_class; -JSObject *jsb_cocos2d_ui_HBox_prototype; +JSClass *jsb_cocos2d_ui_RichElement_class; +JSObject *jsb_cocos2d_ui_RichElement_prototype; -bool js_cocos2dx_ui_HBox_initWithSize(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_RichElement_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::HBox* cobj = (cocos2d::ui::HBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_HBox_initWithSize : Invalid Native Object"); - if (argc == 1) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_HBox_initWithSize : Error processing arguments"); - bool ret = cobj->initWithSize(arg0); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_ui_HBox_initWithSize : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_ui_HBox_create(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - - do { - if (argc == 1) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cocos2d::ui::HBox* ret = cocos2d::ui::HBox::create(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::HBox*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - - do { - if (argc == 0) { - cocos2d::ui::HBox* ret = cocos2d::ui::HBox::create(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::HBox*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - JS_ReportError(cx, "js_cocos2dx_ui_HBox_create : wrong number of arguments"); + cocos2d::ui::RichElement* cobj = (cocos2d::ui::RichElement *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichElement_init : Invalid Native Object"); + if (argc == 3) { + int arg0; + cocos2d::Color3B arg1; + uint16_t arg2; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_cccolor3b(cx, args.get(1), &arg1); + ok &= jsval_to_uint16(cx, args.get(2), &arg2); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichElement_init : Error processing arguments"); + bool ret = cobj->init(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_RichElement_init : wrong number of arguments: %d, was expecting %d", argc, 3); return false; } -bool js_cocos2dx_ui_HBox_constructor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_RichElement_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - cocos2d::ui::HBox* cobj = new (std::nothrow) cocos2d::ui::HBox(); + cocos2d::ui::RichElement* cobj = new (std::nothrow) cocos2d::ui::RichElement(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); if (_ccobj) { _ccobj->autorelease(); } - TypeTest t; + TypeTest t; js_type_class_t *typeClass = nullptr; std::string typeName = t.s_name(); auto typeMapIter = _js_global_type_map.find(typeName); CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::HBox"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElement"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } -extern JSObject *jsb_cocos2d_ui_Layout_prototype; -void js_cocos2d_ui_HBox_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (HBox)", obj); +void js_cocos2d_ui_RichElement_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (RichElement)", obj); } -static bool js_cocos2d_ui_HBox_ctor(JSContext *cx, uint32_t argc, jsval *vp) +static bool js_cocos2d_ui_RichElement_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); - cocos2d::ui::HBox *nobj = new (std::nothrow) cocos2d::ui::HBox(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::ui::RichElement *nobj = new (std::nothrow) cocos2d::ui::RichElement(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::HBox"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElement"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_HBox(JSContext *cx, JSObject *global) { - jsb_cocos2d_ui_HBox_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_ui_HBox_class->name = "HBox"; - jsb_cocos2d_ui_HBox_class->addProperty = JS_PropertyStub; - jsb_cocos2d_ui_HBox_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_ui_HBox_class->getProperty = JS_PropertyStub; - jsb_cocos2d_ui_HBox_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_ui_HBox_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_ui_HBox_class->resolve = JS_ResolveStub; - jsb_cocos2d_ui_HBox_class->convert = JS_ConvertStub; - jsb_cocos2d_ui_HBox_class->finalize = js_cocos2d_ui_HBox_finalize; - jsb_cocos2d_ui_HBox_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); +void js_register_cocos2dx_ui_RichElement(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_RichElement_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_RichElement_class->name = "RichElement"; + jsb_cocos2d_ui_RichElement_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_RichElement_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_RichElement_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_RichElement_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_RichElement_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_RichElement_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_RichElement_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_RichElement_class->finalize = js_cocos2d_ui_RichElement_finalize; + jsb_cocos2d_ui_RichElement_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("initWithSize", js_cocos2dx_ui_HBox_initWithSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("ctor", js_cocos2d_ui_HBox_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("init", js_cocos2dx_ui_RichElement_init, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_ui_RichElement_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; - static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_ui_HBox_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; + JSFunctionSpec *st_funcs = NULL; - jsb_cocos2d_ui_HBox_prototype = JS_InitClass( + jsb_cocos2d_ui_RichElement_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Layout_prototype, - jsb_cocos2d_ui_HBox_class, - js_cocos2dx_ui_HBox_constructor, 0, // constructor + JS::NullPtr(), // parent proto + jsb_cocos2d_ui_RichElement_class, + js_cocos2dx_ui_RichElement_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -10974,174 +11196,178 @@ void js_register_cocos2dx_ui_HBox(JSContext *cx, JSObject *global) { // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "HBox", JSPROP_ENUMERATE | JSPROP_READONLY, &found); +// JS_SetPropertyAttributes(cx, global, "RichElement", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; + TypeTest t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_ui_HBox_class; - p->proto = jsb_cocos2d_ui_HBox_prototype; - p->parentProto = jsb_cocos2d_ui_Layout_prototype; + p->jsclass = jsb_cocos2d_ui_RichElement_class; + p->proto = jsb_cocos2d_ui_RichElement_prototype; + p->parentProto = NULL; _js_global_type_map.insert(std::make_pair(typeName, p)); } } -JSClass *jsb_cocos2d_ui_VBox_class; -JSObject *jsb_cocos2d_ui_VBox_prototype; +JSClass *jsb_cocos2d_ui_RichElementText_class; +JSObject *jsb_cocos2d_ui_RichElementText_prototype; -bool js_cocos2dx_ui_VBox_initWithSize(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_RichElementText_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::VBox* cobj = (cocos2d::ui::VBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_VBox_initWithSize : Invalid Native Object"); - if (argc == 1) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_VBox_initWithSize : Error processing arguments"); - bool ret = cobj->initWithSize(arg0); + cocos2d::ui::RichElementText* cobj = (cocos2d::ui::RichElementText *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichElementText_init : Invalid Native Object"); + if (argc == 6) { + int arg0; + cocos2d::Color3B arg1; + uint16_t arg2; + std::string arg3; + std::string arg4; + double arg5; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_cccolor3b(cx, args.get(1), &arg1); + ok &= jsval_to_uint16(cx, args.get(2), &arg2); + ok &= jsval_to_std_string(cx, args.get(3), &arg3); + ok &= jsval_to_std_string(cx, args.get(4), &arg4); + ok &= JS::ToNumber( cx, args.get(5), &arg5) && !isnan(arg5); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichElementText_init : Error processing arguments"); + bool ret = cobj->init(arg0, arg1, arg2, arg3, arg4, arg5); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_VBox_initWithSize : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_RichElementText_init : wrong number of arguments: %d, was expecting %d", argc, 6); return false; } -bool js_cocos2dx_ui_VBox_create(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_RichElementText_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - - do { - if (argc == 1) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cocos2d::ui::VBox* ret = cocos2d::ui::VBox::create(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::VBox*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - - do { - if (argc == 0) { - cocos2d::ui::VBox* ret = cocos2d::ui::VBox::create(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::VBox*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; + if (argc == 6) { + int arg0; + cocos2d::Color3B arg1; + uint16_t arg2; + std::string arg3; + std::string arg4; + double arg5; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_cccolor3b(cx, args.get(1), &arg1); + ok &= jsval_to_uint16(cx, args.get(2), &arg2); + ok &= jsval_to_std_string(cx, args.get(3), &arg3); + ok &= jsval_to_std_string(cx, args.get(4), &arg4); + ok &= JS::ToNumber( cx, args.get(5), &arg5) && !isnan(arg5); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichElementText_create : Error processing arguments"); + cocos2d::ui::RichElementText* ret = cocos2d::ui::RichElementText::create(arg0, arg1, arg2, arg3, arg4, arg5); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::RichElementText*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; } } while (0); - JS_ReportError(cx, "js_cocos2dx_ui_VBox_create : wrong number of arguments"); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_ui_RichElementText_create : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_VBox_constructor(JSContext *cx, uint32_t argc, jsval *vp) + +bool js_cocos2dx_ui_RichElementText_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - cocos2d::ui::VBox* cobj = new (std::nothrow) cocos2d::ui::VBox(); + cocos2d::ui::RichElementText* cobj = new (std::nothrow) cocos2d::ui::RichElementText(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); if (_ccobj) { _ccobj->autorelease(); } - TypeTest t; + TypeTest t; js_type_class_t *typeClass = nullptr; std::string typeName = t.s_name(); auto typeMapIter = _js_global_type_map.find(typeName); CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::VBox"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElementText"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } -extern JSObject *jsb_cocos2d_ui_Layout_prototype; +extern JSObject *jsb_cocos2d_ui_RichElement_prototype; -void js_cocos2d_ui_VBox_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (VBox)", obj); +void js_cocos2d_ui_RichElementText_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (RichElementText)", obj); } -static bool js_cocos2d_ui_VBox_ctor(JSContext *cx, uint32_t argc, jsval *vp) +static bool js_cocos2d_ui_RichElementText_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); - cocos2d::ui::VBox *nobj = new (std::nothrow) cocos2d::ui::VBox(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::ui::RichElementText *nobj = new (std::nothrow) cocos2d::ui::RichElementText(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::VBox"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElementText"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_VBox(JSContext *cx, JSObject *global) { - jsb_cocos2d_ui_VBox_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_ui_VBox_class->name = "VBox"; - jsb_cocos2d_ui_VBox_class->addProperty = JS_PropertyStub; - jsb_cocos2d_ui_VBox_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_ui_VBox_class->getProperty = JS_PropertyStub; - jsb_cocos2d_ui_VBox_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_ui_VBox_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_ui_VBox_class->resolve = JS_ResolveStub; - jsb_cocos2d_ui_VBox_class->convert = JS_ConvertStub; - jsb_cocos2d_ui_VBox_class->finalize = js_cocos2d_ui_VBox_finalize; - jsb_cocos2d_ui_VBox_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); +void js_register_cocos2dx_ui_RichElementText(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_RichElementText_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_RichElementText_class->name = "RichElementText"; + jsb_cocos2d_ui_RichElementText_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_RichElementText_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_RichElementText_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_RichElementText_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_RichElementText_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_RichElementText_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_RichElementText_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_RichElementText_class->finalize = js_cocos2d_ui_RichElementText_finalize; + jsb_cocos2d_ui_RichElementText_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("initWithSize", js_cocos2dx_ui_VBox_initWithSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("ctor", js_cocos2d_ui_VBox_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("init", js_cocos2dx_ui_RichElementText_init, 6, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_ui_RichElementText_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_ui_VBox_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("create", js_cocos2dx_ui_RichElementText_create, 6, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; - jsb_cocos2d_ui_VBox_prototype = JS_InitClass( + jsb_cocos2d_ui_RichElementText_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Layout_prototype, - jsb_cocos2d_ui_VBox_class, - js_cocos2dx_ui_VBox_constructor, 0, // constructor + JS::RootedObject(cx, jsb_cocos2d_ui_RichElement_prototype), + jsb_cocos2d_ui_RichElementText_class, + js_cocos2dx_ui_RichElementText_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -11149,174 +11375,170 @@ void js_register_cocos2dx_ui_VBox(JSContext *cx, JSObject *global) { // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "VBox", JSPROP_ENUMERATE | JSPROP_READONLY, &found); +// JS_SetPropertyAttributes(cx, global, "RichElementText", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; + TypeTest t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_ui_VBox_class; - p->proto = jsb_cocos2d_ui_VBox_prototype; - p->parentProto = jsb_cocos2d_ui_Layout_prototype; + p->jsclass = jsb_cocos2d_ui_RichElementText_class; + p->proto = jsb_cocos2d_ui_RichElementText_prototype; + p->parentProto = jsb_cocos2d_ui_RichElement_prototype; _js_global_type_map.insert(std::make_pair(typeName, p)); } } -JSClass *jsb_cocos2d_ui_RelativeBox_class; -JSObject *jsb_cocos2d_ui_RelativeBox_prototype; +JSClass *jsb_cocos2d_ui_RichElementImage_class; +JSObject *jsb_cocos2d_ui_RichElementImage_prototype; -bool js_cocos2dx_ui_RelativeBox_initWithSize(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_RichElementImage_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::RelativeBox* cobj = (cocos2d::ui::RelativeBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RelativeBox_initWithSize : Invalid Native Object"); - if (argc == 1) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RelativeBox_initWithSize : Error processing arguments"); - bool ret = cobj->initWithSize(arg0); + cocos2d::ui::RichElementImage* cobj = (cocos2d::ui::RichElementImage *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichElementImage_init : Invalid Native Object"); + if (argc == 4) { + int arg0; + cocos2d::Color3B arg1; + uint16_t arg2; + std::string arg3; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_cccolor3b(cx, args.get(1), &arg1); + ok &= jsval_to_uint16(cx, args.get(2), &arg2); + ok &= jsval_to_std_string(cx, args.get(3), &arg3); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichElementImage_init : Error processing arguments"); + bool ret = cobj->init(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_RelativeBox_initWithSize : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_RichElementImage_init : wrong number of arguments: %d, was expecting %d", argc, 4); return false; } -bool js_cocos2dx_ui_RelativeBox_create(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_RichElementImage_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - - do { - if (argc == 1) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cocos2d::ui::RelativeBox* ret = cocos2d::ui::RelativeBox::create(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::RelativeBox*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - - do { - if (argc == 0) { - cocos2d::ui::RelativeBox* ret = cocos2d::ui::RelativeBox::create(); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::RelativeBox*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; + if (argc == 4) { + int arg0; + cocos2d::Color3B arg1; + uint16_t arg2; + std::string arg3; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_cccolor3b(cx, args.get(1), &arg1); + ok &= jsval_to_uint16(cx, args.get(2), &arg2); + ok &= jsval_to_std_string(cx, args.get(3), &arg3); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichElementImage_create : Error processing arguments"); + cocos2d::ui::RichElementImage* ret = cocos2d::ui::RichElementImage::create(arg0, arg1, arg2, arg3); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::RichElementImage*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; } } while (0); - JS_ReportError(cx, "js_cocos2dx_ui_RelativeBox_create : wrong number of arguments"); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_ui_RichElementImage_create : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_RelativeBox_constructor(JSContext *cx, uint32_t argc, jsval *vp) + +bool js_cocos2dx_ui_RichElementImage_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - cocos2d::ui::RelativeBox* cobj = new (std::nothrow) cocos2d::ui::RelativeBox(); + cocos2d::ui::RichElementImage* cobj = new (std::nothrow) cocos2d::ui::RichElementImage(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); if (_ccobj) { _ccobj->autorelease(); } - TypeTest t; + TypeTest t; js_type_class_t *typeClass = nullptr; std::string typeName = t.s_name(); auto typeMapIter = _js_global_type_map.find(typeName); CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RelativeBox"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElementImage"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } -extern JSObject *jsb_cocos2d_ui_Layout_prototype; +extern JSObject *jsb_cocos2d_ui_RichElement_prototype; -void js_cocos2d_ui_RelativeBox_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (RelativeBox)", obj); +void js_cocos2d_ui_RichElementImage_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (RichElementImage)", obj); } -static bool js_cocos2d_ui_RelativeBox_ctor(JSContext *cx, uint32_t argc, jsval *vp) +static bool js_cocos2d_ui_RichElementImage_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); - cocos2d::ui::RelativeBox *nobj = new (std::nothrow) cocos2d::ui::RelativeBox(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::ui::RichElementImage *nobj = new (std::nothrow) cocos2d::ui::RichElementImage(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RelativeBox"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElementImage"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_RelativeBox(JSContext *cx, JSObject *global) { - jsb_cocos2d_ui_RelativeBox_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_ui_RelativeBox_class->name = "RelativeBox"; - jsb_cocos2d_ui_RelativeBox_class->addProperty = JS_PropertyStub; - jsb_cocos2d_ui_RelativeBox_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_ui_RelativeBox_class->getProperty = JS_PropertyStub; - jsb_cocos2d_ui_RelativeBox_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_ui_RelativeBox_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_ui_RelativeBox_class->resolve = JS_ResolveStub; - jsb_cocos2d_ui_RelativeBox_class->convert = JS_ConvertStub; - jsb_cocos2d_ui_RelativeBox_class->finalize = js_cocos2d_ui_RelativeBox_finalize; - jsb_cocos2d_ui_RelativeBox_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); +void js_register_cocos2dx_ui_RichElementImage(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_RichElementImage_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_RichElementImage_class->name = "RichElementImage"; + jsb_cocos2d_ui_RichElementImage_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_RichElementImage_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_RichElementImage_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_RichElementImage_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_RichElementImage_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_RichElementImage_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_RichElementImage_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_RichElementImage_class->finalize = js_cocos2d_ui_RichElementImage_finalize; + jsb_cocos2d_ui_RichElementImage_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("initWithSize", js_cocos2dx_ui_RelativeBox_initWithSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("ctor", js_cocos2d_ui_RelativeBox_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("init", js_cocos2dx_ui_RichElementImage_init, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_ui_RichElementImage_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_ui_RelativeBox_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("create", js_cocos2dx_ui_RichElementImage_create, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; - jsb_cocos2d_ui_RelativeBox_prototype = JS_InitClass( + jsb_cocos2d_ui_RichElementImage_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Layout_prototype, - jsb_cocos2d_ui_RelativeBox_class, - js_cocos2dx_ui_RelativeBox_constructor, 0, // constructor + JS::RootedObject(cx, jsb_cocos2d_ui_RichElement_prototype), + jsb_cocos2d_ui_RichElementImage_class, + js_cocos2dx_ui_RichElementImage_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -11324,1211 +11546,3013 @@ void js_register_cocos2dx_ui_RelativeBox(JSContext *cx, JSObject *global) { // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "RelativeBox", JSPROP_ENUMERATE | JSPROP_READONLY, &found); +// JS_SetPropertyAttributes(cx, global, "RichElementImage", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; + TypeTest t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_ui_RelativeBox_class; - p->proto = jsb_cocos2d_ui_RelativeBox_prototype; - p->parentProto = jsb_cocos2d_ui_Layout_prototype; + p->jsclass = jsb_cocos2d_ui_RichElementImage_class; + p->proto = jsb_cocos2d_ui_RichElementImage_prototype; + p->parentProto = jsb_cocos2d_ui_RichElement_prototype; _js_global_type_map.insert(std::make_pair(typeName, p)); } } -JSClass *jsb_cocos2d_ui_Scale9Sprite_class; -JSObject *jsb_cocos2d_ui_Scale9Sprite_prototype; +JSClass *jsb_cocos2d_ui_RichElementCustomNode_class; +JSObject *jsb_cocos2d_ui_RichElementCustomNode_prototype; -bool js_cocos2dx_ui_Scale9Sprite_disableCascadeColor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_RichElementCustomNode_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_disableCascadeColor : Invalid Native Object"); - if (argc == 0) { - cobj->disableCascadeColor(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::RichElementCustomNode* cobj = (cocos2d::ui::RichElementCustomNode *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichElementCustomNode_init : Invalid Native Object"); + if (argc == 4) { + int arg0; + cocos2d::Color3B arg1; + uint16_t arg2; + cocos2d::Node* arg3; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_cccolor3b(cx, args.get(1), &arg1); + ok &= jsval_to_uint16(cx, args.get(2), &arg2); + do { + if (!args.get(3).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(3).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg3 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichElementCustomNode_init : Error processing arguments"); + bool ret = cobj->init(arg0, arg1, arg2, arg3); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_disableCascadeColor : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_RichElementCustomNode_init : wrong number of arguments: %d, was expecting %d", argc, 4); return false; } -bool js_cocos2dx_ui_Scale9Sprite_updateWithSprite(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_RichElementCustomNode_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - - JSObject *obj = NULL; - cocos2d::ui::Scale9Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_updateWithSprite : Invalid Native Object"); - do { - if (argc == 6) { - cocos2d::Sprite* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); - if (!ok) { ok = true; break; } - bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); - cocos2d::Vec2 arg3; - ok &= jsval_to_vector2(cx, argv[3], &arg3); - if (!ok) { ok = true; break; } - cocos2d::Size arg4; - ok &= jsval_to_ccsize(cx, argv[4], &arg4); - if (!ok) { ok = true; break; } - cocos2d::Rect arg5; - ok &= jsval_to_ccrect(cx, argv[5], &arg5); - if (!ok) { ok = true; break; } - bool ret = cobj->updateWithSprite(arg0, arg1, arg2, arg3, arg4, arg5); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while(0); - - do { - if (argc == 4) { - cocos2d::Sprite* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); - if (!ok) { ok = true; break; } - bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); - cocos2d::Rect arg3; - ok &= jsval_to_ccrect(cx, argv[3], &arg3); - if (!ok) { ok = true; break; } - bool ret = cobj->updateWithSprite(arg0, arg1, arg2, arg3); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while(0); - - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_updateWithSprite : wrong number of arguments"); - return false; -} -bool js_cocos2dx_ui_Scale9Sprite_isFlippedX(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_isFlippedX : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->isFlippedX(); + if (argc == 4) { + int arg0; + cocos2d::Color3B arg1; + uint16_t arg2; + cocos2d::Node* arg3; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= jsval_to_cccolor3b(cx, args.get(1), &arg1); + ok &= jsval_to_uint16(cx, args.get(2), &arg2); + do { + if (!args.get(3).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(3).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg3 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichElementCustomNode_create : Error processing arguments"); + cocos2d::ui::RichElementCustomNode* ret = cocos2d::ui::RichElementCustomNode::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::RichElementCustomNode*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); return true; } - - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_isFlippedX : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_RichElementCustomNode_create : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_Scale9Sprite_setFlippedY(JSContext *cx, uint32_t argc, jsval *vp) + +bool js_cocos2dx_ui_RichElementCustomNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setFlippedY : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setFlippedY : Error processing arguments"); - cobj->setFlippedY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; + cocos2d::ui::RichElementCustomNode* cobj = new (std::nothrow) cocos2d::ui::RichElementCustomNode(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElementCustomNode"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setFlippedY : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; + +extern JSObject *jsb_cocos2d_ui_RichElement_prototype; + +void js_cocos2d_ui_RichElementCustomNode_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (RichElementCustomNode)", obj); } -bool js_cocos2dx_ui_Scale9Sprite_setFlippedX(JSContext *cx, uint32_t argc, jsval *vp) + +static bool js_cocos2d_ui_RichElementCustomNode_ctor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::ui::RichElementCustomNode *nobj = new (std::nothrow) cocos2d::ui::RichElementCustomNode(); + if (nobj) { + nobj->autorelease(); + } + js_proxy_t* p = jsb_new_proxy(nobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElementCustomNode"); + bool isFound = false; + if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); + return true; +} +void js_register_cocos2dx_ui_RichElementCustomNode(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_RichElementCustomNode_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_RichElementCustomNode_class->name = "RichElementCustomNode"; + jsb_cocos2d_ui_RichElementCustomNode_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_RichElementCustomNode_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_RichElementCustomNode_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_RichElementCustomNode_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_RichElementCustomNode_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_RichElementCustomNode_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_RichElementCustomNode_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_RichElementCustomNode_class->finalize = js_cocos2d_ui_RichElementCustomNode_finalize; + jsb_cocos2d_ui_RichElementCustomNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("init", js_cocos2dx_ui_RichElementCustomNode_init, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_ui_RichElementCustomNode_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_ui_RichElementCustomNode_create, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_ui_RichElementCustomNode_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_ui_RichElement_prototype), + jsb_cocos2d_ui_RichElementCustomNode_class, + js_cocos2dx_ui_RichElementCustomNode_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "RichElementCustomNode", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_ui_RichElementCustomNode_class; + p->proto = jsb_cocos2d_ui_RichElementCustomNode_prototype; + p->parentProto = jsb_cocos2d_ui_RichElement_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_ui_RichText_class; +JSObject *jsb_cocos2d_ui_RichText_prototype; + +bool js_cocos2dx_ui_RichText_insertElement(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setFlippedX : Invalid Native Object"); - if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setFlippedX : Error processing arguments"); - cobj->setFlippedX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::RichText* cobj = (cocos2d::ui::RichText *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichText_insertElement : Invalid Native Object"); + if (argc == 2) { + cocos2d::ui::RichElement* arg0; + int arg1; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::ui::RichElement*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichText_insertElement : Error processing arguments"); + cobj->insertElement(arg0, arg1); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setFlippedX : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_RichText_insertElement : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_ui_Scale9Sprite_setScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_RichText_pushBackElement(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setScale9Enabled : Invalid Native Object"); + cocos2d::ui::RichText* cobj = (cocos2d::ui::RichText *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichText_pushBackElement : Invalid Native Object"); if (argc == 1) { - bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setScale9Enabled : Error processing arguments"); - cobj->setScale9Enabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::RichElement* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::ui::RichElement*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichText_pushBackElement : Error processing arguments"); + cobj->pushBackElement(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setScale9Enabled : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_RichText_pushBackElement : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_Scale9Sprite_disableCascadeOpacity(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_RichText_setVerticalSpace(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_disableCascadeOpacity : Invalid Native Object"); - if (argc == 0) { - cobj->disableCascadeOpacity(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::RichText* cobj = (cocos2d::ui::RichText *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichText_setVerticalSpace : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichText_setVerticalSpace : Error processing arguments"); + cobj->setVerticalSpace(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_disableCascadeOpacity : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_RichText_setVerticalSpace : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_Scale9Sprite_setInsetBottom(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_RichText_formatText(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetBottom : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetBottom : Error processing arguments"); - cobj->setInsetBottom(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::RichText* cobj = (cocos2d::ui::RichText *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichText_formatText : Invalid Native Object"); + if (argc == 0) { + cobj->formatText(); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setInsetBottom : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_RichText_formatText : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrameName(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_RichText_removeElement(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; - cocos2d::ui::Scale9Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx); + cocos2d::ui::RichText* cobj = NULL; + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrameName : Invalid Native Object"); + cobj = (cocos2d::ui::RichText *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichText_removeElement : Invalid Native Object"); do { if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + cocos2d::ui::RichElement* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::ui::RichElement*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); if (!ok) { ok = true; break; } - bool ret = cobj->initWithSpriteFrameName(arg0); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + cobj->removeElement(arg0); + args.rval().setUndefined(); return true; } } while(0); do { - if (argc == 2) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } - bool ret = cobj->initWithSpriteFrameName(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + cobj->removeElement(arg0); + args.rval().setUndefined(); return true; } } while(0); - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrameName : wrong number of arguments"); + JS_ReportError(cx, "js_cocos2dx_ui_RichText_removeElement : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_Scale9Sprite_getSprite(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_RichText_create(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getSprite : Invalid Native Object"); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { - cocos2d::Sprite* ret = cobj->getSprite(); + cocos2d::ui::RichText* ret = cocos2d::ui::RichText::create(); jsval jsret = JSVAL_NULL; do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::RichText*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); return true; } - - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getSprite : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_RichText_create : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_Scale9Sprite_setInsetTop(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetTop : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetTop : Error processing arguments"); - cobj->setInsetTop(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setInsetTop : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_ui_Scale9Sprite_init(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_RichText_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - - JSObject *obj = NULL; - cocos2d::ui::Scale9Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_init : Invalid Native Object"); - do { - if (argc == 4) { - cocos2d::Sprite* arg0; + cocos2d::ui::RichText* cobj = new (std::nothrow) cocos2d::ui::RichText(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichText"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocos2d_ui_Widget_prototype; + +void js_cocos2d_ui_RichText_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (RichText)", obj); +} + +static bool js_cocos2d_ui_RichText_ctor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::ui::RichText *nobj = new (std::nothrow) cocos2d::ui::RichText(); + if (nobj) { + nobj->autorelease(); + } + js_proxy_t* p = jsb_new_proxy(nobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichText"); + bool isFound = false; + if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); + return true; +} +void js_register_cocos2dx_ui_RichText(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_RichText_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_RichText_class->name = "RichText"; + jsb_cocos2d_ui_RichText_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_RichText_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_RichText_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_RichText_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_RichText_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_RichText_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_RichText_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_RichText_class->finalize = js_cocos2d_ui_RichText_finalize; + jsb_cocos2d_ui_RichText_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("insertElement", js_cocos2dx_ui_RichText_insertElement, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("pushBackElement", js_cocos2dx_ui_RichText_pushBackElement, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setVerticalSpace", js_cocos2dx_ui_RichText_setVerticalSpace, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("formatText", js_cocos2dx_ui_RichText_formatText, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("removeElement", js_cocos2dx_ui_RichText_removeElement, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_ui_RichText_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_ui_RichText_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_ui_RichText_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), + jsb_cocos2d_ui_RichText_class, + js_cocos2dx_ui_RichText_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "RichText", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_ui_RichText_class; + p->proto = jsb_cocos2d_ui_RichText_prototype; + p->parentProto = jsb_cocos2d_ui_Widget_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_ui_HBox_class; +JSObject *jsb_cocos2d_ui_HBox_prototype; + +bool js_cocos2dx_ui_HBox_initWithSize(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::HBox* cobj = (cocos2d::ui::HBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_HBox_initWithSize : Invalid Native Object"); + if (argc == 1) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_HBox_initWithSize : Error processing arguments"); + bool ret = cobj->initWithSize(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_HBox_initWithSize : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_HBox_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + do { + if (argc == 1) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::ui::HBox* ret = cocos2d::ui::HBox::create(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::HBox*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 0) { + cocos2d::ui::HBox* ret = cocos2d::ui::HBox::create(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::HBox*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + JS_ReportError(cx, "js_cocos2dx_ui_HBox_create : wrong number of arguments"); + return false; +} +bool js_cocos2dx_ui_HBox_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::ui::HBox* cobj = new (std::nothrow) cocos2d::ui::HBox(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::HBox"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocos2d_ui_Layout_prototype; + +void js_cocos2d_ui_HBox_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (HBox)", obj); +} + +static bool js_cocos2d_ui_HBox_ctor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::ui::HBox *nobj = new (std::nothrow) cocos2d::ui::HBox(); + if (nobj) { + nobj->autorelease(); + } + js_proxy_t* p = jsb_new_proxy(nobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::HBox"); + bool isFound = false; + if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); + return true; +} +void js_register_cocos2dx_ui_HBox(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_HBox_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_HBox_class->name = "HBox"; + jsb_cocos2d_ui_HBox_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_HBox_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_HBox_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_HBox_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_HBox_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_HBox_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_HBox_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_HBox_class->finalize = js_cocos2d_ui_HBox_finalize; + jsb_cocos2d_ui_HBox_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("initWithSize", js_cocos2dx_ui_HBox_initWithSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_ui_HBox_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_ui_HBox_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_ui_HBox_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_ui_Layout_prototype), + jsb_cocos2d_ui_HBox_class, + js_cocos2dx_ui_HBox_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "HBox", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_ui_HBox_class; + p->proto = jsb_cocos2d_ui_HBox_prototype; + p->parentProto = jsb_cocos2d_ui_Layout_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_ui_VBox_class; +JSObject *jsb_cocos2d_ui_VBox_prototype; + +bool js_cocos2dx_ui_VBox_initWithSize(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::VBox* cobj = (cocos2d::ui::VBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_VBox_initWithSize : Invalid Native Object"); + if (argc == 1) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_VBox_initWithSize : Error processing arguments"); + bool ret = cobj->initWithSize(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_VBox_initWithSize : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_VBox_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + do { + if (argc == 1) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::ui::VBox* ret = cocos2d::ui::VBox::create(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::VBox*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 0) { + cocos2d::ui::VBox* ret = cocos2d::ui::VBox::create(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::VBox*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + JS_ReportError(cx, "js_cocos2dx_ui_VBox_create : wrong number of arguments"); + return false; +} +bool js_cocos2dx_ui_VBox_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::ui::VBox* cobj = new (std::nothrow) cocos2d::ui::VBox(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::VBox"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocos2d_ui_Layout_prototype; + +void js_cocos2d_ui_VBox_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (VBox)", obj); +} + +static bool js_cocos2d_ui_VBox_ctor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::ui::VBox *nobj = new (std::nothrow) cocos2d::ui::VBox(); + if (nobj) { + nobj->autorelease(); + } + js_proxy_t* p = jsb_new_proxy(nobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::VBox"); + bool isFound = false; + if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); + return true; +} +void js_register_cocos2dx_ui_VBox(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_VBox_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_VBox_class->name = "VBox"; + jsb_cocos2d_ui_VBox_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_VBox_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_VBox_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_VBox_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_VBox_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_VBox_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_VBox_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_VBox_class->finalize = js_cocos2d_ui_VBox_finalize; + jsb_cocos2d_ui_VBox_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("initWithSize", js_cocos2dx_ui_VBox_initWithSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_ui_VBox_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_ui_VBox_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_ui_VBox_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_ui_Layout_prototype), + jsb_cocos2d_ui_VBox_class, + js_cocos2dx_ui_VBox_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "VBox", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_ui_VBox_class; + p->proto = jsb_cocos2d_ui_VBox_prototype; + p->parentProto = jsb_cocos2d_ui_Layout_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_ui_RelativeBox_class; +JSObject *jsb_cocos2d_ui_RelativeBox_prototype; + +bool js_cocos2dx_ui_RelativeBox_initWithSize(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::RelativeBox* cobj = (cocos2d::ui::RelativeBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RelativeBox_initWithSize : Invalid Native Object"); + if (argc == 1) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RelativeBox_initWithSize : Error processing arguments"); + bool ret = cobj->initWithSize(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_RelativeBox_initWithSize : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_RelativeBox_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + do { + if (argc == 1) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::ui::RelativeBox* ret = cocos2d::ui::RelativeBox::create(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::RelativeBox*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 0) { + cocos2d::ui::RelativeBox* ret = cocos2d::ui::RelativeBox::create(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::RelativeBox*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + JS_ReportError(cx, "js_cocos2dx_ui_RelativeBox_create : wrong number of arguments"); + return false; +} +bool js_cocos2dx_ui_RelativeBox_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::ui::RelativeBox* cobj = new (std::nothrow) cocos2d::ui::RelativeBox(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RelativeBox"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + + +extern JSObject *jsb_cocos2d_ui_Layout_prototype; + +void js_cocos2d_ui_RelativeBox_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (RelativeBox)", obj); +} + +static bool js_cocos2d_ui_RelativeBox_ctor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::ui::RelativeBox *nobj = new (std::nothrow) cocos2d::ui::RelativeBox(); + if (nobj) { + nobj->autorelease(); + } + js_proxy_t* p = jsb_new_proxy(nobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RelativeBox"); + bool isFound = false; + if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); + return true; +} +void js_register_cocos2dx_ui_RelativeBox(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_RelativeBox_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_RelativeBox_class->name = "RelativeBox"; + jsb_cocos2d_ui_RelativeBox_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_RelativeBox_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_RelativeBox_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_RelativeBox_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_RelativeBox_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_RelativeBox_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_RelativeBox_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_RelativeBox_class->finalize = js_cocos2d_ui_RelativeBox_finalize; + jsb_cocos2d_ui_RelativeBox_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("initWithSize", js_cocos2dx_ui_RelativeBox_initWithSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_ui_RelativeBox_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_ui_RelativeBox_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_ui_RelativeBox_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_ui_Layout_prototype), + jsb_cocos2d_ui_RelativeBox_class, + js_cocos2dx_ui_RelativeBox_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "RelativeBox", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_ui_RelativeBox_class; + p->proto = jsb_cocos2d_ui_RelativeBox_prototype; + p->parentProto = jsb_cocos2d_ui_Layout_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_ui_Scale9Sprite_class; +JSObject *jsb_cocos2d_ui_Scale9Sprite_prototype; + +bool js_cocos2dx_ui_Scale9Sprite_disableCascadeColor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_disableCascadeColor : Invalid Native Object"); + if (argc == 0) { + cobj->disableCascadeColor(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_disableCascadeColor : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_updateWithSprite(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + JS::RootedObject obj(cx); + cocos2d::ui::Scale9Sprite* cobj = NULL; + obj = args.thisv().toObjectOrNull(); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_updateWithSprite : Invalid Native Object"); + do { + if (argc == 6) { + cocos2d::Sprite* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cocos2d::Rect arg1; + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + bool arg2; + arg2 = JS::ToBoolean(args.get(2)); + cocos2d::Vec2 arg3; + ok &= jsval_to_vector2(cx, args.get(3), &arg3); + if (!ok) { ok = true; break; } + cocos2d::Size arg4; + ok &= jsval_to_ccsize(cx, args.get(4), &arg4); + if (!ok) { ok = true; break; } + cocos2d::Rect arg5; + ok &= jsval_to_ccrect(cx, args.get(5), &arg5); + if (!ok) { ok = true; break; } + bool ret = cobj->updateWithSprite(arg0, arg1, arg2, arg3, arg4, arg5); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + do { + if (argc == 4) { + cocos2d::Sprite* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cocos2d::Rect arg1; + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + bool arg2; + arg2 = JS::ToBoolean(args.get(2)); + cocos2d::Rect arg3; + ok &= jsval_to_ccrect(cx, args.get(3), &arg3); + if (!ok) { ok = true; break; } + bool ret = cobj->updateWithSprite(arg0, arg1, arg2, arg3); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_updateWithSprite : wrong number of arguments"); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_isFlippedX(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_isFlippedX : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isFlippedX(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_isFlippedX : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_setScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setScale9Enabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setScale9Enabled : Error processing arguments"); + cobj->setScale9Enabled(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setScale9Enabled : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_setFlippedY(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setFlippedY : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setFlippedY : Error processing arguments"); + cobj->setFlippedY(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setFlippedY : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_setFlippedX(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setFlippedX : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setFlippedX : Error processing arguments"); + cobj->setFlippedX(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setFlippedX : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets : Invalid Native Object"); + if (argc == 1) { + cocos2d::Rect arg0; + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets : Error processing arguments"); + cocos2d::ui::Scale9Sprite* ret = cobj->resizableSpriteWithCapInsets(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_disableCascadeOpacity(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_disableCascadeOpacity : Invalid Native Object"); + if (argc == 0) { + cobj->disableCascadeOpacity(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_disableCascadeOpacity : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_setState(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setState : Invalid Native Object"); + if (argc == 1) { + cocos2d::ui::Scale9Sprite::State arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setState : Error processing arguments"); + cobj->setState(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setState : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_setInsetBottom(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetBottom : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetBottom : Error processing arguments"); + cobj->setInsetBottom(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setInsetBottom : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrameName(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + JS::RootedObject obj(cx); + cocos2d::ui::Scale9Sprite* cobj = NULL; + obj = args.thisv().toObjectOrNull(); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrameName : Invalid Native Object"); + do { + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithSpriteFrameName(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::Rect arg1; + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithSpriteFrameName(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrameName : wrong number of arguments"); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_getSprite(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getSprite : Invalid Native Object"); + if (argc == 0) { + cocos2d::Sprite* ret = cobj->getSprite(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Sprite*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getSprite : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_setInsetTop(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetTop : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetTop : Error processing arguments"); + cobj->setInsetTop(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setInsetTop : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_init(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + JS::RootedObject obj(cx); + cocos2d::ui::Scale9Sprite* cobj = NULL; + obj = args.thisv().toObjectOrNull(); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_init : Invalid Native Object"); + do { + if (argc == 3) { + cocos2d::Sprite* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cocos2d::Rect arg1; + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::Rect arg2; + ok &= jsval_to_ccrect(cx, args.get(2), &arg2); + if (!ok) { ok = true; break; } + bool ret = cobj->init(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + do { + if (argc == 4) { + cocos2d::Sprite* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cocos2d::Rect arg1; + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + bool arg2; + arg2 = JS::ToBoolean(args.get(2)); + cocos2d::Rect arg3; + ok &= jsval_to_ccrect(cx, args.get(3), &arg3); + if (!ok) { ok = true; break; } + bool ret = cobj->init(arg0, arg1, arg2, arg3); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + do { + if (argc == 6) { + cocos2d::Sprite* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cocos2d::Rect arg1; + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + bool arg2; + arg2 = JS::ToBoolean(args.get(2)); + cocos2d::Vec2 arg3; + ok &= jsval_to_vector2(cx, args.get(3), &arg3); + if (!ok) { ok = true; break; } + cocos2d::Size arg4; + ok &= jsval_to_ccsize(cx, args.get(4), &arg4); + if (!ok) { ok = true; break; } + cocos2d::Rect arg5; + ok &= jsval_to_ccrect(cx, args.get(5), &arg5); + if (!ok) { ok = true; break; } + bool ret = cobj->init(arg0, arg1, arg2, arg3, arg4, arg5); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_init : wrong number of arguments"); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_setPreferredSize(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setPreferredSize : Invalid Native Object"); + if (argc == 1) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setPreferredSize : Error processing arguments"); + cobj->setPreferredSize(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setPreferredSize : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_setSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setSpriteFrame : Invalid Native Object"); + if (argc == 1) { + cocos2d::SpriteFrame* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setSpriteFrame : Error processing arguments"); + cobj->setSpriteFrame(arg0); + args.rval().setUndefined(); + return true; + } + if (argc == 2) { + cocos2d::SpriteFrame* arg0; + cocos2d::Rect arg1; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setSpriteFrame : Error processing arguments"); + cobj->setSpriteFrame(arg0, arg1); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setSpriteFrame : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getBlendFunc : Invalid Native Object"); + if (argc == 0) { + const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); + jsval jsret = JSVAL_NULL; + jsret = blendfunc_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_getInsetBottom(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getInsetBottom : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getInsetBottom(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getInsetBottom : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_getCapInsets(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getCapInsets : Invalid Native Object"); + if (argc == 0) { + cocos2d::Rect ret = cobj->getCapInsets(); + jsval jsret = JSVAL_NULL; + jsret = ccrect_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getCapInsets : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_isScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_isScale9Enabled : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isScale9Enabled(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_isScale9Enabled : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_getInsetRight(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getInsetRight : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getInsetRight(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getInsetRight : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_getOriginalSize(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getOriginalSize : Invalid Native Object"); + if (argc == 0) { + cocos2d::Size ret = cobj->getOriginalSize(); + jsval jsret = JSVAL_NULL; + jsret = ccsize_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getOriginalSize : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_initWithFile(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + JS::RootedObject obj(cx); + cocos2d::ui::Scale9Sprite* cobj = NULL; + obj = args.thisv().toObjectOrNull(); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_initWithFile : Invalid Native Object"); + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::Rect arg1; + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithFile(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + do { + if (argc == 3) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::Rect arg1; + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::Rect arg2; + ok &= jsval_to_ccrect(cx, args.get(2), &arg2); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithFile(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + do { + if (argc == 2) { + cocos2d::Rect arg0; + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithFile(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + do { + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithFile(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_initWithFile : wrong number of arguments"); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setBlendFunc : Invalid Native Object"); + if (argc == 1) { + cocos2d::BlendFunc arg0; + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setBlendFunc : Error processing arguments"); + cobj->setBlendFunc(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_getInsetTop(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getInsetTop : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getInsetTop(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getInsetTop : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_setInsetLeft(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetLeft : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetLeft : Error processing arguments"); + cobj->setInsetLeft(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setInsetLeft : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + JS::RootedObject obj(cx); + cocos2d::ui::Scale9Sprite* cobj = NULL; + obj = args.thisv().toObjectOrNull(); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrame : Invalid Native Object"); + do { + if (argc == 1) { + cocos2d::SpriteFrame* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithSpriteFrame(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + do { + if (argc == 2) { + cocos2d::SpriteFrame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); - if (!ok) { ok = true; break; } - bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); - cocos2d::Rect arg3; - ok &= jsval_to_ccrect(cx, argv[3], &arg3); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } - bool ret = cobj->init(arg0, arg1, arg2, arg3); + bool ret = cobj->initWithSpriteFrame(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrame : wrong number of arguments"); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_getPreferredSize(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getPreferredSize : Invalid Native Object"); + if (argc == 0) { + cocos2d::Size ret = cobj->getPreferredSize(); + jsval jsret = JSVAL_NULL; + jsret = ccsize_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getPreferredSize : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_setCapInsets(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setCapInsets : Invalid Native Object"); + if (argc == 1) { + cocos2d::Rect arg0; + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setCapInsets : Error processing arguments"); + cobj->setCapInsets(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setCapInsets : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_isFlippedY(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_isFlippedY : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isFlippedY(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_isFlippedY : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_getInsetLeft(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getInsetLeft : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getInsetLeft(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getInsetLeft : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_setInsetRight(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetRight : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetRight : Error processing arguments"); + cobj->setInsetRight(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setInsetRight : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + do { + if (argc == 3) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::Rect arg1; + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::Rect arg2; + ok &= jsval_to_ccrect(cx, args.get(2), &arg2); + if (!ok) { ok = true; break; } + cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::create(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + do { if (argc == 0) { - bool ret = cobj->init(); + cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::create(); jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); return true; } - } while(0); - + } while (0); + do { - if (argc == 3) { - cocos2d::Sprite* arg0; + if (argc == 2) { + cocos2d::Rect arg0; + ok &= jsval_to_ccrect(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::Rect arg1; + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::create(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::create(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_create : wrong number of arguments"); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrameName(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::Rect arg1; + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::createWithSpriteFrameName(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + + do { + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::createWithSpriteFrameName(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + } while (0); + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrameName : wrong number of arguments"); + return false; +} +bool js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + do { + if (argc == 2) { + cocos2d::SpriteFrame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); - if (!ok) { ok = true; break; } - cocos2d::Rect arg2; - ok &= jsval_to_ccrect(cx, argv[2], &arg2); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } - bool ret = cobj->init(arg0, arg1, arg2); + cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::createWithSpriteFrame(arg0, arg1); jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); return true; } - } while(0); - + } while (0); + do { - if (argc == 6) { - cocos2d::Sprite* arg0; + if (argc == 1) { + cocos2d::SpriteFrame* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Sprite*)(jsProxy ? jsProxy->ptr : NULL); + arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } - cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); - if (!ok) { ok = true; break; } - bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); - cocos2d::Vec2 arg3; - ok &= jsval_to_vector2(cx, argv[3], &arg3); - if (!ok) { ok = true; break; } - cocos2d::Size arg4; - ok &= jsval_to_ccsize(cx, argv[4], &arg4); - if (!ok) { ok = true; break; } - cocos2d::Rect arg5; - ok &= jsval_to_ccrect(cx, argv[5], &arg5); - if (!ok) { ok = true; break; } - bool ret = cobj->init(arg0, arg1, arg2, arg3, arg4, arg5); + cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::createWithSpriteFrame(arg0); jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); return true; } - } while(0); - - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_init : wrong number of arguments"); + } while (0); + JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrame : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_Scale9Sprite_setPreferredSize(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_Scale9Sprite_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setPreferredSize : Invalid Native Object"); - if (argc == 1) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setPreferredSize : Error processing arguments"); - cobj->setPreferredSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; + cocos2d::ui::Scale9Sprite* cobj = new (std::nothrow) cocos2d::ui::Scale9Sprite(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Scale9Sprite"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setPreferredSize : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; + +extern JSObject *jsb_cocos2d_Node_prototype; + +void js_cocos2d_ui_Scale9Sprite_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (Scale9Sprite)", obj); } -bool js_cocos2dx_ui_Scale9Sprite_getInsetRight(JSContext *cx, uint32_t argc, jsval *vp) + +static bool js_cocos2d_ui_Scale9Sprite_ctor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::ui::Scale9Sprite *nobj = new (std::nothrow) cocos2d::ui::Scale9Sprite(); + if (nobj) { + nobj->autorelease(); + } + js_proxy_t* p = jsb_new_proxy(nobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Scale9Sprite"); + bool isFound = false; + if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); + return true; +} +void js_register_cocos2dx_ui_Scale9Sprite(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_Scale9Sprite_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_Scale9Sprite_class->name = "Scale9Sprite"; + jsb_cocos2d_ui_Scale9Sprite_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_Scale9Sprite_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_Scale9Sprite_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_Scale9Sprite_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_Scale9Sprite_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_Scale9Sprite_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_Scale9Sprite_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_Scale9Sprite_class->finalize = js_cocos2d_ui_Scale9Sprite_finalize; + jsb_cocos2d_ui_Scale9Sprite_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("disableCascadeColor", js_cocos2dx_ui_Scale9Sprite_disableCascadeColor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("updateWithSprite", js_cocos2dx_ui_Scale9Sprite_updateWithSprite, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isFlippedX", js_cocos2dx_ui_Scale9Sprite_isFlippedX, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setScale9Enabled", js_cocos2dx_ui_Scale9Sprite_setScale9Enabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setFlippedY", js_cocos2dx_ui_Scale9Sprite_setFlippedY, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setFlippedX", js_cocos2dx_ui_Scale9Sprite_setFlippedX, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("resizableSpriteWithCapInsets", js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("disableCascadeOpacity", js_cocos2dx_ui_Scale9Sprite_disableCascadeOpacity, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setState", js_cocos2dx_ui_Scale9Sprite_setState, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setInsetBottom", js_cocos2dx_ui_Scale9Sprite_setInsetBottom, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithSpriteFrameName", js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrameName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getSprite", js_cocos2dx_ui_Scale9Sprite_getSprite, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setInsetTop", js_cocos2dx_ui_Scale9Sprite_setInsetTop, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("init", js_cocos2dx_ui_Scale9Sprite_init, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPreferredSize", js_cocos2dx_ui_Scale9Sprite_setPreferredSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setSpriteFrame", js_cocos2dx_ui_Scale9Sprite_setSpriteFrame, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getBlendFunc", js_cocos2dx_ui_Scale9Sprite_getBlendFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getInsetBottom", js_cocos2dx_ui_Scale9Sprite_getInsetBottom, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getCapInsets", js_cocos2dx_ui_Scale9Sprite_getCapInsets, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isScale9Enabled", js_cocos2dx_ui_Scale9Sprite_isScale9Enabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getInsetRight", js_cocos2dx_ui_Scale9Sprite_getInsetRight, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getOriginalSize", js_cocos2dx_ui_Scale9Sprite_getOriginalSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithFile", js_cocos2dx_ui_Scale9Sprite_initWithFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setBlendFunc", js_cocos2dx_ui_Scale9Sprite_setBlendFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getInsetTop", js_cocos2dx_ui_Scale9Sprite_getInsetTop, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setInsetLeft", js_cocos2dx_ui_Scale9Sprite_setInsetLeft, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithSpriteFrame", js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrame, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getPreferredSize", js_cocos2dx_ui_Scale9Sprite_getPreferredSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setCapInsets", js_cocos2dx_ui_Scale9Sprite_setCapInsets, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isFlippedY", js_cocos2dx_ui_Scale9Sprite_isFlippedY, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getInsetLeft", js_cocos2dx_ui_Scale9Sprite_getInsetLeft, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setInsetRight", js_cocos2dx_ui_Scale9Sprite_setInsetRight, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_ui_Scale9Sprite_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_ui_Scale9Sprite_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("createWithSpriteFrameName", js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrameName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("createWithSpriteFrame", js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrame, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_ui_Scale9Sprite_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), + jsb_cocos2d_ui_Scale9Sprite_class, + js_cocos2dx_ui_Scale9Sprite_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "Scale9Sprite", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_ui_Scale9Sprite_class; + p->proto = jsb_cocos2d_ui_Scale9Sprite_prototype; + p->parentProto = jsb_cocos2d_Node_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +JSClass *jsb_cocos2d_ui_EditBox_class; +JSObject *jsb_cocos2d_ui_EditBox_prototype; + +bool js_cocos2dx_ui_EditBox_getText(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getInsetRight : Invalid Native Object"); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_getText : Invalid Native Object"); if (argc == 0) { - double ret = cobj->getInsetRight(); + const char* ret = cobj->getText(); jsval jsret = JSVAL_NULL; - jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = c_string_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getInsetRight : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_getText : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_Scale9Sprite_setSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_setFontSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setSpriteFrame : Invalid Native Object"); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setFontSize : Invalid Native Object"); if (argc == 1) { - cocos2d::SpriteFrame* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setSpriteFrame : Error processing arguments"); - cobj->setSpriteFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setFontSize : Error processing arguments"); + cobj->setFontSize(arg0); + args.rval().setUndefined(); return true; } - if (argc == 2) { - cocos2d::SpriteFrame* arg0; - cocos2d::Rect arg1; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - ok &= jsval_to_ccrect(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setSpriteFrame : Error processing arguments"); - cobj->setSpriteFrame(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setFontSize : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_EditBox_setPlaceholderFontName(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFontName : Invalid Native Object"); + if (argc == 1) { + const char* arg0; + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFontName : Error processing arguments"); + cobj->setPlaceholderFontName(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setSpriteFrame : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setPlaceholderFontName : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_Scale9Sprite_getInsetBottom(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_getPlaceHolder(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getInsetBottom : Invalid Native Object"); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_getPlaceHolder : Invalid Native Object"); if (argc == 0) { - double ret = cobj->getInsetBottom(); + const char* ret = cobj->getPlaceHolder(); jsval jsret = JSVAL_NULL; - jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = c_string_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getInsetBottom : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_getPlaceHolder : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_setFontName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets : Invalid Native Object"); - if (argc == 1) { - cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets : Error processing arguments"); - cocos2d::ui::Scale9Sprite* ret = cobj->resizableSpriteWithCapInsets(arg0); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setFontName : Invalid Native Object"); + if (argc == 1) { + const char* arg0; + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setFontName : Error processing arguments"); + cobj->setFontName(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setFontName : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_Scale9Sprite_isScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_setText(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_isScale9Enabled : Invalid Native Object"); - if (argc == 0) { - bool ret = cobj->isScale9Enabled(); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setText : Invalid Native Object"); + if (argc == 1) { + const char* arg0; + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setText : Error processing arguments"); + cobj->setText(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_isScale9Enabled : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setText : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_Scale9Sprite_getCapInsets(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_setPlaceholderFontSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getCapInsets : Invalid Native Object"); - if (argc == 0) { - cocos2d::Rect ret = cobj->getCapInsets(); - jsval jsret = JSVAL_NULL; - jsret = ccrect_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFontSize : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFontSize : Error processing arguments"); + cobj->setPlaceholderFontSize(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getCapInsets : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setPlaceholderFontSize : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_Scale9Sprite_getOriginalSize(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_setInputMode(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getOriginalSize : Invalid Native Object"); - if (argc == 0) { - cocos2d::Size ret = cobj->getOriginalSize(); - jsval jsret = JSVAL_NULL; - jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setInputMode : Invalid Native Object"); + if (argc == 1) { + cocos2d::ui::EditBox::InputMode arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setInputMode : Error processing arguments"); + cobj->setInputMode(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getOriginalSize : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setInputMode : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_Scale9Sprite_initWithFile(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_setPlaceholderFontColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; - cocos2d::ui::Scale9Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx); + cocos2d::ui::EditBox* cobj = NULL; + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_initWithFile : Invalid Native Object"); + cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFontColor : Invalid Native Object"); do { - if (argc == 2) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + if (argc == 1) { + cocos2d::Color4B arg0; + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } - bool ret = cobj->initWithFile(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + cobj->setPlaceholderFontColor(arg0); + args.rval().setUndefined(); return true; } } while(0); do { - if (argc == 3) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); - if (!ok) { ok = true; break; } - cocos2d::Rect arg2; - ok &= jsval_to_ccrect(cx, argv[2], &arg2); + if (argc == 1) { + cocos2d::Color3B arg0; + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } - bool ret = cobj->initWithFile(arg0, arg1, arg2); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + cobj->setPlaceholderFontColor(arg0); + args.rval().setUndefined(); return true; } } while(0); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setPlaceholderFontColor : wrong number of arguments"); + return false; +} +bool js_cocos2dx_ui_EditBox_setFontColor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + JS::RootedObject obj(cx); + cocos2d::ui::EditBox* cobj = NULL; + obj = args.thisv().toObjectOrNull(); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setFontColor : Invalid Native Object"); do { - if (argc == 2) { - cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + if (argc == 1) { + cocos2d::Color4B arg0; + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } - bool ret = cobj->initWithFile(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + cobj->setFontColor(arg0); + args.rval().setUndefined(); return true; } } while(0); do { if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + cocos2d::Color3B arg0; + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } - bool ret = cobj->initWithFile(arg0); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + cobj->setFontColor(arg0); + args.rval().setUndefined(); return true; } } while(0); - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_initWithFile : wrong number of arguments"); - return false; -} -bool js_cocos2dx_ui_Scale9Sprite_getInsetTop(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getInsetTop : Invalid Native Object"); - if (argc == 0) { - double ret = cobj->getInsetTop(); - jsval jsret = JSVAL_NULL; - jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getInsetTop : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setFontColor : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_Scale9Sprite_setInsetLeft(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_setPlaceholderFont(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetLeft : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetLeft : Error processing arguments"); - cobj->setInsetLeft(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFont : Invalid Native Object"); + if (argc == 2) { + const char* arg0; + int arg1; + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFont : Error processing arguments"); + cobj->setPlaceholderFont(arg0, arg1); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setInsetLeft : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setPlaceholderFont : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_initWithSizeAndBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; - cocos2d::ui::Scale9Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx); + cocos2d::ui::EditBox* cobj = NULL; + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrame : Invalid Native Object"); + cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_initWithSizeAndBackgroundSprite : Invalid Native Object"); do { - if (argc == 1) { - cocos2d::SpriteFrame* arg0; + if (argc == 2) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::ui::Scale9Sprite* arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + arg1 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } - bool ret = cobj->initWithSpriteFrame(arg0); + bool ret = cobj->initWithSizeAndBackgroundSprite(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); do { if (argc == 2) { - cocos2d::SpriteFrame* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } - cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } - bool ret = cobj->initWithSpriteFrame(arg0, arg1); + bool ret = cobj->initWithSizeAndBackgroundSprite(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrame : wrong number of arguments"); + do { + if (argc == 3) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cocos2d::ui::Widget::TextureResType arg2; + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + if (!ok) { ok = true; break; } + bool ret = cobj->initWithSizeAndBackgroundSprite(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_initWithSizeAndBackgroundSprite : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_Scale9Sprite_getPreferredSize(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_setPlaceHolder(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getPreferredSize : Invalid Native Object"); - if (argc == 0) { - cocos2d::Size ret = cobj->getPreferredSize(); - jsval jsret = JSVAL_NULL; - jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setPlaceHolder : Invalid Native Object"); + if (argc == 1) { + const char* arg0; + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setPlaceHolder : Error processing arguments"); + cobj->setPlaceHolder(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getPreferredSize : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setPlaceHolder : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_Scale9Sprite_setCapInsets(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_setReturnType(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setCapInsets : Invalid Native Object"); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setReturnType : Invalid Native Object"); if (argc == 1) { - cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setCapInsets : Error processing arguments"); - cobj->setCapInsets(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::EditBox::KeyboardReturnType arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setReturnType : Error processing arguments"); + cobj->setReturnType(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setCapInsets : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setReturnType : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_Scale9Sprite_isFlippedY(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_setInputFlag(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_isFlippedY : Invalid Native Object"); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setInputFlag : Invalid Native Object"); + if (argc == 1) { + cocos2d::ui::EditBox::InputFlag arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setInputFlag : Error processing arguments"); + cobj->setInputFlag(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setInputFlag : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_EditBox_getMaxLength(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_getMaxLength : Invalid Native Object"); if (argc == 0) { - bool ret = cobj->isFlippedY(); + int ret = cobj->getMaxLength(); jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_isFlippedY : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_getMaxLength : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_Scale9Sprite_getInsetLeft(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_setMaxLength(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getInsetLeft : Invalid Native Object"); - if (argc == 0) { - double ret = cobj->getInsetLeft(); - jsval jsret = JSVAL_NULL; - jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setMaxLength : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setMaxLength : Error processing arguments"); + cobj->setMaxLength(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_getInsetLeft : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setMaxLength : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_Scale9Sprite_setInsetRight(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_setFont(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetRight : Invalid Native Object"); - if (argc == 1) { - double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setInsetRight : Error processing arguments"); - cobj->setInsetRight(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setFont : Invalid Native Object"); + if (argc == 2) { + const char* arg0; + int arg1; + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setFont : Error processing arguments"); + cobj->setFont(arg0, arg1); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_setInsetRight : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setFont : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_ui_Scale9Sprite_create(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; do { - if (argc == 3) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + if (argc == 2) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } - cocos2d::Rect arg2; - ok &= jsval_to_ccrect(cx, argv[2], &arg2); + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::create(arg0, arg1, arg2); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - - do { - if (argc == 0) { - cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::create(); + cocos2d::ui::EditBox* ret = cocos2d::ui::EditBox::create(arg0, arg1); jsval jsret = JSVAL_NULL; do { if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::EditBox*)ret); jsret = OBJECT_TO_JSVAL(jsProxy->obj); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); - do { - if (argc == 2) { - cocos2d::Rect arg0; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); + if (argc == 3) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::create(arg0, arg1); + cocos2d::ui::Widget::TextureResType arg2; + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + if (!ok) { ok = true; break; } + cocos2d::ui::EditBox* ret = cocos2d::ui::EditBox::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; do { if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::EditBox*)ret); jsret = OBJECT_TO_JSVAL(jsProxy->obj); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); do { if (argc == 2) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::create(arg0, arg1); - jsval jsret = JSVAL_NULL; + cocos2d::ui::Scale9Sprite* arg1; do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } + if (!args.get(1).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(1).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg1 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - - do { - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::create(arg0); + cocos2d::ui::EditBox* ret = cocos2d::ui::EditBox::create(arg0, arg1); jsval jsret = JSVAL_NULL; do { if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::EditBox*)ret); jsret = OBJECT_TO_JSVAL(jsProxy->obj); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_create : wrong number of arguments"); - return false; -} -bool js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrameName(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - do { - if (argc == 2) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + if (argc == 3) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } - cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + cocos2d::ui::Scale9Sprite* arg1; + do { + if (!args.get(1).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(1).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg1 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); + } while (0); if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::createWithSpriteFrameName(arg0, arg1); - jsval jsret = JSVAL_NULL; + cocos2d::ui::Scale9Sprite* arg2; do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } + if (!args.get(2).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(2).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg2 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - - do { - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::createWithSpriteFrameName(arg0); + cocos2d::ui::EditBox* ret = cocos2d::ui::EditBox::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; do { if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::EditBox*)ret); jsret = OBJECT_TO_JSVAL(jsProxy->obj); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrameName : wrong number of arguments"); - return false; -} -bool js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - do { - if (argc == 2) { - cocos2d::SpriteFrame* arg0; + if (argc == 4) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::ui::Scale9Sprite* arg1; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(1).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + arg1 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } - cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); - if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::createWithSpriteFrame(arg0, arg1); - jsval jsret = JSVAL_NULL; + cocos2d::ui::Scale9Sprite* arg2; do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } + if (!args.get(2).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(2).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg2 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - - do { - if (argc == 1) { - cocos2d::SpriteFrame* arg0; + if (!ok) { ok = true; break; } + cocos2d::ui::Scale9Sprite* arg3; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(3).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(3).toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::SpriteFrame*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + arg3 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); } while (0); if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::createWithSpriteFrame(arg0); + cocos2d::ui::EditBox* ret = cocos2d::ui::EditBox::create(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; do { if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::Scale9Sprite*)ret); + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::EditBox*)ret); jsret = OBJECT_TO_JSVAL(jsProxy->obj); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); - JS_ReportError(cx, "js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrame : wrong number of arguments"); + JS_ReportError(cx, "js_cocos2dx_ui_EditBox_create : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_Scale9Sprite_constructor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_EditBox_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - cocos2d::ui::Scale9Sprite* cobj = new (std::nothrow) cocos2d::ui::Scale9Sprite(); + cocos2d::ui::EditBox* cobj = new (std::nothrow) cocos2d::ui::EditBox(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); if (_ccobj) { _ccobj->autorelease(); } - TypeTest t; + TypeTest t; js_type_class_t *typeClass = nullptr; std::string typeName = t.s_name(); auto typeMapIter = _js_global_type_map.find(typeName); CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Scale9Sprite"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::EditBox"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } -extern JSObject *jsb_cocos2d_Node_prototype; +extern JSObject *jsb_cocos2d_ui_Widget_prototype; -void js_cocos2d_ui_Scale9Sprite_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (Scale9Sprite)", obj); +void js_cocos2d_ui_EditBox_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (EditBox)", obj); } -static bool js_cocos2d_ui_Scale9Sprite_ctor(JSContext *cx, uint32_t argc, jsval *vp) +static bool js_cocos2d_ui_EditBox_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); - cocos2d::ui::Scale9Sprite *nobj = new (std::nothrow) cocos2d::ui::Scale9Sprite(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::ui::EditBox *nobj = new (std::nothrow) cocos2d::ui::EditBox(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Scale9Sprite"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::EditBox"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_Scale9Sprite(JSContext *cx, JSObject *global) { - jsb_cocos2d_ui_Scale9Sprite_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_ui_Scale9Sprite_class->name = "Scale9Sprite"; - jsb_cocos2d_ui_Scale9Sprite_class->addProperty = JS_PropertyStub; - jsb_cocos2d_ui_Scale9Sprite_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_ui_Scale9Sprite_class->getProperty = JS_PropertyStub; - jsb_cocos2d_ui_Scale9Sprite_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_ui_Scale9Sprite_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_ui_Scale9Sprite_class->resolve = JS_ResolveStub; - jsb_cocos2d_ui_Scale9Sprite_class->convert = JS_ConvertStub; - jsb_cocos2d_ui_Scale9Sprite_class->finalize = js_cocos2d_ui_Scale9Sprite_finalize; - jsb_cocos2d_ui_Scale9Sprite_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); - - static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} - }; - - static JSFunctionSpec funcs[] = { - JS_FN("disableCascadeColor", js_cocos2dx_ui_Scale9Sprite_disableCascadeColor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("updateWithSprite", js_cocos2dx_ui_Scale9Sprite_updateWithSprite, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("isFlippedX", js_cocos2dx_ui_Scale9Sprite_isFlippedX, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setFlippedY", js_cocos2dx_ui_Scale9Sprite_setFlippedY, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setFlippedX", js_cocos2dx_ui_Scale9Sprite_setFlippedX, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setScale9Enabled", js_cocos2dx_ui_Scale9Sprite_setScale9Enabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("disableCascadeOpacity", js_cocos2dx_ui_Scale9Sprite_disableCascadeOpacity, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setInsetBottom", js_cocos2dx_ui_Scale9Sprite_setInsetBottom, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("initWithSpriteFrameName", js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrameName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getSprite", js_cocos2dx_ui_Scale9Sprite_getSprite, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setInsetTop", js_cocos2dx_ui_Scale9Sprite_setInsetTop, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("init", js_cocos2dx_ui_Scale9Sprite_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setPreferredSize", js_cocos2dx_ui_Scale9Sprite_setPreferredSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getInsetRight", js_cocos2dx_ui_Scale9Sprite_getInsetRight, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setSpriteFrame", js_cocos2dx_ui_Scale9Sprite_setSpriteFrame, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getInsetBottom", js_cocos2dx_ui_Scale9Sprite_getInsetBottom, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("resizableSpriteWithCapInsets", js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("isScale9Enabled", js_cocos2dx_ui_Scale9Sprite_isScale9Enabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getCapInsets", js_cocos2dx_ui_Scale9Sprite_getCapInsets, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getOriginalSize", js_cocos2dx_ui_Scale9Sprite_getOriginalSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("initWithFile", js_cocos2dx_ui_Scale9Sprite_initWithFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getInsetTop", js_cocos2dx_ui_Scale9Sprite_getInsetTop, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setInsetLeft", js_cocos2dx_ui_Scale9Sprite_setInsetLeft, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("initWithSpriteFrame", js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrame, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getPreferredSize", js_cocos2dx_ui_Scale9Sprite_getPreferredSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setCapInsets", js_cocos2dx_ui_Scale9Sprite_setCapInsets, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("isFlippedY", js_cocos2dx_ui_Scale9Sprite_isFlippedY, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getInsetLeft", js_cocos2dx_ui_Scale9Sprite_getInsetLeft, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setInsetRight", js_cocos2dx_ui_Scale9Sprite_setInsetRight, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("ctor", js_cocos2d_ui_Scale9Sprite_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), +void js_register_cocos2dx_ui_EditBox(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_EditBox_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_EditBox_class->name = "EditBox"; + jsb_cocos2d_ui_EditBox_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_EditBox_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_EditBox_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_EditBox_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_EditBox_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_EditBox_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_EditBox_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_EditBox_class->finalize = js_cocos2d_ui_EditBox_finalize; + jsb_cocos2d_ui_EditBox_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("getString", js_cocos2dx_ui_EditBox_getText, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setFontSize", js_cocos2dx_ui_EditBox_setFontSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPlaceholderFontName", js_cocos2dx_ui_EditBox_setPlaceholderFontName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getPlaceHolder", js_cocos2dx_ui_EditBox_getPlaceHolder, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setFontName", js_cocos2dx_ui_EditBox_setFontName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setString", js_cocos2dx_ui_EditBox_setText, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPlaceholderFontSize", js_cocos2dx_ui_EditBox_setPlaceholderFontSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setInputMode", js_cocos2dx_ui_EditBox_setInputMode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPlaceholderFontColor", js_cocos2dx_ui_EditBox_setPlaceholderFontColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setFontColor", js_cocos2dx_ui_EditBox_setFontColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPlaceholderFont", js_cocos2dx_ui_EditBox_setPlaceholderFont, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithSizeAndBackgroundSprite", js_cocos2dx_ui_EditBox_initWithSizeAndBackgroundSprite, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPlaceHolder", js_cocos2dx_ui_EditBox_setPlaceHolder, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setReturnType", js_cocos2dx_ui_EditBox_setReturnType, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setInputFlag", js_cocos2dx_ui_EditBox_setInputFlag, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getMaxLength", js_cocos2dx_ui_EditBox_getMaxLength, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setMaxLength", js_cocos2dx_ui_EditBox_setMaxLength, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setFont", js_cocos2dx_ui_EditBox_setFont, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_ui_EditBox_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_ui_Scale9Sprite_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("createWithSpriteFrameName", js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrameName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("createWithSpriteFrame", js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrame, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("create", js_cocos2dx_ui_EditBox_create, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; - jsb_cocos2d_ui_Scale9Sprite_prototype = JS_InitClass( + jsb_cocos2d_ui_EditBox_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, - jsb_cocos2d_ui_Scale9Sprite_class, - js_cocos2dx_ui_Scale9Sprite_constructor, 0, // constructor + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), + jsb_cocos2d_ui_EditBox_class, + js_cocos2dx_ui_EditBox_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -12536,705 +14560,1143 @@ void js_register_cocos2dx_ui_Scale9Sprite(JSContext *cx, JSObject *global) { // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "Scale9Sprite", JSPROP_ENUMERATE | JSPROP_READONLY, &found); +// JS_SetPropertyAttributes(cx, global, "EditBox", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; + TypeTest t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_ui_Scale9Sprite_class; - p->proto = jsb_cocos2d_ui_Scale9Sprite_prototype; - p->parentProto = jsb_cocos2d_Node_prototype; + p->jsclass = jsb_cocos2d_ui_EditBox_class; + p->proto = jsb_cocos2d_ui_EditBox_prototype; + p->parentProto = jsb_cocos2d_ui_Widget_prototype; _js_global_type_map.insert(std::make_pair(typeName, p)); } } -JSClass *jsb_cocos2d_ui_EditBox_class; -JSObject *jsb_cocos2d_ui_EditBox_prototype; +JSClass *jsb_cocos2d_ui_LayoutComponent_class; +JSObject *jsb_cocos2d_ui_LayoutComponent_prototype; + +bool js_cocos2dx_ui_LayoutComponent_setStretchWidthEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setStretchWidthEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setStretchWidthEnabled : Error processing arguments"); + cobj->setStretchWidthEnabled(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setStretchWidthEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_setPercentWidth(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentWidth : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentWidth : Error processing arguments"); + cobj->setPercentWidth(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setPercentWidth : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_getAnchorPosition(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getAnchorPosition : Invalid Native Object"); + if (argc == 0) { + const cocos2d::Point& ret = cobj->getAnchorPosition(); + jsval jsret = JSVAL_NULL; + jsret = ccpoint_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getAnchorPosition : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_setPositionPercentXEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setPositionPercentXEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPositionPercentXEnabled : Error processing arguments"); + cobj->setPositionPercentXEnabled(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setPositionPercentXEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_setStretchHeightEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setStretchHeightEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setStretchHeightEnabled : Error processing arguments"); + cobj->setStretchHeightEnabled(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setStretchHeightEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_setActiveEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setActiveEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setActiveEnabled : Error processing arguments"); + cobj->setActiveEnabled(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setActiveEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_getRightMargin(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getRightMargin : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getRightMargin(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getRightMargin : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_getSize(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getSize : Invalid Native Object"); + if (argc == 0) { + const cocos2d::Size& ret = cobj->getSize(); + jsval jsret = JSVAL_NULL; + jsret = ccsize_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getSize : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_setAnchorPosition(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setAnchorPosition : Invalid Native Object"); + if (argc == 1) { + cocos2d::Point arg0; + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setAnchorPosition : Error processing arguments"); + cobj->setAnchorPosition(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setAnchorPosition : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_refreshLayout(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_refreshLayout : Invalid Native Object"); + if (argc == 0) { + cobj->refreshLayout(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_refreshLayout : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_isPercentWidthEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_isPercentWidthEnabled : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isPercentWidthEnabled(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_isPercentWidthEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_setVerticalEdge(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setVerticalEdge : Invalid Native Object"); + if (argc == 1) { + cocos2d::ui::LayoutComponent::VerticalEdge arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setVerticalEdge : Error processing arguments"); + cobj->setVerticalEdge(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setVerticalEdge : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_getTopMargin(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getTopMargin : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getTopMargin(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getTopMargin : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_setSizeWidth(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setSizeWidth : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setSizeWidth : Error processing arguments"); + cobj->setSizeWidth(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setSizeWidth : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_getPercentContentSize(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getPercentContentSize : Invalid Native Object"); + if (argc == 0) { + cocos2d::Vec2 ret = cobj->getPercentContentSize(); + jsval jsret = JSVAL_NULL; + jsret = vector2_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getPercentContentSize : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_getVerticalEdge(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getVerticalEdge : Invalid Native Object"); + if (argc == 0) { + int ret = (int)cobj->getVerticalEdge(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getVerticalEdge : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_setPercentWidthEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentWidthEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentWidthEnabled : Error processing arguments"); + cobj->setPercentWidthEnabled(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setPercentWidthEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_isStretchWidthEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_isStretchWidthEnabled : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isStretchWidthEnabled(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_isStretchWidthEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_setLeftMargin(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setLeftMargin : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setLeftMargin : Error processing arguments"); + cobj->setLeftMargin(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setLeftMargin : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_getSizeWidth(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getSizeWidth : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getSizeWidth(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getSizeWidth : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_setPositionPercentYEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setPositionPercentYEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPositionPercentYEnabled : Error processing arguments"); + cobj->setPositionPercentYEnabled(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setPositionPercentYEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_getSizeHeight(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getSizeHeight : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getSizeHeight(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getSizeHeight : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_getPositionPercentY(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getPositionPercentY : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getPositionPercentY(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } -bool js_cocos2dx_ui_EditBox_getText(JSContext *cx, uint32_t argc, jsval *vp) + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getPositionPercentY : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_getPositionPercentX(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_getText : Invalid Native Object"); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getPositionPercentX : Invalid Native Object"); if (argc == 0) { - const char* ret = cobj->getText(); + double ret = cobj->getPositionPercentX(); jsval jsret = JSVAL_NULL; - jsret = c_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_getText : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getPositionPercentX : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_EditBox_setFontSize(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_setTopMargin(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setFontSize : Invalid Native Object"); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setTopMargin : Invalid Native Object"); if (argc == 1) { - int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setFontSize : Error processing arguments"); - cobj->setFontSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setTopMargin : Error processing arguments"); + cobj->setTopMargin(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setFontSize : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setTopMargin : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_EditBox_setPlaceholderFontName(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_getPercentHeight(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFontName : Invalid Native Object"); - if (argc == 1) { - const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFontName : Error processing arguments"); - cobj->setPlaceholderFontName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getPercentHeight : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getPercentHeight(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setPlaceholderFontName : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getPercentHeight : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_EditBox_getPlaceHolder(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_getUsingPercentContentSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_getPlaceHolder : Invalid Native Object"); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getUsingPercentContentSize : Invalid Native Object"); if (argc == 0) { - const char* ret = cobj->getPlaceHolder(); + bool ret = cobj->getUsingPercentContentSize(); jsval jsret = JSVAL_NULL; - jsret = c_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_getPlaceHolder : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getUsingPercentContentSize : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_EditBox_setFontName(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_setPositionPercentY(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setFontName : Invalid Native Object"); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setPositionPercentY : Invalid Native Object"); if (argc == 1) { - const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setFontName : Error processing arguments"); - cobj->setFontName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPositionPercentY : Error processing arguments"); + cobj->setPositionPercentY(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setFontName : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setPositionPercentY : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_EditBox_setText(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_setPositionPercentX(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setText : Invalid Native Object"); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setPositionPercentX : Invalid Native Object"); if (argc == 1) { - const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setText : Error processing arguments"); - cobj->setText(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPositionPercentX : Error processing arguments"); + cobj->setPositionPercentX(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setText : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setPositionPercentX : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_EditBox_setPlaceholderFontSize(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_setRightMargin(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFontSize : Invalid Native Object"); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setRightMargin : Invalid Native Object"); if (argc == 1) { - int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFontSize : Error processing arguments"); - cobj->setPlaceholderFontSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setRightMargin : Error processing arguments"); + cobj->setRightMargin(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setPlaceholderFontSize : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setRightMargin : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_EditBox_setInputMode(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_isPositionPercentYEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_isPositionPercentYEnabled : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isPositionPercentYEnabled(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_isPositionPercentYEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_setPercentHeight(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setInputMode : Invalid Native Object"); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentHeight : Invalid Native Object"); if (argc == 1) { - cocos2d::ui::EditBox::InputMode arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setInputMode : Error processing arguments"); - cobj->setInputMode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentHeight : Error processing arguments"); + cobj->setPercentHeight(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setInputMode : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setPercentHeight : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_EditBox_setPlaceholderFontColor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_setPercentOnlyEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFontColor : Invalid Native Object"); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentOnlyEnabled : Invalid Native Object"); if (argc == 1) { - cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFontColor : Error processing arguments"); - cobj->setPlaceholderFontColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentOnlyEnabled : Error processing arguments"); + cobj->setPercentOnlyEnabled(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setPlaceholderFontColor : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setPercentOnlyEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_EditBox_setFontColor(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_setHorizontalEdge(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setFontColor : Invalid Native Object"); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setHorizontalEdge : Invalid Native Object"); if (argc == 1) { - cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setFontColor : Error processing arguments"); - cobj->setFontColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::LayoutComponent::HorizontalEdge arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setHorizontalEdge : Error processing arguments"); + cobj->setHorizontalEdge(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setFontColor : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setHorizontalEdge : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_EditBox_setPlaceholderFont(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_setPosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFont : Invalid Native Object"); - if (argc == 2) { - const char* arg0; - int arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setPlaceholderFont : Error processing arguments"); - cobj->setPlaceholderFont(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setPosition : Invalid Native Object"); + if (argc == 1) { + cocos2d::Point arg0; + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPosition : Error processing arguments"); + cobj->setPosition(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setPlaceholderFont : wrong number of arguments: %d, was expecting %d", argc, 2); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setPosition : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_EditBox_initWithSizeAndBackgroundSprite(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_setUsingPercentContentSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setUsingPercentContentSize : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setUsingPercentContentSize : Error processing arguments"); + cobj->setUsingPercentContentSize(arg0); + args.rval().setUndefined(); + return true; + } - JSObject *obj = NULL; - cocos2d::ui::EditBox* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setUsingPercentContentSize : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_getLeftMargin(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_initWithSizeAndBackgroundSprite : Invalid Native Object"); - do { - if (argc == 2) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* arg1; - do { - if (!argv[1].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg1 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - bool ret = cobj->initWithSizeAndBackgroundSprite(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while(0); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getLeftMargin : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getLeftMargin(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } - do { - if (argc == 2) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); - if (!ok) { ok = true; break; } - bool ret = cobj->initWithSizeAndBackgroundSprite(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while(0); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getLeftMargin : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_getPosition(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getPosition : Invalid Native Object"); + if (argc == 0) { + const cocos2d::Point& ret = cobj->getPosition(); + jsval jsret = JSVAL_NULL; + jsret = ccpoint_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } - do { - if (argc == 3) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); - if (!ok) { ok = true; break; } - cocos2d::ui::Widget::TextureResType arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - if (!ok) { ok = true; break; } - bool ret = cobj->initWithSizeAndBackgroundSprite(arg0, arg1, arg2); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while(0); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getPosition : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_setSizeHeight(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setSizeHeight : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setSizeHeight : Error processing arguments"); + cobj->setSizeHeight(arg0); + args.rval().setUndefined(); + return true; + } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_initWithSizeAndBackgroundSprite : wrong number of arguments"); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setSizeHeight : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_EditBox_setPlaceHolder(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_isPositionPercentXEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_isPositionPercentXEnabled : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isPositionPercentXEnabled(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_isPositionPercentXEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_getBottomMargin(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getBottomMargin : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getBottomMargin(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getBottomMargin : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_setPercentHeightEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setPlaceHolder : Invalid Native Object"); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentHeightEnabled : Invalid Native Object"); if (argc == 1) { - const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setPlaceHolder : Error processing arguments"); - cobj->setPlaceHolder(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentHeightEnabled : Error processing arguments"); + cobj->setPercentHeightEnabled(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setPlaceHolder : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setPercentHeightEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_EditBox_setReturnType(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_setPercentContentSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setReturnType : Invalid Native Object"); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentContentSize : Invalid Native Object"); if (argc == 1) { - cocos2d::ui::EditBox::KeyboardReturnType arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setReturnType : Error processing arguments"); - cobj->setReturnType(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::Vec2 arg0; + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentContentSize : Error processing arguments"); + cobj->setPercentContentSize(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setReturnType : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setPercentContentSize : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_isPercentHeightEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_isPercentHeightEnabled : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isPercentHeightEnabled(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_isPercentHeightEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_LayoutComponent_getPercentWidth(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getPercentWidth : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getPercentWidth(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getPercentWidth : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_EditBox_setInputFlag(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_getHorizontalEdge(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setInputFlag : Invalid Native Object"); - if (argc == 1) { - cocos2d::ui::EditBox::InputFlag arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setInputFlag : Error processing arguments"); - cobj->setInputFlag(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getHorizontalEdge : Invalid Native Object"); + if (argc == 0) { + int ret = (int)cobj->getHorizontalEdge(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setInputFlag : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_getHorizontalEdge : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_EditBox_getMaxLength(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_isStretchHeightEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_getMaxLength : Invalid Native Object"); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_isStretchHeightEnabled : Invalid Native Object"); if (argc == 0) { - int ret = cobj->getMaxLength(); + bool ret = cobj->isStretchHeightEnabled(); jsval jsret = JSVAL_NULL; - jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_getMaxLength : wrong number of arguments: %d, was expecting %d", argc, 0); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_isStretchHeightEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_ui_EditBox_setMaxLength(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_setBottomMargin(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setMaxLength : Invalid Native Object"); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setBottomMargin : Invalid Native Object"); if (argc == 1) { - int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setMaxLength : Error processing arguments"); - cobj->setMaxLength(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setBottomMargin : Error processing arguments"); + cobj->setBottomMargin(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setMaxLength : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setBottomMargin : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_EditBox_setFont(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_setSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_setFont : Invalid Native Object"); - if (argc == 2) { - const char* arg0; - int arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_EditBox_setFont : Error processing arguments"); - cobj->setFont(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + cocos2d::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_setSize : Invalid Native Object"); + if (argc == 1) { + cocos2d::Size arg0; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setSize : Error processing arguments"); + cobj->setSize(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_setFont : wrong number of arguments: %d, was expecting %d", argc, 2); + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_setSize : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_ui_EditBox_create(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_ui_LayoutComponent_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - - do { - if (argc == 2) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); - if (!ok) { ok = true; break; } - cocos2d::ui::EditBox* ret = cocos2d::ui::EditBox::create(arg0, arg1); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::EditBox*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - do { - if (argc == 3) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); - if (!ok) { ok = true; break; } - cocos2d::ui::Widget::TextureResType arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - if (!ok) { ok = true; break; } - cocos2d::ui::EditBox* ret = cocos2d::ui::EditBox::create(arg0, arg1, arg2); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::EditBox*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - - do { - if (argc == 2) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* arg1; - do { - if (!argv[1].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg1 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cocos2d::ui::EditBox* ret = cocos2d::ui::EditBox::create(arg0, arg1); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::EditBox*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; - } - } while (0); - do { - if (argc == 3) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* arg1; - do { - if (!argv[1].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg1 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* arg2; - do { - if (!argv[2].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg2 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cocos2d::ui::EditBox* ret = cocos2d::ui::EditBox::create(arg0, arg1, arg2); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::EditBox*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (argc == 0) { + cocos2d::ui::LayoutComponent* ret = cocos2d::ui::LayoutComponent::create(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::LayoutComponent*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; } } while (0); - do { - if (argc == 4) { - cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); - if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* arg1; - do { - if (!argv[1].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg1 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* arg2; - do { - if (!argv[2].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg2 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cocos2d::ui::Scale9Sprite* arg3; - do { - if (!argv[3].isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[3]); - jsProxy = jsb_get_js_proxy(tmpObj); - arg3 = (cocos2d::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); - } while (0); - if (!ok) { ok = true; break; } - cocos2d::ui::EditBox* ret = cocos2d::ui::EditBox::create(arg0, arg1, arg2, arg3); - jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::EditBox*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); - JS_SET_RVAL(cx, vp, jsret); - return true; + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_create : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_ui_LayoutComponent_bindLayoutComponent(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + cocos2d::Node* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_bindLayoutComponent : Error processing arguments"); + cocos2d::ui::LayoutComponent* ret = cocos2d::ui::LayoutComponent::bindLayoutComponent(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::ui::LayoutComponent*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; } } while (0); - JS_ReportError(cx, "js_cocos2dx_ui_EditBox_create : wrong number of arguments"); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_ui_LayoutComponent_bindLayoutComponent : wrong number of arguments"); return false; } -bool js_cocos2dx_ui_EditBox_constructor(JSContext *cx, uint32_t argc, jsval *vp) + +bool js_cocos2dx_ui_LayoutComponent_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - cocos2d::ui::EditBox* cobj = new (std::nothrow) cocos2d::ui::EditBox(); + cocos2d::ui::LayoutComponent* cobj = new (std::nothrow) cocos2d::ui::LayoutComponent(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); if (_ccobj) { _ccobj->autorelease(); } - TypeTest t; + TypeTest t; js_type_class_t *typeClass = nullptr; std::string typeName = t.s_name(); auto typeMapIter = _js_global_type_map.find(typeName); CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::EditBox"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::LayoutComponent"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } -extern JSObject *jsb_cocos2d_ui_Widget_prototype; +extern JSObject *jsb_cocos2d_Component_prototype; -void js_cocos2d_ui_EditBox_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (EditBox)", obj); +void js_cocos2d_ui_LayoutComponent_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (LayoutComponent)", obj); } -static bool js_cocos2d_ui_EditBox_ctor(JSContext *cx, uint32_t argc, jsval *vp) +static bool js_cocos2d_ui_LayoutComponent_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); - cocos2d::ui::EditBox *nobj = new (std::nothrow) cocos2d::ui::EditBox(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + cocos2d::ui::LayoutComponent *nobj = new (std::nothrow) cocos2d::ui::LayoutComponent(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::EditBox"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::LayoutComponent"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_EditBox(JSContext *cx, JSObject *global) { - jsb_cocos2d_ui_EditBox_class = (JSClass *)calloc(1, sizeof(JSClass)); - jsb_cocos2d_ui_EditBox_class->name = "EditBox"; - jsb_cocos2d_ui_EditBox_class->addProperty = JS_PropertyStub; - jsb_cocos2d_ui_EditBox_class->delProperty = JS_DeletePropertyStub; - jsb_cocos2d_ui_EditBox_class->getProperty = JS_PropertyStub; - jsb_cocos2d_ui_EditBox_class->setProperty = JS_StrictPropertyStub; - jsb_cocos2d_ui_EditBox_class->enumerate = JS_EnumerateStub; - jsb_cocos2d_ui_EditBox_class->resolve = JS_ResolveStub; - jsb_cocos2d_ui_EditBox_class->convert = JS_ConvertStub; - jsb_cocos2d_ui_EditBox_class->finalize = js_cocos2d_ui_EditBox_finalize; - jsb_cocos2d_ui_EditBox_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); +void js_register_cocos2dx_ui_LayoutComponent(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_ui_LayoutComponent_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_ui_LayoutComponent_class->name = "LayoutComponent"; + jsb_cocos2d_ui_LayoutComponent_class->addProperty = JS_PropertyStub; + jsb_cocos2d_ui_LayoutComponent_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_ui_LayoutComponent_class->getProperty = JS_PropertyStub; + jsb_cocos2d_ui_LayoutComponent_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_ui_LayoutComponent_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_ui_LayoutComponent_class->resolve = JS_ResolveStub; + jsb_cocos2d_ui_LayoutComponent_class->convert = JS_ConvertStub; + jsb_cocos2d_ui_LayoutComponent_class->finalize = js_cocos2d_ui_LayoutComponent_finalize; + jsb_cocos2d_ui_LayoutComponent_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { - JS_FN("getString", js_cocos2dx_ui_EditBox_getText, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setFontSize", js_cocos2dx_ui_EditBox_setFontSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setPlaceholderFontName", js_cocos2dx_ui_EditBox_setPlaceholderFontName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getPlaceHolder", js_cocos2dx_ui_EditBox_getPlaceHolder, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setFontName", js_cocos2dx_ui_EditBox_setFontName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setString", js_cocos2dx_ui_EditBox_setText, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setPlaceholderFontSize", js_cocos2dx_ui_EditBox_setPlaceholderFontSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setInputMode", js_cocos2dx_ui_EditBox_setInputMode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setPlaceholderFontColor", js_cocos2dx_ui_EditBox_setPlaceholderFontColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setFontColor", js_cocos2dx_ui_EditBox_setFontColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setPlaceholderFont", js_cocos2dx_ui_EditBox_setPlaceholderFont, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("initWithSizeAndBackgroundSprite", js_cocos2dx_ui_EditBox_initWithSizeAndBackgroundSprite, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setPlaceHolder", js_cocos2dx_ui_EditBox_setPlaceHolder, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setReturnType", js_cocos2dx_ui_EditBox_setReturnType, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setInputFlag", js_cocos2dx_ui_EditBox_setInputFlag, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getMaxLength", js_cocos2dx_ui_EditBox_getMaxLength, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setMaxLength", js_cocos2dx_ui_EditBox_setMaxLength, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setFont", js_cocos2dx_ui_EditBox_setFont, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("ctor", js_cocos2d_ui_EditBox_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setStretchWidthEnabled", js_cocos2dx_ui_LayoutComponent_setStretchWidthEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPercentWidth", js_cocos2dx_ui_LayoutComponent_setPercentWidth, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getAnchorPosition", js_cocos2dx_ui_LayoutComponent_getAnchorPosition, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPositionPercentXEnabled", js_cocos2dx_ui_LayoutComponent_setPositionPercentXEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setStretchHeightEnabled", js_cocos2dx_ui_LayoutComponent_setStretchHeightEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setActiveEnabled", js_cocos2dx_ui_LayoutComponent_setActiveEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getRightMargin", js_cocos2dx_ui_LayoutComponent_getRightMargin, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getSize", js_cocos2dx_ui_LayoutComponent_getSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setAnchorPosition", js_cocos2dx_ui_LayoutComponent_setAnchorPosition, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("refreshLayout", js_cocos2dx_ui_LayoutComponent_refreshLayout, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isPercentWidthEnabled", js_cocos2dx_ui_LayoutComponent_isPercentWidthEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setVerticalEdge", js_cocos2dx_ui_LayoutComponent_setVerticalEdge, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getTopMargin", js_cocos2dx_ui_LayoutComponent_getTopMargin, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setSizeWidth", js_cocos2dx_ui_LayoutComponent_setSizeWidth, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getPercentContentSize", js_cocos2dx_ui_LayoutComponent_getPercentContentSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getVerticalEdge", js_cocos2dx_ui_LayoutComponent_getVerticalEdge, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPercentWidthEnabled", js_cocos2dx_ui_LayoutComponent_setPercentWidthEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isStretchWidthEnabled", js_cocos2dx_ui_LayoutComponent_isStretchWidthEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setLeftMargin", js_cocos2dx_ui_LayoutComponent_setLeftMargin, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getSizeWidth", js_cocos2dx_ui_LayoutComponent_getSizeWidth, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPositionPercentYEnabled", js_cocos2dx_ui_LayoutComponent_setPositionPercentYEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getSizeHeight", js_cocos2dx_ui_LayoutComponent_getSizeHeight, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getPositionPercentY", js_cocos2dx_ui_LayoutComponent_getPositionPercentY, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getPositionPercentX", js_cocos2dx_ui_LayoutComponent_getPositionPercentX, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setTopMargin", js_cocos2dx_ui_LayoutComponent_setTopMargin, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getPercentHeight", js_cocos2dx_ui_LayoutComponent_getPercentHeight, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getUsingPercentContentSize", js_cocos2dx_ui_LayoutComponent_getUsingPercentContentSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPositionPercentY", js_cocos2dx_ui_LayoutComponent_setPositionPercentY, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPositionPercentX", js_cocos2dx_ui_LayoutComponent_setPositionPercentX, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setRightMargin", js_cocos2dx_ui_LayoutComponent_setRightMargin, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isPositionPercentYEnabled", js_cocos2dx_ui_LayoutComponent_isPositionPercentYEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPercentHeight", js_cocos2dx_ui_LayoutComponent_setPercentHeight, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPercentOnlyEnabled", js_cocos2dx_ui_LayoutComponent_setPercentOnlyEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setHorizontalEdge", js_cocos2dx_ui_LayoutComponent_setHorizontalEdge, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPosition", js_cocos2dx_ui_LayoutComponent_setPosition, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setUsingPercentContentSize", js_cocos2dx_ui_LayoutComponent_setUsingPercentContentSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getLeftMargin", js_cocos2dx_ui_LayoutComponent_getLeftMargin, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getPosition", js_cocos2dx_ui_LayoutComponent_getPosition, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setSizeHeight", js_cocos2dx_ui_LayoutComponent_setSizeHeight, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isPositionPercentXEnabled", js_cocos2dx_ui_LayoutComponent_isPositionPercentXEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getBottomMargin", js_cocos2dx_ui_LayoutComponent_getBottomMargin, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPercentHeightEnabled", js_cocos2dx_ui_LayoutComponent_setPercentHeightEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setPercentContentSize", js_cocos2dx_ui_LayoutComponent_setPercentContentSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isPercentHeightEnabled", js_cocos2dx_ui_LayoutComponent_isPercentHeightEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getPercentWidth", js_cocos2dx_ui_LayoutComponent_getPercentWidth, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getHorizontalEdge", js_cocos2dx_ui_LayoutComponent_getHorizontalEdge, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isStretchHeightEnabled", js_cocos2dx_ui_LayoutComponent_isStretchHeightEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setBottomMargin", js_cocos2dx_ui_LayoutComponent_setBottomMargin, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setSize", js_cocos2dx_ui_LayoutComponent_setSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("ctor", js_cocos2d_ui_LayoutComponent_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_ui_EditBox_create, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("create", js_cocos2dx_ui_LayoutComponent_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("bindLayoutComponent", js_cocos2dx_ui_LayoutComponent_bindLayoutComponent, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; - jsb_cocos2d_ui_EditBox_prototype = JS_InitClass( + jsb_cocos2d_ui_LayoutComponent_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Widget_prototype, - jsb_cocos2d_ui_EditBox_class, - js_cocos2dx_ui_EditBox_constructor, 0, // constructor + JS::RootedObject(cx, jsb_cocos2d_Component_prototype), + jsb_cocos2d_ui_LayoutComponent_class, + js_cocos2dx_ui_LayoutComponent_constructor, 0, // constructor properties, funcs, NULL, // no static properties @@ -13242,63 +15704,56 @@ void js_register_cocos2dx_ui_EditBox(JSContext *cx, JSObject *global) { // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "EditBox", JSPROP_ENUMERATE | JSPROP_READONLY, &found); +// JS_SetPropertyAttributes(cx, global, "LayoutComponent", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; + TypeTest t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_ui_EditBox_class; - p->proto = jsb_cocos2d_ui_EditBox_prototype; - p->parentProto = jsb_cocos2d_ui_Widget_prototype; + p->jsclass = jsb_cocos2d_ui_LayoutComponent_class; + p->proto = jsb_cocos2d_ui_LayoutComponent_prototype; + p->parentProto = jsb_cocos2d_Component_prototype; _js_global_type_map.insert(std::make_pair(typeName, p)); } } -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj) { - // first, try to get the ns - JS::RootedValue nsval(cx); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj) { + // Get the ns JS::RootedObject ns(cx); - JS_GetProperty(cx, obj, "ccui", &nsval); - if (nsval == JSVAL_VOID) { - ns = JS_NewObject(cx, NULL, NULL, NULL); - nsval = OBJECT_TO_JSVAL(ns); - JS_SetProperty(cx, obj, "ccui", nsval); - } else { - JS_ValueToObject(cx, nsval, &ns); - } - obj = ns; - - js_register_cocos2dx_ui_Widget(cx, obj); - js_register_cocos2dx_ui_Layout(cx, obj); - js_register_cocos2dx_ui_RelativeBox(cx, obj); - js_register_cocos2dx_ui_CheckBox(cx, obj); - js_register_cocos2dx_ui_TextAtlas(cx, obj); - js_register_cocos2dx_ui_TextBMFont(cx, obj); - js_register_cocos2dx_ui_LoadingBar(cx, obj); - js_register_cocos2dx_ui_TextField(cx, obj); - js_register_cocos2dx_ui_Scale9Sprite(cx, obj); - js_register_cocos2dx_ui_VBox(cx, obj); - js_register_cocos2dx_ui_RichElement(cx, obj); - js_register_cocos2dx_ui_RichElementCustomNode(cx, obj); - js_register_cocos2dx_ui_Slider(cx, obj); - js_register_cocos2dx_ui_ScrollView(cx, obj); - js_register_cocos2dx_ui_ListView(cx, obj); - js_register_cocos2dx_ui_Button(cx, obj); - js_register_cocos2dx_ui_LayoutParameter(cx, obj); - js_register_cocos2dx_ui_LinearLayoutParameter(cx, obj); - js_register_cocos2dx_ui_ImageView(cx, obj); - js_register_cocos2dx_ui_HBox(cx, obj); - js_register_cocos2dx_ui_RichElementText(cx, obj); - js_register_cocos2dx_ui_PageView(cx, obj); - js_register_cocos2dx_ui_Helper(cx, obj); - js_register_cocos2dx_ui_EditBox(cx, obj); - js_register_cocos2dx_ui_Text(cx, obj); - js_register_cocos2dx_ui_RichText(cx, obj); - js_register_cocos2dx_ui_RichElementImage(cx, obj); - js_register_cocos2dx_ui_RelativeLayoutParameter(cx, obj); + get_or_create_js_obj(cx, obj, "ccui", &ns); + + js_register_cocos2dx_ui_Widget(cx, ns); + js_register_cocos2dx_ui_Layout(cx, ns); + js_register_cocos2dx_ui_RelativeBox(cx, ns); + js_register_cocos2dx_ui_CheckBox(cx, ns); + js_register_cocos2dx_ui_TextAtlas(cx, ns); + js_register_cocos2dx_ui_TextBMFont(cx, ns); + js_register_cocos2dx_ui_LoadingBar(cx, ns); + js_register_cocos2dx_ui_TextField(cx, ns); + js_register_cocos2dx_ui_RichText(cx, ns); + js_register_cocos2dx_ui_Scale9Sprite(cx, ns); + js_register_cocos2dx_ui_VBox(cx, ns); + js_register_cocos2dx_ui_RichElement(cx, ns); + js_register_cocos2dx_ui_RichElementCustomNode(cx, ns); + js_register_cocos2dx_ui_Slider(cx, ns); + js_register_cocos2dx_ui_ScrollView(cx, ns); + js_register_cocos2dx_ui_ListView(cx, ns); + js_register_cocos2dx_ui_LayoutComponent(cx, ns); + js_register_cocos2dx_ui_Button(cx, ns); + js_register_cocos2dx_ui_LayoutParameter(cx, ns); + js_register_cocos2dx_ui_LinearLayoutParameter(cx, ns); + js_register_cocos2dx_ui_ImageView(cx, ns); + js_register_cocos2dx_ui_HBox(cx, ns); + js_register_cocos2dx_ui_RichElementText(cx, ns); + js_register_cocos2dx_ui_PageView(cx, ns); + js_register_cocos2dx_ui_Helper(cx, ns); + js_register_cocos2dx_ui_EditBox(cx, ns); + js_register_cocos2dx_ui_Text(cx, ns); + js_register_cocos2dx_ui_RichElementImage(cx, ns); + js_register_cocos2dx_ui_RelativeLayoutParameter(cx, ns); + js_register_cocos2dx_ui_UICCTextField(cx, ns); } diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_ui_auto.hpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_ui_auto.hpp index 979a6acded..0b5ea66c16 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_ui_auto.hpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_ui_auto.hpp @@ -10,8 +10,8 @@ extern JSObject *jsb_cocos2d_ui_LayoutParameter_prototype; bool js_cocos2dx_ui_LayoutParameter_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_LayoutParameter_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_LayoutParameter(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_LayoutParameter(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_LayoutParameter_clone(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_LayoutParameter_getLayoutType(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_LayoutParameter_createCloneInstance(JSContext *cx, uint32_t argc, jsval *vp); @@ -24,8 +24,8 @@ extern JSObject *jsb_cocos2d_ui_LinearLayoutParameter_prototype; bool js_cocos2dx_ui_LinearLayoutParameter_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_LinearLayoutParameter_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_LinearLayoutParameter(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_LinearLayoutParameter(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_LinearLayoutParameter_setGravity(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_LinearLayoutParameter_getGravity(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_LinearLayoutParameter_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -36,8 +36,8 @@ extern JSObject *jsb_cocos2d_ui_RelativeLayoutParameter_prototype; bool js_cocos2dx_ui_RelativeLayoutParameter_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_RelativeLayoutParameter_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_RelativeLayoutParameter(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_RelativeLayoutParameter(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_RelativeLayoutParameter_setAlign(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RelativeLayoutParameter_setRelativeToWidgetName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RelativeLayoutParameter_getRelativeName(JSContext *cx, uint32_t argc, jsval *vp); @@ -52,8 +52,9 @@ extern JSObject *jsb_cocos2d_ui_Widget_prototype; bool js_cocos2dx_ui_Widget_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_Widget_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_Widget(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_Widget(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_ui_Widget_setLayoutComponentEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Widget_setSizePercent(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Widget_getCustomSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Widget_getLeftBoundary(JSContext *cx, uint32_t argc, jsval *vp); @@ -103,6 +104,7 @@ bool js_cocos2dx_ui_Widget_setUnifySizeEnabled(JSContext *cx, uint32_t argc, jsv bool js_cocos2dx_ui_Widget_isPropagateTouchEvents(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Widget_getCurrentFocusedWidget(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Widget_hitTest(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_Widget_isLayoutComponentEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Widget_requestFocus(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Widget_updateSizeAndPosition(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Widget_onFocusChange(JSContext *cx, uint32_t argc, jsval *vp); @@ -130,8 +132,8 @@ extern JSObject *jsb_cocos2d_ui_Layout_prototype; bool js_cocos2dx_ui_Layout_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_Layout_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_Layout(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_Layout(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_Layout_setBackGroundColorVector(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Layout_setClippingType(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Layout_setBackGroundColorType(JSContext *cx, uint32_t argc, jsval *vp); @@ -174,8 +176,9 @@ extern JSObject *jsb_cocos2d_ui_Button_prototype; bool js_cocos2dx_ui_Button_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_Button_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_Button(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_Button(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_ui_Button_getNormalTextureSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Button_getTitleText(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Button_setTitleFontSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Button_setScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp); @@ -211,8 +214,8 @@ extern JSObject *jsb_cocos2d_ui_CheckBox_prototype; bool js_cocos2dx_ui_CheckBox_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_CheckBox_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_CheckBox(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_CheckBox(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_CheckBox_loadTextureBackGroundSelected(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_CheckBox_loadTextureBackGroundDisabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_CheckBox_setSelected(JSContext *cx, uint32_t argc, jsval *vp); @@ -220,7 +223,9 @@ bool js_cocos2dx_ui_CheckBox_loadTextureFrontCross(JSContext *cx, uint32_t argc, bool js_cocos2dx_ui_CheckBox_isSelected(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_CheckBox_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_CheckBox_loadTextures(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_CheckBox_getZoomScale(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_CheckBox_loadTextureBackGround(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_CheckBox_setZoomScale(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_CheckBox_loadTextureFrontCrossDisabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_CheckBox_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_CheckBox_createInstance(JSContext *cx, uint32_t argc, jsval *vp); @@ -231,8 +236,8 @@ extern JSObject *jsb_cocos2d_ui_ImageView_prototype; bool js_cocos2dx_ui_ImageView_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_ImageView_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_ImageView(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_ImageView(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_ImageView_loadTexture(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ImageView_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ImageView_setScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp); @@ -249,8 +254,8 @@ extern JSObject *jsb_cocos2d_ui_Text_prototype; bool js_cocos2dx_ui_Text_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_Text_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_Text(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_Text(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_Text_enableShadow(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Text_getFontSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Text_getString(JSContext *cx, uint32_t argc, jsval *vp); @@ -265,6 +270,7 @@ bool js_cocos2dx_ui_Text_isTouchScaleChangeEnabled(JSContext *cx, uint32_t argc, bool js_cocos2dx_ui_Text_getFontName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Text_setTextAreaSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Text_getStringLength(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_Text_getAutoRenderSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Text_enableOutline(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Text_getType(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Text_getTextHorizontalAlignment(JSContext *cx, uint32_t argc, jsval *vp); @@ -283,8 +289,8 @@ extern JSObject *jsb_cocos2d_ui_TextAtlas_prototype; bool js_cocos2dx_ui_TextAtlas_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_TextAtlas_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_TextAtlas(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_TextAtlas(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_TextAtlas_getStringLength(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextAtlas_getString(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextAtlas_setString(JSContext *cx, uint32_t argc, jsval *vp); @@ -299,8 +305,8 @@ extern JSObject *jsb_cocos2d_ui_LoadingBar_prototype; bool js_cocos2dx_ui_LoadingBar_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_LoadingBar_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_LoadingBar(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_LoadingBar(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_LoadingBar_setPercent(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_LoadingBar_loadTexture(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_LoadingBar_setDirection(JSContext *cx, uint32_t argc, jsval *vp); @@ -319,8 +325,8 @@ extern JSObject *jsb_cocos2d_ui_ScrollView_prototype; bool js_cocos2dx_ui_ScrollView_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_ScrollView_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_ScrollView(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_ScrollView(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_ScrollView_scrollToTop(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_scrollToPercentHorizontal(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_isInertiaScrollEnabled(JSContext *cx, uint32_t argc, jsval *vp); @@ -361,8 +367,8 @@ extern JSObject *jsb_cocos2d_ui_ListView_prototype; bool js_cocos2dx_ui_ListView_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_ListView_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_ListView(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_ListView(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_ListView_getIndex(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ListView_removeAllItems(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ListView_setGravity(JSContext *cx, uint32_t argc, jsval *vp); @@ -390,8 +396,8 @@ extern JSObject *jsb_cocos2d_ui_Slider_prototype; bool js_cocos2dx_ui_Slider_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_Slider_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_Slider(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_Slider(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_Slider_setPercent(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Slider_loadSlidBallTextureDisabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Slider_loadSlidBallTextureNormal(JSContext *cx, uint32_t argc, jsval *vp); @@ -402,7 +408,9 @@ bool js_cocos2dx_ui_Slider_setCapInsetProgressBarRebderer(JSContext *cx, uint32_ bool js_cocos2dx_ui_Slider_setCapInsetsBarRenderer(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Slider_getCapInsetsProgressBarRebderer(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Slider_setScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_Slider_setZoomScale(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Slider_setCapInsets(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_Slider_getZoomScale(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Slider_loadSlidBallTexturePressed(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Slider_isScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Slider_getCapInsetsBarRenderer(JSContext *cx, uint32_t argc, jsval *vp); @@ -411,13 +419,48 @@ bool js_cocos2dx_ui_Slider_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Slider_createInstance(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Slider_Slider(JSContext *cx, uint32_t argc, jsval *vp); +extern JSClass *jsb_cocos2d_ui_UICCTextField_class; +extern JSObject *jsb_cocos2d_ui_UICCTextField_prototype; + +bool js_cocos2dx_ui_UICCTextField_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_ui_UICCTextField_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_ui_UICCTextField(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_ui_UICCTextField_onTextFieldAttachWithIME(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_setPasswordText(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_setAttachWithIME(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_getDeleteBackward(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_getAttachWithIME(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_onTextFieldDeleteBackward(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_getInsertText(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_deleteBackward(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_setInsertText(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_getDetachWithIME(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_getCharCount(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_closeIME(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_setPasswordEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_setMaxLengthEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_isPasswordEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_insertText(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_setPasswordStyleText(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_onTextFieldInsertText(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_onTextFieldDetachWithIME(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_getMaxLength(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_isMaxLengthEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_openIME(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_setDetachWithIME(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_setMaxLength(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_setDeleteBackward(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_UICCTextField_UICCTextField(JSContext *cx, uint32_t argc, jsval *vp); + extern JSClass *jsb_cocos2d_ui_TextField_class; extern JSObject *jsb_cocos2d_ui_TextField_prototype; bool js_cocos2dx_ui_TextField_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_TextField_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_TextField(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_TextField(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_TextField_setAttachWithIME(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextField_getFontSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextField_getString(JSContext *cx, uint32_t argc, jsval *vp); @@ -436,6 +479,7 @@ bool js_cocos2dx_ui_TextField_getFontName(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_ui_TextField_setTextAreaSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextField_attachWithIME(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextField_getStringLength(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_TextField_getAutoRenderSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextField_setPasswordEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextField_getPlaceHolderColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextField_getPasswordStyleText(JSContext *cx, uint32_t argc, jsval *vp); @@ -451,7 +495,6 @@ bool js_cocos2dx_ui_TextField_getMaxLength(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_ui_TextField_isMaxLengthEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextField_setDetachWithIME(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextField_setTouchAreaEnabled(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ui_TextField_hitTest(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextField_setMaxLength(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextField_setTouchSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextField_getTouchSize(JSContext *cx, uint32_t argc, jsval *vp); @@ -464,8 +507,8 @@ extern JSObject *jsb_cocos2d_ui_TextBMFont_prototype; bool js_cocos2dx_ui_TextBMFont_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_TextBMFont_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_TextBMFont(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_TextBMFont(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_TextBMFont_setFntFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextBMFont_getStringLength(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_TextBMFont_setString(JSContext *cx, uint32_t argc, jsval *vp); @@ -479,8 +522,8 @@ extern JSObject *jsb_cocos2d_ui_PageView_prototype; bool js_cocos2dx_ui_PageView_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_PageView_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_PageView(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_PageView(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_PageView_getCustomScrollThreshold(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_PageView_getCurPageIndex(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_PageView_addWidgetToPage(JSContext *cx, uint32_t argc, jsval *vp); @@ -504,13 +547,14 @@ extern JSObject *jsb_cocos2d_ui_Helper_prototype; bool js_cocos2dx_ui_Helper_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_Helper_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_Helper(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_Helper(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_Helper_getSubStringOfUTF8String(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Helper_changeLayoutSystemActiveState(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Helper_seekActionWidgetByActionTag(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Helper_seekWidgetByName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Helper_seekWidgetByTag(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_Helper_restrictCapInsetRect(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Helper_doLayout(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_ui_RichElement_class; @@ -518,8 +562,8 @@ extern JSObject *jsb_cocos2d_ui_RichElement_prototype; bool js_cocos2dx_ui_RichElement_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_RichElement_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_RichElement(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_RichElement(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_RichElement_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RichElement_RichElement(JSContext *cx, uint32_t argc, jsval *vp); @@ -528,8 +572,8 @@ extern JSObject *jsb_cocos2d_ui_RichElementText_prototype; bool js_cocos2dx_ui_RichElementText_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_RichElementText_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_RichElementText(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_RichElementText(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_RichElementText_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RichElementText_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RichElementText_RichElementText(JSContext *cx, uint32_t argc, jsval *vp); @@ -539,8 +583,8 @@ extern JSObject *jsb_cocos2d_ui_RichElementImage_prototype; bool js_cocos2dx_ui_RichElementImage_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_RichElementImage_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_RichElementImage(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_RichElementImage(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_RichElementImage_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RichElementImage_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RichElementImage_RichElementImage(JSContext *cx, uint32_t argc, jsval *vp); @@ -550,8 +594,8 @@ extern JSObject *jsb_cocos2d_ui_RichElementCustomNode_prototype; bool js_cocos2dx_ui_RichElementCustomNode_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_RichElementCustomNode_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_RichElementCustomNode(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_RichElementCustomNode(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_RichElementCustomNode_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RichElementCustomNode_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RichElementCustomNode_RichElementCustomNode(JSContext *cx, uint32_t argc, jsval *vp); @@ -561,12 +605,10 @@ extern JSObject *jsb_cocos2d_ui_RichText_prototype; bool js_cocos2dx_ui_RichText_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_RichText_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_RichText(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_RichText(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_RichText_insertElement(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ui_RichText_setAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RichText_pushBackElement(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ui_RichText_ignoreContentAdaptWithSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RichText_setVerticalSpace(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RichText_formatText(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RichText_removeElement(JSContext *cx, uint32_t argc, jsval *vp); @@ -578,8 +620,8 @@ extern JSObject *jsb_cocos2d_ui_HBox_prototype; bool js_cocos2dx_ui_HBox_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_HBox_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_HBox(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_HBox(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_HBox_initWithSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_HBox_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_HBox_HBox(JSContext *cx, uint32_t argc, jsval *vp); @@ -589,8 +631,8 @@ extern JSObject *jsb_cocos2d_ui_VBox_prototype; bool js_cocos2dx_ui_VBox_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_VBox_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_VBox(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_VBox(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_VBox_initWithSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_VBox_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_VBox_VBox(JSContext *cx, uint32_t argc, jsval *vp); @@ -600,8 +642,8 @@ extern JSObject *jsb_cocos2d_ui_RelativeBox_prototype; bool js_cocos2dx_ui_RelativeBox_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_RelativeBox_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_RelativeBox(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_RelativeBox(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_RelativeBox_initWithSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RelativeBox_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_RelativeBox_RelativeBox(JSContext *cx, uint32_t argc, jsval *vp); @@ -611,29 +653,32 @@ extern JSObject *jsb_cocos2d_ui_Scale9Sprite_prototype; bool js_cocos2dx_ui_Scale9Sprite_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_Scale9Sprite_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_Scale9Sprite(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_Scale9Sprite(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_Scale9Sprite_disableCascadeColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_updateWithSprite(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_isFlippedX(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_Scale9Sprite_setScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_setFlippedY(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_setFlippedX(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ui_Scale9Sprite_setScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_disableCascadeOpacity(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_Scale9Sprite_setState(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_setInsetBottom(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrameName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_getSprite(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_setInsetTop(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_setPreferredSize(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ui_Scale9Sprite_getInsetRight(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_setSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_Scale9Sprite_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_getInsetBottom(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_ui_Scale9Sprite_isScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_getCapInsets(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_Scale9Sprite_isScale9Enabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_Scale9Sprite_getInsetRight(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_getOriginalSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_initWithFile(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_Scale9Sprite_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_getInsetTop(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_setInsetLeft(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrame(JSContext *cx, uint32_t argc, jsval *vp); @@ -652,8 +697,8 @@ extern JSObject *jsb_cocos2d_ui_EditBox_prototype; bool js_cocos2dx_ui_EditBox_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_ui_EditBox_finalize(JSContext *cx, JSObject *obj); -void js_register_cocos2dx_ui_EditBox(JSContext *cx, JSObject *global); -void register_all_cocos2dx_ui(JSContext* cx, JSObject* obj); +void js_register_cocos2dx_ui_EditBox(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_EditBox_getText(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_EditBox_setFontSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_EditBox_setPlaceholderFontName(JSContext *cx, uint32_t argc, jsval *vp); @@ -674,5 +719,65 @@ bool js_cocos2dx_ui_EditBox_setMaxLength(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_ui_EditBox_setFont(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_EditBox_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_EditBox_EditBox(JSContext *cx, uint32_t argc, jsval *vp); + +extern JSClass *jsb_cocos2d_ui_LayoutComponent_class; +extern JSObject *jsb_cocos2d_ui_LayoutComponent_prototype; + +bool js_cocos2dx_ui_LayoutComponent_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_ui_LayoutComponent_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_ui_LayoutComponent(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_ui_LayoutComponent_setStretchWidthEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setPercentWidth(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getAnchorPosition(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setPositionPercentXEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setStretchHeightEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setActiveEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getRightMargin(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getSize(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setAnchorPosition(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_refreshLayout(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_isPercentWidthEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setVerticalEdge(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getTopMargin(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setSizeWidth(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getPercentContentSize(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getVerticalEdge(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setPercentWidthEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_isStretchWidthEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setLeftMargin(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getSizeWidth(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setPositionPercentYEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getSizeHeight(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getPositionPercentY(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getPositionPercentX(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setTopMargin(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getPercentHeight(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getUsingPercentContentSize(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setPositionPercentY(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setPositionPercentX(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setRightMargin(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_isPositionPercentYEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setPercentHeight(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setPercentOnlyEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setHorizontalEdge(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setPosition(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setUsingPercentContentSize(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getLeftMargin(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getPosition(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setSizeHeight(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_isPositionPercentXEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getBottomMargin(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setPercentHeightEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setPercentContentSize(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_isPercentHeightEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getPercentWidth(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_getHorizontalEdge(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_isStretchHeightEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setBottomMargin(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_setSize(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_bindLayoutComponent(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_LayoutComponent_LayoutComponent(JSContext *cx, uint32_t argc, jsval *vp); #endif diff --git a/frameworks/js-bindings/bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp b/frameworks/js-bindings/bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp new file mode 100644 index 0000000000..b0013ff7bf --- /dev/null +++ b/frameworks/js-bindings/bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp @@ -0,0 +1,159 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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 "jsb_cocos2dx_3d_manual.h" +#include "cocos2d_specifics.hpp" +#include "jsb_cocos2dx_3d_auto.hpp" + +using namespace cocos2d; + +class JSB_HeapValueWrapper{ +public: + JSB_HeapValueWrapper(JSContext* cx, JS::HandleValue value):_cx(cx), _data(value){ + JS::AddValueRoot(_cx, &_data); + } + + ~JSB_HeapValueWrapper(){ + JS::RemoveValueRoot(_cx, &_data); + } + + JS::Value get(){ + return _data.get(); + } +private: + JSContext* _cx; + JS::Heap _data; +}; + +static bool js_cocos2dx_Sprite3D_createAsync(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if(argc == 4 || argc == 5) + { + std::string modelPath; + jsval_to_std_string(cx, args.get(0), &modelPath); + + std::function callback; + std::shared_ptr func(new JSFunctionWrapper(cx, args.get(argc == 4 ? 2 : 3).toObjectOrNull(), args.get(argc == 4 ? 1 : 2))); + auto lambda = [=](Sprite3D* larg0, void* larg1) -> void{ + + jsval largv[2]; + js_proxy_t* proxy = js_get_or_create_proxy(cx, larg0); + largv[0] = proxy ? OBJECT_TO_JSVAL(proxy->obj) : JS::UndefinedValue(); + JSB_HeapValueWrapper* v = (JSB_HeapValueWrapper*)larg1; + largv[1] = v->get(); + + JS::RootedValue rval(cx); + bool ok = func->invoke(2, largv, &rval); + if (!ok && JS_IsExceptionPending(cx)) { + JS_ReportPendingException(cx); + } + + delete v; + }; + callback = lambda; + + JSB_HeapValueWrapper* data = new JSB_HeapValueWrapper(cx, args.get(argc == 4 ? 3 : 4)); + + if(argc == 4) + cocos2d::Sprite3D::createAsync(modelPath, callback, data); + else + { + std::string texturePath; + jsval_to_std_string(cx, args.get(1), &texturePath); + cocos2d::Sprite3D::createAsync(modelPath, texturePath, callback, data); + } + return true; + } + + JS_ReportError(cx, "wrong number of arguments"); + return false; +} + +bool js_cocos2dx_Sprite3D_getAABB(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_setCullFaceEnabled : Invalid Native Object"); + if(argc == 0) + { + cocos2d::AABB aabb = cobj->getAABB(); + + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); + JS::RootedValue min(cx, vector3_to_jsval(cx, aabb._min)); + JS::RootedValue max(cx, vector3_to_jsval(cx, aabb._max)); + + bool ok = JS_DefineProperty(cx, tmp, "min", min, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "max", max, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Sprite3D_setCullFaceEnabled : Error processing arguments"); + + args.rval().set(OBJECT_TO_JSVAL(tmp)); + return true; + } + JS_ReportError(cx, "wrong number of arguments"); + return false; +} + +bool js_cocos2dx_Mesh_getMeshVertexAttribute(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Mesh* cobj = (cocos2d::Mesh *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Mesh_getMeshVertexAttribute : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Mesh_getMeshVertexAttribute : Error processing arguments"); + const cocos2d::MeshVertexAttrib ret = cobj->getMeshVertexAttribute(arg0); + jsval jsret = JSVAL_NULL; + jsret = meshVertexAttrib_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_getMeshVertexAttribute : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} + +void register_all_cocos2dx_3d_manual(JSContext *cx, JS::HandleObject global) +{ + JS::RootedValue tmpVal(cx); + JS::RootedObject ccObj(cx); + JS::RootedObject tmpObj(cx); + get_or_create_js_obj(cx, global, "jsb", &ccObj); + + JS_GetProperty(cx, ccObj, "Sprite3D", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); + JS_DefineFunction(cx, tmpObj, "createAsync", js_cocos2dx_Sprite3D_createAsync, 4, JSPROP_READONLY | JSPROP_PERMANENT); + + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Sprite3D_prototype), "getAABB", js_cocos2dx_Sprite3D_getAABB, 0, JSPROP_READONLY | JSPROP_PERMANENT); + + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Mesh_prototype), "getMeshVertexAttribute", js_cocos2dx_Mesh_getMeshVertexAttribute, 1, JSPROP_READONLY | JSPROP_PERMANENT); +} \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/manual/3d/jsb_cocos2dx_3d_manual.h b/frameworks/js-bindings/bindings/manual/3d/jsb_cocos2dx_3d_manual.h new file mode 100644 index 0000000000..d496e1cd83 --- /dev/null +++ b/frameworks/js-bindings/bindings/manual/3d/jsb_cocos2dx_3d_manual.h @@ -0,0 +1,33 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ +#ifndef __jsb_cocos2dx_3d_manual_h__ +#define __jsb_cocos2dx_3d_manual_h__ + +#include "jsapi.h" + +void register_all_cocos2dx_3d_manual(JSContext *cx, JS::HandleObject global); + +#endif \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/manual/ScriptingCore.cpp b/frameworks/js-bindings/bindings/manual/ScriptingCore.cpp index 439a63c37d..a4eee9e283 100644 --- a/frameworks/js-bindings/bindings/manual/ScriptingCore.cpp +++ b/frameworks/js-bindings/bindings/manual/ScriptingCore.cpp @@ -34,7 +34,7 @@ #include "jsb_cocos2dx_auto.hpp" #include "js_bindings_config.h" // for debug socket -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) #include #include #else @@ -101,11 +101,11 @@ static std::unordered_map filename_script; // port ~> socket map static std::unordered_map ports_sockets; // name ~> globals -static std::unordered_map globals; +static std::unordered_map globals; static void cc_closesocket(int fd) { -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) closesocket(fd); #else close(fd); @@ -121,20 +121,20 @@ static void ReportException(JSContext *cx) } } -static void executeJSFunctionFromReservedSpot(JSContext *cx, JSObject *obj, - jsval &dataVal, jsval &retval) { +static void executeJSFunctionFromReservedSpot(JSContext *cx, JS::HandleObject obj, + const JS::HandleValueArray& dataVal, JS::MutableHandleValue retval) { - jsval func = JS_GetReservedSlot(obj, 0); + JS::RootedValue func(cx, JS_GetReservedSlot(obj, 0)); - if (func == JSVAL_VOID) { return; } - jsval thisObj = JS_GetReservedSlot(obj, 1); + if (func.isNullOrUndefined()) { return; } + JS::RootedValue thisObj(cx, JS_GetReservedSlot(obj, 1)); JSAutoCompartment ac(cx, obj); - if (thisObj == JSVAL_VOID) { - JS_CallFunctionValue(cx, obj, func, 1, &dataVal, &retval); + if (thisObj.isNullOrUndefined()) { + JS_CallFunctionValue(cx, obj, func, dataVal, retval); } else { - assert(!JSVAL_IS_PRIMITIVE(thisObj)); - JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(thisObj), func, 1, &dataVal, &retval); + assert(!thisObj.isPrimitive()); + JS_CallFunctionValue(cx, JS::RootedObject(cx, thisObj.toObjectOrNull()), func, dataVal, retval); } } @@ -208,13 +208,13 @@ static std::string getMouseFuncName(EventMouse::MouseEventType eventType) return funcName; } -static void rootObject(JSContext *cx, JSObject *obj) { - JS_AddNamedObjectRoot(cx, &obj, "unnamed"); +static void rootObject(JSContext *cx, JS::Heap *obj) { + AddNamedObjectRoot(cx, obj, "unnamed"); } -static void unRootObject(JSContext *cx, JSObject *obj) { - JS_RemoveObjectRoot(cx, &obj); +static void unRootObject(JSContext *cx, JS::Heap *obj) { + RemoveObjectRoot(cx, obj); } void removeJSObject(JSContext* cx, void* nativeObj) @@ -225,33 +225,38 @@ void removeJSObject(JSContext* cx, void* nativeObj) nproxy = jsb_get_native_proxy(nativeObj); if (nproxy) { jsproxy = jsb_get_js_proxy(nproxy->obj); - JS_RemoveObjectRoot(cx, &jsproxy->obj); + RemoveObjectRoot(cx, &jsproxy->obj); jsb_remove_proxy(nproxy, jsproxy); } } -void ScriptingCore::executeJSFunctionWithThisObj(jsval thisObj, - jsval callback, - uint32_t argc/* = 0*/, - jsval* vp/* = NULL*/, - jsval* retVal/* = NULL*/) +void ScriptingCore::executeJSFunctionWithThisObj(JS::HandleValue thisObj, JS::HandleValue callback) { - if (callback != JSVAL_VOID || thisObj != JSVAL_VOID) + JS::RootedValue retVal(_cx); + executeJSFunctionWithThisObj(thisObj, callback, JS::HandleValueArray::empty(), &retVal); +} + +void ScriptingCore::executeJSFunctionWithThisObj(JS::HandleValue thisObj, + JS::HandleValue callback, + const JS::HandleValueArray& vp, + JS::MutableHandleValue retVal) +{ + if (!callback.isNullOrUndefined() || !thisObj.isNullOrUndefined()) { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET // Very important: The last parameter 'retVal' passed to 'JS_CallFunctionValue' should not be a NULL pointer. // If it's a NULL pointer, crash will be triggered in 'JS_CallFunctionValue'. To find out the reason of this crash is very difficult. // So we have to check the availability of 'retVal'. - if (retVal) - { - JS_CallFunctionValue(_cx, JSVAL_TO_OBJECT(thisObj), callback, argc, vp, retVal); - } - else - { - jsval jsRet; - JS_CallFunctionValue(_cx, JSVAL_TO_OBJECT(thisObj), callback, argc, vp, &jsRet); - } +// if (retVal) +// { + JS_CallFunctionValue(_cx, JS::RootedObject(_cx, thisObj.toObjectOrNull()), callback, vp, retVal); +// } +// else +// { +// jsval jsRet; +// JS_CallFunctionValue(_cx, JSVAL_TO_OBJECT(thisObj), callback, argc, vp, &jsRet); +// } } } @@ -281,7 +286,7 @@ bool JSBCore_platform(JSContext *cx, uint32_t argc, jsval *vp) JS_ReportError(cx, "Invalid number of arguments in __getPlatform"); return false; } - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); Application::Platform platform; // config.deviceType: Device Type @@ -292,9 +297,7 @@ bool JSBCore_platform(JSContext *cx, uint32_t argc, jsval *vp) platform = Application::getInstance()->getTargetPlatform(); // #endif - jsval ret = INT_TO_JSVAL((int)platform); - - JS_SET_RVAL(cx, vp, ret); + args.rval().set(INT_TO_JSVAL((int)platform)); return true; }; @@ -307,12 +310,12 @@ bool JSBCore_version(JSContext *cx, uint32_t argc, jsval *vp) return false; } + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); char version[256]; snprintf(version, sizeof(version)-1, "%s", cocos2dVersion()); JSString * js_version = JS_InternString(cx, version); - jsval ret = STRING_TO_JSVAL(js_version); - JS_SET_RVAL(cx, vp, ret); + args.rval().set(STRING_TO_JSVAL(js_version)); return true; }; @@ -325,6 +328,8 @@ bool JSBCore_os(JSContext *cx, uint32_t argc, jsval *vp) return false; } + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JSString * os; // osx, ios, android, windows, linux, etc.. @@ -344,12 +349,15 @@ bool JSBCore_os(JSContext *cx, uint32_t argc, jsval *vp) os = JS_InternString(cx, "Blackberry"); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) os = JS_InternString(cx, "OS X"); +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) + os = JS_InternString(cx, "WP8"); +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) + os = JS_InternString(cx, "WINRT"); #else os = JS_InternString(cx, "Unknown"); #endif - jsval ret = STRING_TO_JSVAL(os); - JS_SET_RVAL(cx, vp, ret); + args.rval().set(STRING_TO_JSVAL(os)); return true; }; @@ -361,13 +369,14 @@ bool JSB_cleanScript(JSContext *cx, uint32_t argc, jsval *vp) JS_ReportError(cx, "Invalid number of arguments in JSB_cleanScript"); return false; } - jsval *argv = JS_ARGV(cx, vp); - JSString *jsPath = JSVAL_TO_STRING(argv[0]); + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JSString *jsPath = args.get(0).toString(); JSB_PRECONDITION2(jsPath, cx, false, "Error js file in clean script"); JSStringWrapper wrapper(jsPath); ScriptingCore::getInstance()->cleanScript(wrapper.get()); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; }; @@ -375,28 +384,35 @@ bool JSB_cleanScript(JSContext *cx, uint32_t argc, jsval *vp) bool JSB_core_restartVM(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==0, cx, false, "Invalid number of arguments in executeScript"); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); ScriptingCore::getInstance()->reset(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; }; -void registerDefaultClasses(JSContext* cx, JSObject* global) { +void registerDefaultClasses(JSContext* cx, JS::HandleObject global) { // first, try to get the ns JS::RootedValue nsval(cx); JS::RootedObject ns(cx); JS_GetProperty(cx, global, "cc", &nsval); - if (nsval == JSVAL_VOID) { - ns = JS_NewObject(cx, NULL, NULL, NULL); + // Not exist, create it + if (nsval == JSVAL_VOID) + { + ns.set(JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); nsval = OBJECT_TO_JSVAL(ns); JS_SetProperty(cx, global, "cc", nsval); - } else { - JS_ValueToObject(cx, nsval, &ns); + } + else + { + ns.set(nsval.toObjectOrNull()); } // // Javascript controller (__jsc__) // - JSObject *jsc = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject jsc(cx, JS_NewObject(cx, NULL, proto, parent)); JS::RootedValue jscVal(cx); jscVal = OBJECT_TO_JSVAL(jsc); JS_SetProperty(cx, global, "__jsc__", jscVal); @@ -424,18 +440,27 @@ static void sc_finalize(JSFreeOp *freeOp, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (global class)", obj); } -static JSClass global_class = { +//static JSClass global_class = { +// "global", JSCLASS_GLOBAL_FLAGS, +// JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, +// JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, sc_finalize, +// JSCLASS_NO_OPTIONAL_MEMBERS +//}; + +static const JSClass global_class = { "global", JSCLASS_GLOBAL_FLAGS, JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, sc_finalize, - JSCLASS_NO_OPTIONAL_MEMBERS + nullptr, nullptr, nullptr, + JS_GlobalObjectTraceHook }; + ScriptingCore::ScriptingCore() : _rt(nullptr) , _cx(nullptr) -, _global(nullptr) -, _debugGlobal(nullptr) +//, _global(nullptr) +//, _debugGlobal(nullptr) , _callFromScript(false) { // set utf8 strings internally (we don't need utf16) @@ -450,31 +475,25 @@ void ScriptingCore::initRegister() this->_runLoop = new SimpleRunLoop(); } -void ScriptingCore::string_report(jsval val) { - if (JSVAL_IS_NULL(val)) { +void ScriptingCore::string_report(JS::HandleValue val) { + if (val.isNull()) { LOGD("val : (JSVAL_IS_NULL(val)"); // return 1; - } else if ((JSVAL_IS_BOOLEAN(val)) && - (false == (JSVAL_TO_BOOLEAN(val)))) { + } else if (val.isBoolean() && false == val.toBoolean()) { LOGD("val : (return value is false"); // return 1; - } else if (JSVAL_IS_STRING(val)) { + } else if (val.isString()) { JSContext* cx = this->getGlobalContext(); - JSString *str = JS::ToString(cx, JS::RootedValue(cx, val)); - if (NULL == str) { + JS::RootedString str(cx, val.toString()); + if (str.get()) { LOGD("val : return string is NULL"); } else { JSStringWrapper wrapper(str); LOGD("val : return string =\n%s\n", wrapper.get()); } - } else if (JSVAL_IS_NUMBER(val)) { - double number; - if (false == - JS::ToNumber(this->getGlobalContext(), JS::RootedValue(_cx, val), &number)) { - LOGD("val : return number could not be converted"); - } else { - LOGD("val : return number =\n%f", number); - } + } else if (val.isNumber()) { + double number = val.toNumber(); + LOGD("val : return number =\n%f", number); } } @@ -483,21 +502,10 @@ bool ScriptingCore::evalString(const char *string, jsval *outVal, const char *fi if (cx == NULL) cx = _cx; if (global == NULL) - global = _global; - + global = _global.ref().get(); + JSAutoCompartment ac(cx, global); - - JSScript* script = JS_CompileScript(cx, JS::RootedObject(cx, global), string, strlen(string), JS::CompileOptions(cx)); - if (script) - { - bool evaluatedOK = JS_ExecuteScript(cx, global, script, outVal); - if (false == evaluatedOK) - { - fprintf(stderr, "(evaluatedOK == false)\n"); - } - return evaluatedOK; - } - return false; + return JS_EvaluateScript(cx, JS::RootedObject(cx, global), string, strlen(string), "ScriptingCore::evalString", 1); } void ScriptingCore::start() @@ -513,7 +521,7 @@ void ScriptingCore::addRegisterCallback(sc_register_sth callback) { void ScriptingCore::removeAllRoots(JSContext *cx) { js_proxy_t *current, *tmp; HASH_ITER(hh, _js_native_global_ht, current, tmp) { - JS_RemoveObjectRoot(cx, ¤t->obj); + RemoveObjectRoot(cx, ¤t->obj); HASH_DEL(_js_native_global_ht, current); free(current); } @@ -525,11 +533,21 @@ void ScriptingCore::removeAllRoots(JSContext *cx) { HASH_CLEAR(hh, _native_js_global_ht); } -static JSPrincipals shellTrustedPrincipals = { 1 }; +// Just a wrapper around JSPrincipals that allows static construction. +class CCJSPrincipals : public JSPrincipals +{ + public: + explicit CCJSPrincipals(int rc = 0) + : JSPrincipals() + { + refcount = rc; + } +}; + +static CCJSPrincipals shellTrustedPrincipals(1); static bool -CheckObjectAccess(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JSAccessMode mode, - JS::MutableHandleValue vp) +CheckObjectAccess(JSContext *cx) { return true; } @@ -540,12 +558,12 @@ static JSSecurityCallbacks securityCallbacks = { }; void ScriptingCore::createGlobalContext() { - if (this->_cx && this->_rt) { - ScriptingCore::removeAllRoots(this->_cx); - JS_DestroyContext(this->_cx); - JS_DestroyRuntime(this->_rt); - this->_cx = NULL; - this->_rt = NULL; + if (_cx && _rt) { + ScriptingCore::removeAllRoots(_cx); + JS_DestroyContext(_cx); + JS_DestroyRuntime(_rt); + _cx = NULL; + _rt = NULL; } // Start the engine. Added in SpiderMonkey v25 @@ -554,35 +572,41 @@ void ScriptingCore::createGlobalContext() { // Removed from Spidermonkey 19. //JS_SetCStringsAreUTF8(); - this->_rt = JS_NewRuntime(8L * 1024L * 1024L, JS_USE_HELPER_THREADS); + _rt = JS_NewRuntime(8L * 1024L * 1024L); JS_SetGCParameter(_rt, JSGC_MAX_BYTES, 0xffffffff); JS_SetTrustedPrincipals(_rt, &shellTrustedPrincipals); JS_SetSecurityCallbacks(_rt, &securityCallbacks); JS_SetNativeStackQuota(_rt, JSB_MAX_STACK_QUOTA); - this->_cx = JS_NewContext(_rt, 8192); + _cx = JS_NewContext(_rt, 8192); // Removed in Firefox v27 // JS_SetOptions(this->_cx, JSOPTION_TYPE_INFERENCE); - JS::ContextOptionsRef(_cx).setTypeInference(true); - JS::ContextOptionsRef(_cx).setIon(true); - JS::ContextOptionsRef(_cx).setBaseline(true); + // Removed in Firefox v33 +// JS::ContextOptionsRef(_cx).setTypeInference(true); + + JS::RuntimeOptionsRef(_rt).setIon(true); + JS::RuntimeOptionsRef(_rt).setBaseline(true); // JS_SetVersion(this->_cx, JSVERSION_LATEST); - JS_SetErrorReporter(this->_cx, ScriptingCore::reportError); + JS_SetErrorReporter(_cx, ScriptingCore::reportError); #if defined(JS_GC_ZEAL) && defined(DEBUG) //JS_SetGCZeal(this->_cx, 2, JS_DEFAULT_ZEAL_FREQ); #endif - this->_global = NewGlobalObject(_cx); - JSAutoCompartment ac(_cx, _global); - js::SetDefaultObjectForContext(_cx, _global); + _global.construct(_cx); + _global.ref() = NewGlobalObject(_cx); + + JSAutoCompartment ac(_cx, _global.ref()); + + // Removed in Firefox v34 + js::SetDefaultObjectForContext(_cx, _global.ref()); for (std::vector::iterator it = registrationList.begin(); it != registrationList.end(); it++) { sc_register_sth callback = *it; - callback(this->_cx, this->_global); + callback(_cx, _global.ref()); } } @@ -624,7 +648,7 @@ void ScriptingCore::compileScript(const char *path, JSObject* global, JSContext* cocos2d::FileUtils *futil = cocos2d::FileUtils::getInstance(); if (global == NULL) { - global = _global; + global = _global.ref().get(); } if (cx == NULL) { cx = _cx; @@ -644,7 +668,7 @@ void ScriptingCore::compileScript(const char *path, JSObject* global, JSContext* Data data = futil->getDataFromFile(byteCodePath); if (!data.isNull()) { - script = JS_DecodeScript(cx, data.getBytes(), static_cast(data.getSize()), nullptr, nullptr); + script = JS_DecodeScript(cx, data.getBytes(), static_cast(data.getSize()), nullptr); } } @@ -655,19 +679,22 @@ void ScriptingCore::compileScript(const char *path, JSObject* global, JSContext* ReportException(cx); std::string fullPath = futil->fullPathForFilename(path); - JS::CompileOptions options(cx); - options.setUTF8(true).setFileAndLine(fullPath.c_str(), 1); + + JS::CompileOptions op(cx); + op.setUTF8(true); + op.setFileAndLine(fullPath.c_str(), 1); + bool ok = false; #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) std::string jsFileContent = futil->getStringFromFile(fullPath); if (!jsFileContent.empty()) { - script = JS::Compile(cx, obj, options, jsFileContent.c_str(), jsFileContent.size()); + ok = JS::Compile(cx, obj, op, jsFileContent.c_str(), jsFileContent.size(), &script); } #else - script = JS::Compile(cx, obj, options, fullPath.c_str()); + ok = JS::Compile(cx, obj, op, fullPath.c_str(), &script); #endif - if (script) { + if (ok) { filename_script[fullPath] = script; } } @@ -703,19 +730,48 @@ void ScriptingCore::cleanAllScript() filename_script.clear(); } -bool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* cx) +bool ScriptingCore::runScript(const char *path) +{ + return runScript(path, _global.ref(), _cx); +} + +bool ScriptingCore::runScript(const char *path, JS::HandleObject global, JSContext* cx) { - if (global == NULL) { - global = _global; - } if (cx == NULL) { cx = _cx; } + +#if(CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + //FIX ME : compileScript breaks on windows, execute the script directly + auto fileUtil = FileUtils::getInstance(); + + + // check jsc file first + std::string byteCodePath = RemoveFileExt(std::string(path)) + BYTE_CODE_FILE_EXT; + + // Check whether '.jsc' files exist to avoid outputing log which says 'couldn't find .jsc file'. + if (fileUtil->isFileExist(byteCodePath)) + { + Data data = fileUtil->getDataFromFile(byteCodePath); + if (!data.isNull()) + { + JSAutoCompartment ac(cx, global); + JS::RootedScript script(cx, JS_DecodeScript(cx, data.getBytes(), static_cast(data.getSize()), nullptr)); + bool ok = JS_ExecuteScript(cx, global, script); + return ok; + } + } + + auto fullpath = fileUtil->fullPathForFilename(path); + auto content = fileUtil->getStringFromFile(fullpath); + JSAutoCompartment ac(cx, global); + bool evaluatedOK = JS_EvaluateScript(cx, global, content.c_str(), content.length(), path, 1); +#else compileScript(path,global,cx); - JSScript * script = getScript(path); + JS::RootedScript script(cx, getScript(path)); bool evaluatedOK = false; if (script) { - jsval rval; + JS::RootedValue rval(cx); JSAutoCompartment ac(cx, global); evaluatedOK = JS_ExecuteScript(cx, global, script, &rval); if (false == evaluatedOK) { @@ -723,6 +779,7 @@ bool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* cx) JS_ReportPendingException(cx); } } +#endif return evaluatedOK; } @@ -785,14 +842,15 @@ void ScriptingCore::reportError(JSContext *cx, const char *message, JSErrorRepor bool ScriptingCore::log(JSContext* cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc > 0) { - JSString *string = NULL; - JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &string); + JSString *string = JS::ToString(cx, args.get(0)); if (string) { JSStringWrapper wrapper(string); js_log("%s", wrapper.get()); } } + args.rval().setUndefined(); return true; } @@ -806,7 +864,7 @@ void ScriptingCore::removeScriptObjectByObject(Ref* pObj) if (nproxy) { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); jsproxy = jsb_get_js_proxy(nproxy->obj); - JS_RemoveObjectRoot(cx, &jsproxy->obj); + RemoveObjectRoot(cx, &jsproxy->obj); jsb_remove_proxy(nproxy, jsproxy); } } @@ -819,16 +877,16 @@ bool ScriptingCore::setReservedSpot(uint32_t i, JSObject *obj, jsval value) { bool ScriptingCore::executeScript(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc >= 1) { - jsval* argv = JS_ARGV(cx, vp); - JSString* str = JS::ToString(cx, JS::RootedValue(cx, argv[0])); + JSString* str = JS::ToString(cx, JS::RootedValue(cx, args.get(0))); JSStringWrapper path(str); bool res = false; - if (argc == 2 && argv[1].isString()) { - JSString* globalName = JSVAL_TO_STRING(argv[1]); + if (argc == 2 && args.get(1).isString()) { + JSString* globalName = args.get(1).toString(); JSStringWrapper name(globalName); -// JS::RootedObject* rootedGlobal = globals[name]; - JSObject* debugObj = ScriptingCore::getInstance()->getDebugGlobal(); + + JS::RootedObject debugObj(cx, ScriptingCore::getInstance()->getDebugGlobal()); if (debugObj) { res = ScriptingCore::getInstance()->runScript(path.get(), debugObj); } else { @@ -836,11 +894,12 @@ bool ScriptingCore::executeScript(JSContext *cx, uint32_t argc, jsval *vp) return false; } } else { - JSObject* glob = JS::CurrentGlobalOrNull(cx); + JS::RootedObject glob(cx, JS::CurrentGlobalOrNull(cx)); res = ScriptingCore::getInstance()->runScript(path.get(), glob); } return res; } + args.rval().setUndefined(); return true; } @@ -872,12 +931,12 @@ bool ScriptingCore::dumpRoot(JSContext *cx, uint32_t argc, jsval *vp) bool ScriptingCore::addRootJS(JSContext *cx, uint32_t argc, jsval *vp) { if (argc == 1) { - JSObject *o = NULL; - if (JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "o", &o) == true) { - if (JS_AddNamedObjectRoot(cx, &o, "from-js") == false) { - LOGD("something went wrong when setting an object to the root"); - } + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::Heap o(args.get(0).toObjectOrNull()); + if (AddNamedObjectRoot(cx, &o, "from-js") == false) { + LOGD("something went wrong when setting an object to the root"); } + return true; } return false; @@ -886,9 +945,10 @@ bool ScriptingCore::addRootJS(JSContext *cx, uint32_t argc, jsval *vp) bool ScriptingCore::removeRootJS(JSContext *cx, uint32_t argc, jsval *vp) { if (argc == 1) { - JSObject *o = NULL; - if (JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "o", &o) == true) { - JS_RemoveObjectRoot(cx, &o); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::Heap o(args.get(0).toObjectOrNull()); + if (o != nullptr) { + RemoveObjectRoot(cx, &o); } return true; } @@ -897,7 +957,8 @@ bool ScriptingCore::removeRootJS(JSContext *cx, uint32_t argc, jsval *vp) void ScriptingCore::pauseSchedulesAndActions(js_proxy_t* p) { - __Array * arr = JSScheduleWrapper::getTargetForJSObject(p->obj); + JS::RootedObject obj(_cx, p->obj.get()); + __Array * arr = JSScheduleWrapper::getTargetForJSObject(obj); if (! arr) return; Node* node = (Node*)p->ptr; @@ -911,7 +972,8 @@ void ScriptingCore::pauseSchedulesAndActions(js_proxy_t* p) void ScriptingCore::resumeSchedulesAndActions(js_proxy_t* p) { - __Array * arr = JSScheduleWrapper::getTargetForJSObject(p->obj); + JS::RootedObject obj(_cx, p->obj.get()); + __Array * arr = JSScheduleWrapper::getTargetForJSObject(obj); if (!arr) return; Node* node = (Node*)p->ptr; @@ -923,24 +985,26 @@ void ScriptingCore::resumeSchedulesAndActions(js_proxy_t* p) void ScriptingCore::cleanupSchedulesAndActions(js_proxy_t* p) { - __Array* arr = JSScheduleWrapper::getTargetForJSObject(p->obj); + JS::RootedObject obj(_cx, p->obj.get()); + __Array* arr = JSScheduleWrapper::getTargetForJSObject(obj); if (arr) { - Scheduler* pScheduler = Director::getInstance()->getScheduler(); - Ref* pObj = NULL; + Node* node = (Node*)p->ptr; + Scheduler* pScheduler = node->getScheduler(); + Ref* pObj = nullptr; CCARRAY_FOREACH(arr, pObj) { pScheduler->unscheduleAllForTarget(pObj); } - JSScheduleWrapper::removeAllTargetsForJSObject(p->obj); + JSScheduleWrapper::removeAllTargetsForJSObject(obj); } } -bool ScriptingCore::isFunctionOverridedInJS(JSObject* obj, const std::string& name, JSNative native) +bool ScriptingCore::isFunctionOverridedInJS(JS::HandleObject obj, const std::string& name, JSNative native) { JS::RootedValue value(_cx); bool ok = JS_GetProperty(_cx, obj, name.c_str(), &value); - if (ok && !value.isNullOrUndefined() && !JS_IsNativeFunction(JSVAL_TO_OBJECT(value), native)) + if (ok && !value.isNullOrUndefined() && !JS_IsNativeFunction(value.toObjectOrNull(), native)) { return true; } @@ -964,12 +1028,12 @@ int ScriptingCore::handleNodeEvent(void* data) if (!p) return 0; int ret = 0; - jsval retval; + JS::RootedValue retval(_cx); jsval dataVal = INT_TO_JSVAL(1); if (action == kNodeOnEnter) { - if (isFunctionOverridedInJS(p->obj, "onEnter", js_cocos2dx_Node_onEnter)) + if (isFunctionOverridedInJS(JS::RootedObject(_cx, p->obj.get()), "onEnter", js_cocos2dx_Node_onEnter)) { ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onEnter", 1, &dataVal, &retval); } @@ -977,7 +1041,7 @@ int ScriptingCore::handleNodeEvent(void* data) } else if (action == kNodeOnExit) { - if (isFunctionOverridedInJS(p->obj, "onExit", js_cocos2dx_Node_onExit)) + if (isFunctionOverridedInJS(JS::RootedObject(_cx, p->obj.get()), "onExit", js_cocos2dx_Node_onExit)) { ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onExit", 1, &dataVal, &retval); } @@ -985,14 +1049,14 @@ int ScriptingCore::handleNodeEvent(void* data) } else if (action == kNodeOnEnterTransitionDidFinish) { - if (isFunctionOverridedInJS(p->obj, "onEnterTransitionDidFinish", js_cocos2dx_Node_onEnterTransitionDidFinish)) + if (isFunctionOverridedInJS(JS::RootedObject(_cx, p->obj.get()), "onEnterTransitionDidFinish", js_cocos2dx_Node_onEnterTransitionDidFinish)) { ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onEnterTransitionDidFinish", 1, &dataVal, &retval); } } else if (action == kNodeOnExitTransitionDidStart) { - if (isFunctionOverridedInJS(p->obj, "onExitTransitionDidStart", js_cocos2dx_Node_onExitTransitionDidStart)) + if (isFunctionOverridedInJS(JS::RootedObject(_cx, p->obj.get()), "onExitTransitionDidStart", js_cocos2dx_Node_onExitTransitionDidStart)) { ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onExitTransitionDidStart", 1, &dataVal, &retval); } @@ -1020,12 +1084,12 @@ int ScriptingCore::handleComponentEvent(void* data) if (!p) return 0; int ret = 0; - jsval retval; + JS::RootedValue retval(_cx); jsval dataVal = INT_TO_JSVAL(1); if (action == kComponentOnEnter) { - if (isFunctionOverridedInJS(p->obj, "onEnter", js_cocos2dx_Component_onEnter)) + if (isFunctionOverridedInJS(JS::RootedObject(_cx, p->obj.get()), "onEnter", js_cocos2dx_Component_onEnter)) { ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onEnter", 1, &dataVal, &retval); } @@ -1033,7 +1097,7 @@ int ScriptingCore::handleComponentEvent(void* data) } else if (action == kComponentOnExit) { - if (isFunctionOverridedInJS(p->obj, "onExit", js_cocos2dx_Component_onExit)) + if (isFunctionOverridedInJS(JS::RootedObject(_cx, p->obj.get()), "onExit", js_cocos2dx_Component_onExit)) { ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onExit", 1, &dataVal, &retval); } @@ -1041,7 +1105,7 @@ int ScriptingCore::handleComponentEvent(void* data) } else if (action == kComponentOnUpdate) { - if (isFunctionOverridedInJS(p->obj, "update", js_cocos2dx_Component_update)) + if (isFunctionOverridedInJS(JS::RootedObject(_cx, p->obj.get()), "update", js_cocos2dx_Component_update)) { ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "update", 1, &dataVal, &retval); } @@ -1050,31 +1114,13 @@ int ScriptingCore::handleComponentEvent(void* data) return ret; } -int ScriptingCore::handleMenuClickedEvent(void* data) +bool ScriptingCore::handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, const std::vector& touches, cocos2d::Event* event) { - if (NULL == data) - return 0; - - BasicScriptData* basicScriptData = static_cast(data); - if (NULL == basicScriptData->nativeObject) - return 0; - - MenuItem* menuItem = static_cast(basicScriptData->nativeObject); - - js_proxy_t * p = jsb_get_native_proxy(menuItem); - if (!p) return 0; - - jsval retval; - jsval dataVal; - js_proxy_t *proxy = jsb_get_native_proxy(menuItem); - dataVal = (proxy ? OBJECT_TO_JSVAL(proxy->obj) : JSVAL_NULL); - - executeJSFunctionFromReservedSpot(this->_cx, p->obj, dataVal, retval); - - return 1; + JS::RootedValue ret(_cx); + return handleTouchesEvent(nativeObj, eventCode, touches, event, &ret); } -bool ScriptingCore::handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, const std::vector& touches, cocos2d::Event* event, jsval* jsvalRet/* = nullptr */) +bool ScriptingCore::handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, const std::vector& touches, cocos2d::Event* event, JS::MutableHandleValue jsvalRet) { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET @@ -1082,15 +1128,15 @@ bool ScriptingCore::handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::Eve std::string funcName = getTouchesFuncName(eventCode); - JSObject *jsretArr = JS_NewArrayObject(this->_cx, 0, NULL); + JS::RootedObject jsretArr(_cx, JS_NewArrayObject(this->_cx, 0)); - JS_AddNamedObjectRoot(this->_cx, &jsretArr, "touchArray"); +// AddNamedObjectRoot(this->_cx, &jsretArr, "touchArray"); int count = 0; for (const auto& touch : touches) { JS::RootedValue jsret(_cx, getJSObject(this->_cx, touch)); - if (!JS_SetElement(this->_cx, jsretArr, count, &jsret)) + if (!JS_SetElement(this->_cx, jsretArr, count, jsret)) { break; } @@ -1105,20 +1151,13 @@ bool ScriptingCore::handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::Eve jsval dataVal[2]; dataVal[0] = OBJECT_TO_JSVAL(jsretArr); dataVal[1] = getJSObject(_cx, event); - - if (jsvalRet != nullptr) - { - ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 2, dataVal, jsvalRet); - } - else - { - jsval retval; - ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 2, dataVal, &retval); - } + + ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 2, dataVal, jsvalRet); + } while(false); - JS_RemoveObjectRoot(this->_cx, &jsretArr); +// JS_RemoveObjectRoot(this->_cx, &jsretArr); for (auto& touch : touches) { @@ -1130,7 +1169,13 @@ bool ScriptingCore::handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::Eve return ret; } -bool ScriptingCore::handleTouchEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, cocos2d::Touch* touch, cocos2d::Event* event, jsval* jsvalRet/* = nullptr*/) +bool ScriptingCore::handleTouchEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, cocos2d::Touch* touch, cocos2d::Event* event) +{ + JS::RootedValue ret(_cx); + return handleTouchEvent(nativeObj, eventCode, touch, event, &ret); +} + +bool ScriptingCore::handleTouchEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, cocos2d::Touch* touch, cocos2d::Event* event, JS::MutableHandleValue jsvalRet) { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET @@ -1146,27 +1191,27 @@ bool ScriptingCore::handleTouchEvent(void* nativeObj, cocos2d::EventTouch::Event dataVal[0] = getJSObject(_cx, touch); dataVal[1] = getJSObject(_cx, event); - if (jsvalRet != nullptr) - { +// if (jsvalRet != nullptr) +// { ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 2, dataVal, jsvalRet); - } - else - { - jsval retval; - executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 2, dataVal, &retval); - if(JSVAL_IS_NULL(retval)) - { - ret = false; - } - else if(JSVAL_IS_BOOLEAN(retval)) - { - ret = JSVAL_TO_BOOLEAN(retval); - } - else - { - ret = false; - } - } +// } +// else +// { +// JS::RootedValue retval(_cx); +// executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 2, dataVal, &retval); +// if(retval.isNull()) +// { +// ret = false; +// } +// else if(retval.isBoolean()) +// { +// ret = retval.toBoolean(); +// } +// else +// { +// ret = false; +// } +// } } while(false); removeJSObject(_cx, touch); @@ -1175,7 +1220,13 @@ bool ScriptingCore::handleTouchEvent(void* nativeObj, cocos2d::EventTouch::Event return ret; } -bool ScriptingCore::handleMouseEvent(void* nativeObj, cocos2d::EventMouse::MouseEventType eventType, cocos2d::Event* event, jsval* jsvalRet/* = nullptr*/) +bool ScriptingCore::handleMouseEvent(void* nativeObj, cocos2d::EventMouse::MouseEventType eventType, cocos2d::Event* event) +{ + JS::RootedValue ret(_cx); + return handleMouseEvent(nativeObj, eventType, event, &ret); +} + +bool ScriptingCore::handleMouseEvent(void* nativeObj, cocos2d::EventMouse::MouseEventType eventType, cocos2d::Event* event, JS::MutableHandleValue jsvalRet) { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET @@ -1190,27 +1241,27 @@ bool ScriptingCore::handleMouseEvent(void* nativeObj, cocos2d::EventMouse::Mouse jsval dataVal[1]; dataVal[0] = getJSObject(_cx, event); - if (jsvalRet != nullptr) - { +// if (jsvalRet != nullptr) +// { ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 1, dataVal, jsvalRet); - } - else - { - jsval retval; - executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 1, dataVal, &retval); - if(JSVAL_IS_NULL(retval)) - { - ret = false; - } - else if(JSVAL_IS_BOOLEAN(retval)) - { - ret = JSVAL_TO_BOOLEAN(retval); - } - else - { - ret = false; - } - } +// } +// else +// { +// JS::RootedValue retval(_cx); +// executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 1, dataVal, &retval); +// if(retval.isNull()) +// { +// ret = false; +// } +// else if(retval.isBoolean()) +// { +// ret = retval.toBoolean(); +// } +// else +// { +// ret = false; +// } +// } } while(false); removeJSObject(_cx, event); @@ -1223,26 +1274,48 @@ bool ScriptingCore::executeFunctionWithObjectData(void* nativeObj, const char *n js_proxy_t * p = jsb_get_native_proxy(nativeObj); if (!p) return false; - jsval retval; + JS::RootedValue retval(_cx); jsval dataVal = OBJECT_TO_JSVAL(obj); executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), name, 1, &dataVal, &retval); - if (JSVAL_IS_NULL(retval)) { + if (retval.isNull()) { return false; } - else if (JSVAL_IS_BOOLEAN(retval)) { - return JSVAL_TO_BOOLEAN(retval); + else if (retval.isBoolean()) { + return retval.toBoolean(); } return false; } -bool ScriptingCore::executeFunctionWithOwner(jsval owner, const char *name, uint32_t argc /* = 0 */, jsval *vp /* = NULL */, jsval* retVal /* = NULL */) +bool ScriptingCore::executeFunctionWithOwner(jsval owner, const char *name, uint32_t argc, jsval *vp) +{ + JS::HandleValueArray args = JS::HandleValueArray::fromMarkedLocation(argc, vp); + JS::RootedValue rval(_cx); + return executeFunctionWithOwner(owner, name, args, &rval); +} + +bool ScriptingCore::executeFunctionWithOwner(jsval owner, const char *name, uint32_t argc, jsval *vp, JS::MutableHandleValue retVal) +{ + //should not use CallArgs here, use HandleValueArray instead !! + //because the "jsval* vp" is not the standard format from JSNative, the array doesn't contain this and retval + //JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::HandleValueArray args = JS::HandleValueArray::fromMarkedLocation(argc, vp); + return executeFunctionWithOwner(owner, name, args, retVal); +} + +bool ScriptingCore::executeFunctionWithOwner(jsval owner, const char *name, const JS::HandleValueArray& args) +{ + JS::RootedValue ret(_cx); + return executeFunctionWithOwner(owner, name, args, &ret); +} + +bool ScriptingCore::executeFunctionWithOwner(jsval owner, const char *name, const JS::HandleValueArray& args, JS::MutableHandleValue retVal) { bool bRet = false; bool hasAction; JSContext* cx = this->_cx; JS::RootedValue temp_retval(cx); - JSObject* obj = JSVAL_TO_OBJECT(owner); + JS::RootedObject obj(cx, JS::RootedValue(cx, owner).toObjectOrNull()); do { @@ -1255,14 +1328,9 @@ bool ScriptingCore::executeFunctionWithOwner(jsval owner, const char *name, uint if (temp_retval == JSVAL_VOID) { break; } - - if (retVal) { - bRet = JS_CallFunctionName(cx, obj, name, argc, vp, retVal); - } - else { - jsval jsret; - bRet = JS_CallFunctionName(cx, obj, name, argc, vp, &jsret); - } + + bRet = JS_CallFunctionName(cx, obj, name, args, retVal); + } }while(0); return bRet; @@ -1286,11 +1354,11 @@ bool ScriptingCore::handleKeybardEvent(void* nativeObj, cocos2d::EventKeyboard:: if (isPressed) { - ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onKeyPressed", 2, args); + ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "_onKeyPressed", 2, args); } else { - ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onKeyReleased", 2, args); + ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "_onKeyReleased", 2, args); } removeJSObject(_cx, event); @@ -1298,29 +1366,50 @@ bool ScriptingCore::handleKeybardEvent(void* nativeObj, cocos2d::EventKeyboard:: return ret; } +bool ScriptingCore::handleFocusEvent(void* nativeObj, cocos2d::ui::Widget* widgetLoseFocus, cocos2d::ui::Widget* widgetGetFocus) +{ + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + + js_proxy_t * p = jsb_get_native_proxy(nativeObj); + + if (nullptr == p) + return false; + + jsval args[2] = { + getJSObject(_cx, widgetLoseFocus), + getJSObject(_cx, widgetGetFocus) + }; + + bool ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onFocusChanged", 2, args); + + removeJSObject(_cx, widgetLoseFocus); + removeJSObject(_cx, widgetGetFocus); + + return ret; +} + int ScriptingCore::executeCustomTouchesEvent(EventTouch::EventCode eventType, const std::vector& touches, JSObject *obj) { - jsval retval; std::string funcName = getTouchesFuncName(eventType); - JSObject *jsretArr = JS_NewArrayObject(this->_cx, 0, NULL); - JS_AddNamedObjectRoot(this->_cx, &jsretArr, "touchArray"); + JS::RootedObject jsretArr(_cx, JS_NewArrayObject(this->_cx, 0)); +// JS_AddNamedObjectRoot(this->_cx, &jsretArr, "touchArray"); int count = 0; for (auto& touch : touches) { jsval jsret = getJSObject(this->_cx, touch); JS::RootedValue jsval(_cx, jsret); - if (!JS_SetElement(this->_cx, jsretArr, count, &jsval)) { + if (!JS_SetElement(this->_cx, jsretArr, count, jsval)) { break; } ++count; } jsval jsretArrVal = OBJECT_TO_JSVAL(jsretArr); - executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), funcName.c_str(), 1, &jsretArrVal, &retval); - JS_RemoveObjectRoot(this->_cx, &jsretArr); + executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), funcName.c_str(), 1, &jsretArrVal); +// JS_RemoveObjectRoot(this->_cx, &jsretArr); for (auto& touch : touches) { @@ -1336,7 +1425,7 @@ int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType, { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - jsval retval; + JS::RootedValue retval(_cx); std::string funcName = getTouchFuncName(eventType); jsval jsTouch = getJSObject(this->_cx, pTouch); @@ -1353,7 +1442,7 @@ int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType, int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType, Touch *pTouch, JSObject *obj, - jsval &retval) + JS::MutableHandleValue retval) { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET @@ -1361,7 +1450,7 @@ int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType, jsval jsTouch = getJSObject(this->_cx, pTouch); - executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), funcName.c_str(), 1, &jsTouch, &retval); + executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), funcName.c_str(), 1, &jsTouch, retval); // Remove touch object from global hash table and unroot it. removeJSObject(this->_cx, pTouch); @@ -1382,7 +1471,7 @@ int ScriptingCore::sendEvent(ScriptEvent* evt) return 0; } - JSAutoCompartment ac(_cx, _global); + JSAutoCompartment ac(_cx, _global.ref().get()); switch (evt->type) { @@ -1392,9 +1481,6 @@ int ScriptingCore::sendEvent(ScriptEvent* evt) } break; case kMenuClickedEvent: - { - return handleMenuClickedEvent(evt->data); - } break; case kTouchEvent: { @@ -1426,7 +1512,7 @@ bool ScriptingCore::parseConfig(ConfigType type, const std::string &str) jsval args[2]; args[0] = int32_to_jsval(_cx, static_cast(type)); args[1] = std_string_to_jsval(_cx, str); - return (true == executeFunctionWithOwner(OBJECT_TO_JSVAL(_global), "__onParseConfig", 2, args)); + return (true == executeFunctionWithOwner(OBJECT_TO_JSVAL(_global.ref().get()), "__onParseConfig", 2, args)); } #pragma mark - Debug @@ -1452,13 +1538,13 @@ void SimpleRunLoop::update(float dt) void ScriptingCore::debugProcessInput(const std::string& str) { - JSAutoCompartment ac(_cx, _debugGlobal); + JSAutoCompartment ac(_cx, _debugGlobal.ref()); JSString* jsstr = JS_NewStringCopyZ(_cx, str.c_str()); jsval argv = STRING_TO_JSVAL(jsstr); - jsval outval; + JS::RootedValue outval(_cx); - JS_CallFunctionName(_cx, _debugGlobal, "processInput", 1, &argv, &outval); + JS_CallFunctionName(_cx, JS::RootedObject(_cx, _debugGlobal.ref()), "processInput", JS::HandleValueArray::fromMarkedLocation(1, &argv), &outval); } static bool NS_ProcessNextEvent() @@ -1505,26 +1591,32 @@ bool JSBDebug_enterNestedEventLoop(JSContext* cx, unsigned argc, jsval* vp) CCASSERT(s_nestedLoopLevel <= nestLevel, "nested event didn't unwind properly"); - JS_SET_RVAL(cx, vp, UINT_TO_JSVAL(s_nestedLoopLevel)); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().set(UINT_TO_JSVAL(s_nestedLoopLevel)); +// JS_SET_RVAL(cx, vp, UINT_TO_JSVAL(s_nestedLoopLevel)); return true; } bool JSBDebug_exitNestedEventLoop(JSContext* cx, unsigned argc, jsval* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (s_nestedLoopLevel > 0) { --s_nestedLoopLevel; } else { - JS_SET_RVAL(cx, vp, UINT_TO_JSVAL(0)); + args.rval().set(UINT_TO_JSVAL(0)); +// JS_SET_RVAL(cx, vp, UINT_TO_JSVAL(0)); return true; } - - JS_SET_RVAL(cx, vp, UINT_TO_JSVAL(s_nestedLoopLevel)); + args.rval().setUndefined(); +// JS_SET_RVAL(cx, vp, UINT_TO_JSVAL(s_nestedLoopLevel)); return true; } bool JSBDebug_getEventLoopNestLevel(JSContext* cx, unsigned argc, jsval* vp) { - JS_SET_RVAL(cx, vp, UINT_TO_JSVAL(s_nestedLoopLevel)); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().set(UINT_TO_JSVAL(s_nestedLoopLevel)); +// JS_SET_RVAL(cx, vp, UINT_TO_JSVAL(s_nestedLoopLevel)); return true; } @@ -1568,7 +1660,7 @@ static void serverEntryPoint(unsigned int port) int err = 0; -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) WSADATA wsaData; err = WSAStartup(MAKEWORD(2, 2),&wsaData); #endif @@ -1649,8 +1741,8 @@ static void serverEntryPoint(unsigned int port) bool JSBDebug_BufferWrite(JSContext* cx, unsigned argc, jsval* vp) { if (argc == 1) { - jsval* argv = JS_ARGV(cx, vp); - JSStringWrapper strWrapper(argv[0]); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JSStringWrapper strWrapper(args.get(0)); // this is safe because we're already inside a lock (from clearBuffers) outData.append(strWrapper.get()); _clientSocketWriteAndClearString(outData); @@ -1660,32 +1752,33 @@ bool JSBDebug_BufferWrite(JSContext* cx, unsigned argc, jsval* vp) void ScriptingCore::enableDebugger(unsigned int port) { - if (_debugGlobal == NULL) + if (_debugGlobal.empty()) { - JSAutoCompartment ac0(_cx, _global); + JSAutoCompartment ac0(_cx, _global.ref().get()); JS_SetDebugMode(_cx, true); - _debugGlobal = NewGlobalObject(_cx, true); + _debugGlobal.construct(_cx); + _debugGlobal.ref() = NewGlobalObject(_cx, true); // Adds the debugger object to root, otherwise it may be collected by GC. - JS_AddObjectRoot(_cx, &_debugGlobal); - JS::RootedObject rootedDebugObj(_cx, _debugGlobal); + //AddObjectRoot(_cx, &_debugGlobal); no need, it's persistent rooted now + JS::RootedObject rootedDebugObj(_cx, _debugGlobal.ref()); JS_WrapObject(_cx, &rootedDebugObj); - JSAutoCompartment ac(_cx, _debugGlobal); + //JSAutoCompartment ac(_cx, _debugGlobal.ref()); //really needed? // these are used in the debug program - JS_DefineFunction(_cx, _debugGlobal, "log", ScriptingCore::log, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(_cx, _debugGlobal, "_bufferWrite", JSBDebug_BufferWrite, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(_cx, _debugGlobal, "_enterNestedEventLoop", JSBDebug_enterNestedEventLoop, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(_cx, _debugGlobal, "_exitNestedEventLoop", JSBDebug_exitNestedEventLoop, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(_cx, _debugGlobal, "_getEventLoopNestLevel", JSBDebug_getEventLoopNestLevel, 0, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(_cx, rootedDebugObj, "log", ScriptingCore::log, 0, JSPROP_READONLY | JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(_cx, rootedDebugObj, "_bufferWrite", JSBDebug_BufferWrite, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(_cx, rootedDebugObj, "_enterNestedEventLoop", JSBDebug_enterNestedEventLoop, 0, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(_cx, rootedDebugObj, "_exitNestedEventLoop", JSBDebug_exitNestedEventLoop, 0, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(_cx, rootedDebugObj, "_getEventLoopNestLevel", JSBDebug_getEventLoopNestLevel, 0, JSPROP_READONLY | JSPROP_PERMANENT); - runScript("script/jsb_debugger.js", _debugGlobal); + runScript("script/jsb_debugger.js", rootedDebugObj); // prepare the debugger - jsval argv = OBJECT_TO_JSVAL(_global); - jsval outval; - bool ok = JS_CallFunctionName(_cx, _debugGlobal, "_prepareDebugger", 1, &argv, &outval); + jsval argv = OBJECT_TO_JSVAL(_global.ref().get()); + JS::RootedValue outval(_cx); + bool ok = JS_CallFunctionName(_cx, rootedDebugObj, "_prepareDebugger", JS::HandleValueArray::fromMarkedLocation(1, &argv), &outval); if (!ok) { JS_ReportPendingException(_cx); } @@ -1693,7 +1786,7 @@ void ScriptingCore::enableDebugger(unsigned int port) // start bg thread auto t = std::thread(&serverEntryPoint,port); t.detach(); - + Scheduler* scheduler = Director::getInstance()->getScheduler(); scheduler->scheduleUpdate(this->_runLoop, 0, false); } @@ -1704,7 +1797,7 @@ JSObject* NewGlobalObject(JSContext* cx, bool debug) JS::CompartmentOptions options; options.setVersion(JSVERSION_LATEST); - JS::RootedObject glob(cx, JS_NewGlobalObject(cx, &global_class, NULL, JS::DontFireOnNewGlobalHook, options)); + JS::RootedObject glob(cx, JS_NewGlobalObject(cx, &global_class, &shellTrustedPrincipals, JS::DontFireOnNewGlobalHook, options)); if (!glob) { return NULL; } diff --git a/frameworks/js-bindings/bindings/manual/ScriptingCore.h b/frameworks/js-bindings/bindings/manual/ScriptingCore.h index 96c2292fed..50364a767b 100644 --- a/frameworks/js-bindings/bindings/manual/ScriptingCore.h +++ b/frameworks/js-bindings/bindings/manual/ScriptingCore.h @@ -29,21 +29,23 @@ #include "jsapi.h" #include "jsfriendapi.h" #include "cocos2d.h" +#include "ui/CocosGUI.h" #include "js_bindings_config.h" #include "js_bindings_core.h" #include "spidermonkey_specifics.h" #include "js_manual_conversions.h" +#include "mozilla/Maybe.h" #include #include -#define ENGINE_VERSION "Cocos2d-JS v3.2" +#define ENGINE_VERSION "Cocos2d-JS v3.5" void js_log(const char *format, ...); -typedef void (*sc_register_sth)(JSContext* cx, JSObject* global); +typedef void (*sc_register_sth)(JSContext* cx, JS::HandleObject global); -void registerDefaultClasses(JSContext* cx, JSObject* global); +void registerDefaultClasses(JSContext* cx, JS::HandleObject global); class SimpleRunLoop : public cocos2d::Ref @@ -57,8 +59,10 @@ class ScriptingCore : public cocos2d::ScriptEngineProtocol private: JSRuntime *_rt; JSContext *_cx; - JSObject *_global; - JSObject *_debugGlobal; + mozilla::Maybe _global; + mozilla::Maybe _debugGlobal; + //JS::Heap _global; + //JS::Heap _debugGlobal; SimpleRunLoop* _runLoop; bool _callFromScript; @@ -117,9 +121,14 @@ class ScriptingCore : public cocos2d::ScriptEngineProtocol virtual bool isCalledFromScript() { return _callFromScript; }; bool executeFunctionWithObjectData(void* nativeObj, const char *name, JSObject *obj); - bool executeFunctionWithOwner(jsval owner, const char *name, uint32_t argc = 0, jsval* vp = NULL, jsval* retVal = NULL); - void executeJSFunctionWithThisObj(jsval thisObj, jsval callback, uint32_t argc = 0, jsval* vp = NULL, jsval* retVal = NULL); + bool executeFunctionWithOwner(jsval owner, const char *name, uint32_t argc, jsval *vp); + bool executeFunctionWithOwner(jsval owner, const char *name, uint32_t argc, jsval *vp, JS::MutableHandleValue retVal); + bool executeFunctionWithOwner(jsval owner, const char *name, const JS::HandleValueArray& args); + bool executeFunctionWithOwner(jsval owner, const char *name, const JS::HandleValueArray& args, JS::MutableHandleValue retVal); + + void executeJSFunctionWithThisObj(JS::HandleValue thisObj, JS::HandleValue callback); + void executeJSFunctionWithThisObj(JS::HandleValue thisObj, JS::HandleValue callback, const JS::HandleValueArray& vp, JS::MutableHandleValue retVal); /** * will eval the specified string @@ -146,7 +155,8 @@ class ScriptingCore : public cocos2d::ScriptEngineProtocol * will run the specified string * @param string The path of the script to be run */ - bool runScript(const char *path, JSObject* global = NULL, JSContext* cx = NULL); + bool runScript(const char *path); + bool runScript(const char *path, JS::HandleObject global, JSContext* cx = NULL); /** * will clean script object the specified string @@ -190,7 +200,7 @@ class ScriptingCore : public cocos2d::ScriptEngineProtocol int executeCustomTouchEvent(cocos2d::EventTouch::EventCode eventType, - cocos2d::Touch *pTouch, JSObject *obj, jsval &retval); + cocos2d::Touch *pTouch, JSObject *obj, JS::MutableHandleValue retval); int executeCustomTouchEvent(cocos2d::EventTouch::EventCode eventType, cocos2d::Touch *pTouch, JSObject *obj); int executeCustomTouchesEvent(cocos2d::EventTouch::EventCode eventType, @@ -240,23 +250,30 @@ class ScriptingCore : public cocos2d::ScriptEngineProtocol */ void debugProcessInput(const std::string& str); void enableDebugger(unsigned int port = 5086); - JSObject* getDebugGlobal() { return _debugGlobal; } - JSObject* getGlobalObject() { return _global; } + JSObject* getDebugGlobal() { return _debugGlobal.ref().get(); } + JSObject* getGlobalObject() { return _global.ref().get(); } - bool isFunctionOverridedInJS(JSObject* obj, const std::string& name, JSNative native); + bool isFunctionOverridedInJS(JS::HandleObject obj, const std::string& name, JSNative native); - private: - void string_report(jsval val); +private: + void string_report(JS::HandleValue val); void initRegister(); + public: int handleNodeEvent(void* data); int handleComponentEvent(void* data); - int handleMenuClickedEvent(void* data); - bool handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, const std::vector& touches, cocos2d::Event* event, jsval* jsvalRet = nullptr); - bool handleTouchEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, cocos2d::Touch* touch, cocos2d::Event* event, jsval* jsvalRet = nullptr); - bool handleMouseEvent(void* nativeObj, cocos2d::EventMouse::MouseEventType eventType, cocos2d::Event* event, jsval* jsvalRet = nullptr); + bool handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, const std::vector& touches, cocos2d::Event* event); + bool handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, const std::vector& touches, cocos2d::Event* event, JS::MutableHandleValue jsvalRet); + + bool handleTouchEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, cocos2d::Touch* touch, cocos2d::Event* event); + bool handleTouchEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, cocos2d::Touch* touch, cocos2d::Event* event, JS::MutableHandleValue jsvalRet); + + bool handleMouseEvent(void* nativeObj, cocos2d::EventMouse::MouseEventType eventType, cocos2d::Event* event); + bool handleMouseEvent(void* nativeObj, cocos2d::EventMouse::MouseEventType eventType, cocos2d::Event* event, JS::MutableHandleValue jsvalRet); + bool handleKeybardEvent(void* nativeObj, cocos2d::EventKeyboard::KeyCode keyCode, bool isPressed, cocos2d::Event* event); + bool handleFocusEvent(void* nativeObj, cocos2d::ui::Widget* widgetLoseFocus, cocos2d::ui::Widget* widgetGetFocus); void restartVM(); }; diff --git a/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_auto_classes.cpp b/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_auto_classes.cpp index 2857be8b8f..df9c30a684 100644 --- a/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_auto_classes.cpp +++ b/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_auto_classes.cpp @@ -50,13 +50,13 @@ void JSB_cpConstraint_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: void bool JSB_cpConstraint_activateBodies(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpConstraint* arg0 = (cpConstraint*) proxy->handle; cpConstraintActivateBodies((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -64,13 +64,13 @@ bool JSB_cpConstraint_activateBodies(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpConstraint_destroy(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpConstraint* arg0 = (cpConstraint*) proxy->handle; cpConstraintDestroy((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -78,7 +78,7 @@ bool JSB_cpConstraint_destroy(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBody* bool JSB_cpConstraint_getA(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpConstraint* arg0 = (cpConstraint*) proxy->handle; @@ -86,8 +86,8 @@ bool JSB_cpConstraint_getA(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpConstraintGetA((cpConstraint*)arg0 ); - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JSB_cpBody_object, JSB_cpBody_class, "cpBody" ); - JS_SET_RVAL(cx, vp, ret_jsval); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpBody" ); + args.rval().set(ret_jsval); return true; } @@ -96,7 +96,7 @@ bool JSB_cpConstraint_getA(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBody* bool JSB_cpConstraint_getB(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpConstraint* arg0 = (cpConstraint*) proxy->handle; @@ -104,8 +104,8 @@ bool JSB_cpConstraint_getB(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpConstraintGetB((cpConstraint*)arg0 ); - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JSB_cpBody_object, JSB_cpBody_class, "cpBody" ); - JS_SET_RVAL(cx, vp, ret_jsval); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpBody" ); + args.rval().set(ret_jsval); return true; } @@ -114,14 +114,14 @@ bool JSB_cpConstraint_getB(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpConstraint_getErrorBias(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpConstraint* arg0 = (cpConstraint*) proxy->handle; cpFloat ret_val; ret_val = cpConstraintGetErrorBias((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -129,14 +129,14 @@ bool JSB_cpConstraint_getErrorBias(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpConstraint_getImpulse(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpConstraint* arg0 = (cpConstraint*) proxy->handle; cpFloat ret_val; ret_val = cpConstraintGetImpulse((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -144,14 +144,14 @@ bool JSB_cpConstraint_getImpulse(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpConstraint_getMaxBias(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpConstraint* arg0 = (cpConstraint*) proxy->handle; cpFloat ret_val; ret_val = cpConstraintGetMaxBias((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -159,14 +159,14 @@ bool JSB_cpConstraint_getMaxBias(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpConstraint_getMaxForce(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpConstraint* arg0 = (cpConstraint*) proxy->handle; cpFloat ret_val; ret_val = cpConstraintGetMaxForce((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -174,7 +174,7 @@ bool JSB_cpConstraint_getMaxForce(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpSpace* bool JSB_cpConstraint_getSpace(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpConstraint* arg0 = (cpConstraint*) proxy->handle; @@ -182,8 +182,8 @@ bool JSB_cpConstraint_getSpace(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpConstraintGetSpace((cpConstraint*)arg0 ); - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JSB_cpSpace_object, JSB_cpSpace_class, "cpSpace" ); - JS_SET_RVAL(cx, vp, ret_jsval); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpSpace" ); + args.rval().set(ret_jsval); return true; } @@ -196,15 +196,15 @@ bool JSB_cpConstraint_setErrorBias(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpConstraint* arg0 = (cpConstraint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraintSetErrorBias((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -216,15 +216,15 @@ bool JSB_cpConstraint_setMaxBias(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpConstraint* arg0 = (cpConstraint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraintSetMaxBias((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -236,19 +236,19 @@ bool JSB_cpConstraint_setMaxForce(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpConstraint* arg0 = (cpConstraint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraintSetMaxForce((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -void JSB_cpConstraint_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpConstraint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpConstraint_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpConstraint_class->name = name; @@ -263,7 +263,7 @@ void JSB_cpConstraint_createClass(JSContext *cx, JSObject* globalObj, const char JSB_cpConstraint_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("activateBodies", JSB_cpConstraint_activateBodies, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -284,7 +284,7 @@ void JSB_cpConstraint_createClass(JSContext *cx, JSObject* globalObj, const char JS_FS_END }; - JSB_cpConstraint_object = JS_InitClass(cx, globalObj, JSB_cpBase_object, JSB_cpConstraint_class, JSB_cpConstraint_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpConstraint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpBase_object), JSB_cpConstraint_class, JSB_cpConstraint_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -301,22 +301,22 @@ JSObject* JSB_cpGrooveJoint_object = NULL; bool JSB_cpGrooveJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==5, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpGrooveJoint_class, JSB_cpGrooveJoint_object, NULL); - jsval *argvp = JS_ARGV(cx,vp); + JSObject *jsobj = JS_NewObject(cx, JSB_cpGrooveJoint_class, JS::RootedObject(cx, JSB_cpGrooveJoint_object), JS::NullPtr()); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; cpVect arg2; cpVect arg3; cpVect arg4; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg0, NULL ); - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg3 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg4 ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg0, NULL ); + ok &= jsval_to_c_class( cx, args.get(1), (void**)&arg1, NULL ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(3), (cpVect*) &arg3 ); + ok &= jsval_to_cpVect( cx, args.get(4), (cpVect*) &arg4 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); void* ret_val = cpGrooveJointNew((cpBody*)arg0 , (cpBody*)arg1 , (cpVect)arg2 , (cpVect)arg3 , (cpVect)arg4 ); jsb_set_jsobject_for_proxy(jsobj, ret_val); jsb_set_c_proxy_for_jsobject(jsobj, ret_val, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -341,7 +341,7 @@ void JSB_cpGrooveJoint_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: cpVect bool JSB_cpGrooveJoint_getAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpGrooveJoint* arg0 = (cpGrooveJoint*) proxy->handle; @@ -350,7 +350,7 @@ bool JSB_cpGrooveJoint_getAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpGrooveJointGetAnchr2((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -359,7 +359,7 @@ bool JSB_cpGrooveJoint_getAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpGrooveJoint_getGrooveA(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpGrooveJoint* arg0 = (cpGrooveJoint*) proxy->handle; @@ -368,7 +368,7 @@ bool JSB_cpGrooveJoint_getGrooveA(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpGrooveJointGetGrooveA((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -377,7 +377,7 @@ bool JSB_cpGrooveJoint_getGrooveA(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpGrooveJoint_getGrooveB(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpGrooveJoint* arg0 = (cpGrooveJoint*) proxy->handle; @@ -386,7 +386,7 @@ bool JSB_cpGrooveJoint_getGrooveB(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpGrooveJointGetGrooveB((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -399,15 +399,15 @@ bool JSB_cpGrooveJoint_setAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpGrooveJoint* arg0 = (cpGrooveJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpGrooveJointSetAnchr2((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -419,15 +419,15 @@ bool JSB_cpGrooveJoint_setGrooveA(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpGrooveJoint* arg0 = (cpGrooveJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpGrooveJointSetGrooveA((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -439,19 +439,19 @@ bool JSB_cpGrooveJoint_setGrooveB(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpGrooveJoint* arg0 = (cpGrooveJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpGrooveJointSetGrooveB((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -void JSB_cpGrooveJoint_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpGrooveJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpGrooveJoint_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpGrooveJoint_class->name = name; @@ -466,7 +466,7 @@ void JSB_cpGrooveJoint_createClass(JSContext *cx, JSObject* globalObj, const cha JSB_cpGrooveJoint_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getAnchr2", JSB_cpGrooveJoint_getAnchr2, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -481,7 +481,7 @@ void JSB_cpGrooveJoint_createClass(JSContext *cx, JSObject* globalObj, const cha JS_FS_END }; - JSB_cpGrooveJoint_object = JS_InitClass(cx, globalObj, JSB_cpConstraint_object, JSB_cpGrooveJoint_class, JSB_cpGrooveJoint_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpGrooveJoint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpGrooveJoint_class, JSB_cpGrooveJoint_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -498,20 +498,20 @@ JSObject* JSB_cpSimpleMotor_object = NULL; bool JSB_cpSimpleMotor_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==3, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpSimpleMotor_class, JSB_cpSimpleMotor_object, NULL); - jsval *argvp = JS_ARGV(cx,vp); + JSObject *jsobj = JS_NewObject(cx, JSB_cpSimpleMotor_class, JS::RootedObject(cx, JSB_cpSimpleMotor_object), JS::NullPtr()); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; double arg2; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg0, NULL ); - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg0, NULL ); + ok &= jsval_to_c_class( cx, args.get(1), (void**)&arg1, NULL ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); void* ret_val = cpSimpleMotorNew((cpBody*)arg0 , (cpBody*)arg1 , (cpFloat)arg2 ); jsb_set_jsobject_for_proxy(jsobj, ret_val); jsb_set_c_proxy_for_jsobject(jsobj, ret_val, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -536,14 +536,14 @@ void JSB_cpSimpleMotor_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: cpFloat bool JSB_cpSimpleMotor_getRate(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSimpleMotor* arg0 = (cpSimpleMotor*) proxy->handle; cpFloat ret_val; ret_val = cpSimpleMotorGetRate((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -555,19 +555,19 @@ bool JSB_cpSimpleMotor_setRate(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSimpleMotor* arg0 = (cpSimpleMotor*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSimpleMotorSetRate((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -void JSB_cpSimpleMotor_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpSimpleMotor_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpSimpleMotor_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpSimpleMotor_class->name = name; @@ -582,7 +582,7 @@ void JSB_cpSimpleMotor_createClass(JSContext *cx, JSObject* globalObj, const cha JSB_cpSimpleMotor_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getRate", JSB_cpSimpleMotor_getRate, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -593,7 +593,7 @@ void JSB_cpSimpleMotor_createClass(JSContext *cx, JSObject* globalObj, const cha JS_FS_END }; - JSB_cpSimpleMotor_object = JS_InitClass(cx, globalObj, JSB_cpConstraint_object, JSB_cpSimpleMotor_class, JSB_cpSimpleMotor_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpSimpleMotor_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpSimpleMotor_class, JSB_cpSimpleMotor_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -610,16 +610,16 @@ JSObject* JSB_cpPivotJoint_object = NULL; bool JSB_cpPivotJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==4 || argc==3, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpPivotJoint_class, JSB_cpPivotJoint_object, NULL); - jsval *argvp = JS_ARGV(cx,vp); + JSObject *jsobj = JS_NewObject(cx, JSB_cpPivotJoint_class, JS::RootedObject(cx, JSB_cpPivotJoint_object), JS::NullPtr()); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; cpVect arg2; cpVect arg3; void *ret_val; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg0, NULL ); - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg0, NULL ); + ok &= jsval_to_c_class( cx, args.get(1), (void**)&arg1, NULL ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); if(argc == 4) { - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg3 ); + ok &= jsval_to_cpVect( cx, args.get(3), (cpVect*) &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); ret_val = cpPivotJointNew2((cpBody*)arg0 , (cpBody*)arg1 , (cpVect)arg2, (cpVect)arg3 ); } else { @@ -629,7 +629,7 @@ bool JSB_cpPivotJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) jsb_set_jsobject_for_proxy(jsobj, ret_val); jsb_set_c_proxy_for_jsobject(jsobj, ret_val, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -653,7 +653,7 @@ void JSB_cpPivotJoint_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: cpVect bool JSB_cpPivotJoint_getAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpPivotJoint* arg0 = (cpPivotJoint*) proxy->handle; @@ -662,7 +662,7 @@ bool JSB_cpPivotJoint_getAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpPivotJointGetAnchr1((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -671,7 +671,7 @@ bool JSB_cpPivotJoint_getAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpPivotJoint_getAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpPivotJoint* arg0 = (cpPivotJoint*) proxy->handle; @@ -680,7 +680,7 @@ bool JSB_cpPivotJoint_getAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpPivotJointGetAnchr2((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -693,15 +693,15 @@ bool JSB_cpPivotJoint_setAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpPivotJoint* arg0 = (cpPivotJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpPivotJointSetAnchr1((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -713,19 +713,19 @@ bool JSB_cpPivotJoint_setAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpPivotJoint* arg0 = (cpPivotJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpPivotJointSetAnchr2((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -void JSB_cpPivotJoint_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpPivotJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpPivotJoint_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpPivotJoint_class->name = name; @@ -740,7 +740,7 @@ void JSB_cpPivotJoint_createClass(JSContext *cx, JSObject* globalObj, const char JSB_cpPivotJoint_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getAnchr1", JSB_cpPivotJoint_getAnchr1, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -753,7 +753,7 @@ void JSB_cpPivotJoint_createClass(JSContext *cx, JSObject* globalObj, const char JS_FS_END }; - JSB_cpPivotJoint_object = JS_InitClass(cx, globalObj, JSB_cpConstraint_object, JSB_cpPivotJoint_class, JSB_cpPivotJoint_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpPivotJoint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpPivotJoint_class, JSB_cpPivotJoint_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -770,21 +770,21 @@ JSObject* JSB_cpPinJoint_object = NULL; bool JSB_cpPinJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==4, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpPinJoint_class, JSB_cpPinJoint_object, NULL); - jsval *argvp = JS_ARGV(cx,vp); + JSObject *jsobj = JS_NewObject(cx, JSB_cpPinJoint_class, JS::RootedObject(cx, JSB_cpPinJoint_object), JS::NullPtr()); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; cpVect arg2; cpVect arg3; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg0, NULL ); - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg3 ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg0, NULL ); + ok &= jsval_to_c_class( cx, args.get(1), (void**)&arg1, NULL ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(3), (cpVect*) &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); void* ret_val = cpPinJointNew((cpBody*)arg0 , (cpBody*)arg1 , (cpVect)arg2 , (cpVect)arg3 ); jsb_set_jsobject_for_proxy(jsobj, ret_val); jsb_set_c_proxy_for_jsobject(jsobj, ret_val, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -809,7 +809,7 @@ void JSB_cpPinJoint_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: cpVect bool JSB_cpPinJoint_getAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpPinJoint* arg0 = (cpPinJoint*) proxy->handle; @@ -818,7 +818,7 @@ bool JSB_cpPinJoint_getAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpPinJointGetAnchr1((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -827,7 +827,7 @@ bool JSB_cpPinJoint_getAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpPinJoint_getAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpPinJoint* arg0 = (cpPinJoint*) proxy->handle; @@ -836,7 +836,7 @@ bool JSB_cpPinJoint_getAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpPinJointGetAnchr2((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -845,14 +845,14 @@ bool JSB_cpPinJoint_getAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpPinJoint_getDist(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpPinJoint* arg0 = (cpPinJoint*) proxy->handle; cpFloat ret_val; ret_val = cpPinJointGetDist((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -864,15 +864,15 @@ bool JSB_cpPinJoint_setAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpPinJoint* arg0 = (cpPinJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpPinJointSetAnchr1((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -884,15 +884,15 @@ bool JSB_cpPinJoint_setAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpPinJoint* arg0 = (cpPinJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpPinJointSetAnchr2((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -904,19 +904,19 @@ bool JSB_cpPinJoint_setDist(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpPinJoint* arg0 = (cpPinJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpPinJointSetDist((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -void JSB_cpPinJoint_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpPinJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpPinJoint_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpPinJoint_class->name = name; @@ -931,7 +931,7 @@ void JSB_cpPinJoint_createClass(JSContext *cx, JSObject* globalObj, const char* JSB_cpPinJoint_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getAnchr1", JSB_cpPinJoint_getAnchr1, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -946,7 +946,7 @@ void JSB_cpPinJoint_createClass(JSContext *cx, JSObject* globalObj, const char* JS_FS_END }; - JSB_cpPinJoint_object = JS_InitClass(cx, globalObj, JSB_cpConstraint_object, JSB_cpPinJoint_class, JSB_cpPinJoint_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpPinJoint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpPinJoint_class, JSB_cpPinJoint_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -963,23 +963,23 @@ JSObject* JSB_cpSlideJoint_object = NULL; bool JSB_cpSlideJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==6, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpSlideJoint_class, JSB_cpSlideJoint_object, NULL); - jsval *argvp = JS_ARGV(cx,vp); + JSObject *jsobj = JS_NewObject(cx, JSB_cpSlideJoint_class, JS::RootedObject(cx, JSB_cpSlideJoint_object), JS::NullPtr()); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; cpVect arg2; cpVect arg3; double arg4; double arg5; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg0, NULL ); - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg3 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg4 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg5 ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg0, NULL ); + ok &= jsval_to_c_class( cx, args.get(1), (void**)&arg1, NULL ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(3), (cpVect*) &arg3 ); + ok &= JS::ToNumber( cx, args.get(4), &arg4 ); + ok &= JS::ToNumber( cx, args.get(5), &arg5 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); void* ret_val = cpSlideJointNew((cpBody*)arg0 , (cpBody*)arg1 , (cpVect)arg2 , (cpVect)arg3 , (cpFloat)arg4 , (cpFloat)arg5 ); jsb_set_jsobject_for_proxy(jsobj, ret_val); jsb_set_c_proxy_for_jsobject(jsobj, ret_val, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -1004,7 +1004,7 @@ void JSB_cpSlideJoint_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: cpVect bool JSB_cpSlideJoint_getAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSlideJoint* arg0 = (cpSlideJoint*) proxy->handle; @@ -1013,7 +1013,7 @@ bool JSB_cpSlideJoint_getAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpSlideJointGetAnchr1((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1022,7 +1022,7 @@ bool JSB_cpSlideJoint_getAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpSlideJoint_getAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSlideJoint* arg0 = (cpSlideJoint*) proxy->handle; @@ -1031,7 +1031,7 @@ bool JSB_cpSlideJoint_getAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpSlideJointGetAnchr2((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1040,14 +1040,14 @@ bool JSB_cpSlideJoint_getAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSlideJoint_getMax(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSlideJoint* arg0 = (cpSlideJoint*) proxy->handle; cpFloat ret_val; ret_val = cpSlideJointGetMax((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1055,14 +1055,14 @@ bool JSB_cpSlideJoint_getMax(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSlideJoint_getMin(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSlideJoint* arg0 = (cpSlideJoint*) proxy->handle; cpFloat ret_val; ret_val = cpSlideJointGetMin((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1074,15 +1074,15 @@ bool JSB_cpSlideJoint_setAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSlideJoint* arg0 = (cpSlideJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSlideJointSetAnchr1((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1094,15 +1094,15 @@ bool JSB_cpSlideJoint_setAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSlideJoint* arg0 = (cpSlideJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSlideJointSetAnchr2((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1114,15 +1114,15 @@ bool JSB_cpSlideJoint_setMax(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSlideJoint* arg0 = (cpSlideJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSlideJointSetMax((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1134,19 +1134,19 @@ bool JSB_cpSlideJoint_setMin(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSlideJoint* arg0 = (cpSlideJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSlideJointSetMin((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -void JSB_cpSlideJoint_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpSlideJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpSlideJoint_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpSlideJoint_class->name = name; @@ -1161,7 +1161,7 @@ void JSB_cpSlideJoint_createClass(JSContext *cx, JSObject* globalObj, const char JSB_cpSlideJoint_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getAnchr1", JSB_cpSlideJoint_getAnchr1, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -1178,7 +1178,7 @@ void JSB_cpSlideJoint_createClass(JSContext *cx, JSObject* globalObj, const char JS_FS_END }; - JSB_cpSlideJoint_object = JS_InitClass(cx, globalObj, JSB_cpConstraint_object, JSB_cpSlideJoint_class, JSB_cpSlideJoint_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpSlideJoint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpSlideJoint_class, JSB_cpSlideJoint_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -1195,21 +1195,21 @@ JSObject* JSB_cpGearJoint_object = NULL; bool JSB_cpGearJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==4, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpGearJoint_class, JSB_cpGearJoint_object, NULL); - jsval *argvp = JS_ARGV(cx,vp); + JSObject *jsobj = JS_NewObject(cx, JSB_cpGearJoint_class, JS::RootedObject(cx, JSB_cpGearJoint_object), JS::NullPtr()); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; double arg2; double arg3; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg0, NULL ); - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg3 ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg0, NULL ); + ok &= jsval_to_c_class( cx, args.get(1), (void**)&arg1, NULL ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); + ok &= JS::ToNumber( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); void* ret_val = cpGearJointNew((cpBody*)arg0 , (cpBody*)arg1 , (cpFloat)arg2 , (cpFloat)arg3 ); jsb_set_jsobject_for_proxy(jsobj, ret_val); jsb_set_c_proxy_for_jsobject(jsobj, ret_val, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -1234,14 +1234,14 @@ void JSB_cpGearJoint_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: cpFloat bool JSB_cpGearJoint_getPhase(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpGearJoint* arg0 = (cpGearJoint*) proxy->handle; cpFloat ret_val; ret_val = cpGearJointGetPhase((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1249,14 +1249,14 @@ bool JSB_cpGearJoint_getPhase(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpGearJoint_getRatio(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpGearJoint* arg0 = (cpGearJoint*) proxy->handle; cpFloat ret_val; ret_val = cpGearJointGetRatio((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1268,15 +1268,15 @@ bool JSB_cpGearJoint_setPhase(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpGearJoint* arg0 = (cpGearJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpGearJointSetPhase((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1288,19 +1288,19 @@ bool JSB_cpGearJoint_setRatio(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpGearJoint* arg0 = (cpGearJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpGearJointSetRatio((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -void JSB_cpGearJoint_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpGearJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpGearJoint_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpGearJoint_class->name = name; @@ -1315,7 +1315,7 @@ void JSB_cpGearJoint_createClass(JSContext *cx, JSObject* globalObj, const char* JSB_cpGearJoint_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getPhase", JSB_cpGearJoint_getPhase, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -1328,7 +1328,7 @@ void JSB_cpGearJoint_createClass(JSContext *cx, JSObject* globalObj, const char* JS_FS_END }; - JSB_cpGearJoint_object = JS_InitClass(cx, globalObj, JSB_cpConstraint_object, JSB_cpGearJoint_class, JSB_cpGearJoint_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpGearJoint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpGearJoint_class, JSB_cpGearJoint_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -1345,22 +1345,22 @@ JSObject* JSB_cpDampedRotarySpring_object = NULL; bool JSB_cpDampedRotarySpring_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==5, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpDampedRotarySpring_class, JSB_cpDampedRotarySpring_object, NULL); - jsval *argvp = JS_ARGV(cx,vp); + JSObject *jsobj = JS_NewObject(cx, JSB_cpDampedRotarySpring_class, JS::RootedObject(cx, JSB_cpDampedRotarySpring_object), JS::NullPtr()); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; double arg2; double arg3; double arg4; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg0, NULL ); - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg3 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg4 ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg0, NULL ); + ok &= jsval_to_c_class( cx, args.get(1), (void**)&arg1, NULL ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); + ok &= JS::ToNumber( cx, args.get(3), &arg3 ); + ok &= JS::ToNumber( cx, args.get(4), &arg4 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); void* ret_val = cpDampedRotarySpringNew((cpBody*)arg0 , (cpBody*)arg1 , (cpFloat)arg2 , (cpFloat)arg3 , (cpFloat)arg4 ); jsb_set_jsobject_for_proxy(jsobj, ret_val); jsb_set_c_proxy_for_jsobject(jsobj, ret_val, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -1385,14 +1385,14 @@ void JSB_cpDampedRotarySpring_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: cpFloat bool JSB_cpDampedRotarySpring_getDamping(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedRotarySpring* arg0 = (cpDampedRotarySpring*) proxy->handle; cpFloat ret_val; ret_val = cpDampedRotarySpringGetDamping((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1400,14 +1400,14 @@ bool JSB_cpDampedRotarySpring_getDamping(JSContext *cx, uint32_t argc, jsval *vp // Ret value: cpFloat bool JSB_cpDampedRotarySpring_getRestAngle(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedRotarySpring* arg0 = (cpDampedRotarySpring*) proxy->handle; cpFloat ret_val; ret_val = cpDampedRotarySpringGetRestAngle((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1415,14 +1415,14 @@ bool JSB_cpDampedRotarySpring_getRestAngle(JSContext *cx, uint32_t argc, jsval * // Ret value: cpFloat bool JSB_cpDampedRotarySpring_getStiffness(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedRotarySpring* arg0 = (cpDampedRotarySpring*) proxy->handle; cpFloat ret_val; ret_val = cpDampedRotarySpringGetStiffness((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1434,15 +1434,15 @@ bool JSB_cpDampedRotarySpring_setDamping(JSContext *cx, uint32_t argc, jsval *vp JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedRotarySpring* arg0 = (cpDampedRotarySpring*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedRotarySpringSetDamping((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1454,15 +1454,15 @@ bool JSB_cpDampedRotarySpring_setRestAngle(JSContext *cx, uint32_t argc, jsval * JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedRotarySpring* arg0 = (cpDampedRotarySpring*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedRotarySpringSetRestAngle((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1474,19 +1474,19 @@ bool JSB_cpDampedRotarySpring_setStiffness(JSContext *cx, uint32_t argc, jsval * JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedRotarySpring* arg0 = (cpDampedRotarySpring*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedRotarySpringSetStiffness((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -void JSB_cpDampedRotarySpring_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpDampedRotarySpring_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpDampedRotarySpring_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpDampedRotarySpring_class->name = name; @@ -1501,7 +1501,7 @@ void JSB_cpDampedRotarySpring_createClass(JSContext *cx, JSObject* globalObj, co JSB_cpDampedRotarySpring_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getDamping", JSB_cpDampedRotarySpring_getDamping, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -1516,7 +1516,7 @@ void JSB_cpDampedRotarySpring_createClass(JSContext *cx, JSObject* globalObj, co JS_FS_END }; - JSB_cpDampedRotarySpring_object = JS_InitClass(cx, globalObj, JSB_cpConstraint_object, JSB_cpDampedRotarySpring_class, JSB_cpDampedRotarySpring_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpDampedRotarySpring_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpDampedRotarySpring_class, JSB_cpDampedRotarySpring_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -1533,24 +1533,24 @@ JSObject* JSB_cpDampedSpring_object = NULL; bool JSB_cpDampedSpring_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==7, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpDampedSpring_class, JSB_cpDampedSpring_object, NULL); - jsval *argvp = JS_ARGV(cx,vp); + JSObject *jsobj = JS_NewObject(cx, JSB_cpDampedSpring_class, JS::RootedObject(cx, JSB_cpDampedSpring_object), JS::NullPtr()); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; cpVect arg2; cpVect arg3; double arg4; double arg5; double arg6; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg0, NULL ); - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg3 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg4 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg5 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg6 ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg0, NULL ); + ok &= jsval_to_c_class( cx, args.get(1), (void**)&arg1, NULL ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(3), (cpVect*) &arg3 ); + ok &= JS::ToNumber( cx, args.get(4), &arg4 ); + ok &= JS::ToNumber( cx, args.get(5), &arg5 ); + ok &= JS::ToNumber( cx, args.get(6), &arg6 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); void* ret_val = cpDampedSpringNew((cpBody*)arg0 , (cpBody*)arg1 , (cpVect)arg2 , (cpVect)arg3 , (cpFloat)arg4 , (cpFloat)arg5 , (cpFloat)arg6 ); jsb_set_jsobject_for_proxy(jsobj, ret_val); jsb_set_c_proxy_for_jsobject(jsobj, ret_val, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -1575,7 +1575,7 @@ void JSB_cpDampedSpring_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: cpVect bool JSB_cpDampedSpring_getAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedSpring* arg0 = (cpDampedSpring*) proxy->handle; @@ -1584,7 +1584,7 @@ bool JSB_cpDampedSpring_getAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpDampedSpringGetAnchr1((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1593,7 +1593,7 @@ bool JSB_cpDampedSpring_getAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpDampedSpring_getAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedSpring* arg0 = (cpDampedSpring*) proxy->handle; @@ -1602,7 +1602,7 @@ bool JSB_cpDampedSpring_getAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpDampedSpringGetAnchr2((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1611,14 +1611,14 @@ bool JSB_cpDampedSpring_getAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpDampedSpring_getDamping(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedSpring* arg0 = (cpDampedSpring*) proxy->handle; cpFloat ret_val; ret_val = cpDampedSpringGetDamping((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1626,14 +1626,14 @@ bool JSB_cpDampedSpring_getDamping(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpDampedSpring_getRestLength(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedSpring* arg0 = (cpDampedSpring*) proxy->handle; cpFloat ret_val; ret_val = cpDampedSpringGetRestLength((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1641,14 +1641,14 @@ bool JSB_cpDampedSpring_getRestLength(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpDampedSpring_getStiffness(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedSpring* arg0 = (cpDampedSpring*) proxy->handle; cpFloat ret_val; ret_val = cpDampedSpringGetStiffness((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1660,15 +1660,15 @@ bool JSB_cpDampedSpring_setAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedSpring* arg0 = (cpDampedSpring*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedSpringSetAnchr1((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1680,15 +1680,15 @@ bool JSB_cpDampedSpring_setAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedSpring* arg0 = (cpDampedSpring*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedSpringSetAnchr2((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1700,15 +1700,15 @@ bool JSB_cpDampedSpring_setDamping(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedSpring* arg0 = (cpDampedSpring*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedSpringSetDamping((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1720,15 +1720,15 @@ bool JSB_cpDampedSpring_setRestLength(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedSpring* arg0 = (cpDampedSpring*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedSpringSetRestLength((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1740,19 +1740,19 @@ bool JSB_cpDampedSpring_setStiffness(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpDampedSpring* arg0 = (cpDampedSpring*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedSpringSetStiffness((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -void JSB_cpDampedSpring_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpDampedSpring_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpDampedSpring_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpDampedSpring_class->name = name; @@ -1767,7 +1767,7 @@ void JSB_cpDampedSpring_createClass(JSContext *cx, JSObject* globalObj, const ch JSB_cpDampedSpring_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getAnchr1", JSB_cpDampedSpring_getAnchr1, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -1786,7 +1786,7 @@ void JSB_cpDampedSpring_createClass(JSContext *cx, JSObject* globalObj, const ch JS_FS_END }; - JSB_cpDampedSpring_object = JS_InitClass(cx, globalObj, JSB_cpConstraint_object, JSB_cpDampedSpring_class, JSB_cpDampedSpring_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpDampedSpring_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpDampedSpring_class, JSB_cpDampedSpring_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -1803,21 +1803,21 @@ JSObject* JSB_cpRatchetJoint_object = NULL; bool JSB_cpRatchetJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==4, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpRatchetJoint_class, JSB_cpRatchetJoint_object, NULL); - jsval *argvp = JS_ARGV(cx,vp); + JSObject *jsobj = JS_NewObject(cx, JSB_cpRatchetJoint_class, JS::RootedObject(cx, JSB_cpRatchetJoint_object), JS::NullPtr()); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; double arg2; double arg3; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg0, NULL ); - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg3 ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg0, NULL ); + ok &= jsval_to_c_class( cx, args.get(1), (void**)&arg1, NULL ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); + ok &= JS::ToNumber( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); void* ret_val = cpRatchetJointNew((cpBody*)arg0 , (cpBody*)arg1 , (cpFloat)arg2 , (cpFloat)arg3 ); jsb_set_jsobject_for_proxy(jsobj, ret_val); jsb_set_c_proxy_for_jsobject(jsobj, ret_val, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -1842,14 +1842,14 @@ void JSB_cpRatchetJoint_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: cpFloat bool JSB_cpRatchetJoint_getAngle(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpRatchetJoint* arg0 = (cpRatchetJoint*) proxy->handle; cpFloat ret_val; ret_val = cpRatchetJointGetAngle((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1857,14 +1857,14 @@ bool JSB_cpRatchetJoint_getAngle(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpRatchetJoint_getPhase(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpRatchetJoint* arg0 = (cpRatchetJoint*) proxy->handle; cpFloat ret_val; ret_val = cpRatchetJointGetPhase((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1872,14 +1872,14 @@ bool JSB_cpRatchetJoint_getPhase(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpRatchetJoint_getRatchet(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpRatchetJoint* arg0 = (cpRatchetJoint*) proxy->handle; cpFloat ret_val; ret_val = cpRatchetJointGetRatchet((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1891,15 +1891,15 @@ bool JSB_cpRatchetJoint_setAngle(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpRatchetJoint* arg0 = (cpRatchetJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpRatchetJointSetAngle((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1911,15 +1911,15 @@ bool JSB_cpRatchetJoint_setPhase(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpRatchetJoint* arg0 = (cpRatchetJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpRatchetJointSetPhase((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1931,19 +1931,19 @@ bool JSB_cpRatchetJoint_setRatchet(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpRatchetJoint* arg0 = (cpRatchetJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpRatchetJointSetRatchet((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -void JSB_cpRatchetJoint_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpRatchetJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpRatchetJoint_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpRatchetJoint_class->name = name; @@ -1958,7 +1958,7 @@ void JSB_cpRatchetJoint_createClass(JSContext *cx, JSObject* globalObj, const ch JSB_cpRatchetJoint_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getAngle", JSB_cpRatchetJoint_getAngle, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -1973,7 +1973,7 @@ void JSB_cpRatchetJoint_createClass(JSContext *cx, JSObject* globalObj, const ch JS_FS_END }; - JSB_cpRatchetJoint_object = JS_InitClass(cx, globalObj, JSB_cpConstraint_object, JSB_cpRatchetJoint_class, JSB_cpRatchetJoint_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpRatchetJoint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpRatchetJoint_class, JSB_cpRatchetJoint_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -1990,21 +1990,21 @@ JSObject* JSB_cpRotaryLimitJoint_object = NULL; bool JSB_cpRotaryLimitJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==4, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpRotaryLimitJoint_class, JSB_cpRotaryLimitJoint_object, NULL); - jsval *argvp = JS_ARGV(cx,vp); + JSObject *jsobj = JS_NewObject(cx, JSB_cpRotaryLimitJoint_class, JS::RootedObject(cx, JSB_cpRotaryLimitJoint_object), JS::NullPtr()); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; double arg2; double arg3; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg0, NULL ); - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg3 ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg0, NULL ); + ok &= jsval_to_c_class( cx, args.get(1), (void**)&arg1, NULL ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); + ok &= JS::ToNumber( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); void* ret_val = cpRotaryLimitJointNew((cpBody*)arg0 , (cpBody*)arg1 , (cpFloat)arg2 , (cpFloat)arg3 ); jsb_set_jsobject_for_proxy(jsobj, ret_val); jsb_set_c_proxy_for_jsobject(jsobj, ret_val, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -2029,14 +2029,14 @@ void JSB_cpRotaryLimitJoint_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: cpFloat bool JSB_cpRotaryLimitJoint_getMax(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpRotaryLimitJoint* arg0 = (cpRotaryLimitJoint*) proxy->handle; cpFloat ret_val; ret_val = cpRotaryLimitJointGetMax((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2044,14 +2044,14 @@ bool JSB_cpRotaryLimitJoint_getMax(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpRotaryLimitJoint_getMin(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpRotaryLimitJoint* arg0 = (cpRotaryLimitJoint*) proxy->handle; cpFloat ret_val; ret_val = cpRotaryLimitJointGetMin((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2063,15 +2063,15 @@ bool JSB_cpRotaryLimitJoint_setMax(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpRotaryLimitJoint* arg0 = (cpRotaryLimitJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpRotaryLimitJointSetMax((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2083,19 +2083,19 @@ bool JSB_cpRotaryLimitJoint_setMin(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpRotaryLimitJoint* arg0 = (cpRotaryLimitJoint*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpRotaryLimitJointSetMin((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -void JSB_cpRotaryLimitJoint_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpRotaryLimitJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpRotaryLimitJoint_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpRotaryLimitJoint_class->name = name; @@ -2110,7 +2110,7 @@ void JSB_cpRotaryLimitJoint_createClass(JSContext *cx, JSObject* globalObj, cons JSB_cpRotaryLimitJoint_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getMax", JSB_cpRotaryLimitJoint_getMax, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -2123,7 +2123,7 @@ void JSB_cpRotaryLimitJoint_createClass(JSContext *cx, JSObject* globalObj, cons JS_FS_END }; - JSB_cpRotaryLimitJoint_object = JS_InitClass(cx, globalObj, JSB_cpConstraint_object, JSB_cpRotaryLimitJoint_class, JSB_cpRotaryLimitJoint_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpRotaryLimitJoint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpRotaryLimitJoint_class, JSB_cpRotaryLimitJoint_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -2165,14 +2165,14 @@ void JSB_cpArbiter_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: int bool JSB_cpArbiter_getCount(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; int ret_val; ret_val = cpArbiterGetCount((cpArbiter*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -2184,16 +2184,16 @@ bool JSB_cpArbiter_getDepth(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg1; - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpArbiterGetDepth((cpArbiter*)arg0 , (int)arg1 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2201,14 +2201,14 @@ bool JSB_cpArbiter_getDepth(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpArbiter_getElasticity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; cpFloat ret_val; ret_val = cpArbiterGetElasticity((cpArbiter*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2216,14 +2216,14 @@ bool JSB_cpArbiter_getElasticity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpArbiter_getFriction(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; cpFloat ret_val; ret_val = cpArbiterGetFriction((cpArbiter*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2235,18 +2235,18 @@ bool JSB_cpArbiter_getNormal(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg1; - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpArbiterGetNormal((cpArbiter*)arg0 , (int)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2259,18 +2259,18 @@ bool JSB_cpArbiter_getPoint(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg1; - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpArbiterGetPoint((cpArbiter*)arg0 , (int)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2279,7 +2279,7 @@ bool JSB_cpArbiter_getPoint(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpArbiter_getSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; @@ -2288,7 +2288,7 @@ bool JSB_cpArbiter_getSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpArbiterGetSurfaceVelocity((cpArbiter*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2297,13 +2297,13 @@ bool JSB_cpArbiter_getSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpArbiter_ignore(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; cpArbiterIgnore((cpArbiter*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2311,14 +2311,14 @@ bool JSB_cpArbiter_ignore(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpArbiter_isFirstContact(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; cpBool ret_val; ret_val = cpArbiterIsFirstContact((cpArbiter*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -2330,15 +2330,15 @@ bool JSB_cpArbiter_setElasticity(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpArbiterSetElasticity((cpArbiter*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2350,15 +2350,15 @@ bool JSB_cpArbiter_setFriction(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpArbiterSetFriction((cpArbiter*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2370,15 +2370,15 @@ bool JSB_cpArbiter_setSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpArbiterSetSurfaceVelocity((cpArbiter*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2386,7 +2386,7 @@ bool JSB_cpArbiter_setSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpArbiter_totalImpulse(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; @@ -2395,7 +2395,7 @@ bool JSB_cpArbiter_totalImpulse(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpArbiterTotalImpulse((cpArbiter*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2404,7 +2404,7 @@ bool JSB_cpArbiter_totalImpulse(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpArbiter_totalImpulseWithFriction(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; @@ -2413,7 +2413,7 @@ bool JSB_cpArbiter_totalImpulseWithFriction(JSContext *cx, uint32_t argc, jsval ret_val = cpArbiterTotalImpulseWithFriction((cpArbiter*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2422,74 +2422,78 @@ bool JSB_cpArbiter_totalImpulseWithFriction(JSContext *cx, uint32_t argc, jsval // Ret value: cpFloat bool JSB_cpArbiter_totalKE(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpArbiter* arg0 = (cpArbiter*) proxy->handle; cpFloat ret_val; ret_val = cpArbiterTotalKE((cpArbiter*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } -bool js_get_cpArbiter_a(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +bool js_get_cpArbiter_a(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpArbiter* arbiter = (cpArbiter*) proxy->handle; cpShape* shape = arbiter->a; if(shape){ JSObject* jsobj = jsb_get_jsobject_for_proxy(shape); if(jsobj){ - vp.set(OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } } return false; } -bool js_get_cpArbiter_b(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +bool js_get_cpArbiter_b(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpArbiter* arbiter = (cpArbiter*) proxy->handle; cpShape* shape = arbiter->b; if(shape){ JSObject* jsobj = jsb_get_jsobject_for_proxy(shape); if(jsobj){ - vp.set(OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } } return false; } -bool js_get_cpArbiter_body_a(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +bool js_get_cpArbiter_body_a(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpArbiter* arbiter = (cpArbiter*) proxy->handle; cpBody* body = arbiter->body_a; if(body){ JSObject* jsobj = jsb_get_jsobject_for_proxy(body); if(jsobj){ - vp.set(OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } } return false; } -bool js_get_cpArbiter_body_b(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +bool js_get_cpArbiter_body_b(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpArbiter* arbiter = (cpArbiter*) proxy->handle; cpBody* body = arbiter->body_b; if(body){ JSObject* jsobj = jsb_get_jsobject_for_proxy(body); if(jsobj){ - vp.set(OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } } return false; } -void JSB_cpArbiter_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpArbiter_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpArbiter_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpArbiter_class->name = name; @@ -2504,11 +2508,11 @@ void JSB_cpArbiter_createClass(JSContext *cx, JSObject* globalObj, const char* n JSB_cpArbiter_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {"a", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpArbiter_a), JSOP_NULLWRAPPER}, - {"b", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpArbiter_b), JSOP_NULLWRAPPER}, - {"body_a", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpArbiter_body_a), JSOP_NULLWRAPPER}, - {"body_b", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpArbiter_body_b), JSOP_NULLWRAPPER}, - {0, 0, 0, 0, 0} + JS_PSG("a", js_get_cpArbiter_a, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSG("b", js_get_cpArbiter_b, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSG("body_a", js_get_cpArbiter_body_a, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSG("body_b", js_get_cpArbiter_body_b, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getCount", JSB_cpArbiter_getCount, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -2534,7 +2538,7 @@ void JSB_cpArbiter_createClass(JSContext *cx, JSObject* globalObj, const char* n JS_FS_END }; - JSB_cpArbiter_object = JS_InitClass(cx, globalObj, JSB_cpBase_object, JSB_cpArbiter_class, JSB_cpArbiter_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpArbiter_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpBase_object), JSB_cpArbiter_class, JSB_cpArbiter_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -2551,12 +2555,14 @@ JSObject* JSB_cpSpace_object = NULL; bool JSB_cpSpace_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==0, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpSpace_class, JSB_cpSpace_object, NULL); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + //JSObject* jsobj = JS_NewObjectForConstructor(cx, JSB_cpSpace_class, args); + JSObject *jsobj = JS_NewObject(cx, JSB_cpSpace_class, JS::RootedObject(cx, JSB_cpSpace_object), JS::NullPtr()); void* ret_val = cpSpaceNew( ); jsb_set_jsobject_for_proxy(jsobj, ret_val); jsb_set_c_proxy_for_jsobject(jsobj, ret_val, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -2569,15 +2575,15 @@ bool JSB_cpSpace_activateShapesTouchingShape(JSContext *cx, uint32_t argc, jsval JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg1; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, NULL ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceActivateShapesTouchingShape((cpSpace*)arg0 , (cpShape*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2589,16 +2595,16 @@ bool JSB_cpSpace_containsBody(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg1; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, NULL ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpSpaceContainsBody((cpSpace*)arg0 , (cpBody*)arg1 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -2610,16 +2616,16 @@ bool JSB_cpSpace_containsConstraint(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg1; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, NULL ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpSpaceContainsConstraint((cpSpace*)arg0 , (cpConstraint*)arg1 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -2631,16 +2637,16 @@ bool JSB_cpSpace_containsShape(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg1; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, NULL ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpSpaceContainsShape((cpSpace*)arg0 , (cpShape*)arg1 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -2648,13 +2654,13 @@ bool JSB_cpSpace_containsShape(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpace_destroy(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; cpSpaceDestroy((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2662,14 +2668,14 @@ bool JSB_cpSpace_destroy(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSpace_getCollisionBias(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; cpFloat ret_val; ret_val = cpSpaceGetCollisionBias((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2677,14 +2683,14 @@ bool JSB_cpSpace_getCollisionBias(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpTimestamp bool JSB_cpSpace_getCollisionPersistence(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; cpTimestamp ret_val; ret_val = cpSpaceGetCollisionPersistence((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, UINT_TO_JSVAL((uint32_t)ret_val)); + args.rval().set(UINT_TO_JSVAL((uint32_t)ret_val)); return true; } @@ -2692,14 +2698,14 @@ bool JSB_cpSpace_getCollisionPersistence(JSContext *cx, uint32_t argc, jsval *vp // Ret value: cpFloat bool JSB_cpSpace_getCollisionSlop(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; cpFloat ret_val; ret_val = cpSpaceGetCollisionSlop((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2707,14 +2713,14 @@ bool JSB_cpSpace_getCollisionSlop(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSpace_getCurrentTimeStep(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; cpFloat ret_val; ret_val = cpSpaceGetCurrentTimeStep((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2722,14 +2728,14 @@ bool JSB_cpSpace_getCurrentTimeStep(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSpace_getDamping(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; cpFloat ret_val; ret_val = cpSpaceGetDamping((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2737,14 +2743,14 @@ bool JSB_cpSpace_getDamping(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpSpace_getEnableContactGraph(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; cpBool ret_val; ret_val = cpSpaceGetEnableContactGraph((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -2752,7 +2758,7 @@ bool JSB_cpSpace_getEnableContactGraph(JSContext *cx, uint32_t argc, jsval *vp) // Ret value: cpVect bool JSB_cpSpace_getGravity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; @@ -2761,7 +2767,7 @@ bool JSB_cpSpace_getGravity(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpSpaceGetGravity((cpSpace*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2770,14 +2776,14 @@ bool JSB_cpSpace_getGravity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSpace_getIdleSpeedThreshold(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; cpFloat ret_val; ret_val = cpSpaceGetIdleSpeedThreshold((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2785,14 +2791,14 @@ bool JSB_cpSpace_getIdleSpeedThreshold(JSContext *cx, uint32_t argc, jsval *vp) // Ret value: int bool JSB_cpSpace_getIterations(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; int ret_val; ret_val = cpSpaceGetIterations((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -2800,14 +2806,14 @@ bool JSB_cpSpace_getIterations(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSpace_getSleepTimeThreshold(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; cpFloat ret_val; ret_val = cpSpaceGetSleepTimeThreshold((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2815,7 +2821,7 @@ bool JSB_cpSpace_getSleepTimeThreshold(JSContext *cx, uint32_t argc, jsval *vp) // Ret value: cpBody* bool JSB_cpSpace_getStaticBody(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; @@ -2823,8 +2829,8 @@ bool JSB_cpSpace_getStaticBody(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpSpaceGetStaticBody((cpSpace*)arg0 ); - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JSB_cpBody_object, JSB_cpBody_class, "cpBody" ); - JS_SET_RVAL(cx, vp, ret_jsval); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpBody" ); + args.rval().set(ret_jsval); return true; } @@ -2833,7 +2839,7 @@ bool JSB_cpSpace_getStaticBody(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpSpace* bool JSB_cpSpace_init(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; @@ -2841,8 +2847,8 @@ bool JSB_cpSpace_init(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpSpaceInit((cpSpace*)arg0 ); - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JSB_cpSpace_object, JSB_cpSpace_class, "cpSpace" ); - JS_SET_RVAL(cx, vp, ret_jsval); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpSpace" ); + args.rval().set(ret_jsval); return true; } @@ -2851,14 +2857,14 @@ bool JSB_cpSpace_init(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpSpace_isLocked(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; cpBool ret_val; ret_val = cpSpaceIsLocked((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -2870,23 +2876,23 @@ bool JSB_cpSpace_pointQueryFirst(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; uint32_t arg2; cpGroup arg3; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg2 ); - ok &= jsval_to_uint( cx, *argvp++, (unsigned int*) &arg3 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg2 ); + ok &= jsval_to_uint( cx, args.get(2), (unsigned int*) &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShape* ret_val; ret_val = cpSpacePointQueryFirst((cpSpace*)arg0 , (cpVect)arg1 , (cpLayers)arg2 , (cpGroup)arg3 ); if(ret_val) { - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JSB_cpShape_object, JSB_cpShape_class, "cpShape" ); - JS_SET_RVAL(cx, vp, ret_jsval); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpShape_object), JSB_cpShape_class, "cpShape" ); + args.rval().set(ret_jsval); } else { - JS_SET_RVAL(cx, vp, JSVAL_NULL); + args.rval().set(JSVAL_NULL); } return true; } @@ -2898,15 +2904,15 @@ bool JSB_cpSpace_reindexShape(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg1; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, NULL ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceReindexShape((cpSpace*)arg0 , (cpShape*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2918,15 +2924,15 @@ bool JSB_cpSpace_reindexShapesForBody(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg1; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, NULL ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceReindexShapesForBody((cpSpace*)arg0 , (cpBody*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2934,13 +2940,13 @@ bool JSB_cpSpace_reindexShapesForBody(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpace_reindexStatic(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; cpSpaceReindexStatic((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2952,15 +2958,15 @@ bool JSB_cpSpace_setCollisionBias(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetCollisionBias((cpSpace*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2972,15 +2978,15 @@ bool JSB_cpSpace_setCollisionPersistence(JSContext *cx, uint32_t argc, jsval *vp JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetCollisionPersistence((cpSpace*)arg0 , (cpTimestamp)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2992,15 +2998,15 @@ bool JSB_cpSpace_setCollisionSlop(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetCollisionSlop((cpSpace*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3012,15 +3018,15 @@ bool JSB_cpSpace_setDamping(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetDamping((cpSpace*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3032,15 +3038,15 @@ bool JSB_cpSpace_setEnableContactGraph(JSContext *cx, uint32_t argc, jsval *vp) JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg1; - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetEnableContactGraph((cpSpace*)arg0 , (cpBool)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3052,15 +3058,15 @@ bool JSB_cpSpace_setGravity(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetGravity((cpSpace*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3072,15 +3078,15 @@ bool JSB_cpSpace_setIdleSpeedThreshold(JSContext *cx, uint32_t argc, jsval *vp) JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetIdleSpeedThreshold((cpSpace*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3092,15 +3098,15 @@ bool JSB_cpSpace_setIterations(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg1; - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetIterations((cpSpace*)arg0 , (int)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3112,15 +3118,15 @@ bool JSB_cpSpace_setSleepTimeThreshold(JSContext *cx, uint32_t argc, jsval *vp) JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetSleepTimeThreshold((cpSpace*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3132,15 +3138,15 @@ bool JSB_cpSpace_step(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceStep((cpSpace*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3152,21 +3158,21 @@ bool JSB_cpSpace_useSpatialHash(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; int32_t arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); + ok &= jsval_to_int32( cx, args.get(1), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceUseSpatialHash((cpSpace*)arg0 , (cpFloat)arg1 , (int)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -void JSB_cpSpace_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpSpace_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpSpace_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpSpace_class->name = name; @@ -3239,7 +3245,7 @@ void JSB_cpSpace_createClass(JSContext *cx, JSObject* globalObj, const char* nam JS_FS_END }; - JSB_cpSpace_object = JS_InitClass(cx, globalObj, JSB_cpBase_object, JSB_cpSpace_class, JSB_cpSpace_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpSpace_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpBase_object), JSB_cpSpace_class, JSB_cpSpace_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -3272,13 +3278,13 @@ void JSB_cpBody_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: void bool JSB_cpBody_activate(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpBodyActivate((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3290,15 +3296,15 @@ bool JSB_cpBody_activateStatic(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg1; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, NULL ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodyActivateStatic((cpBody*)arg0 , (cpShape*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3310,16 +3316,16 @@ bool JSB_cpBody_applyForce(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; cpVect arg2; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodyApplyForce((cpBody*)arg0 , (cpVect)arg1 , (cpVect)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3331,16 +3337,16 @@ bool JSB_cpBody_applyImpulse(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; cpVect arg2; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodyApplyImpulse((cpBody*)arg0 , (cpVect)arg1 , (cpVect)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3348,13 +3354,13 @@ bool JSB_cpBody_applyImpulse(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBody_destroy(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpBodyDestroy((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3362,14 +3368,14 @@ bool JSB_cpBody_destroy(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBody_getAngVel(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpFloat ret_val; ret_val = cpBodyGetAngVel((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3377,14 +3383,14 @@ bool JSB_cpBody_getAngVel(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBody_getAngVelLimit(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpFloat ret_val; ret_val = cpBodyGetAngVelLimit((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3392,14 +3398,14 @@ bool JSB_cpBody_getAngVelLimit(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBody_getAngle(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpFloat ret_val; ret_val = cpBodyGetAngle((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3407,7 +3413,7 @@ bool JSB_cpBody_getAngle(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpBody_getForce(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; @@ -3416,7 +3422,7 @@ bool JSB_cpBody_getForce(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpBodyGetForce((cpBody*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3425,14 +3431,14 @@ bool JSB_cpBody_getForce(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBody_getMass(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpFloat ret_val; ret_val = cpBodyGetMass((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3440,14 +3446,14 @@ bool JSB_cpBody_getMass(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBody_getMoment(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpFloat ret_val; ret_val = cpBodyGetMoment((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3455,7 +3461,7 @@ bool JSB_cpBody_getMoment(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpBody_getPos(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; @@ -3464,7 +3470,7 @@ bool JSB_cpBody_getPos(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpBodyGetPos((cpBody*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3473,7 +3479,7 @@ bool JSB_cpBody_getPos(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpBody_getRot(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; @@ -3482,7 +3488,7 @@ bool JSB_cpBody_getRot(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpBodyGetRot((cpBody*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3491,7 +3497,7 @@ bool JSB_cpBody_getRot(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpSpace* bool JSB_cpBody_getSpace(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; @@ -3499,8 +3505,8 @@ bool JSB_cpBody_getSpace(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpBodyGetSpace((cpBody*)arg0 ); - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JSB_cpSpace_object, JSB_cpSpace_class, "cpSpace" ); - JS_SET_RVAL(cx, vp, ret_jsval); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpSpace" ); + args.rval().set(ret_jsval); return true; } @@ -3509,14 +3515,14 @@ bool JSB_cpBody_getSpace(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBody_getTorque(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpFloat ret_val; ret_val = cpBodyGetTorque((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3524,7 +3530,7 @@ bool JSB_cpBody_getTorque(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpBody_getVel(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; @@ -3533,7 +3539,7 @@ bool JSB_cpBody_getVel(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpBodyGetVel((cpBody*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3546,18 +3552,18 @@ bool JSB_cpBody_getVelAtLocalPoint(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpBodyGetVelAtLocalPoint((cpBody*)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3570,18 +3576,18 @@ bool JSB_cpBody_getVelAtWorldPoint(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpBodyGetVelAtWorldPoint((cpBody*)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3590,14 +3596,14 @@ bool JSB_cpBody_getVelAtWorldPoint(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBody_getVelLimit(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpFloat ret_val; ret_val = cpBodyGetVelLimit((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3609,19 +3615,19 @@ bool JSB_cpBody_init(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); + ok &= JS::ToNumber( cx, args.get(1), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBody* ret_val; ret_val = cpBodyInit((cpBody*)arg0 , (cpFloat)arg1 , (cpFloat)arg2 ); - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JSB_cpBody_object, JSB_cpBody_class, "cpBody" ); - JS_SET_RVAL(cx, vp, ret_jsval); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpBody" ); + args.rval().set(ret_jsval); return true; } @@ -3630,7 +3636,7 @@ bool JSB_cpBody_init(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBody* bool JSB_cpBody_initStatic(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; @@ -3638,8 +3644,8 @@ bool JSB_cpBody_initStatic(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpBodyInitStatic((cpBody*)arg0 ); - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JSB_cpBody_object, JSB_cpBody_class, "cpBody" ); - JS_SET_RVAL(cx, vp, ret_jsval); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpBody" ); + args.rval().set(ret_jsval); return true; } @@ -3648,14 +3654,14 @@ bool JSB_cpBody_initStatic(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpBody_isRogue(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpBool ret_val; ret_val = cpBodyIsRogue((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -3663,14 +3669,14 @@ bool JSB_cpBody_isRogue(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpBody_isSleeping(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpBool ret_val; ret_val = cpBodyIsSleeping((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -3678,14 +3684,14 @@ bool JSB_cpBody_isSleeping(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpBody_isStatic(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpBool ret_val; ret_val = cpBodyIsStatic((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -3693,14 +3699,14 @@ bool JSB_cpBody_isStatic(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBody_kineticEnergy(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpFloat ret_val; ret_val = cpBodyKineticEnergy((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3712,18 +3718,18 @@ bool JSB_cpBody_local2World(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpBodyLocal2World((cpBody*)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3732,13 +3738,13 @@ bool JSB_cpBody_local2World(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBody_resetForces(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpBodyResetForces((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3750,15 +3756,15 @@ bool JSB_cpBody_setAngVel(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetAngVel((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3770,15 +3776,15 @@ bool JSB_cpBody_setAngVelLimit(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetAngVelLimit((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3790,15 +3796,15 @@ bool JSB_cpBody_setAngle(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetAngle((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3810,15 +3816,15 @@ bool JSB_cpBody_setForce(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetForce((cpBody*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3830,15 +3836,15 @@ bool JSB_cpBody_setMass(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetMass((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3850,15 +3856,15 @@ bool JSB_cpBody_setMoment(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetMoment((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3870,15 +3876,15 @@ bool JSB_cpBody_setPos(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetPos((cpBody*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3890,15 +3896,15 @@ bool JSB_cpBody_setTorque(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetTorque((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3910,15 +3916,15 @@ bool JSB_cpBody_setVel(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetVel((cpBody*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3930,15 +3936,15 @@ bool JSB_cpBody_setVelLimit(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetVelLimit((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3946,13 +3952,13 @@ bool JSB_cpBody_setVelLimit(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBody_sleep(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; cpBodySleep((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3964,15 +3970,15 @@ bool JSB_cpBody_sleepWithGroup(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg1; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, NULL ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySleepWithGroup((cpBody*)arg0 , (cpBody*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3984,15 +3990,15 @@ bool JSB_cpBody_updatePosition(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodyUpdatePosition((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4004,17 +4010,17 @@ bool JSB_cpBody_updateVelocity(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; double arg2; double arg3; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg3 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); + ok &= JS::ToNumber( cx, args.get(1), &arg2 ); + ok &= JS::ToNumber( cx, args.get(2), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodyUpdateVelocity((cpBody*)arg0 , (cpVect)arg1 , (cpFloat)arg2 , (cpFloat)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4026,55 +4032,59 @@ bool JSB_cpBody_world2Local(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* arg0 = (cpBody*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpBodyWorld2Local((cpBody*)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } -bool js_get_cpBody_vx(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +bool js_get_cpBody_vx(JSContext *cx, uint32_t argc, jsval *vp) { - jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpBody* body = (cpBody*) proxy->handle; - vp.set(DOUBLE_TO_JSVAL(body->v.x)); + args.rval().set(DOUBLE_TO_JSVAL(body->v.x)); return true; } -bool js_get_cpBody_vy(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +bool js_get_cpBody_vy(JSContext *cx, uint32_t argc, jsval *vp) { - jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpBody* body = (cpBody*) proxy->handle; - vp.set(DOUBLE_TO_JSVAL(body->v.y)); + args.rval().set(DOUBLE_TO_JSVAL(body->v.y)); return true; } -bool js_get_cpBody_inverse_m(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +bool js_get_cpBody_inverse_m(JSContext *cx, uint32_t argc, jsval *vp) { - jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpBody* body = (cpBody*) proxy->handle; - vp.set(DOUBLE_TO_JSVAL(body->m_inv)); + args.rval().set(DOUBLE_TO_JSVAL(body->m_inv)); return true; } -bool js_get_cpBody_inverse_i(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +bool js_get_cpBody_inverse_i(JSContext *cx, uint32_t argc, jsval *vp) { - jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpBody* body = (cpBody*) proxy->handle; - vp.set(DOUBLE_TO_JSVAL(body->i_inv)); + args.rval().set(DOUBLE_TO_JSVAL(body->i_inv)); return true; } -void JSB_cpBody_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpBody_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpBody_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpBody_class->name = name; @@ -4089,11 +4099,11 @@ void JSB_cpBody_createClass(JSContext *cx, JSObject* globalObj, const char* name JSB_cpBody_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {"vx", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpBody_vx), JSOP_NULLWRAPPER}, - {"vy", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpBody_vy), JSOP_NULLWRAPPER}, - {"m_inv", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpBody_inverse_m), JSOP_NULLWRAPPER}, - {"i_inv", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpBody_inverse_i), JSOP_NULLWRAPPER}, - {0, 0, 0, 0, 0} + JS_PSG("vx", js_get_cpBody_vx, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSG("vy", js_get_cpBody_vy, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSG("m_inv", js_get_cpBody_inverse_m, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSG("i_inv", js_get_cpBody_inverse_i, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("activate", JSB_cpBody_activate, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -4149,7 +4159,7 @@ void JSB_cpBody_createClass(JSContext *cx, JSObject* globalObj, const char* name JS_FS_END }; - JSB_cpBody_object = JS_InitClass(cx, globalObj, JSB_cpBase_object, JSB_cpBody_class, JSB_cpBody_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpBody_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpBase_object), JSB_cpBody_class, JSB_cpBody_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -4191,7 +4201,7 @@ void JSB_cpShape_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: cpBB bool JSB_cpShape_cacheBB(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; @@ -4200,7 +4210,7 @@ bool JSB_cpShape_cacheBB(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpShapeCacheBB((cpShape*)arg0 ); jsval ret_jsval = cpBB_to_jsval( cx, (cpBB)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4209,13 +4219,13 @@ bool JSB_cpShape_cacheBB(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpShape_destroy(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; cpShapeDestroy((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4223,7 +4233,7 @@ bool JSB_cpShape_destroy(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBB bool JSB_cpShape_getBB(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; @@ -4232,7 +4242,7 @@ bool JSB_cpShape_getBB(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpShapeGetBB((cpShape*)arg0 ); jsval ret_jsval = cpBB_to_jsval( cx, (cpBB)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4241,7 +4251,7 @@ bool JSB_cpShape_getBB(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBody* bool JSB_cpShape_getBody(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; @@ -4249,8 +4259,8 @@ bool JSB_cpShape_getBody(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpShapeGetBody((cpShape*)arg0 ); - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JSB_cpBody_object, JSB_cpBody_class, "cpBody" ); - JS_SET_RVAL(cx, vp, ret_jsval); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpBody" ); + args.rval().set(ret_jsval); return true; } @@ -4259,7 +4269,7 @@ bool JSB_cpShape_getBody(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpCollisionType bool JSB_cpShape_getCollisionType(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; @@ -4268,7 +4278,7 @@ bool JSB_cpShape_getCollisionType(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpShapeGetCollisionType((cpShape*)arg0 ); jsval ret_jsval = uint32_to_jsval( cx, (cpCollisionType)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4277,14 +4287,14 @@ bool JSB_cpShape_getCollisionType(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpShape_getElasticity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; cpFloat ret_val; ret_val = cpShapeGetElasticity((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4292,14 +4302,14 @@ bool JSB_cpShape_getElasticity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpShape_getFriction(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; cpFloat ret_val; ret_val = cpShapeGetFriction((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4307,7 +4317,7 @@ bool JSB_cpShape_getFriction(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpGroup bool JSB_cpShape_getGroup(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; @@ -4316,7 +4326,7 @@ bool JSB_cpShape_getGroup(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpShapeGetGroup((cpShape*)arg0 ); jsval ret_jsval = uint32_to_jsval( cx, (cpGroup)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4325,14 +4335,14 @@ bool JSB_cpShape_getGroup(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpLayers bool JSB_cpShape_getLayers(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; cpLayers ret_val; ret_val = cpShapeGetLayers((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, UINT_TO_JSVAL((uint32_t)ret_val)); + args.rval().set(UINT_TO_JSVAL((uint32_t)ret_val)); return true; } @@ -4340,14 +4350,14 @@ bool JSB_cpShape_getLayers(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpShape_getSensor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; cpBool ret_val; ret_val = cpShapeGetSensor((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -4355,7 +4365,7 @@ bool JSB_cpShape_getSensor(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpSpace* bool JSB_cpShape_getSpace(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; @@ -4363,8 +4373,8 @@ bool JSB_cpShape_getSpace(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpShapeGetSpace((cpShape*)arg0 ); - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JSB_cpSpace_object, JSB_cpSpace_class, "cpSpace" ); - JS_SET_RVAL(cx, vp, ret_jsval); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpSpace" ); + args.rval().set(ret_jsval); return true; } @@ -4373,7 +4383,7 @@ bool JSB_cpShape_getSpace(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpShape_getSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; @@ -4382,7 +4392,7 @@ bool JSB_cpShape_getSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpShapeGetSurfaceVelocity((cpShape*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4395,16 +4405,16 @@ bool JSB_cpShape_pointQuery(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpShapePointQuery((cpShape*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -4416,15 +4426,15 @@ bool JSB_cpShape_setBody(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg1; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, NULL ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, NULL ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetBody((cpShape*)arg0 , (cpBody*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4436,15 +4446,15 @@ bool JSB_cpShape_setCollisionType(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpCollisionType arg1; - ok &= jsval_to_uint( cx, *argvp++, (unsigned int*) &arg1 ); + ok &= jsval_to_uint( cx, args.get(0), (unsigned int*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetCollisionType((cpShape*)arg0 , (cpCollisionType)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4456,15 +4466,15 @@ bool JSB_cpShape_setElasticity(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetElasticity((cpShape*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4476,15 +4486,15 @@ bool JSB_cpShape_setFriction(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetFriction((cpShape*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4496,15 +4506,15 @@ bool JSB_cpShape_setGroup(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpGroup arg1; - ok &= jsval_to_uint( cx, *argvp++, (unsigned int*) &arg1 ); + ok &= jsval_to_uint( cx, args.get(0), (unsigned int*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetGroup((cpShape*)arg0 , (cpGroup)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4516,15 +4526,15 @@ bool JSB_cpShape_setLayers(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetLayers((cpShape*)arg0 , (cpLayers)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4536,15 +4546,15 @@ bool JSB_cpShape_setSensor(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg1; - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetSensor((cpShape*)arg0 , (cpBool)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4556,15 +4566,15 @@ bool JSB_cpShape_setSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetSurfaceVelocity((cpShape*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4576,19 +4586,19 @@ bool JSB_cpShape_update(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; cpVect arg2; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBB ret_val; ret_val = cpShapeUpdate((cpShape*)arg0 , (cpVect)arg1 , (cpVect)arg2 ); jsval ret_jsval = cpBB_to_jsval( cx, (cpBB)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4597,14 +4607,14 @@ bool JSB_cpShape_update(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpShape_active(JSContext *cx, uint32_t argc, jsval *vp){ JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* arg0 = (cpShape*) proxy->handle; bool active = cpShapeActive(arg0); jsval retval = BOOLEAN_TO_JSVAL(active); - JS_SET_RVAL(cx, vp, retval); + args.rval().set(retval); return true; } @@ -4615,18 +4625,18 @@ bool JSB_cpShape_nearestPointQuery(JSContext *cx, uint32_t argc, jsval *vp) JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* shape = (cpShape*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpVect p; - bool ok = jsval_to_cpVect(cx, argvp[0], &p); + bool ok = jsval_to_cpVect(cx, args.get(0), &p); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpNearestPointQueryInfo* info = new cpNearestPointQueryInfo(); cpShapeNearestPointQuery(shape, p, info); - JSObject *jsobj = JS_NewObject(cx, JSB_cpNearestPointQueryInfo_class, JSB_cpNearestPointQueryInfo_object, NULL); + JSObject *jsobj = JS_NewObject(cx, JSB_cpNearestPointQueryInfo_class, JS::RootedObject(cx, JSB_cpNearestPointQueryInfo_object), JS::NullPtr()); jsb_set_jsobject_for_proxy(jsobj, info); jsb_set_c_proxy_for_jsobject(jsobj, info, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -4638,86 +4648,94 @@ bool JSB_cpShape_segmentQuery(JSContext *cx, uint32_t argc, jsval *vp) JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpShape* shape = (cpShape*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpVect a; cpVect b; - bool ok = jsval_to_cpVect(cx, argvp[0], &a); - ok &= jsval_to_cpVect(cx, argvp[1], &b); + bool ok = jsval_to_cpVect(cx, args.get(0), &a); + ok &= jsval_to_cpVect(cx, args.get(1), &b); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSegmentQueryInfo* info = new cpSegmentQueryInfo(); if(cpShapeSegmentQuery(shape, a, b, info)) { - JSObject* jsobj = JS_NewObject(cx, JSB_cpSegmentQueryInfo_class, JSB_cpSegmentQueryInfo_object, NULL); + JSObject* jsobj = JS_NewObject(cx, JSB_cpSegmentQueryInfo_class, JS::RootedObject(cx, JSB_cpSegmentQueryInfo_object), JS::NullPtr()); jsb_set_jsobject_for_proxy(jsobj, info); jsb_set_c_proxy_for_jsobject(jsobj, info, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); } else { delete info; - JS_SET_RVAL(cx, vp, JSVAL_NULL); + args.rval().set(JSVAL_NULL); } return true; } -static bool js_get_cpShape_bbl(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +static bool js_get_cpShape_bbl(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpShape* shape = (cpShape*) proxy->handle; - vp.setNumber(shape->bb.l); + args.rval().setNumber(shape->bb.l); return true; } -static bool js_set_cpShape_bbl(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp){ - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +static bool js_set_cpShape_bbl(JSContext *cx, uint32_t argc, jsval *vp){ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpShape* shape = (cpShape*) proxy->handle; - shape->bb.l = JSVAL_TO_DOUBLE(vp.get()); + shape->bb.l = args.get(0).toDouble(); return true; } -static bool js_get_cpShape_bbb(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +static bool js_get_cpShape_bbb(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpShape* shape = (cpShape*) proxy->handle; - vp.setNumber(shape->bb.b); + args.rval().setNumber(shape->bb.b); return true; } -static bool js_set_cpShape_bbb(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp){ - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +static bool js_set_cpShape_bbb(JSContext *cx, uint32_t argc, jsval *vp){ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpShape* shape = (cpShape*) proxy->handle; - shape->bb.b = JSVAL_TO_DOUBLE(vp.get()); + shape->bb.b = args.get(0).toDouble(); return true; } -static bool js_get_cpShape_bbr(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +static bool js_get_cpShape_bbr(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpShape* shape = (cpShape*) proxy->handle; - vp.setNumber(shape->bb.r); + args.rval().setNumber(shape->bb.r); return true; } -static bool js_set_cpShape_bbr(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp){ - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +static bool js_set_cpShape_bbr(JSContext *cx, uint32_t argc, jsval *vp){ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpShape* shape = (cpShape*) proxy->handle; - shape->bb.r = JSVAL_TO_DOUBLE(vp.get()); + shape->bb.r = args.get(0).toDouble(); return true; } -static bool js_get_cpShape_bbt(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +static bool js_get_cpShape_bbt(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpShape* shape = (cpShape*) proxy->handle; - vp.setNumber(shape->bb.t); + args.rval().setNumber(shape->bb.t); return true; } -static bool js_set_cpShape_bbt(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp){ - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +static bool js_set_cpShape_bbt(JSContext *cx, uint32_t argc, jsval *vp){ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpShape* shape = (cpShape*) proxy->handle; - shape->bb.t = JSVAL_TO_DOUBLE(vp.get()); + shape->bb.t = args.get(0).toDouble(); return true; } -void JSB_cpShape_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpShape_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpShape_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpShape_class->name = name; @@ -4732,11 +4750,11 @@ void JSB_cpShape_createClass(JSContext *cx, JSObject* globalObj, const char* nam JSB_cpShape_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {"bb_l", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpShape_bbl), JSOP_WRAPPER(js_set_cpShape_bbl)}, - {"bb_b", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpShape_bbb), JSOP_WRAPPER(js_set_cpShape_bbb)}, - {"bb_r", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpShape_bbr), JSOP_WRAPPER(js_set_cpShape_bbr)}, - {"bb_t", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpShape_bbt), JSOP_WRAPPER(js_set_cpShape_bbt)}, - {0, 0, 0, 0, 0} + JS_PSGS("bb_l", js_get_cpShape_bbl, js_set_cpShape_bbl, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSGS("bb_b", js_get_cpShape_bbb, js_set_cpShape_bbb, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSGS("bb_r", js_get_cpShape_bbr, js_set_cpShape_bbr, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSGS("bb_t", js_get_cpShape_bbt, js_set_cpShape_bbt, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("cacheBB", JSB_cpShape_cacheBB, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -4770,7 +4788,7 @@ void JSB_cpShape_createClass(JSContext *cx, JSObject* globalObj, const char* nam JS_FS_END }; - JSB_cpShape_object = JS_InitClass(cx, globalObj, JSB_cpBase_object, JSB_cpShape_class, JSB_cpShape_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpShape_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpBase_object), JSB_cpShape_class, JSB_cpShape_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -4787,20 +4805,20 @@ JSObject* JSB_cpCircleShape_object = NULL; bool JSB_cpCircleShape_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==3, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpCircleShape_class, JSB_cpCircleShape_object, NULL); - jsval *argvp = JS_ARGV(cx,vp); + JSObject *jsobj = JS_NewObject(cx, JSB_cpCircleShape_class, JS::RootedObject(cx, JSB_cpCircleShape_object), JS::NullPtr()); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; double arg1; cpVect arg2; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg0, NULL ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg0, NULL ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); void* ret_val = cpCircleShapeNew((cpBody*)arg0 , (cpFloat)arg1 , (cpVect)arg2 ); jsb_set_jsobject_for_proxy(jsobj, ret_val); jsb_set_c_proxy_for_jsobject(jsobj, ret_val, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -4825,7 +4843,7 @@ void JSB_cpCircleShape_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: cpVect bool JSB_cpCircleShape_getOffset(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpCircleShape* arg0 = (cpCircleShape*) proxy->handle; @@ -4834,7 +4852,7 @@ bool JSB_cpCircleShape_getOffset(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpCircleShapeGetOffset((cpShape*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4843,18 +4861,18 @@ bool JSB_cpCircleShape_getOffset(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpCircleShape_getRadius(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpCircleShape* arg0 = (cpCircleShape*) proxy->handle; cpFloat ret_val; ret_val = cpCircleShapeGetRadius((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } -void JSB_cpCircleShape_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpCircleShape_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpCircleShape_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpCircleShape_class->name = name; @@ -4869,7 +4887,7 @@ void JSB_cpCircleShape_createClass(JSContext *cx, JSObject* globalObj, const cha JSB_cpCircleShape_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getOffset", JSB_cpCircleShape_getOffset, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -4880,7 +4898,7 @@ void JSB_cpCircleShape_createClass(JSContext *cx, JSObject* globalObj, const cha JS_FS_END }; - JSB_cpCircleShape_object = JS_InitClass(cx, globalObj, JSB_cpShape_object, JSB_cpCircleShape_class, JSB_cpCircleShape_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpCircleShape_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpShape_object), JSB_cpCircleShape_class, JSB_cpCircleShape_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -4897,21 +4915,21 @@ JSObject* JSB_cpSegmentShape_object = NULL; bool JSB_cpSegmentShape_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==4, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpSegmentShape_class, JSB_cpSegmentShape_object, NULL); - jsval *argvp = JS_ARGV(cx,vp); + JSObject *jsobj = JS_NewObject(cx, JSB_cpSegmentShape_class, JS::RootedObject(cx, JSB_cpSegmentShape_object), JS::NullPtr()); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpVect arg1; cpVect arg2; double arg3; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg0, NULL ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg3 ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg0, NULL ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); + ok &= JS::ToNumber( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); void* ret_val = cpSegmentShapeNew((cpBody*)arg0 , (cpVect)arg1 , (cpVect)arg2 , (cpFloat)arg3 ); jsb_set_jsobject_for_proxy(jsobj, ret_val); jsb_set_c_proxy_for_jsobject(jsobj, ret_val, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -4936,7 +4954,7 @@ void JSB_cpSegmentShape_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: cpVect bool JSB_cpSegmentShape_getA(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSegmentShape* arg0 = (cpSegmentShape*) proxy->handle; @@ -4945,7 +4963,7 @@ bool JSB_cpSegmentShape_getA(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpSegmentShapeGetA((cpShape*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4954,7 +4972,7 @@ bool JSB_cpSegmentShape_getA(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpSegmentShape_getB(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSegmentShape* arg0 = (cpSegmentShape*) proxy->handle; @@ -4963,7 +4981,7 @@ bool JSB_cpSegmentShape_getB(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpSegmentShapeGetB((cpShape*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4972,7 +4990,7 @@ bool JSB_cpSegmentShape_getB(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpSegmentShape_getNormal(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSegmentShape* arg0 = (cpSegmentShape*) proxy->handle; @@ -4981,7 +4999,7 @@ bool JSB_cpSegmentShape_getNormal(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpSegmentShapeGetNormal((cpShape*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4990,14 +5008,14 @@ bool JSB_cpSegmentShape_getNormal(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSegmentShape_getRadius(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSegmentShape* arg0 = (cpSegmentShape*) proxy->handle; cpFloat ret_val; ret_val = cpSegmentShapeGetRadius((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -5009,40 +5027,42 @@ bool JSB_cpSegmentShape_setNeighbors(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSegmentShape* arg0 = (cpSegmentShape*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg1; cpVect arg2; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSegmentShapeSetNeighbors((cpShape*)arg0 , (cpVect)arg1 , (cpVect)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -static bool js_get_cpSegmentShape_a_tangent(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +static bool js_get_cpSegmentShape_a_tangent(JSContext *cx, uint32_t argc, jsval *vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpSegmentShape* shape = (cpSegmentShape*) proxy->handle; cpVect vec = shape->a_tangent; jsval ret = cpVect_to_jsval( cx, vec); - vp.set(ret); + args.rval().set(ret); return true; } -static bool js_get_cpSegmentShape_b_tangent(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +static bool js_get_cpSegmentShape_b_tangent(JSContext *cx, uint32_t argc, jsval *vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpSegmentShape* shape = (cpSegmentShape*) proxy->handle; cpVect vec = shape->b_tangent; jsval ret = cpVect_to_jsval( cx, vec); - vp.set(ret); + args.rval().set(ret); return true; } -void JSB_cpSegmentShape_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpSegmentShape_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpSegmentShape_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpSegmentShape_class->name = name; @@ -5057,9 +5077,9 @@ void JSB_cpSegmentShape_createClass(JSContext *cx, JSObject* globalObj, const ch JSB_cpSegmentShape_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {"a_tangent", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpSegmentShape_a_tangent), JSOP_NULLWRAPPER}, - {"b_tangent", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpSegmentShape_b_tangent), JSOP_NULLWRAPPER}, - {0, 0, 0, 0, 0} + JS_PSG("a_tangent", js_get_cpSegmentShape_a_tangent, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSG("b_tangent", js_get_cpSegmentShape_a_tangent, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getA", JSB_cpSegmentShape_getA, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -5073,7 +5093,7 @@ void JSB_cpSegmentShape_createClass(JSContext *cx, JSObject* globalObj, const ch JS_FS_END }; - JSB_cpSegmentShape_object = JS_InitClass(cx, globalObj, JSB_cpShape_object, JSB_cpSegmentShape_class, JSB_cpSegmentShape_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpSegmentShape_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpShape_object), JSB_cpSegmentShape_class, JSB_cpSegmentShape_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -5106,14 +5126,14 @@ void JSB_cpPolyShape_finalize(JSFreeOp *fop, JSObject *jsthis) // Ret value: int bool JSB_cpPolyShape_getNumVerts(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpPolyShape* arg0 = (cpPolyShape*) proxy->handle; int ret_val; ret_val = cpPolyShapeGetNumVerts((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -5125,30 +5145,31 @@ bool JSB_cpPolyShape_getVert(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpPolyShape* arg0 = (cpPolyShape*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg1; - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpPolyShapeGetVert((cpShape*)arg0 , (int)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } -static bool js_get_cpPolyShape_verts(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +static bool js_get_cpPolyShape_verts(JSContext *cx, uint32_t argc, jsval *vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpPolyShape* shape = (cpPolyShape*) proxy->handle; int numVerts = shape->numVerts; cpVect* verts = shape->verts; - JSObject *jsretArr = JS_NewArrayObject(cx, 0, NULL); + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); int i = 0; while (i < numVerts) { cpVect vec = verts[i]; @@ -5157,22 +5178,23 @@ static bool js_get_cpPolyShape_verts(JSContext *cx, JS::HandleObject obj, JS::Ha JS::RootedValue y(cx); x = DOUBLE_TO_JSVAL(vec.x); y = DOUBLE_TO_JSVAL(vec.y); - JS_SetElement(cx, jsretArr, i*2, &x); - JS_SetElement(cx, jsretArr, i*2+1, &y); + JS_SetElement(cx, jsretArr, i*2, x); + JS_SetElement(cx, jsretArr, i*2+1, y); i++; } - vp.set(OBJECT_TO_JSVAL(jsretArr)); + args.rval().set(OBJECT_TO_JSVAL(jsretArr)); return true; } -static bool js_get_cpPolyShape_planes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +static bool js_get_cpPolyShape_planes(JSContext *cx, uint32_t argc, jsval *vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpPolyShape* shape = (cpPolyShape*) proxy->handle; int numVerts = shape->numVerts; cpSplittingPlane* planes = shape->planes; - JSObject *jsretArr = JS_NewArrayObject(cx, 0, NULL); + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); int i = 0; while(i < numVerts){ cpSplittingPlane *plane = planes + i; @@ -5181,20 +5203,20 @@ static bool js_get_cpPolyShape_planes(JSContext *cx, JS::HandleObject obj, JS::H JSObject *jsobj = jsb_get_jsobject_for_proxy(plane); if(!jsobj) { - jsobj = JS_NewObject(cx, JSB_cpSplittingPlane_class, JSB_cpSplittingPlane_object, NULL); + jsobj = JS_NewObject(cx, JSB_cpSplittingPlane_class, JS::RootedObject(cx, JSB_cpSplittingPlane_object), JS::NullPtr()); jsb_set_jsobject_for_proxy(jsobj, plane); jsb_set_c_proxy_for_jsobject(jsobj, plane, JSB_C_FLAG_DO_NOT_CALL_FREE); } elem = OBJECT_TO_JSVAL(jsobj); - JS_SetElement(cx, jsretArr, i, &elem); + JS_SetElement(cx, jsretArr, i, elem); i++; } - vp.set(OBJECT_TO_JSVAL(jsretArr)); + args.rval().set(OBJECT_TO_JSVAL(jsretArr)); return true; } -void JSB_cpPolyShape_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpPolyShape_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpPolyShape_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpPolyShape_class->name = name; @@ -5209,9 +5231,9 @@ void JSB_cpPolyShape_createClass(JSContext *cx, JSObject* globalObj, const char* JSB_cpPolyShape_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {"verts", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpPolyShape_verts), JSOP_NULLWRAPPER}, - {"planes", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpPolyShape_planes), JSOP_NULLWRAPPER}, - {0, 0, 0, 0, 0} + JS_PSG("verts", js_get_cpPolyShape_verts, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSG("planes", js_get_cpPolyShape_planes, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getNumVerts", JSB_cpPolyShape_getNumVerts, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -5222,7 +5244,7 @@ void JSB_cpPolyShape_createClass(JSContext *cx, JSObject* globalObj, const char* JS_FS_END }; - JSB_cpPolyShape_object = JS_InitClass(cx, globalObj, JSB_cpShape_object, JSB_cpPolyShape_class, JSB_cpPolyShape_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpPolyShape_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpShape_object), JSB_cpPolyShape_class, JSB_cpPolyShape_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -5245,24 +5267,26 @@ void JSB_cpSplittingPlane_finalize(JSFreeOp *fop, JSObject *jsthis) } } -bool js_get_cpSplitting_n(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +bool js_get_cpSplitting_n(JSContext *cx, uint32_t argc, jsval *vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpSplittingPlane* plane = (cpSplittingPlane*) proxy->handle; cpVect vec = plane->n; - vp.set(cpVect_to_jsval(cx, vec)); + args.rval().set(cpVect_to_jsval(cx, vec)); return true; } -bool js_get_cpSplitting_d(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +bool js_get_cpSplitting_d(JSContext *cx, uint32_t argc, jsval *vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpSplittingPlane* plane = (cpSplittingPlane*) proxy->handle; - vp.set(DOUBLE_TO_JSVAL(plane->d)); + args.rval().set(DOUBLE_TO_JSVAL(plane->d)); return true; } -void JSB_cpSplittingPlane_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpSplittingPlane_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpSplittingPlane_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpSplittingPlane_class->name = name; @@ -5277,9 +5301,9 @@ void JSB_cpSplittingPlane_createClass(JSContext *cx, JSObject* globalObj, const JSB_cpSplittingPlane_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {"n", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpSplitting_n), JSOP_NULLWRAPPER}, - {"d", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpSplitting_d), JSOP_NULLWRAPPER}, - {0, 0, 0, 0, 0} + JS_PSG("n", js_get_cpSplitting_n, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSG("d", js_get_cpSplitting_d, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FS_END @@ -5288,7 +5312,7 @@ void JSB_cpSplittingPlane_createClass(JSContext *cx, JSObject* globalObj, const JS_FS_END }; - JSB_cpSplittingPlane_object = JS_InitClass(cx, globalObj, NULL, JSB_cpSplittingPlane_class, NULL,0,properties,funcs,NULL,st_funcs); + JSB_cpSplittingPlane_object = JS_InitClass(cx, globalObj, JS::NullPtr(), JSB_cpSplittingPlane_class, NULL,0,properties,funcs,NULL,st_funcs); } bool JSB_cpSegmentQueryInfo_hitPoint(JSContext *cx, uint32_t argc, jsval *vp){ @@ -5297,19 +5321,19 @@ bool JSB_cpSegmentQueryInfo_hitPoint(JSContext *cx, uint32_t argc, jsval *vp){ JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSegmentQueryInfo* info = (cpSegmentQueryInfo*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpVect start; cpVect end; bool ok = true; - ok &= jsval_to_cpVect( cx, argvp[0], &start ); - ok &= jsval_to_cpVect( cx, argvp[1], &end ); + ok &= jsval_to_cpVect( cx, args.get(0), &start ); + ok &= jsval_to_cpVect( cx, args.get(1), &end ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret = cpSegmentQueryHitPoint(start, end, *info); jsval ret_jsval = cpVect_to_jsval( cx, ret ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -5319,19 +5343,19 @@ bool JSB_cpSegmentQueryInfo_hitDist(JSContext *cx, uint32_t argc, jsval *vp){ JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSegmentQueryInfo* info = (cpSegmentQueryInfo*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpVect start; cpVect end; bool ok = true; - ok &= jsval_to_cpVect( cx, argvp[0], &start ); - ok &= jsval_to_cpVect( cx, argvp[1], &end ); + ok &= jsval_to_cpVect( cx, args.get(0), &start ); + ok &= jsval_to_cpVect( cx, args.get(1), &end ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); float ret = cpSegmentQueryHitDist(start, end, *info); jsval ret_jsval = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -5354,69 +5378,79 @@ void JSB_cpSegmentQueryInfo_finalize(JSFreeOp *fop, JSObject *jsthis) } } -bool js_get_cpSegmentQueryInfo_shape(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +bool js_get_cpSegmentQueryInfo_shape(JSContext *cx, uint32_t argc, jsval *vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpSegmentQueryInfo* info = (cpSegmentQueryInfo*) proxy->handle; cpShape* shape = info->shape; if(shape){ - JSObject *jsobj = JS_NewObject(cx, JSB_cpShape_class, JSB_cpShape_object, NULL); + JSObject *jsobj = JS_NewObject(cx, JSB_cpShape_class, JS::RootedObject(cx, JSB_cpShape_object), JS::NullPtr()); //jsb_set_jsobject_for_proxy(jsobj, shape); jsb_set_c_proxy_for_jsobject(jsobj, shape, JSB_C_FLAG_DO_NOT_CALL_FREE); - vp.set(OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); }else{ - vp.setNull(); + args.rval().setUndefined(); } return true; } -bool js_set_cpSegmentQueryInfo_shape(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) +bool js_set_cpSegmentQueryInfo_shape(JSContext *cx, uint32_t argc, jsval *vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpSegmentQueryInfo* info = (cpSegmentQueryInfo*) proxy->handle; cpShape* shape; struct jsb_c_proxy_s *retproxy; - jsval_to_c_class( cx, vp.get(), (void**)&shape, &retproxy ); + jsval_to_c_class( cx, args.get(0), (void**)&shape, &retproxy ); info->shape = shape; return true; } -bool js_get_cpSegmentQueryInfo_t(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp){ - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +bool js_get_cpSegmentQueryInfo_t(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpSegmentQueryInfo* info = (cpSegmentQueryInfo*) proxy->handle; - vp.setNumber(info->t); + args.rval().setNumber(info->t); return true; } -bool js_set_cpSegmentQueryInfo_t(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp){ - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +bool js_set_cpSegmentQueryInfo_t(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpSegmentQueryInfo* info = (cpSegmentQueryInfo*) proxy->handle; - info->t = JSVAL_TO_DOUBLE(vp.get()); + info->t = args.get(0).toDouble(); return true; } -bool js_get_cpSegmentQueryInfo_n(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp){ - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +bool js_get_cpSegmentQueryInfo_n(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpSegmentQueryInfo* info = (cpSegmentQueryInfo*) proxy->handle; - vp.set(cpVect_to_jsval(cx, info->n)); + args.rval().set(cpVect_to_jsval(cx, info->n)); return true; } -bool js_set_cpSegmentQueryInfo_n(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp){ - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +bool js_set_cpSegmentQueryInfo_n(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpSegmentQueryInfo* info = (cpSegmentQueryInfo*) proxy->handle; cpVect v; - bool ok = jsval_to_cpVect(cx, vp.get(), &v); + bool ok = jsval_to_cpVect(cx, args.get(0), &v); if(ok) info->n = v; return true; } -void JSB_cpSegmentQueryInfo_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpSegmentQueryInfo_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpSegmentQueryInfo_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpSegmentQueryInfo_class->name = name; @@ -5431,10 +5465,10 @@ void JSB_cpSegmentQueryInfo_createClass(JSContext *cx, JSObject* globalObj, cons JSB_cpSegmentQueryInfo_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {"shape", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpSegmentQueryInfo_shape), JSOP_WRAPPER(js_set_cpSegmentQueryInfo_shape)}, - {"t", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpSegmentQueryInfo_t), JSOP_WRAPPER(js_set_cpSegmentQueryInfo_t)}, - {"n", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpSegmentQueryInfo_n), JSOP_WRAPPER(js_set_cpSegmentQueryInfo_n)}, - {0, 0, 0, 0, 0} + JS_PSGS("shape", js_get_cpSegmentQueryInfo_shape, js_set_cpSegmentQueryInfo_shape, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSGS("t", js_get_cpSegmentQueryInfo_t, js_set_cpSegmentQueryInfo_t, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSGS("n", js_get_cpSegmentQueryInfo_n, js_set_cpSegmentQueryInfo_n, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("hitPoint", JSB_cpSegmentQueryInfo_hitPoint, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -5445,70 +5479,80 @@ void JSB_cpSegmentQueryInfo_createClass(JSContext *cx, JSObject* globalObj, cons JS_FS_END }; - JSB_cpSegmentQueryInfo_object = JS_InitClass(cx, globalObj, NULL, JSB_cpSegmentQueryInfo_class, NULL,0,properties,funcs,NULL,st_funcs); + JSB_cpSegmentQueryInfo_object = JS_InitClass(cx, globalObj, JS::NullPtr(), JSB_cpSegmentQueryInfo_class, NULL,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } -bool js_get_cpNearestPointQueryInfo_shape(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +bool js_get_cpNearestPointQueryInfo_shape(JSContext *cx, uint32_t argc, jsval *vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpNearestPointQueryInfo* info = (cpNearestPointQueryInfo*) proxy->handle; cpShape* shape = info->shape; if(shape){ - JSObject *jsobj = JS_NewObject(cx, JSB_cpShape_class, JSB_cpShape_object, NULL); + JSObject *jsobj = JS_NewObject(cx, JSB_cpShape_class, JS::RootedObject(cx, JSB_cpShape_object), JS::NullPtr()); //jsb_set_jsobject_for_proxy(jsobj, shape); jsb_set_c_proxy_for_jsobject(jsobj, shape, JSB_C_FLAG_DO_NOT_CALL_FREE); - vp.set(OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); }else{ - vp.setNull(); + args.rval().setUndefined(); } return true; } -bool js_set_cpNearestPointQueryInfo_shape(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) +bool js_set_cpNearestPointQueryInfo_shape(JSContext *cx, uint32_t argc, jsval *vp) { - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpNearestPointQueryInfo* info = (cpNearestPointQueryInfo*) proxy->handle; cpShape* shape; struct jsb_c_proxy_s *retproxy; - jsval_to_c_class( cx, vp.get(), (void**)&shape, &retproxy ); + jsval_to_c_class( cx, args.get(0), (void**)&shape, &retproxy ); info->shape = shape; return true; } -bool js_get_cpNearestPointQueryInfo_p(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp){ - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +bool js_get_cpNearestPointQueryInfo_p(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpNearestPointQueryInfo* info = (cpNearestPointQueryInfo*) proxy->handle; - vp.set(cpVect_to_jsval(cx, info->p)); + args.rval().set(cpVect_to_jsval(cx, info->p)); return true; } -bool js_set_cpNearestPointQueryInfo_p(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp){ - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +bool js_set_cpNearestPointQueryInfo_p(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpNearestPointQueryInfo* info = (cpNearestPointQueryInfo*) proxy->handle; cpVect v; - bool ok = jsval_to_cpVect(cx, vp.get(), &v); + bool ok = jsval_to_cpVect(cx, args.get(0), &v); if(ok) info->p = v; return true; } -bool js_get_cpNearestPointQueryInfo_d(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp){ - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +bool js_get_cpNearestPointQueryInfo_d(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpNearestPointQueryInfo* info = (cpNearestPointQueryInfo*) proxy->handle; - vp.setNumber(info->d); + args.rval().setNumber(info->d); return true; } -bool js_set_cpNearestPointQueryInfo_d(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp){ - struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); +bool js_set_cpNearestPointQueryInfo_d(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(args.thisv().toObjectOrNull()); cpNearestPointQueryInfo* info = (cpNearestPointQueryInfo*) proxy->handle; - info->d = JSVAL_TO_DOUBLE(vp.get()); + info->d = args.get(0).toDouble(); return true; } @@ -5531,7 +5575,7 @@ void JSB_cpNearestPointQueryInfo_finalize(JSFreeOp *fop, JSObject *jsthis) } } -void JSB_cpNearestPointQueryInfo_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpNearestPointQueryInfo_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpNearestPointQueryInfo_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpNearestPointQueryInfo_class->name = name; @@ -5546,10 +5590,10 @@ void JSB_cpNearestPointQueryInfo_createClass(JSContext *cx, JSObject* globalObj, JSB_cpNearestPointQueryInfo_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {"shape", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpNearestPointQueryInfo_shape), JSOP_WRAPPER(js_set_cpNearestPointQueryInfo_shape)}, - {"p", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpNearestPointQueryInfo_p), JSOP_WRAPPER(js_set_cpNearestPointQueryInfo_p)}, - {"d", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_cpNearestPointQueryInfo_d), JSOP_WRAPPER(js_set_cpNearestPointQueryInfo_d)}, - {0, 0, 0, 0, 0} + JS_PSGS("shape", js_get_cpNearestPointQueryInfo_shape, js_set_cpNearestPointQueryInfo_shape, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSGS("p", js_get_cpNearestPointQueryInfo_p, js_set_cpNearestPointQueryInfo_p, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PSGS("d", js_get_cpNearestPointQueryInfo_d, js_set_cpNearestPointQueryInfo_d, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FS_END @@ -5558,6 +5602,6 @@ void JSB_cpNearestPointQueryInfo_createClass(JSContext *cx, JSObject* globalObj, JS_FS_END }; - JSB_cpNearestPointQueryInfo_object = JS_InitClass(cx, globalObj, NULL, JSB_cpNearestPointQueryInfo_class, NULL,0,properties,funcs,NULL,st_funcs); + JSB_cpNearestPointQueryInfo_object = JS_InitClass(cx, globalObj, JS::NullPtr(), JSB_cpNearestPointQueryInfo_class, NULL,0,properties,funcs,NULL,st_funcs); } #endif // JSB_INCLUDE_CHIPMUNK diff --git a/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_auto_classes.h b/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_auto_classes.h index 1ac11afa92..93f7b77cc8 100644 --- a/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_auto_classes.h +++ b/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_auto_classes.h @@ -9,65 +9,65 @@ #include "js_bindings_chipmunk_manual.h" extern JSObject *JSB_cpConstraint_object; extern JSClass *JSB_cpConstraint_class; -void JSB_cpConstraint_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpConstraint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpGrooveJoint_object; extern JSClass *JSB_cpGrooveJoint_class; -void JSB_cpGrooveJoint_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpGrooveJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpSimpleMotor_object; extern JSClass *JSB_cpSimpleMotor_class; -void JSB_cpSimpleMotor_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpSimpleMotor_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpPivotJoint_object; extern JSClass *JSB_cpPivotJoint_class; -void JSB_cpPivotJoint_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpPivotJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpPinJoint_object; extern JSClass *JSB_cpPinJoint_class; -void JSB_cpPinJoint_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpPinJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpSlideJoint_object; extern JSClass *JSB_cpSlideJoint_class; -void JSB_cpSlideJoint_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpSlideJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpGearJoint_object; extern JSClass *JSB_cpGearJoint_class; -void JSB_cpGearJoint_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpGearJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpDampedRotarySpring_object; extern JSClass *JSB_cpDampedRotarySpring_class; -void JSB_cpDampedRotarySpring_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpDampedRotarySpring_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpDampedSpring_object; extern JSClass *JSB_cpDampedSpring_class; -void JSB_cpDampedSpring_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpDampedSpring_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpRatchetJoint_object; extern JSClass *JSB_cpRatchetJoint_class; -void JSB_cpRatchetJoint_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpRatchetJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpRotaryLimitJoint_object; extern JSClass *JSB_cpRotaryLimitJoint_class; -void JSB_cpRotaryLimitJoint_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpRotaryLimitJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpArbiter_object; extern JSClass *JSB_cpArbiter_class; -void JSB_cpArbiter_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpArbiter_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpSpace_object; extern JSClass *JSB_cpSpace_class; -void JSB_cpSpace_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpSpace_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpBody_object; extern JSClass *JSB_cpBody_class; -void JSB_cpBody_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpBody_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpShape_object; extern JSClass *JSB_cpShape_class; -void JSB_cpShape_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpShape_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpCircleShape_object; extern JSClass *JSB_cpCircleShape_class; -void JSB_cpCircleShape_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpCircleShape_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpSegmentShape_object; extern JSClass *JSB_cpSegmentShape_class; -void JSB_cpSegmentShape_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpSegmentShape_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpPolyShape_object; extern JSClass *JSB_cpPolyShape_class; -void JSB_cpPolyShape_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpPolyShape_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpSegmentQueryInfo_object; extern JSClass *JSB_cpSegmentQueryInfo_class; -void JSB_cpSegmentQueryInfo_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpSegmentQueryInfo_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpNearestPointQueryInfo_object; extern JSClass *JSB_cpNearestPointQueryInfo_class; -void JSB_cpNearestPointQueryInfo_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpNearestPointQueryInfo_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); extern JSObject *JSB_cpSplittingPlane_object; extern JSClass *JSB_cpSplittingPlane_class; -void JSB_cpSplittingPlane_createClass(JSContext *cx, JSObject* globalObj, const char* name ); +void JSB_cpSplittingPlane_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ); #endif // JSB_INCLUDE_CHIPMUNK diff --git a/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_functions.cpp b/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_functions.cpp index 8976e2f089..c1f4904218 100644 --- a/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_functions.cpp +++ b/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_functions.cpp @@ -17,16 +17,16 @@ // Ret value: int bool JSB_cpArbiterGetCount(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); int ret_val; ret_val = cpArbiterGetCount((cpArbiter*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -34,17 +34,17 @@ bool JSB_cpArbiterGetCount(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpArbiterGetDepth(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; int32_t arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpArbiterGetDepth((cpArbiter*)arg0 , (int)arg1 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -52,16 +52,16 @@ bool JSB_cpArbiterGetDepth(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpArbiterGetElasticity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpArbiterGetElasticity((cpArbiter*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -69,16 +69,16 @@ bool JSB_cpArbiterGetElasticity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpArbiterGetFriction(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpArbiterGetFriction((cpArbiter*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -86,19 +86,19 @@ bool JSB_cpArbiterGetFriction(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpArbiterGetNormal(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; int32_t arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpArbiterGetNormal((cpArbiter*)arg0 , (int)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -107,19 +107,19 @@ bool JSB_cpArbiterGetNormal(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpArbiterGetPoint(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; int32_t arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpArbiterGetPoint((cpArbiter*)arg0 , (int)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -128,18 +128,18 @@ bool JSB_cpArbiterGetPoint(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpArbiterGetSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpArbiterGetSurfaceVelocity((cpArbiter*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -148,15 +148,15 @@ bool JSB_cpArbiterGetSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpArbiterIgnore(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpArbiterIgnore((cpArbiter*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -164,16 +164,16 @@ bool JSB_cpArbiterIgnore(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpArbiterIsFirstContact(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpArbiterIsFirstContact((cpArbiter*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -181,16 +181,16 @@ bool JSB_cpArbiterIsFirstContact(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpArbiterSetElasticity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpArbiterSetElasticity((cpArbiter*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -198,16 +198,16 @@ bool JSB_cpArbiterSetElasticity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpArbiterSetFriction(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpArbiterSetFriction((cpArbiter*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -215,16 +215,16 @@ bool JSB_cpArbiterSetFriction(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpArbiterSetSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpArbiterSetSurfaceVelocity((cpArbiter*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -232,18 +232,18 @@ bool JSB_cpArbiterSetSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpArbiterTotalImpulse(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpArbiterTotalImpulse((cpArbiter*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -252,18 +252,18 @@ bool JSB_cpArbiterTotalImpulse(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpArbiterTotalImpulseWithFriction(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpArbiterTotalImpulseWithFriction((cpArbiter*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -272,16 +272,16 @@ bool JSB_cpArbiterTotalImpulseWithFriction(JSContext *cx, uint32_t argc, jsval * // Ret value: cpFloat bool JSB_cpArbiterTotalKE(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpArbiter* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpArbiterTotalKE((cpArbiter*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -289,17 +289,17 @@ bool JSB_cpArbiterTotalKE(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpAreaForCircle(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpAreaForCircle((cpFloat)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -307,18 +307,18 @@ bool JSB_cpAreaForCircle(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpAreaForSegment(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; double arg2; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpAreaForSegment((cpVect)arg0 , (cpVect)arg1 , (cpFloat)arg2 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -326,16 +326,16 @@ bool JSB_cpAreaForSegment(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBBArea(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBB arg0; - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg0 ); + ok &= jsval_to_cpBB( cx, args.get(0), (cpBB*) &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpBBArea((cpBB)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -343,19 +343,19 @@ bool JSB_cpBBArea(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpBBClampVect(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBB arg0; cpVect arg1; - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpBB( cx, args.get(0), (cpBB*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpBBClampVect((cpBB)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -364,17 +364,17 @@ bool JSB_cpBBClampVect(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpBBContainsBB(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBB arg0; cpBB arg1; - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg0 ); - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg1 ); + ok &= jsval_to_cpBB( cx, args.get(0), (cpBB*) &arg0 ); + ok &= jsval_to_cpBB( cx, args.get(1), (cpBB*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpBBContainsBB((cpBB)arg0 , (cpBB)arg1 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -382,17 +382,17 @@ bool JSB_cpBBContainsBB(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpBBContainsVect(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBB arg0; cpVect arg1; - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpBB( cx, args.get(0), (cpBB*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpBBContainsVect((cpBB)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -400,19 +400,19 @@ bool JSB_cpBBContainsVect(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBB bool JSB_cpBBExpand(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBB arg0; cpVect arg1; - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpBB( cx, args.get(0), (cpBB*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBB ret_val; ret_val = cpBBExpand((cpBB)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpBB_to_jsval( cx, (cpBB)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -421,17 +421,17 @@ bool JSB_cpBBExpand(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpBBIntersects(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBB arg0; cpBB arg1; - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg0 ); - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg1 ); + ok &= jsval_to_cpBB( cx, args.get(0), (cpBB*) &arg0 ); + ok &= jsval_to_cpBB( cx, args.get(1), (cpBB*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpBBIntersects((cpBB)arg0 , (cpBB)arg1 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -439,18 +439,18 @@ bool JSB_cpBBIntersects(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpBBIntersectsSegment(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBB arg0; cpVect arg1; cpVect arg2; - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= jsval_to_cpBB( cx, args.get(0), (cpBB*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpBBIntersectsSegment((cpBB)arg0 , (cpVect)arg1 , (cpVect)arg2 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -458,19 +458,19 @@ bool JSB_cpBBIntersectsSegment(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBB bool JSB_cpBBMerge(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBB arg0; cpBB arg1; - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg0 ); - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg1 ); + ok &= jsval_to_cpBB( cx, args.get(0), (cpBB*) &arg0 ); + ok &= jsval_to_cpBB( cx, args.get(1), (cpBB*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBB ret_val; ret_val = cpBBMerge((cpBB)arg0 , (cpBB)arg1 ); jsval ret_jsval = cpBB_to_jsval( cx, (cpBB)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -479,17 +479,17 @@ bool JSB_cpBBMerge(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBBMergedArea(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBB arg0; cpBB arg1; - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg0 ); - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg1 ); + ok &= jsval_to_cpBB( cx, args.get(0), (cpBB*) &arg0 ); + ok &= jsval_to_cpBB( cx, args.get(1), (cpBB*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpBBMergedArea((cpBB)arg0 , (cpBB)arg1 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -497,21 +497,21 @@ bool JSB_cpBBMergedArea(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBB bool JSB_cpBBNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; double arg1; double arg2; double arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg3 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); + ok &= JS::ToNumber( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBB ret_val; ret_val = cpBBNew((cpFloat)arg0 , (cpFloat)arg1 , (cpFloat)arg2 , (cpFloat)arg3 ); jsval ret_jsval = cpBB_to_jsval( cx, (cpBB)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -520,19 +520,19 @@ bool JSB_cpBBNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBB bool JSB_cpBBNewForCircle(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; double arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBB ret_val; ret_val = cpBBNewForCircle((cpVect)arg0 , (cpFloat)arg1 ); jsval ret_jsval = cpBB_to_jsval( cx, (cpBB)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -541,18 +541,18 @@ bool JSB_cpBBNewForCircle(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBBSegmentQuery(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBB arg0; cpVect arg1; cpVect arg2; - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= jsval_to_cpBB( cx, args.get(0), (cpBB*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpBBSegmentQuery((cpBB)arg0 , (cpVect)arg1 , (cpVect)arg2 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -560,19 +560,19 @@ bool JSB_cpBBSegmentQuery(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpBBWrapVect(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBB arg0; cpVect arg1; - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpBB( cx, args.get(0), (cpBB*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpBBWrapVect((cpBB)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -581,15 +581,15 @@ bool JSB_cpBBWrapVect(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodyActivate(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodyActivate((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -597,16 +597,16 @@ bool JSB_cpBodyActivate(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodyActivateStatic(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpShape* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodyActivateStatic((cpBody*)arg0 , (cpShape*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -614,17 +614,17 @@ bool JSB_cpBodyActivateStatic(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodyApplyForce(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpVect arg1; cpVect arg2; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodyApplyForce((cpBody*)arg0 , (cpVect)arg1 , (cpVect)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -632,17 +632,17 @@ bool JSB_cpBodyApplyForce(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodyApplyImpulse(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpVect arg1; cpVect arg2; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodyApplyImpulse((cpBody*)arg0 , (cpVect)arg1 , (cpVect)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -650,15 +650,15 @@ bool JSB_cpBodyApplyImpulse(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodyDestroy(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodyDestroy((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -666,15 +666,15 @@ bool JSB_cpBodyDestroy(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodyFree(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodyFree((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -682,16 +682,16 @@ bool JSB_cpBodyFree(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBodyGetAngVel(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpBodyGetAngVel((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -699,16 +699,16 @@ bool JSB_cpBodyGetAngVel(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBodyGetAngVelLimit(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpBodyGetAngVelLimit((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -716,16 +716,16 @@ bool JSB_cpBodyGetAngVelLimit(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBodyGetAngle(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpBodyGetAngle((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -733,18 +733,18 @@ bool JSB_cpBodyGetAngle(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpBodyGetForce(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpBodyGetForce((cpBody*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -753,16 +753,16 @@ bool JSB_cpBodyGetForce(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBodyGetMass(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpBodyGetMass((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -770,16 +770,16 @@ bool JSB_cpBodyGetMass(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBodyGetMoment(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpBodyGetMoment((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -787,18 +787,18 @@ bool JSB_cpBodyGetMoment(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpBodyGetPos(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpBodyGetPos((cpBody*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -807,18 +807,18 @@ bool JSB_cpBodyGetPos(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpBodyGetRot(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpBodyGetRot((cpBody*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -827,18 +827,18 @@ bool JSB_cpBodyGetRot(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpSpace* bool JSB_cpBodyGetSpace(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpace* ret_val; ret_val = cpBodyGetSpace((cpBody*)arg0 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -847,16 +847,16 @@ bool JSB_cpBodyGetSpace(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBodyGetTorque(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpBodyGetTorque((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -864,18 +864,18 @@ bool JSB_cpBodyGetTorque(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpBodyGetVel(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpBodyGetVel((cpBody*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -884,19 +884,19 @@ bool JSB_cpBodyGetVel(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpBodyGetVelAtLocalPoint(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpBodyGetVelAtLocalPoint((cpBody*)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -905,19 +905,19 @@ bool JSB_cpBodyGetVelAtLocalPoint(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpBodyGetVelAtWorldPoint(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpBodyGetVelAtWorldPoint((cpBody*)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -926,16 +926,16 @@ bool JSB_cpBodyGetVelAtWorldPoint(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBodyGetVelLimit(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpBodyGetVelLimit((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -943,20 +943,20 @@ bool JSB_cpBodyGetVelLimit(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBody* bool JSB_cpBodyInit(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; double arg1; double arg2; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBody* ret_val; ret_val = cpBodyInit((cpBody*)arg0 , (cpFloat)arg1 , (cpFloat)arg2 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -965,18 +965,18 @@ bool JSB_cpBodyInit(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBody* bool JSB_cpBodyInitStatic(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBody* ret_val; ret_val = cpBodyInitStatic((cpBody*)arg0 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -985,16 +985,16 @@ bool JSB_cpBodyInitStatic(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpBodyIsRogue(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpBodyIsRogue((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -1002,16 +1002,16 @@ bool JSB_cpBodyIsRogue(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpBodyIsSleeping(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpBodyIsSleeping((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -1019,16 +1019,16 @@ bool JSB_cpBodyIsSleeping(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpBodyIsStatic(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpBodyIsStatic((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -1036,16 +1036,16 @@ bool JSB_cpBodyIsStatic(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpBodyKineticEnergy(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpBodyKineticEnergy((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1053,19 +1053,19 @@ bool JSB_cpBodyKineticEnergy(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpBodyLocal2World(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpBodyLocal2World((cpBody*)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1074,19 +1074,19 @@ bool JSB_cpBodyLocal2World(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBody* bool JSB_cpBodyNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBody* ret_val; ret_val = cpBodyNew((cpFloat)arg0 , (cpFloat)arg1 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1095,12 +1095,13 @@ bool JSB_cpBodyNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBody* bool JSB_cpBodyNewStatic(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpBody* ret_val; ret_val = cpBodyNewStatic( ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1109,15 +1110,15 @@ bool JSB_cpBodyNewStatic(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodyResetForces(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodyResetForces((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1125,16 +1126,16 @@ bool JSB_cpBodyResetForces(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodySetAngVel(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetAngVel((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1142,16 +1143,16 @@ bool JSB_cpBodySetAngVel(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodySetAngVelLimit(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetAngVelLimit((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1159,16 +1160,16 @@ bool JSB_cpBodySetAngVelLimit(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodySetAngle(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetAngle((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1176,16 +1177,16 @@ bool JSB_cpBodySetAngle(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodySetForce(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetForce((cpBody*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1193,16 +1194,16 @@ bool JSB_cpBodySetForce(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodySetMass(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetMass((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1210,16 +1211,16 @@ bool JSB_cpBodySetMass(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodySetMoment(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetMoment((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1227,16 +1228,16 @@ bool JSB_cpBodySetMoment(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodySetPos(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetPos((cpBody*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1244,16 +1245,16 @@ bool JSB_cpBodySetPos(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodySetTorque(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetTorque((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1261,16 +1262,16 @@ bool JSB_cpBodySetTorque(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodySetVel(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetVel((cpBody*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1278,16 +1279,16 @@ bool JSB_cpBodySetVel(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodySetVelLimit(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySetVelLimit((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1295,15 +1296,15 @@ bool JSB_cpBodySetVelLimit(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodySleep(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySleep((cpBody*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1311,16 +1312,16 @@ bool JSB_cpBodySleep(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodySleepWithGroup(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodySleepWithGroup((cpBody*)arg0 , (cpBody*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1328,16 +1329,16 @@ bool JSB_cpBodySleepWithGroup(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodyUpdatePosition(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodyUpdatePosition((cpBody*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1345,18 +1346,18 @@ bool JSB_cpBodyUpdatePosition(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpBodyUpdateVelocity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpVect arg1; double arg2; double arg3; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg3 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); + ok &= JS::ToNumber( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBodyUpdateVelocity((cpBody*)arg0 , (cpVect)arg1 , (cpFloat)arg2 , (cpFloat)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1364,19 +1365,19 @@ bool JSB_cpBodyUpdateVelocity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpBodyWorld2Local(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpBodyWorld2Local((cpBody*)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1385,20 +1386,20 @@ bool JSB_cpBodyWorld2Local(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpShape* bool JSB_cpBoxShapeNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; double arg1; double arg2; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShape* ret_val; ret_val = cpBoxShapeNew((cpBody*)arg0 , (cpFloat)arg1 , (cpFloat)arg2 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1407,19 +1408,19 @@ bool JSB_cpBoxShapeNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpShape* bool JSB_cpBoxShapeNew2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBB arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpBB( cx, args.get(1), (cpBB*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShape* ret_val; ret_val = cpBoxShapeNew2((cpBody*)arg0 , (cpBB)arg1 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1428,18 +1429,18 @@ bool JSB_cpBoxShapeNew2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpCircleShapeGetOffset(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpCircleShapeGetOffset((cpShape*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1448,16 +1449,16 @@ bool JSB_cpCircleShapeGetOffset(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpCircleShapeGetRadius(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpCircleShapeGetRadius((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1465,20 +1466,20 @@ bool JSB_cpCircleShapeGetRadius(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpShape* bool JSB_cpCircleShapeNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; double arg1; cpVect arg2; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShape* ret_val; ret_val = cpCircleShapeNew((cpBody*)arg0 , (cpFloat)arg1 , (cpVect)arg2 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1487,15 +1488,15 @@ bool JSB_cpCircleShapeNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpConstraintActivateBodies(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraintActivateBodies((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1503,15 +1504,15 @@ bool JSB_cpConstraintActivateBodies(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpConstraintDestroy(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraintDestroy((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1519,15 +1520,15 @@ bool JSB_cpConstraintDestroy(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpConstraintFree(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraintFree((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1535,18 +1536,18 @@ bool JSB_cpConstraintFree(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBody* bool JSB_cpConstraintGetA(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBody* ret_val; ret_val = cpConstraintGetA((cpConstraint*)arg0 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1555,18 +1556,18 @@ bool JSB_cpConstraintGetA(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBody* bool JSB_cpConstraintGetB(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBody* ret_val; ret_val = cpConstraintGetB((cpConstraint*)arg0 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1575,16 +1576,16 @@ bool JSB_cpConstraintGetB(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpConstraintGetErrorBias(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpConstraintGetErrorBias((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1592,16 +1593,16 @@ bool JSB_cpConstraintGetErrorBias(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpConstraintGetImpulse(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpConstraintGetImpulse((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1609,16 +1610,16 @@ bool JSB_cpConstraintGetImpulse(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpConstraintGetMaxBias(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpConstraintGetMaxBias((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1626,16 +1627,16 @@ bool JSB_cpConstraintGetMaxBias(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpConstraintGetMaxForce(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpConstraintGetMaxForce((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1643,18 +1644,18 @@ bool JSB_cpConstraintGetMaxForce(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpSpace* bool JSB_cpConstraintGetSpace(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpace* ret_val; ret_val = cpConstraintGetSpace((cpConstraint*)arg0 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1663,16 +1664,16 @@ bool JSB_cpConstraintGetSpace(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpConstraintSetErrorBias(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraintSetErrorBias((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1680,16 +1681,16 @@ bool JSB_cpConstraintSetErrorBias(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpConstraintSetMaxBias(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraintSetMaxBias((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1697,16 +1698,16 @@ bool JSB_cpConstraintSetMaxBias(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpConstraintSetMaxForce(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraintSetMaxForce((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1714,16 +1715,16 @@ bool JSB_cpConstraintSetMaxForce(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpDampedRotarySpringGetDamping(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpDampedRotarySpringGetDamping((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1731,16 +1732,16 @@ bool JSB_cpDampedRotarySpringGetDamping(JSContext *cx, uint32_t argc, jsval *vp) // Ret value: cpFloat bool JSB_cpDampedRotarySpringGetRestAngle(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpDampedRotarySpringGetRestAngle((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1748,16 +1749,16 @@ bool JSB_cpDampedRotarySpringGetRestAngle(JSContext *cx, uint32_t argc, jsval *v // Ret value: cpFloat bool JSB_cpDampedRotarySpringGetStiffness(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpDampedRotarySpringGetStiffness((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1765,22 +1766,22 @@ bool JSB_cpDampedRotarySpringGetStiffness(JSContext *cx, uint32_t argc, jsval *v // Ret value: cpConstraint* bool JSB_cpDampedRotarySpringNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 5, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; double arg2; double arg3; double arg4; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg3 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg4 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); + ok &= JS::ToNumber( cx, args.get(3), &arg3 ); + ok &= JS::ToNumber( cx, args.get(4), &arg4 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraint* ret_val; ret_val = cpDampedRotarySpringNew((cpBody*)arg0 , (cpBody*)arg1 , (cpFloat)arg2 , (cpFloat)arg3 , (cpFloat)arg4 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1789,16 +1790,16 @@ bool JSB_cpDampedRotarySpringNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpDampedRotarySpringSetDamping(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedRotarySpringSetDamping((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1806,16 +1807,16 @@ bool JSB_cpDampedRotarySpringSetDamping(JSContext *cx, uint32_t argc, jsval *vp) // Ret value: void bool JSB_cpDampedRotarySpringSetRestAngle(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedRotarySpringSetRestAngle((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1823,16 +1824,16 @@ bool JSB_cpDampedRotarySpringSetRestAngle(JSContext *cx, uint32_t argc, jsval *v // Ret value: void bool JSB_cpDampedRotarySpringSetStiffness(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedRotarySpringSetStiffness((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1840,18 +1841,18 @@ bool JSB_cpDampedRotarySpringSetStiffness(JSContext *cx, uint32_t argc, jsval *v // Ret value: cpVect bool JSB_cpDampedSpringGetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpDampedSpringGetAnchr1((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1860,18 +1861,18 @@ bool JSB_cpDampedSpringGetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpDampedSpringGetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpDampedSpringGetAnchr2((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1880,16 +1881,16 @@ bool JSB_cpDampedSpringGetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpDampedSpringGetDamping(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpDampedSpringGetDamping((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1897,16 +1898,16 @@ bool JSB_cpDampedSpringGetDamping(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpDampedSpringGetRestLength(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpDampedSpringGetRestLength((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1914,16 +1915,16 @@ bool JSB_cpDampedSpringGetRestLength(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpDampedSpringGetStiffness(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpDampedSpringGetStiffness((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -1931,24 +1932,24 @@ bool JSB_cpDampedSpringGetStiffness(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpConstraint* bool JSB_cpDampedSpringNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 7, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; cpVect arg2; cpVect arg3; double arg4; double arg5; double arg6; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg3 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg4 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg5 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg6 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(3), (cpVect*) &arg3 ); + ok &= JS::ToNumber( cx, args.get(4), &arg4 ); + ok &= JS::ToNumber( cx, args.get(5), &arg5 ); + ok &= JS::ToNumber( cx, args.get(6), &arg6 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraint* ret_val; ret_val = cpDampedSpringNew((cpBody*)arg0 , (cpBody*)arg1 , (cpVect)arg2 , (cpVect)arg3 , (cpFloat)arg4 , (cpFloat)arg5 , (cpFloat)arg6 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -1957,16 +1958,16 @@ bool JSB_cpDampedSpringNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpDampedSpringSetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedSpringSetAnchr1((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1974,16 +1975,16 @@ bool JSB_cpDampedSpringSetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpDampedSpringSetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedSpringSetAnchr2((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1991,16 +1992,16 @@ bool JSB_cpDampedSpringSetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpDampedSpringSetDamping(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedSpringSetDamping((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2008,16 +2009,16 @@ bool JSB_cpDampedSpringSetDamping(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpDampedSpringSetRestLength(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedSpringSetRestLength((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2025,16 +2026,16 @@ bool JSB_cpDampedSpringSetRestLength(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpDampedSpringSetStiffness(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpDampedSpringSetStiffness((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2042,16 +2043,16 @@ bool JSB_cpDampedSpringSetStiffness(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpGearJointGetPhase(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpGearJointGetPhase((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2059,16 +2060,16 @@ bool JSB_cpGearJointGetPhase(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpGearJointGetRatio(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpGearJointGetRatio((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2076,21 +2077,21 @@ bool JSB_cpGearJointGetRatio(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpConstraint* bool JSB_cpGearJointNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; double arg2; double arg3; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg3 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); + ok &= JS::ToNumber( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraint* ret_val; ret_val = cpGearJointNew((cpBody*)arg0 , (cpBody*)arg1 , (cpFloat)arg2 , (cpFloat)arg3 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2099,16 +2100,16 @@ bool JSB_cpGearJointNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpGearJointSetPhase(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpGearJointSetPhase((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2116,16 +2117,16 @@ bool JSB_cpGearJointSetPhase(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpGearJointSetRatio(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpGearJointSetRatio((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2133,18 +2134,18 @@ bool JSB_cpGearJointSetRatio(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpGrooveJointGetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpGrooveJointGetAnchr2((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2153,18 +2154,18 @@ bool JSB_cpGrooveJointGetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpGrooveJointGetGrooveA(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpGrooveJointGetGrooveA((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2173,18 +2174,18 @@ bool JSB_cpGrooveJointGetGrooveA(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpGrooveJointGetGrooveB(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpGrooveJointGetGrooveB((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2193,22 +2194,22 @@ bool JSB_cpGrooveJointGetGrooveB(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpConstraint* bool JSB_cpGrooveJointNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 5, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; cpVect arg2; cpVect arg3; cpVect arg4; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg3 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg4 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(3), (cpVect*) &arg3 ); + ok &= jsval_to_cpVect( cx, args.get(4), (cpVect*) &arg4 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraint* ret_val; ret_val = cpGrooveJointNew((cpBody*)arg0 , (cpBody*)arg1 , (cpVect)arg2 , (cpVect)arg3 , (cpVect)arg4 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2217,16 +2218,16 @@ bool JSB_cpGrooveJointNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpGrooveJointSetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpGrooveJointSetAnchr2((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2234,16 +2235,16 @@ bool JSB_cpGrooveJointSetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpGrooveJointSetGrooveA(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpGrooveJointSetGrooveA((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2251,16 +2252,16 @@ bool JSB_cpGrooveJointSetGrooveA(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpGrooveJointSetGrooveB(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpGrooveJointSetGrooveB((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2268,9 +2269,9 @@ bool JSB_cpGrooveJointSetGrooveB(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpInitChipmunk(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpInitChipmunk( ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2278,18 +2279,18 @@ bool JSB_cpInitChipmunk(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpMomentForBox(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; double arg1; double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpMomentForBox((cpFloat)arg0 , (cpFloat)arg1 , (cpFloat)arg2 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2297,17 +2298,17 @@ bool JSB_cpMomentForBox(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpMomentForBox2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; cpBB arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); - ok &= jsval_to_cpBB( cx, *argvp++, (cpBB*) &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); + ok &= jsval_to_cpBB( cx, args.get(1), (cpBB*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpMomentForBox2((cpFloat)arg0 , (cpBB)arg1 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2315,19 +2316,19 @@ bool JSB_cpMomentForBox2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpMomentForCircle(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; double arg1; double arg2; cpVect arg3; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg3 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(3), (cpVect*) &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpMomentForCircle((cpFloat)arg0 , (cpFloat)arg1 , (cpFloat)arg2 , (cpVect)arg3 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2335,18 +2336,18 @@ bool JSB_cpMomentForCircle(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpMomentForSegment(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; cpVect arg1; cpVect arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpMomentForSegment((cpFloat)arg0 , (cpVect)arg1 , (cpVect)arg2 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2354,18 +2355,18 @@ bool JSB_cpMomentForSegment(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpPinJointGetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpPinJointGetAnchr1((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2374,18 +2375,18 @@ bool JSB_cpPinJointGetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpPinJointGetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpPinJointGetAnchr2((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2394,16 +2395,16 @@ bool JSB_cpPinJointGetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpPinJointGetDist(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpPinJointGetDist((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2411,21 +2412,21 @@ bool JSB_cpPinJointGetDist(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpConstraint* bool JSB_cpPinJointNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; cpVect arg2; cpVect arg3; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg3 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(3), (cpVect*) &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraint* ret_val; ret_val = cpPinJointNew((cpBody*)arg0 , (cpBody*)arg1 , (cpVect)arg2 , (cpVect)arg3 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2434,16 +2435,16 @@ bool JSB_cpPinJointNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpPinJointSetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpPinJointSetAnchr1((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2451,16 +2452,16 @@ bool JSB_cpPinJointSetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpPinJointSetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpPinJointSetAnchr2((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2468,16 +2469,16 @@ bool JSB_cpPinJointSetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpPinJointSetDist(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpPinJointSetDist((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2485,18 +2486,18 @@ bool JSB_cpPinJointSetDist(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpPivotJointGetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpPivotJointGetAnchr1((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2505,18 +2506,18 @@ bool JSB_cpPivotJointGetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpPivotJointGetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpPivotJointGetAnchr2((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2525,15 +2526,15 @@ bool JSB_cpPivotJointGetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpConstraint* bool JSB_cpPivotJointNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3 || argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; cpVect arg2; cpVect arg3; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); if(argc == 4) { - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg3 ); + ok &= jsval_to_cpVect( cx, args.get(3), (cpVect*) &arg3 ); } JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraint* ret_val; @@ -2545,7 +2546,7 @@ bool JSB_cpPivotJointNew(JSContext *cx, uint32_t argc, jsval *vp) { } jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2554,21 +2555,21 @@ bool JSB_cpPivotJointNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpConstraint* bool JSB_cpPivotJointNew2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; cpVect arg2; cpVect arg3; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg3 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(3), (cpVect*) &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraint* ret_val; ret_val = cpPivotJointNew2((cpBody*)arg0 , (cpBody*)arg1 , (cpVect)arg2 , (cpVect)arg3 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2577,16 +2578,16 @@ bool JSB_cpPivotJointNew2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpPivotJointSetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpPivotJointSetAnchr1((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2594,16 +2595,16 @@ bool JSB_cpPivotJointSetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpPivotJointSetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpPivotJointSetAnchr2((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2611,16 +2612,16 @@ bool JSB_cpPivotJointSetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: int bool JSB_cpPolyShapeGetNumVerts(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); int ret_val; ret_val = cpPolyShapeGetNumVerts((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -2628,19 +2629,19 @@ bool JSB_cpPolyShapeGetNumVerts(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpPolyShapeGetVert(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; int32_t arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpPolyShapeGetVert((cpShape*)arg0 , (int)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2649,16 +2650,16 @@ bool JSB_cpPolyShapeGetVert(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpRatchetJointGetAngle(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpRatchetJointGetAngle((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2666,16 +2667,16 @@ bool JSB_cpRatchetJointGetAngle(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpRatchetJointGetPhase(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpRatchetJointGetPhase((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2683,16 +2684,16 @@ bool JSB_cpRatchetJointGetPhase(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpRatchetJointGetRatchet(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpRatchetJointGetRatchet((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2700,21 +2701,21 @@ bool JSB_cpRatchetJointGetRatchet(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpConstraint* bool JSB_cpRatchetJointNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; double arg2; double arg3; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg3 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); + ok &= JS::ToNumber( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraint* ret_val; ret_val = cpRatchetJointNew((cpBody*)arg0 , (cpBody*)arg1 , (cpFloat)arg2 , (cpFloat)arg3 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2723,16 +2724,16 @@ bool JSB_cpRatchetJointNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpRatchetJointSetAngle(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpRatchetJointSetAngle((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2740,16 +2741,16 @@ bool JSB_cpRatchetJointSetAngle(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpRatchetJointSetPhase(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpRatchetJointSetPhase((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2757,16 +2758,16 @@ bool JSB_cpRatchetJointSetPhase(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpRatchetJointSetRatchet(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpRatchetJointSetRatchet((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2774,9 +2775,9 @@ bool JSB_cpRatchetJointSetRatchet(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpResetShapeIdCounter(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpResetShapeIdCounter( ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2784,16 +2785,16 @@ bool JSB_cpResetShapeIdCounter(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpRotaryLimitJointGetMax(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpRotaryLimitJointGetMax((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2801,16 +2802,16 @@ bool JSB_cpRotaryLimitJointGetMax(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpRotaryLimitJointGetMin(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpRotaryLimitJointGetMin((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2818,21 +2819,21 @@ bool JSB_cpRotaryLimitJointGetMin(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpConstraint* bool JSB_cpRotaryLimitJointNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; double arg2; double arg3; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg3 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); + ok &= JS::ToNumber( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraint* ret_val; ret_val = cpRotaryLimitJointNew((cpBody*)arg0 , (cpBody*)arg1 , (cpFloat)arg2 , (cpFloat)arg3 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2841,16 +2842,16 @@ bool JSB_cpRotaryLimitJointNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpRotaryLimitJointSetMax(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpRotaryLimitJointSetMax((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2858,16 +2859,16 @@ bool JSB_cpRotaryLimitJointSetMax(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpRotaryLimitJointSetMin(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpRotaryLimitJointSetMin((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2875,18 +2876,18 @@ bool JSB_cpRotaryLimitJointSetMin(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpSegmentShapeGetA(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpSegmentShapeGetA((cpShape*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2895,18 +2896,18 @@ bool JSB_cpSegmentShapeGetA(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpSegmentShapeGetB(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpSegmentShapeGetB((cpShape*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2915,18 +2916,18 @@ bool JSB_cpSegmentShapeGetB(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpSegmentShapeGetNormal(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpSegmentShapeGetNormal((cpShape*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2935,16 +2936,16 @@ bool JSB_cpSegmentShapeGetNormal(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSegmentShapeGetRadius(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpSegmentShapeGetRadius((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -2952,21 +2953,21 @@ bool JSB_cpSegmentShapeGetRadius(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpShape* bool JSB_cpSegmentShapeNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpVect arg1; cpVect arg2; double arg3; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg3 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); + ok &= JS::ToNumber( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShape* ret_val; ret_val = cpSegmentShapeNew((cpBody*)arg0 , (cpVect)arg1 , (cpVect)arg2 , (cpFloat)arg3 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -2975,17 +2976,17 @@ bool JSB_cpSegmentShapeNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSegmentShapeSetNeighbors(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; cpVect arg1; cpVect arg2; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSegmentShapeSetNeighbors((cpShape*)arg0 , (cpVect)arg1 , (cpVect)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2993,18 +2994,18 @@ bool JSB_cpSegmentShapeSetNeighbors(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBB bool JSB_cpShapeCacheBB(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBB ret_val; ret_val = cpShapeCacheBB((cpShape*)arg0 ); jsval ret_jsval = cpBB_to_jsval( cx, (cpBB)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3013,15 +3014,15 @@ bool JSB_cpShapeCacheBB(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpShapeDestroy(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeDestroy((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3029,15 +3030,15 @@ bool JSB_cpShapeDestroy(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpShapeFree(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeFree((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3045,18 +3046,18 @@ bool JSB_cpShapeFree(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBB bool JSB_cpShapeGetBB(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBB ret_val; ret_val = cpShapeGetBB((cpShape*)arg0 ); jsval ret_jsval = cpBB_to_jsval( cx, (cpBB)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3065,18 +3066,18 @@ bool JSB_cpShapeGetBB(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBody* bool JSB_cpShapeGetBody(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBody* ret_val; ret_val = cpShapeGetBody((cpShape*)arg0 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3085,18 +3086,18 @@ bool JSB_cpShapeGetBody(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpCollisionType bool JSB_cpShapeGetCollisionType(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpCollisionType ret_val; ret_val = cpShapeGetCollisionType((cpShape*)arg0 ); jsval ret_jsval = uint32_to_jsval( cx, (cpCollisionType)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3105,16 +3106,16 @@ bool JSB_cpShapeGetCollisionType(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpShapeGetElasticity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpShapeGetElasticity((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3122,16 +3123,16 @@ bool JSB_cpShapeGetElasticity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpShapeGetFriction(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpShapeGetFriction((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3139,18 +3140,18 @@ bool JSB_cpShapeGetFriction(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpGroup bool JSB_cpShapeGetGroup(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpGroup ret_val; ret_val = cpShapeGetGroup((cpShape*)arg0 ); jsval ret_jsval = uint32_to_jsval( cx, (cpGroup)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3159,16 +3160,16 @@ bool JSB_cpShapeGetGroup(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpLayers bool JSB_cpShapeGetLayers(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpLayers ret_val; ret_val = cpShapeGetLayers((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, UINT_TO_JSVAL((uint32_t)ret_val)); + args.rval().set(UINT_TO_JSVAL((uint32_t)ret_val)); return true; } @@ -3176,16 +3177,16 @@ bool JSB_cpShapeGetLayers(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpShapeGetSensor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpShapeGetSensor((cpShape*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -3193,18 +3194,18 @@ bool JSB_cpShapeGetSensor(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpSpace* bool JSB_cpShapeGetSpace(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpace* ret_val; ret_val = cpShapeGetSpace((cpShape*)arg0 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3213,18 +3214,18 @@ bool JSB_cpShapeGetSpace(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpShapeGetSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpShapeGetSurfaceVelocity((cpShape*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3233,17 +3234,17 @@ bool JSB_cpShapeGetSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpShapePointQuery(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpShapePointQuery((cpShape*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -3251,16 +3252,16 @@ bool JSB_cpShapePointQuery(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpShapeSetBody(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; cpBody* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetBody((cpShape*)arg0 , (cpBody*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3268,16 +3269,16 @@ bool JSB_cpShapeSetBody(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpShapeSetCollisionType(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; cpCollisionType arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_uint( cx, *argvp++, (unsigned int*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_uint( cx, args.get(1), (unsigned int*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetCollisionType((cpShape*)arg0 , (cpCollisionType)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3285,16 +3286,16 @@ bool JSB_cpShapeSetCollisionType(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpShapeSetElasticity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetElasticity((cpShape*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3302,16 +3303,16 @@ bool JSB_cpShapeSetElasticity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpShapeSetFriction(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetFriction((cpShape*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3319,16 +3320,16 @@ bool JSB_cpShapeSetFriction(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpShapeSetGroup(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; cpGroup arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_uint( cx, *argvp++, (unsigned int*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_uint( cx, args.get(1), (unsigned int*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetGroup((cpShape*)arg0 , (cpGroup)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3336,16 +3337,16 @@ bool JSB_cpShapeSetGroup(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpShapeSetLayers(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; uint32_t arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetLayers((cpShape*)arg0 , (cpLayers)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3353,16 +3354,16 @@ bool JSB_cpShapeSetLayers(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpShapeSetSensor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; int32_t arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetSensor((cpShape*)arg0 , (cpBool)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3370,16 +3371,16 @@ bool JSB_cpShapeSetSensor(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpShapeSetSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShapeSetSurfaceVelocity((cpShape*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3387,20 +3388,20 @@ bool JSB_cpShapeSetSurfaceVelocity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBB bool JSB_cpShapeUpdate(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg0; cpVect arg1; cpVect arg2; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBB ret_val; ret_val = cpShapeUpdate((cpShape*)arg0 , (cpVect)arg1 , (cpVect)arg2 ); jsval ret_jsval = cpBB_to_jsval( cx, (cpBB)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3409,16 +3410,16 @@ bool JSB_cpShapeUpdate(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSimpleMotorGetRate(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpSimpleMotorGetRate((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3426,20 +3427,20 @@ bool JSB_cpSimpleMotorGetRate(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpConstraint* bool JSB_cpSimpleMotorNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; double arg2; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraint* ret_val; ret_val = cpSimpleMotorNew((cpBody*)arg0 , (cpBody*)arg1 , (cpFloat)arg2 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3448,16 +3449,16 @@ bool JSB_cpSimpleMotorNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSimpleMotorSetRate(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSimpleMotorSetRate((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3465,18 +3466,18 @@ bool JSB_cpSimpleMotorSetRate(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpSlideJointGetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpSlideJointGetAnchr1((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3485,18 +3486,18 @@ bool JSB_cpSlideJointGetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpSlideJointGetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpSlideJointGetAnchr2((cpConstraint*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3505,16 +3506,16 @@ bool JSB_cpSlideJointGetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSlideJointGetMax(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpSlideJointGetMax((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3522,16 +3523,16 @@ bool JSB_cpSlideJointGetMax(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSlideJointGetMin(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpSlideJointGetMin((cpConstraint*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3539,23 +3540,23 @@ bool JSB_cpSlideJointGetMin(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpConstraint* bool JSB_cpSlideJointNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 6, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; cpBody* arg1; cpVect arg2; cpVect arg3; double arg4; double arg5; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg2 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg3 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg4 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg5 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(3), (cpVect*) &arg3 ); + ok &= JS::ToNumber( cx, args.get(4), &arg4 ); + ok &= JS::ToNumber( cx, args.get(5), &arg5 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraint* ret_val; ret_val = cpSlideJointNew((cpBody*)arg0 , (cpBody*)arg1 , (cpVect)arg2 , (cpVect)arg3 , (cpFloat)arg4 , (cpFloat)arg5 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3564,16 +3565,16 @@ bool JSB_cpSlideJointNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSlideJointSetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSlideJointSetAnchr1((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3581,16 +3582,16 @@ bool JSB_cpSlideJointSetAnchr1(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSlideJointSetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSlideJointSetAnchr2((cpConstraint*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3598,16 +3599,16 @@ bool JSB_cpSlideJointSetAnchr2(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSlideJointSetMax(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSlideJointSetMax((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3615,16 +3616,16 @@ bool JSB_cpSlideJointSetMax(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSlideJointSetMin(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSlideJointSetMin((cpConstraint*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3632,16 +3633,16 @@ bool JSB_cpSlideJointSetMin(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceActivateShapesTouchingShape(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpShape* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceActivateShapesTouchingShape((cpSpace*)arg0 , (cpShape*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3649,19 +3650,19 @@ bool JSB_cpSpaceActivateShapesTouchingShape(JSContext *cx, uint32_t argc, jsval // Ret value: cpBody* bool JSB_cpSpaceAddBody(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpBody* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBody* ret_val; ret_val = cpSpaceAddBody((cpSpace*)arg0 , (cpBody*)arg1 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3670,19 +3671,19 @@ bool JSB_cpSpaceAddBody(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpConstraint* bool JSB_cpSpaceAddConstraint(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpConstraint* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpConstraint* ret_val; ret_val = cpSpaceAddConstraint((cpSpace*)arg0 , (cpConstraint*)arg1 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3691,19 +3692,19 @@ bool JSB_cpSpaceAddConstraint(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpShape* bool JSB_cpSpaceAddShape(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpShape* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShape* ret_val; ret_val = cpSpaceAddShape((cpSpace*)arg0 , (cpShape*)arg1 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3712,19 +3713,19 @@ bool JSB_cpSpaceAddShape(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpShape* bool JSB_cpSpaceAddStaticShape(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpShape* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShape* ret_val; ret_val = cpSpaceAddStaticShape((cpSpace*)arg0 , (cpShape*)arg1 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3733,17 +3734,17 @@ bool JSB_cpSpaceAddStaticShape(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpSpaceContainsBody(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpBody* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpSpaceContainsBody((cpSpace*)arg0 , (cpBody*)arg1 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -3751,17 +3752,17 @@ bool JSB_cpSpaceContainsBody(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpSpaceContainsConstraint(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpConstraint* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpSpaceContainsConstraint((cpSpace*)arg0 , (cpConstraint*)arg1 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -3769,17 +3770,17 @@ bool JSB_cpSpaceContainsConstraint(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpSpaceContainsShape(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpShape* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpSpaceContainsShape((cpSpace*)arg0 , (cpShape*)arg1 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -3787,15 +3788,15 @@ bool JSB_cpSpaceContainsShape(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceDestroy(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceDestroy((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3803,15 +3804,15 @@ bool JSB_cpSpaceDestroy(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceFree(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceFree((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3819,16 +3820,16 @@ bool JSB_cpSpaceFree(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSpaceGetCollisionBias(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpSpaceGetCollisionBias((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3836,16 +3837,16 @@ bool JSB_cpSpaceGetCollisionBias(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpTimestamp bool JSB_cpSpaceGetCollisionPersistence(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpTimestamp ret_val; ret_val = cpSpaceGetCollisionPersistence((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, UINT_TO_JSVAL((uint32_t)ret_val)); + args.rval().set(UINT_TO_JSVAL((uint32_t)ret_val)); return true; } @@ -3853,16 +3854,16 @@ bool JSB_cpSpaceGetCollisionPersistence(JSContext *cx, uint32_t argc, jsval *vp) // Ret value: cpFloat bool JSB_cpSpaceGetCollisionSlop(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpSpaceGetCollisionSlop((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3870,16 +3871,16 @@ bool JSB_cpSpaceGetCollisionSlop(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSpaceGetCurrentTimeStep(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpSpaceGetCurrentTimeStep((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3887,16 +3888,16 @@ bool JSB_cpSpaceGetCurrentTimeStep(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSpaceGetDamping(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpSpaceGetDamping((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3904,16 +3905,16 @@ bool JSB_cpSpaceGetDamping(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpSpaceGetEnableContactGraph(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpSpaceGetEnableContactGraph((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -3921,18 +3922,18 @@ bool JSB_cpSpaceGetEnableContactGraph(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpSpaceGetGravity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpSpaceGetGravity((cpSpace*)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -3941,16 +3942,16 @@ bool JSB_cpSpaceGetGravity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSpaceGetIdleSpeedThreshold(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpSpaceGetIdleSpeedThreshold((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3958,16 +3959,16 @@ bool JSB_cpSpaceGetIdleSpeedThreshold(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: int bool JSB_cpSpaceGetIterations(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); int ret_val; ret_val = cpSpaceGetIterations((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -3975,16 +3976,16 @@ bool JSB_cpSpaceGetIterations(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpSpaceGetSleepTimeThreshold(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpSpaceGetSleepTimeThreshold((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -3992,18 +3993,18 @@ bool JSB_cpSpaceGetSleepTimeThreshold(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBody* bool JSB_cpSpaceGetStaticBody(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBody* ret_val; ret_val = cpSpaceGetStaticBody((cpSpace*)arg0 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4012,18 +4013,18 @@ bool JSB_cpSpaceGetStaticBody(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpSpace* bool JSB_cpSpaceInit(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpace* ret_val; ret_val = cpSpaceInit((cpSpace*)arg0 ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4032,16 +4033,16 @@ bool JSB_cpSpaceInit(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpSpaceIsLocked(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpSpaceIsLocked((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -4049,12 +4050,13 @@ bool JSB_cpSpaceIsLocked(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpSpace* bool JSB_cpSpaceNew(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpSpace* ret_val; ret_val = cpSpaceNew( ); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4063,23 +4065,23 @@ bool JSB_cpSpaceNew(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpShape* bool JSB_cpSpacePointQueryFirst(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpVect arg1; uint32_t arg2; cpGroup arg3; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg2 ); - ok &= jsval_to_uint( cx, *argvp++, (unsigned int*) &arg3 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= jsval_to_uint32( cx, args.get(2), &arg2 ); + ok &= jsval_to_uint( cx, args.get(3), (unsigned int*) &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpShape* ret_val; ret_val = cpSpacePointQueryFirst((cpSpace*)arg0 , (cpVect)arg1 , (cpLayers)arg2 , (cpGroup)arg3 ); if(ret_val) { jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); } else { - JS_SET_RVAL(cx, vp, JSVAL_NULL); + args.rval().set(JSVAL_NULL); } return true; @@ -4089,16 +4091,16 @@ bool JSB_cpSpacePointQueryFirst(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceReindexShape(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpShape* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceReindexShape((cpSpace*)arg0 , (cpShape*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4106,16 +4108,16 @@ bool JSB_cpSpaceReindexShape(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceReindexShapesForBody(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpBody* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceReindexShapesForBody((cpSpace*)arg0 , (cpBody*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4123,15 +4125,15 @@ bool JSB_cpSpaceReindexShapesForBody(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceReindexStatic(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceReindexStatic((cpSpace*)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4139,16 +4141,16 @@ bool JSB_cpSpaceReindexStatic(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceRemoveBody(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpBody* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceRemoveBody((cpSpace*)arg0 , (cpBody*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4156,16 +4158,16 @@ bool JSB_cpSpaceRemoveBody(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceRemoveConstraint(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpConstraint* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceRemoveConstraint((cpSpace*)arg0 , (cpConstraint*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4173,16 +4175,16 @@ bool JSB_cpSpaceRemoveConstraint(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceRemoveShape(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpShape* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceRemoveShape((cpSpace*)arg0 , (cpShape*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4190,16 +4192,16 @@ bool JSB_cpSpaceRemoveShape(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceRemoveStaticShape(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpShape* arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(1), (void**)&arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceRemoveStaticShape((cpSpace*)arg0 , (cpShape*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4207,16 +4209,16 @@ bool JSB_cpSpaceRemoveStaticShape(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceSetCollisionBias(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetCollisionBias((cpSpace*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4224,16 +4226,16 @@ bool JSB_cpSpaceSetCollisionBias(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceSetCollisionPersistence(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; uint32_t arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetCollisionPersistence((cpSpace*)arg0 , (cpTimestamp)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4241,16 +4243,16 @@ bool JSB_cpSpaceSetCollisionPersistence(JSContext *cx, uint32_t argc, jsval *vp) // Ret value: void bool JSB_cpSpaceSetCollisionSlop(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetCollisionSlop((cpSpace*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4258,16 +4260,16 @@ bool JSB_cpSpaceSetCollisionSlop(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceSetDamping(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetDamping((cpSpace*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4275,16 +4277,16 @@ bool JSB_cpSpaceSetDamping(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceSetEnableContactGraph(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; int32_t arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetEnableContactGraph((cpSpace*)arg0 , (cpBool)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4292,16 +4294,16 @@ bool JSB_cpSpaceSetEnableContactGraph(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceSetGravity(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; cpVect arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetGravity((cpSpace*)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4309,16 +4311,16 @@ bool JSB_cpSpaceSetGravity(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceSetIdleSpeedThreshold(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetIdleSpeedThreshold((cpSpace*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4326,16 +4328,16 @@ bool JSB_cpSpaceSetIdleSpeedThreshold(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceSetIterations(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; int32_t arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetIterations((cpSpace*)arg0 , (int)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4343,16 +4345,16 @@ bool JSB_cpSpaceSetIterations(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceSetSleepTimeThreshold(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceSetSleepTimeThreshold((cpSpace*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4360,16 +4362,16 @@ bool JSB_cpSpaceSetSleepTimeThreshold(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceStep(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; double arg1; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceStep((cpSpace*)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4377,17 +4379,17 @@ bool JSB_cpSpaceStep(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_cpSpaceUseSpatialHash(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; double arg1; int32_t arg2; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSpaceUseSpatialHash((cpSpace*)arg0 , (cpFloat)arg1 , (int)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4395,16 +4397,16 @@ bool JSB_cpSpaceUseSpatialHash(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpfabs(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpfabs((cpFloat)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4412,18 +4414,18 @@ bool JSB_cpfabs(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpfclamp(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; double arg1; double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpfclamp((cpFloat)arg0 , (cpFloat)arg1 , (cpFloat)arg2 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4431,16 +4433,16 @@ bool JSB_cpfclamp(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpfclamp01(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpfclamp01((cpFloat)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4448,18 +4450,18 @@ bool JSB_cpfclamp01(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpflerp(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; double arg1; double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpflerp((cpFloat)arg0 , (cpFloat)arg1 , (cpFloat)arg2 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4467,18 +4469,18 @@ bool JSB_cpflerp(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpflerpconst(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; double arg1; double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpflerpconst((cpFloat)arg0 , (cpFloat)arg1 , (cpFloat)arg2 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4486,17 +4488,17 @@ bool JSB_cpflerpconst(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpfmax(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpfmax((cpFloat)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4504,17 +4506,17 @@ bool JSB_cpfmax(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpfmin(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpfmin((cpFloat)arg0 , (cpFloat)arg1 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4522,19 +4524,19 @@ bool JSB_cpfmin(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvadd(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvadd((cpVect)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4543,19 +4545,19 @@ bool JSB_cpvadd(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvclamp(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; double arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvclamp((cpVect)arg0 , (cpFloat)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4564,17 +4566,17 @@ bool JSB_cpvclamp(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpvcross(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpvcross((cpVect)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4582,17 +4584,17 @@ bool JSB_cpvcross(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpvdist(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpvdist((cpVect)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4600,17 +4602,17 @@ bool JSB_cpvdist(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpvdistsq(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpvdistsq((cpVect)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4618,17 +4620,17 @@ bool JSB_cpvdistsq(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpvdot(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpvdot((cpVect)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4636,17 +4638,17 @@ bool JSB_cpvdot(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpveql(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpveql((cpVect)arg0 , (cpVect)arg1 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -4654,18 +4656,18 @@ bool JSB_cpveql(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvforangle(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg0 ); + ok &= JS::ToNumber( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvforangle((cpFloat)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4674,16 +4676,16 @@ bool JSB_cpvforangle(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpvlength(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpvlength((cpVect)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4691,16 +4693,16 @@ bool JSB_cpvlength(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpvlengthsq(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpvlengthsq((cpVect)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -4708,20 +4710,20 @@ bool JSB_cpvlengthsq(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvlerp(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; double arg2; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvlerp((cpVect)arg0 , (cpVect)arg1 , (cpFloat)arg2 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4730,20 +4732,20 @@ bool JSB_cpvlerp(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvlerpconst(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; double arg2; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvlerpconst((cpVect)arg0 , (cpVect)arg1 , (cpFloat)arg2 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4752,19 +4754,19 @@ bool JSB_cpvlerpconst(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvmult(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; double arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= JS::ToNumber( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvmult((cpVect)arg0 , (cpFloat)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4773,18 +4775,18 @@ bool JSB_cpvmult(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpBool bool JSB_cpvnear(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; double arg2; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpBool ret_val; ret_val = cpvnear((cpVect)arg0 , (cpVect)arg1 , (cpFloat)arg2 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -4792,18 +4794,18 @@ bool JSB_cpvnear(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvneg(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvneg((cpVect)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4812,18 +4814,18 @@ bool JSB_cpvneg(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvnormalize(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvnormalize((cpVect)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4832,18 +4834,18 @@ bool JSB_cpvnormalize(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvnormalize_safe(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvnormalize_safe((cpVect)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4852,18 +4854,18 @@ bool JSB_cpvnormalize_safe(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvperp(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvperp((cpVect)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4872,19 +4874,19 @@ bool JSB_cpvperp(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvproject(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvproject((cpVect)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4893,19 +4895,19 @@ bool JSB_cpvproject(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvrotate(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvrotate((cpVect)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4914,18 +4916,18 @@ bool JSB_cpvrotate(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvrperp(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvrperp((cpVect)arg0 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4934,20 +4936,20 @@ bool JSB_cpvrperp(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvslerp(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; double arg2; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvslerp((cpVect)arg0 , (cpVect)arg1 , (cpFloat)arg2 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4956,20 +4958,20 @@ bool JSB_cpvslerp(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvslerpconst(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; double arg2; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, *argvp++), &arg2 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); + ok &= JS::ToNumber( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvslerpconst((cpVect)arg0 , (cpVect)arg1 , (cpFloat)arg2 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4978,19 +4980,19 @@ bool JSB_cpvslerpconst(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvsub(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvsub((cpVect)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } @@ -4999,16 +5001,16 @@ bool JSB_cpvsub(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpFloat bool JSB_cpvtoangle(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpFloat ret_val; ret_val = cpvtoangle((cpVect)arg0 ); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(ret_val)); + args.rval().set(DOUBLE_TO_JSVAL(ret_val)); return true; } @@ -5016,19 +5018,19 @@ bool JSB_cpvtoangle(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: cpVect bool JSB_cpvunrotate(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect arg0; cpVect arg1; - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg0 ); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &arg1 ); + ok &= jsval_to_cpVect( cx, args.get(0), (cpVect*) &arg0 ); + ok &= jsval_to_cpVect( cx, args.get(1), (cpVect*) &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpVect ret_val; ret_val = cpvunrotate((cpVect)arg0 , (cpVect)arg1 ); jsval ret_jsval = cpVect_to_jsval( cx, (cpVect)ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } diff --git a/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp b/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp index 3b4452c9e7..ad28fd5381 100644 --- a/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp +++ b/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp @@ -25,6 +25,7 @@ #include "jsfriendapi.h" #include "extensions/cocos-ext.h" #include "js_bindings_config.h" +#include "cocos2d_specifics.hpp" #ifdef JSB_INCLUDE_CHIPMUNK #include "js_bindings_chipmunk_manual.h" @@ -47,10 +48,11 @@ static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { p = typeMapIter->second; CCASSERT(p, "The value is null."); - JSObject *_tmp = JS_NewObject(cx, p->jsclass, p->proto, p->parentProto); + JSObject *_tmp = JS_NewObject(cx, p->jsclass, JS::RootedObject(cx, p->proto), JS::RootedObject(cx, p->parentProto)); js_proxy_t *pp = jsb_new_proxy(cobj, _tmp); - JS_AddObjectRoot(cx, &pp->obj); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp)); + JS::AddObjectRoot(cx, &pp->obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().set(OBJECT_TO_JSVAL(_tmp)); return true; } @@ -75,22 +77,23 @@ void JSPROXY_CCPhysicsSprite_finalize(JSFreeOp *fop, JSObject *obj) // Arguments: // Ret value: BOOL (b) bool JSPROXY_CCPhysicsSprite_isDirty(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); PhysicsSprite* real = (PhysicsSprite *)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, real) if (real->isDirty()) { - JS_SET_RVAL(cx, vp, JSVAL_TRUE); + args.rval().set(JSVAL_TRUE); } - else JS_SET_RVAL(cx, vp, JSVAL_FALSE); + else args.rval().set(JSVAL_FALSE); return true; } // Arguments: // Ret value: cpBody* (N/A) bool JSPROXY_CCPhysicsSprite_getCPBody(JSContext *cx, uint32_t argc, jsval *vp) { - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); PhysicsSprite* real = (PhysicsSprite *)(proxy ? proxy->ptr : NULL); @@ -98,8 +101,8 @@ bool JSPROXY_CCPhysicsSprite_getCPBody(JSContext *cx, uint32_t argc, jsval *vp) cpBody* ret_val; ret_val = real->getCPBody(); - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JSB_cpBody_object, JSB_cpBody_class, "cpBody" ); - JS_SET_RVAL(cx, vp, ret_jsval); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpBody" ); + args.rval().set(ret_jsval); return true; } @@ -107,7 +110,7 @@ bool JSPROXY_CCPhysicsSprite_getCPBody(JSContext *cx, uint32_t argc, jsval *vp) // Arguments: // Ret value: BOOL (b) bool JSPROXY_CCPhysicsSprite_ignoreBodyRotation(JSContext *cx, uint32_t argc, jsval *vp) { - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); PhysicsSprite* real = (PhysicsSprite *)(proxy ? proxy->ptr : NULL); @@ -116,7 +119,7 @@ bool JSPROXY_CCPhysicsSprite_ignoreBodyRotation(JSContext *cx, uint32_t argc, js bool ret_val; ret_val = real->isIgnoreBodyRotation(); - JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret_val)); + args.rval().set(BOOLEAN_TO_JSVAL(ret_val)); return true; } @@ -129,16 +132,16 @@ bool JSPROXY_CCPhysicsSprite_setCPBody_(JSContext *cx, uint32_t argc, jsval *vp) PhysicsSprite* real = (PhysicsSprite *)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, real) - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); if( ! ok ) return false; real->setCPBody((cpBody*)arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -151,11 +154,11 @@ bool JSPROXY_CCPhysicsSprite_setIgnoreBodyRotation_(JSContext *cx, uint32_t argc PhysicsSprite* real = (PhysicsSprite *)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, real) - jsval *argvp = JS_ARGV(cx,vp); - bool arg0 = JS::ToBoolean( JS::RootedValue(cx, *argvp++) ); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool arg0 = JS::ToBoolean( args.get(0) ); real->setIgnoreBodyRotation((bool)arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -180,11 +183,11 @@ void JSB_CCPhysicsDebugNode_finalize(JSFreeOp *fop, JSObject *obj) // Ret value: PhysicsDebugNode* (o) bool JSB_CCPhysicsDebugNode_debugNodeForCPSpace__static(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); PhysicsDebugNode* ret = PhysicsDebugNode::create(arg0); @@ -200,15 +203,15 @@ bool JSB_CCPhysicsDebugNode_debugNodeForCPSpace__static(JSContext *cx, uint32_t typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JSObject *obj = JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); jsret = OBJECT_TO_JSVAL(obj); js_proxy_t *p = jsb_new_proxy(ret, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "CCDebugNode"); + JS::AddNamedObjectRoot(cx, &p->obj, "CCDebugNode"); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -223,22 +226,22 @@ bool JSB_CCPhysicsDebugNode_setSpace_(JSContext *cx, uint32_t argc, jsval *vp) { TEST_NATIVE_OBJECT(cx, real) JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpSpace* arg0; - ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); + ok &= jsval_to_opaque( cx, args.get(0), (void**)&arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); real->setSpace(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } // Arguments: // Ret value: cpSpace* (N/A) bool JSB_CCPhysicsDebugNode_space(JSContext *cx, uint32_t argc, jsval *vp) { - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(jsthis); PhysicsDebugNode* real = (PhysicsDebugNode *)(proxy ? proxy->ptr : NULL); @@ -249,14 +252,14 @@ bool JSB_CCPhysicsDebugNode_space(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = real->getSpace(); jsval ret_jsval = opaque_to_jsval( cx, ret_val ); - JS_SET_RVAL(cx, vp, ret_jsval); + args.rval().set(ret_jsval); return true; } bool JSB_CCPhysicsDebugNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; PhysicsDebugNode* cobj = new (std::nothrow) PhysicsDebugNode(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -270,17 +273,18 @@ bool JSB_CCPhysicsDebugNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + //JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, typeClass->jsclass, args)); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto))); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "PhysicsDebugNode"); + JS::AddNamedObjectRoot(cx, &p->obj, "PhysicsDebugNode"); if (JS_HasProperty(cx, obj, "_ctor", &ok)) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } -void JSB_CCPhysicsDebugNode_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_CCPhysicsDebugNode_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_CCPhysicsDebugNode_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_CCPhysicsDebugNode_class->name = name; @@ -295,7 +299,7 @@ void JSB_CCPhysicsDebugNode_createClass(JSContext *cx, JSObject* globalObj, cons JSB_CCPhysicsDebugNode_class->flags = 0; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("_setSpace", JSB_CCPhysicsDebugNode_setSpace_, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -316,7 +320,7 @@ void JSB_CCPhysicsDebugNode_createClass(JSContext *cx, JSObject* globalObj, cons typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSB_CCPhysicsDebugNode_object = JS_InitClass(cx, globalObj, typeClass->proto, JSB_CCPhysicsDebugNode_class, JSB_CCPhysicsDebugNode_constructor, 0,properties,funcs,NULL,st_funcs); + JSB_CCPhysicsDebugNode_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, typeClass->proto), JSB_CCPhysicsDebugNode_class, JSB_CCPhysicsDebugNode_constructor, 0,properties,funcs,NULL,st_funcs); TypeTest t; js_type_class_t *p; @@ -336,13 +340,13 @@ void JSB_CCPhysicsDebugNode_createClass(JSContext *cx, JSObject* globalObj, cons // Ret value: PhysicsSprite* (o) bool JSPROXY_CCPhysicsSprite_spriteWithFile_rect__static(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); cocos2d::Rect arg1; - ok &= jsval_to_ccrect(cx, argv[1], &arg1); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); PhysicsSprite* ret = PhysicsSprite::create(arg0, arg1); @@ -358,20 +362,20 @@ bool JSPROXY_CCPhysicsSprite_spriteWithFile_rect__static(JSContext *cx, uint32_t typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JSObject *obj = JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); jsret = OBJECT_TO_JSVAL(obj); js_proxy_t *p = jsb_new_proxy(ret, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite"); + JS::AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite"); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); PhysicsSprite* ret = PhysicsSprite::create(arg0); @@ -386,15 +390,15 @@ bool JSPROXY_CCPhysicsSprite_spriteWithFile_rect__static(JSContext *cx, uint32_t CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JSObject *obj = JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); jsret = OBJECT_TO_JSVAL(obj); js_proxy_t *p = jsb_new_proxy(ret, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite"); + JS::AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite"); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } return false; @@ -404,12 +408,12 @@ bool JSPROXY_CCPhysicsSprite_spriteWithFile_rect__static(JSContext *cx, uint32_t // Arguments: SpriteFrame* // Ret value: PhysicsSprite* (o) bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrame__static(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cocos2d::SpriteFrame* arg0; if (argc >= 1) { do { js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::SpriteFrame*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, arg0) @@ -427,27 +431,27 @@ bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrame__static(JSContext *cx, uint32 CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JSObject *obj = JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); jsret = OBJECT_TO_JSVAL(obj); js_proxy_t *p = jsb_new_proxy(ret, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite"); + JS::AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite"); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } // Arguments: NSString* // Ret value: PhysicsSprite* (o) bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrameName__static(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; const char* arg0; std::string arg0_tmp; if (argc == 1) { - ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); PhysicsSprite* ret = PhysicsSprite::createWithSpriteFrameName(arg0); @@ -461,15 +465,15 @@ bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrameName__static(JSContext *cx, ui CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JSObject *obj = JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); jsret = OBJECT_TO_JSVAL(obj); js_proxy_t *p = jsb_new_proxy(ret, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite"); + JS::AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite"); } else { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -478,7 +482,7 @@ bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrameName__static(JSContext *cx, ui } bool JSPROXY_CCPhysicsSprite_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; PhysicsSprite* cobj = new PhysicsSprite(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -492,34 +496,35 @@ bool JSPROXY_CCPhysicsSprite_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + //JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, typeClass->jsclass, args)); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto))); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::PhysicsSprite"); + JS::AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::PhysicsSprite"); if (JS_HasProperty(cx, obj, "_ctor", &ok)) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } static bool JSPROXY_CCPhysicsSprite_ctor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); PhysicsSprite *nobj = new PhysicsSprite(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::SpriteFrame"); + JS::AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::SpriteFrame"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound)) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void JSPROXY_CCPhysicsSprite_createClass(JSContext *cx, JSObject* globalObj) +void JSPROXY_CCPhysicsSprite_createClass(JSContext *cx, JS::HandleObject globalObj) { JSPROXY_CCPhysicsSprite_class = (JSClass *)calloc(1, sizeof(JSClass)); JSPROXY_CCPhysicsSprite_class->name = "PhysicsSprite"; @@ -534,7 +539,7 @@ void JSPROXY_CCPhysicsSprite_createClass(JSContext *cx, JSObject* globalObj) JSPROXY_CCPhysicsSprite_class->flags = 0; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("isDirty", JSPROXY_CCPhysicsSprite_isDirty, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -560,7 +565,7 @@ void JSPROXY_CCPhysicsSprite_createClass(JSContext *cx, JSObject* globalObj) typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSPROXY_CCPhysicsSprite_object = JS_InitClass(cx, globalObj, typeClass->proto, JSPROXY_CCPhysicsSprite_class,/* dummy_constructor*/JSPROXY_CCPhysicsSprite_constructor, 0,properties,funcs,NULL,st_funcs); + JSPROXY_CCPhysicsSprite_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, typeClass->proto), JSPROXY_CCPhysicsSprite_class,/* dummy_constructor*/JSPROXY_CCPhysicsSprite_constructor, 0,properties,funcs,NULL,st_funcs); TypeTest t; js_type_class_t *p; @@ -576,34 +581,16 @@ void JSPROXY_CCPhysicsSprite_createClass(JSContext *cx, JSObject* globalObj) } -void register_CCPhysicsSprite(JSContext *cx, JSObject *obj) { - JS::RootedValue nsval(cx); - JS::RootedObject ns(cx); - JS_GetProperty(cx, obj, "cc", &nsval); - if (nsval == JSVAL_VOID) { - ns = JS_NewObject(cx, NULL, NULL, NULL); - nsval = OBJECT_TO_JSVAL(ns); - JS_SetProperty(cx, obj, "cc", nsval); - } else { - JS_ValueToObject(cx, nsval, &ns); - } - obj = ns; - JSPROXY_CCPhysicsSprite_createClass(cx, obj); -} - -void register_CCPhysicsDebugNode(JSContext *cx, JSObject *obj) { - JS::RootedValue nsval(cx); - JS::RootedObject ns(cx); - JS_GetProperty(cx, obj, "cc", &nsval); - if (nsval == JSVAL_VOID) { - ns = JS_NewObject(cx, NULL, NULL, NULL); - nsval = OBJECT_TO_JSVAL(ns); - JS_SetProperty(cx, obj, "cc", nsval); - } else { - JS_ValueToObject(cx, nsval, &ns); - } - obj = ns; - JSB_CCPhysicsDebugNode_createClass(cx, obj, "PhysicsDebugNode"); +void register_CCPhysicsSprite(JSContext *cx, JS::HandleObject obj) { + JS::RootedObject ccObj(cx); + get_or_create_js_obj(cx, obj, "cc", &ccObj); + JSPROXY_CCPhysicsSprite_createClass(cx, ccObj); +} + +void register_CCPhysicsDebugNode(JSContext *cx, JS::HandleObject obj) { + JS::RootedObject ccObj(cx); + get_or_create_js_obj(cx, obj, "cc", &ccObj); + JSB_CCPhysicsDebugNode_createClass(cx, ccObj, "PhysicsDebugNode"); } bool jsval_to_cpBB( JSContext *cx, jsval vp, cpBB *ret ) @@ -641,14 +628,14 @@ bool jsval_to_cpBB( JSContext *cx, jsval vp, cpBB *ret ) jsval cpBB_to_jsval(JSContext *cx, cpBB bb ) { - JSObject *object = JS_NewObject(cx, NULL, NULL, NULL ); + JS::RootedObject object(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); if (!object) return JSVAL_VOID; - if (!JS_DefineProperty(cx, object, "l", DOUBLE_TO_JSVAL(bb.l), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) || - !JS_DefineProperty(cx, object, "b", DOUBLE_TO_JSVAL(bb.b), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) || - !JS_DefineProperty(cx, object, "r", DOUBLE_TO_JSVAL(bb.r), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) || - !JS_DefineProperty(cx, object, "t", DOUBLE_TO_JSVAL(bb.t), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) ) + if (!JS_DefineProperty(cx, object, "l", bb.l, JSPROP_ENUMERATE | JSPROP_PERMANENT) || + !JS_DefineProperty(cx, object, "b", bb.b, JSPROP_ENUMERATE | JSPROP_PERMANENT) || + !JS_DefineProperty(cx, object, "r", bb.r, JSPROP_ENUMERATE | JSPROP_PERMANENT) || + !JS_DefineProperty(cx, object, "t", bb.t, JSPROP_ENUMERATE | JSPROP_PERMANENT) ) return JSVAL_VOID; return OBJECT_TO_JSVAL(object); @@ -694,17 +681,95 @@ bool jsval_to_array_of_cpvect( JSContext *cx, jsval vp, cpVect**verts, int *numV return true; } + +bool jsval_to_cpVect( JSContext *cx, jsval vp, cpVect *ret ) +{ +#ifdef JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES + + JS::RootedObject jsobj(cx); + if( ! JS_ValueToObject( cx, JS::RootedValue(cx, vp), &jsobj ) ) + return false; + + JSB_PRECONDITION( jsobj, "Not a valid JS object"); + + JS::RootedValue valx(cx); + JS::RootedValue valy(cx); + bool ok = true; + ok &= JS_GetProperty(cx, jsobj, "x", &valx); + ok &= JS_GetProperty(cx, jsobj, "y", &valy); + + if( ! ok ) + return false; + + double x, y; + ok &= JS::ToNumber(cx, valx, &x); + ok &= JS::ToNumber(cx, valy, &y); + + if( ! ok ) + return false; + + ret->x = x; + ret->y = y; + + return true; + +#else // #! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES + + JSObject *tmp_arg; + if( ! JS_ValueToObject( cx, vp, &tmp_arg ) ) + return false; + + JSB_PRECONDITION( tmp_arg && JS_IsTypedArrayObject( tmp_arg, cx ), "Not a TypedArray object"); + + JSB_PRECONDITION( JS_GetTypedArrayByteLength( tmp_arg, cx ) == sizeof(cpVect), "Invalid length"); + + *ret = *(cpVect*)JS_GetArrayBufferViewData( tmp_arg, cx ); + + return true; +#endif // #! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES +} + + +jsval cpVect_to_jsval( JSContext *cx, cpVect p) +{ + +#ifdef JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES + + JS::RootedObject object(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr() )); + if (!object) + return JSVAL_VOID; + + if (!JS_DefineProperty(cx, object, "x", p.x, JSPROP_ENUMERATE | JSPROP_PERMANENT) || + !JS_DefineProperty(cx, object, "y", p.y, JSPROP_ENUMERATE | JSPROP_PERMANENT) ) + return JSVAL_VOID; + + return OBJECT_TO_JSVAL(object); + +#else // JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES + +#ifdef __LP64__ + JSObject *typedArray = JS_NewFloat64Array( cx, 2 ); +#else + JSObject *typedArray = JS_NewFloat32Array( cx, 2 ); +#endif + + cpVect *buffer = (cpVect*)JS_GetArrayBufferViewData(typedArray, cx ); + *buffer = p; + return OBJECT_TO_JSVAL(typedArray); +#endif // ! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES +} + #pragma mark - Collision Handler struct collision_handler { cpCollisionType typeA; cpCollisionType typeB; - JSObject *begin; - JSObject *pre; - JSObject *post; - JSObject *separate; - JSObject *jsthis; + JS::Heap begin; + JS::Heap pre; + JS::Heap post; + JS::Heap separate; + JS::Heap jsthis; JSContext *cx; // "owner" of the collision handler @@ -736,8 +801,8 @@ static cpBool myCollisionBegin(cpArbiter *arb, cpSpace *space, void *data) jsval args[2]; if( handler->is_oo ) { - args[0] = c_class_to_jsval(handler->cx, arb, JSB_cpArbiter_object, JSB_cpArbiter_class, "cpArbiter"); - args[1] = c_class_to_jsval(handler->cx, space, JSB_cpSpace_object, JSB_cpSpace_class, "cpArbiter"); + args[0] = c_class_to_jsval(handler->cx, arb, JS::RootedObject(handler->cx, JSB_cpArbiter_object), JSB_cpArbiter_class, "cpArbiter"); + args[1] = c_class_to_jsval(handler->cx, space, JS::RootedObject(handler->cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpArbiter"); } else { args[0] = opaque_to_jsval( handler->cx, arb); args[1] = opaque_to_jsval( handler->cx, space ); @@ -745,12 +810,12 @@ static cpBool myCollisionBegin(cpArbiter *arb, cpSpace *space, void *data) JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - jsval rval; - bool ok = JS_CallFunctionValue( handler->cx, handler->jsthis, OBJECT_TO_JSVAL(handler->begin), 2, args, &rval); + JS::RootedValue rval(handler->cx); + bool ok = JS_CallFunctionValue( handler->cx, JS::RootedObject(handler->cx, handler->jsthis), JS::RootedValue(handler->cx, OBJECT_TO_JSVAL(handler->begin)), JS::HandleValueArray::fromMarkedLocation(2, args), &rval); JSB_PRECONDITION2(ok, handler->cx, cpFalse, "Error calling collision callback: begin"); - if( JSVAL_IS_BOOLEAN(rval) ) { - bool ret = JSVAL_TO_BOOLEAN(rval); + if( rval.isBoolean() ) { + bool ret = rval.toBoolean(); return (cpBool)ret; } return cpTrue; @@ -762,8 +827,8 @@ static cpBool myCollisionPre(cpArbiter *arb, cpSpace *space, void *data) jsval args[2]; if( handler->is_oo ) { - args[0] = c_class_to_jsval(handler->cx, arb, JSB_cpArbiter_object, JSB_cpArbiter_class, "cpArbiter"); - args[1] = c_class_to_jsval(handler->cx, space, JSB_cpSpace_object, JSB_cpSpace_class, "cpArbiter"); + args[0] = c_class_to_jsval(handler->cx, arb, JS::RootedObject(handler->cx, JSB_cpArbiter_object), JSB_cpArbiter_class, "cpArbiter"); + args[1] = c_class_to_jsval(handler->cx, space, JS::RootedObject(handler->cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpArbiter"); } else { args[0] = opaque_to_jsval( handler->cx, arb); args[1] = opaque_to_jsval( handler->cx, space ); @@ -771,12 +836,12 @@ static cpBool myCollisionPre(cpArbiter *arb, cpSpace *space, void *data) JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - jsval rval; - bool ok = JS_CallFunctionValue( handler->cx, handler->jsthis, OBJECT_TO_JSVAL(handler->pre), 2, args, &rval); + JS::RootedValue rval(handler->cx); + bool ok = JS_CallFunctionValue( handler->cx, JS::RootedObject(handler->cx, handler->jsthis), JS::RootedValue(handler->cx, OBJECT_TO_JSVAL(handler->pre)), JS::HandleValueArray::fromMarkedLocation(2, args), &rval); JSB_PRECONDITION2(ok, handler->cx, false, "Error calling collision callback: pre"); - if( JSVAL_IS_BOOLEAN(rval) ) { - bool ret = JSVAL_TO_BOOLEAN(rval); + if( rval.isBoolean() ) { + bool ret = rval.toBoolean(); return (cpBool)ret; } return cpTrue; @@ -789,8 +854,8 @@ static void myCollisionPost(cpArbiter *arb, cpSpace *space, void *data) jsval args[2]; if( handler->is_oo ) { - args[0] = c_class_to_jsval(handler->cx, arb, JSB_cpArbiter_object, JSB_cpArbiter_class, "cpArbiter"); - args[1] = c_class_to_jsval(handler->cx, space, JSB_cpSpace_object, JSB_cpSpace_class, "cpArbiter"); + args[0] = c_class_to_jsval(handler->cx, arb, JS::RootedObject(handler->cx, JSB_cpArbiter_object), JSB_cpArbiter_class, "cpArbiter"); + args[1] = c_class_to_jsval(handler->cx, space, JS::RootedObject(handler->cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpArbiter"); } else { args[0] = opaque_to_jsval( handler->cx, arb); args[1] = opaque_to_jsval( handler->cx, space ); @@ -798,8 +863,8 @@ static void myCollisionPost(cpArbiter *arb, cpSpace *space, void *data) JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - jsval ignore; - bool ok = JS_CallFunctionValue( handler->cx, handler->jsthis, OBJECT_TO_JSVAL(handler->post), 2, args, &ignore); + JS::RootedValue ignore(handler->cx); + bool ok = JS_CallFunctionValue( handler->cx, JS::RootedObject(handler->cx, handler->jsthis), JS::RootedValue(handler->cx, OBJECT_TO_JSVAL(handler->post)), JS::HandleValueArray::fromMarkedLocation(2, args), &ignore); JSB_PRECONDITION2(ok, handler->cx, , "Error calling collision callback: Post"); } @@ -811,8 +876,8 @@ static void myCollisionSeparate(cpArbiter *arb, cpSpace *space, void *data) jsval args[2]; if( handler->is_oo ) { - args[0] = c_class_to_jsval(handler->cx, arb, JSB_cpArbiter_object, JSB_cpArbiter_class, "cpArbiter"); - args[1] = c_class_to_jsval(handler->cx, space, JSB_cpSpace_object, JSB_cpSpace_class, "cpArbiter"); + args[0] = c_class_to_jsval(handler->cx, arb, JS::RootedObject(handler->cx, JSB_cpArbiter_object), JSB_cpArbiter_class, "cpArbiter"); + args[1] = c_class_to_jsval(handler->cx, space, JS::RootedObject(handler->cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpArbiter"); } else { args[0] = opaque_to_jsval( handler->cx, arb); args[1] = opaque_to_jsval( handler->cx, space ); @@ -820,8 +885,8 @@ static void myCollisionSeparate(cpArbiter *arb, cpSpace *space, void *data) JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - jsval ignore; - bool ok = JS_CallFunctionValue( handler->cx, handler->jsthis, OBJECT_TO_JSVAL(handler->separate), 2, args, &ignore); + JS::RootedValue ignore(handler->cx); + bool ok = JS_CallFunctionValue( handler->cx, JS::RootedObject(handler->cx, handler->jsthis), JS::RootedValue(handler->cx, OBJECT_TO_JSVAL(handler->separate)), JS::HandleValueArray::fromMarkedLocation(2, args), &ignore); JSB_PRECONDITION2(ok, handler->cx, , "Error calling collision callback: Separate");} #pragma mark - cpSpace @@ -847,14 +912,14 @@ void JSB_cpSpace_finalize(JSFreeOp *fop, JSObject *jsthis) // unroot it if( current->begin ) { - JS_RemoveObjectRoot(cx, ¤t->begin); + JS::RemoveObjectRoot(cx, ¤t->begin); } if( current->pre ) - JS_RemoveObjectRoot(cx, ¤t->pre); + JS::RemoveObjectRoot(cx, ¤t->pre); if( current->post ) - JS_RemoveObjectRoot(cx, ¤t->post); + JS::RemoveObjectRoot(cx, ¤t->post); if( current->separate ) - JS_RemoveObjectRoot(cx, ¤t->separate); + JS::RemoveObjectRoot(cx, ¤t->separate); HASH_DEL(collision_handler_hash,current); /* delete; users advances to next */ free(current); /* optional- if you want to free */ @@ -884,20 +949,20 @@ bool __jsb_cpSpace_addCollisionHandler(JSContext *cx, jsval *vp, jsval *argvp, c bool ok = true; // args - ok &= jsval_to_int(cx, *argvp++, (int32_t*) &handler->typeA ); - ok &= jsval_to_int(cx, *argvp++, (int32_t*) &handler->typeB ); + ok &= jsval_to_int(cx, JS::RootedValue(cx, *argvp++), (int32_t*) &handler->typeA ); + ok &= jsval_to_int(cx, JS::RootedValue(cx, *argvp++), (int32_t*) &handler->typeB ); // this is no longer passed, so "this" is going to be "this". // ok &= JS_ValueToObject(cx, *argvp++, &handler->jsthis ); handler->jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); - handler->begin = !JSVAL_IS_NULL(*argvp) ? JSVAL_TO_OBJECT(*argvp) : NULL; + handler->begin = argvp->toObjectOrNull(); argvp++; - handler->pre = !JSVAL_IS_NULL(*argvp) ? JSVAL_TO_OBJECT(*argvp) : NULL; + handler->pre = argvp->toObjectOrNull(); argvp++; - handler->post = !JSVAL_IS_NULL(*argvp) ? JSVAL_TO_OBJECT(*argvp) : NULL; + handler->post = argvp->toObjectOrNull(); argvp++; - handler->separate = !JSVAL_IS_NULL(*argvp) ? JSVAL_TO_OBJECT(*argvp) : NULL; + handler->separate = argvp->toObjectOrNull(); argvp++; JSB_PRECONDITION(ok, "Error parsing arguments"); @@ -910,13 +975,13 @@ bool __jsb_cpSpace_addCollisionHandler(JSContext *cx, jsval *vp, jsval *argvp, c // Root it if( handler->begin ) - JS_AddNamedObjectRoot(cx, &handler->begin, "begin collision_handler"); + JS::AddNamedObjectRoot(cx, &handler->begin, "begin collision_handler"); if( handler->pre ) - JS_AddNamedObjectRoot(cx, &handler->pre, "pre collision_handler"); + JS::AddNamedObjectRoot(cx, &handler->pre, "pre collision_handler"); if( handler->post ) - JS_AddNamedObjectRoot(cx, &handler->post, "post collision_handler"); + JS::AddNamedObjectRoot(cx, &handler->post, "post collision_handler"); if( handler->separate ) - JS_AddNamedObjectRoot(cx, &handler->separate, "separate collision_handler"); + JS::AddNamedObjectRoot(cx, &handler->separate, "separate collision_handler"); handler->cx = cx; @@ -943,8 +1008,6 @@ bool __jsb_cpSpace_addCollisionHandler(JSContext *cx, jsval *vp, jsval *argvp, c handler->hash_key = paired_key; HASH_ADD_INT( collision_handler_hash, hash_key, handler ); - - JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; } @@ -953,11 +1016,12 @@ bool JSB_cpSpaceAddCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2(argc==7, cx, false, "Invalid number of arguments"); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); // args cpSpace *space; - bool ok = jsval_to_opaque( cx, *argvp++, (void**)&space); + jsval* argvp = args.array(); + bool ok = jsval_to_opaque( cx, JS::RootedValue(cx, *argvp++), (void**)&space); JSB_PRECONDITION(ok, "Error parsing arguments"); return __jsb_cpSpace_addCollisionHandler(cx, vp, argvp, space, 0); @@ -969,11 +1033,11 @@ bool JSB_cpSpace_addCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2(argc==6, cx, false, "Invalid number of arguments"); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSB_PRECONDITION( jsthis, "Invalid jsthis object"); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); void *handle = proxy->handle; - return __jsb_cpSpace_addCollisionHandler(cx, vp, JS_ARGV(cx,vp), (cpSpace*)handle, 1); + return __jsb_cpSpace_addCollisionHandler(cx, vp, args.array(), (cpSpace*)handle, 1); } bool JSB_cpSpace_setDefaultCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp) @@ -990,11 +1054,11 @@ bool JSB_cpSpace_setDefaultCollisionHandler(JSContext *cx, uint32_t argc, jsval handler->typeB = 0; handler->jsthis = jsthis; - jsval *argv = JS_ARGV(cx,vp); - handler->begin = !JSVAL_IS_NULL(argv[0]) ? JSVAL_TO_OBJECT(argv[0]) : NULL; - handler->pre = !JSVAL_IS_NULL(argv[1]) ? JSVAL_TO_OBJECT(argv[1]) : NULL; - handler->post = !JSVAL_IS_NULL(argv[2]) ? JSVAL_TO_OBJECT(argv[2]) : NULL; - handler->separate = !JSVAL_IS_NULL(argv[3]) ? JSVAL_TO_OBJECT(argv[3]) : NULL; + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + handler->begin = args.get(0).toObjectOrNull(); + handler->pre = args.get(1).toObjectOrNull(); + handler->post = args.get(2).toObjectOrNull(); + handler->separate = args.get(3).toObjectOrNull(); // Object Oriented API ? handler->is_oo = 1; @@ -1019,14 +1083,14 @@ bool JSB_cpSpace_setDefaultCollisionHandler(JSContext *cx, uint32_t argc, jsval HASH_FIND_INT(collision_handler_hash, &paired_key, hashElement); if( hashElement ) { if( hashElement->begin ) { - JS_RemoveObjectRoot(cx, &hashElement->begin); + JS::RemoveObjectRoot(cx, &hashElement->begin); } if( hashElement->pre ) - JS_RemoveObjectRoot(cx, &hashElement->pre); + JS::RemoveObjectRoot(cx, &hashElement->pre); if( hashElement->post ) - JS_RemoveObjectRoot(cx, &hashElement->post); + JS::RemoveObjectRoot(cx, &hashElement->post); if( hashElement->separate ) - JS_RemoveObjectRoot(cx, &hashElement->separate); + JS::RemoveObjectRoot(cx, &hashElement->separate); HASH_DEL( collision_handler_hash, hashElement ); free( hashElement ); } @@ -1036,15 +1100,15 @@ bool JSB_cpSpace_setDefaultCollisionHandler(JSContext *cx, uint32_t argc, jsval // Root it if( handler->begin ) - JS_AddNamedObjectRoot(cx, &handler->begin, "begin collision_handler"); + JS::AddNamedObjectRoot(cx, &handler->begin, "begin collision_handler"); if( handler->pre ) - JS_AddNamedObjectRoot(cx, &handler->pre, "pre collision_handler"); + JS::AddNamedObjectRoot(cx, &handler->pre, "pre collision_handler"); if( handler->post ) - JS_AddNamedObjectRoot(cx, &handler->post, "post collision_handler"); + JS::AddNamedObjectRoot(cx, &handler->post, "post collision_handler"); if( handler->separate ) - JS_AddNamedObjectRoot(cx, &handler->separate, "separate collision_handler"); + JS::AddNamedObjectRoot(cx, &handler->separate, "separate collision_handler"); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1058,8 +1122,8 @@ bool __jsb_cpSpace_removeCollisionHandler(JSContext *cx, jsval *vp, jsval *argvp cpCollisionType typeA; cpCollisionType typeB; - ok &= jsval_to_int(cx, *argvp++, (int32_t*) &typeA ); - ok &= jsval_to_int(cx, *argvp++, (int32_t*) &typeB ); + ok &= jsval_to_int(cx, JS::RootedValue(cx, *argvp++), (int32_t*) &typeA ); + ok &= jsval_to_int(cx, JS::RootedValue(cx, *argvp++), (int32_t*) &typeB ); JSB_PRECONDITION(ok, "Error parsing arguments"); @@ -1073,19 +1137,18 @@ bool __jsb_cpSpace_removeCollisionHandler(JSContext *cx, jsval *vp, jsval *argvp // unroot it if( hashElement->begin ) - JS_RemoveObjectRoot(cx, &hashElement->begin); + JS::RemoveObjectRoot(cx, &hashElement->begin); if( hashElement->pre ) - JS_RemoveObjectRoot(cx, &hashElement->pre); + JS::RemoveObjectRoot(cx, &hashElement->pre); if( hashElement->post ) - JS_RemoveObjectRoot(cx, &hashElement->post); + JS::RemoveObjectRoot(cx, &hashElement->post); if( hashElement->separate ) - JS_RemoveObjectRoot(cx, &hashElement->separate); + JS::RemoveObjectRoot(cx, &hashElement->separate); HASH_DEL( collision_handler_hash, hashElement ); free( hashElement ); } - JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; } @@ -1094,10 +1157,11 @@ bool JSB_cpSpaceRemoveCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==3, cx, false, "Invalid number of arguments"); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpSpace* space; - bool ok = jsval_to_opaque( cx, *argvp++, (void**)&space); + jsval* argvp = args.array(); + bool ok = jsval_to_opaque( cx, JS::RootedValue(cx, *argvp++), (void**)&space); JSB_PRECONDITION(ok, "Error parsing arguments"); @@ -1108,14 +1172,14 @@ bool JSB_cpSpaceRemoveCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp) bool JSB_cpSpace_removeCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==2, cx, false, "Invalid number of arguments"); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSB_PRECONDITION( jsthis, "Invalid jsthis object"); struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); void *handle = proxy->handle; - return __jsb_cpSpace_removeCollisionHandler(cx, vp, JS_ARGV(cx,vp), (cpSpace*)handle); + return __jsb_cpSpace_removeCollisionHandler(cx, vp, args.array(), (cpSpace*)handle); } #pragma mark Add functios. Root JSObjects @@ -1128,21 +1192,21 @@ bool JSB_cpSpace_addBody(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg1; - jsval retval = *argvp; struct jsb_c_proxy_s *retproxy; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, &retproxy ); + jsval retval = args.get(0); struct jsb_c_proxy_s *retproxy; + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, &retproxy ); JSB_PRECONDITION(ok, "Error processing arguments"); cpSpaceAddBody((cpSpace*)arg0 , (cpBody*)arg1 ); // Root it: - JS_AddNamedObjectRoot(cx, &retproxy->jsobj, "cpBody"); + JS::AddNamedObjectRoot(cx, &retproxy->jsobj, "cpBody"); // addBody returns the same object that was added, so return it without conversions - JS_SET_RVAL(cx, vp, retval); + args.rval().set(retval); return true; } @@ -1155,21 +1219,21 @@ bool JSB_cpSpace_addConstraint(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg1; - jsval retval = *argvp; struct jsb_c_proxy_s *retproxy; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, &retproxy ); + jsval retval = args.get(0); struct jsb_c_proxy_s *retproxy; + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, &retproxy ); JSB_PRECONDITION(ok, "Error processing arguments"); cpSpaceAddConstraint((cpSpace*)arg0 , (cpConstraint*)arg1 ); // Root it: - JS_AddNamedObjectRoot(cx, &retproxy->jsobj, "cpConstraint"); + JS::AddNamedObjectRoot(cx, &retproxy->jsobj, "cpConstraint"); // addConstraint returns the same object that was added, so return it without conversions - JS_SET_RVAL(cx, vp, retval); + args.rval().set(retval); return true; } @@ -1182,21 +1246,21 @@ bool JSB_cpSpace_addShape(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg1; - jsval retval = *argvp; struct jsb_c_proxy_s *retproxy; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, &retproxy ); + jsval retval = args.get(0); struct jsb_c_proxy_s *retproxy; + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, &retproxy ); JSB_PRECONDITION(ok, "Error processing arguments"); cpSpaceAddShape((cpSpace*)arg0 , (cpShape*)arg1 ); // Root it: - JS_AddNamedObjectRoot(cx, &retproxy->jsobj, "cpShape"); + JS::AddNamedObjectRoot(cx, &retproxy->jsobj, "cpShape"); // addShape returns the same object that was added, so return it without conversions - JS_SET_RVAL(cx, vp, retval); + args.rval().set(retval); return true; } @@ -1209,21 +1273,21 @@ bool JSB_cpSpace_addStaticShape(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg1; - jsval retval = *argvp; struct jsb_c_proxy_s *retproxy; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, &retproxy ); + jsval retval = args.get(0); struct jsb_c_proxy_s *retproxy; + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, &retproxy ); JSB_PRECONDITION(ok, "Error processing arguments"); cpSpaceAddStaticShape((cpSpace*)arg0 , (cpShape*)arg1 ); // Root it: - JS_AddNamedObjectRoot(cx, &retproxy->jsobj, "cpShape (static)"); + JS::AddNamedObjectRoot(cx, &retproxy->jsobj, "cpShape (static)"); // addStaticShape returns the same object that was added, so return it without conversions - JS_SET_RVAL(cx, vp, retval); + args.rval().set(retval); return true; } @@ -1238,18 +1302,18 @@ bool JSB_cpSpace_removeBody(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg1; struct jsb_c_proxy_s *retproxy; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, &retproxy ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, &retproxy ); JSB_PRECONDITION(ok, "Error processing arguments"); cpSpaceRemoveBody((cpSpace*)arg0 , (cpBody*)arg1 ); - JS_RemoveObjectRoot(cx, &retproxy->jsobj); + JS::RemoveObjectRoot(cx, &retproxy->jsobj); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1261,18 +1325,18 @@ bool JSB_cpSpace_removeConstraint(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpConstraint* arg1; struct jsb_c_proxy_s *retproxy; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, &retproxy ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, &retproxy ); JSB_PRECONDITION(ok, "Error processing arguments"); cpSpaceRemoveConstraint((cpSpace*)arg0 , (cpConstraint*)arg1 ); - JS_RemoveObjectRoot(cx, &retproxy->jsobj); + JS::RemoveObjectRoot(cx, &retproxy->jsobj); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1284,18 +1348,18 @@ bool JSB_cpSpace_removeShape(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg1; struct jsb_c_proxy_s *retproxy; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, &retproxy ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, &retproxy ); JSB_PRECONDITION(ok, "Error processing arguments"); cpSpaceRemoveShape((cpSpace*)arg0 , (cpShape*)arg1 ); - JS_RemoveObjectRoot(cx, &retproxy->jsobj); + JS::RemoveObjectRoot(cx, &retproxy->jsobj); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1307,18 +1371,18 @@ bool JSB_cpSpace_removeStaticShape(JSContext *cx, uint32_t argc, jsval *vp) { JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* arg0 = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpShape* arg1; struct jsb_c_proxy_s *retproxy; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&arg1, &retproxy ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&arg1, &retproxy ); JSB_PRECONDITION(ok, "Error processing arguments"); cpSpaceRemoveStaticShape((cpSpace*)arg0 , (cpShape*)arg1 ); - JS_RemoveObjectRoot(cx, &retproxy->jsobj); + JS::RemoveObjectRoot(cx, &retproxy->jsobj); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1328,17 +1392,17 @@ bool JSB_cpSpace_segmentQueryFirst(JSContext *cx, uint32_t argc, jsval *vp){ JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* space = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpVect start; cpVect end; cpLayers layers; cpGroup group; bool ok = true; - ok &= jsval_to_cpVect( cx, argvp[0], &start ); - ok &= jsval_to_cpVect( cx, argvp[1], &end ); - ok &= jsval_to_uint32( cx, argvp[2], &layers ); - ok &= jsval_to_uint( cx, argvp[3], (unsigned int*)&group ); + ok &= jsval_to_cpVect( cx, args.get(0), &start ); + ok &= jsval_to_cpVect( cx, args.get(1), &end ); + ok &= jsval_to_uint32( cx, args.get(2), &layers ); + ok &= jsval_to_uint( cx, args.get(3), (unsigned int*)&group ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpSegmentQueryInfo *out = new cpSegmentQueryInfo(); @@ -1346,15 +1410,15 @@ bool JSB_cpSpace_segmentQueryFirst(JSContext *cx, uint32_t argc, jsval *vp){ if(target) { - JSObject *jsobj = JS_NewObject(cx, JSB_cpSegmentQueryInfo_class, JSB_cpSegmentQueryInfo_object, NULL); + JSObject *jsobj = JS_NewObject(cx, JSB_cpSegmentQueryInfo_class, JS::RootedObject(cx, JSB_cpSegmentQueryInfo_object), JS::NullPtr()); jsb_set_jsobject_for_proxy(jsobj, out); jsb_set_c_proxy_for_jsobject(jsobj, out, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); } else { delete out; - JS_SET_RVAL(cx, vp, JSVAL_NULL); + args.rval().set(JSVAL_NULL); } return true; } @@ -1365,26 +1429,17 @@ bool JSB_cpSpace_nearestPointQueryNearest(JSContext *cx, uint32_t argc, jsval *v JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* space = (cpSpace*) proxy->handle; - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpVect point; cpFloat maxDistance; cpLayers layers; cpGroup group; bool ok = true; - ok &= jsval_to_cpVect( cx, argvp[0], &point ); - if(JSVAL_IS_INT(argvp[1])) - { - int arg1; - ok &= jsval_to_int(cx, argvp[1], &arg1); - maxDistance = (cpFloat) arg1; - } - else - { - maxDistance = JSVAL_TO_DOUBLE(argvp[1]); - } - ok &= jsval_to_uint32( cx, argvp[2], &layers ); - ok &= jsval_to_uint( cx, argvp[3], (unsigned int*)&group ); + ok &= jsval_to_cpVect( cx, args.get(0), &point ); + ok &= JS::ToNumber(cx, args.get(1), &maxDistance); + ok &= jsval_to_uint32( cx, args.get(2), &layers ); + ok &= jsval_to_uint( cx, args.get(3), (unsigned int*)&group ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cpNearestPointQueryInfo* info = new cpNearestPointQueryInfo(); @@ -1392,15 +1447,15 @@ bool JSB_cpSpace_nearestPointQueryNearest(JSContext *cx, uint32_t argc, jsval *v if(target) { - JSObject *jsobj = JS_NewObject(cx, JSB_cpNearestPointQueryInfo_class, JSB_cpNearestPointQueryInfo_object, NULL); + JSObject *jsobj = JS_NewObject(cx, JSB_cpNearestPointQueryInfo_class, JS::RootedObject(cx, JSB_cpNearestPointQueryInfo_object), JS::NullPtr()); jsb_set_jsobject_for_proxy(jsobj, info); jsb_set_c_proxy_for_jsobject(jsobj, info, JSB_C_FLAG_CALL_FREE); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); } else { delete info; - JS_SET_RVAL(cx, vp, JSVAL_NULL); + args.rval().set(JSVAL_NULL); } return true; } @@ -1418,11 +1473,11 @@ void JSB_cpSpace_pointQuery_func(cpShape *shape, void *data) { JSContext* cx = ((JSB_cp_each_UserData*)data)->cx; jsval* func = ((JSB_cp_each_UserData*)data)->func; - jsval rval; + JS::RootedValue rval(cx); jsval argv = OBJECT_TO_JSVAL(jsCpObject); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS_CallFunctionValue(cx, NULL, *func, 1, &argv, &rval); + JS_CallFunctionValue(cx, JS::NullPtr(), JS::RootedValue(cx, *func), JS::HandleValueArray::fromMarkedLocation(1, &argv), &rval); } } @@ -1432,7 +1487,7 @@ bool JSB_cpSpace_pointQuery(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2(argc == 4, cx, false, "Invalid number of arguments"); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSObject* jsthis = JSVAL_TO_OBJECT(args.thisv()); + JSObject* jsthis = args.thisv().toObjectOrNull(); struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* space = (cpSpace*) proxy->handle; @@ -1467,14 +1522,14 @@ void JSB_cpSpace_nearestPointQuery_func(cpShape *shape, cpFloat distance, cpVect { JSContext* cx = ((JSB_cp_each_UserData*)data)->cx; jsval* func = ((JSB_cp_each_UserData*)data)->func; - jsval rval; + JS::RootedValue rval(cx); jsval argv[3]; argv[0] = OBJECT_TO_JSVAL(jsCpObject); argv[1] = DOUBLE_TO_JSVAL(distance); argv[2] = cpVect_to_jsval(cx, point); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS_CallFunctionValue(cx, NULL, *func, 3, argv, &rval); + JS_CallFunctionValue(cx, JS::NullPtr(), JS::RootedValue(cx, *func), JS::HandleValueArray::fromMarkedLocation(3, argv), &rval); } } @@ -1484,7 +1539,7 @@ bool JSB_cpSpace_nearestPointQuery(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2(argc == 5, cx, false, "Invalid number of arguments"); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSObject* jsthis = JSVAL_TO_OBJECT(args.thisv()); + JSObject* jsthis = args.thisv().toObjectOrNull(); struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* space = (cpSpace*) proxy->handle; @@ -1520,14 +1575,14 @@ void JSB_cpSpace_segmentQuery_func(cpShape *shape, cpFloat t, cpVect n, void *da { JSContext* cx = ((JSB_cp_each_UserData*)data)->cx; jsval* func = ((JSB_cp_each_UserData*)data)->func; - jsval rval; + JS::RootedValue rval(cx); jsval argv[3]; argv[0] = OBJECT_TO_JSVAL(jsCpObject); argv[1] = DOUBLE_TO_JSVAL(t); argv[2] = cpVect_to_jsval(cx, n); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS_CallFunctionValue(cx, NULL, *func, 3, argv, &rval); + JS_CallFunctionValue(cx, JS::NullPtr(), JS::RootedValue(cx, *func), JS::HandleValueArray::fromMarkedLocation(3, argv), &rval); } } @@ -1537,7 +1592,7 @@ bool JSB_cpSpace_segmentQuery(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2(argc == 5, cx, false, "Invalid number of arguments"); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSObject* jsthis = JSVAL_TO_OBJECT(args.thisv()); + JSObject* jsthis = args.thisv().toObjectOrNull(); struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* space = (cpSpace*) proxy->handle; @@ -1574,7 +1629,7 @@ bool JSB_cpSpace_bbQuery(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2(argc == 4, cx, false, "Invalid number of arguments"); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSObject* jsthis = JSVAL_TO_OBJECT(args.thisv()); + JSObject* jsthis = args.thisv().toObjectOrNull(); struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* space = (cpSpace*) proxy->handle; @@ -1611,10 +1666,10 @@ void JSB_cpSpace_each_func(T* cpObject, void *data) { JSContext* cx = ((JSB_cp_each_UserData*)data)->cx; jsval* func = ((JSB_cp_each_UserData*)data)->func; - jsval rval; + JS::RootedValue rval(cx); jsval argv = OBJECT_TO_JSVAL(jsCpObject); - JS_CallFunctionValue(cx, NULL, *func, 1, &argv, &rval); + JS_CallFunctionValue(cx, JS::NullPtr(), JS::RootedValue(cx, *func), JS::HandleValueArray::fromMarkedLocation(1, &argv), &rval); } } @@ -1626,14 +1681,14 @@ bool JSB_cpSpace_eachShape(JSContext *cx, uint32_t argc, jsval *vp) JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* space = (cpSpace*)proxy->handle; - jsval *argvp = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSB_cp_each_UserData *data = (JSB_cp_each_UserData*)malloc(sizeof(JSB_cp_each_UserData)); if (!data) return false; data->cx = cx; - data->func = argvp; + data->func = const_cast(args.get(0).address()); cpSpaceEachShape(space, JSB_cpSpace_each_func, data); free(data); @@ -1647,14 +1702,14 @@ bool JSB_cpSpace_eachBody(JSContext *cx, uint32_t argc, jsval *vp) JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* space = (cpSpace*)proxy->handle; - jsval *argvp = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSB_cp_each_UserData *data = (JSB_cp_each_UserData*)malloc(sizeof(JSB_cp_each_UserData)); if (!data) return false; data->cx = cx; - data->func = argvp; + data->func = const_cast(args.get(0).address()); cpSpaceEachBody(space, JSB_cpSpace_each_func, data); free(data); @@ -1668,14 +1723,14 @@ bool JSB_cpSpace_eachConstraint(JSContext *cx, uint32_t argc, jsval *vp) JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* space = (cpSpace*)proxy->handle; - jsval *argvp = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSB_cp_each_UserData *data = (JSB_cp_each_UserData*)malloc(sizeof(JSB_cp_each_UserData)); if (!data) return false; data->cx = cx; - data->func = argvp; + data->func = const_cast(args.get(0).address()); cpSpaceEachConstraint(space, JSB_cpSpace_each_func, data); free(data); @@ -1690,12 +1745,11 @@ struct __PostStep_data{ void __JSB_PostStep_callback(cpSpace *space, void *key, __PostStep_data *data) { JSContext* cx = data->cx; - jsval func = const_cast(data->func.get()); - jsval rval; - jsval argv; + JS::RootedValue func(cx, data->func); + JS::RootedValue rval(cx); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS_CallFunctionValue(cx, NULL, func, 0, &argv, &rval); + JS_CallFunctionValue(cx, JS::NullPtr(), func, JS::HandleValueArray::empty(), &rval); free(data); } @@ -1705,7 +1759,7 @@ bool JSB_cpSpace_addPostStepCallback(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2(argc == 1, cx, false, "Invalid number of arguments"); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSObject* jsthis = JSVAL_TO_OBJECT(args.thisv()); + JSObject* jsthis = args.thisv().toObjectOrNull(); jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* space = (cpSpace*)proxy->handle; @@ -1733,10 +1787,10 @@ void JSB_cpBody_each_func(cpBody* body, T* cpObject, void* data) { JSContext* cx = ((JSB_cp_each_UserData*)data)->cx; jsval* func = ((JSB_cp_each_UserData*)data)->func; - jsval rval; + JS::RootedValue rval(cx); jsval argv = OBJECT_TO_JSVAL(jsCpObject); - JS_CallFunctionValue(cx, NULL, *func, 1, &argv, &rval); + JS_CallFunctionValue(cx, JS::NullPtr(), JS::RootedValue(cx, *func), JS::HandleValueArray::fromMarkedLocation(1, &argv), &rval); } } @@ -1748,14 +1802,14 @@ bool JSB_cpBody_eachShape(JSContext *cx, uint32_t argc, jsval *vp) JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* body = (cpBody*)proxy->handle; - jsval *argvp = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSB_cp_each_UserData *data = (JSB_cp_each_UserData*)malloc(sizeof(JSB_cp_each_UserData)); if (!data) return false; data->cx = cx; - data->func = argvp; + data->func = const_cast(args.get(0).address()); cpBodyEachShape(body, JSB_cpBody_each_func, data); free(data); @@ -1769,14 +1823,14 @@ bool JSB_cpBody_eachConstraint(JSContext *cx, uint32_t argc, jsval *vp) JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* body = (cpBody*)proxy->handle; - jsval *argvp = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSB_cp_each_UserData *data = (JSB_cp_each_UserData*)malloc(sizeof(JSB_cp_each_UserData)); if (!data) return false; data->cx = cx; - data->func = argvp; + data->func = const_cast(args.get(0).address()); cpBodyEachConstraint(body, JSB_cpBody_each_func, data); free(data); @@ -1790,14 +1844,14 @@ bool JSB_cpBody_eachArbiter(JSContext *cx, uint32_t argc, jsval *vp) JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpBody* body = (cpBody*)proxy->handle; - jsval *argvp = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSB_cp_each_UserData *data = (JSB_cp_each_UserData*)malloc(sizeof(JSB_cp_each_UserData)); if (!data) return false; data->cx = cx; - data->func = argvp; + data->func = const_cast(args.get(0).address()); cpBodyEachArbiter(body, JSB_cpBody_each_func, data); free(data); @@ -1808,7 +1862,7 @@ bool JSB_cpBody_eachArbiter(JSContext *cx, uint32_t argc, jsval *vp) #pragma mark getBodies static -bool __jsb_cpArbiter_getBodies(JSContext *cx, jsval *vp, jsval *argvp, cpArbiter *arbiter, unsigned int is_oo) +bool __jsb_cpArbiter_getBodies(JSContext *cx, const JS::CallArgs& args, cpArbiter *arbiter, unsigned int is_oo) { cpBody *bodyA; cpBody *bodyB; @@ -1817,18 +1871,18 @@ bool __jsb_cpArbiter_getBodies(JSContext *cx, jsval *vp, jsval *argvp, cpArbiter JS::RootedValue valA(cx); JS::RootedValue valB(cx); if( is_oo ) { - valA = c_class_to_jsval(cx, bodyA, JSB_cpBody_object, JSB_cpBody_class, "cpArbiter"); - valB = c_class_to_jsval(cx, bodyB, JSB_cpBody_object, JSB_cpBody_class, "cpArbiter"); + valA = c_class_to_jsval(cx, bodyA, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpArbiter"); + valB = c_class_to_jsval(cx, bodyB, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpArbiter"); } else { valA = opaque_to_jsval(cx, bodyA); valB = opaque_to_jsval(cx, bodyB); } - JS::RootedObject jsobj(cx, JS_NewArrayObject(cx, 2, NULL)); - JS_SetElement(cx, jsobj, 0, &valA); - JS_SetElement(cx, jsobj, 1, &valB); + JS::RootedObject jsobj(cx, JS_NewArrayObject(cx, 2)); + JS_SetElement(cx, jsobj, 0, valA); + JS_SetElement(cx, jsobj, 1, valB); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -1838,13 +1892,13 @@ bool JSB_cpArbiterGetBodies(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==1, cx, false, "Invalid number of arguments"); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpArbiter* arbiter; - if( ! jsval_to_opaque( cx, *argvp++, (void**)&arbiter ) ) + if( ! jsval_to_opaque( cx, args.get(0), (void**)&arbiter ) ) return false; - return __jsb_cpArbiter_getBodies(cx, vp, argvp, arbiter, 0); + return __jsb_cpArbiter_getBodies(cx, args, arbiter, 0); } // Method @@ -1858,13 +1912,13 @@ bool JSB_cpArbiter_getBodies(JSContext *cx, uint32_t argc, jsval *vp) struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); JSB_PRECONDITION( proxy, "Invalid private object"); void *handle = proxy->handle; - - return __jsb_cpArbiter_getBodies(cx, vp, JS_ARGV(cx,vp), (cpArbiter*)handle, 1); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + return __jsb_cpArbiter_getBodies(cx, args, (cpArbiter*)handle, 1); } #pragma mark getShapes static -bool __jsb_cpArbiter_getShapes(JSContext *cx, jsval *vp, jsval *argvp, cpArbiter *arbiter, unsigned int is_oo) +bool __jsb_cpArbiter_getShapes(JSContext *cx, const JS::CallArgs& args, cpArbiter *arbiter, unsigned int is_oo) { cpShape *shapeA; cpShape *shapeB; @@ -1873,18 +1927,18 @@ bool __jsb_cpArbiter_getShapes(JSContext *cx, jsval *vp, jsval *argvp, cpArbiter JS::RootedValue valA(cx); JS::RootedValue valB(cx); if( is_oo ) { - valA = c_class_to_jsval(cx, shapeA, JSB_cpShape_object, JSB_cpShape_class, "cpShape"); - valB = c_class_to_jsval(cx, shapeB, JSB_cpShape_object, JSB_cpShape_class, "cpShape"); + valA = c_class_to_jsval(cx, shapeA, JS::RootedObject(cx, JSB_cpShape_object), JSB_cpShape_class, "cpShape"); + valB = c_class_to_jsval(cx, shapeB, JS::RootedObject(cx, JSB_cpShape_object), JSB_cpShape_class, "cpShape"); } else { valA = opaque_to_jsval(cx, shapeA); valB = opaque_to_jsval(cx, shapeB); } - JS::RootedObject jsobj(cx, JS_NewArrayObject(cx, 2, NULL)); - JS_SetElement(cx, jsobj, 0, &valA); - JS_SetElement(cx, jsobj, 1, &valB); + JS::RootedObject jsobj(cx, JS_NewArrayObject(cx, 2)); + JS_SetElement(cx, jsobj, 0, valA); + JS_SetElement(cx, jsobj, 1, valB); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -1894,13 +1948,13 @@ bool JSB_cpArbiterGetShapes(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==1, cx, false, "Invalid number of arguments"); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpArbiter* arbiter; - if( ! jsval_to_opaque( cx, *argvp++, (void**) &arbiter ) ) + if( ! jsval_to_opaque( cx, args.get(0), (void**) &arbiter ) ) return false; - return __jsb_cpArbiter_getShapes(cx, vp, argvp, arbiter, 0); + return __jsb_cpArbiter_getShapes(cx, args, arbiter, 0); } // method @@ -1912,8 +1966,8 @@ bool JSB_cpArbiter_getShapes(JSContext *cx, uint32_t argc, jsval *vp) struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); void *handle = proxy->handle; - - return __jsb_cpArbiter_getShapes(cx, vp, JS_ARGV(cx,vp), (cpArbiter*)handle, 1); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + return __jsb_cpArbiter_getShapes(cx, args, (cpArbiter*)handle, 1); } #pragma mark - Body @@ -1924,13 +1978,13 @@ bool JSB_cpArbiter_getShapes(JSContext *cx, uint32_t argc, jsval *vp) bool JSB_cpBody_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==2, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpBody_class, JSB_cpBody_object, NULL); - JS::CallArgs argvp = JS::CallArgsFromVp(argc, vp); + JSObject *jsobj = JS_NewObject(cx, JSB_cpBody_class, JS::RootedObject(cx, JSB_cpBody_object), JS::NullPtr()); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double m; double i; - ok &= JS::ToNumber( cx, argvp[0], &m ); - ok &= JS::ToNumber( cx, argvp[1], &i ); + ok &= JS::ToNumber( cx, args.get(0), &m ); + ok &= JS::ToNumber( cx, args.get(1), &i ); JSB_PRECONDITION(ok, "Error processing arguments"); cpBody *ret_body = NULL; @@ -1948,17 +2002,17 @@ bool JSB_cpBody_constructor(JSContext *cx, uint32_t argc, jsval *vp) jsb_set_jsobject_for_proxy(jsobj, ret_body); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } #pragma mark getUserData static -bool __jsb_cpBody_getUserData(JSContext *cx, jsval *vp, jsval *argvp, cpBody *body) +bool __jsb_cpBody_getUserData(JSContext *cx, const JS::CallArgs& args, cpBody *body) { JSObject *data = (JSObject*) cpBodyGetUserData(body); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(data)); + args.rval().set(OBJECT_TO_JSVAL(data)); return true; } @@ -1968,12 +2022,12 @@ bool JSB_cpBodyGetUserData(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==1, cx, false, "Invalid number of arguments"); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpBody *body; - if( ! jsval_to_opaque( cx, *argvp++, (void**) &body ) ) + if( ! jsval_to_opaque( cx, args.get(0), (void**) &body ) ) return false; - return __jsb_cpBody_getUserData(cx, vp, argvp, body); + return __jsb_cpBody_getUserData(cx, args, body); } // method @@ -1985,8 +2039,8 @@ bool JSB_cpBody_getUserData(JSContext *cx, uint32_t argc, jsval *vp) struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); void *handle = proxy->handle; - - return __jsb_cpBody_getUserData(cx, vp, JS_ARGV(cx,vp), (cpBody*)handle); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + return __jsb_cpBody_getUserData(cx, args, (cpBody*)handle); } @@ -2002,7 +2056,6 @@ bool __jsb_cpBody_setUserData(JSContext *cx, jsval *vp, jsval *argvp, cpBody *bo JSB_PRECONDITION(ok, "Error parsing arguments"); cpBodySetUserData(body, jsobj); - JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; } @@ -2012,9 +2065,10 @@ bool JSB_cpBodySetUserData(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==2, cx, false, "Invalid number of arguments"); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpBody *body; - bool ok = jsval_to_opaque( cx, *argvp++, (void**) &body ); + jsval* argvp = args.array(); + bool ok = jsval_to_opaque( cx, JS::RootedValue(cx, *argvp++), (void**) &body ); JSB_PRECONDITION(ok, "Error parsing arguments"); return __jsb_cpBody_setUserData(cx, vp, argvp, body); } @@ -2028,8 +2082,8 @@ bool JSB_cpBody_setUserData(JSContext *cx, uint32_t argc, jsval *vp) struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); void *handle = proxy->handle; - - return __jsb_cpBody_setUserData(cx, vp, JS_ARGV(cx,vp), (cpBody*)handle); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + return __jsb_cpBody_setUserData(cx, vp, args.array(), (cpBody*)handle); } #pragma mark - Poly related @@ -2038,19 +2092,19 @@ bool JSB_cpBody_setUserData(JSContext *cx, uint32_t argc, jsval *vp) bool JSB_cpAreaForPoly(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==1, cx, false, "Invalid number of arguments"); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect *verts; int numVerts; - ok &= jsval_to_array_of_cpvect( cx, *argvp++, &verts, &numVerts); + ok &= jsval_to_array_of_cpvect( cx, args.get(0), &verts, &numVerts); JSB_PRECONDITION2(ok, cx, false, "Error parsing array"); cpFloat area = cpAreaForPoly(numVerts, verts); free(verts); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(area)); + args.rval().set(DOUBLE_TO_JSVAL(area)); return true; } @@ -2058,15 +2112,15 @@ bool JSB_cpAreaForPoly(JSContext *cx, uint32_t argc, jsval *vp) bool JSB_cpMomentForPoly(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==3, cx, false, "Invalid number of arguments"); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect *verts; cpVect offset; int numVerts; double m; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, *argvp++), &m); - ok &= jsval_to_array_of_cpvect( cx, *argvp++, &verts, &numVerts); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &offset ); + ok &= JS::ToNumber(cx, args.get(0), &m); + ok &= jsval_to_array_of_cpvect( cx, args.get(1), &verts, &numVerts); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &offset ); JSB_PRECONDITION2(ok, cx, false, "Error parsing args"); @@ -2074,7 +2128,7 @@ bool JSB_cpMomentForPoly(JSContext *cx, uint32_t argc, jsval *vp) free(verts); - JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(moment)); + args.rval().set(DOUBLE_TO_JSVAL(moment)); return true; } @@ -2082,19 +2136,19 @@ bool JSB_cpMomentForPoly(JSContext *cx, uint32_t argc, jsval *vp) bool JSB_cpCentroidForPoly(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==1, cx, false, "Invalid number of arguments"); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpVect *verts; int numVerts; - ok &= jsval_to_array_of_cpvect( cx, *argvp++, &verts, &numVerts); + ok &= jsval_to_array_of_cpvect( cx, args.get(0), &verts, &numVerts); JSB_PRECONDITION2(ok, cx, false, "Error parsing args"); cpVect centroid = cpCentroidForPoly(numVerts, verts); free(verts); - JS_SET_RVAL(cx, vp, cpVect_to_jsval(cx, (cpVect)centroid)); + args.rval().set(cpVect_to_jsval(cx, (cpVect)centroid)); return true; } @@ -2118,21 +2172,21 @@ bool JSB_cpBase_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc==1, cx, false, "Invalid arguments. Expecting 1"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpBase_class, JSB_cpBase_object, NULL); + JSObject *jsobj = JS_NewObject(cx, JSB_cpBase_class, JS::RootedObject(cx, JSB_cpBase_object), JS::NullPtr()); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; void *handle = NULL; - ok = jsval_to_opaque(cx, *argvp++, &handle); + ok = jsval_to_opaque(cx, args.get(0), &handle); JSB_PRECONDITION(ok, "Error converting arguments for JSB_cpBase_constructor"); jsb_set_c_proxy_for_jsobject(jsobj, handle, JSB_C_FLAG_DO_NOT_CALL_FREE); jsb_set_jsobject_for_proxy(jsobj, handle); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } @@ -2150,11 +2204,12 @@ bool JSB_cpBase_getHandle(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION( jsthis, "Invalid jsthis object"); JSB_PRECONDITION2(argc==0, cx, false, "Invalid number of arguments"); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); void *handle = proxy->handle; jsval ret_val = opaque_to_jsval(cx, handle); - JS_SET_RVAL(cx, vp, ret_val); + args.rval().set(ret_val); return true; } @@ -2164,21 +2219,21 @@ bool JSB_cpBase_setHandle(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION( jsthis, "Invalid jsthis object"); JSB_PRECONDITION2(argc==1, cx, false, "Invalid number of arguments"); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); void *handle; - bool ok = jsval_to_opaque(cx, *argvp++, &handle); + bool ok = jsval_to_opaque(cx, args.get(0), &handle); JSB_PRECONDITION( ok, "Invalid parsing arguments"); jsb_set_c_proxy_for_jsobject(jsthis, handle, JSB_C_FLAG_DO_NOT_CALL_FREE); jsb_set_jsobject_for_proxy(jsthis, handle); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -void JSB_cpBase_createClass(JSContext *cx, JSObject* globalObj, const char* name ) +void JSB_cpBase_createClass(JSContext *cx, JS::HandleObject globalObj, const char* name ) { JSB_cpBase_class = (JSClass *)calloc(1, sizeof(JSClass)); JSB_cpBase_class->name = name; @@ -2193,7 +2248,7 @@ void JSB_cpBase_createClass(JSContext *cx, JSObject* globalObj, const char* name JSB_cpBase_class->flags = JSCLASS_HAS_PRIVATE; static JSPropertySpec properties[] = { - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FN("getHandle", JSB_cpBase_getHandle, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -2204,7 +2259,7 @@ void JSB_cpBase_createClass(JSContext *cx, JSObject* globalObj, const char* name JS_FS_END }; - JSB_cpBase_object = JS_InitClass(cx, globalObj, NULL, JSB_cpBase_class, JSB_cpBase_constructor,0,properties,funcs,NULL,st_funcs); + JSB_cpBase_object = JS_InitClass(cx, globalObj, JS::NullPtr(), JSB_cpBase_class, JSB_cpBase_constructor,0,properties,funcs,NULL,st_funcs); // bool found; // JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } @@ -2214,22 +2269,22 @@ void JSB_cpBase_createClass(JSContext *cx, JSObject* globalObj, const char* name bool JSB_cpPolyShape_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==3, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpPolyShape_class, JSB_cpPolyShape_object, NULL); - jsval *argvp = JS_ARGV(cx,vp); + JSObject *jsobj = JS_NewObject(cx, JSB_cpPolyShape_class, JS::RootedObject(cx, JSB_cpPolyShape_object), JS::NullPtr()); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* body; cpVect *verts; cpVect offset; int numVerts; - ok &= jsval_to_c_class( cx, *argvp++, (void**)&body, NULL ); - ok &= jsval_to_array_of_cpvect( cx, *argvp++, &verts, &numVerts); - ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &offset ); + ok &= jsval_to_c_class( cx, args.get(0), (void**)&body, NULL ); + ok &= jsval_to_array_of_cpvect( cx, args.get(1), &verts, &numVerts); + ok &= jsval_to_cpVect( cx, args.get(2), (cpVect*) &offset ); JSB_PRECONDITION(ok, "Error processing arguments"); cpShape *shape = cpPolyShapeNew(body, numVerts, verts, offset); jsb_set_c_proxy_for_jsobject(jsobj, shape, JSB_C_FLAG_CALL_FREE); jsb_set_jsobject_for_proxy(jsobj, shape); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj)); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); free(verts); @@ -2257,7 +2312,7 @@ static void unroot_jsobject_from_handle(void *handle) // HACK context from global JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_RemoveObjectRoot(cx, &proxy->jsobj); + JS::RemoveObjectRoot(cx, &proxy->jsobj); } } diff --git a/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_manual.h b/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_manual.h index aea05e82a9..c2a9060933 100644 --- a/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_manual.h +++ b/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_manual.h @@ -31,6 +31,7 @@ #include "ScriptingCore.h" #ifdef JSB_INCLUDE_CHIPMUNK +#include "chipmunk_private.h" #include "js_bindings_chipmunk_auto_classes.h" // Free Functions @@ -91,18 +92,15 @@ bool JSB_cpBody_eachArbiter(JSContext *cx, uint32_t argc, jsval *vp); jsval cpBB_to_jsval(JSContext *cx, cpBB bb ); bool jsval_to_cpBB( JSContext *cx, jsval vp, cpBB *ret ); bool jsval_to_array_of_cpvect( JSContext *cx, jsval vp, cpVect**verts, int *numVerts); - -// requires cocos2d -#define cpVect_to_jsval CGPoint_to_jsval -#define jsval_to_cpVect jsval_to_CGPoint - +bool jsval_to_cpVect( JSContext *cx, jsval vp, cpVect *out ); +jsval cpVect_to_jsval( JSContext *cx, cpVect p ); // Object Oriented Chipmunk -void JSB_cpBase_createClass(JSContext* cx, JSObject* globalObj, const char * name ); +void JSB_cpBase_createClass(JSContext* cx, JS::HandleObject globalObj, const char * name ); extern JSObject* JSB_cpBase_object; extern JSClass* JSB_cpBase_class; -extern void register_CCPhysicsSprite(JSContext *cx, JSObject *obj); -extern void register_CCPhysicsDebugNode(JSContext *cx, JSObject *obj); +extern void register_CCPhysicsSprite(JSContext *cx, JS::HandleObject obj); +extern void register_CCPhysicsDebugNode(JSContext *cx, JS::HandleObject obj); // Manual constructor / destructors bool JSB_cpPolyShape_constructor(JSContext *cx, uint32_t argc, jsval *vp); diff --git a/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_registration.cpp b/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_registration.cpp index af88849429..7f8ce5aab6 100644 --- a/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_registration.cpp +++ b/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_registration.cpp @@ -35,12 +35,12 @@ #include "js_bindings_chipmunk_manual.h" -void jsb_register_chipmunk(JSContext* cx, JSObject *object) +void jsb_register_chipmunk(JSContext* cx, JS::HandleObject object) { // // Chipmunk // - JSObject *chipmunk = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject chipmunk(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); JS::RootedValue chipmunkVal(cx); chipmunkVal = OBJECT_TO_JSVAL(chipmunk); @@ -63,11 +63,12 @@ void jsb_register_chipmunk(JSContext* cx, JSObject *object) JS_DefineFunction(cx, chipmunk, "centroidForPoly", JSB_cpCentroidForPoly, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE ); JS_DefineFunction(cx, chipmunk, "recenterPoly", JSB_cpRecenterPoly, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE ); - JS_DefineFunction(cx, JSB_cpSpace_object, "segmentQueryFirst", JSB_cpSpace_segmentQueryFirst, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE); - JS_DefineFunction(cx, JSB_cpSpace_object, "nearestPointQueryNearest", JSB_cpSpace_nearestPointQueryNearest, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE); - JS_DefineFunction(cx, JSB_cpSpace_object, "eachShape", JSB_cpSpace_eachShape, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE); - JS_DefineFunction(cx, JSB_cpSpace_object, "eachBody", JSB_cpSpace_eachBody, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE); - JS_DefineFunction(cx, JSB_cpSpace_object, "eachConstraint", JSB_cpSpace_eachConstraint, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE); + JS::RootedObject space(cx, JSB_cpSpace_object); + JS_DefineFunction(cx, space, "segmentQueryFirst", JSB_cpSpace_segmentQueryFirst, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE); + JS_DefineFunction(cx, space, "nearestPointQueryNearest", JSB_cpSpace_nearestPointQueryNearest, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE); + JS_DefineFunction(cx, space, "eachShape", JSB_cpSpace_eachShape, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE); + JS_DefineFunction(cx, space, "eachBody", JSB_cpSpace_eachBody, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE); + JS_DefineFunction(cx, space, "eachConstraint", JSB_cpSpace_eachConstraint, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE); register_CCPhysicsSprite(cx, object); register_CCPhysicsDebugNode(cx, object); diff --git a/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_registration.h b/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_registration.h index 951439f983..3df6f2a820 100644 --- a/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_registration.h +++ b/frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_registration.h @@ -25,6 +25,6 @@ #ifndef __JSB_CHIPMUNK_REGISTRATION #define __JSB_CHIPMUNK_REGISTRATION -void jsb_register_chipmunk( JSContext *globalC, JSObject *globalO); +void jsb_register_chipmunk( JSContext *globalC, JS::HandleObject globalO); #endif // __JSB_CHIPMUNK_REGISTRATION diff --git a/frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp b/frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp index 320a9dd42f..b21083a85d 100644 --- a/frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp +++ b/frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp @@ -80,7 +80,7 @@ void JSTouchDelegate::setJSObject(JSObject *obj) if (!p) { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_AddNamedObjectRoot(cx, &_obj, "JSB_TouchDelegateTarget, target"); + JS::AddNamedObjectRoot(cx, &_obj, "JSB_TouchDelegateTarget, target"); _needUnroot = true; } } @@ -124,7 +124,7 @@ void JSTouchDelegate::unregisterTouchDelegate() if (_needUnroot) { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_RemoveObjectRoot(cx, &_obj); + JS::RemoveObjectRoot(cx, &_obj); } auto dispatcher = Director::getInstance()->getEventDispatcher(); @@ -137,15 +137,16 @@ void JSTouchDelegate::unregisterTouchDelegate() bool JSTouchDelegate::onTouchBegan(Touch *touch, Event *event) { CC_UNUSED_PARAM(event); - jsval retval; + JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); + JS::RootedValue retval(cx); bool bRet = false; ScriptingCore::getInstance()->executeCustomTouchEvent(EventTouch::EventCode::BEGAN, - touch, _obj, retval); + touch, _obj.get(), &retval); - if(JSVAL_IS_BOOLEAN(retval)) + if(retval.isBoolean()) { - bRet = JSVAL_TO_BOOLEAN(retval); + bRet = retval.toBoolean(); } return bRet; @@ -202,13 +203,14 @@ void JSTouchDelegate::onTouchesCancelled(const std::vector& touches, Eve // cc.EventTouch#getTouches bool js_cocos2dx_EventTouch_getTouches(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JSObject *obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventTouch* cobj = (cocos2d::EventTouch *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventTouch_getTouches : Invalid Native Object"); if (argc == 0) { const std::vector& ret = cobj->getTouches(); - JSObject *jsretArr = JS_NewArrayObject(cx, 0, NULL); + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); int i = 0; for (cocos2d::Touch* touchObj : ret) @@ -220,13 +222,14 @@ bool js_cocos2dx_EventTouch_getTouches(JSContext *cx, uint32_t argc, jsval *vp) if (jsproxy) { arrElement = OBJECT_TO_JSVAL(jsproxy->obj); } - if (!JS_SetElement(cx, jsretArr, i, &arrElement)) { + if (!JS_SetElement(cx, jsretArr, i, arrElement)) { break; } ++i; } - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsretArr)); +// JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsretArr)); + args.rval().set(OBJECT_TO_JSVAL(jsretArr)); return true; } @@ -237,7 +240,8 @@ bool js_cocos2dx_EventTouch_getTouches(JSContext *cx, uint32_t argc, jsval *vp) // cc.EventTouch#setTouches bool js_cocos2dx_EventTouch_setTouches(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); +// jsval *argv = JS_ARGV(cx, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -245,8 +249,8 @@ bool js_cocos2dx_EventTouch_setTouches(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventTouch_setTouches : Invalid Native Object"); if (argc == 1) { std::vector arg0; - JS::RootedObject jsobj(cx); - ok = argv->isObject() && JS_ValueToObject( cx, JS::RootedValue(cx, *argv), &jsobj ); + JS::RootedObject jsobj(cx, args.get(0).toObjectOrNull()); +// ok = argv->isObject() && JS_ValueToObject( cx, JS::RootedValue(cx, *argv), &jsobj ); JSB_PRECONDITION3( ok, cx, false, "Error converting value to object"); JSB_PRECONDITION3( jsobj && JS_IsArrayObject( cx, jsobj), cx, false, "Object must be an array"); @@ -258,7 +262,7 @@ bool js_cocos2dx_EventTouch_setTouches(JSContext *cx, uint32_t argc, jsval *vp) JS::RootedValue value(cx); if (JS_GetElement(cx, jsobj, i, &value)) { - JSObject *tmp = JSVAL_TO_OBJECT(value); + JSObject *tmp = value.toObjectOrNull(); proxy = jsb_get_js_proxy(tmp); cocos2d::Touch* touchObj = (cocos2d::Touch *)(proxy ? proxy->ptr : NULL); if (touchObj) { @@ -267,7 +271,8 @@ bool js_cocos2dx_EventTouch_setTouches(JSContext *cx, uint32_t argc, jsval *vp) } } cobj->setTouches(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); +// args.rval().setUndefined(); + args.rval().setUndefined(); return true; } @@ -294,11 +299,13 @@ JSObject* bind_menu_item(JSContext *cx, T* nativeObj, jsval callback, jsval this } else { js_type_class_t *classType = js_get_type_from_native(nativeObj); assert(classType); - JSObject *tmp = JS_NewObject(cx, classType->jsclass, classType->proto, classType->parentProto); + JS::RootedObject proto(cx, classType->proto); + JS::RootedObject parent(cx, classType->parentProto); + JSObject *tmp = JS_NewObject(cx, classType->jsclass, proto, parent); // bind nativeObj <-> JSObject js_proxy_t *proxy = jsb_new_proxy(nativeObj, tmp); - JS_AddNamedObjectRoot(cx, &proxy->obj, typeid(*nativeObj).name()); + JS::AddNamedObjectRoot(cx, &proxy->obj, typeid(*nativeObj).name()); addCallBackAndThis(tmp, callback, thisObj); return tmp; @@ -307,13 +314,14 @@ JSObject* bind_menu_item(JSContext *cx, T* nativeObj, jsval callback, jsval this bool js_cocos2dx_CCMenu_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); +// jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc > 0) { Vector items; uint32_t i = 0; while (i < argc) { js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[i]); + JSObject *tmpObj = args.get(i).toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); cocos2d::MenuItem *item = (cocos2d::MenuItem*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, item) @@ -336,7 +344,8 @@ bool js_cocos2dx_CCMenu_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); +// args.rval().set(jsret); + args.rval().set(jsret); return true; } if (argc == 0) { @@ -356,7 +365,8 @@ bool js_cocos2dx_CCMenu_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); +// JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -365,18 +375,19 @@ bool js_cocos2dx_CCMenu_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCSequence_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); +// jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc > 0) { Vector array; - if (argc == 1 && JS_IsArrayObject(cx, JSVAL_TO_OBJECT(argv[0]))) { + if (argc == 1 && JS_IsArrayObject(cx, JS::RootedObject(cx, args.get(0).toObjectOrNull()))) { bool ok = true; - ok &= jsval_to_ccvector(cx, argv[0], &array); + ok &= jsval_to_ccvector(cx, args.get(0), &array); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); } else { uint32_t i = 0; while (i < argc) { js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[i]); + JSObject *tmpObj = args.get(i).toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); cocos2d::FiniteTimeAction *item = (cocos2d::FiniteTimeAction*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, item) @@ -400,7 +411,8 @@ bool js_cocos2dx_CCSequence_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); +// JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -409,18 +421,18 @@ bool js_cocos2dx_CCSequence_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCSpawn_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc > 0) { Vector array; - if (argc == 1 && JS_IsArrayObject(cx, JSVAL_TO_OBJECT(argv[0]))) { + if (argc == 1 && JS_IsArrayObject(cx, JS::RootedObject(cx, args.get(0).toObjectOrNull()))) { bool ok = true; - ok &= jsval_to_ccvector(cx, argv[0], &array); + ok &= jsval_to_ccvector(cx, args.get(0), &array); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); } else { uint32_t i = 0; while (i < argc) { js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[i]); + JSObject *tmpObj = args[i].toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); cocos2d::FiniteTimeAction *item = (cocos2d::FiniteTimeAction*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, item) @@ -444,7 +456,7 @@ bool js_cocos2dx_CCSpawn_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -454,10 +466,10 @@ bool js_cocos2dx_CCSpawn_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCMenuItem_create(JSContext *cx, uint32_t argc, jsval *vp) { if (argc >= 1) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cocos2d::MenuItem* ret = cocos2d::MenuItem::create(); - JSObject *obj = bind_menu_item(cx, ret, argv[0], argc == 2? argv[1] : JSVAL_VOID); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + JSObject *obj = bind_menu_item(cx, ret, args.get(0), argc == 2? args.get(1) : JSVAL_VOID); + args.rval().set(OBJECT_TO_JSVAL(obj)); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -469,16 +481,16 @@ bool js_cocos2dx_CCMenuItem_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCMenuItemSprite_create(JSContext *cx, uint32_t argc, jsval *vp) { if (argc >= 2 && argc <= 5) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); js_proxy_t *proxy; JSObject *tmpObj; - tmpObj = JSVAL_TO_OBJECT(argv[0]); + tmpObj = args.get(0).toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); cocos2d::Node* arg0 = (cocos2d::Node*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, arg0); - tmpObj = JSVAL_TO_OBJECT(argv[1]); + tmpObj = args.get(1).toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); cocos2d::Node* arg1 = (cocos2d::Node*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, arg1); @@ -491,7 +503,7 @@ bool js_cocos2dx_CCMenuItemSprite_create(JSContext *cx, uint32_t argc, jsval *vp cocos2d::Node* arg2 = NULL; if (argc >= 3) { - tmpObj = JSVAL_TO_OBJECT(argv[2]); + tmpObj = args.get(2).toObjectOrNull(); thirdArgIsCallback = JS_ObjectIsFunction(cx, tmpObj); if (!thirdArgIsCallback) { proxy = jsb_get_js_proxy(tmpObj); @@ -504,17 +516,17 @@ bool js_cocos2dx_CCMenuItemSprite_create(JSContext *cx, uint32_t argc, jsval *vp if (argc >= 3) { if (thirdArgIsCallback) { //cc.MenuItemSprite.create( normalSprite, selectedSprite, callback_fn, [this] ) - jsCallback = argv[last++]; + jsCallback = args.get(last++); if (argc == 4) { - jsThis = argv[last]; + jsThis = args.get(last); } } else { //cc.MenuItemSprite.create( normalSprite, selectedSprite, disabledSprite, callback_fn, [this] ) if (argc >= 4) { - jsCallback = argv[last++]; + jsCallback = args.get(last++); if (argc == 5) { - jsThis = argv[last]; + jsThis = args.get(last); } } } @@ -522,7 +534,7 @@ bool js_cocos2dx_CCMenuItemSprite_create(JSContext *cx, uint32_t argc, jsval *vp JSObject *obj = bind_menu_item(cx, ret, jsCallback, jsThis); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + args.rval().set(OBJECT_TO_JSVAL(obj)); return true; } JS_ReportError(cx, "Invalid number of arguments. Expecting: 2 <= args <= 5"); @@ -534,15 +546,15 @@ bool js_cocos2dx_CCMenuItemSprite_create(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_CCMenuItemLabel_create(JSContext *cx, uint32_t argc, jsval *vp) { if (argc >= 1 && argc <= 3) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JSObject *tmpObj = args.get(0).toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); cocos2d::Node* arg0 = (cocos2d::Node*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, arg0) cocos2d::MenuItemLabel* ret = cocos2d::MenuItemLabel::create(arg0); - JSObject *obj = bind_menu_item(cx, ret, (argc >= 2 ? argv[1] : JSVAL_VOID), (argc == 3 ? argv[2] : JSVAL_VOID) ); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + JSObject *obj = bind_menu_item(cx, ret, (argc >= 2 ? args.get(1) : JSVAL_VOID), (argc == 3 ? args.get(2) : JSVAL_VOID) ); + args.rval().set(OBJECT_TO_JSVAL(obj)); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d or %d or %d", argc, 1, 2, 3); @@ -553,16 +565,16 @@ bool js_cocos2dx_CCMenuItemAtlasFont_create(JSContext *cx, uint32_t argc, jsval { if (argc >= 5) { bool ok = true; - jsval *argv = JS_ARGV(cx, vp); - JSStringWrapper arg0(argv[0]); - JSStringWrapper arg1(argv[1]); - int arg2; ok &= jsval_to_int32(cx, argv[2], &arg2); - int arg3; ok &= jsval_to_int32(cx, argv[3], &arg3); - int arg4; ok &= jsval_to_int32(cx, argv[4], &arg4); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JSStringWrapper arg0(args.get(0)); + JSStringWrapper arg1(args.get(1)); + int arg2; ok &= jsval_to_int32(cx, args.get(2), &arg2); + int arg3; ok &= jsval_to_int32(cx, args.get(3), &arg3); + int arg4; ok &= jsval_to_int32(cx, args.get(4), &arg4); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cocos2d::MenuItemAtlasFont* ret = cocos2d::MenuItemAtlasFont::create(arg0.get(), arg1.get(), arg2, arg3, arg4); - JSObject *obj = bind_menu_item(cx, ret, (argc >= 6 ? argv[5] : JSVAL_VOID), (argc == 7 ? argv[6] : JSVAL_VOID)); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + JSObject *obj = bind_menu_item(cx, ret, (argc >= 6 ? args.get(5) : JSVAL_VOID), (argc == 7 ? args.get(6) : JSVAL_VOID)); + args.rval().set(OBJECT_TO_JSVAL(obj)); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -574,11 +586,11 @@ bool js_cocos2dx_CCMenuItemAtlasFont_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_CCMenuItemFont_create(JSContext *cx, uint32_t argc, jsval *vp) { if (argc >= 1 && argc <= 3) { - jsval *argv = JS_ARGV(cx, vp); - JSStringWrapper arg0(argv[0]); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JSStringWrapper arg0(args.get(0)); cocos2d::MenuItemFont* ret = cocos2d::MenuItemFont::create(arg0.get()); - JSObject *obj = bind_menu_item(cx, ret, (argc >= 2 ? argv[1] : JSVAL_VOID), (argc == 3 ? argv[2] : JSVAL_VOID)); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + JSObject *obj = bind_menu_item(cx, ret, (argc >= 2 ? args.get(1) : JSVAL_VOID), (argc == 3 ? args.get(2) : JSVAL_VOID)); + args.rval().set(OBJECT_TO_JSVAL(obj)); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d or %d or %d", argc, 1, 2, 3); @@ -589,12 +601,12 @@ bool js_cocos2dx_CCMenuItemFont_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCMenuItemToggle_create(JSContext *cx, uint32_t argc, jsval *vp) { if (argc >= 1) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cocos2d::MenuItemToggle* ret = cocos2d::MenuItemToggle::create(); for (uint32_t i=0; i < argc; i++) { js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[i]); + JSObject *tmpObj = args.get(i).toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); cocos2d::MenuItem* item = (cocos2d::MenuItem*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, item) @@ -617,82 +629,101 @@ bool js_cocos2dx_CCMenuItemToggle_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "wrong number of arguments"); return false; } -// "setCallback" in JS -// item.setCallback( callback_fn, [this]); -template -bool js_cocos2dx_setCallback(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_MenuItem_setCallback(JSContext *cx, uint32_t argc, jsval *vp) { - if(argc == 1 || argc == 2) - { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); - jsval jsThis = JSVAL_VOID; - jsval jsFunc = argv[0]; - - if (jsFunc.isUndefined()) - { - JS_ReportError(cx, "The callback function is undefined."); - return false; - } - - if (argc == 2) - { - jsThis = argv[1]; - } - - js_proxy_t *proxy = jsb_get_js_proxy(obj); - T* item = (T*)(proxy ? proxy->ptr : NULL); - TEST_NATIVE_OBJECT(cx, item) - bind_menu_item(cx, item, jsFunc, jsThis); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::MenuItem* cobj = (cocos2d::MenuItem *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MenuItem_setCallback : Invalid Native Object"); + if (argc == 1 || argc == 2) { + std::function arg0; + do { + if(JS_TypeOfValue(cx, args[0]) == JSTYPE_FUNCTION) + { + JSObject* thisObj; + if (args.get(1).isObject()) + { + thisObj = args.get(1).toObjectOrNull(); + } + else + { + thisObj = JS_THIS_OBJECT(cx, vp); + } + std::shared_ptr func(new JSFunctionWrapper(cx, thisObj, args[0])); + auto lambda = [=](cocos2d::Ref* larg0) -> void { + jsval largv[1]; + do { + if (larg0) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Ref*)larg0); + largv[0] = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + largv[0] = JSVAL_NULL; + } + } while (0); + JS::RootedValue rval(cx); + bool ok = func->invoke(1, &largv[0], &rval); + if (!ok && JS_IsExceptionPending(cx)) { + JS_ReportPendingException(cx); + } + }; + arg0 = lambda; + } + else + { + arg0 = nullptr; + } + } while(0) + ; + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItem_setCallback : Error processing arguments"); + cobj->setCallback(arg0); + args.rval().setUndefined(); return true; } - JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d or %d", argc, 1, 2); - return false; -} -bool js_cocos2dx_CCMenuItem_setCallback(JSContext *cx, uint32_t argc, jsval *vp) { - return js_cocos2dx_setCallback(cx, argc, vp); + JS_ReportError(cx, "js_cocos2dx_MenuItem_setCallback : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; } - bool js_cocos2dx_CCAnimation_create(JSContext *cx, uint32_t argc, jsval *vp) { bool ok = true; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc <= 3) { cocos2d::Animation* ret = nullptr; double arg1 = 0.0f; if (argc == 2) { Vector arg0; if (argc > 0) { - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); } - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(1)), &arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); ret = cocos2d::Animation::createWithSpriteFrames(arg0, arg1); } else if (argc == 3) { Vector arg0; if (argc > 0) { - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); } unsigned int loops; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[1]), &arg1); - ok &= jsval_to_uint32(cx, argv[2], &loops); + ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(1)), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &loops); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); ret = cocos2d::Animation::create(arg0, arg1, loops); } else if (argc == 1) { Vector arg0; if (argc > 0) { - ok &= jsval_to_ccvector(cx, argv[0], &arg0); + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); } ret = cocos2d::Animation::createWithSpriteFrames(arg0); @@ -712,7 +743,7 @@ bool js_cocos2dx_CCAnimation_create(JSContext *cx, uint32_t argc, jsval *vp) } else { jsret = JSVAL_NULL; } - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -721,7 +752,8 @@ bool js_cocos2dx_CCAnimation_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCScene_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JSObject *obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scene* cobj = (cocos2d::Scene *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Scene_init : Invalid Native Object"); @@ -729,7 +761,7 @@ bool js_cocos2dx_CCScene_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -739,10 +771,10 @@ bool js_cocos2dx_CCScene_init(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCLayerMultiplex_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); Vector arg0; bool ok = true; - ok &= jsvals_variadic_to_ccvector(cx, argv, argc, &arg0); + ok &= jsvals_variadic_to_ccvector(cx, args, &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cocos2d::LayerMultiplex* ret = cocos2d::LayerMultiplex::createWithArray(arg0); @@ -755,7 +787,7 @@ bool js_cocos2dx_CCLayerMultiplex_create(JSContext *cx, uint32_t argc, jsval *vp jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -763,7 +795,7 @@ bool js_cocos2dx_JSTouchDelegate_registerStandardDelegate(JSContext *cx, uint32_ { if (argc == 1 || argc == 2) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsobj = NULL; JSTouchDelegate *touch = new JSTouchDelegate(); @@ -771,12 +803,12 @@ bool js_cocos2dx_JSTouchDelegate_registerStandardDelegate(JSContext *cx, uint32_ int priority = 1; if (argc == 2) { - priority = JSVAL_TO_INT(argv[1]); + priority = args.get(1).toInt32(); } touch->registerStandardDelegate(priority); - jsobj = JSVAL_TO_OBJECT(argv[0]); + jsobj = args.get(0).toObjectOrNull(); touch->setJSObject(jsobj); JSTouchDelegate::setDelegateForJSObject(jsobj, touch); return true; @@ -789,13 +821,13 @@ bool js_cocos2dx_JSTouchDelegate_registerTargetedDelegate(JSContext *cx, uint32_ { if (argc == 3) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* jsobj = NULL; JSTouchDelegate *touch = new JSTouchDelegate(); - touch->registerTargetedDelegate(JSVAL_TO_INT(argv[0]), JSVAL_TO_BOOLEAN(argv[1])); + touch->registerTargetedDelegate(args.get(0).toInt32(), args.get(1).toBoolean()); - jsobj = JSVAL_TO_OBJECT(argv[2]); + jsobj = args.get(2).toObjectOrNull(); touch->setJSObject(jsobj); JSTouchDelegate::setDelegateForJSObject(jsobj, touch); @@ -808,8 +840,8 @@ bool js_cocos2dx_JSTouchDelegate_registerTargetedDelegate(JSContext *cx, uint32_ bool js_cocos2dx_JSTouchDelegate_unregisterTouchDelegate(JSContext *cx, uint32_t argc, jsval *vp) { if (argc == 1) { - jsval *argv = JS_ARGV(cx, vp); - JSObject* jsobj = JSVAL_TO_OBJECT(argv[0]); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JSObject* jsobj = args.get(0).toObjectOrNull(); JSTouchDelegate* pDelegate = JSTouchDelegate::getDelegateForJSObject(jsobj); if (pDelegate) { @@ -823,7 +855,7 @@ bool js_cocos2dx_JSTouchDelegate_unregisterTouchDelegate(JSContext *cx, uint32_t return false; } -JSObject* getObjectFromNamespace(JSContext* cx, JSObject *ns, const char *name) { +JSObject* getObjectFromNamespace(JSContext* cx, JS::HandleObject ns, const char *name) { JS::RootedValue out(cx); bool ok = true; if (JS_GetProperty(cx, ns, name, &out) == true) { @@ -834,11 +866,11 @@ JSObject* getObjectFromNamespace(JSContext* cx, JSObject *ns, const char *name) return NULL; } -jsval anonEvaluate(JSContext *cx, JSObject *thisObj, const char* string) { - jsval out; - JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET +jsval anonEvaluate(JSContext *cx, JS::HandleObject thisObj, const char* string) { + JS::RootedValue out(cx); + //JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET if (JS_EvaluateScript(cx, thisObj, string, strlen(string), "(string)", 1, &out) == true) { - return out; + return out.get(); } return JSVAL_VOID; } @@ -852,18 +884,22 @@ JSCallbackWrapper::JSCallbackWrapper() JSCallbackWrapper::~JSCallbackWrapper() { JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_RemoveValueRoot(cx, &_jsCallback); + JS::RemoveValueRoot(cx, &_jsCallback); + JS::RemoveValueRoot(cx, &_jsThisObj); } void JSCallbackWrapper::setJSCallbackFunc(jsval func) { _jsCallback = func; JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); // Root the callback function. - JS_AddNamedValueRoot(cx, &_jsCallback, "JSCallbackWrapper_callback_func"); + JS::AddNamedValueRoot(cx, &_jsCallback, "JSCallbackWrapper_callback_func"); } void JSCallbackWrapper::setJSCallbackThis(jsval thisObj) { _jsThisObj = thisObj; + JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); + // Root the this object. + JS::AddNamedValueRoot(cx, &_jsThisObj, "JSCallbackWrapper_callback_this"); } void JSCallbackWrapper::setJSExtraData(jsval data) { @@ -872,17 +908,17 @@ void JSCallbackWrapper::setJSExtraData(jsval data) { const jsval& JSCallbackWrapper::getJSCallbackFunc() const { - return _jsCallback; + return _jsCallback.get(); } const jsval& JSCallbackWrapper::getJSCallbackThis() const { - return _jsThisObj; + return _jsThisObj.get(); } const jsval& JSCallbackWrapper::getJSExtraData() const { - return _extraData; + return _extraData.get(); } // cc.CallFunc.create( func, this, [data]) @@ -890,32 +926,35 @@ const jsval& JSCallbackWrapper::getJSExtraData() const static bool js_callFunc(JSContext *cx, uint32_t argc, jsval *vp) { if (argc >= 1 && argc <= 3) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); std::shared_ptr tmpCobj(new JSCallbackWrapper()); - tmpCobj->setJSCallbackFunc(argv[0]); + tmpCobj->setJSCallbackFunc(args.get(0)); if(argc >= 2) { - tmpCobj->setJSCallbackThis(argv[1]); + tmpCobj->setJSCallbackThis(args.get(1)); } if(argc == 3) { - tmpCobj->setJSExtraData(argv[2]); + tmpCobj->setJSExtraData(args.get(2)); } CallFuncN *ret = CallFuncN::create([=](Node* sender){ - const jsval& jsvalThis = tmpCobj->getJSCallbackThis(); - const jsval& jsvalCallback = tmpCobj->getJSCallbackFunc(); - const jsval& jsvalExtraData = tmpCobj->getJSExtraData(); - - bool hasExtraData = !JSVAL_IS_VOID(jsvalExtraData); - JSObject* thisObj = JSVAL_IS_VOID(jsvalThis) ? nullptr : JSVAL_TO_OBJECT(jsvalThis); - +// const jsval& jsvalThis = tmpCobj->getJSCallbackThis(); +// const jsval& jsvalCallback = tmpCobj->getJSCallbackFunc(); +// const jsval& jsvalExtraData = tmpCobj->getJSExtraData(); + JS::RootedValue jsvalThis(cx, tmpCobj->getJSCallbackThis()); + JS::RootedValue jsvalCallback(cx, tmpCobj->getJSCallbackFunc()); + JS::RootedValue jsvalExtraData(cx, tmpCobj->getJSExtraData()); + + bool hasExtraData = !jsvalExtraData.isUndefined(); + JS::RootedObject thisObj(cx, jsvalThis.toObjectOrNull()); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET if(sender) { js_proxy_t *proxy = js_get_or_create_proxy(cx, sender); - jsval retval; + JS::RootedValue retval(cx); if(jsvalCallback != JSVAL_VOID) { if (hasExtraData) @@ -924,24 +963,29 @@ static bool js_callFunc(JSContext *cx, uint32_t argc, jsval *vp) valArr[0] = OBJECT_TO_JSVAL(proxy->obj); valArr[1] = jsvalExtraData; - JS_AddValueRoot(cx, valArr); - JS_CallFunctionValue(cx, thisObj, jsvalCallback, 2, valArr, &retval); - JS_RemoveValueRoot(cx, valArr); + //TODO: really need root? +// JS_AddValueRoot(cx, valArr); + JS::HandleValueArray args = JS::HandleValueArray::fromMarkedLocation(2, valArr); + JS_CallFunctionValue(cx, thisObj, jsvalCallback, args, &retval); +// JS_RemoveValueRoot(cx, valArr); } else { jsval senderVal = OBJECT_TO_JSVAL(proxy->obj); - JS_AddValueRoot(cx, &senderVal); - JS_CallFunctionValue(cx, thisObj, jsvalCallback, 1, &senderVal, &retval); - JS_RemoveValueRoot(cx, &senderVal); + JS::HandleValueArray args = JS::HandleValueArray::fromMarkedLocation(1, &senderVal); +// JS_AddValueRoot(cx, &senderVal); + + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + + JS_CallFunctionValue(cx, thisObj, jsvalCallback, args, &retval); +// JS_RemoveValueRoot(cx, &senderVal); } } } else { - jsval arg; - jsval ret; - JS_CallFunctionValue(cx, thisObj, jsvalCallback, 0, &arg, &ret); + JS::RootedValue ret(cx); + JS_CallFunctionValue(cx, thisObj, jsvalCallback, JS::HandleValueArray::empty(), &ret); } // I think the JSCallFuncWrapper isn't needed. @@ -951,14 +995,14 @@ static bool js_callFunc(JSContext *cx, uint32_t argc, jsval *vp) }); js_proxy_t *proxy = js_get_or_create_proxy(cx, ret); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(proxy->obj)); + args.rval().set(OBJECT_TO_JSVAL(proxy->obj)); - JS_SetReservedSlot(proxy->obj, 0, argv[0]); + JS_SetReservedSlot(proxy->obj, 0, args.get(0)); if(argc > 1) { - JS_SetReservedSlot(proxy->obj, 1, argv[1]); + JS_SetReservedSlot(proxy->obj, 1, args.get(1)); } // if(argc == 3) { -// JS_SetReservedSlot(proxy->obj, 2, argv[2]); +// JS_SetReservedSlot(proxy->obj, 2, args.get(2)); // } // test->execute(); @@ -978,24 +1022,27 @@ bool js_cocos2dx_CallFunc_initWithFunction(JSContext *cx, uint32_t argc, jsval * CallFuncN *action = (cocos2d::CallFuncN *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2(action, cx, false, "Invalid Native Object"); - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); std::shared_ptr tmpCobj(new JSCallbackWrapper()); - tmpCobj->setJSCallbackFunc(argv[0]); + tmpCobj->setJSCallbackFunc(args.get(0)); if(argc >= 2) { - tmpCobj->setJSCallbackThis(argv[1]); + tmpCobj->setJSCallbackThis(args.get(1)); } if(argc == 3) { - tmpCobj->setJSExtraData(argv[2]); + tmpCobj->setJSExtraData(args.get(2)); } action->initWithFunction([=](Node* sender){ - const jsval& jsvalThis = tmpCobj->getJSCallbackThis(); - const jsval& jsvalCallback = tmpCobj->getJSCallbackFunc(); - const jsval& jsvalExtraData = tmpCobj->getJSExtraData(); +// const jsval& jsvalThis = tmpCobj->getJSCallbackThis(); +// const jsval& jsvalCallback = tmpCobj->getJSCallbackFunc(); +// const jsval& jsvalExtraData = tmpCobj->getJSExtraData(); + JS::RootedValue jsvalThis(cx, tmpCobj->getJSCallbackThis()); + JS::RootedValue jsvalCallback(cx, tmpCobj->getJSCallbackFunc()); + JS::RootedValue jsvalExtraData(cx, tmpCobj->getJSExtraData()); - bool hasExtraData = !JSVAL_IS_VOID(jsvalExtraData); - JSObject* thisObj = JSVAL_IS_VOID(jsvalThis) ? nullptr : JSVAL_TO_OBJECT(jsvalThis); + bool hasExtraData = !jsvalExtraData.isUndefined(); + JS::RootedObject thisObj(cx, jsvalThis.toObjectOrNull()); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET @@ -1003,7 +1050,7 @@ bool js_cocos2dx_CallFunc_initWithFunction(JSContext *cx, uint32_t argc, jsval * { js_proxy_t *proxy = js_get_or_create_proxy(cx, sender); - jsval retval; + JS::RootedValue retval(cx); if(jsvalCallback != JSVAL_VOID) { if (hasExtraData) @@ -1012,24 +1059,29 @@ bool js_cocos2dx_CallFunc_initWithFunction(JSContext *cx, uint32_t argc, jsval * valArr[0] = OBJECT_TO_JSVAL(proxy->obj); valArr[1] = jsvalExtraData; - JS_AddValueRoot(cx, valArr); - JS_CallFunctionValue(cx, thisObj, jsvalCallback, 2, valArr, &retval); - JS_RemoveValueRoot(cx, valArr); +// JS_AddValueRoot(cx, valArr); +// JS_CallFunctionValue(cx, thisObj, jsvalCallback, 2, valArr, &retval); +// JS_RemoveValueRoot(cx, valArr); + + JS::HandleValueArray args = JS::HandleValueArray::fromMarkedLocation(2, valArr); + JS_CallFunctionValue(cx, thisObj, jsvalCallback, args, &retval); } else { jsval senderVal = OBJECT_TO_JSVAL(proxy->obj); - JS_AddValueRoot(cx, &senderVal); - JS_CallFunctionValue(cx, thisObj, jsvalCallback, 1, &senderVal, &retval); - JS_RemoveValueRoot(cx, &senderVal); +// JS_AddValueRoot(cx, &senderVal); +// JS_CallFunctionValue(cx, thisObj, jsvalCallback, 1, &senderVal, &retval); +// JS_RemoveValueRoot(cx, &senderVal); + + JS::HandleValueArray args = JS::HandleValueArray::fromMarkedLocation(1, &senderVal); + JS_CallFunctionValue(cx, thisObj, jsvalCallback, args, &retval); } } } else { - jsval arg; - jsval ret; - JS_CallFunctionValue(cx, thisObj, jsvalCallback, 0, &arg, &ret); + JS::RootedValue ret(cx); + JS_CallFunctionValue(cx, thisObj, jsvalCallback, JS::HandleValueArray::empty(), &ret); } @@ -1039,9 +1091,9 @@ bool js_cocos2dx_CallFunc_initWithFunction(JSContext *cx, uint32_t argc, jsval * // JSCallFuncWrapper::setTargetForNativeNode(node, (JSCallFuncWrapper *)this); }); - JS_SetReservedSlot(proxy->obj, 0, argv[0]); + JS_SetReservedSlot(proxy->obj, 0, args.get(0)); if(argc > 1) { - JS_SetReservedSlot(proxy->obj, 1, argv[1]); + JS_SetReservedSlot(proxy->obj, 1, args.get(1)); } return true; } @@ -1051,15 +1103,15 @@ bool js_cocos2dx_CallFunc_initWithFunction(JSContext *cx, uint32_t argc, jsval * JSScheduleWrapper::~JSScheduleWrapper() { - if (_pPureJSTarget) { + if (_pPureJSTarget.get()) { JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_RemoveObjectRoot(cx, &_pPureJSTarget); + JS::RemoveObjectRoot(cx, &_pPureJSTarget); } } -void JSScheduleWrapper::setTargetForSchedule(jsval sched, JSScheduleWrapper *target) { +void JSScheduleWrapper::setTargetForSchedule(JS::HandleValue sched, JSScheduleWrapper *target) { do { - JSObject* jsfunc = JSVAL_TO_OBJECT(sched); + JSObject* jsfunc = sched.toObjectOrNull(); auto targetArray = getTargetForSchedule(sched); if (NULL == targetArray) { targetArray = new __Array(); @@ -1077,15 +1129,15 @@ void JSScheduleWrapper::setTargetForSchedule(jsval sched, JSScheduleWrapper *tar } while(0); } -__Array * JSScheduleWrapper::getTargetForSchedule(jsval sched) { +__Array * JSScheduleWrapper::getTargetForSchedule(JS::HandleValue sched) { schedFunc_proxy_t *t = NULL; - JSObject *o = JSVAL_TO_OBJECT(sched); + JSObject *o = sched.toObjectOrNull(); HASH_FIND_PTR(_schedFunc_target_ht, &o, t); return t != NULL ? t->targets : NULL; } -void JSScheduleWrapper::setTargetForJSObject(JSObject* jsTargetObj, JSScheduleWrapper *target) +void JSScheduleWrapper::setTargetForJSObject(JS::HandleObject jsTargetObj, JSScheduleWrapper *target) { auto targetArray = getTargetForJSObject(jsTargetObj); if (NULL == targetArray) { @@ -1102,10 +1154,10 @@ void JSScheduleWrapper::setTargetForJSObject(JSObject* jsTargetObj, JSScheduleWr targetArray->addObject(target); } -__Array * JSScheduleWrapper::getTargetForJSObject(JSObject* jsTargetObj) +__Array * JSScheduleWrapper::getTargetForJSObject(JS::HandleObject jsTargetObj) { schedTarget_proxy_t *t = NULL; - HASH_FIND_PTR(_schedObj_target_ht, &jsTargetObj, t); + HASH_FIND_PTR(_schedObj_target_ht, &jsTargetObj.get(), t); return t != NULL ? t->targets : NULL; } @@ -1210,13 +1262,13 @@ void JSScheduleWrapper::removeAllTargetsForMinPriority(int minPriority) CCLOGINFO("removeAllTargetsForPriority end"); } -void JSScheduleWrapper::removeAllTargetsForJSObject(JSObject* jsTargetObj) +void JSScheduleWrapper::removeAllTargetsForJSObject(JS::HandleObject jsTargetObj) { CCLOGINFO("removeAllTargetsForNatiaveNode begin"); dump(); __Array* removeNativeTargets = NULL; schedTarget_proxy_t *t = NULL; - HASH_FIND_PTR(_schedObj_target_ht, &jsTargetObj, t); + HASH_FIND_PTR(_schedObj_target_ht, &jsTargetObj.get(), t); if (t != NULL) { removeNativeTargets = t->targets; HASH_DEL(_schedObj_target_ht, t); @@ -1258,12 +1310,12 @@ void JSScheduleWrapper::removeAllTargetsForJSObject(JSObject* jsTargetObj) CCLOGINFO("removeAllTargetsForNatiaveNode end"); } -void JSScheduleWrapper::removeTargetForJSObject(JSObject* jsTargetObj, JSScheduleWrapper* target) +void JSScheduleWrapper::removeTargetForJSObject(JS::HandleObject jsTargetObj, JSScheduleWrapper* target) { CCLOGINFO("removeTargetForJSObject begin"); dump(); schedTarget_proxy_t *t = NULL; - HASH_FIND_PTR(_schedObj_target_ht, &jsTargetObj, t); + HASH_FIND_PTR(_schedObj_target_ht, &jsTargetObj.get(), t); if (t != NULL) { t->targets->removeObject(target); if (t->targets->count() == 0) @@ -1341,46 +1393,44 @@ void JSScheduleWrapper::dump() void JSScheduleWrapper::scheduleFunc(float dt) { - jsval retval = JSVAL_NULL; jsval data = DOUBLE_TO_JSVAL(dt); JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - bool ok = JS_AddValueRoot(cx, &data); - if (!ok) { - CCLOG("scheduleFunc: Root value fails."); - return; - } + //XXX: really need root? +// bool ok = JS_AddValueRoot(cx, &data); +// if (!ok) { +// CCLOG("scheduleFunc: Root value fails."); +// return; +// } JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET if(!_jsCallback.isNullOrUndefined()) { - if (!_jsThisObj.isNullOrUndefined()) { - JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(_jsThisObj), _jsCallback, 1, &data, &retval); - } - else { - JS_CallFunctionValue(cx, NULL, _jsCallback, 1, &data, &retval); - } + JS::HandleValueArray args = JS::HandleValueArray::fromMarkedLocation(1, &data); + JS::RootedValue retval(cx); + JS_CallFunctionValue(cx, JS::RootedObject(cx, _jsThisObj.toObjectOrNull()), JS::RootedValue(cx, _jsCallback.get()), args, &retval); } - JS_RemoveValueRoot(cx, &data); +// JS_RemoveValueRoot(cx, &data); } void JSScheduleWrapper::update(float dt) { jsval data = DOUBLE_TO_JSVAL(dt); - JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); + //XXX: really need root? +// JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - bool ok = JS_AddValueRoot(cx, &data); - if (!ok) { - CCLOG("scheduleFunc: Root value fails."); - return; - } +// bool ok = JS_AddValueRoot(cx, &data); +// if (!ok) { +// CCLOG("scheduleFunc: Root value fails."); +// return; +// } ScriptingCore::getInstance()->executeFunctionWithOwner(_jsThisObj, "update", 1, &data); - JS_RemoveValueRoot(cx, &data); +// JS_RemoveValueRoot(cx, &data); } Ref* JSScheduleWrapper::getTarget() @@ -1393,17 +1443,17 @@ void JSScheduleWrapper::setTarget(Ref* pTarget) _pTarget = pTarget; } -void JSScheduleWrapper::setPureJSTarget(JSObject* pPureJSTarget) +void JSScheduleWrapper::setPureJSTarget(JS::HandleObject pPureJSTarget) { CCASSERT(_pPureJSTarget == NULL, "The pure js target has been set"); JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); _pPureJSTarget = pPureJSTarget; - JS_AddNamedObjectRoot(cx, &_pPureJSTarget, "Pure JS target"); + JS::AddNamedObjectRoot(cx, &_pPureJSTarget, "Pure JS target"); } JSObject* JSScheduleWrapper::getPureJSTarget() { - return _pPureJSTarget; + return _pPureJSTarget.get(); } void JSScheduleWrapper::setPriority(int priority) @@ -1429,16 +1479,16 @@ bool JSScheduleWrapper::isUpdateSchedule() bool js_CCNode_unschedule(JSContext *cx, uint32_t argc, jsval *vp) { if (argc == 1) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node *node = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2(node, cx, false, "Invalid Native Object"); Scheduler *sched = node->getScheduler(); - auto targetArray = JSScheduleWrapper::getTargetForSchedule(argv[0]); + auto targetArray = JSScheduleWrapper::getTargetForSchedule(args.get(0)); CCLOGINFO("unschedule target number: %d", targetArray->count()); Ref* tmp = NULL; CCARRAY_FOREACH(targetArray, tmp) @@ -1452,14 +1502,15 @@ bool js_CCNode_unschedule(JSContext *cx, uint32_t argc, jsval *vp) } } - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); } return true; } bool js_cocos2dx_CCNode_unscheduleAllSelectors(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, cobj) @@ -1484,7 +1535,7 @@ bool js_cocos2dx_CCNode_unscheduleAllSelectors(JSContext *cx, uint32_t argc, jsv JSScheduleWrapper::removeAllTargetsForJSObject(obj); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); @@ -1495,9 +1546,10 @@ bool js_CCNode_scheduleOnce(JSContext *cx, uint32_t argc, jsval *vp) { if (argc >= 1) { bool ok = true; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); +// JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node *node = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); @@ -1510,7 +1562,7 @@ bool js_CCNode_scheduleOnce(JSContext *cx, uint32_t argc, jsval *vp) // double delay; if( argc >= 2 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[1]), &delay ); + ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(1)), &delay ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); } @@ -1520,7 +1572,7 @@ bool js_CCNode_scheduleOnce(JSContext *cx, uint32_t argc, jsval *vp) CCARRAY_FOREACH(pTargetArr, pObj) { JSScheduleWrapper* pTarget = static_cast(pObj); - if (argv[0] == pTarget->getJSCallbackFunc()) + if (args.get(0) == pTarget->getJSCallbackFunc()) { tmpCobj = pTarget; bFound = true; @@ -1533,10 +1585,10 @@ bool js_CCNode_scheduleOnce(JSContext *cx, uint32_t argc, jsval *vp) tmpCobj = new JSScheduleWrapper(); tmpCobj->autorelease(); tmpCobj->setJSCallbackThis(OBJECT_TO_JSVAL(obj)); - tmpCobj->setJSCallbackFunc(argv[0]); + tmpCobj->setJSCallbackFunc(args.get(0)); tmpCobj->setTarget(node); - JSScheduleWrapper::setTargetForSchedule(argv[0], tmpCobj); + JSScheduleWrapper::setTargetForSchedule(args.get(0), tmpCobj); JSScheduleWrapper::setTargetForJSObject(obj, tmpCobj); } @@ -1561,9 +1613,9 @@ bool js_CCNode_scheduleOnce(JSContext *cx, uint32_t argc, jsval *vp) the js callback function in JSScheduleWrapper::setJSCallbackFunc and unroot it at the destructor of JSScheduleWrapper. */ - //jsb_set_reserved_slot(proxy->obj, 0, argv[0]); + //jsb_set_reserved_slot(proxy->obj, 0, args.get(0)); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -1574,9 +1626,10 @@ bool js_CCNode_schedule(JSContext *cx, uint32_t argc, jsval *vp) { if (argc >= 1) { bool ok = true; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); +// JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node *node = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); Scheduler *sched = node->getScheduler(); @@ -1585,7 +1638,7 @@ bool js_CCNode_schedule(JSContext *cx, uint32_t argc, jsval *vp) double interval = 0.0; if( argc >= 2 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[1]), &interval ); + ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(1)), &interval ); } // @@ -1593,7 +1646,7 @@ bool js_CCNode_schedule(JSContext *cx, uint32_t argc, jsval *vp) // double repeat = 0.0; if( argc >= 3 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[2]), &repeat ); + ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(2)), &repeat ); } // @@ -1601,7 +1654,7 @@ bool js_CCNode_schedule(JSContext *cx, uint32_t argc, jsval *vp) // double delay = 0.0; if( argc >= 4 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[3]), &delay ); + ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(3)), &delay ); } JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); @@ -1612,7 +1665,7 @@ bool js_CCNode_schedule(JSContext *cx, uint32_t argc, jsval *vp) CCARRAY_FOREACH(pTargetArr, pObj) { JSScheduleWrapper* pTarget = static_cast(pObj); - if (argv[0] == pTarget->getJSCallbackFunc()) + if (args.get(0) == pTarget->getJSCallbackFunc()) { tmpCobj = pTarget; bFound = true; @@ -1625,9 +1678,9 @@ bool js_CCNode_schedule(JSContext *cx, uint32_t argc, jsval *vp) tmpCobj = new JSScheduleWrapper(); tmpCobj->autorelease(); tmpCobj->setJSCallbackThis(OBJECT_TO_JSVAL(obj)); - tmpCobj->setJSCallbackFunc(argv[0]); + tmpCobj->setJSCallbackFunc(args.get(0)); tmpCobj->setTarget(node); - JSScheduleWrapper::setTargetForSchedule(argv[0], tmpCobj); + JSScheduleWrapper::setTargetForSchedule(args.get(0), tmpCobj); JSScheduleWrapper::setTargetForJSObject(obj, tmpCobj); } @@ -1642,9 +1695,9 @@ bool js_CCNode_schedule(JSContext *cx, uint32_t argc, jsval *vp) } // I comment next line with the same reason in the js_CCNode_scheduleOnce. - //jsb_set_reserved_slot(proxy->obj, 0, argv[0]); + //jsb_set_reserved_slot(proxy->obj, 0, args.get(0)); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -1653,15 +1706,16 @@ bool js_CCNode_schedule(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCNode_scheduleUpdateWithPriority(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); +// JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { int arg0 = 0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); bool isFoundUpdate = false; @@ -1673,7 +1727,7 @@ bool js_cocos2dx_CCNode_scheduleUpdateWithPriority(JSContext *cx, uint32_t argc, // if no 'update' property, return true directly. if (!ok) { - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1708,7 +1762,7 @@ bool js_cocos2dx_CCNode_scheduleUpdateWithPriority(JSContext *cx, uint32_t argc, tmpCobj->setPriority(arg0); cobj->getScheduler()->scheduleUpdate(tmpCobj, arg0, !cobj->isRunning()); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1718,7 +1772,9 @@ bool js_cocos2dx_CCNode_scheduleUpdateWithPriority(JSContext *cx, uint32_t argc, bool js_cocos2dx_CCNode_unscheduleUpdate(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); +// JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, cobj) @@ -1727,9 +1783,9 @@ bool js_cocos2dx_CCNode_unscheduleUpdate(JSContext *cx, uint32_t argc, jsval *vp { cobj->unscheduleUpdate(); do { - JSObject *tmpObj = obj; +// JSObject *tmpObj = obj; - __Array *arr = JSScheduleWrapper::getTargetForJSObject(tmpObj); + __Array *arr = JSScheduleWrapper::getTargetForJSObject(obj); // If there aren't any targets, just return true. // Otherwise, the for loop will break immediately. // It will lead to logic errors. @@ -1741,14 +1797,14 @@ bool js_cocos2dx_CCNode_unscheduleUpdate(JSContext *cx, uint32_t argc, jsval *vp wrapper = (JSScheduleWrapper*)arr->getObjectAtIndex(i); if(wrapper && wrapper->isUpdateSchedule()) { cobj->getScheduler()->unscheduleUpdate(wrapper); - CCASSERT(OBJECT_TO_JSVAL(tmpObj) == wrapper->getJSCallbackThis(), "Wrong target object."); - JSScheduleWrapper::removeTargetForJSObject(tmpObj, wrapper); + CCASSERT(OBJECT_TO_JSVAL(obj) == wrapper->getJSCallbackThis(), "Wrong target object."); + JSScheduleWrapper::removeTargetForJSObject(obj, wrapper); break; } } } while (0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); @@ -1757,8 +1813,10 @@ bool js_cocos2dx_CCNode_unscheduleUpdate(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_CCNode_scheduleUpdate(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); +// JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); @@ -1773,7 +1831,7 @@ bool js_cocos2dx_CCNode_scheduleUpdate(JSContext *cx, uint32_t argc, jsval *vp) // if no 'update' property, return true directly. if (!ok) { - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1807,7 +1865,7 @@ bool js_cocos2dx_CCNode_scheduleUpdate(JSContext *cx, uint32_t argc, jsval *vp) cobj->getScheduler()->scheduleUpdate(tmpCobj, 0, !cobj->isRunning()); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1817,7 +1875,7 @@ bool js_cocos2dx_CCNode_scheduleUpdate(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCScheduler_unscheduleAllSelectorsForTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scheduler* cobj = (cocos2d::Scheduler *)(proxy ? proxy->ptr : NULL); @@ -1825,7 +1883,7 @@ bool js_cocos2dx_CCScheduler_unscheduleAllSelectorsForTarget(JSContext *cx, uint if (argc == 1) { do { - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); __Array *arr = JSScheduleWrapper::getTargetForJSObject(tmpObj); // If there aren't any targets, just return true. @@ -1845,7 +1903,7 @@ bool js_cocos2dx_CCScheduler_unscheduleAllSelectorsForTarget(JSContext *cx, uint } while (0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); @@ -1856,7 +1914,7 @@ bool js_CCScheduler_scheduleUpdateForTarget(JSContext *cx, uint32_t argc, jsval { if (argc >= 1) { bool ok = true; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -1864,7 +1922,7 @@ bool js_CCScheduler_scheduleUpdateForTarget(JSContext *cx, uint32_t argc, jsval JSScheduleWrapper *tmpCObj = NULL; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); proxy = jsb_get_js_proxy(tmpObj); bool isPureJSTarget = proxy ? false : true; @@ -1877,19 +1935,19 @@ bool js_CCScheduler_scheduleUpdateForTarget(JSContext *cx, uint32_t argc, jsval // if no 'update' property, return true directly. if (!ok) { - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } int arg1 = 0; if (argc >= 2) { - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); } bool paused = false; if( argc >= 3 ) { - paused = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + paused = JS::ToBoolean(JS::RootedValue(cx, args.get(2))); } JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); @@ -1912,7 +1970,7 @@ bool js_CCScheduler_scheduleUpdateForTarget(JSContext *cx, uint32_t argc, jsval { tmpCObj = new JSScheduleWrapper(); tmpCObj->autorelease(); - tmpCObj->setJSCallbackThis(argv[0]); + tmpCObj->setJSCallbackThis(args.get(0)); tmpCObj->setJSCallbackFunc(jsUpdateFunc); tmpCObj->setUpdateSchedule(true); if (isPureJSTarget) { @@ -1925,7 +1983,7 @@ bool js_CCScheduler_scheduleUpdateForTarget(JSContext *cx, uint32_t argc, jsval tmpCObj->setPriority(arg1); sched->scheduleUpdate(tmpCObj, arg1, paused); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -1934,7 +1992,7 @@ bool js_CCScheduler_scheduleUpdateForTarget(JSContext *cx, uint32_t argc, jsval bool js_CCScheduler_unscheduleUpdateForTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scheduler* cobj = (cocos2d::Scheduler *)(proxy ? proxy->ptr : NULL); @@ -1942,7 +2000,7 @@ bool js_CCScheduler_unscheduleUpdateForTarget(JSContext *cx, uint32_t argc, jsva if (argc == 1) { do { - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); __Array *arr = JSScheduleWrapper::getTargetForJSObject(tmpObj); // If there aren't any targets, just return true. @@ -1956,14 +2014,14 @@ bool js_CCScheduler_unscheduleUpdateForTarget(JSContext *cx, uint32_t argc, jsva wrapper = (JSScheduleWrapper*)arr->getObjectAtIndex(i); if(wrapper && wrapper->isUpdateSchedule()) { cobj->unscheduleUpdate(wrapper); - CCASSERT(argv[0] == wrapper->getJSCallbackThis(), "Wrong target object."); + CCASSERT(args.get(0) == wrapper->getJSCallbackThis(), "Wrong target object."); JSScheduleWrapper::removeTargetForJSObject(tmpObj, wrapper); break; } } } while (0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); @@ -1974,7 +2032,7 @@ bool js_CCScheduler_schedule(JSContext *cx, uint32_t argc, jsval *vp) { if (argc >= 2) { bool ok = true; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -1982,13 +2040,13 @@ bool js_CCScheduler_schedule(JSContext *cx, uint32_t argc, jsval *vp) JSScheduleWrapper *tmpCObj = NULL; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); proxy = jsb_get_js_proxy(tmpObj); bool isPureJSTarget = proxy ? false : true; double interval = 0; if( argc >= 3 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[2]), &interval ); + ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(2)), &interval ); } // @@ -1996,7 +2054,7 @@ bool js_CCScheduler_schedule(JSContext *cx, uint32_t argc, jsval *vp) // double repeat = kRepeatForever; if( argc >= 4 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[3]), &repeat ); + ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(3)), &repeat ); } // @@ -2004,13 +2062,13 @@ bool js_CCScheduler_schedule(JSContext *cx, uint32_t argc, jsval *vp) // double delay = 0; if( argc >= 5 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[4]), &delay ); + ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(4)), &delay ); } bool paused = false; if( argc >= 6 ) { - paused = JS::ToBoolean(JS::RootedValue(cx, argv[5])); + paused = JS::ToBoolean(JS::RootedValue(cx, args.get(5))); } JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); @@ -2021,7 +2079,7 @@ bool js_CCScheduler_schedule(JSContext *cx, uint32_t argc, jsval *vp) CCARRAY_FOREACH(pTargetArr, pObj) { JSScheduleWrapper* pTarget = static_cast(pObj); - if (argv[1] == pTarget->getJSCallbackFunc()) + if (args.get(1) == pTarget->getJSCallbackFunc()) { tmpCObj = pTarget; bFound = true; @@ -2033,19 +2091,19 @@ bool js_CCScheduler_schedule(JSContext *cx, uint32_t argc, jsval *vp) { tmpCObj = new JSScheduleWrapper(); tmpCObj->autorelease(); - tmpCObj->setJSCallbackThis(argv[0]); - tmpCObj->setJSCallbackFunc(argv[1]); + tmpCObj->setJSCallbackThis(args.get(0)); + tmpCObj->setJSCallbackFunc(args.get(1)); if (isPureJSTarget) { tmpCObj->setPureJSTarget(tmpObj); } - JSScheduleWrapper::setTargetForSchedule(argv[1], tmpCObj); + JSScheduleWrapper::setTargetForSchedule(args.get(1), tmpCObj); JSScheduleWrapper::setTargetForJSObject(tmpObj, tmpCObj); } sched->schedule(schedule_selector(JSScheduleWrapper::scheduleFunc), tmpCObj, interval, repeat, delay, paused); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -2054,7 +2112,7 @@ bool js_CCScheduler_schedule(JSContext *cx, uint32_t argc, jsval *vp) bool js_CCScheduler_unscheduleCallbackForTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scheduler* cobj = (cocos2d::Scheduler *)(proxy ? proxy->ptr : NULL); @@ -2062,7 +2120,7 @@ bool js_CCScheduler_unscheduleCallbackForTarget(JSContext *cx, uint32_t argc, js if (argc == 2) { do { - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); __Array *arr = JSScheduleWrapper::getTargetForJSObject(tmpObj); // If there aren't any targets, just return true. @@ -2074,7 +2132,7 @@ bool js_CCScheduler_unscheduleCallbackForTarget(JSContext *cx, uint32_t argc, js JSScheduleWrapper* wrapper = NULL; for(ssize_t i = 0; i < arr->count(); ++i) { wrapper = (JSScheduleWrapper*)arr->getObjectAtIndex(i); - if(wrapper && wrapper->getJSCallbackFunc() == argv[1]) { + if(wrapper && wrapper->getJSCallbackFunc() == args.get(1)) { cobj->unschedule(schedule_selector(JSScheduleWrapper::scheduleFunc), wrapper); JSScheduleWrapper::removeTargetForJSObject(tmpObj, wrapper); break; @@ -2082,7 +2140,7 @@ bool js_CCScheduler_unscheduleCallbackForTarget(JSContext *cx, uint32_t argc, js } } while (0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); @@ -2091,14 +2149,15 @@ bool js_CCScheduler_unscheduleCallbackForTarget(JSContext *cx, uint32_t argc, js bool js_cocos2dx_CCScheduler_unscheduleAll(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scheduler* cobj = (cocos2d::Scheduler *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 0) { cobj->unscheduleAll(); JSScheduleWrapper::removeAllTargets(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2108,7 +2167,7 @@ bool js_cocos2dx_CCScheduler_unscheduleAll(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_CCScheduler_unscheduleAllCallbacksWithMinPriority(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -2116,11 +2175,11 @@ bool js_cocos2dx_CCScheduler_unscheduleAllCallbacksWithMinPriority(JSContext *cx JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->unscheduleAllWithMinPriority(arg0); JSScheduleWrapper::removeAllTargetsForMinPriority(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2131,14 +2190,14 @@ bool js_cocos2dx_CCScheduler_unscheduleAllCallbacksWithMinPriority(JSContext *cx bool js_cocos2dx_CCScheduler_pauseTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scheduler *sched = (cocos2d::Scheduler *)(proxy ? proxy->ptr : NULL); if (argc == 1) { do { - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); __Array *arr = JSScheduleWrapper::getTargetForJSObject(tmpObj); if(! arr) return true; for(ssize_t i = 0; i < arr->count(); ++i) { @@ -2148,7 +2207,7 @@ bool js_cocos2dx_CCScheduler_pauseTarget(JSContext *cx, uint32_t argc, jsval *vp } } while (0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); @@ -2157,14 +2216,14 @@ bool js_cocos2dx_CCScheduler_pauseTarget(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_CCScheduler_resumeTarget(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scheduler *sched = (cocos2d::Scheduler *)(proxy ? proxy->ptr : NULL); if (argc == 1) { do { - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); auto arr = JSScheduleWrapper::getTargetForJSObject(tmpObj); if(! arr) return true; for(ssize_t i = 0; i < arr->count(); ++i) { @@ -2174,7 +2233,7 @@ bool js_cocos2dx_CCScheduler_resumeTarget(JSContext *cx, uint32_t argc, jsval *v } } while (0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); @@ -2183,7 +2242,7 @@ bool js_cocos2dx_CCScheduler_resumeTarget(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_CCScheduler_isTargetPaused(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Scheduler* cobj = (cocos2d::Scheduler *)(proxy ? proxy->ptr : NULL); @@ -2191,7 +2250,7 @@ bool js_cocos2dx_CCScheduler_isTargetPaused(JSContext *cx, uint32_t argc, jsval if (argc == 1) { bool ret = false; do { - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); __Array *arr = JSScheduleWrapper::getTargetForJSObject(tmpObj); if(! arr) return true; for(ssize_t i = 0; i < arr->count(); ++i) { @@ -2202,7 +2261,8 @@ bool js_cocos2dx_CCScheduler_isTargetPaused(JSContext *cx, uint32_t argc, jsval } } } while (0); - JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret)); +// JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret)); + args.rval().set(BOOLEAN_TO_JSVAL(ret)); return true; } @@ -2210,10 +2270,6 @@ bool js_cocos2dx_CCScheduler_isTargetPaused(JSContext *cx, uint32_t argc, jsval return false; } -bool js_doNothing(JSContext *cx, uint32_t argc, jsval *vp) { - return true; -} - bool js_forceGC(JSContext *cx, uint32_t argc, jsval *vp) { JSRuntime *rt = JS_GetRuntime(cx); JS_GC(rt); @@ -2310,7 +2366,7 @@ bool js_cocos2dx_Node_onExitTransitionDidStart(JSContext *cx, uint32_t argc, jsv bool js_cocos2dx_CCNode_setPosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); bool ok = true; js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -2319,21 +2375,21 @@ bool js_cocos2dx_CCNode_setPosition(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->setPosition(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { double x; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[0]), &x ); + ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(0)), &x ); double y; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[1]), &y ); + ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(1)), &y ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->setPosition(Point(x,y)); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); @@ -2342,7 +2398,7 @@ bool js_cocos2dx_CCNode_setPosition(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCNode_setContentSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); bool ok = true; js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -2351,21 +2407,21 @@ bool js_cocos2dx_CCNode_setContentSize(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1) { cocos2d::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &arg0); + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->setContentSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { double width; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[0]), &width ); + ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(0)), &width ); double height; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[1]), &height ); + ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(1)), &height ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->setContentSize(Size(width,height)); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); @@ -2374,7 +2430,7 @@ bool js_cocos2dx_CCNode_setContentSize(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCNode_setAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp) { - JS::CallArgs argv = JS::CallArgsFromVp(argc, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); bool ok = true; js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -2383,21 +2439,21 @@ bool js_cocos2dx_CCNode_setAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->setAnchorPoint(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { double x; - ok &= JS::ToNumber(cx, argv[0], &x ); + ok &= JS::ToNumber(cx, args.get(0), &x ); double y; - ok &= JS::ToNumber(cx, argv[1], &y ); + ok &= JS::ToNumber(cx, args.get(1), &y ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->setAnchorPoint(Point(x,y)); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); @@ -2406,7 +2462,7 @@ bool js_cocos2dx_CCNode_setAnchorPoint(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCNode_setColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -2414,16 +2470,16 @@ bool js_cocos2dx_CCNode_setColor(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setColor : Invalid Native Object"); if (argc == 1) { cocos2d::Color3B arg0; - ok &= jsval_to_cccolor3b(cx, argv[0], &arg0); + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_setColor : Error processing arguments"); cobj->setColor(arg0); // int32_t alpha; -// ok &= jsval_cccolor_to_opacity(cx, argv[0], &alpha); +// ok &= jsval_cccolor_to_opacity(cx, args.get(0), &alpha); // if (ok) { // cobj->setOpacity(alpha); // } - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2434,15 +2490,15 @@ bool js_cocos2dx_CCNode_setColor(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCNode_pause(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSObject *obj = JSVAL_TO_OBJECT(args.thisv()); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_pause : Invalid Native Object"); if (argc == 0) { do { - JSObject *tmpObj = obj; +// JSObject *tmpObj = obj; - __Array *arr = JSScheduleWrapper::getTargetForJSObject(tmpObj); + __Array *arr = JSScheduleWrapper::getTargetForJSObject(obj); if(arr){ JSScheduleWrapper* wrapper = NULL; for(ssize_t i = 0; i < arr->count(); ++i) { @@ -2466,15 +2522,15 @@ bool js_cocos2dx_CCNode_pause(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCNode_resume(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSObject *obj = JSVAL_TO_OBJECT(args.thisv()); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_resume : Invalid Native Object"); if (argc == 0) { do { - JSObject *tmpObj = obj; +// JSObject *tmpObj = obj; - __Array *arr = JSScheduleWrapper::getTargetForJSObject(tmpObj); + __Array *arr = JSScheduleWrapper::getTargetForJSObject(obj); if(arr){ JSScheduleWrapper* wrapper = NULL; for(ssize_t i = 0; i < arr->count(); ++i) { @@ -2527,7 +2583,7 @@ bool js_cocos2dx_Component_onExit(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCTMXLayer_tileFlagsAt(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj; bool ok = true; cocos2d::TMXLayer* cobj; @@ -2538,11 +2594,11 @@ bool js_cocos2dx_CCTMXLayer_tileFlagsAt(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); cocos2d::TMXTileFlags flags = kTMXTileHorizontalFlag; jsval jsret; jsret = UINT_TO_JSVAL((uint32_t)flags); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -2551,7 +2607,8 @@ bool js_cocos2dx_CCTMXLayer_tileFlagsAt(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCTMXLayer_getTiles(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::TMXLayer* cobj = (cocos2d::TMXLayer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); @@ -2566,7 +2623,8 @@ bool js_cocos2dx_CCTMXLayer_getTiles(JSContext *cx, uint32_t argc, jsval *vp) } uint32_t* bufdata = (uint32_t*)JS_GetArrayBufferViewData(array); memcpy(bufdata, ret, count*sizeof(int32_t)); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(array)); + + args.rval().set(OBJECT_TO_JSVAL(array)); return true; } @@ -2579,16 +2637,16 @@ bool js_cocos2dx_CCTMXLayer_getTiles(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ActionInterval_repeat(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionInterval* cobj = (cocos2d::ActionInterval *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionInterval_repeat : Invalid Native Object"); - - JS::CallArgs argv = JS::CallArgsFromVp(argc, vp); + if (argc == 1) { double times; - if( ! JS::ToNumber(cx, argv[0], ×) ) { + if( ! JS::ToNumber(cx, args.get(0), ×) ) { return false; } int timesInt = (int)times; @@ -2598,13 +2656,13 @@ bool js_cocos2dx_ActionInterval_repeat(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Repeat* action = cocos2d::Repeat::create(cobj, timesInt); // Unbind current proxy binding - JS_RemoveObjectRoot(cx, &proxy->obj); + JS::RemoveObjectRoot(cx, &proxy->obj); jsb_remove_proxy(jsb_get_native_proxy(cobj), proxy); // Rebind js obj with new action js_proxy_t* newProxy = jsb_new_proxy(action, obj); - JS_AddNamedObjectRoot(cx, &newProxy->obj, "cocos2d::Repeat"); - - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + JS::AddNamedObjectRoot(cx, &newProxy->obj, "cocos2d::Repeat"); + + args.rval().set(OBJECT_TO_JSVAL(obj)); return true; } @@ -2614,7 +2672,8 @@ bool js_cocos2dx_ActionInterval_repeat(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ActionInterval_repeatForever(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionInterval* cobj = (cocos2d::ActionInterval *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionInterval_repeatForever : Invalid Native Object"); @@ -2622,13 +2681,13 @@ bool js_cocos2dx_ActionInterval_repeatForever(JSContext *cx, uint32_t argc, jsva if (argc == 0) { cocos2d::RepeatForever* action = cocos2d::RepeatForever::create(cobj); // Unbind current proxy binding - JS_RemoveObjectRoot(cx, &proxy->obj); + JS::RemoveObjectRoot(cx, &proxy->obj); jsb_remove_proxy(jsb_get_native_proxy(cobj), proxy); // Rebind js obj with new action js_proxy_t* newProxy = jsb_new_proxy(action, obj); - JS_AddNamedObjectRoot(cx, &newProxy->obj, "cocos2d::RepeatForever"); - - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + JS::AddNamedObjectRoot(cx, &newProxy->obj, "cocos2d::RepeatForever"); + + args.rval().set(OBJECT_TO_JSVAL(obj)); return true; } @@ -2638,16 +2697,16 @@ bool js_cocos2dx_ActionInterval_repeatForever(JSContext *cx, uint32_t argc, jsva bool js_cocos2dx_ActionInterval_speed(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionInterval* cobj = (cocos2d::ActionInterval *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionInterval_speed : Invalid Native Object"); - - JS::CallArgs argv = JS::CallArgsFromVp(argc, vp); + if (argc == 1) { double speed; - if( ! JS::ToNumber(cx, argv[0], &speed) ) { + if( ! JS::ToNumber(cx, args.get(0), &speed) ) { return false; } if (speed < 0) { @@ -2657,13 +2716,13 @@ bool js_cocos2dx_ActionInterval_speed(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Speed* action = cocos2d::Speed::create(cobj, speed); // Unbind current proxy binding - JS_RemoveObjectRoot(cx, &proxy->obj); + JS::RemoveObjectRoot(cx, &proxy->obj); jsb_remove_proxy(jsb_get_native_proxy(cobj), proxy); // Rebind js obj with new action js_proxy_t* newProxy = jsb_new_proxy(action, obj); - JS_AddNamedObjectRoot(cx, &newProxy->obj, "cocos2d::Speed"); - - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + JS::AddNamedObjectRoot(cx, &newProxy->obj, "cocos2d::Speed"); + + args.rval().set(OBJECT_TO_JSVAL(obj)); return true; } @@ -2711,13 +2770,13 @@ enum ACTION_TAG { bool js_cocos2dx_ActionInterval_easing(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ActionInterval* cobj = (cocos2d::ActionInterval *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionInterval_easing : Invalid Native Object"); cocos2d::ActionInterval* currentAction = cobj; - JS::CallArgs argv = JS::CallArgsFromVp(argc, vp); JS::RootedObject tmp(cx); JS::RootedValue jsTag(cx); JS::RootedValue jsParam(cx); @@ -2726,9 +2785,10 @@ bool js_cocos2dx_ActionInterval_easing(JSContext *cx, uint32_t argc, jsval *vp) for (int i = 0; i < argc; i++) { - jsval vpi = argv[i]; +// jsval vpi = argv[i]; + JS::RootedValue vpi(cx, args.get(i)); bool ok = vpi.isObject() && - JS_ValueToObject(cx, JS::RootedValue(cx, vpi), &tmp) && + JS_ValueToObject(cx, vpi, &tmp) && JS_GetProperty(cx, tmp, "tag", &jsTag) && JS::ToNumber(cx, jsTag, &tag); JS_GetProperty(cx, tmp, "param", &jsParam) && JS::ToNumber(cx, jsParam, ¶meter); @@ -2851,29 +2911,29 @@ bool js_cocos2dx_ActionInterval_easing(JSContext *cx, uint32_t argc, jsval *vp) } // Unbind current proxy binding - JS_RemoveObjectRoot(cx, &proxy->obj); + JS::RemoveObjectRoot(cx, &proxy->obj); jsb_remove_proxy(jsb_get_native_proxy(cobj), proxy); // Rebind js obj with new action js_proxy_t* newProxy = jsb_new_proxy(currentAction, obj); - JS_AddNamedObjectRoot(cx, &newProxy->obj, "cocos2d::EaseAction"); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + JS::AddNamedObjectRoot(cx, &newProxy->obj, "cocos2d::EaseAction"); + args.rval().set(OBJECT_TO_JSVAL(obj)); return true; } template bool js_BezierActions_create(JSContext *cx, uint32_t argc, jsval *vp) { - JS::CallArgs argv = JS::CallArgsFromVp(argc, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 2) { double t; - if( ! JS::ToNumber(cx, argv[0], &t) ) { + if( ! JS::ToNumber(cx, args.get(0), &t) ) { return false; } int num; Point *arr; - jsval_to_ccarray_of_CCPoint(cx, argv[1], &arr, &num); + jsval_to_ccarray_of_CCPoint(cx, args.get(1), &arr, &num); ccBezierConfig config; config.controlPoint_1 = arr[0]; @@ -2899,7 +2959,7 @@ bool js_BezierActions_create(JSContext *cx, uint32_t argc, jsval *vp) { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2910,7 +2970,7 @@ bool js_BezierActions_create(JSContext *cx, uint32_t argc, jsval *vp) { template bool js_BezierActions_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -2919,11 +2979,11 @@ bool js_BezierActions_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 2) { double arg0; cocos2d::_ccBezierConfig arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, JS::RootedValue(cx, args.get(0)), &arg0); int num; cocos2d::Vec2 *arr; - jsval_to_ccarray_of_CCPoint(cx, argv[1], &arr, &num); + jsval_to_ccarray_of_CCPoint(cx, args.get(1), &arr, &num); arg1.controlPoint_1 = arr[0]; arg1.controlPoint_2 = arr[1]; @@ -2934,7 +2994,7 @@ bool js_BezierActions_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) delete [] arr; jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2944,19 +3004,19 @@ bool js_BezierActions_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) template bool js_CardinalSplineActions_create(JSContext *cx, uint32_t argc, jsval *vp) { - JS::CallArgs argv = JS::CallArgsFromVp(argc, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 3) { double dur; - ok &= JS::ToNumber(cx, argv[0], &dur); + ok &= JS::ToNumber(cx, args.get(0), &dur); int num; Point *arr; - ok &= jsval_to_ccarray_of_CCPoint(cx, argv[1], &arr, &num); + ok &= jsval_to_ccarray_of_CCPoint(cx, args.get(1), &arr, &num); double ten; - ok &= JS::ToNumber(cx, argv[2], &ten); + ok &= JS::ToNumber(cx, args.get(2), &ten); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); @@ -2985,7 +3045,7 @@ bool js_CardinalSplineActions_create(JSContext *cx, uint32_t argc, jsval *vp) { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2995,16 +3055,16 @@ bool js_CardinalSplineActions_create(JSContext *cx, uint32_t argc, jsval *vp) { template bool js_CatmullRomActions_create(JSContext *cx, uint32_t argc, jsval *vp) { - JS::CallArgs argv = JS::CallArgsFromVp(argc, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { double dur; - ok &= JS::ToNumber(cx, argv[0], &dur); + ok &= JS::ToNumber(cx, args.get(0), &dur); int num; Point *arr; - ok &= jsval_to_ccarray_of_CCPoint(cx, argv[1], &arr, &num); + ok &= jsval_to_ccarray_of_CCPoint(cx, args.get(1), &arr, &num); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); @@ -3033,7 +3093,7 @@ bool js_CatmullRomActions_create(JSContext *cx, uint32_t argc, jsval *vp) { jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3043,7 +3103,7 @@ bool js_CatmullRomActions_create(JSContext *cx, uint32_t argc, jsval *vp) { template bool js_CatmullRomActions_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -3051,11 +3111,11 @@ bool js_CatmullRomActions_initWithDuration(JSContext *cx, uint32_t argc, jsval * JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_CatmullRom_initWithDuration : Invalid Native Object"); if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, JS::RootedValue(cx, args.get(0)), &arg0); int num; Point *arr; - ok &= jsval_to_ccarray_of_CCPoint(cx, argv[1], &arr, &num); + ok &= jsval_to_ccarray_of_CCPoint(cx, args.get(1), &arr, &num); cocos2d::PointArray* arg1 = cocos2d::PointArray::create(num); for( int i=0; i < num;i++) { @@ -3068,7 +3128,7 @@ bool js_CatmullRomActions_initWithDuration(JSContext *cx, uint32_t argc, jsval * delete [] arr; jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3105,7 +3165,7 @@ bool JSB_CCCardinalSplineTo_actionWithDuration(JSContext *cx, uint32_t argc, jsv bool js_cocos2dx_CardinalSplineTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -3115,24 +3175,24 @@ bool js_cocos2dx_CardinalSplineTo_initWithDuration(JSContext *cx, uint32_t argc, double arg0; double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, JS::RootedValue(cx, args.get(0)), &arg0); int num; Point *arr; - ok &= jsval_to_ccarray_of_CCPoint(cx, argv[1], &arr, &num); + ok &= jsval_to_ccarray_of_CCPoint(cx, args.get(1), &arr, &num); cocos2d::PointArray* arg1 = PointArray::create(num); for( int i=0; i < num;i++) { arg1->addControlPoint(arr[i]); } - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); + ok &= JS::ToNumber( cx, JS::RootedValue(cx, args.get(2)), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_CardinalSplineTo_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2); delete [] arr; jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3159,15 +3219,15 @@ bool JSB_CatmullRomTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccGLEnableVertexAttribs(JSContext *cx, uint32_t argc, jsval *vp) { bool ok = true; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 1) { unsigned int arg0; - ok &= jsval_to_uint32(cx, argv[0], &arg0); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GL::enableVertexAttribs(arg0); - JS_SET_RVAL(cx, vp, JSVAL_NULL); + args.rval().setUndefined(); return true; } @@ -3180,19 +3240,19 @@ bool js_cocos2dx_ccGLEnableVertexAttribs(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_ccpAdd(JSContext *cx, uint32_t argc, jsval *vp) { bool ok = true; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 2) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); cocos2d::Point arg1; - ok &= jsval_to_ccpoint(cx, argv[1], &arg1); + ok &= jsval_to_ccpoint(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); Point ret = arg0 + arg1; jsval jsret = ccpoint_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3203,19 +3263,19 @@ bool js_cocos2dx_ccpAdd(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpDistanceSQ(JSContext *cx, uint32_t argc, jsval *vp) { bool ok = true; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 2) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); cocos2d::Point arg1; - ok &= jsval_to_ccpoint(cx, argv[1], &arg1); + ok &= jsval_to_ccpoint(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); float ret = arg0.getDistanceSq(arg1); jsval jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3226,19 +3286,19 @@ bool js_cocos2dx_ccpDistanceSQ(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpDistance(JSContext *cx, uint32_t argc, jsval *vp) { bool ok = true; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 2) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); cocos2d::Point arg1; - ok &= jsval_to_ccpoint(cx, argv[1], &arg1); + ok &= jsval_to_ccpoint(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); float ret = arg0.getDistance(arg1); jsval jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3248,21 +3308,21 @@ bool js_cocos2dx_ccpDistance(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpClamp(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 3) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); cocos2d::Point arg1; - ok &= jsval_to_ccpoint(cx, argv[1], &arg1); + ok &= jsval_to_ccpoint(cx, args.get(1), &arg1); cocos2d::Point arg2; - ok &= jsval_to_ccpoint(cx, argv[2], &arg2); + ok &= jsval_to_ccpoint(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); Point ret = arg0.getClampPoint(arg1, arg2); jsval jsret = ccpoint_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3272,16 +3332,16 @@ bool js_cocos2dx_ccpClamp(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpLengthSQ(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); float ret = arg0.getLengthSq(); jsval jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3292,17 +3352,17 @@ bool js_cocos2dx_ccpLengthSQ(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpLength(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); float ret = arg0.getLength(); jsval jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3313,17 +3373,17 @@ bool js_cocos2dx_ccpLength(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpNeg(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); Point ret = -arg0; jsval jsret = ccpoint_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3334,19 +3394,19 @@ bool js_cocos2dx_ccpNeg(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpSub(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); cocos2d::Point arg1; - ok &= jsval_to_ccpoint(cx, argv[1], &arg1); + ok &= jsval_to_ccpoint(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); Point ret = arg0 - arg1; jsval jsret = ccpoint_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3357,21 +3417,21 @@ bool js_cocos2dx_ccpSub(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpMult(JSContext *cx, uint32_t argc, jsval *vp) { - JS::CallArgs argv = JS::CallArgsFromVp(argc, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); double arg1; - ok &= JS::ToNumber(cx, argv[1], &arg1); + ok &= JS::ToNumber(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); Point ret = arg0 * arg1; jsval jsret = ccpoint_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3382,19 +3442,19 @@ bool js_cocos2dx_ccpMult(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpMidpoint(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); cocos2d::Point arg1; - ok &= jsval_to_ccpoint(cx, argv[1], &arg1); + ok &= jsval_to_ccpoint(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); Point ret = arg0.getMidpoint(arg1); jsval jsret = ccpoint_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3406,19 +3466,19 @@ bool js_cocos2dx_ccpMidpoint(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpDot(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); cocos2d::Point arg1; - ok &= jsval_to_ccpoint(cx, argv[1], &arg1); + ok &= jsval_to_ccpoint(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); float ret = arg0.dot(arg1); jsval jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3429,19 +3489,19 @@ bool js_cocos2dx_ccpDot(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpCross(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); cocos2d::Point arg1; - ok &= jsval_to_ccpoint(cx, argv[1], &arg1); + ok &= jsval_to_ccpoint(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); float ret = arg0.cross(arg1); jsval jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3452,17 +3512,17 @@ bool js_cocos2dx_ccpCross(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpPerp(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); Point ret = arg0.getPerp(); jsval jsret = ccpoint_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3474,17 +3534,17 @@ bool js_cocos2dx_ccpPerp(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpRPerp(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); Point ret = arg0.getRPerp(); jsval jsret = ccpoint_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3496,19 +3556,19 @@ bool js_cocos2dx_ccpRPerp(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpProject(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); cocos2d::Point arg1; - ok &= jsval_to_ccpoint(cx, argv[1], &arg1); + ok &= jsval_to_ccpoint(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); Point ret = arg0.project(arg1); jsval jsret = ccpoint_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3519,19 +3579,19 @@ bool js_cocos2dx_ccpProject(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpRotate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 2) { cocos2d::Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); cocos2d::Point arg1; - ok &= jsval_to_ccpoint(cx, argv[1], &arg1); + ok &= jsval_to_ccpoint(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); Point ret = arg0.rotate(arg1); jsval jsret = ccpoint_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3542,17 +3602,17 @@ bool js_cocos2dx_ccpRotate(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_ccpNormalize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { cocos2d::Vec2 ret; - ok &= jsval_to_vector2(cx, argv[0], &ret); + ok &= jsval_to_vector2(cx, args.get(0), &ret); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); ret.normalize(); jsval jsret = ccpoint_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3561,42 +3621,220 @@ bool js_cocos2dx_ccpNormalize(JSContext *cx, uint32_t argc, jsval *vp) return false; } +bool js_cocos2dx_ccobbGetCorners(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if(argc == 1) + { + cocos2d::OBB obb; + bool ok = jsval_to_obb(cx, args.get(0), &obb); + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + + cocos2d::Vec3 verts[8]; + obb.getCorners(verts); + + JS::RootedObject array(cx, JS_NewArrayObject(cx, 8)); + for(int i = 0; i < 8; ++i) + { + JS::RootedValue vec(cx, vector3_to_jsval(cx, verts[i])); + ok &= JS_SetElement(cx, array, i, vec); + if(!ok) + break; + } + + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + args.rval().set(OBJECT_TO_JSVAL(array)); + return true; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} + +bool js_cocos2dx_ccobbIntersects(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if(argc == 2) + { + cocos2d::OBB obb1, obb2; + bool ok = jsval_to_obb(cx, args.get(0), &obb1); + ok &= jsval_to_obb(cx, args.get(1), &obb2); + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + + bool ret = obb1.intersects(obb2); + + args.rval().set(BOOLEAN_TO_JSVAL(ret)); + return true; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} + +bool js_cocos2dx_ccrayIntersectsObb(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if(argc == 2) + { + cocos2d::Ray ray; + cocos2d::OBB obb; + + bool ok = jsval_to_ray(cx, args.get(0), &ray); + ok &= jsval_to_obb(cx, args.get(1), &obb); + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + + bool ret = ray.intersects(obb); + + args.rval().set(BOOLEAN_TO_JSVAL(ret)); + return true; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} + +bool js_cocos2dx_ccmat4CreateTranslation(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if(argc == 1) + { + cocos2d::Vec3 arg0; + bool ok = jsval_to_vector3(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + + cocos2d::Mat4 ret; + cocos2d::Mat4::createTranslation(arg0, &ret); + jsval jsret = matrix_to_jsval(cx, ret); + + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} + +bool js_cocos2dx_ccmat4CreateRotation(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if(argc == 1) + { + cocos2d::Quaternion arg0; + bool ok = jsval_to_quaternion(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + + cocos2d::Mat4 ret; + cocos2d::Mat4::createRotation(arg0, &ret); + jsval jsret = matrix_to_jsval(cx, ret); + + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} + +bool js_cocos2dx_ccmat4Multiply(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if(argc == 2) + { + cocos2d::Mat4 arg0; + cocos2d::Mat4 arg1; + bool ok = jsval_to_matrix(cx, args.get(0), &arg0); + ok &= jsval_to_matrix(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + + cocos2d::Mat4 ret = arg0 * arg1; + jsval jsret = matrix_to_jsval(cx, ret); + + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} + +bool js_cocos2dx_ccmat4MultiplyVec3(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if(argc == 2) + { + cocos2d::Mat4 arg0; + cocos2d::Vec3 arg1; + bool ok = jsval_to_matrix(cx, args.get(0), &arg0); + ok &= jsval_to_vector3(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + + cocos2d::Vec3 ret = arg0 * arg1; + jsval jsret = vector3_to_jsval(cx, ret); + + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} + +bool js_cocos2dx_ccquatMultiply(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if(argc == 2) + { + cocos2d::Quaternion arg0; + cocos2d::Quaternion arg1; + bool ok = jsval_to_quaternion(cx, args.get(0), &arg0); + ok &= jsval_to_quaternion(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + + cocos2d::Quaternion ret = arg0 * arg1; + jsval jsret = quaternion_to_jsval(cx, ret); + + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} + bool js_cocos2dx_CCSprite_textureLoaded(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj; - Sprite* cobj; - obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cobj = (Sprite*)(proxy ? proxy->ptr : NULL); + Sprite* cobj = (Sprite*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, cobj); bool ret = false; if( cobj->getTexture() ) ret = true; - - JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret)); - + + args.rval().set(BOOLEAN_TO_JSVAL(ret)); return true; } bool js_cocos2dx_CCTexture2D_setTexParameters(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); Texture2D* cobj = (Texture2D*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, cobj) if (argc == 4) { - jsval *argvp = JS_ARGV(cx,vp); bool ok = true; GLuint arg0, arg1, arg2, arg3; - ok &= jsval_to_uint32(cx, *argvp++, &arg0); - ok &= jsval_to_uint32(cx, *argvp++, &arg1); - ok &= jsval_to_uint32(cx, *argvp++, &arg2); - ok &= jsval_to_uint32(cx, *argvp++, &arg3); + ok &= jsval_to_uint32(cx, args.get(0), &arg0); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + ok &= jsval_to_uint32(cx, args.get(3), &arg3); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); @@ -3604,7 +3842,7 @@ bool js_cocos2dx_CCTexture2D_setTexParameters(JSContext *cx, uint32_t argc, jsva cobj->setTexParameters(param); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3614,20 +3852,19 @@ bool js_cocos2dx_CCTexture2D_setTexParameters(JSContext *cx, uint32_t argc, jsva bool js_cocos2dx_CCMenu_alignItemsInRows(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject jsthis(cx, args.thisv().toObjectOrNull()); bool ok = true; js_proxy_t *proxy = jsb_get_js_proxy(jsthis); Menu* cobj = (Menu*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, cobj) - jsval *argvp = JS_ARGV(cx,vp); - ValueVector items; - ok &= jsvals_variadic_to_ccvaluevector(cx, argvp, argc, &items); + ok &= jsvals_variadic_to_ccvaluevector(cx, args.array(), argc, &items); if (ok) { cobj->alignItemsInRowsWithArray(items); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "Error in js_cocos2dx_CCMenu_alignItemsInRows"); @@ -3636,20 +3873,20 @@ bool js_cocos2dx_CCMenu_alignItemsInRows(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_CCMenu_alignItemsInColumns(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject jsthis(cx, args.thisv().toObjectOrNull()); bool ok = true; js_proxy_t *proxy = jsb_get_js_proxy(jsthis); Menu* cobj = (Menu*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, cobj) - jsval *argvp = JS_ARGV(cx,vp); ValueVector items; - ok &= jsvals_variadic_to_ccvaluevector(cx, argvp, argc, &items); + ok &= jsvals_variadic_to_ccvaluevector(cx, args.array(), argc, &items); if (ok) { cobj->alignItemsInColumnsWithArray(items); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "Error in js_cocos2dx_CCMenu_alignItemsInColumns"); @@ -3658,7 +3895,8 @@ bool js_cocos2dx_CCMenu_alignItemsInColumns(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_CCLayer_init(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::Layer* cobj = (cocos2d::Layer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_CCLayer_init : Invalid Native Object"); @@ -3666,7 +3904,7 @@ bool js_cocos2dx_CCLayer_init(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->init(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3678,7 +3916,7 @@ bool js_cocos2dx_CCLayer_init(JSContext *cx, uint32_t argc, jsval *vp) // TMXLayer bool js_cocos2dx_CCTMXLayer_getTileFlagsAt(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj; TMXLayer* cobj; @@ -3690,11 +3928,11 @@ bool js_cocos2dx_CCTMXLayer_getTileFlagsAt(JSContext *cx, uint32_t argc, jsval * { TMXTileFlags flags; Point arg0; - ok &= jsval_to_ccpoint(cx, argv[0], &arg0); + ok &= jsval_to_ccpoint(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->getTileGIDAt(arg0, &flags); - - JS_SET_RVAL(cx, vp, UINT_TO_JSVAL((uint32_t)flags)); + + args.rval().set(UINT_TO_JSVAL((uint32_t)flags)); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2); @@ -3707,13 +3945,14 @@ bool js_cocos2dx_CCTMXLayer_getTileFlagsAt(JSContext *cx, uint32_t argc, jsval * // Ret value: void bool js_cocos2dx_CCDrawNode_drawPolygon(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp); + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); DrawNode* cobj = (DrawNode*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, cobj) if ( argc == 4) { - JS::CallArgs argvp = JS::CallArgsFromVp(argc ,vp); bool ok = true; JS::RootedObject argArray(cx); Color4F argFillColor = Color4F(0.0f, 0.0f, 0.0f, 0.0f); @@ -3721,17 +3960,17 @@ bool js_cocos2dx_CCDrawNode_drawPolygon(JSContext *cx, uint32_t argc, jsval *vp) Color4F argBorderColor = Color4F(0.0f, 0.0f, 0.0f, 0.0f); // Points - ok &= JS_ValueToObject(cx, argvp[0], &argArray); + ok &= JS_ValueToObject(cx, args.get(0), &argArray); JSB_PRECONDITION2( (argArray && JS_IsArrayObject(cx, argArray)) , cx, false, "Vertex should be anArray object"); // Color 4F - ok &= jsval_to_cccolor4f(cx, argvp[1], &argFillColor); + ok &= jsval_to_cccolor4f(cx, args.get(1), &argFillColor); // Width - ok &= JS::ToNumber( cx, argvp[2], &argWidth ); + ok &= JS::ToNumber( cx, args.get(2), &argWidth ); // Color Border (4F) - ok &= jsval_to_cccolor4f(cx, argvp[3], &argBorderColor); + ok &= jsval_to_cccolor4f(cx, args.get(3), &argBorderColor); JSB_PRECONDITION2(ok, cx, false, "Error parsing arguments"); @@ -3756,7 +3995,7 @@ bool js_cocos2dx_CCDrawNode_drawPolygon(JSContext *cx, uint32_t argc, jsval *vp) cobj->drawPolygon(verts, l, argFillColor, argWidth, argBorderColor); CC_SAFE_DELETE_ARRAY(verts); } - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3777,9 +4016,9 @@ static bool jsval_to_string_vector(JSContext* cx, jsval v, std::vector& arr) { - JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0, NULL)); + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); int i = 0; for(std::vector::const_iterator iter = arr.begin(); iter != arr.end(); ++iter, ++i) { JS::RootedValue arrElement(cx, std_string_to_jsval(cx, *iter)); - if(!JS_SetElement(cx, jsretArr, i, &arrElement)) { + if(!JS_SetElement(cx, jsretArr, i, arrElement)) { break; } } @@ -3805,7 +4044,7 @@ static jsval string_vector_to_jsval(JSContext* cx, const std::vector arg0; - ok &= jsval_to_string_vector(cx, argv[0], arg0); + ok &= jsval_to_string_vector(cx, args.get(0), arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->setSearchResolutionsOrder(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); @@ -3826,7 +4065,7 @@ bool js_cocos2dx_CCFileUtils_setSearchResolutionsOrder(JSContext *cx, uint32_t a bool js_cocos2dx_CCFileUtils_setSearchPaths(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -3835,10 +4074,10 @@ bool js_cocos2dx_CCFileUtils_setSearchPaths(JSContext *cx, uint32_t argc, jsval if (argc == 1) { std::vector arg0; - ok &= jsval_to_string_vector(cx, argv[0], arg0); + ok &= jsval_to_string_vector(cx, args.get(0), arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->setSearchPaths(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); @@ -3846,7 +4085,8 @@ bool js_cocos2dx_CCFileUtils_setSearchPaths(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_CCFileUtils_getSearchPaths(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); @@ -3855,7 +4095,7 @@ bool js_cocos2dx_CCFileUtils_getSearchPaths(JSContext *cx, uint32_t argc, jsval std::vector ret = cobj->getSearchPaths(); jsval jsret; jsret = string_vector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); @@ -3864,7 +4104,7 @@ bool js_cocos2dx_CCFileUtils_getSearchPaths(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_CCFileUtils_getDataFromFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -3873,7 +4113,7 @@ bool js_cocos2dx_CCFileUtils_getDataFromFile(JSContext *cx, uint32_t argc, jsval if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); Data data = cobj->getDataFromFile(arg0); @@ -3888,8 +4128,8 @@ bool js_cocos2dx_CCFileUtils_getDataFromFile(JSContext *cx, uint32_t argc, jsval uint8_t* bufdata = (uint8_t*)JS_GetArrayBufferViewData(array); memcpy(bufdata, data.getBytes(), size*sizeof(uint8_t)); - - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(array)); + + args.rval().set(OBJECT_TO_JSVAL(array)); return true; } } while(false); @@ -3903,6 +4143,7 @@ bool js_cocos2dx_CCFileUtils_getDataFromFile(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_CCFileUtils_getSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); @@ -3912,7 +4153,7 @@ bool js_cocos2dx_CCFileUtils_getSearchResolutionsOrder(JSContext *cx, uint32_t a std::vector ret = cobj->getSearchResolutionsOrder(); jsval jsret; jsret = string_vector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); @@ -3921,7 +4162,7 @@ bool js_cocos2dx_CCFileUtils_getSearchResolutionsOrder(JSContext *cx, uint32_t a static bool js_cocos2dx_FileUtils_createDictionaryWithContentsOfFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -3929,12 +4170,12 @@ static bool js_cocos2dx_FileUtils_createDictionaryWithContentsOfFile(JSContext * JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cocos2d::ValueMap ret = FileUtils::getInstance()->getValueMapFromFile(arg0.c_str()); jsval jsret; jsret = ccvaluemap_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3944,7 +4185,7 @@ static bool js_cocos2dx_FileUtils_createDictionaryWithContentsOfFile(JSContext * bool js_cocos2dx_CCGLProgram_setUniformLocationWith4f(JSContext *cx, uint32_t argc, jsval *vp) { - JS::CallArgs argv = JS::CallArgsFromVp(argc, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -3955,33 +4196,33 @@ bool js_cocos2dx_CCGLProgram_setUniformLocationWith4f(JSContext *cx, uint32_t ar double arg2; double arg3; double arg4; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - ok &= JS::ToNumber(cx, argv[1], &arg1); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + ok &= JS::ToNumber(cx, args.get(1), &arg1); if(argc == 2) { JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->setUniformLocationWith1f(arg0, arg1); } if (argc == 3) { - ok &= JS::ToNumber(cx, argv[2], &arg2); + ok &= JS::ToNumber(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->setUniformLocationWith2f(arg0, arg1, arg2); } if(argc == 4) { - ok &= JS::ToNumber(cx, argv[2], &arg2); - ok &= JS::ToNumber(cx, argv[3], &arg3); + ok &= JS::ToNumber(cx, args.get(2), &arg2); + ok &= JS::ToNumber(cx, args.get(3), &arg3); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->setUniformLocationWith3f(arg0, arg1, arg2, arg3); } if(argc == 5) { - ok &= JS::ToNumber(cx, argv[2], &arg2); - ok &= JS::ToNumber(cx, argv[3], &arg3); - ok &= JS::ToNumber(cx, argv[4], &arg4); + ok &= JS::ToNumber(cx, args.get(2), &arg2); + ok &= JS::ToNumber(cx, args.get(3), &arg3); + ok &= JS::ToNumber(cx, args.get(4), &arg4); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->setUniformLocationWith4f(arg0, arg1, arg2, arg3, arg4); } - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 5); return false; @@ -3989,7 +4230,7 @@ bool js_cocos2dx_CCGLProgram_setUniformLocationWith4f(JSContext *cx, uint32_t ar bool js_cocos2dx_CCGLProgram_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if(argc != 2) { JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2); @@ -3997,8 +4238,8 @@ bool js_cocos2dx_CCGLProgram_create(JSContext *cx, uint32_t argc, jsval *vp) } const char *arg0, *arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); GLProgram* ret = new GLProgram(); ret->autorelease(); @@ -4020,7 +4261,7 @@ bool js_cocos2dx_CCGLProgram_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4028,7 +4269,7 @@ bool js_cocos2dx_CCGLProgram_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCGLProgram_createWithString(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if(argc != 2) { JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2); @@ -4036,8 +4277,8 @@ bool js_cocos2dx_CCGLProgram_createWithString(JSContext *cx, uint32_t argc, jsva } const char *arg0, *arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); GLProgram* ret = new GLProgram(); ret->initWithByteArrays(arg0, arg1); @@ -4057,20 +4298,21 @@ bool js_cocos2dx_CCGLProgram_createWithString(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } bool js_cocos2dx_CCGLProgram_getProgram(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::GLProgram* cobj = (cocos2d::GLProgram *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 0) { GLuint ret = cobj->getProgram(); - JS_SET_RVAL(cx, vp, UINT_TO_JSVAL((uint32_t)ret)); + args.rval().set(UINT_TO_JSVAL((uint32_t)ret)); return true; } @@ -4078,6 +4320,80 @@ bool js_cocos2dx_CCGLProgram_getProgram(JSContext *cx, uint32_t argc, jsval *vp) return false; } +bool js_cocos2dx_GLProgramState_setVertexAttribPointer(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::GLProgramState* cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_setVertexAttribPointer : Invalid Native Object"); + if (argc == 6) { + std::string arg0; + int arg1; + unsigned int arg2; + uint16_t arg3; + int arg4; + long arg5; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + ok &= jsval_to_uint16(cx, args.get(3), &arg3); + ok &= jsval_to_int32(cx, args.get(4), (int32_t *)&arg4); + ok &= jsval_to_long(cx, args.get(5), &arg5); + + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_GLProgramState_setVertexAttribPointer : Error processing arguments"); + cobj->setVertexAttribPointer(arg0, arg1, arg2, arg3, arg4, (GLvoid*)arg5); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_GLProgramState_setVertexAttribPointer : wrong number of arguments: %d, was expecting %d", argc, 6); + return false; +} + +bool js_cocos2dx_GLProgramState_setUniformVec4(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t* proxy = jsb_get_js_proxy(obj); + cocos2d::GLProgramState* cobj = (cocos2d::GLProgramState *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_GLProgramState_setUniformVec4 : Invalid Native Object"); + bool ok = true; + if(argc == 2) + { + do { + if (argc == 2) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::Vec4 arg1; + ok &= jsval_to_vector4(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cobj->setUniformVec4(arg0, arg1); + args.rval().setUndefined(); + return true; + } + } while(0); + + do { + if (argc == 2) { + int arg0; + ok &= jsval_to_int(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cocos2d::Vec4 arg1; + ok &= jsval_to_vector4(cx, args.get(1), &arg1); + if (!ok) { ok = true; break; } + cobj->setUniformVec4(arg0, arg1); + args.rval().setUndefined(); + return true; + } + } while(0); + } + JS_ReportError(cx, "js_cocos2dx_GLProgramState_setUniformVec4 : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} + #define js_cocos2dx_CCCamera_getXYZ(funcName) \ bool ok = true; \ JSObject *obj = JS_THIS_OBJECT(cx, vp); \ @@ -4116,6 +4432,7 @@ bool js_cocos2dx_CCGLProgram_getProgram(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_SpriteBatchNode_getDescendants(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); @@ -4123,16 +4440,16 @@ bool js_cocos2dx_SpriteBatchNode_getDescendants(JSContext *cx, uint32_t argc, js if (argc == 0) { std::vector ret = cobj->getDescendants(); - JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0, NULL)); + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); size_t vSize = ret.size(); JS::RootedValue jsret(cx); for (size_t i = 0; i < vSize; i++) { proxy = js_get_or_create_proxy(cx, ret[i]); jsret = OBJECT_TO_JSVAL(proxy->obj); - JS_SetElement(cx, jsretArr, static_cast(i), &jsret); + JS_SetElement(cx, jsretArr, static_cast(i), jsret); } - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsretArr)); + args.rval().set(OBJECT_TO_JSVAL(jsretArr)); return true; } @@ -4142,7 +4459,7 @@ bool js_cocos2dx_SpriteBatchNode_getDescendants(JSContext *cx, uint32_t argc, js bool js_cocos2dx_NodeGrid_setGrid(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -4151,16 +4468,16 @@ bool js_cocos2dx_NodeGrid_setGrid(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1) { cocos2d::GridBase* arg0; do { - if(argv[0].isNull()) { arg0 = nullptr; break;} - if (!argv[0].isObject()) { ok = false; break; } - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + if(args.get(0).isNull()) { arg0 = nullptr; break;} + if (!args.get(0).isObject()) { ok = false; break; } + JSObject *tmpObj = args.get(0).toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::GridBase*)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_NodeGrid_setGrid : Error processing arguments"); cobj->setGrid(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4169,7 +4486,9 @@ bool js_cocos2dx_NodeGrid_setGrid(JSContext *cx, uint32_t argc, jsval *vp) } // cc.PlistParser.getInstance() -bool js_PlistParser_getInstance(JSContext *cx, unsigned argc, JS::Value *vp) { +bool js_PlistParser_getInstance(JSContext *cx, unsigned argc, JS::Value *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); __JSPlistDelegator* delegator = __JSPlistDelegator::getInstance(); SAXParser* parser = delegator->getParser(); @@ -4186,7 +4505,7 @@ bool js_PlistParser_getInstance(JSContext *cx, unsigned argc, JS::Value *vp) { } else { jsret = JSVAL_NULL; } - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4195,22 +4514,27 @@ bool js_PlistParser_parse(JSContext *cx, unsigned argc, JS::Value *vp) { __JSPlistDelegator* delegator = __JSPlistDelegator::getInstance(); bool ok = true; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); std::string parsedStr = delegator->parseText(arg0); + std::replace(parsedStr.begin(), parsedStr.end(), '\n', ' '); + jsval strVal = std_string_to_jsval(cx, parsedStr); // create a new js obj of the parsed string JS::RootedValue outVal(cx); - ok = JS_ParseJSON(cx, JS_GetStringCharsZ(cx, JSVAL_TO_STRING(strVal)), static_cast(JS_GetStringLength(JSVAL_TO_STRING(strVal))), &outVal); + + //JS_GetStringCharsZ was removed in SpiderMonkey 33 + //ok = JS_ParseJSON(cx, JS_GetStringCharsZ(cx, strVal), static_cast(JS_GetStringEncodingLength(JSVAL_TO_STRING(strVal))), &outVal); + ok = JS_ParseJSON(cx, JS::RootedString(cx, strVal.toString()), &outVal); if (ok) - JS_SET_RVAL(cx, vp, outVal); + args.rval().set(outVal); else { - JS_SET_RVAL(cx, vp, JSVAL_NULL); + args.rval().setUndefined(); JS_ReportError(cx, "js_PlistParser_parse : parse error"); } return true; @@ -4310,21 +4634,24 @@ bool jsval_to_TTFConfig(JSContext *cx, jsval v, TTFConfig* ret) { JS::RootedObject tmp(cx); JS::RootedValue js_fontFilePath(cx); JS::RootedValue js_fontSize(cx); + JS::RootedValue js_outlineSize(cx); JS::RootedValue js_glyphs(cx); JS::RootedValue js_customGlyphs(cx); JS::RootedValue js_distanceFieldEnable(cx); std::string fontFilePath,customGlyphs; - double fontSize, glyphs; + double fontSize, glyphs, outlineSize; bool ok = v.isObject() && JS_ValueToObject(cx, JS::RootedValue(cx, v), &tmp) && JS_GetProperty(cx, tmp, "fontFilePath", &js_fontFilePath) && JS_GetProperty(cx, tmp, "fontSize", &js_fontSize) && + JS_GetProperty(cx, tmp, "outlineSize", &js_outlineSize) && JS_GetProperty(cx, tmp, "glyphs", &js_glyphs) && JS_GetProperty(cx, tmp, "customGlyphs", &js_customGlyphs) && JS_GetProperty(cx, tmp, "distanceFieldEnable", &js_distanceFieldEnable) && JS::ToNumber(cx, js_fontSize, &fontSize) && + JS::ToNumber(cx, js_outlineSize, &outlineSize) && JS::ToNumber(cx, js_glyphs, &glyphs) && jsval_to_std_string(cx,js_fontFilePath,&ret->fontFilePath) && jsval_to_std_string(cx,js_customGlyphs,&customGlyphs); @@ -4333,6 +4660,7 @@ bool jsval_to_TTFConfig(JSContext *cx, jsval v, TTFConfig* ret) { JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); ret->fontSize = (int)fontSize; + ret->outlineSize = (int)outlineSize; ret->glyphs = GlyphCollection((int)glyphs); ret->distanceFieldEnabled = distanceFieldEnable; if(ret->glyphs == GlyphCollection::CUSTOM && customGlyphs.length() > 0) @@ -4348,14 +4676,14 @@ bool js_cocos2dx_Label_createWithTTF(JSContext *cx, uint32_t argc, jsval *vp) if (argc < 2) return false; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; TTFConfig ttfConfig(""); std::string text; - ok &= jsval_to_TTFConfig(cx, argv[0], &ttfConfig); - ok &= jsval_to_std_string(cx, argv[1], &text); + ok &= jsval_to_TTFConfig(cx, args.get(0), &ttfConfig); + ok &= jsval_to_std_string(cx, args.get(1), &text); cocos2d::Label* ret = nullptr; @@ -4367,12 +4695,12 @@ bool js_cocos2dx_Label_createWithTTF(JSContext *cx, uint32_t argc, jsval *vp) js_proxy_t *proxy = js_get_or_create_proxy(cx, (cocos2d::Label*)ret); jsret = OBJECT_TO_JSVAL(proxy->obj); } - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 3) { int arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_createWithTTF : Error processing arguments"); TextHAlignment alignment = TextHAlignment(arg2); ret = cocos2d::Label::createWithTTF(ttfConfig, text, alignment); @@ -4381,13 +4709,13 @@ bool js_cocos2dx_Label_createWithTTF(JSContext *cx, uint32_t argc, jsval *vp) js_proxy_t *proxy = js_get_or_create_proxy(cx, (cocos2d::Label*)ret); jsret = OBJECT_TO_JSVAL(proxy->obj); } - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 4) { int arg2,arg3; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); - ok &= jsval_to_int32(cx, argv[3], (int32_t *)&arg3); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(3), (int32_t *)&arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_createWithTTF : Error processing arguments"); TextHAlignment alignment = TextHAlignment(arg2); ret = cocos2d::Label::createWithTTF(ttfConfig, text, alignment, arg3); @@ -4396,7 +4724,7 @@ bool js_cocos2dx_Label_createWithTTF(JSContext *cx, uint32_t argc, jsval *vp) js_proxy_t *proxy = js_get_or_create_proxy(cx, (cocos2d::Label*)ret); jsret = OBJECT_TO_JSVAL(proxy->obj); } - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4406,7 +4734,7 @@ bool js_cocos2dx_Label_createWithTTF(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_Label_setTTFConfig(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -4416,12 +4744,12 @@ bool js_cocos2dx_Label_setTTFConfig(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1) { TTFConfig ttfConfig(""); do { - if (!argv[0].isObject()) { ok = false; break; } - ok &= jsval_to_TTFConfig(cx, argv[0], &ttfConfig); + if (!args.get(0).isObject()) { ok = false; break; } + ok &= jsval_to_TTFConfig(cx, args.get(0), &ttfConfig); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Label_setTTFConfig : Error processing arguments"); cobj->setTTFConfig(ttfConfig); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4431,7 +4759,7 @@ bool js_cocos2dx_Label_setTTFConfig(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = NULL; @@ -4443,15 +4771,15 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Image::Format arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } bool ret = cobj->saveToFile(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -4459,17 +4787,17 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Image::Format arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(JS::RootedValue(cx, args.get(2))); bool ret = cobj->saveToFile(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -4477,16 +4805,16 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v do { if (argc == 4) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cocos2d::Image::Format arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + arg2 = JS::ToBoolean(JS::RootedValue(cx, args.get(2))); std::function &)> arg3; do { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[3])); + std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), args.get(3))); auto lambda = [=](cocos2d::RenderTexture* larg0, const std::string& larg1) -> void { jsval largv[2]; do { @@ -4500,8 +4828,8 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v do { largv[1] = std_string_to_jsval(cx, larg1); } while (0); - jsval rval; - bool ok = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(2, largv, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -4513,7 +4841,7 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v bool ret = cobj->saveToFile(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -4521,12 +4849,12 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } bool ret = cobj->saveToFile(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -4534,14 +4862,14 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } bool arg1; - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(JS::RootedValue(cx, args.get(1))); bool ret = cobj->saveToFile(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -4549,13 +4877,13 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } bool arg1; - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(JS::RootedValue(cx, args.get(1))); std::function &)> arg2; do { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[2])); + std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), args.get(2))); auto lambda = [=](cocos2d::RenderTexture* larg0, const std::string& larg1) -> void { jsval largv[2]; do { @@ -4569,8 +4897,8 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v do { largv[1] = std_string_to_jsval(cx, larg1); } while (0); - jsval rval; - bool ok = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(2, largv, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -4582,7 +4910,7 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v bool ret = cobj->saveToFile(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -4591,17 +4919,264 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v return false; } +bool js_cocos2dx_Camera_unproject(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_unproject : Invalid Native Object"); + if (argc == 2) { + cocos2d::Size arg0; + cocos2d::Vec3 arg1; + cocos2d::Vec3 arg2; + ok &= jsval_to_ccsize(cx, args.get(0), &arg0); + ok &= jsval_to_vector3(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_unproject : Error processing arguments"); + cobj->unproject(arg0, &arg1, &arg2); + args.rval().set(vector3_to_jsval(cx, arg2)); + return true; + } + else if (argc == 1) + { + cocos2d::Vec3 arg0; + ok &= jsval_to_vector3(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_unproject : Error processing arguments"); + cocos2d::Vec3 ret = cobj->unproject(arg0); + args.rval().set(vector3_to_jsval(cx, ret)); + return true; + } + JS_ReportError(cx, "js_cocos2dx_Camera_unproject : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} + +bool js_cocos2dx_Camera_isVisibleInFrustum(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_isVisibleInFrustum : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vec3 min; + JS::RootedValue jsmin(cx); + ok &= JS_GetProperty(cx, JS::RootedObject(cx, args.get(0).toObjectOrNull()), "min", &jsmin); + ok &= jsval_to_vector3(cx, jsmin, &min); + + cocos2d::Vec3 max; + JS::RootedValue jsmax(cx); + ok &= JS_GetProperty(cx, JS::RootedObject(cx, args.get(0).toObjectOrNull()), "max", &jsmax); + ok &= jsval_to_vector3(cx, jsmax, &max); + + cocos2d::AABB aabb(min, max); + + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_isVisibleInFrustum : Error processing arguments"); + bool ret = cobj->isVisibleInFrustum(&aabb); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Camera_isVisibleInFrustum : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} + +bool js_cocos2dx_Node_setAdditionalTransform(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + JS::RootedObject obj(cx); + cocos2d::Node* cobj = NULL; + obj = args.thisv().toObjectOrNull(); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_setAdditionalTransform : Invalid Native Object"); + + do { + if (argc == 1) { + cocos2d::Mat4 arg0; + ok &= jsval_to_matrix(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cobj->setAdditionalTransform(&arg0); + args.rval().setUndefined(); + return true; + } + } while(0); + + do { + if (argc == 1) { + cocos2d::AffineTransform arg0; + ok &= jsval_to_ccaffinetransform(cx, args.get(0), &arg0); + if (!ok) { ok = true; break; } + cobj->setAdditionalTransform(arg0); + args.rval().setUndefined(); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_Node_setAdditionalTransform : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_ClippingNode_init(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ClippingNode* cobj = (cocos2d::ClippingNode *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ClippingNode_init : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->init(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + if (argc == 1) { + cocos2d::Node* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ClippingNode_init : Error processing arguments"); + bool ret = cobj->init(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ClippingNode_init : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} + +// EventKeyboard class bindings, need manual bind for transform key codes + +JSClass *jsb_cocos2d_EventKeyboard_class; +JSObject *jsb_cocos2d_EventKeyboard_prototype; + +bool js_cocos2dx_EventKeyboard_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + + cocos2d::EventKeyboard::KeyCode arg0; + ScriptingCore *core = ScriptingCore::getInstance(); + JS::RootedValue retVal(cx); + core->executeFunctionWithOwner(OBJECT_TO_JSVAL(core->getGlobalObject()), "parseKeyCode", args, &retVal); + ok &= jsval_to_int32(cx, retVal, (int32_t *)&arg0); + + bool arg1; + arg1 = JS::ToBoolean(JS::RootedValue(cx, args.get(1))); + + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventKeyboard_constructor : Error processing arguments"); + + cocos2d::EventKeyboard* cobj = new (std::nothrow) cocos2d::EventKeyboard(arg0, arg1); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + JSObject *obj = JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); + args.rval().set( OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + JS::AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventKeyboard"); + return true; +} + + +extern JSObject *jsb_cocos2d_Event_prototype; + +void js_cocos2d_EventKeyboard_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (EventKeyboard)", obj); +} + +static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().set(BOOLEAN_TO_JSVAL(true)); + return true; +} + +void js_register_cocos2dx_EventKeyboard(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_EventKeyboard_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_EventKeyboard_class->name = "EventKeyboard"; + jsb_cocos2d_EventKeyboard_class->addProperty = JS_PropertyStub; + jsb_cocos2d_EventKeyboard_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_EventKeyboard_class->getProperty = JS_PropertyStub; + jsb_cocos2d_EventKeyboard_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_EventKeyboard_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_EventKeyboard_class->resolve = JS_ResolveStub; + jsb_cocos2d_EventKeyboard_class->convert = JS_ConvertStub; + jsb_cocos2d_EventKeyboard_class->finalize = js_cocos2d_EventKeyboard_finalize; + jsb_cocos2d_EventKeyboard_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FS_END + }; + + JSFunctionSpec *st_funcs = NULL; + + jsb_cocos2d_EventKeyboard_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_Event_prototype), + jsb_cocos2d_EventKeyboard_class, + js_cocos2dx_EventKeyboard_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace + // bool found; + //FIXME: Removed in Firefox v27 + // JS_SetPropertyAttributes(cx, global, "EventKeyboard", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_EventKeyboard_class; + p->proto = jsb_cocos2d_EventKeyboard_prototype; + p->parentProto = jsb_cocos2d_Event_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + // console.log("Message"); bool js_console_log(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 1) { std::string msg; - bool ok = jsval_to_std_string(cx, argv[0], &msg); + bool ok = jsval_to_std_string(cx, args.get(0), &msg); JSB_PRECONDITION2(ok, cx, false, "js_console_log : Error processing arguments"); log("%s", msg.c_str()); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4609,206 +5184,270 @@ bool js_console_log(JSContext *cx, uint32_t argc, jsval *vp) return false; } -void create_js_root_obj(JSContext* cx, JSObject* global, const std::string &name, JS::RootedObject *jsObj) +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, global, name.c_str(), &nsval); + JS_GetProperty(cx, obj, name.c_str(), &nsval); if (nsval == JSVAL_VOID) { - *jsObj = JS_NewObject(cx, NULL, NULL, NULL); - nsval = OBJECT_TO_JSVAL(*jsObj); - JS_SetProperty(cx, global, name.c_str(), nsval); + jsObj.set(JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); + nsval = OBJECT_TO_JSVAL(jsObj); + JS_SetProperty(cx, obj, name.c_str(), nsval); } else { - JS_ValueToObject(cx, nsval, jsObj); + jsObj.set(nsval.toObjectOrNull()); } } -void register_cocos2dx_js_core(JSContext* cx, JSObject* global) +void register_cocos2dx_js_core(JSContext* cx, JS::HandleObject global) { JS::RootedObject ccObj(cx); - create_js_root_obj(cx, global, "cc", &ccObj); - - JSObject *tmpObj; - - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.PlistParser; })()")); + JS::RootedValue tmpVal(cx); + JS::RootedObject tmpObj(cx); + get_or_create_js_obj(cx, global, "cc", &ccObj); + + JS_GetProperty(cx, ccObj, "PlistParser", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "getInstance", js_PlistParser_getInstance, 0, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.PlistParser.getInstance(); })()")); - JS_DefineFunction(cx, tmpObj, "parse", js_PlistParser_parse, 1, JSPROP_READONLY | JSPROP_PERMANENT); - -} -void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global) -{ - JS::RootedObject ccObj(cx); - create_js_root_obj(cx, global, "cc", &ccObj); - - JSObject *tmpObj; - JS_DefineFunction(cx, jsb_cocos2d_Label_prototype, "createWithTTF", js_cocos2dx_Label_createWithTTF, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Label_prototype, "setTTFConfig", js_cocos2dx_Label_setTTFConfig, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_NodeGrid_prototype, "setGrid", js_cocos2dx_NodeGrid_setGrid, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_EventListener_prototype, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_EventListener_prototype, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_Touch_prototype, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Touch_prototype, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_EventTouch_prototype, "getTouches", js_cocos2dx_EventTouch_getTouches, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_EventTouch_prototype, "setTouches", js_cocos2dx_EventTouch_setTouches, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_GLProgram_prototype, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_GLProgram_prototype, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "onEnter", js_cocos2dx_Node_onEnter, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "onExit", js_cocos2dx_Node_onExit, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "onEnterTransitionDidFinish", js_cocos2dx_Node_onEnterTransitionDidFinish, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "onExitTransitionDidStart", js_cocos2dx_Node_onExitTransitionDidStart, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "init", js_doNothing, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "schedule", js_CCNode_schedule, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "scheduleOnce", js_CCNode_scheduleOnce, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "scheduleUpdateWithPriority", js_cocos2dx_CCNode_scheduleUpdateWithPriority, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "unscheduleUpdate", js_cocos2dx_CCNode_unscheduleUpdate, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "scheduleUpdate", js_cocos2dx_CCNode_scheduleUpdate, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "unschedule", js_CCNode_unschedule, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "unscheduleAllCallbacks", js_cocos2dx_CCNode_unscheduleAllSelectors, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "setPosition", js_cocos2dx_CCNode_setPosition, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "setContentSize", js_cocos2dx_CCNode_setContentSize, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "setAnchorPoint", js_cocos2dx_CCNode_setAnchorPoint, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "setColor", js_cocos2dx_CCNode_setColor, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "pause", js_cocos2dx_CCNode_pause, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "resume", js_cocos2dx_CCNode_resume, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_Component_prototype, "onEnter", js_cocos2dx_Component_onEnter, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Component_prototype, "onExit", js_cocos2dx_Component_onExit, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_GLProgram_prototype, "setUniformLocationF32", js_cocos2dx_CCGLProgram_setUniformLocationWith4f, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_GLProgram_prototype, "getProgram", js_cocos2dx_CCGLProgram_getProgram, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_Scheduler_prototype, "resumeTarget", js_cocos2dx_CCScheduler_resumeTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Scheduler_prototype, "pauseTarget", js_cocos2dx_CCScheduler_pauseTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Scheduler_prototype, "scheduleUpdateForTarget", js_CCScheduler_scheduleUpdateForTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Scheduler_prototype, "unscheduleUpdateForTarget", js_CCScheduler_unscheduleUpdateForTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Scheduler_prototype, "scheduleCallbackForTarget", js_CCScheduler_schedule, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Scheduler_prototype, "unscheduleCallbackForTarget", js_CCScheduler_unscheduleCallbackForTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Scheduler_prototype, "unscheduleAllCallbacksForTarget", js_cocos2dx_CCScheduler_unscheduleAllSelectorsForTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Scheduler_prototype, "unscheduleAllCallbacks", js_cocos2dx_CCScheduler_unscheduleAll, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Scheduler_prototype, "unscheduleAllCallbacksWithMinPriority", js_cocos2dx_CCScheduler_unscheduleAllCallbacksWithMinPriority, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Scheduler_prototype, "isTargetPaused", js_cocos2dx_CCScheduler_isTargetPaused, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_TMXLayer_prototype, "getTileFlagsAt", js_cocos2dx_CCTMXLayer_getTileFlagsAt, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_DrawNode_prototype, "drawPoly", js_cocos2dx_CCDrawNode_drawPolygon, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_Texture2D_prototype, "setTexParameters", js_cocos2dx_CCTexture2D_setTexParameters, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Menu_prototype, "alignItemsInRows", js_cocos2dx_CCMenu_alignItemsInRows, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Menu_prototype, "alignItemsInColumns", js_cocos2dx_CCMenu_alignItemsInColumns, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_Layer_prototype, "init", js_cocos2dx_CCLayer_init, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_FileUtils_prototype, "setSearchResolutionsOrder", js_cocos2dx_CCFileUtils_setSearchResolutionsOrder, 1, JSPROP_PERMANENT ); - JS_DefineFunction(cx, jsb_cocos2d_FileUtils_prototype, "setSearchPaths", js_cocos2dx_CCFileUtils_setSearchPaths, 1, JSPROP_PERMANENT ); - JS_DefineFunction(cx, jsb_cocos2d_FileUtils_prototype, "getSearchPaths", js_cocos2dx_CCFileUtils_getSearchPaths, 0, JSPROP_PERMANENT ); - JS_DefineFunction(cx, jsb_cocos2d_FileUtils_prototype, "getSearchResolutionsOrder", js_cocos2dx_CCFileUtils_getSearchResolutionsOrder, 0, JSPROP_PERMANENT ); - - JS_DefineFunction(cx, jsb_cocos2d_FileUtils_prototype, "createDictionaryWithContentsOfFile", js_cocos2dx_FileUtils_createDictionaryWithContentsOfFile, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_FileUtils_prototype, "getDataFromFile", js_cocos2dx_CCFileUtils_getDataFromFile, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.EventListenerTouchOneByOne; })()")); + JS::RootedObject proto(cx, jsb_cocos2d_SAXParser_prototype); + JS_DefineFunction(cx, proto, "parse", js_PlistParser_parse, 1, JSPROP_READONLY | JSPROP_PERMANENT); + + JS_GetProperty(cx, ccObj, "Label", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); + JS_DefineFunction(cx, tmpObj, "createWithTTF", js_cocos2dx_Label_createWithTTF, 4, JSPROP_READONLY | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_Label_prototype); + JS_DefineFunction(cx, tmpObj, "setTTFConfig", js_cocos2dx_Label_setTTFConfig, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_NodeGrid_prototype); + JS_DefineFunction(cx, tmpObj, "setGrid", js_cocos2dx_NodeGrid_setGrid, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_Node_prototype); + JS_DefineFunction(cx, tmpObj, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "onEnter", js_cocos2dx_Node_onEnter, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "onExit", js_cocos2dx_Node_onExit, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "onEnterTransitionDidFinish", js_cocos2dx_Node_onEnterTransitionDidFinish, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "onExitTransitionDidStart", js_cocos2dx_Node_onExitTransitionDidStart, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "schedule", js_CCNode_schedule, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "scheduleOnce", js_CCNode_scheduleOnce, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "scheduleUpdateWithPriority", js_cocos2dx_CCNode_scheduleUpdateWithPriority, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "unscheduleUpdate", js_cocos2dx_CCNode_unscheduleUpdate, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "scheduleUpdate", js_cocos2dx_CCNode_scheduleUpdate, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "unschedule", js_CCNode_unschedule, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "unscheduleAllCallbacks", js_cocos2dx_CCNode_unscheduleAllSelectors, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "setPosition", js_cocos2dx_CCNode_setPosition, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "setContentSize", js_cocos2dx_CCNode_setContentSize, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "setAnchorPoint", js_cocos2dx_CCNode_setAnchorPoint, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "setColor", js_cocos2dx_CCNode_setColor, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "pause", js_cocos2dx_CCNode_pause, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "resume", js_cocos2dx_CCNode_resume, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "setAdditionalTransform", js_cocos2dx_Node_setAdditionalTransform, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_EventListener_prototype); + JS_DefineFunction(cx, tmpObj, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_Touch_prototype); + JS_DefineFunction(cx, tmpObj, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_EventTouch_prototype); + JS_DefineFunction(cx, tmpObj, "getTouches", js_cocos2dx_EventTouch_getTouches, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "setTouches", js_cocos2dx_EventTouch_setTouches, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_GLProgram_prototype); + JS_DefineFunction(cx, tmpObj, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "setUniformLocationF32", js_cocos2dx_CCGLProgram_setUniformLocationWith4f, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "getProgram", js_cocos2dx_CCGLProgram_getProgram, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_GLProgramState_prototype); + JS_DefineFunction(cx, tmpObj, "setVertexAttribPointer", js_cocos2dx_GLProgramState_setVertexAttribPointer, 6, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "setUniformVec4", js_cocos2dx_GLProgramState_setUniformVec4, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_Component_prototype); + JS_DefineFunction(cx, tmpObj, "onEnter", js_cocos2dx_Component_onEnter, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "onExit", js_cocos2dx_Component_onExit, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_Scheduler_prototype); + JS_DefineFunction(cx, tmpObj, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "resumeTarget", js_cocos2dx_CCScheduler_resumeTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "pauseTarget", js_cocos2dx_CCScheduler_pauseTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "scheduleUpdateForTarget", js_CCScheduler_scheduleUpdateForTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "unscheduleUpdateForTarget", js_CCScheduler_unscheduleUpdateForTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "scheduleCallbackForTarget", js_CCScheduler_schedule, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "unscheduleCallbackForTarget", js_CCScheduler_unscheduleCallbackForTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "unscheduleAllCallbacksForTarget", js_cocos2dx_CCScheduler_unscheduleAllSelectorsForTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "unscheduleAllCallbacks", js_cocos2dx_CCScheduler_unscheduleAll, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "unscheduleAllCallbacksWithMinPriority", js_cocos2dx_CCScheduler_unscheduleAllCallbacksWithMinPriority, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "isTargetPaused", js_cocos2dx_CCScheduler_isTargetPaused, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_ActionManager_prototype); + JS_DefineFunction(cx, tmpObj, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_TMXLayer_prototype); + JS_DefineFunction(cx, tmpObj, "getTileFlagsAt", js_cocos2dx_CCTMXLayer_getTileFlagsAt, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_DrawNode_prototype); + JS_DefineFunction(cx, tmpObj, "drawPoly", js_cocos2dx_CCDrawNode_drawPolygon, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_Texture2D_prototype); + JS_DefineFunction(cx, tmpObj, "setTexParameters", js_cocos2dx_CCTexture2D_setTexParameters, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_Menu_prototype); + JS_DefineFunction(cx, tmpObj, "alignItemsInRows", js_cocos2dx_CCMenu_alignItemsInRows, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "alignItemsInColumns", js_cocos2dx_CCMenu_alignItemsInColumns, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_Layer_prototype); + JS_DefineFunction(cx, tmpObj, "init", js_cocos2dx_CCLayer_init, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_FileUtils_prototype); + JS_DefineFunction(cx, tmpObj, "setSearchResolutionsOrder", js_cocos2dx_CCFileUtils_setSearchResolutionsOrder, 1, JSPROP_PERMANENT ); + JS_DefineFunction(cx, tmpObj, "setSearchPaths", js_cocos2dx_CCFileUtils_setSearchPaths, 1, JSPROP_PERMANENT ); + JS_DefineFunction(cx, tmpObj, "getSearchPaths", js_cocos2dx_CCFileUtils_getSearchPaths, 0, JSPROP_PERMANENT ); + JS_DefineFunction(cx, tmpObj, "getSearchResolutionsOrder", js_cocos2dx_CCFileUtils_getSearchResolutionsOrder, 0, JSPROP_PERMANENT ); + JS_DefineFunction(cx, tmpObj, "createDictionaryWithContentsOfFile", js_cocos2dx_FileUtils_createDictionaryWithContentsOfFile, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "getDataFromFile", js_cocos2dx_CCFileUtils_getDataFromFile, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_GetProperty(cx, ccObj, "EventListenerTouchOneByOne", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_EventListenerTouchOneByOne_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.EventListenerTouchAllAtOnce; })()")); + JS_GetProperty(cx, ccObj, "EventListenerTouchAllAtOnce", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_EventListenerTouchAllAtOnce_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.EventListenerMouse; })()")); + JS_GetProperty(cx, ccObj, "EventListenerMouse", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_EventListenerMouse_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.EventListenerKeyboard; })()")); + JS_GetProperty(cx, ccObj, "EventListenerKeyboard", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_EventListenerKeyboard_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.BezierBy; })()")); + JS_GetProperty(cx, ccObj, "EventListenerFocus", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); + JS_DefineFunction(cx, tmpObj, "create", js_EventListenerFocus_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); + + JS_GetProperty(cx, ccObj, "BezierBy", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", JSB_CCBezierBy_actionWithDuration, 2, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_BezierBy_prototype, "initWithDuration", JSB_CCBezierBy_initWithDuration, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.BezierTo; })()")); + tmpObj.set(jsb_cocos2d_BezierBy_prototype); + JS_DefineFunction(cx, tmpObj, "initWithDuration", JSB_CCBezierBy_initWithDuration, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_GetProperty(cx, ccObj, "BezierTo", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", JSB_CCBezierTo_actionWithDuration, 2, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_BezierTo_prototype, "initWithDuration", JSB_CCBezierTo_initWithDuration, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_BezierTo_prototype); + JS_DefineFunction(cx, tmpObj, "initWithDuration", JSB_CCBezierTo_initWithDuration, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.CardinalSplineBy; })()")); + JS_GetProperty(cx, ccObj, "CardinalSplineBy", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", JSB_CCCardinalSplineBy_actionWithDuration, 2, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.CardinalSplineTo; })()")); + JS_GetProperty(cx, ccObj, "CardinalSplineTo", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", JSB_CCCardinalSplineTo_actionWithDuration, 2, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_CardinalSplineTo_prototype, "initWithDuration", js_cocos2dx_CardinalSplineTo_initWithDuration, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.CatmullRomBy; })()")); + tmpObj.set(jsb_cocos2d_CardinalSplineTo_prototype); + JS_DefineFunction(cx, tmpObj, "initWithDuration", js_cocos2dx_CardinalSplineTo_initWithDuration, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_GetProperty(cx, ccObj, "CatmullRomBy", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", JSB_CCCatmullRomBy_actionWithDuration, 2, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_CatmullRomBy_prototype, "initWithDuration", JSB_CatmullRomBy_initWithDuration, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_CatmullRomBy_prototype); + JS_DefineFunction(cx, tmpObj, "initWithDuration", JSB_CatmullRomBy_initWithDuration, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.CatmullRomTo; })()")); + JS_GetProperty(cx, ccObj, "CatmullRomTo", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", JSB_CCCatmullRomTo_actionWithDuration, 2, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_CatmullRomTo_prototype, "initWithDuration", JSB_CatmullRomBy_initWithDuration, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_Sprite_prototype, "textureLoaded", js_cocos2dx_CCSprite_textureLoaded, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_SpriteBatchNode_prototype, "getDescendants", js_cocos2dx_SpriteBatchNode_getDescendants, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_Action_prototype, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Action_prototype, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Animation_prototype, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Animation_prototype, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_SpriteFrame_prototype, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_SpriteFrame_prototype, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_MenuItem_prototype, "setCallback", js_cocos2dx_CCMenuItem_setCallback, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_TMXLayer_prototype, "getTileFlagsAt", js_cocos2dx_CCTMXLayer_tileFlagsAt, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_TMXLayer_prototype, "getTiles", js_cocos2dx_CCTMXLayer_getTiles, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_ActionInterval_prototype, "repeat", js_cocos2dx_ActionInterval_repeat, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_ActionInterval_prototype, "repeatForever", js_cocos2dx_ActionInterval_repeatForever, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_ActionInterval_prototype, "_speed", js_cocos2dx_ActionInterval_speed, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_ActionInterval_prototype, "easing", js_cocos2dx_ActionInterval_easing, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocos2d_RenderTexture_prototype, "saveToFile", js_cocos2dx_RenderTexture_saveToFile, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.Menu; })()")); + tmpObj.set(jsb_cocos2d_CatmullRomTo_prototype); + JS_DefineFunction(cx, tmpObj, "initWithDuration", JSB_CatmullRomBy_initWithDuration, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_Sprite_prototype); + JS_DefineFunction(cx, tmpObj, "textureLoaded", js_cocos2dx_CCSprite_textureLoaded, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_SpriteBatchNode_prototype); + JS_DefineFunction(cx, tmpObj, "getDescendants", js_cocos2dx_SpriteBatchNode_getDescendants, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_Action_prototype); + JS_DefineFunction(cx, tmpObj, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_Animation_prototype); + JS_DefineFunction(cx, tmpObj, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_SpriteFrame_prototype); + JS_DefineFunction(cx, tmpObj, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_MenuItem_prototype); + JS_DefineFunction(cx, tmpObj, "setCallback", js_cocos2dx_MenuItem_setCallback, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_TMXLayer_prototype); + JS_DefineFunction(cx, tmpObj, "getTileFlagsAt", js_cocos2dx_CCTMXLayer_tileFlagsAt, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "getTiles", js_cocos2dx_CCTMXLayer_getTiles, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_ActionInterval_prototype); + JS_DefineFunction(cx, tmpObj, "repeat", js_cocos2dx_ActionInterval_repeat, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "repeatForever", js_cocos2dx_ActionInterval_repeatForever, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "_speed", js_cocos2dx_ActionInterval_speed, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "easing", js_cocos2dx_ActionInterval_easing, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_RenderTexture_prototype); + JS_DefineFunction(cx, tmpObj, "saveToFile", js_cocos2dx_RenderTexture_saveToFile, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_GetProperty(cx, ccObj, "Menu", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "_create", js_cocos2dx_CCMenu_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.MenuItem; })()")); + JS_GetProperty(cx, ccObj, "MenuItem", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCMenuItem_create, 1, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.MenuItemSprite; })()")); + JS_GetProperty(cx, ccObj, "MenuItemSprite", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCMenuItemSprite_create, 1, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.MenuItemLabel; })()")); + JS_GetProperty(cx, ccObj, "MenuItemLabel", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCMenuItemLabel_create, 1, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.MenuItemAtlasFont; })()")); + JS_GetProperty(cx, ccObj, "MenuItemAtlasFont", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCMenuItemAtlasFont_create, 1, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.MenuItemFont; })()")); + JS_GetProperty(cx, ccObj, "MenuItemFont", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCMenuItemFont_create, 1, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.MenuItemToggle; })()")); + JS_GetProperty(cx, ccObj, "MenuItemToggle", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "_create", js_cocos2dx_CCMenuItemToggle_create, 1, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.Sequence; })()")); + JS_GetProperty(cx, ccObj, "Sequence", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCSequence_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.Spawn; })()")); + JS_GetProperty(cx, ccObj, "Spawn", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCSpawn_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); - //tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.Animation; })()")); + //JS_GetProperty(cx, ccObj, "Animation", &tmpVal); + //tmpObj = tmpVal.toObjectOrNull(); //JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCAnimation_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_Scene_prototype, "init", js_cocos2dx_CCScene_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.LayerMultiplex; })()")); + tmpObj.set(jsb_cocos2d_Scene_prototype); + JS_DefineFunction(cx, tmpObj, "init", js_cocos2dx_CCScene_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE); + JS_GetProperty(cx, ccObj, "LayerMultiplex", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCLayerMultiplex_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, ccObj, "registerTargetedDelegate", js_cocos2dx_JSTouchDelegate_registerTargetedDelegate, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, ccObj, "registerStandardDelegate", js_cocos2dx_JSTouchDelegate_registerStandardDelegate, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, ccObj, "unregisterTouchDelegate", js_cocos2dx_JSTouchDelegate_unregisterTouchDelegate, 1, JSPROP_READONLY | JSPROP_PERMANENT); - - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.CallFunc; })()")); + JS_GetProperty(cx, ccObj, "CallFunc", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_callFunc, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_CallFuncN_prototype, "initWithFunction", js_cocos2dx_CallFunc_initWithFunction, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_CallFuncN_prototype); + JS_DefineFunction(cx, tmpObj, "initWithFunction", js_cocos2dx_CallFunc_initWithFunction, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.GLProgram; })()")); + JS_GetProperty(cx, ccObj, "GLProgram", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCGLProgram_create, 1, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, tmpObj, "createWithString", js_cocos2dx_CCGLProgram_createWithString, 1, JSPROP_READONLY | JSPROP_PERMANENT); + + JS_DefineFunction(cx, global, "garbageCollect", js_forceGC, 1, JSPROP_READONLY | JSPROP_PERMANENT); - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return this; })()")); - JS_DefineFunction(cx, tmpObj, "garbageCollect", js_forceGC, 1, JSPROP_READONLY | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_Camera_prototype); + JS_DefineFunction(cx, tmpObj, "unproject", js_cocos2dx_Camera_unproject, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "isVisibleInFrustum", js_cocos2dx_Camera_isVisibleInFrustum, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_ClippingNode_prototype); + JS_DefineFunction(cx, tmpObj, "init", js_cocos2dx_ClippingNode_init, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS_DefineFunction(cx, ccObj, "glEnableVertexAttribs", js_cocos2dx_ccGLEnableVertexAttribs, 1, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, ccObj, "pAdd", js_cocos2dx_ccpAdd, 1, JSPROP_READONLY | JSPROP_PERMANENT); @@ -4828,9 +5467,24 @@ void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global) JS_DefineFunction(cx, ccObj, "pClamp", js_cocos2dx_ccpClamp, 2, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, ccObj, "pLengthSQ", js_cocos2dx_ccpLengthSQ, 1, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, ccObj, "pLength", js_cocos2dx_ccpLength, 1, JSPROP_READONLY | JSPROP_PERMANENT); - - JS::RootedObject consoleObj(cx); - create_js_root_obj(cx, global, "console", &consoleObj); - - JS_DefineFunction(cx, consoleObj, "log", js_console_log, 1, JSPROP_READONLY | JSPROP_PERMANENT); + + + JS_DefineFunction(cx, ccObj, "registerTargetedDelegate", js_cocos2dx_JSTouchDelegate_registerTargetedDelegate, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, ccObj, "registerStandardDelegate", js_cocos2dx_JSTouchDelegate_registerStandardDelegate, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, ccObj, "unregisterTouchDelegate", js_cocos2dx_JSTouchDelegate_unregisterTouchDelegate, 1, JSPROP_READONLY | JSPROP_PERMANENT); + + get_or_create_js_obj(cx, ccObj, "math", &tmpObj); + JS_DefineFunction(cx, tmpObj, "obbGetCorners", js_cocos2dx_ccobbGetCorners, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "obbIntersectsObb", js_cocos2dx_ccobbIntersects, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "rayIntersectsObb", js_cocos2dx_ccrayIntersectsObb, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "mat4CreateTranslation", js_cocos2dx_ccmat4CreateTranslation, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "mat4CreateRotation", js_cocos2dx_ccmat4CreateRotation, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "mat4Multiply", js_cocos2dx_ccmat4Multiply, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "mat4MultiplyVec3", js_cocos2dx_ccmat4MultiplyVec3, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "quatMultiply", js_cocos2dx_ccquatMultiply, 2, JSPROP_READONLY | JSPROP_PERMANENT); + + js_register_cocos2dx_EventKeyboard(cx, ccObj); + + get_or_create_js_obj(cx, global, "console", &tmpObj); + JS_DefineFunction(cx, tmpObj, "log", js_console_log, 1, JSPROP_READONLY | JSPROP_PERMANENT); } diff --git a/frameworks/js-bindings/bindings/manual/cocos2d_specifics.hpp b/frameworks/js-bindings/bindings/manual/cocos2d_specifics.hpp index 907009b633..2fc54b6583 100644 --- a/frameworks/js-bindings/bindings/manual/cocos2d_specifics.hpp +++ b/frameworks/js-bindings/bindings/manual/cocos2d_specifics.hpp @@ -33,13 +33,13 @@ class JSScheduleWrapper; // To debug this, you could refer to JSScheduleWrapper::dump function. // It will prove that i'm right. :) typedef struct jsScheduleFunc_proxy { - JSObject* jsfuncObj; + JS::Heap jsfuncObj; cocos2d::__Array* targets; UT_hash_handle hh; } schedFunc_proxy_t; typedef struct jsScheduleTarget_proxy { - JSObject* jsTargetObj; + JS::Heap jsTargetObj; cocos2d::__Array* targets; UT_hash_handle hh; } schedTarget_proxy_t; @@ -99,13 +99,15 @@ inline js_proxy_t *js_get_or_create_proxy(JSContext *cx, T *native_obj) { } JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - - JSObject* js_obj = JS_NewObject(cx, typeProxy->jsclass, typeProxy->proto, typeProxy->parentProto); + + JS::RootedObject proto(cx, const_cast(typeProxy->proto.get())); + JS::RootedObject parent(cx, const_cast(typeProxy->parentProto.get())); + JS::RootedObject js_obj(cx, JS_NewObject(cx, typeProxy->jsclass, proto, parent)); proxy = jsb_new_proxy(native_obj, js_obj); #ifdef DEBUG - JS_AddNamedObjectRoot(cx, &proxy->obj, typeid(*native_obj).name()); + AddNamedObjectRoot(cx, &proxy->obj, typeid(*native_obj).name()); #else - JS_AddObjectRoot(cx, &proxy->obj); + AddObjectRoot(cx, &proxy->obj); #endif return proxy; } else { @@ -114,9 +116,8 @@ inline js_proxy_t *js_get_or_create_proxy(JSContext *cx, T *native_obj) { return NULL; } -jsval anonEvaluate(JSContext *cx, JSObject *thisObj, const char* string); -void register_cocos2dx_js_core(JSContext* cx, JSObject* obj); -void register_cocos2dx_js_extensions(JSContext* cx, JSObject* obj); +JS::Value anonEvaluate(JSContext *cx, JS::HandleObject thisObj, const char* string); +void register_cocos2dx_js_core(JSContext* cx, JS::HandleObject obj); class JSCallbackWrapper: public cocos2d::Ref { @@ -131,9 +132,9 @@ class JSCallbackWrapper: public cocos2d::Ref { const jsval& getJSCallbackThis() const; const jsval& getJSExtraData() const; protected: - jsval _jsCallback; - jsval _jsThisObj; - jsval _extraData; + JS::Heap _jsCallback; + JS::Heap _jsThisObj; + JS::Heap _extraData; }; @@ -143,19 +144,19 @@ class JSScheduleWrapper: public JSCallbackWrapper { JSScheduleWrapper() : _pTarget(NULL), _pPureJSTarget(NULL), _priority(0), _isUpdateSchedule(false) {} virtual ~JSScheduleWrapper(); - static void setTargetForSchedule(jsval sched, JSScheduleWrapper *target); - static cocos2d::__Array * getTargetForSchedule(jsval sched); - static void setTargetForJSObject(JSObject* jsTargetObj, JSScheduleWrapper *target); - static cocos2d::__Array * getTargetForJSObject(JSObject* jsTargetObj); + static void setTargetForSchedule(JS::HandleValue sched, JSScheduleWrapper *target); + static cocos2d::__Array * getTargetForSchedule(JS::HandleValue sched); + static void setTargetForJSObject(JS::HandleObject jsTargetObj, JSScheduleWrapper *target); + static cocos2d::__Array * getTargetForJSObject(JS::HandleObject jsTargetObj); // Remove all targets. static void removeAllTargets(); // Remove all targets for priority. static void removeAllTargetsForMinPriority(int minPriority); // Remove all targets by js object from hash table(_schedFunc_target_ht and _schedObj_target_ht). - static void removeAllTargetsForJSObject(JSObject* jsTargetObj); + static void removeAllTargetsForJSObject(JS::HandleObject jsTargetObj); // Remove the target by js object and the wrapper for native schedule. - static void removeTargetForJSObject(JSObject* jsTargetObj, JSScheduleWrapper* target); + static void removeTargetForJSObject(JS::HandleObject jsTargetObj, JSScheduleWrapper* target); static void dump(); void pause(); @@ -166,7 +167,7 @@ class JSScheduleWrapper: public JSCallbackWrapper { Ref* getTarget(); void setTarget(Ref* pTarget); - void setPureJSTarget(JSObject* jstarget); + void setPureJSTarget(JS::HandleObject jstarget); JSObject* getPureJSTarget(); void setPriority(int priority); @@ -177,7 +178,7 @@ class JSScheduleWrapper: public JSCallbackWrapper { protected: Ref* _pTarget; - JSObject* _pPureJSTarget; + JS::Heap _pPureJSTarget; int _priority; bool _isUpdateSchedule; }; @@ -216,7 +217,7 @@ class JSTouchDelegate: public cocos2d::Ref void onTouchesCancelled(const std::vector& touches, cocos2d::Event *event); private: - JSObject* _obj; + JS::Heap _obj; typedef std::unordered_map TouchDelegateMap; typedef std::pair TouchDelegatePair; static TouchDelegateMap sTouchDelegateMap; @@ -251,7 +252,7 @@ class __JSPlistDelegator: public cocos2d::SAXDelegator private: cocos2d::SAXParser _parser; - JSObject* _obj; + JS::Heap _obj; std::string _result; bool _isStoringCharacters; std::string _currentValue; @@ -264,6 +265,6 @@ bool js_cocos2dx_Node_onExitTransitionDidStart(JSContext *cx, uint32_t argc, jsv bool js_cocos2dx_Component_onEnter(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Component_onExit(JSContext *cx, uint32_t argc, jsval *vp); -void create_js_root_obj(JSContext* cx, JSObject* global, const std::string &name, JS::RootedObject *jsObj); +void get_or_create_js_obj(JSContext* cx, JS::HandleObject obj, const std::string &name, JS::MutableHandleObject jsObj); #endif diff --git a/frameworks/js-bindings/bindings/manual/cocosbuilder/cocosbuilder_specifics.hpp b/frameworks/js-bindings/bindings/manual/cocosbuilder/cocosbuilder_specifics.hpp index 06749e3c4e..6e41e37186 100644 --- a/frameworks/js-bindings/bindings/manual/cocosbuilder/cocosbuilder_specifics.hpp +++ b/frameworks/js-bindings/bindings/manual/cocosbuilder/cocosbuilder_specifics.hpp @@ -26,20 +26,24 @@ #include "../cocos2d_specifics.hpp" -class JSCCBAnimationWrapper: public JSCallbackWrapper { +class JSCCBAnimationWrapper: public JSCallbackWrapper +{ public: JSCCBAnimationWrapper() {} virtual ~JSCCBAnimationWrapper() {} - void animationCompleteCallback() { - - JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - jsval retval = JSVAL_NULL; - - if(!JSVAL_IS_VOID(_jsCallback) && !JSVAL_IS_VOID(_jsThisObj)) { + void animationCompleteCallback() + { + + if(!_jsCallback.isNullOrUndefined() && !_jsThisObj.isNullOrUndefined()) + { + + JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); + JS::RootedValue retval(cx); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(_jsThisObj), _jsCallback, 0, NULL, &retval); + JS_CallFunctionValue(cx, JS::RootedObject(cx, _jsThisObj.toObjectOrNull()), JS::RootedValue(cx, _jsCallback), JS::HandleValueArray::empty(), &retval); } } diff --git a/frameworks/js-bindings/bindings/manual/cocosbuilder/js_bindings_ccbreader.cpp b/frameworks/js-bindings/bindings/manual/cocosbuilder/js_bindings_ccbreader.cpp index 634104ca15..dd2bb40fc5 100644 --- a/frameworks/js-bindings/bindings/manual/cocosbuilder/js_bindings_ccbreader.cpp +++ b/frameworks/js-bindings/bindings/manual/cocosbuilder/js_bindings_ccbreader.cpp @@ -70,11 +70,13 @@ CCBSelectorResolver * CCBScriptCallbackProxy::createNew() { } void CCBScriptCallbackProxy::menuItemCallback(Ref *pSender) { - ScriptingCore::getInstance()->executeFunctionWithOwner(owner, callBackProp.c_str() ); + jsval arg; + ScriptingCore::getInstance()->executeFunctionWithOwner(owner, callBackProp.c_str(), 0, &arg); } void CCBScriptCallbackProxy::controlCallback(Ref *pSender, Control::EventType event) { - ScriptingCore::getInstance()->executeFunctionWithOwner(owner, callBackProp.c_str() ); + jsval arg; + ScriptingCore::getInstance()->executeFunctionWithOwner(owner, callBackProp.c_str(), 0, &arg); } void CCBScriptCallbackProxy::setCallbackProperty(const char *prop) { @@ -92,7 +94,7 @@ jsval CCBScriptCallbackProxy::getJSOwner() { bool js_cocos2dx_CCBAnimationManager_animationCompleteCallback(JSContext *cx, uint32_t argc, jsval *vp) { if (argc >= 1) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *p = jsb_get_js_proxy(obj); @@ -101,15 +103,15 @@ bool js_cocos2dx_CCBAnimationManager_animationCompleteCallback(JSContext *cx, ui JSCCBAnimationWrapper *tmpCobj = new JSCCBAnimationWrapper(); tmpCobj->autorelease(); - tmpCobj->setJSCallbackThis(argv[0]); + tmpCobj->setJSCallbackThis(args.get(0)); if(argc >= 2) { - tmpCobj->setJSCallbackFunc(argv[1]); + tmpCobj->setJSCallbackFunc(args.get(1)); } node->setAnimationCompletedCallback(tmpCobj, callfunc_selector(JSCCBAnimationWrapper::animationCompleteCallback)); - JS_SetReservedSlot(p->obj, 0, argv[0]); - JS_SetReservedSlot(p->obj, 1, argv[1]); + JS_SetReservedSlot(p->obj, 0, args.get(0)); + JS_SetReservedSlot(p->obj, 1, args.get(1)); return true; } return false; @@ -117,7 +119,7 @@ bool js_cocos2dx_CCBAnimationManager_animationCompleteCallback(JSContext *cx, ui bool js_cocos2dx_CCBReader_readNodeGraphFromFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj; cocosbuilder::CCBReader* cobj; @@ -128,11 +130,11 @@ bool js_cocos2dx_CCBReader_readNodeGraphFromFile(JSContext *cx, uint32_t argc, j if (argc == 2) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); cocos2d::Ref* arg1; do { js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Ref*)(proxy ? proxy->ptr : NULL); } while (0); @@ -148,12 +150,12 @@ bool js_cocos2dx_CCBReader_readNodeGraphFromFile(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cocos2d::Node* ret = cobj->readNodeGraphFromFile(arg0); @@ -165,21 +167,21 @@ bool js_cocos2dx_CCBReader_readNodeGraphFromFile(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 3) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); cocos2d::Ref* arg1; do { js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Ref*)(proxy ? proxy->ptr : NULL); } while (0); cocos2d::Size arg2; - ok &= jsval_to_ccsize(cx, argv[2], &arg2); + ok &= jsval_to_ccsize(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); @@ -192,7 +194,7 @@ bool js_cocos2dx_CCBReader_readNodeGraphFromFile(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } return false; @@ -200,7 +202,7 @@ bool js_cocos2dx_CCBReader_readNodeGraphFromFile(JSContext *cx, uint32_t argc, j bool js_cocos2dx_CCBReader_createSceneWithNodeGraphFromFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj; cocosbuilder::CCBReader* cobj; @@ -211,11 +213,11 @@ bool js_cocos2dx_CCBReader_createSceneWithNodeGraphFromFile(JSContext *cx, uint3 if (argc == 2) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); cocos2d::Ref* arg1; do { js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Ref*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, arg1) @@ -232,12 +234,12 @@ bool js_cocos2dx_CCBReader_createSceneWithNodeGraphFromFile(JSContext *cx, uint3 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cocos2d::Scene* ret = cobj->createSceneWithNodeGraphFromFile(arg0); @@ -249,22 +251,22 @@ bool js_cocos2dx_CCBReader_createSceneWithNodeGraphFromFile(JSContext *cx, uint3 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 3) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); cocos2d::Ref* arg1; do { js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[1]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); arg1 = (cocos2d::Ref*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, arg1) } while (0); cocos2d::Size arg2; - ok &= jsval_to_ccsize(cx, argv[2], &arg2); + ok &= jsval_to_ccsize(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); @@ -277,7 +279,7 @@ bool js_cocos2dx_CCBReader_createSceneWithNodeGraphFromFile(JSContext *cx, uint3 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -287,7 +289,7 @@ bool js_cocos2dx_CCBReader_createSceneWithNodeGraphFromFile(JSContext *cx, uint3 bool js_CocosBuilder_create(JSContext *cx, uint32_t argc, jsval *vp) { - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); NodeLoaderLibrary * ccNodeLoaderLibrary = NodeLoaderLibrary::getInstance(); ccNodeLoaderLibrary->registerNodeLoader("", JSLayerLoader::loader()); @@ -308,7 +310,7 @@ bool js_CocosBuilder_create(JSContext *cx, uint32_t argc, jsval *vp) } else { jsret = JSVAL_NULL; } - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -316,23 +318,18 @@ bool js_CocosBuilder_create(JSContext *cx, uint32_t argc, jsval *vp) extern JSObject* jsb_cocosbuilder_CCBReader_prototype; extern JSObject* jsb_cocosbuilder_CCBAnimationManager_prototype; -void register_CCBuilderReader(JSContext *cx, JSObject *obj) { - JS::RootedValue nsval(cx); - JS::RootedObject ns(cx); - JS_GetProperty(cx, obj, "cc", &nsval); - if (nsval == JSVAL_VOID) { - ns = JS_NewObject(cx, NULL, NULL, NULL); - nsval = OBJECT_TO_JSVAL(ns); - JS_SetProperty(cx, obj, "cc", nsval); - } else { - JS_ValueToObject(cx, nsval, &ns); - } - obj = ns; - - JSObject *tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, obj, "(function () { return cc._Reader; })()")); +void register_CCBuilderReader(JSContext *cx, JS::HandleObject global) +{ + JS::RootedObject ccObj(cx); + JS::RootedValue tmpVal(cx); + JS::RootedObject tmpObj(cx); + get_or_create_js_obj(cx, global, "cc", &ccObj); + + JS_GetProperty(cx, ccObj, "_Reader", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_CocosBuilder_create, 2, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, tmpObj, "loadScene", js_cocos2dx_CCBReader_createSceneWithNodeGraphFromFile, 2, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocosbuilder_CCBReader_prototype, "load", js_cocos2dx_CCBReader_readNodeGraphFromFile, 2, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocosbuilder_CCBAnimationManager_prototype, "setCompletedAnimationCallback", js_cocos2dx_CCBAnimationManager_animationCompleteCallback, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocosbuilder_CCBReader_prototype), "load", js_cocos2dx_CCBReader_readNodeGraphFromFile, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocosbuilder_CCBAnimationManager_prototype), "setCompletedAnimationCallback", js_cocos2dx_CCBAnimationManager_animationCompleteCallback, 2, JSPROP_READONLY | JSPROP_PERMANENT); } diff --git a/frameworks/js-bindings/bindings/manual/cocosbuilder/js_bindings_ccbreader.h b/frameworks/js-bindings/bindings/manual/cocosbuilder/js_bindings_ccbreader.h index ddc63089fe..ba7f00a2ff 100644 --- a/frameworks/js-bindings/bindings/manual/cocosbuilder/js_bindings_ccbreader.h +++ b/frameworks/js-bindings/bindings/manual/cocosbuilder/js_bindings_ccbreader.h @@ -69,7 +69,7 @@ class JSLayerLoader : public cocosbuilder::LayerLoader { CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(CCBScriptCallbackProxy); }; -void register_CCBuilderReader(JSContext *cx, JSObject *global); +void register_CCBuilderReader(JSContext *cx, JS::HandleObject global); bool js_CocosBuilder_Run(JSContext *cx, uint32_t argc, jsval *vp); #endif /* __JS_BINDINGS_CCBREADER_H__ */ diff --git a/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_conversions.cpp b/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_conversions.cpp new file mode 100644 index 0000000000..f996404c8c --- /dev/null +++ b/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_conversions.cpp @@ -0,0 +1,66 @@ +/* + * Created by Huabin LING on 21/1/15. + * Copyright (c) 2015 Chukong Technologies Inc. + * + * 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 "jsb_cocos2dx_studio_conversions.h" +#include "cocos2d_specifics.hpp" +#include "cocostudio/CocoStudio.h" + +jsval animationInfo_to_jsval(JSContext* cx, const cocostudio::timeline::AnimationInfo& v) +{ + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); + if (!tmp) return JSVAL_NULL; + bool ok = JS_DefineProperty(cx, tmp, "name", JS::RootedValue(cx, std_string_to_jsval(cx, v.name)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "startIndex", v.startIndex, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "endIndex", v.endIndex, JSPROP_ENUMERATE | JSPROP_PERMANENT); + if (ok) { + return OBJECT_TO_JSVAL(tmp); + } + return JSVAL_NULL; +} + +bool jsval_to_animationInfo(JSContext* cx, JS::HandleValue vp, cocostudio::timeline::AnimationInfo* ret) +{ + JS::RootedObject tmp(cx); + JS::RootedValue jsName(cx); + JS::RootedValue jsStartId(cx); + JS::RootedValue jsEndId(cx); + std::string name; + double startIndex, endIndex; + + bool ok = vp.isObject() && + JS_ValueToObject(cx, vp, &tmp) && + JS_GetProperty(cx, tmp, "name", &jsName) && + JS_GetProperty(cx, tmp, "startIndex", &jsStartId) && + JS_GetProperty(cx, tmp, "endIndex", &jsEndId) && + JS::ToNumber(cx, jsStartId, &startIndex) && + JS::ToNumber(cx, jsEndId, &endIndex) && + jsval_to_std_string(cx, jsName, &name) && + !isnan(startIndex) && !isnan(endIndex); + + JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); + + ret->name = name; + ret->startIndex = (int)startIndex; + ret->endIndex = (int)endIndex; + return true; +} diff --git a/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_conversions.h b/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_conversions.h new file mode 100644 index 0000000000..513d2847f9 --- /dev/null +++ b/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_conversions.h @@ -0,0 +1,40 @@ +/* + * Created by Huabin LING on 21/1/15. + * Copyright (c) 2015 Chukong Technologies Inc. + * + * 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. + */ + +#ifndef __cocos2d_js_bindings__jsb_cocos2dx_studio_conversions__ +#define __cocos2d_js_bindings__jsb_cocos2dx_studio_conversions__ + +#include "jsapi.h" + +namespace cocostudio +{ + namespace timeline + { + struct AnimationInfo; + } +} + +extern jsval animationInfo_to_jsval(JSContext* cx, const cocostudio::timeline::AnimationInfo& v); +extern bool jsval_to_animationInfo(JSContext* cx, JS::HandleValue vp, cocostudio::timeline::AnimationInfo* ret); + +#endif /* defined(__cocos2d_js_bindings__jsb_cocos2dx_studio_conversions__) */ diff --git a/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp b/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp index 1400fc693c..3341ceac0f 100644 --- a/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp +++ b/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp @@ -52,30 +52,30 @@ JSArmatureWrapper::~JSArmatureWrapper() if (m_bNeedUnroot) { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_RemoveValueRoot(cx, &_jsThisObj); + JS::RemoveValueRoot(cx, &_jsThisObj); } } -void JSArmatureWrapper::setJSCallbackThis(jsval _jsThisObj) +void JSArmatureWrapper::setJSCallbackThis(jsval obj) { - JSCallbackWrapper::setJSCallbackThis(_jsThisObj); + JSCallbackWrapper::setJSCallbackThis(obj); - JSObject *thisObj = JSVAL_TO_OBJECT(_jsThisObj); + JSObject *thisObj = obj.toObjectOrNull(); js_proxy *p = jsb_get_js_proxy(thisObj); if (!p) { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); m_bNeedUnroot = true; - m_bNeedUnroot &= JS_AddValueRoot(cx, &_jsThisObj); + m_bNeedUnroot &= JS::AddValueRoot(cx, &_jsThisObj); } } void JSArmatureWrapper::movementCallbackFunc(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID) { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JSObject *thisObj = JSVAL_IS_VOID(_jsThisObj) ? NULL : JSVAL_TO_OBJECT(_jsThisObj); + JS::RootedObject thisObj(cx, _jsThisObj.toObjectOrNull()); js_proxy_t *proxy = js_get_or_create_proxy(cx, armature); - jsval retval; + JS::RootedValue retval(cx); if (_jsCallback != JSVAL_VOID) { int movementEventType = (int)movementType; @@ -88,30 +88,30 @@ void JSArmatureWrapper::movementCallbackFunc(cocostudio::Armature *armature, coc valArr[1] = movementVal; valArr[2] = idVal; - JS_AddValueRoot(cx, valArr); + //JS_AddValueRoot(cx, valArr); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS_CallFunctionValue(cx, thisObj, _jsCallback, 3, valArr, &retval); - JS_RemoveValueRoot(cx, valArr); + JS_CallFunctionValue(cx, thisObj, JS::RootedValue(cx, _jsCallback), JS::HandleValueArray::fromMarkedLocation(3, valArr), &retval); + //JS_RemoveValueRoot(cx, valArr); } } void JSArmatureWrapper::addArmatureFileInfoAsyncCallbackFunc(float percent) { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JSObject *thisObj = JSVAL_IS_VOID(_jsThisObj) ? NULL : JSVAL_TO_OBJECT(_jsThisObj); - jsval retval; + JS::RootedObject thisObj(cx, _jsThisObj.toObjectOrNull()); + JS::RootedValue retval(cx); if (_jsCallback != JSVAL_VOID) { jsval percentVal = DOUBLE_TO_JSVAL(percent); - JS_AddValueRoot(cx, &percentVal); + //JS_AddValueRoot(cx, &percentVal); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS_CallFunctionValue(cx, thisObj, _jsCallback, 1, &percentVal, &retval); - JS_RemoveValueRoot(cx, &percentVal); + JS_CallFunctionValue(cx, thisObj, JS::RootedValue(cx, _jsCallback), JS::HandleValueArray::fromMarkedLocation(1, &percentVal), &retval); + //JS_RemoveValueRoot(cx, &percentVal); } } @@ -121,9 +121,9 @@ void JSArmatureWrapper::frameCallbackFunc(cocostudio::Bone *bone, const std::str JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JSObject *thisObj = JSVAL_IS_VOID(_jsThisObj) ? NULL : JSVAL_TO_OBJECT(_jsThisObj); + JS::RootedObject thisObj(cx, _jsThisObj.toObjectOrNull()); js_proxy_t *proxy = js_get_or_create_proxy(cx, bone); - jsval retval; + JS::RootedValue retval(cx); if (_jsCallback != JSVAL_VOID) { jsval nameVal = std_string_to_jsval(cx, evt); @@ -136,10 +136,10 @@ void JSArmatureWrapper::frameCallbackFunc(cocostudio::Bone *bone, const std::str valArr[2] = originIndexVal; valArr[3] = currentIndexVal; - JS_AddValueRoot(cx, valArr); + //JS_AddValueRoot(cx, valArr); - JS_CallFunctionValue(cx, thisObj, _jsCallback, 4, valArr, &retval); - JS_RemoveValueRoot(cx, valArr); + JS_CallFunctionValue(cx, thisObj, JS::RootedValue(cx, _jsCallback), JS::HandleValueArray::fromMarkedLocation(4, valArr), &retval); + //JS_RemoveValueRoot(cx, valArr); } } @@ -151,9 +151,9 @@ static bool js_cocos2dx_ArmatureAnimation_setMovementEventCallFunc(JSContext *cx JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc > 0) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - if (JSVAL_IS_NULL(argv[0])) { + if (args.get(0).isNull()) { cobj->setMovementEventCallFunc(nullptr); return true; @@ -170,14 +170,14 @@ static bool js_cocos2dx_ArmatureAnimation_setMovementEventCallFunc(JSContext *cx } dict->setObject(tmpObj, "moveEvent"); - tmpObj->setJSCallbackFunc(argv[0]); + tmpObj->setJSCallbackFunc(args.get(0)); if (argc == 1) { tmpObj->setJSCallbackThis(JSVAL_NULL); } else { - tmpObj->setJSCallbackThis(argv[1]); + tmpObj->setJSCallbackThis(args.get(1)); } cobj->setMovementEventCallFunc(CC_CALLBACK_0(JSArmatureWrapper::movementCallbackFunc, tmpObj, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); @@ -197,9 +197,9 @@ static bool js_cocos2dx_ArmatureAnimation_setFrameEventCallFunc(JSContext *cx, u JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc > 0) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - if (JSVAL_IS_NULL(argv[0])) { + if (args.get(0).isNull()) { cobj->setFrameEventCallFunc(nullptr); return true; @@ -216,14 +216,14 @@ static bool js_cocos2dx_ArmatureAnimation_setFrameEventCallFunc(JSContext *cx, u } dict->setObject(tmpObj, "frameEvent"); - tmpObj->setJSCallbackFunc(argv[0]); + tmpObj->setJSCallbackFunc(args.get(0)); if (argc == 1) { tmpObj->setJSCallbackThis(JSVAL_NULL); } else { - tmpObj->setJSCallbackThis(argv[1]); + tmpObj->setJSCallbackThis(args.get(1)); } cobj->setFrameEventCallFunc(CC_CALLBACK_0(JSArmatureWrapper::frameCallbackFunc, tmpObj, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); @@ -244,16 +244,16 @@ static bool jsb_Animation_addArmatureFileInfoAsyncCallFunc(JSContext *cx, uint32 JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 3) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSArmatureWrapper *tmpObj = new JSArmatureWrapper(); tmpObj->autorelease(); - tmpObj->setJSCallbackFunc(argv[1]); - tmpObj->setJSCallbackThis(argv[2]); + tmpObj->setJSCallbackFunc(args.get(1)); + tmpObj->setJSCallbackThis(args.get(2)); std::string ret; - jsval_to_std_string(cx, argv[0], &ret); + jsval_to_std_string(cx, args.get(0), &ret); cobj->addArmatureFileInfoAsync(ret.c_str(), tmpObj, schedule_selector(JSArmatureWrapper::addArmatureFileInfoAsyncCallbackFunc)); @@ -261,22 +261,22 @@ static bool jsb_Animation_addArmatureFileInfoAsyncCallFunc(JSContext *cx, uint32 } if(argc == 5){ - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSArmatureWrapper *tmpObj = new JSArmatureWrapper(); tmpObj->autorelease(); - tmpObj->setJSCallbackFunc(argv[3]); - tmpObj->setJSCallbackThis(argv[4]); + tmpObj->setJSCallbackFunc(args.get(3)); + tmpObj->setJSCallbackThis(args.get(4)); std::string imagePath; - jsval_to_std_string(cx ,argv[0] , &imagePath); + jsval_to_std_string(cx ,args.get(0) , &imagePath); std::string plistPath; - jsval_to_std_string(cx ,argv[1] , &plistPath); + jsval_to_std_string(cx ,args.get(1) , &plistPath); std::string configFilePath; - jsval_to_std_string(cx ,argv[2] , &configFilePath); + jsval_to_std_string(cx ,args.get(2) , &configFilePath); cobj->addArmatureFileInfoAsync(imagePath.c_str(), plistPath.c_str(), configFilePath.c_str(), tmpObj, schedule_selector(JSArmatureWrapper::addArmatureFileInfoAsyncCallbackFunc)); @@ -286,6 +286,43 @@ static bool jsb_Animation_addArmatureFileInfoAsyncCallFunc(JSContext *cx, uint32 return false; } +static bool js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocostudio::ActionManagerEx* cobj = (cocostudio::ActionManagerEx *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx : Invalid Native Object"); + if (argc == 3) { + const char* arg0; + const char* arg1; + cocos2d::Ref* arg2; + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); + rapidjson::Document arg1Jsondoc; + arg1Jsondoc.Parse<0>(arg1); + if (arg1Jsondoc.HasParseError()) { + CCLOG("GetParseError %s\n",arg1Jsondoc.GetParseError()); + } + do { + if (!args.get(2).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(2).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg2 = (cocos2d::Ref*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx : Error processing arguments"); + cobj->initWithDictionary(arg0, arg1Jsondoc, arg2); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx : wrong number of arguments: %d, was expecting %d", argc, 3); + return false; +} + bool js_cocos2dx_studio_ColliderBody_getCalculatedVertexList(JSContext *cx, uint32_t argc, jsval *vp) { JSObject *obj = JS_THIS_OBJECT(cx, vp); @@ -293,26 +330,28 @@ bool js_cocos2dx_studio_ColliderBody_getCalculatedVertexList(JSContext *cx, uint cocostudio::ColliderBody* cobj = (cocostudio::ColliderBody *)(proxy ? proxy->ptr : nullptr); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 0) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); const std::vector& ret = cobj->getCalculatedVertexList(); - JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0, nullptr)); + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); jsval jsret; //CCObject* obj; int i = 0; + JS::RootedObject tmp(cx); for(const auto& point : ret) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + tmp = JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr()); if (!tmp) break; - bool ok = JS_DefineProperty(cx, tmp, "x", DOUBLE_TO_JSVAL(point.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "y", DOUBLE_TO_JSVAL(point.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "x", point.x, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "y", point.y, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS::RootedValue jsTmp(cx, OBJECT_TO_JSVAL(tmp)); - if(!ok || !JS_SetElement(cx, jsretArr, i, &jsTmp)) + if(!ok || !JS_SetElement(cx, jsretArr, i, jsTmp)) { break; } ++i; } jsret = OBJECT_TO_JSVAL(jsretArr); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -341,7 +380,7 @@ bool js_get_BaseData_x(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS: bool js_set_BaseData_x(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::BaseData* cobj = (cocostudio::BaseData*)JS_GetPrivate(obj); if (cobj) { - cobj->x = (float)JSVAL_TO_DOUBLE(vp.get()); + cobj->x = (float)vp.get().toDouble(); return true; } JS_ReportError(cx, "js_set_BaseData_x : Invalid native object."); @@ -367,7 +406,7 @@ bool js_get_BaseData_y(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS: bool js_set_BaseData_y(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::BaseData* cobj = (cocostudio::BaseData*)JS_GetPrivate(obj); if (cobj) { - cobj->y = (float)JSVAL_TO_DOUBLE(vp.get()); + cobj->y = (float)vp.get().toDouble(); return true; } JS_ReportError(cx, "js_set_BaseData_y : Invalid native object."); @@ -393,7 +432,7 @@ bool js_get_BaseData_zOrder(JSContext *cx, JS::HandleObject obj, JS::HandleId id bool js_set_BaseData_zOrder(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::BaseData* cobj = (cocostudio::BaseData*)JS_GetPrivate(obj); if (cobj) { - cobj->y = (int)JSVAL_TO_INT(vp.get()); + cobj->y = (int)vp.get().toDouble(); return true; } JS_ReportError(cx, "js_set_BaseData_zOrder : Invalid native object."); @@ -419,7 +458,7 @@ bool js_get_BaseData_skewX(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool js_set_BaseData_skewX(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::BaseData* cobj = (cocostudio::BaseData*)JS_GetPrivate(obj); if (cobj) { - cobj->skewX = (float)JSVAL_TO_DOUBLE(vp.get()); + cobj->skewX = (float)vp.get().toDouble(); return true; } JS_ReportError(cx, "js_set_BaseData_skewX : Invalid native object."); @@ -445,7 +484,7 @@ bool js_get_BaseData_skewY(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool js_set_BaseData_skewY(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::BaseData* cobj = (cocostudio::BaseData*)JS_GetPrivate(obj); if (cobj) { - cobj->skewY = (float)JSVAL_TO_DOUBLE(vp.get()); + cobj->skewY = (float)vp.get().toDouble(); return true; } JS_ReportError(cx, "js_set_BaseData_skewY : Invalid native object."); @@ -471,7 +510,7 @@ bool js_get_BaseData_scaleX(JSContext *cx, JS::HandleObject obj, JS::HandleId id bool js_set_BaseData_scaleX(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::BaseData* cobj = (cocostudio::BaseData*)JS_GetPrivate(obj); if (cobj) { - cobj->scaleX = (float)JSVAL_TO_DOUBLE(vp.get()); + cobj->scaleX = (float)vp.get().toDouble(); return true; } JS_ReportError(cx, "js_set_BaseData_scaleX : Invalid native object."); @@ -497,7 +536,7 @@ bool js_get_BaseData_scaleY(JSContext *cx, JS::HandleObject obj, JS::HandleId id bool js_set_BaseData_scaleY(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::BaseData* cobj = (cocostudio::BaseData*)JS_GetPrivate(obj); if (cobj) { - cobj->scaleY = (float)JSVAL_TO_DOUBLE(vp.get()); + cobj->scaleY = (float)vp.get().toDouble(); return true; } JS_ReportError(cx, "js_set_BaseData_scaleY : Invalid native object."); @@ -523,7 +562,7 @@ bool js_get_BaseData_tweenRotate(JSContext *cx, JS::HandleObject obj, JS::Handle bool js_set_BaseData_tweenRotate(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::BaseData* cobj = (cocostudio::BaseData*)JS_GetPrivate(obj); if (cobj) { - cobj->tweenRotate = (float)JSVAL_TO_DOUBLE(vp.get()); + cobj->tweenRotate = (float)vp.get().toDouble(); return true; } JS_ReportError(cx, "js_set_BaseData_tweenRotate : Invalid native object."); @@ -549,7 +588,7 @@ bool js_get_BaseData_isUseColorInfo(JSContext *cx, JS::HandleObject obj, JS::Han bool js_set_BaseData_isUseColorInfo(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::BaseData* cobj = (cocostudio::BaseData*)JS_GetPrivate(obj); if (cobj) { - cobj->isUseColorInfo = JSVAL_TO_BOOLEAN(vp.get()); + cobj->isUseColorInfo = vp.get().toBoolean(); return true; } JS_ReportError(cx, "js_set_BaseData_isUseColorInfo : Invalid native object."); @@ -575,7 +614,7 @@ bool js_get_BaseData_a(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS: bool js_set_BaseData_a(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::BaseData* cobj = (cocostudio::BaseData*)JS_GetPrivate(obj); if (cobj) { - cobj->a = JSVAL_TO_INT(vp.get()); + cobj->a = vp.get().toInt32(); return true; } JS_ReportError(cx, "js_set_BaseData_a : Invalid native object."); @@ -601,7 +640,7 @@ bool js_get_BaseData_r(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS: bool js_set_BaseData_r(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::BaseData* cobj = (cocostudio::BaseData*)JS_GetPrivate(obj); if (cobj) { - cobj->r = JSVAL_TO_INT(vp.get()); + cobj->r = vp.get().toInt32(); return true; } JS_ReportError(cx, "js_set_BaseData_r : Invalid native object."); @@ -627,7 +666,7 @@ bool js_get_BaseData_g(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS: bool js_set_BaseData_g(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::BaseData* cobj = (cocostudio::BaseData*)JS_GetPrivate(obj); if (cobj) { - cobj->g = JSVAL_TO_INT(vp.get()); + cobj->g = vp.get().toInt32(); return true; } JS_ReportError(cx, "js_set_BaseData_g : Invalid native object."); @@ -653,7 +692,7 @@ bool js_get_BaseData_b(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS: bool js_set_BaseData_b(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::BaseData* cobj = (cocostudio::BaseData*)JS_GetPrivate(obj); if (cobj) { - cobj->b = JSVAL_TO_INT(vp.get()); + cobj->b = vp.get().toInt32(); return true; } JS_ReportError(cx, "js_set_BaseData_b : Invalid native object."); @@ -682,7 +721,7 @@ bool js_set_AnimationData_name(JSContext *cx, JS::HandleObject obj, JS::HandleId cocostudio::AnimationData* cobj = (cocostudio::AnimationData*)JS_GetPrivate(obj); if (cobj) { std::string name; - bool ok = jsval_to_std_string(cx, vp.get(), &name); + bool ok = jsval_to_std_string(cx, JS::RootedValue(cx, vp.get()), &name); JSB_PRECONDITION2(ok, cx, false, "js_set_AnimationData_name : Error processing arguments"); cobj->name = name; return true; @@ -711,7 +750,7 @@ bool js_set_AnimationData_movementNames(JSContext *cx, JS::HandleObject obj, JS: cocostudio::AnimationData* cobj = (cocostudio::AnimationData*)JS_GetPrivate(obj); if (cobj) { std::vector movementNames; - bool ok = jsval_to_std_vector_string(cx, vp.get(), &movementNames); + bool ok = jsval_to_std_vector_string(cx, JS::RootedValue(cx, vp.get()), &movementNames); JSB_PRECONDITION2(ok, cx, false, "js_set_AnimationData_movementNames : Error processing arguments."); cobj->movementNames.clear(); cobj->movementNames = movementNames; @@ -725,7 +764,7 @@ bool js_get_AnimationData_movementDataDic(JSContext *cx, JS::HandleObject obj, J cocostudio::AnimationData* cobj = (cocostudio::AnimationData*)JS_GetPrivate(obj); if (cobj) { cocos2d::Map dic = cobj->movementDataDic; - JSObject* jsRet = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject jsRet(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); for (auto iter = dic.begin(); iter != dic.end(); ++iter) { @@ -764,33 +803,32 @@ bool js_get_AnimationData_movementDataDic(JSContext *cx, JS::HandleObject obj, J bool js_set_AnimationData_movementDataDic(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::AnimationData* cobj = (cocostudio::AnimationData*)JS_GetPrivate(obj); if (cobj) { - jsval val = vp.get(); - if (JSVAL_IS_NULL(val) || JSVAL_IS_VOID(val)) + if (vp.isNullOrUndefined()) { return true; } - JSObject* tmp = JSVAL_TO_OBJECT(val); + JS::RootedObject tmp(cx, vp.toObjectOrNull()); JSB_PRECONDITION2(tmp, cx, false, "js_set_AnimationData_movementDataDic: the js value is not an object."); cocos2d::Map dict; - JSObject* it = JS_NewPropertyIterator(cx, tmp); + JS::RootedObject it(cx, JS_NewPropertyIterator(cx, tmp)); while (true) { - jsid idp; - jsval key; - if (! JS_NextProperty(cx, it, &idp) || ! JS_IdToValue(cx, idp, &key)) { + JS::RootedId idp(cx); + JS::RootedValue key(cx); + if (! JS_NextProperty(cx, it, idp.address()) || ! JS_IdToValue(cx, idp, &key)) { CCLOGERROR("js_set_AnimationData_movementDataDic : Error processing arguments."); return false; // error } if (key == JSVAL_VOID) { break; // end of iteration } - if (!JSVAL_IS_STRING(key)) { + if (!key.isString()) { continue; // ignore integer properties } - JSStringWrapper keyWrapper(JSVAL_TO_STRING(key), cx); + JSStringWrapper keyWrapper(key.toString(), cx); JS::RootedValue value(cx); JS_GetPropertyById(cx, tmp, idp, &value); @@ -799,7 +837,7 @@ bool js_set_AnimationData_movementDataDic(JSContext *cx, JS::HandleObject obj, J do { if (!value.isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(value); + JSObject *tmpObj = value.toObjectOrNull(); jsProxy = jsb_get_js_proxy(tmpObj); movementData = (cocostudio::MovementData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2(movementData, cx, false, "js_set_AnimationData_movementDataDic : Invalid Native Object."); @@ -837,7 +875,7 @@ bool js_set_MovementData_name(JSContext *cx, JS::HandleObject obj, JS::HandleId cocostudio::MovementData* cobj = (cocostudio::MovementData*)JS_GetPrivate(obj); if (cobj) { std::string name; - bool ok = jsval_to_std_string(cx, vp.get(), &name); + bool ok = jsval_to_std_string(cx, JS::RootedValue(cx, vp.get()), &name); JSB_PRECONDITION2(ok, cx, false, "js_set_MovementData_name : Error processing arguments"); cobj->name = name; return true; @@ -865,7 +903,7 @@ bool js_get_MovementData_duration(JSContext *cx, JS::HandleObject obj, JS::Handl bool js_set_MovementData_duration(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::MovementData* cobj = (cocostudio::MovementData*)JS_GetPrivate(obj); if (cobj) { - cobj->duration = JSVAL_TO_INT(vp.get()); + cobj->duration = vp.get().toInt32(); return true; } JS_ReportError(cx, "js_set_MovementData_duration : Invalid native object."); @@ -891,7 +929,7 @@ bool js_get_MovementData_scale(JSContext *cx, JS::HandleObject obj, JS::HandleId bool js_set_MovementData_scale(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::MovementData* cobj = (cocostudio::MovementData*)JS_GetPrivate(obj); if (cobj) { - cobj->scale = (float)JSVAL_TO_DOUBLE(vp.get()); + cobj->scale = (float)vp.get().toDouble(); return true; } JS_ReportError(cx, "js_set_MovementData_scale : Invalid native object."); @@ -917,7 +955,7 @@ bool js_get_MovementData_durationTo(JSContext *cx, JS::HandleObject obj, JS::Han bool js_set_MovementData_durationTo(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::MovementData* cobj = (cocostudio::MovementData*)JS_GetPrivate(obj); if (cobj) { - cobj->durationTo = JSVAL_TO_INT(vp.get()); + cobj->durationTo = vp.get().toInt32(); return true; } JS_ReportError(cx, "js_set_MovementData_durationTo : Invalid native object."); @@ -943,7 +981,7 @@ bool js_get_MovementData_durationTween(JSContext *cx, JS::HandleObject obj, JS:: bool js_set_MovementData_durationTween(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::MovementData* cobj = (cocostudio::MovementData*)JS_GetPrivate(obj); if (cobj) { - cobj->durationTween = JSVAL_TO_INT(vp.get()); + cobj->durationTween = vp.get().toInt32(); return true; } JS_ReportError(cx, "js_set_MovementData_durationTween : Invalid native object."); @@ -969,7 +1007,7 @@ bool js_get_MovementData_loop(JSContext *cx, JS::HandleObject obj, JS::HandleId bool js_set_MovementData_loop(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::MovementData* cobj = (cocostudio::MovementData*)JS_GetPrivate(obj); if (cobj) { - cobj->loop = JSVAL_TO_BOOLEAN(vp.get()); + cobj->loop = vp.get().toBoolean(); return true; } JS_ReportError(cx, "js_get_MovementData_loop : Invalid native object."); @@ -995,65 +1033,392 @@ bool js_get_MovementData_tweenEasing(JSContext *cx, JS::HandleObject obj, JS::Ha bool js_set_MovementData_tweenEasing(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { cocostudio::MovementData* cobj = (cocostudio::MovementData*)JS_GetPrivate(obj); if (cobj) { - cobj->tweenEasing = (cocos2d::tweenfunc::TweenType)JSVAL_TO_INT(vp.get()); + cobj->tweenEasing = (cocos2d::tweenfunc::TweenType)vp.get().toInt32(); return true; } JS_ReportError(cx, "js_set_MovementData_tweenEasing : Invalid native object."); return false; } +// ContourData properties + +bool js_get_ContourData_vertexList(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy = jsb_get_js_proxy(jsobj); + cocostudio::ContourData* cobj = (cocostudio::ContourData*)(proxy ? proxy->ptr : NULL); + if (cobj) { + const std::vector& ret = cobj->vertexList; + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); + jsval jsret; + //CCObject* obj; + int i = 0; + for(const auto& vec2 : ret) + { + JS::RootedValue arrElement(cx); + arrElement = vector2_to_jsval(cx, vec2); + + if (!JS_SetElement(cx, jsretArr, i, arrElement)) { + break; + } + ++i; + } + jsret = OBJECT_TO_JSVAL(jsretArr); + if (jsret != JSVAL_NULL) + { + vp.set(jsret); + return true; + } + CCLOGERROR("js_get_ContourData_vertexList : Fail to retrieve property from ContourData."); + return false; + } + JS_ReportError(cx, "js_get_ContourData_vertexList : Invalid native object."); + return false; +} +bool js_set_ContourData_vertexList(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy = jsb_get_js_proxy(jsobj); + cocostudio::ContourData* cobj = (cocostudio::ContourData*)(proxy ? proxy->ptr : NULL); + if (cobj) { + JS::RootedObject jsListObj(cx); + jsListObj = vp.get().toObjectOrNull(); + JSB_PRECONDITION3(jsListObj && JS_IsArrayObject(cx, jsListObj), cx, false, "Object must be an array"); + + std::vector list; + uint32_t len = 0; + JS_GetArrayLength(cx, jsListObj, &len); + bool ok; + + for (uint32_t i=0; i < len; i++) + { + JS::RootedValue value(cx); + if (JS_GetElement(cx, jsListObj, i, &value)) + { + cocos2d::Vec2 vec2; + ok = jsval_to_vector2(cx, value, &vec2); + if (ok) + { + list.push_back(vec2); + } + } + } + + cobj->vertexList = list; + return true; + } + JS_ReportError(cx, "js_set_ContourData_vertexList : Invalid native object."); + return false; +} + +// TextureData properties + +bool js_get_TextureData_contourDataList(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy = jsb_get_js_proxy(jsobj); + cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); + if (cobj) { + const cocos2d::Vector& ret = cobj->contourDataList; + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); + jsval jsret; + //CCObject* obj; + int i = 0; + for(const auto& contourData : ret) + { + JS::RootedValue arrElement(cx); + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocostudio::ContourData*)contourData); + arrElement = OBJECT_TO_JSVAL(jsProxy->obj); + + if (!JS_SetElement(cx, jsretArr, i, arrElement)) { + break; + } + ++i; + } + jsret = OBJECT_TO_JSVAL(jsretArr); + if (jsret != JSVAL_NULL) + { + vp.set(jsret); + return true; + } + CCLOGERROR("js_get_TextureData_contourDataList : Fail to retrieve property from TextureData."); + return false; + } + JS_ReportError(cx, "js_get_TextureData_contourDataList : Invalid native object."); + return false; +} +bool js_set_TextureData_contourDataList(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy = jsb_get_js_proxy(jsobj); + cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); + if (cobj) { + JS::RootedObject jsListObj(cx); + jsListObj = vp.get().toObjectOrNull(); + JSB_PRECONDITION3(jsListObj && JS_IsArrayObject(cx, jsListObj), cx, false, "Object must be an array"); + + cocos2d::Vector list; + uint32_t len = 0; + JS_GetArrayLength(cx, jsListObj, &len); + bool ok; + + for (uint32_t i=0; i < len; i++) + { + JS::RootedValue value(cx); + if (JS_GetElement(cx, jsListObj, i, &value)) + { + cocostudio::ContourData* contourData; + do { + if (!value.isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = value.toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + contourData = (cocostudio::ContourData*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2(contourData, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_set_TextureData_contourDataList : Error processing arguments"); + + list.pushBack(contourData); + } + } + + cobj->contourDataList = list; + return true; + } + JS_ReportError(cx, "js_set_TextureData_contourDataList : Invalid native object."); + return false; +} + +bool js_get_TextureData_width(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy = jsb_get_js_proxy(jsobj); + cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); + + //struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(obj); + //cocostudio::TextureData* cobj = (cocostudio::TextureData*)proxy->handle; + + //jsval argv; + //cocostudio::TextureData* cobj = (cocostudio::TextureData*)JS_GetInstancePrivate(cx, obj.get(), jsb_cocostudio_TextureData_class, &argv); + if (cobj) { + jsval ret = DOUBLE_TO_JSVAL(cobj->width); + + if (ret != JSVAL_NULL) + { + vp.set(ret); + return true; + } + CCLOGERROR("js_get_TextureData_width : Fail to retrieve property from TextureData."); + return false; + } + JS_ReportError(cx, "js_get_TextureData_width : Invalid native object."); + return false; +} +bool js_set_TextureData_width(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy = jsb_get_js_proxy(jsobj); + cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); + if (cobj) { + cobj->width = (float)(vp.get().toNumber()); + return true; + } + JS_ReportError(cx, "js_set_TextureData_width : Invalid native object."); + return false; +} + +bool js_get_TextureData_height(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy = jsb_get_js_proxy(jsobj); + cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); + if (cobj) { + jsval ret = DOUBLE_TO_JSVAL(cobj->height); + + if (ret != JSVAL_NULL) + { + vp.set(ret); + return true; + } + CCLOGERROR("js_get_TextureData_height : Fail to retrieve property from TextureData."); + return false; + } + JS_ReportError(cx, "js_get_TextureData_height : Invalid native object."); + return false; +} +bool js_set_TextureData_height(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy = jsb_get_js_proxy(jsobj); + cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); + if (cobj) { + cobj->height = (float)vp.get().toNumber(); + return true; + } + JS_ReportError(cx, "js_set_TextureData_height : Invalid native object."); + return false; +} + +bool js_get_TextureData_pivotX(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy = jsb_get_js_proxy(jsobj); + cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); + if (cobj) { + jsval ret = DOUBLE_TO_JSVAL(cobj->pivotX); + + if (ret != JSVAL_NULL) + { + vp.set(ret); + return true; + } + CCLOGERROR("js_get_TextureData_pivotX : Fail to retrieve property from TextureData."); + return false; + } + JS_ReportError(cx, "js_get_TextureData_pivotX : Invalid native object."); + return false; +} +bool js_set_TextureData_pivotX(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy = jsb_get_js_proxy(jsobj); + cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); + if (cobj) { + cobj->pivotX = (float)vp.get().toNumber(); + return true; + } + JS_ReportError(cx, "js_set_TextureData_pivotX : Invalid native object."); + return false; +} + +bool js_get_TextureData_pivotY(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy = jsb_get_js_proxy(jsobj); + cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); + if (cobj) { + jsval ret = DOUBLE_TO_JSVAL(cobj->pivotY); + + if (ret != JSVAL_NULL) + { + vp.set(ret); + return true; + } + CCLOGERROR("js_get_TextureData_pivotY : Fail to retrieve property from TextureData."); + return false; + } + JS_ReportError(cx, "js_get_TextureData_pivotY : Invalid native object."); + return false; +} +bool js_set_TextureData_pivotY(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy = jsb_get_js_proxy(jsobj); + cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); + if (cobj) { + cobj->pivotY = (float)vp.get().toNumber(); + return true; + } + JS_ReportError(cx, "js_set_TextureData_pivotY : Invalid native object."); + return false; +} + +bool js_get_TextureData_name(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy = jsb_get_js_proxy(jsobj); + cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); + if (cobj) { + jsval ret = std_string_to_jsval(cx, cobj->name); + + if (ret != JSVAL_NULL) + { + vp.set(ret); + return true; + } + CCLOGERROR("js_get_TextureData_name : Fail to retrieve property name of TextureData."); + return false; + } + JS_ReportError(cx, "js_get_TextureData_name : Invalid native object."); + return false; +} +bool js_set_TextureData_name(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy = jsb_get_js_proxy(jsobj); + cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); + if (cobj) { + std::string name; + bool ok = jsval_to_std_string(cx, JS::RootedValue(cx, vp.get()), &name); + JSB_PRECONDITION2(ok, cx, false, "js_set_TextureData_name : Error processing arguments"); + cobj->name = name; + return true; + } + JS_ReportError(cx, "js_set_TextureData_name : Invalid native object."); + return false; +} + + extern JSObject* jsb_cocostudio_ArmatureAnimation_prototype; extern JSObject* jsb_cocostudio_ArmatureDataManager_prototype; extern JSObject* jsb_cocostudio_ColliderBody_prototype; extern JSObject* jsb_cocostudio_BaseData_prototype; extern JSObject* jsb_cocostudio_AnimationData_prototype; extern JSObject* jsb_cocostudio_MovementData_prototype; +extern JSObject* jsb_cocostudio_ActionManagerEx_prototype; +extern JSObject* jsb_cocostudio_ContourData_prototype; +extern JSObject* jsb_cocostudio_TextureData_prototype; -void register_all_cocos2dx_studio_manual(JSContext* cx, JSObject* global) +void register_all_cocos2dx_studio_manual(JSContext* cx, JS::HandleObject global) { - JS_DefineFunction(cx, jsb_cocostudio_ColliderBody_prototype, "getCalculatedVertexList", js_cocos2dx_studio_ColliderBody_getCalculatedVertexList, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocostudio_ArmatureAnimation_prototype, "setMovementEventCallFunc", js_cocos2dx_ArmatureAnimation_setMovementEventCallFunc, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocostudio_ArmatureAnimation_prototype, "setFrameEventCallFunc", js_cocos2dx_ArmatureAnimation_setFrameEventCallFunc, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocostudio_ColliderBody_prototype), "getCalculatedVertexList", js_cocos2dx_studio_ColliderBody_getCalculatedVertexList, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocostudio_ArmatureAnimation_prototype), "setMovementEventCallFunc", js_cocos2dx_ArmatureAnimation_setMovementEventCallFunc, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocostudio_ArmatureAnimation_prototype), "setFrameEventCallFunc", js_cocos2dx_ArmatureAnimation_setFrameEventCallFunc, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocostudio_ArmatureDataManager_prototype), "addArmatureFileInfoAsync", jsb_Animation_addArmatureFileInfoAsyncCallFunc, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocostudio_ActionManagerEx_prototype), "initWithDictionaryEx", js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE); + + JS::RootedObject baseData(cx, jsb_cocostudio_BaseData_prototype); + JS_DefineProperty(cx, baseData, "x", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_BaseData_x, js_set_BaseData_x); + JS_DefineProperty(cx, baseData, "y", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_BaseData_y, js_set_BaseData_y); + JS_DefineProperty(cx, baseData, "zOrder", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_BaseData_zOrder, js_set_BaseData_zOrder); + JS_DefineProperty(cx, baseData, "skewX", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_BaseData_skewX, js_set_BaseData_skewX); + JS_DefineProperty(cx, baseData, "skewY", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_BaseData_skewY, js_set_BaseData_skewY); + JS_DefineProperty(cx, baseData, "scaleX", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_BaseData_scaleX, js_set_BaseData_scaleX); + JS_DefineProperty(cx, baseData, "scaleY", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_BaseData_scaleY, js_set_BaseData_scaleY); + JS_DefineProperty(cx, baseData, "tweenRotate", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_BaseData_tweenRotate, js_set_BaseData_tweenRotate); + JS_DefineProperty(cx, baseData, "isUseColorInfo", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_BaseData_isUseColorInfo, js_set_BaseData_isUseColorInfo); + JS_DefineProperty(cx, baseData, "a", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_BaseData_a, js_set_BaseData_a); + JS_DefineProperty(cx, baseData, "r", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_BaseData_r, js_set_BaseData_r); + JS_DefineProperty(cx, baseData, "g", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_BaseData_g, js_set_BaseData_g); + JS_DefineProperty(cx, baseData, "b", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_BaseData_b, js_set_BaseData_b); - JS_DefineFunction(cx, jsb_cocostudio_ArmatureDataManager_prototype, "addArmatureFileInfoAsync", jsb_Animation_addArmatureFileInfoAsyncCallFunc, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); - static JSPropertySpec baseDataProps[] = { - {"x", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_BaseData_x), JSOP_WRAPPER(js_set_BaseData_x)}, - {"y", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_BaseData_y), JSOP_WRAPPER(js_set_BaseData_y)}, - {"zOrder", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_BaseData_zOrder), JSOP_WRAPPER(js_set_BaseData_zOrder)}, - {"skewX", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_BaseData_skewX), JSOP_WRAPPER(js_set_BaseData_skewX)}, - {"skewY", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_BaseData_skewY), JSOP_WRAPPER(js_set_BaseData_skewY)}, - {"scaleX", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_BaseData_scaleX), JSOP_WRAPPER(js_set_BaseData_scaleX)}, - {"scaleY", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_BaseData_scaleY), JSOP_WRAPPER(js_set_BaseData_scaleY)}, - {"tweenRotate", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_BaseData_tweenRotate), JSOP_WRAPPER(js_set_BaseData_tweenRotate)}, - {"isUseColorInfo", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_BaseData_isUseColorInfo), JSOP_WRAPPER(js_set_BaseData_isUseColorInfo)}, - {"a", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_BaseData_a), JSOP_WRAPPER(js_set_BaseData_a)}, - {"r", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_BaseData_r), JSOP_WRAPPER(js_set_BaseData_r)}, - {"g", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_BaseData_g), JSOP_WRAPPER(js_set_BaseData_g)}, - {"b", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_BaseData_b), JSOP_WRAPPER(js_set_BaseData_b)}, - {0, 0, 0, 0, 0} - }; - JS_DefineProperties(cx, jsb_cocostudio_BaseData_prototype, baseDataProps); + JS::RootedObject animationData(cx, jsb_cocostudio_AnimationData_prototype); + JS_DefineProperty(cx, animationData, "name", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_AnimationData_name, js_set_AnimationData_name); + JS_DefineProperty(cx, animationData, "movementNames", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_AnimationData_movementNames, js_set_AnimationData_movementNames); + JS_DefineProperty(cx, animationData, "movementDataDic", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_AnimationData_movementDataDic, js_set_AnimationData_movementDataDic); + + JS::RootedObject movementData(cx, jsb_cocostudio_MovementData_prototype); + JS_DefineProperty(cx, movementData, "name", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_MovementData_name, js_set_MovementData_name); + JS_DefineProperty(cx, movementData, "duration", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_MovementData_duration, js_set_MovementData_duration); + JS_DefineProperty(cx, movementData, "scale", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_MovementData_scale, js_set_MovementData_scale); + JS_DefineProperty(cx, movementData, "durationTo", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_MovementData_durationTo, js_set_MovementData_durationTo); + JS_DefineProperty(cx, movementData, "durationTween", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_MovementData_durationTween, js_set_MovementData_durationTween); + JS_DefineProperty(cx, movementData, "loop", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_MovementData_loop, js_set_MovementData_loop); + JS_DefineProperty(cx, movementData, "tweenEasing", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_MovementData_tweenEasing, js_set_MovementData_tweenEasing); + + JS_DefineProperty(cx, JS::RootedObject(cx, jsb_cocostudio_ContourData_prototype), "vertextList", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_ContourData_vertexList, js_set_ContourData_vertexList); - static JSPropertySpec animationDataProps[] = { - {"name", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_AnimationData_name), JSOP_WRAPPER(js_set_AnimationData_name)}, - {"movementNames", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_AnimationData_movementNames), JSOP_WRAPPER(js_set_AnimationData_movementNames)}, - {"movementDataDic", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_AnimationData_movementDataDic), JSOP_WRAPPER(js_set_AnimationData_movementDataDic)}, - {0, 0, 0, 0, 0} - }; - JS_DefineProperties(cx, jsb_cocostudio_AnimationData_prototype, animationDataProps); - - static JSPropertySpec movementDataProps[] = { - {"name", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_MovementData_name), JSOP_WRAPPER(js_set_MovementData_name)}, - {"duration", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_MovementData_duration), JSOP_WRAPPER(js_set_MovementData_duration)}, - {"scale", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_MovementData_scale), JSOP_WRAPPER(js_set_MovementData_scale)}, - {"durationTo", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_MovementData_durationTo), JSOP_WRAPPER(js_set_MovementData_durationTo)}, - {"durationTween", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_MovementData_durationTween), JSOP_WRAPPER(js_set_MovementData_durationTween)}, - {"loop", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_MovementData_loop), JSOP_WRAPPER(js_set_MovementData_loop)}, - {"tweenEasing", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_MovementData_tweenEasing), JSOP_WRAPPER(js_set_MovementData_tweenEasing)}, - {0, 0, 0, 0, 0} - }; - JS_DefineProperties(cx, jsb_cocostudio_AnimationData_prototype, movementDataProps); + JS::RootedObject textureData(cx, jsb_cocostudio_TextureData_prototype); + JS_DefineProperty(cx, textureData, "contourDataList", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_TextureData_contourDataList, js_set_TextureData_contourDataList); + JS_DefineProperty(cx, textureData, "name", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_TextureData_name, js_set_TextureData_name); + JS_DefineProperty(cx, textureData, "width", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_TextureData_width, js_set_TextureData_width); + JS_DefineProperty(cx, textureData, "height", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_TextureData_height, js_set_TextureData_height); + JS_DefineProperty(cx, textureData, "pivotX", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_TextureData_pivotX, js_set_TextureData_pivotX); + JS_DefineProperty(cx, textureData, "pivotY", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_TextureData_pivotY, js_set_TextureData_pivotY); + } \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.h b/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.h index a401ea2566..0efa151a22 100644 --- a/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.h +++ b/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.h @@ -27,6 +27,6 @@ #include "jsapi.h" #include "jsfriendapi.h" -void register_all_cocos2dx_studio_manual(JSContext* cx, JSObject* global); +void register_all_cocos2dx_studio_manual(JSContext* cx, JS::HandleObject global); #endif /* defined(__jsb_cocos2dx_studio_manual__) */ diff --git a/frameworks/js-bindings/bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp b/frameworks/js-bindings/bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp index 9cddd6f9bf..00edfc795d 100644 --- a/frameworks/js-bindings/bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp +++ b/frameworks/js-bindings/bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp @@ -25,6 +25,8 @@ #include "extensions/cocos-ext.h" #include "ScriptingCore.h" #include "cocos2d_specifics.hpp" +#include "jsb_cocos2dx_auto.hpp" +#include USING_NS_CC; USING_NS_CC_EXT; @@ -45,7 +47,7 @@ class JSB_ScrollViewDelegate if (_needUnroot) { JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_RemoveObjectRoot(cx, &_JSDelegate); + JS::RemoveObjectRoot(cx, &_JSDelegate); } } @@ -55,7 +57,7 @@ class JSB_ScrollViewDelegate if (!p) return; jsval arg = OBJECT_TO_JSVAL(p->obj); - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), "scrollViewDidScroll", 1, &arg, NULL); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), "scrollViewDidScroll", 1, &arg); } virtual void scrollViewDidZoom(ScrollView* view) override @@ -64,7 +66,7 @@ class JSB_ScrollViewDelegate if (!p) return; jsval arg = OBJECT_TO_JSVAL(p->obj); - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), "scrollViewDidZoom", 1, &arg, NULL); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), "scrollViewDidZoom", 1, &arg); } void setJSDelegate(JSObject* pJSDelegate) @@ -77,17 +79,17 @@ class JSB_ScrollViewDelegate { _needUnroot = true; JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_AddNamedObjectRoot(cx, &_JSDelegate, "TableViewDelegate"); + JS::AddNamedObjectRoot(cx, &_JSDelegate, "TableViewDelegate"); } } private: - JSObject* _JSDelegate; + JS::Heap _JSDelegate; bool _needUnroot; }; static bool js_cocos2dx_CCScrollView_setDelegate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); @@ -96,7 +98,7 @@ static bool js_cocos2dx_CCScrollView_setDelegate(JSContext *cx, uint32_t argc, j if (argc == 1) { // save the delegate - JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]); + JSObject *jsDelegate = args.get(0).toObjectOrNull(); JSB_ScrollViewDelegate* nativeDelegate = new JSB_ScrollViewDelegate(); nativeDelegate->setJSDelegate(jsDelegate); @@ -105,7 +107,7 @@ static bool js_cocos2dx_CCScrollView_setDelegate(JSContext *cx, uint32_t argc, j nativeDelegate->release(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); @@ -131,7 +133,7 @@ class JSB_TableViewDelegate if (_needUnroot) { JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_RemoveObjectRoot(cx, &_JSDelegate); + JS::RemoveObjectRoot(cx, &_JSDelegate); } } @@ -175,7 +177,7 @@ class JSB_TableViewDelegate { _needUnroot = true; JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_AddNamedObjectRoot(cx, &_JSDelegate, "TableViewDelegate"); + JS::AddNamedObjectRoot(cx, &_JSDelegate, "TableViewDelegate"); } } @@ -187,7 +189,7 @@ class JSB_TableViewDelegate if (!p) return; jsval arg = OBJECT_TO_JSVAL(p->obj); - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), jsFunctionName.c_str(), 1, &arg, NULL); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), jsFunctionName.c_str(), 1, &arg); } void callJSDelegate(TableView* table, TableViewCell* cell, std::string jsFunctionName) @@ -202,16 +204,16 @@ class JSB_TableViewDelegate args[0] = OBJECT_TO_JSVAL(p->obj); args[1] = OBJECT_TO_JSVAL(pCellProxy->obj); - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), jsFunctionName.c_str(), 2, args, NULL); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), jsFunctionName.c_str(), 2, args); } - JSObject* _JSDelegate; + JS::Heap _JSDelegate; bool _needUnroot; }; static bool js_cocos2dx_CCTableView_setDelegate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); @@ -220,7 +222,7 @@ static bool js_cocos2dx_CCTableView_setDelegate(JSContext *cx, uint32_t argc, js if (argc == 1) { // save the delegate - JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]); + JSObject *jsDelegate = args.get(0).toObjectOrNull(); JSB_TableViewDelegate* nativeDelegate = new JSB_TableViewDelegate(); nativeDelegate->setJSDelegate(jsDelegate); @@ -238,7 +240,7 @@ static bool js_cocos2dx_CCTableView_setDelegate(JSContext *cx, uint32_t argc, js nativeDelegate->release(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); @@ -260,22 +262,23 @@ class JSB_TableViewDataSource if (_needUnroot) { JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_RemoveObjectRoot(cx, &_JSTableViewDataSource); + JS::RemoveObjectRoot(cx, &_JSTableViewDataSource); } } virtual Size tableCellSizeForIndex(TableView *table, ssize_t idx) override { - jsval ret; - bool ok = callJSDelegate(table, idx, "tableCellSizeForIndex", ret); + JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); + JS::RootedValue ret(cx); + bool ok = callJSDelegate(table, idx, "tableCellSizeForIndex", &ret); if (!ok) { - ok = callJSDelegate(table, "cellSizeForTable", ret); + ok = callJSDelegate(table, "cellSizeForTable", &ret); } if (ok) { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); + Size size; bool isSucceed = jsval_to_ccsize(cx, ret, &size); if (isSucceed) return size; @@ -286,15 +289,15 @@ class JSB_TableViewDataSource virtual TableViewCell* tableCellAtIndex(TableView *table, ssize_t idx) override { - jsval ret; - bool ok = callJSDelegate(table, idx, "tableCellAtIndex", ret); + JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); + JS::RootedValue ret(cx); + bool ok = callJSDelegate(table, idx, "tableCellAtIndex", &ret); if (ok) { - JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); cocos2d::extension::TableViewCell* arg0; do { js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(ret); + JSObject *tmpObj = ret.toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); arg0 = (cocos2d::extension::TableViewCell*)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( arg0, cx, NULL, "Invalid Native Object"); @@ -306,11 +309,11 @@ class JSB_TableViewDataSource virtual ssize_t numberOfCellsInTableView(TableView *table) override { - jsval ret; - bool ok = callJSDelegate(table, "numberOfCellsInTableView", ret); + JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); + JS::RootedValue ret(cx); + bool ok = callJSDelegate(table, "numberOfCellsInTableView", &ret); if (ok) { - JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); ssize_t count = 0; bool isSucceed = jsval_to_ssize(cx, ret, &count); if (isSucceed) return count; @@ -329,12 +332,12 @@ class JSB_TableViewDataSource { _needUnroot = true; JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_AddNamedObjectRoot(cx, &_JSTableViewDataSource, "TableViewDataSource"); + JS::AddNamedObjectRoot(cx, &_JSTableViewDataSource, "TableViewDataSource"); } } private: - bool callJSDelegate(TableView* table, std::string jsFunctionName, jsval& retVal) + bool callJSDelegate(TableView* table, std::string jsFunctionName, JS::MutableHandleValue retVal) { js_proxy_t * p = jsb_get_native_proxy(table); if (!p) return false; @@ -345,7 +348,7 @@ class JSB_TableViewDataSource JS::RootedValue temp_retval(cx); jsval dataVal = OBJECT_TO_JSVAL(p->obj); - JSObject* obj = _JSTableViewDataSource; + JS::RootedObject obj(cx, _JSTableViewDataSource); JSAutoCompartment ac(cx, obj); if (JS_HasProperty(cx, obj, jsFunctionName.c_str(), &hasAction) && hasAction) @@ -360,13 +363,13 @@ class JSB_TableViewDataSource } JS_CallFunctionName(cx, obj, jsFunctionName.c_str(), - 1, &dataVal, &retVal); + JS::HandleValueArray::fromMarkedLocation(1, &dataVal), retVal); return true; } return false; } - bool callJSDelegate(TableView* table, ssize_t idx, std::string jsFunctionName, jsval& retVal) + bool callJSDelegate(TableView* table, ssize_t idx, std::string jsFunctionName, JS::MutableHandleValue retVal) { js_proxy_t * p = jsb_get_native_proxy(table); if (!p) return false; @@ -378,7 +381,7 @@ class JSB_TableViewDataSource dataVal[0] = OBJECT_TO_JSVAL(p->obj); dataVal[1] = ssize_to_jsval(cx,idx); - JSObject* obj = _JSTableViewDataSource; + JS::RootedObject obj(cx, _JSTableViewDataSource); JSAutoCompartment ac(cx, obj); if (JS_HasProperty(cx, obj, jsFunctionName.c_str(), &hasAction) && hasAction) @@ -394,20 +397,20 @@ class JSB_TableViewDataSource } bool ret = JS_CallFunctionName(cx, obj, jsFunctionName.c_str(), - 2, dataVal, &retVal); + JS::HandleValueArray::fromMarkedLocation(2, dataVal), retVal); return ret == true ? true : false; } return false; } private: - JSObject* _JSTableViewDataSource; + JS::Heap _JSTableViewDataSource; bool _needUnroot; }; static bool js_cocos2dx_CCTableView_setDataSource(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); @@ -415,7 +418,7 @@ static bool js_cocos2dx_CCTableView_setDataSource(JSContext *cx, uint32_t argc, if (argc == 1) { JSB_TableViewDataSource* pNativeSource = new JSB_TableViewDataSource(); - pNativeSource->setTableViewDataSource(JSVAL_TO_OBJECT(argv[0])); + pNativeSource->setTableViewDataSource(args.get(0).toObjectOrNull()); __Dictionary* userDict = static_cast<__Dictionary*>(cobj->getUserObject()); if (NULL == userDict) @@ -431,7 +434,7 @@ static bool js_cocos2dx_CCTableView_setDataSource(JSContext *cx, uint32_t argc, pNativeSource->release(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -441,16 +444,16 @@ static bool js_cocos2dx_CCTableView_setDataSource(JSContext *cx, uint32_t argc, static bool js_cocos2dx_CCTableView_create(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 3 || argc == 2) { JSB_TableViewDataSource* pNativeSource = new JSB_TableViewDataSource(); - pNativeSource->setTableViewDataSource(JSVAL_TO_OBJECT(argv[0])); + pNativeSource->setTableViewDataSource(args.get(0).toObjectOrNull()); cocos2d::Size arg1; - ok &= jsval_to_ccsize(cx, argv[1], &arg1); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); cocos2d::extension::TableView* ret = NULL; ret = new TableView(); ret->autorelease(); @@ -480,7 +483,7 @@ static bool js_cocos2dx_CCTableView_create(JSContext *cx, uint32_t argc, jsval * do { js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::Node*)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -497,7 +500,7 @@ static bool js_cocos2dx_CCTableView_create(JSContext *cx, uint32_t argc, jsval * pNativeSource->release(); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -507,7 +510,7 @@ static bool js_cocos2dx_CCTableView_create(JSContext *cx, uint32_t argc, jsval * static bool js_cocos2dx_CCTableView_init(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); @@ -517,11 +520,11 @@ static bool js_cocos2dx_CCTableView_init(JSContext *cx, uint32_t argc, jsval *vp { JSB_TableViewDataSource* pNativeSource = new JSB_TableViewDataSource(); - pNativeSource->setTableViewDataSource(JSVAL_TO_OBJECT(argv[0])); + pNativeSource->setTableViewDataSource(args.get(0).toObjectOrNull()); cobj->setDataSource(pNativeSource); cocos2d::Size arg1; - ok &= jsval_to_ccsize(cx, argv[1], &arg1); + ok &= jsval_to_ccsize(cx, args.get(1), &arg1); if (argc == 2) { @@ -533,7 +536,7 @@ static bool js_cocos2dx_CCTableView_init(JSContext *cx, uint32_t argc, jsval *vp do { js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[2]); + JSObject *tmpObj = args.get(2).toObjectOrNull(); proxy = jsb_get_js_proxy(tmpObj); arg2 = (cocos2d::Node*)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -550,7 +553,7 @@ static bool js_cocos2dx_CCTableView_init(JSContext *cx, uint32_t argc, jsval *vp pNativeSource->release(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -576,10 +579,10 @@ class JSB_ControlButtonTarget : public Ref JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); if (_needUnroot) { - JS_RemoveObjectRoot(cx, &_jsTarget); + JS::RemoveObjectRoot(cx, &_jsTarget); } - JS_RemoveObjectRoot(cx, &_jsFunc); + JS::RemoveObjectRoot(cx, &_jsFunc); for (auto iter = _jsNativeTargetMap.begin(); iter != _jsNativeTargetMap.end(); ++iter) { @@ -605,9 +608,11 @@ class JSB_ControlButtonTarget : public Ref dataVal[0] = OBJECT_TO_JSVAL(p->obj); int arg1 = (int)event; dataVal[1] = INT_TO_JSVAL(arg1); - jsval jsRet; - ScriptingCore::getInstance()->executeJSFunctionWithThisObj(OBJECT_TO_JSVAL(_jsTarget), OBJECT_TO_JSVAL(_jsFunc), 2, dataVal, &jsRet); + JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); + JS::RootedValue jsRet(cx); + + ScriptingCore::getInstance()->executeJSFunctionWithThisObj(JS::RootedValue(cx, OBJECT_TO_JSVAL(_jsTarget)), JS::RootedValue(cx, OBJECT_TO_JSVAL(_jsFunc)), JS::HandleValueArray::fromMarkedLocation(2, dataVal), &jsRet); } void setJSTarget(JSObject* pJSTarget) @@ -618,7 +623,7 @@ class JSB_ControlButtonTarget : public Ref if (!p) { JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_AddNamedObjectRoot(cx, &_jsTarget, "JSB_ControlButtonTarget, target"); + JS::AddNamedObjectRoot(cx, &_jsTarget, "JSB_ControlButtonTarget, target"); _needUnroot = true; } } @@ -628,7 +633,7 @@ class JSB_ControlButtonTarget : public Ref _jsFunc = jsFunc; JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_AddNamedObjectRoot(cx, &_jsFunc, "JSB_ControlButtonTarget, func"); + JS::AddNamedObjectRoot(cx, &_jsFunc, "JSB_ControlButtonTarget, func"); } void setEventType(Control::EventType type) @@ -638,10 +643,10 @@ class JSB_ControlButtonTarget : public Ref public: static std::multimap _jsNativeTargetMap; - JSObject* _jsFunc; + JS::Heap _jsFunc; Control::EventType _type; private: - JSObject* _jsTarget; + JS::Heap _jsTarget; bool _needUnroot; }; @@ -649,7 +654,7 @@ std::multimap JSB_ControlButtonTarget::_jsN static bool js_cocos2dx_CCControl_addTargetWithActionForControlEvents(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); @@ -658,10 +663,10 @@ static bool js_cocos2dx_CCControl_addTargetWithActionForControlEvents(JSContext bool ok = true; if (argc == 3) { - JSObject* jsDelegate = JSVAL_TO_OBJECT(argv[0]); - JSObject* jsFunc = JSVAL_TO_OBJECT(argv[1]); + JSObject* jsDelegate = args.get(0).toObjectOrNull(); + JSObject* jsFunc = args.get(1).toObjectOrNull(); Control::EventType arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); JSB_PRECONDITION2(ok, cx, false, "Error processing control event"); // Check whether the target already exists. @@ -671,7 +676,7 @@ static bool js_cocos2dx_CCControl_addTargetWithActionForControlEvents(JSContext if (it->second->_jsFunc == jsFunc && arg2 == it->second->_type) { // Return true directly. - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } @@ -699,7 +704,7 @@ static bool js_cocos2dx_CCControl_addTargetWithActionForControlEvents(JSContext JSB_ControlButtonTarget::_jsNativeTargetMap.insert(std::make_pair(jsDelegate, nativeDelegate)); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -709,7 +714,7 @@ static bool js_cocos2dx_CCControl_addTargetWithActionForControlEvents(JSContext static bool js_cocos2dx_CCControl_removeTargetWithActionForControlEvents(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); @@ -719,11 +724,11 @@ static bool js_cocos2dx_CCControl_removeTargetWithActionForControlEvents(JSConte if (argc == 3) { Control::EventType arg2; - ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); + ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2); JSB_PRECONDITION2(ok, cx, false, "Error processing control event"); - obj = JSVAL_TO_OBJECT(argv[0]); - JSObject* jsFunc = JSVAL_TO_OBJECT(argv[1]); + obj = args.get(0).toObjectOrNull(); + JSObject* jsFunc = args.get(1).toObjectOrNull(); JSB_ControlButtonTarget* nativeTargetToRemoved = nullptr; @@ -903,32 +908,37 @@ bool js_cocos2dx_ext_release(JSContext *cx, uint32_t argc, jsval *vp) } -__JSDownloaderDelegator::__JSDownloaderDelegator(JSContext *cx, JSObject *obj, const std::string &url, const jsval &callback) +__JSDownloaderDelegator::__JSDownloaderDelegator(JSContext *cx, JS::HandleObject obj, const std::string &url, JS::HandleValue callback) : _cx(cx) -, _obj(obj) , _url(url) -, _jsCallback(callback) , _buffer(nullptr) { - _downloader = std::make_shared(); - _downloader->setConnectionTimeout(8); - _downloader->setErrorCallback( std::bind(&__JSDownloaderDelegator::onError, this, std::placeholders::_1) ); - _downloader->setSuccessCallback( std::bind(&__JSDownloaderDelegator::onSuccess, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3) ); - - JSContext *globalCx = ScriptingCore::getInstance()->getGlobalContext(); - if (!JSVAL_IS_NULL(_jsCallback)) { - JS_AddNamedValueRoot(globalCx, &_jsCallback, "JSB_DownloadDelegator_jsCallback"); - } + _obj.construct(_cx); + _obj.ref().set(obj); + _jsCallback.construct(_cx); + _jsCallback.ref().set(callback); - long contentSize = _downloader->getContentSize(_url); - if (contentSize == -1) { - cocos2d::extension::Downloader::Error err; - onError(err); + if (Director::getInstance()->getTextureCache()->getTextureForKey(_url)) + { + onSuccess(nullptr, nullptr, nullptr); } - else { - _size = contentSize / sizeof(unsigned char); - _buffer = (unsigned char*)malloc(contentSize); - _downloader->downloadToBufferAsync(_url, _buffer, _size); + else + { + _downloader = std::make_shared(); + _downloader->setConnectionTimeout(8); + _downloader->setErrorCallback( std::bind(&__JSDownloaderDelegator::onError, this, std::placeholders::_1) ); + _downloader->setSuccessCallback( std::bind(&__JSDownloaderDelegator::onSuccess, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3) ); + + long contentSize = _downloader->getContentSize(_url); + if (contentSize == -1) { + cocos2d::extension::Downloader::Error err; + onError(err); + } + else { + _size = contentSize / sizeof(unsigned char); + _buffer = (unsigned char*)malloc(contentSize); + _downloader->downloadToBufferSync(_url, _buffer, _size); + } } } @@ -942,19 +952,15 @@ __JSDownloaderDelegator::~__JSDownloaderDelegator() void __JSDownloaderDelegator::onError(const cocos2d::extension::Downloader::Error &error) { - if (!JSVAL_IS_NULL(_jsCallback)) { + if (!_jsCallback.ref().isNull()) { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JSObject *global = ScriptingCore::getInstance()->getGlobalObject(); + JS::RootedObject global(cx, ScriptingCore::getInstance()->getGlobalObject()); - JSAutoCompartment ac(_cx, _obj); + JSAutoCompartment ac(_cx, _obj.ref()); jsval succeed = BOOLEAN_TO_JSVAL(false); - jsval retval; - JS_AddValueRoot(cx, &succeed); - JS_CallFunctionValue(cx, global, _jsCallback, 1, &succeed, &retval); - JS_RemoveValueRoot(cx, &succeed); - - JS_RemoveValueRoot(cx, &_jsCallback); + JS::RootedValue retval(cx); + JS_CallFunctionValue(cx, global, _jsCallback.ref(), JS::HandleValueArray::fromMarkedLocation(1, &succeed), &retval); } this->release(); } @@ -964,21 +970,28 @@ void __JSDownloaderDelegator::onSuccess(const std::string &srcUrl, const std::st Image *image = new Image(); jsval valArr[2]; JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JSObject *global = ScriptingCore::getInstance()->getGlobalObject(); + JS::RootedObject global(cx, ScriptingCore::getInstance()->getGlobalObject()); + cocos2d::TextureCache *cache = Director::getInstance()->getTextureCache(); - JSAutoCompartment ac(_cx, _obj); + JSAutoCompartment ac(_cx, _obj.ref() ? _obj.ref() : global); - if(image->initWithImageData(_buffer, _size)) + Texture2D *tex = cache->getTextureForKey(_url); + if (tex) { - Texture2D *tex = Director::getInstance()->getTextureCache()->addImage(image, srcUrl); + valArr[0] = BOOLEAN_TO_JSVAL(true); + js_proxy_t* p = jsb_get_native_proxy(tex); + valArr[1] = OBJECT_TO_JSVAL(p->obj); + } + else if (image->initWithImageData(_buffer, _size)) + { + tex = Director::getInstance()->getTextureCache()->addImage(image, _url); valArr[0] = BOOLEAN_TO_JSVAL(true); - js_type_class_t *classType = js_get_type_from_native(tex); - assert(classType); - JSObject *obj = JS_NewObject(cx, classType->jsclass, classType->proto, classType->parentProto); + JS::RootedObject texProto(cx, jsb_cocos2d_Texture2D_prototype); + JSObject *obj = JS_NewObject(cx, jsb_cocos2d_Texture2D_class, texProto, global); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(tex, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Texture2D"); + JS::AddNamedObjectRoot(cx, &p->obj, "cocos2d::Texture2D"); valArr[1] = OBJECT_TO_JSVAL(p->obj); } else @@ -989,37 +1002,36 @@ void __JSDownloaderDelegator::onSuccess(const std::string &srcUrl, const std::st image->release(); - if (!JSVAL_IS_NULL(_jsCallback)) { - jsval retval; - JS_AddValueRoot(cx, valArr); - JS_CallFunctionValue(cx, global, _jsCallback, 2, valArr, &retval); - JS_RemoveValueRoot(cx, valArr); - - JS_RemoveValueRoot(cx, &_jsCallback); + if (!_jsCallback.ref().isNull()) { + JS::RootedValue retval(cx); + JS_CallFunctionValue(cx, global, _jsCallback.ref(), JS::HandleValueArray::fromMarkedLocation(2, valArr), &retval); } this->release(); } -void __JSDownloaderDelegator::download(JSContext *cx, JSObject *obj, const std::string &url, const jsval &callback) +void __JSDownloaderDelegator::download(JSContext *cx, JS::HandleObject obj, const std::string &url, JS::HandleValue callback) { - new __JSDownloaderDelegator(cx, obj, url, callback); + auto t = std::thread([cx, obj, url, callback]() { + new __JSDownloaderDelegator(cx, obj, url, callback); + }); + t.detach(); } // jsb.loadRemoteImg(url, function(succeed, result) {}) bool js_load_remote_image(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, JS_THIS_OBJECT(cx, vp)); if (argc == 2) { std::string url; - bool ok = jsval_to_std_string(cx, argv[0], &url); - jsval callback = argv[1]; + bool ok = jsval_to_std_string(cx, args.get(0), &url); + JS::RootedValue callback(cx, args.get(1)); __JSDownloaderDelegator::download(cx, obj, url, callback); JSB_PRECONDITION2(ok, cx, false, "js_console_log : Error processing arguments"); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1033,29 +1045,38 @@ extern JSObject* jsb_cocos2d_extension_Control_prototype; extern JSObject* jsb_cocos2d_extension_AssetsManagerEx_prototype; extern JSObject* jsb_cocos2d_extension_Manifest_prototype; -void register_all_cocos2dx_extension_manual(JSContext* cx, JSObject* global) +void register_all_cocos2dx_extension_manual(JSContext* cx, JS::HandleObject global) { - JS_DefineFunction(cx, jsb_cocos2d_extension_AssetsManagerEx_prototype, "retain", js_cocos2dx_ext_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_extension_AssetsManagerEx_prototype, "release", js_cocos2dx_ext_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_extension_Manifest_prototype, "retain", js_cocos2dx_ext_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_extension_Manifest_prototype, "release", js_cocos2dx_ext_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS::RootedObject ccObj(cx); + JS::RootedValue tmpVal(cx); + JS::RootedObject tmpObj(cx); + get_or_create_js_obj(cx, global, "cc", &ccObj); + + JS::RootedObject am(cx, jsb_cocos2d_extension_AssetsManagerEx_prototype); + JS_DefineFunction(cx, am, "retain", js_cocos2dx_ext_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, am, "release", js_cocos2dx_ext_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS::RootedObject manifest(cx, jsb_cocos2d_extension_Manifest_prototype); + JS_DefineFunction(cx, manifest, "retain", js_cocos2dx_ext_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, manifest, "release", js_cocos2dx_ext_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); //JS_DefineFunction(cx, jsb_cocos2d_extension_AssetsManager_prototype, "updateAssets", js_cocos2dx_ext_AssetsManager_updateAssets, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); //JS_DefineFunction(cx, jsb_cocos2d_extension_AssetsManager_prototype, "getFailedAssets", js_cocos2dx_ext_AssetsManager_getFailedAssets, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_extension_ScrollView_prototype, "setDelegate", js_cocos2dx_CCScrollView_setDelegate, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_extension_TableView_prototype, "setDelegate", js_cocos2dx_CCTableView_setDelegate, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_extension_TableView_prototype, "setDataSource", js_cocos2dx_CCTableView_setDataSource, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_extension_TableView_prototype, "_init", js_cocos2dx_CCTableView_init, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_extension_Control_prototype, "addTargetWithActionForControlEvents", js_cocos2dx_CCControl_addTargetWithActionForControlEvents, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_extension_Control_prototype, "removeTargetWithActionForControlEvents", js_cocos2dx_CCControl_removeTargetWithActionForControlEvents, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_extension_ScrollView_prototype), "setDelegate", js_cocos2dx_CCScrollView_setDelegate, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS::RootedObject tableview(cx, jsb_cocos2d_extension_TableView_prototype); + JS_DefineFunction(cx, tableview, "setDelegate", js_cocos2dx_CCTableView_setDelegate, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tableview, "setDataSource", js_cocos2dx_CCTableView_setDataSource, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tableview, "_init", js_cocos2dx_CCTableView_init, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS::RootedObject control(cx, jsb_cocos2d_extension_Control_prototype); + JS_DefineFunction(cx, control, "addTargetWithActionForControlEvents", js_cocos2dx_CCControl_addTargetWithActionForControlEvents, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, control, "removeTargetWithActionForControlEvents", js_cocos2dx_CCControl_removeTargetWithActionForControlEvents, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JSObject *tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.TableView; })()")); + JS_GetProperty(cx, ccObj, "TableView", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCTableView_create, 3, JSPROP_READONLY | JSPROP_PERMANENT); - JS::RootedObject jsbObj(cx); - create_js_root_obj(cx, global, "jsb", &jsbObj); + get_or_create_js_obj(cx, global, "jsb", &jsbObj); JS_DefineFunction(cx, jsbObj, "loadRemoteImg", js_load_remote_image, 2, JSPROP_READONLY | JSPROP_PERMANENT); } \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/manual/extension/jsb_cocos2dx_extension_manual.h b/frameworks/js-bindings/bindings/manual/extension/jsb_cocos2dx_extension_manual.h index c3d97a1b39..29cd76e94b 100644 --- a/frameworks/js-bindings/bindings/manual/extension/jsb_cocos2dx_extension_manual.h +++ b/frameworks/js-bindings/bindings/manual/extension/jsb_cocos2dx_extension_manual.h @@ -26,29 +26,30 @@ #include "jsapi.h" #include "jsfriendapi.h" +#include "mozilla/Maybe.h" #include "extensions/assets-manager/Downloader.h" class __JSDownloaderDelegator : cocos2d::Ref { public: - static void download(JSContext *cx, JSObject *obj, const std::string &url, const jsval &callback); + static void download(JSContext *cx, JS::HandleObject obj, const std::string &url, JS::HandleValue callback); protected: - __JSDownloaderDelegator(JSContext *cx, JSObject *obj, const std::string &url, const jsval &callback); + __JSDownloaderDelegator(JSContext *cx, JS::HandleObject obj, const std::string &url, JS::HandleValue callback); ~__JSDownloaderDelegator(); private: void onSuccess(const std::string &srcUrl, const std::string &storagePath, const std::string &customId); void onError(const cocos2d::extension::Downloader::Error &error); - jsval _jsCallback; unsigned char *_buffer; long _size; std::shared_ptr _downloader; std::string _url; JSContext *_cx; - JSObject *_obj; + mozilla::Maybe _jsCallback; + mozilla::Maybe _obj; }; -void register_all_cocos2dx_extension_manual(JSContext* cx, JSObject* global); +void register_all_cocos2dx_extension_manual(JSContext* cx, JS::HandleObject global); #endif /* defined(__jsb_cocos2dx_extension_manual__) */ diff --git a/frameworks/js-bindings/bindings/manual/js_bindings_core.cpp b/frameworks/js-bindings/bindings/manual/js_bindings_core.cpp index 5ef7221a38..be2fbc2264 100644 --- a/frameworks/js-bindings/bindings/manual/js_bindings_core.cpp +++ b/frameworks/js-bindings/bindings/manual/js_bindings_core.cpp @@ -159,6 +159,7 @@ void jsb_set_c_proxy_for_jsobject( JSObject *jsobj, void *handle, unsigned long bool JSB_do_nothing(JSContext *cx, uint32_t argc, jsval *vp) { - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setUndefined(); return true; } diff --git a/frameworks/js-bindings/bindings/manual/js_bindings_core.h b/frameworks/js-bindings/bindings/manual/js_bindings_core.h index e474a444a2..4669b2ab5a 100644 --- a/frameworks/js-bindings/bindings/manual/js_bindings_core.h +++ b/frameworks/js-bindings/bindings/manual/js_bindings_core.h @@ -42,7 +42,7 @@ extern "C" { struct jsb_c_proxy_s { unsigned long flags; // Should it be removed at "destructor" time, or not ? void *handle; // native object, like cpSpace, cpBody, etc. - JSObject *jsobj; // JS Object. Needed for rooting / unrooting + JS::Heap jsobj; // JS Object. Needed for rooting / unrooting }; // Functions for setting / removing / getting the proxy used by the "C" Object Oriented API. Think of Chipmunk classes diff --git a/frameworks/js-bindings/bindings/manual/js_bindings_opengl.cpp b/frameworks/js-bindings/bindings/manual/js_bindings_opengl.cpp index af8f50ed35..0a795eb802 100644 --- a/frameworks/js-bindings/bindings/manual/js_bindings_opengl.cpp +++ b/frameworks/js-bindings/bindings/manual/js_bindings_opengl.cpp @@ -37,7 +37,8 @@ void GLNode::onDraw(Mat4 &transform, uint32_t flags) proxy = js_get_or_create_proxy(cx, this); if( proxy ) { - JSObject *jsObj = proxy->obj; +// JSObject *jsObj = proxy->obj; + JS::RootedObject jsObj(cx, proxy->obj.get()); if (jsObj) { bool found = false; JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET @@ -50,10 +51,9 @@ void GLNode::onDraw(Mat4 &transform, uint32_t flags) JS::RootedValue rval(cx); JS::RootedValue fval(cx); - jsval *argv = NULL; unsigned argc=0; - JS_GetProperty(cx, jsObj, "draw", &fval); - JS_CallFunctionValue(cx, jsObj, fval, argc, argv, rval.address()); + + JS_CallFunctionValue(cx, jsObj, fval, JS::HandleValueArray::empty(), &rval); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } @@ -85,12 +85,13 @@ bool js_cocos2dx_GLNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + JSObject *obj = JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t *p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::GLNode"); + JS::AddNamedObjectRoot(cx, &p->obj, "cocos2d::GLNode"); return true; } @@ -107,13 +108,15 @@ static bool js_cocos2dx_GLNode_ctor(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::GLNode *nobj = new cocos2d::GLNode(); js_proxy_t* p = jsb_new_proxy(nobj, obj); nobj->autorelease(); - JS_AddNamedObjectRoot(cx, &p->obj, "GLNode"); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + JS::AddNamedObjectRoot(cx, &p->obj, "GLNode"); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setUndefined(); return true; } bool js_cocos2dx_GLNode_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cocos2d::GLNode* ret = new cocos2d::GLNode(); jsval jsret; do { @@ -124,13 +127,13 @@ bool js_cocos2dx_GLNode_create(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } extern JSObject* jsb_cocos2d_Node_prototype; -void js_register_cocos2dx_GLNode(JSContext *cx, JSObject *global) { +void js_register_cocos2dx_GLNode(JSContext *cx, JS::HandleObject global) { js_cocos2dx_GLNode_class = (JSClass *)calloc(1, sizeof(JSClass)); js_cocos2dx_GLNode_class->name = "GLNode"; js_cocos2dx_GLNode_class->addProperty = JS_PropertyStub; @@ -159,7 +162,7 @@ void js_register_cocos2dx_GLNode(JSContext *cx, JSObject *global) { js_cocos2dx_GLNode_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), js_cocos2dx_GLNode_class, js_cocos2dx_GLNode_constructor, 0, // constructor properties, diff --git a/frameworks/js-bindings/bindings/manual/js_bindings_opengl.h b/frameworks/js-bindings/bindings/manual/js_bindings_opengl.h index 11788eb533..061cecf5d3 100644 --- a/frameworks/js-bindings/bindings/manual/js_bindings_opengl.h +++ b/frameworks/js-bindings/bindings/manual/js_bindings_opengl.h @@ -36,4 +36,4 @@ class GLNode : public cocos2d::Node NS_CC_END -void js_register_cocos2dx_GLNode(JSContext *cx, JSObject *global); +void js_register_cocos2dx_GLNode(JSContext *cx, JS::HandleObject global); diff --git a/frameworks/js-bindings/bindings/manual/js_manual_conversions.cpp b/frameworks/js-bindings/bindings/manual/js_manual_conversions.cpp index d8a9753b62..3172edb002 100644 --- a/frameworks/js-bindings/bindings/manual/js_manual_conversions.cpp +++ b/frameworks/js-bindings/bindings/manual/js_manual_conversions.cpp @@ -50,7 +50,7 @@ JSStringWrapper::JSStringWrapper(jsval val, JSContext* cx/* = NULL*/) JSStringWrapper::~JSStringWrapper() { - CC_SAFE_DELETE_ARRAY(_buffer); + JS_free(ScriptingCore::getInstance()->getGlobalContext(), (void*)_buffer); } void JSStringWrapper::set(jsval val, JSContext* cx) @@ -75,9 +75,17 @@ void JSStringWrapper::set(JSString* str, JSContext* cx) } // JS_EncodeString isn't supported in SpiderMonkey ff19.0. //buffer = JS_EncodeString(cx, string); - unsigned short* pStrUTF16 = (unsigned short*)JS_GetStringCharsZ(cx, str); - - _buffer = cc_utf16_to_utf8(pStrUTF16, -1, NULL, NULL); + + //JS_GetStringCharsZ is removed in SpiderMonkey 33 +// unsigned short* pStrUTF16 = (unsigned short*)JS_GetStringCharsZ(cx, str); + +// _buffer = cc_utf16_to_utf8(pStrUTF16, -1, NULL, NULL); + +#if(CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + _buffer = JS_EncodeString(cx, str); +#else + _buffer = JS_EncodeStringToUTF8(cx, JS::RootedString(cx, str)); +#endif } const char* JSStringWrapper::get() @@ -91,24 +99,24 @@ JSFunctionWrapper::JSFunctionWrapper(JSContext* cx, JSObject *jsthis, jsval fval , _jsthis(jsthis) , _fval(fval) { - JS_AddNamedValueRoot(cx, &this->_fval, "JSFunctionWrapper"); - JS_AddNamedObjectRoot(cx, &this->_jsthis, "JSFunctionWrapper"); + JS::AddNamedValueRoot(cx, &this->_fval, "JSFunctionWrapper"); + JS::AddNamedObjectRoot(cx, &this->_jsthis, "JSFunctionWrapper"); } JSFunctionWrapper::~JSFunctionWrapper() { - JS_RemoveValueRoot(this->_cx, &this->_fval); - JS_RemoveObjectRoot(this->_cx, &this->_jsthis); + JS::RemoveValueRoot(this->_cx, &this->_fval); + JS::RemoveObjectRoot(this->_cx, &this->_jsthis); } -bool JSFunctionWrapper::invoke(unsigned int argc, jsval *argv, jsval &rval) +bool JSFunctionWrapper::invoke(unsigned int argc, jsval *argv, JS::MutableHandleValue rval) { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - return JS_CallFunctionValue(this->_cx, this->_jsthis, this->_fval, argc, argv, &rval); + return JS_CallFunctionValue(this->_cx, JS::RootedObject(_cx, this->_jsthis.get()), JS::RootedValue(_cx, this->_fval.get()), JS::HandleValueArray::fromMarkedLocation(argc, argv), rval); } -static Color3B getColorFromJSObject(JSContext *cx, JSObject *colorObject) +static Color3B getColorFromJSObject(JSContext *cx, JS::HandleObject colorObject) { JS::RootedValue jsr(cx); Color3B out; @@ -132,7 +140,7 @@ static Color3B getColorFromJSObject(JSContext *cx, JSObject *colorObject) return out; } -static Size getSizeFromJSObject(JSContext *cx, JSObject *sizeObject) +static Size getSizeFromJSObject(JSContext *cx, JS::HandleObject sizeObject) { JS::RootedValue jsr(cx); Size out; @@ -152,13 +160,13 @@ static Size getSizeFromJSObject(JSContext *cx, JSObject *sizeObject) return out; } -bool jsval_to_opaque( JSContext *cx, jsval vp, void **r) +bool jsval_to_opaque( JSContext *cx, JS::HandleValue vp, void **r) { #ifdef __LP64__ // begin JS::RootedObject tmp_arg(cx); - bool ok = JS_ValueToObject( cx, JS::RootedValue(cx, vp), &tmp_arg ); + bool ok = JS_ValueToObject( cx, vp, &tmp_arg ); JSB_PRECONDITION2( ok, cx, false, "Error converting value to object"); JSB_PRECONDITION2( tmp_arg && JS_IsTypedArrayObject( tmp_arg ), cx, false, "Not a TypedArray object"); JSB_PRECONDITION2( JS_GetTypedArrayByteLength( tmp_arg ) == sizeof(void*), cx, false, "Invalid Typed Array length"); @@ -178,7 +186,7 @@ bool jsval_to_opaque( JSContext *cx, jsval vp, void **r) return true; } -bool jsval_to_int( JSContext *cx, jsval vp, int *ret ) +bool jsval_to_int( JSContext *cx, JS::HandleValue vp, int *ret ) { // Since this is called to cast uint64 to uint32, // it is needed to initialize the value to 0 first @@ -205,13 +213,14 @@ jsval opaque_to_jsval( JSContext *cx, void *opaque ) #endif } -jsval c_class_to_jsval( JSContext *cx, void* handle, JSObject* object, JSClass *klass, const char* class_name) +jsval c_class_to_jsval( JSContext *cx, void* handle, JS::HandleObject object, JSClass *klass, const char* class_name) { - JSObject *jsobj; + JS::RootedObject jsobj(cx); jsobj = jsb_get_jsobject_for_proxy(handle); if( !jsobj ) { - jsobj = JS_NewObject(cx, klass, object, NULL); + JS::RootedObject parent(cx); + jsobj = JS_NewObject(cx, klass, object, parent); CCASSERT(jsobj, "Invalid object"); jsb_set_c_proxy_for_jsobject(jsobj, handle, JSB_C_FLAG_DO_NOT_CALL_FREE); jsb_set_jsobject_for_proxy(jsobj, handle); @@ -220,10 +229,10 @@ jsval c_class_to_jsval( JSContext *cx, void* handle, JSObject* object, JSClass * return OBJECT_TO_JSVAL(jsobj); } -bool jsval_to_c_class( JSContext *cx, jsval vp, void **out_native, struct jsb_c_proxy_s **out_proxy) +bool jsval_to_c_class( JSContext *cx, JS::HandleValue vp, void **out_native, struct jsb_c_proxy_s **out_proxy) { JS::RootedObject jsobj(cx); - bool ok = JS_ValueToObject( cx, JS::RootedValue(cx, vp), &jsobj ); + bool ok = JS_ValueToObject( cx, vp, &jsobj ); JSB_PRECONDITION2(ok, cx, false, "Error converting jsval to object"); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsobj); @@ -233,7 +242,7 @@ bool jsval_to_c_class( JSContext *cx, jsval vp, void **out_native, struct jsb_c_ return true; } -bool jsval_to_uint( JSContext *cx, jsval vp, unsigned int *ret ) +bool jsval_to_uint( JSContext *cx, JS::HandleValue vp, unsigned int *ret ) { // Since this is called to cast uint64 to uint32, // it is needed to initialize the value to 0 first @@ -292,13 +301,14 @@ jsval long_long_to_jsval( JSContext *cx, long long number ) #endif } -bool jsval_to_charptr( JSContext *cx, jsval vp, const char **ret ) +bool jsval_to_charptr( JSContext *cx, JS::HandleValue vp, const char **ret ) { - JSString *jsstr = JS::ToString( cx, JS::RootedValue(cx, vp) ); + JSString *jsstr = JS::ToString( cx, vp ); JSB_PRECONDITION2( jsstr, cx, false, "invalid string" ); + //XXX: what's this? // root it - vp = STRING_TO_JSVAL(jsstr); +// vp = STRING_TO_JSVAL(jsstr); JSStringWrapper strWrapper(jsstr); @@ -317,10 +327,10 @@ jsval charptr_to_jsval( JSContext *cx, const char *str) return c_string_to_jsval(cx, str); } -bool JSB_jsval_typedarray_to_dataptr( JSContext *cx, jsval vp, GLsizei *count, void **data, JSArrayBufferViewType t) +bool JSB_jsval_typedarray_to_dataptr( JSContext *cx, JS::HandleValue vp, GLsizei *count, void **data, js::Scalar::Type t) { JS::RootedObject jsobj(cx); - bool ok = JS_ValueToObject( cx, JS::RootedValue(cx, vp), &jsobj ); + bool ok = JS_ValueToObject( cx, vp, &jsobj ); JSB_PRECONDITION2( ok && jsobj, cx, false, "Error converting value to object"); // WebGL supports TypedArray and sequences for some of its APIs. So when converting a TypedArray, we should @@ -329,26 +339,26 @@ bool JSB_jsval_typedarray_to_dataptr( JSContext *cx, jsval vp, GLsizei *count, v if( JS_IsTypedArrayObject( jsobj ) ) { *count = JS_GetTypedArrayLength(jsobj); - JSArrayBufferViewType type = JS_GetArrayBufferViewType(jsobj); + js::Scalar::Type type = JS_GetArrayBufferViewType(jsobj); JSB_PRECONDITION2(t==type, cx, false, "TypedArray type different than expected type"); switch (t) { - case js::ArrayBufferView::TYPE_INT8: - case js::ArrayBufferView::TYPE_UINT8: + case js::Scalar::Int8: + case js::Scalar::Uint8: *data = JS_GetUint8ArrayData(jsobj); break; - case js::ArrayBufferView::TYPE_INT16: - case js::ArrayBufferView::TYPE_UINT16: + case js::Scalar::Int16: + case js::Scalar::Uint16: *data = JS_GetUint16ArrayData(jsobj); break; - case js::ArrayBufferView::TYPE_INT32: - case js::ArrayBufferView::TYPE_UINT32: + case js::Scalar::Int32: + case js::Scalar::Uint32: *data = JS_GetUint32ArrayData(jsobj); break; - case js::ArrayBufferView::TYPE_FLOAT32: + case js::Scalar::Float32: *data = JS_GetFloat32ArrayData(jsobj); break; @@ -368,16 +378,16 @@ bool JSB_jsval_typedarray_to_dataptr( JSContext *cx, jsval vp, GLsizei *count, v JS_GetElement(cx, jsobj, i, &valarg); switch(t) { - case js::ArrayBufferView::TYPE_INT32: - case js::ArrayBufferView::TYPE_UINT32: + case js::Scalar::Int32: + case js::Scalar::Uint32: { - uint32_t e = JSVAL_TO_INT(valarg); + uint32_t e = valarg.toInt32(); ((uint32_t*)data)[i] = e; break; } - case js::ArrayBufferView::TYPE_FLOAT32: + case js::Scalar::Float32: { - double e = JSVAL_TO_DOUBLE(valarg); + double e = valarg.toNumber(); ((GLfloat*)data)[i] = (GLfloat)e; break; } @@ -393,10 +403,10 @@ bool JSB_jsval_typedarray_to_dataptr( JSContext *cx, jsval vp, GLsizei *count, v return true; } -bool JSB_get_arraybufferview_dataptr( JSContext *cx, jsval vp, GLsizei *count, GLvoid **data ) +bool JSB_get_arraybufferview_dataptr( JSContext *cx, JS::HandleValue vp, GLsizei *count, GLvoid **data ) { JS::RootedObject jsobj(cx); - bool ok = JS_ValueToObject( cx, JS::RootedValue(cx, vp), &jsobj ); + bool ok = JS_ValueToObject( cx, vp, &jsobj ); JSB_PRECONDITION2( ok && jsobj, cx, false, "Error converting value to object"); JSB_PRECONDITION2( JS_IsArrayBufferViewObject(jsobj), cx, false, "Not an ArrayBufferView object"); @@ -408,11 +418,11 @@ bool JSB_get_arraybufferview_dataptr( JSContext *cx, jsval vp, GLsizei *count, G #pragma mark - Conversion Routines -bool jsval_to_ushort( JSContext *cx, jsval vp, unsigned short *outval ) +bool jsval_to_ushort( JSContext *cx, JS::HandleValue vp, unsigned short *outval ) { bool ok = true; double dp; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, vp), &dp); + ok &= JS::ToNumber(cx, vp, &dp); JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); ok &= !isnan(dp); JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); @@ -422,11 +432,11 @@ bool jsval_to_ushort( JSContext *cx, jsval vp, unsigned short *outval ) return ok; } -bool jsval_to_int32( JSContext *cx, jsval vp, int32_t *outval ) +bool jsval_to_int32( JSContext *cx, JS::HandleValue vp, int32_t *outval ) { bool ok = true; double dp; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, vp), &dp); + ok &= JS::ToNumber(cx, vp, &dp); JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); ok &= !isnan(dp); JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); @@ -436,11 +446,11 @@ bool jsval_to_int32( JSContext *cx, jsval vp, int32_t *outval ) return ok; } -bool jsval_to_uint32( JSContext *cx, jsval vp, uint32_t *outval ) +bool jsval_to_uint32( JSContext *cx, JS::HandleValue vp, uint32_t *outval ) { bool ok = true; double dp; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, vp), &dp); + ok &= JS::ToNumber(cx, vp, &dp); JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); ok &= !isnan(dp); JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); @@ -450,11 +460,11 @@ bool jsval_to_uint32( JSContext *cx, jsval vp, uint32_t *outval ) return ok; } -bool jsval_to_uint16( JSContext *cx, jsval vp, uint16_t *outval ) +bool jsval_to_uint16( JSContext *cx, JS::HandleValue vp, uint16_t *outval ) { bool ok = true; double dp; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, vp), &dp); + ok &= JS::ToNumber(cx, vp, &dp); JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); ok &= !isnan(dp); JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); @@ -465,12 +475,12 @@ bool jsval_to_uint16( JSContext *cx, jsval vp, uint16_t *outval ) } // XXX: sizeof(long) == 8 in 64 bits on OS X... apparently on Windows it is 32 bits (???) -bool jsval_to_long( JSContext *cx, jsval vp, long *r ) +bool jsval_to_long( JSContext *cx, JS::HandleValue vp, long *r ) { #ifdef __LP64__ // compatibility check assert( sizeof(long)==8); - JSString *jsstr = JS::ToString(cx, JS::RootedValue(cx, vp)); + JSString *jsstr = JS::ToString(cx, vp); JSB_PRECONDITION2(jsstr, cx, false, "Error converting value to string"); char *str = JS_EncodeString(cx, jsstr); @@ -485,7 +495,7 @@ bool jsval_to_long( JSContext *cx, jsval vp, long *r ) #else // compatibility check assert( sizeof(int)==4); - long ret = JSVAL_TO_INT(vp); + long ret = vp.toInt32(); #endif *r = ret; @@ -493,7 +503,7 @@ bool jsval_to_long( JSContext *cx, jsval vp, long *r ) } -bool jsval_to_ulong( JSContext *cx, jsval vp, unsigned long *out) +bool jsval_to_ulong( JSContext *cx, JS::HandleValue vp, unsigned long *out) { if (out == nullptr) return false; @@ -508,39 +518,46 @@ bool jsval_to_ulong( JSContext *cx, jsval vp, unsigned long *out) return ret; } -bool jsval_to_long_long(JSContext *cx, jsval vp, long long* r) +bool jsval_to_long_long(JSContext *cx, JS::HandleValue vp, long long* r) { - JS::RootedObject tmp_arg(cx); - bool ok = JS_ValueToObject( cx, JS::RootedValue(cx, vp), &tmp_arg ); - JSB_PRECONDITION3( ok, cx, false, "Error converting value to object"); - JSB_PRECONDITION3( tmp_arg && JS_IsTypedArrayObject( tmp_arg ), cx, false, "Not a TypedArray object"); - JSB_PRECONDITION3( JS_GetTypedArrayByteLength( tmp_arg ) == sizeof(long long), cx, false, "Invalid Typed Array length"); + JSString *jsstr = JS::ToString(cx, vp); + JSB_PRECONDITION2(jsstr, cx, false, "Error converting value to string"); - uint32_t* arg_array = (uint32_t*)JS_GetArrayBufferViewData( tmp_arg ); - long long ret = arg_array[0]; - ret = ret << 32; - ret |= arg_array[1]; + char *str = JS_EncodeString(cx, jsstr); + JSB_PRECONDITION2(str, cx, false, "Error encoding string"); + + char *endptr; +#if(CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WP8) + __int64 ret = _strtoi64(str, &endptr, 10); +#else + long long ret = strtoll(str, &endptr, 10); +#endif *r = ret; return true; } -bool jsval_to_std_string(JSContext *cx, jsval v, std::string* ret) { - JSString *tmp = JS::ToString(cx, JS::RootedValue(cx, v)); - JSB_PRECONDITION3(tmp, cx, false, "Error processing arguments"); - - JSStringWrapper str(tmp); - *ret = str.get(); - return true; +bool jsval_to_std_string(JSContext *cx, JS::HandleValue v, std::string* ret) { + if(v.isString() || v.isNumber()) + { + JSString *tmp = JS::ToString(cx, v); + JSB_PRECONDITION3(tmp, cx, false, "Error processing arguments"); + + JSStringWrapper str(tmp); + *ret = str.get(); + return true; + } + + return false; } -bool jsval_to_ccpoint(JSContext *cx, jsval v, Point* ret) { +bool jsval_to_ccpoint(JSContext *cx, JS::HandleValue v, Point* ret) { JS::RootedObject tmp(cx); JS::RootedValue jsx(cx); JS::RootedValue jsy(cx); double x, y; bool ok = v.isObject() && - JS_ValueToObject(cx, JS::RootedValue(cx, v), &tmp) && + JS_ValueToObject(cx, v, &tmp) && JS_GetProperty(cx, tmp, "x", &jsx) && JS_GetProperty(cx, tmp, "y", &jsy) && JS::ToNumber(cx, jsx, &x) && @@ -553,7 +570,7 @@ bool jsval_to_ccpoint(JSContext *cx, jsval v, Point* ret) { return true; } -bool jsval_to_ccacceleration(JSContext* cx,jsval v, Acceleration* ret) { +bool jsval_to_ccacceleration(JSContext* cx, JS::HandleValue v, Acceleration* ret) { JS::RootedObject tmp(cx); JS::RootedValue jsx(cx); JS::RootedValue jsy(cx); @@ -562,7 +579,7 @@ bool jsval_to_ccacceleration(JSContext* cx,jsval v, Acceleration* ret) { double x, y, timestamp, z; bool ok = v.isObject() && - JS_ValueToObject(cx, JS::RootedValue(cx, v), &tmp) && + JS_ValueToObject(cx, v, &tmp) && JS_GetProperty(cx, tmp, "x", &jsx) && JS_GetProperty(cx, tmp, "y", &jsy) && JS_GetProperty(cx, tmp, "z", &jsz) && @@ -581,6 +598,99 @@ bool jsval_to_ccacceleration(JSContext* cx,jsval v, Acceleration* ret) { return true; } +bool jsval_to_quaternion( JSContext *cx, JS::HandleValue v, cocos2d::Quaternion* ret) +{ + JS::RootedObject tmp(cx); + JS::RootedValue x(cx); + JS::RootedValue y(cx); + JS::RootedValue z(cx); + JS::RootedValue w(cx); + + double xx, yy, zz, ww; + bool ok = v.isObject() && + JS_ValueToObject(cx, v, &tmp) && + JS_GetProperty(cx, tmp, "x", &x) && + JS_GetProperty(cx, tmp, "y", &y) && + JS_GetProperty(cx, tmp, "z", &z) && + JS_GetProperty(cx, tmp, "w", &w) && + JS::ToNumber(cx, x, &xx) && + JS::ToNumber(cx, y, &yy) && + JS::ToNumber(cx, z, &zz) && + JS::ToNumber(cx, w, &ww) && + !isnan(xx) && !isnan(yy) && !isnan(zz) && !isnan(ww); + + JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); + + ret->set(xx, yy, zz, ww); + + return true; +} + +bool jsval_to_obb(JSContext *cx, JS::HandleValue v, cocos2d::OBB* ret) +{ + JS::RootedObject tmp(cx); + JS::RootedValue jscenter(cx); + JS::RootedValue jsxAxis(cx); + JS::RootedValue jsyAxis(cx); + JS::RootedValue jszAxis(cx); + JS::RootedValue jsextents(cx); + JS::RootedValue jsextentx(cx); + JS::RootedValue jsextenty(cx); + JS::RootedValue jsextentz(cx); + + cocos2d::Vec3 center, xAxis, yAxis, zAxis, extents, extentx, extenty, extentz; + bool ok = v.isObject() && + JS_ValueToObject(cx, v, &tmp) && + JS_GetProperty(cx, tmp, "center", &jscenter) && + JS_GetProperty(cx, tmp, "xAxis", &jsxAxis) && + JS_GetProperty(cx, tmp, "yAxis", &jsyAxis) && + JS_GetProperty(cx, tmp, "zAxis", &jszAxis) && + JS_GetProperty(cx, tmp, "extents", &jsextents) && + JS_GetProperty(cx, tmp, "extentX", &jsextentx) && + JS_GetProperty(cx, tmp, "extentY", &jsextenty) && + JS_GetProperty(cx, tmp, "extentZ", &jsextentz) && + jsval_to_vector3(cx, jscenter, ¢er) && + jsval_to_vector3(cx, jsxAxis, &xAxis) && + jsval_to_vector3(cx, jsyAxis, &yAxis) && + jsval_to_vector3(cx, jszAxis, &zAxis) && + jsval_to_vector3(cx, jsextents, &extents) && + jsval_to_vector3(cx, jsextentx, &extentx) && + jsval_to_vector3(cx, jsextenty, &extenty) && + jsval_to_vector3(cx, jsextentz, &extentz); + + JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); + + ret->_center.set(center); + ret->_xAxis.set(xAxis); + ret->_yAxis.set(yAxis); + ret->_zAxis.set(zAxis); + ret->_extents.set(extents); + ret->_extentX.set(extentx); + ret->_extentY.set(extenty); + ret->_extentZ.set(extentz); + return true; +} + +bool jsval_to_ray(JSContext *cx, JS::HandleValue v, cocos2d::Ray* ret) +{ + JS::RootedObject tmp(cx); + JS::RootedValue jsorigin(cx); + JS::RootedValue jsdirection(cx); + + cocos2d::Vec3 origin, direction; + bool ok = v.isObject() && + JS_ValueToObject(cx, v, &tmp) && + JS_GetProperty(cx, tmp, "origin", &jsorigin) && + JS_GetProperty(cx, tmp, "direction", &jsdirection) && + jsval_to_vector3(cx, jsorigin, &origin) && + jsval_to_vector3(cx, jsdirection, &direction); + + JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); + + ret->set(origin, direction); + return true; +} + bool jsvals_variadic_to_ccarray( JSContext *cx, jsval *vp, int argc, __Array** ret) { bool ok = true; @@ -589,22 +699,22 @@ bool jsvals_variadic_to_ccarray( JSContext *cx, jsval *vp, int argc, __Array** r { double num = 0.0; // optimization: JS::ToNumber is expensive. And can convert an string like "12" to a number - if ( JSVAL_IS_NUMBER(*vp)) { + if (vp->isNumber()) { ok &= JS::ToNumber(cx, JS::RootedValue(cx, *vp), &num ); if (!ok) { break; } pArray->addObject(Integer::create((int)num)); } - else if (JSVAL_IS_STRING(*vp)) + else if (vp->isString()) { - JSStringWrapper str(JSVAL_TO_STRING(*vp), cx); + JSStringWrapper str(vp->toString(), cx); pArray->addObject(String::create(str.get())); } else { js_proxy_t* p; - JSObject* obj = JSVAL_TO_OBJECT(*vp); + JSObject* obj = vp->toObjectOrNull(); p = jsb_get_js_proxy(obj); if (p) { pArray->addObject((Ref*)p->ptr); @@ -620,13 +730,13 @@ bool jsvals_variadic_to_ccarray( JSContext *cx, jsval *vp, int argc, __Array** r bool jsvals_variadic_to_ccvaluevector( JSContext *cx, jsval *vp, int argc, cocos2d::ValueVector* ret) { - + JS::RootedValue value(cx); for (int i = 0; i < argc; i++) { - jsval value = *vp; + value = *vp; if (value.isObject()) { - JSObject* jsobj = JSVAL_TO_OBJECT(value); + JS::RootedObject jsobj(cx, value.toObjectOrNull()); CCASSERT(jsb_get_js_proxy(jsobj) == nullptr, "Native object should be added!"); if (!JS_IsArrayObject(cx, jsobj)) @@ -649,23 +759,23 @@ bool jsvals_variadic_to_ccvaluevector( JSContext *cx, jsval *vp, int argc, cocos } } } - else if (JSVAL_IS_STRING(value)) + else if (value.isString()) { - JSStringWrapper valueWapper(JSVAL_TO_STRING(value), cx); + JSStringWrapper valueWapper(value.toString(), cx); ret->push_back(Value(valueWapper.get())); } - else if (JSVAL_IS_NUMBER(value)) + else if (value.isNumber()) { double number = 0.0; - bool ok = JS::ToNumber(cx, JS::RootedValue(cx, value), &number); + bool ok = JS::ToNumber(cx, value, &number); if (ok) { ret->push_back(Value(number)); } } - else if (JSVAL_IS_BOOLEAN(value)) + else if (value.isBoolean()) { - bool boolVal = JS::ToBoolean(JS::RootedValue(cx, value)); + bool boolVal = JS::ToBoolean(value); ret->push_back(Value(boolVal)); } else @@ -679,7 +789,7 @@ bool jsvals_variadic_to_ccvaluevector( JSContext *cx, jsval *vp, int argc, cocos return true; } -bool jsval_to_ccrect(JSContext *cx, jsval v, Rect* ret) { +bool jsval_to_ccrect(JSContext *cx, JS::HandleValue v, Rect* ret) { JS::RootedObject tmp(cx); JS::RootedValue jsx(cx); JS::RootedValue jsy(cx); @@ -688,7 +798,7 @@ bool jsval_to_ccrect(JSContext *cx, jsval v, Rect* ret) { double x, y, width, height; bool ok = v.isObject() && - JS_ValueToObject(cx, JS::RootedValue(cx, v), &tmp) && + JS_ValueToObject(cx, v, &tmp) && JS_GetProperty(cx, tmp, "x", &jsx) && JS_GetProperty(cx, tmp, "y", &jsy) && JS_GetProperty(cx, tmp, "width", &jswidth) && @@ -707,13 +817,13 @@ bool jsval_to_ccrect(JSContext *cx, jsval v, Rect* ret) { return true; } -bool jsval_to_ccsize(JSContext *cx, jsval v, Size* ret) { +bool jsval_to_ccsize(JSContext *cx, JS::HandleValue v, Size* ret) { JS::RootedObject tmp(cx); JS::RootedValue jsw(cx); JS::RootedValue jsh(cx); double w, h; bool ok = v.isObject() && - JS_ValueToObject(cx, JS::RootedValue(cx, v), &tmp) && + JS_ValueToObject(cx, v, &tmp) && JS_GetProperty(cx, tmp, "width", &jsw) && JS_GetProperty(cx, tmp, "height", &jsh) && JS::ToNumber(cx, jsw, &w) && @@ -725,7 +835,7 @@ bool jsval_to_ccsize(JSContext *cx, jsval v, Size* ret) { return true; } -bool jsval_to_cccolor4b(JSContext *cx, jsval v, Color4B* ret) { +bool jsval_to_cccolor4b(JSContext *cx, JS::HandleValue v, Color4B* ret) { JS::RootedObject tmp(cx); JS::RootedValue jsr(cx); JS::RootedValue jsg(cx); @@ -734,7 +844,7 @@ bool jsval_to_cccolor4b(JSContext *cx, jsval v, Color4B* ret) { double r, g, b, a; bool ok = v.isObject() && - JS_ValueToObject(cx, JS::RootedValue(cx, v), &tmp) && + JS_ValueToObject(cx, v, &tmp) && JS_GetProperty(cx, tmp, "r", &jsr) && JS_GetProperty(cx, tmp, "g", &jsg) && JS_GetProperty(cx, tmp, "b", &jsb) && @@ -753,7 +863,7 @@ bool jsval_to_cccolor4b(JSContext *cx, jsval v, Color4B* ret) { return true; } -bool jsval_to_cccolor4f(JSContext *cx, jsval v, Color4F* ret) { +bool jsval_to_cccolor4f(JSContext *cx, JS::HandleValue v, Color4F* ret) { JS::RootedObject tmp(cx); JS::RootedValue jsr(cx); JS::RootedValue jsg(cx); @@ -761,7 +871,7 @@ bool jsval_to_cccolor4f(JSContext *cx, jsval v, Color4F* ret) { JS::RootedValue jsa(cx); double r, g, b, a; bool ok = v.isObject() && - JS_ValueToObject(cx, JS::RootedValue(cx, v), &tmp) && + JS_ValueToObject(cx, v, &tmp) && JS_GetProperty(cx, tmp, "r", &jsr) && JS_GetProperty(cx, tmp, "g", &jsg) && JS_GetProperty(cx, tmp, "b", &jsb) && @@ -779,14 +889,14 @@ bool jsval_to_cccolor4f(JSContext *cx, jsval v, Color4F* ret) { return true; } -bool jsval_to_cccolor3b(JSContext *cx, jsval v, Color3B* ret) { +bool jsval_to_cccolor3b(JSContext *cx, JS::HandleValue v, Color3B* ret) { JS::RootedObject tmp(cx); JS::RootedValue jsr(cx); JS::RootedValue jsg(cx); JS::RootedValue jsb(cx); double r, g, b; bool ok = v.isObject() && - JS_ValueToObject(cx, JS::RootedValue(cx, v), &tmp) && + JS_ValueToObject(cx, v, &tmp) && JS_GetProperty(cx, tmp, "r", &jsr) && JS_GetProperty(cx, tmp, "g", &jsg) && JS_GetProperty(cx, tmp, "b", &jsb) && @@ -802,13 +912,13 @@ bool jsval_to_cccolor3b(JSContext *cx, jsval v, Color3B* ret) { return true; } -bool jsval_cccolor_to_opacity(JSContext *cx, jsval v, int32_t* ret) { +bool jsval_cccolor_to_opacity(JSContext *cx, JS::HandleValue v, int32_t* ret) { JS::RootedObject tmp(cx); JS::RootedValue jsa(cx); double a; bool ok = v.isObject() && - JS_ValueToObject(cx, JS::RootedValue(cx, v), &tmp) && + JS_ValueToObject(cx, v, &tmp) && JS_LookupProperty(cx, tmp, "a", &jsa) && !jsa.isUndefined() && JS::ToNumber(cx, jsa, &a); @@ -820,10 +930,10 @@ bool jsval_cccolor_to_opacity(JSContext *cx, jsval v, int32_t* ret) { else return false; } -bool jsval_to_ccarray_of_CCPoint(JSContext* cx, jsval v, Point **points, int *numPoints) { +bool jsval_to_ccarray_of_CCPoint(JSContext* cx, JS::HandleValue v, Point **points, int *numPoints) { // Parsing sequence JS::RootedObject jsobj(cx); - bool ok = v.isObject() && JS_ValueToObject( cx, JS::RootedValue(cx, v), &jsobj ); + bool ok = v.isObject() && JS_ValueToObject( cx, v, &jsobj ); JSB_PRECONDITION3( ok, cx, false, "Error converting value to object"); JSB_PRECONDITION3( jsobj && JS_IsArrayObject( cx, jsobj), cx, false, "Object must be an array"); @@ -847,10 +957,10 @@ bool jsval_to_ccarray_of_CCPoint(JSContext* cx, jsval v, Point **points, int *nu } -bool jsval_to_ccarray(JSContext* cx, jsval v, __Array** ret) +bool jsval_to_ccarray(JSContext* cx, JS::HandleValue v, __Array** ret) { JS::RootedObject jsobj(cx); - bool ok = v.isObject() && JS_ValueToObject( cx, JS::RootedValue(cx, v), &jsobj ); + bool ok = v.isObject() && JS_ValueToObject( cx, v, &jsobj ); JSB_PRECONDITION3( ok, cx, false, "Error converting value to object"); JSB_PRECONDITION3( jsobj && JS_IsArrayObject( cx, jsobj), cx, false, "Object must be an array"); @@ -863,7 +973,7 @@ bool jsval_to_ccarray(JSContext* cx, jsval v, __Array** ret) if (value.isObject()) { js_proxy_t *proxy; - JSObject *tmp = JSVAL_TO_OBJECT(value); + JS::RootedObject tmp(cx, value.toObjectOrNull()); proxy = jsb_get_js_proxy(tmp); cocos2d::Ref* cobj = (cocos2d::Ref *)(proxy ? proxy->ptr : NULL); // Don't test it. @@ -889,12 +999,12 @@ bool jsval_to_ccarray(JSContext* cx, jsval v, __Array** ret) } } } - else if (JSVAL_IS_STRING(value)) { - JSStringWrapper valueWapper(JSVAL_TO_STRING(value), cx); + else if (value.isString()) { + JSStringWrapper valueWapper(value.toString(), cx); arr->addObject(String::create(valueWapper.get())); // CCLOG("iterate array: value = %s", valueWapper.get().c_str()); } - else if (JSVAL_IS_NUMBER(value)) { + else if (value.isNumber()) { double number = 0.0; ok = JS::ToNumber(cx, value, &number); if (ok) { @@ -902,7 +1012,7 @@ bool jsval_to_ccarray(JSContext* cx, jsval v, __Array** ret) // CCLOG("iterate array: value = %lf", number); } } - else if (JSVAL_IS_BOOLEAN(value)) { + else if (value.isBoolean()) { bool boolVal = JS::ToBoolean(value); arr->addObject(Bool::create(boolVal)); // CCLOG("iterate object: value = %d", boolVal); @@ -916,11 +1026,11 @@ bool jsval_to_ccarray(JSContext* cx, jsval v, __Array** ret) return true; } -bool jsval_to_ccvalue(JSContext* cx, jsval v, cocos2d::Value* ret) +bool jsval_to_ccvalue(JSContext* cx, JS::HandleValue v, cocos2d::Value* ret) { if (v.isObject()) { - JSObject* jsobj = JSVAL_TO_OBJECT(v); + JS::RootedObject jsobj(cx, v.toObjectOrNull()); CCASSERT(jsb_get_js_proxy(jsobj) == nullptr, "Native object should be added!"); if (!JS_IsArrayObject(cx, jsobj)) { @@ -942,22 +1052,22 @@ bool jsval_to_ccvalue(JSContext* cx, jsval v, cocos2d::Value* ret) } } } - else if (JSVAL_IS_STRING(v)) + else if (v.isString()) { - JSStringWrapper valueWapper(JSVAL_TO_STRING(v), cx); + JSStringWrapper valueWapper(v.toString(), cx); *ret = Value(valueWapper.get()); } - else if (JSVAL_IS_NUMBER(v)) + else if (v.isNumber()) { double number = 0.0; - bool ok = JS::ToNumber(cx, JS::RootedValue(cx, v), &number); + bool ok = JS::ToNumber(cx, v, &number); if (ok) { *ret = Value(number); } } - else if (JSVAL_IS_BOOLEAN(v)) + else if (v.isBoolean()) { - bool boolVal = JS::ToBoolean(JS::RootedValue(cx, v)); + bool boolVal = JS::ToBoolean(v); *ret = Value(boolVal); } else { @@ -967,46 +1077,46 @@ bool jsval_to_ccvalue(JSContext* cx, jsval v, cocos2d::Value* ret) return true; } -bool jsval_to_ccvaluemap(JSContext* cx, jsval v, cocos2d::ValueMap* ret) +bool jsval_to_ccvaluemap(JSContext* cx, JS::HandleValue v, cocos2d::ValueMap* ret) { - if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) + if (v.isNullOrUndefined()) { return true; } - JSObject* tmp = JSVAL_TO_OBJECT(v); + JS::RootedObject tmp(cx, v.toObjectOrNull()); if (!tmp) { CCLOG("%s", "jsval_to_ccvaluemap: the jsval is not an object."); return false; } - JSObject* it = JS_NewPropertyIterator(cx, tmp); + JS::RootedObject it(cx, JS_NewPropertyIterator(cx, tmp)); ValueMap& dict = *ret; while (true) { - jsid idp; - jsval key; - if (! JS_NextProperty(cx, it, &idp) || ! JS_IdToValue(cx, idp, &key)) { + JS::RootedId idp(cx); + JS::RootedValue key(cx); + if (! JS_NextProperty(cx, it, idp.address()) || ! JS_IdToValue(cx, idp, &key)) { return false; // error } - if (key == JSVAL_VOID) { + if (key.isNullOrUndefined()) { break; // end of iteration } - if (!JSVAL_IS_STRING(key)) { + if (!key.isString()) { continue; // ignore integer properties } - JSStringWrapper keyWrapper(JSVAL_TO_STRING(key), cx); + JSStringWrapper keyWrapper(key.toString(), cx); JS::RootedValue value(cx); JS_GetPropertyById(cx, tmp, idp, &value); if (value.isObject()) { - JSObject* jsobj = JSVAL_TO_OBJECT(value); + JS::RootedObject jsobj(cx, value.toObjectOrNull()); CCASSERT(jsb_get_js_proxy(jsobj) == nullptr, "Native object should be added!"); if (!JS_IsArrayObject(cx, jsobj)) { @@ -1028,13 +1138,13 @@ bool jsval_to_ccvaluemap(JSContext* cx, jsval v, cocos2d::ValueMap* ret) } } } - else if (JSVAL_IS_STRING(value)) + else if (value.isString()) { - JSStringWrapper valueWapper(JSVAL_TO_STRING(value), cx); + JSStringWrapper valueWapper(value.toString(), cx); dict.insert(ValueMap::value_type(keyWrapper.get(), Value(valueWapper.get()))); // CCLOG("iterate object: key = %s, value = %s", keyWrapper.get().c_str(), valueWapper.get().c_str()); } - else if (JSVAL_IS_NUMBER(value)) + else if (value.isNumber()) { double number = 0.0; bool ok = JS::ToNumber(cx, value, &number); @@ -1043,7 +1153,7 @@ bool jsval_to_ccvaluemap(JSContext* cx, jsval v, cocos2d::ValueMap* ret) // CCLOG("iterate object: key = %s, value = %lf", keyWrapper.get().c_str(), number); } } - else if (JSVAL_IS_BOOLEAN(value)) + else if (value.isBoolean()) { bool boolVal = JS::ToBoolean(value); dict.insert(ValueMap::value_type(keyWrapper.get(), Value(boolVal))); @@ -1057,46 +1167,46 @@ bool jsval_to_ccvaluemap(JSContext* cx, jsval v, cocos2d::ValueMap* ret) return true; } -bool jsval_to_ccvaluemapintkey(JSContext* cx, jsval v, cocos2d::ValueMapIntKey* ret) +bool jsval_to_ccvaluemapintkey(JSContext* cx, JS::HandleValue v, cocos2d::ValueMapIntKey* ret) { - if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) + if (v.isNullOrUndefined()) { return true; } - JSObject* tmp = JSVAL_TO_OBJECT(v); + JS::RootedObject tmp(cx, v.toObjectOrNull()); if (!tmp) { CCLOG("%s", "jsval_to_ccvaluemap: the jsval is not an object."); return false; } - JSObject* it = JS_NewPropertyIterator(cx, tmp); + JS::RootedObject it(cx, JS_NewPropertyIterator(cx, tmp)); ValueMapIntKey& dict = *ret; while (true) { - jsid idp; - jsval key; - if (! JS_NextProperty(cx, it, &idp) || ! JS_IdToValue(cx, idp, &key)) { + JS::RootedId idp(cx); + JS::RootedValue key(cx); + if (! JS_NextProperty(cx, it, idp.address()) || ! JS_IdToValue(cx, idp, &key)) { return false; // error } - if (key == JSVAL_VOID) { + if (key.isNullOrUndefined()) { break; // end of iteration } - if (!JSVAL_IS_STRING(key)) { + if (!key.isString()) { continue; // ignore integer properties } - int keyVal = JSVAL_TO_INT(key); + int keyVal = key.toInt32(); JS::RootedValue value(cx); JS_GetPropertyById(cx, tmp, idp, &value); if (value.isObject()) { - JSObject* jsobj = JSVAL_TO_OBJECT(value); + JS::RootedObject jsobj(cx, value.toObjectOrNull()); CCASSERT(jsb_get_js_proxy(jsobj) == nullptr, "Native object should be added!"); if (!JS_IsArrayObject(cx, jsobj)) { @@ -1118,12 +1228,12 @@ bool jsval_to_ccvaluemapintkey(JSContext* cx, jsval v, cocos2d::ValueMapIntKey* } } } - else if (JSVAL_IS_STRING(value)) + else if (value.isString()) { - JSStringWrapper valueWapper(JSVAL_TO_STRING(value), cx); + JSStringWrapper valueWapper(value.toString(), cx); dict.insert(ValueMapIntKey::value_type(keyVal, Value(valueWapper.get()))); } - else if (JSVAL_IS_NUMBER(value)) + else if (value.isNumber()) { double number = 0.0; bool ok = JS::ToNumber(cx, value, &number); @@ -1131,7 +1241,7 @@ bool jsval_to_ccvaluemapintkey(JSContext* cx, jsval v, cocos2d::ValueMapIntKey* dict.insert(ValueMapIntKey::value_type(keyVal, Value(number))); } } - else if (JSVAL_IS_BOOLEAN(value)) + else if (value.isBoolean()) { bool boolVal = JS::ToBoolean(value); dict.insert(ValueMapIntKey::value_type(keyVal, Value(boolVal))); @@ -1144,10 +1254,10 @@ bool jsval_to_ccvaluemapintkey(JSContext* cx, jsval v, cocos2d::ValueMapIntKey* return true; } -bool jsval_to_ccvaluevector(JSContext* cx, jsval v, cocos2d::ValueVector* ret) +bool jsval_to_ccvaluevector(JSContext* cx, JS::HandleValue v, cocos2d::ValueVector* ret) { JS::RootedObject jsArr(cx); - bool ok = v.isObject() && JS_ValueToObject( cx, JS::RootedValue(cx, v), &jsArr ); + bool ok = v.isObject() && JS_ValueToObject( cx, v, &jsArr ); JSB_PRECONDITION3( ok, cx, false, "Error converting value to object"); JSB_PRECONDITION3( jsArr && JS_IsArrayObject( cx, jsArr), cx, false, "Object must be an array"); @@ -1161,7 +1271,7 @@ bool jsval_to_ccvaluevector(JSContext* cx, jsval v, cocos2d::ValueVector* ret) { if (value.isObject()) { - JSObject* jsobj = JSVAL_TO_OBJECT(value); + JS::RootedObject jsobj(cx, value.toObjectOrNull()); CCASSERT(jsb_get_js_proxy(jsobj) == nullptr, "Native object should be added!"); if (!JS_IsArrayObject(cx, jsobj)) @@ -1184,12 +1294,12 @@ bool jsval_to_ccvaluevector(JSContext* cx, jsval v, cocos2d::ValueVector* ret) } } } - else if (JSVAL_IS_STRING(value)) + else if (value.isString()) { - JSStringWrapper valueWapper(JSVAL_TO_STRING(value), cx); + JSStringWrapper valueWapper(value.toString(), cx); ret->push_back(Value(valueWapper.get())); } - else if (JSVAL_IS_NUMBER(value)) + else if (value.isNumber()) { double number = 0.0; ok = JS::ToNumber(cx, value, &number); @@ -1198,7 +1308,7 @@ bool jsval_to_ccvaluevector(JSContext* cx, jsval v, cocos2d::ValueVector* ret) ret->push_back(Value(number)); } } - else if (JSVAL_IS_BOOLEAN(value)) + else if (value.isBoolean()) { bool boolVal = JS::ToBoolean(value); ret->push_back(Value(boolVal)); @@ -1213,7 +1323,7 @@ bool jsval_to_ccvaluevector(JSContext* cx, jsval v, cocos2d::ValueVector* ret) return true; } -bool jsval_to_ssize( JSContext *cx, jsval vp, ssize_t* size) +bool jsval_to_ssize( JSContext *cx, JS::HandleValue vp, ssize_t* size) { bool ret = false; int32_t sizeInt32 = 0; @@ -1222,10 +1332,10 @@ bool jsval_to_ssize( JSContext *cx, jsval vp, ssize_t* size) return ret; } -bool jsval_to_std_vector_string( JSContext *cx, jsval vp, std::vector* ret) +bool jsval_to_std_vector_string( JSContext *cx, JS::HandleValue vp, std::vector* ret) { JS::RootedObject jsobj(cx); - bool ok = vp.isObject() && JS_ValueToObject( cx, JS::RootedValue(cx, vp), &jsobj ); + bool ok = vp.isObject() && JS_ValueToObject( cx, vp, &jsobj ); JSB_PRECONDITION3( ok, cx, false, "Error converting value to object"); JSB_PRECONDITION3( jsobj && JS_IsArrayObject( cx, jsobj), cx, false, "Object must be an array"); @@ -1237,9 +1347,9 @@ bool jsval_to_std_vector_string( JSContext *cx, jsval vp, std::vectorpush_back(valueWapper.get()); } else @@ -1253,10 +1363,10 @@ bool jsval_to_std_vector_string( JSContext *cx, jsval vp, std::vector* ret) +bool jsval_to_std_vector_int( JSContext *cx, JS::HandleValue vp, std::vector* ret) { JS::RootedObject jsobj(cx); - bool ok = vp.isObject() && JS_ValueToObject( cx, JS::RootedValue(cx, vp), &jsobj ); + bool ok = vp.isObject() && JS_ValueToObject( cx, vp, &jsobj ); JSB_PRECONDITION3( ok, cx, false, "Error converting value to object"); JSB_PRECONDITION3( jsobj && JS_IsArrayObject( cx, jsobj), cx, false, "Object must be an array"); @@ -1268,7 +1378,7 @@ bool jsval_to_std_vector_int( JSContext *cx, jsval vp, std::vector* ret) JS::RootedValue value(cx); if (JS_GetElement(cx, jsobj, i, &value)) { - if (JSVAL_IS_NUMBER(value)) + if (value.isNumber()) { double number = 0.0; ok = JS::ToNumber(cx, value, &number); @@ -1288,10 +1398,10 @@ bool jsval_to_std_vector_int( JSContext *cx, jsval vp, std::vector* ret) return true; } -bool jsval_to_matrix(JSContext *cx, jsval vp, cocos2d::Mat4* ret) +bool jsval_to_matrix(JSContext *cx, JS::HandleValue vp, cocos2d::Mat4* ret) { JS::RootedObject jsobj(cx); - bool ok = vp.isObject() && JS_ValueToObject( cx, JS::RootedValue(cx, vp), &jsobj ); + bool ok = vp.isObject() && JS_ValueToObject( cx, vp, &jsobj ); JSB_PRECONDITION3( ok, cx, false, "Error converting value to object"); JSB_PRECONDITION3( jsobj && JS_IsArrayObject( cx, jsobj), cx, false, "Object must be an matrix"); @@ -1308,7 +1418,7 @@ bool jsval_to_matrix(JSContext *cx, jsval vp, cocos2d::Mat4* ret) JS::RootedValue value(cx); if (JS_GetElement(cx, jsobj, i, &value)) { - if (JSVAL_IS_NUMBER(value)) + if (value.isNumber()) { double number = 0.0; ok = JS::ToNumber(cx, value, &number); @@ -1328,14 +1438,14 @@ bool jsval_to_matrix(JSContext *cx, jsval vp, cocos2d::Mat4* ret) return true; } -bool jsval_to_vector2(JSContext *cx, jsval vp, cocos2d::Vec2* ret) +bool jsval_to_vector2(JSContext *cx, JS::HandleValue vp, cocos2d::Vec2* ret) { JS::RootedObject tmp(cx); JS::RootedValue jsx(cx); JS::RootedValue jsy(cx); double x, y; bool ok = vp.isObject() && - JS_ValueToObject(cx, JS::RootedValue(cx, vp), &tmp) && + JS_ValueToObject(cx, vp, &tmp) && JS_GetProperty(cx, tmp, "x", &jsx) && JS_GetProperty(cx, tmp, "y", &jsy) && JS::ToNumber(cx, jsx, &x) && @@ -1348,7 +1458,7 @@ bool jsval_to_vector2(JSContext *cx, jsval vp, cocos2d::Vec2* ret) return true; } -bool jsval_to_vector3(JSContext *cx, jsval vp, cocos2d::Vec3* ret) +bool jsval_to_vector3(JSContext *cx, JS::HandleValue vp, cocos2d::Vec3* ret) { JS::RootedObject tmp(cx); JS::RootedValue jsx(cx); @@ -1356,13 +1466,14 @@ bool jsval_to_vector3(JSContext *cx, jsval vp, cocos2d::Vec3* ret) JS::RootedValue jsz(cx); double x, y, z; bool ok = vp.isObject() && - JS_ValueToObject(cx, JS::RootedValue(cx, vp), &tmp) && + JS_ValueToObject(cx, vp, &tmp) && JS_GetProperty(cx, tmp, "x", &jsx) && JS_GetProperty(cx, tmp, "y", &jsy) && JS_GetProperty(cx, tmp, "z", &jsz) && JS::ToNumber(cx, jsx, &x) && JS::ToNumber(cx, jsy, &y) && - JS::ToNumber(cx, jsz, &z); + JS::ToNumber(cx, jsz, &z) && + !isnan(x) && !isnan(y) && !isnan(z); JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); @@ -1372,14 +1483,43 @@ bool jsval_to_vector3(JSContext *cx, jsval vp, cocos2d::Vec3* ret) return true; } -bool jsval_to_blendfunc(JSContext *cx, jsval vp, cocos2d::BlendFunc* ret) +bool jsval_to_vector4(JSContext *cx, JS::HandleValue vp, cocos2d::Vec4* ret) +{ + JS::RootedObject tmp(cx); + JS::RootedValue jsx(cx); + JS::RootedValue jsy(cx); + JS::RootedValue jsz(cx); + JS::RootedValue jsw(cx); + double x, y, z, w; + bool ok = vp.isObject() && + JS_ValueToObject(cx, vp, &tmp) && + JS_GetProperty(cx, tmp, "x", &jsx) && + JS_GetProperty(cx, tmp, "y", &jsy) && + JS_GetProperty(cx, tmp, "z", &jsz) && + JS_GetProperty(cx, tmp, "w", &jsw) && + JS::ToNumber(cx, jsx, &x) && + JS::ToNumber(cx, jsy, &y) && + JS::ToNumber(cx, jsz, &z) && + JS::ToNumber(cx, jsw, &w) && + !isnan(x) && !isnan(y) && !isnan(z) && !isnan(w); + + JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); + + ret->x = (float)x; + ret->y = (float)y; + ret->z = (float)z; + ret->w = (float)w; + return true; +} + +bool jsval_to_blendfunc(JSContext *cx, JS::HandleValue vp, cocos2d::BlendFunc* ret) { JS::RootedObject tmp(cx); JS::RootedValue jssrc(cx); JS::RootedValue jsdst(cx); double src, dst; bool ok = vp.isObject() && - JS_ValueToObject(cx, JS::RootedValue(cx, vp), &tmp) && + JS_ValueToObject(cx, vp, &tmp) && JS_GetProperty(cx, tmp, "src", &jssrc) && JS_GetProperty(cx, tmp, "dst", &jsdst) && JS::ToNumber(cx, jssrc, &src) && @@ -1397,7 +1537,7 @@ bool jsval_to_blendfunc(JSContext *cx, jsval vp, cocos2d::BlendFunc* ret) jsval ccarray_to_jsval(JSContext* cx, __Array *arr) { - JSObject *jsretArr = JS_NewArrayObject(cx, 0, NULL); + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); Ref* obj; int i = 0; @@ -1437,7 +1577,7 @@ jsval ccarray_to_jsval(JSContext* cx, __Array *arr) CCASSERT(false, "the type isn't suppored."); } } - if (!JS_SetElement(cx, jsretArr, i, &arrElement)) { + if (!JS_SetElement(cx, jsretArr, i, arrElement)) { break; } ++i; @@ -1447,7 +1587,10 @@ jsval ccarray_to_jsval(JSContext* cx, __Array *arr) jsval ccdictionary_to_jsval(JSContext* cx, __Dictionary* dict) { - JSObject* jsRet = JS_NewObject(cx, NULL, NULL, NULL); + + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject jsRet(cx, JS_NewObject(cx, NULL, proto, parent)); DictElement* pElement = NULL; CCDICT_FOREACH(dict, pElement) { @@ -1494,40 +1637,40 @@ jsval ccdictionary_to_jsval(JSContext* cx, __Dictionary* dict) return OBJECT_TO_JSVAL(jsRet); } -bool jsval_to_ccdictionary(JSContext* cx, jsval v, __Dictionary** ret) +bool jsval_to_ccdictionary(JSContext* cx, JS::HandleValue v, __Dictionary** ret) { - if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) + if (v.isNullOrUndefined()) { *ret = NULL; return true; } - JSObject* tmp = JSVAL_TO_OBJECT(v); + JS::RootedObject tmp(cx, v.toObjectOrNull()); if (!tmp) { CCLOG("%s", "jsval_to_ccdictionary: the jsval is not an object."); return false; } - JSObject* it = JS_NewPropertyIterator(cx, tmp); + JS::RootedObject it(cx, JS_NewPropertyIterator(cx, tmp)); __Dictionary* dict = NULL; while (true) { - jsid idp; - jsval key; - if (! JS_NextProperty(cx, it, &idp) || ! JS_IdToValue(cx, idp, &key)) { + JS::RootedId idp(cx); + JS::RootedValue key(cx); + if (! JS_NextProperty(cx, it, idp.address()) || ! JS_IdToValue(cx, idp, &key)) { return false; // error } - if (key == JSVAL_VOID) { + if (key.isNullOrUndefined()) { break; // end of iteration } - if (!JSVAL_IS_STRING(key)) { + if (!key.isString()) { continue; // ignore integer properties } - JSStringWrapper keyWrapper(JSVAL_TO_STRING(key), cx); + JSStringWrapper keyWrapper(key.toString(), cx); if (!dict) { dict = __Dictionary::create(); } @@ -1537,7 +1680,7 @@ bool jsval_to_ccdictionary(JSContext* cx, jsval v, __Dictionary** ret) if (value.isObject()) { js_proxy_t *proxy; - tmp = JSVAL_TO_OBJECT(value); + tmp = value.toObjectOrNull(); proxy = jsb_get_js_proxy(tmp); cocos2d::Ref* cobj = (cocos2d::Ref *)(proxy ? proxy->ptr : NULL); // Don't test it. @@ -1563,12 +1706,12 @@ bool jsval_to_ccdictionary(JSContext* cx, jsval v, __Dictionary** ret) } } } - else if (JSVAL_IS_STRING(value)) { - JSStringWrapper valueWapper(JSVAL_TO_STRING(value), cx); + else if (value.isString()) { + JSStringWrapper valueWapper(value.toString(), cx); dict->setObject(String::create(valueWapper.get()), keyWrapper.get()); // CCLOG("iterate object: key = %s, value = %s", keyWrapper.get().c_str(), valueWapper.get().c_str()); } - else if (JSVAL_IS_NUMBER(value)) { + else if (value.isNumber()) { double number = 0.0; bool ok = JS::ToNumber(cx, value, &number); if (ok) { @@ -1576,7 +1719,7 @@ bool jsval_to_ccdictionary(JSContext* cx, jsval v, __Dictionary** ret) // CCLOG("iterate object: key = %s, value = %lf", keyWrapper.get().c_str(), number); } } - else if (JSVAL_IS_BOOLEAN(value)) { + else if (value.isBoolean()) { bool boolVal = JS::ToBoolean(value); dict->setObject(Bool::create(boolVal), keyWrapper.get()); // CCLOG("iterate object: key = %s, value = %d", keyWrapper.get().c_str(), boolVal); @@ -1590,7 +1733,7 @@ bool jsval_to_ccdictionary(JSContext* cx, jsval v, __Dictionary** ret) return true; } -bool jsval_to_ccaffinetransform(JSContext* cx, jsval v, AffineTransform* ret) +bool jsval_to_ccaffinetransform(JSContext* cx, JS::HandleValue v, AffineTransform* ret) { JS::RootedObject tmp(cx); JS::RootedValue jsa(cx); @@ -1600,7 +1743,7 @@ bool jsval_to_ccaffinetransform(JSContext* cx, jsval v, AffineTransform* ret) JS::RootedValue jstx(cx); JS::RootedValue jsty(cx); double a, b, c, d, tx, ty; - bool ok = JS_ValueToObject(cx, JS::RootedValue(cx, v), &tmp) && + bool ok = JS_ValueToObject(cx, v, &tmp) && JS_GetProperty(cx, tmp, "a", &jsa) && JS_GetProperty(cx, tmp, "b", &jsb) && JS_GetProperty(cx, tmp, "c", &jsc) && @@ -1661,6 +1804,9 @@ jsval c_string_to_jsval(JSContext* cx, const char* v, size_t length /* = -1 */) } jsval ret = JSVAL_NULL; + + //XXX: JS_NewUCStringCopyN can't be resolved on Win32 +#if(CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) int utf16_size = 0; jschar* strUTF16 = (jschar*)cc_utf8_to_utf16(v, (int)length, &utf16_size); @@ -1671,15 +1817,24 @@ jsval c_string_to_jsval(JSContext* cx, const char* v, size_t length /* = -1 */) } delete[] strUTF16; } +#else + JSString* str = JS_NewStringCopyN(cx, v, length); + if(str) + { + ret = STRING_TO_JSVAL(str); + } +#endif return ret; } jsval ccpoint_to_jsval(JSContext* cx, const Point& v) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent)); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "x", DOUBLE_TO_JSVAL(v.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "y", DOUBLE_TO_JSVAL(v.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "x", v.x, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "y", v.y, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { return OBJECT_TO_JSVAL(tmp); } @@ -1689,13 +1844,15 @@ jsval ccpoint_to_jsval(JSContext* cx, const Point& v) jsval ccacceleration_to_jsval(JSContext* cx, const Acceleration& v) { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent)); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "x", DOUBLE_TO_JSVAL(v.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "y", DOUBLE_TO_JSVAL(v.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "z", DOUBLE_TO_JSVAL(v.z), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "timestamp", DOUBLE_TO_JSVAL(v.timestamp), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "x", v.x, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "y", v.y, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "z", v.z, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "timestamp", v.timestamp, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { return OBJECT_TO_JSVAL(tmp); } @@ -1704,12 +1861,14 @@ jsval ccacceleration_to_jsval(JSContext* cx, const Acceleration& v) jsval ccrect_to_jsval(JSContext* cx, const Rect& v) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent)); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "x", DOUBLE_TO_JSVAL(v.origin.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "y", DOUBLE_TO_JSVAL(v.origin.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "width", DOUBLE_TO_JSVAL(v.size.width), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "height", DOUBLE_TO_JSVAL(v.size.height), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "x", v.origin.x, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "y", v.origin.y, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "width", v.size.width, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "height", v.size.height, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { return OBJECT_TO_JSVAL(tmp); } @@ -1718,10 +1877,12 @@ jsval ccrect_to_jsval(JSContext* cx, const Rect& v) jsval ccsize_to_jsval(JSContext* cx, const Size& v) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent)); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "width", DOUBLE_TO_JSVAL(v.width), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "height", DOUBLE_TO_JSVAL(v.height), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "width", v.width, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "height", v.height, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { return OBJECT_TO_JSVAL(tmp); } @@ -1730,37 +1891,45 @@ jsval ccsize_to_jsval(JSContext* cx, const Size& v) jsval cccolor4b_to_jsval(JSContext* cx, const Color4B& v) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent)); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "r", INT_TO_JSVAL(v.r), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "g", INT_TO_JSVAL(v.g), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "b", INT_TO_JSVAL(v.b), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "a", INT_TO_JSVAL(v.a), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "r", (int32_t)v.r, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "g", (int32_t)v.g, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "b", (int32_t)v.b, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "a", (int32_t)v.a, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { return OBJECT_TO_JSVAL(tmp); } return JSVAL_NULL; } -jsval cccolor4f_to_jsval(JSContext* cx, const Color4F& v) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); +jsval cccolor4f_to_jsval(JSContext* cx, const Color4F& v) +{ + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent)); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "r", INT_TO_JSVAL((int)(v.r * 255)), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "g", INT_TO_JSVAL((int)(v.g * 255)), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "b", INT_TO_JSVAL((int)(v.b * 255)), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "a", INT_TO_JSVAL((int)(v.a * 255)), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "r", (int32_t)(v.r * 255), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "g", (int32_t)(v.g * 255), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "b", (int32_t)(v.b * 255), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "a", (int32_t)(v.a * 255), JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { return OBJECT_TO_JSVAL(tmp); } return JSVAL_NULL; } -jsval cccolor3b_to_jsval(JSContext* cx, const Color3B& v) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); +jsval cccolor3b_to_jsval(JSContext* cx, const Color3B& v) +{ + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent)); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "r", INT_TO_JSVAL(v.r), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "g", INT_TO_JSVAL(v.g), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "b", INT_TO_JSVAL(v.b), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "r", (int32_t)v.r, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "g", (int32_t)v.g, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "b", (int32_t)v.b, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { return OBJECT_TO_JSVAL(tmp); } @@ -1769,57 +1938,89 @@ jsval cccolor3b_to_jsval(JSContext* cx, const Color3B& v) { jsval ccaffinetransform_to_jsval(JSContext* cx, const AffineTransform& t) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent)); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "a", DOUBLE_TO_JSVAL(t.a), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "b", DOUBLE_TO_JSVAL(t.b), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "c", DOUBLE_TO_JSVAL(t.c), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "d", DOUBLE_TO_JSVAL(t.d), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "tx", DOUBLE_TO_JSVAL(t.tx), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "ty", DOUBLE_TO_JSVAL(t.ty), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "a", t.a, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "b", t.b, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "c", t.c, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "d", t.d, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "tx", t.tx, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "ty", t.ty, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { return OBJECT_TO_JSVAL(tmp); } return JSVAL_NULL; } +jsval quaternion_to_jsval(JSContext* cx, const cocos2d::Quaternion& q) +{ + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); + if(!tmp) return JSVAL_NULL; + bool ok = JS_DefineProperty(cx, tmp, "x", q.x, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "y", q.y, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "z", q.z, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "w", q.w, JSPROP_ENUMERATE | JSPROP_PERMANENT); + if(ok) + return OBJECT_TO_JSVAL(tmp); + + return JSVAL_NULL; +} + +jsval meshVertexAttrib_to_jsval(JSContext* cx, const cocos2d::MeshVertexAttrib& q) +{ + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); + if(!tmp) return JSVAL_NULL; + bool ok = JS_DefineProperty(cx, tmp, "size", q.size, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "type", q.type, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "vertexAttrib", q.vertexAttrib, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "attribSizeBytes", q.attribSizeBytes, JSPROP_ENUMERATE | JSPROP_PERMANENT); + if(ok) + return OBJECT_TO_JSVAL(tmp); + + return JSVAL_NULL; +} + jsval FontDefinition_to_jsval(JSContext* cx, const FontDefinition& t) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); - if (!tmp) return JSVAL_NULL; + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent)); +// if (!tmp) return JSVAL_NULL; bool ok = true; + + ok &= JS_DefineProperty(cx, tmp, "fontName", JS::RootedValue(cx, std_string_to_jsval(cx, t._fontName)), JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "fontName", std_string_to_jsval(cx, t._fontName), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - ok &= JS_DefineProperty(cx, tmp, "fontSize", int32_to_jsval(cx, t._fontSize), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + ok &= JS_DefineProperty(cx, tmp, "fontSize", t._fontSize, JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "textAlign", int32_to_jsval(cx, (int32_t)t._alignment), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + ok &= JS_DefineProperty(cx, tmp, "textAlign", (int32_t)t._alignment, JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "verticalAlign", int32_to_jsval(cx, (int32_t)t._vertAlignment), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + ok &= JS_DefineProperty(cx, tmp, "verticalAlign", (int32_t)t._vertAlignment, JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "fillStyle", cccolor3b_to_jsval(cx, t._fontFillColor), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + ok &= JS_DefineProperty(cx, tmp, "fillStyle", JS::RootedValue(cx, cccolor3b_to_jsval(cx, t._fontFillColor)), JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "boundingWidth", DOUBLE_TO_JSVAL(t._dimensions.width), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + ok &= JS_DefineProperty(cx, tmp, "boundingWidth", t._dimensions.width, JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "boundingHeight", DOUBLE_TO_JSVAL(t._dimensions.height), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + ok &= JS_DefineProperty(cx, tmp, "boundingHeight", t._dimensions.height, JSPROP_ENUMERATE | JSPROP_PERMANENT); // Shadow - ok &= JS_DefineProperty(cx, tmp, "shadowEnabled", BOOLEAN_TO_JSVAL(t._shadow._shadowEnabled), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + ok &= JS_DefineProperty(cx, tmp, "shadowEnabled", JS::RootedValue(cx, BOOLEAN_TO_JSVAL(t._shadow._shadowEnabled)), JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "shadowOffsetX", DOUBLE_TO_JSVAL(t._shadow._shadowOffset.width), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + ok &= JS_DefineProperty(cx, tmp, "shadowOffsetX", t._shadow._shadowOffset.width, JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "shadowOffsetY", DOUBLE_TO_JSVAL(t._shadow._shadowOffset.height), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + ok &= JS_DefineProperty(cx, tmp, "shadowOffsetY", t._shadow._shadowOffset.height, JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "shadowBlur", DOUBLE_TO_JSVAL(t._shadow._shadowBlur), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + ok &= JS_DefineProperty(cx, tmp, "shadowBlur", t._shadow._shadowBlur, JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "shadowOpacity", DOUBLE_TO_JSVAL(t._shadow._shadowOpacity), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + ok &= JS_DefineProperty(cx, tmp, "shadowOpacity", t._shadow._shadowOpacity, JSPROP_ENUMERATE | JSPROP_PERMANENT); // Stroke - ok &= JS_DefineProperty(cx, tmp, "strokeEnabled", BOOLEAN_TO_JSVAL(t._stroke._strokeEnabled), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + ok &= JS_DefineProperty(cx, tmp, "strokeEnabled", JS::RootedValue(cx, BOOLEAN_TO_JSVAL(t._stroke._strokeEnabled)), JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "strokeStyle", cccolor3b_to_jsval(cx, t._stroke._strokeColor), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + ok &= JS_DefineProperty(cx, tmp, "strokeStyle", JS::RootedValue(cx, cccolor3b_to_jsval(cx, t._stroke._strokeColor)), JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "lineWidth", DOUBLE_TO_JSVAL(t._stroke._strokeSize), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + ok &= JS_DefineProperty(cx, tmp, "lineWidth", t._stroke._strokeSize, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { return OBJECT_TO_JSVAL(tmp); @@ -1827,11 +2028,11 @@ jsval FontDefinition_to_jsval(JSContext* cx, const FontDefinition& t) return JSVAL_NULL; } -bool jsval_to_FontDefinition( JSContext *cx, jsval vp, FontDefinition *out ) +bool jsval_to_FontDefinition( JSContext *cx, JS::HandleValue vp, FontDefinition *out ) { JS::RootedObject jsobj(cx); - if (!JS_ValueToObject( cx, JS::RootedValue(cx, vp), &jsobj ) ) + if (!JS_ValueToObject( cx, vp, &jsobj ) ) return false; JSB_PRECONDITION( jsobj, "Not a valid JS object"); @@ -2036,14 +2237,12 @@ bool jsval_to_FontDefinition( JSContext *cx, jsval vp, FontDefinition *out ) return true; } -#define JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES - -bool jsval_to_CCPoint( JSContext *cx, jsval vp, Point *ret ) +bool jsval_to_CCPoint( JSContext *cx, JS::HandleValue vp, Point *ret ) { #ifdef JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES JS::RootedObject jsobj(cx); - if( ! JS_ValueToObject( cx, JS::RootedValue(cx, vp), &jsobj ) ) + if( ! JS_ValueToObject( cx, vp, &jsobj ) ) return false; JSB_PRECONDITION( jsobj, "Not a valid JS object"); @@ -2085,84 +2284,6 @@ bool jsval_to_CCPoint( JSContext *cx, jsval vp, Point *ret ) #endif // #! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES } - -bool jsval_to_CGPoint( JSContext *cx, jsval vp, cpVect *ret ) -{ -#ifdef JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES - - JS::RootedObject jsobj(cx); - if( ! JS_ValueToObject( cx, JS::RootedValue(cx, vp), &jsobj ) ) - return false; - - JSB_PRECONDITION( jsobj, "Not a valid JS object"); - - JS::RootedValue valx(cx); - JS::RootedValue valy(cx); - bool ok = true; - ok &= JS_GetProperty(cx, jsobj, "x", &valx); - ok &= JS_GetProperty(cx, jsobj, "y", &valy); - - if( ! ok ) - return false; - - double x, y; - ok &= JS::ToNumber(cx, valx, &x); - ok &= JS::ToNumber(cx, valy, &y); - - if( ! ok ) - return false; - - ret->x = x; - ret->y = y; - - return true; - -#else // #! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES - - JSObject *tmp_arg; - if( ! JS_ValueToObject( cx, vp, &tmp_arg ) ) - return false; - - JSB_PRECONDITION( tmp_arg && JS_IsTypedArrayObject( tmp_arg, cx ), "Not a TypedArray object"); - - JSB_PRECONDITION( JS_GetTypedArrayByteLength( tmp_arg, cx ) == sizeof(cpVect), "Invalid length"); - - *ret = *(cpVect*)JS_GetArrayBufferViewData( tmp_arg, cx ); - - return true; -#endif // #! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES -} - - -jsval CGPoint_to_jsval( JSContext *cx, cpVect p) -{ - -#ifdef JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES - - JSObject *object = JS_NewObject(cx, NULL, NULL, NULL ); - if (!object) - return JSVAL_VOID; - - if (!JS_DefineProperty(cx, object, "x", DOUBLE_TO_JSVAL(p.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) || - !JS_DefineProperty(cx, object, "y", DOUBLE_TO_JSVAL(p.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) ) - return JSVAL_VOID; - - return OBJECT_TO_JSVAL(object); - -#else // JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES - -#ifdef __LP64__ - JSObject *typedArray = JS_NewFloat64Array( cx, 2 ); -#else - JSObject *typedArray = JS_NewFloat32Array( cx, 2 ); -#endif - - cpVect *buffer = (cpVect*)JS_GetArrayBufferViewData(typedArray, cx ); - *buffer = p; - return OBJECT_TO_JSVAL(typedArray); -#endif // ! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES -} - jsval ccvalue_to_jsval(JSContext* cx, const cocos2d::Value& v) { jsval ret = JSVAL_NULL; @@ -2201,7 +2322,7 @@ jsval ccvalue_to_jsval(JSContext* cx, const cocos2d::Value& v) jsval ccvaluemap_to_jsval(JSContext* cx, const cocos2d::ValueMap& v) { - JSObject* jsRet = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject jsRet(cx, JS_NewArrayObject(cx, 0)); for (auto iter = v.begin(); iter != v.end(); ++iter) { @@ -2248,7 +2369,7 @@ jsval ccvaluemap_to_jsval(JSContext* cx, const cocos2d::ValueMap& v) jsval ccvaluemapintkey_to_jsval(JSContext* cx, const cocos2d::ValueMapIntKey& v) { - JSObject* jsRet = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject jsRet(cx, JS_NewArrayObject(cx, 0)); for (auto iter = v.begin(); iter != v.end(); ++iter) { @@ -2297,7 +2418,7 @@ jsval ccvaluemapintkey_to_jsval(JSContext* cx, const cocos2d::ValueMapIntKey& v) jsval ccvaluevector_to_jsval(JSContext* cx, const cocos2d::ValueVector& v) { - JSObject *jsretArr = JS_NewArrayObject(cx, 0, NULL); + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); int i = 0; for (const auto& obj : v) @@ -2332,7 +2453,7 @@ jsval ccvaluevector_to_jsval(JSContext* cx, const cocos2d::ValueVector& v) break; } - if (!JS_SetElement(cx, jsretArr, i, &arrElement)) { + if (!JS_SetElement(cx, jsretArr, i, arrElement)) { break; } ++i; @@ -2348,7 +2469,7 @@ jsval ssize_to_jsval(JSContext *cx, ssize_t v) jsval std_vector_string_to_jsval( JSContext *cx, const std::vector& v) { - JSObject *jsretArr = JS_NewArrayObject(cx, 0, NULL); + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); int i = 0; for (const std::string obj : v) @@ -2356,7 +2477,7 @@ jsval std_vector_string_to_jsval( JSContext *cx, const std::vector& JS::RootedValue arrElement(cx); arrElement = std_string_to_jsval(cx, obj); - if (!JS_SetElement(cx, jsretArr, i, &arrElement)) { + if (!JS_SetElement(cx, jsretArr, i, arrElement)) { break; } ++i; @@ -2366,7 +2487,7 @@ jsval std_vector_string_to_jsval( JSContext *cx, const std::vector& jsval std_vector_int_to_jsval( JSContext *cx, const std::vector& v) { - JSObject *jsretArr = JS_NewArrayObject(cx, 0, NULL); + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); int i = 0; for (const int obj : v) @@ -2374,7 +2495,7 @@ jsval std_vector_int_to_jsval( JSContext *cx, const std::vector& v) JS::RootedValue arrElement(cx); arrElement = int32_to_jsval(cx, obj); - if (!JS_SetElement(cx, jsretArr, i, &arrElement)) { + if (!JS_SetElement(cx, jsretArr, i, arrElement)) { break; } ++i; @@ -2384,31 +2505,28 @@ jsval std_vector_int_to_jsval( JSContext *cx, const std::vector& v) jsval matrix_to_jsval(JSContext *cx, const cocos2d::Mat4& v) { - /*JSObject *jsretArr = JS_NewArrayObject(cx, 0, NULL); + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 16)); for (int i = 0; i < 16; i++) { JS::RootedValue arrElement(cx); arrElement = DOUBLE_TO_JSVAL(v.m[i]); - if (!JS_SetElement(cx, jsretArr, i, &arrElement)) { + if (!JS_SetElement(cx, jsretArr, i, arrElement)) { break; } } - return OBJECT_TO_JSVAL(jsretArr);*/ - - //convert Mat4 to AffineTransform to be compatible with html5 - cocos2d::AffineTransform affineTransform; - cocos2d::GLToCGAffine(v.m, &affineTransform); - return ccaffinetransform_to_jsval(cx, affineTransform); + return OBJECT_TO_JSVAL(jsretArr); } jsval vector2_to_jsval(JSContext *cx, const cocos2d::Vec2& v) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent)); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "x", DOUBLE_TO_JSVAL(v.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "y", DOUBLE_TO_JSVAL(v.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "x", v.x, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "y", v.y, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { return OBJECT_TO_JSVAL(tmp); } @@ -2417,11 +2535,13 @@ jsval vector2_to_jsval(JSContext *cx, const cocos2d::Vec2& v) jsval vector3_to_jsval(JSContext *cx, const cocos2d::Vec3& v) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent)); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "x", DOUBLE_TO_JSVAL(v.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "y", DOUBLE_TO_JSVAL(v.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "z", DOUBLE_TO_JSVAL(v.z), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "x", v.x, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "y", v.y, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "z", v.z, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { return OBJECT_TO_JSVAL(tmp); } @@ -2430,10 +2550,12 @@ jsval vector3_to_jsval(JSContext *cx, const cocos2d::Vec3& v) jsval blendfunc_to_jsval(JSContext *cx, const cocos2d::BlendFunc& v) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent)); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "src", uint32_to_jsval(cx, v.src), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "dst", uint32_to_jsval(cx, v.dst), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "src", (uint32_t)v.src, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "dst", (uint32_t)v.dst, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { return OBJECT_TO_JSVAL(tmp); } diff --git a/frameworks/js-bindings/bindings/manual/js_manual_conversions.h b/frameworks/js-bindings/bindings/manual/js_manual_conversions.h index 64c6d23d19..575dc940c6 100644 --- a/frameworks/js-bindings/bindings/manual/js_manual_conversions.h +++ b/frameworks/js-bindings/bindings/manual/js_manual_conversions.h @@ -31,7 +31,8 @@ #include "js_bindings_config.h" #include "cocos2d.h" #include "spidermonkey_specifics.h" -#include "chipmunk_private.h" + +#define JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES // just a simple utility to avoid mem leaking when using JSString class JSStringWrapper @@ -60,73 +61,75 @@ class JSFunctionWrapper JSFunctionWrapper(JSContext* cx, JSObject *jsthis, jsval fval); ~JSFunctionWrapper(); - bool invoke(unsigned int argc, jsval *argv, jsval &rval); + bool invoke(unsigned int argc, jsval *argv, JS::MutableHandleValue rval); private: JSContext *_cx; - JSObject *_jsthis; - jsval _fval; + JS::Heap _jsthis; + JS::Heap _fval; private: CC_DISALLOW_COPY_AND_ASSIGN(JSFunctionWrapper); }; -bool jsval_to_opaque( JSContext *cx, jsval vp, void **out ); -bool jsval_to_int( JSContext *cx, jsval vp, int *out); -bool jsval_to_uint( JSContext *cx, jsval vp, unsigned int *out); -bool jsval_to_c_class( JSContext *cx, jsval vp, void **out_native, struct jsb_c_proxy_s **out_proxy); +bool jsval_to_opaque( JSContext *cx, JS::HandleValue vp, void **out ); +bool jsval_to_int( JSContext *cx, JS::HandleValue vp, int *out); +bool jsval_to_uint( JSContext *cx, JS::HandleValue vp, unsigned int *out); +bool jsval_to_c_class( JSContext *cx, JS::HandleValue vp, void **out_native, struct jsb_c_proxy_s **out_proxy); /** converts a jsval (JS string) into a char */ -bool jsval_to_charptr( JSContext *cx, jsval vp, const char **out); +bool jsval_to_charptr( JSContext *cx, JS::HandleValue vp, const char **out); jsval opaque_to_jsval( JSContext *cx, void* opaque); -jsval c_class_to_jsval( JSContext *cx, void* handle, JSObject* object, JSClass *klass, const char* class_name); +jsval c_class_to_jsval( JSContext *cx, void* handle, JS::HandleObject object, JSClass *klass, const char* class_name); /* Converts a char ptr into a jsval (using JS string) */ jsval charptr_to_jsval( JSContext *cx, const char *str); -bool JSB_jsval_typedarray_to_dataptr( JSContext *cx, jsval vp, GLsizei *count, void **data, JSArrayBufferViewType t); -bool JSB_get_arraybufferview_dataptr( JSContext *cx, jsval vp, GLsizei *count, GLvoid **data ); +bool JSB_jsval_typedarray_to_dataptr( JSContext *cx, JS::HandleValue vp, GLsizei *count, void **data, js::Scalar::Type t); +bool JSB_get_arraybufferview_dataptr( JSContext *cx, JS::HandleValue vp, GLsizei *count, GLvoid **data ); // some utility functions // to native -bool jsval_to_ushort( JSContext *cx, jsval vp, unsigned short *ret ); -bool jsval_to_int32( JSContext *cx, jsval vp, int32_t *ret ); -bool jsval_to_uint32( JSContext *cx, jsval vp, uint32_t *ret ); -bool jsval_to_uint16( JSContext *cx, jsval vp, uint16_t *ret ); -bool jsval_to_long( JSContext *cx, jsval vp, long *out); -bool jsval_to_ulong( JSContext *cx, jsval vp, unsigned long *out); -bool jsval_to_long_long(JSContext *cx, jsval v, long long* ret); -bool jsval_to_std_string(JSContext *cx, jsval v, std::string* ret); -bool jsval_to_ccpoint(JSContext *cx, jsval v, cocos2d::Point* ret); -bool jsval_to_ccrect(JSContext *cx, jsval v, cocos2d::Rect* ret); -bool jsval_to_ccsize(JSContext *cx, jsval v, cocos2d::Size* ret); -bool jsval_to_cccolor4b(JSContext *cx, jsval v, cocos2d::Color4B* ret); -bool jsval_to_cccolor4f(JSContext *cx, jsval v, cocos2d::Color4F* ret); -bool jsval_to_cccolor3b(JSContext *cx, jsval v, cocos2d::Color3B* ret); -bool jsval_cccolor_to_opacity(JSContext *cx, jsval v, int32_t* ret); -bool jsval_to_ccarray_of_CCPoint(JSContext* cx, jsval v, cocos2d::Point **points, int *numPoints); -bool jsval_to_ccarray(JSContext* cx, jsval v, cocos2d::__Array** ret); -bool jsval_to_ccdictionary(JSContext* cx, jsval v, cocos2d::__Dictionary** ret); -bool jsval_to_ccacceleration(JSContext* cx,jsval v, cocos2d::Acceleration* ret); +bool jsval_to_ushort( JSContext *cx, JS::HandleValue vp, unsigned short *ret ); +bool jsval_to_int32( JSContext *cx, JS::HandleValue vp, int32_t *ret ); +bool jsval_to_uint32( JSContext *cx, JS::HandleValue vp, uint32_t *ret ); +bool jsval_to_uint16( JSContext *cx, JS::HandleValue vp, uint16_t *ret ); +bool jsval_to_long( JSContext *cx, JS::HandleValue vp, long *out); +bool jsval_to_ulong( JSContext *cx, JS::HandleValue vp, unsigned long *out); +bool jsval_to_long_long(JSContext *cx, JS::HandleValue v, long long* ret); +bool jsval_to_std_string(JSContext *cx, JS::HandleValue v, std::string* ret); +bool jsval_to_ccpoint(JSContext *cx, JS::HandleValue v, cocos2d::Point* ret); +bool jsval_to_ccrect(JSContext *cx, JS::HandleValue v, cocos2d::Rect* ret); +bool jsval_to_ccsize(JSContext *cx, JS::HandleValue v, cocos2d::Size* ret); +bool jsval_to_cccolor4b(JSContext *cx, JS::HandleValue v, cocos2d::Color4B* ret); +bool jsval_to_cccolor4f(JSContext *cx, JS::HandleValue v, cocos2d::Color4F* ret); +bool jsval_to_cccolor3b(JSContext *cx, JS::HandleValue v, cocos2d::Color3B* ret); +bool jsval_cccolor_to_opacity(JSContext *cx, JS::HandleValue v, int32_t* ret); +bool jsval_to_ccarray_of_CCPoint(JSContext* cx, JS::HandleValue v, cocos2d::Point **points, int *numPoints); +bool jsval_to_ccarray(JSContext* cx, JS::HandleValue v, cocos2d::__Array** ret); +bool jsval_to_ccdictionary(JSContext* cx, JS::HandleValue v, cocos2d::__Dictionary** ret); +bool jsval_to_ccacceleration(JSContext* cx, JS::HandleValue v, cocos2d::Acceleration* ret); bool jsvals_variadic_to_ccarray( JSContext *cx, jsval *vp, int argc, cocos2d::__Array** ret); +bool jsval_to_quaternion(JSContext *cx, JS::HandleValue vp, cocos2d::Quaternion* ret); +bool jsval_to_obb(JSContext *cx, JS::HandleValue vp, cocos2d::OBB* ret); +bool jsval_to_ray(JSContext *cx, JS::HandleValue vp, cocos2d::Ray* ret); // forward declaration js_proxy_t* jsb_get_js_proxy(JSObject* jsObj); template -bool jsvals_variadic_to_ccvector( JSContext *cx, jsval *vp, int argc, cocos2d::Vector* ret) +bool jsvals_variadic_to_ccvector( JSContext *cx, /*jsval *vp, int argc,*/const JS::CallArgs& args, cocos2d::Vector* ret) { bool ok = true; - for (int i = 0; i < argc; i++) + for (int i = 0; i < args.length(); i++) { js_proxy_t* p; - JSObject* obj = JSVAL_TO_OBJECT(*vp); + JSObject* obj = JS::RootedValue(cx, args.get(i)).toObjectOrNull(); + p = jsb_get_js_proxy(obj); CCASSERT(p, "Native object not found!"); if (p) { ret->pushBack((T)p->ptr); } - - // next - vp++; + } JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); @@ -135,16 +138,15 @@ bool jsvals_variadic_to_ccvector( JSContext *cx, jsval *vp, int argc, cocos2d::V bool jsvals_variadic_to_ccvaluevector( JSContext *cx, jsval *vp, int argc, cocos2d::ValueVector* ret); -bool jsval_to_ccaffinetransform(JSContext* cx, jsval v, cocos2d::AffineTransform* ret); -bool jsval_to_FontDefinition( JSContext *cx, jsval vp, cocos2d::FontDefinition* ret ); +bool jsval_to_ccaffinetransform(JSContext* cx, JS::HandleValue v, cocos2d::AffineTransform* ret); +bool jsval_to_FontDefinition( JSContext *cx, JS::HandleValue vp, cocos2d::FontDefinition* ret ); template -bool jsval_to_ccvector(JSContext* cx, jsval v, cocos2d::Vector* ret) +bool jsval_to_ccvector(JSContext* cx, JS::HandleValue v, cocos2d::Vector* ret) { JS::RootedObject jsobj(cx); - JS::RootedValue jsval(cx, v); - bool ok = jsval.isObject() && JS_ValueToObject( cx, jsval, &jsobj ); + bool ok = v.isObject() && JS_ValueToObject( cx, v, &jsobj ); JSB_PRECONDITION3( ok, cx, false, "Error converting value to object"); JSB_PRECONDITION3( jsobj && JS_IsArrayObject( cx, jsobj), cx, false, "Object must be an array"); @@ -159,7 +161,7 @@ bool jsval_to_ccvector(JSContext* cx, jsval v, cocos2d::Vector* ret) CCASSERT(value.isObject(), "the element in Vector isn't a native object."); js_proxy_t *proxy; - JSObject *tmp = JSVAL_TO_OBJECT(value); + JSObject *tmp = value.toObjectOrNull(); proxy = jsb_get_js_proxy(tmp); T cobj = (T)(proxy ? proxy->ptr : nullptr); if (cobj) @@ -172,58 +174,60 @@ bool jsval_to_ccvector(JSContext* cx, jsval v, cocos2d::Vector* ret) return true; } -bool jsval_to_ccvalue(JSContext* cx, jsval v, cocos2d::Value* ret); -bool jsval_to_ccvaluemap(JSContext* cx, jsval v, cocos2d::ValueMap* ret); -bool jsval_to_ccvaluemapintkey(JSContext* cx, jsval v, cocos2d::ValueMapIntKey* ret); -bool jsval_to_ccvaluevector(JSContext* cx, jsval v, cocos2d::ValueVector* ret); -bool jsval_to_ssize( JSContext *cx, jsval vp, ssize_t* ret); -bool jsval_to_std_vector_string( JSContext *cx, jsval vp, std::vector* ret); -bool jsval_to_std_vector_int( JSContext *cx, jsval vp, std::vector* ret); -bool jsval_to_matrix(JSContext *cx, jsval vp, cocos2d::Mat4* ret); -bool jsval_to_vector2(JSContext *cx, jsval vp, cocos2d::Vec2* ret); -bool jsval_to_vector3(JSContext *cx, jsval vp, cocos2d::Vec3* ret); -bool jsval_to_blendfunc(JSContext *cx, jsval vp, cocos2d::BlendFunc* ret); +bool jsval_to_ccvalue(JSContext* cx, JS::HandleValue v, cocos2d::Value* ret); +bool jsval_to_ccvaluemap(JSContext* cx, JS::HandleValue v, cocos2d::ValueMap* ret); +bool jsval_to_ccvaluemapintkey(JSContext* cx, JS::HandleValue v, cocos2d::ValueMapIntKey* ret); +bool jsval_to_ccvaluevector(JSContext* cx, JS::HandleValue v, cocos2d::ValueVector* ret); +bool jsval_to_ssize( JSContext *cx, JS::HandleValue vp, ssize_t* ret); +bool jsval_to_std_vector_string( JSContext *cx, JS::HandleValue vp, std::vector* ret); +bool jsval_to_std_vector_int( JSContext *cx, JS::HandleValue vp, std::vector* ret); +bool jsval_to_matrix(JSContext *cx, JS::HandleValue vp, cocos2d::Mat4* ret); +bool jsval_to_vector2(JSContext *cx, JS::HandleValue vp, cocos2d::Vec2* ret); +bool jsval_to_vector3(JSContext *cx, JS::HandleValue vp, cocos2d::Vec3* ret); +bool jsval_to_vector4(JSContext *cx, JS::HandleValue vp, cocos2d::Vec4* ret); +bool jsval_to_blendfunc(JSContext *cx, JS::HandleValue vp, cocos2d::BlendFunc* ret); template -bool jsval_to_ccmap_string_key(JSContext *cx, jsval v, cocos2d::Map* ret) +bool jsval_to_ccmap_string_key(JSContext *cx, JS::HandleValue v, cocos2d::Map* ret) { - if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) + if (v.isNullOrUndefined()) { return true; } - - JSObject* tmp = JSVAL_TO_OBJECT(v); + + JS::RootedObject tmp(cx, v.toObjectOrNull()); + if (!tmp) { CCLOG("%s", "jsval_to_ccvaluemap: the jsval is not an object."); return false; } - - JSObject* it = JS_NewPropertyIterator(cx, tmp); + + JS::RootedObject it(cx, JS_NewPropertyIterator(cx, tmp)); while (true) { - jsid idp; - jsval key; - if (! JS_NextProperty(cx, it, &idp) || ! JS_IdToValue(cx, idp, &key)) { + JS::RootedId idp(cx); + JS::RootedValue key(cx); + if (! JS_NextProperty(cx, it, idp.address()) || ! JS_IdToValue(cx, idp, &key)) { return false; // error } - if (key == JSVAL_VOID) { + if (key.isUndefined()) { break; // end of iteration } - if (!JSVAL_IS_STRING(key)) { + if (!key.isString()) { continue; // ignore integer properties } - JSStringWrapper keyWrapper(JSVAL_TO_STRING(key), cx); + JSStringWrapper keyWrapper(key.toString(), cx); JS::RootedValue value(cx); JS_GetPropertyById(cx, tmp, idp, &value); if (value.isObject()) { js_proxy_t *proxy = nullptr; - JSObject* jsobj = JSVAL_TO_OBJECT(value); + JSObject* jsobj = value.toObjectOrNull(); proxy = jsb_get_js_proxy(jsobj); CCASSERT(proxy, "Native object should be added!"); T cobj = (T)(proxy ? proxy->ptr : nullptr); @@ -258,13 +262,8 @@ jsval ccarray_to_jsval(JSContext* cx, cocos2d::__Array *arr); jsval ccacceleration_to_jsval(JSContext* cx, const cocos2d::Acceleration& v); jsval ccaffinetransform_to_jsval(JSContext* cx, const cocos2d::AffineTransform& t); jsval FontDefinition_to_jsval(JSContext* cx, const cocos2d::FontDefinition& t); - -bool jsval_to_CGPoint( JSContext *cx, jsval vp, cpVect *out ); -jsval CGPoint_to_jsval( JSContext *cx, cpVect p ); - -#define cpVect_to_jsval CGPoint_to_jsval -#define jsval_to_cpVect jsval_to_CGPoint - +jsval quaternion_to_jsval(JSContext* cx, const cocos2d::Quaternion& q); +jsval meshVertexAttrib_to_jsval(JSContext* cx, const cocos2d::MeshVertexAttrib& q); template js_proxy_t *js_get_or_create_proxy(JSContext *cx, T *native_obj); @@ -272,7 +271,7 @@ js_proxy_t *js_get_or_create_proxy(JSContext *cx, T *native_obj); template jsval ccvector_to_jsval(JSContext* cx, const cocos2d::Vector& v) { - JSObject *jsretArr = JS_NewArrayObject(cx, 0, NULL); + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); int i = 0; for (const auto& obj : v) @@ -285,7 +284,7 @@ jsval ccvector_to_jsval(JSContext* cx, const cocos2d::Vector& v) arrElement = OBJECT_TO_JSVAL(jsproxy->obj); } - if (!JS_SetElement(cx, jsretArr, i, &arrElement)) { + if (!JS_SetElement(cx, jsretArr, i, arrElement)) { break; } ++i; @@ -296,7 +295,9 @@ jsval ccvector_to_jsval(JSContext* cx, const cocos2d::Vector& v) template jsval ccmap_string_key_to_jsval(JSContext* cx, const cocos2d::Map& v) { - JSObject* jsRet = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject proto(cx); + JS::RootedObject parent(cx); + JS::RootedObject jsRet(cx, JS_NewObject(cx, NULL, proto, parent)); for (auto iter = v.begin(); iter != v.end(); ++iter) { diff --git a/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.cpp b/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.cpp index 16a48aad9c..2481746993 100644 --- a/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.cpp +++ b/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.cpp @@ -29,19 +29,20 @@ USING_NS_CC; bool js_EventListenerTouchOneByOne_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { auto ret = EventListenerTouchOneByOne::create(); - ret->onTouchBegan = [ret](Touch* touch, Event* event) -> bool { - jsval jsret = JSVAL_NULL; + ret->onTouchBegan = [cx, ret](Touch* touch, Event* event) -> bool { + JS::RootedValue jsret(cx); bool ok = ScriptingCore::getInstance()->handleTouchEvent(ret, EventTouch::EventCode::BEGAN, touch, event, &jsret); // Not found the method, just return false. if (!ok) return false; - CCASSERT(JSVAL_IS_BOOLEAN(jsret), "the return value of onTouchBegan isn't boolean"); - return JSVAL_TO_BOOLEAN(jsret); + CCASSERT(jsret.isBoolean(), "the return value of onTouchBegan isn't boolean"); + return jsret.toBoolean(); }; ret->onTouchMoved = [ret](Touch* touch, Event* event) { @@ -57,7 +58,7 @@ bool js_EventListenerTouchOneByOne_create(JSContext *cx, uint32_t argc, jsval *v }; jsval jsret = getJSObject(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -67,6 +68,7 @@ bool js_EventListenerTouchOneByOne_create(JSContext *cx, uint32_t argc, jsval *v bool js_EventListenerTouchAllAtOnce_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { auto ret = EventListenerTouchAllAtOnce::create(); @@ -87,7 +89,7 @@ bool js_EventListenerTouchAllAtOnce_create(JSContext *cx, uint32_t argc, jsval * }; jsval jsret = getJSObject(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -97,6 +99,7 @@ bool js_EventListenerTouchAllAtOnce_create(JSContext *cx, uint32_t argc, jsval * bool js_EventListenerMouse_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { auto ret = EventListenerMouse::create(); @@ -117,7 +120,7 @@ bool js_EventListenerMouse_create(JSContext *cx, uint32_t argc, jsval *vp) }; jsval jsret = getJSObject(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -127,6 +130,7 @@ bool js_EventListenerMouse_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_EventListenerKeyboard_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { auto ret = EventListenerKeyboard::create(); @@ -139,7 +143,7 @@ bool js_EventListenerKeyboard_create(JSContext *cx, uint32_t argc, jsval *vp) }; jsval jsret = getJSObject(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -147,4 +151,23 @@ bool js_EventListenerKeyboard_create(JSContext *cx, uint32_t argc, jsval *vp) return false; } +bool js_EventListenerFocus_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + if(argc == 0) + { + auto ret = EventListenerFocus::create(); + ret->onFocusChanged = [ret](ui::Widget* widgetLoseFocus, ui::Widget* widgetGetFocus){ + ScriptingCore::getInstance()->handleFocusEvent(ret, widgetLoseFocus, widgetGetFocus); + }; + + jsval jsret = getJSObject(cx, ret); + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} diff --git a/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.h b/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.h index 095a96f1b4..dd222e34e3 100644 --- a/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.h +++ b/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.h @@ -30,5 +30,6 @@ bool js_EventListenerTouchOneByOne_create(JSContext *cx, uint32_t argc, jsval *v bool js_EventListenerTouchAllAtOnce_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_EventListenerKeyboard_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_EventListenerMouse_create(JSContext *cx, uint32_t argc, jsval *vp); +bool js_EventListenerFocus_create(JSContext *cx, uint32_t argc, jsval *vp); #endif /* defined(__cocos2d_js_bindings__jsb_event_dispatcher__) */ diff --git a/frameworks/js-bindings/bindings/manual/jsb_helper.h b/frameworks/js-bindings/bindings/manual/jsb_helper.h index 95d19b42ba..72cc68f551 100644 --- a/frameworks/js-bindings/bindings/manual/jsb_helper.h +++ b/frameworks/js-bindings/bindings/manual/jsb_helper.h @@ -36,7 +36,7 @@ static JSClass js_class; \ static JSObject* js_proto; \ static JSObject* js_parent; \ -static void _js_register(JSContext* cx, JSObject* global); +static void _js_register(JSContext* cx, JS::HandleObject global); #define JS_BINDED_CLASS_GLUE_IMPL(klass) \ JSClass klass::js_class = {}; \ @@ -77,42 +77,46 @@ out = OBJECT_TO_JSVAL(obj); \ JS_FN(#name, klass##_func_##name, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT) #define JS_BINDED_PROP_GET(klass, propName) \ -bool _js_get_##propName(JSContext *cx, JS::HandleId id, JS::MutableHandleValue vp) +bool _js_get_##propName(JSContext *cx, const JS::CallArgs& args) #define JS_BINDED_PROP_GET_IMPL(klass, propName) \ -static bool _js_get_##klass##_##propName(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) { \ +static bool _js_get_##klass##_##propName(JSContext *cx, unsigned argc, jsval *vp) { \ +JS::CallArgs args = JS::CallArgsFromVp(argc, vp); \ +JSObject* obj = args.thisv().toObjectOrNull(); \ klass* cobj = (klass*)JS_GetPrivate(obj); \ if (cobj) { \ -return cobj->_js_get_##propName(cx, id, vp); \ +return cobj->_js_get_##propName(cx, args); \ } \ JS_ReportError(cx, "Invalid getter call for property %s", #propName); \ return false; \ } \ -bool klass::_js_get_##propName(JSContext *cx, JS::HandleId id, JS::MutableHandleValue vp) +bool klass::_js_get_##propName(JSContext *cx, const JS::CallArgs& args) #define JS_BINDED_PROP_SET(klass, propName) \ -bool _js_set_##propName(JSContext *cx, JS::HandleId id, bool strict, JS::MutableHandleValue vp) +bool _js_set_##propName(JSContext *cx, const JS::CallArgs& args) #define JS_BINDED_PROP_SET_IMPL(klass, propName) \ -static bool _js_set_##klass##_##propName(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) { \ +static bool _js_set_##klass##_##propName(JSContext *cx, unsigned argc, jsval *vp) { \ +JS::CallArgs args = JS::CallArgsFromVp(argc, vp); \ +JSObject* obj = args.thisv().toObjectOrNull(); \ klass* cobj = (klass*)JS_GetPrivate(obj); \ if (cobj) { \ -return cobj->_js_set_##propName(cx, id, strict, vp); \ +return cobj->_js_set_##propName(cx, args); \ } \ JS_ReportError(cx, "Invalid setter call for property %s", #propName); \ return false; \ } \ -bool klass::_js_set_##propName(JSContext *cx, JS::HandleId id, bool strict, JS::MutableHandleValue vp) +bool klass::_js_set_##propName(JSContext *cx, const JS::CallArgs& args) #define JS_BINDED_PROP_ACCESSOR(klass, propName) \ JS_BINDED_PROP_GET(klass, propName); \ JS_BINDED_PROP_SET(klass, propName); #define JS_BINDED_PROP_DEF_GETTER(klass, propName) \ -{#propName, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(_js_get_##klass##_##propName), NULL} +JS_PSG(#propName, _js_get_##klass##_##propName, JSPROP_ENUMERATE | JSPROP_PERMANENT) #define JS_BINDED_PROP_DEF_ACCESSOR(klass, propName) \ -{#propName, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(_js_get_##klass##_##propName), JSOP_WRAPPER(_js_set_##klass##_##propName)} +JS_PSGS(#propName, _js_get_##klass##_##propName, _js_set_##klass##_##propName, JSPROP_ENUMERATE | JSPROP_PERMANENT) #define JS_CREATE_UINT_WRAPPED(valOut, propName, val) \ do { \ diff --git a/frameworks/js-bindings/bindings/manual/jsb_opengl_functions.cpp b/frameworks/js-bindings/bindings/manual/jsb_opengl_functions.cpp index 4d22fc2605..3d7004b491 100644 --- a/frameworks/js-bindings/bindings/manual/jsb_opengl_functions.cpp +++ b/frameworks/js-bindings/bindings/manual/jsb_opengl_functions.cpp @@ -18,15 +18,15 @@ // Ret value: void bool JSB_glActiveTexture(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glActiveTexture((GLenum)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -34,16 +34,17 @@ bool JSB_glActiveTexture(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glAttachShader(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glAttachShader((GLuint)arg0 , (GLuint)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + + args.rval().setUndefined(); return true; } @@ -51,17 +52,17 @@ bool JSB_glAttachShader(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glBindAttribLocation(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; const char* arg2; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); - ok &= jsval_to_charptr(cx, *argvp++, &arg2 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); + ok &= jsval_to_charptr(cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glBindAttribLocation((GLuint)arg0 , (GLuint)arg1 , (char*)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -69,16 +70,16 @@ bool JSB_glBindAttribLocation(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glBindBuffer(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glBindBuffer((GLenum)arg0 , (GLuint)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -86,16 +87,16 @@ bool JSB_glBindBuffer(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glBindFramebuffer(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glBindFramebuffer((GLenum)arg0 , (GLuint)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -103,16 +104,16 @@ bool JSB_glBindFramebuffer(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glBindRenderbuffer(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glBindRenderbuffer((GLenum)arg0 , (GLuint)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -120,16 +121,16 @@ bool JSB_glBindRenderbuffer(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glBindTexture(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glBindTexture((GLenum)arg0 , (GLuint)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -137,18 +138,18 @@ bool JSB_glBindTexture(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glBlendColor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glBlendColor((GLclampf)arg0 , (GLclampf)arg1 , (GLclampf)arg2 , (GLclampf)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -156,15 +157,15 @@ bool JSB_glBlendColor(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glBlendEquation(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glBlendEquation((GLenum)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -172,16 +173,16 @@ bool JSB_glBlendEquation(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glBlendEquationSeparate(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glBlendEquationSeparate((GLenum)arg0 , (GLenum)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -189,16 +190,16 @@ bool JSB_glBlendEquationSeparate(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glBlendFunc((GLenum)arg0 , (GLenum)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -206,18 +207,18 @@ bool JSB_glBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glBlendFuncSeparate(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; uint32_t arg2; uint32_t arg3; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg2 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg3 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); + ok &= jsval_to_uint32( cx, args.get(2), &arg2 ); + ok &= jsval_to_uint32( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glBlendFuncSeparate((GLenum)arg0 , (GLenum)arg1 , (GLenum)arg2 , (GLenum)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -225,18 +226,18 @@ bool JSB_glBlendFuncSeparate(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glBufferData(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; void* arg1; uint32_t arg2; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); GLsizei count; - ok &= JSB_get_arraybufferview_dataptr( cx, *argvp++, &count, &arg1); - ok &= jsval_to_uint32( cx, *argvp++, &arg2 ); + ok &= JSB_get_arraybufferview_dataptr( cx, args.get(1), &count, &arg1); + ok &= jsval_to_uint32( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glBufferData((GLenum)arg0 , count, (GLvoid*)arg1 , (GLenum)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -244,18 +245,18 @@ bool JSB_glBufferData(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glBufferSubData(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; void* arg2; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); GLsizei count; - ok &= JSB_get_arraybufferview_dataptr( cx, *argvp++, &count, &arg2); + ok &= JSB_get_arraybufferview_dataptr( cx, args.get(2), &count, &arg2); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glBufferSubData((GLenum)arg0 , (GLintptr)arg1 , count, (GLvoid*)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -263,16 +264,16 @@ bool JSB_glBufferSubData(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: GLenum bool JSB_glCheckFramebufferStatus(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLenum ret_val; ret_val = glCheckFramebufferStatus((GLenum)arg0 ); - JS_SET_RVAL(cx, vp, UINT_TO_JSVAL((uint32_t)ret_val)); + args.rval().set(UINT_TO_JSVAL((uint32_t)ret_val)); return true; } @@ -280,15 +281,15 @@ bool JSB_glCheckFramebufferStatus(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glClear(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glClear((GLbitfield)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -296,18 +297,18 @@ bool JSB_glClear(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glClearColor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glClearColor((GLclampf)arg0 , (GLclampf)arg1 , (GLclampf)arg2 , (GLclampf)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -315,15 +316,15 @@ bool JSB_glClearColor(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glClearDepthf(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glClearDepthf((GLclampf)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -331,15 +332,15 @@ bool JSB_glClearDepthf(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glClearStencil(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glClearStencil((GLint)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -347,18 +348,18 @@ bool JSB_glClearStencil(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glColorMask(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint16_t arg0; uint16_t arg1; uint16_t arg2; uint16_t arg3; - ok &= jsval_to_uint16( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint16( cx, *argvp++, &arg1 ); - ok &= jsval_to_uint16( cx, *argvp++, &arg2 ); - ok &= jsval_to_uint16( cx, *argvp++, &arg3 ); + ok &= jsval_to_uint16( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint16( cx, args.get(1), &arg1 ); + ok &= jsval_to_uint16( cx, args.get(2), &arg2 ); + ok &= jsval_to_uint16( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glColorMask((GLboolean)arg0 , (GLboolean)arg1 , (GLboolean)arg2 , (GLboolean)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -366,15 +367,15 @@ bool JSB_glColorMask(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glCompileShader(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glCompileShader((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -382,23 +383,23 @@ bool JSB_glCompileShader(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glCompressedTexImage2D(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 8, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; uint32_t arg2; int32_t arg3; int32_t arg4; int32_t arg5; int32_t arg6; void* arg7; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); - ok &= jsval_to_int32( cx, *argvp++, &arg4 ); - ok &= jsval_to_int32( cx, *argvp++, &arg5 ); - ok &= jsval_to_int32( cx, *argvp++, &arg6 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_uint32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); + ok &= jsval_to_int32( cx, args.get(4), &arg4 ); + ok &= jsval_to_int32( cx, args.get(5), &arg5 ); + ok &= jsval_to_int32( cx, args.get(6), &arg6 ); GLsizei count; - ok &= JSB_get_arraybufferview_dataptr( cx, *argvp++, &count, &arg7); + ok &= JSB_get_arraybufferview_dataptr( cx, args.get(7), &count, &arg7); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glCompressedTexImage2D((GLenum)arg0 , (GLint)arg1 , (GLenum)arg2 , (GLsizei)arg3 , (GLsizei)arg4 , (GLint)arg5 , (GLsizei)arg6 , (GLvoid*)arg7 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -406,24 +407,24 @@ bool JSB_glCompressedTexImage2D(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glCompressedTexSubImage2D(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 9, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; int32_t arg4; int32_t arg5; uint32_t arg6; int32_t arg7; void* arg8; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); - ok &= jsval_to_int32( cx, *argvp++, &arg4 ); - ok &= jsval_to_int32( cx, *argvp++, &arg5 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg6 ); - ok &= jsval_to_int32( cx, *argvp++, &arg7 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); + ok &= jsval_to_int32( cx, args.get(4), &arg4 ); + ok &= jsval_to_int32( cx, args.get(5), &arg5 ); + ok &= jsval_to_uint32( cx, args.get(6), &arg6 ); + ok &= jsval_to_int32( cx, args.get(7), &arg7 ); GLsizei count; - ok &= JSB_get_arraybufferview_dataptr( cx, *argvp++, &count, &arg8); + ok &= JSB_get_arraybufferview_dataptr( cx, args.get(8), &count, &arg8); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glCompressedTexSubImage2D((GLenum)arg0 , (GLint)arg1 , (GLint)arg2 , (GLint)arg3 , (GLsizei)arg4 , (GLsizei)arg5 , (GLenum)arg6 , (GLsizei)arg7 , (GLvoid*)arg8 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -431,22 +432,22 @@ bool JSB_glCompressedTexSubImage2D(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glCopyTexImage2D(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 8, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; uint32_t arg2; int32_t arg3; int32_t arg4; int32_t arg5; int32_t arg6; int32_t arg7; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); - ok &= jsval_to_int32( cx, *argvp++, &arg4 ); - ok &= jsval_to_int32( cx, *argvp++, &arg5 ); - ok &= jsval_to_int32( cx, *argvp++, &arg6 ); - ok &= jsval_to_int32( cx, *argvp++, &arg7 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_uint32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); + ok &= jsval_to_int32( cx, args.get(4), &arg4 ); + ok &= jsval_to_int32( cx, args.get(5), &arg5 ); + ok &= jsval_to_int32( cx, args.get(6), &arg6 ); + ok &= jsval_to_int32( cx, args.get(7), &arg7 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glCopyTexImage2D((GLenum)arg0 , (GLint)arg1 , (GLenum)arg2 , (GLint)arg3 , (GLint)arg4 , (GLsizei)arg5 , (GLsizei)arg6 , (GLint)arg7 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -454,22 +455,22 @@ bool JSB_glCopyTexImage2D(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glCopyTexSubImage2D(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 8, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; int32_t arg4; int32_t arg5; int32_t arg6; int32_t arg7; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); - ok &= jsval_to_int32( cx, *argvp++, &arg4 ); - ok &= jsval_to_int32( cx, *argvp++, &arg5 ); - ok &= jsval_to_int32( cx, *argvp++, &arg6 ); - ok &= jsval_to_int32( cx, *argvp++, &arg7 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); + ok &= jsval_to_int32( cx, args.get(4), &arg4 ); + ok &= jsval_to_int32( cx, args.get(5), &arg5 ); + ok &= jsval_to_int32( cx, args.get(6), &arg6 ); + ok &= jsval_to_int32( cx, args.get(7), &arg7 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glCopyTexSubImage2D((GLenum)arg0 , (GLint)arg1 , (GLint)arg2 , (GLint)arg3 , (GLint)arg4 , (GLint)arg5 , (GLsizei)arg6 , (GLsizei)arg7 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -477,10 +478,11 @@ bool JSB_glCopyTexSubImage2D(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: GLuint bool JSB_glCreateProgram(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); GLuint ret_val; ret_val = glCreateProgram( ); - JS_SET_RVAL(cx, vp, UINT_TO_JSVAL((uint32_t)ret_val)); + args.rval().set(UINT_TO_JSVAL((uint32_t)ret_val)); return true; } @@ -488,16 +490,16 @@ bool JSB_glCreateProgram(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: GLuint bool JSB_glCreateShader(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLuint ret_val; ret_val = glCreateShader((GLenum)arg0 ); - JS_SET_RVAL(cx, vp, UINT_TO_JSVAL((uint32_t)ret_val)); + args.rval().set(UINT_TO_JSVAL((uint32_t)ret_val)); return true; } @@ -505,15 +507,15 @@ bool JSB_glCreateShader(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glCullFace(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glCullFace((GLenum)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -521,15 +523,15 @@ bool JSB_glCullFace(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glDeleteProgram(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glDeleteProgram((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -537,15 +539,15 @@ bool JSB_glDeleteProgram(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glDeleteShader(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glDeleteShader((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -553,15 +555,15 @@ bool JSB_glDeleteShader(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glDepthFunc(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glDepthFunc((GLenum)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -569,15 +571,15 @@ bool JSB_glDepthFunc(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glDepthMask(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint16_t arg0; - ok &= jsval_to_uint16( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint16( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glDepthMask((GLboolean)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -585,16 +587,16 @@ bool JSB_glDepthMask(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glDepthRangef(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glDepthRangef((GLclampf)arg0 , (GLclampf)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -602,16 +604,16 @@ bool JSB_glDepthRangef(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glDetachShader(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glDetachShader((GLuint)arg0 , (GLuint)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -619,15 +621,15 @@ bool JSB_glDetachShader(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glDisable(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glDisable((GLenum)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -635,15 +637,15 @@ bool JSB_glDisable(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glDisableVertexAttribArray(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glDisableVertexAttribArray((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -651,17 +653,17 @@ bool JSB_glDisableVertexAttribArray(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glDrawArrays(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; int32_t arg2; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glDrawArrays((GLenum)arg0 , (GLint)arg1 , (GLsizei)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -669,19 +671,19 @@ bool JSB_glDrawArrays(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glDrawElements(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; uint32_t arg2; void* arg3; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg2 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_uint32( cx, args.get(2), &arg2 ); GLsizei count; - ok &= JSB_get_arraybufferview_dataptr( cx, *argvp++, &count, &arg3); + ok &= JSB_get_arraybufferview_dataptr( cx, args.get(3), &count, &arg3); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glDrawElements((GLenum)arg0 , (GLsizei)arg1 , (GLenum)arg2 , (GLvoid*)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -689,15 +691,15 @@ bool JSB_glDrawElements(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glEnable(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glEnable((GLenum)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -705,15 +707,15 @@ bool JSB_glEnable(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glEnableVertexAttribArray(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glEnableVertexAttribArray((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -721,9 +723,9 @@ bool JSB_glEnableVertexAttribArray(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glFinish(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); glFinish( ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -731,9 +733,9 @@ bool JSB_glFinish(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glFlush(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); glFlush( ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -741,18 +743,18 @@ bool JSB_glFlush(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glFramebufferRenderbuffer(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; uint32_t arg2; uint32_t arg3; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg2 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg3 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); + ok &= jsval_to_uint32( cx, args.get(2), &arg2 ); + ok &= jsval_to_uint32( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glFramebufferRenderbuffer((GLenum)arg0 , (GLenum)arg1 , (GLenum)arg2 , (GLuint)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -760,19 +762,19 @@ bool JSB_glFramebufferRenderbuffer(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glFramebufferTexture2D(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 5, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; uint32_t arg2; uint32_t arg3; int32_t arg4; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg2 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg3 ); - ok &= jsval_to_int32( cx, *argvp++, &arg4 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); + ok &= jsval_to_uint32( cx, args.get(2), &arg2 ); + ok &= jsval_to_uint32( cx, args.get(3), &arg3 ); + ok &= jsval_to_int32( cx, args.get(4), &arg4 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glFramebufferTexture2D((GLenum)arg0 , (GLenum)arg1 , (GLenum)arg2 , (GLuint)arg3 , (GLint)arg4 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -780,15 +782,15 @@ bool JSB_glFramebufferTexture2D(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glFrontFace(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glFrontFace((GLenum)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -796,15 +798,15 @@ bool JSB_glFrontFace(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glGenerateMipmap(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glGenerateMipmap((GLenum)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -812,17 +814,17 @@ bool JSB_glGenerateMipmap(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: int bool JSB_glGetAttribLocation(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; const char* arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_charptr( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_charptr( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); int ret_val; ret_val = glGetAttribLocation((GLuint)arg0 , (char*)arg1 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -830,10 +832,11 @@ bool JSB_glGetAttribLocation(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: GLenum bool JSB_glGetError(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); GLenum ret_val; ret_val = glGetError( ); - JS_SET_RVAL(cx, vp, UINT_TO_JSVAL((uint32_t)ret_val)); + args.rval().set(UINT_TO_JSVAL((uint32_t)ret_val)); return true; } @@ -841,18 +844,18 @@ bool JSB_glGetError(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: int bool JSB_glGetUniformLocation(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; const char* arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_charptr( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_charptr( cx, args.get(1), &arg1 ); printf("%s ", arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); int ret_val; ret_val = glGetUniformLocation((GLuint)arg0 , (char*)arg1 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -860,16 +863,16 @@ bool JSB_glGetUniformLocation(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glHint(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glHint((GLenum)arg0 , (GLenum)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -877,16 +880,16 @@ bool JSB_glHint(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: GLboolean bool JSB_glIsBuffer(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLboolean ret_val; ret_val = glIsBuffer((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -894,16 +897,16 @@ bool JSB_glIsBuffer(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: GLboolean bool JSB_glIsEnabled(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLboolean ret_val; ret_val = glIsEnabled((GLenum)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -911,16 +914,16 @@ bool JSB_glIsEnabled(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: GLboolean bool JSB_glIsFramebuffer(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLboolean ret_val; ret_val = glIsFramebuffer((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -928,16 +931,16 @@ bool JSB_glIsFramebuffer(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: GLboolean bool JSB_glIsProgram(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLboolean ret_val; ret_val = glIsProgram((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -945,16 +948,16 @@ bool JSB_glIsProgram(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: GLboolean bool JSB_glIsRenderbuffer(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLboolean ret_val; ret_val = glIsRenderbuffer((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -962,16 +965,16 @@ bool JSB_glIsRenderbuffer(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: GLboolean bool JSB_glIsShader(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLboolean ret_val; ret_val = glIsShader((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -979,16 +982,16 @@ bool JSB_glIsShader(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: GLboolean bool JSB_glIsTexture(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLboolean ret_val; ret_val = glIsTexture((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL((int32_t)ret_val)); + args.rval().set(INT_TO_JSVAL((int32_t)ret_val)); return true; } @@ -996,15 +999,15 @@ bool JSB_glIsTexture(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glLineWidth(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glLineWidth((GLfloat)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1012,15 +1015,15 @@ bool JSB_glLineWidth(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glLinkProgram(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glLinkProgram((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1028,16 +1031,16 @@ bool JSB_glLinkProgram(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glPixelStorei(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glPixelStorei((GLenum)arg0 , (GLint)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1045,16 +1048,16 @@ bool JSB_glPixelStorei(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glPolygonOffset(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glPolygonOffset((GLfloat)arg0 , (GLfloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1062,22 +1065,22 @@ bool JSB_glPolygonOffset(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glReadPixels(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 7, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; uint32_t arg4; uint32_t arg5; void* arg6; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg4 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg5 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); + ok &= jsval_to_uint32( cx, args.get(4), &arg4 ); + ok &= jsval_to_uint32( cx, args.get(5), &arg5 ); GLsizei count; - ok &= JSB_get_arraybufferview_dataptr( cx, *argvp++, &count, &arg6); + ok &= JSB_get_arraybufferview_dataptr( cx, args.get(6), &count, &arg6); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glReadPixels((GLint)arg0 , (GLint)arg1 , (GLsizei)arg2 , (GLsizei)arg3 , (GLenum)arg4 , (GLenum)arg5 , (GLvoid*)arg6 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1085,9 +1088,9 @@ bool JSB_glReadPixels(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glReleaseShaderCompiler(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); glReleaseShaderCompiler( ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1095,18 +1098,18 @@ bool JSB_glReleaseShaderCompiler(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glRenderbufferStorage(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; int32_t arg2; int32_t arg3; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glRenderbufferStorage((GLenum)arg0 , (GLenum)arg1 , (GLsizei)arg2 , (GLsizei)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1114,16 +1117,16 @@ bool JSB_glRenderbufferStorage(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glSampleCoverage(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; uint16_t arg1; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint16( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint16( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glSampleCoverage((GLclampf)arg0 , (GLboolean)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1131,18 +1134,18 @@ bool JSB_glSampleCoverage(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glScissor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glScissor((GLint)arg0 , (GLint)arg1 , (GLsizei)arg2 , (GLsizei)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1150,17 +1153,17 @@ bool JSB_glScissor(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glStencilFunc(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; uint32_t arg2; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg2 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_uint32( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glStencilFunc((GLenum)arg0 , (GLint)arg1 , (GLuint)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1168,18 +1171,18 @@ bool JSB_glStencilFunc(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glStencilFuncSeparate(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; int32_t arg2; uint32_t arg3; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg3 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_uint32( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glStencilFuncSeparate((GLenum)arg0 , (GLenum)arg1 , (GLint)arg2 , (GLuint)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1187,15 +1190,15 @@ bool JSB_glStencilFuncSeparate(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glStencilMask(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glStencilMask((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1203,16 +1206,16 @@ bool JSB_glStencilMask(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glStencilMaskSeparate(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glStencilMaskSeparate((GLenum)arg0 , (GLuint)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1220,17 +1223,17 @@ bool JSB_glStencilMaskSeparate(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glStencilOp(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; uint32_t arg2; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg2 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); + ok &= jsval_to_uint32( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glStencilOp((GLenum)arg0 , (GLenum)arg1 , (GLenum)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1238,18 +1241,18 @@ bool JSB_glStencilOp(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glStencilOpSeparate(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; uint32_t arg2; uint32_t arg3; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg2 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg3 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); + ok &= jsval_to_uint32( cx, args.get(2), &arg2 ); + ok &= jsval_to_uint32( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glStencilOpSeparate((GLenum)arg0 , (GLenum)arg1 , (GLenum)arg2 , (GLenum)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1257,24 +1260,24 @@ bool JSB_glStencilOpSeparate(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glTexImage2D(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 9, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; int32_t arg4; int32_t arg5; uint32_t arg6; uint32_t arg7; void* arg8; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); - ok &= jsval_to_int32( cx, *argvp++, &arg4 ); - ok &= jsval_to_int32( cx, *argvp++, &arg5 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg6 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg7 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); + ok &= jsval_to_int32( cx, args.get(4), &arg4 ); + ok &= jsval_to_int32( cx, args.get(5), &arg5 ); + ok &= jsval_to_uint32( cx, args.get(6), &arg6 ); + ok &= jsval_to_uint32( cx, args.get(7), &arg7 ); GLsizei count; - ok &= JSB_get_arraybufferview_dataptr( cx, *argvp++, &count, &arg8); + ok &= JSB_get_arraybufferview_dataptr( cx, args.get(8), &count, &arg8); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glTexImage2D((GLenum)arg0 , (GLint)arg1 , (GLint)arg2 , (GLsizei)arg3 , (GLsizei)arg4 , (GLint)arg5 , (GLenum)arg6 , (GLenum)arg7 , (GLvoid*)arg8 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1282,17 +1285,17 @@ bool JSB_glTexImage2D(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glTexParameterf(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; int32_t arg2; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glTexParameterf((GLenum)arg0 , (GLenum)arg1 , (GLfloat)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1300,17 +1303,17 @@ bool JSB_glTexParameterf(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glTexParameteri(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; uint32_t arg1; int32_t arg2; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glTexParameteri((GLenum)arg0 , (GLenum)arg1 , (GLint)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1318,24 +1321,24 @@ bool JSB_glTexParameteri(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glTexSubImage2D(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 9, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; int32_t arg4; int32_t arg5; uint32_t arg6; uint32_t arg7; void* arg8; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); - ok &= jsval_to_int32( cx, *argvp++, &arg4 ); - ok &= jsval_to_int32( cx, *argvp++, &arg5 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg6 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg7 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); + ok &= jsval_to_int32( cx, args.get(4), &arg4 ); + ok &= jsval_to_int32( cx, args.get(5), &arg5 ); + ok &= jsval_to_uint32( cx, args.get(6), &arg6 ); + ok &= jsval_to_uint32( cx, args.get(7), &arg7 ); GLsizei count; - ok &= JSB_get_arraybufferview_dataptr( cx, *argvp++, &count, &arg8); + ok &= JSB_get_arraybufferview_dataptr( cx, args.get(8), &count, &arg8); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glTexSubImage2D((GLenum)arg0 , (GLint)arg1 , (GLint)arg2 , (GLint)arg3 , (GLsizei)arg4 , (GLsizei)arg5 , (GLenum)arg6 , (GLenum)arg7 , (GLvoid*)arg8 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1343,16 +1346,16 @@ bool JSB_glTexSubImage2D(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform1f(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform1f((GLint)arg0 , (GLfloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1360,18 +1363,18 @@ bool JSB_glUniform1f(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform1fv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; void* arg2; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg2, js::ArrayBufferView::TYPE_FLOAT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(2), &count, &arg2, js::Scalar::Float32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform1fv((GLint)arg0 , (GLsizei)arg1 , (GLfloat*)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1379,16 +1382,16 @@ bool JSB_glUniform1fv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform1i(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform1i((GLint)arg0 , (GLint)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1396,18 +1399,18 @@ bool JSB_glUniform1i(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform1iv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; void* arg2; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg2, js::ArrayBufferView::TYPE_INT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(2), &count, &arg2, js::Scalar::Int32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform1iv((GLint)arg0 , (GLsizei)arg1 , (GLint*)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1415,17 +1418,17 @@ bool JSB_glUniform1iv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform2f(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; int32_t arg2; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform2f((GLint)arg0 , (GLfloat)arg1 , (GLfloat)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1433,18 +1436,18 @@ bool JSB_glUniform2f(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform2fv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; void* arg2; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg2, js::ArrayBufferView::TYPE_FLOAT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(2), &count, &arg2, js::Scalar::Float32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform2fv((GLint)arg0 , (GLsizei)arg1 , (GLfloat*)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1452,17 +1455,17 @@ bool JSB_glUniform2fv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform2i(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; int32_t arg2; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform2i((GLint)arg0 , (GLint)arg1 , (GLint)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1470,18 +1473,18 @@ bool JSB_glUniform2i(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform2iv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; void* arg2; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg2, js::ArrayBufferView::TYPE_INT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(2), &count, &arg2, js::Scalar::Int32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform2iv((GLint)arg0 , (GLsizei)arg1 , (GLint*)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1489,18 +1492,18 @@ bool JSB_glUniform2iv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform3f(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform3f((GLint)arg0 , (GLfloat)arg1 , (GLfloat)arg2 , (GLfloat)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1508,18 +1511,18 @@ bool JSB_glUniform3f(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform3fv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; void* arg2; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg2, js::ArrayBufferView::TYPE_FLOAT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(2), &count, &arg2, js::Scalar::Float32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform3fv((GLint)arg0 , (GLsizei)arg1 , (GLfloat*)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1527,18 +1530,18 @@ bool JSB_glUniform3fv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform3i(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform3i((GLint)arg0 , (GLint)arg1 , (GLint)arg2 , (GLint)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1546,18 +1549,18 @@ bool JSB_glUniform3i(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform3iv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; void* arg2; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg2, js::ArrayBufferView::TYPE_INT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(2), &count, &arg2, js::Scalar::Int32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform3iv((GLint)arg0 , (GLsizei)arg1 , (GLint*)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1565,19 +1568,19 @@ bool JSB_glUniform3iv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform4f(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 5, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; int32_t arg4; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); - ok &= jsval_to_int32( cx, *argvp++, &arg4 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); + ok &= jsval_to_int32( cx, args.get(4), &arg4 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform4f((GLint)arg0 , (GLfloat)arg1 , (GLfloat)arg2 , (GLfloat)arg3 , (GLfloat)arg4 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1585,18 +1588,18 @@ bool JSB_glUniform4f(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform4fv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; void* arg2; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg2, js::ArrayBufferView::TYPE_FLOAT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(2), &count, &arg2, js::Scalar::Float32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform4fv((GLint)arg0 , (GLsizei)arg1 , (GLfloat*)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1604,19 +1607,19 @@ bool JSB_glUniform4fv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform4i(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 5, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; int32_t arg4; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); - ok &= jsval_to_int32( cx, *argvp++, &arg4 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); + ok &= jsval_to_int32( cx, args.get(4), &arg4 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform4i((GLint)arg0 , (GLint)arg1 , (GLint)arg2 , (GLint)arg3 , (GLint)arg4 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1624,18 +1627,18 @@ bool JSB_glUniform4i(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniform4iv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; void* arg2; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg2, js::ArrayBufferView::TYPE_INT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(2), &count, &arg2, js::Scalar::Int32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniform4iv((GLint)arg0 , (GLsizei)arg1 , (GLint*)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1643,18 +1646,18 @@ bool JSB_glUniform4iv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniformMatrix2fv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; uint16_t arg1; void* arg2; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint16( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint16( cx, args.get(1), &arg1 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg2, js::ArrayBufferView::TYPE_FLOAT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(2), &count, &arg2, js::Scalar::Float32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniformMatrix2fv(arg0, 1, (GLboolean)arg1 , (GLfloat*)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1662,18 +1665,18 @@ bool JSB_glUniformMatrix2fv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniformMatrix3fv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; uint16_t arg1; void* arg2; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint16( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint16( cx, args.get(1), &arg1 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg2, js::ArrayBufferView::TYPE_FLOAT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(2), &count, &arg2, js::Scalar::Float32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniformMatrix3fv(arg0, 1, (GLboolean)arg1 , (GLfloat*)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1681,18 +1684,18 @@ bool JSB_glUniformMatrix3fv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUniformMatrix4fv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; uint16_t arg1; void* arg2; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint16( cx, *argvp++, &arg1 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint16( cx, args.get(1), &arg1 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg2, js::ArrayBufferView::TYPE_FLOAT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(2), &count, &arg2, js::Scalar::Float32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUniformMatrix4fv(arg0, 1, (GLboolean)arg1 , (GLfloat*)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1700,15 +1703,15 @@ bool JSB_glUniformMatrix4fv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glUseProgram(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glUseProgram((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1716,15 +1719,15 @@ bool JSB_glUseProgram(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glValidateProgram(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glValidateProgram((GLuint)arg0 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1732,16 +1735,16 @@ bool JSB_glValidateProgram(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glVertexAttrib1f(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glVertexAttrib1f((GLuint)arg0 , (GLfloat)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1749,17 +1752,17 @@ bool JSB_glVertexAttrib1f(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glVertexAttrib1fv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; void* arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg1, js::ArrayBufferView::TYPE_FLOAT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(1), &count, &arg1, js::Scalar::Float32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glVertexAttrib1fv((GLuint)arg0 , (GLfloat*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1767,17 +1770,17 @@ bool JSB_glVertexAttrib1fv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glVertexAttrib2f(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 3, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; int32_t arg2; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glVertexAttrib2f((GLuint)arg0 , (GLfloat)arg1 , (GLfloat)arg2 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1785,17 +1788,17 @@ bool JSB_glVertexAttrib2f(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glVertexAttrib2fv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; void* arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg1, js::ArrayBufferView::TYPE_FLOAT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(1), &count, &arg1, js::Scalar::Float32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glVertexAttrib2fv((GLuint)arg0 , (GLfloat*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1803,18 +1806,18 @@ bool JSB_glVertexAttrib2fv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glVertexAttrib3f(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glVertexAttrib3f((GLuint)arg0 , (GLfloat)arg1 , (GLfloat)arg2 , (GLfloat)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1822,17 +1825,17 @@ bool JSB_glVertexAttrib3f(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glVertexAttrib3fv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; void* arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg1, js::ArrayBufferView::TYPE_FLOAT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(1), &count, &arg1, js::Scalar::Float32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glVertexAttrib3fv((GLuint)arg0 , (GLfloat*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1840,19 +1843,19 @@ bool JSB_glVertexAttrib3fv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glVertexAttrib4f(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 5, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; int32_t arg4; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); - ok &= jsval_to_int32( cx, *argvp++, &arg4 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); + ok &= jsval_to_int32( cx, args.get(4), &arg4 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glVertexAttrib4f((GLuint)arg0 , (GLfloat)arg1 , (GLfloat)arg2 , (GLfloat)arg3 , (GLfloat)arg4 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1860,17 +1863,17 @@ bool JSB_glVertexAttrib4f(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glVertexAttrib4fv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; void* arg1; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); GLsizei count; - ok &= JSB_jsval_typedarray_to_dataptr( cx, *argvp++, &count, &arg1, js::ArrayBufferView::TYPE_FLOAT32); + ok &= JSB_jsval_typedarray_to_dataptr( cx, args.get(1), &count, &arg1, js::Scalar::Float32); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glVertexAttrib4fv((GLuint)arg0 , (GLfloat*)arg1 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1878,20 +1881,20 @@ bool JSB_glVertexAttrib4fv(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glVertexAttribPointer(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 6, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; int32_t arg1; uint32_t arg2; uint16_t arg3; int32_t arg4; int32_t arg5; - ok &= jsval_to_uint32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_uint32( cx, *argvp++, &arg2 ); - ok &= jsval_to_uint16( cx, *argvp++, &arg3 ); - ok &= jsval_to_int32( cx, *argvp++, &arg4 ); - ok &= jsval_to_int32( cx, *argvp++, &arg5 ); + ok &= jsval_to_uint32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_uint32( cx, args.get(2), &arg2 ); + ok &= jsval_to_uint16( cx, args.get(3), &arg3 ); + ok &= jsval_to_int32( cx, args.get(4), &arg4 ); + ok &= jsval_to_int32( cx, args.get(5), &arg5 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glVertexAttribPointer((GLuint)arg0 , (GLint)arg1 , (GLenum)arg2 , (GLboolean)arg3 , (GLsizei)arg4 , (GLvoid*)arg5 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1899,18 +1902,18 @@ bool JSB_glVertexAttribPointer(JSContext *cx, uint32_t argc, jsval *vp) { // Ret value: void bool JSB_glViewport(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 4, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; int32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; - ok &= jsval_to_int32( cx, *argvp++, &arg0 ); - ok &= jsval_to_int32( cx, *argvp++, &arg1 ); - ok &= jsval_to_int32( cx, *argvp++, &arg2 ); - ok &= jsval_to_int32( cx, *argvp++, &arg3 ); + ok &= jsval_to_int32( cx, args.get(0), &arg0 ); + ok &= jsval_to_int32( cx, args.get(1), &arg1 ); + ok &= jsval_to_int32( cx, args.get(2), &arg2 ); + ok &= jsval_to_int32( cx, args.get(3), &arg3 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glViewport((GLint)arg0 , (GLint)arg1 , (GLsizei)arg2 , (GLsizei)arg3 ); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } diff --git a/frameworks/js-bindings/bindings/manual/jsb_opengl_manual.cpp b/frameworks/js-bindings/bindings/manual/jsb_opengl_manual.cpp index eafcbffb5f..0da5d5af9f 100644 --- a/frameworks/js-bindings/bindings/manual/jsb_opengl_manual.cpp +++ b/frameworks/js-bindings/bindings/manual/jsb_opengl_manual.cpp @@ -34,161 +34,162 @@ bool JSB_glGenTextures(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); GLuint texture; glGenTextures(1, &texture); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL(texture)); + + args.rval().set(INT_TO_JSVAL(texture)); return true; } bool JSB_glGenBuffers(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); GLuint buffer; glGenBuffers(1, &buffer); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL(buffer)); + args.rval().set(INT_TO_JSVAL(buffer)); return true; } bool JSB_glGenRenderbuffers(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); GLuint renderbuffers; glGenRenderbuffers(1, &renderbuffers); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL(renderbuffers)); + args.rval().set(INT_TO_JSVAL(renderbuffers)); return true; } bool JSB_glGenFramebuffers(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" ); - + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); GLuint framebuffers; glGenFramebuffers(1, &framebuffers); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL(framebuffers)); + args.rval().set(INT_TO_JSVAL(framebuffers)); return true; } bool JSB_glDeleteTextures(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glDeleteTextures(1, &arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().set(JSVAL_VOID); return true; } bool JSB_glDeleteBuffers(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glDeleteBuffers(1, &arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().set(JSVAL_VOID); return true; } bool JSB_glDeleteRenderbuffers(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glDeleteRenderbuffers(1, &arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().set(JSVAL_VOID); return true; } bool JSB_glDeleteFramebuffers(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glDeleteFramebuffers(1, &arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().set(JSVAL_VOID); return true; } bool JSB_glShaderSource(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; const char *arg1; - ok &= jsval_to_uint( cx, *argvp++, &arg0 ); - ok &= jsval_to_charptr(cx, *argvp++, &arg1); + ok &= jsval_to_uint( cx, args.get(0), &arg0 ); + ok &= jsval_to_charptr(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); glShaderSource(arg0, 1, &arg1, NULL); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().set(JSVAL_VOID); return true; } bool JSB_glGetShaderiv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0, arg1; - ok &= jsval_to_uint( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLint ret; glGetShaderiv(arg0, arg1, &ret); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL(ret)); + args.rval().set(INT_TO_JSVAL(ret)); return true; } bool JSB_glGetProgramiv(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0, arg1; - ok &= jsval_to_uint( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLint ret; glGetProgramiv(arg0, arg1, &ret); - JS_SET_RVAL(cx, vp, INT_TO_JSVAL(ret)); + args.rval().set(INT_TO_JSVAL(ret)); return true; } bool JSB_glGetProgramInfoLog(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLsizei length; @@ -196,7 +197,7 @@ bool JSB_glGetProgramInfoLog(JSContext *cx, uint32_t argc, jsval *vp) GLchar* src = new GLchar[length]; glGetProgramInfoLog(arg0, length, NULL, src); - JS_SET_RVAL(cx, vp, charptr_to_jsval(cx, src)); + args.rval().set(charptr_to_jsval(cx, src)); CC_SAFE_DELETE_ARRAY(src); return true; } @@ -205,11 +206,11 @@ bool JSB_glGetProgramInfoLog(JSContext *cx, uint32_t argc, jsval *vp) bool JSB_glGetShaderInfoLog(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLsizei length; @@ -217,7 +218,7 @@ bool JSB_glGetShaderInfoLog(JSContext *cx, uint32_t argc, jsval *vp) GLchar* src = new GLchar[length]; glGetShaderInfoLog(arg0, length, NULL, src); - JS_SET_RVAL(cx, vp, charptr_to_jsval(cx, src)); + args.rval().set(charptr_to_jsval(cx, src)); CC_SAFE_DELETE_ARRAY(src); return true; } @@ -226,11 +227,11 @@ bool JSB_glGetShaderInfoLog(JSContext *cx, uint32_t argc, jsval *vp) bool JSB_glGetShaderSource(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLsizei length; @@ -238,7 +239,7 @@ bool JSB_glGetShaderSource(JSContext *cx, uint32_t argc, jsval *vp) GLchar* src = new GLchar[length]; glGetShaderSource(arg0, length, NULL, src); - JS_SET_RVAL(cx, vp, charptr_to_jsval(cx, src)); + args.rval().set(charptr_to_jsval(cx, src)); CC_SAFE_DELETE_ARRAY(src); return true; } @@ -251,12 +252,12 @@ bool JSB_glGetShaderSource(JSContext *cx, uint32_t argc, jsval *vp) bool JSB_glGetActiveAttrib(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0, arg1; - ok &= jsval_to_uint( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLsizei length; @@ -269,17 +270,17 @@ bool JSB_glGetActiveAttrib(JSContext *cx, uint32_t argc, jsval *vp) jsval retval = JSVAL_VOID; - JSObject *object = JS_NewObject(cx, NULL, NULL, NULL ); + JS::RootedObject object(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr() )); JSB_PRECONDITION2(ok, cx, false, "Error creating JS Object"); - if (!JS_DefineProperty(cx, object, "size", INT_TO_JSVAL(size), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) || - !JS_DefineProperty(cx, object, "type", INT_TO_JSVAL(type), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) || - !JS_DefineProperty(cx, object, "name", charptr_to_jsval(cx, buffer), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) ) + if (!JS_DefineProperty(cx, object, "size", (int32_t)size, JSPROP_ENUMERATE | JSPROP_PERMANENT) || + !JS_DefineProperty(cx, object, "type", (int32_t)type, JSPROP_ENUMERATE | JSPROP_PERMANENT) || + !JS_DefineProperty(cx, object, "name", JS::RootedValue(cx, charptr_to_jsval(cx, buffer)), JSPROP_ENUMERATE | JSPROP_PERMANENT) ) return false; retval = OBJECT_TO_JSVAL(object); - JS_SET_RVAL(cx, vp, retval); + args.rval().set(retval); CC_SAFE_DELETE_ARRAY(buffer); return true; } @@ -294,12 +295,12 @@ bool JSB_glGetActiveAttrib(JSContext *cx, uint32_t argc, jsval *vp) bool JSB_glGetActiveUniform(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 2, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0, arg1; - ok &= jsval_to_uint( cx, *argvp++, &arg0 ); - ok &= jsval_to_uint( cx, *argvp++, &arg1 ); + ok &= jsval_to_uint( cx, args.get(0), &arg0 ); + ok &= jsval_to_uint( cx, args.get(1), &arg1 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLsizei length; @@ -312,18 +313,18 @@ bool JSB_glGetActiveUniform(JSContext *cx, uint32_t argc, jsval *vp) jsval retval = JSVAL_VOID; - - JSObject *object = JS_NewObject(cx, NULL, NULL, NULL ); + + JS::RootedObject object(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr() )); JSB_PRECONDITION2(ok, cx, false, "Error creating JS Object"); - if (!JS_DefineProperty(cx, object, "size", INT_TO_JSVAL(size), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) || - !JS_DefineProperty(cx, object, "type", INT_TO_JSVAL(type), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) || - !JS_DefineProperty(cx, object, "name", charptr_to_jsval(cx, buffer), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) ) + if (!JS_DefineProperty(cx, object, "size", (int32_t)size, JSPROP_ENUMERATE | JSPROP_PERMANENT) || + !JS_DefineProperty(cx, object, "type", (int32_t)type, JSPROP_ENUMERATE | JSPROP_PERMANENT) || + !JS_DefineProperty(cx, object, "name", JS::RootedValue(cx, charptr_to_jsval(cx, buffer)), JSPROP_ENUMERATE | JSPROP_PERMANENT) ) return false; retval = OBJECT_TO_JSVAL(object); - JS_SET_RVAL(cx, vp, retval); + args.rval().set(retval); CC_SAFE_DELETE_ARRAY(buffer); return true; } @@ -332,11 +333,11 @@ bool JSB_glGetActiveUniform(JSContext *cx, uint32_t argc, jsval *vp) bool JSB_glGetAttachedShaders(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); - jsval *argvp = JS_ARGV(cx,vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; - ok &= jsval_to_uint( cx, *argvp++, &arg0 ); + ok &= jsval_to_uint( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLsizei length; @@ -347,15 +348,15 @@ bool JSB_glGetAttachedShaders(JSContext *cx, uint32_t argc, jsval *vp) GLsizei realShaderCount = 0; glGetAttachedShaders(arg0, length, &realShaderCount, buffer); - JSObject *jsobj = JS_NewArrayObject(cx, length, NULL); + JS::RootedObject jsobj(cx, JS_NewArrayObject(cx, length)); JSB_PRECONDITION2(jsobj, cx, false, "Error creating JS Object"); for( int i=0; i +#include using namespace std; @@ -40,7 +41,7 @@ using namespace std; */ void MinXmlHttpRequest::_gotHeader(string header) { - // Get Header and Set StatusText + // Get Header and Set StatusText // Split String into Tokens char * cstr = new char [header.length()+1]; @@ -58,9 +59,17 @@ void MinXmlHttpRequest::_gotHeader(string header) // Get rid of all \n if (!http_value.empty() && http_value[http_value.size() - 1] == '\n') { - http_value.erase(http_value.size() - 1); + http_value.erase(http_value.size() - 1); + } + + // Get rid of leading space (header is field: value format) + if (!http_value.empty() && http_value[0] == ' ') { + http_value.erase(0, 1); } + // Transform field name to lower case as they are case-insensitive + std::transform(http_field.begin(), http_field.end(), http_field.begin(), ::tolower); + _httpHeader[http_field] = http_value; } @@ -163,6 +172,16 @@ void MinXmlHttpRequest::_setHttpRequestHeader() } +void MinXmlHttpRequest::_setHttpRequestData(const char *data, size_t len) +{ + if (len > 0 && + (_meth.compare("post") == 0 || _meth.compare("POST") == 0 || + _meth.compare("put") == 0 || _meth.compare("PUT") == 0)) + { + _httpRequest->setRequestData(data, len); + } +} + /** * @brief Callback for HTTPRequest. Handles the response and invokes Callback. * @param sender Object which initialized callback @@ -170,7 +189,10 @@ void MinXmlHttpRequest::_setHttpRequestHeader() */ void MinXmlHttpRequest::handle_requestResponse(cocos2d::network::HttpClient *sender, cocos2d::network::HttpResponse *response) { - if(_isAborted) + _elapsedTime = 0; + _scheduler->unscheduleAllForTarget(this); + + if(_isAborted || _readyState == UNSENT) { return; } @@ -187,11 +209,13 @@ void MinXmlHttpRequest::handle_requestResponse(cocos2d::network::HttpClient *sen if (!response->isSucceed()) { CCLOG("Response failed, error buffer: %s", response->getErrorBuffer()); - if (statusCode == 0) + if (statusCode == 0 || statusCode == -1) { _errorFlag = true; _status = 0; _statusText.clear(); + _notify(_onerrorCallback); + _notify(_onloadendCallback); return; } } @@ -218,26 +242,10 @@ void MinXmlHttpRequest::handle_requestResponse(cocos2d::network::HttpClient *sen _data = (char*) malloc(_dataSize + 1); _data[_dataSize] = '\0'; memcpy((void*)_data, (const void*)buffer->data(), _dataSize); - - js_proxy_t * p; - void* ptr = (void*)this; - p = jsb_get_native_proxy(ptr); - if(p) - { - JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - - if (_onreadystateCallback) - { - JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - //JS_IsExceptionPending(cx) && JS_ReportPendingException(cx); - jsval fval = OBJECT_TO_JSVAL(_onreadystateCallback); - jsval out; - JS_CallFunctionValue(cx, NULL, fval, 0, NULL, &out); - } - - } - + _notify(_onreadystateCallback); + _notify(_onloadCallback); + _notify(_onloadendCallback); } /** * @brief Send out request and fire callback when done. @@ -262,11 +270,18 @@ MinXmlHttpRequest::MinXmlHttpRequest() , _data(nullptr) , _dataSize() , _onreadystateCallback(nullptr) +, _onloadstartCallback(nullptr) +, _onabortCallback(nullptr) +, _onerrorCallback(nullptr) +, _onloadCallback(nullptr) +, _onloadendCallback(nullptr) +, _ontimeoutCallback(nullptr) , _readyState(UNSENT) , _status(0) , _statusText() , _responseType() , _timeout(0) +, _elapsedTime(.0) , _isAsync() , _httpRequest(new cocos2d::network::HttpRequest()) , _isNetwork(true) @@ -276,6 +291,8 @@ MinXmlHttpRequest::MinXmlHttpRequest() , _requestHeader() , _isAborted(false) { + _scheduler = cocos2d::Director::getInstance()->getScheduler(); + _scheduler->retain(); } /** @@ -284,10 +301,19 @@ MinXmlHttpRequest::MinXmlHttpRequest() */ MinXmlHttpRequest::~MinXmlHttpRequest() { - if (_onreadystateCallback != NULL) - { - JS_RemoveObjectRoot(_cx, &_onreadystateCallback); + +#define SAFE_REMOVE_OBJECT(callback) if (callback != NULL)\ + {\ + JS::RemoveObjectRoot(_cx, &callback);\ } + + SAFE_REMOVE_OBJECT(_onreadystateCallback); + SAFE_REMOVE_OBJECT(_onloadstartCallback); + SAFE_REMOVE_OBJECT(_onloadendCallback); + SAFE_REMOVE_OBJECT(_onloadCallback); + SAFE_REMOVE_OBJECT(_onerrorCallback); + SAFE_REMOVE_OBJECT(_onabortCallback); + SAFE_REMOVE_OBJECT(_ontimeoutCallback); if (_httpRequest) { @@ -296,6 +322,7 @@ MinXmlHttpRequest::~MinXmlHttpRequest() } CC_SAFE_FREE(_data); + CC_SAFE_RELEASE_NULL(_scheduler); } /** @@ -310,65 +337,66 @@ JS_BINDED_CLASS_GLUE_IMPL(MinXmlHttpRequest); */ JS_BINDED_CONSTRUCTOR_IMPL(MinXmlHttpRequest) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); MinXmlHttpRequest* req = new MinXmlHttpRequest(); req->autorelease(); js_proxy_t *p; jsval out; - JSObject *obj = JS_NewObject(cx, &MinXmlHttpRequest::js_class, MinXmlHttpRequest::js_proto, MinXmlHttpRequest::js_parent); + JSObject *obj = JS_NewObject(cx, &MinXmlHttpRequest::js_class, JS::RootedObject(cx, MinXmlHttpRequest::js_proto), JS::RootedObject(cx, MinXmlHttpRequest::js_parent)); if (obj) { JS_SetPrivate(obj, req); out = OBJECT_TO_JSVAL(obj); } - JS_SET_RVAL(cx, vp, out); + args.rval().set(out); p =jsb_new_proxy(req, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "XMLHttpRequest"); + JS::AddNamedObjectRoot(cx, &p->obj, "XMLHttpRequest"); return true; } -/** - * @brief get Callback function for Javascript - * - */ -JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, onreadystatechange) -{ - if (_onreadystateCallback) - { - JSString *tmpstr = JS_NewStringCopyZ(cx, "1"); - JS::RootedValue tmpval(cx); - tmpval = STRING_TO_JSVAL(tmpstr); - JS_SetProperty(cx, _onreadystateCallback, "readyState", tmpval); - - jsval out = OBJECT_TO_JSVAL(_onreadystateCallback); - vp.set(out); - - } - else - { - vp.set(JSVAL_NULL); - } - return true; -} /** + * @brief Get Callback function for Javascript * @brief Set Callback function coming from Javascript * - * */ -JS_BINDED_PROP_SET_IMPL(MinXmlHttpRequest, onreadystatechange) -{ - jsval callback = vp.get(); - if (callback != JSVAL_NULL) - { - _onreadystateCallback = JSVAL_TO_OBJECT(callback); - JS_AddNamedObjectRoot(cx, &_onreadystateCallback, "onreadystateCallback"); - } - return true; -} +#define GETTER_SETTER_FOR_CALLBACK_PROP(x,y) JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, x)\ +{\ + if (y)\ + {\ + jsval out = OBJECT_TO_JSVAL(y);\ + args.rval().set(out);\ + }\ + else\ + {\ + args.rval().set(JSVAL_NULL);\ + }\ + return true;\ +}\ +JS_BINDED_PROP_SET_IMPL(MinXmlHttpRequest, x)\ +{\ + jsval callback = args.get(0);\ + if (callback != JSVAL_NULL)\ + {\ + y = callback.toObjectOrNull();\ + JS::AddNamedObjectRoot(cx, &y, #y);\ + }\ + return true;\ +} + + +GETTER_SETTER_FOR_CALLBACK_PROP(onreadystatechange, _onreadystateCallback) +GETTER_SETTER_FOR_CALLBACK_PROP(onloadstart, _onloadstartCallback) +GETTER_SETTER_FOR_CALLBACK_PROP(onabort, _onabortCallback) +GETTER_SETTER_FOR_CALLBACK_PROP(onerror, _onerrorCallback) +GETTER_SETTER_FOR_CALLBACK_PROP(onload, _onloadCallback) +GETTER_SETTER_FOR_CALLBACK_PROP(onloadend, _onloadendCallback) +GETTER_SETTER_FOR_CALLBACK_PROP(ontimeout, _ontimeoutCallback) + /** * @brief upload getter - TODO @@ -377,7 +405,7 @@ JS_BINDED_PROP_SET_IMPL(MinXmlHttpRequest, onreadystatechange) */ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, upload) { - vp.set(JSVAL_NULL); + args.rval().set(JSVAL_NULL); return true; } @@ -388,32 +416,29 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, upload) */ JS_BINDED_PROP_SET_IMPL(MinXmlHttpRequest, upload) { - vp.set(JSVAL_NULL); + args.rval().set(JSVAL_NULL); return true; } /** * @brief timeout getter - TODO * - * Placeholder for further implementations */ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, timeout) { - vp.set(INT_TO_JSVAL(_timeout)); + args.rval().set(long_long_to_jsval(cx, _timeout)); return true; } /** * @brief timeout setter - TODO * - * Placeholder for further implementations */ JS_BINDED_PROP_SET_IMPL(MinXmlHttpRequest, timeout) { - jsval timeout_ms = vp.get(); - - _timeout = JSVAL_TO_INT(timeout_ms); - //curl_easy_setopt(curlHandle, CURLOPT_CONNECTTIMEOUT_MS, timeout); + long long tmp; + jsval_to_long_long(cx, args.get(0), &tmp); + _timeout = (unsigned long long)tmp; return true; } @@ -426,7 +451,7 @@ JS_BINDED_PROP_SET_IMPL(MinXmlHttpRequest, timeout) JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, responseType) { JSString* str = JS_NewStringCopyN(cx, "", 0); - vp.set(STRING_TO_JSVAL(str)); + args.rval().set(STRING_TO_JSVAL(str)); return true; } @@ -437,7 +462,7 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, responseType) */ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, responseXML) { - vp.set(JSVAL_NULL); + args.rval().set(JSVAL_NULL); return true; } @@ -448,7 +473,7 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, responseXML) */ JS_BINDED_PROP_SET_IMPL(MinXmlHttpRequest, responseType) { - jsval type = vp.get(); + jsval type = args.get(0); if (type.isString()) { JSString* str = type.toString(); bool equal; @@ -487,7 +512,7 @@ JS_BINDED_PROP_SET_IMPL(MinXmlHttpRequest, responseType) */ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, readyState) { - vp.set(INT_TO_JSVAL(_readyState)); + args.rval().set(INT_TO_JSVAL(_readyState)); return true; } @@ -498,7 +523,7 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, readyState) */ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, status) { - vp.set(INT_TO_JSVAL(_status)); + args.rval().set(INT_TO_JSVAL(_status)); return true; } @@ -513,7 +538,7 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, statusText) if (strVal != JSVAL_NULL) { - vp.set(strVal); + args.rval().set(strVal); return true; } else @@ -529,7 +554,7 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, statusText) */ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, withCredentials) { - vp.set(BOOLEAN_TO_JSVAL(_withCredentialsValue)); + args.rval().set(BOOLEAN_TO_JSVAL(_withCredentialsValue)); return true; } @@ -539,10 +564,10 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, withCredentials) */ JS_BINDED_PROP_SET_IMPL(MinXmlHttpRequest, withCredentials) { - jsval credential = vp.get(); + jsval credential = args.get(0); if (credential != JSVAL_NULL) { - _withCredentialsValue = JSVAL_TO_BOOLEAN(credential); + _withCredentialsValue = credential.toBoolean(); } return true; @@ -560,7 +585,7 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, responseText) if (strVal != JSVAL_NULL) { - vp.set(strVal); + args.rval().set(strVal); return true; } } @@ -568,7 +593,7 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, responseText) CCLOGERROR("ResponseText was empty, probably there is a network error!"); // Return an empty string - vp.set(std_string_to_jsval(cx, "")); + args.rval().set(std_string_to_jsval(cx, "")); return true; } @@ -581,13 +606,13 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, response) { if (_responseType == ResponseType::STRING) { - return _js_get_responseText(cx, id, vp); + return _js_get_responseText(cx, args); } else { if (_readyState != DONE || _errorFlag) { - vp.set(JSVAL_NULL); + args.rval().set(JSVAL_NULL); return true; } @@ -596,9 +621,15 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, response) JS::RootedValue outVal(cx); jsval strVal = std_string_to_jsval(cx, _data); - if (JS_ParseJSON(cx, JS_GetStringCharsZ(cx, JSVAL_TO_STRING(strVal)), _dataSize, &outVal)) + + //size_t utf16Count = 0; + //const jschar* utf16Buf = JS_GetStringCharsZAndLength(cx, JSVAL_TO_STRING(strVal), &utf16Count); + //bool ok = JS_ParseJSON(cx, utf16Buf, static_cast(utf16Count), &outVal); + bool ok = JS_ParseJSON(cx, JS::RootedString(cx, strVal.toString()), &outVal); + + if (ok) { - vp.set(outVal); + args.rval().set(outVal); return true; } } @@ -609,11 +640,11 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, response) memcpy((void*)tmpData, (const void*)_data, _dataSize); jsval outVal = OBJECT_TO_JSVAL(tmp); - vp.set(outVal); + args.rval().set(outVal); return true; } // by default, return text - return _js_get_responseText(cx, id, vp); + return _js_get_responseText(cx, args); } } @@ -627,15 +658,15 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, open) { if (argc >= 2) { - jsval* argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); const char* method; const char* urlstr; bool async = true; - JSString* jsMethod = JS::ToString( cx, JS::RootedValue(cx, argv[0]) ); - JSString* jsURL = JS::ToString( cx, JS::RootedValue(cx, argv[1]) ); + JSString* jsMethod = JS::ToString( cx, args.get(0) ); + JSString* jsURL = JS::ToString( cx, args.get(1) ); if (argc > 2) { - async = JS::ToBoolean( JS::RootedValue(cx, argv[2]) ); + async = JS::ToBoolean( args.get(2) ); } JSStringWrapper w1(jsMethod); @@ -653,6 +684,7 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, open) _responseType = ResponseType::JSON; } + { auto requestType = (_meth.compare("get") == 0 || _meth.compare("GET") == 0) ? cocos2d::network::HttpRequest::Type::GET : ( @@ -665,6 +697,8 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, open) _httpRequest->setUrl(_url.c_str()); } + printf("[XMLHttpRequest] %s %s\n", _meth.c_str(), _url.c_str()); + _isNetwork = true; _readyState = OPENED; _status = 0; @@ -684,7 +718,6 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, open) */ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, send) { - JSString *str = NULL; std::string data; // Clean up header map. New request, new headers! @@ -694,28 +727,60 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, send) if (argc == 1) { - if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &str)) + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (args.get(0).isString()) + { + JSStringWrapper strWrap(args.get(0).toString()); + data = strWrap.get(); + _setHttpRequestData(data.c_str(), static_cast(data.length())); + } + else if (args.get(0).isObject()) + { + JSObject *obj = args.get(0).toObjectOrNull(); + if (JS_IsArrayBufferObject(obj)) + { + _setHttpRequestData((const char *)JS_GetArrayBufferData(obj), JS_GetArrayBufferByteLength(obj)); + } + else if (JS_IsArrayBufferViewObject(obj)) + { + _setHttpRequestData((const char *)JS_GetArrayBufferViewData(obj), JS_GetArrayBufferViewByteLength(obj)); + } + else + { + return false; + } + } + else { return false; } - JSStringWrapper strWrap(str); - data = strWrap.get(); - } - - - if (data.length() > 0 && - (_meth.compare("post") == 0 || _meth.compare("POST") == 0 || - _meth.compare("put") == 0 || _meth.compare("PUT") == 0)) - { - _httpRequest->setRequestData(data.c_str(), static_cast(data.length())); } _setHttpRequestHeader(); _sendRequest(cx); + _notify(_onloadstartCallback); + + //begin schedule for timeout + if(_timeout > 0) + { + _scheduler->scheduleUpdate(this, 0, false); + } return true; } +void MinXmlHttpRequest::update(float dt) +{ + _elapsedTime += dt; + if(_elapsedTime * 1000 >= _timeout) + { + _notify(_ontimeoutCallback); + _elapsedTime = 0; + _readyState = UNSENT; + _scheduler->unscheduleAllForTarget(this); + } +} + /** * @brief abort function * @@ -730,6 +795,9 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, abort) //3.Change the state to UNSENT. _readyState = UNSENT; + + _notify(_onabortCallback); + return true; } @@ -739,6 +807,7 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, abort) */ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, getAllResponseHeaders) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); stringstream responseheaders; string responseheader; @@ -752,7 +821,7 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, getAllResponseHeaders) jsval strVal = std_string_to_jsval(cx, responseheader); if (strVal != JSVAL_NULL) { - JS_SET_RVAL(cx, vp, strVal); + args.rval().set(strVal); return true; } else @@ -772,9 +841,11 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, getResponseHeader) { JSString *header_value; - if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &header_value)) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (!args.get(0).isString()) { return false; }; + header_value = args.get(0).toString(); std::string data; JSStringWrapper strWrap(header_value); @@ -785,16 +856,17 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, getResponseHeader) streamdata << data; string value = streamdata.str(); + std::transform(value.begin(), value.end(), value.begin(), ::tolower); auto iter = _httpHeader.find(value); if (iter != _httpHeader.end()) { jsval js_ret_val = std_string_to_jsval(cx, iter->second); - JS_SET_RVAL(cx, vp, js_ret_val); + args.rval().set(js_ret_val); return true; } else { - JS_SET_RVAL(cx, vp, JSVAL_NULL); + args.rval().setUndefined(); return true; } } @@ -808,12 +880,12 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, setRequestHeader) { if (argc >= 2) { - jsval* argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); const char* field; const char* value; - JSString* jsField = JS::ToString( cx, JS::RootedValue(cx, argv[0]) ); - JSString* jsValue = JS::ToString( cx, JS::RootedValue(cx, argv[1]) ); + JSString* jsField = JS::ToString( cx, args.get(0) ); + JSString* jsValue = JS::ToString( cx, args.get(1) ); JSStringWrapper w1(jsField); JSStringWrapper w2(jsValue); @@ -846,7 +918,29 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, overrideMimeType) */ static void basic_object_finalize(JSFreeOp *freeOp, JSObject *obj) { - CCLOG("basic_object_finalize %p ...", obj); + CCLOG("basic_object_finalize %p ...", obj); +} + +void MinXmlHttpRequest::_notify(JSObject * callback) +{ + js_proxy_t * p; + void* ptr = (void*)this; + p = jsb_get_native_proxy(ptr); + + if(p) + { + JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); + + if (callback) + { + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + //JS_IsExceptionPending(cx) && JS_ReportPendingException(cx); + JS::RootedValue fval(cx, OBJECT_TO_JSVAL(callback)); + JS::RootedValue out(cx); + JS_CallFunctionValue(cx, JS::NullPtr(), fval, JS::HandleValueArray::empty(), &out); + } + + } } /** @@ -854,27 +948,34 @@ static void basic_object_finalize(JSFreeOp *freeOp, JSObject *obj) * @param cx Global Spidermonkey JS Context. * @param global Global Spidermonkey Javascript object. */ -void MinXmlHttpRequest::_js_register(JSContext *cx, JSObject *global) +void MinXmlHttpRequest::_js_register(JSContext *cx, JS::HandleObject global) { JSClass jsclass = { "XMLHttpRequest", JSCLASS_HAS_PRIVATE, JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, - basic_object_finalize, JSCLASS_NO_OPTIONAL_MEMBERS + basic_object_finalize }; MinXmlHttpRequest::js_class = jsclass; static JSPropertySpec props[] = { + JS_BINDED_PROP_DEF_ACCESSOR(MinXmlHttpRequest, onloadstart), + JS_BINDED_PROP_DEF_ACCESSOR(MinXmlHttpRequest, onabort), + JS_BINDED_PROP_DEF_ACCESSOR(MinXmlHttpRequest, onerror), + JS_BINDED_PROP_DEF_ACCESSOR(MinXmlHttpRequest, onload), + JS_BINDED_PROP_DEF_ACCESSOR(MinXmlHttpRequest, onloadend), + JS_BINDED_PROP_DEF_ACCESSOR(MinXmlHttpRequest, ontimeout), JS_BINDED_PROP_DEF_ACCESSOR(MinXmlHttpRequest, onreadystatechange), JS_BINDED_PROP_DEF_ACCESSOR(MinXmlHttpRequest, responseType), JS_BINDED_PROP_DEF_ACCESSOR(MinXmlHttpRequest, withCredentials), + JS_BINDED_PROP_DEF_ACCESSOR(MinXmlHttpRequest, timeout), JS_BINDED_PROP_DEF_GETTER(MinXmlHttpRequest, readyState), JS_BINDED_PROP_DEF_GETTER(MinXmlHttpRequest, status), JS_BINDED_PROP_DEF_GETTER(MinXmlHttpRequest, statusText), JS_BINDED_PROP_DEF_GETTER(MinXmlHttpRequest, responseText), JS_BINDED_PROP_DEF_GETTER(MinXmlHttpRequest, responseXML), JS_BINDED_PROP_DEF_GETTER(MinXmlHttpRequest, response), - {0, 0, 0, 0, 0} + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -888,8 +989,8 @@ void MinXmlHttpRequest::_js_register(JSContext *cx, JSObject *global) JS_FS_END }; - MinXmlHttpRequest::js_parent = NULL; - MinXmlHttpRequest::js_proto = JS_InitClass(cx, global, NULL, &MinXmlHttpRequest::js_class , MinXmlHttpRequest::_js_constructor, 0, props, funcs, NULL, NULL); + MinXmlHttpRequest::js_parent = nullptr; + MinXmlHttpRequest::js_proto = JS_InitClass(cx, global, JS::NullPtr(), &MinXmlHttpRequest::js_class , MinXmlHttpRequest::_js_constructor, 0, props, funcs, nullptr, nullptr); } diff --git a/frameworks/js-bindings/bindings/manual/network/XMLHTTPRequest.h b/frameworks/js-bindings/bindings/manual/network/XMLHTTPRequest.h index ca1f1ace04..dc255c9ec4 100644 --- a/frameworks/js-bindings/bindings/manual/network/XMLHTTPRequest.h +++ b/frameworks/js-bindings/bindings/manual/network/XMLHTTPRequest.h @@ -60,11 +60,17 @@ class MinXmlHttpRequest : public cocos2d::Ref JS_BINDED_CLASS_GLUE(MinXmlHttpRequest); JS_BINDED_CONSTRUCTOR(MinXmlHttpRequest); + JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, onloadstart); JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, onreadystatechange); - JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, responseType); + JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, onabort); + JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, onerror); + JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, onload); + JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, onloadend); + JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, ontimeout); JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, withCredentials); JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, upload); JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, timeout); + JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, responseType); JS_BINDED_PROP_GET(MinXmlHttpRequest, readyState); JS_BINDED_PROP_GET(MinXmlHttpRequest, status); JS_BINDED_PROP_GET(MinXmlHttpRequest, statusText); @@ -81,12 +87,14 @@ class MinXmlHttpRequest : public cocos2d::Ref void handle_requestResponse(cocos2d::network::HttpClient *sender, cocos2d::network::HttpResponse *response); - + void update(float dt); private: void _gotHeader(std::string header); void _setRequestHeader(const char* field, const char* value); void _setHttpRequestHeader(); + void _setHttpRequestData(const char *data, size_t len); void _sendRequest(JSContext *cx); + void _notify(JSObject * callback); std::string _url; JSContext* _cx; @@ -94,12 +102,19 @@ class MinXmlHttpRequest : public cocos2d::Ref std::string _type; char* _data; uint32_t _dataSize; - JSObject* _onreadystateCallback; + JS::Heap _onloadstartCallback; + JS::Heap _onabortCallback; + JS::Heap _onerrorCallback; + JS::Heap _onloadCallback; + JS::Heap _onloadendCallback; + JS::Heap _ontimeoutCallback; + JS::Heap _onreadystateCallback; int _readyState; int _status; std::string _statusText; ResponseType _responseType; - unsigned _timeout; + unsigned long long _timeout; + float _elapsedTime; bool _isAsync; cocos2d::network::HttpRequest* _httpRequest; bool _isNetwork; @@ -108,6 +123,7 @@ class MinXmlHttpRequest : public cocos2d::Ref std::unordered_map _httpHeader; std::unordered_map _requestHeader; bool _isAborted; + cocos2d::Scheduler* _scheduler; }; #endif diff --git a/frameworks/js-bindings/bindings/manual/network/jsb_socketio.cpp b/frameworks/js-bindings/bindings/manual/network/jsb_socketio.cpp index 4d1276ee03..29e1c8f39b 100644 --- a/frameworks/js-bindings/bindings/manual/network/jsb_socketio.cpp +++ b/frameworks/js-bindings/bindings/manual/network/jsb_socketio.cpp @@ -40,8 +40,8 @@ class JSB_SIOEvent : public cocos2d::Object { const jsval& getJSCallbackFunc() const; private: - jsval _jsCallback; - jsval _extraData; + JS::Heap _jsCallback; + JS::Heap _extraData; }; @@ -54,14 +54,14 @@ JSB_SIOEvent::JSB_SIOEvent() JSB_SIOEvent::~JSB_SIOEvent() { JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_RemoveValueRoot(cx, &_jsCallback); + JS::RemoveValueRoot(cx, &_jsCallback); } void JSB_SIOEvent::setJSCallbackFunc(jsval func) { _jsCallback = func; JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); // Root the callback function. - JS_AddNamedValueRoot(cx, &_jsCallback, "JSB_SIOEvent_callback_func"); + JS::AddNamedValueRoot(cx, &_jsCallback, "JSB_SIOEvent_callback_func"); } const jsval& JSB_SIOEvent::getJSCallbackFunc() const @@ -130,7 +130,8 @@ class JSB_SocketIODelegate : public SocketIO::SIODelegate { if(it != _eventRegistry.end()) { JSB_SIOEvent e = it->second; - ScriptingCore::getInstance()->executeJSFunctionWithThisObj(OBJECT_TO_JSVAL(p->obj), e.getJSCallbackFunc(), 1, &args); + JS::RootedValue rval(cx); + ScriptingCore::getInstance()->executeJSFunctionWithThisObj(JS::RootedValue(cx, OBJECT_TO_JSVAL(p->obj)), JS::RootedValue(cx, e.getJSCallbackFunc()), JS::HandleValueArray::fromMarkedLocation(1, &args), &rval); } } @@ -144,7 +145,7 @@ class JSB_SocketIODelegate : public SocketIO::SIODelegate { } private: - JSObject* _JSDelegate; + JS::Heap _JSDelegate; JSB_SIOEventRegistry _eventRegistry; @@ -167,14 +168,14 @@ bool js_cocos2dx_SocketIO_constructor(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_SocketIO_connect(JSContext* cx, uint32_t argc, jsval* vp){ CCLOG("JSB SocketIO.connect method called"); - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 1 || argc == 2) { std::string url; do { - bool ok = jsval_to_std_string(cx, argv[0], &url); + bool ok = jsval_to_std_string(cx, args.get(0), &url); JSB_PRECONDITION2( ok, cx, false, "Error processing arguments"); } while (0); @@ -191,9 +192,9 @@ bool js_cocos2dx_SocketIO_connect(JSContext* cx, uint32_t argc, jsval* vp){ HASH_FIND_PTR(_native_js_global_ht, &ret, p); if(!p) { //previous connection not found, create a new one - JSObject *obj = JS_NewObject(cx, js_cocos2dx_socketio_class, js_cocos2dx_socketio_prototype, NULL); + JSObject *obj = JS_NewObject(cx, js_cocos2dx_socketio_class, JS::RootedObject(cx, js_cocos2dx_socketio_prototype), JS::NullPtr()); p = jsb_new_proxy(ret, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "SocketIO"); + JS::AddNamedObjectRoot(cx, &p->obj, "SocketIO"); siodelegate->setJSDelegate(p->obj); } @@ -204,7 +205,8 @@ bool js_cocos2dx_SocketIO_connect(JSContext* cx, uint32_t argc, jsval* vp){ jsret = JSVAL_NULL; } } while(0); - JS_SET_RVAL(cx, vp, jsret); + + args.rval().set(jsret); return true; @@ -217,7 +219,7 @@ bool js_cocos2dx_SocketIO_connect(JSContext* cx, uint32_t argc, jsval* vp){ bool js_cocos2dx_SocketIO_send(JSContext* cx, uint32_t argc, jsval* vp){ CCLOG("JSB SocketIO.send method called"); - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL); @@ -228,7 +230,7 @@ bool js_cocos2dx_SocketIO_send(JSContext* cx, uint32_t argc, jsval* vp){ std::string payload; do { - bool ok = jsval_to_std_string(cx, argv[0], &payload); + bool ok = jsval_to_std_string(cx, args.get(0), &payload); JSB_PRECONDITION2( ok, cx, false, "Error processing arguments"); } while (0); @@ -248,7 +250,7 @@ bool js_cocos2dx_SocketIO_send(JSContext* cx, uint32_t argc, jsval* vp){ bool js_cocos2dx_SocketIO_emit(JSContext* cx, uint32_t argc, jsval* vp){ CCLOG("JSB SocketIO.emit method called"); - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL); @@ -259,14 +261,14 @@ bool js_cocos2dx_SocketIO_emit(JSContext* cx, uint32_t argc, jsval* vp){ std::string eventName; do { - bool ok = jsval_to_std_string(cx, argv[0], &eventName); + bool ok = jsval_to_std_string(cx, args.get(0), &eventName); JSB_PRECONDITION2( ok, cx, false, "Error processing arguments"); } while (0); std::string payload; do { - bool ok = jsval_to_std_string(cx, argv[1], &payload); + bool ok = jsval_to_std_string(cx, args.get(1), &payload); JSB_PRECONDITION2( ok, cx, false, "Error processing arguments"); } while (0); @@ -286,7 +288,7 @@ bool js_cocos2dx_SocketIO_emit(JSContext* cx, uint32_t argc, jsval* vp){ bool js_cocos2dx_SocketIO_disconnect(JSContext* cx, uint32_t argc, jsval* vp){ CCLOG("JSB SocketIO.disconnect method called"); - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL); @@ -295,7 +297,7 @@ bool js_cocos2dx_SocketIO_disconnect(JSContext* cx, uint32_t argc, jsval* vp){ if(argc == 0) { cobj->disconnect(); - JS_SET_RVAL(cx, vp, JSVAL_NULL); + args.rval().setUndefined(); return true; } @@ -311,8 +313,8 @@ bool js_cocos2dx_SocketIO_close(JSContext* cx, uint32_t argc, jsval* vp){ //This method was previously implemented to take care of the HTTPClient instance not being destroyed properly //SocketIO::close(); - - JS_SET_RVAL(cx, vp, JSVAL_NULL); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setUndefined(); return true; } @@ -321,10 +323,11 @@ bool js_cocos2dx_SocketIO_close(JSContext* cx, uint32_t argc, jsval* vp){ } -static bool _js_set_SIOClient_tag(JSContext* cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) +static bool _js_set_SIOClient_tag(JSContext* cx, uint32_t argc, jsval* vp) { - CCLOG("JSB SocketIO.setTag method called"); - JSObject* jsobj = obj.get(); + CCLOG("JSB SocketIO.setTag method called"); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JSObject* jsobj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(jsobj); SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); @@ -332,7 +335,7 @@ static bool _js_set_SIOClient_tag(JSContext* cx, JS::HandleObject obj, JS::Handl if (cobj) { std::string out = ""; - jsval_to_std_string(cx, vp, &out); + jsval_to_std_string(cx, args.get(0), &out); cobj->setTag(out.c_str()); return true; } else { @@ -342,16 +345,17 @@ static bool _js_set_SIOClient_tag(JSContext* cx, JS::HandleObject obj, JS::Handl } -static bool _js_get_SIOClient_tag(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +static bool _js_get_SIOClient_tag(JSContext* cx, uint32_t argc, jsval* vp) { CCLOG("JSB SocketIO.getTag method called"); - JSObject* jsobj = obj.get(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JSObject* jsobj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(jsobj); SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (cobj) { - vp.set(std_string_to_jsval(cx, cobj->getTag())); + args.rval().set(std_string_to_jsval(cx, cobj->getTag())); return true; } else { JS_ReportError(cx, "Error: SocketIO instance is invalid."); @@ -364,7 +368,7 @@ static bool _js_get_SIOClient_tag(JSContext* cx, JS::HandleObject obj, JS::Handl bool js_cocos2dx_SocketIO_on(JSContext* cx, uint32_t argc, jsval* vp){ CCLOG("JSB SocketIO.on method called"); - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL); @@ -375,20 +379,20 @@ bool js_cocos2dx_SocketIO_on(JSContext* cx, uint32_t argc, jsval* vp){ std::string eventName; do { - bool ok = jsval_to_std_string(cx, argv[0], &eventName); + bool ok = jsval_to_std_string(cx, args.get(0), &eventName); JSB_PRECONDITION2( ok, cx, false, "Error processing arguments"); } while (0); CCLOG("JSB SocketIO eventName to: '%s'", eventName.c_str()); JSB_SIOEvent tmpCobj; - tmpCobj.setJSCallbackFunc(argv[1]); + tmpCobj.setJSCallbackFunc(args.get(1)); ((JSB_SocketIODelegate *)cobj->getDelegate())->addEvent(eventName, tmpCobj); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(proxy->obj)); + args.rval().set(OBJECT_TO_JSVAL(proxy->obj)); - JS_SetReservedSlot(proxy->obj, 0, argv[1]); + JS_SetReservedSlot(proxy->obj, 0, args.get(1)); return true; } @@ -398,7 +402,7 @@ bool js_cocos2dx_SocketIO_on(JSContext* cx, uint32_t argc, jsval* vp){ } -void register_jsb_socketio(JSContext *cx, JSObject *global) { +void register_jsb_socketio(JSContext *cx, JS::HandleObject global) { js_cocos2dx_socketio_class = (JSClass *)calloc(1, sizeof(JSClass)); js_cocos2dx_socketio_class->name = "SocketIO"; @@ -413,8 +417,8 @@ void register_jsb_socketio(JSContext *cx, JSObject *global) { js_cocos2dx_socketio_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - JS_BINDED_PROP_DEF_ACCESSOR(SIOClient, tag), - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSGS("tag", _js_get_SIOClient_tag, _js_set_SIOClient_tag, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -433,15 +437,15 @@ void register_jsb_socketio(JSContext *cx, JSObject *global) { js_cocos2dx_socketio_prototype = JS_InitClass( cx, global, - NULL, + JS::NullPtr(), js_cocos2dx_socketio_class, js_cocos2dx_SocketIO_constructor, 0, // constructor - properties, + nullptr, funcs, - NULL, // no static properties + nullptr, // no static properties st_funcs); - JSObject* jsclassObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return SocketIO; })()")); + JSObject* jsclassObj = anonEvaluate(cx, global, "(function () { return SocketIO; })()").toObjectOrNull(); } diff --git a/frameworks/js-bindings/bindings/manual/network/jsb_socketio.h b/frameworks/js-bindings/bindings/manual/network/jsb_socketio.h index a3859b359b..279f54de1f 100644 --- a/frameworks/js-bindings/bindings/manual/network/jsb_socketio.h +++ b/frameworks/js-bindings/bindings/manual/network/jsb_socketio.h @@ -27,6 +27,6 @@ #include "jsapi.h" #include "jsfriendapi.h" -void register_jsb_socketio(JSContext* cx, JSObject* global); +void register_jsb_socketio(JSContext* cx, JS::HandleObject global); #endif /* defined(__jsb_socketio__) */ diff --git a/frameworks/js-bindings/bindings/manual/network/jsb_websocket.cpp b/frameworks/js-bindings/bindings/manual/network/jsb_websocket.cpp index 5aa374eb74..fdfb4993c2 100644 --- a/frameworks/js-bindings/bindings/manual/network/jsb_websocket.cpp +++ b/frameworks/js-bindings/bindings/manual/network/jsb_websocket.cpp @@ -68,7 +68,7 @@ class JSB_WebSocketDelegate : public WebSocket::Delegate JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JSObject* jsobj = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject jsobj(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); JS::RootedValue vp(cx); vp = c_string_to_jsval(cx, "open"); JS_SetProperty(cx, jsobj, "type", vp); @@ -86,7 +86,7 @@ class JSB_WebSocketDelegate : public WebSocket::Delegate JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JSObject* jsobj = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject jsobj(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); JS::RootedValue vp(cx); vp = c_string_to_jsval(cx, "message"); JS_SetProperty(cx, jsobj, "type", vp); @@ -120,7 +120,7 @@ class JSB_WebSocketDelegate : public WebSocket::Delegate JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JSObject* jsobj = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject jsobj(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); JS::RootedValue vp(cx); vp = c_string_to_jsval(cx, "close"); JS_SetProperty(cx, jsobj, "type", vp); @@ -129,7 +129,7 @@ class JSB_WebSocketDelegate : public WebSocket::Delegate ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), "onclose", 1, &args); js_proxy_t* jsproxy = jsb_get_js_proxy(p->obj); - JS_RemoveObjectRoot(cx, &jsproxy->obj); + JS::RemoveObjectRoot(cx, &jsproxy->obj); jsb_remove_proxy(p, jsproxy); CC_SAFE_DELETE(ws); } @@ -142,7 +142,7 @@ class JSB_WebSocketDelegate : public WebSocket::Delegate JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JSObject* jsobj = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject jsobj(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); JS::RootedValue vp(cx); vp = c_string_to_jsval(cx, "error"); JS_SetProperty(cx, jsobj, "type", vp); @@ -157,7 +157,7 @@ class JSB_WebSocketDelegate : public WebSocket::Delegate _JSDelegate = pJSDelegate; } private: - JSObject* _JSDelegate; + JS::Heap _JSDelegate; }; JSClass *js_cocos2dx_websocket_class; @@ -169,7 +169,7 @@ void js_cocos2dx_WebSocket_finalize(JSFreeOp *fop, JSObject *obj) { bool js_cocos2dx_extension_WebSocket_send(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); WebSocket* cobj = (WebSocket *)(proxy ? proxy->ptr : NULL); @@ -178,20 +178,20 @@ bool js_cocos2dx_extension_WebSocket_send(JSContext *cx, uint32_t argc, jsval *v if(argc == 1){ do { - if (JSVAL_IS_STRING(argv[0])) + if (args.get(0).isString()) { std::string data; - jsval_to_std_string(cx, argv[0], &data); + jsval_to_std_string(cx, args.get(0), &data); cobj->send(data); break; } - if (argv[0].isObject()) + if (args.get(0).isObject()) { uint8_t *bufdata = NULL; uint32_t len = 0; - JSObject* jsobj = JSVAL_TO_OBJECT(argv[0]); + JSObject* jsobj = args.get(0).toObjectOrNull(); if (JS_IsArrayBufferObject(jsobj)) { bufdata = JS_GetArrayBufferData(jsobj); @@ -214,7 +214,7 @@ bool js_cocos2dx_extension_WebSocket_send(JSContext *cx, uint32_t argc, jsval *v } while (0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -223,6 +223,7 @@ bool js_cocos2dx_extension_WebSocket_send(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_extension_WebSocket_close(JSContext *cx, uint32_t argc, jsval *vp){ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); WebSocket* cobj = (WebSocket *)(proxy ? proxy->ptr : NULL); @@ -230,7 +231,7 @@ bool js_cocos2dx_extension_WebSocket_close(JSContext *cx, uint32_t argc, jsval * if(argc == 0){ cobj->close(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); @@ -239,7 +240,7 @@ bool js_cocos2dx_extension_WebSocket_close(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_extension_WebSocket_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 1 || argc == 2) { @@ -247,12 +248,12 @@ bool js_cocos2dx_extension_WebSocket_constructor(JSContext *cx, uint32_t argc, j std::string url; do { - bool ok = jsval_to_std_string(cx, argv[0], &url); + bool ok = jsval_to_std_string(cx, args.get(0), &url); JSB_PRECONDITION2( ok, cx, false, "Error processing arguments"); } while (0); - JSObject *obj = JS_NewObject(cx, js_cocos2dx_websocket_class, js_cocos2dx_websocket_prototype, NULL); - + JS::RootedObject obj(cx, JS_NewObject(cx, js_cocos2dx_websocket_class, JS::RootedObject(cx, js_cocos2dx_websocket_prototype), JS::NullPtr())); + //JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, js_cocos2dx_websocket_class, args)); WebSocket* cobj = new WebSocket(); JSB_WebSocketDelegate* delegate = new JSB_WebSocketDelegate(); @@ -262,19 +263,19 @@ bool js_cocos2dx_extension_WebSocket_constructor(JSContext *cx, uint32_t argc, j { std::vector protocols; - if (JSVAL_IS_STRING(argv[1])) + if (args.get(1).isString()) { std::string protocol; do { - bool ok = jsval_to_std_string(cx, argv[1], &protocol); + bool ok = jsval_to_std_string(cx, args.get(1), &protocol); JSB_PRECONDITION2( ok, cx, false, "Error processing arguments"); } while (0); protocols.push_back(protocol); } - else if (argv[1].isObject()) + else if (args.get(1).isObject()) { bool ok = true; - JSObject* arg2 = JSVAL_TO_OBJECT(argv[1]); + JS::RootedObject arg2(cx, args.get(1).toObjectOrNull()); JSB_PRECONDITION(JS_IsArrayObject( cx, arg2 ), "Object must be an array"); uint32_t len = 0; @@ -301,18 +302,16 @@ bool js_cocos2dx_extension_WebSocket_constructor(JSContext *cx, uint32_t argc, j } - JS_DefineProperty(cx, obj, "URL", argv[0] - , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); + JS_DefineProperty(cx, obj, "URL", args.get(0), JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); //protocol not support yet (always return "") - JS_DefineProperty(cx, obj, "protocol", c_string_to_jsval(cx, "") - , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); + JS_DefineProperty(cx, obj, "protocol", JS::RootedValue(cx, c_string_to_jsval(cx, "")), JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); // link the native object with the javascript object js_proxy_t *p = jsb_new_proxy(cobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "WebSocket"); + JS::AddNamedObjectRoot(cx, &p->obj, "WebSocket"); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + args.rval().set(OBJECT_TO_JSVAL(obj)); return true; } @@ -320,15 +319,16 @@ bool js_cocos2dx_extension_WebSocket_constructor(JSContext *cx, uint32_t argc, j return false; } -static bool js_cocos2dx_extension_WebSocket_get_readyState(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +static bool js_cocos2dx_extension_WebSocket_get_readyState(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject* jsobj = obj.get(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JSObject* jsobj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(jsobj); WebSocket* cobj = (WebSocket *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (cobj) { - vp.set(INT_TO_JSVAL((int)cobj->getReadyState())); + args.rval().set(INT_TO_JSVAL((int)cobj->getReadyState())); return true; } else { JS_ReportError(cx, "Error: WebSocket instance is invalid."); @@ -336,7 +336,7 @@ static bool js_cocos2dx_extension_WebSocket_get_readyState(JSContext *cx, JS::Ha } } -void register_jsb_websocket(JSContext *cx, JSObject *global) { +void register_jsb_websocket(JSContext *cx, JS::HandleObject global) { js_cocos2dx_websocket_class = (JSClass *)calloc(1, sizeof(JSClass)); js_cocos2dx_websocket_class->name = "WebSocket"; @@ -351,8 +351,8 @@ void register_jsb_websocket(JSContext *cx, JSObject *global) { js_cocos2dx_websocket_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"readyState", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_cocos2dx_extension_WebSocket_get_readyState), NULL}, - {0, 0, 0, 0, 0} + JS_PSG("readyState", js_cocos2dx_extension_WebSocket_get_readyState, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -367,7 +367,7 @@ void register_jsb_websocket(JSContext *cx, JSObject *global) { js_cocos2dx_websocket_prototype = JS_InitClass( cx, global, - NULL, + JS::NullPtr(), js_cocos2dx_websocket_class, js_cocos2dx_extension_WebSocket_constructor, 0, // constructor properties, @@ -375,16 +375,12 @@ void register_jsb_websocket(JSContext *cx, JSObject *global) { NULL, // no static properties st_funcs); - JSObject* jsclassObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return WebSocket; })()")); + JS::RootedObject jsclassObj(cx, anonEvaluate(cx, global, "(function () { return WebSocket; })()").toObjectOrNull()); - JS_DefineProperty(cx, jsclassObj, "CONNECTING", INT_TO_JSVAL((int)WebSocket::State::CONNECTING) - , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); - JS_DefineProperty(cx, jsclassObj, "OPEN", INT_TO_JSVAL((int)WebSocket::State::OPEN) - , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); - JS_DefineProperty(cx, jsclassObj, "CLOSING", INT_TO_JSVAL((int)WebSocket::State::CLOSING) - , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); - JS_DefineProperty(cx, jsclassObj, "CLOSED", INT_TO_JSVAL((int)WebSocket::State::CLOSED) - , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); + JS_DefineProperty(cx, jsclassObj, "CONNECTING", (int)WebSocket::State::CONNECTING, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); + JS_DefineProperty(cx, jsclassObj, "OPEN", (int)WebSocket::State::OPEN, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); + JS_DefineProperty(cx, jsclassObj, "CLOSING", (int)WebSocket::State::CLOSING, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); + JS_DefineProperty(cx, jsclassObj, "CLOSED", (int)WebSocket::State::CLOSED, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); // make the class enumerable in the registered namespace //FIXME: bool found; diff --git a/frameworks/js-bindings/bindings/manual/network/jsb_websocket.h b/frameworks/js-bindings/bindings/manual/network/jsb_websocket.h index 4282ad6084..ed517b920f 100644 --- a/frameworks/js-bindings/bindings/manual/network/jsb_websocket.h +++ b/frameworks/js-bindings/bindings/manual/network/jsb_websocket.h @@ -27,6 +27,6 @@ #include "jsapi.h" #include "jsfriendapi.h" -void register_jsb_websocket(JSContext* cx, JSObject* global); +void register_jsb_websocket(JSContext* cx, JS::HandleObject global); #endif /* defined(__jsb_websocket__) */ diff --git a/frameworks/js-bindings/bindings/manual/platform/android/CCJavascriptJavaBridge.cpp b/frameworks/js-bindings/bindings/manual/platform/android/CCJavascriptJavaBridge.cpp index 845edddff9..0bc811356a 100644 --- a/frameworks/js-bindings/bindings/manual/platform/android/CCJavascriptJavaBridge.cpp +++ b/frameworks/js-bindings/bindings/manual/platform/android/CCJavascriptJavaBridge.cpp @@ -292,22 +292,23 @@ JS_BINDED_CLASS_GLUE_IMPL(JavascriptJavaBridge); */ JS_BINDED_CONSTRUCTOR_IMPL(JavascriptJavaBridge) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JavascriptJavaBridge* jsj = new JavascriptJavaBridge(); js_proxy_t *p; jsval out; - JSObject *obj = JS_NewObject(cx, &JavascriptJavaBridge::js_class, JavascriptJavaBridge::js_proto, JavascriptJavaBridge::js_parent); + JSObject *obj = JS_NewObject(cx, &JavascriptJavaBridge::js_class, JS::RootedObject(cx, JavascriptJavaBridge::js_proto), JS::RootedObject(cx, JavascriptJavaBridge::js_parent)); if (obj) { JS_SetPrivate(obj, jsj); out = OBJECT_TO_JSVAL(obj); } - JS_SET_RVAL(cx, vp, out); + args.rval().set(out); p =jsb_new_proxy(jsj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "JavascriptJavaBridge"); + JS::AddNamedObjectRoot(cx, &p->obj, "JavascriptJavaBridge"); return true; } @@ -330,7 +331,7 @@ static void basic_object_finalize(JSFreeOp *freeOp, JSObject *obj) */ JS_BINDED_FUNC_IMPL(JavascriptJavaBridge, callStaticMethod) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs argv = JS::CallArgsFromVp(argc, vp); if (argc == 3) { JSStringWrapper arg0(argv[0]); JSStringWrapper arg1(argv[1]); @@ -342,7 +343,7 @@ JS_BINDED_FUNC_IMPL(JavascriptJavaBridge, callStaticMethod) int errorCode = call.getErrorCode(); if(errorCode < 0) JS_ReportError(cx, "js_cocos2dx_JSJavaBridge : call result code: %d", errorCode); - JS_SET_RVAL(cx, vp, convertReturnValue(cx, call.getReturnValue(), call.getReturnValueType())); + argv.rval().set(convertReturnValue(cx, call.getReturnValue(), call.getReturnValueType())); return success; } } @@ -361,23 +362,23 @@ JS_BINDED_FUNC_IMPL(JavascriptJavaBridge, callStaticMethod) { case TypeInteger: double interger; - JS::ToNumber(cx, JS::RootedValue(cx, argv[index]), &interger); + JS::ToNumber(cx, argv.get(index), &interger); args[i].i = (int)interger; break; case TypeFloat: double floatNumber; - JS::ToNumber(cx, JS::RootedValue(cx, argv[index]), &floatNumber); + JS::ToNumber(cx, argv.get(index), &floatNumber); args[i].f = (float)floatNumber; break; case TypeBoolean: - args[i].z = JS::ToBoolean(JS::RootedValue(cx, argv[index])) ? JNI_TRUE : JNI_FALSE; + args[i].z = JS::ToBoolean(argv.get(index)) ? JNI_TRUE : JNI_FALSE; break; case TypeString: default: - JSStringWrapper arg(argv[index]); + JSStringWrapper arg(argv.get(index)); args[i].l = call.getEnv()->NewStringUTF(arg.get()); break; } @@ -387,7 +388,7 @@ JS_BINDED_FUNC_IMPL(JavascriptJavaBridge, callStaticMethod) int errorCode = call.getErrorCode(); if(errorCode < 0) JS_ReportError(cx, "js_cocos2dx_JSJavaBridge : call result code: %d", errorCode); - JS_SET_RVAL(cx, vp, convertReturnValue(cx, call.getReturnValue(), call.getReturnValueType())); + argv.rval().set(convertReturnValue(cx, call.getReturnValue(), call.getReturnValueType())); return success; } @@ -398,9 +399,10 @@ JS_BINDED_FUNC_IMPL(JavascriptJavaBridge, callStaticMethod) return false; } -static bool js_is_native_obj(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) { - vp.set(BOOLEAN_TO_JSVAL(true)); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setBoolean(true); return true; } @@ -408,16 +410,16 @@ static bool js_is_native_obj(JSContext *cx, JS::HandleObject obj, JS::HandleId i * @brief register JavascriptJavaBridge to be usable in js * */ -void JavascriptJavaBridge::_js_register(JSContext *cx, JSObject *global) +void JavascriptJavaBridge::_js_register(JSContext *cx, JS::HandleObject global) { JSClass jsclass = { - "JavascriptJavaBridge", JSCLASS_HAS_PRIVATE, JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub,basic_object_finalize, JSCLASS_NO_OPTIONAL_MEMBERS + "JavascriptJavaBridge", JSCLASS_HAS_PRIVATE, JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub,basic_object_finalize }; JavascriptJavaBridge::js_class = jsclass; static JSPropertySpec props[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -426,5 +428,5 @@ void JavascriptJavaBridge::_js_register(JSContext *cx, JSObject *global) }; JavascriptJavaBridge::js_parent = NULL; - JavascriptJavaBridge::js_proto = JS_InitClass(cx, global, NULL, &JavascriptJavaBridge::js_class , JavascriptJavaBridge::_js_constructor, 0, props, funcs, NULL, NULL); + JavascriptJavaBridge::js_proto = JS_InitClass(cx, global, JS::NullPtr(), &JavascriptJavaBridge::js_class , JavascriptJavaBridge::_js_constructor, 0, props, funcs, NULL, NULL); } \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/manual/platform/ios/JavaScriptObjCBridge.mm b/frameworks/js-bindings/bindings/manual/platform/ios/JavaScriptObjCBridge.mm index 783d4b695c..cedeccbf5f 100644 --- a/frameworks/js-bindings/bindings/manual/platform/ios/JavaScriptObjCBridge.mm +++ b/frameworks/js-bindings/bindings/manual/platform/ios/JavaScriptObjCBridge.mm @@ -20,13 +20,13 @@ * THE SOFTWARE. */ +#import #import "JavaScriptObjCBridge.h" #include "spidermonkey_specifics.h" #include "ScriptingCore.h" #include "js_manual_conversions.h" #include "cocos2d.h" -#import JavaScriptObjCBridge::CallInfo::~CallInfo(void) { if (m_returnType == TypeString) @@ -64,20 +64,20 @@ for(int i = 2;iobj, "JavaScriptObjCBridge"); + JS::AddNamedObjectRoot(cx, &p->obj, "JavaScriptObjCBridge"); return true; } @@ -245,41 +246,45 @@ static void basic_object_finalize(JSFreeOp *freeOp, JSObject *obj) { CCLOG("basic_object_finalize %p ...", obj); } + JS_BINDED_FUNC_IMPL(JavaScriptObjCBridge, callStaticMethod){ - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc >= 2) { - JSStringWrapper arg0(argv[0]); - JSStringWrapper arg1(argv[1]); + JSStringWrapper arg0(args.get(0)); + JSStringWrapper arg1(args.get(1)); CallInfo call(arg0.get(),arg1.get()); - bool ok = call.execute(cx,argv,argc); + bool ok = call.execute(cx,args.array(),argc); if(!ok){ JS_ReportError(cx, "js_cocos2dx_JSJavaBridge : call result code: %d", call.getErrorCode()); return false; } - JS_SET_RVAL(cx, vp, convertReturnValue(cx, call.getReturnValue(), call.getReturnValueType())); + args.rval().set(convertReturnValue(cx, call.getReturnValue(), call.getReturnValueType())); return ok; } return false; } -static bool js_is_native_obj(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) + +static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) { - vp.set(BOOLEAN_TO_JSVAL(true)); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setBoolean(true); return true; } + /** * @brief register JavascriptJavaBridge to be usable in js * */ -void JavaScriptObjCBridge::_js_register(JSContext *cx, JSObject *global) +void JavaScriptObjCBridge::_js_register(JSContext *cx, JS::HandleObject global) { JSClass jsclass = { - "JavaScriptObjCBridge", JSCLASS_HAS_PRIVATE, JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub,basic_object_finalize, JSCLASS_NO_OPTIONAL_MEMBERS + "JavaScriptObjCBridge", JSCLASS_HAS_PRIVATE, JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub,basic_object_finalize }; JavaScriptObjCBridge::js_class = jsclass; static JSPropertySpec props[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE ), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -288,7 +293,7 @@ static bool js_is_native_obj(JSContext *cx, JS::HandleObject obj, JS::HandleId i }; JavaScriptObjCBridge::js_parent = NULL; - JavaScriptObjCBridge::js_proto = JS_InitClass(cx, global, NULL, &JavaScriptObjCBridge::js_class , JavaScriptObjCBridge::_js_constructor, 0, props, funcs, NULL, NULL); + JavaScriptObjCBridge::js_proto = JS_InitClass(cx, global, JS::NullPtr(), &JavaScriptObjCBridge::js_class , JavaScriptObjCBridge::_js_constructor, 0, props, funcs, NULL, NULL); } diff --git a/frameworks/js-bindings/bindings/manual/spidermonkey_specifics.h b/frameworks/js-bindings/bindings/manual/spidermonkey_specifics.h index f781cdc661..a196189731 100644 --- a/frameworks/js-bindings/bindings/manual/spidermonkey_specifics.h +++ b/frameworks/js-bindings/bindings/manual/spidermonkey_specifics.h @@ -30,7 +30,7 @@ typedef struct js_proxy { void *ptr; - JSObject *obj; + JS::Heap obj; UT_hash_handle hh; } js_proxy_t; @@ -39,8 +39,8 @@ extern js_proxy_t *_js_native_global_ht; typedef struct js_type_class { JSClass *jsclass; - JSObject *proto; - JSObject *parentProto; + JS::Heap proto; + JS::Heap parentProto; } js_type_class_t; extern std::unordered_map _js_global_type_map; diff --git a/frameworks/js-bindings/bindings/manual/spine/jsb_cocos2dx_spine_manual.cpp b/frameworks/js-bindings/bindings/manual/spine/jsb_cocos2dx_spine_manual.cpp index 5d20b05fa0..22881421c7 100644 --- a/frameworks/js-bindings/bindings/manual/spine/jsb_cocos2dx_spine_manual.cpp +++ b/frameworks/js-bindings/bindings/manual/spine/jsb_cocos2dx_spine_manual.cpp @@ -30,12 +30,12 @@ using namespace spine; jsval speventdata_to_jsval(JSContext* cx, spEventData& v) { - JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "name", c_string_to_jsval(cx, v.name), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "intValue", INT_TO_JSVAL(v.intValue), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "floatValue", DOUBLE_TO_JSVAL(v.floatValue), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "stringValue", c_string_to_jsval(cx, v.stringValue), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "name", JS::RootedValue(cx, c_string_to_jsval(cx, v.name)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "intValue", v.intValue, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "floatValue", v.floatValue, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "stringValue", JS::RootedValue(cx, c_string_to_jsval(cx, v.stringValue)), JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -46,13 +46,13 @@ jsval speventdata_to_jsval(JSContext* cx, spEventData& v) jsval spevent_to_jsval(JSContext* cx, spEvent& v) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "data", speventdata_to_jsval(cx, *v.data), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "intValue", INT_TO_JSVAL(v.intValue), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "floatValue", DOUBLE_TO_JSVAL(v.floatValue), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "stringValue", c_string_to_jsval(cx, v.stringValue), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "data", JS::RootedValue(cx, speventdata_to_jsval(cx, *v.data)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "intValue", v.intValue, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "floatValue", v.floatValue, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "stringValue", JS::RootedValue(cx, c_string_to_jsval(cx, v.stringValue)), JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -64,24 +64,24 @@ jsval spevent_to_jsval(JSContext* cx, spEvent& v) jsval spbonedata_to_jsval(JSContext* cx, const spBoneData* v) { - JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; // root haven't parent - jsval parentVal = JSVAL_NULL; + JS::RootedValue parentVal(cx); if (strcmp(v->name, "root")) parentVal = spbonedata_to_jsval(cx, v->parent); - bool ok = JS_DefineProperty(cx, tmp, "name", c_string_to_jsval(cx, v->name), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "parent", parentVal, NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "length", DOUBLE_TO_JSVAL(v->length), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "x", DOUBLE_TO_JSVAL(v->x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "y", DOUBLE_TO_JSVAL(v->y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "rotation", DOUBLE_TO_JSVAL(v->rotation), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "scaleX", DOUBLE_TO_JSVAL(v->scaleX), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "scaleY", DOUBLE_TO_JSVAL(v->scaleY), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "inheritScale", INT_TO_JSVAL(v->inheritScale), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "inheritRotation", INT_TO_JSVAL(v->inheritRotation), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "name", JS::RootedValue(cx, c_string_to_jsval(cx, v->name)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "parent", parentVal,JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "length", v->length, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "x", v->x, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "y", v->y, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "rotation", v->rotation, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "scaleX", v->scaleX, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "scaleY", v->scaleY, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "inheritScale", v->inheritScale, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "inheritRotation", v->inheritRotation, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -93,30 +93,30 @@ jsval spbonedata_to_jsval(JSContext* cx, const spBoneData* v) jsval spbone_to_jsval(JSContext* cx, spBone& v) { - JSObject* tmp =JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; // root haven't parent - jsval parentVal = JSVAL_NULL; + JS::RootedValue parentVal(cx); if (strcmp(v.data->name, "root")) parentVal = spbone_to_jsval(cx, *v.parent); - bool ok = JS_DefineProperty(cx, tmp, "data", spbonedata_to_jsval(cx, v.data), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "parent", parentVal, NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "x", DOUBLE_TO_JSVAL(v.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "y", DOUBLE_TO_JSVAL(v.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "rotation", DOUBLE_TO_JSVAL(v.rotation), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "scaleX", DOUBLE_TO_JSVAL(v.scaleX), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "scaleY", DOUBLE_TO_JSVAL(v.scaleY), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "m00", DOUBLE_TO_JSVAL(v.m00), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "m01", DOUBLE_TO_JSVAL(v.m01), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "worldX", DOUBLE_TO_JSVAL(v.worldX), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "m10", DOUBLE_TO_JSVAL(v.m10), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "m11", DOUBLE_TO_JSVAL(v.m11), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "worldY", DOUBLE_TO_JSVAL(v.worldY), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "worldRotation", DOUBLE_TO_JSVAL(v.worldRotation), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "worldScaleX", DOUBLE_TO_JSVAL(v.worldScaleX), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "worldScaleY", DOUBLE_TO_JSVAL(v.worldScaleY), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "data", JS::RootedValue(cx, spbonedata_to_jsval(cx, v.data)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "parent", parentVal, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "x", v.x, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "y", v.y, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "rotation", v.rotation, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "scaleX", v.scaleX, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "scaleY", v.scaleY, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "m00", v.m00, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "m01", v.m01, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "worldX", v.worldX, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "m10", v.m10, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "m11", v.m11, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "worldY", v.worldY, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "worldRotation", v.worldRotation, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "worldScaleX", v.worldScaleX, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "worldScaleY", v.worldScaleY, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -128,16 +128,16 @@ jsval spbone_to_jsval(JSContext* cx, spBone& v) jsval spskeleton_to_jsval(JSContext* cx, spSkeleton& v) { - JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "x", DOUBLE_TO_JSVAL(v.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "y", DOUBLE_TO_JSVAL(v.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "flipX", DOUBLE_TO_JSVAL(v.flipX), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "flipY", DOUBLE_TO_JSVAL(v.flipY), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "time", DOUBLE_TO_JSVAL(v.time), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "boneCount", INT_TO_JSVAL(v.bonesCount), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "slotCount", INT_TO_JSVAL(v.slotsCount), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "x", v.x, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "y", v.y, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "flipX", v.flipX, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "flipY", v.flipY, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "time", v.time, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "boneCount", v.bonesCount, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "slotCount", v.slotsCount, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -149,11 +149,11 @@ jsval spskeleton_to_jsval(JSContext* cx, spSkeleton& v) jsval spattachment_to_jsval(JSContext* cx, spAttachment& v) { - JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "name", c_string_to_jsval(cx, v.name), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "type", INT_TO_JSVAL(v.type), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "name", JS::RootedValue(cx, c_string_to_jsval(cx, v.name)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "type", v.type, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -165,17 +165,17 @@ jsval spattachment_to_jsval(JSContext* cx, spAttachment& v) jsval spslotdata_to_jsval(JSContext* cx, spSlotData& v) { - JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "name", c_string_to_jsval(cx, v.name), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "attachmentName", c_string_to_jsval(cx, v.attachmentName), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "r", DOUBLE_TO_JSVAL(v.r), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "g", DOUBLE_TO_JSVAL(v.g), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "b", DOUBLE_TO_JSVAL(v.b), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "a", DOUBLE_TO_JSVAL(v.a), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "additiveBlending", INT_TO_JSVAL(v.additiveBlending), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "boneData", spbonedata_to_jsval(cx, v.boneData), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "name", JS::RootedValue(cx, c_string_to_jsval(cx, v.name)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "attachmentName", JS::RootedValue(cx, c_string_to_jsval(cx, v.attachmentName)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "r", v.r, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "g", v.g, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "b", v.b, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "a", v.a, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "additiveBlending", v.additiveBlending, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "boneData", JS::RootedValue(cx, spbonedata_to_jsval(cx, v.boneData)), JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -187,17 +187,17 @@ jsval spslotdata_to_jsval(JSContext* cx, spSlotData& v) jsval spslot_to_jsval(JSContext* cx, spSlot& v) { - JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "r", DOUBLE_TO_JSVAL(v.r), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "g", DOUBLE_TO_JSVAL(v.g), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "b", DOUBLE_TO_JSVAL(v.b), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "a", DOUBLE_TO_JSVAL(v.a), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "bone", spbone_to_jsval(cx, *v.bone), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - //JS_DefineProperty(cx, tmp, "skeleton", spskeleton_to_jsval(cx, *v.skeleton), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "attachment", spattachment_to_jsval(cx, *v.attachment), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "data", spslotdata_to_jsval(cx, *v.data), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "r", v.r, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "g", v.g, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "b", v.b, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "a", v.a, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "bone", JS::RootedValue(cx, spbone_to_jsval(cx, *v.bone)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + //JS_DefineProperty(cx, tmp, "skeleton", spskeleton_to_jsval(cx, *v.skeleton), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "attachment", JS::RootedValue(cx, spattachment_to_jsval(cx, *v.attachment)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "data", JS::RootedValue(cx, spslotdata_to_jsval(cx, *v.data)), JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -209,10 +209,10 @@ jsval spslot_to_jsval(JSContext* cx, spSlot& v) jsval sptimeline_to_jsval(JSContext* cx, spTimeline& v) { - JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "type", int32_to_jsval(cx, v.type), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "type", v.type, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -224,11 +224,11 @@ jsval sptimeline_to_jsval(JSContext* cx, spTimeline& v) jsval spanimationstate_to_jsval(JSContext* cx, spAnimationState& v) { - JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "timeScale", DOUBLE_TO_JSVAL(v.timeScale), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "trackCount", DOUBLE_TO_JSVAL(v.tracksCount), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "timeScale", v.timeScale, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "trackCount", v.tracksCount, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -240,13 +240,13 @@ jsval spanimationstate_to_jsval(JSContext* cx, spAnimationState& v) jsval spanimation_to_jsval(JSContext* cx, spAnimation& v) { - JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "duration", DOUBLE_TO_JSVAL(v.duration), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "timelineCount", INT_TO_JSVAL(v.timelinesCount), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "name", c_string_to_jsval(cx, v.name), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "timelines", sptimeline_to_jsval(cx, **v.timelines), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "duration", v.duration, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "timelineCount", v.timelinesCount, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "name", JS::RootedValue(cx, c_string_to_jsval(cx, v.name)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "timelines", JS::RootedValue(cx, sptimeline_to_jsval(cx, **v.timelines)), JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -258,27 +258,27 @@ jsval spanimation_to_jsval(JSContext* cx, spAnimation& v) jsval sptrackentry_to_jsval(JSContext* cx, spTrackEntry& v) { - JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - jsval nextVal = JSVAL_NULL; + JS::RootedValue nextVal(cx); if (v.next) nextVal = sptrackentry_to_jsval(cx, *v.next); - jsval previousVal = JSVAL_NULL; + JS::RootedValue previousVal(cx); if (v.previous) previousVal = sptrackentry_to_jsval(cx, *v.previous); - bool ok = JS_DefineProperty(cx, tmp, "delay", DOUBLE_TO_JSVAL(v.delay), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "time", DOUBLE_TO_JSVAL(v.time), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "lastTime", DOUBLE_TO_JSVAL(v.lastTime), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "endTime", DOUBLE_TO_JSVAL(v.endTime), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "timeScale", DOUBLE_TO_JSVAL(v.timeScale), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "mixTime", DOUBLE_TO_JSVAL(v.mixTime), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "mixDuration", DOUBLE_TO_JSVAL(v.mixDuration), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "animation", spanimation_to_jsval(cx, *v.animation), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "next", nextVal, NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "previous", previousVal, NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "delay", v.delay, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "time", v.time, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "lastTime", v.lastTime, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "endTime", v.endTime, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "timeScale", v.timeScale, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "mixTime", v.mixTime, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "mixDuration", v.mixDuration, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "animation", JS::RootedValue(cx, spanimation_to_jsval(cx, *v.animation)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "next", nextVal, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "previous", previousVal, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -290,7 +290,7 @@ jsval sptrackentry_to_jsval(JSContext* cx, spTrackEntry& v) bool jsb_cocos2dx_spine_findBone(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -298,7 +298,7 @@ bool jsb_cocos2dx_spine_findBone(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); spBone* ret = cobj->findBone(arg0); jsval jsret = JSVAL_NULL; @@ -309,7 +309,7 @@ bool jsb_cocos2dx_spine_findBone(JSContext *cx, uint32_t argc, jsval *vp) } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -319,7 +319,7 @@ bool jsb_cocos2dx_spine_findBone(JSContext *cx, uint32_t argc, jsval *vp) bool jsb_cocos2dx_spine_findSlot(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -327,7 +327,7 @@ bool jsb_cocos2dx_spine_findSlot(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); spSlot* ret = cobj->findSlot(arg0); jsval jsret = JSVAL_NULL; @@ -338,7 +338,7 @@ bool jsb_cocos2dx_spine_findSlot(JSContext *cx, uint32_t argc, jsval *vp) } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -348,16 +348,16 @@ bool jsb_cocos2dx_spine_findSlot(JSContext *cx, uint32_t argc, jsval *vp) bool jsb_cocos2dx_spine_setDebugBones(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); SkeletonRenderer* cobj = (SkeletonRenderer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { - bool enable = JSVAL_TO_BOOLEAN(argv[0]); + bool enable = args.get(0).toBoolean(); cobj->setDebugBonesEnabled(enable); - JS_SET_RVAL(cx, vp, JSVAL_NULL); + args.rval().setUndefined(); return true; } @@ -367,16 +367,16 @@ bool jsb_cocos2dx_spine_setDebugBones(JSContext *cx, uint32_t argc, jsval *vp) bool jsb_cocos2dx_spine_setDebugSolots(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); SkeletonRenderer* cobj = (SkeletonRenderer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { - bool enable = JSVAL_TO_BOOLEAN(argv[0]); + bool enable = args.get(0).toBoolean(); cobj->setDebugSlotsEnabled(enable); - JS_SET_RVAL(cx, vp, JSVAL_NULL); + args.rval().setUndefined(); return true; } @@ -386,7 +386,7 @@ bool jsb_cocos2dx_spine_setDebugSolots(JSContext *cx, uint32_t argc, jsval *vp) bool jsb_cocos2dx_spine_getAttachment(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -394,9 +394,9 @@ bool jsb_cocos2dx_spine_getAttachment(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 2) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); const char* arg1; - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); spAttachment* ret = cobj->getAttachment(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -407,7 +407,7 @@ bool jsb_cocos2dx_spine_getAttachment(JSContext *cx, uint32_t argc, jsval *vp) } } while(0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -417,7 +417,7 @@ bool jsb_cocos2dx_spine_getAttachment(JSContext *cx, uint32_t argc, jsval *vp) bool jsb_cocos2dx_spine_getCurrent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -425,7 +425,7 @@ bool jsb_cocos2dx_spine_getCurrent(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); spTrackEntry* ret = cobj->getCurrent(arg0); jsval jsret = JSVAL_NULL; @@ -436,7 +436,7 @@ bool jsb_cocos2dx_spine_getCurrent(JSContext *cx, uint32_t argc, jsval *vp) } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } else if (argc == 0) { @@ -449,7 +449,7 @@ bool jsb_cocos2dx_spine_getCurrent(JSContext *cx, uint32_t argc, jsval *vp) } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -459,7 +459,7 @@ bool jsb_cocos2dx_spine_getCurrent(JSContext *cx, uint32_t argc, jsval *vp) bool jsb_cocos2dx_spine_setAnimation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -467,12 +467,12 @@ bool jsb_cocos2dx_spine_setAnimation(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 3) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); const char* arg1; - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); - bool arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + bool arg2 = JS::ToBoolean(JS::RootedValue(cx, args.get(2))); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); spTrackEntry* ret = cobj->setAnimation(arg0, arg1, arg2); @@ -485,7 +485,7 @@ bool jsb_cocos2dx_spine_setAnimation(JSContext *cx, uint32_t argc, jsval *vp) } } while(0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -496,7 +496,7 @@ bool jsb_cocos2dx_spine_setAnimation(JSContext *cx, uint32_t argc, jsval *vp) bool jsb_cocos2dx_spine_addAnimation(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -504,12 +504,12 @@ bool jsb_cocos2dx_spine_addAnimation(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 3) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); const char* arg1; - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); - bool arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + bool arg2 = JS::ToBoolean(args.get(2)); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); spTrackEntry* ret = cobj->addAnimation(arg0, arg1, arg2); @@ -522,19 +522,19 @@ bool jsb_cocos2dx_spine_addAnimation(JSContext *cx, uint32_t argc, jsval *vp) } } while(0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } else if (argc == 4) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); const char* arg1; - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); - bool arg2 = JS::ToBoolean(JS::RootedValue(cx, argv[2])); + bool arg2 = JS::ToBoolean(args.get(2)); double arg3; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[3]), &arg3); + ok &= JS::ToNumber(cx, args.get(3), &arg3); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); spTrackEntry* ret = cobj->addAnimation(arg0, arg1, arg2, arg3); @@ -547,7 +547,7 @@ bool jsb_cocos2dx_spine_addAnimation(JSContext *cx, uint32_t argc, jsval *vp) } } while(0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -564,9 +564,9 @@ class JSSkeletonAnimationWrapper: public JSCallbackWrapper void animationCallbackFunc(spine::SkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount) const { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JSObject *thisObj = JSVAL_IS_VOID(_jsThisObj) ? NULL : JSVAL_TO_OBJECT(_jsThisObj); + JS::RootedObject thisObj(cx, _jsThisObj.toObjectOrNull()); js_proxy_t *proxy = js_get_or_create_proxy(cx, node); - jsval retval; + JS::RootedValue retval(cx); if (_jsCallback != JSVAL_VOID) { jsval nodeVal = OBJECT_TO_JSVAL(proxy->obj); @@ -585,50 +585,30 @@ class JSSkeletonAnimationWrapper: public JSCallbackWrapper valArr[3] = eventVal; valArr[4] = loopCountVal; - JS_AddValueRoot(cx, valArr); + //JS_AddValueRoot(cx, valArr); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS_CallFunctionValue(cx, thisObj, _jsCallback, 5, valArr, &retval); - JS_RemoveValueRoot(cx, valArr); + JS_CallFunctionValue(cx, thisObj, JS::RootedValue(cx, _jsCallback), JS::HandleValueArray::fromMarkedLocation(5, valArr), &retval); + //JS_RemoveValueRoot(cx, valArr); } } }; -static bool jsb_cocos2dx_spine_setAnimationListener(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - - spine::SkeletonAnimation* node = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( node, cx, false, "Invalid Native Object"); - if (argc == 2) { - JSSkeletonAnimationWrapper *tmpCobj = new JSSkeletonAnimationWrapper(); - jsval *argv = JS_ARGV(cx, vp); - - tmpCobj->setJSCallbackFunc(argv[1]); - tmpCobj->setJSCallbackThis(argv[0]); - - //node->setAnimationListener(tmpCobj, animationStateEvent_selector(JSSkeletonAnimationWrapper::animationCallbackFunc)); - - JS_SET_RVAL(cx, vp, JSVAL_VOID); - - return true; - } - JS_ReportError(cx, "Invalid number of arguments"); - return false; -} extern JSObject* jsb_spine_SkeletonRenderer_prototype; extern JSObject* jsb_spine_SkeletonAnimation_prototype; -void register_all_cocos2dx_spine_manual(JSContext* cx, JSObject* global) +void register_all_cocos2dx_spine_manual(JSContext* cx, JS::HandleObject global) { - JS_DefineFunction(cx, jsb_spine_SkeletonRenderer_prototype, "findBone", jsb_cocos2dx_spine_findBone, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_spine_SkeletonRenderer_prototype, "findSlot", jsb_cocos2dx_spine_findSlot, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_spine_SkeletonRenderer_prototype, "setDebugBones", jsb_cocos2dx_spine_setDebugBones, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_spine_SkeletonRenderer_prototype, "setDebugSolots", jsb_cocos2dx_spine_setDebugSolots, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_spine_SkeletonRenderer_prototype, "getAttachment", jsb_cocos2dx_spine_getAttachment, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_spine_SkeletonAnimation_prototype, "getCurrent", jsb_cocos2dx_spine_getCurrent, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_spine_SkeletonAnimation_prototype, "setAnimation", jsb_cocos2dx_spine_setAnimation, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_spine_SkeletonAnimation_prototype, "addAnimation", jsb_cocos2dx_spine_addAnimation, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_spine_SkeletonAnimation_prototype, "setAnimationListener", jsb_cocos2dx_spine_setAnimationListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS::RootedObject skeletonRenderer(cx, jsb_spine_SkeletonRenderer_prototype); + JS_DefineFunction(cx, skeletonRenderer, "findBone", jsb_cocos2dx_spine_findBone, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, skeletonRenderer, "findSlot", jsb_cocos2dx_spine_findSlot, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, skeletonRenderer, "setDebugBones", jsb_cocos2dx_spine_setDebugBones, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, skeletonRenderer, "setDebugSolots", jsb_cocos2dx_spine_setDebugSolots, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, skeletonRenderer, "getAttachment", jsb_cocos2dx_spine_getAttachment, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS::RootedObject skeletonAnimation(cx, jsb_spine_SkeletonAnimation_prototype); + JS_DefineFunction(cx, skeletonAnimation, "getCurrent", jsb_cocos2dx_spine_getCurrent, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, skeletonAnimation, "setAnimation", jsb_cocos2dx_spine_setAnimation, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, skeletonAnimation, "addAnimation", jsb_cocos2dx_spine_addAnimation, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT); + } diff --git a/frameworks/js-bindings/bindings/manual/spine/jsb_cocos2dx_spine_manual.h b/frameworks/js-bindings/bindings/manual/spine/jsb_cocos2dx_spine_manual.h index da8ef65bac..6ccf87be76 100644 --- a/frameworks/js-bindings/bindings/manual/spine/jsb_cocos2dx_spine_manual.h +++ b/frameworks/js-bindings/bindings/manual/spine/jsb_cocos2dx_spine_manual.h @@ -24,10 +24,22 @@ #ifndef __jsb_cocos2dx_spine_manual__ #define __jsb_cocos2dx_spine_manual__ - #include "jsapi.h" -#include "jsfriendapi.h" +#include "spine/spine-cocos2dx.h" + +void register_all_cocos2dx_spine_manual(JSContext* cx, JS::HandleObject global); -void register_all_cocos2dx_spine_manual(JSContext* cx, JSObject* global); +extern jsval speventdata_to_jsval(JSContext* cx, spEventData& v); +extern jsval spevent_to_jsval(JSContext* cx, spEvent& v); +extern jsval spbonedata_to_jsval(JSContext* cx, const spBoneData* v); +extern jsval spbone_to_jsval(JSContext* cx, spBone& v); +extern jsval spskeleton_to_jsval(JSContext* cx, spSkeleton& v); +extern jsval spattachment_to_jsval(JSContext* cx, spAttachment& v); +extern jsval spslotdata_to_jsval(JSContext* cx, spSlotData& v); +extern jsval spslot_to_jsval(JSContext* cx, spSlot& v); +extern jsval sptimeline_to_jsval(JSContext* cx, spTimeline& v); +extern jsval spanimationstate_to_jsval(JSContext* cx, spAnimationState& v); +extern jsval spanimation_to_jsval(JSContext* cx, spAnimation& v); +extern jsval sptrackentry_to_jsval(JSContext* cx, spTrackEntry& v); #endif /* defined(__jsb_cocos2dx_spine_manual__) */ diff --git a/frameworks/js-bindings/bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp b/frameworks/js-bindings/bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp index 7d014cbb32..07b338d760 100755 --- a/frameworks/js-bindings/bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp +++ b/frameworks/js-bindings/bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp @@ -53,7 +53,7 @@ JSStudioEventListenerWrapper::~JSStudioEventListenerWrapper() if (m_bNeedUnroot) { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_RemoveValueRoot(cx, &_jsThisObj); + JS::RemoveValueRoot(cx, &_jsThisObj); } } @@ -61,23 +61,23 @@ void JSStudioEventListenerWrapper::setJSCallbackThis(jsval jsThisObj) { JSCallbackWrapper::setJSCallbackThis(jsThisObj); - JSObject *thisObj = JSVAL_TO_OBJECT(jsThisObj); + JSObject *thisObj = jsThisObj.toObjectOrNull(); js_proxy *p = jsb_get_js_proxy(thisObj); if (!p) { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); m_bNeedUnroot = true; - m_bNeedUnroot &= JS_AddValueRoot(cx, &jsThisObj); + m_bNeedUnroot &= JS::AddValueRoot(cx, &_jsThisObj); } } void JSStudioEventListenerWrapper::eventCallbackFunc(Ref* sender,int eventType) { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JSObject *thisObj = JSVAL_IS_VOID(_jsThisObj) ? NULL : JSVAL_TO_OBJECT(_jsThisObj); + JS::RootedObject thisObj(cx, _jsThisObj.isNullOrUndefined() ? NULL : _jsThisObj.toObjectOrNull()); js_proxy_t *proxy = js_get_or_create_proxy(cx, sender); - jsval retval; - if (_jsCallback != JSVAL_VOID) + JS::RootedValue retval(cx); + if (!_jsCallback.isNullOrUndefined()) { jsval touchVal = INT_TO_JSVAL(eventType); @@ -85,12 +85,12 @@ void JSStudioEventListenerWrapper::eventCallbackFunc(Ref* sender,int eventType) valArr[0] = OBJECT_TO_JSVAL(proxy->obj); valArr[1] = touchVal; - JS_AddValueRoot(cx, valArr); + //JS::AddValueRoot(cx, valArr); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS_CallFunctionValue(cx, thisObj, _jsCallback, 2, valArr, &retval); - JS_RemoveValueRoot(cx, valArr); + JS_CallFunctionValue(cx, thisObj, JS::RootedValue(cx, _jsCallback), JS::HandleValueArray::fromMarkedLocation(2, valArr), &retval); + //JS::RemoveValueRoot(cx, valArr); } } @@ -125,7 +125,7 @@ static bool js_cocos2dx_UIWidget_addTouchEventListener(JSContext *cx, uint32_t a JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 2) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSStudioEventListenerWrapper *tmpObj = new JSStudioEventListenerWrapper(); tmpObj->autorelease(); @@ -140,8 +140,8 @@ static bool js_cocos2dx_UIWidget_addTouchEventListener(JSContext *cx, uint32_t a cocos2d::__Dictionary* dict = comp->callbacks; dict->setObject(tmpObj, "widgetTouchEvent"); - tmpObj->setJSCallbackFunc(argv[0]); - tmpObj->setJSCallbackThis(argv[1]); + tmpObj->setJSCallbackFunc(args.get(0)); + tmpObj->setJSCallbackThis(args.get(1)); cobj->addTouchEventListener(tmpObj, toucheventselector(JSStudioEventListenerWrapper::eventCallbackFunc)); @@ -158,9 +158,9 @@ static bool js_cocos2dx_UIWidget_addTouchEventListener(JSContext *cx, uint32_t a else arg[0] = JSVAL_NULL; arg[1] = int32_to_jsval(cx, (int32_t)type); - jsval rval; + JS::RootedValue rval(cx); - bool ok = func->invoke(2, arg, rval); + bool ok = func->invoke(2, arg, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -179,21 +179,23 @@ static bool js_cocos2dx_UICheckBox_addEventListener(JSContext *cx, uint32_t argc JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 2) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSStudioEventListenerWrapper *tmpObj = new JSStudioEventListenerWrapper(); tmpObj->autorelease(); - cocos2d::__Dictionary* dict = static_cast(cobj->getUserObject()); - if (nullptr == dict) + CallbacksComponent *comp = static_cast(cobj->getComponent(CallbacksComponent::NAME)); + if (nullptr == comp) { - dict = cocos2d::__Dictionary::create(); - cobj->setUserObject(dict); + comp = new CallbacksComponent(); + comp->autorelease(); + cobj->addComponent(comp); } + cocos2d::__Dictionary* dict = comp->callbacks; dict->setObject(tmpObj, "checkBoxEventListener"); - tmpObj->setJSCallbackFunc(argv[0]); - tmpObj->setJSCallbackThis(argv[1]); + tmpObj->setJSCallbackFunc(args.get(0)); + tmpObj->setJSCallbackThis(args.get(1)); cobj->addEventListenerCheckBox(tmpObj, checkboxselectedeventselector(JSStudioEventListenerWrapper::eventCallbackFunc)); @@ -210,9 +212,9 @@ static bool js_cocos2dx_UICheckBox_addEventListener(JSContext *cx, uint32_t argc else arg[0] = JSVAL_NULL; arg[1] = int32_to_jsval(cx, (int32_t)type); - jsval rval; + JS::RootedValue rval(cx); - bool ok = func->invoke(2, arg, rval); + bool ok = func->invoke(2, arg, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -231,21 +233,23 @@ static bool js_cocos2dx_UISlider_addEventListener(JSContext *cx, uint32_t argc, JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 2) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSStudioEventListenerWrapper *tmpObj = new JSStudioEventListenerWrapper(); tmpObj->autorelease(); - cocos2d::__Dictionary* dict = static_cast(cobj->getUserObject()); - if (nullptr == dict) + CallbacksComponent *comp = static_cast(cobj->getComponent(CallbacksComponent::NAME)); + if (nullptr == comp) { - dict = cocos2d::__Dictionary::create(); - cobj->setUserObject(dict); + comp = new CallbacksComponent(); + comp->autorelease(); + cobj->addComponent(comp); } + cocos2d::__Dictionary* dict = comp->callbacks; dict->setObject(tmpObj, "sliderEventListener"); - tmpObj->setJSCallbackFunc(argv[0]); - tmpObj->setJSCallbackThis(argv[1]); + tmpObj->setJSCallbackFunc(args.get(0)); + tmpObj->setJSCallbackThis(args.get(1)); cobj->addEventListenerSlider(tmpObj, sliderpercentchangedselector(JSStudioEventListenerWrapper::eventCallbackFunc)); @@ -262,9 +266,9 @@ static bool js_cocos2dx_UISlider_addEventListener(JSContext *cx, uint32_t argc, else arg[0] = JSVAL_NULL; arg[1] = int32_to_jsval(cx, (int32_t)type); - jsval rval; + JS::RootedValue rval(cx); - bool ok = func->invoke(2, arg, rval); + bool ok = func->invoke(2, arg, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -283,21 +287,23 @@ static bool js_cocos2dx_UITextField_addEventListener(JSContext *cx, uint32_t arg JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 2) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSStudioEventListenerWrapper *tmpObj = new JSStudioEventListenerWrapper(); tmpObj->autorelease(); - cocos2d::__Dictionary* dict = static_cast(cobj->getUserObject()); - if (nullptr == dict) + CallbacksComponent *comp = static_cast(cobj->getComponent(CallbacksComponent::NAME)); + if (nullptr == comp) { - dict = cocos2d::__Dictionary::create(); - cobj->setUserObject(dict); + comp = new CallbacksComponent(); + comp->autorelease(); + cobj->addComponent(comp); } + cocos2d::__Dictionary* dict = comp->callbacks; dict->setObject(tmpObj, "textfieldEventListener"); - tmpObj->setJSCallbackFunc(argv[0]); - tmpObj->setJSCallbackThis(argv[1]); + tmpObj->setJSCallbackFunc(args.get(0)); + tmpObj->setJSCallbackThis(args.get(1)); cobj->addEventListenerTextField(tmpObj, textfieldeventselector(JSStudioEventListenerWrapper::eventCallbackFunc)); @@ -314,9 +320,9 @@ static bool js_cocos2dx_UITextField_addEventListener(JSContext *cx, uint32_t arg else arg[0] = JSVAL_NULL; arg[1] = int32_to_jsval(cx, (int32_t)type); - jsval rval; + JS::RootedValue rval(cx); - bool ok = func->invoke(2, arg, rval); + bool ok = func->invoke(2, arg, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -335,21 +341,23 @@ static bool js_cocos2dx_UIPageView_addEventListener(JSContext *cx, uint32_t argc JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 2) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSStudioEventListenerWrapper *tmpObj = new JSStudioEventListenerWrapper(); tmpObj->autorelease(); - cocos2d::__Dictionary* dict = static_cast(cobj->getUserObject()); - if (nullptr == dict) + CallbacksComponent *comp = static_cast(cobj->getComponent(CallbacksComponent::NAME)); + if (nullptr == comp) { - dict = cocos2d::__Dictionary::create(); - cobj->setUserObject(dict); + comp = new CallbacksComponent(); + comp->autorelease(); + cobj->addComponent(comp); } + cocos2d::__Dictionary* dict = comp->callbacks; dict->setObject(tmpObj, "pageViewEventListener"); - tmpObj->setJSCallbackFunc(argv[0]); - tmpObj->setJSCallbackThis(argv[1]); + tmpObj->setJSCallbackFunc(args.get(0)); + tmpObj->setJSCallbackThis(args.get(1)); cobj->addEventListenerPageView(tmpObj, pagevieweventselector(JSStudioEventListenerWrapper::eventCallbackFunc)); @@ -366,9 +374,9 @@ static bool js_cocos2dx_UIPageView_addEventListener(JSContext *cx, uint32_t argc else arg[0] = JSVAL_NULL; arg[1] = int32_to_jsval(cx, (int32_t)type); - jsval rval; + JS::RootedValue rval(cx); - bool ok = func->invoke(2, arg, rval); + bool ok = func->invoke(2, arg, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -387,21 +395,23 @@ static bool js_cocos2dx_UIScrollView_addEventListener(JSContext *cx, uint32_t ar JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 2) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSStudioEventListenerWrapper *tmpObj = new JSStudioEventListenerWrapper(); tmpObj->autorelease(); - cocos2d::__Dictionary* dict = static_cast(cobj->getUserObject()); - if (nullptr == dict) + CallbacksComponent *comp = static_cast(cobj->getComponent(CallbacksComponent::NAME)); + if (nullptr == comp) { - dict = cocos2d::__Dictionary::create(); - cobj->setUserObject(dict); + comp = new CallbacksComponent(); + comp->autorelease(); + cobj->addComponent(comp); } + cocos2d::__Dictionary* dict = comp->callbacks; dict->setObject(tmpObj, "scrollViewEventListener"); - tmpObj->setJSCallbackFunc(argv[0]); - tmpObj->setJSCallbackThis(argv[1]); + tmpObj->setJSCallbackFunc(args.get(0)); + tmpObj->setJSCallbackThis(args.get(1)); cobj->addEventListenerScrollView(tmpObj, scrollvieweventselector(JSStudioEventListenerWrapper::eventCallbackFunc)); @@ -417,9 +427,9 @@ static bool js_cocos2dx_UIScrollView_addEventListener(JSContext *cx, uint32_t ar else arg[0] = JSVAL_NULL; arg[1] = int32_to_jsval(cx, (int32_t)type); - jsval rval; + JS::RootedValue rval(cx); - bool ok = func->invoke(2, arg, rval); + bool ok = func->invoke(2, arg, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -438,21 +448,23 @@ static bool js_cocos2dx_UIListView_addEventListener(JSContext *cx, uint32_t argc JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 2) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSStudioEventListenerWrapper *tmpObj = new JSStudioEventListenerWrapper(); tmpObj->autorelease(); - cocos2d::__Dictionary* dict = static_cast(cobj->getUserObject()); - if (nullptr == dict) + CallbacksComponent *comp = static_cast(cobj->getComponent(CallbacksComponent::NAME)); + if (nullptr == comp) { - dict = cocos2d::__Dictionary::create(); - cobj->setUserObject(dict); + comp = new CallbacksComponent(); + comp->autorelease(); + cobj->addComponent(comp); } + cocos2d::__Dictionary* dict = comp->callbacks; dict->setObject(tmpObj, "listViewEventListener"); - tmpObj->setJSCallbackFunc(argv[0]); - tmpObj->setJSCallbackThis(argv[1]); + tmpObj->setJSCallbackFunc(args.get(0)); + tmpObj->setJSCallbackThis(args.get(1)); cobj->addEventListenerListView(tmpObj, listvieweventselector(JSStudioEventListenerWrapper::eventCallbackFunc)); @@ -469,9 +481,9 @@ static bool js_cocos2dx_UIListView_addEventListener(JSContext *cx, uint32_t argc else arg[0] = JSVAL_NULL; arg[1] = int32_to_jsval(cx, (int32_t)type); - jsval rval; + JS::RootedValue rval(cx); - bool ok = func->invoke(2, arg, rval); + bool ok = func->invoke(2, arg, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -514,6 +526,20 @@ static bool js_cocos2dx_LayoutParameter_setMargin(JSContext *cx, uint32_t argc, cobj->setMargin(ui::Margin(left,top,right,bottom)); return true; } + else if (argc == 4) { + JS::CallArgs argv = CallArgsFromVp(argc, vp); + bool ok = true; + double left, top,right,bottom; + ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &left); + ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &top); + ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &right); + ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[3]), &bottom); + + JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); + + cobj->setMargin(ui::Margin(left,top,right,bottom)); + return true; + } JS_ReportError(cx, "Invalid number of arguments"); return false; } @@ -526,16 +552,18 @@ static bool js_cocos2dx_LayoutParameter_getMargin(JSContext *cx, uint32_t argc, JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 0) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); if (!tmp) return false; ui::Margin margin = cobj->getMargin(); - bool ok = JS_DefineProperty(cx, tmp, "left", DOUBLE_TO_JSVAL(margin.left), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "top", DOUBLE_TO_JSVAL(margin.top), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "right", DOUBLE_TO_JSVAL(margin.right), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "bottom", DOUBLE_TO_JSVAL(margin.bottom), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + bool ok = JS_DefineProperty(cx, tmp, "left", margin.left, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "top", margin.top, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "right", margin.right, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "bottom", margin.bottom, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(tmp)); + //JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(tmp)); + args.rval().set(OBJECT_TO_JSVAL(tmp)); } else { @@ -553,7 +581,7 @@ class JSB_EditBoxDelegate { public: JSB_EditBoxDelegate() - : _JSDelegate(NULL) + : _JSDelegate(nullptr) , _needUnroot(false) {} @@ -562,7 +590,7 @@ class JSB_EditBoxDelegate if (_needUnroot) { JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_RemoveObjectRoot(cx, &_JSDelegate); + JS::RemoveObjectRoot(cx, &_JSDelegate); } } @@ -572,7 +600,7 @@ class JSB_EditBoxDelegate if (!p) return; jsval arg = OBJECT_TO_JSVAL(p->obj); - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), "editBoxEditingDidBegin", 1, &arg, NULL); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), "editBoxEditingDidBegin", 1, &arg); } virtual void editBoxEditingDidEnd(EditBox* editBox) override @@ -581,7 +609,7 @@ class JSB_EditBoxDelegate if (!p) return; jsval arg = OBJECT_TO_JSVAL(p->obj); - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), "editBoxEditingDidEnd", 1, &arg, NULL); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), "editBoxEditingDidEnd", 1, &arg); } virtual void editBoxTextChanged(EditBox* editBox, const std::string& text) override @@ -594,7 +622,7 @@ class JSB_EditBoxDelegate std::string arg1 = text; dataVal[1] = std_string_to_jsval(ScriptingCore::getInstance()->getGlobalContext(), arg1); - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), "editBoxTextChanged", 2, dataVal, NULL); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), "editBoxTextChanged", 2, dataVal); } virtual void editBoxReturn(EditBox* editBox) override @@ -603,7 +631,7 @@ class JSB_EditBoxDelegate if (!p) return; jsval arg = OBJECT_TO_JSVAL(p->obj); - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), "editBoxReturn", 1, &arg, NULL); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), "editBoxReturn", 1, &arg); } void setJSDelegate(JSObject* pJSDelegate) @@ -616,17 +644,17 @@ class JSB_EditBoxDelegate { _needUnroot = true; JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_AddNamedObjectRoot(cx, &_JSDelegate, "TableViewDelegate"); + JS::AddNamedObjectRoot(cx, &_JSDelegate, "TableViewDelegate"); } } private: - JSObject* _JSDelegate; + JS::Heap _JSDelegate; bool _needUnroot; }; static bool js_cocos2dx_CCEditBox_setDelegate(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); @@ -635,7 +663,7 @@ static bool js_cocos2dx_CCEditBox_setDelegate(JSContext *cx, uint32_t argc, jsva if (argc == 1) { // save the delegate - JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]); + JSObject *jsDelegate = args.get(0).toObjectOrNull(); JSB_EditBoxDelegate* nativeDelegate = new JSB_EditBoxDelegate(); nativeDelegate->setJSDelegate(jsDelegate); @@ -644,7 +672,7 @@ static bool js_cocos2dx_CCEditBox_setDelegate(JSContext *cx, uint32_t argc, jsva nativeDelegate->release(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); @@ -661,25 +689,25 @@ extern JSObject* jsb_cocos2d_ui_ScrollView_prototype; extern JSObject* jsb_cocos2d_ui_ListView_prototype; extern JSObject* jsb_cocos2d_ui_EditBox_prototype; -void register_all_cocos2dx_ui_manual(JSContext* cx, JSObject* global) +void register_all_cocos2dx_ui_manual(JSContext* cx, JS::HandleObject global) { - JS_DefineFunction(cx, jsb_cocos2d_ui_Widget_prototype, "addTouchEventListener", js_cocos2dx_UIWidget_addTouchEventListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), "addTouchEventListener", js_cocos2dx_UIWidget_addTouchEventListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_ui_CheckBox_prototype, "addEventListener", js_cocos2dx_UICheckBox_addEventListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_ui_CheckBox_prototype), "addEventListener", js_cocos2dx_UICheckBox_addEventListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_ui_Slider_prototype, "addEventListener", js_cocos2dx_UISlider_addEventListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_ui_Slider_prototype), "addEventListener", js_cocos2dx_UISlider_addEventListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_ui_TextField_prototype, "addEventListener", js_cocos2dx_UITextField_addEventListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_ui_TextField_prototype), "addEventListener", js_cocos2dx_UITextField_addEventListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_ui_PageView_prototype, "addEventListener", js_cocos2dx_UIPageView_addEventListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_ui_PageView_prototype), "addEventListener", js_cocos2dx_UIPageView_addEventListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_ui_ScrollView_prototype, "addEventListener", js_cocos2dx_UIScrollView_addEventListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_ui_ScrollView_prototype), "addEventListener", js_cocos2dx_UIScrollView_addEventListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_ui_ListView_prototype, "addEventListener", js_cocos2dx_UIListView_addEventListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_ui_ListView_prototype), "addEventListener", js_cocos2dx_UIListView_addEventListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_ui_LayoutParameter_prototype, "setMargin", js_cocos2dx_LayoutParameter_setMargin, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_ui_LayoutParameter_prototype), "setMargin", js_cocos2dx_LayoutParameter_setMargin, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_ui_LayoutParameter_prototype, "getMargin", js_cocos2dx_LayoutParameter_getMargin, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_ui_LayoutParameter_prototype), "getMargin", js_cocos2dx_LayoutParameter_getMargin, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_ui_EditBox_prototype, "setDelegate", js_cocos2dx_CCEditBox_setDelegate, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_ui_EditBox_prototype), "setDelegate", js_cocos2dx_CCEditBox_setDelegate, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); } diff --git a/frameworks/js-bindings/bindings/manual/ui/jsb_cocos2dx_ui_manual.h b/frameworks/js-bindings/bindings/manual/ui/jsb_cocos2dx_ui_manual.h index e20238b147..a4822433bc 100644 --- a/frameworks/js-bindings/bindings/manual/ui/jsb_cocos2dx_ui_manual.h +++ b/frameworks/js-bindings/bindings/manual/ui/jsb_cocos2dx_ui_manual.h @@ -27,6 +27,6 @@ #include "jsapi.h" #include "jsfriendapi.h" -void register_all_cocos2dx_ui_manual(JSContext* cx, JSObject* global); +void register_all_cocos2dx_ui_manual(JSContext* cx, JS::HandleObject global); #endif /* defined(__jsb_cocos2dx_ui_manual__) */ diff --git a/frameworks/js-bindings/bindings/proj.ios_mac/cocos2d_js_bindings.xcodeproj/project.pbxproj b/frameworks/js-bindings/bindings/proj.ios_mac/cocos2d_js_bindings.xcodeproj/project.pbxproj index 81ec8e2bd2..20f2298872 100644 --- a/frameworks/js-bindings/bindings/proj.ios_mac/cocos2d_js_bindings.xcodeproj/project.pbxproj +++ b/frameworks/js-bindings/bindings/proj.ios_mac/cocos2d_js_bindings.xcodeproj/project.pbxproj @@ -138,10 +138,22 @@ 1AB5E63418D05BF30088DAA4 /* jsb_cocos2dx_ui_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AB5E63118D05BF30088DAA4 /* jsb_cocos2dx_ui_manual.cpp */; }; 1AB5E63518D05BF30088DAA4 /* jsb_cocos2dx_ui_manual.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB5E63218D05BF30088DAA4 /* jsb_cocos2dx_ui_manual.h */; }; 1AB5E63618D05BF30088DAA4 /* jsb_cocos2dx_ui_manual.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB5E63218D05BF30088DAA4 /* jsb_cocos2dx_ui_manual.h */; }; + 420BBCF01AA48EDE00493976 /* jsb_cocos2dx_3d_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 420BBCEE1AA48EDE00493976 /* jsb_cocos2dx_3d_auto.cpp */; }; + 420BBCF11AA48EDE00493976 /* jsb_cocos2dx_3d_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 420BBCEE1AA48EDE00493976 /* jsb_cocos2dx_3d_auto.cpp */; }; + 420BBCF21AA48EDE00493976 /* jsb_cocos2dx_3d_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 420BBCEF1AA48EDE00493976 /* jsb_cocos2dx_3d_auto.hpp */; }; + 420BBCF31AA48EDE00493976 /* jsb_cocos2dx_3d_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 420BBCEF1AA48EDE00493976 /* jsb_cocos2dx_3d_auto.hpp */; }; + 420BBCF71AA48EE900493976 /* jsb_cocos2dx_3d_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 420BBCF51AA48EE900493976 /* jsb_cocos2dx_3d_manual.cpp */; }; + 420BBCF81AA48EE900493976 /* jsb_cocos2dx_3d_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 420BBCF51AA48EE900493976 /* jsb_cocos2dx_3d_manual.cpp */; }; + 420BBCF91AA48EE900493976 /* jsb_cocos2dx_3d_manual.h in Headers */ = {isa = PBXBuildFile; fileRef = 420BBCF61AA48EE900493976 /* jsb_cocos2dx_3d_manual.h */; }; + 420BBCFA1AA48EE900493976 /* jsb_cocos2dx_3d_manual.h in Headers */ = {isa = PBXBuildFile; fileRef = 420BBCF61AA48EE900493976 /* jsb_cocos2dx_3d_manual.h */; }; 83A5661918DA878400FC31A0 /* jsb_socketio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83A5661718DA878400FC31A0 /* jsb_socketio.cpp */; }; 83A5661A18DA878400FC31A0 /* jsb_socketio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83A5661718DA878400FC31A0 /* jsb_socketio.cpp */; }; 83A5661B18DA878400FC31A0 /* jsb_socketio.h in Headers */ = {isa = PBXBuildFile; fileRef = 83A5661818DA878400FC31A0 /* jsb_socketio.h */; }; 83A5661C18DA878400FC31A0 /* jsb_socketio.h in Headers */ = {isa = PBXBuildFile; fileRef = 83A5661818DA878400FC31A0 /* jsb_socketio.h */; }; + BA4095C21A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA4095C01A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp */; }; + BA4095C31A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA4095C01A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp */; }; + BA4095C41A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h in Headers */ = {isa = PBXBuildFile; fileRef = BA4095C11A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h */; }; + BA4095C51A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h in Headers */ = {isa = PBXBuildFile; fileRef = BA4095C11A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h */; }; BA623E09191A195F00761F37 /* jsb_pluginx_basic_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA623DFC191A195F00761F37 /* jsb_pluginx_basic_conversions.cpp */; }; BA623E0A191A195F00761F37 /* jsb_pluginx_basic_conversions.h in Headers */ = {isa = PBXBuildFile; fileRef = BA623DFD191A195F00761F37 /* jsb_pluginx_basic_conversions.h */; }; BA623E0B191A195F00761F37 /* jsb_pluginx_extension_registration.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA623DFE191A195F00761F37 /* jsb_pluginx_extension_registration.cpp */; }; @@ -157,6 +169,10 @@ BA623E15191A195F00761F37 /* uthash.h in Headers */ = {isa = PBXBuildFile; fileRef = BA623E08191A195F00761F37 /* uthash.h */; }; BA623E18191A196F00761F37 /* jsb_cocos2dx_pluginx_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA623E16191A196F00761F37 /* jsb_cocos2dx_pluginx_auto.cpp */; }; BA623E19191A196F00761F37 /* jsb_cocos2dx_pluginx_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BA623E17191A196F00761F37 /* jsb_cocos2dx_pluginx_auto.hpp */; }; + BAEE4D711AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BAEE4D6F1AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.cpp */; }; + BAEE4D721AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BAEE4D6F1AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.cpp */; }; + BAEE4D731AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BAEE4D701AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.hpp */; }; + BAEE4D741AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BAEE4D701AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.hpp */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -236,8 +252,14 @@ 1AB5E62A18D05BC80088DAA4 /* jsb_cocos2dx_ui_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_ui_auto.hpp; sourceTree = ""; }; 1AB5E63118D05BF30088DAA4 /* jsb_cocos2dx_ui_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_ui_manual.cpp; sourceTree = ""; }; 1AB5E63218D05BF30088DAA4 /* jsb_cocos2dx_ui_manual.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsb_cocos2dx_ui_manual.h; sourceTree = ""; }; + 420BBCEE1AA48EDE00493976 /* jsb_cocos2dx_3d_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_3d_auto.cpp; sourceTree = ""; }; + 420BBCEF1AA48EDE00493976 /* jsb_cocos2dx_3d_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_3d_auto.hpp; sourceTree = ""; }; + 420BBCF51AA48EE900493976 /* jsb_cocos2dx_3d_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_3d_manual.cpp; sourceTree = ""; }; + 420BBCF61AA48EE900493976 /* jsb_cocos2dx_3d_manual.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsb_cocos2dx_3d_manual.h; sourceTree = ""; }; 83A5661718DA878400FC31A0 /* jsb_socketio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_socketio.cpp; sourceTree = ""; }; 83A5661818DA878400FC31A0 /* jsb_socketio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsb_socketio.h; sourceTree = ""; }; + BA4095C01A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_studio_conversions.cpp; sourceTree = ""; }; + BA4095C11A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsb_cocos2dx_studio_conversions.h; sourceTree = ""; }; BA623DFC191A195F00761F37 /* jsb_pluginx_basic_conversions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = jsb_pluginx_basic_conversions.cpp; path = "../../cocos2d-x/plugin/jsbindings/manual/jsb_pluginx_basic_conversions.cpp"; sourceTree = ""; }; BA623DFD191A195F00761F37 /* jsb_pluginx_basic_conversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jsb_pluginx_basic_conversions.h; path = "../../cocos2d-x/plugin/jsbindings/manual/jsb_pluginx_basic_conversions.h"; sourceTree = ""; }; BA623DFE191A195F00761F37 /* jsb_pluginx_extension_registration.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = jsb_pluginx_extension_registration.cpp; path = "../../cocos2d-x/plugin/jsbindings/manual/jsb_pluginx_extension_registration.cpp"; sourceTree = ""; }; @@ -253,6 +275,8 @@ BA623E08191A195F00761F37 /* uthash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = uthash.h; path = "../../cocos2d-x/plugin/jsbindings/manual/uthash.h"; sourceTree = ""; }; BA623E16191A196F00761F37 /* jsb_cocos2dx_pluginx_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = jsb_cocos2dx_pluginx_auto.cpp; path = "../../cocos2d-x/plugin/jsbindings/auto/jsb_cocos2dx_pluginx_auto.cpp"; sourceTree = ""; }; BA623E17191A196F00761F37 /* jsb_cocos2dx_pluginx_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = jsb_cocos2dx_pluginx_auto.hpp; path = "../../cocos2d-x/plugin/jsbindings/auto/jsb_cocos2dx_pluginx_auto.hpp"; sourceTree = ""; }; + BAEE4D6F1AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_3d_extension_auto.cpp; sourceTree = ""; }; + BAEE4D701AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_3d_extension_auto.hpp; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -299,6 +323,10 @@ 1A119E2E18BDF19200352BAA /* auto */ = { isa = PBXGroup; children = ( + 420BBCEE1AA48EDE00493976 /* jsb_cocos2dx_3d_auto.cpp */, + 420BBCEF1AA48EDE00493976 /* jsb_cocos2dx_3d_auto.hpp */, + BAEE4D6F1AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.cpp */, + BAEE4D701AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.hpp */, 1A119E2F18BDF19200352BAA /* jsb_cocos2dx_auto.cpp */, 1A119E3018BDF19200352BAA /* jsb_cocos2dx_auto.hpp */, 1A119E3218BDF19200352BAA /* jsb_cocos2dx_builder_auto.cpp */, @@ -321,6 +349,7 @@ 1A119E4118BDF19200352BAA /* manual */ = { isa = PBXGroup; children = ( + 420BBCF41AA48EE900493976 /* 3d */, 0541A74C1973876100E45470 /* ios */, 1A119E4218BDF19200352BAA /* chipmunk */, 1A119E4E18BDF19200352BAA /* cocos2d_specifics.cpp */, @@ -392,6 +421,8 @@ 1A119E5618BDF19200352BAA /* Android.mk */, 1A119E5718BDF19200352BAA /* jsb_cocos2dx_studio_manual.cpp */, 1A119E5818BDF19200352BAA /* jsb_cocos2dx_studio_manual.h */, + BA4095C01A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp */, + BA4095C11A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h */, ); path = cocostudio; sourceTree = ""; @@ -485,6 +516,15 @@ path = ui; sourceTree = ""; }; + 420BBCF41AA48EE900493976 /* 3d */ = { + isa = PBXGroup; + children = ( + 420BBCF51AA48EE900493976 /* jsb_cocos2dx_3d_manual.cpp */, + 420BBCF61AA48EE900493976 /* jsb_cocos2dx_3d_manual.h */, + ); + path = 3d; + sourceTree = ""; + }; BA623DFB191A192700761F37 /* pluginx */ = { isa = PBXGroup; children = ( @@ -526,6 +566,7 @@ 1A119E8B18BDF19200352BAA /* jsb_cocos2dx_builder_auto.hpp in Headers */, 1A119EA918BDF19200352BAA /* js_bindings_chipmunk_auto_classes.h in Headers */, 1A119E9D18BDF19200352BAA /* jsb_cocos2dx_spine_auto.hpp in Headers */, + BAEE4D731AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.hpp in Headers */, 1A119EEB18BDF19200352BAA /* jsb_opengl_registration.h in Headers */, 1A119F0318BDF19200352BAA /* spidermonkey_specifics.h in Headers */, 1A119EE718BDF19200352BAA /* jsb_opengl_manual.h in Headers */, @@ -540,10 +581,13 @@ 1A119EE318BDF19200352BAA /* jsb_opengl_functions.h in Headers */, 0541A74F1973876100E45470 /* JavaScriptObjCBridge.h in Headers */, 1AB5E62D18D05BC80088DAA4 /* jsb_cocos2dx_ui_auto.hpp in Headers */, + 420BBCF91AA48EE900493976 /* jsb_cocos2dx_3d_manual.h in Headers */, 1A119ED918BDF19200352BAA /* js_bindings_opengl.h in Headers */, + BA4095C41A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h in Headers */, 1A119EC718BDF19200352BAA /* jsb_cocos2dx_studio_manual.h in Headers */, 1A119EAB18BDF19200352BAA /* js_bindings_chipmunk_auto_classes_registration.h in Headers */, 1A119EB918BDF19200352BAA /* js_bindings_chipmunk_registration.h in Headers */, + 420BBCF21AA48EDE00493976 /* jsb_cocos2dx_3d_auto.hpp in Headers */, 1A119EAF18BDF19200352BAA /* js_bindings_chipmunk_functions.h in Headers */, 1A119EB118BDF19200352BAA /* js_bindings_chipmunk_functions_registration.h in Headers */, 1A119EF118BDF19200352BAA /* js_bindings_system_functions_registration.h in Headers */, @@ -562,8 +606,10 @@ 83A5661C18DA878400FC31A0 /* jsb_socketio.h in Headers */, 1A1D3B7B18C44FD000922D3C /* jsb_event_dispatcher_manual.h in Headers */, 1A119EF618BDF19200352BAA /* js_bindings_system_registration.h in Headers */, + BA4095C51A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h in Headers */, 1A119EC018BDF19200352BAA /* cocosbuilder_specifics.hpp in Headers */, 1A119ED218BDF19200352BAA /* js_bindings_config.h in Headers */, + BAEE4D741AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.hpp in Headers */, 1A119EB618BDF19200352BAA /* js_bindings_chipmunk_manual.h in Headers */, 1A119EFA18BDF19200352BAA /* jsb_websocket.h in Headers */, 1A119E9218BDF19200352BAA /* jsb_cocos2dx_extension_auto.hpp in Headers */, @@ -588,8 +634,10 @@ 1AB5E62E18D05BC80088DAA4 /* jsb_cocos2dx_ui_auto.hpp in Headers */, 1A119EDA18BDF19200352BAA /* js_bindings_opengl.h in Headers */, 1A119EC818BDF19200352BAA /* jsb_cocos2dx_studio_manual.h in Headers */, + 420BBCFA1AA48EE900493976 /* jsb_cocos2dx_3d_manual.h in Headers */, BA623E0C191A195F00761F37 /* jsb_pluginx_extension_registration.h in Headers */, 1A119EAC18BDF19200352BAA /* js_bindings_chipmunk_auto_classes_registration.h in Headers */, + 420BBCF31AA48EDE00493976 /* jsb_cocos2dx_3d_auto.hpp in Headers */, 1A119EBA18BDF19200352BAA /* js_bindings_chipmunk_registration.h in Headers */, 1A119EB018BDF19200352BAA /* js_bindings_chipmunk_functions.h in Headers */, BA623E0E191A195F00761F37 /* jsb_pluginx_manual_callback.h in Headers */, @@ -682,6 +730,7 @@ 1A119ED318BDF19200352BAA /* js_bindings_core.cpp in Sources */, 1A119EC118BDF19200352BAA /* js_bindings_ccbreader.cpp in Sources */, 1A119EFB18BDF19200352BAA /* XMLHTTPRequest.cpp in Sources */, + BAEE4D711AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.cpp in Sources */, 1A119EC518BDF19200352BAA /* jsb_cocos2dx_studio_manual.cpp in Sources */, 1A119E8F18BDF19200352BAA /* jsb_cocos2dx_extension_auto.cpp in Sources */, 1A119ED718BDF19200352BAA /* js_bindings_opengl.cpp in Sources */, @@ -692,11 +741,14 @@ 1A119EE518BDF19200352BAA /* jsb_opengl_manual.cpp in Sources */, 1A119F0518BDF19200352BAA /* jsb_cocos2dx_spine_manual.cpp in Sources */, 1A119EB718BDF19200352BAA /* js_bindings_chipmunk_registration.cpp in Sources */, + 420BBCF71AA48EE900493976 /* jsb_cocos2dx_3d_manual.cpp in Sources */, + BA4095C21A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp in Sources */, 1A119E8318BDF19200352BAA /* jsb_cocos2dx_auto.cpp in Sources */, 1AB5E63318D05BF30088DAA4 /* jsb_cocos2dx_ui_manual.cpp in Sources */, 1A119EC918BDF19200352BAA /* jsb_cocos2dx_extension_manual.cpp in Sources */, 1A119EA118BDF19200352BAA /* jsb_cocos2dx_studio_auto.cpp in Sources */, 1A119EDB18BDF19200352BAA /* js_manual_conversions.cpp in Sources */, + 420BBCF01AA48EDE00493976 /* jsb_cocos2dx_3d_auto.cpp in Sources */, 83A5661918DA878400FC31A0 /* jsb_socketio.cpp in Sources */, 1A119EE118BDF19200352BAA /* jsb_opengl_functions.cpp in Sources */, 1A119EA718BDF19200352BAA /* js_bindings_chipmunk_auto_classes.cpp in Sources */, @@ -710,6 +762,7 @@ buildActionMask = 2147483647; files = ( 0541A75B19738AD200E45470 /* JavaScriptObjCBridge.mm in Sources */, + 420BBCF81AA48EE900493976 /* jsb_cocos2dx_3d_manual.cpp in Sources */, 1A119E8A18BDF19200352BAA /* jsb_cocos2dx_builder_auto.cpp in Sources */, 1A119EAE18BDF19200352BAA /* js_bindings_chipmunk_functions.cpp in Sources */, 1A119EEE18BDF19200352BAA /* js_bindings_system_functions.cpp in Sources */, @@ -717,6 +770,7 @@ 1A119EEA18BDF19200352BAA /* jsb_opengl_registration.cpp in Sources */, 1A119EF818BDF19200352BAA /* jsb_websocket.cpp in Sources */, 1A119ED418BDF19200352BAA /* js_bindings_core.cpp in Sources */, + 420BBCF11AA48EDE00493976 /* jsb_cocos2dx_3d_auto.cpp in Sources */, 1A119EC218BDF19200352BAA /* js_bindings_ccbreader.cpp in Sources */, 1A119EFC18BDF19200352BAA /* XMLHTTPRequest.cpp in Sources */, 1A119EC618BDF19200352BAA /* jsb_cocos2dx_studio_manual.cpp in Sources */, @@ -730,6 +784,7 @@ 1A119F0618BDF19200352BAA /* jsb_cocos2dx_spine_manual.cpp in Sources */, BA623E0F191A195F00761F37 /* jsb_pluginx_manual_protocols.cpp in Sources */, BA623E13191A195F00761F37 /* pluginxUTF8.cpp in Sources */, + BAEE4D721AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.cpp in Sources */, 1A119EB818BDF19200352BAA /* js_bindings_chipmunk_registration.cpp in Sources */, 1A119E8418BDF19200352BAA /* jsb_cocos2dx_auto.cpp in Sources */, 1AB5E63418D05BF30088DAA4 /* jsb_cocos2dx_ui_manual.cpp in Sources */, @@ -739,6 +794,7 @@ 83A5661A18DA878400FC31A0 /* jsb_socketio.cpp in Sources */, 1A119EE218BDF19200352BAA /* jsb_opengl_functions.cpp in Sources */, 1A119EA818BDF19200352BAA /* js_bindings_chipmunk_auto_classes.cpp in Sources */, + BA4095C31A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp in Sources */, BA623E0B191A195F00761F37 /* jsb_pluginx_extension_registration.cpp in Sources */, BA623E11191A195F00761F37 /* jsb_pluginx_spidermonkey_specifics.cpp in Sources */, BA623E18191A196F00761F37 /* jsb_cocos2dx_pluginx_auto.cpp in Sources */, diff --git a/frameworks/js-bindings/bindings/proj.win32/libJSBinding.vcxproj b/frameworks/js-bindings/bindings/proj.win32/libJSBinding.vcxproj index 48d1b4b5c8..4f581d7eda 100644 --- a/frameworks/js-bindings/bindings/proj.win32/libJSBinding.vcxproj +++ b/frameworks/js-bindings/bindings/proj.win32/libJSBinding.vcxproj @@ -11,18 +11,22 @@ + + + + @@ -42,12 +46,15 @@ + + + @@ -57,6 +64,7 @@ + @@ -142,7 +150,7 @@ Level3 Disabled WIN32;_WINDOWS;_DEBUG;_LIB;COCOS2D_DEBUG=1;XP_WIN;JS_HAVE___INTN;JS_INTPTR_TYPE=int;COCOS2D_JAVASCRIPT=1;CC_ENABLE_CHIPMUNK_INTEGRATION=1;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - $(ProjectDir)..;$(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\audio\include;$(EngineRoot)extensions;$(EngineRoot)external;$(ProjectDir)..\auto;$(ProjectDir)..\manual;$(ProjectDir)..\..\external\spidermonkey\include\win32;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + $(ProjectDir)..;$(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\audio\include;$(EngineRoot)extensions;$(EngineRoot)external;$(ProjectDir)..\auto;$(ProjectDir)..\manual;$(ProjectDir)..\manual\cocostudio;$(ProjectDir)..\manual\spine;$(ProjectDir)..\..\external\spidermonkey\include\win32;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) 4068;4101;4800;4251;4244;4099;4083;4700;%(DisableSpecificWarnings) true false @@ -166,7 +174,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\cocos2d-x\external\sqlite3\libraries\win32\*.*" true true WIN32;_WINDOWS;NDEBUG;_LIB;XP_WIN;JS_HAVE___INTN;JS_INTPTR_TYPE=int;COCOS2D_JAVASCRIPT=1;CC_ENABLE_CHIPMUNK_INTEGRATION=1;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - $(ProjectDir)..;$(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\audio\include;$(EngineRoot)extensions;$(EngineRoot)external;$(ProjectDir)..\auto;$(ProjectDir)..\manual;$(ProjectDir)..\..\external\spidermonkey\include\win32;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + $(ProjectDir)..;$(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\audio\include;$(EngineRoot)extensions;$(EngineRoot)external;$(ProjectDir)..\auto;$(ProjectDir)..\manual;$(ProjectDir)..\manual\cocostudio;$(ProjectDir)..\manual\spine;$(ProjectDir)..\..\external\spidermonkey\include\win32;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) 4068;4101;4800;4251;4244;4099;4083;4700;%(DisableSpecificWarnings) true diff --git a/frameworks/js-bindings/bindings/proj.win32/libJSBinding.vcxproj.filters b/frameworks/js-bindings/bindings/proj.win32/libJSBinding.vcxproj.filters index dc3360a1b2..ac28a2d61c 100644 --- a/frameworks/js-bindings/bindings/proj.win32/libJSBinding.vcxproj.filters +++ b/frameworks/js-bindings/bindings/proj.win32/libJSBinding.vcxproj.filters @@ -33,6 +33,9 @@ {db4d6533-8c6a-4a18-bdd6-c9b98b897458} + + {6a921126-b873-4314-99f1-c872271db9a8} + @@ -122,6 +125,18 @@ manual\ui + + manual\cocostudio + + + auto + + + manual\3d + + + auto + @@ -232,5 +247,17 @@ manual\ui + + manual\cocostudio + + + auto + + + manual\3d + + + auto + \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding.sln b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding.sln new file mode 100644 index 0000000000..823ab616a2 --- /dev/null +++ b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding.sln @@ -0,0 +1,60 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libJSBinding", "libJSBinding", "{93494B3A-2760-42B3-BAA1-4A600A53EEDB}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libJSBinding.Shared", "libJSBinding\libJSBinding.Shared\libJSBinding.Shared.vcxitems", "{BEA66276-51DD-4C53-92A8-F3D1FEA50892}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libJSBinding.Windows", "libJSBinding\libJSBinding.Windows\libJSBinding.Windows.vcxproj", "{BCF5546D-66A0-4998-AFD6-C5514F618930}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libJSBinding.WindowsPhone", "libJSBinding\libJSBinding.WindowsPhone\libJSBinding.WindowsPhone.vcxproj", "{CA082EC4-17CE-430B-8207-D1E947A5D1E9}" +EndProject +Global + GlobalSection(SharedMSBuildProjectFiles) = preSolution + libJSBinding\libJSBinding.Shared\libJSBinding.Shared.vcxitems*{ca082ec4-17ce-430b-8207-d1e947a5d1e9}*SharedItemsImports = 4 + libJSBinding\libJSBinding.Shared\libJSBinding.Shared.vcxitems*{bea66276-51dd-4c53-92a8-f3d1fea50892}*SharedItemsImports = 9 + libJSBinding\libJSBinding.Shared\libJSBinding.Shared.vcxitems*{bcf5546d-66a0-4998-afd6-c5514f618930}*SharedItemsImports = 4 + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM = Debug|ARM + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|ARM = Release|ARM + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|ARM.ActiveCfg = Debug|ARM + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|ARM.Build.0 = Debug|ARM + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|Win32.ActiveCfg = Debug|Win32 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|Win32.Build.0 = Debug|Win32 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|x64.ActiveCfg = Debug|x64 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|x64.Build.0 = Debug|x64 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|ARM.ActiveCfg = Release|ARM + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|ARM.Build.0 = Release|ARM + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|Win32.ActiveCfg = Release|Win32 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|Win32.Build.0 = Release|Win32 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|x64.ActiveCfg = Release|x64 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|x64.Build.0 = Release|x64 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|ARM.ActiveCfg = Debug|ARM + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|ARM.Build.0 = Debug|ARM + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|Win32.ActiveCfg = Debug|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|Win32.Build.0 = Debug|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|x64.ActiveCfg = Debug|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|ARM.ActiveCfg = Release|ARM + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|ARM.Build.0 = Release|ARM + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|Win32.ActiveCfg = Release|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|Win32.Build.0 = Release|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|x64.ActiveCfg = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {BEA66276-51DD-4C53-92A8-F3D1FEA50892} = {93494B3A-2760-42B3-BAA1-4A600A53EEDB} + {BCF5546D-66A0-4998-AFD6-C5514F618930} = {93494B3A-2760-42B3-BAA1-4A600A53EEDB} + {CA082EC4-17CE-430B-8207-D1E947A5D1E9} = {93494B3A-2760-42B3-BAA1-4A600A53EEDB} + EndGlobalSection +EndGlobal diff --git a/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Shared/libJSBinding.Shared.vcxitems b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Shared/libJSBinding.Shared.vcxitems new file mode 100644 index 0000000000..4ee5f965dc --- /dev/null +++ b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Shared/libJSBinding.Shared.vcxitems @@ -0,0 +1,106 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + {bea66276-51dd-4c53-92a8-f3d1fea50892} + libJSBinding + libJSBinding.Shared + 248F659F-DAC5-46E8-AC09-60EC9FC95053 + + + + %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Shared/libJSBinding.Shared.vcxitems.filters b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Shared/libJSBinding.Shared.vcxitems.filters new file mode 100644 index 0000000000..0727ed9b2b --- /dev/null +++ b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Shared/libJSBinding.Shared.vcxitems.filters @@ -0,0 +1,288 @@ + + + + + + auto + + + auto + + + auto + + + auto + + + auto + + + auto + + + auto + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual\chipmunk + + + manual\chipmunk + + + manual\chipmunk + + + manual\chipmunk + + + manual\chipmunk + + + manual\chipmunk + + + manual\cocosbuilder + + + manual\cocosbuilder + + + manual\cocostudio + + + manual\cocostudio + + + manual\extension + + + manual\localstorage + + + manual\localstorage + + + manual\localstorage + + + manual\network + + + manual\network + + + manual\network + + + manual\ui + + + manual\spine + + + auto + + + + + auto + + + auto + + + auto + + + auto + + + auto + + + auto + + + auto + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual\chipmunk + + + manual\chipmunk + + + manual\chipmunk + + + manual\chipmunk + + + manual\cocosbuilder + + + manual\cocostudio + + + manual\cocostudio + + + manual\extension + + + manual\localstorage + + + manual\localstorage + + + manual\network + + + manual\network + + + manual\network + + + manual\ui + + + manual\spine + + + auto + + + + + {c82eec33-f18d-4e3b-aa7e-4f75fd188ccc} + + + {69cfef88-18f0-4cc3-946e-26e1b5617cc0} + + + {68194864-f409-45ce-97d8-25ce6ffb220d} + + + {2e5c2cc9-45ed-4be9-a5df-3425a4bd9f9f} + + + {1c2fc87d-036e-4de9-a530-d6088e34e905} + + + {363afad8-dbaf-400e-b9a8-e27a06423c7c} + + + {1342560f-e950-4f9e-ad6b-253d35430ea4} + + + {c4db8dfe-e868-4e05-abf8-454496eee310} + + + {fc1ed5ab-66bf-472f-9467-06b41e3eec47} + + + {b55ad312-2220-4a48-bcf3-b048b39d8176} + + + {1455b26b-f54b-4a98-80c5-bb4cf0052afe} + + + {d5fa188f-db09-4c4b-a366-682bf76fcea2} + + + + + auto\api + + + auto\api + + + auto\api + + + auto\api + + + auto\api + + + auto\api + + + auto\api + + + \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Shared/targetver.h b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Shared/targetver.h new file mode 100644 index 0000000000..eddeeea96b --- /dev/null +++ b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Shared/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Windows/libJSBinding.Windows.vcxproj b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Windows/libJSBinding.Windows.vcxproj new file mode 100644 index 0000000000..ee64b92b55 --- /dev/null +++ b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Windows/libJSBinding.Windows.vcxproj @@ -0,0 +1,253 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM + + + Release + Win32 + + + Release + x64 + + + + {bcf5546d-66a0-4998-afd6-c5514f618930} + libJSBinding + en-US + 12.0 + true + Windows Store + 8.1 + CodeSharingStaticLibrary + + + + StaticLibrary + true + v120 + + + StaticLibrary + true + v120 + + + StaticLibrary + true + v120 + + + StaticLibrary + false + true + v120 + + + StaticLibrary + false + true + v120 + + + StaticLibrary + false + true + v120 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + false + + + false + + + false + + + false + + + false + + + + NotUsing + true + false + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support;$(EngineRoot)extensions;$(EngineRoot)\..\external\spidermonkey\include\wp8;$(ProjectDir)..\..\..\auto;$(ProjectDir)..\..\..\manual;$(ProjectDir)..\..\..\manual\cocostudio;$(ProjectDir)..\..\..\manual\spine;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + 4800;4703;4101;4083;4700;4068;%(DisableSpecificWarnings) + Level3 + CC_ENABLE_CHIPMUNK_INTEGRATION=1;_DEBUG;COCOS2D_DEBUG=1;%(PreprocessorDefinitions) + true + + + Console + false + false + + + /IGNORE:4264 %(AdditionalOptions) + + + + + NotUsing + true + false + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support;$(EngineRoot)extensions;$(EngineRoot)\..\external\spidermonkey\include\wp8;$(ProjectDir)..\..\..\auto;$(ProjectDir)..\..\..\manual;$(ProjectDir)..\..\..\manual\cocostudio;$(ProjectDir)..\..\..\manual\spine;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + 4800;4703;4101;4083;4700;4068;%(DisableSpecificWarnings) + Level3 + CC_ENABLE_CHIPMUNK_INTEGRATION=1;%(PreprocessorDefinitions) + false + OldStyle + + + Console + false + false + + + false + /IGNORE:4264 %(AdditionalOptions) + + + + + NotUsing + true + false + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support;$(EngineRoot)extensions;$(EngineRoot)\..\external\spidermonkey\include\wp8;$(ProjectDir)..\..\..\auto;$(ProjectDir)..\..\..\manual;$(ProjectDir)..\..\..\manual\cocostudio;$(ProjectDir)..\..\..\manual\spine;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + 4800;4703;4101;4083;4700;4068;%(DisableSpecificWarnings) + Level3 + CC_ENABLE_CHIPMUNK_INTEGRATION=1;_DEBUG;COCOS2D_DEBUG=1;%(PreprocessorDefinitions) + true + + + Console + false + false + + + /IGNORE:4264 %(AdditionalOptions) + + + + + NotUsing + true + false + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support;$(EngineRoot)extensions;$(EngineRoot)\..\external\spidermonkey\include\wp8;$(ProjectDir)..\..\..\auto;$(ProjectDir)..\..\..\manual;$(ProjectDir)..\..\..\manual\cocostudio;$(ProjectDir)..\..\..\manual\spine;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + 4800;4703;4101;4083;4700;4068;%(DisableSpecificWarnings) + Level3 + CC_ENABLE_CHIPMUNK_INTEGRATION=1;%(PreprocessorDefinitions) + false + OldStyle + + + Console + false + false + + + false + /IGNORE:4264 %(AdditionalOptions) + + + + + NotUsing + true + false + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support;$(EngineRoot)extensions;$(EngineRoot)\..\external\spidermonkey\include\wp8;$(ProjectDir)..\..\..\auto;$(ProjectDir)..\..\..\manual;$(ProjectDir)..\..\..\manual\cocostudio;$(ProjectDir)..\..\..\manual\spine;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + 4800;4703;4101;4083;4700;4068;%(DisableSpecificWarnings) + Level3 + CC_ENABLE_CHIPMUNK_INTEGRATION=1;_DEBUG;COCOS2D_DEBUG=1;%(PreprocessorDefinitions) + true + + + Console + false + false + + + /IGNORE:4264 %(AdditionalOptions) + + + + + NotUsing + true + false + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support;$(EngineRoot)extensions;$(EngineRoot)\..\external\spidermonkey\include\wp8;$(ProjectDir)..\..\..\auto;$(ProjectDir)..\..\..\manual;$(ProjectDir)..\..\..\manual\cocostudio;$(ProjectDir)..\..\..\manual\spine;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + 4800;4703;4101;4083;4700;4068;%(DisableSpecificWarnings) + Level3 + CC_ENABLE_CHIPMUNK_INTEGRATION=1;%(PreprocessorDefinitions) + false + OldStyle + + + Console + false + false + + + false + /IGNORE:4264 %(AdditionalOptions) + + + + + + \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Windows/libJSBinding.Windows.vcxproj.filters b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Windows/libJSBinding.Windows.vcxproj.filters new file mode 100644 index 0000000000..6ccd4c934e --- /dev/null +++ b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.Windows/libJSBinding.Windows.vcxproj.filters @@ -0,0 +1,5 @@ + + + + + diff --git a/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.WindowsPhone/libJSBinding.WindowsPhone.vcxproj b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.WindowsPhone/libJSBinding.WindowsPhone.vcxproj new file mode 100644 index 0000000000..1c3ce5317c --- /dev/null +++ b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.WindowsPhone/libJSBinding.WindowsPhone.vcxproj @@ -0,0 +1,176 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Release + ARM + + + Release + Win32 + + + + {ca082ec4-17ce-430b-8207-d1e947a5d1e9} + libJSBinding + en-US + 12.0 + true + Windows Phone + 8.1 + CodeSharingStaticLibrary + + + + StaticLibrary + true + v120_wp81 + + + StaticLibrary + true + v120_wp81 + + + StaticLibrary + false + true + v120_wp81 + + + StaticLibrary + false + true + v120_wp81 + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + false + + + false + + + false + + + + NotUsing + true + false + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support;$(EngineRoot)extensions;$(EngineRoot)\..\external\spidermonkey\include\wp8;$(ProjectDir)..\..\..\auto;$(ProjectDir)..\..\..\manual;$(ProjectDir)..\..\..\manual\cocostudio;$(ProjectDir)..\..\..\manual\spine;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + 4800;4703;4101;4083;4700;4068;%(DisableSpecificWarnings) + Level3 + CC_ENABLE_CHIPMUNK_INTEGRATION=1;_DEBUG;COCOS2D_DEBUG=1;%(PreprocessorDefinitions) + true + + + Console + false + false + + + /IGNORE:4264 %(AdditionalOptions) + + + + + NotUsing + true + false + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support;$(EngineRoot)extensions;$(EngineRoot)\..\external\spidermonkey\include\wp8;$(ProjectDir)..\..\..\auto;$(ProjectDir)..\..\..\manual;$(ProjectDir)..\..\..\manual\cocostudio;$(ProjectDir)..\..\..\manual\spine;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + 4800;4703;4101;4083;4700;4068;%(DisableSpecificWarnings) + Level3 + CC_ENABLE_CHIPMUNK_INTEGRATION=1;%(PreprocessorDefinitions) + false + OldStyle + + + Console + false + false + + + false + /IGNORE:4264 %(AdditionalOptions) + + + + + NotUsing + true + false + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support;$(EngineRoot)extensions;$(EngineRoot)\..\external\spidermonkey\include\wp8;$(ProjectDir)..\..\..\auto;$(ProjectDir)..\..\..\manual;$(ProjectDir)..\..\..\manual\cocostudio;$(ProjectDir)..\..\..\manual\spine;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + 4800;4703;4101;4083;4700;4068;%(DisableSpecificWarnings) + Level3 + CC_ENABLE_CHIPMUNK_INTEGRATION=1;_DEBUG;COCOS2D_DEBUG=1;%(PreprocessorDefinitions) + true + + + Console + false + false + + + /IGNORE:4264 %(AdditionalOptions) + + + + + NotUsing + true + false + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support;$(EngineRoot)extensions;$(EngineRoot)\..\external\spidermonkey\include\wp8;$(ProjectDir)..\..\..\auto;$(ProjectDir)..\..\..\manual;$(ProjectDir)..\..\..\manual\cocostudio;$(ProjectDir)..\..\..\manual\spine;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + 4800;4703;4101;4083;4700;4068;%(DisableSpecificWarnings) + Level3 + CC_ENABLE_CHIPMUNK_INTEGRATION=1;%(PreprocessorDefinitions) + false + OldStyle + + + Console + false + false + + + false + /IGNORE:4264 %(AdditionalOptions) + + + + + + \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.WindowsPhone/libJSBinding.WindowsPhone.vcxproj.filters b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.WindowsPhone/libJSBinding.WindowsPhone.vcxproj.filters new file mode 100644 index 0000000000..6ccd4c934e --- /dev/null +++ b/frameworks/js-bindings/bindings/proj.win8.1-universal/libJSBinding/libJSBinding.WindowsPhone/libJSBinding.WindowsPhone.vcxproj.filters @@ -0,0 +1,5 @@ + + + + + diff --git a/frameworks/js-bindings/bindings/proj.wp8/libJSBinding.user b/frameworks/js-bindings/bindings/proj.wp8/libJSBinding.user new file mode 100644 index 0000000000..17f726ed50 --- /dev/null +++ b/frameworks/js-bindings/bindings/proj.wp8/libJSBinding.user @@ -0,0 +1,6 @@ + + + + true + + \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/proj.wp8/libJSBinding.vcxproj b/frameworks/js-bindings/bindings/proj.wp8/libJSBinding.vcxproj new file mode 100644 index 0000000000..6eaf5725c2 --- /dev/null +++ b/frameworks/js-bindings/bindings/proj.wp8/libJSBinding.vcxproj @@ -0,0 +1,255 @@ + + + + + Debug + Win32 + + + Debug + ARM + + + Release + Win32 + + + Release + ARM + + + + {DD11890A-006E-4D4B-BBE6-A577601288A2} + libjsbindings_wp8 + en-US + 11.0 + + + + StaticLibrary + true + v110_wp80 + + + StaticLibrary + true + v110_wp80 + + + StaticLibrary + false + true + v110_wp80 + + + StaticLibrary + false + true + v110_wp80 + + + + + + + + + + + + + + + + + + + + false + + + + _LIB;%(PreprocessorDefinitions) + NotUsing + pch.h + $(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories) + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support;$(EngineRoot)extensions;$(EngineRoot)\..\external\spidermonkey\include\wp8;$(ProjectDir)..\auto;$(ProjectDir)..\manual;$(ProjectDir)..\manual\cocostudio;$(ProjectDir)..\manual\spine;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + WP8;_DEBUG;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;CC_ENABLE_CHIPMUNK_INTEGRATION=1;%(PreprocessorDefinitions) + 4267;4251;4244;4700;4083;4068;%(DisableSpecificWarnings) + + + /Zm200 %(AdditionalOptions) + + + Console + false + + + /IGNORE:4264 %(AdditionalOptions) + + + + + _LIB;NDEBUG;%(PreprocessorDefinitions) + NotUsing + pch.h + $(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories) + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support;$(EngineRoot)extensions;$(EngineRoot)\..\external\spidermonkey\include\wp8;$(ProjectDir)..\auto;$(ProjectDir)..\manual;$(ProjectDir)..\manual\cocostudio;$(ProjectDir)..\manual\spine;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + WP8;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;CC_ENABLE_CHIPMUNK_INTEGRATION=1;%(PreprocessorDefinitions) + + + /Zm200 %(AdditionalOptions) + 4267;4251;4244;4700;4083;4068;%(DisableSpecificWarnings) + false + + + Console + false + + + /IGNORE:4264 %(AdditionalOptions) + false + + + + + _LIB;%(PreprocessorDefinitions) + NotUsing + pch.h + $(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories) + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support;$(EngineRoot)extensions;$(EngineRoot)\..\external\spidermonkey\include\wp8;$(ProjectDir)..\auto;$(ProjectDir)..\manual;$(ProjectDir)..\manual\cocostudio;$(ProjectDir)..\manual\spine;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + WP8;_DEBUG;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;CC_ENABLE_CHIPMUNK_INTEGRATION=1;%(PreprocessorDefinitions) + 4267;4251;4244;4700;4083;4068;%(DisableSpecificWarnings) + + + /Zm200 %(AdditionalOptions) + true + + + Console + false + + + /IGNORE:4264 %(AdditionalOptions) + + + + + _LIB;NDEBUG;%(PreprocessorDefinitions) + NotUsing + pch.h + $(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories) + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\storage;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support;$(EngineRoot)extensions;$(EngineRoot)\..\external\spidermonkey\include\wp8;$(ProjectDir)..\auto;$(ProjectDir)..\manual;$(ProjectDir)..\manual\cocostudio;$(ProjectDir)..\manual\spine;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories) + WP8;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;CC_ENABLE_CHIPMUNK_INTEGRATION=1;%(PreprocessorDefinitions) + + + /Zm200 %(AdditionalOptions) + true + 4267;4251;4244;4700;4083;4068;%(DisableSpecificWarnings) + false + + + Console + false + + + /IGNORE:4264 %(AdditionalOptions) + false + + + + + true + + + true + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {7c5dbc42-27f6-4978-aabc-02ba77e2a7f0} + + + + + + + \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/proj.wp8/libJSBinding.vcxproj.filters b/frameworks/js-bindings/bindings/proj.wp8/libJSBinding.vcxproj.filters new file mode 100644 index 0000000000..bc1d74766d --- /dev/null +++ b/frameworks/js-bindings/bindings/proj.wp8/libJSBinding.vcxproj.filters @@ -0,0 +1,261 @@ + + + + + {3c8a4d4b-c651-4a7c-b646-ca5f82965a59} + + + {f4df562c-261e-4691-859d-13361244ad06} + + + {4b3109c2-a594-4bf4-a877-79d582934667} + + + {3bf7b9ca-d7ab-43c6-9c61-f6ef912b616c} + + + {21c17f2f-bd37-41ea-8e42-71e3bb28c34c} + + + {fa47668b-9915-47f9-bda5-80b4508ccb5b} + + + {4ad34514-219d-47af-8dbc-75d7cfef8aec} + + + {f1f8cb02-18d2-41af-b81b-9bcdbe67dd6b} + + + {0777a12e-32f2-46ce-9b38-add98f48a347} + + + {23253176-9614-4dbf-8f84-32fdb9383b3c} + + + {87cb2246-a309-48b4-82bc-c24ec9ad1bda} + + + + + auto + + + auto + + + auto + + + auto + + + auto + + + auto + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual\chipmunk + + + manual\chipmunk + + + manual\chipmunk + + + manual\chipmunk + + + manual\cocosbuilder + + + manual\cocostudio + + + manual\cocostudio + + + manual\extension + + + manual\localstorage + + + manual\localstorage + + + manual\network + + + manual\network + + + manual\network + + + manual\spine + + + manual\ui + + + auto + + + manual\3d + + + auto + + + + + auto + + + auto + + + auto + + + auto + + + auto + + + auto + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual + + + manual\chipmunk + + + manual\chipmunk + + + manual\chipmunk + + + manual\chipmunk + + + manual\chipmunk + + + manual\chipmunk + + + manual\cocosbuilder + + + manual\cocosbuilder + + + manual\cocostudio + + + manual\cocostudio + + + manual\extension + + + manual\localstorage + + + manual\localstorage + + + manual\localstorage + + + manual\network + + + manual\network + + + manual\network + + + manual\spine + + + manual\ui + + + auto + + + manual\3d + + + auto + + + \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/proj.wp8/libJSBinding.vcxproj.user b/frameworks/js-bindings/bindings/proj.wp8/libJSBinding.vcxproj.user new file mode 100644 index 0000000000..b0dc84df25 --- /dev/null +++ b/frameworks/js-bindings/bindings/proj.wp8/libJSBinding.vcxproj.user @@ -0,0 +1,6 @@ + + + + true + + \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/script/3d/jsb_cocos2d_3d.js b/frameworks/js-bindings/bindings/script/3d/jsb_cocos2d_3d.js new file mode 100644 index 0000000000..7db2366c2e --- /dev/null +++ b/frameworks/js-bindings/bindings/script/3d/jsb_cocos2d_3d.js @@ -0,0 +1,256 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ +cc.CameraFlag = { + DEFAULT : 1, + USER1 : 1 << 1, + USER2 : 1 << 2, + USER3 : 1 << 3, + USER4 : 1 << 4, + USER5 : 1 << 5, + USER6 : 1 << 6, + USER7 : 1 << 7, + USER8 : 1 << 8 +}; + +cc.LightType = { + DIRECTIONAL : 0, + POINT : 1, + SPOT : 2, + AMBIENT : 3, +}; + +cc.LightFlag = { + LIGHT0 : 1, + LIGHT1 : 1 << 1, + LIGHT2 : 1 << 2, + LIGHT3 : 1 << 3, + LIGHT4 : 1 << 4, + LIGHT5 : 1 << 5, + LIGHT6 : 1 << 6, + LIGHT7 : 1 << 7, + LIGHT8 : 1 << 8, + LIGHT9 : 1 << 9, + LIGHT10 : 1 << 10, + LIGHT11 : 1 << 11, + LIGHT12 : 1 << 12, + LIGHT13 : 1 << 13, + LIGHT14 : 1 << 14, + LIGHT15 : 1 << 15, +}; + +cc.AsyncTaskPool.TaskType = { + TASK_IO : 0, + TASK_NETWORK : 1, + TASK_OTHER : 2, + TASK_MAX_TYPE : 3 +}; + +jsb.BillBoard.Mode = { + VIEW_POINT_ORIENTED : 0, // orient to the camera + VIEW_PLANE_ORIENTED : 1 // orient to the XOY plane of camera +}; + +cc.attributeNames = [cc.ATTRIBUTE_NAME_POSITION, + cc.ATTRIBUTE_NAME_COLOR, + cc.ATTRIBUTE_NAME_TEX_COORD, + cc.ATTRIBUTE_NAME_TEX_COORD1, + cc.ATTRIBUTE_NAME_TEX_COORD2, + cc.ATTRIBUTE_NAME_TEX_COORD3, + cc.ATTRIBUTE_NAME_NORMAL, + cc.ATTRIBUTE_NAME_BLEND_WEIGHT, + cc.ATTRIBUTE_NAME_BLEND_INDEX]; + +cc.math = cc.math || {}; + +cc.math.Vec3 = function(x=0, y=0, z=0){ + this.x = x; + this.y = y; + this.z = z; +}; + +cc.math.Vec3.prototype.normalize = function(){ + var n = this.x * this.x + this.y * this.y + this.z * this.z; + n = 1 / Math.sqrt(n); + this.x *= n; + this.y *= n; + this.z *= n; +}; + +cc.math.vec3 = function(x, y, z){ + return new cc.math.Vec3(x, y, z); +}; + +cc.math.vec3Cross = function(v1, v2){ + return new cc.math.Vec3(v1.y * v2.z - v1.z * v2.y, + v1.z * v2.x - v1.x * v2.z, + v1.x * v2.y - v1.y * v2.x); +}; + +cc.math.vec3Dot = function(v1, v2){ + return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; +}; + +cc.math.vec3Length = function(v){ + return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z); +}; + +cc.math.vec3Normalize = function(v){ + var n = v.x * v.x + v.y * v.y + v.z * v.z; + n = 1 / Math.sqrt(n); + return cc.math.vec3(v.x * n, v.y * n, v.z * n); +}; + +cc.math.vec3Add = function(v1, v2){ + return new cc.math.Vec3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); +}; + +cc.math.vec3Sub = function(v1, v2){ + return new cc.math.Vec3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); +}; + +cc.math.Quaternion = function(x=0, y=0, z=0, w=0){ + this.x = x; + this.y = y; + this.z = z; + this.w = w; +}; + +cc.math.quaternion = function(xOrAxis, yOrAngle, z, w){ + if(w !== undefined){ + return new cc.math.Quaternion(xOrAxis, yOrAngle, z, w); + } + else if(yOrAngle !== undefined){ + var sinHalfAngle = Math.sin(yOrAngle / 2); + var normal = cc.math.vec3(xOrAxis.x, xOrAxis.y, xOrAxis.z); + normal.normalize(); + return cc.math.quaternion(normal.x * sinHalfAngle, normal.y * sinHalfAngle, normal.z * sinHalfAngle, Math.cos(yOrAngle / 2)); + } +}; + +cc.math.AABB = function(min=cc.math.vec3(99999, 99999, 99999), max=cc.math.vec3(-99999, -99999, -99999)){ + this.min = min; + this.max = max; +}; + +cc.math.aabb = function(min, max){ + return new cc.math.AABB(min, max); +}; + +cc.math.aabbGetCorners = function(aabb){ + var corners = new Array(8); + corners[0] = cc.math.vec3(aabb.min.x, aabb.max.y, aabb.max.z); + corners[1] = cc.math.vec3(aabb.min.x, aabb.min.y, aabb.max.z); + corners[2] = cc.math.vec3(aabb.max.x, aabb.min.y, aabb.max.z); + corners[3] = cc.math.vec3(aabb.max.x, aabb.max.y, aabb.max.z); + + corners[4] = cc.math.vec3(aabb.max.x, aabb.max.y, aabb.min.z); + corners[5] = cc.math.vec3(aabb.max.x, aabb.min.y, aabb.min.z); + corners[6] = cc.math.vec3(aabb.min.x, aabb.min.y, aabb.min.z); + corners[7] = cc.math.vec3(aabb.min.x, aabb.max.y, aabb.min.z); + return corners; +}; + +cc.math.OBB = function(aabb){ + this.center = cc.math.vec3((aabb.min.x + aabb.max.x)/2, (aabb.min.y + aabb.max.y)/2, (aabb.min.z + aabb.max.z)/2); // obb center + this.xAxis = cc.math.vec3(1, 0, 0); // x axis of obb, unit vector + this.yAxis = cc.math.vec3(0, 1, 0); // y axis of obb, unit vecotr + this.zAxis = cc.math.vec3(0, 0, 1); // z axis of obb, unit vector + this.extents = cc.math.vec3((aabb.max.x - aabb.min.x)/2, (aabb.max.y - aabb.min.y)/2, (aabb.max.z - aabb.min.z)/2); // obb length along each axis + this.extentX = cc.math.vec3((aabb.max.x - aabb.min.x)/2, 0, 0); // _xAxis * _extents.x + this.extentY = cc.math.vec3(0, (aabb.max.y - aabb.min.y)/2, 0); // _yAxis * _extents.y + this.extentZ = cc.math.vec3(0, 0, (aabb.max.z - aabb.min.z)/2); // _zAxis * _extents.z +}; + +cc.math.obb = function(aabb){ + return new cc.math.OBB(aabb); +}; + +cc.math.Ray = function(origin = cc.math.vec3(0, 0, 0), direction = cc.math.vec3(0, 0, 1)){ + this.origin = origin; + this.direction = direction; +}; + +cc.math.ray = function(origin, direction){ + return new cc.math.Ray(origin, direction); +}; + +cc.math.Vec4 = cc.math.Quaternion; + +cc.math.vec4 = function(x, y, z, w){ + return new cc.math.Vec4(x, y, z, w); +}; + +jsb.sprite3DCache = jsb.Sprite3DCache.getInstance(); + +jsb.Sprite3D.extend = cc.Class.extend; + +jsb.Sprite3D.prototype._setBlendFunc = jsb.Sprite3D.prototype.setBlendFunc; +jsb.Sprite3D.prototype.setBlendFunc = templateSetBlendFunc; + +jsb.Mesh.prototype._setBlendFunc = jsb.Mesh.prototype.setBlendFunc; +jsb.Mesh.prototype.setBlendFunc = templateSetBlendFunc; + +jsb.Sprite3D.prototype._ctor = function(modelPath, texturePath){ + if(modelPath === undefined){ + this.init(); + }else{ + if(modelPath.length < 4){ + cc.log("invalid filename for Sprite3D"); + return; + } + this.initWithFile(modelPath); + var bb = this.getBoundingBox(); + this.setContentSize(cc.size(bb.width, bb.height)); + + if(texturePath !== undefined) + this.setTexture(texturePath); + } +}; + +jsb.BillBoard.prototype._ctor = function(filename, rect, mode = jsb.BillBoard.Mode.VIEW_POINT_ORIENTED){ + if(filename !== undefined && filename instanceof cc.Texture2D){ + rect = rect || jsb.BillBoard.Mode.VIEW_POINT_ORIENTED; + this.initWithTexture(filename); + this.setMode(rect); + }else if(filename !== undefined && typeof filename === "string"){ + if(rect !== undefined){ + if(typeof rect === "object"){ + this.initWithFile(filename, rect); + this.setMode(mode); + }else{ + this.initWithFile(filename); + this.setMode(rect); + } + }else{ + this.initWithFile(filename); + this.setMode(jsb.BillBoard.Mode.VIEW_POINT_ORIENTED); + } + }else{ + filename = filename || jsb.BillBoard.Mode.VIEW_POINT_ORIENTED; + this.init(); + this.setMode(filename); + } +} \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/script/3d/jsb_cocos2d_3d_ext.js b/frameworks/js-bindings/bindings/script/3d/jsb_cocos2d_3d_ext.js new file mode 100644 index 0000000000..653e88fdbe --- /dev/null +++ b/frameworks/js-bindings/bindings/script/3d/jsb_cocos2d_3d_ext.js @@ -0,0 +1,28 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ + +jsb.ParticleSystem3D.prototype._setBlendFunc = jsb.ParticleSystem3D.prototype.setBlendFunc; +jsb.ParticleSystem3D.prototype.setBlendFunc = templateSetBlendFunc; \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/script/ccui/jsb_ccui_create_apis.js b/frameworks/js-bindings/bindings/script/ccui/jsb_ccui_create_apis.js index f66f88e471..86bd8f6ab7 100644 --- a/frameworks/js-bindings/bindings/script/ccui/jsb_ccui_create_apis.js +++ b/frameworks/js-bindings/bindings/script/ccui/jsb_ccui_create_apis.js @@ -40,8 +40,18 @@ ccui.Widget.prototype._ctor this.init(); } -ccui.Button.prototype._ctor = function (normalImage, selectedImage,disableImage, texType) { - texType !== undefined ? ccui.Button.prototype.init.call(this, normalImage, selectedImage,disableImage, texType) : ccui.Widget.prototype.init.call(this); +ccui.Button.prototype._ctor = function (normalImage, selectedImage, disableImage, texType) { + if(texType !== undefined) + ccui.Button.prototype.init.call(this, normalImage, selectedImage, disableImage, texType); + else if(disableImage !== undefined) + ccui.Button.prototype.init.call(this, normalImage, selectedImage, disableImage); + else if(selectedImage !== undefined) + ccui.Button.prototype.init.call(this, normalImage, selectedImage); + else if(normalImage !== undefined) + ccui.Button.prototype.init.call(this, normalImage); + else + ccui.Widget.prototype.init.call(this); + this.setTouchEnabled(true); }; @@ -49,17 +59,25 @@ ccui.CheckBox.prototype._ctor = function (backGround, backGroundSelected, cross, if (frontCrossDisabled !== undefined) { texType = texType || ccui.Widget.LOCAL_TEXTURE; ccui.CheckBox.prototype.init.call(this, backGround, backGroundSelected, cross, backGroundDisabled, frontCrossDisabled, texType); + }else if(backGroundSelected !== undefined){ + texType = ccui.Widget.LOCAL_TEXTURE; + cross = backGroundSelected; + backGroundSelected = backGroundDisabled = frontCrossDisabled = backGround; + ccui.CheckBox.prototype.init.call(this, backGround, backGroundSelected, cross, backGroundDisabled, frontCrossDisabled, texType); } else { ccui.Widget.prototype.init.call(this); } + this.setSelected(false); this.setTouchEnabled(true); }; ccui.ImageView.prototype._ctor = function(imageFileName, texType){ - if(texType !== undefined) + if(imageFileName !== undefined){ + texType = texType || ccui.Widget.LOCAL_TEXTURE; ccui.ImageView.prototype._init.call(this, imageFileName, texType); + } else ccui.Widget.prototype.init.call(this); } @@ -138,4 +156,4 @@ cc.Scale9Sprite.prototype._ctor = function(file, rect, capInsets){ cc.EditBox.prototype._ctor = function(size, normal9SpriteBg, press9SpriteBg, disabled9SpriteBg){ normal9SpriteBg && this.initWithSizeAndBackgroundSprite(size, normal9SpriteBg); -}; \ No newline at end of file +}; diff --git a/frameworks/js-bindings/bindings/script/ccui/jsb_cocos2d_ui.js b/frameworks/js-bindings/bindings/script/ccui/jsb_cocos2d_ui.js index fdd0b5ca85..8a4d52fdd2 100644 --- a/frameworks/js-bindings/bindings/script/ccui/jsb_cocos2d_ui.js +++ b/frameworks/js-bindings/bindings/script/ccui/jsb_cocos2d_ui.js @@ -136,6 +136,18 @@ ccui.LayoutParameter.NONE = 0; ccui.LayoutParameter.LINEAR = 1; ccui.LayoutParameter.RELATIVE = 2; +//LayoutComponent +ccui.LayoutComponent.horizontalEdge = {}; +ccui.LayoutComponent.horizontalEdge.NONE = 0; +ccui.LayoutComponent.horizontalEdge.LEFT = 1; +ccui.LayoutComponent.horizontalEdge.RIGHT = 2; +ccui.LayoutComponent.horizontalEdge.CENTER = 3; + +ccui.LayoutComponent.verticalEdge = {}; +ccui.LayoutComponent.verticalEdge.NONE = 0; +ccui.LayoutComponent.verticalEdge.BOTTOM = 1; +ccui.LayoutComponent.verticalEdge.TOP = 2; +ccui.LayoutComponent.verticalEdge.CENTER = 3; /* * UIWidget */ @@ -166,6 +178,12 @@ ccui.Widget.SIZE_PERCENT = 1; ccui.Widget.POSITION_ABSOLUTE = 0; ccui.Widget.POSITION_PERCENT = 1; +//focus direction +ccui.Widget.LEFT = 0; +ccui.Widget.RIGHT = 1; +ccui.Widget.UP = 2; +ccui.Widget.DOWN = 3; + /* * UIListView */ diff --git a/frameworks/js-bindings/bindings/script/jsb.js b/frameworks/js-bindings/bindings/script/jsb.js index 3bd89b3426..1ae745a3c5 100644 --- a/frameworks/js-bindings/bindings/script/jsb.js +++ b/frameworks/js-bindings/bindings/script/jsb.js @@ -27,7 +27,7 @@ // DO NOT ALTER THE ORDER require('script/jsb_cocos2d_constants.js'); require('script/jsb_cocos2d.js'); - +require('script/jsb_common.js'); require('script/jsb_property_impls.js'); require('script/jsb_property_apis.js'); require('script/jsb_create_apis.js'); @@ -42,6 +42,15 @@ if (window.ccs) { require('script/studio/jsb_cocos2d_studio.js'); require('script/studio/jsb_studio_property_apis.js'); require('script/studio/jsb_studio_create_apis.js'); + + require('script/studio/jsb_studio_load.js'); + require('script/studio/parsers/action-1.x.js'); + require('script/studio/parsers/action-2.x.js'); + require('script/studio/parsers/scene-1.x.js'); + require('script/studio/parsers/timelineParser-1.x.js'); + require('script/studio/parsers/timelineParser-2.x.js'); + require('script/studio/parsers/uiParser-1.x.js'); + require('script/studio/parsers/compatible.js'); } if (window.ccui) { @@ -116,3 +125,15 @@ if (jsb.fileUtils.isFileExist('jsb_pluginx.js')) { require('jsb_pluginx.js'); } } + +if (window.sp) { + require('script/jsb_spine.js'); +} + +if (jsb.Sprite3D){ + require('script/3d/jsb_cocos2d_3d.js'); +} + +if (jsb.ParticleSystem3D) { + require('script/3d/jsb_cocos2d_3d_ext.js'); +} \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/script/jsb_boot.js b/frameworks/js-bindings/bindings/script/jsb_boot.js index 74c28d913e..33d2653645 100644 --- a/frameworks/js-bindings/bindings/script/jsb_boot.js +++ b/frameworks/js-bindings/bindings/script/jsb_boot.js @@ -101,7 +101,8 @@ cc.isString = function(obj) { * @returns {boolean} */ cc.isArray = function(obj) { - return Object.prototype.toString.call(obj) == '[object Array]'; + return Array.isArray(obj) || + (typeof obj === 'object' && objectToString(obj) === '[object Array]'); }; /** @@ -110,7 +111,7 @@ cc.isArray = function(obj) { * @returns {boolean} */ cc.isUndefined = function(obj) { - return typeof obj == 'undefined'; + return typeof obj === 'undefined'; }; /** @@ -119,9 +120,8 @@ cc.isUndefined = function(obj) { * @returns {boolean} */ cc.isObject = function(obj) { - var type = typeof obj; - - return type == 'function' || (obj && type == 'object'); + return obj.__nativeObj !== undefined || + ( typeof obj === "object" && Object.prototype.toString.call(obj) === '[object Object]' ); }; /** @@ -574,10 +574,11 @@ cc.loader = { }); } else { - var tex = cc.textureCache._addImage(url); - if (tex instanceof cc.Texture2D) - cb && cb(null, tex); - else cb && cb("Load image failed"); + cc.textureCache._addImageAsync(url, function (tex){ + if (tex instanceof cc.Texture2D) + cb && cb(null, tex); + else cb && cb("Load image failed"); + }); } }, /** @@ -909,6 +910,7 @@ cc.view.getTargetDensityDPI = function() {return cc.DENSITYDPI_DEVICE;}; * @name cc.eventManager */ cc.eventManager = cc.director.getEventDispatcher(); + /** * @type {cc.AudioEngine} * @name cc.audioEngine @@ -931,8 +933,8 @@ cc.configuration = cc.Configuration.getInstance(); * cc.textureCache is the global cache for cc.Texture2D */ cc.textureCache = cc.director.getTextureCache(); -cc.TextureCache.prototype._addImage = cc.TextureCache.prototype.addImage; -cc.TextureCache.prototype.addImage = function(url, cb, target) { +cc.TextureCache.prototype._addImageAsync = cc.TextureCache.prototype.addImageAsync; +cc.TextureCache.prototype.addImageAsync = function(url, cb, target) { var localTex = null; cc.loader.loadImg(url, function(err, tex) { if (err) tex = null; @@ -943,6 +945,21 @@ cc.TextureCache.prototype.addImage = function(url, cb, target) { }); return localTex; }; +// Fix for compatibility with old APIs +cc.TextureCache.prototype._addImage = cc.TextureCache.prototype.addImage; +cc.TextureCache.prototype.addImage = function(url, cb, target) { + if (typeof cb === "function") { + return this.addImageAsync(url, cb, target); + } + else { + if (cb) { + return this._addImage(url, cb) + } + else { + return this._addImage(url); + } + } +}; /** * @type {Object} * @name cc.shaderCache @@ -1157,117 +1174,204 @@ cc._initSys = function(config, CONFIG_KEY){ */ locSys.LANGUAGE_POLISH = "pl"; - /** + * @memberof cc.sys + * @name OS_IOS * @constant - * @default * @type {string} */ - locSys.OS_WINDOWS = "Windows"; + sys.OS_IOS = "iOS"; /** + * @memberof cc.sys + * @name OS_ANDROID * @constant - * @default * @type {string} */ - locSys.OS_IOS = "iOS"; + sys.OS_ANDROID = "Android"; /** + * @memberof cc.sys + * @name OS_WINDOWS * @constant - * @default * @type {string} */ - locSys.OS_OSX = "OS X"; + sys.OS_WINDOWS = "Windows"; /** + * @memberof cc.sys + * @name OS_MARMALADE * @constant - * @default * @type {string} */ - locSys.OS_UNIX = "UNIX"; + sys.OS_MARMALADE = "Marmalade"; /** + * @memberof cc.sys + * @name OS_LINUX * @constant - * @default * @type {string} */ - locSys.OS_LINUX = "Linux"; + sys.OS_LINUX = "Linux"; /** + * @memberof cc.sys + * @name OS_BADA + * @constant + * @type {string} + */ + sys.OS_BADA = "Bada"; + /** + * @memberof cc.sys + * @name OS_BLACKBERRY + * @constant + * @type {string} + */ + sys.OS_BLACKBERRY = "Blackberry"; + /** + * @memberof cc.sys + * @name OS_OSX + * @constant + * @type {string} + */ + sys.OS_OSX = "OS X"; + /** + * @memberof cc.sys + * @name OS_WP8 + * @constant + * @type {string} + */ + sys.OS_WP8 = "WP8"; + /** + * @memberof cc.sys + * @name OS_WINRT + * @constant + * @type {string} + */ + sys.OS_WINRT = "WINRT"; + /** + * @memberof cc.sys + * @name OS_UNKNOWN * @constant - * @default * @type {string} */ - locSys.OS_ANDROID = "Android"; - locSys.OS_UNKNOWN = "unknown"; + sys.OS_UNKNOWN = "Unknown"; /** + * @memberof cc.sys + * @name UNKNOWN + * @constant + * @default + * @type {Number} + */ + sys.UNKNOWN = 0; + /** + * @memberof cc.sys + * @name IOS * @constant * @default * @type {Number} */ - locSys.WINDOWS = 0; + sys.IOS = 1; /** + * @memberof cc.sys + * @name ANDROID * @constant * @default * @type {Number} */ - locSys.LINUX = 1; + sys.ANDROID = 2; /** + * @memberof cc.sys + * @name WIN32 * @constant * @default * @type {Number} */ - locSys.MACOS = 2; + sys.WIN32 = 3; /** + * @memberof cc.sys + * @name MARMALADE * @constant * @default * @type {Number} */ - locSys.ANDROID = 3; + sys.MARMALADE = 4; /** + * @memberof cc.sys + * @name LINUX * @constant * @default * @type {Number} */ - locSys.IPHONE = 4; + sys.LINUX = 5; /** + * @memberof cc.sys + * @name BADA * @constant * @default * @type {Number} */ - locSys.IPAD = 5; + sys.BADA = 6; /** + * @memberof cc.sys + * @name BLACKBERRY * @constant * @default * @type {Number} */ - locSys.BLACKBERRY = 6; + sys.BLACKBERRY = 7; /** + * @memberof cc.sys + * @name MACOS * @constant * @default * @type {Number} */ - locSys.NACL = 7; + sys.MACOS = 8; /** + * @memberof cc.sys + * @name NACL * @constant * @default * @type {Number} */ - locSys.EMSCRIPTEN = 8; + sys.NACL = 9; /** + * @memberof cc.sys + * @name EMSCRIPTEN * @constant * @default * @type {Number} */ - locSys.TIZEN = 9; + sys.EMSCRIPTEN = 10; /** + * @memberof cc.sys + * @name TIZEN * @constant * @default * @type {Number} */ - locSys.WINRT = 10; + sys.TIZEN = 11; /** + * @memberof cc.sys + * @name QT5 * @constant * @default * @type {Number} */ - locSys.WP8 = 11; + sys.QT5 = 12; + /** + * @memberof cc.sys + * @name WP8 + * @constant + * @default + * @type {Number} + */ + sys.WP8 = 13; + /** + * @memberof cc.sys + * @name WINRT + * @constant + * @default + * @type {Number} + */ + sys.WINRT = 14; /** * @constant * @default @@ -1345,7 +1449,7 @@ cc._initSys = function(config, CONFIG_KEY){ cc.log(str); } - locSys.isMobile = (locSys.os == locSys.OS_ANDROID || locSys.os == locSys.OS_IOS) ? true : false; + locSys.isMobile = (locSys.os == locSys.OS_ANDROID || locSys.os == locSys.OS_IOS || locSys.os == locSys.OS_WP8 || locSys.os == locSys.OS_WINRT) ? true : false; locSys.language = (function(){ var language = cc.Application.getInstance().getCurrentLanguage(); @@ -1381,6 +1485,16 @@ cc._initSys = function(config, CONFIG_KEY){ capabilities["keyboard"] = true; capabilities["mouse"] = true; } + + /** + * Open a url in browser + * @memberof cc.sys + * @name openURL + * @param {String} url + */ + locSys.openURL = function(url){ + cc.Application.getInstance().openURL(url); + } }; //+++++++++++++++++++++++++something about sys end+++++++++++++++++++++++++++++ @@ -1624,11 +1738,6 @@ jsb.urlRegExp = new RegExp( // user:pass authentication "(?:\\S+(?::\\S*)?@)?" + "(?:" + - // IP address exclusion - // private & local networks - "(?!(?:10|127)(?:\\.\\d{1,3}){3})" + - "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" + - "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" + // IP address dotted notation octets // excludes loopback network 0.0.0.0 // excludes reserved space >= 224.0.0.0 diff --git a/frameworks/js-bindings/bindings/script/jsb_cocos2d.js b/frameworks/js-bindings/bindings/script/jsb_cocos2d.js index fb1c7c551a..621aa3ad89 100644 --- a/frameworks/js-bindings/bindings/script/jsb_cocos2d.js +++ b/frameworks/js-bindings/bindings/script/jsb_cocos2d.js @@ -26,7 +26,7 @@ // CCConfig.js // -cc.ENGINE_VERSION = "Cocos2d-JS v3.2"; +cc.ENGINE_VERSION = "Cocos2d-JS v3.5"; cc.FIX_ARTIFACTS_BY_STRECHING_TEXEL = 0; cc.DIRECTOR_STATS_POSITION = {x: 0, y: 0}; @@ -237,7 +237,9 @@ cc.Event.TOUCH = 0; //CCEvent.js cc.Event.KEYBOARD = 1; cc.Event.ACCELERATION = 2; cc.Event.MOUSE = 3; -cc.Event.CUSTOM = 4; +cc.Event.FOCUS = 4 +//game controller 5 +cc.Event.CUSTOM = 6; cc.EventMouse.NONE = 0; cc.EventMouse.DOWN = 1; cc.EventMouse.UP = 2; @@ -252,8 +254,9 @@ cc.EventMouse.BUTTON_6 = 5; cc.EventMouse.BUTTON_7 = 6; cc.EventMouse.BUTTON_8 = 7; cc.EventTouch.MAX_TOUCHES = 5; +cc.EventTouch.EventCode = {BEGAN: 0, MOVED: 1, ENDED: 2, CANCELLED: 3}; -cc.DEFAULT_SPRITE_BATCH_CAPACITY = 29; //CCSpriteBatchNode.js +cc.SpriteBatchNode.DEFAULT_CAPACITY = 29; //CCSpriteBatchNode.js cc.ParticleSystem.SHAPE_MODE = 0; //CCParticleSystem.js cc.ParticleSystem.TEXTURE_MODE = 1; @@ -281,103 +284,6 @@ cc.SCENE_FADE = 4208917214; //CCTransition.js cc.SCENE_RADIAL = 0xc001; //CCTransitionProgress.js -cc.KEY = { - //android - back:6, - menu:15, - //desktop - backspace:7, - tab:8, - enter:32, - shift:12, - ctrl:13, - alt:14, - pause:1, - capslock:11, - escape:6, - pageup:35, - pagedown:41, - end:21, - home:33, - left:23, - up:25, - right:24, - down:26, - insert:17, - Delete:20, - 0:73, - 1:74, - 2:75, - 3:76, - 4:77, - 5:78, - 6:79, - 7:80, - 8:81, - 9:82, - a:121, - b:122, - c:123, - d:124, - e:125, - f:126, - g:127, - h:128, - i:129, - j:130, - k:131, - l:132, - m:133, - n:134, - o:135, - p:136, - q:137, - r:138, - s:139, - t:140, - u:141, - v:142, - w:143, - x:144, - y:145, - z:146, - '*':30, - '+':28, - '-':29, - 'numdel':71, - '/':31, - f1:44, - f2:45, - f3:46, - f4:47, - f5:48, - f6:49, - f7:50, - f8:51, - f9:52, - f10:53, - f11:54, - f12:55, - numlock:27, - scrolllock:2, - semicolon:84, - ',':69, - equal:86, - '=':86, - ';':84, - comma:69, - '.':71, - period:71, - forwardslash:72, - grave:120, - '[':116, - openbracket:116, - ']':118, - closebracket:118, - backslash:117, - quote:58, - space:56 -}; // // CCMacro.js export // @@ -1555,6 +1461,7 @@ cc.TMXLayer.extend = cc.Class.extend; cc.TMXTiledMap.extend = cc.Class.extend; cc.TMXMapInfo.extend = cc.Class.extend; cc.TransitionScene.extend = cc.Class.extend; +cc.GLProgram.extend = cc.Class.extend; // Cocos2d-html5 supports multi scene resources preloading. @@ -1668,7 +1575,10 @@ cc.EventListener.TOUCH_ALL_AT_ONCE = 2; cc.EventListener.KEYBOARD = 3; cc.EventListener.MOUSE = 4; cc.EventListener.ACCELERATION = 5; -cc.EventListener.CUSTOM = 6; +cc.EventListener.FOCUS = 6; +//game controller 7 +cc.EventListener.CUSTOM = 8; + cc.EventListener.create = function(argObj){ if(!argObj || !argObj.event){ @@ -1697,6 +1607,8 @@ cc.EventListener.create = function(argObj){ else if(listenerType === cc.EventListener.ACCELERATION){ listener = cc.EventListenerAcceleration.create(argObj.callback); delete argObj.callback; + }else if(listenerType === cc.EventListener.FOCUS){ + listener = cc.EventListenerFocus.create(); } else { @@ -1780,6 +1692,12 @@ cc.EventListenerKeyboard.prototype.clone = function() { return ret; }; +cc.EventListenerFocus.prototype.clone = function() { + var ret = cc.EventListenerFocus.create(); + ret.onFocusChanged = this.onFocusChanged; + return ret; +}; + cc.EventListenerMouse.prototype.clone = function() { var ret = cc.EventListenerMouse.create(); ret._onMouseDown = this._onMouseDown; @@ -1805,6 +1723,18 @@ cc.EventListenerMouse.prototype.onMouseDown = function(event) { this._onMouseDown(event); }; +cc.EventListenerKeyboard.prototype._onKeyPressed = function(keyCode, event) { + if (!this.onKeyPressed) + return; + this.onKeyPressed(jsbKeyArr[keyCode], event); +}; + +cc.EventListenerKeyboard.prototype._onKeyReleased = function(keyCode, event) { + if (!this.onKeyReleased) + return; + this.onKeyReleased(jsbKeyArr[keyCode], event); +}; + cc.EventMouse.prototype.getLocation = function(){ return { x: this.getLocationX(), y: this.getLocationY() }; }; @@ -2242,7 +2172,6 @@ var templateSetBlendFunc = function(src, dst) { else blendf = {src: src, dst: dst}; this._setBlendFunc(blendf); - var b = this.getBlendFunc(); }; for (var i = 0, l = protoHasBlend.length; i < l; i++) { var proto = protoHasBlend[i]; @@ -2738,6 +2667,15 @@ cc.Node.prototype.getUserData = function () { return this.userData; }; +//for compatibility with html5 +cc.Node.prototype._setNormalizedPosition = cc.Node.prototype.setNormalizedPosition; +cc.Node.prototype.setNormalizedPosition = function(pos, y){ + if(y === undefined) + cc.Node.prototype._setNormalizedPosition.call(this, pos); + else + cc.Node.prototype._setNormalizedPosition.call(this, cc.p(pos, y)); +}; + /** returns a "world" axis aligned bounding box of the node.
* @return {cc.Rect} */ @@ -2847,3 +2785,41 @@ _p.setDisabledSpriteFrame = function(frame) { frame = cc.spriteFrameCache.getSpriteFrame(frame.substr(1)); this._setDisabledSpriteFrame(frame); } + +cc.MenuItemToggle.prototype.selectedItem = cc.MenuItemToggle.prototype.getSelectedItem; + + +// +// LabelTTF setDimensions support two parameters +// +cc.LabelTTF.prototype._setDimensions = cc.LabelTTF.prototype.setDimensions; +cc.LabelTTF.prototype.setDimensions = function (dim, height) { + if (!isNaN(height)) { + dim = {width: dim, height: height}; + } + this._setDimensions(dim); +}; + + +// +// Label adaptation to LabelTTF/LabelBMFont/LabelAtlas +// +_p = cc.Label.prototype; +_p.enableStroke = _p.enableOutline; +_p.setBoundingWidth = _p.setWidth; +_p.setBoundingHeight = _p.setHeight; + + +// +// 3D module rename to jsb namespace +// +jsb.BaseLight = cc.BaseLight; +delete cc.BaseLight; +jsb.DirectionLight = cc.DirectionLight; +delete cc.DirectionLight; +jsb.PointLight = cc.PointLight; +delete cc.PointLight; +jsb.SpotLight = cc.SpotLight; +delete cc.SpotLight; +jsb.AmbientLight = cc.AmbientLight; +delete cc.AmbientLight; diff --git a/frameworks/js-bindings/bindings/script/jsb_cocos2d_constants.js b/frameworks/js-bindings/bindings/script/jsb_cocos2d_constants.js index 5a0b860202..42bff9663e 100644 --- a/frameworks/js-bindings/bindings/script/jsb_cocos2d_constants.js +++ b/frameworks/js-bindings/bindings/script/jsb_cocos2d_constants.js @@ -133,3 +133,9 @@ cc.CHIPMUNK_IMPORT = 'chipmunk.h'; cc.ATTRIBUTE_NAME_COLOR = 'a_color'; cc.ATTRIBUTE_NAME_POSITION = 'a_position'; cc.ATTRIBUTE_NAME_TEX_COORD = 'a_texCoord'; +cc.ATTRIBUTE_NAME_TEX_COORD1 = "a_texCoord1"; +cc.ATTRIBUTE_NAME_TEX_COORD2 = "a_texCoord2"; +cc.ATTRIBUTE_NAME_TEX_COORD3 = "a_texCoord3"; +cc.ATTRIBUTE_NAME_NORMAL = "a_normal"; +cc.ATTRIBUTE_NAME_BLEND_WEIGHT = "a_blendWeight"; +cc.ATTRIBUTE_NAME_BLEND_INDEX = "a_blendIndex"; diff --git a/frameworks/js-bindings/bindings/script/jsb_common.js b/frameworks/js-bindings/bindings/script/jsb_common.js new file mode 100644 index 0000000000..5b779f07f2 --- /dev/null +++ b/frameworks/js-bindings/bindings/script/jsb_common.js @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2013-2014 Chukong Technologies Inc. + * + * 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. + */ + +cc.KEY = { + none:0, + + // android + back:6, + menu:18, + + // desktop + backspace:8, + tab:9, + + enter:13, + + shift:16, //should use shiftkey instead + ctrl:17, //should use ctrlkey + alt:18, //should use altkey + pause:19, + capslock:20, + + escape:27, + space:32, + pageup:33, + pagedown:34, + end:35, + home:36, + left:37, + up:38, + right:39, + down:40, + select:41, + + insert:45, + Delete:46, + 0:48, + 1:49, + 2:50, + 3:51, + 4:52, + 5:53, + 6:54, + 7:55, + 8:56, + 9:57, + a:65, + b:66, + c:67, + d:68, + e:69, + f:70, + g:71, + h:72, + i:73, + j:74, + k:75, + l:76, + m:77, + n:78, + o:79, + p:80, + q:81, + r:82, + s:83, + t:84, + u:85, + v:86, + w:87, + x:88, + y:89, + z:90, + + num0:96, + num1:97, + num2:98, + num3:99, + num4:100, + num5:101, + num6:102, + num7:103, + num8:104, + num9:105, + '*':106, + '+':107, + '-':109, + 'numdel':110, + '/':111, + f1:112, //f1-f12 dont work on ie + f2:113, + f3:114, + f4:115, + f5:116, + f6:117, + f7:118, + f8:119, + f9:120, + f10:121, + f11:122, + f12:123, + + numlock:144, + scrolllock:145, + + ';':186, + semicolon:186, + equal:187, + '=':187, + ',':188, + comma:188, + dash:189, + '.':190, + period:190, + forwardslash:191, + grave:192, + '[':219, + openbracket:219, + backslash:220, + ']':221, + closebracket:221, + quote:222, + + // gamepad controll + dpadLeft:1000, + dpadRight:1001, + dpadUp:1003, + dpadDown:1004, + dpadCenter:1005 +}; + +var jsbKeyArr = [ + cc.KEY["none"],//0 + cc.KEY["pause"],//1 + cc.KEY["scrolllock"],//2 + cc.KEY["none"],//3 + cc.KEY["none"],//4 + cc.KEY["none"],//5 + cc.KEY["back"],//6 + cc.KEY["backspace"],//7 + cc.KEY["tab"],//8 + cc.KEY["none"],//9 + cc.KEY["none"],//10 + cc.KEY["capslock"],//11 + cc.KEY["shift"],//12//should use shiftkey instead + cc.KEY["shift"],//13 + cc.KEY["ctrl"],//14//should use ctrlkey + cc.KEY["ctrl"],//15 + cc.KEY["alt"],//16//should use altkey + cc.KEY["alt"],//17 + cc.KEY["menu"],//18 + cc.KEY["none"],//19 + cc.KEY["insert"],//20 + cc.KEY["home"],//21 + cc.KEY["pageup"],//22 + cc.KEY["Delete"],//23 + cc.KEY["end"],//24 + cc.KEY["pagedown"],//25 + cc.KEY["left"],//26 + cc.KEY["right"],//27 + cc.KEY["up"],//28 + cc.KEY["down"],//29 + cc.KEY["numlock"],//30 + cc.KEY["+"],//31 + cc.KEY["-"],//32 + cc.KEY["*"],//33 + cc.KEY["none"],//34 + cc.KEY["enter"],//35 + cc.KEY["home"],//36 + cc.KEY["up"],//37 + cc.KEY["pageup"],//38 + cc.KEY["left"],//39 + cc.KEY["num5"],//40 + cc.KEY["right"],//41 + cc.KEY["end"],//42 + cc.KEY["down"],//43 + cc.KEY["pagedown"],//44 + cc.KEY["insert"],//45 + cc.KEY["Delete"],//46 + cc.KEY["f1"],//47 + cc.KEY["f2"],//48 + cc.KEY["f3"],//49 + cc.KEY["f4"],//50 + cc.KEY["f5"],//51 + cc.KEY["f6"],//52 + cc.KEY["f7"],//53 + cc.KEY["f8"],//54 + cc.KEY["f9"],//55 + cc.KEY["f10"],//56 + cc.KEY["f11"],//57 + cc.KEY["f12"],//58 + cc.KEY["space"],//59 + cc.KEY["none"],//60 + cc.KEY["quote"],//61 + cc.KEY["none"],//62 + cc.KEY["none"],//63 + cc.KEY["none"],//64 + cc.KEY["none"],//65 + cc.KEY["none"],//66 + cc.KEY["quote"],//67 + cc.KEY["none"],//68 + cc.KEY["none"],//69 + cc.KEY["none"],//70 + cc.KEY["none"],//71 + cc.KEY["comma"],//72 + cc.KEY["-"],//73 + cc.KEY["period"],//74 + cc.KEY["forwardslash"],//75//word keyboard + cc.KEY["num0"],//76 + cc.KEY["num1"],//77 + cc.KEY["num2"],//78 + cc.KEY["num3"],//79 + cc.KEY["num4"],//80 + cc.KEY["num5"],//81 + cc.KEY["num6"],//82 + cc.KEY["num7"],//83 + cc.KEY["num8"],//84 + cc.KEY["num9"],//85 + cc.KEY["none"],//86 + cc.KEY["semicolon"],//87 + cc.KEY["none"],//88 + cc.KEY["equal"],//89 + cc.KEY["none"],//90 + cc.KEY["none"],//91 + cc.KEY["none"],//92 + cc.KEY["a"],//93 + cc.KEY["b"],//94 + cc.KEY["c"],//95 + cc.KEY["d"],//96 + cc.KEY["e"],//97 + cc.KEY["f"],//98 + cc.KEY["g"],//99 + cc.KEY["h"],//100 + cc.KEY["i"],//101 + cc.KEY["j"],//102 + cc.KEY["k"],//103 + cc.KEY["l"],//104 + cc.KEY["m"],//105 + cc.KEY["n"],//106 + cc.KEY["o"],//107 + cc.KEY["p"],//108 + cc.KEY["q"],//109 + cc.KEY["r"],//110 + cc.KEY["s"],//111 + cc.KEY["t"],//112 + cc.KEY["u"],//113 + cc.KEY["v"],//114 + cc.KEY["w"],//115 + cc.KEY["x"],//116 + cc.KEY["y"],//117 + cc.KEY["z"],//118 + cc.KEY["openbracket"],//119 + cc.KEY["backslash"],//120 + cc.KEY["closebracket"],//121 + cc.KEY["none"],//122 + cc.KEY["grave"],//123 + cc.KEY["a"],//124 + cc.KEY["b"],//125 + cc.KEY["c"],//126 + cc.KEY["d"],//127 + cc.KEY["e"],//128 + cc.KEY["f"],//129 + cc.KEY["g"],//130 + cc.KEY["h"],//131 + cc.KEY["i"],//132 + cc.KEY["j"],//133 + cc.KEY["k"],//134 + cc.KEY["l"],//135 + cc.KEY["m"],//136 + cc.KEY["n"],//137 + cc.KEY["o"],//138 + cc.KEY["p"],//139 + cc.KEY["q"],//140 + cc.KEY["r"],//141 + cc.KEY["s"],//142 + cc.KEY["t"],//143 + cc.KEY["u"],//144 + cc.KEY["v"],//145 + cc.KEY["w"],//146 + cc.KEY["x"],//147 + cc.KEY["y"],//148 + cc.KEY["z"],//149 + cc.KEY["none"],//150 + cc.KEY["none"],//151 + cc.KEY["none"],//152 + cc.KEY["none"],//153 + cc.KEY["none"],//154 + cc.KEY["none"],//155 + cc.KEY["none"],//156 + cc.KEY["none"],//157 + cc.KEY["none"],//158 + cc.KEY["dpadLeft"],//159 + cc.KEY["dpadRight"],//160 + cc.KEY["dpadUp"],//161 + cc.KEY["dpadDown"],//162 + cc.KEY["dpadCenter"],//163 + cc.KEY["enter"],//164 + cc.KEY["none"]//165 + // html5 more key, these key can not trigge + //'numdel' + //select + //dash +]; + +if (cc.sys.os != cc.sys.OS_ANDROID) +{ + jsbKeyArr[6] = cc.KEY["escape"];//6 +} + +var parseKeyCode = function (keycode) +{ + var keyIndex = jsbKeyArr.indexOf(keycode); + var jsbKeyCode = keyIndex == -1 ? cc.KEY.none : keyIndex; + return jsbKeyCode; +} diff --git a/frameworks/js-bindings/bindings/script/jsb_create_apis.js b/frameworks/js-bindings/bindings/script/jsb_create_apis.js index a70fc904ee..5048a2dfb7 100644 --- a/frameworks/js-bindings/bindings/script/jsb_create_apis.js +++ b/frameworks/js-bindings/bindings/script/jsb_create_apis.js @@ -47,12 +47,16 @@ _p._ctor = function(color, w, h) { _p = cc.LayerGradient.prototype; -_p._ctor = function(start, end, v) { +_p._ctor = function(start, end, v, colorStops) { start = start || cc.color(0,0,0,255); end = end || cc.color(0,0,0,255); v = v || cc.p(0, -1); this.initWithColor(start, end, v); + + if (colorStops instanceof Array) { + cc.log("Warning: Color stops parameter is not supported in JSB."); + } }; @@ -99,7 +103,7 @@ _p._ctor = function(fileName, rect) { _p = cc.SpriteBatchNode.prototype; _p._ctor = function(fileImage, capacity) { - capacity = capacity || cc.DEFAULT_SPRITE_BATCH_CAPACITY; + capacity = capacity || cc.SpriteBatchNode.DEFAULT_CAPACITY; if (typeof(fileImage) == "string") this.initWithFile(fileImage, capacity); else @@ -232,8 +236,14 @@ _p._ctor = function(normalImage, selectedImage, three, four, five) { callback = three; } else if (five === undefined) { - callback = three; - target = four; + if (typeof three === "function") { + callback = three; + target = four; + } + else { + disabledImage = three; + callback = four; + } } else if (five) { disabledImage = three; @@ -297,8 +307,10 @@ _p._ctor = function(plistFile){ if (!plistFile || typeof(plistFile) === "number") { var ton = plistFile || 100; this.initWithTotalParticles(ton); - } else if (plistFile) { + } else if ( typeof plistFile === "string") { this.initWithFile(plistFile); + } else if(plistFile){ + this.initWithDictionary(plistFile); } }; @@ -735,6 +747,10 @@ cc.Animation.prototype._ctor = function(frames, delay, loops) { } }; +cc.AnimationFrame.prototype._ctor = function(spriteFrame, delayUnits, userInfo) { + delayUnits !== undefined && this.initWithSpriteFrame(spriteFrame, delayUnits, userInfo); +}; + /************************ Nodes *************************/ @@ -798,7 +814,11 @@ cc.Touch.prototype._ctor = function(x, y, id) { }; cc.GLProgram.prototype._ctor = function(vShaderFileName, fShaderFileName) { - vShaderFileName !== undefined && fShaderFileName !== undefined && cc.GLProgram.prototype.init.call(this, vShaderFileName, fShaderFileName); + if(vShaderFileName !== undefined && fShaderFileName !== undefined){ + cc.GLProgram.prototype.init.call(this, vShaderFileName, fShaderFileName); + cc.GLProgram.prototype.link.call(this); + cc.GLProgram.prototype.updateUniforms.call(this); + } }; @@ -1000,7 +1020,7 @@ cc.ParticleSystem.create = function(plistFile){ var particleSystem =null; if (typeof(plistFile) === "number") { particleSystem = cc.ParticleSystem.createWithTotalParticles(plistFile); - }else if(typeof(plistFile) === "string"){ + }else if(typeof(plistFile) === "string" || typeof(plistFile) === "object"){ particleSystem = cc.ParticleSystem._create(plistFile); } return particleSystem; diff --git a/frameworks/js-bindings/bindings/script/jsb_loaders.js b/frameworks/js-bindings/bindings/script/jsb_loaders.js index 9503e9652f..035e910672 100644 --- a/frameworks/js-bindings/bindings/script/jsb_loaders.js +++ b/frameworks/js-bindings/bindings/script/jsb_loaders.js @@ -26,6 +26,18 @@ // This helper file should be required after jsb_cocos2d.js // +cc._emptyLoader = { + load : function(realUrl, url){ + return null; + } +}; + +cc.loader.register([ + "mp3", "ogg", "wav", "mp4", "m4a", + "font", "eot", "ttf", "woff", "svg" + ], + cc._emptyLoader); + cc._txtLoader = { load : function(realUrl, url){ return jsb.fileUtils.getStringFromFile(realUrl); @@ -68,13 +80,6 @@ cc._plistLoader = { }; cc.loader.register(["plist"], cc._plistLoader); -cc._fontLoader = { - load : function(realUrl, url){ - return null; - } -}; -cc.loader.register(["font", "eot", "ttf", "woff", "svg"], cc._fontLoader); - cc._binaryLoader = { load : function(realUrl, url){ return cc.loader.loadBinarySync(realUrl); diff --git a/frameworks/js-bindings/bindings/script/jsb_property_apis.js b/frameworks/js-bindings/bindings/script/jsb_property_apis.js index c50f4b9f87..e80bc6aa33 100644 --- a/frameworks/js-bindings/bindings/script/jsb_property_apis.js +++ b/frameworks/js-bindings/bindings/script/jsb_property_apis.js @@ -43,6 +43,13 @@ cc.defineGetterSetter(_proto, "opacity", _proto.getOpacity, _proto.setOpacity); cc.defineGetterSetter(_proto, "opacityModifyRGB", _proto.isOpacityModifyRGB, _proto.setOpacityModifyRGB); cc.defineGetterSetter(_proto, "color", _proto.getColor, _proto.setColor); +_proto = cc.Label.prototype; +cc.defineGetterSetter(_proto, "size", _proto.getContentSize, _proto.setContentSize); +cc.defineGetterSetter(_proto, "width", _proto._getWidth, _proto._setWidth); +cc.defineGetterSetter(_proto, "height", _proto._getHeight, _proto._setHeight); +cc.defineGetterSetter(_proto, "boundingWidth", _proto.getWidth, _proto.setWidth); +cc.defineGetterSetter(_proto, "boundingHeight", _proto.getHeight, _proto.setHeight); + _proto = cc.LabelTTF.prototype; cc.defineGetterSetter(_proto, "size", _proto.getContentSize, _proto.setContentSize); cc.defineGetterSetter(_proto, "width", _proto._getWidth, _proto._setWidth); @@ -260,6 +267,7 @@ _proto = cc.LabelBMFont.prototype; cc.defineGetterSetter(_proto, "string", _proto.getString, _proto._setStringForSetter); cc.defineGetterSetter(_proto, "textAlign", _proto._getAlignment, _proto.setAlignment); cc.defineGetterSetter(_proto, "boundingWidth", _proto._getBoundingWidth, _proto.setBoundingWidth); +cc.defineGetterSetter(_proto, "boundingHeight", _proto._getBoundingHeight, _proto.setBoundingHeight); _proto = cc.Menu.prototype; cc.defineGetterSetter(_proto, "enabled", _proto.getEnabled, _proto.setEnabled); diff --git a/frameworks/js-bindings/bindings/script/jsb_spine.js b/frameworks/js-bindings/bindings/script/jsb_spine.js new file mode 100644 index 0000000000..ce75a6e601 --- /dev/null +++ b/frameworks/js-bindings/bindings/script/jsb_spine.js @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2013-2014 Chukong Technologies Inc. + * + * 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. + */ + +sp.ANIMATION_EVENT_TYPE = { + START: 0, + END: 1, + COMPLETE: 2, + EVENT: 3 +}; + +sp.SkeletonAnimation.prototype._ctor = function(skeletonDataFile, atlasFile, scale) { + if(atlasFile) { + if (isNaN(scale)) { + scale = 1; + } + + this.initWithFile(skeletonDataFile, atlasFile, scale); + this.initialize(); + + this._target = null; + this._callback = null; + } +}; + +sp.SkeletonAnimation.extend = cc.Class.extend; + +// Temporary solution before upgrade the Spine API +sp.SkeletonAnimation.prototype.setAnimationListener = function (target, callback) { + this._target = target; + this._callback = callback; + + this.setStartListener(function (trackIndex) { + if (this._target && this._callback) { + this._callback.call(this._target, this, trackIndex, sp.ANIMATION_EVENT_TYPE.START, null, 0); + } + }); + + this.setEndListener(function (trackIndex) { + if (this._target && this._callback) { + this._callback.call(this._target, this, trackIndex, sp.ANIMATION_EVENT_TYPE.END, null, 0); + } + }); + + this.setCompleteListener(function (trackIndex, loopCount) { + if (this._target && this._callback) { + this._callback.call(this._target, this, trackIndex, sp.ANIMATION_EVENT_TYPE.COMPLETE, null, loopCount); + } + }); + + this.setEventListener(function (trackIndex, event) { + if (this._target && this._callback) { + this._callback.call(this._target, this, trackIndex, sp.ANIMATION_EVENT_TYPE.EVENT, event, 0); + } + }); +} \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/script/studio/jsb_cocos2d_studio.js b/frameworks/js-bindings/bindings/script/studio/jsb_cocos2d_studio.js index d525e35913..71f1a443d5 100644 --- a/frameworks/js-bindings/bindings/script/studio/jsb_cocos2d_studio.js +++ b/frameworks/js-bindings/bindings/script/studio/jsb_cocos2d_studio.js @@ -30,13 +30,26 @@ var ccs = ccs || {}; ccs.Class = ccs.Class || cc.Class || {}; -//movement event type +// Movement event type ccs.MovementEventType = { start: 0, complete: 1, loopComplete: 2 }; +// Inner action type +ccs.InnerActionType = { + LoopAction: 0, + NoLoopAction: 1, + SingleFrame: 2 +}; + +ccs.AnimationInfo = function (name, startIndex, endIndex) { + this.name = name || ""; + this.startIndex = startIndex != undefined ? startIndex : 0; + this.endIndex = endIndex != undefined ? endIndex : 0; +}; + // Armature if(ccs.Armature){ ccs.Armature.prototype.setBody = function( body ) { @@ -50,6 +63,9 @@ if(ccs.Armature){ ccs.Armature.extend = cc.Class.extend; } +ccs.Armature.prototype._setBlendFunc = ccs.Armature.prototype.setBlendFunc; +ccs.Armature.prototype.setBlendFunc = templateSetBlendFunc; + ccs.sendEvent = function (event) { var triggerObjArr = ccs.triggerManager.get(event); diff --git a/frameworks/js-bindings/bindings/script/studio/jsb_studio_boot.js b/frameworks/js-bindings/bindings/script/studio/jsb_studio_boot.js index c159245ca6..033ee6999f 100644 --- a/frameworks/js-bindings/bindings/script/studio/jsb_studio_boot.js +++ b/frameworks/js-bindings/bindings/script/studio/jsb_studio_boot.js @@ -20,26 +20,6 @@ * THE SOFTWARE. */ -//ccs.nodeReader = ccs.NodeReader.getInstance(); -ccs.actionTimelineCache = ccs.ActionTimelineCache.getInstance(); -ccs.actionTimelineCache.createAction = ccs.ActionTimelineCache.createAction; - -ccs.csLoader = ccs.CSLoader.getInstance(); -ccs.csLoader.createNode = ccs.CSLoader.createNode; -ccs.csLoader.createTimeline = ccs.CSLoader.createTimeline; - -// In extension -/** - * @type {Object} Base object for ccs.uiReader - * @name ccs.uiReader - */ -ccs.uiReader = null; -cc.defineGetterSetter(ccs, "uiReader", function() { - return ccs.GUIReader.getInstance(); -}); -ccs.GUIReader.prototype.clear = function() { - ccs.GUIReader.destroyInstance(); -}; /** * @type {Object} Format and manage armature configuration and armature animation * @name ccs.armatureDataManager @@ -51,20 +31,7 @@ cc.defineGetterSetter(ccs, "armatureDataManager", function() { ccs.ArmatureDataManager.prototype.clear = function() { ccs.ArmatureDataManager.destroyInstance(); }; -/** - * @type {Object} Base singleton object for ccs.sceneReader - * @name ccs.sceneReader - */ -ccs.sceneReader = null; -cc.defineGetterSetter(ccs, "sceneReader", function() { - return ccs.SceneReader.getInstance(); -}); -ccs.SceneReader.prototype.clear = function() { - ccs.SceneReader.destroyInstance(); -}; -ccs.SceneReader.prototype.version = function() { - return ccs.SceneReader.sceneReaderVersion(); -}; + /** * @type {Object} Base singleton object for ccs.ActionManager * @name ccs.actionManager @@ -73,6 +40,30 @@ ccs.actionManager = ccs.ActionManager.getInstance(); ccs.ActionManager.prototype.clear = function() { this.releaseActions(); }; +ccs.ActionManager.prototype.initWithDictionary = function(file, dic, node) { + ccs.actionManager.initWithDictionaryEx(file, JSON.stringify(dic), node); +} + +/** + * The same as cc.Node + * @class + * @extends ccs.Class + */ +ccs.Node = ccs.Node || cc.Node; +ccs.Node.extend = ccs.Node.extend || cc.Node.extend; -//ccs.spriteFrameCacheHelper = ccs.SpriteFrameCacheHelper.getInstance(); -//ccs.dataReaderHelper = ccs.DataReaderHelper.getInstance(); \ No newline at end of file +/** + * The same as cc.Sprite + * @class + * @extends ccs.Class + */ +ccs.Sprite = ccs.Sprite || cc.Sprite; +ccs.Sprite.extend = ccs.Sprite.extend || cc.Sprite.extend; + +/** + * The same as cc.Component + * @class + * @extends ccs.Class + */ +ccs.Component = ccs.Component || cc.Component; +ccs.Component.extend = ccs.Component.extend || cc.Component.extend; \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/script/studio/jsb_studio_create_apis.js b/frameworks/js-bindings/bindings/script/studio/jsb_studio_create_apis.js index e4afbb78b4..55ee7b08ac 100644 --- a/frameworks/js-bindings/bindings/script/studio/jsb_studio_create_apis.js +++ b/frameworks/js-bindings/bindings/script/studio/jsb_studio_create_apis.js @@ -89,4 +89,15 @@ ccs.ComController.prototype._ctor = function() { ccs.ComRender.prototype._ctor = function() { ccs.ComRender.prototype.init.call(this); +}; + +ccs.ActionTimelineData.prototype._ctor = function(actionTag) { + if (actionTag !== undefined) + { + ccs.ActionTimelineData.prototype.init.call(this,actionTag); + } +}; + +ccs.ObjectExtensionData.prototype._ctor = function() { + ccs.ObjectExtensionData.prototype.init.call(this); }; \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/script/studio/jsb_studio_load.js b/frameworks/js-bindings/bindings/script/studio/jsb_studio_load.js new file mode 100644 index 0000000000..8578034ee0 --- /dev/null +++ b/frameworks/js-bindings/bindings/script/studio/jsb_studio_load.js @@ -0,0 +1,223 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ + +ccs._load = (function(){ + + /** + * load file + * @param {String} file + * @param {String} [type=] - ccui|node|action + * @param {String} [path=] - Resource search path + * @returns {*} + */ + var load = function(file, type, path){ + + var json = cc.loader.getRes(file); + + if(!json) + return cc.log("%s is not exists", file); + var ext = extname(file).toLocaleLowerCase(); + if(ext !== "json" && ext !== "exportjson") + return cc.log("%s load error, must be json file", file); + + var parse; + if(!type){ + if(json["widgetTree"]) + parse = parser["ccui"]; + else if(json["nodeTree"]) + parse = parser["timeline"]; + else if(json["Content"] && json["Content"]["Content"]) + parse = parser["timeline"]; + else if(json["gameobjects"]) + parse = parser["scene"]; + }else{ + parse = parser[type]; + } + + if(!parse){ + cc.log("Can't find the parser : %s", file); + return new cc.Node(); + } + var version = json["version"] || json["Version"]; + if(!version && json["armature_data"]){ + cc.warn("%s is armature. please use:", file); + cc.warn(" ccs.armatureDataManager.addArmatureFileInfoAsync(%s);", file); + cc.warn(" var armature = new ccs.Armature('name');"); + return new cc.Node(); + } + var currentParser = getParser(parse, version); + if(!currentParser){ + cc.log("Can't find the parser : %s", file); + return new cc.Node(); + } + + return currentParser.parse(file, json, path) || null; + }; + + var parser = { + "ccui": {}, + "timeline": {}, + "action": {}, + "scene": {} + }; + + load.registerParser = function(name, version, target){ + if(!name || !version || !target) + return cc.log("register parser error"); + if(!parser[name]) + parser[name] = {}; + parser[name][version] = target; + }; + + load.getParser = function(name, version){ + if(name && version) + return parser[name] ? parser[name][version] : undefined; + if(name) + return parser[name]; + return parser; + }; + + //Gets the file extension + var extname = function(fileName){ + var arr = fileName.match(extnameReg); + return ( arr && arr[1] ) ? arr[1] : null; + }; + var extnameReg = /\.([^\.]+)$/; + + + var parserReg = /([^\.](\.\*)?)*$/; + var getParser = function(parser, version){ + if(parser[version]) + return parser[version]; + else if(version === "*") + return null; + else + return getParser(parser, version.replace(parserReg, "*")); + }; + + return load; + +})(); + +ccs._parser = cc.Class.extend({ + + ctor: function(){ + this.parsers = {}; + }, + + _dirnameReg: /\S*\//, + _dirname: function(path){ + var arr = path.match(this._dirnameReg); + return (arr && arr[0]) ? arr[0] : ""; + }, + + getClass: function(json){ + return json["classname"]; + }, + + getNodeJson: function(json){ + return json["widgetTree"]; + }, + + parse: function(file, json){ + var resourcePath = this._dirname(file); + this.pretreatment(json, resourcePath); + var node = this.parseNode(this.getNodeJson(json), resourcePath, file); + node && this.deferred(json, resourcePath, node, file); + return node; + }, + + pretreatment: function(json, resourcePath, file){}, + + deferred: function(json, resourcePath, node, file){}, + + parseNode: function(json, resourcePath){ + var parser = this.parsers[this.getClass(json)]; + var widget = null; + if(parser) + widget = parser.call(this, json, resourcePath); + else + cc.log("Can't find the parser : %s", this.getClass(json)); + + return widget; + }, + + registerParser: function(widget, parse){ + this.parsers[widget] = parse; + } +}); + +/** + * Analysis of studio JSON file + * The incoming file name, parse out the corresponding object + * Temporary support file list: + * ui 1.* + * node 1.* - 2.* + * action 1.* - 2.* + * scene 0.* - 1.* + * @param {String} file + * @param {String} [path=] Resource path + * @returns {{node: cc.Node, action: cc.Action}} + */ +ccs.load = function(file, path){ + var object = { + node: null, + action: null + }; + + object.node = ccs._load(file, null, path); + object.action = ccs._load(file, "action", path); + if(object.action && object.action.tag === -1 && object.node) + object.action.tag = object.node.tag; + return object; +}; + +//Forward compatible interface + +ccs.actionTimelineCache = { + + + //@deprecated This function will be deprecated sooner or later please use ccs.load + /** + * Create Timeline Action + * @param file + * @returns {*} + */ + createAction: function(file){ + return ccs._load(file, "action"); + } +}; + +ccs.csLoader = { + + //@deprecated This function will be deprecated sooner or later please use ccs.load + /** + * Create Timeline Node + * @param file + * @returns {*} + */ + createNode: function(file){ + return ccs._load(file); + } +}; \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/script/studio/parsers/action-1.x.js b/frameworks/js-bindings/bindings/script/studio/parsers/action-1.x.js new file mode 100644 index 0000000000..c5c20446c4 --- /dev/null +++ b/frameworks/js-bindings/bindings/script/studio/parsers/action-1.x.js @@ -0,0 +1,238 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ + +(function(load, baseParser){ + + var cache = {}; + + var Parser = baseParser.extend({ + + getNodeJson: function(json){ + return json["action"]; + }, + + parseNode: function(json, resourcePath, file){ + if(!json) + return null; + if(cache[file]) + return cache[file].clone(); + + var self = this, + action = new ccs.ActionTimeline(); + + action.setDuration(json["duration"]); + action.setTimeSpeed(json["speed"] || 1); + //The process of analysis + var timelines = json["timelines"]; + timelines.forEach(function(timeline){ + var parser = self.parsers[timeline["frameType"]]; + var frame; + if(parser) + frame = parser.call(self, timeline, resourcePath); + else + cc.log("parser is not exists : %s", timeline["frameType"]); + if(frame) + action.addTimeline(frame); + + if(timeline["frameType"] == "ColorFrame"){ + action.addTimeline( + self.parsers["AlphaFrame"].call(self, timeline, resourcePath) + ); + } + }); + + cache[file] = action; + cache[file].retain(); + return action.clone(); + } + + }); + + var parser = new Parser(); + + var frameList = [ + { + name: "PositionFrame", + handle: function(options){ + var frame = new ccs.PositionFrame(); + var x = options["x"]; + var y = options["y"]; + frame.setPosition(cc.p(x,y)); + return frame; + } + }, + { + name: "VisibleFrame", + handle: function(options){ + var frame = new ccs.VisibleFrame(); + var visible = options["value"]; + frame.setVisible(visible); + return frame; + } + }, + { + name: "ScaleFrame", + handle: function(options){ + var frame = new ccs.ScaleFrame(); + var scalex = options["x"]; + var scaley = options["y"]; + frame.setScaleX(scalex); + frame.setScaleY(scaley); + return frame; + } + }, + { + name: "RotationFrame", + handle: function(options){ + var frame = new ccs.RotationFrame(); + var rotation = options["rotation"]; + frame.setRotation(rotation); + return frame; + } + }, + { + name: "SkewFrame", + handle: function(options){ + var frame = new ccs.SkewFrame(); + var skewx = options["x"]; + var skewy = options["y"]; + frame.setSkewX(skewx); + frame.setSkewY(skewy); + return frame; + } + }, + { + name: "RotationSkewFrame", + handle: function(options){ + var frame = new ccs.RotationSkewFrame(); + var skewx = options["x"]; + var skewy = options["y"]; + frame.setSkewX(skewx); + frame.setSkewY(skewy); + return frame; + } + }, + { + name: "AnchorFrame", + handle: function(options){ + var frame = new ccs.AnchorPointFrame(); + var anchorx = options["x"]; + var anchory = options["y"]; + frame.setAnchorPoint(cc.p(anchorx, anchory)); + return frame; + } + }, + { + name: "InnerActionFrame", + handle: function(options){ + var frame = new ccs.InnerActionFrame(); + var type = options["innerActionType"]; + var startFrame = options["startFrame"]; + frame.setInnerActionType(type); + frame.setStartFrameIndex(startFrame); + return frame; + } + }, + { + name: "ColorFrame", + handle: function(options){ + var frame = new ccs.ColorFrame(); + var red = options["red"]; + var green = options["green"]; + var blue = options["blue"]; + frame.setColor(cc.color(red, green, blue)); + var alphaFrame = new ccs.AlphaFrame(); + var alpha = options["alpha"]; + alphaFrame.setAlpha(alpha); + return frame; + } + }, + { + name: "AlphaFrame", + handle: function(options){ + var frame = new ccs.AlphaFrame(); + var alpha = options["alpha"]; + frame.setAlpha(alpha); + return frame; + } + }, + { + name: "TextureFrame", + handle: function(options){ + var frame = new ccs.TextureFrame(); + var texture = options["value"]; + if(texture != null) { + var path = texture; + var spriteFrame = cc.spriteFrameCache.getSpriteFrame(path); + if(spriteFrame == null){ + var jsonPath = ccs.csLoader.getJsonPath(); + path = jsonPath + texture; + } + frame.setTextureName(path); + } + return frame; + } + }, + { + name: "EventFrame", + handle: function(options){ + var frame = new ccs.EventFrame(); + var evnt = options["value"]; + if(evnt != null) + frame.setEvent(evnt); + return frame; + } + }, + { + name: "ZOrderFrame", + handle: function(options){ + var frame = new ccs.ZOrderFrame(); + var zorder = options["value"]; + frame.setZOrder(zorder); + return frame; + } + } + ]; + + frameList.forEach(function(item){ + parser.registerParser(item.name, function(options, resourcePath){ + var timeline = new ccs.Timeline(); + timeline.setActionTag(options["actionTag"]); + + var frames = options["frames"]; + if(frames && frames.length){ + frames.forEach(function(frameData){ + var frame = item.handle(frameData); + frame.setFrameIndex(frameData["frameIndex"]); + frame.setTween(frameData["tween"]); + timeline.addFrame(frame); + }); + } + return timeline; + }); + }); + + load.registerParser("action", "*", parser); + +})(ccs._load, ccs._parser); \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/script/studio/parsers/action-2.x.js b/frameworks/js-bindings/bindings/script/studio/parsers/action-2.x.js new file mode 100644 index 0000000000..555ec76181 --- /dev/null +++ b/frameworks/js-bindings/bindings/script/studio/parsers/action-2.x.js @@ -0,0 +1,269 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ + +(function(load, baseParser){ + + var cache = {}; + + var Parser = baseParser.extend({ + + getNodeJson: function(json){ + return json["Content"]["Content"]["Animation"]; + }, + + parseNode: function(json, resourcePath, file){ + if(!json) + return null; + if(cache[file]) + return cache[file].clone(); + + var self = this, + action = new ccs.ActionTimeline(); + + action.setDuration(json["Duration"]); + action.setTimeSpeed(json["Speed"] || 1); + //The process of analysis + var timelines = json["Timelines"]; + timelines.forEach(function(timeline){ + var parser = self.parsers[timeline["Property"]]; + var frame; + if(parser) + frame = parser.call(self, timeline, resourcePath); + else + cc.log("parser is not exists : %s", timeline["Property"]); + if(frame) + action.addTimeline(frame); + }); + + cache[file] = action; + cache[file].retain(); + return action.clone(); + }, + + deferred: function(json, resourcePath, action, file){ + if(cc.sys.isNative){ + var animationlist = json["Content"]["Content"]["AnimationList"]; + var length = animationlist ? animationlist.length : 0; + for (var i = 0; i < length; i++){ + var animationdata = animationlist[i]; + var info = { name: null, startIndex: null, endIndex: null }; + info.name = animationdata["Name"]; + info.startIndex = animationdata["StartIndex"]; + info.endIndex = animationdata["EndIndex"]; + action.addAnimationInfo(info); + } + } + } + + }); + var parser = new Parser(); + + var frameList = [ + { + name: "Position", + handle: function(options){ + var frame = new ccs.PositionFrame(); + var x = options["X"]; + var y = options["Y"]; + frame.setPosition(cc.p(x,y)); + return frame; + } + }, + { + name: "VisibleForFrame", + handle: function(options){ + var frame = new ccs.VisibleFrame(); + var visible = options["Value"]; + frame.setVisible(visible); + return frame; + } + }, + { + name: "Scale", + handle: function(options){ + var frame = new ccs.ScaleFrame(); + var scalex = options["X"]; + var scaley = options["Y"]; + frame.setScaleX(scalex); + frame.setScaleY(scaley); + return frame; + } + }, + { + name: "Rotation", + handle: function(options){ + var frame = new ccs.RotationFrame(); + var rotation = options["Rotation"]; + frame.setRotation(rotation); + return frame; + } + }, + { + name: "Skew", + handle: function(options){ + var frame = new ccs.SkewFrame(); + var skewx = options["X"]; + var skewy = options["Y"]; + frame.setSkewX(skewx); + frame.setSkewY(skewy); + return frame; + } + }, + { + name: "RotationSkew", + handle: function(options){ + var frame = new ccs.RotationSkewFrame(); + var skewx = options["X"]; + var skewy = options["Y"]; + frame.setSkewX(skewx); + frame.setSkewY(skewy); + return frame; + } + }, + { + name: "Anchor", + handle: function(options){ + var frame = new ccs.AnchorPointFrame(); + var anchorx = options["X"]; + var anchory = options["Y"]; + frame.setAnchorPoint(cc.p(anchorx, anchory)); + return frame; + } + }, + { + name: "InnerAction", + handle: function(options){ + var frame = new ccs.InnerActionFrame(); + var type = options["InnerActionType"]; + var startFrame = options["StartFrame"]; + frame.setInnerActionType(type); + frame.setStartFrameIndex(startFrame); + return frame; + } + }, + { + name: "CColor", + handle: function(options){ + var frame = new ccs.ColorFrame(); + var color = options["Color"]; + if(!color) color = {}; + color["R"] = color["R"] || 255; + color["G"] = color["G"] || 255; + color["B"] = color["B"] || 255; + frame.setColor(cc.color(color["R"], color["G"], color["B"])); + return frame; + } + }, + { + name: "Alpha", + handle: function(options){ + var frame = new ccs.AlphaFrame(); + var alpha = options["Value"]; + frame.setAlpha(alpha); + return frame; + } + }, + { + name: "FileData", + handle: function(options, resourcePath){ + var frame = new ccs.TextureFrame(); + var texture = options["TextureFile"]; + if(texture != null) { + var path = texture["Path"]; + var spriteFrame = cc.spriteFrameCache.getSpriteFrame(path); + if(spriteFrame == null){ + path = resourcePath + path; + } + frame.setTextureName(path); + } + return frame; + } + }, + { + name: "FrameEvent", + handle: function(options){ + var frame = new ccs.EventFrame(); + var evnt = options["Value"]; + if(evnt != null) + frame.setEvent(evnt); + return frame; + } + }, + { + name: "ZOrder", + handle: function(options){ + var frame = new ccs.ZOrderFrame(); + var zorder = options["Value"]; + frame.setZOrder(zorder); + return frame; + } + }, + { + name: "ActionValue", + handle: function (options) { + + var frame = new ccs.InnerActionFrame(); + var innerActionType = options["InnerActionType"]; + + var currentAnimationFrame = options["CurrentAniamtionName"]; + + var singleFrameIndex = options["SingleFrameIndex"]; + + var frameIndex = options["FrameIndex"]; + if(frameIndex !== undefined) + frame.setFrameIndex(frameIndex); + + frame.setInnerActionType(ccs.InnerActionType[innerActionType]); + frame.setSingleFrameIndex(singleFrameIndex); + + frame.setEnterWithName(true); + frame.setAnimationName(currentAnimationFrame); + + return frame; + } + } + ]; + + frameList.forEach(function(item){ + parser.registerParser(item.name, function(options, resourcePath){ + var timeline = new ccs.Timeline(); + timeline.setActionTag(options["ActionTag"]); + + var frames = options["Frames"]; + if(frames && frames.length){ + frames.forEach(function(frameData){ + var frame = item.handle(frameData, resourcePath); + frame.setFrameIndex(frameData["FrameIndex"]); + var tween = frameData["Tween"] != null ? frameData["Tween"] : true; + frame.setTween(tween); + timeline.addFrame(frame); + }); + } + return timeline; + }); + }); + + load.registerParser("action", "2.*", parser); + +})(ccs._load, ccs._parser); diff --git a/frameworks/js-bindings/bindings/script/studio/parsers/compatible.js b/frameworks/js-bindings/bindings/script/studio/parsers/compatible.js new file mode 100644 index 0000000000..0969d257d5 --- /dev/null +++ b/frameworks/js-bindings/bindings/script/studio/parsers/compatible.js @@ -0,0 +1,251 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ + + +/* + This file is for compatibility compatibility with older versions of GUIReader and SceneReader + todo: deprecated all + */ + +(function(){ + + ccs.uiReader = { + + _fileDesignSizes: {}, + + //@deprecated This function will be deprecated sooner or later please use ccs.load + /** + * Create CCUI Node + * @param file + * @returns {*} + */ + widgetFromJsonFile: function(file){ + var json = cc.loader.getRes(file); + if(json) + this._fileDesignSizes[file] = cc.size(json["designWidth"]||0, json["designHeight"]||0); + + var version = json["Version"] || json["version"]; + var versionNum = ccs.uiReader.getVersionInteger(version); + if(!version || versionNum >= 1700){ + cc.warn("Not supported file types, Please try use the ccs.load"); + return null; + } + return ccs._load(file, "ccui"); + }, + + //@deprecated This function will be deprecated sooner or later please use parser.registerParser + /** + * Register a custom Widget reader + * @param classType + * @param ins + * @param object + * @param callback + * @deprecated This function will be deprecated sooner or later please use parser.registerParser + */ + registerTypeAndCallBack: function(classType, ins, object, callback){ + var parser = ccs._load.getParser("ccui")["*"]; + var func = callback.bind(object); + parser.registerParser(classType, function(options, resourcePath){ + var widget = new ins(); + var uiOptions = options["options"]; + object.setPropsFromJsonDictionary && object.setPropsFromJsonDictionary(widget, uiOptions); + this.generalAttributes(widget, uiOptions); + var customProperty = uiOptions["customProperty"]; + if(customProperty) + customProperty = JSON.parse(customProperty); + else + customProperty = {}; + func(classType, widget, customProperty); + this.colorAttributes(widget, uiOptions); + this.anchorPointAttributes(widget, uiOptions); + this.parseChild.call(this, widget, options, resourcePath); + return widget; + }); + }, + + //@deprecated This function will be deprecated sooner or later + /** + * Gets the version number by version string. + * @param {String} version version string. + * @returns {Number} + */ + getVersionInteger: function(version){ + if(!version || typeof version != "string") return 0; + var arr = version.split("."); + if (arr.length != 4) + return 0; + var num = 0; + arr.forEach(function(n, i){ + num += n * Math.pow(10, 3 - i); + }); + return num; + }, + + //@deprecated This function will be deprecated sooner or later + /** + * stores the designSize of UI file. + * @param {String} fileName + * @param {cc.Size} size + */ + storeFileDesignSize: function (fileName, size) { + this._fileDesignSizes[fileName] = size; + }, + + //@deprecated This function will be deprecated sooner or later + /** + * Gets the design size by filename. + * @param {String} fileName + * @returns {cc.Size} + */ + getFileDesignSize: function (fileName) { + return this._fileDesignSizes[fileName]; + }, + + //@deprecated This function will be deprecated sooner or later + /** + * Returns the file path + * @returns {string} + */ + getFilePath: function(){ + return this._filePath; + }, + + //@deprecated This function will be deprecated sooner or later + setFilePath: function(path){ + this._filePath = path; + }, + + //@deprecated This function will be deprecated sooner or later + /** + * Returns the parsed object map. (analytic function) + * @returns {Object} + */ + getParseObjectMap: function(){ + return ccs._load.getParser("ccui")["*"]["parsers"]; + }, + + //@deprecated This function will be deprecated sooner or later + /** + * Returns the parsed callback map. (analytic function) + * @returns {*} + */ + getParseCallBackMap: function(){ + return ccs._load.getParser("ccui")["*"]["parsers"]; + }, + + //@deprecated This function will be deprecated sooner or later + clear: function(){} + }; + + var parser = ccs._load.getParser("ccui")["*"]; + ccs.imageViewReader = {setPropsFromJsonDictionary: parser.ImageViewAttributes}; + ccs.buttonReader = {setPropsFromJsonDictionary: parser.ButtonAttributes}; + ccs.checkBoxReader = {setPropsFromJsonDictionary: parser.CheckBoxAttributes}; + ccs.labelAtlasReader = {setPropsFromJsonDictionary: parser.TextAtlasAttributes}; + ccs.labelBMFontReader= {setPropsFromJsonDictionary: parser.TextBMFontAttributes}; + ccs.labelReader = {setPropsFromJsonDictionary: parser.TextAttributes}; + ccs.layoutReader = {setPropsFromJsonDictionary: parser.LayoutAttributes}; + ccs.listViewReader = {setPropsFromJsonDictionary: parser.ListViewAttributes}; + ccs.loadingBarReader = {setPropsFromJsonDictionary: parser.LoadingBarAttributes}; + ccs.pageViewReader = {setPropsFromJsonDictionary: parser.PageViewAttributes}; + ccs.scrollViewReader = {setPropsFromJsonDictionary: parser.ScrollViewAttributes}; + ccs.sliderReader = {setPropsFromJsonDictionary: parser.SliderAttributes}; + ccs.textFieldReader = {setPropsFromJsonDictionary: parser.TextFieldAttributes}; +})(); + +(function(){ + ccs.sceneReader = { + + _node: null, + + //@deprecated This function will be deprecated sooner or later please use ccs.load + /** + * Create Scene Node + * @param file + * @returns {*} + */ + createNodeWithSceneFile: function(file){ + var node = ccs._load(file, "scene"); + this._node = node; + return node; + }, + + /** + * Get a node by tag. + * @param {Number} tag + * @returns {cc.Node|null} + */ + getNodeByTag: function(tag){ + if (this._node == null) + return null; + if (this._node.getTag() == tag) + return this._node; + return this._nodeByTag(this._node, tag); + }, + + _nodeByTag: function (parent, tag) { + if (parent == null) + return null; + var retNode = null; + var children = parent.getChildren(); + for (var i = 0; i < children.length; i++) { + var child = children[i]; + if (child && child.getTag() == tag) { + retNode = child; + break; + } else { + retNode = this._nodeByTag(child, tag); + if (retNode) + break; + } + } + return retNode; + }, + + //@deprecated This function will be deprecated sooner or later + /** + * Returns the version of ccs.SceneReader. + * @returns {string} + */ + version: function(){ + return "*"; + }, + + //@deprecated This function will be deprecated sooner or later + /** + * Sets the listener to reader. + * Cannot use + */ + setTarget: function(){}, + + //@deprecated This function will be deprecated sooner or later + /** + * Clear all triggers and stops all sounds. + */ + clear: function(){ + ccs.triggerManager.removeAll(); + cc.audioEngine.end(); + } + }; +})(); \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/script/studio/parsers/scene-1.x.js b/frameworks/js-bindings/bindings/script/studio/parsers/scene-1.x.js new file mode 100644 index 0000000000..aad9b5a73b --- /dev/null +++ b/frameworks/js-bindings/bindings/script/studio/parsers/scene-1.x.js @@ -0,0 +1,262 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ + +(function(load, baseParser){ + + var Parser = baseParser.extend({ + + getNodeJson: function(json){ + return json; + }, + + parseNode: function(json, resourcePath){ + var parser = this.parsers[this.getClass(json)]; + var node = null; + if(parser) + node = parser.call(this, json, resourcePath); + else + cc.log("Can't find the parser : %s", this.getClass(json)); + + return node; + }, + + deferred: function(json, resourcePath, node, file){ + ccs.triggerManager.parse(json["Triggers"]||[]); + if(ccs.sceneReader) + ccs.sceneReader._node = node; + }, + + setPropertyFromJsonDict: function(node, json){ + var x = (cc.isUndefined(json["x"]))?0:json["x"]; + var y = (cc.isUndefined(json["y"]))?0:json["y"]; + node.setPosition(x, y); + + var bVisible = Boolean((cc.isUndefined(json["visible"]))?1:json["visible"]); + node.setVisible(bVisible); + + var nTag = (cc.isUndefined(json["objecttag"]))?-1:json["objecttag"]; + node.setTag(nTag); + + var nZorder = (cc.isUndefined(json["zorder"]))?0:json["zorder"]; + node.setLocalZOrder(nZorder); + + var fScaleX = (cc.isUndefined(json["scalex"]))?1:json["scalex"]; + var fScaleY = (cc.isUndefined(json["scaley"]))?1:json["scaley"]; + node.setScaleX(fScaleX); + node.setScaleY(fScaleY); + + var fRotationZ = (cc.isUndefined(json["rotation"]))?0:json["rotation"]; + node.setRotation(fRotationZ); + + var sName = json["name"] || ""; + node.setName(sName); + } + + }); + + var parser = new Parser(); + + parser.parseChild = function(node, objects, resourcePath){ + for (var i = 0; i < objects.length; i++) { + var child, + options = objects[i]; + if(options) + child = this.parseNode(options, resourcePath); + if(child) + node.addChild(child); + } + }; + + var componentsParser = { + "CCSprite": function(node, component, resourcePath){ + var child = new cc.Sprite(); + loadTexture(component["fileData"], resourcePath, function(path, type){ + if(type == 0) + child.setTexture(path); + else if(type == 1){ + var spriteFrame = cc.spriteFrameCache.getSpriteFrame(path); + child.setSpriteFrame(spriteFrame); + } + }); + var render = new ccs.ComRender(child, "CCSprite"); + node.addComponent(render); + return render; + }, + "CCTMXTiledMap": function(node, component, resourcePath){ + var child = null; + loadTexture(component["fileData"], resourcePath, function(path, type){ + if(type == 0) + child = new cc.TMXTiledMap(path); + }); + var render = new ccs.ComRender(child, "CCTMXTiledMap"); + node.addComponent(render); + return render; + }, + "CCParticleSystemQuad": function(node, component, resourcePath){ + var child = null; + loadTexture(component["fileData"], resourcePath, function(path, type){ + if(type == 0) + child = new cc.ParticleSystem(path); + else + cc.log("unknown resourcetype on CCParticleSystemQuad!"); + child.setPosition(0, 0); + }); + var render = new ccs.ComRender(child, "CCParticleSystemQuad"); + node.addComponent(render); + return render; + }, + "CCArmature": function(node, component, resourcePath){ + var child = null; + loadTexture(component["fileData"], resourcePath, function(path, type){ + if(type == 0){ + var jsonDict = cc.loader.getRes(path); + if (!jsonDict) cc.log("Please load the resource [%s] first!", path); + var armature_data = jsonDict["armature_data"]; + var subData = armature_data[0]; + var name = subData["name"]; + ccs.armatureDataManager.addArmatureFileInfo(path); + child = new ccs.Armature(name); + } + }); + if(child){ + var render = new ccs.ComRender(child, "CCArmature"); + node.addComponent(render); + var actionName = component["selectedactionname"]; + if (actionName && child.getAnimation()) + child.getAnimation().play(actionName); + + return render; + } + + }, + "CCComAudio": function(node, component, resourcePath){ + var audio = null; + loadTexture(component["fileData"], resourcePath, function(path, type){ + if(type == 0){ + audio = new ccs.ComAudio(); + audio.preloadEffect(path); + var name = component["name"]; + if(name) + audio.setName(name); + node.addComponent(audio); + } + }); + }, + "CCComAttribute": function(node, component, resourcePath){ + var attribute = null; + loadTexture(component["fileData"], resourcePath, function(path, type){ + if(type == 0){ + attribute = new ccs.ComAttribute(); + if (path != "") + attribute.parse(path); + node.addComponent(attribute); + }else + cc.log("unknown resourcetype on CCComAttribute!"); + }); + return attribute; + }, + "CCBackgroundAudio": function(node, component, resourcePath){ + var audio = null; + loadTexture(component["fileData"], resourcePath, function(path, type){ + if(type == 0){ + audio = new ccs.ComAudio(); + audio.preloadBackgroundMusic(path); + audio.setFile(path);var bLoop = Boolean(component["loop"] || 0); + audio.setLoop(bLoop); + var name = component["name"]; + if(name) + audio.setName(name); + node.addComponent(audio); + audio.playBackgroundMusic(path, bLoop); + } + }); + }, + "GUIComponent": function(node, component, resourcePath){ + var widget = null; + loadTexture(component["fileData"], resourcePath, function(path, type){ + widget = ccs._load(path, "ccui"); + }); + var render = new ccs.ComRender(widget, "GUIComponent"); + node.addComponent(render); + return render; + }, + "CCScene": function(){} + }; + var loadedPlist = {}; + var loadTexture = function(json, resourcePath, cb){ + if(json != null){ + var path = json["path"]; + var type = json["resourceType"]; + var plist = json["plist"]; + if(!path) + return; + if(plist){ + if(cc.loader.getRes(resourcePath + plist)){ + loadedPlist[resourcePath + plist] = true; + cc.spriteFrameCache.addSpriteFrames(resourcePath + plist); + }else{ + if(!loadedPlist[resourcePath + plist]) + cc.log("%s need to be preloaded", resourcePath + plist); + } + } + if(type !== 0) + cb(path, type); + else + cb(resourcePath + path, type); + } + }; + + parser.parseComponents = function(node, json, resourcePath){ + if(!node || !json) + return; + json.forEach(function(component){ + var parser = componentsParser[component["classname"]]; + var render = null; + if(parser) + render = parser(node, component, resourcePath); + else + cc.log("Can't find the component parser : %s", component["classname"]); + var name = component["name"]; + if(render && name){ + render.setName(name); + } + }); + }; + + parser.registerParser("CCNode", function(options, resourcePath){ + var node = new cc.Node(); + this.setPropertyFromJsonDict(node, options); + this.parseChild.call(this, node, options["gameobjects"], resourcePath); + this.parseComponents(node, options["components"], resourcePath); + var size = options["CanvasSize"]; + if (size) + node.setContentSize(cc.size(size["_width"], size["_height"])); + + return node; + }); + + load.registerParser("scene", "*", parser); + + +})(ccs._load, ccs._parser); diff --git a/frameworks/js-bindings/bindings/script/studio/parsers/timelineParser-1.x.js b/frameworks/js-bindings/bindings/script/studio/parsers/timelineParser-1.x.js new file mode 100644 index 0000000000..5b0c849df9 --- /dev/null +++ b/frameworks/js-bindings/bindings/script/studio/parsers/timelineParser-1.x.js @@ -0,0 +1,292 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ + +(function(load, baseParser){ + + var loadedPlist = {}; + + var Parser = baseParser.extend({ + + getNodeJson: function(json){ + return json["nodeTree"]; + }, + + addSpriteFrame: function(plists, pngs, resourcePath){ + if(!plists || !pngs || plists.length != pngs.length) + return; + for (var i = 0; i < plists.length; i++) { + var plist = resourcePath + plists[i]; + if(!cc.loader.getRes(plist) && !loadedPlist[plist]) + cc.log("%s need to be preloaded", plist); + else + loadedPlist[plist] = true; + cc.spriteFrameCache.addSpriteFrames( + plist, + resourcePath + pngs[i] + ); + } + }, + + pretreatment: function(json, resourcePath, file){ + this.addSpriteFrame(json["textures"], json["texturesPng"], resourcePath); + } + + }); + var parser = new Parser(); + + parser.generalAttributes = function(node, options){ + var width = options["width"] !=null ? options["width"] : 0; + var height = options["height"] !=null ? options["height"] : 0; + var x = options["x"] !=null ? options["x"] : 0; + var y = options["y"] !=null ? options["y"] : 0; + var scalex = options["scaleX"] !=null ? options["scaleX"] : 1; + var scaley = options["scaleY"] !=null ? options["scaleY"] : 1; + var rotation = options["rotation"] !=null ? options["rotation"] : 0; + var rotationSkewX = options["rotationSkewX"]!=null ? options["rotationSkewX"] : 0; + var rotationSkewY = options["rotationSkewY"]!=null ? options["rotationSkewY"] : 0; + var skewx = options["skewX"] !=null ? options["skewX"] : 0; + var skewy = options["skewY"] !=null ? options["skewY"] : 0; + var anchorx = options["anchorPointX"] !=null ? options["anchorPointX"] : 0.5; + var anchory = options["anchorPointY"] !=null ? options["anchorPointY"] : 0.5; + var alpha = options["opacity"] !=null ? options["opacity"] : 255; + var red = options["colorR"] !=null ? options["colorR"] : 255; + var green = options["colorG"] !=null ? options["colorG"] : 255; + var blue = options["colorB"] !=null ? options["colorB"] : 255; + var zorder = options["colorR"] !=null ? options["colorR"] : 0; + var tag = options["tag"] !=null ? options["tag"] : 0; + var actionTag = options["actionTag"] !=null ? options["actionTag"] : 0; + var visible = options["visible"] !=null ? options["visible"] : true; + + if(x != 0 || y != 0) + node.setPosition(cc.p(x, y)); + if(scalex != 1) + node.setScaleX(scalex); + if(scaley != 1) + node.setScaleY(scaley); + if (rotation != 0) + node.setRotation(rotation); + if(rotationSkewX != 0) + node.setRotationX(rotationSkewX); + if(rotationSkewY != 0) + node.setRotationY(rotationSkewY); + if(skewx != 0) + node.setSkewX(skewx); + if(skewy != 0) + node.setSkewY(skewy); + if(anchorx != 0.5 || anchory != 0.5) + node.setAnchorPoint(cc.p(anchorx, anchory)); + if(width != 0 || height != 0) + node.setContentSize(cc.size(width, height)); + if(zorder != 0) + node.setLocalZOrder(zorder); + if(visible != true) + node.setVisible(visible); + + if(alpha != 255) + { + node.setOpacity(alpha); + } + if(red != 255 || green != 255 || blue != 255) + { + node.setColor(cc.color(red, green, blue)); + } + + + node.setTag(tag); + node.setUserObject(new ccs.ActionTimelineData(actionTag)); + }; + + parser.parseComponent = function(node, options){ + if(!options) return; + for (var i = 0; i < options.length; ++i){ + var dic = options[i]; + var component = this.loadComponent(dic); + if (component){ + node.addComponent(component); + } + } + }; + + parser.parseChild = function(parse, widget, options, resourcePath){ + var children = options["children"]; + for (var i = 0; i < children.length; i++) { + var child = this.parseNode(children[i], resourcePath); + if(child){ + if(widget instanceof ccui.PageView){ + if(child instanceof ccui.Layout) + widget.addPage(child); + } else { + if(widget instanceof ccui.ListView){ + if(child instanceof ccui.Widget) + widget.pushBackCustomItem(child); + } else { + if(!(widget instanceof ccui.Layout) && child instanceof ccui.Widget) { + if(child.getPositionType() == ccui.Widget.POSITION_PERCENT) { + var position = child.getPositionPercent(); + var anchor = widget.getAnchorPoint(); + child.setPositionPercent(cc.p(position.x + anchor.x, position.y + anchor.y)); + } + //To make up for the studio positioning error problem + var AnchorPointIn = widget.getAnchorPointInPoints(); + child.setPosition(cc.p(child.getPositionX() + AnchorPointIn.x, child.getPositionY() + AnchorPointIn.y)); + } + widget.addChild(child); + } + } + } + } + }; + + parser.initNode = function(options){ + var node = new cc.Node(); + this.generalAttributes(node, options); + return node; + }; + parser.initSubGraph = function(options){ + var filePath = options["fileName"]; + + var node; + if (filePath && "" != filePath){ + node = this.createNode(filePath); + }else{ + node = new ccs.Node(); + } + this.generalAttributes(node, options); + return node; + }; + parser.initSprite = function(options, resourcePath){ + var path = options["fileName"]; + var sprite; + if(path != null){ + var spriteFrame = cc.spriteFrameCache.getSpriteFrame(path); + if(!spriteFrame){ + path = resourcePath + path; + sprite = new ccs.Sprite(path); + }else{ + sprite = ccs.Sprite.createWithSpriteFrame(spriteFrame); + } + + if(!sprite){ + sprite = new cc.Sprite(); + cc.log("filePath is empty. Create a sprite with no texture"); + } + }else{ + sprite = new ccs.Sprite(); + } + this.generalAttributes(sprite, options); + var flipX = options["flipX"]; + var flipY = options["flipY"]; + + if(flipX != false) + sprite.setFlippedX(flipX); + if(flipY != false) + sprite.setFlippedY(flipY); + return sprite; + }; + parser.initParticle = function(options, resourcePath){ + var filePath = options["plistFile"]; + var num = options["tmxFile"]; + var particle = new cc.ParticleSystemQuad(filePath); + particle.setTotalParticles(num); + this.generalAttributes(particle, options); + return particle; + }; + parser.initTMXTiledMap = function(options, resourcePath){ + var tmxFile = options["tmxFile"]; + var tmxString = options["tmxString"]; + //todo check path and resourcePath + var path = options["resourcePath"]; + + var tmx = null; + if (tmxFile && "" != tmxFile){ + tmx = new cc.TMXTiledMap(tmxFile); + }else if (tmxString && "" != tmxString && path && "" != path){ + tmx = new cc.TMXTiledMap(tmxString, path); + } + return tmx; + }; + var uiParser = load.getParser("ccui")["*"]; + parser.initWidget = function(options, resourcePath){ + var type = options["classname"]; + + var parser = uiParser.parsers[type]; + if(!parser) + return cc.log("%s parser is not found", type); + + var node = parser.call(uiParser, options, resourcePath); + if(node){ + var rotationSkewX = options["rotationSkewX"]; + var rotationSkewY = options["rotationSkewY"]; + var skewx = options["skewX"]; + var skewy = options["skewY"]; + if(rotationSkewX != 0) + node.setRotationX(rotationSkewX); + if(rotationSkewY != 0) + node.setRotationY(rotationSkewY); + if(skewx != 0) + node.setSkewX(skewx); + if(skewy != 0) + node.setSkewY(skewy); + + var actionTag = options["actionTag"]; + node.setUserObject(new ccs.ActionTimelineData(actionTag)); + } + return node; + }; + + var register = [ + {name: "Node", handle: parser.initNode}, + {name: "SubGraph", handle: parser.initSubGraph}, + {name: "Sprite", handle: parser.initSprite}, + {name: "Particle", handle: parser.initParticle}, + {name: "TMXTiledMap", handle: parser.initTMXTiledMap}, + + {name: "Widget", handle: parser.initWidget}, + {name: "Panel", handle: parser.initWidget}, + {name: "Button", handle: parser.initWidget}, + {name: "CheckBox", handle: parser.initWidget}, + {name: "ImageView", handle: parser.initWidget}, + {name: "LabelAtlas", handle: parser.initWidget}, + {name: "LabelBMFont", handle: parser.initWidget}, + {name: "Label", handle: parser.initWidget}, + {name: "ListView", handle: parser.initWidget}, + {name: "LoadingBar", handle: parser.initWidget}, + {name: "PageView", handle: parser.initWidget}, + {name: "ScrollView", handle: parser.initWidget}, + {name: "Slider", handle: parser.initWidget}, + {name: "TextField", handle: parser.initWidget} + ]; + + register.forEach(function(item){ + parser.registerParser(item.name, function(options, parse, resourcePath){ + var node = item.handle.call(this, options["options"]); + this.parseComponent(node, options["components"]); + this.parseChild(parse, node, options, resourcePath); + return node; + }); + }); + + load.registerParser("timeline", "*", parser); + +})(ccs._load, ccs._parser); diff --git a/frameworks/js-bindings/bindings/script/studio/parsers/timelineParser-2.x.js b/frameworks/js-bindings/bindings/script/studio/parsers/timelineParser-2.x.js new file mode 100644 index 0000000000..6b5ab6ed54 --- /dev/null +++ b/frameworks/js-bindings/bindings/script/studio/parsers/timelineParser-2.x.js @@ -0,0 +1,1477 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ + +(function(load, baseParser){ + + var DEBUG = false; + + var Parser = baseParser.extend({ + + parse: function(file, json, path){ + var resourcePath; + if(path !== undefined) + resourcePath = path; + else + resourcePath = this._dirname(file); + this.pretreatment(json, resourcePath, file); + var node = this.parseNode(this.getNodeJson(json), resourcePath); + this.deferred(json, resourcePath, node, file); + return node; + }, + + getNodeJson: function(json){ + return json["Content"]["Content"]["ObjectData"]; + }, + + getClass: function(json){ + return json["ctype"]; + } + + }); + var parser = new Parser(); + + + var getParam = function(value, dValue){ + if(value === undefined) + return dValue; + else + return value; + }; + + ////////// + // NODE // + ////////// + + parser.generalAttributes = function(node, json){ + if(json["Name"] != null) + node.setName(json["Name"]); + + var position = json["Position"]; + if(position != null && (position["X"] != null || position["Y"] != null)) + node.setPosition(cc.p(position["X"]||0, position["Y"]||0)); + + var scale = json["Scale"]; + if(scale != null){ + if(scale["ScaleX"] != null) + node.setScaleX(scale["ScaleX"]); + if(scale["ScaleY"] != null) + node.setScaleY(scale["ScaleY"]); + } + + var rotationSkewX = json["RotationSkewX"]; + if (rotationSkewX != null) + node.setRotationX(rotationSkewX); + + var rotationSkewY = json["RotationSkewY"]; + if (json["RotationSkewY"] != null) + node.setRotationY(rotationSkewY); + + + var anchor = json["AnchorPoint"]; + if(anchor != null){ + if(anchor["ScaleX"] == null) + anchor["ScaleX"] = 0; + if(anchor["ScaleY"] == null) + anchor["ScaleY"] = 0; + if(anchor["ScaleX"] != 0.5 || anchor["ScaleY"] != 0.5) + node.setAnchorPoint(cc.p(anchor["ScaleX"], anchor["ScaleY"])); + } + + if (json["ZOrder"] != null) + node.setLocalZOrder(json["ZOrder"]); + + var visible = getParam(json["VisibleForFrame"], true); + node.setVisible(visible); + + setContentSize(node, json["Size"]); + + if (json["Alpha"] !== undefined) + node.setOpacity(json["Alpha"]); + + node.setTag(json["Tag"] || 0); + + var actionTag = json["ActionTag"] || 0; + if (cc.sys.isNative){ + var extensionData = new ccs.ObjectExtensionData(); + var customProperty = json["UserData"]; + if(customProperty !== undefined) + extensionData.setCustomProperty(customProperty); + extensionData.setActionTag(actionTag); + node.setUserObject(extensionData); + } else { + node.setUserObject(new ccs.ActionTimelineData(actionTag)); + } + + node.setCascadeColorEnabled(true); + node.setCascadeOpacityEnabled(true); + }; + + parser.parseChild = function(node, children, resourcePath){ + if(!node || !children) return; + for (var i = 0; i < children.length; i++) { + var child = this.parseNode(children[i], resourcePath); + if(child){ + if(node instanceof ccui.PageView){ + if(child instanceof ccui.Layout) + node.addPage(child); + } else { + if(node instanceof ccui.ListView){ + if(child instanceof ccui.Widget) + node.pushBackCustomItem(child); + } else { + if(!(node instanceof ccui.Layout) && child instanceof ccui.Widget) { + if(child.getPositionType() == ccui.Widget.POSITION_PERCENT) { + var position = child.getPositionPercent(); + var anchor = node.getAnchorPoint(); + child.setPositionPercent(cc.p(position.x + anchor.x, position.y + anchor.y)); + } + } + node.addChild(child); + } + } + } + } + }; + + /** + * SingleNode + * @param json + * @returns {cc.Node} + */ + parser.initSingleNode = function(json){ + var node = new cc.Node(); + + this.generalAttributes(node, json); + + return node; + }; + + /** + * Sprite + * @param json + * @param resourcePath + * @returns {cc.Sprite} + */ + parser.initSprite = function(json, resourcePath){ + var node = new cc.Sprite(); + + loadTexture(json["FileData"], resourcePath, function(path, type){ + if(type == 0) + node.setTexture(path); + else if(type == 1){ + var spriteFrame = cc.spriteFrameCache.getSpriteFrame(path); + node.setSpriteFrame(spriteFrame); + } + }); + + if(json["FlipX"]) + node.setFlippedX(true); + if(json["FlipY"]) + node.setFlippedY(true); + + this.generalAttributes(node, json); + var color = json["CColor"]; + if(color != null) + node.setColor(getColor(color)); + + return node; + }; + + /** + * Particle + * @param json + * @param resourcePath + * @returns {*} + */ + parser.initParticle = function(json, resourcePath){ + var node, + self = this; + loadTexture(json["FileData"], resourcePath, function(path, type){ + if(!cc.loader.getRes(path)) + cc.log("%s need to be preloaded", path); + node = new cc.ParticleSystem(path); + self.generalAttributes(node, json); + !cc.sys.isNative && node.setDrawMode(cc.ParticleSystem.TEXTURE_MODE); + }); + return node; + }; + + + //////////// + // WIDGET // + //////////// + + parser.widgetAttributes = function(widget, json) { + widget.setCascadeColorEnabled(true); + widget.setCascadeOpacityEnabled(true); + + widget.setUnifySizeEnabled(false); + //widget.setLayoutComponentEnabled(true); + widget.ignoreContentAdaptWithSize(false); + setContentSize(widget, json["Size"]); + + var name = json["Name"]; + if (name) + widget.setName(name); + + var actionTag = json["ActionTag"] || 0; + widget.setActionTag(actionTag); + + if (cc.sys.isNative){ + var extensionData = new ccs.ObjectExtensionData(); + var customProperty = json["UserData"]; + if(customProperty !== undefined) + extensionData.setCustomProperty(customProperty); + extensionData.setActionTag(actionTag); + widget.setUserObject(extensionData); + } else { + widget.setUserObject(new ccs.ActionTimelineData(actionTag)); + } + + var rotationSkewX = json["RotationSkewX"]; + if (rotationSkewX) + widget.setRotationX(rotationSkewX); + + var rotationSkewY = json["RotationSkewY"]; + if (rotationSkewY) + widget.setRotationY(rotationSkewY); + + //var rotation = json["Rotation"]; + + var flipX = json["FlipX"]; + if (flipX) + widget.setFlippedX(true); + + var flipY = json["FlipY"]; + if (flipY) + widget.setFlippedY(true); + + var zOrder = json["zOrder"]; + if (zOrder != null) + widget.setLocalZOrder(zOrder); + + //var visible = json["Visible"]; + + var visible = getParam(json["VisibleForFrame"], true); + widget.setVisible(visible); + + var alpha = json["Alpha"]; + if (alpha != null) + widget.setOpacity(alpha); + + widget.setTag(json["Tag"] || 0); + + var touchEnabled = json["TouchEnable"] || false; + widget.setTouchEnabled(touchEnabled); + + // -- var frameEvent = json["FrameEvent"]; + + var callBackType = json["CallBackType"]; + if (callBackType != null) + widget.setCallbackType(callBackType); + + var callBackName = json["CallBackName"]; + if (callBackName) + widget.setCallbackName(callBackName); + + var position = json["Position"]; + if (position != null) + widget.setPosition(position["X"] || 0, position["Y"] || 0); + + var scale = json["Scale"]; + if (scale != null) { + var scaleX = getParam(scale["ScaleX"], 1); + var scaleY = getParam(scale["ScaleY"], 1); + widget.setScaleX(scaleX); + widget.setScaleY(scaleY); + } + + var anchorPoint = json["AnchorPoint"]; + if (anchorPoint != null) + widget.setAnchorPoint(anchorPoint["ScaleX"] || 0, anchorPoint["ScaleY"] || 0); + + var color = json["CColor"]; + if (color != null) + widget.setColor(getColor(color)); + + var layoutComponent = ccui.LayoutComponent.bindLayoutComponent(widget); + if(!layoutComponent) + return; + + var positionXPercentEnabled = json["PositionPercentXEnable"] || false; + var positionYPercentEnabled = json["PositionPercentYEnable"] || false; + var positionXPercent = 0, + positionYPercent = 0, + PrePosition = json["PrePosition"]; + if (PrePosition != null) { + positionXPercent = PrePosition["X"] || 0; + positionYPercent = PrePosition["Y"] || 0; + } + var sizeXPercentEnable = json["PercentWidthEnable"] || false; + var sizeYPercentEnable = json["PercentHeightEnable"] || false; + var sizeXPercent = 0, + sizeYPercent = 0, + PreSize = json["PreSize"]; + if (PrePosition != null) { + sizeXPercent = PreSize["X"] || 0; + sizeYPercent = PreSize["Y"] || 0; + } + var stretchHorizontalEnabled = json["StretchWidthEnable"] || false; + var stretchVerticalEnabled = json["StretchHeightEnable"] || false; + var horizontalEdge = json["HorizontalEdge"];// = ccui.LayoutComponent.horizontalEdge.LEFT; + var verticalEdge = json["VerticalEdge"]; // = ccui.LayoutComponent.verticalEdge.TOP; + var leftMargin = json["LeftMargin"] || 0; + var rightMargin = json["RightMargin"] || 0; + var topMargin = json["TopMargin"] || 0; + var bottomMargin = json["BottomMargin"] || 0; + + layoutComponent.setPositionPercentXEnabled(positionXPercentEnabled); + layoutComponent.setPositionPercentYEnabled(positionYPercentEnabled); + layoutComponent.setPositionPercentX(positionXPercent); + layoutComponent.setPositionPercentY(positionYPercent); + layoutComponent.setPercentWidthEnabled(sizeXPercentEnable); + layoutComponent.setPercentHeightEnabled(sizeYPercentEnable); + layoutComponent.setPercentWidth(sizeXPercent); + layoutComponent.setPercentHeight(sizeYPercent); + layoutComponent.setStretchWidthEnabled(stretchHorizontalEnabled); + layoutComponent.setStretchHeightEnabled(stretchVerticalEnabled); + + var horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.NONE; + if (horizontalEdge == "LeftEdge") { + horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.LEFT; + } else if (horizontalEdge == "RightEdge") { + horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.RIGHT; + } else if (horizontalEdge == "BothEdge") { + horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.CENTER; + } + layoutComponent.setHorizontalEdge(horizontalEdgeType); + + var verticalEdgeType = ccui.LayoutComponent.verticalEdge.NONE; + if (verticalEdge == "TopEdge") { + verticalEdgeType = ccui.LayoutComponent.verticalEdge.TOP; + } else if (verticalEdge == "BottomEdge") { + verticalEdgeType = ccui.LayoutComponent.verticalEdge.BOTTOM; + } else if (verticalEdge == "BothEdge") { + verticalEdgeType = ccui.LayoutComponent.verticalEdge.CENTER; + } + layoutComponent.setVerticalEdge(verticalEdgeType); + + layoutComponent.setTopMargin(topMargin); + layoutComponent.setBottomMargin(bottomMargin); + layoutComponent.setLeftMargin(leftMargin); + layoutComponent.setRightMargin(rightMargin); + }; + + /** + * Layout + * @param json + * @param resourcePath + * @returns {ccui.Layout} + */ + parser.initPanel = function(json, resourcePath){ + var widget = new ccui.Layout(); + + this.widgetAttributes(widget, json); + + var clipEnabled = json["ClipAble"]; + if(clipEnabled != null) + widget.setClippingEnabled(clipEnabled); + + var colorType = getParam(json["ComboBoxIndex"], 0); + widget.setBackGroundColorType(colorType); + + var bgColorOpacity = getParam(json["BackColorAlpha"], 255); + if(bgColorOpacity != null) + widget.setBackGroundColorOpacity(bgColorOpacity); + + var backGroundScale9Enabled = json["Scale9Enable"]; + if(backGroundScale9Enabled != null) + widget.setBackGroundImageScale9Enabled(backGroundScale9Enabled); + + var opacity = getParam(json["Alpha"], 255); + widget.setOpacity(opacity); + + loadTexture(json["FileData"], resourcePath, function(path, type){ + widget.setBackGroundImage(path, type); + }); + + if(backGroundScale9Enabled){ + var scale9OriginX = json["Scale9OriginX"] || 0; + var scale9OriginY = json["Scale9OriginY"] || 0; + + var scale9Width = json["Scale9Width"] || 0; + var scale9Height = json["Scale9Height"] || 0; + + widget.setBackGroundImageCapInsets(cc.rect( + scale9OriginX, scale9OriginY, scale9Width, scale9Height + )); + + setContentSize(widget, json["Size"]); + }else{ + if (!widget.isIgnoreContentAdaptWithSize()){ + setContentSize(widget, json["Size"]); + } + + } + + var firstColor = json["FirstColor"]; + var endColor = json["EndColor"]; + if(endColor["R"] != null && endColor["G"] != null && endColor["B"] != null) + widget.setBackGroundColor(getColor(firstColor), getColor(endColor)); + else + widget.setBackGroundColor(getColor(json["SingleColor"])); + + var colorVector = json["ColorVector"]; + if(colorVector != null) + widget.setBackGroundColorVector(cc.p(colorVector["ScaleX"], colorVector["ScaleY"])); + + return widget; + }; + + /** + * Text + * @param json + * @param resourcePath + */ + parser.initText = function(json, resourcePath){ + + var widget = new ccui.Text(); + + this.widgetAttributes(widget, json); + + var touchScaleEnabled = json["TouchScaleChangeAble"]; + if(touchScaleEnabled != null) + widget.setTouchScaleChangeEnabled(touchScaleEnabled); + + var text = json["LabelText"]; + if(text != null) + widget.setString(text); + + var fontSize = json["FontSize"]; + if(fontSize != null) + widget.setFontSize(fontSize); + + var fontName = json["FontName"]; + if(fontName != null) + widget.setFontName(fontName); + + var areaWidth = json["AreaWidth"]; + var areaHeight = json["areaHeight"]; + if(areaWidth && areaHeight) + widget.setTextAreaSize(cc.size(areaWidth, areaHeight)); + + var h_alignment = json["HorizontalAlignmentType"] || "HT_Left"; + switch(h_alignment){ + case "HT_Right": + h_alignment = 2; break; + case "HT_Center": + h_alignment = 1; break; + case "HT_Left": + default: + h_alignment = 0; + } + widget.setTextHorizontalAlignment(h_alignment); + + var v_alignment = json["VerticalAlignmentType"] || "VT_Top"; + switch(v_alignment){ + case "VT_Bottom": + v_alignment = 2; break; + case "VT_Center": + v_alignment = 1; break; + case "VT_Top": + default: + v_alignment = 0; + } + widget.setTextVerticalAlignment(v_alignment); + + //todo check it + var isCustomSize = json["IsCustomSize"]; + if(isCustomSize != null) + widget.ignoreContentAdaptWithSize(!isCustomSize); + + var fontResource = json["FontResource"]; + if(fontResource != null){ + var path = fontResource["Path"]; + //resoutceType = fontResource["Type"]; + if(path != null){ + if (cc.sys.isNative) { + fontName = cc.path.join(cc.loader.resPath, resourcePath, path); + } else { + fontName = path.match(/([^\/]+)\.ttf/); + fontName = fontName ? fontName[1] : ""; + } + widget.setFontName(fontName); + } + } + + widget.setUnifySizeEnabled(false); + + if(widget.isIgnoreContentAdaptWithSize()) + setContentSize(widget, json["Size"]); + + return widget; + + }; + + /** + * Button + * @param json + * @param resourcePath + */ + parser.initButton = function(json, resourcePath){ + + var widget = new ccui.Button(); + + loadTexture(json["NormalFileData"], resourcePath, function(path, type){ + widget.loadTextureNormal(path, type); + }); + loadTexture(json["PressedFileData"], resourcePath, function(path, type){ + widget.loadTexturePressed(path, type); + }); + loadTexture(json["DisabledFileData"], resourcePath, function(path, type){ + widget.loadTextureDisabled(path, type); + }); + + var scale9Enabled = getParam(json["Scale9Enable"], false); + if(scale9Enabled) { + widget.setScale9Enabled(scale9Enabled); + } + + var text = json["ButtonText"]; + if(text != null) + widget.setTitleText(text); + + var fontSize = json["FontSize"]; + if(fontSize != null) + widget.setTitleFontSize(fontSize); + + var fontName = json["FontName"]; + if(fontName != null) + widget.setTitleFontName(fontName); + + var textColor = json["TextColor"]; + if(textColor != null) + widget.setTitleColor(getColor(textColor)); + + var displaystate = getParam(json["DisplayState"], true); + widget.setBright(displaystate); + widget.setEnabled(displaystate); + + var fontResource = json["FontResource"]; + if(fontResource != null){ + var path = fontResource["Path"]; + //resoutceType = fontResource["Type"]; + if(path != null){ + if (cc.sys.isNative) { + fontName = cc.path.join(cc.loader.resPath, resourcePath, path); + } else { + fontName = path.match(/([^\/]+)\.ttf/); + fontName = fontName ? fontName[1] : ""; + } + widget.setTitleFontName(fontName); + } + } + this.widgetAttributes(widget, json); + + if(scale9Enabled) { + widget.setUnifySizeEnabled(false); + widget.ignoreContentAdaptWithSize(false); + var capInsets = cc.rect( + json["Scale9OriginX"] || 0, + json["Scale9OriginY"] || 0, + json["Scale9Width"] || 0, + json["Scale9Height"] || 0 + ); + widget.setCapInsets(capInsets); + + } + + setContentSize(widget, json["Size"]); + + return widget; + + }; + + /** + * CheckBox + * @param json + * @param resourcePath + */ + parser.initCheckBox = function(json, resourcePath){ + + var widget = new ccui.CheckBox(); + + this.widgetAttributes(widget, json); + + var dataList = [ + {name: "NormalBackFileData", handle: widget.loadTextureBackGround}, + {name: "PressedBackFileData", handle: widget.loadTextureBackGroundSelected}, + {name: "NodeNormalFileData", handle: widget.loadTextureFrontCross}, + {name: "DisableBackFileData", handle: widget.loadTextureBackGroundDisabled}, + {name: "NodeDisableFileData", handle: widget.loadTextureFrontCrossDisabled} + ]; + + dataList.forEach(function(item){ + loadTexture(json[item.name], resourcePath, function(path, type){ + item.handle.call(widget, path, type); + }); + }); + + var selectedState = getParam(json["CheckedState"], false); + widget.setSelected(selectedState); + + var displaystate = getParam(json["DisplayState"], true); + widget.setBright(displaystate); + widget.setEnabled(displaystate); + + return widget; + }; + + /** + * ScrollView + * @param json + * @param resourcePath + */ + parser.initScrollView = function(json, resourcePath){ + var widget = new ccui.ScrollView(); + + this.widgetAttributes(widget, json); + + loadTexture(json["FileData"], resourcePath, function(path, type){ + widget.setBackGroundImage(path, type); + }); + + var clipEnabled = json["ClipAble"]; + widget.setClippingEnabled(clipEnabled); + + var colorType = getParam(json["ComboBoxIndex"], 0); + widget.setBackGroundColorType(colorType); + + var bgColorOpacity = json["BackColorAlpha"]; + if(bgColorOpacity != null) + widget.setBackGroundColorOpacity(bgColorOpacity); + + var backGroundScale9Enabled = json["Scale9Enable"]; + if(backGroundScale9Enabled){ + widget.setBackGroundImageScale9Enabled(true); + + + var scale9OriginX = json["Scale9OriginX"] || 0; + var scale9OriginY = json["Scale9OriginY"] || 0; + var scale9Width = json["Scale9Width"] || 0; + var scale9Height = json["Scale9Height"] || 0; + widget.setBackGroundImageCapInsets(cc.rect( + scale9OriginX, scale9OriginY, scale9Width, scale9Height + )); + setContentSize(widget, json["Size"]); + }else if(!widget.isIgnoreContentAdaptWithSize()){ + setContentSize(widget, json["Size"]); + } + + var firstColor = json["FirstColor"]; + var endColor = json["EndColor"]; + if(firstColor && endColor){ + if(endColor["R"] != null && endColor["G"] != null && endColor["B"] != null) + widget.setBackGroundColor(getColor(firstColor), getColor(endColor)); + else + widget.setBackGroundColor(getColor(firstColor)); + }else{ + widget.setBackGroundColor(getColor(json["SingleColor"])); + } + + + var colorVector = json["ColorVector"]; + if(colorVector){ + var colorVectorX = getParam(colorVector["ScaleX"], 1); + var colorVectorY = getParam(colorVector["ScaleY"], 1); + widget.setBackGroundColorVector(cc.p(colorVectorX, colorVectorY)); + } + + var innerNodeSize = json["InnerNodeSize"]; + var innerSize = cc.size( + innerNodeSize["Width"] || 0, + innerNodeSize["Height"] || 0 + ); + widget.setInnerContainerSize(innerSize); + + var direction = 0; + if(json["ScrollDirectionType"] == "Vertical") direction = 1; + if(json["ScrollDirectionType"] == "Horizontal") direction = 2; + if(json["ScrollDirectionType"] == "Vertical_Horizontal") direction = 3; + widget.setDirection(direction); + + var bounceEnabled = getParam(json["IsBounceEnabled"], false); + widget.setBounceEnabled(bounceEnabled); + + return widget; + }; + + /** + * ImageView + * @param json + * @param resourcePath + */ + parser.initImageView = function(json, resourcePath){ + + var widget = new ccui.ImageView(); + + loadTexture(json["FileData"], resourcePath, function(path, type){ + widget.loadTexture(path, type); + }); + loadTexture(json["ImageFileData"], resourcePath, function(path, type){ + widget.loadTexture(path, type); + }); + + var scale9Enabled = json["Scale9Enable"]; + if(scale9Enabled){ + widget.setScale9Enabled(true); + widget.setUnifySizeEnabled(false); + widget.ignoreContentAdaptWithSize(false); + + var scale9OriginX = json["Scale9OriginX"] || 0; + var scale9OriginY = json["Scale9OriginY"] || 0; + var scale9Width = json["Scale9Width"] || 0; + var scale9Height = json["Scale9Height"] || 0; + widget.setCapInsets(cc.rect( + scale9OriginX , + scale9OriginY, + scale9Width, + scale9Height + )); + } else + setContentSize(widget, json["Size"]); + + this.widgetAttributes(widget, json); + + return widget; + }; + + /** + * LoadingBar + * @param json + * @param resourcePath + * @returns {ccui.LoadingBar} + */ + parser.initLoadingBar = function(json, resourcePath){ + + var widget = new ccui.LoadingBar(); + + this.widgetAttributes(widget, json); + + loadTexture(json["ImageFileData"], resourcePath, function(path, type){ + widget.loadTexture(path, type); + }); + + var direction = json["ProgressType"] === "Right_To_Left" ? 1 : 0; + widget.setDirection(direction); + + var percent = getParam(json["ProgressInfo"], 80); + if(percent != null) + widget.setPercent(percent); + + return widget; + + }; + + /** + * Slider + * @param json + * @param resourcePath + */ + parser.initSlider = function(json, resourcePath){ + + var widget = new ccui.Slider(); + var loader = cc.loader; + + this.widgetAttributes(widget, json); + + var textureList = [ + {name: "BackGroundData", handle: widget.loadBarTexture}, + {name: "BallNormalData", handle: widget.loadSlidBallTextureNormal}, + {name: "BallPressedData", handle: widget.loadSlidBallTexturePressed}, + {name: "BallDisabledData", handle: widget.loadSlidBallTextureDisabled}, + {name: "ProgressBarData", handle: widget.loadProgressBarTexture} + ]; + textureList.forEach(function(item){ + loadTexture(json[item.name], resourcePath, function(path, type){ + if(type == 0 && !loader.getRes(path)) + cc.log("%s need to be preloaded", path); + item.handle.call(widget, path, type); + }); + }); + + var percent = json["PercentInfo"] || 0; + widget.setPercent(percent); + + var displaystate = getParam(json["DisplayState"], true); + widget.setBright(displaystate); + widget.setEnabled(displaystate); + + return widget; + }; + + /** + * PageView + * @param json + * @param resourcePath + */ + parser.initPageView = function(json, resourcePath){ + + var widget = new ccui.PageView(); + + this.widgetAttributes(widget, json); + + loadTexture(json["FileData"], resourcePath, function(path, type){ + widget.setBackGroundImage(path, type); + }); + + var clipEnabled = json["ClipAble"] || false; + widget.setClippingEnabled(clipEnabled); + + var backGroundScale9Enabled = json["Scale9Enable"]; + if(backGroundScale9Enabled){ + widget.setBackGroundImageScale9Enabled(true); + + var scale9OriginX = json["Scale9OriginX"] || 0; + var scale9OriginY = json["Scale9OriginY"] || 0; + var scale9Width = json["Scale9Width"] || 0; + var scale9Height = json["Scale9Height"] || 0; + widget.setBackGroundImageCapInsets(cc.rect( + scale9OriginX, + scale9OriginY, + scale9Width, + scale9Height + )); + } + + var colorType = getParam(json["ComboBoxIndex"], 0); + widget.setBackGroundColorType(colorType); + + var bgColorOpacity = json["BackColorAlpha"]; + var firstColor = json["FirstColor"]; + var endColor = json["EndColor"]; + if(firstColor && endColor){ + if(endColor["R"] != null && endColor["G"] != null && endColor["B"] != null) + widget.setBackGroundColor(getColor(firstColor), getColor(endColor)); + else + widget.setBackGroundColor(getColor(firstColor)); + }else{ + widget.setBackGroundColor(getColor(json["SingleColor"])); + } + + var colorVector = json["ColorVector"]; + if(colorVector != null && colorVector["ScaleX"] != null && colorVector["ScaleY"] != null) + widget.setBackGroundColorVector(cc.p(colorVector["ScaleX"], colorVector["ScaleY"])); + if(bgColorOpacity != null) + widget.setBackGroundColorOpacity(bgColorOpacity); + + setContentSize(widget, json["Size"]); + + return widget; + + }; + + /** + * ListView + * @param json + * @param resourcePath + * @returns {ccui.ListView} + */ + parser.initListView = function(json, resourcePath){ + + var widget = new ccui.ListView(); + + this.widgetAttributes(widget, json); + + loadTexture(json["FileData"], resourcePath, function(path, type){ + widget.setBackGroundImage(path, type); + }); + + var clipEnabled = json["ClipAble"] || false; + widget.setClippingEnabled(clipEnabled); + + var colorType = getParam(json["ComboBoxIndex"], 0); + widget.setBackGroundColorType(colorType); + + var bgColorOpacity = getParam(json["BackColorAlpha"], 255); + var backGroundScale9Enabled = json["Scale9Enable"]; + if(backGroundScale9Enabled){ + widget.setBackGroundImageScale9Enabled(true); + + var scale9OriginX = json["Scale9OriginX"] || 0; + var scale9OriginY = json["Scale9OriginY"] || 0; + var scale9Width = json["Scale9Width"] || 0; + var scale9Height = json["Scale9Height"] || 0; + widget.setBackGroundImageCapInsets(cc.rect( + scale9OriginX, + scale9OriginY, + scale9Width, + scale9Height + )); + } + + var directionType = getParam(json["DirectionType"], ccui.ListView.DIR_HORIZONTAL); + var verticalType = getParam(json["VerticalType"], "Align_Left"); + var horizontalType = getParam(json["HorizontalType"], "Align_Top"); + if(!directionType){ + widget.setDirection(ccui.ScrollView.DIR_HORIZONTAL); + if(verticalType == "Align_Bottom") + widget.setGravity(ccui.ListView.GRAVITY_BOTTOM); + else if(verticalType == "Align_VerticalCenter") + widget.setGravity(ccui.ListView.GRAVITY_CENTER_VERTICAL); + else + widget.setGravity(ccui.ListView.GRAVITY_TOP); + }else if(directionType == "Vertical"){ + widget.setDirection(ccui.ScrollView.DIR_VERTICAL); + if (horizontalType == "") + widget.setGravity(ccui.ListView.GRAVITY_LEFT); + else if (horizontalType == "Align_Right") + widget.setGravity(ccui.ListView.GRAVITY_RIGHT); + else if (horizontalType == "Align_HorizontalCenter") + widget.setGravity(ccui.ListView.GRAVITY_CENTER_HORIZONTAL); + } + + + var bounceEnabled = getParam(json["IsBounceEnabled"], false); + widget.setBounceEnabled(bounceEnabled); + + var itemMargin = json["ItemMargin"] || 0; + widget.setItemsMargin(itemMargin); + + var innerSize = json["InnerNodeSize"]; + //Width + if(innerSize != null) + widget.setInnerContainerSize(cc.size(innerSize["Widget"]||0, innerSize["Height"]||0)); + + var firstColor = json["FirstColor"]; + var endColor = json["EndColor"]; + if(firstColor && endColor){ + if(endColor["R"] != null && endColor["G"] != null && endColor["B"] != null) + widget.setBackGroundColor(getColor(firstColor), getColor(endColor)); + else + widget.setBackGroundColor(getColor(firstColor)); + }else{ + widget.setBackGroundColor(getColor(json["SingleColor"])); + } + + var colorVector = json["ColorVector"]; + if(colorVector != null && colorVector["ScaleX"] != null && colorVector["ScaleY"] != null) + widget.setBackGroundColorVector(cc.p(colorVector["ScaleX"], colorVector["ScaleY"])); + if(bgColorOpacity != null) + widget.setBackGroundColorOpacity(bgColorOpacity); + + setContentSize(widget, json["Size"]); + + return widget; + }; + + /** + * TextAtlas + * @param json + * @param resourcePath + * @returns {ccui.TextAtlas} + */ + parser.initTextAtlas = function(json, resourcePath){ + + var widget = new ccui.TextAtlas(); + + var stringValue = json["LabelText"]; + var itemWidth = json["CharWidth"]; + var itemHeight = json["CharHeight"]; + + var startCharMap = json["StartChar"]; + + loadTexture(json["LabelAtlasFileImage_CNB"], resourcePath, function(path, type){ + if(!cc.loader.getRes(path)) + cc.log("%s need to be preloaded", path); + if(type == 0){ + widget.setProperty(stringValue, path, itemWidth, itemHeight, startCharMap); + } + }); + this.widgetAttributes(widget, json); + + return widget; + }; + + /** + * TextBMFont + * @param json + * @param resourcePath + * @returns {ccui.TextBMFont} + */ + parser.initTextBMFont = function(json, resourcePath){ + + var widget = new ccui.TextBMFont(); + this.widgetAttributes(widget, json); + + var text = json["LabelText"]; + widget.setString(text); + + loadTexture(json["LabelBMFontFile_CNB"], resourcePath, function(path, type){ + if(!cc.loader.getRes(path)) + cc.log("%s need to be pre loaded", path); + widget.setFntFile(path); + }); + return widget; + }; + + /** + * TextField + * @param json + * @param resourcePath + * @returns {ccui.TextField} + */ + parser.initTextField = function(json, resourcePath){ + var widget = new ccui.TextField(); + + var passwordEnabled = json["PasswordEnable"]; + if(passwordEnabled){ + widget.setPasswordEnabled(true); + var passwordStyleText = json["PasswordStyleText"] || "*"; + widget.setPasswordStyleText(passwordStyleText); + } + + var placeHolder = json["PlaceHolderText"]; + if(placeHolder != null) + widget.setPlaceHolder(placeHolder); + + var fontSize = json["FontSize"]; + if(fontSize != null) + widget.setFontSize(fontSize); + + var fontName = json["FontName"]; + if(fontName != null) + widget.setFontName(fontName); + + var maxLengthEnabled = json["MaxLengthEnable"]; + if(maxLengthEnabled){ + widget.setMaxLengthEnabled(true); + var maxLength = json["MaxLengthText"] || 0; + widget.setMaxLength(maxLength); + } + + //var isCustomSize = json["IsCustomSize"]; + this.widgetAttributes(widget, json); + + var text = json["LabelText"]; + if(text != null) + widget.setString(text); + + var fontResource = json["FontResource"]; + if(fontResource != null){ + var path = fontResource["Path"]; + //resoutceType = fontResource["Type"]; + if(path != null){ + if (cc.sys.isNative) { + fontName = cc.path.join(cc.loader.resPath, resourcePath, path); + } else { + fontName = path.match(/([^\/]+)\.ttf/); + fontName = fontName ? fontName[1] : ""; + } + widget.setFontName(fontName); + } + } + + widget.setUnifySizeEnabled(false); + widget.ignoreContentAdaptWithSize(false); + + var color = json["CColor"]; + if(color != null) + widget.setTextColor(getColor(color)); + + if (!widget.isIgnoreContentAdaptWithSize()){ + setContentSize(widget, json["Size"]); + if (cc.sys.isNative) + widget.getVirtualRenderer().setLineBreakWithoutSpace(true); + } + + + return widget; + + }; + + /** + * SimpleAudio + * @param json + * @param resourcePath + */ + parser.initSimpleAudio = function(json, resourcePath){ + + var loop = json["Loop"] || false; + var volume = json["Volume"] || 0; + cc.audioEngine.setMusicVolume(volume); + //var name = json["Name"]; + var resPath = ""; + if(cc.loader.resPath) + resPath = (cc.loader.resPath + "/").replace(/\/\/$/, "/"); + + loadTexture(json["FileData"], resourcePath, function(path, type){ + cc.loader.load(path, function(){ + cc.audioEngine.playMusic(resPath + path, loop); + }); + }); + + }; + + /** + * GameMap + * @param json + * @param resourcePath + * @returns {*} + */ + parser.initGameMap = function(json, resourcePath){ + + var node = null; + + loadTexture(json["FileData"], resourcePath, function(path, type){ + if(type == 0) + node = new cc.TMXTiledMap(path); + + parser.generalAttributes(node, json); + }); + + return node; + }; + + /** + * ProjectNode + * @param json + * @param resourcePath + * @returns {*} + */ + parser.initProjectNode = function(json, resourcePath){ + var projectFile = json["FileData"]; + if(projectFile != null && projectFile["Path"]){ + var file = resourcePath + projectFile["Path"]; + if(cc.loader.getRes(file)){ + var obj = ccs.load(file, resourcePath); + parser.generalAttributes(obj.node, json); + if(obj.action && obj.node){ + obj.action.tag = obj.node.tag; + var InnerActionSpeed = json["InnerActionSpeed"]; + if(InnerActionSpeed !== undefined) + obj.action.setTimeSpeed(InnerActionSpeed); + obj.node.runAction(obj.action); + obj.action.gotoFrameAndPause(0); + } + return obj.node; + } else + cc.log("%s need to be preloaded", file); + } + }; + + var getFileName = function(name){ + if(!name) return ""; + var arr = name.match(/([^\/]+)\.[^\/]+$/); + if(arr && arr[1]) + return arr[1]; + else + return ""; + }; + + /** + * Armature + * @param json + * @param resourcePath + */ + parser.initArmature = function(json, resourcePath){ + + var node = new ccs.Armature(); + + var isLoop = json["IsLoop"]; + + var isAutoPlay = json["IsAutoPlay"]; + + var currentAnimationName = json["CurrentAnimationName"]; + + parser.generalAttributes(node, json); + + loadTexture(json["FileData"], resourcePath, function(path, type){ + var plists, pngs; + var armJson = cc.loader.getRes(path); + if(!armJson) + cc.log("%s need to be preloaded", path); + else{ + plists = armJson["config_file_path"]; + pngs = armJson["config_png_path"]; + plists.forEach(function(plist, index){ + if(pngs[index]) + cc.spriteFrameCache.addSpriteFrames(plist, pngs[index]); + }); + } + ccs.armatureDataManager.addArmatureFileInfo(path); + node.init(getFileName(path)); + if(isAutoPlay) + node.getAnimation().play(currentAnimationName, -1, isLoop); + + }); + return node; + }; + + var loadedPlist = {}; + var loadTexture = function(json, resourcePath, cb){ + if(json != null){ + var path = json["Path"]; + var type; + if(json["Type"] == "Default" || json["Type"] == "Normal") + type = 0; + else + type = 1; + var plist = json["Plist"]; + if(plist){ + if(cc.loader.getRes(resourcePath + plist)){ + loadedPlist[resourcePath + plist] = true; + cc.spriteFrameCache.addSpriteFrames(resourcePath + plist); + }else{ + if(!loadedPlist[resourcePath + plist]) + cc.log("%s need to be preloaded", resourcePath + plist); + } + } + if(type !== 0) + cb(path, type); + else + cb(resourcePath + path, type); + } + }; + + var getColor = function(json){ + if(!json) return; + var r = json["R"] != null ? json["R"] : 255; + var g = json["G"] != null ? json["G"] : 255; + var b = json["B"] != null ? json["B"] : 255; + return cc.color(r, g, b); + }; + + var setContentSize = function(node, size){ + var x = size["X"] || 0; + var y = size["Y"] || 0; + if(size) + node.setContentSize(cc.size(x, y)); + }; + + var get3DVector = function(json, name, defValue){ + var x = defValue, y = defValue, z = defValue; + if(json && name && json[name]){ + x = null != json[name]["ValueX"] ? json[name]["ValueX"] : defValue; + y = null != json[name]["ValueY"] ? json[name]["ValueY"] : defValue; + z = null != json[name]["ValueZ"] ? json[name]["ValueZ"] : defValue; + } + var vec3 = cc.math.vec3(x, y, z); + return vec3; + }; + + parser.general3DAttributes = function(node, json){ + var pos = get3DVector(json, "Position3D", 0); + node.setPosition3D(pos); + + var rotation = get3DVector(json, "Rotation3D", 0); + node.setRotation3D(rotation); + + var scale = get3DVector(json, "Scale3D", 1.0); + node.setScaleX(scale.x); + node.setScaleY(scale.y); + node.setScaleZ(scale.z); + + var camMask =json["CameraFlagMode"]; + if(undefined !== camMask && null !== camMask) + node.setCameraMask(camMask); + + this.generalAttributes(node, json); + }; + + /** + * Node3D + * @param json + * @returns {*} + */ + parser.initNode3D = function(json){ + var node = cc.Node.create(); + if(node) + this.general3DAttributes(node, json); + return node; + }; + + /** + * Camera + * @param json + * @returns {*} + */ + parser.initCamera = function(json){ + var s = cc.winSize; + var fov = json["Fov"] ? json["Fov"] : 60; + + var nearClip = 1; + var farClip = 500; + if(json["ClipPlane"]){ + nearClip = json["ClipPlane"]["ValueX"]; + farClip = json["ClipPlane"]["ValueY"]; + if(null === nearClip || isNaN(nearClip)) + nearClip = 1; + if(null === farClip || isNaN(farClip)) + farClip = 500; + } + + var node = cc.Camera.createPerspective(fov, s.width/s.height, nearClip, farClip); + + if(node){ + this.general3DAttributes(node, json); + + var camMode = json["UserCameraFlagMode"]; + switch(camMode){ + case "USER1": + node.setCameraFlag(cc.CameraFlag.USER1); break; + case "USER2": + node.setCameraFlag(cc.CameraFlag.USER2); break; + case "USER3": + node.setCameraFlag(cc.CameraFlag.USER3); break; + case "USER4": + node.setCameraFlag(cc.CameraFlag.USER4); break; + case "USER5": + node.setCameraFlag(cc.CameraFlag.USER5); break; + case "USER6": + node.setCameraFlag(cc.CameraFlag.USER6); break; + case "USER7": + node.setCameraFlag(cc.CameraFlag.USER7); break; + case "USER8": + node.setCameraFlag(cc.CameraFlag.USER8); break; + case "DEFAULT": + node.setCameraFlag(cc.CameraFlag.DEFAULT); break; + default: + node.setCameraFlag(cc.CameraFlag.USER1); + } + } + + return node; + }; + + /** + * Sprite3D + * @param json + * @param resourcePath + * @returns {*} + */ + parser.initSprite3D = function(json, resourcePath){ + var resFile = null; + if(json["FileData"] && json["FileData"]["Path"]) + resFile = resourcePath + json["FileData"]["Path"]; + + var node; + if(resFile) + node = jsb.Sprite3D.create(resFile); + else + node = jsb.Sprite3D.create(); + + if(node) { + this.general3DAttributes(node, json); + + if(json["CColor"]) { + var col = getColor(json["CColor"]); + if(col && col.r !== 255 || col.g !== 255 || col.b !== 255) + node.setColor(col); + } + + var autoAction = getParam(json["RunAction3D"], false); + if(autoAction && resFile){ + var animation = jsb.Animation3D.create(resFile, ""); + if(animation){ + var animate = jsb.Animate3D.create(animation); + var action = cc.RepeatForever.create(animate); + node.runAction(action); + } + } + } + + return node; + }; + + /** + * Particle3D + * @param json + * @param resourcePath + * @returns {*} + */ + parser.initParticle3D = function(json, resourcePath){ + var node = null; + + var resFile = null; + if(json["FileData"] && json["FileData"]["Path"]) + resFile = resourcePath+json["FileData"]["Path"]; + + if(resFile) + node = jsb.PUParticleSystem3D.create(resFile); + else + node = jsb.PUParticleSystem3D.create(); + + if(node){ + this.general3DAttributes(node, json); + node.startParticleSystem(); + } + + return node; + }; + + var register = [ + {name: "SingleNodeObjectData", handle: parser.initSingleNode}, + {name: "NodeObjectData", handle: parser.initSingleNode}, + {name: "LayerObjectData", handle: parser.initSingleNode}, + {name: "SpriteObjectData", handle: parser.initSprite}, + {name: "ParticleObjectData", handle: parser.initParticle}, + {name: "PanelObjectData", handle: parser.initPanel}, + {name: "TextObjectData", handle: parser.initText}, + {name: "ButtonObjectData", handle: parser.initButton}, + {name: "CheckBoxObjectData", handle: parser.initCheckBox}, + {name: "ScrollViewObjectData", handle: parser.initScrollView}, + {name: "ImageViewObjectData", handle: parser.initImageView}, + {name: "LoadingBarObjectData", handle: parser.initLoadingBar}, + {name: "SliderObjectData", handle: parser.initSlider}, + {name: "PageViewObjectData", handle: parser.initPageView}, + {name: "ListViewObjectData", handle: parser.initListView}, + {name: "TextAtlasObjectData", handle: parser.initTextAtlas}, + {name: "TextBMFontObjectData", handle: parser.initTextBMFont}, + {name: "TextFieldObjectData", handle: parser.initTextField}, + {name: "SimpleAudioObjectData", handle: parser.initSimpleAudio}, + {name: "GameMapObjectData", handle: parser.initGameMap}, + {name: "ProjectNodeObjectData", handle: parser.initProjectNode}, + {name: "ArmatureNodeObjectData", handle: parser.initArmature}, + + {name: "Sprite3DObjectData", handle: parser.initSprite3D}, + {name: "Particle3DObjectData", handle: parser.initParticle3D}, + {name: "UserCameraObjectData", handle: parser.initCamera}, + {name: "Node3DObjectData", handle: parser.initNode3D} + ]; + + register.forEach(function(item){ + parser.registerParser(item.name, function(options, resourcePath){ + var node = item.handle.call(this, options, resourcePath); + this.parseChild(node, options["Children"], resourcePath); + DEBUG && node && (node.__parserName = item.name); + return node; + }); + }); + + + load.registerParser("timeline", "2.*", parser); + + +})(ccs._load, ccs._parser); diff --git a/frameworks/js-bindings/bindings/script/studio/parsers/uiParser-1.x.js b/frameworks/js-bindings/bindings/script/studio/parsers/uiParser-1.x.js new file mode 100644 index 0000000000..a6762cac64 --- /dev/null +++ b/frameworks/js-bindings/bindings/script/studio/parsers/uiParser-1.x.js @@ -0,0 +1,698 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ + +(function(load, baseParser){ + + var Parser = baseParser.extend({ + + addSpriteFrame: function(textures, resourcePath){ + if(!textures) return; + for (var i = 0; i < textures.length; i++) { + cc.spriteFrameCache.addSpriteFrames(resourcePath + textures[i]); + } + }, + + pretreatment: function(json, resourcePath){ + this.addSpriteFrame(json["textures"], resourcePath); + }, + + deferred: function(json, resourcePath, node, file){ + if(node){ + ccs.actionManager.initWithDictionary(file, json["animation"], node); + node.setContentSize(cc.size(json["designWidth"], json["designHeight"])); + } + } + + }); + var parser = new Parser(); + + + parser.generalAttributes = function(widget, options){ + var ignoreSizeExsit = options["ignoreSize"]; + if(ignoreSizeExsit != null) + widget.ignoreContentAdaptWithSize(ignoreSizeExsit); + + if (options["sizeType"]) + { + widget.setSizeType(options["sizeType"]); + } + + if (options["positionType"]) + { + widget.setPositionType(options["positionType"]); + } + + widget.setSizePercent(cc.p(options["sizePercentX"], options["sizePercentY"])); + widget.setPositionPercent(cc.p(options["positionPercentX"], options["positionPercentY"])); + + /* adapt screen */ + var w = 0, h = 0; + var adaptScreen = options["adaptScreen"]; + if (adaptScreen) { + var screenSize = cc.director.getWinSize(); + w = screenSize.width; + h = screenSize.height; + } else { + w = options["width"]; + h = options["height"]; + } + widget.setContentSize(w, h); + + widget.setTag(options["tag"]); + widget.setActionTag(options["actiontag"]); + widget.setTouchEnabled(options["touchAble"]); + var name = options["name"]; + var widgetName = name ? name : "default"; + widget.setName(widgetName); + + var x = options["x"]; + var y = options["y"]; + widget.setPosition(x, y); + + var sx = options["scaleX"]!=null ? options["scaleX"] : 1; + widget.setScaleX(sx); + + var sy = options["scaleY"]!=null ? options["scaleY"] : 1; + widget.setScaleY(sy); + + var rt = options["rotation"] || 0; + widget.setRotation(rt); + + var vb = options["visible"] || false; + if(vb != null) + widget.setVisible(vb); + widget.setLocalZOrder(options["ZOrder"]); + + var layout = options["layoutParameter"]; + if(layout != null){ + var layoutParameterDic = options["layoutParameter"]; + var paramType = layoutParameterDic["type"]; + var parameter = null; + + switch(paramType){ + case 0: + break; + case 1: + parameter = new ccui.LinearLayoutParameter(); + var gravity = layoutParameterDic["gravity"]; + parameter.setGravity(gravity); + break; + case 2: + parameter = new ccui.RelativeLayoutParameter(); + var rParameter = parameter; + var relativeName = layoutParameterDic["relativeName"]; + rParameter.setRelativeName(relativeName); + var relativeToName = layoutParameterDic["relativeToName"]; + rParameter.setRelativeToWidgetName(relativeToName); + var align = layoutParameterDic["align"]; + rParameter.setAlign(align); + break; + default: + break; + } + if(parameter != null){ + var mgl = layoutParameterDic["marginLeft"]||0; + var mgt = layoutParameterDic["marginTop"]||0; + var mgr = layoutParameterDic["marginRight"]||0; + var mgb = layoutParameterDic["marginDown"]||0; + parameter.setMargin(mgl, mgt, mgr, mgb); + widget.setLayoutParameter(parameter); + } + } + }; + + parser.colorAttributes = function(widget, options){ + var op = options["opacity"]; + if(op != null) + widget.setOpacity(op); + var colorR = options["colorR"]; + var colorG = options["colorG"]; + var colorB = options["colorB"]; + widget.setColor(cc.color((colorR == null) ? 255 : colorR, (colorG == null) ? 255 : colorG, (colorB == null) ? 255 : colorB)); + + widget.setFlippedX(options["flipX"]); + widget.setFlippedY(options["flipY"]); + }; + + parser.anchorPointAttributes = function(widget, options){ + var isAnchorPointXExists = options["anchorPointX"]; + var anchorPointXInFile; + if (isAnchorPointXExists != null) + anchorPointXInFile = options["anchorPointX"]; + else + anchorPointXInFile = widget.getAnchorPoint().x; + + var isAnchorPointYExists = options["anchorPointY"]; + var anchorPointYInFile; + if (isAnchorPointYExists != null) + anchorPointYInFile = options["anchorPointY"]; + else + anchorPointYInFile = widget.getAnchorPoint().y; + + if (isAnchorPointXExists != null || isAnchorPointYExists != null) + widget.setAnchorPoint(cc.p(anchorPointXInFile, anchorPointYInFile)); + }; + + parser.parseChild = function(widget, options, resourcePath){ + var children = options["children"]; + for (var i = 0; i < children.length; i++) { + var child = this.parseNode(children[i], resourcePath); + if(child){ + if(widget instanceof ccui.PageView) + widget.addPage(child); + else { + if(widget instanceof ccui.ListView){ + widget.pushBackCustomItem(child); + } else { + if(!(widget instanceof ccui.Layout)) { + if(child.getPositionType() == ccui.Widget.POSITION_PERCENT) { + var position = child.getPositionPercent(); + var anchor = widget.getAnchorPoint(); + child.setPositionPercent(cc.p(position.x + anchor.x, position.y + anchor.y)); + } + var AnchorPointIn = widget.getAnchorPointInPoints(); + child.setPosition(cc.p(child.getPositionX() + AnchorPointIn.x, child.getPositionY() + AnchorPointIn.y)); + } + widget.addChild(child); + } + } + } + } + }; + + var getPath = function(res, type, path, cb){ + if(path){ + if(type == 0) + cb(res + path, type); + else + cb(path, type); + } + }; + + /** + * Panel parser (UILayout) + */ + parser.LayoutAttributes = function(widget, options, resourcePath){ + var w = 0, h = 0; + var adaptScreen = options["adaptScreen"]; + if (adaptScreen){ + var screenSize = cc.director.getWinSize(); + w = screenSize.width; + h = screenSize.height; + }else{ + w = options["width"]; + h = options["height"]; + } + widget.setSize(cc.size(w, h)); + + widget.setClippingEnabled(options["clipAble"]); + + var backGroundScale9Enable = options["backGroundScale9Enable"]; + widget.setBackGroundImageScale9Enabled(backGroundScale9Enable); + var cr = options["bgColorR"]; + var cg = options["bgColorG"]; + var cb = options["bgColorB"]; + + var scr = options["bgStartColorR"]; + var scg = options["bgStartColorG"]; + var scb = options["bgStartColorB"]; + + var ecr = options["bgEndColorR"]; + var ecg = options["bgEndColorG"]; + var ecb = options["bgEndColorB"]; + + var bgcv1 = options["vectorX"]; + var bgcv2 = options["vectorY"]; + widget.setBackGroundColorVector(cc.p(bgcv1, bgcv2)); + + var co = options["bgColorOpacity"]; + + var colorType = options["colorType"]; + widget.setBackGroundColorType(colorType/*ui.LayoutBackGroundColorType(colorType)*/); + widget.setBackGroundColor(cc.color(scr, scg, scb), cc.color(ecr, ecg, ecb)); + widget.setBackGroundColor(cc.color(cr, cg, cb)); + widget.setBackGroundColorOpacity(co); + + + var imageFileNameDic = options["backGroundImageData"]; + if(imageFileNameDic){ + getPath(resourcePath, imageFileNameDic["resourceType"], imageFileNameDic["path"], function(path, type){ + widget.setBackGroundImage(path, type); + }); + } + + if (backGroundScale9Enable){ + var cx = options["capInsetsX"]; + var cy = options["capInsetsY"]; + var cw = options["capInsetsWidth"]; + var ch = options["capInsetsHeight"]; + widget.setBackGroundImageCapInsets(cc.rect(cx, cy, cw, ch)); + } + if (options["layoutType"]) + { + widget.setLayoutType(options["layoutType"]); + } + }; + /** + * Button parser (UIButton) + */ + parser.ButtonAttributes = function(widget, options, resourcePath){ + var button = widget; + var scale9Enable = options["scale9Enable"]; + button.setScale9Enabled(scale9Enable); + + var normalDic = options["normalData"]; + getPath(resourcePath, normalDic["resourceType"], normalDic["path"], function(path, type){ + button.loadTextureNormal(path, type); + }); + var pressedDic = options["pressedData"]; + getPath(resourcePath, pressedDic["resourceType"], pressedDic["path"], function(path, type){ + button.loadTexturePressed(path, type); + }); + var disabledDic = options["disabledData"]; + getPath(resourcePath, disabledDic["resourceType"], disabledDic["path"], function(path, type){ + button.loadTextureDisabled(path, type); + }); + if (scale9Enable) { + var cx = options["capInsetsX"]; + var cy = options["capInsetsY"]; + var cw = options["capInsetsWidth"]; + var ch = options["capInsetsHeight"]; + + button.setCapInsets(cc.rect(cx, cy, cw, ch)); + var sw = options["scale9Width"]; + var sh = options["scale9Height"]; + if (sw != null && sh != null) + button.setSize(cc.size(sw, sh)); + } + var text = options["text"]; + if (text != null) + button.setTitleText(text); + + var cr = options["textColorR"]; + var cg = options["textColorG"]; + var cb = options["textColorB"]; + var cri = cr!==null?options["textColorR"]:255; + var cgi = cg!==null?options["textColorG"]:255; + var cbi = cb!==null?options["textColorB"]:255; + + button.setTitleColor(cc.color(cri,cgi,cbi)); + var fs = options["fontSize"]; + if (fs != null) + button.setTitleFontSize(options["fontSize"]); + var fn = options["fontName"]; + if (fn) + button.setTitleFontName(options["fontName"]); + }; + /** + * CheckBox parser (UICheckBox) + */ + parser.CheckBoxAttributes = function(widget, options, resourcePath){ + //load background image + var backGroundDic = options["backGroundBoxData"]; + getPath(resourcePath, backGroundDic["resourceType"], backGroundDic["path"], function(path, type){ + widget.loadTextureBackGround(path, type); + }); + + //load background selected image + var backGroundSelectedDic = options["backGroundBoxSelectedData"]; + getPath( + resourcePath, + backGroundSelectedDic["resourceType"] || backGroundDic["resourceType"], + backGroundSelectedDic["path"] || backGroundDic["path"], + function(path, type){ + widget.loadTextureBackGroundSelected(path, type); + }); + + //load frontCross image + var frontCrossDic = options["frontCrossData"]; + getPath(resourcePath, frontCrossDic["resourceType"], frontCrossDic["path"], function(path, type){ + widget.loadTextureFrontCross(path, type); + }); + + //load backGroundBoxDisabledData + var backGroundDisabledDic = options["backGroundBoxDisabledData"]; + getPath( + resourcePath, + backGroundDisabledDic["resourceType"] || frontCrossDic["resourceType"], + backGroundDisabledDic["path"] || frontCrossDic["path"], + function(path, type){ + widget.loadTextureBackGroundDisabled(path, type); + }); + + ///load frontCrossDisabledData + var frontCrossDisabledDic = options["frontCrossDisabledData"]; + getPath(resourcePath, frontCrossDisabledDic["resourceType"], frontCrossDisabledDic["path"], function(path, type){ + widget.loadTextureFrontCrossDisabled(path, type); + }); + + if (options["selectedState"]) + widget.setSelected(options["selectedState"]); + }; + /** + * ImageView parser (UIImageView) + */ + parser.ImageViewAttributes = function(widget, options, resourcePath){ + var imageFileNameDic = options["fileNameData"] + getPath(resourcePath, imageFileNameDic["resourceType"], imageFileNameDic["path"], function(path, type){ + widget.loadTexture(path, type); + }); + + var scale9EnableExist = options["scale9Enable"]; + var scale9Enable = false; + if (scale9EnableExist){ + scale9Enable = options["scale9Enable"]; + } + widget.setScale9Enabled(scale9Enable); + + if (scale9Enable){ + var sw = options["scale9Width"]; + var sh = options["scale9Height"]; + if (sw && sh) + { + var swf = options["scale9Width"]; + var shf = options["scale9Height"]; + widget.setSize(cc.size(swf, shf)); + } + + var cx = options["capInsetsX"]; + var cy = options["capInsetsY"]; + var cw = options["capInsetsWidth"]; + var ch = options["capInsetsHeight"]; + + widget.setCapInsets(cc.rect(cx, cy, cw, ch)); + + } + }; + /** + * TextAtlas parser (UITextAtlas) + */ + parser.TextAtlasAttributes = function(widget, options, resourcePath){ + var sv = options["stringValue"]; + var cmf = options["charMapFileData"]; // || options["charMapFile"]; + var iw = options["itemWidth"]; + var ih = options["itemHeight"]; + var scm = options["startCharMap"]; + if (sv != null && cmf && iw != null && ih != null && scm != null){ + var cmftDic = options["charMapFileData"]; + var cmfType = cmftDic["resourceType"]; + switch (cmfType){ + case 0: + var tp_c = resourcePath; + var cmfPath = cmftDic["path"]; + var cmf_tp = tp_c + cmfPath; + widget.setProperty(sv, cmf_tp, iw, ih, scm); + break; + case 1: + cc.log("Wrong res type of LabelAtlas!"); + break; + default: + break; + } + } + }; + /** + * TextBMFont parser (UITextBMFont) + */ + parser.TextBMFontAttributes = function(widget, options, resourcePath){ + var cmftDic = options["fileNameData"]; + var cmfType = cmftDic["resourceType"]; + switch (cmfType) { + case 0: + var tp_c = resourcePath; + var cmfPath = cmftDic["path"]; + var cmf_tp = tp_c + cmfPath; + widget.setFntFile(cmf_tp); + break; + case 1: + cc.log("Wrong res type of LabelAtlas!"); + break; + default: + break; + } + + var text = options["text"]; + widget.setString(text); + }; + /** + * Text parser (UIText) + */ + var regTTF = /\.ttf$/; + parser.TextAttributes = function(widget, options, resourcePath){ + var touchScaleChangeAble = options["touchScaleEnable"]; + widget.setTouchScaleChangeEnabled(touchScaleChangeAble); + var text = options["text"]; + widget.setString(text); + var fs = options["fontSize"]; + if (fs != null){ + widget.setFontSize(options["fontSize"]); + } + var fn = options["fontName"]; + if (fn != null){ + if(cc.sys.isNative){ + if(regTTF.test(fn)){ + widget.setFontName(cc.path.join(cc.loader.resPath, resourcePath, fn)); + }else{ + widget.setFontName(fn); + } + }else{ + widget.setFontName(fn.replace(regTTF, '')); + } + } + var aw = options["areaWidth"]; + var ah = options["areaHeight"]; + if (aw != null && ah != null){ + var size = cc.size(options["areaWidth"], options["areaHeight"]); + widget.setTextAreaSize(size); + } + var ha = options["hAlignment"]; + if (ha != null){ + widget.setTextHorizontalAlignment(options["hAlignment"]); + } + var va = options["vAlignment"]; + if (va != null){ + widget.setTextVerticalAlignment(options["vAlignment"]); + } + }; + /** + * ListView parser (UIListView) + */ + parser.ListViewAttributes = function(widget, options, resoutcePath){ + parser.ScrollViewAttributes(widget, options,resoutcePath); + var direction = options["direction"]; + widget.setDirection(direction); + var gravity = options["gravity"]; + widget.setGravity(gravity); + var itemMargin = options["itemMargin"]; + widget.setItemsMargin(itemMargin); + }; + /** + * LoadingBar parser (UILoadingBar) + */ + parser.LoadingBarAttributes = function(widget, options, resourcePath){ + var imageFileNameDic = options["textureData"]; + getPath(resourcePath, imageFileNameDic["resourceType"], imageFileNameDic["path"], function(path, type){ + widget.loadTexture(path, type); + }); + + var scale9Enable = options["scale9Enable"]; + widget.setScale9Enabled(scale9Enable); + + if (scale9Enable){ + var cx = options["capInsetsX"]; + var cy = options["capInsetsY"]; + var cw = options["capInsetsWidth"]; + var ch = options["capInsetsHeight"]; + + widget.setCapInsets(cc.rect(cx, cy, cw, ch)); + + var width = options["width"]; + var height = options["height"]; + widget.setSize(cc.size(width, height)); + } + + widget.setDirection(options["direction"]); + widget.setPercent(options["percent"]); + }; + /** + * PageView parser (UIPageView) + */ + parser.PageViewAttributes = parser.LayoutAttributes; + /** + * ScrollView parser (UIScrollView) + */ + parser.ScrollViewAttributes = function(widget, options, resoutcePath){ + parser.LayoutAttributes(widget, options,resoutcePath); + var innerWidth = options["innerWidth"]!=null ? options["innerWidth"] : 200; + var innerHeight = options["innerHeight"]!=null ? options["innerHeight"] : 200; + widget.setInnerContainerSize(cc.size(innerWidth, innerHeight)); + + var direction = options["direction"]!=null ? options["direction"] : 1; + widget.setDirection(direction); + widget.setBounceEnabled(options["bounceEnable"]); + }; + /** + * Slider parser (UISlider) + */ + parser.SliderAttributes = function(widget, options, resourcePath){ + + var slider = widget; + + var barTextureScale9Enable = options["scale9Enable"]; + slider.setScale9Enabled(barTextureScale9Enable); + var bt = options["barFileName"]; + var barLength = options["length"]; + + var imageFileNameDic = options["barFileNameData"]; + var imageFileType = imageFileNameDic["resourceType"]; + var imageFileName = imageFileNameDic["path"]; + + if(bt != null){ + if(barTextureScale9Enable){ + getPath(resourcePath, imageFileType, imageFileName, function(path, type){ + slider.loadBarTexture(path, type); + }); + slider.setSize(cc.size(barLength, slider.getContentSize().height)); + } + }else{ + getPath(resourcePath, imageFileType, imageFileName, function(path, type){ + slider.loadBarTexture(path, type); + }); + } + + var normalDic = options["ballNormalData"]; + getPath(resourcePath, normalDic["resourceType"], normalDic["path"], function(path, type){ + slider.loadSlidBallTextureNormal(path, type); + }); + + var pressedDic = options["ballPressedData"]; + getPath( + resourcePath, + pressedDic["resourceType"] || normalDic["resourceType"], + pressedDic["path"] || normalDic["path"], + function(path, type){ + slider.loadSlidBallTexturePressed(path, type); + }); + + var disabledDic = options["ballDisabledData"]; + getPath(resourcePath, disabledDic["resourceType"], disabledDic["path"], function(path, type){ + slider.loadSlidBallTextureDisabled(path, type); + }); + + var progressBarDic = options["progressBarData"]; + getPath(resourcePath, progressBarDic["resourceType"], progressBarDic["path"], function(path, type){ + slider.loadProgressBarTexture(path, type); + }); + }; + /** + * TextField parser (UITextField) + */ + parser.TextFieldAttributes = function(widget, options, resourcePath){ + var ph = options["placeHolder"]; + if(ph) + widget.setPlaceHolder(ph); + widget.setString(options["text"]||""); + var fs = options["fontSize1"]; + if(fs) + widget.setFontSize(fs); + var fn = options["fontName"]; + if (fn != null){ + if(cc.sys.isNative){ + if(regTTF.test(fn)){ + widget.setFontName(cc.path.join(cc.loader.resPath, resourcePath, fn)); + }else{ + widget.setFontName(fn); + } + }else{ + widget.setFontName(fn.replace(regTTF, '')); + } + } + var tsw = options["touchSizeWidth"]; + var tsh = options["touchSizeHeight"]; + if(tsw!=null && tsh!=null) + widget.setTouchSize(tsw, tsh); + + var dw = options["width"]; + var dh = options["height"]; + if(dw > 0 || dh > 0){ + //textField.setSize(cc.size(dw, dh)); + } + var maxLengthEnable = options["maxLengthEnable"]; + widget.setMaxLengthEnabled(maxLengthEnable); + + if(maxLengthEnable){ + var maxLength = options["maxLength"]; + widget.setMaxLength(maxLength); + } + var passwordEnable = options["passwordEnable"]; + widget.setPasswordEnabled(passwordEnable); + if(passwordEnable) + widget.setPasswordStyleText(options["passwordStyleText"]); + + var aw = options["areaWidth"]; + var ah = options["areaHeight"]; + if(aw && ah){ + var size = cc.size(aw, ah); + widget.setTextAreaSize(size); + } + var ha = options["hAlignment"]; + if(ha) + widget.setTextHorizontalAlignment(ha); + var va = options["vAlignment"]; + if(va) + widget.setTextVerticalAlignment(va); + }; + + var register = [ + {name: "Panel", object: ccui.Layout, handle: parser.LayoutAttributes}, + {name: "Button", object: ccui.Button, handle: parser.ButtonAttributes}, + {name: "CheckBox", object: ccui.CheckBox, handle: parser.CheckBoxAttributes}, + {name: "ImageView", object: ccui.ImageView, handle: parser.ImageViewAttributes}, + {name: "LabelAtlas", object: ccui.TextAtlas, handle: parser.TextAtlasAttributes}, + {name: "LabelBMFont", object: ccui.TextBMFont, handle: parser.TextBMFontAttributes}, + {name: "Label", object: ccui.Text, handle: parser.TextAttributes}, + {name: "ListView", object: ccui.ListView, handle: parser.ListViewAttributes}, + {name: "LoadingBar", object: ccui.LoadingBar, handle: parser.LoadingBarAttributes}, + {name: "PageView", object: ccui.PageView, handle: parser.PageViewAttributes}, + {name: "ScrollView", object: ccui.ScrollView, handle: parser.ScrollViewAttributes}, + {name: "Slider", object: ccui.Slider, handle: parser.SliderAttributes}, + {name: "TextField", object: ccui.TextField, handle: parser.TextFieldAttributes} + ]; + + register.forEach(function(item){ + parser.registerParser(item.name, function(options, resourcePath){ + var widget = new item.object; + var uiOptions = options["options"]; + parser.generalAttributes(widget, uiOptions); + item.handle(widget, uiOptions, resourcePath); + parser.colorAttributes(widget, uiOptions); + parser.anchorPointAttributes(widget, uiOptions); + parser.parseChild.call(this, widget, options, resourcePath); + return widget; + }); + }); + + load.registerParser("ccui", "*", parser); + +})(ccs._load, ccs._parser); \ No newline at end of file diff --git a/frameworks/js-bindings/cocos2d-x b/frameworks/js-bindings/cocos2d-x index daa4a85447..b0f97059de 160000 --- a/frameworks/js-bindings/cocos2d-x +++ b/frameworks/js-bindings/cocos2d-x @@ -1 +1 @@ -Subproject commit daa4a85447b286aaed00c8f7cd8fe4cd7409f211 +Subproject commit b0f97059de5ccbb16327b558415c55ed9c33b583 diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js-config.h b/frameworks/js-bindings/external/spidermonkey/include/android/js-config.h index 093a586b00..2cedc513e7 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js-config.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js-config.h @@ -12,6 +12,12 @@ This header file is generated by the SpiderMonkey configure script, and installed along with jsapi.h. */ +/* Define to 1 if SpiderMonkey is in debug mode. */ +/* #undef JS_DEBUG */ + +/* Define to 1 if SpiderMonkey should not use struct types in debug builds. */ +/* #undef JS_NO_JSVAL_JSID_STRUCT_TYPES */ + /* Define to 1 if SpiderMonkey should support multi-threaded clients. */ /* #undef JS_THREADSAFE */ @@ -34,8 +40,14 @@ useable. See jscpucfg.h. */ /* #undef JS_HAVE_SYS_ISA_DEFS_H */ +/* Define to 1 if SpiderMonkey is in NUNBOX32 mode. */ +#define JS_NUNBOX32 1 + +/* Define to 1 if SpiderMonkey is in PUNBOX64 mode. */ +/* #undef JS_PUNBOX64 */ + /* MOZILLA JSAPI version number components */ -#define MOZJS_MAJOR_VERSION 28 -#define MOZJS_MINOR_VERSION 0 +#define MOZJS_MAJOR_VERSION 33 +#define MOZJS_MINOR_VERSION 1 #endif /* js_config_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js.msg b/frameworks/js-bindings/external/spidermonkey/include/android/js.msg index 5a8344163b..d342ad4506 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js.msg +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js.msg @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -105,7 +105,7 @@ MSG_DEF(JSMSG_BAD_DESTRUCT_ASS, 51, 0, JSEXN_REFERENCEERR, "invalid destr MSG_DEF(JSMSG_PAREN_AFTER_LET, 52, 0, JSEXN_SYNTAXERR, "missing ) after let head") MSG_DEF(JSMSG_CURLY_AFTER_LET, 53, 0, JSEXN_SYNTAXERR, "missing } after let block") MSG_DEF(JSMSG_MISSING_PAREN, 54, 0, JSEXN_SYNTAXERR, "unterminated parenthetical") -MSG_DEF(JSMSG_UNTERM_CLASS, 55, 1, JSEXN_SYNTAXERR, "unterminated character class {0}") +MSG_DEF(JSMSG_UNTERM_CLASS, 55, 0, JSEXN_SYNTAXERR, "unterminated character class") MSG_DEF(JSMSG_TRAILING_SLASH, 56, 0, JSEXN_SYNTAXERR, "trailing \\ in regular expression") MSG_DEF(JSMSG_BAD_CLASS_RANGE, 57, 0, JSEXN_SYNTAXERR, "invalid range in character class") MSG_DEF(JSMSG_BAD_REGEXP_FLAG, 58, 1, JSEXN_SYNTAXERR, "invalid regular expression flag {0}") @@ -223,30 +223,30 @@ MSG_DEF(JSMSG_TOO_MANY_CATCH_VARS, 169, 0, JSEXN_SYNTAXERR, "too many catch v MSG_DEF(JSMSG_NEGATIVE_REPETITION_COUNT, 170, 0, JSEXN_RANGEERR, "repeat count must be non-negative") MSG_DEF(JSMSG_INVALID_FOR_OF_INIT, 171, 0, JSEXN_SYNTAXERR, "for-of loop variable declaration may not have an initializer") MSG_DEF(JSMSG_INVALID_MAP_ITERABLE, 172, 0, JSEXN_TYPEERR, "iterable for map should have array-like objects") -MSG_DEF(JSMSG_UNUSED173, 173, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED174, 174, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_NOT_A_CODEPOINT, 173, 1, JSEXN_RANGEERR, "{0} is not a valid code point") +MSG_DEF(JSMSG_BRACKET_AFTER_ARRAY_COMPREHENSION, 174, 0, JSEXN_SYNTAXERR, "missing ] after array comprehension") MSG_DEF(JSMSG_NESTING_GENERATOR, 175, 0, JSEXN_TYPEERR, "already executing generator") -MSG_DEF(JSMSG_UNUSED176, 176, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED177, 177, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED178, 178, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED179, 179, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED180, 180, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED181, 181, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_PAREN_AFTER_FOR_OF_ITERABLE, 176, 0, JSEXN_SYNTAXERR, "missing ) after for-of iterable") +MSG_DEF(JSMSG_INVALID_NORMALIZE_FORM, 177, 0, JSEXN_RANGEERR, "form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD'") +MSG_DEF(JSMSG_NOTHING_TO_REPEAT, 178, 0, JSEXN_SYNTAXERR, "nothing to repeat") +MSG_DEF(JSMSG_INVALID_GROUP, 179, 0, JSEXN_SYNTAXERR, "invalid regexp group") +MSG_DEF(JSMSG_ESCAPE_AT_END_OF_REGEXP, 180, 0, JSEXN_SYNTAXERR, "\\ at end of pattern") +MSG_DEF(JSMSG_NUMBERS_OUT_OF_ORDER, 181, 0, JSEXN_SYNTAXERR, "numbers out of order in {} quantifier.") MSG_DEF(JSMSG_BAD_GENERATOR_SEND, 182, 1, JSEXN_TYPEERR, "attempt to send {0} to newborn generator") MSG_DEF(JSMSG_SC_NOT_TRANSFERABLE, 183, 0, JSEXN_TYPEERR, "invalid transferable array for structured clone") MSG_DEF(JSMSG_SC_DUP_TRANSFERABLE, 184, 0, JSEXN_TYPEERR, "duplicate transferable for structured clone") MSG_DEF(JSMSG_CANT_REPORT_AS_NON_EXTENSIBLE, 185, 0, JSEXN_TYPEERR, "proxy can't report an extensible object as non-extensible") -MSG_DEF(JSMSG_UNUSED186, 186, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_SYMBOL_TO_STRING, 186, 0, JSEXN_TYPEERR, "can't convert symbol to string") MSG_DEF(JSMSG_UNUSED187, 187, 0, JSEXN_NONE, "") MSG_DEF(JSMSG_INCOMPATIBLE_METHOD, 188, 3, JSEXN_TYPEERR, "{0} {1} called on incompatible {2}") -MSG_DEF(JSMSG_UNUSED189, 189, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_SYMBOL_TO_PRIMITIVE, 189, 0, JSEXN_TYPEERR, "can't convert symbol object to primitive") MSG_DEF(JSMSG_UNUSED190, 190, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED191, 191, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED192, 192, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_BAD_INDEX, 191, 0, JSEXN_RANGEERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_SELFHOSTED_TOP_LEVEL_LET,192,0, JSEXN_SYNTAXERR, "self-hosted code cannot contain top-level 'let' declarations") MSG_DEF(JSMSG_BAD_FOR_EACH_LOOP, 193, 0, JSEXN_SYNTAXERR, "invalid for each loop") -MSG_DEF(JSMSG_OBJECT_WATCH_DEPRECATED,194, 0, JSEXN_TYPEERR, "Object.prototype.watch and unwatch are very slow, non-standard, and deprecated; use a getter/setter instead") -MSG_DEF(JSMSG_UNUSED195, 195, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED196, 196, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_OBJECT_WATCH_DEPRECATED,194, 0, JSEXN_NONE, "Object.prototype.watch and unwatch are very slow, non-standard, and deprecated; use a getter/setter instead") +MSG_DEF(JSMSG_TYPE_ERR_BAD_ARGS, 195, 0, JSEXN_TYPEERR, "invalid arguments") +MSG_DEF(JSMSG_REDECLARED_CATCH_IDENTIFIER, 196, 1, JSEXN_TYPEERR, "redeclaration of identifier '{0}' in catch") MSG_DEF(JSMSG_INTERNAL_INTL_ERROR, 197, 0, JSEXN_ERR, "internal error while computing Intl data") MSG_DEF(JSMSG_DEFAULT_LOCALE_ERROR, 198, 0, JSEXN_ERR, "internal error getting the default locale") MSG_DEF(JSMSG_TOO_MANY_LOCALS, 199, 0, JSEXN_SYNTAXERR, "too many local variables") @@ -260,25 +260,25 @@ MSG_DEF(JSMSG_USER_DEFINED_ERROR, 206, 0, JSEXN_ERR, "JS_ReportError was cal MSG_DEF(JSMSG_WRONG_CONSTRUCTOR, 207, 1, JSEXN_TYPEERR, "wrong constructor called for {0}") MSG_DEF(JSMSG_BAD_GENERATOR_RETURN, 208, 1, JSEXN_TYPEERR, "generator function {0} returns a value") MSG_DEF(JSMSG_BAD_ANON_GENERATOR_RETURN, 209, 0, JSEXN_TYPEERR, "anonymous generator function returns a value") -MSG_DEF(JSMSG_UNUSED210, 210, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_PROTO_SETTING_SLOW, 210, 0, JSEXN_NONE, "mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create") MSG_DEF(JSMSG_IN_AFTER_FOR_NAME, 211, 0, JSEXN_SYNTAXERR, "missing 'in' or 'of' after for") MSG_DEF(JSMSG_BAD_TRAP_RETURN_VALUE, 212, 2, JSEXN_TYPEERR,"trap {1} for {0} returned a primitive value") -MSG_DEF(JSMSG_UNUSED213, 213, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_OF_AFTER_FOR_NAME, 213, 0, JSEXN_SYNTAXERR, "missing 'of' after for") MSG_DEF(JSMSG_BAD_GENERATOR_YIELD, 214, 1, JSEXN_TYPEERR, "yield from closing generator {0}") MSG_DEF(JSMSG_BAD_GENERATOR_SYNTAX, 215, 1, JSEXN_SYNTAXERR, "{0} expression must be parenthesized") MSG_DEF(JSMSG_ARRAY_COMP_LEFTSIDE, 216, 0, JSEXN_SYNTAXERR, "invalid array comprehension left-hand side") -MSG_DEF(JSMSG_UNUSED217, 217, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_LET_COMP_BINDING, 217, 0, JSEXN_SYNTAXERR, "'let' is not a valid name for a comprehension variable") MSG_DEF(JSMSG_EMPTY_ARRAY_REDUCE, 218, 0, JSEXN_TYPEERR, "reduce of empty array with no initial value") MSG_DEF(JSMSG_BAD_SYMBOL, 219, 1, JSEXN_TYPEERR, "{0} is not a well-known @@-symbol") MSG_DEF(JSMSG_BAD_DELETE_OPERAND, 220, 0, JSEXN_REFERENCEERR, "invalid delete operand") MSG_DEF(JSMSG_BAD_INCOP_OPERAND, 221, 0, JSEXN_REFERENCEERR, "invalid increment/decrement operand") MSG_DEF(JSMSG_UNEXPECTED_TYPE, 222, 2, JSEXN_TYPEERR, "{0} is {1}") MSG_DEF(JSMSG_LET_DECL_NOT_IN_BLOCK, 223, 0, JSEXN_SYNTAXERR, "let declaration not directly within block") -MSG_DEF(JSMSG_BAD_OBJECT_INIT, 224, 0, JSEXN_SYNTAXERR, "invalid object initializer") +MSG_DEF(JSMSG_UNUSED224, 224, 0, JSEXN_NONE, "") MSG_DEF(JSMSG_CANT_SET_ARRAY_ATTRS, 225, 0, JSEXN_INTERNALERR, "can't set attributes on indexed array properties") MSG_DEF(JSMSG_EVAL_ARITY, 226, 0, JSEXN_TYPEERR, "eval accepts only one parameter") MSG_DEF(JSMSG_MISSING_FUN_ARG, 227, 2, JSEXN_TYPEERR, "missing argument {0} when calling function {1}") -MSG_DEF(JSMSG_JSON_BAD_PARSE, 228, 1, JSEXN_SYNTAXERR, "JSON.parse: {0}") +MSG_DEF(JSMSG_JSON_BAD_PARSE, 228, 3, JSEXN_SYNTAXERR, "JSON.parse: {0} at line {1} column {2} of the JSON data") MSG_DEF(JSMSG_JSON_BAD_STRINGIFY, 229, 0, JSEXN_ERR, "JSON.stringify") MSG_DEF(JSMSG_NOT_CALLABLE_OR_UNDEFINED, 230, 0, JSEXN_TYPEERR, "value is not a function or undefined") MSG_DEF(JSMSG_NOT_NONNULL_OBJECT, 231, 0, JSEXN_TYPEERR, "value is not a non-null object") @@ -353,11 +353,11 @@ MSG_DEF(JSMSG_REST_WITH_DEFAULT, 299, 0, JSEXN_SYNTAXERR, "rest parameter m MSG_DEF(JSMSG_NONDEFAULT_FORMAL_AFTER_DEFAULT, 300, 0, JSEXN_SYNTAXERR, "parameter(s) with default followed by parameter without default") MSG_DEF(JSMSG_YIELD_IN_DEFAULT, 301, 0, JSEXN_SYNTAXERR, "yield in default expression") MSG_DEF(JSMSG_INTRINSIC_NOT_DEFINED, 302, 1, JSEXN_REFERENCEERR, "no intrinsic function {0}") -MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 303, 2, JSEXN_ERR, "{0} is being assigned a {1}, but already has one") -MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 304, 1, JSEXN_RANGEERR, "invalid ParallelArray{0} argument") -MSG_DEF(JSMSG_PAR_ARRAY_BAD_PARTITION, 305, 0, JSEXN_ERR, "argument must be divisible by outermost dimension") -MSG_DEF(JSMSG_PAR_ARRAY_REDUCE_EMPTY, 306, 0, JSEXN_ERR, "cannot reduce ParallelArray object whose outermost dimension is empty") -MSG_DEF(JSMSG_PAR_ARRAY_ALREADY_FLAT, 307, 0, JSEXN_ERR, "cannot flatten 1-dimensional ParallelArray object") +MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 303, 2, JSEXN_NONE, "{0} is being assigned a {1}, but already has one") +MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 304, 0, JSEXN_RANGEERR, "invalid parallel method argument") +MSG_DEF(JSMSG_REGEXP_RUNTIME_ERROR, 305, 0, JSEXN_INTERNALERR, "an error occurred while executing regular expression") +MSG_DEF(JSMSG_DEBUG_OPTIMIZED_OUT, 306, 0, JSEXN_ERR, "variable has been optimized out") +MSG_DEF(JSMSG_NEXT_RETURNED_PRIMITIVE,307, 0, JSEXN_TYPEERR, "iterator.next() returned a non-object value") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_CONFLICT, 308, 0, JSEXN_ERR, "no conflict resolution function provided") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BOUNDS, 309, 0, JSEXN_ERR, "index in scatter vector out of bounds") MSG_DEF(JSMSG_CANT_REPORT_NC_AS_NE, 310, 0, JSEXN_TYPEERR, "proxy can't report a non-configurable own property as non-existent") @@ -391,13 +391,13 @@ MSG_DEF(JSMSG_DATE_NOT_FINITE, 337, 0, JSEXN_RANGEERR, "date value is not MSG_DEF(JSMSG_USE_ASM_DIRECTIVE_FAIL, 338, 0, JSEXN_SYNTAXERR, "\"use asm\" is only meaningful in the Directive Prologue of a function body") MSG_DEF(JSMSG_USE_ASM_TYPE_FAIL, 339, 1, JSEXN_TYPEERR, "asm.js type error: {0}") MSG_DEF(JSMSG_USE_ASM_LINK_FAIL, 340, 1, JSEXN_TYPEERR, "asm.js link error: {0}") -MSG_DEF(JSMSG_USE_ASM_TYPE_OK, 341, 1, JSEXN_ERR, "successfully compiled asm.js code ({0})") +MSG_DEF(JSMSG_USE_ASM_TYPE_OK, 341, 1, JSEXN_NONE, "Successfully compiled asm.js code ({0})") MSG_DEF(JSMSG_BAD_ARROW_ARGS, 342, 0, JSEXN_SYNTAXERR, "invalid arrow-function arguments (parentheses around the arrow-function may help)") MSG_DEF(JSMSG_YIELD_IN_ARROW, 343, 0, JSEXN_SYNTAXERR, "arrow function may not contain yield") MSG_DEF(JSMSG_WRONG_VALUE, 344, 2, JSEXN_ERR, "expected {0} but found {1}") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BAD_TARGET, 345, 1, JSEXN_ERR, "target for index {0} is not an integer") MSG_DEF(JSMSG_SELFHOSTED_UNBOUND_NAME,346, 0, JSEXN_TYPEERR, "self-hosted code may not contain unbound name lookups") -MSG_DEF(JSMSG_DEPRECATED_PRAGMA, 347, 1, JSEXN_SYNTAXERR, "Using //@ to indicate {0} pragmas is deprecated. Use //# instead") +MSG_DEF(JSMSG_DEPRECATED_PRAGMA, 347, 1, JSEXN_NONE, "Using //@ to indicate {0} pragmas is deprecated. Use //# instead") MSG_DEF(JSMSG_BAD_DESTRUCT_ASSIGN, 348, 1, JSEXN_SYNTAXERR, "can't assign to {0} using destructuring assignment") MSG_DEF(JSMSG_TYPEDOBJECT_ARRAYTYPE_BAD_ARGS, 349, 0, JSEXN_ERR, "Invalid arguments") MSG_DEF(JSMSG_TYPEDOBJECT_BINARYARRAY_BAD_INDEX, 350, 0, JSEXN_RANGEERR, "invalid or out-of-range index") @@ -414,7 +414,7 @@ MSG_DEF(JSMSG_TOO_MANY_FUN_SPREADARGS, 360, 0, JSEXN_RANGEERR, "too many functio MSG_DEF(JSMSG_DEBUG_NOT_DEBUGGEE, 361, 2, JSEXN_ERR, "{0} is not a debuggee {1}") MSG_DEF(JSMSG_TYPEDOBJECT_NOT_TYPED_OBJECT, 362, 0, JSEXN_ERR, "Expected a typed object") MSG_DEF(JSMSG_TYPEDOBJECT_NO_SUCH_PROP, 363, 1, JSEXN_TYPEERR, "No such property: {0}") -MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_BAD_ARGS, 364, 2, JSEXN_TYPEERR, "argument {0} invalid: expected {1}") +MSG_DEF(JSMSG_TYPEDOBJECT_BAD_ARGS, 364, 0, JSEXN_TYPEERR, "invalid arguments") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_UNATTACHED, 365, 0, JSEXN_TYPEERR, "handle unattached") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_BAD_TYPE, 366, 0, JSEXN_TYPEERR, "handle moved to destination of incorrect type") @@ -433,3 +433,11 @@ MSG_DEF(JSMSG_NO_EXPORT_NAME, 378, 0, JSEXN_SYNTAXERR, "missing export MSG_DEF(JSMSG_DECLARATION_AFTER_EXPORT, 379, 0, JSEXN_SYNTAXERR, "missing declaration after 'export' keyword") MSG_DEF(JSMSG_INVALID_PROTOTYPE, 380, 0, JSEXN_TYPEERR, "prototype field is not an object") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_TO_UNSIZED, 381, 0, JSEXN_TYPEERR, "cannot create a handle to an unsized type") +MSG_DEF(JSMSG_SETPROTOTYPEOF_FAIL, 382, 1, JSEXN_TYPEERR, "[[SetPrototypeOf]] failed on {0}") +MSG_DEF(JSMSG_INVALID_ARG_TYPE, 383, 3, JSEXN_TYPEERR, "Invalid type: {0} can't be a{1} {2}") +MSG_DEF(JSMSG_TERMINATED, 384, 1, JSEXN_ERR, "Script terminated by timeout at:\n{0}") +MSG_DEF(JSMSG_NO_SUCH_SELF_HOSTED_PROP, 385, 1, JSEXN_ERR, "No such property on self-hosted object: {0}") +MSG_DEF(JSMSG_PROXY_EXTENSIBILITY, 386, 0, JSEXN_TYPEERR, "proxy must report same extensiblitity as target") +MSG_DEF(JSMSG_PROXY_CONSTRUCT_OBJECT, 387, 0, JSEXN_TYPEERR, "proxy [[Construct]] must return an object") +MSG_DEF(JSMSG_PROXY_GETOWN_OBJORUNDEF, 388, 0, JSEXN_TYPEERR, "proxy [[GetOwnProperty]] must return an object or undefined") +MSG_DEF(JSMSG_CANT_REPORT_C_AS_NC, 389, 0, JSEXN_TYPEERR, "proxy can't report existing configurable property as non-configurable") diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/CallArgs.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/CallArgs.h index 5c7a201101..3be3f1575a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/CallArgs.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/CallArgs.h @@ -44,7 +44,7 @@ typedef bool /* Typedef for native functions that may be called in parallel. */ typedef bool -(* JSParallelNative)(js::ForkJoinSlice *slice, unsigned argc, JS::Value *vp); +(* JSParallelNative)(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); /* * Typedef for native functions that may be called either in parallel or @@ -63,7 +63,7 @@ JSNativeThreadSafeWrapper(JSContext *cx, unsigned argc, JS::Value *vp); template inline bool -JSParallelNativeThreadSafeWrapper(js::ForkJoinSlice *slice, unsigned argc, JS::Value *vp); +JSParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); /* * Compute |this| for the |vp| inside a JSNative, either boxing primitives or @@ -118,7 +118,7 @@ extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; namespace detail { -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_PUBLIC_API(void) CheckIsValidConstructible(Value v); #endif @@ -147,7 +147,7 @@ class MOZ_STACK_CLASS UsedRvalBase template class MOZ_STACK_CLASS CallReceiverBase : public UsedRvalBase< -#ifdef DEBUG +#ifdef JS_DEBUG WantUsedRval #else NoUsedRval @@ -197,7 +197,7 @@ class MOZ_STACK_CLASS CallReceiverBase : public UsedRvalBase< } bool isConstructing() const { -#ifdef DEBUG +#ifdef JS_DEBUG if (this->usedRval_) CheckIsValidConstructible(calleev()); #endif @@ -388,11 +388,7 @@ CallArgsFromSp(unsigned argc, Value *sp) * take a const JS::CallArgs&. */ -#define JS_CALLEE(cx,vp) ((vp)[0]) -#define JS_THIS_OBJECT(cx,vp) (JSVAL_TO_OBJECT(JS_THIS(cx,vp))) -#define JS_ARGV(cx,vp) ((vp) + 2) -#define JS_RVAL(cx,vp) (*(vp)) -#define JS_SET_RVAL(cx,vp,v) (*(vp) = (v)) +#define JS_THIS_OBJECT(cx,vp) (JS_THIS(cx,vp).toObjectOrNull()) /* * Note: if this method returns null, an error has occurred and must be @@ -401,7 +397,7 @@ CallArgsFromSp(unsigned argc, Value *sp) MOZ_ALWAYS_INLINE JS::Value JS_THIS(JSContext *cx, JS::Value *vp) { - return JSVAL_IS_PRIMITIVE(vp[1]) ? JS_ComputeThis(cx, vp) : vp[1]; + return vp[1].isPrimitive() ? JS_ComputeThis(cx, vp) : vp[1]; } /* diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/CallNonGenericMethod.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/CallNonGenericMethod.h index 05097f0294..ad9a7f708c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/CallNonGenericMethod.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/CallNonGenericMethod.h @@ -14,7 +14,7 @@ namespace JS { // Returns true if |v| is considered an acceptable this-value. -typedef bool (*IsAcceptableThis)(Handle v); +typedef bool (*IsAcceptableThis)(HandleValue v); // Implements the guts of a method; guaranteed to be provided an acceptable // this-value, as determined by a corresponding IsAcceptableThis method. @@ -92,7 +92,7 @@ CallMethodIfWrapped(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallA // tail position in a JSNative. Do not call it from any other place. // template -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool CallNonGenericMethod(JSContext *cx, CallArgs args) { HandleValue thisv = args.thisv(); @@ -102,7 +102,7 @@ CallNonGenericMethod(JSContext *cx, CallArgs args) return detail::CallMethodIfWrapped(cx, Test, Impl, args); } -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool CallNonGenericMethod(JSContext *cx, IsAcceptableThis Test, NativeImpl Impl, CallArgs args) { HandleValue thisv = args.thisv(); diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/CharacterEncoding.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/CharacterEncoding.h index 7918b83484..45c77761b3 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/CharacterEncoding.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/CharacterEncoding.h @@ -17,6 +17,8 @@ namespace js { struct ThreadSafeContext; } +class JSFlatString; + namespace JS { /* @@ -25,40 +27,45 @@ namespace JS { * byte is treated as a 2-byte character, and there is no way to pass in a * string containing characters beyond U+00FF. */ -class Latin1Chars : public mozilla::Range +class Latin1Chars : public mozilla::Range { - typedef mozilla::Range Base; + typedef mozilla::Range Base; public: Latin1Chars() : Base() {} - Latin1Chars(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) {} + Latin1Chars(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) {} + Latin1Chars(const Latin1Char *aBytes, size_t aLength) + : Base(const_cast(aBytes), aLength) + {} Latin1Chars(const char *aBytes, size_t aLength) - : Base(reinterpret_cast(const_cast(aBytes)), aLength) + : Base(reinterpret_cast(const_cast(aBytes)), aLength) {} }; /* * A Latin1Chars, but with \0 termination for C compatibility. */ -class Latin1CharsZ : public mozilla::RangedPtr +class Latin1CharsZ : public mozilla::RangedPtr { - typedef mozilla::RangedPtr Base; + typedef mozilla::RangedPtr Base; public: Latin1CharsZ() : Base(nullptr, 0) {} Latin1CharsZ(char *aBytes, size_t aLength) - : Base(reinterpret_cast(aBytes), aLength) + : Base(reinterpret_cast(aBytes), aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } - Latin1CharsZ(unsigned char *aBytes, size_t aLength) + Latin1CharsZ(Latin1Char *aBytes, size_t aLength) : Base(aBytes, aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } + using Base::operator=; + char *c_str() { return reinterpret_cast(get()); } }; @@ -89,15 +96,17 @@ class UTF8CharsZ : public mozilla::RangedPtr UTF8CharsZ(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } UTF8CharsZ(unsigned char *aBytes, size_t aLength) : Base(aBytes, aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } + using Base::operator=; + char *c_str() { return reinterpret_cast(get()); } }; @@ -119,21 +128,6 @@ class TwoByteChars : public mozilla::Range TwoByteChars(const jschar *aChars, size_t aLength) : Base(const_cast(aChars), aLength) {} }; -/* - * A non-convertible variant of TwoByteChars that does not refer to characters - * inlined inside a JSShortString or a JSInlineString. StableTwoByteChars are - * thus safe to hold across a GC. - */ -class StableTwoByteChars : public mozilla::Range -{ - typedef mozilla::Range Base; - - public: - StableTwoByteChars() : Base() {} - StableTwoByteChars(jschar *aChars, size_t aLength) : Base(aChars, aLength) {} - StableTwoByteChars(const jschar *aChars, size_t aLength) : Base(const_cast(aChars), aLength) {} -}; - /* * A TwoByteChars, but \0 terminated for compatibility with JSFlatString. */ @@ -147,10 +141,31 @@ class TwoByteCharsZ : public mozilla::RangedPtr TwoByteCharsZ(jschar *chars, size_t length) : Base(chars, length) { - JS_ASSERT(chars[length] == '\0'); + MOZ_ASSERT(chars[length] == '\0'); } + + using Base::operator=; }; +typedef mozilla::RangedPtr ConstCharPtr; + +/* + * Like TwoByteChars, but the chars are const. + */ +class ConstTwoByteChars : public mozilla::RangedPtr +{ + public: + ConstTwoByteChars(const ConstTwoByteChars &s) : ConstCharPtr(s) {} + MOZ_IMPLICIT ConstTwoByteChars(const mozilla::RangedPtr &s) : ConstCharPtr(s) {} + ConstTwoByteChars(const jschar *s, size_t len) : ConstCharPtr(s, len) {} + ConstTwoByteChars(const jschar *pos, const jschar *start, size_t len) + : ConstCharPtr(pos, start, len) + {} + + using ConstCharPtr::operator=; +}; + + /* * Convert a 2-byte character sequence to "ISO-Latin-1". This works by * truncating each 2-byte pair in the sequence to a 1-byte pair. If the source @@ -162,10 +177,12 @@ class TwoByteCharsZ : public mozilla::RangedPtr * This method cannot trigger GC. */ extern Latin1CharsZ -LossyTwoByteCharsToNewLatin1CharsZ(js::ThreadSafeContext *cx, TwoByteChars tbchars); +LossyTwoByteCharsToNewLatin1CharsZ(js::ThreadSafeContext *cx, + const mozilla::Range tbchars); +template extern UTF8CharsZ -TwoByteCharsToNewUTF8CharsZ(js::ThreadSafeContext *cx, TwoByteChars tbchars); +CharsToNewUTF8CharsZ(js::ThreadSafeContext *cx, const mozilla::Range chars); uint32_t Utf8ToOneUcs4Char(const uint8_t *utf8Buffer, int utf8Length); @@ -187,6 +204,20 @@ UTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen) extern TwoByteCharsZ LossyUTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen); +/* + * Returns the length of the char buffer required to encode |s| as UTF8. + * Does not include the null-terminator. + */ +JS_PUBLIC_API(size_t) +GetDeflatedUTF8StringLength(JSFlatString *s); + +/* + * Encode |src| as UTF8. The caller must ensure |dst| has enough space. + * Does not write the null terminator. + */ +JS_PUBLIC_API(void) +DeflateStringToUTF8Buffer(JSFlatString *src, mozilla::RangedPtr dst); + } // namespace JS inline void JS_free(JS::Latin1CharsZ &ptr) { js_free((void*)ptr.get()); } diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/Class.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/Class.h index b908fe1604..559cc65c85 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/Class.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/Class.h @@ -24,126 +24,20 @@ * object behavior and, e.g., allows custom slow layout. */ -class JSFreeOp; +struct JSFreeOp; +struct JSFunctionSpec; namespace js { -class Class; +struct Class; class FreeOp; -class PropertyId; class PropertyName; class Shape; -class SpecialId; // This is equal to JSFunction::class_. Use it in places where you don't want // to #include jsfun.h. extern JS_FRIEND_DATA(const js::Class* const) FunctionClassPtr; -static JS_ALWAYS_INLINE jsid -SPECIALID_TO_JSID(const SpecialId &sid); - -/* - * We partition the ways to refer to a property into three: by an index - * (uint32_t); by a string whose characters do not represent an index - * (PropertyName, see vm/String.h); and by various special values. - * - * Special values are encoded using SpecialId, which is layout-compatible but - * non-interconvertible with jsid. A SpecialId is used for JSID_VOID, which - * does not occur in JS scripts but may be used to indicate the absence of a - * valid identifier. In the future, a SpecialId may also be an object used by - * Harmony-proposed private names. - */ -class SpecialId -{ - uintptr_t bits_; - - /* Needs access to raw bits. */ - friend JS_ALWAYS_INLINE jsid SPECIALID_TO_JSID(const SpecialId &sid); - friend class PropertyId; - - static const uintptr_t TYPE_VOID = JSID_TYPE_VOID; - static const uintptr_t TYPE_OBJECT = JSID_TYPE_OBJECT; - static const uintptr_t TYPE_MASK = JSID_TYPE_MASK; - - SpecialId(uintptr_t bits) : bits_(bits) { } - - public: - SpecialId() : bits_(TYPE_VOID) { } - - /* Object-valued */ - - SpecialId(JSObject &obj) - : bits_(uintptr_t(&obj) | TYPE_OBJECT) - { - JS_ASSERT(&obj != nullptr); - JS_ASSERT((uintptr_t(&obj) & TYPE_MASK) == 0); - } - - bool isObject() const { - return (bits_ & TYPE_MASK) == TYPE_OBJECT && bits_ != TYPE_OBJECT; - } - - JSObject *toObject() const { - JS_ASSERT(isObject()); - return reinterpret_cast(bits_ & ~TYPE_MASK); - } - - /* Empty */ - - static SpecialId empty() { - SpecialId sid(TYPE_OBJECT); - JS_ASSERT(sid.isEmpty()); - return sid; - } - - bool isEmpty() const { - return bits_ == TYPE_OBJECT; - } - - /* Void */ - - static SpecialId voidId() { - SpecialId sid(TYPE_VOID); - JS_ASSERT(sid.isVoid()); - return sid; - } - - bool isVoid() const { - return bits_ == TYPE_VOID; - } -}; - -static JS_ALWAYS_INLINE jsid -SPECIALID_TO_JSID(const SpecialId &sid) -{ - jsid id; - JSID_BITS(id) = sid.bits_; - JS_ASSERT_IF(sid.isObject(), JSID_IS_OBJECT(id) && JSID_TO_OBJECT(id) == sid.toObject()); - JS_ASSERT_IF(sid.isVoid(), JSID_IS_VOID(id)); - JS_ASSERT_IF(sid.isEmpty(), JSID_IS_EMPTY(id)); - return id; -} - -static JS_ALWAYS_INLINE bool -JSID_IS_SPECIAL(jsid id) -{ - return JSID_IS_OBJECT(id) || JSID_IS_EMPTY(id) || JSID_IS_VOID(id); -} - -static JS_ALWAYS_INLINE SpecialId -JSID_TO_SPECIALID(jsid id) -{ - JS_ASSERT(JSID_IS_SPECIAL(id)); - if (JSID_IS_OBJECT(id)) - return SpecialId(*JSID_TO_OBJECT(id)); - if (JSID_IS_EMPTY(id)) - return SpecialId::empty(); - JS_ASSERT(JSID_IS_VOID(id)); - return SpecialId::voidId(); -} - -typedef JS::Handle HandleSpecialId; - } // namespace js // JSClass operation signatures. @@ -152,8 +46,8 @@ typedef JS::Handle HandleSpecialId; // be a string (Unicode property identifier) or an int (element index). The // *vp out parameter, on success, is the new property value after the action. typedef bool -(* JSPropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - JS::MutableHandle vp); +(* JSPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); // Set a property named by id in obj, treating the assignment as strict // mode code if strict is true. Note the jsid id type -- id may be a string @@ -161,8 +55,8 @@ typedef bool // parameter, on success, is the new property value after the // set. typedef bool -(* JSStrictPropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - bool strict, JS::MutableHandle vp); +(* JSStrictPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool strict, JS::MutableHandleValue vp); // Delete a property named by id in obj. // @@ -178,7 +72,7 @@ typedef bool // property, or an inherited property, is allowed -- it's just pointless), // set *succeeded to true and return true. typedef bool -(* JSDeletePropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, +(* JSDeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); // This function type is used for callbacks that enumerate the properties of @@ -212,13 +106,13 @@ typedef bool // The return value is used to indicate success, with a value of false // indicating failure. typedef bool -(* JSNewEnumerateOp)(JSContext *cx, JS::Handle obj, JSIterateOp enum_op, - JS::MutableHandle statep, JS::MutableHandle idp); +(* JSNewEnumerateOp)(JSContext *cx, JS::HandleObject obj, JSIterateOp enum_op, + JS::MutableHandleValue statep, JS::MutableHandleId idp); // The old-style JSClass.enumerate op should define all lazy properties not // yet reflected in obj. typedef bool -(* JSEnumerateOp)(JSContext *cx, JS::Handle obj); +(* JSEnumerateOp)(JSContext *cx, JS::HandleObject obj); // Resolve a lazy property named by id in obj by defining it directly in obj. // Lazy properties are those reflected from some peer native property space @@ -231,27 +125,24 @@ typedef bool // // NB: JSNewResolveOp provides a cheaper way to resolve lazy properties. typedef bool -(* JSResolveOp)(JSContext *cx, JS::Handle obj, JS::Handle id); +(* JSResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); -// Like JSResolveOp, but flags provide contextual information as follows: -// -// JSRESOLVE_ASSIGNING obj[id] is on the left-hand side of an assignment -// -// The *objp out parameter, on success, should be null to indicate that id -// was not resolved; and non-null, referring to obj or one of its prototypes, -// if id was resolved. The hook may assume *objp is null on entry. +// Like JSResolveOp, except the *objp out parameter, on success, should be null +// to indicate that id was not resolved; and non-null, referring to obj or one +// of its prototypes, if id was resolved. The hook may assume *objp is null on +// entry. // // This hook instead of JSResolveOp is called via the JSClass.resolve member // if JSCLASS_NEW_RESOLVE is set in JSClass.flags. typedef bool -(* JSNewResolveOp)(JSContext *cx, JS::Handle obj, JS::Handle id, unsigned flags, - JS::MutableHandle objp); +(* JSNewResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleObject objp); // Convert obj to the given type, returning true with the resulting value in // *vp on success, and returning false on error or exception. typedef bool -(* JSConvertOp)(JSContext *cx, JS::Handle obj, JSType type, - JS::MutableHandle vp); +(* JSConvertOp)(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); // Finalize obj, which the garbage collector has determined to be unreachable // from other live objects or from GC roots. Obviously, finalizers must never @@ -264,25 +155,11 @@ struct JSStringFinalizer { void (*finalize)(const JSStringFinalizer *fin, jschar *chars); }; -// JSClass.checkAccess type: check whether obj[id] may be accessed per mode, -// returning false on error/exception, true on success with obj[id]'s last-got -// value in *vp, and its attributes in *attrsp. As for JSPropertyOp above, id -// is either a string or an int jsval. -typedef bool -(* JSCheckAccessOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - JSAccessMode mode, JS::MutableHandle vp); - -// Return whether the first principal subsumes the second. The exact meaning of -// 'subsumes' is left up to the browser. Subsumption is checked inside the JS -// engine when determining, e.g., which stack frames to display in a backtrace. -typedef bool -(* JSSubsumesOp)(JSPrincipals *first, JSPrincipals *second); - // Check whether v is an instance of obj. Return false on error or exception, // true on success with true in *bp if v is an instance of obj, false in // *bp otherwise. typedef bool -(* JSHasInstanceOp)(JSContext *cx, JS::Handle obj, JS::MutableHandle vp, +(* JSHasInstanceOp)(JSContext *cx, JS::HandleObject obj, JS::MutableHandleValue vp, bool *bp); // Function type for trace operation of the class called to enumerate all @@ -300,11 +177,6 @@ typedef bool typedef void (* JSTraceOp)(JSTracer *trc, JSObject *obj); -// A generic type for functions mapping an object to another object, or null -// if an error or exception was thrown on cx. -typedef JSObject * -(* JSObjectOp)(JSContext *cx, JS::Handle obj); - // Hook that creates an iterator object for a given object. Returns the // iterator object or null if an error or exception was thrown on cx. typedef JSObject * @@ -327,9 +199,6 @@ typedef bool (* LookupElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleObject objp, JS::MutableHandle propp); typedef bool -(* LookupSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::MutableHandleObject objp, JS::MutableHandle propp); -typedef bool (* DefineGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); typedef bool @@ -340,10 +209,6 @@ typedef bool (* DefineElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); typedef bool -(* DefineSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); -typedef bool (* GenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, JS::MutableHandleValue vp); typedef bool @@ -353,12 +218,6 @@ typedef bool (* ElementIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, JS::MutableHandleValue vp); typedef bool -(* ElementIfPresentOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, - uint32_t index, JS::MutableHandleValue vp, bool* present); -typedef bool -(* SpecialIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, - HandleSpecialId sid, JS::MutableHandleValue vp); -typedef bool (* StrictGenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, bool strict); typedef bool @@ -368,20 +227,12 @@ typedef bool (* StrictElementIdOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp, bool strict); typedef bool -(* StrictSpecialIdOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::MutableHandleValue vp, bool strict); -typedef bool (* GenericAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); typedef bool (* PropertyAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, unsigned *attrsp); typedef bool -(* DeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, - bool *succeeded); -typedef bool -(* DeleteElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded); -typedef bool -(* DeleteSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, bool *succeeded); +(* DeleteGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); typedef bool (* WatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); @@ -389,12 +240,23 @@ typedef bool typedef bool (* UnwatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); +typedef bool +(* SliceOp)(JSContext *cx, JS::HandleObject obj, uint32_t begin, uint32_t end, + JS::HandleObject result); // result is actually preallocted. + +// A generic type for functions mapping an object to another object, or null +// if an error or exception was thrown on cx. typedef JSObject * (* ObjectOp)(JSContext *cx, JS::HandleObject obj); + +// Hook to map an object to its inner object. Infallible. +typedef JSObject * +(* InnerObjectOp)(JSObject *obj); + typedef void (* FinalizeOp)(FreeOp *fop, JSObject *obj); -#define JS_CLASS_MEMBERS \ +#define JS_CLASS_MEMBERS(FinalizeOpType) \ const char *name; \ uint32_t flags; \ \ @@ -408,26 +270,34 @@ typedef void JSConvertOp convert; \ \ /* Optional members (may be null). */ \ - FinalizeOp finalize; \ - JSCheckAccessOp checkAccess; \ + FinalizeOpType finalize; \ JSNative call; \ JSHasInstanceOp hasInstance; \ JSNative construct; \ JSTraceOp trace -/* - * The helper struct to measure the size of JS_CLASS_MEMBERS to know how much - * we have to pad js::Class to match the size of JSClass. - */ -struct ClassSizeMeasurement +// Callback for the creation of constructor and prototype objects. +typedef JSObject *(*ClassObjectCreationOp)(JSContext *cx, JSProtoKey key); + +// Callback for custom post-processing after class initialization via ClassSpec. +typedef bool (*FinishClassInitOp)(JSContext *cx, JS::HandleObject ctor, + JS::HandleObject proto); + +struct ClassSpec { - JS_CLASS_MEMBERS; + ClassObjectCreationOp createConstructor; + ClassObjectCreationOp createPrototype; + const JSFunctionSpec *constructorFunctions; + const JSFunctionSpec *prototypeFunctions; + const JSPropertySpec *prototypeProperties; + FinishClassInitOp finishInit; + bool defined() const { return !!createConstructor; } }; struct ClassExtension { - JSObjectOp outerObject; - JSObjectOp innerObject; + ObjectOp outerObject; + InnerObjectOp innerObject; JSIteratorOp iteratorObject; /* @@ -450,6 +320,7 @@ struct ClassExtension JSWeakmapKeyDelegateOp weakmapKeyDelegateOp; }; +#define JS_NULL_CLASS_SPEC {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr} #define JS_NULL_CLASS_EXT {nullptr,nullptr,nullptr,false,nullptr} struct ObjectOps @@ -457,36 +328,29 @@ struct ObjectOps LookupGenericOp lookupGeneric; LookupPropOp lookupProperty; LookupElementOp lookupElement; - LookupSpecialOp lookupSpecial; DefineGenericOp defineGeneric; DefinePropOp defineProperty; DefineElementOp defineElement; - DefineSpecialOp defineSpecial; GenericIdOp getGeneric; PropertyIdOp getProperty; ElementIdOp getElement; - ElementIfPresentOp getElementIfPresent; /* can be null */ - SpecialIdOp getSpecial; StrictGenericIdOp setGeneric; StrictPropertyIdOp setProperty; StrictElementIdOp setElement; - StrictSpecialIdOp setSpecial; GenericAttributesOp getGenericAttributes; GenericAttributesOp setGenericAttributes; - DeletePropertyOp deleteProperty; - DeleteElementOp deleteElement; - DeleteSpecialOp deleteSpecial; + DeleteGenericOp deleteGeneric; WatchOp watch; UnwatchOp unwatch; - + SliceOp slice; // Optimized slice, can be null. JSNewEnumerateOp enumerate; ObjectOp thisObject; }; #define JS_NULL_OBJECT_OPS \ - {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, \ - nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, \ - nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr} + {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr} } // namespace js @@ -495,27 +359,9 @@ struct ObjectOps typedef void (*JSClassInternal)(); struct JSClass { - const char *name; - uint32_t flags; - - // Mandatory function pointer members. - JSPropertyOp addProperty; - JSDeletePropertyOp delProperty; - JSPropertyOp getProperty; - JSStrictPropertyOp setProperty; - JSEnumerateOp enumerate; - JSResolveOp resolve; - JSConvertOp convert; - - // Optional members (may be null). - JSFinalizeOp finalize; - JSCheckAccessOp checkAccess; - JSNative call; - JSHasInstanceOp hasInstance; - JSNative construct; - JSTraceOp trace; - - void *reserved[42]; + JS_CLASS_MEMBERS(JSFinalizeOp); + + void *reserved[31]; }; #define JSCLASS_HAS_PRIVATE (1<<0) // objects have private slot @@ -550,9 +396,9 @@ struct JSClass { #define JSCLASS_INTERNAL_FLAG2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2)) #define JSCLASS_INTERNAL_FLAG3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3)) -// Indicate whether the proto or ctor should be frozen. -#define JSCLASS_FREEZE_PROTO (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4)) -#define JSCLASS_FREEZE_CTOR (1<<(JSCLASS_HIGH_FLAGS_SHIFT+5)) +#define JSCLASS_IS_PROXY (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4)) + +// Bit 22 unused. // Reserved for embeddings. #define JSCLASS_USERBIT2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+6)) @@ -573,7 +419,11 @@ struct JSClass { // with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS was // previously allowed, but is now an ES5 violation and thus unsupported. // -#define JSCLASS_GLOBAL_SLOT_COUNT (3 + JSProto_LIMIT * 3 + 27) +// JSCLASS_GLOBAL_APPLICATION_SLOTS is the number of slots reserved at +// the beginning of every global object's slots for use by the +// application. +#define JSCLASS_GLOBAL_APPLICATION_SLOTS 3 +#define JSCLASS_GLOBAL_SLOT_COUNT (JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 3 + 30) #define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n) \ (JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + (n))) #define JSCLASS_GLOBAL_FLAGS \ @@ -600,11 +450,10 @@ namespace js { struct Class { - JS_CLASS_MEMBERS; + JS_CLASS_MEMBERS(FinalizeOp); + ClassSpec spec; ClassExtension ext; ObjectOps ops; - uint8_t pad[sizeof(JSClass) - sizeof(ClassSizeMeasurement) - - sizeof(ClassExtension) - sizeof(ObjectOps)]; /* Class is not native and its map is not a scope. */ static const uint32_t NON_NATIVE = JSCLASS_INTERNAL_FLAG2; @@ -621,8 +470,20 @@ struct Class return flags & JSCLASS_EMULATES_UNDEFINED; } + bool isJSFunction() const { + return this == js::FunctionClassPtr; + } + bool isCallable() const { - return this == js::FunctionClassPtr || call; + return isJSFunction() || call; + } + + bool isProxy() const { + return flags & JSCLASS_IS_PROXY; + } + + bool isDOMClass() const { + return flags & JSCLASS_IS_DOMJSCLASS; } static size_t offsetOfFlags() { return offsetof(Class, flags); } @@ -638,20 +499,19 @@ JS_STATIC_ASSERT(offsetof(JSClass, enumerate) == offsetof(Class, enumerate)); JS_STATIC_ASSERT(offsetof(JSClass, resolve) == offsetof(Class, resolve)); JS_STATIC_ASSERT(offsetof(JSClass, convert) == offsetof(Class, convert)); JS_STATIC_ASSERT(offsetof(JSClass, finalize) == offsetof(Class, finalize)); -JS_STATIC_ASSERT(offsetof(JSClass, checkAccess) == offsetof(Class, checkAccess)); JS_STATIC_ASSERT(offsetof(JSClass, call) == offsetof(Class, call)); JS_STATIC_ASSERT(offsetof(JSClass, construct) == offsetof(Class, construct)); JS_STATIC_ASSERT(offsetof(JSClass, hasInstance) == offsetof(Class, hasInstance)); JS_STATIC_ASSERT(offsetof(JSClass, trace) == offsetof(Class, trace)); JS_STATIC_ASSERT(sizeof(JSClass) == sizeof(Class)); -static JS_ALWAYS_INLINE const JSClass * +static MOZ_ALWAYS_INLINE const JSClass * Jsvalify(const Class *c) { return (const JSClass *)c; } -static JS_ALWAYS_INLINE const Class * +static MOZ_ALWAYS_INLINE const Class * Valueify(const JSClass *c) { return (const Class *)c; @@ -679,21 +539,6 @@ ObjectClassIs(JSObject &obj, ESClassValue classValue, JSContext *cx); inline bool IsObjectWithClass(const JS::Value &v, ESClassValue classValue, JSContext *cx); -inline bool -IsPoisonedSpecialId(js::SpecialId iden) -{ - if (iden.isObject()) - return JS::IsPoisonedPtr(iden.toObject()); - return false; -} - -template <> struct GCMethods -{ - static SpecialId initial() { return SpecialId(); } - static ThingRootKind kind() { return THING_ROOT_ID; } - static bool poisoned(SpecialId id) { return IsPoisonedSpecialId(id); } -}; - } /* namespace js */ #endif /* js_Class_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/GCAPI.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/GCAPI.h index 190b781060..c58d62d029 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/GCAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/GCAPI.h @@ -10,8 +10,26 @@ #include "mozilla/NullPtr.h" #include "js/HeapAPI.h" -#include "js/RootingAPI.h" -#include "js/Value.h" + +namespace js { +namespace gc { +class GCRuntime; +} +} + +typedef enum JSGCMode { + /* Perform only global GCs. */ + JSGC_MODE_GLOBAL = 0, + + /* Perform per-compartment GCs until too much garbage has accumulated. */ + JSGC_MODE_COMPARTMENT = 1, + + /* + * Collect in short time slices rather than all at once. Implies + * JSGC_MODE_COMPARTMENT. + */ + JSGC_MODE_INCREMENTAL = 2 +} JSGCMode; namespace JS { @@ -95,40 +113,117 @@ enum Reason { } /* namespace gcreason */ +/* + * Zone GC: + * + * SpiderMonkey's GC is capable of performing a collection on an arbitrary + * subset of the zones in the system. This allows an embedding to minimize + * collection time by only collecting zones that have run code recently, + * ignoring the parts of the heap that are unlikely to have changed. + * + * When triggering a GC using one of the functions below, it is first necessary + * to select the zones to be collected. To do this, you can call + * PrepareZoneForGC on each zone, or you can call PrepareForFullGC to select + * all zones. Failing to select any zone is an error. + */ + +/* + * Schedule the given zone to be collected as part of the next GC. + */ extern JS_FRIEND_API(void) PrepareZoneForGC(Zone *zone); +/* + * Schedule all zones to be collected in the next GC. + */ extern JS_FRIEND_API(void) PrepareForFullGC(JSRuntime *rt); +/* + * When performing an incremental GC, the zones that were selected for the + * previous incremental slice must be selected in subsequent slices as well. + * This function selects those slices automatically. + */ extern JS_FRIEND_API(void) PrepareForIncrementalGC(JSRuntime *rt); +/* + * Returns true if any zone in the system has been scheduled for GC with one of + * the functions above or by the JS engine. + */ extern JS_FRIEND_API(bool) IsGCScheduled(JSRuntime *rt); +/* + * Undoes the effect of the Prepare methods above. The given zone will not be + * collected in the next GC. + */ extern JS_FRIEND_API(void) SkipZoneForGC(Zone *zone); /* - * When triggering a GC using one of the functions below, it is first necessary - * to select the compartments to be collected. To do this, you can call - * PrepareZoneForGC on each compartment, or you can call PrepareForFullGC - * to select all compartments. Failing to select any compartment is an error. + * Non-Incremental GC: + * + * The following functions perform a non-incremental GC. */ +/* + * Performs a non-incremental collection of all selected zones. Some objects + * that are unreachable from the program may still be alive afterwards because + * of internal references. + */ extern JS_FRIEND_API(void) GCForReason(JSRuntime *rt, gcreason::Reason reason); +/* + * Perform a non-incremental collection after clearing caches and other + * temporary references to objects. This will remove all unreferenced objects + * in the system. + */ extern JS_FRIEND_API(void) ShrinkingGC(JSRuntime *rt, gcreason::Reason reason); -extern JS_FRIEND_API(void) -ShrinkGCBuffers(JSRuntime *rt); +/* + * Incremental GC: + * + * Incremental GC divides the full mark-and-sweep collection into multiple + * slices, allowing client JavaScript code to run between each slice. This + * allows interactive apps to avoid long collection pauses. Incremental GC does + * not make collection take less time, it merely spreads that time out so that + * the pauses are less noticable. + * + * For a collection to be carried out incrementally the following conditions + * must be met: + * - The collection must be run by calling JS::IncrementalGC() rather than + * JS_GC(). + * - The GC mode must have been set to JSGC_MODE_INCREMENTAL with + * JS_SetGCParameter(). + * - All native objects that have their own trace hook must indicate that they + * implement read and write barriers with the JSCLASS_IMPLEMENTS_BARRIERS + * flag. + * + * Note: Even if incremental GC is enabled and working correctly, + * non-incremental collections can still happen when low on memory. + */ +/* + * Begin an incremental collection and perform one slice worth of work or + * perform a slice of an ongoing incremental collection. When this function + * returns, the collection is not complete. This function must be called + * repeatedly until !IsIncrementalGCInProgress(rt). + * + * Note: SpiderMonkey's GC is not realtime. Slices in practice may be longer or + * shorter than the requested interval. + */ extern JS_FRIEND_API(void) IncrementalGC(JSRuntime *rt, gcreason::Reason reason, int64_t millis = 0); +/* + * If IsIncrementalGCInProgress(rt), this call finishes the ongoing collection + * by performing an arbitrarily long slice. If !IsIncrementalGCInProgress(rt), + * this is equivalent to GCForReason. When this function returns, + * IsIncrementalGCInProgress(rt) will always be false. + */ extern JS_FRIEND_API(void) FinishIncrementalGC(JSRuntime *rt, gcreason::Reason reason); @@ -152,7 +247,7 @@ enum GCProgress { struct JS_FRIEND_API(GCDescription) { bool isCompartment_; - GCDescription(bool isCompartment) + explicit GCDescription(bool isCompartment) : isCompartment_(isCompartment) {} jschar *formatMessage(JSRuntime *rt) const; @@ -162,37 +257,56 @@ struct JS_FRIEND_API(GCDescription) { typedef void (* GCSliceCallback)(JSRuntime *rt, GCProgress progress, const GCDescription &desc); +/* + * The GC slice callback is called at the beginning and end of each slice. This + * callback may be used for GC notifications as well as to perform additional + * marking. + */ extern JS_FRIEND_API(GCSliceCallback) SetGCSliceCallback(JSRuntime *rt, GCSliceCallback callback); /* - * Signals a good place to do an incremental slice, because the browser is - * drawing a frame. + * Incremental GC defaults to enabled, but may be disabled for testing or in + * embeddings that have not yet implemented barriers on their native classes. + * There is not currently a way to re-enable incremental GC once it has been + * disabled on the runtime. */ extern JS_FRIEND_API(void) -NotifyDidPaint(JSRuntime *rt); +DisableIncrementalGC(JSRuntime *rt); +/* + * Returns true if incremental GC is enabled. Simply having incremental GC + * enabled is not sufficient to ensure incremental collections are happening. + * See the comment "Incremental GC" above for reasons why incremental GC may be + * suppressed. Inspection of the "nonincremental reason" field of the + * GCDescription returned by GCSliceCallback may help narrow down the cause if + * collections are not happening incrementally when expected. + */ extern JS_FRIEND_API(bool) IsIncrementalGCEnabled(JSRuntime *rt); +/* + * Returns true while an incremental GC is ongoing, both when actively + * collecting and between slices. + */ JS_FRIEND_API(bool) IsIncrementalGCInProgress(JSRuntime *rt); -extern JS_FRIEND_API(void) -DisableIncrementalGC(JSRuntime *rt); - -extern JS_FRIEND_API(void) -DisableGenerationalGC(JSRuntime *rt); - -extern JS_FRIEND_API(void) -EnableGenerationalGC(JSRuntime *rt); - +/* + * Returns true when writes to GC things must call an incremental (pre) barrier. + * This is generally only true when running mutator code in-between GC slices. + * At other times, the barrier may be elided for performance. + */ extern JS_FRIEND_API(bool) IsIncrementalBarrierNeeded(JSRuntime *rt); extern JS_FRIEND_API(bool) IsIncrementalBarrierNeeded(JSContext *cx); +/* + * Notify the GC that a reference to a GC thing is about to be overwritten. + * These methods must be called if IsIncrementalBarrierNeeded. + */ extern JS_FRIEND_API(void) IncrementalReferenceBarrier(void *ptr, JSGCTraceKind kind); @@ -202,73 +316,118 @@ IncrementalValueBarrier(const Value &v); extern JS_FRIEND_API(void) IncrementalObjectBarrier(JSObject *obj); -extern JS_FRIEND_API(void) -PokeGC(JSRuntime *rt); - -/* Was the most recent GC run incrementally? */ +/* + * Returns true if the most recent GC ran incrementally. + */ extern JS_FRIEND_API(bool) WasIncrementalGC(JSRuntime *rt); +/* + * Generational GC: + * + * Note: Generational GC is not yet enabled by default. The following class + * is non-functional unless SpiderMonkey was configured with + * --enable-gcgenerational. + */ + +/* Ensure that generational GC is disabled within some scope. */ +class JS_FRIEND_API(AutoDisableGenerationalGC) +{ + js::gc::GCRuntime *gc; +#if defined(JSGC_GENERATIONAL) && defined(JS_GC_ZEAL) + bool restartVerifier; +#endif + + public: + explicit AutoDisableGenerationalGC(JSRuntime *rt); + ~AutoDisableGenerationalGC(); +}; + +/* + * Returns true if generational allocation and collection is currently enabled + * on the given runtime. + */ +extern JS_FRIEND_API(bool) +IsGenerationalGCEnabled(JSRuntime *rt); + +/* + * Returns the GC's "number". This does not correspond directly to the number + * of GCs that have been run, but is guaranteed to be monotonically increasing + * with GC activity. + */ extern JS_FRIEND_API(size_t) GetGCNumber(); -class JS_PUBLIC_API(AutoAssertNoGC) +/* + * The GC does not immediately return the unused memory freed by a collection + * back to the system incase it is needed soon afterwards. This call forces the + * GC to return this memory immediately. + */ +extern JS_FRIEND_API(void) +ShrinkGCBuffers(JSRuntime *rt); + +/* + * Assert if a GC occurs while this class is live. This class does not disable + * the static rooting hazard analysis. + */ +class JS_PUBLIC_API(AutoAssertOnGC) { #ifdef DEBUG - JSRuntime *runtime; + js::gc::GCRuntime *gc; size_t gcNumber; public: - AutoAssertNoGC(); - AutoAssertNoGC(JSRuntime *rt); - ~AutoAssertNoGC(); + AutoAssertOnGC(); + explicit AutoAssertOnGC(JSRuntime *rt); + ~AutoAssertOnGC(); + + static void VerifyIsSafeToGC(JSRuntime *rt); #else public: - /* Prevent unreferenced local warnings in opt builds. */ - AutoAssertNoGC() {} - AutoAssertNoGC(JSRuntime *) {} + AutoAssertOnGC() {} + explicit AutoAssertOnGC(JSRuntime *rt) {} + ~AutoAssertOnGC() {} + + static void VerifyIsSafeToGC(JSRuntime *rt) {} #endif }; -class JS_PUBLIC_API(ObjectPtr) +/* + * Disable the static rooting hazard analysis in the live region, but assert if + * any GC occurs while this guard object is live. This is most useful to help + * the exact rooting hazard analysis in complex regions, since it cannot + * understand dataflow. + * + * Note: GC behavior is unpredictable even when deterministice and is generally + * non-deterministic in practice. The fact that this guard has not + * asserted is not a guarantee that a GC cannot happen in the guarded + * region. As a rule, anyone performing a GC unsafe action should + * understand the GC properties of all code in that region and ensure + * that the hazard analysis is correct for that code, rather than relying + * on this class. + */ +class JS_PUBLIC_API(AutoSuppressGCAnalysis) : public AutoAssertOnGC { - Heap value; - public: - ObjectPtr() : value(nullptr) {} - - ObjectPtr(JSObject *obj) : value(obj) {} - - /* Always call finalize before the destructor. */ - ~ObjectPtr() { JS_ASSERT(!value); } - - void finalize(JSRuntime *rt) { - if (IsIncrementalBarrierNeeded(rt)) - IncrementalObjectBarrier(value); - value = nullptr; - } - - void init(JSObject *obj) { value = obj; } - - JSObject *get() const { return value; } - - void writeBarrierPre(JSRuntime *rt) { - IncrementalObjectBarrier(value); - } - - bool isAboutToBeFinalized(); - - ObjectPtr &operator=(JSObject *obj) { - IncrementalObjectBarrier(value); - value = obj; - return *this; - } - - void trace(JSTracer *trc, const char *name); + AutoSuppressGCAnalysis() : AutoAssertOnGC() {} + explicit AutoSuppressGCAnalysis(JSRuntime *rt) : AutoAssertOnGC(rt) {} +}; - JSObject &operator*() const { return *value; } - JSObject *operator->() const { return value; } - operator JSObject *() const { return value; } +/* + * Place AutoCheckCannotGC in scopes that you believe can never GC. These + * annotations will be verified both dynamically via AutoAssertOnGC, and + * statically with the rooting hazard analysis (implemented by making the + * analysis consider AutoCheckCannotGC to be a GC pointer, and therefore + * complain if it is live across a GC call.) It is useful when dealing with + * internal pointers to GC things where the GC thing itself may not be present + * for the static analysis: e.g. acquiring inline chars from a JSString* on the + * heap. + */ +class JS_PUBLIC_API(AutoCheckCannotGC) : public AutoAssertOnGC +{ + public: + AutoCheckCannotGC() : AutoAssertOnGC() {} + explicit AutoCheckCannotGC(JSRuntime *rt) : AutoAssertOnGC(rt) {} }; /* @@ -284,10 +443,10 @@ UnmarkGrayGCThingRecursively(void *thing, JSGCTraceKind kind); * data). During incremental GC, since the gray bits haven't been computed yet, * we conservatively mark the object black. */ -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) { - JS_ASSERT(kind != JSTRACE_SHAPE); + MOZ_ASSERT(kind != JSTRACE_SHAPE); shadow::Runtime *rt = js::gc::GetGCThingRuntime(thing); #ifdef JSGC_GENERATIONAL @@ -296,7 +455,7 @@ ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) * All live objects in the nursery are moved to tenured at the beginning of * each GC slice, so the gray marker never sees nursery things. */ - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return; #endif if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) @@ -305,14 +464,7 @@ ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) UnmarkGrayGCThingRecursively(thing, kind); } -static JS_ALWAYS_INLINE void -ExposeValueToActiveJS(const Value &v) -{ - if (v.isMarkable()) - ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); -} - -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void ExposeObjectToActiveJS(JSObject *obj) { ExposeGCThingToActiveJS(obj, JSTRACE_OBJECT); @@ -321,7 +473,7 @@ ExposeObjectToActiveJS(JSObject *obj) /* * If a GC is currently marking, mark the object black. */ -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void MarkGCThingAsLive(JSRuntime *rt_, void *thing, JSGCTraceKind kind) { shadow::Runtime *rt = shadow::Runtime::asShadowRuntime(rt_); @@ -329,20 +481,34 @@ MarkGCThingAsLive(JSRuntime *rt_, void *thing, JSGCTraceKind kind) /* * Any object in the nursery will not be freed during any GC running at that time. */ - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return; #endif if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) IncrementalReferenceBarrier(thing, kind); } -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void MarkStringAsLive(Zone *zone, JSString *string) { JSRuntime *rt = JS::shadow::Zone::asShadowZone(zone)->runtimeFromMainThread(); MarkGCThingAsLive(rt, string, JSTRACE_STRING); } +/* + * Internal to Firefox. + * + * Note: this is not related to the PokeGC in nsJSEnvironment. + */ +extern JS_FRIEND_API(void) +PokeGC(JSRuntime *rt); + +/* + * Internal to Firefox. + */ +extern JS_FRIEND_API(void) +NotifyDidPaint(JSRuntime *rt); + } /* namespace JS */ #endif /* js_GCAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/HashTable.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/HashTable.h index eb98804c8e..4c27308b5e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/HashTable.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/HashTable.h @@ -73,7 +73,7 @@ class HashMap // HashMap construction is fallible (due to OOM); thus the user must call // init after constructing a HashMap and check the return value. - HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} + explicit HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} bool init(uint32_t len = 16) { return impl.init(len); } bool initialized() const { return impl.initialized(); } @@ -159,7 +159,7 @@ class HashMap // typedef HashMap HM; // HM h; // for (HM::Range r = h.all(); !r.empty(); r.popFront()) - // char c = r.front().value; + // char c = r.front().value(); // // Also see the definition of Range in HashTable above (with T = Entry). typedef typename Impl::Range Range; @@ -171,7 +171,7 @@ class HashMap // typedef HashMap HM; // HM s; // for (HM::Enum e(s); !e.empty(); e.popFront()) - // if (e.front().value == 'l') + // if (e.front().value() == 'l') // e.removeFront(); // // Table resize may occur in Enum's destructor. Also see the definition of @@ -182,9 +182,6 @@ class HashMap // using the finish() method. void clear() { impl.clear(); } - // Remove all entries without triggering destructors. This method is unsafe. - void clearWithoutCallingDestructors() { impl.clearWithoutCallingDestructors(); } - // Remove all the entries and release all internal buffers. The map must // be initialized again before any use. void finish() { impl.finish(); } @@ -210,7 +207,7 @@ class HashMap // If |generation()| is the same before and after a HashMap operation, // pointers into the table remain valid. - unsigned generation() const { return impl.generation(); } + uint32_t generation() const { return impl.generation(); } /************************************************** Shorthand operations */ @@ -317,7 +314,7 @@ class HashSet // HashSet construction is fallible (due to OOM); thus the user must call // init after constructing a HashSet and check the return value. - HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} + explicit HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} bool init(uint32_t len = 16) { return impl.init(len); } bool initialized() const { return impl.initialized(); } @@ -438,7 +435,7 @@ class HashSet // If |generation()| is the same before and after a HashSet operation, // pointers into the table remain valid. - unsigned generation() const { return impl.generation(); } + uint32_t generation() const { return impl.generation(); } /************************************************** Shorthand operations */ @@ -482,6 +479,13 @@ class HashSet impl.rekeyAndMaybeRehash(p, new_lookup, new_value); } + // Infallibly rekey one entry with a new key that is equivalent. + void rekeyInPlace(Ptr p, const T &new_value) + { + MOZ_ASSERT(HashPolicy::match(*p, new_value)); + impl.rekeyInPlace(p, new_value); + } + // HashSet is movable HashSet(HashSet &&rhs) : impl(mozilla::Move(rhs.impl)) {} void operator=(HashSet &&rhs) { @@ -531,7 +535,7 @@ struct PointerHasher { typedef Key Lookup; static HashNumber hash(const Lookup &l) { - JS_ASSERT(!JS::IsPoisonedPtr(l)); + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); size_t word = reinterpret_cast(l) >> zeroBits; JS_STATIC_ASSERT(sizeof(HashNumber) == 4); #if JS_BITS_PER_WORD == 32 @@ -542,8 +546,8 @@ struct PointerHasher #endif } static bool match(const Key &k, const Lookup &l) { - JS_ASSERT(!JS::IsPoisonedPtr(k)); - JS_ASSERT(!JS::IsPoisonedPtr(l)); + MOZ_ASSERT(!JS::IsPoisonedPtr(k)); + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); return k == l; } static void rekey(Key &k, const Key& newKey) { @@ -701,7 +705,7 @@ class HashTableEntry } void destroy() { - JS_ASSERT(isLive()); + MOZ_ASSERT(isLive()); mem.addr()->~T(); } @@ -710,16 +714,16 @@ class HashTableEntry mozilla::Swap(mem, other->mem); } - T &get() { JS_ASSERT(isLive()); return *mem.addr(); } + T &get() { MOZ_ASSERT(isLive()); return *mem.addr(); } bool isFree() const { return keyHash == sFreeKey; } - void clearLive() { JS_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); } + void clearLive() { MOZ_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); } void clear() { if (isLive()) mem.addr()->~T(); keyHash = sFreeKey; } bool isRemoved() const { return keyHash == sRemovedKey; } - void removeLive() { JS_ASSERT(isLive()); keyHash = sRemovedKey; mem.addr()->~T(); } + void removeLive() { MOZ_ASSERT(isLive()); keyHash = sRemovedKey; mem.addr()->~T(); } bool isLive() const { return isLiveHash(keyHash); } - void setCollision() { JS_ASSERT(isLive()); keyHash |= sCollisionBit; } - void setCollision(HashNumber bit) { JS_ASSERT(isLive()); keyHash |= bit; } + void setCollision() { MOZ_ASSERT(isLive()); keyHash |= sCollisionBit; } + void setCollision(HashNumber bit) { MOZ_ASSERT(isLive()); keyHash |= bit; } void unsetCollision() { keyHash &= ~sCollisionBit; } bool hasCollision() const { return keyHash & sCollisionBit; } bool matchHash(HashNumber hn) { return (keyHash & ~sCollisionBit) == hn; } @@ -728,16 +732,18 @@ class HashTableEntry template void setLive(HashNumber hn, U &&u) { - JS_ASSERT(!isLive()); + MOZ_ASSERT(!isLive()); keyHash = hn; new(mem.addr()) T(mozilla::Forward(u)); - JS_ASSERT(isLive()); + MOZ_ASSERT(isLive()); } }; template class HashTable : private AllocPolicy { + friend class mozilla::ReentrancyGuard; + typedef typename mozilla::RemoveConst::Type NonConstT; typedef typename HashPolicy::KeyType Key; typedef typename HashPolicy::Lookup Lookup; @@ -756,25 +762,56 @@ class HashTable : private AllocPolicy void nonNull() {} Entry *entry_; +#ifdef DEBUG + const HashTable *table_; + uint32_t generation; +#endif protected: - Ptr(Entry &entry) : entry_(&entry) {} + Ptr(Entry &entry, const HashTable &tableArg) + : entry_(&entry) +#ifdef DEBUG + , table_(&tableArg) + , generation(tableArg.generation()) +#endif + {} public: // Leaves Ptr uninitialized. Ptr() { -#ifdef DEBUG +#ifdef JS_DEBUG entry_ = (Entry *)0xbad; #endif } - bool found() const { return entry_->isLive(); } - operator ConvertibleToBool() const { return found() ? &Ptr::nonNull : 0; } - bool operator==(const Ptr &rhs) const { JS_ASSERT(found() && rhs.found()); return entry_ == rhs.entry_; } - bool operator!=(const Ptr &rhs) const { return !(*this == rhs); } + bool found() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->isLive(); + } - T &operator*() const { return entry_->get(); } - T *operator->() const { return &entry_->get(); } + operator ConvertibleToBool() const { + return found() ? &Ptr::nonNull : 0; + } + + bool operator==(const Ptr &rhs) const { + MOZ_ASSERT(found() && rhs.found()); + return entry_ == rhs.entry_; + } + + bool operator!=(const Ptr &rhs) const { + MOZ_ASSERT(generation == table_->generation()); + return !(*this == rhs); + } + + T &operator*() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->get(); + } + + T *operator->() const { + MOZ_ASSERT(generation == table_->generation()); + return &entry_->get(); + } }; // A Ptr that can be used to add a key after a failed lookup. @@ -782,9 +819,18 @@ class HashTable : private AllocPolicy { friend class HashTable; HashNumber keyHash; - mozilla::DebugOnly mutationCount; +#ifdef DEBUG + uint64_t mutationCount; +#endif + + AddPtr(Entry &entry, const HashTable &tableArg, HashNumber hn) + : Ptr(entry, tableArg) + , keyHash(hn) +#ifdef DEBUG + , mutationCount(tableArg.mutationCount) +#endif + {} - AddPtr(Entry &entry, HashNumber hn) : Ptr(entry), keyHash(hn) {} public: // Leaves AddPtr uninitialized. AddPtr() {} @@ -799,32 +845,63 @@ class HashTable : private AllocPolicy protected: friend class HashTable; - Range(Entry *c, Entry *e) : cur(c), end(e), validEntry(true) { + Range(const HashTable &tableArg, Entry *c, Entry *e) + : cur(c) + , end(e) +#ifdef DEBUG + , table_(&tableArg) + , mutationCount(tableArg.mutationCount) + , generation(tableArg.generation()) + , validEntry(true) +#endif + { while (cur < end && !cur->isLive()) ++cur; } Entry *cur, *end; - mozilla::DebugOnly validEntry; +#ifdef DEBUG + const HashTable *table_; + uint64_t mutationCount; + uint32_t generation; + bool validEntry; +#endif public: - Range() : cur(nullptr), end(nullptr), validEntry(false) {} + Range() + : cur(nullptr) + , end(nullptr) +#ifdef DEBUG + , table_(nullptr) + , mutationCount(0) + , generation(0) + , validEntry(false) +#endif + {} bool empty() const { + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); return cur == end; } T &front() const { - JS_ASSERT(validEntry); - JS_ASSERT(!empty()); + MOZ_ASSERT(validEntry); + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); return cur->get(); } void popFront() { - JS_ASSERT(!empty()); + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); while (++cur < end && !cur->isLive()) continue; +#ifdef DEBUG validEntry = true; +#endif } }; @@ -837,17 +914,17 @@ class HashTable : private AllocPolicy { friend class HashTable; - HashTable &table; + HashTable &table_; bool rekeyed; bool removed; /* Not copyable. */ - Enum(const Enum &); - void operator=(const Enum &); + Enum(const Enum &) MOZ_DELETE; + void operator=(const Enum &) MOZ_DELETE; public: template explicit - Enum(Map &map) : Range(map.all()), table(map.impl), rekeyed(false), removed(false) {} + Enum(Map &map) : Range(map.all()), table_(map.impl), rekeyed(false), removed(false) {} // Removes the |front()| element from the table, leaving |front()| // invalid until the next call to |popFront()|. For example: @@ -857,18 +934,25 @@ class HashTable : private AllocPolicy // if (e.front() == 42) // e.removeFront(); void removeFront() { - table.remove(*this->cur); + table_.remove(*this->cur); removed = true; +#ifdef DEBUG this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif } // Removes the |front()| element and re-inserts it into the table with // a new key at the new Lookup position. |front()| is invalid after // this operation until the next call to |popFront()|. void rekeyFront(const Lookup &l, const Key &k) { - table.rekeyWithoutRehash(*this->cur, l, k); + Ptr p(*this->cur, table_); + table_.rekeyWithoutRehash(p, l, k); rekeyed = true; +#ifdef DEBUG this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif } void rekeyFront(const Key &k) { @@ -878,12 +962,12 @@ class HashTable : private AllocPolicy // Potentially rehashes the table. ~Enum() { if (rekeyed) { - table.gen++; - table.checkOverRemoved(); + table_.gen++; + table_.checkOverRemoved(); } if (removed) - table.compactIfUnderloaded(); + table_.compactIfUnderloaded(); } }; @@ -908,18 +992,18 @@ class HashTable : private AllocPolicy void operator=(const HashTable &) MOZ_DELETE; private: - uint32_t hashShift; // multiplicative hash shift - uint32_t entryCount; // number of entries in table - uint32_t gen; // entry storage generation number - uint32_t removedCount; // removed entry sentinels in table - Entry *table; // entry storage + static const size_t CAP_BITS = 24; - void setTableSizeLog2(unsigned sizeLog2) - { - hashShift = sHashBits - sizeLog2; - } + public: + Entry *table; // entry storage + uint32_t gen; // entry storage generation number + uint32_t entryCount; // number of entries in table + uint32_t removedCount:CAP_BITS; // removed entry sentinels in table + uint32_t hashShift:8; // multiplicative hash shift -#ifdef DEBUG +#ifdef JS_DEBUG + mozilla::DebugOnly mutationCount; + mutable mozilla::DebugOnly mEntered; mutable struct Stats { uint32_t searches; // total number of table searches @@ -939,16 +1023,12 @@ class HashTable : private AllocPolicy # define METER(x) #endif - friend class mozilla::ReentrancyGuard; - mutable mozilla::DebugOnly entered; - mozilla::DebugOnly mutationCount; - // The default initial capacity is 32 (enough to hold 16 elements), but it // can be as low as 4. static const unsigned sMinCapacityLog2 = 2; static const unsigned sMinCapacity = 1 << sMinCapacityLog2; - static const unsigned sMaxInit = JS_BIT(23); - static const unsigned sMaxCapacity = JS_BIT(24); + static const unsigned sMaxInit = JS_BIT(CAP_BITS - 1); + static const unsigned sMaxCapacity = JS_BIT(CAP_BITS); static const unsigned sHashBits = mozilla::tl::BitSize::value; // Hash-table alpha is conceptually a fraction, but to avoid floating-point @@ -961,6 +1041,11 @@ class HashTable : private AllocPolicy static const HashNumber sRemovedKey = Entry::sRemovedKey; static const HashNumber sCollisionBit = Entry::sCollisionBit; + void setTableSizeLog2(unsigned sizeLog2) + { + hashShift = sHashBits - sizeLog2; + } + static bool isLiveHash(HashNumber hash) { return Entry::isLiveHash(hash); @@ -993,20 +1078,22 @@ class HashTable : private AllocPolicy } public: - HashTable(AllocPolicy ap) - : AllocPolicy(ap), - hashShift(sHashBits), - entryCount(0), - gen(0), - removedCount(0), - table(nullptr), - entered(false), - mutationCount(0) + explicit HashTable(AllocPolicy ap) + : AllocPolicy(ap) + , table(nullptr) + , gen(0) + , entryCount(0) + , removedCount(0) + , hashShift(sHashBits) +#ifdef DEBUG + , mutationCount(0) + , mEntered(false) +#endif {} MOZ_WARN_UNUSED_RESULT bool init(uint32_t length) { - JS_ASSERT(!initialized()); + MOZ_ASSERT(!initialized()); // Reject all lengths whose initial computed capacity would exceed // sMaxCapacity. Round that maximum length down to the nearest power @@ -1116,10 +1203,10 @@ class HashTable : private AllocPolicy Entry &lookup(const Lookup &l, HashNumber keyHash, unsigned collisionBit) const { - JS_ASSERT(isLiveHash(keyHash)); - JS_ASSERT(!(keyHash & sCollisionBit)); - JS_ASSERT(collisionBit == 0 || collisionBit == sCollisionBit); - JS_ASSERT(table); + MOZ_ASSERT(isLiveHash(keyHash)); + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(collisionBit == 0 || collisionBit == sCollisionBit); + MOZ_ASSERT(table); METER(stats.searches++); // Compute the primary hash address. @@ -1145,7 +1232,7 @@ class HashTable : private AllocPolicy Entry *firstRemoved = nullptr; while(true) { - if (JS_UNLIKELY(entry->isRemoved())) { + if (MOZ_UNLIKELY(entry->isRemoved())) { if (!firstRemoved) firstRemoved = entry; } else { @@ -1176,8 +1263,8 @@ class HashTable : private AllocPolicy // from entries, which allows more flexible Lookup/Key types. Entry &findFreeEntry(HashNumber keyHash) { - JS_ASSERT(!(keyHash & sCollisionBit)); - JS_ASSERT(table); + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(table); METER(stats.searches++); // We assume 'keyHash' has already been distributed. @@ -1196,7 +1283,7 @@ class HashTable : private AllocPolicy DoubleHash dh = hash2(keyHash); while(true) { - JS_ASSERT(!entry->isRemoved()); + MOZ_ASSERT(!entry->isRemoved()); entry->setCollision(); METER(stats.steps++); @@ -1277,7 +1364,7 @@ class HashTable : private AllocPolicy void remove(Entry &e) { - JS_ASSERT(table); + MOZ_ASSERT(table); METER(stats.removes++); if (e.hasCollision()) { @@ -1288,7 +1375,9 @@ class HashTable : private AllocPolicy e.clearLive(); } entryCount--; +#ifdef DEBUG mutationCount++; +#endif } void checkUnderloaded() @@ -1371,12 +1460,14 @@ class HashTable : private AllocPolicy } removedCount = 0; entryCount = 0; +#ifdef DEBUG mutationCount++; +#endif } void finish() { - JS_ASSERT(!entered); + MOZ_ASSERT(!mEntered); if (!table) return; @@ -1386,36 +1477,38 @@ class HashTable : private AllocPolicy gen++; entryCount = 0; removedCount = 0; +#ifdef DEBUG mutationCount++; +#endif } Range all() const { - JS_ASSERT(table); - return Range(table, table + capacity()); + MOZ_ASSERT(table); + return Range(*this, table, table + capacity()); } bool empty() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return !entryCount; } uint32_t count() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return entryCount; } uint32_t capacity() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return JS_BIT(sHashBits - hashShift); } uint32_t generation() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return gen; } @@ -1433,13 +1526,13 @@ class HashTable : private AllocPolicy { mozilla::ReentrancyGuard g(*this); HashNumber keyHash = prepareHash(l); - return Ptr(lookup(l, keyHash, 0)); + return Ptr(lookup(l, keyHash, 0), *this); } Ptr readonlyThreadsafeLookup(const Lookup &l) const { HashNumber keyHash = prepareHash(l); - return Ptr(lookup(l, keyHash, 0)); + return Ptr(lookup(l, keyHash, 0), *this); } AddPtr lookupForAdd(const Lookup &l) const @@ -1447,8 +1540,7 @@ class HashTable : private AllocPolicy mozilla::ReentrancyGuard g(*this); HashNumber keyHash = prepareHash(l); Entry &entry = lookup(l, keyHash, sCollisionBit); - AddPtr p(entry, keyHash); - p.mutationCount = mutationCount; + AddPtr p(entry, *this, keyHash); return p; } @@ -1456,10 +1548,9 @@ class HashTable : private AllocPolicy bool add(AddPtr &p, U &&u) { mozilla::ReentrancyGuard g(*this); - JS_ASSERT(mutationCount == p.mutationCount); - JS_ASSERT(table); - JS_ASSERT(!p.found()); - JS_ASSERT(!(p.keyHash & sCollisionBit)); + MOZ_ASSERT(table); + MOZ_ASSERT(!p.found()); + MOZ_ASSERT(!(p.keyHash & sCollisionBit)); // Changing an entry from removed to live does not affect whether we // are overloaded and can be handled separately. @@ -1478,7 +1569,11 @@ class HashTable : private AllocPolicy p.entry_->setLive(p.keyHash, mozilla::Forward(u)); entryCount++; +#ifdef DEBUG mutationCount++; + p.generation = generation(); + p.mutationCount = mutationCount; +#endif return true; } @@ -1487,7 +1582,7 @@ class HashTable : private AllocPolicy template void putNewInfallible(const Lookup &l, U &&u) { - JS_ASSERT(table); + MOZ_ASSERT(table); HashNumber keyHash = prepareHash(l); Entry *entry = &findFreeEntry(keyHash); @@ -1500,7 +1595,9 @@ class HashTable : private AllocPolicy entry->setLive(keyHash, mozilla::Forward(u)); entryCount++; +#ifdef DEBUG mutationCount++; +#endif } // Note: |l| may be a reference to a piece of |u|, so this function @@ -1520,10 +1617,13 @@ class HashTable : private AllocPolicy template bool relookupOrAdd(AddPtr& p, const Lookup &l, U &&u) { +#ifdef DEBUG + p.generation = generation(); p.mutationCount = mutationCount; +#endif { mozilla::ReentrancyGuard g(*this); - JS_ASSERT(prepareHash(l) == p.keyHash); // l has not been destroyed + MOZ_ASSERT(prepareHash(l) == p.keyHash); // l has not been destroyed p.entry_ = &lookup(l, p.keyHash, sCollisionBit); } return p.found() || add(p, mozilla::Forward(u)); @@ -1531,18 +1631,18 @@ class HashTable : private AllocPolicy void remove(Ptr p) { - JS_ASSERT(table); + MOZ_ASSERT(table); mozilla::ReentrancyGuard g(*this); - JS_ASSERT(p.found()); + MOZ_ASSERT(p.found()); remove(*p.entry_); checkUnderloaded(); } void rekeyWithoutRehash(Ptr p, const Lookup &l, const Key &k) { - JS_ASSERT(table); + MOZ_ASSERT(table); mozilla::ReentrancyGuard g(*this); - JS_ASSERT(p.found()); + MOZ_ASSERT(p.found()); typename HashTableEntry::NonConstT t(mozilla::Move(*p)); HashPolicy::setKey(t, const_cast(k)); remove(*p.entry_); @@ -1555,6 +1655,14 @@ class HashTable : private AllocPolicy checkOverRemoved(); } + void rekeyInPlace(Ptr p, const Key &k) + { + MOZ_ASSERT(table); + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(p.found()); + HashPolicy::rekey(const_cast(*p), const_cast(k)); + } + #undef METER }; diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/HeapAPI.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/HeapAPI.h index 9993751d46..bdd63c1937 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/HeapAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/HeapAPI.h @@ -26,11 +26,17 @@ CurrentThreadCanAccessZone(JS::Zone *zone); namespace gc { +struct Cell; + const size_t ArenaShift = 12; const size_t ArenaSize = size_t(1) << ArenaShift; const size_t ArenaMask = ArenaSize - 1; +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkShift = 18; +#else const size_t ChunkShift = 20; +#endif const size_t ChunkSize = size_t(1) << ChunkShift; const size_t ChunkMask = ChunkSize - 1; @@ -39,9 +45,15 @@ const size_t CellSize = size_t(1) << CellShift; const size_t CellMask = CellSize - 1; /* These are magic constants derived from actual offsets in gc/Heap.h. */ -const size_t ChunkMarkBitmapOffset = 1032368; +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkMarkBitmapOffset = 258104; +const size_t ChunkMarkBitmapBits = 31744; +#else +const size_t ChunkMarkBitmapOffset = 1032352; const size_t ChunkMarkBitmapBits = 129024; +#endif const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*); +const size_t ChunkLocationOffset = ChunkSize - 2 * sizeof(void*) - sizeof(uint64_t); /* * Live objects are marked black. How many other additional colors are available @@ -51,14 +63,98 @@ const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*); static const uint32_t BLACK = 0; static const uint32_t GRAY = 1; +/* + * The "location" field in the Chunk trailer is a bit vector indicting various + * roles of the chunk. + * + * The value 0 for the "location" field is invalid, at least one bit must be + * set. + * + * Some bits preclude others, for example, any "nursery" bit precludes any + * "tenured" or "middle generation" bit. + */ +const uintptr_t ChunkLocationBitNursery = 1; // Standard GGC nursery +const uintptr_t ChunkLocationBitTenuredHeap = 2; // Standard GGC tenured generation +const uintptr_t ChunkLocationBitPJSNewspace = 4; // The PJS generational GC's allocation space +const uintptr_t ChunkLocationBitPJSFromspace = 8; // The PJS generational GC's fromspace (during GC) + +const uintptr_t ChunkLocationAnyNursery = ChunkLocationBitNursery | + ChunkLocationBitPJSNewspace | + ChunkLocationBitPJSFromspace; + +#ifdef JS_DEBUG +/* When downcasting, ensure we are actually the right type. */ +extern JS_FRIEND_API(void) +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind); +#else +inline void +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind) {} +#endif + } /* namespace gc */ } /* namespace js */ namespace JS { struct Zone; -} /* namespace JS */ -namespace JS { +/* Default size for the generational nursery in bytes. */ +const uint32_t DefaultNurseryBytes = 16 * 1024 * 1024; + +/* Default maximum heap size in bytes to pass to JS_NewRuntime(). */ +const uint32_t DefaultHeapMaxBytes = 32 * 1024 * 1024; + +/* + * We cannot expose the class hierarchy: the implementation is hidden. Instead + * we provide cast functions with strong debug-mode assertions. + */ +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSObject *obj) +{ + js::gc::Cell *cell = reinterpret_cast(obj); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFunction *fun) +{ + js::gc::Cell *cell = reinterpret_cast(fun); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSString *str) +{ + js::gc::Cell *cell = reinterpret_cast(str); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFlatString *flat) +{ + js::gc::Cell *cell = reinterpret_cast(flat); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JS::Symbol *sym) +{ + js::gc::Cell *cell = reinterpret_cast(sym); + AssertGCThingHasType(cell, JSTRACE_SYMBOL); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSScript *script) +{ + js::gc::Cell *cell = reinterpret_cast(script); + AssertGCThingHasType(cell, JSTRACE_SCRIPT); + return cell; +} + namespace shadow { struct ArenaHeader @@ -86,13 +182,13 @@ struct Zone } JSTracer *barrierTracer() { - JS_ASSERT(needsBarrier_); - JS_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + MOZ_ASSERT(needsBarrier_); + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); return barrierTracer_; } JSRuntime *runtimeFromMainThread() const { - JS_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); return runtime_; } @@ -113,40 +209,40 @@ struct Zone namespace js { namespace gc { -static JS_ALWAYS_INLINE uintptr_t * +static MOZ_ALWAYS_INLINE uintptr_t * GetGCThingMarkBitmap(const void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); uintptr_t addr = uintptr_t(thing); addr &= ~js::gc::ChunkMask; addr |= js::gc::ChunkMarkBitmapOffset; return reinterpret_cast(addr); } -static JS_ALWAYS_INLINE JS::shadow::Runtime * +static MOZ_ALWAYS_INLINE JS::shadow::Runtime * GetGCThingRuntime(const void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); uintptr_t addr = uintptr_t(thing); addr &= ~js::gc::ChunkMask; addr |= js::gc::ChunkRuntimeOffset; return *reinterpret_cast(addr); } -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void GetGCThingMarkWordAndMask(const void *thing, uint32_t color, uintptr_t **wordp, uintptr_t *maskp) { uintptr_t addr = uintptr_t(thing); size_t bit = (addr & js::gc::ChunkMask) / js::gc::CellSize + color; - JS_ASSERT(bit < js::gc::ChunkMarkBitmapBits); + MOZ_ASSERT(bit < js::gc::ChunkMarkBitmapBits); uintptr_t *bitmap = GetGCThingMarkBitmap(thing); const uintptr_t nbits = sizeof(*bitmap) * CHAR_BIT; *maskp = uintptr_t(1) << (bit % nbits); *wordp = &bitmap[bit / nbits]; } -static JS_ALWAYS_INLINE JS::shadow::ArenaHeader * +static MOZ_ALWAYS_INLINE JS::shadow::ArenaHeader * GetGCThingArena(void *thing) { uintptr_t addr = uintptr_t(thing); @@ -154,11 +250,18 @@ GetGCThingArena(void *thing) return reinterpret_cast(addr); } -JS_ALWAYS_INLINE bool -IsInsideNursery(const JS::shadow::Runtime *runtime, const void *p) +MOZ_ALWAYS_INLINE bool +IsInsideNursery(const js::gc::Cell *cell) { #ifdef JSGC_GENERATIONAL - return uintptr_t(p) >= runtime->gcNurseryStart_ && uintptr_t(p) < runtime->gcNurseryEnd_; + if (!cell) + return false; + uintptr_t addr = uintptr_t(cell); + addr &= ~js::gc::ChunkMask; + addr |= js::gc::ChunkLocationOffset; + uint32_t location = *reinterpret_cast(addr); + JS_ASSERT(location != 0); + return location & ChunkLocationAnyNursery; #else return false; #endif @@ -170,20 +273,20 @@ IsInsideNursery(const JS::shadow::Runtime *runtime, const void *p) namespace JS { -static JS_ALWAYS_INLINE Zone * +static MOZ_ALWAYS_INLINE Zone * GetGCThingZone(void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); return js::gc::GetGCThingArena(thing)->zone; } -static JS_ALWAYS_INLINE Zone * +static MOZ_ALWAYS_INLINE Zone * GetObjectZone(JSObject *obj) { return GetGCThingZone(obj); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool GCThingIsMarkedGray(void *thing) { #ifdef JSGC_GENERATIONAL @@ -192,8 +295,7 @@ GCThingIsMarkedGray(void *thing) * All live objects in the nursery are moved to tenured at the beginning of * each GC slice, so the gray marker never sees nursery things. */ - JS::shadow::Runtime *rt = js::gc::GetGCThingRuntime(thing); - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return false; #endif uintptr_t *word, mask; @@ -201,7 +303,7 @@ GCThingIsMarkedGray(void *thing) return *word & mask; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool IsIncrementalBarrierNeededOnGCThing(shadow::Runtime *rt, void *thing, JSGCTraceKind kind) { if (!rt->needsBarrier_) diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/Id.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/Id.h index 447deb62e6..11116f2efe 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/Id.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/Id.h @@ -21,164 +21,155 @@ // JS_IdToValue must be used instead. #include "mozilla/NullPtr.h" - + #include "jstypes.h" +#include "js/HeapAPI.h" #include "js/RootingAPI.h" #include "js/TypeDecls.h" #include "js/Utility.h" -#ifdef JS_USE_JSID_STRUCT_TYPES struct jsid { size_t asBits; bool operator==(jsid rhs) const { return asBits == rhs.asBits; } bool operator!=(jsid rhs) const { return asBits != rhs.asBits; } }; -# define JSID_BITS(id) (id.asBits) -#else -# define JSID_BITS(id) (id) -#endif +#define JSID_BITS(id) (id.asBits) #define JSID_TYPE_STRING 0x0 #define JSID_TYPE_INT 0x1 #define JSID_TYPE_VOID 0x2 -#define JSID_TYPE_OBJECT 0x4 +#define JSID_TYPE_SYMBOL 0x4 #define JSID_TYPE_MASK 0x7 // Avoid using canonical 'id' for jsid parameters since this is a magic word in // Objective-C++ which, apparently, wants to be able to #include jsapi.h. #define id iden -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_STRING(jsid id) { return (JSID_BITS(id) & JSID_TYPE_MASK) == 0; } -static JS_ALWAYS_INLINE JSString * +static MOZ_ALWAYS_INLINE JSString * JSID_TO_STRING(jsid id) { - JS_ASSERT(JSID_IS_STRING(id)); + MOZ_ASSERT(JSID_IS_STRING(id)); return (JSString *)JSID_BITS(id); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ZERO(jsid id) { return JSID_BITS(id) == 0; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_INT(jsid id) { return !!(JSID_BITS(id) & JSID_TYPE_INT); } -static JS_ALWAYS_INLINE int32_t +static MOZ_ALWAYS_INLINE int32_t JSID_TO_INT(jsid id) { - JS_ASSERT(JSID_IS_INT(id)); + MOZ_ASSERT(JSID_IS_INT(id)); return ((uint32_t)JSID_BITS(id)) >> 1; } #define JSID_INT_MIN 0 #define JSID_INT_MAX INT32_MAX -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool INT_FITS_IN_JSID(int32_t i) { return i >= 0; } -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid INT_TO_JSID(int32_t i) { jsid id; - JS_ASSERT(INT_FITS_IN_JSID(i)); + MOZ_ASSERT(INT_FITS_IN_JSID(i)); JSID_BITS(id) = ((i << 1) | JSID_TYPE_INT); return id; } -static JS_ALWAYS_INLINE bool -JSID_IS_OBJECT(jsid id) +static MOZ_ALWAYS_INLINE bool +JSID_IS_SYMBOL(jsid id) { - return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_OBJECT && - (size_t)JSID_BITS(id) != JSID_TYPE_OBJECT; + return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_SYMBOL && + JSID_BITS(id) != JSID_TYPE_SYMBOL; } -static JS_ALWAYS_INLINE JSObject * -JSID_TO_OBJECT(jsid id) +static MOZ_ALWAYS_INLINE JS::Symbol * +JSID_TO_SYMBOL(jsid id) { - JS_ASSERT(JSID_IS_OBJECT(id)); - return (JSObject *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); + MOZ_ASSERT(JSID_IS_SYMBOL(id)); + return (JS::Symbol *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); } -static JS_ALWAYS_INLINE jsid -OBJECT_TO_JSID(JSObject *obj) +static MOZ_ALWAYS_INLINE jsid +SYMBOL_TO_JSID(JS::Symbol *sym) { jsid id; - JS_ASSERT(obj != nullptr); - JS_ASSERT(((size_t)obj & JSID_TYPE_MASK) == 0); - JSID_BITS(id) = ((size_t)obj | JSID_TYPE_OBJECT); + MOZ_ASSERT(sym != nullptr); + MOZ_ASSERT((size_t(sym) & JSID_TYPE_MASK) == 0); + JS_ASSERT(!js::gc::IsInsideNursery(JS::AsCell(sym))); + JS_ASSERT(!JS::IsPoisonedPtr(sym)); + JSID_BITS(id) = (size_t(sym) | JSID_TYPE_SYMBOL); return id; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_GCTHING(jsid id) { - return JSID_IS_STRING(id) || JSID_IS_OBJECT(id); + return JSID_IS_STRING(id) || JSID_IS_SYMBOL(id); } -static JS_ALWAYS_INLINE void * +static MOZ_ALWAYS_INLINE void * JSID_TO_GCTHING(jsid id) { return (void *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_VOID(const jsid id) { - JS_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID, + MOZ_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID, JSID_BITS(id) == JSID_TYPE_VOID); return ((size_t)JSID_BITS(id) == JSID_TYPE_VOID); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_EMPTY(const jsid id) { - return ((size_t)JSID_BITS(id) == JSID_TYPE_OBJECT); + return ((size_t)JSID_BITS(id) == JSID_TYPE_SYMBOL); } -#undef id - -#ifdef JS_USE_JSID_STRUCT_TYPES extern JS_PUBLIC_DATA(const jsid) JSID_VOID; extern JS_PUBLIC_DATA(const jsid) JSID_EMPTY; -#else -# define JSID_VOID ((jsid)JSID_TYPE_VOID) -# define JSID_EMPTY ((jsid)JSID_TYPE_OBJECT) -#endif -extern JS_PUBLIC_DATA(const JS::Handle) JSID_VOIDHANDLE; -extern JS_PUBLIC_DATA(const JS::Handle) JSID_EMPTYHANDLE; +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_VOIDHANDLE; +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_EMPTYHANDLE; namespace js { inline bool -IsPoisonedId(jsid iden) +IsPoisonedId(jsid id) { - if (JSID_IS_STRING(iden)) - return JS::IsPoisonedPtr(JSID_TO_STRING(iden)); - if (JSID_IS_OBJECT(iden)) - return JS::IsPoisonedPtr(JSID_TO_OBJECT(iden)); + if (JSID_IS_STRING(id)) + return JS::IsPoisonedPtr(JSID_TO_STRING(id)); + if (JSID_IS_SYMBOL(id)) + return JS::IsPoisonedPtr(JSID_TO_SYMBOL(id)); return false; } template <> struct GCMethods { static jsid initial() { return JSID_VOID; } - static ThingRootKind kind() { return THING_ROOT_ID; } static bool poisoned(jsid id) { return IsPoisonedId(id); } static bool needsPostBarrier(jsid id) { return false; } #ifdef JSGC_GENERATIONAL @@ -187,6 +178,8 @@ template <> struct GCMethods #endif }; +#undef id + } #endif /* js_Id_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/MemoryMetrics.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/MemoryMetrics.h index 95ac91b9f6..31e456baba 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/MemoryMetrics.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/MemoryMetrics.h @@ -77,6 +77,13 @@ struct InefficientNonFlatteningStringHashPolicy static bool match(const JSString *const &k, const Lookup &l); }; +struct CStringHashPolicy +{ + typedef const char *Lookup; + static HashNumber hash(const Lookup &l); + static bool match(const char *const &k, const Lookup &l); +}; + // This file features many classes with numerous size_t fields, and each such // class has one or more methods that need to operate on all of these fields. // Writing these individually is error-prone -- it's easy to add a new field @@ -92,6 +99,9 @@ struct InefficientNonFlatteningStringHashPolicy #define ZERO_SIZE(kind, gc, mSize) mSize(0), #define COPY_OTHER_SIZE(kind, gc, mSize) mSize(other.mSize), #define ADD_OTHER_SIZE(kind, gc, mSize) mSize += other.mSize; +#define SUB_OTHER_SIZE(kind, gc, mSize) MOZ_ASSERT(mSize >= other.mSize); \ + mSize -= other.mSize; +#define ADD_SIZE_TO_N(kind, gc, mSize) n += mSize; #define ADD_SIZE_TO_N_IF_LIVE_GC_THING(kind, gc, mSize) n += (js::gc) ? mSize : 0; #define ADD_TO_TAB_SIZES(kind, gc, mSize) sizes->add(JS::TabSizes::kind, mSize); @@ -101,49 +111,6 @@ enum { IsLiveGCThing = true }; -struct ZoneStatsPod -{ -#define FOR_EACH_SIZE(macro) \ - macro(Other, NotLiveGCThing, gcHeapArenaAdmin) \ - macro(Other, NotLiveGCThing, unusedGCThings) \ - macro(Other, IsLiveGCThing, lazyScriptsGCHeap) \ - macro(Other, NotLiveGCThing, lazyScriptsMallocHeap) \ - macro(Other, IsLiveGCThing, ionCodesGCHeap) \ - macro(Other, IsLiveGCThing, typeObjectsGCHeap) \ - macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \ - macro(Other, NotLiveGCThing, typePool) \ - macro(Strings, IsLiveGCThing, stringsShortGCHeap) \ - macro(Strings, IsLiveGCThing, stringsNormalGCHeap) \ - macro(Strings, NotLiveGCThing, stringsNormalMallocHeap) - - ZoneStatsPod() - : FOR_EACH_SIZE(ZERO_SIZE) - extra() - {} - - void add(const ZoneStatsPod &other) { - FOR_EACH_SIZE(ADD_OTHER_SIZE) - // Do nothing with |extra|. - } - - size_t sizeOfLiveGCThings() const { - size_t n = 0; - FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) - // Do nothing with |extra|. - return n; - } - - void addToTabSizes(JS::TabSizes *sizes) const { - FOR_EACH_SIZE(ADD_TO_TAB_SIZES) - // Do nothing with |extra|. - } - - FOR_EACH_SIZE(DECL_SIZE) - void *extra; // This field can be used by embedders. - -#undef FOR_EACH_SIZE -}; - } // namespace js namespace JS { @@ -156,6 +123,7 @@ struct ObjectsExtraSizes macro(Objects, NotLiveGCThing, mallocHeapElementsNonAsmJS) \ macro(Objects, NotLiveGCThing, mallocHeapElementsAsmJS) \ macro(Objects, NotLiveGCThing, nonHeapElementsAsmJS) \ + macro(Objects, NotLiveGCThing, nonHeapElementsMapped) \ macro(Objects, NotLiveGCThing, nonHeapCodeAsmJS) \ macro(Objects, NotLiveGCThing, mallocHeapAsmJSModuleData) \ macro(Objects, NotLiveGCThing, mallocHeapArgumentsData) \ @@ -209,6 +177,33 @@ struct CodeSizes #undef FOR_EACH_SIZE }; +// Data for tracking GC memory usage. +struct GCSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, marker) \ + macro(_, _, nurseryCommitted) \ + macro(_, _, nurseryDecommitted) \ + macro(_, _, nurseryHugeSlots) \ + macro(_, _, storeBufferVals) \ + macro(_, _, storeBufferCells) \ + macro(_, _, storeBufferSlots) \ + macro(_, _, storeBufferWholeCells) \ + macro(_, _, storeBufferRelocVals) \ + macro(_, _, storeBufferRelocCells) \ + macro(_, _, storeBufferGenerics) + + GCSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + dummy() + {} + + FOR_EACH_SIZE(DECL_SIZE) + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) + +#undef FOR_EACH_SIZE +}; + // This class holds information about the memory taken up by identical copies of // a particular string. Multiple JSStrings may have their sizes aggregated // together into one StringInfo object. Note that two strings with identical @@ -216,50 +211,59 @@ struct CodeSizes // is not. struct StringInfo { - StringInfo() - : numCopies(0), - isShort(0), - gcHeap(0), - mallocHeap(0) - {} +#define FOR_EACH_SIZE(macro) \ + macro(Strings, IsLiveGCThing, gcHeapLatin1) \ + macro(Strings, IsLiveGCThing, gcHeapTwoByte) \ + macro(Strings, NotLiveGCThing, mallocHeapLatin1) \ + macro(Strings, NotLiveGCThing, mallocHeapTwoByte) - StringInfo(bool isShort, size_t gcSize, size_t mallocSize) - : numCopies(1), - isShort(isShort), - gcHeap(gcSize), - mallocHeap(mallocSize) + StringInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numCopies(0) {} - void add(bool isShort, size_t gcSize, size_t mallocSize) { + void add(const StringInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE); numCopies++; - MOZ_ASSERT(isShort == this->isShort); - gcHeap += gcSize; - mallocHeap += mallocSize; } - void add(const StringInfo& info) { - numCopies += info.numCopies; - MOZ_ASSERT(info.isShort == isShort); - gcHeap += info.gcHeap; - mallocHeap += info.mallocHeap; + void subtract(const StringInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE); + numCopies--; } - uint32_t numCopies:31; // How many copies of the string have we seen? - uint32_t isShort:1; // Is it a short string? + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + size_t sizeOfLiveGCThings() const { + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + return n; + } + + void addToTabSizes(TabSizes *sizes) const { + FOR_EACH_SIZE(ADD_TO_TAB_SIZES) + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numCopies; // How many copies of the string have we seen? - // These are all totals across all copies of the string we've seen. - size_t gcHeap; - size_t mallocHeap; +#undef FOR_EACH_SIZE }; -// Holds data about a notable string (one which uses more than -// NotableStringInfo::notableSize() bytes of memory), so we can report it -// individually. +// Holds data about a notable string (one which, counting all duplicates, uses +// more than a certain amount of memory) so we can report it individually. // -// Essentially the only difference between this class and StringInfo is that -// NotableStringInfo holds a copy of the string's chars. +// The only difference between this class and StringInfo is that +// NotableStringInfo holds a copy of some or all of the string's chars. struct NotableStringInfo : public StringInfo { + static const size_t MAX_SAVED_CHARS = 1024; + NotableStringInfo(); NotableStringInfo(JSString *str, const StringInfo &info); NotableStringInfo(NotableStringInfo &&info); @@ -269,12 +273,6 @@ struct NotableStringInfo : public StringInfo js_free(buffer); } - // A string needs to take up this many bytes of storage before we consider - // it to be "notable". - static size_t notableSize() { - return js::MemoryReportingSundriesThreshold(); - } - char *buffer; size_t length; @@ -282,6 +280,67 @@ struct NotableStringInfo : public StringInfo NotableStringInfo(const NotableStringInfo& info) MOZ_DELETE; }; +// This class holds information about the memory taken up by script sources +// from a particular file. +struct ScriptSourceInfo +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, compressed) \ + macro(_, _, uncompressed) \ + macro(_, _, misc) + + ScriptSourceInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numScripts(0) + {} + + void add(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE) + numScripts++; + } + + void subtract(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE) + numScripts--; + } + + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numScripts; // How many ScriptSources come from this file? (It + // can be more than one in XML files that have + // multiple scripts in CDATA sections.) +#undef FOR_EACH_SIZE +}; + +// Holds data about a notable script source file (one whose combined +// script sources use more than a certain amount of memory) so we can report it +// individually. +// +// The only difference between this class and ScriptSourceInfo is that this +// class holds a copy of the filename. +struct NotableScriptSourceInfo : public ScriptSourceInfo +{ + NotableScriptSourceInfo(); + NotableScriptSourceInfo(const char *filename, const ScriptSourceInfo &info); + NotableScriptSourceInfo(NotableScriptSourceInfo &&info); + NotableScriptSourceInfo &operator=(NotableScriptSourceInfo &&info); + + ~NotableScriptSourceInfo() { + js_free(filename_); + } + + char *filename_; + + private: + NotableScriptSourceInfo(const NotableScriptSourceInfo& info) MOZ_DELETE; +}; + // These measurements relate directly to the JSRuntime, and not to zones and // compartments within it. struct RuntimeSizes @@ -292,81 +351,139 @@ struct RuntimeSizes macro(_, _, contexts) \ macro(_, _, dtoa) \ macro(_, _, temporary) \ - macro(_, _, regexpData) \ macro(_, _, interpreterStack) \ - macro(_, _, gcMarker) \ macro(_, _, mathCache) \ + macro(_, _, uncompressedSourceCache) \ + macro(_, _, compressedSourceSet) \ macro(_, _, scriptData) \ - macro(_, _, scriptSources) RuntimeSizes() : FOR_EACH_SIZE(ZERO_SIZE) - code() - {} + scriptSourceInfo(), + code(), + gc(), + notableScriptSources() + { + allScriptSources = js_new(); + if (!allScriptSources || !allScriptSources->init()) + MOZ_CRASH("oom"); + } + ~RuntimeSizes() { + // |allScriptSources| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allScriptSources); + } + + // The script source measurements in |scriptSourceInfo| are initially for + // all script sources. At the end, if the measurement granularity is + // FineGrained, we subtract the measurements of the notable script sources + // and move them into |notableScriptSources|. FOR_EACH_SIZE(DECL_SIZE) - CodeSizes code; + ScriptSourceInfo scriptSourceInfo; + CodeSizes code; + GCSizes gc; + + typedef js::HashMap ScriptSourcesHashMap; + + // |allScriptSources| is only used transiently. During the reporting phase + // it is filled with info about every script source in the runtime. It's + // then used to fill in |notableScriptSources| (which actually gets + // reported), and immediately discarded afterwards. + ScriptSourcesHashMap *allScriptSources; + js::Vector notableScriptSources; #undef FOR_EACH_SIZE }; -struct ZoneStats : js::ZoneStatsPod +struct ZoneStats { +#define FOR_EACH_SIZE(macro) \ + macro(Other, IsLiveGCThing, symbolsGCHeap) \ + macro(Other, NotLiveGCThing, gcHeapArenaAdmin) \ + macro(Other, NotLiveGCThing, unusedGCThings) \ + macro(Other, IsLiveGCThing, lazyScriptsGCHeap) \ + macro(Other, NotLiveGCThing, lazyScriptsMallocHeap) \ + macro(Other, IsLiveGCThing, jitCodesGCHeap) \ + macro(Other, IsLiveGCThing, typeObjectsGCHeap) \ + macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \ + macro(Other, NotLiveGCThing, typePool) \ + macro(Other, NotLiveGCThing, baselineStubsOptimized) \ + ZoneStats() - : strings(nullptr) + : FOR_EACH_SIZE(ZERO_SIZE) + stringInfo(), + extra(), + allStrings(nullptr), + notableStrings(), + isTotals(true) {} ZoneStats(ZoneStats &&other) - : ZoneStatsPod(mozilla::Move(other)), - strings(other.strings), - notableStrings(mozilla::Move(other.notableStrings)) + : FOR_EACH_SIZE(COPY_OTHER_SIZE) + stringInfo(mozilla::Move(other.stringInfo)), + extra(other.extra), + allStrings(other.allStrings), + notableStrings(mozilla::Move(other.notableStrings)), + isTotals(other.isTotals) { - other.strings = nullptr; + other.allStrings = nullptr; + MOZ_ASSERT(!other.isTotals); } - bool initStrings(JSRuntime *rt); - - // Add |other|'s numbers to this object's numbers. The strings data isn't - // touched. - void addIgnoringStrings(const ZoneStats &other) { - ZoneStatsPod::add(other); + ~ZoneStats() { + // |allStrings| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allStrings); } - // Add |other|'s strings data to this object's strings data. (We don't do - // anything with notableStrings.) - void addStrings(const ZoneStats &other) { - for (StringsHashMap::Range r = other.strings->all(); !r.empty(); r.popFront()) { - StringsHashMap::AddPtr p = strings->lookupForAdd(r.front().key()); - if (p) { - // We've seen this string before; add its size to our tally. - p->value().add(r.front().value()); - } else { - // We haven't seen this string before; add it to the hashtable. - strings->add(p, r.front().key(), r.front().value()); - } - } + bool initStrings(JSRuntime *rt); + + void addSizes(const ZoneStats &other) { + MOZ_ASSERT(isTotals); + FOR_EACH_SIZE(ADD_OTHER_SIZE) + stringInfo.add(other.stringInfo); } size_t sizeOfLiveGCThings() const { - size_t n = ZoneStatsPod::sizeOfLiveGCThings(); - for (size_t i = 0; i < notableStrings.length(); i++) { - const JS::NotableStringInfo& info = notableStrings[i]; - n += info.gcHeap; - } + MOZ_ASSERT(isTotals); + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + n += stringInfo.sizeOfLiveGCThings(); return n; } - typedef js::HashMap StringsHashMap; - // |strings| is only used transiently. During the zone traversal it is + // |allStrings| is only used transiently. During the zone traversal it is // filled with info about every string in the zone. It's then used to fill // in |notableStrings| (which actually gets reported), and immediately // discarded afterwards. - StringsHashMap *strings; + StringsHashMap *allStrings; js::Vector notableStrings; + bool isTotals; + +#undef FOR_EACH_SIZE }; struct CompartmentStats @@ -390,17 +507,16 @@ struct CompartmentStats macro(Other, NotLiveGCThing, scriptsMallocHeapData) \ macro(Other, NotLiveGCThing, baselineData) \ macro(Other, NotLiveGCThing, baselineStubsFallback) \ - macro(Other, NotLiveGCThing, baselineStubsOptimized) \ macro(Other, NotLiveGCThing, ionData) \ macro(Other, NotLiveGCThing, typeInferenceTypeScripts) \ - macro(Other, NotLiveGCThing, typeInferencePendingArrays) \ macro(Other, NotLiveGCThing, typeInferenceAllocationSiteTables) \ macro(Other, NotLiveGCThing, typeInferenceArrayTypeTables) \ macro(Other, NotLiveGCThing, typeInferenceObjectTypeTables) \ macro(Other, NotLiveGCThing, compartmentObject) \ macro(Other, NotLiveGCThing, crossCompartmentWrappersTable) \ macro(Other, NotLiveGCThing, regexpCompartment) \ - macro(Other, NotLiveGCThing, debuggeesSet) + macro(Other, NotLiveGCThing, debuggeesSet) \ + macro(Other, NotLiveGCThing, savedStacksSet) CompartmentStats() : FOR_EACH_SIZE(ZERO_SIZE) @@ -454,7 +570,7 @@ struct RuntimeStats macro(_, _, gcHeapChunkAdmin) \ macro(_, _, gcHeapGCThings) \ - RuntimeStats(mozilla::MallocSizeOf mallocSizeOf) + explicit RuntimeStats(mozilla::MallocSizeOf mallocSizeOf) : FOR_EACH_SIZE(ZERO_SIZE) runtime(), cTotals(), @@ -517,13 +633,13 @@ class ObjectPrivateVisitor typedef bool(*GetISupportsFun)(JSObject *obj, nsISupports **iface); GetISupportsFun getISupports_; - ObjectPrivateVisitor(GetISupportsFun getISupports) + explicit ObjectPrivateVisitor(GetISupportsFun getISupports) : getISupports_(getISupports) {} }; extern JS_PUBLIC_API(bool) -CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv); +CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv, bool anonymize); extern JS_PUBLIC_API(size_t) SystemCompartmentCount(JSRuntime *rt); @@ -544,6 +660,8 @@ AddSizeOfTab(JSRuntime *rt, JS::HandleObject obj, mozilla::MallocSizeOf mallocSi #undef ZERO_SIZE #undef COPY_OTHER_SIZE #undef ADD_OTHER_SIZE +#undef SUB_OTHER_SIZE +#undef ADD_SIZE_TO_N #undef ADD_SIZE_TO_N_IF_LIVE_GC_THING #undef ADD_TO_TAB_SIZES diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/OldDebugAPI.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/OldDebugAPI.h index 5e5bdf38d7..7117d754d9 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/OldDebugAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/OldDebugAPI.h @@ -12,47 +12,40 @@ */ #include "mozilla/NullPtr.h" - + +#include "jsapi.h" #include "jsbytecode.h" #include "js/CallArgs.h" #include "js/TypeDecls.h" class JSAtom; -class JSFreeOp; - -namespace js { class StackFrame; } +struct JSFreeOp; -namespace JS { - -struct FrameDescription -{ - JSScript *script; - unsigned lineno; - JSFunction *fun; -}; +namespace js { +class InterpreterFrame; +class FrameIter; +class ScriptSource; +} -struct StackDescription -{ - unsigned nframes; - FrameDescription *frames; -}; +// Raw JSScript* because this needs to be callable from a signal handler. +extern JS_PUBLIC_API(unsigned) +JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); -extern JS_PUBLIC_API(StackDescription *) -DescribeStack(JSContext *cx, unsigned maxFrames); +extern JS_PUBLIC_API(const char *) +JS_GetScriptFilename(JSScript *script); -extern JS_PUBLIC_API(void) -FreeStackDescription(JSContext *cx, StackDescription *desc); +namespace JS { extern JS_PUBLIC_API(char *) FormatStackDump(JSContext *cx, char *buf, bool showArgs, bool showLocals, bool showThisProps); -} +} // namespace JS -# ifdef DEBUG +# ifdef JS_DEBUG JS_FRIEND_API(void) js_DumpValue(const JS::Value &val); JS_FRIEND_API(void) js_DumpId(jsid id); -JS_FRIEND_API(void) js_DumpStackFrame(JSContext *cx, js::StackFrame *start = nullptr); +JS_FRIEND_API(void) js_DumpInterpreterFrame(JSContext *cx, js::InterpreterFrame *start = nullptr); # endif JS_FRIEND_API(void) @@ -70,48 +63,21 @@ typedef JSTrapStatus (* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, JS::Value closure); -typedef JSTrapStatus -(* JSInterruptHook)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, - void *closure); - typedef JSTrapStatus (* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, void *closure); -typedef JSTrapStatus -(* JSThrowHook)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, - void *closure); - typedef bool (* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, JS::Value old, JS::Value *newp, void *closure); -/* called just after script creation */ -typedef void -(* JSNewScriptHook)(JSContext *cx, - const char *filename, /* URL of script */ - unsigned lineno, /* first line */ - JSScript *script, - JSFunction *fun, - void *callerdata); - -/* called just before script destruction */ -typedef void -(* JSDestroyScriptHook)(JSFreeOp *fop, - JSScript *script, - void *callerdata); - -typedef void -(* JSSourceHandler)(const char *filename, unsigned lineno, const jschar *str, - size_t length, void **listenerTSData, void *closure); - extern JS_PUBLIC_API(JSCompartment *) JS_EnterCompartmentOfScript(JSContext *cx, JSScript *target); extern JS_PUBLIC_API(JSString *) -JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned indent); +JS_DecompileScript(JSContext *cx, JS::HandleScript script, const char *name, unsigned indent); /* * Currently, we only support runtime-wide debugging. In the future, we should @@ -157,12 +123,12 @@ JS_SetDebugMode(JSContext *cx, bool debug); /* Turn on single step mode. */ extern JS_PUBLIC_API(bool) -JS_SetSingleStepMode(JSContext *cx, JSScript *script, bool singleStep); +JS_SetSingleStepMode(JSContext *cx, JS::HandleScript script, bool singleStep); /* The closure argument will be marked. */ extern JS_PUBLIC_API(bool) -JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc, - JSTrapHandler handler, JS::Value closure); +JS_SetTrap(JSContext *cx, JS::HandleScript script, jsbytecode *pc, + JSTrapHandler handler, JS::HandleValue closure); extern JS_PUBLIC_API(void) JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc, @@ -174,17 +140,11 @@ JS_ClearScriptTraps(JSRuntime *rt, JSScript *script); extern JS_PUBLIC_API(void) JS_ClearAllTrapsForCompartment(JSContext *cx); -extern JS_PUBLIC_API(bool) -JS_SetInterrupt(JSRuntime *rt, JSInterruptHook handler, void *closure); - -extern JS_PUBLIC_API(bool) -JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *handlerp, void **closurep); - /************************************************************************/ extern JS_PUBLIC_API(bool) -JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsid id, - JSWatchPointHandler handler, JSObject *closure); +JS_SetWatchPoint(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JSWatchPointHandler handler, JS::HandleObject closure); extern JS_PUBLIC_API(bool) JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id, @@ -195,10 +155,6 @@ JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj); /************************************************************************/ -// Raw JSScript* because this needs to be callable from a signal handler. -extern JS_PUBLIC_API(unsigned) -JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); - extern JS_PUBLIC_API(jsbytecode *) JS_LineNumberToPC(JSContext *cx, JSScript *script, unsigned lineno); @@ -234,17 +190,11 @@ extern JS_PUBLIC_API(void) JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mark); extern JS_PUBLIC_API(JSScript *) -JS_GetFunctionScript(JSContext *cx, JSFunction *fun); +JS_GetFunctionScript(JSContext *cx, JS::HandleFunction fun); extern JS_PUBLIC_API(JSNative) JS_GetFunctionNative(JSContext *cx, JSFunction *fun); -extern JS_PUBLIC_API(JSPrincipals *) -JS_GetScriptPrincipals(JSScript *script); - -extern JS_PUBLIC_API(JSPrincipals *) -JS_GetScriptOriginPrincipals(JSScript *script); - JS_PUBLIC_API(JSFunction *) JS_GetScriptFunction(JSContext *cx, JSScript *script); @@ -264,9 +214,6 @@ JS_GetDebugClassName(JSObject *obj); /************************************************************************/ -extern JS_PUBLIC_API(const char *) -JS_GetScriptFilename(JSContext *cx, JSScript *script); - extern JS_PUBLIC_API(const jschar *) JS_GetScriptSourceMap(JSContext *cx, JSScript *script); @@ -284,22 +231,6 @@ JS_GetScriptIsSelfHosted(JSScript *script); /************************************************************************/ -/* - * Hook setters for script creation and destruction. These macros provide - * binary compatibility and newer, shorter synonyms. - */ -#define JS_SetNewScriptHook JS_SetNewScriptHookProc -#define JS_SetDestroyScriptHook JS_SetDestroyScriptHookProc - -extern JS_PUBLIC_API(void) -JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata); - -extern JS_PUBLIC_API(void) -JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook, - void *callerdata); - -/************************************************************************/ - typedef struct JSPropertyDesc { JS::Value id; /* primary id, atomized string, or int */ JS::Value value; /* property value */ @@ -325,7 +256,7 @@ typedef struct JSPropertyDescArray { typedef struct JSScopeProperty JSScopeProperty; extern JS_PUBLIC_API(bool) -JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda); +JS_GetPropertyDescArray(JSContext *cx, JS::HandleObject obj, JSPropertyDescArray *pda); extern JS_PUBLIC_API(void) JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); @@ -339,16 +270,18 @@ JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); class JS_PUBLIC_API(JSAbstractFramePtr) { uintptr_t ptr_; + jsbytecode *pc_; protected: JSAbstractFramePtr() - : ptr_(0) + : ptr_(0), pc_(nullptr) { } public: - explicit JSAbstractFramePtr(void *raw); + JSAbstractFramePtr(void *raw, jsbytecode *pc); uintptr_t raw() const { return ptr_; } + jsbytecode *pc() const { return pc_; } operator bool() const { return !!ptr_; } @@ -393,7 +326,7 @@ class JS_PUBLIC_API(JSBrokenFrameIterator) void *data_; public: - JSBrokenFrameIterator(JSContext *cx); + explicit JSBrokenFrameIterator(JSContext *cx); ~JSBrokenFrameIterator(); bool done() const; @@ -405,58 +338,13 @@ class JS_PUBLIC_API(JSBrokenFrameIterator) bool isConstructing() const; }; -/* - * This hook captures high level script execution and function calls (JS or - * native). It is used by JS_SetExecuteHook to hook top level scripts and by - * JS_SetCallHook to hook function calls. It will get called twice per script - * or function call: just before execution begins and just after it finishes. - * In both cases the 'current' frame is that of the executing code. - * - * The 'before' param is true for the hook invocation before the execution - * and false for the invocation after the code has run. - * - * The 'ok' param is significant only on the post execution invocation to - * signify whether or not the code completed 'normally'. - * - * The 'closure' param is as passed to JS_SetExecuteHook or JS_SetCallHook - * for the 'before'invocation, but is whatever value is returned from that - * invocation for the 'after' invocation. Thus, the hook implementor *could* - * allocate a structure in the 'before' invocation and return a pointer to that - * structure. The pointer would then be handed to the hook for the 'after' - * invocation. Alternately, the 'before' could just return the same value as - * in 'closure' to cause the 'after' invocation to be called with the same - * 'closure' value as the 'before'. - * - * Returning nullptr in the 'before' hook will cause the 'after' hook *not* to - * be called. - */ -typedef void * -(* JSInterpreterHook)(JSContext *cx, JSAbstractFramePtr frame, bool isConstructing, - bool before, bool *ok, void *closure); - typedef bool (* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report, void *closure); typedef struct JSDebugHooks { - JSInterruptHook interruptHook; - void *interruptHookData; - JSNewScriptHook newScriptHook; - void *newScriptHookData; - JSDestroyScriptHook destroyScriptHook; - void *destroyScriptHookData; JSDebuggerHandler debuggerHandler; void *debuggerHandlerData; - JSSourceHandler sourceHandler; - void *sourceHandlerData; - JSInterpreterHook executeHook; - void *executeHookData; - JSInterpreterHook callHook; - void *callHookData; - JSThrowHook throwHook; - void *throwHookData; - JSDebugErrorHook debugErrorHook; - void *debugErrorHookData; } JSDebugHooks; /************************************************************************/ @@ -464,21 +352,6 @@ typedef struct JSDebugHooks { extern JS_PUBLIC_API(bool) JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler hook, void *closure); -extern JS_PUBLIC_API(bool) -JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetThrowHook(JSRuntime *rt, JSThrowHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure); - /************************************************************************/ extern JS_PUBLIC_API(const JSDebugHooks *) @@ -492,16 +365,10 @@ JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj); /* Defined in vm/Debugger.cpp. */ extern JS_PUBLIC_API(bool) -JS_DefineDebuggerObject(JSContext *cx, JSObject *obj); - -extern JS_PUBLIC_API(void) -JS_DumpBytecode(JSContext *cx, JSScript *script); - -extern JS_PUBLIC_API(void) -JS_DumpCompartmentBytecode(JSContext *cx); +JS_DefineDebuggerObject(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(void) -JS_DumpPCCounts(JSContext *cx, JSScript *script); +JS_DumpPCCounts(JSContext *cx, JS::HandleScript script); extern JS_PUBLIC_API(void) JS_DumpCompartmentPCCounts(JSContext *cx); diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/Principals.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/Principals.h new file mode 100644 index 0000000000..78d8c7e893 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/Principals.h @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JSPrincipals and related interfaces. */ + +#ifndef js_Principals_h +#define js_Principals_h + +#include "mozilla/Atomics.h" + +#include + +#include "jspubtd.h" + +struct JSPrincipals { + /* Don't call "destroy"; use reference counting macros below. */ +#ifdef JS_THREADSAFE + mozilla::Atomic refcount; +#else + int32_t refcount; +#endif + +#ifdef JS_DEBUG + /* A helper to facilitate principals debugging. */ + uint32_t debugToken; +#endif + + void setDebugToken(uint32_t token) { +# ifdef JS_DEBUG + debugToken = token; +# endif + } + + /* + * This is not defined by the JS engine but should be provided by the + * embedding. + */ + JS_PUBLIC_API(void) dump(); +}; + +extern JS_PUBLIC_API(void) +JS_HoldPrincipals(JSPrincipals *principals); + +extern JS_PUBLIC_API(void) +JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals); + +// Return whether the first principal subsumes the second. The exact meaning of +// 'subsumes' is left up to the browser. Subsumption is checked inside the JS +// engine when determining, e.g., which stack frames to display in a backtrace. +typedef bool +(* JSSubsumesOp)(JSPrincipals *first, JSPrincipals *second); + +/* + * Used to check if a CSP instance wants to disable eval() and friends. + * See js_CheckCSPPermitsJSAction() in jsobj. + */ +typedef bool +(* JSCSPEvalChecker)(JSContext *cx); + +struct JSSecurityCallbacks { + JSCSPEvalChecker contentSecurityPolicyAllows; + JSSubsumesOp subsumes; +}; + +extern JS_PUBLIC_API(void) +JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks); + +extern JS_PUBLIC_API(const JSSecurityCallbacks *) +JS_GetSecurityCallbacks(JSRuntime *rt); + +/* + * Code running with "trusted" principals will be given a deeper stack + * allocation than ordinary scripts. This allows trusted script to run after + * untrusted script has exhausted the stack. This function sets the + * runtime-wide trusted principal. + * + * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since + * there is no available JSContext. Instead, the caller must ensure that the + * given principals stays valid for as long as 'rt' may point to it. If the + * principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be + * called again, passing nullptr for 'prin'. + */ +extern JS_PUBLIC_API(void) +JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin); + +typedef void +(* JSDestroyPrincipalsOp)(JSPrincipals *principals); + +/* + * Initialize the callback that is called to destroy JSPrincipals instance + * when its reference counter drops to zero. The initialization can be done + * only once per JS runtime. + */ +extern JS_PUBLIC_API(void) +JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals); + +#endif /* js_Principals_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/ProfilingStack.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/ProfilingStack.h index 213e47bb7d..e82ce1c9d8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/ProfilingStack.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/ProfilingStack.h @@ -8,7 +8,8 @@ #define js_ProfilingStack_h #include "mozilla/NullPtr.h" - +#include "mozilla/TypedEnum.h" + #include "jsbytecode.h" #include "jstypes.h" @@ -34,50 +35,120 @@ class ProfileEntry // If the size modification were somehow reordered before the stores, then // if a sample were taken it would be examining bogus information. // - // A ProfileEntry represents both a C++ profile entry and a JS one. Both use - // the string as a description, but JS uses the sp as nullptr to indicate - // that it is a JS entry. The script_ is then only ever examined for a JS - // entry, and the idx is used by both, but with different meanings. - // - const char * volatile string; // Descriptive string of this entry - void * volatile sp; // Relevant stack pointer for the entry - JSScript * volatile script_; // if js(), non-null script which is running - int32_t volatile idx; // if js(), idx of pc, otherwise line number + // A ProfileEntry represents both a C++ profile entry and a JS one. + + // Descriptive string of this entry. + const char * volatile string; + + // Stack pointer for non-JS entries, the script pointer otherwise. + void * volatile spOrScript; + + // Line number for non-JS entries, the bytecode offset otherwise. + int32_t volatile lineOrPc; + + // General purpose storage describing this frame. + uint32_t volatile flags_; public: + // These traits are bit masks. Make sure they're powers of 2. + enum Flags { + // Indicate whether a profile entry represents a CPP frame. If not set, + // a JS frame is assumed by default. You're not allowed to publicly + // change the frame type. Instead, call `setJsFrame` or `setCppFrame`. + IS_CPP_ENTRY = 0x01, + + // Indicate that copying the frame label is not necessary when taking a + // sample of the pseudostack. + FRAME_LABEL_COPY = 0x02, + + // Mask for removing all flags except the category information. + CATEGORY_MASK = ~IS_CPP_ENTRY & ~FRAME_LABEL_COPY + }; + + MOZ_BEGIN_NESTED_ENUM_CLASS(Category, uint32_t) + OTHER = 0x04, + CSS = 0x08, + JS = 0x10, + GC = 0x20, + CC = 0x40, + NETWORK = 0x80, + GRAPHICS = 0x100, + STORAGE = 0x200, + EVENTS = 0x400, + + FIRST = OTHER, + LAST = EVENTS + MOZ_END_NESTED_ENUM_CLASS(Category) + // All of these methods are marked with the 'volatile' keyword because SPS's // representation of the stack is stored such that all ProfileEntry // instances are volatile. These methods would not be available unless they // were marked as volatile as well. - bool js() const volatile { - JS_ASSERT_IF(sp == nullptr, script_ != nullptr); - return sp == nullptr; - } + bool isCpp() const volatile { return hasFlag(IS_CPP_ENTRY); } + bool isJs() const volatile { return !isCpp(); } - uint32_t line() const volatile { JS_ASSERT(!js()); return idx; } - JSScript *script() const volatile { JS_ASSERT(js()); return script_; } - void *stackAddress() const volatile { return sp; } - const char *label() const volatile { return string; } + bool isCopyLabel() const volatile { return hasFlag(FRAME_LABEL_COPY); }; - void setLine(uint32_t aLine) volatile { JS_ASSERT(!js()); idx = aLine; } void setLabel(const char *aString) volatile { string = aString; } - void setStackAddress(void *aSp) volatile { sp = aSp; } - void setScript(JSScript *aScript) volatile { script_ = aScript; } + const char *label() const volatile { return string; } + + void setJsFrame(JSScript *aScript, jsbytecode *aPc) volatile { + flags_ = 0; + spOrScript = aScript; + setPC(aPc); + } + void setCppFrame(void *aSp, uint32_t aLine) volatile { + flags_ = IS_CPP_ENTRY; + spOrScript = aSp; + lineOrPc = static_cast(aLine); + } + + void setFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ |= flag; + } + void unsetFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ &= ~flag; + } + bool hasFlag(uint32_t flag) const volatile { + return bool(flags_ & flag); + } + + uint32_t flags() const volatile { + return flags_; + } + uint32_t category() const volatile { + return flags_ & CATEGORY_MASK; + } + + void *stackAddress() const volatile { + MOZ_ASSERT(!isJs()); + return spOrScript; + } + JSScript *script() const volatile { + MOZ_ASSERT(isJs()); + return (JSScript *)spOrScript; + } + uint32_t line() const volatile { + MOZ_ASSERT(!isJs()); + return static_cast(lineOrPc); + } // We can't know the layout of JSScript, so look in vm/SPSProfiler.cpp. JS_FRIEND_API(jsbytecode *) pc() const volatile; JS_FRIEND_API(void) setPC(jsbytecode *pc) volatile; - static size_t offsetOfString() { return offsetof(ProfileEntry, string); } - static size_t offsetOfStackAddress() { return offsetof(ProfileEntry, sp); } - static size_t offsetOfPCIdx() { return offsetof(ProfileEntry, idx); } - static size_t offsetOfScript() { return offsetof(ProfileEntry, script_); } + // The offset of a pc into a script's code can actually be 0, so to + // signify a nullptr pc, use a -1 index. This is checked against in + // pc() and setPC() to set/get the right pc. + static const int32_t NullPCOffset = -1; - // The index used in the entry can either be a line number or the offset of - // a pc into a script's code. To signify a nullptr pc, use a -1 index. This - // is checked against in pc() and setPC() to set/get the right pc. - static const int32_t NullPCIndex = -1; + static size_t offsetOfLabel() { return offsetof(ProfileEntry, string); } + static size_t offsetOfSpOrScript() { return offsetof(ProfileEntry, spOrScript); } + static size_t offsetOfLineOrPc() { return offsetof(ProfileEntry, lineOrPc); } + static size_t offsetOfFlags() { return offsetof(ProfileEntry, flags_); } }; JS_FRIEND_API(void) @@ -87,6 +158,9 @@ SetRuntimeProfilingStack(JSRuntime *rt, ProfileEntry *stack, uint32_t *size, JS_FRIEND_API(void) EnableRuntimeProfilingStack(JSRuntime *rt, bool enabled); +JS_FRIEND_API(void) +RegisterRuntimeProfilingEventMarker(JSRuntime *rt, void (*fn)(const char *)); + JS_FRIEND_API(jsbytecode*) ProfilingGetPC(JSRuntime *rt, JSScript *script, void *ip); diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/RequiredDefines.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/RequiredDefines.h index 3c8f429132..308fd7d625 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/RequiredDefines.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/RequiredDefines.h @@ -28,4 +28,7 @@ #define __STDC_CONSTANT_MACROS #define __STDC_FORMAT_MACROS +/* Also define a char16_t type if not provided by the compiler. */ +#include "mozilla/Char16.h" + #endif /* js_RequiredDefines_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/RootingAPI.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/RootingAPI.h index 5b612660cd..621a1e4394 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/RootingAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/RootingAPI.h @@ -15,6 +15,8 @@ #include "jspubtd.h" +#include "js/GCAPI.h" +#include "js/HeapAPI.h" #include "js/TypeDecls.h" #include "js/Utility.h" @@ -138,6 +140,8 @@ struct NullPtr namespace gc { struct Cell; +template +struct PersistentRootedMarker; } /* namespace gc */ } /* namespace js */ @@ -150,11 +154,6 @@ template class PersistentRooted; /* This is exposing internal state of the GC for inlining purposes. */ JS_FRIEND_API(bool) isGCEnabled(); -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) -extern void -CheckStackRoots(JSContext *cx); -#endif - /* * JS::NullPtr acts like a nullptr pointer in contexts that require a Handle. * @@ -198,6 +197,13 @@ class Heap : public js::HeapBase init(js::GCMethods::initial()); } explicit Heap(T p) { init(p); } + + /* + * For Heap, move semantics are equivalent to copy semantics. In C++, a + * copy constructor taking const-ref is the way to get a single function + * that will be used for both lvalue and rvalue copies, so we can simply + * omit the rvalue variant. + */ explicit Heap(const Heap &p) { init(p.ptr); } ~Heap() { @@ -229,7 +235,7 @@ class Heap : public js::HeapBase } void set(T newPtr) { - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); if (js::GCMethods::needsPostBarrier(newPtr)) { ptr = newPtr; post(); @@ -241,9 +247,21 @@ class Heap : public js::HeapBase } } + /* + * Set the pointer to a value which will cause a crash if it is + * dereferenced. + */ + void setToCrashOnTouch() { + ptr = reinterpret_cast(crashOnTouchPointer); + } + + bool isSetToCrashOnTouch() { + return ptr == crashOnTouchPointer; + } + private: void init(T newPtr) { - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); ptr = newPtr; if (js::GCMethods::needsPostBarrier(ptr)) post(); @@ -251,7 +269,7 @@ class Heap : public js::HeapBase void post() { #ifdef JSGC_GENERATIONAL - JS_ASSERT(js::GCMethods::needsPostBarrier(ptr)); + MOZ_ASSERT(js::GCMethods::needsPostBarrier(ptr)); js::GCMethods::postBarrier(&ptr); #endif } @@ -262,10 +280,14 @@ class Heap : public js::HeapBase #endif } + enum { + crashOnTouchPointer = 1 + }; + T ptr; }; -#ifdef DEBUG +#ifdef JS_DEBUG /* * For generational GC, assert that an object is in the tenured generation as * opposed to being in the nursery. @@ -315,31 +337,31 @@ class TenuredHeap : public js::HeapBase "TenuredHeap must be binary compatible with T."); } explicit TenuredHeap(T p) : bits(0) { setPtr(p); } - explicit TenuredHeap(const TenuredHeap &p) : bits(0) { setPtr(p.ptr); } + explicit TenuredHeap(const TenuredHeap &p) : bits(0) { setPtr(p.getPtr()); } bool operator==(const TenuredHeap &other) { return bits == other.bits; } bool operator!=(const TenuredHeap &other) { return bits != other.bits; } void setPtr(T newPtr) { - JS_ASSERT((reinterpret_cast(newPtr) & flagsMask) == 0); - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT((reinterpret_cast(newPtr) & flagsMask) == 0); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); if (newPtr) AssertGCThingMustBeTenured(newPtr); bits = (bits & flagsMask) | reinterpret_cast(newPtr); } void setFlags(uintptr_t flagsToSet) { - JS_ASSERT((flagsToSet & ~flagsMask) == 0); + MOZ_ASSERT((flagsToSet & ~flagsMask) == 0); bits |= flagsToSet; } void unsetFlags(uintptr_t flagsToUnset) { - JS_ASSERT((flagsToUnset & ~flagsMask) == 0); + MOZ_ASSERT((flagsToUnset & ~flagsMask) == 0); bits &= ~flagsToUnset; } bool hasFlag(uintptr_t flag) const { - JS_ASSERT((flag & ~flagsMask) == 0); + MOZ_ASSERT((flag & ~flagsMask) == 0); return (bits & flag) != 0; } @@ -359,23 +381,10 @@ class TenuredHeap : public js::HeapBase return *this; } - /* - * Set the pointer to a value which will cause a crash if it is - * dereferenced. - */ - void setToCrashOnTouch() { - bits = (bits & flagsMask) | crashOnTouchPointer; - } - - bool isSetToCrashOnTouch() { - return (bits & ~flagsMask) == crashOnTouchPointer; - } - private: enum { maskBits = 3, flagsMask = (1 << maskBits) - 1, - crashOnTouchPointer = 1 << maskBits }; uintptr_t bits; @@ -406,20 +415,20 @@ class MOZ_NONHEAP_CLASS Handle : public js::HandleBase } /* Create a handle for a nullptr pointer. */ - Handle(js::NullPtr) { + MOZ_IMPLICIT Handle(js::NullPtr) { static_assert(mozilla::IsPointer::value, "js::NullPtr overload not valid for non-pointer types"); ptr = reinterpret_cast(&js::NullPtr::constNullValue); } /* Create a handle for a nullptr pointer. */ - Handle(JS::NullPtr) { + MOZ_IMPLICIT Handle(JS::NullPtr) { static_assert(mozilla::IsPointer::value, "JS::NullPtr overload not valid for non-pointer types"); ptr = reinterpret_cast(&JS::NullPtr::constNullValue); } - Handle(MutableHandle handle) { + MOZ_IMPLICIT Handle(MutableHandle handle) { ptr = handle.address(); } @@ -476,9 +485,6 @@ class MOZ_NONHEAP_CLASS Handle : public js::HandleBase bool operator!=(const T &other) const { return *ptr != other; } bool operator==(const T &other) const { return *ptr == other; } - /* Change this handle to point to the same rooted location RHS does. */ - void repoint(const Handle &rhs) { ptr = rhs.address(); } - private: Handle() {} @@ -504,15 +510,23 @@ template class MOZ_STACK_CLASS MutableHandle : public js::MutableHandleBase { public: - inline MutableHandle(Rooted *root); - inline MutableHandle(PersistentRooted *root); - MutableHandle(int) MOZ_DELETE; -#ifdef MOZ_HAVE_CXX11_NULLPTR - MutableHandle(decltype(nullptr)) MOZ_DELETE; -#endif + inline MOZ_IMPLICIT MutableHandle(Rooted *root); + inline MOZ_IMPLICIT MutableHandle(PersistentRooted *root); + + private: + // Disallow true nullptr and emulated nullptr (gcc 4.4/4.5, __null, appears + // as int/long [32/64-bit]) for overloading purposes. + template + MutableHandle(N, + typename mozilla::EnableIf::value || + mozilla::IsSame::value || + mozilla::IsSame::value, + int>::Type dummy = 0) + MOZ_DELETE; + public: void set(T v) { - JS_ASSERT(!js::GCMethods::poisoned(v)); + MOZ_ASSERT(!js::GCMethods::poisoned(v)); *ptr = v; } @@ -549,8 +563,8 @@ class MOZ_STACK_CLASS MutableHandle : public js::MutableHandleBase }; #ifdef JSGC_GENERATIONAL -JS_PUBLIC_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); -JS_PUBLIC_API(void) HeapCellRelocate(js::gc::Cell **cellp); +JS_FRIEND_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); +JS_FRIEND_API(void) HeapCellRelocate(js::gc::Cell **cellp); #endif } /* namespace JS */ @@ -612,7 +626,7 @@ class InternalHandle * Make this private to prevent accidental misuse; this is only for * fromMarkedLocation(). */ - InternalHandle(T *field) + explicit InternalHandle(T *field) : holder(reinterpret_cast(&js::NullPtr::constNullValue)), offset(uintptr_t(field)) {} @@ -621,10 +635,16 @@ class InternalHandle }; /* - * By default, pointers should use the inheritance hierarchy to find their + * By default, things should use the inheritance hierarchy to find their * ThingRootKind. Some pointer types are explicitly set in jspubtd.h so that * Rooted may be used without the class definition being available. */ +template +struct RootKind +{ + static ThingRootKind rootKind() { return T::rootKind(); } +}; + template struct RootKind { @@ -635,20 +655,51 @@ template struct GCMethods { static T *initial() { return nullptr; } - static ThingRootKind kind() { return RootKind::rootKind(); } static bool poisoned(T *v) { return JS::IsPoisonedPtr(v); } - static bool needsPostBarrier(T *v) { return v; } + static bool needsPostBarrier(T *v) { return false; } #ifdef JSGC_GENERATIONAL - static void postBarrier(T **vp) { + static void postBarrier(T **vp) {} + static void relocate(T **vp) {} +#endif +}; + +template <> +struct GCMethods +{ + static JSObject *initial() { return nullptr; } + static bool poisoned(JSObject *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSObject *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSObject **vp) { JS::HeapCellPostBarrier(reinterpret_cast(vp)); } - static void relocate(T **vp) { + static void relocate(JSObject **vp) { JS::HeapCellRelocate(reinterpret_cast(vp)); } #endif }; -#if defined(DEBUG) +template <> +struct GCMethods +{ + static JSFunction *initial() { return nullptr; } + static bool poisoned(JSFunction *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSFunction *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSFunction **vp) { + JS::HeapCellPostBarrier(reinterpret_cast(vp)); + } + static void relocate(JSFunction **vp) { + JS::HeapCellRelocate(reinterpret_cast(vp)); + } +#endif +}; + +#ifdef JS_DEBUG /* This helper allows us to assert that Rooted is scoped within a request. */ extern JS_PUBLIC_API(bool) IsInRequest(JSContext *cx); @@ -673,22 +724,24 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase template void init(CX *cx) { #ifdef JSGC_TRACK_EXACT_ROOTS - js::ThingRootKind kind = js::GCMethods::kind(); + js::ThingRootKind kind = js::RootKind::rootKind(); this->stack = &cx->thingGCRooters[kind]; this->prev = *stack; *stack = reinterpret_cast*>(this); - JS_ASSERT(!js::GCMethods::poisoned(ptr)); + MOZ_ASSERT(!js::GCMethods::poisoned(ptr)); #endif } public: - Rooted(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG MOZ_ASSERT(js::IsInRequest(cx)); +#endif init(js::ContextFriendFields::get(cx)); } @@ -697,12 +750,14 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase : ptr(initial) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG MOZ_ASSERT(js::IsInRequest(cx)); +#endif init(js::ContextFriendFields::get(cx)); } - Rooted(js::ContextFriendFields *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(js::ContextFriendFields *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -717,8 +772,8 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase init(cx); } - Rooted(js::PerThreadDataFriendFields *pt - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(js::PerThreadDataFriendFields *pt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -733,8 +788,8 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase init(pt); } - Rooted(JSRuntime *rt - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(JSRuntime *rt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -754,13 +809,13 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase // using MSVC, see bug 915735 for more details. #ifdef JSGC_TRACK_EXACT_ROOTS ~Rooted() { - JS_ASSERT(*stack == reinterpret_cast*>(this)); + MOZ_ASSERT(*stack == reinterpret_cast*>(this)); *stack = prev; } #endif #ifdef JSGC_TRACK_EXACT_ROOTS - Rooted *previous() { return prev; } + Rooted *previous() { return reinterpret_cast*>(prev); } #endif /* @@ -775,7 +830,7 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase const T &get() const { return ptr; } T &operator=(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; return ptr; } @@ -786,7 +841,7 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase } void set(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; } @@ -795,16 +850,12 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase private: #ifdef JSGC_TRACK_EXACT_ROOTS - Rooted **stack, *prev; -#endif - -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* Has the rooting analysis ever scanned this Rooted's stack location? */ - friend void JS::CheckStackRoots(JSContext*); -#endif - -#ifdef JSGC_ROOT_ANALYSIS - bool scanned; + /* + * These need to be templated on void* to avoid aliasing issues between, for + * example, Rooted and Rooted, which use the same + * stack head pointer for different classes. + */ + Rooted **stack, *prev; #endif /* @@ -818,90 +869,26 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase Rooted(const Rooted &) MOZ_DELETE; }; -#if !(defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)) -// Defined in vm/String.h. -template <> -class Rooted; -#endif - } /* namespace JS */ namespace js { /* - * Mark a stack location as a root for the rooting analysis, without actually - * rooting it in release builds. This should only be used for stack locations - * of GC things that cannot be relocated by a garbage collection, and that - * are definitely reachable via another path. + * Augment the generic Rooted interface when T = JSObject* with + * class-querying and downcasting operations. + * + * Given a Rooted obj, one can view + * Handle h = obj.as(); + * as an optimization of + * Rooted rooted(cx, &obj->as()); + * Handle h = rooted; */ -class SkipRoot +template <> +class RootedBase { -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - - SkipRoot **stack, *prev; - const uint8_t *start; - const uint8_t *end; - - template - void init(CX *cx, const T *ptr, size_t count) { - SkipRoot **head = &cx->skipGCRooters; - this->stack = head; - this->prev = *stack; - *stack = this; - this->start = (const uint8_t *) ptr; - this->end = this->start + (sizeof(T) * count); - } - public: - ~SkipRoot() { - JS_ASSERT(*stack == this); - *stack = prev; - } - - SkipRoot *previous() { return prev; } - - bool contains(const uint8_t *v, size_t len) { - return v >= start && v + len <= end; - } - -#else /* DEBUG && JSGC_ROOT_ANALYSIS */ - - template - void init(js::ContextFriendFields *cx, const T *ptr, size_t count) {} - - public: - ~SkipRoot() { - // An empty destructor is needed to avoid warnings from clang about - // unused local variables of this type. - } - -#endif /* DEBUG && JSGC_ROOT_ANALYSIS */ - - template - SkipRoot(JSContext *cx, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(ContextFriendFields::get(cx), ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - template - SkipRoot(ContextFriendFields *cx, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(cx, ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - template - SkipRoot(PerThreadData *pt, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(PerThreadDataFriendFields::get(pt), ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + template + JS::Handle as() const; }; /* Interface substitute for Rooted which does not root the variable's memory. */ @@ -933,13 +920,13 @@ class FakeRooted : public RootedBase const T &get() const { return ptr; } FakeRooted &operator=(T value) { - JS_ASSERT(!GCMethods::poisoned(value)); + MOZ_ASSERT(!GCMethods::poisoned(value)); ptr = value; return *this; } FakeRooted &operator=(const FakeRooted &other) { - JS_ASSERT(!GCMethods::poisoned(other.ptr)); + MOZ_ASSERT(!GCMethods::poisoned(other.ptr)); ptr = other.ptr; return *this; } @@ -960,16 +947,16 @@ template class FakeMutableHandle : public js::MutableHandleBase { public: - FakeMutableHandle(T *t) { + MOZ_IMPLICIT FakeMutableHandle(T *t) { ptr = t; } - FakeMutableHandle(FakeRooted *root) { + MOZ_IMPLICIT FakeMutableHandle(FakeRooted *root) { ptr = root->address(); } void set(T v) { - JS_ASSERT(!js::GCMethods::poisoned(v)); + MOZ_ASSERT(!js::GCMethods::poisoned(v)); *ptr = v; } @@ -992,7 +979,7 @@ class FakeMutableHandle : public js::MutableHandleBase /* * Types for a variable that either should or shouldn't be rooted, depending on - * the template parameter Rooted. Used for implementing functions that can + * the template parameter allowGC. Used for implementing functions that can * operate on either rooted or unrooted data. * * The toHandle() and toMutableHandle() functions are for calling functions @@ -1031,12 +1018,12 @@ template class MaybeRooted typedef FakeRooted RootType; typedef FakeMutableHandle MutableHandleType; - static inline JS::Handle toHandle(HandleType v) { - MOZ_ASSUME_UNREACHABLE("Bad conversion"); + static JS::Handle toHandle(HandleType v) { + MOZ_CRASH("Bad conversion"); } - static inline JS::MutableHandle toMutableHandle(MutableHandleType v) { - MOZ_ASSUME_UNREACHABLE("Bad conversion"); + static JS::MutableHandle toMutableHandle(MutableHandleType v) { + MOZ_CRASH("Bad conversion"); } }; @@ -1086,7 +1073,6 @@ MutableHandle::MutableHandle(PersistentRooted *root) ptr = root->address(); } - /* * A copyable, assignable global GC root type with arbitrary lifetime, an * infallible constructor, and automatic unrooting on destruction. @@ -1120,9 +1106,11 @@ MutableHandle::MutableHandle(PersistentRooted *root) * marked when the object itself is marked. */ template -class PersistentRooted : public mozilla::LinkedListElement > { - typedef mozilla::LinkedList List; - typedef mozilla::LinkedListElement Element; +class PersistentRooted : private mozilla::LinkedListElement > { + friend class mozilla::LinkedList; + friend class mozilla::LinkedListElement; + + friend struct js::gc::PersistentRootedMarker; void registerWithRuntime(JSRuntime *rt) { JS::shadow::Runtime *srt = JS::shadow::Runtime::asShadowRuntime(rt); @@ -1130,7 +1118,7 @@ class PersistentRooted : public mozilla::LinkedListElement > } public: - PersistentRooted(JSContext *cx) : ptr(js::GCMethods::initial()) + explicit PersistentRooted(JSContext *cx) : ptr(js::GCMethods::initial()) { registerWithRuntime(js::GetRuntime(cx)); } @@ -1140,7 +1128,7 @@ class PersistentRooted : public mozilla::LinkedListElement > registerWithRuntime(js::GetRuntime(cx)); } - PersistentRooted(JSRuntime *rt) : ptr(js::GCMethods::initial()) + explicit PersistentRooted(JSRuntime *rt) : ptr(js::GCMethods::initial()) { registerWithRuntime(rt); } @@ -1150,14 +1138,19 @@ class PersistentRooted : public mozilla::LinkedListElement > registerWithRuntime(rt); } - PersistentRooted(PersistentRooted &rhs) : ptr(rhs.ptr) + PersistentRooted(const PersistentRooted &rhs) + : mozilla::LinkedListElement >(), + ptr(rhs.ptr) { /* * Copy construction takes advantage of the fact that the original * is already inserted, and simply adds itself to whatever list the * original was on - no JSRuntime pointer needed. + * + * This requires mutating rhs's links, but those should be 'mutable' + * anyway. C++ doesn't let us declare mutable base classes. */ - rhs.setNext(this); + const_cast(rhs).setNext(this); } /* @@ -1172,7 +1165,7 @@ class PersistentRooted : public mozilla::LinkedListElement > const T &get() const { return ptr; } T &operator=(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; return ptr; } @@ -1183,7 +1176,7 @@ class PersistentRooted : public mozilla::LinkedListElement > } void set(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; } @@ -1194,26 +1187,56 @@ class PersistentRooted : public mozilla::LinkedListElement > T ptr; }; +class JS_PUBLIC_API(ObjectPtr) +{ + Heap value; + + public: + ObjectPtr() : value(nullptr) {} + + explicit ObjectPtr(JSObject *obj) : value(obj) {} + + /* Always call finalize before the destructor. */ + ~ObjectPtr() { MOZ_ASSERT(!value); } + + void finalize(JSRuntime *rt) { + if (IsIncrementalBarrierNeeded(rt)) + IncrementalObjectBarrier(value); + value = nullptr; + } + + void init(JSObject *obj) { value = obj; } + + JSObject *get() const { return value; } + + void writeBarrierPre(JSRuntime *rt) { + IncrementalObjectBarrier(value); + } + + bool isAboutToBeFinalized(); + + ObjectPtr &operator=(JSObject *obj) { + IncrementalObjectBarrier(value); + value = obj; + return *this; + } + + void trace(JSTracer *trc, const char *name); + + JSObject &operator*() const { return *value; } + JSObject *operator->() const { return value; } + operator JSObject *() const { return value; } +}; + } /* namespace JS */ namespace js { -/* - * Hook for dynamic root analysis. Checks the native stack and poisons - * references to GC things which have not been rooted. - */ -inline void MaybeCheckStackRoots(JSContext *cx) -{ -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - JS::CheckStackRoots(cx); -#endif -} - /* Base class for automatic read-only object rooting during compilation. */ class CompilerRootNode { protected: - CompilerRootNode(js::gc::Cell *ptr) : next(nullptr), ptr_(ptr) {} + explicit CompilerRootNode(js::gc::Cell *ptr) : next(nullptr), ptr_(ptr) {} public: void **address() { return (void **)&ptr_; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/SliceBudget.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/SliceBudget.h index ccade643b3..7c602c5572 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/SliceBudget.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/SliceBudget.h @@ -32,11 +32,11 @@ struct JS_PUBLIC_API(SliceBudget) SliceBudget(); /* Instantiate as SliceBudget(Time/WorkBudget(n)). */ - SliceBudget(int64_t budget); + explicit SliceBudget(int64_t budget); void reset() { - deadline = INT64_MAX; - counter = INTPTR_MAX; + deadline = unlimitedDeadline; + counter = unlimitedStartCounter; } void step(intptr_t amt = 1) { @@ -50,6 +50,15 @@ struct JS_PUBLIC_API(SliceBudget) return false; return checkOverBudget(); } + + bool isUnlimited() { + return deadline == unlimitedDeadline; + } + +private: + static const int64_t unlimitedDeadline = INT64_MAX; + static const intptr_t unlimitedStartCounter = INTPTR_MAX; + }; } // namespace js diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/StructuredClone.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/StructuredClone.h index d32bdd8dd6..fa48ce045a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/StructuredClone.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/StructuredClone.h @@ -23,6 +23,35 @@ struct JSStructuredCloneWriter; // API for the HTML5 internal structured cloning algorithm. +namespace JS { +enum TransferableOwnership { + // Transferable data has not been filled in yet + SCTAG_TMO_UNFILLED = 0, + + // Structured clone buffer does not yet own the data + SCTAG_TMO_UNOWNED = 1, + + // All values at least this large are owned by the clone buffer + SCTAG_TMO_FIRST_OWNED = 2, + + // Data is a pointer that can be freed + SCTAG_TMO_ALLOC_DATA = 2, + + // Data is a SharedArrayBufferObject's buffer + SCTAG_TMO_SHARED_BUFFER = 3, + + // Data is a memory mapped pointer + SCTAG_TMO_MAPPED_DATA = 4, + + // Data is embedding-specific. The engine can free it by calling the + // freeTransfer op. The embedding can also use SCTAG_TMO_USER_MIN and + // greater, up to 32 bits, to distinguish specific ownership variants. + SCTAG_TMO_CUSTOM = 5, + + SCTAG_TMO_USER_MIN +}; +} /* namespace JS */ + // Read structured data from the reader r. This hook is used to read a value // previously serialized by a call to the WriteStructuredCloneOp hook. // @@ -43,22 +72,64 @@ typedef JSObject *(*ReadStructuredCloneOp)(JSContext *cx, JSStructuredCloneReade // // Return true on success, false on error/exception. typedef bool (*WriteStructuredCloneOp)(JSContext *cx, JSStructuredCloneWriter *w, - JS::Handle obj, void *closure); + JS::HandleObject obj, void *closure); // This is called when JS_WriteStructuredClone is given an invalid transferable. // To follow HTML5, the application must throw a DATA_CLONE_ERR DOMException // with error set to one of the JS_SCERR_* values. typedef void (*StructuredCloneErrorOp)(JSContext *cx, uint32_t errorid); +// This is called when JS_ReadStructuredClone receives a transferable object +// not known to the engine. If this hook does not exist or returns false, the +// JS engine calls the reportError op if set, otherwise it throws a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback and must return a non-null object in returnObject on success. +typedef bool (*ReadTransferStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r, + uint32_t tag, void *content, uint64_t extraData, + void *closure, + JS::MutableHandleObject returnObject); + +// Called when JS_WriteStructuredClone receives a transferable object not +// handled by the engine. If this hook does not exist or returns false, the JS +// engine will call the reportError hook or fall back to throwing a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback. +// +// tag: indicates what type of transferable this is. Must be greater than +// 0xFFFF0201 (value of the internal SCTAG_TRANSFER_MAP_PENDING_ENTRY) +// +// ownership: see TransferableOwnership, above. Used to communicate any needed +// ownership info to the FreeTransferStructuredCloneOp. +// +// content, extraData: what the ReadTransferStructuredCloneOp will receive +// +typedef bool (*TransferStructuredCloneOp)(JSContext *cx, + JS::Handle obj, + void *closure, + // Output: + uint32_t *tag, + JS::TransferableOwnership *ownership, + void **content, + uint64_t *extraData); + +// Called when JS_ClearStructuredClone has to free an unknown transferable +// object. Note that it should never trigger a garbage collection (and will +// assert in a debug build if it does.) +typedef void (*FreeTransferStructuredCloneOp)(uint32_t tag, JS::TransferableOwnership ownership, + void *content, uint64_t extraData, void *closure); + // The maximum supported structured-clone serialization format version. Note // that this does not need to be bumped for Transferable-only changes, since // they are never saved to persistent storage. -#define JS_STRUCTURED_CLONE_VERSION 2 +#define JS_STRUCTURED_CLONE_VERSION 4 struct JSStructuredCloneCallbacks { ReadStructuredCloneOp read; WriteStructuredCloneOp write; StructuredCloneErrorOp reportError; + ReadTransferStructuredCloneOp readTransfer; + TransferStructuredCloneOp writeTransfer; + FreeTransferStructuredCloneOp freeTransfer; }; // Note: if the *data contains transferable objects, it can be read only once. @@ -68,14 +139,16 @@ JS_ReadStructuredClone(JSContext *cx, uint64_t *data, size_t nbytes, uint32_t ve const JSStructuredCloneCallbacks *optionalCallbacks, void *closure); // Note: On success, the caller is responsible for calling -// JS_ClearStructuredClone(*datap, nbytesp). +// JS_ClearStructuredClone(*datap, nbytes, optionalCallbacks, closure). JS_PUBLIC_API(bool) JS_WriteStructuredClone(JSContext *cx, JS::HandleValue v, uint64_t **datap, size_t *nbytesp, const JSStructuredCloneCallbacks *optionalCallbacks, void *closure, JS::HandleValue transferable); JS_PUBLIC_API(bool) -JS_ClearStructuredClone(const uint64_t *data, size_t nbytes); +JS_ClearStructuredClone(uint64_t *data, size_t nbytes, + const JSStructuredCloneCallbacks *optionalCallbacks, + void *closure); JS_PUBLIC_API(bool) JS_StructuredCloneHasTransferables(const uint64_t *data, size_t nbytes, bool *hasTransferable); @@ -89,10 +162,22 @@ class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) { uint64_t *data_; size_t nbytes_; uint32_t version_; + const JSStructuredCloneCallbacks *callbacks_; + void *closure_; public: JSAutoStructuredCloneBuffer() - : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION) {} + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(nullptr), closure_(nullptr) + {} + + JSAutoStructuredCloneBuffer(const JSStructuredCloneCallbacks *callbacks, void *closure) + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(callbacks), closure_(closure) + {} + + JSAutoStructuredCloneBuffer(JSAutoStructuredCloneBuffer &&other); + JSAutoStructuredCloneBuffer &operator=(JSAutoStructuredCloneBuffer &&other); ~JSAutoStructuredCloneBuffer() { clear(); } @@ -123,13 +208,10 @@ class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) { bool write(JSContext *cx, JS::HandleValue v, JS::HandleValue transferable, const JSStructuredCloneCallbacks *optionalCallbacks=nullptr, void *closure=nullptr); - // Swap ownership with another JSAutoStructuredCloneBuffer. - void swap(JSAutoStructuredCloneBuffer &other); - private: // Copy and assignment are not supported. - JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other); - JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other); + JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; + JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; }; // The range of tag values the application may use for its own custom object types. @@ -149,7 +231,7 @@ JS_PUBLIC_API(bool) JS_ReadBytes(JSStructuredCloneReader *r, void *p, size_t len); JS_PUBLIC_API(bool) -JS_ReadTypedArray(JSStructuredCloneReader *r, JS::Value *vp); +JS_ReadTypedArray(JSStructuredCloneReader *r, JS::MutableHandleValue vp); JS_PUBLIC_API(bool) JS_WriteUint32Pair(JSStructuredCloneWriter *w, uint32_t tag, uint32_t data); @@ -158,6 +240,6 @@ JS_PUBLIC_API(bool) JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len); JS_PUBLIC_API(bool) -JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::Value v); +JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::HandleValue v); #endif /* js_StructuredClone_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/Tracer.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/TracingAPI.h similarity index 53% rename from frameworks/js-bindings/external/spidermonkey/include/android/js/Tracer.h rename to frameworks/js-bindings/external/spidermonkey/include/android/js/TracingAPI.h index 89994612f6..3c7fdbe1b1 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/Tracer.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/TracingAPI.h @@ -4,14 +4,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef js_Tracer_h -#define js_Tracer_h +#ifndef js_TracingAPI_h +#define js_TracingAPI_h #include "mozilla/NullPtr.h" - + #include "jspubtd.h" -struct JSTracer; +class JS_PUBLIC_API(JSTracer); namespace JS { template class Heap; @@ -46,74 +46,101 @@ enum WeakMapTraceKind { TraceWeakMapKeysValues = 2 }; -struct JSTracer { - JSRuntime *runtime; - JSTraceCallback callback; - JSTraceNamePrinter debugPrinter; - const void *debugPrintArg; - size_t debugPrintIndex; - WeakMapTraceKind eagerlyTraceWeakMaps; -#ifdef JS_GC_ZEAL - void *realLocation; -#endif -}; +class JS_PUBLIC_API(JSTracer) +{ + public: + JSTracer(JSRuntime *rt, JSTraceCallback traceCallback, + WeakMapTraceKind weakTraceKind = TraceWeakMapValues); + + // Set debugging information about a reference to a traceable thing to prepare + // for the following call to JS_CallTracer. + // + // When printer is null, arg must be const char * or char * C string naming + // the reference and index must be either (size_t)-1 indicating that the name + // alone describes the reference or it must be an index into some array vector + // that stores the reference. + // + // When printer callback is not null, the arg and index arguments are + // available to the callback as debugPrintArg_ and debugPrintIndex_ fields + // of JSTracer. + // + // The storage for name or callback's arguments needs to live only until + // the following call to JS_CallTracer returns. + void setTracingDetails(JSTraceNamePrinter printer, const void *arg, size_t index) { + debugPrinter_ = printer; + debugPrintArg_ = arg; + debugPrintIndex_ = index; + } + + void setTracingIndex(const char *name, size_t index) { + setTracingDetails(nullptr, (void *)name, index); + } + + void setTracingName(const char *name) { + setTracingDetails(nullptr, (void *)name, size_t(-1)); + } + + // Remove the currently set tracing details. + void clearTracingDetails() { + debugPrinter_ = nullptr; + debugPrintArg_ = nullptr; + } + + // Return true if tracing details are currently set. + bool hasTracingDetails() const; + + // Get the string set with the most recent call to setTracingName or return + // fallback if a name printer function has been installed. + const char *tracingName(const char *fallback) const; + + // Build a description of this edge in the heap graph. This call may invoke + // the debug printer, which may inspect arbitrary areas of the heap. + const char *getTracingEdgeName(char *buffer, size_t bufferSize); + + // Access the currently active tracing details. + JSTraceNamePrinter debugPrinter() const; + const void *debugPrintArg() const; + size_t debugPrintIndex() const; + + // Return the runtime set on the tracer. + JSRuntime *runtime() const { return runtime_; } + + // Return the weak map tracing behavior set on this tracer. + WeakMapTraceKind eagerlyTraceWeakMaps() const { return eagerlyTraceWeakMaps_; } + + // Update the trace callback. + void setTraceCallback(JSTraceCallback traceCallback); -// Set debugging information about a reference to a traceable thing to prepare -// for the following call to JS_CallTracer. -// -// When printer is null, arg must be const char * or char * C string naming -// the reference and index must be either (size_t)-1 indicating that the name -// alone describes the reference or it must be an index into some array vector -// that stores the reference. -// -// When printer callback is not null, the arg and index arguments are -// available to the callback as debugPrintArg and debugPrintIndex fields -// of JSTracer. -// -// The storage for name or callback's arguments needs to live only until -// the following call to JS_CallTracer returns. -// -# define JS_SET_TRACING_DETAILS(trc, printer, arg, index) \ - JS_BEGIN_MACRO \ - (trc)->debugPrinter = (printer); \ - (trc)->debugPrintArg = (arg); \ - (trc)->debugPrintIndex = (index); \ - JS_END_MACRO - -// Sets the real location for a marked reference, when passing the address -// directly is not feasable. -// -// FIXME: This is currently overcomplicated by our need to nest calls for Values -// stored as keys in hash tables, but will get simplified once we can rekey -// in-place. -// #ifdef JS_GC_ZEAL -# define JS_SET_TRACING_LOCATION(trc, location) \ - JS_BEGIN_MACRO \ - if (!(trc)->realLocation || !(location)) \ - (trc)->realLocation = (location); \ - JS_END_MACRO -# define JS_UNSET_TRACING_LOCATION(trc) \ - JS_BEGIN_MACRO \ - (trc)->realLocation = nullptr; \ - JS_END_MACRO + // Sets the "real" location for a marked reference, when passing the address + // directly is not feasable. This address is used for matching against the + // store buffer when verifying the correctness of the entrees there. + // + // This is currently complicated by our need to nest calls for Values + // stored as keys in hash tables. + void setTracingLocation(void *location); + void unsetTracingLocation(); + void **tracingLocation(void **thingp); #else -# define JS_SET_TRACING_LOCATION(trc, location) \ - JS_BEGIN_MACRO \ - JS_END_MACRO -# define JS_UNSET_TRACING_LOCATION(trc) \ - JS_BEGIN_MACRO \ - JS_END_MACRO + void setTracingLocation(void *location) {} + void unsetTracingLocation() {} + void **tracingLocation(void **thingp) { return nullptr; } #endif -// Convenience macro to describe the argument of JS_CallTracer using C string -// and index. -# define JS_SET_TRACING_INDEX(trc, name, index) \ - JS_SET_TRACING_DETAILS(trc, nullptr, name, index) + // We expose |callback| directly so that IS_GC_MARKING_TRACER can compare + // it to GCMarker::GrayCallback. + JSTraceCallback callback; -// Convenience macro to describe the argument of JS_CallTracer using C string. -# define JS_SET_TRACING_NAME(trc, name) \ - JS_SET_TRACING_DETAILS(trc, nullptr, name, (size_t)-1) + private: + JSRuntime *runtime_; + JSTraceNamePrinter debugPrinter_; + const void *debugPrintArg_; + size_t debugPrintIndex_; + WeakMapTraceKind eagerlyTraceWeakMaps_; +#ifdef JS_GC_ZEAL + void *realLocation_; +#endif +}; // The JS_Call*Tracer family of functions traces the given GC thing reference. // This performs the tracing action configured on the given JSTracer: @@ -157,12 +184,15 @@ JS_CallHeapStringTracer(JSTracer *trc, JS::Heap *strp, const char *n extern JS_PUBLIC_API(void) JS_CallHeapScriptTracer(JSTracer *trc, JS::Heap *scriptp, const char *name); +extern JS_PUBLIC_API(void) +JS_CallHeapFunctionTracer(JSTracer *trc, JS::Heap *funp, const char *name); + template inline void JS_CallHashSetObjectTracer(JSTracer *trc, HashSetEnum &e, JSObject *const &key, const char *name) { JSObject *updated = key; - JS_SET_TRACING_LOCATION(trc, reinterpret_cast(&const_cast(key))); + trc->setTracingLocation(reinterpret_cast(&const_cast(key))); JS_CallObjectTracer(trc, &updated, name); if (updated != key) e.rekeyFront(key, updated); @@ -173,10 +203,6 @@ JS_CallHashSetObjectTracer(JSTracer *trc, HashSetEnum &e, JSObject *const &key, extern JS_PUBLIC_API(void) JS_CallTenuredObjectTracer(JSTracer *trc, JS::TenuredHeap *objp, const char *name); -// API for JSTraceCallback implementations. -extern JS_PUBLIC_API(void) -JS_TracerInit(JSTracer *trc, JSRuntime *rt, JSTraceCallback callback); - extern JS_PUBLIC_API(void) JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind); @@ -187,7 +213,4 @@ extern JS_PUBLIC_API(void) JS_GetTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc, void *thing, JSGCTraceKind kind, bool includeDetails); -extern JS_PUBLIC_API(const char *) -JS_GetTraceEdgeName(JSTracer *trc, char *buffer, int bufferSize); - -#endif /* js_Tracer_h */ +#endif /* js_TracingAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/TypeDecls.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/TypeDecls.h index 027d7b8fb7..3e1e8afc66 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/TypeDecls.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/TypeDecls.h @@ -20,44 +20,24 @@ #include #include +#include "js-config.h" + struct JSContext; class JSFunction; class JSObject; class JSScript; class JSString; +class JSAddonId; -// In release builds, jsid is defined to be an integral type. This -// prevents many bugs from being caught at compile time. E.g.: -// -// jsid id = ... -// if (id) // error -// ... -// -// size_t n = id; // error -// -// To catch more errors, jsid is given a struct type in C++ debug builds. -// Struct assignment and (in C++) operator== allow correct code to be mostly -// oblivious to the change. This feature can be explicitly disabled in debug -// builds by defining JS_NO_JSVAL_JSID_STRUCT_TYPES. -// - -// Needed for cocos2d-js -#define JS_NO_JSVAL_JSID_STRUCT_TYPES - -#if defined(DEBUG) && !defined(JS_NO_JSVAL_JSID_STRUCT_TYPES) -# define JS_USE_JSID_STRUCT_TYPES -#endif - -#ifdef JS_USE_JSID_STRUCT_TYPES struct jsid; -#else -typedef ptrdiff_t jsid; -#endif typedef char16_t jschar; namespace JS { +typedef unsigned char Latin1Char; + +class Symbol; class Value; template class Handle; template class MutableHandle; @@ -69,6 +49,7 @@ typedef Handle HandleId; typedef Handle HandleObject; typedef Handle HandleScript; typedef Handle HandleString; +typedef Handle HandleSymbol; typedef Handle HandleValue; typedef MutableHandle MutableHandleFunction; @@ -76,12 +57,14 @@ typedef MutableHandle MutableHandleId; typedef MutableHandle MutableHandleObject; typedef MutableHandle MutableHandleScript; typedef MutableHandle MutableHandleString; +typedef MutableHandle MutableHandleSymbol; typedef MutableHandle MutableHandleValue; typedef Rooted RootedObject; typedef Rooted RootedFunction; typedef Rooted RootedScript; typedef Rooted RootedString; +typedef Rooted RootedSymbol; typedef Rooted RootedId; typedef Rooted RootedValue; @@ -90,6 +73,7 @@ typedef PersistentRooted PersistentRootedId; typedef PersistentRooted PersistentRootedObject; typedef PersistentRooted PersistentRootedScript; typedef PersistentRooted PersistentRootedString; +typedef PersistentRooted PersistentRootedSymbol; typedef PersistentRooted PersistentRootedValue; } // namespace JS diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/UbiNode.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/UbiNode.h new file mode 100644 index 0000000000..d2acc2e242 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/UbiNode.h @@ -0,0 +1,462 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_UbiNode_h +#define js_UbiNode_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" + +#include "jspubtd.h" + +#include "js/GCAPI.h" +#include "js/HashTable.h" +#include "js/TypeDecls.h" + +// JS::ubi::Node +// +// JS::ubi::Node is a pointer-like type designed for internal use by heap +// analysis tools. A ubi::Node can refer to: +// +// - a JS value, like a string or object; +// - an internal SpiderMonkey structure, like a shape or a scope chain object +// - an instance of some embedding-provided type: in Firefox, an XPCOM +// object, or an internal DOM node class instance +// +// A ubi::Node instance provides metadata about its referent, and can +// enumerate its referent's outgoing edges, so you can implement heap analysis +// algorithms that walk the graph - finding paths between objects, or +// computing heap dominator trees, say - using ubi::Node, while remaining +// ignorant of the details of the types you're operating on. +// +// Of course, when it comes to presenting the results in a developer-facing +// tool, you'll need to stop being ignorant of those details, because you have +// to discuss the ubi::Nodes' referents with the developer. Here, ubi::Node +// can hand you dynamically checked, properly typed pointers to the original +// objects via the as method, or generate descriptions of the referent +// itself. +// +// ubi::Node instances are lightweight (two-word) value types. Instances: +// - compare equal if and only if they refer to the same object; +// - have hash values that respect their equality relation; and +// - have serializations that are only equal if the ubi::Nodes are equal. +// +// A ubi::Node is only valid for as long as its referent is alive; if its +// referent goes away, the ubi::Node becomes a dangling pointer. A ubi::Node +// that refers to a GC-managed object is not automatically a GC root; if the +// GC frees or relocates its referent, the ubi::Node becomes invalid. A +// ubi::Node that refers to a reference-counted object does not bump the +// reference count. +// +// ubi::Node values require no supporting data structures, making them +// feasible for use in memory-constrained devices --- ideally, the memory +// requirements of the algorithm which uses them will be the limiting factor, +// not the demands of ubi::Node itself. +// +// One can construct a ubi::Node value given a pointer to a type that ubi::Node +// supports. In the other direction, one can convert a ubi::Node back to a +// pointer; these downcasts are checked dynamically. In particular, one can +// convert a 'JSRuntime *' to a ubi::Node, yielding a node with an outgoing edge +// for every root registered with the runtime; starting from this, one can walk +// the entire heap. (Of course, one could also start traversal at any other kind +// of type to which one has a pointer.) +// +// +// Extending ubi::Node To Handle Your Embedding's Types +// +// To add support for a new ubi::Node referent type R, you must define a +// specialization of the ubi::Concrete template, ubi::Concrete, which +// inherits from ubi::Base. ubi::Node itself uses the specialization for +// compile-time information (i.e. the checked conversions between R * and +// ubi::Node), and the inheritance for run-time dispatching. +// +// +// ubi::Node Exposes Implementation Details +// +// In many cases, a JavaScript developer's view of their data differs +// substantially from its actual implementation. For example, while the +// ECMAScript specification describes objects as maps from property names to +// sets of attributes (like ECMAScript's [[Value]]), in practice many objects +// have only a pointer to a shape, shared with other similar objects, and +// indexed slots that contain the [[Value]] attributes. As another example, a +// string produced by concatenating two other strings may sometimes be +// represented by a "rope", a structure that points to the two original +// strings. +// + +// We intend to use ubi::Node to write tools that report memory usage, so it's +// important that ubi::Node accurately portray how much memory nodes consume. +// Thus, for example, when data that apparently belongs to multiple nodes is +// in fact shared in a common structure, ubi::Node's graph uses a separate +// node for that shared structure, and presents edges to it from the data's +// apparent owners. For example, ubi::Node exposes SpiderMonkey objects' +// shapes and base shapes, and exposes rope string and substring structure, +// because these optimizations become visible when a tool reports how much +// memory a structure consumes. +// +// However, fine granularity is not a goal. When a particular object is the +// exclusive owner of a separate block of memory, ubi::Node may present the +// object and its block as a single node, and add their sizes together when +// reporting the node's size, as there is no meaningful loss of data in this +// case. Thus, for example, a ubi::Node referring to a JavaScript object, when +// asked for the object's size in bytes, includes the object's slot and +// element arrays' sizes in the total. There is no separate ubi::Node value +// representing the slot and element arrays, since they are owned exclusively +// by the object. +// +// +// Presenting Analysis Results To JavaScript Developers +// +// If an analysis provides its results in terms of ubi::Node values, a user +// interface presenting those results will generally need to clean them up +// before they can be understood by JavaScript developers. For example, +// JavaScript developers should not need to understand shapes, only JavaScript +// objects. Similarly, they should not need to understand the distinction +// between DOM nodes and the JavaScript shadow objects that represent them. +// +// +// Rooting Restrictions +// +// At present there is no way to root ubi::Node instances, so instances can't be +// live across any operation that might GC. Analyses using ubi::Node must either +// run to completion and convert their results to some other rootable type, or +// save their intermediate state in some rooted structure if they must GC before +// they complete. (For algorithms like path-finding and dominator tree +// computation, we implement the algorithm avoiding any operation that could +// cause a GC --- and use AutoCheckCannotGC to verify this.) +// +// If this restriction prevents us from implementing interesting tools, we may +// teach the GC how to root ubi::Nodes, fix up hash tables that use them as +// keys, etc. + + +// Forward declarations of SpiderMonkey's ubi::Node reference types. +namespace js { +class LazyScript; +class Shape; +class BaseShape; +namespace jit { +class JitCode; +} +namespace types { +struct TypeObject; +} +} + + +namespace JS { +namespace ubi { + +class Edge; +class EdgeRange; + +// The base class implemented by each ubi::Node referent type. Subclasses must +// not add data members to this class. +class Base { + friend class Node; + + // For performance's sake, we'd prefer to avoid a virtual destructor; and + // an empty constructor seems consistent with the 'lightweight value type' + // visible behavior we're trying to achieve. But if the destructor isn't + // virtual, and a subclass overrides it, the subclass's destructor will be + // ignored. Is there a way to make the compiler catch that error? + + protected: + // Space for the actual pointer. Concrete subclasses should define a + // properly typed 'get' member function to access this. + void *ptr; + + Base(void *ptr) : ptr(ptr) { } + + public: + bool operator==(const Base &rhs) const { + // Some compilers will indeed place objects of different types at + // the same address, so technically, we should include the vtable + // in this comparison. But it seems unlikely to cause problems in + // practice. + return ptr == rhs.ptr; + } + bool operator!=(const Base &rhs) const { return !(*this == rhs); } + + // Return a human-readable name for the referent's type. The result should + // be statically allocated. (You can use MOZ_UTF16("strings") for this.) + // + // This must always return Concrete::concreteTypeName; we use that + // pointer as a tag for this particular referent type. + virtual const jschar *typeName() const = 0; + + // Return the size of this node, in bytes. Include any structures that this + // node owns exclusively that are not exposed as their own ubi::Nodes. + virtual size_t size() const = 0; + + // Return an EdgeRange that initially contains all the referent's outgoing + // edges. The EdgeRange should be freed with 'js_delete'. (You could use + // ScopedDJSeletePtr to manage it.) On OOM, report an exception + // on |cx| and return nullptr. + virtual EdgeRange *edges(JSContext *cx) const = 0; + + private: + Base(const Base &rhs) MOZ_DELETE; + Base &operator=(const Base &rhs) MOZ_DELETE; +}; + +// A traits template with a specialization for each referent type that +// ubi::Node supports. The specialization must be the concrete subclass of +// Base that represents a pointer to the referent type. It must also +// include the members described here. +template +struct Concrete { + // The specific jschar array returned by Concrete::typeName. + static const jschar concreteTypeName[]; + + // Construct an instance of this concrete class in |storage| referring + // to |referent|. Implementations typically use a placement 'new'. + // + // In some cases, |referent| will contain dynamic type information that + // identifies it a some more specific subclass of |Referent|. For example, + // when |Referent| is |JSObject|, then |referent->getClass()| could tell us + // that it's actually a JSFunction. Similarly, if |Referent| is + // |nsISupports|, we would like a ubi::Node that knows its final + // implementation type. + // + // So, we delegate the actual construction to this specialization, which + // knows Referent's details. + static void construct(void *storage, Referent *referent); +}; + +// A container for a Base instance; all members simply forward to the contained instance. +// This container allows us to pass ubi::Node instances by value. +class Node { + // Storage in which we allocate Base subclasses. + mozilla::AlignedStorage2 storage; + Base *base() { return storage.addr(); } + const Base *base() const { return storage.addr(); } + + template + void construct(T *ptr) { + static_assert(sizeof(Concrete) == sizeof(*base()), + "ubi::Base specializations must be the same size as ubi::Base"); + Concrete::construct(base(), ptr); + } + + typedef void (Node::* ConvertibleToBool)(); + void nonNull() {} + + public: + Node() { construct(nullptr); } + + template + Node(T *ptr) { + construct(ptr); + } + template + Node &operator=(T *ptr) { + construct(ptr); + return *this; + } + + // We can construct and assign from rooted forms of pointers. + template + Node(const Rooted &root) { + construct(root.get()); + } + template + Node &operator=(const Rooted &root) { + construct(root.get()); + return *this; + } + + // Constructors accepting SpiderMonkey's other generic-pointer-ish types. + Node(JS::Value value); + Node(JSGCTraceKind kind, void *ptr); + + // copy construction and copy assignment just use memcpy, since we know + // instances contain nothing but a vtable pointer and a data pointer. + // + // To be completely correct, concrete classes could provide a virtual + // 'construct' member function, which we could invoke on rhs to construct an + // instance in our storage. But this is good enough; there's no need to jump + // through vtables for copying and assignment that are just going to move + // two words around. The compiler knows how to optimize memcpy. + Node(const Node &rhs) { + memcpy(storage.u.mBytes, rhs.storage.u.mBytes, sizeof(storage.u)); + } + + Node &operator=(const Node &rhs) { + memcpy(storage.u.mBytes, rhs.storage.u.mBytes, sizeof(storage.u)); + return *this; + } + + bool operator==(const Node &rhs) const { return *base() == *rhs.base(); } + bool operator!=(const Node &rhs) const { return *base() != *rhs.base(); } + + operator ConvertibleToBool() const { + return base()->ptr ? &Node::nonNull : 0; + } + + template + bool is() const { + return base()->typeName() == Concrete::concreteTypeName; + } + + template + T *as() const { + MOZ_ASSERT(is()); + return static_cast(base()->ptr); + } + + template + T *asOrNull() const { + return is() ? static_cast(base()->ptr) : nullptr; + } + + // If this node refers to something that can be represented as a + // JavaScript value that is safe to expose to JavaScript code, return that + // value. Otherwise return UndefinedValue(). JSStrings and some (but not + // all!) JSObjects can be exposed. + JS::Value exposeToJS() const; + + const jschar *typeName() const { return base()->typeName(); } + size_t size() const { return base()->size(); } + EdgeRange *edges(JSContext *cx) const { return base()->edges(cx); } + + // A hash policy for ubi::Nodes. + // This simply uses the stock PointerHasher on the ubi::Node's pointer. + // We specialize DefaultHasher below to make this the default. + class HashPolicy { + typedef js::PointerHasher::value> PtrHash; + + public: + typedef Node Lookup; + + static js::HashNumber hash(const Lookup &l) { return PtrHash::hash(l.base()->ptr); } + static bool match(const Node &k, const Lookup &l) { return k == l; } + static void rekey(Node &k, const Node &newKey) { k = newKey; } + }; +}; + + +// Edge is the abstract base class representing an outgoing edge of a node. +// Edges are owned by EdgeRanges, and need not have assignment operators or copy +// constructors. +// +// Each Edge class should inherit from this base class, overriding as +// appropriate. +class Edge { + protected: + Edge() : name(nullptr), referent() { } + virtual ~Edge() { } + + public: + // This edge's name. + // + // The storage is owned by this Edge, and will be freed when this Edge is + // destructed. + // + // (In real life we'll want a better representation for names, to avoid + // creating tons of strings when the names follow a pattern; and we'll need + // to think about lifetimes carefully to ensure traversal stays cheap.) + const jschar *name; + + // This edge's referent. + Node referent; + + private: + Edge(const Edge &) MOZ_DELETE; + Edge &operator=(const Edge &) MOZ_DELETE; +}; + + +// EdgeRange is an abstract base class for iterating over a node's outgoing +// edges. (This is modeled after js::HashTable::Range.) +// +// Concrete instances of this class need not be as lightweight as Node itself, +// since they're usually only instantiated while iterating over a particular +// object's edges. For example, a dumb implementation for JS Cells might use +// JS_TraceChildren to to get the outgoing edges, and then store them in an +// array internal to the EdgeRange. +class EdgeRange { + protected: + // The current front edge of this range, or nullptr if this range is empty. + Edge *front_; + + EdgeRange() : front_(nullptr) { } + + public: + virtual ~EdgeRange() { }; + + // True if there are no more edges in this range. + bool empty() const { return !front_; } + + // The front edge of this range. This is owned by the EdgeRange, and is + // only guaranteed to live until the next call to popFront, or until + // the EdgeRange is destructed. + const Edge &front() { return *front_; } + + // Remove the front edge from this range. This should only be called if + // !empty(). + virtual void popFront() = 0; + + private: + EdgeRange(const EdgeRange &) MOZ_DELETE; + EdgeRange &operator=(const EdgeRange &) MOZ_DELETE; +}; + + +// Concrete classes for ubi::Node referent types. + +// A reusable ubi::Concrete specialization base class for types supported by +// JS_TraceChildren. +template +class TracerConcrete : public Base { + const jschar *typeName() const MOZ_OVERRIDE { return concreteTypeName; } + size_t size() const MOZ_OVERRIDE { return 0; } // not implemented yet; bug 1011300 + EdgeRange *edges(JSContext *) const MOZ_OVERRIDE; + + TracerConcrete(Referent *ptr) : Base(ptr) { } + + public: + static const jschar concreteTypeName[]; + static void construct(void *storage, Referent *ptr) { new (storage) TracerConcrete(ptr); }; +}; + +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; + +// The ubi::Node null pointer. Any attempt to operate on a null ubi::Node asserts. +template<> +class Concrete : public Base { + const jschar *typeName() const MOZ_OVERRIDE; + size_t size() const MOZ_OVERRIDE; + EdgeRange *edges(JSContext *cx) const MOZ_OVERRIDE; + + Concrete(void *ptr) : Base(ptr) { } + + public: + static void construct(void *storage, void *ptr) { new (storage) Concrete(ptr); } + static const jschar concreteTypeName[]; +}; + + +} // namespace ubi +} // namespace JS + +namespace js { + +// Make ubi::Node::HashPolicy the default hash policy for ubi::Node. +template<> struct DefaultHasher : JS::ubi::Node::HashPolicy { }; + +} // namespace js + +#endif // js_UbiNode_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/UbiNodeTraverse.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/UbiNodeTraverse.h new file mode 100644 index 0000000000..6072cbc489 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/UbiNodeTraverse.h @@ -0,0 +1,208 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_UbiNodeTraverse_h +#define js_UbiNodeTraverse_h + +#include "js/UbiNode.h" +#include "js/Utility.h" +#include "js/Vector.h" + +namespace JS { +namespace ubi { + +// A breadth-first traversal template for graphs of ubi::Nodes. +// +// No GC may occur while an instance of this template is live. +// +// The provided Handler type should have two members: +// +// typename NodeData; +// +// The value type of |BreadthFirst::visited|, the HashMap of +// ubi::Nodes that have been visited so far. Since the algorithm needs a +// hash table like this for its own use anyway, it is simple to let +// Handler store its own metadata about each node in the same table. +// +// For example, if you want to find a shortest path to each node from any +// traversal starting point, your |NodeData| type could record the first +// edge to reach each node, and the node from which it originates. Then, +// when the traversal is complete, you can walk backwards from any node +// to some starting point, and the path recorded will be a shortest path. +// +// This type must have a default constructor. If this type owns any other +// resources, move constructors and assignment operators are probably a +// good idea, too. +// +// bool operator() (BreadthFirst &traversal, +// Node origin, const Edge &edge, +// Handler::NodeData *referentData, bool first); +// +// The visitor function, called to report that we have traversed +// |edge| from |origin|. This is called once for each edge we traverse. +// As this is a breadth-first search, any prior calls to the visitor function +// were for origin nodes not further from the start nodes than |origin|. +// +// |traversal| is this traversal object, passed along for convenience. +// +// |referentData| is a pointer to the value of the entry in +// |traversal.visited| for |edge.referent|; the visitor function can +// store whatever metadata it likes about |edge.referent| there. +// +// |first| is true if this is the first time we have visited an edge +// leading to |edge.referent|. This could be stored in NodeData, but +// the algorithm knows whether it has just created the entry in +// |traversal.visited|, so it passes it along for convenience. +// +// The visitor function may call |traversal.stop()| if it doesn't want +// to visit any more nodes. +// +// The visitor function may consult |traversal.visited| for information +// about other nodes, but it should not add or remove entries. +// +// The visitor function should return true on success, or false if an +// error occurs. A false return value terminates the traversal +// immediately, and causes BreadthFirst::traverse to return +// false. +template +struct BreadthFirst { + + // Construct a breadth-first traversal object that reports the nodes it + // reaches to |handler|. The traversal object reports OOM on |cx|, and + // asserts that no GC happens in |cx|'s runtime during its lifetime. + // + // We do nothing with noGC, other than require it to exist, with a lifetime + // that encloses our own. + BreadthFirst(JSContext *cx, Handler &handler, const JS::AutoCheckCannotGC &noGC) + : cx(cx), visited(cx), handler(handler), pending(cx), + traversalBegun(false), stopRequested(false) + { } + + // Initialize this traversal object. Return false on OOM. + bool init() { return visited.init(); } + + // Add |node| as a starting point for the traversal. You may add + // as many starting points as you like. Return false on OOM. + bool addStart(Node node) { return pending.append(node); } + + // Traverse the graph in breadth-first order, starting at the given + // start nodes, applying |handler::operator()| for each edge traversed + // as described above. + // + // This should be called only once per instance of this class. + // + // Return false on OOM or error return from |handler::operator()|. + bool traverse() + { + MOZ_ASSERT(!traversalBegun); + traversalBegun = true; + + // While there are pending nodes, visit them, until we've found a path to the target. + while (!pending.empty()) { + Node origin = pending.front(); + pending.popFront(); + + // Get a range containing all origin's outgoing edges. + js::ScopedJSDeletePtr range(origin.edges(cx)); + if (!range) + return false; + + // Traverse each edge. + for (; !range->empty(); range->popFront()) { + MOZ_ASSERT(!stopRequested); + + const Edge &edge = range->front(); + typename NodeMap::AddPtr a = visited.lookupForAdd(edge.referent); + bool first = !a; + + if (first) { + // This is the first time we've reached |edge.referent|. + // Create an entry for it in |visited|, and arrange to + // traverse its outgoing edges later. + if (!visited.add(a, edge.referent, typename Handler::NodeData()) || + !pending.append(edge.referent)) { + return false; + } + } + + MOZ_ASSERT(a); + + // Report this edge to the visitor function. + if (!handler(*this, origin, edge, &a->value(), first)) + return false; + + if (stopRequested) + return true; + } + } + + return true; + } + + // Stop traversal, and return true from |traverse| without visiting any + // more nodes. Only |handler::operator()| should call this function; it + // may do so to stop the traversal early, without returning false and + // then making |traverse|'s caller disambiguate that result from a real + // error. + void stop() { stopRequested = true; } + + // The context with which we were constructed. + JSContext *cx; + + // A map associating each node N that we have reached with a + // Handler::NodeData, for |handler|'s use. This is public, so that + // |handler| can access it to see the traversal thus far. + typedef js::HashMap NodeMap; + NodeMap visited; + + private: + // Our handler object. + Handler &handler; + + // A queue template. Appending and popping the front are constant time. + // Wasted space is never more than some recent actual population plus the + // current population. + template + class Queue { + js::Vector head, tail; + size_t frontIndex; + public: + Queue(JSContext *cx) : head(cx), tail(cx), frontIndex(0) { } + bool empty() { return frontIndex >= head.length(); } + T &front() { + MOZ_ASSERT(!empty()); + return head[frontIndex]; + } + void popFront() { + MOZ_ASSERT(!empty()); + frontIndex++; + if (frontIndex >= head.length()) { + head.clearAndFree(); + head.swap(tail); + frontIndex = 0; + } + } + bool append(const T &elt) { + return frontIndex == 0 ? head.append(elt) : tail.append(elt); + } + }; + + // A queue of nodes that we have reached, but whose outgoing edges we + // have not yet traversed. Nodes reachable in fewer edges are enqueued + // earlier. + Queue pending; + + // True if our traverse function has been called. + bool traversalBegun; + + // True if we've been asked to stop the traversal. + bool stopRequested; +}; + +} // namespace ubi +} // namespace JS + +#endif // js_UbiNodeTraverse.h diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/Utility.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/Utility.h index adee3b15d8..89c495e411 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/Utility.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/Utility.h @@ -35,23 +35,22 @@ namespace mozilla {} namespace js {} /* - * Pattern used to overwrite freed memory. If you are accessing an object with - * this pattern, you probably have a dangling pointer. + * Patterns used by SpiderMonkey to overwrite unused memory. If you are + * accessing an object with one of these pattern, you probably have a dangling + * pointer. */ -#define JS_FREE_PATTERN 0xDA +#define JS_FRESH_NURSERY_PATTERN 0x2F +#define JS_SWEPT_NURSERY_PATTERN 0x2B +#define JS_ALLOCATED_NURSERY_PATTERN 0x2D +#define JS_FRESH_TENURED_PATTERN 0x4F +#define JS_SWEPT_TENURED_PATTERN 0x4B +#define JS_ALLOCATED_TENURED_PATTERN 0x4D +#define JS_SWEPT_CODE_PATTERN 0x3b +#define JS_SWEPT_FRAME_PATTERN 0x5b +#define JS_POISONED_FORKJOIN_CHUNK 0xBD #define JS_ASSERT(expr) MOZ_ASSERT(expr) #define JS_ASSERT_IF(cond, expr) MOZ_ASSERT_IF(cond, expr) -#define JS_ALWAYS_TRUE(expr) MOZ_ALWAYS_TRUE(expr) -#define JS_ALWAYS_FALSE(expr) MOZ_ALWAYS_FALSE(expr) - -#if defined(DEBUG) -# define JS_DIAGNOSTICS_ASSERT(expr) MOZ_ASSERT(expr) -#elif defined(JS_CRASH_DIAGNOSTICS) -# define JS_DIAGNOSTICS_ASSERT(expr) do { if (!(expr)) MOZ_CRASH(); } while(0) -#else -# define JS_DIAGNOSTICS_ASSERT(expr) ((void) 0) -#endif #define JS_STATIC_ASSERT(cond) static_assert(cond, "JS_STATIC_ASSERT") #define JS_STATIC_ASSERT_IF(cond, expr) MOZ_STATIC_ASSERT_IF(cond, expr, "JS_STATIC_ASSERT_IF") @@ -59,84 +58,40 @@ namespace js {} extern MOZ_NORETURN JS_PUBLIC_API(void) JS_Assert(const char *s, const char *file, int ln); -/* - * Abort the process in a non-graceful manner. This will cause a core file, - * call to the debugger or other moral equivalent as well as causing the - * entire process to stop. - */ -extern JS_PUBLIC_API(void) JS_Abort(void); - /* * Custom allocator support for SpiderMonkey */ #if defined JS_USE_CUSTOM_ALLOCATOR # include "jscustomallocator.h" #else -# ifdef DEBUG +# if defined(DEBUG) || defined(JS_OOM_BREAKPOINT) /* * In order to test OOM conditions, when the testing function * oomAfterAllocations COUNT is passed, we fail continuously after the NUM'th * allocation from now. */ -extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtins/TestingFunctions.cpp */ +extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtin/TestingFunctions.cpp */ extern JS_PUBLIC_DATA(uint32_t) OOM_counter; /* data race, who cares. */ -#ifdef JS_OOM_DO_BACKTRACES -#define JS_OOM_BACKTRACE_SIZE 32 -static JS_ALWAYS_INLINE void -PrintBacktrace() -{ - void* OOM_trace[JS_OOM_BACKTRACE_SIZE]; - char** OOM_traceSymbols = nullptr; - int32_t OOM_traceSize = 0; - int32_t OOM_traceIdx = 0; - OOM_traceSize = backtrace(OOM_trace, JS_OOM_BACKTRACE_SIZE); - OOM_traceSymbols = backtrace_symbols(OOM_trace, OOM_traceSize); - - if (!OOM_traceSymbols) - return; - - for (OOM_traceIdx = 0; OOM_traceIdx < OOM_traceSize; ++OOM_traceIdx) { - fprintf(stderr, "#%d %s\n", OOM_traceIdx, OOM_traceSymbols[OOM_traceIdx]); - } - - // This must be free(), not js_free(), because backtrace_symbols() - // allocates with malloc(). - free(OOM_traceSymbols); -} - -#define JS_OOM_EMIT_BACKTRACE() \ - do {\ - fprintf(stderr, "Forcing artificial memory allocation function failure:\n");\ - PrintBacktrace();\ - } while (0) -# else -# define JS_OOM_EMIT_BACKTRACE() do {} while(0) -#endif /* JS_OOM_DO_BACKTRACES */ +#ifdef JS_OOM_BREAKPOINT +static MOZ_NEVER_INLINE void js_failedAllocBreakpoint() { asm(""); } +#define JS_OOM_CALL_BP_FUNC() js_failedAllocBreakpoint() +#else +#define JS_OOM_CALL_BP_FUNC() do {} while(0) +#endif # define JS_OOM_POSSIBLY_FAIL() \ do \ { \ if (++OOM_counter > OOM_maxAllocations) { \ - JS_OOM_EMIT_BACKTRACE();\ - return nullptr; \ - } \ - } while (0) - -# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) \ - do \ - { \ - if (++OOM_counter > OOM_maxAllocations) { \ - JS_OOM_EMIT_BACKTRACE();\ - js_ReportOutOfMemory(cx);\ + JS_OOM_CALL_BP_FUNC();\ return nullptr; \ } \ } while (0) # else # define JS_OOM_POSSIBLY_FAIL() do {} while(0) -# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) do {} while(0) -# endif /* DEBUG */ +# endif /* DEBUG || JS_OOM_BREAKPOINT */ static inline void* js_malloc(size_t bytes) { @@ -168,26 +123,6 @@ static inline void js_free(void* p) } #endif/* JS_USE_CUSTOM_ALLOCATOR */ -/* - * JS_ROTATE_LEFT32 - * - * There is no rotate operation in the C Language so the construct (a << 4) | - * (a >> 28) is used instead. Most compilers convert this to a rotate - * instruction but some versions of MSVC don't without a little help. To get - * MSVC to generate a rotate instruction, we have to use the _rotl intrinsic - * and use a pragma to make _rotl inline. - * - * MSVC in VS2005 will do an inline rotate instruction on the above construct. - */ -#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || \ - defined(_M_X64)) -#include -#pragma intrinsic(_rotl) -#define JS_ROTATE_LEFT32(a, bits) _rotl(a, bits) -#else -#define JS_ROTATE_LEFT32(a, bits) (((a) << (bits)) | ((a) >> (32 - (bits)))) -#endif - #include /* @@ -235,6 +170,9 @@ static inline void js_free(void* p) #define JS_NEW_BODY(allocator, t, parms) \ void *memory = allocator(sizeof(t)); \ return memory ? new(memory) t parms : nullptr; +#define JS_MAKE_BODY(newname, T, parms) \ + T *ptr = newname parms; \ + return mozilla::UniquePtr>(ptr); /* * Given a class which should provide 'new' methods, add @@ -389,10 +327,191 @@ static inline void js_free(void* p) mozilla::Forward(p12)))\ }\ -JS_DECLARE_NEW_METHODS(js_new, js_malloc, static JS_ALWAYS_INLINE) +/* + * Given a class which should provide 'make' methods, add + * JS_DECLARE_MAKE_METHODS (see JSContext for a usage example). This method + * is functionally the same as JS_DECLARE_NEW_METHODS: it just declares methods + * that return mozilla::UniquePtr instances that will singly-manage ownership + * of the created object. This adds makes with up to 12 parameters. Add more + * versions below if you need more than 12 parameters. + * + * Note: Do not add a ; at the end of a use of JS_DECLARE_MAKE_METHODS, + * or the build will break. + */ +#define JS_DECLARE_MAKE_METHODS(MAKENAME, NEWNAME, QUALIFIERS)\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME() MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T, ())\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1)))\ + }\ +\ + template \ + QUALIFIERS \ +mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11, P12 &&p12) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11),\ + mozilla::Forward(p12)))\ + }\ + +JS_DECLARE_NEW_METHODS(js_new, js_malloc, static MOZ_ALWAYS_INLINE) template -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void js_delete(T *p) { if (p) { @@ -402,7 +521,7 @@ js_delete(T *p) } template -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void js_delete_poison(T *p) { if (p) { @@ -413,21 +532,21 @@ js_delete_poison(T *p) } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_malloc() { return (T *)js_malloc(sizeof(T)); } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_calloc() { return (T *)js_calloc(sizeof(T)); } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_malloc(size_t numElems) { if (numElems & mozilla::tl::MulOverflowMask::value) @@ -436,7 +555,7 @@ js_pod_malloc(size_t numElems) } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_calloc(size_t numElems) { if (numElems & mozilla::tl::MulOverflowMask::value) @@ -471,6 +590,25 @@ SCOPED_TEMPLATE(ScopedReleasePtr, ScopedReleasePtrTraits) } /* namespace js */ +namespace JS { + +template +struct DeletePolicy +{ + void operator()(T* ptr) { + js_delete(ptr); + } +}; + +struct FreePolicy +{ + void operator()(void* ptr) { + js_free(ptr); + } +}; + +} // namespace JS + namespace js { /* Integral types for all hash functions. */ @@ -535,7 +673,7 @@ namespace JS { inline void PoisonPtr(void *v) { -#if defined(JSGC_ROOT_ANALYSIS) && defined(DEBUG) +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) uint8_t *ptr = (uint8_t *) v + 3; *ptr = JS_FREE_PATTERN; #endif @@ -544,7 +682,7 @@ inline void PoisonPtr(void *v) template inline bool IsPoisonedPtr(T *v) { -#if defined(JSGC_ROOT_ANALYSIS) && defined(DEBUG) +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) uint32_t mask = uintptr_t(v) & 0xff000000; return mask == uint32_t(JS_FREE_PATTERN << 24); #else diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/Value.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/Value.h index ee4f3a64d3..4a14d1714f 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/Value.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/Value.h @@ -15,9 +15,11 @@ #include /* for std::numeric_limits */ +#include "js-config.h" #include "jstypes.h" #include "js/Anchor.h" +#include "js/GCAPI.h" #include "js/RootingAPI.h" #include "js/Utility.h" @@ -46,7 +48,7 @@ namespace JS { class Value; } # define JSVAL_ALIGNMENT #endif -#if JS_BITS_PER_WORD == 64 +#if defined(JS_PUNBOX64) # define JSVAL_TAG_SHIFT 47 #endif @@ -74,8 +76,9 @@ JS_ENUM_HEADER(JSValueType, uint8_t) JSVAL_TYPE_BOOLEAN = 0x03, JSVAL_TYPE_MAGIC = 0x04, JSVAL_TYPE_STRING = 0x05, - JSVAL_TYPE_NULL = 0x06, - JSVAL_TYPE_OBJECT = 0x07, + JSVAL_TYPE_SYMBOL = 0x06, + JSVAL_TYPE_NULL = 0x07, + JSVAL_TYPE_OBJECT = 0x08, /* These never appear in a jsval; they are only provided as an out-of-band value. */ JSVAL_TYPE_UNKNOWN = 0x20, @@ -84,7 +87,7 @@ JS_ENUM_HEADER(JSValueType, uint8_t) JS_STATIC_ASSERT(sizeof(JSValueType) == 1); -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) /* Remember to propagate changes to the C defines below. */ JS_ENUM_HEADER(JSValueTag, uint32_t) @@ -93,6 +96,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JSVAL_TAG_INT32 = JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32, JSVAL_TAG_UNDEFINED = JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED, JSVAL_TAG_STRING = JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL, JSVAL_TAG_BOOLEAN = JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN, JSVAL_TAG_MAGIC = JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC, JSVAL_TAG_NULL = JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL, @@ -101,7 +105,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JS_STATIC_ASSERT(sizeof(JSValueTag) == 4); -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) /* Remember to propagate changes to the C defines below. */ JS_ENUM_HEADER(JSValueTag, uint32_t) @@ -110,6 +114,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JSVAL_TAG_INT32 = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32, JSVAL_TAG_UNDEFINED = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED, JSVAL_TAG_STRING = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL, JSVAL_TAG_BOOLEAN = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN, JSVAL_TAG_MAGIC = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC, JSVAL_TAG_NULL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL, @@ -124,6 +129,7 @@ JS_ENUM_HEADER(JSValueShiftedTag, uint64_t) JSVAL_SHIFTED_TAG_INT32 = (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_UNDEFINED = (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_STRING = (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_SYMBOL = (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_BOOLEAN = (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_MAGIC = (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_NULL = (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT), @@ -143,29 +149,32 @@ typedef uint8_t JSValueType; #define JSVAL_TYPE_BOOLEAN ((uint8_t)0x03) #define JSVAL_TYPE_MAGIC ((uint8_t)0x04) #define JSVAL_TYPE_STRING ((uint8_t)0x05) -#define JSVAL_TYPE_NULL ((uint8_t)0x06) -#define JSVAL_TYPE_OBJECT ((uint8_t)0x07) +#define JSVAL_TYPE_SYMBOL ((uint8_t)0x06) +#define JSVAL_TYPE_NULL ((uint8_t)0x07) +#define JSVAL_TYPE_OBJECT ((uint8_t)0x08) #define JSVAL_TYPE_UNKNOWN ((uint8_t)0x20) -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) typedef uint32_t JSValueTag; #define JSVAL_TAG_CLEAR ((uint32_t)(0xFFFFFF80)) #define JSVAL_TAG_INT32 ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32)) #define JSVAL_TAG_UNDEFINED ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED)) #define JSVAL_TAG_STRING ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING)) +#define JSVAL_TAG_SYMBOL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL)) #define JSVAL_TAG_BOOLEAN ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN)) #define JSVAL_TAG_MAGIC ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC)) #define JSVAL_TAG_NULL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL)) #define JSVAL_TAG_OBJECT ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT)) -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) typedef uint32_t JSValueTag; #define JSVAL_TAG_MAX_DOUBLE ((uint32_t)(0x1FFF0)) #define JSVAL_TAG_INT32 (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32) #define JSVAL_TAG_UNDEFINED (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED) #define JSVAL_TAG_STRING (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING) +#define JSVAL_TAG_SYMBOL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL) #define JSVAL_TAG_BOOLEAN (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN) #define JSVAL_TAG_MAGIC (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC) #define JSVAL_TAG_NULL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL) @@ -176,20 +185,16 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_SHIFTED_TAG_INT32 (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_UNDEFINED (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_STRING (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_SYMBOL (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_BOOLEAN (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_MAGIC (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_NULL (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_OBJECT (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT) -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ #endif /* !defined(__SUNPRO_CC) && !defined(__xlC__) */ -#define JSVAL_LOWER_INCL_TYPE_OF_OBJ_OR_NULL_SET JSVAL_TYPE_NULL -#define JSVAL_UPPER_EXCL_TYPE_OF_PRIMITIVE_SET JSVAL_TYPE_OBJECT -#define JSVAL_UPPER_INCL_TYPE_OF_NUMBER_SET JSVAL_TYPE_INT32 -#define JSVAL_LOWER_INCL_TYPE_OF_PTR_PAYLOAD_SET JSVAL_TYPE_MAGIC - -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) #define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_CLEAR | (type))) @@ -198,7 +203,7 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32 #define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) #define JSVAL_PAYLOAD_MASK 0x00007FFFFFFFFFFFLL #define JSVAL_TAG_MASK 0xFFFF800000000000LL @@ -215,7 +220,7 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET JSVAL_SHIFTED_TAG_UNDEFINED #define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET JSVAL_SHIFTED_TAG_STRING -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ typedef enum JSWhyMagic { @@ -233,16 +238,16 @@ typedef enum JSWhyMagic JS_OPTIMIZED_ARGUMENTS, /* optimized-away 'arguments' value */ JS_IS_CONSTRUCTING, /* magic value passed to natives to indicate construction */ JS_OVERWRITTEN_CALLEE, /* arguments.callee has been overwritten */ - JS_FORWARD_TO_CALL_OBJECT, /* args object element stored in call object */ JS_BLOCK_NEEDS_CLONE, /* value of static block object slot */ JS_HASH_KEY_EMPTY, /* see class js::HashableValue */ JS_ION_ERROR, /* error while running Ion code */ - JS_ION_BAILOUT, /* status code to signal EnterIon will OSR into Interpret */ + JS_ION_BAILOUT, /* missing recover instruction result */ + JS_OPTIMIZED_OUT, /* optimized out slot */ JS_GENERIC_MAGIC /* for local use */ } JSWhyMagic; #if defined(IS_LITTLE_ENDIAN) -# if JS_BITS_PER_WORD == 32 +# if defined(JS_NUNBOX32) typedef union jsval_layout { uint64_t asBits; @@ -252,7 +257,9 @@ typedef union jsval_layout uint32_t u32; uint32_t boo; // Don't use |bool| -- it must be four bytes. JSString *str; + JS::Symbol *sym; JSObject *obj; + js::gc::Cell *cell; void *ptr; JSWhyMagic why; size_t word; @@ -263,7 +270,7 @@ typedef union jsval_layout double asDouble; void *asPtr; } JSVAL_ALIGNMENT jsval_layout; -# elif JS_BITS_PER_WORD == 64 +# elif defined(JS_PUNBOX64) typedef union jsval_layout { uint64_t asBits; @@ -286,9 +293,9 @@ typedef union jsval_layout size_t asWord; uintptr_t asUIntPtr; } JSVAL_ALIGNMENT jsval_layout; -# endif /* JS_BITS_PER_WORD */ +# endif /* JS_PUNBOX64 */ #else /* defined(IS_LITTLE_ENDIAN) */ -# if JS_BITS_PER_WORD == 32 +# if defined(JS_NUNBOX32) typedef union jsval_layout { uint64_t asBits; @@ -299,7 +306,9 @@ typedef union jsval_layout uint32_t u32; uint32_t boo; // Don't use |bool| -- it must be four bytes. JSString *str; + JS::Symbol *sym; JSObject *obj; + js::gc::Cell *cell; void *ptr; JSWhyMagic why; size_t word; @@ -309,7 +318,7 @@ typedef union jsval_layout double asDouble; void *asPtr; } JSVAL_ALIGNMENT jsval_layout; -# elif JS_BITS_PER_WORD == 64 +# elif defined(JS_PUNBOX64) typedef union jsval_layout { uint64_t asBits; @@ -330,10 +339,13 @@ typedef union jsval_layout size_t asWord; uintptr_t asUIntPtr; } JSVAL_ALIGNMENT jsval_layout; -# endif /* JS_BITS_PER_WORD */ +# endif /* JS_PUNBOX64 */ #endif /* defined(IS_LITTLE_ENDIAN) */ +//this is a workaround for fixing binding-generator errors +#ifndef NO_JS_ASSERT JS_STATIC_ASSERT(sizeof(jsval_layout) == 8); +#endif /* * For codesize purposes on some platforms, it's important that the @@ -378,7 +390,7 @@ JS_STATIC_ASSERT(sizeof(jsval_layout) == 8); # define JS_VALUE_CONSTEXPR_VAR const #endif -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) /* * N.B. GCC, in some but not all cases, chooses to emit signed comparison of @@ -456,7 +468,7 @@ static inline jsval_layout STRING_TO_JSVAL_IMPL(JSString *str) { jsval_layout l; - MOZ_ASSERT(str); + MOZ_ASSERT(uintptr_t(str) > 0x1000); l.s.tag = JSVAL_TAG_STRING; l.s.payload.str = str; return l; @@ -468,6 +480,28 @@ JSVAL_TO_STRING_IMPL(jsval_layout l) return l.s.payload.str; } +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + l.s.tag = JSVAL_TAG_SYMBOL; + l.s.payload.sym = sym; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.payload.sym; +} + static inline bool JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) { @@ -524,7 +558,7 @@ static inline jsval_layout OBJECT_TO_JSVAL_IMPL(JSObject *obj) { jsval_layout l; - MOZ_ASSERT(obj); + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); l.s.tag = JSVAL_TAG_OBJECT; l.s.payload.obj = obj; return l; @@ -560,22 +594,22 @@ JSVAL_IS_GCTHING_IMPL(jsval_layout l) return (uint32_t)l.s.tag >= (uint32_t)JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET; } -static inline void * +static inline js::gc::Cell * JSVAL_TO_GCTHING_IMPL(jsval_layout l) { - return l.s.payload.ptr; -} - -static inline bool -JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) -{ - return l.s.tag == JSVAL_TAG_STRING || l.s.tag == JSVAL_TAG_OBJECT; + return l.s.payload.cell; } static inline uint32_t JSVAL_TRACE_KIND_IMPL(jsval_layout l) { - return (uint32_t)(bool)JSVAL_IS_STRING_IMPL(l); + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return l.s.tag & 0x03; } static inline bool @@ -585,7 +619,7 @@ JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) } static inline bool -JSVAL_IS_SPECIFIC_BOOLEAN(jsval_layout l, bool b) +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) { return (l.s.tag == JSVAL_TAG_BOOLEAN) && (l.s.payload.boo == uint32_t(b)); } @@ -599,6 +633,15 @@ MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) return l; } +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.s.tag = JSVAL_TAG_MAGIC; + l.s.payload.u32 = payload; + return l; +} + static inline bool JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) { @@ -614,7 +657,7 @@ JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) return (JSValueType)type; } -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) static inline JS_VALUE_CONSTEXPR jsval_layout BUILD_JSVAL(JSValueTag tag, uint64_t payload) @@ -678,7 +721,7 @@ STRING_TO_JSVAL_IMPL(JSString *str) { jsval_layout l; uint64_t strBits = (uint64_t)str; - MOZ_ASSERT(str); + MOZ_ASSERT(uintptr_t(str) > 0x1000); MOZ_ASSERT((strBits >> JSVAL_TAG_SHIFT) == 0); l.asBits = strBits | JSVAL_SHIFTED_TAG_STRING; return l; @@ -690,6 +733,29 @@ JSVAL_TO_STRING_IMPL(jsval_layout l) return (JSString *)(l.asBits & JSVAL_PAYLOAD_MASK); } +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + uint64_t symBits = (uint64_t)sym; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + MOZ_ASSERT((symBits >> JSVAL_TAG_SHIFT) == 0); + l.asBits = symBits | JSVAL_SHIFTED_TAG_SYMBOL; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return (JS::Symbol *)(l.asBits & JSVAL_PAYLOAD_MASK); +} + static inline bool JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) { @@ -725,7 +791,7 @@ JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l) static inline bool JSVAL_IS_OBJECT_IMPL(jsval_layout l) { - MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_SHIFTED_TAG_OBJECT); + MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_TAG_OBJECT); return l.asBits >= JSVAL_SHIFTED_TAG_OBJECT; } @@ -749,7 +815,7 @@ OBJECT_TO_JSVAL_IMPL(JSObject *obj) { jsval_layout l; uint64_t objBits = (uint64_t)obj; - MOZ_ASSERT(obj); + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); MOZ_ASSERT((objBits >> JSVAL_TAG_SHIFT) == 0); l.asBits = objBits | JSVAL_SHIFTED_TAG_OBJECT; return l; @@ -767,24 +833,24 @@ JSVAL_IS_GCTHING_IMPL(jsval_layout l) return l.asBits >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET; } -static inline void * +static inline js::gc::Cell * JSVAL_TO_GCTHING_IMPL(jsval_layout l) { uint64_t ptrBits = l.asBits & JSVAL_PAYLOAD_MASK; MOZ_ASSERT((ptrBits & 0x7) == 0); - return (void *)ptrBits; -} - -static inline bool -JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) -{ - return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l); + return reinterpret_cast(ptrBits); } static inline uint32_t JSVAL_TRACE_KIND_IMPL(jsval_layout l) { - return (uint32_t)(bool)!(JSVAL_IS_OBJECT_IMPL(l)); + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) & 0x03; } static inline jsval_layout @@ -812,7 +878,7 @@ JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) } static inline bool -JSVAL_IS_SPECIFIC_BOOLEAN(jsval_layout l, bool b) +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) { return l.asBits == (((uint64_t)(uint32_t)b) | JSVAL_SHIFTED_TAG_BOOLEAN); } @@ -825,6 +891,14 @@ MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) return l; } +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.asBits = ((uint64_t)payload) | JSVAL_SHIFTED_TAG_MAGIC; + return l; +} + static inline bool JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) { @@ -841,7 +915,13 @@ JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) return (JSValueType)type; } -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ + +static inline bool +JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) +{ + return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l); +} static inline jsval_layout JSVAL_TO_IMPL(JS::Value v); static inline JS_VALUE_CONSTEXPR JS::Value IMPL_TO_JSVAL(jsval_layout l); @@ -859,7 +939,7 @@ static inline JS_VALUE_CONSTEXPR JS::Value UndefinedValue(); static MOZ_ALWAYS_INLINE double GenericNaN() { - return mozilla::SpecificNaN(0, 0x8000000000000ULL); + return mozilla::SpecificNaN(0, 0x8000000000000ULL); } /* MSVC with PGO miscompiles this function. */ @@ -883,27 +963,23 @@ CanonicalizeNaN(double d) * * - JS::Value has setX() and isX() members for X in * - * { Int32, Double, String, Boolean, Undefined, Null, Object, Magic } + * { Int32, Double, String, Symbol, Boolean, Undefined, Null, Object, Magic } * * JS::Value also contains toX() for each of the non-singleton types. * - * - Magic is a singleton type whose payload contains a JSWhyMagic "reason" for - * the magic value. By providing JSWhyMagic values when creating and checking - * for magic values, it is possible to assert, at runtime, that only magic - * values with the expected reason flow through a particular value. For - * example, if cx->exception has a magic value, the reason must be - * JS_GENERATOR_CLOSING. + * - Magic is a singleton type whose payload contains either a JSWhyMagic "reason" for + * the magic value or a uint32_t value. By providing JSWhyMagic values when + * creating and checking for magic values, it is possible to assert, at + * runtime, that only magic values with the expected reason flow through a + * particular value. For example, if cx->exception has a magic value, the + * reason must be JS_GENERATOR_CLOSING. * * - The JS::Value operations are preferred. The JSVAL_* operations remain for * compatibility; they may be removed at some point. These operations mostly * provide similar functionality. But there are a few key differences. One - * is that JS::Value gives null a separate type. Thus - * - * JSVAL_IS_OBJECT(v) === v.isObjectOrNull() - * !JSVAL_IS_PRIMITIVE(v) === v.isObject() - * + * is that JS::Value gives null a separate type. * Also, to help prevent mistakenly boxing a nullable JSObject* as an object, - * Value::setObject takes a JSObject&. (Conversely, Value::asObject returns a + * Value::setObject takes a JSObject&. (Conversely, Value::toObject returns a * JSObject&.) A convenience member Value::setObjectOrNull is provided. * * - JSVAL_VOID is the same as the singleton value of the Undefined type. @@ -961,6 +1037,11 @@ class Value data = STRING_TO_JSVAL_IMPL(str); } + void setSymbol(JS::Symbol *sym) { + MOZ_ASSERT(!IsPoisonedPtr(sym)); + data = SYMBOL_TO_JSVAL_IMPL(sym); + } + void setObject(JSObject &obj) { MOZ_ASSERT(!IsPoisonedPtr(&obj)); data = OBJECT_TO_JSVAL_IMPL(&obj); @@ -974,6 +1055,10 @@ class Value data = MAGIC_TO_JSVAL_IMPL(why); } + void setMagicUint32(uint32_t payload) { + data = MAGIC_UINT32_TO_JSVAL_IMPL(payload); + } + bool setNumber(uint32_t ui) { if (ui > JSVAL_INT_MAX) { setDouble((double)ui); @@ -986,7 +1071,7 @@ class Value bool setNumber(double d) { int32_t i; - if (mozilla::DoubleIsInt32(d, &i)) { + if (mozilla::NumberIsInt32(d, &i)) { setInt32(i); return true; } @@ -1042,6 +1127,10 @@ class Value return JSVAL_IS_STRING_IMPL(data); } + bool isSymbol() const { + return JSVAL_IS_SYMBOL_IMPL(data); + } + bool isObject() const { return JSVAL_IS_OBJECT_IMPL(data); } @@ -1063,11 +1152,11 @@ class Value } bool isTrue() const { - return JSVAL_IS_SPECIFIC_BOOLEAN(data, true); + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, true); } bool isFalse() const { - return JSVAL_IS_SPECIFIC_BOOLEAN(data, false); + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, false); } bool isMagic() const { @@ -1093,6 +1182,11 @@ class Value return data.s.payload.why; } + uint32_t magicUint32() const { + MOZ_ASSERT(isMagic()); + return data.s.payload.u32; + } + /*** Comparison ***/ bool operator==(const Value &rhs) const { @@ -1127,6 +1221,11 @@ class Value return JSVAL_TO_STRING_IMPL(data); } + JS::Symbol *toSymbol() const { + MOZ_ASSERT(isSymbol()); + return JSVAL_TO_SYMBOL_IMPL(data); + } + JSObject &toObject() const { MOZ_ASSERT(isObject()); return *JSVAL_TO_OBJECT_IMPL(data); @@ -1137,7 +1236,7 @@ class Value return JSVAL_TO_OBJECT_IMPL(data); } - void *toGCThing() const { + js::gc::Cell *toGCThing() const { MOZ_ASSERT(isGCThing()); return JSVAL_TO_GCTHING_IMPL(data); } @@ -1202,17 +1301,17 @@ class Value } const size_t *payloadWord() const { -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) return &data.s.payload.word; -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) return &data.asWord; #endif } const uintptr_t *payloadUIntPtr() const { -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) return &data.s.payload.uintptr; -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) return &data.asUIntPtr; #endif } @@ -1228,14 +1327,17 @@ class Value private: #if defined(JS_VALUE_IS_CONSTEXPR) - JS_VALUE_CONSTEXPR Value(jsval_layout layout) : data(layout) {} + MOZ_IMPLICIT JS_VALUE_CONSTEXPR Value(jsval_layout layout) : data(layout) {} #endif void staticAssertions() { JS_STATIC_ASSERT(sizeof(JSValueType) == 1); JS_STATIC_ASSERT(sizeof(JSValueTag) == 4); JS_STATIC_ASSERT(sizeof(JSWhyMagic) <= 4); + //this is a workaround for fixing binding-generator errors + #ifndef NO_JS_ASSERT JS_STATIC_ASSERT(sizeof(Value) == 8); + #endif } friend jsval_layout (::JSVAL_TO_IMPL)(Value); @@ -1248,11 +1350,30 @@ IsPoisonedValue(const Value &v) { if (v.isString()) return IsPoisonedPtr(v.toString()); + if (v.isSymbol()) + return IsPoisonedPtr(v.toSymbol()); if (v.isObject()) return IsPoisonedPtr(&v.toObject()); return false; } +inline bool +IsOptimizedPlaceholderMagicValue(const Value &v) +{ + if (v.isMagic()) { + MOZ_ASSERT(v.whyMagic() == JS_OPTIMIZED_ARGUMENTS || v.whyMagic() == JS_OPTIMIZED_OUT); + return true; + } + return false; +} + +static MOZ_ALWAYS_INLINE void +ExposeValueToActiveJS(const Value &v) +{ + if (v.isMarkable()) + ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); +} + /************************************************************************/ static inline Value @@ -1315,6 +1436,14 @@ StringValue(JSString *str) return v; } +static inline Value +SymbolValue(JS::Symbol *sym) +{ + Value v; + v.setSymbol(sym); + return v; +} + static inline Value BooleanValue(bool boo) { @@ -1363,6 +1492,14 @@ MagicValue(JSWhyMagic why) return v; } +static inline Value +MagicValueUint32(uint32_t payload) +{ + Value v; + v.setMagicUint32(payload); + return v; +} + static inline Value NumberValue(float f) { @@ -1507,16 +1644,16 @@ namespace js { template <> struct GCMethods { static JS::Value initial() { return JS::UndefinedValue(); } - static ThingRootKind kind() { return THING_ROOT_VALUE; } static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } }; template <> struct GCMethods { static JS::Value initial() { return JS::UndefinedValue(); } - static ThingRootKind kind() { return THING_ROOT_VALUE; } static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } - static bool needsPostBarrier(const JS::Value &v) { return v.isMarkable(); } + static bool needsPostBarrier(const JS::Value &v) { + return v.isObject() && gc::IsInsideNursery(reinterpret_cast(&v.toObject())); + } #ifdef JSGC_GENERATIONAL static void postBarrier(JS::Value *v) { JS::HeapValuePostBarrier(v); } static void relocate(JS::Value *v) { JS::HeapValueRelocate(v); } @@ -1548,6 +1685,7 @@ class ValueOperations bool isInt32() const { return value()->isInt32(); } bool isDouble() const { return value()->isDouble(); } bool isString() const { return value()->isString(); } + bool isSymbol() const { return value()->isSymbol(); } bool isObject() const { return value()->isObject(); } bool isMagic() const { return value()->isMagic(); } bool isMagic(JSWhyMagic why) const { return value()->isMagic(why); } @@ -1563,14 +1701,17 @@ class ValueOperations int32_t toInt32() const { return value()->toInt32(); } double toDouble() const { return value()->toDouble(); } JSString *toString() const { return value()->toString(); } + JS::Symbol *toSymbol() const { return value()->toSymbol(); } JSObject &toObject() const { return value()->toObject(); } JSObject *toObjectOrNull() const { return value()->toObjectOrNull(); } void *toGCThing() const { return value()->toGCThing(); } + uint64_t asRawBits() const { return value()->asRawBits(); } JSValueType extractNonDoubleType() const { return value()->extractNonDoubleType(); } uint32_t toPrivateUint32() const { return value()->toPrivateUint32(); } JSWhyMagic whyMagic() const { return value()->whyMagic(); } + uint32_t magicUint32() const { return value()->magicUint32(); } }; /* @@ -1595,6 +1736,7 @@ class MutableValueOperations : public ValueOperations bool setNumber(uint32_t ui) { return value()->setNumber(ui); } bool setNumber(double d) { return value()->setNumber(d); } void setString(JSString *str) { this->value()->setString(str); } + void setSymbol(JS::Symbol *sym) { this->value()->setSymbol(sym); } void setObject(JSObject &obj) { this->value()->setObject(obj); } void setObjectOrNull(JSObject *arg) { this->value()->setObjectOrNull(arg); } }; @@ -1625,6 +1767,7 @@ class HeapBase : public ValueOperations > void setBoolean(bool b) { setBarriered(JS::BooleanValue(b)); } void setMagic(JSWhyMagic why) { setBarriered(JS::MagicValue(why)); } void setString(JSString *str) { setBarriered(JS::StringValue(str)); } + void setSymbol(JS::Symbol *sym) { setBarriered(JS::SymbolValue(sym)); } void setObject(JSObject &obj) { setBarriered(JS::ObjectValue(obj)); } bool setNumber(uint32_t ui) { @@ -1639,7 +1782,7 @@ class HeapBase : public ValueOperations > bool setNumber(double d) { int32_t i; - if (mozilla::DoubleIsInt32(d, &i)) { + if (mozilla::NumberIsInt32(d, &i)) { setInt32(i); return true; } @@ -1747,7 +1890,7 @@ inline Anchor::~Anchor() } #endif -#ifdef DEBUG +#ifdef JS_DEBUG namespace detail { struct ValueAlignmentTester { char c; JS::Value v; }; @@ -1759,7 +1902,7 @@ static_assert(sizeof(LayoutAlignmentTester) == 16, "jsval_layout must be 16-byte-aligned"); } // namespace detail -#endif /* DEBUG */ +#endif /* JS_DEBUG */ } // namespace JS @@ -1775,52 +1918,12 @@ static_assert(sizeof(jsval_layout) == sizeof(JS::Value), /************************************************************************/ -static inline bool -JSVAL_IS_NULL(jsval v) -{ - return JSVAL_IS_NULL_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_VOID(jsval v) -{ - return JSVAL_IS_UNDEFINED_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_INT(jsval v) -{ - return JSVAL_IS_INT32_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline int32_t -JSVAL_TO_INT(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_INT(v)); - return JSVAL_TO_INT32_IMPL(JSVAL_TO_IMPL(v)); -} - static inline JS_VALUE_CONSTEXPR jsval INT_TO_JSVAL(int32_t i) { return IMPL_TO_JSVAL(INT32_TO_JSVAL_IMPL(i)); } -static inline bool -JSVAL_IS_DOUBLE(jsval v) -{ - return JSVAL_IS_DOUBLE_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline double -JSVAL_TO_DOUBLE(jsval v) -{ - jsval_layout l; - MOZ_ASSERT(JSVAL_IS_DOUBLE(v)); - l = JSVAL_TO_IMPL(v); - return l.asDouble; -} - static inline JS_VALUE_CONSTEXPR jsval DOUBLE_TO_JSVAL(double d) { @@ -1852,38 +1955,12 @@ UINT_TO_JSVAL(uint32_t i) : DOUBLE_TO_JSVAL((double)i)); } -static inline bool -JSVAL_IS_NUMBER(jsval v) -{ - return JSVAL_IS_NUMBER_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_STRING(jsval v) -{ - return JSVAL_IS_STRING_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline JSString * -JSVAL_TO_STRING(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_STRING(v)); - return JSVAL_TO_STRING_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval STRING_TO_JSVAL(JSString *str) { return IMPL_TO_JSVAL(STRING_TO_JSVAL_IMPL(str)); } -static inline JSObject * -JSVAL_TO_OBJECT(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_OBJECT_OR_NULL_IMPL(JSVAL_TO_IMPL(v))); - return JSVAL_TO_OBJECT_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval OBJECT_TO_JSVAL(JSObject *obj) { @@ -1892,44 +1969,12 @@ OBJECT_TO_JSVAL(JSObject *obj) return IMPL_TO_JSVAL(BUILD_JSVAL(JSVAL_TAG_NULL, 0)); } -static inline bool -JSVAL_IS_BOOLEAN(jsval v) -{ - return JSVAL_IS_BOOLEAN_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_TO_BOOLEAN(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_BOOLEAN(v)); - return JSVAL_TO_BOOLEAN_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval BOOLEAN_TO_JSVAL(bool b) { return IMPL_TO_JSVAL(BOOLEAN_TO_JSVAL_IMPL(b)); } -static inline bool -JSVAL_IS_PRIMITIVE(jsval v) -{ - return JSVAL_IS_PRIMITIVE_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_GCTHING(jsval v) -{ - return JSVAL_IS_GCTHING_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline void * -JSVAL_TO_GCTHING(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_GCTHING(v)); - return JSVAL_TO_GCTHING_IMPL(JSVAL_TO_IMPL(v)); -} - /* To be GC-safe, privates are tagged as doubles. */ static inline jsval @@ -1938,13 +1983,6 @@ PRIVATE_TO_JSVAL(void *ptr) return IMPL_TO_JSVAL(PRIVATE_PTR_TO_JSVAL_IMPL(ptr)); } -static inline void * -JSVAL_TO_PRIVATE(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_DOUBLE(v)); - return JSVAL_TO_PRIVATE_PTR_IMPL(JSVAL_TO_IMPL(v)); -} - // JS constants. For efficiency, prefer predicates (e.g. v.isNull()) and // constructing values from scratch (e.g. Int32Value(0)). These constants are // stored in memory and initialized at startup, so testing against them and @@ -1958,8 +1996,10 @@ extern JS_PUBLIC_DATA(const jsval) JSVAL_VOID; namespace JS { -extern JS_PUBLIC_DATA(const Handle) NullHandleValue; -extern JS_PUBLIC_DATA(const Handle) UndefinedHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) NullHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) TrueHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) FalseHandleValue; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/Vector.h index e8aef1713d..a2d24b10ed 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/js/Vector.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/Vector.h @@ -54,7 +54,7 @@ class Vector typedef typename mozilla::VectorBase Base; public: - Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} Vector(Vector &&vec) : Base(mozilla::Move(vec)) {} Vector &operator=(Vector &&vec) { return Base::operator=(mozilla::Move(vec)); diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/js/WeakMapPtr.h b/frameworks/js-bindings/external/spidermonkey/include/android/js/WeakMapPtr.h new file mode 100644 index 0000000000..f5822bef4b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/js/WeakMapPtr.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_WeakMapPtr_h +#define js_WeakMapPtr_h + +#include "jspubtd.h" + +#include "js/TypeDecls.h" + +namespace JS { + +// A wrapper around the internal C++ representation of SpiderMonkey WeakMaps, +// usable outside the engine. +// +// The supported template specializations are enumerated in WeakMapPtr.cpp. If +// you want to use this class for a different key/value combination, add it to +// the list and the compiler will generate the relevant machinery. +template +class JS_PUBLIC_API(WeakMapPtr) +{ + public: + WeakMapPtr() : ptr(nullptr) {}; + bool init(JSContext *cx); + bool initialized() { return ptr != nullptr; }; + void destroy(); + virtual ~WeakMapPtr() { MOZ_ASSERT(!initialized()); } + void trace(JSTracer *tracer); + + V lookup(const K &key); + bool put(JSContext *cx, const K &key, const V &value); + + static void keyMarkCallback(JSTracer *trc, K key, void *data); + + private: + void *ptr; + + // WeakMapPtr is neither copyable nor assignable. + WeakMapPtr(const WeakMapPtr &wmp) MOZ_DELETE; + WeakMapPtr &operator=(const WeakMapPtr &wmp) MOZ_DELETE; +}; + +} /* namespace JS */ + +#endif /* js_WeakMapPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/jsalloc.h b/frameworks/js-bindings/external/spidermonkey/include/android/jsalloc.h index 03b6b569e1..a1e547cec9 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/jsalloc.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/jsalloc.h @@ -4,7 +4,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/* JS allocation policies. */ +/* + * JS allocation policies. + * + * The allocators here are for system memory with lifetimes which are not + * managed by the GC. See the comment at the top of vm/MallocProvider.h. + */ #ifndef jsalloc_h #define jsalloc_h @@ -14,7 +19,7 @@ namespace js { -class ContextFriendFields; +struct ContextFriendFields; /* Policy for using system memory functions and doing no error reporting. */ class SystemAllocPolicy @@ -47,26 +52,26 @@ class TempAllocPolicy JS_FRIEND_API(void *) onOutOfMemory(void *p, size_t nbytes); public: - TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( - TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} + MOZ_IMPLICIT TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( + MOZ_IMPLICIT TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} void *malloc_(size_t bytes) { void *p = js_malloc(bytes); - if (JS_UNLIKELY(!p)) + if (MOZ_UNLIKELY(!p)) p = onOutOfMemory(nullptr, bytes); return p; } void *calloc_(size_t bytes) { void *p = js_calloc(bytes); - if (JS_UNLIKELY(!p)) + if (MOZ_UNLIKELY(!p)) p = onOutOfMemory(nullptr, bytes); return p; } void *realloc_(void *p, size_t oldBytes, size_t bytes) { void *p2 = js_realloc(p, bytes); - if (JS_UNLIKELY(!p2)) + if (MOZ_UNLIKELY(!p2)) p2 = onOutOfMemory(p2, bytes); return p2; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/jsapi.h b/frameworks/js-bindings/external/spidermonkey/include/android/jsapi.h index 6d47488a33..4b5a4ce1ff 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/jsapi.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/jsapi.h @@ -9,10 +9,11 @@ #ifndef jsapi_h #define jsapi_h -#include "mozilla/Atomics.h" #include "mozilla/FloatingPoint.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/Range.h" #include "mozilla/RangedPtr.h" +#include "mozilla/TypedEnum.h" #include #include @@ -26,40 +27,28 @@ #include "js/Class.h" #include "js/HashTable.h" #include "js/Id.h" +#include "js/Principals.h" #include "js/RootingAPI.h" +#include "js/TracingAPI.h" #include "js/Utility.h" #include "js/Value.h" #include "js/Vector.h" /************************************************************************/ -struct JSTracer; - namespace JS { class Latin1CharsZ; class TwoByteChars; -typedef mozilla::RangedPtr CharPtr; - -class StableCharPtr : public CharPtr { - public: - StableCharPtr(const StableCharPtr &s) : CharPtr(s) {} - StableCharPtr(const mozilla::RangedPtr &s) : CharPtr(s) {} - StableCharPtr(const jschar *s, size_t len) : CharPtr(s, len) {} - StableCharPtr(const jschar *pos, const jschar *start, size_t len) - : CharPtr(pos, start, len) - {} -}; - -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG class JS_PUBLIC_API(AutoCheckRequestDepth) { JSContext *cx; public: - AutoCheckRequestDepth(JSContext *cx); - AutoCheckRequestDepth(js::ContextFriendFields *cx); + explicit AutoCheckRequestDepth(JSContext *cx); + explicit AutoCheckRequestDepth(js::ContextFriendFields *cx); ~AutoCheckRequestDepth(); }; @@ -71,155 +60,53 @@ class JS_PUBLIC_API(AutoCheckRequestDepth) # define CHECK_REQUEST(cx) \ ((void) 0) -#endif /* JS_THREADSAFE && DEBUG */ +#endif /* JS_THREADSAFE && JS_DEBUG */ -#ifdef DEBUG +#ifdef JS_DEBUG /* * Assert that we're not doing GC on cx, that we're in a request as * needed, and that the compartments for cx and v are correct. * Also check that GC would be safe at this point. */ JS_PUBLIC_API(void) -AssertArgumentsAreSane(JSContext *cx, JS::Handle v); +AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v); #else -inline void AssertArgumentsAreSane(JSContext *cx, JS::Handle v) { +inline void AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v) { /* Do nothing */ } -#endif /* DEBUG */ - -class JS_PUBLIC_API(AutoGCRooter) { - public: - AutoGCRooter(JSContext *cx, ptrdiff_t tag); - AutoGCRooter(js::ContextFriendFields *cx, ptrdiff_t tag); - - ~AutoGCRooter() { - JS_ASSERT(this == *stackTop); - *stackTop = down; - } - - /* Implemented in gc/RootMarking.cpp. */ - inline void trace(JSTracer *trc); - static void traceAll(JSTracer *trc); - static void traceAllWrappers(JSTracer *trc); - - protected: - AutoGCRooter * const down; - - /* - * Discriminates actual subclass of this being used. If non-negative, the - * subclass roots an array of values of the length stored in this field. - * If negative, meaning is indicated by the corresponding value in the enum - * below. Any other negative value indicates some deeper problem such as - * memory corruption. - */ - ptrdiff_t tag_; - - enum { - VALARRAY = -2, /* js::AutoValueArray */ - PARSER = -3, /* js::frontend::Parser */ - SHAPEVECTOR = -4, /* js::AutoShapeVector */ - IDARRAY = -6, /* js::AutoIdArray */ - DESCRIPTORS = -7, /* js::AutoPropDescArrayRooter */ - ID = -9, /* js::AutoIdRooter */ - VALVECTOR = -10, /* js::AutoValueVector */ - STRING = -12, /* js::AutoStringRooter */ - IDVECTOR = -13, /* js::AutoIdVector */ - OBJVECTOR = -14, /* js::AutoObjectVector */ - STRINGVECTOR =-15, /* js::AutoStringVector */ - SCRIPTVECTOR =-16, /* js::AutoScriptVector */ - NAMEVECTOR = -17, /* js::AutoNameVector */ - HASHABLEVALUE=-18, /* js::HashableValue */ - IONMASM = -19, /* js::jit::MacroAssembler */ - IONALLOC = -20, /* js::jit::AutoTempAllocatorRooter */ - WRAPVECTOR = -21, /* js::AutoWrapperVector */ - WRAPPER = -22, /* js::AutoWrapperRooter */ - OBJOBJHASHMAP=-23, /* js::AutoObjectObjectHashMap */ - OBJU32HASHMAP=-24, /* js::AutoObjectUnsigned32HashMap */ - OBJHASHSET = -25, /* js::AutoObjectHashSet */ - JSONPARSER = -26, /* js::JSONParser */ - CUSTOM = -27, /* js::CustomAutoRooter */ - FUNVECTOR = -28 /* js::AutoFunctionVector */ - }; - - private: - AutoGCRooter ** const stackTop; - - /* No copy or assignment semantics. */ - AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; - void operator=(AutoGCRooter &ida) MOZ_DELETE; -}; - -class AutoStringRooter : private AutoGCRooter { - public: - AutoStringRooter(JSContext *cx, JSString *str = nullptr - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, STRING), str_(str) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - void setString(JSString *str) { - str_ = str; - } - - JSString * string() const { - return str_; - } - - JSString ** addr() { - return &str_; - } - - JSString * const * addr() const { - return &str_; - } - - friend void AutoGCRooter::trace(JSTracer *trc); +#endif /* JS_DEBUG */ - private: - JSString *str_; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER -}; +/* AutoValueArray roots an internal fixed-size array of Values. */ +template +class AutoValueArray : public AutoGCRooter +{ + const size_t length_; + Value elements_[N]; -class AutoArrayRooter : private AutoGCRooter { public: - AutoArrayRooter(JSContext *cx, size_t len, Value *vec - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, len), array(vec), skip(cx, array, len) + explicit AutoValueArray(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, VALARRAY), length_(N) { + /* Always initialize in case we GC before assignment. */ + mozilla::PodArrayZero(elements_); MOZ_GUARD_OBJECT_NOTIFIER_INIT; - JS_ASSERT(tag_ >= 0); - } - - void changeLength(size_t newLength) { - tag_ = ptrdiff_t(newLength); - JS_ASSERT(tag_ >= 0); - } - - void changeArray(Value *newArray, size_t newLength) { - changeLength(newLength); - array = newArray; } - Value *array; + unsigned length() const { return length_; } + const Value *begin() const { return elements_; } + Value *begin() { return elements_; } - MutableHandle handleAt(size_t i) - { - JS_ASSERT(i < size_t(tag_)); - return MutableHandle::fromMarkedLocation(&array[i]); + HandleValue operator[](unsigned i) const { + JS_ASSERT(i < N); + return HandleValue::fromMarkedLocation(&elements_[i]); } - Handle handleAt(size_t i) const - { - JS_ASSERT(i < size_t(tag_)); - return Handle::fromMarkedLocation(&array[i]); + MutableHandleValue operator[](unsigned i) { + JS_ASSERT(i < N); + return MutableHandleValue::fromMarkedLocation(&elements_[i]); } - friend void AutoGCRooter::trace(JSTracer *trc); - - private: MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER - - js::SkipRoot skip; }; template @@ -228,20 +115,17 @@ class AutoVectorRooter : protected AutoGCRooter typedef js::Vector VectorImpl; VectorImpl vector; - /* Prevent overwriting of inline elements in vector. */ - js::SkipRoot vectorRoot; - public: explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, tag), vector(cx), vectorRoot(cx, &vector) + : AutoGCRooter(cx, tag), vector(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; } explicit AutoVectorRooter(js::ContextFriendFields *cx, ptrdiff_t tag MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, tag), vector(cx), vectorRoot(cx, &vector) + : AutoGCRooter(cx, tag), vector(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; } @@ -253,6 +137,7 @@ class AutoVectorRooter : protected AutoGCRooter bool empty() const { return vector.empty(); } bool append(const T &v) { return vector.append(v); } + bool append(const T *ptr, size_t len) { return vector.append(ptr, len); } bool appendAll(const AutoVectorRooter &other) { return vector.appendAll(other.vector); } @@ -291,13 +176,10 @@ class AutoVectorRooter : protected AutoGCRooter return vector.reserve(newLength); } - T &operator[](size_t i) { return vector[i]; } - const T &operator[](size_t i) const { return vector[i]; } - - JS::MutableHandle handleAt(size_t i) { + JS::MutableHandle operator[](size_t i) { return JS::MutableHandle::fromMarkedLocation(&vector[i]); } - JS::Handle handleAt(size_t i) const { + JS::Handle operator[](size_t i) const { return JS::Handle::fromMarkedLocation(&vector[i]); } @@ -408,7 +290,7 @@ class AutoHashMapRooter : protected AutoGCRooter return map.sizeOfIncludingThis(mallocSizeOf); } - unsigned generation() const { + uint32_t generation() const { return map.generation(); } @@ -523,7 +405,7 @@ class AutoHashSetRooter : protected AutoGCRooter return set.sizeOfIncludingThis(mallocSizeOf); } - unsigned generation() const { + uint32_t generation() const { return set.generation(); } @@ -629,7 +511,7 @@ class AutoScriptVector : public AutoVectorRooter }; /* - * Cutsom rooting behavior for internal and external clients. + * Custom rooting behavior for internal and external clients. */ class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter { @@ -651,6 +533,86 @@ class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER }; +/* + * RootedGeneric allows a class to instantiate its own Rooted type by + * including the method: + * + * void trace(JSTracer *trc); + * + * The trace() method must trace all of the class's fields. + */ +template +class RootedGeneric : private CustomAutoRooter +{ + public: + template + explicit RootedGeneric(CX *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + template + explicit RootedGeneric(CX *cx, const T& initial MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx), value(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + operator const T&() const { return value; } + T operator->() const { return value; } + + private: + virtual void trace(JSTracer *trc) { value->trace(trc); } + + T value; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* A handle to an array of rooted values. */ +class HandleValueArray +{ + const size_t length_; + const Value * const elements_; + + HandleValueArray(size_t len, const Value *elements) : length_(len), elements_(elements) {} + + public: + explicit HandleValueArray(const RootedValue& value) : length_(1), elements_(value.address()) {} + + MOZ_IMPLICIT HandleValueArray(const AutoValueVector& values) + : length_(values.length()), elements_(values.begin()) {} + + template + HandleValueArray(const AutoValueArray& values) : length_(N), elements_(values.begin()) {} + + /* CallArgs must already be rooted somewhere up the stack. */ + MOZ_IMPLICIT HandleValueArray(const JS::CallArgs& args) : length_(args.length()), elements_(args.array()) {} + + /* Use with care! Only call this if the data is guaranteed to be marked. */ + static HandleValueArray fromMarkedLocation(size_t len, const Value *elements) { + return HandleValueArray(len, elements); + } + + static HandleValueArray subarray(const HandleValueArray& values, size_t startIndex, size_t len) { + JS_ASSERT(startIndex + len <= values.length()); + return HandleValueArray(len, values.begin() + startIndex); + } + + static HandleValueArray empty() { + return HandleValueArray(0, nullptr); + } + + size_t length() const { return length_; } + const Value *begin() const { return elements_; } + + HandleValue operator[](size_t i) const { + JS_ASSERT(i < length_); + return HandleValue::fromMarkedLocation(&elements_[i]); + } +}; + } /* namespace JS */ /************************************************************************/ @@ -660,7 +622,7 @@ struct JSFreeOp { JSRuntime *runtime_; protected: - JSFreeOp(JSRuntime *rt) + explicit JSFreeOp(JSRuntime *rt) : runtime_(rt) { } public: @@ -725,10 +687,10 @@ typedef enum JSFinalizeStatus { } JSFinalizeStatus; typedef void -(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment); +(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment, void *data); typedef bool -(* JSOperationCallback)(JSContext *cx); +(* JSInterruptCallback)(JSContext *cx); typedef void (* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report); @@ -771,37 +733,20 @@ typedef struct JSErrorFormatString { } JSErrorFormatString; typedef const JSErrorFormatString * -(* JSErrorCallback)(void *userRef, const char *locale, - const unsigned errorNumber); +(* JSErrorCallback)(void *userRef, const unsigned errorNumber); typedef bool -(* JSLocaleToUpperCase)(JSContext *cx, JS::Handle src, - JS::MutableHandle rval); +(* JSLocaleToUpperCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); typedef bool -(* JSLocaleToLowerCase)(JSContext *cx, JS::Handle src, - JS::MutableHandle rval); +(* JSLocaleToLowerCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); typedef bool -(* JSLocaleCompare)(JSContext *cx, JS::Handle src1, JS::Handle src2, - JS::MutableHandle rval); - -typedef bool -(* JSLocaleToUnicode)(JSContext *cx, const char *src, JS::MutableHandle rval); - -/* - * Security protocol types. - */ - -typedef void -(* JSDestroyPrincipalsOp)(JSPrincipals *principals); +(* JSLocaleCompare)(JSContext *cx, JS::HandleString src1, JS::HandleString src2, + JS::MutableHandleValue rval); -/* - * Used to check if a CSP instance wants to disable eval() and friends. - * See js_CheckCSPPermitsJSAction() in jsobj. - */ typedef bool -(* JSCSPEvalChecker)(JSContext *cx); +(* JSLocaleToUnicode)(JSContext *cx, const char *src, JS::MutableHandleValue rval); /* * Callback used to ask the embedding for the cross compartment wrapper handler @@ -813,9 +758,8 @@ typedef bool * guaranteed not to wrap a function. */ typedef JSObject * -(* JSWrapObjectCallback)(JSContext *cx, JS::Handle existing, JS::Handle obj, - JS::Handle proto, JS::Handle parent, - unsigned flags); +(* JSWrapObjectCallback)(JSContext *cx, JS::HandleObject existing, JS::HandleObject obj, + JS::HandleObject parent, unsigned flags); /* * Callback used by the wrap hook to ask the embedding to prepare an object @@ -823,26 +767,12 @@ typedef JSObject * * or even finding a more suitable object for the new compartment. */ typedef JSObject * -(* JSPreWrapCallback)(JSContext *cx, JS::Handle scope, JS::Handle obj, +(* JSPreWrapCallback)(JSContext *cx, JS::HandleObject scope, JS::HandleObject obj, unsigned flags); -/* - * Callback used when wrapping determines that the underlying object is already - * in the compartment for which it is being wrapped. This allows consumers to - * maintain same-compartment wrapping invariants. - * - * |obj| is guaranteed to be same-compartment as |cx|, but it may (or may not) - * be a security or cross-compartment wrapper. This is an unfortunate contract, - * but is important for to avoid unnecessarily recomputing every cross- - * compartment wrapper that gets passed to wrap. - */ -typedef JSObject * -(* JSSameCompartmentWrapObjectCallback)(JSContext *cx, JS::Handle obj); - struct JSWrapObjectCallbacks { JSWrapObjectCallback wrap; - JSSameCompartmentWrapObjectCallback sameCompartmentWrap; JSPreWrapCallback preWrap; }; @@ -858,12 +788,12 @@ typedef void /************************************************************************/ -static JS_ALWAYS_INLINE jsval +static MOZ_ALWAYS_INLINE jsval JS_NumberValue(double d) { int32_t i; d = JS::CanonicalizeNaN(d); - if (mozilla::DoubleIsInt32(d, &i)) + if (mozilla::NumberIsInt32(d, &i)) return INT_TO_JSVAL(i); return DOUBLE_TO_JSVAL(d); } @@ -883,41 +813,91 @@ JS_StringHasBeenInterned(JSContext *cx, JSString *str); JS_PUBLIC_API(jsid) INTERNED_STRING_TO_JSID(JSContext *cx, JSString *str); -/* - * Returns true iff the given jsval is immune to GC and can be used across - * multiple JSRuntimes without requiring any conversion API. - */ -static JS_ALWAYS_INLINE bool -JSVAL_IS_UNIVERSAL(jsval v) -{ - return !JSVAL_IS_GCTHING(v); -} - namespace JS { -class AutoIdRooter : private AutoGCRooter +// Container class for passing in script source buffers to the JS engine. This +// not only groups the buffer and length values, it also provides a way to +// optionally pass ownership of the buffer to the JS engine without copying. +// Rules for use: +// +// 1) The data array must be allocated with js_malloc() or js_realloc() if +// ownership is being granted to the SourceBufferHolder. +// 2) If ownership is not given to the SourceBufferHolder, then the memory +// must be kept alive until the JS compilation is complete. +// 3) Any code calling SourceBufferHolder::take() must guarantee to keep the +// memory alive until JS compilation completes. Normally only the JS +// engine should be calling take(). +// +// Example use: +// +// size_t length = 512; +// jschar* chars = static_cast(js_malloc(sizeof(jschar) * length)); +// JS::SourceBufferHolder srcBuf(chars, length, JS::SourceBufferHolder::GiveOwnership); +// JS::Compile(cx, obj, options, srcBuf); +// +class MOZ_STACK_CLASS SourceBufferHolder MOZ_FINAL { public: - explicit AutoIdRooter(JSContext *cx, jsid aId = INT_TO_JSID(0) - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, ID), id_(aId) + enum Ownership { + NoOwnership, + GiveOwnership + }; + + SourceBufferHolder(const jschar *data, size_t dataLength, Ownership ownership) + : data_(data), + length_(dataLength), + ownsChars_(ownership == GiveOwnership) { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; + // Ensure that null buffers properly return an unowned, empty, + // null-terminated string. + static const jschar NullChar_ = 0; + if (!get()) { + data_ = &NullChar_; + length_ = 0; + ownsChars_ = false; + } } - jsid id() { - return id_; + ~SourceBufferHolder() { + if (ownsChars_) + js_free(const_cast(data_)); } - jsid * addr() { - return &id_; - } + // Access the underlying source buffer without affecting ownership. + const jschar *get() const { return data_; } - friend void AutoGCRooter::trace(JSTracer *trc); + // Length of the source buffer in jschars (not bytes) + size_t length() const { return length_; } + + // Returns true if the SourceBufferHolder owns the buffer and will free + // it upon destruction. If true, it is legal to call take(). + bool ownsChars() const { return ownsChars_; } + + // Retrieve and take ownership of the underlying data buffer. The caller + // is now responsible for calling js_free() on the returned value, *but only + // after JS script compilation has completed*. + // + // After the buffer has been taken the SourceBufferHolder functions as if + // it had been constructed on an unowned buffer; get() and length() still + // work. In order for this to be safe the taken buffer must be kept alive + // until after JS script compilation completes as noted above. + // + // Note, it's the caller's responsibility to check ownsChars() before taking + // the buffer. Taking and then free'ing an unowned buffer will have dire + // consequences. + jschar *take() { + JS_ASSERT(ownsChars_); + ownsChars_ = false; + return const_cast(data_); + } private: - jsid id_; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + SourceBufferHolder(SourceBufferHolder &) MOZ_DELETE; + SourceBufferHolder &operator=(SourceBufferHolder &) MOZ_DELETE; + + const jschar *data_; + size_t length_; + bool ownsChars_; }; } /* namespace JS */ @@ -941,8 +921,6 @@ class AutoIdRooter : private AutoGCRooter object that delegates to a prototype containing this property */ #define JSPROP_INDEX 0x80 /* name is actually (int) index */ -#define JSPROP_SHORTID 0x100 /* set in JS_DefineProperty attrs - if getters/setters use a shortid */ #define JSFUN_STUB_GSOPS 0x200 /* use JS_PropertyStub getter/setter instead of defaulting to class gsops @@ -1029,13 +1007,12 @@ JS_GetEmptyString(JSRuntime *rt); * unconverted arguments. */ extern JS_PUBLIC_API(bool) -JS_ConvertArguments(JSContext *cx, unsigned argc, jsval *argv, const char *format, - ...); +JS_ConvertArguments(JSContext *cx, const JS::CallArgs &args, const char *format, ...); #ifdef va_start extern JS_PUBLIC_API(bool) -JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv, - const char *format, va_list ap); +JS_ConvertArgumentsVA(JSContext *cx, const JS::CallArgs &args, const char *format, + va_list ap); #endif extern JS_PUBLIC_API(bool) @@ -1051,7 +1028,7 @@ extern JS_PUBLIC_API(JSFunction *) JS_ValueToConstructor(JSContext *cx, JS::HandleValue v); extern JS_PUBLIC_API(JSString *) -JS_ValueToSource(JSContext *cx, jsval v); +JS_ValueToSource(JSContext *cx, JS::Handle v); namespace js { /* @@ -1076,14 +1053,10 @@ ToStringSlow(JSContext *cx, JS::HandleValue v); namespace JS { /* ES5 9.3 ToNumber. */ -JS_ALWAYS_INLINE bool -ToNumber(JSContext *cx, Handle v, double *out) +MOZ_ALWAYS_INLINE bool +ToNumber(JSContext *cx, HandleValue v, double *out) { AssertArgumentsAreSane(cx, v); - { - js::SkipRoot root(cx, &v); - js::MaybeCheckStackRoots(cx); - } if (v.isNumber()) { *out = v.toNumber(); @@ -1092,7 +1065,7 @@ ToNumber(JSContext *cx, Handle v, double *out) return js::ToNumberSlow(cx, v, out); } -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool ToBoolean(HandleValue v) { if (v.isBoolean()) @@ -1105,12 +1078,14 @@ ToBoolean(HandleValue v) double d = v.toDouble(); return !mozilla::IsNaN(d) && d != 0; } + if (v.isSymbol()) + return true; /* The slow path handles strings and objects. */ return js::ToBooleanSlow(v); } -JS_ALWAYS_INLINE JSString* +MOZ_ALWAYS_INLINE JSString* ToString(JSContext *cx, HandleValue v) { if (v.isString()) @@ -1133,32 +1108,31 @@ JS_DoubleToUint32(double d); namespace js { /* DO NOT CALL THIS. Use JS::ToUint16. */ extern JS_PUBLIC_API(bool) -ToUint16Slow(JSContext *cx, JS::Handle v, uint16_t *out); +ToUint16Slow(JSContext *cx, JS::HandleValue v, uint16_t *out); /* DO NOT CALL THIS. Use JS::ToInt32. */ extern JS_PUBLIC_API(bool) -ToInt32Slow(JSContext *cx, JS::Handle v, int32_t *out); +ToInt32Slow(JSContext *cx, JS::HandleValue v, int32_t *out); /* DO NOT CALL THIS. Use JS::ToUint32. */ extern JS_PUBLIC_API(bool) -ToUint32Slow(JSContext *cx, JS::Handle v, uint32_t *out); +ToUint32Slow(JSContext *cx, JS::HandleValue v, uint32_t *out); /* DO NOT CALL THIS. Use JS::ToInt64. */ extern JS_PUBLIC_API(bool) -ToInt64Slow(JSContext *cx, JS::Handle v, int64_t *out); +ToInt64Slow(JSContext *cx, JS::HandleValue v, int64_t *out); /* DO NOT CALL THIS. Use JS::ToUint64. */ extern JS_PUBLIC_API(bool) -ToUint64Slow(JSContext *cx, JS::Handle v, uint64_t *out); +ToUint64Slow(JSContext *cx, JS::HandleValue v, uint64_t *out); } /* namespace js */ namespace JS { -JS_ALWAYS_INLINE bool -ToUint16(JSContext *cx, JS::Handle v, uint16_t *out) +MOZ_ALWAYS_INLINE bool +ToUint16(JSContext *cx, JS::HandleValue v, uint16_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = uint16_t(v.toInt32()); @@ -1167,11 +1141,10 @@ ToUint16(JSContext *cx, JS::Handle v, uint16_t *out) return js::ToUint16Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToInt32(JSContext *cx, JS::Handle v, int32_t *out) +MOZ_ALWAYS_INLINE bool +ToInt32(JSContext *cx, JS::HandleValue v, int32_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = v.toInt32(); @@ -1180,11 +1153,10 @@ ToInt32(JSContext *cx, JS::Handle v, int32_t *out) return js::ToInt32Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToUint32(JSContext *cx, JS::Handle v, uint32_t *out) +MOZ_ALWAYS_INLINE bool +ToUint32(JSContext *cx, JS::HandleValue v, uint32_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = uint32_t(v.toInt32()); @@ -1193,32 +1165,28 @@ ToUint32(JSContext *cx, JS::Handle v, uint32_t *out) return js::ToUint32Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToInt64(JSContext *cx, JS::Handle v, int64_t *out) +MOZ_ALWAYS_INLINE bool +ToInt64(JSContext *cx, JS::HandleValue v, int64_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = int64_t(v.toInt32()); return true; } - return js::ToInt64Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToUint64(JSContext *cx, JS::Handle v, uint64_t *out) +MOZ_ALWAYS_INLINE bool +ToUint64(JSContext *cx, JS::HandleValue v, uint64_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { /* Account for sign extension of negatives into the longer 64bit space. */ *out = uint64_t(int64_t(v.toInt32())); return true; } - return js::ToUint64Slow(cx, v, out); } @@ -1226,7 +1194,7 @@ ToUint64(JSContext *cx, JS::Handle v, uint64_t *out) } /* namespace JS */ extern JS_PUBLIC_API(JSType) -JS_TypeOfValue(JSContext *cx, jsval v); +JS_TypeOfValue(JSContext *cx, JS::Handle v); extern JS_PUBLIC_API(const char *) JS_GetTypeName(JSContext *cx, JSType type); @@ -1235,7 +1203,7 @@ extern JS_PUBLIC_API(bool) JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal); extern JS_PUBLIC_API(bool) -JS_LooselyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal); +JS_LooselyEqual(JSContext *cx, JS::Handle v1, JS::Handle v2, bool *equal); extern JS_PUBLIC_API(bool) JS_SameValue(JSContext *cx, jsval v1, jsval v2, bool *same); @@ -1258,12 +1226,6 @@ JS_IsBuiltinFunctionConstructor(JSFunction *fun); * See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference */ -typedef enum JSUseHelperThreads -{ - JS_NO_HELPER_THREADS, - JS_USE_HELPER_THREADS -} JSUseHelperThreads; - /** * Initialize SpiderMonkey, returning true only if initialization succeeded. * Once this method has succeeded, it is safe to call JS_NewRuntime and other @@ -1301,7 +1263,9 @@ extern JS_PUBLIC_API(void) JS_ShutDown(void); extern JS_PUBLIC_API(JSRuntime *) -JS_NewRuntime(uint32_t maxbytes, JSUseHelperThreads useHelperThreads); +JS_NewRuntime(uint32_t maxbytes, + uint32_t maxNurseryBytes = JS::DefaultNurseryBytes, + JSRuntime *parentRuntime = nullptr); extern JS_PUBLIC_API(void) JS_DestroyRuntime(JSRuntime *rt); @@ -1324,6 +1288,9 @@ JS_GetRuntimePrivate(JSRuntime *rt); extern JS_PUBLIC_API(JSRuntime *) JS_GetRuntime(JSContext *cx); +extern JS_PUBLIC_API(JSRuntime *) +JS_GetParentRuntime(JSContext *cx); + JS_PUBLIC_API(void) JS_SetRuntimePrivate(JSRuntime *rt, void *data); @@ -1349,8 +1316,8 @@ AssertHeapIsIdle(JSContext *cx); class JSAutoRequest { public: - JSAutoRequest(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit JSAutoRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : mContext(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -1374,10 +1341,10 @@ class JSAutoRequest class JSAutoCheckRequest { public: - JSAutoCheckRequest(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit JSAutoCheckRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) { -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG mContext = cx; JS_ASSERT(JS_IsInRequest(JS_GetRuntime(cx))); #endif @@ -1385,14 +1352,14 @@ class JSAutoCheckRequest } ~JSAutoCheckRequest() { -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG JS_ASSERT(JS_IsInRequest(JS_GetRuntime(mContext))); #endif } private: -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG JSContext *mContext; #endif MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER @@ -1448,54 +1415,122 @@ JS_StringToVersion(const char *string); namespace JS { -class JS_PUBLIC_API(ContextOptions) { +class JS_PUBLIC_API(RuntimeOptions) { public: - ContextOptions() - : extraWarnings_(false), + RuntimeOptions() + : baseline_(false), + ion_(false), + asmJS_(false), + nativeRegExp_(false), werror_(false), - varObjFix_(false), - privateIsNSISupports_(false), - dontReportUncaught_(false), - noDefaultCompartmentObject_(false), - noScriptRval_(false), strictMode_(false), - baseline_(false), - typeInference_(false), - ion_(false), - asmJS_(false) + varObjFix_(false) { } - bool extraWarnings() const { return extraWarnings_; } - ContextOptions &setExtraWarnings(bool flag) { - extraWarnings_ = flag; + bool baseline() const { return baseline_; } + RuntimeOptions &setBaseline(bool flag) { + baseline_ = flag; return *this; } - ContextOptions &toggleExtraWarnings() { - extraWarnings_ = !extraWarnings_; + RuntimeOptions &toggleBaseline() { + baseline_ = !baseline_; + return *this; + } + + bool ion() const { return ion_; } + RuntimeOptions &setIon(bool flag) { + ion_ = flag; + return *this; + } + RuntimeOptions &toggleIon() { + ion_ = !ion_; + return *this; + } + + bool asmJS() const { return asmJS_; } + RuntimeOptions &setAsmJS(bool flag) { + asmJS_ = flag; + return *this; + } + RuntimeOptions &toggleAsmJS() { + asmJS_ = !asmJS_; + return *this; + } + + bool nativeRegExp() const { return nativeRegExp_; } + RuntimeOptions &setNativeRegExp(bool flag) { + nativeRegExp_ = flag; return *this; } bool werror() const { return werror_; } - ContextOptions &setWerror(bool flag) { + RuntimeOptions &setWerror(bool flag) { werror_ = flag; return *this; } - ContextOptions &toggleWerror() { + RuntimeOptions &toggleWerror() { werror_ = !werror_; return *this; } + bool strictMode() const { return strictMode_; } + RuntimeOptions &setStrictMode(bool flag) { + strictMode_ = flag; + return *this; + } + RuntimeOptions &toggleStrictMode() { + strictMode_ = !strictMode_; + return *this; + } + bool varObjFix() const { return varObjFix_; } - ContextOptions &setVarObjFix(bool flag) { + RuntimeOptions &setVarObjFix(bool flag) { varObjFix_ = flag; return *this; } - ContextOptions &toggleVarObjFix() { + RuntimeOptions &toggleVarObjFix() { varObjFix_ = !varObjFix_; return *this; } + private: + bool baseline_ : 1; + bool ion_ : 1; + bool asmJS_ : 1; + bool nativeRegExp_ : 1; + bool werror_ : 1; + bool strictMode_ : 1; + bool varObjFix_ : 1; +}; + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSRuntime *rt); + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSContext *cx); + +class JS_PUBLIC_API(ContextOptions) { + public: + ContextOptions() + : extraWarnings_(false), + privateIsNSISupports_(false), + dontReportUncaught_(false), + noDefaultCompartmentObject_(false), + noScriptRval_(false) + { + } + + bool extraWarnings() const { return extraWarnings_; } + ContextOptions &setExtraWarnings(bool flag) { + extraWarnings_ = flag; + return *this; + } + ContextOptions &toggleExtraWarnings() { + extraWarnings_ = !extraWarnings_; + return *this; + } + bool privateIsNSISupports() const { return privateIsNSISupports_; } ContextOptions &setPrivateIsNSISupports(bool flag) { privateIsNSISupports_ = flag; @@ -1536,69 +1571,12 @@ class JS_PUBLIC_API(ContextOptions) { return *this; } - bool strictMode() const { return strictMode_; } - ContextOptions &setStrictMode(bool flag) { - strictMode_ = flag; - return *this; - } - ContextOptions &toggleStrictMode() { - strictMode_ = !strictMode_; - return *this; - } - - bool baseline() const { return baseline_; } - ContextOptions &setBaseline(bool flag) { - baseline_ = flag; - return *this; - } - ContextOptions &toggleBaseline() { - baseline_ = !baseline_; - return *this; - } - - bool typeInference() const { return typeInference_; } - ContextOptions &setTypeInference(bool flag) { - typeInference_ = flag; - return *this; - } - ContextOptions &toggleTypeInference() { - typeInference_ = !typeInference_; - return *this; - } - - bool ion() const { return ion_; } - ContextOptions &setIon(bool flag) { - ion_ = flag; - return *this; - } - ContextOptions &toggleIon() { - ion_ = !ion_; - return *this; - } - - bool asmJS() const { return asmJS_; } - ContextOptions &setAsmJS(bool flag) { - asmJS_ = flag; - return *this; - } - ContextOptions &toggleAsmJS() { - asmJS_ = !asmJS_; - return *this; - } - private: bool extraWarnings_ : 1; - bool werror_ : 1; - bool varObjFix_ : 1; bool privateIsNSISupports_ : 1; bool dontReportUncaught_ : 1; bool noDefaultCompartmentObject_ : 1; bool noScriptRval_ : 1; - bool strictMode_ : 1; - bool baseline_ : 1; - bool typeInference_ : 1; - bool ion_ : 1; - bool asmJS_ : 1; }; JS_PUBLIC_API(ContextOptions &) @@ -1606,7 +1584,7 @@ ContextOptionsRef(JSContext *cx); class JS_PUBLIC_API(AutoSaveContextOptions) { public: - AutoSaveContextOptions(JSContext *cx) + explicit AutoSaveContextOptions(JSContext *cx) : cx_(cx), oldOptions_(ContextOptionsRef(cx_)) { @@ -1624,9 +1602,6 @@ class JS_PUBLIC_API(AutoSaveContextOptions) { } /* namespace JS */ -extern JS_PUBLIC_API(void) -JS_SetJitHardening(JSRuntime *rt, bool enabled); - extern JS_PUBLIC_API(const char *) JS_GetImplementationVersion(void); @@ -1663,14 +1638,11 @@ JS_WrapObject(JSContext *cx, JS::MutableHandleObject objp); extern JS_PUBLIC_API(bool) JS_WrapValue(JSContext *cx, JS::MutableHandleValue vp); -extern JS_PUBLIC_API(bool) -JS_WrapId(JSContext *cx, jsid *idp); - extern JS_PUBLIC_API(JSObject *) -JS_TransplantObject(JSContext *cx, JS::Handle origobj, JS::Handle target); +JS_TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target); extern JS_PUBLIC_API(bool) -JS_RefreshCrossCompartmentWrappers(JSContext *cx, JSObject *ob); +JS_RefreshCrossCompartmentWrappers(JSContext *cx, JS::Handle obj); /* * At any time, a JSContext has a current (possibly-nullptr) compartment. @@ -1717,6 +1689,15 @@ class JS_PUBLIC_API(JSAutoCompartment) ~JSAutoCompartment(); }; +class JS_PUBLIC_API(JSAutoNullableCompartment) +{ + JSContext *cx_; + JSCompartment *oldCompartment_; + public: + explicit JSAutoNullableCompartment(JSContext *cx, JSObject *targetOrNull); + ~JSAutoNullableCompartment(); +}; + /* NB: This API is infallible; a nullptr return value does not indicate error. */ extern JS_PUBLIC_API(JSCompartment *) JS_EnterCompartment(JSContext *cx, JSObject *target); @@ -1743,7 +1724,7 @@ JS_IterateCompartments(JSRuntime *rt, void *data, * NB: This sets cx's global object to obj if it was null. */ extern JS_PUBLIC_API(bool) -JS_InitStandardClasses(JSContext *cx, JSObject *obj); +JS_InitStandardClasses(JSContext *cx, JS::Handle obj); /* * Resolve id, which must contain either a string or an int, to a standard @@ -1759,20 +1740,40 @@ JS_InitStandardClasses(JSContext *cx, JSObject *obj); * loops any classes not yet resolved lazily. */ extern JS_PUBLIC_API(bool) -JS_ResolveStandardClass(JSContext *cx, JS::Handle obj, JS::Handle id, - bool *resolved); +JS_ResolveStandardClass(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *resolved); extern JS_PUBLIC_API(bool) -JS_EnumerateStandardClasses(JSContext *cx, JS::Handle obj); +JS_EnumerateStandardClasses(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, JSObject **objp); +JS_GetClassObject(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); extern JS_PUBLIC_API(bool) -JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JSObject **objp); +JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); + +namespace JS { + +/* + * Determine if the given object is an instance/prototype/constructor for a standard + * class. If so, return the associated JSProtoKey. If not, return JSProto_Null. + */ + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstance(JSObject *obj); extern JS_PUBLIC_API(JSProtoKey) -JS_IdentifyClassPrototype(JSContext *cx, JSObject *obj); +IdentifyStandardPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstanceOrPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardConstructor(JSObject *obj); + +extern JS_PUBLIC_API(void) +ProtoKeyToId(JSContext *cx, JSProtoKey key, JS::MutableHandleId idp); + +} /* namespace JS */ extern JS_PUBLIC_API(JSProtoKey) JS_IdToProtoKey(JSContext *cx, JS::HandleId id); @@ -1782,21 +1783,28 @@ JS_IdToProtoKey(JSContext *cx, JS::HandleId id); * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetFunctionPrototype(JSContext *cx, JSObject *forObj); +JS_GetFunctionPrototype(JSContext *cx, JS::HandleObject forObj); /* * Returns the original value of |Object.prototype| from the global object in * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetObjectPrototype(JSContext *cx, JSObject *forObj); +JS_GetObjectPrototype(JSContext *cx, JS::HandleObject forObj); /* * Returns the original value of |Array.prototype| from the global object in * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetArrayPrototype(JSContext *cx, JSObject *forObj); +JS_GetArrayPrototype(JSContext *cx, JS::HandleObject forObj); + +/* + * Returns the original value of |Error.prototype| from the global + * object of the current compartment of cx. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetErrorPrototype(JSContext *cx); extern JS_PUBLIC_API(JSObject *) JS_GetGlobalForObject(JSContext *cx, JSObject *obj); @@ -1818,23 +1826,11 @@ CurrentGlobalOrNull(JSContext *cx); } -/* - * This method returns the global corresponding to the most recent scripted - * frame, which may not match the cx's current compartment. This is extremely - * dangerous, because it can bypass compartment security invariants in subtle - * ways. To use it safely, the caller must perform a subsequent security - * check. There is currently only one consumer of this function in Gecko, and - * it should probably stay that way. If you'd like to use it, please consult - * the XPConnect module owner first. - */ -extern JS_PUBLIC_API(JSObject *) -JS_GetScriptedGlobal(JSContext *cx); - /* * Initialize the 'Reflect' object on a global object. */ extern JS_PUBLIC_API(JSObject *) -JS_InitReflect(JSContext *cx, JSObject *global); +JS_InitReflect(JSContext *cx, JS::HandleObject global); #ifdef JS_HAS_CTYPES /* @@ -1842,7 +1838,7 @@ JS_InitReflect(JSContext *cx, JSObject *global); * object will be sealed. */ extern JS_PUBLIC_API(bool) -JS_InitCTypesClass(JSContext *cx, JSObject *global); +JS_InitCTypesClass(JSContext *cx, JS::HandleObject global); /* * Convert a unicode string 'source' of length 'slen' to the platform native @@ -1917,6 +1913,7 @@ JS_strdup(JSContext *cx, const char *s); extern JS_PUBLIC_API(char *) JS_strdup(JSRuntime *rt, const char *s); +namespace JS { /* * A GC root is a pointer to a jsval, JSObject * or JSString * that itself @@ -1944,52 +1941,54 @@ JS_strdup(JSRuntime *rt, const char *s); * before freeing structPtr's memory. */ extern JS_PUBLIC_API(bool) -JS_AddValueRoot(JSContext *cx, jsval *vp); +AddValueRoot(JSContext *cx, JS::Heap *vp); extern JS_PUBLIC_API(bool) -JS_AddStringRoot(JSContext *cx, JSString **rp); +AddStringRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(bool) -JS_AddObjectRoot(JSContext *cx, JSObject **rp); +AddObjectRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(bool) -JS_AddNamedValueRoot(JSContext *cx, jsval *vp, const char *name); +AddNamedValueRoot(JSContext *cx, JS::Heap *vp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedValueRootRT(JSRuntime *rt, jsval *vp, const char *name); +AddNamedValueRootRT(JSRuntime *rt, JS::Heap *vp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedStringRoot(JSContext *cx, JSString **rp, const char *name); +AddNamedStringRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedObjectRoot(JSContext *cx, JSObject **rp, const char *name); +AddNamedObjectRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedScriptRoot(JSContext *cx, JSScript **rp, const char *name); +AddNamedScriptRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(void) -JS_RemoveValueRoot(JSContext *cx, jsval *vp); +RemoveValueRoot(JSContext *cx, JS::Heap *vp); extern JS_PUBLIC_API(void) -JS_RemoveStringRoot(JSContext *cx, JSString **rp); +RemoveStringRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveObjectRoot(JSContext *cx, JSObject **rp); +RemoveObjectRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveScriptRoot(JSContext *cx, JSScript **rp); +RemoveScriptRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveValueRootRT(JSRuntime *rt, jsval *vp); +RemoveValueRootRT(JSRuntime *rt, JS::Heap *vp); extern JS_PUBLIC_API(void) -JS_RemoveStringRootRT(JSRuntime *rt, JSString **rp); +RemoveStringRootRT(JSRuntime *rt, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveObjectRootRT(JSRuntime *rt, JSObject **rp); +RemoveObjectRootRT(JSRuntime *rt, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveScriptRootRT(JSRuntime *rt, JSScript **rp); +RemoveScriptRootRT(JSRuntime *rt, JS::Heap *rp); + +} /* namespace JS */ /* * Register externally maintained GC roots. @@ -2005,42 +2004,10 @@ JS_AddExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); extern JS_PUBLIC_API(void) JS_RemoveExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); -/* - * JS_CallTracer API and related macros for implementors of JSTraceOp, to - * enumerate all references to traceable things reachable via a property or - * other strong ref identified for debugging purposes by name or index or - * a naming callback. - * - * See the JSTraceOp typedef. - */ +#ifdef JS_DEBUG /* - * Use the following macros to check if a particular jsval is a traceable - * thing and to extract the thing and its kind to pass to JS_CallTracer. - */ -static JS_ALWAYS_INLINE bool -JSVAL_IS_TRACEABLE(jsval v) -{ - return JSVAL_IS_TRACEABLE_IMPL(JSVAL_TO_IMPL(v)); -} - -static JS_ALWAYS_INLINE void * -JSVAL_TO_TRACEABLE(jsval v) -{ - return JSVAL_TO_GCTHING(v); -} - -static JS_ALWAYS_INLINE JSGCTraceKind -JSVAL_TRACE_KIND(jsval v) -{ - JS_ASSERT(JSVAL_IS_GCTHING(v)); - return (JSGCTraceKind) JSVAL_TRACE_KIND_IMPL(JSVAL_TO_IMPL(v)); -} - -#ifdef DEBUG - -/* - * DEBUG-only method to dump the object graph of heap-allocated things. + * Debug-only method to dump the object graph of heap-allocated things. * * fp: file for the dump output. * start: when non-null, dump only things reachable from start @@ -2072,14 +2039,17 @@ JS_MaybeGC(JSContext *cx); extern JS_PUBLIC_API(void) JS_SetGCCallback(JSRuntime *rt, JSGCCallback cb, void *data); +extern JS_PUBLIC_API(bool) +JS_AddFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb, void *data); + extern JS_PUBLIC_API(void) -JS_SetFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); +JS_RemoveFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); extern JS_PUBLIC_API(bool) JS_IsGCMarkingTracer(JSTracer *trc); /* For assertions only. */ -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_PUBLIC_API(bool) JS_IsMarkingGray(JSTracer *trc); #endif @@ -2175,22 +2145,17 @@ typedef enum JSGCParamKey { * available to be decommitted, then JS_MaybeGC will trigger a shrinking GC * to decommit it. */ - JSGC_DECOMMIT_THRESHOLD = 20 -} JSGCParamKey; - -typedef enum JSGCMode { - /* Perform only global GCs. */ - JSGC_MODE_GLOBAL = 0, - - /* Perform per-compartment GCs until too much garbage has accumulated. */ - JSGC_MODE_COMPARTMENT = 1, + JSGC_DECOMMIT_THRESHOLD = 20, /* - * Collect in short time slices rather than all at once. Implies - * JSGC_MODE_COMPARTMENT. + * We try to keep at least this many unused chunks in the free chunk pool at + * all times, even after a shrinking GC. */ - JSGC_MODE_INCREMENTAL = 2 -} JSGCMode; + JSGC_MIN_EMPTY_CHUNK_COUNT = 21, + + /* We never keep more than this many unused chunks in the free chunk pool. */ + JSGC_MAX_EMPTY_CHUNK_COUNT = 22 +} JSGCParamKey; extern JS_PUBLIC_API(void) JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32_t value); @@ -2204,6 +2169,9 @@ JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32_t value); extern JS_PUBLIC_API(uint32_t) JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key); +extern JS_PUBLIC_API(void) +JS_SetGCParametersBasedOnAvailableMemory(JSRuntime *rt, uint32_t availMem); + /* * Create a new JSString whose chars member refers to external memory, i.e., * memory requiring application-specific finalization. @@ -2252,7 +2220,7 @@ extern JS_PUBLIC_API(int) JS_IdArrayLength(JSContext *cx, JSIdArray *ida); extern JS_PUBLIC_API(jsid) -JS_IdArrayGet(JSContext *cx, JSIdArray *ida, int index); +JS_IdArrayGet(JSContext *cx, JSIdArray *ida, unsigned index); extern JS_PUBLIC_API(void) JS_DestroyIdArray(JSContext *cx, JSIdArray *ida); @@ -2272,13 +2240,12 @@ class AutoIdArray : private AutoGCRooter if (idArray) JS_DestroyIdArray(context, idArray); } - bool operator!() { + bool operator!() const { return !idArray; } jsid operator[](size_t i) const { JS_ASSERT(idArray); - JS_ASSERT(i < length()); - return JS_IdArrayGet(context, idArray, i); + return JS_IdArrayGet(context, idArray, unsigned(i)); } size_t length() const { return JS_IdArrayLength(context, idArray); @@ -2308,15 +2275,13 @@ class AutoIdArray : private AutoGCRooter } /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_ValueToId(JSContext *cx, jsval v, jsid *idp); +JS_ValueToId(JSContext *cx, JS::HandleValue v, JS::MutableHandleId idp); extern JS_PUBLIC_API(bool) -JS_IdToValue(JSContext *cx, jsid id, jsval *vp); +JS_StringToId(JSContext *cx, JS::HandleString s, JS::MutableHandleId idp); -/* - * JSNewResolveOp flag bits. - */ -#define JSRESOLVE_ASSIGNING 0x01 /* resolve on the left of assignment */ +extern JS_PUBLIC_API(bool) +JS_IdToValue(JSContext *cx, jsid id, JS::MutableHandle vp); /* * Invoke the [[DefaultValue]] hook (see ES5 8.6.2) with the provided hint on @@ -2325,29 +2290,30 @@ JS_IdToValue(JSContext *cx, jsid id, jsval *vp); * success the resulting value is stored in *vp. */ extern JS_PUBLIC_API(bool) -JS_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp); +JS_DefaultValue(JSContext *cx, JS::Handle obj, JSType hint, + JS::MutableHandle vp); extern JS_PUBLIC_API(bool) -JS_PropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, - JS::MutableHandle vp); +JS_PropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_StrictPropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, bool strict, - JS::MutableHandle vp); +JS_StrictPropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_DeletePropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, +JS_DeletePropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_EnumerateStub(JSContext *cx, JS::Handle obj); +JS_EnumerateStub(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_ResolveStub(JSContext *cx, JS::Handle obj, JS::Handle id); +JS_ResolveStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id); extern JS_PUBLIC_API(bool) -JS_ConvertStub(JSContext *cx, JS::Handle obj, JSType type, - JS::MutableHandle vp); +JS_ConvertStub(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); struct JSConstDoubleSpec { double dval; @@ -2385,7 +2351,7 @@ typedef struct JSNativeWrapper { * Macro static initializers which make it easy to pass no JSJitInfo as part of a * JSPropertySpec or JSFunctionSpec. */ -#define JSOP_WRAPPER(op) {op, nullptr} +#define JSOP_WRAPPER(op) { {op, nullptr} } #define JSOP_NULLWRAPPER JSOP_WRAPPER(nullptr) /* @@ -2394,13 +2360,29 @@ typedef struct JSNativeWrapper { * JSPROP_INDEX bit in flags. */ struct JSPropertySpec { + struct SelfHostedWrapper { + void *unused; + const char *funname; + }; + const char *name; - int8_t tinyid; uint8_t flags; - JSPropertyOpWrapper getter; - JSStrictPropertyOpWrapper setter; - const char *selfHostedGetter; - const char *selfHostedSetter; + union { + JSPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } getter; + union { + JSStrictPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } setter; + +private: + void StaticAsserts() { + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSPropertyOpWrapper)); + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSStrictPropertyOpWrapper)); + JS_STATIC_ASSERT(offsetof(SelfHostedWrapper, funname) == + offsetof(JSPropertyOpWrapper, info)); + } }; namespace JS { @@ -2409,6 +2391,11 @@ namespace detail { /* NEVER DEFINED, DON'T USE. For use by JS_CAST_NATIVE_TO only. */ inline int CheckIsNative(JSNative native); +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_STRING_TO only. */ +template +inline int +CheckIsCharacterLiteral(const char (&arr)[N]); + } // namespace detail } // namespace JS @@ -2416,6 +2403,10 @@ inline int CheckIsNative(JSNative native); (static_cast(sizeof(JS::detail::CheckIsNative(v))), \ reinterpret_cast(v)) +#define JS_CAST_STRING_TO(s, To) \ + (static_cast(sizeof(JS::detail::CheckIsCharacterLiteral(s))), \ + reinterpret_cast(s)) + #define JS_CHECK_ACCESSOR_FLAGS(flags) \ (static_cast::Type>(0), \ (flags)) @@ -2428,26 +2419,26 @@ inline int CheckIsNative(JSNative native); * JSNatives. */ #define JS_PSG(name, getter, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ - JSOP_NULLWRAPPER, nullptr, nullptr} + JSOP_NULLWRAPPER} #define JS_PSGS(name, getter, setter, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ - JSOP_WRAPPER(JS_CAST_NATIVE_TO(setter, JSStrictPropertyOp)), \ - nullptr, nullptr} + JSOP_WRAPPER(JS_CAST_NATIVE_TO(setter, JSStrictPropertyOp))} #define JS_SELF_HOSTED_GET(name, getterName, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER), \ - JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, getterName, nullptr} + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + JSOP_NULLWRAPPER } #define JS_SELF_HOSTED_GETSET(name, getterName, setterName, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER | JSPROP_SETTER), \ - JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, getterName, setterName} -#define JS_PS_END {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, \ - nullptr, nullptr} + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + { nullptr, JS_CAST_STRING_TO(setterName, const JSJitInfo *) } } +#define JS_PS_END { nullptr, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER } /* * To define a native function, set call to a JSNativeWrapper. To define a @@ -2487,7 +2478,7 @@ struct JSFunctionSpec { {name, {call, info}, nargs, flags, selfHostedName} extern JS_PUBLIC_API(JSObject *) -JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, +JS_InitClass(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent_proto, const JSClass *clasp, JSNative constructor, unsigned nargs, const JSPropertySpec *ps, const JSFunctionSpec *fs, const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs); @@ -2497,16 +2488,17 @@ JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, * right property flags. */ extern JS_PUBLIC_API(bool) -JS_LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor, JSObject *proto); +JS_LinkConstructorAndPrototype(JSContext *cx, JS::Handle ctor, + JS::Handle proto); extern JS_PUBLIC_API(const JSClass *) JS_GetClass(JSObject *obj); extern JS_PUBLIC_API(bool) -JS_InstanceOf(JSContext *cx, JSObject *obj, const JSClass *clasp, jsval *argv); +JS_InstanceOf(JSContext *cx, JS::Handle obj, const JSClass *clasp, JS::CallArgs *args); extern JS_PUBLIC_API(bool) -JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, bool *bp); +JS_HasInstance(JSContext *cx, JS::Handle obj, JS::Handle v, bool *bp); extern JS_PUBLIC_API(void *) JS_GetPrivate(JSObject *obj); @@ -2515,31 +2507,23 @@ extern JS_PUBLIC_API(void) JS_SetPrivate(JSObject *obj, void *data); extern JS_PUBLIC_API(void *) -JS_GetInstancePrivate(JSContext *cx, JSObject *obj, const JSClass *clasp, - jsval *argv); +JS_GetInstancePrivate(JSContext *cx, JS::Handle obj, const JSClass *clasp, + JS::CallArgs *args); extern JS_PUBLIC_API(bool) -JS_GetPrototype(JSContext *cx, JS::Handle obj, JS::MutableHandle protop); +JS_GetPrototype(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject protop); extern JS_PUBLIC_API(bool) -JS_SetPrototype(JSContext *cx, JS::Handle obj, JS::Handle proto); +JS_SetPrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); extern JS_PUBLIC_API(JSObject *) JS_GetParent(JSObject *obj); extern JS_PUBLIC_API(bool) -JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent); +JS_SetParent(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent); extern JS_PUBLIC_API(JSObject *) -JS_GetConstructor(JSContext *cx, JSObject *proto); - -/* - * Get a unique identifier for obj, good for the lifetime of obj (even if it - * is moved by a copying GC). Return false on failure (likely out of memory), - * and true with *idp containing the unique id on success. - */ -extern JS_PUBLIC_API(bool) -JS_GetObjectId(JSContext *cx, JSObject *obj, jsid *idp); +JS_GetConstructor(JSContext *cx, JS::Handle proto); namespace JS { @@ -2582,6 +2566,12 @@ class JS_PUBLIC_API(CompartmentOptions) explicit CompartmentOptions() : version_(JSVERSION_UNKNOWN) , invisibleToDebugger_(false) + , mergeable_(false) + , discardSource_(false) + , cloneSingletons_(false) + , traceGlobal_(nullptr) + , singletonsAsTemplates_(true) + , addonId_(nullptr) { zone_.spec = JS::FreshZone; } @@ -2597,23 +2587,36 @@ class JS_PUBLIC_API(CompartmentOptions) // of the embedding, and references to them should never leak out to script. // This flag causes the this compartment to skip firing onNewGlobalObject // and makes addDebuggee a no-op for this global. - bool invisibleToDebugger() { return invisibleToDebugger_; } + bool invisibleToDebugger() const { return invisibleToDebugger_; } CompartmentOptions &setInvisibleToDebugger(bool flag) { invisibleToDebugger_ = flag; return *this; } - bool baseline(JSContext *cx) const; - Override &baselineOverride() { return baselineOverride_; } + // Compartments used for off-thread compilation have their contents merged + // into a target compartment when the compilation is finished. This is only + // allowed if this flag is set. The invisibleToDebugger flag must also be + // set for such compartments. + bool mergeable() const { return mergeable_; } + CompartmentOptions &setMergeable(bool flag) { + mergeable_ = flag; + return *this; + } - bool typeInference(const js::ExclusiveContext *cx) const; - Override &typeInferenceOverride() { return typeInferenceOverride_; } + // For certain globals, we know enough about the code that will run in them + // that we can discard script source entirely. + bool discardSource() const { return discardSource_; } + CompartmentOptions &setDiscardSource(bool flag) { + discardSource_ = flag; + return *this; + } - bool ion(JSContext *cx) const; - Override &ionOverride() { return ionOverride_; } - bool asmJS(JSContext *cx) const; - Override &asmJSOverride() { return asmJSOverride_; } + bool cloneSingletons() const { return cloneSingletons_; } + CompartmentOptions &setCloneSingletons(bool flag) { + cloneSingletons_ = flag; + return *this; + } void *zonePointer() const { JS_ASSERT(uintptr_t(zone_.pointer) > uintptr_t(JS::SystemZone)); @@ -2623,22 +2626,55 @@ class JS_PUBLIC_API(CompartmentOptions) CompartmentOptions &setZone(ZoneSpecifier spec); CompartmentOptions &setSameZoneAs(JSObject *obj); + void setSingletonsAsValues() { + singletonsAsTemplates_ = false; + } + bool getSingletonsAsTemplates() const { + return singletonsAsTemplates_; + }; + + // A null add-on ID means that the compartment is not associated with an + // add-on. + JSAddonId *addonIdOrNull() const { return addonId_; } + CompartmentOptions &setAddonId(JSAddonId *id) { + addonId_ = id; + return *this; + } + + CompartmentOptions &setTrace(JSTraceOp op) { + traceGlobal_ = op; + return *this; + } + JSTraceOp getTrace() const { + return traceGlobal_; + } + private: JSVersion version_; bool invisibleToDebugger_; - Override baselineOverride_; - Override typeInferenceOverride_; - Override ionOverride_; - Override asmJSOverride_; + bool mergeable_; + bool discardSource_; + bool cloneSingletons_; union { ZoneSpecifier spec; void *pointer; // js::Zone* is not exposed in the API. } zone_; + JSTraceOp traceGlobal_; + + // To XDR singletons, we need to ensure that all singletons are all used as + // templates, by making JSOP_OBJECT return a clone of the JSScript + // singleton, instead of returning the value which is baked in the JSScript. + bool singletonsAsTemplates_; + + JSAddonId *addonId_; }; JS_PUBLIC_API(CompartmentOptions &) CompartmentOptionsRef(JSCompartment *compartment); +JS_PUBLIC_API(CompartmentOptions &) +CompartmentOptionsRef(JSObject *obj); + JS_PUBLIC_API(CompartmentOptions &) CompartmentOptionsRef(JSContext *cx); @@ -2673,16 +2709,28 @@ extern JS_PUBLIC_API(JSObject *) JS_NewGlobalObject(JSContext *cx, const JSClass *clasp, JSPrincipals *principals, JS::OnNewGlobalHookOption hookOption, const JS::CompartmentOptions &options = JS::CompartmentOptions()); +/* + * Spidermonkey does not have a good way of keeping track of what compartments should be marked on + * their own. We can mark the roots unconditionally, but marking GC things only relevant in live + * compartments is hard. To mitigate this, we create a static trace hook, installed on each global + * object, from which we can be sure the compartment is relevant, and mark it. + * + * It is still possible to specify custom trace hooks for global object classes. They can be + * provided via the CompartmentOptions passed to JS_NewGlobalObject. + */ +extern JS_PUBLIC_API(void) +JS_GlobalObjectTraceHook(JSTracer *trc, JSObject *global); extern JS_PUBLIC_API(void) JS_FireOnNewGlobalObject(JSContext *cx, JS::HandleObject global); extern JS_PUBLIC_API(JSObject *) -JS_NewObject(JSContext *cx, const JSClass *clasp, JSObject *proto, JSObject *parent); +JS_NewObject(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); /* Queries the [[Extensible]] property of the object. */ extern JS_PUBLIC_API(bool) -JS_IsExtensible(JSContext *cx, JS::Handle obj, bool *extensible); +JS_IsExtensible(JSContext *cx, JS::HandleObject obj, bool *extensible); extern JS_PUBLIC_API(bool) JS_IsNative(JSObject *obj); @@ -2695,8 +2743,8 @@ JS_GetObjectRuntime(JSObject *obj); * proto if proto's actual parameter value is null. */ extern JS_PUBLIC_API(JSObject *) -JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JSObject *proto, - JSObject *parent); +JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); /* * Freeze obj, and all objects it refers to, recursively. This will not recurse @@ -2704,88 +2752,126 @@ JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JSObject *proto, * deep-frozen. */ extern JS_PUBLIC_API(bool) -JS_DeepFreezeObject(JSContext *cx, JSObject *obj); +JS_DeepFreezeObject(JSContext *cx, JS::Handle obj); /* * Freezes an object; see ES5's Object.freeze(obj) method. */ extern JS_PUBLIC_API(bool) -JS_FreezeObject(JSContext *cx, JSObject *obj); +JS_FreezeObject(JSContext *cx, JS::Handle obj); extern JS_PUBLIC_API(bool) -JS_PreventExtensions(JSContext *cx, JS::Handle obj); +JS_PreventExtensions(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(JSObject *) -JS_New(JSContext *cx, JSObject *ctor, unsigned argc, jsval *argv); +JS_New(JSContext *cx, JS::HandleObject ctor, const JS::HandleValueArray& args); extern JS_PUBLIC_API(JSObject *) -JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, const JSClass *clasp, - JSObject *proto, unsigned attrs); +JS_DefineObject(JSContext *cx, JS::HandleObject obj, const char *name, + const JSClass *clasp = nullptr, JS::HandleObject proto = JS::NullPtr(), + unsigned attrs = 0); extern JS_PUBLIC_API(bool) -JS_DefineConstDoubles(JSContext *cx, JSObject *obj, const JSConstDoubleSpec *cds); +JS_DefineConstDoubles(JSContext *cx, JS::HandleObject obj, const JSConstDoubleSpec *cds); extern JS_PUBLIC_API(bool) -JS_DefineProperties(JSContext *cx, JSObject *obj, const JSPropertySpec *ps); +JS_DefineProperties(JSContext *cx, JS::HandleObject obj, const JSPropertySpec *ps); extern JS_PUBLIC_API(bool) -JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id, jsval descriptor, bool *bp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name, - int8_t tinyid, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name, - bool *foundp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnPropertyById(JSContext *cx, JSObject *obj, jsid id, - bool *foundp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, bool *foundp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, bool *foundp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name, - unsigned flags, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id, - unsigned flags, JSObject **objp, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnProperty(JSContext *cx, JS::HandleObject obj, const char *name, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasProperty(JSContext *cx, JS::HandleObject obj, const char *name, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_LookupPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); struct JSPropertyDescriptor { JSObject *obj; unsigned attrs; - unsigned shortid; JSPropertyOp getter; JSStrictPropertyOp setter; JS::Value value; - JSPropertyDescriptor() : obj(nullptr), attrs(0), shortid(0), getter(nullptr), - setter(nullptr), value(JSVAL_VOID) + JSPropertyDescriptor() + : obj(nullptr), attrs(0), getter(nullptr), setter(nullptr), value(JSVAL_VOID) {} void trace(JSTracer *trc); + + static js::ThingRootKind rootKind() { return js::THING_ROOT_PROPERTY_DESCRIPTOR; } }; namespace JS { @@ -2803,30 +2889,29 @@ class PropertyDescriptorOperations bool hasGetterObject() const { return desc()->attrs & JSPROP_GETTER; } bool hasSetterObject() const { return desc()->attrs & JSPROP_SETTER; } bool hasGetterOrSetterObject() const { return desc()->attrs & (JSPROP_GETTER | JSPROP_SETTER); } + bool hasGetterOrSetter() const { return desc()->getter || desc()->setter; } bool isShared() const { return desc()->attrs & JSPROP_SHARED; } bool isIndex() const { return desc()->attrs & JSPROP_INDEX; } - bool hasShortId() const { return desc()->attrs & JSPROP_SHORTID; } bool hasAttributes(unsigned attrs) const { return desc()->attrs & attrs; } - JS::Handle object() const { - return JS::Handle::fromMarkedLocation(&desc()->obj); + JS::HandleObject object() const { + return JS::HandleObject::fromMarkedLocation(&desc()->obj); } unsigned attributes() const { return desc()->attrs; } - unsigned shortid() const { return desc()->shortid; } JSPropertyOp getter() const { return desc()->getter; } JSStrictPropertyOp setter() const { return desc()->setter; } - JS::Handle getterObject() const { + JS::HandleObject getterObject() const { MOZ_ASSERT(hasGetterObject()); - return JS::Handle::fromMarkedLocation( + return JS::HandleObject::fromMarkedLocation( reinterpret_cast(&desc()->getter)); } - JS::Handle setterObject() const { + JS::HandleObject setterObject() const { MOZ_ASSERT(hasSetterObject()); - return JS::Handle::fromMarkedLocation( + return JS::HandleObject::fromMarkedLocation( reinterpret_cast(&desc()->setter)); } - JS::Handle value() const { - return JS::Handle::fromMarkedLocation(&desc()->value); + JS::HandleValue value() const { + return JS::HandleValue::fromMarkedLocation(&desc()->value); } }; @@ -2840,30 +2925,47 @@ class MutablePropertyDescriptorOperations : public PropertyDescriptorOperations< void clear() { object().set(nullptr); setAttributes(0); - setShortId(0); setGetter(nullptr); setSetter(nullptr); value().setUndefined(); } - JS::MutableHandle object() { - return JS::MutableHandle::fromMarkedLocation(&desc()->obj); + void assign(JSPropertyDescriptor &other) { + object().set(other.obj); + setAttributes(other.attrs); + setGetter(other.getter); + setSetter(other.setter); + value().set(other.value); + } + + JS::MutableHandleObject object() { + return JS::MutableHandleObject::fromMarkedLocation(&desc()->obj); } unsigned &attributesRef() { return desc()->attrs; } JSPropertyOp &getter() { return desc()->getter; } JSStrictPropertyOp &setter() { return desc()->setter; } - JS::MutableHandle value() { - return JS::MutableHandle::fromMarkedLocation(&desc()->value); + JS::MutableHandleValue value() { + return JS::MutableHandleValue::fromMarkedLocation(&desc()->value); } void setEnumerable() { desc()->attrs |= JSPROP_ENUMERATE; } void setAttributes(unsigned attrs) { desc()->attrs = attrs; } - void setShortId(unsigned id) { desc()->shortid = id; } void setGetter(JSPropertyOp op) { desc()->getter = op; } void setSetter(JSStrictPropertyOp op) { desc()->setter = op; } void setGetterObject(JSObject *obj) { desc()->getter = reinterpret_cast(obj); } void setSetterObject(JSObject *obj) { desc()->setter = reinterpret_cast(obj); } + + JS::MutableHandleObject getterObject() { + MOZ_ASSERT(this->hasGetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->getter)); + } + JS::MutableHandleObject setterObject() { + MOZ_ASSERT(this->hasSetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->setter)); + } }; } /* namespace JS */ @@ -2873,7 +2975,6 @@ namespace js { template <> struct GCMethods { static JSPropertyDescriptor initial() { return JSPropertyDescriptor(); } - static ThingRootKind kind() { return THING_ROOT_PROPERTY_DESCRIPTOR; } static bool poisoned(const JSPropertyDescriptor &desc) { return (desc.obj && JS::IsPoisonedPtr(desc.obj)) || (desc.attrs & JSPROP_GETTER && desc.getter && JS::IsPoisonedPtr(desc.getter)) || @@ -2922,12 +3023,22 @@ class MutableHandleBase } /* namespace js */ +namespace JS { + +extern JS_PUBLIC_API(bool) +ParsePropertyDescriptorObject(JSContext *cx, + JS::HandleObject obj, + JS::HandleValue descriptor, + JS::MutableHandle desc); + +} // namespace JS + extern JS_PUBLIC_API(bool) -JS_GetOwnPropertyDescriptorById(JSContext *cx, JSObject *objArg, jsid id, unsigned flags, +JS_GetOwnPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, const char *name, unsigned flags, +JS_GetOwnPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandle desc); /* @@ -2936,138 +3047,193 @@ JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, const char *name, u * then this property was not found on the prototype chain. */ extern JS_PUBLIC_API(bool) -JS_GetPropertyDescriptorById(JSContext *cx, JSObject *obj, jsid id, unsigned flags, +JS_GetPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetPropertyDescriptor(JSContext *cx, JSObject *obj, const char *name, unsigned flags, +JS_GetPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, JS::MutableHandle vp); +JS_GetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetPropertyTo(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject onBehalfOf, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); +JS_SetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_ForwardGetPropertyTo(JSContext *cx, JSObject *obj, jsid id, JSObject *onBehalfOf, - JS::MutableHandle vp); +JS_DeleteProperty(JSContext *cx, JS::HandleObject obj, const char *name); extern JS_PUBLIC_API(bool) -JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, JS::Handle v); +JS_DeleteProperty2(JSContext *cx, JS::HandleObject obj, const char *name, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_SetPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::Handle v); +JS_DeletePropertyById(JSContext *cx, JS::HandleObject obj, jsid id); extern JS_PUBLIC_API(bool) -JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name); +JS_DeletePropertyById2(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name, bool *succeeded); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleValue value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DeletePropertyById(JSContext *cx, JSObject *obj, jsid id); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleObject value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, bool *succeeded); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleString value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineUCProperty(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + int32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, - int8_t tinyid, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + uint32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnUCProperty(JSContext *cx, JSObject *obj, const jschar *name, +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + double value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *foundp); extern JS_PUBLIC_API(bool) -JS_HasUCProperty(JSContext *cx, JSObject *obj, +JS_HasUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *vp); extern JS_PUBLIC_API(bool) -JS_LookupUCProperty(JSContext *cx, JSObject *obj, +JS_LookupUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::MutableHandle vp); + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_GetUCProperty(JSContext *cx, JSObject *obj, +JS_GetUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::MutableHandle vp); + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_SetUCProperty(JSContext *cx, JSObject *obj, +JS_SetUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::Handle v); + JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_DeleteUCProperty2(JSContext *cx, JSObject *obj, const jschar *name, size_t namelen, +JS_DeleteUCProperty2(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *succeeded); extern JS_PUBLIC_API(JSObject *) -JS_NewArrayObject(JSContext *cx, int length, jsval *vector); +JS_NewArrayObject(JSContext *cx, const JS::HandleValueArray& contents); + +extern JS_PUBLIC_API(JSObject *) +JS_NewArrayObject(JSContext *cx, size_t length); extern JS_PUBLIC_API(bool) -JS_IsArrayObject(JSContext *cx, JSObject *obj); +JS_IsArrayObject(JSContext *cx, JS::HandleValue value); extern JS_PUBLIC_API(bool) -JS_GetArrayLength(JSContext *cx, JSObject *obj, uint32_t *lengthp); +JS_IsArrayObject(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_SetArrayLength(JSContext *cx, JSObject *obj, uint32_t length); +JS_GetArrayLength(JSContext *cx, JS::Handle obj, uint32_t *lengthp); extern JS_PUBLIC_API(bool) -JS_DefineElement(JSContext *cx, JSObject *obj, uint32_t index, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_SetArrayLength(JSContext *cx, JS::Handle obj, uint32_t length); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnElement(JSContext *cx, JSObject *obj, uint32_t index, bool *foundp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasElement(JSContext *cx, JSObject *obj, uint32_t index, bool *foundp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_GetElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_ForwardGetElementTo(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf, - JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetElementTo(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::HandleObject onBehalfOf, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t v); -/* - * Get the property with name given by |index|, if it has one. If - * not, |*present| will be set to false and the value of |vp| must not - * be relied on. - */ extern JS_PUBLIC_API(bool) -JS_GetElementIfPresent(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf, - JS::MutableHandle vp, bool* present); +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t v); extern JS_PUBLIC_API(bool) -JS_SetElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double v); extern JS_PUBLIC_API(bool) -JS_DeleteElement(JSContext *cx, JSObject *obj, uint32_t index); +JS_DeleteElement(JSContext *cx, JS::HandleObject obj, uint32_t index); extern JS_PUBLIC_API(bool) -JS_DeleteElement2(JSContext *cx, JSObject *obj, uint32_t index, bool *succeeded); +JS_DeleteElement2(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded); /* * Remove all configurable properties from the given (non-global) object and * assign undefined to all writable data properties. */ JS_PUBLIC_API(void) -JS_ClearNonGlobalObject(JSContext *cx, JSObject *objArg); +JS_ClearNonGlobalObject(JSContext *cx, JS::HandleObject obj); /* * Assign 'undefined' to all of the object's non-reserved slots. Note: this is @@ -3077,48 +3243,64 @@ JS_PUBLIC_API(void) JS_SetAllNonReservedSlotsToUndefined(JSContext *cx, JSObject *objArg); /* - * Create a new array buffer with the given contents, which must have been - * returned by JS_AllocateArrayBufferContents or JS_StealArrayBufferContents. - * The new array buffer takes ownership. After calling this function, do not - * free |contents| or use |contents| from another thread. + * Create a new array buffer with the given contents. On success, the ownership + * is transferred to the new array buffer. */ extern JS_PUBLIC_API(JSObject *) -JS_NewArrayBufferWithContents(JSContext *cx, void *contents); +JS_NewArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); /* * Steal the contents of the given array buffer. The array buffer has its * length set to 0 and its contents array cleared. The caller takes ownership - * of |*contents| and must free it or transfer ownership via + * of the return value and must free it or transfer ownership via * JS_NewArrayBufferWithContents when done using it. - * To free |*contents|, call free(). - * A pointer to the buffer's data is returned in |*data|. This pointer can - * be used until |*contents| is freed or has its ownership transferred. */ -extern JS_PUBLIC_API(bool) -JS_StealArrayBufferContents(JSContext *cx, JS::HandleObject obj, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_StealArrayBufferContents(JSContext *cx, JS::HandleObject obj); /* * Allocate memory that may be eventually passed to - * JS_NewArrayBufferWithContents. |nbytes| is the number of payload bytes - * required. The pointer to pass to JS_NewArrayBufferWithContents is returned - * in |contents|. The pointer to the |nbytes| of usable memory is returned in - * |data|. (*|contents| will contain a header before |data|.) The only legal - * operations on *|contents| is to free it, or pass it to - * JS_NewArrayBufferWithContents or JS_ReallocateArrayBufferContents. + * JS_NewArrayBufferWithContents. |maybecx| is optional; if a non-nullptr cx is + * given, it will be used for memory accounting and OOM reporting. |nbytes| is + * the number of payload bytes required. */ -extern JS_PUBLIC_API(bool) -JS_AllocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_AllocateArrayBufferContents(JSContext *maybecx, uint32_t nbytes); /* * Reallocate memory allocated by JS_AllocateArrayBufferContents, growing or - * shrinking it as appropriate. The new data pointer will be returned in data. - * If *contents is nullptr, behaves like JS_AllocateArrayBufferContents. + * shrinking it as appropriate. If oldContents is null then this behaves like + * JS_AllocateArrayBufferContents. */ -extern JS_PUBLIC_API(bool) -JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void *oldContents, uint32_t oldNbytes); + +/* + * Create a new mapped array buffer with the given memory mapped contents. On success, + * the ownership is transferred to the new mapped array buffer. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewMappedArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); + +/* + * Create memory mapped array buffer contents. + * Caller must take care of closing fd after calling this function. + */ +extern JS_PUBLIC_API(void *) +JS_CreateMappedArrayBufferContents(int fd, size_t offset, size_t length); + +/* + * Release the allocated resource of mapped array buffer contents before the + * object is created. + * If a new object has been created by JS_NewMappedArrayBufferWithContents() + * with this content, then JS_NeuterArrayBuffer() should be used instead to + * release the resource used by the object. + */ +extern JS_PUBLIC_API(void) +JS_ReleaseMappedArrayBufferContents(void *contents, size_t length); extern JS_PUBLIC_API(JSIdArray *) -JS_Enumerate(JSContext *cx, JSObject *obj); +JS_Enumerate(JSContext *cx, JS::HandleObject obj); /* * Create an object to iterate over enumerable properties of obj, in arbitrary @@ -3126,7 +3308,7 @@ JS_Enumerate(JSContext *cx, JSObject *obj); * order, which uses order of property definition in obj. */ extern JS_PUBLIC_API(JSObject *) -JS_NewPropertyIterator(JSContext *cx, JSObject *obj); +JS_NewPropertyIterator(JSContext *cx, JS::Handle obj); /* * Return true on success with *idp containing the id of the next enumerable @@ -3134,11 +3316,7 @@ JS_NewPropertyIterator(JSContext *cx, JSObject *obj); * left to visit. Return false on error. */ extern JS_PUBLIC_API(bool) -JS_NextProperty(JSContext *cx, JSObject *iterobj, jsid *idp); - -extern JS_PUBLIC_API(bool) -JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, - jsval *vp, unsigned *attrsp); +JS_NextProperty(JSContext *cx, JS::Handle iterobj, jsid *idp); extern JS_PUBLIC_API(jsval) JS_GetReservedSlot(JSObject *obj, uint32_t index); @@ -3148,84 +3326,12 @@ JS_SetReservedSlot(JSObject *obj, uint32_t index, jsval v); /************************************************************************/ -/* - * Security protocol. - */ -struct JSPrincipals { - /* Don't call "destroy"; use reference counting macros below. */ -#ifdef JS_THREADSAFE - mozilla::Atomic refcount; -#else - int32_t refcount; -#endif - -#ifdef DEBUG - /* A helper to facilitate principals debugging. */ - uint32_t debugToken; -#endif - - void setDebugToken(uint32_t token) { -# ifdef DEBUG - debugToken = token; -# endif - } - - /* - * This is not defined by the JS engine but should be provided by the - * embedding. - */ - JS_PUBLIC_API(void) dump(); -}; - -extern JS_PUBLIC_API(void) -JS_HoldPrincipals(JSPrincipals *principals); - -extern JS_PUBLIC_API(void) -JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals); - -struct JSSecurityCallbacks { - JSCheckAccessOp checkObjectAccess; - JSCSPEvalChecker contentSecurityPolicyAllows; - JSSubsumesOp subsumes; -}; - -extern JS_PUBLIC_API(void) -JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks); - -extern JS_PUBLIC_API(const JSSecurityCallbacks *) -JS_GetSecurityCallbacks(JSRuntime *rt); - -/* - * Code running with "trusted" principals will be given a deeper stack - * allocation than ordinary scripts. This allows trusted script to run after - * untrusted script has exhausted the stack. This function sets the - * runtime-wide trusted principal. - * - * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since - * there is no available JSContext. Instead, the caller must ensure that the - * given principals stays valid for as long as 'rt' may point to it. If the - * principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be - * called again, passing nullptr for 'prin'. - */ -extern JS_PUBLIC_API(void) -JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin); - -/* - * Initialize the callback that is called to destroy JSPrincipals instance - * when its reference counter drops to zero. The initialization can be done - * only once per JS runtime. - */ -extern JS_PUBLIC_API(void) -JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals); - -/************************************************************************/ - /* * Functions and scripts. */ extern JS_PUBLIC_API(JSFunction *) JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, - JSObject *parent, const char *name); + JS::Handle parent, const char *name); /* * Create the function with the name given by the id. JSID_IS_STRING(id) must @@ -3233,12 +3339,13 @@ JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, */ extern JS_PUBLIC_API(JSFunction *) JS_NewFunctionById(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, - JSObject *parent, jsid id); + JS::Handle parent, JS::Handle id); namespace JS { extern JS_PUBLIC_API(JSFunction *) -GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, jsid id, unsigned nargs); +GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, JS::Handle id, + unsigned nargs); } /* namespace JS */ @@ -3295,22 +3402,22 @@ JS_IsConstructor(JSFunction *fun); * If |callable| is not callable, will throw and return nullptr. */ extern JS_PUBLIC_API(JSObject*) -JS_BindCallable(JSContext *cx, JSObject *callable, JSObject *newThis); +JS_BindCallable(JSContext *cx, JS::Handle callable, JS::Handle newThis); extern JS_PUBLIC_API(bool) -JS_DefineFunctions(JSContext *cx, JSObject *obj, const JSFunctionSpec *fs); +JS_DefineFunctions(JSContext *cx, JS::Handle obj, const JSFunctionSpec *fs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call, +JS_DefineFunction(JSContext *cx, JS::Handle obj, const char *name, JSNative call, unsigned nargs, unsigned attrs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineUCFunction(JSContext *cx, JSObject *obj, +JS_DefineUCFunction(JSContext *cx, JS::Handle obj, const jschar *name, size_t namelen, JSNative call, unsigned nargs, unsigned attrs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call, +JS_DefineFunctionById(JSContext *cx, JS::Handle obj, JS::Handle id, JSNative call, unsigned nargs, unsigned attrs); /* @@ -3318,7 +3425,7 @@ JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call, * fail if funobj was lexically nested inside some other function. */ extern JS_PUBLIC_API(JSObject *) -JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent); +JS_CloneFunctionObject(JSContext *cx, JS::Handle funobj, JS::Handle parent); /* * Given a buffer, return false if the buffer might become a valid @@ -3328,32 +3435,49 @@ JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent); * the compiler. */ extern JS_PUBLIC_API(bool) -JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj, const char *utf8, size_t length); +JS_BufferIsCompilableUnit(JSContext *cx, JS::Handle obj, const char *utf8, + size_t length); -extern JS_PUBLIC_API(JSScript *) +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileScript(JSContext *cx, JS::HandleObject obj, const char *ascii, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileUCScript(JSContext *cx, JS::HandleObject obj, const jschar *chars, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleScript script); extern JS_PUBLIC_API(JSObject *) JS_GetGlobalFromScript(JSScript *script); -extern JS_PUBLIC_API(JSFunction *) +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileFunction(JSContext *cx, JS::HandleObject obj, const char *name, unsigned nargs, const char *const *argnames, const char *bytes, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); -extern JS_PUBLIC_API(JSFunction *) +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileUCFunction(JSContext *cx, JS::HandleObject obj, const char *name, unsigned nargs, const char *const *argnames, const jschar *chars, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); namespace JS { @@ -3401,12 +3525,14 @@ namespace JS { * is protected anyway); instead, create instances only of the derived classes: * CompileOptions and OwningCompileOptions. */ -class JS_PUBLIC_API(ReadOnlyCompileOptions) +class JS_FRIEND_API(ReadOnlyCompileOptions) { + friend class CompileOptions; + protected: - JSPrincipals *principals_; JSPrincipals *originPrincipals_; const char *filename_; + const char *introducerFilename_; const jschar *sourceMapURL_; // This constructor leaves 'version' set to JSVERSION_UNKNOWN. The structure @@ -3414,9 +3540,9 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) // classes' constructors take care of that, in ways appropriate to their // purpose. ReadOnlyCompileOptions() - : principals_(nullptr), - originPrincipals_(nullptr), + : originPrincipals_(nullptr), filename_(nullptr), + introducerFilename_(nullptr), sourceMapURL_(nullptr), version(JSVERSION_UNKNOWN), versionSet(false), @@ -3425,6 +3551,7 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) column(0), compileAndGo(false), forEval(false), + defineOnScope(true), noScriptRval(false), selfHostingMode(false), canLazilyParse(true), @@ -3433,7 +3560,12 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) werrorOption(false), asmJSOption(false), forceAsync(false), - sourcePolicy(SAVE_SOURCE) + installedFile(false), + sourceIsLazy(false), + introductionType(nullptr), + introductionLineno(0), + introductionOffset(0), + hasIntroductionInfo(false) { } // Set all POD options (those not requiring reference counts, copies, @@ -3443,12 +3575,13 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) public: // Read-only accessors for non-POD options. The proper way to set these // depends on the derived type. - JSPrincipals *principals() const { return principals_; } - JSPrincipals *originPrincipals() const; + JSPrincipals *originPrincipals(js::ExclusiveContext *cx) const; const char *filename() const { return filename_; } + const char *introducerFilename() const { return introducerFilename_; } const jschar *sourceMapURL() const { return sourceMapURL_; } virtual JSObject *element() const = 0; - virtual JSString *elementProperty() const = 0; + virtual JSString *elementAttributeName() const = 0; + virtual JSScript *introductionScript() const = 0; // POD options. JSVersion version; @@ -3458,6 +3591,7 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) unsigned column; bool compileAndGo; bool forEval; + bool defineOnScope; bool noScriptRval; bool selfHostingMode; bool canLazilyParse; @@ -3466,11 +3600,15 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) bool werrorOption; bool asmJSOption; bool forceAsync; - enum SourcePolicy { - NO_SOURCE, - LAZY_SOURCE, - SAVE_SOURCE - } sourcePolicy; + bool installedFile; // 'true' iff pre-compiling js file in packaged app + bool sourceIsLazy; + + // |introductionType| is a statically allocated C string: + // one of "eval", "Function", or "GeneratorFunction". + const char *introductionType; + unsigned introductionLineno; + uint32_t introductionOffset; + bool hasIntroductionInfo; private: static JSObject * const nullObjectPtr; @@ -3490,11 +3628,12 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) * comes to refer to the object that owns this, then the whole cycle, and * anything else it entrains, will never be freed. */ -class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions +class JS_FRIEND_API(OwningCompileOptions) : public ReadOnlyCompileOptions { JSRuntime *runtime; PersistentRootedObject elementRoot; - PersistentRootedString elementPropertyRoot; + PersistentRootedString elementAttributeNameRoot; + PersistentRootedScript introductionScriptRoot; public: // A minimal constructor, for use with OwningCompileOptions::copy. This @@ -3505,22 +3644,30 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions ~OwningCompileOptions(); JSObject *element() const MOZ_OVERRIDE { return elementRoot; } - JSString *elementProperty() const MOZ_OVERRIDE { return elementPropertyRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } // Set this to a copy of |rhs|. Return false on OOM. bool copy(JSContext *cx, const ReadOnlyCompileOptions &rhs); /* These setters make copies of their string arguments, and are fallible. */ + bool setFile(JSContext *cx, const char *f); bool setFileAndLine(JSContext *cx, const char *f, unsigned l); bool setSourceMapURL(JSContext *cx, const jschar *s); + bool setIntroducerFilename(JSContext *cx, const char *s); /* These setters are infallible, and can be chained. */ - OwningCompileOptions &setElement(JSObject *e) { elementRoot = e; return *this; } - OwningCompileOptions &setElementProperty(JSString *p) { elementPropertyRoot = p; return *this; } - OwningCompileOptions &setPrincipals(JSPrincipals *p) { - if (p) JS_HoldPrincipals(p); - if (principals_) JS_DropPrincipals(runtime, principals_); - principals_ = p; + OwningCompileOptions &setLine(unsigned l) { lineno = l; return *this; } + OwningCompileOptions &setElement(JSObject *e) { + elementRoot = e; + return *this; + } + OwningCompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + OwningCompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; return *this; } OwningCompileOptions &setOriginPrincipals(JSPrincipals *p) { @@ -3538,10 +3685,27 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions OwningCompileOptions &setColumn(unsigned c) { column = c; return *this; } OwningCompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } OwningCompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + OwningCompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } OwningCompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } OwningCompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } OwningCompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } - OwningCompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; } + OwningCompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + OwningCompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + bool setIntroductionInfo(JSContext *cx, const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + if (!setIntroducerFilename(cx, introducerFn)) + return false; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return true; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; }; /* @@ -3551,36 +3715,47 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions * create an instance of this type, it's up to you to guarantee that * everything you store in it will outlive it. */ -class MOZ_STACK_CLASS JS_PUBLIC_API(CompileOptions) : public ReadOnlyCompileOptions +class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOptions { RootedObject elementRoot; - RootedString elementPropertyRoot; + RootedString elementAttributeNameRoot; + RootedScript introductionScriptRoot; public: explicit CompileOptions(JSContext *cx, JSVersion version = JSVERSION_UNKNOWN); CompileOptions(js::ContextFriendFields *cx, const ReadOnlyCompileOptions &rhs) - : ReadOnlyCompileOptions(), elementRoot(cx), elementPropertyRoot(cx) + : ReadOnlyCompileOptions(), elementRoot(cx), elementAttributeNameRoot(cx), + introductionScriptRoot(cx) { copyPODOptions(rhs); - principals_ = rhs.principals(); - originPrincipals_ = rhs.originPrincipals(); + originPrincipals_ = rhs.originPrincipals_; filename_ = rhs.filename(); sourceMapURL_ = rhs.sourceMapURL(); elementRoot = rhs.element(); - elementPropertyRoot = rhs.elementProperty(); + elementAttributeNameRoot = rhs.elementAttributeName(); + introductionScriptRoot = rhs.introductionScript(); } JSObject *element() const MOZ_OVERRIDE { return elementRoot; } - JSString *elementProperty() const MOZ_OVERRIDE { return elementPropertyRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } + CompileOptions &setFile(const char *f) { filename_ = f; return *this; } + CompileOptions &setLine(unsigned l) { lineno = l; return *this; } CompileOptions &setFileAndLine(const char *f, unsigned l) { filename_ = f; lineno = l; return *this; } CompileOptions &setSourceMapURL(const jschar *s) { sourceMapURL_ = s; return *this; } CompileOptions &setElement(JSObject *e) { elementRoot = e; return *this; } - CompileOptions &setElementProperty(JSString *p) { elementPropertyRoot = p; return *this; } - CompileOptions &setPrincipals(JSPrincipals *p) { principals_ = p; return *this; } + CompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + CompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; + return *this; + } CompileOptions &setOriginPrincipals(JSPrincipals *p) { originPrincipals_ = p; return *this; @@ -3594,25 +3769,50 @@ class MOZ_STACK_CLASS JS_PUBLIC_API(CompileOptions) : public ReadOnlyCompileOpti CompileOptions &setColumn(unsigned c) { column = c; return *this; } CompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } CompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + CompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } CompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } CompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } CompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } - CompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; } + CompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + CompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + CompileOptions &setIntroductionInfo(const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + introducerFilename_ = introducerFn; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return *this; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; }; -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *bytes, size_t length); +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const jschar *chars, size_t length); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, FILE *file); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, const char *filename); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, FILE *file, + JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *filename, + JS::MutableHandleScript script); extern JS_PUBLIC_API(bool) CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t length); @@ -3625,8 +3825,8 @@ CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t * for the compilation. The callback will be invoked while off the main thread, * so must ensure that its operations are thread safe. Afterwards, * FinishOffThreadScript must be invoked on the main thread to get the result - * script or nullptr. If maybecx is specified, this method will also report - * any error or warnings generated during the parse. + * script or nullptr. If maybecx is not specified, the resources will be freed, + * but no script will be returned. * * The characters passed in to CompileOffThread must remain live until the * callback is invoked, and the resulting script will be rooted until the call @@ -3634,27 +3834,32 @@ CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t */ extern JS_PUBLIC_API(bool) -CompileOffThread(JSContext *cx, Handle obj, const ReadOnlyCompileOptions &options, +CompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, const jschar *chars, size_t length, OffThreadCompileCallback callback, void *callbackData); extern JS_PUBLIC_API(JSScript *) FinishOffThreadScript(JSContext *maybecx, JSRuntime *rt, void *token); -extern JS_PUBLIC_API(JSFunction *) -CompileFunction(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *name, unsigned nargs, const char *const *argnames, - const char *bytes, size_t length); + SourceBufferHolder &srcBuf, JS::MutableHandleFunction fun); -extern JS_PUBLIC_API(JSFunction *) -CompileFunction(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *name, unsigned nargs, const char *const *argnames, + const char *bytes, size_t length, JS::MutableHandleFunction fun); + +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *name, unsigned nargs, const char *const *argnames, - const jschar *chars, size_t length); + const jschar *chars, size_t length, JS::MutableHandleFunction fun); } /* namespace JS */ extern JS_PUBLIC_API(JSString *) -JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned indent); +JS_DecompileScript(JSContext *cx, JS::Handle script, const char *name, unsigned indent); /* * API extension: OR this into indent to avoid pretty-printing the decompiled @@ -3663,10 +3868,10 @@ JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned i #define JS_DONT_PRETTY_PRINT ((unsigned)0x8000) extern JS_PUBLIC_API(JSString *) -JS_DecompileFunction(JSContext *cx, JSFunction *fun, unsigned indent); +JS_DecompileFunction(JSContext *cx, JS::Handle fun, unsigned indent); extern JS_PUBLIC_API(JSString *) -JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, unsigned indent); +JS_DecompileFunctionBody(JSContext *cx, JS::Handle fun, unsigned indent); /* * NB: JS_ExecuteScript and the JS_Evaluate*Script* quadruplets use the obj @@ -3702,158 +3907,159 @@ JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, unsigned indent); * etc., entry points. */ extern JS_PUBLIC_API(bool) -JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval); +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval, - JSVersion version); +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script); + +namespace JS { /* - * Execute either the function-defining prolog of a script, or the script's - * main body, but not both. + * Like the above, but handles a cross-compartment script. If the script is + * cross-compartment, it is cloned into the current compartment before executing. */ -typedef enum JSExecPart { JSEXEC_PROLOG, JSEXEC_MAIN } JSExecPart; +extern JS_PUBLIC_API(bool) +CloneAndExecuteScript(JSContext *cx, JS::Handle obj, JS::Handle script); + +} /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_EvaluateScript(JSContext *cx, JSObject *obj, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleValue rval, JSVersion version); + +extern JS_PUBLIC_API(bool) +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JSVersion version); extern JS_PUBLIC_API(bool) -JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_EvaluateScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno); extern JS_PUBLIC_API(bool) -JS_EvaluateUCScript(JSContext *cx, JSObject *obj, +JS_EvaluateUCScript(JSContext *cx, JS::Handle obj, const jschar *chars, unsigned length, const char *filename, unsigned lineno, - jsval *rval); + JS::MutableHandle rval); + +namespace JS { extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleValue rval); -/* - * JSAPI clients may optionally specify the 'originPrincipals' of a script. - * A script's originPrincipals may be retrieved through the debug API (via - * JS_GetScriptOriginPrincipals) and the originPrincipals are transitively - * assigned to any nested scripts (including scripts dynamically created via - * eval and the Function constructor). If originPrincipals is null, then the - * value of principals is used as origin principals for the script. - */ extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipalsVersionOrigin(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - JSPrincipals *originPrincipals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleValue rval); -namespace JS { +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const jschar *chars, size_t length, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *bytes, size_t length, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *filename, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename); } /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunction(JSContext *cx, JS::HandleObject obj, JS::HandleFunction fun, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunctionName(JSContext *cx, JS::HandleObject obj, const char *name, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunctionValue(JSContext *cx, JS::HandleObject obj, JS::HandleValue fval, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); namespace JS { static inline bool -Call(JSContext *cx, JSObject *thisObj, JSFunction *fun, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleFunction fun, + const JS::HandleValueArray &args, MutableHandleValue rval) { - return !!JS_CallFunction(cx, thisObj, fun, argc, argv, rval.address()); + return !!JS_CallFunction(cx, thisObj, fun, args, rval); } static inline bool -Call(JSContext *cx, JSObject *thisObj, const char *name, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, const char *name, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return !!JS_CallFunctionName(cx, thisObj, name, argc, argv, rval.address()); + return !!JS_CallFunctionName(cx, thisObj, name, args, rval); } static inline bool -Call(JSContext *cx, JSObject *thisObj, jsval fun, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return !!JS_CallFunctionValue(cx, thisObj, fun, argc, argv, rval.address()); + return !!JS_CallFunctionValue(cx, thisObj, fun, args, rval); } extern JS_PUBLIC_API(bool) -Call(JSContext *cx, jsval thisv, jsval fun, unsigned argc, jsval *argv, MutableHandle rval); +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval); static inline bool -Call(JSContext *cx, jsval thisv, JSObject *funObj, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleObject funObj, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return Call(cx, thisv, OBJECT_TO_JSVAL(funObj), argc, argv, rval); + JS_ASSERT(funObj); + JS::RootedValue fun(cx, JS::ObjectValue(*funObj)); + return Call(cx, thisv, fun, args, rval); } +extern JS_PUBLIC_API(bool) +Construct(JSContext *cx, JS::HandleValue fun, + const JS::HandleValueArray& args, + MutableHandleValue rval); + } /* namespace JS */ /* - * These functions allow setting an operation callback that will be called + * These functions allow setting an interrupt callback that will be called * from the JS thread some time after any thread triggered the callback using - * JS_TriggerOperationCallback(rt). + * JS_RequestInterruptCallback(rt). * * To schedule the GC and for other activities the engine internally triggers - * operation callbacks. The embedding should thus not rely on callbacks being + * interrupt callbacks. The embedding should thus not rely on callbacks being * triggered through the external API only. * * Important note: Additional callbacks can occur inside the callback handler * if it re-enters the JS engine. The embedding must ensure that the callback * is disconnected before attempting such re-entry. */ -extern JS_PUBLIC_API(JSOperationCallback) -JS_SetOperationCallback(JSRuntime *rt, JSOperationCallback callback); +extern JS_PUBLIC_API(JSInterruptCallback) +JS_SetInterruptCallback(JSRuntime *rt, JSInterruptCallback callback); -extern JS_PUBLIC_API(JSOperationCallback) -JS_GetOperationCallback(JSRuntime *rt); +extern JS_PUBLIC_API(JSInterruptCallback) +JS_GetInterruptCallback(JSRuntime *rt); extern JS_PUBLIC_API(void) -JS_TriggerOperationCallback(JSRuntime *rt); +JS_RequestInterruptCallback(JSRuntime *rt); extern JS_PUBLIC_API(bool) JS_IsRunning(JSContext *cx); @@ -3878,7 +4084,7 @@ JS_RestoreFrameChain(JSContext *cx); #ifdef MOZ_TRACE_JSCALLS /* * The callback is expected to be quick and noninvasive. It should not - * trigger interrupts, turn on debugging, or produce uncaught JS + * request interrupts, turn on debugging, or produce uncaught JS * exceptions. The state of the stack and registers in the context * cannot be relied upon, since this callback may be invoked directly * from either JIT. The 'entering' field means we are entering a @@ -3953,15 +4159,16 @@ JS_FileEscapedString(FILE *fp, JSString *str, char quote); * special cases where getting the chars is infallible: * * The first case is interned strings, i.e., strings from JS_InternString or - * JSID_TO_STRING(id), using JS_GetInternedStringChars*. + * JSID_TO_STRING(id), using JS_GetLatin1InternedStringChars or + * JS_GetTwoByteInternedStringChars. * * The second case is "flat" strings that have been explicitly prepared in a * fallible context by JS_FlattenString. To catch errors, a separate opaque * JSFlatString type is returned by JS_FlattenString and expected by * JS_GetFlatStringChars. Note, though, that this is purely a syntactic * distinction: the input and output of JS_FlattenString are the same actual - * GC-thing so only one needs to be rooted. If a JSString is known to be flat, - * JS_ASSERT_STRING_IS_FLAT can be used to make a debug-checked cast. Example: + * GC-thing. If a JSString is known to be flat, JS_ASSERT_STRING_IS_FLAT can be + * used to make a debug-checked cast. Example: * * // in a fallible context * JSFlatString *fstr = JS_FlattenString(cx, str); @@ -3970,55 +4177,80 @@ JS_FileEscapedString(FILE *fp, JSString *str, char quote); * JS_ASSERT(fstr == JS_ASSERT_STRING_IS_FLAT(str)); * * // in an infallible context, for the same 'str' - * const jschar *chars = JS_GetFlatStringChars(fstr) + * AutoCheckCannotGC nogc; + * const jschar *chars = JS_GetTwoByteFlatStringChars(nogc, fstr) * JS_ASSERT(chars); * - * The CharsZ APIs guarantee that the returned array has a null character at - * chars[length]. This can require additional copying so clients should prefer - * APIs without CharsZ if possible. The infallible functions also return - * null-terminated arrays. (There is no additional cost or non-Z alternative - * for the infallible functions, so 'Z' is left out of the identifier.) + * Flat strings and interned strings are always null-terminated, so + * JS_FlattenString can be used to get a null-terminated string. + * + * Additionally, string characters are stored as either Latin1Char (8-bit) + * or jschar (16-bit). Clients can use JS_StringHasLatin1Chars and can then + * call either the Latin1* or TwoByte* functions. Some functions like + * JS_CopyStringChars and JS_GetStringCharAt accept both Latin1 and TwoByte + * strings. */ extern JS_PUBLIC_API(size_t) JS_GetStringLength(JSString *str); -extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsAndLength(JSContext *cx, JSString *str, size_t *length); +extern JS_PUBLIC_API(bool) +JS_StringIsFlat(JSString *str); -extern JS_PUBLIC_API(const jschar *) -JS_GetInternedStringChars(JSString *str); +/* Returns true iff the string's characters are stored as Latin1. */ +extern JS_PUBLIC_API(bool) +JS_StringHasLatin1Chars(JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1StringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); extern JS_PUBLIC_API(const jschar *) -JS_GetInternedStringCharsAndLength(JSString *str, size_t *length); +JS_GetTwoByteStringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); + +extern JS_PUBLIC_API(bool) +JS_GetStringCharAt(JSContext *cx, JSString *str, size_t index, jschar *res); + +extern JS_PUBLIC_API(jschar) +JS_GetFlatStringCharAt(JSFlatString *str, size_t index); extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsZ(JSContext *cx, JSString *str); +JS_GetTwoByteExternalStringChars(JSString *str); + +extern JS_PUBLIC_API(bool) +JS_CopyStringChars(JSContext *cx, mozilla::Range dest, JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1InternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsZAndLength(JSContext *cx, JSString *str, size_t *length); +JS_GetTwoByteInternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); extern JS_PUBLIC_API(JSFlatString *) JS_FlattenString(JSContext *cx, JSString *str); +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1FlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); + extern JS_PUBLIC_API(const jschar *) -JS_GetFlatStringChars(JSFlatString *str); +JS_GetTwoByteFlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); -static JS_ALWAYS_INLINE JSFlatString * +static MOZ_ALWAYS_INLINE JSFlatString * JSID_TO_FLAT_STRING(jsid id) { JS_ASSERT(JSID_IS_STRING(id)); return (JSFlatString *)(JSID_BITS(id)); } -static JS_ALWAYS_INLINE JSFlatString * +static MOZ_ALWAYS_INLINE JSFlatString * JS_ASSERT_STRING_IS_FLAT(JSString *str) { - JS_ASSERT(JS_GetFlatStringChars((JSFlatString *)str)); + JS_ASSERT(JS_StringIsFlat(str)); return (JSFlatString *)str; } -static JS_ALWAYS_INLINE JSString * +static MOZ_ALWAYS_INLINE JSString * JS_FORGET_STRING_FLATNESS(JSFlatString *fstr) { return (JSString *)fstr; @@ -4078,7 +4310,7 @@ JS_EncodeString(JSContext *cx, JSString *str); * Same behavior as JS_EncodeString(), but encode into UTF-8 string */ JS_PUBLIC_API(char *) -JS_EncodeStringToUTF8(JSContext *cx, JSString *str); +JS_EncodeStringToUTF8(JSContext *cx, JS::HandleString str); /* * Get number of bytes in the string encoding (without accounting for a @@ -4110,7 +4342,7 @@ class JSAutoByteString MOZ_GUARD_OBJECT_NOTIFIER_INIT; } - JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + explicit JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) : mBytes(nullptr) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -4135,7 +4367,7 @@ class JSAutoByteString char *encodeLatin1(js::ExclusiveContext *cx, JSString *str); - char *encodeUtf8(JSContext *cx, JSString *str) { + char *encodeUtf8(JSContext *cx, JS::HandleString str) { JS_ASSERT(!mBytes); JS_ASSERT(cx); mBytes = JS_EncodeStringToUTF8(cx, str); @@ -4170,6 +4402,84 @@ class JSAutoByteString JSAutoByteString &operator=(const JSAutoByteString &another); }; +namespace JS { + +extern JS_PUBLIC_API(JSAddonId *) +NewAddonId(JSContext *cx, JS::HandleString str); + +extern JS_PUBLIC_API(JSString *) +StringOfAddonId(JSAddonId *id); + +extern JS_PUBLIC_API(JSAddonId *) +AddonIdOfObject(JSObject *obj); + +} // namespace JS + +/************************************************************************/ +/* + * Symbols + */ + +namespace JS { + +/* + * Create a new Symbol with the given description. This function never returns + * a Symbol that is in the Runtime-wide symbol registry. + * + * If description is null, the new Symbol's [[Description]] attribute is + * undefined. + */ +JS_PUBLIC_API(Symbol *) +NewSymbol(JSContext *cx, HandleString description); + +/* + * Symbol.for as specified in ES6. + * + * Get a Symbol with the description 'key' from the Runtime-wide symbol registry. + * If there is not already a Symbol with that description in the registry, a new + * Symbol is created and registered. 'key' must not be null. + */ +JS_PUBLIC_API(Symbol *) +GetSymbolFor(JSContext *cx, HandleString key); + +/* + * Get the [[Description]] attribute of the given symbol. + * + * This function is infallible. If it returns null, that means the symbol's + * [[Description]] is undefined. + */ +JS_PUBLIC_API(JSString *) +GetSymbolDescription(HandleSymbol symbol); + +/* Well-known symbols. */ +MOZ_BEGIN_ENUM_CLASS(SymbolCode, uint32_t) + iterator, // well-known Symbol.iterator + InSymbolRegistry = 0xfffffffe, // created by Symbol.for() or JS::GetSymbolFor() + UniqueSymbol = 0xffffffff // created by Symbol() or JS::NewSymbol() +MOZ_END_ENUM_CLASS(SymbolCode) + +/* For use in loops that iterate over the well-known symbols. */ +const size_t WellKnownSymbolLimit = 1; + +/* + * Return the SymbolCode telling what sort of symbol `symbol` is. + * + * A symbol's SymbolCode never changes once it is created. + */ +JS_PUBLIC_API(SymbolCode) +GetSymbolCode(Handle symbol); + +/* + * Get one of the well-known symbols defined by ES6. A single set of well-known + * symbols is shared by all compartments in a JSRuntime. + * + * `which` must be in the range [0, WellKnownSymbolLimit). + */ +JS_PUBLIC_API(Symbol *) +GetWellKnownSymbol(JSContext *cx, SymbolCode which); + +} /* namespace JS */ + /************************************************************************/ /* * JSON functions @@ -4189,10 +4499,17 @@ JS_Stringify(JSContext *cx, JS::MutableHandleValue value, JS::HandleObject repla JS_PUBLIC_API(bool) JS_ParseJSON(JSContext *cx, const jschar *chars, uint32_t len, JS::MutableHandleValue vp); +JS_PUBLIC_API(bool) +JS_ParseJSON(JSContext *cx, JS::HandleString str, JS::MutableHandleValue vp); + JS_PUBLIC_API(bool) JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32_t len, JS::HandleValue reviver, JS::MutableHandleValue vp); +JS_PUBLIC_API(bool) +JS_ParseJSONWithReviver(JSContext *cx, JS::HandleString str, JS::HandleValue reviver, + JS::MutableHandleValue vp); + /************************************************************************/ /* @@ -4219,7 +4536,6 @@ struct JSLocaleCallbacks { JSLocaleToLowerCase localeToLowerCase; JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API JSLocaleToUnicode localeToUnicode; - JSErrorCallback localeGetErrorMessage; }; /* @@ -4357,8 +4673,35 @@ JS_GetErrorReporter(JSContext *cx); extern JS_PUBLIC_API(JSErrorReporter) JS_SetErrorReporter(JSContext *cx, JSErrorReporter er); +namespace JS { + +extern JS_PUBLIC_API(bool) +CreateError(JSContext *cx, JSExnType type, HandleString stack, + HandleString fileName, uint32_t lineNumber, uint32_t columnNumber, + JSErrorReport *report, HandleString message, MutableHandleValue rval); + /************************************************************************/ +/* + * Weak Maps. + */ + +extern JS_PUBLIC_API(JSObject *) +NewWeakMapObject(JSContext *cx); + +extern JS_PUBLIC_API(bool) +IsWeakMapObject(JSObject *obj); + +extern JS_PUBLIC_API(bool) +GetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::MutableHandleValue val); + +extern JS_PUBLIC_API(bool) +SetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::HandleValue val); + +} /* namespace JS */ + /* * Dates. */ @@ -4387,10 +4730,10 @@ JS_ClearDateCaches(JSContext *cx); /* * Regular Expressions. */ -#define JSREG_FOLD 0x01 /* fold uppercase to lowercase */ -#define JSREG_GLOB 0x02 /* global exec, creates array of matches */ -#define JSREG_MULTILINE 0x04 /* treat ^ and $ as begin and end of line */ -#define JSREG_STICKY 0x08 /* only match starting at lastIndex */ +#define JSREG_FOLD 0x01u /* fold uppercase to lowercase */ +#define JSREG_GLOB 0x02u /* global exec, creates array of matches */ +#define JSREG_MULTILINE 0x04u /* treat ^ and $ as begin and end of line */ +#define JSREG_STICKY 0x08u /* only match starting at lastIndex */ extern JS_PUBLIC_API(JSObject *) JS_NewRegExpObject(JSContext *cx, JS::HandleObject obj, char *bytes, size_t length, @@ -4400,11 +4743,11 @@ extern JS_PUBLIC_API(JSObject *) JS_NewUCRegExpObject(JSContext *cx, JS::HandleObject obj, jschar *chars, size_t length, unsigned flags); -extern JS_PUBLIC_API(void) +extern JS_PUBLIC_API(bool) JS_SetRegExpInput(JSContext *cx, JS::HandleObject obj, JS::HandleString input, bool multiline); -extern JS_PUBLIC_API(void) +extern JS_PUBLIC_API(bool) JS_ClearRegExpStatics(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) @@ -4450,17 +4793,62 @@ JS_ClearPendingException(JSContext *cx); extern JS_PUBLIC_API(bool) JS_ReportPendingException(JSContext *cx); +namespace JS { + /* - * Save the current exception state. This takes a snapshot of cx's current - * exception state without making any change to that state. + * Save and later restore the current exception state of a given JSContext. + * This is useful for implementing behavior in C++ that's like try/catch + * or try/finally in JS. * - * The returned state pointer MUST be passed later to JS_RestoreExceptionState - * (to restore that saved state, overriding any more recent state) or else to - * JS_DropExceptionState (to free the state struct in case it is not correct - * or desirable to restore it). Both Restore and Drop free the state struct, - * so callers must stop using the pointer returned from Save after calling the - * Release or Drop API. + * Typical usage: + * + * bool ok = JS_EvaluateScript(cx, ...); + * AutoSaveExceptionState savedExc(cx); + * ... cleanup that might re-enter JS ... + * return ok; */ +class JS_PUBLIC_API(AutoSaveExceptionState) +{ + private: + JSContext *context; + bool wasPropagatingForcedReturn; + bool wasThrowing; + RootedValue exceptionValue; + + public: + /* + * Take a snapshot of cx's current exception state. Then clear any current + * pending exception in cx. + */ + explicit AutoSaveExceptionState(JSContext *cx); + + /* + * If neither drop() nor restore() was called, restore the exception + * state only if no exception is currently pending on cx. + */ + ~AutoSaveExceptionState(); + + /* + * Discard any stored exception state. + * If this is called, the destructor is a no-op. + */ + void drop() { + wasPropagatingForcedReturn = false; + wasThrowing = false; + exceptionValue.setUndefined(); + } + + /* + * Replace cx's exception state with the stored exception state. Then + * discard the stored exception state. If this is called, the + * destructor is a no-op. + */ + void restore(); +}; + +} /* namespace JS */ + +/* Deprecated API. Use AutoSaveExceptionState instead. */ extern JS_PUBLIC_API(JSExceptionState *) JS_SaveExceptionState(JSContext *cx); @@ -4471,22 +4859,14 @@ extern JS_PUBLIC_API(void) JS_DropExceptionState(JSContext *cx, JSExceptionState *state); /* - * If the given value is an exception object that originated from an error, - * the exception will contain an error report struct, and this API will return - * the address of that struct. Otherwise, it returns nullptr. The lifetime + * If the given object is an exception object, the exception will have (or be + * able to lazily create) an error report struct, and this function will return + * the address of that struct. Otherwise, it returns nullptr. The lifetime * of the error report struct that might be returned is the same as the * lifetime of the exception object. */ extern JS_PUBLIC_API(JSErrorReport *) -JS_ErrorFromException(JSContext *cx, JS::HandleValue v); - -/* - * Given a reported error's message and JSErrorReport struct pointer, throw - * the corresponding exception on cx. - */ -extern JS_PUBLIC_API(bool) -JS_ThrowReportedError(JSContext *cx, const char *message, - JSErrorReport *reportp); +JS_ErrorFromException(JSContext *cx, JS::HandleObject obj); /* * Throws a StopIteration exception on cx. @@ -4521,7 +4901,7 @@ JS_AbortIfWrongThread(JSRuntime *rt); * [[Prototype]]. */ extern JS_PUBLIC_API(JSObject *) -JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const jsval *vp); +JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const JS::CallArgs& args); /************************************************************************/ @@ -4536,16 +4916,18 @@ JS_ScheduleGC(JSContext *cx, uint32_t count); #endif extern JS_PUBLIC_API(void) -JS_SetParallelParsingEnabled(JSContext *cx, bool enabled); +JS_SetParallelParsingEnabled(JSRuntime *rt, bool enabled); extern JS_PUBLIC_API(void) -JS_SetParallelIonCompilationEnabled(JSContext *cx, bool enabled); +JS_SetOffthreadIonCompilationEnabled(JSRuntime *rt, bool enabled); -#define JIT_COMPILER_OPTIONS(Register) \ - Register(BASELINE_USECOUNT_TRIGGER, "baseline.usecount.trigger") \ - Register(ION_USECOUNT_TRIGGER, "ion.usecount.trigger") \ - Register(ION_ENABLE, "ion.enable") \ - Register(BASELINE_ENABLE, "baseline.enable") +#define JIT_COMPILER_OPTIONS(Register) \ + Register(BASELINE_USECOUNT_TRIGGER, "baseline.usecount.trigger") \ + Register(ION_USECOUNT_TRIGGER, "ion.usecount.trigger") \ + Register(ION_ENABLE, "ion.enable") \ + Register(BASELINE_ENABLE, "baseline.enable") \ + Register(OFFTHREAD_COMPILATION_ENABLE, "offthread-compilation.enable") \ + Register(SIGNALS_ENABLE, "signals.enable") typedef enum JSJitCompilerOption { #define JIT_COMPILER_DECLARE(key, str) \ @@ -4558,7 +4940,9 @@ typedef enum JSJitCompilerOption { } JSJitCompilerOption; extern JS_PUBLIC_API(void) -JS_SetGlobalJitCompilerOption(JSContext *cx, JSJitCompilerOption opt, uint32_t value); +JS_SetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt, uint32_t value); +extern JS_PUBLIC_API(int) +JS_GetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt); /* * Convert a uint32_t index into a jsid. @@ -4580,13 +4964,80 @@ JS_CharsToId(JSContext* cx, JS::TwoByteChars chars, JS::MutableHandleId); extern JS_PUBLIC_API(bool) JS_IsIdentifier(JSContext *cx, JS::HandleString str, bool *isIdentifier); +namespace JS { + +/* + * AutoFilename encapsulates a pointer to a C-string and keeps the C-string + * alive for as long as the associated AutoFilename object is alive. + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(AutoFilename) +{ + void *scriptSource_; + + AutoFilename(const AutoFilename &) MOZ_DELETE; + void operator=(const AutoFilename &) MOZ_DELETE; + + public: + AutoFilename() : scriptSource_(nullptr) {} + ~AutoFilename() { reset(nullptr); } + + const char *get() const; + + void reset(void *newScriptSource); +}; + /* - * Return the current script and line number of the most currently running + * Return the current filename and line number of the most currently running * frame. Returns true if a scripted frame was found, false otherwise. + * + * If a the embedding has hidden the scripted caller for the topmost activation + * record, this will also return false. */ extern JS_PUBLIC_API(bool) -JS_DescribeScriptedCaller(JSContext *cx, JS::MutableHandleScript script, unsigned *lineno); +DescribeScriptedCaller(JSContext *cx, AutoFilename *filename = nullptr, + unsigned *lineno = nullptr); +extern JS_PUBLIC_API(JSObject *) +GetScriptedCallerGlobal(JSContext *cx); + +/* + * Informs the JS engine that the scripted caller should be hidden. This can be + * used by the embedding to maintain an override of the scripted caller in its + * calculations, by hiding the scripted caller in the JS engine and pushing data + * onto a separate stack, which it inspects when DescribeScriptedCaller returns + * null. + * + * We maintain a counter on each activation record. Add() increments the counter + * of the topmost activation, and Remove() decrements it. The count may never + * drop below zero, and must always be exactly zero when the activation is + * popped from the stack. + */ +extern JS_PUBLIC_API(void) +HideScriptedCaller(JSContext *cx); + +extern JS_PUBLIC_API(void) +UnhideScriptedCaller(JSContext *cx); + +class AutoHideScriptedCaller +{ + public: + explicit AutoHideScriptedCaller(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mContext(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + HideScriptedCaller(mContext); + } + ~AutoHideScriptedCaller() { + UnhideScriptedCaller(mContext); + } + + protected: + JSContext *mContext; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +} /* namespace JS */ /* * Encode/Decode interpreted scripts and functions to/from memory. @@ -4599,12 +5050,11 @@ extern JS_PUBLIC_API(void *) JS_EncodeInterpretedFunction(JSContext *cx, JS::HandleObject funobj, uint32_t *lengthp); extern JS_PUBLIC_API(JSScript *) -JS_DecodeScript(JSContext *cx, const void *data, uint32_t length, - JSPrincipals *principals, JSPrincipals *originPrincipals); +JS_DecodeScript(JSContext *cx, const void *data, uint32_t length, JSPrincipals *originPrincipals); extern JS_PUBLIC_API(JSObject *) JS_DecodeInterpretedFunction(JSContext *cx, const void *data, uint32_t length, - JSPrincipals *principals, JSPrincipals *originPrincipals); + JSPrincipals *originPrincipals); namespace JS { @@ -4621,8 +5071,7 @@ typedef bool (* OpenAsmJSCacheEntryForReadOp)(HandleObject global, const jschar *begin, const jschar *limit, size_t *size, const uint8_t **memory, intptr_t *handle); typedef void -(* CloseAsmJSCacheEntryForReadOp)(HandleObject global, size_t size, const uint8_t *memory, - intptr_t handle); +(* CloseAsmJSCacheEntryForReadOp)(size_t size, const uint8_t *memory, intptr_t handle); /* * This callback represents a request by the JS engine to open for writing a @@ -4632,21 +5081,30 @@ typedef void * outparams. If the callback returns 'true', the JS engine guarantees a call * to CloseAsmJSCacheEntryForWriteOp passing the same base address, size and * handle. + * + * If 'installed' is true, then the cache entry is associated with a permanently + * installed JS file (e.g., in a packaged webapp). This information allows the + * embedding to store the cache entry in a installed location associated with + * the principal of 'global' where it will not be evicted until the associated + * installed JS file is removed. */ typedef bool -(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, const jschar *begin, const jschar *end, +(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, bool installed, + const jschar *begin, const jschar *end, size_t size, uint8_t **memory, intptr_t *handle); typedef void -(* CloseAsmJSCacheEntryForWriteOp)(HandleObject global, size_t size, uint8_t *memory, - intptr_t handle); +(* CloseAsmJSCacheEntryForWriteOp)(size_t size, uint8_t *memory, intptr_t handle); + +typedef js::Vector BuildIdCharVector; // Return the buildId (represented as a sequence of characters) associated with // the currently-executing build. If the JS engine is embedded such that a // single cache entry can be observed by different compiled versions of the JS // engine, it is critical that the buildId shall change for each new build of // the JS engine. + typedef bool -(* BuildIdOp)(js::Vector *buildId); +(* BuildIdOp)(BuildIdCharVector *buildId); struct AsmJSCacheOps { @@ -4660,6 +5118,132 @@ struct AsmJSCacheOps extern JS_PUBLIC_API(void) SetAsmJSCacheOps(JSRuntime *rt, const AsmJSCacheOps *callbacks); +/* + * Convenience class for imitating a JS level for-of loop. Typical usage: + * + * ForOfIterator it(cx); + * if (!it.init(iterable)) + * return false; + * RootedValue val(cx); + * while (true) { + * bool done; + * if (!it.next(&val, &done)) + * return false; + * if (done) + * break; + * if (!DoStuff(cx, val)) + * return false; + * } + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(ForOfIterator) { + protected: + JSContext *cx_; + /* + * Use the ForOfPIC on the global object (see vm/GlobalObject.h) to try + * to optimize iteration across arrays. + * + * Case 1: Regular Iteration + * iterator - pointer to the iterator object. + * index - fixed to NOT_ARRAY (== UINT32_MAX) + * + * Case 2: Optimized Array Iteration + * iterator - pointer to the array object. + * index - current position in array. + * + * The cases are distinguished by whether or not |index| is equal to NOT_ARRAY. + */ + JS::RootedObject iterator; + uint32_t index; + + static const uint32_t NOT_ARRAY = UINT32_MAX; + + ForOfIterator(const ForOfIterator &) MOZ_DELETE; + ForOfIterator &operator=(const ForOfIterator &) MOZ_DELETE; + + public: + explicit ForOfIterator(JSContext *cx) : cx_(cx), iterator(cx_), index(NOT_ARRAY) { } + + enum NonIterableBehavior { + ThrowOnNonIterable, + AllowNonIterable + }; + + /* + * Initialize the iterator. If AllowNonIterable is passed then if iterable + * does not have a callable @@iterator init() will just return true instead + * of throwing. Callers should then check valueIsIterable() before + * continuing with the iteration. + */ + bool init(JS::HandleValue iterable, + NonIterableBehavior nonIterableBehavior = ThrowOnNonIterable); + + /* + * This method assumes that |iterator| is already an iterator. It will not + * check for, and call @@iterator. Callers should make sure that the passed + * in value is in fact an iterator. + */ + bool initWithIterator(JS::HandleValue aIterator); + + /* + * Get the next value from the iterator. If false *done is true + * after this call, do not examine val. + */ + bool next(JS::MutableHandleValue val, bool *done); + + /* + * If initialized with throwOnNonCallable = false, check whether + * the value is iterable. + */ + bool valueIsIterable() const { + return iterator; + } + + private: + inline bool nextFromOptimizedArray(MutableHandleValue val, bool *done); + bool materializeArrayIterator(); +}; + + +/* + * If a large allocation fails, the JS engine may call the large-allocation- + * failure callback, if set, to allow the embedding to flush caches, possibly + * perform shrinking GCs, etc. to make some room so that the allocation will + * succeed if retried. After the callback returns, the JS engine will try to + * allocate again and may be succesful. + */ + +typedef void +(* LargeAllocationFailureCallback)(void *data); + +extern JS_PUBLIC_API(void) +SetLargeAllocationFailureCallback(JSRuntime *rt, LargeAllocationFailureCallback afc, void *data); + +/* + * Unlike the error reporter, which is only called if the exception for an OOM + * bubbles up and is not caught, the OutOfMemoryCallback is called immediately + * at the OOM site to allow the embedding to capture the current state of heap + * allocation before anything is freed. If the large-allocation-failure callback + * is called at all (not all allocation sites call the large-allocation-failure + * callback on failure), it is called before the out-of-memory callback; the + * out-of-memory callback is only called if the allocation still fails after the + * large-allocation-failure callback has returned. + */ + +typedef void +(* OutOfMemoryCallback)(JSContext *cx, void *data); + +extern JS_PUBLIC_API(void) +SetOutOfMemoryCallback(JSRuntime *rt, OutOfMemoryCallback cb, void *data); + + +/* + * Capture the current call stack as a chain of SavedFrame objects, and set + * |stackp| to the SavedFrame for the newest stack frame. If |maxFrameCount| is + * non-zero, capture at most the youngest |maxFrameCount| frames. + */ +extern JS_PUBLIC_API(bool) +CaptureCurrentStack(JSContext *cx, MutableHandleObject stackp, unsigned maxFrameCount = 0); + } /* namespace JS */ #endif /* jsapi_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/jscpucfg.h b/frameworks/js-bindings/external/spidermonkey/include/android/jscpucfg.h index e545d8329d..a7a00613bb 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/jscpucfg.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/jscpucfg.h @@ -18,7 +18,7 @@ # error "CPU type is unknown" # endif /* !(defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)) */ -#elif defined(_WIN32) || defined(XP_OS2) +#elif defined(_WIN32) # ifdef __WATCOMC__ # define HAVE_VA_LIST_AS_ARRAY 1 @@ -27,7 +27,7 @@ # define IS_LITTLE_ENDIAN 1 # undef IS_BIG_ENDIAN -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) # if __LITTLE_ENDIAN__ # define IS_LITTLE_ENDIAN 1 # undef IS_BIG_ENDIAN @@ -89,8 +89,7 @@ # endif #elif defined(__sparc) || defined(__sparc__) || \ - defined(_POWER) || defined(__powerpc__) || \ - defined(__ppc__) || defined(__hppa) || \ + defined(_POWER) || defined(__hppa) || \ defined(_MIPSEB) || defined(_BIG_ENDIAN) /* IA64 running HP-UX will have _BIG_ENDIAN defined. * IA64 running Linux will have endian.h and be handled above. diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/jsfriendapi.h b/frameworks/js-bindings/external/spidermonkey/include/android/jsfriendapi.h index eb05652a5b..674999eb62 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/jsfriendapi.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/jsfriendapi.h @@ -7,8 +7,12 @@ #ifndef jsfriendapi_h #define jsfriendapi_h +#include "mozilla/Casting.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/TypedEnum.h" +#include "mozilla/UniquePtr.h" +#include "jsapi.h" // For JSAutoByteString. See bug 1033916. #include "jsbytecode.h" #include "jspubtd.h" @@ -19,14 +23,20 @@ /* * This macro checks if the stack pointer has exceeded a given limit. If * |tolerance| is non-zero, it returns true only if the stack pointer has - * exceeded the limit by more than |tolerance| bytes. + * exceeded the limit by more than |tolerance| bytes. The WITH_INTOLERANCE + * versions use a negative tolerance (i.e., the limit is reduced by + * |intolerance| bytes). */ #if JS_STACK_GROWTH_DIRECTION > 0 # define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ ((uintptr_t)(sp) < (limit)+(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) < (limit)-(intolerance)) #else # define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ ((uintptr_t)(sp) > (limit)-(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) > (limit)+(intolerance)) #endif #define JS_CHECK_STACK_SIZE(limit, lval) JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, lval, 0) @@ -35,33 +45,35 @@ class JSAtom; struct JSErrorFormatString; class JSLinearString; struct JSJitInfo; -class JSErrorReport; +struct JSErrorReport; namespace JS { template class Heap; } /* namespace JS */ +namespace js { +class JS_FRIEND_API(BaseProxyHandler); +} /* namespace js */ + extern JS_FRIEND_API(void) JS_SetGrayGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); extern JS_FRIEND_API(JSString *) JS_GetAnonymousString(JSRuntime *rt); -extern JS_FRIEND_API(void) -JS_SetIsWorkerRuntime(JSRuntime *rt); - extern JS_FRIEND_API(JSObject *) -JS_FindCompilationScope(JSContext *cx, JSObject *obj); +JS_FindCompilationScope(JSContext *cx, JS::HandleObject obj); extern JS_FRIEND_API(JSFunction *) JS_GetObjectFunction(JSObject *obj); extern JS_FRIEND_API(bool) -JS_SplicePrototype(JSContext *cx, JSObject *obj, JSObject *proto); +JS_SplicePrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); extern JS_FRIEND_API(JSObject *) -JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JSObject *proto, JSObject *parent); +JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JS::HandleObject proto, + JS::HandleObject parent); extern JS_FRIEND_API(uint32_t) JS_ObjectCountDynamicSlots(JS::HandleObject obj); @@ -73,7 +85,7 @@ extern JS_FRIEND_API(size_t) JS_GetCustomIteratorCount(JSContext *cx); extern JS_FRIEND_API(bool) -JS_NondeterministicGetWeakMapKeys(JSContext *cx, JSObject *obj, JSObject **ret); +JS_NondeterministicGetWeakMapKeys(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject ret); /* * Determine whether the given object is backed by a DeadObjectProxy. @@ -122,16 +134,23 @@ JS_GetCompartmentPrincipals(JSCompartment *compartment); extern JS_FRIEND_API(void) JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals); +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptPrincipals(JSScript *script); + +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptOriginPrincipals(JSScript *script); + /* Safe to call with input obj == nullptr. Returns non-nullptr iff obj != nullptr. */ extern JS_FRIEND_API(JSObject *) -JS_ObjectToInnerObject(JSContext *cx, JSObject *obj); +JS_ObjectToInnerObject(JSContext *cx, JS::HandleObject obj); /* Requires obj != nullptr. */ extern JS_FRIEND_API(JSObject *) -JS_ObjectToOuterObject(JSContext *cx, JSObject *obj); +JS_ObjectToOuterObject(JSContext *cx, JS::HandleObject obj); extern JS_FRIEND_API(JSObject *) -JS_CloneObject(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent); +JS_CloneObject(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto, + JS::HandleObject parent); extern JS_FRIEND_API(JSString *) JS_BasicObjectToString(JSContext *cx, JS::HandleObject obj); @@ -149,13 +168,17 @@ js_ObjectClassIs(JSContext *cx, JS::HandleObject obj, js::ESClassValue classValu JS_FRIEND_API(const char *) js_ObjectClassName(JSContext *cx, JS::HandleObject obj); +namespace js { + JS_FRIEND_API(bool) -js_AddObjectRoot(JSRuntime *rt, JSObject **objp); +AddRawValueRoot(JSContext *cx, JS::Value *vp, const char *name); JS_FRIEND_API(void) -js_RemoveObjectRoot(JSRuntime *rt, JSObject **objp); +RemoveRawValueRoot(JSContext *cx, JS::Value *vp); -#ifdef DEBUG +} /* namespace js */ + +#ifdef JS_DEBUG /* * Routines to print out values during debugging. These are FRIEND_API to help @@ -184,7 +207,7 @@ js_DumpChars(const jschar *s, size_t n); * restrictions on the compartment of |cx|. */ extern JS_FRIEND_API(bool) -JS_CopyPropertiesFrom(JSContext *cx, JSObject *target, JSObject *obj); +JS_CopyPropertiesFrom(JSContext *cx, JS::HandleObject target, JS::HandleObject obj); /* * Single-property version of the above. This function asserts that an |own| @@ -221,20 +244,164 @@ struct JSFunctionSpecWithHelp { {nullptr, nullptr, 0, 0, nullptr, nullptr} extern JS_FRIEND_API(bool) -JS_DefineFunctionsWithHelp(JSContext *cx, JSObject *obj, const JSFunctionSpecWithHelp *fs); +JS_DefineFunctionsWithHelp(JSContext *cx, JS::HandleObject obj, const JSFunctionSpecWithHelp *fs); namespace js { +/* + * Helper Macros for creating JSClasses that function as proxies. + * + * NB: The macro invocation must be surrounded by braces, so as to + * allow for potention JSClass extensions. + */ +#define PROXY_MAKE_EXT(outerObject, innerObject, iteratorObject, \ + isWrappedNative) \ + { \ + outerObject, \ + innerObject, \ + iteratorObject, \ + isWrappedNative, \ + js::proxy_WeakmapKeyDelegate \ + } + +#define PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, ext) \ + { \ + name, \ + js::Class::NON_NATIVE | \ + JSCLASS_IS_PROXY | \ + JSCLASS_IMPLEMENTS_BARRIERS | \ + JSCLASS_HAS_RESERVED_SLOTS(js::PROXY_MINIMUM_SLOTS + (extraSlots)) | \ + flags, \ + JS_PropertyStub, /* addProperty */ \ + JS_DeletePropertyStub, /* delProperty */ \ + JS_PropertyStub, /* getProperty */ \ + JS_StrictPropertyStub, /* setProperty */ \ + JS_EnumerateStub, \ + JS_ResolveStub, \ + js::proxy_Convert, \ + js::proxy_Finalize, /* finalize */ \ + callOp, /* call */ \ + js::proxy_HasInstance, /* hasInstance */ \ + constructOp, /* construct */ \ + js::proxy_Trace, /* trace */ \ + JS_NULL_CLASS_SPEC, \ + ext, \ + { \ + js::proxy_LookupGeneric, \ + js::proxy_LookupProperty, \ + js::proxy_LookupElement, \ + js::proxy_DefineGeneric, \ + js::proxy_DefineProperty, \ + js::proxy_DefineElement, \ + js::proxy_GetGeneric, \ + js::proxy_GetProperty, \ + js::proxy_GetElement, \ + js::proxy_SetGeneric, \ + js::proxy_SetProperty, \ + js::proxy_SetElement, \ + js::proxy_GetGenericAttributes, \ + js::proxy_SetGenericAttributes, \ + js::proxy_DeleteGeneric, \ + js::proxy_Watch, js::proxy_Unwatch, \ + js::proxy_Slice, \ + nullptr, /* enumerate */ \ + nullptr, /* thisObject */ \ + } \ + } + +#define PROXY_CLASS_DEF(name, extraSlots, flags, callOp, constructOp) \ + PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, \ + PROXY_MAKE_EXT( \ + nullptr, /* outerObject */ \ + nullptr, /* innerObject */ \ + nullptr, /* iteratorObject */ \ + false /* isWrappedNative */ \ + )) + +/* + * Proxy stubs, similar to JS_*Stub, for embedder proxy class definitions. + * + * NB: Should not be called directly. + */ + +extern JS_FRIEND_API(bool) +proxy_LookupGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleObject objp, JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_DefineGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, + unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_GetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetProperty(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, + JS::Handle name, JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetElement(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_SetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp, + bool strict); +extern JS_FRIEND_API(bool) +proxy_GetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_SetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_DeleteGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); + +extern JS_FRIEND_API(void) +proxy_Trace(JSTracer *trc, JSObject *obj); +extern JS_FRIEND_API(JSObject *) +proxy_WeakmapKeyDelegate(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Convert(JSContext *cx, JS::HandleObject proxy, JSType hint, JS::MutableHandleValue vp); +extern JS_FRIEND_API(void) +proxy_Finalize(FreeOp *fop, JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_HasInstance(JSContext *cx, JS::HandleObject proxy, JS::MutableHandleValue v, bool *bp); +extern JS_FRIEND_API(bool) +proxy_Call(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(bool) +proxy_Construct(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(JSObject *) +proxy_innerObject(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Watch(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); +extern JS_FRIEND_API(bool) +proxy_Unwatch(JSContext *cx, JS::HandleObject obj, JS::HandleId id); +extern JS_FRIEND_API(bool) +proxy_Slice(JSContext *cx, JS::HandleObject proxy, uint32_t begin, uint32_t end, + JS::HandleObject result); + /* * A class of objects that return source code on demand. * - * When code is compiled with CompileOptions::LAZY_SOURCE, SpiderMonkey - * doesn't retain the source code (and doesn't do lazy bytecode - * generation). If we ever need the source code, say, in response to a call - * to Function.prototype.toSource or Debugger.Source.prototype.text, then - * we call the 'load' member function of the instance of this class that - * has hopefully been registered with the runtime, passing the code's URL, - * and hope that it will be able to find the source. + * When code is compiled with setSourceIsLazy(true), SpiderMonkey doesn't + * retain the source code (and doesn't do lazy bytecode generation). If we ever + * need the source code, say, in response to a call to Function.prototype. + * toSource or Debugger.Source.prototype.text, then we call the 'load' member + * function of the instance of this class that has hopefully been registered + * with the runtime, passing the code's URL, and hope that it will be able to + * find the source. */ class SourceHook { public: @@ -249,18 +416,25 @@ class SourceHook { }; /* - * Have |rt| use |hook| to retrieve LAZY_SOURCE source code. See the + * Have |rt| use |hook| to retrieve lazily-retrieved source code. See the * comments for SourceHook. The runtime takes ownership of the hook, and * will delete it when the runtime itself is deleted, or when a new hook is * set. */ extern JS_FRIEND_API(void) -SetSourceHook(JSRuntime *rt, SourceHook *hook); +SetSourceHook(JSRuntime *rt, mozilla::UniquePtr hook); /* Remove |rt|'s source hook, and return it. The caller now owns the hook. */ -extern JS_FRIEND_API(SourceHook *) +extern JS_FRIEND_API(mozilla::UniquePtr) ForgetSourceHook(JSRuntime *rt); +#ifdef NIGHTLY_BUILD +typedef void (*AssertOnScriptEntryHook)(JSContext *cx, JS::HandleScript script); + +extern JS_FRIEND_API(void) +SetAssertOnScriptEntryHook(JSRuntime *rt, AssertOnScriptEntryHook hook); +#endif + extern JS_FRIEND_API(JS::Zone *) GetCompartmentZone(JSCompartment *comp); @@ -293,16 +467,6 @@ IsSystemZone(JS::Zone *zone); extern JS_FRIEND_API(bool) IsAtomsCompartment(JSCompartment *comp); -/* - * Check whether it is OK to assign an undeclared variable with the name - * |propname| at the current location in script. It is not an error if there is - * no current script location, or if that location is not an assignment to an - * undeclared variable. Reports an error if one needs to be reported (and, - * particularly, always reports when it returns false). - */ -extern JS_FRIEND_API(bool) -ReportIfUndeclaredVarAssignment(JSContext *cx, JS::HandleString propname); - /* * Returns whether we're in a non-strict property set (in that we're in a * non-strict script and the bytecode we're on is a property set). The return @@ -339,6 +503,9 @@ TraceWeakMaps(WeakMapTracer *trc); extern JS_FRIEND_API(bool) AreGCGrayBitsValid(JSRuntime *rt); +extern JS_FRIEND_API(bool) +ZoneGlobalsAreAllGray(JS::Zone *zone); + typedef void (*GCThingCallback)(void *closure, void *gcthing); @@ -379,7 +546,7 @@ struct TypeObject { }; struct BaseShape { - const js::Class *clasp; + const js::Class *clasp_; JSObject *parent; JSObject *_1; JSCompartment *compartment; @@ -427,10 +594,20 @@ struct Function { void *_1; }; -struct Atom { - static const size_t LENGTH_SHIFT = 4; - size_t lengthAndFlags; - const jschar *chars; +struct String +{ + static const uint32_t INLINE_CHARS_BIT = JS_BIT(2); + static const uint32_t LATIN1_CHARS_BIT = JS_BIT(6); + static const uint32_t ROPE_FLAGS = 0; + static const uint32_t TYPE_FLAGS_MASK = JS_BIT(6) - 1; + uint32_t flags; + uint32_t length; + union { + const JS::Latin1Char *nonInlineCharsLatin1; + const jschar *nonInlineCharsTwoByte; + JS::Latin1Char inlineStorageLatin1[1]; + jschar inlineStorageTwoByte[1]; + }; }; } /* namespace shadow */ @@ -451,6 +628,46 @@ GetObjectJSClass(JSObject *obj) return js::Jsvalify(GetObjectClass(obj)); } +JS_FRIEND_API(const Class *) +ProtoKeyToClass(JSProtoKey key); + +// Returns true if the standard class identified by |key| inherits from +// another standard class with the same js::Class. This basically means +// that the various properties described by our js::Class are intended +// to live higher up on the proto chain. +// +// In practice, this only returns true for Error subtypes. +inline bool +StandardClassIsDependent(JSProtoKey key) +{ + JSProtoKey keyFromClass = JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + MOZ_ASSERT(keyFromClass); + return key != keyFromClass; +} + +// Returns the key for the class inherited by a given standard class (that +// is to say, the prototype of this standard class's prototype). +// +// You must be sure that this corresponds to a standard class with a cached +// JSProtoKey before calling this function. In general |key| will match the +// cached proto key, except in cases where multiple JSProtoKeys share a +// JSClass. +inline JSProtoKey +ParentKeyForStandardClass(JSProtoKey key) +{ + // [Object] has nothing to inherit from. + if (key == JSProto_Object) + return JSProto_Null; + + // If we're dependent (i.e. an Error subtype), return the key of the class + // we depend on. + if (StandardClassIsDependent(key)) + return JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + + // Otherwise, we inherit [Object]. + return JSProto_Object; +} + inline bool IsInnerObject(JSObject *obj) { return !!GetObjectClass(obj)->ext.outerObject; @@ -477,7 +694,7 @@ GetObjectParent(JSObject *obj) return reinterpret_cast(obj)->shape->base->parent; } -static JS_ALWAYS_INLINE JSCompartment * +static MOZ_ALWAYS_INLINE JSCompartment * GetObjectCompartment(JSObject *obj) { return reinterpret_cast(obj)->shape->base->compartment; @@ -489,10 +706,15 @@ GetObjectParentMaybeScope(JSObject *obj); JS_FRIEND_API(JSObject *) GetGlobalForObjectCrossCompartment(JSObject *obj); +// Sidestep the activeContext checking implicitly performed in +// JS_SetPendingException. +JS_FRIEND_API(void) +SetPendingExceptionCrossContext(JSContext *cx, JS::HandleValue v); + JS_FRIEND_API(void) AssertSameCompartment(JSContext *cx, JSObject *obj); -#ifdef DEBUG +#ifdef JS_DEBUG JS_FRIEND_API(void) AssertSameCompartment(JSObject *objA, JSObject *objB); #else @@ -509,9 +731,6 @@ SetDefaultObjectForContext(JSContext *cx, JSObject *obj); JS_FRIEND_API(void) NotifyAnimationActivity(JSObject *obj); -JS_FRIEND_API(bool) -IsOriginalScriptFunction(JSFunction *fun); - /* * Return the outermost enclosing function (script) of the scripted caller. * This function returns nullptr in several cases: @@ -521,7 +740,7 @@ IsOriginalScriptFunction(JSFunction *fun); * thus it will really return the outermost enclosing function *since the * innermost eval*. */ -JS_FRIEND_API(JSScript *) +JS_FRIEND_API(JSFunction *) GetOutermostEnclosingFunctionOfScriptedCaller(JSContext *cx); JS_FRIEND_API(JSFunction *) @@ -536,12 +755,6 @@ JS_FRIEND_API(JSFunction *) NewFunctionByIdWithReserved(JSContext *cx, JSNative native, unsigned nargs, unsigned flags, JSObject *parent, jsid id); -JS_FRIEND_API(JSObject *) -InitClassWithReserved(JSContext *cx, JSObject *obj, JSObject *parent_proto, - const JSClass *clasp, JSNative constructor, unsigned nargs, - const JSPropertySpec *ps, const JSFunctionSpec *fs, - const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs); - JS_FRIEND_API(const JS::Value &) GetFunctionNativeReserved(JSObject *fun, size_t which); @@ -549,7 +762,7 @@ JS_FRIEND_API(void) SetFunctionNativeReserved(JSObject *fun, size_t which, const JS::Value &val); JS_FRIEND_API(bool) -GetObjectProto(JSContext *cx, JS::Handle obj, JS::MutableHandle proto); +GetObjectProto(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject proto); JS_FRIEND_API(bool) GetOriginalEval(JSContext *cx, JS::HandleObject scope, @@ -604,25 +817,142 @@ GetObjectSlot(JSObject *obj, size_t slot) return reinterpret_cast(obj)->slotRef(slot); } -inline const jschar * -GetAtomChars(JSAtom *atom) +MOZ_ALWAYS_INLINE size_t +GetAtomLength(JSAtom *atom) { - return reinterpret_cast(atom)->chars; + return reinterpret_cast(atom)->length; } -inline size_t -GetAtomLength(JSAtom *atom) +static const uint32_t MaxStringLength = (1 << 28) - 1; + +MOZ_ALWAYS_INLINE size_t +GetStringLength(JSString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetFlatStringLength(JSFlatString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetLinearStringLength(JSLinearString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE bool +LinearStringHasLatin1Chars(JSLinearString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE bool +AtomHasLatin1Chars(JSAtom *atom) { - using shadow::Atom; - return reinterpret_cast(atom)->lengthAndFlags >> Atom::LENGTH_SHIFT; + return reinterpret_cast(atom)->flags & shadow::String::LATIN1_CHARS_BIT; } -inline JSLinearString * +MOZ_ALWAYS_INLINE bool +StringHasLatin1Chars(JSString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1LinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageLatin1; + return s->nonInlineCharsLatin1; +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteLinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(!LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageTwoByte; + return s->nonInlineCharsTwoByte; +} + +MOZ_ALWAYS_INLINE JSLinearString * AtomToLinearString(JSAtom *atom) { return reinterpret_cast(atom); } +MOZ_ALWAYS_INLINE JSLinearString * +FlatStringToLinearString(JSFlatString *s) +{ + return reinterpret_cast(s); +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1AtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetLatin1LinearStringChars(nogc, AtomToLinearString(atom)); +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteAtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetTwoByteLinearStringChars(nogc, AtomToLinearString(atom)); +} + +JS_FRIEND_API(JSLinearString *) +StringToLinearStringSlow(JSContext *cx, JSString *str); + +MOZ_ALWAYS_INLINE JSLinearString * +StringToLinearString(JSContext *cx, JSString *str) +{ + using shadow::String; + String *s = reinterpret_cast(str); + if (MOZ_UNLIKELY((s->flags & String::TYPE_FLAGS_MASK) == String::ROPE_FLAGS)) + return StringToLinearStringSlow(cx, str); + return reinterpret_cast(str); +} + +MOZ_ALWAYS_INLINE void +CopyLinearStringChars(jschar *dest, JSLinearString *s, size_t len) +{ + JS::AutoCheckCannotGC nogc; + if (LinearStringHasLatin1Chars(s)) { + const JS::Latin1Char *src = GetLatin1LinearStringChars(nogc, s); + for (size_t i = 0; i < len; i++) + dest[i] = src[i]; + } else { + const jschar *src = GetTwoByteLinearStringChars(nogc, s); + mozilla::PodCopy(dest, src, len); + } +} + +inline bool +CopyStringChars(JSContext *cx, jschar *dest, JSString *s, size_t len) +{ + JSLinearString *linear = StringToLinearString(cx, s); + if (!linear) + return false; + + CopyLinearStringChars(dest, linear, len); + return true; +} + +inline void +CopyFlatStringChars(jschar *dest, JSFlatString *s, size_t len) +{ + CopyLinearStringChars(dest, FlatStringToLinearString(s), len); +} + JS_FRIEND_API(bool) GetPropertyNames(JSContext *cx, JSObject *obj, unsigned flags, JS::AutoIdVector *props); @@ -641,24 +971,18 @@ SetPreserveWrapperCallback(JSRuntime *rt, PreserveWrapperCallback callback); JS_FRIEND_API(bool) IsObjectInContextCompartment(JSObject *obj, const JSContext *cx); -/* - * ErrorFromException takes a raw Value so that it's possible to call it during - * GC/CC/whatever, when it may not be possible to get a JSContext to create a - * Rooted. It promises to never ever GC. - */ -JS_FRIEND_API(JSErrorReport*) -ErrorFromException(JS::Value val); - /* * NB: these flag bits are encoded into the bytecode stream in the immediate * operand of JSOP_ITER, so don't change them without advancing vm/Xdr.h's * XDR_BYTECODE_VERSION. */ #define JSITER_ENUMERATE 0x1 /* for-in compatible hidden default iterator */ -#define JSITER_FOREACH 0x2 /* return [key, value] pair rather than key */ -#define JSITER_KEYVALUE 0x4 /* destructuring for-in wants [key, value] */ +#define JSITER_FOREACH 0x2 /* get obj[key] for each property */ +#define JSITER_KEYVALUE 0x4 /* obsolete destructuring for-in wants [key, value] */ #define JSITER_OWNONLY 0x8 /* iterate over obj's own properties only */ #define JSITER_HIDDEN 0x10 /* also enumerate non-enumerable properties */ +#define JSITER_SYMBOLS 0x20 /* also include symbol property keys */ +#define JSITER_SYMBOLSONLY 0x40 /* exclude string property keys */ JS_FRIEND_API(bool) RunningWithTrustedPrincipals(JSContext *cx); @@ -677,6 +1001,7 @@ GetNativeStackLimit(JSContext *cx) * These macros report a stack overflow and run |onerror| if we are close to * using up the C stack. The JS_CHECK_CHROME_RECURSION variant gives us a little * extra space so that we can ensure that crucial code is able to run. + * JS_CHECK_RECURSION_CONSERVATIVE gives us a little less space. */ #define JS_CHECK_RECURSION(cx, onerror) \ @@ -723,6 +1048,18 @@ GetNativeStackLimit(JSContext *cx) } \ JS_END_MACRO +#define JS_CHECK_RECURSION_CONSERVATIVE(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(js::GetNativeStackLimit(cx), \ + &stackDummy_, \ + 1024 * sizeof(size_t))) \ + { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + JS_FRIEND_API(void) StartPCCountProfiling(JSContext *cx); @@ -764,9 +1101,10 @@ extern JS_FRIEND_API(bool) IsContextRunningJS(JSContext *cx); typedef bool -(* DOMInstanceClassMatchesProto)(JSObject *protoObject, uint32_t protoID, uint32_t depth); +(* DOMInstanceClassHasProtoAtDepth)(const Class *instanceClass, + uint32_t protoID, uint32_t depth); struct JSDOMCallbacks { - DOMInstanceClassMatchesProto instanceClassMatchesProto; + DOMInstanceClassHasProtoAtDepth instanceClassMatchesProto; }; typedef struct JSDOMCallbacks DOMCallbacks; @@ -796,10 +1134,10 @@ CastToJSFreeOp(FreeOp *fop) * Get an error type name from a JSExnType constant. * Returns nullptr for invalid arguments and JSEXN_INTERNALERR */ -extern JS_FRIEND_API(const jschar*) -GetErrorTypeName(JSRuntime* rt, int16_t exnType); +extern JS_FRIEND_API(JSFlatString *) +GetErrorTypeName(JSRuntime *rt, int16_t exnType); -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_FRIEND_API(unsigned) GetEnterCompartmentDepth(JSContext* cx); #endif @@ -836,13 +1174,13 @@ struct ChromeCompartmentsOnly : public CompartmentFilter { struct SingleCompartment : public CompartmentFilter { JSCompartment *ours; - SingleCompartment(JSCompartment *c) : ours(c) {} + explicit SingleCompartment(JSCompartment *c) : ours(c) {} virtual bool match(JSCompartment *c) const { return c == ours; } }; struct CompartmentsWithPrincipals : public CompartmentFilter { JSPrincipals *principals; - CompartmentsWithPrincipals(JSPrincipals *p) : principals(p) {} + explicit CompartmentsWithPrincipals(JSPrincipals *p) : principals(p) {} virtual bool match(JSCompartment *c) const { return JS_GetCompartmentPrincipals(c) == principals; } @@ -941,49 +1279,198 @@ typedef enum JSErrNum { } JSErrNum; extern JS_FRIEND_API(const JSErrorFormatString *) -js_GetErrorMessage(void *userRef, const char *locale, const unsigned errorNumber); +js_GetErrorMessage(void *userRef, const unsigned errorNumber); + +namespace js { + +// AutoStableStringChars is here so we can use it in ErrorReport. It +// should get moved out of here if we can manage it. See bug 1040316. + +/* + * This class provides safe access to a string's chars across a GC. Once + * we allocate strings and chars in the nursery (bug 903519), this class + * will have to make a copy of the string's chars if they are allocated + * in the nursery, so it's best to avoid using this class unless you really + * need it. It's usually more efficient to use the latin1Chars/twoByteChars + * JSString methods and often the code can be rewritten so that only indexes + * instead of char pointers are used in parts of the code that can GC. + */ +class MOZ_STACK_CLASS AutoStableStringChars +{ + /* Ensure the string is kept alive while we're using its chars. */ + JS::RootedString s_; + union { + const jschar *twoByteChars_; + const JS::Latin1Char *latin1Chars_; + }; + enum State { Uninitialized, Latin1, TwoByte }; + State state_; + bool ownsChars_; + + public: + AutoStableStringChars(JSContext *cx) + : s_(cx), state_(Uninitialized), ownsChars_(false) + {}; + ~AutoStableStringChars(); + + bool init(JSContext *cx, JSString *s); + + /* Like init(), but Latin1 chars are inflated to TwoByte. */ + bool initTwoByte(JSContext *cx, JSString *s); + + bool isLatin1() const { return state_ == Latin1; } + bool isTwoByte() const { return state_ == TwoByte; } + + const jschar *twoByteChars() const { + MOZ_ASSERT(state_ == TwoByte); + return twoByteChars_; + } + + mozilla::Range latin1Range() const { + MOZ_ASSERT(state_ == Latin1); + return mozilla::Range(latin1Chars_, + GetStringLength(s_)); + } + + mozilla::Range twoByteRange() const { + MOZ_ASSERT(state_ == TwoByte); + return mozilla::Range(twoByteChars_, + GetStringLength(s_)); + } + + /* If we own the chars, transfer ownership to the caller. */ + bool maybeGiveOwnershipToCaller() { + MOZ_ASSERT(state_ != Uninitialized); + if (!ownsChars_) + return false; + state_ = Uninitialized; + ownsChars_ = false; + return true; + } + + private: + AutoStableStringChars(const AutoStableStringChars &other) MOZ_DELETE; + void operator=(const AutoStableStringChars &other) MOZ_DELETE; +}; + +// Creates a string of the form |ErrorType: ErrorMessage| for a JSErrorReport, +// which generally matches the toString() behavior of an ErrorObject. +extern JS_FRIEND_API(JSString *) +ErrorReportToString(JSContext *cx, JSErrorReport *reportp); + +struct MOZ_STACK_CLASS JS_FRIEND_API(ErrorReport) +{ + ErrorReport(JSContext *cx); + ~ErrorReport(); + + bool init(JSContext *cx, JS::HandleValue exn); + + JSErrorReport *report() + { + return reportp; + } + + const char *message() + { + return message_; + } + + private: + // More or less an equivalent of JS_ReportErrorNumber/js_ReportErrorNumberVA + // but fills in an ErrorReport instead of reporting it. Uses varargs to + // make it simpler to call js_ExpandErrorArguments. + void populateUncaughtExceptionReport(JSContext *cx, ...); + void populateUncaughtExceptionReportVA(JSContext *cx, va_list ap); + + // We may have a provided JSErrorReport, so need a way to represent that. + JSErrorReport *reportp; + + // And we may have a message. + const char *message_; + + // Or we may need to synthesize a JSErrorReport one of our own. + JSErrorReport ownedReport; + + // Or a message of our own. If this is non-null, we need to clean up both + // it and ownedReport. + char *ownedMessage; + + // And we have a string to maybe keep alive that has pointers into + // it from ownedReport. + JS::RootedString str; + + // And keep its chars alive too. + AutoStableStringChars strChars; + + // And we need to root our exception value. + JS::RootedObject exnObject; + + // And possibly some byte storage for our message_. + JSAutoByteString bytesStorage; + + // And for our filename. + JSAutoByteString filename; + + // True if we need to free message_ and the stuff in ownedReport + bool ownsMessageAndReport; +}; + +} /* namespace js */ + /* Implemented in jsclone.cpp. */ extern JS_FRIEND_API(uint64_t) js_GetSCOffset(JSStructuredCloneWriter* writer); -/* Typed Array functions, implemented in jstypedarray.cpp */ - namespace js { -namespace ArrayBufferView { - -enum ViewType { - TYPE_INT8 = 0, - TYPE_UINT8, - TYPE_INT16, - TYPE_UINT16, - TYPE_INT32, - TYPE_UINT32, - TYPE_FLOAT32, - TYPE_FLOAT64, +namespace Scalar { + +/* Scalar types which can appear in typed arrays and typed objects. */ +enum Type { + Int8 = 0, + Uint8, + Int16, + Uint16, + Int32, + Uint32, + Float32, + Float64, /* * Special type that is a uint8_t, but assignments are clamped to [0, 256). * Treat the raw data type as a uint8_t. */ - TYPE_UINT8_CLAMPED, + Uint8Clamped, - /* - * Type returned for a DataView. Note that there is no single element type - * in this case. - */ - TYPE_DATAVIEW, - - TYPE_MAX + TypeMax }; -} /* namespace ArrayBufferView */ +static inline size_t +byteSize(Type atype) +{ + switch (atype) { + case Int8: + case Uint8: + case Uint8Clamped: + return 1; + case Int16: + case Uint16: + return 2; + case Int32: + case Uint32: + case Float32: + return 4; + case Float64: + return 8; + default: + MOZ_CRASH("invalid scalar type"); + } +} +} /* namespace Scalar */ } /* namespace js */ -typedef js::ArrayBufferView::ViewType JSArrayBufferViewType; - /* * Create a new typed array with nelements elements. * @@ -1019,23 +1506,23 @@ JS_NewFloat64Array(JSContext *cx, uint32_t nelements); */ extern JS_FRIEND_API(JSObject *) -JS_NewInt8ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt8ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint8ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ClampedArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint8ClampedArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewInt16ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt16ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint16ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint16ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewInt32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewFloat32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewFloat32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewFloat64ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewFloat64ArrayFromArray(JSContext *cx, JS::HandleObject array); /* * Create a new typed array using the given ArrayBuffer for storage. The @@ -1044,31 +1531,31 @@ JS_NewFloat64ArrayFromArray(JSContext *cx, JSObject *array); */ extern JS_FRIEND_API(JSObject *) -JS_NewInt8ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewInt16ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint16ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewInt32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewFloat32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewFloat32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewFloat64ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewFloat64ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); /* @@ -1119,6 +1606,93 @@ JS_IsFloat32Array(JSObject *obj); extern JS_FRIEND_API(bool) JS_IsFloat64Array(JSObject *obj); +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +namespace js { + +extern JS_FRIEND_API(JSObject *) +UnwrapInt8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8ClampedArray(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat64Array(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBuffer(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBufferView(JSObject *obj); + +namespace detail { + +extern JS_FRIEND_DATA(const Class* const) Int8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ClampedArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float64ArrayClassPtr; + +const size_t TypedArrayLengthSlot = 1; + +} // namespace detail + +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +#define JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Type, type) \ +inline void \ +Get ## Type ## ArrayLengthAndData(JSObject *obj, uint32_t *length, type **data) \ +{ \ + JS_ASSERT(GetObjectClass(obj) == detail::Type ## ArrayClassPtr); \ + const JS::Value &slot = GetReservedSlot(obj, detail::TypedArrayLengthSlot); \ + *length = mozilla::SafeCast(slot.toInt32()); \ + *data = static_cast(GetObjectPrivate(obj)); \ +} + +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int8, int8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8Clamped, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int16, int16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint16, uint16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int32, int32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint32, uint32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float32, float) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float64, double) + +#undef JS_DEFINE_DATA_AND_LENGTH_ACCESSOR + +// This one isn't inlined because it's rather tricky (by dint of having to deal +// with a dozen-plus classes and varying slot layouts. +extern JS_FRIEND_API(void) +GetArrayBufferViewLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +// This one isn't inlined because there are a bunch of different ArrayBuffer +// classes that would have to be individually handled here. +extern JS_FRIEND_API(void) +GetArrayBufferLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +} // namespace js + /* * Unwrap Typed arrays all at once. Return nullptr without throwing if the * object cannot be viewed as the correct typed array, or the typed array @@ -1148,13 +1722,13 @@ extern JS_FRIEND_API(JSObject *) JS_GetObjectAsArrayBuffer(JSObject *obj, uint32_t *length, uint8_t **data); /* - * Get the type of elements in a typed array, or TYPE_DATAVIEW if a DataView. + * Get the type of elements in a typed array, or TypeMax if a DataView. * * |obj| must have passed a JS_IsArrayBufferView/JS_Is*Array test, or somehow * be known that it would pass such a test: it is an ArrayBufferView or a * wrapper of an ArrayBufferView, and the unwrapping will succeed. */ -extern JS_FRIEND_API(JSArrayBufferViewType) +extern JS_FRIEND_API(js::Scalar::Type) JS_GetArrayBufferViewType(JSObject *obj); /* @@ -1177,16 +1751,12 @@ extern JS_FRIEND_API(uint32_t) JS_GetArrayBufferByteLength(JSObject *obj); /* - * Return a pointer to an array buffer's data. The buffer is still owned by the - * array buffer object, and should not be modified on another thread. The - * returned pointer is stable across GCs. - * - * |obj| must have passed a JS_IsArrayBufferObject test, or somehow be known - * that it would pass such a test: it is an ArrayBuffer or a wrapper of an - * ArrayBuffer, and the unwrapping will succeed. + * Check whether the obj is ArrayBufferObject and memory mapped. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. */ -extern JS_FRIEND_API(uint8_t *) -JS_GetArrayBufferData(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsMappedArrayBufferObject(JSObject *obj); /* * Return the number of elements in a typed array. @@ -1236,13 +1806,17 @@ JS_GetArrayBufferViewByteLength(JSObject *obj); /* * Return a pointer to the start of the data referenced by a typed array. The * data is still owned by the typed array, and should not be modified on - * another thread. + * another thread. Furthermore, the pointer can become invalid on GC (if the + * data is small and fits inside the array's GC header), so callers must take + * care not to hold on across anything that could GC. * * |obj| must have passed a JS_Is*Array test, or somehow be known that it would * pass such a test: it is a typed array or a wrapper of a typed array, and the * unwrapping will succeed. */ +extern JS_FRIEND_API(uint8_t *) +JS_GetArrayBufferData(JSObject *obj); extern JS_FRIEND_API(int8_t *) JS_GetInt8ArrayData(JSObject *obj); extern JS_FRIEND_API(uint8_t *) @@ -1262,6 +1836,13 @@ JS_GetFloat32ArrayData(JSObject *obj); extern JS_FRIEND_API(double *) JS_GetFloat64ArrayData(JSObject *obj); +/* + * Stable versions of the above functions where the buffer remains valid as long + * as the object is live. + */ +extern JS_FRIEND_API(uint8_t *) +JS_GetStableArrayBufferData(JSContext *cx, JS::HandleObject obj); + /* * Same as above, but for any kind of ArrayBufferView. Prefer the type-specific * versions when possible. @@ -1275,13 +1856,33 @@ JS_GetArrayBufferViewData(JSObject *obj); * object that would return true for JS_IsArrayBufferViewObject(). */ extern JS_FRIEND_API(JSObject *) -JS_GetArrayBufferViewBuffer(JSObject *obj); +JS_GetArrayBufferViewBuffer(JSContext *cx, JS::HandleObject obj); + +typedef enum { + ChangeData, + KeepData +} NeuterDataDisposition; /* * Set an ArrayBuffer's length to 0 and neuter all of its views. + * + * The |changeData| argument is a hint to inform internal behavior with respect + * to the internal pointer to the ArrayBuffer's data after being neutered. + * There is no guarantee it will be respected. But if it is respected, the + * ArrayBuffer's internal data pointer will, or will not, have changed + * accordingly. + */ +extern JS_FRIEND_API(bool) +JS_NeuterArrayBuffer(JSContext *cx, JS::HandleObject obj, + NeuterDataDisposition changeData); + +/* + * Check whether the obj is ArrayBufferObject and neutered. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. */ extern JS_FRIEND_API(bool) -JS_NeuterArrayBuffer(JSContext *cx, JS::HandleObject obj); +JS_IsNeuteredArrayBufferObject(JSObject *obj); /* * Check whether obj supports JS_GetDataView* APIs. @@ -1360,7 +1961,7 @@ class JSJitGetterCallArgs : protected JS::MutableHandleValue : JS::MutableHandleValue(args.rval()) {} - explicit JSJitGetterCallArgs(JS::Rooted* rooted) + explicit JSJitGetterCallArgs(JS::RootedValue* rooted) : JS::MutableHandleValue(rooted) {} @@ -1422,6 +2023,12 @@ class JSJitMethodCallArgs : protected JS::detail::CallArgsBaseusedRval_, which we don't have. + return argv_[-2].toObject(); + } + // Add get() as needed }; @@ -1451,7 +2058,10 @@ struct JSJitInfo { Getter, Setter, Method, - OpType_None + ParallelNative, + StaticMethod, + // Must be last + OpTypeCount }; enum ArgType { @@ -1475,6 +2085,13 @@ struct JSJitInfo { ArgTypeListEnd = (1 << 31) }; + static_assert(Any & String, "Any must include String."); + static_assert(Any & Integer, "Any must include Integer."); + static_assert(Any & Double, "Any must include Double."); + static_assert(Any & Boolean, "Any must include Boolean."); + static_assert(Any & Object, "Any must include Object."); + static_assert(Any & Null, "Any must include Null."); + enum AliasSet { // An enum that describes what this getter/setter/method aliases. This // determines what things can be hoisted past this call, and if this @@ -1490,69 +2107,172 @@ struct JSJitInfo { // Alias the world. Calling this can change arbitrary values anywhere // in the system. Most things fall in this bucket. - AliasEverything + AliasEverything, + + // Must be last. + AliasSetCount }; - bool isDOMJitInfo() const + bool hasParallelNative() const + { + return type() == ParallelNative; + } + + bool needsOuterizedThisObject() const + { + return type() != Getter && type() != Setter; + } + + bool isTypedMethodJitInfo() const { - return type != OpType_None; + return isTypedMethod; + } + + OpType type() const + { + return OpType(type_); + } + + AliasSet aliasSet() const + { + return AliasSet(aliasSet_); + } + + JSValueType returnType() const + { + return JSValueType(returnType_); } union { JSJitGetterOp getter; JSJitSetterOp setter; JSJitMethodOp method; + /* An alternative native that's safe to call in parallel mode. */ + JSParallelNative parallelNative; + /* A DOM static method, used for Promise wrappers */ + JSNative staticMethod; }; - uint32_t protoID; - uint32_t depth; - // type not being OpType_None means this is a DOM method. If you - // change that, come up with a different way of implementing - // isDOMJitInfo(). - OpType type; - bool isInfallible; /* Is op fallible? False in setters. */ - bool isMovable; /* Is op movable? To be movable the op must not - AliasEverything, but even that might not be - enough (e.g. in cases when it can throw). */ - AliasSet aliasSet; /* The alias set for this op. This is a _minimal_ - alias set; in particular for a method it does not - include whatever argument conversions might do. - That's covered by argTypes and runtime analysis - of the actual argument types being passed in. */ - // XXXbz should we have a JSGetterJitInfo subclass or something? + uint16_t protoID; + uint16_t depth; + + // These fields are carefully packed to take up 4 bytes. If you need more + // bits for whatever reason, please see if you can steal bits from existing + // fields before adding more members to this structure. + +#define JITINFO_OP_TYPE_BITS 4 +#define JITINFO_ALIAS_SET_BITS 4 +#define JITINFO_RETURN_TYPE_BITS 8 + + // The OpType that says what sort of function we are. + uint32_t type_ : JITINFO_OP_TYPE_BITS; + + // The alias set for this op. This is a _minimal_ alias set; in + // particular for a method it does not include whatever argument + // conversions might do. That's covered by argTypes and runtime + // analysis of the actual argument types being passed in. + uint32_t aliasSet_ : JITINFO_ALIAS_SET_BITS; + + // The return type tag. Might be JSVAL_TYPE_UNKNOWN. + uint32_t returnType_ : JITINFO_RETURN_TYPE_BITS; + + static_assert(OpTypeCount <= (1 << JITINFO_OP_TYPE_BITS), + "Not enough space for OpType"); + static_assert(AliasSetCount <= (1 << JITINFO_ALIAS_SET_BITS), + "Not enough space for AliasSet"); + static_assert((sizeof(JSValueType) * 8) <= JITINFO_RETURN_TYPE_BITS, + "Not enough space for JSValueType"); + +#undef JITINFO_RETURN_TYPE_BITS +#undef JITINFO_ALIAS_SET_BITS +#undef JITINFO_OP_TYPE_BITS + + uint32_t isInfallible : 1; /* Is op fallible? False in setters. */ + uint32_t isMovable : 1; /* Is op movable? To be movable the op must + not AliasEverything, but even that might + not be enough (e.g. in cases when it can + throw). */ // XXXbz should we have a JSValueType for the type of the member? - bool isInSlot; /* True if this is a getter that can get a member - from a slot of the "this" object directly. */ - size_t slotIndex; /* If isMember is true, the index of the slot to get - the value from. Otherwise 0. */ - JSValueType returnType; /* The return type tag. Might be JSVAL_TYPE_UNKNOWN */ - - const ArgType* const argTypes; /* For a method, a list of sets of types that - the function expects. This can be used, - for example, to figure out when argument - coercions can have side-effects. nullptr - if we have no type information for - arguments. */ - - /* An alternative native that's safe to call in parallel mode. */ - JSParallelNative parallelNative; - -private: - static void staticAsserts() - { - JS_STATIC_ASSERT(Any & String); - JS_STATIC_ASSERT(Any & Integer); - JS_STATIC_ASSERT(Any & Double); - JS_STATIC_ASSERT(Any & Boolean); - JS_STATIC_ASSERT(Any & Object); - JS_STATIC_ASSERT(Any & Null); - } + uint32_t isAlwaysInSlot : 1; /* True if this is a getter that can always + get the value from a slot of the "this" + object. */ + uint32_t isLazilyCachedInSlot : 1; /* True if this is a getter that can + sometimes (if the slot doesn't contain + UndefinedValue()) get the value from a + slot of the "this" object. */ + uint32_t isTypedMethod : 1; /* True if this is an instance of + JSTypedMethodJitInfo. */ + uint32_t slotIndex : 11; /* If isAlwaysInSlot or isSometimesInSlot is + true, the index of the slot to get the value + from. Otherwise 0. */ }; -#define JS_JITINFO_NATIVE_PARALLEL(op) \ - {{nullptr},0,0,JSJitInfo::OpType_None,false,false,JSJitInfo::AliasEverything,false,0,JSVAL_TYPE_MISSING,nullptr,op} +static_assert(sizeof(JSJitInfo) == (sizeof(void*) + 2 * sizeof(uint32_t)), + "There are several thousand instances of JSJitInfo stored in " + "a binary. Please don't increase its space requirements without " + "verifying that there is no other way forward (better packing, " + "smaller datatypes for fields, subclassing, etc.)."); -static JS_ALWAYS_INLINE const JSJitInfo * +struct JSTypedMethodJitInfo +{ + // We use C-style inheritance here, rather than C++ style inheritance + // because not all compilers support brace-initialization for non-aggregate + // classes. Using C++ style inheritance and constructors instead of + // brace-initialization would also force the creation of static + // constructors (on some compilers) when JSJitInfo and JSTypedMethodJitInfo + // structures are declared. Since there can be several thousand of these + // structures present and we want to have roughly equivalent performance + // across a range of compilers, we do things manually. + JSJitInfo base; + + const JSJitInfo::ArgType* const argTypes; /* For a method, a list of sets of + types that the function + expects. This can be used, + for example, to figure out + when argument coercions can + have side-effects. */ +}; + +namespace JS { +namespace detail { + +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_PARALLEL_NATIVE_TO only. */ +inline int CheckIsParallelNative(JSParallelNative parallelNative); + +} // namespace detail +} // namespace JS + +#define JS_CAST_PARALLEL_NATIVE_TO(v, To) \ + (static_cast(sizeof(JS::detail::CheckIsParallelNative(v))), \ + reinterpret_cast(v)) + +/* + * You may ask yourself: why do we define a wrapper around a wrapper here? + * The answer is that some compilers don't understand initializing a union + * as we do below with a construct like: + * + * reinterpret_cast(JSParallelNativeThreadSafeWrapper) + * + * (We need the reinterpret_cast because we must initialize the union with + * a datum of the type of the union's first member.) + * + * Presumably this has something to do with template instantiation. + * Initializing with a normal function pointer seems to work fine. Hence + * the ugliness that you see before you. + */ +#define JS_JITINFO_NATIVE_PARALLEL(infoName, parallelOp) \ + const JSJitInfo infoName = \ + {{JS_CAST_PARALLEL_NATIVE_TO(parallelOp, JSJitGetterOp)},0,0,JSJitInfo::ParallelNative,JSJitInfo::AliasEverything,JSVAL_TYPE_MISSING,false,false,false,false,false,0} + +#define JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(infoName, wrapperName, serialOp) \ + bool wrapperName##_ParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, \ + JS::Value *vp) \ + { \ + return JSParallelNativeThreadSafeWrapper(cx, argc, vp); \ + } \ + JS_JITINFO_NATIVE_PARALLEL(infoName, wrapperName##_ParallelNativeThreadSafeWrapper) + +static MOZ_ALWAYS_INLINE const JSJitInfo * FUNCTION_VALUE_TO_JITINFO(const JS::Value& v) { JS_ASSERT(js::GetObjectClass(&v.toObject()) == js::FunctionClassPtr); @@ -1562,7 +2282,7 @@ FUNCTION_VALUE_TO_JITINFO(const JS::Value& v) /* Statically asserted in jsfun.h. */ static const unsigned JS_FUNCTION_INTERPRETED_BIT = 0x1; -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void SET_JITINFO(JSFunction * func, const JSJitInfo *info) { js::shadow::Function *fun = reinterpret_cast(func); @@ -1575,7 +2295,7 @@ SET_JITINFO(JSFunction * func, const JSJitInfo *info) * eliminate Gecko's dependencies on it! */ -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid JSID_FROM_BITS(size_t bits) { jsid id; @@ -1610,7 +2330,7 @@ bool IdMatchesAtom(jsid id, JSAtom *atom); * Thus, it is only the rare third case which needs this function, which * handles any JSAtom* that is known not to be representable with an int jsid. */ -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid NON_INTEGER_ATOM_TO_JSID(JSAtom *atom) { JS_ASSERT(((size_t)atom & 0x7) == 0); @@ -1620,19 +2340,19 @@ NON_INTEGER_ATOM_TO_JSID(JSAtom *atom) } /* All strings stored in jsids are atomized, but are not necessarily property names. */ -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ATOM(jsid id) { return JSID_IS_STRING(id); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ATOM(jsid id, JSAtom *atom) { return id == JSID_FROM_BITS((size_t)atom); } -static JS_ALWAYS_INLINE JSAtom * +static MOZ_ALWAYS_INLINE JSAtom * JSID_TO_ATOM(jsid id) { return (JSAtom *)JSID_TO_STRING(id); @@ -1642,31 +2362,19 @@ JS_STATIC_ASSERT(sizeof(jsid) == sizeof(void*)); namespace js { -static JS_ALWAYS_INLINE JS::Value +static MOZ_ALWAYS_INLINE JS::Value IdToValue(jsid id) { if (JSID_IS_STRING(id)) return JS::StringValue(JSID_TO_STRING(id)); - if (JS_LIKELY(JSID_IS_INT(id))) + if (JSID_IS_INT(id)) return JS::Int32Value(JSID_TO_INT(id)); - if (JS_LIKELY(JSID_IS_OBJECT(id))) - return JS::ObjectValue(*JSID_TO_OBJECT(id)); + if (JSID_IS_SYMBOL(id)) + return JS::SymbolValue(JSID_TO_SYMBOL(id)); JS_ASSERT(JSID_IS_VOID(id)); return JS::UndefinedValue(); } -static JS_ALWAYS_INLINE jsval -IdToJsval(jsid id) -{ - return IdToValue(id); -} - -extern JS_FRIEND_API(bool) -IsReadOnlyDateMethod(JS::IsAcceptableThis test, JS::NativeImpl method); - -extern JS_FRIEND_API(bool) -IsTypedArrayThisCheck(JS::IsAcceptableThis test); - /* * If the embedder has registered a default JSContext callback, returns the * result of the callback. Otherwise, asserts that |rt| has exactly one @@ -1681,6 +2389,21 @@ typedef JSContext* JS_FRIEND_API(void) SetDefaultJSContextCallback(JSRuntime *rt, DefaultJSContextCallback cb); +/* + * To help embedders enforce their invariants, we allow them to specify in + * advance which JSContext should be passed to JSAPI calls. If this is set + * to a non-null value, the assertSameCompartment machinery does double- + * duty (in debug builds) to verify that it matches the cx being used. + */ +#ifdef DEBUG +JS_FRIEND_API(void) +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx); +#else +inline void +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx) {}; +#endif + + enum CTypesActivityType { CTYPES_CALL_BEGIN, CTYPES_CALL_END, @@ -1720,13 +2443,6 @@ class JS_FRIEND_API(AutoCTypesActivityCallback) { } }; -#ifdef DEBUG -extern JS_FRIEND_API(void) -assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id); -#else -inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id) {}; -#endif - typedef bool (* ObjectMetadataCallback)(JSContext *cx, JSObject **pmetadata); @@ -1747,6 +2463,13 @@ SetObjectMetadata(JSContext *cx, JS::HandleObject obj, JS::HandleObject metadata JS_FRIEND_API(JSObject *) GetObjectMetadata(JSObject *obj); +JS_FRIEND_API(void) +UnsafeDefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value); + +JS_FRIEND_API(bool) +SliceSlowly(JSContext* cx, JS::HandleObject obj, JS::HandleObject receiver, + uint32_t begin, uint32_t end, JS::HandleObject result); + /* ES5 8.12.8. */ extern JS_FRIEND_API(bool) DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandleValue vp); @@ -1766,7 +2489,43 @@ DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandle */ extern JS_FRIEND_API(bool) CheckDefineProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +/* + * Helper function for HTMLDocument and HTMLFormElement. + * + * These are the only two interfaces that have [OverrideBuiltins], a named + * getter, and no named setter. They're implemented as proxies with a custom + * getOwnPropertyDescriptor() method. Unfortunately, overriding + * getOwnPropertyDescriptor() automatically affects the behavior of set(), + * which normally is just common sense but is *not* desired for these two + * interfaces. + * + * The fix is for these two interfaces to override set() to ignore the + * getOwnPropertyDescriptor() override. + * + * SetPropertyIgnoringNamedGetter is exposed to make it easier to override + * set() in this way. It carries out all the steps of BaseProxyHandler::set() + * except the initial getOwnPropertyDescriptor()/getPropertyDescriptor() calls. + * The caller must supply those results as the 'desc' and 'descIsOwn' + * parameters. + * + * Implemented in jsproxy.cpp. + */ +JS_FRIEND_API(bool) +SetPropertyIgnoringNamedGetter(JSContext *cx, const BaseProxyHandler *handler, + JS::HandleObject proxy, JS::HandleObject receiver, + JS::HandleId id, JS::MutableHandle desc, + bool descIsOwn, bool strict, JS::MutableHandleValue vp); + +JS_FRIEND_API(void) +ReportErrorWithId(JSContext *cx, const char *msg, JS::HandleId id); + +// This function is for one specific use case, please don't use this for anything else! +extern JS_FRIEND_API(bool) +ExecuteInGlobalAndReturnScope(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleObject scope); } /* namespace js */ @@ -1775,27 +2534,27 @@ js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg, JS::Handle descriptor, bool *bp); extern JS_FRIEND_API(bool) -js_ReportIsNotFunction(JSContext *cx, const JS::Value& v); +js_ReportIsNotFunction(JSContext *cx, JS::HandleValue v); #ifdef JSGC_GENERATIONAL extern JS_FRIEND_API(void) JS_StoreObjectPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSObject *key, void *data), JSObject *key, void *data); extern JS_FRIEND_API(void) JS_StoreStringPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSString *key, void *data), JSString *key, void *data); #else inline void JS_StoreObjectPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSObject *key, void *data), JSObject *key, void *data) {} inline void JS_StoreStringPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSString *key, void *data), JSString *key, void *data) {} #endif /* JSGC_GENERATIONAL */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/jsperf.h b/frameworks/js-bindings/external/spidermonkey/include/android/jsperf.h index e3cbc23143..60c572f559 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/jsperf.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/jsperf.h @@ -88,7 +88,7 @@ class JS_FRIEND_API(PerfMeasurement) * then the eventsMeasured bitmask will only include the subset of * |toMeasure| corresponding to the events that can be measured. */ - PerfMeasurement(EventMask toMeasure); + explicit PerfMeasurement(EventMask toMeasure); /* Done with this set of measurements, tear down OS-level state. */ ~PerfMeasurement(); @@ -118,7 +118,7 @@ class JS_FRIEND_API(PerfMeasurement) * global object). The JS-visible API is identical to the C++ API. */ extern JS_FRIEND_API(JSObject*) - RegisterPerfMeasurement(JSContext *cx, JSObject *global); + RegisterPerfMeasurement(JSContext *cx, JS::HandleObject global); /* * Given a Value which contains an instance of the aforementioned diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/jsprf.h b/frameworks/js-bindings/external/spidermonkey/include/android/jsprf.h index b235f0b4fb..bfedf98ca8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/jsprf.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/jsprf.h @@ -57,23 +57,11 @@ extern JS_PUBLIC_API(void) JS_smprintf_free(char *mem); */ extern JS_PUBLIC_API(char*) JS_sprintf_append(char *last, const char *fmt, ...); -/* -** sprintf into a function. The function "f" is called with a string to -** place into the output. "arg" is an opaque pointer used by the stuff -** function to hold any state needed to do the storage of the output -** data. The return value is a count of the number of characters fed to -** the stuff function, or (uint32_t)-1 if an error occurs. -*/ -typedef int (*JSStuffFunc)(void *arg, const char *s, uint32_t slen); - -extern JS_PUBLIC_API(uint32_t) JS_sxprintf(JSStuffFunc f, void *arg, const char *fmt, ...); - /* ** va_list forms of the above. */ extern JS_PUBLIC_API(uint32_t) JS_vsnprintf(char *out, uint32_t outlen, const char *fmt, va_list ap); extern JS_PUBLIC_API(char*) JS_vsmprintf(const char *fmt, va_list ap); extern JS_PUBLIC_API(char*) JS_vsprintf_append(char *last, const char *fmt, va_list ap); -extern JS_PUBLIC_API(uint32_t) JS_vsxprintf(JSStuffFunc f, void *arg, const char *fmt, va_list ap); #endif /* jsprf_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/jsprototypes.h b/frameworks/js-bindings/external/spidermonkey/include/android/jsprototypes.h index bc4a767033..1cb56bf8da 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/jsprototypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/jsprototypes.h @@ -34,7 +34,7 @@ #define CLASP(name) (&name##Class) #define OCLASP(name) (&name##Object::class_) -#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[ScalarTypeRepresentation::type]) +#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[Scalar::type]) #ifdef ENABLE_PARALLEL_JS #define IF_PJS(real,imaginary) real @@ -54,47 +54,61 @@ #define IF_BDATA(real,imaginary) imaginary #endif +#ifdef ENABLE_SHARED_ARRAY_BUFFER +#define IF_SAB(real,imaginary) real +#else +#define IF_SAB(real,imaginary) imaginary +#endif + +#ifdef JS_HAS_SYMBOLS +#define IF_SYMBOLS(real,imaginary) real +#else +#define IF_SYMBOLS(real,imaginary) imaginary +#endif + #define JS_FOR_PROTOTYPES(real,imaginary) \ imaginary(Null, 0, js_InitNullClass, dummy) \ - real(Object, 1, js_InitObjectClass, &JSObject::class_) \ - real(Function, 2, js_InitFunctionClass, &JSFunction::class_) \ - real(Array, 3, js_InitArrayClass, OCLASP(Array)) \ + real(Object, 1, js_InitViaClassSpec, &JSObject::class_) \ + real(Function, 2, js_InitViaClassSpec, &JSFunction::class_) \ + real(Array, 3, js_InitViaClassSpec, OCLASP(Array)) \ real(Boolean, 4, js_InitBooleanClass, OCLASP(Boolean)) \ real(JSON, 5, js_InitJSONClass, CLASP(JSON)) \ - real(Date, 6, js_InitDateClass, OCLASP(Date)) \ + real(Date, 6, js_InitViaClassSpec, OCLASP(Date)) \ real(Math, 7, js_InitMathClass, CLASP(Math)) \ real(Number, 8, js_InitNumberClass, OCLASP(Number)) \ real(String, 9, js_InitStringClass, OCLASP(String)) \ real(RegExp, 10, js_InitRegExpClass, OCLASP(RegExp)) \ - real(Error, 11, js_InitExceptionClasses, OCLASP(Error)) \ - real(InternalError, 12, js_InitExceptionClasses, OCLASP(Error)) \ - real(EvalError, 13, js_InitExceptionClasses, OCLASP(Error)) \ - real(RangeError, 14, js_InitExceptionClasses, OCLASP(Error)) \ - real(ReferenceError, 15, js_InitExceptionClasses, OCLASP(Error)) \ - real(SyntaxError, 16, js_InitExceptionClasses, OCLASP(Error)) \ - real(TypeError, 17, js_InitExceptionClasses, OCLASP(Error)) \ - real(URIError, 18, js_InitExceptionClasses, OCLASP(Error)) \ + real(Error, 11, js_InitViaClassSpec, OCLASP(Error)) \ + real(InternalError, 12, js_InitViaClassSpec, OCLASP(Error)) \ + real(EvalError, 13, js_InitViaClassSpec, OCLASP(Error)) \ + real(RangeError, 14, js_InitViaClassSpec, OCLASP(Error)) \ + real(ReferenceError, 15, js_InitViaClassSpec, OCLASP(Error)) \ + real(SyntaxError, 16, js_InitViaClassSpec, OCLASP(Error)) \ + real(TypeError, 17, js_InitViaClassSpec, OCLASP(Error)) \ + real(URIError, 18, js_InitViaClassSpec, OCLASP(Error)) \ real(Iterator, 19, js_InitIteratorClasses, OCLASP(PropertyIterator)) \ real(StopIteration, 20, js_InitIteratorClasses, OCLASP(StopIteration)) \ - real(ArrayBuffer, 21, js_InitTypedArrayClasses, &js::ArrayBufferObject::protoClass) \ - real(Int8Array, 22, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT8)) \ - real(Uint8Array, 23, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT8)) \ - real(Int16Array, 24, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT16)) \ - real(Uint16Array, 25, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT16)) \ - real(Int32Array, 26, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT32)) \ - real(Uint32Array, 27, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT32)) \ - real(Float32Array, 28, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_FLOAT32)) \ - real(Float64Array, 29, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_FLOAT64)) \ - real(Uint8ClampedArray, 30, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT8_CLAMPED)) \ + real(ArrayBuffer, 21, js_InitArrayBufferClass, &js::ArrayBufferObject::protoClass) \ + real(Int8Array, 22, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int8)) \ + real(Uint8Array, 23, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8)) \ + real(Int16Array, 24, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int16)) \ + real(Uint16Array, 25, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint16)) \ + real(Int32Array, 26, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int32)) \ + real(Uint32Array, 27, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint32)) \ + real(Float32Array, 28, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float32)) \ + real(Float64Array, 29, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float64)) \ + real(Uint8ClampedArray, 30, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8Clamped)) \ real(Proxy, 31, js_InitProxyClass, &ProxyObject::uncallableClass_) \ real(WeakMap, 32, js_InitWeakMapClass, OCLASP(WeakMap)) \ real(Map, 33, js_InitMapClass, OCLASP(Map)) \ real(Set, 34, js_InitSetClass, OCLASP(Set)) \ - real(DataView, 35, js_InitTypedArrayClasses, OCLASP(DataView)) \ -IF_PJS(real,imaginary) (ParallelArray, 36, js_InitParallelArrayClass, OCLASP(ParallelArray)) \ -IF_INTL(real,imaginary) (Intl, 37, js_InitIntlClass, CLASP(Intl)) \ -IF_BDATA(real,imaginary)(TypedObject, 38, js_InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \ - imaginary(GeneratorFunction, 39, js_InitIteratorClasses, dummy) \ + real(DataView, 35, js_InitDataViewClass, OCLASP(DataView)) \ +IF_SYMBOLS(real,imaginary)(Symbol, 36, js_InitSymbolClass, &js::SymbolObject::class_) \ +IF_SAB(real,imaginary)(SharedArrayBuffer, 37, js_InitSharedArrayBufferClass, &js::SharedArrayBufferObject::protoClass) \ +IF_INTL(real,imaginary) (Intl, 38, js_InitIntlClass, CLASP(Intl)) \ +IF_BDATA(real,imaginary)(TypedObject, 39, js_InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \ + imaginary(GeneratorFunction, 40, js_InitIteratorClasses, dummy) \ +IF_BDATA(real,imaginary)(SIMD, 41, js_InitSIMDClass, OCLASP(SIMD)) \ #define JS_FOR_EACH_PROTOTYPE(macro) JS_FOR_PROTOTYPES(macro,macro) diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/jsproxy.h b/frameworks/js-bindings/external/spidermonkey/include/android/jsproxy.h index 3d2ea81cb3..b4588c4c2a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/jsproxy.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/jsproxy.h @@ -47,6 +47,22 @@ class JS_FRIEND_API(Wrapper); * BaseProxyHandler provides implementations of the derived traps in terms of * the (pure virtual) fundamental traps. * + * In addition to the normal traps, there are two models for proxy prototype + * chains. First, proxies may opt to use the standard prototype mechanism used + * throughout the engine. To do so, simply pass a prototype to NewProxyObject() + * at creation time. All prototype accesses will then "just work" to treat the + * proxy as a "normal" object. Alternatively, if instead the proxy wishes to + * implement more complicated prototype semantics (if, for example, it wants to + * delegate the prototype lookup to a wrapped object), it may pass Proxy::LazyProto + * as the prototype at create time and opt in to the trapped prototype system, + * which guarantees that their trap will be called on any and every prototype + * chain access of the object. + * + * This system is implemented with two traps: {get,set}PrototypeOf. The default + * implementation of setPrototypeOf throws a TypeError. Since it is not possible + * to create an object without a sense of prototype chain, handler implementors + * must provide a getPrototypeOf trap if opting in to the dynamic prototype system. + * * To minimize code duplication, a set of abstract proxy handler classes is * provided, from which other handlers may inherit. These abstract classes * are organized in the following hierarchy: @@ -72,37 +88,55 @@ class JS_FRIEND_API(Wrapper); class JS_FRIEND_API(BaseProxyHandler) { const void *mFamily; + + /* + * Proxy handlers can use mHasPrototype to request the following special + * treatment from the JS engine: + * + * - When mHasPrototype is true, the engine never calls these methods: + * getPropertyDescriptor, has, set, enumerate, iterate. Instead, for + * these operations, it calls the "own" traps like + * getOwnPropertyDescriptor, hasOwn, defineProperty, keys, etc., and + * consults the prototype chain if needed. + * + * - When mHasPrototype is true, the engine calls handler->get() only if + * handler->hasOwn() says an own property exists on the proxy. If not, + * it consults the prototype chain. + * + * This is useful because it frees the ProxyHandler from having to implement + * any behavior having to do with the prototype chain. + */ bool mHasPrototype; - bool mHasPolicy; - protected: - // Subclasses may set this in their constructor. - void setHasPrototype(bool aHasPrototype) { mHasPrototype = aHasPrototype; } - void setHasPolicy(bool aHasPolicy) { mHasPolicy = aHasPolicy; } + + /* + * All proxies indicate whether they have any sort of interesting security + * policy that might prevent the caller from doing something it wants to + * the object. In the case of wrappers, this distinction is used to + * determine whether the caller may strip off the wrapper if it so desires. + */ + bool mHasSecurityPolicy; public: - explicit BaseProxyHandler(const void *family); + explicit BaseProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); virtual ~BaseProxyHandler(); - bool hasPrototype() { + bool hasPrototype() const { return mHasPrototype; } - bool hasPolicy() { - return mHasPolicy; + bool hasSecurityPolicy() const { + return mHasSecurityPolicy; } - inline const void *family() { + inline const void *family() const { return mFamily; } static size_t offsetOfFamily() { return offsetof(BaseProxyHandler, mFamily); } - virtual bool isOuterWindow() { - return false; - } - - virtual bool finalizeInBackground(Value priv) { + virtual bool finalizeInBackground(Value priv) const { /* * Called on creation of a proxy to determine whether its finalize * method can be finalized on the background thread. @@ -119,66 +153,75 @@ class JS_FRIEND_API(BaseProxyHandler) * The |act| parameter to enter() specifies the action being performed. * If |bp| is false, the trap suggests that the caller throw (though it * may still decide to squelch the error). + * + * We make these OR-able so that assertEnteredPolicy can pass a union of them. + * For example, get{,Own}PropertyDescriptor is invoked by both calls to ::get() + * and ::set() (since we need to look up the accessor), so its + * assertEnteredPolicy would pass GET | SET. */ - enum Action { - GET, - SET, - CALL + typedef uint32_t Action; + enum { + NONE = 0x00, + GET = 0x01, + SET = 0x02, + CALL = 0x04, + ENUMERATE = 0x08 }; + virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Action act, - bool *bp); + bool *bp) const; /* ES5 Harmony fundamental proxy traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) = 0; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const = 0; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, - unsigned flags) = 0; + MutableHandle desc) const = 0; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, - HandleId id, MutableHandle desc, - unsigned flags) = 0; + HandleId id, MutableHandle desc) const = 0; virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc) = 0; + MutableHandle desc) const = 0; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, - AutoIdVector &props) = 0; - virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) = 0; - virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) = 0; + AutoIdVector &props) const = 0; + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const = 0; + virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) const = 0; /* ES5 Harmony derived proxy traps. */ - virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); - virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); + virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; + virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, MutableHandleValue vp); + HandleId id, MutableHandleValue vp) const; virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp); - virtual bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props); + HandleId id, bool strict, MutableHandleValue vp) const; + virtual bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props) const; virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, - MutableHandleValue vp); + MutableHandleValue vp) const; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) = 0; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args); - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args); - virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args); - virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp); - virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx); - virtual const char *className(JSContext *cx, HandleObject proxy); - virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent); - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g); - virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); - virtual void finalize(JSFreeOp *fop, JSObject *proxy); - virtual bool getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver, - uint32_t index, MutableHandleValue vp, bool *present); - virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const = 0; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args) const; + virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp) const; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx) const; + virtual const char *className(JSContext *cx, HandleObject proxy) const; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const; + virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp) const; + virtual void finalize(JSFreeOp *fop, JSObject *proxy) const; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop) const; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp) const; // These two hooks must be overridden, or not overridden, in tandem -- no // overriding just one! virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable); - virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id); + JS::HandleObject callable) const; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const; + + virtual bool slice(JSContext *cx, HandleObject proxy, uint32_t begin, uint32_t end, + HandleObject result) const; /* See comment for weakmapKeyDelegateOp in js/Class.h. */ - virtual JSObject *weakmapKeyDelegate(JSObject *proxy); - virtual bool isScripted() { return false; } + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const; + virtual bool isScripted() const { return false; } }; /* @@ -194,54 +237,58 @@ class JS_FRIEND_API(BaseProxyHandler) class JS_PUBLIC_API(DirectProxyHandler) : public BaseProxyHandler { public: - explicit DirectProxyHandler(const void *family); + explicit DirectProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); /* ES5 Harmony fundamental proxy traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags) MOZ_OVERRIDE; - virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, - HandleId id, MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool enumerate(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; /* ES5 Harmony derived proxy traps. */ virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool keys(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, - unsigned indent) MOZ_OVERRIDE; + unsigned indent) const MOZ_OVERRIDE; virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, - RegExpGuard *g) MOZ_OVERRIDE; - virtual JSObject *weakmapKeyDelegate(JSObject *proxy); + RegExpGuard *g) const MOZ_OVERRIDE; + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const MOZ_OVERRIDE; }; /* @@ -257,16 +304,15 @@ class Proxy /* ES5 Harmony fundamental proxy traps. */ static bool preventExtensions(JSContext *cx, HandleObject proxy); static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags); - static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, unsigned flags, HandleId id, + MutableHandle desc); + static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, MutableHandleValue vp); static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags); - static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, unsigned flags, HandleId id, + MutableHandle desc); + static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, MutableHandleValue vp); static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, MutableHandle desc); - static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, HandleValue v); static bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props); static bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); static bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props); @@ -276,8 +322,6 @@ class Proxy static bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); static bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, MutableHandleValue vp); - static bool getElementIfPresent(JSContext *cx, HandleObject proxy, HandleObject receiver, - uint32_t index, MutableHandleValue vp, bool *present); static bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, bool strict, MutableHandleValue vp); static bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props); @@ -295,44 +339,26 @@ class Proxy static bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g); static bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); static bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + static bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp); - static bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable); - static bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id); + static bool watch(JSContext *cx, HandleObject proxy, HandleId id, HandleObject callable); + static bool unwatch(JSContext *cx, HandleObject proxy, HandleId id); + + static bool slice(JSContext *cx, HandleObject obj, uint32_t begin, uint32_t end, + HandleObject result); /* IC entry path for handling __noSuchMethod__ on access. */ static bool callProp(JSContext *cx, HandleObject proxy, HandleObject reveiver, HandleId id, MutableHandleValue vp); - - static JSObject * const LazyProto; }; // Use these in places where you don't want to #include vm/ProxyObject.h. extern JS_FRIEND_DATA(const js::Class* const) CallableProxyClassPtr; extern JS_FRIEND_DATA(const js::Class* const) UncallableProxyClassPtr; -extern JS_FRIEND_DATA(const js::Class* const) OuterWindowProxyClassPtr; - -inline bool IsProxyClass(const Class *clasp) -{ - return clasp == CallableProxyClassPtr || - clasp == UncallableProxyClassPtr || - clasp == OuterWindowProxyClassPtr; -} inline bool IsProxy(JSObject *obj) { - return IsProxyClass(GetObjectClass(obj)); -} - -BaseProxyHandler * -GetProxyHandler(JSObject *obj); - -inline bool IsScriptedProxy(JSObject *obj) -{ - if (!IsProxy(obj)) - return false; - - return GetProxyHandler(obj)->isScripted(); + return GetObjectClass(obj)->isProxy(); } /* @@ -343,15 +369,16 @@ inline bool IsScriptedProxy(JSObject *obj) * needs to store one slot's worth of data doesn't need to branch on what sort * of object it has. */ -const uint32_t PROXY_PRIVATE_SLOT = 0; -const uint32_t PROXY_HANDLER_SLOT = 1; -const uint32_t PROXY_EXTRA_SLOT = 2; +const uint32_t PROXY_PRIVATE_SLOT = 0; +const uint32_t PROXY_HANDLER_SLOT = 1; +const uint32_t PROXY_EXTRA_SLOT = 2; +const uint32_t PROXY_MINIMUM_SLOTS = 4; -inline BaseProxyHandler * +inline const BaseProxyHandler * GetProxyHandler(JSObject *obj) { JS_ASSERT(IsProxy(obj)); - return (BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate(); + return (const BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate(); } inline const Value & @@ -390,17 +417,24 @@ SetProxyExtra(JSObject *obj, size_t n, const Value &extra) SetReservedSlot(obj, PROXY_EXTRA_SLOT + n, extra); } +inline bool +IsScriptedProxy(JSObject *obj) +{ + return IsProxy(obj) && GetProxyHandler(obj)->isScripted(); +} + class MOZ_STACK_CLASS ProxyOptions { - public: - ProxyOptions() : callable_(false), - singleton_(false) + protected: + /* protected constructor for subclass */ + ProxyOptions(bool singletonArg, const Class *claspArg) + : singleton_(singletonArg), + clasp_(claspArg) {} - bool callable() const { return callable_; } - ProxyOptions &setCallable(bool flag) { - callable_ = flag; - return *this; - } + public: + ProxyOptions() : singleton_(false), + clasp_(UncallableProxyClassPtr) + {} bool singleton() const { return singleton_; } ProxyOptions &setSingleton(bool flag) { @@ -408,13 +442,26 @@ class MOZ_STACK_CLASS ProxyOptions { return *this; } + const Class *clasp() const { + return clasp_; + } + ProxyOptions &setClass(const Class *claspArg) { + clasp_ = claspArg; + return *this; + } + ProxyOptions &selectDefaultClass(bool callable) { + const Class *classp = callable? CallableProxyClassPtr : + UncallableProxyClassPtr; + return setClass(classp); + } + private: - bool callable_; bool singleton_; + const Class *clasp_; }; JS_FRIEND_API(JSObject *) -NewProxyObject(JSContext *cx, BaseProxyHandler *handler, HandleValue priv, +NewProxyObject(JSContext *cx, const BaseProxyHandler *handler, HandleValue priv, JSObject *proto, JSObject *parent, const ProxyOptions &options = ProxyOptions()); JSObject * @@ -424,15 +471,15 @@ class JS_FRIEND_API(AutoEnterPolicy) { public: typedef BaseProxyHandler::Action Action; - AutoEnterPolicy(JSContext *cx, BaseProxyHandler *handler, + AutoEnterPolicy(JSContext *cx, const BaseProxyHandler *handler, HandleObject wrapper, HandleId id, Action act, bool mayThrow) -#ifdef DEBUG +#ifdef JS_DEBUG : context(nullptr) #endif { - allow = handler->hasPolicy() ? handler->enter(cx, wrapper, id, act, &rv) - : true; - recordEnter(cx, wrapper, id); + allow = handler->hasSecurityPolicy() ? handler->enter(cx, wrapper, id, act, &rv) + : true; + recordEnter(cx, wrapper, id, act); // We want to throw an exception if all of the following are true: // * The policy disallowed access. // * The policy set rv to false, indicating that we should throw. @@ -449,48 +496,65 @@ class JS_FRIEND_API(AutoEnterPolicy) protected: // no-op constructor for subclass AutoEnterPolicy() -#ifdef DEBUG +#ifdef JS_DEBUG : context(nullptr) + , enteredAction(BaseProxyHandler::NONE) #endif {}; void reportErrorIfExceptionIsNotPending(JSContext *cx, jsid id); bool allow; bool rv; -#ifdef DEBUG +#ifdef JS_DEBUG JSContext *context; mozilla::Maybe enteredProxy; mozilla::Maybe enteredId; + Action enteredAction; + // NB: We explicitly don't track the entered action here, because sometimes // SET traps do an implicit GET during their implementation, leading to // spurious assertions. AutoEnterPolicy *prev; - void recordEnter(JSContext *cx, HandleObject proxy, HandleId id); + void recordEnter(JSContext *cx, HandleObject proxy, HandleId id, Action act); void recordLeave(); - friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id); + friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id, Action act); #else - inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id) {} + inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id, Action act) {} inline void recordLeave() {} #endif }; -#ifdef DEBUG +#ifdef JS_DEBUG class JS_FRIEND_API(AutoWaivePolicy) : public AutoEnterPolicy { public: - AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id) + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) { allow = true; - recordEnter(cx, proxy, id); + recordEnter(cx, proxy, id, act); } }; #else class JS_FRIEND_API(AutoWaivePolicy) { - public: AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id) {}; + public: + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) + {} }; #endif +#ifdef JS_DEBUG +extern JS_FRIEND_API(void) +assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act); +#else +inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act) +{}; +#endif + } /* namespace js */ extern JS_FRIEND_API(JSObject *) diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/jspubtd.h b/frameworks/js-bindings/external/spidermonkey/include/android/jspubtd.h index 9683c23ea4..ffd75e2e5c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/jspubtd.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/jspubtd.h @@ -11,6 +11,7 @@ * JS public API typedefs. */ +#include "mozilla/Assertions.h" #include "mozilla/LinkedList.h" #include "mozilla/NullPtr.h" #include "mozilla/PodOperations.h" @@ -20,7 +21,7 @@ #include "js/TypeDecls.h" -#if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING) || defined(DEBUG) +#if defined(JSGC_USE_EXACT_ROOTING) || defined(JS_DEBUG) # define JSGC_TRACK_EXACT_ROOTS #endif @@ -32,23 +33,25 @@ class CallArgs; template class Rooted; -class JS_PUBLIC_API(AutoGCRooter); - -class JS_PUBLIC_API(CompileOptions); -class JS_PUBLIC_API(ReadOnlyCompileOptions); -class JS_PUBLIC_API(OwningCompileOptions); +class JS_FRIEND_API(CompileOptions); +class JS_FRIEND_API(ReadOnlyCompileOptions); +class JS_FRIEND_API(OwningCompileOptions); class JS_PUBLIC_API(CompartmentOptions); struct Zone; } /* namespace JS */ +namespace js { +struct ContextFriendFields; +} // namespace js + /* * Run-time version enumeration. For compile-time version checking, please use * the JS_HAS_* macros in jsversion.h, or use MOZJS_MAJOR_VERSION, * MOZJS_MINOR_VERSION, MOZJS_PATCH_VERSION, and MOZJS_ALPHA definitions. */ -typedef enum JSVersion { +enum JSVersion { JSVERSION_ECMA_3 = 148, JSVERSION_1_6 = 160, JSVERSION_1_7 = 170, @@ -57,10 +60,10 @@ typedef enum JSVersion { JSVERSION_DEFAULT = 0, JSVERSION_UNKNOWN = -1, JSVERSION_LATEST = JSVERSION_ECMA_5 -} JSVersion; +}; /* Result of typeof operator enumeration. */ -typedef enum JSType { +enum JSType { JSTYPE_VOID, /* undefined */ JSTYPE_OBJECT, /* object */ JSTYPE_FUNCTION, /* function */ @@ -68,44 +71,23 @@ typedef enum JSType { JSTYPE_NUMBER, /* number */ JSTYPE_BOOLEAN, /* boolean */ JSTYPE_NULL, /* null */ + JSTYPE_SYMBOL, /* symbol */ JSTYPE_LIMIT -} JSType; +}; /* Dense index into cached prototypes and class atoms for standard objects. */ -typedef enum JSProtoKey { +enum JSProtoKey { #define PROTOKEY_AND_INITIALIZER(name,code,init,clasp) JSProto_##name = code, JS_FOR_EACH_PROTOTYPE(PROTOKEY_AND_INITIALIZER) #undef PROTOKEY_AND_INITIALIZER JSProto_LIMIT -} JSProtoKey; - -/* js_CheckAccess mode enumeration. */ -typedef enum JSAccessMode { - JSACC_PROTO = 0, /* XXXbe redundant w.r.t. id */ - - /* - * enum value #1 formerly called JSACC_PARENT, - * gap preserved for ABI compatibility. - */ - - /* - * enum value #2 formerly called JSACC_IMPORT, - * gap preserved for ABI compatibility. - */ - - JSACC_WATCH = 3, /* a watchpoint on object foo for id 'bar' */ - JSACC_READ = 4, /* a "get" of foo.bar */ - JSACC_WRITE = 8, /* a "set" of foo.bar = baz */ - JSACC_LIMIT -} JSAccessMode; - -#define JSACC_TYPEMASK (JSACC_WRITE - 1) +}; /* * This enum type is used to control the behavior of a JSObject property * iterator function that has type JSNewEnumerate. */ -typedef enum JSIterateOp { +enum JSIterateOp { /* Create new iterator state over enumerable properties. */ JSENUMERATE_INIT, @@ -117,12 +99,13 @@ typedef enum JSIterateOp { /* Destroy iterator state. */ JSENUMERATE_DESTROY -} JSIterateOp; +}; -/* See JSVAL_TRACE_KIND and JSTraceCallback in jsapi.h. */ -typedef enum { +/* See Value::gcKind() and JSTraceCallback in Tracer.h. */ +enum JSGCTraceKind { JSTRACE_OBJECT, JSTRACE_STRING, + JSTRACE_SYMBOL, JSTRACE_SCRIPT, /* @@ -130,37 +113,36 @@ typedef enum { * it implements JSTraceCallback. */ JSTRACE_LAZY_SCRIPT, - JSTRACE_IONCODE, + JSTRACE_JITCODE, JSTRACE_SHAPE, JSTRACE_BASE_SHAPE, JSTRACE_TYPE_OBJECT, JSTRACE_LAST = JSTRACE_TYPE_OBJECT -} JSGCTraceKind; - -/* Struct typedefs and class forward declarations. */ -typedef struct JSClass JSClass; -typedef struct JSCompartment JSCompartment; -typedef struct JSConstDoubleSpec JSConstDoubleSpec; -typedef struct JSCrossCompartmentCall JSCrossCompartmentCall; -typedef struct JSErrorReport JSErrorReport; -typedef struct JSExceptionState JSExceptionState; -typedef struct JSFunctionSpec JSFunctionSpec; -typedef struct JSIdArray JSIdArray; -typedef struct JSLocaleCallbacks JSLocaleCallbacks; -typedef struct JSObjectMap JSObjectMap; -typedef struct JSPrincipals JSPrincipals; -typedef struct JSPropertyDescriptor JSPropertyDescriptor; -typedef struct JSPropertyName JSPropertyName; -typedef struct JSPropertySpec JSPropertySpec; -typedef struct JSRuntime JSRuntime; -typedef struct JSSecurityCallbacks JSSecurityCallbacks; -typedef struct JSStructuredCloneCallbacks JSStructuredCloneCallbacks; -typedef struct JSStructuredCloneReader JSStructuredCloneReader; -typedef struct JSStructuredCloneWriter JSStructuredCloneWriter; -typedef struct JSTracer JSTracer; - -class JSFlatString; -class JSStableString; // long story +}; + +/* Struct forward declarations. */ +struct JSClass; +struct JSCompartment; +struct JSConstDoubleSpec; +struct JSCrossCompartmentCall; +struct JSErrorReport; +struct JSExceptionState; +struct JSFunctionSpec; +struct JSIdArray; +struct JSLocaleCallbacks; +struct JSObjectMap; +struct JSPrincipals; +struct JSPropertyDescriptor; +struct JSPropertyName; +struct JSPropertySpec; +struct JSRuntime; +struct JSSecurityCallbacks; +struct JSStructuredCloneCallbacks; +struct JSStructuredCloneReader; +struct JSStructuredCloneWriter; +class JS_PUBLIC_API(JSTracer); + +class JSFlatString; #ifdef JS_THREADSAFE typedef struct PRCallOnceType JSCallOnceType; @@ -182,6 +164,7 @@ namespace js { namespace gc { class StoreBuffer; void MarkPersistentRootedChains(JSTracer *); +void FinishPersistentRootedChains(JSRuntime *); } } @@ -197,24 +180,18 @@ struct Runtime bool needsBarrier_; #ifdef JSGC_GENERATIONAL - /* Allow inlining of Nursery::isInside. */ - uintptr_t gcNurseryStart_; - uintptr_t gcNurseryEnd_; - private: js::gc::StoreBuffer *gcStoreBufferPtr_; #endif public: - Runtime( + explicit Runtime( #ifdef JSGC_GENERATIONAL js::gc::StoreBuffer *storeBuffer #endif ) : needsBarrier_(false) #ifdef JSGC_GENERATIONAL - , gcNurseryStart_(0) - , gcNurseryEnd_(0) , gcStoreBufferPtr_(storeBuffer) #endif {} @@ -235,7 +212,7 @@ struct Runtime private: template friend class JS::PersistentRooted; friend void js::gc::MarkPersistentRootedChains(JSTracer *); - friend void ::js_FinishGC(JSRuntime *rt); + friend void js::gc::FinishPersistentRootedChains(JSRuntime *rt); mozilla::LinkedList functionPersistentRooteds; mozilla::LinkedList idPersistentRooteds; @@ -274,6 +251,75 @@ inline mozilla::LinkedList &Runtime::getPersistentRootedList() { return valuePersistentRooteds; } } /* namespace shadow */ + +class JS_PUBLIC_API(AutoGCRooter) +{ + public: + AutoGCRooter(JSContext *cx, ptrdiff_t tag); + AutoGCRooter(js::ContextFriendFields *cx, ptrdiff_t tag); + + ~AutoGCRooter() { + MOZ_ASSERT(this == *stackTop); + *stackTop = down; + } + + /* Implemented in gc/RootMarking.cpp. */ + inline void trace(JSTracer *trc); + static void traceAll(JSTracer *trc); + static void traceAllWrappers(JSTracer *trc); + + /* T must be a context type */ + template + static void traceAllInContext(T* cx, JSTracer *trc) { + for (AutoGCRooter *gcr = cx->autoGCRooters; gcr; gcr = gcr->down) + gcr->trace(trc); + } + + protected: + AutoGCRooter * const down; + + /* + * Discriminates actual subclass of this being used. If non-negative, the + * subclass roots an array of values of the length stored in this field. + * If negative, meaning is indicated by the corresponding value in the enum + * below. Any other negative value indicates some deeper problem such as + * memory corruption. + */ + ptrdiff_t tag_; + + enum { + VALARRAY = -2, /* js::AutoValueArray */ + PARSER = -3, /* js::frontend::Parser */ + SHAPEVECTOR = -4, /* js::AutoShapeVector */ + IDARRAY = -6, /* js::AutoIdArray */ + DESCVECTOR = -7, /* js::AutoPropDescVector */ + VALVECTOR = -10, /* js::AutoValueVector */ + IDVECTOR = -13, /* js::AutoIdVector */ + OBJVECTOR = -14, /* js::AutoObjectVector */ + STRINGVECTOR =-15, /* js::AutoStringVector */ + SCRIPTVECTOR =-16, /* js::AutoScriptVector */ + NAMEVECTOR = -17, /* js::AutoNameVector */ + HASHABLEVALUE=-18, /* js::HashableValue */ + IONMASM = -19, /* js::jit::MacroAssembler */ + IONALLOC = -20, /* js::jit::AutoTempAllocatorRooter */ + WRAPVECTOR = -21, /* js::AutoWrapperVector */ + WRAPPER = -22, /* js::AutoWrapperRooter */ + OBJOBJHASHMAP=-23, /* js::AutoObjectObjectHashMap */ + OBJU32HASHMAP=-24, /* js::AutoObjectUnsigned32HashMap */ + OBJHASHSET = -25, /* js::AutoObjectHashSet */ + JSONPARSER = -26, /* js::JSONParser */ + CUSTOM = -27, /* js::CustomAutoRooter */ + FUNVECTOR = -28 /* js::AutoFunctionVector */ + }; + + private: + AutoGCRooter ** const stackTop; + + /* No copy or assignment semantics. */ + AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; + void operator=(AutoGCRooter &ida) MOZ_DELETE; +}; + } /* namespace JS */ namespace js { @@ -287,13 +333,11 @@ namespace js { enum ParallelResult { TP_SUCCESS, TP_RETRY_SEQUENTIALLY, TP_RETRY_AFTER_GC, TP_FATAL }; struct ThreadSafeContext; -struct ForkJoinSlice; +class ForkJoinContext; class ExclusiveContext; class Allocator; -class SkipRoot; - enum ThingRootKind { THING_ROOT_OBJECT, @@ -301,14 +345,16 @@ enum ThingRootKind THING_ROOT_BASE_SHAPE, THING_ROOT_TYPE_OBJECT, THING_ROOT_STRING, - THING_ROOT_ION_CODE, + THING_ROOT_SYMBOL, + THING_ROOT_JIT_CODE, THING_ROOT_SCRIPT, + THING_ROOT_LAZY_SCRIPT, THING_ROOT_ID, - THING_ROOT_PROPERTY_ID, THING_ROOT_VALUE, THING_ROOT_TYPE, THING_ROOT_BINDINGS, THING_ROOT_PROPERTY_DESCRIPTOR, + THING_ROOT_PROP_DESC, THING_ROOT_LIMIT }; @@ -343,6 +389,7 @@ template <> struct RootKind : SpecificRootKind struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; @@ -364,9 +411,6 @@ struct ContextFriendFields { #ifdef JSGC_TRACK_EXACT_ROOTS mozilla::PodArrayZero(thingGCRooters); -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - skipGCRooters = nullptr; #endif } @@ -379,31 +423,31 @@ struct ContextFriendFields } #ifdef JSGC_TRACK_EXACT_ROOTS + private: /* * Stack allocated GC roots for stack GC heap pointers, which may be * overwritten if moved during a GC. */ JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* - * Stack allocated list of stack locations which hold non-relocatable - * GC heap pointers (where the target is rooted somewhere else) or integer - * values which may be confused for GC heap pointers. These are used to - * suppress false positives which occur when a rooting analysis treats the - * location as holding a relocatable pointer, but have no other effect on - * GC behavior. - */ - SkipRoot *skipGCRooters; + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } + #endif + void checkNoGCRooters(); + /* Stack of thread-stack-allocated GC roots. */ JS::AutoGCRooter *autoGCRooters; friend JSRuntime *GetRuntime(const JSContext *cx); friend JSCompartment *GetContextCompartment(const JSContext *cx); friend JS::Zone *GetContextZone(const JSContext *cx); + template friend class JS::Rooted; }; /* @@ -447,7 +491,7 @@ struct PerThreadDataFriendFields struct PerThreadDummy { void *field1; uintptr_t field2; -#ifdef DEBUG +#ifdef JS_DEBUG uint64_t field3; #endif } mainThread; @@ -458,23 +502,19 @@ struct PerThreadDataFriendFields PerThreadDataFriendFields(); #ifdef JSGC_TRACK_EXACT_ROOTS + private: /* * Stack allocated GC roots for stack GC heap pointers, which may be * overwritten if moved during a GC. */ JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* - * Stack allocated list of stack locations which hold non-relocatable - * GC heap pointers (where the target is rooted somewhere else) or integer - * values which may be confused for GC heap pointers. These are used to - * suppress false positives which occur when a rooting analysis treats the - * location as holding a relocatable pointer, but have no other effect on - * GC behavior. - */ - SkipRoot *skipGCRooters; + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } #endif /* Limit pointer for checking native stack consumption. */ @@ -499,6 +539,8 @@ struct PerThreadDataFriendFields return reinterpret_cast( reinterpret_cast(rt) + RuntimeMainThreadOffset); } + + template friend class JS::Rooted; }; } /* namespace js */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/jstypes.h b/frameworks/js-bindings/external/spidermonkey/include/android/jstypes.h index d5b15ccb1d..e9927bca0d 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/jstypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/jstypes.h @@ -77,8 +77,13 @@ # define JS_PUBLIC_DATA(t) MOZ_IMPORT_DATA t #endif -#define JS_FRIEND_API(t) JS_PUBLIC_API(t) -#define JS_FRIEND_DATA(t) JS_PUBLIC_DATA(t) +#if defined(STATIC_JS_API) || defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API) +# define JS_FRIEND_API(t) MOZ_EXPORT t +# define JS_FRIEND_DATA(t) MOZ_EXPORT t +#else +# define JS_FRIEND_API(t) MOZ_IMPORT_API t +# define JS_FRIEND_DATA(t) MOZ_IMPORT_DATA t +#endif #if defined(_MSC_VER) && defined(_M_IX86) #define JS_FASTCALL __fastcall @@ -89,22 +94,6 @@ #define JS_NO_FASTCALL #endif -#ifndef JS_ALWAYS_INLINE -#define JS_ALWAYS_INLINE MOZ_ALWAYS_INLINE -#endif - -#ifndef JS_NEVER_INLINE -#define JS_NEVER_INLINE MOZ_NEVER_INLINE -#endif - -#ifndef JS_WARN_UNUSED_RESULT -# if defined __GNUC__ -# define JS_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -# else -# define JS_WARN_UNUSED_RESULT -# endif -#endif - /*********************************************************************** ** MACROS: JS_BEGIN_MACRO ** JS_END_MACRO @@ -122,15 +111,6 @@ # define JS_END_MACRO } while (0) #endif -/*********************************************************************** -** MACROS: JS_BEGIN_EXTERN_C -** JS_END_EXTERN_C -** DESCRIPTION: -** Macro shorthands for conditional C++ extern block delimiters. -***********************************************************************/ -#define JS_BEGIN_EXTERN_C MOZ_BEGIN_EXTERN_C -#define JS_END_EXTERN_C MOZ_END_EXTERN_C - /*********************************************************************** ** MACROS: JS_BIT ** JS_BITMASK @@ -143,8 +123,6 @@ /*********************************************************************** ** MACROS: JS_HOWMANY ** JS_ROUNDUP -** JS_MIN -** JS_MAX ** DESCRIPTION: ** Commonly used macros for operations on compatible types. ***********************************************************************/ @@ -183,34 +161,6 @@ # error "Implement me" #endif -/*********************************************************************** -** MACROS: JS_LIKELY -** JS_UNLIKELY -** DESCRIPTION: -** These macros allow you to give a hint to the compiler about branch -** probability so that it can better optimize. Use them like this: -** -** if (JS_LIKELY(v == 1)) { -** ... expected code path ... -** } -** -** if (JS_UNLIKELY(v == 0)) { -** ... non-expected code path ... -** } -** -***********************************************************************/ -#ifdef __GNUC__ - -# define JS_LIKELY(x) (__builtin_expect((x), 1)) -# define JS_UNLIKELY(x) (__builtin_expect((x), 0)) - -#else - -# define JS_LIKELY(x) (x) -# define JS_UNLIKELY(x) (x) - -#endif - /*********************************************************************** ** MACROS: JS_ARRAY_LENGTH ** JS_ARRAY_END diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/jsversion.h b/frameworks/js-bindings/external/spidermonkey/include/android/jsversion.h index 827a56981d..1f31e40b5e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/jsversion.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/jsversion.h @@ -25,6 +25,9 @@ #define JS_HAS_DESTRUCTURING 2 /* has [a,b] = ... or {p:a,q:b} = ... */ #define JS_HAS_GENERATOR_EXPRS 1 /* has (expr for (lhs in iterable)) */ #define JS_HAS_EXPR_CLOSURES 1 /* has function (formals) listexpr */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_TEMPLATE_STRINGS 1 /* has template string support */ +#endif /* Support for JS_NewGlobalObject. */ #define JS_HAS_NEW_GLOBAL_OBJECT 1 @@ -41,14 +44,9 @@ */ #define JS_OLD_GETTER_SETTER_METHODS 1 -/* A kill-switch for bug 586842. Embedders shouldn't touch this! */ -#define JS_USE_NEW_OBJECT_REPRESENTATION 0 - -#if JS_USE_NEW_OBJECT_REPRESENTATION -# define JS_NEW_OBJECT_REPRESENTATION_ONLY() ((void)0) -#else -# define JS_NEW_OBJECT_REPRESENTATION_ONLY() \ - MOZ_ASSUME_UNREACHABLE("don't call this! to be used in the new object representation") +/* Support for Symbols - Nightly-only for now. */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_SYMBOLS 1 #endif #endif /* jsversion_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/jswrapper.h b/frameworks/js-bindings/external/spidermonkey/include/android/jswrapper.h index 1bf1e16664..a8a510c4f7 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/jswrapper.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/jswrapper.h @@ -15,6 +15,35 @@ namespace js { class DummyFrameGuard; +/* + * Helper for Wrapper::New default options. + * + * Callers of Wrapper::New() who wish to specify a prototype for the created + * Wrapper, *MUST* construct a WrapperOptions with a JSContext. + */ +class MOZ_STACK_CLASS WrapperOptions : public ProxyOptions { + public: + WrapperOptions() : ProxyOptions(false, nullptr), + proto_() + {} + + explicit WrapperOptions(JSContext *cx) : ProxyOptions(false, nullptr), + proto_() + { + proto_.construct(cx); + } + + inline JSObject *proto() const; + WrapperOptions &setProto(JSObject *protoArg) { + JS_ASSERT(!proto_.empty()); + proto_.ref() = protoArg; + return *this; + } + + private: + mozilla::Maybe proto_; +}; + /* * A wrapper is a proxy with a target object to which it generally forwards * operations, but may restrict access to certain operations or instrument @@ -27,7 +56,6 @@ class DummyFrameGuard; class JS_FRIEND_API(Wrapper) : public DirectProxyHandler { unsigned mFlags; - bool mSafeToUnwrap; public: using BaseProxyHandler::Action; @@ -38,23 +66,14 @@ class JS_FRIEND_API(Wrapper) : public DirectProxyHandler }; virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; - /* - * Wrappers can explicitly specify that they are unsafe to unwrap from a - * security perspective (as is the case for SecurityWrappers). If a wrapper - * is not safe to unwrap, operations requiring full access to the underlying - * object (via CheckedUnwrap) will throw. Otherwise, they will succeed. - */ - void setSafeToUnwrap(bool safe) { mSafeToUnwrap = safe; } - bool isSafeToUnwrap() { return mSafeToUnwrap; } + static JSObject *New(JSContext *cx, JSObject *obj, JSObject *parent, const Wrapper *handler, + const WrapperOptions *options = nullptr); - static JSObject *New(JSContext *cx, JSObject *obj, JSObject *proto, - JSObject *parent, Wrapper *handler); + static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, const Wrapper *handler); - static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, Wrapper *handler); - - static Wrapper *wrapperHandler(JSObject *wrapper); + static const Wrapper *wrapperHandler(JSObject *wrapper); static JSObject *wrappedObject(JSObject *wrapper); @@ -62,68 +81,78 @@ class JS_FRIEND_API(Wrapper) : public DirectProxyHandler return mFlags; } - explicit Wrapper(unsigned flags, bool hasPrototype = false); + explicit Wrapper(unsigned flags, bool hasPrototype = false, bool hasSecurityPolicy = false); virtual ~Wrapper(); - virtual bool finalizeInBackground(Value priv) MOZ_OVERRIDE; + virtual bool finalizeInBackground(Value priv) const MOZ_OVERRIDE; + + static const Wrapper singleton; + static const Wrapper singletonWithPrototype; - static Wrapper singleton; - static Wrapper singletonWithPrototype; + static JSObject *defaultProto; }; +inline JSObject * +WrapperOptions::proto() const +{ + return proto_.empty() ? Wrapper::defaultProto : proto_.ref(); +} + /* Base class for all cross compartment wrapper handlers. */ class JS_FRIEND_API(CrossCompartmentWrapper) : public Wrapper { public: - CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false); + explicit CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false, + bool hasSecurityPolicy = false); virtual ~CrossCompartmentWrapper(); /* ES5 Harmony fundamental wrapper traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, - AutoIdVector &props) MOZ_OVERRIDE; - virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; /* ES5 Harmony derived wrapper traps. */ - virtual bool has(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool hasOwn(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; + virtual bool has(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool hasOwn(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; virtual bool get(JSContext *cx, HandleObject wrapper, HandleObject receiver, - HandleId id, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool set(JSContext *cx, HandleObject wrapper, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool keys(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool keys(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; virtual bool iterate(JSContext *cx, HandleObject wrapper, unsigned flags, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject wrapper, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject wrapper, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject wrapper, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual JSString *fun_toString(JSContext *cx, HandleObject wrapper, - unsigned indent) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; - static CrossCompartmentWrapper singleton; - static CrossCompartmentWrapper singletonWithPrototype; + static const CrossCompartmentWrapper singleton; + static const CrossCompartmentWrapper singletonWithPrototype; }; /* @@ -139,25 +168,28 @@ template class JS_FRIEND_API(SecurityWrapper) : public Base { public: - SecurityWrapper(unsigned flags); + explicit SecurityWrapper(unsigned flags, bool hasPrototype = false); - virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) MOZ_OVERRIDE; - virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Wrapper::Action act, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; + + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable) MOZ_OVERRIDE; - virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) MOZ_OVERRIDE; + JS::HandleObject callable) const MOZ_OVERRIDE; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const MOZ_OVERRIDE; /* * Allow our subclasses to select the superclass behavior they want without @@ -179,48 +211,42 @@ class JS_FRIEND_API(DeadObjectProxy) : public BaseProxyHandler explicit DeadObjectProxy(); /* ES5 Harmony fundamental wrapper traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, - AutoIdVector &props) MOZ_OVERRIDE; - virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; - virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver, - uint32_t index, MutableHandleValue vp, - bool *present) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, - MutableHandleObject protop) MOZ_OVERRIDE; + MutableHandleObject protop) const MOZ_OVERRIDE; - static DeadObjectProxy singleton; + static const DeadObjectProxy singleton; }; extern JSObject * TransparentObjectWrapper(JSContext *cx, HandleObject existing, HandleObject obj, - HandleObject wrappedProto, HandleObject parent, - unsigned flags); + HandleObject parent, unsigned flags); // Proxy family for wrappers. Public so that IsWrapper() can be fully inlined by // jsfriendapi users. @@ -295,8 +321,8 @@ RecomputeWrappers(JSContext *cx, const CompartmentFilter &sourceFilter, struct JS_FRIEND_API(AutoMaybeTouchDeadZones) { // The version that takes an object just uses it for its runtime. - AutoMaybeTouchDeadZones(JSContext *cx); - AutoMaybeTouchDeadZones(JSObject *obj); + explicit AutoMaybeTouchDeadZones(JSContext *cx); + explicit AutoMaybeTouchDeadZones(JSObject *obj); ~AutoMaybeTouchDeadZones(); private: diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Alignment.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Alignment.h index 29599d0ef1..0ac8a48779 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Alignment.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Alignment.h @@ -21,14 +21,14 @@ namespace mozilla { template class AlignmentFinder { - struct Aligner - { - char c; - T t; - }; - - public: - static const size_t alignment = sizeof(Aligner) - sizeof(T); + struct Aligner + { + char mChar; + T mT; + }; + +public: + static const size_t alignment = sizeof(Aligner) - sizeof(T); }; #define MOZ_ALIGNOF(T) mozilla::AlignmentFinder::alignment @@ -64,38 +64,38 @@ template struct AlignedElem; /* - * We have to specialize this template because GCC doesn't like __attribute__((aligned(foo))) where - * foo is a template parameter. + * We have to specialize this template because GCC doesn't like + * __attribute__((aligned(foo))) where foo is a template parameter. */ template<> struct AlignedElem<1> { - MOZ_ALIGNED_DECL(uint8_t elem, 1); + MOZ_ALIGNED_DECL(uint8_t elem, 1); }; template<> struct AlignedElem<2> { - MOZ_ALIGNED_DECL(uint8_t elem, 2); + MOZ_ALIGNED_DECL(uint8_t elem, 2); }; template<> struct AlignedElem<4> { - MOZ_ALIGNED_DECL(uint8_t elem, 4); + MOZ_ALIGNED_DECL(uint8_t elem, 4); }; template<> struct AlignedElem<8> { - MOZ_ALIGNED_DECL(uint8_t elem, 8); + MOZ_ALIGNED_DECL(uint8_t elem, 8); }; template<> struct AlignedElem<16> { - MOZ_ALIGNED_DECL(uint8_t elem, 16); + MOZ_ALIGNED_DECL(uint8_t elem, 16); }; /* @@ -111,25 +111,27 @@ struct AlignedElem<16> template struct AlignedStorage { - union U { - char bytes[Nbytes]; - uint64_t _; - } u; - - const void* addr() const { return u.bytes; } - void* addr() { return u.bytes; } + union U + { + char mBytes[Nbytes]; + uint64_t mDummy; + } u; + + const void* addr() const { return u.mBytes; } + void* addr() { return u.mBytes; } }; template struct AlignedStorage2 { - union U { - char bytes[sizeof(T)]; - uint64_t _; - } u; - - const T* addr() const { return reinterpret_cast(u.bytes); } - T* addr() { return static_cast(static_cast(u.bytes)); } + union U + { + char mBytes[sizeof(T)]; + uint64_t mDummy; + } u; + + const T* addr() const { return reinterpret_cast(u.mBytes); } + T* addr() { return static_cast(static_cast(u.mBytes)); } }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/AllocPolicy.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/AllocPolicy.h index 20087e93bb..357c632a02 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/AllocPolicy.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/AllocPolicy.h @@ -49,14 +49,31 @@ namespace mozilla { */ class MallocAllocPolicy { - public: - void* malloc_(size_t bytes) { return malloc(bytes); } - void* calloc_(size_t bytes) { return calloc(bytes, 1); } - void* realloc_(void* p, size_t oldBytes, size_t bytes) { return realloc(p, bytes); } - void free_(void* p) { free(p); } - void reportAllocOverflow() const {} -}; +public: + void* malloc_(size_t aBytes) + { + return malloc(aBytes); + } + + void* calloc_(size_t aBytes) + { + return calloc(aBytes, 1); + } + + void* realloc_(void* aPtr, size_t aOldBytes, size_t aBytes) + { + return realloc(aPtr, aBytes); + } + void free_(void* aPtr) + { + free(aPtr); + } + + void reportAllocOverflow() const + { + } +}; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Array.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Array.h index 5af9aaa133..b2ab578d4b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Array.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Array.h @@ -19,31 +19,35 @@ namespace mozilla { template class Array { - T arr[Length]; - - public: - T& operator[](size_t i) { - MOZ_ASSERT(i < Length); - return arr[i]; - } - - const T& operator[](size_t i) const { - MOZ_ASSERT(i < Length); - return arr[i]; - } + T mArr[Length]; + +public: + T& operator[](size_t aIndex) + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } + + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } }; template class Array { - public: - T& operator[](size_t i) { - MOZ_ASSUME_UNREACHABLE("indexing into zero-length array"); - } - - const T& operator[](size_t i) const { - MOZ_ASSUME_UNREACHABLE("indexing into zero-length array"); - } +public: + T& operator[](size_t aIndex) + { + MOZ_CRASH("indexing into zero-length array"); + } + + const T& operator[](size_t aIndex) const + { + MOZ_CRASH("indexing into zero-length array"); + } }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ArrayUtils.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ArrayUtils.h index e2226bf59d..44f5980c44 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ArrayUtils.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ArrayUtils.h @@ -18,22 +18,24 @@ #ifdef __cplusplus +#include "mozilla/Alignment.h" #include "mozilla/Array.h" +#include "mozilla/TypeTraits.h" namespace mozilla { /* - * Safely subtract two pointers when it is known that end >= begin. This avoids - * the common compiler bug that if (size_t(end) - size_t(begin)) has the MSB - * set, the unsigned subtraction followed by right shift will produce -1, or - * size_t(-1), instead of the real difference. + * Safely subtract two pointers when it is known that aEnd >= aBegin. This + * avoids the common compiler bug that if (size_t(aEnd) - size_t(aBegin)) has + * the MSB set, the unsigned subtraction followed by right shift will produce + * -1, or size_t(-1), instead of the real difference. */ template MOZ_ALWAYS_INLINE size_t -PointerRangeSize(T* begin, T* end) +PointerRangeSize(T* aBegin, T* aEnd) { - MOZ_ASSERT(end >= begin); - return (size_t(end) - size_t(begin)) / sizeof(T); + MOZ_ASSERT(aEnd >= aBegin); + return (size_t(aEnd) - size_t(aBegin)) / sizeof(T); } /* @@ -44,14 +46,14 @@ PointerRangeSize(T* begin, T* end) */ template MOZ_CONSTEXPR size_t -ArrayLength(T (&arr)[N]) +ArrayLength(T (&aArr)[N]) { return N; } template MOZ_CONSTEXPR size_t -ArrayLength(const Array& arr) +ArrayLength(const Array& aArr) { return N; } @@ -63,25 +65,100 @@ ArrayLength(const Array& arr) */ template MOZ_CONSTEXPR T* -ArrayEnd(T (&arr)[N]) +ArrayEnd(T (&aArr)[N]) { - return arr + ArrayLength(arr); + return aArr + ArrayLength(aArr); } template MOZ_CONSTEXPR T* -ArrayEnd(Array& arr) +ArrayEnd(Array& aArr) { - return &arr[0] + ArrayLength(arr); + return &aArr[0] + ArrayLength(aArr); } template MOZ_CONSTEXPR const T* -ArrayEnd(const Array& arr) +ArrayEnd(const Array& aArr) { - return &arr[0] + ArrayLength(arr); + return &aArr[0] + ArrayLength(aArr); } +namespace detail { + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % MOZ_ALIGNOF(AlignType)) == 0, + "performing a range-check with a misaligned pointer"); + } +}; + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + } +}; + +} // namespace detail + +/** + * Determines whether |aPtr| points at an object in the range [aBegin, aEnd). + * + * |aPtr| must have the same alignment as |aBegin| and |aEnd|. This usually + * should be achieved by ensuring |aPtr| points at a |U|, not just that it + * points at a |T|. + * + * It is a usage error for any argument to be misaligned. + * + * It's okay for T* to be void*, and if so U* may also be void*. In the latter + * case no argument is required to be aligned (obviously, as void* implies no + * particular alignment). + */ +template +inline typename EnableIf::value || + IsBaseOf::value || + IsVoid::value, + bool>::Type +IsInRange(T* aPtr, U* aBegin, U* aEnd) +{ + MOZ_ASSERT(aBegin <= aEnd); + detail::AlignedChecker::test(aPtr); + detail::AlignedChecker::test(aBegin); + detail::AlignedChecker::test(aEnd); + return aBegin <= static_cast(aPtr) && static_cast(aPtr) < aEnd; +} + +/** + * Convenience version of the above method when the valid range is specified as + * uintptr_t values. As above, |aPtr| must be aligned, and |aBegin| and |aEnd| + * must be aligned with respect to |T|. + */ +template +inline bool +IsInRange(T* aPtr, uintptr_t aBegin, uintptr_t aEnd) +{ + return IsInRange(aPtr, + reinterpret_cast(aBegin), reinterpret_cast(aEnd)); +} + +namespace detail { + +/* + * Helper for the MOZ_ARRAY_LENGTH() macro to make the length a typesafe + * compile-time constant even on compilers lacking constexpr support. + */ +template +char (&ArrayLengthHelper(T (&array)[N]))[N]; + +} /* namespace detail */ + } /* namespace mozilla */ #endif /* __cplusplus */ @@ -91,8 +168,8 @@ ArrayEnd(const Array& arr) * that can't use C++ template functions and for static_assert() calls that * can't call ArrayLength() when it is not a C++11 constexpr function. */ -#ifdef MOZ_HAVE_CXX11_CONSTEXPR -# define MOZ_ARRAY_LENGTH(array) mozilla::ArrayLength(array) +#ifdef __cplusplus +# define MOZ_ARRAY_LENGTH(array) sizeof(mozilla::detail::ArrayLengthHelper(array)) #else # define MOZ_ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0])) #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Assertions.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Assertions.h index 8a5fa205f9..a463b2768d 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Assertions.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Assertions.h @@ -9,9 +9,17 @@ #ifndef mozilla_Assertions_h #define mozilla_Assertions_h +#if defined(MOZILLA_INTERNAL_API) && defined(__cplusplus) +#define MOZ_DUMP_ASSERTION_STACK +#endif + #include "mozilla/Attributes.h" #include "mozilla/Compiler.h" #include "mozilla/Likely.h" +#include "mozilla/MacroArgs.h" +#ifdef MOZ_DUMP_ASSERTION_STACK +#include "nsTraceRefcnt.h" +#endif #include #include @@ -24,13 +32,13 @@ * number of undesired macros and symbols. */ # ifdef __cplusplus - extern "C" { +extern "C" { # endif - __declspec(dllimport) int __stdcall - TerminateProcess(void* hProcess, unsigned int uExitCode); - __declspec(dllimport) void* __stdcall GetCurrentProcess(void); +__declspec(dllimport) int __stdcall +TerminateProcess(void* hProcess, unsigned int uExitCode); +__declspec(dllimport) void* __stdcall GetCurrentProcess(void); # ifdef __cplusplus - } +} # endif #else # include @@ -116,33 +124,42 @@ extern "C" { #endif /* - * Prints |s| as an assertion failure (using file and ln as the location of the - * assertion) to the standard debug-output channel. + * Prints |aStr| as an assertion failure (using aFilename and aLine as the + * location of the assertion) to the standard debug-output channel. * * Usually you should use MOZ_ASSERT or MOZ_CRASH instead of this method. This * method is primarily for internal use in this header, and only secondarily * for use in implementing release-build assertions. */ static MOZ_ALWAYS_INLINE void -MOZ_ReportAssertionFailure(const char* s, const char* file, int ln) +MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS { #ifdef ANDROID __android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert", - "Assertion failure: %s, at %s:%d\n", s, file, ln); + "Assertion failure: %s, at %s:%d\n", + aStr, aFilename, aLine); #else - fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln); + fprintf(stderr, "Assertion failure: %s, at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif fflush(stderr); #endif } static MOZ_ALWAYS_INLINE void -MOZ_ReportCrash(const char* s, const char* file, int ln) +MOZ_ReportCrash(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS { #ifdef ANDROID - __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", - "Hit MOZ_CRASH(%s) at %s:%d\n", s, file, ln); + __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", + "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); #else - fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", s, file, ln); + fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif fflush(stderr); #endif } @@ -238,7 +255,7 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} do { \ MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \ MOZ_REALLY_CRASH(); \ - } while(0) + } while (0) #endif #ifdef __cplusplus @@ -279,52 +296,108 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} * MOZ_RELEASE_ASSERT, which applies to non-debug builds as well. */ +/* + * Implement MOZ_VALIDATE_ASSERT_CONDITION_TYPE, which is used to guard against + * accidentally passing something unintended in lieu of an assertion condition. + */ + +#ifdef __cplusplus +# if defined(__clang__) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# elif defined(__GNUC__) +// B2G GCC 4.4 has insufficient decltype support. +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# endif +# elif defined(_MSC_VER) +// Disabled for now because of insufficient decltype support. Bug 1004028. +# endif +#endif + +#ifdef MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# include "mozilla/TypeTraits.h" +namespace mozilla { +namespace detail { + +template +struct IsFunction +{ + static const bool value = false; +}; + +template +struct IsFunction +{ + static const bool value = true; +}; + +template +void ValidateAssertConditionType() +{ + typedef typename RemoveReference::Type ValueT; + static_assert(!IsArray::value, + "Expected boolean assertion condition, got an array or a " + "string!"); + static_assert(!IsFunction::value, + "Expected boolean assertion condition, got a function! Did " + "you intend to call that function?"); + static_assert(!IsFloatingPoint::value, + "It's often a bad idea to assert that a floating-point number " + "is nonzero, because such assertions tend to intermittently " + "fail. Shouldn't your code gracefully handle this case instead " + "of asserting? Anyway, if you really want to do that, write an " + "explicit boolean condition, like !!x or x!=0."); +} + +} // namespace detail +} // namespace mozilla +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) \ + mozilla::detail::ValidateAssertConditionType() +#else +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) +#endif + /* First the single-argument form. */ #define MOZ_ASSERT_HELPER1(expr) \ - do { \ - if (MOZ_UNLIKELY(!(expr))) { \ - MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } \ - } while (0) + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) /* Now the two-argument form. */ #define MOZ_ASSERT_HELPER2(expr, explain) \ - do { \ - if (MOZ_UNLIKELY(!(expr))) { \ - MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } \ - } while (0) -/* And now, helper macrology up the wazoo. */ -/* - * Count the number of arguments passed to MOZ_ASSERT, very carefully - * tiptoeing around an MSVC bug where it improperly expands __VA_ARGS__ as a - * single token in argument lists. See these URLs for details: - * - * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement - * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 - */ -#define MOZ_COUNT_ASSERT_ARGS_IMPL2(_1, _2, count, ...) \ - count -#define MOZ_COUNT_ASSERT_ARGS_IMPL(args) \ - MOZ_COUNT_ASSERT_ARGS_IMPL2 args -#define MOZ_COUNT_ASSERT_ARGS(...) \ - MOZ_COUNT_ASSERT_ARGS_IMPL((__VA_ARGS__, 2, 1, 0)) -/* Pick the right helper macro to invoke. */ -#define MOZ_ASSERT_CHOOSE_HELPER2(count) MOZ_ASSERT_HELPER##count -#define MOZ_ASSERT_CHOOSE_HELPER1(count) MOZ_ASSERT_CHOOSE_HELPER2(count) -#define MOZ_ASSERT_CHOOSE_HELPER(count) MOZ_ASSERT_CHOOSE_HELPER1(count) -/* The actual macros. */ -#define MOZ_ASSERT_GLUE(x, y) x y + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) + +#define MOZ_RELEASE_ASSERT_GLUE(a, b) a b #define MOZ_RELEASE_ASSERT(...) \ - MOZ_ASSERT_GLUE(MOZ_ASSERT_CHOOSE_HELPER(MOZ_COUNT_ASSERT_ARGS(__VA_ARGS__)), \ - (__VA_ARGS__)) + MOZ_RELEASE_ASSERT_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \ + (__VA_ARGS__)) + #ifdef DEBUG # define MOZ_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) #else -# define MOZ_ASSERT(...) do { } while(0) +# define MOZ_ASSERT(...) do { } while (0) #endif /* DEBUG */ +/* + * MOZ_NIGHTLY_ASSERT is defined for both debug and release builds on the + * Nightly channel, but only debug builds on Aurora, Beta, and Release. + */ +#if defined(NIGHTLY_BUILD) +# define MOZ_NIGHTLY_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) +#else +# define MOZ_NIGHTLY_ASSERT(...) MOZ_ASSERT(__VA_ARGS__) +#endif + /* * MOZ_ASSERT_IF(cond1, cond2) is equivalent to MOZ_ASSERT(cond2) if cond1 is * true. @@ -337,19 +410,20 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} #ifdef DEBUG # define MOZ_ASSERT_IF(cond, expr) \ do { \ - if (cond) \ + if (cond) { \ MOZ_ASSERT(expr); \ + } \ } while (0) #else # define MOZ_ASSERT_IF(cond, expr) do { } while (0) #endif /* - * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that it is - * undefined behavior for execution to reach this point. No guarantees are made - * about what will happen if this is reached at runtime. Most code should - * probably use the higher level MOZ_ASSUME_UNREACHABLE, which uses this when - * appropriate. + * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that + * it is undefined behavior for execution to reach this point. No guarantees + * are made about what will happen if this is reached at runtime. Most code + * should use MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE because it has extra + * asserts. */ #if defined(__clang__) # define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable() @@ -379,21 +453,22 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} #endif /* - * MOZ_ASSUME_UNREACHABLE([reason]) tells the compiler that it can assume that - * the macro call cannot be reached during execution. This lets the compiler - * generate better-optimized code under some circumstances, at the expense of - * the program's behavior being undefined if control reaches the - * MOZ_ASSUME_UNREACHABLE. + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE([reason]) tells the compiler that it + * can assume that the macro call cannot be reached during execution. This lets + * the compiler generate better-optimized code under some circumstances, at the + * expense of the program's behavior being undefined if control reaches the + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE. * * In Gecko, you probably should not use this macro outside of performance- or * size-critical code, because it's unsafe. If you don't care about code size * or performance, you should probably use MOZ_ASSERT or MOZ_CRASH. * * SpiderMonkey is a different beast, and there it's acceptable to use - * MOZ_ASSUME_UNREACHABLE more widely. + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE more widely. * - * Note that MOZ_ASSUME_UNREACHABLE is noreturn, so it's valid not to return a - * value following a MOZ_ASSUME_UNREACHABLE call. + * Note that MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE is noreturn, so it's valid + * not to return a value following a MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE + * call. * * Example usage: * @@ -413,19 +488,32 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} * case VALUE_FLOAT: * return (int) *(float*) value; * default: - * MOZ_ASSUME_UNREACHABLE("can only handle VALUE_INT and VALUE_FLOAT"); + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected ValueType"); * } * } */ -#if defined(DEBUG) -# define MOZ_ASSUME_UNREACHABLE(...) \ - do { \ - MOZ_ASSERT(false, "MOZ_ASSUME_UNREACHABLE(" __VA_ARGS__ ")"); \ - MOZ_ASSUME_UNREACHABLE_MARKER(); \ - } while (0) -#else -# define MOZ_ASSUME_UNREACHABLE(reason) MOZ_ASSUME_UNREACHABLE_MARKER() -#endif + +/* + * Assert in all debug builds plus the Nightly channel's release builds. Take + * this extra testing precaution because hitting MOZ_ASSUME_UNREACHABLE_MARKER + * could trigger exploitable undefined behavior. + */ +#define MOZ_ASSERT_UNREACHABLE(reason) \ + MOZ_NIGHTLY_ASSERT(false, "MOZ_ASSERT_UNREACHABLE: " reason) + +#define MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) \ + do { \ + MOZ_ASSERT_UNREACHABLE(reason); \ + MOZ_ASSUME_UNREACHABLE_MARKER(); \ + } while (0) + +/* + * TODO: Bug 990764: Audit all MOZ_ASSUME_UNREACHABLE calls and replace them + * with MOZ_ASSERT_UNREACHABLE, MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE, or + * MOZ_CRASH. For now, preserve the macro's same meaning of unreachable. + */ +#define MOZ_ASSUME_UNREACHABLE(reason) \ + MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) /* * MOZ_ALWAYS_TRUE(expr) and MOZ_ALWAYS_FALSE(expr) always evaluate the provided @@ -441,4 +529,6 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} # define MOZ_ALWAYS_FALSE(expr) ((void)(expr)) #endif +#undef MOZ_DUMP_ASSERTION_STACK + #endif /* mozilla_Assertions_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Atomics.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Atomics.h index 03ae7c34f3..71d95c61ba 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Atomics.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Atomics.h @@ -41,6 +41,13 @@ # define MOZ_HAVE_CXX11_ATOMICS # endif #elif defined(_MSC_VER) && _MSC_VER >= 1700 +# if defined(DEBUG) + /* + * Provide our own failure code since we're having trouble linking to + * std::_Debug_message (bug 982310). + */ +# define _INVALID_MEMORY_ORDER MOZ_CRASH("Invalid memory order") +# endif # define MOZ_HAVE_CXX11_ATOMICS #endif @@ -107,6 +114,7 @@ enum MemoryOrdering { * ordering if you can't easily test non-x86 architectures! */ Relaxed, + /* * When an atomic value is updated with ReleaseAcquire ordering, and * that new value is observed with ReleaseAcquire ordering, prior @@ -128,6 +136,7 @@ enum MemoryOrdering { * a good, hard look at actual lock or mutex primitives first. */ ReleaseAcquire, + /* * When an atomic value is updated with SequentiallyConsistent * ordering, all writes observable when the update is observed, just @@ -177,126 +186,154 @@ template struct AtomicOrderConstraints; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_relaxed; - static const std::memory_order LoadOrder = std::memory_order_relaxed; - static const std::memory_order StoreOrder = std::memory_order_relaxed; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_relaxed; + static const std::memory_order AtomicRMWOrder = std::memory_order_relaxed; + static const std::memory_order LoadOrder = std::memory_order_relaxed; + static const std::memory_order StoreOrder = std::memory_order_relaxed; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_relaxed; }; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_acq_rel; - static const std::memory_order LoadOrder = std::memory_order_acquire; - static const std::memory_order StoreOrder = std::memory_order_release; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_acquire; + static const std::memory_order AtomicRMWOrder = std::memory_order_acq_rel; + static const std::memory_order LoadOrder = std::memory_order_acquire; + static const std::memory_order StoreOrder = std::memory_order_release; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_acquire; }; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_seq_cst; - static const std::memory_order LoadOrder = std::memory_order_seq_cst; - static const std::memory_order StoreOrder = std::memory_order_seq_cst; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_seq_cst; + static const std::memory_order AtomicRMWOrder = std::memory_order_seq_cst; + static const std::memory_order LoadOrder = std::memory_order_seq_cst; + static const std::memory_order StoreOrder = std::memory_order_seq_cst; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_seq_cst; }; template struct IntrinsicBase { - typedef std::atomic ValueType; - typedef AtomicOrderConstraints OrderedOp; + typedef std::atomic ValueType; + typedef AtomicOrderConstraints OrderedOp; }; template struct IntrinsicMemoryOps : public IntrinsicBase { - typedef IntrinsicBase Base; - static T load(const typename Base::ValueType& ptr) { - return ptr.load(Base::OrderedOp::LoadOrder); - } - static void store(typename Base::ValueType& ptr, T val) { - ptr.store(val, Base::OrderedOp::StoreOrder); - } - static T exchange(typename Base::ValueType& ptr, T val) { - return ptr.exchange(val, Base::OrderedOp::AtomicRMWOrder); - } - static bool compareExchange(typename Base::ValueType& ptr, T oldVal, T newVal) { - return ptr.compare_exchange_strong(oldVal, newVal, - Base::OrderedOp::AtomicRMWOrder, - Base::OrderedOp::CompareExchangeFailureOrder); - } + typedef IntrinsicBase Base; + + static T load(const typename Base::ValueType& aPtr) + { + return aPtr.load(Base::OrderedOp::LoadOrder); + } + + static void store(typename Base::ValueType& aPtr, T aVal) + { + aPtr.store(aVal, Base::OrderedOp::StoreOrder); + } + + static T exchange(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.exchange(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static bool compareExchange(typename Base::ValueType& aPtr, + T aOldVal, T aNewVal) + { + return aPtr.compare_exchange_strong(aOldVal, aNewVal, + Base::OrderedOp::AtomicRMWOrder, + Base::OrderedOp::CompareExchangeFailureOrder); + } }; template struct IntrinsicAddSub : public IntrinsicBase { - typedef IntrinsicBase Base; - static T add(typename Base::ValueType& ptr, T val) { - return ptr.fetch_add(val, Base::OrderedOp::AtomicRMWOrder); - } - static T sub(typename Base::ValueType& ptr, T val) { - return ptr.fetch_sub(val, Base::OrderedOp::AtomicRMWOrder); - } + typedef IntrinsicBase Base; + + static T add(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_add(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T sub(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_sub(aVal, Base::OrderedOp::AtomicRMWOrder); + } }; template struct IntrinsicAddSub : public IntrinsicBase { - typedef IntrinsicBase Base; - static T* add(typename Base::ValueType& ptr, ptrdiff_t val) { - return ptr.fetch_add(fixupAddend(val), Base::OrderedOp::AtomicRMWOrder); - } - static T* sub(typename Base::ValueType& ptr, ptrdiff_t val) { - return ptr.fetch_sub(fixupAddend(val), Base::OrderedOp::AtomicRMWOrder); - } - private: - /* - * GCC 4.6's header has a bug where adding X to an - * atomic is not the same as adding X to a T*. Hence the need - * for this function to provide the correct addend. - */ - static ptrdiff_t fixupAddend(ptrdiff_t val) { + typedef IntrinsicBase Base; + + static T* add(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_add(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } + + static T* sub(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_sub(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } +private: + /* + * GCC 4.6's header has a bug where adding X to an + * atomic is not the same as adding X to a T*. Hence the need + * for this function to provide the correct addend. + */ + static ptrdiff_t fixupAddend(ptrdiff_t aVal) + { #if defined(__clang__) || defined(_MSC_VER) - return val; + return aVal; #elif defined(__GNUC__) && MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) && \ - !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) - return val * sizeof(T); + !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) + return aVal * sizeof(T); #else - return val; + return aVal; #endif - } + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - typedef IntrinsicBase Base; - static T inc(typename Base::ValueType& ptr) { - return IntrinsicAddSub::add(ptr, 1); - } - static T dec(typename Base::ValueType& ptr) { - return IntrinsicAddSub::sub(ptr, 1); - } + typedef IntrinsicBase Base; + + static T inc(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::add(aPtr, 1); + } + + static T dec(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::sub(aPtr, 1); + } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef IntrinsicBase Base; - static T or_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_or(val, Base::OrderedOp::AtomicRMWOrder); - } - static T xor_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_xor(val, Base::OrderedOp::AtomicRMWOrder); - } - static T and_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_and(val, Base::OrderedOp::AtomicRMWOrder); - } + typedef IntrinsicBase Base; + + static T or_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_or(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T xor_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_xor(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T and_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_and(aVal, Base::OrderedOp::AtomicRMWOrder); + } }; template @@ -345,111 +382,119 @@ template struct Barrier; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() {} - static void beforeStore() {} - static void afterStore() {} + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} + static void afterStore() {} }; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() { __sync_synchronize(); } - static void beforeStore() { __sync_synchronize(); } - static void afterStore() {} + static void beforeLoad() {} + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() {} }; template<> struct Barrier { - static void beforeLoad() { __sync_synchronize(); } - static void afterLoad() { __sync_synchronize(); } - static void beforeStore() { __sync_synchronize(); } - static void afterStore() { __sync_synchronize(); } + static void beforeLoad() { __sync_synchronize(); } + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() { __sync_synchronize(); } }; template struct IntrinsicMemoryOps { - static T load(const T& ptr) { - Barrier::beforeLoad(); - T val = ptr; - Barrier::afterLoad(); - return val; - } - static void store(T& ptr, T val) { - Barrier::beforeStore(); - ptr = val; - Barrier::afterStore(); - } - static T exchange(T& ptr, T val) { - // __sync_lock_test_and_set is only an acquire barrier; loads and stores - // can't be moved up from after to before it, but they can be moved down - // from before to after it. We may want a stricter ordering, so we need - // an explicit barrier. - - Barrier::beforeStore(); - return __sync_lock_test_and_set(&ptr, val); - } - static bool compareExchange(T& ptr, T oldVal, T newVal) { - return __sync_bool_compare_and_swap(&ptr, oldVal, newVal); - } + static T load(const T& aPtr) + { + Barrier::beforeLoad(); + T val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(T& aPtr, T aVal) + { + Barrier::beforeStore(); + aPtr = aVal; + Barrier::afterStore(); + } + + static T exchange(T& aPtr, T aVal) + { + // __sync_lock_test_and_set is only an acquire barrier; loads and stores + // can't be moved up from after to before it, but they can be moved down + // from before to after it. We may want a stricter ordering, so we need + // an explicit barrier. + Barrier::beforeStore(); + return __sync_lock_test_and_set(&aPtr, aVal); + } + + static bool compareExchange(T& aPtr, T aOldVal, T aNewVal) + { + return __sync_bool_compare_and_swap(&aPtr, aOldVal, aNewVal); + } }; template struct IntrinsicAddSub { - typedef T ValueType; - static T add(T& ptr, T val) { - return __sync_fetch_and_add(&ptr, val); - } - static T sub(T& ptr, T val) { - return __sync_fetch_and_sub(&ptr, val); - } + typedef T ValueType; + + static T add(T& aPtr, T aVal) + { + return __sync_fetch_and_add(&aPtr, aVal); + } + + static T sub(T& aPtr, T aVal) + { + return __sync_fetch_and_sub(&aPtr, aVal); + } }; template struct IntrinsicAddSub { - typedef T* ValueType; - /* - * The reinterpret_casts are needed so that - * __sync_fetch_and_{add,sub} will properly type-check. - * - * Also, these functions do not provide standard semantics for - * pointer types, so we need to adjust the addend. - */ - static ValueType add(ValueType& ptr, ptrdiff_t val) { - ValueType amount = reinterpret_cast(val * sizeof(T)); - return __sync_fetch_and_add(&ptr, amount); - } - static ValueType sub(ValueType& ptr, ptrdiff_t val) { - ValueType amount = reinterpret_cast(val * sizeof(T)); - return __sync_fetch_and_sub(&ptr, amount); - } + typedef T* ValueType; + + /* + * The reinterpret_casts are needed so that + * __sync_fetch_and_{add,sub} will properly type-check. + * + * Also, these functions do not provide standard semantics for + * pointer types, so we need to adjust the addend. + */ + static ValueType add(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_add(&aPtr, amount); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_sub(&aPtr, amount); + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - static T inc(T& ptr) { return IntrinsicAddSub::add(ptr, 1); } - static T dec(T& ptr) { return IntrinsicAddSub::sub(ptr, 1); } + static T inc(T& aPtr) { return IntrinsicAddSub::add(aPtr, 1); } + static T dec(T& aPtr) { return IntrinsicAddSub::sub(aPtr, 1); } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - static T or_(T& ptr, T val) { - return __sync_fetch_and_or(&ptr, val); - } - static T xor_(T& ptr, T val) { - return __sync_fetch_and_xor(&ptr, val); - } - static T and_(T& ptr, T val) { - return __sync_fetch_and_and(&ptr, val); - } + static T or_( T& aPtr, T aVal) { return __sync_fetch_and_or(&aPtr, aVal); } + static T xor_(T& aPtr, T aVal) { return __sync_fetch_and_xor(&aPtr, aVal); } + static T and_(T& aPtr, T aVal) { return __sync_fetch_and_and(&aPtr, aVal); } }; template @@ -470,19 +515,9 @@ struct AtomicIntrinsics : public IntrinsicMemoryOps, * version of Windows we support. Therefore, we only provide operations * on 32-bit datatypes for 32-bit Windows versions; for 64-bit Windows * versions, we support 64-bit datatypes as well. - * - * To avoid namespace pollution issues, we declare whatever functions we - * need ourselves. */ -extern "C" { -long __cdecl _InterlockedExchangeAdd(long volatile* dst, long value); -long __cdecl _InterlockedOr(long volatile* dst, long value); -long __cdecl _InterlockedXor(long volatile* dst, long value); -long __cdecl _InterlockedAnd(long volatile* dst, long value); -long __cdecl _InterlockedExchange(long volatile *dst, long value); -long __cdecl _InterlockedCompareExchange(long volatile *dst, long newVal, long oldVal); -} +# include # pragma intrinsic(_InterlockedExchangeAdd) # pragma intrinsic(_InterlockedOr) @@ -507,34 +542,34 @@ namespace detail { * The PrimitiveIntrinsics template should define |Type|, the datatype of size * DataSize upon which we operate, and the following eight functions. * - * static Type add(Type* ptr, Type val); - * static Type sub(Type* ptr, Type val); - * static Type or_(Type* ptr, Type val); - * static Type xor_(Type* ptr, Type val); - * static Type and_(Type* ptr, Type val); + * static Type add(Type* aPtr, Type aVal); + * static Type sub(Type* aPtr, Type aVal); + * static Type or_(Type* aPtr, Type aVal); + * static Type xor_(Type* aPtr, Type aVal); + * static Type and_(Type* aPtr, Type aVal); * * These functions perform the obvious operation on the value contained in - * |*ptr| combined with |val| and return the value previously stored in - * |*ptr|. + * |*aPtr| combined with |aVal| and return the value previously stored in + * |*aPtr|. * - * static void store(Type* ptr, Type val); + * static void store(Type* aPtr, Type aVal); * - * This function atomically stores |val| into |*ptr| and must provide a full + * This function atomically stores |aVal| into |*aPtr| and must provide a full * memory fence after the store to prevent compiler and hardware instruction * reordering. It should also act as a compiler barrier to prevent reads and * writes from moving to after the store. * - * static Type exchange(Type* ptr, Type val); + * static Type exchange(Type* aPtr, Type aVal); * - * This function atomically stores |val| into |*ptr| and returns the previous - * contents of *ptr; + * This function atomically stores |aVal| into |*aPtr| and returns the + * previous contents of |*aPtr|; * - * static bool compareExchange(Type* ptr, Type oldVal, Type newVal); + * static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal); * * This function atomically performs the following operation: * - * if (*ptr == oldVal) { - * *ptr = newVal; + * if (*aPtr == aOldVal) { + * *aPtr = aNewVal; * return true; * } else { * return false; @@ -546,56 +581,55 @@ template struct PrimitiveIntrinsics; template<> struct PrimitiveIntrinsics<4> { - typedef long Type; + typedef long Type; - static Type add(Type* ptr, Type val) { - return _InterlockedExchangeAdd(ptr, val); - } - static Type sub(Type* ptr, Type val) { - /* - * _InterlockedExchangeSubtract isn't available before Windows 7, - * and we must support Windows XP. - */ - return _InterlockedExchangeAdd(ptr, -val); - } - static Type or_(Type* ptr, Type val) { - return _InterlockedOr(ptr, val); - } - static Type xor_(Type* ptr, Type val) { - return _InterlockedXor(ptr, val); - } - static Type and_(Type* ptr, Type val) { - return _InterlockedAnd(ptr, val); - } - static void store(Type* ptr, Type val) { - _InterlockedExchange(ptr, val); - } - static Type exchange(Type* ptr, Type val) { - return _InterlockedExchange(ptr, val); - } - static bool compareExchange(Type* ptr, Type oldVal, Type newVal) { - return _InterlockedCompareExchange(ptr, newVal, oldVal) == oldVal; - } + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * _InterlockedExchangeSubtract isn't available before Windows 7, + * and we must support Windows XP. + */ + return _InterlockedExchangeAdd(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange(aPtr, aNewVal, aOldVal) == aOldVal; + } }; # if defined(_M_X64) -extern "C" { -long long __cdecl _InterlockedExchangeAdd64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedOr64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedXor64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedAnd64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedExchange64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedCompareExchange64(long long volatile* dst, - long long newVal, - long long oldVal); -} - # pragma intrinsic(_InterlockedExchangeAdd64) # pragma intrinsic(_InterlockedOr64) # pragma intrinsic(_InterlockedXor64) @@ -606,41 +640,54 @@ long long __cdecl _InterlockedCompareExchange64(long long volatile* dst, template <> struct PrimitiveIntrinsics<8> { - typedef __int64 Type; + typedef __int64 Type; - static Type add(Type* ptr, Type val) { - return _InterlockedExchangeAdd64(ptr, val); - } - static Type sub(Type* ptr, Type val) { - /* - * There is no _InterlockedExchangeSubtract64. - */ - return _InterlockedExchangeAdd64(ptr, -val); - } - static Type or_(Type* ptr, Type val) { - return _InterlockedOr64(ptr, val); - } - static Type xor_(Type* ptr, Type val) { - return _InterlockedXor64(ptr, val); - } - static Type and_(Type* ptr, Type val) { - return _InterlockedAnd64(ptr, val); - } - static void store(Type* ptr, Type val) { - _InterlockedExchange64(ptr, val); - } - static Type exchange(Type* ptr, Type val) { - return _InterlockedExchange64(ptr, val); - } - static bool compareExchange(Type* ptr, Type oldVal, Type newVal) { - return _InterlockedCompareExchange64(ptr, newVal, oldVal) == oldVal; - } + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd64(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * There is no _InterlockedExchangeSubtract64. + */ + return _InterlockedExchangeAdd64(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr64(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor64(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd64(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange64(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange64(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange64(aPtr, aNewVal, aOldVal) == aOldVal; + } }; # endif -extern "C" { void _ReadWriteBarrier(); } - # pragma intrinsic(_ReadWriteBarrier) template struct Barrier; @@ -654,168 +701,198 @@ template struct Barrier; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() {} - static void beforeStore() {} + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} }; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() { _ReadWriteBarrier(); } - static void beforeStore() { _ReadWriteBarrier(); } + static void beforeLoad() {} + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } }; template<> struct Barrier { - static void beforeLoad() { _ReadWriteBarrier(); } - static void afterLoad() { _ReadWriteBarrier(); } - static void beforeStore() { _ReadWriteBarrier(); } + static void beforeLoad() { _ReadWriteBarrier(); } + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } }; template struct CastHelper { - static PrimType toPrimType(T val) { return static_cast(val); } - static T fromPrimType(PrimType val) { return static_cast(val); } + static PrimType toPrimType(T aVal) { return static_cast(aVal); } + static T fromPrimType(PrimType aVal) { return static_cast(aVal); } }; template struct CastHelper { - static PrimType toPrimType(T* val) { return reinterpret_cast(val); } - static T* fromPrimType(PrimType val) { return reinterpret_cast(val); } + static PrimType toPrimType(T* aVal) { return reinterpret_cast(aVal); } + static T* fromPrimType(PrimType aVal) { return reinterpret_cast(aVal); } }; template struct IntrinsicBase { - typedef T ValueType; - typedef PrimitiveIntrinsics Primitives; - typedef typename Primitives::Type PrimType; - static_assert(sizeof(PrimType) == sizeof(T), - "Selection of PrimitiveIntrinsics was wrong"); - typedef CastHelper Cast; + typedef T ValueType; + typedef PrimitiveIntrinsics Primitives; + typedef typename Primitives::Type PrimType; + static_assert(sizeof(PrimType) == sizeof(T), + "Selection of PrimitiveIntrinsics was wrong"); + typedef CastHelper Cast; }; template struct IntrinsicMemoryOps : public IntrinsicBase { - typedef typename IntrinsicBase::ValueType ValueType; - typedef typename IntrinsicBase::Primitives Primitives; - typedef typename IntrinsicBase::PrimType PrimType; - typedef typename IntrinsicBase::Cast Cast; - static ValueType load(const ValueType& ptr) { - Barrier::beforeLoad(); - ValueType val = ptr; - Barrier::afterLoad(); - return val; - } - static void store(ValueType& ptr, ValueType val) { - // For SequentiallyConsistent, Primitives::store() will generate the - // proper memory fence. Everything else just needs a barrier before - // the store. - if (Order == SequentiallyConsistent) { - Primitives::store(reinterpret_cast(&ptr), - Cast::toPrimType(val)); - } else { - Barrier::beforeStore(); - ptr = val; - } - } - static ValueType exchange(ValueType& ptr, ValueType val) { - PrimType oldval = - Primitives::exchange(reinterpret_cast(&ptr), - Cast::toPrimType(val)); - return Cast::fromPrimType(oldval); - } - static bool compareExchange(ValueType& ptr, ValueType oldVal, ValueType newVal) { - return Primitives::compareExchange(reinterpret_cast(&ptr), - Cast::toPrimType(oldVal), - Cast::toPrimType(newVal)); + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + + static ValueType load(const ValueType& aPtr) + { + Barrier::beforeLoad(); + ValueType val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(ValueType& aPtr, ValueType aVal) + { + // For SequentiallyConsistent, Primitives::store() will generate the + // proper memory fence. Everything else just needs a barrier before + // the store. + if (Order == SequentiallyConsistent) { + Primitives::store(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + } else { + Barrier::beforeStore(); + aPtr = aVal; } + } + + static ValueType exchange(ValueType& aPtr, ValueType aVal) + { + PrimType oldval = + Primitives::exchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + return Cast::fromPrimType(oldval); + } + + static bool compareExchange(ValueType& aPtr, ValueType aOldVal, + ValueType aNewVal) + { + return Primitives::compareExchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aOldVal), + Cast::toPrimType(aNewVal)); + } }; template struct IntrinsicApplyHelper : public IntrinsicBase { - typedef typename IntrinsicBase::ValueType ValueType; - typedef typename IntrinsicBase::PrimType PrimType; - typedef typename IntrinsicBase::Cast Cast; - typedef PrimType (*BinaryOp)(PrimType*, PrimType); - typedef PrimType (*UnaryOp)(PrimType*); - - static ValueType applyBinaryFunction(BinaryOp op, ValueType& ptr, - ValueType val) { - PrimType* primTypePtr = reinterpret_cast(&ptr); - PrimType primTypeVal = Cast::toPrimType(val); - return Cast::fromPrimType(op(primTypePtr, primTypeVal)); - } - - static ValueType applyUnaryFunction(UnaryOp op, ValueType& ptr) { - PrimType* primTypePtr = reinterpret_cast(&ptr); - return Cast::fromPrimType(op(primTypePtr)); - } + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + typedef PrimType (*BinaryOp)(PrimType*, PrimType); + typedef PrimType (*UnaryOp)(PrimType*); + + static ValueType applyBinaryFunction(BinaryOp aOp, ValueType& aPtr, + ValueType aVal) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + PrimType primTypeVal = Cast::toPrimType(aVal); + return Cast::fromPrimType(aOp(primTypePtr, primTypeVal)); + } + + static ValueType applyUnaryFunction(UnaryOp aOp, ValueType& aPtr) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + return Cast::fromPrimType(aOp(primTypePtr)); + } }; template struct IntrinsicAddSub : public IntrinsicApplyHelper { - typedef typename IntrinsicApplyHelper::ValueType ValueType; - typedef typename IntrinsicBase::Primitives Primitives; - static ValueType add(ValueType& ptr, ValueType val) { - return applyBinaryFunction(&Primitives::add, ptr, val); - } - static ValueType sub(ValueType& ptr, ValueType val) { - return applyBinaryFunction(&Primitives::sub, ptr, val); - } + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::add, aPtr, aVal); + } + + static ValueType sub(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::sub, aPtr, aVal); + } }; template struct IntrinsicAddSub : public IntrinsicApplyHelper { - typedef typename IntrinsicApplyHelper::ValueType ValueType; - static ValueType add(ValueType& ptr, ptrdiff_t amount) { - return applyBinaryFunction(&Primitives::add, ptr, - (ValueType)(amount * sizeof(ValueType))); - } - static ValueType sub(ValueType& ptr, ptrdiff_t amount) { - return applyBinaryFunction(&Primitives::sub, ptr, - (ValueType)(amount * sizeof(ValueType))); - } + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::add, aPtr, + (ValueType)(aAmount * sizeof(T))); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::sub, aPtr, + (ValueType)(aAmount * sizeof(T))); + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - typedef typename IntrinsicAddSub::ValueType ValueType; - static ValueType inc(ValueType& ptr) { return add(ptr, 1); } - static ValueType dec(ValueType& ptr) { return sub(ptr, 1); } + typedef typename IntrinsicAddSub::ValueType ValueType; + static ValueType inc(ValueType& aPtr) { return add(aPtr, 1); } + static ValueType dec(ValueType& aPtr) { return sub(aPtr, 1); } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef typename IntrinsicIncDec::ValueType ValueType; - static ValueType or_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::or_, ptr, val); - } - static ValueType xor_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::xor_, ptr, val); - } - static ValueType and_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::and_, ptr, val); - } + typedef typename IntrinsicIncDec::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType or_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::or_, aPtr, aVal); + } + + static ValueType xor_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::xor_, aPtr, aVal); + } + + static ValueType and_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::and_, aPtr, aVal); + } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef typename IntrinsicMemoryOps::ValueType ValueType; + typedef typename IntrinsicMemoryOps::ValueType ValueType; + // This is required to make us be able to build with MSVC10, for unknown + // reasons. + typedef typename IntrinsicBase::Primitives Primitives; }; } // namespace detail @@ -832,73 +909,80 @@ namespace detail { template class AtomicBase { - // We only support 32-bit types on 32-bit Windows, which constrains our - // implementation elsewhere. But we support pointer-sized types everywhere. - static_assert(sizeof(T) == 4 || (sizeof(uintptr_t) == 8 && sizeof(T) == 8), - "mozilla/Atomics.h only supports 32-bit and pointer-sized types"); - - protected: - typedef typename detail::AtomicIntrinsics Intrinsics; - typename Intrinsics::ValueType mValue; - - public: - MOZ_CONSTEXPR AtomicBase() : mValue() {} - MOZ_CONSTEXPR AtomicBase(T aInit) : mValue(aInit) {} - - operator T() const { return Intrinsics::load(mValue); } - - T operator=(T aValue) { - Intrinsics::store(mValue, aValue); - return aValue; - } - - /** - * Performs an atomic swap operation. aValue is stored and the previous - * value of this variable is returned. - */ - T exchange(T aValue) { - return Intrinsics::exchange(mValue, aValue); - } - - /** - * Performs an atomic compare-and-swap operation and returns true if it - * succeeded. This is equivalent to atomically doing - * - * if (mValue == aOldValue) { - * mValue = aNewValue; - * return true; - * } else { - * return false; - * } - */ - bool compareExchange(T aOldValue, T aNewValue) { - return Intrinsics::compareExchange(mValue, aOldValue, aNewValue); - } - - private: - template - AtomicBase(const AtomicBase& aCopy) MOZ_DELETE; + // We only support 32-bit types on 32-bit Windows, which constrains our + // implementation elsewhere. But we support pointer-sized types everywhere. + static_assert(sizeof(T) == 4 || (sizeof(uintptr_t) == 8 && sizeof(T) == 8), + "mozilla/Atomics.h only supports 32-bit and pointer-sized types"); + +protected: + typedef typename detail::AtomicIntrinsics Intrinsics; + typename Intrinsics::ValueType mValue; + +public: + MOZ_CONSTEXPR AtomicBase() : mValue() {} + explicit MOZ_CONSTEXPR AtomicBase(T aInit) : mValue(aInit) {} + + // Note: we can't provide operator T() here because Atomic inherits + // from AtomcBase with T=uint32_t and not T=bool. If we implemented + // operator T() here, it would cause errors when comparing Atomic with + // a regular bool. + + T operator=(T aVal) + { + Intrinsics::store(mValue, aVal); + return aVal; + } + + /** + * Performs an atomic swap operation. aVal is stored and the previous + * value of this variable is returned. + */ + T exchange(T aVal) + { + return Intrinsics::exchange(mValue, aVal); + } + + /** + * Performs an atomic compare-and-swap operation and returns true if it + * succeeded. This is equivalent to atomically doing + * + * if (mValue == aOldValue) { + * mValue = aNewValue; + * return true; + * } else { + * return false; + * } + */ + bool compareExchange(T aOldValue, T aNewValue) + { + return Intrinsics::compareExchange(mValue, aOldValue, aNewValue); + } + +private: + template + AtomicBase(const AtomicBase& aCopy) MOZ_DELETE; }; template class AtomicBaseIncDec : public AtomicBase { - typedef typename detail::AtomicBase Base; + typedef typename detail::AtomicBase Base; - public: - MOZ_CONSTEXPR AtomicBaseIncDec() : Base() {} - MOZ_CONSTEXPR AtomicBaseIncDec(T aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR AtomicBaseIncDec() : Base() {} + explicit MOZ_CONSTEXPR AtomicBaseIncDec(T aInit) : Base(aInit) {} - using Base::operator=; + using Base::operator=; - T operator++(int) { return Base::Intrinsics::inc(Base::mValue); } - T operator--(int) { return Base::Intrinsics::dec(Base::mValue); } - T operator++() { return Base::Intrinsics::inc(Base::mValue) + 1; } - T operator--() { return Base::Intrinsics::dec(Base::mValue) - 1; } + operator T() const { return Base::Intrinsics::load(Base::mValue); } + T operator++(int) { return Base::Intrinsics::inc(Base::mValue); } + T operator--(int) { return Base::Intrinsics::dec(Base::mValue); } + T operator++() { return Base::Intrinsics::inc(Base::mValue) + 1; } + T operator--() { return Base::Intrinsics::dec(Base::mValue) - 1; } - private: - template - AtomicBaseIncDec(const AtomicBaseIncDec& aCopy) MOZ_DELETE; +private: + template + AtomicBaseIncDec(const AtomicBaseIncDec& aCopy) MOZ_DELETE; }; } // namespace detail @@ -934,25 +1018,45 @@ class Atomic; * swap method is provided. */ template -class Atomic::value>::Type> +class Atomic::value && + !IsSame::value>::Type> : public detail::AtomicBaseIncDec { - typedef typename detail::AtomicBaseIncDec Base; + typedef typename detail::AtomicBaseIncDec Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + + using Base::operator=; + + T operator+=(T aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + T operator-=(T aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } - using Base::operator=; + T operator|=(T aVal) + { + return Base::Intrinsics::or_(Base::mValue, aVal) | aVal; + } - T operator+=(T delta) { return Base::Intrinsics::add(Base::mValue, delta) + delta; } - T operator-=(T delta) { return Base::Intrinsics::sub(Base::mValue, delta) - delta; } - T operator|=(T val) { return Base::Intrinsics::or_(Base::mValue, val) | val; } - T operator^=(T val) { return Base::Intrinsics::xor_(Base::mValue, val) ^ val; } - T operator&=(T val) { return Base::Intrinsics::and_(Base::mValue, val) & val; } + T operator^=(T aVal) + { + return Base::Intrinsics::xor_(Base::mValue, aVal) ^ aVal; + } - private: - Atomic(Atomic& aOther) MOZ_DELETE; + T operator&=(T aVal) + { + return Base::Intrinsics::and_(Base::mValue, aVal) & aVal; + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; /** @@ -966,23 +1070,26 @@ class Atomic::value>::Type> template class Atomic : public detail::AtomicBaseIncDec { - typedef typename detail::AtomicBaseIncDec Base; + typedef typename detail::AtomicBaseIncDec Base; - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T* aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T* aInit) : Base(aInit) {} - using Base::operator=; + using Base::operator=; - T* operator+=(ptrdiff_t delta) { - return Base::Intrinsics::add(Base::mValue, delta) + delta; - } - T* operator-=(ptrdiff_t delta) { - return Base::Intrinsics::sub(Base::mValue, delta) - delta; - } + T* operator+=(ptrdiff_t aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } + + T* operator-=(ptrdiff_t aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } - private: - Atomic(Atomic& aOther) MOZ_DELETE; +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; /** @@ -994,16 +1101,69 @@ template class Atomic::value>::Type> : public detail::AtomicBase { - typedef typename detail::AtomicBase Base; + typedef typename detail::AtomicBase Base; - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} - using Base::operator=; + operator T() const { return Base::Intrinsics::load(Base::mValue); } - private: - Atomic(Atomic& aOther) MOZ_DELETE; + using Base::operator=; + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +/** + * Atomic implementation for boolean types. + * + * The atomic store and load operations and the atomic swap method is provided. + * + * Note: + * + * - sizeof(Atomic) != sizeof(bool) for some implementations of + * bool and/or some implementations of std::atomic. This is allowed in + * [atomic.types.generic]p9. + * + * - It's not obvious whether the 8-bit atomic functions on Windows are always + * inlined or not. If they are not inlined, the corresponding functions in the + * runtime library are not available on Windows XP. This is why we implement + * Atomic with an underlying type of uint32_t. + */ +template +class Atomic + : protected detail::AtomicBase +{ + typedef typename detail::AtomicBase Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(bool aInit) : Base(aInit) {} + + // We provide boolean wrappers for the underlying AtomicBase methods. + operator bool() const + { + return Base::Intrinsics::load(Base::mValue); + } + + bool operator=(bool aVal) + { + return Base::operator=(aVal); + } + + bool exchange(bool aVal) + { + return Base::exchange(aVal); + } + + bool compareExchange(bool aOldValue, bool aNewValue) + { + return Base::compareExchange(aOldValue, aNewValue); + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Attributes.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Attributes.h index 671f30cded..cdce8c7717 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Attributes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Attributes.h @@ -37,6 +37,7 @@ # define MOZ_ALWAYS_INLINE inline #endif +#if defined(_MSC_VER) /* * g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality * without warnings (functionality used by the macros below). These modes are @@ -44,8 +45,27 @@ * standardly, by checking whether __cplusplus has a C++11 or greater value. * Current versions of g++ do not correctly set __cplusplus, so we check both * for forward compatibility. + * + * Even though some versions of MSVC support explicit conversion operators, we + * don't indicate support for them here, due to + * http://stackoverflow.com/questions/20498142/visual-studio-2013-explicit-keyword-bug */ -#if defined(__clang__) +# if _MSC_VER >= 1800 +# define MOZ_HAVE_CXX11_DELETE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_FINAL final +# else +# if defined(__clang__) +# error Please do not try to use clang-cl with MSVC10 or below emulation! +# endif + /* MSVC <= 10 used to spell "final" as "sealed". */ +# define MOZ_HAVE_CXX11_FINAL sealed +# endif +# define MOZ_HAVE_CXX11_OVERRIDE +# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) +# define MOZ_HAVE_NORETURN __declspec(noreturn) +#elif defined(__clang__) /* * Per Clang documentation, "Note that marketing version numbers should not * be used to check for language features, as different vendors use different @@ -57,6 +77,9 @@ # if __has_extension(cxx_constexpr) # define MOZ_HAVE_CXX11_CONSTEXPR # endif +# if __has_extension(cxx_explicit_conversions) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif # if __has_extension(cxx_deleted_functions) # define MOZ_HAVE_CXX11_DELETE # endif @@ -79,6 +102,9 @@ # if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) # define MOZ_HAVE_CXX11_CONSTEXPR # endif +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif # define MOZ_HAVE_CXX11_DELETE # else /* __final is a non-C++11 GCC synonym for 'final', per GCC r176655. */ @@ -88,19 +114,16 @@ # endif # define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) # define MOZ_HAVE_NORETURN __attribute__((noreturn)) -#elif defined(_MSC_VER) -# if _MSC_VER >= 1800 -# define MOZ_HAVE_CXX11_DELETE -# endif -# if _MSC_VER >= 1700 -# define MOZ_HAVE_CXX11_FINAL final -# else - /* MSVC <= 10 used to spell "final" as "sealed". */ -# define MOZ_HAVE_CXX11_FINAL sealed +#endif + +/* + * When built with clang analyzer (a.k.a scan-build), define MOZ_HAVE_NORETURN + * to mark some false positives + */ +#ifdef __clang_analyzer__ +# if __has_extension(attribute_analyzer_noreturn) +# define MOZ_HAVE_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) # endif -# define MOZ_HAVE_CXX11_OVERRIDE -# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) -# define MOZ_HAVE_NORETURN __declspec(noreturn) #endif /* @@ -121,6 +144,31 @@ # define MOZ_CONSTEXPR_VAR const #endif +/* + * MOZ_EXPLICIT_CONVERSION is a specifier on a type conversion + * overloaded operator that declares that a C++11 compiler should restrict + * this operator to allow only explicit type conversions, disallowing + * implicit conversions. + * + * Example: + * + * template + * class Ptr + * { + * T* mPtr; + * MOZ_EXPLICIT_CONVERSION operator bool() const + * { + * return mPtr != nullptr; + * } + * }; + * + */ +#ifdef MOZ_HAVE_EXPLICIT_CONVERSION +# define MOZ_EXPLICIT_CONVERSION explicit +#else +# define MOZ_EXPLICIT_CONVERSION /* no support */ +#endif + /* * MOZ_NEVER_INLINE is a macro which expands to tell the compiler that the * method decorated with it must never be inlined, even if the compiler would @@ -153,18 +201,47 @@ # define MOZ_NORETURN /* no support */ #endif +/* + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS, specified at the end of a function + * declaration, indicates that for the purposes of static analysis, this + * function does not return. (The function definition does not need to be + * annotated.) + * + * MOZ_ReportCrash(const char* s, const char* file, int ln) + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS + * + * Some static analyzers, like scan-build from clang, can use this information + * to eliminate false positives. From the upstream documentation of scan-build: + * "This attribute is useful for annotating assertion handlers that actually + * can return, but for the purpose of using the analyzer we want to pretend + * that such functions do not return." + * + */ +#if defined(MOZ_HAVE_ANALYZER_NORETURN) +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS MOZ_HAVE_ANALYZER_NORETURN +#else +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS /* no support */ +#endif + /* * MOZ_ASAN_BLACKLIST is a macro to tell AddressSanitizer (a compile-time - * instrumentation shipped with Clang) to not instrument the annotated function. - * Furthermore, it will prevent the compiler from inlining the function because - * inlining currently breaks the blacklisting mechanism of AddressSanitizer. + * instrumentation shipped with Clang and GCC) to not instrument the annotated + * function. Furthermore, it will prevent the compiler from inlining the + * function because inlining currently breaks the blacklisting mechanism of + * AddressSanitizer. */ #if defined(__has_feature) # if __has_feature(address_sanitizer) -# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) -# else -# define MOZ_ASAN_BLACKLIST /* nothing */ +# define MOZ_HAVE_ASAN_BLACKLIST # endif +#elif defined(__GNUC__) +# if defined(__SANITIZE_ADDRESS__) +# define MOZ_HAVE_ASAN_BLACKLIST +# endif +#endif + +#if defined(MOZ_HAVE_ASAN_BLACKLIST) +# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) #else # define MOZ_ASAN_BLACKLIST /* nothing */ #endif @@ -197,9 +274,9 @@ * * struct NonCopyable * { - * private: - * NonCopyable(const NonCopyable& other) MOZ_DELETE; - * void operator=(const NonCopyable& other) MOZ_DELETE; + * private: + * NonCopyable(const NonCopyable& aOther) MOZ_DELETE; + * void operator=(const NonCopyable& aOther) MOZ_DELETE; * }; * * If MOZ_DELETE can't be implemented for the current compiler, use of the @@ -225,23 +302,23 @@ * * class Base * { - * public: - * virtual void f() = 0; + * public: + * virtual void f() = 0; * }; * class Derived1 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE; + * public: + * virtual void f() MOZ_OVERRIDE; * }; * class Derived2 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE = 0; + * public: + * virtual void f() MOZ_OVERRIDE = 0; * }; * class Derived3 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE { } + * public: + * virtual void f() MOZ_OVERRIDE { } * }; * * In compilers supporting C++11 override controls, MOZ_OVERRIDE *requires* that @@ -269,16 +346,16 @@ * * class Base MOZ_FINAL * { - * public: - * Base(); - * ~Base(); - * virtual void f() { } + * public: + * Base(); + * ~Base(); + * virtual void f() { } * }; * // This will be an error in some compilers: * class Derived : public Base * { - * public: - * ~Derived() { } + * public: + * ~Derived() { } * }; * * One particularly common reason to specify MOZ_FINAL upon a class is to tell @@ -305,14 +382,14 @@ * * class Base * { - * public: - * virtual void f() MOZ_FINAL; + * public: + * virtual void f() MOZ_FINAL; * }; * class Derived * { - * public: - * // This will be an error in some compilers: - * virtual void f(); + * public: + * // This will be an error in some compilers: + * virtual void f(); * }; * * In compilers implementing final controls, it is an error for a derived class @@ -372,13 +449,13 @@ * * typedef int MOZ_TYPE_ATTRIBUTE MagicInt; * int MOZ_TYPE_ATTRIBUTE someVariable; - * int * MOZ_TYPE_ATTRIBUTE magicPtrInt; - * int MOZ_TYPE_ATTRIBUTE * ptrToMagicInt; + * int* MOZ_TYPE_ATTRIBUTE magicPtrInt; + * int MOZ_TYPE_ATTRIBUTE* ptrToMagicInt; * * Attributes that apply to statements precede the statement: * * MOZ_IF_ATTRIBUTE if (x == 0) - * MOZ_DO_ATTRIBUTE do { } while(0); + * MOZ_DO_ATTRIBUTE do { } while (0); * * Attributes that apply to labels precede the label: * @@ -412,11 +489,16 @@ * MOZ_HEAP_ALLOCATOR: Applies to any function. This indicates that the return * value is allocated on the heap, and will as a result check such allocations * during MOZ_STACK_CLASS and MOZ_NONHEAP_CLASS annotation checking. + * MOZ_IMPLICIT: Applies to constructors. Implicit conversion constructors + * are disallowed by default unless they are marked as MOZ_IMPLICIT. This + * attribute must be used for constructors which intend to provide implicit + * conversions. */ #ifdef MOZ_CLANG_PLUGIN # define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override"))) # define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class"))) # define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class"))) +# define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) /* * It turns out that clang doesn't like void func() __attribute__ {} without a * warning, so use pragmas to disable the warning. This code won't work on GCC @@ -431,6 +513,7 @@ # define MOZ_MUST_OVERRIDE /* nothing */ # define MOZ_STACK_CLASS /* nothing */ # define MOZ_NONHEAP_CLASS /* nothing */ +# define MOZ_IMPLICIT /* nothing */ # define MOZ_HEAP_ALLOCATOR /* nothing */ #endif /* MOZ_CLANG_PLUGIN */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/BinarySearch.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/BinarySearch.h new file mode 100644 index 0000000000..c8f593d6a9 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/BinarySearch.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_BinarySearch_h +#define mozilla_BinarySearch_h + +#include "mozilla/Assertions.h" + +#include + +namespace mozilla { + +/* + * The algorithm searches the given container |aContainer| over the sorted + * index range [aBegin, aEnd) for an index |i| where |aContainer[i] == aTarget|. + * If such an index |i| is found, BinarySearch returns |true| and the index is + * returned via the outparam |aMatchOrInsertionPoint|. If no index is found, + * BinarySearch returns |false| and the outparam returns the first index in + * [aBegin, aEnd] where |aTarget| can be inserted to maintain sorted order. + * + * Example: + * + * Vector sortedInts = ... + * + * size_t match; + * if (BinarySearch(sortedInts, 0, sortedInts.length(), 13, &match)) { + * printf("found 13 at %lu\n", match); + * } + */ + +template +bool +BinarySearch(const Container& aContainer, size_t aBegin, size_t aEnd, + T aTarget, size_t* aMatchOrInsertionPoint) +{ + MOZ_ASSERT(aBegin <= aEnd); + + size_t low = aBegin; + size_t high = aEnd; + while (low != high) { + size_t middle = low + (high - low) / 2; + + // Allow any intermediate type so long as it provides a suitable ordering + // relation. + const auto& middleValue = aContainer[middle]; + + MOZ_ASSERT(aContainer[low] <= aContainer[middle]); + MOZ_ASSERT(aContainer[middle] <= aContainer[high - 1]); + MOZ_ASSERT(aContainer[low] <= aContainer[high - 1]); + + if (aTarget == middleValue) { + *aMatchOrInsertionPoint = middle; + return true; + } + + if (aTarget < middleValue) { + high = middle; + } else { + low = middle + 1; + } + } + + *aMatchOrInsertionPoint = low; + return false; +} + +} // namespace mozilla + +#endif // mozilla_BinarySearch_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/BloomFilter.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/BloomFilter.h index 8129c489d4..6757e41181 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/BloomFilter.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/BloomFilter.h @@ -55,177 +55,199 @@ namespace mozilla { template class BloomFilter { - /* - * A counting Bloom filter with 8-bit counters. For now we assume - * that having two hash functions is enough, but we may revisit that - * decision later. - * - * The filter uses an array with 2**KeySize entries. - * - * Assuming a well-distributed hash function, a Bloom filter with - * array size M containing N elements and - * using k hash function has expected false positive rate exactly - * - * $ (1 - (1 - 1/M)^{kN})^k $ - * - * because each array slot has a - * - * $ (1 - 1/M)^{kN} $ - * - * chance of being 0, and the expected false positive rate is the - * probability that all of the k hash functions will hit a nonzero - * slot. - * - * For reasonable assumptions (M large, kN large, which should both - * hold if we're worried about false positives) about M and kN this - * becomes approximately - * - * $$ (1 - \exp(-kN/M))^k $$ - * - * For our special case of k == 2, that's $(1 - \exp(-2N/M))^2$, - * or in other words - * - * $$ N/M = -0.5 * \ln(1 - \sqrt(r)) $$ - * - * where r is the false positive rate. This can be used to compute - * the desired KeySize for a given load N and false positive rate r. - * - * If N/M is assumed small, then the false positive rate can - * further be approximated as 4*N^2/M^2. So increasing KeySize by - * 1, which doubles M, reduces the false positive rate by about a - * factor of 4, and a false positive rate of 1% corresponds to - * about M/N == 20. - * - * What this means in practice is that for a few hundred keys using a - * KeySize of 12 gives false positive rates on the order of 0.25-4%. - * - * Similarly, using a KeySize of 10 would lead to a 4% false - * positive rate for N == 100 and to quite bad false positive - * rates for larger N. - */ - public: - BloomFilter() { - static_assert(KeySize <= keyShift, "KeySize too big"); - - // Should we have a custom operator new using calloc instead and - // require that we're allocated via the operator? - clear(); - } - - /* - * Clear the filter. This should be done before reusing it, because - * just removing all items doesn't clear counters that hit the upper - * bound. - */ - void clear(); - - /* - * Add an item to the filter. - */ - void add(const T* t); - - /* - * Remove an item from the filter. - */ - void remove(const T* t); - - /* - * Check whether the filter might contain an item. This can - * sometimes return true even if the item is not in the filter, - * but will never return false for items that are actually in the - * filter. - */ - bool mightContain(const T* t) const; - - /* - * Methods for add/remove/contain when we already have a hash computed - */ - void add(uint32_t hash); - void remove(uint32_t hash); - bool mightContain(uint32_t hash) const; - - private: - static const size_t arraySize = (1 << KeySize); - static const uint32_t keyMask = (1 << KeySize) - 1; - static const uint32_t keyShift = 16; - - static uint32_t hash1(uint32_t hash) { return hash & keyMask; } - static uint32_t hash2(uint32_t hash) { return (hash >> keyShift) & keyMask; } - - uint8_t& firstSlot(uint32_t hash) { return counters[hash1(hash)]; } - uint8_t& secondSlot(uint32_t hash) { return counters[hash2(hash)]; } - const uint8_t& firstSlot(uint32_t hash) const { return counters[hash1(hash)]; } - const uint8_t& secondSlot(uint32_t hash) const { return counters[hash2(hash)]; } - - static bool full(const uint8_t& slot) { return slot == UINT8_MAX; } - - uint8_t counters[arraySize]; + /* + * A counting Bloom filter with 8-bit counters. For now we assume + * that having two hash functions is enough, but we may revisit that + * decision later. + * + * The filter uses an array with 2**KeySize entries. + * + * Assuming a well-distributed hash function, a Bloom filter with + * array size M containing N elements and + * using k hash function has expected false positive rate exactly + * + * $ (1 - (1 - 1/M)^{kN})^k $ + * + * because each array slot has a + * + * $ (1 - 1/M)^{kN} $ + * + * chance of being 0, and the expected false positive rate is the + * probability that all of the k hash functions will hit a nonzero + * slot. + * + * For reasonable assumptions (M large, kN large, which should both + * hold if we're worried about false positives) about M and kN this + * becomes approximately + * + * $$ (1 - \exp(-kN/M))^k $$ + * + * For our special case of k == 2, that's $(1 - \exp(-2N/M))^2$, + * or in other words + * + * $$ N/M = -0.5 * \ln(1 - \sqrt(r)) $$ + * + * where r is the false positive rate. This can be used to compute + * the desired KeySize for a given load N and false positive rate r. + * + * If N/M is assumed small, then the false positive rate can + * further be approximated as 4*N^2/M^2. So increasing KeySize by + * 1, which doubles M, reduces the false positive rate by about a + * factor of 4, and a false positive rate of 1% corresponds to + * about M/N == 20. + * + * What this means in practice is that for a few hundred keys using a + * KeySize of 12 gives false positive rates on the order of 0.25-4%. + * + * Similarly, using a KeySize of 10 would lead to a 4% false + * positive rate for N == 100 and to quite bad false positive + * rates for larger N. + */ +public: + BloomFilter() + { + static_assert(KeySize <= kKeyShift, "KeySize too big"); + + // Should we have a custom operator new using calloc instead and + // require that we're allocated via the operator? + clear(); + } + + /* + * Clear the filter. This should be done before reusing it, because + * just removing all items doesn't clear counters that hit the upper + * bound. + */ + void clear(); + + /* + * Add an item to the filter. + */ + void add(const T* aValue); + + /* + * Remove an item from the filter. + */ + void remove(const T* aValue); + + /* + * Check whether the filter might contain an item. This can + * sometimes return true even if the item is not in the filter, + * but will never return false for items that are actually in the + * filter. + */ + bool mightContain(const T* aValue) const; + + /* + * Methods for add/remove/contain when we already have a hash computed + */ + void add(uint32_t aHash); + void remove(uint32_t aHash); + bool mightContain(uint32_t aHash) const; + +private: + static const size_t kArraySize = (1 << KeySize); + static const uint32_t kKeyMask = (1 << KeySize) - 1; + static const uint32_t kKeyShift = 16; + + static uint32_t hash1(uint32_t aHash) + { + return aHash & kKeyMask; + } + static uint32_t hash2(uint32_t aHash) + { + return (aHash >> kKeyShift) & kKeyMask; + } + + uint8_t& firstSlot(uint32_t aHash) + { + return mCounters[hash1(aHash)]; + } + uint8_t& secondSlot(uint32_t aHash) + { + return mCounters[hash2(aHash)]; + } + + const uint8_t& firstSlot(uint32_t aHash) const + { + return mCounters[hash1(aHash)]; + } + const uint8_t& secondSlot(uint32_t aHash) const + { + return mCounters[hash2(aHash)]; + } + + static bool full(const uint8_t& aSlot) { return aSlot == UINT8_MAX; } + + uint8_t mCounters[kArraySize]; }; template inline void BloomFilter::clear() { - memset(counters, 0, arraySize); + memset(mCounters, 0, kArraySize); } template inline void -BloomFilter::add(uint32_t hash) +BloomFilter::add(uint32_t aHash) { - uint8_t& slot1 = firstSlot(hash); - if (MOZ_LIKELY(!full(slot1))) + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { ++slot1; - - uint8_t& slot2 = secondSlot(hash); - if (MOZ_LIKELY(!full(slot2))) + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { ++slot2; + } } template MOZ_ALWAYS_INLINE void -BloomFilter::add(const T* t) +BloomFilter::add(const T* aValue) { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); return add(hash); } template inline void -BloomFilter::remove(uint32_t hash) +BloomFilter::remove(uint32_t aHash) { // If the slots are full, we don't know whether we bumped them to be // there when we added or not, so just leave them full. - uint8_t& slot1 = firstSlot(hash); - if (MOZ_LIKELY(!full(slot1))) + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { --slot1; - - uint8_t& slot2 = secondSlot(hash); - if (MOZ_LIKELY(!full(slot2))) + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { --slot2; + } } template MOZ_ALWAYS_INLINE void -BloomFilter::remove(const T* t) +BloomFilter::remove(const T* aValue) { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); remove(hash); } template MOZ_ALWAYS_INLINE bool -BloomFilter::mightContain(uint32_t hash) const +BloomFilter::mightContain(uint32_t aHash) const { // Check that all the slots for this hash contain something - return firstSlot(hash) && secondSlot(hash); + return firstSlot(aHash) && secondSlot(aHash); } template MOZ_ALWAYS_INLINE bool -BloomFilter::mightContain(const T* t) const +BloomFilter::mightContain(const T* aValue) const { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); return mightContain(hash); } diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Casting.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Casting.h index 76df0ef27e..dc449af6b6 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Casting.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Casting.h @@ -17,7 +17,8 @@ namespace mozilla { /** - * Return a value of type |To|, containing the underlying bit pattern of |from|. + * Return a value of type |To|, containing the underlying bit pattern of + * |aFrom|. * * |To| and |From| must be types of the same size; be careful of cross-platform * size differences, or this might fail to compile on some but not all @@ -25,16 +26,17 @@ namespace mozilla { */ template inline To -BitwiseCast(const From from) +BitwiseCast(const From aFrom) { static_assert(sizeof(From) == sizeof(To), "To and From must have the same size"); - union { - From from; - To to; + union + { + From mFrom; + To mTo; } u; - u.from = from; - return u.to; + u.mFrom = aFrom; + return u.mTo; } namespace detail { @@ -58,34 +60,39 @@ enum UUComparison { FromIsBigger, FromIsNotBigger }; // Unsigned-to-unsigned range check template sizeof(To)) ? FromIsBigger : FromIsNotBigger> + UUComparison = (sizeof(From) > sizeof(To)) + ? FromIsBigger + : FromIsNotBigger> struct UnsignedUnsignedCheck; template struct UnsignedUnsignedCheck { - public: - static bool checkBounds(const From from) { - return from <= From(To(-1)); - } +public: + static bool checkBounds(const From aFrom) + { + return aFrom <= From(To(-1)); + } }; template struct UnsignedUnsignedCheck { - public: - static bool checkBounds(const From from) { - return true; - } +public: + static bool checkBounds(const From aFrom) + { + return true; + } }; template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - return UnsignedUnsignedCheck::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return UnsignedUnsignedCheck::checkBounds(aFrom); + } }; // Signed-to-unsigned range check @@ -93,14 +100,17 @@ struct BoundsCheckImpl template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - if (from < 0) - return false; - if (sizeof(To) >= sizeof(From)) - return true; - return from <= From(To(-1)); +public: + static bool checkBounds(const From aFrom) + { + if (aFrom < 0) { + return false; + } + if (sizeof(To) >= sizeof(From)) { + return true; } + return aFrom <= From(To(-1)); + } }; // Unsigned-to-signed range check @@ -108,35 +118,40 @@ struct BoundsCheckImpl enum USComparison { FromIsSmaller, FromIsNotSmaller }; template + USComparison = (sizeof(From) < sizeof(To)) + ? FromIsSmaller + : FromIsNotSmaller> struct UnsignedSignedCheck; template struct UnsignedSignedCheck { - public: - static bool checkBounds(const From from) { - return true; - } +public: + static bool checkBounds(const From aFrom) + { + return true; + } }; template struct UnsignedSignedCheck { - public: - static bool checkBounds(const From from) { - const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); - return from <= From(MaxValue); - } +public: + static bool checkBounds(const From aFrom) + { + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + return aFrom <= From(MaxValue); + } }; template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - return UnsignedSignedCheck::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return UnsignedSignedCheck::checkBounds(aFrom); + } }; // Signed-to-signed range check @@ -144,42 +159,46 @@ struct BoundsCheckImpl template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - if (sizeof(From) <= sizeof(To)) - return true; - const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); - const To MinValue = -MaxValue - To(1); - return From(MinValue) <= from && - From(from) <= From(MaxValue); +public: + static bool checkBounds(const From aFrom) + { + if (sizeof(From) <= sizeof(To)) { + return true; } + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + const To MinValue = -MaxValue - To(1); + return From(MinValue) <= aFrom && + From(aFrom) <= From(MaxValue); + } }; template::value && IsIntegral::value> + bool TypesAreIntegral = IsIntegral::value && + IsIntegral::value> class BoundsChecker; template class BoundsChecker { - public: - static bool checkBounds(const From from) { return true; } +public: + static bool checkBounds(const From aFrom) { return true; } }; template class BoundsChecker { - public: - static bool checkBounds(const From from) { - return BoundsCheckImpl::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return BoundsCheckImpl::checkBounds(aFrom); + } }; template inline bool -IsInBounds(const From from) +IsInBounds(const From aFrom) { - return BoundsChecker::checkBounds(from); + return BoundsChecker::checkBounds(aFrom); } } // namespace detail @@ -191,10 +210,10 @@ IsInBounds(const From from) */ template inline To -SafeCast(const From from) +SafeCast(const From aFrom) { - MOZ_ASSERT((detail::IsInBounds(from))); - return static_cast(from); + MOZ_ASSERT((detail::IsInBounds(aFrom))); + return static_cast(aFrom); } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ChaosMode.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ChaosMode.h new file mode 100644 index 0000000000..ff59f2c6ec --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ChaosMode.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_ChaosMode_h +#define mozilla_ChaosMode_h + +#include +#include + +namespace mozilla { + +/** + * When "chaos mode" is activated, code that makes implicitly nondeterministic + * choices is encouraged to make random and extreme choices, to test more + * code paths and uncover bugs. + */ +class ChaosMode +{ +public: + static bool isActive() + { + // Flip this to true to activate chaos mode + return false; + } + + /** + * Returns a somewhat (but not uniformly) random uint32_t < aBound. + * Not to be used for anything except ChaosMode, since it's not very random. + */ + static uint32_t randomUint32LessThan(uint32_t aBound) + { + return uint32_t(rand()) % aBound; + } +}; + +} /* namespace mozilla */ + +#endif /* mozilla_ChaosMode_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Char16.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Char16.h index ba1acd8c76..e54eb0d5c8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Char16.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Char16.h @@ -9,11 +9,12 @@ #ifndef mozilla_Char16_h #define mozilla_Char16_h +#ifdef __cplusplus + /* - * C11 and C++11 introduce a char16_t type and support for UTF-16 string and - * character literals. C++11's char16_t is a distinct builtin type. C11's - * char16_t is a typedef for uint_least16_t. Technically, char16_t is a 16-bit - * code unit of a Unicode code point, not a "character". + * C++11 introduces a char16_t type and support for UTF-16 string and character + * literals. C++11's char16_t is a distinct builtin type. Technically, char16_t + * is a 16-bit code unit of a Unicode code point, not a "character". */ #ifdef _MSC_VER @@ -23,8 +24,7 @@ * to Windows's 16-bit wchar_t so we can declare UTF-16 literals as constant * expressions (and pass char16_t pointers to Windows APIs). We #define * _CHAR16T here in order to prevent yvals.h from overriding our char16_t - * typedefs, which we set to wchar_t for C++ code and to unsigned short for - * C code. + * typedefs, which we set to wchar_t for C++ code. * * In addition, #defining _CHAR16T will prevent yvals.h from defining a * char32_t type, so we have to undo that damage here and provide our own, @@ -32,14 +32,9 @@ */ # define MOZ_UTF16_HELPER(s) L##s # define _CHAR16T -# ifdef __cplusplus - typedef wchar_t char16_t; -# else - typedef unsigned short char16_t; -# endif - typedef unsigned int char32_t; -#elif defined(__cplusplus) && \ - (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)) +typedef wchar_t char16_t; +typedef unsigned int char32_t; +#else /* C++11 has a builtin char16_t type. */ # define MOZ_UTF16_HELPER(s) u##s /** @@ -50,20 +45,6 @@ # ifdef WIN32 # define MOZ_USE_CHAR16_WRAPPER # endif -#elif !defined(__cplusplus) -# if defined(WIN32) -# include - typedef wchar_t char16_t; -# else - /** - * We can't use the stdint.h uint16_t type here because including - * stdint.h will break building some of our C libraries, such as - * sqlite. - */ - typedef unsigned short char16_t; -# endif -#else -# error "Char16.h requires C++11 (or something like it) for UTF-16 support." #endif #ifdef MOZ_USE_CHAR16_WRAPPER @@ -80,86 +61,109 @@ */ class char16ptr_t { - private: - const char16_t* ptr; - static_assert(sizeof(char16_t) == sizeof(wchar_t), "char16_t and wchar_t sizes differ"); - - public: - char16ptr_t(const char16_t* ptr) : ptr(ptr) {} - char16ptr_t(const wchar_t* ptr) : ptr(reinterpret_cast(ptr)) {} - - /* Without this, nullptr assignment would be ambiguous. */ - constexpr char16ptr_t(decltype(nullptr)) : ptr(nullptr) {} - - operator const char16_t*() const { - return ptr; - } - operator const wchar_t*() const { - return reinterpret_cast(ptr); - } - operator const void*() const { - return ptr; - } - operator bool() const { - return ptr != nullptr; - } - operator std::wstring() const { - return std::wstring(static_cast(*this)); - } - - /* Explicit cast operators to allow things like (char16_t*)str. */ - explicit operator char16_t*() const { - return const_cast(ptr); - } - explicit operator wchar_t*() const { - return const_cast(static_cast(*this)); - } - - /** - * Some Windows API calls accept BYTE* but require that data actually be WCHAR*. - * Supporting this requires explicit operators to support the requisite explicit - * casts. - */ - explicit operator const char*() const { - return reinterpret_cast(ptr); - } - explicit operator const unsigned char*() const { - return reinterpret_cast(ptr); - } - explicit operator unsigned char*() const { - return const_cast(reinterpret_cast(ptr)); - } - explicit operator void*() const { - return const_cast(ptr); - } - - /* Some operators used on pointers. */ - char16_t operator[](size_t i) const { - return ptr[i]; - } - bool operator==(const char16ptr_t &x) const { - return ptr == x.ptr; - } - bool operator==(decltype(nullptr)) const { - return ptr == nullptr; - } - bool operator!=(const char16ptr_t &x) const { - return ptr != x.ptr; - } - bool operator!=(decltype(nullptr)) const { - return ptr != nullptr; - } - char16ptr_t operator+(size_t add) const { - return char16ptr_t(ptr + add); - } - ptrdiff_t operator-(const char16ptr_t &other) const { - return ptr - other.ptr; - } +private: + const char16_t* mPtr; + static_assert(sizeof(char16_t) == sizeof(wchar_t), + "char16_t and wchar_t sizes differ"); + +public: + char16ptr_t(const char16_t* aPtr) : mPtr(aPtr) {} + char16ptr_t(const wchar_t* aPtr) : + mPtr(reinterpret_cast(aPtr)) + {} + + /* Without this, nullptr assignment would be ambiguous. */ + constexpr char16ptr_t(decltype(nullptr)) : mPtr(nullptr) {} + + operator const char16_t*() const + { + return mPtr; + } + operator const wchar_t*() const + { + return reinterpret_cast(mPtr); + } + operator const void*() const + { + return mPtr; + } + operator bool() const + { + return mPtr != nullptr; + } + operator std::wstring() const + { + return std::wstring(static_cast(*this)); + } + + /* Explicit cast operators to allow things like (char16_t*)str. */ + explicit operator char16_t*() const + { + return const_cast(mPtr); + } + explicit operator wchar_t*() const + { + return const_cast(static_cast(*this)); + } + + /** + * Some Windows API calls accept BYTE* but require that data actually be + * WCHAR*. Supporting this requires explicit operators to support the + * requisite explicit casts. + */ + explicit operator const char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator const unsigned char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator unsigned char*() const + { + return + const_cast(reinterpret_cast(mPtr)); + } + explicit operator void*() const + { + return const_cast(mPtr); + } + + /* Some operators used on pointers. */ + char16_t operator[](size_t aIndex) const + { + return mPtr[aIndex]; + } + bool operator==(const char16ptr_t& aOther) const + { + return mPtr == aOther.mPtr; + } + bool operator==(decltype(nullptr)) const + { + return mPtr == nullptr; + } + bool operator!=(const char16ptr_t& aOther) const + { + return mPtr != aOther.mPtr; + } + bool operator!=(decltype(nullptr)) const + { + return mPtr != nullptr; + } + char16ptr_t operator+(size_t aValue) const + { + return char16ptr_t(mPtr + aValue); + } + ptrdiff_t operator-(const char16ptr_t& aOther) const + { + return mPtr - aOther.mPtr; + } }; inline decltype((char*)0-(char*)0) -operator-(const char16_t* x, const char16ptr_t y) { - return x - static_cast(y); +operator-(const char16_t* aX, const char16ptr_t aY) +{ + return aX - static_cast(aY); } #else @@ -168,10 +172,6 @@ typedef const char16_t* char16ptr_t; #endif -/* This is a temporary hack until bug 927728 is fixed. */ -#define __PRUNICHAR__ -typedef char16_t PRUnichar; - /* * Macro arguments used in concatenation or stringification won't be expanded. * Therefore, in order for |MOZ_UTF16(FOO)| to work as expected (which is to @@ -182,12 +182,11 @@ typedef char16_t PRUnichar; */ #define MOZ_UTF16(s) MOZ_UTF16_HELPER(s) -#if defined(__cplusplus) && \ - (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)) static_assert(sizeof(char16_t) == 2, "Is char16_t type 16 bits?"); static_assert(char16_t(-1) > char16_t(0), "Is char16_t type unsigned?"); static_assert(sizeof(MOZ_UTF16('A')) == 2, "Is char literal 16 bits?"); static_assert(sizeof(MOZ_UTF16("")[0]) == 2, "Is string char 16 bits?"); + #endif #endif /* mozilla_Char16_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/CheckedInt.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/CheckedInt.h index 050cef8ed8..ad4c5fef41 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/CheckedInt.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/CheckedInt.h @@ -9,21 +9,9 @@ #ifndef mozilla_CheckedInt_h #define mozilla_CheckedInt_h -// Enable relying of Mozilla's MFBT for possibly-available C++11 features -#define MOZ_CHECKEDINT_USE_MFBT - #include - -#ifdef MOZ_CHECKEDINT_USE_MFBT -# include "mozilla/Assertions.h" -#else -# include -# define MOZ_ASSERT(cond, reason) assert((cond) && reason) -# define MOZ_DELETE -#endif - -#include -#include +#include "mozilla/Assertions.h" +#include "mozilla/IntegerTypeTraits.h" namespace mozilla { @@ -47,13 +35,13 @@ struct UnsupportedType {}; template struct IsSupportedPass2 { - static const bool value = false; + static const bool value = false; }; template struct IsSupported { - static const bool value = IsSupportedPass2::value; + static const bool value = IsSupportedPass2::value; }; template<> @@ -134,133 +122,45 @@ struct IsSupportedPass2 { static const bool value = true; }; /* - * Step 2: some integer-traits kind of stuff. + * Step 2: Implement the actual validity checks. + * + * Ideas taken from IntegerLib, code different. */ -template -struct StdintTypeForSizeAndSignedness -{}; - -template<> -struct StdintTypeForSizeAndSignedness<1, true> -{ typedef int8_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<1, false> -{ typedef uint8_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<2, true> -{ typedef int16_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<2, false> -{ typedef uint16_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<4, true> -{ typedef int32_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<4, false> -{ typedef uint32_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<8, true> -{ typedef int64_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<8, false> -{ typedef uint64_t Type; }; - -template -struct UnsignedType -{ - typedef typename StdintTypeForSizeAndSignedness::Type Type; -}; - -template -struct IsSigned -{ - static const bool value = IntegerType(-1) <= IntegerType(0); -}; - template struct TwiceBiggerType { - typedef typename StdintTypeForSizeAndSignedness< - sizeof(IntegerType) * 2, - IsSigned::value - >::Type Type; + typedef typename detail::StdintTypeForSizeAndSignedness< + sizeof(IntegerType) * 2, + IsSigned::value + >::Type Type; }; template struct TwiceBiggerType { - typedef UnsupportedType Type; + typedef UnsupportedType Type; }; -template -struct PositionOfSignBit -{ - static const size_t value = CHAR_BIT * sizeof(IntegerType) - 1; -}; - -template -struct MinValue -{ - private: - typedef typename UnsignedType::Type UnsignedIntegerType; - static const size_t PosOfSignBit = PositionOfSignBit::value; - - public: - // Bitwise ops may return a larger type, that's why we cast explicitly. - // In C++, left bit shifts on signed values is undefined by the standard - // unless the shifted value is representable. - // Notice that signed-to-unsigned conversions are always well-defined in - // the standard as the value congruent to 2**n, as expected. By contrast, - // unsigned-to-signed is only well-defined if the value is representable. - static const IntegerType value = - IsSigned::value - ? IntegerType(UnsignedIntegerType(1) << PosOfSignBit) - : IntegerType(0); -}; - -template -struct MaxValue -{ - // Tricksy, but covered by the unit test. - // Relies heavily on the type of MinValue::value - // being IntegerType. - static const IntegerType value = ~MinValue::value; -}; - -/* - * Step 3: Implement the actual validity checks. - * - * Ideas taken from IntegerLib, code different. - */ - template inline bool -HasSignBit(T x) +HasSignBit(T aX) { // In C++, right bit shifts on negative values is undefined by the standard. // Notice that signed-to-unsigned conversions are always well-defined in the // standard, as the value congruent modulo 2**n as expected. By contrast, // unsigned-to-signed is only well-defined if the value is representable. - return bool(typename UnsignedType::Type(x) - >> PositionOfSignBit::value); + return bool(typename MakeUnsigned::Type(aX) >> + PositionOfSignBit::value); } // Bitwise ops may return a larger type, so it's good to use this inline // helper guaranteeing that the result is really of type T. template inline T -BinaryComplement(T x) +BinaryComplement(T aX) { - return ~x; + return ~aX; } template struct DoesRangeContainRange { - static const bool value = sizeof(T) >= sizeof(U); + static const bool value = sizeof(T) >= sizeof(U); }; template struct DoesRangeContainRange { - static const bool value = sizeof(T) > sizeof(U); + static const bool value = sizeof(T) > sizeof(U); }; template struct DoesRangeContainRange { - static const bool value = false; + static const bool value = false; }; template struct IsInRangeImpl { - static bool run(U) - { - return true; - } + static bool run(U) + { + return true; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return x <= MaxValue::value && x >= MinValue::value; - } + static bool run(U aX) + { + return aX <= MaxValue::value && aX >= MinValue::value; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return x <= MaxValue::value; - } + static bool run(U aX) + { + return aX <= MaxValue::value; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return sizeof(T) > sizeof(U) || x <= U(MaxValue::value); - } + static bool run(U aX) + { + return sizeof(T) > sizeof(U) || aX <= U(MaxValue::value); + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return sizeof(T) >= sizeof(U) - ? x >= 0 - : x >= 0 && x <= U(MaxValue::value); - } + static bool run(U aX) + { + return sizeof(T) >= sizeof(U) + ? aX >= 0 + : aX >= 0 && aX <= U(MaxValue::value); + } }; template inline bool -IsInRange(U x) +IsInRange(U aX) { - return IsInRangeImpl::run(x); + return IsInRangeImpl::run(aX); } template inline bool -IsAddValid(T x, T y) +IsAddValid(T aX, T aY) { - // Addition is valid if the sign of x+y is equal to either that of x or that - // of y. Since the value of x+y is undefined if we have a signed type, we - // compute it using the unsigned type of the same size. - // Beware! These bitwise operations can return a larger integer type, - // if T was a small type like int8_t, so we explicitly cast to T. + // Addition is valid if the sign of aX+aY is equal to either that of aX or + // that of aY. Since the value of aX+aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. Beware! + // These bitwise operations can return a larger integer type, if T was a + // small type like int8_t, so we explicitly cast to T. - typename UnsignedType::Type ux = x; - typename UnsignedType::Type uy = y; - typename UnsignedType::Type result = ux + uy; + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux + uy; return IsSigned::value - ? HasSignBit(BinaryComplement(T((result ^ x) & (result ^ y)))) - : BinaryComplement(x) >= y; + ? HasSignBit(BinaryComplement(T((result ^ aX) & (result ^ aY)))) + : BinaryComplement(aX) >= aY; } template inline bool -IsSubValid(T x, T y) +IsSubValid(T aX, T aY) { - // Subtraction is valid if either x and y have same sign, or x-y and x have - // same sign. Since the value of x-y is undefined if we have a signed type, - // we compute it using the unsigned type of the same size. - typename UnsignedType::Type ux = x; - typename UnsignedType::Type uy = y; - typename UnsignedType::Type result = ux - uy; + // Subtraction is valid if either aX and aY have same sign, or aX-aY and aX + // have same sign. Since the value of aX-aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux - uy; return IsSigned::value - ? HasSignBit(BinaryComplement(T((result ^ x) & (x ^ y)))) - : x >= y; + ? HasSignBit(BinaryComplement(T((result ^ aX) & (aX ^ aY)))) + : aX >= aY; } template struct IsMulValidImpl { - static bool run(T x, T y) - { - typedef typename TwiceBiggerType::Type TwiceBiggerType; - TwiceBiggerType product = TwiceBiggerType(x) * TwiceBiggerType(y); - return IsInRange(product); - } + static bool run(T aX, T aY) + { + typedef typename TwiceBiggerType::Type TwiceBiggerType; + TwiceBiggerType product = TwiceBiggerType(aX) * TwiceBiggerType(aY); + return IsInRange(product); + } }; template struct IsMulValidImpl { - static bool run(T x, T y) - { - const T max = MaxValue::value; - const T min = MinValue::value; - - if (x == 0 || y == 0) - return true; - - if (x > 0) { - return y > 0 - ? x <= max / y - : y >= min / x; - } + static bool run(T aX, T aY) + { + const T max = MaxValue::value; + const T min = MinValue::value; - // If we reach this point, we know that x < 0. - return y > 0 - ? x >= min / y - : y >= max / x; + if (aX == 0 || aY == 0) { + return true; } + if (aX > 0) { + return aY > 0 + ? aX <= max / aY + : aY >= min / aX; + } + + // If we reach this point, we know that aX < 0. + return aY > 0 + ? aX >= min / aY + : aY >= max / aX; + } }; template struct IsMulValidImpl { - static bool run(T x, T y) - { - return y == 0 || x <= MaxValue::value / y; - } + static bool run(T aX, T aY) + { + return aY == 0 || aX <= MaxValue::value / aY; + } }; template inline bool -IsMulValid(T x, T y) +IsMulValid(T aX, T aY) { - return IsMulValidImpl::run(x, y); + return IsMulValidImpl::run(aX, aY); } template inline bool -IsDivValid(T x, T y) +IsDivValid(T aX, T aY) { - // Keep in mind that in the signed case, min/-1 is invalid because abs(min)>max. - return y != 0 && - !(IsSigned::value && x == MinValue::value && y == T(-1)); + // Keep in mind that in the signed case, min/-1 is invalid because + // abs(min)>max. + return aY != 0 && + !(IsSigned::value && aX == MinValue::value && aY == T(-1)); } template::value> @@ -455,36 +356,40 @@ struct IsModValidImpl; template inline bool -IsModValid(T x, T y) +IsModValid(T aX, T aY) { - return IsModValidImpl::run(x, y); + return IsModValidImpl::run(aX, aY); } /* * Mod is pretty simple. * For now, let's just use the ANSI C definition: - * If x or y are negative, the results are implementation defined. + * If aX or aY are negative, the results are implementation defined. * Consider these invalid. - * Undefined for y=0. - * The result will never exceed either x or y. + * Undefined for aY=0. + * The result will never exceed either aX or aY. * - * Checking that x>=0 is a warning when T is unsigned. + * Checking that aX>=0 is a warning when T is unsigned. */ template -struct IsModValidImpl { - static inline bool run(T x, T y) { - return y >= 1; +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + return aY >= 1; } }; template -struct IsModValidImpl { - static inline bool run(T x, T y) { - if (x < 0) +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + if (aX < 0) { return false; - - return y >= 1; + } + return aY >= 1; } }; @@ -494,32 +399,33 @@ struct NegateImpl; template struct NegateImpl { - static CheckedInt negate(const CheckedInt& val) - { - // Handle negation separately for signed/unsigned, for simpler code and to - // avoid an MSVC warning negating an unsigned value. - return CheckedInt(0, val.isValid() && val.mValue == 0); - } + static CheckedInt negate(const CheckedInt& aVal) + { + // Handle negation separately for signed/unsigned, for simpler code and to + // avoid an MSVC warning negating an unsigned value. + return CheckedInt(0, aVal.isValid() && aVal.mValue == 0); + } }; template struct NegateImpl { - static CheckedInt negate(const CheckedInt& val) - { - // Watch out for the min-value, which (with twos-complement) can't be - // negated as -min-value is then (max-value + 1). - if (!val.isValid() || val.mValue == MinValue::value) - return CheckedInt(val.mValue, false); - return CheckedInt(-val.mValue, true); + static CheckedInt negate(const CheckedInt& aVal) + { + // Watch out for the min-value, which (with twos-complement) can't be + // negated as -min-value is then (max-value + 1). + if (!aVal.isValid() || aVal.mValue == MinValue::value) { + return CheckedInt(aVal.mValue, false); } + return CheckedInt(-aVal.mValue, true); + } }; } // namespace detail /* - * Step 4: Now define the CheckedInt class. + * Step 3: Now define the CheckedInt class. */ /** @@ -538,18 +444,18 @@ struct NegateImpl * (e.g. in case of a division by zero). * * For example, suppose that you want to implement a function that computes - * (x+y)/z, that doesn't crash if z==0, and that reports on error (divide by + * (aX+aY)/aZ, that doesn't crash if aZ==0, and that reports on error (divide by * zero or integer overflow). You could code it as follows: @code - bool computeXPlusYOverZ(int x, int y, int z, int *result) + bool computeXPlusYOverZ(int aX, int aY, int aZ, int* aResult) { - CheckedInt checkedResult = (CheckedInt(x) + y) / z; - if (checkedResult.isValid()) { - *result = checkedResult.value(); - return true; - } else { - return false; - } + CheckedInt checkedResult = (CheckedInt(aX) + aY) / aZ; + if (checkedResult.isValid()) { + *aResult = checkedResult.value(); + return true; + } else { + return false; + } } @endcode * @@ -592,193 +498,188 @@ struct NegateImpl template class CheckedInt { - protected: - T mValue; - bool mIsValid; +protected: + T mValue; + bool mIsValid; - template - CheckedInt(U value, bool isValid) : mValue(value), mIsValid(isValid) - { - static_assert(detail::IsSupported::value && - detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + template + CheckedInt(U aValue, bool aIsValid) : mValue(aValue), mIsValid(aIsValid) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - friend struct detail::NegateImpl; - - public: - /** - * Constructs a checked integer with given @a value. The checked integer is - * initialized as valid or invalid depending on whether the @a value - * is in range. - * - * This constructor is not explicit. Instead, the type of its argument is a - * separate template parameter, ensuring that no conversion is performed - * before this constructor is actually called. As explained in the above - * documentation for class CheckedInt, this constructor checks that its - * argument is valid. - */ - template - CheckedInt(U value) - : mValue(T(value)), - mIsValid(detail::IsInRange(value)) - { - static_assert(detail::IsSupported::value && - detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + friend struct detail::NegateImpl; + +public: + /** + * Constructs a checked integer with given @a value. The checked integer is + * initialized as valid or invalid depending on whether the @a value + * is in range. + * + * This constructor is not explicit. Instead, the type of its argument is a + * separate template parameter, ensuring that no conversion is performed + * before this constructor is actually called. As explained in the above + * documentation for class CheckedInt, this constructor checks that its + * argument is valid. + */ + template + CheckedInt(U aValue) + : mValue(T(aValue)), + mIsValid(detail::IsInRange(aValue)) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - template - friend class CheckedInt; + template + friend class CheckedInt; - template - CheckedInt toChecked() const - { - CheckedInt ret(mValue); - ret.mIsValid = ret.mIsValid && mIsValid; - return ret; - } + template + CheckedInt toChecked() const + { + CheckedInt ret(mValue); + ret.mIsValid = ret.mIsValid && mIsValid; + return ret; + } - /** Constructs a valid checked integer with initial value 0 */ - CheckedInt() : mValue(0), mIsValid(true) - { - static_assert(detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + /** Constructs a valid checked integer with initial value 0 */ + CheckedInt() : mValue(0), mIsValid(true) + { + static_assert(detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - /** @returns the actual value */ - T value() const - { - MOZ_ASSERT(mIsValid, "Invalid checked integer (division by zero or integer overflow)"); - return mValue; - } + /** @returns the actual value */ + T value() const + { + MOZ_ASSERT(mIsValid, "Invalid checked integer (division by zero or integer overflow)"); + return mValue; + } - /** - * @returns true if the checked integer is valid, i.e. is not the result - * of an invalid operation or of an operation involving an invalid checked - * integer - */ - bool isValid() const - { - return mIsValid; - } + /** + * @returns true if the checked integer is valid, i.e. is not the result + * of an invalid operation or of an operation involving an invalid checked + * integer + */ + bool isValid() const + { + return mIsValid; + } - template - friend CheckedInt operator +(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator +=(U rhs); - - template - friend CheckedInt operator -(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator -=(U rhs); - - template - friend CheckedInt operator *(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator *=(U rhs); - - template - friend CheckedInt operator /(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator /=(U rhs); - - template - friend CheckedInt operator %(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator %=(U rhs); - - CheckedInt operator -() const - { - return detail::NegateImpl::negate(*this); - } + template + friend CheckedInt operator +(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator +=(U aRhs); + + template + friend CheckedInt operator -(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator -=(U aRhs); + + template + friend CheckedInt operator *(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator *=(U aRhs); + + template + friend CheckedInt operator /(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator /=(U aRhs); + + template + friend CheckedInt operator %(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator %=(U aRhs); + + CheckedInt operator -() const + { + return detail::NegateImpl::negate(*this); + } - /** - * @returns true if the left and right hand sides are valid - * and have the same value. - * - * Note that these semantics are the reason why we don't offer - * a operator!=. Indeed, we'd want to have a!=b be equivalent to !(a==b) - * but that would mean that whenever a or b is invalid, a!=b - * is always true, which would be very confusing. - * - * For similar reasons, operators <, >, <=, >= would be very tricky to - * specify, so we just avoid offering them. - * - * Notice that these == semantics are made more reasonable by these facts: - * 1. a==b implies equality at the raw data level - * (the converse is false, as a==b is never true among invalids) - * 2. This is similar to the behavior of IEEE floats, where a==b - * means that a and b have the same value *and* neither is NaN. - */ - bool operator ==(const CheckedInt& other) const - { - return mIsValid && other.mIsValid && mValue == other.mValue; - } + /** + * @returns true if the left and right hand sides are valid + * and have the same value. + * + * Note that these semantics are the reason why we don't offer + * a operator!=. Indeed, we'd want to have a!=b be equivalent to !(a==b) + * but that would mean that whenever a or b is invalid, a!=b + * is always true, which would be very confusing. + * + * For similar reasons, operators <, >, <=, >= would be very tricky to + * specify, so we just avoid offering them. + * + * Notice that these == semantics are made more reasonable by these facts: + * 1. a==b implies equality at the raw data level + * (the converse is false, as a==b is never true among invalids) + * 2. This is similar to the behavior of IEEE floats, where a==b + * means that a and b have the same value *and* neither is NaN. + */ + bool operator ==(const CheckedInt& aOther) const + { + return mIsValid && aOther.mIsValid && mValue == aOther.mValue; + } - /** prefix ++ */ - CheckedInt& operator++() - { - *this += 1; - return *this; - } + /** prefix ++ */ + CheckedInt& operator++() + { + *this += 1; + return *this; + } - /** postfix ++ */ - CheckedInt operator++(int) - { - CheckedInt tmp = *this; - *this += 1; - return tmp; - } + /** postfix ++ */ + CheckedInt operator++(int) + { + CheckedInt tmp = *this; + *this += 1; + return tmp; + } - /** prefix -- */ - CheckedInt& operator--() - { - *this -= 1; - return *this; - } + /** prefix -- */ + CheckedInt& operator--() + { + *this -= 1; + return *this; + } - /** postfix -- */ - CheckedInt operator--(int) - { - CheckedInt tmp = *this; - *this -= 1; - return tmp; - } + /** postfix -- */ + CheckedInt operator--(int) + { + CheckedInt tmp = *this; + *this -= 1; + return tmp; + } - private: - /** - * The !=, <, <=, >, >= operators are disabled: - * see the comment on operator==. - */ - template - bool operator !=(U other) const MOZ_DELETE; - template - bool operator <(U other) const MOZ_DELETE; - template - bool operator <=(U other) const MOZ_DELETE; - template - bool operator >(U other) const MOZ_DELETE; - template - bool operator >=(U other) const MOZ_DELETE; +private: + /** + * The !=, <, <=, >, >= operators are disabled: + * see the comment on operator==. + */ + template bool operator !=(U aOther) const MOZ_DELETE; + template bool operator < (U aOther) const MOZ_DELETE; + template bool operator <=(U aOther) const MOZ_DELETE; + template bool operator > (U aOther) const MOZ_DELETE; + template bool operator >=(U aOther) const MOZ_DELETE; }; -#define MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP) \ -template \ -inline CheckedInt operator OP(const CheckedInt &lhs, \ - const CheckedInt &rhs) \ -{ \ - if (!detail::Is##NAME##Valid(lhs.mValue, rhs.mValue)) \ - return CheckedInt(0, false); \ - \ - return CheckedInt(lhs.mValue OP rhs.mValue, \ - lhs.mIsValid && rhs.mIsValid); \ -} +#define MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP) \ + template \ + inline CheckedInt \ + operator OP(const CheckedInt &aLhs, const CheckedInt &aRhs) \ + { \ + if (!detail::Is##NAME##Valid(aLhs.mValue, aRhs.mValue)) { \ + return CheckedInt(0, false); \ + } \ + return CheckedInt(aLhs.mValue OP aRhs.mValue, \ + aLhs.mIsValid && aRhs.mIsValid); \ + } MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Add, +) MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Sub, -) @@ -799,47 +700,47 @@ namespace detail { template struct CastToCheckedIntImpl { - typedef CheckedInt ReturnType; - static CheckedInt run(U u) { return u; } + typedef CheckedInt ReturnType; + static CheckedInt run(U aU) { return aU; } }; template struct CastToCheckedIntImpl > { - typedef const CheckedInt& ReturnType; - static const CheckedInt& run(const CheckedInt& u) { return u; } + typedef const CheckedInt& ReturnType; + static const CheckedInt& run(const CheckedInt& aU) { return aU; } }; } // namespace detail template inline typename detail::CastToCheckedIntImpl::ReturnType -castToCheckedInt(U u) +castToCheckedInt(U aU) { static_assert(detail::IsSupported::value && detail::IsSupported::value, "This type is not supported by CheckedInt"); - return detail::CastToCheckedIntImpl::run(u); + return detail::CastToCheckedIntImpl::run(aU); } -#define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP) \ -template \ -template \ -CheckedInt& CheckedInt::operator COMPOUND_OP(U rhs) \ -{ \ - *this = *this OP castToCheckedInt(rhs); \ - return *this; \ -} \ -template \ -inline CheckedInt operator OP(const CheckedInt &lhs, U rhs) \ -{ \ - return lhs OP castToCheckedInt(rhs); \ -} \ -template \ -inline CheckedInt operator OP(U lhs, const CheckedInt &rhs) \ -{ \ - return castToCheckedInt(lhs) OP rhs; \ -} +#define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP) \ + template \ + template \ + CheckedInt& CheckedInt::operator COMPOUND_OP(U aRhs) \ + { \ + *this = *this OP castToCheckedInt(aRhs); \ + return *this; \ + } \ + template \ + inline CheckedInt operator OP(const CheckedInt &aLhs, U aRhs) \ + { \ + return aLhs OP castToCheckedInt(aRhs); \ + } \ + template \ + inline CheckedInt operator OP(U aLhs, const CheckedInt &aRhs) \ + { \ + return castToCheckedInt(aLhs) OP aRhs; \ + } MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(+, +=) MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(*, *=) @@ -851,16 +752,16 @@ MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(%, %=) template inline bool -operator ==(const CheckedInt &lhs, U rhs) +operator ==(const CheckedInt &aLhs, U aRhs) { - return lhs == castToCheckedInt(rhs); + return aLhs == castToCheckedInt(aRhs); } template inline bool -operator ==(U lhs, const CheckedInt &rhs) +operator ==(U aLhs, const CheckedInt &aRhs) { - return castToCheckedInt(lhs) == rhs; + return castToCheckedInt(aLhs) == aRhs; } // Convenience typedefs. diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Compiler.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Compiler.h index fd5c98c98d..50f127da86 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Compiler.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Compiler.h @@ -9,23 +9,41 @@ #ifndef mozilla_Compiler_h #define mozilla_Compiler_h +#define MOZ_IS_GCC 0 +#define MOS_IS_MSVC 0 + #if !defined(__clang__) && defined(__GNUC__) -#define MOZ_IS_GCC 1 +# undef MOZ_IS_GCC +# define MOZ_IS_GCC 1 /* * This macro should simplify gcc version checking. For example, to check - * for gcc 4.5.1 or later, check `#ifdef MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`. + * for gcc 4.5.1 or later, check `#if MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`. */ # define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel) \ ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \ >= ((major) * 10000 + (minor) * 100 + (patchlevel))) -#if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0) -# error "mfbt (and Gecko) require at least gcc 4.4 to build." -#endif +# if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0) +# error "mfbt (and Gecko) require at least gcc 4.4 to build." +# endif -#else +#elif defined(_MSC_VER) -#define MOZ_IS_GCC 0 +# undef MOZ_IS_MSVC +# define MOZ_IS_MSVC 1 + /* + * This macro should simplify MSVC version checking. For example, to check + * for VC10 or later, check `#ifdef MOZ_MSVC_VERSION_AT_LEAST(10)`. + */ +# define MOZ_MSVC_VERSION_AT_LEAST(version) \ + (version == 10 ? _MSC_VER >= 1600 : \ + (version == 11 ? _MSC_VER >= 1700 : \ + (version == 12 ? _MSC_VER >= 1800 : \ + (version == 13 ? _MSC_VER >= 1900 : \ + 0)))) +# if !MOZ_MSVC_VERSION_AT_LEAST(10) +# error "mfbt (and Gecko) require at least MSVC 2010 RTM to build." +# endif #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Compression.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Compression.h index 2b8a7a7d8e..a764a1b5d5 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Compression.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Compression.h @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -22,41 +23,41 @@ namespace Compression { * * Compared to zlib it compresses at about 10x the speed, decompresses at about * 4x the speed and produces output of about 1.5x the size. - * */ class LZ4 { - public: - /** - * Compresses 'inputSize' bytes from 'source' into 'dest'. - * Destination buffer must be already allocated, - * and must be sized to handle worst cases situations (input data not compressible) - * Worst case size evaluation is provided by function LZ4_compressBound() + * Compresses |aInputSize| bytes from |aSource| into |aDest|. Destination + * buffer must be already allocated, and must be sized to handle worst cases + * situations (input data not compressible). Worst case size evaluation is + * provided by function maxCompressedSize() * - * @param inputSize is the input size. Max supported value is ~1.9GB - * @param return the number of bytes written in buffer dest + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return the number of bytes written in buffer |aDest| */ - static MFBT_API size_t compress(const char* source, size_t inputSize, char* dest); + static MFBT_API size_t + compress(const char* aSource, size_t aInputSize, char* aDest); /** - * Compress 'inputSize' bytes from 'source' into an output buffer - * 'dest' of maximum size 'maxOutputSize'. If it cannot achieve it, + * Compress |aInputSize| bytes from |aSource| into an output buffer + * |aDest| of maximum size |aMaxOutputSize|. If it cannot achieve it, * compression will stop, and result of the function will be zero, - * 'dest' will still be written to, but since the number of input + * |aDest| will still be written to, but since the number of input * bytes consumed is not returned the result is not usable. * * This function never writes outside of provided output buffer. * - * @param inputSize is the input size. Max supported value is ~1.9GB - * @param maxOutputSize is the size of the destination buffer (which must be already allocated) - * @return the number of bytes written in buffer 'dest' - or 0 if the compression fails - */ - static MFBT_API size_t compressLimitedOutput(const char* source, size_t inputSize, char* dest, - size_t maxOutputSize); + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @param aMaxOutputSize is the size of the destination buffer (which must + * be already allocated) + * @return the number of bytes written in buffer |aDest| or 0 if the + * compression fails + */ + static MFBT_API size_t + compressLimitedOutput(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize); /** * If the source stream is malformed, the function will stop decoding @@ -66,48 +67,50 @@ class LZ4 * This function never writes outside of provided buffers, and never * modifies input buffer. * - * note : destination buffer must be already allocated. - * its size must be a minimum of 'outputSize' bytes. - * @param outputSize is the output size, therefore the original size + * Note: destination buffer must be already allocated, and its size must be a + * minimum of |aOutputSize| bytes. + * + * @param aOutputSize is the output size, therefore the original size * @return the number of bytes read in the source buffer - */ - static MFBT_API bool decompress(const char* source, char* dest, size_t outputSize); + */ + static MFBT_API bool + decompress(const char* aSource, char* aDest, size_t aOutputSize); /** * If the source stream is malformed, the function will stop decoding * and return false. * - * This function never writes beyond dest + maxOutputSize, and is + * This function never writes beyond aDest + aMaxOutputSize, and is * therefore protected against malicious data packets. * - * note : Destination buffer must be already allocated. - * This version is slightly slower than the decompress - * without the maxOutputSize + * Note: Destination buffer must be already allocated. This version is + * slightly slower than the decompress without the aMaxOutputSize. * - * @param inputSize is the length of the input compressed data - * @param maxOutputSize is the size of the destination buffer (which must be already allocated) - * @param outputSize the actual number of bytes decoded in the destination buffer (necessarily <= maxOutputSize) - - */ - static MFBT_API bool decompress(const char* source, size_t inputSize, char* dest, - size_t maxOutputSize, size_t *outputSize); + * @param aInputSize is the length of the input compressed data + * @param aMaxOutputSize is the size of the destination buffer (which must be + * already allocated) + * @param aOutputSize the actual number of bytes decoded in the destination + * buffer (necessarily <= aMaxOutputSize) + */ + static MFBT_API bool + decompress(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize, size_t* aOutputSize); /* - Provides the maximum size that LZ4 may output in a "worst case" - scenario (input data not compressible) primarily useful for memory - allocation of output buffer. - note : this function is limited by "int" range (2^31-1) - - @param inputSize is the input size. Max supported value is ~1.9GB - @return maximum output size in a "worst case" scenario - */ - static inline size_t maxCompressedSize(size_t inputSize) + * Provides the maximum size that LZ4 may output in a "worst case" + * scenario (input data not compressible) primarily useful for memory + * allocation of output buffer. + * note : this function is limited by "int" range (2^31-1) + * + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return maximum output size in a "worst case" scenario + */ + static inline size_t maxCompressedSize(size_t aInputSize) { - size_t max = ((inputSize) + ((inputSize)/255) + 16); - MOZ_ASSERT(max > inputSize); - return max; + size_t max = (aInputSize + (aInputSize / 255) + 16); + MOZ_ASSERT(max > aInputSize); + return max; } - }; } /* namespace Compression */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/DebugOnly.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/DebugOnly.h index e5f0d729b5..5d0197b194 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/DebugOnly.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/DebugOnly.h @@ -12,6 +12,8 @@ #ifndef mozilla_DebugOnly_h #define mozilla_DebugOnly_h +#include "mozilla/Attributes.h" + namespace mozilla { /** @@ -27,50 +29,51 @@ namespace mozilla { * * DebugOnly instances can only be coerced to T in debug builds. In release * builds they don't have a value, so type coercion is not well defined. + * + * Note that DebugOnly instances still take up one byte of space, plus padding, + * when used as members of structs. */ template class DebugOnly { - public: +public: #ifdef DEBUG - T value; + T value; + + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T& aOther) : value(aOther) { } + DebugOnly(const DebugOnly& aOther) : value(aOther.value) { } + DebugOnly& operator=(const T& aRhs) { + value = aRhs; + return *this; + } - DebugOnly() { } - DebugOnly(const T& other) : value(other) { } - DebugOnly(const DebugOnly& other) : value(other.value) { } - DebugOnly& operator=(const T& rhs) { - value = rhs; - return *this; - } - void operator++(int) { - value++; - } - void operator--(int) { - value--; - } + void operator++(int) { value++; } + void operator--(int) { value--; } - T* operator&() { return &value; } + T* operator&() { return &value; } - operator T&() { return value; } - operator const T&() const { return value; } + operator T&() { return value; } + operator const T&() const { return value; } - T& operator->() { return value; } + T& operator->() { return value; } + const T& operator->() const { return value; } #else - DebugOnly() { } - DebugOnly(const T&) { } - DebugOnly(const DebugOnly&) { } - DebugOnly& operator=(const T&) { return *this; } - void operator++(int) { } - void operator--(int) { } + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T&) { } + DebugOnly(const DebugOnly&) { } + DebugOnly& operator=(const T&) { return *this; } + void operator++(int) { } + void operator--(int) { } #endif - /* - * DebugOnly must always have a destructor or else it will - * generate "unused variable" warnings, exactly what it's intended - * to avoid! - */ - ~DebugOnly() {} + /* + * DebugOnly must always have a destructor or else it will + * generate "unused variable" warnings, exactly what it's intended + * to avoid! + */ + ~DebugOnly() {} }; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Decimal.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Decimal.h index 3c67d784c9..9f4926bd06 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Decimal.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Decimal.h @@ -112,7 +112,7 @@ class Decimal { Sign m_sign; }; - MFBT_API Decimal(int32_t = 0); + MFBT_API explicit Decimal(int32_t = 0); MFBT_API Decimal(Sign, int exponent, uint64_t coefficient); MFBT_API Decimal(const Decimal&); @@ -185,7 +185,7 @@ class Decimal { int exponent; }; - MFBT_API Decimal(double); + MFBT_API explicit Decimal(double); MFBT_API Decimal compareTo(const Decimal&) const; static MFBT_API AlignedOperands alignOperands(const Decimal& lhs, const Decimal& rhs); diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Endian.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Endian.h index cb6bd27c05..e4e1ff8549 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Endian.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Endian.h @@ -42,21 +42,22 @@ * * class ExampleHeader * { - * private: - * uint32_t magic; - * uint32_t length; - * uint32_t totalRecords; - * uint64_t checksum; + * private: + * uint32_t mMagic; + * uint32_t mLength; + * uint32_t mTotalRecords; + * uint64_t mChecksum; * - * public: - * ExampleHeader(const void* data) { - * const uint8_t* ptr = static_cast(data); - * magic = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * length = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * totalRecords = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * checksum = BigEndian::readUint64(ptr); - * } - * ... + * public: + * ExampleHeader(const void* data) + * { + * const uint8_t* ptr = static_cast(data); + * mMagic = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mLength = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mTotalRecords = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mChecksum = BigEndian::readUint64(ptr); + * } + * ... * }; */ @@ -91,7 +92,7 @@ # else # error "CPU type is unknown" # endif -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) # if __LITTLE_ENDIAN__ # define MOZ_LITTLE_ENDIAN 1 # elif __BIG_ENDIAN__ @@ -119,17 +120,16 @@ * cases. */ #elif defined(__sparc) || defined(__sparc__) || \ - defined(_POWER) || defined(__powerpc__) || \ - defined(__ppc__) || defined(__hppa) || \ + defined(_POWER) || defined(__hppa) || \ defined(_MIPSEB) || defined(__ARMEB__) || \ - defined(__s390__) || \ + defined(__s390__) || defined(__AARCH64EB__) || \ (defined(__sh__) && defined(__LITTLE_ENDIAN__)) || \ (defined(__ia64) && defined(__BIG_ENDIAN__)) # define MOZ_BIG_ENDIAN 1 #elif defined(__i386) || defined(__i386__) || \ defined(__x86_64) || defined(__x86_64__) || \ defined(_MIPSEL) || defined(__ARMEL__) || \ - defined(__alpha__) || \ + defined(__alpha__) || defined(__AARCH64EL__) || \ (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ (defined(__ia64) && !defined(__BIG_ENDIAN__)) # define MOZ_LITTLE_ENDIAN 1 @@ -170,12 +170,12 @@ struct Swapper; template struct Swapper { - static T swap(T value) + static T swap(T aValue) { #if defined(MOZ_HAVE_BUILTIN_BYTESWAP16) - return MOZ_HAVE_BUILTIN_BYTESWAP16(value); + return MOZ_HAVE_BUILTIN_BYTESWAP16(aValue); #else - return T(((value & 0x00ff) << 8) | ((value & 0xff00) >> 8)); + return T(((aValue & 0x00ff) << 8) | ((aValue & 0xff00) >> 8)); #endif } }; @@ -183,17 +183,17 @@ struct Swapper template struct Swapper { - static T swap(T value) + static T swap(T aValue) { #if defined(__clang__) || defined(__GNUC__) - return T(__builtin_bswap32(value)); + return T(__builtin_bswap32(aValue)); #elif defined(_MSC_VER) - return T(_byteswap_ulong(value)); + return T(_byteswap_ulong(aValue)); #else - return T(((value & 0x000000ffU) << 24) | - ((value & 0x0000ff00U) << 8) | - ((value & 0x00ff0000U) >> 8) | - ((value & 0xff000000U) >> 24)); + return T(((aValue & 0x000000ffU) << 24) | + ((aValue & 0x0000ff00U) << 8) | + ((aValue & 0x00ff0000U) >> 8) | + ((aValue & 0xff000000U) >> 24)); #endif } }; @@ -201,21 +201,21 @@ struct Swapper template struct Swapper { - static inline T swap(T value) + static inline T swap(T aValue) { #if defined(__clang__) || defined(__GNUC__) - return T(__builtin_bswap64(value)); + return T(__builtin_bswap64(aValue)); #elif defined(_MSC_VER) - return T(_byteswap_uint64(value)); + return T(_byteswap_uint64(aValue)); #else - return T(((value & 0x00000000000000ffULL) << 56) | - ((value & 0x000000000000ff00ULL) << 40) | - ((value & 0x0000000000ff0000ULL) << 24) | - ((value & 0x00000000ff000000ULL) << 8) | - ((value & 0x000000ff00000000ULL) >> 8) | - ((value & 0x0000ff0000000000ULL) >> 24) | - ((value & 0x00ff000000000000ULL) >> 40) | - ((value & 0xff00000000000000ULL) >> 56)); + return T(((aValue & 0x00000000000000ffULL) << 56) | + ((aValue & 0x000000000000ff00ULL) << 40) | + ((aValue & 0x0000000000ff0000ULL) << 24) | + ((aValue & 0x00000000ff000000ULL) << 8) | + ((aValue & 0x000000ff00000000ULL) >> 8) | + ((aValue & 0x0000ff0000000000ULL) >> 24) | + ((aValue & 0x00ff000000000000ULL) >> 40) | + ((aValue & 0xff00000000000000ULL) >> 56)); #endif } }; @@ -230,360 +230,415 @@ enum Endianness { Little, Big }; class EndianUtils { - /** - * Assert that the memory regions [dest, dest+count) and [src, src+count] - * do not overlap. count is given in bytes. - */ - static void assertNoOverlap(const void* dest, const void* src, size_t count) - { - DebugOnly byteDestPtr = static_cast(dest); - DebugOnly byteSrcPtr = static_cast(src); - MOZ_ASSERT((byteDestPtr <= byteSrcPtr && - byteDestPtr + count <= byteSrcPtr) || - (byteSrcPtr <= byteDestPtr && - byteSrcPtr + count <= byteDestPtr)); - } + /** + * Assert that the memory regions [aDest, aDest+aCount) and + * [aSrc, aSrc+aCount] do not overlap. aCount is given in bytes. + */ + static void assertNoOverlap(const void* aDest, const void* aSrc, + size_t aCount) + { + DebugOnly byteDestPtr = static_cast(aDest); + DebugOnly byteSrcPtr = static_cast(aSrc); + MOZ_ASSERT((byteDestPtr <= byteSrcPtr && + byteDestPtr + aCount <= byteSrcPtr) || + (byteSrcPtr <= byteDestPtr && + byteSrcPtr + aCount <= byteDestPtr)); + } - template - static void assertAligned(T* ptr) - { - MOZ_ASSERT((uintptr_t(ptr) % sizeof(T)) == 0, "Unaligned pointer!"); + template + static void assertAligned(T* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % sizeof(T)) == 0, "Unaligned pointer!"); + } + +protected: + /** + * Return |aValue| converted from SourceEndian encoding to DestEndian + * encoding. + */ + template + static inline T maybeSwap(T aValue) + { + if (SourceEndian == DestEndian) { + return aValue; } + return Swapper::swap(aValue); + } - protected: - /** - * Return |value| converted from SourceEndian encoding to DestEndian - * encoding. - */ - template - static inline T maybeSwap(T value) - { - if (SourceEndian == DestEndian) - return value; + /** + * Convert |aCount| elements at |aPtr| from SourceEndian encoding to + * DestEndian encoding. + */ + template + static inline void maybeSwapInPlace(T* aPtr, size_t aCount) + { + assertAligned(aPtr); - return Swapper::swap(value); + if (SourceEndian == DestEndian) { + return; } + for (size_t i = 0; i < aCount; i++) { + aPtr[i] = Swapper::swap(aPtr[i]); + } + } - /** - * Convert |count| elements at |ptr| from SourceEndian encoding to - * DestEndian encoding. - */ - template - static inline void maybeSwapInPlace(T* ptr, size_t count) - { - assertAligned(ptr); + /** + * Write |aCount| elements to the unaligned address |aDest| in DestEndian + * format, using elements found at |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapTo(void* aDest, const T* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aSrc); - if (SourceEndian == DestEndian) - return; + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; + } - for (size_t i = 0; i < count; i++) - ptr[i] = Swapper::swap(ptr[i]); + uint8_t* byteDestPtr = static_cast(aDest); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + u.mVal = maybeSwap(aSrc[i]); + memcpy(byteDestPtr, u.mBuffer, sizeof(T)); + byteDestPtr += sizeof(T); } + } - /** - * Write |count| elements to the unaligned address |dest| in DestEndian - * format, using elements found at |src| in SourceEndian format. - */ - template - static void copyAndSwapTo(void* dest, const T* src, size_t count) - { - assertNoOverlap(dest, src, count * sizeof(T)); - assertAligned(src); - - if (SourceEndian == DestEndian) { - memcpy(dest, src, count * sizeof(T)); - return; - } - - uint8_t* byteDestPtr = static_cast(dest); - for (size_t i = 0; i < count; ++i) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - u.val = maybeSwap(src[i]); - memcpy(byteDestPtr, u.buffer, sizeof(T)); - byteDestPtr += sizeof(T); - } + /** + * Write |aCount| elements to |aDest| in DestEndian format, using elements + * found at the unaligned address |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapFrom(T* aDest, const void* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aDest); + + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; } - /** - * Write |count| elements to |dest| in DestEndian format, using elements - * found at the unaligned address |src| in SourceEndian format. - */ - template - static void copyAndSwapFrom(T* dest, const void* src, size_t count) - { - assertNoOverlap(dest, src, count * sizeof(T)); - assertAligned(dest); - - if (SourceEndian == DestEndian) { - memcpy(dest, src, count * sizeof(T)); - return; - } - - const uint8_t* byteSrcPtr = static_cast(src); - for (size_t i = 0; i < count; ++i) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - memcpy(u.buffer, byteSrcPtr, sizeof(T)); - dest[i] = maybeSwap(u.val); - byteSrcPtr += sizeof(T); - } + const uint8_t* byteSrcPtr = static_cast(aSrc); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, byteSrcPtr, sizeof(T)); + aDest[i] = maybeSwap(u.mVal); + byteSrcPtr += sizeof(T); } + } }; template class Endian : private EndianUtils { - protected: - /** Read a uint16_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint16_t readUint16(const void* p) { - return read(p); - } +protected: + /** Read a uint16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint16_t readUint16(const void* aPtr) + { + return read(aPtr); + } - /** Read a uint32_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint32_t readUint32(const void* p) { - return read(p); - } + /** Read a uint32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint32_t readUint32(const void* aPtr) + { + return read(aPtr); + } - /** Read a uint64_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint64_t readUint64(const void* p) { - return read(p); - } + /** Read a uint64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint64_t readUint64(const void* aPtr) + { + return read(aPtr); + } - /** Read an int16_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int16_t readInt16(const void* p) { - return read(p); - } + /** Read an int16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int16_t readInt16(const void* aPtr) + { + return read(aPtr); + } - /** Read an int32_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int32_t readInt32(const void* p) { - return read(p); - } + /** Read an int32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int32_t readInt32(const void* aPtr) + { + return read(aPtr); + } - /** Read an int64_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int64_t readInt64(const void* p) { - return read(p); - } + /** Read an int64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int64_t readInt64(const void* aPtr) + { + return read(aPtr); + } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint16(void* p, uint16_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint32(void* p, uint32_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint64(void* p, uint64_t val) { - write(p, val); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint16(void* aPtr, uint16_t aValue) + { + write(aPtr, aValue); + } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt16(void* p, int16_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt32(void* p, int32_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt64(void* p, int64_t val) { - write(p, val); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint32(void* aPtr, uint32_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T to little-endian format. - * - * This function is intended for cases where you have data in your - * native-endian format and you need it to appear in little-endian - * format for transmission. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToLittleEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to little-endian format if ThisEndian is Big. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapToLittleEndian(void* dest, const T* src, - size_t count) { - copyAndSwapTo(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapToLittleEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint64(void* aPtr, uint64_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T to big-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToBigEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to big-endian format if ThisEndian is Little. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapToBigEndian(void* dest, const T* src, size_t count) { - copyAndSwapTo(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapToBigEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt16(void* aPtr, int16_t aValue) + { + write(aPtr, aValue); + } - /* - * Synonyms for the big-endian functions, for better readability - * in network code. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToNetworkOrder(T value) { - return swapToBigEndian(value); - } - template - static void - copyAndSwapToNetworkOrder(void* dest, const T* src, size_t count) { - copyAndSwapToBigEndian(dest, src, count); - } - template - static void - swapToNetworkOrderInPlace(T* p, size_t count) { - swapToBigEndianInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt32(void* aPtr, int32_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T from little-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromLittleEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to little-endian format if ThisEndian is Big. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapFromLittleEndian(T* dest, const void* src, - size_t count) { - copyAndSwapFrom(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapFromLittleEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt64(void* aPtr, int64_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T from big-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromBigEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to big-endian format if ThisEndian is Little. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapFromBigEndian(T* dest, const void* src, - size_t count) { - copyAndSwapFrom(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapFromBigEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /* + * Converts a value of type T to little-endian format. + * + * This function is intended for cases where you have data in your + * native-endian format and you need it to appear in little-endian + * format for transmission. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToLittleEndian(T aValue) + { + return maybeSwap(aValue); + } - /* - * Synonyms for the big-endian functions, for better readability - * in network code. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromNetworkOrder(T value) { - return swapFromBigEndian(value); - } - template - static void copyAndSwapFromNetworkOrder(T* dest, const void* src, - size_t count) { - copyAndSwapFromBigEndian(dest, src, count); - } - template - static void swapFromNetworkOrderInPlace(T* p, size_t count) { - swapFromBigEndianInPlace(p, count); - } + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToLittleEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } - private: - /** - * Read a value of type T, encoded in endianness ThisEndian from |p|. - * Return that value encoded in native endianness. - */ - template - static T read(const void* p) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - memcpy(u.buffer, p, sizeof(T)); - return maybeSwap(u.val); - } + /* + * Likewise, but converts values in place. + */ + template + static void swapToLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } - /** - * Write a value of type T, in native endianness, to |p|, in ThisEndian - * endianness. - */ - template - static void write(void* p, T value) { - T tmp = maybeSwap(value); - memcpy(p, &tmp, sizeof(T)); - } + /* + * Converts a value of type T to big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToBigEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapToBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + + template + MOZ_WARN_UNUSED_RESULT static T swapToNetworkOrder(T aValue) + { + return swapToBigEndian(aValue); + } + + template + static void + copyAndSwapToNetworkOrder(void* aDest, const T* aSrc, size_t aCount) + { + copyAndSwapToBigEndian(aDest, aSrc, aCount); + } + + template + static void + swapToNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapToBigEndianInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from little-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromLittleEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromLittleEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromBigEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromNetworkOrder(T aValue) + { + return swapFromBigEndian(aValue); + } + + template + static void copyAndSwapFromNetworkOrder(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFromBigEndian(aDest, aSrc, aCount); + } + + template + static void swapFromNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapFromBigEndianInPlace(aPtr, aCount); + } + +private: + /** + * Read a value of type T, encoded in endianness ThisEndian from |aPtr|. + * Return that value encoded in native endianness. + */ + template + static T read(const void* aPtr) + { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, aPtr, sizeof(T)); + return maybeSwap(u.mVal); + } + + /** + * Write a value of type T, in native endianness, to |aPtr|, in ThisEndian + * endianness. + */ + template + static void write(void* aPtr, T aValue) + { + T tmp = maybeSwap(aValue); + memcpy(aPtr, &tmp, sizeof(T)); + } - Endian() MOZ_DELETE; - Endian(const Endian& other) MOZ_DELETE; - void operator=(const Endian& other) MOZ_DELETE; + Endian() MOZ_DELETE; + Endian(const Endian& aTther) MOZ_DELETE; + void operator=(const Endian& aOther) MOZ_DELETE; }; template class EndianReadWrite : public Endian { - private: - typedef Endian super; - - public: - using super::readUint16; - using super::readUint32; - using super::readUint64; - using super::readInt16; - using super::readInt32; - using super::readInt64; - using super::writeUint16; - using super::writeUint32; - using super::writeUint64; - using super::writeInt16; - using super::writeInt32; - using super::writeInt64; +private: + typedef Endian super; + +public: + using super::readUint16; + using super::readUint32; + using super::readUint64; + using super::readInt16; + using super::readInt32; + using super::readInt64; + using super::writeUint16; + using super::writeUint32; + using super::writeUint64; + using super::writeInt16; + using super::writeInt32; + using super::writeInt64; }; } /* namespace detail */ @@ -598,39 +653,39 @@ typedef BigEndian NetworkEndian; class NativeEndian MOZ_FINAL : public detail::Endian { - private: - typedef detail::Endian super; - - public: - /* - * These functions are intended for cases where you have data in your - * native-endian format and you need the data to appear in the appropriate - * endianness for transmission, serialization, etc. - */ - using super::swapToLittleEndian; - using super::copyAndSwapToLittleEndian; - using super::swapToLittleEndianInPlace; - using super::swapToBigEndian; - using super::copyAndSwapToBigEndian; - using super::swapToBigEndianInPlace; - using super::swapToNetworkOrder; - using super::copyAndSwapToNetworkOrder; - using super::swapToNetworkOrderInPlace; - - /* - * These functions are intended for cases where you have data in the - * given endianness (e.g. reading from disk or a file-format) and you - * need the data to appear in native-endian format for processing. - */ - using super::swapFromLittleEndian; - using super::copyAndSwapFromLittleEndian; - using super::swapFromLittleEndianInPlace; - using super::swapFromBigEndian; - using super::copyAndSwapFromBigEndian; - using super::swapFromBigEndianInPlace; - using super::swapFromNetworkOrder; - using super::copyAndSwapFromNetworkOrder; - using super::swapFromNetworkOrderInPlace; +private: + typedef detail::Endian super; + +public: + /* + * These functions are intended for cases where you have data in your + * native-endian format and you need the data to appear in the appropriate + * endianness for transmission, serialization, etc. + */ + using super::swapToLittleEndian; + using super::copyAndSwapToLittleEndian; + using super::swapToLittleEndianInPlace; + using super::swapToBigEndian; + using super::copyAndSwapToBigEndian; + using super::swapToBigEndianInPlace; + using super::swapToNetworkOrder; + using super::copyAndSwapToNetworkOrder; + using super::swapToNetworkOrderInPlace; + + /* + * These functions are intended for cases where you have data in the + * given endianness (e.g. reading from disk or a file-format) and you + * need the data to appear in native-endian format for processing. + */ + using super::swapFromLittleEndian; + using super::copyAndSwapFromLittleEndian; + using super::swapFromLittleEndianInPlace; + using super::swapFromBigEndian; + using super::copyAndSwapFromBigEndian; + using super::swapFromBigEndianInPlace; + using super::swapFromNetworkOrder; + using super::copyAndSwapFromNetworkOrder; + using super::swapFromNetworkOrderInPlace; }; #undef MOZ_NATIVE_ENDIANNESS diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/EnumSet.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/EnumSet.h index 95c5608cf4..8c78b2b442 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/EnumSet.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/EnumSet.h @@ -10,6 +10,7 @@ #define mozilla_EnumSet_h #include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" #include @@ -23,153 +24,181 @@ namespace mozilla { template class EnumSet { - public: - EnumSet() - : mBitField(0) - { } - - EnumSet(T aEnum) - : mBitField(aEnum) - { } - - EnumSet(T aEnum1, T aEnum2) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2)) - { } - - EnumSet(T aEnum1, T aEnum2, T aEnum3) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2) | - bitFor(aEnum3)) - { } - - EnumSet(T aEnum1, T aEnum2, T aEnum3, T aEnum4) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2) | - bitFor(aEnum3) | - bitFor(aEnum4)) - { } - - EnumSet(const EnumSet& aEnumSet) - : mBitField(aEnumSet.mBitField) - { } - - /** - * Add an element - */ - void operator+=(T aEnum) { - mBitField |= bitFor(aEnum); - } - - /** - * Add an element - */ - EnumSet operator+(T aEnum) const { - EnumSet result(*this); - result += aEnum; - return result; - } - - /** - * Union - */ - void operator+=(const EnumSet aEnumSet) { - mBitField |= aEnumSet.mBitField; - } - - /** - * Union - */ - EnumSet operator+(const EnumSet aEnumSet) const { - EnumSet result(*this); - result += aEnumSet; - return result; - } - - /** - * Remove an element - */ - void operator-=(T aEnum) { - mBitField &= ~(bitFor(aEnum)); - } - - /** - * Remove an element - */ - EnumSet operator-(T aEnum) const { - EnumSet result(*this); - result -= aEnum; - return result; - } - - /** - * Remove a set of elements - */ - void operator-=(const EnumSet aEnumSet) { - mBitField &= ~(aEnumSet.mBitField); - } - - /** - * Remove a set of elements - */ - EnumSet operator-(const EnumSet aEnumSet) const { - EnumSet result(*this); - result -= aEnumSet; - return result; - } - - /** - * Intersection - */ - void operator&=(const EnumSet aEnumSet) { - mBitField &= aEnumSet.mBitField; - } - - /** - * Intersection - */ - EnumSet operator&(const EnumSet aEnumSet) const { - EnumSet result(*this); - result &= aEnumSet; - return result; - } - - /** - * Equality - */ - - bool operator==(const EnumSet aEnumSet) const { - return mBitField == aEnumSet.mBitField; - } - - /** - * Test is an element is contained in the set - */ - bool contains(T aEnum) const { - return mBitField & bitFor(aEnum); - } - - /** - * Return the number of elements in the set - */ - - uint8_t size() { - uint8_t count = 0; - for (uint32_t bitField = mBitField; bitField; bitField >>= 1) { - if (bitField & 1) - count++; +public: + EnumSet() + : mBitField(0) + { } + + MOZ_IMPLICIT EnumSet(T aEnum) + : mBitField(bitFor(aEnum)) + { } + + EnumSet(T aEnum1, T aEnum2) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3, T aEnum4) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3) | + bitFor(aEnum4)) + { } + + EnumSet(const EnumSet& aEnumSet) + : mBitField(aEnumSet.mBitField) + { } + + /** + * Add an element + */ + void operator+=(T aEnum) + { + mBitField |= bitFor(aEnum); + } + + /** + * Add an element + */ + EnumSet operator+(T aEnum) const + { + EnumSet result(*this); + result += aEnum; + return result; + } + + /** + * Union + */ + void operator+=(const EnumSet aEnumSet) + { + mBitField |= aEnumSet.mBitField; + } + + /** + * Union + */ + EnumSet operator+(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result += aEnumSet; + return result; + } + + /** + * Remove an element + */ + void operator-=(T aEnum) + { + mBitField &= ~(bitFor(aEnum)); + } + + /** + * Remove an element + */ + EnumSet operator-(T aEnum) const + { + EnumSet result(*this); + result -= aEnum; + return result; + } + + /** + * Remove a set of elements + */ + void operator-=(const EnumSet aEnumSet) + { + mBitField &= ~(aEnumSet.mBitField); + } + + /** + * Remove a set of elements + */ + EnumSet operator-(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result -= aEnumSet; + return result; + } + + /** + * Intersection + */ + void operator&=(const EnumSet aEnumSet) + { + mBitField &= aEnumSet.mBitField; + } + + /** + * Intersection + */ + EnumSet operator&(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result &= aEnumSet; + return result; + } + + /** + * Equality + */ + bool operator==(const EnumSet aEnumSet) const + { + return mBitField == aEnumSet.mBitField; + } + + /** + * Test is an element is contained in the set. + */ + bool contains(T aEnum) const + { + return mBitField & bitFor(aEnum); + } + + /** + * Return the number of elements in the set. + */ + uint8_t size() + { + uint8_t count = 0; + for (uint32_t bitField = mBitField; bitField; bitField >>= 1) { + if (bitField & 1) { + count++; } - return count; } - - private: - static uint32_t bitFor(T aEnum) { - uint32_t bitNumber(aEnum); - MOZ_ASSERT(bitNumber < 32); - return 1U << bitNumber; - } - - uint32_t mBitField; + return count; + } + + bool isEmpty() const + { + return mBitField == 0; + } + + uint32_t serialize() const + { + return mBitField; + } + + void deserialize(uint32_t aValue) + { + mBitField = aValue; + } + +private: + static uint32_t bitFor(T aEnum) + { + uint32_t bitNumber = (uint32_t)aEnum; + MOZ_ASSERT(bitNumber < 32); + return 1U << bitNumber; + } + + uint32_t mBitField; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/EnumeratedArray.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/EnumeratedArray.h new file mode 100644 index 0000000000..7e8e89275f --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/EnumeratedArray.h @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* EnumeratedArray is like Array, but indexed by a typed enum. */ + +#ifndef mozilla_EnumeratedArray_h +#define mozilla_EnumeratedArray_h + +#include "mozilla/Array.h" +#include "mozilla/TypedEnum.h" + +namespace mozilla { + +/** + * EnumeratedArray is a fixed-size array container for use when an + * array is indexed by a specific enum class, as currently implemented + * by MOZ_BEGIN_ENUM_CLASS. + * + * This provides type safety by guarding at compile time against accidentally + * indexing such arrays with unrelated values. This also removes the need + * for manual casting when using a typed enum value to index arrays. + * + * Aside from the typing of indices, EnumeratedArray is similar to Array. + * + * Example: + * + * MOZ_BEGIN_ENUM_CLASS(AnimalSpecies) + * Cow, + * Sheep, + * Count + * MOZ_END_ENUM_CLASS(AnimalSpecies) + * + * EnumeratedArray headCount; + * + * headCount[AnimalSpecies::Cow] = 17; + * headCount[AnimalSpecies::Sheep] = 30; + * + */ +template +class EnumeratedArray +{ +public: + static const size_t kSize = size_t(SizeAsEnumValue); + +private: + Array mArray; + +public: + EnumeratedArray() {} + + explicit EnumeratedArray(const EnumeratedArray& aOther) + { + for (size_t i = 0; i < kSize; i++) { + mArray[i] = aOther.mArray[i]; + } + } + + ValueType& operator[](IndexType aIndex) + { + return mArray[size_t(aIndex)]; + } + + const ValueType& operator[](IndexType aIndex) const + { + return mArray[size_t(aIndex)]; + } +}; + +} // namespace mozilla + +#endif // mozilla_EnumeratedArray_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/FloatingPoint.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/FloatingPoint.h index 7d6b28b413..0ed567832b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/FloatingPoint.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/FloatingPoint.h @@ -12,6 +12,7 @@ #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/Casting.h" +#include "mozilla/MathAlgorithms.h" #include "mozilla/Types.h" #include @@ -33,211 +34,274 @@ namespace mozilla { * compiler bustage, particularly PGO-specific bustage. */ -/* - * These implementations all assume |double| is a 64-bit double format number - * type, compatible with the IEEE-754 standard. C/C++ don't require this to be - * the case. But we required this in implementations of these algorithms that - * preceded this header, so we shouldn't break anything if we continue doing so. - */ -static_assert(sizeof(double) == sizeof(uint64_t), "double must be 64 bits"); +struct FloatTypeTraits +{ + typedef uint32_t Bits; -const unsigned DoubleExponentBias = 1023; -const unsigned DoubleExponentShift = 52; + static const unsigned kExponentBias = 127; + static const unsigned kExponentShift = 23; -const uint64_t DoubleSignBit = 0x8000000000000000ULL; -const uint64_t DoubleExponentBits = 0x7ff0000000000000ULL; -const uint64_t DoubleSignificandBits = 0x000fffffffffffffULL; + static const Bits kSignBit = 0x80000000UL; + static const Bits kExponentBits = 0x7F800000UL; + static const Bits kSignificandBits = 0x007FFFFFUL; +}; + +struct DoubleTypeTraits +{ + typedef uint64_t Bits; -static_assert((DoubleSignBit & DoubleExponentBits) == 0, - "sign bit doesn't overlap exponent bits"); -static_assert((DoubleSignBit & DoubleSignificandBits) == 0, - "sign bit doesn't overlap significand bits"); -static_assert((DoubleExponentBits & DoubleSignificandBits) == 0, - "exponent bits don't overlap significand bits"); + static const unsigned kExponentBias = 1023; + static const unsigned kExponentShift = 52; -static_assert((DoubleSignBit | DoubleExponentBits | DoubleSignificandBits) == - ~uint64_t(0), - "all bits accounted for"); + static const Bits kSignBit = 0x8000000000000000ULL; + static const Bits kExponentBits = 0x7ff0000000000000ULL; + static const Bits kSignificandBits = 0x000fffffffffffffULL; +}; + +template struct SelectTrait; +template<> struct SelectTrait : public FloatTypeTraits {}; +template<> struct SelectTrait : public DoubleTypeTraits {}; /* - * Ditto for |float| that must be a 32-bit double format number type, compatible - * with the IEEE-754 standard. + * This struct contains details regarding the encoding of floating-point + * numbers that can be useful for direct bit manipulation. As of now, the + * template parameter has to be float or double. + * + * The nested typedef |Bits| is the unsigned integral type with the same size + * as T: uint32_t for float and uint64_t for double (static assertions + * double-check these assumptions). + * + * kExponentBias is the offset that is subtracted from the exponent when + * computing the value, i.e. one plus the opposite of the mininum possible + * exponent. + * kExponentShift is the shift that one needs to apply to retrieve the + * exponent component of the value. + * + * kSignBit contains a bits mask. Bit-and-ing with this mask will result in + * obtaining the sign bit. + * kExponentBits contains the mask needed for obtaining the exponent bits and + * kSignificandBits contains the mask needed for obtaining the significand + * bits. + * + * Full details of how floating point number formats are encoded are beyond + * the scope of this comment. For more information, see + * http://en.wikipedia.org/wiki/IEEE_floating_point + * http://en.wikipedia.org/wiki/Floating_point#IEEE_754:_floating_point_in_modern_computers */ -static_assert(sizeof(float) == sizeof(uint32_t), "float must be 32bits"); - -const unsigned FloatExponentBias = 127; -const unsigned FloatExponentShift = 23; +template +struct FloatingPoint : public SelectTrait +{ + typedef SelectTrait Base; + typedef typename Base::Bits Bits; -const uint32_t FloatSignBit = 0x80000000UL; -const uint32_t FloatExponentBits = 0x7F800000UL; -const uint32_t FloatSignificandBits = 0x007FFFFFUL; + static_assert((Base::kSignBit & Base::kExponentBits) == 0, + "sign bit shouldn't overlap exponent bits"); + static_assert((Base::kSignBit & Base::kSignificandBits) == 0, + "sign bit shouldn't overlap significand bits"); + static_assert((Base::kExponentBits & Base::kSignificandBits) == 0, + "exponent bits shouldn't overlap significand bits"); -static_assert((FloatSignBit & FloatExponentBits) == 0, - "sign bit doesn't overlap exponent bits"); -static_assert((FloatSignBit & FloatSignificandBits) == 0, - "sign bit doesn't overlap significand bits"); -static_assert((FloatExponentBits & FloatSignificandBits) == 0, - "exponent bits don't overlap significand bits"); + static_assert((Base::kSignBit | Base::kExponentBits | Base::kSignificandBits) == + ~Bits(0), + "all bits accounted for"); -static_assert((FloatSignBit | FloatExponentBits | FloatSignificandBits) == - ~uint32_t(0), - "all bits accounted for"); + /* + * These implementations assume float/double are 32/64-bit single/double + * format number types compatible with the IEEE-754 standard. C++ don't + * require this to be the case. But we required this in implementations of + * these algorithms that preceded this header, so we shouldn't break anything + * if we keep doing so. + */ + static_assert(sizeof(T) == sizeof(Bits), "Bits must be same size as T"); +}; /** Determines whether a double is NaN. */ +template static MOZ_ALWAYS_INLINE bool -IsNaN(double d) +IsNaN(T aValue) { /* - * A double is NaN if all exponent bits are 1 and the significand contains at - * least one non-zero bit. + * A float/double is NaN if all exponent bits are 1 and the significand + * contains at least one non-zero bit. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleExponentBits) == DoubleExponentBits && - (bits & DoubleSignificandBits) != 0; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) == Traits::kExponentBits && + (bits & Traits::kSignificandBits) != 0; } -/** Determines whether a double is +Infinity or -Infinity. */ +/** Determines whether a float/double is +Infinity or -Infinity. */ +template static MOZ_ALWAYS_INLINE bool -IsInfinite(double d) +IsInfinite(T aValue) { /* Infinities have all exponent bits set to 1 and an all-0 significand. */ - uint64_t bits = BitwiseCast(d); - return (bits & ~DoubleSignBit) == DoubleExponentBits; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & ~Traits::kSignBit) == Traits::kExponentBits; } -/** Determines whether a double is not NaN or infinite. */ +/** Determines whether a float/double is not NaN or infinite. */ +template static MOZ_ALWAYS_INLINE bool -IsFinite(double d) +IsFinite(T aValue) { /* - * NaN and Infinities are the only non-finite doubles, and both have all - * exponent bits set to 1. + * NaN and Infinities are the only non-finite floats/doubles, and both have + * all exponent bits set to 1. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleExponentBits) != DoubleExponentBits; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) != Traits::kExponentBits; } /** - * Determines whether a double is negative. It is an error to call this method - * on a double which is NaN. + * Determines whether a float/double is negative. It is an error to call this + * method on a float/double which is NaN. */ +template static MOZ_ALWAYS_INLINE bool -IsNegative(double d) +IsNegative(T aValue) { - MOZ_ASSERT(!IsNaN(d), "NaN does not have a sign"); + MOZ_ASSERT(!IsNaN(aValue), "NaN does not have a sign"); /* The sign bit is set if the double is negative. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleSignBit) != 0; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kSignBit) != 0; } -/** Determines whether a double represents -0. */ +/** Determines whether a float/double represents -0. */ +template static MOZ_ALWAYS_INLINE bool -IsNegativeZero(double d) +IsNegativeZero(T aValue) { - /* Only the sign bit is set if the double is -0. */ - uint64_t bits = BitwiseCast(d); - return bits == DoubleSignBit; + /* Only the sign bit is set if the value is -0. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return bits == Traits::kSignBit; } /** - * Returns the exponent portion of the double. + * Returns the exponent portion of the float/double. * * Zero is not special-cased, so ExponentComponent(0.0) is - * -int_fast16_t(DoubleExponentBias). + * -int_fast16_t(Traits::kExponentBias). */ +template static MOZ_ALWAYS_INLINE int_fast16_t -ExponentComponent(double d) +ExponentComponent(T aValue) { /* - * The exponent component of a double is an unsigned number, biased from its - * actual value. Subtract the bias to retrieve the actual exponent. + * The exponent component of a float/double is an unsigned number, biased + * from its actual value. Subtract the bias to retrieve the actual exponent. */ - uint64_t bits = BitwiseCast(d); - return int_fast16_t((bits & DoubleExponentBits) >> DoubleExponentShift) - - int_fast16_t(DoubleExponentBias); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return int_fast16_t((bits & Traits::kExponentBits) >> Traits::kExponentShift) - + int_fast16_t(Traits::kExponentBias); } /** Returns +Infinity. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T PositiveInfinity() { /* * Positive infinity has all exponent bits set, sign bit set to 0, and no * significand. */ - return BitwiseCast(DoubleExponentBits); + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kExponentBits); } /** Returns -Infinity. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T NegativeInfinity() { /* * Negative infinity has all exponent bits set, sign bit set to 1, and no * significand. */ - return BitwiseCast(DoubleSignBit | DoubleExponentBits); + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kSignBit | Traits::kExponentBits); } + /** Constructs a NaN value with the specified sign bit and significand bits. */ -static MOZ_ALWAYS_INLINE double -SpecificNaN(int signbit, uint64_t significand) +template +static MOZ_ALWAYS_INLINE T +SpecificNaN(int signbit, typename FloatingPoint::Bits significand) { + typedef FloatingPoint Traits; MOZ_ASSERT(signbit == 0 || signbit == 1); - MOZ_ASSERT((significand & ~DoubleSignificandBits) == 0); - MOZ_ASSERT(significand & DoubleSignificandBits); - - double d = BitwiseCast((signbit ? DoubleSignBit : 0) | - DoubleExponentBits | - significand); - MOZ_ASSERT(IsNaN(d)); - return d; + MOZ_ASSERT((significand & ~Traits::kSignificandBits) == 0); + MOZ_ASSERT(significand & Traits::kSignificandBits); + + T t = BitwiseCast((signbit ? Traits::kSignBit : 0) | + Traits::kExponentBits | + significand); + MOZ_ASSERT(IsNaN(t)); + return t; } -/** Computes the smallest non-zero positive double value. */ -static MOZ_ALWAYS_INLINE double -MinDoubleValue() +/** Computes the smallest non-zero positive float/double value. */ +template +static MOZ_ALWAYS_INLINE T +MinNumberValue() { - return BitwiseCast(uint64_t(1)); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + return BitwiseCast(Bits(1)); } /** - * If d is equal to some int32_t value, set *i to that value and return true; - * otherwise return false. + * If aValue is equal to some int32_t value, set *aInt32 to that value and + * return true; otherwise return false. * * Note that negative zero is "equal" to zero here. To test whether a value can - * be losslessly converted to int32_t and back, use DoubleIsInt32 instead. + * be losslessly converted to int32_t and back, use NumberIsInt32 instead. */ +template static MOZ_ALWAYS_INLINE bool -DoubleEqualsInt32(double d, int32_t* i) +NumberEqualsInt32(T aValue, int32_t* aInt32) { /* - * XXX Casting a double that doesn't truncate to int32_t, to int32_t, induces - * undefined behavior. We should definitely fix this (bug 744965), but as - * apparently it "works" in practice, it's not a pressing concern now. + * XXX Casting a floating-point value that doesn't truncate to int32_t, to + * int32_t, induces undefined behavior. We should definitely fix this + * (bug 744965), but as apparently it "works" in practice, it's not a + * pressing concern now. */ - return d == (*i = int32_t(d)); + return aValue == (*aInt32 = int32_t(aValue)); } /** * If d can be converted to int32_t and back to an identical double value, - * set *i to that value and return true; otherwise return false. + * set *aInt32 to that value and return true; otherwise return false. * - * The difference between this and DoubleEqualsInt32 is that this method returns + * The difference between this and NumberEqualsInt32 is that this method returns * false for negative zero. */ +template static MOZ_ALWAYS_INLINE bool -DoubleIsInt32(double d, int32_t* i) +NumberIsInt32(T aValue, int32_t* aInt32) { - return !IsNegativeZero(d) && DoubleEqualsInt32(d, i); + return !IsNegativeZero(aValue) && NumberEqualsInt32(aValue, aInt32); } /** * Computes a NaN value. Do not use this method if you depend upon a particular * NaN value being returned. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T UnspecifiedNaN() { /* @@ -246,7 +310,8 @@ UnspecifiedNaN() * this value can be represented in a 32-bit signed immediate field, allowing * it to be stored to memory in a single instruction). */ - return SpecificNaN(1, 0xfffffffffffffULL); + typedef FloatingPoint Traits; + return SpecificNaN(1, Traits::kSignificandBits); } /** @@ -254,40 +319,81 @@ UnspecifiedNaN() * any NaN value to any other NaN value. (The normal equality operators equate * -0 with +0, and they equate NaN to no other value.) */ +template static inline bool -DoublesAreIdentical(double d1, double d2) +NumbersAreIdentical(T aValue1, T aValue2) { - if (IsNaN(d1)) - return IsNaN(d2); - return BitwiseCast(d1) == BitwiseCast(d2); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + if (IsNaN(aValue1)) { + return IsNaN(aValue2); + } + return BitwiseCast(aValue1) == BitwiseCast(aValue2); } -/** Determines whether a float is NaN. */ +namespace detail { + +template +struct FuzzyEqualsEpsilon; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-5 that is exactly representable in a float. + static float value() { return 1.0f / (1 << 17); } +}; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-12 that is exactly representable in a double. + static double value() { return 1.0 / (1LL << 40); } +}; + +} // namespace detail + +/** + * Compare two floating point values for equality, modulo rounding error. That + * is, the two values are considered equal if they are both not NaN and if they + * are less than or equal to aEpsilon apart. The default value of aEpsilon is + * near 1e-5. + * + * For most scenarios you will want to use FuzzyEqualsMultiplicative instead, + * as it is more reasonable over the entire range of floating point numbers. + * This additive version should only be used if you know the range of the + * numbers you are dealing with is bounded and stays around the same order of + * magnitude. + */ +template static MOZ_ALWAYS_INLINE bool -IsFloatNaN(float f) +FuzzyEqualsAdditive(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) { - /* - * A float is NaN if all exponent bits are 1 and the significand contains at - * least one non-zero bit. - */ - uint32_t bits = BitwiseCast(f); - return (bits & FloatExponentBits) == FloatExponentBits && - (bits & FloatSignificandBits) != 0; + static_assert(IsFloatingPoint::value, "floating point type required"); + return Abs(aValue1 - aValue2) <= aEpsilon; } -/** Constructs a NaN value with the specified sign bit and significand bits. */ -static MOZ_ALWAYS_INLINE float -SpecificFloatNaN(int signbit, uint32_t significand) +/** + * Compare two floating point values for equality, allowing for rounding error + * relative to the magnitude of the values. That is, the two values are + * considered equal if they are both not NaN and they are less than or equal to + * some aEpsilon apart, where the aEpsilon is scaled by the smaller of the two + * argument values. + * + * In most cases you will want to use this rather than FuzzyEqualsAdditive, as + * this function effectively masks out differences in the bottom few bits of + * the floating point numbers being compared, regardless of what order of + * magnitude those numbers are at. + */ +template +static MOZ_ALWAYS_INLINE bool +FuzzyEqualsMultiplicative(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) { - MOZ_ASSERT(signbit == 0 || signbit == 1); - MOZ_ASSERT((significand & ~FloatSignificandBits) == 0); - MOZ_ASSERT(significand & FloatSignificandBits); - - float f = BitwiseCast((signbit ? FloatSignBit : 0) | - FloatExponentBits | - significand); - MOZ_ASSERT(IsFloatNaN(f)); - return f; + static_assert(IsFloatingPoint::value, "floating point type required"); + // can't use std::min because of bug 965340 + T smaller = Abs(aValue1) < Abs(aValue2) ? Abs(aValue1) : Abs(aValue2); + return Abs(aValue1 - aValue2) <= aEpsilon * smaller; } /** @@ -300,7 +406,7 @@ SpecificFloatNaN(int signbit, uint32_t significand) */ MOZ_WARN_UNUSED_RESULT extern MFBT_API bool -IsFloat32Representable(double x); +IsFloat32Representable(double aFloat32); } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/GuardObjects.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/GuardObjects.h index aeae7dcbc0..2cd950f314 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/GuardObjects.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/GuardObjects.h @@ -68,48 +68,49 @@ namespace detail { * For more details, and examples of using these macros, see * https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla */ -class MOZ_EXPORT GuardObjectNotifier +class GuardObjectNotifier { - private: - bool* statementDone; +private: + bool* mStatementDone; - public: - GuardObjectNotifier() : statementDone(nullptr) { } +public: + GuardObjectNotifier() : mStatementDone(nullptr) { } - ~GuardObjectNotifier() { - *statementDone = true; - } + ~GuardObjectNotifier() { *mStatementDone = true; } - void setStatementDone(bool* statementIsDone) { - statementDone = statementIsDone; - } + void setStatementDone(bool* aStatementIsDone) + { + mStatementDone = aStatementIsDone; + } }; -class MOZ_EXPORT GuardObjectNotificationReceiver +class GuardObjectNotificationReceiver { - private: - bool statementDone; - - public: - GuardObjectNotificationReceiver() : statementDone(false) { } - - ~GuardObjectNotificationReceiver() { - /* - * Assert that the guard object was not used as a temporary. (Note that - * this assert might also fire if init is not called because the guard - * object's implementation is not using the above macros correctly.) - */ - MOZ_ASSERT(statementDone); - } - - void init(const GuardObjectNotifier& constNotifier) { - /* - * constNotifier is passed as a const reference so that we can pass a - * temporary, but we really intend it as non-const. - */ - GuardObjectNotifier& notifier = const_cast(constNotifier); - notifier.setStatementDone(&statementDone); - } +private: + bool mStatementDone; + +public: + GuardObjectNotificationReceiver() : mStatementDone(false) { } + + ~GuardObjectNotificationReceiver() { + /* + * Assert that the guard object was not used as a temporary. (Note that + * this assert might also fire if init is not called because the guard + * object's implementation is not using the above macros correctly.) + */ + MOZ_ASSERT(mStatementDone); + } + + void init(const GuardObjectNotifier& aConstNotifier) + { + /* + * aConstNotifier is passed as a const reference so that we can pass a + * temporary, but we really intend it as non-const. + */ + GuardObjectNotifier& notifier = + const_cast(aConstNotifier); + notifier.setStatementDone(&mStatementDone); + } }; } /* namespace detail */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/HashFunctions.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/HashFunctions.h index b228955ce5..8b2c172bd1 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/HashFunctions.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/HashFunctions.h @@ -27,16 +27,17 @@ * * class ComplexObject * { - * char* str; - * uint32_t uint1, uint2; - * void (*callbackFn)(); + * char* mStr; + * uint32_t mUint1, mUint2; + * void (*mCallbackFn)(); * - * public: - * uint32_t hash() { - * uint32_t hash = HashString(str); - * hash = AddToHash(hash, uint1, uint2); - * return AddToHash(hash, callbackFn); - * } + * public: + * uint32_t hash() + * { + * uint32_t hash = HashString(mStr); + * hash = AddToHash(hash, mUint1, mUint2); + * return AddToHash(hash, mCallbackFn); + * } * }; * * If you want to hash an nsAString or nsACString, use the HashString functions @@ -59,19 +60,19 @@ namespace mozilla { /** * The golden ratio as a 32-bit fixed-point value. */ -static const uint32_t GoldenRatioU32 = 0x9E3779B9U; +static const uint32_t kGoldenRatioU32 = 0x9E3779B9U; inline uint32_t -RotateBitsLeft32(uint32_t value, uint8_t bits) +RotateBitsLeft32(uint32_t aValue, uint8_t aBits) { - MOZ_ASSERT(bits < 32); - return (value << bits) | (value >> (32 - bits)); + MOZ_ASSERT(aBits < 32); + return (aValue << aBits) | (aValue >> (32 - aBits)); } namespace detail { inline uint32_t -AddU32ToHash(uint32_t hash, uint32_t value) +AddU32ToHash(uint32_t aHash, uint32_t aValue) { /* * This is the meat of all our hash routines. This hash function is not @@ -91,12 +92,12 @@ AddU32ToHash(uint32_t hash, uint32_t value) * preferable so our hash explores the whole universe of possible rotations. * * Finally, we multiply by the golden ratio *after* xor'ing, not before. - * Otherwise, if |hash| is 0 (as it often is for the beginning of a message), - * the expression + * Otherwise, if |aHash| is 0 (as it often is for the beginning of a + * message), the expression * - * (GoldenRatioU32 * RotateBitsLeft(hash, 5)) |xor| value + * (kGoldenRatioU32 * RotateBitsLeft(aHash, 5)) |xor| aValue * - * evaluates to |value|. + * evaluates to |aValue|. * * (Number-theoretic aside: Because any odd number |m| is relatively prime to * our modulus (2^32), the list @@ -112,7 +113,7 @@ AddU32ToHash(uint32_t hash, uint32_t value) * multiplicative effect. Our golden ratio constant has order 2^29, which is * more than enough for our purposes.) */ - return GoldenRatioU32 * (RotateBitsLeft32(hash, 5) ^ value); + return kGoldenRatioU32 * (RotateBitsLeft32(aHash, 5) ^ aValue); } /** @@ -120,29 +121,29 @@ AddU32ToHash(uint32_t hash, uint32_t value) */ template inline uint32_t -AddUintptrToHash(uint32_t hash, uintptr_t value); +AddUintptrToHash(uint32_t aHash, uintptr_t aValue); template<> inline uint32_t -AddUintptrToHash<4>(uint32_t hash, uintptr_t value) +AddUintptrToHash<4>(uint32_t aHash, uintptr_t aValue) { - return AddU32ToHash(hash, static_cast(value)); + return AddU32ToHash(aHash, static_cast(aValue)); } template<> inline uint32_t -AddUintptrToHash<8>(uint32_t hash, uintptr_t value) +AddUintptrToHash<8>(uint32_t aHash, uintptr_t aValue) { /* * The static cast to uint64_t below is necessary because this function * sometimes gets compiled on 32-bit platforms (yes, even though it's a * template and we never call this particular override in a 32-bit build). If - * we do value >> 32 on a 32-bit machine, we're shifting a 32-bit uintptr_t + * we do aValue >> 32 on a 32-bit machine, we're shifting a 32-bit uintptr_t * right 32 bits, and the compiler throws an error. */ - uint32_t v1 = static_cast(value); - uint32_t v2 = static_cast(static_cast(value) >> 32); - return AddU32ToHash(AddU32ToHash(hash, v1), v2); + uint32_t v1 = static_cast(aValue); + uint32_t v2 = static_cast(static_cast(aValue) >> 32); + return AddU32ToHash(AddU32ToHash(aHash, v1), v2); } } /* namespace detail */ @@ -155,71 +156,63 @@ AddUintptrToHash<8>(uint32_t hash, uintptr_t value) * convert to uint32_t, data pointers, and function pointers. */ template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, A a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A aA) { /* * Try to convert |A| to uint32_t implicitly. If this works, great. If not, * we'll error out. */ - return detail::AddU32ToHash(hash, a); + return detail::AddU32ToHash(aHash, aA); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, A* a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A* aA) { /* * You might think this function should just take a void*. But then we'd only * catch data pointers and couldn't handle function pointers. */ - static_assert(sizeof(a) == sizeof(uintptr_t), - "Strange pointer!"); + static_assert(sizeof(aA) == sizeof(uintptr_t), "Strange pointer!"); - return detail::AddUintptrToHash(hash, uintptr_t(a)); + return detail::AddUintptrToHash(aHash, uintptr_t(aA)); } template<> -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, uintptr_t a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, uintptr_t aA) { - return detail::AddUintptrToHash(hash, a); + return detail::AddUintptrToHash(aHash, aA); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB) { - return AddToHash(AddToHash(hash, a), b); + return AddToHash(AddToHash(aHash, aA), aB); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC) { - return AddToHash(AddToHash(hash, a, b), c); + return AddToHash(AddToHash(aHash, aA, aB), aC); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c, D d) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD) { - return AddToHash(AddToHash(hash, a, b, c), d); + return AddToHash(AddToHash(aHash, aA, aB, aC), aD); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c, D d, E e) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD, E aE) { - return AddToHash(AddToHash(hash, a, b, c, d), e); + return AddToHash(AddToHash(aHash, aA, aB, aC, aD), aE); } /** @@ -230,64 +223,61 @@ AddToHash(uint32_t hash, A a, B b, C c, D d, E e) * that x has already been hashed. */ template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA) { - return AddToHash(0, a); + return AddToHash(0, aA); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB) { - return AddToHash(0, a, b); + return AddToHash(0, aA, aB); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC) { - return AddToHash(0, a, b, c); + return AddToHash(0, aA, aB, aC); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c, D d) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD) { - return AddToHash(0, a, b, c, d); + return AddToHash(0, aA, aB, aC, aD); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c, D d, E e) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD, E aE) { - return AddToHash(0, a, b, c, d, e); + return AddToHash(0, aA, aB, aC, aD, aE); } namespace detail { template uint32_t -HashUntilZero(const T* str) +HashUntilZero(const T* aStr) { uint32_t hash = 0; - for (T c; (c = *str); str++) + for (T c; (c = *aStr); aStr++) { hash = AddToHash(hash, c); + } return hash; } template uint32_t -HashKnownLength(const T* str, size_t length) +HashKnownLength(const T* aStr, size_t aLength) { uint32_t hash = 0; - for (size_t i = 0; i < length; i++) - hash = AddToHash(hash, str[i]); + for (size_t i = 0; i < aLength; i++) { + hash = AddToHash(hash, aStr[i]); + } return hash; } @@ -299,67 +289,66 @@ HashKnownLength(const T* str, size_t length) * If you have the string's length, you might as well call the overload which * includes the length. It may be marginally faster. */ -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } MOZ_WARN_UNUSED_RESULT inline uint32_t -HashString(const uint16_t* str) +HashString(const unsigned char* aStr, size_t aLength) { - return detail::HashUntilZero(str); + return detail::HashKnownLength(aStr, aLength); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const uint16_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr) { - return detail::HashKnownLength(str, length); + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); } #ifdef MOZ_CHAR16_IS_NOT_WCHAR -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char16_t* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char16_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } #endif /* - * On Windows, wchar_t (PRUnichar) is not the same as uint16_t, even though it's + * On Windows, wchar_t (char16_t) is not the same as uint16_t, even though it's * the same width! */ #ifdef WIN32 -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const wchar_t* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const wchar_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } #endif @@ -369,9 +358,8 @@ HashString(const wchar_t* str, size_t length) * This hash walks word-by-word, rather than byte-by-byte, so you won't get the * same result out of HashBytes as you would out of HashString. */ -MOZ_WARN_UNUSED_RESULT -extern MFBT_API uint32_t -HashBytes(const void* bytes, size_t length); +MOZ_WARN_UNUSED_RESULT extern MFBT_API uint32_t +HashBytes(const void* bytes, size_t aLength); } /* namespace mozilla */ #endif /* __cplusplus */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/IntegerPrintfMacros.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/IntegerPrintfMacros.h index 1ae60d618e..ff2415a86f 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/IntegerPrintfMacros.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/IntegerPrintfMacros.h @@ -1,7 +1,8 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* Implements the C99 interface, minus the SCN* format macros. */ @@ -37,4 +38,25 @@ # include #endif +/* + * Fix up Android's broken [u]intptr_t inttype macros. Android's PRI*PTR + * macros are defined as "ld", but sizeof(long) is 8 and sizeof(intptr_t) + * is 4 on 32-bit Android. TestTypeTraits.cpp asserts that these new macro + * definitions match the actual type sizes seen at compile time. + */ +#if defined(ANDROID) && !defined(__LP64__) +# undef PRIdPTR /* intptr_t */ +# define PRIdPTR "d" /* intptr_t */ +# undef PRIiPTR /* intptr_t */ +# define PRIiPTR "i" /* intptr_t */ +# undef PRIoPTR /* uintptr_t */ +# define PRIoPTR "o" /* uintptr_t */ +# undef PRIuPTR /* uintptr_t */ +# define PRIuPTR "u" /* uintptr_t */ +# undef PRIxPTR /* uintptr_t */ +# define PRIxPTR "x" /* uintptr_t */ +# undef PRIXPTR /* uintptr_t */ +# define PRIXPTR "X" /* uintptr_t */ +#endif + #endif /* mozilla_IntegerPrintfMacros_h_ */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/IntegerTypeTraits.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/IntegerTypeTraits.h new file mode 100644 index 0000000000..9414451f91 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/IntegerTypeTraits.h @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Helpers to manipulate integer types that don't fit in TypeTraits.h */ + +#ifndef mozilla_IntegerTypeTraits_h +#define mozilla_IntegerTypeTraits_h + +#include "mozilla/TypeTraits.h" +#include + +namespace mozilla { + +namespace detail { + +/** + * StdintTypeForSizeAndSignedness returns the stdint integer type + * of given size (can be 1, 2, 4 or 8) and given signedness + * (false means unsigned, true means signed). + */ +template +struct StdintTypeForSizeAndSignedness; + +template<> +struct StdintTypeForSizeAndSignedness<1, true> +{ + typedef int8_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<1, false> +{ + typedef uint8_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<2, true> +{ + typedef int16_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<2, false> +{ + typedef uint16_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<4, true> +{ + typedef int32_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<4, false> +{ + typedef uint32_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<8, true> +{ + typedef int64_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<8, false> +{ + typedef uint64_t Type; +}; + +} // namespace detail + +template +struct UnsignedStdintTypeForSize + : detail::StdintTypeForSizeAndSignedness +{}; + +template +struct PositionOfSignBit +{ + static_assert(IsIntegral::value, + "PositionOfSignBit is only for integral types"); + // 8 here should be CHAR_BIT from limits.h, but the world has moved on. + static const size_t value = 8 * sizeof(IntegerType) - 1; +}; + +/** + * MinValue returns the minimum value of the given integer type as a + * compile-time constant, which std::numeric_limits::min() + * cannot do in c++98. + */ +template +struct MinValue +{ +private: + static_assert(IsIntegral::value, + "MinValue is only for integral types"); + + typedef typename MakeUnsigned::Type UnsignedIntegerType; + static const size_t PosOfSignBit = PositionOfSignBit::value; + +public: + // Bitwise ops may return a larger type, that's why we cast explicitly. + // In C++, left bit shifts on signed values is undefined by the standard + // unless the shifted value is representable. + // Notice that signed-to-unsigned conversions are always well-defined in + // the standard as the value congruent to 2**n, as expected. By contrast, + // unsigned-to-signed is only well-defined if the value is representable. + static const IntegerType value = + IsSigned::value + ? IntegerType(UnsignedIntegerType(1) << PosOfSignBit) + : IntegerType(0); +}; + +/** + * MaxValue returns the maximum value of the given integer type as a + * compile-time constant, which std::numeric_limits::max() + * cannot do in c++98. + */ +template +struct MaxValue +{ + static_assert(IsIntegral::value, + "MaxValue is only for integral types"); + + // Tricksy, but covered by the CheckedInt unit test. + // Relies on the type of MinValue::value + // being IntegerType. + static const IntegerType value = ~MinValue::value; +}; + +} // namespace mozilla + +#endif // mozilla_IntegerTypeTraits_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/LinkedList.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/LinkedList.h index 3aee7cde45..693c019f92 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/LinkedList.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/LinkedList.h @@ -23,32 +23,36 @@ * * class Observer : public LinkedListElement * { - * public: - * void observe(char* topic) { ... } + * public: + * void observe(char* aTopic) { ... } * }; * * class ObserverContainer * { - * private: - * LinkedList list; + * private: + * LinkedList list; * - * public: - * void addObserver(Observer* observer) { - * // Will assert if |observer| is part of another list. - * list.insertBack(observer); - * } + * public: + * void addObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is part of another list. + * list.insertBack(aObserver); + * } * - * void removeObserver(Observer* observer) { - * // Will assert if |observer| is not part of some list. - * observer.remove(); - * // Or, will assert if |observer| is not part of |list| specifically. - * // observer.removeFrom(list); - * } + * void removeObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is not part of some list. + * aObserver.remove(); + * // Or, will assert if |aObserver| is not part of |list| specifically. + * // aObserver.removeFrom(list); + * } * - * void notifyObservers(char* topic) { - * for (Observer* o = list.getFirst(); o != nullptr; o = o->getNext()) - * o->observe(topic); + * void notifyObservers(char* aTopic) + * { + * for (Observer* o = list.getFirst(); o != nullptr; o = o->getNext()) { + * o->observe(aTopic); * } + * } * }; * */ @@ -72,411 +76,407 @@ class LinkedList; template class LinkedListElement { - /* - * It's convenient that we return nullptr when getNext() or getPrevious() - * hits the end of the list, but doing so costs an extra word of storage in - * each linked list node (to keep track of whether |this| is the sentinel - * node) and a branch on this value in getNext/getPrevious. - * - * We could get rid of the extra word of storage by shoving the "is - * sentinel" bit into one of the pointers, although this would, of course, - * have performance implications of its own. - * - * But the goal here isn't to win an award for the fastest or slimmest - * linked list; rather, we want a *convenient* linked list. So we won't - * waste time guessing which micro-optimization strategy is best. - * - * - * Speaking of unnecessary work, it's worth addressing here why we wrote - * mozilla::LinkedList in the first place, instead of using stl::list. - * - * The key difference between mozilla::LinkedList and stl::list is that - * mozilla::LinkedList stores the prev/next pointers in the object itself, - * while stl::list stores the prev/next pointers in a list element which - * itself points to the object being stored. - * - * mozilla::LinkedList's approach makes it harder to store an object in more - * than one list. But the upside is that you can call next() / prev() / - * remove() directly on the object. With stl::list, you'd need to store a - * pointer to its iterator in the object in order to accomplish this. Not - * only would this waste space, but you'd have to remember to update that - * pointer every time you added or removed the object from a list. - * - * In-place, constant-time removal is a killer feature of doubly-linked - * lists, and supporting this painlessly was a key design criterion. - */ - - private: - LinkedListElement* next; - LinkedListElement* prev; - const bool isSentinel; - - public: - LinkedListElement() - : next(MOZ_THIS_IN_INITIALIZER_LIST()), - prev(MOZ_THIS_IN_INITIALIZER_LIST()), - isSentinel(false) - { } - - LinkedListElement(LinkedListElement&& other) - : isSentinel(other.isSentinel) - { - if (!other.isInList()) { - next = this; - prev = this; - return; - } - - MOZ_ASSERT(other.next->prev == &other); - MOZ_ASSERT(other.prev->next == &other); - - /* - * Initialize |this| with |other|'s prev/next pointers, and adjust those - * element to point to this one. - */ - next = other.next; - prev = other.prev; - - next->prev = this; - prev->next = this; - - /* - * Adjust |other| so it doesn't think it's in a list. This makes it - * safely destructable. - */ - other.next = &other; - other.prev = &other; - } - - ~LinkedListElement() { - if (!isSentinel && isInList()) - remove(); - } - - /* - * Get the next element in the list, or nullptr if this is the last element - * in the list. - */ - T* getNext() { - return next->asT(); - } - const T* getNext() const { - return next->asT(); + /* + * It's convenient that we return nullptr when getNext() or getPrevious() + * hits the end of the list, but doing so costs an extra word of storage in + * each linked list node (to keep track of whether |this| is the sentinel + * node) and a branch on this value in getNext/getPrevious. + * + * We could get rid of the extra word of storage by shoving the "is + * sentinel" bit into one of the pointers, although this would, of course, + * have performance implications of its own. + * + * But the goal here isn't to win an award for the fastest or slimmest + * linked list; rather, we want a *convenient* linked list. So we won't + * waste time guessing which micro-optimization strategy is best. + * + * + * Speaking of unnecessary work, it's worth addressing here why we wrote + * mozilla::LinkedList in the first place, instead of using stl::list. + * + * The key difference between mozilla::LinkedList and stl::list is that + * mozilla::LinkedList stores the mPrev/mNext pointers in the object itself, + * while stl::list stores the mPrev/mNext pointers in a list element which + * itself points to the object being stored. + * + * mozilla::LinkedList's approach makes it harder to store an object in more + * than one list. But the upside is that you can call next() / prev() / + * remove() directly on the object. With stl::list, you'd need to store a + * pointer to its iterator in the object in order to accomplish this. Not + * only would this waste space, but you'd have to remember to update that + * pointer every time you added or removed the object from a list. + * + * In-place, constant-time removal is a killer feature of doubly-linked + * lists, and supporting this painlessly was a key design criterion. + */ + +private: + LinkedListElement* mNext; + LinkedListElement* mPrev; + const bool mIsSentinel; + +public: + LinkedListElement() + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(false) + { } + + LinkedListElement(LinkedListElement&& other) + : mIsSentinel(other.mIsSentinel) + { + if (!other.isInList()) { + mNext = this; + mPrev = this; + return; } - /* - * Get the previous element in the list, or nullptr if this is the first - * element in the list. - */ - T* getPrevious() { - return prev->asT(); - } - const T* getPrevious() const { - return prev->asT(); - } + MOZ_ASSERT(other.mNext->mPrev == &other); + MOZ_ASSERT(other.mPrev->mNext == &other); /* - * Insert elem after this element in the list. |this| must be part of a - * linked list when you call setNext(); otherwise, this method will assert. + * Initialize |this| with |other|'s mPrev/mNext pointers, and adjust those + * element to point to this one. */ - void setNext(T* elem) { - MOZ_ASSERT(isInList()); - setNextUnsafe(elem); - } + mNext = other.mNext; + mPrev = other.mPrev; - /* - * Insert elem before this element in the list. |this| must be part of a - * linked list when you call setPrevious(); otherwise, this method will - * assert. - */ - void setPrevious(T* elem) { - MOZ_ASSERT(isInList()); - setPreviousUnsafe(elem); - } + mNext->mPrev = this; + mPrev->mNext = this; /* - * Remove this element from the list which contains it. If this element is - * not currently part of a linked list, this method asserts. + * Adjust |other| so it doesn't think it's in a list. This makes it + * safely destructable. */ - void remove() { - MOZ_ASSERT(isInList()); - - prev->next = next; - next->prev = prev; - next = this; - prev = this; - } + other.mNext = &other; + other.mPrev = &other; + } - /* - * Identical to remove(), but also asserts in debug builds that this element - * is in list. - */ - void removeFrom(const LinkedList& list) { - list.assertContains(asT()); + ~LinkedListElement() + { + if (!mIsSentinel && isInList()) { remove(); } - - /* - * Return true if |this| part is of a linked list, and false otherwise. - */ - bool isInList() const { - MOZ_ASSERT((next == this) == (prev == this)); - return next != this; - } - - private: - friend class LinkedList; - - enum NodeKind { - NODE_KIND_NORMAL, - NODE_KIND_SENTINEL - }; - - LinkedListElement(NodeKind nodeKind) - : next(MOZ_THIS_IN_INITIALIZER_LIST()), - prev(MOZ_THIS_IN_INITIALIZER_LIST()), - isSentinel(nodeKind == NODE_KIND_SENTINEL) - { } - - /* - * Return |this| cast to T* if we're a normal node, or return nullptr if - * we're a sentinel node. - */ - T* asT() { - if (isSentinel) - return nullptr; - - return static_cast(this); - } - const T* asT() const { - if (isSentinel) - return nullptr; - - return static_cast(this); - } - - /* - * Insert elem after this element, but don't check that this element is in - * the list. This is called by LinkedList::insertFront(). - */ - void setNextUnsafe(T* elem) { - LinkedListElement *listElem = static_cast(elem); - MOZ_ASSERT(!listElem->isInList()); - - listElem->next = this->next; - listElem->prev = this; - this->next->prev = listElem; - this->next = listElem; - } - - /* - * Insert elem before this element, but don't check that this element is in - * the list. This is called by LinkedList::insertBack(). - */ - void setPreviousUnsafe(T* elem) { - LinkedListElement* listElem = static_cast*>(elem); - MOZ_ASSERT(!listElem->isInList()); - - listElem->next = this; - listElem->prev = this->prev; - this->prev->next = listElem; - this->prev = listElem; - } - - private: - LinkedListElement& operator=(const LinkedListElement& other) MOZ_DELETE; - LinkedListElement(const LinkedListElement& other) MOZ_DELETE; + } + + /* + * Get the next element in the list, or nullptr if this is the last element + * in the list. + */ + T* getNext() { return mNext->asT(); } + const T* getNext() const { return mNext->asT(); } + + /* + * Get the previous element in the list, or nullptr if this is the first + * element in the list. + */ + T* getPrevious() { return mPrev->asT(); } + const T* getPrevious() const { return mPrev->asT(); } + + /* + * Insert aElem after this element in the list. |this| must be part of a + * linked list when you call setNext(); otherwise, this method will assert. + */ + void setNext(T* aElem) + { + MOZ_ASSERT(isInList()); + setNextUnsafe(aElem); + } + + /* + * Insert aElem before this element in the list. |this| must be part of a + * linked list when you call setPrevious(); otherwise, this method will + * assert. + */ + void setPrevious(T* aElem) + { + MOZ_ASSERT(isInList()); + setPreviousUnsafe(aElem); + } + + /* + * Remove this element from the list which contains it. If this element is + * not currently part of a linked list, this method asserts. + */ + void remove() + { + MOZ_ASSERT(isInList()); + + mPrev->mNext = mNext; + mNext->mPrev = mPrev; + mNext = this; + mPrev = this; + } + + /* + * Identical to remove(), but also asserts in debug builds that this element + * is in aList. + */ + void removeFrom(const LinkedList& aList) + { + aList.assertContains(asT()); + remove(); + } + + /* + * Return true if |this| part is of a linked list, and false otherwise. + */ + bool isInList() const + { + MOZ_ASSERT((mNext == this) == (mPrev == this)); + return mNext != this; + } + +private: + friend class LinkedList; + + enum NodeKind { + NODE_KIND_NORMAL, + NODE_KIND_SENTINEL + }; + + explicit LinkedListElement(NodeKind nodeKind) + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(nodeKind == NODE_KIND_SENTINEL) + { } + + /* + * Return |this| cast to T* if we're a normal node, or return nullptr if + * we're a sentinel node. + */ + T* asT() + { + return mIsSentinel ? nullptr : static_cast(this); + } + const T* asT() const + { + return mIsSentinel ? nullptr : static_cast(this); + } + + /* + * Insert aElem after this element, but don't check that this element is in + * the list. This is called by LinkedList::insertFront(). + */ + void setNextUnsafe(T* aElem) + { + LinkedListElement *listElem = static_cast(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this->mNext; + listElem->mPrev = this; + this->mNext->mPrev = listElem; + this->mNext = listElem; + } + + /* + * Insert aElem before this element, but don't check that this element is in + * the list. This is called by LinkedList::insertBack(). + */ + void setPreviousUnsafe(T* aElem) + { + LinkedListElement* listElem = static_cast*>(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this; + listElem->mPrev = this->mPrev; + this->mPrev->mNext = listElem; + this->mPrev = listElem; + } + +private: + LinkedListElement& operator=(const LinkedListElement& aOther) MOZ_DELETE; + LinkedListElement(const LinkedListElement& aOther) MOZ_DELETE; }; template class LinkedList { - private: - LinkedListElement sentinel; - - public: - LinkedList() : sentinel(LinkedListElement::NODE_KIND_SENTINEL) { } - - LinkedList(LinkedList&& other) - : sentinel(mozilla::Move(other.sentinel)) - { } - - ~LinkedList() { - MOZ_ASSERT(isEmpty()); - } - - /* - * Add elem to the front of the list. - */ - void insertFront(T* elem) { - /* Bypass setNext()'s this->isInList() assertion. */ - sentinel.setNextUnsafe(elem); - } - - /* - * Add elem to the back of the list. - */ - void insertBack(T* elem) { - sentinel.setPreviousUnsafe(elem); - } - - /* - * Get the first element of the list, or nullptr if the list is empty. - */ - T* getFirst() { - return sentinel.getNext(); - } - const T* getFirst() const { - return sentinel.getNext(); +private: + LinkedListElement sentinel; + +public: + LinkedList() : sentinel(LinkedListElement::NODE_KIND_SENTINEL) { } + + LinkedList(LinkedList&& aOther) + : sentinel(mozilla::Move(aOther.sentinel)) + { } + + ~LinkedList() { MOZ_ASSERT(isEmpty()); } + + /* + * Add aElem to the front of the list. + */ + void insertFront(T* aElem) + { + /* Bypass setNext()'s this->isInList() assertion. */ + sentinel.setNextUnsafe(aElem); + } + + /* + * Add aElem to the back of the list. + */ + void insertBack(T* aElem) + { + sentinel.setPreviousUnsafe(aElem); + } + + /* + * Get the first element of the list, or nullptr if the list is empty. + */ + T* getFirst() { return sentinel.getNext(); } + const T* getFirst() const { return sentinel.getNext(); } + + /* + * Get the last element of the list, or nullptr if the list is empty. + */ + T* getLast() { return sentinel.getPrevious(); } + const T* getLast() const { return sentinel.getPrevious(); } + + /* + * Get and remove the first element of the list. If the list is empty, + * return nullptr. + */ + T* popFirst() + { + T* ret = sentinel.getNext(); + if (ret) { + static_cast*>(ret)->remove(); } - - /* - * Get the last element of the list, or nullptr if the list is empty. - */ - T* getLast() { - return sentinel.getPrevious(); - } - const T* getLast() const { - return sentinel.getPrevious(); - } - - /* - * Get and remove the first element of the list. If the list is empty, - * return nullptr. - */ - T* popFirst() { - T* ret = sentinel.getNext(); - if (ret) - static_cast*>(ret)->remove(); - return ret; + return ret; + } + + /* + * Get and remove the last element of the list. If the list is empty, + * return nullptr. + */ + T* popLast() + { + T* ret = sentinel.getPrevious(); + if (ret) { + static_cast*>(ret)->remove(); } - - /* - * Get and remove the last element of the list. If the list is empty, - * return nullptr. - */ - T* popLast() { - T* ret = sentinel.getPrevious(); - if (ret) - static_cast*>(ret)->remove(); - return ret; + return ret; + } + + /* + * Return true if the list is empty, or false otherwise. + */ + bool isEmpty() const + { + return !sentinel.isInList(); + } + + /* + * Remove all the elements from the list. + * + * This runs in time linear to the list's length, because we have to mark + * each element as not in the list. + */ + void clear() + { + while (popFirst()) { + continue; } - - /* - * Return true if the list is empty, or false otherwise. - */ - bool isEmpty() const { - return !sentinel.isInList(); + } + + /* + * Measures the memory consumption of the list excluding |this|. Note that + * it only measures the list elements themselves. If the list elements + * contain pointers to other memory blocks, those blocks must be measured + * separately during a subsequent iteration over the list. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const + { + size_t n = 0; + for (const T* t = getFirst(); t; t = t->getNext()) { + n += aMallocSizeOf(t); } + return n; + } + + /* + * Like sizeOfExcludingThis(), but measures |this| as well. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const + { + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); + } + + /* + * In a debug build, make sure that the list is sane (no cycles, consistent + * mNext/mPrev pointers, only one sentinel). Has no effect in release builds. + */ + void debugAssertIsSane() const + { +#ifdef DEBUG + const LinkedListElement* slow; + const LinkedListElement* fast1; + const LinkedListElement* fast2; /* - * Remove all the elements from the list. - * - * This runs in time linear to the list's length, because we have to mark - * each element as not in the list. + * Check for cycles in the forward singly-linked list using the + * tortoise/hare algorithm. */ - void clear() { - while (popFirst()) - continue; + for (slow = sentinel.mNext, + fast1 = sentinel.mNext->mNext, + fast2 = sentinel.mNext->mNext->mNext; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mNext, fast1 = fast2->mNext, fast2 = fast1->mNext) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); } - /* - * Measures the memory consumption of the list excluding |this|. Note that - * it only measures the list elements themselves. If the list elements - * contain pointers to other memory blocks, those blocks must be measured - * separately during a subsequent iteration over the list. - */ - size_t sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const { - size_t n = 0; - for (const T* t = getFirst(); t; t = t->getNext()) - n += mallocSizeOf(t); - return n; + /* Check for cycles in the backward singly-linked list. */ + for (slow = sentinel.mPrev, + fast1 = sentinel.mPrev->mPrev, + fast2 = sentinel.mPrev->mPrev->mPrev; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mPrev, fast1 = fast2->mPrev, fast2 = fast1->mPrev) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); } /* - * Like sizeOfExcludingThis(), but measures |this| as well. + * Check that |sentinel| is the only node in the list with + * mIsSentinel == true. */ - size_t sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const { - return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + for (const LinkedListElement* elem = sentinel.mNext; + elem != &sentinel; + elem = elem->mNext) { + MOZ_ASSERT(!elem->mIsSentinel); } - /* - * In a debug build, make sure that the list is sane (no cycles, consistent - * next/prev pointers, only one sentinel). Has no effect in release builds. - */ - void debugAssertIsSane() const { -#ifdef DEBUG - const LinkedListElement* slow; - const LinkedListElement* fast1; - const LinkedListElement* fast2; - - /* - * Check for cycles in the forward singly-linked list using the - * tortoise/hare algorithm. - */ - for (slow = sentinel.next, - fast1 = sentinel.next->next, - fast2 = sentinel.next->next->next; - slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; - slow = slow->next, fast1 = fast2->next, fast2 = fast1->next) - { - MOZ_ASSERT(slow != fast1); - MOZ_ASSERT(slow != fast2); - } - - /* Check for cycles in the backward singly-linked list. */ - for (slow = sentinel.prev, - fast1 = sentinel.prev->prev, - fast2 = sentinel.prev->prev->prev; - slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; - slow = slow->prev, fast1 = fast2->prev, fast2 = fast1->prev) - { - MOZ_ASSERT(slow != fast1); - MOZ_ASSERT(slow != fast2); - } - - /* - * Check that |sentinel| is the only node in the list with - * isSentinel == true. - */ - for (const LinkedListElement* elem = sentinel.next; - elem != &sentinel; - elem = elem->next) - { - MOZ_ASSERT(!elem->isSentinel); - } - - /* Check that the next/prev pointers match up. */ - const LinkedListElement* prev = &sentinel; - const LinkedListElement* cur = sentinel.next; - do { - MOZ_ASSERT(cur->prev == prev); - MOZ_ASSERT(prev->next == cur); + /* Check that the mNext/mPrev pointers match up. */ + const LinkedListElement* prev = &sentinel; + const LinkedListElement* cur = sentinel.mNext; + do { + MOZ_ASSERT(cur->mPrev == prev); + MOZ_ASSERT(prev->mNext == cur); - prev = cur; - cur = cur->next; - } while (cur != &sentinel); + prev = cur; + cur = cur->mNext; + } while (cur != &sentinel); #endif /* ifdef DEBUG */ - } + } - private: - friend class LinkedListElement; +private: + friend class LinkedListElement; - void assertContains(const T* t) const { + void assertContains(const T* aValue) const + { #ifdef DEBUG - for (const T* elem = getFirst(); - elem; - elem = elem->getNext()) - { - if (elem == t) - return; + for (const T* elem = getFirst(); elem; elem = elem->getNext()) { + if (elem == aValue) { + return; } - MOZ_CRASH("element wasn't found in this list!"); -#endif } + MOZ_CRASH("element wasn't found in this list!"); +#endif + } - LinkedList& operator=(const LinkedList& other) MOZ_DELETE; - LinkedList(const LinkedList& other) MOZ_DELETE; + LinkedList& operator=(const LinkedList& aOther) MOZ_DELETE; + LinkedList(const LinkedList& aOther) MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/LinuxSignal.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/LinuxSignal.h new file mode 100644 index 0000000000..9b8e1bbbbe --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/LinuxSignal.h @@ -0,0 +1,48 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_LinuxSignal_h +#define mozilla_LinuxSignal_h + +namespace mozilla { + +#if defined(__arm__) + +// Some (old) Linux kernels on ARM have a bug where a signal handler +// can be called without clearing the IT bits in CPSR first. The result +// is that the first few instructions of the handler could be skipped, +// ultimately resulting in crashes. To workaround this bug, the handler +// on ARM is a trampoline that starts with enough NOP instructions, so +// that even if the IT bits are not cleared, only the NOP instructions +// will be skipped over. + +template +__attribute__((naked)) void +SignalTrampoline(int aSignal, siginfo_t* aInfo, void* aContext) +{ + asm volatile ( + "nop; nop; nop; nop" + : : : "memory"); + + // Because the assembler may generate additional insturctions below, we + // need to ensure NOPs are inserted first by separating them out above. + + asm volatile ( + "bx %0" + : + : "r"(H), "l"(aSignal), "l"(aInfo), "l"(aContext) + : "memory"); +} + +# define MOZ_SIGNAL_TRAMPOLINE(h) (mozilla::SignalTrampoline) + +#else // __arm__ + +# define MOZ_SIGNAL_TRAMPOLINE(h) (h) + +#endif // __arm__ + +} // namespace mozilla + +#endif // mozilla_LinuxSignal_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MSIntTypes.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MSIntTypes.h index 3dfba55f58..4ce922fbc5 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MSIntTypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MSIntTypes.h @@ -1,32 +1,32 @@ // ISO C9x compliant inttypes.h for Microsoft Visual Studio -// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 -// +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// // Copyright (c) 2006 Alexander Chemeris -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: -// +// // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. -// +// // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. -// +// // 3. The name of the author may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// +// /////////////////////////////////////////////////////////////////////////////// #ifndef _MSC_VER // [ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MacroArgs.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MacroArgs.h new file mode 100644 index 0000000000..c8b7338210 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MacroArgs.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements various macros meant to ease the use of variadic macros. + */ + +#ifndef mozilla_MacroArgs_h +#define mozilla_MacroArgs_h + +/* + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) counts the number of variadic + * arguments and prefixes it with |aPrefix|. For example: + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(, foo, 42) expands to 2 + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(A, foo, 42, bar) expands to A3 + * + * You must pass in between 1 and 50 (inclusive) variadic arguments, past + * |aPrefix|. It is not legal to do + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(prefix) + * + * (that is, pass in 0 variadic arguments). To ensure that a compile-time + * error occurs when these constraints are violated, use the + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT macro with the same variaidc arguments + * wherever this macro is used. + * + * Passing (__VA_ARGS__, ) rather than simply calling + * MOZ_MACROARGS_ARG_COUNT_HELPER2(__VA_ARGS__, ) very + * carefully tiptoes around a MSVC bug where it improperly expands __VA_ARGS__ + * as a single token in argument lists. For details, see: + * + * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement + * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 + */ +#define MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) \ + MOZ_MACROARGS_ARG_COUNT_HELPER((__VA_ARGS__, \ + aPrefix##50, aPrefix##49, aPrefix##48, aPrefix##47, aPrefix##46, \ + aPrefix##45, aPrefix##44, aPrefix##43, aPrefix##42, aPrefix##41, \ + aPrefix##40, aPrefix##39, aPrefix##38, aPrefix##37, aPrefix##36, \ + aPrefix##35, aPrefix##34, aPrefix##33, aPrefix##32, aPrefix##31, \ + aPrefix##30, aPrefix##29, aPrefix##28, aPrefix##27, aPrefix##26, \ + aPrefix##25, aPrefix##24, aPrefix##23, aPrefix##22, aPrefix##21, \ + aPrefix##20, aPrefix##19, aPrefix##18, aPrefix##17, aPrefix##16, \ + aPrefix##15, aPrefix##14, aPrefix##13, aPrefix##12, aPrefix##11, \ + aPrefix##10, aPrefix##9, aPrefix##8, aPrefix##7, aPrefix##6, \ + aPrefix##5, aPrefix##4, aPrefix##3, aPrefix##2, aPrefix##1, aPrefix##0)) + +#define MOZ_MACROARGS_ARG_COUNT_HELPER(aArgs) \ + MOZ_MACROARGS_ARG_COUNT_HELPER2 aArgs + +#define MOZ_MACROARGS_ARG_COUNT_HELPER2( \ + a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, \ + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \ + a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \ + a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \ + a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \ + a51, ...) a51 + +/* + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT ensures that a compile-time error occurs + * when the argument count constraints of MOZ_PASTE_PREFIX_AND_ARG_COUNT are + * violated. Use this macro wherever MOZ_PASTE_PREFIX_AND_ARG_COUNT is used + * and pass it the same variadic arguments. + * + * This macro employs a few dirty tricks to function. To detect the zero + * argument case, |(__VA_ARGS__)| is stringified, sizeof-ed, and compared to + * what it should be in the absence of arguments. + * + * Detecting too many arguments is a little trickier. With a valid argument + * count and a prefix of 1, MOZ_PASTE_PREFIX_AND_ARG_COUNT expands to e.g. 14. + * With a prefix of 0.0, it expands to e.g. 0.04. If there are too many + * arguments, it expands to the first argument over the limit. If this + * exceeding argument is a number, the assertion will fail as there is no + * number than can simultaneously be both > 10 and == 0. If the exceeding + * argument is not a number, a compile-time error should still occur due to + * the operations performed on it. + */ +#define MOZ_MACROARGS_STRINGIFY_HELPER(x) #x +#define MOZ_STATIC_ASSERT_VALID_ARG_COUNT(...) \ + static_assert( \ + sizeof(MOZ_MACROARGS_STRINGIFY_HELPER((__VA_ARGS__))) != sizeof("()") && \ + (MOZ_PASTE_PREFIX_AND_ARG_COUNT(1, __VA_ARGS__)) > 10 && \ + (int)(MOZ_PASTE_PREFIX_AND_ARG_COUNT(0.0, __VA_ARGS__)) == 0, \ + "MOZ_STATIC_ASSERT_VALID_ARG_COUNT requires 1 to 50 arguments") /* ; */ + +/* + * MOZ_ARGS_AFTER_N expands to its arguments excluding the first |N| + * arguments. For example: + * + * MOZ_ARGS_AFTER_2(a, b, c, d) expands to: c, d + */ +#define MOZ_ARGS_AFTER_1(a1, ...) __VA_ARGS__ +#define MOZ_ARGS_AFTER_2(a1, a2, ...) __VA_ARGS__ + +/* + * MOZ_ARG_N expands to its |N|th argument. + */ +#define MOZ_ARG_1(a1, ...) a1 +#define MOZ_ARG_2(a1, a2, ...) a2 + +#endif /* mozilla_MacroArgs_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MacroForEach.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MacroForEach.h new file mode 100644 index 0000000000..ae1f4d0e99 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MacroForEach.h @@ -0,0 +1,158 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements a higher-order macro for iteratively calling another macro with + * fixed leading arguments, plus a trailing element picked from a second list + * of arguments. + */ + +#ifndef mozilla_MacroForEach_h +#define mozilla_MacroForEach_h + +#include "mozilla/MacroArgs.h" + +/* + * MOZ_FOR_EACH(aMacro, aFixedArgs, aArgs) expands to N calls to the macro + * |aMacro| where N is equal the number of items in the list |aArgs|. The + * arguments for each |aMacro| call are composed of *all* arguments in the list + * |aFixedArgs| as well as a single argument in the list |aArgs|. For example: + * + * #define MACRO_A(x) x + + * int a = MOZ_FOR_EACH(MACRO_A, (), (1, 2, 3)) 0; + * // Expands to: MACRO_A(1) MACRO_A(2) MACRO_A(3) 0; + * // And further to: 1 + 2 + 3 + 0; + * + * #define MACRO_B(k, x) (k + x) + + * int b = MOZ_FOR_EACH(MACRO_B, (5,), (1, 2)) 0; + * // Expands to: MACRO_B(5, 1) MACRO_B(5, 2) 0; + * + * #define MACRO_C(k1, k2, x) (k1 + k2 + x) + + * int c = MOZ_FOR_EACH(MACRO_C, (5, 8,), (1, 2)) 0; + * // Expands to: MACRO_B(5, 8, 1) MACRO_B(5, 8, 2) 0; + * + * If the |aFixedArgs| list is not empty, a trailing comma must be included. + * + * The |aArgs| list must be not be empty and may be up to 50 items long. Use + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT to ensure that violating this constraint + * results in a compile-time error. + */ +#define MOZ_FOR_EACH_EXPAND_HELPER(...) __VA_ARGS__ +#define MOZ_FOR_EACH_GLUE(a, b) a b +#define MOZ_FOR_EACH(aMacro, aFixedArgs, aArgs) \ + MOZ_FOR_EACH_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_FOR_EACH_, \ + MOZ_FOR_EACH_EXPAND_HELPER aArgs), \ + (aMacro, aFixedArgs, aArgs)) + +#define MOZ_FOR_EACH_HELPER_GLUE(a, b) a b +#define MOZ_FOR_EACH_HELPER(aMacro, aFixedArgs, aArgs) \ + MOZ_FOR_EACH_HELPER_GLUE( \ + aMacro, \ + (MOZ_FOR_EACH_EXPAND_HELPER aFixedArgs MOZ_ARG_1 aArgs)) + +#define MOZ_FOR_EACH_1(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) +#define MOZ_FOR_EACH_2(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_1(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_3(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_2(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_4(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_3(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_5(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_4(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_6(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_5(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_7(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_6(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_8(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_7(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_9(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_8(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_10(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_9(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_11(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_10(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_12(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_11(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_13(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_12(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_14(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_13(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_15(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_14(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_16(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_15(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_17(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_16(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_18(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_17(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_19(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_18(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_20(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_19(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_21(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_20(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_22(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_21(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_23(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_22(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_24(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_23(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_25(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_24(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_26(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_25(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_27(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_26(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_28(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_27(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_29(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_28(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_30(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_29(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_31(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_30(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_32(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_31(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_33(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_32(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_34(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_33(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_35(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_34(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_36(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_35(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_37(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_36(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_38(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_37(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_39(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_38(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_40(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_39(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_41(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_40(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_42(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_41(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_43(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_42(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_44(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_43(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_45(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_44(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_46(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_45(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_47(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_46(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_48(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_47(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_49(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_48(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_50(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_49(m, fa, (MOZ_ARGS_AFTER_1 a)) + +#endif /* mozilla_MacroForEach_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MathAlgorithms.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MathAlgorithms.h index 7b98c7fc19..cd71d19770 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MathAlgorithms.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MathAlgorithms.h @@ -21,31 +21,31 @@ namespace mozilla { // Greatest Common Divisor template MOZ_ALWAYS_INLINE IntegerType -EuclidGCD(IntegerType a, IntegerType b) +EuclidGCD(IntegerType aA, IntegerType aB) { // Euclid's algorithm; O(N) in the worst case. (There are better // ways, but we don't need them for the current use of this algo.) - MOZ_ASSERT(a > 0); - MOZ_ASSERT(b > 0); + MOZ_ASSERT(aA > IntegerType(0)); + MOZ_ASSERT(aB > IntegerType(0)); - while (a != b) { - if (a > b) { - a = a - b; + while (aA != aB) { + if (aA > aB) { + aA = aA - aB; } else { - b = b - a; + aB = aB - aA; } } - return a; + return aA; } // Least Common Multiple template MOZ_ALWAYS_INLINE IntegerType -EuclidLCM(IntegerType a, IntegerType b) +EuclidLCM(IntegerType aA, IntegerType aB) { // Divide first to reduce overflow risk. - return (a / EuclidGCD(a, b)) * b; + return (aA / EuclidGCD(aA, aB)) * aB; } namespace detail { @@ -68,7 +68,7 @@ template<> struct AllowDeprecatedAbs : TrueType {}; // to Abs below, and it will be removed when all callers have been changed. template inline typename mozilla::EnableIf::value, T>::Type -DeprecatedAbs(const T t) +DeprecatedAbs(const T aValue) { // The absolute value of the smallest possible value of a signed-integer type // won't fit in that type (on twos-complement systems -- and we're blithely @@ -79,10 +79,10 @@ DeprecatedAbs(const T t) // value in the range [-maxvalue, 0]), then negating (giving a value in the // range [0, maxvalue]), doesn't produce maxvalue (because in twos-complement, // (minvalue + 1) == -maxvalue). - MOZ_ASSERT(t >= 0 || - -(t + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1), + MOZ_ASSERT(aValue >= 0 || + -(aValue + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1), "You can't negate the smallest possible negative integer!"); - return t >= 0 ? t : -t; + return aValue >= 0 ? aValue : -aValue; } namespace detail { @@ -102,7 +102,8 @@ template<> struct AbsReturnTypeFixed { typedef uint64_t Type; }; template struct AbsReturnType : AbsReturnTypeFixed {}; -template<> struct AbsReturnType : EnableIf {}; +template<> struct AbsReturnType : + EnableIf {}; template<> struct AbsReturnType { typedef unsigned char Type; }; template<> struct AbsReturnType { typedef unsigned short Type; }; template<> struct AbsReturnType { typedef unsigned int Type; }; @@ -116,50 +117,46 @@ template<> struct AbsReturnType { typedef long double Type; }; template inline typename detail::AbsReturnType::Type -Abs(const T t) +Abs(const T aValue) { typedef typename detail::AbsReturnType::Type ReturnType; - return t >= 0 ? ReturnType(t) : ~ReturnType(t) + 1; + return aValue >= 0 ? ReturnType(aValue) : ~ReturnType(aValue) + 1; } template<> inline float -Abs(const float f) +Abs(const float aFloat) { - return std::fabs(f); + return std::fabs(aFloat); } template<> inline double -Abs(const double d) +Abs(const double aDouble) { - return std::fabs(d); + return std::fabs(aDouble); } template<> inline long double -Abs(const long double d) +Abs(const long double aLongDouble) { - return std::fabs(d); + return std::fabs(aLongDouble); } } // namespace mozilla -#if defined(_WIN32) && (_MSC_VER >= 1300) && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) +#if defined(_WIN32) && (_MSC_VER >= 1300) && \ + (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) # define MOZ_BITSCAN_WINDOWS - extern "C" { - unsigned char _BitScanForward(unsigned long* Index, unsigned long mask); - unsigned char _BitScanReverse(unsigned long* Index, unsigned long mask); +# include # pragma intrinsic(_BitScanForward, _BitScanReverse) # if defined(_M_AMD64) || defined(_M_X64) # define MOZ_BITSCAN_WINDOWS64 - unsigned char _BitScanForward64(unsigned long* index, unsigned __int64 mask); - unsigned char _BitScanReverse64(unsigned long* index, unsigned __int64 mask); # pragma intrinsic(_BitScanForward64, _BitScanReverse64) # endif - } // extern "C" #endif @@ -169,62 +166,68 @@ namespace detail { #if defined(MOZ_BITSCAN_WINDOWS) - inline uint_fast8_t - CountLeadingZeroes32(uint32_t u) - { - unsigned long index; - _BitScanReverse(&index, static_cast(u)); - return uint_fast8_t(31 - index); - } +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanReverse(&index, static_cast(aValue)); + return uint_fast8_t(31 - index); +} - inline uint_fast8_t - CountTrailingZeroes32(uint32_t u) - { - unsigned long index; - _BitScanForward(&index, static_cast(u)); - return uint_fast8_t(index); - } +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanForward(&index, static_cast(aValue)); + return uint_fast8_t(index); +} - inline uint_fast8_t - CountPopulation32(uint32_t u) - { - uint32_t sum2 = (u & 0x55555555) + ((u & 0xaaaaaaaa) >> 1); - uint32_t sum4 = (sum2 & 0x33333333) + ((sum2 & 0xcccccccc) >> 2); - uint32_t sum8 = (sum4 & 0x0f0f0f0f) + ((sum4 & 0xf0f0f0f0) >> 4); - uint32_t sum16 = (sum8 & 0x00ff00ff) + ((sum8 & 0xff00ff00) >> 8); - return sum16; - } +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + uint32_t x = aValue - ((aValue >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + return (((x + (x >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; +} +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return uint_fast8_t(CountPopulation32(aValue & 0xffffffff) + + CountPopulation32(aValue >> 32)); +} - inline uint_fast8_t - CountLeadingZeroes64(uint64_t u) - { -# if defined(MOZ_BITSCAN_WINDOWS64) - unsigned long index; - _BitScanReverse64(&index, static_cast(u)); - return uint_fast8_t(63 - index); -# else - uint32_t hi = uint32_t(u >> 32); - if (hi != 0) - return CountLeadingZeroes32(hi); - return 32 + CountLeadingZeroes32(uint32_t(u)); -# endif +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanReverse64(&index, static_cast(aValue)); + return uint_fast8_t(63 - index); +#else + uint32_t hi = uint32_t(aValue >> 32); + if (hi != 0) { + return CountLeadingZeroes32(hi); } + return 32u + CountLeadingZeroes32(uint32_t(aValue)); +#endif +} - inline uint_fast8_t - CountTrailingZeroes64(uint64_t u) - { -# if defined(MOZ_BITSCAN_WINDOWS64) - unsigned long index; - _BitScanForward64(&index, static_cast(u)); - return uint_fast8_t(index); -# else - uint32_t lo = uint32_t(u); - if (lo != 0) - return CountTrailingZeroes32(lo); - return 32 + CountTrailingZeroes32(uint32_t(u >> 32)); -# endif +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanForward64(&index, static_cast(aValue)); + return uint_fast8_t(index); +#else + uint32_t lo = uint32_t(aValue); + if (lo != 0) { + return CountTrailingZeroes32(lo); } + return 32u + CountTrailingZeroes32(uint32_t(aValue >> 32)); +#endif +} # ifdef MOZ_HAVE_BITSCAN64 # undef MOZ_HAVE_BITSCAN64 @@ -240,52 +243,59 @@ namespace detail { // gcc has had __builtin_clz and friends since 3.4: no need to check. # endif - inline uint_fast8_t - CountLeadingZeroes32(uint32_t u) - { - return __builtin_clz(u); - } +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + return __builtin_clz(aValue); +} - inline uint_fast8_t - CountTrailingZeroes32(uint32_t u) - { - return __builtin_ctz(u); - } +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + return __builtin_ctz(aValue); +} - inline uint_fast8_t - CountPopulation32(uint32_t u) - { - return __builtin_popcount(u); - } +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + return __builtin_popcount(aValue); +} - inline uint_fast8_t - CountLeadingZeroes64(uint64_t u) - { - return __builtin_clzll(u); - } +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return __builtin_popcountll(aValue); +} - inline uint_fast8_t - CountTrailingZeroes64(uint64_t u) - { - return __builtin_ctzll(u); - } +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ + return __builtin_clzll(aValue); +} + +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ + return __builtin_ctzll(aValue); +} #else # error "Implement these!" - inline uint_fast8_t CountLeadingZeroes32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountTrailingZeroes32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountPopulation32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountLeadingZeroes64(uint64_t u) MOZ_DELETE; - inline uint_fast8_t CountTrailingZeroes64(uint64_t u) MOZ_DELETE; +inline uint_fast8_t CountLeadingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountLeadingZeroes64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes64(uint64_t aValue) MOZ_DELETE; #endif } // namespace detail /** - * Compute the number of high-order zero bits in the NON-ZERO number |u|. That - * is, looking at the bitwise representation of the number, with the highest- - * valued bits at the start, return the number of zeroes before the first one - * is observed. + * Compute the number of high-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * highest- valued bits at the start, return the number of zeroes before the + * first one is observed. * * CountLeadingZeroes32(0xF0FF1000) is 0; * CountLeadingZeroes32(0x7F8F0001) is 1; @@ -293,17 +303,17 @@ namespace detail { * CountLeadingZeroes32(0x1FF50010) is 3; and so on. */ inline uint_fast8_t -CountLeadingZeroes32(uint32_t u) +CountLeadingZeroes32(uint32_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountLeadingZeroes32(u); + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes32(aValue); } /** - * Compute the number of low-order zero bits in the NON-ZERO number |u|. That - * is, looking at the bitwise representation of the number, with the lowest- - * valued bits at the start, return the number of zeroes before the first one - * is observed. + * Compute the number of low-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * lowest- valued bits at the start, return the number of zeroes before the + * first one is observed. * * CountTrailingZeroes32(0x0100FFFF) is 0; * CountTrailingZeroes32(0x7000FFFE) is 1; @@ -311,35 +321,42 @@ CountLeadingZeroes32(uint32_t u) * CountTrailingZeroes32(0x0080FFF8) is 3; and so on. */ inline uint_fast8_t -CountTrailingZeroes32(uint32_t u) +CountTrailingZeroes32(uint32_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountTrailingZeroes32(u); + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes32(aValue); } /** - * Compute the number of one bits in the number |u|, + * Compute the number of one bits in the number |aValue|, */ inline uint_fast8_t -CountPopulation32(uint32_t u) +CountPopulation32(uint32_t aValue) +{ + return detail::CountPopulation32(aValue); +} + +/** Analogous to CoutPopulation32, but for 64-bit numbers */ +inline uint_fast8_t +CountPopulation64(uint64_t aValue) { - return detail::CountPopulation32(u); + return detail::CountPopulation64(aValue); } /** Analogous to CountLeadingZeroes32, but for 64-bit numbers. */ inline uint_fast8_t -CountLeadingZeroes64(uint64_t u) +CountLeadingZeroes64(uint64_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountLeadingZeroes64(u); + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes64(aValue); } /** Analogous to CountTrailingZeroes32, but for 64-bit numbers. */ inline uint_fast8_t -CountTrailingZeroes64(uint64_t u) +CountTrailingZeroes64(uint64_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountTrailingZeroes64(u); + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes64(aValue); } namespace detail { @@ -350,27 +367,29 @@ class CeilingLog2; template class CeilingLog2 { - public: - static uint_fast8_t compute(const T t) { - // Check for <= 1 to avoid the == 0 undefined case. - return t <= 1 ? 0 : 32 - CountLeadingZeroes32(t - 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0u : 32u - CountLeadingZeroes32(aValue - 1); + } }; template class CeilingLog2 { - public: - static uint_fast8_t compute(const T t) { - // Check for <= 1 to avoid the == 0 undefined case. - return t <= 1 ? 0 : 64 - CountLeadingZeroes64(t - 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0 : 64 - CountLeadingZeroes64(aValue - 1); + } }; } // namespace detail /** - * Compute the log of the least power of 2 greater than or equal to |t|. + * Compute the log of the least power of 2 greater than or equal to |aValue|. * * CeilingLog2(0..1) is 0; * CeilingLog2(2) is 1; @@ -380,16 +399,16 @@ class CeilingLog2 */ template inline uint_fast8_t -CeilingLog2(const T t) +CeilingLog2(const T aValue) { - return detail::CeilingLog2::compute(t); + return detail::CeilingLog2::compute(aValue); } /** A CeilingLog2 variant that accepts only size_t. */ inline uint_fast8_t -CeilingLog2Size(size_t n) +CeilingLog2Size(size_t aValue) { - return CeilingLog2(n); + return CeilingLog2(aValue); } namespace detail { @@ -400,25 +419,27 @@ class FloorLog2; template class FloorLog2 { - public: - static uint_fast8_t compute(const T t) { - return 31 - CountLeadingZeroes32(t | 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + return 31u - CountLeadingZeroes32(aValue | 1); + } }; template class FloorLog2 { - public: - static uint_fast8_t compute(const T t) { - return 63 - CountLeadingZeroes64(t | 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + return 63u - CountLeadingZeroes64(aValue | 1); + } }; } // namespace detail /** - * Compute the log of the greatest power of 2 less than or equal to |t|. + * Compute the log of the greatest power of 2 less than or equal to |aValue|. * * FloorLog2(0..1) is 0; * FloorLog2(2..3) is 1; @@ -427,16 +448,16 @@ class FloorLog2 */ template inline uint_fast8_t -FloorLog2(const T t) +FloorLog2(const T aValue) { - return detail::FloorLog2::compute(t); + return detail::FloorLog2::compute(aValue); } /** A FloorLog2 variant that accepts only size_t. */ inline uint_fast8_t -FloorLog2Size(size_t n) +FloorLog2Size(size_t aValue) { - return FloorLog2(n); + return FloorLog2(aValue); } /* @@ -444,11 +465,11 @@ FloorLog2Size(size_t n) * be so great that the computed value would overflow |size_t|. */ inline size_t -RoundUpPow2(size_t x) +RoundUpPow2(size_t aValue) { - MOZ_ASSERT(x <= (size_t(1) << (sizeof(size_t) * CHAR_BIT - 1)), + MOZ_ASSERT(aValue <= (size_t(1) << (sizeof(size_t) * CHAR_BIT - 1)), "can't round up -- will overflow!"); - return size_t(1) << CeilingLog2(x); + return size_t(1) << CeilingLog2(aValue); } /** @@ -456,11 +477,11 @@ RoundUpPow2(size_t x) */ template inline T -RotateLeft(const T t, uint_fast8_t shift) +RotateLeft(const T aValue, uint_fast8_t aShift) { - MOZ_ASSERT(shift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); static_assert(IsUnsigned::value, "Rotates require unsigned values"); - return (t << shift) | (t >> (sizeof(T) * CHAR_BIT - shift)); + return (aValue << aShift) | (aValue >> (sizeof(T) * CHAR_BIT - aShift)); } /** @@ -468,11 +489,11 @@ RotateLeft(const T t, uint_fast8_t shift) */ template inline T -RotateRight(const T t, uint_fast8_t shift) +RotateRight(const T aValue, uint_fast8_t aShift) { - MOZ_ASSERT(shift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); static_assert(IsUnsigned::value, "Rotates require unsigned values"); - return (t >> shift) | (t << (sizeof(T) * CHAR_BIT - shift)); + return (aValue >> aShift) | (aValue << (sizeof(T) * CHAR_BIT - aShift)); } } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Maybe.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Maybe.h index 25683a28ab..4ba88f6771 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Maybe.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Maybe.h @@ -31,131 +31,150 @@ namespace mozilla { template class Maybe { - AlignedStorage2 storage; - bool constructed; - - T& asT() { return *storage.addr(); } - - public: - Maybe() { constructed = false; } - ~Maybe() { if (constructed) asT().~T(); } - - bool empty() const { return !constructed; } - - void construct() { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(); - constructed = true; - } - - template - void construct(const T1& t1) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8, const T9& t9) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8, t9); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); - constructed = true; - } - - T* addr() { - MOZ_ASSERT(constructed); - return &asT(); - } - - T& ref() { - MOZ_ASSERT(constructed); - return asT(); - } - - const T& ref() const { - MOZ_ASSERT(constructed); - return const_cast(this)->asT(); - } - - void destroy() { - ref().~T(); - constructed = false; - } - - void destroyIfConstructed() { - if (!empty()) - destroy(); - } - - private: - Maybe(const Maybe& other) MOZ_DELETE; - const Maybe& operator=(const Maybe& other) MOZ_DELETE; + AlignedStorage2 storage; + bool constructed; + + T& asT() { return *storage.addr(); } + +public: + Maybe() { constructed = false; } + ~Maybe() { if (constructed) { asT().~T(); } } + + bool empty() const { return !constructed; } + + void construct() + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(); + constructed = true; + } + + template + void construct(const T1& aT1) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9, const T10& aT10) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9, aT10); + constructed = true; + } + + T* addr() + { + MOZ_ASSERT(constructed); + return &asT(); + } + + T& ref() + { + MOZ_ASSERT(constructed); + return asT(); + } + + const T& ref() const + { + MOZ_ASSERT(constructed); + return const_cast(this)->asT(); + } + + void destroy() + { + ref().~T(); + constructed = false; + } + + void destroyIfConstructed() + { + if (!empty()) { + destroy(); + } + } + +private: + Maybe(const Maybe& aOther) MOZ_DELETE; + const Maybe& operator=(const Maybe& aOther) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MaybeOneOf.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MaybeOneOf.h new file mode 100644 index 0000000000..1c58f88253 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MaybeOneOf.h @@ -0,0 +1,144 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_MaybeOneOf_h +#define mozilla_MaybeOneOf_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" +#include "mozilla/Move.h" +#include "mozilla/TemplateLib.h" + +#include // For placement new + +namespace mozilla { + +/* + * MaybeOneOf is like Maybe, but it supports constructing either T1 + * or T2. When a MaybeOneOf is constructed, it is |empty()|, i.e., + * no value has been constructed and no destructor will be called when the + * MaybeOneOf is destroyed. Upon calling |construct()| or + * |construct()|, a T1 or T2 object will be constructed with the given + * arguments and that object will be destroyed when the owning MaybeOneOf is + * destroyed. + */ +template +class MaybeOneOf +{ + AlignedStorage::value> storage; + + enum State { None, SomeT1, SomeT2 } state; + template struct Type2State {}; + + template + T& as() + { + MOZ_ASSERT(state == Type2State::result); + return *(T*)storage.addr(); + } + + template + const T& as() const + { + MOZ_ASSERT(state == Type2State::result); + return *(T*)storage.addr(); + } + +public: + MaybeOneOf() : state(None) {} + ~MaybeOneOf() { destroyIfConstructed(); } + + bool empty() const { return state == None; } + + template + bool constructed() const { return state == Type2State::result; } + + template + void construct() + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(); + } + + template + void construct(U&& aU) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(Move(aU)); + } + + template + void construct(const U1& aU1) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(aU1); + } + + template + void construct(const U1& aU1, const U2& aU2) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(aU1, aU2); + } + + template + T& ref() + { + return as(); + } + + template + const T& ref() const + { + return as(); + } + + void destroy() + { + MOZ_ASSERT(state == SomeT1 || state == SomeT2); + if (state == SomeT1) { + as().~T1(); + } else if (state == SomeT2) { + as().~T2(); + } + state = None; + } + + void destroyIfConstructed() + { + if (!empty()) { + destroy(); + } + } + +private: + MaybeOneOf(const MaybeOneOf& aOther) MOZ_DELETE; + const MaybeOneOf& operator=(const MaybeOneOf& aOther) MOZ_DELETE; +}; + +template +template +struct MaybeOneOf::Type2State +{ + typedef MaybeOneOf Enclosing; + static const typename Enclosing::State result = Enclosing::SomeT1; +}; + +template +template +struct MaybeOneOf::Type2State +{ + typedef MaybeOneOf Enclosing; + static const typename Enclosing::State result = Enclosing::SomeT2; +}; + +} // namespace mozilla + +#endif /* mozilla_MaybeOneOf_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MemoryChecking.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MemoryChecking.h index 2130990c6b..0642d758c0 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MemoryChecking.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/MemoryChecking.h @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* - * Provides a common interface to the ASan (AddressSanitizer) and Valgrind + * Provides a common interface to the ASan (AddressSanitizer) and Valgrind * functions used to mark memory in certain ways. In detail, the following * three macros are provided: * @@ -34,14 +34,14 @@ #if defined(MOZ_ASAN) #include +#include "mozilla/Types.h" + extern "C" { - /* These definitions are usually provided through the - * sanitizer/asan_interface.h header installed by ASan. - */ - void __asan_poison_memory_region(void const volatile *addr, size_t size) - __attribute__((visibility("default"))); - void __asan_unpoison_memory_region(void const volatile *addr, size_t size) - __attribute__((visibility("default"))); +/* These definitions are usually provided through the + * sanitizer/asan_interface.h header installed by ASan. + */ +void MOZ_EXPORT __asan_poison_memory_region(void const volatile *addr, size_t size); +void MOZ_EXPORT __asan_unpoison_memory_region(void const volatile *addr, size_t size); #define MOZ_MAKE_MEM_NOACCESS(addr, size) \ __asan_poison_memory_region((addr), (size)) @@ -63,9 +63,9 @@ extern "C" { VALGRIND_MAKE_MEM_DEFINED((addr), (size)) #else -#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while(0) -#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while(0) -#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while(0) +#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while (0) #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Move.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Move.h index f7d39ffa9b..08ae86fa57 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Move.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Move.h @@ -105,7 +105,7 @@ namespace mozilla { * * c2 = Move(c1); * - * This destroys c1, moves c1's value to c2, and leaves c1 in an undefined but + * This destroys c2, moves c1's value to c2, and leaves c1 in an undefined but * destructible state. * * As we say, a move must leave the original in a "destructible" state. The @@ -132,7 +132,7 @@ namespace mozilla { * * To avoid this, C++11 has tweaks to make it possible to write what you mean. * The four constructor overloads above can be written as one constructor - * template like so: + * template like so[0]: * * template * C::C(XArg&& x, YArg&& y) : x(Forward(x)), y(Forward(y)) { } @@ -144,8 +144,8 @@ namespace mozilla { * - First, when a function template takes an argument that is an rvalue * reference to a template argument (like 'XArg&& x' and 'YArg&& y' above), * then when the argument is applied to an lvalue, the template argument - * resolves to 'T &'; and when it is applied to an rvalue, the template - * argument resolves to 'T &&'. Thus, in a call to C::C like: + * resolves to 'T&'; and when it is applied to an rvalue, the template + * argument resolves to 'T&&'. Thus, in a call to C::C like: * * X foo(int); * Y yy; @@ -180,6 +180,28 @@ namespace mozilla { * 'std::forward', which are just like our 'Move' and 'Forward'; but those * definitions aren't available in that header on all our platforms, so we * define them ourselves here.) + * + * 0. This pattern is known as "perfect forwarding". Interestingly, it is not + * actually perfect, and it can't forward all possible argument expressions! + * There are two issues: one that's a C++11 issue, and one that's a legacy + * compiler issue. + * + * The C++11 issue is that you can't form a reference to a bit-field. As a + * workaround, assign the bit-field to a local variable and use that: + * + * // C is as above + * struct S { int x : 1; } s; + * C(s.x, 0); // BAD: s.x is a reference to a bit-field, can't form those + * int tmp = s.x; + * C(tmp, 0); // OK: tmp not a bit-field + * + * The legacy issue is that when we don't have true nullptr and must emulate + * it (gcc 4.4/4.5), forwarding |nullptr| results in an |int| or |long| + * forwarded reference. But such a reference, even if its value is a null + * pointer constant expression, is not itself a null pointer constant + * expression. This causes -Werror=conversion-null errors and pointer-to- + * integer comparison errors. Until we always have true nullptr, users of + * forwarding methods must not pass |nullptr| to them. */ /** @@ -188,9 +210,9 @@ namespace mozilla { */ template inline typename RemoveReference::Type&& -Move(T&& a) +Move(T&& aX) { - return static_cast::Type&&>(a); + return static_cast::Type&&>(aX); } /** @@ -199,28 +221,28 @@ Move(T&& a) */ template inline T&& -Forward(typename RemoveReference::Type& a) +Forward(typename RemoveReference::Type& aX) { - return static_cast(a); + return static_cast(aX); } template inline T&& -Forward(typename RemoveReference::Type&& t) +Forward(typename RemoveReference::Type&& aX) { static_assert(!IsLvalueReference::value, "misuse of Forward detected! try the other overload"); - return static_cast(t); + return static_cast(aX); } -/** Swap |t| and |u| using move-construction if possible. */ +/** Swap |aX| and |aY| using move-construction if possible. */ template inline void -Swap(T& t, T& u) +Swap(T& aX, T& aY) { - T tmp(Move(t)); - t = Move(u); - u = Move(tmp); + T tmp(Move(aX)); + aX = Move(aY); + aY = Move(tmp); } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/NullPtr.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/NullPtr.h index 35faadc4c3..5963613c4b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/NullPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/NullPtr.h @@ -13,12 +13,10 @@ #define mozilla_NullPtr_h #if defined(__clang__) -# ifndef __has_extension -# define __has_extension __has_feature -# endif -# if __has_extension(cxx_nullptr) -# define MOZ_HAVE_CXX11_NULLPTR +# if !__has_extension(cxx_nullptr) +# error "clang version natively supporting nullptr is required." # endif +# define MOZ_HAVE_CXX11_NULLPTR #elif defined(__GNUC__) # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L # include "mozilla/Compiler.h" @@ -26,23 +24,89 @@ # define MOZ_HAVE_CXX11_NULLPTR # endif # endif -#elif _MSC_VER >= 1600 -# define MOZ_HAVE_CXX11_NULLPTR +#elif defined(_MSC_VER) + // The minimum supported MSVC (10, _MSC_VER 1600) supports nullptr. +# define MOZ_HAVE_CXX11_NULLPTR #endif +namespace mozilla { + /** - * Use C++11 nullptr if available; otherwise use __null for gcc, or a 0 literal - * with the correct size to match the size of a pointer on a given platform. + * IsNullPointer::value is true iff T is the type of C++11's nullptr. If + * nullptr is emulated, IsNullPointer::value is false for all T. + * + * IsNullPointer is useful to give an argument the true decltype(nullptr) type. + * decltype(nullptr) doesn't work when nullptr is emulated. The simplest + * workaround is to use template overloading and SFINAE to expose an overload + * only if an argument's type is decltype(nullptr). Some examples (that assume + * namespace mozilla has been opened, for simplicity): + * + * // foo(T*), foo(stuff that converts to T*), and foo(decltype(nullptr)) + * // (only invoked if nullptr is true nullptr, otherwise foo(T*) is invoked) + * // but nothing else + * void foo(T*) { } + * template + * void foo(N, + * typename EnableIf::value, int>::Type dummy = 0) + * { } + * + * // foo(T*) *exactly* and foo(decltype(nullptr)), nothing else + * void foo(T*) { } + * template + * void foo(U, + * typename EnableIf::value, int>::Type dummy = 0) + * MOZ_DELETE; + * + * The exact details of how set up the SFINAE bits vary on a case-by-case basis. + * If you need help with this (and unless you've internalized way more sadmaking + * nullptr-emulation knowledge than you should have, you do), feel free to poke + * the person with blame on this comment with questions. :-) + * + * Ideally this would be in TypeTraits.h, but C++11 omitted std::is_null_pointer + * (fixed in C++1y), so in the interests of easing a switch to , + * this trait lives elsewhere. */ +template +struct IsNullPointer { static const bool value = false; }; -#ifndef MOZ_HAVE_CXX11_NULLPTR -# if defined(__GNUC__) -# define nullptr __null -# elif defined(_WIN64) -# define nullptr 0LL -# else -# define nullptr 0L -# endif +} // namespace mozilla + +/** + * mozilla::NullptrT is a type that's sort of like decltype(nullptr). But it + * can't be identical, because emulated nullptr doesn't have a distinct type. + * Only with gcc 4.4/4.5, emulated nullptr is __null, and decltype(__null) is + * int or long. But passing __null to an int/long parameter triggers + * -Werror=conversion-null errors with gcc 4.5, or (depending on subsequent use + * inside the overloaded function) can trigger pointer-to-integer comparison + * compiler errors. So fairly often, actually, NullptrT is *not* what you want. + * + * Instead, often you should use template-based overloading in concert with + * SFINAE to add a nullptr overload -- see the comments by IsNullPointer. + * + * So when *should* you use NullptrT? Thus far, the only truly good use seems + * to be as an argument type for operator overloads (because C++ doesn't allow + * operator= to have more than one argument, operator== to have more than two, + * &c.). But even in such cases, it really only works if there are no other + * overloads of the operator that accept a pointer type. If you want both T* + * and nullptr_t overloads, you'll have to wait til we drop gcc 4.4/4.5 support. + * (Currently b2g is the only impediment to this.) + */ +#ifdef MOZ_HAVE_CXX11_NULLPTR +// decltype does the right thing for actual nullptr. +namespace mozilla { +typedef decltype(nullptr) NullptrT; +template<> +struct IsNullPointer { static const bool value = true; }; +} +# undef MOZ_HAVE_CXX11_NULLPTR +#elif MOZ_IS_GCC +# define nullptr __null +// void* sweeps up more than just nullptr, but compilers supporting true +// nullptr are the majority now, so they should detect mistakes. If you're +// feeling paranoid, check/assert that your NullptrT equals nullptr. +namespace mozilla { typedef void* NullptrT; } +#else +# error "No compiler support for nullptr or its emulation." #endif #endif /* mozilla_NullPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/NumericLimits.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/NumericLimits.h index d2ee29813e..730fcb410b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/NumericLimits.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/NumericLimits.h @@ -17,10 +17,10 @@ namespace mozilla { /** - * The NumericLimits class provides a compatibility layer with std::numeric_limits - * for char16_t, otherwise it is exactly the same as std::numeric_limits. - * Code which does not need std::numeric_limits should avoid using - * NumericLimits. + * The NumericLimits class provides a compatibility layer with + * std::numeric_limits for char16_t, otherwise it is exactly the same as + * std::numeric_limits. Code which does not need std::numeric_limits + * should avoid using NumericLimits. */ template class NumericLimits : public std::numeric_limits diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Pair.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Pair.h new file mode 100644 index 0000000000..e9e8a76938 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Pair.h @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A class holding a pair of objects that tries to conserve storage space. */ + +#ifndef mozilla_Pair_h +#define mozilla_Pair_h + +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +namespace detail { + +enum StorageType { AsBase, AsMember }; + +// Optimize storage using the Empty Base Optimization -- that empty base classes +// don't take up space -- to optimize size when one or the other class is +// stateless and can be used as a base class. +// +// The extra conditions on storage for B are necessary so that PairHelper won't +// ambiguously inherit from either A or B, such that one or the other base class +// would be inaccessible. +template::value ? detail::AsBase : detail::AsMember, + detail::StorageType = + IsEmpty::value && !IsBaseOf::value && !IsBaseOf::value + ? detail::AsBase + : detail::AsMember> +struct PairHelper; + +template +struct PairHelper +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : mFirstA(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(mSecondB, aOther.mSecondB); + } + +private: + A mFirstA; + B mSecondB; +}; + +template +struct PairHelper : private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : B(Forward(aB)), + mFirstA(Forward(aA)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return *this; } + const B& second() const { return *this; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(static_cast(*this), static_cast(aOther)); + } + +private: + A mFirstA; +}; + +template +struct PairHelper : private A +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return *this; } + const A& first() const { return *this; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(mSecondB, aOther.mSecondB); + } + +private: + B mSecondB; +}; + +template +struct PairHelper : private A, private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + B(Forward(aB)) + {} + + A& first() { return static_cast(*this); } + const A& first() const { return static_cast(*this); } + B& second() { return static_cast(*this); } + const B& second() const { return static_cast(*this); } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(static_cast(*this), static_cast(aOther)); + } +}; + +} // namespace detail + +/** + * Pair is the logical concatenation of an instance of A with an instance B. + * Space is conserved when possible. Neither A nor B may be a final class. + * + * It's typically clearer to have individual A and B member fields. Except if + * you want the space-conserving qualities of Pair, you're probably better off + * not using this! + * + * No guarantees are provided about the memory layout of A and B, the order of + * initialization or destruction of A and B, and so on. (This is approximately + * required to optimize space usage.) The first/second names are merely + * conceptual! + */ +template +struct Pair + : private detail::PairHelper +{ + typedef typename detail::PairHelper Base; + +public: + template + Pair(AArg&& aA, BArg&& aB) + : Base(Forward(aA), Forward(aB)) + {} + + /** The A instance. */ + using Base::first; + /** The B instance. */ + using Base::second; + + /** Swap this pair with another pair. */ + void swap(Pair& aOther) { Base::swap(aOther); } + +private: + Pair(const Pair&) MOZ_DELETE; +}; + +template +void +Swap(Pair& aX, Pair& aY) +{ + aX.swap(aY); +} + +} // namespace mozilla + +#endif /* mozilla_Pair_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/PodOperations.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/PodOperations.h index adbf2e699d..843e1311d3 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/PodOperations.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/PodOperations.h @@ -24,26 +24,27 @@ namespace mozilla { -/** Set the contents of |t| to 0. */ +/** Set the contents of |aT| to 0. */ template static MOZ_ALWAYS_INLINE void -PodZero(T* t) +PodZero(T* aT) { - memset(t, 0, sizeof(T)); + memset(aT, 0, sizeof(T)); } -/** Set the contents of |nelem| elements starting at |t| to 0. */ +/** Set the contents of |aNElem| elements starting at |aT| to 0. */ template static MOZ_ALWAYS_INLINE void -PodZero(T* t, size_t nelem) +PodZero(T* aT, size_t aNElem) { /* - * This function is often called with 'nelem' small; we use an inline loop + * This function is often called with 'aNElem' small; we use an inline loop * instead of calling 'memset' with a non-constant length. The compiler * should inline the memset call with constant size, though. */ - for (T* end = t + nelem; t < end; t++) - memset(t, 0, sizeof(T)); + for (T* end = aT + aNElem; aT < end; aT++) { + memset(aT, 0, sizeof(T)); + } } /* @@ -54,107 +55,116 @@ PodZero(T* t, size_t nelem) * compile error involving PodZero and array types, use PodArrayZero instead. */ template -static void PodZero(T (&t)[N]) MOZ_DELETE; +static void PodZero(T (&aT)[N]) MOZ_DELETE; template -static void PodZero(T (&t)[N], size_t nelem) MOZ_DELETE; +static void PodZero(T (&aT)[N], size_t aNElem) MOZ_DELETE; -/** Set the contents of the array |t| to zero. */ +/** Set the contents of the array |aT| to zero. */ template static MOZ_ALWAYS_INLINE void -PodArrayZero(T (&t)[N]) +PodArrayZero(T (&aT)[N]) { - memset(t, 0, N * sizeof(T)); + memset(aT, 0, N * sizeof(T)); } template static MOZ_ALWAYS_INLINE void -PodArrayZero(Array& arr) +PodArrayZero(Array& aArr) { - memset(&arr[0], 0, N * sizeof(T)); + memset(&aArr[0], 0, N * sizeof(T)); } /** - * Assign |*src| to |*dst|. The locations must not be the same and must not + * Assign |*aSrc| to |*aDst|. The locations must not be the same and must not * overlap. */ template static MOZ_ALWAYS_INLINE void -PodAssign(T* dst, const T* src) +PodAssign(T* aDst, const T* aSrc) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, PointerRangeSize(src, static_cast(dst)) >= 1); - MOZ_ASSERT_IF(dst < src, PointerRangeSize(static_cast(dst), src) >= 1); - memcpy(reinterpret_cast(dst), reinterpret_cast(src), sizeof(T)); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= 1); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= 1); + memcpy(reinterpret_cast(aDst), reinterpret_cast(aSrc), + sizeof(T)); } /** - * Copy |nelem| T elements from |src| to |dst|. The two memory ranges must not - * overlap! + * Copy |aNElem| T elements from |aSrc| to |aDst|. The two memory ranges must + * not overlap! */ template static MOZ_ALWAYS_INLINE void -PodCopy(T* dst, const T* src, size_t nelem) +PodCopy(T* aDst, const T* aSrc, size_t aNElem) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, PointerRangeSize(src, static_cast(dst)) >= nelem); - MOZ_ASSERT_IF(dst < src, PointerRangeSize(static_cast(dst), src) >= nelem); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); - if (nelem < 128) { + if (aNElem < 128) { /* * Avoid using operator= in this loop, as it may have been * intentionally deleted by the POD type. */ - for (const T* srcend = src + nelem; src < srcend; src++, dst++) - PodAssign(dst, src); + for (const T* srcend = aSrc + aNElem; aSrc < srcend; aSrc++, aDst++) { + PodAssign(aDst, aSrc); + } } else { - memcpy(dst, src, nelem * sizeof(T)); + memcpy(aDst, aSrc, aNElem * sizeof(T)); } } template static MOZ_ALWAYS_INLINE void -PodCopy(volatile T* dst, const volatile T* src, size_t nelem) +PodCopy(volatile T* aDst, const volatile T* aSrc, size_t aNElem) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, - PointerRangeSize(src, static_cast(dst)) >= nelem); - MOZ_ASSERT_IF(dst < src, - PointerRangeSize(static_cast(dst), src) >= nelem); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); /* - * Volatile |dst| requires extra work, because it's undefined behavior to + * Volatile |aDst| requires extra work, because it's undefined behavior to * modify volatile objects using the mem* functions. Just write out the * loops manually, using operator= rather than memcpy for the same reason, * and let the compiler optimize to the extent it can. */ - for (const volatile T* srcend = src + nelem; src < srcend; src++, dst++) - *dst = *src; + for (const volatile T* srcend = aSrc + aNElem; + aSrc < srcend; + aSrc++, aDst++) { + *aDst = *aSrc; + } } /* - * Copy the contents of the array |src| into the array |dst|, both of size N. + * Copy the contents of the array |aSrc| into the array |aDst|, both of size N. * The arrays must not overlap! */ template static MOZ_ALWAYS_INLINE void -PodArrayCopy(T (&dst)[N], const T (&src)[N]) +PodArrayCopy(T (&aDst)[N], const T (&aSrc)[N]) { - PodCopy(dst, src, N); + PodCopy(aDst, aSrc, N); } /** - * Copy the memory for |nelem| T elements from |src| to |dst|. If the two - * memory ranges overlap, then the effect is as if the |nelem| elements are - * first copied from |src| to a temporary array, and then from the temporary - * array to |dst|. + * Copy the memory for |aNElem| T elements from |aSrc| to |aDst|. If the two + * memory ranges overlap, then the effect is as if the |aNElem| elements are + * first copied from |aSrc| to a temporary array, and then from the temporary + * array to |aDst|. */ template static MOZ_ALWAYS_INLINE void -PodMove(T* dst, const T* src, size_t nelem) +PodMove(T* aDst, const T* aSrc, size_t aNElem) { - MOZ_ASSERT(nelem <= SIZE_MAX / sizeof(T), + MOZ_ASSERT(aNElem <= SIZE_MAX / sizeof(T), "trying to move an impossible number of elements"); - memmove(dst, src, nelem * sizeof(T)); + memmove(aDst, aSrc, aNElem * sizeof(T)); } /** @@ -170,8 +180,9 @@ PodEqual(const T* one, const T* two, size_t len) const T* p1 = one; const T* p2 = two; for (; p1 < p1end; p1++, p2++) { - if (*p1 != *p2) + if (*p1 != *p2) { return false; + } } return true; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Range.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Range.h index 4e02d962b5..814a2821ad 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Range.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Range.h @@ -18,32 +18,26 @@ namespace mozilla { template class Range { - RangedPtr mStart; - RangedPtr mEnd; + const RangedPtr mStart; + const RangedPtr mEnd; - typedef void (Range::* ConvertibleToBool)(); - void nonNull() {} + typedef void (Range::* ConvertibleToBool)(); + void nonNull() {} - public: - Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} - Range(T* p, size_t len) - : mStart(p, p, p + len), - mEnd(p + len, p, p + len) - {} +public: + Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} + Range(T* aPtr, size_t aLength) + : mStart(aPtr, aPtr, aPtr + aLength), + mEnd(aPtr + aLength, aPtr, aPtr + aLength) + {} - RangedPtr start() const { return mStart; } - RangedPtr end() const { return mEnd; } - size_t length() const { return mEnd - mStart; } + RangedPtr start() const { return mStart; } + RangedPtr end() const { return mEnd; } + size_t length() const { return mEnd - mStart; } - T& operator[](size_t offset) { - return mStart[offset]; - } + T& operator[](size_t aOffset) const { return mStart[aOffset]; } - const T& operator[](size_t offset) const { - return mStart[offset]; - } - - operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } + operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RangedPtr.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RangedPtr.h index 561e564ded..4d94035b90 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RangedPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RangedPtr.h @@ -43,214 +43,240 @@ namespace mozilla { template class RangedPtr { - T* ptr; + T* mPtr; #ifdef DEBUG - T* const rangeStart; - T* const rangeEnd; + T* const mRangeStart; + T* const mRangeEnd; #endif - typedef void (RangedPtr::* ConvertibleToBool)(); - void nonNull() {} + typedef void (RangedPtr::* ConvertibleToBool)(); + void nonNull() {} - void checkSanity() { - MOZ_ASSERT(rangeStart <= ptr); - MOZ_ASSERT(ptr <= rangeEnd); - } + void checkSanity() + { + MOZ_ASSERT(mRangeStart <= mPtr); + MOZ_ASSERT(mPtr <= mRangeEnd); + } - /* Creates a new pointer for |p|, restricted to this pointer's range. */ - RangedPtr create(T *p) const { + /* Creates a new pointer for |aPtr|, restricted to this pointer's range. */ + RangedPtr create(T* aPtr) const + { #ifdef DEBUG - return RangedPtr(p, rangeStart, rangeEnd); + return RangedPtr(aPtr, mRangeStart, mRangeEnd); #else - return RangedPtr(p, nullptr, size_t(0)); + return RangedPtr(aPtr, nullptr, size_t(0)); #endif - } + } - uintptr_t asUintptr() const { return uintptr_t(ptr); } + uintptr_t asUintptr() const { return reinterpret_cast(mPtr); } - public: - RangedPtr(T* p, T* start, T* end) - : ptr(p) +public: + RangedPtr(T* aPtr, T* aStart, T* aEnd) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(start), rangeEnd(end) + , mRangeStart(aStart), mRangeEnd(aEnd) #endif - { - MOZ_ASSERT(rangeStart <= rangeEnd); - checkSanity(); - } - RangedPtr(T* p, T* start, size_t length) - : ptr(p) + { + MOZ_ASSERT(mRangeStart <= mRangeEnd); + checkSanity(); + } + RangedPtr(T* aPtr, T* aStart, size_t aLength) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(start), rangeEnd(start + length) + , mRangeStart(aStart), mRangeEnd(aStart + aLength) #endif - { - MOZ_ASSERT(length <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(uintptr_t(rangeStart) + length * sizeof(T) >= uintptr_t(rangeStart)); - checkSanity(); - } - - /* Equivalent to RangedPtr(p, p, length). */ - RangedPtr(T* p, size_t length) - : ptr(p) + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aPtr, aPtr, aLength). */ + RangedPtr(T* aPtr, size_t aLength) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(p), rangeEnd(p + length) + , mRangeStart(aPtr), mRangeEnd(aPtr + aLength) #endif - { - MOZ_ASSERT(length <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(uintptr_t(rangeStart) + length * sizeof(T) >= uintptr_t(rangeStart)); - checkSanity(); - } - - /* Equivalent to RangedPtr(arr, arr, N). */ - template - RangedPtr(T (&arr)[N]) - : ptr(arr) + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aArr, aArr, N). */ + template + RangedPtr(T (&aArr)[N]) + : mPtr(aArr) #ifdef DEBUG - , rangeStart(arr), rangeEnd(arr + N) + , mRangeStart(aArr), mRangeEnd(aArr + N) #endif - { - checkSanity(); - } - - T* get() const { - return ptr; - } - - operator ConvertibleToBool() const { return ptr ? &RangedPtr::nonNull : 0; } - - /* - * You can only assign one RangedPtr into another if the two pointers have - * the same valid range: - * - * char arr1[] = "hi"; - * char arr2[] = "bye"; - * RangedPtr p1(arr1, 2); - * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works - * p1 = RangedPtr(arr2, 3); // asserts - */ - RangedPtr& operator=(const RangedPtr& other) { - MOZ_ASSERT(rangeStart == other.rangeStart); - MOZ_ASSERT(rangeEnd == other.rangeEnd); - ptr = other.ptr; - checkSanity(); - return *this; - } - - RangedPtr operator+(size_t inc) { - MOZ_ASSERT(inc <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(asUintptr() + inc * sizeof(T) >= asUintptr()); - return create(ptr + inc); - } - - RangedPtr operator-(size_t dec) { - MOZ_ASSERT(dec <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(asUintptr() - dec * sizeof(T) <= asUintptr()); - return create(ptr - dec); - } - - /* - * You can assign a raw pointer into a RangedPtr if the raw pointer is - * within the range specified at creation. - */ - template - RangedPtr& operator=(U* p) { - *this = create(p); - return *this; - } - - template - RangedPtr& operator=(const RangedPtr& p) { - MOZ_ASSERT(rangeStart <= p.ptr); - MOZ_ASSERT(p.ptr <= rangeEnd); - ptr = p.ptr; - checkSanity(); - return *this; - } - - RangedPtr& operator++() { - return (*this += 1); - } - - RangedPtr operator++(int) { - RangedPtr rcp = *this; - ++*this; - return rcp; - } - - RangedPtr& operator--() { - return (*this -= 1); - } - - RangedPtr operator--(int) { - RangedPtr rcp = *this; - --*this; - return rcp; - } - - RangedPtr& operator+=(size_t inc) { - *this = *this + inc; - return *this; - } - - RangedPtr& operator-=(size_t dec) { - *this = *this - dec; - return *this; - } - - T& operator[](int index) const { - MOZ_ASSERT(size_t(index > 0 ? index : -index) <= size_t(-1) / sizeof(T)); - return *create(ptr + index); - } - - T& operator*() const { - return *ptr; - } - - template - bool operator==(const RangedPtr& other) const { - return ptr == other.ptr; - } - template - bool operator!=(const RangedPtr& other) const { - return !(*this == other); - } - - template - bool operator==(const U* u) const { - return ptr == u; - } - template - bool operator!=(const U* u) const { - return !(*this == u); - } - - template - bool operator<(const RangedPtr& other) const { - return ptr < other.ptr; - } - template - bool operator<=(const RangedPtr& other) const { - return ptr <= other.ptr; - } - - template - bool operator>(const RangedPtr& other) const { - return ptr > other.ptr; - } - template - bool operator>=(const RangedPtr& other) const { - return ptr >= other.ptr; - } - - size_t operator-(const RangedPtr& other) const { - MOZ_ASSERT(ptr >= other.ptr); - return PointerRangeSize(other.ptr, ptr); - } - - private: - RangedPtr() MOZ_DELETE; - T* operator&() MOZ_DELETE; + { + checkSanity(); + } + + T* get() const { return mPtr; } + + operator ConvertibleToBool() const { return mPtr ? &RangedPtr::nonNull : 0; } + + /* + * You can only assign one RangedPtr into another if the two pointers have + * the same valid range: + * + * char arr1[] = "hi"; + * char arr2[] = "bye"; + * RangedPtr p1(arr1, 2); + * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works + * p1 = RangedPtr(arr2, 3); // asserts + */ + RangedPtr& operator=(const RangedPtr& aOther) + { + MOZ_ASSERT(mRangeStart == aOther.mRangeStart); + MOZ_ASSERT(mRangeEnd == aOther.mRangeEnd); + mPtr = aOther.mPtr; + checkSanity(); + return *this; + } + + RangedPtr operator+(size_t aInc) + { + MOZ_ASSERT(aInc <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() + aInc * sizeof(T) >= asUintptr()); + return create(mPtr + aInc); + } + + RangedPtr operator-(size_t aDec) + { + MOZ_ASSERT(aDec <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() - aDec * sizeof(T) <= asUintptr()); + return create(mPtr - aDec); + } + + /* + * You can assign a raw pointer into a RangedPtr if the raw pointer is + * within the range specified at creation. + */ + template + RangedPtr& operator=(U* aPtr) + { + *this = create(aPtr); + return *this; + } + + template + RangedPtr& operator=(const RangedPtr& aPtr) + { + MOZ_ASSERT(mRangeStart <= aPtr.mPtr); + MOZ_ASSERT(aPtr.mPtr <= mRangeEnd); + mPtr = aPtr.mPtr; + checkSanity(); + return *this; + } + + RangedPtr& operator++() + { + return (*this += 1); + } + + RangedPtr operator++(int) + { + RangedPtr rcp = *this; + ++*this; + return rcp; + } + + RangedPtr& operator--() + { + return (*this -= 1); + } + + RangedPtr operator--(int) + { + RangedPtr rcp = *this; + --*this; + return rcp; + } + + RangedPtr& operator+=(size_t aInc) + { + *this = *this + aInc; + return *this; + } + + RangedPtr& operator-=(size_t aDec) + { + *this = *this - aDec; + return *this; + } + + T& operator[](int aIndex) const + { + MOZ_ASSERT(size_t(aIndex > 0 ? aIndex : -aIndex) <= size_t(-1) / sizeof(T)); + return *create(mPtr + aIndex); + } + + T& operator*() const + { + MOZ_ASSERT(mPtr >= mRangeStart); + MOZ_ASSERT(mPtr < mRangeEnd); + return *mPtr; + } + + template + bool operator==(const RangedPtr& aOther) const + { + return mPtr == aOther.mPtr; + } + template + bool operator!=(const RangedPtr& aOther) const + { + return !(*this == aOther); + } + + template + bool operator==(const U* u) const + { + return mPtr == u; + } + template + bool operator!=(const U* u) const + { + return !(*this == u); + } + + template + bool operator<(const RangedPtr& aOther) const + { + return mPtr < aOther.mPtr; + } + template + bool operator<=(const RangedPtr& aOther) const + { + return mPtr <= aOther.mPtr; + } + + template + bool operator>(const RangedPtr& aOther) const + { + return mPtr > aOther.mPtr; + } + template + bool operator>=(const RangedPtr& aOther) const + { + return mPtr >= aOther.mPtr; + } + + size_t operator-(const RangedPtr& aOther) const + { + MOZ_ASSERT(mPtr >= aOther.mPtr); + return PointerRangeSize(aOther.mPtr, mPtr); + } + +private: + RangedPtr() MOZ_DELETE; + T* operator&() MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ReentrancyGuard.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ReentrancyGuard.h index d589f368a2..557c61015e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ReentrancyGuard.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ReentrancyGuard.h @@ -18,38 +18,38 @@ namespace mozilla { /* Useful for implementing containers that assert non-reentrancy */ class ReentrancyGuard { - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER #ifdef DEBUG - bool& entered; + bool& mEntered; #endif - public: - template +public: + template #ifdef DEBUG - ReentrancyGuard(T& obj - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : entered(obj.entered) + ReentrancyGuard(T& aObj + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mEntered(aObj.mEntered) #else - ReentrancyGuard(T& - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + ReentrancyGuard(T& + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) #endif - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; #ifdef DEBUG - MOZ_ASSERT(!entered); - entered = true; + MOZ_ASSERT(!mEntered); + mEntered = true; #endif - } - ~ReentrancyGuard() - { + } + ~ReentrancyGuard() + { #ifdef DEBUG - entered = false; + mEntered = false; #endif - } + } - private: - ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; - void operator=(const ReentrancyGuard&) MOZ_DELETE; +private: + ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; + void operator=(const ReentrancyGuard&) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RefCountType.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RefCountType.h new file mode 100644 index 0000000000..e95a22a0ca --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RefCountType.h @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_RefCountType_h +#define mozilla_RefCountType_h + +#include + +/** + * MozRefCountType is Mozilla's reference count type. + * + * We use the same type to represent the refcount of RefCounted objects + * as well, in order to be able to use the leak detection facilities + * that are implemented by XPCOM. + * + * Note that this type is not in the mozilla namespace so that it is + * usable for both C and C++ code. + */ +typedef uintptr_t MozRefCountType; + +/* + * This is the return type for AddRef() and Release() in nsISupports. + * IUnknown of COM returns an unsigned long from equivalent functions. + * + * The following ifdef exists to maintain binary compatibility with + * IUnknown, the base interface in Microsoft COM. + */ +#ifdef XP_WIN +typedef unsigned long MozExternalRefCountType; +#else +typedef uint32_t MozExternalRefCountType; +#endif + +#endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RefPtr.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RefPtr.h index 72c7904554..4901067b4c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RefPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RefPtr.h @@ -12,7 +12,17 @@ #include "mozilla/Assertions.h" #include "mozilla/Atomics.h" #include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" +#include "mozilla/RefCountType.h" #include "mozilla/TypeTraits.h" +#if defined(MOZILLA_INTERNAL_API) +#include "nsXPCOM.h" +#endif + +#if defined(MOZILLA_INTERNAL_API) && \ + (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) +#define MOZ_REFCOUNTED_LEAK_CHECKING +#endif namespace mozilla { @@ -42,10 +52,37 @@ template OutParamRef byRef(RefPtr&); * state is represented in DEBUG builds by refcount==0xffffdead. This * state distinguishes use-before-ref (refcount==0) from * use-after-destroy (refcount==0xffffdead). + * + * Note that when deriving from RefCounted or AtomicRefCounted, you + * should add MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public + * section of your class, where ClassName is the name of your class. */ namespace detail { #ifdef DEBUG -static const int DEAD = 0xffffdead; +const MozRefCountType DEAD = 0xffffdead; +#endif + +// When building code that gets compiled into Gecko, try to use the +// trace-refcount leak logging facilities. +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +class RefCountLogger +{ +public: + static void logAddRef(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName, uint32_t aInstanceSize) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogAddRef(const_cast(aPointer), aRefCount, aTypeName, + aInstanceSize); + } + + static void logRelease(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogRelease(const_cast(aPointer), aRefCount, aTypeName); + } +}; #endif // This is used WeakPtr.h as well as this file. @@ -58,70 +95,122 @@ enum RefCountAtomicity template class RefCounted { - friend class RefPtr; + friend class RefPtr; - protected: - RefCounted() : refCnt(0) { } - ~RefCounted() { - MOZ_ASSERT(refCnt == detail::DEAD); - } +protected: + RefCounted() : mRefCnt(0) {} + ~RefCounted() { MOZ_ASSERT(mRefCnt == detail::DEAD); } - public: - // Compatibility with nsRefPtr. - void AddRef() const { - MOZ_ASSERT(refCnt >= 0); - ++refCnt; - } +public: + // Compatibility with nsRefPtr. + void AddRef() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) >= 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + ++mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + uint32_t size = static_cast(this)->typeSize(); + const void* ptr = static_cast(this); + MozRefCountType cnt = ++mRefCnt; + detail::RefCountLogger::logAddRef(ptr, cnt, type, size); +#endif + } - void Release() const { - MOZ_ASSERT(refCnt > 0); - if (0 == --refCnt) { + void Release() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) > 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + MozRefCountType cnt = --mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + const void* ptr = static_cast(this); + MozRefCountType cnt = --mRefCnt; + // Note: it's not safe to touch |this| after decrementing the refcount, + // except for below. + detail::RefCountLogger::logRelease(ptr, cnt, type); +#endif + if (0 == cnt) { + // Because we have atomically decremented the refcount above, only + // one thread can get a 0 count here, so as long as we can assume that + // everything else in the system is accessing this object through + // RefPtrs, it's safe to access |this| here. #ifdef DEBUG - refCnt = detail::DEAD; + mRefCnt = detail::DEAD; #endif - delete static_cast(this); - } + delete static_cast(this); } + } - // Compatibility with wtf::RefPtr. - void ref() { AddRef(); } - void deref() { Release(); } - int refCount() const { return refCnt; } - bool hasOneRef() const { - MOZ_ASSERT(refCnt > 0); - return refCnt == 1; - } + // Compatibility with wtf::RefPtr. + void ref() { AddRef(); } + void deref() { Release(); } + MozRefCountType refCount() const { return mRefCnt; } + bool hasOneRef() const + { + MOZ_ASSERT(mRefCnt > 0); + return mRefCnt == 1; + } - private: - mutable typename Conditional, int>::Type refCnt; +private: + mutable typename Conditional, + MozRefCountType>::Type mRefCnt; }; -} +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) \ + virtual const char* typeName() const { return #T; } \ + virtual size_t typeSize() const { return sizeof(*this); } +#else +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) +#endif + +// Note that this macro is expanded unconditionally because it declares only +// two small inline functions which will hopefully get eliminated by the linker +// in non-leak-checking builds. +#define MOZ_DECLARE_REFCOUNTED_TYPENAME(T) \ + const char* typeName() const { return #T; } \ + size_t typeSize() const { return sizeof(*this); } + +} // namespace detail template class RefCounted : public detail::RefCounted { - public: - ~RefCounted() { - static_assert(IsBaseOf::value, - "T must derive from RefCounted"); - } +public: + ~RefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from RefCounted"); + } }; +namespace external { + /** * AtomicRefCounted is like RefCounted, with an atomically updated * reference counter. + * + * NOTE: Please do not use this class, use NS_INLINE_DECL_THREADSAFE_REFCOUNTING + * instead. */ template -class AtomicRefCounted : public detail::RefCounted +class AtomicRefCounted : + public mozilla::detail::RefCounted { - public: - ~AtomicRefCounted() { - static_assert(IsBaseOf::value, - "T must derive from AtomicRefCounted"); - } +public: + ~AtomicRefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from AtomicRefCounted"); + } }; +} // namespace external + /** * RefPtr points to a refcounted thing that has AddRef and Release * methods to increase/decrease the refcount, respectively. After a @@ -135,73 +224,83 @@ class AtomicRefCounted : public detail::RefCounted template class RefPtr { - // To allow them to use unref() - friend class TemporaryRef; - friend class OutParamRef; + // To allow them to use unref() + friend class TemporaryRef; + friend class OutParamRef; - struct DontRef {}; + struct DontRef {}; - public: - RefPtr() : ptr(0) { } - RefPtr(const RefPtr& o) : ptr(ref(o.ptr)) {} - RefPtr(const TemporaryRef& o) : ptr(o.drop()) {} - RefPtr(T* t) : ptr(ref(t)) {} +public: + RefPtr() : mPtr(0) {} + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.mPtr)) {} + MOZ_IMPLICIT RefPtr(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + MOZ_IMPLICIT RefPtr(T* aVal) : mPtr(ref(aVal)) {} - template - RefPtr(const RefPtr& o) : ptr(ref(o.get())) {} + template + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.get())) {} - ~RefPtr() { unref(ptr); } + ~RefPtr() { unref(mPtr); } - RefPtr& operator=(const RefPtr& o) { - assign(ref(o.ptr)); - return *this; - } - RefPtr& operator=(const TemporaryRef& o) { - assign(o.drop()); - return *this; - } - RefPtr& operator=(T* t) { - assign(ref(t)); - return *this; - } + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.mPtr)); + return *this; + } + RefPtr& operator=(const TemporaryRef& aOther) + { + assign(aOther.drop()); + return *this; + } + RefPtr& operator=(T* aVal) + { + assign(ref(aVal)); + return *this; + } - template - RefPtr& operator=(const RefPtr& o) { - assign(ref(o.get())); - return *this; - } + template + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.get())); + return *this; + } - TemporaryRef forget() { - T* tmp = ptr; - ptr = 0; - return TemporaryRef(tmp, DontRef()); - } + TemporaryRef forget() + { + T* tmp = mPtr; + mPtr = nullptr; + return TemporaryRef(tmp, DontRef()); + } - T* get() const { return ptr; } - operator T*() const { return ptr; } - T* operator->() const { return ptr; } - T& operator*() const { return *ptr; } - template - operator TemporaryRef() { return TemporaryRef(ptr); } - - private: - void assign(T* t) { - unref(ptr); - ptr = t; - } + T* get() const { return mPtr; } + operator T*() const { return mPtr; } + T* operator->() const { return mPtr; } + T& operator*() const { return *mPtr; } + template + operator TemporaryRef() { return TemporaryRef(mPtr); } + +private: + void assign(T* aVal) + { + unref(mPtr); + mPtr = aVal; + } - T* ptr; + T* mPtr; - static MOZ_ALWAYS_INLINE T* ref(T* t) { - if (t) - t->AddRef(); - return t; + static MOZ_ALWAYS_INLINE T* ref(T* aVal) + { + if (aVal) { + aVal->AddRef(); } + return aVal; + } - static MOZ_ALWAYS_INLINE void unref(T* t) { - if (t) - t->Release(); + static MOZ_ALWAYS_INLINE void unref(T* aVal) + { + if (aVal) { + aVal->Release(); } + } }; /** @@ -213,33 +312,34 @@ class RefPtr template class TemporaryRef { - // To allow it to construct TemporaryRef from a bare T* - friend class RefPtr; + // To allow it to construct TemporaryRef from a bare T* + friend class RefPtr; - typedef typename RefPtr::DontRef DontRef; + typedef typename RefPtr::DontRef DontRef; - public: - TemporaryRef(T* t) : ptr(RefPtr::ref(t)) {} - TemporaryRef(const TemporaryRef& o) : ptr(o.drop()) {} +public: + MOZ_IMPLICIT TemporaryRef(T* aVal) : mPtr(RefPtr::ref(aVal)) {} + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} - template - TemporaryRef(const TemporaryRef& o) : ptr(o.drop()) {} + template + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} - ~TemporaryRef() { RefPtr::unref(ptr); } + ~TemporaryRef() { RefPtr::unref(mPtr); } - T* drop() const { - T* tmp = ptr; - ptr = 0; - return tmp; - } + T* drop() const + { + T* tmp = mPtr; + mPtr = nullptr; + return tmp; + } - private: - TemporaryRef(T* t, const DontRef&) : ptr(t) {} +private: + TemporaryRef(T* aVal, const DontRef&) : mPtr(aVal) {} - mutable T* ptr; + mutable T* mPtr; - TemporaryRef() MOZ_DELETE; - void operator=(const TemporaryRef&) MOZ_DELETE; + TemporaryRef() MOZ_DELETE; + void operator=(const TemporaryRef&) MOZ_DELETE; }; /** @@ -259,24 +359,25 @@ class TemporaryRef template class OutParamRef { - friend OutParamRef byRef(RefPtr&); + friend OutParamRef byRef(RefPtr&); - public: - ~OutParamRef() { - RefPtr::unref(refPtr.ptr); - refPtr.ptr = tmp; - } +public: + ~OutParamRef() + { + RefPtr::unref(mRefPtr.mPtr); + mRefPtr.mPtr = mTmp; + } - operator T**() { return &tmp; } + operator T**() { return &mTmp; } - private: - OutParamRef(RefPtr& p) : refPtr(p), tmp(p.get()) {} +private: + explicit OutParamRef(RefPtr& p) : mRefPtr(p), mTmp(p.get()) {} - RefPtr& refPtr; - T* tmp; + RefPtr& mRefPtr; + T* mTmp; - OutParamRef() MOZ_DELETE; - OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; + OutParamRef() MOZ_DELETE; + OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; }; /** @@ -284,9 +385,9 @@ class OutParamRef */ template OutParamRef -byRef(RefPtr& ptr) +byRef(RefPtr& aPtr) { - return OutParamRef(ptr); + return OutParamRef(aPtr); } } // namespace mozilla @@ -301,19 +402,21 @@ using namespace mozilla; struct Foo : public RefCounted { - Foo() : dead(false) { } - ~Foo() { - MOZ_ASSERT(!dead); - dead = true; - numDestroyed++; + MOZ_DECLARE_REFCOUNTED_TYPENAME(Foo) + Foo() : mDead(false) {} + ~Foo() + { + MOZ_ASSERT(!mDead); + mDead = true; + sNumDestroyed++; } - bool dead; - static int numDestroyed; + bool mDead; + static int sNumDestroyed; }; -int Foo::numDestroyed; +int Foo::sNumDestroyed; -struct Bar : public Foo { }; +struct Bar : public Foo {}; TemporaryRef NewFoo() @@ -364,25 +467,25 @@ main(int argc, char** argv) // This should blow up // Foo* f = new Foo(); delete f; - MOZ_ASSERT(0 == Foo::numDestroyed); + MOZ_ASSERT(0 == Foo::sNumDestroyed); { RefPtr f = new Foo(); MOZ_ASSERT(f->refCount() == 1); } - MOZ_ASSERT(1 == Foo::numDestroyed); + MOZ_ASSERT(1 == Foo::sNumDestroyed); { RefPtr f1 = NewFoo(); RefPtr f2(NewFoo()); - MOZ_ASSERT(1 == Foo::numDestroyed); + MOZ_ASSERT(1 == Foo::sNumDestroyed); } - MOZ_ASSERT(3 == Foo::numDestroyed); + MOZ_ASSERT(3 == Foo::sNumDestroyed); { RefPtr b = NewBar(); - MOZ_ASSERT(3 == Foo::numDestroyed); + MOZ_ASSERT(3 == Foo::sNumDestroyed); } - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); { RefPtr f1; @@ -390,56 +493,56 @@ main(int argc, char** argv) f1 = new Foo(); RefPtr f2(f1); RefPtr f3 = f2; - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); } - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); } - MOZ_ASSERT(5 == Foo::numDestroyed); + MOZ_ASSERT(5 == Foo::sNumDestroyed); { RefPtr f = new Foo(); f.forget(); - MOZ_ASSERT(6 == Foo::numDestroyed); + MOZ_ASSERT(6 == Foo::sNumDestroyed); } { RefPtr f = new Foo(); GetNewFoo(byRef(f)); - MOZ_ASSERT(7 == Foo::numDestroyed); + MOZ_ASSERT(7 == Foo::sNumDestroyed); } - MOZ_ASSERT(8 == Foo::numDestroyed); + MOZ_ASSERT(8 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetPassedFoo(byRef(f)); - MOZ_ASSERT(8 == Foo::numDestroyed); + MOZ_ASSERT(8 == Foo::sNumDestroyed); } - MOZ_ASSERT(9 == Foo::numDestroyed); + MOZ_ASSERT(9 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetNewFoo(&f); - MOZ_ASSERT(10 == Foo::numDestroyed); + MOZ_ASSERT(10 == Foo::sNumDestroyed); } - MOZ_ASSERT(11 == Foo::numDestroyed); + MOZ_ASSERT(11 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetPassedFoo(&f); - MOZ_ASSERT(11 == Foo::numDestroyed); + MOZ_ASSERT(11 == Foo::sNumDestroyed); } - MOZ_ASSERT(12 == Foo::numDestroyed); + MOZ_ASSERT(12 == Foo::sNumDestroyed); { RefPtr f1 = new Bar(); } - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); { RefPtr f = GetNullFoo(); - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); } - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); return 0; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RollingMean.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RollingMean.h index 5caee3bc83..5add14c879 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RollingMean.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/RollingMean.h @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-w idth: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -12,9 +13,7 @@ #include "mozilla/TypeTraits.h" #include "mozilla/Vector.h" -#include #include -#include namespace mozilla { @@ -30,78 +29,85 @@ namespace mozilla { template class RollingMean { - private: - size_t mInsertIndex; - size_t mMaxValues; - Vector mValues; - S mTotal; - - public: - static_assert(!IsFloatingPoint::value, - "floating-point types are unsupported due to rounding " - "errors"); - - RollingMean(size_t aMaxValues) - : mInsertIndex(0), - mMaxValues(aMaxValues), - mTotal(0) - { - MOZ_ASSERT(aMaxValues > 0); - } - - RollingMean& operator=(RollingMean&& aOther) { - MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); - this->~RollingMean(); - new(this) RollingMean(aOther.mMaxValues); - mInsertIndex = aOther.mInsertIndex; - mTotal = aOther.mTotal; - mValues.swap(aOther.mValues); - return *this; - } - - /** - * Insert a value into the rolling mean. - */ - bool insert(T aValue) { - MOZ_ASSERT(mValues.length() <= mMaxValues); - - if (mValues.length() == mMaxValues) { - mTotal = mTotal - mValues[mInsertIndex] + aValue; - mValues[mInsertIndex] = aValue; - } else { - if (!mValues.append(aValue)) - return false; - mTotal = mTotal + aValue; +private: + size_t mInsertIndex; + size_t mMaxValues; + Vector mValues; + S mTotal; + +public: + static_assert(!IsFloatingPoint::value, + "floating-point types are unsupported due to rounding " + "errors"); + + explicit RollingMean(size_t aMaxValues) + : mInsertIndex(0), + mMaxValues(aMaxValues), + mTotal(0) + { + MOZ_ASSERT(aMaxValues > 0); + } + + RollingMean& operator=(RollingMean&& aOther) + { + MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); + this->~RollingMean(); + new(this) RollingMean(aOther.mMaxValues); + mInsertIndex = aOther.mInsertIndex; + mTotal = aOther.mTotal; + mValues.swap(aOther.mValues); + return *this; + } + + /** + * Insert a value into the rolling mean. + */ + bool insert(T aValue) + { + MOZ_ASSERT(mValues.length() <= mMaxValues); + + if (mValues.length() == mMaxValues) { + mTotal = mTotal - mValues[mInsertIndex] + aValue; + mValues[mInsertIndex] = aValue; + } else { + if (!mValues.append(aValue)) { + return false; } - - mInsertIndex = (mInsertIndex + 1) % mMaxValues; - return true; - } - - /** - * Calculate the rolling mean. - */ - T mean() { - MOZ_ASSERT(!empty()); - return T(mTotal / mValues.length()); - } - - bool empty() { - return mValues.empty(); + mTotal = mTotal + aValue; } - /** - * Remove all values from the rolling mean. - */ - void clear() { - mValues.clear(); - mInsertIndex = 0; - mTotal = T(0); - } - - size_t maxValues() { - return mMaxValues; - } + mInsertIndex = (mInsertIndex + 1) % mMaxValues; + return true; + } + + /** + * Calculate the rolling mean. + */ + T mean() + { + MOZ_ASSERT(!empty()); + return T(mTotal / mValues.length()); + } + + bool empty() + { + return mValues.empty(); + } + + /** + * Remove all values from the rolling mean. + */ + void clear() + { + mValues.clear(); + mInsertIndex = 0; + mTotal = T(0); + } + + size_t maxValues() + { + return mMaxValues; + } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/SHA1.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/SHA1.h index b167648540..ddccaa67e7 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/SHA1.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/SHA1.h @@ -36,25 +36,26 @@ namespace mozilla { */ class SHA1Sum { - union { - uint32_t w[16]; /* input buffer */ - uint8_t b[64]; - } u; - uint64_t size; /* count of hashed bytes. */ - unsigned H[22]; /* 5 state variables, 16 tmp values, 1 extra */ - bool mDone; - - public: - MFBT_API SHA1Sum(); - - static const size_t HashSize = 20; - typedef uint8_t Hash[HashSize]; - - /* Add len bytes of dataIn to the data sequence being hashed. */ - MFBT_API void update(const void* dataIn, uint32_t len); - - /* Compute the final hash of all data into hashOut. */ - MFBT_API void finish(SHA1Sum::Hash& hashOut); + union + { + uint32_t mW[16]; /* input buffer */ + uint8_t mB[64]; + } mU; + uint64_t mSize; /* count of hashed bytes. */ + unsigned mH[22]; /* 5 state variables, 16 tmp values, 1 extra */ + bool mDone; + +public: + MFBT_API SHA1Sum(); + + static const size_t kHashSize = 20; + typedef uint8_t Hash[kHashSize]; + + /* Add len bytes of dataIn to the data sequence being hashed. */ + MFBT_API void update(const void* aData, uint32_t aLength); + + /* Compute the final hash of all data into hashOut. */ + MFBT_API void finish(SHA1Sum::Hash& aHashOut); }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Scoped.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Scoped.h index fc48584b3e..3f854d6375 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Scoped.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Scoped.h @@ -52,8 +52,10 @@ * the scope, graphics contexts, etc. */ +#include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/GuardObjects.h" +#include "mozilla/Move.h" #include "mozilla/NullPtr.h" namespace mozilla { @@ -62,7 +64,8 @@ namespace mozilla { * Scoped is a helper to create RAII wrappers * Type argument |Traits| is expected to have the following structure: * - * struct Traits { + * struct Traits + * { * // Define the type of the value stored in the wrapper * typedef value_type type; * // Returns the value corresponding to the uninitialized or freed state @@ -75,84 +78,102 @@ namespace mozilla { template class Scoped { - public: - typedef typename Traits::type Resource; +public: + typedef typename Traits::type Resource; - explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) - : value(Traits::empty()) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - explicit Scoped(const Resource& v - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : value(v) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - ~Scoped() { - Traits::release(value); - } + explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + : mValue(Traits::empty()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } - // Constant getter - operator const Resource&() const { return value; } - const Resource& operator->() const { return value; } - const Resource& get() const { return value; } - // Non-constant getter. - Resource& rwget() { return value; } + explicit Scoped(const Resource& aValue + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(aValue) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } - /* - * Forget the resource. - * - * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will - * have no effect at destruction (unless it is reset to another resource by - * |operator=|). - * - * @return The original resource. - */ - Resource forget() { - Resource tmp = value; - value = Traits::empty(); - return tmp; - } + /* Move constructor. */ + explicit Scoped(Scoped&& aOther + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(Move(aOther.mValue)) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + aOther.mValue = Traits::empty(); + } - /* - * Perform immediate clean-up of this |Scoped|. - * - * If this |Scoped| is currently empty, this method has no effect. - */ - void dispose() { - Traits::release(value); - value = Traits::empty(); - } + ~Scoped() { Traits::release(mValue); } - bool operator==(const Resource& other) const { - return value == other; - } + // Constant getter + operator const Resource&() const { return mValue; } + const Resource& operator->() const { return mValue; } + const Resource& get() const { return mValue; } + // Non-constant getter. + Resource& rwget() { return mValue; } - /* - * Replace the resource with another resource. - * - * Calling |operator=| has the side-effect of triggering clean-up. If you do - * not want to trigger clean-up, you should first invoke |forget|. - * - * @return this - */ - Scoped& operator=(const Resource& other) { - return reset(other); - } - Scoped& reset(const Resource& other) { - Traits::release(value); - value = other; - return *this; - } + /* + * Forget the resource. + * + * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will + * have no effect at destruction (unless it is reset to another resource by + * |operator=|). + * + * @return The original resource. + */ + Resource forget() + { + Resource tmp = mValue; + mValue = Traits::empty(); + return tmp; + } + + /* + * Perform immediate clean-up of this |Scoped|. + * + * If this |Scoped| is currently empty, this method has no effect. + */ + void dispose() + { + Traits::release(mValue); + mValue = Traits::empty(); + } + + bool operator==(const Resource& aOther) const { return mValue == aOther; } + + /* + * Replace the resource with another resource. + * + * Calling |operator=| has the side-effect of triggering clean-up. If you do + * not want to trigger clean-up, you should first invoke |forget|. + * + * @return this + */ + Scoped& operator=(const Resource& aOther) { return reset(aOther); } + + Scoped& reset(const Resource& aOther) + { + Traits::release(mValue); + mValue = aOther; + return *this; + } + + /* Move assignment operator. */ + Scoped& operator=(Scoped&& aRhs) + { + MOZ_ASSERT(&aRhs != this, "self-move-assignment not allowed"); + this->~Scoped(); + new(this) Scoped(Move(aRhs)); + return *this; + } - private: - explicit Scoped(const Scoped& value) MOZ_DELETE; - Scoped& operator=(const Scoped& value) MOZ_DELETE; +private: + explicit Scoped(const Scoped& aValue) MOZ_DELETE; + Scoped& operator=(const Scoped& aValue) MOZ_DELETE; - private: - Resource value; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +private: + Resource mValue; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER }; /* @@ -163,26 +184,38 @@ class Scoped * @param Traits A struct implementing clean-up. See the implementations * for more details. */ -#define SCOPED_TEMPLATE(name, Traits) \ -template \ -struct name : public mozilla::Scoped > \ -{ \ - typedef mozilla::Scoped > Super; \ - typedef typename Super::Resource Resource; \ - name& operator=(Resource ptr) { \ - Super::operator=(ptr); \ - return *this; \ - } \ - explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ - : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ - {} \ - explicit name(Resource ptr \ - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ - : Super(ptr MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ - {} \ - private: \ - explicit name(name& source) MOZ_DELETE; \ - name& operator=(name& source) MOZ_DELETE; \ +#define SCOPED_TEMPLATE(name, Traits) \ +template \ +struct name : public mozilla::Scoped > \ +{ \ + typedef mozilla::Scoped > Super; \ + typedef typename Super::Resource Resource; \ + name& operator=(Resource aRhs) \ + { \ + Super::operator=(aRhs); \ + return *this; \ + } \ + name& operator=(name&& aRhs) \ + { \ + Super::operator=(Move(aRhs)); \ + return *this; \ + } \ + explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ + : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ + {} \ + explicit name(Resource aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ + explicit name(name&& aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(Move(aRhs) \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ +private: \ + explicit name(name&) MOZ_DELETE; \ + name& operator=(name&) MOZ_DELETE; \ }; /* @@ -195,9 +228,9 @@ struct name : public mozilla::Scoped > \ template struct ScopedFreePtrTraits { - typedef T* type; - static T* empty() { return nullptr; } - static void release(T* ptr) { free(ptr); } + typedef T* type; + static T* empty() { return nullptr; } + static void release(T* aPtr) { free(aPtr); } }; SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) @@ -210,7 +243,7 @@ SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) template struct ScopedDeletePtrTraits : public ScopedFreePtrTraits { - static void release(T* ptr) { delete ptr; } + static void release(T* aPtr) { delete aPtr; } }; SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) @@ -223,7 +256,7 @@ SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) template struct ScopedDeleteArrayTraits : public ScopedFreePtrTraits { - static void release(T* ptr) { delete [] ptr; } + static void release(T* aPtr) { delete [] aPtr; } }; SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) @@ -250,21 +283,22 @@ SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) * } // file is closed with PR_Close here */ #define MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(name, Type, Deleter) \ -template <> inline void TypeSpecificDelete(Type * value) { Deleter(value); } \ +template <> inline void TypeSpecificDelete(Type* aValue) { Deleter(aValue); } \ typedef ::mozilla::TypeSpecificScopedPointer name; -template void TypeSpecificDelete(T * value); +template void TypeSpecificDelete(T* aValue); template struct TypeSpecificScopedPointerTraits { - typedef T* type; - const static type empty() { return nullptr; } - const static void release(type value) - { - if (value) - TypeSpecificDelete(value); + typedef T* type; + static type empty() { return nullptr; } + static void release(type aValue) + { + if (aValue) { + TypeSpecificDelete(aValue); } + } }; SCOPED_TEMPLATE(TypeSpecificScopedPointer, TypeSpecificScopedPointerTraits) diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/SplayTree.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/SplayTree.h index 58ba5432b6..a6d692266f 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/SplayTree.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/SplayTree.h @@ -23,18 +23,20 @@ class SplayTree; template class SplayTreeNode { - public: - template - friend class SplayTree; - - SplayTreeNode() - : left(nullptr), right(nullptr), parent(nullptr) - {} - - private: - T* left; - T* right; - T* parent; +public: + template + friend class SplayTree; + + SplayTreeNode() + : mLeft(nullptr) + , mRight(nullptr) + , mParent(nullptr) + {} + +private: + T* mLeft; + T* mRight; + T* mParent; }; @@ -51,232 +53,242 @@ class SplayTreeNode template class SplayTree { - T* root; - T* freeList; + T* mRoot; - public: - SplayTree() - : root(nullptr), freeList(nullptr) - {} - - bool empty() const { - return !root; - } +public: + SplayTree() + : mRoot(nullptr) + {} - T* find(const T& v) - { - if (empty()) - return nullptr; + bool empty() const + { + return !mRoot; + } - T* last = lookup(v); - splay(last); - checkCoherency(root, nullptr); - return Comparator::compare(v, *last) == 0 ? last : nullptr; + T* find(const T& aValue) + { + if (empty()) { + return nullptr; } - bool insert(T* v) - { - MOZ_ASSERT(!find(*v), "Duplicate elements are not allowed."); - - if (!root) { - root = v; - return true; - } - T* last = lookup(*v); - int cmp = Comparator::compare(*v, *last); + T* last = lookup(aValue); + splay(last); + checkCoherency(mRoot, nullptr); + return Comparator::compare(aValue, *last) == 0 ? last : nullptr; + } - T** parentPointer = (cmp < 0) ? &last->left : &last->right; - MOZ_ASSERT(!*parentPointer); - *parentPointer = v; - v->parent = last; + bool insert(T* aValue) + { + MOZ_ASSERT(!find(*aValue), "Duplicate elements are not allowed."); - splay(v); - checkCoherency(root, nullptr); + if (!mRoot) { + mRoot = aValue; return true; } - - T* remove(const T& v) - { - T* last = lookup(v); - MOZ_ASSERT(last, "This tree must contain the element being removed."); - MOZ_ASSERT(Comparator::compare(v, *last) == 0); - - // Splay the tree so that the item to remove is the root. - splay(last); - MOZ_ASSERT(last == root); - - // Find another node which can be swapped in for the root: either the - // rightmost child of the root's left, or the leftmost child of the - // root's right. - T* swap; - T* swapChild; - if (root->left) { - swap = root->left; - while (swap->right) - swap = swap->right; - swapChild = swap->left; - } else if (root->right) { - swap = root->right; - while (swap->left) - swap = swap->left; - swapChild = swap->right; - } else { - T* result = root; - root = nullptr; - return result; - } - - // The selected node has at most one child, in swapChild. Detach it - // from the subtree by replacing it with that child. - if (swap == swap->parent->left) - swap->parent->left = swapChild; - else - swap->parent->right = swapChild; - if (swapChild) - swapChild->parent = swap->parent; - - // Make the selected node the new root. - root = swap; - root->parent = nullptr; - root->left = last->left; - root->right = last->right; - if (root->left) { - root->left->parent = root; + T* last = lookup(*aValue); + int cmp = Comparator::compare(*aValue, *last); + + T** parentPointer = (cmp < 0) ? &last->mLeft : &last->mRight; + MOZ_ASSERT(!*parentPointer); + *parentPointer = aValue; + aValue->mParent = last; + + splay(aValue); + checkCoherency(mRoot, nullptr); + return true; + } + + T* remove(const T& aValue) + { + T* last = lookup(aValue); + MOZ_ASSERT(last, "This tree must contain the element being removed."); + MOZ_ASSERT(Comparator::compare(aValue, *last) == 0); + + // Splay the tree so that the item to remove is the root. + splay(last); + MOZ_ASSERT(last == mRoot); + + // Find another node which can be swapped in for the root: either the + // rightmost child of the root's left, or the leftmost child of the + // root's right. + T* swap; + T* swapChild; + if (mRoot->mLeft) { + swap = mRoot->mLeft; + while (swap->mRight) { + swap = swap->mRight; } - if (root->right) { - root->right->parent = root; + swapChild = swap->mLeft; + } else if (mRoot->mRight) { + swap = mRoot->mRight; + while (swap->mLeft) { + swap = swap->mLeft; } - - checkCoherency(root, nullptr); - return last; + swapChild = swap->mRight; + } else { + T* result = mRoot; + mRoot = nullptr; + return result; } - T* removeMin() - { - MOZ_ASSERT(root, "No min to remove!"); - - T* min = root; - while (min->left) - min = min->left; - return remove(*min); + // The selected node has at most one child, in swapChild. Detach it + // from the subtree by replacing it with that child. + if (swap == swap->mParent->mLeft) { + swap->mParent->mLeft = swapChild; + } else { + swap->mParent->mRight = swapChild; } - - private: - /** - * Returns the node in this comparing equal to |v|, or a node just greater or - * just less than |v| if there is no such node. - */ - T* lookup(const T& v) - { - MOZ_ASSERT(!empty()); - - T* node = root; - T* parent; - do { - parent = node; - int c = Comparator::compare(v, *node); - if (c == 0) - return node; - else if (c < 0) - node = node->left; - else - node = node->right; - } while (node); - return parent; + if (swapChild) { + swapChild->mParent = swap->mParent; } - /** - * Rotate the tree until |node| is at the root of the tree. Performing - * the rotations in this fashion preserves the amortized balancing of - * the tree. - */ - void splay(T* node) - { - MOZ_ASSERT(node); - - while (node != root) { - T* parent = node->parent; - if (parent == root) { - // Zig rotation. - rotate(node); - MOZ_ASSERT(node == root); - return; - } - T* grandparent = parent->parent; - if ((parent->left == node) == (grandparent->left == parent)) { - // Zig-zig rotation. - rotate(parent); - rotate(node); - } else { - // Zig-zag rotation. - rotate(node); - rotate(node); - } - } + // Make the selected node the new root. + mRoot = swap; + mRoot->mParent = nullptr; + mRoot->mLeft = last->mLeft; + mRoot->mRight = last->mRight; + if (mRoot->mLeft) { + mRoot->mLeft->mParent = mRoot; } + if (mRoot->mRight) { + mRoot->mRight->mParent = mRoot; + } + + checkCoherency(mRoot, nullptr); + return last; + } - void rotate(T* node) - { - // Rearrange nodes so that node becomes the parent of its current - // parent, while preserving the sortedness of the tree. - T* parent = node->parent; - if (parent->left == node) { - // x y - // y c ==> a x - // a b b c - parent->left = node->right; - if (node->right) - node->right->parent = parent; - node->right = parent; + T* removeMin() + { + MOZ_ASSERT(mRoot, "No min to remove!"); + + T* min = mRoot; + while (min->mLeft) { + min = min->mLeft; + } + return remove(*min); + } + +private: + /** + * Returns the node in this comparing equal to |aValue|, or a node just + * greater or just less than |aValue| if there is no such node. + */ + T* lookup(const T& aValue) + { + MOZ_ASSERT(!empty()); + + T* node = mRoot; + T* parent; + do { + parent = node; + int c = Comparator::compare(aValue, *node); + if (c == 0) { + return node; + } else if (c < 0) { + node = node->mLeft; } else { - MOZ_ASSERT(parent->right == node); - // x y - // a y ==> x c - // b c a b - parent->right = node->left; - if (node->left) - node->left->parent = parent; - node->left = parent; + node = node->mRight; } - node->parent = parent->parent; - parent->parent = node; - if (T* grandparent = node->parent) { - if (grandparent->left == parent) - grandparent->left = node; - else - grandparent->right = node; + } while (node); + return parent; + } + + /** + * Rotate the tree until |node| is at the root of the tree. Performing + * the rotations in this fashion preserves the amortized balancing of + * the tree. + */ + void splay(T* aNode) + { + MOZ_ASSERT(aNode); + + while (aNode != mRoot) { + T* parent = aNode->mParent; + if (parent == mRoot) { + // Zig rotation. + rotate(aNode); + MOZ_ASSERT(aNode == mRoot); + return; + } + T* grandparent = parent->mParent; + if ((parent->mLeft == aNode) == (grandparent->mLeft == parent)) { + // Zig-zig rotation. + rotate(parent); + rotate(aNode); } else { - root = node; + // Zig-zag rotation. + rotate(aNode); + rotate(aNode); } } - - T* checkCoherency(T* node, T* minimum) - { -#ifdef DEBUG - MOZ_ASSERT_IF(root, !root->parent); - if (!node) { - MOZ_ASSERT(!root); - return nullptr; + } + + void rotate(T* aNode) + { + // Rearrange nodes so that aNode becomes the parent of its current + // parent, while preserving the sortedness of the tree. + T* parent = aNode->mParent; + if (parent->mLeft == aNode) { + // x y + // y c ==> a x + // a b b c + parent->mLeft = aNode->mRight; + if (aNode->mRight) { + aNode->mRight->mParent = parent; } - MOZ_ASSERT_IF(!node->parent, node == root); - MOZ_ASSERT_IF(minimum, Comparator::compare(*minimum, *node) < 0); - if (node->left) { - MOZ_ASSERT(node->left->parent == node); - T* leftMaximum = checkCoherency(node->left, minimum); - MOZ_ASSERT(Comparator::compare(*leftMaximum, *node) < 0); + aNode->mRight = parent; + } else { + MOZ_ASSERT(parent->mRight == aNode); + // x y + // a y ==> x c + // b c a b + parent->mRight = aNode->mLeft; + if (aNode->mLeft) { + aNode->mLeft->mParent = parent; } - if (node->right) { - MOZ_ASSERT(node->right->parent == node); - return checkCoherency(node->right, node); + aNode->mLeft = parent; + } + aNode->mParent = parent->mParent; + parent->mParent = aNode; + if (T* grandparent = aNode->mParent) { + if (grandparent->mLeft == parent) { + grandparent->mLeft = aNode; + } else { + grandparent->mRight = aNode; } - return node; -#else + } else { + mRoot = aNode; + } + } + + T* checkCoherency(T* aNode, T* aMinimum) + { +#ifdef DEBUG + MOZ_ASSERT_IF(mRoot, !mRoot->mParent); + if (!aNode) { + MOZ_ASSERT(!mRoot); return nullptr; -#endif } + MOZ_ASSERT_IF(!aNode->mParent, aNode == mRoot); + MOZ_ASSERT_IF(aMinimum, Comparator::compare(*aMinimum, *aNode) < 0); + if (aNode->mLeft) { + MOZ_ASSERT(aNode->mLeft->mParent == aNode); + T* leftMaximum = checkCoherency(aNode->mLeft, aMinimum); + MOZ_ASSERT(Comparator::compare(*leftMaximum, *aNode) < 0); + } + if (aNode->mRight) { + MOZ_ASSERT(aNode->mRight->mParent == aNode); + return checkCoherency(aNode->mRight, aNode); + } + return aNode; +#else + return nullptr; +#endif + } - SplayTree(const SplayTree&) MOZ_DELETE; - void operator=(const SplayTree&) MOZ_DELETE; + SplayTree(const SplayTree&) MOZ_DELETE; + void operator=(const SplayTree&) MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TaggedAnonymousMemory.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TaggedAnonymousMemory.h new file mode 100644 index 0000000000..d26b06dfb4 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TaggedAnonymousMemory.h @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Some Linux kernels -- specifically, newer versions of Android and +// some B2G devices -- have a feature for assigning names to ranges of +// anonymous memory (i.e., memory that doesn't have a "name" in the +// form of an underlying mapped file). These names are reported in +// /proc//smaps alongside system-level memory usage information +// such as Proportional Set Size (memory usage adjusted for sharing +// between processes), which allows reporting this information at a +// finer granularity than would otherwise be possible (e.g., +// separating malloc() heap from JS heap). +// +// Existing memory can be tagged with MozTagAnonymousMemory(); it will +// tag the range of complete pages containing the given interval, so +// the results may be inexact if the range isn't page-aligned. +// MozTaggedAnonymousMmap() can be used like mmap() with an extra +// parameter, and will tag the returned memory if the mapping was +// successful (and if it was in fact anonymous). +// +// NOTE: The pointer given as the "tag" argument MUST remain valid as +// long as the mapping exists. The referenced string is read when +// /proc//smaps or /proc//maps is read, not when the tag is +// established, so freeing it or changing its contents will have +// unexpected results. Using a static string is probably best. +// +// Also note that this header can be used by both C and C++ code. + +#ifndef mozilla_TaggedAnonymousMemory_h +#define mozilla_TaggedAnonymousMemory_h + +#ifndef XP_WIN + +#include +#include + +#include "mozilla/Types.h" + +#ifdef ANDROID + +#ifdef __cplusplus +extern "C" { +#endif + +MFBT_API void +MozTagAnonymousMemory(const void* aPtr, size_t aLength, const char* aTag); + +MFBT_API void* +MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt, int aFlags, + int aFd, off_t aOffset, const char* aTag); + +MFBT_API int +MozTaggedMemoryIsSupported(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#else // ANDROID + +static inline void +MozTagAnonymousMemory(const void* aPtr, size_t aLength, const char* aTag) +{ +} + +static inline void* +MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt, int aFlags, + int aFd, off_t aOffset, const char* aTag) +{ + return mmap(aAddr, aLength, aProt, aFlags, aFd, aOffset); +} + +static inline int +MozTaggedMemoryIsSupported(void) +{ + return 0; +} + +#endif // ANDROID + +#endif // !XP_WIN + +#endif // mozilla_TaggedAnonymousMemory_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TemplateLib.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TemplateLib.h index 50275fdadb..ea12c18b2b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TemplateLib.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TemplateLib.h @@ -28,19 +28,19 @@ namespace tl { template struct Min { - static const size_t value = I < J ? I : J; + static const size_t value = I < J ? I : J; }; template struct Max { - static const size_t value = I > J ? I : J; + static const size_t value = I > J ? I : J; }; /** Compute floor(log2(i)). */ template struct FloorLog2 { - static const size_t value = 1 + FloorLog2::value; + static const size_t value = 1 + FloorLog2::value; }; template<> struct FloorLog2<0> { /* Error */ }; template<> struct FloorLog2<1> { static const size_t value = 0; }; @@ -49,26 +49,26 @@ template<> struct FloorLog2<1> { static const size_t value = 0; }; template struct CeilingLog2 { - static const size_t value = FloorLog2<2 * I - 1>::value; + static const size_t value = FloorLog2<2 * I - 1>::value; }; /** Round up to the nearest power of 2. */ template struct RoundUpPow2 { - static const size_t value = size_t(1) << CeilingLog2::value; + static const size_t value = size_t(1) << CeilingLog2::value; }; template<> struct RoundUpPow2<0> { - static const size_t value = 1; + static const size_t value = 1; }; /** Compute the number of bits in the given unsigned type. */ template struct BitSize { - static const size_t value = sizeof(T) * CHAR_BIT; + static const size_t value = sizeof(T) * CHAR_BIT; }; /** @@ -78,17 +78,18 @@ struct BitSize template struct NBitMask { - // Assert the precondition. On success this evaluates to 0. Otherwise it - // triggers divide-by-zero at compile time: a guaranteed compile error in - // C++11, and usually one in C++98. Add this value to |value| to assure - // its computation. - static const size_t checkPrecondition = 0 / size_t(N < BitSize::value); - static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; + // Assert the precondition. On success this evaluates to 0. Otherwise it + // triggers divide-by-zero at compile time: a guaranteed compile error in + // C++11, and usually one in C++98. Add this value to |value| to assure + // its computation. + static const size_t checkPrecondition = + 0 / size_t(N < BitSize::value); + static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; }; template<> struct NBitMask::value> { - static const size_t value = size_t(-1); + static const size_t value = size_t(-1); }; /** @@ -98,8 +99,8 @@ struct NBitMask::value> template struct MulOverflowMask { - static const size_t value = - ~NBitMask::value - CeilingLog2::value>::value; + static const size_t value = + ~NBitMask::value - CeilingLog2::value>::value; }; template<> struct MulOverflowMask<0> { /* Error */ }; template<> struct MulOverflowMask<1> { static const size_t value = 0; }; diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ThreadLocal.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ThreadLocal.h index 6df109821f..28015de22e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ThreadLocal.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ThreadLocal.h @@ -54,7 +54,10 @@ typedef sig_atomic_t sig_safe_t; * * API usage: * - * // Create a TLS item + * // Create a TLS item. + * // + * // Note that init() should be invoked exactly once, before any usage of set() + * // or get(). * mozilla::ThreadLocal tlsKey; * if (!tlsKey.init()) { * // deal with the error @@ -70,30 +73,29 @@ template class ThreadLocal { #if defined(XP_WIN) - typedef unsigned long key_t; + typedef unsigned long key_t; #else - typedef pthread_key_t key_t; + typedef pthread_key_t key_t; #endif - union Helper { - void* ptr; - T value; - }; + union Helper + { + void* mPtr; + T mValue; + }; - public: - MOZ_WARN_UNUSED_RESULT inline bool init(); +public: + MOZ_WARN_UNUSED_RESULT inline bool init(); - inline T get() const; + inline T get() const; - inline void set(const T value); + inline void set(const T aValue); - bool initialized() const { - return inited; - } + bool initialized() const { return mInited; } - private: - key_t key; - bool inited; +private: + key_t mKey; + bool mInited; }; template @@ -105,12 +107,12 @@ ThreadLocal::init() "a pointer"); MOZ_ASSERT(!initialized()); #ifdef XP_WIN - key = TlsAlloc(); - inited = key != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES + mKey = TlsAlloc(); + mInited = mKey != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES #else - inited = !pthread_key_create(&key, nullptr); + mInited = !pthread_key_create(&mKey, nullptr); #endif - return inited; + return mInited; } template @@ -120,28 +122,28 @@ ThreadLocal::get() const MOZ_ASSERT(initialized()); Helper h; #ifdef XP_WIN - h.ptr = TlsGetValue(key); + h.mPtr = TlsGetValue(mKey); #else - h.ptr = pthread_getspecific(key); + h.mPtr = pthread_getspecific(mKey); #endif - return h.value; + return h.mValue; } template inline void -ThreadLocal::set(const T value) +ThreadLocal::set(const T aValue) { MOZ_ASSERT(initialized()); Helper h; - h.value = value; - bool succeeded; + h.mValue = aValue; #ifdef XP_WIN - succeeded = TlsSetValue(key, h.ptr); + bool succeeded = TlsSetValue(mKey, h.mPtr); #else - succeeded = !pthread_setspecific(key, h.ptr); + bool succeeded = !pthread_setspecific(mKey, h.mPtr); #endif - if (!succeeded) + if (!succeeded) { MOZ_CRASH(); + } } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ToString.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ToString.h new file mode 100644 index 0000000000..f11cad5cb6 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/ToString.h @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Utilities for converting an object to a string representation. */ + +#ifndef mozilla_ToString_h +#define mozilla_ToString_h + +#include +#include + +namespace mozilla { + +/** + * A convenience function for converting an object to a string representation. + * Supports any object which can be streamed to an std::ostream. + */ +template +std::string +ToString(const T& aValue) +{ + std::ostringstream stream; + stream << aValue; + return stream.str(); +} + +} // namespace mozilla + +#endif /* mozilla_ToString_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TypeTraits.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TypeTraits.h index 1ccd0c85d1..515c68d94e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TypeTraits.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TypeTraits.h @@ -9,6 +9,8 @@ #ifndef mozilla_TypeTraits_h #define mozilla_TypeTraits_h +#include "mozilla/Types.h" + /* * These traits are approximate copies of the traits and semantics from C++11's * header. Don't add traits not in that header! When all @@ -32,9 +34,9 @@ template struct RemoveCV; template struct IntegralConstant { - static const T value = Value; - typedef T ValueType; - typedef IntegralConstant Type; + static const T value = Value; + typedef T ValueType; + typedef IntegralConstant Type; }; /** Convenient aliases. */ @@ -47,6 +49,27 @@ typedef IntegralConstant FalseType; namespace detail { +template +struct IsVoidHelper : FalseType {}; + +template<> +struct IsVoidHelper : TrueType {}; + +} // namespace detail + +/** + * IsVoid determines whether a type is void. + * + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true; + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true. + */ +template +struct IsVoid : detail::IsVoidHelper::Type> {}; + +namespace detail { + template struct IsIntegralHelper : FalseType {}; @@ -114,6 +137,31 @@ struct IsFloatingPoint : detail::IsFloatingPointHelper::Type> {}; +namespace detail { + +template +struct IsArrayHelper : FalseType {}; + +template +struct IsArrayHelper : TrueType {}; + +template +struct IsArrayHelper : TrueType {}; + +} // namespace detail + +/** + * IsArray determines whether a type is an array type, of known or unknown + * length. + * + * mozilla::IsArray::value is false; + * mozilla::IsArray::value is true; + * mozilla::IsArray::value is true. + */ +template +struct IsArray : detail::IsArrayHelper::Type> +{}; + /** * IsPointer determines whether a type is a pointer type (but not a pointer-to- * member type). @@ -130,6 +178,40 @@ struct IsPointer : FalseType {}; template struct IsPointer : TrueType {}; +/** + * IsLvalueReference determines whether a type is an lvalue reference. + * + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is true; + * mozilla::IsLvalueReference::value is false. + */ +template +struct IsLvalueReference : FalseType {}; + +template +struct IsLvalueReference : TrueType {}; + +/** + * IsRvalueReference determines whether a type is an rvalue reference. + * + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is true. + */ +template +struct IsRvalueReference : FalseType {}; + +template +struct IsRvalueReference : TrueType {}; + namespace detail { // __is_enum is a supported extension across all of our supported compilers. @@ -152,8 +234,55 @@ struct IsEnum : detail::IsEnumHelper::Type> {}; +namespace detail { + +// __is_class is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx +template +struct IsClassHelper + : IntegralConstant +{}; + +} // namespace detail + +/** + * IsClass determines whether a type is a class type (but not a union). + * + * struct S {}; + * union U {}; + * mozilla::IsClass::value is false; + * mozilla::IsClass::value is true; + * mozilla::IsClass::value is false; + */ +template +struct IsClass + : detail::IsClassHelper::Type> +{}; + /* 20.9.4.2 Composite type traits [meta.unary.comp] */ +/** + * IsReference determines whether a type is an lvalue or rvalue reference. + * + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true. + */ +template +struct IsReference + : IntegralConstant::value || IsRvalueReference::value> +{}; + /** * IsArithmetic determines whether a type is arithmetic. A type is arithmetic * iff it is an integral type or a floating point type. @@ -228,26 +357,90 @@ template struct IsPod : TrueType {}; namespace detail { -template::value> -struct IsSignedHelper; - +// __is_empty is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx template -struct IsSignedHelper : TrueType {}; +struct IsEmptyHelper + : IntegralConstant::value && __is_empty(T)> +{}; +} // namespace detail + +/** + * IsEmpty determines whether a type is a class (but not a union) that is empty. + * + * A class is empty iff it and all its base classes have no non-static data + * members (except bit-fields of length 0) and no virtual member functions, and + * no base class is empty or a virtual base class. + * + * Intuitively, empty classes don't have any data that has to be stored in + * instances of those classes. (The size of the class must still be non-zero, + * because distinct array elements of any type must have different addresses. + * However, if the Empty Base Optimization is implemented by the compiler [most + * compilers implement it, and in certain cases C++11 requires it], the size of + * a class inheriting from an empty |Base| class need not be inflated by + * |sizeof(Base)|.) And intuitively, non-empty classes have data members and/or + * vtable pointers that must be stored in each instance for proper behavior. + * + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * union U1 { int x; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct E1 {}; + * struct E2 { int : 0 }; + * struct E3 : E1 {}; + * struct E4 : E2 {}; + * static_assert(mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value, + * "all empty"); + * union U2 { E1 e1; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct NE1 { int x; }; + * struct NE2 : virtual E1 {}; + * struct NE3 : E2 { virtual ~NE3() {} }; + * struct NE4 { virtual void f() {} }; + * static_assert(!mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value, + * "all empty"); + */ template -struct IsSignedHelper - : IntegralConstant::value && T(-1) < T(1)> +struct IsEmpty : detail::IsEmptyHelper::Type> {}; + +namespace detail { + +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> +struct IsSignedHelper; + +// Floating point is signed. +template +struct IsSignedHelper : TrueType {}; + +// Integral is conditionally signed. +template +struct IsSignedHelper + : IntegralConstant +{}; + +// Non-floating point, non-integral is not signed. +template +struct IsSignedHelper : FalseType {}; + } // namespace detail /** * IsSigned determines whether a type is a signed arithmetic type. |char| is * considered a signed type if it has the same representation as |signed char|. * - * Don't use this if the type might be user-defined! You might or might not get - * a compile error, depending. - * * mozilla::IsSigned::value is true; * mozilla::IsSigned::value is false; * mozilla::IsSigned::value is false; @@ -258,28 +451,32 @@ struct IsSigned : detail::IsSignedHelper {}; namespace detail { -template::value> +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> struct IsUnsignedHelper; -template -struct IsUnsignedHelper : FalseType {}; +// Floating point is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; -template -struct IsUnsignedHelper +// Integral is conditionally unsigned. +template +struct IsUnsignedHelper : IntegralConstant::value && - (IsSame::Type, bool>::value || - T(1) < T(-1))> + (IsSame::value || bool(NoCV(1) < NoCV(-1)))> {}; +// Non-floating point, non-integral is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; + } // namespace detail /** * IsUnsigned determines whether a type is an unsigned arithmetic type. * - * Don't use this if the type might be user-defined! You might or might not get - * a compile error, depending. - * * mozilla::IsUnsigned::value is false; * mozilla::IsUnsigned::value is true; * mozilla::IsUnsigned::value is true; @@ -310,6 +507,13 @@ struct IsSame : TrueType {}; namespace detail { +#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) + +template +struct BaseOfTester : IntegralConstant {}; + +#else + // The trickery used to implement IsBaseOf here makes it possible to use it for // the cases of private and multiple inheritance. This code was inspired by the // sample code here: @@ -318,35 +522,35 @@ namespace detail { template struct BaseOfHelper { - public: - operator Base*() const; - operator Derived*(); +public: + operator Base*() const; + operator Derived*(); }; template struct BaseOfTester { - private: - template - static char test(Derived*, T); - static int test(Base*, int); - - public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); }; template struct BaseOfTester { - private: - template - static char test(Derived*, T); - static int test(Base*, int); - - public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); }; template @@ -358,6 +562,8 @@ struct BaseOfTester : TrueType {}; template struct BaseOfTester : TrueType {}; +#endif + } /* namespace detail */ /* @@ -382,18 +588,18 @@ namespace detail { template struct ConvertibleTester { - private: - static From create(); +private: + static From create(); - template - static char test(To to); + template + static char test(To to); - template - static int test(...); + template + static int test(...); - public: - static const bool value = - sizeof(test(create())) == sizeof(char); +public: + static const bool value = + sizeof(test(create())) == sizeof(char); }; } // namespace detail @@ -424,16 +630,6 @@ struct IsConvertible : IntegralConstant::value> {}; -/** - * Is IsLvalueReference is true if its template param is T& and is false if - * its type is T or T&&. - */ -template -struct IsLvalueReference : FalseType {}; - -template -struct IsLvalueReference : TrueType {}; - /* 20.9.7 Transformations between types [meta.trans] */ /* 20.9.7.1 Const-volatile modifications [meta.trans.cv] */ @@ -449,13 +645,13 @@ struct IsLvalueReference : TrueType {}; template struct RemoveConst { - typedef T Type; + typedef T Type; }; template struct RemoveConst { - typedef T Type; + typedef T Type; }; /** @@ -469,13 +665,13 @@ struct RemoveConst template struct RemoveVolatile { - typedef T Type; + typedef T Type; }; template struct RemoveVolatile { - typedef T Type; + typedef T Type; }; /** @@ -489,7 +685,7 @@ struct RemoveVolatile template struct RemoveCV { - typedef typename RemoveConst::Type>::Type Type; + typedef typename RemoveConst::Type>::Type Type; }; /* 20.9.7.2 Reference modifications [meta.trans.ref] */ @@ -505,29 +701,69 @@ struct RemoveCV template struct RemoveReference { - typedef T Type; + typedef T Type; }; template struct RemoveReference { - typedef T Type; + typedef T Type; }; template struct RemoveReference { - typedef T Type; + typedef T Type; }; +template +struct Conditional; + +namespace detail { + +enum Voidness { TIsVoid, TIsNotVoid }; + +template::value ? TIsVoid : TIsNotVoid> +struct AddLvalueReferenceHelper; + +template +struct AddLvalueReferenceHelper +{ + typedef void Type; +}; + +template +struct AddLvalueReferenceHelper +{ + typedef T& Type; +}; + +} // namespace detail + +/** + * AddLvalueReference adds an lvalue & reference to T if one isn't already + * present. (Note: adding an lvalue reference to an rvalue && reference in + * essence replaces the && with a &&, per C+11 reference collapsing rules. For + * example, int&& would become int&.) + * + * The final computed type will only *not* be an lvalue reference if T is void. + * + * mozilla::AddLvalueReference::Type is int&; + * mozilla::AddLvalueRference::Type is volatile int&; + * mozilla::AddLvalueReference::Type is void*&; + * mozilla::AddLvalueReference::Type is void; + * mozilla::AddLvalueReference::Type is struct S&. + */ +template +struct AddLvalueReference + : detail::AddLvalueReferenceHelper +{}; + /* 20.9.7.3 Sign modifications [meta.trans.sign] */ template struct EnableIf; -template -struct Conditional; - namespace detail { template @@ -568,7 +804,7 @@ struct MakeSigned; template struct MakeSigned { - typedef T Type; + typedef T Type; }; template @@ -603,7 +839,8 @@ struct MakeSigned */ template struct MakeSigned - : EnableIf::value && !IsSame::Type>::value, + : EnableIf::value && + !IsSame::Type>::value, typename detail::MakeSigned >::Type {}; @@ -636,7 +873,7 @@ struct MakeUnsigned; template struct MakeUnsigned { - typedef T Type; + typedef T Type; }; template @@ -671,13 +908,41 @@ struct MakeUnsigned */ template struct MakeUnsigned - : EnableIf::value && !IsSame::Type>::value, + : EnableIf::value && + !IsSame::Type>::value, typename detail::MakeUnsigned >::Type {}; /* 20.9.7.4 Array modifications [meta.trans.arr] */ +/** + * RemoveExtent produces either the type of the elements of the array T, or T + * itself. + * + * mozilla::RemoveExtent::Type is int; + * mozilla::RemoveExtent::Type is const int; + * mozilla::RemoveExtent::Type is volatile int; + * mozilla::RemoveExtent::Type is long[17]. + */ +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + /* 20.9.7.5 Pointer modifications [meta.trans.ptr] */ /* 20.9.7.6 Other transformations [meta.trans.other] */ @@ -707,7 +972,7 @@ struct EnableIf template struct EnableIf { - typedef T Type; + typedef T Type; }; /** @@ -719,13 +984,13 @@ struct EnableIf template struct Conditional { - typedef A Type; + typedef A Type; }; template struct Conditional { - typedef B Type; + typedef B Type; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TypedEnum.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TypedEnum.h index e55365abb8..d84cd90257 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TypedEnum.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TypedEnum.h @@ -9,39 +9,11 @@ #ifndef mozilla_TypedEnum_h #define mozilla_TypedEnum_h -#include "mozilla/Attributes.h" +#include "mozilla/TypedEnumInternal.h" +#include "mozilla/MacroArgs.h" #if defined(__cplusplus) -#if defined(__clang__) - /* - * Per Clang documentation, "Note that marketing version numbers should not - * be used to check for language features, as different vendors use different - * numbering schemes. Instead, use the feature checking macros." - */ -# ifndef __has_extension -# define __has_extension __has_feature /* compatibility, for older versions of clang */ -# endif -# if __has_extension(cxx_strong_enums) -# define MOZ_HAVE_CXX11_ENUM_TYPE -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -#elif defined(__GNUC__) -# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L -# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3) -# define MOZ_HAVE_CXX11_ENUM_TYPE -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -# endif -#elif defined(_MSC_VER) -# if _MSC_VER >= 1400 -# define MOZ_HAVE_CXX11_ENUM_TYPE -# endif -# if _MSC_VER >= 1700 -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -#endif - /** * MOZ_ENUM_TYPE specifies the underlying numeric type for an enum. It's * specified by placing MOZ_ENUM_TYPE(type) immediately after the enum name in @@ -97,13 +69,12 @@ * in namespace scope to handle bits that can only be implemented with * namespace-scoped code. For example: * - * class FooBar { - * + * class FooBar + * { * MOZ_BEGIN_NESTED_ENUM_CLASS(Enum, int32_t) * A, * B = 6 * MOZ_END_NESTED_ENUM_CLASS(Enum) - * * }; * * MOZ_FINISH_NESTED_ENUM_CLASS(FooBar::Enum) @@ -131,6 +102,10 @@ * these are already integer types so there is nothing more to do. */ # define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name + /* + * See the comment below about MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) Name #else /** * We need Name to both name a type, and scope the provided enumerator @@ -172,24 +147,28 @@ # define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER1(Name) \ class Name \ { \ - public: \ - enum Enum \ - { + public: \ + enum Enum \ + { /* Two-argument form. */ # define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER2(Name, type) \ class Name \ { \ - public: \ - enum Enum MOZ_ENUM_TYPE(type) \ - { + public: \ + enum Enum MOZ_ENUM_TYPE(type) \ + { # define MOZ_END_NESTED_ENUM_CLASS(Name) \ - }; \ - Name() {} \ - Name(Enum aEnum) : mEnum(aEnum) {} \ - explicit Name(int num) : mEnum((Enum)num) {} \ - operator Enum() const { return mEnum; } \ - private: \ - Enum mEnum; \ + }; \ + Name() {} \ + MOZ_CONSTEXPR Name(Enum aEnum) : mEnum(aEnum) {} \ + template \ + explicit MOZ_CONSTEXPR Name(Other num) : mEnum((Enum)num) {} \ + MOZ_CONSTEXPR operator Enum() const { return mEnum; } \ + explicit MOZ_CONSTEXPR Name(const mozilla::CastableTypedEnumResult& aOther) \ + : mEnum(aOther.get()) \ + {} \ + private: \ + Enum mEnum; \ }; # define MOZ_FINISH_NESTED_ENUM_CLASS(Name) \ inline int operator+(const int&, const Name::Enum&) MOZ_DELETE; \ @@ -225,7 +204,6 @@ inline bool operator&&(const Name::Enum&, const bool&) MOZ_DELETE; \ inline bool operator||(const bool&, const Name::Enum&) MOZ_DELETE; \ inline bool operator||(const Name::Enum&, const bool&) MOZ_DELETE; \ - inline int operator~(const Name::Enum&) MOZ_DELETE; \ inline int operator&(const int&, const Name::Enum&) MOZ_DELETE; \ inline int operator&(const Name::Enum&, const int&) MOZ_DELETE; \ inline int operator|(const int&, const Name::Enum&) MOZ_DELETE; \ @@ -253,35 +231,45 @@ * In the present case, the integer type is the Enum nested type. */ # define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name::Enum + /* + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is a variant of MOZ_ENUM_CLASS_ENUM_TYPE + * to be used when the enum class at hand depends on template parameters. + * + * Indeed, if T depends on template parameters, in order to name a nested type + * in T, C++ does not allow to just write "T::NestedType". Instead, we have + * to write "typename T::NestedType". The role of this macro is to add + * this "typename" keywords where needed. + * + * Example: + * + * template + * struct S {}; + * + * MOZ_BEGIN_ENUM_CLASS(E) + * Foo, + * Bar + * MOZ_END_ENUM_CLASS(E) + * + * S s; + * + * In this example, the second template parameter to S is meant to be of type + * T, but on non-C++11 compilers, type T is a class type, not an integer + * type, so it is not accepted as the type of a constant template parameter. + * One would then want to use MOZ_ENUM_CLASS_ENUM_TYPE(T), but that doesn't + * work either as T depends on template parameters (more specifically here, T + * _is_ a template parameter) so as MOZ_ENUM_CLASS_ENUM_TYPE(T) expands to + * T::Enum, we are missing the required "typename" keyword. So here, + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is needed. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) typename Name::Enum #endif - /* - * Count the number of arguments passed to MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS, - * very carefully tiptoeing around an MSVC bug where it improperly expands - * __VA_ARGS__ as a single token in argument lists. See these URLs for - * details: - * - * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement - * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 - */ -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL2(_1, _2, count, ...) \ - count -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL(args) \ - MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL2 args -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS(...) \ - MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL((__VA_ARGS__, 2, 1, 0)) - /* Pick the right helper macro to invoke. */ -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER2(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER##count -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER1(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER2(count) -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER1(count) - /* The actual macro. */ -# define MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(x, y) x y +# define MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(a, b) a b # define MOZ_BEGIN_NESTED_ENUM_CLASS(...) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER(MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS(__VA_ARGS__)), \ - (__VA_ARGS__)) + MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER, \ + __VA_ARGS__), \ + (__VA_ARGS__)) # define MOZ_BEGIN_ENUM_CLASS(...) MOZ_BEGIN_NESTED_ENUM_CLASS(__VA_ARGS__) # define MOZ_END_ENUM_CLASS(Name) \ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TypedEnumBits.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TypedEnumBits.h new file mode 100644 index 0000000000..1f439f1239 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TypedEnumBits.h @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS allows using a typed enum as bit flags. + */ + +#ifndef mozilla_TypedEnumBits_h +#define mozilla_TypedEnumBits_h + +#include "mozilla/IntegerTypeTraits.h" +#include "mozilla/TypedEnumInternal.h" + +namespace mozilla { + +#define MOZ_CASTABLETYPEDENUMRESULT_BINOP(Op, OtherType, ReturnType) \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const OtherType& aE, const CastableTypedEnumResult& aR) \ +{ \ + return ReturnType(aE Op OtherType(aR)); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR, const OtherType& aE) \ +{ \ + return ReturnType(OtherType(aR) Op aE); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR1, \ + const CastableTypedEnumResult& aR2) \ +{ \ + return ReturnType(OtherType(aR1) Op OtherType(aR2)); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_BINOP(|, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(&, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(^, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(==, E, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(!=, E, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(||, bool, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(&&, bool, bool) + +template +MOZ_CONSTEXPR CastableTypedEnumResult +operator ~(const CastableTypedEnumResult& aR) +{ + return CastableTypedEnumResult(~(E(aR))); +} + +#define MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(Op) \ +template \ +E& \ +operator Op(E& aR1, \ + const CastableTypedEnumResult& aR2) \ +{ \ + return aR1 Op E(aR2); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(&=) +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(|=) +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(^=) + +#undef MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP + +#undef MOZ_CASTABLETYPEDENUMRESULT_BINOP + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS + +#define MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(Op, ReturnType) \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(typename E::Enum aE, const CastableTypedEnumResult& aR) \ +{ \ + return ReturnType(aE Op E(aR)); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR, typename E::Enum aE) \ +{ \ + return ReturnType(E(aR) Op aE); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(|, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(&, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(^, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(==, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(!=, bool) + +#undef MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11 + +#endif // not MOZ_HAVE_CXX11_STRONG_ENUMS + +namespace detail { +template +struct UnsignedIntegerTypeForEnum + : UnsignedStdintTypeForSize +{}; +} + +} // namespace mozilla + +#define MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, Op) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name a, Name b) \ + { \ + typedef mozilla::CastableTypedEnumResult Result; \ + typedef mozilla::detail::UnsignedIntegerTypeForEnum::Type U; \ + return Result(Name(U(a) Op U(b))); \ + } \ + \ + inline Name& \ + operator Op##=(Name& a, Name b) \ + { \ + return a = a Op b; \ + } + +#define MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, |) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, &) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, ^) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator~(Name a) \ + { \ + typedef mozilla::CastableTypedEnumResult Result; \ + typedef mozilla::detail::UnsignedIntegerTypeForEnum::Type U; \ + return Result(Name(~(U(a)))); \ + } + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS +# define MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, Op) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name a, Name::Enum b) \ + { \ + return a Op Name(b); \ + } \ + \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name::Enum a, Name b) \ + { \ + return Name(a) Op b; \ + } \ + \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name::Enum a, Name::Enum b) \ + { \ + return Name(a) Op Name(b); \ + } \ + \ + inline Name& \ + operator Op##=(Name& a, Name::Enum b) \ + { \ + return a = a Op Name(b); \ + } + +# define MOZ_MAKE_ENUM_CLASS_OPS_EXTRA_NON_CXX11(Name) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, |) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, &) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, ^) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator~(Name::Enum a) \ + { \ + return ~(Name(a)); \ + } +#endif + +/** + * MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS generates standard bitwise operators + * for the given enum type. Use this to enable using an enum type as bit-field. + */ +#ifdef MOZ_HAVE_CXX11_STRONG_ENUMS +# define MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) +#else +# define MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_EXTRA_NON_CXX11(Name) +#endif + +#endif // mozilla_TypedEnumBits_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TypedEnumInternal.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TypedEnumInternal.h new file mode 100644 index 0000000000..8c88cb589b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/TypedEnumInternal.h @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Internal stuff needed by TypedEnum.h and TypedEnumBits.h. */ + +// NOTE: When we can assume C++11 enum class support and TypedEnum.h goes away, +// we should then consider folding TypedEnumInternal.h into TypedEnumBits.h. + +#ifndef mozilla_TypedEnumInternal_h +#define mozilla_TypedEnumInternal_h + +#include "mozilla/Attributes.h" + +#if defined(__cplusplus) + +#if defined(__clang__) + /* + * Per Clang documentation, "Note that marketing version numbers should not + * be used to check for language features, as different vendors use different + * numbering schemes. Instead, use the feature checking macros." + */ +# ifndef __has_extension +# define __has_extension __has_feature /* compatibility, for older versions of clang */ +# endif +# if __has_extension(cxx_strong_enums) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#elif defined(__GNUC__) +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +# endif +#elif defined(_MSC_VER) +# if _MSC_VER >= 1400 +# define MOZ_HAVE_CXX11_ENUM_TYPE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#endif + +namespace mozilla { + +/* + * The problem that CastableTypedEnumResult aims to solve is that + * typed enums are not convertible to bool, and there is no way to make them + * be, yet user code wants to be able to write + * + * if (myFlags & Flags::SOME_PARTICULAR_FLAG) (1) + * + * There are different approaches to solving this. Most of them require + * adapting user code. For example, we could implement operator! and have + * the user write + * + * if (!!(myFlags & Flags::SOME_PARTICULAR_FLAG)) (2) + * + * Or we could supply a IsNonZero() or Any() function returning whether + * an enum value is nonzero, and have the user write + * + * if (Any(Flags & Flags::SOME_PARTICULAR_FLAG)) (3) + * + * But instead, we choose to preserve the original user syntax (1) as it + * is inherently more readable, and to ease porting existing code to typed + * enums. We achieve this by having operator& and other binary bitwise + * operators have as return type a class, CastableTypedEnumResult, + * that wraps a typed enum but adds bool convertibility. + */ +template +class CastableTypedEnumResult +{ +private: + const E mValue; + +public: + explicit MOZ_CONSTEXPR CastableTypedEnumResult(E aValue) + : mValue(aValue) + {} + + MOZ_CONSTEXPR operator E() const { return mValue; } + + template + MOZ_EXPLICIT_CONVERSION MOZ_CONSTEXPR + operator DestinationType() const { return DestinationType(mValue); } + + MOZ_CONSTEXPR bool operator !() const { return !bool(mValue); } + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS + // This get() method is used to implement a constructor in the + // non-c++11 fallback path for MOZ_BEGIN_ENUM_CLASS, taking a + // CastableTypedEnumResult. If we try to implement it using the + // above conversion operator E(), then at least clang 3.3 + // (when forced to take the non-c++11 fallback path) compiles + // this constructor to an infinite recursion. So we introduce this + // get() method, that does exactly the same as the conversion operator, + // to work around this. + MOZ_CONSTEXPR E get() const { return mValue; } +#endif +}; + +} // namespace mozilla + +#endif // __cplusplus + +#endif // mozilla_TypedEnumInternal_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Types.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Types.h index 5340b2b600..e7e18abb27 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Types.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Types.h @@ -37,7 +37,7 @@ * These macros are designed for use by library interfaces -- not for normal * methods or data used cross-file. */ -#if defined(WIN32) || defined(XP_OS2) +#if defined(WIN32) # define MOZ_EXPORT __declspec(dllexport) #else /* Unix */ # ifdef HAVE_VISIBILITY_ATTRIBUTE @@ -63,16 +63,12 @@ # else # define MOZ_IMPORT_API __declspec(dllimport) # endif -#elif defined(XP_OS2) -# define MOZ_IMPORT_API __declspec(dllimport) #else # define MOZ_IMPORT_API MOZ_EXPORT #endif #if defined(_WIN32) && !defined(__MWERKS__) # define MOZ_IMPORT_DATA __declspec(dllimport) -#elif defined(XP_OS2) -# define MOZ_IMPORT_DATA __declspec(dllimport) #else # define MOZ_IMPORT_DATA MOZ_EXPORT #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/UniquePtr.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/UniquePtr.h new file mode 100644 index 0000000000..9c873db90c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/UniquePtr.h @@ -0,0 +1,674 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Smart pointer managing sole ownership of a resource. */ + +#ifndef mozilla_UniquePtr_h +#define mozilla_UniquePtr_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/Pair.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +template class DefaultDelete; +template> class UniquePtr; + +} // namespace mozilla + +namespace mozilla { + +/** + * UniquePtr is a smart pointer that wholly owns a resource. Ownership may be + * transferred out of a UniquePtr through explicit action, but otherwise the + * resource is destroyed when the UniquePtr is destroyed. + * + * UniquePtr is similar to C++98's std::auto_ptr, but it improves upon auto_ptr + * in one crucial way: it's impossible to copy a UniquePtr. Copying an auto_ptr + * obviously *can't* copy ownership of its singly-owned resource. So what + * happens if you try to copy one? Bizarrely, ownership is implicitly + * *transferred*, preserving single ownership but breaking code that assumes a + * copy of an object is identical to the original. (This is why auto_ptr is + * prohibited in STL containers.) + * + * UniquePtr solves this problem by being *movable* rather than copyable. + * Instead of passing a |UniquePtr u| directly to the constructor or assignment + * operator, you pass |Move(u)|. In doing so you indicate that you're *moving* + * ownership out of |u|, into the target of the construction/assignment. After + * the transfer completes, |u| contains |nullptr| and may be safely destroyed. + * This preserves single ownership but also allows UniquePtr to be moved by + * algorithms that have been made move-safe. (Note: if |u| is instead a + * temporary expression, don't use |Move()|: just pass the expression, because + * it's already move-ready. For more information see Move.h.) + * + * UniquePtr is also better than std::auto_ptr in that the deletion operation is + * customizable. An optional second template parameter specifies a class that + * (through its operator()(T*)) implements the desired deletion policy. If no + * policy is specified, mozilla::DefaultDelete is used -- which will either + * |delete| or |delete[]| the resource, depending whether the resource is an + * array. Custom deletion policies ideally should be empty classes (no member + * fields, no member fields in base classes, no virtual methods/inheritance), + * because then UniquePtr can be just as efficient as a raw pointer. + * + * Use of UniquePtr proceeds like so: + * + * UniquePtr g1; // initializes to nullptr + * g1.reset(new int); // switch resources using reset() + * g1 = nullptr; // clears g1, deletes the int + * + * UniquePtr g2(new int); // owns that int + * int* p = g2.release(); // g2 leaks its int -- still requires deletion + * delete p; // now freed + * + * struct S { int x; S(int x) : x(x) {} }; + * UniquePtr g3, g4(new S(5)); + * g3 = Move(g4); // g3 owns the S, g4 cleared + * S* p = g3.get(); // g3 still owns |p| + * assert(g3->x == 5); // operator-> works (if .get() != nullptr) + * assert((*g3).x == 5); // also operator* (again, if not cleared) + * Swap(g3, g4); // g4 now owns the S, g3 cleared + * g3.swap(g4); // g3 now owns the S, g4 cleared + * UniquePtr g5(Move(g3)); // g5 owns the S, g3 cleared + * g5.reset(); // deletes the S, g5 cleared + * + * struct FreePolicy { void operator()(void* p) { free(p); } }; + * UniquePtr g6(static_cast(malloc(sizeof(int)))); + * int* ptr = g6.get(); + * g6 = nullptr; // calls free(ptr) + * + * Now, carefully note a few things you *can't* do: + * + * UniquePtr b1; + * b1 = new int; // BAD: can only assign another UniquePtr + * int* ptr = b1; // BAD: no auto-conversion to pointer, use get() + * + * UniquePtr b2(b1); // BAD: can't copy a UniquePtr + * UniquePtr b3 = b1; // BAD: can't copy-assign a UniquePtr + * + * A few miscellaneous notes: + * + * UniquePtr, when not instantiated for an array type, can be move-constructed + * and move-assigned, not only from itself but from "derived" UniquePtr + * instantiations where U converts to T and E converts to D. If you want to use + * this, you're going to have to specify a deletion policy for both UniquePtr + * instantations, and T pretty much has to have a virtual destructor. In other + * words, this doesn't work: + * + * struct Base { virtual ~Base() {} }; + * struct Derived : Base {}; + * + * UniquePtr b1; + * // BAD: DefaultDelete and DefaultDelete don't interconvert + * UniquePtr d1(Move(b)); + * + * UniquePtr b2; + * UniquePtr> d2(Move(b2)); // okay + * + * UniquePtr is specialized for array types. Specializing with an array type + * creates a smart-pointer version of that array -- not a pointer to such an + * array. + * + * UniquePtr arr(new int[5]); + * arr[0] = 4; + * + * What else is different? Deletion of course uses |delete[]|. An operator[] + * is provided. Functionality that doesn't make sense for arrays is removed. + * The constructors and mutating methods only accept array pointers (not T*, U* + * that converts to T*, or UniquePtr or UniquePtr) or |nullptr|. + * + * It's perfectly okay to return a UniquePtr from a method to assure the related + * resource is properly deleted. You'll need to use |Move()| when returning a + * local UniquePtr. Otherwise you can return |nullptr|, or you can return + * |UniquePtr(ptr)|. + * + * UniquePtr will commonly be a member of a class, with lifetime equivalent to + * that of that class. If you want to expose the related resource, you could + * expose a raw pointer via |get()|, but ownership of a raw pointer is + * inherently unclear. So it's better to expose a |const UniquePtr&| instead. + * This prohibits mutation but still allows use of |get()| when needed (but + * operator-> is preferred). Of course, you can only use this smart pointer as + * long as the enclosing class instance remains live -- no different than if you + * exposed the |get()| raw pointer. + * + * To pass a UniquePtr-managed resource as a pointer, use a |const UniquePtr&| + * argument. To specify an inout parameter (where the method may or may not + * take ownership of the resource, or reset it), or to specify an out parameter + * (where simply returning a |UniquePtr| isn't possible), use a |UniquePtr&| + * argument. To unconditionally transfer ownership of a UniquePtr + * into a method, use a |UniquePtr| argument. To conditionally transfer + * ownership of a resource into a method, should the method want it, use a + * |UniquePtr&&| argument. + */ +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + Pointer& ptr() { return tuple.first(); } + const Pointer& ptr() const { return tuple.first(); } + + DeleterType& del() { return tuple.second(); } + const DeleterType& del() const { return tuple.second(); } + + public: + /** + * Construct a UniquePtr containing |nullptr|. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! Ideally + // you should make deletion use the same function every time, using a + // deleter policy: + // + // // BAD, won't compile with MSVC10, deleter doesn't need to be a + // // variable at all + // typedef void (&FreeSignature)(void*); + // UniquePtr ptr((int*) malloc(sizeof(int)), free); + // + // // GOOD, compiles with MSVC10, deletion behavior statically known and + // // optimizable + // struct DeleteByFreeing + // { + // void operator()(void* ptr) { free(ptr); } + // }; + // + // If deletion really, truly, must be a variable: you might be able to work + // around this with a deleter class that contains the function reference. + // But this workaround is untried and untested, because variable deletion + // behavior really isn't something you should use. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + template + UniquePtr(UniquePtr&& other, + typename EnableIf::Pointer, + Pointer>::value && + !IsArray::value && + (IsReference::value + ? IsSame::value + : IsConvertible::value), + int>::Type dummy = 0) + : tuple(other.release(), Forward(other.getDeleter())) + { + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + template + UniquePtr& operator=(UniquePtr&& other) + { + static_assert(IsConvertible::Pointer, Pointer>::value, + "incompatible UniquePtr pointees"); + static_assert(!IsArray::value, + "can't assign from UniquePtr holding an array"); + + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT n) { + MOZ_ASSERT(n == nullptr); + reset(nullptr); + return *this; + } + + T& operator*() const { return *get(); } + Pointer operator->() const { + MOZ_ASSERT(get(), "dereferencing a UniquePtr containing nullptr"); + return get(); + } + + Pointer get() const { return ptr(); } + + DeleterType& getDeleter() { return del(); } + const DeleterType& getDeleter() const { return del(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = ptr(); + ptr() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = ptr(); + ptr() = p; + if (old != nullptr) + getDeleter()(old); + } + + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +// In case you didn't read the comment by the main definition (you should!): the +// UniquePtr specialization exists to manage array pointers. It deletes +// such pointers using delete[], it will reject construction and modification +// attempts using U* or U[]. Otherwise it works like the normal UniquePtr. +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + public: + /** + * Construct a UniquePtr containing nullptr. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + private: + // delete[] knows how to handle *only* an array of a single class type. For + // delete[] to work correctly, it must know the size of each element, the + // fields and base classes of each element requiring destruction, and so on. + // So forbid all overloads which would end up invoking delete[] on a pointer + // of the wrong type. + template + UniquePtr(U&& u, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! See the + // comment by this constructor in the non-T[] specialization above. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + private: + // Forbidden for the same reasons as stated above. + template + UniquePtr(U&& u, V&& v, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT) { + reset(); + return *this; + } + + T& operator[](decltype(sizeof(int)) i) const { return get()[i]; } + Pointer get() const { return tuple.first(); } + + DeleterType& getDeleter() { return tuple.second(); } + const DeleterType& getDeleter() const { return tuple.second(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = tuple.first(); + tuple.first() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = tuple.first(); + tuple.first() = p; + if (old != nullptr) + tuple.second()(old); + } + + private: + // Kill off all remaining overloads that aren't true nullptr (the overload + // above should handle that) or emulated nullptr (which acts like int/long + // on gcc 4.4/4.5). + template + void reset(U, + typename EnableIf::value && + !IsSame::Type>::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +/** A default deletion policy using plain old operator delete. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + template + DefaultDelete(const DefaultDelete& other, + typename EnableIf::value, + int>::Type dummy = 0) + {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete ptr; + } +}; + +/** A default deletion policy using operator delete[]. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete[] ptr; + } + + private: + template + void operator()(U* ptr) const MOZ_DELETE; +}; + +template +void +Swap(UniquePtr& x, UniquePtr& y) +{ + x.swap(y); +} + +template +bool +operator==(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() == y.get(); +} + +template +bool +operator!=(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() != y.get(); +} + +template +bool +operator==(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator==(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator!=(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +template +bool +operator!=(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +// No operator<, operator>, operator<=, operator>= for now because simplicity. + +namespace detail { + +template +struct UniqueSelector +{ + typedef UniquePtr SingleObject; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr UnknownBound; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr KnownBound; +}; + +} // namespace detail + +// We don't have variadic template support everywhere, so just hard-code arities +// 0-4 for now. If you need more arguments, feel free to add the extra +// overloads. +// +// Beware! Due to lack of true nullptr support in gcc 4.4 and 4.5, passing +// literal nullptr to MakeUnique will not work on some platforms. See Move.h +// for more details. + +template +typename detail::UniqueSelector::SingleObject +MakeUnique() +{ + return UniquePtr(new T()); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1) +{ + return UniquePtr(new T(Forward(a1))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2) +{ + return UniquePtr(new T(Forward(a1), Forward(a2))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4), Forward(a5))); +} + +template +typename detail::UniqueSelector::UnknownBound +MakeUnique(decltype(sizeof(int)) n) +{ + typedef typename RemoveExtent::Type ArrayType; + return UniquePtr(new ArrayType[n]()); +} + +template +typename detail::UniqueSelector::KnownBound +MakeUnique() MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) MOZ_DELETE; + +} // namespace mozilla + +#endif /* mozilla_UniquePtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Vector.h index c67467524f..8540caf476 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Vector.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/Vector.h @@ -39,14 +39,13 @@ namespace detail { /* * Check that the given capacity wastes the minimal amount of space if - * allocated on the heap. This means that cap*sizeof(T) is as close to a - * power-of-two as possible. growStorageBy() is responsible for ensuring - * this. + * allocated on the heap. This means that aCapacity*sizeof(T) is as close to a + * power-of-two as possible. growStorageBy() is responsible for ensuring this. */ template -static bool CapacityHasExcessSpace(size_t cap) +static bool CapacityHasExcessSpace(size_t aCapacity) { - size_t size = cap * sizeof(T); + size_t size = aCapacity * sizeof(T); return RoundUpPow2(size) - size >= sizeof(T); } @@ -57,72 +56,90 @@ static bool CapacityHasExcessSpace(size_t cap) template struct VectorImpl { - /* Destroys constructed objects in the range [begin, end). */ - static inline void destroy(T* begin, T* end) { - for (T* p = begin; p < end; ++p) - p->~T(); + /* Destroys constructed objects in the range [aBegin, aEnd). */ + static inline void destroy(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + p->~T(); } + } - /* Constructs objects in the uninitialized range [begin, end). */ - static inline void initialize(T* begin, T* end) { - for (T* p = begin; p < end; ++p) - new(p) T(); + /* Constructs objects in the uninitialized range [aBegin, aEnd). */ + static inline void initialize(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); } + } - /* - * Copy-constructs objects in the uninitialized range - * [dst, dst+(srcend-srcbeg)) from the range [srcbeg, srcend). - */ - template - static inline void copyConstruct(T* dst, const U* srcbeg, const U* srcend) { - for (const U* p = srcbeg; p < srcend; ++p, ++dst) - new(dst) T(*p); + /* + * Copy-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(*p); } + } - /* - * Move-constructs objects in the uninitialized range - * [dst, dst+(srcend-srcbeg)) from the range [srcbeg, srcend). - */ - template - static inline void moveConstruct(T* dst, U* srcbeg, U* srcend) { - for (U* p = srcbeg; p < srcend; ++p, ++dst) - new(dst) T(Move(*p)); + /* + * Move-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void moveConstruct(T* aDst, U* aSrcStart, U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(Move(*p)); } + } - /* - * Copy-constructs objects in the uninitialized range [dst, dst+n) from the - * same object u. - */ - template - static inline void copyConstructN(T* dst, size_t n, const U& u) { - for (T* end = dst + n; dst < end; ++dst) - new(dst) T(u); + /* + * Copy-constructs objects in the uninitialized range [aDst, aDst+aN) from + * the same object aU. + */ + template + static inline void copyConstructN(T* aDst, size_t aN, const U& aU) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + new(aDst) T(aU); } + } - /* - * Grows the given buffer to have capacity newCap, preserving the objects - * constructed in the range [begin, end) and updating v. Assumes that (1) - * newCap has not overflowed, and (2) multiplying newCap by sizeof(T) will - * not overflow. - */ - static inline bool - growTo(VectorBase& v, size_t newCap) { - MOZ_ASSERT(!v.usingInlineStorage()); - MOZ_ASSERT(!CapacityHasExcessSpace(newCap)); - T* newbuf = reinterpret_cast(v.malloc_(newCap * sizeof(T))); - if (!newbuf) - return false; - T* dst = newbuf; - T* src = v.beginNoCheck(); - for (; src < v.endNoCheck(); ++dst, ++src) - new(dst) T(Move(*src)); - VectorImpl::destroy(v.beginNoCheck(), v.endNoCheck()); - v.free_(v.mBegin); - v.mBegin = newbuf; - /* v.mLength is unchanged. */ - v.mCapacity = newCap; - return true; + /* + * Grows the given buffer to have capacity aNewCap, preserving the objects + * constructed in the range [begin, end) and updating aV. Assumes that (1) + * aNewCap has not overflowed, and (2) multiplying aNewCap by sizeof(T) will + * not overflow. + */ + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + T* newbuf = reinterpret_cast(aV.malloc_(aNewCap * sizeof(T))); + if (!newbuf) { + return false; + } + T* dst = newbuf; + T* src = aV.beginNoCheck(); + for (; src < aV.endNoCheck(); ++dst, ++src) { + new(dst) T(Move(*src)); } + VectorImpl::destroy(aV.beginNoCheck(), aV.endNoCheck()); + aV.free_(aV.mBegin); + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } }; /* @@ -133,58 +150,71 @@ struct VectorImpl template struct VectorImpl { - static inline void destroy(T*, T*) {} - - static inline void initialize(T* begin, T* end) { - /* - * You would think that memset would be a big win (or even break even) - * when we know T is a POD. But currently it's not. This is probably - * because |append| tends to be given small ranges and memset requires - * a function call that doesn't get inlined. - * - * memset(begin, 0, sizeof(T) * (end-begin)); - */ - for (T* p = begin; p < end; ++p) - new(p) T(); - } + static inline void destroy(T*, T*) {} - template - static inline void copyConstruct(T* dst, const U* srcbeg, const U* srcend) { - /* - * See above memset comment. Also, notice that copyConstruct is - * currently templated (T != U), so memcpy won't work without - * requiring T == U. - * - * memcpy(dst, srcbeg, sizeof(T) * (srcend - srcbeg)); - */ - for (const U* p = srcbeg; p < srcend; ++p, ++dst) - *dst = *p; + static inline void initialize(T* aBegin, T* aEnd) + { + /* + * You would think that memset would be a big win (or even break even) + * when we know T is a POD. But currently it's not. This is probably + * because |append| tends to be given small ranges and memset requires + * a function call that doesn't get inlined. + * + * memset(aBegin, 0, sizeof(T) * (aEnd - aBegin)); + */ + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); } + } - template - static inline void moveConstruct(T* dst, const U* srcbeg, const U* srcend) { - copyConstruct(dst, srcbeg, srcend); + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + /* + * See above memset comment. Also, notice that copyConstruct is + * currently templated (T != U), so memcpy won't work without + * requiring T == U. + * + * memcpy(aDst, aSrcStart, sizeof(T) * (aSrcEnd - aSrcStart)); + */ + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + *aDst = *p; } + } - static inline void copyConstructN(T* dst, size_t n, const T& t) { - for (T* end = dst + n; dst < end; ++dst) - *dst = t; + template + static inline void moveConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + copyConstruct(aDst, aSrcStart, aSrcEnd); + } + + static inline void copyConstructN(T* aDst, size_t aN, const T& aT) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + *aDst = aT; } + } - static inline bool - growTo(VectorBase& v, size_t newCap) { - MOZ_ASSERT(!v.usingInlineStorage()); - MOZ_ASSERT(!CapacityHasExcessSpace(newCap)); - size_t oldSize = sizeof(T) * v.mCapacity; - size_t newSize = sizeof(T) * newCap; - T* newbuf = reinterpret_cast(v.realloc_(v.mBegin, oldSize, newSize)); - if (!newbuf) - return false; - v.mBegin = newbuf; - /* v.mLength is unchanged. */ - v.mCapacity = newCap; - return true; + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + size_t oldSize = sizeof(T) * aV.mCapacity; + size_t newSize = sizeof(T) * aNewCap; + T* newbuf = reinterpret_cast(aV.realloc_(aV.mBegin, oldSize, newSize)); + if (!newbuf) { + return false; } + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } }; } // namespace detail @@ -199,368 +229,387 @@ struct VectorImpl template class VectorBase : private AllocPolicy { - /* utilities */ + /* utilities */ - static const bool sElemIsPod = IsPod::value; - typedef detail::VectorImpl Impl; - friend struct detail::VectorImpl; + static const bool kElemIsPod = IsPod::value; + typedef detail::VectorImpl Impl; + friend struct detail::VectorImpl; - bool growStorageBy(size_t incr); - bool convertToHeapStorage(size_t newCap); + bool growStorageBy(size_t aIncr); + bool convertToHeapStorage(size_t aNewCap); - /* magic constants */ + /* magic constants */ - static const int sMaxInlineBytes = 1024; + static const int kMaxInlineBytes = 1024; - /* compute constants */ + /* compute constants */ - /* - * Consider element size to be 1 for buffer sizing if there are 0 inline - * elements. This allows us to compile when the definition of the element - * type is not visible here. - * - * Explicit specialization is only allowed at namespace scope, so in order - * to keep everything here, we use a dummy template parameter with partial - * specialization. - */ - template - struct ElemSize - { - static const size_t value = sizeof(T); - }; - template - struct ElemSize<0, Dummy> - { - static const size_t value = 1; - }; - - static const size_t sInlineCapacity = - tl::Min::value>::value; - - /* Calculate inline buffer size; avoid 0-sized array. */ - static const size_t sInlineBytes = - tl::Max<1, sInlineCapacity * ElemSize::value>::value; - - /* member data */ + /* + * Consider element size to be 1 for buffer sizing if there are 0 inline + * elements. This allows us to compile when the definition of the element + * type is not visible here. + * + * Explicit specialization is only allowed at namespace scope, so in order + * to keep everything here, we use a dummy template parameter with partial + * specialization. + */ + template + struct ElemSize + { + static const size_t value = sizeof(T); + }; + template + struct ElemSize<0, Dummy> + { + static const size_t value = 1; + }; + + static const size_t kInlineCapacity = + tl::Min::value>::value; + + /* Calculate inline buffer size; avoid 0-sized array. */ + static const size_t kInlineBytes = + tl::Max<1, kInlineCapacity * ElemSize::value>::value; + + /* member data */ - /* - * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, - * mBegin + mLength) hold valid constructed T objects. The range [mBegin + - * mLength, mBegin + mCapacity) holds uninitialized memory. The range - * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory - * previously allocated by a call to reserve(). - */ - T* mBegin; + /* + * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, + * mBegin + mLength) hold valid constructed T objects. The range [mBegin + + * mLength, mBegin + mCapacity) holds uninitialized memory. The range + * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory + * previously allocated by a call to reserve(). + */ + T* mBegin; - /* Number of elements in the vector. */ - size_t mLength; + /* Number of elements in the vector. */ + size_t mLength; - /* Max number of elements storable in the vector without resizing. */ - size_t mCapacity; + /* Max number of elements storable in the vector without resizing. */ + size_t mCapacity; #ifdef DEBUG - /* Max elements of reserved or used space in this vector. */ - size_t mReserved; + /* Max elements of reserved or used space in this vector. */ + size_t mReserved; #endif - /* Memory used for inline storage. */ - AlignedStorage storage; + /* Memory used for inline storage. */ + AlignedStorage mStorage; #ifdef DEBUG - friend class ReentrancyGuard; - bool entered; + friend class ReentrancyGuard; + bool mEntered; #endif - /* private accessors */ + /* private accessors */ - bool usingInlineStorage() const { - return mBegin == const_cast(this)->inlineStorage(); - } + bool usingInlineStorage() const + { + return mBegin == const_cast(this)->inlineStorage(); + } - T* inlineStorage() { - return static_cast(storage.addr()); - } + T* inlineStorage() + { + return static_cast(mStorage.addr()); + } - T* beginNoCheck() const { - return mBegin; - } + T* beginNoCheck() const + { + return mBegin; + } - T* endNoCheck() { - return mBegin + mLength; - } + T* endNoCheck() + { + return mBegin + mLength; + } - const T* endNoCheck() const { - return mBegin + mLength; - } + const T* endNoCheck() const + { + return mBegin + mLength; + } #ifdef DEBUG - size_t reserved() const { - MOZ_ASSERT(mReserved <= mCapacity); - MOZ_ASSERT(mLength <= mReserved); - return mReserved; - } + size_t reserved() const + { + MOZ_ASSERT(mReserved <= mCapacity); + MOZ_ASSERT(mLength <= mReserved); + return mReserved; + } #endif - /* Append operations guaranteed to succeed due to pre-reserved space. */ - template void internalAppend(U&& u); - template - void internalAppendAll(const VectorBase& u); - void internalAppendN(const T& t, size_t n); - template void internalAppend(const U* begin, size_t length); + /* Append operations guaranteed to succeed due to pre-reserved space. */ + template void internalAppend(U&& aU); + template + void internalAppendAll(const VectorBase& aU); + void internalAppendN(const T& aT, size_t aN); + template void internalAppend(const U* aBegin, size_t aLength); - public: - static const size_t sMaxInlineStorage = N; +public: + static const size_t sMaxInlineStorage = N; - typedef T ElementType; + typedef T ElementType; - VectorBase(AllocPolicy = AllocPolicy()); - VectorBase(ThisVector&&); /* Move constructor. */ - ThisVector& operator=(ThisVector&&); /* Move assignment. */ - ~VectorBase(); + explicit VectorBase(AllocPolicy = AllocPolicy()); + explicit VectorBase(ThisVector&&); /* Move constructor. */ + ThisVector& operator=(ThisVector&&); /* Move assignment. */ + ~VectorBase(); - /* accessors */ + /* accessors */ - const AllocPolicy& allocPolicy() const { - return *this; - } + const AllocPolicy& allocPolicy() const { return *this; } - AllocPolicy& allocPolicy() { - return *this; - } + AllocPolicy& allocPolicy() { return *this; } - enum { InlineLength = N }; + enum { InlineLength = N }; - size_t length() const { - return mLength; - } + size_t length() const { return mLength; } - bool empty() const { - return mLength == 0; - } + bool empty() const { return mLength == 0; } - size_t capacity() const { - return mCapacity; - } + size_t capacity() const { return mCapacity; } - T* begin() { - MOZ_ASSERT(!entered); - return mBegin; - } + T* begin() + { + MOZ_ASSERT(!mEntered); + return mBegin; + } - const T* begin() const { - MOZ_ASSERT(!entered); - return mBegin; - } + const T* begin() const + { + MOZ_ASSERT(!mEntered); + return mBegin; + } - T* end() { - MOZ_ASSERT(!entered); - return mBegin + mLength; - } + T* end() + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } - const T* end() const { - MOZ_ASSERT(!entered); - return mBegin + mLength; - } + const T* end() const + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } - T& operator[](size_t i) { - MOZ_ASSERT(!entered); - MOZ_ASSERT(i < mLength); - return begin()[i]; - } + T& operator[](size_t aIndex) + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } - const T& operator[](size_t i) const { - MOZ_ASSERT(!entered); - MOZ_ASSERT(i < mLength); - return begin()[i]; - } + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } - T& back() { - MOZ_ASSERT(!entered); - MOZ_ASSERT(!empty()); - return *(end() - 1); - } + T& back() + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } - const T& back() const { - MOZ_ASSERT(!entered); - MOZ_ASSERT(!empty()); - return *(end() - 1); - } + const T& back() const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } - class Range + class Range + { + friend class VectorBase; + T* mCur; + T* mEnd; + Range(T* aCur, T* aEnd) + : mCur(aCur) + , mEnd(aEnd) { - friend class VectorBase; - T* cur_; - T* end_; - Range(T* cur, T* end) : cur_(cur), end_(end) {} - - public: - Range() {} - bool empty() const { return cur_ == end_; } - size_t remain() const { return end_ - cur_; } - T& front() const { return *cur_; } - void popFront() { MOZ_ASSERT(!empty()); ++cur_; } - T popCopyFront() { MOZ_ASSERT(!empty()); return *cur_++; } - }; - - Range all() { - return Range(begin(), end()); + MOZ_ASSERT(aCur <= aEnd); } - /* mutators */ + public: + Range() {} + bool empty() const { return mCur == mEnd; } + size_t remain() const { return PointerRangeSize(mCur, mEnd); } + T& front() const { MOZ_ASSERT(!empty()); return *mCur; } + void popFront() { MOZ_ASSERT(!empty()); ++mCur; } + T popCopyFront() { MOZ_ASSERT(!empty()); return *mCur++; } + }; - /** - * Given that the vector is empty and has no inline storage, grow to - * |capacity|. - */ - bool initCapacity(size_t request); + Range all() { return Range(begin(), end()); } - /** - * If reserve(length() + N) succeeds, the N next appends are guaranteed to - * succeed. - */ - bool reserve(size_t request); + /* mutators */ - /** - * Destroy elements in the range [end() - incr, end()). Does not deallocate - * or unreserve storage for those elements. - */ - void shrinkBy(size_t incr); + /** + * Given that the vector is empty and has no inline storage, grow to + * |capacity|. + */ + bool initCapacity(size_t aRequest); - /** Grow the vector by incr elements. */ - bool growBy(size_t incr); + /** + * If reserve(length() + N) succeeds, the N next appends are guaranteed to + * succeed. + */ + bool reserve(size_t aRequest); - /** Call shrinkBy or growBy based on whether newSize > length(). */ - bool resize(size_t newLength); + /** + * Destroy elements in the range [end() - aIncr, end()). Does not deallocate + * or unreserve storage for those elements. + */ + void shrinkBy(size_t aIncr); - /** - * Increase the length of the vector, but don't initialize the new elements - * -- leave them as uninitialized memory. - */ - bool growByUninitialized(size_t incr); - bool resizeUninitialized(size_t newLength); + /** Grow the vector by aIncr elements. */ + bool growBy(size_t aIncr); - /** Shorthand for shrinkBy(length()). */ - void clear(); + /** Call shrinkBy or growBy based on whether newSize > length(). */ + bool resize(size_t aNewLength); - /** Clears and releases any heap-allocated storage. */ - void clearAndFree(); + /** + * Increase the length of the vector, but don't initialize the new elements + * -- leave them as uninitialized memory. + */ + bool growByUninitialized(size_t aIncr); + bool resizeUninitialized(size_t aNewLength); - /** - * If true, appending |needed| elements won't reallocate elements storage. - * This *doesn't* mean that infallibleAppend may be used! You still must - * reserve the extra space, even if this method indicates that appends won't - * need to reallocate elements storage. - */ - bool canAppendWithoutRealloc(size_t needed) const; + /** Shorthand for shrinkBy(length()). */ + void clear(); - /** Potentially fallible append operations. */ + /** Clears and releases any heap-allocated storage. */ + void clearAndFree(); - /** - * This can take either a T& or a T&&. Given a T&&, it moves |u| into the - * vector, instead of copying it. If it fails, |u| is left unmoved. ("We are - * not amused.") - */ - template bool append(U&& u); + /** + * If true, appending |aNeeded| elements won't reallocate elements storage. + * This *doesn't* mean that infallibleAppend may be used! You still must + * reserve the extra space, even if this method indicates that appends won't + * need to reallocate elements storage. + */ + bool canAppendWithoutRealloc(size_t aNeeded) const; - template - bool appendAll(const VectorBase& u); - bool appendN(const T& t, size_t n); - template bool append(const U* begin, const U* end); - template bool append(const U* begin, size_t length); + /** Potentially fallible append operations. */ - /* - * Guaranteed-infallible append operations for use upon vectors whose - * memory has been pre-reserved. Don't use this if you haven't reserved the - * memory! - */ - template void infallibleAppend(U&& u) { - internalAppend(Forward(u)); - } - void infallibleAppendN(const T& t, size_t n) { - internalAppendN(t, n); - } - template void infallibleAppend(const U* aBegin, const U* aEnd) { - internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); - } - template void infallibleAppend(const U* aBegin, size_t aLength) { - internalAppend(aBegin, aLength); - } + /** + * This can take either a T& or a T&&. Given a T&&, it moves |aU| into the + * vector, instead of copying it. If it fails, |aU| is left unmoved. ("We are + * not amused.") + */ + template bool append(U&& aU); + + template + bool appendAll(const VectorBase& aU); + bool appendN(const T& aT, size_t aN); + template bool append(const U* aBegin, const U* aEnd); + template bool append(const U* aBegin, size_t aLength); - void popBack(); + /* + * Guaranteed-infallible append operations for use upon vectors whose + * memory has been pre-reserved. Don't use this if you haven't reserved the + * memory! + */ + template void infallibleAppend(U&& aU) + { + internalAppend(Forward(aU)); + } + void infallibleAppendN(const T& aT, size_t aN) + { + internalAppendN(aT, aN); + } + template void infallibleAppend(const U* aBegin, const U* aEnd) + { + internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); + } + template void infallibleAppend(const U* aBegin, size_t aLength) + { + internalAppend(aBegin, aLength); + } - T popCopy(); + void popBack(); - /** - * Transfers ownership of the internal buffer used by this vector to the - * caller. (It's the caller's responsibility to properly deallocate this - * buffer, in accordance with this vector's AllocPolicy.) After this call, - * the vector is empty. Since the returned buffer may need to be allocated - * (if the elements are currently stored in-place), the call can fail, - * returning nullptr. - * - * N.B. Although a T*, only the range [0, length()) is constructed. - */ - T* extractRawBuffer(); + T popCopy(); - /** - * Transfer ownership of an array of objects into the vector. The caller - * must have allocated the array in accordance with this vector's - * AllocPolicy. - * - * N.B. This call assumes that there are no uninitialized elements in the - * passed array. - */ - void replaceRawBuffer(T* p, size_t length); + /** + * Transfers ownership of the internal buffer used by this vector to the + * caller. (It's the caller's responsibility to properly deallocate this + * buffer, in accordance with this vector's AllocPolicy.) After this call, + * the vector is empty. Since the returned buffer may need to be allocated + * (if the elements are currently stored in-place), the call can fail, + * returning nullptr. + * + * N.B. Although a T*, only the range [0, length()) is constructed. + */ + T* extractRawBuffer(); + + /** + * Transfer ownership of an array of objects into the vector. The caller + * must have allocated the array in accordance with this vector's + * AllocPolicy. + * + * N.B. This call assumes that there are no uninitialized elements in the + * passed array. + */ + void replaceRawBuffer(T* aP, size_t aLength); + + /** + * Places |aVal| at position |aP|, shifting existing elements from |aP| onward + * one position higher. On success, |aP| should not be reused because it'll + * be a dangling pointer if reallocation of the vector storage occurred; the + * return value should be used instead. On failure, nullptr is returned. + * + * Example usage: + * + * if (!(p = vec.insert(p, val))) { + * + * } + * + * + * This is inherently a linear-time operation. Be careful! + */ + template + T* insert(T* aP, U&& aVal); - /** - * Places |val| at position |p|, shifting existing elements from |p| onward - * one position higher. On success, |p| should not be reused because it'll - * be a dangling pointer if reallocation of the vector storage occurred; the - * return value should be used instead. On failure, nullptr is returned. - * - * Example usage: - * - * if (!(p = vec.insert(p, val))) - * - * - * - * This is inherently a linear-time operation. Be careful! - */ - template - T* insert(T* p, U&& val); + /** + * Removes the element |aT|, which must fall in the bounds [begin, end), + * shifting existing elements from |aT + 1| onward one position lower. + */ + void erase(T* aT); - /** - * Removes the element |t|, which must fall in the bounds [begin, end), - * shifting existing elements from |t + 1| onward one position lower. - */ - void erase(T* t); + /** + * Removes the elements [|aBegin|, |aEnd|), which must fall in the bounds + * [begin, end), shifting existing elements from |aEnd + 1| onward to aBegin's + * old position. + */ + void erase(T* aBegin, T* aEnd); - /** - * Measure the size of the vector's heap-allocated storage. - */ - size_t sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const; + /** + * Measure the size of the vector's heap-allocated storage. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const; - /** - * Like sizeOfExcludingThis, but also measures the size of the vector - * object (which must be heap-allocated) itself. - */ - size_t sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const; + /** + * Like sizeOfExcludingThis, but also measures the size of the vector + * object (which must be heap-allocated) itself. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; - void swap(ThisVector& other); + void swap(ThisVector& aOther); - private: - VectorBase(const VectorBase&) MOZ_DELETE; - void operator=(const VectorBase&) MOZ_DELETE; +private: + VectorBase(const VectorBase&) MOZ_DELETE; + void operator=(const VectorBase&) MOZ_DELETE; - /* Move-construct/assign only from our derived class, ThisVector. */ - VectorBase(VectorBase&&) MOZ_DELETE; - void operator=(VectorBase&&) MOZ_DELETE; + /* Move-construct/assign only from our derived class, ThisVector. */ + VectorBase(VectorBase&&) MOZ_DELETE; + void operator=(VectorBase&&) MOZ_DELETE; }; /* This does the re-entrancy check plus several other sanity checks. */ #define MOZ_REENTRANCY_GUARD_ET_AL \ ReentrancyGuard g(*this); \ - MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == sInlineCapacity); \ + MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == kInlineCapacity); \ MOZ_ASSERT(reserved() <= mCapacity); \ MOZ_ASSERT(mLength <= reserved()); \ MOZ_ASSERT(mLength <= mCapacity) @@ -569,39 +618,39 @@ class VectorBase : private AllocPolicy template MOZ_ALWAYS_INLINE -VectorBase::VectorBase(AP ap) - : AP(ap), - mLength(0), - mCapacity(sInlineCapacity) +VectorBase::VectorBase(AP aAP) + : AP(aAP) + , mLength(0) + , mCapacity(kInlineCapacity) #ifdef DEBUG - , mReserved(sInlineCapacity), - entered(false) + , mReserved(kInlineCapacity) + , mEntered(false) #endif { - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); } /* Move constructor. */ template MOZ_ALWAYS_INLINE -VectorBase::VectorBase(TV&& rhs) - : AllocPolicy(Move(rhs)) +VectorBase::VectorBase(TV&& aRhs) + : AllocPolicy(Move(aRhs)) #ifdef DEBUG - , entered(false) + , mEntered(false) #endif { - mLength = rhs.mLength; - mCapacity = rhs.mCapacity; + mLength = aRhs.mLength; + mCapacity = aRhs.mCapacity; #ifdef DEBUG - mReserved = rhs.mReserved; + mReserved = aRhs.mReserved; #endif - if (rhs.usingInlineStorage()) { + if (aRhs.usingInlineStorage()) { /* We can't move the buffer over in this case, so copy elements. */ - mBegin = static_cast(storage.addr()); - Impl::moveConstruct(mBegin, rhs.beginNoCheck(), rhs.endNoCheck()); + mBegin = static_cast(mStorage.addr()); + Impl::moveConstruct(mBegin, aRhs.beginNoCheck(), aRhs.endNoCheck()); /* - * Leave rhs's mLength, mBegin, mCapacity, and mReserved as they are. + * Leave aRhs's mLength, mBegin, mCapacity, and mReserved as they are. * The elements in its in-line storage still need to be destroyed. */ } else { @@ -609,26 +658,25 @@ VectorBase::VectorBase(TV&& rhs) * Take src's buffer, and turn src into an empty vector using * in-line storage. */ - mBegin = rhs.mBegin; - rhs.mBegin = static_cast(rhs.storage.addr()); - rhs.mCapacity = sInlineCapacity; - rhs.mLength = 0; + mBegin = aRhs.mBegin; + aRhs.mBegin = static_cast(aRhs.mStorage.addr()); + aRhs.mCapacity = kInlineCapacity; + aRhs.mLength = 0; #ifdef DEBUG - rhs.mReserved = sInlineCapacity; + aRhs.mReserved = kInlineCapacity; #endif } } /* Move assignment. */ template -MOZ_ALWAYS_INLINE -TV& -VectorBase::operator=(TV&& rhs) +MOZ_ALWAYS_INLINE TV& +VectorBase::operator=(TV&& aRhs) { - MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + MOZ_ASSERT(this != &aRhs, "self-move assignment is prohibited"); TV* tv = static_cast(this); tv->~TV(); - new(tv) TV(Move(rhs)); + new(tv) TV(Move(aRhs)); return *tv; } @@ -638,26 +686,28 @@ VectorBase::~VectorBase() { MOZ_REENTRANCY_GUARD_ET_AL; Impl::destroy(beginNoCheck(), endNoCheck()); - if (!usingInlineStorage()) + if (!usingInlineStorage()) { this->free_(beginNoCheck()); + } } /* - * This function will create a new heap buffer with capacity newCap, + * This function will create a new heap buffer with capacity aNewCap, * move all elements in the inline buffer to this new buffer, * and fail on OOM. */ template inline bool -VectorBase::convertToHeapStorage(size_t newCap) +VectorBase::convertToHeapStorage(size_t aNewCap) { MOZ_ASSERT(usingInlineStorage()); /* Allocate buffer. */ - MOZ_ASSERT(!detail::CapacityHasExcessSpace(newCap)); - T* newBuf = reinterpret_cast(this->malloc_(newCap * sizeof(T))); - if (!newBuf) + MOZ_ASSERT(!detail::CapacityHasExcessSpace(aNewCap)); + T* newBuf = reinterpret_cast(this->malloc_(aNewCap * sizeof(T))); + if (!newBuf) { return false; + } /* Copy inline elements into heap buffer. */ Impl::moveConstruct(newBuf, beginNoCheck(), endNoCheck()); @@ -666,15 +716,15 @@ VectorBase::convertToHeapStorage(size_t newCap) /* Switch in heap buffer. */ mBegin = newBuf; /* mLength is unchanged. */ - mCapacity = newCap; + mCapacity = aNewCap; return true; } template MOZ_NEVER_INLINE bool -VectorBase::growStorageBy(size_t incr) +VectorBase::growStorageBy(size_t aIncr) { - MOZ_ASSERT(mLength + incr > mCapacity); + MOZ_ASSERT(mLength + aIncr > mCapacity); MOZ_ASSERT_IF(!usingInlineStorage(), !detail::CapacityHasExcessSpace(mCapacity)); @@ -688,11 +738,11 @@ VectorBase::growStorageBy(size_t incr) size_t newCap; - if (incr == 1) { + if (aIncr == 1) { if (usingInlineStorage()) { /* This case occurs in ~70--80% of the calls to this function. */ size_t newSize = - tl::RoundUpPow2<(sInlineCapacity + 1) * sizeof(T)>::value; + tl::RoundUpPow2<(kInlineCapacity + 1) * sizeof(T)>::value; newCap = newSize / sizeof(T); goto convert; } @@ -725,13 +775,14 @@ VectorBase::growStorageBy(size_t incr) * then there might be space for one more element. */ newCap = mLength * 2; - if (detail::CapacityHasExcessSpace(newCap)) + if (detail::CapacityHasExcessSpace(newCap)) { newCap += 1; + } } else { /* This case occurs in ~2% of the calls to this function. */ - size_t newMinCap = mLength + incr; + size_t newMinCap = mLength + aIncr; - /* Did mLength + incr overflow? Will newCap * sizeof(T) overflow? */ + /* Did mLength + aIncr overflow? Will newCap * sizeof(T) overflow? */ if (newMinCap < mLength || newMinCap & tl::MulOverflowMask<2 * sizeof(T)>::value) { @@ -745,7 +796,7 @@ VectorBase::growStorageBy(size_t incr) } if (usingInlineStorage()) { - convert: +convert: return convertToHeapStorage(newCap); } @@ -755,34 +806,37 @@ VectorBase::growStorageBy(size_t incr) template inline bool -VectorBase::initCapacity(size_t request) +VectorBase::initCapacity(size_t aRequest) { MOZ_ASSERT(empty()); MOZ_ASSERT(usingInlineStorage()); - if (request == 0) + if (aRequest == 0) { return true; - T* newbuf = reinterpret_cast(this->malloc_(request * sizeof(T))); - if (!newbuf) + } + T* newbuf = reinterpret_cast(this->malloc_(aRequest * sizeof(T))); + if (!newbuf) { return false; + } mBegin = newbuf; - mCapacity = request; + mCapacity = aRequest; #ifdef DEBUG - mReserved = request; + mReserved = aRequest; #endif return true; } template inline bool -VectorBase::reserve(size_t request) +VectorBase::reserve(size_t aRequest) { MOZ_REENTRANCY_GUARD_ET_AL; - if (request > mCapacity && !growStorageBy(request - mLength)) + if (aRequest > mCapacity && !growStorageBy(aRequest - mLength)) { return false; - + } #ifdef DEBUG - if (request > mReserved) - mReserved = request; + if (aRequest > mReserved) { + mReserved = aRequest; + } MOZ_ASSERT(mLength <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); #endif @@ -791,69 +845,73 @@ VectorBase::reserve(size_t request) template inline void -VectorBase::shrinkBy(size_t incr) +VectorBase::shrinkBy(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - MOZ_ASSERT(incr <= mLength); - Impl::destroy(endNoCheck() - incr, endNoCheck()); - mLength -= incr; + MOZ_ASSERT(aIncr <= mLength); + Impl::destroy(endNoCheck() - aIncr, endNoCheck()); + mLength -= aIncr; } template MOZ_ALWAYS_INLINE bool -VectorBase::growBy(size_t incr) +VectorBase::growBy(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - if (incr > mCapacity - mLength && !growStorageBy(incr)) + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { return false; - - MOZ_ASSERT(mLength + incr <= mCapacity); - T* newend = endNoCheck() + incr; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + T* newend = endNoCheck() + aIncr; Impl::initialize(endNoCheck(), newend); - mLength += incr; + mLength += aIncr; #ifdef DEBUG - if (mLength > mReserved) + if (mLength > mReserved) { mReserved = mLength; + } #endif return true; } template MOZ_ALWAYS_INLINE bool -VectorBase::growByUninitialized(size_t incr) +VectorBase::growByUninitialized(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - if (incr > mCapacity - mLength && !growStorageBy(incr)) + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { return false; - - MOZ_ASSERT(mLength + incr <= mCapacity); - mLength += incr; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + mLength += aIncr; #ifdef DEBUG - if (mLength > mReserved) + if (mLength > mReserved) { mReserved = mLength; + } #endif return true; } template inline bool -VectorBase::resize(size_t newLength) +VectorBase::resize(size_t aNewLength) { size_t curLength = mLength; - if (newLength > curLength) - return growBy(newLength - curLength); - shrinkBy(curLength - newLength); + if (aNewLength > curLength) { + return growBy(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); return true; } template MOZ_ALWAYS_INLINE bool -VectorBase::resizeUninitialized(size_t newLength) +VectorBase::resizeUninitialized(size_t aNewLength) { size_t curLength = mLength; - if (newLength > curLength) - return growByUninitialized(newLength - curLength); - shrinkBy(curLength - newLength); + if (aNewLength > curLength) { + return growByUninitialized(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); return true; } @@ -872,166 +930,186 @@ VectorBase::clearAndFree() { clear(); - if (usingInlineStorage()) + if (usingInlineStorage()) { return; - + } this->free_(beginNoCheck()); - mBegin = static_cast(storage.addr()); - mCapacity = sInlineCapacity; + mBegin = static_cast(mStorage.addr()); + mCapacity = kInlineCapacity; #ifdef DEBUG - mReserved = sInlineCapacity; + mReserved = kInlineCapacity; #endif } template inline bool -VectorBase::canAppendWithoutRealloc(size_t needed) const +VectorBase::canAppendWithoutRealloc(size_t aNeeded) const { - return mLength + needed <= mCapacity; + return mLength + aNeeded <= mCapacity; } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppendAll(const VectorBase& other) +VectorBase::internalAppendAll( + const VectorBase& aOther) { - internalAppend(other.begin(), other.length()); + internalAppend(aOther.begin(), aOther.length()); } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppend(U&& u) +VectorBase::internalAppend(U&& aU) { MOZ_ASSERT(mLength + 1 <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - new(endNoCheck()) T(Forward(u)); + new(endNoCheck()) T(Forward(aU)); ++mLength; } template MOZ_ALWAYS_INLINE bool -VectorBase::appendN(const T& t, size_t needed) +VectorBase::appendN(const T& aT, size_t aNeeded) { MOZ_REENTRANCY_GUARD_ET_AL; - if (mLength + needed > mCapacity && !growStorageBy(needed)) + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { return false; - + } #ifdef DEBUG - if (mLength + needed > mReserved) - mReserved = mLength + needed; + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } #endif - internalAppendN(t, needed); + internalAppendN(aT, aNeeded); return true; } template MOZ_ALWAYS_INLINE void -VectorBase::internalAppendN(const T& t, size_t needed) +VectorBase::internalAppendN(const T& aT, size_t aNeeded) { - MOZ_ASSERT(mLength + needed <= mReserved); + MOZ_ASSERT(mLength + aNeeded <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - Impl::copyConstructN(endNoCheck(), needed, t); - mLength += needed; + Impl::copyConstructN(endNoCheck(), aNeeded, aT); + mLength += aNeeded; } template template inline T* -VectorBase::insert(T* p, U&& val) +VectorBase::insert(T* aP, U&& aVal) { - MOZ_ASSERT(begin() <= p); - MOZ_ASSERT(p <= end()); - size_t pos = p - begin(); + MOZ_ASSERT(begin() <= aP); + MOZ_ASSERT(aP <= end()); + size_t pos = aP - begin(); MOZ_ASSERT(pos <= mLength); size_t oldLength = mLength; if (pos == oldLength) { - if (!append(Forward(val))) + if (!append(Forward(aVal))) { return nullptr; + } } else { T oldBack = Move(back()); - if (!append(Move(oldBack))) /* Dup the last element. */ + if (!append(Move(oldBack))) { /* Dup the last element. */ return nullptr; - for (size_t i = oldLength; i > pos; --i) + } + for (size_t i = oldLength; i > pos; --i) { (*this)[i] = Move((*this)[i - 1]); - (*this)[pos] = Forward(val); + } + (*this)[pos] = Forward(aVal); } return begin() + pos; } template inline void -VectorBase::erase(T* it) +VectorBase::erase(T* aIt) { - MOZ_ASSERT(begin() <= it); - MOZ_ASSERT(it < end()); - while (it + 1 < end()) { - *it = *(it + 1); - ++it; + MOZ_ASSERT(begin() <= aIt); + MOZ_ASSERT(aIt < end()); + while (aIt + 1 < end()) { + *aIt = Move(*(aIt + 1)); + ++aIt; } - popBack(); + popBack(); +} + +template +inline void +VectorBase::erase(T* aBegin, T* aEnd) +{ + MOZ_ASSERT(begin() <= aBegin); + MOZ_ASSERT(aBegin <= aEnd); + MOZ_ASSERT(aEnd <= end()); + while (aEnd < end()) { + *aBegin++ = Move(*aEnd++); + } + shrinkBy(aEnd - aBegin); } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(const U* insBegin, const U* insEnd) +VectorBase::append(const U* aInsBegin, const U* aInsEnd) { MOZ_REENTRANCY_GUARD_ET_AL; - size_t needed = PointerRangeSize(insBegin, insEnd); - if (mLength + needed > mCapacity && !growStorageBy(needed)) + size_t aNeeded = PointerRangeSize(aInsBegin, aInsEnd); + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { return false; - + } #ifdef DEBUG - if (mLength + needed > mReserved) - mReserved = mLength + needed; + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } #endif - internalAppend(insBegin, needed); + internalAppend(aInsBegin, aNeeded); return true; } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppend(const U* insBegin, size_t insLength) +VectorBase::internalAppend(const U* aInsBegin, size_t aInsLength) { - MOZ_ASSERT(mLength + insLength <= mReserved); + MOZ_ASSERT(mLength + aInsLength <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - Impl::copyConstruct(endNoCheck(), insBegin, insBegin + insLength); - mLength += insLength; + Impl::copyConstruct(endNoCheck(), aInsBegin, aInsBegin + aInsLength); + mLength += aInsLength; } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(U&& u) +VectorBase::append(U&& aU) { MOZ_REENTRANCY_GUARD_ET_AL; - if (mLength == mCapacity && !growStorageBy(1)) + if (mLength == mCapacity && !growStorageBy(1)) { return false; - + } #ifdef DEBUG - if (mLength + 1 > mReserved) + if (mLength + 1 > mReserved) { mReserved = mLength + 1; + } #endif - internalAppend(Forward(u)); + internalAppend(Forward(aU)); return true; } template template MOZ_ALWAYS_INLINE bool -VectorBase::appendAll(const VectorBase& other) +VectorBase::appendAll(const VectorBase& aOther) { - return append(other.begin(), other.length()); + return append(aOther.begin(), aOther.length()); } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(const U *insBegin, size_t insLength) +VectorBase::append(const U* aInsBegin, size_t aInsLength) { - return append(insBegin, insBegin + insLength); + return append(aInsBegin, aInsBegin + aInsLength); } template @@ -1060,19 +1138,20 @@ VectorBase::extractRawBuffer() T* ret; if (usingInlineStorage()) { ret = reinterpret_cast(this->malloc_(mLength * sizeof(T))); - if (!ret) + if (!ret) { return nullptr; + } Impl::copyConstruct(ret, beginNoCheck(), endNoCheck()); Impl::destroy(beginNoCheck(), endNoCheck()); /* mBegin, mCapacity are unchanged. */ mLength = 0; } else { ret = mBegin; - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); mLength = 0; - mCapacity = sInlineCapacity; + mCapacity = kInlineCapacity; #ifdef DEBUG - mReserved = sInlineCapacity; + mReserved = kInlineCapacity; #endif } return ret; @@ -1080,30 +1159,31 @@ VectorBase::extractRawBuffer() template inline void -VectorBase::replaceRawBuffer(T* p, size_t aLength) +VectorBase::replaceRawBuffer(T* aP, size_t aLength) { MOZ_REENTRANCY_GUARD_ET_AL; /* Destroy what we have. */ Impl::destroy(beginNoCheck(), endNoCheck()); - if (!usingInlineStorage()) + if (!usingInlineStorage()) { this->free_(beginNoCheck()); + } /* Take in the new buffer. */ - if (aLength <= sInlineCapacity) { + if (aLength <= kInlineCapacity) { /* - * We convert to inline storage if possible, even though p might + * We convert to inline storage if possible, even though aP might * otherwise be acceptable. Maybe this behaviour should be * specifiable with an argument to this function. */ - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); mLength = aLength; - mCapacity = sInlineCapacity; - Impl::moveConstruct(mBegin, p, p + aLength); - Impl::destroy(p, p + aLength); - this->free_(p); + mCapacity = kInlineCapacity; + Impl::moveConstruct(mBegin, aP, aP + aLength); + Impl::destroy(aP, aP + aLength); + this->free_(aP); } else { - mBegin = p; + mBegin = aP; mLength = aLength; mCapacity = aLength; } @@ -1114,42 +1194,42 @@ VectorBase::replaceRawBuffer(T* p, size_t aLength) template inline size_t -VectorBase::sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const +VectorBase::sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { - return usingInlineStorage() ? 0 : mallocSizeOf(beginNoCheck()); + return usingInlineStorage() ? 0 : aMallocSizeOf(beginNoCheck()); } template inline size_t -VectorBase::sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const +VectorBase::sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { - return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); } template inline void -VectorBase::swap(TV& other) +VectorBase::swap(TV& aOther) { static_assert(N == 0, "still need to implement this for N != 0"); // This only works when inline storage is always empty. - if (!usingInlineStorage() && other.usingInlineStorage()) { - other.mBegin = mBegin; + if (!usingInlineStorage() && aOther.usingInlineStorage()) { + aOther.mBegin = mBegin; mBegin = inlineStorage(); - } else if (usingInlineStorage() && !other.usingInlineStorage()) { - mBegin = other.mBegin; - other.mBegin = other.inlineStorage(); - } else if (!usingInlineStorage() && !other.usingInlineStorage()) { - Swap(mBegin, other.mBegin); + } else if (usingInlineStorage() && !aOther.usingInlineStorage()) { + mBegin = aOther.mBegin; + aOther.mBegin = aOther.inlineStorage(); + } else if (!usingInlineStorage() && !aOther.usingInlineStorage()) { + Swap(mBegin, aOther.mBegin); } else { // This case is a no-op, since we'd set both to use their inline storage. } - Swap(mLength, other.mLength); - Swap(mCapacity, other.mCapacity); + Swap(mLength, aOther.mLength); + Swap(mCapacity, aOther.mCapacity); #ifdef DEBUG - Swap(mReserved, other.mReserved); + Swap(mReserved, aOther.mReserved); #endif } @@ -1180,14 +1260,15 @@ class Vector AllocPolicy, Vector > { - typedef VectorBase Base; - - public: - Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} - Vector(Vector&& vec) : Base(Move(vec)) {} - Vector& operator=(Vector&& vec) { - return Base::operator=(Move(vec)); - } + typedef VectorBase Base; + +public: + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + Vector(Vector&& vec) : Base(Move(vec)) {} + Vector& operator=(Vector&& aOther) + { + return Base::operator=(Move(aOther)); + } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/WeakPtr.h b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/WeakPtr.h index 0165e3a017..07f00bc295 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/WeakPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/android/mozilla/WeakPtr.h @@ -14,21 +14,29 @@ * the WeakPtrs to it and allows the WeakReference to live beyond the lifetime * of 'Foo'. * + * PLEASE NOTE: This weak pointer implementation is not thread-safe. + * + * Note that when deriving from SupportsWeakPtr you should add + * MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public section of your + * class, where ClassName is the name of your class. + * * The overhead of WeakPtr is that accesses to 'Foo' becomes an additional * dereference, and an additional heap allocated pointer sized object shared * between all of the WeakPtrs. * * Example of usage: * - * // To have a class C support weak pointers, inherit from SupportsWeakPtr. + * // To have a class C support weak pointers, inherit from + * // SupportsWeakPtr. * class C : public SupportsWeakPtr * { - * public: - * int num; - * void act(); + * public: + * MOZ_DECLARE_REFCOUNTED_TYPENAME(C) + * int mNum; + * void act(); * }; * - * C* ptr = new C(); + * C* ptr = new C(); * * // Get weak pointers to ptr. The first time asWeakPtr is called * // a reference counted WeakReference object is created that @@ -39,7 +47,7 @@ * * // Test a weak pointer for validity before using it. * if (weak) { - * weak->num = 17; + * weak->mNum = 17; * weak->act(); * } * @@ -59,11 +67,14 @@ #ifndef mozilla_WeakPtr_h #define mozilla_WeakPtr_h +#include "mozilla/ArrayUtils.h" #include "mozilla/Assertions.h" #include "mozilla/NullPtr.h" #include "mozilla/RefPtr.h" #include "mozilla/TypeTraits.h" +#include + namespace mozilla { template class WeakPtrBase; @@ -71,23 +82,48 @@ template class SupportsWeakPtrBase; namespace detail { -// This can live beyond the lifetime of the class derived from SupportsWeakPtrBase. +// This can live beyond the lifetime of the class derived from +// SupportsWeakPtrBase. template class WeakReference : public ::mozilla::RefCounted > { - public: - explicit WeakReference(T* p) : ptr(p) {} - T* get() const { - return ptr; - } - - private: - friend class WeakPtrBase >; - friend class SupportsWeakPtrBase >; - void detach() { - ptr = nullptr; - } - T* ptr; +public: + explicit WeakReference(T* p) : mPtr(p) {} + + T* get() const { return mPtr; } + +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#ifdef XP_WIN +#define snprintf _snprintf +#endif + const char* typeName() const + { + static char nameBuffer[1024]; + const char* innerType = mPtr->typeName(); + // We could do fancier length checks at runtime, but innerType is + // controlled by us so we can ensure that this never causes a buffer + // overflow by this assertion. + MOZ_ASSERT(strlen(innerType) + sizeof("WeakReference<>") < + ArrayLength(nameBuffer), + "Exceedingly large type name"); + snprintf(nameBuffer, ArrayLength(nameBuffer), "WeakReference<%s>", + innerType); + // This is usually not OK, but here we are returning a pointer to a static + // buffer which will immediately be used by the caller. + return nameBuffer; + } + + size_t typeSize() const { return sizeof(*this); } +#undef snprintf +#endif + +private: + friend class WeakPtrBase >; + friend class SupportsWeakPtrBase >; + + void detach() { mPtr = nullptr; } + + T* mPtr; }; } // namespace detail @@ -95,25 +131,29 @@ class WeakReference : public ::mozilla::RefCounted > template class SupportsWeakPtrBase { - public: - WeakPtrBase asWeakPtr() { - if (!weakRef) - weakRef = new WeakReference(static_cast(this)); - return WeakPtrBase(weakRef); +public: + WeakPtrBase asWeakPtr() + { + if (!weakRef) { + weakRef = new WeakReference(static_cast(this)); } - - protected: - ~SupportsWeakPtrBase() { - static_assert(IsBaseOf, T>::value, - "T must derive from SupportsWeakPtrBase"); - if (weakRef) - weakRef->detach(); + return WeakPtrBase(weakRef); + } + +protected: + ~SupportsWeakPtrBase() + { + static_assert(IsBaseOf, T>::value, + "T must derive from SupportsWeakPtrBase"); + if (weakRef) { + weakRef->detach(); } + } - private: - friend class WeakPtrBase; +private: + friend class WeakPtrBase; - RefPtr weakRef; + RefPtr weakRef; }; template @@ -124,42 +164,37 @@ class SupportsWeakPtr : public SupportsWeakPtrBase > template class WeakPtrBase { - public: - WeakPtrBase(const WeakPtrBase& o) : ref(o.ref) {} - // Ensure that ref is dereferenceable in the uninitialized state - WeakPtrBase() : ref(new WeakReference(nullptr)) {} +public: + WeakPtrBase(const WeakPtrBase& aOther) + : mRef(aOther.mRef) + {} - operator T*() const { - return ref->get(); - } - T& operator*() const { - return *ref->get(); - } + // Ensure that mRef is dereferenceable in the uninitialized state. + WeakPtrBase() : mRef(new WeakReference(nullptr)) {} - T* operator->() const { - return ref->get(); - } + operator T*() const { return mRef->get(); } + T& operator*() const { return *mRef->get(); } - T* get() const { - return ref->get(); - } + T* operator->() const { return mRef->get(); } + + T* get() const { return mRef->get(); } - private: - friend class SupportsWeakPtrBase; +private: + friend class SupportsWeakPtrBase; - explicit WeakPtrBase(const RefPtr &o) : ref(o) {} + explicit WeakPtrBase(const RefPtr &aOther) : mRef(aOther) {} - RefPtr ref; + RefPtr mRef; }; template class WeakPtr : public WeakPtrBase > { - typedef WeakPtrBase > Base; - public: - WeakPtr(const WeakPtr& o) : Base(o) {} - WeakPtr(const Base& o) : Base(o) {} - WeakPtr() {} + typedef WeakPtrBase > Base; +public: + WeakPtr(const WeakPtr& aOther) : Base(aOther) {} + MOZ_IMPLICIT WeakPtr(const Base& aOther) : Base(aOther) {} + WeakPtr() {} }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js-config-32.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js-config-32.h new file mode 100644 index 0000000000..2cedc513e7 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js-config-32.h @@ -0,0 +1,53 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sw=4 et tw=78: + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_config_h +#define js_config_h + +/* Definitions set at build time that affect SpiderMonkey's public API. + This header file is generated by the SpiderMonkey configure script, + and installed along with jsapi.h. */ + +/* Define to 1 if SpiderMonkey is in debug mode. */ +/* #undef JS_DEBUG */ + +/* Define to 1 if SpiderMonkey should not use struct types in debug builds. */ +/* #undef JS_NO_JSVAL_JSID_STRUCT_TYPES */ + +/* Define to 1 if SpiderMonkey should support multi-threaded clients. */ +/* #undef JS_THREADSAFE */ + +/* Define to 1 if SpiderMonkey should include ctypes support. */ +/* #undef JS_HAS_CTYPES */ + +/* Define to 1 if SpiderMonkey should support the ability to perform + entirely too much GC. */ +/* #undef JS_GC_ZEAL */ + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +#define JS_HAVE_ENDIAN_H 1 + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +#define JS_HAVE_MACHINE_ENDIAN_H 1 + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +/* #undef JS_HAVE_SYS_ISA_DEFS_H */ + +/* Define to 1 if SpiderMonkey is in NUNBOX32 mode. */ +#define JS_NUNBOX32 1 + +/* Define to 1 if SpiderMonkey is in PUNBOX64 mode. */ +/* #undef JS_PUNBOX64 */ + +/* MOZILLA JSAPI version number components */ +#define MOZJS_MAJOR_VERSION 33 +#define MOZJS_MINOR_VERSION 1 + +#endif /* js_config_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js-config-64.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js-config-64.h new file mode 100644 index 0000000000..b0977e896a --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js-config-64.h @@ -0,0 +1,53 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sw=4 et tw=78: + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_config_h +#define js_config_h + +/* Definitions set at build time that affect SpiderMonkey's public API. + This header file is generated by the SpiderMonkey configure script, + and installed along with jsapi.h. */ + +/* Define to 1 if SpiderMonkey is in debug mode. */ +/* #undef JS_DEBUG */ + +/* Define to 1 if SpiderMonkey should not use struct types in debug builds. */ +/* #undef JS_NO_JSVAL_JSID_STRUCT_TYPES */ + +/* Define to 1 if SpiderMonkey should support multi-threaded clients. */ +/* #undef JS_THREADSAFE */ + +/* Define to 1 if SpiderMonkey should include ctypes support. */ +/* #undef JS_HAS_CTYPES */ + +/* Define to 1 if SpiderMonkey should support the ability to perform + entirely too much GC. */ +/* #undef JS_GC_ZEAL */ + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +#define JS_HAVE_ENDIAN_H 1 + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +#define JS_HAVE_MACHINE_ENDIAN_H 1 + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +/* #undef JS_HAVE_SYS_ISA_DEFS_H */ + +/* Define to 1 if SpiderMonkey is in NUNBOX32 mode. */ +/* #undef JS_NUNBOX32 */ + +/* Define to 1 if SpiderMonkey is in PUNBOX64 mode. */ +#define JS_PUNBOX64 1 + +/* MOZILLA JSAPI version number components */ +#define MOZJS_MAJOR_VERSION 33 +#define MOZJS_MINOR_VERSION 1 + +#endif /* js_config_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js-config.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js-config.h index 093a586b00..a1ded849ae 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js-config.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js-config.h @@ -1,41 +1,5 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * vim: set ts=8 sw=4 et tw=78: - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef js_config_h -#define js_config_h - -/* Definitions set at build time that affect SpiderMonkey's public API. - This header file is generated by the SpiderMonkey configure script, - and installed along with jsapi.h. */ - -/* Define to 1 if SpiderMonkey should support multi-threaded clients. */ -/* #undef JS_THREADSAFE */ - -/* Define to 1 if SpiderMonkey should include ctypes support. */ -/* #undef JS_HAS_CTYPES */ - -/* Define to 1 if SpiderMonkey should support the ability to perform - entirely too much GC. */ -/* #undef JS_GC_ZEAL */ - -/* Define to 1 if the header is present and - useable. See jscpucfg.h. */ -#define JS_HAVE_ENDIAN_H 1 - -/* Define to 1 if the header is present and - useable. See jscpucfg.h. */ -#define JS_HAVE_MACHINE_ENDIAN_H 1 - -/* Define to 1 if the header is present and - useable. See jscpucfg.h. */ -/* #undef JS_HAVE_SYS_ISA_DEFS_H */ - -/* MOZILLA JSAPI version number components */ -#define MOZJS_MAJOR_VERSION 28 -#define MOZJS_MINOR_VERSION 0 - -#endif /* js_config_h */ +#if defined(__LP64__) && __LP64__ +#include"js-config-64.h" +#else +#include"js-config-32.h" +#endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js.msg b/frameworks/js-bindings/external/spidermonkey/include/ios/js.msg index 5a8344163b..d342ad4506 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js.msg +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js.msg @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -105,7 +105,7 @@ MSG_DEF(JSMSG_BAD_DESTRUCT_ASS, 51, 0, JSEXN_REFERENCEERR, "invalid destr MSG_DEF(JSMSG_PAREN_AFTER_LET, 52, 0, JSEXN_SYNTAXERR, "missing ) after let head") MSG_DEF(JSMSG_CURLY_AFTER_LET, 53, 0, JSEXN_SYNTAXERR, "missing } after let block") MSG_DEF(JSMSG_MISSING_PAREN, 54, 0, JSEXN_SYNTAXERR, "unterminated parenthetical") -MSG_DEF(JSMSG_UNTERM_CLASS, 55, 1, JSEXN_SYNTAXERR, "unterminated character class {0}") +MSG_DEF(JSMSG_UNTERM_CLASS, 55, 0, JSEXN_SYNTAXERR, "unterminated character class") MSG_DEF(JSMSG_TRAILING_SLASH, 56, 0, JSEXN_SYNTAXERR, "trailing \\ in regular expression") MSG_DEF(JSMSG_BAD_CLASS_RANGE, 57, 0, JSEXN_SYNTAXERR, "invalid range in character class") MSG_DEF(JSMSG_BAD_REGEXP_FLAG, 58, 1, JSEXN_SYNTAXERR, "invalid regular expression flag {0}") @@ -223,30 +223,30 @@ MSG_DEF(JSMSG_TOO_MANY_CATCH_VARS, 169, 0, JSEXN_SYNTAXERR, "too many catch v MSG_DEF(JSMSG_NEGATIVE_REPETITION_COUNT, 170, 0, JSEXN_RANGEERR, "repeat count must be non-negative") MSG_DEF(JSMSG_INVALID_FOR_OF_INIT, 171, 0, JSEXN_SYNTAXERR, "for-of loop variable declaration may not have an initializer") MSG_DEF(JSMSG_INVALID_MAP_ITERABLE, 172, 0, JSEXN_TYPEERR, "iterable for map should have array-like objects") -MSG_DEF(JSMSG_UNUSED173, 173, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED174, 174, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_NOT_A_CODEPOINT, 173, 1, JSEXN_RANGEERR, "{0} is not a valid code point") +MSG_DEF(JSMSG_BRACKET_AFTER_ARRAY_COMPREHENSION, 174, 0, JSEXN_SYNTAXERR, "missing ] after array comprehension") MSG_DEF(JSMSG_NESTING_GENERATOR, 175, 0, JSEXN_TYPEERR, "already executing generator") -MSG_DEF(JSMSG_UNUSED176, 176, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED177, 177, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED178, 178, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED179, 179, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED180, 180, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED181, 181, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_PAREN_AFTER_FOR_OF_ITERABLE, 176, 0, JSEXN_SYNTAXERR, "missing ) after for-of iterable") +MSG_DEF(JSMSG_INVALID_NORMALIZE_FORM, 177, 0, JSEXN_RANGEERR, "form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD'") +MSG_DEF(JSMSG_NOTHING_TO_REPEAT, 178, 0, JSEXN_SYNTAXERR, "nothing to repeat") +MSG_DEF(JSMSG_INVALID_GROUP, 179, 0, JSEXN_SYNTAXERR, "invalid regexp group") +MSG_DEF(JSMSG_ESCAPE_AT_END_OF_REGEXP, 180, 0, JSEXN_SYNTAXERR, "\\ at end of pattern") +MSG_DEF(JSMSG_NUMBERS_OUT_OF_ORDER, 181, 0, JSEXN_SYNTAXERR, "numbers out of order in {} quantifier.") MSG_DEF(JSMSG_BAD_GENERATOR_SEND, 182, 1, JSEXN_TYPEERR, "attempt to send {0} to newborn generator") MSG_DEF(JSMSG_SC_NOT_TRANSFERABLE, 183, 0, JSEXN_TYPEERR, "invalid transferable array for structured clone") MSG_DEF(JSMSG_SC_DUP_TRANSFERABLE, 184, 0, JSEXN_TYPEERR, "duplicate transferable for structured clone") MSG_DEF(JSMSG_CANT_REPORT_AS_NON_EXTENSIBLE, 185, 0, JSEXN_TYPEERR, "proxy can't report an extensible object as non-extensible") -MSG_DEF(JSMSG_UNUSED186, 186, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_SYMBOL_TO_STRING, 186, 0, JSEXN_TYPEERR, "can't convert symbol to string") MSG_DEF(JSMSG_UNUSED187, 187, 0, JSEXN_NONE, "") MSG_DEF(JSMSG_INCOMPATIBLE_METHOD, 188, 3, JSEXN_TYPEERR, "{0} {1} called on incompatible {2}") -MSG_DEF(JSMSG_UNUSED189, 189, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_SYMBOL_TO_PRIMITIVE, 189, 0, JSEXN_TYPEERR, "can't convert symbol object to primitive") MSG_DEF(JSMSG_UNUSED190, 190, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED191, 191, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED192, 192, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_BAD_INDEX, 191, 0, JSEXN_RANGEERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_SELFHOSTED_TOP_LEVEL_LET,192,0, JSEXN_SYNTAXERR, "self-hosted code cannot contain top-level 'let' declarations") MSG_DEF(JSMSG_BAD_FOR_EACH_LOOP, 193, 0, JSEXN_SYNTAXERR, "invalid for each loop") -MSG_DEF(JSMSG_OBJECT_WATCH_DEPRECATED,194, 0, JSEXN_TYPEERR, "Object.prototype.watch and unwatch are very slow, non-standard, and deprecated; use a getter/setter instead") -MSG_DEF(JSMSG_UNUSED195, 195, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED196, 196, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_OBJECT_WATCH_DEPRECATED,194, 0, JSEXN_NONE, "Object.prototype.watch and unwatch are very slow, non-standard, and deprecated; use a getter/setter instead") +MSG_DEF(JSMSG_TYPE_ERR_BAD_ARGS, 195, 0, JSEXN_TYPEERR, "invalid arguments") +MSG_DEF(JSMSG_REDECLARED_CATCH_IDENTIFIER, 196, 1, JSEXN_TYPEERR, "redeclaration of identifier '{0}' in catch") MSG_DEF(JSMSG_INTERNAL_INTL_ERROR, 197, 0, JSEXN_ERR, "internal error while computing Intl data") MSG_DEF(JSMSG_DEFAULT_LOCALE_ERROR, 198, 0, JSEXN_ERR, "internal error getting the default locale") MSG_DEF(JSMSG_TOO_MANY_LOCALS, 199, 0, JSEXN_SYNTAXERR, "too many local variables") @@ -260,25 +260,25 @@ MSG_DEF(JSMSG_USER_DEFINED_ERROR, 206, 0, JSEXN_ERR, "JS_ReportError was cal MSG_DEF(JSMSG_WRONG_CONSTRUCTOR, 207, 1, JSEXN_TYPEERR, "wrong constructor called for {0}") MSG_DEF(JSMSG_BAD_GENERATOR_RETURN, 208, 1, JSEXN_TYPEERR, "generator function {0} returns a value") MSG_DEF(JSMSG_BAD_ANON_GENERATOR_RETURN, 209, 0, JSEXN_TYPEERR, "anonymous generator function returns a value") -MSG_DEF(JSMSG_UNUSED210, 210, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_PROTO_SETTING_SLOW, 210, 0, JSEXN_NONE, "mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create") MSG_DEF(JSMSG_IN_AFTER_FOR_NAME, 211, 0, JSEXN_SYNTAXERR, "missing 'in' or 'of' after for") MSG_DEF(JSMSG_BAD_TRAP_RETURN_VALUE, 212, 2, JSEXN_TYPEERR,"trap {1} for {0} returned a primitive value") -MSG_DEF(JSMSG_UNUSED213, 213, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_OF_AFTER_FOR_NAME, 213, 0, JSEXN_SYNTAXERR, "missing 'of' after for") MSG_DEF(JSMSG_BAD_GENERATOR_YIELD, 214, 1, JSEXN_TYPEERR, "yield from closing generator {0}") MSG_DEF(JSMSG_BAD_GENERATOR_SYNTAX, 215, 1, JSEXN_SYNTAXERR, "{0} expression must be parenthesized") MSG_DEF(JSMSG_ARRAY_COMP_LEFTSIDE, 216, 0, JSEXN_SYNTAXERR, "invalid array comprehension left-hand side") -MSG_DEF(JSMSG_UNUSED217, 217, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_LET_COMP_BINDING, 217, 0, JSEXN_SYNTAXERR, "'let' is not a valid name for a comprehension variable") MSG_DEF(JSMSG_EMPTY_ARRAY_REDUCE, 218, 0, JSEXN_TYPEERR, "reduce of empty array with no initial value") MSG_DEF(JSMSG_BAD_SYMBOL, 219, 1, JSEXN_TYPEERR, "{0} is not a well-known @@-symbol") MSG_DEF(JSMSG_BAD_DELETE_OPERAND, 220, 0, JSEXN_REFERENCEERR, "invalid delete operand") MSG_DEF(JSMSG_BAD_INCOP_OPERAND, 221, 0, JSEXN_REFERENCEERR, "invalid increment/decrement operand") MSG_DEF(JSMSG_UNEXPECTED_TYPE, 222, 2, JSEXN_TYPEERR, "{0} is {1}") MSG_DEF(JSMSG_LET_DECL_NOT_IN_BLOCK, 223, 0, JSEXN_SYNTAXERR, "let declaration not directly within block") -MSG_DEF(JSMSG_BAD_OBJECT_INIT, 224, 0, JSEXN_SYNTAXERR, "invalid object initializer") +MSG_DEF(JSMSG_UNUSED224, 224, 0, JSEXN_NONE, "") MSG_DEF(JSMSG_CANT_SET_ARRAY_ATTRS, 225, 0, JSEXN_INTERNALERR, "can't set attributes on indexed array properties") MSG_DEF(JSMSG_EVAL_ARITY, 226, 0, JSEXN_TYPEERR, "eval accepts only one parameter") MSG_DEF(JSMSG_MISSING_FUN_ARG, 227, 2, JSEXN_TYPEERR, "missing argument {0} when calling function {1}") -MSG_DEF(JSMSG_JSON_BAD_PARSE, 228, 1, JSEXN_SYNTAXERR, "JSON.parse: {0}") +MSG_DEF(JSMSG_JSON_BAD_PARSE, 228, 3, JSEXN_SYNTAXERR, "JSON.parse: {0} at line {1} column {2} of the JSON data") MSG_DEF(JSMSG_JSON_BAD_STRINGIFY, 229, 0, JSEXN_ERR, "JSON.stringify") MSG_DEF(JSMSG_NOT_CALLABLE_OR_UNDEFINED, 230, 0, JSEXN_TYPEERR, "value is not a function or undefined") MSG_DEF(JSMSG_NOT_NONNULL_OBJECT, 231, 0, JSEXN_TYPEERR, "value is not a non-null object") @@ -353,11 +353,11 @@ MSG_DEF(JSMSG_REST_WITH_DEFAULT, 299, 0, JSEXN_SYNTAXERR, "rest parameter m MSG_DEF(JSMSG_NONDEFAULT_FORMAL_AFTER_DEFAULT, 300, 0, JSEXN_SYNTAXERR, "parameter(s) with default followed by parameter without default") MSG_DEF(JSMSG_YIELD_IN_DEFAULT, 301, 0, JSEXN_SYNTAXERR, "yield in default expression") MSG_DEF(JSMSG_INTRINSIC_NOT_DEFINED, 302, 1, JSEXN_REFERENCEERR, "no intrinsic function {0}") -MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 303, 2, JSEXN_ERR, "{0} is being assigned a {1}, but already has one") -MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 304, 1, JSEXN_RANGEERR, "invalid ParallelArray{0} argument") -MSG_DEF(JSMSG_PAR_ARRAY_BAD_PARTITION, 305, 0, JSEXN_ERR, "argument must be divisible by outermost dimension") -MSG_DEF(JSMSG_PAR_ARRAY_REDUCE_EMPTY, 306, 0, JSEXN_ERR, "cannot reduce ParallelArray object whose outermost dimension is empty") -MSG_DEF(JSMSG_PAR_ARRAY_ALREADY_FLAT, 307, 0, JSEXN_ERR, "cannot flatten 1-dimensional ParallelArray object") +MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 303, 2, JSEXN_NONE, "{0} is being assigned a {1}, but already has one") +MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 304, 0, JSEXN_RANGEERR, "invalid parallel method argument") +MSG_DEF(JSMSG_REGEXP_RUNTIME_ERROR, 305, 0, JSEXN_INTERNALERR, "an error occurred while executing regular expression") +MSG_DEF(JSMSG_DEBUG_OPTIMIZED_OUT, 306, 0, JSEXN_ERR, "variable has been optimized out") +MSG_DEF(JSMSG_NEXT_RETURNED_PRIMITIVE,307, 0, JSEXN_TYPEERR, "iterator.next() returned a non-object value") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_CONFLICT, 308, 0, JSEXN_ERR, "no conflict resolution function provided") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BOUNDS, 309, 0, JSEXN_ERR, "index in scatter vector out of bounds") MSG_DEF(JSMSG_CANT_REPORT_NC_AS_NE, 310, 0, JSEXN_TYPEERR, "proxy can't report a non-configurable own property as non-existent") @@ -391,13 +391,13 @@ MSG_DEF(JSMSG_DATE_NOT_FINITE, 337, 0, JSEXN_RANGEERR, "date value is not MSG_DEF(JSMSG_USE_ASM_DIRECTIVE_FAIL, 338, 0, JSEXN_SYNTAXERR, "\"use asm\" is only meaningful in the Directive Prologue of a function body") MSG_DEF(JSMSG_USE_ASM_TYPE_FAIL, 339, 1, JSEXN_TYPEERR, "asm.js type error: {0}") MSG_DEF(JSMSG_USE_ASM_LINK_FAIL, 340, 1, JSEXN_TYPEERR, "asm.js link error: {0}") -MSG_DEF(JSMSG_USE_ASM_TYPE_OK, 341, 1, JSEXN_ERR, "successfully compiled asm.js code ({0})") +MSG_DEF(JSMSG_USE_ASM_TYPE_OK, 341, 1, JSEXN_NONE, "Successfully compiled asm.js code ({0})") MSG_DEF(JSMSG_BAD_ARROW_ARGS, 342, 0, JSEXN_SYNTAXERR, "invalid arrow-function arguments (parentheses around the arrow-function may help)") MSG_DEF(JSMSG_YIELD_IN_ARROW, 343, 0, JSEXN_SYNTAXERR, "arrow function may not contain yield") MSG_DEF(JSMSG_WRONG_VALUE, 344, 2, JSEXN_ERR, "expected {0} but found {1}") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BAD_TARGET, 345, 1, JSEXN_ERR, "target for index {0} is not an integer") MSG_DEF(JSMSG_SELFHOSTED_UNBOUND_NAME,346, 0, JSEXN_TYPEERR, "self-hosted code may not contain unbound name lookups") -MSG_DEF(JSMSG_DEPRECATED_PRAGMA, 347, 1, JSEXN_SYNTAXERR, "Using //@ to indicate {0} pragmas is deprecated. Use //# instead") +MSG_DEF(JSMSG_DEPRECATED_PRAGMA, 347, 1, JSEXN_NONE, "Using //@ to indicate {0} pragmas is deprecated. Use //# instead") MSG_DEF(JSMSG_BAD_DESTRUCT_ASSIGN, 348, 1, JSEXN_SYNTAXERR, "can't assign to {0} using destructuring assignment") MSG_DEF(JSMSG_TYPEDOBJECT_ARRAYTYPE_BAD_ARGS, 349, 0, JSEXN_ERR, "Invalid arguments") MSG_DEF(JSMSG_TYPEDOBJECT_BINARYARRAY_BAD_INDEX, 350, 0, JSEXN_RANGEERR, "invalid or out-of-range index") @@ -414,7 +414,7 @@ MSG_DEF(JSMSG_TOO_MANY_FUN_SPREADARGS, 360, 0, JSEXN_RANGEERR, "too many functio MSG_DEF(JSMSG_DEBUG_NOT_DEBUGGEE, 361, 2, JSEXN_ERR, "{0} is not a debuggee {1}") MSG_DEF(JSMSG_TYPEDOBJECT_NOT_TYPED_OBJECT, 362, 0, JSEXN_ERR, "Expected a typed object") MSG_DEF(JSMSG_TYPEDOBJECT_NO_SUCH_PROP, 363, 1, JSEXN_TYPEERR, "No such property: {0}") -MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_BAD_ARGS, 364, 2, JSEXN_TYPEERR, "argument {0} invalid: expected {1}") +MSG_DEF(JSMSG_TYPEDOBJECT_BAD_ARGS, 364, 0, JSEXN_TYPEERR, "invalid arguments") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_UNATTACHED, 365, 0, JSEXN_TYPEERR, "handle unattached") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_BAD_TYPE, 366, 0, JSEXN_TYPEERR, "handle moved to destination of incorrect type") @@ -433,3 +433,11 @@ MSG_DEF(JSMSG_NO_EXPORT_NAME, 378, 0, JSEXN_SYNTAXERR, "missing export MSG_DEF(JSMSG_DECLARATION_AFTER_EXPORT, 379, 0, JSEXN_SYNTAXERR, "missing declaration after 'export' keyword") MSG_DEF(JSMSG_INVALID_PROTOTYPE, 380, 0, JSEXN_TYPEERR, "prototype field is not an object") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_TO_UNSIZED, 381, 0, JSEXN_TYPEERR, "cannot create a handle to an unsized type") +MSG_DEF(JSMSG_SETPROTOTYPEOF_FAIL, 382, 1, JSEXN_TYPEERR, "[[SetPrototypeOf]] failed on {0}") +MSG_DEF(JSMSG_INVALID_ARG_TYPE, 383, 3, JSEXN_TYPEERR, "Invalid type: {0} can't be a{1} {2}") +MSG_DEF(JSMSG_TERMINATED, 384, 1, JSEXN_ERR, "Script terminated by timeout at:\n{0}") +MSG_DEF(JSMSG_NO_SUCH_SELF_HOSTED_PROP, 385, 1, JSEXN_ERR, "No such property on self-hosted object: {0}") +MSG_DEF(JSMSG_PROXY_EXTENSIBILITY, 386, 0, JSEXN_TYPEERR, "proxy must report same extensiblitity as target") +MSG_DEF(JSMSG_PROXY_CONSTRUCT_OBJECT, 387, 0, JSEXN_TYPEERR, "proxy [[Construct]] must return an object") +MSG_DEF(JSMSG_PROXY_GETOWN_OBJORUNDEF, 388, 0, JSEXN_TYPEERR, "proxy [[GetOwnProperty]] must return an object or undefined") +MSG_DEF(JSMSG_CANT_REPORT_C_AS_NC, 389, 0, JSEXN_TYPEERR, "proxy can't report existing configurable property as non-configurable") diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/CallArgs.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/CallArgs.h index 5c7a201101..3be3f1575a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/CallArgs.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/CallArgs.h @@ -44,7 +44,7 @@ typedef bool /* Typedef for native functions that may be called in parallel. */ typedef bool -(* JSParallelNative)(js::ForkJoinSlice *slice, unsigned argc, JS::Value *vp); +(* JSParallelNative)(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); /* * Typedef for native functions that may be called either in parallel or @@ -63,7 +63,7 @@ JSNativeThreadSafeWrapper(JSContext *cx, unsigned argc, JS::Value *vp); template inline bool -JSParallelNativeThreadSafeWrapper(js::ForkJoinSlice *slice, unsigned argc, JS::Value *vp); +JSParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); /* * Compute |this| for the |vp| inside a JSNative, either boxing primitives or @@ -118,7 +118,7 @@ extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; namespace detail { -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_PUBLIC_API(void) CheckIsValidConstructible(Value v); #endif @@ -147,7 +147,7 @@ class MOZ_STACK_CLASS UsedRvalBase template class MOZ_STACK_CLASS CallReceiverBase : public UsedRvalBase< -#ifdef DEBUG +#ifdef JS_DEBUG WantUsedRval #else NoUsedRval @@ -197,7 +197,7 @@ class MOZ_STACK_CLASS CallReceiverBase : public UsedRvalBase< } bool isConstructing() const { -#ifdef DEBUG +#ifdef JS_DEBUG if (this->usedRval_) CheckIsValidConstructible(calleev()); #endif @@ -388,11 +388,7 @@ CallArgsFromSp(unsigned argc, Value *sp) * take a const JS::CallArgs&. */ -#define JS_CALLEE(cx,vp) ((vp)[0]) -#define JS_THIS_OBJECT(cx,vp) (JSVAL_TO_OBJECT(JS_THIS(cx,vp))) -#define JS_ARGV(cx,vp) ((vp) + 2) -#define JS_RVAL(cx,vp) (*(vp)) -#define JS_SET_RVAL(cx,vp,v) (*(vp) = (v)) +#define JS_THIS_OBJECT(cx,vp) (JS_THIS(cx,vp).toObjectOrNull()) /* * Note: if this method returns null, an error has occurred and must be @@ -401,7 +397,7 @@ CallArgsFromSp(unsigned argc, Value *sp) MOZ_ALWAYS_INLINE JS::Value JS_THIS(JSContext *cx, JS::Value *vp) { - return JSVAL_IS_PRIMITIVE(vp[1]) ? JS_ComputeThis(cx, vp) : vp[1]; + return vp[1].isPrimitive() ? JS_ComputeThis(cx, vp) : vp[1]; } /* diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/CallNonGenericMethod.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/CallNonGenericMethod.h index 05097f0294..ad9a7f708c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/CallNonGenericMethod.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/CallNonGenericMethod.h @@ -14,7 +14,7 @@ namespace JS { // Returns true if |v| is considered an acceptable this-value. -typedef bool (*IsAcceptableThis)(Handle v); +typedef bool (*IsAcceptableThis)(HandleValue v); // Implements the guts of a method; guaranteed to be provided an acceptable // this-value, as determined by a corresponding IsAcceptableThis method. @@ -92,7 +92,7 @@ CallMethodIfWrapped(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallA // tail position in a JSNative. Do not call it from any other place. // template -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool CallNonGenericMethod(JSContext *cx, CallArgs args) { HandleValue thisv = args.thisv(); @@ -102,7 +102,7 @@ CallNonGenericMethod(JSContext *cx, CallArgs args) return detail::CallMethodIfWrapped(cx, Test, Impl, args); } -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool CallNonGenericMethod(JSContext *cx, IsAcceptableThis Test, NativeImpl Impl, CallArgs args) { HandleValue thisv = args.thisv(); diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/CharacterEncoding.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/CharacterEncoding.h index 7918b83484..45c77761b3 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/CharacterEncoding.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/CharacterEncoding.h @@ -17,6 +17,8 @@ namespace js { struct ThreadSafeContext; } +class JSFlatString; + namespace JS { /* @@ -25,40 +27,45 @@ namespace JS { * byte is treated as a 2-byte character, and there is no way to pass in a * string containing characters beyond U+00FF. */ -class Latin1Chars : public mozilla::Range +class Latin1Chars : public mozilla::Range { - typedef mozilla::Range Base; + typedef mozilla::Range Base; public: Latin1Chars() : Base() {} - Latin1Chars(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) {} + Latin1Chars(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) {} + Latin1Chars(const Latin1Char *aBytes, size_t aLength) + : Base(const_cast(aBytes), aLength) + {} Latin1Chars(const char *aBytes, size_t aLength) - : Base(reinterpret_cast(const_cast(aBytes)), aLength) + : Base(reinterpret_cast(const_cast(aBytes)), aLength) {} }; /* * A Latin1Chars, but with \0 termination for C compatibility. */ -class Latin1CharsZ : public mozilla::RangedPtr +class Latin1CharsZ : public mozilla::RangedPtr { - typedef mozilla::RangedPtr Base; + typedef mozilla::RangedPtr Base; public: Latin1CharsZ() : Base(nullptr, 0) {} Latin1CharsZ(char *aBytes, size_t aLength) - : Base(reinterpret_cast(aBytes), aLength) + : Base(reinterpret_cast(aBytes), aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } - Latin1CharsZ(unsigned char *aBytes, size_t aLength) + Latin1CharsZ(Latin1Char *aBytes, size_t aLength) : Base(aBytes, aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } + using Base::operator=; + char *c_str() { return reinterpret_cast(get()); } }; @@ -89,15 +96,17 @@ class UTF8CharsZ : public mozilla::RangedPtr UTF8CharsZ(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } UTF8CharsZ(unsigned char *aBytes, size_t aLength) : Base(aBytes, aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } + using Base::operator=; + char *c_str() { return reinterpret_cast(get()); } }; @@ -119,21 +128,6 @@ class TwoByteChars : public mozilla::Range TwoByteChars(const jschar *aChars, size_t aLength) : Base(const_cast(aChars), aLength) {} }; -/* - * A non-convertible variant of TwoByteChars that does not refer to characters - * inlined inside a JSShortString or a JSInlineString. StableTwoByteChars are - * thus safe to hold across a GC. - */ -class StableTwoByteChars : public mozilla::Range -{ - typedef mozilla::Range Base; - - public: - StableTwoByteChars() : Base() {} - StableTwoByteChars(jschar *aChars, size_t aLength) : Base(aChars, aLength) {} - StableTwoByteChars(const jschar *aChars, size_t aLength) : Base(const_cast(aChars), aLength) {} -}; - /* * A TwoByteChars, but \0 terminated for compatibility with JSFlatString. */ @@ -147,10 +141,31 @@ class TwoByteCharsZ : public mozilla::RangedPtr TwoByteCharsZ(jschar *chars, size_t length) : Base(chars, length) { - JS_ASSERT(chars[length] == '\0'); + MOZ_ASSERT(chars[length] == '\0'); } + + using Base::operator=; }; +typedef mozilla::RangedPtr ConstCharPtr; + +/* + * Like TwoByteChars, but the chars are const. + */ +class ConstTwoByteChars : public mozilla::RangedPtr +{ + public: + ConstTwoByteChars(const ConstTwoByteChars &s) : ConstCharPtr(s) {} + MOZ_IMPLICIT ConstTwoByteChars(const mozilla::RangedPtr &s) : ConstCharPtr(s) {} + ConstTwoByteChars(const jschar *s, size_t len) : ConstCharPtr(s, len) {} + ConstTwoByteChars(const jschar *pos, const jschar *start, size_t len) + : ConstCharPtr(pos, start, len) + {} + + using ConstCharPtr::operator=; +}; + + /* * Convert a 2-byte character sequence to "ISO-Latin-1". This works by * truncating each 2-byte pair in the sequence to a 1-byte pair. If the source @@ -162,10 +177,12 @@ class TwoByteCharsZ : public mozilla::RangedPtr * This method cannot trigger GC. */ extern Latin1CharsZ -LossyTwoByteCharsToNewLatin1CharsZ(js::ThreadSafeContext *cx, TwoByteChars tbchars); +LossyTwoByteCharsToNewLatin1CharsZ(js::ThreadSafeContext *cx, + const mozilla::Range tbchars); +template extern UTF8CharsZ -TwoByteCharsToNewUTF8CharsZ(js::ThreadSafeContext *cx, TwoByteChars tbchars); +CharsToNewUTF8CharsZ(js::ThreadSafeContext *cx, const mozilla::Range chars); uint32_t Utf8ToOneUcs4Char(const uint8_t *utf8Buffer, int utf8Length); @@ -187,6 +204,20 @@ UTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen) extern TwoByteCharsZ LossyUTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen); +/* + * Returns the length of the char buffer required to encode |s| as UTF8. + * Does not include the null-terminator. + */ +JS_PUBLIC_API(size_t) +GetDeflatedUTF8StringLength(JSFlatString *s); + +/* + * Encode |src| as UTF8. The caller must ensure |dst| has enough space. + * Does not write the null terminator. + */ +JS_PUBLIC_API(void) +DeflateStringToUTF8Buffer(JSFlatString *src, mozilla::RangedPtr dst); + } // namespace JS inline void JS_free(JS::Latin1CharsZ &ptr) { js_free((void*)ptr.get()); } diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/Class.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/Class.h index b908fe1604..559cc65c85 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/Class.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/Class.h @@ -24,126 +24,20 @@ * object behavior and, e.g., allows custom slow layout. */ -class JSFreeOp; +struct JSFreeOp; +struct JSFunctionSpec; namespace js { -class Class; +struct Class; class FreeOp; -class PropertyId; class PropertyName; class Shape; -class SpecialId; // This is equal to JSFunction::class_. Use it in places where you don't want // to #include jsfun.h. extern JS_FRIEND_DATA(const js::Class* const) FunctionClassPtr; -static JS_ALWAYS_INLINE jsid -SPECIALID_TO_JSID(const SpecialId &sid); - -/* - * We partition the ways to refer to a property into three: by an index - * (uint32_t); by a string whose characters do not represent an index - * (PropertyName, see vm/String.h); and by various special values. - * - * Special values are encoded using SpecialId, which is layout-compatible but - * non-interconvertible with jsid. A SpecialId is used for JSID_VOID, which - * does not occur in JS scripts but may be used to indicate the absence of a - * valid identifier. In the future, a SpecialId may also be an object used by - * Harmony-proposed private names. - */ -class SpecialId -{ - uintptr_t bits_; - - /* Needs access to raw bits. */ - friend JS_ALWAYS_INLINE jsid SPECIALID_TO_JSID(const SpecialId &sid); - friend class PropertyId; - - static const uintptr_t TYPE_VOID = JSID_TYPE_VOID; - static const uintptr_t TYPE_OBJECT = JSID_TYPE_OBJECT; - static const uintptr_t TYPE_MASK = JSID_TYPE_MASK; - - SpecialId(uintptr_t bits) : bits_(bits) { } - - public: - SpecialId() : bits_(TYPE_VOID) { } - - /* Object-valued */ - - SpecialId(JSObject &obj) - : bits_(uintptr_t(&obj) | TYPE_OBJECT) - { - JS_ASSERT(&obj != nullptr); - JS_ASSERT((uintptr_t(&obj) & TYPE_MASK) == 0); - } - - bool isObject() const { - return (bits_ & TYPE_MASK) == TYPE_OBJECT && bits_ != TYPE_OBJECT; - } - - JSObject *toObject() const { - JS_ASSERT(isObject()); - return reinterpret_cast(bits_ & ~TYPE_MASK); - } - - /* Empty */ - - static SpecialId empty() { - SpecialId sid(TYPE_OBJECT); - JS_ASSERT(sid.isEmpty()); - return sid; - } - - bool isEmpty() const { - return bits_ == TYPE_OBJECT; - } - - /* Void */ - - static SpecialId voidId() { - SpecialId sid(TYPE_VOID); - JS_ASSERT(sid.isVoid()); - return sid; - } - - bool isVoid() const { - return bits_ == TYPE_VOID; - } -}; - -static JS_ALWAYS_INLINE jsid -SPECIALID_TO_JSID(const SpecialId &sid) -{ - jsid id; - JSID_BITS(id) = sid.bits_; - JS_ASSERT_IF(sid.isObject(), JSID_IS_OBJECT(id) && JSID_TO_OBJECT(id) == sid.toObject()); - JS_ASSERT_IF(sid.isVoid(), JSID_IS_VOID(id)); - JS_ASSERT_IF(sid.isEmpty(), JSID_IS_EMPTY(id)); - return id; -} - -static JS_ALWAYS_INLINE bool -JSID_IS_SPECIAL(jsid id) -{ - return JSID_IS_OBJECT(id) || JSID_IS_EMPTY(id) || JSID_IS_VOID(id); -} - -static JS_ALWAYS_INLINE SpecialId -JSID_TO_SPECIALID(jsid id) -{ - JS_ASSERT(JSID_IS_SPECIAL(id)); - if (JSID_IS_OBJECT(id)) - return SpecialId(*JSID_TO_OBJECT(id)); - if (JSID_IS_EMPTY(id)) - return SpecialId::empty(); - JS_ASSERT(JSID_IS_VOID(id)); - return SpecialId::voidId(); -} - -typedef JS::Handle HandleSpecialId; - } // namespace js // JSClass operation signatures. @@ -152,8 +46,8 @@ typedef JS::Handle HandleSpecialId; // be a string (Unicode property identifier) or an int (element index). The // *vp out parameter, on success, is the new property value after the action. typedef bool -(* JSPropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - JS::MutableHandle vp); +(* JSPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); // Set a property named by id in obj, treating the assignment as strict // mode code if strict is true. Note the jsid id type -- id may be a string @@ -161,8 +55,8 @@ typedef bool // parameter, on success, is the new property value after the // set. typedef bool -(* JSStrictPropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - bool strict, JS::MutableHandle vp); +(* JSStrictPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool strict, JS::MutableHandleValue vp); // Delete a property named by id in obj. // @@ -178,7 +72,7 @@ typedef bool // property, or an inherited property, is allowed -- it's just pointless), // set *succeeded to true and return true. typedef bool -(* JSDeletePropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, +(* JSDeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); // This function type is used for callbacks that enumerate the properties of @@ -212,13 +106,13 @@ typedef bool // The return value is used to indicate success, with a value of false // indicating failure. typedef bool -(* JSNewEnumerateOp)(JSContext *cx, JS::Handle obj, JSIterateOp enum_op, - JS::MutableHandle statep, JS::MutableHandle idp); +(* JSNewEnumerateOp)(JSContext *cx, JS::HandleObject obj, JSIterateOp enum_op, + JS::MutableHandleValue statep, JS::MutableHandleId idp); // The old-style JSClass.enumerate op should define all lazy properties not // yet reflected in obj. typedef bool -(* JSEnumerateOp)(JSContext *cx, JS::Handle obj); +(* JSEnumerateOp)(JSContext *cx, JS::HandleObject obj); // Resolve a lazy property named by id in obj by defining it directly in obj. // Lazy properties are those reflected from some peer native property space @@ -231,27 +125,24 @@ typedef bool // // NB: JSNewResolveOp provides a cheaper way to resolve lazy properties. typedef bool -(* JSResolveOp)(JSContext *cx, JS::Handle obj, JS::Handle id); +(* JSResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); -// Like JSResolveOp, but flags provide contextual information as follows: -// -// JSRESOLVE_ASSIGNING obj[id] is on the left-hand side of an assignment -// -// The *objp out parameter, on success, should be null to indicate that id -// was not resolved; and non-null, referring to obj or one of its prototypes, -// if id was resolved. The hook may assume *objp is null on entry. +// Like JSResolveOp, except the *objp out parameter, on success, should be null +// to indicate that id was not resolved; and non-null, referring to obj or one +// of its prototypes, if id was resolved. The hook may assume *objp is null on +// entry. // // This hook instead of JSResolveOp is called via the JSClass.resolve member // if JSCLASS_NEW_RESOLVE is set in JSClass.flags. typedef bool -(* JSNewResolveOp)(JSContext *cx, JS::Handle obj, JS::Handle id, unsigned flags, - JS::MutableHandle objp); +(* JSNewResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleObject objp); // Convert obj to the given type, returning true with the resulting value in // *vp on success, and returning false on error or exception. typedef bool -(* JSConvertOp)(JSContext *cx, JS::Handle obj, JSType type, - JS::MutableHandle vp); +(* JSConvertOp)(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); // Finalize obj, which the garbage collector has determined to be unreachable // from other live objects or from GC roots. Obviously, finalizers must never @@ -264,25 +155,11 @@ struct JSStringFinalizer { void (*finalize)(const JSStringFinalizer *fin, jschar *chars); }; -// JSClass.checkAccess type: check whether obj[id] may be accessed per mode, -// returning false on error/exception, true on success with obj[id]'s last-got -// value in *vp, and its attributes in *attrsp. As for JSPropertyOp above, id -// is either a string or an int jsval. -typedef bool -(* JSCheckAccessOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - JSAccessMode mode, JS::MutableHandle vp); - -// Return whether the first principal subsumes the second. The exact meaning of -// 'subsumes' is left up to the browser. Subsumption is checked inside the JS -// engine when determining, e.g., which stack frames to display in a backtrace. -typedef bool -(* JSSubsumesOp)(JSPrincipals *first, JSPrincipals *second); - // Check whether v is an instance of obj. Return false on error or exception, // true on success with true in *bp if v is an instance of obj, false in // *bp otherwise. typedef bool -(* JSHasInstanceOp)(JSContext *cx, JS::Handle obj, JS::MutableHandle vp, +(* JSHasInstanceOp)(JSContext *cx, JS::HandleObject obj, JS::MutableHandleValue vp, bool *bp); // Function type for trace operation of the class called to enumerate all @@ -300,11 +177,6 @@ typedef bool typedef void (* JSTraceOp)(JSTracer *trc, JSObject *obj); -// A generic type for functions mapping an object to another object, or null -// if an error or exception was thrown on cx. -typedef JSObject * -(* JSObjectOp)(JSContext *cx, JS::Handle obj); - // Hook that creates an iterator object for a given object. Returns the // iterator object or null if an error or exception was thrown on cx. typedef JSObject * @@ -327,9 +199,6 @@ typedef bool (* LookupElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleObject objp, JS::MutableHandle propp); typedef bool -(* LookupSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::MutableHandleObject objp, JS::MutableHandle propp); -typedef bool (* DefineGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); typedef bool @@ -340,10 +209,6 @@ typedef bool (* DefineElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); typedef bool -(* DefineSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); -typedef bool (* GenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, JS::MutableHandleValue vp); typedef bool @@ -353,12 +218,6 @@ typedef bool (* ElementIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, JS::MutableHandleValue vp); typedef bool -(* ElementIfPresentOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, - uint32_t index, JS::MutableHandleValue vp, bool* present); -typedef bool -(* SpecialIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, - HandleSpecialId sid, JS::MutableHandleValue vp); -typedef bool (* StrictGenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, bool strict); typedef bool @@ -368,20 +227,12 @@ typedef bool (* StrictElementIdOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp, bool strict); typedef bool -(* StrictSpecialIdOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::MutableHandleValue vp, bool strict); -typedef bool (* GenericAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); typedef bool (* PropertyAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, unsigned *attrsp); typedef bool -(* DeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, - bool *succeeded); -typedef bool -(* DeleteElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded); -typedef bool -(* DeleteSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, bool *succeeded); +(* DeleteGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); typedef bool (* WatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); @@ -389,12 +240,23 @@ typedef bool typedef bool (* UnwatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); +typedef bool +(* SliceOp)(JSContext *cx, JS::HandleObject obj, uint32_t begin, uint32_t end, + JS::HandleObject result); // result is actually preallocted. + +// A generic type for functions mapping an object to another object, or null +// if an error or exception was thrown on cx. typedef JSObject * (* ObjectOp)(JSContext *cx, JS::HandleObject obj); + +// Hook to map an object to its inner object. Infallible. +typedef JSObject * +(* InnerObjectOp)(JSObject *obj); + typedef void (* FinalizeOp)(FreeOp *fop, JSObject *obj); -#define JS_CLASS_MEMBERS \ +#define JS_CLASS_MEMBERS(FinalizeOpType) \ const char *name; \ uint32_t flags; \ \ @@ -408,26 +270,34 @@ typedef void JSConvertOp convert; \ \ /* Optional members (may be null). */ \ - FinalizeOp finalize; \ - JSCheckAccessOp checkAccess; \ + FinalizeOpType finalize; \ JSNative call; \ JSHasInstanceOp hasInstance; \ JSNative construct; \ JSTraceOp trace -/* - * The helper struct to measure the size of JS_CLASS_MEMBERS to know how much - * we have to pad js::Class to match the size of JSClass. - */ -struct ClassSizeMeasurement +// Callback for the creation of constructor and prototype objects. +typedef JSObject *(*ClassObjectCreationOp)(JSContext *cx, JSProtoKey key); + +// Callback for custom post-processing after class initialization via ClassSpec. +typedef bool (*FinishClassInitOp)(JSContext *cx, JS::HandleObject ctor, + JS::HandleObject proto); + +struct ClassSpec { - JS_CLASS_MEMBERS; + ClassObjectCreationOp createConstructor; + ClassObjectCreationOp createPrototype; + const JSFunctionSpec *constructorFunctions; + const JSFunctionSpec *prototypeFunctions; + const JSPropertySpec *prototypeProperties; + FinishClassInitOp finishInit; + bool defined() const { return !!createConstructor; } }; struct ClassExtension { - JSObjectOp outerObject; - JSObjectOp innerObject; + ObjectOp outerObject; + InnerObjectOp innerObject; JSIteratorOp iteratorObject; /* @@ -450,6 +320,7 @@ struct ClassExtension JSWeakmapKeyDelegateOp weakmapKeyDelegateOp; }; +#define JS_NULL_CLASS_SPEC {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr} #define JS_NULL_CLASS_EXT {nullptr,nullptr,nullptr,false,nullptr} struct ObjectOps @@ -457,36 +328,29 @@ struct ObjectOps LookupGenericOp lookupGeneric; LookupPropOp lookupProperty; LookupElementOp lookupElement; - LookupSpecialOp lookupSpecial; DefineGenericOp defineGeneric; DefinePropOp defineProperty; DefineElementOp defineElement; - DefineSpecialOp defineSpecial; GenericIdOp getGeneric; PropertyIdOp getProperty; ElementIdOp getElement; - ElementIfPresentOp getElementIfPresent; /* can be null */ - SpecialIdOp getSpecial; StrictGenericIdOp setGeneric; StrictPropertyIdOp setProperty; StrictElementIdOp setElement; - StrictSpecialIdOp setSpecial; GenericAttributesOp getGenericAttributes; GenericAttributesOp setGenericAttributes; - DeletePropertyOp deleteProperty; - DeleteElementOp deleteElement; - DeleteSpecialOp deleteSpecial; + DeleteGenericOp deleteGeneric; WatchOp watch; UnwatchOp unwatch; - + SliceOp slice; // Optimized slice, can be null. JSNewEnumerateOp enumerate; ObjectOp thisObject; }; #define JS_NULL_OBJECT_OPS \ - {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, \ - nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, \ - nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr} + {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr} } // namespace js @@ -495,27 +359,9 @@ struct ObjectOps typedef void (*JSClassInternal)(); struct JSClass { - const char *name; - uint32_t flags; - - // Mandatory function pointer members. - JSPropertyOp addProperty; - JSDeletePropertyOp delProperty; - JSPropertyOp getProperty; - JSStrictPropertyOp setProperty; - JSEnumerateOp enumerate; - JSResolveOp resolve; - JSConvertOp convert; - - // Optional members (may be null). - JSFinalizeOp finalize; - JSCheckAccessOp checkAccess; - JSNative call; - JSHasInstanceOp hasInstance; - JSNative construct; - JSTraceOp trace; - - void *reserved[42]; + JS_CLASS_MEMBERS(JSFinalizeOp); + + void *reserved[31]; }; #define JSCLASS_HAS_PRIVATE (1<<0) // objects have private slot @@ -550,9 +396,9 @@ struct JSClass { #define JSCLASS_INTERNAL_FLAG2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2)) #define JSCLASS_INTERNAL_FLAG3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3)) -// Indicate whether the proto or ctor should be frozen. -#define JSCLASS_FREEZE_PROTO (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4)) -#define JSCLASS_FREEZE_CTOR (1<<(JSCLASS_HIGH_FLAGS_SHIFT+5)) +#define JSCLASS_IS_PROXY (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4)) + +// Bit 22 unused. // Reserved for embeddings. #define JSCLASS_USERBIT2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+6)) @@ -573,7 +419,11 @@ struct JSClass { // with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS was // previously allowed, but is now an ES5 violation and thus unsupported. // -#define JSCLASS_GLOBAL_SLOT_COUNT (3 + JSProto_LIMIT * 3 + 27) +// JSCLASS_GLOBAL_APPLICATION_SLOTS is the number of slots reserved at +// the beginning of every global object's slots for use by the +// application. +#define JSCLASS_GLOBAL_APPLICATION_SLOTS 3 +#define JSCLASS_GLOBAL_SLOT_COUNT (JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 3 + 30) #define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n) \ (JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + (n))) #define JSCLASS_GLOBAL_FLAGS \ @@ -600,11 +450,10 @@ namespace js { struct Class { - JS_CLASS_MEMBERS; + JS_CLASS_MEMBERS(FinalizeOp); + ClassSpec spec; ClassExtension ext; ObjectOps ops; - uint8_t pad[sizeof(JSClass) - sizeof(ClassSizeMeasurement) - - sizeof(ClassExtension) - sizeof(ObjectOps)]; /* Class is not native and its map is not a scope. */ static const uint32_t NON_NATIVE = JSCLASS_INTERNAL_FLAG2; @@ -621,8 +470,20 @@ struct Class return flags & JSCLASS_EMULATES_UNDEFINED; } + bool isJSFunction() const { + return this == js::FunctionClassPtr; + } + bool isCallable() const { - return this == js::FunctionClassPtr || call; + return isJSFunction() || call; + } + + bool isProxy() const { + return flags & JSCLASS_IS_PROXY; + } + + bool isDOMClass() const { + return flags & JSCLASS_IS_DOMJSCLASS; } static size_t offsetOfFlags() { return offsetof(Class, flags); } @@ -638,20 +499,19 @@ JS_STATIC_ASSERT(offsetof(JSClass, enumerate) == offsetof(Class, enumerate)); JS_STATIC_ASSERT(offsetof(JSClass, resolve) == offsetof(Class, resolve)); JS_STATIC_ASSERT(offsetof(JSClass, convert) == offsetof(Class, convert)); JS_STATIC_ASSERT(offsetof(JSClass, finalize) == offsetof(Class, finalize)); -JS_STATIC_ASSERT(offsetof(JSClass, checkAccess) == offsetof(Class, checkAccess)); JS_STATIC_ASSERT(offsetof(JSClass, call) == offsetof(Class, call)); JS_STATIC_ASSERT(offsetof(JSClass, construct) == offsetof(Class, construct)); JS_STATIC_ASSERT(offsetof(JSClass, hasInstance) == offsetof(Class, hasInstance)); JS_STATIC_ASSERT(offsetof(JSClass, trace) == offsetof(Class, trace)); JS_STATIC_ASSERT(sizeof(JSClass) == sizeof(Class)); -static JS_ALWAYS_INLINE const JSClass * +static MOZ_ALWAYS_INLINE const JSClass * Jsvalify(const Class *c) { return (const JSClass *)c; } -static JS_ALWAYS_INLINE const Class * +static MOZ_ALWAYS_INLINE const Class * Valueify(const JSClass *c) { return (const Class *)c; @@ -679,21 +539,6 @@ ObjectClassIs(JSObject &obj, ESClassValue classValue, JSContext *cx); inline bool IsObjectWithClass(const JS::Value &v, ESClassValue classValue, JSContext *cx); -inline bool -IsPoisonedSpecialId(js::SpecialId iden) -{ - if (iden.isObject()) - return JS::IsPoisonedPtr(iden.toObject()); - return false; -} - -template <> struct GCMethods -{ - static SpecialId initial() { return SpecialId(); } - static ThingRootKind kind() { return THING_ROOT_ID; } - static bool poisoned(SpecialId id) { return IsPoisonedSpecialId(id); } -}; - } /* namespace js */ #endif /* js_Class_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/GCAPI.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/GCAPI.h index 190b781060..c58d62d029 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/GCAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/GCAPI.h @@ -10,8 +10,26 @@ #include "mozilla/NullPtr.h" #include "js/HeapAPI.h" -#include "js/RootingAPI.h" -#include "js/Value.h" + +namespace js { +namespace gc { +class GCRuntime; +} +} + +typedef enum JSGCMode { + /* Perform only global GCs. */ + JSGC_MODE_GLOBAL = 0, + + /* Perform per-compartment GCs until too much garbage has accumulated. */ + JSGC_MODE_COMPARTMENT = 1, + + /* + * Collect in short time slices rather than all at once. Implies + * JSGC_MODE_COMPARTMENT. + */ + JSGC_MODE_INCREMENTAL = 2 +} JSGCMode; namespace JS { @@ -95,40 +113,117 @@ enum Reason { } /* namespace gcreason */ +/* + * Zone GC: + * + * SpiderMonkey's GC is capable of performing a collection on an arbitrary + * subset of the zones in the system. This allows an embedding to minimize + * collection time by only collecting zones that have run code recently, + * ignoring the parts of the heap that are unlikely to have changed. + * + * When triggering a GC using one of the functions below, it is first necessary + * to select the zones to be collected. To do this, you can call + * PrepareZoneForGC on each zone, or you can call PrepareForFullGC to select + * all zones. Failing to select any zone is an error. + */ + +/* + * Schedule the given zone to be collected as part of the next GC. + */ extern JS_FRIEND_API(void) PrepareZoneForGC(Zone *zone); +/* + * Schedule all zones to be collected in the next GC. + */ extern JS_FRIEND_API(void) PrepareForFullGC(JSRuntime *rt); +/* + * When performing an incremental GC, the zones that were selected for the + * previous incremental slice must be selected in subsequent slices as well. + * This function selects those slices automatically. + */ extern JS_FRIEND_API(void) PrepareForIncrementalGC(JSRuntime *rt); +/* + * Returns true if any zone in the system has been scheduled for GC with one of + * the functions above or by the JS engine. + */ extern JS_FRIEND_API(bool) IsGCScheduled(JSRuntime *rt); +/* + * Undoes the effect of the Prepare methods above. The given zone will not be + * collected in the next GC. + */ extern JS_FRIEND_API(void) SkipZoneForGC(Zone *zone); /* - * When triggering a GC using one of the functions below, it is first necessary - * to select the compartments to be collected. To do this, you can call - * PrepareZoneForGC on each compartment, or you can call PrepareForFullGC - * to select all compartments. Failing to select any compartment is an error. + * Non-Incremental GC: + * + * The following functions perform a non-incremental GC. */ +/* + * Performs a non-incremental collection of all selected zones. Some objects + * that are unreachable from the program may still be alive afterwards because + * of internal references. + */ extern JS_FRIEND_API(void) GCForReason(JSRuntime *rt, gcreason::Reason reason); +/* + * Perform a non-incremental collection after clearing caches and other + * temporary references to objects. This will remove all unreferenced objects + * in the system. + */ extern JS_FRIEND_API(void) ShrinkingGC(JSRuntime *rt, gcreason::Reason reason); -extern JS_FRIEND_API(void) -ShrinkGCBuffers(JSRuntime *rt); +/* + * Incremental GC: + * + * Incremental GC divides the full mark-and-sweep collection into multiple + * slices, allowing client JavaScript code to run between each slice. This + * allows interactive apps to avoid long collection pauses. Incremental GC does + * not make collection take less time, it merely spreads that time out so that + * the pauses are less noticable. + * + * For a collection to be carried out incrementally the following conditions + * must be met: + * - The collection must be run by calling JS::IncrementalGC() rather than + * JS_GC(). + * - The GC mode must have been set to JSGC_MODE_INCREMENTAL with + * JS_SetGCParameter(). + * - All native objects that have their own trace hook must indicate that they + * implement read and write barriers with the JSCLASS_IMPLEMENTS_BARRIERS + * flag. + * + * Note: Even if incremental GC is enabled and working correctly, + * non-incremental collections can still happen when low on memory. + */ +/* + * Begin an incremental collection and perform one slice worth of work or + * perform a slice of an ongoing incremental collection. When this function + * returns, the collection is not complete. This function must be called + * repeatedly until !IsIncrementalGCInProgress(rt). + * + * Note: SpiderMonkey's GC is not realtime. Slices in practice may be longer or + * shorter than the requested interval. + */ extern JS_FRIEND_API(void) IncrementalGC(JSRuntime *rt, gcreason::Reason reason, int64_t millis = 0); +/* + * If IsIncrementalGCInProgress(rt), this call finishes the ongoing collection + * by performing an arbitrarily long slice. If !IsIncrementalGCInProgress(rt), + * this is equivalent to GCForReason. When this function returns, + * IsIncrementalGCInProgress(rt) will always be false. + */ extern JS_FRIEND_API(void) FinishIncrementalGC(JSRuntime *rt, gcreason::Reason reason); @@ -152,7 +247,7 @@ enum GCProgress { struct JS_FRIEND_API(GCDescription) { bool isCompartment_; - GCDescription(bool isCompartment) + explicit GCDescription(bool isCompartment) : isCompartment_(isCompartment) {} jschar *formatMessage(JSRuntime *rt) const; @@ -162,37 +257,56 @@ struct JS_FRIEND_API(GCDescription) { typedef void (* GCSliceCallback)(JSRuntime *rt, GCProgress progress, const GCDescription &desc); +/* + * The GC slice callback is called at the beginning and end of each slice. This + * callback may be used for GC notifications as well as to perform additional + * marking. + */ extern JS_FRIEND_API(GCSliceCallback) SetGCSliceCallback(JSRuntime *rt, GCSliceCallback callback); /* - * Signals a good place to do an incremental slice, because the browser is - * drawing a frame. + * Incremental GC defaults to enabled, but may be disabled for testing or in + * embeddings that have not yet implemented barriers on their native classes. + * There is not currently a way to re-enable incremental GC once it has been + * disabled on the runtime. */ extern JS_FRIEND_API(void) -NotifyDidPaint(JSRuntime *rt); +DisableIncrementalGC(JSRuntime *rt); +/* + * Returns true if incremental GC is enabled. Simply having incremental GC + * enabled is not sufficient to ensure incremental collections are happening. + * See the comment "Incremental GC" above for reasons why incremental GC may be + * suppressed. Inspection of the "nonincremental reason" field of the + * GCDescription returned by GCSliceCallback may help narrow down the cause if + * collections are not happening incrementally when expected. + */ extern JS_FRIEND_API(bool) IsIncrementalGCEnabled(JSRuntime *rt); +/* + * Returns true while an incremental GC is ongoing, both when actively + * collecting and between slices. + */ JS_FRIEND_API(bool) IsIncrementalGCInProgress(JSRuntime *rt); -extern JS_FRIEND_API(void) -DisableIncrementalGC(JSRuntime *rt); - -extern JS_FRIEND_API(void) -DisableGenerationalGC(JSRuntime *rt); - -extern JS_FRIEND_API(void) -EnableGenerationalGC(JSRuntime *rt); - +/* + * Returns true when writes to GC things must call an incremental (pre) barrier. + * This is generally only true when running mutator code in-between GC slices. + * At other times, the barrier may be elided for performance. + */ extern JS_FRIEND_API(bool) IsIncrementalBarrierNeeded(JSRuntime *rt); extern JS_FRIEND_API(bool) IsIncrementalBarrierNeeded(JSContext *cx); +/* + * Notify the GC that a reference to a GC thing is about to be overwritten. + * These methods must be called if IsIncrementalBarrierNeeded. + */ extern JS_FRIEND_API(void) IncrementalReferenceBarrier(void *ptr, JSGCTraceKind kind); @@ -202,73 +316,118 @@ IncrementalValueBarrier(const Value &v); extern JS_FRIEND_API(void) IncrementalObjectBarrier(JSObject *obj); -extern JS_FRIEND_API(void) -PokeGC(JSRuntime *rt); - -/* Was the most recent GC run incrementally? */ +/* + * Returns true if the most recent GC ran incrementally. + */ extern JS_FRIEND_API(bool) WasIncrementalGC(JSRuntime *rt); +/* + * Generational GC: + * + * Note: Generational GC is not yet enabled by default. The following class + * is non-functional unless SpiderMonkey was configured with + * --enable-gcgenerational. + */ + +/* Ensure that generational GC is disabled within some scope. */ +class JS_FRIEND_API(AutoDisableGenerationalGC) +{ + js::gc::GCRuntime *gc; +#if defined(JSGC_GENERATIONAL) && defined(JS_GC_ZEAL) + bool restartVerifier; +#endif + + public: + explicit AutoDisableGenerationalGC(JSRuntime *rt); + ~AutoDisableGenerationalGC(); +}; + +/* + * Returns true if generational allocation and collection is currently enabled + * on the given runtime. + */ +extern JS_FRIEND_API(bool) +IsGenerationalGCEnabled(JSRuntime *rt); + +/* + * Returns the GC's "number". This does not correspond directly to the number + * of GCs that have been run, but is guaranteed to be monotonically increasing + * with GC activity. + */ extern JS_FRIEND_API(size_t) GetGCNumber(); -class JS_PUBLIC_API(AutoAssertNoGC) +/* + * The GC does not immediately return the unused memory freed by a collection + * back to the system incase it is needed soon afterwards. This call forces the + * GC to return this memory immediately. + */ +extern JS_FRIEND_API(void) +ShrinkGCBuffers(JSRuntime *rt); + +/* + * Assert if a GC occurs while this class is live. This class does not disable + * the static rooting hazard analysis. + */ +class JS_PUBLIC_API(AutoAssertOnGC) { #ifdef DEBUG - JSRuntime *runtime; + js::gc::GCRuntime *gc; size_t gcNumber; public: - AutoAssertNoGC(); - AutoAssertNoGC(JSRuntime *rt); - ~AutoAssertNoGC(); + AutoAssertOnGC(); + explicit AutoAssertOnGC(JSRuntime *rt); + ~AutoAssertOnGC(); + + static void VerifyIsSafeToGC(JSRuntime *rt); #else public: - /* Prevent unreferenced local warnings in opt builds. */ - AutoAssertNoGC() {} - AutoAssertNoGC(JSRuntime *) {} + AutoAssertOnGC() {} + explicit AutoAssertOnGC(JSRuntime *rt) {} + ~AutoAssertOnGC() {} + + static void VerifyIsSafeToGC(JSRuntime *rt) {} #endif }; -class JS_PUBLIC_API(ObjectPtr) +/* + * Disable the static rooting hazard analysis in the live region, but assert if + * any GC occurs while this guard object is live. This is most useful to help + * the exact rooting hazard analysis in complex regions, since it cannot + * understand dataflow. + * + * Note: GC behavior is unpredictable even when deterministice and is generally + * non-deterministic in practice. The fact that this guard has not + * asserted is not a guarantee that a GC cannot happen in the guarded + * region. As a rule, anyone performing a GC unsafe action should + * understand the GC properties of all code in that region and ensure + * that the hazard analysis is correct for that code, rather than relying + * on this class. + */ +class JS_PUBLIC_API(AutoSuppressGCAnalysis) : public AutoAssertOnGC { - Heap value; - public: - ObjectPtr() : value(nullptr) {} - - ObjectPtr(JSObject *obj) : value(obj) {} - - /* Always call finalize before the destructor. */ - ~ObjectPtr() { JS_ASSERT(!value); } - - void finalize(JSRuntime *rt) { - if (IsIncrementalBarrierNeeded(rt)) - IncrementalObjectBarrier(value); - value = nullptr; - } - - void init(JSObject *obj) { value = obj; } - - JSObject *get() const { return value; } - - void writeBarrierPre(JSRuntime *rt) { - IncrementalObjectBarrier(value); - } - - bool isAboutToBeFinalized(); - - ObjectPtr &operator=(JSObject *obj) { - IncrementalObjectBarrier(value); - value = obj; - return *this; - } - - void trace(JSTracer *trc, const char *name); + AutoSuppressGCAnalysis() : AutoAssertOnGC() {} + explicit AutoSuppressGCAnalysis(JSRuntime *rt) : AutoAssertOnGC(rt) {} +}; - JSObject &operator*() const { return *value; } - JSObject *operator->() const { return value; } - operator JSObject *() const { return value; } +/* + * Place AutoCheckCannotGC in scopes that you believe can never GC. These + * annotations will be verified both dynamically via AutoAssertOnGC, and + * statically with the rooting hazard analysis (implemented by making the + * analysis consider AutoCheckCannotGC to be a GC pointer, and therefore + * complain if it is live across a GC call.) It is useful when dealing with + * internal pointers to GC things where the GC thing itself may not be present + * for the static analysis: e.g. acquiring inline chars from a JSString* on the + * heap. + */ +class JS_PUBLIC_API(AutoCheckCannotGC) : public AutoAssertOnGC +{ + public: + AutoCheckCannotGC() : AutoAssertOnGC() {} + explicit AutoCheckCannotGC(JSRuntime *rt) : AutoAssertOnGC(rt) {} }; /* @@ -284,10 +443,10 @@ UnmarkGrayGCThingRecursively(void *thing, JSGCTraceKind kind); * data). During incremental GC, since the gray bits haven't been computed yet, * we conservatively mark the object black. */ -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) { - JS_ASSERT(kind != JSTRACE_SHAPE); + MOZ_ASSERT(kind != JSTRACE_SHAPE); shadow::Runtime *rt = js::gc::GetGCThingRuntime(thing); #ifdef JSGC_GENERATIONAL @@ -296,7 +455,7 @@ ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) * All live objects in the nursery are moved to tenured at the beginning of * each GC slice, so the gray marker never sees nursery things. */ - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return; #endif if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) @@ -305,14 +464,7 @@ ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) UnmarkGrayGCThingRecursively(thing, kind); } -static JS_ALWAYS_INLINE void -ExposeValueToActiveJS(const Value &v) -{ - if (v.isMarkable()) - ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); -} - -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void ExposeObjectToActiveJS(JSObject *obj) { ExposeGCThingToActiveJS(obj, JSTRACE_OBJECT); @@ -321,7 +473,7 @@ ExposeObjectToActiveJS(JSObject *obj) /* * If a GC is currently marking, mark the object black. */ -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void MarkGCThingAsLive(JSRuntime *rt_, void *thing, JSGCTraceKind kind) { shadow::Runtime *rt = shadow::Runtime::asShadowRuntime(rt_); @@ -329,20 +481,34 @@ MarkGCThingAsLive(JSRuntime *rt_, void *thing, JSGCTraceKind kind) /* * Any object in the nursery will not be freed during any GC running at that time. */ - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return; #endif if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) IncrementalReferenceBarrier(thing, kind); } -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void MarkStringAsLive(Zone *zone, JSString *string) { JSRuntime *rt = JS::shadow::Zone::asShadowZone(zone)->runtimeFromMainThread(); MarkGCThingAsLive(rt, string, JSTRACE_STRING); } +/* + * Internal to Firefox. + * + * Note: this is not related to the PokeGC in nsJSEnvironment. + */ +extern JS_FRIEND_API(void) +PokeGC(JSRuntime *rt); + +/* + * Internal to Firefox. + */ +extern JS_FRIEND_API(void) +NotifyDidPaint(JSRuntime *rt); + } /* namespace JS */ #endif /* js_GCAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/HashTable.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/HashTable.h index eb98804c8e..4c27308b5e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/HashTable.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/HashTable.h @@ -73,7 +73,7 @@ class HashMap // HashMap construction is fallible (due to OOM); thus the user must call // init after constructing a HashMap and check the return value. - HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} + explicit HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} bool init(uint32_t len = 16) { return impl.init(len); } bool initialized() const { return impl.initialized(); } @@ -159,7 +159,7 @@ class HashMap // typedef HashMap HM; // HM h; // for (HM::Range r = h.all(); !r.empty(); r.popFront()) - // char c = r.front().value; + // char c = r.front().value(); // // Also see the definition of Range in HashTable above (with T = Entry). typedef typename Impl::Range Range; @@ -171,7 +171,7 @@ class HashMap // typedef HashMap HM; // HM s; // for (HM::Enum e(s); !e.empty(); e.popFront()) - // if (e.front().value == 'l') + // if (e.front().value() == 'l') // e.removeFront(); // // Table resize may occur in Enum's destructor. Also see the definition of @@ -182,9 +182,6 @@ class HashMap // using the finish() method. void clear() { impl.clear(); } - // Remove all entries without triggering destructors. This method is unsafe. - void clearWithoutCallingDestructors() { impl.clearWithoutCallingDestructors(); } - // Remove all the entries and release all internal buffers. The map must // be initialized again before any use. void finish() { impl.finish(); } @@ -210,7 +207,7 @@ class HashMap // If |generation()| is the same before and after a HashMap operation, // pointers into the table remain valid. - unsigned generation() const { return impl.generation(); } + uint32_t generation() const { return impl.generation(); } /************************************************** Shorthand operations */ @@ -317,7 +314,7 @@ class HashSet // HashSet construction is fallible (due to OOM); thus the user must call // init after constructing a HashSet and check the return value. - HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} + explicit HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} bool init(uint32_t len = 16) { return impl.init(len); } bool initialized() const { return impl.initialized(); } @@ -438,7 +435,7 @@ class HashSet // If |generation()| is the same before and after a HashSet operation, // pointers into the table remain valid. - unsigned generation() const { return impl.generation(); } + uint32_t generation() const { return impl.generation(); } /************************************************** Shorthand operations */ @@ -482,6 +479,13 @@ class HashSet impl.rekeyAndMaybeRehash(p, new_lookup, new_value); } + // Infallibly rekey one entry with a new key that is equivalent. + void rekeyInPlace(Ptr p, const T &new_value) + { + MOZ_ASSERT(HashPolicy::match(*p, new_value)); + impl.rekeyInPlace(p, new_value); + } + // HashSet is movable HashSet(HashSet &&rhs) : impl(mozilla::Move(rhs.impl)) {} void operator=(HashSet &&rhs) { @@ -531,7 +535,7 @@ struct PointerHasher { typedef Key Lookup; static HashNumber hash(const Lookup &l) { - JS_ASSERT(!JS::IsPoisonedPtr(l)); + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); size_t word = reinterpret_cast(l) >> zeroBits; JS_STATIC_ASSERT(sizeof(HashNumber) == 4); #if JS_BITS_PER_WORD == 32 @@ -542,8 +546,8 @@ struct PointerHasher #endif } static bool match(const Key &k, const Lookup &l) { - JS_ASSERT(!JS::IsPoisonedPtr(k)); - JS_ASSERT(!JS::IsPoisonedPtr(l)); + MOZ_ASSERT(!JS::IsPoisonedPtr(k)); + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); return k == l; } static void rekey(Key &k, const Key& newKey) { @@ -701,7 +705,7 @@ class HashTableEntry } void destroy() { - JS_ASSERT(isLive()); + MOZ_ASSERT(isLive()); mem.addr()->~T(); } @@ -710,16 +714,16 @@ class HashTableEntry mozilla::Swap(mem, other->mem); } - T &get() { JS_ASSERT(isLive()); return *mem.addr(); } + T &get() { MOZ_ASSERT(isLive()); return *mem.addr(); } bool isFree() const { return keyHash == sFreeKey; } - void clearLive() { JS_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); } + void clearLive() { MOZ_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); } void clear() { if (isLive()) mem.addr()->~T(); keyHash = sFreeKey; } bool isRemoved() const { return keyHash == sRemovedKey; } - void removeLive() { JS_ASSERT(isLive()); keyHash = sRemovedKey; mem.addr()->~T(); } + void removeLive() { MOZ_ASSERT(isLive()); keyHash = sRemovedKey; mem.addr()->~T(); } bool isLive() const { return isLiveHash(keyHash); } - void setCollision() { JS_ASSERT(isLive()); keyHash |= sCollisionBit; } - void setCollision(HashNumber bit) { JS_ASSERT(isLive()); keyHash |= bit; } + void setCollision() { MOZ_ASSERT(isLive()); keyHash |= sCollisionBit; } + void setCollision(HashNumber bit) { MOZ_ASSERT(isLive()); keyHash |= bit; } void unsetCollision() { keyHash &= ~sCollisionBit; } bool hasCollision() const { return keyHash & sCollisionBit; } bool matchHash(HashNumber hn) { return (keyHash & ~sCollisionBit) == hn; } @@ -728,16 +732,18 @@ class HashTableEntry template void setLive(HashNumber hn, U &&u) { - JS_ASSERT(!isLive()); + MOZ_ASSERT(!isLive()); keyHash = hn; new(mem.addr()) T(mozilla::Forward(u)); - JS_ASSERT(isLive()); + MOZ_ASSERT(isLive()); } }; template class HashTable : private AllocPolicy { + friend class mozilla::ReentrancyGuard; + typedef typename mozilla::RemoveConst::Type NonConstT; typedef typename HashPolicy::KeyType Key; typedef typename HashPolicy::Lookup Lookup; @@ -756,25 +762,56 @@ class HashTable : private AllocPolicy void nonNull() {} Entry *entry_; +#ifdef DEBUG + const HashTable *table_; + uint32_t generation; +#endif protected: - Ptr(Entry &entry) : entry_(&entry) {} + Ptr(Entry &entry, const HashTable &tableArg) + : entry_(&entry) +#ifdef DEBUG + , table_(&tableArg) + , generation(tableArg.generation()) +#endif + {} public: // Leaves Ptr uninitialized. Ptr() { -#ifdef DEBUG +#ifdef JS_DEBUG entry_ = (Entry *)0xbad; #endif } - bool found() const { return entry_->isLive(); } - operator ConvertibleToBool() const { return found() ? &Ptr::nonNull : 0; } - bool operator==(const Ptr &rhs) const { JS_ASSERT(found() && rhs.found()); return entry_ == rhs.entry_; } - bool operator!=(const Ptr &rhs) const { return !(*this == rhs); } + bool found() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->isLive(); + } - T &operator*() const { return entry_->get(); } - T *operator->() const { return &entry_->get(); } + operator ConvertibleToBool() const { + return found() ? &Ptr::nonNull : 0; + } + + bool operator==(const Ptr &rhs) const { + MOZ_ASSERT(found() && rhs.found()); + return entry_ == rhs.entry_; + } + + bool operator!=(const Ptr &rhs) const { + MOZ_ASSERT(generation == table_->generation()); + return !(*this == rhs); + } + + T &operator*() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->get(); + } + + T *operator->() const { + MOZ_ASSERT(generation == table_->generation()); + return &entry_->get(); + } }; // A Ptr that can be used to add a key after a failed lookup. @@ -782,9 +819,18 @@ class HashTable : private AllocPolicy { friend class HashTable; HashNumber keyHash; - mozilla::DebugOnly mutationCount; +#ifdef DEBUG + uint64_t mutationCount; +#endif + + AddPtr(Entry &entry, const HashTable &tableArg, HashNumber hn) + : Ptr(entry, tableArg) + , keyHash(hn) +#ifdef DEBUG + , mutationCount(tableArg.mutationCount) +#endif + {} - AddPtr(Entry &entry, HashNumber hn) : Ptr(entry), keyHash(hn) {} public: // Leaves AddPtr uninitialized. AddPtr() {} @@ -799,32 +845,63 @@ class HashTable : private AllocPolicy protected: friend class HashTable; - Range(Entry *c, Entry *e) : cur(c), end(e), validEntry(true) { + Range(const HashTable &tableArg, Entry *c, Entry *e) + : cur(c) + , end(e) +#ifdef DEBUG + , table_(&tableArg) + , mutationCount(tableArg.mutationCount) + , generation(tableArg.generation()) + , validEntry(true) +#endif + { while (cur < end && !cur->isLive()) ++cur; } Entry *cur, *end; - mozilla::DebugOnly validEntry; +#ifdef DEBUG + const HashTable *table_; + uint64_t mutationCount; + uint32_t generation; + bool validEntry; +#endif public: - Range() : cur(nullptr), end(nullptr), validEntry(false) {} + Range() + : cur(nullptr) + , end(nullptr) +#ifdef DEBUG + , table_(nullptr) + , mutationCount(0) + , generation(0) + , validEntry(false) +#endif + {} bool empty() const { + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); return cur == end; } T &front() const { - JS_ASSERT(validEntry); - JS_ASSERT(!empty()); + MOZ_ASSERT(validEntry); + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); return cur->get(); } void popFront() { - JS_ASSERT(!empty()); + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); while (++cur < end && !cur->isLive()) continue; +#ifdef DEBUG validEntry = true; +#endif } }; @@ -837,17 +914,17 @@ class HashTable : private AllocPolicy { friend class HashTable; - HashTable &table; + HashTable &table_; bool rekeyed; bool removed; /* Not copyable. */ - Enum(const Enum &); - void operator=(const Enum &); + Enum(const Enum &) MOZ_DELETE; + void operator=(const Enum &) MOZ_DELETE; public: template explicit - Enum(Map &map) : Range(map.all()), table(map.impl), rekeyed(false), removed(false) {} + Enum(Map &map) : Range(map.all()), table_(map.impl), rekeyed(false), removed(false) {} // Removes the |front()| element from the table, leaving |front()| // invalid until the next call to |popFront()|. For example: @@ -857,18 +934,25 @@ class HashTable : private AllocPolicy // if (e.front() == 42) // e.removeFront(); void removeFront() { - table.remove(*this->cur); + table_.remove(*this->cur); removed = true; +#ifdef DEBUG this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif } // Removes the |front()| element and re-inserts it into the table with // a new key at the new Lookup position. |front()| is invalid after // this operation until the next call to |popFront()|. void rekeyFront(const Lookup &l, const Key &k) { - table.rekeyWithoutRehash(*this->cur, l, k); + Ptr p(*this->cur, table_); + table_.rekeyWithoutRehash(p, l, k); rekeyed = true; +#ifdef DEBUG this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif } void rekeyFront(const Key &k) { @@ -878,12 +962,12 @@ class HashTable : private AllocPolicy // Potentially rehashes the table. ~Enum() { if (rekeyed) { - table.gen++; - table.checkOverRemoved(); + table_.gen++; + table_.checkOverRemoved(); } if (removed) - table.compactIfUnderloaded(); + table_.compactIfUnderloaded(); } }; @@ -908,18 +992,18 @@ class HashTable : private AllocPolicy void operator=(const HashTable &) MOZ_DELETE; private: - uint32_t hashShift; // multiplicative hash shift - uint32_t entryCount; // number of entries in table - uint32_t gen; // entry storage generation number - uint32_t removedCount; // removed entry sentinels in table - Entry *table; // entry storage + static const size_t CAP_BITS = 24; - void setTableSizeLog2(unsigned sizeLog2) - { - hashShift = sHashBits - sizeLog2; - } + public: + Entry *table; // entry storage + uint32_t gen; // entry storage generation number + uint32_t entryCount; // number of entries in table + uint32_t removedCount:CAP_BITS; // removed entry sentinels in table + uint32_t hashShift:8; // multiplicative hash shift -#ifdef DEBUG +#ifdef JS_DEBUG + mozilla::DebugOnly mutationCount; + mutable mozilla::DebugOnly mEntered; mutable struct Stats { uint32_t searches; // total number of table searches @@ -939,16 +1023,12 @@ class HashTable : private AllocPolicy # define METER(x) #endif - friend class mozilla::ReentrancyGuard; - mutable mozilla::DebugOnly entered; - mozilla::DebugOnly mutationCount; - // The default initial capacity is 32 (enough to hold 16 elements), but it // can be as low as 4. static const unsigned sMinCapacityLog2 = 2; static const unsigned sMinCapacity = 1 << sMinCapacityLog2; - static const unsigned sMaxInit = JS_BIT(23); - static const unsigned sMaxCapacity = JS_BIT(24); + static const unsigned sMaxInit = JS_BIT(CAP_BITS - 1); + static const unsigned sMaxCapacity = JS_BIT(CAP_BITS); static const unsigned sHashBits = mozilla::tl::BitSize::value; // Hash-table alpha is conceptually a fraction, but to avoid floating-point @@ -961,6 +1041,11 @@ class HashTable : private AllocPolicy static const HashNumber sRemovedKey = Entry::sRemovedKey; static const HashNumber sCollisionBit = Entry::sCollisionBit; + void setTableSizeLog2(unsigned sizeLog2) + { + hashShift = sHashBits - sizeLog2; + } + static bool isLiveHash(HashNumber hash) { return Entry::isLiveHash(hash); @@ -993,20 +1078,22 @@ class HashTable : private AllocPolicy } public: - HashTable(AllocPolicy ap) - : AllocPolicy(ap), - hashShift(sHashBits), - entryCount(0), - gen(0), - removedCount(0), - table(nullptr), - entered(false), - mutationCount(0) + explicit HashTable(AllocPolicy ap) + : AllocPolicy(ap) + , table(nullptr) + , gen(0) + , entryCount(0) + , removedCount(0) + , hashShift(sHashBits) +#ifdef DEBUG + , mutationCount(0) + , mEntered(false) +#endif {} MOZ_WARN_UNUSED_RESULT bool init(uint32_t length) { - JS_ASSERT(!initialized()); + MOZ_ASSERT(!initialized()); // Reject all lengths whose initial computed capacity would exceed // sMaxCapacity. Round that maximum length down to the nearest power @@ -1116,10 +1203,10 @@ class HashTable : private AllocPolicy Entry &lookup(const Lookup &l, HashNumber keyHash, unsigned collisionBit) const { - JS_ASSERT(isLiveHash(keyHash)); - JS_ASSERT(!(keyHash & sCollisionBit)); - JS_ASSERT(collisionBit == 0 || collisionBit == sCollisionBit); - JS_ASSERT(table); + MOZ_ASSERT(isLiveHash(keyHash)); + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(collisionBit == 0 || collisionBit == sCollisionBit); + MOZ_ASSERT(table); METER(stats.searches++); // Compute the primary hash address. @@ -1145,7 +1232,7 @@ class HashTable : private AllocPolicy Entry *firstRemoved = nullptr; while(true) { - if (JS_UNLIKELY(entry->isRemoved())) { + if (MOZ_UNLIKELY(entry->isRemoved())) { if (!firstRemoved) firstRemoved = entry; } else { @@ -1176,8 +1263,8 @@ class HashTable : private AllocPolicy // from entries, which allows more flexible Lookup/Key types. Entry &findFreeEntry(HashNumber keyHash) { - JS_ASSERT(!(keyHash & sCollisionBit)); - JS_ASSERT(table); + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(table); METER(stats.searches++); // We assume 'keyHash' has already been distributed. @@ -1196,7 +1283,7 @@ class HashTable : private AllocPolicy DoubleHash dh = hash2(keyHash); while(true) { - JS_ASSERT(!entry->isRemoved()); + MOZ_ASSERT(!entry->isRemoved()); entry->setCollision(); METER(stats.steps++); @@ -1277,7 +1364,7 @@ class HashTable : private AllocPolicy void remove(Entry &e) { - JS_ASSERT(table); + MOZ_ASSERT(table); METER(stats.removes++); if (e.hasCollision()) { @@ -1288,7 +1375,9 @@ class HashTable : private AllocPolicy e.clearLive(); } entryCount--; +#ifdef DEBUG mutationCount++; +#endif } void checkUnderloaded() @@ -1371,12 +1460,14 @@ class HashTable : private AllocPolicy } removedCount = 0; entryCount = 0; +#ifdef DEBUG mutationCount++; +#endif } void finish() { - JS_ASSERT(!entered); + MOZ_ASSERT(!mEntered); if (!table) return; @@ -1386,36 +1477,38 @@ class HashTable : private AllocPolicy gen++; entryCount = 0; removedCount = 0; +#ifdef DEBUG mutationCount++; +#endif } Range all() const { - JS_ASSERT(table); - return Range(table, table + capacity()); + MOZ_ASSERT(table); + return Range(*this, table, table + capacity()); } bool empty() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return !entryCount; } uint32_t count() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return entryCount; } uint32_t capacity() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return JS_BIT(sHashBits - hashShift); } uint32_t generation() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return gen; } @@ -1433,13 +1526,13 @@ class HashTable : private AllocPolicy { mozilla::ReentrancyGuard g(*this); HashNumber keyHash = prepareHash(l); - return Ptr(lookup(l, keyHash, 0)); + return Ptr(lookup(l, keyHash, 0), *this); } Ptr readonlyThreadsafeLookup(const Lookup &l) const { HashNumber keyHash = prepareHash(l); - return Ptr(lookup(l, keyHash, 0)); + return Ptr(lookup(l, keyHash, 0), *this); } AddPtr lookupForAdd(const Lookup &l) const @@ -1447,8 +1540,7 @@ class HashTable : private AllocPolicy mozilla::ReentrancyGuard g(*this); HashNumber keyHash = prepareHash(l); Entry &entry = lookup(l, keyHash, sCollisionBit); - AddPtr p(entry, keyHash); - p.mutationCount = mutationCount; + AddPtr p(entry, *this, keyHash); return p; } @@ -1456,10 +1548,9 @@ class HashTable : private AllocPolicy bool add(AddPtr &p, U &&u) { mozilla::ReentrancyGuard g(*this); - JS_ASSERT(mutationCount == p.mutationCount); - JS_ASSERT(table); - JS_ASSERT(!p.found()); - JS_ASSERT(!(p.keyHash & sCollisionBit)); + MOZ_ASSERT(table); + MOZ_ASSERT(!p.found()); + MOZ_ASSERT(!(p.keyHash & sCollisionBit)); // Changing an entry from removed to live does not affect whether we // are overloaded and can be handled separately. @@ -1478,7 +1569,11 @@ class HashTable : private AllocPolicy p.entry_->setLive(p.keyHash, mozilla::Forward(u)); entryCount++; +#ifdef DEBUG mutationCount++; + p.generation = generation(); + p.mutationCount = mutationCount; +#endif return true; } @@ -1487,7 +1582,7 @@ class HashTable : private AllocPolicy template void putNewInfallible(const Lookup &l, U &&u) { - JS_ASSERT(table); + MOZ_ASSERT(table); HashNumber keyHash = prepareHash(l); Entry *entry = &findFreeEntry(keyHash); @@ -1500,7 +1595,9 @@ class HashTable : private AllocPolicy entry->setLive(keyHash, mozilla::Forward(u)); entryCount++; +#ifdef DEBUG mutationCount++; +#endif } // Note: |l| may be a reference to a piece of |u|, so this function @@ -1520,10 +1617,13 @@ class HashTable : private AllocPolicy template bool relookupOrAdd(AddPtr& p, const Lookup &l, U &&u) { +#ifdef DEBUG + p.generation = generation(); p.mutationCount = mutationCount; +#endif { mozilla::ReentrancyGuard g(*this); - JS_ASSERT(prepareHash(l) == p.keyHash); // l has not been destroyed + MOZ_ASSERT(prepareHash(l) == p.keyHash); // l has not been destroyed p.entry_ = &lookup(l, p.keyHash, sCollisionBit); } return p.found() || add(p, mozilla::Forward(u)); @@ -1531,18 +1631,18 @@ class HashTable : private AllocPolicy void remove(Ptr p) { - JS_ASSERT(table); + MOZ_ASSERT(table); mozilla::ReentrancyGuard g(*this); - JS_ASSERT(p.found()); + MOZ_ASSERT(p.found()); remove(*p.entry_); checkUnderloaded(); } void rekeyWithoutRehash(Ptr p, const Lookup &l, const Key &k) { - JS_ASSERT(table); + MOZ_ASSERT(table); mozilla::ReentrancyGuard g(*this); - JS_ASSERT(p.found()); + MOZ_ASSERT(p.found()); typename HashTableEntry::NonConstT t(mozilla::Move(*p)); HashPolicy::setKey(t, const_cast(k)); remove(*p.entry_); @@ -1555,6 +1655,14 @@ class HashTable : private AllocPolicy checkOverRemoved(); } + void rekeyInPlace(Ptr p, const Key &k) + { + MOZ_ASSERT(table); + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(p.found()); + HashPolicy::rekey(const_cast(*p), const_cast(k)); + } + #undef METER }; diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/HeapAPI.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/HeapAPI.h index 9993751d46..bdd63c1937 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/HeapAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/HeapAPI.h @@ -26,11 +26,17 @@ CurrentThreadCanAccessZone(JS::Zone *zone); namespace gc { +struct Cell; + const size_t ArenaShift = 12; const size_t ArenaSize = size_t(1) << ArenaShift; const size_t ArenaMask = ArenaSize - 1; +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkShift = 18; +#else const size_t ChunkShift = 20; +#endif const size_t ChunkSize = size_t(1) << ChunkShift; const size_t ChunkMask = ChunkSize - 1; @@ -39,9 +45,15 @@ const size_t CellSize = size_t(1) << CellShift; const size_t CellMask = CellSize - 1; /* These are magic constants derived from actual offsets in gc/Heap.h. */ -const size_t ChunkMarkBitmapOffset = 1032368; +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkMarkBitmapOffset = 258104; +const size_t ChunkMarkBitmapBits = 31744; +#else +const size_t ChunkMarkBitmapOffset = 1032352; const size_t ChunkMarkBitmapBits = 129024; +#endif const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*); +const size_t ChunkLocationOffset = ChunkSize - 2 * sizeof(void*) - sizeof(uint64_t); /* * Live objects are marked black. How many other additional colors are available @@ -51,14 +63,98 @@ const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*); static const uint32_t BLACK = 0; static const uint32_t GRAY = 1; +/* + * The "location" field in the Chunk trailer is a bit vector indicting various + * roles of the chunk. + * + * The value 0 for the "location" field is invalid, at least one bit must be + * set. + * + * Some bits preclude others, for example, any "nursery" bit precludes any + * "tenured" or "middle generation" bit. + */ +const uintptr_t ChunkLocationBitNursery = 1; // Standard GGC nursery +const uintptr_t ChunkLocationBitTenuredHeap = 2; // Standard GGC tenured generation +const uintptr_t ChunkLocationBitPJSNewspace = 4; // The PJS generational GC's allocation space +const uintptr_t ChunkLocationBitPJSFromspace = 8; // The PJS generational GC's fromspace (during GC) + +const uintptr_t ChunkLocationAnyNursery = ChunkLocationBitNursery | + ChunkLocationBitPJSNewspace | + ChunkLocationBitPJSFromspace; + +#ifdef JS_DEBUG +/* When downcasting, ensure we are actually the right type. */ +extern JS_FRIEND_API(void) +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind); +#else +inline void +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind) {} +#endif + } /* namespace gc */ } /* namespace js */ namespace JS { struct Zone; -} /* namespace JS */ -namespace JS { +/* Default size for the generational nursery in bytes. */ +const uint32_t DefaultNurseryBytes = 16 * 1024 * 1024; + +/* Default maximum heap size in bytes to pass to JS_NewRuntime(). */ +const uint32_t DefaultHeapMaxBytes = 32 * 1024 * 1024; + +/* + * We cannot expose the class hierarchy: the implementation is hidden. Instead + * we provide cast functions with strong debug-mode assertions. + */ +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSObject *obj) +{ + js::gc::Cell *cell = reinterpret_cast(obj); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFunction *fun) +{ + js::gc::Cell *cell = reinterpret_cast(fun); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSString *str) +{ + js::gc::Cell *cell = reinterpret_cast(str); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFlatString *flat) +{ + js::gc::Cell *cell = reinterpret_cast(flat); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JS::Symbol *sym) +{ + js::gc::Cell *cell = reinterpret_cast(sym); + AssertGCThingHasType(cell, JSTRACE_SYMBOL); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSScript *script) +{ + js::gc::Cell *cell = reinterpret_cast(script); + AssertGCThingHasType(cell, JSTRACE_SCRIPT); + return cell; +} + namespace shadow { struct ArenaHeader @@ -86,13 +182,13 @@ struct Zone } JSTracer *barrierTracer() { - JS_ASSERT(needsBarrier_); - JS_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + MOZ_ASSERT(needsBarrier_); + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); return barrierTracer_; } JSRuntime *runtimeFromMainThread() const { - JS_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); return runtime_; } @@ -113,40 +209,40 @@ struct Zone namespace js { namespace gc { -static JS_ALWAYS_INLINE uintptr_t * +static MOZ_ALWAYS_INLINE uintptr_t * GetGCThingMarkBitmap(const void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); uintptr_t addr = uintptr_t(thing); addr &= ~js::gc::ChunkMask; addr |= js::gc::ChunkMarkBitmapOffset; return reinterpret_cast(addr); } -static JS_ALWAYS_INLINE JS::shadow::Runtime * +static MOZ_ALWAYS_INLINE JS::shadow::Runtime * GetGCThingRuntime(const void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); uintptr_t addr = uintptr_t(thing); addr &= ~js::gc::ChunkMask; addr |= js::gc::ChunkRuntimeOffset; return *reinterpret_cast(addr); } -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void GetGCThingMarkWordAndMask(const void *thing, uint32_t color, uintptr_t **wordp, uintptr_t *maskp) { uintptr_t addr = uintptr_t(thing); size_t bit = (addr & js::gc::ChunkMask) / js::gc::CellSize + color; - JS_ASSERT(bit < js::gc::ChunkMarkBitmapBits); + MOZ_ASSERT(bit < js::gc::ChunkMarkBitmapBits); uintptr_t *bitmap = GetGCThingMarkBitmap(thing); const uintptr_t nbits = sizeof(*bitmap) * CHAR_BIT; *maskp = uintptr_t(1) << (bit % nbits); *wordp = &bitmap[bit / nbits]; } -static JS_ALWAYS_INLINE JS::shadow::ArenaHeader * +static MOZ_ALWAYS_INLINE JS::shadow::ArenaHeader * GetGCThingArena(void *thing) { uintptr_t addr = uintptr_t(thing); @@ -154,11 +250,18 @@ GetGCThingArena(void *thing) return reinterpret_cast(addr); } -JS_ALWAYS_INLINE bool -IsInsideNursery(const JS::shadow::Runtime *runtime, const void *p) +MOZ_ALWAYS_INLINE bool +IsInsideNursery(const js::gc::Cell *cell) { #ifdef JSGC_GENERATIONAL - return uintptr_t(p) >= runtime->gcNurseryStart_ && uintptr_t(p) < runtime->gcNurseryEnd_; + if (!cell) + return false; + uintptr_t addr = uintptr_t(cell); + addr &= ~js::gc::ChunkMask; + addr |= js::gc::ChunkLocationOffset; + uint32_t location = *reinterpret_cast(addr); + JS_ASSERT(location != 0); + return location & ChunkLocationAnyNursery; #else return false; #endif @@ -170,20 +273,20 @@ IsInsideNursery(const JS::shadow::Runtime *runtime, const void *p) namespace JS { -static JS_ALWAYS_INLINE Zone * +static MOZ_ALWAYS_INLINE Zone * GetGCThingZone(void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); return js::gc::GetGCThingArena(thing)->zone; } -static JS_ALWAYS_INLINE Zone * +static MOZ_ALWAYS_INLINE Zone * GetObjectZone(JSObject *obj) { return GetGCThingZone(obj); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool GCThingIsMarkedGray(void *thing) { #ifdef JSGC_GENERATIONAL @@ -192,8 +295,7 @@ GCThingIsMarkedGray(void *thing) * All live objects in the nursery are moved to tenured at the beginning of * each GC slice, so the gray marker never sees nursery things. */ - JS::shadow::Runtime *rt = js::gc::GetGCThingRuntime(thing); - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return false; #endif uintptr_t *word, mask; @@ -201,7 +303,7 @@ GCThingIsMarkedGray(void *thing) return *word & mask; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool IsIncrementalBarrierNeededOnGCThing(shadow::Runtime *rt, void *thing, JSGCTraceKind kind) { if (!rt->needsBarrier_) diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/Id.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/Id.h index 447deb62e6..11116f2efe 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/Id.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/Id.h @@ -21,164 +21,155 @@ // JS_IdToValue must be used instead. #include "mozilla/NullPtr.h" - + #include "jstypes.h" +#include "js/HeapAPI.h" #include "js/RootingAPI.h" #include "js/TypeDecls.h" #include "js/Utility.h" -#ifdef JS_USE_JSID_STRUCT_TYPES struct jsid { size_t asBits; bool operator==(jsid rhs) const { return asBits == rhs.asBits; } bool operator!=(jsid rhs) const { return asBits != rhs.asBits; } }; -# define JSID_BITS(id) (id.asBits) -#else -# define JSID_BITS(id) (id) -#endif +#define JSID_BITS(id) (id.asBits) #define JSID_TYPE_STRING 0x0 #define JSID_TYPE_INT 0x1 #define JSID_TYPE_VOID 0x2 -#define JSID_TYPE_OBJECT 0x4 +#define JSID_TYPE_SYMBOL 0x4 #define JSID_TYPE_MASK 0x7 // Avoid using canonical 'id' for jsid parameters since this is a magic word in // Objective-C++ which, apparently, wants to be able to #include jsapi.h. #define id iden -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_STRING(jsid id) { return (JSID_BITS(id) & JSID_TYPE_MASK) == 0; } -static JS_ALWAYS_INLINE JSString * +static MOZ_ALWAYS_INLINE JSString * JSID_TO_STRING(jsid id) { - JS_ASSERT(JSID_IS_STRING(id)); + MOZ_ASSERT(JSID_IS_STRING(id)); return (JSString *)JSID_BITS(id); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ZERO(jsid id) { return JSID_BITS(id) == 0; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_INT(jsid id) { return !!(JSID_BITS(id) & JSID_TYPE_INT); } -static JS_ALWAYS_INLINE int32_t +static MOZ_ALWAYS_INLINE int32_t JSID_TO_INT(jsid id) { - JS_ASSERT(JSID_IS_INT(id)); + MOZ_ASSERT(JSID_IS_INT(id)); return ((uint32_t)JSID_BITS(id)) >> 1; } #define JSID_INT_MIN 0 #define JSID_INT_MAX INT32_MAX -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool INT_FITS_IN_JSID(int32_t i) { return i >= 0; } -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid INT_TO_JSID(int32_t i) { jsid id; - JS_ASSERT(INT_FITS_IN_JSID(i)); + MOZ_ASSERT(INT_FITS_IN_JSID(i)); JSID_BITS(id) = ((i << 1) | JSID_TYPE_INT); return id; } -static JS_ALWAYS_INLINE bool -JSID_IS_OBJECT(jsid id) +static MOZ_ALWAYS_INLINE bool +JSID_IS_SYMBOL(jsid id) { - return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_OBJECT && - (size_t)JSID_BITS(id) != JSID_TYPE_OBJECT; + return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_SYMBOL && + JSID_BITS(id) != JSID_TYPE_SYMBOL; } -static JS_ALWAYS_INLINE JSObject * -JSID_TO_OBJECT(jsid id) +static MOZ_ALWAYS_INLINE JS::Symbol * +JSID_TO_SYMBOL(jsid id) { - JS_ASSERT(JSID_IS_OBJECT(id)); - return (JSObject *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); + MOZ_ASSERT(JSID_IS_SYMBOL(id)); + return (JS::Symbol *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); } -static JS_ALWAYS_INLINE jsid -OBJECT_TO_JSID(JSObject *obj) +static MOZ_ALWAYS_INLINE jsid +SYMBOL_TO_JSID(JS::Symbol *sym) { jsid id; - JS_ASSERT(obj != nullptr); - JS_ASSERT(((size_t)obj & JSID_TYPE_MASK) == 0); - JSID_BITS(id) = ((size_t)obj | JSID_TYPE_OBJECT); + MOZ_ASSERT(sym != nullptr); + MOZ_ASSERT((size_t(sym) & JSID_TYPE_MASK) == 0); + JS_ASSERT(!js::gc::IsInsideNursery(JS::AsCell(sym))); + JS_ASSERT(!JS::IsPoisonedPtr(sym)); + JSID_BITS(id) = (size_t(sym) | JSID_TYPE_SYMBOL); return id; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_GCTHING(jsid id) { - return JSID_IS_STRING(id) || JSID_IS_OBJECT(id); + return JSID_IS_STRING(id) || JSID_IS_SYMBOL(id); } -static JS_ALWAYS_INLINE void * +static MOZ_ALWAYS_INLINE void * JSID_TO_GCTHING(jsid id) { return (void *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_VOID(const jsid id) { - JS_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID, + MOZ_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID, JSID_BITS(id) == JSID_TYPE_VOID); return ((size_t)JSID_BITS(id) == JSID_TYPE_VOID); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_EMPTY(const jsid id) { - return ((size_t)JSID_BITS(id) == JSID_TYPE_OBJECT); + return ((size_t)JSID_BITS(id) == JSID_TYPE_SYMBOL); } -#undef id - -#ifdef JS_USE_JSID_STRUCT_TYPES extern JS_PUBLIC_DATA(const jsid) JSID_VOID; extern JS_PUBLIC_DATA(const jsid) JSID_EMPTY; -#else -# define JSID_VOID ((jsid)JSID_TYPE_VOID) -# define JSID_EMPTY ((jsid)JSID_TYPE_OBJECT) -#endif -extern JS_PUBLIC_DATA(const JS::Handle) JSID_VOIDHANDLE; -extern JS_PUBLIC_DATA(const JS::Handle) JSID_EMPTYHANDLE; +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_VOIDHANDLE; +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_EMPTYHANDLE; namespace js { inline bool -IsPoisonedId(jsid iden) +IsPoisonedId(jsid id) { - if (JSID_IS_STRING(iden)) - return JS::IsPoisonedPtr(JSID_TO_STRING(iden)); - if (JSID_IS_OBJECT(iden)) - return JS::IsPoisonedPtr(JSID_TO_OBJECT(iden)); + if (JSID_IS_STRING(id)) + return JS::IsPoisonedPtr(JSID_TO_STRING(id)); + if (JSID_IS_SYMBOL(id)) + return JS::IsPoisonedPtr(JSID_TO_SYMBOL(id)); return false; } template <> struct GCMethods { static jsid initial() { return JSID_VOID; } - static ThingRootKind kind() { return THING_ROOT_ID; } static bool poisoned(jsid id) { return IsPoisonedId(id); } static bool needsPostBarrier(jsid id) { return false; } #ifdef JSGC_GENERATIONAL @@ -187,6 +178,8 @@ template <> struct GCMethods #endif }; +#undef id + } #endif /* js_Id_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/MemoryMetrics.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/MemoryMetrics.h index 95ac91b9f6..31e456baba 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/MemoryMetrics.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/MemoryMetrics.h @@ -77,6 +77,13 @@ struct InefficientNonFlatteningStringHashPolicy static bool match(const JSString *const &k, const Lookup &l); }; +struct CStringHashPolicy +{ + typedef const char *Lookup; + static HashNumber hash(const Lookup &l); + static bool match(const char *const &k, const Lookup &l); +}; + // This file features many classes with numerous size_t fields, and each such // class has one or more methods that need to operate on all of these fields. // Writing these individually is error-prone -- it's easy to add a new field @@ -92,6 +99,9 @@ struct InefficientNonFlatteningStringHashPolicy #define ZERO_SIZE(kind, gc, mSize) mSize(0), #define COPY_OTHER_SIZE(kind, gc, mSize) mSize(other.mSize), #define ADD_OTHER_SIZE(kind, gc, mSize) mSize += other.mSize; +#define SUB_OTHER_SIZE(kind, gc, mSize) MOZ_ASSERT(mSize >= other.mSize); \ + mSize -= other.mSize; +#define ADD_SIZE_TO_N(kind, gc, mSize) n += mSize; #define ADD_SIZE_TO_N_IF_LIVE_GC_THING(kind, gc, mSize) n += (js::gc) ? mSize : 0; #define ADD_TO_TAB_SIZES(kind, gc, mSize) sizes->add(JS::TabSizes::kind, mSize); @@ -101,49 +111,6 @@ enum { IsLiveGCThing = true }; -struct ZoneStatsPod -{ -#define FOR_EACH_SIZE(macro) \ - macro(Other, NotLiveGCThing, gcHeapArenaAdmin) \ - macro(Other, NotLiveGCThing, unusedGCThings) \ - macro(Other, IsLiveGCThing, lazyScriptsGCHeap) \ - macro(Other, NotLiveGCThing, lazyScriptsMallocHeap) \ - macro(Other, IsLiveGCThing, ionCodesGCHeap) \ - macro(Other, IsLiveGCThing, typeObjectsGCHeap) \ - macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \ - macro(Other, NotLiveGCThing, typePool) \ - macro(Strings, IsLiveGCThing, stringsShortGCHeap) \ - macro(Strings, IsLiveGCThing, stringsNormalGCHeap) \ - macro(Strings, NotLiveGCThing, stringsNormalMallocHeap) - - ZoneStatsPod() - : FOR_EACH_SIZE(ZERO_SIZE) - extra() - {} - - void add(const ZoneStatsPod &other) { - FOR_EACH_SIZE(ADD_OTHER_SIZE) - // Do nothing with |extra|. - } - - size_t sizeOfLiveGCThings() const { - size_t n = 0; - FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) - // Do nothing with |extra|. - return n; - } - - void addToTabSizes(JS::TabSizes *sizes) const { - FOR_EACH_SIZE(ADD_TO_TAB_SIZES) - // Do nothing with |extra|. - } - - FOR_EACH_SIZE(DECL_SIZE) - void *extra; // This field can be used by embedders. - -#undef FOR_EACH_SIZE -}; - } // namespace js namespace JS { @@ -156,6 +123,7 @@ struct ObjectsExtraSizes macro(Objects, NotLiveGCThing, mallocHeapElementsNonAsmJS) \ macro(Objects, NotLiveGCThing, mallocHeapElementsAsmJS) \ macro(Objects, NotLiveGCThing, nonHeapElementsAsmJS) \ + macro(Objects, NotLiveGCThing, nonHeapElementsMapped) \ macro(Objects, NotLiveGCThing, nonHeapCodeAsmJS) \ macro(Objects, NotLiveGCThing, mallocHeapAsmJSModuleData) \ macro(Objects, NotLiveGCThing, mallocHeapArgumentsData) \ @@ -209,6 +177,33 @@ struct CodeSizes #undef FOR_EACH_SIZE }; +// Data for tracking GC memory usage. +struct GCSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, marker) \ + macro(_, _, nurseryCommitted) \ + macro(_, _, nurseryDecommitted) \ + macro(_, _, nurseryHugeSlots) \ + macro(_, _, storeBufferVals) \ + macro(_, _, storeBufferCells) \ + macro(_, _, storeBufferSlots) \ + macro(_, _, storeBufferWholeCells) \ + macro(_, _, storeBufferRelocVals) \ + macro(_, _, storeBufferRelocCells) \ + macro(_, _, storeBufferGenerics) + + GCSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + dummy() + {} + + FOR_EACH_SIZE(DECL_SIZE) + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) + +#undef FOR_EACH_SIZE +}; + // This class holds information about the memory taken up by identical copies of // a particular string. Multiple JSStrings may have their sizes aggregated // together into one StringInfo object. Note that two strings with identical @@ -216,50 +211,59 @@ struct CodeSizes // is not. struct StringInfo { - StringInfo() - : numCopies(0), - isShort(0), - gcHeap(0), - mallocHeap(0) - {} +#define FOR_EACH_SIZE(macro) \ + macro(Strings, IsLiveGCThing, gcHeapLatin1) \ + macro(Strings, IsLiveGCThing, gcHeapTwoByte) \ + macro(Strings, NotLiveGCThing, mallocHeapLatin1) \ + macro(Strings, NotLiveGCThing, mallocHeapTwoByte) - StringInfo(bool isShort, size_t gcSize, size_t mallocSize) - : numCopies(1), - isShort(isShort), - gcHeap(gcSize), - mallocHeap(mallocSize) + StringInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numCopies(0) {} - void add(bool isShort, size_t gcSize, size_t mallocSize) { + void add(const StringInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE); numCopies++; - MOZ_ASSERT(isShort == this->isShort); - gcHeap += gcSize; - mallocHeap += mallocSize; } - void add(const StringInfo& info) { - numCopies += info.numCopies; - MOZ_ASSERT(info.isShort == isShort); - gcHeap += info.gcHeap; - mallocHeap += info.mallocHeap; + void subtract(const StringInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE); + numCopies--; } - uint32_t numCopies:31; // How many copies of the string have we seen? - uint32_t isShort:1; // Is it a short string? + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + size_t sizeOfLiveGCThings() const { + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + return n; + } + + void addToTabSizes(TabSizes *sizes) const { + FOR_EACH_SIZE(ADD_TO_TAB_SIZES) + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numCopies; // How many copies of the string have we seen? - // These are all totals across all copies of the string we've seen. - size_t gcHeap; - size_t mallocHeap; +#undef FOR_EACH_SIZE }; -// Holds data about a notable string (one which uses more than -// NotableStringInfo::notableSize() bytes of memory), so we can report it -// individually. +// Holds data about a notable string (one which, counting all duplicates, uses +// more than a certain amount of memory) so we can report it individually. // -// Essentially the only difference between this class and StringInfo is that -// NotableStringInfo holds a copy of the string's chars. +// The only difference between this class and StringInfo is that +// NotableStringInfo holds a copy of some or all of the string's chars. struct NotableStringInfo : public StringInfo { + static const size_t MAX_SAVED_CHARS = 1024; + NotableStringInfo(); NotableStringInfo(JSString *str, const StringInfo &info); NotableStringInfo(NotableStringInfo &&info); @@ -269,12 +273,6 @@ struct NotableStringInfo : public StringInfo js_free(buffer); } - // A string needs to take up this many bytes of storage before we consider - // it to be "notable". - static size_t notableSize() { - return js::MemoryReportingSundriesThreshold(); - } - char *buffer; size_t length; @@ -282,6 +280,67 @@ struct NotableStringInfo : public StringInfo NotableStringInfo(const NotableStringInfo& info) MOZ_DELETE; }; +// This class holds information about the memory taken up by script sources +// from a particular file. +struct ScriptSourceInfo +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, compressed) \ + macro(_, _, uncompressed) \ + macro(_, _, misc) + + ScriptSourceInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numScripts(0) + {} + + void add(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE) + numScripts++; + } + + void subtract(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE) + numScripts--; + } + + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numScripts; // How many ScriptSources come from this file? (It + // can be more than one in XML files that have + // multiple scripts in CDATA sections.) +#undef FOR_EACH_SIZE +}; + +// Holds data about a notable script source file (one whose combined +// script sources use more than a certain amount of memory) so we can report it +// individually. +// +// The only difference between this class and ScriptSourceInfo is that this +// class holds a copy of the filename. +struct NotableScriptSourceInfo : public ScriptSourceInfo +{ + NotableScriptSourceInfo(); + NotableScriptSourceInfo(const char *filename, const ScriptSourceInfo &info); + NotableScriptSourceInfo(NotableScriptSourceInfo &&info); + NotableScriptSourceInfo &operator=(NotableScriptSourceInfo &&info); + + ~NotableScriptSourceInfo() { + js_free(filename_); + } + + char *filename_; + + private: + NotableScriptSourceInfo(const NotableScriptSourceInfo& info) MOZ_DELETE; +}; + // These measurements relate directly to the JSRuntime, and not to zones and // compartments within it. struct RuntimeSizes @@ -292,81 +351,139 @@ struct RuntimeSizes macro(_, _, contexts) \ macro(_, _, dtoa) \ macro(_, _, temporary) \ - macro(_, _, regexpData) \ macro(_, _, interpreterStack) \ - macro(_, _, gcMarker) \ macro(_, _, mathCache) \ + macro(_, _, uncompressedSourceCache) \ + macro(_, _, compressedSourceSet) \ macro(_, _, scriptData) \ - macro(_, _, scriptSources) RuntimeSizes() : FOR_EACH_SIZE(ZERO_SIZE) - code() - {} + scriptSourceInfo(), + code(), + gc(), + notableScriptSources() + { + allScriptSources = js_new(); + if (!allScriptSources || !allScriptSources->init()) + MOZ_CRASH("oom"); + } + ~RuntimeSizes() { + // |allScriptSources| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allScriptSources); + } + + // The script source measurements in |scriptSourceInfo| are initially for + // all script sources. At the end, if the measurement granularity is + // FineGrained, we subtract the measurements of the notable script sources + // and move them into |notableScriptSources|. FOR_EACH_SIZE(DECL_SIZE) - CodeSizes code; + ScriptSourceInfo scriptSourceInfo; + CodeSizes code; + GCSizes gc; + + typedef js::HashMap ScriptSourcesHashMap; + + // |allScriptSources| is only used transiently. During the reporting phase + // it is filled with info about every script source in the runtime. It's + // then used to fill in |notableScriptSources| (which actually gets + // reported), and immediately discarded afterwards. + ScriptSourcesHashMap *allScriptSources; + js::Vector notableScriptSources; #undef FOR_EACH_SIZE }; -struct ZoneStats : js::ZoneStatsPod +struct ZoneStats { +#define FOR_EACH_SIZE(macro) \ + macro(Other, IsLiveGCThing, symbolsGCHeap) \ + macro(Other, NotLiveGCThing, gcHeapArenaAdmin) \ + macro(Other, NotLiveGCThing, unusedGCThings) \ + macro(Other, IsLiveGCThing, lazyScriptsGCHeap) \ + macro(Other, NotLiveGCThing, lazyScriptsMallocHeap) \ + macro(Other, IsLiveGCThing, jitCodesGCHeap) \ + macro(Other, IsLiveGCThing, typeObjectsGCHeap) \ + macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \ + macro(Other, NotLiveGCThing, typePool) \ + macro(Other, NotLiveGCThing, baselineStubsOptimized) \ + ZoneStats() - : strings(nullptr) + : FOR_EACH_SIZE(ZERO_SIZE) + stringInfo(), + extra(), + allStrings(nullptr), + notableStrings(), + isTotals(true) {} ZoneStats(ZoneStats &&other) - : ZoneStatsPod(mozilla::Move(other)), - strings(other.strings), - notableStrings(mozilla::Move(other.notableStrings)) + : FOR_EACH_SIZE(COPY_OTHER_SIZE) + stringInfo(mozilla::Move(other.stringInfo)), + extra(other.extra), + allStrings(other.allStrings), + notableStrings(mozilla::Move(other.notableStrings)), + isTotals(other.isTotals) { - other.strings = nullptr; + other.allStrings = nullptr; + MOZ_ASSERT(!other.isTotals); } - bool initStrings(JSRuntime *rt); - - // Add |other|'s numbers to this object's numbers. The strings data isn't - // touched. - void addIgnoringStrings(const ZoneStats &other) { - ZoneStatsPod::add(other); + ~ZoneStats() { + // |allStrings| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allStrings); } - // Add |other|'s strings data to this object's strings data. (We don't do - // anything with notableStrings.) - void addStrings(const ZoneStats &other) { - for (StringsHashMap::Range r = other.strings->all(); !r.empty(); r.popFront()) { - StringsHashMap::AddPtr p = strings->lookupForAdd(r.front().key()); - if (p) { - // We've seen this string before; add its size to our tally. - p->value().add(r.front().value()); - } else { - // We haven't seen this string before; add it to the hashtable. - strings->add(p, r.front().key(), r.front().value()); - } - } + bool initStrings(JSRuntime *rt); + + void addSizes(const ZoneStats &other) { + MOZ_ASSERT(isTotals); + FOR_EACH_SIZE(ADD_OTHER_SIZE) + stringInfo.add(other.stringInfo); } size_t sizeOfLiveGCThings() const { - size_t n = ZoneStatsPod::sizeOfLiveGCThings(); - for (size_t i = 0; i < notableStrings.length(); i++) { - const JS::NotableStringInfo& info = notableStrings[i]; - n += info.gcHeap; - } + MOZ_ASSERT(isTotals); + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + n += stringInfo.sizeOfLiveGCThings(); return n; } - typedef js::HashMap StringsHashMap; - // |strings| is only used transiently. During the zone traversal it is + // |allStrings| is only used transiently. During the zone traversal it is // filled with info about every string in the zone. It's then used to fill // in |notableStrings| (which actually gets reported), and immediately // discarded afterwards. - StringsHashMap *strings; + StringsHashMap *allStrings; js::Vector notableStrings; + bool isTotals; + +#undef FOR_EACH_SIZE }; struct CompartmentStats @@ -390,17 +507,16 @@ struct CompartmentStats macro(Other, NotLiveGCThing, scriptsMallocHeapData) \ macro(Other, NotLiveGCThing, baselineData) \ macro(Other, NotLiveGCThing, baselineStubsFallback) \ - macro(Other, NotLiveGCThing, baselineStubsOptimized) \ macro(Other, NotLiveGCThing, ionData) \ macro(Other, NotLiveGCThing, typeInferenceTypeScripts) \ - macro(Other, NotLiveGCThing, typeInferencePendingArrays) \ macro(Other, NotLiveGCThing, typeInferenceAllocationSiteTables) \ macro(Other, NotLiveGCThing, typeInferenceArrayTypeTables) \ macro(Other, NotLiveGCThing, typeInferenceObjectTypeTables) \ macro(Other, NotLiveGCThing, compartmentObject) \ macro(Other, NotLiveGCThing, crossCompartmentWrappersTable) \ macro(Other, NotLiveGCThing, regexpCompartment) \ - macro(Other, NotLiveGCThing, debuggeesSet) + macro(Other, NotLiveGCThing, debuggeesSet) \ + macro(Other, NotLiveGCThing, savedStacksSet) CompartmentStats() : FOR_EACH_SIZE(ZERO_SIZE) @@ -454,7 +570,7 @@ struct RuntimeStats macro(_, _, gcHeapChunkAdmin) \ macro(_, _, gcHeapGCThings) \ - RuntimeStats(mozilla::MallocSizeOf mallocSizeOf) + explicit RuntimeStats(mozilla::MallocSizeOf mallocSizeOf) : FOR_EACH_SIZE(ZERO_SIZE) runtime(), cTotals(), @@ -517,13 +633,13 @@ class ObjectPrivateVisitor typedef bool(*GetISupportsFun)(JSObject *obj, nsISupports **iface); GetISupportsFun getISupports_; - ObjectPrivateVisitor(GetISupportsFun getISupports) + explicit ObjectPrivateVisitor(GetISupportsFun getISupports) : getISupports_(getISupports) {} }; extern JS_PUBLIC_API(bool) -CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv); +CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv, bool anonymize); extern JS_PUBLIC_API(size_t) SystemCompartmentCount(JSRuntime *rt); @@ -544,6 +660,8 @@ AddSizeOfTab(JSRuntime *rt, JS::HandleObject obj, mozilla::MallocSizeOf mallocSi #undef ZERO_SIZE #undef COPY_OTHER_SIZE #undef ADD_OTHER_SIZE +#undef SUB_OTHER_SIZE +#undef ADD_SIZE_TO_N #undef ADD_SIZE_TO_N_IF_LIVE_GC_THING #undef ADD_TO_TAB_SIZES diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/OldDebugAPI.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/OldDebugAPI.h index 5e5bdf38d7..7117d754d9 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/OldDebugAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/OldDebugAPI.h @@ -12,47 +12,40 @@ */ #include "mozilla/NullPtr.h" - + +#include "jsapi.h" #include "jsbytecode.h" #include "js/CallArgs.h" #include "js/TypeDecls.h" class JSAtom; -class JSFreeOp; - -namespace js { class StackFrame; } +struct JSFreeOp; -namespace JS { - -struct FrameDescription -{ - JSScript *script; - unsigned lineno; - JSFunction *fun; -}; +namespace js { +class InterpreterFrame; +class FrameIter; +class ScriptSource; +} -struct StackDescription -{ - unsigned nframes; - FrameDescription *frames; -}; +// Raw JSScript* because this needs to be callable from a signal handler. +extern JS_PUBLIC_API(unsigned) +JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); -extern JS_PUBLIC_API(StackDescription *) -DescribeStack(JSContext *cx, unsigned maxFrames); +extern JS_PUBLIC_API(const char *) +JS_GetScriptFilename(JSScript *script); -extern JS_PUBLIC_API(void) -FreeStackDescription(JSContext *cx, StackDescription *desc); +namespace JS { extern JS_PUBLIC_API(char *) FormatStackDump(JSContext *cx, char *buf, bool showArgs, bool showLocals, bool showThisProps); -} +} // namespace JS -# ifdef DEBUG +# ifdef JS_DEBUG JS_FRIEND_API(void) js_DumpValue(const JS::Value &val); JS_FRIEND_API(void) js_DumpId(jsid id); -JS_FRIEND_API(void) js_DumpStackFrame(JSContext *cx, js::StackFrame *start = nullptr); +JS_FRIEND_API(void) js_DumpInterpreterFrame(JSContext *cx, js::InterpreterFrame *start = nullptr); # endif JS_FRIEND_API(void) @@ -70,48 +63,21 @@ typedef JSTrapStatus (* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, JS::Value closure); -typedef JSTrapStatus -(* JSInterruptHook)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, - void *closure); - typedef JSTrapStatus (* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, void *closure); -typedef JSTrapStatus -(* JSThrowHook)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, - void *closure); - typedef bool (* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, JS::Value old, JS::Value *newp, void *closure); -/* called just after script creation */ -typedef void -(* JSNewScriptHook)(JSContext *cx, - const char *filename, /* URL of script */ - unsigned lineno, /* first line */ - JSScript *script, - JSFunction *fun, - void *callerdata); - -/* called just before script destruction */ -typedef void -(* JSDestroyScriptHook)(JSFreeOp *fop, - JSScript *script, - void *callerdata); - -typedef void -(* JSSourceHandler)(const char *filename, unsigned lineno, const jschar *str, - size_t length, void **listenerTSData, void *closure); - extern JS_PUBLIC_API(JSCompartment *) JS_EnterCompartmentOfScript(JSContext *cx, JSScript *target); extern JS_PUBLIC_API(JSString *) -JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned indent); +JS_DecompileScript(JSContext *cx, JS::HandleScript script, const char *name, unsigned indent); /* * Currently, we only support runtime-wide debugging. In the future, we should @@ -157,12 +123,12 @@ JS_SetDebugMode(JSContext *cx, bool debug); /* Turn on single step mode. */ extern JS_PUBLIC_API(bool) -JS_SetSingleStepMode(JSContext *cx, JSScript *script, bool singleStep); +JS_SetSingleStepMode(JSContext *cx, JS::HandleScript script, bool singleStep); /* The closure argument will be marked. */ extern JS_PUBLIC_API(bool) -JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc, - JSTrapHandler handler, JS::Value closure); +JS_SetTrap(JSContext *cx, JS::HandleScript script, jsbytecode *pc, + JSTrapHandler handler, JS::HandleValue closure); extern JS_PUBLIC_API(void) JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc, @@ -174,17 +140,11 @@ JS_ClearScriptTraps(JSRuntime *rt, JSScript *script); extern JS_PUBLIC_API(void) JS_ClearAllTrapsForCompartment(JSContext *cx); -extern JS_PUBLIC_API(bool) -JS_SetInterrupt(JSRuntime *rt, JSInterruptHook handler, void *closure); - -extern JS_PUBLIC_API(bool) -JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *handlerp, void **closurep); - /************************************************************************/ extern JS_PUBLIC_API(bool) -JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsid id, - JSWatchPointHandler handler, JSObject *closure); +JS_SetWatchPoint(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JSWatchPointHandler handler, JS::HandleObject closure); extern JS_PUBLIC_API(bool) JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id, @@ -195,10 +155,6 @@ JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj); /************************************************************************/ -// Raw JSScript* because this needs to be callable from a signal handler. -extern JS_PUBLIC_API(unsigned) -JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); - extern JS_PUBLIC_API(jsbytecode *) JS_LineNumberToPC(JSContext *cx, JSScript *script, unsigned lineno); @@ -234,17 +190,11 @@ extern JS_PUBLIC_API(void) JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mark); extern JS_PUBLIC_API(JSScript *) -JS_GetFunctionScript(JSContext *cx, JSFunction *fun); +JS_GetFunctionScript(JSContext *cx, JS::HandleFunction fun); extern JS_PUBLIC_API(JSNative) JS_GetFunctionNative(JSContext *cx, JSFunction *fun); -extern JS_PUBLIC_API(JSPrincipals *) -JS_GetScriptPrincipals(JSScript *script); - -extern JS_PUBLIC_API(JSPrincipals *) -JS_GetScriptOriginPrincipals(JSScript *script); - JS_PUBLIC_API(JSFunction *) JS_GetScriptFunction(JSContext *cx, JSScript *script); @@ -264,9 +214,6 @@ JS_GetDebugClassName(JSObject *obj); /************************************************************************/ -extern JS_PUBLIC_API(const char *) -JS_GetScriptFilename(JSContext *cx, JSScript *script); - extern JS_PUBLIC_API(const jschar *) JS_GetScriptSourceMap(JSContext *cx, JSScript *script); @@ -284,22 +231,6 @@ JS_GetScriptIsSelfHosted(JSScript *script); /************************************************************************/ -/* - * Hook setters for script creation and destruction. These macros provide - * binary compatibility and newer, shorter synonyms. - */ -#define JS_SetNewScriptHook JS_SetNewScriptHookProc -#define JS_SetDestroyScriptHook JS_SetDestroyScriptHookProc - -extern JS_PUBLIC_API(void) -JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata); - -extern JS_PUBLIC_API(void) -JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook, - void *callerdata); - -/************************************************************************/ - typedef struct JSPropertyDesc { JS::Value id; /* primary id, atomized string, or int */ JS::Value value; /* property value */ @@ -325,7 +256,7 @@ typedef struct JSPropertyDescArray { typedef struct JSScopeProperty JSScopeProperty; extern JS_PUBLIC_API(bool) -JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda); +JS_GetPropertyDescArray(JSContext *cx, JS::HandleObject obj, JSPropertyDescArray *pda); extern JS_PUBLIC_API(void) JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); @@ -339,16 +270,18 @@ JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); class JS_PUBLIC_API(JSAbstractFramePtr) { uintptr_t ptr_; + jsbytecode *pc_; protected: JSAbstractFramePtr() - : ptr_(0) + : ptr_(0), pc_(nullptr) { } public: - explicit JSAbstractFramePtr(void *raw); + JSAbstractFramePtr(void *raw, jsbytecode *pc); uintptr_t raw() const { return ptr_; } + jsbytecode *pc() const { return pc_; } operator bool() const { return !!ptr_; } @@ -393,7 +326,7 @@ class JS_PUBLIC_API(JSBrokenFrameIterator) void *data_; public: - JSBrokenFrameIterator(JSContext *cx); + explicit JSBrokenFrameIterator(JSContext *cx); ~JSBrokenFrameIterator(); bool done() const; @@ -405,58 +338,13 @@ class JS_PUBLIC_API(JSBrokenFrameIterator) bool isConstructing() const; }; -/* - * This hook captures high level script execution and function calls (JS or - * native). It is used by JS_SetExecuteHook to hook top level scripts and by - * JS_SetCallHook to hook function calls. It will get called twice per script - * or function call: just before execution begins and just after it finishes. - * In both cases the 'current' frame is that of the executing code. - * - * The 'before' param is true for the hook invocation before the execution - * and false for the invocation after the code has run. - * - * The 'ok' param is significant only on the post execution invocation to - * signify whether or not the code completed 'normally'. - * - * The 'closure' param is as passed to JS_SetExecuteHook or JS_SetCallHook - * for the 'before'invocation, but is whatever value is returned from that - * invocation for the 'after' invocation. Thus, the hook implementor *could* - * allocate a structure in the 'before' invocation and return a pointer to that - * structure. The pointer would then be handed to the hook for the 'after' - * invocation. Alternately, the 'before' could just return the same value as - * in 'closure' to cause the 'after' invocation to be called with the same - * 'closure' value as the 'before'. - * - * Returning nullptr in the 'before' hook will cause the 'after' hook *not* to - * be called. - */ -typedef void * -(* JSInterpreterHook)(JSContext *cx, JSAbstractFramePtr frame, bool isConstructing, - bool before, bool *ok, void *closure); - typedef bool (* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report, void *closure); typedef struct JSDebugHooks { - JSInterruptHook interruptHook; - void *interruptHookData; - JSNewScriptHook newScriptHook; - void *newScriptHookData; - JSDestroyScriptHook destroyScriptHook; - void *destroyScriptHookData; JSDebuggerHandler debuggerHandler; void *debuggerHandlerData; - JSSourceHandler sourceHandler; - void *sourceHandlerData; - JSInterpreterHook executeHook; - void *executeHookData; - JSInterpreterHook callHook; - void *callHookData; - JSThrowHook throwHook; - void *throwHookData; - JSDebugErrorHook debugErrorHook; - void *debugErrorHookData; } JSDebugHooks; /************************************************************************/ @@ -464,21 +352,6 @@ typedef struct JSDebugHooks { extern JS_PUBLIC_API(bool) JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler hook, void *closure); -extern JS_PUBLIC_API(bool) -JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetThrowHook(JSRuntime *rt, JSThrowHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure); - /************************************************************************/ extern JS_PUBLIC_API(const JSDebugHooks *) @@ -492,16 +365,10 @@ JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj); /* Defined in vm/Debugger.cpp. */ extern JS_PUBLIC_API(bool) -JS_DefineDebuggerObject(JSContext *cx, JSObject *obj); - -extern JS_PUBLIC_API(void) -JS_DumpBytecode(JSContext *cx, JSScript *script); - -extern JS_PUBLIC_API(void) -JS_DumpCompartmentBytecode(JSContext *cx); +JS_DefineDebuggerObject(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(void) -JS_DumpPCCounts(JSContext *cx, JSScript *script); +JS_DumpPCCounts(JSContext *cx, JS::HandleScript script); extern JS_PUBLIC_API(void) JS_DumpCompartmentPCCounts(JSContext *cx); diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/Principals.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/Principals.h new file mode 100644 index 0000000000..78d8c7e893 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/Principals.h @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JSPrincipals and related interfaces. */ + +#ifndef js_Principals_h +#define js_Principals_h + +#include "mozilla/Atomics.h" + +#include + +#include "jspubtd.h" + +struct JSPrincipals { + /* Don't call "destroy"; use reference counting macros below. */ +#ifdef JS_THREADSAFE + mozilla::Atomic refcount; +#else + int32_t refcount; +#endif + +#ifdef JS_DEBUG + /* A helper to facilitate principals debugging. */ + uint32_t debugToken; +#endif + + void setDebugToken(uint32_t token) { +# ifdef JS_DEBUG + debugToken = token; +# endif + } + + /* + * This is not defined by the JS engine but should be provided by the + * embedding. + */ + JS_PUBLIC_API(void) dump(); +}; + +extern JS_PUBLIC_API(void) +JS_HoldPrincipals(JSPrincipals *principals); + +extern JS_PUBLIC_API(void) +JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals); + +// Return whether the first principal subsumes the second. The exact meaning of +// 'subsumes' is left up to the browser. Subsumption is checked inside the JS +// engine when determining, e.g., which stack frames to display in a backtrace. +typedef bool +(* JSSubsumesOp)(JSPrincipals *first, JSPrincipals *second); + +/* + * Used to check if a CSP instance wants to disable eval() and friends. + * See js_CheckCSPPermitsJSAction() in jsobj. + */ +typedef bool +(* JSCSPEvalChecker)(JSContext *cx); + +struct JSSecurityCallbacks { + JSCSPEvalChecker contentSecurityPolicyAllows; + JSSubsumesOp subsumes; +}; + +extern JS_PUBLIC_API(void) +JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks); + +extern JS_PUBLIC_API(const JSSecurityCallbacks *) +JS_GetSecurityCallbacks(JSRuntime *rt); + +/* + * Code running with "trusted" principals will be given a deeper stack + * allocation than ordinary scripts. This allows trusted script to run after + * untrusted script has exhausted the stack. This function sets the + * runtime-wide trusted principal. + * + * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since + * there is no available JSContext. Instead, the caller must ensure that the + * given principals stays valid for as long as 'rt' may point to it. If the + * principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be + * called again, passing nullptr for 'prin'. + */ +extern JS_PUBLIC_API(void) +JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin); + +typedef void +(* JSDestroyPrincipalsOp)(JSPrincipals *principals); + +/* + * Initialize the callback that is called to destroy JSPrincipals instance + * when its reference counter drops to zero. The initialization can be done + * only once per JS runtime. + */ +extern JS_PUBLIC_API(void) +JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals); + +#endif /* js_Principals_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/ProfilingStack.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/ProfilingStack.h index 213e47bb7d..e82ce1c9d8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/ProfilingStack.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/ProfilingStack.h @@ -8,7 +8,8 @@ #define js_ProfilingStack_h #include "mozilla/NullPtr.h" - +#include "mozilla/TypedEnum.h" + #include "jsbytecode.h" #include "jstypes.h" @@ -34,50 +35,120 @@ class ProfileEntry // If the size modification were somehow reordered before the stores, then // if a sample were taken it would be examining bogus information. // - // A ProfileEntry represents both a C++ profile entry and a JS one. Both use - // the string as a description, but JS uses the sp as nullptr to indicate - // that it is a JS entry. The script_ is then only ever examined for a JS - // entry, and the idx is used by both, but with different meanings. - // - const char * volatile string; // Descriptive string of this entry - void * volatile sp; // Relevant stack pointer for the entry - JSScript * volatile script_; // if js(), non-null script which is running - int32_t volatile idx; // if js(), idx of pc, otherwise line number + // A ProfileEntry represents both a C++ profile entry and a JS one. + + // Descriptive string of this entry. + const char * volatile string; + + // Stack pointer for non-JS entries, the script pointer otherwise. + void * volatile spOrScript; + + // Line number for non-JS entries, the bytecode offset otherwise. + int32_t volatile lineOrPc; + + // General purpose storage describing this frame. + uint32_t volatile flags_; public: + // These traits are bit masks. Make sure they're powers of 2. + enum Flags { + // Indicate whether a profile entry represents a CPP frame. If not set, + // a JS frame is assumed by default. You're not allowed to publicly + // change the frame type. Instead, call `setJsFrame` or `setCppFrame`. + IS_CPP_ENTRY = 0x01, + + // Indicate that copying the frame label is not necessary when taking a + // sample of the pseudostack. + FRAME_LABEL_COPY = 0x02, + + // Mask for removing all flags except the category information. + CATEGORY_MASK = ~IS_CPP_ENTRY & ~FRAME_LABEL_COPY + }; + + MOZ_BEGIN_NESTED_ENUM_CLASS(Category, uint32_t) + OTHER = 0x04, + CSS = 0x08, + JS = 0x10, + GC = 0x20, + CC = 0x40, + NETWORK = 0x80, + GRAPHICS = 0x100, + STORAGE = 0x200, + EVENTS = 0x400, + + FIRST = OTHER, + LAST = EVENTS + MOZ_END_NESTED_ENUM_CLASS(Category) + // All of these methods are marked with the 'volatile' keyword because SPS's // representation of the stack is stored such that all ProfileEntry // instances are volatile. These methods would not be available unless they // were marked as volatile as well. - bool js() const volatile { - JS_ASSERT_IF(sp == nullptr, script_ != nullptr); - return sp == nullptr; - } + bool isCpp() const volatile { return hasFlag(IS_CPP_ENTRY); } + bool isJs() const volatile { return !isCpp(); } - uint32_t line() const volatile { JS_ASSERT(!js()); return idx; } - JSScript *script() const volatile { JS_ASSERT(js()); return script_; } - void *stackAddress() const volatile { return sp; } - const char *label() const volatile { return string; } + bool isCopyLabel() const volatile { return hasFlag(FRAME_LABEL_COPY); }; - void setLine(uint32_t aLine) volatile { JS_ASSERT(!js()); idx = aLine; } void setLabel(const char *aString) volatile { string = aString; } - void setStackAddress(void *aSp) volatile { sp = aSp; } - void setScript(JSScript *aScript) volatile { script_ = aScript; } + const char *label() const volatile { return string; } + + void setJsFrame(JSScript *aScript, jsbytecode *aPc) volatile { + flags_ = 0; + spOrScript = aScript; + setPC(aPc); + } + void setCppFrame(void *aSp, uint32_t aLine) volatile { + flags_ = IS_CPP_ENTRY; + spOrScript = aSp; + lineOrPc = static_cast(aLine); + } + + void setFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ |= flag; + } + void unsetFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ &= ~flag; + } + bool hasFlag(uint32_t flag) const volatile { + return bool(flags_ & flag); + } + + uint32_t flags() const volatile { + return flags_; + } + uint32_t category() const volatile { + return flags_ & CATEGORY_MASK; + } + + void *stackAddress() const volatile { + MOZ_ASSERT(!isJs()); + return spOrScript; + } + JSScript *script() const volatile { + MOZ_ASSERT(isJs()); + return (JSScript *)spOrScript; + } + uint32_t line() const volatile { + MOZ_ASSERT(!isJs()); + return static_cast(lineOrPc); + } // We can't know the layout of JSScript, so look in vm/SPSProfiler.cpp. JS_FRIEND_API(jsbytecode *) pc() const volatile; JS_FRIEND_API(void) setPC(jsbytecode *pc) volatile; - static size_t offsetOfString() { return offsetof(ProfileEntry, string); } - static size_t offsetOfStackAddress() { return offsetof(ProfileEntry, sp); } - static size_t offsetOfPCIdx() { return offsetof(ProfileEntry, idx); } - static size_t offsetOfScript() { return offsetof(ProfileEntry, script_); } + // The offset of a pc into a script's code can actually be 0, so to + // signify a nullptr pc, use a -1 index. This is checked against in + // pc() and setPC() to set/get the right pc. + static const int32_t NullPCOffset = -1; - // The index used in the entry can either be a line number or the offset of - // a pc into a script's code. To signify a nullptr pc, use a -1 index. This - // is checked against in pc() and setPC() to set/get the right pc. - static const int32_t NullPCIndex = -1; + static size_t offsetOfLabel() { return offsetof(ProfileEntry, string); } + static size_t offsetOfSpOrScript() { return offsetof(ProfileEntry, spOrScript); } + static size_t offsetOfLineOrPc() { return offsetof(ProfileEntry, lineOrPc); } + static size_t offsetOfFlags() { return offsetof(ProfileEntry, flags_); } }; JS_FRIEND_API(void) @@ -87,6 +158,9 @@ SetRuntimeProfilingStack(JSRuntime *rt, ProfileEntry *stack, uint32_t *size, JS_FRIEND_API(void) EnableRuntimeProfilingStack(JSRuntime *rt, bool enabled); +JS_FRIEND_API(void) +RegisterRuntimeProfilingEventMarker(JSRuntime *rt, void (*fn)(const char *)); + JS_FRIEND_API(jsbytecode*) ProfilingGetPC(JSRuntime *rt, JSScript *script, void *ip); diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/RequiredDefines.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/RequiredDefines.h index 3c8f429132..308fd7d625 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/RequiredDefines.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/RequiredDefines.h @@ -28,4 +28,7 @@ #define __STDC_CONSTANT_MACROS #define __STDC_FORMAT_MACROS +/* Also define a char16_t type if not provided by the compiler. */ +#include "mozilla/Char16.h" + #endif /* js_RequiredDefines_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/RootingAPI.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/RootingAPI.h index 5b612660cd..621a1e4394 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/RootingAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/RootingAPI.h @@ -15,6 +15,8 @@ #include "jspubtd.h" +#include "js/GCAPI.h" +#include "js/HeapAPI.h" #include "js/TypeDecls.h" #include "js/Utility.h" @@ -138,6 +140,8 @@ struct NullPtr namespace gc { struct Cell; +template +struct PersistentRootedMarker; } /* namespace gc */ } /* namespace js */ @@ -150,11 +154,6 @@ template class PersistentRooted; /* This is exposing internal state of the GC for inlining purposes. */ JS_FRIEND_API(bool) isGCEnabled(); -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) -extern void -CheckStackRoots(JSContext *cx); -#endif - /* * JS::NullPtr acts like a nullptr pointer in contexts that require a Handle. * @@ -198,6 +197,13 @@ class Heap : public js::HeapBase init(js::GCMethods::initial()); } explicit Heap(T p) { init(p); } + + /* + * For Heap, move semantics are equivalent to copy semantics. In C++, a + * copy constructor taking const-ref is the way to get a single function + * that will be used for both lvalue and rvalue copies, so we can simply + * omit the rvalue variant. + */ explicit Heap(const Heap &p) { init(p.ptr); } ~Heap() { @@ -229,7 +235,7 @@ class Heap : public js::HeapBase } void set(T newPtr) { - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); if (js::GCMethods::needsPostBarrier(newPtr)) { ptr = newPtr; post(); @@ -241,9 +247,21 @@ class Heap : public js::HeapBase } } + /* + * Set the pointer to a value which will cause a crash if it is + * dereferenced. + */ + void setToCrashOnTouch() { + ptr = reinterpret_cast(crashOnTouchPointer); + } + + bool isSetToCrashOnTouch() { + return ptr == crashOnTouchPointer; + } + private: void init(T newPtr) { - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); ptr = newPtr; if (js::GCMethods::needsPostBarrier(ptr)) post(); @@ -251,7 +269,7 @@ class Heap : public js::HeapBase void post() { #ifdef JSGC_GENERATIONAL - JS_ASSERT(js::GCMethods::needsPostBarrier(ptr)); + MOZ_ASSERT(js::GCMethods::needsPostBarrier(ptr)); js::GCMethods::postBarrier(&ptr); #endif } @@ -262,10 +280,14 @@ class Heap : public js::HeapBase #endif } + enum { + crashOnTouchPointer = 1 + }; + T ptr; }; -#ifdef DEBUG +#ifdef JS_DEBUG /* * For generational GC, assert that an object is in the tenured generation as * opposed to being in the nursery. @@ -315,31 +337,31 @@ class TenuredHeap : public js::HeapBase "TenuredHeap must be binary compatible with T."); } explicit TenuredHeap(T p) : bits(0) { setPtr(p); } - explicit TenuredHeap(const TenuredHeap &p) : bits(0) { setPtr(p.ptr); } + explicit TenuredHeap(const TenuredHeap &p) : bits(0) { setPtr(p.getPtr()); } bool operator==(const TenuredHeap &other) { return bits == other.bits; } bool operator!=(const TenuredHeap &other) { return bits != other.bits; } void setPtr(T newPtr) { - JS_ASSERT((reinterpret_cast(newPtr) & flagsMask) == 0); - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT((reinterpret_cast(newPtr) & flagsMask) == 0); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); if (newPtr) AssertGCThingMustBeTenured(newPtr); bits = (bits & flagsMask) | reinterpret_cast(newPtr); } void setFlags(uintptr_t flagsToSet) { - JS_ASSERT((flagsToSet & ~flagsMask) == 0); + MOZ_ASSERT((flagsToSet & ~flagsMask) == 0); bits |= flagsToSet; } void unsetFlags(uintptr_t flagsToUnset) { - JS_ASSERT((flagsToUnset & ~flagsMask) == 0); + MOZ_ASSERT((flagsToUnset & ~flagsMask) == 0); bits &= ~flagsToUnset; } bool hasFlag(uintptr_t flag) const { - JS_ASSERT((flag & ~flagsMask) == 0); + MOZ_ASSERT((flag & ~flagsMask) == 0); return (bits & flag) != 0; } @@ -359,23 +381,10 @@ class TenuredHeap : public js::HeapBase return *this; } - /* - * Set the pointer to a value which will cause a crash if it is - * dereferenced. - */ - void setToCrashOnTouch() { - bits = (bits & flagsMask) | crashOnTouchPointer; - } - - bool isSetToCrashOnTouch() { - return (bits & ~flagsMask) == crashOnTouchPointer; - } - private: enum { maskBits = 3, flagsMask = (1 << maskBits) - 1, - crashOnTouchPointer = 1 << maskBits }; uintptr_t bits; @@ -406,20 +415,20 @@ class MOZ_NONHEAP_CLASS Handle : public js::HandleBase } /* Create a handle for a nullptr pointer. */ - Handle(js::NullPtr) { + MOZ_IMPLICIT Handle(js::NullPtr) { static_assert(mozilla::IsPointer::value, "js::NullPtr overload not valid for non-pointer types"); ptr = reinterpret_cast(&js::NullPtr::constNullValue); } /* Create a handle for a nullptr pointer. */ - Handle(JS::NullPtr) { + MOZ_IMPLICIT Handle(JS::NullPtr) { static_assert(mozilla::IsPointer::value, "JS::NullPtr overload not valid for non-pointer types"); ptr = reinterpret_cast(&JS::NullPtr::constNullValue); } - Handle(MutableHandle handle) { + MOZ_IMPLICIT Handle(MutableHandle handle) { ptr = handle.address(); } @@ -476,9 +485,6 @@ class MOZ_NONHEAP_CLASS Handle : public js::HandleBase bool operator!=(const T &other) const { return *ptr != other; } bool operator==(const T &other) const { return *ptr == other; } - /* Change this handle to point to the same rooted location RHS does. */ - void repoint(const Handle &rhs) { ptr = rhs.address(); } - private: Handle() {} @@ -504,15 +510,23 @@ template class MOZ_STACK_CLASS MutableHandle : public js::MutableHandleBase { public: - inline MutableHandle(Rooted *root); - inline MutableHandle(PersistentRooted *root); - MutableHandle(int) MOZ_DELETE; -#ifdef MOZ_HAVE_CXX11_NULLPTR - MutableHandle(decltype(nullptr)) MOZ_DELETE; -#endif + inline MOZ_IMPLICIT MutableHandle(Rooted *root); + inline MOZ_IMPLICIT MutableHandle(PersistentRooted *root); + + private: + // Disallow true nullptr and emulated nullptr (gcc 4.4/4.5, __null, appears + // as int/long [32/64-bit]) for overloading purposes. + template + MutableHandle(N, + typename mozilla::EnableIf::value || + mozilla::IsSame::value || + mozilla::IsSame::value, + int>::Type dummy = 0) + MOZ_DELETE; + public: void set(T v) { - JS_ASSERT(!js::GCMethods::poisoned(v)); + MOZ_ASSERT(!js::GCMethods::poisoned(v)); *ptr = v; } @@ -549,8 +563,8 @@ class MOZ_STACK_CLASS MutableHandle : public js::MutableHandleBase }; #ifdef JSGC_GENERATIONAL -JS_PUBLIC_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); -JS_PUBLIC_API(void) HeapCellRelocate(js::gc::Cell **cellp); +JS_FRIEND_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); +JS_FRIEND_API(void) HeapCellRelocate(js::gc::Cell **cellp); #endif } /* namespace JS */ @@ -612,7 +626,7 @@ class InternalHandle * Make this private to prevent accidental misuse; this is only for * fromMarkedLocation(). */ - InternalHandle(T *field) + explicit InternalHandle(T *field) : holder(reinterpret_cast(&js::NullPtr::constNullValue)), offset(uintptr_t(field)) {} @@ -621,10 +635,16 @@ class InternalHandle }; /* - * By default, pointers should use the inheritance hierarchy to find their + * By default, things should use the inheritance hierarchy to find their * ThingRootKind. Some pointer types are explicitly set in jspubtd.h so that * Rooted may be used without the class definition being available. */ +template +struct RootKind +{ + static ThingRootKind rootKind() { return T::rootKind(); } +}; + template struct RootKind { @@ -635,20 +655,51 @@ template struct GCMethods { static T *initial() { return nullptr; } - static ThingRootKind kind() { return RootKind::rootKind(); } static bool poisoned(T *v) { return JS::IsPoisonedPtr(v); } - static bool needsPostBarrier(T *v) { return v; } + static bool needsPostBarrier(T *v) { return false; } #ifdef JSGC_GENERATIONAL - static void postBarrier(T **vp) { + static void postBarrier(T **vp) {} + static void relocate(T **vp) {} +#endif +}; + +template <> +struct GCMethods +{ + static JSObject *initial() { return nullptr; } + static bool poisoned(JSObject *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSObject *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSObject **vp) { JS::HeapCellPostBarrier(reinterpret_cast(vp)); } - static void relocate(T **vp) { + static void relocate(JSObject **vp) { JS::HeapCellRelocate(reinterpret_cast(vp)); } #endif }; -#if defined(DEBUG) +template <> +struct GCMethods +{ + static JSFunction *initial() { return nullptr; } + static bool poisoned(JSFunction *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSFunction *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSFunction **vp) { + JS::HeapCellPostBarrier(reinterpret_cast(vp)); + } + static void relocate(JSFunction **vp) { + JS::HeapCellRelocate(reinterpret_cast(vp)); + } +#endif +}; + +#ifdef JS_DEBUG /* This helper allows us to assert that Rooted is scoped within a request. */ extern JS_PUBLIC_API(bool) IsInRequest(JSContext *cx); @@ -673,22 +724,24 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase template void init(CX *cx) { #ifdef JSGC_TRACK_EXACT_ROOTS - js::ThingRootKind kind = js::GCMethods::kind(); + js::ThingRootKind kind = js::RootKind::rootKind(); this->stack = &cx->thingGCRooters[kind]; this->prev = *stack; *stack = reinterpret_cast*>(this); - JS_ASSERT(!js::GCMethods::poisoned(ptr)); + MOZ_ASSERT(!js::GCMethods::poisoned(ptr)); #endif } public: - Rooted(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG MOZ_ASSERT(js::IsInRequest(cx)); +#endif init(js::ContextFriendFields::get(cx)); } @@ -697,12 +750,14 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase : ptr(initial) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG MOZ_ASSERT(js::IsInRequest(cx)); +#endif init(js::ContextFriendFields::get(cx)); } - Rooted(js::ContextFriendFields *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(js::ContextFriendFields *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -717,8 +772,8 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase init(cx); } - Rooted(js::PerThreadDataFriendFields *pt - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(js::PerThreadDataFriendFields *pt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -733,8 +788,8 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase init(pt); } - Rooted(JSRuntime *rt - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(JSRuntime *rt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -754,13 +809,13 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase // using MSVC, see bug 915735 for more details. #ifdef JSGC_TRACK_EXACT_ROOTS ~Rooted() { - JS_ASSERT(*stack == reinterpret_cast*>(this)); + MOZ_ASSERT(*stack == reinterpret_cast*>(this)); *stack = prev; } #endif #ifdef JSGC_TRACK_EXACT_ROOTS - Rooted *previous() { return prev; } + Rooted *previous() { return reinterpret_cast*>(prev); } #endif /* @@ -775,7 +830,7 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase const T &get() const { return ptr; } T &operator=(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; return ptr; } @@ -786,7 +841,7 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase } void set(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; } @@ -795,16 +850,12 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase private: #ifdef JSGC_TRACK_EXACT_ROOTS - Rooted **stack, *prev; -#endif - -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* Has the rooting analysis ever scanned this Rooted's stack location? */ - friend void JS::CheckStackRoots(JSContext*); -#endif - -#ifdef JSGC_ROOT_ANALYSIS - bool scanned; + /* + * These need to be templated on void* to avoid aliasing issues between, for + * example, Rooted and Rooted, which use the same + * stack head pointer for different classes. + */ + Rooted **stack, *prev; #endif /* @@ -818,90 +869,26 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase Rooted(const Rooted &) MOZ_DELETE; }; -#if !(defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)) -// Defined in vm/String.h. -template <> -class Rooted; -#endif - } /* namespace JS */ namespace js { /* - * Mark a stack location as a root for the rooting analysis, without actually - * rooting it in release builds. This should only be used for stack locations - * of GC things that cannot be relocated by a garbage collection, and that - * are definitely reachable via another path. + * Augment the generic Rooted interface when T = JSObject* with + * class-querying and downcasting operations. + * + * Given a Rooted obj, one can view + * Handle h = obj.as(); + * as an optimization of + * Rooted rooted(cx, &obj->as()); + * Handle h = rooted; */ -class SkipRoot +template <> +class RootedBase { -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - - SkipRoot **stack, *prev; - const uint8_t *start; - const uint8_t *end; - - template - void init(CX *cx, const T *ptr, size_t count) { - SkipRoot **head = &cx->skipGCRooters; - this->stack = head; - this->prev = *stack; - *stack = this; - this->start = (const uint8_t *) ptr; - this->end = this->start + (sizeof(T) * count); - } - public: - ~SkipRoot() { - JS_ASSERT(*stack == this); - *stack = prev; - } - - SkipRoot *previous() { return prev; } - - bool contains(const uint8_t *v, size_t len) { - return v >= start && v + len <= end; - } - -#else /* DEBUG && JSGC_ROOT_ANALYSIS */ - - template - void init(js::ContextFriendFields *cx, const T *ptr, size_t count) {} - - public: - ~SkipRoot() { - // An empty destructor is needed to avoid warnings from clang about - // unused local variables of this type. - } - -#endif /* DEBUG && JSGC_ROOT_ANALYSIS */ - - template - SkipRoot(JSContext *cx, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(ContextFriendFields::get(cx), ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - template - SkipRoot(ContextFriendFields *cx, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(cx, ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - template - SkipRoot(PerThreadData *pt, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(PerThreadDataFriendFields::get(pt), ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + template + JS::Handle as() const; }; /* Interface substitute for Rooted which does not root the variable's memory. */ @@ -933,13 +920,13 @@ class FakeRooted : public RootedBase const T &get() const { return ptr; } FakeRooted &operator=(T value) { - JS_ASSERT(!GCMethods::poisoned(value)); + MOZ_ASSERT(!GCMethods::poisoned(value)); ptr = value; return *this; } FakeRooted &operator=(const FakeRooted &other) { - JS_ASSERT(!GCMethods::poisoned(other.ptr)); + MOZ_ASSERT(!GCMethods::poisoned(other.ptr)); ptr = other.ptr; return *this; } @@ -960,16 +947,16 @@ template class FakeMutableHandle : public js::MutableHandleBase { public: - FakeMutableHandle(T *t) { + MOZ_IMPLICIT FakeMutableHandle(T *t) { ptr = t; } - FakeMutableHandle(FakeRooted *root) { + MOZ_IMPLICIT FakeMutableHandle(FakeRooted *root) { ptr = root->address(); } void set(T v) { - JS_ASSERT(!js::GCMethods::poisoned(v)); + MOZ_ASSERT(!js::GCMethods::poisoned(v)); *ptr = v; } @@ -992,7 +979,7 @@ class FakeMutableHandle : public js::MutableHandleBase /* * Types for a variable that either should or shouldn't be rooted, depending on - * the template parameter Rooted. Used for implementing functions that can + * the template parameter allowGC. Used for implementing functions that can * operate on either rooted or unrooted data. * * The toHandle() and toMutableHandle() functions are for calling functions @@ -1031,12 +1018,12 @@ template class MaybeRooted typedef FakeRooted RootType; typedef FakeMutableHandle MutableHandleType; - static inline JS::Handle toHandle(HandleType v) { - MOZ_ASSUME_UNREACHABLE("Bad conversion"); + static JS::Handle toHandle(HandleType v) { + MOZ_CRASH("Bad conversion"); } - static inline JS::MutableHandle toMutableHandle(MutableHandleType v) { - MOZ_ASSUME_UNREACHABLE("Bad conversion"); + static JS::MutableHandle toMutableHandle(MutableHandleType v) { + MOZ_CRASH("Bad conversion"); } }; @@ -1086,7 +1073,6 @@ MutableHandle::MutableHandle(PersistentRooted *root) ptr = root->address(); } - /* * A copyable, assignable global GC root type with arbitrary lifetime, an * infallible constructor, and automatic unrooting on destruction. @@ -1120,9 +1106,11 @@ MutableHandle::MutableHandle(PersistentRooted *root) * marked when the object itself is marked. */ template -class PersistentRooted : public mozilla::LinkedListElement > { - typedef mozilla::LinkedList List; - typedef mozilla::LinkedListElement Element; +class PersistentRooted : private mozilla::LinkedListElement > { + friend class mozilla::LinkedList; + friend class mozilla::LinkedListElement; + + friend struct js::gc::PersistentRootedMarker; void registerWithRuntime(JSRuntime *rt) { JS::shadow::Runtime *srt = JS::shadow::Runtime::asShadowRuntime(rt); @@ -1130,7 +1118,7 @@ class PersistentRooted : public mozilla::LinkedListElement > } public: - PersistentRooted(JSContext *cx) : ptr(js::GCMethods::initial()) + explicit PersistentRooted(JSContext *cx) : ptr(js::GCMethods::initial()) { registerWithRuntime(js::GetRuntime(cx)); } @@ -1140,7 +1128,7 @@ class PersistentRooted : public mozilla::LinkedListElement > registerWithRuntime(js::GetRuntime(cx)); } - PersistentRooted(JSRuntime *rt) : ptr(js::GCMethods::initial()) + explicit PersistentRooted(JSRuntime *rt) : ptr(js::GCMethods::initial()) { registerWithRuntime(rt); } @@ -1150,14 +1138,19 @@ class PersistentRooted : public mozilla::LinkedListElement > registerWithRuntime(rt); } - PersistentRooted(PersistentRooted &rhs) : ptr(rhs.ptr) + PersistentRooted(const PersistentRooted &rhs) + : mozilla::LinkedListElement >(), + ptr(rhs.ptr) { /* * Copy construction takes advantage of the fact that the original * is already inserted, and simply adds itself to whatever list the * original was on - no JSRuntime pointer needed. + * + * This requires mutating rhs's links, but those should be 'mutable' + * anyway. C++ doesn't let us declare mutable base classes. */ - rhs.setNext(this); + const_cast(rhs).setNext(this); } /* @@ -1172,7 +1165,7 @@ class PersistentRooted : public mozilla::LinkedListElement > const T &get() const { return ptr; } T &operator=(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; return ptr; } @@ -1183,7 +1176,7 @@ class PersistentRooted : public mozilla::LinkedListElement > } void set(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; } @@ -1194,26 +1187,56 @@ class PersistentRooted : public mozilla::LinkedListElement > T ptr; }; +class JS_PUBLIC_API(ObjectPtr) +{ + Heap value; + + public: + ObjectPtr() : value(nullptr) {} + + explicit ObjectPtr(JSObject *obj) : value(obj) {} + + /* Always call finalize before the destructor. */ + ~ObjectPtr() { MOZ_ASSERT(!value); } + + void finalize(JSRuntime *rt) { + if (IsIncrementalBarrierNeeded(rt)) + IncrementalObjectBarrier(value); + value = nullptr; + } + + void init(JSObject *obj) { value = obj; } + + JSObject *get() const { return value; } + + void writeBarrierPre(JSRuntime *rt) { + IncrementalObjectBarrier(value); + } + + bool isAboutToBeFinalized(); + + ObjectPtr &operator=(JSObject *obj) { + IncrementalObjectBarrier(value); + value = obj; + return *this; + } + + void trace(JSTracer *trc, const char *name); + + JSObject &operator*() const { return *value; } + JSObject *operator->() const { return value; } + operator JSObject *() const { return value; } +}; + } /* namespace JS */ namespace js { -/* - * Hook for dynamic root analysis. Checks the native stack and poisons - * references to GC things which have not been rooted. - */ -inline void MaybeCheckStackRoots(JSContext *cx) -{ -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - JS::CheckStackRoots(cx); -#endif -} - /* Base class for automatic read-only object rooting during compilation. */ class CompilerRootNode { protected: - CompilerRootNode(js::gc::Cell *ptr) : next(nullptr), ptr_(ptr) {} + explicit CompilerRootNode(js::gc::Cell *ptr) : next(nullptr), ptr_(ptr) {} public: void **address() { return (void **)&ptr_; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/SliceBudget.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/SliceBudget.h index ccade643b3..7c602c5572 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/SliceBudget.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/SliceBudget.h @@ -32,11 +32,11 @@ struct JS_PUBLIC_API(SliceBudget) SliceBudget(); /* Instantiate as SliceBudget(Time/WorkBudget(n)). */ - SliceBudget(int64_t budget); + explicit SliceBudget(int64_t budget); void reset() { - deadline = INT64_MAX; - counter = INTPTR_MAX; + deadline = unlimitedDeadline; + counter = unlimitedStartCounter; } void step(intptr_t amt = 1) { @@ -50,6 +50,15 @@ struct JS_PUBLIC_API(SliceBudget) return false; return checkOverBudget(); } + + bool isUnlimited() { + return deadline == unlimitedDeadline; + } + +private: + static const int64_t unlimitedDeadline = INT64_MAX; + static const intptr_t unlimitedStartCounter = INTPTR_MAX; + }; } // namespace js diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/StructuredClone.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/StructuredClone.h index d32bdd8dd6..fa48ce045a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/StructuredClone.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/StructuredClone.h @@ -23,6 +23,35 @@ struct JSStructuredCloneWriter; // API for the HTML5 internal structured cloning algorithm. +namespace JS { +enum TransferableOwnership { + // Transferable data has not been filled in yet + SCTAG_TMO_UNFILLED = 0, + + // Structured clone buffer does not yet own the data + SCTAG_TMO_UNOWNED = 1, + + // All values at least this large are owned by the clone buffer + SCTAG_TMO_FIRST_OWNED = 2, + + // Data is a pointer that can be freed + SCTAG_TMO_ALLOC_DATA = 2, + + // Data is a SharedArrayBufferObject's buffer + SCTAG_TMO_SHARED_BUFFER = 3, + + // Data is a memory mapped pointer + SCTAG_TMO_MAPPED_DATA = 4, + + // Data is embedding-specific. The engine can free it by calling the + // freeTransfer op. The embedding can also use SCTAG_TMO_USER_MIN and + // greater, up to 32 bits, to distinguish specific ownership variants. + SCTAG_TMO_CUSTOM = 5, + + SCTAG_TMO_USER_MIN +}; +} /* namespace JS */ + // Read structured data from the reader r. This hook is used to read a value // previously serialized by a call to the WriteStructuredCloneOp hook. // @@ -43,22 +72,64 @@ typedef JSObject *(*ReadStructuredCloneOp)(JSContext *cx, JSStructuredCloneReade // // Return true on success, false on error/exception. typedef bool (*WriteStructuredCloneOp)(JSContext *cx, JSStructuredCloneWriter *w, - JS::Handle obj, void *closure); + JS::HandleObject obj, void *closure); // This is called when JS_WriteStructuredClone is given an invalid transferable. // To follow HTML5, the application must throw a DATA_CLONE_ERR DOMException // with error set to one of the JS_SCERR_* values. typedef void (*StructuredCloneErrorOp)(JSContext *cx, uint32_t errorid); +// This is called when JS_ReadStructuredClone receives a transferable object +// not known to the engine. If this hook does not exist or returns false, the +// JS engine calls the reportError op if set, otherwise it throws a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback and must return a non-null object in returnObject on success. +typedef bool (*ReadTransferStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r, + uint32_t tag, void *content, uint64_t extraData, + void *closure, + JS::MutableHandleObject returnObject); + +// Called when JS_WriteStructuredClone receives a transferable object not +// handled by the engine. If this hook does not exist or returns false, the JS +// engine will call the reportError hook or fall back to throwing a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback. +// +// tag: indicates what type of transferable this is. Must be greater than +// 0xFFFF0201 (value of the internal SCTAG_TRANSFER_MAP_PENDING_ENTRY) +// +// ownership: see TransferableOwnership, above. Used to communicate any needed +// ownership info to the FreeTransferStructuredCloneOp. +// +// content, extraData: what the ReadTransferStructuredCloneOp will receive +// +typedef bool (*TransferStructuredCloneOp)(JSContext *cx, + JS::Handle obj, + void *closure, + // Output: + uint32_t *tag, + JS::TransferableOwnership *ownership, + void **content, + uint64_t *extraData); + +// Called when JS_ClearStructuredClone has to free an unknown transferable +// object. Note that it should never trigger a garbage collection (and will +// assert in a debug build if it does.) +typedef void (*FreeTransferStructuredCloneOp)(uint32_t tag, JS::TransferableOwnership ownership, + void *content, uint64_t extraData, void *closure); + // The maximum supported structured-clone serialization format version. Note // that this does not need to be bumped for Transferable-only changes, since // they are never saved to persistent storage. -#define JS_STRUCTURED_CLONE_VERSION 2 +#define JS_STRUCTURED_CLONE_VERSION 4 struct JSStructuredCloneCallbacks { ReadStructuredCloneOp read; WriteStructuredCloneOp write; StructuredCloneErrorOp reportError; + ReadTransferStructuredCloneOp readTransfer; + TransferStructuredCloneOp writeTransfer; + FreeTransferStructuredCloneOp freeTransfer; }; // Note: if the *data contains transferable objects, it can be read only once. @@ -68,14 +139,16 @@ JS_ReadStructuredClone(JSContext *cx, uint64_t *data, size_t nbytes, uint32_t ve const JSStructuredCloneCallbacks *optionalCallbacks, void *closure); // Note: On success, the caller is responsible for calling -// JS_ClearStructuredClone(*datap, nbytesp). +// JS_ClearStructuredClone(*datap, nbytes, optionalCallbacks, closure). JS_PUBLIC_API(bool) JS_WriteStructuredClone(JSContext *cx, JS::HandleValue v, uint64_t **datap, size_t *nbytesp, const JSStructuredCloneCallbacks *optionalCallbacks, void *closure, JS::HandleValue transferable); JS_PUBLIC_API(bool) -JS_ClearStructuredClone(const uint64_t *data, size_t nbytes); +JS_ClearStructuredClone(uint64_t *data, size_t nbytes, + const JSStructuredCloneCallbacks *optionalCallbacks, + void *closure); JS_PUBLIC_API(bool) JS_StructuredCloneHasTransferables(const uint64_t *data, size_t nbytes, bool *hasTransferable); @@ -89,10 +162,22 @@ class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) { uint64_t *data_; size_t nbytes_; uint32_t version_; + const JSStructuredCloneCallbacks *callbacks_; + void *closure_; public: JSAutoStructuredCloneBuffer() - : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION) {} + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(nullptr), closure_(nullptr) + {} + + JSAutoStructuredCloneBuffer(const JSStructuredCloneCallbacks *callbacks, void *closure) + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(callbacks), closure_(closure) + {} + + JSAutoStructuredCloneBuffer(JSAutoStructuredCloneBuffer &&other); + JSAutoStructuredCloneBuffer &operator=(JSAutoStructuredCloneBuffer &&other); ~JSAutoStructuredCloneBuffer() { clear(); } @@ -123,13 +208,10 @@ class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) { bool write(JSContext *cx, JS::HandleValue v, JS::HandleValue transferable, const JSStructuredCloneCallbacks *optionalCallbacks=nullptr, void *closure=nullptr); - // Swap ownership with another JSAutoStructuredCloneBuffer. - void swap(JSAutoStructuredCloneBuffer &other); - private: // Copy and assignment are not supported. - JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other); - JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other); + JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; + JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; }; // The range of tag values the application may use for its own custom object types. @@ -149,7 +231,7 @@ JS_PUBLIC_API(bool) JS_ReadBytes(JSStructuredCloneReader *r, void *p, size_t len); JS_PUBLIC_API(bool) -JS_ReadTypedArray(JSStructuredCloneReader *r, JS::Value *vp); +JS_ReadTypedArray(JSStructuredCloneReader *r, JS::MutableHandleValue vp); JS_PUBLIC_API(bool) JS_WriteUint32Pair(JSStructuredCloneWriter *w, uint32_t tag, uint32_t data); @@ -158,6 +240,6 @@ JS_PUBLIC_API(bool) JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len); JS_PUBLIC_API(bool) -JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::Value v); +JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::HandleValue v); #endif /* js_StructuredClone_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/Tracer.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/TracingAPI.h similarity index 53% rename from frameworks/js-bindings/external/spidermonkey/include/ios/js/Tracer.h rename to frameworks/js-bindings/external/spidermonkey/include/ios/js/TracingAPI.h index 89994612f6..3c7fdbe1b1 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/Tracer.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/TracingAPI.h @@ -4,14 +4,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef js_Tracer_h -#define js_Tracer_h +#ifndef js_TracingAPI_h +#define js_TracingAPI_h #include "mozilla/NullPtr.h" - + #include "jspubtd.h" -struct JSTracer; +class JS_PUBLIC_API(JSTracer); namespace JS { template class Heap; @@ -46,74 +46,101 @@ enum WeakMapTraceKind { TraceWeakMapKeysValues = 2 }; -struct JSTracer { - JSRuntime *runtime; - JSTraceCallback callback; - JSTraceNamePrinter debugPrinter; - const void *debugPrintArg; - size_t debugPrintIndex; - WeakMapTraceKind eagerlyTraceWeakMaps; -#ifdef JS_GC_ZEAL - void *realLocation; -#endif -}; +class JS_PUBLIC_API(JSTracer) +{ + public: + JSTracer(JSRuntime *rt, JSTraceCallback traceCallback, + WeakMapTraceKind weakTraceKind = TraceWeakMapValues); + + // Set debugging information about a reference to a traceable thing to prepare + // for the following call to JS_CallTracer. + // + // When printer is null, arg must be const char * or char * C string naming + // the reference and index must be either (size_t)-1 indicating that the name + // alone describes the reference or it must be an index into some array vector + // that stores the reference. + // + // When printer callback is not null, the arg and index arguments are + // available to the callback as debugPrintArg_ and debugPrintIndex_ fields + // of JSTracer. + // + // The storage for name or callback's arguments needs to live only until + // the following call to JS_CallTracer returns. + void setTracingDetails(JSTraceNamePrinter printer, const void *arg, size_t index) { + debugPrinter_ = printer; + debugPrintArg_ = arg; + debugPrintIndex_ = index; + } + + void setTracingIndex(const char *name, size_t index) { + setTracingDetails(nullptr, (void *)name, index); + } + + void setTracingName(const char *name) { + setTracingDetails(nullptr, (void *)name, size_t(-1)); + } + + // Remove the currently set tracing details. + void clearTracingDetails() { + debugPrinter_ = nullptr; + debugPrintArg_ = nullptr; + } + + // Return true if tracing details are currently set. + bool hasTracingDetails() const; + + // Get the string set with the most recent call to setTracingName or return + // fallback if a name printer function has been installed. + const char *tracingName(const char *fallback) const; + + // Build a description of this edge in the heap graph. This call may invoke + // the debug printer, which may inspect arbitrary areas of the heap. + const char *getTracingEdgeName(char *buffer, size_t bufferSize); + + // Access the currently active tracing details. + JSTraceNamePrinter debugPrinter() const; + const void *debugPrintArg() const; + size_t debugPrintIndex() const; + + // Return the runtime set on the tracer. + JSRuntime *runtime() const { return runtime_; } + + // Return the weak map tracing behavior set on this tracer. + WeakMapTraceKind eagerlyTraceWeakMaps() const { return eagerlyTraceWeakMaps_; } + + // Update the trace callback. + void setTraceCallback(JSTraceCallback traceCallback); -// Set debugging information about a reference to a traceable thing to prepare -// for the following call to JS_CallTracer. -// -// When printer is null, arg must be const char * or char * C string naming -// the reference and index must be either (size_t)-1 indicating that the name -// alone describes the reference or it must be an index into some array vector -// that stores the reference. -// -// When printer callback is not null, the arg and index arguments are -// available to the callback as debugPrintArg and debugPrintIndex fields -// of JSTracer. -// -// The storage for name or callback's arguments needs to live only until -// the following call to JS_CallTracer returns. -// -# define JS_SET_TRACING_DETAILS(trc, printer, arg, index) \ - JS_BEGIN_MACRO \ - (trc)->debugPrinter = (printer); \ - (trc)->debugPrintArg = (arg); \ - (trc)->debugPrintIndex = (index); \ - JS_END_MACRO - -// Sets the real location for a marked reference, when passing the address -// directly is not feasable. -// -// FIXME: This is currently overcomplicated by our need to nest calls for Values -// stored as keys in hash tables, but will get simplified once we can rekey -// in-place. -// #ifdef JS_GC_ZEAL -# define JS_SET_TRACING_LOCATION(trc, location) \ - JS_BEGIN_MACRO \ - if (!(trc)->realLocation || !(location)) \ - (trc)->realLocation = (location); \ - JS_END_MACRO -# define JS_UNSET_TRACING_LOCATION(trc) \ - JS_BEGIN_MACRO \ - (trc)->realLocation = nullptr; \ - JS_END_MACRO + // Sets the "real" location for a marked reference, when passing the address + // directly is not feasable. This address is used for matching against the + // store buffer when verifying the correctness of the entrees there. + // + // This is currently complicated by our need to nest calls for Values + // stored as keys in hash tables. + void setTracingLocation(void *location); + void unsetTracingLocation(); + void **tracingLocation(void **thingp); #else -# define JS_SET_TRACING_LOCATION(trc, location) \ - JS_BEGIN_MACRO \ - JS_END_MACRO -# define JS_UNSET_TRACING_LOCATION(trc) \ - JS_BEGIN_MACRO \ - JS_END_MACRO + void setTracingLocation(void *location) {} + void unsetTracingLocation() {} + void **tracingLocation(void **thingp) { return nullptr; } #endif -// Convenience macro to describe the argument of JS_CallTracer using C string -// and index. -# define JS_SET_TRACING_INDEX(trc, name, index) \ - JS_SET_TRACING_DETAILS(trc, nullptr, name, index) + // We expose |callback| directly so that IS_GC_MARKING_TRACER can compare + // it to GCMarker::GrayCallback. + JSTraceCallback callback; -// Convenience macro to describe the argument of JS_CallTracer using C string. -# define JS_SET_TRACING_NAME(trc, name) \ - JS_SET_TRACING_DETAILS(trc, nullptr, name, (size_t)-1) + private: + JSRuntime *runtime_; + JSTraceNamePrinter debugPrinter_; + const void *debugPrintArg_; + size_t debugPrintIndex_; + WeakMapTraceKind eagerlyTraceWeakMaps_; +#ifdef JS_GC_ZEAL + void *realLocation_; +#endif +}; // The JS_Call*Tracer family of functions traces the given GC thing reference. // This performs the tracing action configured on the given JSTracer: @@ -157,12 +184,15 @@ JS_CallHeapStringTracer(JSTracer *trc, JS::Heap *strp, const char *n extern JS_PUBLIC_API(void) JS_CallHeapScriptTracer(JSTracer *trc, JS::Heap *scriptp, const char *name); +extern JS_PUBLIC_API(void) +JS_CallHeapFunctionTracer(JSTracer *trc, JS::Heap *funp, const char *name); + template inline void JS_CallHashSetObjectTracer(JSTracer *trc, HashSetEnum &e, JSObject *const &key, const char *name) { JSObject *updated = key; - JS_SET_TRACING_LOCATION(trc, reinterpret_cast(&const_cast(key))); + trc->setTracingLocation(reinterpret_cast(&const_cast(key))); JS_CallObjectTracer(trc, &updated, name); if (updated != key) e.rekeyFront(key, updated); @@ -173,10 +203,6 @@ JS_CallHashSetObjectTracer(JSTracer *trc, HashSetEnum &e, JSObject *const &key, extern JS_PUBLIC_API(void) JS_CallTenuredObjectTracer(JSTracer *trc, JS::TenuredHeap *objp, const char *name); -// API for JSTraceCallback implementations. -extern JS_PUBLIC_API(void) -JS_TracerInit(JSTracer *trc, JSRuntime *rt, JSTraceCallback callback); - extern JS_PUBLIC_API(void) JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind); @@ -187,7 +213,4 @@ extern JS_PUBLIC_API(void) JS_GetTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc, void *thing, JSGCTraceKind kind, bool includeDetails); -extern JS_PUBLIC_API(const char *) -JS_GetTraceEdgeName(JSTracer *trc, char *buffer, int bufferSize); - -#endif /* js_Tracer_h */ +#endif /* js_TracingAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/TypeDecls.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/TypeDecls.h index 027d7b8fb7..908582caa2 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/TypeDecls.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/TypeDecls.h @@ -20,44 +20,27 @@ #include #include +#include "js-config.h" + +// Needed for cocos2d-js +#define JS_NO_JSVAL_JSID_STRUCT_TYPES + struct JSContext; class JSFunction; class JSObject; class JSScript; class JSString; +class JSAddonId; -// In release builds, jsid is defined to be an integral type. This -// prevents many bugs from being caught at compile time. E.g.: -// -// jsid id = ... -// if (id) // error -// ... -// -// size_t n = id; // error -// -// To catch more errors, jsid is given a struct type in C++ debug builds. -// Struct assignment and (in C++) operator== allow correct code to be mostly -// oblivious to the change. This feature can be explicitly disabled in debug -// builds by defining JS_NO_JSVAL_JSID_STRUCT_TYPES. -// - -// Needed for cocos2d-js -#define JS_NO_JSVAL_JSID_STRUCT_TYPES - -#if defined(DEBUG) && !defined(JS_NO_JSVAL_JSID_STRUCT_TYPES) -# define JS_USE_JSID_STRUCT_TYPES -#endif - -#ifdef JS_USE_JSID_STRUCT_TYPES struct jsid; -#else -typedef ptrdiff_t jsid; -#endif typedef char16_t jschar; namespace JS { +typedef unsigned char Latin1Char; + +class Symbol; class Value; template class Handle; template class MutableHandle; @@ -69,6 +52,7 @@ typedef Handle HandleId; typedef Handle HandleObject; typedef Handle HandleScript; typedef Handle HandleString; +typedef Handle HandleSymbol; typedef Handle HandleValue; typedef MutableHandle MutableHandleFunction; @@ -76,12 +60,14 @@ typedef MutableHandle MutableHandleId; typedef MutableHandle MutableHandleObject; typedef MutableHandle MutableHandleScript; typedef MutableHandle MutableHandleString; +typedef MutableHandle MutableHandleSymbol; typedef MutableHandle MutableHandleValue; typedef Rooted RootedObject; typedef Rooted RootedFunction; typedef Rooted RootedScript; typedef Rooted RootedString; +typedef Rooted RootedSymbol; typedef Rooted RootedId; typedef Rooted RootedValue; @@ -90,6 +76,7 @@ typedef PersistentRooted PersistentRootedId; typedef PersistentRooted PersistentRootedObject; typedef PersistentRooted PersistentRootedScript; typedef PersistentRooted PersistentRootedString; +typedef PersistentRooted PersistentRootedSymbol; typedef PersistentRooted PersistentRootedValue; } // namespace JS diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/UbiNode.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/UbiNode.h new file mode 100644 index 0000000000..d2acc2e242 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/UbiNode.h @@ -0,0 +1,462 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_UbiNode_h +#define js_UbiNode_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" + +#include "jspubtd.h" + +#include "js/GCAPI.h" +#include "js/HashTable.h" +#include "js/TypeDecls.h" + +// JS::ubi::Node +// +// JS::ubi::Node is a pointer-like type designed for internal use by heap +// analysis tools. A ubi::Node can refer to: +// +// - a JS value, like a string or object; +// - an internal SpiderMonkey structure, like a shape or a scope chain object +// - an instance of some embedding-provided type: in Firefox, an XPCOM +// object, or an internal DOM node class instance +// +// A ubi::Node instance provides metadata about its referent, and can +// enumerate its referent's outgoing edges, so you can implement heap analysis +// algorithms that walk the graph - finding paths between objects, or +// computing heap dominator trees, say - using ubi::Node, while remaining +// ignorant of the details of the types you're operating on. +// +// Of course, when it comes to presenting the results in a developer-facing +// tool, you'll need to stop being ignorant of those details, because you have +// to discuss the ubi::Nodes' referents with the developer. Here, ubi::Node +// can hand you dynamically checked, properly typed pointers to the original +// objects via the as method, or generate descriptions of the referent +// itself. +// +// ubi::Node instances are lightweight (two-word) value types. Instances: +// - compare equal if and only if they refer to the same object; +// - have hash values that respect their equality relation; and +// - have serializations that are only equal if the ubi::Nodes are equal. +// +// A ubi::Node is only valid for as long as its referent is alive; if its +// referent goes away, the ubi::Node becomes a dangling pointer. A ubi::Node +// that refers to a GC-managed object is not automatically a GC root; if the +// GC frees or relocates its referent, the ubi::Node becomes invalid. A +// ubi::Node that refers to a reference-counted object does not bump the +// reference count. +// +// ubi::Node values require no supporting data structures, making them +// feasible for use in memory-constrained devices --- ideally, the memory +// requirements of the algorithm which uses them will be the limiting factor, +// not the demands of ubi::Node itself. +// +// One can construct a ubi::Node value given a pointer to a type that ubi::Node +// supports. In the other direction, one can convert a ubi::Node back to a +// pointer; these downcasts are checked dynamically. In particular, one can +// convert a 'JSRuntime *' to a ubi::Node, yielding a node with an outgoing edge +// for every root registered with the runtime; starting from this, one can walk +// the entire heap. (Of course, one could also start traversal at any other kind +// of type to which one has a pointer.) +// +// +// Extending ubi::Node To Handle Your Embedding's Types +// +// To add support for a new ubi::Node referent type R, you must define a +// specialization of the ubi::Concrete template, ubi::Concrete, which +// inherits from ubi::Base. ubi::Node itself uses the specialization for +// compile-time information (i.e. the checked conversions between R * and +// ubi::Node), and the inheritance for run-time dispatching. +// +// +// ubi::Node Exposes Implementation Details +// +// In many cases, a JavaScript developer's view of their data differs +// substantially from its actual implementation. For example, while the +// ECMAScript specification describes objects as maps from property names to +// sets of attributes (like ECMAScript's [[Value]]), in practice many objects +// have only a pointer to a shape, shared with other similar objects, and +// indexed slots that contain the [[Value]] attributes. As another example, a +// string produced by concatenating two other strings may sometimes be +// represented by a "rope", a structure that points to the two original +// strings. +// + +// We intend to use ubi::Node to write tools that report memory usage, so it's +// important that ubi::Node accurately portray how much memory nodes consume. +// Thus, for example, when data that apparently belongs to multiple nodes is +// in fact shared in a common structure, ubi::Node's graph uses a separate +// node for that shared structure, and presents edges to it from the data's +// apparent owners. For example, ubi::Node exposes SpiderMonkey objects' +// shapes and base shapes, and exposes rope string and substring structure, +// because these optimizations become visible when a tool reports how much +// memory a structure consumes. +// +// However, fine granularity is not a goal. When a particular object is the +// exclusive owner of a separate block of memory, ubi::Node may present the +// object and its block as a single node, and add their sizes together when +// reporting the node's size, as there is no meaningful loss of data in this +// case. Thus, for example, a ubi::Node referring to a JavaScript object, when +// asked for the object's size in bytes, includes the object's slot and +// element arrays' sizes in the total. There is no separate ubi::Node value +// representing the slot and element arrays, since they are owned exclusively +// by the object. +// +// +// Presenting Analysis Results To JavaScript Developers +// +// If an analysis provides its results in terms of ubi::Node values, a user +// interface presenting those results will generally need to clean them up +// before they can be understood by JavaScript developers. For example, +// JavaScript developers should not need to understand shapes, only JavaScript +// objects. Similarly, they should not need to understand the distinction +// between DOM nodes and the JavaScript shadow objects that represent them. +// +// +// Rooting Restrictions +// +// At present there is no way to root ubi::Node instances, so instances can't be +// live across any operation that might GC. Analyses using ubi::Node must either +// run to completion and convert their results to some other rootable type, or +// save their intermediate state in some rooted structure if they must GC before +// they complete. (For algorithms like path-finding and dominator tree +// computation, we implement the algorithm avoiding any operation that could +// cause a GC --- and use AutoCheckCannotGC to verify this.) +// +// If this restriction prevents us from implementing interesting tools, we may +// teach the GC how to root ubi::Nodes, fix up hash tables that use them as +// keys, etc. + + +// Forward declarations of SpiderMonkey's ubi::Node reference types. +namespace js { +class LazyScript; +class Shape; +class BaseShape; +namespace jit { +class JitCode; +} +namespace types { +struct TypeObject; +} +} + + +namespace JS { +namespace ubi { + +class Edge; +class EdgeRange; + +// The base class implemented by each ubi::Node referent type. Subclasses must +// not add data members to this class. +class Base { + friend class Node; + + // For performance's sake, we'd prefer to avoid a virtual destructor; and + // an empty constructor seems consistent with the 'lightweight value type' + // visible behavior we're trying to achieve. But if the destructor isn't + // virtual, and a subclass overrides it, the subclass's destructor will be + // ignored. Is there a way to make the compiler catch that error? + + protected: + // Space for the actual pointer. Concrete subclasses should define a + // properly typed 'get' member function to access this. + void *ptr; + + Base(void *ptr) : ptr(ptr) { } + + public: + bool operator==(const Base &rhs) const { + // Some compilers will indeed place objects of different types at + // the same address, so technically, we should include the vtable + // in this comparison. But it seems unlikely to cause problems in + // practice. + return ptr == rhs.ptr; + } + bool operator!=(const Base &rhs) const { return !(*this == rhs); } + + // Return a human-readable name for the referent's type. The result should + // be statically allocated. (You can use MOZ_UTF16("strings") for this.) + // + // This must always return Concrete::concreteTypeName; we use that + // pointer as a tag for this particular referent type. + virtual const jschar *typeName() const = 0; + + // Return the size of this node, in bytes. Include any structures that this + // node owns exclusively that are not exposed as their own ubi::Nodes. + virtual size_t size() const = 0; + + // Return an EdgeRange that initially contains all the referent's outgoing + // edges. The EdgeRange should be freed with 'js_delete'. (You could use + // ScopedDJSeletePtr to manage it.) On OOM, report an exception + // on |cx| and return nullptr. + virtual EdgeRange *edges(JSContext *cx) const = 0; + + private: + Base(const Base &rhs) MOZ_DELETE; + Base &operator=(const Base &rhs) MOZ_DELETE; +}; + +// A traits template with a specialization for each referent type that +// ubi::Node supports. The specialization must be the concrete subclass of +// Base that represents a pointer to the referent type. It must also +// include the members described here. +template +struct Concrete { + // The specific jschar array returned by Concrete::typeName. + static const jschar concreteTypeName[]; + + // Construct an instance of this concrete class in |storage| referring + // to |referent|. Implementations typically use a placement 'new'. + // + // In some cases, |referent| will contain dynamic type information that + // identifies it a some more specific subclass of |Referent|. For example, + // when |Referent| is |JSObject|, then |referent->getClass()| could tell us + // that it's actually a JSFunction. Similarly, if |Referent| is + // |nsISupports|, we would like a ubi::Node that knows its final + // implementation type. + // + // So, we delegate the actual construction to this specialization, which + // knows Referent's details. + static void construct(void *storage, Referent *referent); +}; + +// A container for a Base instance; all members simply forward to the contained instance. +// This container allows us to pass ubi::Node instances by value. +class Node { + // Storage in which we allocate Base subclasses. + mozilla::AlignedStorage2 storage; + Base *base() { return storage.addr(); } + const Base *base() const { return storage.addr(); } + + template + void construct(T *ptr) { + static_assert(sizeof(Concrete) == sizeof(*base()), + "ubi::Base specializations must be the same size as ubi::Base"); + Concrete::construct(base(), ptr); + } + + typedef void (Node::* ConvertibleToBool)(); + void nonNull() {} + + public: + Node() { construct(nullptr); } + + template + Node(T *ptr) { + construct(ptr); + } + template + Node &operator=(T *ptr) { + construct(ptr); + return *this; + } + + // We can construct and assign from rooted forms of pointers. + template + Node(const Rooted &root) { + construct(root.get()); + } + template + Node &operator=(const Rooted &root) { + construct(root.get()); + return *this; + } + + // Constructors accepting SpiderMonkey's other generic-pointer-ish types. + Node(JS::Value value); + Node(JSGCTraceKind kind, void *ptr); + + // copy construction and copy assignment just use memcpy, since we know + // instances contain nothing but a vtable pointer and a data pointer. + // + // To be completely correct, concrete classes could provide a virtual + // 'construct' member function, which we could invoke on rhs to construct an + // instance in our storage. But this is good enough; there's no need to jump + // through vtables for copying and assignment that are just going to move + // two words around. The compiler knows how to optimize memcpy. + Node(const Node &rhs) { + memcpy(storage.u.mBytes, rhs.storage.u.mBytes, sizeof(storage.u)); + } + + Node &operator=(const Node &rhs) { + memcpy(storage.u.mBytes, rhs.storage.u.mBytes, sizeof(storage.u)); + return *this; + } + + bool operator==(const Node &rhs) const { return *base() == *rhs.base(); } + bool operator!=(const Node &rhs) const { return *base() != *rhs.base(); } + + operator ConvertibleToBool() const { + return base()->ptr ? &Node::nonNull : 0; + } + + template + bool is() const { + return base()->typeName() == Concrete::concreteTypeName; + } + + template + T *as() const { + MOZ_ASSERT(is()); + return static_cast(base()->ptr); + } + + template + T *asOrNull() const { + return is() ? static_cast(base()->ptr) : nullptr; + } + + // If this node refers to something that can be represented as a + // JavaScript value that is safe to expose to JavaScript code, return that + // value. Otherwise return UndefinedValue(). JSStrings and some (but not + // all!) JSObjects can be exposed. + JS::Value exposeToJS() const; + + const jschar *typeName() const { return base()->typeName(); } + size_t size() const { return base()->size(); } + EdgeRange *edges(JSContext *cx) const { return base()->edges(cx); } + + // A hash policy for ubi::Nodes. + // This simply uses the stock PointerHasher on the ubi::Node's pointer. + // We specialize DefaultHasher below to make this the default. + class HashPolicy { + typedef js::PointerHasher::value> PtrHash; + + public: + typedef Node Lookup; + + static js::HashNumber hash(const Lookup &l) { return PtrHash::hash(l.base()->ptr); } + static bool match(const Node &k, const Lookup &l) { return k == l; } + static void rekey(Node &k, const Node &newKey) { k = newKey; } + }; +}; + + +// Edge is the abstract base class representing an outgoing edge of a node. +// Edges are owned by EdgeRanges, and need not have assignment operators or copy +// constructors. +// +// Each Edge class should inherit from this base class, overriding as +// appropriate. +class Edge { + protected: + Edge() : name(nullptr), referent() { } + virtual ~Edge() { } + + public: + // This edge's name. + // + // The storage is owned by this Edge, and will be freed when this Edge is + // destructed. + // + // (In real life we'll want a better representation for names, to avoid + // creating tons of strings when the names follow a pattern; and we'll need + // to think about lifetimes carefully to ensure traversal stays cheap.) + const jschar *name; + + // This edge's referent. + Node referent; + + private: + Edge(const Edge &) MOZ_DELETE; + Edge &operator=(const Edge &) MOZ_DELETE; +}; + + +// EdgeRange is an abstract base class for iterating over a node's outgoing +// edges. (This is modeled after js::HashTable::Range.) +// +// Concrete instances of this class need not be as lightweight as Node itself, +// since they're usually only instantiated while iterating over a particular +// object's edges. For example, a dumb implementation for JS Cells might use +// JS_TraceChildren to to get the outgoing edges, and then store them in an +// array internal to the EdgeRange. +class EdgeRange { + protected: + // The current front edge of this range, or nullptr if this range is empty. + Edge *front_; + + EdgeRange() : front_(nullptr) { } + + public: + virtual ~EdgeRange() { }; + + // True if there are no more edges in this range. + bool empty() const { return !front_; } + + // The front edge of this range. This is owned by the EdgeRange, and is + // only guaranteed to live until the next call to popFront, or until + // the EdgeRange is destructed. + const Edge &front() { return *front_; } + + // Remove the front edge from this range. This should only be called if + // !empty(). + virtual void popFront() = 0; + + private: + EdgeRange(const EdgeRange &) MOZ_DELETE; + EdgeRange &operator=(const EdgeRange &) MOZ_DELETE; +}; + + +// Concrete classes for ubi::Node referent types. + +// A reusable ubi::Concrete specialization base class for types supported by +// JS_TraceChildren. +template +class TracerConcrete : public Base { + const jschar *typeName() const MOZ_OVERRIDE { return concreteTypeName; } + size_t size() const MOZ_OVERRIDE { return 0; } // not implemented yet; bug 1011300 + EdgeRange *edges(JSContext *) const MOZ_OVERRIDE; + + TracerConcrete(Referent *ptr) : Base(ptr) { } + + public: + static const jschar concreteTypeName[]; + static void construct(void *storage, Referent *ptr) { new (storage) TracerConcrete(ptr); }; +}; + +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; + +// The ubi::Node null pointer. Any attempt to operate on a null ubi::Node asserts. +template<> +class Concrete : public Base { + const jschar *typeName() const MOZ_OVERRIDE; + size_t size() const MOZ_OVERRIDE; + EdgeRange *edges(JSContext *cx) const MOZ_OVERRIDE; + + Concrete(void *ptr) : Base(ptr) { } + + public: + static void construct(void *storage, void *ptr) { new (storage) Concrete(ptr); } + static const jschar concreteTypeName[]; +}; + + +} // namespace ubi +} // namespace JS + +namespace js { + +// Make ubi::Node::HashPolicy the default hash policy for ubi::Node. +template<> struct DefaultHasher : JS::ubi::Node::HashPolicy { }; + +} // namespace js + +#endif // js_UbiNode_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/UbiNodeTraverse.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/UbiNodeTraverse.h new file mode 100644 index 0000000000..6072cbc489 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/UbiNodeTraverse.h @@ -0,0 +1,208 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_UbiNodeTraverse_h +#define js_UbiNodeTraverse_h + +#include "js/UbiNode.h" +#include "js/Utility.h" +#include "js/Vector.h" + +namespace JS { +namespace ubi { + +// A breadth-first traversal template for graphs of ubi::Nodes. +// +// No GC may occur while an instance of this template is live. +// +// The provided Handler type should have two members: +// +// typename NodeData; +// +// The value type of |BreadthFirst::visited|, the HashMap of +// ubi::Nodes that have been visited so far. Since the algorithm needs a +// hash table like this for its own use anyway, it is simple to let +// Handler store its own metadata about each node in the same table. +// +// For example, if you want to find a shortest path to each node from any +// traversal starting point, your |NodeData| type could record the first +// edge to reach each node, and the node from which it originates. Then, +// when the traversal is complete, you can walk backwards from any node +// to some starting point, and the path recorded will be a shortest path. +// +// This type must have a default constructor. If this type owns any other +// resources, move constructors and assignment operators are probably a +// good idea, too. +// +// bool operator() (BreadthFirst &traversal, +// Node origin, const Edge &edge, +// Handler::NodeData *referentData, bool first); +// +// The visitor function, called to report that we have traversed +// |edge| from |origin|. This is called once for each edge we traverse. +// As this is a breadth-first search, any prior calls to the visitor function +// were for origin nodes not further from the start nodes than |origin|. +// +// |traversal| is this traversal object, passed along for convenience. +// +// |referentData| is a pointer to the value of the entry in +// |traversal.visited| for |edge.referent|; the visitor function can +// store whatever metadata it likes about |edge.referent| there. +// +// |first| is true if this is the first time we have visited an edge +// leading to |edge.referent|. This could be stored in NodeData, but +// the algorithm knows whether it has just created the entry in +// |traversal.visited|, so it passes it along for convenience. +// +// The visitor function may call |traversal.stop()| if it doesn't want +// to visit any more nodes. +// +// The visitor function may consult |traversal.visited| for information +// about other nodes, but it should not add or remove entries. +// +// The visitor function should return true on success, or false if an +// error occurs. A false return value terminates the traversal +// immediately, and causes BreadthFirst::traverse to return +// false. +template +struct BreadthFirst { + + // Construct a breadth-first traversal object that reports the nodes it + // reaches to |handler|. The traversal object reports OOM on |cx|, and + // asserts that no GC happens in |cx|'s runtime during its lifetime. + // + // We do nothing with noGC, other than require it to exist, with a lifetime + // that encloses our own. + BreadthFirst(JSContext *cx, Handler &handler, const JS::AutoCheckCannotGC &noGC) + : cx(cx), visited(cx), handler(handler), pending(cx), + traversalBegun(false), stopRequested(false) + { } + + // Initialize this traversal object. Return false on OOM. + bool init() { return visited.init(); } + + // Add |node| as a starting point for the traversal. You may add + // as many starting points as you like. Return false on OOM. + bool addStart(Node node) { return pending.append(node); } + + // Traverse the graph in breadth-first order, starting at the given + // start nodes, applying |handler::operator()| for each edge traversed + // as described above. + // + // This should be called only once per instance of this class. + // + // Return false on OOM or error return from |handler::operator()|. + bool traverse() + { + MOZ_ASSERT(!traversalBegun); + traversalBegun = true; + + // While there are pending nodes, visit them, until we've found a path to the target. + while (!pending.empty()) { + Node origin = pending.front(); + pending.popFront(); + + // Get a range containing all origin's outgoing edges. + js::ScopedJSDeletePtr range(origin.edges(cx)); + if (!range) + return false; + + // Traverse each edge. + for (; !range->empty(); range->popFront()) { + MOZ_ASSERT(!stopRequested); + + const Edge &edge = range->front(); + typename NodeMap::AddPtr a = visited.lookupForAdd(edge.referent); + bool first = !a; + + if (first) { + // This is the first time we've reached |edge.referent|. + // Create an entry for it in |visited|, and arrange to + // traverse its outgoing edges later. + if (!visited.add(a, edge.referent, typename Handler::NodeData()) || + !pending.append(edge.referent)) { + return false; + } + } + + MOZ_ASSERT(a); + + // Report this edge to the visitor function. + if (!handler(*this, origin, edge, &a->value(), first)) + return false; + + if (stopRequested) + return true; + } + } + + return true; + } + + // Stop traversal, and return true from |traverse| without visiting any + // more nodes. Only |handler::operator()| should call this function; it + // may do so to stop the traversal early, without returning false and + // then making |traverse|'s caller disambiguate that result from a real + // error. + void stop() { stopRequested = true; } + + // The context with which we were constructed. + JSContext *cx; + + // A map associating each node N that we have reached with a + // Handler::NodeData, for |handler|'s use. This is public, so that + // |handler| can access it to see the traversal thus far. + typedef js::HashMap NodeMap; + NodeMap visited; + + private: + // Our handler object. + Handler &handler; + + // A queue template. Appending and popping the front are constant time. + // Wasted space is never more than some recent actual population plus the + // current population. + template + class Queue { + js::Vector head, tail; + size_t frontIndex; + public: + Queue(JSContext *cx) : head(cx), tail(cx), frontIndex(0) { } + bool empty() { return frontIndex >= head.length(); } + T &front() { + MOZ_ASSERT(!empty()); + return head[frontIndex]; + } + void popFront() { + MOZ_ASSERT(!empty()); + frontIndex++; + if (frontIndex >= head.length()) { + head.clearAndFree(); + head.swap(tail); + frontIndex = 0; + } + } + bool append(const T &elt) { + return frontIndex == 0 ? head.append(elt) : tail.append(elt); + } + }; + + // A queue of nodes that we have reached, but whose outgoing edges we + // have not yet traversed. Nodes reachable in fewer edges are enqueued + // earlier. + Queue pending; + + // True if our traverse function has been called. + bool traversalBegun; + + // True if we've been asked to stop the traversal. + bool stopRequested; +}; + +} // namespace ubi +} // namespace JS + +#endif // js_UbiNodeTraverse.h diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/Utility.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/Utility.h index adee3b15d8..89c495e411 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/Utility.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/Utility.h @@ -35,23 +35,22 @@ namespace mozilla {} namespace js {} /* - * Pattern used to overwrite freed memory. If you are accessing an object with - * this pattern, you probably have a dangling pointer. + * Patterns used by SpiderMonkey to overwrite unused memory. If you are + * accessing an object with one of these pattern, you probably have a dangling + * pointer. */ -#define JS_FREE_PATTERN 0xDA +#define JS_FRESH_NURSERY_PATTERN 0x2F +#define JS_SWEPT_NURSERY_PATTERN 0x2B +#define JS_ALLOCATED_NURSERY_PATTERN 0x2D +#define JS_FRESH_TENURED_PATTERN 0x4F +#define JS_SWEPT_TENURED_PATTERN 0x4B +#define JS_ALLOCATED_TENURED_PATTERN 0x4D +#define JS_SWEPT_CODE_PATTERN 0x3b +#define JS_SWEPT_FRAME_PATTERN 0x5b +#define JS_POISONED_FORKJOIN_CHUNK 0xBD #define JS_ASSERT(expr) MOZ_ASSERT(expr) #define JS_ASSERT_IF(cond, expr) MOZ_ASSERT_IF(cond, expr) -#define JS_ALWAYS_TRUE(expr) MOZ_ALWAYS_TRUE(expr) -#define JS_ALWAYS_FALSE(expr) MOZ_ALWAYS_FALSE(expr) - -#if defined(DEBUG) -# define JS_DIAGNOSTICS_ASSERT(expr) MOZ_ASSERT(expr) -#elif defined(JS_CRASH_DIAGNOSTICS) -# define JS_DIAGNOSTICS_ASSERT(expr) do { if (!(expr)) MOZ_CRASH(); } while(0) -#else -# define JS_DIAGNOSTICS_ASSERT(expr) ((void) 0) -#endif #define JS_STATIC_ASSERT(cond) static_assert(cond, "JS_STATIC_ASSERT") #define JS_STATIC_ASSERT_IF(cond, expr) MOZ_STATIC_ASSERT_IF(cond, expr, "JS_STATIC_ASSERT_IF") @@ -59,84 +58,40 @@ namespace js {} extern MOZ_NORETURN JS_PUBLIC_API(void) JS_Assert(const char *s, const char *file, int ln); -/* - * Abort the process in a non-graceful manner. This will cause a core file, - * call to the debugger or other moral equivalent as well as causing the - * entire process to stop. - */ -extern JS_PUBLIC_API(void) JS_Abort(void); - /* * Custom allocator support for SpiderMonkey */ #if defined JS_USE_CUSTOM_ALLOCATOR # include "jscustomallocator.h" #else -# ifdef DEBUG +# if defined(DEBUG) || defined(JS_OOM_BREAKPOINT) /* * In order to test OOM conditions, when the testing function * oomAfterAllocations COUNT is passed, we fail continuously after the NUM'th * allocation from now. */ -extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtins/TestingFunctions.cpp */ +extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtin/TestingFunctions.cpp */ extern JS_PUBLIC_DATA(uint32_t) OOM_counter; /* data race, who cares. */ -#ifdef JS_OOM_DO_BACKTRACES -#define JS_OOM_BACKTRACE_SIZE 32 -static JS_ALWAYS_INLINE void -PrintBacktrace() -{ - void* OOM_trace[JS_OOM_BACKTRACE_SIZE]; - char** OOM_traceSymbols = nullptr; - int32_t OOM_traceSize = 0; - int32_t OOM_traceIdx = 0; - OOM_traceSize = backtrace(OOM_trace, JS_OOM_BACKTRACE_SIZE); - OOM_traceSymbols = backtrace_symbols(OOM_trace, OOM_traceSize); - - if (!OOM_traceSymbols) - return; - - for (OOM_traceIdx = 0; OOM_traceIdx < OOM_traceSize; ++OOM_traceIdx) { - fprintf(stderr, "#%d %s\n", OOM_traceIdx, OOM_traceSymbols[OOM_traceIdx]); - } - - // This must be free(), not js_free(), because backtrace_symbols() - // allocates with malloc(). - free(OOM_traceSymbols); -} - -#define JS_OOM_EMIT_BACKTRACE() \ - do {\ - fprintf(stderr, "Forcing artificial memory allocation function failure:\n");\ - PrintBacktrace();\ - } while (0) -# else -# define JS_OOM_EMIT_BACKTRACE() do {} while(0) -#endif /* JS_OOM_DO_BACKTRACES */ +#ifdef JS_OOM_BREAKPOINT +static MOZ_NEVER_INLINE void js_failedAllocBreakpoint() { asm(""); } +#define JS_OOM_CALL_BP_FUNC() js_failedAllocBreakpoint() +#else +#define JS_OOM_CALL_BP_FUNC() do {} while(0) +#endif # define JS_OOM_POSSIBLY_FAIL() \ do \ { \ if (++OOM_counter > OOM_maxAllocations) { \ - JS_OOM_EMIT_BACKTRACE();\ - return nullptr; \ - } \ - } while (0) - -# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) \ - do \ - { \ - if (++OOM_counter > OOM_maxAllocations) { \ - JS_OOM_EMIT_BACKTRACE();\ - js_ReportOutOfMemory(cx);\ + JS_OOM_CALL_BP_FUNC();\ return nullptr; \ } \ } while (0) # else # define JS_OOM_POSSIBLY_FAIL() do {} while(0) -# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) do {} while(0) -# endif /* DEBUG */ +# endif /* DEBUG || JS_OOM_BREAKPOINT */ static inline void* js_malloc(size_t bytes) { @@ -168,26 +123,6 @@ static inline void js_free(void* p) } #endif/* JS_USE_CUSTOM_ALLOCATOR */ -/* - * JS_ROTATE_LEFT32 - * - * There is no rotate operation in the C Language so the construct (a << 4) | - * (a >> 28) is used instead. Most compilers convert this to a rotate - * instruction but some versions of MSVC don't without a little help. To get - * MSVC to generate a rotate instruction, we have to use the _rotl intrinsic - * and use a pragma to make _rotl inline. - * - * MSVC in VS2005 will do an inline rotate instruction on the above construct. - */ -#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || \ - defined(_M_X64)) -#include -#pragma intrinsic(_rotl) -#define JS_ROTATE_LEFT32(a, bits) _rotl(a, bits) -#else -#define JS_ROTATE_LEFT32(a, bits) (((a) << (bits)) | ((a) >> (32 - (bits)))) -#endif - #include /* @@ -235,6 +170,9 @@ static inline void js_free(void* p) #define JS_NEW_BODY(allocator, t, parms) \ void *memory = allocator(sizeof(t)); \ return memory ? new(memory) t parms : nullptr; +#define JS_MAKE_BODY(newname, T, parms) \ + T *ptr = newname parms; \ + return mozilla::UniquePtr>(ptr); /* * Given a class which should provide 'new' methods, add @@ -389,10 +327,191 @@ static inline void js_free(void* p) mozilla::Forward(p12)))\ }\ -JS_DECLARE_NEW_METHODS(js_new, js_malloc, static JS_ALWAYS_INLINE) +/* + * Given a class which should provide 'make' methods, add + * JS_DECLARE_MAKE_METHODS (see JSContext for a usage example). This method + * is functionally the same as JS_DECLARE_NEW_METHODS: it just declares methods + * that return mozilla::UniquePtr instances that will singly-manage ownership + * of the created object. This adds makes with up to 12 parameters. Add more + * versions below if you need more than 12 parameters. + * + * Note: Do not add a ; at the end of a use of JS_DECLARE_MAKE_METHODS, + * or the build will break. + */ +#define JS_DECLARE_MAKE_METHODS(MAKENAME, NEWNAME, QUALIFIERS)\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME() MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T, ())\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1)))\ + }\ +\ + template \ + QUALIFIERS \ +mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11, P12 &&p12) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11),\ + mozilla::Forward(p12)))\ + }\ + +JS_DECLARE_NEW_METHODS(js_new, js_malloc, static MOZ_ALWAYS_INLINE) template -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void js_delete(T *p) { if (p) { @@ -402,7 +521,7 @@ js_delete(T *p) } template -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void js_delete_poison(T *p) { if (p) { @@ -413,21 +532,21 @@ js_delete_poison(T *p) } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_malloc() { return (T *)js_malloc(sizeof(T)); } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_calloc() { return (T *)js_calloc(sizeof(T)); } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_malloc(size_t numElems) { if (numElems & mozilla::tl::MulOverflowMask::value) @@ -436,7 +555,7 @@ js_pod_malloc(size_t numElems) } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_calloc(size_t numElems) { if (numElems & mozilla::tl::MulOverflowMask::value) @@ -471,6 +590,25 @@ SCOPED_TEMPLATE(ScopedReleasePtr, ScopedReleasePtrTraits) } /* namespace js */ +namespace JS { + +template +struct DeletePolicy +{ + void operator()(T* ptr) { + js_delete(ptr); + } +}; + +struct FreePolicy +{ + void operator()(void* ptr) { + js_free(ptr); + } +}; + +} // namespace JS + namespace js { /* Integral types for all hash functions. */ @@ -535,7 +673,7 @@ namespace JS { inline void PoisonPtr(void *v) { -#if defined(JSGC_ROOT_ANALYSIS) && defined(DEBUG) +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) uint8_t *ptr = (uint8_t *) v + 3; *ptr = JS_FREE_PATTERN; #endif @@ -544,7 +682,7 @@ inline void PoisonPtr(void *v) template inline bool IsPoisonedPtr(T *v) { -#if defined(JSGC_ROOT_ANALYSIS) && defined(DEBUG) +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) uint32_t mask = uintptr_t(v) & 0xff000000; return mask == uint32_t(JS_FREE_PATTERN << 24); #else diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/Value.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/Value.h index ee4f3a64d3..e7b89e684d 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/Value.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/Value.h @@ -15,9 +15,11 @@ #include /* for std::numeric_limits */ +#include "js-config.h" #include "jstypes.h" #include "js/Anchor.h" +#include "js/GCAPI.h" #include "js/RootingAPI.h" #include "js/Utility.h" @@ -46,7 +48,7 @@ namespace JS { class Value; } # define JSVAL_ALIGNMENT #endif -#if JS_BITS_PER_WORD == 64 +#if defined(JS_PUNBOX64) # define JSVAL_TAG_SHIFT 47 #endif @@ -74,8 +76,9 @@ JS_ENUM_HEADER(JSValueType, uint8_t) JSVAL_TYPE_BOOLEAN = 0x03, JSVAL_TYPE_MAGIC = 0x04, JSVAL_TYPE_STRING = 0x05, - JSVAL_TYPE_NULL = 0x06, - JSVAL_TYPE_OBJECT = 0x07, + JSVAL_TYPE_SYMBOL = 0x06, + JSVAL_TYPE_NULL = 0x07, + JSVAL_TYPE_OBJECT = 0x08, /* These never appear in a jsval; they are only provided as an out-of-band value. */ JSVAL_TYPE_UNKNOWN = 0x20, @@ -84,7 +87,7 @@ JS_ENUM_HEADER(JSValueType, uint8_t) JS_STATIC_ASSERT(sizeof(JSValueType) == 1); -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) /* Remember to propagate changes to the C defines below. */ JS_ENUM_HEADER(JSValueTag, uint32_t) @@ -93,6 +96,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JSVAL_TAG_INT32 = JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32, JSVAL_TAG_UNDEFINED = JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED, JSVAL_TAG_STRING = JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL, JSVAL_TAG_BOOLEAN = JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN, JSVAL_TAG_MAGIC = JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC, JSVAL_TAG_NULL = JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL, @@ -101,7 +105,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JS_STATIC_ASSERT(sizeof(JSValueTag) == 4); -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) /* Remember to propagate changes to the C defines below. */ JS_ENUM_HEADER(JSValueTag, uint32_t) @@ -110,6 +114,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JSVAL_TAG_INT32 = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32, JSVAL_TAG_UNDEFINED = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED, JSVAL_TAG_STRING = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL, JSVAL_TAG_BOOLEAN = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN, JSVAL_TAG_MAGIC = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC, JSVAL_TAG_NULL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL, @@ -124,6 +129,7 @@ JS_ENUM_HEADER(JSValueShiftedTag, uint64_t) JSVAL_SHIFTED_TAG_INT32 = (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_UNDEFINED = (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_STRING = (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_SYMBOL = (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_BOOLEAN = (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_MAGIC = (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_NULL = (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT), @@ -143,29 +149,32 @@ typedef uint8_t JSValueType; #define JSVAL_TYPE_BOOLEAN ((uint8_t)0x03) #define JSVAL_TYPE_MAGIC ((uint8_t)0x04) #define JSVAL_TYPE_STRING ((uint8_t)0x05) -#define JSVAL_TYPE_NULL ((uint8_t)0x06) -#define JSVAL_TYPE_OBJECT ((uint8_t)0x07) +#define JSVAL_TYPE_SYMBOL ((uint8_t)0x06) +#define JSVAL_TYPE_NULL ((uint8_t)0x07) +#define JSVAL_TYPE_OBJECT ((uint8_t)0x08) #define JSVAL_TYPE_UNKNOWN ((uint8_t)0x20) -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) typedef uint32_t JSValueTag; #define JSVAL_TAG_CLEAR ((uint32_t)(0xFFFFFF80)) #define JSVAL_TAG_INT32 ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32)) #define JSVAL_TAG_UNDEFINED ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED)) #define JSVAL_TAG_STRING ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING)) +#define JSVAL_TAG_SYMBOL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL)) #define JSVAL_TAG_BOOLEAN ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN)) #define JSVAL_TAG_MAGIC ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC)) #define JSVAL_TAG_NULL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL)) #define JSVAL_TAG_OBJECT ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT)) -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) typedef uint32_t JSValueTag; #define JSVAL_TAG_MAX_DOUBLE ((uint32_t)(0x1FFF0)) #define JSVAL_TAG_INT32 (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32) #define JSVAL_TAG_UNDEFINED (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED) #define JSVAL_TAG_STRING (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING) +#define JSVAL_TAG_SYMBOL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL) #define JSVAL_TAG_BOOLEAN (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN) #define JSVAL_TAG_MAGIC (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC) #define JSVAL_TAG_NULL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL) @@ -176,20 +185,16 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_SHIFTED_TAG_INT32 (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_UNDEFINED (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_STRING (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_SYMBOL (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_BOOLEAN (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_MAGIC (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_NULL (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_OBJECT (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT) -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ #endif /* !defined(__SUNPRO_CC) && !defined(__xlC__) */ -#define JSVAL_LOWER_INCL_TYPE_OF_OBJ_OR_NULL_SET JSVAL_TYPE_NULL -#define JSVAL_UPPER_EXCL_TYPE_OF_PRIMITIVE_SET JSVAL_TYPE_OBJECT -#define JSVAL_UPPER_INCL_TYPE_OF_NUMBER_SET JSVAL_TYPE_INT32 -#define JSVAL_LOWER_INCL_TYPE_OF_PTR_PAYLOAD_SET JSVAL_TYPE_MAGIC - -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) #define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_CLEAR | (type))) @@ -198,7 +203,7 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32 #define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) #define JSVAL_PAYLOAD_MASK 0x00007FFFFFFFFFFFLL #define JSVAL_TAG_MASK 0xFFFF800000000000LL @@ -215,7 +220,7 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET JSVAL_SHIFTED_TAG_UNDEFINED #define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET JSVAL_SHIFTED_TAG_STRING -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ typedef enum JSWhyMagic { @@ -233,16 +238,16 @@ typedef enum JSWhyMagic JS_OPTIMIZED_ARGUMENTS, /* optimized-away 'arguments' value */ JS_IS_CONSTRUCTING, /* magic value passed to natives to indicate construction */ JS_OVERWRITTEN_CALLEE, /* arguments.callee has been overwritten */ - JS_FORWARD_TO_CALL_OBJECT, /* args object element stored in call object */ JS_BLOCK_NEEDS_CLONE, /* value of static block object slot */ JS_HASH_KEY_EMPTY, /* see class js::HashableValue */ JS_ION_ERROR, /* error while running Ion code */ - JS_ION_BAILOUT, /* status code to signal EnterIon will OSR into Interpret */ + JS_ION_BAILOUT, /* missing recover instruction result */ + JS_OPTIMIZED_OUT, /* optimized out slot */ JS_GENERIC_MAGIC /* for local use */ } JSWhyMagic; #if defined(IS_LITTLE_ENDIAN) -# if JS_BITS_PER_WORD == 32 +# if defined(JS_NUNBOX32) typedef union jsval_layout { uint64_t asBits; @@ -252,7 +257,9 @@ typedef union jsval_layout uint32_t u32; uint32_t boo; // Don't use |bool| -- it must be four bytes. JSString *str; + JS::Symbol *sym; JSObject *obj; + js::gc::Cell *cell; void *ptr; JSWhyMagic why; size_t word; @@ -263,7 +270,7 @@ typedef union jsval_layout double asDouble; void *asPtr; } JSVAL_ALIGNMENT jsval_layout; -# elif JS_BITS_PER_WORD == 64 +# elif defined(JS_PUNBOX64) typedef union jsval_layout { uint64_t asBits; @@ -286,9 +293,9 @@ typedef union jsval_layout size_t asWord; uintptr_t asUIntPtr; } JSVAL_ALIGNMENT jsval_layout; -# endif /* JS_BITS_PER_WORD */ +# endif /* JS_PUNBOX64 */ #else /* defined(IS_LITTLE_ENDIAN) */ -# if JS_BITS_PER_WORD == 32 +# if defined(JS_NUNBOX32) typedef union jsval_layout { uint64_t asBits; @@ -299,7 +306,9 @@ typedef union jsval_layout uint32_t u32; uint32_t boo; // Don't use |bool| -- it must be four bytes. JSString *str; + JS::Symbol *sym; JSObject *obj; + js::gc::Cell *cell; void *ptr; JSWhyMagic why; size_t word; @@ -309,7 +318,7 @@ typedef union jsval_layout double asDouble; void *asPtr; } JSVAL_ALIGNMENT jsval_layout; -# elif JS_BITS_PER_WORD == 64 +# elif defined(JS_PUNBOX64) typedef union jsval_layout { uint64_t asBits; @@ -330,7 +339,7 @@ typedef union jsval_layout size_t asWord; uintptr_t asUIntPtr; } JSVAL_ALIGNMENT jsval_layout; -# endif /* JS_BITS_PER_WORD */ +# endif /* JS_PUNBOX64 */ #endif /* defined(IS_LITTLE_ENDIAN) */ JS_STATIC_ASSERT(sizeof(jsval_layout) == 8); @@ -378,7 +387,7 @@ JS_STATIC_ASSERT(sizeof(jsval_layout) == 8); # define JS_VALUE_CONSTEXPR_VAR const #endif -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) /* * N.B. GCC, in some but not all cases, chooses to emit signed comparison of @@ -456,7 +465,7 @@ static inline jsval_layout STRING_TO_JSVAL_IMPL(JSString *str) { jsval_layout l; - MOZ_ASSERT(str); + MOZ_ASSERT(uintptr_t(str) > 0x1000); l.s.tag = JSVAL_TAG_STRING; l.s.payload.str = str; return l; @@ -468,6 +477,28 @@ JSVAL_TO_STRING_IMPL(jsval_layout l) return l.s.payload.str; } +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + l.s.tag = JSVAL_TAG_SYMBOL; + l.s.payload.sym = sym; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.payload.sym; +} + static inline bool JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) { @@ -524,7 +555,7 @@ static inline jsval_layout OBJECT_TO_JSVAL_IMPL(JSObject *obj) { jsval_layout l; - MOZ_ASSERT(obj); + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); l.s.tag = JSVAL_TAG_OBJECT; l.s.payload.obj = obj; return l; @@ -560,22 +591,22 @@ JSVAL_IS_GCTHING_IMPL(jsval_layout l) return (uint32_t)l.s.tag >= (uint32_t)JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET; } -static inline void * +static inline js::gc::Cell * JSVAL_TO_GCTHING_IMPL(jsval_layout l) { - return l.s.payload.ptr; -} - -static inline bool -JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) -{ - return l.s.tag == JSVAL_TAG_STRING || l.s.tag == JSVAL_TAG_OBJECT; + return l.s.payload.cell; } static inline uint32_t JSVAL_TRACE_KIND_IMPL(jsval_layout l) { - return (uint32_t)(bool)JSVAL_IS_STRING_IMPL(l); + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return l.s.tag & 0x03; } static inline bool @@ -585,7 +616,7 @@ JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) } static inline bool -JSVAL_IS_SPECIFIC_BOOLEAN(jsval_layout l, bool b) +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) { return (l.s.tag == JSVAL_TAG_BOOLEAN) && (l.s.payload.boo == uint32_t(b)); } @@ -599,6 +630,15 @@ MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) return l; } +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.s.tag = JSVAL_TAG_MAGIC; + l.s.payload.u32 = payload; + return l; +} + static inline bool JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) { @@ -614,7 +654,7 @@ JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) return (JSValueType)type; } -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) static inline JS_VALUE_CONSTEXPR jsval_layout BUILD_JSVAL(JSValueTag tag, uint64_t payload) @@ -678,7 +718,7 @@ STRING_TO_JSVAL_IMPL(JSString *str) { jsval_layout l; uint64_t strBits = (uint64_t)str; - MOZ_ASSERT(str); + MOZ_ASSERT(uintptr_t(str) > 0x1000); MOZ_ASSERT((strBits >> JSVAL_TAG_SHIFT) == 0); l.asBits = strBits | JSVAL_SHIFTED_TAG_STRING; return l; @@ -690,6 +730,29 @@ JSVAL_TO_STRING_IMPL(jsval_layout l) return (JSString *)(l.asBits & JSVAL_PAYLOAD_MASK); } +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + uint64_t symBits = (uint64_t)sym; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + MOZ_ASSERT((symBits >> JSVAL_TAG_SHIFT) == 0); + l.asBits = symBits | JSVAL_SHIFTED_TAG_SYMBOL; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return (JS::Symbol *)(l.asBits & JSVAL_PAYLOAD_MASK); +} + static inline bool JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) { @@ -725,7 +788,7 @@ JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l) static inline bool JSVAL_IS_OBJECT_IMPL(jsval_layout l) { - MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_SHIFTED_TAG_OBJECT); + MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_TAG_OBJECT); return l.asBits >= JSVAL_SHIFTED_TAG_OBJECT; } @@ -749,7 +812,7 @@ OBJECT_TO_JSVAL_IMPL(JSObject *obj) { jsval_layout l; uint64_t objBits = (uint64_t)obj; - MOZ_ASSERT(obj); + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); MOZ_ASSERT((objBits >> JSVAL_TAG_SHIFT) == 0); l.asBits = objBits | JSVAL_SHIFTED_TAG_OBJECT; return l; @@ -767,24 +830,24 @@ JSVAL_IS_GCTHING_IMPL(jsval_layout l) return l.asBits >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET; } -static inline void * +static inline js::gc::Cell * JSVAL_TO_GCTHING_IMPL(jsval_layout l) { uint64_t ptrBits = l.asBits & JSVAL_PAYLOAD_MASK; MOZ_ASSERT((ptrBits & 0x7) == 0); - return (void *)ptrBits; -} - -static inline bool -JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) -{ - return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l); + return reinterpret_cast(ptrBits); } static inline uint32_t JSVAL_TRACE_KIND_IMPL(jsval_layout l) { - return (uint32_t)(bool)!(JSVAL_IS_OBJECT_IMPL(l)); + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) & 0x03; } static inline jsval_layout @@ -812,7 +875,7 @@ JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) } static inline bool -JSVAL_IS_SPECIFIC_BOOLEAN(jsval_layout l, bool b) +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) { return l.asBits == (((uint64_t)(uint32_t)b) | JSVAL_SHIFTED_TAG_BOOLEAN); } @@ -825,6 +888,14 @@ MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) return l; } +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.asBits = ((uint64_t)payload) | JSVAL_SHIFTED_TAG_MAGIC; + return l; +} + static inline bool JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) { @@ -841,7 +912,13 @@ JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) return (JSValueType)type; } -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ + +static inline bool +JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) +{ + return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l); +} static inline jsval_layout JSVAL_TO_IMPL(JS::Value v); static inline JS_VALUE_CONSTEXPR JS::Value IMPL_TO_JSVAL(jsval_layout l); @@ -859,7 +936,7 @@ static inline JS_VALUE_CONSTEXPR JS::Value UndefinedValue(); static MOZ_ALWAYS_INLINE double GenericNaN() { - return mozilla::SpecificNaN(0, 0x8000000000000ULL); + return mozilla::SpecificNaN(0, 0x8000000000000ULL); } /* MSVC with PGO miscompiles this function. */ @@ -883,27 +960,23 @@ CanonicalizeNaN(double d) * * - JS::Value has setX() and isX() members for X in * - * { Int32, Double, String, Boolean, Undefined, Null, Object, Magic } + * { Int32, Double, String, Symbol, Boolean, Undefined, Null, Object, Magic } * * JS::Value also contains toX() for each of the non-singleton types. * - * - Magic is a singleton type whose payload contains a JSWhyMagic "reason" for - * the magic value. By providing JSWhyMagic values when creating and checking - * for magic values, it is possible to assert, at runtime, that only magic - * values with the expected reason flow through a particular value. For - * example, if cx->exception has a magic value, the reason must be - * JS_GENERATOR_CLOSING. + * - Magic is a singleton type whose payload contains either a JSWhyMagic "reason" for + * the magic value or a uint32_t value. By providing JSWhyMagic values when + * creating and checking for magic values, it is possible to assert, at + * runtime, that only magic values with the expected reason flow through a + * particular value. For example, if cx->exception has a magic value, the + * reason must be JS_GENERATOR_CLOSING. * * - The JS::Value operations are preferred. The JSVAL_* operations remain for * compatibility; they may be removed at some point. These operations mostly * provide similar functionality. But there are a few key differences. One - * is that JS::Value gives null a separate type. Thus - * - * JSVAL_IS_OBJECT(v) === v.isObjectOrNull() - * !JSVAL_IS_PRIMITIVE(v) === v.isObject() - * + * is that JS::Value gives null a separate type. * Also, to help prevent mistakenly boxing a nullable JSObject* as an object, - * Value::setObject takes a JSObject&. (Conversely, Value::asObject returns a + * Value::setObject takes a JSObject&. (Conversely, Value::toObject returns a * JSObject&.) A convenience member Value::setObjectOrNull is provided. * * - JSVAL_VOID is the same as the singleton value of the Undefined type. @@ -961,6 +1034,11 @@ class Value data = STRING_TO_JSVAL_IMPL(str); } + void setSymbol(JS::Symbol *sym) { + MOZ_ASSERT(!IsPoisonedPtr(sym)); + data = SYMBOL_TO_JSVAL_IMPL(sym); + } + void setObject(JSObject &obj) { MOZ_ASSERT(!IsPoisonedPtr(&obj)); data = OBJECT_TO_JSVAL_IMPL(&obj); @@ -974,6 +1052,10 @@ class Value data = MAGIC_TO_JSVAL_IMPL(why); } + void setMagicUint32(uint32_t payload) { + data = MAGIC_UINT32_TO_JSVAL_IMPL(payload); + } + bool setNumber(uint32_t ui) { if (ui > JSVAL_INT_MAX) { setDouble((double)ui); @@ -986,7 +1068,7 @@ class Value bool setNumber(double d) { int32_t i; - if (mozilla::DoubleIsInt32(d, &i)) { + if (mozilla::NumberIsInt32(d, &i)) { setInt32(i); return true; } @@ -1042,6 +1124,10 @@ class Value return JSVAL_IS_STRING_IMPL(data); } + bool isSymbol() const { + return JSVAL_IS_SYMBOL_IMPL(data); + } + bool isObject() const { return JSVAL_IS_OBJECT_IMPL(data); } @@ -1063,11 +1149,11 @@ class Value } bool isTrue() const { - return JSVAL_IS_SPECIFIC_BOOLEAN(data, true); + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, true); } bool isFalse() const { - return JSVAL_IS_SPECIFIC_BOOLEAN(data, false); + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, false); } bool isMagic() const { @@ -1093,6 +1179,11 @@ class Value return data.s.payload.why; } + uint32_t magicUint32() const { + MOZ_ASSERT(isMagic()); + return data.s.payload.u32; + } + /*** Comparison ***/ bool operator==(const Value &rhs) const { @@ -1127,6 +1218,11 @@ class Value return JSVAL_TO_STRING_IMPL(data); } + JS::Symbol *toSymbol() const { + MOZ_ASSERT(isSymbol()); + return JSVAL_TO_SYMBOL_IMPL(data); + } + JSObject &toObject() const { MOZ_ASSERT(isObject()); return *JSVAL_TO_OBJECT_IMPL(data); @@ -1137,7 +1233,7 @@ class Value return JSVAL_TO_OBJECT_IMPL(data); } - void *toGCThing() const { + js::gc::Cell *toGCThing() const { MOZ_ASSERT(isGCThing()); return JSVAL_TO_GCTHING_IMPL(data); } @@ -1202,17 +1298,17 @@ class Value } const size_t *payloadWord() const { -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) return &data.s.payload.word; -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) return &data.asWord; #endif } const uintptr_t *payloadUIntPtr() const { -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) return &data.s.payload.uintptr; -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) return &data.asUIntPtr; #endif } @@ -1228,7 +1324,7 @@ class Value private: #if defined(JS_VALUE_IS_CONSTEXPR) - JS_VALUE_CONSTEXPR Value(jsval_layout layout) : data(layout) {} + MOZ_IMPLICIT JS_VALUE_CONSTEXPR Value(jsval_layout layout) : data(layout) {} #endif void staticAssertions() { @@ -1248,11 +1344,30 @@ IsPoisonedValue(const Value &v) { if (v.isString()) return IsPoisonedPtr(v.toString()); + if (v.isSymbol()) + return IsPoisonedPtr(v.toSymbol()); if (v.isObject()) return IsPoisonedPtr(&v.toObject()); return false; } +inline bool +IsOptimizedPlaceholderMagicValue(const Value &v) +{ + if (v.isMagic()) { + MOZ_ASSERT(v.whyMagic() == JS_OPTIMIZED_ARGUMENTS || v.whyMagic() == JS_OPTIMIZED_OUT); + return true; + } + return false; +} + +static MOZ_ALWAYS_INLINE void +ExposeValueToActiveJS(const Value &v) +{ + if (v.isMarkable()) + ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); +} + /************************************************************************/ static inline Value @@ -1315,6 +1430,14 @@ StringValue(JSString *str) return v; } +static inline Value +SymbolValue(JS::Symbol *sym) +{ + Value v; + v.setSymbol(sym); + return v; +} + static inline Value BooleanValue(bool boo) { @@ -1363,6 +1486,14 @@ MagicValue(JSWhyMagic why) return v; } +static inline Value +MagicValueUint32(uint32_t payload) +{ + Value v; + v.setMagicUint32(payload); + return v; +} + static inline Value NumberValue(float f) { @@ -1507,16 +1638,16 @@ namespace js { template <> struct GCMethods { static JS::Value initial() { return JS::UndefinedValue(); } - static ThingRootKind kind() { return THING_ROOT_VALUE; } static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } }; template <> struct GCMethods { static JS::Value initial() { return JS::UndefinedValue(); } - static ThingRootKind kind() { return THING_ROOT_VALUE; } static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } - static bool needsPostBarrier(const JS::Value &v) { return v.isMarkable(); } + static bool needsPostBarrier(const JS::Value &v) { + return v.isObject() && gc::IsInsideNursery(reinterpret_cast(&v.toObject())); + } #ifdef JSGC_GENERATIONAL static void postBarrier(JS::Value *v) { JS::HeapValuePostBarrier(v); } static void relocate(JS::Value *v) { JS::HeapValueRelocate(v); } @@ -1548,6 +1679,7 @@ class ValueOperations bool isInt32() const { return value()->isInt32(); } bool isDouble() const { return value()->isDouble(); } bool isString() const { return value()->isString(); } + bool isSymbol() const { return value()->isSymbol(); } bool isObject() const { return value()->isObject(); } bool isMagic() const { return value()->isMagic(); } bool isMagic(JSWhyMagic why) const { return value()->isMagic(why); } @@ -1563,14 +1695,17 @@ class ValueOperations int32_t toInt32() const { return value()->toInt32(); } double toDouble() const { return value()->toDouble(); } JSString *toString() const { return value()->toString(); } + JS::Symbol *toSymbol() const { return value()->toSymbol(); } JSObject &toObject() const { return value()->toObject(); } JSObject *toObjectOrNull() const { return value()->toObjectOrNull(); } void *toGCThing() const { return value()->toGCThing(); } + uint64_t asRawBits() const { return value()->asRawBits(); } JSValueType extractNonDoubleType() const { return value()->extractNonDoubleType(); } uint32_t toPrivateUint32() const { return value()->toPrivateUint32(); } JSWhyMagic whyMagic() const { return value()->whyMagic(); } + uint32_t magicUint32() const { return value()->magicUint32(); } }; /* @@ -1595,6 +1730,7 @@ class MutableValueOperations : public ValueOperations bool setNumber(uint32_t ui) { return value()->setNumber(ui); } bool setNumber(double d) { return value()->setNumber(d); } void setString(JSString *str) { this->value()->setString(str); } + void setSymbol(JS::Symbol *sym) { this->value()->setSymbol(sym); } void setObject(JSObject &obj) { this->value()->setObject(obj); } void setObjectOrNull(JSObject *arg) { this->value()->setObjectOrNull(arg); } }; @@ -1625,6 +1761,7 @@ class HeapBase : public ValueOperations > void setBoolean(bool b) { setBarriered(JS::BooleanValue(b)); } void setMagic(JSWhyMagic why) { setBarriered(JS::MagicValue(why)); } void setString(JSString *str) { setBarriered(JS::StringValue(str)); } + void setSymbol(JS::Symbol *sym) { setBarriered(JS::SymbolValue(sym)); } void setObject(JSObject &obj) { setBarriered(JS::ObjectValue(obj)); } bool setNumber(uint32_t ui) { @@ -1639,7 +1776,7 @@ class HeapBase : public ValueOperations > bool setNumber(double d) { int32_t i; - if (mozilla::DoubleIsInt32(d, &i)) { + if (mozilla::NumberIsInt32(d, &i)) { setInt32(i); return true; } @@ -1747,7 +1884,7 @@ inline Anchor::~Anchor() } #endif -#ifdef DEBUG +#ifdef JS_DEBUG namespace detail { struct ValueAlignmentTester { char c; JS::Value v; }; @@ -1759,7 +1896,7 @@ static_assert(sizeof(LayoutAlignmentTester) == 16, "jsval_layout must be 16-byte-aligned"); } // namespace detail -#endif /* DEBUG */ +#endif /* JS_DEBUG */ } // namespace JS @@ -1775,52 +1912,12 @@ static_assert(sizeof(jsval_layout) == sizeof(JS::Value), /************************************************************************/ -static inline bool -JSVAL_IS_NULL(jsval v) -{ - return JSVAL_IS_NULL_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_VOID(jsval v) -{ - return JSVAL_IS_UNDEFINED_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_INT(jsval v) -{ - return JSVAL_IS_INT32_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline int32_t -JSVAL_TO_INT(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_INT(v)); - return JSVAL_TO_INT32_IMPL(JSVAL_TO_IMPL(v)); -} - static inline JS_VALUE_CONSTEXPR jsval INT_TO_JSVAL(int32_t i) { return IMPL_TO_JSVAL(INT32_TO_JSVAL_IMPL(i)); } -static inline bool -JSVAL_IS_DOUBLE(jsval v) -{ - return JSVAL_IS_DOUBLE_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline double -JSVAL_TO_DOUBLE(jsval v) -{ - jsval_layout l; - MOZ_ASSERT(JSVAL_IS_DOUBLE(v)); - l = JSVAL_TO_IMPL(v); - return l.asDouble; -} - static inline JS_VALUE_CONSTEXPR jsval DOUBLE_TO_JSVAL(double d) { @@ -1852,38 +1949,12 @@ UINT_TO_JSVAL(uint32_t i) : DOUBLE_TO_JSVAL((double)i)); } -static inline bool -JSVAL_IS_NUMBER(jsval v) -{ - return JSVAL_IS_NUMBER_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_STRING(jsval v) -{ - return JSVAL_IS_STRING_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline JSString * -JSVAL_TO_STRING(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_STRING(v)); - return JSVAL_TO_STRING_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval STRING_TO_JSVAL(JSString *str) { return IMPL_TO_JSVAL(STRING_TO_JSVAL_IMPL(str)); } -static inline JSObject * -JSVAL_TO_OBJECT(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_OBJECT_OR_NULL_IMPL(JSVAL_TO_IMPL(v))); - return JSVAL_TO_OBJECT_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval OBJECT_TO_JSVAL(JSObject *obj) { @@ -1892,44 +1963,12 @@ OBJECT_TO_JSVAL(JSObject *obj) return IMPL_TO_JSVAL(BUILD_JSVAL(JSVAL_TAG_NULL, 0)); } -static inline bool -JSVAL_IS_BOOLEAN(jsval v) -{ - return JSVAL_IS_BOOLEAN_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_TO_BOOLEAN(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_BOOLEAN(v)); - return JSVAL_TO_BOOLEAN_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval BOOLEAN_TO_JSVAL(bool b) { return IMPL_TO_JSVAL(BOOLEAN_TO_JSVAL_IMPL(b)); } -static inline bool -JSVAL_IS_PRIMITIVE(jsval v) -{ - return JSVAL_IS_PRIMITIVE_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_GCTHING(jsval v) -{ - return JSVAL_IS_GCTHING_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline void * -JSVAL_TO_GCTHING(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_GCTHING(v)); - return JSVAL_TO_GCTHING_IMPL(JSVAL_TO_IMPL(v)); -} - /* To be GC-safe, privates are tagged as doubles. */ static inline jsval @@ -1938,13 +1977,6 @@ PRIVATE_TO_JSVAL(void *ptr) return IMPL_TO_JSVAL(PRIVATE_PTR_TO_JSVAL_IMPL(ptr)); } -static inline void * -JSVAL_TO_PRIVATE(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_DOUBLE(v)); - return JSVAL_TO_PRIVATE_PTR_IMPL(JSVAL_TO_IMPL(v)); -} - // JS constants. For efficiency, prefer predicates (e.g. v.isNull()) and // constructing values from scratch (e.g. Int32Value(0)). These constants are // stored in memory and initialized at startup, so testing against them and @@ -1958,8 +1990,10 @@ extern JS_PUBLIC_DATA(const jsval) JSVAL_VOID; namespace JS { -extern JS_PUBLIC_DATA(const Handle) NullHandleValue; -extern JS_PUBLIC_DATA(const Handle) UndefinedHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) NullHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) TrueHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) FalseHandleValue; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/Vector.h index e8aef1713d..a2d24b10ed 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/Vector.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/Vector.h @@ -54,7 +54,7 @@ class Vector typedef typename mozilla::VectorBase Base; public: - Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} Vector(Vector &&vec) : Base(mozilla::Move(vec)) {} Vector &operator=(Vector &&vec) { return Base::operator=(mozilla::Move(vec)); diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/WeakMapPtr.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/WeakMapPtr.h new file mode 100644 index 0000000000..f5822bef4b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/WeakMapPtr.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_WeakMapPtr_h +#define js_WeakMapPtr_h + +#include "jspubtd.h" + +#include "js/TypeDecls.h" + +namespace JS { + +// A wrapper around the internal C++ representation of SpiderMonkey WeakMaps, +// usable outside the engine. +// +// The supported template specializations are enumerated in WeakMapPtr.cpp. If +// you want to use this class for a different key/value combination, add it to +// the list and the compiler will generate the relevant machinery. +template +class JS_PUBLIC_API(WeakMapPtr) +{ + public: + WeakMapPtr() : ptr(nullptr) {}; + bool init(JSContext *cx); + bool initialized() { return ptr != nullptr; }; + void destroy(); + virtual ~WeakMapPtr() { MOZ_ASSERT(!initialized()); } + void trace(JSTracer *tracer); + + V lookup(const K &key); + bool put(JSContext *cx, const K &key, const V &value); + + static void keyMarkCallback(JSTracer *trc, K key, void *data); + + private: + void *ptr; + + // WeakMapPtr is neither copyable nor assignable. + WeakMapPtr(const WeakMapPtr &wmp) MOZ_DELETE; + WeakMapPtr &operator=(const WeakMapPtr &wmp) MOZ_DELETE; +}; + +} /* namespace JS */ + +#endif /* js_WeakMapPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/jsalloc.h b/frameworks/js-bindings/external/spidermonkey/include/ios/jsalloc.h index 03b6b569e1..a1e547cec9 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/jsalloc.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/jsalloc.h @@ -4,7 +4,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/* JS allocation policies. */ +/* + * JS allocation policies. + * + * The allocators here are for system memory with lifetimes which are not + * managed by the GC. See the comment at the top of vm/MallocProvider.h. + */ #ifndef jsalloc_h #define jsalloc_h @@ -14,7 +19,7 @@ namespace js { -class ContextFriendFields; +struct ContextFriendFields; /* Policy for using system memory functions and doing no error reporting. */ class SystemAllocPolicy @@ -47,26 +52,26 @@ class TempAllocPolicy JS_FRIEND_API(void *) onOutOfMemory(void *p, size_t nbytes); public: - TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( - TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} + MOZ_IMPLICIT TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( + MOZ_IMPLICIT TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} void *malloc_(size_t bytes) { void *p = js_malloc(bytes); - if (JS_UNLIKELY(!p)) + if (MOZ_UNLIKELY(!p)) p = onOutOfMemory(nullptr, bytes); return p; } void *calloc_(size_t bytes) { void *p = js_calloc(bytes); - if (JS_UNLIKELY(!p)) + if (MOZ_UNLIKELY(!p)) p = onOutOfMemory(nullptr, bytes); return p; } void *realloc_(void *p, size_t oldBytes, size_t bytes) { void *p2 = js_realloc(p, bytes); - if (JS_UNLIKELY(!p2)) + if (MOZ_UNLIKELY(!p2)) p2 = onOutOfMemory(p2, bytes); return p2; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/jsapi.h b/frameworks/js-bindings/external/spidermonkey/include/ios/jsapi.h index 6d47488a33..4b5a4ce1ff 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/jsapi.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/jsapi.h @@ -9,10 +9,11 @@ #ifndef jsapi_h #define jsapi_h -#include "mozilla/Atomics.h" #include "mozilla/FloatingPoint.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/Range.h" #include "mozilla/RangedPtr.h" +#include "mozilla/TypedEnum.h" #include #include @@ -26,40 +27,28 @@ #include "js/Class.h" #include "js/HashTable.h" #include "js/Id.h" +#include "js/Principals.h" #include "js/RootingAPI.h" +#include "js/TracingAPI.h" #include "js/Utility.h" #include "js/Value.h" #include "js/Vector.h" /************************************************************************/ -struct JSTracer; - namespace JS { class Latin1CharsZ; class TwoByteChars; -typedef mozilla::RangedPtr CharPtr; - -class StableCharPtr : public CharPtr { - public: - StableCharPtr(const StableCharPtr &s) : CharPtr(s) {} - StableCharPtr(const mozilla::RangedPtr &s) : CharPtr(s) {} - StableCharPtr(const jschar *s, size_t len) : CharPtr(s, len) {} - StableCharPtr(const jschar *pos, const jschar *start, size_t len) - : CharPtr(pos, start, len) - {} -}; - -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG class JS_PUBLIC_API(AutoCheckRequestDepth) { JSContext *cx; public: - AutoCheckRequestDepth(JSContext *cx); - AutoCheckRequestDepth(js::ContextFriendFields *cx); + explicit AutoCheckRequestDepth(JSContext *cx); + explicit AutoCheckRequestDepth(js::ContextFriendFields *cx); ~AutoCheckRequestDepth(); }; @@ -71,155 +60,53 @@ class JS_PUBLIC_API(AutoCheckRequestDepth) # define CHECK_REQUEST(cx) \ ((void) 0) -#endif /* JS_THREADSAFE && DEBUG */ +#endif /* JS_THREADSAFE && JS_DEBUG */ -#ifdef DEBUG +#ifdef JS_DEBUG /* * Assert that we're not doing GC on cx, that we're in a request as * needed, and that the compartments for cx and v are correct. * Also check that GC would be safe at this point. */ JS_PUBLIC_API(void) -AssertArgumentsAreSane(JSContext *cx, JS::Handle v); +AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v); #else -inline void AssertArgumentsAreSane(JSContext *cx, JS::Handle v) { +inline void AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v) { /* Do nothing */ } -#endif /* DEBUG */ - -class JS_PUBLIC_API(AutoGCRooter) { - public: - AutoGCRooter(JSContext *cx, ptrdiff_t tag); - AutoGCRooter(js::ContextFriendFields *cx, ptrdiff_t tag); - - ~AutoGCRooter() { - JS_ASSERT(this == *stackTop); - *stackTop = down; - } - - /* Implemented in gc/RootMarking.cpp. */ - inline void trace(JSTracer *trc); - static void traceAll(JSTracer *trc); - static void traceAllWrappers(JSTracer *trc); - - protected: - AutoGCRooter * const down; - - /* - * Discriminates actual subclass of this being used. If non-negative, the - * subclass roots an array of values of the length stored in this field. - * If negative, meaning is indicated by the corresponding value in the enum - * below. Any other negative value indicates some deeper problem such as - * memory corruption. - */ - ptrdiff_t tag_; - - enum { - VALARRAY = -2, /* js::AutoValueArray */ - PARSER = -3, /* js::frontend::Parser */ - SHAPEVECTOR = -4, /* js::AutoShapeVector */ - IDARRAY = -6, /* js::AutoIdArray */ - DESCRIPTORS = -7, /* js::AutoPropDescArrayRooter */ - ID = -9, /* js::AutoIdRooter */ - VALVECTOR = -10, /* js::AutoValueVector */ - STRING = -12, /* js::AutoStringRooter */ - IDVECTOR = -13, /* js::AutoIdVector */ - OBJVECTOR = -14, /* js::AutoObjectVector */ - STRINGVECTOR =-15, /* js::AutoStringVector */ - SCRIPTVECTOR =-16, /* js::AutoScriptVector */ - NAMEVECTOR = -17, /* js::AutoNameVector */ - HASHABLEVALUE=-18, /* js::HashableValue */ - IONMASM = -19, /* js::jit::MacroAssembler */ - IONALLOC = -20, /* js::jit::AutoTempAllocatorRooter */ - WRAPVECTOR = -21, /* js::AutoWrapperVector */ - WRAPPER = -22, /* js::AutoWrapperRooter */ - OBJOBJHASHMAP=-23, /* js::AutoObjectObjectHashMap */ - OBJU32HASHMAP=-24, /* js::AutoObjectUnsigned32HashMap */ - OBJHASHSET = -25, /* js::AutoObjectHashSet */ - JSONPARSER = -26, /* js::JSONParser */ - CUSTOM = -27, /* js::CustomAutoRooter */ - FUNVECTOR = -28 /* js::AutoFunctionVector */ - }; - - private: - AutoGCRooter ** const stackTop; - - /* No copy or assignment semantics. */ - AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; - void operator=(AutoGCRooter &ida) MOZ_DELETE; -}; - -class AutoStringRooter : private AutoGCRooter { - public: - AutoStringRooter(JSContext *cx, JSString *str = nullptr - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, STRING), str_(str) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - void setString(JSString *str) { - str_ = str; - } - - JSString * string() const { - return str_; - } - - JSString ** addr() { - return &str_; - } - - JSString * const * addr() const { - return &str_; - } - - friend void AutoGCRooter::trace(JSTracer *trc); +#endif /* JS_DEBUG */ - private: - JSString *str_; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER -}; +/* AutoValueArray roots an internal fixed-size array of Values. */ +template +class AutoValueArray : public AutoGCRooter +{ + const size_t length_; + Value elements_[N]; -class AutoArrayRooter : private AutoGCRooter { public: - AutoArrayRooter(JSContext *cx, size_t len, Value *vec - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, len), array(vec), skip(cx, array, len) + explicit AutoValueArray(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, VALARRAY), length_(N) { + /* Always initialize in case we GC before assignment. */ + mozilla::PodArrayZero(elements_); MOZ_GUARD_OBJECT_NOTIFIER_INIT; - JS_ASSERT(tag_ >= 0); - } - - void changeLength(size_t newLength) { - tag_ = ptrdiff_t(newLength); - JS_ASSERT(tag_ >= 0); - } - - void changeArray(Value *newArray, size_t newLength) { - changeLength(newLength); - array = newArray; } - Value *array; + unsigned length() const { return length_; } + const Value *begin() const { return elements_; } + Value *begin() { return elements_; } - MutableHandle handleAt(size_t i) - { - JS_ASSERT(i < size_t(tag_)); - return MutableHandle::fromMarkedLocation(&array[i]); + HandleValue operator[](unsigned i) const { + JS_ASSERT(i < N); + return HandleValue::fromMarkedLocation(&elements_[i]); } - Handle handleAt(size_t i) const - { - JS_ASSERT(i < size_t(tag_)); - return Handle::fromMarkedLocation(&array[i]); + MutableHandleValue operator[](unsigned i) { + JS_ASSERT(i < N); + return MutableHandleValue::fromMarkedLocation(&elements_[i]); } - friend void AutoGCRooter::trace(JSTracer *trc); - - private: MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER - - js::SkipRoot skip; }; template @@ -228,20 +115,17 @@ class AutoVectorRooter : protected AutoGCRooter typedef js::Vector VectorImpl; VectorImpl vector; - /* Prevent overwriting of inline elements in vector. */ - js::SkipRoot vectorRoot; - public: explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, tag), vector(cx), vectorRoot(cx, &vector) + : AutoGCRooter(cx, tag), vector(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; } explicit AutoVectorRooter(js::ContextFriendFields *cx, ptrdiff_t tag MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, tag), vector(cx), vectorRoot(cx, &vector) + : AutoGCRooter(cx, tag), vector(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; } @@ -253,6 +137,7 @@ class AutoVectorRooter : protected AutoGCRooter bool empty() const { return vector.empty(); } bool append(const T &v) { return vector.append(v); } + bool append(const T *ptr, size_t len) { return vector.append(ptr, len); } bool appendAll(const AutoVectorRooter &other) { return vector.appendAll(other.vector); } @@ -291,13 +176,10 @@ class AutoVectorRooter : protected AutoGCRooter return vector.reserve(newLength); } - T &operator[](size_t i) { return vector[i]; } - const T &operator[](size_t i) const { return vector[i]; } - - JS::MutableHandle handleAt(size_t i) { + JS::MutableHandle operator[](size_t i) { return JS::MutableHandle::fromMarkedLocation(&vector[i]); } - JS::Handle handleAt(size_t i) const { + JS::Handle operator[](size_t i) const { return JS::Handle::fromMarkedLocation(&vector[i]); } @@ -408,7 +290,7 @@ class AutoHashMapRooter : protected AutoGCRooter return map.sizeOfIncludingThis(mallocSizeOf); } - unsigned generation() const { + uint32_t generation() const { return map.generation(); } @@ -523,7 +405,7 @@ class AutoHashSetRooter : protected AutoGCRooter return set.sizeOfIncludingThis(mallocSizeOf); } - unsigned generation() const { + uint32_t generation() const { return set.generation(); } @@ -629,7 +511,7 @@ class AutoScriptVector : public AutoVectorRooter }; /* - * Cutsom rooting behavior for internal and external clients. + * Custom rooting behavior for internal and external clients. */ class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter { @@ -651,6 +533,86 @@ class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER }; +/* + * RootedGeneric allows a class to instantiate its own Rooted type by + * including the method: + * + * void trace(JSTracer *trc); + * + * The trace() method must trace all of the class's fields. + */ +template +class RootedGeneric : private CustomAutoRooter +{ + public: + template + explicit RootedGeneric(CX *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + template + explicit RootedGeneric(CX *cx, const T& initial MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx), value(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + operator const T&() const { return value; } + T operator->() const { return value; } + + private: + virtual void trace(JSTracer *trc) { value->trace(trc); } + + T value; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* A handle to an array of rooted values. */ +class HandleValueArray +{ + const size_t length_; + const Value * const elements_; + + HandleValueArray(size_t len, const Value *elements) : length_(len), elements_(elements) {} + + public: + explicit HandleValueArray(const RootedValue& value) : length_(1), elements_(value.address()) {} + + MOZ_IMPLICIT HandleValueArray(const AutoValueVector& values) + : length_(values.length()), elements_(values.begin()) {} + + template + HandleValueArray(const AutoValueArray& values) : length_(N), elements_(values.begin()) {} + + /* CallArgs must already be rooted somewhere up the stack. */ + MOZ_IMPLICIT HandleValueArray(const JS::CallArgs& args) : length_(args.length()), elements_(args.array()) {} + + /* Use with care! Only call this if the data is guaranteed to be marked. */ + static HandleValueArray fromMarkedLocation(size_t len, const Value *elements) { + return HandleValueArray(len, elements); + } + + static HandleValueArray subarray(const HandleValueArray& values, size_t startIndex, size_t len) { + JS_ASSERT(startIndex + len <= values.length()); + return HandleValueArray(len, values.begin() + startIndex); + } + + static HandleValueArray empty() { + return HandleValueArray(0, nullptr); + } + + size_t length() const { return length_; } + const Value *begin() const { return elements_; } + + HandleValue operator[](size_t i) const { + JS_ASSERT(i < length_); + return HandleValue::fromMarkedLocation(&elements_[i]); + } +}; + } /* namespace JS */ /************************************************************************/ @@ -660,7 +622,7 @@ struct JSFreeOp { JSRuntime *runtime_; protected: - JSFreeOp(JSRuntime *rt) + explicit JSFreeOp(JSRuntime *rt) : runtime_(rt) { } public: @@ -725,10 +687,10 @@ typedef enum JSFinalizeStatus { } JSFinalizeStatus; typedef void -(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment); +(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment, void *data); typedef bool -(* JSOperationCallback)(JSContext *cx); +(* JSInterruptCallback)(JSContext *cx); typedef void (* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report); @@ -771,37 +733,20 @@ typedef struct JSErrorFormatString { } JSErrorFormatString; typedef const JSErrorFormatString * -(* JSErrorCallback)(void *userRef, const char *locale, - const unsigned errorNumber); +(* JSErrorCallback)(void *userRef, const unsigned errorNumber); typedef bool -(* JSLocaleToUpperCase)(JSContext *cx, JS::Handle src, - JS::MutableHandle rval); +(* JSLocaleToUpperCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); typedef bool -(* JSLocaleToLowerCase)(JSContext *cx, JS::Handle src, - JS::MutableHandle rval); +(* JSLocaleToLowerCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); typedef bool -(* JSLocaleCompare)(JSContext *cx, JS::Handle src1, JS::Handle src2, - JS::MutableHandle rval); - -typedef bool -(* JSLocaleToUnicode)(JSContext *cx, const char *src, JS::MutableHandle rval); - -/* - * Security protocol types. - */ - -typedef void -(* JSDestroyPrincipalsOp)(JSPrincipals *principals); +(* JSLocaleCompare)(JSContext *cx, JS::HandleString src1, JS::HandleString src2, + JS::MutableHandleValue rval); -/* - * Used to check if a CSP instance wants to disable eval() and friends. - * See js_CheckCSPPermitsJSAction() in jsobj. - */ typedef bool -(* JSCSPEvalChecker)(JSContext *cx); +(* JSLocaleToUnicode)(JSContext *cx, const char *src, JS::MutableHandleValue rval); /* * Callback used to ask the embedding for the cross compartment wrapper handler @@ -813,9 +758,8 @@ typedef bool * guaranteed not to wrap a function. */ typedef JSObject * -(* JSWrapObjectCallback)(JSContext *cx, JS::Handle existing, JS::Handle obj, - JS::Handle proto, JS::Handle parent, - unsigned flags); +(* JSWrapObjectCallback)(JSContext *cx, JS::HandleObject existing, JS::HandleObject obj, + JS::HandleObject parent, unsigned flags); /* * Callback used by the wrap hook to ask the embedding to prepare an object @@ -823,26 +767,12 @@ typedef JSObject * * or even finding a more suitable object for the new compartment. */ typedef JSObject * -(* JSPreWrapCallback)(JSContext *cx, JS::Handle scope, JS::Handle obj, +(* JSPreWrapCallback)(JSContext *cx, JS::HandleObject scope, JS::HandleObject obj, unsigned flags); -/* - * Callback used when wrapping determines that the underlying object is already - * in the compartment for which it is being wrapped. This allows consumers to - * maintain same-compartment wrapping invariants. - * - * |obj| is guaranteed to be same-compartment as |cx|, but it may (or may not) - * be a security or cross-compartment wrapper. This is an unfortunate contract, - * but is important for to avoid unnecessarily recomputing every cross- - * compartment wrapper that gets passed to wrap. - */ -typedef JSObject * -(* JSSameCompartmentWrapObjectCallback)(JSContext *cx, JS::Handle obj); - struct JSWrapObjectCallbacks { JSWrapObjectCallback wrap; - JSSameCompartmentWrapObjectCallback sameCompartmentWrap; JSPreWrapCallback preWrap; }; @@ -858,12 +788,12 @@ typedef void /************************************************************************/ -static JS_ALWAYS_INLINE jsval +static MOZ_ALWAYS_INLINE jsval JS_NumberValue(double d) { int32_t i; d = JS::CanonicalizeNaN(d); - if (mozilla::DoubleIsInt32(d, &i)) + if (mozilla::NumberIsInt32(d, &i)) return INT_TO_JSVAL(i); return DOUBLE_TO_JSVAL(d); } @@ -883,41 +813,91 @@ JS_StringHasBeenInterned(JSContext *cx, JSString *str); JS_PUBLIC_API(jsid) INTERNED_STRING_TO_JSID(JSContext *cx, JSString *str); -/* - * Returns true iff the given jsval is immune to GC and can be used across - * multiple JSRuntimes without requiring any conversion API. - */ -static JS_ALWAYS_INLINE bool -JSVAL_IS_UNIVERSAL(jsval v) -{ - return !JSVAL_IS_GCTHING(v); -} - namespace JS { -class AutoIdRooter : private AutoGCRooter +// Container class for passing in script source buffers to the JS engine. This +// not only groups the buffer and length values, it also provides a way to +// optionally pass ownership of the buffer to the JS engine without copying. +// Rules for use: +// +// 1) The data array must be allocated with js_malloc() or js_realloc() if +// ownership is being granted to the SourceBufferHolder. +// 2) If ownership is not given to the SourceBufferHolder, then the memory +// must be kept alive until the JS compilation is complete. +// 3) Any code calling SourceBufferHolder::take() must guarantee to keep the +// memory alive until JS compilation completes. Normally only the JS +// engine should be calling take(). +// +// Example use: +// +// size_t length = 512; +// jschar* chars = static_cast(js_malloc(sizeof(jschar) * length)); +// JS::SourceBufferHolder srcBuf(chars, length, JS::SourceBufferHolder::GiveOwnership); +// JS::Compile(cx, obj, options, srcBuf); +// +class MOZ_STACK_CLASS SourceBufferHolder MOZ_FINAL { public: - explicit AutoIdRooter(JSContext *cx, jsid aId = INT_TO_JSID(0) - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, ID), id_(aId) + enum Ownership { + NoOwnership, + GiveOwnership + }; + + SourceBufferHolder(const jschar *data, size_t dataLength, Ownership ownership) + : data_(data), + length_(dataLength), + ownsChars_(ownership == GiveOwnership) { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; + // Ensure that null buffers properly return an unowned, empty, + // null-terminated string. + static const jschar NullChar_ = 0; + if (!get()) { + data_ = &NullChar_; + length_ = 0; + ownsChars_ = false; + } } - jsid id() { - return id_; + ~SourceBufferHolder() { + if (ownsChars_) + js_free(const_cast(data_)); } - jsid * addr() { - return &id_; - } + // Access the underlying source buffer without affecting ownership. + const jschar *get() const { return data_; } - friend void AutoGCRooter::trace(JSTracer *trc); + // Length of the source buffer in jschars (not bytes) + size_t length() const { return length_; } + + // Returns true if the SourceBufferHolder owns the buffer and will free + // it upon destruction. If true, it is legal to call take(). + bool ownsChars() const { return ownsChars_; } + + // Retrieve and take ownership of the underlying data buffer. The caller + // is now responsible for calling js_free() on the returned value, *but only + // after JS script compilation has completed*. + // + // After the buffer has been taken the SourceBufferHolder functions as if + // it had been constructed on an unowned buffer; get() and length() still + // work. In order for this to be safe the taken buffer must be kept alive + // until after JS script compilation completes as noted above. + // + // Note, it's the caller's responsibility to check ownsChars() before taking + // the buffer. Taking and then free'ing an unowned buffer will have dire + // consequences. + jschar *take() { + JS_ASSERT(ownsChars_); + ownsChars_ = false; + return const_cast(data_); + } private: - jsid id_; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + SourceBufferHolder(SourceBufferHolder &) MOZ_DELETE; + SourceBufferHolder &operator=(SourceBufferHolder &) MOZ_DELETE; + + const jschar *data_; + size_t length_; + bool ownsChars_; }; } /* namespace JS */ @@ -941,8 +921,6 @@ class AutoIdRooter : private AutoGCRooter object that delegates to a prototype containing this property */ #define JSPROP_INDEX 0x80 /* name is actually (int) index */ -#define JSPROP_SHORTID 0x100 /* set in JS_DefineProperty attrs - if getters/setters use a shortid */ #define JSFUN_STUB_GSOPS 0x200 /* use JS_PropertyStub getter/setter instead of defaulting to class gsops @@ -1029,13 +1007,12 @@ JS_GetEmptyString(JSRuntime *rt); * unconverted arguments. */ extern JS_PUBLIC_API(bool) -JS_ConvertArguments(JSContext *cx, unsigned argc, jsval *argv, const char *format, - ...); +JS_ConvertArguments(JSContext *cx, const JS::CallArgs &args, const char *format, ...); #ifdef va_start extern JS_PUBLIC_API(bool) -JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv, - const char *format, va_list ap); +JS_ConvertArgumentsVA(JSContext *cx, const JS::CallArgs &args, const char *format, + va_list ap); #endif extern JS_PUBLIC_API(bool) @@ -1051,7 +1028,7 @@ extern JS_PUBLIC_API(JSFunction *) JS_ValueToConstructor(JSContext *cx, JS::HandleValue v); extern JS_PUBLIC_API(JSString *) -JS_ValueToSource(JSContext *cx, jsval v); +JS_ValueToSource(JSContext *cx, JS::Handle v); namespace js { /* @@ -1076,14 +1053,10 @@ ToStringSlow(JSContext *cx, JS::HandleValue v); namespace JS { /* ES5 9.3 ToNumber. */ -JS_ALWAYS_INLINE bool -ToNumber(JSContext *cx, Handle v, double *out) +MOZ_ALWAYS_INLINE bool +ToNumber(JSContext *cx, HandleValue v, double *out) { AssertArgumentsAreSane(cx, v); - { - js::SkipRoot root(cx, &v); - js::MaybeCheckStackRoots(cx); - } if (v.isNumber()) { *out = v.toNumber(); @@ -1092,7 +1065,7 @@ ToNumber(JSContext *cx, Handle v, double *out) return js::ToNumberSlow(cx, v, out); } -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool ToBoolean(HandleValue v) { if (v.isBoolean()) @@ -1105,12 +1078,14 @@ ToBoolean(HandleValue v) double d = v.toDouble(); return !mozilla::IsNaN(d) && d != 0; } + if (v.isSymbol()) + return true; /* The slow path handles strings and objects. */ return js::ToBooleanSlow(v); } -JS_ALWAYS_INLINE JSString* +MOZ_ALWAYS_INLINE JSString* ToString(JSContext *cx, HandleValue v) { if (v.isString()) @@ -1133,32 +1108,31 @@ JS_DoubleToUint32(double d); namespace js { /* DO NOT CALL THIS. Use JS::ToUint16. */ extern JS_PUBLIC_API(bool) -ToUint16Slow(JSContext *cx, JS::Handle v, uint16_t *out); +ToUint16Slow(JSContext *cx, JS::HandleValue v, uint16_t *out); /* DO NOT CALL THIS. Use JS::ToInt32. */ extern JS_PUBLIC_API(bool) -ToInt32Slow(JSContext *cx, JS::Handle v, int32_t *out); +ToInt32Slow(JSContext *cx, JS::HandleValue v, int32_t *out); /* DO NOT CALL THIS. Use JS::ToUint32. */ extern JS_PUBLIC_API(bool) -ToUint32Slow(JSContext *cx, JS::Handle v, uint32_t *out); +ToUint32Slow(JSContext *cx, JS::HandleValue v, uint32_t *out); /* DO NOT CALL THIS. Use JS::ToInt64. */ extern JS_PUBLIC_API(bool) -ToInt64Slow(JSContext *cx, JS::Handle v, int64_t *out); +ToInt64Slow(JSContext *cx, JS::HandleValue v, int64_t *out); /* DO NOT CALL THIS. Use JS::ToUint64. */ extern JS_PUBLIC_API(bool) -ToUint64Slow(JSContext *cx, JS::Handle v, uint64_t *out); +ToUint64Slow(JSContext *cx, JS::HandleValue v, uint64_t *out); } /* namespace js */ namespace JS { -JS_ALWAYS_INLINE bool -ToUint16(JSContext *cx, JS::Handle v, uint16_t *out) +MOZ_ALWAYS_INLINE bool +ToUint16(JSContext *cx, JS::HandleValue v, uint16_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = uint16_t(v.toInt32()); @@ -1167,11 +1141,10 @@ ToUint16(JSContext *cx, JS::Handle v, uint16_t *out) return js::ToUint16Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToInt32(JSContext *cx, JS::Handle v, int32_t *out) +MOZ_ALWAYS_INLINE bool +ToInt32(JSContext *cx, JS::HandleValue v, int32_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = v.toInt32(); @@ -1180,11 +1153,10 @@ ToInt32(JSContext *cx, JS::Handle v, int32_t *out) return js::ToInt32Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToUint32(JSContext *cx, JS::Handle v, uint32_t *out) +MOZ_ALWAYS_INLINE bool +ToUint32(JSContext *cx, JS::HandleValue v, uint32_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = uint32_t(v.toInt32()); @@ -1193,32 +1165,28 @@ ToUint32(JSContext *cx, JS::Handle v, uint32_t *out) return js::ToUint32Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToInt64(JSContext *cx, JS::Handle v, int64_t *out) +MOZ_ALWAYS_INLINE bool +ToInt64(JSContext *cx, JS::HandleValue v, int64_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = int64_t(v.toInt32()); return true; } - return js::ToInt64Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToUint64(JSContext *cx, JS::Handle v, uint64_t *out) +MOZ_ALWAYS_INLINE bool +ToUint64(JSContext *cx, JS::HandleValue v, uint64_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { /* Account for sign extension of negatives into the longer 64bit space. */ *out = uint64_t(int64_t(v.toInt32())); return true; } - return js::ToUint64Slow(cx, v, out); } @@ -1226,7 +1194,7 @@ ToUint64(JSContext *cx, JS::Handle v, uint64_t *out) } /* namespace JS */ extern JS_PUBLIC_API(JSType) -JS_TypeOfValue(JSContext *cx, jsval v); +JS_TypeOfValue(JSContext *cx, JS::Handle v); extern JS_PUBLIC_API(const char *) JS_GetTypeName(JSContext *cx, JSType type); @@ -1235,7 +1203,7 @@ extern JS_PUBLIC_API(bool) JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal); extern JS_PUBLIC_API(bool) -JS_LooselyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal); +JS_LooselyEqual(JSContext *cx, JS::Handle v1, JS::Handle v2, bool *equal); extern JS_PUBLIC_API(bool) JS_SameValue(JSContext *cx, jsval v1, jsval v2, bool *same); @@ -1258,12 +1226,6 @@ JS_IsBuiltinFunctionConstructor(JSFunction *fun); * See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference */ -typedef enum JSUseHelperThreads -{ - JS_NO_HELPER_THREADS, - JS_USE_HELPER_THREADS -} JSUseHelperThreads; - /** * Initialize SpiderMonkey, returning true only if initialization succeeded. * Once this method has succeeded, it is safe to call JS_NewRuntime and other @@ -1301,7 +1263,9 @@ extern JS_PUBLIC_API(void) JS_ShutDown(void); extern JS_PUBLIC_API(JSRuntime *) -JS_NewRuntime(uint32_t maxbytes, JSUseHelperThreads useHelperThreads); +JS_NewRuntime(uint32_t maxbytes, + uint32_t maxNurseryBytes = JS::DefaultNurseryBytes, + JSRuntime *parentRuntime = nullptr); extern JS_PUBLIC_API(void) JS_DestroyRuntime(JSRuntime *rt); @@ -1324,6 +1288,9 @@ JS_GetRuntimePrivate(JSRuntime *rt); extern JS_PUBLIC_API(JSRuntime *) JS_GetRuntime(JSContext *cx); +extern JS_PUBLIC_API(JSRuntime *) +JS_GetParentRuntime(JSContext *cx); + JS_PUBLIC_API(void) JS_SetRuntimePrivate(JSRuntime *rt, void *data); @@ -1349,8 +1316,8 @@ AssertHeapIsIdle(JSContext *cx); class JSAutoRequest { public: - JSAutoRequest(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit JSAutoRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : mContext(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -1374,10 +1341,10 @@ class JSAutoRequest class JSAutoCheckRequest { public: - JSAutoCheckRequest(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit JSAutoCheckRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) { -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG mContext = cx; JS_ASSERT(JS_IsInRequest(JS_GetRuntime(cx))); #endif @@ -1385,14 +1352,14 @@ class JSAutoCheckRequest } ~JSAutoCheckRequest() { -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG JS_ASSERT(JS_IsInRequest(JS_GetRuntime(mContext))); #endif } private: -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG JSContext *mContext; #endif MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER @@ -1448,54 +1415,122 @@ JS_StringToVersion(const char *string); namespace JS { -class JS_PUBLIC_API(ContextOptions) { +class JS_PUBLIC_API(RuntimeOptions) { public: - ContextOptions() - : extraWarnings_(false), + RuntimeOptions() + : baseline_(false), + ion_(false), + asmJS_(false), + nativeRegExp_(false), werror_(false), - varObjFix_(false), - privateIsNSISupports_(false), - dontReportUncaught_(false), - noDefaultCompartmentObject_(false), - noScriptRval_(false), strictMode_(false), - baseline_(false), - typeInference_(false), - ion_(false), - asmJS_(false) + varObjFix_(false) { } - bool extraWarnings() const { return extraWarnings_; } - ContextOptions &setExtraWarnings(bool flag) { - extraWarnings_ = flag; + bool baseline() const { return baseline_; } + RuntimeOptions &setBaseline(bool flag) { + baseline_ = flag; return *this; } - ContextOptions &toggleExtraWarnings() { - extraWarnings_ = !extraWarnings_; + RuntimeOptions &toggleBaseline() { + baseline_ = !baseline_; + return *this; + } + + bool ion() const { return ion_; } + RuntimeOptions &setIon(bool flag) { + ion_ = flag; + return *this; + } + RuntimeOptions &toggleIon() { + ion_ = !ion_; + return *this; + } + + bool asmJS() const { return asmJS_; } + RuntimeOptions &setAsmJS(bool flag) { + asmJS_ = flag; + return *this; + } + RuntimeOptions &toggleAsmJS() { + asmJS_ = !asmJS_; + return *this; + } + + bool nativeRegExp() const { return nativeRegExp_; } + RuntimeOptions &setNativeRegExp(bool flag) { + nativeRegExp_ = flag; return *this; } bool werror() const { return werror_; } - ContextOptions &setWerror(bool flag) { + RuntimeOptions &setWerror(bool flag) { werror_ = flag; return *this; } - ContextOptions &toggleWerror() { + RuntimeOptions &toggleWerror() { werror_ = !werror_; return *this; } + bool strictMode() const { return strictMode_; } + RuntimeOptions &setStrictMode(bool flag) { + strictMode_ = flag; + return *this; + } + RuntimeOptions &toggleStrictMode() { + strictMode_ = !strictMode_; + return *this; + } + bool varObjFix() const { return varObjFix_; } - ContextOptions &setVarObjFix(bool flag) { + RuntimeOptions &setVarObjFix(bool flag) { varObjFix_ = flag; return *this; } - ContextOptions &toggleVarObjFix() { + RuntimeOptions &toggleVarObjFix() { varObjFix_ = !varObjFix_; return *this; } + private: + bool baseline_ : 1; + bool ion_ : 1; + bool asmJS_ : 1; + bool nativeRegExp_ : 1; + bool werror_ : 1; + bool strictMode_ : 1; + bool varObjFix_ : 1; +}; + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSRuntime *rt); + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSContext *cx); + +class JS_PUBLIC_API(ContextOptions) { + public: + ContextOptions() + : extraWarnings_(false), + privateIsNSISupports_(false), + dontReportUncaught_(false), + noDefaultCompartmentObject_(false), + noScriptRval_(false) + { + } + + bool extraWarnings() const { return extraWarnings_; } + ContextOptions &setExtraWarnings(bool flag) { + extraWarnings_ = flag; + return *this; + } + ContextOptions &toggleExtraWarnings() { + extraWarnings_ = !extraWarnings_; + return *this; + } + bool privateIsNSISupports() const { return privateIsNSISupports_; } ContextOptions &setPrivateIsNSISupports(bool flag) { privateIsNSISupports_ = flag; @@ -1536,69 +1571,12 @@ class JS_PUBLIC_API(ContextOptions) { return *this; } - bool strictMode() const { return strictMode_; } - ContextOptions &setStrictMode(bool flag) { - strictMode_ = flag; - return *this; - } - ContextOptions &toggleStrictMode() { - strictMode_ = !strictMode_; - return *this; - } - - bool baseline() const { return baseline_; } - ContextOptions &setBaseline(bool flag) { - baseline_ = flag; - return *this; - } - ContextOptions &toggleBaseline() { - baseline_ = !baseline_; - return *this; - } - - bool typeInference() const { return typeInference_; } - ContextOptions &setTypeInference(bool flag) { - typeInference_ = flag; - return *this; - } - ContextOptions &toggleTypeInference() { - typeInference_ = !typeInference_; - return *this; - } - - bool ion() const { return ion_; } - ContextOptions &setIon(bool flag) { - ion_ = flag; - return *this; - } - ContextOptions &toggleIon() { - ion_ = !ion_; - return *this; - } - - bool asmJS() const { return asmJS_; } - ContextOptions &setAsmJS(bool flag) { - asmJS_ = flag; - return *this; - } - ContextOptions &toggleAsmJS() { - asmJS_ = !asmJS_; - return *this; - } - private: bool extraWarnings_ : 1; - bool werror_ : 1; - bool varObjFix_ : 1; bool privateIsNSISupports_ : 1; bool dontReportUncaught_ : 1; bool noDefaultCompartmentObject_ : 1; bool noScriptRval_ : 1; - bool strictMode_ : 1; - bool baseline_ : 1; - bool typeInference_ : 1; - bool ion_ : 1; - bool asmJS_ : 1; }; JS_PUBLIC_API(ContextOptions &) @@ -1606,7 +1584,7 @@ ContextOptionsRef(JSContext *cx); class JS_PUBLIC_API(AutoSaveContextOptions) { public: - AutoSaveContextOptions(JSContext *cx) + explicit AutoSaveContextOptions(JSContext *cx) : cx_(cx), oldOptions_(ContextOptionsRef(cx_)) { @@ -1624,9 +1602,6 @@ class JS_PUBLIC_API(AutoSaveContextOptions) { } /* namespace JS */ -extern JS_PUBLIC_API(void) -JS_SetJitHardening(JSRuntime *rt, bool enabled); - extern JS_PUBLIC_API(const char *) JS_GetImplementationVersion(void); @@ -1663,14 +1638,11 @@ JS_WrapObject(JSContext *cx, JS::MutableHandleObject objp); extern JS_PUBLIC_API(bool) JS_WrapValue(JSContext *cx, JS::MutableHandleValue vp); -extern JS_PUBLIC_API(bool) -JS_WrapId(JSContext *cx, jsid *idp); - extern JS_PUBLIC_API(JSObject *) -JS_TransplantObject(JSContext *cx, JS::Handle origobj, JS::Handle target); +JS_TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target); extern JS_PUBLIC_API(bool) -JS_RefreshCrossCompartmentWrappers(JSContext *cx, JSObject *ob); +JS_RefreshCrossCompartmentWrappers(JSContext *cx, JS::Handle obj); /* * At any time, a JSContext has a current (possibly-nullptr) compartment. @@ -1717,6 +1689,15 @@ class JS_PUBLIC_API(JSAutoCompartment) ~JSAutoCompartment(); }; +class JS_PUBLIC_API(JSAutoNullableCompartment) +{ + JSContext *cx_; + JSCompartment *oldCompartment_; + public: + explicit JSAutoNullableCompartment(JSContext *cx, JSObject *targetOrNull); + ~JSAutoNullableCompartment(); +}; + /* NB: This API is infallible; a nullptr return value does not indicate error. */ extern JS_PUBLIC_API(JSCompartment *) JS_EnterCompartment(JSContext *cx, JSObject *target); @@ -1743,7 +1724,7 @@ JS_IterateCompartments(JSRuntime *rt, void *data, * NB: This sets cx's global object to obj if it was null. */ extern JS_PUBLIC_API(bool) -JS_InitStandardClasses(JSContext *cx, JSObject *obj); +JS_InitStandardClasses(JSContext *cx, JS::Handle obj); /* * Resolve id, which must contain either a string or an int, to a standard @@ -1759,20 +1740,40 @@ JS_InitStandardClasses(JSContext *cx, JSObject *obj); * loops any classes not yet resolved lazily. */ extern JS_PUBLIC_API(bool) -JS_ResolveStandardClass(JSContext *cx, JS::Handle obj, JS::Handle id, - bool *resolved); +JS_ResolveStandardClass(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *resolved); extern JS_PUBLIC_API(bool) -JS_EnumerateStandardClasses(JSContext *cx, JS::Handle obj); +JS_EnumerateStandardClasses(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, JSObject **objp); +JS_GetClassObject(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); extern JS_PUBLIC_API(bool) -JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JSObject **objp); +JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); + +namespace JS { + +/* + * Determine if the given object is an instance/prototype/constructor for a standard + * class. If so, return the associated JSProtoKey. If not, return JSProto_Null. + */ + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstance(JSObject *obj); extern JS_PUBLIC_API(JSProtoKey) -JS_IdentifyClassPrototype(JSContext *cx, JSObject *obj); +IdentifyStandardPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstanceOrPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardConstructor(JSObject *obj); + +extern JS_PUBLIC_API(void) +ProtoKeyToId(JSContext *cx, JSProtoKey key, JS::MutableHandleId idp); + +} /* namespace JS */ extern JS_PUBLIC_API(JSProtoKey) JS_IdToProtoKey(JSContext *cx, JS::HandleId id); @@ -1782,21 +1783,28 @@ JS_IdToProtoKey(JSContext *cx, JS::HandleId id); * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetFunctionPrototype(JSContext *cx, JSObject *forObj); +JS_GetFunctionPrototype(JSContext *cx, JS::HandleObject forObj); /* * Returns the original value of |Object.prototype| from the global object in * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetObjectPrototype(JSContext *cx, JSObject *forObj); +JS_GetObjectPrototype(JSContext *cx, JS::HandleObject forObj); /* * Returns the original value of |Array.prototype| from the global object in * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetArrayPrototype(JSContext *cx, JSObject *forObj); +JS_GetArrayPrototype(JSContext *cx, JS::HandleObject forObj); + +/* + * Returns the original value of |Error.prototype| from the global + * object of the current compartment of cx. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetErrorPrototype(JSContext *cx); extern JS_PUBLIC_API(JSObject *) JS_GetGlobalForObject(JSContext *cx, JSObject *obj); @@ -1818,23 +1826,11 @@ CurrentGlobalOrNull(JSContext *cx); } -/* - * This method returns the global corresponding to the most recent scripted - * frame, which may not match the cx's current compartment. This is extremely - * dangerous, because it can bypass compartment security invariants in subtle - * ways. To use it safely, the caller must perform a subsequent security - * check. There is currently only one consumer of this function in Gecko, and - * it should probably stay that way. If you'd like to use it, please consult - * the XPConnect module owner first. - */ -extern JS_PUBLIC_API(JSObject *) -JS_GetScriptedGlobal(JSContext *cx); - /* * Initialize the 'Reflect' object on a global object. */ extern JS_PUBLIC_API(JSObject *) -JS_InitReflect(JSContext *cx, JSObject *global); +JS_InitReflect(JSContext *cx, JS::HandleObject global); #ifdef JS_HAS_CTYPES /* @@ -1842,7 +1838,7 @@ JS_InitReflect(JSContext *cx, JSObject *global); * object will be sealed. */ extern JS_PUBLIC_API(bool) -JS_InitCTypesClass(JSContext *cx, JSObject *global); +JS_InitCTypesClass(JSContext *cx, JS::HandleObject global); /* * Convert a unicode string 'source' of length 'slen' to the platform native @@ -1917,6 +1913,7 @@ JS_strdup(JSContext *cx, const char *s); extern JS_PUBLIC_API(char *) JS_strdup(JSRuntime *rt, const char *s); +namespace JS { /* * A GC root is a pointer to a jsval, JSObject * or JSString * that itself @@ -1944,52 +1941,54 @@ JS_strdup(JSRuntime *rt, const char *s); * before freeing structPtr's memory. */ extern JS_PUBLIC_API(bool) -JS_AddValueRoot(JSContext *cx, jsval *vp); +AddValueRoot(JSContext *cx, JS::Heap *vp); extern JS_PUBLIC_API(bool) -JS_AddStringRoot(JSContext *cx, JSString **rp); +AddStringRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(bool) -JS_AddObjectRoot(JSContext *cx, JSObject **rp); +AddObjectRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(bool) -JS_AddNamedValueRoot(JSContext *cx, jsval *vp, const char *name); +AddNamedValueRoot(JSContext *cx, JS::Heap *vp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedValueRootRT(JSRuntime *rt, jsval *vp, const char *name); +AddNamedValueRootRT(JSRuntime *rt, JS::Heap *vp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedStringRoot(JSContext *cx, JSString **rp, const char *name); +AddNamedStringRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedObjectRoot(JSContext *cx, JSObject **rp, const char *name); +AddNamedObjectRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedScriptRoot(JSContext *cx, JSScript **rp, const char *name); +AddNamedScriptRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(void) -JS_RemoveValueRoot(JSContext *cx, jsval *vp); +RemoveValueRoot(JSContext *cx, JS::Heap *vp); extern JS_PUBLIC_API(void) -JS_RemoveStringRoot(JSContext *cx, JSString **rp); +RemoveStringRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveObjectRoot(JSContext *cx, JSObject **rp); +RemoveObjectRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveScriptRoot(JSContext *cx, JSScript **rp); +RemoveScriptRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveValueRootRT(JSRuntime *rt, jsval *vp); +RemoveValueRootRT(JSRuntime *rt, JS::Heap *vp); extern JS_PUBLIC_API(void) -JS_RemoveStringRootRT(JSRuntime *rt, JSString **rp); +RemoveStringRootRT(JSRuntime *rt, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveObjectRootRT(JSRuntime *rt, JSObject **rp); +RemoveObjectRootRT(JSRuntime *rt, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveScriptRootRT(JSRuntime *rt, JSScript **rp); +RemoveScriptRootRT(JSRuntime *rt, JS::Heap *rp); + +} /* namespace JS */ /* * Register externally maintained GC roots. @@ -2005,42 +2004,10 @@ JS_AddExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); extern JS_PUBLIC_API(void) JS_RemoveExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); -/* - * JS_CallTracer API and related macros for implementors of JSTraceOp, to - * enumerate all references to traceable things reachable via a property or - * other strong ref identified for debugging purposes by name or index or - * a naming callback. - * - * See the JSTraceOp typedef. - */ +#ifdef JS_DEBUG /* - * Use the following macros to check if a particular jsval is a traceable - * thing and to extract the thing and its kind to pass to JS_CallTracer. - */ -static JS_ALWAYS_INLINE bool -JSVAL_IS_TRACEABLE(jsval v) -{ - return JSVAL_IS_TRACEABLE_IMPL(JSVAL_TO_IMPL(v)); -} - -static JS_ALWAYS_INLINE void * -JSVAL_TO_TRACEABLE(jsval v) -{ - return JSVAL_TO_GCTHING(v); -} - -static JS_ALWAYS_INLINE JSGCTraceKind -JSVAL_TRACE_KIND(jsval v) -{ - JS_ASSERT(JSVAL_IS_GCTHING(v)); - return (JSGCTraceKind) JSVAL_TRACE_KIND_IMPL(JSVAL_TO_IMPL(v)); -} - -#ifdef DEBUG - -/* - * DEBUG-only method to dump the object graph of heap-allocated things. + * Debug-only method to dump the object graph of heap-allocated things. * * fp: file for the dump output. * start: when non-null, dump only things reachable from start @@ -2072,14 +2039,17 @@ JS_MaybeGC(JSContext *cx); extern JS_PUBLIC_API(void) JS_SetGCCallback(JSRuntime *rt, JSGCCallback cb, void *data); +extern JS_PUBLIC_API(bool) +JS_AddFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb, void *data); + extern JS_PUBLIC_API(void) -JS_SetFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); +JS_RemoveFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); extern JS_PUBLIC_API(bool) JS_IsGCMarkingTracer(JSTracer *trc); /* For assertions only. */ -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_PUBLIC_API(bool) JS_IsMarkingGray(JSTracer *trc); #endif @@ -2175,22 +2145,17 @@ typedef enum JSGCParamKey { * available to be decommitted, then JS_MaybeGC will trigger a shrinking GC * to decommit it. */ - JSGC_DECOMMIT_THRESHOLD = 20 -} JSGCParamKey; - -typedef enum JSGCMode { - /* Perform only global GCs. */ - JSGC_MODE_GLOBAL = 0, - - /* Perform per-compartment GCs until too much garbage has accumulated. */ - JSGC_MODE_COMPARTMENT = 1, + JSGC_DECOMMIT_THRESHOLD = 20, /* - * Collect in short time slices rather than all at once. Implies - * JSGC_MODE_COMPARTMENT. + * We try to keep at least this many unused chunks in the free chunk pool at + * all times, even after a shrinking GC. */ - JSGC_MODE_INCREMENTAL = 2 -} JSGCMode; + JSGC_MIN_EMPTY_CHUNK_COUNT = 21, + + /* We never keep more than this many unused chunks in the free chunk pool. */ + JSGC_MAX_EMPTY_CHUNK_COUNT = 22 +} JSGCParamKey; extern JS_PUBLIC_API(void) JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32_t value); @@ -2204,6 +2169,9 @@ JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32_t value); extern JS_PUBLIC_API(uint32_t) JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key); +extern JS_PUBLIC_API(void) +JS_SetGCParametersBasedOnAvailableMemory(JSRuntime *rt, uint32_t availMem); + /* * Create a new JSString whose chars member refers to external memory, i.e., * memory requiring application-specific finalization. @@ -2252,7 +2220,7 @@ extern JS_PUBLIC_API(int) JS_IdArrayLength(JSContext *cx, JSIdArray *ida); extern JS_PUBLIC_API(jsid) -JS_IdArrayGet(JSContext *cx, JSIdArray *ida, int index); +JS_IdArrayGet(JSContext *cx, JSIdArray *ida, unsigned index); extern JS_PUBLIC_API(void) JS_DestroyIdArray(JSContext *cx, JSIdArray *ida); @@ -2272,13 +2240,12 @@ class AutoIdArray : private AutoGCRooter if (idArray) JS_DestroyIdArray(context, idArray); } - bool operator!() { + bool operator!() const { return !idArray; } jsid operator[](size_t i) const { JS_ASSERT(idArray); - JS_ASSERT(i < length()); - return JS_IdArrayGet(context, idArray, i); + return JS_IdArrayGet(context, idArray, unsigned(i)); } size_t length() const { return JS_IdArrayLength(context, idArray); @@ -2308,15 +2275,13 @@ class AutoIdArray : private AutoGCRooter } /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_ValueToId(JSContext *cx, jsval v, jsid *idp); +JS_ValueToId(JSContext *cx, JS::HandleValue v, JS::MutableHandleId idp); extern JS_PUBLIC_API(bool) -JS_IdToValue(JSContext *cx, jsid id, jsval *vp); +JS_StringToId(JSContext *cx, JS::HandleString s, JS::MutableHandleId idp); -/* - * JSNewResolveOp flag bits. - */ -#define JSRESOLVE_ASSIGNING 0x01 /* resolve on the left of assignment */ +extern JS_PUBLIC_API(bool) +JS_IdToValue(JSContext *cx, jsid id, JS::MutableHandle vp); /* * Invoke the [[DefaultValue]] hook (see ES5 8.6.2) with the provided hint on @@ -2325,29 +2290,30 @@ JS_IdToValue(JSContext *cx, jsid id, jsval *vp); * success the resulting value is stored in *vp. */ extern JS_PUBLIC_API(bool) -JS_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp); +JS_DefaultValue(JSContext *cx, JS::Handle obj, JSType hint, + JS::MutableHandle vp); extern JS_PUBLIC_API(bool) -JS_PropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, - JS::MutableHandle vp); +JS_PropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_StrictPropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, bool strict, - JS::MutableHandle vp); +JS_StrictPropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_DeletePropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, +JS_DeletePropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_EnumerateStub(JSContext *cx, JS::Handle obj); +JS_EnumerateStub(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_ResolveStub(JSContext *cx, JS::Handle obj, JS::Handle id); +JS_ResolveStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id); extern JS_PUBLIC_API(bool) -JS_ConvertStub(JSContext *cx, JS::Handle obj, JSType type, - JS::MutableHandle vp); +JS_ConvertStub(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); struct JSConstDoubleSpec { double dval; @@ -2385,7 +2351,7 @@ typedef struct JSNativeWrapper { * Macro static initializers which make it easy to pass no JSJitInfo as part of a * JSPropertySpec or JSFunctionSpec. */ -#define JSOP_WRAPPER(op) {op, nullptr} +#define JSOP_WRAPPER(op) { {op, nullptr} } #define JSOP_NULLWRAPPER JSOP_WRAPPER(nullptr) /* @@ -2394,13 +2360,29 @@ typedef struct JSNativeWrapper { * JSPROP_INDEX bit in flags. */ struct JSPropertySpec { + struct SelfHostedWrapper { + void *unused; + const char *funname; + }; + const char *name; - int8_t tinyid; uint8_t flags; - JSPropertyOpWrapper getter; - JSStrictPropertyOpWrapper setter; - const char *selfHostedGetter; - const char *selfHostedSetter; + union { + JSPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } getter; + union { + JSStrictPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } setter; + +private: + void StaticAsserts() { + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSPropertyOpWrapper)); + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSStrictPropertyOpWrapper)); + JS_STATIC_ASSERT(offsetof(SelfHostedWrapper, funname) == + offsetof(JSPropertyOpWrapper, info)); + } }; namespace JS { @@ -2409,6 +2391,11 @@ namespace detail { /* NEVER DEFINED, DON'T USE. For use by JS_CAST_NATIVE_TO only. */ inline int CheckIsNative(JSNative native); +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_STRING_TO only. */ +template +inline int +CheckIsCharacterLiteral(const char (&arr)[N]); + } // namespace detail } // namespace JS @@ -2416,6 +2403,10 @@ inline int CheckIsNative(JSNative native); (static_cast(sizeof(JS::detail::CheckIsNative(v))), \ reinterpret_cast(v)) +#define JS_CAST_STRING_TO(s, To) \ + (static_cast(sizeof(JS::detail::CheckIsCharacterLiteral(s))), \ + reinterpret_cast(s)) + #define JS_CHECK_ACCESSOR_FLAGS(flags) \ (static_cast::Type>(0), \ (flags)) @@ -2428,26 +2419,26 @@ inline int CheckIsNative(JSNative native); * JSNatives. */ #define JS_PSG(name, getter, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ - JSOP_NULLWRAPPER, nullptr, nullptr} + JSOP_NULLWRAPPER} #define JS_PSGS(name, getter, setter, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ - JSOP_WRAPPER(JS_CAST_NATIVE_TO(setter, JSStrictPropertyOp)), \ - nullptr, nullptr} + JSOP_WRAPPER(JS_CAST_NATIVE_TO(setter, JSStrictPropertyOp))} #define JS_SELF_HOSTED_GET(name, getterName, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER), \ - JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, getterName, nullptr} + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + JSOP_NULLWRAPPER } #define JS_SELF_HOSTED_GETSET(name, getterName, setterName, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER | JSPROP_SETTER), \ - JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, getterName, setterName} -#define JS_PS_END {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, \ - nullptr, nullptr} + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + { nullptr, JS_CAST_STRING_TO(setterName, const JSJitInfo *) } } +#define JS_PS_END { nullptr, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER } /* * To define a native function, set call to a JSNativeWrapper. To define a @@ -2487,7 +2478,7 @@ struct JSFunctionSpec { {name, {call, info}, nargs, flags, selfHostedName} extern JS_PUBLIC_API(JSObject *) -JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, +JS_InitClass(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent_proto, const JSClass *clasp, JSNative constructor, unsigned nargs, const JSPropertySpec *ps, const JSFunctionSpec *fs, const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs); @@ -2497,16 +2488,17 @@ JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, * right property flags. */ extern JS_PUBLIC_API(bool) -JS_LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor, JSObject *proto); +JS_LinkConstructorAndPrototype(JSContext *cx, JS::Handle ctor, + JS::Handle proto); extern JS_PUBLIC_API(const JSClass *) JS_GetClass(JSObject *obj); extern JS_PUBLIC_API(bool) -JS_InstanceOf(JSContext *cx, JSObject *obj, const JSClass *clasp, jsval *argv); +JS_InstanceOf(JSContext *cx, JS::Handle obj, const JSClass *clasp, JS::CallArgs *args); extern JS_PUBLIC_API(bool) -JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, bool *bp); +JS_HasInstance(JSContext *cx, JS::Handle obj, JS::Handle v, bool *bp); extern JS_PUBLIC_API(void *) JS_GetPrivate(JSObject *obj); @@ -2515,31 +2507,23 @@ extern JS_PUBLIC_API(void) JS_SetPrivate(JSObject *obj, void *data); extern JS_PUBLIC_API(void *) -JS_GetInstancePrivate(JSContext *cx, JSObject *obj, const JSClass *clasp, - jsval *argv); +JS_GetInstancePrivate(JSContext *cx, JS::Handle obj, const JSClass *clasp, + JS::CallArgs *args); extern JS_PUBLIC_API(bool) -JS_GetPrototype(JSContext *cx, JS::Handle obj, JS::MutableHandle protop); +JS_GetPrototype(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject protop); extern JS_PUBLIC_API(bool) -JS_SetPrototype(JSContext *cx, JS::Handle obj, JS::Handle proto); +JS_SetPrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); extern JS_PUBLIC_API(JSObject *) JS_GetParent(JSObject *obj); extern JS_PUBLIC_API(bool) -JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent); +JS_SetParent(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent); extern JS_PUBLIC_API(JSObject *) -JS_GetConstructor(JSContext *cx, JSObject *proto); - -/* - * Get a unique identifier for obj, good for the lifetime of obj (even if it - * is moved by a copying GC). Return false on failure (likely out of memory), - * and true with *idp containing the unique id on success. - */ -extern JS_PUBLIC_API(bool) -JS_GetObjectId(JSContext *cx, JSObject *obj, jsid *idp); +JS_GetConstructor(JSContext *cx, JS::Handle proto); namespace JS { @@ -2582,6 +2566,12 @@ class JS_PUBLIC_API(CompartmentOptions) explicit CompartmentOptions() : version_(JSVERSION_UNKNOWN) , invisibleToDebugger_(false) + , mergeable_(false) + , discardSource_(false) + , cloneSingletons_(false) + , traceGlobal_(nullptr) + , singletonsAsTemplates_(true) + , addonId_(nullptr) { zone_.spec = JS::FreshZone; } @@ -2597,23 +2587,36 @@ class JS_PUBLIC_API(CompartmentOptions) // of the embedding, and references to them should never leak out to script. // This flag causes the this compartment to skip firing onNewGlobalObject // and makes addDebuggee a no-op for this global. - bool invisibleToDebugger() { return invisibleToDebugger_; } + bool invisibleToDebugger() const { return invisibleToDebugger_; } CompartmentOptions &setInvisibleToDebugger(bool flag) { invisibleToDebugger_ = flag; return *this; } - bool baseline(JSContext *cx) const; - Override &baselineOverride() { return baselineOverride_; } + // Compartments used for off-thread compilation have their contents merged + // into a target compartment when the compilation is finished. This is only + // allowed if this flag is set. The invisibleToDebugger flag must also be + // set for such compartments. + bool mergeable() const { return mergeable_; } + CompartmentOptions &setMergeable(bool flag) { + mergeable_ = flag; + return *this; + } - bool typeInference(const js::ExclusiveContext *cx) const; - Override &typeInferenceOverride() { return typeInferenceOverride_; } + // For certain globals, we know enough about the code that will run in them + // that we can discard script source entirely. + bool discardSource() const { return discardSource_; } + CompartmentOptions &setDiscardSource(bool flag) { + discardSource_ = flag; + return *this; + } - bool ion(JSContext *cx) const; - Override &ionOverride() { return ionOverride_; } - bool asmJS(JSContext *cx) const; - Override &asmJSOverride() { return asmJSOverride_; } + bool cloneSingletons() const { return cloneSingletons_; } + CompartmentOptions &setCloneSingletons(bool flag) { + cloneSingletons_ = flag; + return *this; + } void *zonePointer() const { JS_ASSERT(uintptr_t(zone_.pointer) > uintptr_t(JS::SystemZone)); @@ -2623,22 +2626,55 @@ class JS_PUBLIC_API(CompartmentOptions) CompartmentOptions &setZone(ZoneSpecifier spec); CompartmentOptions &setSameZoneAs(JSObject *obj); + void setSingletonsAsValues() { + singletonsAsTemplates_ = false; + } + bool getSingletonsAsTemplates() const { + return singletonsAsTemplates_; + }; + + // A null add-on ID means that the compartment is not associated with an + // add-on. + JSAddonId *addonIdOrNull() const { return addonId_; } + CompartmentOptions &setAddonId(JSAddonId *id) { + addonId_ = id; + return *this; + } + + CompartmentOptions &setTrace(JSTraceOp op) { + traceGlobal_ = op; + return *this; + } + JSTraceOp getTrace() const { + return traceGlobal_; + } + private: JSVersion version_; bool invisibleToDebugger_; - Override baselineOverride_; - Override typeInferenceOverride_; - Override ionOverride_; - Override asmJSOverride_; + bool mergeable_; + bool discardSource_; + bool cloneSingletons_; union { ZoneSpecifier spec; void *pointer; // js::Zone* is not exposed in the API. } zone_; + JSTraceOp traceGlobal_; + + // To XDR singletons, we need to ensure that all singletons are all used as + // templates, by making JSOP_OBJECT return a clone of the JSScript + // singleton, instead of returning the value which is baked in the JSScript. + bool singletonsAsTemplates_; + + JSAddonId *addonId_; }; JS_PUBLIC_API(CompartmentOptions &) CompartmentOptionsRef(JSCompartment *compartment); +JS_PUBLIC_API(CompartmentOptions &) +CompartmentOptionsRef(JSObject *obj); + JS_PUBLIC_API(CompartmentOptions &) CompartmentOptionsRef(JSContext *cx); @@ -2673,16 +2709,28 @@ extern JS_PUBLIC_API(JSObject *) JS_NewGlobalObject(JSContext *cx, const JSClass *clasp, JSPrincipals *principals, JS::OnNewGlobalHookOption hookOption, const JS::CompartmentOptions &options = JS::CompartmentOptions()); +/* + * Spidermonkey does not have a good way of keeping track of what compartments should be marked on + * their own. We can mark the roots unconditionally, but marking GC things only relevant in live + * compartments is hard. To mitigate this, we create a static trace hook, installed on each global + * object, from which we can be sure the compartment is relevant, and mark it. + * + * It is still possible to specify custom trace hooks for global object classes. They can be + * provided via the CompartmentOptions passed to JS_NewGlobalObject. + */ +extern JS_PUBLIC_API(void) +JS_GlobalObjectTraceHook(JSTracer *trc, JSObject *global); extern JS_PUBLIC_API(void) JS_FireOnNewGlobalObject(JSContext *cx, JS::HandleObject global); extern JS_PUBLIC_API(JSObject *) -JS_NewObject(JSContext *cx, const JSClass *clasp, JSObject *proto, JSObject *parent); +JS_NewObject(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); /* Queries the [[Extensible]] property of the object. */ extern JS_PUBLIC_API(bool) -JS_IsExtensible(JSContext *cx, JS::Handle obj, bool *extensible); +JS_IsExtensible(JSContext *cx, JS::HandleObject obj, bool *extensible); extern JS_PUBLIC_API(bool) JS_IsNative(JSObject *obj); @@ -2695,8 +2743,8 @@ JS_GetObjectRuntime(JSObject *obj); * proto if proto's actual parameter value is null. */ extern JS_PUBLIC_API(JSObject *) -JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JSObject *proto, - JSObject *parent); +JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); /* * Freeze obj, and all objects it refers to, recursively. This will not recurse @@ -2704,88 +2752,126 @@ JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JSObject *proto, * deep-frozen. */ extern JS_PUBLIC_API(bool) -JS_DeepFreezeObject(JSContext *cx, JSObject *obj); +JS_DeepFreezeObject(JSContext *cx, JS::Handle obj); /* * Freezes an object; see ES5's Object.freeze(obj) method. */ extern JS_PUBLIC_API(bool) -JS_FreezeObject(JSContext *cx, JSObject *obj); +JS_FreezeObject(JSContext *cx, JS::Handle obj); extern JS_PUBLIC_API(bool) -JS_PreventExtensions(JSContext *cx, JS::Handle obj); +JS_PreventExtensions(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(JSObject *) -JS_New(JSContext *cx, JSObject *ctor, unsigned argc, jsval *argv); +JS_New(JSContext *cx, JS::HandleObject ctor, const JS::HandleValueArray& args); extern JS_PUBLIC_API(JSObject *) -JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, const JSClass *clasp, - JSObject *proto, unsigned attrs); +JS_DefineObject(JSContext *cx, JS::HandleObject obj, const char *name, + const JSClass *clasp = nullptr, JS::HandleObject proto = JS::NullPtr(), + unsigned attrs = 0); extern JS_PUBLIC_API(bool) -JS_DefineConstDoubles(JSContext *cx, JSObject *obj, const JSConstDoubleSpec *cds); +JS_DefineConstDoubles(JSContext *cx, JS::HandleObject obj, const JSConstDoubleSpec *cds); extern JS_PUBLIC_API(bool) -JS_DefineProperties(JSContext *cx, JSObject *obj, const JSPropertySpec *ps); +JS_DefineProperties(JSContext *cx, JS::HandleObject obj, const JSPropertySpec *ps); extern JS_PUBLIC_API(bool) -JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id, jsval descriptor, bool *bp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name, - int8_t tinyid, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name, - bool *foundp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnPropertyById(JSContext *cx, JSObject *obj, jsid id, - bool *foundp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, bool *foundp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, bool *foundp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name, - unsigned flags, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id, - unsigned flags, JSObject **objp, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnProperty(JSContext *cx, JS::HandleObject obj, const char *name, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasProperty(JSContext *cx, JS::HandleObject obj, const char *name, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_LookupPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); struct JSPropertyDescriptor { JSObject *obj; unsigned attrs; - unsigned shortid; JSPropertyOp getter; JSStrictPropertyOp setter; JS::Value value; - JSPropertyDescriptor() : obj(nullptr), attrs(0), shortid(0), getter(nullptr), - setter(nullptr), value(JSVAL_VOID) + JSPropertyDescriptor() + : obj(nullptr), attrs(0), getter(nullptr), setter(nullptr), value(JSVAL_VOID) {} void trace(JSTracer *trc); + + static js::ThingRootKind rootKind() { return js::THING_ROOT_PROPERTY_DESCRIPTOR; } }; namespace JS { @@ -2803,30 +2889,29 @@ class PropertyDescriptorOperations bool hasGetterObject() const { return desc()->attrs & JSPROP_GETTER; } bool hasSetterObject() const { return desc()->attrs & JSPROP_SETTER; } bool hasGetterOrSetterObject() const { return desc()->attrs & (JSPROP_GETTER | JSPROP_SETTER); } + bool hasGetterOrSetter() const { return desc()->getter || desc()->setter; } bool isShared() const { return desc()->attrs & JSPROP_SHARED; } bool isIndex() const { return desc()->attrs & JSPROP_INDEX; } - bool hasShortId() const { return desc()->attrs & JSPROP_SHORTID; } bool hasAttributes(unsigned attrs) const { return desc()->attrs & attrs; } - JS::Handle object() const { - return JS::Handle::fromMarkedLocation(&desc()->obj); + JS::HandleObject object() const { + return JS::HandleObject::fromMarkedLocation(&desc()->obj); } unsigned attributes() const { return desc()->attrs; } - unsigned shortid() const { return desc()->shortid; } JSPropertyOp getter() const { return desc()->getter; } JSStrictPropertyOp setter() const { return desc()->setter; } - JS::Handle getterObject() const { + JS::HandleObject getterObject() const { MOZ_ASSERT(hasGetterObject()); - return JS::Handle::fromMarkedLocation( + return JS::HandleObject::fromMarkedLocation( reinterpret_cast(&desc()->getter)); } - JS::Handle setterObject() const { + JS::HandleObject setterObject() const { MOZ_ASSERT(hasSetterObject()); - return JS::Handle::fromMarkedLocation( + return JS::HandleObject::fromMarkedLocation( reinterpret_cast(&desc()->setter)); } - JS::Handle value() const { - return JS::Handle::fromMarkedLocation(&desc()->value); + JS::HandleValue value() const { + return JS::HandleValue::fromMarkedLocation(&desc()->value); } }; @@ -2840,30 +2925,47 @@ class MutablePropertyDescriptorOperations : public PropertyDescriptorOperations< void clear() { object().set(nullptr); setAttributes(0); - setShortId(0); setGetter(nullptr); setSetter(nullptr); value().setUndefined(); } - JS::MutableHandle object() { - return JS::MutableHandle::fromMarkedLocation(&desc()->obj); + void assign(JSPropertyDescriptor &other) { + object().set(other.obj); + setAttributes(other.attrs); + setGetter(other.getter); + setSetter(other.setter); + value().set(other.value); + } + + JS::MutableHandleObject object() { + return JS::MutableHandleObject::fromMarkedLocation(&desc()->obj); } unsigned &attributesRef() { return desc()->attrs; } JSPropertyOp &getter() { return desc()->getter; } JSStrictPropertyOp &setter() { return desc()->setter; } - JS::MutableHandle value() { - return JS::MutableHandle::fromMarkedLocation(&desc()->value); + JS::MutableHandleValue value() { + return JS::MutableHandleValue::fromMarkedLocation(&desc()->value); } void setEnumerable() { desc()->attrs |= JSPROP_ENUMERATE; } void setAttributes(unsigned attrs) { desc()->attrs = attrs; } - void setShortId(unsigned id) { desc()->shortid = id; } void setGetter(JSPropertyOp op) { desc()->getter = op; } void setSetter(JSStrictPropertyOp op) { desc()->setter = op; } void setGetterObject(JSObject *obj) { desc()->getter = reinterpret_cast(obj); } void setSetterObject(JSObject *obj) { desc()->setter = reinterpret_cast(obj); } + + JS::MutableHandleObject getterObject() { + MOZ_ASSERT(this->hasGetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->getter)); + } + JS::MutableHandleObject setterObject() { + MOZ_ASSERT(this->hasSetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->setter)); + } }; } /* namespace JS */ @@ -2873,7 +2975,6 @@ namespace js { template <> struct GCMethods { static JSPropertyDescriptor initial() { return JSPropertyDescriptor(); } - static ThingRootKind kind() { return THING_ROOT_PROPERTY_DESCRIPTOR; } static bool poisoned(const JSPropertyDescriptor &desc) { return (desc.obj && JS::IsPoisonedPtr(desc.obj)) || (desc.attrs & JSPROP_GETTER && desc.getter && JS::IsPoisonedPtr(desc.getter)) || @@ -2922,12 +3023,22 @@ class MutableHandleBase } /* namespace js */ +namespace JS { + +extern JS_PUBLIC_API(bool) +ParsePropertyDescriptorObject(JSContext *cx, + JS::HandleObject obj, + JS::HandleValue descriptor, + JS::MutableHandle desc); + +} // namespace JS + extern JS_PUBLIC_API(bool) -JS_GetOwnPropertyDescriptorById(JSContext *cx, JSObject *objArg, jsid id, unsigned flags, +JS_GetOwnPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, const char *name, unsigned flags, +JS_GetOwnPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandle desc); /* @@ -2936,138 +3047,193 @@ JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, const char *name, u * then this property was not found on the prototype chain. */ extern JS_PUBLIC_API(bool) -JS_GetPropertyDescriptorById(JSContext *cx, JSObject *obj, jsid id, unsigned flags, +JS_GetPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetPropertyDescriptor(JSContext *cx, JSObject *obj, const char *name, unsigned flags, +JS_GetPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, JS::MutableHandle vp); +JS_GetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetPropertyTo(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject onBehalfOf, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); +JS_SetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_ForwardGetPropertyTo(JSContext *cx, JSObject *obj, jsid id, JSObject *onBehalfOf, - JS::MutableHandle vp); +JS_DeleteProperty(JSContext *cx, JS::HandleObject obj, const char *name); extern JS_PUBLIC_API(bool) -JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, JS::Handle v); +JS_DeleteProperty2(JSContext *cx, JS::HandleObject obj, const char *name, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_SetPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::Handle v); +JS_DeletePropertyById(JSContext *cx, JS::HandleObject obj, jsid id); extern JS_PUBLIC_API(bool) -JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name); +JS_DeletePropertyById2(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name, bool *succeeded); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleValue value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DeletePropertyById(JSContext *cx, JSObject *obj, jsid id); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleObject value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, bool *succeeded); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleString value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineUCProperty(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + int32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, - int8_t tinyid, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + uint32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnUCProperty(JSContext *cx, JSObject *obj, const jschar *name, +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + double value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *foundp); extern JS_PUBLIC_API(bool) -JS_HasUCProperty(JSContext *cx, JSObject *obj, +JS_HasUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *vp); extern JS_PUBLIC_API(bool) -JS_LookupUCProperty(JSContext *cx, JSObject *obj, +JS_LookupUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::MutableHandle vp); + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_GetUCProperty(JSContext *cx, JSObject *obj, +JS_GetUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::MutableHandle vp); + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_SetUCProperty(JSContext *cx, JSObject *obj, +JS_SetUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::Handle v); + JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_DeleteUCProperty2(JSContext *cx, JSObject *obj, const jschar *name, size_t namelen, +JS_DeleteUCProperty2(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *succeeded); extern JS_PUBLIC_API(JSObject *) -JS_NewArrayObject(JSContext *cx, int length, jsval *vector); +JS_NewArrayObject(JSContext *cx, const JS::HandleValueArray& contents); + +extern JS_PUBLIC_API(JSObject *) +JS_NewArrayObject(JSContext *cx, size_t length); extern JS_PUBLIC_API(bool) -JS_IsArrayObject(JSContext *cx, JSObject *obj); +JS_IsArrayObject(JSContext *cx, JS::HandleValue value); extern JS_PUBLIC_API(bool) -JS_GetArrayLength(JSContext *cx, JSObject *obj, uint32_t *lengthp); +JS_IsArrayObject(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_SetArrayLength(JSContext *cx, JSObject *obj, uint32_t length); +JS_GetArrayLength(JSContext *cx, JS::Handle obj, uint32_t *lengthp); extern JS_PUBLIC_API(bool) -JS_DefineElement(JSContext *cx, JSObject *obj, uint32_t index, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_SetArrayLength(JSContext *cx, JS::Handle obj, uint32_t length); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnElement(JSContext *cx, JSObject *obj, uint32_t index, bool *foundp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasElement(JSContext *cx, JSObject *obj, uint32_t index, bool *foundp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_GetElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_ForwardGetElementTo(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf, - JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetElementTo(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::HandleObject onBehalfOf, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t v); -/* - * Get the property with name given by |index|, if it has one. If - * not, |*present| will be set to false and the value of |vp| must not - * be relied on. - */ extern JS_PUBLIC_API(bool) -JS_GetElementIfPresent(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf, - JS::MutableHandle vp, bool* present); +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t v); extern JS_PUBLIC_API(bool) -JS_SetElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double v); extern JS_PUBLIC_API(bool) -JS_DeleteElement(JSContext *cx, JSObject *obj, uint32_t index); +JS_DeleteElement(JSContext *cx, JS::HandleObject obj, uint32_t index); extern JS_PUBLIC_API(bool) -JS_DeleteElement2(JSContext *cx, JSObject *obj, uint32_t index, bool *succeeded); +JS_DeleteElement2(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded); /* * Remove all configurable properties from the given (non-global) object and * assign undefined to all writable data properties. */ JS_PUBLIC_API(void) -JS_ClearNonGlobalObject(JSContext *cx, JSObject *objArg); +JS_ClearNonGlobalObject(JSContext *cx, JS::HandleObject obj); /* * Assign 'undefined' to all of the object's non-reserved slots. Note: this is @@ -3077,48 +3243,64 @@ JS_PUBLIC_API(void) JS_SetAllNonReservedSlotsToUndefined(JSContext *cx, JSObject *objArg); /* - * Create a new array buffer with the given contents, which must have been - * returned by JS_AllocateArrayBufferContents or JS_StealArrayBufferContents. - * The new array buffer takes ownership. After calling this function, do not - * free |contents| or use |contents| from another thread. + * Create a new array buffer with the given contents. On success, the ownership + * is transferred to the new array buffer. */ extern JS_PUBLIC_API(JSObject *) -JS_NewArrayBufferWithContents(JSContext *cx, void *contents); +JS_NewArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); /* * Steal the contents of the given array buffer. The array buffer has its * length set to 0 and its contents array cleared. The caller takes ownership - * of |*contents| and must free it or transfer ownership via + * of the return value and must free it or transfer ownership via * JS_NewArrayBufferWithContents when done using it. - * To free |*contents|, call free(). - * A pointer to the buffer's data is returned in |*data|. This pointer can - * be used until |*contents| is freed or has its ownership transferred. */ -extern JS_PUBLIC_API(bool) -JS_StealArrayBufferContents(JSContext *cx, JS::HandleObject obj, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_StealArrayBufferContents(JSContext *cx, JS::HandleObject obj); /* * Allocate memory that may be eventually passed to - * JS_NewArrayBufferWithContents. |nbytes| is the number of payload bytes - * required. The pointer to pass to JS_NewArrayBufferWithContents is returned - * in |contents|. The pointer to the |nbytes| of usable memory is returned in - * |data|. (*|contents| will contain a header before |data|.) The only legal - * operations on *|contents| is to free it, or pass it to - * JS_NewArrayBufferWithContents or JS_ReallocateArrayBufferContents. + * JS_NewArrayBufferWithContents. |maybecx| is optional; if a non-nullptr cx is + * given, it will be used for memory accounting and OOM reporting. |nbytes| is + * the number of payload bytes required. */ -extern JS_PUBLIC_API(bool) -JS_AllocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_AllocateArrayBufferContents(JSContext *maybecx, uint32_t nbytes); /* * Reallocate memory allocated by JS_AllocateArrayBufferContents, growing or - * shrinking it as appropriate. The new data pointer will be returned in data. - * If *contents is nullptr, behaves like JS_AllocateArrayBufferContents. + * shrinking it as appropriate. If oldContents is null then this behaves like + * JS_AllocateArrayBufferContents. */ -extern JS_PUBLIC_API(bool) -JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void *oldContents, uint32_t oldNbytes); + +/* + * Create a new mapped array buffer with the given memory mapped contents. On success, + * the ownership is transferred to the new mapped array buffer. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewMappedArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); + +/* + * Create memory mapped array buffer contents. + * Caller must take care of closing fd after calling this function. + */ +extern JS_PUBLIC_API(void *) +JS_CreateMappedArrayBufferContents(int fd, size_t offset, size_t length); + +/* + * Release the allocated resource of mapped array buffer contents before the + * object is created. + * If a new object has been created by JS_NewMappedArrayBufferWithContents() + * with this content, then JS_NeuterArrayBuffer() should be used instead to + * release the resource used by the object. + */ +extern JS_PUBLIC_API(void) +JS_ReleaseMappedArrayBufferContents(void *contents, size_t length); extern JS_PUBLIC_API(JSIdArray *) -JS_Enumerate(JSContext *cx, JSObject *obj); +JS_Enumerate(JSContext *cx, JS::HandleObject obj); /* * Create an object to iterate over enumerable properties of obj, in arbitrary @@ -3126,7 +3308,7 @@ JS_Enumerate(JSContext *cx, JSObject *obj); * order, which uses order of property definition in obj. */ extern JS_PUBLIC_API(JSObject *) -JS_NewPropertyIterator(JSContext *cx, JSObject *obj); +JS_NewPropertyIterator(JSContext *cx, JS::Handle obj); /* * Return true on success with *idp containing the id of the next enumerable @@ -3134,11 +3316,7 @@ JS_NewPropertyIterator(JSContext *cx, JSObject *obj); * left to visit. Return false on error. */ extern JS_PUBLIC_API(bool) -JS_NextProperty(JSContext *cx, JSObject *iterobj, jsid *idp); - -extern JS_PUBLIC_API(bool) -JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, - jsval *vp, unsigned *attrsp); +JS_NextProperty(JSContext *cx, JS::Handle iterobj, jsid *idp); extern JS_PUBLIC_API(jsval) JS_GetReservedSlot(JSObject *obj, uint32_t index); @@ -3148,84 +3326,12 @@ JS_SetReservedSlot(JSObject *obj, uint32_t index, jsval v); /************************************************************************/ -/* - * Security protocol. - */ -struct JSPrincipals { - /* Don't call "destroy"; use reference counting macros below. */ -#ifdef JS_THREADSAFE - mozilla::Atomic refcount; -#else - int32_t refcount; -#endif - -#ifdef DEBUG - /* A helper to facilitate principals debugging. */ - uint32_t debugToken; -#endif - - void setDebugToken(uint32_t token) { -# ifdef DEBUG - debugToken = token; -# endif - } - - /* - * This is not defined by the JS engine but should be provided by the - * embedding. - */ - JS_PUBLIC_API(void) dump(); -}; - -extern JS_PUBLIC_API(void) -JS_HoldPrincipals(JSPrincipals *principals); - -extern JS_PUBLIC_API(void) -JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals); - -struct JSSecurityCallbacks { - JSCheckAccessOp checkObjectAccess; - JSCSPEvalChecker contentSecurityPolicyAllows; - JSSubsumesOp subsumes; -}; - -extern JS_PUBLIC_API(void) -JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks); - -extern JS_PUBLIC_API(const JSSecurityCallbacks *) -JS_GetSecurityCallbacks(JSRuntime *rt); - -/* - * Code running with "trusted" principals will be given a deeper stack - * allocation than ordinary scripts. This allows trusted script to run after - * untrusted script has exhausted the stack. This function sets the - * runtime-wide trusted principal. - * - * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since - * there is no available JSContext. Instead, the caller must ensure that the - * given principals stays valid for as long as 'rt' may point to it. If the - * principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be - * called again, passing nullptr for 'prin'. - */ -extern JS_PUBLIC_API(void) -JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin); - -/* - * Initialize the callback that is called to destroy JSPrincipals instance - * when its reference counter drops to zero. The initialization can be done - * only once per JS runtime. - */ -extern JS_PUBLIC_API(void) -JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals); - -/************************************************************************/ - /* * Functions and scripts. */ extern JS_PUBLIC_API(JSFunction *) JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, - JSObject *parent, const char *name); + JS::Handle parent, const char *name); /* * Create the function with the name given by the id. JSID_IS_STRING(id) must @@ -3233,12 +3339,13 @@ JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, */ extern JS_PUBLIC_API(JSFunction *) JS_NewFunctionById(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, - JSObject *parent, jsid id); + JS::Handle parent, JS::Handle id); namespace JS { extern JS_PUBLIC_API(JSFunction *) -GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, jsid id, unsigned nargs); +GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, JS::Handle id, + unsigned nargs); } /* namespace JS */ @@ -3295,22 +3402,22 @@ JS_IsConstructor(JSFunction *fun); * If |callable| is not callable, will throw and return nullptr. */ extern JS_PUBLIC_API(JSObject*) -JS_BindCallable(JSContext *cx, JSObject *callable, JSObject *newThis); +JS_BindCallable(JSContext *cx, JS::Handle callable, JS::Handle newThis); extern JS_PUBLIC_API(bool) -JS_DefineFunctions(JSContext *cx, JSObject *obj, const JSFunctionSpec *fs); +JS_DefineFunctions(JSContext *cx, JS::Handle obj, const JSFunctionSpec *fs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call, +JS_DefineFunction(JSContext *cx, JS::Handle obj, const char *name, JSNative call, unsigned nargs, unsigned attrs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineUCFunction(JSContext *cx, JSObject *obj, +JS_DefineUCFunction(JSContext *cx, JS::Handle obj, const jschar *name, size_t namelen, JSNative call, unsigned nargs, unsigned attrs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call, +JS_DefineFunctionById(JSContext *cx, JS::Handle obj, JS::Handle id, JSNative call, unsigned nargs, unsigned attrs); /* @@ -3318,7 +3425,7 @@ JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call, * fail if funobj was lexically nested inside some other function. */ extern JS_PUBLIC_API(JSObject *) -JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent); +JS_CloneFunctionObject(JSContext *cx, JS::Handle funobj, JS::Handle parent); /* * Given a buffer, return false if the buffer might become a valid @@ -3328,32 +3435,49 @@ JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent); * the compiler. */ extern JS_PUBLIC_API(bool) -JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj, const char *utf8, size_t length); +JS_BufferIsCompilableUnit(JSContext *cx, JS::Handle obj, const char *utf8, + size_t length); -extern JS_PUBLIC_API(JSScript *) +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileScript(JSContext *cx, JS::HandleObject obj, const char *ascii, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileUCScript(JSContext *cx, JS::HandleObject obj, const jschar *chars, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleScript script); extern JS_PUBLIC_API(JSObject *) JS_GetGlobalFromScript(JSScript *script); -extern JS_PUBLIC_API(JSFunction *) +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileFunction(JSContext *cx, JS::HandleObject obj, const char *name, unsigned nargs, const char *const *argnames, const char *bytes, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); -extern JS_PUBLIC_API(JSFunction *) +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileUCFunction(JSContext *cx, JS::HandleObject obj, const char *name, unsigned nargs, const char *const *argnames, const jschar *chars, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); namespace JS { @@ -3401,12 +3525,14 @@ namespace JS { * is protected anyway); instead, create instances only of the derived classes: * CompileOptions and OwningCompileOptions. */ -class JS_PUBLIC_API(ReadOnlyCompileOptions) +class JS_FRIEND_API(ReadOnlyCompileOptions) { + friend class CompileOptions; + protected: - JSPrincipals *principals_; JSPrincipals *originPrincipals_; const char *filename_; + const char *introducerFilename_; const jschar *sourceMapURL_; // This constructor leaves 'version' set to JSVERSION_UNKNOWN. The structure @@ -3414,9 +3540,9 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) // classes' constructors take care of that, in ways appropriate to their // purpose. ReadOnlyCompileOptions() - : principals_(nullptr), - originPrincipals_(nullptr), + : originPrincipals_(nullptr), filename_(nullptr), + introducerFilename_(nullptr), sourceMapURL_(nullptr), version(JSVERSION_UNKNOWN), versionSet(false), @@ -3425,6 +3551,7 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) column(0), compileAndGo(false), forEval(false), + defineOnScope(true), noScriptRval(false), selfHostingMode(false), canLazilyParse(true), @@ -3433,7 +3560,12 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) werrorOption(false), asmJSOption(false), forceAsync(false), - sourcePolicy(SAVE_SOURCE) + installedFile(false), + sourceIsLazy(false), + introductionType(nullptr), + introductionLineno(0), + introductionOffset(0), + hasIntroductionInfo(false) { } // Set all POD options (those not requiring reference counts, copies, @@ -3443,12 +3575,13 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) public: // Read-only accessors for non-POD options. The proper way to set these // depends on the derived type. - JSPrincipals *principals() const { return principals_; } - JSPrincipals *originPrincipals() const; + JSPrincipals *originPrincipals(js::ExclusiveContext *cx) const; const char *filename() const { return filename_; } + const char *introducerFilename() const { return introducerFilename_; } const jschar *sourceMapURL() const { return sourceMapURL_; } virtual JSObject *element() const = 0; - virtual JSString *elementProperty() const = 0; + virtual JSString *elementAttributeName() const = 0; + virtual JSScript *introductionScript() const = 0; // POD options. JSVersion version; @@ -3458,6 +3591,7 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) unsigned column; bool compileAndGo; bool forEval; + bool defineOnScope; bool noScriptRval; bool selfHostingMode; bool canLazilyParse; @@ -3466,11 +3600,15 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) bool werrorOption; bool asmJSOption; bool forceAsync; - enum SourcePolicy { - NO_SOURCE, - LAZY_SOURCE, - SAVE_SOURCE - } sourcePolicy; + bool installedFile; // 'true' iff pre-compiling js file in packaged app + bool sourceIsLazy; + + // |introductionType| is a statically allocated C string: + // one of "eval", "Function", or "GeneratorFunction". + const char *introductionType; + unsigned introductionLineno; + uint32_t introductionOffset; + bool hasIntroductionInfo; private: static JSObject * const nullObjectPtr; @@ -3490,11 +3628,12 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) * comes to refer to the object that owns this, then the whole cycle, and * anything else it entrains, will never be freed. */ -class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions +class JS_FRIEND_API(OwningCompileOptions) : public ReadOnlyCompileOptions { JSRuntime *runtime; PersistentRootedObject elementRoot; - PersistentRootedString elementPropertyRoot; + PersistentRootedString elementAttributeNameRoot; + PersistentRootedScript introductionScriptRoot; public: // A minimal constructor, for use with OwningCompileOptions::copy. This @@ -3505,22 +3644,30 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions ~OwningCompileOptions(); JSObject *element() const MOZ_OVERRIDE { return elementRoot; } - JSString *elementProperty() const MOZ_OVERRIDE { return elementPropertyRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } // Set this to a copy of |rhs|. Return false on OOM. bool copy(JSContext *cx, const ReadOnlyCompileOptions &rhs); /* These setters make copies of their string arguments, and are fallible. */ + bool setFile(JSContext *cx, const char *f); bool setFileAndLine(JSContext *cx, const char *f, unsigned l); bool setSourceMapURL(JSContext *cx, const jschar *s); + bool setIntroducerFilename(JSContext *cx, const char *s); /* These setters are infallible, and can be chained. */ - OwningCompileOptions &setElement(JSObject *e) { elementRoot = e; return *this; } - OwningCompileOptions &setElementProperty(JSString *p) { elementPropertyRoot = p; return *this; } - OwningCompileOptions &setPrincipals(JSPrincipals *p) { - if (p) JS_HoldPrincipals(p); - if (principals_) JS_DropPrincipals(runtime, principals_); - principals_ = p; + OwningCompileOptions &setLine(unsigned l) { lineno = l; return *this; } + OwningCompileOptions &setElement(JSObject *e) { + elementRoot = e; + return *this; + } + OwningCompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + OwningCompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; return *this; } OwningCompileOptions &setOriginPrincipals(JSPrincipals *p) { @@ -3538,10 +3685,27 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions OwningCompileOptions &setColumn(unsigned c) { column = c; return *this; } OwningCompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } OwningCompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + OwningCompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } OwningCompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } OwningCompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } OwningCompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } - OwningCompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; } + OwningCompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + OwningCompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + bool setIntroductionInfo(JSContext *cx, const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + if (!setIntroducerFilename(cx, introducerFn)) + return false; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return true; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; }; /* @@ -3551,36 +3715,47 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions * create an instance of this type, it's up to you to guarantee that * everything you store in it will outlive it. */ -class MOZ_STACK_CLASS JS_PUBLIC_API(CompileOptions) : public ReadOnlyCompileOptions +class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOptions { RootedObject elementRoot; - RootedString elementPropertyRoot; + RootedString elementAttributeNameRoot; + RootedScript introductionScriptRoot; public: explicit CompileOptions(JSContext *cx, JSVersion version = JSVERSION_UNKNOWN); CompileOptions(js::ContextFriendFields *cx, const ReadOnlyCompileOptions &rhs) - : ReadOnlyCompileOptions(), elementRoot(cx), elementPropertyRoot(cx) + : ReadOnlyCompileOptions(), elementRoot(cx), elementAttributeNameRoot(cx), + introductionScriptRoot(cx) { copyPODOptions(rhs); - principals_ = rhs.principals(); - originPrincipals_ = rhs.originPrincipals(); + originPrincipals_ = rhs.originPrincipals_; filename_ = rhs.filename(); sourceMapURL_ = rhs.sourceMapURL(); elementRoot = rhs.element(); - elementPropertyRoot = rhs.elementProperty(); + elementAttributeNameRoot = rhs.elementAttributeName(); + introductionScriptRoot = rhs.introductionScript(); } JSObject *element() const MOZ_OVERRIDE { return elementRoot; } - JSString *elementProperty() const MOZ_OVERRIDE { return elementPropertyRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } + CompileOptions &setFile(const char *f) { filename_ = f; return *this; } + CompileOptions &setLine(unsigned l) { lineno = l; return *this; } CompileOptions &setFileAndLine(const char *f, unsigned l) { filename_ = f; lineno = l; return *this; } CompileOptions &setSourceMapURL(const jschar *s) { sourceMapURL_ = s; return *this; } CompileOptions &setElement(JSObject *e) { elementRoot = e; return *this; } - CompileOptions &setElementProperty(JSString *p) { elementPropertyRoot = p; return *this; } - CompileOptions &setPrincipals(JSPrincipals *p) { principals_ = p; return *this; } + CompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + CompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; + return *this; + } CompileOptions &setOriginPrincipals(JSPrincipals *p) { originPrincipals_ = p; return *this; @@ -3594,25 +3769,50 @@ class MOZ_STACK_CLASS JS_PUBLIC_API(CompileOptions) : public ReadOnlyCompileOpti CompileOptions &setColumn(unsigned c) { column = c; return *this; } CompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } CompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + CompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } CompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } CompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } CompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } - CompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; } + CompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + CompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + CompileOptions &setIntroductionInfo(const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + introducerFilename_ = introducerFn; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return *this; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; }; -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *bytes, size_t length); +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const jschar *chars, size_t length); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, FILE *file); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, const char *filename); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, FILE *file, + JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *filename, + JS::MutableHandleScript script); extern JS_PUBLIC_API(bool) CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t length); @@ -3625,8 +3825,8 @@ CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t * for the compilation. The callback will be invoked while off the main thread, * so must ensure that its operations are thread safe. Afterwards, * FinishOffThreadScript must be invoked on the main thread to get the result - * script or nullptr. If maybecx is specified, this method will also report - * any error or warnings generated during the parse. + * script or nullptr. If maybecx is not specified, the resources will be freed, + * but no script will be returned. * * The characters passed in to CompileOffThread must remain live until the * callback is invoked, and the resulting script will be rooted until the call @@ -3634,27 +3834,32 @@ CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t */ extern JS_PUBLIC_API(bool) -CompileOffThread(JSContext *cx, Handle obj, const ReadOnlyCompileOptions &options, +CompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, const jschar *chars, size_t length, OffThreadCompileCallback callback, void *callbackData); extern JS_PUBLIC_API(JSScript *) FinishOffThreadScript(JSContext *maybecx, JSRuntime *rt, void *token); -extern JS_PUBLIC_API(JSFunction *) -CompileFunction(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *name, unsigned nargs, const char *const *argnames, - const char *bytes, size_t length); + SourceBufferHolder &srcBuf, JS::MutableHandleFunction fun); -extern JS_PUBLIC_API(JSFunction *) -CompileFunction(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *name, unsigned nargs, const char *const *argnames, + const char *bytes, size_t length, JS::MutableHandleFunction fun); + +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *name, unsigned nargs, const char *const *argnames, - const jschar *chars, size_t length); + const jschar *chars, size_t length, JS::MutableHandleFunction fun); } /* namespace JS */ extern JS_PUBLIC_API(JSString *) -JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned indent); +JS_DecompileScript(JSContext *cx, JS::Handle script, const char *name, unsigned indent); /* * API extension: OR this into indent to avoid pretty-printing the decompiled @@ -3663,10 +3868,10 @@ JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned i #define JS_DONT_PRETTY_PRINT ((unsigned)0x8000) extern JS_PUBLIC_API(JSString *) -JS_DecompileFunction(JSContext *cx, JSFunction *fun, unsigned indent); +JS_DecompileFunction(JSContext *cx, JS::Handle fun, unsigned indent); extern JS_PUBLIC_API(JSString *) -JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, unsigned indent); +JS_DecompileFunctionBody(JSContext *cx, JS::Handle fun, unsigned indent); /* * NB: JS_ExecuteScript and the JS_Evaluate*Script* quadruplets use the obj @@ -3702,158 +3907,159 @@ JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, unsigned indent); * etc., entry points. */ extern JS_PUBLIC_API(bool) -JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval); +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval, - JSVersion version); +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script); + +namespace JS { /* - * Execute either the function-defining prolog of a script, or the script's - * main body, but not both. + * Like the above, but handles a cross-compartment script. If the script is + * cross-compartment, it is cloned into the current compartment before executing. */ -typedef enum JSExecPart { JSEXEC_PROLOG, JSEXEC_MAIN } JSExecPart; +extern JS_PUBLIC_API(bool) +CloneAndExecuteScript(JSContext *cx, JS::Handle obj, JS::Handle script); + +} /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_EvaluateScript(JSContext *cx, JSObject *obj, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleValue rval, JSVersion version); + +extern JS_PUBLIC_API(bool) +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JSVersion version); extern JS_PUBLIC_API(bool) -JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_EvaluateScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno); extern JS_PUBLIC_API(bool) -JS_EvaluateUCScript(JSContext *cx, JSObject *obj, +JS_EvaluateUCScript(JSContext *cx, JS::Handle obj, const jschar *chars, unsigned length, const char *filename, unsigned lineno, - jsval *rval); + JS::MutableHandle rval); + +namespace JS { extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleValue rval); -/* - * JSAPI clients may optionally specify the 'originPrincipals' of a script. - * A script's originPrincipals may be retrieved through the debug API (via - * JS_GetScriptOriginPrincipals) and the originPrincipals are transitively - * assigned to any nested scripts (including scripts dynamically created via - * eval and the Function constructor). If originPrincipals is null, then the - * value of principals is used as origin principals for the script. - */ extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipalsVersionOrigin(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - JSPrincipals *originPrincipals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleValue rval); -namespace JS { +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const jschar *chars, size_t length, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *bytes, size_t length, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *filename, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename); } /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunction(JSContext *cx, JS::HandleObject obj, JS::HandleFunction fun, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunctionName(JSContext *cx, JS::HandleObject obj, const char *name, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunctionValue(JSContext *cx, JS::HandleObject obj, JS::HandleValue fval, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); namespace JS { static inline bool -Call(JSContext *cx, JSObject *thisObj, JSFunction *fun, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleFunction fun, + const JS::HandleValueArray &args, MutableHandleValue rval) { - return !!JS_CallFunction(cx, thisObj, fun, argc, argv, rval.address()); + return !!JS_CallFunction(cx, thisObj, fun, args, rval); } static inline bool -Call(JSContext *cx, JSObject *thisObj, const char *name, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, const char *name, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return !!JS_CallFunctionName(cx, thisObj, name, argc, argv, rval.address()); + return !!JS_CallFunctionName(cx, thisObj, name, args, rval); } static inline bool -Call(JSContext *cx, JSObject *thisObj, jsval fun, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return !!JS_CallFunctionValue(cx, thisObj, fun, argc, argv, rval.address()); + return !!JS_CallFunctionValue(cx, thisObj, fun, args, rval); } extern JS_PUBLIC_API(bool) -Call(JSContext *cx, jsval thisv, jsval fun, unsigned argc, jsval *argv, MutableHandle rval); +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval); static inline bool -Call(JSContext *cx, jsval thisv, JSObject *funObj, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleObject funObj, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return Call(cx, thisv, OBJECT_TO_JSVAL(funObj), argc, argv, rval); + JS_ASSERT(funObj); + JS::RootedValue fun(cx, JS::ObjectValue(*funObj)); + return Call(cx, thisv, fun, args, rval); } +extern JS_PUBLIC_API(bool) +Construct(JSContext *cx, JS::HandleValue fun, + const JS::HandleValueArray& args, + MutableHandleValue rval); + } /* namespace JS */ /* - * These functions allow setting an operation callback that will be called + * These functions allow setting an interrupt callback that will be called * from the JS thread some time after any thread triggered the callback using - * JS_TriggerOperationCallback(rt). + * JS_RequestInterruptCallback(rt). * * To schedule the GC and for other activities the engine internally triggers - * operation callbacks. The embedding should thus not rely on callbacks being + * interrupt callbacks. The embedding should thus not rely on callbacks being * triggered through the external API only. * * Important note: Additional callbacks can occur inside the callback handler * if it re-enters the JS engine. The embedding must ensure that the callback * is disconnected before attempting such re-entry. */ -extern JS_PUBLIC_API(JSOperationCallback) -JS_SetOperationCallback(JSRuntime *rt, JSOperationCallback callback); +extern JS_PUBLIC_API(JSInterruptCallback) +JS_SetInterruptCallback(JSRuntime *rt, JSInterruptCallback callback); -extern JS_PUBLIC_API(JSOperationCallback) -JS_GetOperationCallback(JSRuntime *rt); +extern JS_PUBLIC_API(JSInterruptCallback) +JS_GetInterruptCallback(JSRuntime *rt); extern JS_PUBLIC_API(void) -JS_TriggerOperationCallback(JSRuntime *rt); +JS_RequestInterruptCallback(JSRuntime *rt); extern JS_PUBLIC_API(bool) JS_IsRunning(JSContext *cx); @@ -3878,7 +4084,7 @@ JS_RestoreFrameChain(JSContext *cx); #ifdef MOZ_TRACE_JSCALLS /* * The callback is expected to be quick and noninvasive. It should not - * trigger interrupts, turn on debugging, or produce uncaught JS + * request interrupts, turn on debugging, or produce uncaught JS * exceptions. The state of the stack and registers in the context * cannot be relied upon, since this callback may be invoked directly * from either JIT. The 'entering' field means we are entering a @@ -3953,15 +4159,16 @@ JS_FileEscapedString(FILE *fp, JSString *str, char quote); * special cases where getting the chars is infallible: * * The first case is interned strings, i.e., strings from JS_InternString or - * JSID_TO_STRING(id), using JS_GetInternedStringChars*. + * JSID_TO_STRING(id), using JS_GetLatin1InternedStringChars or + * JS_GetTwoByteInternedStringChars. * * The second case is "flat" strings that have been explicitly prepared in a * fallible context by JS_FlattenString. To catch errors, a separate opaque * JSFlatString type is returned by JS_FlattenString and expected by * JS_GetFlatStringChars. Note, though, that this is purely a syntactic * distinction: the input and output of JS_FlattenString are the same actual - * GC-thing so only one needs to be rooted. If a JSString is known to be flat, - * JS_ASSERT_STRING_IS_FLAT can be used to make a debug-checked cast. Example: + * GC-thing. If a JSString is known to be flat, JS_ASSERT_STRING_IS_FLAT can be + * used to make a debug-checked cast. Example: * * // in a fallible context * JSFlatString *fstr = JS_FlattenString(cx, str); @@ -3970,55 +4177,80 @@ JS_FileEscapedString(FILE *fp, JSString *str, char quote); * JS_ASSERT(fstr == JS_ASSERT_STRING_IS_FLAT(str)); * * // in an infallible context, for the same 'str' - * const jschar *chars = JS_GetFlatStringChars(fstr) + * AutoCheckCannotGC nogc; + * const jschar *chars = JS_GetTwoByteFlatStringChars(nogc, fstr) * JS_ASSERT(chars); * - * The CharsZ APIs guarantee that the returned array has a null character at - * chars[length]. This can require additional copying so clients should prefer - * APIs without CharsZ if possible. The infallible functions also return - * null-terminated arrays. (There is no additional cost or non-Z alternative - * for the infallible functions, so 'Z' is left out of the identifier.) + * Flat strings and interned strings are always null-terminated, so + * JS_FlattenString can be used to get a null-terminated string. + * + * Additionally, string characters are stored as either Latin1Char (8-bit) + * or jschar (16-bit). Clients can use JS_StringHasLatin1Chars and can then + * call either the Latin1* or TwoByte* functions. Some functions like + * JS_CopyStringChars and JS_GetStringCharAt accept both Latin1 and TwoByte + * strings. */ extern JS_PUBLIC_API(size_t) JS_GetStringLength(JSString *str); -extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsAndLength(JSContext *cx, JSString *str, size_t *length); +extern JS_PUBLIC_API(bool) +JS_StringIsFlat(JSString *str); -extern JS_PUBLIC_API(const jschar *) -JS_GetInternedStringChars(JSString *str); +/* Returns true iff the string's characters are stored as Latin1. */ +extern JS_PUBLIC_API(bool) +JS_StringHasLatin1Chars(JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1StringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); extern JS_PUBLIC_API(const jschar *) -JS_GetInternedStringCharsAndLength(JSString *str, size_t *length); +JS_GetTwoByteStringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); + +extern JS_PUBLIC_API(bool) +JS_GetStringCharAt(JSContext *cx, JSString *str, size_t index, jschar *res); + +extern JS_PUBLIC_API(jschar) +JS_GetFlatStringCharAt(JSFlatString *str, size_t index); extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsZ(JSContext *cx, JSString *str); +JS_GetTwoByteExternalStringChars(JSString *str); + +extern JS_PUBLIC_API(bool) +JS_CopyStringChars(JSContext *cx, mozilla::Range dest, JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1InternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsZAndLength(JSContext *cx, JSString *str, size_t *length); +JS_GetTwoByteInternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); extern JS_PUBLIC_API(JSFlatString *) JS_FlattenString(JSContext *cx, JSString *str); +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1FlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); + extern JS_PUBLIC_API(const jschar *) -JS_GetFlatStringChars(JSFlatString *str); +JS_GetTwoByteFlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); -static JS_ALWAYS_INLINE JSFlatString * +static MOZ_ALWAYS_INLINE JSFlatString * JSID_TO_FLAT_STRING(jsid id) { JS_ASSERT(JSID_IS_STRING(id)); return (JSFlatString *)(JSID_BITS(id)); } -static JS_ALWAYS_INLINE JSFlatString * +static MOZ_ALWAYS_INLINE JSFlatString * JS_ASSERT_STRING_IS_FLAT(JSString *str) { - JS_ASSERT(JS_GetFlatStringChars((JSFlatString *)str)); + JS_ASSERT(JS_StringIsFlat(str)); return (JSFlatString *)str; } -static JS_ALWAYS_INLINE JSString * +static MOZ_ALWAYS_INLINE JSString * JS_FORGET_STRING_FLATNESS(JSFlatString *fstr) { return (JSString *)fstr; @@ -4078,7 +4310,7 @@ JS_EncodeString(JSContext *cx, JSString *str); * Same behavior as JS_EncodeString(), but encode into UTF-8 string */ JS_PUBLIC_API(char *) -JS_EncodeStringToUTF8(JSContext *cx, JSString *str); +JS_EncodeStringToUTF8(JSContext *cx, JS::HandleString str); /* * Get number of bytes in the string encoding (without accounting for a @@ -4110,7 +4342,7 @@ class JSAutoByteString MOZ_GUARD_OBJECT_NOTIFIER_INIT; } - JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + explicit JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) : mBytes(nullptr) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -4135,7 +4367,7 @@ class JSAutoByteString char *encodeLatin1(js::ExclusiveContext *cx, JSString *str); - char *encodeUtf8(JSContext *cx, JSString *str) { + char *encodeUtf8(JSContext *cx, JS::HandleString str) { JS_ASSERT(!mBytes); JS_ASSERT(cx); mBytes = JS_EncodeStringToUTF8(cx, str); @@ -4170,6 +4402,84 @@ class JSAutoByteString JSAutoByteString &operator=(const JSAutoByteString &another); }; +namespace JS { + +extern JS_PUBLIC_API(JSAddonId *) +NewAddonId(JSContext *cx, JS::HandleString str); + +extern JS_PUBLIC_API(JSString *) +StringOfAddonId(JSAddonId *id); + +extern JS_PUBLIC_API(JSAddonId *) +AddonIdOfObject(JSObject *obj); + +} // namespace JS + +/************************************************************************/ +/* + * Symbols + */ + +namespace JS { + +/* + * Create a new Symbol with the given description. This function never returns + * a Symbol that is in the Runtime-wide symbol registry. + * + * If description is null, the new Symbol's [[Description]] attribute is + * undefined. + */ +JS_PUBLIC_API(Symbol *) +NewSymbol(JSContext *cx, HandleString description); + +/* + * Symbol.for as specified in ES6. + * + * Get a Symbol with the description 'key' from the Runtime-wide symbol registry. + * If there is not already a Symbol with that description in the registry, a new + * Symbol is created and registered. 'key' must not be null. + */ +JS_PUBLIC_API(Symbol *) +GetSymbolFor(JSContext *cx, HandleString key); + +/* + * Get the [[Description]] attribute of the given symbol. + * + * This function is infallible. If it returns null, that means the symbol's + * [[Description]] is undefined. + */ +JS_PUBLIC_API(JSString *) +GetSymbolDescription(HandleSymbol symbol); + +/* Well-known symbols. */ +MOZ_BEGIN_ENUM_CLASS(SymbolCode, uint32_t) + iterator, // well-known Symbol.iterator + InSymbolRegistry = 0xfffffffe, // created by Symbol.for() or JS::GetSymbolFor() + UniqueSymbol = 0xffffffff // created by Symbol() or JS::NewSymbol() +MOZ_END_ENUM_CLASS(SymbolCode) + +/* For use in loops that iterate over the well-known symbols. */ +const size_t WellKnownSymbolLimit = 1; + +/* + * Return the SymbolCode telling what sort of symbol `symbol` is. + * + * A symbol's SymbolCode never changes once it is created. + */ +JS_PUBLIC_API(SymbolCode) +GetSymbolCode(Handle symbol); + +/* + * Get one of the well-known symbols defined by ES6. A single set of well-known + * symbols is shared by all compartments in a JSRuntime. + * + * `which` must be in the range [0, WellKnownSymbolLimit). + */ +JS_PUBLIC_API(Symbol *) +GetWellKnownSymbol(JSContext *cx, SymbolCode which); + +} /* namespace JS */ + /************************************************************************/ /* * JSON functions @@ -4189,10 +4499,17 @@ JS_Stringify(JSContext *cx, JS::MutableHandleValue value, JS::HandleObject repla JS_PUBLIC_API(bool) JS_ParseJSON(JSContext *cx, const jschar *chars, uint32_t len, JS::MutableHandleValue vp); +JS_PUBLIC_API(bool) +JS_ParseJSON(JSContext *cx, JS::HandleString str, JS::MutableHandleValue vp); + JS_PUBLIC_API(bool) JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32_t len, JS::HandleValue reviver, JS::MutableHandleValue vp); +JS_PUBLIC_API(bool) +JS_ParseJSONWithReviver(JSContext *cx, JS::HandleString str, JS::HandleValue reviver, + JS::MutableHandleValue vp); + /************************************************************************/ /* @@ -4219,7 +4536,6 @@ struct JSLocaleCallbacks { JSLocaleToLowerCase localeToLowerCase; JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API JSLocaleToUnicode localeToUnicode; - JSErrorCallback localeGetErrorMessage; }; /* @@ -4357,8 +4673,35 @@ JS_GetErrorReporter(JSContext *cx); extern JS_PUBLIC_API(JSErrorReporter) JS_SetErrorReporter(JSContext *cx, JSErrorReporter er); +namespace JS { + +extern JS_PUBLIC_API(bool) +CreateError(JSContext *cx, JSExnType type, HandleString stack, + HandleString fileName, uint32_t lineNumber, uint32_t columnNumber, + JSErrorReport *report, HandleString message, MutableHandleValue rval); + /************************************************************************/ +/* + * Weak Maps. + */ + +extern JS_PUBLIC_API(JSObject *) +NewWeakMapObject(JSContext *cx); + +extern JS_PUBLIC_API(bool) +IsWeakMapObject(JSObject *obj); + +extern JS_PUBLIC_API(bool) +GetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::MutableHandleValue val); + +extern JS_PUBLIC_API(bool) +SetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::HandleValue val); + +} /* namespace JS */ + /* * Dates. */ @@ -4387,10 +4730,10 @@ JS_ClearDateCaches(JSContext *cx); /* * Regular Expressions. */ -#define JSREG_FOLD 0x01 /* fold uppercase to lowercase */ -#define JSREG_GLOB 0x02 /* global exec, creates array of matches */ -#define JSREG_MULTILINE 0x04 /* treat ^ and $ as begin and end of line */ -#define JSREG_STICKY 0x08 /* only match starting at lastIndex */ +#define JSREG_FOLD 0x01u /* fold uppercase to lowercase */ +#define JSREG_GLOB 0x02u /* global exec, creates array of matches */ +#define JSREG_MULTILINE 0x04u /* treat ^ and $ as begin and end of line */ +#define JSREG_STICKY 0x08u /* only match starting at lastIndex */ extern JS_PUBLIC_API(JSObject *) JS_NewRegExpObject(JSContext *cx, JS::HandleObject obj, char *bytes, size_t length, @@ -4400,11 +4743,11 @@ extern JS_PUBLIC_API(JSObject *) JS_NewUCRegExpObject(JSContext *cx, JS::HandleObject obj, jschar *chars, size_t length, unsigned flags); -extern JS_PUBLIC_API(void) +extern JS_PUBLIC_API(bool) JS_SetRegExpInput(JSContext *cx, JS::HandleObject obj, JS::HandleString input, bool multiline); -extern JS_PUBLIC_API(void) +extern JS_PUBLIC_API(bool) JS_ClearRegExpStatics(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) @@ -4450,17 +4793,62 @@ JS_ClearPendingException(JSContext *cx); extern JS_PUBLIC_API(bool) JS_ReportPendingException(JSContext *cx); +namespace JS { + /* - * Save the current exception state. This takes a snapshot of cx's current - * exception state without making any change to that state. + * Save and later restore the current exception state of a given JSContext. + * This is useful for implementing behavior in C++ that's like try/catch + * or try/finally in JS. * - * The returned state pointer MUST be passed later to JS_RestoreExceptionState - * (to restore that saved state, overriding any more recent state) or else to - * JS_DropExceptionState (to free the state struct in case it is not correct - * or desirable to restore it). Both Restore and Drop free the state struct, - * so callers must stop using the pointer returned from Save after calling the - * Release or Drop API. + * Typical usage: + * + * bool ok = JS_EvaluateScript(cx, ...); + * AutoSaveExceptionState savedExc(cx); + * ... cleanup that might re-enter JS ... + * return ok; */ +class JS_PUBLIC_API(AutoSaveExceptionState) +{ + private: + JSContext *context; + bool wasPropagatingForcedReturn; + bool wasThrowing; + RootedValue exceptionValue; + + public: + /* + * Take a snapshot of cx's current exception state. Then clear any current + * pending exception in cx. + */ + explicit AutoSaveExceptionState(JSContext *cx); + + /* + * If neither drop() nor restore() was called, restore the exception + * state only if no exception is currently pending on cx. + */ + ~AutoSaveExceptionState(); + + /* + * Discard any stored exception state. + * If this is called, the destructor is a no-op. + */ + void drop() { + wasPropagatingForcedReturn = false; + wasThrowing = false; + exceptionValue.setUndefined(); + } + + /* + * Replace cx's exception state with the stored exception state. Then + * discard the stored exception state. If this is called, the + * destructor is a no-op. + */ + void restore(); +}; + +} /* namespace JS */ + +/* Deprecated API. Use AutoSaveExceptionState instead. */ extern JS_PUBLIC_API(JSExceptionState *) JS_SaveExceptionState(JSContext *cx); @@ -4471,22 +4859,14 @@ extern JS_PUBLIC_API(void) JS_DropExceptionState(JSContext *cx, JSExceptionState *state); /* - * If the given value is an exception object that originated from an error, - * the exception will contain an error report struct, and this API will return - * the address of that struct. Otherwise, it returns nullptr. The lifetime + * If the given object is an exception object, the exception will have (or be + * able to lazily create) an error report struct, and this function will return + * the address of that struct. Otherwise, it returns nullptr. The lifetime * of the error report struct that might be returned is the same as the * lifetime of the exception object. */ extern JS_PUBLIC_API(JSErrorReport *) -JS_ErrorFromException(JSContext *cx, JS::HandleValue v); - -/* - * Given a reported error's message and JSErrorReport struct pointer, throw - * the corresponding exception on cx. - */ -extern JS_PUBLIC_API(bool) -JS_ThrowReportedError(JSContext *cx, const char *message, - JSErrorReport *reportp); +JS_ErrorFromException(JSContext *cx, JS::HandleObject obj); /* * Throws a StopIteration exception on cx. @@ -4521,7 +4901,7 @@ JS_AbortIfWrongThread(JSRuntime *rt); * [[Prototype]]. */ extern JS_PUBLIC_API(JSObject *) -JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const jsval *vp); +JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const JS::CallArgs& args); /************************************************************************/ @@ -4536,16 +4916,18 @@ JS_ScheduleGC(JSContext *cx, uint32_t count); #endif extern JS_PUBLIC_API(void) -JS_SetParallelParsingEnabled(JSContext *cx, bool enabled); +JS_SetParallelParsingEnabled(JSRuntime *rt, bool enabled); extern JS_PUBLIC_API(void) -JS_SetParallelIonCompilationEnabled(JSContext *cx, bool enabled); +JS_SetOffthreadIonCompilationEnabled(JSRuntime *rt, bool enabled); -#define JIT_COMPILER_OPTIONS(Register) \ - Register(BASELINE_USECOUNT_TRIGGER, "baseline.usecount.trigger") \ - Register(ION_USECOUNT_TRIGGER, "ion.usecount.trigger") \ - Register(ION_ENABLE, "ion.enable") \ - Register(BASELINE_ENABLE, "baseline.enable") +#define JIT_COMPILER_OPTIONS(Register) \ + Register(BASELINE_USECOUNT_TRIGGER, "baseline.usecount.trigger") \ + Register(ION_USECOUNT_TRIGGER, "ion.usecount.trigger") \ + Register(ION_ENABLE, "ion.enable") \ + Register(BASELINE_ENABLE, "baseline.enable") \ + Register(OFFTHREAD_COMPILATION_ENABLE, "offthread-compilation.enable") \ + Register(SIGNALS_ENABLE, "signals.enable") typedef enum JSJitCompilerOption { #define JIT_COMPILER_DECLARE(key, str) \ @@ -4558,7 +4940,9 @@ typedef enum JSJitCompilerOption { } JSJitCompilerOption; extern JS_PUBLIC_API(void) -JS_SetGlobalJitCompilerOption(JSContext *cx, JSJitCompilerOption opt, uint32_t value); +JS_SetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt, uint32_t value); +extern JS_PUBLIC_API(int) +JS_GetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt); /* * Convert a uint32_t index into a jsid. @@ -4580,13 +4964,80 @@ JS_CharsToId(JSContext* cx, JS::TwoByteChars chars, JS::MutableHandleId); extern JS_PUBLIC_API(bool) JS_IsIdentifier(JSContext *cx, JS::HandleString str, bool *isIdentifier); +namespace JS { + +/* + * AutoFilename encapsulates a pointer to a C-string and keeps the C-string + * alive for as long as the associated AutoFilename object is alive. + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(AutoFilename) +{ + void *scriptSource_; + + AutoFilename(const AutoFilename &) MOZ_DELETE; + void operator=(const AutoFilename &) MOZ_DELETE; + + public: + AutoFilename() : scriptSource_(nullptr) {} + ~AutoFilename() { reset(nullptr); } + + const char *get() const; + + void reset(void *newScriptSource); +}; + /* - * Return the current script and line number of the most currently running + * Return the current filename and line number of the most currently running * frame. Returns true if a scripted frame was found, false otherwise. + * + * If a the embedding has hidden the scripted caller for the topmost activation + * record, this will also return false. */ extern JS_PUBLIC_API(bool) -JS_DescribeScriptedCaller(JSContext *cx, JS::MutableHandleScript script, unsigned *lineno); +DescribeScriptedCaller(JSContext *cx, AutoFilename *filename = nullptr, + unsigned *lineno = nullptr); +extern JS_PUBLIC_API(JSObject *) +GetScriptedCallerGlobal(JSContext *cx); + +/* + * Informs the JS engine that the scripted caller should be hidden. This can be + * used by the embedding to maintain an override of the scripted caller in its + * calculations, by hiding the scripted caller in the JS engine and pushing data + * onto a separate stack, which it inspects when DescribeScriptedCaller returns + * null. + * + * We maintain a counter on each activation record. Add() increments the counter + * of the topmost activation, and Remove() decrements it. The count may never + * drop below zero, and must always be exactly zero when the activation is + * popped from the stack. + */ +extern JS_PUBLIC_API(void) +HideScriptedCaller(JSContext *cx); + +extern JS_PUBLIC_API(void) +UnhideScriptedCaller(JSContext *cx); + +class AutoHideScriptedCaller +{ + public: + explicit AutoHideScriptedCaller(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mContext(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + HideScriptedCaller(mContext); + } + ~AutoHideScriptedCaller() { + UnhideScriptedCaller(mContext); + } + + protected: + JSContext *mContext; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +} /* namespace JS */ /* * Encode/Decode interpreted scripts and functions to/from memory. @@ -4599,12 +5050,11 @@ extern JS_PUBLIC_API(void *) JS_EncodeInterpretedFunction(JSContext *cx, JS::HandleObject funobj, uint32_t *lengthp); extern JS_PUBLIC_API(JSScript *) -JS_DecodeScript(JSContext *cx, const void *data, uint32_t length, - JSPrincipals *principals, JSPrincipals *originPrincipals); +JS_DecodeScript(JSContext *cx, const void *data, uint32_t length, JSPrincipals *originPrincipals); extern JS_PUBLIC_API(JSObject *) JS_DecodeInterpretedFunction(JSContext *cx, const void *data, uint32_t length, - JSPrincipals *principals, JSPrincipals *originPrincipals); + JSPrincipals *originPrincipals); namespace JS { @@ -4621,8 +5071,7 @@ typedef bool (* OpenAsmJSCacheEntryForReadOp)(HandleObject global, const jschar *begin, const jschar *limit, size_t *size, const uint8_t **memory, intptr_t *handle); typedef void -(* CloseAsmJSCacheEntryForReadOp)(HandleObject global, size_t size, const uint8_t *memory, - intptr_t handle); +(* CloseAsmJSCacheEntryForReadOp)(size_t size, const uint8_t *memory, intptr_t handle); /* * This callback represents a request by the JS engine to open for writing a @@ -4632,21 +5081,30 @@ typedef void * outparams. If the callback returns 'true', the JS engine guarantees a call * to CloseAsmJSCacheEntryForWriteOp passing the same base address, size and * handle. + * + * If 'installed' is true, then the cache entry is associated with a permanently + * installed JS file (e.g., in a packaged webapp). This information allows the + * embedding to store the cache entry in a installed location associated with + * the principal of 'global' where it will not be evicted until the associated + * installed JS file is removed. */ typedef bool -(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, const jschar *begin, const jschar *end, +(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, bool installed, + const jschar *begin, const jschar *end, size_t size, uint8_t **memory, intptr_t *handle); typedef void -(* CloseAsmJSCacheEntryForWriteOp)(HandleObject global, size_t size, uint8_t *memory, - intptr_t handle); +(* CloseAsmJSCacheEntryForWriteOp)(size_t size, uint8_t *memory, intptr_t handle); + +typedef js::Vector BuildIdCharVector; // Return the buildId (represented as a sequence of characters) associated with // the currently-executing build. If the JS engine is embedded such that a // single cache entry can be observed by different compiled versions of the JS // engine, it is critical that the buildId shall change for each new build of // the JS engine. + typedef bool -(* BuildIdOp)(js::Vector *buildId); +(* BuildIdOp)(BuildIdCharVector *buildId); struct AsmJSCacheOps { @@ -4660,6 +5118,132 @@ struct AsmJSCacheOps extern JS_PUBLIC_API(void) SetAsmJSCacheOps(JSRuntime *rt, const AsmJSCacheOps *callbacks); +/* + * Convenience class for imitating a JS level for-of loop. Typical usage: + * + * ForOfIterator it(cx); + * if (!it.init(iterable)) + * return false; + * RootedValue val(cx); + * while (true) { + * bool done; + * if (!it.next(&val, &done)) + * return false; + * if (done) + * break; + * if (!DoStuff(cx, val)) + * return false; + * } + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(ForOfIterator) { + protected: + JSContext *cx_; + /* + * Use the ForOfPIC on the global object (see vm/GlobalObject.h) to try + * to optimize iteration across arrays. + * + * Case 1: Regular Iteration + * iterator - pointer to the iterator object. + * index - fixed to NOT_ARRAY (== UINT32_MAX) + * + * Case 2: Optimized Array Iteration + * iterator - pointer to the array object. + * index - current position in array. + * + * The cases are distinguished by whether or not |index| is equal to NOT_ARRAY. + */ + JS::RootedObject iterator; + uint32_t index; + + static const uint32_t NOT_ARRAY = UINT32_MAX; + + ForOfIterator(const ForOfIterator &) MOZ_DELETE; + ForOfIterator &operator=(const ForOfIterator &) MOZ_DELETE; + + public: + explicit ForOfIterator(JSContext *cx) : cx_(cx), iterator(cx_), index(NOT_ARRAY) { } + + enum NonIterableBehavior { + ThrowOnNonIterable, + AllowNonIterable + }; + + /* + * Initialize the iterator. If AllowNonIterable is passed then if iterable + * does not have a callable @@iterator init() will just return true instead + * of throwing. Callers should then check valueIsIterable() before + * continuing with the iteration. + */ + bool init(JS::HandleValue iterable, + NonIterableBehavior nonIterableBehavior = ThrowOnNonIterable); + + /* + * This method assumes that |iterator| is already an iterator. It will not + * check for, and call @@iterator. Callers should make sure that the passed + * in value is in fact an iterator. + */ + bool initWithIterator(JS::HandleValue aIterator); + + /* + * Get the next value from the iterator. If false *done is true + * after this call, do not examine val. + */ + bool next(JS::MutableHandleValue val, bool *done); + + /* + * If initialized with throwOnNonCallable = false, check whether + * the value is iterable. + */ + bool valueIsIterable() const { + return iterator; + } + + private: + inline bool nextFromOptimizedArray(MutableHandleValue val, bool *done); + bool materializeArrayIterator(); +}; + + +/* + * If a large allocation fails, the JS engine may call the large-allocation- + * failure callback, if set, to allow the embedding to flush caches, possibly + * perform shrinking GCs, etc. to make some room so that the allocation will + * succeed if retried. After the callback returns, the JS engine will try to + * allocate again and may be succesful. + */ + +typedef void +(* LargeAllocationFailureCallback)(void *data); + +extern JS_PUBLIC_API(void) +SetLargeAllocationFailureCallback(JSRuntime *rt, LargeAllocationFailureCallback afc, void *data); + +/* + * Unlike the error reporter, which is only called if the exception for an OOM + * bubbles up and is not caught, the OutOfMemoryCallback is called immediately + * at the OOM site to allow the embedding to capture the current state of heap + * allocation before anything is freed. If the large-allocation-failure callback + * is called at all (not all allocation sites call the large-allocation-failure + * callback on failure), it is called before the out-of-memory callback; the + * out-of-memory callback is only called if the allocation still fails after the + * large-allocation-failure callback has returned. + */ + +typedef void +(* OutOfMemoryCallback)(JSContext *cx, void *data); + +extern JS_PUBLIC_API(void) +SetOutOfMemoryCallback(JSRuntime *rt, OutOfMemoryCallback cb, void *data); + + +/* + * Capture the current call stack as a chain of SavedFrame objects, and set + * |stackp| to the SavedFrame for the newest stack frame. If |maxFrameCount| is + * non-zero, capture at most the youngest |maxFrameCount| frames. + */ +extern JS_PUBLIC_API(bool) +CaptureCurrentStack(JSContext *cx, MutableHandleObject stackp, unsigned maxFrameCount = 0); + } /* namespace JS */ #endif /* jsapi_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/jscpucfg.h b/frameworks/js-bindings/external/spidermonkey/include/ios/jscpucfg.h index e545d8329d..a7a00613bb 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/jscpucfg.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/jscpucfg.h @@ -18,7 +18,7 @@ # error "CPU type is unknown" # endif /* !(defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)) */ -#elif defined(_WIN32) || defined(XP_OS2) +#elif defined(_WIN32) # ifdef __WATCOMC__ # define HAVE_VA_LIST_AS_ARRAY 1 @@ -27,7 +27,7 @@ # define IS_LITTLE_ENDIAN 1 # undef IS_BIG_ENDIAN -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) # if __LITTLE_ENDIAN__ # define IS_LITTLE_ENDIAN 1 # undef IS_BIG_ENDIAN @@ -89,8 +89,7 @@ # endif #elif defined(__sparc) || defined(__sparc__) || \ - defined(_POWER) || defined(__powerpc__) || \ - defined(__ppc__) || defined(__hppa) || \ + defined(_POWER) || defined(__hppa) || \ defined(_MIPSEB) || defined(_BIG_ENDIAN) /* IA64 running HP-UX will have _BIG_ENDIAN defined. * IA64 running Linux will have endian.h and be handled above. diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/jsfriendapi.h b/frameworks/js-bindings/external/spidermonkey/include/ios/jsfriendapi.h index eb05652a5b..674999eb62 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/jsfriendapi.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/jsfriendapi.h @@ -7,8 +7,12 @@ #ifndef jsfriendapi_h #define jsfriendapi_h +#include "mozilla/Casting.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/TypedEnum.h" +#include "mozilla/UniquePtr.h" +#include "jsapi.h" // For JSAutoByteString. See bug 1033916. #include "jsbytecode.h" #include "jspubtd.h" @@ -19,14 +23,20 @@ /* * This macro checks if the stack pointer has exceeded a given limit. If * |tolerance| is non-zero, it returns true only if the stack pointer has - * exceeded the limit by more than |tolerance| bytes. + * exceeded the limit by more than |tolerance| bytes. The WITH_INTOLERANCE + * versions use a negative tolerance (i.e., the limit is reduced by + * |intolerance| bytes). */ #if JS_STACK_GROWTH_DIRECTION > 0 # define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ ((uintptr_t)(sp) < (limit)+(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) < (limit)-(intolerance)) #else # define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ ((uintptr_t)(sp) > (limit)-(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) > (limit)+(intolerance)) #endif #define JS_CHECK_STACK_SIZE(limit, lval) JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, lval, 0) @@ -35,33 +45,35 @@ class JSAtom; struct JSErrorFormatString; class JSLinearString; struct JSJitInfo; -class JSErrorReport; +struct JSErrorReport; namespace JS { template class Heap; } /* namespace JS */ +namespace js { +class JS_FRIEND_API(BaseProxyHandler); +} /* namespace js */ + extern JS_FRIEND_API(void) JS_SetGrayGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); extern JS_FRIEND_API(JSString *) JS_GetAnonymousString(JSRuntime *rt); -extern JS_FRIEND_API(void) -JS_SetIsWorkerRuntime(JSRuntime *rt); - extern JS_FRIEND_API(JSObject *) -JS_FindCompilationScope(JSContext *cx, JSObject *obj); +JS_FindCompilationScope(JSContext *cx, JS::HandleObject obj); extern JS_FRIEND_API(JSFunction *) JS_GetObjectFunction(JSObject *obj); extern JS_FRIEND_API(bool) -JS_SplicePrototype(JSContext *cx, JSObject *obj, JSObject *proto); +JS_SplicePrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); extern JS_FRIEND_API(JSObject *) -JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JSObject *proto, JSObject *parent); +JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JS::HandleObject proto, + JS::HandleObject parent); extern JS_FRIEND_API(uint32_t) JS_ObjectCountDynamicSlots(JS::HandleObject obj); @@ -73,7 +85,7 @@ extern JS_FRIEND_API(size_t) JS_GetCustomIteratorCount(JSContext *cx); extern JS_FRIEND_API(bool) -JS_NondeterministicGetWeakMapKeys(JSContext *cx, JSObject *obj, JSObject **ret); +JS_NondeterministicGetWeakMapKeys(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject ret); /* * Determine whether the given object is backed by a DeadObjectProxy. @@ -122,16 +134,23 @@ JS_GetCompartmentPrincipals(JSCompartment *compartment); extern JS_FRIEND_API(void) JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals); +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptPrincipals(JSScript *script); + +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptOriginPrincipals(JSScript *script); + /* Safe to call with input obj == nullptr. Returns non-nullptr iff obj != nullptr. */ extern JS_FRIEND_API(JSObject *) -JS_ObjectToInnerObject(JSContext *cx, JSObject *obj); +JS_ObjectToInnerObject(JSContext *cx, JS::HandleObject obj); /* Requires obj != nullptr. */ extern JS_FRIEND_API(JSObject *) -JS_ObjectToOuterObject(JSContext *cx, JSObject *obj); +JS_ObjectToOuterObject(JSContext *cx, JS::HandleObject obj); extern JS_FRIEND_API(JSObject *) -JS_CloneObject(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent); +JS_CloneObject(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto, + JS::HandleObject parent); extern JS_FRIEND_API(JSString *) JS_BasicObjectToString(JSContext *cx, JS::HandleObject obj); @@ -149,13 +168,17 @@ js_ObjectClassIs(JSContext *cx, JS::HandleObject obj, js::ESClassValue classValu JS_FRIEND_API(const char *) js_ObjectClassName(JSContext *cx, JS::HandleObject obj); +namespace js { + JS_FRIEND_API(bool) -js_AddObjectRoot(JSRuntime *rt, JSObject **objp); +AddRawValueRoot(JSContext *cx, JS::Value *vp, const char *name); JS_FRIEND_API(void) -js_RemoveObjectRoot(JSRuntime *rt, JSObject **objp); +RemoveRawValueRoot(JSContext *cx, JS::Value *vp); -#ifdef DEBUG +} /* namespace js */ + +#ifdef JS_DEBUG /* * Routines to print out values during debugging. These are FRIEND_API to help @@ -184,7 +207,7 @@ js_DumpChars(const jschar *s, size_t n); * restrictions on the compartment of |cx|. */ extern JS_FRIEND_API(bool) -JS_CopyPropertiesFrom(JSContext *cx, JSObject *target, JSObject *obj); +JS_CopyPropertiesFrom(JSContext *cx, JS::HandleObject target, JS::HandleObject obj); /* * Single-property version of the above. This function asserts that an |own| @@ -221,20 +244,164 @@ struct JSFunctionSpecWithHelp { {nullptr, nullptr, 0, 0, nullptr, nullptr} extern JS_FRIEND_API(bool) -JS_DefineFunctionsWithHelp(JSContext *cx, JSObject *obj, const JSFunctionSpecWithHelp *fs); +JS_DefineFunctionsWithHelp(JSContext *cx, JS::HandleObject obj, const JSFunctionSpecWithHelp *fs); namespace js { +/* + * Helper Macros for creating JSClasses that function as proxies. + * + * NB: The macro invocation must be surrounded by braces, so as to + * allow for potention JSClass extensions. + */ +#define PROXY_MAKE_EXT(outerObject, innerObject, iteratorObject, \ + isWrappedNative) \ + { \ + outerObject, \ + innerObject, \ + iteratorObject, \ + isWrappedNative, \ + js::proxy_WeakmapKeyDelegate \ + } + +#define PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, ext) \ + { \ + name, \ + js::Class::NON_NATIVE | \ + JSCLASS_IS_PROXY | \ + JSCLASS_IMPLEMENTS_BARRIERS | \ + JSCLASS_HAS_RESERVED_SLOTS(js::PROXY_MINIMUM_SLOTS + (extraSlots)) | \ + flags, \ + JS_PropertyStub, /* addProperty */ \ + JS_DeletePropertyStub, /* delProperty */ \ + JS_PropertyStub, /* getProperty */ \ + JS_StrictPropertyStub, /* setProperty */ \ + JS_EnumerateStub, \ + JS_ResolveStub, \ + js::proxy_Convert, \ + js::proxy_Finalize, /* finalize */ \ + callOp, /* call */ \ + js::proxy_HasInstance, /* hasInstance */ \ + constructOp, /* construct */ \ + js::proxy_Trace, /* trace */ \ + JS_NULL_CLASS_SPEC, \ + ext, \ + { \ + js::proxy_LookupGeneric, \ + js::proxy_LookupProperty, \ + js::proxy_LookupElement, \ + js::proxy_DefineGeneric, \ + js::proxy_DefineProperty, \ + js::proxy_DefineElement, \ + js::proxy_GetGeneric, \ + js::proxy_GetProperty, \ + js::proxy_GetElement, \ + js::proxy_SetGeneric, \ + js::proxy_SetProperty, \ + js::proxy_SetElement, \ + js::proxy_GetGenericAttributes, \ + js::proxy_SetGenericAttributes, \ + js::proxy_DeleteGeneric, \ + js::proxy_Watch, js::proxy_Unwatch, \ + js::proxy_Slice, \ + nullptr, /* enumerate */ \ + nullptr, /* thisObject */ \ + } \ + } + +#define PROXY_CLASS_DEF(name, extraSlots, flags, callOp, constructOp) \ + PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, \ + PROXY_MAKE_EXT( \ + nullptr, /* outerObject */ \ + nullptr, /* innerObject */ \ + nullptr, /* iteratorObject */ \ + false /* isWrappedNative */ \ + )) + +/* + * Proxy stubs, similar to JS_*Stub, for embedder proxy class definitions. + * + * NB: Should not be called directly. + */ + +extern JS_FRIEND_API(bool) +proxy_LookupGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleObject objp, JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_DefineGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, + unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_GetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetProperty(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, + JS::Handle name, JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetElement(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_SetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp, + bool strict); +extern JS_FRIEND_API(bool) +proxy_GetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_SetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_DeleteGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); + +extern JS_FRIEND_API(void) +proxy_Trace(JSTracer *trc, JSObject *obj); +extern JS_FRIEND_API(JSObject *) +proxy_WeakmapKeyDelegate(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Convert(JSContext *cx, JS::HandleObject proxy, JSType hint, JS::MutableHandleValue vp); +extern JS_FRIEND_API(void) +proxy_Finalize(FreeOp *fop, JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_HasInstance(JSContext *cx, JS::HandleObject proxy, JS::MutableHandleValue v, bool *bp); +extern JS_FRIEND_API(bool) +proxy_Call(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(bool) +proxy_Construct(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(JSObject *) +proxy_innerObject(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Watch(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); +extern JS_FRIEND_API(bool) +proxy_Unwatch(JSContext *cx, JS::HandleObject obj, JS::HandleId id); +extern JS_FRIEND_API(bool) +proxy_Slice(JSContext *cx, JS::HandleObject proxy, uint32_t begin, uint32_t end, + JS::HandleObject result); + /* * A class of objects that return source code on demand. * - * When code is compiled with CompileOptions::LAZY_SOURCE, SpiderMonkey - * doesn't retain the source code (and doesn't do lazy bytecode - * generation). If we ever need the source code, say, in response to a call - * to Function.prototype.toSource or Debugger.Source.prototype.text, then - * we call the 'load' member function of the instance of this class that - * has hopefully been registered with the runtime, passing the code's URL, - * and hope that it will be able to find the source. + * When code is compiled with setSourceIsLazy(true), SpiderMonkey doesn't + * retain the source code (and doesn't do lazy bytecode generation). If we ever + * need the source code, say, in response to a call to Function.prototype. + * toSource or Debugger.Source.prototype.text, then we call the 'load' member + * function of the instance of this class that has hopefully been registered + * with the runtime, passing the code's URL, and hope that it will be able to + * find the source. */ class SourceHook { public: @@ -249,18 +416,25 @@ class SourceHook { }; /* - * Have |rt| use |hook| to retrieve LAZY_SOURCE source code. See the + * Have |rt| use |hook| to retrieve lazily-retrieved source code. See the * comments for SourceHook. The runtime takes ownership of the hook, and * will delete it when the runtime itself is deleted, or when a new hook is * set. */ extern JS_FRIEND_API(void) -SetSourceHook(JSRuntime *rt, SourceHook *hook); +SetSourceHook(JSRuntime *rt, mozilla::UniquePtr hook); /* Remove |rt|'s source hook, and return it. The caller now owns the hook. */ -extern JS_FRIEND_API(SourceHook *) +extern JS_FRIEND_API(mozilla::UniquePtr) ForgetSourceHook(JSRuntime *rt); +#ifdef NIGHTLY_BUILD +typedef void (*AssertOnScriptEntryHook)(JSContext *cx, JS::HandleScript script); + +extern JS_FRIEND_API(void) +SetAssertOnScriptEntryHook(JSRuntime *rt, AssertOnScriptEntryHook hook); +#endif + extern JS_FRIEND_API(JS::Zone *) GetCompartmentZone(JSCompartment *comp); @@ -293,16 +467,6 @@ IsSystemZone(JS::Zone *zone); extern JS_FRIEND_API(bool) IsAtomsCompartment(JSCompartment *comp); -/* - * Check whether it is OK to assign an undeclared variable with the name - * |propname| at the current location in script. It is not an error if there is - * no current script location, or if that location is not an assignment to an - * undeclared variable. Reports an error if one needs to be reported (and, - * particularly, always reports when it returns false). - */ -extern JS_FRIEND_API(bool) -ReportIfUndeclaredVarAssignment(JSContext *cx, JS::HandleString propname); - /* * Returns whether we're in a non-strict property set (in that we're in a * non-strict script and the bytecode we're on is a property set). The return @@ -339,6 +503,9 @@ TraceWeakMaps(WeakMapTracer *trc); extern JS_FRIEND_API(bool) AreGCGrayBitsValid(JSRuntime *rt); +extern JS_FRIEND_API(bool) +ZoneGlobalsAreAllGray(JS::Zone *zone); + typedef void (*GCThingCallback)(void *closure, void *gcthing); @@ -379,7 +546,7 @@ struct TypeObject { }; struct BaseShape { - const js::Class *clasp; + const js::Class *clasp_; JSObject *parent; JSObject *_1; JSCompartment *compartment; @@ -427,10 +594,20 @@ struct Function { void *_1; }; -struct Atom { - static const size_t LENGTH_SHIFT = 4; - size_t lengthAndFlags; - const jschar *chars; +struct String +{ + static const uint32_t INLINE_CHARS_BIT = JS_BIT(2); + static const uint32_t LATIN1_CHARS_BIT = JS_BIT(6); + static const uint32_t ROPE_FLAGS = 0; + static const uint32_t TYPE_FLAGS_MASK = JS_BIT(6) - 1; + uint32_t flags; + uint32_t length; + union { + const JS::Latin1Char *nonInlineCharsLatin1; + const jschar *nonInlineCharsTwoByte; + JS::Latin1Char inlineStorageLatin1[1]; + jschar inlineStorageTwoByte[1]; + }; }; } /* namespace shadow */ @@ -451,6 +628,46 @@ GetObjectJSClass(JSObject *obj) return js::Jsvalify(GetObjectClass(obj)); } +JS_FRIEND_API(const Class *) +ProtoKeyToClass(JSProtoKey key); + +// Returns true if the standard class identified by |key| inherits from +// another standard class with the same js::Class. This basically means +// that the various properties described by our js::Class are intended +// to live higher up on the proto chain. +// +// In practice, this only returns true for Error subtypes. +inline bool +StandardClassIsDependent(JSProtoKey key) +{ + JSProtoKey keyFromClass = JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + MOZ_ASSERT(keyFromClass); + return key != keyFromClass; +} + +// Returns the key for the class inherited by a given standard class (that +// is to say, the prototype of this standard class's prototype). +// +// You must be sure that this corresponds to a standard class with a cached +// JSProtoKey before calling this function. In general |key| will match the +// cached proto key, except in cases where multiple JSProtoKeys share a +// JSClass. +inline JSProtoKey +ParentKeyForStandardClass(JSProtoKey key) +{ + // [Object] has nothing to inherit from. + if (key == JSProto_Object) + return JSProto_Null; + + // If we're dependent (i.e. an Error subtype), return the key of the class + // we depend on. + if (StandardClassIsDependent(key)) + return JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + + // Otherwise, we inherit [Object]. + return JSProto_Object; +} + inline bool IsInnerObject(JSObject *obj) { return !!GetObjectClass(obj)->ext.outerObject; @@ -477,7 +694,7 @@ GetObjectParent(JSObject *obj) return reinterpret_cast(obj)->shape->base->parent; } -static JS_ALWAYS_INLINE JSCompartment * +static MOZ_ALWAYS_INLINE JSCompartment * GetObjectCompartment(JSObject *obj) { return reinterpret_cast(obj)->shape->base->compartment; @@ -489,10 +706,15 @@ GetObjectParentMaybeScope(JSObject *obj); JS_FRIEND_API(JSObject *) GetGlobalForObjectCrossCompartment(JSObject *obj); +// Sidestep the activeContext checking implicitly performed in +// JS_SetPendingException. +JS_FRIEND_API(void) +SetPendingExceptionCrossContext(JSContext *cx, JS::HandleValue v); + JS_FRIEND_API(void) AssertSameCompartment(JSContext *cx, JSObject *obj); -#ifdef DEBUG +#ifdef JS_DEBUG JS_FRIEND_API(void) AssertSameCompartment(JSObject *objA, JSObject *objB); #else @@ -509,9 +731,6 @@ SetDefaultObjectForContext(JSContext *cx, JSObject *obj); JS_FRIEND_API(void) NotifyAnimationActivity(JSObject *obj); -JS_FRIEND_API(bool) -IsOriginalScriptFunction(JSFunction *fun); - /* * Return the outermost enclosing function (script) of the scripted caller. * This function returns nullptr in several cases: @@ -521,7 +740,7 @@ IsOriginalScriptFunction(JSFunction *fun); * thus it will really return the outermost enclosing function *since the * innermost eval*. */ -JS_FRIEND_API(JSScript *) +JS_FRIEND_API(JSFunction *) GetOutermostEnclosingFunctionOfScriptedCaller(JSContext *cx); JS_FRIEND_API(JSFunction *) @@ -536,12 +755,6 @@ JS_FRIEND_API(JSFunction *) NewFunctionByIdWithReserved(JSContext *cx, JSNative native, unsigned nargs, unsigned flags, JSObject *parent, jsid id); -JS_FRIEND_API(JSObject *) -InitClassWithReserved(JSContext *cx, JSObject *obj, JSObject *parent_proto, - const JSClass *clasp, JSNative constructor, unsigned nargs, - const JSPropertySpec *ps, const JSFunctionSpec *fs, - const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs); - JS_FRIEND_API(const JS::Value &) GetFunctionNativeReserved(JSObject *fun, size_t which); @@ -549,7 +762,7 @@ JS_FRIEND_API(void) SetFunctionNativeReserved(JSObject *fun, size_t which, const JS::Value &val); JS_FRIEND_API(bool) -GetObjectProto(JSContext *cx, JS::Handle obj, JS::MutableHandle proto); +GetObjectProto(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject proto); JS_FRIEND_API(bool) GetOriginalEval(JSContext *cx, JS::HandleObject scope, @@ -604,25 +817,142 @@ GetObjectSlot(JSObject *obj, size_t slot) return reinterpret_cast(obj)->slotRef(slot); } -inline const jschar * -GetAtomChars(JSAtom *atom) +MOZ_ALWAYS_INLINE size_t +GetAtomLength(JSAtom *atom) { - return reinterpret_cast(atom)->chars; + return reinterpret_cast(atom)->length; } -inline size_t -GetAtomLength(JSAtom *atom) +static const uint32_t MaxStringLength = (1 << 28) - 1; + +MOZ_ALWAYS_INLINE size_t +GetStringLength(JSString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetFlatStringLength(JSFlatString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetLinearStringLength(JSLinearString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE bool +LinearStringHasLatin1Chars(JSLinearString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE bool +AtomHasLatin1Chars(JSAtom *atom) { - using shadow::Atom; - return reinterpret_cast(atom)->lengthAndFlags >> Atom::LENGTH_SHIFT; + return reinterpret_cast(atom)->flags & shadow::String::LATIN1_CHARS_BIT; } -inline JSLinearString * +MOZ_ALWAYS_INLINE bool +StringHasLatin1Chars(JSString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1LinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageLatin1; + return s->nonInlineCharsLatin1; +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteLinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(!LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageTwoByte; + return s->nonInlineCharsTwoByte; +} + +MOZ_ALWAYS_INLINE JSLinearString * AtomToLinearString(JSAtom *atom) { return reinterpret_cast(atom); } +MOZ_ALWAYS_INLINE JSLinearString * +FlatStringToLinearString(JSFlatString *s) +{ + return reinterpret_cast(s); +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1AtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetLatin1LinearStringChars(nogc, AtomToLinearString(atom)); +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteAtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetTwoByteLinearStringChars(nogc, AtomToLinearString(atom)); +} + +JS_FRIEND_API(JSLinearString *) +StringToLinearStringSlow(JSContext *cx, JSString *str); + +MOZ_ALWAYS_INLINE JSLinearString * +StringToLinearString(JSContext *cx, JSString *str) +{ + using shadow::String; + String *s = reinterpret_cast(str); + if (MOZ_UNLIKELY((s->flags & String::TYPE_FLAGS_MASK) == String::ROPE_FLAGS)) + return StringToLinearStringSlow(cx, str); + return reinterpret_cast(str); +} + +MOZ_ALWAYS_INLINE void +CopyLinearStringChars(jschar *dest, JSLinearString *s, size_t len) +{ + JS::AutoCheckCannotGC nogc; + if (LinearStringHasLatin1Chars(s)) { + const JS::Latin1Char *src = GetLatin1LinearStringChars(nogc, s); + for (size_t i = 0; i < len; i++) + dest[i] = src[i]; + } else { + const jschar *src = GetTwoByteLinearStringChars(nogc, s); + mozilla::PodCopy(dest, src, len); + } +} + +inline bool +CopyStringChars(JSContext *cx, jschar *dest, JSString *s, size_t len) +{ + JSLinearString *linear = StringToLinearString(cx, s); + if (!linear) + return false; + + CopyLinearStringChars(dest, linear, len); + return true; +} + +inline void +CopyFlatStringChars(jschar *dest, JSFlatString *s, size_t len) +{ + CopyLinearStringChars(dest, FlatStringToLinearString(s), len); +} + JS_FRIEND_API(bool) GetPropertyNames(JSContext *cx, JSObject *obj, unsigned flags, JS::AutoIdVector *props); @@ -641,24 +971,18 @@ SetPreserveWrapperCallback(JSRuntime *rt, PreserveWrapperCallback callback); JS_FRIEND_API(bool) IsObjectInContextCompartment(JSObject *obj, const JSContext *cx); -/* - * ErrorFromException takes a raw Value so that it's possible to call it during - * GC/CC/whatever, when it may not be possible to get a JSContext to create a - * Rooted. It promises to never ever GC. - */ -JS_FRIEND_API(JSErrorReport*) -ErrorFromException(JS::Value val); - /* * NB: these flag bits are encoded into the bytecode stream in the immediate * operand of JSOP_ITER, so don't change them without advancing vm/Xdr.h's * XDR_BYTECODE_VERSION. */ #define JSITER_ENUMERATE 0x1 /* for-in compatible hidden default iterator */ -#define JSITER_FOREACH 0x2 /* return [key, value] pair rather than key */ -#define JSITER_KEYVALUE 0x4 /* destructuring for-in wants [key, value] */ +#define JSITER_FOREACH 0x2 /* get obj[key] for each property */ +#define JSITER_KEYVALUE 0x4 /* obsolete destructuring for-in wants [key, value] */ #define JSITER_OWNONLY 0x8 /* iterate over obj's own properties only */ #define JSITER_HIDDEN 0x10 /* also enumerate non-enumerable properties */ +#define JSITER_SYMBOLS 0x20 /* also include symbol property keys */ +#define JSITER_SYMBOLSONLY 0x40 /* exclude string property keys */ JS_FRIEND_API(bool) RunningWithTrustedPrincipals(JSContext *cx); @@ -677,6 +1001,7 @@ GetNativeStackLimit(JSContext *cx) * These macros report a stack overflow and run |onerror| if we are close to * using up the C stack. The JS_CHECK_CHROME_RECURSION variant gives us a little * extra space so that we can ensure that crucial code is able to run. + * JS_CHECK_RECURSION_CONSERVATIVE gives us a little less space. */ #define JS_CHECK_RECURSION(cx, onerror) \ @@ -723,6 +1048,18 @@ GetNativeStackLimit(JSContext *cx) } \ JS_END_MACRO +#define JS_CHECK_RECURSION_CONSERVATIVE(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(js::GetNativeStackLimit(cx), \ + &stackDummy_, \ + 1024 * sizeof(size_t))) \ + { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + JS_FRIEND_API(void) StartPCCountProfiling(JSContext *cx); @@ -764,9 +1101,10 @@ extern JS_FRIEND_API(bool) IsContextRunningJS(JSContext *cx); typedef bool -(* DOMInstanceClassMatchesProto)(JSObject *protoObject, uint32_t protoID, uint32_t depth); +(* DOMInstanceClassHasProtoAtDepth)(const Class *instanceClass, + uint32_t protoID, uint32_t depth); struct JSDOMCallbacks { - DOMInstanceClassMatchesProto instanceClassMatchesProto; + DOMInstanceClassHasProtoAtDepth instanceClassMatchesProto; }; typedef struct JSDOMCallbacks DOMCallbacks; @@ -796,10 +1134,10 @@ CastToJSFreeOp(FreeOp *fop) * Get an error type name from a JSExnType constant. * Returns nullptr for invalid arguments and JSEXN_INTERNALERR */ -extern JS_FRIEND_API(const jschar*) -GetErrorTypeName(JSRuntime* rt, int16_t exnType); +extern JS_FRIEND_API(JSFlatString *) +GetErrorTypeName(JSRuntime *rt, int16_t exnType); -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_FRIEND_API(unsigned) GetEnterCompartmentDepth(JSContext* cx); #endif @@ -836,13 +1174,13 @@ struct ChromeCompartmentsOnly : public CompartmentFilter { struct SingleCompartment : public CompartmentFilter { JSCompartment *ours; - SingleCompartment(JSCompartment *c) : ours(c) {} + explicit SingleCompartment(JSCompartment *c) : ours(c) {} virtual bool match(JSCompartment *c) const { return c == ours; } }; struct CompartmentsWithPrincipals : public CompartmentFilter { JSPrincipals *principals; - CompartmentsWithPrincipals(JSPrincipals *p) : principals(p) {} + explicit CompartmentsWithPrincipals(JSPrincipals *p) : principals(p) {} virtual bool match(JSCompartment *c) const { return JS_GetCompartmentPrincipals(c) == principals; } @@ -941,49 +1279,198 @@ typedef enum JSErrNum { } JSErrNum; extern JS_FRIEND_API(const JSErrorFormatString *) -js_GetErrorMessage(void *userRef, const char *locale, const unsigned errorNumber); +js_GetErrorMessage(void *userRef, const unsigned errorNumber); + +namespace js { + +// AutoStableStringChars is here so we can use it in ErrorReport. It +// should get moved out of here if we can manage it. See bug 1040316. + +/* + * This class provides safe access to a string's chars across a GC. Once + * we allocate strings and chars in the nursery (bug 903519), this class + * will have to make a copy of the string's chars if they are allocated + * in the nursery, so it's best to avoid using this class unless you really + * need it. It's usually more efficient to use the latin1Chars/twoByteChars + * JSString methods and often the code can be rewritten so that only indexes + * instead of char pointers are used in parts of the code that can GC. + */ +class MOZ_STACK_CLASS AutoStableStringChars +{ + /* Ensure the string is kept alive while we're using its chars. */ + JS::RootedString s_; + union { + const jschar *twoByteChars_; + const JS::Latin1Char *latin1Chars_; + }; + enum State { Uninitialized, Latin1, TwoByte }; + State state_; + bool ownsChars_; + + public: + AutoStableStringChars(JSContext *cx) + : s_(cx), state_(Uninitialized), ownsChars_(false) + {}; + ~AutoStableStringChars(); + + bool init(JSContext *cx, JSString *s); + + /* Like init(), but Latin1 chars are inflated to TwoByte. */ + bool initTwoByte(JSContext *cx, JSString *s); + + bool isLatin1() const { return state_ == Latin1; } + bool isTwoByte() const { return state_ == TwoByte; } + + const jschar *twoByteChars() const { + MOZ_ASSERT(state_ == TwoByte); + return twoByteChars_; + } + + mozilla::Range latin1Range() const { + MOZ_ASSERT(state_ == Latin1); + return mozilla::Range(latin1Chars_, + GetStringLength(s_)); + } + + mozilla::Range twoByteRange() const { + MOZ_ASSERT(state_ == TwoByte); + return mozilla::Range(twoByteChars_, + GetStringLength(s_)); + } + + /* If we own the chars, transfer ownership to the caller. */ + bool maybeGiveOwnershipToCaller() { + MOZ_ASSERT(state_ != Uninitialized); + if (!ownsChars_) + return false; + state_ = Uninitialized; + ownsChars_ = false; + return true; + } + + private: + AutoStableStringChars(const AutoStableStringChars &other) MOZ_DELETE; + void operator=(const AutoStableStringChars &other) MOZ_DELETE; +}; + +// Creates a string of the form |ErrorType: ErrorMessage| for a JSErrorReport, +// which generally matches the toString() behavior of an ErrorObject. +extern JS_FRIEND_API(JSString *) +ErrorReportToString(JSContext *cx, JSErrorReport *reportp); + +struct MOZ_STACK_CLASS JS_FRIEND_API(ErrorReport) +{ + ErrorReport(JSContext *cx); + ~ErrorReport(); + + bool init(JSContext *cx, JS::HandleValue exn); + + JSErrorReport *report() + { + return reportp; + } + + const char *message() + { + return message_; + } + + private: + // More or less an equivalent of JS_ReportErrorNumber/js_ReportErrorNumberVA + // but fills in an ErrorReport instead of reporting it. Uses varargs to + // make it simpler to call js_ExpandErrorArguments. + void populateUncaughtExceptionReport(JSContext *cx, ...); + void populateUncaughtExceptionReportVA(JSContext *cx, va_list ap); + + // We may have a provided JSErrorReport, so need a way to represent that. + JSErrorReport *reportp; + + // And we may have a message. + const char *message_; + + // Or we may need to synthesize a JSErrorReport one of our own. + JSErrorReport ownedReport; + + // Or a message of our own. If this is non-null, we need to clean up both + // it and ownedReport. + char *ownedMessage; + + // And we have a string to maybe keep alive that has pointers into + // it from ownedReport. + JS::RootedString str; + + // And keep its chars alive too. + AutoStableStringChars strChars; + + // And we need to root our exception value. + JS::RootedObject exnObject; + + // And possibly some byte storage for our message_. + JSAutoByteString bytesStorage; + + // And for our filename. + JSAutoByteString filename; + + // True if we need to free message_ and the stuff in ownedReport + bool ownsMessageAndReport; +}; + +} /* namespace js */ + /* Implemented in jsclone.cpp. */ extern JS_FRIEND_API(uint64_t) js_GetSCOffset(JSStructuredCloneWriter* writer); -/* Typed Array functions, implemented in jstypedarray.cpp */ - namespace js { -namespace ArrayBufferView { - -enum ViewType { - TYPE_INT8 = 0, - TYPE_UINT8, - TYPE_INT16, - TYPE_UINT16, - TYPE_INT32, - TYPE_UINT32, - TYPE_FLOAT32, - TYPE_FLOAT64, +namespace Scalar { + +/* Scalar types which can appear in typed arrays and typed objects. */ +enum Type { + Int8 = 0, + Uint8, + Int16, + Uint16, + Int32, + Uint32, + Float32, + Float64, /* * Special type that is a uint8_t, but assignments are clamped to [0, 256). * Treat the raw data type as a uint8_t. */ - TYPE_UINT8_CLAMPED, + Uint8Clamped, - /* - * Type returned for a DataView. Note that there is no single element type - * in this case. - */ - TYPE_DATAVIEW, - - TYPE_MAX + TypeMax }; -} /* namespace ArrayBufferView */ +static inline size_t +byteSize(Type atype) +{ + switch (atype) { + case Int8: + case Uint8: + case Uint8Clamped: + return 1; + case Int16: + case Uint16: + return 2; + case Int32: + case Uint32: + case Float32: + return 4; + case Float64: + return 8; + default: + MOZ_CRASH("invalid scalar type"); + } +} +} /* namespace Scalar */ } /* namespace js */ -typedef js::ArrayBufferView::ViewType JSArrayBufferViewType; - /* * Create a new typed array with nelements elements. * @@ -1019,23 +1506,23 @@ JS_NewFloat64Array(JSContext *cx, uint32_t nelements); */ extern JS_FRIEND_API(JSObject *) -JS_NewInt8ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt8ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint8ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ClampedArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint8ClampedArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewInt16ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt16ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint16ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint16ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewInt32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewFloat32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewFloat32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewFloat64ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewFloat64ArrayFromArray(JSContext *cx, JS::HandleObject array); /* * Create a new typed array using the given ArrayBuffer for storage. The @@ -1044,31 +1531,31 @@ JS_NewFloat64ArrayFromArray(JSContext *cx, JSObject *array); */ extern JS_FRIEND_API(JSObject *) -JS_NewInt8ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewInt16ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint16ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewInt32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewFloat32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewFloat32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewFloat64ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewFloat64ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); /* @@ -1119,6 +1606,93 @@ JS_IsFloat32Array(JSObject *obj); extern JS_FRIEND_API(bool) JS_IsFloat64Array(JSObject *obj); +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +namespace js { + +extern JS_FRIEND_API(JSObject *) +UnwrapInt8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8ClampedArray(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat64Array(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBuffer(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBufferView(JSObject *obj); + +namespace detail { + +extern JS_FRIEND_DATA(const Class* const) Int8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ClampedArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float64ArrayClassPtr; + +const size_t TypedArrayLengthSlot = 1; + +} // namespace detail + +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +#define JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Type, type) \ +inline void \ +Get ## Type ## ArrayLengthAndData(JSObject *obj, uint32_t *length, type **data) \ +{ \ + JS_ASSERT(GetObjectClass(obj) == detail::Type ## ArrayClassPtr); \ + const JS::Value &slot = GetReservedSlot(obj, detail::TypedArrayLengthSlot); \ + *length = mozilla::SafeCast(slot.toInt32()); \ + *data = static_cast(GetObjectPrivate(obj)); \ +} + +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int8, int8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8Clamped, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int16, int16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint16, uint16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int32, int32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint32, uint32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float32, float) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float64, double) + +#undef JS_DEFINE_DATA_AND_LENGTH_ACCESSOR + +// This one isn't inlined because it's rather tricky (by dint of having to deal +// with a dozen-plus classes and varying slot layouts. +extern JS_FRIEND_API(void) +GetArrayBufferViewLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +// This one isn't inlined because there are a bunch of different ArrayBuffer +// classes that would have to be individually handled here. +extern JS_FRIEND_API(void) +GetArrayBufferLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +} // namespace js + /* * Unwrap Typed arrays all at once. Return nullptr without throwing if the * object cannot be viewed as the correct typed array, or the typed array @@ -1148,13 +1722,13 @@ extern JS_FRIEND_API(JSObject *) JS_GetObjectAsArrayBuffer(JSObject *obj, uint32_t *length, uint8_t **data); /* - * Get the type of elements in a typed array, or TYPE_DATAVIEW if a DataView. + * Get the type of elements in a typed array, or TypeMax if a DataView. * * |obj| must have passed a JS_IsArrayBufferView/JS_Is*Array test, or somehow * be known that it would pass such a test: it is an ArrayBufferView or a * wrapper of an ArrayBufferView, and the unwrapping will succeed. */ -extern JS_FRIEND_API(JSArrayBufferViewType) +extern JS_FRIEND_API(js::Scalar::Type) JS_GetArrayBufferViewType(JSObject *obj); /* @@ -1177,16 +1751,12 @@ extern JS_FRIEND_API(uint32_t) JS_GetArrayBufferByteLength(JSObject *obj); /* - * Return a pointer to an array buffer's data. The buffer is still owned by the - * array buffer object, and should not be modified on another thread. The - * returned pointer is stable across GCs. - * - * |obj| must have passed a JS_IsArrayBufferObject test, or somehow be known - * that it would pass such a test: it is an ArrayBuffer or a wrapper of an - * ArrayBuffer, and the unwrapping will succeed. + * Check whether the obj is ArrayBufferObject and memory mapped. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. */ -extern JS_FRIEND_API(uint8_t *) -JS_GetArrayBufferData(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsMappedArrayBufferObject(JSObject *obj); /* * Return the number of elements in a typed array. @@ -1236,13 +1806,17 @@ JS_GetArrayBufferViewByteLength(JSObject *obj); /* * Return a pointer to the start of the data referenced by a typed array. The * data is still owned by the typed array, and should not be modified on - * another thread. + * another thread. Furthermore, the pointer can become invalid on GC (if the + * data is small and fits inside the array's GC header), so callers must take + * care not to hold on across anything that could GC. * * |obj| must have passed a JS_Is*Array test, or somehow be known that it would * pass such a test: it is a typed array or a wrapper of a typed array, and the * unwrapping will succeed. */ +extern JS_FRIEND_API(uint8_t *) +JS_GetArrayBufferData(JSObject *obj); extern JS_FRIEND_API(int8_t *) JS_GetInt8ArrayData(JSObject *obj); extern JS_FRIEND_API(uint8_t *) @@ -1262,6 +1836,13 @@ JS_GetFloat32ArrayData(JSObject *obj); extern JS_FRIEND_API(double *) JS_GetFloat64ArrayData(JSObject *obj); +/* + * Stable versions of the above functions where the buffer remains valid as long + * as the object is live. + */ +extern JS_FRIEND_API(uint8_t *) +JS_GetStableArrayBufferData(JSContext *cx, JS::HandleObject obj); + /* * Same as above, but for any kind of ArrayBufferView. Prefer the type-specific * versions when possible. @@ -1275,13 +1856,33 @@ JS_GetArrayBufferViewData(JSObject *obj); * object that would return true for JS_IsArrayBufferViewObject(). */ extern JS_FRIEND_API(JSObject *) -JS_GetArrayBufferViewBuffer(JSObject *obj); +JS_GetArrayBufferViewBuffer(JSContext *cx, JS::HandleObject obj); + +typedef enum { + ChangeData, + KeepData +} NeuterDataDisposition; /* * Set an ArrayBuffer's length to 0 and neuter all of its views. + * + * The |changeData| argument is a hint to inform internal behavior with respect + * to the internal pointer to the ArrayBuffer's data after being neutered. + * There is no guarantee it will be respected. But if it is respected, the + * ArrayBuffer's internal data pointer will, or will not, have changed + * accordingly. + */ +extern JS_FRIEND_API(bool) +JS_NeuterArrayBuffer(JSContext *cx, JS::HandleObject obj, + NeuterDataDisposition changeData); + +/* + * Check whether the obj is ArrayBufferObject and neutered. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. */ extern JS_FRIEND_API(bool) -JS_NeuterArrayBuffer(JSContext *cx, JS::HandleObject obj); +JS_IsNeuteredArrayBufferObject(JSObject *obj); /* * Check whether obj supports JS_GetDataView* APIs. @@ -1360,7 +1961,7 @@ class JSJitGetterCallArgs : protected JS::MutableHandleValue : JS::MutableHandleValue(args.rval()) {} - explicit JSJitGetterCallArgs(JS::Rooted* rooted) + explicit JSJitGetterCallArgs(JS::RootedValue* rooted) : JS::MutableHandleValue(rooted) {} @@ -1422,6 +2023,12 @@ class JSJitMethodCallArgs : protected JS::detail::CallArgsBaseusedRval_, which we don't have. + return argv_[-2].toObject(); + } + // Add get() as needed }; @@ -1451,7 +2058,10 @@ struct JSJitInfo { Getter, Setter, Method, - OpType_None + ParallelNative, + StaticMethod, + // Must be last + OpTypeCount }; enum ArgType { @@ -1475,6 +2085,13 @@ struct JSJitInfo { ArgTypeListEnd = (1 << 31) }; + static_assert(Any & String, "Any must include String."); + static_assert(Any & Integer, "Any must include Integer."); + static_assert(Any & Double, "Any must include Double."); + static_assert(Any & Boolean, "Any must include Boolean."); + static_assert(Any & Object, "Any must include Object."); + static_assert(Any & Null, "Any must include Null."); + enum AliasSet { // An enum that describes what this getter/setter/method aliases. This // determines what things can be hoisted past this call, and if this @@ -1490,69 +2107,172 @@ struct JSJitInfo { // Alias the world. Calling this can change arbitrary values anywhere // in the system. Most things fall in this bucket. - AliasEverything + AliasEverything, + + // Must be last. + AliasSetCount }; - bool isDOMJitInfo() const + bool hasParallelNative() const + { + return type() == ParallelNative; + } + + bool needsOuterizedThisObject() const + { + return type() != Getter && type() != Setter; + } + + bool isTypedMethodJitInfo() const { - return type != OpType_None; + return isTypedMethod; + } + + OpType type() const + { + return OpType(type_); + } + + AliasSet aliasSet() const + { + return AliasSet(aliasSet_); + } + + JSValueType returnType() const + { + return JSValueType(returnType_); } union { JSJitGetterOp getter; JSJitSetterOp setter; JSJitMethodOp method; + /* An alternative native that's safe to call in parallel mode. */ + JSParallelNative parallelNative; + /* A DOM static method, used for Promise wrappers */ + JSNative staticMethod; }; - uint32_t protoID; - uint32_t depth; - // type not being OpType_None means this is a DOM method. If you - // change that, come up with a different way of implementing - // isDOMJitInfo(). - OpType type; - bool isInfallible; /* Is op fallible? False in setters. */ - bool isMovable; /* Is op movable? To be movable the op must not - AliasEverything, but even that might not be - enough (e.g. in cases when it can throw). */ - AliasSet aliasSet; /* The alias set for this op. This is a _minimal_ - alias set; in particular for a method it does not - include whatever argument conversions might do. - That's covered by argTypes and runtime analysis - of the actual argument types being passed in. */ - // XXXbz should we have a JSGetterJitInfo subclass or something? + uint16_t protoID; + uint16_t depth; + + // These fields are carefully packed to take up 4 bytes. If you need more + // bits for whatever reason, please see if you can steal bits from existing + // fields before adding more members to this structure. + +#define JITINFO_OP_TYPE_BITS 4 +#define JITINFO_ALIAS_SET_BITS 4 +#define JITINFO_RETURN_TYPE_BITS 8 + + // The OpType that says what sort of function we are. + uint32_t type_ : JITINFO_OP_TYPE_BITS; + + // The alias set for this op. This is a _minimal_ alias set; in + // particular for a method it does not include whatever argument + // conversions might do. That's covered by argTypes and runtime + // analysis of the actual argument types being passed in. + uint32_t aliasSet_ : JITINFO_ALIAS_SET_BITS; + + // The return type tag. Might be JSVAL_TYPE_UNKNOWN. + uint32_t returnType_ : JITINFO_RETURN_TYPE_BITS; + + static_assert(OpTypeCount <= (1 << JITINFO_OP_TYPE_BITS), + "Not enough space for OpType"); + static_assert(AliasSetCount <= (1 << JITINFO_ALIAS_SET_BITS), + "Not enough space for AliasSet"); + static_assert((sizeof(JSValueType) * 8) <= JITINFO_RETURN_TYPE_BITS, + "Not enough space for JSValueType"); + +#undef JITINFO_RETURN_TYPE_BITS +#undef JITINFO_ALIAS_SET_BITS +#undef JITINFO_OP_TYPE_BITS + + uint32_t isInfallible : 1; /* Is op fallible? False in setters. */ + uint32_t isMovable : 1; /* Is op movable? To be movable the op must + not AliasEverything, but even that might + not be enough (e.g. in cases when it can + throw). */ // XXXbz should we have a JSValueType for the type of the member? - bool isInSlot; /* True if this is a getter that can get a member - from a slot of the "this" object directly. */ - size_t slotIndex; /* If isMember is true, the index of the slot to get - the value from. Otherwise 0. */ - JSValueType returnType; /* The return type tag. Might be JSVAL_TYPE_UNKNOWN */ - - const ArgType* const argTypes; /* For a method, a list of sets of types that - the function expects. This can be used, - for example, to figure out when argument - coercions can have side-effects. nullptr - if we have no type information for - arguments. */ - - /* An alternative native that's safe to call in parallel mode. */ - JSParallelNative parallelNative; - -private: - static void staticAsserts() - { - JS_STATIC_ASSERT(Any & String); - JS_STATIC_ASSERT(Any & Integer); - JS_STATIC_ASSERT(Any & Double); - JS_STATIC_ASSERT(Any & Boolean); - JS_STATIC_ASSERT(Any & Object); - JS_STATIC_ASSERT(Any & Null); - } + uint32_t isAlwaysInSlot : 1; /* True if this is a getter that can always + get the value from a slot of the "this" + object. */ + uint32_t isLazilyCachedInSlot : 1; /* True if this is a getter that can + sometimes (if the slot doesn't contain + UndefinedValue()) get the value from a + slot of the "this" object. */ + uint32_t isTypedMethod : 1; /* True if this is an instance of + JSTypedMethodJitInfo. */ + uint32_t slotIndex : 11; /* If isAlwaysInSlot or isSometimesInSlot is + true, the index of the slot to get the value + from. Otherwise 0. */ }; -#define JS_JITINFO_NATIVE_PARALLEL(op) \ - {{nullptr},0,0,JSJitInfo::OpType_None,false,false,JSJitInfo::AliasEverything,false,0,JSVAL_TYPE_MISSING,nullptr,op} +static_assert(sizeof(JSJitInfo) == (sizeof(void*) + 2 * sizeof(uint32_t)), + "There are several thousand instances of JSJitInfo stored in " + "a binary. Please don't increase its space requirements without " + "verifying that there is no other way forward (better packing, " + "smaller datatypes for fields, subclassing, etc.)."); -static JS_ALWAYS_INLINE const JSJitInfo * +struct JSTypedMethodJitInfo +{ + // We use C-style inheritance here, rather than C++ style inheritance + // because not all compilers support brace-initialization for non-aggregate + // classes. Using C++ style inheritance and constructors instead of + // brace-initialization would also force the creation of static + // constructors (on some compilers) when JSJitInfo and JSTypedMethodJitInfo + // structures are declared. Since there can be several thousand of these + // structures present and we want to have roughly equivalent performance + // across a range of compilers, we do things manually. + JSJitInfo base; + + const JSJitInfo::ArgType* const argTypes; /* For a method, a list of sets of + types that the function + expects. This can be used, + for example, to figure out + when argument coercions can + have side-effects. */ +}; + +namespace JS { +namespace detail { + +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_PARALLEL_NATIVE_TO only. */ +inline int CheckIsParallelNative(JSParallelNative parallelNative); + +} // namespace detail +} // namespace JS + +#define JS_CAST_PARALLEL_NATIVE_TO(v, To) \ + (static_cast(sizeof(JS::detail::CheckIsParallelNative(v))), \ + reinterpret_cast(v)) + +/* + * You may ask yourself: why do we define a wrapper around a wrapper here? + * The answer is that some compilers don't understand initializing a union + * as we do below with a construct like: + * + * reinterpret_cast(JSParallelNativeThreadSafeWrapper) + * + * (We need the reinterpret_cast because we must initialize the union with + * a datum of the type of the union's first member.) + * + * Presumably this has something to do with template instantiation. + * Initializing with a normal function pointer seems to work fine. Hence + * the ugliness that you see before you. + */ +#define JS_JITINFO_NATIVE_PARALLEL(infoName, parallelOp) \ + const JSJitInfo infoName = \ + {{JS_CAST_PARALLEL_NATIVE_TO(parallelOp, JSJitGetterOp)},0,0,JSJitInfo::ParallelNative,JSJitInfo::AliasEverything,JSVAL_TYPE_MISSING,false,false,false,false,false,0} + +#define JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(infoName, wrapperName, serialOp) \ + bool wrapperName##_ParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, \ + JS::Value *vp) \ + { \ + return JSParallelNativeThreadSafeWrapper(cx, argc, vp); \ + } \ + JS_JITINFO_NATIVE_PARALLEL(infoName, wrapperName##_ParallelNativeThreadSafeWrapper) + +static MOZ_ALWAYS_INLINE const JSJitInfo * FUNCTION_VALUE_TO_JITINFO(const JS::Value& v) { JS_ASSERT(js::GetObjectClass(&v.toObject()) == js::FunctionClassPtr); @@ -1562,7 +2282,7 @@ FUNCTION_VALUE_TO_JITINFO(const JS::Value& v) /* Statically asserted in jsfun.h. */ static const unsigned JS_FUNCTION_INTERPRETED_BIT = 0x1; -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void SET_JITINFO(JSFunction * func, const JSJitInfo *info) { js::shadow::Function *fun = reinterpret_cast(func); @@ -1575,7 +2295,7 @@ SET_JITINFO(JSFunction * func, const JSJitInfo *info) * eliminate Gecko's dependencies on it! */ -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid JSID_FROM_BITS(size_t bits) { jsid id; @@ -1610,7 +2330,7 @@ bool IdMatchesAtom(jsid id, JSAtom *atom); * Thus, it is only the rare third case which needs this function, which * handles any JSAtom* that is known not to be representable with an int jsid. */ -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid NON_INTEGER_ATOM_TO_JSID(JSAtom *atom) { JS_ASSERT(((size_t)atom & 0x7) == 0); @@ -1620,19 +2340,19 @@ NON_INTEGER_ATOM_TO_JSID(JSAtom *atom) } /* All strings stored in jsids are atomized, but are not necessarily property names. */ -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ATOM(jsid id) { return JSID_IS_STRING(id); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ATOM(jsid id, JSAtom *atom) { return id == JSID_FROM_BITS((size_t)atom); } -static JS_ALWAYS_INLINE JSAtom * +static MOZ_ALWAYS_INLINE JSAtom * JSID_TO_ATOM(jsid id) { return (JSAtom *)JSID_TO_STRING(id); @@ -1642,31 +2362,19 @@ JS_STATIC_ASSERT(sizeof(jsid) == sizeof(void*)); namespace js { -static JS_ALWAYS_INLINE JS::Value +static MOZ_ALWAYS_INLINE JS::Value IdToValue(jsid id) { if (JSID_IS_STRING(id)) return JS::StringValue(JSID_TO_STRING(id)); - if (JS_LIKELY(JSID_IS_INT(id))) + if (JSID_IS_INT(id)) return JS::Int32Value(JSID_TO_INT(id)); - if (JS_LIKELY(JSID_IS_OBJECT(id))) - return JS::ObjectValue(*JSID_TO_OBJECT(id)); + if (JSID_IS_SYMBOL(id)) + return JS::SymbolValue(JSID_TO_SYMBOL(id)); JS_ASSERT(JSID_IS_VOID(id)); return JS::UndefinedValue(); } -static JS_ALWAYS_INLINE jsval -IdToJsval(jsid id) -{ - return IdToValue(id); -} - -extern JS_FRIEND_API(bool) -IsReadOnlyDateMethod(JS::IsAcceptableThis test, JS::NativeImpl method); - -extern JS_FRIEND_API(bool) -IsTypedArrayThisCheck(JS::IsAcceptableThis test); - /* * If the embedder has registered a default JSContext callback, returns the * result of the callback. Otherwise, asserts that |rt| has exactly one @@ -1681,6 +2389,21 @@ typedef JSContext* JS_FRIEND_API(void) SetDefaultJSContextCallback(JSRuntime *rt, DefaultJSContextCallback cb); +/* + * To help embedders enforce their invariants, we allow them to specify in + * advance which JSContext should be passed to JSAPI calls. If this is set + * to a non-null value, the assertSameCompartment machinery does double- + * duty (in debug builds) to verify that it matches the cx being used. + */ +#ifdef DEBUG +JS_FRIEND_API(void) +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx); +#else +inline void +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx) {}; +#endif + + enum CTypesActivityType { CTYPES_CALL_BEGIN, CTYPES_CALL_END, @@ -1720,13 +2443,6 @@ class JS_FRIEND_API(AutoCTypesActivityCallback) { } }; -#ifdef DEBUG -extern JS_FRIEND_API(void) -assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id); -#else -inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id) {}; -#endif - typedef bool (* ObjectMetadataCallback)(JSContext *cx, JSObject **pmetadata); @@ -1747,6 +2463,13 @@ SetObjectMetadata(JSContext *cx, JS::HandleObject obj, JS::HandleObject metadata JS_FRIEND_API(JSObject *) GetObjectMetadata(JSObject *obj); +JS_FRIEND_API(void) +UnsafeDefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value); + +JS_FRIEND_API(bool) +SliceSlowly(JSContext* cx, JS::HandleObject obj, JS::HandleObject receiver, + uint32_t begin, uint32_t end, JS::HandleObject result); + /* ES5 8.12.8. */ extern JS_FRIEND_API(bool) DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandleValue vp); @@ -1766,7 +2489,43 @@ DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandle */ extern JS_FRIEND_API(bool) CheckDefineProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +/* + * Helper function for HTMLDocument and HTMLFormElement. + * + * These are the only two interfaces that have [OverrideBuiltins], a named + * getter, and no named setter. They're implemented as proxies with a custom + * getOwnPropertyDescriptor() method. Unfortunately, overriding + * getOwnPropertyDescriptor() automatically affects the behavior of set(), + * which normally is just common sense but is *not* desired for these two + * interfaces. + * + * The fix is for these two interfaces to override set() to ignore the + * getOwnPropertyDescriptor() override. + * + * SetPropertyIgnoringNamedGetter is exposed to make it easier to override + * set() in this way. It carries out all the steps of BaseProxyHandler::set() + * except the initial getOwnPropertyDescriptor()/getPropertyDescriptor() calls. + * The caller must supply those results as the 'desc' and 'descIsOwn' + * parameters. + * + * Implemented in jsproxy.cpp. + */ +JS_FRIEND_API(bool) +SetPropertyIgnoringNamedGetter(JSContext *cx, const BaseProxyHandler *handler, + JS::HandleObject proxy, JS::HandleObject receiver, + JS::HandleId id, JS::MutableHandle desc, + bool descIsOwn, bool strict, JS::MutableHandleValue vp); + +JS_FRIEND_API(void) +ReportErrorWithId(JSContext *cx, const char *msg, JS::HandleId id); + +// This function is for one specific use case, please don't use this for anything else! +extern JS_FRIEND_API(bool) +ExecuteInGlobalAndReturnScope(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleObject scope); } /* namespace js */ @@ -1775,27 +2534,27 @@ js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg, JS::Handle descriptor, bool *bp); extern JS_FRIEND_API(bool) -js_ReportIsNotFunction(JSContext *cx, const JS::Value& v); +js_ReportIsNotFunction(JSContext *cx, JS::HandleValue v); #ifdef JSGC_GENERATIONAL extern JS_FRIEND_API(void) JS_StoreObjectPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSObject *key, void *data), JSObject *key, void *data); extern JS_FRIEND_API(void) JS_StoreStringPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSString *key, void *data), JSString *key, void *data); #else inline void JS_StoreObjectPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSObject *key, void *data), JSObject *key, void *data) {} inline void JS_StoreStringPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSString *key, void *data), JSString *key, void *data) {} #endif /* JSGC_GENERATIONAL */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/jsperf.h b/frameworks/js-bindings/external/spidermonkey/include/ios/jsperf.h index e3cbc23143..60c572f559 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/jsperf.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/jsperf.h @@ -88,7 +88,7 @@ class JS_FRIEND_API(PerfMeasurement) * then the eventsMeasured bitmask will only include the subset of * |toMeasure| corresponding to the events that can be measured. */ - PerfMeasurement(EventMask toMeasure); + explicit PerfMeasurement(EventMask toMeasure); /* Done with this set of measurements, tear down OS-level state. */ ~PerfMeasurement(); @@ -118,7 +118,7 @@ class JS_FRIEND_API(PerfMeasurement) * global object). The JS-visible API is identical to the C++ API. */ extern JS_FRIEND_API(JSObject*) - RegisterPerfMeasurement(JSContext *cx, JSObject *global); + RegisterPerfMeasurement(JSContext *cx, JS::HandleObject global); /* * Given a Value which contains an instance of the aforementioned diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/jsprf.h b/frameworks/js-bindings/external/spidermonkey/include/ios/jsprf.h index b235f0b4fb..bfedf98ca8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/jsprf.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/jsprf.h @@ -57,23 +57,11 @@ extern JS_PUBLIC_API(void) JS_smprintf_free(char *mem); */ extern JS_PUBLIC_API(char*) JS_sprintf_append(char *last, const char *fmt, ...); -/* -** sprintf into a function. The function "f" is called with a string to -** place into the output. "arg" is an opaque pointer used by the stuff -** function to hold any state needed to do the storage of the output -** data. The return value is a count of the number of characters fed to -** the stuff function, or (uint32_t)-1 if an error occurs. -*/ -typedef int (*JSStuffFunc)(void *arg, const char *s, uint32_t slen); - -extern JS_PUBLIC_API(uint32_t) JS_sxprintf(JSStuffFunc f, void *arg, const char *fmt, ...); - /* ** va_list forms of the above. */ extern JS_PUBLIC_API(uint32_t) JS_vsnprintf(char *out, uint32_t outlen, const char *fmt, va_list ap); extern JS_PUBLIC_API(char*) JS_vsmprintf(const char *fmt, va_list ap); extern JS_PUBLIC_API(char*) JS_vsprintf_append(char *last, const char *fmt, va_list ap); -extern JS_PUBLIC_API(uint32_t) JS_vsxprintf(JSStuffFunc f, void *arg, const char *fmt, va_list ap); #endif /* jsprf_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/jsprototypes.h b/frameworks/js-bindings/external/spidermonkey/include/ios/jsprototypes.h index bc4a767033..1cb56bf8da 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/jsprototypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/jsprototypes.h @@ -34,7 +34,7 @@ #define CLASP(name) (&name##Class) #define OCLASP(name) (&name##Object::class_) -#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[ScalarTypeRepresentation::type]) +#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[Scalar::type]) #ifdef ENABLE_PARALLEL_JS #define IF_PJS(real,imaginary) real @@ -54,47 +54,61 @@ #define IF_BDATA(real,imaginary) imaginary #endif +#ifdef ENABLE_SHARED_ARRAY_BUFFER +#define IF_SAB(real,imaginary) real +#else +#define IF_SAB(real,imaginary) imaginary +#endif + +#ifdef JS_HAS_SYMBOLS +#define IF_SYMBOLS(real,imaginary) real +#else +#define IF_SYMBOLS(real,imaginary) imaginary +#endif + #define JS_FOR_PROTOTYPES(real,imaginary) \ imaginary(Null, 0, js_InitNullClass, dummy) \ - real(Object, 1, js_InitObjectClass, &JSObject::class_) \ - real(Function, 2, js_InitFunctionClass, &JSFunction::class_) \ - real(Array, 3, js_InitArrayClass, OCLASP(Array)) \ + real(Object, 1, js_InitViaClassSpec, &JSObject::class_) \ + real(Function, 2, js_InitViaClassSpec, &JSFunction::class_) \ + real(Array, 3, js_InitViaClassSpec, OCLASP(Array)) \ real(Boolean, 4, js_InitBooleanClass, OCLASP(Boolean)) \ real(JSON, 5, js_InitJSONClass, CLASP(JSON)) \ - real(Date, 6, js_InitDateClass, OCLASP(Date)) \ + real(Date, 6, js_InitViaClassSpec, OCLASP(Date)) \ real(Math, 7, js_InitMathClass, CLASP(Math)) \ real(Number, 8, js_InitNumberClass, OCLASP(Number)) \ real(String, 9, js_InitStringClass, OCLASP(String)) \ real(RegExp, 10, js_InitRegExpClass, OCLASP(RegExp)) \ - real(Error, 11, js_InitExceptionClasses, OCLASP(Error)) \ - real(InternalError, 12, js_InitExceptionClasses, OCLASP(Error)) \ - real(EvalError, 13, js_InitExceptionClasses, OCLASP(Error)) \ - real(RangeError, 14, js_InitExceptionClasses, OCLASP(Error)) \ - real(ReferenceError, 15, js_InitExceptionClasses, OCLASP(Error)) \ - real(SyntaxError, 16, js_InitExceptionClasses, OCLASP(Error)) \ - real(TypeError, 17, js_InitExceptionClasses, OCLASP(Error)) \ - real(URIError, 18, js_InitExceptionClasses, OCLASP(Error)) \ + real(Error, 11, js_InitViaClassSpec, OCLASP(Error)) \ + real(InternalError, 12, js_InitViaClassSpec, OCLASP(Error)) \ + real(EvalError, 13, js_InitViaClassSpec, OCLASP(Error)) \ + real(RangeError, 14, js_InitViaClassSpec, OCLASP(Error)) \ + real(ReferenceError, 15, js_InitViaClassSpec, OCLASP(Error)) \ + real(SyntaxError, 16, js_InitViaClassSpec, OCLASP(Error)) \ + real(TypeError, 17, js_InitViaClassSpec, OCLASP(Error)) \ + real(URIError, 18, js_InitViaClassSpec, OCLASP(Error)) \ real(Iterator, 19, js_InitIteratorClasses, OCLASP(PropertyIterator)) \ real(StopIteration, 20, js_InitIteratorClasses, OCLASP(StopIteration)) \ - real(ArrayBuffer, 21, js_InitTypedArrayClasses, &js::ArrayBufferObject::protoClass) \ - real(Int8Array, 22, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT8)) \ - real(Uint8Array, 23, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT8)) \ - real(Int16Array, 24, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT16)) \ - real(Uint16Array, 25, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT16)) \ - real(Int32Array, 26, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT32)) \ - real(Uint32Array, 27, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT32)) \ - real(Float32Array, 28, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_FLOAT32)) \ - real(Float64Array, 29, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_FLOAT64)) \ - real(Uint8ClampedArray, 30, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT8_CLAMPED)) \ + real(ArrayBuffer, 21, js_InitArrayBufferClass, &js::ArrayBufferObject::protoClass) \ + real(Int8Array, 22, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int8)) \ + real(Uint8Array, 23, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8)) \ + real(Int16Array, 24, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int16)) \ + real(Uint16Array, 25, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint16)) \ + real(Int32Array, 26, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int32)) \ + real(Uint32Array, 27, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint32)) \ + real(Float32Array, 28, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float32)) \ + real(Float64Array, 29, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float64)) \ + real(Uint8ClampedArray, 30, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8Clamped)) \ real(Proxy, 31, js_InitProxyClass, &ProxyObject::uncallableClass_) \ real(WeakMap, 32, js_InitWeakMapClass, OCLASP(WeakMap)) \ real(Map, 33, js_InitMapClass, OCLASP(Map)) \ real(Set, 34, js_InitSetClass, OCLASP(Set)) \ - real(DataView, 35, js_InitTypedArrayClasses, OCLASP(DataView)) \ -IF_PJS(real,imaginary) (ParallelArray, 36, js_InitParallelArrayClass, OCLASP(ParallelArray)) \ -IF_INTL(real,imaginary) (Intl, 37, js_InitIntlClass, CLASP(Intl)) \ -IF_BDATA(real,imaginary)(TypedObject, 38, js_InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \ - imaginary(GeneratorFunction, 39, js_InitIteratorClasses, dummy) \ + real(DataView, 35, js_InitDataViewClass, OCLASP(DataView)) \ +IF_SYMBOLS(real,imaginary)(Symbol, 36, js_InitSymbolClass, &js::SymbolObject::class_) \ +IF_SAB(real,imaginary)(SharedArrayBuffer, 37, js_InitSharedArrayBufferClass, &js::SharedArrayBufferObject::protoClass) \ +IF_INTL(real,imaginary) (Intl, 38, js_InitIntlClass, CLASP(Intl)) \ +IF_BDATA(real,imaginary)(TypedObject, 39, js_InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \ + imaginary(GeneratorFunction, 40, js_InitIteratorClasses, dummy) \ +IF_BDATA(real,imaginary)(SIMD, 41, js_InitSIMDClass, OCLASP(SIMD)) \ #define JS_FOR_EACH_PROTOTYPE(macro) JS_FOR_PROTOTYPES(macro,macro) diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/jsproxy.h b/frameworks/js-bindings/external/spidermonkey/include/ios/jsproxy.h index 3d2ea81cb3..b4588c4c2a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/jsproxy.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/jsproxy.h @@ -47,6 +47,22 @@ class JS_FRIEND_API(Wrapper); * BaseProxyHandler provides implementations of the derived traps in terms of * the (pure virtual) fundamental traps. * + * In addition to the normal traps, there are two models for proxy prototype + * chains. First, proxies may opt to use the standard prototype mechanism used + * throughout the engine. To do so, simply pass a prototype to NewProxyObject() + * at creation time. All prototype accesses will then "just work" to treat the + * proxy as a "normal" object. Alternatively, if instead the proxy wishes to + * implement more complicated prototype semantics (if, for example, it wants to + * delegate the prototype lookup to a wrapped object), it may pass Proxy::LazyProto + * as the prototype at create time and opt in to the trapped prototype system, + * which guarantees that their trap will be called on any and every prototype + * chain access of the object. + * + * This system is implemented with two traps: {get,set}PrototypeOf. The default + * implementation of setPrototypeOf throws a TypeError. Since it is not possible + * to create an object without a sense of prototype chain, handler implementors + * must provide a getPrototypeOf trap if opting in to the dynamic prototype system. + * * To minimize code duplication, a set of abstract proxy handler classes is * provided, from which other handlers may inherit. These abstract classes * are organized in the following hierarchy: @@ -72,37 +88,55 @@ class JS_FRIEND_API(Wrapper); class JS_FRIEND_API(BaseProxyHandler) { const void *mFamily; + + /* + * Proxy handlers can use mHasPrototype to request the following special + * treatment from the JS engine: + * + * - When mHasPrototype is true, the engine never calls these methods: + * getPropertyDescriptor, has, set, enumerate, iterate. Instead, for + * these operations, it calls the "own" traps like + * getOwnPropertyDescriptor, hasOwn, defineProperty, keys, etc., and + * consults the prototype chain if needed. + * + * - When mHasPrototype is true, the engine calls handler->get() only if + * handler->hasOwn() says an own property exists on the proxy. If not, + * it consults the prototype chain. + * + * This is useful because it frees the ProxyHandler from having to implement + * any behavior having to do with the prototype chain. + */ bool mHasPrototype; - bool mHasPolicy; - protected: - // Subclasses may set this in their constructor. - void setHasPrototype(bool aHasPrototype) { mHasPrototype = aHasPrototype; } - void setHasPolicy(bool aHasPolicy) { mHasPolicy = aHasPolicy; } + + /* + * All proxies indicate whether they have any sort of interesting security + * policy that might prevent the caller from doing something it wants to + * the object. In the case of wrappers, this distinction is used to + * determine whether the caller may strip off the wrapper if it so desires. + */ + bool mHasSecurityPolicy; public: - explicit BaseProxyHandler(const void *family); + explicit BaseProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); virtual ~BaseProxyHandler(); - bool hasPrototype() { + bool hasPrototype() const { return mHasPrototype; } - bool hasPolicy() { - return mHasPolicy; + bool hasSecurityPolicy() const { + return mHasSecurityPolicy; } - inline const void *family() { + inline const void *family() const { return mFamily; } static size_t offsetOfFamily() { return offsetof(BaseProxyHandler, mFamily); } - virtual bool isOuterWindow() { - return false; - } - - virtual bool finalizeInBackground(Value priv) { + virtual bool finalizeInBackground(Value priv) const { /* * Called on creation of a proxy to determine whether its finalize * method can be finalized on the background thread. @@ -119,66 +153,75 @@ class JS_FRIEND_API(BaseProxyHandler) * The |act| parameter to enter() specifies the action being performed. * If |bp| is false, the trap suggests that the caller throw (though it * may still decide to squelch the error). + * + * We make these OR-able so that assertEnteredPolicy can pass a union of them. + * For example, get{,Own}PropertyDescriptor is invoked by both calls to ::get() + * and ::set() (since we need to look up the accessor), so its + * assertEnteredPolicy would pass GET | SET. */ - enum Action { - GET, - SET, - CALL + typedef uint32_t Action; + enum { + NONE = 0x00, + GET = 0x01, + SET = 0x02, + CALL = 0x04, + ENUMERATE = 0x08 }; + virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Action act, - bool *bp); + bool *bp) const; /* ES5 Harmony fundamental proxy traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) = 0; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const = 0; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, - unsigned flags) = 0; + MutableHandle desc) const = 0; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, - HandleId id, MutableHandle desc, - unsigned flags) = 0; + HandleId id, MutableHandle desc) const = 0; virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc) = 0; + MutableHandle desc) const = 0; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, - AutoIdVector &props) = 0; - virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) = 0; - virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) = 0; + AutoIdVector &props) const = 0; + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const = 0; + virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) const = 0; /* ES5 Harmony derived proxy traps. */ - virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); - virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); + virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; + virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, MutableHandleValue vp); + HandleId id, MutableHandleValue vp) const; virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp); - virtual bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props); + HandleId id, bool strict, MutableHandleValue vp) const; + virtual bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props) const; virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, - MutableHandleValue vp); + MutableHandleValue vp) const; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) = 0; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args); - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args); - virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args); - virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp); - virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx); - virtual const char *className(JSContext *cx, HandleObject proxy); - virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent); - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g); - virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); - virtual void finalize(JSFreeOp *fop, JSObject *proxy); - virtual bool getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver, - uint32_t index, MutableHandleValue vp, bool *present); - virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const = 0; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args) const; + virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp) const; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx) const; + virtual const char *className(JSContext *cx, HandleObject proxy) const; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const; + virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp) const; + virtual void finalize(JSFreeOp *fop, JSObject *proxy) const; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop) const; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp) const; // These two hooks must be overridden, or not overridden, in tandem -- no // overriding just one! virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable); - virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id); + JS::HandleObject callable) const; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const; + + virtual bool slice(JSContext *cx, HandleObject proxy, uint32_t begin, uint32_t end, + HandleObject result) const; /* See comment for weakmapKeyDelegateOp in js/Class.h. */ - virtual JSObject *weakmapKeyDelegate(JSObject *proxy); - virtual bool isScripted() { return false; } + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const; + virtual bool isScripted() const { return false; } }; /* @@ -194,54 +237,58 @@ class JS_FRIEND_API(BaseProxyHandler) class JS_PUBLIC_API(DirectProxyHandler) : public BaseProxyHandler { public: - explicit DirectProxyHandler(const void *family); + explicit DirectProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); /* ES5 Harmony fundamental proxy traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags) MOZ_OVERRIDE; - virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, - HandleId id, MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool enumerate(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; /* ES5 Harmony derived proxy traps. */ virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool keys(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, - unsigned indent) MOZ_OVERRIDE; + unsigned indent) const MOZ_OVERRIDE; virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, - RegExpGuard *g) MOZ_OVERRIDE; - virtual JSObject *weakmapKeyDelegate(JSObject *proxy); + RegExpGuard *g) const MOZ_OVERRIDE; + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const MOZ_OVERRIDE; }; /* @@ -257,16 +304,15 @@ class Proxy /* ES5 Harmony fundamental proxy traps. */ static bool preventExtensions(JSContext *cx, HandleObject proxy); static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags); - static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, unsigned flags, HandleId id, + MutableHandle desc); + static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, MutableHandleValue vp); static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags); - static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, unsigned flags, HandleId id, + MutableHandle desc); + static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, MutableHandleValue vp); static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, MutableHandle desc); - static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, HandleValue v); static bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props); static bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); static bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props); @@ -276,8 +322,6 @@ class Proxy static bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); static bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, MutableHandleValue vp); - static bool getElementIfPresent(JSContext *cx, HandleObject proxy, HandleObject receiver, - uint32_t index, MutableHandleValue vp, bool *present); static bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, bool strict, MutableHandleValue vp); static bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props); @@ -295,44 +339,26 @@ class Proxy static bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g); static bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); static bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + static bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp); - static bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable); - static bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id); + static bool watch(JSContext *cx, HandleObject proxy, HandleId id, HandleObject callable); + static bool unwatch(JSContext *cx, HandleObject proxy, HandleId id); + + static bool slice(JSContext *cx, HandleObject obj, uint32_t begin, uint32_t end, + HandleObject result); /* IC entry path for handling __noSuchMethod__ on access. */ static bool callProp(JSContext *cx, HandleObject proxy, HandleObject reveiver, HandleId id, MutableHandleValue vp); - - static JSObject * const LazyProto; }; // Use these in places where you don't want to #include vm/ProxyObject.h. extern JS_FRIEND_DATA(const js::Class* const) CallableProxyClassPtr; extern JS_FRIEND_DATA(const js::Class* const) UncallableProxyClassPtr; -extern JS_FRIEND_DATA(const js::Class* const) OuterWindowProxyClassPtr; - -inline bool IsProxyClass(const Class *clasp) -{ - return clasp == CallableProxyClassPtr || - clasp == UncallableProxyClassPtr || - clasp == OuterWindowProxyClassPtr; -} inline bool IsProxy(JSObject *obj) { - return IsProxyClass(GetObjectClass(obj)); -} - -BaseProxyHandler * -GetProxyHandler(JSObject *obj); - -inline bool IsScriptedProxy(JSObject *obj) -{ - if (!IsProxy(obj)) - return false; - - return GetProxyHandler(obj)->isScripted(); + return GetObjectClass(obj)->isProxy(); } /* @@ -343,15 +369,16 @@ inline bool IsScriptedProxy(JSObject *obj) * needs to store one slot's worth of data doesn't need to branch on what sort * of object it has. */ -const uint32_t PROXY_PRIVATE_SLOT = 0; -const uint32_t PROXY_HANDLER_SLOT = 1; -const uint32_t PROXY_EXTRA_SLOT = 2; +const uint32_t PROXY_PRIVATE_SLOT = 0; +const uint32_t PROXY_HANDLER_SLOT = 1; +const uint32_t PROXY_EXTRA_SLOT = 2; +const uint32_t PROXY_MINIMUM_SLOTS = 4; -inline BaseProxyHandler * +inline const BaseProxyHandler * GetProxyHandler(JSObject *obj) { JS_ASSERT(IsProxy(obj)); - return (BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate(); + return (const BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate(); } inline const Value & @@ -390,17 +417,24 @@ SetProxyExtra(JSObject *obj, size_t n, const Value &extra) SetReservedSlot(obj, PROXY_EXTRA_SLOT + n, extra); } +inline bool +IsScriptedProxy(JSObject *obj) +{ + return IsProxy(obj) && GetProxyHandler(obj)->isScripted(); +} + class MOZ_STACK_CLASS ProxyOptions { - public: - ProxyOptions() : callable_(false), - singleton_(false) + protected: + /* protected constructor for subclass */ + ProxyOptions(bool singletonArg, const Class *claspArg) + : singleton_(singletonArg), + clasp_(claspArg) {} - bool callable() const { return callable_; } - ProxyOptions &setCallable(bool flag) { - callable_ = flag; - return *this; - } + public: + ProxyOptions() : singleton_(false), + clasp_(UncallableProxyClassPtr) + {} bool singleton() const { return singleton_; } ProxyOptions &setSingleton(bool flag) { @@ -408,13 +442,26 @@ class MOZ_STACK_CLASS ProxyOptions { return *this; } + const Class *clasp() const { + return clasp_; + } + ProxyOptions &setClass(const Class *claspArg) { + clasp_ = claspArg; + return *this; + } + ProxyOptions &selectDefaultClass(bool callable) { + const Class *classp = callable? CallableProxyClassPtr : + UncallableProxyClassPtr; + return setClass(classp); + } + private: - bool callable_; bool singleton_; + const Class *clasp_; }; JS_FRIEND_API(JSObject *) -NewProxyObject(JSContext *cx, BaseProxyHandler *handler, HandleValue priv, +NewProxyObject(JSContext *cx, const BaseProxyHandler *handler, HandleValue priv, JSObject *proto, JSObject *parent, const ProxyOptions &options = ProxyOptions()); JSObject * @@ -424,15 +471,15 @@ class JS_FRIEND_API(AutoEnterPolicy) { public: typedef BaseProxyHandler::Action Action; - AutoEnterPolicy(JSContext *cx, BaseProxyHandler *handler, + AutoEnterPolicy(JSContext *cx, const BaseProxyHandler *handler, HandleObject wrapper, HandleId id, Action act, bool mayThrow) -#ifdef DEBUG +#ifdef JS_DEBUG : context(nullptr) #endif { - allow = handler->hasPolicy() ? handler->enter(cx, wrapper, id, act, &rv) - : true; - recordEnter(cx, wrapper, id); + allow = handler->hasSecurityPolicy() ? handler->enter(cx, wrapper, id, act, &rv) + : true; + recordEnter(cx, wrapper, id, act); // We want to throw an exception if all of the following are true: // * The policy disallowed access. // * The policy set rv to false, indicating that we should throw. @@ -449,48 +496,65 @@ class JS_FRIEND_API(AutoEnterPolicy) protected: // no-op constructor for subclass AutoEnterPolicy() -#ifdef DEBUG +#ifdef JS_DEBUG : context(nullptr) + , enteredAction(BaseProxyHandler::NONE) #endif {}; void reportErrorIfExceptionIsNotPending(JSContext *cx, jsid id); bool allow; bool rv; -#ifdef DEBUG +#ifdef JS_DEBUG JSContext *context; mozilla::Maybe enteredProxy; mozilla::Maybe enteredId; + Action enteredAction; + // NB: We explicitly don't track the entered action here, because sometimes // SET traps do an implicit GET during their implementation, leading to // spurious assertions. AutoEnterPolicy *prev; - void recordEnter(JSContext *cx, HandleObject proxy, HandleId id); + void recordEnter(JSContext *cx, HandleObject proxy, HandleId id, Action act); void recordLeave(); - friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id); + friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id, Action act); #else - inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id) {} + inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id, Action act) {} inline void recordLeave() {} #endif }; -#ifdef DEBUG +#ifdef JS_DEBUG class JS_FRIEND_API(AutoWaivePolicy) : public AutoEnterPolicy { public: - AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id) + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) { allow = true; - recordEnter(cx, proxy, id); + recordEnter(cx, proxy, id, act); } }; #else class JS_FRIEND_API(AutoWaivePolicy) { - public: AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id) {}; + public: + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) + {} }; #endif +#ifdef JS_DEBUG +extern JS_FRIEND_API(void) +assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act); +#else +inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act) +{}; +#endif + } /* namespace js */ extern JS_FRIEND_API(JSObject *) diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/jspubtd.h b/frameworks/js-bindings/external/spidermonkey/include/ios/jspubtd.h index 9683c23ea4..ffd75e2e5c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/jspubtd.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/jspubtd.h @@ -11,6 +11,7 @@ * JS public API typedefs. */ +#include "mozilla/Assertions.h" #include "mozilla/LinkedList.h" #include "mozilla/NullPtr.h" #include "mozilla/PodOperations.h" @@ -20,7 +21,7 @@ #include "js/TypeDecls.h" -#if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING) || defined(DEBUG) +#if defined(JSGC_USE_EXACT_ROOTING) || defined(JS_DEBUG) # define JSGC_TRACK_EXACT_ROOTS #endif @@ -32,23 +33,25 @@ class CallArgs; template class Rooted; -class JS_PUBLIC_API(AutoGCRooter); - -class JS_PUBLIC_API(CompileOptions); -class JS_PUBLIC_API(ReadOnlyCompileOptions); -class JS_PUBLIC_API(OwningCompileOptions); +class JS_FRIEND_API(CompileOptions); +class JS_FRIEND_API(ReadOnlyCompileOptions); +class JS_FRIEND_API(OwningCompileOptions); class JS_PUBLIC_API(CompartmentOptions); struct Zone; } /* namespace JS */ +namespace js { +struct ContextFriendFields; +} // namespace js + /* * Run-time version enumeration. For compile-time version checking, please use * the JS_HAS_* macros in jsversion.h, or use MOZJS_MAJOR_VERSION, * MOZJS_MINOR_VERSION, MOZJS_PATCH_VERSION, and MOZJS_ALPHA definitions. */ -typedef enum JSVersion { +enum JSVersion { JSVERSION_ECMA_3 = 148, JSVERSION_1_6 = 160, JSVERSION_1_7 = 170, @@ -57,10 +60,10 @@ typedef enum JSVersion { JSVERSION_DEFAULT = 0, JSVERSION_UNKNOWN = -1, JSVERSION_LATEST = JSVERSION_ECMA_5 -} JSVersion; +}; /* Result of typeof operator enumeration. */ -typedef enum JSType { +enum JSType { JSTYPE_VOID, /* undefined */ JSTYPE_OBJECT, /* object */ JSTYPE_FUNCTION, /* function */ @@ -68,44 +71,23 @@ typedef enum JSType { JSTYPE_NUMBER, /* number */ JSTYPE_BOOLEAN, /* boolean */ JSTYPE_NULL, /* null */ + JSTYPE_SYMBOL, /* symbol */ JSTYPE_LIMIT -} JSType; +}; /* Dense index into cached prototypes and class atoms for standard objects. */ -typedef enum JSProtoKey { +enum JSProtoKey { #define PROTOKEY_AND_INITIALIZER(name,code,init,clasp) JSProto_##name = code, JS_FOR_EACH_PROTOTYPE(PROTOKEY_AND_INITIALIZER) #undef PROTOKEY_AND_INITIALIZER JSProto_LIMIT -} JSProtoKey; - -/* js_CheckAccess mode enumeration. */ -typedef enum JSAccessMode { - JSACC_PROTO = 0, /* XXXbe redundant w.r.t. id */ - - /* - * enum value #1 formerly called JSACC_PARENT, - * gap preserved for ABI compatibility. - */ - - /* - * enum value #2 formerly called JSACC_IMPORT, - * gap preserved for ABI compatibility. - */ - - JSACC_WATCH = 3, /* a watchpoint on object foo for id 'bar' */ - JSACC_READ = 4, /* a "get" of foo.bar */ - JSACC_WRITE = 8, /* a "set" of foo.bar = baz */ - JSACC_LIMIT -} JSAccessMode; - -#define JSACC_TYPEMASK (JSACC_WRITE - 1) +}; /* * This enum type is used to control the behavior of a JSObject property * iterator function that has type JSNewEnumerate. */ -typedef enum JSIterateOp { +enum JSIterateOp { /* Create new iterator state over enumerable properties. */ JSENUMERATE_INIT, @@ -117,12 +99,13 @@ typedef enum JSIterateOp { /* Destroy iterator state. */ JSENUMERATE_DESTROY -} JSIterateOp; +}; -/* See JSVAL_TRACE_KIND and JSTraceCallback in jsapi.h. */ -typedef enum { +/* See Value::gcKind() and JSTraceCallback in Tracer.h. */ +enum JSGCTraceKind { JSTRACE_OBJECT, JSTRACE_STRING, + JSTRACE_SYMBOL, JSTRACE_SCRIPT, /* @@ -130,37 +113,36 @@ typedef enum { * it implements JSTraceCallback. */ JSTRACE_LAZY_SCRIPT, - JSTRACE_IONCODE, + JSTRACE_JITCODE, JSTRACE_SHAPE, JSTRACE_BASE_SHAPE, JSTRACE_TYPE_OBJECT, JSTRACE_LAST = JSTRACE_TYPE_OBJECT -} JSGCTraceKind; - -/* Struct typedefs and class forward declarations. */ -typedef struct JSClass JSClass; -typedef struct JSCompartment JSCompartment; -typedef struct JSConstDoubleSpec JSConstDoubleSpec; -typedef struct JSCrossCompartmentCall JSCrossCompartmentCall; -typedef struct JSErrorReport JSErrorReport; -typedef struct JSExceptionState JSExceptionState; -typedef struct JSFunctionSpec JSFunctionSpec; -typedef struct JSIdArray JSIdArray; -typedef struct JSLocaleCallbacks JSLocaleCallbacks; -typedef struct JSObjectMap JSObjectMap; -typedef struct JSPrincipals JSPrincipals; -typedef struct JSPropertyDescriptor JSPropertyDescriptor; -typedef struct JSPropertyName JSPropertyName; -typedef struct JSPropertySpec JSPropertySpec; -typedef struct JSRuntime JSRuntime; -typedef struct JSSecurityCallbacks JSSecurityCallbacks; -typedef struct JSStructuredCloneCallbacks JSStructuredCloneCallbacks; -typedef struct JSStructuredCloneReader JSStructuredCloneReader; -typedef struct JSStructuredCloneWriter JSStructuredCloneWriter; -typedef struct JSTracer JSTracer; - -class JSFlatString; -class JSStableString; // long story +}; + +/* Struct forward declarations. */ +struct JSClass; +struct JSCompartment; +struct JSConstDoubleSpec; +struct JSCrossCompartmentCall; +struct JSErrorReport; +struct JSExceptionState; +struct JSFunctionSpec; +struct JSIdArray; +struct JSLocaleCallbacks; +struct JSObjectMap; +struct JSPrincipals; +struct JSPropertyDescriptor; +struct JSPropertyName; +struct JSPropertySpec; +struct JSRuntime; +struct JSSecurityCallbacks; +struct JSStructuredCloneCallbacks; +struct JSStructuredCloneReader; +struct JSStructuredCloneWriter; +class JS_PUBLIC_API(JSTracer); + +class JSFlatString; #ifdef JS_THREADSAFE typedef struct PRCallOnceType JSCallOnceType; @@ -182,6 +164,7 @@ namespace js { namespace gc { class StoreBuffer; void MarkPersistentRootedChains(JSTracer *); +void FinishPersistentRootedChains(JSRuntime *); } } @@ -197,24 +180,18 @@ struct Runtime bool needsBarrier_; #ifdef JSGC_GENERATIONAL - /* Allow inlining of Nursery::isInside. */ - uintptr_t gcNurseryStart_; - uintptr_t gcNurseryEnd_; - private: js::gc::StoreBuffer *gcStoreBufferPtr_; #endif public: - Runtime( + explicit Runtime( #ifdef JSGC_GENERATIONAL js::gc::StoreBuffer *storeBuffer #endif ) : needsBarrier_(false) #ifdef JSGC_GENERATIONAL - , gcNurseryStart_(0) - , gcNurseryEnd_(0) , gcStoreBufferPtr_(storeBuffer) #endif {} @@ -235,7 +212,7 @@ struct Runtime private: template friend class JS::PersistentRooted; friend void js::gc::MarkPersistentRootedChains(JSTracer *); - friend void ::js_FinishGC(JSRuntime *rt); + friend void js::gc::FinishPersistentRootedChains(JSRuntime *rt); mozilla::LinkedList functionPersistentRooteds; mozilla::LinkedList idPersistentRooteds; @@ -274,6 +251,75 @@ inline mozilla::LinkedList &Runtime::getPersistentRootedList() { return valuePersistentRooteds; } } /* namespace shadow */ + +class JS_PUBLIC_API(AutoGCRooter) +{ + public: + AutoGCRooter(JSContext *cx, ptrdiff_t tag); + AutoGCRooter(js::ContextFriendFields *cx, ptrdiff_t tag); + + ~AutoGCRooter() { + MOZ_ASSERT(this == *stackTop); + *stackTop = down; + } + + /* Implemented in gc/RootMarking.cpp. */ + inline void trace(JSTracer *trc); + static void traceAll(JSTracer *trc); + static void traceAllWrappers(JSTracer *trc); + + /* T must be a context type */ + template + static void traceAllInContext(T* cx, JSTracer *trc) { + for (AutoGCRooter *gcr = cx->autoGCRooters; gcr; gcr = gcr->down) + gcr->trace(trc); + } + + protected: + AutoGCRooter * const down; + + /* + * Discriminates actual subclass of this being used. If non-negative, the + * subclass roots an array of values of the length stored in this field. + * If negative, meaning is indicated by the corresponding value in the enum + * below. Any other negative value indicates some deeper problem such as + * memory corruption. + */ + ptrdiff_t tag_; + + enum { + VALARRAY = -2, /* js::AutoValueArray */ + PARSER = -3, /* js::frontend::Parser */ + SHAPEVECTOR = -4, /* js::AutoShapeVector */ + IDARRAY = -6, /* js::AutoIdArray */ + DESCVECTOR = -7, /* js::AutoPropDescVector */ + VALVECTOR = -10, /* js::AutoValueVector */ + IDVECTOR = -13, /* js::AutoIdVector */ + OBJVECTOR = -14, /* js::AutoObjectVector */ + STRINGVECTOR =-15, /* js::AutoStringVector */ + SCRIPTVECTOR =-16, /* js::AutoScriptVector */ + NAMEVECTOR = -17, /* js::AutoNameVector */ + HASHABLEVALUE=-18, /* js::HashableValue */ + IONMASM = -19, /* js::jit::MacroAssembler */ + IONALLOC = -20, /* js::jit::AutoTempAllocatorRooter */ + WRAPVECTOR = -21, /* js::AutoWrapperVector */ + WRAPPER = -22, /* js::AutoWrapperRooter */ + OBJOBJHASHMAP=-23, /* js::AutoObjectObjectHashMap */ + OBJU32HASHMAP=-24, /* js::AutoObjectUnsigned32HashMap */ + OBJHASHSET = -25, /* js::AutoObjectHashSet */ + JSONPARSER = -26, /* js::JSONParser */ + CUSTOM = -27, /* js::CustomAutoRooter */ + FUNVECTOR = -28 /* js::AutoFunctionVector */ + }; + + private: + AutoGCRooter ** const stackTop; + + /* No copy or assignment semantics. */ + AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; + void operator=(AutoGCRooter &ida) MOZ_DELETE; +}; + } /* namespace JS */ namespace js { @@ -287,13 +333,11 @@ namespace js { enum ParallelResult { TP_SUCCESS, TP_RETRY_SEQUENTIALLY, TP_RETRY_AFTER_GC, TP_FATAL }; struct ThreadSafeContext; -struct ForkJoinSlice; +class ForkJoinContext; class ExclusiveContext; class Allocator; -class SkipRoot; - enum ThingRootKind { THING_ROOT_OBJECT, @@ -301,14 +345,16 @@ enum ThingRootKind THING_ROOT_BASE_SHAPE, THING_ROOT_TYPE_OBJECT, THING_ROOT_STRING, - THING_ROOT_ION_CODE, + THING_ROOT_SYMBOL, + THING_ROOT_JIT_CODE, THING_ROOT_SCRIPT, + THING_ROOT_LAZY_SCRIPT, THING_ROOT_ID, - THING_ROOT_PROPERTY_ID, THING_ROOT_VALUE, THING_ROOT_TYPE, THING_ROOT_BINDINGS, THING_ROOT_PROPERTY_DESCRIPTOR, + THING_ROOT_PROP_DESC, THING_ROOT_LIMIT }; @@ -343,6 +389,7 @@ template <> struct RootKind : SpecificRootKind struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; @@ -364,9 +411,6 @@ struct ContextFriendFields { #ifdef JSGC_TRACK_EXACT_ROOTS mozilla::PodArrayZero(thingGCRooters); -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - skipGCRooters = nullptr; #endif } @@ -379,31 +423,31 @@ struct ContextFriendFields } #ifdef JSGC_TRACK_EXACT_ROOTS + private: /* * Stack allocated GC roots for stack GC heap pointers, which may be * overwritten if moved during a GC. */ JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* - * Stack allocated list of stack locations which hold non-relocatable - * GC heap pointers (where the target is rooted somewhere else) or integer - * values which may be confused for GC heap pointers. These are used to - * suppress false positives which occur when a rooting analysis treats the - * location as holding a relocatable pointer, but have no other effect on - * GC behavior. - */ - SkipRoot *skipGCRooters; + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } + #endif + void checkNoGCRooters(); + /* Stack of thread-stack-allocated GC roots. */ JS::AutoGCRooter *autoGCRooters; friend JSRuntime *GetRuntime(const JSContext *cx); friend JSCompartment *GetContextCompartment(const JSContext *cx); friend JS::Zone *GetContextZone(const JSContext *cx); + template friend class JS::Rooted; }; /* @@ -447,7 +491,7 @@ struct PerThreadDataFriendFields struct PerThreadDummy { void *field1; uintptr_t field2; -#ifdef DEBUG +#ifdef JS_DEBUG uint64_t field3; #endif } mainThread; @@ -458,23 +502,19 @@ struct PerThreadDataFriendFields PerThreadDataFriendFields(); #ifdef JSGC_TRACK_EXACT_ROOTS + private: /* * Stack allocated GC roots for stack GC heap pointers, which may be * overwritten if moved during a GC. */ JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* - * Stack allocated list of stack locations which hold non-relocatable - * GC heap pointers (where the target is rooted somewhere else) or integer - * values which may be confused for GC heap pointers. These are used to - * suppress false positives which occur when a rooting analysis treats the - * location as holding a relocatable pointer, but have no other effect on - * GC behavior. - */ - SkipRoot *skipGCRooters; + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } #endif /* Limit pointer for checking native stack consumption. */ @@ -499,6 +539,8 @@ struct PerThreadDataFriendFields return reinterpret_cast( reinterpret_cast(rt) + RuntimeMainThreadOffset); } + + template friend class JS::Rooted; }; } /* namespace js */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/jstypes.h b/frameworks/js-bindings/external/spidermonkey/include/ios/jstypes.h index d5b15ccb1d..e9927bca0d 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/jstypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/jstypes.h @@ -77,8 +77,13 @@ # define JS_PUBLIC_DATA(t) MOZ_IMPORT_DATA t #endif -#define JS_FRIEND_API(t) JS_PUBLIC_API(t) -#define JS_FRIEND_DATA(t) JS_PUBLIC_DATA(t) +#if defined(STATIC_JS_API) || defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API) +# define JS_FRIEND_API(t) MOZ_EXPORT t +# define JS_FRIEND_DATA(t) MOZ_EXPORT t +#else +# define JS_FRIEND_API(t) MOZ_IMPORT_API t +# define JS_FRIEND_DATA(t) MOZ_IMPORT_DATA t +#endif #if defined(_MSC_VER) && defined(_M_IX86) #define JS_FASTCALL __fastcall @@ -89,22 +94,6 @@ #define JS_NO_FASTCALL #endif -#ifndef JS_ALWAYS_INLINE -#define JS_ALWAYS_INLINE MOZ_ALWAYS_INLINE -#endif - -#ifndef JS_NEVER_INLINE -#define JS_NEVER_INLINE MOZ_NEVER_INLINE -#endif - -#ifndef JS_WARN_UNUSED_RESULT -# if defined __GNUC__ -# define JS_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -# else -# define JS_WARN_UNUSED_RESULT -# endif -#endif - /*********************************************************************** ** MACROS: JS_BEGIN_MACRO ** JS_END_MACRO @@ -122,15 +111,6 @@ # define JS_END_MACRO } while (0) #endif -/*********************************************************************** -** MACROS: JS_BEGIN_EXTERN_C -** JS_END_EXTERN_C -** DESCRIPTION: -** Macro shorthands for conditional C++ extern block delimiters. -***********************************************************************/ -#define JS_BEGIN_EXTERN_C MOZ_BEGIN_EXTERN_C -#define JS_END_EXTERN_C MOZ_END_EXTERN_C - /*********************************************************************** ** MACROS: JS_BIT ** JS_BITMASK @@ -143,8 +123,6 @@ /*********************************************************************** ** MACROS: JS_HOWMANY ** JS_ROUNDUP -** JS_MIN -** JS_MAX ** DESCRIPTION: ** Commonly used macros for operations on compatible types. ***********************************************************************/ @@ -183,34 +161,6 @@ # error "Implement me" #endif -/*********************************************************************** -** MACROS: JS_LIKELY -** JS_UNLIKELY -** DESCRIPTION: -** These macros allow you to give a hint to the compiler about branch -** probability so that it can better optimize. Use them like this: -** -** if (JS_LIKELY(v == 1)) { -** ... expected code path ... -** } -** -** if (JS_UNLIKELY(v == 0)) { -** ... non-expected code path ... -** } -** -***********************************************************************/ -#ifdef __GNUC__ - -# define JS_LIKELY(x) (__builtin_expect((x), 1)) -# define JS_UNLIKELY(x) (__builtin_expect((x), 0)) - -#else - -# define JS_LIKELY(x) (x) -# define JS_UNLIKELY(x) (x) - -#endif - /*********************************************************************** ** MACROS: JS_ARRAY_LENGTH ** JS_ARRAY_END diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/jsversion.h b/frameworks/js-bindings/external/spidermonkey/include/ios/jsversion.h index 827a56981d..1f31e40b5e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/jsversion.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/jsversion.h @@ -25,6 +25,9 @@ #define JS_HAS_DESTRUCTURING 2 /* has [a,b] = ... or {p:a,q:b} = ... */ #define JS_HAS_GENERATOR_EXPRS 1 /* has (expr for (lhs in iterable)) */ #define JS_HAS_EXPR_CLOSURES 1 /* has function (formals) listexpr */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_TEMPLATE_STRINGS 1 /* has template string support */ +#endif /* Support for JS_NewGlobalObject. */ #define JS_HAS_NEW_GLOBAL_OBJECT 1 @@ -41,14 +44,9 @@ */ #define JS_OLD_GETTER_SETTER_METHODS 1 -/* A kill-switch for bug 586842. Embedders shouldn't touch this! */ -#define JS_USE_NEW_OBJECT_REPRESENTATION 0 - -#if JS_USE_NEW_OBJECT_REPRESENTATION -# define JS_NEW_OBJECT_REPRESENTATION_ONLY() ((void)0) -#else -# define JS_NEW_OBJECT_REPRESENTATION_ONLY() \ - MOZ_ASSUME_UNREACHABLE("don't call this! to be used in the new object representation") +/* Support for Symbols - Nightly-only for now. */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_SYMBOLS 1 #endif #endif /* jsversion_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/jswrapper.h b/frameworks/js-bindings/external/spidermonkey/include/ios/jswrapper.h index 1bf1e16664..a8a510c4f7 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/jswrapper.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/jswrapper.h @@ -15,6 +15,35 @@ namespace js { class DummyFrameGuard; +/* + * Helper for Wrapper::New default options. + * + * Callers of Wrapper::New() who wish to specify a prototype for the created + * Wrapper, *MUST* construct a WrapperOptions with a JSContext. + */ +class MOZ_STACK_CLASS WrapperOptions : public ProxyOptions { + public: + WrapperOptions() : ProxyOptions(false, nullptr), + proto_() + {} + + explicit WrapperOptions(JSContext *cx) : ProxyOptions(false, nullptr), + proto_() + { + proto_.construct(cx); + } + + inline JSObject *proto() const; + WrapperOptions &setProto(JSObject *protoArg) { + JS_ASSERT(!proto_.empty()); + proto_.ref() = protoArg; + return *this; + } + + private: + mozilla::Maybe proto_; +}; + /* * A wrapper is a proxy with a target object to which it generally forwards * operations, but may restrict access to certain operations or instrument @@ -27,7 +56,6 @@ class DummyFrameGuard; class JS_FRIEND_API(Wrapper) : public DirectProxyHandler { unsigned mFlags; - bool mSafeToUnwrap; public: using BaseProxyHandler::Action; @@ -38,23 +66,14 @@ class JS_FRIEND_API(Wrapper) : public DirectProxyHandler }; virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; - /* - * Wrappers can explicitly specify that they are unsafe to unwrap from a - * security perspective (as is the case for SecurityWrappers). If a wrapper - * is not safe to unwrap, operations requiring full access to the underlying - * object (via CheckedUnwrap) will throw. Otherwise, they will succeed. - */ - void setSafeToUnwrap(bool safe) { mSafeToUnwrap = safe; } - bool isSafeToUnwrap() { return mSafeToUnwrap; } + static JSObject *New(JSContext *cx, JSObject *obj, JSObject *parent, const Wrapper *handler, + const WrapperOptions *options = nullptr); - static JSObject *New(JSContext *cx, JSObject *obj, JSObject *proto, - JSObject *parent, Wrapper *handler); + static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, const Wrapper *handler); - static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, Wrapper *handler); - - static Wrapper *wrapperHandler(JSObject *wrapper); + static const Wrapper *wrapperHandler(JSObject *wrapper); static JSObject *wrappedObject(JSObject *wrapper); @@ -62,68 +81,78 @@ class JS_FRIEND_API(Wrapper) : public DirectProxyHandler return mFlags; } - explicit Wrapper(unsigned flags, bool hasPrototype = false); + explicit Wrapper(unsigned flags, bool hasPrototype = false, bool hasSecurityPolicy = false); virtual ~Wrapper(); - virtual bool finalizeInBackground(Value priv) MOZ_OVERRIDE; + virtual bool finalizeInBackground(Value priv) const MOZ_OVERRIDE; + + static const Wrapper singleton; + static const Wrapper singletonWithPrototype; - static Wrapper singleton; - static Wrapper singletonWithPrototype; + static JSObject *defaultProto; }; +inline JSObject * +WrapperOptions::proto() const +{ + return proto_.empty() ? Wrapper::defaultProto : proto_.ref(); +} + /* Base class for all cross compartment wrapper handlers. */ class JS_FRIEND_API(CrossCompartmentWrapper) : public Wrapper { public: - CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false); + explicit CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false, + bool hasSecurityPolicy = false); virtual ~CrossCompartmentWrapper(); /* ES5 Harmony fundamental wrapper traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, - AutoIdVector &props) MOZ_OVERRIDE; - virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; /* ES5 Harmony derived wrapper traps. */ - virtual bool has(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool hasOwn(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; + virtual bool has(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool hasOwn(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; virtual bool get(JSContext *cx, HandleObject wrapper, HandleObject receiver, - HandleId id, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool set(JSContext *cx, HandleObject wrapper, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool keys(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool keys(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; virtual bool iterate(JSContext *cx, HandleObject wrapper, unsigned flags, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject wrapper, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject wrapper, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject wrapper, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual JSString *fun_toString(JSContext *cx, HandleObject wrapper, - unsigned indent) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; - static CrossCompartmentWrapper singleton; - static CrossCompartmentWrapper singletonWithPrototype; + static const CrossCompartmentWrapper singleton; + static const CrossCompartmentWrapper singletonWithPrototype; }; /* @@ -139,25 +168,28 @@ template class JS_FRIEND_API(SecurityWrapper) : public Base { public: - SecurityWrapper(unsigned flags); + explicit SecurityWrapper(unsigned flags, bool hasPrototype = false); - virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) MOZ_OVERRIDE; - virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Wrapper::Action act, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; + + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable) MOZ_OVERRIDE; - virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) MOZ_OVERRIDE; + JS::HandleObject callable) const MOZ_OVERRIDE; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const MOZ_OVERRIDE; /* * Allow our subclasses to select the superclass behavior they want without @@ -179,48 +211,42 @@ class JS_FRIEND_API(DeadObjectProxy) : public BaseProxyHandler explicit DeadObjectProxy(); /* ES5 Harmony fundamental wrapper traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, - AutoIdVector &props) MOZ_OVERRIDE; - virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; - virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver, - uint32_t index, MutableHandleValue vp, - bool *present) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, - MutableHandleObject protop) MOZ_OVERRIDE; + MutableHandleObject protop) const MOZ_OVERRIDE; - static DeadObjectProxy singleton; + static const DeadObjectProxy singleton; }; extern JSObject * TransparentObjectWrapper(JSContext *cx, HandleObject existing, HandleObject obj, - HandleObject wrappedProto, HandleObject parent, - unsigned flags); + HandleObject parent, unsigned flags); // Proxy family for wrappers. Public so that IsWrapper() can be fully inlined by // jsfriendapi users. @@ -295,8 +321,8 @@ RecomputeWrappers(JSContext *cx, const CompartmentFilter &sourceFilter, struct JS_FRIEND_API(AutoMaybeTouchDeadZones) { // The version that takes an object just uses it for its runtime. - AutoMaybeTouchDeadZones(JSContext *cx); - AutoMaybeTouchDeadZones(JSObject *obj); + explicit AutoMaybeTouchDeadZones(JSContext *cx); + explicit AutoMaybeTouchDeadZones(JSObject *obj); ~AutoMaybeTouchDeadZones(); private: diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Alignment.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Alignment.h index 29599d0ef1..0ac8a48779 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Alignment.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Alignment.h @@ -21,14 +21,14 @@ namespace mozilla { template class AlignmentFinder { - struct Aligner - { - char c; - T t; - }; - - public: - static const size_t alignment = sizeof(Aligner) - sizeof(T); + struct Aligner + { + char mChar; + T mT; + }; + +public: + static const size_t alignment = sizeof(Aligner) - sizeof(T); }; #define MOZ_ALIGNOF(T) mozilla::AlignmentFinder::alignment @@ -64,38 +64,38 @@ template struct AlignedElem; /* - * We have to specialize this template because GCC doesn't like __attribute__((aligned(foo))) where - * foo is a template parameter. + * We have to specialize this template because GCC doesn't like + * __attribute__((aligned(foo))) where foo is a template parameter. */ template<> struct AlignedElem<1> { - MOZ_ALIGNED_DECL(uint8_t elem, 1); + MOZ_ALIGNED_DECL(uint8_t elem, 1); }; template<> struct AlignedElem<2> { - MOZ_ALIGNED_DECL(uint8_t elem, 2); + MOZ_ALIGNED_DECL(uint8_t elem, 2); }; template<> struct AlignedElem<4> { - MOZ_ALIGNED_DECL(uint8_t elem, 4); + MOZ_ALIGNED_DECL(uint8_t elem, 4); }; template<> struct AlignedElem<8> { - MOZ_ALIGNED_DECL(uint8_t elem, 8); + MOZ_ALIGNED_DECL(uint8_t elem, 8); }; template<> struct AlignedElem<16> { - MOZ_ALIGNED_DECL(uint8_t elem, 16); + MOZ_ALIGNED_DECL(uint8_t elem, 16); }; /* @@ -111,25 +111,27 @@ struct AlignedElem<16> template struct AlignedStorage { - union U { - char bytes[Nbytes]; - uint64_t _; - } u; - - const void* addr() const { return u.bytes; } - void* addr() { return u.bytes; } + union U + { + char mBytes[Nbytes]; + uint64_t mDummy; + } u; + + const void* addr() const { return u.mBytes; } + void* addr() { return u.mBytes; } }; template struct AlignedStorage2 { - union U { - char bytes[sizeof(T)]; - uint64_t _; - } u; - - const T* addr() const { return reinterpret_cast(u.bytes); } - T* addr() { return static_cast(static_cast(u.bytes)); } + union U + { + char mBytes[sizeof(T)]; + uint64_t mDummy; + } u; + + const T* addr() const { return reinterpret_cast(u.mBytes); } + T* addr() { return static_cast(static_cast(u.mBytes)); } }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/AllocPolicy.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/AllocPolicy.h index 20087e93bb..357c632a02 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/AllocPolicy.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/AllocPolicy.h @@ -49,14 +49,31 @@ namespace mozilla { */ class MallocAllocPolicy { - public: - void* malloc_(size_t bytes) { return malloc(bytes); } - void* calloc_(size_t bytes) { return calloc(bytes, 1); } - void* realloc_(void* p, size_t oldBytes, size_t bytes) { return realloc(p, bytes); } - void free_(void* p) { free(p); } - void reportAllocOverflow() const {} -}; +public: + void* malloc_(size_t aBytes) + { + return malloc(aBytes); + } + + void* calloc_(size_t aBytes) + { + return calloc(aBytes, 1); + } + + void* realloc_(void* aPtr, size_t aOldBytes, size_t aBytes) + { + return realloc(aPtr, aBytes); + } + void free_(void* aPtr) + { + free(aPtr); + } + + void reportAllocOverflow() const + { + } +}; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Array.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Array.h index 5af9aaa133..b2ab578d4b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Array.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Array.h @@ -19,31 +19,35 @@ namespace mozilla { template class Array { - T arr[Length]; - - public: - T& operator[](size_t i) { - MOZ_ASSERT(i < Length); - return arr[i]; - } - - const T& operator[](size_t i) const { - MOZ_ASSERT(i < Length); - return arr[i]; - } + T mArr[Length]; + +public: + T& operator[](size_t aIndex) + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } + + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } }; template class Array { - public: - T& operator[](size_t i) { - MOZ_ASSUME_UNREACHABLE("indexing into zero-length array"); - } - - const T& operator[](size_t i) const { - MOZ_ASSUME_UNREACHABLE("indexing into zero-length array"); - } +public: + T& operator[](size_t aIndex) + { + MOZ_CRASH("indexing into zero-length array"); + } + + const T& operator[](size_t aIndex) const + { + MOZ_CRASH("indexing into zero-length array"); + } }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ArrayUtils.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ArrayUtils.h index e2226bf59d..44f5980c44 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ArrayUtils.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ArrayUtils.h @@ -18,22 +18,24 @@ #ifdef __cplusplus +#include "mozilla/Alignment.h" #include "mozilla/Array.h" +#include "mozilla/TypeTraits.h" namespace mozilla { /* - * Safely subtract two pointers when it is known that end >= begin. This avoids - * the common compiler bug that if (size_t(end) - size_t(begin)) has the MSB - * set, the unsigned subtraction followed by right shift will produce -1, or - * size_t(-1), instead of the real difference. + * Safely subtract two pointers when it is known that aEnd >= aBegin. This + * avoids the common compiler bug that if (size_t(aEnd) - size_t(aBegin)) has + * the MSB set, the unsigned subtraction followed by right shift will produce + * -1, or size_t(-1), instead of the real difference. */ template MOZ_ALWAYS_INLINE size_t -PointerRangeSize(T* begin, T* end) +PointerRangeSize(T* aBegin, T* aEnd) { - MOZ_ASSERT(end >= begin); - return (size_t(end) - size_t(begin)) / sizeof(T); + MOZ_ASSERT(aEnd >= aBegin); + return (size_t(aEnd) - size_t(aBegin)) / sizeof(T); } /* @@ -44,14 +46,14 @@ PointerRangeSize(T* begin, T* end) */ template MOZ_CONSTEXPR size_t -ArrayLength(T (&arr)[N]) +ArrayLength(T (&aArr)[N]) { return N; } template MOZ_CONSTEXPR size_t -ArrayLength(const Array& arr) +ArrayLength(const Array& aArr) { return N; } @@ -63,25 +65,100 @@ ArrayLength(const Array& arr) */ template MOZ_CONSTEXPR T* -ArrayEnd(T (&arr)[N]) +ArrayEnd(T (&aArr)[N]) { - return arr + ArrayLength(arr); + return aArr + ArrayLength(aArr); } template MOZ_CONSTEXPR T* -ArrayEnd(Array& arr) +ArrayEnd(Array& aArr) { - return &arr[0] + ArrayLength(arr); + return &aArr[0] + ArrayLength(aArr); } template MOZ_CONSTEXPR const T* -ArrayEnd(const Array& arr) +ArrayEnd(const Array& aArr) { - return &arr[0] + ArrayLength(arr); + return &aArr[0] + ArrayLength(aArr); } +namespace detail { + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % MOZ_ALIGNOF(AlignType)) == 0, + "performing a range-check with a misaligned pointer"); + } +}; + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + } +}; + +} // namespace detail + +/** + * Determines whether |aPtr| points at an object in the range [aBegin, aEnd). + * + * |aPtr| must have the same alignment as |aBegin| and |aEnd|. This usually + * should be achieved by ensuring |aPtr| points at a |U|, not just that it + * points at a |T|. + * + * It is a usage error for any argument to be misaligned. + * + * It's okay for T* to be void*, and if so U* may also be void*. In the latter + * case no argument is required to be aligned (obviously, as void* implies no + * particular alignment). + */ +template +inline typename EnableIf::value || + IsBaseOf::value || + IsVoid::value, + bool>::Type +IsInRange(T* aPtr, U* aBegin, U* aEnd) +{ + MOZ_ASSERT(aBegin <= aEnd); + detail::AlignedChecker::test(aPtr); + detail::AlignedChecker::test(aBegin); + detail::AlignedChecker::test(aEnd); + return aBegin <= static_cast(aPtr) && static_cast(aPtr) < aEnd; +} + +/** + * Convenience version of the above method when the valid range is specified as + * uintptr_t values. As above, |aPtr| must be aligned, and |aBegin| and |aEnd| + * must be aligned with respect to |T|. + */ +template +inline bool +IsInRange(T* aPtr, uintptr_t aBegin, uintptr_t aEnd) +{ + return IsInRange(aPtr, + reinterpret_cast(aBegin), reinterpret_cast(aEnd)); +} + +namespace detail { + +/* + * Helper for the MOZ_ARRAY_LENGTH() macro to make the length a typesafe + * compile-time constant even on compilers lacking constexpr support. + */ +template +char (&ArrayLengthHelper(T (&array)[N]))[N]; + +} /* namespace detail */ + } /* namespace mozilla */ #endif /* __cplusplus */ @@ -91,8 +168,8 @@ ArrayEnd(const Array& arr) * that can't use C++ template functions and for static_assert() calls that * can't call ArrayLength() when it is not a C++11 constexpr function. */ -#ifdef MOZ_HAVE_CXX11_CONSTEXPR -# define MOZ_ARRAY_LENGTH(array) mozilla::ArrayLength(array) +#ifdef __cplusplus +# define MOZ_ARRAY_LENGTH(array) sizeof(mozilla::detail::ArrayLengthHelper(array)) #else # define MOZ_ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0])) #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Assertions.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Assertions.h index 8a5fa205f9..a463b2768d 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Assertions.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Assertions.h @@ -9,9 +9,17 @@ #ifndef mozilla_Assertions_h #define mozilla_Assertions_h +#if defined(MOZILLA_INTERNAL_API) && defined(__cplusplus) +#define MOZ_DUMP_ASSERTION_STACK +#endif + #include "mozilla/Attributes.h" #include "mozilla/Compiler.h" #include "mozilla/Likely.h" +#include "mozilla/MacroArgs.h" +#ifdef MOZ_DUMP_ASSERTION_STACK +#include "nsTraceRefcnt.h" +#endif #include #include @@ -24,13 +32,13 @@ * number of undesired macros and symbols. */ # ifdef __cplusplus - extern "C" { +extern "C" { # endif - __declspec(dllimport) int __stdcall - TerminateProcess(void* hProcess, unsigned int uExitCode); - __declspec(dllimport) void* __stdcall GetCurrentProcess(void); +__declspec(dllimport) int __stdcall +TerminateProcess(void* hProcess, unsigned int uExitCode); +__declspec(dllimport) void* __stdcall GetCurrentProcess(void); # ifdef __cplusplus - } +} # endif #else # include @@ -116,33 +124,42 @@ extern "C" { #endif /* - * Prints |s| as an assertion failure (using file and ln as the location of the - * assertion) to the standard debug-output channel. + * Prints |aStr| as an assertion failure (using aFilename and aLine as the + * location of the assertion) to the standard debug-output channel. * * Usually you should use MOZ_ASSERT or MOZ_CRASH instead of this method. This * method is primarily for internal use in this header, and only secondarily * for use in implementing release-build assertions. */ static MOZ_ALWAYS_INLINE void -MOZ_ReportAssertionFailure(const char* s, const char* file, int ln) +MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS { #ifdef ANDROID __android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert", - "Assertion failure: %s, at %s:%d\n", s, file, ln); + "Assertion failure: %s, at %s:%d\n", + aStr, aFilename, aLine); #else - fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln); + fprintf(stderr, "Assertion failure: %s, at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif fflush(stderr); #endif } static MOZ_ALWAYS_INLINE void -MOZ_ReportCrash(const char* s, const char* file, int ln) +MOZ_ReportCrash(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS { #ifdef ANDROID - __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", - "Hit MOZ_CRASH(%s) at %s:%d\n", s, file, ln); + __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", + "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); #else - fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", s, file, ln); + fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif fflush(stderr); #endif } @@ -238,7 +255,7 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} do { \ MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \ MOZ_REALLY_CRASH(); \ - } while(0) + } while (0) #endif #ifdef __cplusplus @@ -279,52 +296,108 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} * MOZ_RELEASE_ASSERT, which applies to non-debug builds as well. */ +/* + * Implement MOZ_VALIDATE_ASSERT_CONDITION_TYPE, which is used to guard against + * accidentally passing something unintended in lieu of an assertion condition. + */ + +#ifdef __cplusplus +# if defined(__clang__) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# elif defined(__GNUC__) +// B2G GCC 4.4 has insufficient decltype support. +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# endif +# elif defined(_MSC_VER) +// Disabled for now because of insufficient decltype support. Bug 1004028. +# endif +#endif + +#ifdef MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# include "mozilla/TypeTraits.h" +namespace mozilla { +namespace detail { + +template +struct IsFunction +{ + static const bool value = false; +}; + +template +struct IsFunction +{ + static const bool value = true; +}; + +template +void ValidateAssertConditionType() +{ + typedef typename RemoveReference::Type ValueT; + static_assert(!IsArray::value, + "Expected boolean assertion condition, got an array or a " + "string!"); + static_assert(!IsFunction::value, + "Expected boolean assertion condition, got a function! Did " + "you intend to call that function?"); + static_assert(!IsFloatingPoint::value, + "It's often a bad idea to assert that a floating-point number " + "is nonzero, because such assertions tend to intermittently " + "fail. Shouldn't your code gracefully handle this case instead " + "of asserting? Anyway, if you really want to do that, write an " + "explicit boolean condition, like !!x or x!=0."); +} + +} // namespace detail +} // namespace mozilla +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) \ + mozilla::detail::ValidateAssertConditionType() +#else +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) +#endif + /* First the single-argument form. */ #define MOZ_ASSERT_HELPER1(expr) \ - do { \ - if (MOZ_UNLIKELY(!(expr))) { \ - MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } \ - } while (0) + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) /* Now the two-argument form. */ #define MOZ_ASSERT_HELPER2(expr, explain) \ - do { \ - if (MOZ_UNLIKELY(!(expr))) { \ - MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } \ - } while (0) -/* And now, helper macrology up the wazoo. */ -/* - * Count the number of arguments passed to MOZ_ASSERT, very carefully - * tiptoeing around an MSVC bug where it improperly expands __VA_ARGS__ as a - * single token in argument lists. See these URLs for details: - * - * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement - * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 - */ -#define MOZ_COUNT_ASSERT_ARGS_IMPL2(_1, _2, count, ...) \ - count -#define MOZ_COUNT_ASSERT_ARGS_IMPL(args) \ - MOZ_COUNT_ASSERT_ARGS_IMPL2 args -#define MOZ_COUNT_ASSERT_ARGS(...) \ - MOZ_COUNT_ASSERT_ARGS_IMPL((__VA_ARGS__, 2, 1, 0)) -/* Pick the right helper macro to invoke. */ -#define MOZ_ASSERT_CHOOSE_HELPER2(count) MOZ_ASSERT_HELPER##count -#define MOZ_ASSERT_CHOOSE_HELPER1(count) MOZ_ASSERT_CHOOSE_HELPER2(count) -#define MOZ_ASSERT_CHOOSE_HELPER(count) MOZ_ASSERT_CHOOSE_HELPER1(count) -/* The actual macros. */ -#define MOZ_ASSERT_GLUE(x, y) x y + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) + +#define MOZ_RELEASE_ASSERT_GLUE(a, b) a b #define MOZ_RELEASE_ASSERT(...) \ - MOZ_ASSERT_GLUE(MOZ_ASSERT_CHOOSE_HELPER(MOZ_COUNT_ASSERT_ARGS(__VA_ARGS__)), \ - (__VA_ARGS__)) + MOZ_RELEASE_ASSERT_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \ + (__VA_ARGS__)) + #ifdef DEBUG # define MOZ_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) #else -# define MOZ_ASSERT(...) do { } while(0) +# define MOZ_ASSERT(...) do { } while (0) #endif /* DEBUG */ +/* + * MOZ_NIGHTLY_ASSERT is defined for both debug and release builds on the + * Nightly channel, but only debug builds on Aurora, Beta, and Release. + */ +#if defined(NIGHTLY_BUILD) +# define MOZ_NIGHTLY_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) +#else +# define MOZ_NIGHTLY_ASSERT(...) MOZ_ASSERT(__VA_ARGS__) +#endif + /* * MOZ_ASSERT_IF(cond1, cond2) is equivalent to MOZ_ASSERT(cond2) if cond1 is * true. @@ -337,19 +410,20 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} #ifdef DEBUG # define MOZ_ASSERT_IF(cond, expr) \ do { \ - if (cond) \ + if (cond) { \ MOZ_ASSERT(expr); \ + } \ } while (0) #else # define MOZ_ASSERT_IF(cond, expr) do { } while (0) #endif /* - * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that it is - * undefined behavior for execution to reach this point. No guarantees are made - * about what will happen if this is reached at runtime. Most code should - * probably use the higher level MOZ_ASSUME_UNREACHABLE, which uses this when - * appropriate. + * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that + * it is undefined behavior for execution to reach this point. No guarantees + * are made about what will happen if this is reached at runtime. Most code + * should use MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE because it has extra + * asserts. */ #if defined(__clang__) # define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable() @@ -379,21 +453,22 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} #endif /* - * MOZ_ASSUME_UNREACHABLE([reason]) tells the compiler that it can assume that - * the macro call cannot be reached during execution. This lets the compiler - * generate better-optimized code under some circumstances, at the expense of - * the program's behavior being undefined if control reaches the - * MOZ_ASSUME_UNREACHABLE. + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE([reason]) tells the compiler that it + * can assume that the macro call cannot be reached during execution. This lets + * the compiler generate better-optimized code under some circumstances, at the + * expense of the program's behavior being undefined if control reaches the + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE. * * In Gecko, you probably should not use this macro outside of performance- or * size-critical code, because it's unsafe. If you don't care about code size * or performance, you should probably use MOZ_ASSERT or MOZ_CRASH. * * SpiderMonkey is a different beast, and there it's acceptable to use - * MOZ_ASSUME_UNREACHABLE more widely. + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE more widely. * - * Note that MOZ_ASSUME_UNREACHABLE is noreturn, so it's valid not to return a - * value following a MOZ_ASSUME_UNREACHABLE call. + * Note that MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE is noreturn, so it's valid + * not to return a value following a MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE + * call. * * Example usage: * @@ -413,19 +488,32 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} * case VALUE_FLOAT: * return (int) *(float*) value; * default: - * MOZ_ASSUME_UNREACHABLE("can only handle VALUE_INT and VALUE_FLOAT"); + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected ValueType"); * } * } */ -#if defined(DEBUG) -# define MOZ_ASSUME_UNREACHABLE(...) \ - do { \ - MOZ_ASSERT(false, "MOZ_ASSUME_UNREACHABLE(" __VA_ARGS__ ")"); \ - MOZ_ASSUME_UNREACHABLE_MARKER(); \ - } while (0) -#else -# define MOZ_ASSUME_UNREACHABLE(reason) MOZ_ASSUME_UNREACHABLE_MARKER() -#endif + +/* + * Assert in all debug builds plus the Nightly channel's release builds. Take + * this extra testing precaution because hitting MOZ_ASSUME_UNREACHABLE_MARKER + * could trigger exploitable undefined behavior. + */ +#define MOZ_ASSERT_UNREACHABLE(reason) \ + MOZ_NIGHTLY_ASSERT(false, "MOZ_ASSERT_UNREACHABLE: " reason) + +#define MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) \ + do { \ + MOZ_ASSERT_UNREACHABLE(reason); \ + MOZ_ASSUME_UNREACHABLE_MARKER(); \ + } while (0) + +/* + * TODO: Bug 990764: Audit all MOZ_ASSUME_UNREACHABLE calls and replace them + * with MOZ_ASSERT_UNREACHABLE, MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE, or + * MOZ_CRASH. For now, preserve the macro's same meaning of unreachable. + */ +#define MOZ_ASSUME_UNREACHABLE(reason) \ + MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) /* * MOZ_ALWAYS_TRUE(expr) and MOZ_ALWAYS_FALSE(expr) always evaluate the provided @@ -441,4 +529,6 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} # define MOZ_ALWAYS_FALSE(expr) ((void)(expr)) #endif +#undef MOZ_DUMP_ASSERTION_STACK + #endif /* mozilla_Assertions_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Atomics.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Atomics.h index 03ae7c34f3..71d95c61ba 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Atomics.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Atomics.h @@ -41,6 +41,13 @@ # define MOZ_HAVE_CXX11_ATOMICS # endif #elif defined(_MSC_VER) && _MSC_VER >= 1700 +# if defined(DEBUG) + /* + * Provide our own failure code since we're having trouble linking to + * std::_Debug_message (bug 982310). + */ +# define _INVALID_MEMORY_ORDER MOZ_CRASH("Invalid memory order") +# endif # define MOZ_HAVE_CXX11_ATOMICS #endif @@ -107,6 +114,7 @@ enum MemoryOrdering { * ordering if you can't easily test non-x86 architectures! */ Relaxed, + /* * When an atomic value is updated with ReleaseAcquire ordering, and * that new value is observed with ReleaseAcquire ordering, prior @@ -128,6 +136,7 @@ enum MemoryOrdering { * a good, hard look at actual lock or mutex primitives first. */ ReleaseAcquire, + /* * When an atomic value is updated with SequentiallyConsistent * ordering, all writes observable when the update is observed, just @@ -177,126 +186,154 @@ template struct AtomicOrderConstraints; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_relaxed; - static const std::memory_order LoadOrder = std::memory_order_relaxed; - static const std::memory_order StoreOrder = std::memory_order_relaxed; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_relaxed; + static const std::memory_order AtomicRMWOrder = std::memory_order_relaxed; + static const std::memory_order LoadOrder = std::memory_order_relaxed; + static const std::memory_order StoreOrder = std::memory_order_relaxed; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_relaxed; }; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_acq_rel; - static const std::memory_order LoadOrder = std::memory_order_acquire; - static const std::memory_order StoreOrder = std::memory_order_release; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_acquire; + static const std::memory_order AtomicRMWOrder = std::memory_order_acq_rel; + static const std::memory_order LoadOrder = std::memory_order_acquire; + static const std::memory_order StoreOrder = std::memory_order_release; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_acquire; }; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_seq_cst; - static const std::memory_order LoadOrder = std::memory_order_seq_cst; - static const std::memory_order StoreOrder = std::memory_order_seq_cst; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_seq_cst; + static const std::memory_order AtomicRMWOrder = std::memory_order_seq_cst; + static const std::memory_order LoadOrder = std::memory_order_seq_cst; + static const std::memory_order StoreOrder = std::memory_order_seq_cst; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_seq_cst; }; template struct IntrinsicBase { - typedef std::atomic ValueType; - typedef AtomicOrderConstraints OrderedOp; + typedef std::atomic ValueType; + typedef AtomicOrderConstraints OrderedOp; }; template struct IntrinsicMemoryOps : public IntrinsicBase { - typedef IntrinsicBase Base; - static T load(const typename Base::ValueType& ptr) { - return ptr.load(Base::OrderedOp::LoadOrder); - } - static void store(typename Base::ValueType& ptr, T val) { - ptr.store(val, Base::OrderedOp::StoreOrder); - } - static T exchange(typename Base::ValueType& ptr, T val) { - return ptr.exchange(val, Base::OrderedOp::AtomicRMWOrder); - } - static bool compareExchange(typename Base::ValueType& ptr, T oldVal, T newVal) { - return ptr.compare_exchange_strong(oldVal, newVal, - Base::OrderedOp::AtomicRMWOrder, - Base::OrderedOp::CompareExchangeFailureOrder); - } + typedef IntrinsicBase Base; + + static T load(const typename Base::ValueType& aPtr) + { + return aPtr.load(Base::OrderedOp::LoadOrder); + } + + static void store(typename Base::ValueType& aPtr, T aVal) + { + aPtr.store(aVal, Base::OrderedOp::StoreOrder); + } + + static T exchange(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.exchange(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static bool compareExchange(typename Base::ValueType& aPtr, + T aOldVal, T aNewVal) + { + return aPtr.compare_exchange_strong(aOldVal, aNewVal, + Base::OrderedOp::AtomicRMWOrder, + Base::OrderedOp::CompareExchangeFailureOrder); + } }; template struct IntrinsicAddSub : public IntrinsicBase { - typedef IntrinsicBase Base; - static T add(typename Base::ValueType& ptr, T val) { - return ptr.fetch_add(val, Base::OrderedOp::AtomicRMWOrder); - } - static T sub(typename Base::ValueType& ptr, T val) { - return ptr.fetch_sub(val, Base::OrderedOp::AtomicRMWOrder); - } + typedef IntrinsicBase Base; + + static T add(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_add(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T sub(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_sub(aVal, Base::OrderedOp::AtomicRMWOrder); + } }; template struct IntrinsicAddSub : public IntrinsicBase { - typedef IntrinsicBase Base; - static T* add(typename Base::ValueType& ptr, ptrdiff_t val) { - return ptr.fetch_add(fixupAddend(val), Base::OrderedOp::AtomicRMWOrder); - } - static T* sub(typename Base::ValueType& ptr, ptrdiff_t val) { - return ptr.fetch_sub(fixupAddend(val), Base::OrderedOp::AtomicRMWOrder); - } - private: - /* - * GCC 4.6's header has a bug where adding X to an - * atomic is not the same as adding X to a T*. Hence the need - * for this function to provide the correct addend. - */ - static ptrdiff_t fixupAddend(ptrdiff_t val) { + typedef IntrinsicBase Base; + + static T* add(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_add(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } + + static T* sub(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_sub(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } +private: + /* + * GCC 4.6's header has a bug where adding X to an + * atomic is not the same as adding X to a T*. Hence the need + * for this function to provide the correct addend. + */ + static ptrdiff_t fixupAddend(ptrdiff_t aVal) + { #if defined(__clang__) || defined(_MSC_VER) - return val; + return aVal; #elif defined(__GNUC__) && MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) && \ - !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) - return val * sizeof(T); + !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) + return aVal * sizeof(T); #else - return val; + return aVal; #endif - } + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - typedef IntrinsicBase Base; - static T inc(typename Base::ValueType& ptr) { - return IntrinsicAddSub::add(ptr, 1); - } - static T dec(typename Base::ValueType& ptr) { - return IntrinsicAddSub::sub(ptr, 1); - } + typedef IntrinsicBase Base; + + static T inc(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::add(aPtr, 1); + } + + static T dec(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::sub(aPtr, 1); + } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef IntrinsicBase Base; - static T or_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_or(val, Base::OrderedOp::AtomicRMWOrder); - } - static T xor_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_xor(val, Base::OrderedOp::AtomicRMWOrder); - } - static T and_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_and(val, Base::OrderedOp::AtomicRMWOrder); - } + typedef IntrinsicBase Base; + + static T or_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_or(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T xor_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_xor(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T and_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_and(aVal, Base::OrderedOp::AtomicRMWOrder); + } }; template @@ -345,111 +382,119 @@ template struct Barrier; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() {} - static void beforeStore() {} - static void afterStore() {} + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} + static void afterStore() {} }; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() { __sync_synchronize(); } - static void beforeStore() { __sync_synchronize(); } - static void afterStore() {} + static void beforeLoad() {} + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() {} }; template<> struct Barrier { - static void beforeLoad() { __sync_synchronize(); } - static void afterLoad() { __sync_synchronize(); } - static void beforeStore() { __sync_synchronize(); } - static void afterStore() { __sync_synchronize(); } + static void beforeLoad() { __sync_synchronize(); } + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() { __sync_synchronize(); } }; template struct IntrinsicMemoryOps { - static T load(const T& ptr) { - Barrier::beforeLoad(); - T val = ptr; - Barrier::afterLoad(); - return val; - } - static void store(T& ptr, T val) { - Barrier::beforeStore(); - ptr = val; - Barrier::afterStore(); - } - static T exchange(T& ptr, T val) { - // __sync_lock_test_and_set is only an acquire barrier; loads and stores - // can't be moved up from after to before it, but they can be moved down - // from before to after it. We may want a stricter ordering, so we need - // an explicit barrier. - - Barrier::beforeStore(); - return __sync_lock_test_and_set(&ptr, val); - } - static bool compareExchange(T& ptr, T oldVal, T newVal) { - return __sync_bool_compare_and_swap(&ptr, oldVal, newVal); - } + static T load(const T& aPtr) + { + Barrier::beforeLoad(); + T val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(T& aPtr, T aVal) + { + Barrier::beforeStore(); + aPtr = aVal; + Barrier::afterStore(); + } + + static T exchange(T& aPtr, T aVal) + { + // __sync_lock_test_and_set is only an acquire barrier; loads and stores + // can't be moved up from after to before it, but they can be moved down + // from before to after it. We may want a stricter ordering, so we need + // an explicit barrier. + Barrier::beforeStore(); + return __sync_lock_test_and_set(&aPtr, aVal); + } + + static bool compareExchange(T& aPtr, T aOldVal, T aNewVal) + { + return __sync_bool_compare_and_swap(&aPtr, aOldVal, aNewVal); + } }; template struct IntrinsicAddSub { - typedef T ValueType; - static T add(T& ptr, T val) { - return __sync_fetch_and_add(&ptr, val); - } - static T sub(T& ptr, T val) { - return __sync_fetch_and_sub(&ptr, val); - } + typedef T ValueType; + + static T add(T& aPtr, T aVal) + { + return __sync_fetch_and_add(&aPtr, aVal); + } + + static T sub(T& aPtr, T aVal) + { + return __sync_fetch_and_sub(&aPtr, aVal); + } }; template struct IntrinsicAddSub { - typedef T* ValueType; - /* - * The reinterpret_casts are needed so that - * __sync_fetch_and_{add,sub} will properly type-check. - * - * Also, these functions do not provide standard semantics for - * pointer types, so we need to adjust the addend. - */ - static ValueType add(ValueType& ptr, ptrdiff_t val) { - ValueType amount = reinterpret_cast(val * sizeof(T)); - return __sync_fetch_and_add(&ptr, amount); - } - static ValueType sub(ValueType& ptr, ptrdiff_t val) { - ValueType amount = reinterpret_cast(val * sizeof(T)); - return __sync_fetch_and_sub(&ptr, amount); - } + typedef T* ValueType; + + /* + * The reinterpret_casts are needed so that + * __sync_fetch_and_{add,sub} will properly type-check. + * + * Also, these functions do not provide standard semantics for + * pointer types, so we need to adjust the addend. + */ + static ValueType add(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_add(&aPtr, amount); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_sub(&aPtr, amount); + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - static T inc(T& ptr) { return IntrinsicAddSub::add(ptr, 1); } - static T dec(T& ptr) { return IntrinsicAddSub::sub(ptr, 1); } + static T inc(T& aPtr) { return IntrinsicAddSub::add(aPtr, 1); } + static T dec(T& aPtr) { return IntrinsicAddSub::sub(aPtr, 1); } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - static T or_(T& ptr, T val) { - return __sync_fetch_and_or(&ptr, val); - } - static T xor_(T& ptr, T val) { - return __sync_fetch_and_xor(&ptr, val); - } - static T and_(T& ptr, T val) { - return __sync_fetch_and_and(&ptr, val); - } + static T or_( T& aPtr, T aVal) { return __sync_fetch_and_or(&aPtr, aVal); } + static T xor_(T& aPtr, T aVal) { return __sync_fetch_and_xor(&aPtr, aVal); } + static T and_(T& aPtr, T aVal) { return __sync_fetch_and_and(&aPtr, aVal); } }; template @@ -470,19 +515,9 @@ struct AtomicIntrinsics : public IntrinsicMemoryOps, * version of Windows we support. Therefore, we only provide operations * on 32-bit datatypes for 32-bit Windows versions; for 64-bit Windows * versions, we support 64-bit datatypes as well. - * - * To avoid namespace pollution issues, we declare whatever functions we - * need ourselves. */ -extern "C" { -long __cdecl _InterlockedExchangeAdd(long volatile* dst, long value); -long __cdecl _InterlockedOr(long volatile* dst, long value); -long __cdecl _InterlockedXor(long volatile* dst, long value); -long __cdecl _InterlockedAnd(long volatile* dst, long value); -long __cdecl _InterlockedExchange(long volatile *dst, long value); -long __cdecl _InterlockedCompareExchange(long volatile *dst, long newVal, long oldVal); -} +# include # pragma intrinsic(_InterlockedExchangeAdd) # pragma intrinsic(_InterlockedOr) @@ -507,34 +542,34 @@ namespace detail { * The PrimitiveIntrinsics template should define |Type|, the datatype of size * DataSize upon which we operate, and the following eight functions. * - * static Type add(Type* ptr, Type val); - * static Type sub(Type* ptr, Type val); - * static Type or_(Type* ptr, Type val); - * static Type xor_(Type* ptr, Type val); - * static Type and_(Type* ptr, Type val); + * static Type add(Type* aPtr, Type aVal); + * static Type sub(Type* aPtr, Type aVal); + * static Type or_(Type* aPtr, Type aVal); + * static Type xor_(Type* aPtr, Type aVal); + * static Type and_(Type* aPtr, Type aVal); * * These functions perform the obvious operation on the value contained in - * |*ptr| combined with |val| and return the value previously stored in - * |*ptr|. + * |*aPtr| combined with |aVal| and return the value previously stored in + * |*aPtr|. * - * static void store(Type* ptr, Type val); + * static void store(Type* aPtr, Type aVal); * - * This function atomically stores |val| into |*ptr| and must provide a full + * This function atomically stores |aVal| into |*aPtr| and must provide a full * memory fence after the store to prevent compiler and hardware instruction * reordering. It should also act as a compiler barrier to prevent reads and * writes from moving to after the store. * - * static Type exchange(Type* ptr, Type val); + * static Type exchange(Type* aPtr, Type aVal); * - * This function atomically stores |val| into |*ptr| and returns the previous - * contents of *ptr; + * This function atomically stores |aVal| into |*aPtr| and returns the + * previous contents of |*aPtr|; * - * static bool compareExchange(Type* ptr, Type oldVal, Type newVal); + * static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal); * * This function atomically performs the following operation: * - * if (*ptr == oldVal) { - * *ptr = newVal; + * if (*aPtr == aOldVal) { + * *aPtr = aNewVal; * return true; * } else { * return false; @@ -546,56 +581,55 @@ template struct PrimitiveIntrinsics; template<> struct PrimitiveIntrinsics<4> { - typedef long Type; + typedef long Type; - static Type add(Type* ptr, Type val) { - return _InterlockedExchangeAdd(ptr, val); - } - static Type sub(Type* ptr, Type val) { - /* - * _InterlockedExchangeSubtract isn't available before Windows 7, - * and we must support Windows XP. - */ - return _InterlockedExchangeAdd(ptr, -val); - } - static Type or_(Type* ptr, Type val) { - return _InterlockedOr(ptr, val); - } - static Type xor_(Type* ptr, Type val) { - return _InterlockedXor(ptr, val); - } - static Type and_(Type* ptr, Type val) { - return _InterlockedAnd(ptr, val); - } - static void store(Type* ptr, Type val) { - _InterlockedExchange(ptr, val); - } - static Type exchange(Type* ptr, Type val) { - return _InterlockedExchange(ptr, val); - } - static bool compareExchange(Type* ptr, Type oldVal, Type newVal) { - return _InterlockedCompareExchange(ptr, newVal, oldVal) == oldVal; - } + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * _InterlockedExchangeSubtract isn't available before Windows 7, + * and we must support Windows XP. + */ + return _InterlockedExchangeAdd(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange(aPtr, aNewVal, aOldVal) == aOldVal; + } }; # if defined(_M_X64) -extern "C" { -long long __cdecl _InterlockedExchangeAdd64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedOr64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedXor64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedAnd64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedExchange64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedCompareExchange64(long long volatile* dst, - long long newVal, - long long oldVal); -} - # pragma intrinsic(_InterlockedExchangeAdd64) # pragma intrinsic(_InterlockedOr64) # pragma intrinsic(_InterlockedXor64) @@ -606,41 +640,54 @@ long long __cdecl _InterlockedCompareExchange64(long long volatile* dst, template <> struct PrimitiveIntrinsics<8> { - typedef __int64 Type; + typedef __int64 Type; - static Type add(Type* ptr, Type val) { - return _InterlockedExchangeAdd64(ptr, val); - } - static Type sub(Type* ptr, Type val) { - /* - * There is no _InterlockedExchangeSubtract64. - */ - return _InterlockedExchangeAdd64(ptr, -val); - } - static Type or_(Type* ptr, Type val) { - return _InterlockedOr64(ptr, val); - } - static Type xor_(Type* ptr, Type val) { - return _InterlockedXor64(ptr, val); - } - static Type and_(Type* ptr, Type val) { - return _InterlockedAnd64(ptr, val); - } - static void store(Type* ptr, Type val) { - _InterlockedExchange64(ptr, val); - } - static Type exchange(Type* ptr, Type val) { - return _InterlockedExchange64(ptr, val); - } - static bool compareExchange(Type* ptr, Type oldVal, Type newVal) { - return _InterlockedCompareExchange64(ptr, newVal, oldVal) == oldVal; - } + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd64(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * There is no _InterlockedExchangeSubtract64. + */ + return _InterlockedExchangeAdd64(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr64(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor64(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd64(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange64(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange64(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange64(aPtr, aNewVal, aOldVal) == aOldVal; + } }; # endif -extern "C" { void _ReadWriteBarrier(); } - # pragma intrinsic(_ReadWriteBarrier) template struct Barrier; @@ -654,168 +701,198 @@ template struct Barrier; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() {} - static void beforeStore() {} + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} }; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() { _ReadWriteBarrier(); } - static void beforeStore() { _ReadWriteBarrier(); } + static void beforeLoad() {} + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } }; template<> struct Barrier { - static void beforeLoad() { _ReadWriteBarrier(); } - static void afterLoad() { _ReadWriteBarrier(); } - static void beforeStore() { _ReadWriteBarrier(); } + static void beforeLoad() { _ReadWriteBarrier(); } + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } }; template struct CastHelper { - static PrimType toPrimType(T val) { return static_cast(val); } - static T fromPrimType(PrimType val) { return static_cast(val); } + static PrimType toPrimType(T aVal) { return static_cast(aVal); } + static T fromPrimType(PrimType aVal) { return static_cast(aVal); } }; template struct CastHelper { - static PrimType toPrimType(T* val) { return reinterpret_cast(val); } - static T* fromPrimType(PrimType val) { return reinterpret_cast(val); } + static PrimType toPrimType(T* aVal) { return reinterpret_cast(aVal); } + static T* fromPrimType(PrimType aVal) { return reinterpret_cast(aVal); } }; template struct IntrinsicBase { - typedef T ValueType; - typedef PrimitiveIntrinsics Primitives; - typedef typename Primitives::Type PrimType; - static_assert(sizeof(PrimType) == sizeof(T), - "Selection of PrimitiveIntrinsics was wrong"); - typedef CastHelper Cast; + typedef T ValueType; + typedef PrimitiveIntrinsics Primitives; + typedef typename Primitives::Type PrimType; + static_assert(sizeof(PrimType) == sizeof(T), + "Selection of PrimitiveIntrinsics was wrong"); + typedef CastHelper Cast; }; template struct IntrinsicMemoryOps : public IntrinsicBase { - typedef typename IntrinsicBase::ValueType ValueType; - typedef typename IntrinsicBase::Primitives Primitives; - typedef typename IntrinsicBase::PrimType PrimType; - typedef typename IntrinsicBase::Cast Cast; - static ValueType load(const ValueType& ptr) { - Barrier::beforeLoad(); - ValueType val = ptr; - Barrier::afterLoad(); - return val; - } - static void store(ValueType& ptr, ValueType val) { - // For SequentiallyConsistent, Primitives::store() will generate the - // proper memory fence. Everything else just needs a barrier before - // the store. - if (Order == SequentiallyConsistent) { - Primitives::store(reinterpret_cast(&ptr), - Cast::toPrimType(val)); - } else { - Barrier::beforeStore(); - ptr = val; - } - } - static ValueType exchange(ValueType& ptr, ValueType val) { - PrimType oldval = - Primitives::exchange(reinterpret_cast(&ptr), - Cast::toPrimType(val)); - return Cast::fromPrimType(oldval); - } - static bool compareExchange(ValueType& ptr, ValueType oldVal, ValueType newVal) { - return Primitives::compareExchange(reinterpret_cast(&ptr), - Cast::toPrimType(oldVal), - Cast::toPrimType(newVal)); + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + + static ValueType load(const ValueType& aPtr) + { + Barrier::beforeLoad(); + ValueType val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(ValueType& aPtr, ValueType aVal) + { + // For SequentiallyConsistent, Primitives::store() will generate the + // proper memory fence. Everything else just needs a barrier before + // the store. + if (Order == SequentiallyConsistent) { + Primitives::store(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + } else { + Barrier::beforeStore(); + aPtr = aVal; } + } + + static ValueType exchange(ValueType& aPtr, ValueType aVal) + { + PrimType oldval = + Primitives::exchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + return Cast::fromPrimType(oldval); + } + + static bool compareExchange(ValueType& aPtr, ValueType aOldVal, + ValueType aNewVal) + { + return Primitives::compareExchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aOldVal), + Cast::toPrimType(aNewVal)); + } }; template struct IntrinsicApplyHelper : public IntrinsicBase { - typedef typename IntrinsicBase::ValueType ValueType; - typedef typename IntrinsicBase::PrimType PrimType; - typedef typename IntrinsicBase::Cast Cast; - typedef PrimType (*BinaryOp)(PrimType*, PrimType); - typedef PrimType (*UnaryOp)(PrimType*); - - static ValueType applyBinaryFunction(BinaryOp op, ValueType& ptr, - ValueType val) { - PrimType* primTypePtr = reinterpret_cast(&ptr); - PrimType primTypeVal = Cast::toPrimType(val); - return Cast::fromPrimType(op(primTypePtr, primTypeVal)); - } - - static ValueType applyUnaryFunction(UnaryOp op, ValueType& ptr) { - PrimType* primTypePtr = reinterpret_cast(&ptr); - return Cast::fromPrimType(op(primTypePtr)); - } + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + typedef PrimType (*BinaryOp)(PrimType*, PrimType); + typedef PrimType (*UnaryOp)(PrimType*); + + static ValueType applyBinaryFunction(BinaryOp aOp, ValueType& aPtr, + ValueType aVal) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + PrimType primTypeVal = Cast::toPrimType(aVal); + return Cast::fromPrimType(aOp(primTypePtr, primTypeVal)); + } + + static ValueType applyUnaryFunction(UnaryOp aOp, ValueType& aPtr) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + return Cast::fromPrimType(aOp(primTypePtr)); + } }; template struct IntrinsicAddSub : public IntrinsicApplyHelper { - typedef typename IntrinsicApplyHelper::ValueType ValueType; - typedef typename IntrinsicBase::Primitives Primitives; - static ValueType add(ValueType& ptr, ValueType val) { - return applyBinaryFunction(&Primitives::add, ptr, val); - } - static ValueType sub(ValueType& ptr, ValueType val) { - return applyBinaryFunction(&Primitives::sub, ptr, val); - } + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::add, aPtr, aVal); + } + + static ValueType sub(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::sub, aPtr, aVal); + } }; template struct IntrinsicAddSub : public IntrinsicApplyHelper { - typedef typename IntrinsicApplyHelper::ValueType ValueType; - static ValueType add(ValueType& ptr, ptrdiff_t amount) { - return applyBinaryFunction(&Primitives::add, ptr, - (ValueType)(amount * sizeof(ValueType))); - } - static ValueType sub(ValueType& ptr, ptrdiff_t amount) { - return applyBinaryFunction(&Primitives::sub, ptr, - (ValueType)(amount * sizeof(ValueType))); - } + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::add, aPtr, + (ValueType)(aAmount * sizeof(T))); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::sub, aPtr, + (ValueType)(aAmount * sizeof(T))); + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - typedef typename IntrinsicAddSub::ValueType ValueType; - static ValueType inc(ValueType& ptr) { return add(ptr, 1); } - static ValueType dec(ValueType& ptr) { return sub(ptr, 1); } + typedef typename IntrinsicAddSub::ValueType ValueType; + static ValueType inc(ValueType& aPtr) { return add(aPtr, 1); } + static ValueType dec(ValueType& aPtr) { return sub(aPtr, 1); } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef typename IntrinsicIncDec::ValueType ValueType; - static ValueType or_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::or_, ptr, val); - } - static ValueType xor_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::xor_, ptr, val); - } - static ValueType and_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::and_, ptr, val); - } + typedef typename IntrinsicIncDec::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType or_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::or_, aPtr, aVal); + } + + static ValueType xor_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::xor_, aPtr, aVal); + } + + static ValueType and_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::and_, aPtr, aVal); + } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef typename IntrinsicMemoryOps::ValueType ValueType; + typedef typename IntrinsicMemoryOps::ValueType ValueType; + // This is required to make us be able to build with MSVC10, for unknown + // reasons. + typedef typename IntrinsicBase::Primitives Primitives; }; } // namespace detail @@ -832,73 +909,80 @@ namespace detail { template class AtomicBase { - // We only support 32-bit types on 32-bit Windows, which constrains our - // implementation elsewhere. But we support pointer-sized types everywhere. - static_assert(sizeof(T) == 4 || (sizeof(uintptr_t) == 8 && sizeof(T) == 8), - "mozilla/Atomics.h only supports 32-bit and pointer-sized types"); - - protected: - typedef typename detail::AtomicIntrinsics Intrinsics; - typename Intrinsics::ValueType mValue; - - public: - MOZ_CONSTEXPR AtomicBase() : mValue() {} - MOZ_CONSTEXPR AtomicBase(T aInit) : mValue(aInit) {} - - operator T() const { return Intrinsics::load(mValue); } - - T operator=(T aValue) { - Intrinsics::store(mValue, aValue); - return aValue; - } - - /** - * Performs an atomic swap operation. aValue is stored and the previous - * value of this variable is returned. - */ - T exchange(T aValue) { - return Intrinsics::exchange(mValue, aValue); - } - - /** - * Performs an atomic compare-and-swap operation and returns true if it - * succeeded. This is equivalent to atomically doing - * - * if (mValue == aOldValue) { - * mValue = aNewValue; - * return true; - * } else { - * return false; - * } - */ - bool compareExchange(T aOldValue, T aNewValue) { - return Intrinsics::compareExchange(mValue, aOldValue, aNewValue); - } - - private: - template - AtomicBase(const AtomicBase& aCopy) MOZ_DELETE; + // We only support 32-bit types on 32-bit Windows, which constrains our + // implementation elsewhere. But we support pointer-sized types everywhere. + static_assert(sizeof(T) == 4 || (sizeof(uintptr_t) == 8 && sizeof(T) == 8), + "mozilla/Atomics.h only supports 32-bit and pointer-sized types"); + +protected: + typedef typename detail::AtomicIntrinsics Intrinsics; + typename Intrinsics::ValueType mValue; + +public: + MOZ_CONSTEXPR AtomicBase() : mValue() {} + explicit MOZ_CONSTEXPR AtomicBase(T aInit) : mValue(aInit) {} + + // Note: we can't provide operator T() here because Atomic inherits + // from AtomcBase with T=uint32_t and not T=bool. If we implemented + // operator T() here, it would cause errors when comparing Atomic with + // a regular bool. + + T operator=(T aVal) + { + Intrinsics::store(mValue, aVal); + return aVal; + } + + /** + * Performs an atomic swap operation. aVal is stored and the previous + * value of this variable is returned. + */ + T exchange(T aVal) + { + return Intrinsics::exchange(mValue, aVal); + } + + /** + * Performs an atomic compare-and-swap operation and returns true if it + * succeeded. This is equivalent to atomically doing + * + * if (mValue == aOldValue) { + * mValue = aNewValue; + * return true; + * } else { + * return false; + * } + */ + bool compareExchange(T aOldValue, T aNewValue) + { + return Intrinsics::compareExchange(mValue, aOldValue, aNewValue); + } + +private: + template + AtomicBase(const AtomicBase& aCopy) MOZ_DELETE; }; template class AtomicBaseIncDec : public AtomicBase { - typedef typename detail::AtomicBase Base; + typedef typename detail::AtomicBase Base; - public: - MOZ_CONSTEXPR AtomicBaseIncDec() : Base() {} - MOZ_CONSTEXPR AtomicBaseIncDec(T aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR AtomicBaseIncDec() : Base() {} + explicit MOZ_CONSTEXPR AtomicBaseIncDec(T aInit) : Base(aInit) {} - using Base::operator=; + using Base::operator=; - T operator++(int) { return Base::Intrinsics::inc(Base::mValue); } - T operator--(int) { return Base::Intrinsics::dec(Base::mValue); } - T operator++() { return Base::Intrinsics::inc(Base::mValue) + 1; } - T operator--() { return Base::Intrinsics::dec(Base::mValue) - 1; } + operator T() const { return Base::Intrinsics::load(Base::mValue); } + T operator++(int) { return Base::Intrinsics::inc(Base::mValue); } + T operator--(int) { return Base::Intrinsics::dec(Base::mValue); } + T operator++() { return Base::Intrinsics::inc(Base::mValue) + 1; } + T operator--() { return Base::Intrinsics::dec(Base::mValue) - 1; } - private: - template - AtomicBaseIncDec(const AtomicBaseIncDec& aCopy) MOZ_DELETE; +private: + template + AtomicBaseIncDec(const AtomicBaseIncDec& aCopy) MOZ_DELETE; }; } // namespace detail @@ -934,25 +1018,45 @@ class Atomic; * swap method is provided. */ template -class Atomic::value>::Type> +class Atomic::value && + !IsSame::value>::Type> : public detail::AtomicBaseIncDec { - typedef typename detail::AtomicBaseIncDec Base; + typedef typename detail::AtomicBaseIncDec Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + + using Base::operator=; + + T operator+=(T aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + T operator-=(T aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } - using Base::operator=; + T operator|=(T aVal) + { + return Base::Intrinsics::or_(Base::mValue, aVal) | aVal; + } - T operator+=(T delta) { return Base::Intrinsics::add(Base::mValue, delta) + delta; } - T operator-=(T delta) { return Base::Intrinsics::sub(Base::mValue, delta) - delta; } - T operator|=(T val) { return Base::Intrinsics::or_(Base::mValue, val) | val; } - T operator^=(T val) { return Base::Intrinsics::xor_(Base::mValue, val) ^ val; } - T operator&=(T val) { return Base::Intrinsics::and_(Base::mValue, val) & val; } + T operator^=(T aVal) + { + return Base::Intrinsics::xor_(Base::mValue, aVal) ^ aVal; + } - private: - Atomic(Atomic& aOther) MOZ_DELETE; + T operator&=(T aVal) + { + return Base::Intrinsics::and_(Base::mValue, aVal) & aVal; + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; /** @@ -966,23 +1070,26 @@ class Atomic::value>::Type> template class Atomic : public detail::AtomicBaseIncDec { - typedef typename detail::AtomicBaseIncDec Base; + typedef typename detail::AtomicBaseIncDec Base; - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T* aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T* aInit) : Base(aInit) {} - using Base::operator=; + using Base::operator=; - T* operator+=(ptrdiff_t delta) { - return Base::Intrinsics::add(Base::mValue, delta) + delta; - } - T* operator-=(ptrdiff_t delta) { - return Base::Intrinsics::sub(Base::mValue, delta) - delta; - } + T* operator+=(ptrdiff_t aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } + + T* operator-=(ptrdiff_t aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } - private: - Atomic(Atomic& aOther) MOZ_DELETE; +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; /** @@ -994,16 +1101,69 @@ template class Atomic::value>::Type> : public detail::AtomicBase { - typedef typename detail::AtomicBase Base; + typedef typename detail::AtomicBase Base; - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} - using Base::operator=; + operator T() const { return Base::Intrinsics::load(Base::mValue); } - private: - Atomic(Atomic& aOther) MOZ_DELETE; + using Base::operator=; + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +/** + * Atomic implementation for boolean types. + * + * The atomic store and load operations and the atomic swap method is provided. + * + * Note: + * + * - sizeof(Atomic) != sizeof(bool) for some implementations of + * bool and/or some implementations of std::atomic. This is allowed in + * [atomic.types.generic]p9. + * + * - It's not obvious whether the 8-bit atomic functions on Windows are always + * inlined or not. If they are not inlined, the corresponding functions in the + * runtime library are not available on Windows XP. This is why we implement + * Atomic with an underlying type of uint32_t. + */ +template +class Atomic + : protected detail::AtomicBase +{ + typedef typename detail::AtomicBase Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(bool aInit) : Base(aInit) {} + + // We provide boolean wrappers for the underlying AtomicBase methods. + operator bool() const + { + return Base::Intrinsics::load(Base::mValue); + } + + bool operator=(bool aVal) + { + return Base::operator=(aVal); + } + + bool exchange(bool aVal) + { + return Base::exchange(aVal); + } + + bool compareExchange(bool aOldValue, bool aNewValue) + { + return Base::compareExchange(aOldValue, aNewValue); + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Attributes.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Attributes.h index 671f30cded..cdce8c7717 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Attributes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Attributes.h @@ -37,6 +37,7 @@ # define MOZ_ALWAYS_INLINE inline #endif +#if defined(_MSC_VER) /* * g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality * without warnings (functionality used by the macros below). These modes are @@ -44,8 +45,27 @@ * standardly, by checking whether __cplusplus has a C++11 or greater value. * Current versions of g++ do not correctly set __cplusplus, so we check both * for forward compatibility. + * + * Even though some versions of MSVC support explicit conversion operators, we + * don't indicate support for them here, due to + * http://stackoverflow.com/questions/20498142/visual-studio-2013-explicit-keyword-bug */ -#if defined(__clang__) +# if _MSC_VER >= 1800 +# define MOZ_HAVE_CXX11_DELETE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_FINAL final +# else +# if defined(__clang__) +# error Please do not try to use clang-cl with MSVC10 or below emulation! +# endif + /* MSVC <= 10 used to spell "final" as "sealed". */ +# define MOZ_HAVE_CXX11_FINAL sealed +# endif +# define MOZ_HAVE_CXX11_OVERRIDE +# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) +# define MOZ_HAVE_NORETURN __declspec(noreturn) +#elif defined(__clang__) /* * Per Clang documentation, "Note that marketing version numbers should not * be used to check for language features, as different vendors use different @@ -57,6 +77,9 @@ # if __has_extension(cxx_constexpr) # define MOZ_HAVE_CXX11_CONSTEXPR # endif +# if __has_extension(cxx_explicit_conversions) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif # if __has_extension(cxx_deleted_functions) # define MOZ_HAVE_CXX11_DELETE # endif @@ -79,6 +102,9 @@ # if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) # define MOZ_HAVE_CXX11_CONSTEXPR # endif +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif # define MOZ_HAVE_CXX11_DELETE # else /* __final is a non-C++11 GCC synonym for 'final', per GCC r176655. */ @@ -88,19 +114,16 @@ # endif # define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) # define MOZ_HAVE_NORETURN __attribute__((noreturn)) -#elif defined(_MSC_VER) -# if _MSC_VER >= 1800 -# define MOZ_HAVE_CXX11_DELETE -# endif -# if _MSC_VER >= 1700 -# define MOZ_HAVE_CXX11_FINAL final -# else - /* MSVC <= 10 used to spell "final" as "sealed". */ -# define MOZ_HAVE_CXX11_FINAL sealed +#endif + +/* + * When built with clang analyzer (a.k.a scan-build), define MOZ_HAVE_NORETURN + * to mark some false positives + */ +#ifdef __clang_analyzer__ +# if __has_extension(attribute_analyzer_noreturn) +# define MOZ_HAVE_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) # endif -# define MOZ_HAVE_CXX11_OVERRIDE -# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) -# define MOZ_HAVE_NORETURN __declspec(noreturn) #endif /* @@ -121,6 +144,31 @@ # define MOZ_CONSTEXPR_VAR const #endif +/* + * MOZ_EXPLICIT_CONVERSION is a specifier on a type conversion + * overloaded operator that declares that a C++11 compiler should restrict + * this operator to allow only explicit type conversions, disallowing + * implicit conversions. + * + * Example: + * + * template + * class Ptr + * { + * T* mPtr; + * MOZ_EXPLICIT_CONVERSION operator bool() const + * { + * return mPtr != nullptr; + * } + * }; + * + */ +#ifdef MOZ_HAVE_EXPLICIT_CONVERSION +# define MOZ_EXPLICIT_CONVERSION explicit +#else +# define MOZ_EXPLICIT_CONVERSION /* no support */ +#endif + /* * MOZ_NEVER_INLINE is a macro which expands to tell the compiler that the * method decorated with it must never be inlined, even if the compiler would @@ -153,18 +201,47 @@ # define MOZ_NORETURN /* no support */ #endif +/* + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS, specified at the end of a function + * declaration, indicates that for the purposes of static analysis, this + * function does not return. (The function definition does not need to be + * annotated.) + * + * MOZ_ReportCrash(const char* s, const char* file, int ln) + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS + * + * Some static analyzers, like scan-build from clang, can use this information + * to eliminate false positives. From the upstream documentation of scan-build: + * "This attribute is useful for annotating assertion handlers that actually + * can return, but for the purpose of using the analyzer we want to pretend + * that such functions do not return." + * + */ +#if defined(MOZ_HAVE_ANALYZER_NORETURN) +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS MOZ_HAVE_ANALYZER_NORETURN +#else +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS /* no support */ +#endif + /* * MOZ_ASAN_BLACKLIST is a macro to tell AddressSanitizer (a compile-time - * instrumentation shipped with Clang) to not instrument the annotated function. - * Furthermore, it will prevent the compiler from inlining the function because - * inlining currently breaks the blacklisting mechanism of AddressSanitizer. + * instrumentation shipped with Clang and GCC) to not instrument the annotated + * function. Furthermore, it will prevent the compiler from inlining the + * function because inlining currently breaks the blacklisting mechanism of + * AddressSanitizer. */ #if defined(__has_feature) # if __has_feature(address_sanitizer) -# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) -# else -# define MOZ_ASAN_BLACKLIST /* nothing */ +# define MOZ_HAVE_ASAN_BLACKLIST # endif +#elif defined(__GNUC__) +# if defined(__SANITIZE_ADDRESS__) +# define MOZ_HAVE_ASAN_BLACKLIST +# endif +#endif + +#if defined(MOZ_HAVE_ASAN_BLACKLIST) +# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) #else # define MOZ_ASAN_BLACKLIST /* nothing */ #endif @@ -197,9 +274,9 @@ * * struct NonCopyable * { - * private: - * NonCopyable(const NonCopyable& other) MOZ_DELETE; - * void operator=(const NonCopyable& other) MOZ_DELETE; + * private: + * NonCopyable(const NonCopyable& aOther) MOZ_DELETE; + * void operator=(const NonCopyable& aOther) MOZ_DELETE; * }; * * If MOZ_DELETE can't be implemented for the current compiler, use of the @@ -225,23 +302,23 @@ * * class Base * { - * public: - * virtual void f() = 0; + * public: + * virtual void f() = 0; * }; * class Derived1 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE; + * public: + * virtual void f() MOZ_OVERRIDE; * }; * class Derived2 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE = 0; + * public: + * virtual void f() MOZ_OVERRIDE = 0; * }; * class Derived3 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE { } + * public: + * virtual void f() MOZ_OVERRIDE { } * }; * * In compilers supporting C++11 override controls, MOZ_OVERRIDE *requires* that @@ -269,16 +346,16 @@ * * class Base MOZ_FINAL * { - * public: - * Base(); - * ~Base(); - * virtual void f() { } + * public: + * Base(); + * ~Base(); + * virtual void f() { } * }; * // This will be an error in some compilers: * class Derived : public Base * { - * public: - * ~Derived() { } + * public: + * ~Derived() { } * }; * * One particularly common reason to specify MOZ_FINAL upon a class is to tell @@ -305,14 +382,14 @@ * * class Base * { - * public: - * virtual void f() MOZ_FINAL; + * public: + * virtual void f() MOZ_FINAL; * }; * class Derived * { - * public: - * // This will be an error in some compilers: - * virtual void f(); + * public: + * // This will be an error in some compilers: + * virtual void f(); * }; * * In compilers implementing final controls, it is an error for a derived class @@ -372,13 +449,13 @@ * * typedef int MOZ_TYPE_ATTRIBUTE MagicInt; * int MOZ_TYPE_ATTRIBUTE someVariable; - * int * MOZ_TYPE_ATTRIBUTE magicPtrInt; - * int MOZ_TYPE_ATTRIBUTE * ptrToMagicInt; + * int* MOZ_TYPE_ATTRIBUTE magicPtrInt; + * int MOZ_TYPE_ATTRIBUTE* ptrToMagicInt; * * Attributes that apply to statements precede the statement: * * MOZ_IF_ATTRIBUTE if (x == 0) - * MOZ_DO_ATTRIBUTE do { } while(0); + * MOZ_DO_ATTRIBUTE do { } while (0); * * Attributes that apply to labels precede the label: * @@ -412,11 +489,16 @@ * MOZ_HEAP_ALLOCATOR: Applies to any function. This indicates that the return * value is allocated on the heap, and will as a result check such allocations * during MOZ_STACK_CLASS and MOZ_NONHEAP_CLASS annotation checking. + * MOZ_IMPLICIT: Applies to constructors. Implicit conversion constructors + * are disallowed by default unless they are marked as MOZ_IMPLICIT. This + * attribute must be used for constructors which intend to provide implicit + * conversions. */ #ifdef MOZ_CLANG_PLUGIN # define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override"))) # define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class"))) # define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class"))) +# define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) /* * It turns out that clang doesn't like void func() __attribute__ {} without a * warning, so use pragmas to disable the warning. This code won't work on GCC @@ -431,6 +513,7 @@ # define MOZ_MUST_OVERRIDE /* nothing */ # define MOZ_STACK_CLASS /* nothing */ # define MOZ_NONHEAP_CLASS /* nothing */ +# define MOZ_IMPLICIT /* nothing */ # define MOZ_HEAP_ALLOCATOR /* nothing */ #endif /* MOZ_CLANG_PLUGIN */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/BinarySearch.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/BinarySearch.h new file mode 100644 index 0000000000..c8f593d6a9 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/BinarySearch.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_BinarySearch_h +#define mozilla_BinarySearch_h + +#include "mozilla/Assertions.h" + +#include + +namespace mozilla { + +/* + * The algorithm searches the given container |aContainer| over the sorted + * index range [aBegin, aEnd) for an index |i| where |aContainer[i] == aTarget|. + * If such an index |i| is found, BinarySearch returns |true| and the index is + * returned via the outparam |aMatchOrInsertionPoint|. If no index is found, + * BinarySearch returns |false| and the outparam returns the first index in + * [aBegin, aEnd] where |aTarget| can be inserted to maintain sorted order. + * + * Example: + * + * Vector sortedInts = ... + * + * size_t match; + * if (BinarySearch(sortedInts, 0, sortedInts.length(), 13, &match)) { + * printf("found 13 at %lu\n", match); + * } + */ + +template +bool +BinarySearch(const Container& aContainer, size_t aBegin, size_t aEnd, + T aTarget, size_t* aMatchOrInsertionPoint) +{ + MOZ_ASSERT(aBegin <= aEnd); + + size_t low = aBegin; + size_t high = aEnd; + while (low != high) { + size_t middle = low + (high - low) / 2; + + // Allow any intermediate type so long as it provides a suitable ordering + // relation. + const auto& middleValue = aContainer[middle]; + + MOZ_ASSERT(aContainer[low] <= aContainer[middle]); + MOZ_ASSERT(aContainer[middle] <= aContainer[high - 1]); + MOZ_ASSERT(aContainer[low] <= aContainer[high - 1]); + + if (aTarget == middleValue) { + *aMatchOrInsertionPoint = middle; + return true; + } + + if (aTarget < middleValue) { + high = middle; + } else { + low = middle + 1; + } + } + + *aMatchOrInsertionPoint = low; + return false; +} + +} // namespace mozilla + +#endif // mozilla_BinarySearch_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/BloomFilter.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/BloomFilter.h index 8129c489d4..6757e41181 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/BloomFilter.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/BloomFilter.h @@ -55,177 +55,199 @@ namespace mozilla { template class BloomFilter { - /* - * A counting Bloom filter with 8-bit counters. For now we assume - * that having two hash functions is enough, but we may revisit that - * decision later. - * - * The filter uses an array with 2**KeySize entries. - * - * Assuming a well-distributed hash function, a Bloom filter with - * array size M containing N elements and - * using k hash function has expected false positive rate exactly - * - * $ (1 - (1 - 1/M)^{kN})^k $ - * - * because each array slot has a - * - * $ (1 - 1/M)^{kN} $ - * - * chance of being 0, and the expected false positive rate is the - * probability that all of the k hash functions will hit a nonzero - * slot. - * - * For reasonable assumptions (M large, kN large, which should both - * hold if we're worried about false positives) about M and kN this - * becomes approximately - * - * $$ (1 - \exp(-kN/M))^k $$ - * - * For our special case of k == 2, that's $(1 - \exp(-2N/M))^2$, - * or in other words - * - * $$ N/M = -0.5 * \ln(1 - \sqrt(r)) $$ - * - * where r is the false positive rate. This can be used to compute - * the desired KeySize for a given load N and false positive rate r. - * - * If N/M is assumed small, then the false positive rate can - * further be approximated as 4*N^2/M^2. So increasing KeySize by - * 1, which doubles M, reduces the false positive rate by about a - * factor of 4, and a false positive rate of 1% corresponds to - * about M/N == 20. - * - * What this means in practice is that for a few hundred keys using a - * KeySize of 12 gives false positive rates on the order of 0.25-4%. - * - * Similarly, using a KeySize of 10 would lead to a 4% false - * positive rate for N == 100 and to quite bad false positive - * rates for larger N. - */ - public: - BloomFilter() { - static_assert(KeySize <= keyShift, "KeySize too big"); - - // Should we have a custom operator new using calloc instead and - // require that we're allocated via the operator? - clear(); - } - - /* - * Clear the filter. This should be done before reusing it, because - * just removing all items doesn't clear counters that hit the upper - * bound. - */ - void clear(); - - /* - * Add an item to the filter. - */ - void add(const T* t); - - /* - * Remove an item from the filter. - */ - void remove(const T* t); - - /* - * Check whether the filter might contain an item. This can - * sometimes return true even if the item is not in the filter, - * but will never return false for items that are actually in the - * filter. - */ - bool mightContain(const T* t) const; - - /* - * Methods for add/remove/contain when we already have a hash computed - */ - void add(uint32_t hash); - void remove(uint32_t hash); - bool mightContain(uint32_t hash) const; - - private: - static const size_t arraySize = (1 << KeySize); - static const uint32_t keyMask = (1 << KeySize) - 1; - static const uint32_t keyShift = 16; - - static uint32_t hash1(uint32_t hash) { return hash & keyMask; } - static uint32_t hash2(uint32_t hash) { return (hash >> keyShift) & keyMask; } - - uint8_t& firstSlot(uint32_t hash) { return counters[hash1(hash)]; } - uint8_t& secondSlot(uint32_t hash) { return counters[hash2(hash)]; } - const uint8_t& firstSlot(uint32_t hash) const { return counters[hash1(hash)]; } - const uint8_t& secondSlot(uint32_t hash) const { return counters[hash2(hash)]; } - - static bool full(const uint8_t& slot) { return slot == UINT8_MAX; } - - uint8_t counters[arraySize]; + /* + * A counting Bloom filter with 8-bit counters. For now we assume + * that having two hash functions is enough, but we may revisit that + * decision later. + * + * The filter uses an array with 2**KeySize entries. + * + * Assuming a well-distributed hash function, a Bloom filter with + * array size M containing N elements and + * using k hash function has expected false positive rate exactly + * + * $ (1 - (1 - 1/M)^{kN})^k $ + * + * because each array slot has a + * + * $ (1 - 1/M)^{kN} $ + * + * chance of being 0, and the expected false positive rate is the + * probability that all of the k hash functions will hit a nonzero + * slot. + * + * For reasonable assumptions (M large, kN large, which should both + * hold if we're worried about false positives) about M and kN this + * becomes approximately + * + * $$ (1 - \exp(-kN/M))^k $$ + * + * For our special case of k == 2, that's $(1 - \exp(-2N/M))^2$, + * or in other words + * + * $$ N/M = -0.5 * \ln(1 - \sqrt(r)) $$ + * + * where r is the false positive rate. This can be used to compute + * the desired KeySize for a given load N and false positive rate r. + * + * If N/M is assumed small, then the false positive rate can + * further be approximated as 4*N^2/M^2. So increasing KeySize by + * 1, which doubles M, reduces the false positive rate by about a + * factor of 4, and a false positive rate of 1% corresponds to + * about M/N == 20. + * + * What this means in practice is that for a few hundred keys using a + * KeySize of 12 gives false positive rates on the order of 0.25-4%. + * + * Similarly, using a KeySize of 10 would lead to a 4% false + * positive rate for N == 100 and to quite bad false positive + * rates for larger N. + */ +public: + BloomFilter() + { + static_assert(KeySize <= kKeyShift, "KeySize too big"); + + // Should we have a custom operator new using calloc instead and + // require that we're allocated via the operator? + clear(); + } + + /* + * Clear the filter. This should be done before reusing it, because + * just removing all items doesn't clear counters that hit the upper + * bound. + */ + void clear(); + + /* + * Add an item to the filter. + */ + void add(const T* aValue); + + /* + * Remove an item from the filter. + */ + void remove(const T* aValue); + + /* + * Check whether the filter might contain an item. This can + * sometimes return true even if the item is not in the filter, + * but will never return false for items that are actually in the + * filter. + */ + bool mightContain(const T* aValue) const; + + /* + * Methods for add/remove/contain when we already have a hash computed + */ + void add(uint32_t aHash); + void remove(uint32_t aHash); + bool mightContain(uint32_t aHash) const; + +private: + static const size_t kArraySize = (1 << KeySize); + static const uint32_t kKeyMask = (1 << KeySize) - 1; + static const uint32_t kKeyShift = 16; + + static uint32_t hash1(uint32_t aHash) + { + return aHash & kKeyMask; + } + static uint32_t hash2(uint32_t aHash) + { + return (aHash >> kKeyShift) & kKeyMask; + } + + uint8_t& firstSlot(uint32_t aHash) + { + return mCounters[hash1(aHash)]; + } + uint8_t& secondSlot(uint32_t aHash) + { + return mCounters[hash2(aHash)]; + } + + const uint8_t& firstSlot(uint32_t aHash) const + { + return mCounters[hash1(aHash)]; + } + const uint8_t& secondSlot(uint32_t aHash) const + { + return mCounters[hash2(aHash)]; + } + + static bool full(const uint8_t& aSlot) { return aSlot == UINT8_MAX; } + + uint8_t mCounters[kArraySize]; }; template inline void BloomFilter::clear() { - memset(counters, 0, arraySize); + memset(mCounters, 0, kArraySize); } template inline void -BloomFilter::add(uint32_t hash) +BloomFilter::add(uint32_t aHash) { - uint8_t& slot1 = firstSlot(hash); - if (MOZ_LIKELY(!full(slot1))) + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { ++slot1; - - uint8_t& slot2 = secondSlot(hash); - if (MOZ_LIKELY(!full(slot2))) + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { ++slot2; + } } template MOZ_ALWAYS_INLINE void -BloomFilter::add(const T* t) +BloomFilter::add(const T* aValue) { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); return add(hash); } template inline void -BloomFilter::remove(uint32_t hash) +BloomFilter::remove(uint32_t aHash) { // If the slots are full, we don't know whether we bumped them to be // there when we added or not, so just leave them full. - uint8_t& slot1 = firstSlot(hash); - if (MOZ_LIKELY(!full(slot1))) + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { --slot1; - - uint8_t& slot2 = secondSlot(hash); - if (MOZ_LIKELY(!full(slot2))) + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { --slot2; + } } template MOZ_ALWAYS_INLINE void -BloomFilter::remove(const T* t) +BloomFilter::remove(const T* aValue) { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); remove(hash); } template MOZ_ALWAYS_INLINE bool -BloomFilter::mightContain(uint32_t hash) const +BloomFilter::mightContain(uint32_t aHash) const { // Check that all the slots for this hash contain something - return firstSlot(hash) && secondSlot(hash); + return firstSlot(aHash) && secondSlot(aHash); } template MOZ_ALWAYS_INLINE bool -BloomFilter::mightContain(const T* t) const +BloomFilter::mightContain(const T* aValue) const { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); return mightContain(hash); } diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Casting.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Casting.h index 76df0ef27e..dc449af6b6 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Casting.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Casting.h @@ -17,7 +17,8 @@ namespace mozilla { /** - * Return a value of type |To|, containing the underlying bit pattern of |from|. + * Return a value of type |To|, containing the underlying bit pattern of + * |aFrom|. * * |To| and |From| must be types of the same size; be careful of cross-platform * size differences, or this might fail to compile on some but not all @@ -25,16 +26,17 @@ namespace mozilla { */ template inline To -BitwiseCast(const From from) +BitwiseCast(const From aFrom) { static_assert(sizeof(From) == sizeof(To), "To and From must have the same size"); - union { - From from; - To to; + union + { + From mFrom; + To mTo; } u; - u.from = from; - return u.to; + u.mFrom = aFrom; + return u.mTo; } namespace detail { @@ -58,34 +60,39 @@ enum UUComparison { FromIsBigger, FromIsNotBigger }; // Unsigned-to-unsigned range check template sizeof(To)) ? FromIsBigger : FromIsNotBigger> + UUComparison = (sizeof(From) > sizeof(To)) + ? FromIsBigger + : FromIsNotBigger> struct UnsignedUnsignedCheck; template struct UnsignedUnsignedCheck { - public: - static bool checkBounds(const From from) { - return from <= From(To(-1)); - } +public: + static bool checkBounds(const From aFrom) + { + return aFrom <= From(To(-1)); + } }; template struct UnsignedUnsignedCheck { - public: - static bool checkBounds(const From from) { - return true; - } +public: + static bool checkBounds(const From aFrom) + { + return true; + } }; template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - return UnsignedUnsignedCheck::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return UnsignedUnsignedCheck::checkBounds(aFrom); + } }; // Signed-to-unsigned range check @@ -93,14 +100,17 @@ struct BoundsCheckImpl template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - if (from < 0) - return false; - if (sizeof(To) >= sizeof(From)) - return true; - return from <= From(To(-1)); +public: + static bool checkBounds(const From aFrom) + { + if (aFrom < 0) { + return false; + } + if (sizeof(To) >= sizeof(From)) { + return true; } + return aFrom <= From(To(-1)); + } }; // Unsigned-to-signed range check @@ -108,35 +118,40 @@ struct BoundsCheckImpl enum USComparison { FromIsSmaller, FromIsNotSmaller }; template + USComparison = (sizeof(From) < sizeof(To)) + ? FromIsSmaller + : FromIsNotSmaller> struct UnsignedSignedCheck; template struct UnsignedSignedCheck { - public: - static bool checkBounds(const From from) { - return true; - } +public: + static bool checkBounds(const From aFrom) + { + return true; + } }; template struct UnsignedSignedCheck { - public: - static bool checkBounds(const From from) { - const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); - return from <= From(MaxValue); - } +public: + static bool checkBounds(const From aFrom) + { + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + return aFrom <= From(MaxValue); + } }; template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - return UnsignedSignedCheck::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return UnsignedSignedCheck::checkBounds(aFrom); + } }; // Signed-to-signed range check @@ -144,42 +159,46 @@ struct BoundsCheckImpl template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - if (sizeof(From) <= sizeof(To)) - return true; - const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); - const To MinValue = -MaxValue - To(1); - return From(MinValue) <= from && - From(from) <= From(MaxValue); +public: + static bool checkBounds(const From aFrom) + { + if (sizeof(From) <= sizeof(To)) { + return true; } + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + const To MinValue = -MaxValue - To(1); + return From(MinValue) <= aFrom && + From(aFrom) <= From(MaxValue); + } }; template::value && IsIntegral::value> + bool TypesAreIntegral = IsIntegral::value && + IsIntegral::value> class BoundsChecker; template class BoundsChecker { - public: - static bool checkBounds(const From from) { return true; } +public: + static bool checkBounds(const From aFrom) { return true; } }; template class BoundsChecker { - public: - static bool checkBounds(const From from) { - return BoundsCheckImpl::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return BoundsCheckImpl::checkBounds(aFrom); + } }; template inline bool -IsInBounds(const From from) +IsInBounds(const From aFrom) { - return BoundsChecker::checkBounds(from); + return BoundsChecker::checkBounds(aFrom); } } // namespace detail @@ -191,10 +210,10 @@ IsInBounds(const From from) */ template inline To -SafeCast(const From from) +SafeCast(const From aFrom) { - MOZ_ASSERT((detail::IsInBounds(from))); - return static_cast(from); + MOZ_ASSERT((detail::IsInBounds(aFrom))); + return static_cast(aFrom); } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ChaosMode.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ChaosMode.h new file mode 100644 index 0000000000..ff59f2c6ec --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ChaosMode.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_ChaosMode_h +#define mozilla_ChaosMode_h + +#include +#include + +namespace mozilla { + +/** + * When "chaos mode" is activated, code that makes implicitly nondeterministic + * choices is encouraged to make random and extreme choices, to test more + * code paths and uncover bugs. + */ +class ChaosMode +{ +public: + static bool isActive() + { + // Flip this to true to activate chaos mode + return false; + } + + /** + * Returns a somewhat (but not uniformly) random uint32_t < aBound. + * Not to be used for anything except ChaosMode, since it's not very random. + */ + static uint32_t randomUint32LessThan(uint32_t aBound) + { + return uint32_t(rand()) % aBound; + } +}; + +} /* namespace mozilla */ + +#endif /* mozilla_ChaosMode_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Char16.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Char16.h index ba1acd8c76..e54eb0d5c8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Char16.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Char16.h @@ -9,11 +9,12 @@ #ifndef mozilla_Char16_h #define mozilla_Char16_h +#ifdef __cplusplus + /* - * C11 and C++11 introduce a char16_t type and support for UTF-16 string and - * character literals. C++11's char16_t is a distinct builtin type. C11's - * char16_t is a typedef for uint_least16_t. Technically, char16_t is a 16-bit - * code unit of a Unicode code point, not a "character". + * C++11 introduces a char16_t type and support for UTF-16 string and character + * literals. C++11's char16_t is a distinct builtin type. Technically, char16_t + * is a 16-bit code unit of a Unicode code point, not a "character". */ #ifdef _MSC_VER @@ -23,8 +24,7 @@ * to Windows's 16-bit wchar_t so we can declare UTF-16 literals as constant * expressions (and pass char16_t pointers to Windows APIs). We #define * _CHAR16T here in order to prevent yvals.h from overriding our char16_t - * typedefs, which we set to wchar_t for C++ code and to unsigned short for - * C code. + * typedefs, which we set to wchar_t for C++ code. * * In addition, #defining _CHAR16T will prevent yvals.h from defining a * char32_t type, so we have to undo that damage here and provide our own, @@ -32,14 +32,9 @@ */ # define MOZ_UTF16_HELPER(s) L##s # define _CHAR16T -# ifdef __cplusplus - typedef wchar_t char16_t; -# else - typedef unsigned short char16_t; -# endif - typedef unsigned int char32_t; -#elif defined(__cplusplus) && \ - (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)) +typedef wchar_t char16_t; +typedef unsigned int char32_t; +#else /* C++11 has a builtin char16_t type. */ # define MOZ_UTF16_HELPER(s) u##s /** @@ -50,20 +45,6 @@ # ifdef WIN32 # define MOZ_USE_CHAR16_WRAPPER # endif -#elif !defined(__cplusplus) -# if defined(WIN32) -# include - typedef wchar_t char16_t; -# else - /** - * We can't use the stdint.h uint16_t type here because including - * stdint.h will break building some of our C libraries, such as - * sqlite. - */ - typedef unsigned short char16_t; -# endif -#else -# error "Char16.h requires C++11 (or something like it) for UTF-16 support." #endif #ifdef MOZ_USE_CHAR16_WRAPPER @@ -80,86 +61,109 @@ */ class char16ptr_t { - private: - const char16_t* ptr; - static_assert(sizeof(char16_t) == sizeof(wchar_t), "char16_t and wchar_t sizes differ"); - - public: - char16ptr_t(const char16_t* ptr) : ptr(ptr) {} - char16ptr_t(const wchar_t* ptr) : ptr(reinterpret_cast(ptr)) {} - - /* Without this, nullptr assignment would be ambiguous. */ - constexpr char16ptr_t(decltype(nullptr)) : ptr(nullptr) {} - - operator const char16_t*() const { - return ptr; - } - operator const wchar_t*() const { - return reinterpret_cast(ptr); - } - operator const void*() const { - return ptr; - } - operator bool() const { - return ptr != nullptr; - } - operator std::wstring() const { - return std::wstring(static_cast(*this)); - } - - /* Explicit cast operators to allow things like (char16_t*)str. */ - explicit operator char16_t*() const { - return const_cast(ptr); - } - explicit operator wchar_t*() const { - return const_cast(static_cast(*this)); - } - - /** - * Some Windows API calls accept BYTE* but require that data actually be WCHAR*. - * Supporting this requires explicit operators to support the requisite explicit - * casts. - */ - explicit operator const char*() const { - return reinterpret_cast(ptr); - } - explicit operator const unsigned char*() const { - return reinterpret_cast(ptr); - } - explicit operator unsigned char*() const { - return const_cast(reinterpret_cast(ptr)); - } - explicit operator void*() const { - return const_cast(ptr); - } - - /* Some operators used on pointers. */ - char16_t operator[](size_t i) const { - return ptr[i]; - } - bool operator==(const char16ptr_t &x) const { - return ptr == x.ptr; - } - bool operator==(decltype(nullptr)) const { - return ptr == nullptr; - } - bool operator!=(const char16ptr_t &x) const { - return ptr != x.ptr; - } - bool operator!=(decltype(nullptr)) const { - return ptr != nullptr; - } - char16ptr_t operator+(size_t add) const { - return char16ptr_t(ptr + add); - } - ptrdiff_t operator-(const char16ptr_t &other) const { - return ptr - other.ptr; - } +private: + const char16_t* mPtr; + static_assert(sizeof(char16_t) == sizeof(wchar_t), + "char16_t and wchar_t sizes differ"); + +public: + char16ptr_t(const char16_t* aPtr) : mPtr(aPtr) {} + char16ptr_t(const wchar_t* aPtr) : + mPtr(reinterpret_cast(aPtr)) + {} + + /* Without this, nullptr assignment would be ambiguous. */ + constexpr char16ptr_t(decltype(nullptr)) : mPtr(nullptr) {} + + operator const char16_t*() const + { + return mPtr; + } + operator const wchar_t*() const + { + return reinterpret_cast(mPtr); + } + operator const void*() const + { + return mPtr; + } + operator bool() const + { + return mPtr != nullptr; + } + operator std::wstring() const + { + return std::wstring(static_cast(*this)); + } + + /* Explicit cast operators to allow things like (char16_t*)str. */ + explicit operator char16_t*() const + { + return const_cast(mPtr); + } + explicit operator wchar_t*() const + { + return const_cast(static_cast(*this)); + } + + /** + * Some Windows API calls accept BYTE* but require that data actually be + * WCHAR*. Supporting this requires explicit operators to support the + * requisite explicit casts. + */ + explicit operator const char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator const unsigned char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator unsigned char*() const + { + return + const_cast(reinterpret_cast(mPtr)); + } + explicit operator void*() const + { + return const_cast(mPtr); + } + + /* Some operators used on pointers. */ + char16_t operator[](size_t aIndex) const + { + return mPtr[aIndex]; + } + bool operator==(const char16ptr_t& aOther) const + { + return mPtr == aOther.mPtr; + } + bool operator==(decltype(nullptr)) const + { + return mPtr == nullptr; + } + bool operator!=(const char16ptr_t& aOther) const + { + return mPtr != aOther.mPtr; + } + bool operator!=(decltype(nullptr)) const + { + return mPtr != nullptr; + } + char16ptr_t operator+(size_t aValue) const + { + return char16ptr_t(mPtr + aValue); + } + ptrdiff_t operator-(const char16ptr_t& aOther) const + { + return mPtr - aOther.mPtr; + } }; inline decltype((char*)0-(char*)0) -operator-(const char16_t* x, const char16ptr_t y) { - return x - static_cast(y); +operator-(const char16_t* aX, const char16ptr_t aY) +{ + return aX - static_cast(aY); } #else @@ -168,10 +172,6 @@ typedef const char16_t* char16ptr_t; #endif -/* This is a temporary hack until bug 927728 is fixed. */ -#define __PRUNICHAR__ -typedef char16_t PRUnichar; - /* * Macro arguments used in concatenation or stringification won't be expanded. * Therefore, in order for |MOZ_UTF16(FOO)| to work as expected (which is to @@ -182,12 +182,11 @@ typedef char16_t PRUnichar; */ #define MOZ_UTF16(s) MOZ_UTF16_HELPER(s) -#if defined(__cplusplus) && \ - (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)) static_assert(sizeof(char16_t) == 2, "Is char16_t type 16 bits?"); static_assert(char16_t(-1) > char16_t(0), "Is char16_t type unsigned?"); static_assert(sizeof(MOZ_UTF16('A')) == 2, "Is char literal 16 bits?"); static_assert(sizeof(MOZ_UTF16("")[0]) == 2, "Is string char 16 bits?"); + #endif #endif /* mozilla_Char16_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/CheckedInt.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/CheckedInt.h index 050cef8ed8..ad4c5fef41 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/CheckedInt.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/CheckedInt.h @@ -9,21 +9,9 @@ #ifndef mozilla_CheckedInt_h #define mozilla_CheckedInt_h -// Enable relying of Mozilla's MFBT for possibly-available C++11 features -#define MOZ_CHECKEDINT_USE_MFBT - #include - -#ifdef MOZ_CHECKEDINT_USE_MFBT -# include "mozilla/Assertions.h" -#else -# include -# define MOZ_ASSERT(cond, reason) assert((cond) && reason) -# define MOZ_DELETE -#endif - -#include -#include +#include "mozilla/Assertions.h" +#include "mozilla/IntegerTypeTraits.h" namespace mozilla { @@ -47,13 +35,13 @@ struct UnsupportedType {}; template struct IsSupportedPass2 { - static const bool value = false; + static const bool value = false; }; template struct IsSupported { - static const bool value = IsSupportedPass2::value; + static const bool value = IsSupportedPass2::value; }; template<> @@ -134,133 +122,45 @@ struct IsSupportedPass2 { static const bool value = true; }; /* - * Step 2: some integer-traits kind of stuff. + * Step 2: Implement the actual validity checks. + * + * Ideas taken from IntegerLib, code different. */ -template -struct StdintTypeForSizeAndSignedness -{}; - -template<> -struct StdintTypeForSizeAndSignedness<1, true> -{ typedef int8_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<1, false> -{ typedef uint8_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<2, true> -{ typedef int16_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<2, false> -{ typedef uint16_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<4, true> -{ typedef int32_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<4, false> -{ typedef uint32_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<8, true> -{ typedef int64_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<8, false> -{ typedef uint64_t Type; }; - -template -struct UnsignedType -{ - typedef typename StdintTypeForSizeAndSignedness::Type Type; -}; - -template -struct IsSigned -{ - static const bool value = IntegerType(-1) <= IntegerType(0); -}; - template struct TwiceBiggerType { - typedef typename StdintTypeForSizeAndSignedness< - sizeof(IntegerType) * 2, - IsSigned::value - >::Type Type; + typedef typename detail::StdintTypeForSizeAndSignedness< + sizeof(IntegerType) * 2, + IsSigned::value + >::Type Type; }; template struct TwiceBiggerType { - typedef UnsupportedType Type; + typedef UnsupportedType Type; }; -template -struct PositionOfSignBit -{ - static const size_t value = CHAR_BIT * sizeof(IntegerType) - 1; -}; - -template -struct MinValue -{ - private: - typedef typename UnsignedType::Type UnsignedIntegerType; - static const size_t PosOfSignBit = PositionOfSignBit::value; - - public: - // Bitwise ops may return a larger type, that's why we cast explicitly. - // In C++, left bit shifts on signed values is undefined by the standard - // unless the shifted value is representable. - // Notice that signed-to-unsigned conversions are always well-defined in - // the standard as the value congruent to 2**n, as expected. By contrast, - // unsigned-to-signed is only well-defined if the value is representable. - static const IntegerType value = - IsSigned::value - ? IntegerType(UnsignedIntegerType(1) << PosOfSignBit) - : IntegerType(0); -}; - -template -struct MaxValue -{ - // Tricksy, but covered by the unit test. - // Relies heavily on the type of MinValue::value - // being IntegerType. - static const IntegerType value = ~MinValue::value; -}; - -/* - * Step 3: Implement the actual validity checks. - * - * Ideas taken from IntegerLib, code different. - */ - template inline bool -HasSignBit(T x) +HasSignBit(T aX) { // In C++, right bit shifts on negative values is undefined by the standard. // Notice that signed-to-unsigned conversions are always well-defined in the // standard, as the value congruent modulo 2**n as expected. By contrast, // unsigned-to-signed is only well-defined if the value is representable. - return bool(typename UnsignedType::Type(x) - >> PositionOfSignBit::value); + return bool(typename MakeUnsigned::Type(aX) >> + PositionOfSignBit::value); } // Bitwise ops may return a larger type, so it's good to use this inline // helper guaranteeing that the result is really of type T. template inline T -BinaryComplement(T x) +BinaryComplement(T aX) { - return ~x; + return ~aX; } template struct DoesRangeContainRange { - static const bool value = sizeof(T) >= sizeof(U); + static const bool value = sizeof(T) >= sizeof(U); }; template struct DoesRangeContainRange { - static const bool value = sizeof(T) > sizeof(U); + static const bool value = sizeof(T) > sizeof(U); }; template struct DoesRangeContainRange { - static const bool value = false; + static const bool value = false; }; template struct IsInRangeImpl { - static bool run(U) - { - return true; - } + static bool run(U) + { + return true; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return x <= MaxValue::value && x >= MinValue::value; - } + static bool run(U aX) + { + return aX <= MaxValue::value && aX >= MinValue::value; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return x <= MaxValue::value; - } + static bool run(U aX) + { + return aX <= MaxValue::value; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return sizeof(T) > sizeof(U) || x <= U(MaxValue::value); - } + static bool run(U aX) + { + return sizeof(T) > sizeof(U) || aX <= U(MaxValue::value); + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return sizeof(T) >= sizeof(U) - ? x >= 0 - : x >= 0 && x <= U(MaxValue::value); - } + static bool run(U aX) + { + return sizeof(T) >= sizeof(U) + ? aX >= 0 + : aX >= 0 && aX <= U(MaxValue::value); + } }; template inline bool -IsInRange(U x) +IsInRange(U aX) { - return IsInRangeImpl::run(x); + return IsInRangeImpl::run(aX); } template inline bool -IsAddValid(T x, T y) +IsAddValid(T aX, T aY) { - // Addition is valid if the sign of x+y is equal to either that of x or that - // of y. Since the value of x+y is undefined if we have a signed type, we - // compute it using the unsigned type of the same size. - // Beware! These bitwise operations can return a larger integer type, - // if T was a small type like int8_t, so we explicitly cast to T. + // Addition is valid if the sign of aX+aY is equal to either that of aX or + // that of aY. Since the value of aX+aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. Beware! + // These bitwise operations can return a larger integer type, if T was a + // small type like int8_t, so we explicitly cast to T. - typename UnsignedType::Type ux = x; - typename UnsignedType::Type uy = y; - typename UnsignedType::Type result = ux + uy; + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux + uy; return IsSigned::value - ? HasSignBit(BinaryComplement(T((result ^ x) & (result ^ y)))) - : BinaryComplement(x) >= y; + ? HasSignBit(BinaryComplement(T((result ^ aX) & (result ^ aY)))) + : BinaryComplement(aX) >= aY; } template inline bool -IsSubValid(T x, T y) +IsSubValid(T aX, T aY) { - // Subtraction is valid if either x and y have same sign, or x-y and x have - // same sign. Since the value of x-y is undefined if we have a signed type, - // we compute it using the unsigned type of the same size. - typename UnsignedType::Type ux = x; - typename UnsignedType::Type uy = y; - typename UnsignedType::Type result = ux - uy; + // Subtraction is valid if either aX and aY have same sign, or aX-aY and aX + // have same sign. Since the value of aX-aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux - uy; return IsSigned::value - ? HasSignBit(BinaryComplement(T((result ^ x) & (x ^ y)))) - : x >= y; + ? HasSignBit(BinaryComplement(T((result ^ aX) & (aX ^ aY)))) + : aX >= aY; } template struct IsMulValidImpl { - static bool run(T x, T y) - { - typedef typename TwiceBiggerType::Type TwiceBiggerType; - TwiceBiggerType product = TwiceBiggerType(x) * TwiceBiggerType(y); - return IsInRange(product); - } + static bool run(T aX, T aY) + { + typedef typename TwiceBiggerType::Type TwiceBiggerType; + TwiceBiggerType product = TwiceBiggerType(aX) * TwiceBiggerType(aY); + return IsInRange(product); + } }; template struct IsMulValidImpl { - static bool run(T x, T y) - { - const T max = MaxValue::value; - const T min = MinValue::value; - - if (x == 0 || y == 0) - return true; - - if (x > 0) { - return y > 0 - ? x <= max / y - : y >= min / x; - } + static bool run(T aX, T aY) + { + const T max = MaxValue::value; + const T min = MinValue::value; - // If we reach this point, we know that x < 0. - return y > 0 - ? x >= min / y - : y >= max / x; + if (aX == 0 || aY == 0) { + return true; } + if (aX > 0) { + return aY > 0 + ? aX <= max / aY + : aY >= min / aX; + } + + // If we reach this point, we know that aX < 0. + return aY > 0 + ? aX >= min / aY + : aY >= max / aX; + } }; template struct IsMulValidImpl { - static bool run(T x, T y) - { - return y == 0 || x <= MaxValue::value / y; - } + static bool run(T aX, T aY) + { + return aY == 0 || aX <= MaxValue::value / aY; + } }; template inline bool -IsMulValid(T x, T y) +IsMulValid(T aX, T aY) { - return IsMulValidImpl::run(x, y); + return IsMulValidImpl::run(aX, aY); } template inline bool -IsDivValid(T x, T y) +IsDivValid(T aX, T aY) { - // Keep in mind that in the signed case, min/-1 is invalid because abs(min)>max. - return y != 0 && - !(IsSigned::value && x == MinValue::value && y == T(-1)); + // Keep in mind that in the signed case, min/-1 is invalid because + // abs(min)>max. + return aY != 0 && + !(IsSigned::value && aX == MinValue::value && aY == T(-1)); } template::value> @@ -455,36 +356,40 @@ struct IsModValidImpl; template inline bool -IsModValid(T x, T y) +IsModValid(T aX, T aY) { - return IsModValidImpl::run(x, y); + return IsModValidImpl::run(aX, aY); } /* * Mod is pretty simple. * For now, let's just use the ANSI C definition: - * If x or y are negative, the results are implementation defined. + * If aX or aY are negative, the results are implementation defined. * Consider these invalid. - * Undefined for y=0. - * The result will never exceed either x or y. + * Undefined for aY=0. + * The result will never exceed either aX or aY. * - * Checking that x>=0 is a warning when T is unsigned. + * Checking that aX>=0 is a warning when T is unsigned. */ template -struct IsModValidImpl { - static inline bool run(T x, T y) { - return y >= 1; +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + return aY >= 1; } }; template -struct IsModValidImpl { - static inline bool run(T x, T y) { - if (x < 0) +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + if (aX < 0) { return false; - - return y >= 1; + } + return aY >= 1; } }; @@ -494,32 +399,33 @@ struct NegateImpl; template struct NegateImpl { - static CheckedInt negate(const CheckedInt& val) - { - // Handle negation separately for signed/unsigned, for simpler code and to - // avoid an MSVC warning negating an unsigned value. - return CheckedInt(0, val.isValid() && val.mValue == 0); - } + static CheckedInt negate(const CheckedInt& aVal) + { + // Handle negation separately for signed/unsigned, for simpler code and to + // avoid an MSVC warning negating an unsigned value. + return CheckedInt(0, aVal.isValid() && aVal.mValue == 0); + } }; template struct NegateImpl { - static CheckedInt negate(const CheckedInt& val) - { - // Watch out for the min-value, which (with twos-complement) can't be - // negated as -min-value is then (max-value + 1). - if (!val.isValid() || val.mValue == MinValue::value) - return CheckedInt(val.mValue, false); - return CheckedInt(-val.mValue, true); + static CheckedInt negate(const CheckedInt& aVal) + { + // Watch out for the min-value, which (with twos-complement) can't be + // negated as -min-value is then (max-value + 1). + if (!aVal.isValid() || aVal.mValue == MinValue::value) { + return CheckedInt(aVal.mValue, false); } + return CheckedInt(-aVal.mValue, true); + } }; } // namespace detail /* - * Step 4: Now define the CheckedInt class. + * Step 3: Now define the CheckedInt class. */ /** @@ -538,18 +444,18 @@ struct NegateImpl * (e.g. in case of a division by zero). * * For example, suppose that you want to implement a function that computes - * (x+y)/z, that doesn't crash if z==0, and that reports on error (divide by + * (aX+aY)/aZ, that doesn't crash if aZ==0, and that reports on error (divide by * zero or integer overflow). You could code it as follows: @code - bool computeXPlusYOverZ(int x, int y, int z, int *result) + bool computeXPlusYOverZ(int aX, int aY, int aZ, int* aResult) { - CheckedInt checkedResult = (CheckedInt(x) + y) / z; - if (checkedResult.isValid()) { - *result = checkedResult.value(); - return true; - } else { - return false; - } + CheckedInt checkedResult = (CheckedInt(aX) + aY) / aZ; + if (checkedResult.isValid()) { + *aResult = checkedResult.value(); + return true; + } else { + return false; + } } @endcode * @@ -592,193 +498,188 @@ struct NegateImpl template class CheckedInt { - protected: - T mValue; - bool mIsValid; +protected: + T mValue; + bool mIsValid; - template - CheckedInt(U value, bool isValid) : mValue(value), mIsValid(isValid) - { - static_assert(detail::IsSupported::value && - detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + template + CheckedInt(U aValue, bool aIsValid) : mValue(aValue), mIsValid(aIsValid) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - friend struct detail::NegateImpl; - - public: - /** - * Constructs a checked integer with given @a value. The checked integer is - * initialized as valid or invalid depending on whether the @a value - * is in range. - * - * This constructor is not explicit. Instead, the type of its argument is a - * separate template parameter, ensuring that no conversion is performed - * before this constructor is actually called. As explained in the above - * documentation for class CheckedInt, this constructor checks that its - * argument is valid. - */ - template - CheckedInt(U value) - : mValue(T(value)), - mIsValid(detail::IsInRange(value)) - { - static_assert(detail::IsSupported::value && - detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + friend struct detail::NegateImpl; + +public: + /** + * Constructs a checked integer with given @a value. The checked integer is + * initialized as valid or invalid depending on whether the @a value + * is in range. + * + * This constructor is not explicit. Instead, the type of its argument is a + * separate template parameter, ensuring that no conversion is performed + * before this constructor is actually called. As explained in the above + * documentation for class CheckedInt, this constructor checks that its + * argument is valid. + */ + template + CheckedInt(U aValue) + : mValue(T(aValue)), + mIsValid(detail::IsInRange(aValue)) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - template - friend class CheckedInt; + template + friend class CheckedInt; - template - CheckedInt toChecked() const - { - CheckedInt ret(mValue); - ret.mIsValid = ret.mIsValid && mIsValid; - return ret; - } + template + CheckedInt toChecked() const + { + CheckedInt ret(mValue); + ret.mIsValid = ret.mIsValid && mIsValid; + return ret; + } - /** Constructs a valid checked integer with initial value 0 */ - CheckedInt() : mValue(0), mIsValid(true) - { - static_assert(detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + /** Constructs a valid checked integer with initial value 0 */ + CheckedInt() : mValue(0), mIsValid(true) + { + static_assert(detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - /** @returns the actual value */ - T value() const - { - MOZ_ASSERT(mIsValid, "Invalid checked integer (division by zero or integer overflow)"); - return mValue; - } + /** @returns the actual value */ + T value() const + { + MOZ_ASSERT(mIsValid, "Invalid checked integer (division by zero or integer overflow)"); + return mValue; + } - /** - * @returns true if the checked integer is valid, i.e. is not the result - * of an invalid operation or of an operation involving an invalid checked - * integer - */ - bool isValid() const - { - return mIsValid; - } + /** + * @returns true if the checked integer is valid, i.e. is not the result + * of an invalid operation or of an operation involving an invalid checked + * integer + */ + bool isValid() const + { + return mIsValid; + } - template - friend CheckedInt operator +(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator +=(U rhs); - - template - friend CheckedInt operator -(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator -=(U rhs); - - template - friend CheckedInt operator *(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator *=(U rhs); - - template - friend CheckedInt operator /(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator /=(U rhs); - - template - friend CheckedInt operator %(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator %=(U rhs); - - CheckedInt operator -() const - { - return detail::NegateImpl::negate(*this); - } + template + friend CheckedInt operator +(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator +=(U aRhs); + + template + friend CheckedInt operator -(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator -=(U aRhs); + + template + friend CheckedInt operator *(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator *=(U aRhs); + + template + friend CheckedInt operator /(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator /=(U aRhs); + + template + friend CheckedInt operator %(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator %=(U aRhs); + + CheckedInt operator -() const + { + return detail::NegateImpl::negate(*this); + } - /** - * @returns true if the left and right hand sides are valid - * and have the same value. - * - * Note that these semantics are the reason why we don't offer - * a operator!=. Indeed, we'd want to have a!=b be equivalent to !(a==b) - * but that would mean that whenever a or b is invalid, a!=b - * is always true, which would be very confusing. - * - * For similar reasons, operators <, >, <=, >= would be very tricky to - * specify, so we just avoid offering them. - * - * Notice that these == semantics are made more reasonable by these facts: - * 1. a==b implies equality at the raw data level - * (the converse is false, as a==b is never true among invalids) - * 2. This is similar to the behavior of IEEE floats, where a==b - * means that a and b have the same value *and* neither is NaN. - */ - bool operator ==(const CheckedInt& other) const - { - return mIsValid && other.mIsValid && mValue == other.mValue; - } + /** + * @returns true if the left and right hand sides are valid + * and have the same value. + * + * Note that these semantics are the reason why we don't offer + * a operator!=. Indeed, we'd want to have a!=b be equivalent to !(a==b) + * but that would mean that whenever a or b is invalid, a!=b + * is always true, which would be very confusing. + * + * For similar reasons, operators <, >, <=, >= would be very tricky to + * specify, so we just avoid offering them. + * + * Notice that these == semantics are made more reasonable by these facts: + * 1. a==b implies equality at the raw data level + * (the converse is false, as a==b is never true among invalids) + * 2. This is similar to the behavior of IEEE floats, where a==b + * means that a and b have the same value *and* neither is NaN. + */ + bool operator ==(const CheckedInt& aOther) const + { + return mIsValid && aOther.mIsValid && mValue == aOther.mValue; + } - /** prefix ++ */ - CheckedInt& operator++() - { - *this += 1; - return *this; - } + /** prefix ++ */ + CheckedInt& operator++() + { + *this += 1; + return *this; + } - /** postfix ++ */ - CheckedInt operator++(int) - { - CheckedInt tmp = *this; - *this += 1; - return tmp; - } + /** postfix ++ */ + CheckedInt operator++(int) + { + CheckedInt tmp = *this; + *this += 1; + return tmp; + } - /** prefix -- */ - CheckedInt& operator--() - { - *this -= 1; - return *this; - } + /** prefix -- */ + CheckedInt& operator--() + { + *this -= 1; + return *this; + } - /** postfix -- */ - CheckedInt operator--(int) - { - CheckedInt tmp = *this; - *this -= 1; - return tmp; - } + /** postfix -- */ + CheckedInt operator--(int) + { + CheckedInt tmp = *this; + *this -= 1; + return tmp; + } - private: - /** - * The !=, <, <=, >, >= operators are disabled: - * see the comment on operator==. - */ - template - bool operator !=(U other) const MOZ_DELETE; - template - bool operator <(U other) const MOZ_DELETE; - template - bool operator <=(U other) const MOZ_DELETE; - template - bool operator >(U other) const MOZ_DELETE; - template - bool operator >=(U other) const MOZ_DELETE; +private: + /** + * The !=, <, <=, >, >= operators are disabled: + * see the comment on operator==. + */ + template bool operator !=(U aOther) const MOZ_DELETE; + template bool operator < (U aOther) const MOZ_DELETE; + template bool operator <=(U aOther) const MOZ_DELETE; + template bool operator > (U aOther) const MOZ_DELETE; + template bool operator >=(U aOther) const MOZ_DELETE; }; -#define MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP) \ -template \ -inline CheckedInt operator OP(const CheckedInt &lhs, \ - const CheckedInt &rhs) \ -{ \ - if (!detail::Is##NAME##Valid(lhs.mValue, rhs.mValue)) \ - return CheckedInt(0, false); \ - \ - return CheckedInt(lhs.mValue OP rhs.mValue, \ - lhs.mIsValid && rhs.mIsValid); \ -} +#define MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP) \ + template \ + inline CheckedInt \ + operator OP(const CheckedInt &aLhs, const CheckedInt &aRhs) \ + { \ + if (!detail::Is##NAME##Valid(aLhs.mValue, aRhs.mValue)) { \ + return CheckedInt(0, false); \ + } \ + return CheckedInt(aLhs.mValue OP aRhs.mValue, \ + aLhs.mIsValid && aRhs.mIsValid); \ + } MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Add, +) MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Sub, -) @@ -799,47 +700,47 @@ namespace detail { template struct CastToCheckedIntImpl { - typedef CheckedInt ReturnType; - static CheckedInt run(U u) { return u; } + typedef CheckedInt ReturnType; + static CheckedInt run(U aU) { return aU; } }; template struct CastToCheckedIntImpl > { - typedef const CheckedInt& ReturnType; - static const CheckedInt& run(const CheckedInt& u) { return u; } + typedef const CheckedInt& ReturnType; + static const CheckedInt& run(const CheckedInt& aU) { return aU; } }; } // namespace detail template inline typename detail::CastToCheckedIntImpl::ReturnType -castToCheckedInt(U u) +castToCheckedInt(U aU) { static_assert(detail::IsSupported::value && detail::IsSupported::value, "This type is not supported by CheckedInt"); - return detail::CastToCheckedIntImpl::run(u); + return detail::CastToCheckedIntImpl::run(aU); } -#define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP) \ -template \ -template \ -CheckedInt& CheckedInt::operator COMPOUND_OP(U rhs) \ -{ \ - *this = *this OP castToCheckedInt(rhs); \ - return *this; \ -} \ -template \ -inline CheckedInt operator OP(const CheckedInt &lhs, U rhs) \ -{ \ - return lhs OP castToCheckedInt(rhs); \ -} \ -template \ -inline CheckedInt operator OP(U lhs, const CheckedInt &rhs) \ -{ \ - return castToCheckedInt(lhs) OP rhs; \ -} +#define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP) \ + template \ + template \ + CheckedInt& CheckedInt::operator COMPOUND_OP(U aRhs) \ + { \ + *this = *this OP castToCheckedInt(aRhs); \ + return *this; \ + } \ + template \ + inline CheckedInt operator OP(const CheckedInt &aLhs, U aRhs) \ + { \ + return aLhs OP castToCheckedInt(aRhs); \ + } \ + template \ + inline CheckedInt operator OP(U aLhs, const CheckedInt &aRhs) \ + { \ + return castToCheckedInt(aLhs) OP aRhs; \ + } MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(+, +=) MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(*, *=) @@ -851,16 +752,16 @@ MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(%, %=) template inline bool -operator ==(const CheckedInt &lhs, U rhs) +operator ==(const CheckedInt &aLhs, U aRhs) { - return lhs == castToCheckedInt(rhs); + return aLhs == castToCheckedInt(aRhs); } template inline bool -operator ==(U lhs, const CheckedInt &rhs) +operator ==(U aLhs, const CheckedInt &aRhs) { - return castToCheckedInt(lhs) == rhs; + return castToCheckedInt(aLhs) == aRhs; } // Convenience typedefs. diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Compiler.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Compiler.h index fd5c98c98d..50f127da86 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Compiler.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Compiler.h @@ -9,23 +9,41 @@ #ifndef mozilla_Compiler_h #define mozilla_Compiler_h +#define MOZ_IS_GCC 0 +#define MOS_IS_MSVC 0 + #if !defined(__clang__) && defined(__GNUC__) -#define MOZ_IS_GCC 1 +# undef MOZ_IS_GCC +# define MOZ_IS_GCC 1 /* * This macro should simplify gcc version checking. For example, to check - * for gcc 4.5.1 or later, check `#ifdef MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`. + * for gcc 4.5.1 or later, check `#if MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`. */ # define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel) \ ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \ >= ((major) * 10000 + (minor) * 100 + (patchlevel))) -#if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0) -# error "mfbt (and Gecko) require at least gcc 4.4 to build." -#endif +# if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0) +# error "mfbt (and Gecko) require at least gcc 4.4 to build." +# endif -#else +#elif defined(_MSC_VER) -#define MOZ_IS_GCC 0 +# undef MOZ_IS_MSVC +# define MOZ_IS_MSVC 1 + /* + * This macro should simplify MSVC version checking. For example, to check + * for VC10 or later, check `#ifdef MOZ_MSVC_VERSION_AT_LEAST(10)`. + */ +# define MOZ_MSVC_VERSION_AT_LEAST(version) \ + (version == 10 ? _MSC_VER >= 1600 : \ + (version == 11 ? _MSC_VER >= 1700 : \ + (version == 12 ? _MSC_VER >= 1800 : \ + (version == 13 ? _MSC_VER >= 1900 : \ + 0)))) +# if !MOZ_MSVC_VERSION_AT_LEAST(10) +# error "mfbt (and Gecko) require at least MSVC 2010 RTM to build." +# endif #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Compression.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Compression.h index 2b8a7a7d8e..a764a1b5d5 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Compression.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Compression.h @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -22,41 +23,41 @@ namespace Compression { * * Compared to zlib it compresses at about 10x the speed, decompresses at about * 4x the speed and produces output of about 1.5x the size. - * */ class LZ4 { - public: - /** - * Compresses 'inputSize' bytes from 'source' into 'dest'. - * Destination buffer must be already allocated, - * and must be sized to handle worst cases situations (input data not compressible) - * Worst case size evaluation is provided by function LZ4_compressBound() + * Compresses |aInputSize| bytes from |aSource| into |aDest|. Destination + * buffer must be already allocated, and must be sized to handle worst cases + * situations (input data not compressible). Worst case size evaluation is + * provided by function maxCompressedSize() * - * @param inputSize is the input size. Max supported value is ~1.9GB - * @param return the number of bytes written in buffer dest + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return the number of bytes written in buffer |aDest| */ - static MFBT_API size_t compress(const char* source, size_t inputSize, char* dest); + static MFBT_API size_t + compress(const char* aSource, size_t aInputSize, char* aDest); /** - * Compress 'inputSize' bytes from 'source' into an output buffer - * 'dest' of maximum size 'maxOutputSize'. If it cannot achieve it, + * Compress |aInputSize| bytes from |aSource| into an output buffer + * |aDest| of maximum size |aMaxOutputSize|. If it cannot achieve it, * compression will stop, and result of the function will be zero, - * 'dest' will still be written to, but since the number of input + * |aDest| will still be written to, but since the number of input * bytes consumed is not returned the result is not usable. * * This function never writes outside of provided output buffer. * - * @param inputSize is the input size. Max supported value is ~1.9GB - * @param maxOutputSize is the size of the destination buffer (which must be already allocated) - * @return the number of bytes written in buffer 'dest' - or 0 if the compression fails - */ - static MFBT_API size_t compressLimitedOutput(const char* source, size_t inputSize, char* dest, - size_t maxOutputSize); + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @param aMaxOutputSize is the size of the destination buffer (which must + * be already allocated) + * @return the number of bytes written in buffer |aDest| or 0 if the + * compression fails + */ + static MFBT_API size_t + compressLimitedOutput(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize); /** * If the source stream is malformed, the function will stop decoding @@ -66,48 +67,50 @@ class LZ4 * This function never writes outside of provided buffers, and never * modifies input buffer. * - * note : destination buffer must be already allocated. - * its size must be a minimum of 'outputSize' bytes. - * @param outputSize is the output size, therefore the original size + * Note: destination buffer must be already allocated, and its size must be a + * minimum of |aOutputSize| bytes. + * + * @param aOutputSize is the output size, therefore the original size * @return the number of bytes read in the source buffer - */ - static MFBT_API bool decompress(const char* source, char* dest, size_t outputSize); + */ + static MFBT_API bool + decompress(const char* aSource, char* aDest, size_t aOutputSize); /** * If the source stream is malformed, the function will stop decoding * and return false. * - * This function never writes beyond dest + maxOutputSize, and is + * This function never writes beyond aDest + aMaxOutputSize, and is * therefore protected against malicious data packets. * - * note : Destination buffer must be already allocated. - * This version is slightly slower than the decompress - * without the maxOutputSize + * Note: Destination buffer must be already allocated. This version is + * slightly slower than the decompress without the aMaxOutputSize. * - * @param inputSize is the length of the input compressed data - * @param maxOutputSize is the size of the destination buffer (which must be already allocated) - * @param outputSize the actual number of bytes decoded in the destination buffer (necessarily <= maxOutputSize) - - */ - static MFBT_API bool decompress(const char* source, size_t inputSize, char* dest, - size_t maxOutputSize, size_t *outputSize); + * @param aInputSize is the length of the input compressed data + * @param aMaxOutputSize is the size of the destination buffer (which must be + * already allocated) + * @param aOutputSize the actual number of bytes decoded in the destination + * buffer (necessarily <= aMaxOutputSize) + */ + static MFBT_API bool + decompress(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize, size_t* aOutputSize); /* - Provides the maximum size that LZ4 may output in a "worst case" - scenario (input data not compressible) primarily useful for memory - allocation of output buffer. - note : this function is limited by "int" range (2^31-1) - - @param inputSize is the input size. Max supported value is ~1.9GB - @return maximum output size in a "worst case" scenario - */ - static inline size_t maxCompressedSize(size_t inputSize) + * Provides the maximum size that LZ4 may output in a "worst case" + * scenario (input data not compressible) primarily useful for memory + * allocation of output buffer. + * note : this function is limited by "int" range (2^31-1) + * + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return maximum output size in a "worst case" scenario + */ + static inline size_t maxCompressedSize(size_t aInputSize) { - size_t max = ((inputSize) + ((inputSize)/255) + 16); - MOZ_ASSERT(max > inputSize); - return max; + size_t max = (aInputSize + (aInputSize / 255) + 16); + MOZ_ASSERT(max > aInputSize); + return max; } - }; } /* namespace Compression */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/DebugOnly.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/DebugOnly.h index e5f0d729b5..5d0197b194 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/DebugOnly.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/DebugOnly.h @@ -12,6 +12,8 @@ #ifndef mozilla_DebugOnly_h #define mozilla_DebugOnly_h +#include "mozilla/Attributes.h" + namespace mozilla { /** @@ -27,50 +29,51 @@ namespace mozilla { * * DebugOnly instances can only be coerced to T in debug builds. In release * builds they don't have a value, so type coercion is not well defined. + * + * Note that DebugOnly instances still take up one byte of space, plus padding, + * when used as members of structs. */ template class DebugOnly { - public: +public: #ifdef DEBUG - T value; + T value; + + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T& aOther) : value(aOther) { } + DebugOnly(const DebugOnly& aOther) : value(aOther.value) { } + DebugOnly& operator=(const T& aRhs) { + value = aRhs; + return *this; + } - DebugOnly() { } - DebugOnly(const T& other) : value(other) { } - DebugOnly(const DebugOnly& other) : value(other.value) { } - DebugOnly& operator=(const T& rhs) { - value = rhs; - return *this; - } - void operator++(int) { - value++; - } - void operator--(int) { - value--; - } + void operator++(int) { value++; } + void operator--(int) { value--; } - T* operator&() { return &value; } + T* operator&() { return &value; } - operator T&() { return value; } - operator const T&() const { return value; } + operator T&() { return value; } + operator const T&() const { return value; } - T& operator->() { return value; } + T& operator->() { return value; } + const T& operator->() const { return value; } #else - DebugOnly() { } - DebugOnly(const T&) { } - DebugOnly(const DebugOnly&) { } - DebugOnly& operator=(const T&) { return *this; } - void operator++(int) { } - void operator--(int) { } + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T&) { } + DebugOnly(const DebugOnly&) { } + DebugOnly& operator=(const T&) { return *this; } + void operator++(int) { } + void operator--(int) { } #endif - /* - * DebugOnly must always have a destructor or else it will - * generate "unused variable" warnings, exactly what it's intended - * to avoid! - */ - ~DebugOnly() {} + /* + * DebugOnly must always have a destructor or else it will + * generate "unused variable" warnings, exactly what it's intended + * to avoid! + */ + ~DebugOnly() {} }; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Decimal.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Decimal.h index 3c67d784c9..9f4926bd06 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Decimal.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Decimal.h @@ -112,7 +112,7 @@ class Decimal { Sign m_sign; }; - MFBT_API Decimal(int32_t = 0); + MFBT_API explicit Decimal(int32_t = 0); MFBT_API Decimal(Sign, int exponent, uint64_t coefficient); MFBT_API Decimal(const Decimal&); @@ -185,7 +185,7 @@ class Decimal { int exponent; }; - MFBT_API Decimal(double); + MFBT_API explicit Decimal(double); MFBT_API Decimal compareTo(const Decimal&) const; static MFBT_API AlignedOperands alignOperands(const Decimal& lhs, const Decimal& rhs); diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Endian.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Endian.h index cb6bd27c05..e4e1ff8549 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Endian.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Endian.h @@ -42,21 +42,22 @@ * * class ExampleHeader * { - * private: - * uint32_t magic; - * uint32_t length; - * uint32_t totalRecords; - * uint64_t checksum; + * private: + * uint32_t mMagic; + * uint32_t mLength; + * uint32_t mTotalRecords; + * uint64_t mChecksum; * - * public: - * ExampleHeader(const void* data) { - * const uint8_t* ptr = static_cast(data); - * magic = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * length = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * totalRecords = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * checksum = BigEndian::readUint64(ptr); - * } - * ... + * public: + * ExampleHeader(const void* data) + * { + * const uint8_t* ptr = static_cast(data); + * mMagic = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mLength = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mTotalRecords = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mChecksum = BigEndian::readUint64(ptr); + * } + * ... * }; */ @@ -91,7 +92,7 @@ # else # error "CPU type is unknown" # endif -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) # if __LITTLE_ENDIAN__ # define MOZ_LITTLE_ENDIAN 1 # elif __BIG_ENDIAN__ @@ -119,17 +120,16 @@ * cases. */ #elif defined(__sparc) || defined(__sparc__) || \ - defined(_POWER) || defined(__powerpc__) || \ - defined(__ppc__) || defined(__hppa) || \ + defined(_POWER) || defined(__hppa) || \ defined(_MIPSEB) || defined(__ARMEB__) || \ - defined(__s390__) || \ + defined(__s390__) || defined(__AARCH64EB__) || \ (defined(__sh__) && defined(__LITTLE_ENDIAN__)) || \ (defined(__ia64) && defined(__BIG_ENDIAN__)) # define MOZ_BIG_ENDIAN 1 #elif defined(__i386) || defined(__i386__) || \ defined(__x86_64) || defined(__x86_64__) || \ defined(_MIPSEL) || defined(__ARMEL__) || \ - defined(__alpha__) || \ + defined(__alpha__) || defined(__AARCH64EL__) || \ (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ (defined(__ia64) && !defined(__BIG_ENDIAN__)) # define MOZ_LITTLE_ENDIAN 1 @@ -170,12 +170,12 @@ struct Swapper; template struct Swapper { - static T swap(T value) + static T swap(T aValue) { #if defined(MOZ_HAVE_BUILTIN_BYTESWAP16) - return MOZ_HAVE_BUILTIN_BYTESWAP16(value); + return MOZ_HAVE_BUILTIN_BYTESWAP16(aValue); #else - return T(((value & 0x00ff) << 8) | ((value & 0xff00) >> 8)); + return T(((aValue & 0x00ff) << 8) | ((aValue & 0xff00) >> 8)); #endif } }; @@ -183,17 +183,17 @@ struct Swapper template struct Swapper { - static T swap(T value) + static T swap(T aValue) { #if defined(__clang__) || defined(__GNUC__) - return T(__builtin_bswap32(value)); + return T(__builtin_bswap32(aValue)); #elif defined(_MSC_VER) - return T(_byteswap_ulong(value)); + return T(_byteswap_ulong(aValue)); #else - return T(((value & 0x000000ffU) << 24) | - ((value & 0x0000ff00U) << 8) | - ((value & 0x00ff0000U) >> 8) | - ((value & 0xff000000U) >> 24)); + return T(((aValue & 0x000000ffU) << 24) | + ((aValue & 0x0000ff00U) << 8) | + ((aValue & 0x00ff0000U) >> 8) | + ((aValue & 0xff000000U) >> 24)); #endif } }; @@ -201,21 +201,21 @@ struct Swapper template struct Swapper { - static inline T swap(T value) + static inline T swap(T aValue) { #if defined(__clang__) || defined(__GNUC__) - return T(__builtin_bswap64(value)); + return T(__builtin_bswap64(aValue)); #elif defined(_MSC_VER) - return T(_byteswap_uint64(value)); + return T(_byteswap_uint64(aValue)); #else - return T(((value & 0x00000000000000ffULL) << 56) | - ((value & 0x000000000000ff00ULL) << 40) | - ((value & 0x0000000000ff0000ULL) << 24) | - ((value & 0x00000000ff000000ULL) << 8) | - ((value & 0x000000ff00000000ULL) >> 8) | - ((value & 0x0000ff0000000000ULL) >> 24) | - ((value & 0x00ff000000000000ULL) >> 40) | - ((value & 0xff00000000000000ULL) >> 56)); + return T(((aValue & 0x00000000000000ffULL) << 56) | + ((aValue & 0x000000000000ff00ULL) << 40) | + ((aValue & 0x0000000000ff0000ULL) << 24) | + ((aValue & 0x00000000ff000000ULL) << 8) | + ((aValue & 0x000000ff00000000ULL) >> 8) | + ((aValue & 0x0000ff0000000000ULL) >> 24) | + ((aValue & 0x00ff000000000000ULL) >> 40) | + ((aValue & 0xff00000000000000ULL) >> 56)); #endif } }; @@ -230,360 +230,415 @@ enum Endianness { Little, Big }; class EndianUtils { - /** - * Assert that the memory regions [dest, dest+count) and [src, src+count] - * do not overlap. count is given in bytes. - */ - static void assertNoOverlap(const void* dest, const void* src, size_t count) - { - DebugOnly byteDestPtr = static_cast(dest); - DebugOnly byteSrcPtr = static_cast(src); - MOZ_ASSERT((byteDestPtr <= byteSrcPtr && - byteDestPtr + count <= byteSrcPtr) || - (byteSrcPtr <= byteDestPtr && - byteSrcPtr + count <= byteDestPtr)); - } + /** + * Assert that the memory regions [aDest, aDest+aCount) and + * [aSrc, aSrc+aCount] do not overlap. aCount is given in bytes. + */ + static void assertNoOverlap(const void* aDest, const void* aSrc, + size_t aCount) + { + DebugOnly byteDestPtr = static_cast(aDest); + DebugOnly byteSrcPtr = static_cast(aSrc); + MOZ_ASSERT((byteDestPtr <= byteSrcPtr && + byteDestPtr + aCount <= byteSrcPtr) || + (byteSrcPtr <= byteDestPtr && + byteSrcPtr + aCount <= byteDestPtr)); + } - template - static void assertAligned(T* ptr) - { - MOZ_ASSERT((uintptr_t(ptr) % sizeof(T)) == 0, "Unaligned pointer!"); + template + static void assertAligned(T* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % sizeof(T)) == 0, "Unaligned pointer!"); + } + +protected: + /** + * Return |aValue| converted from SourceEndian encoding to DestEndian + * encoding. + */ + template + static inline T maybeSwap(T aValue) + { + if (SourceEndian == DestEndian) { + return aValue; } + return Swapper::swap(aValue); + } - protected: - /** - * Return |value| converted from SourceEndian encoding to DestEndian - * encoding. - */ - template - static inline T maybeSwap(T value) - { - if (SourceEndian == DestEndian) - return value; + /** + * Convert |aCount| elements at |aPtr| from SourceEndian encoding to + * DestEndian encoding. + */ + template + static inline void maybeSwapInPlace(T* aPtr, size_t aCount) + { + assertAligned(aPtr); - return Swapper::swap(value); + if (SourceEndian == DestEndian) { + return; } + for (size_t i = 0; i < aCount; i++) { + aPtr[i] = Swapper::swap(aPtr[i]); + } + } - /** - * Convert |count| elements at |ptr| from SourceEndian encoding to - * DestEndian encoding. - */ - template - static inline void maybeSwapInPlace(T* ptr, size_t count) - { - assertAligned(ptr); + /** + * Write |aCount| elements to the unaligned address |aDest| in DestEndian + * format, using elements found at |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapTo(void* aDest, const T* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aSrc); - if (SourceEndian == DestEndian) - return; + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; + } - for (size_t i = 0; i < count; i++) - ptr[i] = Swapper::swap(ptr[i]); + uint8_t* byteDestPtr = static_cast(aDest); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + u.mVal = maybeSwap(aSrc[i]); + memcpy(byteDestPtr, u.mBuffer, sizeof(T)); + byteDestPtr += sizeof(T); } + } - /** - * Write |count| elements to the unaligned address |dest| in DestEndian - * format, using elements found at |src| in SourceEndian format. - */ - template - static void copyAndSwapTo(void* dest, const T* src, size_t count) - { - assertNoOverlap(dest, src, count * sizeof(T)); - assertAligned(src); - - if (SourceEndian == DestEndian) { - memcpy(dest, src, count * sizeof(T)); - return; - } - - uint8_t* byteDestPtr = static_cast(dest); - for (size_t i = 0; i < count; ++i) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - u.val = maybeSwap(src[i]); - memcpy(byteDestPtr, u.buffer, sizeof(T)); - byteDestPtr += sizeof(T); - } + /** + * Write |aCount| elements to |aDest| in DestEndian format, using elements + * found at the unaligned address |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapFrom(T* aDest, const void* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aDest); + + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; } - /** - * Write |count| elements to |dest| in DestEndian format, using elements - * found at the unaligned address |src| in SourceEndian format. - */ - template - static void copyAndSwapFrom(T* dest, const void* src, size_t count) - { - assertNoOverlap(dest, src, count * sizeof(T)); - assertAligned(dest); - - if (SourceEndian == DestEndian) { - memcpy(dest, src, count * sizeof(T)); - return; - } - - const uint8_t* byteSrcPtr = static_cast(src); - for (size_t i = 0; i < count; ++i) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - memcpy(u.buffer, byteSrcPtr, sizeof(T)); - dest[i] = maybeSwap(u.val); - byteSrcPtr += sizeof(T); - } + const uint8_t* byteSrcPtr = static_cast(aSrc); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, byteSrcPtr, sizeof(T)); + aDest[i] = maybeSwap(u.mVal); + byteSrcPtr += sizeof(T); } + } }; template class Endian : private EndianUtils { - protected: - /** Read a uint16_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint16_t readUint16(const void* p) { - return read(p); - } +protected: + /** Read a uint16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint16_t readUint16(const void* aPtr) + { + return read(aPtr); + } - /** Read a uint32_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint32_t readUint32(const void* p) { - return read(p); - } + /** Read a uint32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint32_t readUint32(const void* aPtr) + { + return read(aPtr); + } - /** Read a uint64_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint64_t readUint64(const void* p) { - return read(p); - } + /** Read a uint64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint64_t readUint64(const void* aPtr) + { + return read(aPtr); + } - /** Read an int16_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int16_t readInt16(const void* p) { - return read(p); - } + /** Read an int16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int16_t readInt16(const void* aPtr) + { + return read(aPtr); + } - /** Read an int32_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int32_t readInt32(const void* p) { - return read(p); - } + /** Read an int32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int32_t readInt32(const void* aPtr) + { + return read(aPtr); + } - /** Read an int64_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int64_t readInt64(const void* p) { - return read(p); - } + /** Read an int64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int64_t readInt64(const void* aPtr) + { + return read(aPtr); + } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint16(void* p, uint16_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint32(void* p, uint32_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint64(void* p, uint64_t val) { - write(p, val); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint16(void* aPtr, uint16_t aValue) + { + write(aPtr, aValue); + } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt16(void* p, int16_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt32(void* p, int32_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt64(void* p, int64_t val) { - write(p, val); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint32(void* aPtr, uint32_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T to little-endian format. - * - * This function is intended for cases where you have data in your - * native-endian format and you need it to appear in little-endian - * format for transmission. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToLittleEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to little-endian format if ThisEndian is Big. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapToLittleEndian(void* dest, const T* src, - size_t count) { - copyAndSwapTo(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapToLittleEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint64(void* aPtr, uint64_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T to big-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToBigEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to big-endian format if ThisEndian is Little. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapToBigEndian(void* dest, const T* src, size_t count) { - copyAndSwapTo(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapToBigEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt16(void* aPtr, int16_t aValue) + { + write(aPtr, aValue); + } - /* - * Synonyms for the big-endian functions, for better readability - * in network code. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToNetworkOrder(T value) { - return swapToBigEndian(value); - } - template - static void - copyAndSwapToNetworkOrder(void* dest, const T* src, size_t count) { - copyAndSwapToBigEndian(dest, src, count); - } - template - static void - swapToNetworkOrderInPlace(T* p, size_t count) { - swapToBigEndianInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt32(void* aPtr, int32_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T from little-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromLittleEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to little-endian format if ThisEndian is Big. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapFromLittleEndian(T* dest, const void* src, - size_t count) { - copyAndSwapFrom(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapFromLittleEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt64(void* aPtr, int64_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T from big-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromBigEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to big-endian format if ThisEndian is Little. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapFromBigEndian(T* dest, const void* src, - size_t count) { - copyAndSwapFrom(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapFromBigEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /* + * Converts a value of type T to little-endian format. + * + * This function is intended for cases where you have data in your + * native-endian format and you need it to appear in little-endian + * format for transmission. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToLittleEndian(T aValue) + { + return maybeSwap(aValue); + } - /* - * Synonyms for the big-endian functions, for better readability - * in network code. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromNetworkOrder(T value) { - return swapFromBigEndian(value); - } - template - static void copyAndSwapFromNetworkOrder(T* dest, const void* src, - size_t count) { - copyAndSwapFromBigEndian(dest, src, count); - } - template - static void swapFromNetworkOrderInPlace(T* p, size_t count) { - swapFromBigEndianInPlace(p, count); - } + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToLittleEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } - private: - /** - * Read a value of type T, encoded in endianness ThisEndian from |p|. - * Return that value encoded in native endianness. - */ - template - static T read(const void* p) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - memcpy(u.buffer, p, sizeof(T)); - return maybeSwap(u.val); - } + /* + * Likewise, but converts values in place. + */ + template + static void swapToLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } - /** - * Write a value of type T, in native endianness, to |p|, in ThisEndian - * endianness. - */ - template - static void write(void* p, T value) { - T tmp = maybeSwap(value); - memcpy(p, &tmp, sizeof(T)); - } + /* + * Converts a value of type T to big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToBigEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapToBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + + template + MOZ_WARN_UNUSED_RESULT static T swapToNetworkOrder(T aValue) + { + return swapToBigEndian(aValue); + } + + template + static void + copyAndSwapToNetworkOrder(void* aDest, const T* aSrc, size_t aCount) + { + copyAndSwapToBigEndian(aDest, aSrc, aCount); + } + + template + static void + swapToNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapToBigEndianInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from little-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromLittleEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromLittleEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromBigEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromNetworkOrder(T aValue) + { + return swapFromBigEndian(aValue); + } + + template + static void copyAndSwapFromNetworkOrder(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFromBigEndian(aDest, aSrc, aCount); + } + + template + static void swapFromNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapFromBigEndianInPlace(aPtr, aCount); + } + +private: + /** + * Read a value of type T, encoded in endianness ThisEndian from |aPtr|. + * Return that value encoded in native endianness. + */ + template + static T read(const void* aPtr) + { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, aPtr, sizeof(T)); + return maybeSwap(u.mVal); + } + + /** + * Write a value of type T, in native endianness, to |aPtr|, in ThisEndian + * endianness. + */ + template + static void write(void* aPtr, T aValue) + { + T tmp = maybeSwap(aValue); + memcpy(aPtr, &tmp, sizeof(T)); + } - Endian() MOZ_DELETE; - Endian(const Endian& other) MOZ_DELETE; - void operator=(const Endian& other) MOZ_DELETE; + Endian() MOZ_DELETE; + Endian(const Endian& aTther) MOZ_DELETE; + void operator=(const Endian& aOther) MOZ_DELETE; }; template class EndianReadWrite : public Endian { - private: - typedef Endian super; - - public: - using super::readUint16; - using super::readUint32; - using super::readUint64; - using super::readInt16; - using super::readInt32; - using super::readInt64; - using super::writeUint16; - using super::writeUint32; - using super::writeUint64; - using super::writeInt16; - using super::writeInt32; - using super::writeInt64; +private: + typedef Endian super; + +public: + using super::readUint16; + using super::readUint32; + using super::readUint64; + using super::readInt16; + using super::readInt32; + using super::readInt64; + using super::writeUint16; + using super::writeUint32; + using super::writeUint64; + using super::writeInt16; + using super::writeInt32; + using super::writeInt64; }; } /* namespace detail */ @@ -598,39 +653,39 @@ typedef BigEndian NetworkEndian; class NativeEndian MOZ_FINAL : public detail::Endian { - private: - typedef detail::Endian super; - - public: - /* - * These functions are intended for cases where you have data in your - * native-endian format and you need the data to appear in the appropriate - * endianness for transmission, serialization, etc. - */ - using super::swapToLittleEndian; - using super::copyAndSwapToLittleEndian; - using super::swapToLittleEndianInPlace; - using super::swapToBigEndian; - using super::copyAndSwapToBigEndian; - using super::swapToBigEndianInPlace; - using super::swapToNetworkOrder; - using super::copyAndSwapToNetworkOrder; - using super::swapToNetworkOrderInPlace; - - /* - * These functions are intended for cases where you have data in the - * given endianness (e.g. reading from disk or a file-format) and you - * need the data to appear in native-endian format for processing. - */ - using super::swapFromLittleEndian; - using super::copyAndSwapFromLittleEndian; - using super::swapFromLittleEndianInPlace; - using super::swapFromBigEndian; - using super::copyAndSwapFromBigEndian; - using super::swapFromBigEndianInPlace; - using super::swapFromNetworkOrder; - using super::copyAndSwapFromNetworkOrder; - using super::swapFromNetworkOrderInPlace; +private: + typedef detail::Endian super; + +public: + /* + * These functions are intended for cases where you have data in your + * native-endian format and you need the data to appear in the appropriate + * endianness for transmission, serialization, etc. + */ + using super::swapToLittleEndian; + using super::copyAndSwapToLittleEndian; + using super::swapToLittleEndianInPlace; + using super::swapToBigEndian; + using super::copyAndSwapToBigEndian; + using super::swapToBigEndianInPlace; + using super::swapToNetworkOrder; + using super::copyAndSwapToNetworkOrder; + using super::swapToNetworkOrderInPlace; + + /* + * These functions are intended for cases where you have data in the + * given endianness (e.g. reading from disk or a file-format) and you + * need the data to appear in native-endian format for processing. + */ + using super::swapFromLittleEndian; + using super::copyAndSwapFromLittleEndian; + using super::swapFromLittleEndianInPlace; + using super::swapFromBigEndian; + using super::copyAndSwapFromBigEndian; + using super::swapFromBigEndianInPlace; + using super::swapFromNetworkOrder; + using super::copyAndSwapFromNetworkOrder; + using super::swapFromNetworkOrderInPlace; }; #undef MOZ_NATIVE_ENDIANNESS diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/EnumSet.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/EnumSet.h index 95c5608cf4..8c78b2b442 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/EnumSet.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/EnumSet.h @@ -10,6 +10,7 @@ #define mozilla_EnumSet_h #include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" #include @@ -23,153 +24,181 @@ namespace mozilla { template class EnumSet { - public: - EnumSet() - : mBitField(0) - { } - - EnumSet(T aEnum) - : mBitField(aEnum) - { } - - EnumSet(T aEnum1, T aEnum2) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2)) - { } - - EnumSet(T aEnum1, T aEnum2, T aEnum3) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2) | - bitFor(aEnum3)) - { } - - EnumSet(T aEnum1, T aEnum2, T aEnum3, T aEnum4) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2) | - bitFor(aEnum3) | - bitFor(aEnum4)) - { } - - EnumSet(const EnumSet& aEnumSet) - : mBitField(aEnumSet.mBitField) - { } - - /** - * Add an element - */ - void operator+=(T aEnum) { - mBitField |= bitFor(aEnum); - } - - /** - * Add an element - */ - EnumSet operator+(T aEnum) const { - EnumSet result(*this); - result += aEnum; - return result; - } - - /** - * Union - */ - void operator+=(const EnumSet aEnumSet) { - mBitField |= aEnumSet.mBitField; - } - - /** - * Union - */ - EnumSet operator+(const EnumSet aEnumSet) const { - EnumSet result(*this); - result += aEnumSet; - return result; - } - - /** - * Remove an element - */ - void operator-=(T aEnum) { - mBitField &= ~(bitFor(aEnum)); - } - - /** - * Remove an element - */ - EnumSet operator-(T aEnum) const { - EnumSet result(*this); - result -= aEnum; - return result; - } - - /** - * Remove a set of elements - */ - void operator-=(const EnumSet aEnumSet) { - mBitField &= ~(aEnumSet.mBitField); - } - - /** - * Remove a set of elements - */ - EnumSet operator-(const EnumSet aEnumSet) const { - EnumSet result(*this); - result -= aEnumSet; - return result; - } - - /** - * Intersection - */ - void operator&=(const EnumSet aEnumSet) { - mBitField &= aEnumSet.mBitField; - } - - /** - * Intersection - */ - EnumSet operator&(const EnumSet aEnumSet) const { - EnumSet result(*this); - result &= aEnumSet; - return result; - } - - /** - * Equality - */ - - bool operator==(const EnumSet aEnumSet) const { - return mBitField == aEnumSet.mBitField; - } - - /** - * Test is an element is contained in the set - */ - bool contains(T aEnum) const { - return mBitField & bitFor(aEnum); - } - - /** - * Return the number of elements in the set - */ - - uint8_t size() { - uint8_t count = 0; - for (uint32_t bitField = mBitField; bitField; bitField >>= 1) { - if (bitField & 1) - count++; +public: + EnumSet() + : mBitField(0) + { } + + MOZ_IMPLICIT EnumSet(T aEnum) + : mBitField(bitFor(aEnum)) + { } + + EnumSet(T aEnum1, T aEnum2) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3, T aEnum4) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3) | + bitFor(aEnum4)) + { } + + EnumSet(const EnumSet& aEnumSet) + : mBitField(aEnumSet.mBitField) + { } + + /** + * Add an element + */ + void operator+=(T aEnum) + { + mBitField |= bitFor(aEnum); + } + + /** + * Add an element + */ + EnumSet operator+(T aEnum) const + { + EnumSet result(*this); + result += aEnum; + return result; + } + + /** + * Union + */ + void operator+=(const EnumSet aEnumSet) + { + mBitField |= aEnumSet.mBitField; + } + + /** + * Union + */ + EnumSet operator+(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result += aEnumSet; + return result; + } + + /** + * Remove an element + */ + void operator-=(T aEnum) + { + mBitField &= ~(bitFor(aEnum)); + } + + /** + * Remove an element + */ + EnumSet operator-(T aEnum) const + { + EnumSet result(*this); + result -= aEnum; + return result; + } + + /** + * Remove a set of elements + */ + void operator-=(const EnumSet aEnumSet) + { + mBitField &= ~(aEnumSet.mBitField); + } + + /** + * Remove a set of elements + */ + EnumSet operator-(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result -= aEnumSet; + return result; + } + + /** + * Intersection + */ + void operator&=(const EnumSet aEnumSet) + { + mBitField &= aEnumSet.mBitField; + } + + /** + * Intersection + */ + EnumSet operator&(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result &= aEnumSet; + return result; + } + + /** + * Equality + */ + bool operator==(const EnumSet aEnumSet) const + { + return mBitField == aEnumSet.mBitField; + } + + /** + * Test is an element is contained in the set. + */ + bool contains(T aEnum) const + { + return mBitField & bitFor(aEnum); + } + + /** + * Return the number of elements in the set. + */ + uint8_t size() + { + uint8_t count = 0; + for (uint32_t bitField = mBitField; bitField; bitField >>= 1) { + if (bitField & 1) { + count++; } - return count; } - - private: - static uint32_t bitFor(T aEnum) { - uint32_t bitNumber(aEnum); - MOZ_ASSERT(bitNumber < 32); - return 1U << bitNumber; - } - - uint32_t mBitField; + return count; + } + + bool isEmpty() const + { + return mBitField == 0; + } + + uint32_t serialize() const + { + return mBitField; + } + + void deserialize(uint32_t aValue) + { + mBitField = aValue; + } + +private: + static uint32_t bitFor(T aEnum) + { + uint32_t bitNumber = (uint32_t)aEnum; + MOZ_ASSERT(bitNumber < 32); + return 1U << bitNumber; + } + + uint32_t mBitField; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/EnumeratedArray.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/EnumeratedArray.h new file mode 100644 index 0000000000..7e8e89275f --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/EnumeratedArray.h @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* EnumeratedArray is like Array, but indexed by a typed enum. */ + +#ifndef mozilla_EnumeratedArray_h +#define mozilla_EnumeratedArray_h + +#include "mozilla/Array.h" +#include "mozilla/TypedEnum.h" + +namespace mozilla { + +/** + * EnumeratedArray is a fixed-size array container for use when an + * array is indexed by a specific enum class, as currently implemented + * by MOZ_BEGIN_ENUM_CLASS. + * + * This provides type safety by guarding at compile time against accidentally + * indexing such arrays with unrelated values. This also removes the need + * for manual casting when using a typed enum value to index arrays. + * + * Aside from the typing of indices, EnumeratedArray is similar to Array. + * + * Example: + * + * MOZ_BEGIN_ENUM_CLASS(AnimalSpecies) + * Cow, + * Sheep, + * Count + * MOZ_END_ENUM_CLASS(AnimalSpecies) + * + * EnumeratedArray headCount; + * + * headCount[AnimalSpecies::Cow] = 17; + * headCount[AnimalSpecies::Sheep] = 30; + * + */ +template +class EnumeratedArray +{ +public: + static const size_t kSize = size_t(SizeAsEnumValue); + +private: + Array mArray; + +public: + EnumeratedArray() {} + + explicit EnumeratedArray(const EnumeratedArray& aOther) + { + for (size_t i = 0; i < kSize; i++) { + mArray[i] = aOther.mArray[i]; + } + } + + ValueType& operator[](IndexType aIndex) + { + return mArray[size_t(aIndex)]; + } + + const ValueType& operator[](IndexType aIndex) const + { + return mArray[size_t(aIndex)]; + } +}; + +} // namespace mozilla + +#endif // mozilla_EnumeratedArray_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/FloatingPoint.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/FloatingPoint.h index 7d6b28b413..0ed567832b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/FloatingPoint.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/FloatingPoint.h @@ -12,6 +12,7 @@ #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/Casting.h" +#include "mozilla/MathAlgorithms.h" #include "mozilla/Types.h" #include @@ -33,211 +34,274 @@ namespace mozilla { * compiler bustage, particularly PGO-specific bustage. */ -/* - * These implementations all assume |double| is a 64-bit double format number - * type, compatible with the IEEE-754 standard. C/C++ don't require this to be - * the case. But we required this in implementations of these algorithms that - * preceded this header, so we shouldn't break anything if we continue doing so. - */ -static_assert(sizeof(double) == sizeof(uint64_t), "double must be 64 bits"); +struct FloatTypeTraits +{ + typedef uint32_t Bits; -const unsigned DoubleExponentBias = 1023; -const unsigned DoubleExponentShift = 52; + static const unsigned kExponentBias = 127; + static const unsigned kExponentShift = 23; -const uint64_t DoubleSignBit = 0x8000000000000000ULL; -const uint64_t DoubleExponentBits = 0x7ff0000000000000ULL; -const uint64_t DoubleSignificandBits = 0x000fffffffffffffULL; + static const Bits kSignBit = 0x80000000UL; + static const Bits kExponentBits = 0x7F800000UL; + static const Bits kSignificandBits = 0x007FFFFFUL; +}; + +struct DoubleTypeTraits +{ + typedef uint64_t Bits; -static_assert((DoubleSignBit & DoubleExponentBits) == 0, - "sign bit doesn't overlap exponent bits"); -static_assert((DoubleSignBit & DoubleSignificandBits) == 0, - "sign bit doesn't overlap significand bits"); -static_assert((DoubleExponentBits & DoubleSignificandBits) == 0, - "exponent bits don't overlap significand bits"); + static const unsigned kExponentBias = 1023; + static const unsigned kExponentShift = 52; -static_assert((DoubleSignBit | DoubleExponentBits | DoubleSignificandBits) == - ~uint64_t(0), - "all bits accounted for"); + static const Bits kSignBit = 0x8000000000000000ULL; + static const Bits kExponentBits = 0x7ff0000000000000ULL; + static const Bits kSignificandBits = 0x000fffffffffffffULL; +}; + +template struct SelectTrait; +template<> struct SelectTrait : public FloatTypeTraits {}; +template<> struct SelectTrait : public DoubleTypeTraits {}; /* - * Ditto for |float| that must be a 32-bit double format number type, compatible - * with the IEEE-754 standard. + * This struct contains details regarding the encoding of floating-point + * numbers that can be useful for direct bit manipulation. As of now, the + * template parameter has to be float or double. + * + * The nested typedef |Bits| is the unsigned integral type with the same size + * as T: uint32_t for float and uint64_t for double (static assertions + * double-check these assumptions). + * + * kExponentBias is the offset that is subtracted from the exponent when + * computing the value, i.e. one plus the opposite of the mininum possible + * exponent. + * kExponentShift is the shift that one needs to apply to retrieve the + * exponent component of the value. + * + * kSignBit contains a bits mask. Bit-and-ing with this mask will result in + * obtaining the sign bit. + * kExponentBits contains the mask needed for obtaining the exponent bits and + * kSignificandBits contains the mask needed for obtaining the significand + * bits. + * + * Full details of how floating point number formats are encoded are beyond + * the scope of this comment. For more information, see + * http://en.wikipedia.org/wiki/IEEE_floating_point + * http://en.wikipedia.org/wiki/Floating_point#IEEE_754:_floating_point_in_modern_computers */ -static_assert(sizeof(float) == sizeof(uint32_t), "float must be 32bits"); - -const unsigned FloatExponentBias = 127; -const unsigned FloatExponentShift = 23; +template +struct FloatingPoint : public SelectTrait +{ + typedef SelectTrait Base; + typedef typename Base::Bits Bits; -const uint32_t FloatSignBit = 0x80000000UL; -const uint32_t FloatExponentBits = 0x7F800000UL; -const uint32_t FloatSignificandBits = 0x007FFFFFUL; + static_assert((Base::kSignBit & Base::kExponentBits) == 0, + "sign bit shouldn't overlap exponent bits"); + static_assert((Base::kSignBit & Base::kSignificandBits) == 0, + "sign bit shouldn't overlap significand bits"); + static_assert((Base::kExponentBits & Base::kSignificandBits) == 0, + "exponent bits shouldn't overlap significand bits"); -static_assert((FloatSignBit & FloatExponentBits) == 0, - "sign bit doesn't overlap exponent bits"); -static_assert((FloatSignBit & FloatSignificandBits) == 0, - "sign bit doesn't overlap significand bits"); -static_assert((FloatExponentBits & FloatSignificandBits) == 0, - "exponent bits don't overlap significand bits"); + static_assert((Base::kSignBit | Base::kExponentBits | Base::kSignificandBits) == + ~Bits(0), + "all bits accounted for"); -static_assert((FloatSignBit | FloatExponentBits | FloatSignificandBits) == - ~uint32_t(0), - "all bits accounted for"); + /* + * These implementations assume float/double are 32/64-bit single/double + * format number types compatible with the IEEE-754 standard. C++ don't + * require this to be the case. But we required this in implementations of + * these algorithms that preceded this header, so we shouldn't break anything + * if we keep doing so. + */ + static_assert(sizeof(T) == sizeof(Bits), "Bits must be same size as T"); +}; /** Determines whether a double is NaN. */ +template static MOZ_ALWAYS_INLINE bool -IsNaN(double d) +IsNaN(T aValue) { /* - * A double is NaN if all exponent bits are 1 and the significand contains at - * least one non-zero bit. + * A float/double is NaN if all exponent bits are 1 and the significand + * contains at least one non-zero bit. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleExponentBits) == DoubleExponentBits && - (bits & DoubleSignificandBits) != 0; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) == Traits::kExponentBits && + (bits & Traits::kSignificandBits) != 0; } -/** Determines whether a double is +Infinity or -Infinity. */ +/** Determines whether a float/double is +Infinity or -Infinity. */ +template static MOZ_ALWAYS_INLINE bool -IsInfinite(double d) +IsInfinite(T aValue) { /* Infinities have all exponent bits set to 1 and an all-0 significand. */ - uint64_t bits = BitwiseCast(d); - return (bits & ~DoubleSignBit) == DoubleExponentBits; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & ~Traits::kSignBit) == Traits::kExponentBits; } -/** Determines whether a double is not NaN or infinite. */ +/** Determines whether a float/double is not NaN or infinite. */ +template static MOZ_ALWAYS_INLINE bool -IsFinite(double d) +IsFinite(T aValue) { /* - * NaN and Infinities are the only non-finite doubles, and both have all - * exponent bits set to 1. + * NaN and Infinities are the only non-finite floats/doubles, and both have + * all exponent bits set to 1. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleExponentBits) != DoubleExponentBits; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) != Traits::kExponentBits; } /** - * Determines whether a double is negative. It is an error to call this method - * on a double which is NaN. + * Determines whether a float/double is negative. It is an error to call this + * method on a float/double which is NaN. */ +template static MOZ_ALWAYS_INLINE bool -IsNegative(double d) +IsNegative(T aValue) { - MOZ_ASSERT(!IsNaN(d), "NaN does not have a sign"); + MOZ_ASSERT(!IsNaN(aValue), "NaN does not have a sign"); /* The sign bit is set if the double is negative. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleSignBit) != 0; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kSignBit) != 0; } -/** Determines whether a double represents -0. */ +/** Determines whether a float/double represents -0. */ +template static MOZ_ALWAYS_INLINE bool -IsNegativeZero(double d) +IsNegativeZero(T aValue) { - /* Only the sign bit is set if the double is -0. */ - uint64_t bits = BitwiseCast(d); - return bits == DoubleSignBit; + /* Only the sign bit is set if the value is -0. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return bits == Traits::kSignBit; } /** - * Returns the exponent portion of the double. + * Returns the exponent portion of the float/double. * * Zero is not special-cased, so ExponentComponent(0.0) is - * -int_fast16_t(DoubleExponentBias). + * -int_fast16_t(Traits::kExponentBias). */ +template static MOZ_ALWAYS_INLINE int_fast16_t -ExponentComponent(double d) +ExponentComponent(T aValue) { /* - * The exponent component of a double is an unsigned number, biased from its - * actual value. Subtract the bias to retrieve the actual exponent. + * The exponent component of a float/double is an unsigned number, biased + * from its actual value. Subtract the bias to retrieve the actual exponent. */ - uint64_t bits = BitwiseCast(d); - return int_fast16_t((bits & DoubleExponentBits) >> DoubleExponentShift) - - int_fast16_t(DoubleExponentBias); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return int_fast16_t((bits & Traits::kExponentBits) >> Traits::kExponentShift) - + int_fast16_t(Traits::kExponentBias); } /** Returns +Infinity. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T PositiveInfinity() { /* * Positive infinity has all exponent bits set, sign bit set to 0, and no * significand. */ - return BitwiseCast(DoubleExponentBits); + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kExponentBits); } /** Returns -Infinity. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T NegativeInfinity() { /* * Negative infinity has all exponent bits set, sign bit set to 1, and no * significand. */ - return BitwiseCast(DoubleSignBit | DoubleExponentBits); + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kSignBit | Traits::kExponentBits); } + /** Constructs a NaN value with the specified sign bit and significand bits. */ -static MOZ_ALWAYS_INLINE double -SpecificNaN(int signbit, uint64_t significand) +template +static MOZ_ALWAYS_INLINE T +SpecificNaN(int signbit, typename FloatingPoint::Bits significand) { + typedef FloatingPoint Traits; MOZ_ASSERT(signbit == 0 || signbit == 1); - MOZ_ASSERT((significand & ~DoubleSignificandBits) == 0); - MOZ_ASSERT(significand & DoubleSignificandBits); - - double d = BitwiseCast((signbit ? DoubleSignBit : 0) | - DoubleExponentBits | - significand); - MOZ_ASSERT(IsNaN(d)); - return d; + MOZ_ASSERT((significand & ~Traits::kSignificandBits) == 0); + MOZ_ASSERT(significand & Traits::kSignificandBits); + + T t = BitwiseCast((signbit ? Traits::kSignBit : 0) | + Traits::kExponentBits | + significand); + MOZ_ASSERT(IsNaN(t)); + return t; } -/** Computes the smallest non-zero positive double value. */ -static MOZ_ALWAYS_INLINE double -MinDoubleValue() +/** Computes the smallest non-zero positive float/double value. */ +template +static MOZ_ALWAYS_INLINE T +MinNumberValue() { - return BitwiseCast(uint64_t(1)); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + return BitwiseCast(Bits(1)); } /** - * If d is equal to some int32_t value, set *i to that value and return true; - * otherwise return false. + * If aValue is equal to some int32_t value, set *aInt32 to that value and + * return true; otherwise return false. * * Note that negative zero is "equal" to zero here. To test whether a value can - * be losslessly converted to int32_t and back, use DoubleIsInt32 instead. + * be losslessly converted to int32_t and back, use NumberIsInt32 instead. */ +template static MOZ_ALWAYS_INLINE bool -DoubleEqualsInt32(double d, int32_t* i) +NumberEqualsInt32(T aValue, int32_t* aInt32) { /* - * XXX Casting a double that doesn't truncate to int32_t, to int32_t, induces - * undefined behavior. We should definitely fix this (bug 744965), but as - * apparently it "works" in practice, it's not a pressing concern now. + * XXX Casting a floating-point value that doesn't truncate to int32_t, to + * int32_t, induces undefined behavior. We should definitely fix this + * (bug 744965), but as apparently it "works" in practice, it's not a + * pressing concern now. */ - return d == (*i = int32_t(d)); + return aValue == (*aInt32 = int32_t(aValue)); } /** * If d can be converted to int32_t and back to an identical double value, - * set *i to that value and return true; otherwise return false. + * set *aInt32 to that value and return true; otherwise return false. * - * The difference between this and DoubleEqualsInt32 is that this method returns + * The difference between this and NumberEqualsInt32 is that this method returns * false for negative zero. */ +template static MOZ_ALWAYS_INLINE bool -DoubleIsInt32(double d, int32_t* i) +NumberIsInt32(T aValue, int32_t* aInt32) { - return !IsNegativeZero(d) && DoubleEqualsInt32(d, i); + return !IsNegativeZero(aValue) && NumberEqualsInt32(aValue, aInt32); } /** * Computes a NaN value. Do not use this method if you depend upon a particular * NaN value being returned. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T UnspecifiedNaN() { /* @@ -246,7 +310,8 @@ UnspecifiedNaN() * this value can be represented in a 32-bit signed immediate field, allowing * it to be stored to memory in a single instruction). */ - return SpecificNaN(1, 0xfffffffffffffULL); + typedef FloatingPoint Traits; + return SpecificNaN(1, Traits::kSignificandBits); } /** @@ -254,40 +319,81 @@ UnspecifiedNaN() * any NaN value to any other NaN value. (The normal equality operators equate * -0 with +0, and they equate NaN to no other value.) */ +template static inline bool -DoublesAreIdentical(double d1, double d2) +NumbersAreIdentical(T aValue1, T aValue2) { - if (IsNaN(d1)) - return IsNaN(d2); - return BitwiseCast(d1) == BitwiseCast(d2); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + if (IsNaN(aValue1)) { + return IsNaN(aValue2); + } + return BitwiseCast(aValue1) == BitwiseCast(aValue2); } -/** Determines whether a float is NaN. */ +namespace detail { + +template +struct FuzzyEqualsEpsilon; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-5 that is exactly representable in a float. + static float value() { return 1.0f / (1 << 17); } +}; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-12 that is exactly representable in a double. + static double value() { return 1.0 / (1LL << 40); } +}; + +} // namespace detail + +/** + * Compare two floating point values for equality, modulo rounding error. That + * is, the two values are considered equal if they are both not NaN and if they + * are less than or equal to aEpsilon apart. The default value of aEpsilon is + * near 1e-5. + * + * For most scenarios you will want to use FuzzyEqualsMultiplicative instead, + * as it is more reasonable over the entire range of floating point numbers. + * This additive version should only be used if you know the range of the + * numbers you are dealing with is bounded and stays around the same order of + * magnitude. + */ +template static MOZ_ALWAYS_INLINE bool -IsFloatNaN(float f) +FuzzyEqualsAdditive(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) { - /* - * A float is NaN if all exponent bits are 1 and the significand contains at - * least one non-zero bit. - */ - uint32_t bits = BitwiseCast(f); - return (bits & FloatExponentBits) == FloatExponentBits && - (bits & FloatSignificandBits) != 0; + static_assert(IsFloatingPoint::value, "floating point type required"); + return Abs(aValue1 - aValue2) <= aEpsilon; } -/** Constructs a NaN value with the specified sign bit and significand bits. */ -static MOZ_ALWAYS_INLINE float -SpecificFloatNaN(int signbit, uint32_t significand) +/** + * Compare two floating point values for equality, allowing for rounding error + * relative to the magnitude of the values. That is, the two values are + * considered equal if they are both not NaN and they are less than or equal to + * some aEpsilon apart, where the aEpsilon is scaled by the smaller of the two + * argument values. + * + * In most cases you will want to use this rather than FuzzyEqualsAdditive, as + * this function effectively masks out differences in the bottom few bits of + * the floating point numbers being compared, regardless of what order of + * magnitude those numbers are at. + */ +template +static MOZ_ALWAYS_INLINE bool +FuzzyEqualsMultiplicative(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) { - MOZ_ASSERT(signbit == 0 || signbit == 1); - MOZ_ASSERT((significand & ~FloatSignificandBits) == 0); - MOZ_ASSERT(significand & FloatSignificandBits); - - float f = BitwiseCast((signbit ? FloatSignBit : 0) | - FloatExponentBits | - significand); - MOZ_ASSERT(IsFloatNaN(f)); - return f; + static_assert(IsFloatingPoint::value, "floating point type required"); + // can't use std::min because of bug 965340 + T smaller = Abs(aValue1) < Abs(aValue2) ? Abs(aValue1) : Abs(aValue2); + return Abs(aValue1 - aValue2) <= aEpsilon * smaller; } /** @@ -300,7 +406,7 @@ SpecificFloatNaN(int signbit, uint32_t significand) */ MOZ_WARN_UNUSED_RESULT extern MFBT_API bool -IsFloat32Representable(double x); +IsFloat32Representable(double aFloat32); } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/GuardObjects.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/GuardObjects.h index aeae7dcbc0..2cd950f314 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/GuardObjects.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/GuardObjects.h @@ -68,48 +68,49 @@ namespace detail { * For more details, and examples of using these macros, see * https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla */ -class MOZ_EXPORT GuardObjectNotifier +class GuardObjectNotifier { - private: - bool* statementDone; +private: + bool* mStatementDone; - public: - GuardObjectNotifier() : statementDone(nullptr) { } +public: + GuardObjectNotifier() : mStatementDone(nullptr) { } - ~GuardObjectNotifier() { - *statementDone = true; - } + ~GuardObjectNotifier() { *mStatementDone = true; } - void setStatementDone(bool* statementIsDone) { - statementDone = statementIsDone; - } + void setStatementDone(bool* aStatementIsDone) + { + mStatementDone = aStatementIsDone; + } }; -class MOZ_EXPORT GuardObjectNotificationReceiver +class GuardObjectNotificationReceiver { - private: - bool statementDone; - - public: - GuardObjectNotificationReceiver() : statementDone(false) { } - - ~GuardObjectNotificationReceiver() { - /* - * Assert that the guard object was not used as a temporary. (Note that - * this assert might also fire if init is not called because the guard - * object's implementation is not using the above macros correctly.) - */ - MOZ_ASSERT(statementDone); - } - - void init(const GuardObjectNotifier& constNotifier) { - /* - * constNotifier is passed as a const reference so that we can pass a - * temporary, but we really intend it as non-const. - */ - GuardObjectNotifier& notifier = const_cast(constNotifier); - notifier.setStatementDone(&statementDone); - } +private: + bool mStatementDone; + +public: + GuardObjectNotificationReceiver() : mStatementDone(false) { } + + ~GuardObjectNotificationReceiver() { + /* + * Assert that the guard object was not used as a temporary. (Note that + * this assert might also fire if init is not called because the guard + * object's implementation is not using the above macros correctly.) + */ + MOZ_ASSERT(mStatementDone); + } + + void init(const GuardObjectNotifier& aConstNotifier) + { + /* + * aConstNotifier is passed as a const reference so that we can pass a + * temporary, but we really intend it as non-const. + */ + GuardObjectNotifier& notifier = + const_cast(aConstNotifier); + notifier.setStatementDone(&mStatementDone); + } }; } /* namespace detail */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/HashFunctions.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/HashFunctions.h index b228955ce5..8b2c172bd1 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/HashFunctions.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/HashFunctions.h @@ -27,16 +27,17 @@ * * class ComplexObject * { - * char* str; - * uint32_t uint1, uint2; - * void (*callbackFn)(); + * char* mStr; + * uint32_t mUint1, mUint2; + * void (*mCallbackFn)(); * - * public: - * uint32_t hash() { - * uint32_t hash = HashString(str); - * hash = AddToHash(hash, uint1, uint2); - * return AddToHash(hash, callbackFn); - * } + * public: + * uint32_t hash() + * { + * uint32_t hash = HashString(mStr); + * hash = AddToHash(hash, mUint1, mUint2); + * return AddToHash(hash, mCallbackFn); + * } * }; * * If you want to hash an nsAString or nsACString, use the HashString functions @@ -59,19 +60,19 @@ namespace mozilla { /** * The golden ratio as a 32-bit fixed-point value. */ -static const uint32_t GoldenRatioU32 = 0x9E3779B9U; +static const uint32_t kGoldenRatioU32 = 0x9E3779B9U; inline uint32_t -RotateBitsLeft32(uint32_t value, uint8_t bits) +RotateBitsLeft32(uint32_t aValue, uint8_t aBits) { - MOZ_ASSERT(bits < 32); - return (value << bits) | (value >> (32 - bits)); + MOZ_ASSERT(aBits < 32); + return (aValue << aBits) | (aValue >> (32 - aBits)); } namespace detail { inline uint32_t -AddU32ToHash(uint32_t hash, uint32_t value) +AddU32ToHash(uint32_t aHash, uint32_t aValue) { /* * This is the meat of all our hash routines. This hash function is not @@ -91,12 +92,12 @@ AddU32ToHash(uint32_t hash, uint32_t value) * preferable so our hash explores the whole universe of possible rotations. * * Finally, we multiply by the golden ratio *after* xor'ing, not before. - * Otherwise, if |hash| is 0 (as it often is for the beginning of a message), - * the expression + * Otherwise, if |aHash| is 0 (as it often is for the beginning of a + * message), the expression * - * (GoldenRatioU32 * RotateBitsLeft(hash, 5)) |xor| value + * (kGoldenRatioU32 * RotateBitsLeft(aHash, 5)) |xor| aValue * - * evaluates to |value|. + * evaluates to |aValue|. * * (Number-theoretic aside: Because any odd number |m| is relatively prime to * our modulus (2^32), the list @@ -112,7 +113,7 @@ AddU32ToHash(uint32_t hash, uint32_t value) * multiplicative effect. Our golden ratio constant has order 2^29, which is * more than enough for our purposes.) */ - return GoldenRatioU32 * (RotateBitsLeft32(hash, 5) ^ value); + return kGoldenRatioU32 * (RotateBitsLeft32(aHash, 5) ^ aValue); } /** @@ -120,29 +121,29 @@ AddU32ToHash(uint32_t hash, uint32_t value) */ template inline uint32_t -AddUintptrToHash(uint32_t hash, uintptr_t value); +AddUintptrToHash(uint32_t aHash, uintptr_t aValue); template<> inline uint32_t -AddUintptrToHash<4>(uint32_t hash, uintptr_t value) +AddUintptrToHash<4>(uint32_t aHash, uintptr_t aValue) { - return AddU32ToHash(hash, static_cast(value)); + return AddU32ToHash(aHash, static_cast(aValue)); } template<> inline uint32_t -AddUintptrToHash<8>(uint32_t hash, uintptr_t value) +AddUintptrToHash<8>(uint32_t aHash, uintptr_t aValue) { /* * The static cast to uint64_t below is necessary because this function * sometimes gets compiled on 32-bit platforms (yes, even though it's a * template and we never call this particular override in a 32-bit build). If - * we do value >> 32 on a 32-bit machine, we're shifting a 32-bit uintptr_t + * we do aValue >> 32 on a 32-bit machine, we're shifting a 32-bit uintptr_t * right 32 bits, and the compiler throws an error. */ - uint32_t v1 = static_cast(value); - uint32_t v2 = static_cast(static_cast(value) >> 32); - return AddU32ToHash(AddU32ToHash(hash, v1), v2); + uint32_t v1 = static_cast(aValue); + uint32_t v2 = static_cast(static_cast(aValue) >> 32); + return AddU32ToHash(AddU32ToHash(aHash, v1), v2); } } /* namespace detail */ @@ -155,71 +156,63 @@ AddUintptrToHash<8>(uint32_t hash, uintptr_t value) * convert to uint32_t, data pointers, and function pointers. */ template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, A a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A aA) { /* * Try to convert |A| to uint32_t implicitly. If this works, great. If not, * we'll error out. */ - return detail::AddU32ToHash(hash, a); + return detail::AddU32ToHash(aHash, aA); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, A* a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A* aA) { /* * You might think this function should just take a void*. But then we'd only * catch data pointers and couldn't handle function pointers. */ - static_assert(sizeof(a) == sizeof(uintptr_t), - "Strange pointer!"); + static_assert(sizeof(aA) == sizeof(uintptr_t), "Strange pointer!"); - return detail::AddUintptrToHash(hash, uintptr_t(a)); + return detail::AddUintptrToHash(aHash, uintptr_t(aA)); } template<> -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, uintptr_t a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, uintptr_t aA) { - return detail::AddUintptrToHash(hash, a); + return detail::AddUintptrToHash(aHash, aA); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB) { - return AddToHash(AddToHash(hash, a), b); + return AddToHash(AddToHash(aHash, aA), aB); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC) { - return AddToHash(AddToHash(hash, a, b), c); + return AddToHash(AddToHash(aHash, aA, aB), aC); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c, D d) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD) { - return AddToHash(AddToHash(hash, a, b, c), d); + return AddToHash(AddToHash(aHash, aA, aB, aC), aD); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c, D d, E e) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD, E aE) { - return AddToHash(AddToHash(hash, a, b, c, d), e); + return AddToHash(AddToHash(aHash, aA, aB, aC, aD), aE); } /** @@ -230,64 +223,61 @@ AddToHash(uint32_t hash, A a, B b, C c, D d, E e) * that x has already been hashed. */ template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA) { - return AddToHash(0, a); + return AddToHash(0, aA); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB) { - return AddToHash(0, a, b); + return AddToHash(0, aA, aB); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC) { - return AddToHash(0, a, b, c); + return AddToHash(0, aA, aB, aC); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c, D d) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD) { - return AddToHash(0, a, b, c, d); + return AddToHash(0, aA, aB, aC, aD); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c, D d, E e) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD, E aE) { - return AddToHash(0, a, b, c, d, e); + return AddToHash(0, aA, aB, aC, aD, aE); } namespace detail { template uint32_t -HashUntilZero(const T* str) +HashUntilZero(const T* aStr) { uint32_t hash = 0; - for (T c; (c = *str); str++) + for (T c; (c = *aStr); aStr++) { hash = AddToHash(hash, c); + } return hash; } template uint32_t -HashKnownLength(const T* str, size_t length) +HashKnownLength(const T* aStr, size_t aLength) { uint32_t hash = 0; - for (size_t i = 0; i < length; i++) - hash = AddToHash(hash, str[i]); + for (size_t i = 0; i < aLength; i++) { + hash = AddToHash(hash, aStr[i]); + } return hash; } @@ -299,67 +289,66 @@ HashKnownLength(const T* str, size_t length) * If you have the string's length, you might as well call the overload which * includes the length. It may be marginally faster. */ -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } MOZ_WARN_UNUSED_RESULT inline uint32_t -HashString(const uint16_t* str) +HashString(const unsigned char* aStr, size_t aLength) { - return detail::HashUntilZero(str); + return detail::HashKnownLength(aStr, aLength); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const uint16_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr) { - return detail::HashKnownLength(str, length); + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); } #ifdef MOZ_CHAR16_IS_NOT_WCHAR -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char16_t* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char16_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } #endif /* - * On Windows, wchar_t (PRUnichar) is not the same as uint16_t, even though it's + * On Windows, wchar_t (char16_t) is not the same as uint16_t, even though it's * the same width! */ #ifdef WIN32 -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const wchar_t* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const wchar_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } #endif @@ -369,9 +358,8 @@ HashString(const wchar_t* str, size_t length) * This hash walks word-by-word, rather than byte-by-byte, so you won't get the * same result out of HashBytes as you would out of HashString. */ -MOZ_WARN_UNUSED_RESULT -extern MFBT_API uint32_t -HashBytes(const void* bytes, size_t length); +MOZ_WARN_UNUSED_RESULT extern MFBT_API uint32_t +HashBytes(const void* bytes, size_t aLength); } /* namespace mozilla */ #endif /* __cplusplus */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/IntegerPrintfMacros.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/IntegerPrintfMacros.h index 1ae60d618e..ff2415a86f 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/IntegerPrintfMacros.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/IntegerPrintfMacros.h @@ -1,7 +1,8 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* Implements the C99 interface, minus the SCN* format macros. */ @@ -37,4 +38,25 @@ # include #endif +/* + * Fix up Android's broken [u]intptr_t inttype macros. Android's PRI*PTR + * macros are defined as "ld", but sizeof(long) is 8 and sizeof(intptr_t) + * is 4 on 32-bit Android. TestTypeTraits.cpp asserts that these new macro + * definitions match the actual type sizes seen at compile time. + */ +#if defined(ANDROID) && !defined(__LP64__) +# undef PRIdPTR /* intptr_t */ +# define PRIdPTR "d" /* intptr_t */ +# undef PRIiPTR /* intptr_t */ +# define PRIiPTR "i" /* intptr_t */ +# undef PRIoPTR /* uintptr_t */ +# define PRIoPTR "o" /* uintptr_t */ +# undef PRIuPTR /* uintptr_t */ +# define PRIuPTR "u" /* uintptr_t */ +# undef PRIxPTR /* uintptr_t */ +# define PRIxPTR "x" /* uintptr_t */ +# undef PRIXPTR /* uintptr_t */ +# define PRIXPTR "X" /* uintptr_t */ +#endif + #endif /* mozilla_IntegerPrintfMacros_h_ */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/IntegerTypeTraits.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/IntegerTypeTraits.h new file mode 100644 index 0000000000..9414451f91 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/IntegerTypeTraits.h @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Helpers to manipulate integer types that don't fit in TypeTraits.h */ + +#ifndef mozilla_IntegerTypeTraits_h +#define mozilla_IntegerTypeTraits_h + +#include "mozilla/TypeTraits.h" +#include + +namespace mozilla { + +namespace detail { + +/** + * StdintTypeForSizeAndSignedness returns the stdint integer type + * of given size (can be 1, 2, 4 or 8) and given signedness + * (false means unsigned, true means signed). + */ +template +struct StdintTypeForSizeAndSignedness; + +template<> +struct StdintTypeForSizeAndSignedness<1, true> +{ + typedef int8_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<1, false> +{ + typedef uint8_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<2, true> +{ + typedef int16_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<2, false> +{ + typedef uint16_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<4, true> +{ + typedef int32_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<4, false> +{ + typedef uint32_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<8, true> +{ + typedef int64_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<8, false> +{ + typedef uint64_t Type; +}; + +} // namespace detail + +template +struct UnsignedStdintTypeForSize + : detail::StdintTypeForSizeAndSignedness +{}; + +template +struct PositionOfSignBit +{ + static_assert(IsIntegral::value, + "PositionOfSignBit is only for integral types"); + // 8 here should be CHAR_BIT from limits.h, but the world has moved on. + static const size_t value = 8 * sizeof(IntegerType) - 1; +}; + +/** + * MinValue returns the minimum value of the given integer type as a + * compile-time constant, which std::numeric_limits::min() + * cannot do in c++98. + */ +template +struct MinValue +{ +private: + static_assert(IsIntegral::value, + "MinValue is only for integral types"); + + typedef typename MakeUnsigned::Type UnsignedIntegerType; + static const size_t PosOfSignBit = PositionOfSignBit::value; + +public: + // Bitwise ops may return a larger type, that's why we cast explicitly. + // In C++, left bit shifts on signed values is undefined by the standard + // unless the shifted value is representable. + // Notice that signed-to-unsigned conversions are always well-defined in + // the standard as the value congruent to 2**n, as expected. By contrast, + // unsigned-to-signed is only well-defined if the value is representable. + static const IntegerType value = + IsSigned::value + ? IntegerType(UnsignedIntegerType(1) << PosOfSignBit) + : IntegerType(0); +}; + +/** + * MaxValue returns the maximum value of the given integer type as a + * compile-time constant, which std::numeric_limits::max() + * cannot do in c++98. + */ +template +struct MaxValue +{ + static_assert(IsIntegral::value, + "MaxValue is only for integral types"); + + // Tricksy, but covered by the CheckedInt unit test. + // Relies on the type of MinValue::value + // being IntegerType. + static const IntegerType value = ~MinValue::value; +}; + +} // namespace mozilla + +#endif // mozilla_IntegerTypeTraits_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/LinkedList.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/LinkedList.h index 3aee7cde45..693c019f92 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/LinkedList.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/LinkedList.h @@ -23,32 +23,36 @@ * * class Observer : public LinkedListElement * { - * public: - * void observe(char* topic) { ... } + * public: + * void observe(char* aTopic) { ... } * }; * * class ObserverContainer * { - * private: - * LinkedList list; + * private: + * LinkedList list; * - * public: - * void addObserver(Observer* observer) { - * // Will assert if |observer| is part of another list. - * list.insertBack(observer); - * } + * public: + * void addObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is part of another list. + * list.insertBack(aObserver); + * } * - * void removeObserver(Observer* observer) { - * // Will assert if |observer| is not part of some list. - * observer.remove(); - * // Or, will assert if |observer| is not part of |list| specifically. - * // observer.removeFrom(list); - * } + * void removeObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is not part of some list. + * aObserver.remove(); + * // Or, will assert if |aObserver| is not part of |list| specifically. + * // aObserver.removeFrom(list); + * } * - * void notifyObservers(char* topic) { - * for (Observer* o = list.getFirst(); o != nullptr; o = o->getNext()) - * o->observe(topic); + * void notifyObservers(char* aTopic) + * { + * for (Observer* o = list.getFirst(); o != nullptr; o = o->getNext()) { + * o->observe(aTopic); * } + * } * }; * */ @@ -72,411 +76,407 @@ class LinkedList; template class LinkedListElement { - /* - * It's convenient that we return nullptr when getNext() or getPrevious() - * hits the end of the list, but doing so costs an extra word of storage in - * each linked list node (to keep track of whether |this| is the sentinel - * node) and a branch on this value in getNext/getPrevious. - * - * We could get rid of the extra word of storage by shoving the "is - * sentinel" bit into one of the pointers, although this would, of course, - * have performance implications of its own. - * - * But the goal here isn't to win an award for the fastest or slimmest - * linked list; rather, we want a *convenient* linked list. So we won't - * waste time guessing which micro-optimization strategy is best. - * - * - * Speaking of unnecessary work, it's worth addressing here why we wrote - * mozilla::LinkedList in the first place, instead of using stl::list. - * - * The key difference between mozilla::LinkedList and stl::list is that - * mozilla::LinkedList stores the prev/next pointers in the object itself, - * while stl::list stores the prev/next pointers in a list element which - * itself points to the object being stored. - * - * mozilla::LinkedList's approach makes it harder to store an object in more - * than one list. But the upside is that you can call next() / prev() / - * remove() directly on the object. With stl::list, you'd need to store a - * pointer to its iterator in the object in order to accomplish this. Not - * only would this waste space, but you'd have to remember to update that - * pointer every time you added or removed the object from a list. - * - * In-place, constant-time removal is a killer feature of doubly-linked - * lists, and supporting this painlessly was a key design criterion. - */ - - private: - LinkedListElement* next; - LinkedListElement* prev; - const bool isSentinel; - - public: - LinkedListElement() - : next(MOZ_THIS_IN_INITIALIZER_LIST()), - prev(MOZ_THIS_IN_INITIALIZER_LIST()), - isSentinel(false) - { } - - LinkedListElement(LinkedListElement&& other) - : isSentinel(other.isSentinel) - { - if (!other.isInList()) { - next = this; - prev = this; - return; - } - - MOZ_ASSERT(other.next->prev == &other); - MOZ_ASSERT(other.prev->next == &other); - - /* - * Initialize |this| with |other|'s prev/next pointers, and adjust those - * element to point to this one. - */ - next = other.next; - prev = other.prev; - - next->prev = this; - prev->next = this; - - /* - * Adjust |other| so it doesn't think it's in a list. This makes it - * safely destructable. - */ - other.next = &other; - other.prev = &other; - } - - ~LinkedListElement() { - if (!isSentinel && isInList()) - remove(); - } - - /* - * Get the next element in the list, or nullptr if this is the last element - * in the list. - */ - T* getNext() { - return next->asT(); - } - const T* getNext() const { - return next->asT(); + /* + * It's convenient that we return nullptr when getNext() or getPrevious() + * hits the end of the list, but doing so costs an extra word of storage in + * each linked list node (to keep track of whether |this| is the sentinel + * node) and a branch on this value in getNext/getPrevious. + * + * We could get rid of the extra word of storage by shoving the "is + * sentinel" bit into one of the pointers, although this would, of course, + * have performance implications of its own. + * + * But the goal here isn't to win an award for the fastest or slimmest + * linked list; rather, we want a *convenient* linked list. So we won't + * waste time guessing which micro-optimization strategy is best. + * + * + * Speaking of unnecessary work, it's worth addressing here why we wrote + * mozilla::LinkedList in the first place, instead of using stl::list. + * + * The key difference between mozilla::LinkedList and stl::list is that + * mozilla::LinkedList stores the mPrev/mNext pointers in the object itself, + * while stl::list stores the mPrev/mNext pointers in a list element which + * itself points to the object being stored. + * + * mozilla::LinkedList's approach makes it harder to store an object in more + * than one list. But the upside is that you can call next() / prev() / + * remove() directly on the object. With stl::list, you'd need to store a + * pointer to its iterator in the object in order to accomplish this. Not + * only would this waste space, but you'd have to remember to update that + * pointer every time you added or removed the object from a list. + * + * In-place, constant-time removal is a killer feature of doubly-linked + * lists, and supporting this painlessly was a key design criterion. + */ + +private: + LinkedListElement* mNext; + LinkedListElement* mPrev; + const bool mIsSentinel; + +public: + LinkedListElement() + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(false) + { } + + LinkedListElement(LinkedListElement&& other) + : mIsSentinel(other.mIsSentinel) + { + if (!other.isInList()) { + mNext = this; + mPrev = this; + return; } - /* - * Get the previous element in the list, or nullptr if this is the first - * element in the list. - */ - T* getPrevious() { - return prev->asT(); - } - const T* getPrevious() const { - return prev->asT(); - } + MOZ_ASSERT(other.mNext->mPrev == &other); + MOZ_ASSERT(other.mPrev->mNext == &other); /* - * Insert elem after this element in the list. |this| must be part of a - * linked list when you call setNext(); otherwise, this method will assert. + * Initialize |this| with |other|'s mPrev/mNext pointers, and adjust those + * element to point to this one. */ - void setNext(T* elem) { - MOZ_ASSERT(isInList()); - setNextUnsafe(elem); - } + mNext = other.mNext; + mPrev = other.mPrev; - /* - * Insert elem before this element in the list. |this| must be part of a - * linked list when you call setPrevious(); otherwise, this method will - * assert. - */ - void setPrevious(T* elem) { - MOZ_ASSERT(isInList()); - setPreviousUnsafe(elem); - } + mNext->mPrev = this; + mPrev->mNext = this; /* - * Remove this element from the list which contains it. If this element is - * not currently part of a linked list, this method asserts. + * Adjust |other| so it doesn't think it's in a list. This makes it + * safely destructable. */ - void remove() { - MOZ_ASSERT(isInList()); - - prev->next = next; - next->prev = prev; - next = this; - prev = this; - } + other.mNext = &other; + other.mPrev = &other; + } - /* - * Identical to remove(), but also asserts in debug builds that this element - * is in list. - */ - void removeFrom(const LinkedList& list) { - list.assertContains(asT()); + ~LinkedListElement() + { + if (!mIsSentinel && isInList()) { remove(); } - - /* - * Return true if |this| part is of a linked list, and false otherwise. - */ - bool isInList() const { - MOZ_ASSERT((next == this) == (prev == this)); - return next != this; - } - - private: - friend class LinkedList; - - enum NodeKind { - NODE_KIND_NORMAL, - NODE_KIND_SENTINEL - }; - - LinkedListElement(NodeKind nodeKind) - : next(MOZ_THIS_IN_INITIALIZER_LIST()), - prev(MOZ_THIS_IN_INITIALIZER_LIST()), - isSentinel(nodeKind == NODE_KIND_SENTINEL) - { } - - /* - * Return |this| cast to T* if we're a normal node, or return nullptr if - * we're a sentinel node. - */ - T* asT() { - if (isSentinel) - return nullptr; - - return static_cast(this); - } - const T* asT() const { - if (isSentinel) - return nullptr; - - return static_cast(this); - } - - /* - * Insert elem after this element, but don't check that this element is in - * the list. This is called by LinkedList::insertFront(). - */ - void setNextUnsafe(T* elem) { - LinkedListElement *listElem = static_cast(elem); - MOZ_ASSERT(!listElem->isInList()); - - listElem->next = this->next; - listElem->prev = this; - this->next->prev = listElem; - this->next = listElem; - } - - /* - * Insert elem before this element, but don't check that this element is in - * the list. This is called by LinkedList::insertBack(). - */ - void setPreviousUnsafe(T* elem) { - LinkedListElement* listElem = static_cast*>(elem); - MOZ_ASSERT(!listElem->isInList()); - - listElem->next = this; - listElem->prev = this->prev; - this->prev->next = listElem; - this->prev = listElem; - } - - private: - LinkedListElement& operator=(const LinkedListElement& other) MOZ_DELETE; - LinkedListElement(const LinkedListElement& other) MOZ_DELETE; + } + + /* + * Get the next element in the list, or nullptr if this is the last element + * in the list. + */ + T* getNext() { return mNext->asT(); } + const T* getNext() const { return mNext->asT(); } + + /* + * Get the previous element in the list, or nullptr if this is the first + * element in the list. + */ + T* getPrevious() { return mPrev->asT(); } + const T* getPrevious() const { return mPrev->asT(); } + + /* + * Insert aElem after this element in the list. |this| must be part of a + * linked list when you call setNext(); otherwise, this method will assert. + */ + void setNext(T* aElem) + { + MOZ_ASSERT(isInList()); + setNextUnsafe(aElem); + } + + /* + * Insert aElem before this element in the list. |this| must be part of a + * linked list when you call setPrevious(); otherwise, this method will + * assert. + */ + void setPrevious(T* aElem) + { + MOZ_ASSERT(isInList()); + setPreviousUnsafe(aElem); + } + + /* + * Remove this element from the list which contains it. If this element is + * not currently part of a linked list, this method asserts. + */ + void remove() + { + MOZ_ASSERT(isInList()); + + mPrev->mNext = mNext; + mNext->mPrev = mPrev; + mNext = this; + mPrev = this; + } + + /* + * Identical to remove(), but also asserts in debug builds that this element + * is in aList. + */ + void removeFrom(const LinkedList& aList) + { + aList.assertContains(asT()); + remove(); + } + + /* + * Return true if |this| part is of a linked list, and false otherwise. + */ + bool isInList() const + { + MOZ_ASSERT((mNext == this) == (mPrev == this)); + return mNext != this; + } + +private: + friend class LinkedList; + + enum NodeKind { + NODE_KIND_NORMAL, + NODE_KIND_SENTINEL + }; + + explicit LinkedListElement(NodeKind nodeKind) + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(nodeKind == NODE_KIND_SENTINEL) + { } + + /* + * Return |this| cast to T* if we're a normal node, or return nullptr if + * we're a sentinel node. + */ + T* asT() + { + return mIsSentinel ? nullptr : static_cast(this); + } + const T* asT() const + { + return mIsSentinel ? nullptr : static_cast(this); + } + + /* + * Insert aElem after this element, but don't check that this element is in + * the list. This is called by LinkedList::insertFront(). + */ + void setNextUnsafe(T* aElem) + { + LinkedListElement *listElem = static_cast(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this->mNext; + listElem->mPrev = this; + this->mNext->mPrev = listElem; + this->mNext = listElem; + } + + /* + * Insert aElem before this element, but don't check that this element is in + * the list. This is called by LinkedList::insertBack(). + */ + void setPreviousUnsafe(T* aElem) + { + LinkedListElement* listElem = static_cast*>(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this; + listElem->mPrev = this->mPrev; + this->mPrev->mNext = listElem; + this->mPrev = listElem; + } + +private: + LinkedListElement& operator=(const LinkedListElement& aOther) MOZ_DELETE; + LinkedListElement(const LinkedListElement& aOther) MOZ_DELETE; }; template class LinkedList { - private: - LinkedListElement sentinel; - - public: - LinkedList() : sentinel(LinkedListElement::NODE_KIND_SENTINEL) { } - - LinkedList(LinkedList&& other) - : sentinel(mozilla::Move(other.sentinel)) - { } - - ~LinkedList() { - MOZ_ASSERT(isEmpty()); - } - - /* - * Add elem to the front of the list. - */ - void insertFront(T* elem) { - /* Bypass setNext()'s this->isInList() assertion. */ - sentinel.setNextUnsafe(elem); - } - - /* - * Add elem to the back of the list. - */ - void insertBack(T* elem) { - sentinel.setPreviousUnsafe(elem); - } - - /* - * Get the first element of the list, or nullptr if the list is empty. - */ - T* getFirst() { - return sentinel.getNext(); - } - const T* getFirst() const { - return sentinel.getNext(); +private: + LinkedListElement sentinel; + +public: + LinkedList() : sentinel(LinkedListElement::NODE_KIND_SENTINEL) { } + + LinkedList(LinkedList&& aOther) + : sentinel(mozilla::Move(aOther.sentinel)) + { } + + ~LinkedList() { MOZ_ASSERT(isEmpty()); } + + /* + * Add aElem to the front of the list. + */ + void insertFront(T* aElem) + { + /* Bypass setNext()'s this->isInList() assertion. */ + sentinel.setNextUnsafe(aElem); + } + + /* + * Add aElem to the back of the list. + */ + void insertBack(T* aElem) + { + sentinel.setPreviousUnsafe(aElem); + } + + /* + * Get the first element of the list, or nullptr if the list is empty. + */ + T* getFirst() { return sentinel.getNext(); } + const T* getFirst() const { return sentinel.getNext(); } + + /* + * Get the last element of the list, or nullptr if the list is empty. + */ + T* getLast() { return sentinel.getPrevious(); } + const T* getLast() const { return sentinel.getPrevious(); } + + /* + * Get and remove the first element of the list. If the list is empty, + * return nullptr. + */ + T* popFirst() + { + T* ret = sentinel.getNext(); + if (ret) { + static_cast*>(ret)->remove(); } - - /* - * Get the last element of the list, or nullptr if the list is empty. - */ - T* getLast() { - return sentinel.getPrevious(); - } - const T* getLast() const { - return sentinel.getPrevious(); - } - - /* - * Get and remove the first element of the list. If the list is empty, - * return nullptr. - */ - T* popFirst() { - T* ret = sentinel.getNext(); - if (ret) - static_cast*>(ret)->remove(); - return ret; + return ret; + } + + /* + * Get and remove the last element of the list. If the list is empty, + * return nullptr. + */ + T* popLast() + { + T* ret = sentinel.getPrevious(); + if (ret) { + static_cast*>(ret)->remove(); } - - /* - * Get and remove the last element of the list. If the list is empty, - * return nullptr. - */ - T* popLast() { - T* ret = sentinel.getPrevious(); - if (ret) - static_cast*>(ret)->remove(); - return ret; + return ret; + } + + /* + * Return true if the list is empty, or false otherwise. + */ + bool isEmpty() const + { + return !sentinel.isInList(); + } + + /* + * Remove all the elements from the list. + * + * This runs in time linear to the list's length, because we have to mark + * each element as not in the list. + */ + void clear() + { + while (popFirst()) { + continue; } - - /* - * Return true if the list is empty, or false otherwise. - */ - bool isEmpty() const { - return !sentinel.isInList(); + } + + /* + * Measures the memory consumption of the list excluding |this|. Note that + * it only measures the list elements themselves. If the list elements + * contain pointers to other memory blocks, those blocks must be measured + * separately during a subsequent iteration over the list. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const + { + size_t n = 0; + for (const T* t = getFirst(); t; t = t->getNext()) { + n += aMallocSizeOf(t); } + return n; + } + + /* + * Like sizeOfExcludingThis(), but measures |this| as well. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const + { + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); + } + + /* + * In a debug build, make sure that the list is sane (no cycles, consistent + * mNext/mPrev pointers, only one sentinel). Has no effect in release builds. + */ + void debugAssertIsSane() const + { +#ifdef DEBUG + const LinkedListElement* slow; + const LinkedListElement* fast1; + const LinkedListElement* fast2; /* - * Remove all the elements from the list. - * - * This runs in time linear to the list's length, because we have to mark - * each element as not in the list. + * Check for cycles in the forward singly-linked list using the + * tortoise/hare algorithm. */ - void clear() { - while (popFirst()) - continue; + for (slow = sentinel.mNext, + fast1 = sentinel.mNext->mNext, + fast2 = sentinel.mNext->mNext->mNext; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mNext, fast1 = fast2->mNext, fast2 = fast1->mNext) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); } - /* - * Measures the memory consumption of the list excluding |this|. Note that - * it only measures the list elements themselves. If the list elements - * contain pointers to other memory blocks, those blocks must be measured - * separately during a subsequent iteration over the list. - */ - size_t sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const { - size_t n = 0; - for (const T* t = getFirst(); t; t = t->getNext()) - n += mallocSizeOf(t); - return n; + /* Check for cycles in the backward singly-linked list. */ + for (slow = sentinel.mPrev, + fast1 = sentinel.mPrev->mPrev, + fast2 = sentinel.mPrev->mPrev->mPrev; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mPrev, fast1 = fast2->mPrev, fast2 = fast1->mPrev) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); } /* - * Like sizeOfExcludingThis(), but measures |this| as well. + * Check that |sentinel| is the only node in the list with + * mIsSentinel == true. */ - size_t sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const { - return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + for (const LinkedListElement* elem = sentinel.mNext; + elem != &sentinel; + elem = elem->mNext) { + MOZ_ASSERT(!elem->mIsSentinel); } - /* - * In a debug build, make sure that the list is sane (no cycles, consistent - * next/prev pointers, only one sentinel). Has no effect in release builds. - */ - void debugAssertIsSane() const { -#ifdef DEBUG - const LinkedListElement* slow; - const LinkedListElement* fast1; - const LinkedListElement* fast2; - - /* - * Check for cycles in the forward singly-linked list using the - * tortoise/hare algorithm. - */ - for (slow = sentinel.next, - fast1 = sentinel.next->next, - fast2 = sentinel.next->next->next; - slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; - slow = slow->next, fast1 = fast2->next, fast2 = fast1->next) - { - MOZ_ASSERT(slow != fast1); - MOZ_ASSERT(slow != fast2); - } - - /* Check for cycles in the backward singly-linked list. */ - for (slow = sentinel.prev, - fast1 = sentinel.prev->prev, - fast2 = sentinel.prev->prev->prev; - slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; - slow = slow->prev, fast1 = fast2->prev, fast2 = fast1->prev) - { - MOZ_ASSERT(slow != fast1); - MOZ_ASSERT(slow != fast2); - } - - /* - * Check that |sentinel| is the only node in the list with - * isSentinel == true. - */ - for (const LinkedListElement* elem = sentinel.next; - elem != &sentinel; - elem = elem->next) - { - MOZ_ASSERT(!elem->isSentinel); - } - - /* Check that the next/prev pointers match up. */ - const LinkedListElement* prev = &sentinel; - const LinkedListElement* cur = sentinel.next; - do { - MOZ_ASSERT(cur->prev == prev); - MOZ_ASSERT(prev->next == cur); + /* Check that the mNext/mPrev pointers match up. */ + const LinkedListElement* prev = &sentinel; + const LinkedListElement* cur = sentinel.mNext; + do { + MOZ_ASSERT(cur->mPrev == prev); + MOZ_ASSERT(prev->mNext == cur); - prev = cur; - cur = cur->next; - } while (cur != &sentinel); + prev = cur; + cur = cur->mNext; + } while (cur != &sentinel); #endif /* ifdef DEBUG */ - } + } - private: - friend class LinkedListElement; +private: + friend class LinkedListElement; - void assertContains(const T* t) const { + void assertContains(const T* aValue) const + { #ifdef DEBUG - for (const T* elem = getFirst(); - elem; - elem = elem->getNext()) - { - if (elem == t) - return; + for (const T* elem = getFirst(); elem; elem = elem->getNext()) { + if (elem == aValue) { + return; } - MOZ_CRASH("element wasn't found in this list!"); -#endif } + MOZ_CRASH("element wasn't found in this list!"); +#endif + } - LinkedList& operator=(const LinkedList& other) MOZ_DELETE; - LinkedList(const LinkedList& other) MOZ_DELETE; + LinkedList& operator=(const LinkedList& aOther) MOZ_DELETE; + LinkedList(const LinkedList& aOther) MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MSIntTypes.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MSIntTypes.h index 3dfba55f58..4ce922fbc5 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MSIntTypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MSIntTypes.h @@ -1,32 +1,32 @@ // ISO C9x compliant inttypes.h for Microsoft Visual Studio -// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 -// +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// // Copyright (c) 2006 Alexander Chemeris -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: -// +// // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. -// +// // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. -// +// // 3. The name of the author may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// +// /////////////////////////////////////////////////////////////////////////////// #ifndef _MSC_VER // [ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MacroArgs.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MacroArgs.h new file mode 100644 index 0000000000..c8b7338210 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MacroArgs.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements various macros meant to ease the use of variadic macros. + */ + +#ifndef mozilla_MacroArgs_h +#define mozilla_MacroArgs_h + +/* + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) counts the number of variadic + * arguments and prefixes it with |aPrefix|. For example: + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(, foo, 42) expands to 2 + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(A, foo, 42, bar) expands to A3 + * + * You must pass in between 1 and 50 (inclusive) variadic arguments, past + * |aPrefix|. It is not legal to do + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(prefix) + * + * (that is, pass in 0 variadic arguments). To ensure that a compile-time + * error occurs when these constraints are violated, use the + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT macro with the same variaidc arguments + * wherever this macro is used. + * + * Passing (__VA_ARGS__, ) rather than simply calling + * MOZ_MACROARGS_ARG_COUNT_HELPER2(__VA_ARGS__, ) very + * carefully tiptoes around a MSVC bug where it improperly expands __VA_ARGS__ + * as a single token in argument lists. For details, see: + * + * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement + * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 + */ +#define MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) \ + MOZ_MACROARGS_ARG_COUNT_HELPER((__VA_ARGS__, \ + aPrefix##50, aPrefix##49, aPrefix##48, aPrefix##47, aPrefix##46, \ + aPrefix##45, aPrefix##44, aPrefix##43, aPrefix##42, aPrefix##41, \ + aPrefix##40, aPrefix##39, aPrefix##38, aPrefix##37, aPrefix##36, \ + aPrefix##35, aPrefix##34, aPrefix##33, aPrefix##32, aPrefix##31, \ + aPrefix##30, aPrefix##29, aPrefix##28, aPrefix##27, aPrefix##26, \ + aPrefix##25, aPrefix##24, aPrefix##23, aPrefix##22, aPrefix##21, \ + aPrefix##20, aPrefix##19, aPrefix##18, aPrefix##17, aPrefix##16, \ + aPrefix##15, aPrefix##14, aPrefix##13, aPrefix##12, aPrefix##11, \ + aPrefix##10, aPrefix##9, aPrefix##8, aPrefix##7, aPrefix##6, \ + aPrefix##5, aPrefix##4, aPrefix##3, aPrefix##2, aPrefix##1, aPrefix##0)) + +#define MOZ_MACROARGS_ARG_COUNT_HELPER(aArgs) \ + MOZ_MACROARGS_ARG_COUNT_HELPER2 aArgs + +#define MOZ_MACROARGS_ARG_COUNT_HELPER2( \ + a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, \ + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \ + a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \ + a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \ + a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \ + a51, ...) a51 + +/* + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT ensures that a compile-time error occurs + * when the argument count constraints of MOZ_PASTE_PREFIX_AND_ARG_COUNT are + * violated. Use this macro wherever MOZ_PASTE_PREFIX_AND_ARG_COUNT is used + * and pass it the same variadic arguments. + * + * This macro employs a few dirty tricks to function. To detect the zero + * argument case, |(__VA_ARGS__)| is stringified, sizeof-ed, and compared to + * what it should be in the absence of arguments. + * + * Detecting too many arguments is a little trickier. With a valid argument + * count and a prefix of 1, MOZ_PASTE_PREFIX_AND_ARG_COUNT expands to e.g. 14. + * With a prefix of 0.0, it expands to e.g. 0.04. If there are too many + * arguments, it expands to the first argument over the limit. If this + * exceeding argument is a number, the assertion will fail as there is no + * number than can simultaneously be both > 10 and == 0. If the exceeding + * argument is not a number, a compile-time error should still occur due to + * the operations performed on it. + */ +#define MOZ_MACROARGS_STRINGIFY_HELPER(x) #x +#define MOZ_STATIC_ASSERT_VALID_ARG_COUNT(...) \ + static_assert( \ + sizeof(MOZ_MACROARGS_STRINGIFY_HELPER((__VA_ARGS__))) != sizeof("()") && \ + (MOZ_PASTE_PREFIX_AND_ARG_COUNT(1, __VA_ARGS__)) > 10 && \ + (int)(MOZ_PASTE_PREFIX_AND_ARG_COUNT(0.0, __VA_ARGS__)) == 0, \ + "MOZ_STATIC_ASSERT_VALID_ARG_COUNT requires 1 to 50 arguments") /* ; */ + +/* + * MOZ_ARGS_AFTER_N expands to its arguments excluding the first |N| + * arguments. For example: + * + * MOZ_ARGS_AFTER_2(a, b, c, d) expands to: c, d + */ +#define MOZ_ARGS_AFTER_1(a1, ...) __VA_ARGS__ +#define MOZ_ARGS_AFTER_2(a1, a2, ...) __VA_ARGS__ + +/* + * MOZ_ARG_N expands to its |N|th argument. + */ +#define MOZ_ARG_1(a1, ...) a1 +#define MOZ_ARG_2(a1, a2, ...) a2 + +#endif /* mozilla_MacroArgs_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MacroForEach.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MacroForEach.h new file mode 100644 index 0000000000..ae1f4d0e99 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MacroForEach.h @@ -0,0 +1,158 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements a higher-order macro for iteratively calling another macro with + * fixed leading arguments, plus a trailing element picked from a second list + * of arguments. + */ + +#ifndef mozilla_MacroForEach_h +#define mozilla_MacroForEach_h + +#include "mozilla/MacroArgs.h" + +/* + * MOZ_FOR_EACH(aMacro, aFixedArgs, aArgs) expands to N calls to the macro + * |aMacro| where N is equal the number of items in the list |aArgs|. The + * arguments for each |aMacro| call are composed of *all* arguments in the list + * |aFixedArgs| as well as a single argument in the list |aArgs|. For example: + * + * #define MACRO_A(x) x + + * int a = MOZ_FOR_EACH(MACRO_A, (), (1, 2, 3)) 0; + * // Expands to: MACRO_A(1) MACRO_A(2) MACRO_A(3) 0; + * // And further to: 1 + 2 + 3 + 0; + * + * #define MACRO_B(k, x) (k + x) + + * int b = MOZ_FOR_EACH(MACRO_B, (5,), (1, 2)) 0; + * // Expands to: MACRO_B(5, 1) MACRO_B(5, 2) 0; + * + * #define MACRO_C(k1, k2, x) (k1 + k2 + x) + + * int c = MOZ_FOR_EACH(MACRO_C, (5, 8,), (1, 2)) 0; + * // Expands to: MACRO_B(5, 8, 1) MACRO_B(5, 8, 2) 0; + * + * If the |aFixedArgs| list is not empty, a trailing comma must be included. + * + * The |aArgs| list must be not be empty and may be up to 50 items long. Use + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT to ensure that violating this constraint + * results in a compile-time error. + */ +#define MOZ_FOR_EACH_EXPAND_HELPER(...) __VA_ARGS__ +#define MOZ_FOR_EACH_GLUE(a, b) a b +#define MOZ_FOR_EACH(aMacro, aFixedArgs, aArgs) \ + MOZ_FOR_EACH_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_FOR_EACH_, \ + MOZ_FOR_EACH_EXPAND_HELPER aArgs), \ + (aMacro, aFixedArgs, aArgs)) + +#define MOZ_FOR_EACH_HELPER_GLUE(a, b) a b +#define MOZ_FOR_EACH_HELPER(aMacro, aFixedArgs, aArgs) \ + MOZ_FOR_EACH_HELPER_GLUE( \ + aMacro, \ + (MOZ_FOR_EACH_EXPAND_HELPER aFixedArgs MOZ_ARG_1 aArgs)) + +#define MOZ_FOR_EACH_1(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) +#define MOZ_FOR_EACH_2(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_1(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_3(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_2(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_4(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_3(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_5(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_4(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_6(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_5(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_7(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_6(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_8(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_7(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_9(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_8(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_10(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_9(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_11(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_10(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_12(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_11(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_13(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_12(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_14(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_13(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_15(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_14(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_16(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_15(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_17(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_16(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_18(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_17(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_19(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_18(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_20(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_19(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_21(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_20(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_22(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_21(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_23(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_22(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_24(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_23(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_25(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_24(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_26(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_25(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_27(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_26(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_28(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_27(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_29(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_28(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_30(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_29(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_31(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_30(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_32(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_31(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_33(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_32(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_34(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_33(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_35(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_34(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_36(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_35(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_37(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_36(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_38(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_37(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_39(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_38(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_40(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_39(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_41(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_40(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_42(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_41(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_43(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_42(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_44(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_43(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_45(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_44(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_46(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_45(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_47(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_46(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_48(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_47(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_49(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_48(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_50(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_49(m, fa, (MOZ_ARGS_AFTER_1 a)) + +#endif /* mozilla_MacroForEach_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MathAlgorithms.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MathAlgorithms.h index 7b98c7fc19..cd71d19770 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MathAlgorithms.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MathAlgorithms.h @@ -21,31 +21,31 @@ namespace mozilla { // Greatest Common Divisor template MOZ_ALWAYS_INLINE IntegerType -EuclidGCD(IntegerType a, IntegerType b) +EuclidGCD(IntegerType aA, IntegerType aB) { // Euclid's algorithm; O(N) in the worst case. (There are better // ways, but we don't need them for the current use of this algo.) - MOZ_ASSERT(a > 0); - MOZ_ASSERT(b > 0); + MOZ_ASSERT(aA > IntegerType(0)); + MOZ_ASSERT(aB > IntegerType(0)); - while (a != b) { - if (a > b) { - a = a - b; + while (aA != aB) { + if (aA > aB) { + aA = aA - aB; } else { - b = b - a; + aB = aB - aA; } } - return a; + return aA; } // Least Common Multiple template MOZ_ALWAYS_INLINE IntegerType -EuclidLCM(IntegerType a, IntegerType b) +EuclidLCM(IntegerType aA, IntegerType aB) { // Divide first to reduce overflow risk. - return (a / EuclidGCD(a, b)) * b; + return (aA / EuclidGCD(aA, aB)) * aB; } namespace detail { @@ -68,7 +68,7 @@ template<> struct AllowDeprecatedAbs : TrueType {}; // to Abs below, and it will be removed when all callers have been changed. template inline typename mozilla::EnableIf::value, T>::Type -DeprecatedAbs(const T t) +DeprecatedAbs(const T aValue) { // The absolute value of the smallest possible value of a signed-integer type // won't fit in that type (on twos-complement systems -- and we're blithely @@ -79,10 +79,10 @@ DeprecatedAbs(const T t) // value in the range [-maxvalue, 0]), then negating (giving a value in the // range [0, maxvalue]), doesn't produce maxvalue (because in twos-complement, // (minvalue + 1) == -maxvalue). - MOZ_ASSERT(t >= 0 || - -(t + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1), + MOZ_ASSERT(aValue >= 0 || + -(aValue + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1), "You can't negate the smallest possible negative integer!"); - return t >= 0 ? t : -t; + return aValue >= 0 ? aValue : -aValue; } namespace detail { @@ -102,7 +102,8 @@ template<> struct AbsReturnTypeFixed { typedef uint64_t Type; }; template struct AbsReturnType : AbsReturnTypeFixed {}; -template<> struct AbsReturnType : EnableIf {}; +template<> struct AbsReturnType : + EnableIf {}; template<> struct AbsReturnType { typedef unsigned char Type; }; template<> struct AbsReturnType { typedef unsigned short Type; }; template<> struct AbsReturnType { typedef unsigned int Type; }; @@ -116,50 +117,46 @@ template<> struct AbsReturnType { typedef long double Type; }; template inline typename detail::AbsReturnType::Type -Abs(const T t) +Abs(const T aValue) { typedef typename detail::AbsReturnType::Type ReturnType; - return t >= 0 ? ReturnType(t) : ~ReturnType(t) + 1; + return aValue >= 0 ? ReturnType(aValue) : ~ReturnType(aValue) + 1; } template<> inline float -Abs(const float f) +Abs(const float aFloat) { - return std::fabs(f); + return std::fabs(aFloat); } template<> inline double -Abs(const double d) +Abs(const double aDouble) { - return std::fabs(d); + return std::fabs(aDouble); } template<> inline long double -Abs(const long double d) +Abs(const long double aLongDouble) { - return std::fabs(d); + return std::fabs(aLongDouble); } } // namespace mozilla -#if defined(_WIN32) && (_MSC_VER >= 1300) && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) +#if defined(_WIN32) && (_MSC_VER >= 1300) && \ + (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) # define MOZ_BITSCAN_WINDOWS - extern "C" { - unsigned char _BitScanForward(unsigned long* Index, unsigned long mask); - unsigned char _BitScanReverse(unsigned long* Index, unsigned long mask); +# include # pragma intrinsic(_BitScanForward, _BitScanReverse) # if defined(_M_AMD64) || defined(_M_X64) # define MOZ_BITSCAN_WINDOWS64 - unsigned char _BitScanForward64(unsigned long* index, unsigned __int64 mask); - unsigned char _BitScanReverse64(unsigned long* index, unsigned __int64 mask); # pragma intrinsic(_BitScanForward64, _BitScanReverse64) # endif - } // extern "C" #endif @@ -169,62 +166,68 @@ namespace detail { #if defined(MOZ_BITSCAN_WINDOWS) - inline uint_fast8_t - CountLeadingZeroes32(uint32_t u) - { - unsigned long index; - _BitScanReverse(&index, static_cast(u)); - return uint_fast8_t(31 - index); - } +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanReverse(&index, static_cast(aValue)); + return uint_fast8_t(31 - index); +} - inline uint_fast8_t - CountTrailingZeroes32(uint32_t u) - { - unsigned long index; - _BitScanForward(&index, static_cast(u)); - return uint_fast8_t(index); - } +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanForward(&index, static_cast(aValue)); + return uint_fast8_t(index); +} - inline uint_fast8_t - CountPopulation32(uint32_t u) - { - uint32_t sum2 = (u & 0x55555555) + ((u & 0xaaaaaaaa) >> 1); - uint32_t sum4 = (sum2 & 0x33333333) + ((sum2 & 0xcccccccc) >> 2); - uint32_t sum8 = (sum4 & 0x0f0f0f0f) + ((sum4 & 0xf0f0f0f0) >> 4); - uint32_t sum16 = (sum8 & 0x00ff00ff) + ((sum8 & 0xff00ff00) >> 8); - return sum16; - } +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + uint32_t x = aValue - ((aValue >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + return (((x + (x >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; +} +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return uint_fast8_t(CountPopulation32(aValue & 0xffffffff) + + CountPopulation32(aValue >> 32)); +} - inline uint_fast8_t - CountLeadingZeroes64(uint64_t u) - { -# if defined(MOZ_BITSCAN_WINDOWS64) - unsigned long index; - _BitScanReverse64(&index, static_cast(u)); - return uint_fast8_t(63 - index); -# else - uint32_t hi = uint32_t(u >> 32); - if (hi != 0) - return CountLeadingZeroes32(hi); - return 32 + CountLeadingZeroes32(uint32_t(u)); -# endif +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanReverse64(&index, static_cast(aValue)); + return uint_fast8_t(63 - index); +#else + uint32_t hi = uint32_t(aValue >> 32); + if (hi != 0) { + return CountLeadingZeroes32(hi); } + return 32u + CountLeadingZeroes32(uint32_t(aValue)); +#endif +} - inline uint_fast8_t - CountTrailingZeroes64(uint64_t u) - { -# if defined(MOZ_BITSCAN_WINDOWS64) - unsigned long index; - _BitScanForward64(&index, static_cast(u)); - return uint_fast8_t(index); -# else - uint32_t lo = uint32_t(u); - if (lo != 0) - return CountTrailingZeroes32(lo); - return 32 + CountTrailingZeroes32(uint32_t(u >> 32)); -# endif +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanForward64(&index, static_cast(aValue)); + return uint_fast8_t(index); +#else + uint32_t lo = uint32_t(aValue); + if (lo != 0) { + return CountTrailingZeroes32(lo); } + return 32u + CountTrailingZeroes32(uint32_t(aValue >> 32)); +#endif +} # ifdef MOZ_HAVE_BITSCAN64 # undef MOZ_HAVE_BITSCAN64 @@ -240,52 +243,59 @@ namespace detail { // gcc has had __builtin_clz and friends since 3.4: no need to check. # endif - inline uint_fast8_t - CountLeadingZeroes32(uint32_t u) - { - return __builtin_clz(u); - } +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + return __builtin_clz(aValue); +} - inline uint_fast8_t - CountTrailingZeroes32(uint32_t u) - { - return __builtin_ctz(u); - } +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + return __builtin_ctz(aValue); +} - inline uint_fast8_t - CountPopulation32(uint32_t u) - { - return __builtin_popcount(u); - } +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + return __builtin_popcount(aValue); +} - inline uint_fast8_t - CountLeadingZeroes64(uint64_t u) - { - return __builtin_clzll(u); - } +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return __builtin_popcountll(aValue); +} - inline uint_fast8_t - CountTrailingZeroes64(uint64_t u) - { - return __builtin_ctzll(u); - } +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ + return __builtin_clzll(aValue); +} + +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ + return __builtin_ctzll(aValue); +} #else # error "Implement these!" - inline uint_fast8_t CountLeadingZeroes32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountTrailingZeroes32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountPopulation32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountLeadingZeroes64(uint64_t u) MOZ_DELETE; - inline uint_fast8_t CountTrailingZeroes64(uint64_t u) MOZ_DELETE; +inline uint_fast8_t CountLeadingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountLeadingZeroes64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes64(uint64_t aValue) MOZ_DELETE; #endif } // namespace detail /** - * Compute the number of high-order zero bits in the NON-ZERO number |u|. That - * is, looking at the bitwise representation of the number, with the highest- - * valued bits at the start, return the number of zeroes before the first one - * is observed. + * Compute the number of high-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * highest- valued bits at the start, return the number of zeroes before the + * first one is observed. * * CountLeadingZeroes32(0xF0FF1000) is 0; * CountLeadingZeroes32(0x7F8F0001) is 1; @@ -293,17 +303,17 @@ namespace detail { * CountLeadingZeroes32(0x1FF50010) is 3; and so on. */ inline uint_fast8_t -CountLeadingZeroes32(uint32_t u) +CountLeadingZeroes32(uint32_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountLeadingZeroes32(u); + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes32(aValue); } /** - * Compute the number of low-order zero bits in the NON-ZERO number |u|. That - * is, looking at the bitwise representation of the number, with the lowest- - * valued bits at the start, return the number of zeroes before the first one - * is observed. + * Compute the number of low-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * lowest- valued bits at the start, return the number of zeroes before the + * first one is observed. * * CountTrailingZeroes32(0x0100FFFF) is 0; * CountTrailingZeroes32(0x7000FFFE) is 1; @@ -311,35 +321,42 @@ CountLeadingZeroes32(uint32_t u) * CountTrailingZeroes32(0x0080FFF8) is 3; and so on. */ inline uint_fast8_t -CountTrailingZeroes32(uint32_t u) +CountTrailingZeroes32(uint32_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountTrailingZeroes32(u); + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes32(aValue); } /** - * Compute the number of one bits in the number |u|, + * Compute the number of one bits in the number |aValue|, */ inline uint_fast8_t -CountPopulation32(uint32_t u) +CountPopulation32(uint32_t aValue) +{ + return detail::CountPopulation32(aValue); +} + +/** Analogous to CoutPopulation32, but for 64-bit numbers */ +inline uint_fast8_t +CountPopulation64(uint64_t aValue) { - return detail::CountPopulation32(u); + return detail::CountPopulation64(aValue); } /** Analogous to CountLeadingZeroes32, but for 64-bit numbers. */ inline uint_fast8_t -CountLeadingZeroes64(uint64_t u) +CountLeadingZeroes64(uint64_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountLeadingZeroes64(u); + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes64(aValue); } /** Analogous to CountTrailingZeroes32, but for 64-bit numbers. */ inline uint_fast8_t -CountTrailingZeroes64(uint64_t u) +CountTrailingZeroes64(uint64_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountTrailingZeroes64(u); + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes64(aValue); } namespace detail { @@ -350,27 +367,29 @@ class CeilingLog2; template class CeilingLog2 { - public: - static uint_fast8_t compute(const T t) { - // Check for <= 1 to avoid the == 0 undefined case. - return t <= 1 ? 0 : 32 - CountLeadingZeroes32(t - 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0u : 32u - CountLeadingZeroes32(aValue - 1); + } }; template class CeilingLog2 { - public: - static uint_fast8_t compute(const T t) { - // Check for <= 1 to avoid the == 0 undefined case. - return t <= 1 ? 0 : 64 - CountLeadingZeroes64(t - 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0 : 64 - CountLeadingZeroes64(aValue - 1); + } }; } // namespace detail /** - * Compute the log of the least power of 2 greater than or equal to |t|. + * Compute the log of the least power of 2 greater than or equal to |aValue|. * * CeilingLog2(0..1) is 0; * CeilingLog2(2) is 1; @@ -380,16 +399,16 @@ class CeilingLog2 */ template inline uint_fast8_t -CeilingLog2(const T t) +CeilingLog2(const T aValue) { - return detail::CeilingLog2::compute(t); + return detail::CeilingLog2::compute(aValue); } /** A CeilingLog2 variant that accepts only size_t. */ inline uint_fast8_t -CeilingLog2Size(size_t n) +CeilingLog2Size(size_t aValue) { - return CeilingLog2(n); + return CeilingLog2(aValue); } namespace detail { @@ -400,25 +419,27 @@ class FloorLog2; template class FloorLog2 { - public: - static uint_fast8_t compute(const T t) { - return 31 - CountLeadingZeroes32(t | 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + return 31u - CountLeadingZeroes32(aValue | 1); + } }; template class FloorLog2 { - public: - static uint_fast8_t compute(const T t) { - return 63 - CountLeadingZeroes64(t | 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + return 63u - CountLeadingZeroes64(aValue | 1); + } }; } // namespace detail /** - * Compute the log of the greatest power of 2 less than or equal to |t|. + * Compute the log of the greatest power of 2 less than or equal to |aValue|. * * FloorLog2(0..1) is 0; * FloorLog2(2..3) is 1; @@ -427,16 +448,16 @@ class FloorLog2 */ template inline uint_fast8_t -FloorLog2(const T t) +FloorLog2(const T aValue) { - return detail::FloorLog2::compute(t); + return detail::FloorLog2::compute(aValue); } /** A FloorLog2 variant that accepts only size_t. */ inline uint_fast8_t -FloorLog2Size(size_t n) +FloorLog2Size(size_t aValue) { - return FloorLog2(n); + return FloorLog2(aValue); } /* @@ -444,11 +465,11 @@ FloorLog2Size(size_t n) * be so great that the computed value would overflow |size_t|. */ inline size_t -RoundUpPow2(size_t x) +RoundUpPow2(size_t aValue) { - MOZ_ASSERT(x <= (size_t(1) << (sizeof(size_t) * CHAR_BIT - 1)), + MOZ_ASSERT(aValue <= (size_t(1) << (sizeof(size_t) * CHAR_BIT - 1)), "can't round up -- will overflow!"); - return size_t(1) << CeilingLog2(x); + return size_t(1) << CeilingLog2(aValue); } /** @@ -456,11 +477,11 @@ RoundUpPow2(size_t x) */ template inline T -RotateLeft(const T t, uint_fast8_t shift) +RotateLeft(const T aValue, uint_fast8_t aShift) { - MOZ_ASSERT(shift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); static_assert(IsUnsigned::value, "Rotates require unsigned values"); - return (t << shift) | (t >> (sizeof(T) * CHAR_BIT - shift)); + return (aValue << aShift) | (aValue >> (sizeof(T) * CHAR_BIT - aShift)); } /** @@ -468,11 +489,11 @@ RotateLeft(const T t, uint_fast8_t shift) */ template inline T -RotateRight(const T t, uint_fast8_t shift) +RotateRight(const T aValue, uint_fast8_t aShift) { - MOZ_ASSERT(shift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); static_assert(IsUnsigned::value, "Rotates require unsigned values"); - return (t >> shift) | (t << (sizeof(T) * CHAR_BIT - shift)); + return (aValue >> aShift) | (aValue << (sizeof(T) * CHAR_BIT - aShift)); } } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Maybe.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Maybe.h index 25683a28ab..4ba88f6771 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Maybe.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Maybe.h @@ -31,131 +31,150 @@ namespace mozilla { template class Maybe { - AlignedStorage2 storage; - bool constructed; - - T& asT() { return *storage.addr(); } - - public: - Maybe() { constructed = false; } - ~Maybe() { if (constructed) asT().~T(); } - - bool empty() const { return !constructed; } - - void construct() { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(); - constructed = true; - } - - template - void construct(const T1& t1) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8, const T9& t9) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8, t9); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); - constructed = true; - } - - T* addr() { - MOZ_ASSERT(constructed); - return &asT(); - } - - T& ref() { - MOZ_ASSERT(constructed); - return asT(); - } - - const T& ref() const { - MOZ_ASSERT(constructed); - return const_cast(this)->asT(); - } - - void destroy() { - ref().~T(); - constructed = false; - } - - void destroyIfConstructed() { - if (!empty()) - destroy(); - } - - private: - Maybe(const Maybe& other) MOZ_DELETE; - const Maybe& operator=(const Maybe& other) MOZ_DELETE; + AlignedStorage2 storage; + bool constructed; + + T& asT() { return *storage.addr(); } + +public: + Maybe() { constructed = false; } + ~Maybe() { if (constructed) { asT().~T(); } } + + bool empty() const { return !constructed; } + + void construct() + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(); + constructed = true; + } + + template + void construct(const T1& aT1) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9, const T10& aT10) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9, aT10); + constructed = true; + } + + T* addr() + { + MOZ_ASSERT(constructed); + return &asT(); + } + + T& ref() + { + MOZ_ASSERT(constructed); + return asT(); + } + + const T& ref() const + { + MOZ_ASSERT(constructed); + return const_cast(this)->asT(); + } + + void destroy() + { + ref().~T(); + constructed = false; + } + + void destroyIfConstructed() + { + if (!empty()) { + destroy(); + } + } + +private: + Maybe(const Maybe& aOther) MOZ_DELETE; + const Maybe& operator=(const Maybe& aOther) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MaybeOneOf.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MaybeOneOf.h new file mode 100644 index 0000000000..1c58f88253 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MaybeOneOf.h @@ -0,0 +1,144 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_MaybeOneOf_h +#define mozilla_MaybeOneOf_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" +#include "mozilla/Move.h" +#include "mozilla/TemplateLib.h" + +#include // For placement new + +namespace mozilla { + +/* + * MaybeOneOf is like Maybe, but it supports constructing either T1 + * or T2. When a MaybeOneOf is constructed, it is |empty()|, i.e., + * no value has been constructed and no destructor will be called when the + * MaybeOneOf is destroyed. Upon calling |construct()| or + * |construct()|, a T1 or T2 object will be constructed with the given + * arguments and that object will be destroyed when the owning MaybeOneOf is + * destroyed. + */ +template +class MaybeOneOf +{ + AlignedStorage::value> storage; + + enum State { None, SomeT1, SomeT2 } state; + template struct Type2State {}; + + template + T& as() + { + MOZ_ASSERT(state == Type2State::result); + return *(T*)storage.addr(); + } + + template + const T& as() const + { + MOZ_ASSERT(state == Type2State::result); + return *(T*)storage.addr(); + } + +public: + MaybeOneOf() : state(None) {} + ~MaybeOneOf() { destroyIfConstructed(); } + + bool empty() const { return state == None; } + + template + bool constructed() const { return state == Type2State::result; } + + template + void construct() + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(); + } + + template + void construct(U&& aU) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(Move(aU)); + } + + template + void construct(const U1& aU1) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(aU1); + } + + template + void construct(const U1& aU1, const U2& aU2) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(aU1, aU2); + } + + template + T& ref() + { + return as(); + } + + template + const T& ref() const + { + return as(); + } + + void destroy() + { + MOZ_ASSERT(state == SomeT1 || state == SomeT2); + if (state == SomeT1) { + as().~T1(); + } else if (state == SomeT2) { + as().~T2(); + } + state = None; + } + + void destroyIfConstructed() + { + if (!empty()) { + destroy(); + } + } + +private: + MaybeOneOf(const MaybeOneOf& aOther) MOZ_DELETE; + const MaybeOneOf& operator=(const MaybeOneOf& aOther) MOZ_DELETE; +}; + +template +template +struct MaybeOneOf::Type2State +{ + typedef MaybeOneOf Enclosing; + static const typename Enclosing::State result = Enclosing::SomeT1; +}; + +template +template +struct MaybeOneOf::Type2State +{ + typedef MaybeOneOf Enclosing; + static const typename Enclosing::State result = Enclosing::SomeT2; +}; + +} // namespace mozilla + +#endif /* mozilla_MaybeOneOf_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MemoryChecking.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MemoryChecking.h index 2130990c6b..0642d758c0 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MemoryChecking.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/MemoryChecking.h @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* - * Provides a common interface to the ASan (AddressSanitizer) and Valgrind + * Provides a common interface to the ASan (AddressSanitizer) and Valgrind * functions used to mark memory in certain ways. In detail, the following * three macros are provided: * @@ -34,14 +34,14 @@ #if defined(MOZ_ASAN) #include +#include "mozilla/Types.h" + extern "C" { - /* These definitions are usually provided through the - * sanitizer/asan_interface.h header installed by ASan. - */ - void __asan_poison_memory_region(void const volatile *addr, size_t size) - __attribute__((visibility("default"))); - void __asan_unpoison_memory_region(void const volatile *addr, size_t size) - __attribute__((visibility("default"))); +/* These definitions are usually provided through the + * sanitizer/asan_interface.h header installed by ASan. + */ +void MOZ_EXPORT __asan_poison_memory_region(void const volatile *addr, size_t size); +void MOZ_EXPORT __asan_unpoison_memory_region(void const volatile *addr, size_t size); #define MOZ_MAKE_MEM_NOACCESS(addr, size) \ __asan_poison_memory_region((addr), (size)) @@ -63,9 +63,9 @@ extern "C" { VALGRIND_MAKE_MEM_DEFINED((addr), (size)) #else -#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while(0) -#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while(0) -#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while(0) +#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while (0) #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Move.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Move.h index f7d39ffa9b..08ae86fa57 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Move.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Move.h @@ -105,7 +105,7 @@ namespace mozilla { * * c2 = Move(c1); * - * This destroys c1, moves c1's value to c2, and leaves c1 in an undefined but + * This destroys c2, moves c1's value to c2, and leaves c1 in an undefined but * destructible state. * * As we say, a move must leave the original in a "destructible" state. The @@ -132,7 +132,7 @@ namespace mozilla { * * To avoid this, C++11 has tweaks to make it possible to write what you mean. * The four constructor overloads above can be written as one constructor - * template like so: + * template like so[0]: * * template * C::C(XArg&& x, YArg&& y) : x(Forward(x)), y(Forward(y)) { } @@ -144,8 +144,8 @@ namespace mozilla { * - First, when a function template takes an argument that is an rvalue * reference to a template argument (like 'XArg&& x' and 'YArg&& y' above), * then when the argument is applied to an lvalue, the template argument - * resolves to 'T &'; and when it is applied to an rvalue, the template - * argument resolves to 'T &&'. Thus, in a call to C::C like: + * resolves to 'T&'; and when it is applied to an rvalue, the template + * argument resolves to 'T&&'. Thus, in a call to C::C like: * * X foo(int); * Y yy; @@ -180,6 +180,28 @@ namespace mozilla { * 'std::forward', which are just like our 'Move' and 'Forward'; but those * definitions aren't available in that header on all our platforms, so we * define them ourselves here.) + * + * 0. This pattern is known as "perfect forwarding". Interestingly, it is not + * actually perfect, and it can't forward all possible argument expressions! + * There are two issues: one that's a C++11 issue, and one that's a legacy + * compiler issue. + * + * The C++11 issue is that you can't form a reference to a bit-field. As a + * workaround, assign the bit-field to a local variable and use that: + * + * // C is as above + * struct S { int x : 1; } s; + * C(s.x, 0); // BAD: s.x is a reference to a bit-field, can't form those + * int tmp = s.x; + * C(tmp, 0); // OK: tmp not a bit-field + * + * The legacy issue is that when we don't have true nullptr and must emulate + * it (gcc 4.4/4.5), forwarding |nullptr| results in an |int| or |long| + * forwarded reference. But such a reference, even if its value is a null + * pointer constant expression, is not itself a null pointer constant + * expression. This causes -Werror=conversion-null errors and pointer-to- + * integer comparison errors. Until we always have true nullptr, users of + * forwarding methods must not pass |nullptr| to them. */ /** @@ -188,9 +210,9 @@ namespace mozilla { */ template inline typename RemoveReference::Type&& -Move(T&& a) +Move(T&& aX) { - return static_cast::Type&&>(a); + return static_cast::Type&&>(aX); } /** @@ -199,28 +221,28 @@ Move(T&& a) */ template inline T&& -Forward(typename RemoveReference::Type& a) +Forward(typename RemoveReference::Type& aX) { - return static_cast(a); + return static_cast(aX); } template inline T&& -Forward(typename RemoveReference::Type&& t) +Forward(typename RemoveReference::Type&& aX) { static_assert(!IsLvalueReference::value, "misuse of Forward detected! try the other overload"); - return static_cast(t); + return static_cast(aX); } -/** Swap |t| and |u| using move-construction if possible. */ +/** Swap |aX| and |aY| using move-construction if possible. */ template inline void -Swap(T& t, T& u) +Swap(T& aX, T& aY) { - T tmp(Move(t)); - t = Move(u); - u = Move(tmp); + T tmp(Move(aX)); + aX = Move(aY); + aY = Move(tmp); } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/NullPtr.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/NullPtr.h index 35faadc4c3..5963613c4b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/NullPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/NullPtr.h @@ -13,12 +13,10 @@ #define mozilla_NullPtr_h #if defined(__clang__) -# ifndef __has_extension -# define __has_extension __has_feature -# endif -# if __has_extension(cxx_nullptr) -# define MOZ_HAVE_CXX11_NULLPTR +# if !__has_extension(cxx_nullptr) +# error "clang version natively supporting nullptr is required." # endif +# define MOZ_HAVE_CXX11_NULLPTR #elif defined(__GNUC__) # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L # include "mozilla/Compiler.h" @@ -26,23 +24,89 @@ # define MOZ_HAVE_CXX11_NULLPTR # endif # endif -#elif _MSC_VER >= 1600 -# define MOZ_HAVE_CXX11_NULLPTR +#elif defined(_MSC_VER) + // The minimum supported MSVC (10, _MSC_VER 1600) supports nullptr. +# define MOZ_HAVE_CXX11_NULLPTR #endif +namespace mozilla { + /** - * Use C++11 nullptr if available; otherwise use __null for gcc, or a 0 literal - * with the correct size to match the size of a pointer on a given platform. + * IsNullPointer::value is true iff T is the type of C++11's nullptr. If + * nullptr is emulated, IsNullPointer::value is false for all T. + * + * IsNullPointer is useful to give an argument the true decltype(nullptr) type. + * decltype(nullptr) doesn't work when nullptr is emulated. The simplest + * workaround is to use template overloading and SFINAE to expose an overload + * only if an argument's type is decltype(nullptr). Some examples (that assume + * namespace mozilla has been opened, for simplicity): + * + * // foo(T*), foo(stuff that converts to T*), and foo(decltype(nullptr)) + * // (only invoked if nullptr is true nullptr, otherwise foo(T*) is invoked) + * // but nothing else + * void foo(T*) { } + * template + * void foo(N, + * typename EnableIf::value, int>::Type dummy = 0) + * { } + * + * // foo(T*) *exactly* and foo(decltype(nullptr)), nothing else + * void foo(T*) { } + * template + * void foo(U, + * typename EnableIf::value, int>::Type dummy = 0) + * MOZ_DELETE; + * + * The exact details of how set up the SFINAE bits vary on a case-by-case basis. + * If you need help with this (and unless you've internalized way more sadmaking + * nullptr-emulation knowledge than you should have, you do), feel free to poke + * the person with blame on this comment with questions. :-) + * + * Ideally this would be in TypeTraits.h, but C++11 omitted std::is_null_pointer + * (fixed in C++1y), so in the interests of easing a switch to , + * this trait lives elsewhere. */ +template +struct IsNullPointer { static const bool value = false; }; -#ifndef MOZ_HAVE_CXX11_NULLPTR -# if defined(__GNUC__) -# define nullptr __null -# elif defined(_WIN64) -# define nullptr 0LL -# else -# define nullptr 0L -# endif +} // namespace mozilla + +/** + * mozilla::NullptrT is a type that's sort of like decltype(nullptr). But it + * can't be identical, because emulated nullptr doesn't have a distinct type. + * Only with gcc 4.4/4.5, emulated nullptr is __null, and decltype(__null) is + * int or long. But passing __null to an int/long parameter triggers + * -Werror=conversion-null errors with gcc 4.5, or (depending on subsequent use + * inside the overloaded function) can trigger pointer-to-integer comparison + * compiler errors. So fairly often, actually, NullptrT is *not* what you want. + * + * Instead, often you should use template-based overloading in concert with + * SFINAE to add a nullptr overload -- see the comments by IsNullPointer. + * + * So when *should* you use NullptrT? Thus far, the only truly good use seems + * to be as an argument type for operator overloads (because C++ doesn't allow + * operator= to have more than one argument, operator== to have more than two, + * &c.). But even in such cases, it really only works if there are no other + * overloads of the operator that accept a pointer type. If you want both T* + * and nullptr_t overloads, you'll have to wait til we drop gcc 4.4/4.5 support. + * (Currently b2g is the only impediment to this.) + */ +#ifdef MOZ_HAVE_CXX11_NULLPTR +// decltype does the right thing for actual nullptr. +namespace mozilla { +typedef decltype(nullptr) NullptrT; +template<> +struct IsNullPointer { static const bool value = true; }; +} +# undef MOZ_HAVE_CXX11_NULLPTR +#elif MOZ_IS_GCC +# define nullptr __null +// void* sweeps up more than just nullptr, but compilers supporting true +// nullptr are the majority now, so they should detect mistakes. If you're +// feeling paranoid, check/assert that your NullptrT equals nullptr. +namespace mozilla { typedef void* NullptrT; } +#else +# error "No compiler support for nullptr or its emulation." #endif #endif /* mozilla_NullPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/NumericLimits.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/NumericLimits.h index d2ee29813e..730fcb410b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/NumericLimits.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/NumericLimits.h @@ -17,10 +17,10 @@ namespace mozilla { /** - * The NumericLimits class provides a compatibility layer with std::numeric_limits - * for char16_t, otherwise it is exactly the same as std::numeric_limits. - * Code which does not need std::numeric_limits should avoid using - * NumericLimits. + * The NumericLimits class provides a compatibility layer with + * std::numeric_limits for char16_t, otherwise it is exactly the same as + * std::numeric_limits. Code which does not need std::numeric_limits + * should avoid using NumericLimits. */ template class NumericLimits : public std::numeric_limits diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Pair.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Pair.h new file mode 100644 index 0000000000..e9e8a76938 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Pair.h @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A class holding a pair of objects that tries to conserve storage space. */ + +#ifndef mozilla_Pair_h +#define mozilla_Pair_h + +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +namespace detail { + +enum StorageType { AsBase, AsMember }; + +// Optimize storage using the Empty Base Optimization -- that empty base classes +// don't take up space -- to optimize size when one or the other class is +// stateless and can be used as a base class. +// +// The extra conditions on storage for B are necessary so that PairHelper won't +// ambiguously inherit from either A or B, such that one or the other base class +// would be inaccessible. +template::value ? detail::AsBase : detail::AsMember, + detail::StorageType = + IsEmpty::value && !IsBaseOf::value && !IsBaseOf::value + ? detail::AsBase + : detail::AsMember> +struct PairHelper; + +template +struct PairHelper +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : mFirstA(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(mSecondB, aOther.mSecondB); + } + +private: + A mFirstA; + B mSecondB; +}; + +template +struct PairHelper : private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : B(Forward(aB)), + mFirstA(Forward(aA)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return *this; } + const B& second() const { return *this; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(static_cast(*this), static_cast(aOther)); + } + +private: + A mFirstA; +}; + +template +struct PairHelper : private A +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return *this; } + const A& first() const { return *this; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(mSecondB, aOther.mSecondB); + } + +private: + B mSecondB; +}; + +template +struct PairHelper : private A, private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + B(Forward(aB)) + {} + + A& first() { return static_cast(*this); } + const A& first() const { return static_cast(*this); } + B& second() { return static_cast(*this); } + const B& second() const { return static_cast(*this); } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(static_cast(*this), static_cast(aOther)); + } +}; + +} // namespace detail + +/** + * Pair is the logical concatenation of an instance of A with an instance B. + * Space is conserved when possible. Neither A nor B may be a final class. + * + * It's typically clearer to have individual A and B member fields. Except if + * you want the space-conserving qualities of Pair, you're probably better off + * not using this! + * + * No guarantees are provided about the memory layout of A and B, the order of + * initialization or destruction of A and B, and so on. (This is approximately + * required to optimize space usage.) The first/second names are merely + * conceptual! + */ +template +struct Pair + : private detail::PairHelper +{ + typedef typename detail::PairHelper Base; + +public: + template + Pair(AArg&& aA, BArg&& aB) + : Base(Forward(aA), Forward(aB)) + {} + + /** The A instance. */ + using Base::first; + /** The B instance. */ + using Base::second; + + /** Swap this pair with another pair. */ + void swap(Pair& aOther) { Base::swap(aOther); } + +private: + Pair(const Pair&) MOZ_DELETE; +}; + +template +void +Swap(Pair& aX, Pair& aY) +{ + aX.swap(aY); +} + +} // namespace mozilla + +#endif /* mozilla_Pair_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/PodOperations.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/PodOperations.h index adbf2e699d..843e1311d3 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/PodOperations.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/PodOperations.h @@ -24,26 +24,27 @@ namespace mozilla { -/** Set the contents of |t| to 0. */ +/** Set the contents of |aT| to 0. */ template static MOZ_ALWAYS_INLINE void -PodZero(T* t) +PodZero(T* aT) { - memset(t, 0, sizeof(T)); + memset(aT, 0, sizeof(T)); } -/** Set the contents of |nelem| elements starting at |t| to 0. */ +/** Set the contents of |aNElem| elements starting at |aT| to 0. */ template static MOZ_ALWAYS_INLINE void -PodZero(T* t, size_t nelem) +PodZero(T* aT, size_t aNElem) { /* - * This function is often called with 'nelem' small; we use an inline loop + * This function is often called with 'aNElem' small; we use an inline loop * instead of calling 'memset' with a non-constant length. The compiler * should inline the memset call with constant size, though. */ - for (T* end = t + nelem; t < end; t++) - memset(t, 0, sizeof(T)); + for (T* end = aT + aNElem; aT < end; aT++) { + memset(aT, 0, sizeof(T)); + } } /* @@ -54,107 +55,116 @@ PodZero(T* t, size_t nelem) * compile error involving PodZero and array types, use PodArrayZero instead. */ template -static void PodZero(T (&t)[N]) MOZ_DELETE; +static void PodZero(T (&aT)[N]) MOZ_DELETE; template -static void PodZero(T (&t)[N], size_t nelem) MOZ_DELETE; +static void PodZero(T (&aT)[N], size_t aNElem) MOZ_DELETE; -/** Set the contents of the array |t| to zero. */ +/** Set the contents of the array |aT| to zero. */ template static MOZ_ALWAYS_INLINE void -PodArrayZero(T (&t)[N]) +PodArrayZero(T (&aT)[N]) { - memset(t, 0, N * sizeof(T)); + memset(aT, 0, N * sizeof(T)); } template static MOZ_ALWAYS_INLINE void -PodArrayZero(Array& arr) +PodArrayZero(Array& aArr) { - memset(&arr[0], 0, N * sizeof(T)); + memset(&aArr[0], 0, N * sizeof(T)); } /** - * Assign |*src| to |*dst|. The locations must not be the same and must not + * Assign |*aSrc| to |*aDst|. The locations must not be the same and must not * overlap. */ template static MOZ_ALWAYS_INLINE void -PodAssign(T* dst, const T* src) +PodAssign(T* aDst, const T* aSrc) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, PointerRangeSize(src, static_cast(dst)) >= 1); - MOZ_ASSERT_IF(dst < src, PointerRangeSize(static_cast(dst), src) >= 1); - memcpy(reinterpret_cast(dst), reinterpret_cast(src), sizeof(T)); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= 1); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= 1); + memcpy(reinterpret_cast(aDst), reinterpret_cast(aSrc), + sizeof(T)); } /** - * Copy |nelem| T elements from |src| to |dst|. The two memory ranges must not - * overlap! + * Copy |aNElem| T elements from |aSrc| to |aDst|. The two memory ranges must + * not overlap! */ template static MOZ_ALWAYS_INLINE void -PodCopy(T* dst, const T* src, size_t nelem) +PodCopy(T* aDst, const T* aSrc, size_t aNElem) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, PointerRangeSize(src, static_cast(dst)) >= nelem); - MOZ_ASSERT_IF(dst < src, PointerRangeSize(static_cast(dst), src) >= nelem); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); - if (nelem < 128) { + if (aNElem < 128) { /* * Avoid using operator= in this loop, as it may have been * intentionally deleted by the POD type. */ - for (const T* srcend = src + nelem; src < srcend; src++, dst++) - PodAssign(dst, src); + for (const T* srcend = aSrc + aNElem; aSrc < srcend; aSrc++, aDst++) { + PodAssign(aDst, aSrc); + } } else { - memcpy(dst, src, nelem * sizeof(T)); + memcpy(aDst, aSrc, aNElem * sizeof(T)); } } template static MOZ_ALWAYS_INLINE void -PodCopy(volatile T* dst, const volatile T* src, size_t nelem) +PodCopy(volatile T* aDst, const volatile T* aSrc, size_t aNElem) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, - PointerRangeSize(src, static_cast(dst)) >= nelem); - MOZ_ASSERT_IF(dst < src, - PointerRangeSize(static_cast(dst), src) >= nelem); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); /* - * Volatile |dst| requires extra work, because it's undefined behavior to + * Volatile |aDst| requires extra work, because it's undefined behavior to * modify volatile objects using the mem* functions. Just write out the * loops manually, using operator= rather than memcpy for the same reason, * and let the compiler optimize to the extent it can. */ - for (const volatile T* srcend = src + nelem; src < srcend; src++, dst++) - *dst = *src; + for (const volatile T* srcend = aSrc + aNElem; + aSrc < srcend; + aSrc++, aDst++) { + *aDst = *aSrc; + } } /* - * Copy the contents of the array |src| into the array |dst|, both of size N. + * Copy the contents of the array |aSrc| into the array |aDst|, both of size N. * The arrays must not overlap! */ template static MOZ_ALWAYS_INLINE void -PodArrayCopy(T (&dst)[N], const T (&src)[N]) +PodArrayCopy(T (&aDst)[N], const T (&aSrc)[N]) { - PodCopy(dst, src, N); + PodCopy(aDst, aSrc, N); } /** - * Copy the memory for |nelem| T elements from |src| to |dst|. If the two - * memory ranges overlap, then the effect is as if the |nelem| elements are - * first copied from |src| to a temporary array, and then from the temporary - * array to |dst|. + * Copy the memory for |aNElem| T elements from |aSrc| to |aDst|. If the two + * memory ranges overlap, then the effect is as if the |aNElem| elements are + * first copied from |aSrc| to a temporary array, and then from the temporary + * array to |aDst|. */ template static MOZ_ALWAYS_INLINE void -PodMove(T* dst, const T* src, size_t nelem) +PodMove(T* aDst, const T* aSrc, size_t aNElem) { - MOZ_ASSERT(nelem <= SIZE_MAX / sizeof(T), + MOZ_ASSERT(aNElem <= SIZE_MAX / sizeof(T), "trying to move an impossible number of elements"); - memmove(dst, src, nelem * sizeof(T)); + memmove(aDst, aSrc, aNElem * sizeof(T)); } /** @@ -170,8 +180,9 @@ PodEqual(const T* one, const T* two, size_t len) const T* p1 = one; const T* p2 = two; for (; p1 < p1end; p1++, p2++) { - if (*p1 != *p2) + if (*p1 != *p2) { return false; + } } return true; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Range.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Range.h index 4e02d962b5..814a2821ad 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Range.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Range.h @@ -18,32 +18,26 @@ namespace mozilla { template class Range { - RangedPtr mStart; - RangedPtr mEnd; + const RangedPtr mStart; + const RangedPtr mEnd; - typedef void (Range::* ConvertibleToBool)(); - void nonNull() {} + typedef void (Range::* ConvertibleToBool)(); + void nonNull() {} - public: - Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} - Range(T* p, size_t len) - : mStart(p, p, p + len), - mEnd(p + len, p, p + len) - {} +public: + Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} + Range(T* aPtr, size_t aLength) + : mStart(aPtr, aPtr, aPtr + aLength), + mEnd(aPtr + aLength, aPtr, aPtr + aLength) + {} - RangedPtr start() const { return mStart; } - RangedPtr end() const { return mEnd; } - size_t length() const { return mEnd - mStart; } + RangedPtr start() const { return mStart; } + RangedPtr end() const { return mEnd; } + size_t length() const { return mEnd - mStart; } - T& operator[](size_t offset) { - return mStart[offset]; - } + T& operator[](size_t aOffset) const { return mStart[aOffset]; } - const T& operator[](size_t offset) const { - return mStart[offset]; - } - - operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } + operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RangedPtr.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RangedPtr.h index 561e564ded..4d94035b90 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RangedPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RangedPtr.h @@ -43,214 +43,240 @@ namespace mozilla { template class RangedPtr { - T* ptr; + T* mPtr; #ifdef DEBUG - T* const rangeStart; - T* const rangeEnd; + T* const mRangeStart; + T* const mRangeEnd; #endif - typedef void (RangedPtr::* ConvertibleToBool)(); - void nonNull() {} + typedef void (RangedPtr::* ConvertibleToBool)(); + void nonNull() {} - void checkSanity() { - MOZ_ASSERT(rangeStart <= ptr); - MOZ_ASSERT(ptr <= rangeEnd); - } + void checkSanity() + { + MOZ_ASSERT(mRangeStart <= mPtr); + MOZ_ASSERT(mPtr <= mRangeEnd); + } - /* Creates a new pointer for |p|, restricted to this pointer's range. */ - RangedPtr create(T *p) const { + /* Creates a new pointer for |aPtr|, restricted to this pointer's range. */ + RangedPtr create(T* aPtr) const + { #ifdef DEBUG - return RangedPtr(p, rangeStart, rangeEnd); + return RangedPtr(aPtr, mRangeStart, mRangeEnd); #else - return RangedPtr(p, nullptr, size_t(0)); + return RangedPtr(aPtr, nullptr, size_t(0)); #endif - } + } - uintptr_t asUintptr() const { return uintptr_t(ptr); } + uintptr_t asUintptr() const { return reinterpret_cast(mPtr); } - public: - RangedPtr(T* p, T* start, T* end) - : ptr(p) +public: + RangedPtr(T* aPtr, T* aStart, T* aEnd) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(start), rangeEnd(end) + , mRangeStart(aStart), mRangeEnd(aEnd) #endif - { - MOZ_ASSERT(rangeStart <= rangeEnd); - checkSanity(); - } - RangedPtr(T* p, T* start, size_t length) - : ptr(p) + { + MOZ_ASSERT(mRangeStart <= mRangeEnd); + checkSanity(); + } + RangedPtr(T* aPtr, T* aStart, size_t aLength) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(start), rangeEnd(start + length) + , mRangeStart(aStart), mRangeEnd(aStart + aLength) #endif - { - MOZ_ASSERT(length <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(uintptr_t(rangeStart) + length * sizeof(T) >= uintptr_t(rangeStart)); - checkSanity(); - } - - /* Equivalent to RangedPtr(p, p, length). */ - RangedPtr(T* p, size_t length) - : ptr(p) + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aPtr, aPtr, aLength). */ + RangedPtr(T* aPtr, size_t aLength) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(p), rangeEnd(p + length) + , mRangeStart(aPtr), mRangeEnd(aPtr + aLength) #endif - { - MOZ_ASSERT(length <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(uintptr_t(rangeStart) + length * sizeof(T) >= uintptr_t(rangeStart)); - checkSanity(); - } - - /* Equivalent to RangedPtr(arr, arr, N). */ - template - RangedPtr(T (&arr)[N]) - : ptr(arr) + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aArr, aArr, N). */ + template + RangedPtr(T (&aArr)[N]) + : mPtr(aArr) #ifdef DEBUG - , rangeStart(arr), rangeEnd(arr + N) + , mRangeStart(aArr), mRangeEnd(aArr + N) #endif - { - checkSanity(); - } - - T* get() const { - return ptr; - } - - operator ConvertibleToBool() const { return ptr ? &RangedPtr::nonNull : 0; } - - /* - * You can only assign one RangedPtr into another if the two pointers have - * the same valid range: - * - * char arr1[] = "hi"; - * char arr2[] = "bye"; - * RangedPtr p1(arr1, 2); - * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works - * p1 = RangedPtr(arr2, 3); // asserts - */ - RangedPtr& operator=(const RangedPtr& other) { - MOZ_ASSERT(rangeStart == other.rangeStart); - MOZ_ASSERT(rangeEnd == other.rangeEnd); - ptr = other.ptr; - checkSanity(); - return *this; - } - - RangedPtr operator+(size_t inc) { - MOZ_ASSERT(inc <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(asUintptr() + inc * sizeof(T) >= asUintptr()); - return create(ptr + inc); - } - - RangedPtr operator-(size_t dec) { - MOZ_ASSERT(dec <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(asUintptr() - dec * sizeof(T) <= asUintptr()); - return create(ptr - dec); - } - - /* - * You can assign a raw pointer into a RangedPtr if the raw pointer is - * within the range specified at creation. - */ - template - RangedPtr& operator=(U* p) { - *this = create(p); - return *this; - } - - template - RangedPtr& operator=(const RangedPtr& p) { - MOZ_ASSERT(rangeStart <= p.ptr); - MOZ_ASSERT(p.ptr <= rangeEnd); - ptr = p.ptr; - checkSanity(); - return *this; - } - - RangedPtr& operator++() { - return (*this += 1); - } - - RangedPtr operator++(int) { - RangedPtr rcp = *this; - ++*this; - return rcp; - } - - RangedPtr& operator--() { - return (*this -= 1); - } - - RangedPtr operator--(int) { - RangedPtr rcp = *this; - --*this; - return rcp; - } - - RangedPtr& operator+=(size_t inc) { - *this = *this + inc; - return *this; - } - - RangedPtr& operator-=(size_t dec) { - *this = *this - dec; - return *this; - } - - T& operator[](int index) const { - MOZ_ASSERT(size_t(index > 0 ? index : -index) <= size_t(-1) / sizeof(T)); - return *create(ptr + index); - } - - T& operator*() const { - return *ptr; - } - - template - bool operator==(const RangedPtr& other) const { - return ptr == other.ptr; - } - template - bool operator!=(const RangedPtr& other) const { - return !(*this == other); - } - - template - bool operator==(const U* u) const { - return ptr == u; - } - template - bool operator!=(const U* u) const { - return !(*this == u); - } - - template - bool operator<(const RangedPtr& other) const { - return ptr < other.ptr; - } - template - bool operator<=(const RangedPtr& other) const { - return ptr <= other.ptr; - } - - template - bool operator>(const RangedPtr& other) const { - return ptr > other.ptr; - } - template - bool operator>=(const RangedPtr& other) const { - return ptr >= other.ptr; - } - - size_t operator-(const RangedPtr& other) const { - MOZ_ASSERT(ptr >= other.ptr); - return PointerRangeSize(other.ptr, ptr); - } - - private: - RangedPtr() MOZ_DELETE; - T* operator&() MOZ_DELETE; + { + checkSanity(); + } + + T* get() const { return mPtr; } + + operator ConvertibleToBool() const { return mPtr ? &RangedPtr::nonNull : 0; } + + /* + * You can only assign one RangedPtr into another if the two pointers have + * the same valid range: + * + * char arr1[] = "hi"; + * char arr2[] = "bye"; + * RangedPtr p1(arr1, 2); + * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works + * p1 = RangedPtr(arr2, 3); // asserts + */ + RangedPtr& operator=(const RangedPtr& aOther) + { + MOZ_ASSERT(mRangeStart == aOther.mRangeStart); + MOZ_ASSERT(mRangeEnd == aOther.mRangeEnd); + mPtr = aOther.mPtr; + checkSanity(); + return *this; + } + + RangedPtr operator+(size_t aInc) + { + MOZ_ASSERT(aInc <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() + aInc * sizeof(T) >= asUintptr()); + return create(mPtr + aInc); + } + + RangedPtr operator-(size_t aDec) + { + MOZ_ASSERT(aDec <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() - aDec * sizeof(T) <= asUintptr()); + return create(mPtr - aDec); + } + + /* + * You can assign a raw pointer into a RangedPtr if the raw pointer is + * within the range specified at creation. + */ + template + RangedPtr& operator=(U* aPtr) + { + *this = create(aPtr); + return *this; + } + + template + RangedPtr& operator=(const RangedPtr& aPtr) + { + MOZ_ASSERT(mRangeStart <= aPtr.mPtr); + MOZ_ASSERT(aPtr.mPtr <= mRangeEnd); + mPtr = aPtr.mPtr; + checkSanity(); + return *this; + } + + RangedPtr& operator++() + { + return (*this += 1); + } + + RangedPtr operator++(int) + { + RangedPtr rcp = *this; + ++*this; + return rcp; + } + + RangedPtr& operator--() + { + return (*this -= 1); + } + + RangedPtr operator--(int) + { + RangedPtr rcp = *this; + --*this; + return rcp; + } + + RangedPtr& operator+=(size_t aInc) + { + *this = *this + aInc; + return *this; + } + + RangedPtr& operator-=(size_t aDec) + { + *this = *this - aDec; + return *this; + } + + T& operator[](int aIndex) const + { + MOZ_ASSERT(size_t(aIndex > 0 ? aIndex : -aIndex) <= size_t(-1) / sizeof(T)); + return *create(mPtr + aIndex); + } + + T& operator*() const + { + MOZ_ASSERT(mPtr >= mRangeStart); + MOZ_ASSERT(mPtr < mRangeEnd); + return *mPtr; + } + + template + bool operator==(const RangedPtr& aOther) const + { + return mPtr == aOther.mPtr; + } + template + bool operator!=(const RangedPtr& aOther) const + { + return !(*this == aOther); + } + + template + bool operator==(const U* u) const + { + return mPtr == u; + } + template + bool operator!=(const U* u) const + { + return !(*this == u); + } + + template + bool operator<(const RangedPtr& aOther) const + { + return mPtr < aOther.mPtr; + } + template + bool operator<=(const RangedPtr& aOther) const + { + return mPtr <= aOther.mPtr; + } + + template + bool operator>(const RangedPtr& aOther) const + { + return mPtr > aOther.mPtr; + } + template + bool operator>=(const RangedPtr& aOther) const + { + return mPtr >= aOther.mPtr; + } + + size_t operator-(const RangedPtr& aOther) const + { + MOZ_ASSERT(mPtr >= aOther.mPtr); + return PointerRangeSize(aOther.mPtr, mPtr); + } + +private: + RangedPtr() MOZ_DELETE; + T* operator&() MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ReentrancyGuard.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ReentrancyGuard.h index d589f368a2..557c61015e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ReentrancyGuard.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ReentrancyGuard.h @@ -18,38 +18,38 @@ namespace mozilla { /* Useful for implementing containers that assert non-reentrancy */ class ReentrancyGuard { - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER #ifdef DEBUG - bool& entered; + bool& mEntered; #endif - public: - template +public: + template #ifdef DEBUG - ReentrancyGuard(T& obj - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : entered(obj.entered) + ReentrancyGuard(T& aObj + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mEntered(aObj.mEntered) #else - ReentrancyGuard(T& - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + ReentrancyGuard(T& + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) #endif - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; #ifdef DEBUG - MOZ_ASSERT(!entered); - entered = true; + MOZ_ASSERT(!mEntered); + mEntered = true; #endif - } - ~ReentrancyGuard() - { + } + ~ReentrancyGuard() + { #ifdef DEBUG - entered = false; + mEntered = false; #endif - } + } - private: - ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; - void operator=(const ReentrancyGuard&) MOZ_DELETE; +private: + ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; + void operator=(const ReentrancyGuard&) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RefCountType.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RefCountType.h new file mode 100644 index 0000000000..e95a22a0ca --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RefCountType.h @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_RefCountType_h +#define mozilla_RefCountType_h + +#include + +/** + * MozRefCountType is Mozilla's reference count type. + * + * We use the same type to represent the refcount of RefCounted objects + * as well, in order to be able to use the leak detection facilities + * that are implemented by XPCOM. + * + * Note that this type is not in the mozilla namespace so that it is + * usable for both C and C++ code. + */ +typedef uintptr_t MozRefCountType; + +/* + * This is the return type for AddRef() and Release() in nsISupports. + * IUnknown of COM returns an unsigned long from equivalent functions. + * + * The following ifdef exists to maintain binary compatibility with + * IUnknown, the base interface in Microsoft COM. + */ +#ifdef XP_WIN +typedef unsigned long MozExternalRefCountType; +#else +typedef uint32_t MozExternalRefCountType; +#endif + +#endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RefPtr.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RefPtr.h index 72c7904554..4901067b4c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RefPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RefPtr.h @@ -12,7 +12,17 @@ #include "mozilla/Assertions.h" #include "mozilla/Atomics.h" #include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" +#include "mozilla/RefCountType.h" #include "mozilla/TypeTraits.h" +#if defined(MOZILLA_INTERNAL_API) +#include "nsXPCOM.h" +#endif + +#if defined(MOZILLA_INTERNAL_API) && \ + (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) +#define MOZ_REFCOUNTED_LEAK_CHECKING +#endif namespace mozilla { @@ -42,10 +52,37 @@ template OutParamRef byRef(RefPtr&); * state is represented in DEBUG builds by refcount==0xffffdead. This * state distinguishes use-before-ref (refcount==0) from * use-after-destroy (refcount==0xffffdead). + * + * Note that when deriving from RefCounted or AtomicRefCounted, you + * should add MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public + * section of your class, where ClassName is the name of your class. */ namespace detail { #ifdef DEBUG -static const int DEAD = 0xffffdead; +const MozRefCountType DEAD = 0xffffdead; +#endif + +// When building code that gets compiled into Gecko, try to use the +// trace-refcount leak logging facilities. +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +class RefCountLogger +{ +public: + static void logAddRef(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName, uint32_t aInstanceSize) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogAddRef(const_cast(aPointer), aRefCount, aTypeName, + aInstanceSize); + } + + static void logRelease(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogRelease(const_cast(aPointer), aRefCount, aTypeName); + } +}; #endif // This is used WeakPtr.h as well as this file. @@ -58,70 +95,122 @@ enum RefCountAtomicity template class RefCounted { - friend class RefPtr; + friend class RefPtr; - protected: - RefCounted() : refCnt(0) { } - ~RefCounted() { - MOZ_ASSERT(refCnt == detail::DEAD); - } +protected: + RefCounted() : mRefCnt(0) {} + ~RefCounted() { MOZ_ASSERT(mRefCnt == detail::DEAD); } - public: - // Compatibility with nsRefPtr. - void AddRef() const { - MOZ_ASSERT(refCnt >= 0); - ++refCnt; - } +public: + // Compatibility with nsRefPtr. + void AddRef() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) >= 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + ++mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + uint32_t size = static_cast(this)->typeSize(); + const void* ptr = static_cast(this); + MozRefCountType cnt = ++mRefCnt; + detail::RefCountLogger::logAddRef(ptr, cnt, type, size); +#endif + } - void Release() const { - MOZ_ASSERT(refCnt > 0); - if (0 == --refCnt) { + void Release() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) > 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + MozRefCountType cnt = --mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + const void* ptr = static_cast(this); + MozRefCountType cnt = --mRefCnt; + // Note: it's not safe to touch |this| after decrementing the refcount, + // except for below. + detail::RefCountLogger::logRelease(ptr, cnt, type); +#endif + if (0 == cnt) { + // Because we have atomically decremented the refcount above, only + // one thread can get a 0 count here, so as long as we can assume that + // everything else in the system is accessing this object through + // RefPtrs, it's safe to access |this| here. #ifdef DEBUG - refCnt = detail::DEAD; + mRefCnt = detail::DEAD; #endif - delete static_cast(this); - } + delete static_cast(this); } + } - // Compatibility with wtf::RefPtr. - void ref() { AddRef(); } - void deref() { Release(); } - int refCount() const { return refCnt; } - bool hasOneRef() const { - MOZ_ASSERT(refCnt > 0); - return refCnt == 1; - } + // Compatibility with wtf::RefPtr. + void ref() { AddRef(); } + void deref() { Release(); } + MozRefCountType refCount() const { return mRefCnt; } + bool hasOneRef() const + { + MOZ_ASSERT(mRefCnt > 0); + return mRefCnt == 1; + } - private: - mutable typename Conditional, int>::Type refCnt; +private: + mutable typename Conditional, + MozRefCountType>::Type mRefCnt; }; -} +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) \ + virtual const char* typeName() const { return #T; } \ + virtual size_t typeSize() const { return sizeof(*this); } +#else +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) +#endif + +// Note that this macro is expanded unconditionally because it declares only +// two small inline functions which will hopefully get eliminated by the linker +// in non-leak-checking builds. +#define MOZ_DECLARE_REFCOUNTED_TYPENAME(T) \ + const char* typeName() const { return #T; } \ + size_t typeSize() const { return sizeof(*this); } + +} // namespace detail template class RefCounted : public detail::RefCounted { - public: - ~RefCounted() { - static_assert(IsBaseOf::value, - "T must derive from RefCounted"); - } +public: + ~RefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from RefCounted"); + } }; +namespace external { + /** * AtomicRefCounted is like RefCounted, with an atomically updated * reference counter. + * + * NOTE: Please do not use this class, use NS_INLINE_DECL_THREADSAFE_REFCOUNTING + * instead. */ template -class AtomicRefCounted : public detail::RefCounted +class AtomicRefCounted : + public mozilla::detail::RefCounted { - public: - ~AtomicRefCounted() { - static_assert(IsBaseOf::value, - "T must derive from AtomicRefCounted"); - } +public: + ~AtomicRefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from AtomicRefCounted"); + } }; +} // namespace external + /** * RefPtr points to a refcounted thing that has AddRef and Release * methods to increase/decrease the refcount, respectively. After a @@ -135,73 +224,83 @@ class AtomicRefCounted : public detail::RefCounted template class RefPtr { - // To allow them to use unref() - friend class TemporaryRef; - friend class OutParamRef; + // To allow them to use unref() + friend class TemporaryRef; + friend class OutParamRef; - struct DontRef {}; + struct DontRef {}; - public: - RefPtr() : ptr(0) { } - RefPtr(const RefPtr& o) : ptr(ref(o.ptr)) {} - RefPtr(const TemporaryRef& o) : ptr(o.drop()) {} - RefPtr(T* t) : ptr(ref(t)) {} +public: + RefPtr() : mPtr(0) {} + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.mPtr)) {} + MOZ_IMPLICIT RefPtr(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + MOZ_IMPLICIT RefPtr(T* aVal) : mPtr(ref(aVal)) {} - template - RefPtr(const RefPtr& o) : ptr(ref(o.get())) {} + template + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.get())) {} - ~RefPtr() { unref(ptr); } + ~RefPtr() { unref(mPtr); } - RefPtr& operator=(const RefPtr& o) { - assign(ref(o.ptr)); - return *this; - } - RefPtr& operator=(const TemporaryRef& o) { - assign(o.drop()); - return *this; - } - RefPtr& operator=(T* t) { - assign(ref(t)); - return *this; - } + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.mPtr)); + return *this; + } + RefPtr& operator=(const TemporaryRef& aOther) + { + assign(aOther.drop()); + return *this; + } + RefPtr& operator=(T* aVal) + { + assign(ref(aVal)); + return *this; + } - template - RefPtr& operator=(const RefPtr& o) { - assign(ref(o.get())); - return *this; - } + template + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.get())); + return *this; + } - TemporaryRef forget() { - T* tmp = ptr; - ptr = 0; - return TemporaryRef(tmp, DontRef()); - } + TemporaryRef forget() + { + T* tmp = mPtr; + mPtr = nullptr; + return TemporaryRef(tmp, DontRef()); + } - T* get() const { return ptr; } - operator T*() const { return ptr; } - T* operator->() const { return ptr; } - T& operator*() const { return *ptr; } - template - operator TemporaryRef() { return TemporaryRef(ptr); } - - private: - void assign(T* t) { - unref(ptr); - ptr = t; - } + T* get() const { return mPtr; } + operator T*() const { return mPtr; } + T* operator->() const { return mPtr; } + T& operator*() const { return *mPtr; } + template + operator TemporaryRef() { return TemporaryRef(mPtr); } + +private: + void assign(T* aVal) + { + unref(mPtr); + mPtr = aVal; + } - T* ptr; + T* mPtr; - static MOZ_ALWAYS_INLINE T* ref(T* t) { - if (t) - t->AddRef(); - return t; + static MOZ_ALWAYS_INLINE T* ref(T* aVal) + { + if (aVal) { + aVal->AddRef(); } + return aVal; + } - static MOZ_ALWAYS_INLINE void unref(T* t) { - if (t) - t->Release(); + static MOZ_ALWAYS_INLINE void unref(T* aVal) + { + if (aVal) { + aVal->Release(); } + } }; /** @@ -213,33 +312,34 @@ class RefPtr template class TemporaryRef { - // To allow it to construct TemporaryRef from a bare T* - friend class RefPtr; + // To allow it to construct TemporaryRef from a bare T* + friend class RefPtr; - typedef typename RefPtr::DontRef DontRef; + typedef typename RefPtr::DontRef DontRef; - public: - TemporaryRef(T* t) : ptr(RefPtr::ref(t)) {} - TemporaryRef(const TemporaryRef& o) : ptr(o.drop()) {} +public: + MOZ_IMPLICIT TemporaryRef(T* aVal) : mPtr(RefPtr::ref(aVal)) {} + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} - template - TemporaryRef(const TemporaryRef& o) : ptr(o.drop()) {} + template + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} - ~TemporaryRef() { RefPtr::unref(ptr); } + ~TemporaryRef() { RefPtr::unref(mPtr); } - T* drop() const { - T* tmp = ptr; - ptr = 0; - return tmp; - } + T* drop() const + { + T* tmp = mPtr; + mPtr = nullptr; + return tmp; + } - private: - TemporaryRef(T* t, const DontRef&) : ptr(t) {} +private: + TemporaryRef(T* aVal, const DontRef&) : mPtr(aVal) {} - mutable T* ptr; + mutable T* mPtr; - TemporaryRef() MOZ_DELETE; - void operator=(const TemporaryRef&) MOZ_DELETE; + TemporaryRef() MOZ_DELETE; + void operator=(const TemporaryRef&) MOZ_DELETE; }; /** @@ -259,24 +359,25 @@ class TemporaryRef template class OutParamRef { - friend OutParamRef byRef(RefPtr&); + friend OutParamRef byRef(RefPtr&); - public: - ~OutParamRef() { - RefPtr::unref(refPtr.ptr); - refPtr.ptr = tmp; - } +public: + ~OutParamRef() + { + RefPtr::unref(mRefPtr.mPtr); + mRefPtr.mPtr = mTmp; + } - operator T**() { return &tmp; } + operator T**() { return &mTmp; } - private: - OutParamRef(RefPtr& p) : refPtr(p), tmp(p.get()) {} +private: + explicit OutParamRef(RefPtr& p) : mRefPtr(p), mTmp(p.get()) {} - RefPtr& refPtr; - T* tmp; + RefPtr& mRefPtr; + T* mTmp; - OutParamRef() MOZ_DELETE; - OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; + OutParamRef() MOZ_DELETE; + OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; }; /** @@ -284,9 +385,9 @@ class OutParamRef */ template OutParamRef -byRef(RefPtr& ptr) +byRef(RefPtr& aPtr) { - return OutParamRef(ptr); + return OutParamRef(aPtr); } } // namespace mozilla @@ -301,19 +402,21 @@ using namespace mozilla; struct Foo : public RefCounted { - Foo() : dead(false) { } - ~Foo() { - MOZ_ASSERT(!dead); - dead = true; - numDestroyed++; + MOZ_DECLARE_REFCOUNTED_TYPENAME(Foo) + Foo() : mDead(false) {} + ~Foo() + { + MOZ_ASSERT(!mDead); + mDead = true; + sNumDestroyed++; } - bool dead; - static int numDestroyed; + bool mDead; + static int sNumDestroyed; }; -int Foo::numDestroyed; +int Foo::sNumDestroyed; -struct Bar : public Foo { }; +struct Bar : public Foo {}; TemporaryRef NewFoo() @@ -364,25 +467,25 @@ main(int argc, char** argv) // This should blow up // Foo* f = new Foo(); delete f; - MOZ_ASSERT(0 == Foo::numDestroyed); + MOZ_ASSERT(0 == Foo::sNumDestroyed); { RefPtr f = new Foo(); MOZ_ASSERT(f->refCount() == 1); } - MOZ_ASSERT(1 == Foo::numDestroyed); + MOZ_ASSERT(1 == Foo::sNumDestroyed); { RefPtr f1 = NewFoo(); RefPtr f2(NewFoo()); - MOZ_ASSERT(1 == Foo::numDestroyed); + MOZ_ASSERT(1 == Foo::sNumDestroyed); } - MOZ_ASSERT(3 == Foo::numDestroyed); + MOZ_ASSERT(3 == Foo::sNumDestroyed); { RefPtr b = NewBar(); - MOZ_ASSERT(3 == Foo::numDestroyed); + MOZ_ASSERT(3 == Foo::sNumDestroyed); } - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); { RefPtr f1; @@ -390,56 +493,56 @@ main(int argc, char** argv) f1 = new Foo(); RefPtr f2(f1); RefPtr f3 = f2; - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); } - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); } - MOZ_ASSERT(5 == Foo::numDestroyed); + MOZ_ASSERT(5 == Foo::sNumDestroyed); { RefPtr f = new Foo(); f.forget(); - MOZ_ASSERT(6 == Foo::numDestroyed); + MOZ_ASSERT(6 == Foo::sNumDestroyed); } { RefPtr f = new Foo(); GetNewFoo(byRef(f)); - MOZ_ASSERT(7 == Foo::numDestroyed); + MOZ_ASSERT(7 == Foo::sNumDestroyed); } - MOZ_ASSERT(8 == Foo::numDestroyed); + MOZ_ASSERT(8 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetPassedFoo(byRef(f)); - MOZ_ASSERT(8 == Foo::numDestroyed); + MOZ_ASSERT(8 == Foo::sNumDestroyed); } - MOZ_ASSERT(9 == Foo::numDestroyed); + MOZ_ASSERT(9 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetNewFoo(&f); - MOZ_ASSERT(10 == Foo::numDestroyed); + MOZ_ASSERT(10 == Foo::sNumDestroyed); } - MOZ_ASSERT(11 == Foo::numDestroyed); + MOZ_ASSERT(11 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetPassedFoo(&f); - MOZ_ASSERT(11 == Foo::numDestroyed); + MOZ_ASSERT(11 == Foo::sNumDestroyed); } - MOZ_ASSERT(12 == Foo::numDestroyed); + MOZ_ASSERT(12 == Foo::sNumDestroyed); { RefPtr f1 = new Bar(); } - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); { RefPtr f = GetNullFoo(); - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); } - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); return 0; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RollingMean.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RollingMean.h index 5caee3bc83..5add14c879 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RollingMean.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/RollingMean.h @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-w idth: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -12,9 +13,7 @@ #include "mozilla/TypeTraits.h" #include "mozilla/Vector.h" -#include #include -#include namespace mozilla { @@ -30,78 +29,85 @@ namespace mozilla { template class RollingMean { - private: - size_t mInsertIndex; - size_t mMaxValues; - Vector mValues; - S mTotal; - - public: - static_assert(!IsFloatingPoint::value, - "floating-point types are unsupported due to rounding " - "errors"); - - RollingMean(size_t aMaxValues) - : mInsertIndex(0), - mMaxValues(aMaxValues), - mTotal(0) - { - MOZ_ASSERT(aMaxValues > 0); - } - - RollingMean& operator=(RollingMean&& aOther) { - MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); - this->~RollingMean(); - new(this) RollingMean(aOther.mMaxValues); - mInsertIndex = aOther.mInsertIndex; - mTotal = aOther.mTotal; - mValues.swap(aOther.mValues); - return *this; - } - - /** - * Insert a value into the rolling mean. - */ - bool insert(T aValue) { - MOZ_ASSERT(mValues.length() <= mMaxValues); - - if (mValues.length() == mMaxValues) { - mTotal = mTotal - mValues[mInsertIndex] + aValue; - mValues[mInsertIndex] = aValue; - } else { - if (!mValues.append(aValue)) - return false; - mTotal = mTotal + aValue; +private: + size_t mInsertIndex; + size_t mMaxValues; + Vector mValues; + S mTotal; + +public: + static_assert(!IsFloatingPoint::value, + "floating-point types are unsupported due to rounding " + "errors"); + + explicit RollingMean(size_t aMaxValues) + : mInsertIndex(0), + mMaxValues(aMaxValues), + mTotal(0) + { + MOZ_ASSERT(aMaxValues > 0); + } + + RollingMean& operator=(RollingMean&& aOther) + { + MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); + this->~RollingMean(); + new(this) RollingMean(aOther.mMaxValues); + mInsertIndex = aOther.mInsertIndex; + mTotal = aOther.mTotal; + mValues.swap(aOther.mValues); + return *this; + } + + /** + * Insert a value into the rolling mean. + */ + bool insert(T aValue) + { + MOZ_ASSERT(mValues.length() <= mMaxValues); + + if (mValues.length() == mMaxValues) { + mTotal = mTotal - mValues[mInsertIndex] + aValue; + mValues[mInsertIndex] = aValue; + } else { + if (!mValues.append(aValue)) { + return false; } - - mInsertIndex = (mInsertIndex + 1) % mMaxValues; - return true; - } - - /** - * Calculate the rolling mean. - */ - T mean() { - MOZ_ASSERT(!empty()); - return T(mTotal / mValues.length()); - } - - bool empty() { - return mValues.empty(); + mTotal = mTotal + aValue; } - /** - * Remove all values from the rolling mean. - */ - void clear() { - mValues.clear(); - mInsertIndex = 0; - mTotal = T(0); - } - - size_t maxValues() { - return mMaxValues; - } + mInsertIndex = (mInsertIndex + 1) % mMaxValues; + return true; + } + + /** + * Calculate the rolling mean. + */ + T mean() + { + MOZ_ASSERT(!empty()); + return T(mTotal / mValues.length()); + } + + bool empty() + { + return mValues.empty(); + } + + /** + * Remove all values from the rolling mean. + */ + void clear() + { + mValues.clear(); + mInsertIndex = 0; + mTotal = T(0); + } + + size_t maxValues() + { + return mMaxValues; + } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/SHA1.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/SHA1.h index b167648540..ddccaa67e7 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/SHA1.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/SHA1.h @@ -36,25 +36,26 @@ namespace mozilla { */ class SHA1Sum { - union { - uint32_t w[16]; /* input buffer */ - uint8_t b[64]; - } u; - uint64_t size; /* count of hashed bytes. */ - unsigned H[22]; /* 5 state variables, 16 tmp values, 1 extra */ - bool mDone; - - public: - MFBT_API SHA1Sum(); - - static const size_t HashSize = 20; - typedef uint8_t Hash[HashSize]; - - /* Add len bytes of dataIn to the data sequence being hashed. */ - MFBT_API void update(const void* dataIn, uint32_t len); - - /* Compute the final hash of all data into hashOut. */ - MFBT_API void finish(SHA1Sum::Hash& hashOut); + union + { + uint32_t mW[16]; /* input buffer */ + uint8_t mB[64]; + } mU; + uint64_t mSize; /* count of hashed bytes. */ + unsigned mH[22]; /* 5 state variables, 16 tmp values, 1 extra */ + bool mDone; + +public: + MFBT_API SHA1Sum(); + + static const size_t kHashSize = 20; + typedef uint8_t Hash[kHashSize]; + + /* Add len bytes of dataIn to the data sequence being hashed. */ + MFBT_API void update(const void* aData, uint32_t aLength); + + /* Compute the final hash of all data into hashOut. */ + MFBT_API void finish(SHA1Sum::Hash& aHashOut); }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Scoped.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Scoped.h index fc48584b3e..3f854d6375 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Scoped.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Scoped.h @@ -52,8 +52,10 @@ * the scope, graphics contexts, etc. */ +#include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/GuardObjects.h" +#include "mozilla/Move.h" #include "mozilla/NullPtr.h" namespace mozilla { @@ -62,7 +64,8 @@ namespace mozilla { * Scoped is a helper to create RAII wrappers * Type argument |Traits| is expected to have the following structure: * - * struct Traits { + * struct Traits + * { * // Define the type of the value stored in the wrapper * typedef value_type type; * // Returns the value corresponding to the uninitialized or freed state @@ -75,84 +78,102 @@ namespace mozilla { template class Scoped { - public: - typedef typename Traits::type Resource; +public: + typedef typename Traits::type Resource; - explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) - : value(Traits::empty()) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - explicit Scoped(const Resource& v - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : value(v) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - ~Scoped() { - Traits::release(value); - } + explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + : mValue(Traits::empty()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } - // Constant getter - operator const Resource&() const { return value; } - const Resource& operator->() const { return value; } - const Resource& get() const { return value; } - // Non-constant getter. - Resource& rwget() { return value; } + explicit Scoped(const Resource& aValue + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(aValue) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } - /* - * Forget the resource. - * - * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will - * have no effect at destruction (unless it is reset to another resource by - * |operator=|). - * - * @return The original resource. - */ - Resource forget() { - Resource tmp = value; - value = Traits::empty(); - return tmp; - } + /* Move constructor. */ + explicit Scoped(Scoped&& aOther + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(Move(aOther.mValue)) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + aOther.mValue = Traits::empty(); + } - /* - * Perform immediate clean-up of this |Scoped|. - * - * If this |Scoped| is currently empty, this method has no effect. - */ - void dispose() { - Traits::release(value); - value = Traits::empty(); - } + ~Scoped() { Traits::release(mValue); } - bool operator==(const Resource& other) const { - return value == other; - } + // Constant getter + operator const Resource&() const { return mValue; } + const Resource& operator->() const { return mValue; } + const Resource& get() const { return mValue; } + // Non-constant getter. + Resource& rwget() { return mValue; } - /* - * Replace the resource with another resource. - * - * Calling |operator=| has the side-effect of triggering clean-up. If you do - * not want to trigger clean-up, you should first invoke |forget|. - * - * @return this - */ - Scoped& operator=(const Resource& other) { - return reset(other); - } - Scoped& reset(const Resource& other) { - Traits::release(value); - value = other; - return *this; - } + /* + * Forget the resource. + * + * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will + * have no effect at destruction (unless it is reset to another resource by + * |operator=|). + * + * @return The original resource. + */ + Resource forget() + { + Resource tmp = mValue; + mValue = Traits::empty(); + return tmp; + } + + /* + * Perform immediate clean-up of this |Scoped|. + * + * If this |Scoped| is currently empty, this method has no effect. + */ + void dispose() + { + Traits::release(mValue); + mValue = Traits::empty(); + } + + bool operator==(const Resource& aOther) const { return mValue == aOther; } + + /* + * Replace the resource with another resource. + * + * Calling |operator=| has the side-effect of triggering clean-up. If you do + * not want to trigger clean-up, you should first invoke |forget|. + * + * @return this + */ + Scoped& operator=(const Resource& aOther) { return reset(aOther); } + + Scoped& reset(const Resource& aOther) + { + Traits::release(mValue); + mValue = aOther; + return *this; + } + + /* Move assignment operator. */ + Scoped& operator=(Scoped&& aRhs) + { + MOZ_ASSERT(&aRhs != this, "self-move-assignment not allowed"); + this->~Scoped(); + new(this) Scoped(Move(aRhs)); + return *this; + } - private: - explicit Scoped(const Scoped& value) MOZ_DELETE; - Scoped& operator=(const Scoped& value) MOZ_DELETE; +private: + explicit Scoped(const Scoped& aValue) MOZ_DELETE; + Scoped& operator=(const Scoped& aValue) MOZ_DELETE; - private: - Resource value; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +private: + Resource mValue; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER }; /* @@ -163,26 +184,38 @@ class Scoped * @param Traits A struct implementing clean-up. See the implementations * for more details. */ -#define SCOPED_TEMPLATE(name, Traits) \ -template \ -struct name : public mozilla::Scoped > \ -{ \ - typedef mozilla::Scoped > Super; \ - typedef typename Super::Resource Resource; \ - name& operator=(Resource ptr) { \ - Super::operator=(ptr); \ - return *this; \ - } \ - explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ - : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ - {} \ - explicit name(Resource ptr \ - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ - : Super(ptr MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ - {} \ - private: \ - explicit name(name& source) MOZ_DELETE; \ - name& operator=(name& source) MOZ_DELETE; \ +#define SCOPED_TEMPLATE(name, Traits) \ +template \ +struct name : public mozilla::Scoped > \ +{ \ + typedef mozilla::Scoped > Super; \ + typedef typename Super::Resource Resource; \ + name& operator=(Resource aRhs) \ + { \ + Super::operator=(aRhs); \ + return *this; \ + } \ + name& operator=(name&& aRhs) \ + { \ + Super::operator=(Move(aRhs)); \ + return *this; \ + } \ + explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ + : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ + {} \ + explicit name(Resource aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ + explicit name(name&& aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(Move(aRhs) \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ +private: \ + explicit name(name&) MOZ_DELETE; \ + name& operator=(name&) MOZ_DELETE; \ }; /* @@ -195,9 +228,9 @@ struct name : public mozilla::Scoped > \ template struct ScopedFreePtrTraits { - typedef T* type; - static T* empty() { return nullptr; } - static void release(T* ptr) { free(ptr); } + typedef T* type; + static T* empty() { return nullptr; } + static void release(T* aPtr) { free(aPtr); } }; SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) @@ -210,7 +243,7 @@ SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) template struct ScopedDeletePtrTraits : public ScopedFreePtrTraits { - static void release(T* ptr) { delete ptr; } + static void release(T* aPtr) { delete aPtr; } }; SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) @@ -223,7 +256,7 @@ SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) template struct ScopedDeleteArrayTraits : public ScopedFreePtrTraits { - static void release(T* ptr) { delete [] ptr; } + static void release(T* aPtr) { delete [] aPtr; } }; SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) @@ -250,21 +283,22 @@ SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) * } // file is closed with PR_Close here */ #define MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(name, Type, Deleter) \ -template <> inline void TypeSpecificDelete(Type * value) { Deleter(value); } \ +template <> inline void TypeSpecificDelete(Type* aValue) { Deleter(aValue); } \ typedef ::mozilla::TypeSpecificScopedPointer name; -template void TypeSpecificDelete(T * value); +template void TypeSpecificDelete(T* aValue); template struct TypeSpecificScopedPointerTraits { - typedef T* type; - const static type empty() { return nullptr; } - const static void release(type value) - { - if (value) - TypeSpecificDelete(value); + typedef T* type; + static type empty() { return nullptr; } + static void release(type aValue) + { + if (aValue) { + TypeSpecificDelete(aValue); } + } }; SCOPED_TEMPLATE(TypeSpecificScopedPointer, TypeSpecificScopedPointerTraits) diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/SplayTree.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/SplayTree.h index 58ba5432b6..a6d692266f 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/SplayTree.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/SplayTree.h @@ -23,18 +23,20 @@ class SplayTree; template class SplayTreeNode { - public: - template - friend class SplayTree; - - SplayTreeNode() - : left(nullptr), right(nullptr), parent(nullptr) - {} - - private: - T* left; - T* right; - T* parent; +public: + template + friend class SplayTree; + + SplayTreeNode() + : mLeft(nullptr) + , mRight(nullptr) + , mParent(nullptr) + {} + +private: + T* mLeft; + T* mRight; + T* mParent; }; @@ -51,232 +53,242 @@ class SplayTreeNode template class SplayTree { - T* root; - T* freeList; + T* mRoot; - public: - SplayTree() - : root(nullptr), freeList(nullptr) - {} - - bool empty() const { - return !root; - } +public: + SplayTree() + : mRoot(nullptr) + {} - T* find(const T& v) - { - if (empty()) - return nullptr; + bool empty() const + { + return !mRoot; + } - T* last = lookup(v); - splay(last); - checkCoherency(root, nullptr); - return Comparator::compare(v, *last) == 0 ? last : nullptr; + T* find(const T& aValue) + { + if (empty()) { + return nullptr; } - bool insert(T* v) - { - MOZ_ASSERT(!find(*v), "Duplicate elements are not allowed."); - - if (!root) { - root = v; - return true; - } - T* last = lookup(*v); - int cmp = Comparator::compare(*v, *last); + T* last = lookup(aValue); + splay(last); + checkCoherency(mRoot, nullptr); + return Comparator::compare(aValue, *last) == 0 ? last : nullptr; + } - T** parentPointer = (cmp < 0) ? &last->left : &last->right; - MOZ_ASSERT(!*parentPointer); - *parentPointer = v; - v->parent = last; + bool insert(T* aValue) + { + MOZ_ASSERT(!find(*aValue), "Duplicate elements are not allowed."); - splay(v); - checkCoherency(root, nullptr); + if (!mRoot) { + mRoot = aValue; return true; } - - T* remove(const T& v) - { - T* last = lookup(v); - MOZ_ASSERT(last, "This tree must contain the element being removed."); - MOZ_ASSERT(Comparator::compare(v, *last) == 0); - - // Splay the tree so that the item to remove is the root. - splay(last); - MOZ_ASSERT(last == root); - - // Find another node which can be swapped in for the root: either the - // rightmost child of the root's left, or the leftmost child of the - // root's right. - T* swap; - T* swapChild; - if (root->left) { - swap = root->left; - while (swap->right) - swap = swap->right; - swapChild = swap->left; - } else if (root->right) { - swap = root->right; - while (swap->left) - swap = swap->left; - swapChild = swap->right; - } else { - T* result = root; - root = nullptr; - return result; - } - - // The selected node has at most one child, in swapChild. Detach it - // from the subtree by replacing it with that child. - if (swap == swap->parent->left) - swap->parent->left = swapChild; - else - swap->parent->right = swapChild; - if (swapChild) - swapChild->parent = swap->parent; - - // Make the selected node the new root. - root = swap; - root->parent = nullptr; - root->left = last->left; - root->right = last->right; - if (root->left) { - root->left->parent = root; + T* last = lookup(*aValue); + int cmp = Comparator::compare(*aValue, *last); + + T** parentPointer = (cmp < 0) ? &last->mLeft : &last->mRight; + MOZ_ASSERT(!*parentPointer); + *parentPointer = aValue; + aValue->mParent = last; + + splay(aValue); + checkCoherency(mRoot, nullptr); + return true; + } + + T* remove(const T& aValue) + { + T* last = lookup(aValue); + MOZ_ASSERT(last, "This tree must contain the element being removed."); + MOZ_ASSERT(Comparator::compare(aValue, *last) == 0); + + // Splay the tree so that the item to remove is the root. + splay(last); + MOZ_ASSERT(last == mRoot); + + // Find another node which can be swapped in for the root: either the + // rightmost child of the root's left, or the leftmost child of the + // root's right. + T* swap; + T* swapChild; + if (mRoot->mLeft) { + swap = mRoot->mLeft; + while (swap->mRight) { + swap = swap->mRight; } - if (root->right) { - root->right->parent = root; + swapChild = swap->mLeft; + } else if (mRoot->mRight) { + swap = mRoot->mRight; + while (swap->mLeft) { + swap = swap->mLeft; } - - checkCoherency(root, nullptr); - return last; + swapChild = swap->mRight; + } else { + T* result = mRoot; + mRoot = nullptr; + return result; } - T* removeMin() - { - MOZ_ASSERT(root, "No min to remove!"); - - T* min = root; - while (min->left) - min = min->left; - return remove(*min); + // The selected node has at most one child, in swapChild. Detach it + // from the subtree by replacing it with that child. + if (swap == swap->mParent->mLeft) { + swap->mParent->mLeft = swapChild; + } else { + swap->mParent->mRight = swapChild; } - - private: - /** - * Returns the node in this comparing equal to |v|, or a node just greater or - * just less than |v| if there is no such node. - */ - T* lookup(const T& v) - { - MOZ_ASSERT(!empty()); - - T* node = root; - T* parent; - do { - parent = node; - int c = Comparator::compare(v, *node); - if (c == 0) - return node; - else if (c < 0) - node = node->left; - else - node = node->right; - } while (node); - return parent; + if (swapChild) { + swapChild->mParent = swap->mParent; } - /** - * Rotate the tree until |node| is at the root of the tree. Performing - * the rotations in this fashion preserves the amortized balancing of - * the tree. - */ - void splay(T* node) - { - MOZ_ASSERT(node); - - while (node != root) { - T* parent = node->parent; - if (parent == root) { - // Zig rotation. - rotate(node); - MOZ_ASSERT(node == root); - return; - } - T* grandparent = parent->parent; - if ((parent->left == node) == (grandparent->left == parent)) { - // Zig-zig rotation. - rotate(parent); - rotate(node); - } else { - // Zig-zag rotation. - rotate(node); - rotate(node); - } - } + // Make the selected node the new root. + mRoot = swap; + mRoot->mParent = nullptr; + mRoot->mLeft = last->mLeft; + mRoot->mRight = last->mRight; + if (mRoot->mLeft) { + mRoot->mLeft->mParent = mRoot; } + if (mRoot->mRight) { + mRoot->mRight->mParent = mRoot; + } + + checkCoherency(mRoot, nullptr); + return last; + } - void rotate(T* node) - { - // Rearrange nodes so that node becomes the parent of its current - // parent, while preserving the sortedness of the tree. - T* parent = node->parent; - if (parent->left == node) { - // x y - // y c ==> a x - // a b b c - parent->left = node->right; - if (node->right) - node->right->parent = parent; - node->right = parent; + T* removeMin() + { + MOZ_ASSERT(mRoot, "No min to remove!"); + + T* min = mRoot; + while (min->mLeft) { + min = min->mLeft; + } + return remove(*min); + } + +private: + /** + * Returns the node in this comparing equal to |aValue|, or a node just + * greater or just less than |aValue| if there is no such node. + */ + T* lookup(const T& aValue) + { + MOZ_ASSERT(!empty()); + + T* node = mRoot; + T* parent; + do { + parent = node; + int c = Comparator::compare(aValue, *node); + if (c == 0) { + return node; + } else if (c < 0) { + node = node->mLeft; } else { - MOZ_ASSERT(parent->right == node); - // x y - // a y ==> x c - // b c a b - parent->right = node->left; - if (node->left) - node->left->parent = parent; - node->left = parent; + node = node->mRight; } - node->parent = parent->parent; - parent->parent = node; - if (T* grandparent = node->parent) { - if (grandparent->left == parent) - grandparent->left = node; - else - grandparent->right = node; + } while (node); + return parent; + } + + /** + * Rotate the tree until |node| is at the root of the tree. Performing + * the rotations in this fashion preserves the amortized balancing of + * the tree. + */ + void splay(T* aNode) + { + MOZ_ASSERT(aNode); + + while (aNode != mRoot) { + T* parent = aNode->mParent; + if (parent == mRoot) { + // Zig rotation. + rotate(aNode); + MOZ_ASSERT(aNode == mRoot); + return; + } + T* grandparent = parent->mParent; + if ((parent->mLeft == aNode) == (grandparent->mLeft == parent)) { + // Zig-zig rotation. + rotate(parent); + rotate(aNode); } else { - root = node; + // Zig-zag rotation. + rotate(aNode); + rotate(aNode); } } - - T* checkCoherency(T* node, T* minimum) - { -#ifdef DEBUG - MOZ_ASSERT_IF(root, !root->parent); - if (!node) { - MOZ_ASSERT(!root); - return nullptr; + } + + void rotate(T* aNode) + { + // Rearrange nodes so that aNode becomes the parent of its current + // parent, while preserving the sortedness of the tree. + T* parent = aNode->mParent; + if (parent->mLeft == aNode) { + // x y + // y c ==> a x + // a b b c + parent->mLeft = aNode->mRight; + if (aNode->mRight) { + aNode->mRight->mParent = parent; } - MOZ_ASSERT_IF(!node->parent, node == root); - MOZ_ASSERT_IF(minimum, Comparator::compare(*minimum, *node) < 0); - if (node->left) { - MOZ_ASSERT(node->left->parent == node); - T* leftMaximum = checkCoherency(node->left, minimum); - MOZ_ASSERT(Comparator::compare(*leftMaximum, *node) < 0); + aNode->mRight = parent; + } else { + MOZ_ASSERT(parent->mRight == aNode); + // x y + // a y ==> x c + // b c a b + parent->mRight = aNode->mLeft; + if (aNode->mLeft) { + aNode->mLeft->mParent = parent; } - if (node->right) { - MOZ_ASSERT(node->right->parent == node); - return checkCoherency(node->right, node); + aNode->mLeft = parent; + } + aNode->mParent = parent->mParent; + parent->mParent = aNode; + if (T* grandparent = aNode->mParent) { + if (grandparent->mLeft == parent) { + grandparent->mLeft = aNode; + } else { + grandparent->mRight = aNode; } - return node; -#else + } else { + mRoot = aNode; + } + } + + T* checkCoherency(T* aNode, T* aMinimum) + { +#ifdef DEBUG + MOZ_ASSERT_IF(mRoot, !mRoot->mParent); + if (!aNode) { + MOZ_ASSERT(!mRoot); return nullptr; -#endif } + MOZ_ASSERT_IF(!aNode->mParent, aNode == mRoot); + MOZ_ASSERT_IF(aMinimum, Comparator::compare(*aMinimum, *aNode) < 0); + if (aNode->mLeft) { + MOZ_ASSERT(aNode->mLeft->mParent == aNode); + T* leftMaximum = checkCoherency(aNode->mLeft, aMinimum); + MOZ_ASSERT(Comparator::compare(*leftMaximum, *aNode) < 0); + } + if (aNode->mRight) { + MOZ_ASSERT(aNode->mRight->mParent == aNode); + return checkCoherency(aNode->mRight, aNode); + } + return aNode; +#else + return nullptr; +#endif + } - SplayTree(const SplayTree&) MOZ_DELETE; - void operator=(const SplayTree&) MOZ_DELETE; + SplayTree(const SplayTree&) MOZ_DELETE; + void operator=(const SplayTree&) MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TaggedAnonymousMemory.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TaggedAnonymousMemory.h new file mode 100644 index 0000000000..d26b06dfb4 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TaggedAnonymousMemory.h @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Some Linux kernels -- specifically, newer versions of Android and +// some B2G devices -- have a feature for assigning names to ranges of +// anonymous memory (i.e., memory that doesn't have a "name" in the +// form of an underlying mapped file). These names are reported in +// /proc//smaps alongside system-level memory usage information +// such as Proportional Set Size (memory usage adjusted for sharing +// between processes), which allows reporting this information at a +// finer granularity than would otherwise be possible (e.g., +// separating malloc() heap from JS heap). +// +// Existing memory can be tagged with MozTagAnonymousMemory(); it will +// tag the range of complete pages containing the given interval, so +// the results may be inexact if the range isn't page-aligned. +// MozTaggedAnonymousMmap() can be used like mmap() with an extra +// parameter, and will tag the returned memory if the mapping was +// successful (and if it was in fact anonymous). +// +// NOTE: The pointer given as the "tag" argument MUST remain valid as +// long as the mapping exists. The referenced string is read when +// /proc//smaps or /proc//maps is read, not when the tag is +// established, so freeing it or changing its contents will have +// unexpected results. Using a static string is probably best. +// +// Also note that this header can be used by both C and C++ code. + +#ifndef mozilla_TaggedAnonymousMemory_h +#define mozilla_TaggedAnonymousMemory_h + +#ifndef XP_WIN + +#include +#include + +#include "mozilla/Types.h" + +#ifdef ANDROID + +#ifdef __cplusplus +extern "C" { +#endif + +MFBT_API void +MozTagAnonymousMemory(const void* aPtr, size_t aLength, const char* aTag); + +MFBT_API void* +MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt, int aFlags, + int aFd, off_t aOffset, const char* aTag); + +MFBT_API int +MozTaggedMemoryIsSupported(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#else // ANDROID + +static inline void +MozTagAnonymousMemory(const void* aPtr, size_t aLength, const char* aTag) +{ +} + +static inline void* +MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt, int aFlags, + int aFd, off_t aOffset, const char* aTag) +{ + return mmap(aAddr, aLength, aProt, aFlags, aFd, aOffset); +} + +static inline int +MozTaggedMemoryIsSupported(void) +{ + return 0; +} + +#endif // ANDROID + +#endif // !XP_WIN + +#endif // mozilla_TaggedAnonymousMemory_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TemplateLib.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TemplateLib.h index 50275fdadb..ea12c18b2b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TemplateLib.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TemplateLib.h @@ -28,19 +28,19 @@ namespace tl { template struct Min { - static const size_t value = I < J ? I : J; + static const size_t value = I < J ? I : J; }; template struct Max { - static const size_t value = I > J ? I : J; + static const size_t value = I > J ? I : J; }; /** Compute floor(log2(i)). */ template struct FloorLog2 { - static const size_t value = 1 + FloorLog2::value; + static const size_t value = 1 + FloorLog2::value; }; template<> struct FloorLog2<0> { /* Error */ }; template<> struct FloorLog2<1> { static const size_t value = 0; }; @@ -49,26 +49,26 @@ template<> struct FloorLog2<1> { static const size_t value = 0; }; template struct CeilingLog2 { - static const size_t value = FloorLog2<2 * I - 1>::value; + static const size_t value = FloorLog2<2 * I - 1>::value; }; /** Round up to the nearest power of 2. */ template struct RoundUpPow2 { - static const size_t value = size_t(1) << CeilingLog2::value; + static const size_t value = size_t(1) << CeilingLog2::value; }; template<> struct RoundUpPow2<0> { - static const size_t value = 1; + static const size_t value = 1; }; /** Compute the number of bits in the given unsigned type. */ template struct BitSize { - static const size_t value = sizeof(T) * CHAR_BIT; + static const size_t value = sizeof(T) * CHAR_BIT; }; /** @@ -78,17 +78,18 @@ struct BitSize template struct NBitMask { - // Assert the precondition. On success this evaluates to 0. Otherwise it - // triggers divide-by-zero at compile time: a guaranteed compile error in - // C++11, and usually one in C++98. Add this value to |value| to assure - // its computation. - static const size_t checkPrecondition = 0 / size_t(N < BitSize::value); - static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; + // Assert the precondition. On success this evaluates to 0. Otherwise it + // triggers divide-by-zero at compile time: a guaranteed compile error in + // C++11, and usually one in C++98. Add this value to |value| to assure + // its computation. + static const size_t checkPrecondition = + 0 / size_t(N < BitSize::value); + static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; }; template<> struct NBitMask::value> { - static const size_t value = size_t(-1); + static const size_t value = size_t(-1); }; /** @@ -98,8 +99,8 @@ struct NBitMask::value> template struct MulOverflowMask { - static const size_t value = - ~NBitMask::value - CeilingLog2::value>::value; + static const size_t value = + ~NBitMask::value - CeilingLog2::value>::value; }; template<> struct MulOverflowMask<0> { /* Error */ }; template<> struct MulOverflowMask<1> { static const size_t value = 0; }; diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ThreadLocal.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ThreadLocal.h index 6df109821f..28015de22e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ThreadLocal.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ThreadLocal.h @@ -54,7 +54,10 @@ typedef sig_atomic_t sig_safe_t; * * API usage: * - * // Create a TLS item + * // Create a TLS item. + * // + * // Note that init() should be invoked exactly once, before any usage of set() + * // or get(). * mozilla::ThreadLocal tlsKey; * if (!tlsKey.init()) { * // deal with the error @@ -70,30 +73,29 @@ template class ThreadLocal { #if defined(XP_WIN) - typedef unsigned long key_t; + typedef unsigned long key_t; #else - typedef pthread_key_t key_t; + typedef pthread_key_t key_t; #endif - union Helper { - void* ptr; - T value; - }; + union Helper + { + void* mPtr; + T mValue; + }; - public: - MOZ_WARN_UNUSED_RESULT inline bool init(); +public: + MOZ_WARN_UNUSED_RESULT inline bool init(); - inline T get() const; + inline T get() const; - inline void set(const T value); + inline void set(const T aValue); - bool initialized() const { - return inited; - } + bool initialized() const { return mInited; } - private: - key_t key; - bool inited; +private: + key_t mKey; + bool mInited; }; template @@ -105,12 +107,12 @@ ThreadLocal::init() "a pointer"); MOZ_ASSERT(!initialized()); #ifdef XP_WIN - key = TlsAlloc(); - inited = key != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES + mKey = TlsAlloc(); + mInited = mKey != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES #else - inited = !pthread_key_create(&key, nullptr); + mInited = !pthread_key_create(&mKey, nullptr); #endif - return inited; + return mInited; } template @@ -120,28 +122,28 @@ ThreadLocal::get() const MOZ_ASSERT(initialized()); Helper h; #ifdef XP_WIN - h.ptr = TlsGetValue(key); + h.mPtr = TlsGetValue(mKey); #else - h.ptr = pthread_getspecific(key); + h.mPtr = pthread_getspecific(mKey); #endif - return h.value; + return h.mValue; } template inline void -ThreadLocal::set(const T value) +ThreadLocal::set(const T aValue) { MOZ_ASSERT(initialized()); Helper h; - h.value = value; - bool succeeded; + h.mValue = aValue; #ifdef XP_WIN - succeeded = TlsSetValue(key, h.ptr); + bool succeeded = TlsSetValue(mKey, h.mPtr); #else - succeeded = !pthread_setspecific(key, h.ptr); + bool succeeded = !pthread_setspecific(mKey, h.mPtr); #endif - if (!succeeded) + if (!succeeded) { MOZ_CRASH(); + } } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ToString.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ToString.h new file mode 100644 index 0000000000..f11cad5cb6 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/ToString.h @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Utilities for converting an object to a string representation. */ + +#ifndef mozilla_ToString_h +#define mozilla_ToString_h + +#include +#include + +namespace mozilla { + +/** + * A convenience function for converting an object to a string representation. + * Supports any object which can be streamed to an std::ostream. + */ +template +std::string +ToString(const T& aValue) +{ + std::ostringstream stream; + stream << aValue; + return stream.str(); +} + +} // namespace mozilla + +#endif /* mozilla_ToString_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TypeTraits.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TypeTraits.h index 1ccd0c85d1..515c68d94e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TypeTraits.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TypeTraits.h @@ -9,6 +9,8 @@ #ifndef mozilla_TypeTraits_h #define mozilla_TypeTraits_h +#include "mozilla/Types.h" + /* * These traits are approximate copies of the traits and semantics from C++11's * header. Don't add traits not in that header! When all @@ -32,9 +34,9 @@ template struct RemoveCV; template struct IntegralConstant { - static const T value = Value; - typedef T ValueType; - typedef IntegralConstant Type; + static const T value = Value; + typedef T ValueType; + typedef IntegralConstant Type; }; /** Convenient aliases. */ @@ -47,6 +49,27 @@ typedef IntegralConstant FalseType; namespace detail { +template +struct IsVoidHelper : FalseType {}; + +template<> +struct IsVoidHelper : TrueType {}; + +} // namespace detail + +/** + * IsVoid determines whether a type is void. + * + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true; + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true. + */ +template +struct IsVoid : detail::IsVoidHelper::Type> {}; + +namespace detail { + template struct IsIntegralHelper : FalseType {}; @@ -114,6 +137,31 @@ struct IsFloatingPoint : detail::IsFloatingPointHelper::Type> {}; +namespace detail { + +template +struct IsArrayHelper : FalseType {}; + +template +struct IsArrayHelper : TrueType {}; + +template +struct IsArrayHelper : TrueType {}; + +} // namespace detail + +/** + * IsArray determines whether a type is an array type, of known or unknown + * length. + * + * mozilla::IsArray::value is false; + * mozilla::IsArray::value is true; + * mozilla::IsArray::value is true. + */ +template +struct IsArray : detail::IsArrayHelper::Type> +{}; + /** * IsPointer determines whether a type is a pointer type (but not a pointer-to- * member type). @@ -130,6 +178,40 @@ struct IsPointer : FalseType {}; template struct IsPointer : TrueType {}; +/** + * IsLvalueReference determines whether a type is an lvalue reference. + * + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is true; + * mozilla::IsLvalueReference::value is false. + */ +template +struct IsLvalueReference : FalseType {}; + +template +struct IsLvalueReference : TrueType {}; + +/** + * IsRvalueReference determines whether a type is an rvalue reference. + * + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is true. + */ +template +struct IsRvalueReference : FalseType {}; + +template +struct IsRvalueReference : TrueType {}; + namespace detail { // __is_enum is a supported extension across all of our supported compilers. @@ -152,8 +234,55 @@ struct IsEnum : detail::IsEnumHelper::Type> {}; +namespace detail { + +// __is_class is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx +template +struct IsClassHelper + : IntegralConstant +{}; + +} // namespace detail + +/** + * IsClass determines whether a type is a class type (but not a union). + * + * struct S {}; + * union U {}; + * mozilla::IsClass::value is false; + * mozilla::IsClass::value is true; + * mozilla::IsClass::value is false; + */ +template +struct IsClass + : detail::IsClassHelper::Type> +{}; + /* 20.9.4.2 Composite type traits [meta.unary.comp] */ +/** + * IsReference determines whether a type is an lvalue or rvalue reference. + * + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true. + */ +template +struct IsReference + : IntegralConstant::value || IsRvalueReference::value> +{}; + /** * IsArithmetic determines whether a type is arithmetic. A type is arithmetic * iff it is an integral type or a floating point type. @@ -228,26 +357,90 @@ template struct IsPod : TrueType {}; namespace detail { -template::value> -struct IsSignedHelper; - +// __is_empty is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx template -struct IsSignedHelper : TrueType {}; +struct IsEmptyHelper + : IntegralConstant::value && __is_empty(T)> +{}; +} // namespace detail + +/** + * IsEmpty determines whether a type is a class (but not a union) that is empty. + * + * A class is empty iff it and all its base classes have no non-static data + * members (except bit-fields of length 0) and no virtual member functions, and + * no base class is empty or a virtual base class. + * + * Intuitively, empty classes don't have any data that has to be stored in + * instances of those classes. (The size of the class must still be non-zero, + * because distinct array elements of any type must have different addresses. + * However, if the Empty Base Optimization is implemented by the compiler [most + * compilers implement it, and in certain cases C++11 requires it], the size of + * a class inheriting from an empty |Base| class need not be inflated by + * |sizeof(Base)|.) And intuitively, non-empty classes have data members and/or + * vtable pointers that must be stored in each instance for proper behavior. + * + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * union U1 { int x; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct E1 {}; + * struct E2 { int : 0 }; + * struct E3 : E1 {}; + * struct E4 : E2 {}; + * static_assert(mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value, + * "all empty"); + * union U2 { E1 e1; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct NE1 { int x; }; + * struct NE2 : virtual E1 {}; + * struct NE3 : E2 { virtual ~NE3() {} }; + * struct NE4 { virtual void f() {} }; + * static_assert(!mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value, + * "all empty"); + */ template -struct IsSignedHelper - : IntegralConstant::value && T(-1) < T(1)> +struct IsEmpty : detail::IsEmptyHelper::Type> {}; + +namespace detail { + +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> +struct IsSignedHelper; + +// Floating point is signed. +template +struct IsSignedHelper : TrueType {}; + +// Integral is conditionally signed. +template +struct IsSignedHelper + : IntegralConstant +{}; + +// Non-floating point, non-integral is not signed. +template +struct IsSignedHelper : FalseType {}; + } // namespace detail /** * IsSigned determines whether a type is a signed arithmetic type. |char| is * considered a signed type if it has the same representation as |signed char|. * - * Don't use this if the type might be user-defined! You might or might not get - * a compile error, depending. - * * mozilla::IsSigned::value is true; * mozilla::IsSigned::value is false; * mozilla::IsSigned::value is false; @@ -258,28 +451,32 @@ struct IsSigned : detail::IsSignedHelper {}; namespace detail { -template::value> +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> struct IsUnsignedHelper; -template -struct IsUnsignedHelper : FalseType {}; +// Floating point is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; -template -struct IsUnsignedHelper +// Integral is conditionally unsigned. +template +struct IsUnsignedHelper : IntegralConstant::value && - (IsSame::Type, bool>::value || - T(1) < T(-1))> + (IsSame::value || bool(NoCV(1) < NoCV(-1)))> {}; +// Non-floating point, non-integral is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; + } // namespace detail /** * IsUnsigned determines whether a type is an unsigned arithmetic type. * - * Don't use this if the type might be user-defined! You might or might not get - * a compile error, depending. - * * mozilla::IsUnsigned::value is false; * mozilla::IsUnsigned::value is true; * mozilla::IsUnsigned::value is true; @@ -310,6 +507,13 @@ struct IsSame : TrueType {}; namespace detail { +#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) + +template +struct BaseOfTester : IntegralConstant {}; + +#else + // The trickery used to implement IsBaseOf here makes it possible to use it for // the cases of private and multiple inheritance. This code was inspired by the // sample code here: @@ -318,35 +522,35 @@ namespace detail { template struct BaseOfHelper { - public: - operator Base*() const; - operator Derived*(); +public: + operator Base*() const; + operator Derived*(); }; template struct BaseOfTester { - private: - template - static char test(Derived*, T); - static int test(Base*, int); - - public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); }; template struct BaseOfTester { - private: - template - static char test(Derived*, T); - static int test(Base*, int); - - public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); }; template @@ -358,6 +562,8 @@ struct BaseOfTester : TrueType {}; template struct BaseOfTester : TrueType {}; +#endif + } /* namespace detail */ /* @@ -382,18 +588,18 @@ namespace detail { template struct ConvertibleTester { - private: - static From create(); +private: + static From create(); - template - static char test(To to); + template + static char test(To to); - template - static int test(...); + template + static int test(...); - public: - static const bool value = - sizeof(test(create())) == sizeof(char); +public: + static const bool value = + sizeof(test(create())) == sizeof(char); }; } // namespace detail @@ -424,16 +630,6 @@ struct IsConvertible : IntegralConstant::value> {}; -/** - * Is IsLvalueReference is true if its template param is T& and is false if - * its type is T or T&&. - */ -template -struct IsLvalueReference : FalseType {}; - -template -struct IsLvalueReference : TrueType {}; - /* 20.9.7 Transformations between types [meta.trans] */ /* 20.9.7.1 Const-volatile modifications [meta.trans.cv] */ @@ -449,13 +645,13 @@ struct IsLvalueReference : TrueType {}; template struct RemoveConst { - typedef T Type; + typedef T Type; }; template struct RemoveConst { - typedef T Type; + typedef T Type; }; /** @@ -469,13 +665,13 @@ struct RemoveConst template struct RemoveVolatile { - typedef T Type; + typedef T Type; }; template struct RemoveVolatile { - typedef T Type; + typedef T Type; }; /** @@ -489,7 +685,7 @@ struct RemoveVolatile template struct RemoveCV { - typedef typename RemoveConst::Type>::Type Type; + typedef typename RemoveConst::Type>::Type Type; }; /* 20.9.7.2 Reference modifications [meta.trans.ref] */ @@ -505,29 +701,69 @@ struct RemoveCV template struct RemoveReference { - typedef T Type; + typedef T Type; }; template struct RemoveReference { - typedef T Type; + typedef T Type; }; template struct RemoveReference { - typedef T Type; + typedef T Type; }; +template +struct Conditional; + +namespace detail { + +enum Voidness { TIsVoid, TIsNotVoid }; + +template::value ? TIsVoid : TIsNotVoid> +struct AddLvalueReferenceHelper; + +template +struct AddLvalueReferenceHelper +{ + typedef void Type; +}; + +template +struct AddLvalueReferenceHelper +{ + typedef T& Type; +}; + +} // namespace detail + +/** + * AddLvalueReference adds an lvalue & reference to T if one isn't already + * present. (Note: adding an lvalue reference to an rvalue && reference in + * essence replaces the && with a &&, per C+11 reference collapsing rules. For + * example, int&& would become int&.) + * + * The final computed type will only *not* be an lvalue reference if T is void. + * + * mozilla::AddLvalueReference::Type is int&; + * mozilla::AddLvalueRference::Type is volatile int&; + * mozilla::AddLvalueReference::Type is void*&; + * mozilla::AddLvalueReference::Type is void; + * mozilla::AddLvalueReference::Type is struct S&. + */ +template +struct AddLvalueReference + : detail::AddLvalueReferenceHelper +{}; + /* 20.9.7.3 Sign modifications [meta.trans.sign] */ template struct EnableIf; -template -struct Conditional; - namespace detail { template @@ -568,7 +804,7 @@ struct MakeSigned; template struct MakeSigned { - typedef T Type; + typedef T Type; }; template @@ -603,7 +839,8 @@ struct MakeSigned */ template struct MakeSigned - : EnableIf::value && !IsSame::Type>::value, + : EnableIf::value && + !IsSame::Type>::value, typename detail::MakeSigned >::Type {}; @@ -636,7 +873,7 @@ struct MakeUnsigned; template struct MakeUnsigned { - typedef T Type; + typedef T Type; }; template @@ -671,13 +908,41 @@ struct MakeUnsigned */ template struct MakeUnsigned - : EnableIf::value && !IsSame::Type>::value, + : EnableIf::value && + !IsSame::Type>::value, typename detail::MakeUnsigned >::Type {}; /* 20.9.7.4 Array modifications [meta.trans.arr] */ +/** + * RemoveExtent produces either the type of the elements of the array T, or T + * itself. + * + * mozilla::RemoveExtent::Type is int; + * mozilla::RemoveExtent::Type is const int; + * mozilla::RemoveExtent::Type is volatile int; + * mozilla::RemoveExtent::Type is long[17]. + */ +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + /* 20.9.7.5 Pointer modifications [meta.trans.ptr] */ /* 20.9.7.6 Other transformations [meta.trans.other] */ @@ -707,7 +972,7 @@ struct EnableIf template struct EnableIf { - typedef T Type; + typedef T Type; }; /** @@ -719,13 +984,13 @@ struct EnableIf template struct Conditional { - typedef A Type; + typedef A Type; }; template struct Conditional { - typedef B Type; + typedef B Type; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TypedEnum.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TypedEnum.h index e55365abb8..d84cd90257 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TypedEnum.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TypedEnum.h @@ -9,39 +9,11 @@ #ifndef mozilla_TypedEnum_h #define mozilla_TypedEnum_h -#include "mozilla/Attributes.h" +#include "mozilla/TypedEnumInternal.h" +#include "mozilla/MacroArgs.h" #if defined(__cplusplus) -#if defined(__clang__) - /* - * Per Clang documentation, "Note that marketing version numbers should not - * be used to check for language features, as different vendors use different - * numbering schemes. Instead, use the feature checking macros." - */ -# ifndef __has_extension -# define __has_extension __has_feature /* compatibility, for older versions of clang */ -# endif -# if __has_extension(cxx_strong_enums) -# define MOZ_HAVE_CXX11_ENUM_TYPE -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -#elif defined(__GNUC__) -# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L -# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3) -# define MOZ_HAVE_CXX11_ENUM_TYPE -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -# endif -#elif defined(_MSC_VER) -# if _MSC_VER >= 1400 -# define MOZ_HAVE_CXX11_ENUM_TYPE -# endif -# if _MSC_VER >= 1700 -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -#endif - /** * MOZ_ENUM_TYPE specifies the underlying numeric type for an enum. It's * specified by placing MOZ_ENUM_TYPE(type) immediately after the enum name in @@ -97,13 +69,12 @@ * in namespace scope to handle bits that can only be implemented with * namespace-scoped code. For example: * - * class FooBar { - * + * class FooBar + * { * MOZ_BEGIN_NESTED_ENUM_CLASS(Enum, int32_t) * A, * B = 6 * MOZ_END_NESTED_ENUM_CLASS(Enum) - * * }; * * MOZ_FINISH_NESTED_ENUM_CLASS(FooBar::Enum) @@ -131,6 +102,10 @@ * these are already integer types so there is nothing more to do. */ # define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name + /* + * See the comment below about MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) Name #else /** * We need Name to both name a type, and scope the provided enumerator @@ -172,24 +147,28 @@ # define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER1(Name) \ class Name \ { \ - public: \ - enum Enum \ - { + public: \ + enum Enum \ + { /* Two-argument form. */ # define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER2(Name, type) \ class Name \ { \ - public: \ - enum Enum MOZ_ENUM_TYPE(type) \ - { + public: \ + enum Enum MOZ_ENUM_TYPE(type) \ + { # define MOZ_END_NESTED_ENUM_CLASS(Name) \ - }; \ - Name() {} \ - Name(Enum aEnum) : mEnum(aEnum) {} \ - explicit Name(int num) : mEnum((Enum)num) {} \ - operator Enum() const { return mEnum; } \ - private: \ - Enum mEnum; \ + }; \ + Name() {} \ + MOZ_CONSTEXPR Name(Enum aEnum) : mEnum(aEnum) {} \ + template \ + explicit MOZ_CONSTEXPR Name(Other num) : mEnum((Enum)num) {} \ + MOZ_CONSTEXPR operator Enum() const { return mEnum; } \ + explicit MOZ_CONSTEXPR Name(const mozilla::CastableTypedEnumResult& aOther) \ + : mEnum(aOther.get()) \ + {} \ + private: \ + Enum mEnum; \ }; # define MOZ_FINISH_NESTED_ENUM_CLASS(Name) \ inline int operator+(const int&, const Name::Enum&) MOZ_DELETE; \ @@ -225,7 +204,6 @@ inline bool operator&&(const Name::Enum&, const bool&) MOZ_DELETE; \ inline bool operator||(const bool&, const Name::Enum&) MOZ_DELETE; \ inline bool operator||(const Name::Enum&, const bool&) MOZ_DELETE; \ - inline int operator~(const Name::Enum&) MOZ_DELETE; \ inline int operator&(const int&, const Name::Enum&) MOZ_DELETE; \ inline int operator&(const Name::Enum&, const int&) MOZ_DELETE; \ inline int operator|(const int&, const Name::Enum&) MOZ_DELETE; \ @@ -253,35 +231,45 @@ * In the present case, the integer type is the Enum nested type. */ # define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name::Enum + /* + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is a variant of MOZ_ENUM_CLASS_ENUM_TYPE + * to be used when the enum class at hand depends on template parameters. + * + * Indeed, if T depends on template parameters, in order to name a nested type + * in T, C++ does not allow to just write "T::NestedType". Instead, we have + * to write "typename T::NestedType". The role of this macro is to add + * this "typename" keywords where needed. + * + * Example: + * + * template + * struct S {}; + * + * MOZ_BEGIN_ENUM_CLASS(E) + * Foo, + * Bar + * MOZ_END_ENUM_CLASS(E) + * + * S s; + * + * In this example, the second template parameter to S is meant to be of type + * T, but on non-C++11 compilers, type T is a class type, not an integer + * type, so it is not accepted as the type of a constant template parameter. + * One would then want to use MOZ_ENUM_CLASS_ENUM_TYPE(T), but that doesn't + * work either as T depends on template parameters (more specifically here, T + * _is_ a template parameter) so as MOZ_ENUM_CLASS_ENUM_TYPE(T) expands to + * T::Enum, we are missing the required "typename" keyword. So here, + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is needed. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) typename Name::Enum #endif - /* - * Count the number of arguments passed to MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS, - * very carefully tiptoeing around an MSVC bug where it improperly expands - * __VA_ARGS__ as a single token in argument lists. See these URLs for - * details: - * - * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement - * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 - */ -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL2(_1, _2, count, ...) \ - count -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL(args) \ - MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL2 args -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS(...) \ - MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL((__VA_ARGS__, 2, 1, 0)) - /* Pick the right helper macro to invoke. */ -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER2(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER##count -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER1(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER2(count) -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER1(count) - /* The actual macro. */ -# define MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(x, y) x y +# define MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(a, b) a b # define MOZ_BEGIN_NESTED_ENUM_CLASS(...) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER(MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS(__VA_ARGS__)), \ - (__VA_ARGS__)) + MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER, \ + __VA_ARGS__), \ + (__VA_ARGS__)) # define MOZ_BEGIN_ENUM_CLASS(...) MOZ_BEGIN_NESTED_ENUM_CLASS(__VA_ARGS__) # define MOZ_END_ENUM_CLASS(Name) \ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TypedEnumBits.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TypedEnumBits.h new file mode 100644 index 0000000000..1f439f1239 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TypedEnumBits.h @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS allows using a typed enum as bit flags. + */ + +#ifndef mozilla_TypedEnumBits_h +#define mozilla_TypedEnumBits_h + +#include "mozilla/IntegerTypeTraits.h" +#include "mozilla/TypedEnumInternal.h" + +namespace mozilla { + +#define MOZ_CASTABLETYPEDENUMRESULT_BINOP(Op, OtherType, ReturnType) \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const OtherType& aE, const CastableTypedEnumResult& aR) \ +{ \ + return ReturnType(aE Op OtherType(aR)); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR, const OtherType& aE) \ +{ \ + return ReturnType(OtherType(aR) Op aE); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR1, \ + const CastableTypedEnumResult& aR2) \ +{ \ + return ReturnType(OtherType(aR1) Op OtherType(aR2)); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_BINOP(|, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(&, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(^, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(==, E, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(!=, E, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(||, bool, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(&&, bool, bool) + +template +MOZ_CONSTEXPR CastableTypedEnumResult +operator ~(const CastableTypedEnumResult& aR) +{ + return CastableTypedEnumResult(~(E(aR))); +} + +#define MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(Op) \ +template \ +E& \ +operator Op(E& aR1, \ + const CastableTypedEnumResult& aR2) \ +{ \ + return aR1 Op E(aR2); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(&=) +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(|=) +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(^=) + +#undef MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP + +#undef MOZ_CASTABLETYPEDENUMRESULT_BINOP + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS + +#define MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(Op, ReturnType) \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(typename E::Enum aE, const CastableTypedEnumResult& aR) \ +{ \ + return ReturnType(aE Op E(aR)); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR, typename E::Enum aE) \ +{ \ + return ReturnType(E(aR) Op aE); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(|, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(&, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(^, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(==, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(!=, bool) + +#undef MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11 + +#endif // not MOZ_HAVE_CXX11_STRONG_ENUMS + +namespace detail { +template +struct UnsignedIntegerTypeForEnum + : UnsignedStdintTypeForSize +{}; +} + +} // namespace mozilla + +#define MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, Op) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name a, Name b) \ + { \ + typedef mozilla::CastableTypedEnumResult Result; \ + typedef mozilla::detail::UnsignedIntegerTypeForEnum::Type U; \ + return Result(Name(U(a) Op U(b))); \ + } \ + \ + inline Name& \ + operator Op##=(Name& a, Name b) \ + { \ + return a = a Op b; \ + } + +#define MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, |) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, &) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, ^) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator~(Name a) \ + { \ + typedef mozilla::CastableTypedEnumResult Result; \ + typedef mozilla::detail::UnsignedIntegerTypeForEnum::Type U; \ + return Result(Name(~(U(a)))); \ + } + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS +# define MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, Op) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name a, Name::Enum b) \ + { \ + return a Op Name(b); \ + } \ + \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name::Enum a, Name b) \ + { \ + return Name(a) Op b; \ + } \ + \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name::Enum a, Name::Enum b) \ + { \ + return Name(a) Op Name(b); \ + } \ + \ + inline Name& \ + operator Op##=(Name& a, Name::Enum b) \ + { \ + return a = a Op Name(b); \ + } + +# define MOZ_MAKE_ENUM_CLASS_OPS_EXTRA_NON_CXX11(Name) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, |) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, &) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, ^) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator~(Name::Enum a) \ + { \ + return ~(Name(a)); \ + } +#endif + +/** + * MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS generates standard bitwise operators + * for the given enum type. Use this to enable using an enum type as bit-field. + */ +#ifdef MOZ_HAVE_CXX11_STRONG_ENUMS +# define MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) +#else +# define MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_EXTRA_NON_CXX11(Name) +#endif + +#endif // mozilla_TypedEnumBits_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TypedEnumInternal.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TypedEnumInternal.h new file mode 100644 index 0000000000..8c88cb589b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/TypedEnumInternal.h @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Internal stuff needed by TypedEnum.h and TypedEnumBits.h. */ + +// NOTE: When we can assume C++11 enum class support and TypedEnum.h goes away, +// we should then consider folding TypedEnumInternal.h into TypedEnumBits.h. + +#ifndef mozilla_TypedEnumInternal_h +#define mozilla_TypedEnumInternal_h + +#include "mozilla/Attributes.h" + +#if defined(__cplusplus) + +#if defined(__clang__) + /* + * Per Clang documentation, "Note that marketing version numbers should not + * be used to check for language features, as different vendors use different + * numbering schemes. Instead, use the feature checking macros." + */ +# ifndef __has_extension +# define __has_extension __has_feature /* compatibility, for older versions of clang */ +# endif +# if __has_extension(cxx_strong_enums) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#elif defined(__GNUC__) +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +# endif +#elif defined(_MSC_VER) +# if _MSC_VER >= 1400 +# define MOZ_HAVE_CXX11_ENUM_TYPE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#endif + +namespace mozilla { + +/* + * The problem that CastableTypedEnumResult aims to solve is that + * typed enums are not convertible to bool, and there is no way to make them + * be, yet user code wants to be able to write + * + * if (myFlags & Flags::SOME_PARTICULAR_FLAG) (1) + * + * There are different approaches to solving this. Most of them require + * adapting user code. For example, we could implement operator! and have + * the user write + * + * if (!!(myFlags & Flags::SOME_PARTICULAR_FLAG)) (2) + * + * Or we could supply a IsNonZero() or Any() function returning whether + * an enum value is nonzero, and have the user write + * + * if (Any(Flags & Flags::SOME_PARTICULAR_FLAG)) (3) + * + * But instead, we choose to preserve the original user syntax (1) as it + * is inherently more readable, and to ease porting existing code to typed + * enums. We achieve this by having operator& and other binary bitwise + * operators have as return type a class, CastableTypedEnumResult, + * that wraps a typed enum but adds bool convertibility. + */ +template +class CastableTypedEnumResult +{ +private: + const E mValue; + +public: + explicit MOZ_CONSTEXPR CastableTypedEnumResult(E aValue) + : mValue(aValue) + {} + + MOZ_CONSTEXPR operator E() const { return mValue; } + + template + MOZ_EXPLICIT_CONVERSION MOZ_CONSTEXPR + operator DestinationType() const { return DestinationType(mValue); } + + MOZ_CONSTEXPR bool operator !() const { return !bool(mValue); } + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS + // This get() method is used to implement a constructor in the + // non-c++11 fallback path for MOZ_BEGIN_ENUM_CLASS, taking a + // CastableTypedEnumResult. If we try to implement it using the + // above conversion operator E(), then at least clang 3.3 + // (when forced to take the non-c++11 fallback path) compiles + // this constructor to an infinite recursion. So we introduce this + // get() method, that does exactly the same as the conversion operator, + // to work around this. + MOZ_CONSTEXPR E get() const { return mValue; } +#endif +}; + +} // namespace mozilla + +#endif // __cplusplus + +#endif // mozilla_TypedEnumInternal_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Types.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Types.h index 5340b2b600..e7e18abb27 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Types.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Types.h @@ -37,7 +37,7 @@ * These macros are designed for use by library interfaces -- not for normal * methods or data used cross-file. */ -#if defined(WIN32) || defined(XP_OS2) +#if defined(WIN32) # define MOZ_EXPORT __declspec(dllexport) #else /* Unix */ # ifdef HAVE_VISIBILITY_ATTRIBUTE @@ -63,16 +63,12 @@ # else # define MOZ_IMPORT_API __declspec(dllimport) # endif -#elif defined(XP_OS2) -# define MOZ_IMPORT_API __declspec(dllimport) #else # define MOZ_IMPORT_API MOZ_EXPORT #endif #if defined(_WIN32) && !defined(__MWERKS__) # define MOZ_IMPORT_DATA __declspec(dllimport) -#elif defined(XP_OS2) -# define MOZ_IMPORT_DATA __declspec(dllimport) #else # define MOZ_IMPORT_DATA MOZ_EXPORT #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/UniquePtr.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/UniquePtr.h new file mode 100644 index 0000000000..9c873db90c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/UniquePtr.h @@ -0,0 +1,674 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Smart pointer managing sole ownership of a resource. */ + +#ifndef mozilla_UniquePtr_h +#define mozilla_UniquePtr_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/Pair.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +template class DefaultDelete; +template> class UniquePtr; + +} // namespace mozilla + +namespace mozilla { + +/** + * UniquePtr is a smart pointer that wholly owns a resource. Ownership may be + * transferred out of a UniquePtr through explicit action, but otherwise the + * resource is destroyed when the UniquePtr is destroyed. + * + * UniquePtr is similar to C++98's std::auto_ptr, but it improves upon auto_ptr + * in one crucial way: it's impossible to copy a UniquePtr. Copying an auto_ptr + * obviously *can't* copy ownership of its singly-owned resource. So what + * happens if you try to copy one? Bizarrely, ownership is implicitly + * *transferred*, preserving single ownership but breaking code that assumes a + * copy of an object is identical to the original. (This is why auto_ptr is + * prohibited in STL containers.) + * + * UniquePtr solves this problem by being *movable* rather than copyable. + * Instead of passing a |UniquePtr u| directly to the constructor or assignment + * operator, you pass |Move(u)|. In doing so you indicate that you're *moving* + * ownership out of |u|, into the target of the construction/assignment. After + * the transfer completes, |u| contains |nullptr| and may be safely destroyed. + * This preserves single ownership but also allows UniquePtr to be moved by + * algorithms that have been made move-safe. (Note: if |u| is instead a + * temporary expression, don't use |Move()|: just pass the expression, because + * it's already move-ready. For more information see Move.h.) + * + * UniquePtr is also better than std::auto_ptr in that the deletion operation is + * customizable. An optional second template parameter specifies a class that + * (through its operator()(T*)) implements the desired deletion policy. If no + * policy is specified, mozilla::DefaultDelete is used -- which will either + * |delete| or |delete[]| the resource, depending whether the resource is an + * array. Custom deletion policies ideally should be empty classes (no member + * fields, no member fields in base classes, no virtual methods/inheritance), + * because then UniquePtr can be just as efficient as a raw pointer. + * + * Use of UniquePtr proceeds like so: + * + * UniquePtr g1; // initializes to nullptr + * g1.reset(new int); // switch resources using reset() + * g1 = nullptr; // clears g1, deletes the int + * + * UniquePtr g2(new int); // owns that int + * int* p = g2.release(); // g2 leaks its int -- still requires deletion + * delete p; // now freed + * + * struct S { int x; S(int x) : x(x) {} }; + * UniquePtr g3, g4(new S(5)); + * g3 = Move(g4); // g3 owns the S, g4 cleared + * S* p = g3.get(); // g3 still owns |p| + * assert(g3->x == 5); // operator-> works (if .get() != nullptr) + * assert((*g3).x == 5); // also operator* (again, if not cleared) + * Swap(g3, g4); // g4 now owns the S, g3 cleared + * g3.swap(g4); // g3 now owns the S, g4 cleared + * UniquePtr g5(Move(g3)); // g5 owns the S, g3 cleared + * g5.reset(); // deletes the S, g5 cleared + * + * struct FreePolicy { void operator()(void* p) { free(p); } }; + * UniquePtr g6(static_cast(malloc(sizeof(int)))); + * int* ptr = g6.get(); + * g6 = nullptr; // calls free(ptr) + * + * Now, carefully note a few things you *can't* do: + * + * UniquePtr b1; + * b1 = new int; // BAD: can only assign another UniquePtr + * int* ptr = b1; // BAD: no auto-conversion to pointer, use get() + * + * UniquePtr b2(b1); // BAD: can't copy a UniquePtr + * UniquePtr b3 = b1; // BAD: can't copy-assign a UniquePtr + * + * A few miscellaneous notes: + * + * UniquePtr, when not instantiated for an array type, can be move-constructed + * and move-assigned, not only from itself but from "derived" UniquePtr + * instantiations where U converts to T and E converts to D. If you want to use + * this, you're going to have to specify a deletion policy for both UniquePtr + * instantations, and T pretty much has to have a virtual destructor. In other + * words, this doesn't work: + * + * struct Base { virtual ~Base() {} }; + * struct Derived : Base {}; + * + * UniquePtr b1; + * // BAD: DefaultDelete and DefaultDelete don't interconvert + * UniquePtr d1(Move(b)); + * + * UniquePtr b2; + * UniquePtr> d2(Move(b2)); // okay + * + * UniquePtr is specialized for array types. Specializing with an array type + * creates a smart-pointer version of that array -- not a pointer to such an + * array. + * + * UniquePtr arr(new int[5]); + * arr[0] = 4; + * + * What else is different? Deletion of course uses |delete[]|. An operator[] + * is provided. Functionality that doesn't make sense for arrays is removed. + * The constructors and mutating methods only accept array pointers (not T*, U* + * that converts to T*, or UniquePtr or UniquePtr) or |nullptr|. + * + * It's perfectly okay to return a UniquePtr from a method to assure the related + * resource is properly deleted. You'll need to use |Move()| when returning a + * local UniquePtr. Otherwise you can return |nullptr|, or you can return + * |UniquePtr(ptr)|. + * + * UniquePtr will commonly be a member of a class, with lifetime equivalent to + * that of that class. If you want to expose the related resource, you could + * expose a raw pointer via |get()|, but ownership of a raw pointer is + * inherently unclear. So it's better to expose a |const UniquePtr&| instead. + * This prohibits mutation but still allows use of |get()| when needed (but + * operator-> is preferred). Of course, you can only use this smart pointer as + * long as the enclosing class instance remains live -- no different than if you + * exposed the |get()| raw pointer. + * + * To pass a UniquePtr-managed resource as a pointer, use a |const UniquePtr&| + * argument. To specify an inout parameter (where the method may or may not + * take ownership of the resource, or reset it), or to specify an out parameter + * (where simply returning a |UniquePtr| isn't possible), use a |UniquePtr&| + * argument. To unconditionally transfer ownership of a UniquePtr + * into a method, use a |UniquePtr| argument. To conditionally transfer + * ownership of a resource into a method, should the method want it, use a + * |UniquePtr&&| argument. + */ +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + Pointer& ptr() { return tuple.first(); } + const Pointer& ptr() const { return tuple.first(); } + + DeleterType& del() { return tuple.second(); } + const DeleterType& del() const { return tuple.second(); } + + public: + /** + * Construct a UniquePtr containing |nullptr|. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! Ideally + // you should make deletion use the same function every time, using a + // deleter policy: + // + // // BAD, won't compile with MSVC10, deleter doesn't need to be a + // // variable at all + // typedef void (&FreeSignature)(void*); + // UniquePtr ptr((int*) malloc(sizeof(int)), free); + // + // // GOOD, compiles with MSVC10, deletion behavior statically known and + // // optimizable + // struct DeleteByFreeing + // { + // void operator()(void* ptr) { free(ptr); } + // }; + // + // If deletion really, truly, must be a variable: you might be able to work + // around this with a deleter class that contains the function reference. + // But this workaround is untried and untested, because variable deletion + // behavior really isn't something you should use. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + template + UniquePtr(UniquePtr&& other, + typename EnableIf::Pointer, + Pointer>::value && + !IsArray::value && + (IsReference::value + ? IsSame::value + : IsConvertible::value), + int>::Type dummy = 0) + : tuple(other.release(), Forward(other.getDeleter())) + { + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + template + UniquePtr& operator=(UniquePtr&& other) + { + static_assert(IsConvertible::Pointer, Pointer>::value, + "incompatible UniquePtr pointees"); + static_assert(!IsArray::value, + "can't assign from UniquePtr holding an array"); + + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT n) { + MOZ_ASSERT(n == nullptr); + reset(nullptr); + return *this; + } + + T& operator*() const { return *get(); } + Pointer operator->() const { + MOZ_ASSERT(get(), "dereferencing a UniquePtr containing nullptr"); + return get(); + } + + Pointer get() const { return ptr(); } + + DeleterType& getDeleter() { return del(); } + const DeleterType& getDeleter() const { return del(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = ptr(); + ptr() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = ptr(); + ptr() = p; + if (old != nullptr) + getDeleter()(old); + } + + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +// In case you didn't read the comment by the main definition (you should!): the +// UniquePtr specialization exists to manage array pointers. It deletes +// such pointers using delete[], it will reject construction and modification +// attempts using U* or U[]. Otherwise it works like the normal UniquePtr. +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + public: + /** + * Construct a UniquePtr containing nullptr. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + private: + // delete[] knows how to handle *only* an array of a single class type. For + // delete[] to work correctly, it must know the size of each element, the + // fields and base classes of each element requiring destruction, and so on. + // So forbid all overloads which would end up invoking delete[] on a pointer + // of the wrong type. + template + UniquePtr(U&& u, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! See the + // comment by this constructor in the non-T[] specialization above. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + private: + // Forbidden for the same reasons as stated above. + template + UniquePtr(U&& u, V&& v, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT) { + reset(); + return *this; + } + + T& operator[](decltype(sizeof(int)) i) const { return get()[i]; } + Pointer get() const { return tuple.first(); } + + DeleterType& getDeleter() { return tuple.second(); } + const DeleterType& getDeleter() const { return tuple.second(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = tuple.first(); + tuple.first() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = tuple.first(); + tuple.first() = p; + if (old != nullptr) + tuple.second()(old); + } + + private: + // Kill off all remaining overloads that aren't true nullptr (the overload + // above should handle that) or emulated nullptr (which acts like int/long + // on gcc 4.4/4.5). + template + void reset(U, + typename EnableIf::value && + !IsSame::Type>::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +/** A default deletion policy using plain old operator delete. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + template + DefaultDelete(const DefaultDelete& other, + typename EnableIf::value, + int>::Type dummy = 0) + {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete ptr; + } +}; + +/** A default deletion policy using operator delete[]. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete[] ptr; + } + + private: + template + void operator()(U* ptr) const MOZ_DELETE; +}; + +template +void +Swap(UniquePtr& x, UniquePtr& y) +{ + x.swap(y); +} + +template +bool +operator==(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() == y.get(); +} + +template +bool +operator!=(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() != y.get(); +} + +template +bool +operator==(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator==(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator!=(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +template +bool +operator!=(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +// No operator<, operator>, operator<=, operator>= for now because simplicity. + +namespace detail { + +template +struct UniqueSelector +{ + typedef UniquePtr SingleObject; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr UnknownBound; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr KnownBound; +}; + +} // namespace detail + +// We don't have variadic template support everywhere, so just hard-code arities +// 0-4 for now. If you need more arguments, feel free to add the extra +// overloads. +// +// Beware! Due to lack of true nullptr support in gcc 4.4 and 4.5, passing +// literal nullptr to MakeUnique will not work on some platforms. See Move.h +// for more details. + +template +typename detail::UniqueSelector::SingleObject +MakeUnique() +{ + return UniquePtr(new T()); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1) +{ + return UniquePtr(new T(Forward(a1))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2) +{ + return UniquePtr(new T(Forward(a1), Forward(a2))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4), Forward(a5))); +} + +template +typename detail::UniqueSelector::UnknownBound +MakeUnique(decltype(sizeof(int)) n) +{ + typedef typename RemoveExtent::Type ArrayType; + return UniquePtr(new ArrayType[n]()); +} + +template +typename detail::UniqueSelector::KnownBound +MakeUnique() MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) MOZ_DELETE; + +} // namespace mozilla + +#endif /* mozilla_UniquePtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Vector.h index c67467524f..8540caf476 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Vector.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Vector.h @@ -39,14 +39,13 @@ namespace detail { /* * Check that the given capacity wastes the minimal amount of space if - * allocated on the heap. This means that cap*sizeof(T) is as close to a - * power-of-two as possible. growStorageBy() is responsible for ensuring - * this. + * allocated on the heap. This means that aCapacity*sizeof(T) is as close to a + * power-of-two as possible. growStorageBy() is responsible for ensuring this. */ template -static bool CapacityHasExcessSpace(size_t cap) +static bool CapacityHasExcessSpace(size_t aCapacity) { - size_t size = cap * sizeof(T); + size_t size = aCapacity * sizeof(T); return RoundUpPow2(size) - size >= sizeof(T); } @@ -57,72 +56,90 @@ static bool CapacityHasExcessSpace(size_t cap) template struct VectorImpl { - /* Destroys constructed objects in the range [begin, end). */ - static inline void destroy(T* begin, T* end) { - for (T* p = begin; p < end; ++p) - p->~T(); + /* Destroys constructed objects in the range [aBegin, aEnd). */ + static inline void destroy(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + p->~T(); } + } - /* Constructs objects in the uninitialized range [begin, end). */ - static inline void initialize(T* begin, T* end) { - for (T* p = begin; p < end; ++p) - new(p) T(); + /* Constructs objects in the uninitialized range [aBegin, aEnd). */ + static inline void initialize(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); } + } - /* - * Copy-constructs objects in the uninitialized range - * [dst, dst+(srcend-srcbeg)) from the range [srcbeg, srcend). - */ - template - static inline void copyConstruct(T* dst, const U* srcbeg, const U* srcend) { - for (const U* p = srcbeg; p < srcend; ++p, ++dst) - new(dst) T(*p); + /* + * Copy-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(*p); } + } - /* - * Move-constructs objects in the uninitialized range - * [dst, dst+(srcend-srcbeg)) from the range [srcbeg, srcend). - */ - template - static inline void moveConstruct(T* dst, U* srcbeg, U* srcend) { - for (U* p = srcbeg; p < srcend; ++p, ++dst) - new(dst) T(Move(*p)); + /* + * Move-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void moveConstruct(T* aDst, U* aSrcStart, U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(Move(*p)); } + } - /* - * Copy-constructs objects in the uninitialized range [dst, dst+n) from the - * same object u. - */ - template - static inline void copyConstructN(T* dst, size_t n, const U& u) { - for (T* end = dst + n; dst < end; ++dst) - new(dst) T(u); + /* + * Copy-constructs objects in the uninitialized range [aDst, aDst+aN) from + * the same object aU. + */ + template + static inline void copyConstructN(T* aDst, size_t aN, const U& aU) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + new(aDst) T(aU); } + } - /* - * Grows the given buffer to have capacity newCap, preserving the objects - * constructed in the range [begin, end) and updating v. Assumes that (1) - * newCap has not overflowed, and (2) multiplying newCap by sizeof(T) will - * not overflow. - */ - static inline bool - growTo(VectorBase& v, size_t newCap) { - MOZ_ASSERT(!v.usingInlineStorage()); - MOZ_ASSERT(!CapacityHasExcessSpace(newCap)); - T* newbuf = reinterpret_cast(v.malloc_(newCap * sizeof(T))); - if (!newbuf) - return false; - T* dst = newbuf; - T* src = v.beginNoCheck(); - for (; src < v.endNoCheck(); ++dst, ++src) - new(dst) T(Move(*src)); - VectorImpl::destroy(v.beginNoCheck(), v.endNoCheck()); - v.free_(v.mBegin); - v.mBegin = newbuf; - /* v.mLength is unchanged. */ - v.mCapacity = newCap; - return true; + /* + * Grows the given buffer to have capacity aNewCap, preserving the objects + * constructed in the range [begin, end) and updating aV. Assumes that (1) + * aNewCap has not overflowed, and (2) multiplying aNewCap by sizeof(T) will + * not overflow. + */ + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + T* newbuf = reinterpret_cast(aV.malloc_(aNewCap * sizeof(T))); + if (!newbuf) { + return false; + } + T* dst = newbuf; + T* src = aV.beginNoCheck(); + for (; src < aV.endNoCheck(); ++dst, ++src) { + new(dst) T(Move(*src)); } + VectorImpl::destroy(aV.beginNoCheck(), aV.endNoCheck()); + aV.free_(aV.mBegin); + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } }; /* @@ -133,58 +150,71 @@ struct VectorImpl template struct VectorImpl { - static inline void destroy(T*, T*) {} - - static inline void initialize(T* begin, T* end) { - /* - * You would think that memset would be a big win (or even break even) - * when we know T is a POD. But currently it's not. This is probably - * because |append| tends to be given small ranges and memset requires - * a function call that doesn't get inlined. - * - * memset(begin, 0, sizeof(T) * (end-begin)); - */ - for (T* p = begin; p < end; ++p) - new(p) T(); - } + static inline void destroy(T*, T*) {} - template - static inline void copyConstruct(T* dst, const U* srcbeg, const U* srcend) { - /* - * See above memset comment. Also, notice that copyConstruct is - * currently templated (T != U), so memcpy won't work without - * requiring T == U. - * - * memcpy(dst, srcbeg, sizeof(T) * (srcend - srcbeg)); - */ - for (const U* p = srcbeg; p < srcend; ++p, ++dst) - *dst = *p; + static inline void initialize(T* aBegin, T* aEnd) + { + /* + * You would think that memset would be a big win (or even break even) + * when we know T is a POD. But currently it's not. This is probably + * because |append| tends to be given small ranges and memset requires + * a function call that doesn't get inlined. + * + * memset(aBegin, 0, sizeof(T) * (aEnd - aBegin)); + */ + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); } + } - template - static inline void moveConstruct(T* dst, const U* srcbeg, const U* srcend) { - copyConstruct(dst, srcbeg, srcend); + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + /* + * See above memset comment. Also, notice that copyConstruct is + * currently templated (T != U), so memcpy won't work without + * requiring T == U. + * + * memcpy(aDst, aSrcStart, sizeof(T) * (aSrcEnd - aSrcStart)); + */ + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + *aDst = *p; } + } - static inline void copyConstructN(T* dst, size_t n, const T& t) { - for (T* end = dst + n; dst < end; ++dst) - *dst = t; + template + static inline void moveConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + copyConstruct(aDst, aSrcStart, aSrcEnd); + } + + static inline void copyConstructN(T* aDst, size_t aN, const T& aT) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + *aDst = aT; } + } - static inline bool - growTo(VectorBase& v, size_t newCap) { - MOZ_ASSERT(!v.usingInlineStorage()); - MOZ_ASSERT(!CapacityHasExcessSpace(newCap)); - size_t oldSize = sizeof(T) * v.mCapacity; - size_t newSize = sizeof(T) * newCap; - T* newbuf = reinterpret_cast(v.realloc_(v.mBegin, oldSize, newSize)); - if (!newbuf) - return false; - v.mBegin = newbuf; - /* v.mLength is unchanged. */ - v.mCapacity = newCap; - return true; + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + size_t oldSize = sizeof(T) * aV.mCapacity; + size_t newSize = sizeof(T) * aNewCap; + T* newbuf = reinterpret_cast(aV.realloc_(aV.mBegin, oldSize, newSize)); + if (!newbuf) { + return false; } + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } }; } // namespace detail @@ -199,368 +229,387 @@ struct VectorImpl template class VectorBase : private AllocPolicy { - /* utilities */ + /* utilities */ - static const bool sElemIsPod = IsPod::value; - typedef detail::VectorImpl Impl; - friend struct detail::VectorImpl; + static const bool kElemIsPod = IsPod::value; + typedef detail::VectorImpl Impl; + friend struct detail::VectorImpl; - bool growStorageBy(size_t incr); - bool convertToHeapStorage(size_t newCap); + bool growStorageBy(size_t aIncr); + bool convertToHeapStorage(size_t aNewCap); - /* magic constants */ + /* magic constants */ - static const int sMaxInlineBytes = 1024; + static const int kMaxInlineBytes = 1024; - /* compute constants */ + /* compute constants */ - /* - * Consider element size to be 1 for buffer sizing if there are 0 inline - * elements. This allows us to compile when the definition of the element - * type is not visible here. - * - * Explicit specialization is only allowed at namespace scope, so in order - * to keep everything here, we use a dummy template parameter with partial - * specialization. - */ - template - struct ElemSize - { - static const size_t value = sizeof(T); - }; - template - struct ElemSize<0, Dummy> - { - static const size_t value = 1; - }; - - static const size_t sInlineCapacity = - tl::Min::value>::value; - - /* Calculate inline buffer size; avoid 0-sized array. */ - static const size_t sInlineBytes = - tl::Max<1, sInlineCapacity * ElemSize::value>::value; - - /* member data */ + /* + * Consider element size to be 1 for buffer sizing if there are 0 inline + * elements. This allows us to compile when the definition of the element + * type is not visible here. + * + * Explicit specialization is only allowed at namespace scope, so in order + * to keep everything here, we use a dummy template parameter with partial + * specialization. + */ + template + struct ElemSize + { + static const size_t value = sizeof(T); + }; + template + struct ElemSize<0, Dummy> + { + static const size_t value = 1; + }; + + static const size_t kInlineCapacity = + tl::Min::value>::value; + + /* Calculate inline buffer size; avoid 0-sized array. */ + static const size_t kInlineBytes = + tl::Max<1, kInlineCapacity * ElemSize::value>::value; + + /* member data */ - /* - * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, - * mBegin + mLength) hold valid constructed T objects. The range [mBegin + - * mLength, mBegin + mCapacity) holds uninitialized memory. The range - * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory - * previously allocated by a call to reserve(). - */ - T* mBegin; + /* + * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, + * mBegin + mLength) hold valid constructed T objects. The range [mBegin + + * mLength, mBegin + mCapacity) holds uninitialized memory. The range + * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory + * previously allocated by a call to reserve(). + */ + T* mBegin; - /* Number of elements in the vector. */ - size_t mLength; + /* Number of elements in the vector. */ + size_t mLength; - /* Max number of elements storable in the vector without resizing. */ - size_t mCapacity; + /* Max number of elements storable in the vector without resizing. */ + size_t mCapacity; #ifdef DEBUG - /* Max elements of reserved or used space in this vector. */ - size_t mReserved; + /* Max elements of reserved or used space in this vector. */ + size_t mReserved; #endif - /* Memory used for inline storage. */ - AlignedStorage storage; + /* Memory used for inline storage. */ + AlignedStorage mStorage; #ifdef DEBUG - friend class ReentrancyGuard; - bool entered; + friend class ReentrancyGuard; + bool mEntered; #endif - /* private accessors */ + /* private accessors */ - bool usingInlineStorage() const { - return mBegin == const_cast(this)->inlineStorage(); - } + bool usingInlineStorage() const + { + return mBegin == const_cast(this)->inlineStorage(); + } - T* inlineStorage() { - return static_cast(storage.addr()); - } + T* inlineStorage() + { + return static_cast(mStorage.addr()); + } - T* beginNoCheck() const { - return mBegin; - } + T* beginNoCheck() const + { + return mBegin; + } - T* endNoCheck() { - return mBegin + mLength; - } + T* endNoCheck() + { + return mBegin + mLength; + } - const T* endNoCheck() const { - return mBegin + mLength; - } + const T* endNoCheck() const + { + return mBegin + mLength; + } #ifdef DEBUG - size_t reserved() const { - MOZ_ASSERT(mReserved <= mCapacity); - MOZ_ASSERT(mLength <= mReserved); - return mReserved; - } + size_t reserved() const + { + MOZ_ASSERT(mReserved <= mCapacity); + MOZ_ASSERT(mLength <= mReserved); + return mReserved; + } #endif - /* Append operations guaranteed to succeed due to pre-reserved space. */ - template void internalAppend(U&& u); - template - void internalAppendAll(const VectorBase& u); - void internalAppendN(const T& t, size_t n); - template void internalAppend(const U* begin, size_t length); + /* Append operations guaranteed to succeed due to pre-reserved space. */ + template void internalAppend(U&& aU); + template + void internalAppendAll(const VectorBase& aU); + void internalAppendN(const T& aT, size_t aN); + template void internalAppend(const U* aBegin, size_t aLength); - public: - static const size_t sMaxInlineStorage = N; +public: + static const size_t sMaxInlineStorage = N; - typedef T ElementType; + typedef T ElementType; - VectorBase(AllocPolicy = AllocPolicy()); - VectorBase(ThisVector&&); /* Move constructor. */ - ThisVector& operator=(ThisVector&&); /* Move assignment. */ - ~VectorBase(); + explicit VectorBase(AllocPolicy = AllocPolicy()); + explicit VectorBase(ThisVector&&); /* Move constructor. */ + ThisVector& operator=(ThisVector&&); /* Move assignment. */ + ~VectorBase(); - /* accessors */ + /* accessors */ - const AllocPolicy& allocPolicy() const { - return *this; - } + const AllocPolicy& allocPolicy() const { return *this; } - AllocPolicy& allocPolicy() { - return *this; - } + AllocPolicy& allocPolicy() { return *this; } - enum { InlineLength = N }; + enum { InlineLength = N }; - size_t length() const { - return mLength; - } + size_t length() const { return mLength; } - bool empty() const { - return mLength == 0; - } + bool empty() const { return mLength == 0; } - size_t capacity() const { - return mCapacity; - } + size_t capacity() const { return mCapacity; } - T* begin() { - MOZ_ASSERT(!entered); - return mBegin; - } + T* begin() + { + MOZ_ASSERT(!mEntered); + return mBegin; + } - const T* begin() const { - MOZ_ASSERT(!entered); - return mBegin; - } + const T* begin() const + { + MOZ_ASSERT(!mEntered); + return mBegin; + } - T* end() { - MOZ_ASSERT(!entered); - return mBegin + mLength; - } + T* end() + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } - const T* end() const { - MOZ_ASSERT(!entered); - return mBegin + mLength; - } + const T* end() const + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } - T& operator[](size_t i) { - MOZ_ASSERT(!entered); - MOZ_ASSERT(i < mLength); - return begin()[i]; - } + T& operator[](size_t aIndex) + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } - const T& operator[](size_t i) const { - MOZ_ASSERT(!entered); - MOZ_ASSERT(i < mLength); - return begin()[i]; - } + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } - T& back() { - MOZ_ASSERT(!entered); - MOZ_ASSERT(!empty()); - return *(end() - 1); - } + T& back() + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } - const T& back() const { - MOZ_ASSERT(!entered); - MOZ_ASSERT(!empty()); - return *(end() - 1); - } + const T& back() const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } - class Range + class Range + { + friend class VectorBase; + T* mCur; + T* mEnd; + Range(T* aCur, T* aEnd) + : mCur(aCur) + , mEnd(aEnd) { - friend class VectorBase; - T* cur_; - T* end_; - Range(T* cur, T* end) : cur_(cur), end_(end) {} - - public: - Range() {} - bool empty() const { return cur_ == end_; } - size_t remain() const { return end_ - cur_; } - T& front() const { return *cur_; } - void popFront() { MOZ_ASSERT(!empty()); ++cur_; } - T popCopyFront() { MOZ_ASSERT(!empty()); return *cur_++; } - }; - - Range all() { - return Range(begin(), end()); + MOZ_ASSERT(aCur <= aEnd); } - /* mutators */ + public: + Range() {} + bool empty() const { return mCur == mEnd; } + size_t remain() const { return PointerRangeSize(mCur, mEnd); } + T& front() const { MOZ_ASSERT(!empty()); return *mCur; } + void popFront() { MOZ_ASSERT(!empty()); ++mCur; } + T popCopyFront() { MOZ_ASSERT(!empty()); return *mCur++; } + }; - /** - * Given that the vector is empty and has no inline storage, grow to - * |capacity|. - */ - bool initCapacity(size_t request); + Range all() { return Range(begin(), end()); } - /** - * If reserve(length() + N) succeeds, the N next appends are guaranteed to - * succeed. - */ - bool reserve(size_t request); + /* mutators */ - /** - * Destroy elements in the range [end() - incr, end()). Does not deallocate - * or unreserve storage for those elements. - */ - void shrinkBy(size_t incr); + /** + * Given that the vector is empty and has no inline storage, grow to + * |capacity|. + */ + bool initCapacity(size_t aRequest); - /** Grow the vector by incr elements. */ - bool growBy(size_t incr); + /** + * If reserve(length() + N) succeeds, the N next appends are guaranteed to + * succeed. + */ + bool reserve(size_t aRequest); - /** Call shrinkBy or growBy based on whether newSize > length(). */ - bool resize(size_t newLength); + /** + * Destroy elements in the range [end() - aIncr, end()). Does not deallocate + * or unreserve storage for those elements. + */ + void shrinkBy(size_t aIncr); - /** - * Increase the length of the vector, but don't initialize the new elements - * -- leave them as uninitialized memory. - */ - bool growByUninitialized(size_t incr); - bool resizeUninitialized(size_t newLength); + /** Grow the vector by aIncr elements. */ + bool growBy(size_t aIncr); - /** Shorthand for shrinkBy(length()). */ - void clear(); + /** Call shrinkBy or growBy based on whether newSize > length(). */ + bool resize(size_t aNewLength); - /** Clears and releases any heap-allocated storage. */ - void clearAndFree(); + /** + * Increase the length of the vector, but don't initialize the new elements + * -- leave them as uninitialized memory. + */ + bool growByUninitialized(size_t aIncr); + bool resizeUninitialized(size_t aNewLength); - /** - * If true, appending |needed| elements won't reallocate elements storage. - * This *doesn't* mean that infallibleAppend may be used! You still must - * reserve the extra space, even if this method indicates that appends won't - * need to reallocate elements storage. - */ - bool canAppendWithoutRealloc(size_t needed) const; + /** Shorthand for shrinkBy(length()). */ + void clear(); - /** Potentially fallible append operations. */ + /** Clears and releases any heap-allocated storage. */ + void clearAndFree(); - /** - * This can take either a T& or a T&&. Given a T&&, it moves |u| into the - * vector, instead of copying it. If it fails, |u| is left unmoved. ("We are - * not amused.") - */ - template bool append(U&& u); + /** + * If true, appending |aNeeded| elements won't reallocate elements storage. + * This *doesn't* mean that infallibleAppend may be used! You still must + * reserve the extra space, even if this method indicates that appends won't + * need to reallocate elements storage. + */ + bool canAppendWithoutRealloc(size_t aNeeded) const; - template - bool appendAll(const VectorBase& u); - bool appendN(const T& t, size_t n); - template bool append(const U* begin, const U* end); - template bool append(const U* begin, size_t length); + /** Potentially fallible append operations. */ - /* - * Guaranteed-infallible append operations for use upon vectors whose - * memory has been pre-reserved. Don't use this if you haven't reserved the - * memory! - */ - template void infallibleAppend(U&& u) { - internalAppend(Forward(u)); - } - void infallibleAppendN(const T& t, size_t n) { - internalAppendN(t, n); - } - template void infallibleAppend(const U* aBegin, const U* aEnd) { - internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); - } - template void infallibleAppend(const U* aBegin, size_t aLength) { - internalAppend(aBegin, aLength); - } + /** + * This can take either a T& or a T&&. Given a T&&, it moves |aU| into the + * vector, instead of copying it. If it fails, |aU| is left unmoved. ("We are + * not amused.") + */ + template bool append(U&& aU); + + template + bool appendAll(const VectorBase& aU); + bool appendN(const T& aT, size_t aN); + template bool append(const U* aBegin, const U* aEnd); + template bool append(const U* aBegin, size_t aLength); - void popBack(); + /* + * Guaranteed-infallible append operations for use upon vectors whose + * memory has been pre-reserved. Don't use this if you haven't reserved the + * memory! + */ + template void infallibleAppend(U&& aU) + { + internalAppend(Forward(aU)); + } + void infallibleAppendN(const T& aT, size_t aN) + { + internalAppendN(aT, aN); + } + template void infallibleAppend(const U* aBegin, const U* aEnd) + { + internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); + } + template void infallibleAppend(const U* aBegin, size_t aLength) + { + internalAppend(aBegin, aLength); + } - T popCopy(); + void popBack(); - /** - * Transfers ownership of the internal buffer used by this vector to the - * caller. (It's the caller's responsibility to properly deallocate this - * buffer, in accordance with this vector's AllocPolicy.) After this call, - * the vector is empty. Since the returned buffer may need to be allocated - * (if the elements are currently stored in-place), the call can fail, - * returning nullptr. - * - * N.B. Although a T*, only the range [0, length()) is constructed. - */ - T* extractRawBuffer(); + T popCopy(); - /** - * Transfer ownership of an array of objects into the vector. The caller - * must have allocated the array in accordance with this vector's - * AllocPolicy. - * - * N.B. This call assumes that there are no uninitialized elements in the - * passed array. - */ - void replaceRawBuffer(T* p, size_t length); + /** + * Transfers ownership of the internal buffer used by this vector to the + * caller. (It's the caller's responsibility to properly deallocate this + * buffer, in accordance with this vector's AllocPolicy.) After this call, + * the vector is empty. Since the returned buffer may need to be allocated + * (if the elements are currently stored in-place), the call can fail, + * returning nullptr. + * + * N.B. Although a T*, only the range [0, length()) is constructed. + */ + T* extractRawBuffer(); + + /** + * Transfer ownership of an array of objects into the vector. The caller + * must have allocated the array in accordance with this vector's + * AllocPolicy. + * + * N.B. This call assumes that there are no uninitialized elements in the + * passed array. + */ + void replaceRawBuffer(T* aP, size_t aLength); + + /** + * Places |aVal| at position |aP|, shifting existing elements from |aP| onward + * one position higher. On success, |aP| should not be reused because it'll + * be a dangling pointer if reallocation of the vector storage occurred; the + * return value should be used instead. On failure, nullptr is returned. + * + * Example usage: + * + * if (!(p = vec.insert(p, val))) { + * + * } + * + * + * This is inherently a linear-time operation. Be careful! + */ + template + T* insert(T* aP, U&& aVal); - /** - * Places |val| at position |p|, shifting existing elements from |p| onward - * one position higher. On success, |p| should not be reused because it'll - * be a dangling pointer if reallocation of the vector storage occurred; the - * return value should be used instead. On failure, nullptr is returned. - * - * Example usage: - * - * if (!(p = vec.insert(p, val))) - * - * - * - * This is inherently a linear-time operation. Be careful! - */ - template - T* insert(T* p, U&& val); + /** + * Removes the element |aT|, which must fall in the bounds [begin, end), + * shifting existing elements from |aT + 1| onward one position lower. + */ + void erase(T* aT); - /** - * Removes the element |t|, which must fall in the bounds [begin, end), - * shifting existing elements from |t + 1| onward one position lower. - */ - void erase(T* t); + /** + * Removes the elements [|aBegin|, |aEnd|), which must fall in the bounds + * [begin, end), shifting existing elements from |aEnd + 1| onward to aBegin's + * old position. + */ + void erase(T* aBegin, T* aEnd); - /** - * Measure the size of the vector's heap-allocated storage. - */ - size_t sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const; + /** + * Measure the size of the vector's heap-allocated storage. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const; - /** - * Like sizeOfExcludingThis, but also measures the size of the vector - * object (which must be heap-allocated) itself. - */ - size_t sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const; + /** + * Like sizeOfExcludingThis, but also measures the size of the vector + * object (which must be heap-allocated) itself. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; - void swap(ThisVector& other); + void swap(ThisVector& aOther); - private: - VectorBase(const VectorBase&) MOZ_DELETE; - void operator=(const VectorBase&) MOZ_DELETE; +private: + VectorBase(const VectorBase&) MOZ_DELETE; + void operator=(const VectorBase&) MOZ_DELETE; - /* Move-construct/assign only from our derived class, ThisVector. */ - VectorBase(VectorBase&&) MOZ_DELETE; - void operator=(VectorBase&&) MOZ_DELETE; + /* Move-construct/assign only from our derived class, ThisVector. */ + VectorBase(VectorBase&&) MOZ_DELETE; + void operator=(VectorBase&&) MOZ_DELETE; }; /* This does the re-entrancy check plus several other sanity checks. */ #define MOZ_REENTRANCY_GUARD_ET_AL \ ReentrancyGuard g(*this); \ - MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == sInlineCapacity); \ + MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == kInlineCapacity); \ MOZ_ASSERT(reserved() <= mCapacity); \ MOZ_ASSERT(mLength <= reserved()); \ MOZ_ASSERT(mLength <= mCapacity) @@ -569,39 +618,39 @@ class VectorBase : private AllocPolicy template MOZ_ALWAYS_INLINE -VectorBase::VectorBase(AP ap) - : AP(ap), - mLength(0), - mCapacity(sInlineCapacity) +VectorBase::VectorBase(AP aAP) + : AP(aAP) + , mLength(0) + , mCapacity(kInlineCapacity) #ifdef DEBUG - , mReserved(sInlineCapacity), - entered(false) + , mReserved(kInlineCapacity) + , mEntered(false) #endif { - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); } /* Move constructor. */ template MOZ_ALWAYS_INLINE -VectorBase::VectorBase(TV&& rhs) - : AllocPolicy(Move(rhs)) +VectorBase::VectorBase(TV&& aRhs) + : AllocPolicy(Move(aRhs)) #ifdef DEBUG - , entered(false) + , mEntered(false) #endif { - mLength = rhs.mLength; - mCapacity = rhs.mCapacity; + mLength = aRhs.mLength; + mCapacity = aRhs.mCapacity; #ifdef DEBUG - mReserved = rhs.mReserved; + mReserved = aRhs.mReserved; #endif - if (rhs.usingInlineStorage()) { + if (aRhs.usingInlineStorage()) { /* We can't move the buffer over in this case, so copy elements. */ - mBegin = static_cast(storage.addr()); - Impl::moveConstruct(mBegin, rhs.beginNoCheck(), rhs.endNoCheck()); + mBegin = static_cast(mStorage.addr()); + Impl::moveConstruct(mBegin, aRhs.beginNoCheck(), aRhs.endNoCheck()); /* - * Leave rhs's mLength, mBegin, mCapacity, and mReserved as they are. + * Leave aRhs's mLength, mBegin, mCapacity, and mReserved as they are. * The elements in its in-line storage still need to be destroyed. */ } else { @@ -609,26 +658,25 @@ VectorBase::VectorBase(TV&& rhs) * Take src's buffer, and turn src into an empty vector using * in-line storage. */ - mBegin = rhs.mBegin; - rhs.mBegin = static_cast(rhs.storage.addr()); - rhs.mCapacity = sInlineCapacity; - rhs.mLength = 0; + mBegin = aRhs.mBegin; + aRhs.mBegin = static_cast(aRhs.mStorage.addr()); + aRhs.mCapacity = kInlineCapacity; + aRhs.mLength = 0; #ifdef DEBUG - rhs.mReserved = sInlineCapacity; + aRhs.mReserved = kInlineCapacity; #endif } } /* Move assignment. */ template -MOZ_ALWAYS_INLINE -TV& -VectorBase::operator=(TV&& rhs) +MOZ_ALWAYS_INLINE TV& +VectorBase::operator=(TV&& aRhs) { - MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + MOZ_ASSERT(this != &aRhs, "self-move assignment is prohibited"); TV* tv = static_cast(this); tv->~TV(); - new(tv) TV(Move(rhs)); + new(tv) TV(Move(aRhs)); return *tv; } @@ -638,26 +686,28 @@ VectorBase::~VectorBase() { MOZ_REENTRANCY_GUARD_ET_AL; Impl::destroy(beginNoCheck(), endNoCheck()); - if (!usingInlineStorage()) + if (!usingInlineStorage()) { this->free_(beginNoCheck()); + } } /* - * This function will create a new heap buffer with capacity newCap, + * This function will create a new heap buffer with capacity aNewCap, * move all elements in the inline buffer to this new buffer, * and fail on OOM. */ template inline bool -VectorBase::convertToHeapStorage(size_t newCap) +VectorBase::convertToHeapStorage(size_t aNewCap) { MOZ_ASSERT(usingInlineStorage()); /* Allocate buffer. */ - MOZ_ASSERT(!detail::CapacityHasExcessSpace(newCap)); - T* newBuf = reinterpret_cast(this->malloc_(newCap * sizeof(T))); - if (!newBuf) + MOZ_ASSERT(!detail::CapacityHasExcessSpace(aNewCap)); + T* newBuf = reinterpret_cast(this->malloc_(aNewCap * sizeof(T))); + if (!newBuf) { return false; + } /* Copy inline elements into heap buffer. */ Impl::moveConstruct(newBuf, beginNoCheck(), endNoCheck()); @@ -666,15 +716,15 @@ VectorBase::convertToHeapStorage(size_t newCap) /* Switch in heap buffer. */ mBegin = newBuf; /* mLength is unchanged. */ - mCapacity = newCap; + mCapacity = aNewCap; return true; } template MOZ_NEVER_INLINE bool -VectorBase::growStorageBy(size_t incr) +VectorBase::growStorageBy(size_t aIncr) { - MOZ_ASSERT(mLength + incr > mCapacity); + MOZ_ASSERT(mLength + aIncr > mCapacity); MOZ_ASSERT_IF(!usingInlineStorage(), !detail::CapacityHasExcessSpace(mCapacity)); @@ -688,11 +738,11 @@ VectorBase::growStorageBy(size_t incr) size_t newCap; - if (incr == 1) { + if (aIncr == 1) { if (usingInlineStorage()) { /* This case occurs in ~70--80% of the calls to this function. */ size_t newSize = - tl::RoundUpPow2<(sInlineCapacity + 1) * sizeof(T)>::value; + tl::RoundUpPow2<(kInlineCapacity + 1) * sizeof(T)>::value; newCap = newSize / sizeof(T); goto convert; } @@ -725,13 +775,14 @@ VectorBase::growStorageBy(size_t incr) * then there might be space for one more element. */ newCap = mLength * 2; - if (detail::CapacityHasExcessSpace(newCap)) + if (detail::CapacityHasExcessSpace(newCap)) { newCap += 1; + } } else { /* This case occurs in ~2% of the calls to this function. */ - size_t newMinCap = mLength + incr; + size_t newMinCap = mLength + aIncr; - /* Did mLength + incr overflow? Will newCap * sizeof(T) overflow? */ + /* Did mLength + aIncr overflow? Will newCap * sizeof(T) overflow? */ if (newMinCap < mLength || newMinCap & tl::MulOverflowMask<2 * sizeof(T)>::value) { @@ -745,7 +796,7 @@ VectorBase::growStorageBy(size_t incr) } if (usingInlineStorage()) { - convert: +convert: return convertToHeapStorage(newCap); } @@ -755,34 +806,37 @@ VectorBase::growStorageBy(size_t incr) template inline bool -VectorBase::initCapacity(size_t request) +VectorBase::initCapacity(size_t aRequest) { MOZ_ASSERT(empty()); MOZ_ASSERT(usingInlineStorage()); - if (request == 0) + if (aRequest == 0) { return true; - T* newbuf = reinterpret_cast(this->malloc_(request * sizeof(T))); - if (!newbuf) + } + T* newbuf = reinterpret_cast(this->malloc_(aRequest * sizeof(T))); + if (!newbuf) { return false; + } mBegin = newbuf; - mCapacity = request; + mCapacity = aRequest; #ifdef DEBUG - mReserved = request; + mReserved = aRequest; #endif return true; } template inline bool -VectorBase::reserve(size_t request) +VectorBase::reserve(size_t aRequest) { MOZ_REENTRANCY_GUARD_ET_AL; - if (request > mCapacity && !growStorageBy(request - mLength)) + if (aRequest > mCapacity && !growStorageBy(aRequest - mLength)) { return false; - + } #ifdef DEBUG - if (request > mReserved) - mReserved = request; + if (aRequest > mReserved) { + mReserved = aRequest; + } MOZ_ASSERT(mLength <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); #endif @@ -791,69 +845,73 @@ VectorBase::reserve(size_t request) template inline void -VectorBase::shrinkBy(size_t incr) +VectorBase::shrinkBy(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - MOZ_ASSERT(incr <= mLength); - Impl::destroy(endNoCheck() - incr, endNoCheck()); - mLength -= incr; + MOZ_ASSERT(aIncr <= mLength); + Impl::destroy(endNoCheck() - aIncr, endNoCheck()); + mLength -= aIncr; } template MOZ_ALWAYS_INLINE bool -VectorBase::growBy(size_t incr) +VectorBase::growBy(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - if (incr > mCapacity - mLength && !growStorageBy(incr)) + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { return false; - - MOZ_ASSERT(mLength + incr <= mCapacity); - T* newend = endNoCheck() + incr; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + T* newend = endNoCheck() + aIncr; Impl::initialize(endNoCheck(), newend); - mLength += incr; + mLength += aIncr; #ifdef DEBUG - if (mLength > mReserved) + if (mLength > mReserved) { mReserved = mLength; + } #endif return true; } template MOZ_ALWAYS_INLINE bool -VectorBase::growByUninitialized(size_t incr) +VectorBase::growByUninitialized(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - if (incr > mCapacity - mLength && !growStorageBy(incr)) + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { return false; - - MOZ_ASSERT(mLength + incr <= mCapacity); - mLength += incr; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + mLength += aIncr; #ifdef DEBUG - if (mLength > mReserved) + if (mLength > mReserved) { mReserved = mLength; + } #endif return true; } template inline bool -VectorBase::resize(size_t newLength) +VectorBase::resize(size_t aNewLength) { size_t curLength = mLength; - if (newLength > curLength) - return growBy(newLength - curLength); - shrinkBy(curLength - newLength); + if (aNewLength > curLength) { + return growBy(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); return true; } template MOZ_ALWAYS_INLINE bool -VectorBase::resizeUninitialized(size_t newLength) +VectorBase::resizeUninitialized(size_t aNewLength) { size_t curLength = mLength; - if (newLength > curLength) - return growByUninitialized(newLength - curLength); - shrinkBy(curLength - newLength); + if (aNewLength > curLength) { + return growByUninitialized(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); return true; } @@ -872,166 +930,186 @@ VectorBase::clearAndFree() { clear(); - if (usingInlineStorage()) + if (usingInlineStorage()) { return; - + } this->free_(beginNoCheck()); - mBegin = static_cast(storage.addr()); - mCapacity = sInlineCapacity; + mBegin = static_cast(mStorage.addr()); + mCapacity = kInlineCapacity; #ifdef DEBUG - mReserved = sInlineCapacity; + mReserved = kInlineCapacity; #endif } template inline bool -VectorBase::canAppendWithoutRealloc(size_t needed) const +VectorBase::canAppendWithoutRealloc(size_t aNeeded) const { - return mLength + needed <= mCapacity; + return mLength + aNeeded <= mCapacity; } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppendAll(const VectorBase& other) +VectorBase::internalAppendAll( + const VectorBase& aOther) { - internalAppend(other.begin(), other.length()); + internalAppend(aOther.begin(), aOther.length()); } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppend(U&& u) +VectorBase::internalAppend(U&& aU) { MOZ_ASSERT(mLength + 1 <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - new(endNoCheck()) T(Forward(u)); + new(endNoCheck()) T(Forward(aU)); ++mLength; } template MOZ_ALWAYS_INLINE bool -VectorBase::appendN(const T& t, size_t needed) +VectorBase::appendN(const T& aT, size_t aNeeded) { MOZ_REENTRANCY_GUARD_ET_AL; - if (mLength + needed > mCapacity && !growStorageBy(needed)) + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { return false; - + } #ifdef DEBUG - if (mLength + needed > mReserved) - mReserved = mLength + needed; + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } #endif - internalAppendN(t, needed); + internalAppendN(aT, aNeeded); return true; } template MOZ_ALWAYS_INLINE void -VectorBase::internalAppendN(const T& t, size_t needed) +VectorBase::internalAppendN(const T& aT, size_t aNeeded) { - MOZ_ASSERT(mLength + needed <= mReserved); + MOZ_ASSERT(mLength + aNeeded <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - Impl::copyConstructN(endNoCheck(), needed, t); - mLength += needed; + Impl::copyConstructN(endNoCheck(), aNeeded, aT); + mLength += aNeeded; } template template inline T* -VectorBase::insert(T* p, U&& val) +VectorBase::insert(T* aP, U&& aVal) { - MOZ_ASSERT(begin() <= p); - MOZ_ASSERT(p <= end()); - size_t pos = p - begin(); + MOZ_ASSERT(begin() <= aP); + MOZ_ASSERT(aP <= end()); + size_t pos = aP - begin(); MOZ_ASSERT(pos <= mLength); size_t oldLength = mLength; if (pos == oldLength) { - if (!append(Forward(val))) + if (!append(Forward(aVal))) { return nullptr; + } } else { T oldBack = Move(back()); - if (!append(Move(oldBack))) /* Dup the last element. */ + if (!append(Move(oldBack))) { /* Dup the last element. */ return nullptr; - for (size_t i = oldLength; i > pos; --i) + } + for (size_t i = oldLength; i > pos; --i) { (*this)[i] = Move((*this)[i - 1]); - (*this)[pos] = Forward(val); + } + (*this)[pos] = Forward(aVal); } return begin() + pos; } template inline void -VectorBase::erase(T* it) +VectorBase::erase(T* aIt) { - MOZ_ASSERT(begin() <= it); - MOZ_ASSERT(it < end()); - while (it + 1 < end()) { - *it = *(it + 1); - ++it; + MOZ_ASSERT(begin() <= aIt); + MOZ_ASSERT(aIt < end()); + while (aIt + 1 < end()) { + *aIt = Move(*(aIt + 1)); + ++aIt; } - popBack(); + popBack(); +} + +template +inline void +VectorBase::erase(T* aBegin, T* aEnd) +{ + MOZ_ASSERT(begin() <= aBegin); + MOZ_ASSERT(aBegin <= aEnd); + MOZ_ASSERT(aEnd <= end()); + while (aEnd < end()) { + *aBegin++ = Move(*aEnd++); + } + shrinkBy(aEnd - aBegin); } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(const U* insBegin, const U* insEnd) +VectorBase::append(const U* aInsBegin, const U* aInsEnd) { MOZ_REENTRANCY_GUARD_ET_AL; - size_t needed = PointerRangeSize(insBegin, insEnd); - if (mLength + needed > mCapacity && !growStorageBy(needed)) + size_t aNeeded = PointerRangeSize(aInsBegin, aInsEnd); + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { return false; - + } #ifdef DEBUG - if (mLength + needed > mReserved) - mReserved = mLength + needed; + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } #endif - internalAppend(insBegin, needed); + internalAppend(aInsBegin, aNeeded); return true; } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppend(const U* insBegin, size_t insLength) +VectorBase::internalAppend(const U* aInsBegin, size_t aInsLength) { - MOZ_ASSERT(mLength + insLength <= mReserved); + MOZ_ASSERT(mLength + aInsLength <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - Impl::copyConstruct(endNoCheck(), insBegin, insBegin + insLength); - mLength += insLength; + Impl::copyConstruct(endNoCheck(), aInsBegin, aInsBegin + aInsLength); + mLength += aInsLength; } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(U&& u) +VectorBase::append(U&& aU) { MOZ_REENTRANCY_GUARD_ET_AL; - if (mLength == mCapacity && !growStorageBy(1)) + if (mLength == mCapacity && !growStorageBy(1)) { return false; - + } #ifdef DEBUG - if (mLength + 1 > mReserved) + if (mLength + 1 > mReserved) { mReserved = mLength + 1; + } #endif - internalAppend(Forward(u)); + internalAppend(Forward(aU)); return true; } template template MOZ_ALWAYS_INLINE bool -VectorBase::appendAll(const VectorBase& other) +VectorBase::appendAll(const VectorBase& aOther) { - return append(other.begin(), other.length()); + return append(aOther.begin(), aOther.length()); } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(const U *insBegin, size_t insLength) +VectorBase::append(const U* aInsBegin, size_t aInsLength) { - return append(insBegin, insBegin + insLength); + return append(aInsBegin, aInsBegin + aInsLength); } template @@ -1060,19 +1138,20 @@ VectorBase::extractRawBuffer() T* ret; if (usingInlineStorage()) { ret = reinterpret_cast(this->malloc_(mLength * sizeof(T))); - if (!ret) + if (!ret) { return nullptr; + } Impl::copyConstruct(ret, beginNoCheck(), endNoCheck()); Impl::destroy(beginNoCheck(), endNoCheck()); /* mBegin, mCapacity are unchanged. */ mLength = 0; } else { ret = mBegin; - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); mLength = 0; - mCapacity = sInlineCapacity; + mCapacity = kInlineCapacity; #ifdef DEBUG - mReserved = sInlineCapacity; + mReserved = kInlineCapacity; #endif } return ret; @@ -1080,30 +1159,31 @@ VectorBase::extractRawBuffer() template inline void -VectorBase::replaceRawBuffer(T* p, size_t aLength) +VectorBase::replaceRawBuffer(T* aP, size_t aLength) { MOZ_REENTRANCY_GUARD_ET_AL; /* Destroy what we have. */ Impl::destroy(beginNoCheck(), endNoCheck()); - if (!usingInlineStorage()) + if (!usingInlineStorage()) { this->free_(beginNoCheck()); + } /* Take in the new buffer. */ - if (aLength <= sInlineCapacity) { + if (aLength <= kInlineCapacity) { /* - * We convert to inline storage if possible, even though p might + * We convert to inline storage if possible, even though aP might * otherwise be acceptable. Maybe this behaviour should be * specifiable with an argument to this function. */ - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); mLength = aLength; - mCapacity = sInlineCapacity; - Impl::moveConstruct(mBegin, p, p + aLength); - Impl::destroy(p, p + aLength); - this->free_(p); + mCapacity = kInlineCapacity; + Impl::moveConstruct(mBegin, aP, aP + aLength); + Impl::destroy(aP, aP + aLength); + this->free_(aP); } else { - mBegin = p; + mBegin = aP; mLength = aLength; mCapacity = aLength; } @@ -1114,42 +1194,42 @@ VectorBase::replaceRawBuffer(T* p, size_t aLength) template inline size_t -VectorBase::sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const +VectorBase::sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { - return usingInlineStorage() ? 0 : mallocSizeOf(beginNoCheck()); + return usingInlineStorage() ? 0 : aMallocSizeOf(beginNoCheck()); } template inline size_t -VectorBase::sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const +VectorBase::sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { - return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); } template inline void -VectorBase::swap(TV& other) +VectorBase::swap(TV& aOther) { static_assert(N == 0, "still need to implement this for N != 0"); // This only works when inline storage is always empty. - if (!usingInlineStorage() && other.usingInlineStorage()) { - other.mBegin = mBegin; + if (!usingInlineStorage() && aOther.usingInlineStorage()) { + aOther.mBegin = mBegin; mBegin = inlineStorage(); - } else if (usingInlineStorage() && !other.usingInlineStorage()) { - mBegin = other.mBegin; - other.mBegin = other.inlineStorage(); - } else if (!usingInlineStorage() && !other.usingInlineStorage()) { - Swap(mBegin, other.mBegin); + } else if (usingInlineStorage() && !aOther.usingInlineStorage()) { + mBegin = aOther.mBegin; + aOther.mBegin = aOther.inlineStorage(); + } else if (!usingInlineStorage() && !aOther.usingInlineStorage()) { + Swap(mBegin, aOther.mBegin); } else { // This case is a no-op, since we'd set both to use their inline storage. } - Swap(mLength, other.mLength); - Swap(mCapacity, other.mCapacity); + Swap(mLength, aOther.mLength); + Swap(mCapacity, aOther.mCapacity); #ifdef DEBUG - Swap(mReserved, other.mReserved); + Swap(mReserved, aOther.mReserved); #endif } @@ -1180,14 +1260,15 @@ class Vector AllocPolicy, Vector > { - typedef VectorBase Base; - - public: - Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} - Vector(Vector&& vec) : Base(Move(vec)) {} - Vector& operator=(Vector&& vec) { - return Base::operator=(Move(vec)); - } + typedef VectorBase Base; + +public: + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + Vector(Vector&& vec) : Base(Move(vec)) {} + Vector& operator=(Vector&& aOther) + { + return Base::operator=(Move(aOther)); + } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/WeakPtr.h b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/WeakPtr.h index 0165e3a017..07f00bc295 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/WeakPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/WeakPtr.h @@ -14,21 +14,29 @@ * the WeakPtrs to it and allows the WeakReference to live beyond the lifetime * of 'Foo'. * + * PLEASE NOTE: This weak pointer implementation is not thread-safe. + * + * Note that when deriving from SupportsWeakPtr you should add + * MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public section of your + * class, where ClassName is the name of your class. + * * The overhead of WeakPtr is that accesses to 'Foo' becomes an additional * dereference, and an additional heap allocated pointer sized object shared * between all of the WeakPtrs. * * Example of usage: * - * // To have a class C support weak pointers, inherit from SupportsWeakPtr. + * // To have a class C support weak pointers, inherit from + * // SupportsWeakPtr. * class C : public SupportsWeakPtr * { - * public: - * int num; - * void act(); + * public: + * MOZ_DECLARE_REFCOUNTED_TYPENAME(C) + * int mNum; + * void act(); * }; * - * C* ptr = new C(); + * C* ptr = new C(); * * // Get weak pointers to ptr. The first time asWeakPtr is called * // a reference counted WeakReference object is created that @@ -39,7 +47,7 @@ * * // Test a weak pointer for validity before using it. * if (weak) { - * weak->num = 17; + * weak->mNum = 17; * weak->act(); * } * @@ -59,11 +67,14 @@ #ifndef mozilla_WeakPtr_h #define mozilla_WeakPtr_h +#include "mozilla/ArrayUtils.h" #include "mozilla/Assertions.h" #include "mozilla/NullPtr.h" #include "mozilla/RefPtr.h" #include "mozilla/TypeTraits.h" +#include + namespace mozilla { template class WeakPtrBase; @@ -71,23 +82,48 @@ template class SupportsWeakPtrBase; namespace detail { -// This can live beyond the lifetime of the class derived from SupportsWeakPtrBase. +// This can live beyond the lifetime of the class derived from +// SupportsWeakPtrBase. template class WeakReference : public ::mozilla::RefCounted > { - public: - explicit WeakReference(T* p) : ptr(p) {} - T* get() const { - return ptr; - } - - private: - friend class WeakPtrBase >; - friend class SupportsWeakPtrBase >; - void detach() { - ptr = nullptr; - } - T* ptr; +public: + explicit WeakReference(T* p) : mPtr(p) {} + + T* get() const { return mPtr; } + +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#ifdef XP_WIN +#define snprintf _snprintf +#endif + const char* typeName() const + { + static char nameBuffer[1024]; + const char* innerType = mPtr->typeName(); + // We could do fancier length checks at runtime, but innerType is + // controlled by us so we can ensure that this never causes a buffer + // overflow by this assertion. + MOZ_ASSERT(strlen(innerType) + sizeof("WeakReference<>") < + ArrayLength(nameBuffer), + "Exceedingly large type name"); + snprintf(nameBuffer, ArrayLength(nameBuffer), "WeakReference<%s>", + innerType); + // This is usually not OK, but here we are returning a pointer to a static + // buffer which will immediately be used by the caller. + return nameBuffer; + } + + size_t typeSize() const { return sizeof(*this); } +#undef snprintf +#endif + +private: + friend class WeakPtrBase >; + friend class SupportsWeakPtrBase >; + + void detach() { mPtr = nullptr; } + + T* mPtr; }; } // namespace detail @@ -95,25 +131,29 @@ class WeakReference : public ::mozilla::RefCounted > template class SupportsWeakPtrBase { - public: - WeakPtrBase asWeakPtr() { - if (!weakRef) - weakRef = new WeakReference(static_cast(this)); - return WeakPtrBase(weakRef); +public: + WeakPtrBase asWeakPtr() + { + if (!weakRef) { + weakRef = new WeakReference(static_cast(this)); } - - protected: - ~SupportsWeakPtrBase() { - static_assert(IsBaseOf, T>::value, - "T must derive from SupportsWeakPtrBase"); - if (weakRef) - weakRef->detach(); + return WeakPtrBase(weakRef); + } + +protected: + ~SupportsWeakPtrBase() + { + static_assert(IsBaseOf, T>::value, + "T must derive from SupportsWeakPtrBase"); + if (weakRef) { + weakRef->detach(); } + } - private: - friend class WeakPtrBase; +private: + friend class WeakPtrBase; - RefPtr weakRef; + RefPtr weakRef; }; template @@ -124,42 +164,37 @@ class SupportsWeakPtr : public SupportsWeakPtrBase > template class WeakPtrBase { - public: - WeakPtrBase(const WeakPtrBase& o) : ref(o.ref) {} - // Ensure that ref is dereferenceable in the uninitialized state - WeakPtrBase() : ref(new WeakReference(nullptr)) {} +public: + WeakPtrBase(const WeakPtrBase& aOther) + : mRef(aOther.mRef) + {} - operator T*() const { - return ref->get(); - } - T& operator*() const { - return *ref->get(); - } + // Ensure that mRef is dereferenceable in the uninitialized state. + WeakPtrBase() : mRef(new WeakReference(nullptr)) {} - T* operator->() const { - return ref->get(); - } + operator T*() const { return mRef->get(); } + T& operator*() const { return *mRef->get(); } - T* get() const { - return ref->get(); - } + T* operator->() const { return mRef->get(); } + + T* get() const { return mRef->get(); } - private: - friend class SupportsWeakPtrBase; +private: + friend class SupportsWeakPtrBase; - explicit WeakPtrBase(const RefPtr &o) : ref(o) {} + explicit WeakPtrBase(const RefPtr &aOther) : mRef(aOther) {} - RefPtr ref; + RefPtr mRef; }; template class WeakPtr : public WeakPtrBase > { - typedef WeakPtrBase > Base; - public: - WeakPtr(const WeakPtr& o) : Base(o) {} - WeakPtr(const Base& o) : Base(o) {} - WeakPtr() {} + typedef WeakPtrBase > Base; +public: + WeakPtr(const WeakPtr& aOther) : Base(aOther) {} + MOZ_IMPLICIT WeakPtr(const Base& aOther) : Base(aOther) {} + WeakPtr() {} }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js-config.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js-config.h index 1aeadbd000..d055574fba 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js-config.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js-config.h @@ -12,6 +12,12 @@ This header file is generated by the SpiderMonkey configure script, and installed along with jsapi.h. */ +/* Define to 1 if SpiderMonkey is in debug mode. */ +/* #undef JS_DEBUG */ + +/* Define to 1 if SpiderMonkey should not use struct types in debug builds. */ +/* #undef JS_NO_JSVAL_JSID_STRUCT_TYPES */ + /* Define to 1 if SpiderMonkey should support multi-threaded clients. */ /* #undef JS_THREADSAFE */ @@ -34,8 +40,14 @@ useable. See jscpucfg.h. */ /* #undef JS_HAVE_SYS_ISA_DEFS_H */ +/* Define to 1 if SpiderMonkey is in NUNBOX32 mode. */ +/* #undef JS_NUNBOX32 */ + +/* Define to 1 if SpiderMonkey is in PUNBOX64 mode. */ +#define JS_PUNBOX64 1 + /* MOZILLA JSAPI version number components */ -#define MOZJS_MAJOR_VERSION 28 -#define MOZJS_MINOR_VERSION 0 +#define MOZJS_MAJOR_VERSION 33 +#define MOZJS_MINOR_VERSION 1 #endif /* js_config_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js.msg b/frameworks/js-bindings/external/spidermonkey/include/linux/js.msg index 5a8344163b..d342ad4506 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js.msg +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js.msg @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -105,7 +105,7 @@ MSG_DEF(JSMSG_BAD_DESTRUCT_ASS, 51, 0, JSEXN_REFERENCEERR, "invalid destr MSG_DEF(JSMSG_PAREN_AFTER_LET, 52, 0, JSEXN_SYNTAXERR, "missing ) after let head") MSG_DEF(JSMSG_CURLY_AFTER_LET, 53, 0, JSEXN_SYNTAXERR, "missing } after let block") MSG_DEF(JSMSG_MISSING_PAREN, 54, 0, JSEXN_SYNTAXERR, "unterminated parenthetical") -MSG_DEF(JSMSG_UNTERM_CLASS, 55, 1, JSEXN_SYNTAXERR, "unterminated character class {0}") +MSG_DEF(JSMSG_UNTERM_CLASS, 55, 0, JSEXN_SYNTAXERR, "unterminated character class") MSG_DEF(JSMSG_TRAILING_SLASH, 56, 0, JSEXN_SYNTAXERR, "trailing \\ in regular expression") MSG_DEF(JSMSG_BAD_CLASS_RANGE, 57, 0, JSEXN_SYNTAXERR, "invalid range in character class") MSG_DEF(JSMSG_BAD_REGEXP_FLAG, 58, 1, JSEXN_SYNTAXERR, "invalid regular expression flag {0}") @@ -223,30 +223,30 @@ MSG_DEF(JSMSG_TOO_MANY_CATCH_VARS, 169, 0, JSEXN_SYNTAXERR, "too many catch v MSG_DEF(JSMSG_NEGATIVE_REPETITION_COUNT, 170, 0, JSEXN_RANGEERR, "repeat count must be non-negative") MSG_DEF(JSMSG_INVALID_FOR_OF_INIT, 171, 0, JSEXN_SYNTAXERR, "for-of loop variable declaration may not have an initializer") MSG_DEF(JSMSG_INVALID_MAP_ITERABLE, 172, 0, JSEXN_TYPEERR, "iterable for map should have array-like objects") -MSG_DEF(JSMSG_UNUSED173, 173, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED174, 174, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_NOT_A_CODEPOINT, 173, 1, JSEXN_RANGEERR, "{0} is not a valid code point") +MSG_DEF(JSMSG_BRACKET_AFTER_ARRAY_COMPREHENSION, 174, 0, JSEXN_SYNTAXERR, "missing ] after array comprehension") MSG_DEF(JSMSG_NESTING_GENERATOR, 175, 0, JSEXN_TYPEERR, "already executing generator") -MSG_DEF(JSMSG_UNUSED176, 176, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED177, 177, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED178, 178, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED179, 179, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED180, 180, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED181, 181, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_PAREN_AFTER_FOR_OF_ITERABLE, 176, 0, JSEXN_SYNTAXERR, "missing ) after for-of iterable") +MSG_DEF(JSMSG_INVALID_NORMALIZE_FORM, 177, 0, JSEXN_RANGEERR, "form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD'") +MSG_DEF(JSMSG_NOTHING_TO_REPEAT, 178, 0, JSEXN_SYNTAXERR, "nothing to repeat") +MSG_DEF(JSMSG_INVALID_GROUP, 179, 0, JSEXN_SYNTAXERR, "invalid regexp group") +MSG_DEF(JSMSG_ESCAPE_AT_END_OF_REGEXP, 180, 0, JSEXN_SYNTAXERR, "\\ at end of pattern") +MSG_DEF(JSMSG_NUMBERS_OUT_OF_ORDER, 181, 0, JSEXN_SYNTAXERR, "numbers out of order in {} quantifier.") MSG_DEF(JSMSG_BAD_GENERATOR_SEND, 182, 1, JSEXN_TYPEERR, "attempt to send {0} to newborn generator") MSG_DEF(JSMSG_SC_NOT_TRANSFERABLE, 183, 0, JSEXN_TYPEERR, "invalid transferable array for structured clone") MSG_DEF(JSMSG_SC_DUP_TRANSFERABLE, 184, 0, JSEXN_TYPEERR, "duplicate transferable for structured clone") MSG_DEF(JSMSG_CANT_REPORT_AS_NON_EXTENSIBLE, 185, 0, JSEXN_TYPEERR, "proxy can't report an extensible object as non-extensible") -MSG_DEF(JSMSG_UNUSED186, 186, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_SYMBOL_TO_STRING, 186, 0, JSEXN_TYPEERR, "can't convert symbol to string") MSG_DEF(JSMSG_UNUSED187, 187, 0, JSEXN_NONE, "") MSG_DEF(JSMSG_INCOMPATIBLE_METHOD, 188, 3, JSEXN_TYPEERR, "{0} {1} called on incompatible {2}") -MSG_DEF(JSMSG_UNUSED189, 189, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_SYMBOL_TO_PRIMITIVE, 189, 0, JSEXN_TYPEERR, "can't convert symbol object to primitive") MSG_DEF(JSMSG_UNUSED190, 190, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED191, 191, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED192, 192, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_BAD_INDEX, 191, 0, JSEXN_RANGEERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_SELFHOSTED_TOP_LEVEL_LET,192,0, JSEXN_SYNTAXERR, "self-hosted code cannot contain top-level 'let' declarations") MSG_DEF(JSMSG_BAD_FOR_EACH_LOOP, 193, 0, JSEXN_SYNTAXERR, "invalid for each loop") -MSG_DEF(JSMSG_OBJECT_WATCH_DEPRECATED,194, 0, JSEXN_TYPEERR, "Object.prototype.watch and unwatch are very slow, non-standard, and deprecated; use a getter/setter instead") -MSG_DEF(JSMSG_UNUSED195, 195, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED196, 196, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_OBJECT_WATCH_DEPRECATED,194, 0, JSEXN_NONE, "Object.prototype.watch and unwatch are very slow, non-standard, and deprecated; use a getter/setter instead") +MSG_DEF(JSMSG_TYPE_ERR_BAD_ARGS, 195, 0, JSEXN_TYPEERR, "invalid arguments") +MSG_DEF(JSMSG_REDECLARED_CATCH_IDENTIFIER, 196, 1, JSEXN_TYPEERR, "redeclaration of identifier '{0}' in catch") MSG_DEF(JSMSG_INTERNAL_INTL_ERROR, 197, 0, JSEXN_ERR, "internal error while computing Intl data") MSG_DEF(JSMSG_DEFAULT_LOCALE_ERROR, 198, 0, JSEXN_ERR, "internal error getting the default locale") MSG_DEF(JSMSG_TOO_MANY_LOCALS, 199, 0, JSEXN_SYNTAXERR, "too many local variables") @@ -260,25 +260,25 @@ MSG_DEF(JSMSG_USER_DEFINED_ERROR, 206, 0, JSEXN_ERR, "JS_ReportError was cal MSG_DEF(JSMSG_WRONG_CONSTRUCTOR, 207, 1, JSEXN_TYPEERR, "wrong constructor called for {0}") MSG_DEF(JSMSG_BAD_GENERATOR_RETURN, 208, 1, JSEXN_TYPEERR, "generator function {0} returns a value") MSG_DEF(JSMSG_BAD_ANON_GENERATOR_RETURN, 209, 0, JSEXN_TYPEERR, "anonymous generator function returns a value") -MSG_DEF(JSMSG_UNUSED210, 210, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_PROTO_SETTING_SLOW, 210, 0, JSEXN_NONE, "mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create") MSG_DEF(JSMSG_IN_AFTER_FOR_NAME, 211, 0, JSEXN_SYNTAXERR, "missing 'in' or 'of' after for") MSG_DEF(JSMSG_BAD_TRAP_RETURN_VALUE, 212, 2, JSEXN_TYPEERR,"trap {1} for {0} returned a primitive value") -MSG_DEF(JSMSG_UNUSED213, 213, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_OF_AFTER_FOR_NAME, 213, 0, JSEXN_SYNTAXERR, "missing 'of' after for") MSG_DEF(JSMSG_BAD_GENERATOR_YIELD, 214, 1, JSEXN_TYPEERR, "yield from closing generator {0}") MSG_DEF(JSMSG_BAD_GENERATOR_SYNTAX, 215, 1, JSEXN_SYNTAXERR, "{0} expression must be parenthesized") MSG_DEF(JSMSG_ARRAY_COMP_LEFTSIDE, 216, 0, JSEXN_SYNTAXERR, "invalid array comprehension left-hand side") -MSG_DEF(JSMSG_UNUSED217, 217, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_LET_COMP_BINDING, 217, 0, JSEXN_SYNTAXERR, "'let' is not a valid name for a comprehension variable") MSG_DEF(JSMSG_EMPTY_ARRAY_REDUCE, 218, 0, JSEXN_TYPEERR, "reduce of empty array with no initial value") MSG_DEF(JSMSG_BAD_SYMBOL, 219, 1, JSEXN_TYPEERR, "{0} is not a well-known @@-symbol") MSG_DEF(JSMSG_BAD_DELETE_OPERAND, 220, 0, JSEXN_REFERENCEERR, "invalid delete operand") MSG_DEF(JSMSG_BAD_INCOP_OPERAND, 221, 0, JSEXN_REFERENCEERR, "invalid increment/decrement operand") MSG_DEF(JSMSG_UNEXPECTED_TYPE, 222, 2, JSEXN_TYPEERR, "{0} is {1}") MSG_DEF(JSMSG_LET_DECL_NOT_IN_BLOCK, 223, 0, JSEXN_SYNTAXERR, "let declaration not directly within block") -MSG_DEF(JSMSG_BAD_OBJECT_INIT, 224, 0, JSEXN_SYNTAXERR, "invalid object initializer") +MSG_DEF(JSMSG_UNUSED224, 224, 0, JSEXN_NONE, "") MSG_DEF(JSMSG_CANT_SET_ARRAY_ATTRS, 225, 0, JSEXN_INTERNALERR, "can't set attributes on indexed array properties") MSG_DEF(JSMSG_EVAL_ARITY, 226, 0, JSEXN_TYPEERR, "eval accepts only one parameter") MSG_DEF(JSMSG_MISSING_FUN_ARG, 227, 2, JSEXN_TYPEERR, "missing argument {0} when calling function {1}") -MSG_DEF(JSMSG_JSON_BAD_PARSE, 228, 1, JSEXN_SYNTAXERR, "JSON.parse: {0}") +MSG_DEF(JSMSG_JSON_BAD_PARSE, 228, 3, JSEXN_SYNTAXERR, "JSON.parse: {0} at line {1} column {2} of the JSON data") MSG_DEF(JSMSG_JSON_BAD_STRINGIFY, 229, 0, JSEXN_ERR, "JSON.stringify") MSG_DEF(JSMSG_NOT_CALLABLE_OR_UNDEFINED, 230, 0, JSEXN_TYPEERR, "value is not a function or undefined") MSG_DEF(JSMSG_NOT_NONNULL_OBJECT, 231, 0, JSEXN_TYPEERR, "value is not a non-null object") @@ -353,11 +353,11 @@ MSG_DEF(JSMSG_REST_WITH_DEFAULT, 299, 0, JSEXN_SYNTAXERR, "rest parameter m MSG_DEF(JSMSG_NONDEFAULT_FORMAL_AFTER_DEFAULT, 300, 0, JSEXN_SYNTAXERR, "parameter(s) with default followed by parameter without default") MSG_DEF(JSMSG_YIELD_IN_DEFAULT, 301, 0, JSEXN_SYNTAXERR, "yield in default expression") MSG_DEF(JSMSG_INTRINSIC_NOT_DEFINED, 302, 1, JSEXN_REFERENCEERR, "no intrinsic function {0}") -MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 303, 2, JSEXN_ERR, "{0} is being assigned a {1}, but already has one") -MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 304, 1, JSEXN_RANGEERR, "invalid ParallelArray{0} argument") -MSG_DEF(JSMSG_PAR_ARRAY_BAD_PARTITION, 305, 0, JSEXN_ERR, "argument must be divisible by outermost dimension") -MSG_DEF(JSMSG_PAR_ARRAY_REDUCE_EMPTY, 306, 0, JSEXN_ERR, "cannot reduce ParallelArray object whose outermost dimension is empty") -MSG_DEF(JSMSG_PAR_ARRAY_ALREADY_FLAT, 307, 0, JSEXN_ERR, "cannot flatten 1-dimensional ParallelArray object") +MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 303, 2, JSEXN_NONE, "{0} is being assigned a {1}, but already has one") +MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 304, 0, JSEXN_RANGEERR, "invalid parallel method argument") +MSG_DEF(JSMSG_REGEXP_RUNTIME_ERROR, 305, 0, JSEXN_INTERNALERR, "an error occurred while executing regular expression") +MSG_DEF(JSMSG_DEBUG_OPTIMIZED_OUT, 306, 0, JSEXN_ERR, "variable has been optimized out") +MSG_DEF(JSMSG_NEXT_RETURNED_PRIMITIVE,307, 0, JSEXN_TYPEERR, "iterator.next() returned a non-object value") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_CONFLICT, 308, 0, JSEXN_ERR, "no conflict resolution function provided") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BOUNDS, 309, 0, JSEXN_ERR, "index in scatter vector out of bounds") MSG_DEF(JSMSG_CANT_REPORT_NC_AS_NE, 310, 0, JSEXN_TYPEERR, "proxy can't report a non-configurable own property as non-existent") @@ -391,13 +391,13 @@ MSG_DEF(JSMSG_DATE_NOT_FINITE, 337, 0, JSEXN_RANGEERR, "date value is not MSG_DEF(JSMSG_USE_ASM_DIRECTIVE_FAIL, 338, 0, JSEXN_SYNTAXERR, "\"use asm\" is only meaningful in the Directive Prologue of a function body") MSG_DEF(JSMSG_USE_ASM_TYPE_FAIL, 339, 1, JSEXN_TYPEERR, "asm.js type error: {0}") MSG_DEF(JSMSG_USE_ASM_LINK_FAIL, 340, 1, JSEXN_TYPEERR, "asm.js link error: {0}") -MSG_DEF(JSMSG_USE_ASM_TYPE_OK, 341, 1, JSEXN_ERR, "successfully compiled asm.js code ({0})") +MSG_DEF(JSMSG_USE_ASM_TYPE_OK, 341, 1, JSEXN_NONE, "Successfully compiled asm.js code ({0})") MSG_DEF(JSMSG_BAD_ARROW_ARGS, 342, 0, JSEXN_SYNTAXERR, "invalid arrow-function arguments (parentheses around the arrow-function may help)") MSG_DEF(JSMSG_YIELD_IN_ARROW, 343, 0, JSEXN_SYNTAXERR, "arrow function may not contain yield") MSG_DEF(JSMSG_WRONG_VALUE, 344, 2, JSEXN_ERR, "expected {0} but found {1}") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BAD_TARGET, 345, 1, JSEXN_ERR, "target for index {0} is not an integer") MSG_DEF(JSMSG_SELFHOSTED_UNBOUND_NAME,346, 0, JSEXN_TYPEERR, "self-hosted code may not contain unbound name lookups") -MSG_DEF(JSMSG_DEPRECATED_PRAGMA, 347, 1, JSEXN_SYNTAXERR, "Using //@ to indicate {0} pragmas is deprecated. Use //# instead") +MSG_DEF(JSMSG_DEPRECATED_PRAGMA, 347, 1, JSEXN_NONE, "Using //@ to indicate {0} pragmas is deprecated. Use //# instead") MSG_DEF(JSMSG_BAD_DESTRUCT_ASSIGN, 348, 1, JSEXN_SYNTAXERR, "can't assign to {0} using destructuring assignment") MSG_DEF(JSMSG_TYPEDOBJECT_ARRAYTYPE_BAD_ARGS, 349, 0, JSEXN_ERR, "Invalid arguments") MSG_DEF(JSMSG_TYPEDOBJECT_BINARYARRAY_BAD_INDEX, 350, 0, JSEXN_RANGEERR, "invalid or out-of-range index") @@ -414,7 +414,7 @@ MSG_DEF(JSMSG_TOO_MANY_FUN_SPREADARGS, 360, 0, JSEXN_RANGEERR, "too many functio MSG_DEF(JSMSG_DEBUG_NOT_DEBUGGEE, 361, 2, JSEXN_ERR, "{0} is not a debuggee {1}") MSG_DEF(JSMSG_TYPEDOBJECT_NOT_TYPED_OBJECT, 362, 0, JSEXN_ERR, "Expected a typed object") MSG_DEF(JSMSG_TYPEDOBJECT_NO_SUCH_PROP, 363, 1, JSEXN_TYPEERR, "No such property: {0}") -MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_BAD_ARGS, 364, 2, JSEXN_TYPEERR, "argument {0} invalid: expected {1}") +MSG_DEF(JSMSG_TYPEDOBJECT_BAD_ARGS, 364, 0, JSEXN_TYPEERR, "invalid arguments") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_UNATTACHED, 365, 0, JSEXN_TYPEERR, "handle unattached") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_BAD_TYPE, 366, 0, JSEXN_TYPEERR, "handle moved to destination of incorrect type") @@ -433,3 +433,11 @@ MSG_DEF(JSMSG_NO_EXPORT_NAME, 378, 0, JSEXN_SYNTAXERR, "missing export MSG_DEF(JSMSG_DECLARATION_AFTER_EXPORT, 379, 0, JSEXN_SYNTAXERR, "missing declaration after 'export' keyword") MSG_DEF(JSMSG_INVALID_PROTOTYPE, 380, 0, JSEXN_TYPEERR, "prototype field is not an object") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_TO_UNSIZED, 381, 0, JSEXN_TYPEERR, "cannot create a handle to an unsized type") +MSG_DEF(JSMSG_SETPROTOTYPEOF_FAIL, 382, 1, JSEXN_TYPEERR, "[[SetPrototypeOf]] failed on {0}") +MSG_DEF(JSMSG_INVALID_ARG_TYPE, 383, 3, JSEXN_TYPEERR, "Invalid type: {0} can't be a{1} {2}") +MSG_DEF(JSMSG_TERMINATED, 384, 1, JSEXN_ERR, "Script terminated by timeout at:\n{0}") +MSG_DEF(JSMSG_NO_SUCH_SELF_HOSTED_PROP, 385, 1, JSEXN_ERR, "No such property on self-hosted object: {0}") +MSG_DEF(JSMSG_PROXY_EXTENSIBILITY, 386, 0, JSEXN_TYPEERR, "proxy must report same extensiblitity as target") +MSG_DEF(JSMSG_PROXY_CONSTRUCT_OBJECT, 387, 0, JSEXN_TYPEERR, "proxy [[Construct]] must return an object") +MSG_DEF(JSMSG_PROXY_GETOWN_OBJORUNDEF, 388, 0, JSEXN_TYPEERR, "proxy [[GetOwnProperty]] must return an object or undefined") +MSG_DEF(JSMSG_CANT_REPORT_C_AS_NC, 389, 0, JSEXN_TYPEERR, "proxy can't report existing configurable property as non-configurable") diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/CallArgs.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/CallArgs.h index 5c7a201101..3be3f1575a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/CallArgs.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/CallArgs.h @@ -44,7 +44,7 @@ typedef bool /* Typedef for native functions that may be called in parallel. */ typedef bool -(* JSParallelNative)(js::ForkJoinSlice *slice, unsigned argc, JS::Value *vp); +(* JSParallelNative)(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); /* * Typedef for native functions that may be called either in parallel or @@ -63,7 +63,7 @@ JSNativeThreadSafeWrapper(JSContext *cx, unsigned argc, JS::Value *vp); template inline bool -JSParallelNativeThreadSafeWrapper(js::ForkJoinSlice *slice, unsigned argc, JS::Value *vp); +JSParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); /* * Compute |this| for the |vp| inside a JSNative, either boxing primitives or @@ -118,7 +118,7 @@ extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; namespace detail { -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_PUBLIC_API(void) CheckIsValidConstructible(Value v); #endif @@ -147,7 +147,7 @@ class MOZ_STACK_CLASS UsedRvalBase template class MOZ_STACK_CLASS CallReceiverBase : public UsedRvalBase< -#ifdef DEBUG +#ifdef JS_DEBUG WantUsedRval #else NoUsedRval @@ -197,7 +197,7 @@ class MOZ_STACK_CLASS CallReceiverBase : public UsedRvalBase< } bool isConstructing() const { -#ifdef DEBUG +#ifdef JS_DEBUG if (this->usedRval_) CheckIsValidConstructible(calleev()); #endif @@ -388,11 +388,7 @@ CallArgsFromSp(unsigned argc, Value *sp) * take a const JS::CallArgs&. */ -#define JS_CALLEE(cx,vp) ((vp)[0]) -#define JS_THIS_OBJECT(cx,vp) (JSVAL_TO_OBJECT(JS_THIS(cx,vp))) -#define JS_ARGV(cx,vp) ((vp) + 2) -#define JS_RVAL(cx,vp) (*(vp)) -#define JS_SET_RVAL(cx,vp,v) (*(vp) = (v)) +#define JS_THIS_OBJECT(cx,vp) (JS_THIS(cx,vp).toObjectOrNull()) /* * Note: if this method returns null, an error has occurred and must be @@ -401,7 +397,7 @@ CallArgsFromSp(unsigned argc, Value *sp) MOZ_ALWAYS_INLINE JS::Value JS_THIS(JSContext *cx, JS::Value *vp) { - return JSVAL_IS_PRIMITIVE(vp[1]) ? JS_ComputeThis(cx, vp) : vp[1]; + return vp[1].isPrimitive() ? JS_ComputeThis(cx, vp) : vp[1]; } /* diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/CallNonGenericMethod.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/CallNonGenericMethod.h index 05097f0294..ad9a7f708c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/CallNonGenericMethod.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/CallNonGenericMethod.h @@ -14,7 +14,7 @@ namespace JS { // Returns true if |v| is considered an acceptable this-value. -typedef bool (*IsAcceptableThis)(Handle v); +typedef bool (*IsAcceptableThis)(HandleValue v); // Implements the guts of a method; guaranteed to be provided an acceptable // this-value, as determined by a corresponding IsAcceptableThis method. @@ -92,7 +92,7 @@ CallMethodIfWrapped(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallA // tail position in a JSNative. Do not call it from any other place. // template -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool CallNonGenericMethod(JSContext *cx, CallArgs args) { HandleValue thisv = args.thisv(); @@ -102,7 +102,7 @@ CallNonGenericMethod(JSContext *cx, CallArgs args) return detail::CallMethodIfWrapped(cx, Test, Impl, args); } -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool CallNonGenericMethod(JSContext *cx, IsAcceptableThis Test, NativeImpl Impl, CallArgs args) { HandleValue thisv = args.thisv(); diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/CharacterEncoding.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/CharacterEncoding.h index 7918b83484..45c77761b3 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/CharacterEncoding.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/CharacterEncoding.h @@ -17,6 +17,8 @@ namespace js { struct ThreadSafeContext; } +class JSFlatString; + namespace JS { /* @@ -25,40 +27,45 @@ namespace JS { * byte is treated as a 2-byte character, and there is no way to pass in a * string containing characters beyond U+00FF. */ -class Latin1Chars : public mozilla::Range +class Latin1Chars : public mozilla::Range { - typedef mozilla::Range Base; + typedef mozilla::Range Base; public: Latin1Chars() : Base() {} - Latin1Chars(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) {} + Latin1Chars(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) {} + Latin1Chars(const Latin1Char *aBytes, size_t aLength) + : Base(const_cast(aBytes), aLength) + {} Latin1Chars(const char *aBytes, size_t aLength) - : Base(reinterpret_cast(const_cast(aBytes)), aLength) + : Base(reinterpret_cast(const_cast(aBytes)), aLength) {} }; /* * A Latin1Chars, but with \0 termination for C compatibility. */ -class Latin1CharsZ : public mozilla::RangedPtr +class Latin1CharsZ : public mozilla::RangedPtr { - typedef mozilla::RangedPtr Base; + typedef mozilla::RangedPtr Base; public: Latin1CharsZ() : Base(nullptr, 0) {} Latin1CharsZ(char *aBytes, size_t aLength) - : Base(reinterpret_cast(aBytes), aLength) + : Base(reinterpret_cast(aBytes), aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } - Latin1CharsZ(unsigned char *aBytes, size_t aLength) + Latin1CharsZ(Latin1Char *aBytes, size_t aLength) : Base(aBytes, aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } + using Base::operator=; + char *c_str() { return reinterpret_cast(get()); } }; @@ -89,15 +96,17 @@ class UTF8CharsZ : public mozilla::RangedPtr UTF8CharsZ(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } UTF8CharsZ(unsigned char *aBytes, size_t aLength) : Base(aBytes, aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } + using Base::operator=; + char *c_str() { return reinterpret_cast(get()); } }; @@ -119,21 +128,6 @@ class TwoByteChars : public mozilla::Range TwoByteChars(const jschar *aChars, size_t aLength) : Base(const_cast(aChars), aLength) {} }; -/* - * A non-convertible variant of TwoByteChars that does not refer to characters - * inlined inside a JSShortString or a JSInlineString. StableTwoByteChars are - * thus safe to hold across a GC. - */ -class StableTwoByteChars : public mozilla::Range -{ - typedef mozilla::Range Base; - - public: - StableTwoByteChars() : Base() {} - StableTwoByteChars(jschar *aChars, size_t aLength) : Base(aChars, aLength) {} - StableTwoByteChars(const jschar *aChars, size_t aLength) : Base(const_cast(aChars), aLength) {} -}; - /* * A TwoByteChars, but \0 terminated for compatibility with JSFlatString. */ @@ -147,10 +141,31 @@ class TwoByteCharsZ : public mozilla::RangedPtr TwoByteCharsZ(jschar *chars, size_t length) : Base(chars, length) { - JS_ASSERT(chars[length] == '\0'); + MOZ_ASSERT(chars[length] == '\0'); } + + using Base::operator=; }; +typedef mozilla::RangedPtr ConstCharPtr; + +/* + * Like TwoByteChars, but the chars are const. + */ +class ConstTwoByteChars : public mozilla::RangedPtr +{ + public: + ConstTwoByteChars(const ConstTwoByteChars &s) : ConstCharPtr(s) {} + MOZ_IMPLICIT ConstTwoByteChars(const mozilla::RangedPtr &s) : ConstCharPtr(s) {} + ConstTwoByteChars(const jschar *s, size_t len) : ConstCharPtr(s, len) {} + ConstTwoByteChars(const jschar *pos, const jschar *start, size_t len) + : ConstCharPtr(pos, start, len) + {} + + using ConstCharPtr::operator=; +}; + + /* * Convert a 2-byte character sequence to "ISO-Latin-1". This works by * truncating each 2-byte pair in the sequence to a 1-byte pair. If the source @@ -162,10 +177,12 @@ class TwoByteCharsZ : public mozilla::RangedPtr * This method cannot trigger GC. */ extern Latin1CharsZ -LossyTwoByteCharsToNewLatin1CharsZ(js::ThreadSafeContext *cx, TwoByteChars tbchars); +LossyTwoByteCharsToNewLatin1CharsZ(js::ThreadSafeContext *cx, + const mozilla::Range tbchars); +template extern UTF8CharsZ -TwoByteCharsToNewUTF8CharsZ(js::ThreadSafeContext *cx, TwoByteChars tbchars); +CharsToNewUTF8CharsZ(js::ThreadSafeContext *cx, const mozilla::Range chars); uint32_t Utf8ToOneUcs4Char(const uint8_t *utf8Buffer, int utf8Length); @@ -187,6 +204,20 @@ UTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen) extern TwoByteCharsZ LossyUTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen); +/* + * Returns the length of the char buffer required to encode |s| as UTF8. + * Does not include the null-terminator. + */ +JS_PUBLIC_API(size_t) +GetDeflatedUTF8StringLength(JSFlatString *s); + +/* + * Encode |src| as UTF8. The caller must ensure |dst| has enough space. + * Does not write the null terminator. + */ +JS_PUBLIC_API(void) +DeflateStringToUTF8Buffer(JSFlatString *src, mozilla::RangedPtr dst); + } // namespace JS inline void JS_free(JS::Latin1CharsZ &ptr) { js_free((void*)ptr.get()); } diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/Class.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/Class.h index b908fe1604..559cc65c85 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/Class.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/Class.h @@ -24,126 +24,20 @@ * object behavior and, e.g., allows custom slow layout. */ -class JSFreeOp; +struct JSFreeOp; +struct JSFunctionSpec; namespace js { -class Class; +struct Class; class FreeOp; -class PropertyId; class PropertyName; class Shape; -class SpecialId; // This is equal to JSFunction::class_. Use it in places where you don't want // to #include jsfun.h. extern JS_FRIEND_DATA(const js::Class* const) FunctionClassPtr; -static JS_ALWAYS_INLINE jsid -SPECIALID_TO_JSID(const SpecialId &sid); - -/* - * We partition the ways to refer to a property into three: by an index - * (uint32_t); by a string whose characters do not represent an index - * (PropertyName, see vm/String.h); and by various special values. - * - * Special values are encoded using SpecialId, which is layout-compatible but - * non-interconvertible with jsid. A SpecialId is used for JSID_VOID, which - * does not occur in JS scripts but may be used to indicate the absence of a - * valid identifier. In the future, a SpecialId may also be an object used by - * Harmony-proposed private names. - */ -class SpecialId -{ - uintptr_t bits_; - - /* Needs access to raw bits. */ - friend JS_ALWAYS_INLINE jsid SPECIALID_TO_JSID(const SpecialId &sid); - friend class PropertyId; - - static const uintptr_t TYPE_VOID = JSID_TYPE_VOID; - static const uintptr_t TYPE_OBJECT = JSID_TYPE_OBJECT; - static const uintptr_t TYPE_MASK = JSID_TYPE_MASK; - - SpecialId(uintptr_t bits) : bits_(bits) { } - - public: - SpecialId() : bits_(TYPE_VOID) { } - - /* Object-valued */ - - SpecialId(JSObject &obj) - : bits_(uintptr_t(&obj) | TYPE_OBJECT) - { - JS_ASSERT(&obj != nullptr); - JS_ASSERT((uintptr_t(&obj) & TYPE_MASK) == 0); - } - - bool isObject() const { - return (bits_ & TYPE_MASK) == TYPE_OBJECT && bits_ != TYPE_OBJECT; - } - - JSObject *toObject() const { - JS_ASSERT(isObject()); - return reinterpret_cast(bits_ & ~TYPE_MASK); - } - - /* Empty */ - - static SpecialId empty() { - SpecialId sid(TYPE_OBJECT); - JS_ASSERT(sid.isEmpty()); - return sid; - } - - bool isEmpty() const { - return bits_ == TYPE_OBJECT; - } - - /* Void */ - - static SpecialId voidId() { - SpecialId sid(TYPE_VOID); - JS_ASSERT(sid.isVoid()); - return sid; - } - - bool isVoid() const { - return bits_ == TYPE_VOID; - } -}; - -static JS_ALWAYS_INLINE jsid -SPECIALID_TO_JSID(const SpecialId &sid) -{ - jsid id; - JSID_BITS(id) = sid.bits_; - JS_ASSERT_IF(sid.isObject(), JSID_IS_OBJECT(id) && JSID_TO_OBJECT(id) == sid.toObject()); - JS_ASSERT_IF(sid.isVoid(), JSID_IS_VOID(id)); - JS_ASSERT_IF(sid.isEmpty(), JSID_IS_EMPTY(id)); - return id; -} - -static JS_ALWAYS_INLINE bool -JSID_IS_SPECIAL(jsid id) -{ - return JSID_IS_OBJECT(id) || JSID_IS_EMPTY(id) || JSID_IS_VOID(id); -} - -static JS_ALWAYS_INLINE SpecialId -JSID_TO_SPECIALID(jsid id) -{ - JS_ASSERT(JSID_IS_SPECIAL(id)); - if (JSID_IS_OBJECT(id)) - return SpecialId(*JSID_TO_OBJECT(id)); - if (JSID_IS_EMPTY(id)) - return SpecialId::empty(); - JS_ASSERT(JSID_IS_VOID(id)); - return SpecialId::voidId(); -} - -typedef JS::Handle HandleSpecialId; - } // namespace js // JSClass operation signatures. @@ -152,8 +46,8 @@ typedef JS::Handle HandleSpecialId; // be a string (Unicode property identifier) or an int (element index). The // *vp out parameter, on success, is the new property value after the action. typedef bool -(* JSPropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - JS::MutableHandle vp); +(* JSPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); // Set a property named by id in obj, treating the assignment as strict // mode code if strict is true. Note the jsid id type -- id may be a string @@ -161,8 +55,8 @@ typedef bool // parameter, on success, is the new property value after the // set. typedef bool -(* JSStrictPropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - bool strict, JS::MutableHandle vp); +(* JSStrictPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool strict, JS::MutableHandleValue vp); // Delete a property named by id in obj. // @@ -178,7 +72,7 @@ typedef bool // property, or an inherited property, is allowed -- it's just pointless), // set *succeeded to true and return true. typedef bool -(* JSDeletePropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, +(* JSDeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); // This function type is used for callbacks that enumerate the properties of @@ -212,13 +106,13 @@ typedef bool // The return value is used to indicate success, with a value of false // indicating failure. typedef bool -(* JSNewEnumerateOp)(JSContext *cx, JS::Handle obj, JSIterateOp enum_op, - JS::MutableHandle statep, JS::MutableHandle idp); +(* JSNewEnumerateOp)(JSContext *cx, JS::HandleObject obj, JSIterateOp enum_op, + JS::MutableHandleValue statep, JS::MutableHandleId idp); // The old-style JSClass.enumerate op should define all lazy properties not // yet reflected in obj. typedef bool -(* JSEnumerateOp)(JSContext *cx, JS::Handle obj); +(* JSEnumerateOp)(JSContext *cx, JS::HandleObject obj); // Resolve a lazy property named by id in obj by defining it directly in obj. // Lazy properties are those reflected from some peer native property space @@ -231,27 +125,24 @@ typedef bool // // NB: JSNewResolveOp provides a cheaper way to resolve lazy properties. typedef bool -(* JSResolveOp)(JSContext *cx, JS::Handle obj, JS::Handle id); +(* JSResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); -// Like JSResolveOp, but flags provide contextual information as follows: -// -// JSRESOLVE_ASSIGNING obj[id] is on the left-hand side of an assignment -// -// The *objp out parameter, on success, should be null to indicate that id -// was not resolved; and non-null, referring to obj or one of its prototypes, -// if id was resolved. The hook may assume *objp is null on entry. +// Like JSResolveOp, except the *objp out parameter, on success, should be null +// to indicate that id was not resolved; and non-null, referring to obj or one +// of its prototypes, if id was resolved. The hook may assume *objp is null on +// entry. // // This hook instead of JSResolveOp is called via the JSClass.resolve member // if JSCLASS_NEW_RESOLVE is set in JSClass.flags. typedef bool -(* JSNewResolveOp)(JSContext *cx, JS::Handle obj, JS::Handle id, unsigned flags, - JS::MutableHandle objp); +(* JSNewResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleObject objp); // Convert obj to the given type, returning true with the resulting value in // *vp on success, and returning false on error or exception. typedef bool -(* JSConvertOp)(JSContext *cx, JS::Handle obj, JSType type, - JS::MutableHandle vp); +(* JSConvertOp)(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); // Finalize obj, which the garbage collector has determined to be unreachable // from other live objects or from GC roots. Obviously, finalizers must never @@ -264,25 +155,11 @@ struct JSStringFinalizer { void (*finalize)(const JSStringFinalizer *fin, jschar *chars); }; -// JSClass.checkAccess type: check whether obj[id] may be accessed per mode, -// returning false on error/exception, true on success with obj[id]'s last-got -// value in *vp, and its attributes in *attrsp. As for JSPropertyOp above, id -// is either a string or an int jsval. -typedef bool -(* JSCheckAccessOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - JSAccessMode mode, JS::MutableHandle vp); - -// Return whether the first principal subsumes the second. The exact meaning of -// 'subsumes' is left up to the browser. Subsumption is checked inside the JS -// engine when determining, e.g., which stack frames to display in a backtrace. -typedef bool -(* JSSubsumesOp)(JSPrincipals *first, JSPrincipals *second); - // Check whether v is an instance of obj. Return false on error or exception, // true on success with true in *bp if v is an instance of obj, false in // *bp otherwise. typedef bool -(* JSHasInstanceOp)(JSContext *cx, JS::Handle obj, JS::MutableHandle vp, +(* JSHasInstanceOp)(JSContext *cx, JS::HandleObject obj, JS::MutableHandleValue vp, bool *bp); // Function type for trace operation of the class called to enumerate all @@ -300,11 +177,6 @@ typedef bool typedef void (* JSTraceOp)(JSTracer *trc, JSObject *obj); -// A generic type for functions mapping an object to another object, or null -// if an error or exception was thrown on cx. -typedef JSObject * -(* JSObjectOp)(JSContext *cx, JS::Handle obj); - // Hook that creates an iterator object for a given object. Returns the // iterator object or null if an error or exception was thrown on cx. typedef JSObject * @@ -327,9 +199,6 @@ typedef bool (* LookupElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleObject objp, JS::MutableHandle propp); typedef bool -(* LookupSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::MutableHandleObject objp, JS::MutableHandle propp); -typedef bool (* DefineGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); typedef bool @@ -340,10 +209,6 @@ typedef bool (* DefineElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); typedef bool -(* DefineSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); -typedef bool (* GenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, JS::MutableHandleValue vp); typedef bool @@ -353,12 +218,6 @@ typedef bool (* ElementIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, JS::MutableHandleValue vp); typedef bool -(* ElementIfPresentOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, - uint32_t index, JS::MutableHandleValue vp, bool* present); -typedef bool -(* SpecialIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, - HandleSpecialId sid, JS::MutableHandleValue vp); -typedef bool (* StrictGenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, bool strict); typedef bool @@ -368,20 +227,12 @@ typedef bool (* StrictElementIdOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp, bool strict); typedef bool -(* StrictSpecialIdOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::MutableHandleValue vp, bool strict); -typedef bool (* GenericAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); typedef bool (* PropertyAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, unsigned *attrsp); typedef bool -(* DeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, - bool *succeeded); -typedef bool -(* DeleteElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded); -typedef bool -(* DeleteSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, bool *succeeded); +(* DeleteGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); typedef bool (* WatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); @@ -389,12 +240,23 @@ typedef bool typedef bool (* UnwatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); +typedef bool +(* SliceOp)(JSContext *cx, JS::HandleObject obj, uint32_t begin, uint32_t end, + JS::HandleObject result); // result is actually preallocted. + +// A generic type for functions mapping an object to another object, or null +// if an error or exception was thrown on cx. typedef JSObject * (* ObjectOp)(JSContext *cx, JS::HandleObject obj); + +// Hook to map an object to its inner object. Infallible. +typedef JSObject * +(* InnerObjectOp)(JSObject *obj); + typedef void (* FinalizeOp)(FreeOp *fop, JSObject *obj); -#define JS_CLASS_MEMBERS \ +#define JS_CLASS_MEMBERS(FinalizeOpType) \ const char *name; \ uint32_t flags; \ \ @@ -408,26 +270,34 @@ typedef void JSConvertOp convert; \ \ /* Optional members (may be null). */ \ - FinalizeOp finalize; \ - JSCheckAccessOp checkAccess; \ + FinalizeOpType finalize; \ JSNative call; \ JSHasInstanceOp hasInstance; \ JSNative construct; \ JSTraceOp trace -/* - * The helper struct to measure the size of JS_CLASS_MEMBERS to know how much - * we have to pad js::Class to match the size of JSClass. - */ -struct ClassSizeMeasurement +// Callback for the creation of constructor and prototype objects. +typedef JSObject *(*ClassObjectCreationOp)(JSContext *cx, JSProtoKey key); + +// Callback for custom post-processing after class initialization via ClassSpec. +typedef bool (*FinishClassInitOp)(JSContext *cx, JS::HandleObject ctor, + JS::HandleObject proto); + +struct ClassSpec { - JS_CLASS_MEMBERS; + ClassObjectCreationOp createConstructor; + ClassObjectCreationOp createPrototype; + const JSFunctionSpec *constructorFunctions; + const JSFunctionSpec *prototypeFunctions; + const JSPropertySpec *prototypeProperties; + FinishClassInitOp finishInit; + bool defined() const { return !!createConstructor; } }; struct ClassExtension { - JSObjectOp outerObject; - JSObjectOp innerObject; + ObjectOp outerObject; + InnerObjectOp innerObject; JSIteratorOp iteratorObject; /* @@ -450,6 +320,7 @@ struct ClassExtension JSWeakmapKeyDelegateOp weakmapKeyDelegateOp; }; +#define JS_NULL_CLASS_SPEC {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr} #define JS_NULL_CLASS_EXT {nullptr,nullptr,nullptr,false,nullptr} struct ObjectOps @@ -457,36 +328,29 @@ struct ObjectOps LookupGenericOp lookupGeneric; LookupPropOp lookupProperty; LookupElementOp lookupElement; - LookupSpecialOp lookupSpecial; DefineGenericOp defineGeneric; DefinePropOp defineProperty; DefineElementOp defineElement; - DefineSpecialOp defineSpecial; GenericIdOp getGeneric; PropertyIdOp getProperty; ElementIdOp getElement; - ElementIfPresentOp getElementIfPresent; /* can be null */ - SpecialIdOp getSpecial; StrictGenericIdOp setGeneric; StrictPropertyIdOp setProperty; StrictElementIdOp setElement; - StrictSpecialIdOp setSpecial; GenericAttributesOp getGenericAttributes; GenericAttributesOp setGenericAttributes; - DeletePropertyOp deleteProperty; - DeleteElementOp deleteElement; - DeleteSpecialOp deleteSpecial; + DeleteGenericOp deleteGeneric; WatchOp watch; UnwatchOp unwatch; - + SliceOp slice; // Optimized slice, can be null. JSNewEnumerateOp enumerate; ObjectOp thisObject; }; #define JS_NULL_OBJECT_OPS \ - {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, \ - nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, \ - nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr} + {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr} } // namespace js @@ -495,27 +359,9 @@ struct ObjectOps typedef void (*JSClassInternal)(); struct JSClass { - const char *name; - uint32_t flags; - - // Mandatory function pointer members. - JSPropertyOp addProperty; - JSDeletePropertyOp delProperty; - JSPropertyOp getProperty; - JSStrictPropertyOp setProperty; - JSEnumerateOp enumerate; - JSResolveOp resolve; - JSConvertOp convert; - - // Optional members (may be null). - JSFinalizeOp finalize; - JSCheckAccessOp checkAccess; - JSNative call; - JSHasInstanceOp hasInstance; - JSNative construct; - JSTraceOp trace; - - void *reserved[42]; + JS_CLASS_MEMBERS(JSFinalizeOp); + + void *reserved[31]; }; #define JSCLASS_HAS_PRIVATE (1<<0) // objects have private slot @@ -550,9 +396,9 @@ struct JSClass { #define JSCLASS_INTERNAL_FLAG2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2)) #define JSCLASS_INTERNAL_FLAG3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3)) -// Indicate whether the proto or ctor should be frozen. -#define JSCLASS_FREEZE_PROTO (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4)) -#define JSCLASS_FREEZE_CTOR (1<<(JSCLASS_HIGH_FLAGS_SHIFT+5)) +#define JSCLASS_IS_PROXY (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4)) + +// Bit 22 unused. // Reserved for embeddings. #define JSCLASS_USERBIT2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+6)) @@ -573,7 +419,11 @@ struct JSClass { // with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS was // previously allowed, but is now an ES5 violation and thus unsupported. // -#define JSCLASS_GLOBAL_SLOT_COUNT (3 + JSProto_LIMIT * 3 + 27) +// JSCLASS_GLOBAL_APPLICATION_SLOTS is the number of slots reserved at +// the beginning of every global object's slots for use by the +// application. +#define JSCLASS_GLOBAL_APPLICATION_SLOTS 3 +#define JSCLASS_GLOBAL_SLOT_COUNT (JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 3 + 30) #define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n) \ (JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + (n))) #define JSCLASS_GLOBAL_FLAGS \ @@ -600,11 +450,10 @@ namespace js { struct Class { - JS_CLASS_MEMBERS; + JS_CLASS_MEMBERS(FinalizeOp); + ClassSpec spec; ClassExtension ext; ObjectOps ops; - uint8_t pad[sizeof(JSClass) - sizeof(ClassSizeMeasurement) - - sizeof(ClassExtension) - sizeof(ObjectOps)]; /* Class is not native and its map is not a scope. */ static const uint32_t NON_NATIVE = JSCLASS_INTERNAL_FLAG2; @@ -621,8 +470,20 @@ struct Class return flags & JSCLASS_EMULATES_UNDEFINED; } + bool isJSFunction() const { + return this == js::FunctionClassPtr; + } + bool isCallable() const { - return this == js::FunctionClassPtr || call; + return isJSFunction() || call; + } + + bool isProxy() const { + return flags & JSCLASS_IS_PROXY; + } + + bool isDOMClass() const { + return flags & JSCLASS_IS_DOMJSCLASS; } static size_t offsetOfFlags() { return offsetof(Class, flags); } @@ -638,20 +499,19 @@ JS_STATIC_ASSERT(offsetof(JSClass, enumerate) == offsetof(Class, enumerate)); JS_STATIC_ASSERT(offsetof(JSClass, resolve) == offsetof(Class, resolve)); JS_STATIC_ASSERT(offsetof(JSClass, convert) == offsetof(Class, convert)); JS_STATIC_ASSERT(offsetof(JSClass, finalize) == offsetof(Class, finalize)); -JS_STATIC_ASSERT(offsetof(JSClass, checkAccess) == offsetof(Class, checkAccess)); JS_STATIC_ASSERT(offsetof(JSClass, call) == offsetof(Class, call)); JS_STATIC_ASSERT(offsetof(JSClass, construct) == offsetof(Class, construct)); JS_STATIC_ASSERT(offsetof(JSClass, hasInstance) == offsetof(Class, hasInstance)); JS_STATIC_ASSERT(offsetof(JSClass, trace) == offsetof(Class, trace)); JS_STATIC_ASSERT(sizeof(JSClass) == sizeof(Class)); -static JS_ALWAYS_INLINE const JSClass * +static MOZ_ALWAYS_INLINE const JSClass * Jsvalify(const Class *c) { return (const JSClass *)c; } -static JS_ALWAYS_INLINE const Class * +static MOZ_ALWAYS_INLINE const Class * Valueify(const JSClass *c) { return (const Class *)c; @@ -679,21 +539,6 @@ ObjectClassIs(JSObject &obj, ESClassValue classValue, JSContext *cx); inline bool IsObjectWithClass(const JS::Value &v, ESClassValue classValue, JSContext *cx); -inline bool -IsPoisonedSpecialId(js::SpecialId iden) -{ - if (iden.isObject()) - return JS::IsPoisonedPtr(iden.toObject()); - return false; -} - -template <> struct GCMethods -{ - static SpecialId initial() { return SpecialId(); } - static ThingRootKind kind() { return THING_ROOT_ID; } - static bool poisoned(SpecialId id) { return IsPoisonedSpecialId(id); } -}; - } /* namespace js */ #endif /* js_Class_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/GCAPI.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/GCAPI.h index 190b781060..c58d62d029 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/GCAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/GCAPI.h @@ -10,8 +10,26 @@ #include "mozilla/NullPtr.h" #include "js/HeapAPI.h" -#include "js/RootingAPI.h" -#include "js/Value.h" + +namespace js { +namespace gc { +class GCRuntime; +} +} + +typedef enum JSGCMode { + /* Perform only global GCs. */ + JSGC_MODE_GLOBAL = 0, + + /* Perform per-compartment GCs until too much garbage has accumulated. */ + JSGC_MODE_COMPARTMENT = 1, + + /* + * Collect in short time slices rather than all at once. Implies + * JSGC_MODE_COMPARTMENT. + */ + JSGC_MODE_INCREMENTAL = 2 +} JSGCMode; namespace JS { @@ -95,40 +113,117 @@ enum Reason { } /* namespace gcreason */ +/* + * Zone GC: + * + * SpiderMonkey's GC is capable of performing a collection on an arbitrary + * subset of the zones in the system. This allows an embedding to minimize + * collection time by only collecting zones that have run code recently, + * ignoring the parts of the heap that are unlikely to have changed. + * + * When triggering a GC using one of the functions below, it is first necessary + * to select the zones to be collected. To do this, you can call + * PrepareZoneForGC on each zone, or you can call PrepareForFullGC to select + * all zones. Failing to select any zone is an error. + */ + +/* + * Schedule the given zone to be collected as part of the next GC. + */ extern JS_FRIEND_API(void) PrepareZoneForGC(Zone *zone); +/* + * Schedule all zones to be collected in the next GC. + */ extern JS_FRIEND_API(void) PrepareForFullGC(JSRuntime *rt); +/* + * When performing an incremental GC, the zones that were selected for the + * previous incremental slice must be selected in subsequent slices as well. + * This function selects those slices automatically. + */ extern JS_FRIEND_API(void) PrepareForIncrementalGC(JSRuntime *rt); +/* + * Returns true if any zone in the system has been scheduled for GC with one of + * the functions above or by the JS engine. + */ extern JS_FRIEND_API(bool) IsGCScheduled(JSRuntime *rt); +/* + * Undoes the effect of the Prepare methods above. The given zone will not be + * collected in the next GC. + */ extern JS_FRIEND_API(void) SkipZoneForGC(Zone *zone); /* - * When triggering a GC using one of the functions below, it is first necessary - * to select the compartments to be collected. To do this, you can call - * PrepareZoneForGC on each compartment, or you can call PrepareForFullGC - * to select all compartments. Failing to select any compartment is an error. + * Non-Incremental GC: + * + * The following functions perform a non-incremental GC. */ +/* + * Performs a non-incremental collection of all selected zones. Some objects + * that are unreachable from the program may still be alive afterwards because + * of internal references. + */ extern JS_FRIEND_API(void) GCForReason(JSRuntime *rt, gcreason::Reason reason); +/* + * Perform a non-incremental collection after clearing caches and other + * temporary references to objects. This will remove all unreferenced objects + * in the system. + */ extern JS_FRIEND_API(void) ShrinkingGC(JSRuntime *rt, gcreason::Reason reason); -extern JS_FRIEND_API(void) -ShrinkGCBuffers(JSRuntime *rt); +/* + * Incremental GC: + * + * Incremental GC divides the full mark-and-sweep collection into multiple + * slices, allowing client JavaScript code to run between each slice. This + * allows interactive apps to avoid long collection pauses. Incremental GC does + * not make collection take less time, it merely spreads that time out so that + * the pauses are less noticable. + * + * For a collection to be carried out incrementally the following conditions + * must be met: + * - The collection must be run by calling JS::IncrementalGC() rather than + * JS_GC(). + * - The GC mode must have been set to JSGC_MODE_INCREMENTAL with + * JS_SetGCParameter(). + * - All native objects that have their own trace hook must indicate that they + * implement read and write barriers with the JSCLASS_IMPLEMENTS_BARRIERS + * flag. + * + * Note: Even if incremental GC is enabled and working correctly, + * non-incremental collections can still happen when low on memory. + */ +/* + * Begin an incremental collection and perform one slice worth of work or + * perform a slice of an ongoing incremental collection. When this function + * returns, the collection is not complete. This function must be called + * repeatedly until !IsIncrementalGCInProgress(rt). + * + * Note: SpiderMonkey's GC is not realtime. Slices in practice may be longer or + * shorter than the requested interval. + */ extern JS_FRIEND_API(void) IncrementalGC(JSRuntime *rt, gcreason::Reason reason, int64_t millis = 0); +/* + * If IsIncrementalGCInProgress(rt), this call finishes the ongoing collection + * by performing an arbitrarily long slice. If !IsIncrementalGCInProgress(rt), + * this is equivalent to GCForReason. When this function returns, + * IsIncrementalGCInProgress(rt) will always be false. + */ extern JS_FRIEND_API(void) FinishIncrementalGC(JSRuntime *rt, gcreason::Reason reason); @@ -152,7 +247,7 @@ enum GCProgress { struct JS_FRIEND_API(GCDescription) { bool isCompartment_; - GCDescription(bool isCompartment) + explicit GCDescription(bool isCompartment) : isCompartment_(isCompartment) {} jschar *formatMessage(JSRuntime *rt) const; @@ -162,37 +257,56 @@ struct JS_FRIEND_API(GCDescription) { typedef void (* GCSliceCallback)(JSRuntime *rt, GCProgress progress, const GCDescription &desc); +/* + * The GC slice callback is called at the beginning and end of each slice. This + * callback may be used for GC notifications as well as to perform additional + * marking. + */ extern JS_FRIEND_API(GCSliceCallback) SetGCSliceCallback(JSRuntime *rt, GCSliceCallback callback); /* - * Signals a good place to do an incremental slice, because the browser is - * drawing a frame. + * Incremental GC defaults to enabled, but may be disabled for testing or in + * embeddings that have not yet implemented barriers on their native classes. + * There is not currently a way to re-enable incremental GC once it has been + * disabled on the runtime. */ extern JS_FRIEND_API(void) -NotifyDidPaint(JSRuntime *rt); +DisableIncrementalGC(JSRuntime *rt); +/* + * Returns true if incremental GC is enabled. Simply having incremental GC + * enabled is not sufficient to ensure incremental collections are happening. + * See the comment "Incremental GC" above for reasons why incremental GC may be + * suppressed. Inspection of the "nonincremental reason" field of the + * GCDescription returned by GCSliceCallback may help narrow down the cause if + * collections are not happening incrementally when expected. + */ extern JS_FRIEND_API(bool) IsIncrementalGCEnabled(JSRuntime *rt); +/* + * Returns true while an incremental GC is ongoing, both when actively + * collecting and between slices. + */ JS_FRIEND_API(bool) IsIncrementalGCInProgress(JSRuntime *rt); -extern JS_FRIEND_API(void) -DisableIncrementalGC(JSRuntime *rt); - -extern JS_FRIEND_API(void) -DisableGenerationalGC(JSRuntime *rt); - -extern JS_FRIEND_API(void) -EnableGenerationalGC(JSRuntime *rt); - +/* + * Returns true when writes to GC things must call an incremental (pre) barrier. + * This is generally only true when running mutator code in-between GC slices. + * At other times, the barrier may be elided for performance. + */ extern JS_FRIEND_API(bool) IsIncrementalBarrierNeeded(JSRuntime *rt); extern JS_FRIEND_API(bool) IsIncrementalBarrierNeeded(JSContext *cx); +/* + * Notify the GC that a reference to a GC thing is about to be overwritten. + * These methods must be called if IsIncrementalBarrierNeeded. + */ extern JS_FRIEND_API(void) IncrementalReferenceBarrier(void *ptr, JSGCTraceKind kind); @@ -202,73 +316,118 @@ IncrementalValueBarrier(const Value &v); extern JS_FRIEND_API(void) IncrementalObjectBarrier(JSObject *obj); -extern JS_FRIEND_API(void) -PokeGC(JSRuntime *rt); - -/* Was the most recent GC run incrementally? */ +/* + * Returns true if the most recent GC ran incrementally. + */ extern JS_FRIEND_API(bool) WasIncrementalGC(JSRuntime *rt); +/* + * Generational GC: + * + * Note: Generational GC is not yet enabled by default. The following class + * is non-functional unless SpiderMonkey was configured with + * --enable-gcgenerational. + */ + +/* Ensure that generational GC is disabled within some scope. */ +class JS_FRIEND_API(AutoDisableGenerationalGC) +{ + js::gc::GCRuntime *gc; +#if defined(JSGC_GENERATIONAL) && defined(JS_GC_ZEAL) + bool restartVerifier; +#endif + + public: + explicit AutoDisableGenerationalGC(JSRuntime *rt); + ~AutoDisableGenerationalGC(); +}; + +/* + * Returns true if generational allocation and collection is currently enabled + * on the given runtime. + */ +extern JS_FRIEND_API(bool) +IsGenerationalGCEnabled(JSRuntime *rt); + +/* + * Returns the GC's "number". This does not correspond directly to the number + * of GCs that have been run, but is guaranteed to be monotonically increasing + * with GC activity. + */ extern JS_FRIEND_API(size_t) GetGCNumber(); -class JS_PUBLIC_API(AutoAssertNoGC) +/* + * The GC does not immediately return the unused memory freed by a collection + * back to the system incase it is needed soon afterwards. This call forces the + * GC to return this memory immediately. + */ +extern JS_FRIEND_API(void) +ShrinkGCBuffers(JSRuntime *rt); + +/* + * Assert if a GC occurs while this class is live. This class does not disable + * the static rooting hazard analysis. + */ +class JS_PUBLIC_API(AutoAssertOnGC) { #ifdef DEBUG - JSRuntime *runtime; + js::gc::GCRuntime *gc; size_t gcNumber; public: - AutoAssertNoGC(); - AutoAssertNoGC(JSRuntime *rt); - ~AutoAssertNoGC(); + AutoAssertOnGC(); + explicit AutoAssertOnGC(JSRuntime *rt); + ~AutoAssertOnGC(); + + static void VerifyIsSafeToGC(JSRuntime *rt); #else public: - /* Prevent unreferenced local warnings in opt builds. */ - AutoAssertNoGC() {} - AutoAssertNoGC(JSRuntime *) {} + AutoAssertOnGC() {} + explicit AutoAssertOnGC(JSRuntime *rt) {} + ~AutoAssertOnGC() {} + + static void VerifyIsSafeToGC(JSRuntime *rt) {} #endif }; -class JS_PUBLIC_API(ObjectPtr) +/* + * Disable the static rooting hazard analysis in the live region, but assert if + * any GC occurs while this guard object is live. This is most useful to help + * the exact rooting hazard analysis in complex regions, since it cannot + * understand dataflow. + * + * Note: GC behavior is unpredictable even when deterministice and is generally + * non-deterministic in practice. The fact that this guard has not + * asserted is not a guarantee that a GC cannot happen in the guarded + * region. As a rule, anyone performing a GC unsafe action should + * understand the GC properties of all code in that region and ensure + * that the hazard analysis is correct for that code, rather than relying + * on this class. + */ +class JS_PUBLIC_API(AutoSuppressGCAnalysis) : public AutoAssertOnGC { - Heap value; - public: - ObjectPtr() : value(nullptr) {} - - ObjectPtr(JSObject *obj) : value(obj) {} - - /* Always call finalize before the destructor. */ - ~ObjectPtr() { JS_ASSERT(!value); } - - void finalize(JSRuntime *rt) { - if (IsIncrementalBarrierNeeded(rt)) - IncrementalObjectBarrier(value); - value = nullptr; - } - - void init(JSObject *obj) { value = obj; } - - JSObject *get() const { return value; } - - void writeBarrierPre(JSRuntime *rt) { - IncrementalObjectBarrier(value); - } - - bool isAboutToBeFinalized(); - - ObjectPtr &operator=(JSObject *obj) { - IncrementalObjectBarrier(value); - value = obj; - return *this; - } - - void trace(JSTracer *trc, const char *name); + AutoSuppressGCAnalysis() : AutoAssertOnGC() {} + explicit AutoSuppressGCAnalysis(JSRuntime *rt) : AutoAssertOnGC(rt) {} +}; - JSObject &operator*() const { return *value; } - JSObject *operator->() const { return value; } - operator JSObject *() const { return value; } +/* + * Place AutoCheckCannotGC in scopes that you believe can never GC. These + * annotations will be verified both dynamically via AutoAssertOnGC, and + * statically with the rooting hazard analysis (implemented by making the + * analysis consider AutoCheckCannotGC to be a GC pointer, and therefore + * complain if it is live across a GC call.) It is useful when dealing with + * internal pointers to GC things where the GC thing itself may not be present + * for the static analysis: e.g. acquiring inline chars from a JSString* on the + * heap. + */ +class JS_PUBLIC_API(AutoCheckCannotGC) : public AutoAssertOnGC +{ + public: + AutoCheckCannotGC() : AutoAssertOnGC() {} + explicit AutoCheckCannotGC(JSRuntime *rt) : AutoAssertOnGC(rt) {} }; /* @@ -284,10 +443,10 @@ UnmarkGrayGCThingRecursively(void *thing, JSGCTraceKind kind); * data). During incremental GC, since the gray bits haven't been computed yet, * we conservatively mark the object black. */ -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) { - JS_ASSERT(kind != JSTRACE_SHAPE); + MOZ_ASSERT(kind != JSTRACE_SHAPE); shadow::Runtime *rt = js::gc::GetGCThingRuntime(thing); #ifdef JSGC_GENERATIONAL @@ -296,7 +455,7 @@ ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) * All live objects in the nursery are moved to tenured at the beginning of * each GC slice, so the gray marker never sees nursery things. */ - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return; #endif if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) @@ -305,14 +464,7 @@ ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) UnmarkGrayGCThingRecursively(thing, kind); } -static JS_ALWAYS_INLINE void -ExposeValueToActiveJS(const Value &v) -{ - if (v.isMarkable()) - ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); -} - -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void ExposeObjectToActiveJS(JSObject *obj) { ExposeGCThingToActiveJS(obj, JSTRACE_OBJECT); @@ -321,7 +473,7 @@ ExposeObjectToActiveJS(JSObject *obj) /* * If a GC is currently marking, mark the object black. */ -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void MarkGCThingAsLive(JSRuntime *rt_, void *thing, JSGCTraceKind kind) { shadow::Runtime *rt = shadow::Runtime::asShadowRuntime(rt_); @@ -329,20 +481,34 @@ MarkGCThingAsLive(JSRuntime *rt_, void *thing, JSGCTraceKind kind) /* * Any object in the nursery will not be freed during any GC running at that time. */ - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return; #endif if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) IncrementalReferenceBarrier(thing, kind); } -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void MarkStringAsLive(Zone *zone, JSString *string) { JSRuntime *rt = JS::shadow::Zone::asShadowZone(zone)->runtimeFromMainThread(); MarkGCThingAsLive(rt, string, JSTRACE_STRING); } +/* + * Internal to Firefox. + * + * Note: this is not related to the PokeGC in nsJSEnvironment. + */ +extern JS_FRIEND_API(void) +PokeGC(JSRuntime *rt); + +/* + * Internal to Firefox. + */ +extern JS_FRIEND_API(void) +NotifyDidPaint(JSRuntime *rt); + } /* namespace JS */ #endif /* js_GCAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/HashTable.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/HashTable.h index eb98804c8e..4c27308b5e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/HashTable.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/HashTable.h @@ -73,7 +73,7 @@ class HashMap // HashMap construction is fallible (due to OOM); thus the user must call // init after constructing a HashMap and check the return value. - HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} + explicit HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} bool init(uint32_t len = 16) { return impl.init(len); } bool initialized() const { return impl.initialized(); } @@ -159,7 +159,7 @@ class HashMap // typedef HashMap HM; // HM h; // for (HM::Range r = h.all(); !r.empty(); r.popFront()) - // char c = r.front().value; + // char c = r.front().value(); // // Also see the definition of Range in HashTable above (with T = Entry). typedef typename Impl::Range Range; @@ -171,7 +171,7 @@ class HashMap // typedef HashMap HM; // HM s; // for (HM::Enum e(s); !e.empty(); e.popFront()) - // if (e.front().value == 'l') + // if (e.front().value() == 'l') // e.removeFront(); // // Table resize may occur in Enum's destructor. Also see the definition of @@ -182,9 +182,6 @@ class HashMap // using the finish() method. void clear() { impl.clear(); } - // Remove all entries without triggering destructors. This method is unsafe. - void clearWithoutCallingDestructors() { impl.clearWithoutCallingDestructors(); } - // Remove all the entries and release all internal buffers. The map must // be initialized again before any use. void finish() { impl.finish(); } @@ -210,7 +207,7 @@ class HashMap // If |generation()| is the same before and after a HashMap operation, // pointers into the table remain valid. - unsigned generation() const { return impl.generation(); } + uint32_t generation() const { return impl.generation(); } /************************************************** Shorthand operations */ @@ -317,7 +314,7 @@ class HashSet // HashSet construction is fallible (due to OOM); thus the user must call // init after constructing a HashSet and check the return value. - HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} + explicit HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} bool init(uint32_t len = 16) { return impl.init(len); } bool initialized() const { return impl.initialized(); } @@ -438,7 +435,7 @@ class HashSet // If |generation()| is the same before and after a HashSet operation, // pointers into the table remain valid. - unsigned generation() const { return impl.generation(); } + uint32_t generation() const { return impl.generation(); } /************************************************** Shorthand operations */ @@ -482,6 +479,13 @@ class HashSet impl.rekeyAndMaybeRehash(p, new_lookup, new_value); } + // Infallibly rekey one entry with a new key that is equivalent. + void rekeyInPlace(Ptr p, const T &new_value) + { + MOZ_ASSERT(HashPolicy::match(*p, new_value)); + impl.rekeyInPlace(p, new_value); + } + // HashSet is movable HashSet(HashSet &&rhs) : impl(mozilla::Move(rhs.impl)) {} void operator=(HashSet &&rhs) { @@ -531,7 +535,7 @@ struct PointerHasher { typedef Key Lookup; static HashNumber hash(const Lookup &l) { - JS_ASSERT(!JS::IsPoisonedPtr(l)); + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); size_t word = reinterpret_cast(l) >> zeroBits; JS_STATIC_ASSERT(sizeof(HashNumber) == 4); #if JS_BITS_PER_WORD == 32 @@ -542,8 +546,8 @@ struct PointerHasher #endif } static bool match(const Key &k, const Lookup &l) { - JS_ASSERT(!JS::IsPoisonedPtr(k)); - JS_ASSERT(!JS::IsPoisonedPtr(l)); + MOZ_ASSERT(!JS::IsPoisonedPtr(k)); + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); return k == l; } static void rekey(Key &k, const Key& newKey) { @@ -701,7 +705,7 @@ class HashTableEntry } void destroy() { - JS_ASSERT(isLive()); + MOZ_ASSERT(isLive()); mem.addr()->~T(); } @@ -710,16 +714,16 @@ class HashTableEntry mozilla::Swap(mem, other->mem); } - T &get() { JS_ASSERT(isLive()); return *mem.addr(); } + T &get() { MOZ_ASSERT(isLive()); return *mem.addr(); } bool isFree() const { return keyHash == sFreeKey; } - void clearLive() { JS_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); } + void clearLive() { MOZ_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); } void clear() { if (isLive()) mem.addr()->~T(); keyHash = sFreeKey; } bool isRemoved() const { return keyHash == sRemovedKey; } - void removeLive() { JS_ASSERT(isLive()); keyHash = sRemovedKey; mem.addr()->~T(); } + void removeLive() { MOZ_ASSERT(isLive()); keyHash = sRemovedKey; mem.addr()->~T(); } bool isLive() const { return isLiveHash(keyHash); } - void setCollision() { JS_ASSERT(isLive()); keyHash |= sCollisionBit; } - void setCollision(HashNumber bit) { JS_ASSERT(isLive()); keyHash |= bit; } + void setCollision() { MOZ_ASSERT(isLive()); keyHash |= sCollisionBit; } + void setCollision(HashNumber bit) { MOZ_ASSERT(isLive()); keyHash |= bit; } void unsetCollision() { keyHash &= ~sCollisionBit; } bool hasCollision() const { return keyHash & sCollisionBit; } bool matchHash(HashNumber hn) { return (keyHash & ~sCollisionBit) == hn; } @@ -728,16 +732,18 @@ class HashTableEntry template void setLive(HashNumber hn, U &&u) { - JS_ASSERT(!isLive()); + MOZ_ASSERT(!isLive()); keyHash = hn; new(mem.addr()) T(mozilla::Forward(u)); - JS_ASSERT(isLive()); + MOZ_ASSERT(isLive()); } }; template class HashTable : private AllocPolicy { + friend class mozilla::ReentrancyGuard; + typedef typename mozilla::RemoveConst::Type NonConstT; typedef typename HashPolicy::KeyType Key; typedef typename HashPolicy::Lookup Lookup; @@ -756,25 +762,56 @@ class HashTable : private AllocPolicy void nonNull() {} Entry *entry_; +#ifdef DEBUG + const HashTable *table_; + uint32_t generation; +#endif protected: - Ptr(Entry &entry) : entry_(&entry) {} + Ptr(Entry &entry, const HashTable &tableArg) + : entry_(&entry) +#ifdef DEBUG + , table_(&tableArg) + , generation(tableArg.generation()) +#endif + {} public: // Leaves Ptr uninitialized. Ptr() { -#ifdef DEBUG +#ifdef JS_DEBUG entry_ = (Entry *)0xbad; #endif } - bool found() const { return entry_->isLive(); } - operator ConvertibleToBool() const { return found() ? &Ptr::nonNull : 0; } - bool operator==(const Ptr &rhs) const { JS_ASSERT(found() && rhs.found()); return entry_ == rhs.entry_; } - bool operator!=(const Ptr &rhs) const { return !(*this == rhs); } + bool found() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->isLive(); + } - T &operator*() const { return entry_->get(); } - T *operator->() const { return &entry_->get(); } + operator ConvertibleToBool() const { + return found() ? &Ptr::nonNull : 0; + } + + bool operator==(const Ptr &rhs) const { + MOZ_ASSERT(found() && rhs.found()); + return entry_ == rhs.entry_; + } + + bool operator!=(const Ptr &rhs) const { + MOZ_ASSERT(generation == table_->generation()); + return !(*this == rhs); + } + + T &operator*() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->get(); + } + + T *operator->() const { + MOZ_ASSERT(generation == table_->generation()); + return &entry_->get(); + } }; // A Ptr that can be used to add a key after a failed lookup. @@ -782,9 +819,18 @@ class HashTable : private AllocPolicy { friend class HashTable; HashNumber keyHash; - mozilla::DebugOnly mutationCount; +#ifdef DEBUG + uint64_t mutationCount; +#endif + + AddPtr(Entry &entry, const HashTable &tableArg, HashNumber hn) + : Ptr(entry, tableArg) + , keyHash(hn) +#ifdef DEBUG + , mutationCount(tableArg.mutationCount) +#endif + {} - AddPtr(Entry &entry, HashNumber hn) : Ptr(entry), keyHash(hn) {} public: // Leaves AddPtr uninitialized. AddPtr() {} @@ -799,32 +845,63 @@ class HashTable : private AllocPolicy protected: friend class HashTable; - Range(Entry *c, Entry *e) : cur(c), end(e), validEntry(true) { + Range(const HashTable &tableArg, Entry *c, Entry *e) + : cur(c) + , end(e) +#ifdef DEBUG + , table_(&tableArg) + , mutationCount(tableArg.mutationCount) + , generation(tableArg.generation()) + , validEntry(true) +#endif + { while (cur < end && !cur->isLive()) ++cur; } Entry *cur, *end; - mozilla::DebugOnly validEntry; +#ifdef DEBUG + const HashTable *table_; + uint64_t mutationCount; + uint32_t generation; + bool validEntry; +#endif public: - Range() : cur(nullptr), end(nullptr), validEntry(false) {} + Range() + : cur(nullptr) + , end(nullptr) +#ifdef DEBUG + , table_(nullptr) + , mutationCount(0) + , generation(0) + , validEntry(false) +#endif + {} bool empty() const { + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); return cur == end; } T &front() const { - JS_ASSERT(validEntry); - JS_ASSERT(!empty()); + MOZ_ASSERT(validEntry); + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); return cur->get(); } void popFront() { - JS_ASSERT(!empty()); + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); while (++cur < end && !cur->isLive()) continue; +#ifdef DEBUG validEntry = true; +#endif } }; @@ -837,17 +914,17 @@ class HashTable : private AllocPolicy { friend class HashTable; - HashTable &table; + HashTable &table_; bool rekeyed; bool removed; /* Not copyable. */ - Enum(const Enum &); - void operator=(const Enum &); + Enum(const Enum &) MOZ_DELETE; + void operator=(const Enum &) MOZ_DELETE; public: template explicit - Enum(Map &map) : Range(map.all()), table(map.impl), rekeyed(false), removed(false) {} + Enum(Map &map) : Range(map.all()), table_(map.impl), rekeyed(false), removed(false) {} // Removes the |front()| element from the table, leaving |front()| // invalid until the next call to |popFront()|. For example: @@ -857,18 +934,25 @@ class HashTable : private AllocPolicy // if (e.front() == 42) // e.removeFront(); void removeFront() { - table.remove(*this->cur); + table_.remove(*this->cur); removed = true; +#ifdef DEBUG this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif } // Removes the |front()| element and re-inserts it into the table with // a new key at the new Lookup position. |front()| is invalid after // this operation until the next call to |popFront()|. void rekeyFront(const Lookup &l, const Key &k) { - table.rekeyWithoutRehash(*this->cur, l, k); + Ptr p(*this->cur, table_); + table_.rekeyWithoutRehash(p, l, k); rekeyed = true; +#ifdef DEBUG this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif } void rekeyFront(const Key &k) { @@ -878,12 +962,12 @@ class HashTable : private AllocPolicy // Potentially rehashes the table. ~Enum() { if (rekeyed) { - table.gen++; - table.checkOverRemoved(); + table_.gen++; + table_.checkOverRemoved(); } if (removed) - table.compactIfUnderloaded(); + table_.compactIfUnderloaded(); } }; @@ -908,18 +992,18 @@ class HashTable : private AllocPolicy void operator=(const HashTable &) MOZ_DELETE; private: - uint32_t hashShift; // multiplicative hash shift - uint32_t entryCount; // number of entries in table - uint32_t gen; // entry storage generation number - uint32_t removedCount; // removed entry sentinels in table - Entry *table; // entry storage + static const size_t CAP_BITS = 24; - void setTableSizeLog2(unsigned sizeLog2) - { - hashShift = sHashBits - sizeLog2; - } + public: + Entry *table; // entry storage + uint32_t gen; // entry storage generation number + uint32_t entryCount; // number of entries in table + uint32_t removedCount:CAP_BITS; // removed entry sentinels in table + uint32_t hashShift:8; // multiplicative hash shift -#ifdef DEBUG +#ifdef JS_DEBUG + mozilla::DebugOnly mutationCount; + mutable mozilla::DebugOnly mEntered; mutable struct Stats { uint32_t searches; // total number of table searches @@ -939,16 +1023,12 @@ class HashTable : private AllocPolicy # define METER(x) #endif - friend class mozilla::ReentrancyGuard; - mutable mozilla::DebugOnly entered; - mozilla::DebugOnly mutationCount; - // The default initial capacity is 32 (enough to hold 16 elements), but it // can be as low as 4. static const unsigned sMinCapacityLog2 = 2; static const unsigned sMinCapacity = 1 << sMinCapacityLog2; - static const unsigned sMaxInit = JS_BIT(23); - static const unsigned sMaxCapacity = JS_BIT(24); + static const unsigned sMaxInit = JS_BIT(CAP_BITS - 1); + static const unsigned sMaxCapacity = JS_BIT(CAP_BITS); static const unsigned sHashBits = mozilla::tl::BitSize::value; // Hash-table alpha is conceptually a fraction, but to avoid floating-point @@ -961,6 +1041,11 @@ class HashTable : private AllocPolicy static const HashNumber sRemovedKey = Entry::sRemovedKey; static const HashNumber sCollisionBit = Entry::sCollisionBit; + void setTableSizeLog2(unsigned sizeLog2) + { + hashShift = sHashBits - sizeLog2; + } + static bool isLiveHash(HashNumber hash) { return Entry::isLiveHash(hash); @@ -993,20 +1078,22 @@ class HashTable : private AllocPolicy } public: - HashTable(AllocPolicy ap) - : AllocPolicy(ap), - hashShift(sHashBits), - entryCount(0), - gen(0), - removedCount(0), - table(nullptr), - entered(false), - mutationCount(0) + explicit HashTable(AllocPolicy ap) + : AllocPolicy(ap) + , table(nullptr) + , gen(0) + , entryCount(0) + , removedCount(0) + , hashShift(sHashBits) +#ifdef DEBUG + , mutationCount(0) + , mEntered(false) +#endif {} MOZ_WARN_UNUSED_RESULT bool init(uint32_t length) { - JS_ASSERT(!initialized()); + MOZ_ASSERT(!initialized()); // Reject all lengths whose initial computed capacity would exceed // sMaxCapacity. Round that maximum length down to the nearest power @@ -1116,10 +1203,10 @@ class HashTable : private AllocPolicy Entry &lookup(const Lookup &l, HashNumber keyHash, unsigned collisionBit) const { - JS_ASSERT(isLiveHash(keyHash)); - JS_ASSERT(!(keyHash & sCollisionBit)); - JS_ASSERT(collisionBit == 0 || collisionBit == sCollisionBit); - JS_ASSERT(table); + MOZ_ASSERT(isLiveHash(keyHash)); + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(collisionBit == 0 || collisionBit == sCollisionBit); + MOZ_ASSERT(table); METER(stats.searches++); // Compute the primary hash address. @@ -1145,7 +1232,7 @@ class HashTable : private AllocPolicy Entry *firstRemoved = nullptr; while(true) { - if (JS_UNLIKELY(entry->isRemoved())) { + if (MOZ_UNLIKELY(entry->isRemoved())) { if (!firstRemoved) firstRemoved = entry; } else { @@ -1176,8 +1263,8 @@ class HashTable : private AllocPolicy // from entries, which allows more flexible Lookup/Key types. Entry &findFreeEntry(HashNumber keyHash) { - JS_ASSERT(!(keyHash & sCollisionBit)); - JS_ASSERT(table); + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(table); METER(stats.searches++); // We assume 'keyHash' has already been distributed. @@ -1196,7 +1283,7 @@ class HashTable : private AllocPolicy DoubleHash dh = hash2(keyHash); while(true) { - JS_ASSERT(!entry->isRemoved()); + MOZ_ASSERT(!entry->isRemoved()); entry->setCollision(); METER(stats.steps++); @@ -1277,7 +1364,7 @@ class HashTable : private AllocPolicy void remove(Entry &e) { - JS_ASSERT(table); + MOZ_ASSERT(table); METER(stats.removes++); if (e.hasCollision()) { @@ -1288,7 +1375,9 @@ class HashTable : private AllocPolicy e.clearLive(); } entryCount--; +#ifdef DEBUG mutationCount++; +#endif } void checkUnderloaded() @@ -1371,12 +1460,14 @@ class HashTable : private AllocPolicy } removedCount = 0; entryCount = 0; +#ifdef DEBUG mutationCount++; +#endif } void finish() { - JS_ASSERT(!entered); + MOZ_ASSERT(!mEntered); if (!table) return; @@ -1386,36 +1477,38 @@ class HashTable : private AllocPolicy gen++; entryCount = 0; removedCount = 0; +#ifdef DEBUG mutationCount++; +#endif } Range all() const { - JS_ASSERT(table); - return Range(table, table + capacity()); + MOZ_ASSERT(table); + return Range(*this, table, table + capacity()); } bool empty() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return !entryCount; } uint32_t count() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return entryCount; } uint32_t capacity() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return JS_BIT(sHashBits - hashShift); } uint32_t generation() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return gen; } @@ -1433,13 +1526,13 @@ class HashTable : private AllocPolicy { mozilla::ReentrancyGuard g(*this); HashNumber keyHash = prepareHash(l); - return Ptr(lookup(l, keyHash, 0)); + return Ptr(lookup(l, keyHash, 0), *this); } Ptr readonlyThreadsafeLookup(const Lookup &l) const { HashNumber keyHash = prepareHash(l); - return Ptr(lookup(l, keyHash, 0)); + return Ptr(lookup(l, keyHash, 0), *this); } AddPtr lookupForAdd(const Lookup &l) const @@ -1447,8 +1540,7 @@ class HashTable : private AllocPolicy mozilla::ReentrancyGuard g(*this); HashNumber keyHash = prepareHash(l); Entry &entry = lookup(l, keyHash, sCollisionBit); - AddPtr p(entry, keyHash); - p.mutationCount = mutationCount; + AddPtr p(entry, *this, keyHash); return p; } @@ -1456,10 +1548,9 @@ class HashTable : private AllocPolicy bool add(AddPtr &p, U &&u) { mozilla::ReentrancyGuard g(*this); - JS_ASSERT(mutationCount == p.mutationCount); - JS_ASSERT(table); - JS_ASSERT(!p.found()); - JS_ASSERT(!(p.keyHash & sCollisionBit)); + MOZ_ASSERT(table); + MOZ_ASSERT(!p.found()); + MOZ_ASSERT(!(p.keyHash & sCollisionBit)); // Changing an entry from removed to live does not affect whether we // are overloaded and can be handled separately. @@ -1478,7 +1569,11 @@ class HashTable : private AllocPolicy p.entry_->setLive(p.keyHash, mozilla::Forward(u)); entryCount++; +#ifdef DEBUG mutationCount++; + p.generation = generation(); + p.mutationCount = mutationCount; +#endif return true; } @@ -1487,7 +1582,7 @@ class HashTable : private AllocPolicy template void putNewInfallible(const Lookup &l, U &&u) { - JS_ASSERT(table); + MOZ_ASSERT(table); HashNumber keyHash = prepareHash(l); Entry *entry = &findFreeEntry(keyHash); @@ -1500,7 +1595,9 @@ class HashTable : private AllocPolicy entry->setLive(keyHash, mozilla::Forward(u)); entryCount++; +#ifdef DEBUG mutationCount++; +#endif } // Note: |l| may be a reference to a piece of |u|, so this function @@ -1520,10 +1617,13 @@ class HashTable : private AllocPolicy template bool relookupOrAdd(AddPtr& p, const Lookup &l, U &&u) { +#ifdef DEBUG + p.generation = generation(); p.mutationCount = mutationCount; +#endif { mozilla::ReentrancyGuard g(*this); - JS_ASSERT(prepareHash(l) == p.keyHash); // l has not been destroyed + MOZ_ASSERT(prepareHash(l) == p.keyHash); // l has not been destroyed p.entry_ = &lookup(l, p.keyHash, sCollisionBit); } return p.found() || add(p, mozilla::Forward(u)); @@ -1531,18 +1631,18 @@ class HashTable : private AllocPolicy void remove(Ptr p) { - JS_ASSERT(table); + MOZ_ASSERT(table); mozilla::ReentrancyGuard g(*this); - JS_ASSERT(p.found()); + MOZ_ASSERT(p.found()); remove(*p.entry_); checkUnderloaded(); } void rekeyWithoutRehash(Ptr p, const Lookup &l, const Key &k) { - JS_ASSERT(table); + MOZ_ASSERT(table); mozilla::ReentrancyGuard g(*this); - JS_ASSERT(p.found()); + MOZ_ASSERT(p.found()); typename HashTableEntry::NonConstT t(mozilla::Move(*p)); HashPolicy::setKey(t, const_cast(k)); remove(*p.entry_); @@ -1555,6 +1655,14 @@ class HashTable : private AllocPolicy checkOverRemoved(); } + void rekeyInPlace(Ptr p, const Key &k) + { + MOZ_ASSERT(table); + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(p.found()); + HashPolicy::rekey(const_cast(*p), const_cast(k)); + } + #undef METER }; diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/HeapAPI.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/HeapAPI.h index 9993751d46..bdd63c1937 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/HeapAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/HeapAPI.h @@ -26,11 +26,17 @@ CurrentThreadCanAccessZone(JS::Zone *zone); namespace gc { +struct Cell; + const size_t ArenaShift = 12; const size_t ArenaSize = size_t(1) << ArenaShift; const size_t ArenaMask = ArenaSize - 1; +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkShift = 18; +#else const size_t ChunkShift = 20; +#endif const size_t ChunkSize = size_t(1) << ChunkShift; const size_t ChunkMask = ChunkSize - 1; @@ -39,9 +45,15 @@ const size_t CellSize = size_t(1) << CellShift; const size_t CellMask = CellSize - 1; /* These are magic constants derived from actual offsets in gc/Heap.h. */ -const size_t ChunkMarkBitmapOffset = 1032368; +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkMarkBitmapOffset = 258104; +const size_t ChunkMarkBitmapBits = 31744; +#else +const size_t ChunkMarkBitmapOffset = 1032352; const size_t ChunkMarkBitmapBits = 129024; +#endif const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*); +const size_t ChunkLocationOffset = ChunkSize - 2 * sizeof(void*) - sizeof(uint64_t); /* * Live objects are marked black. How many other additional colors are available @@ -51,14 +63,98 @@ const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*); static const uint32_t BLACK = 0; static const uint32_t GRAY = 1; +/* + * The "location" field in the Chunk trailer is a bit vector indicting various + * roles of the chunk. + * + * The value 0 for the "location" field is invalid, at least one bit must be + * set. + * + * Some bits preclude others, for example, any "nursery" bit precludes any + * "tenured" or "middle generation" bit. + */ +const uintptr_t ChunkLocationBitNursery = 1; // Standard GGC nursery +const uintptr_t ChunkLocationBitTenuredHeap = 2; // Standard GGC tenured generation +const uintptr_t ChunkLocationBitPJSNewspace = 4; // The PJS generational GC's allocation space +const uintptr_t ChunkLocationBitPJSFromspace = 8; // The PJS generational GC's fromspace (during GC) + +const uintptr_t ChunkLocationAnyNursery = ChunkLocationBitNursery | + ChunkLocationBitPJSNewspace | + ChunkLocationBitPJSFromspace; + +#ifdef JS_DEBUG +/* When downcasting, ensure we are actually the right type. */ +extern JS_FRIEND_API(void) +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind); +#else +inline void +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind) {} +#endif + } /* namespace gc */ } /* namespace js */ namespace JS { struct Zone; -} /* namespace JS */ -namespace JS { +/* Default size for the generational nursery in bytes. */ +const uint32_t DefaultNurseryBytes = 16 * 1024 * 1024; + +/* Default maximum heap size in bytes to pass to JS_NewRuntime(). */ +const uint32_t DefaultHeapMaxBytes = 32 * 1024 * 1024; + +/* + * We cannot expose the class hierarchy: the implementation is hidden. Instead + * we provide cast functions with strong debug-mode assertions. + */ +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSObject *obj) +{ + js::gc::Cell *cell = reinterpret_cast(obj); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFunction *fun) +{ + js::gc::Cell *cell = reinterpret_cast(fun); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSString *str) +{ + js::gc::Cell *cell = reinterpret_cast(str); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFlatString *flat) +{ + js::gc::Cell *cell = reinterpret_cast(flat); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JS::Symbol *sym) +{ + js::gc::Cell *cell = reinterpret_cast(sym); + AssertGCThingHasType(cell, JSTRACE_SYMBOL); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSScript *script) +{ + js::gc::Cell *cell = reinterpret_cast(script); + AssertGCThingHasType(cell, JSTRACE_SCRIPT); + return cell; +} + namespace shadow { struct ArenaHeader @@ -86,13 +182,13 @@ struct Zone } JSTracer *barrierTracer() { - JS_ASSERT(needsBarrier_); - JS_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + MOZ_ASSERT(needsBarrier_); + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); return barrierTracer_; } JSRuntime *runtimeFromMainThread() const { - JS_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); return runtime_; } @@ -113,40 +209,40 @@ struct Zone namespace js { namespace gc { -static JS_ALWAYS_INLINE uintptr_t * +static MOZ_ALWAYS_INLINE uintptr_t * GetGCThingMarkBitmap(const void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); uintptr_t addr = uintptr_t(thing); addr &= ~js::gc::ChunkMask; addr |= js::gc::ChunkMarkBitmapOffset; return reinterpret_cast(addr); } -static JS_ALWAYS_INLINE JS::shadow::Runtime * +static MOZ_ALWAYS_INLINE JS::shadow::Runtime * GetGCThingRuntime(const void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); uintptr_t addr = uintptr_t(thing); addr &= ~js::gc::ChunkMask; addr |= js::gc::ChunkRuntimeOffset; return *reinterpret_cast(addr); } -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void GetGCThingMarkWordAndMask(const void *thing, uint32_t color, uintptr_t **wordp, uintptr_t *maskp) { uintptr_t addr = uintptr_t(thing); size_t bit = (addr & js::gc::ChunkMask) / js::gc::CellSize + color; - JS_ASSERT(bit < js::gc::ChunkMarkBitmapBits); + MOZ_ASSERT(bit < js::gc::ChunkMarkBitmapBits); uintptr_t *bitmap = GetGCThingMarkBitmap(thing); const uintptr_t nbits = sizeof(*bitmap) * CHAR_BIT; *maskp = uintptr_t(1) << (bit % nbits); *wordp = &bitmap[bit / nbits]; } -static JS_ALWAYS_INLINE JS::shadow::ArenaHeader * +static MOZ_ALWAYS_INLINE JS::shadow::ArenaHeader * GetGCThingArena(void *thing) { uintptr_t addr = uintptr_t(thing); @@ -154,11 +250,18 @@ GetGCThingArena(void *thing) return reinterpret_cast(addr); } -JS_ALWAYS_INLINE bool -IsInsideNursery(const JS::shadow::Runtime *runtime, const void *p) +MOZ_ALWAYS_INLINE bool +IsInsideNursery(const js::gc::Cell *cell) { #ifdef JSGC_GENERATIONAL - return uintptr_t(p) >= runtime->gcNurseryStart_ && uintptr_t(p) < runtime->gcNurseryEnd_; + if (!cell) + return false; + uintptr_t addr = uintptr_t(cell); + addr &= ~js::gc::ChunkMask; + addr |= js::gc::ChunkLocationOffset; + uint32_t location = *reinterpret_cast(addr); + JS_ASSERT(location != 0); + return location & ChunkLocationAnyNursery; #else return false; #endif @@ -170,20 +273,20 @@ IsInsideNursery(const JS::shadow::Runtime *runtime, const void *p) namespace JS { -static JS_ALWAYS_INLINE Zone * +static MOZ_ALWAYS_INLINE Zone * GetGCThingZone(void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); return js::gc::GetGCThingArena(thing)->zone; } -static JS_ALWAYS_INLINE Zone * +static MOZ_ALWAYS_INLINE Zone * GetObjectZone(JSObject *obj) { return GetGCThingZone(obj); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool GCThingIsMarkedGray(void *thing) { #ifdef JSGC_GENERATIONAL @@ -192,8 +295,7 @@ GCThingIsMarkedGray(void *thing) * All live objects in the nursery are moved to tenured at the beginning of * each GC slice, so the gray marker never sees nursery things. */ - JS::shadow::Runtime *rt = js::gc::GetGCThingRuntime(thing); - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return false; #endif uintptr_t *word, mask; @@ -201,7 +303,7 @@ GCThingIsMarkedGray(void *thing) return *word & mask; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool IsIncrementalBarrierNeededOnGCThing(shadow::Runtime *rt, void *thing, JSGCTraceKind kind) { if (!rt->needsBarrier_) diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/Id.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/Id.h index 447deb62e6..11116f2efe 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/Id.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/Id.h @@ -21,164 +21,155 @@ // JS_IdToValue must be used instead. #include "mozilla/NullPtr.h" - + #include "jstypes.h" +#include "js/HeapAPI.h" #include "js/RootingAPI.h" #include "js/TypeDecls.h" #include "js/Utility.h" -#ifdef JS_USE_JSID_STRUCT_TYPES struct jsid { size_t asBits; bool operator==(jsid rhs) const { return asBits == rhs.asBits; } bool operator!=(jsid rhs) const { return asBits != rhs.asBits; } }; -# define JSID_BITS(id) (id.asBits) -#else -# define JSID_BITS(id) (id) -#endif +#define JSID_BITS(id) (id.asBits) #define JSID_TYPE_STRING 0x0 #define JSID_TYPE_INT 0x1 #define JSID_TYPE_VOID 0x2 -#define JSID_TYPE_OBJECT 0x4 +#define JSID_TYPE_SYMBOL 0x4 #define JSID_TYPE_MASK 0x7 // Avoid using canonical 'id' for jsid parameters since this is a magic word in // Objective-C++ which, apparently, wants to be able to #include jsapi.h. #define id iden -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_STRING(jsid id) { return (JSID_BITS(id) & JSID_TYPE_MASK) == 0; } -static JS_ALWAYS_INLINE JSString * +static MOZ_ALWAYS_INLINE JSString * JSID_TO_STRING(jsid id) { - JS_ASSERT(JSID_IS_STRING(id)); + MOZ_ASSERT(JSID_IS_STRING(id)); return (JSString *)JSID_BITS(id); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ZERO(jsid id) { return JSID_BITS(id) == 0; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_INT(jsid id) { return !!(JSID_BITS(id) & JSID_TYPE_INT); } -static JS_ALWAYS_INLINE int32_t +static MOZ_ALWAYS_INLINE int32_t JSID_TO_INT(jsid id) { - JS_ASSERT(JSID_IS_INT(id)); + MOZ_ASSERT(JSID_IS_INT(id)); return ((uint32_t)JSID_BITS(id)) >> 1; } #define JSID_INT_MIN 0 #define JSID_INT_MAX INT32_MAX -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool INT_FITS_IN_JSID(int32_t i) { return i >= 0; } -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid INT_TO_JSID(int32_t i) { jsid id; - JS_ASSERT(INT_FITS_IN_JSID(i)); + MOZ_ASSERT(INT_FITS_IN_JSID(i)); JSID_BITS(id) = ((i << 1) | JSID_TYPE_INT); return id; } -static JS_ALWAYS_INLINE bool -JSID_IS_OBJECT(jsid id) +static MOZ_ALWAYS_INLINE bool +JSID_IS_SYMBOL(jsid id) { - return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_OBJECT && - (size_t)JSID_BITS(id) != JSID_TYPE_OBJECT; + return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_SYMBOL && + JSID_BITS(id) != JSID_TYPE_SYMBOL; } -static JS_ALWAYS_INLINE JSObject * -JSID_TO_OBJECT(jsid id) +static MOZ_ALWAYS_INLINE JS::Symbol * +JSID_TO_SYMBOL(jsid id) { - JS_ASSERT(JSID_IS_OBJECT(id)); - return (JSObject *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); + MOZ_ASSERT(JSID_IS_SYMBOL(id)); + return (JS::Symbol *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); } -static JS_ALWAYS_INLINE jsid -OBJECT_TO_JSID(JSObject *obj) +static MOZ_ALWAYS_INLINE jsid +SYMBOL_TO_JSID(JS::Symbol *sym) { jsid id; - JS_ASSERT(obj != nullptr); - JS_ASSERT(((size_t)obj & JSID_TYPE_MASK) == 0); - JSID_BITS(id) = ((size_t)obj | JSID_TYPE_OBJECT); + MOZ_ASSERT(sym != nullptr); + MOZ_ASSERT((size_t(sym) & JSID_TYPE_MASK) == 0); + JS_ASSERT(!js::gc::IsInsideNursery(JS::AsCell(sym))); + JS_ASSERT(!JS::IsPoisonedPtr(sym)); + JSID_BITS(id) = (size_t(sym) | JSID_TYPE_SYMBOL); return id; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_GCTHING(jsid id) { - return JSID_IS_STRING(id) || JSID_IS_OBJECT(id); + return JSID_IS_STRING(id) || JSID_IS_SYMBOL(id); } -static JS_ALWAYS_INLINE void * +static MOZ_ALWAYS_INLINE void * JSID_TO_GCTHING(jsid id) { return (void *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_VOID(const jsid id) { - JS_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID, + MOZ_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID, JSID_BITS(id) == JSID_TYPE_VOID); return ((size_t)JSID_BITS(id) == JSID_TYPE_VOID); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_EMPTY(const jsid id) { - return ((size_t)JSID_BITS(id) == JSID_TYPE_OBJECT); + return ((size_t)JSID_BITS(id) == JSID_TYPE_SYMBOL); } -#undef id - -#ifdef JS_USE_JSID_STRUCT_TYPES extern JS_PUBLIC_DATA(const jsid) JSID_VOID; extern JS_PUBLIC_DATA(const jsid) JSID_EMPTY; -#else -# define JSID_VOID ((jsid)JSID_TYPE_VOID) -# define JSID_EMPTY ((jsid)JSID_TYPE_OBJECT) -#endif -extern JS_PUBLIC_DATA(const JS::Handle) JSID_VOIDHANDLE; -extern JS_PUBLIC_DATA(const JS::Handle) JSID_EMPTYHANDLE; +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_VOIDHANDLE; +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_EMPTYHANDLE; namespace js { inline bool -IsPoisonedId(jsid iden) +IsPoisonedId(jsid id) { - if (JSID_IS_STRING(iden)) - return JS::IsPoisonedPtr(JSID_TO_STRING(iden)); - if (JSID_IS_OBJECT(iden)) - return JS::IsPoisonedPtr(JSID_TO_OBJECT(iden)); + if (JSID_IS_STRING(id)) + return JS::IsPoisonedPtr(JSID_TO_STRING(id)); + if (JSID_IS_SYMBOL(id)) + return JS::IsPoisonedPtr(JSID_TO_SYMBOL(id)); return false; } template <> struct GCMethods { static jsid initial() { return JSID_VOID; } - static ThingRootKind kind() { return THING_ROOT_ID; } static bool poisoned(jsid id) { return IsPoisonedId(id); } static bool needsPostBarrier(jsid id) { return false; } #ifdef JSGC_GENERATIONAL @@ -187,6 +178,8 @@ template <> struct GCMethods #endif }; +#undef id + } #endif /* js_Id_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/MemoryMetrics.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/MemoryMetrics.h index 95ac91b9f6..31e456baba 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/MemoryMetrics.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/MemoryMetrics.h @@ -77,6 +77,13 @@ struct InefficientNonFlatteningStringHashPolicy static bool match(const JSString *const &k, const Lookup &l); }; +struct CStringHashPolicy +{ + typedef const char *Lookup; + static HashNumber hash(const Lookup &l); + static bool match(const char *const &k, const Lookup &l); +}; + // This file features many classes with numerous size_t fields, and each such // class has one or more methods that need to operate on all of these fields. // Writing these individually is error-prone -- it's easy to add a new field @@ -92,6 +99,9 @@ struct InefficientNonFlatteningStringHashPolicy #define ZERO_SIZE(kind, gc, mSize) mSize(0), #define COPY_OTHER_SIZE(kind, gc, mSize) mSize(other.mSize), #define ADD_OTHER_SIZE(kind, gc, mSize) mSize += other.mSize; +#define SUB_OTHER_SIZE(kind, gc, mSize) MOZ_ASSERT(mSize >= other.mSize); \ + mSize -= other.mSize; +#define ADD_SIZE_TO_N(kind, gc, mSize) n += mSize; #define ADD_SIZE_TO_N_IF_LIVE_GC_THING(kind, gc, mSize) n += (js::gc) ? mSize : 0; #define ADD_TO_TAB_SIZES(kind, gc, mSize) sizes->add(JS::TabSizes::kind, mSize); @@ -101,49 +111,6 @@ enum { IsLiveGCThing = true }; -struct ZoneStatsPod -{ -#define FOR_EACH_SIZE(macro) \ - macro(Other, NotLiveGCThing, gcHeapArenaAdmin) \ - macro(Other, NotLiveGCThing, unusedGCThings) \ - macro(Other, IsLiveGCThing, lazyScriptsGCHeap) \ - macro(Other, NotLiveGCThing, lazyScriptsMallocHeap) \ - macro(Other, IsLiveGCThing, ionCodesGCHeap) \ - macro(Other, IsLiveGCThing, typeObjectsGCHeap) \ - macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \ - macro(Other, NotLiveGCThing, typePool) \ - macro(Strings, IsLiveGCThing, stringsShortGCHeap) \ - macro(Strings, IsLiveGCThing, stringsNormalGCHeap) \ - macro(Strings, NotLiveGCThing, stringsNormalMallocHeap) - - ZoneStatsPod() - : FOR_EACH_SIZE(ZERO_SIZE) - extra() - {} - - void add(const ZoneStatsPod &other) { - FOR_EACH_SIZE(ADD_OTHER_SIZE) - // Do nothing with |extra|. - } - - size_t sizeOfLiveGCThings() const { - size_t n = 0; - FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) - // Do nothing with |extra|. - return n; - } - - void addToTabSizes(JS::TabSizes *sizes) const { - FOR_EACH_SIZE(ADD_TO_TAB_SIZES) - // Do nothing with |extra|. - } - - FOR_EACH_SIZE(DECL_SIZE) - void *extra; // This field can be used by embedders. - -#undef FOR_EACH_SIZE -}; - } // namespace js namespace JS { @@ -156,6 +123,7 @@ struct ObjectsExtraSizes macro(Objects, NotLiveGCThing, mallocHeapElementsNonAsmJS) \ macro(Objects, NotLiveGCThing, mallocHeapElementsAsmJS) \ macro(Objects, NotLiveGCThing, nonHeapElementsAsmJS) \ + macro(Objects, NotLiveGCThing, nonHeapElementsMapped) \ macro(Objects, NotLiveGCThing, nonHeapCodeAsmJS) \ macro(Objects, NotLiveGCThing, mallocHeapAsmJSModuleData) \ macro(Objects, NotLiveGCThing, mallocHeapArgumentsData) \ @@ -209,6 +177,33 @@ struct CodeSizes #undef FOR_EACH_SIZE }; +// Data for tracking GC memory usage. +struct GCSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, marker) \ + macro(_, _, nurseryCommitted) \ + macro(_, _, nurseryDecommitted) \ + macro(_, _, nurseryHugeSlots) \ + macro(_, _, storeBufferVals) \ + macro(_, _, storeBufferCells) \ + macro(_, _, storeBufferSlots) \ + macro(_, _, storeBufferWholeCells) \ + macro(_, _, storeBufferRelocVals) \ + macro(_, _, storeBufferRelocCells) \ + macro(_, _, storeBufferGenerics) + + GCSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + dummy() + {} + + FOR_EACH_SIZE(DECL_SIZE) + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) + +#undef FOR_EACH_SIZE +}; + // This class holds information about the memory taken up by identical copies of // a particular string. Multiple JSStrings may have their sizes aggregated // together into one StringInfo object. Note that two strings with identical @@ -216,50 +211,59 @@ struct CodeSizes // is not. struct StringInfo { - StringInfo() - : numCopies(0), - isShort(0), - gcHeap(0), - mallocHeap(0) - {} +#define FOR_EACH_SIZE(macro) \ + macro(Strings, IsLiveGCThing, gcHeapLatin1) \ + macro(Strings, IsLiveGCThing, gcHeapTwoByte) \ + macro(Strings, NotLiveGCThing, mallocHeapLatin1) \ + macro(Strings, NotLiveGCThing, mallocHeapTwoByte) - StringInfo(bool isShort, size_t gcSize, size_t mallocSize) - : numCopies(1), - isShort(isShort), - gcHeap(gcSize), - mallocHeap(mallocSize) + StringInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numCopies(0) {} - void add(bool isShort, size_t gcSize, size_t mallocSize) { + void add(const StringInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE); numCopies++; - MOZ_ASSERT(isShort == this->isShort); - gcHeap += gcSize; - mallocHeap += mallocSize; } - void add(const StringInfo& info) { - numCopies += info.numCopies; - MOZ_ASSERT(info.isShort == isShort); - gcHeap += info.gcHeap; - mallocHeap += info.mallocHeap; + void subtract(const StringInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE); + numCopies--; } - uint32_t numCopies:31; // How many copies of the string have we seen? - uint32_t isShort:1; // Is it a short string? + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + size_t sizeOfLiveGCThings() const { + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + return n; + } + + void addToTabSizes(TabSizes *sizes) const { + FOR_EACH_SIZE(ADD_TO_TAB_SIZES) + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numCopies; // How many copies of the string have we seen? - // These are all totals across all copies of the string we've seen. - size_t gcHeap; - size_t mallocHeap; +#undef FOR_EACH_SIZE }; -// Holds data about a notable string (one which uses more than -// NotableStringInfo::notableSize() bytes of memory), so we can report it -// individually. +// Holds data about a notable string (one which, counting all duplicates, uses +// more than a certain amount of memory) so we can report it individually. // -// Essentially the only difference between this class and StringInfo is that -// NotableStringInfo holds a copy of the string's chars. +// The only difference between this class and StringInfo is that +// NotableStringInfo holds a copy of some or all of the string's chars. struct NotableStringInfo : public StringInfo { + static const size_t MAX_SAVED_CHARS = 1024; + NotableStringInfo(); NotableStringInfo(JSString *str, const StringInfo &info); NotableStringInfo(NotableStringInfo &&info); @@ -269,12 +273,6 @@ struct NotableStringInfo : public StringInfo js_free(buffer); } - // A string needs to take up this many bytes of storage before we consider - // it to be "notable". - static size_t notableSize() { - return js::MemoryReportingSundriesThreshold(); - } - char *buffer; size_t length; @@ -282,6 +280,67 @@ struct NotableStringInfo : public StringInfo NotableStringInfo(const NotableStringInfo& info) MOZ_DELETE; }; +// This class holds information about the memory taken up by script sources +// from a particular file. +struct ScriptSourceInfo +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, compressed) \ + macro(_, _, uncompressed) \ + macro(_, _, misc) + + ScriptSourceInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numScripts(0) + {} + + void add(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE) + numScripts++; + } + + void subtract(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE) + numScripts--; + } + + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numScripts; // How many ScriptSources come from this file? (It + // can be more than one in XML files that have + // multiple scripts in CDATA sections.) +#undef FOR_EACH_SIZE +}; + +// Holds data about a notable script source file (one whose combined +// script sources use more than a certain amount of memory) so we can report it +// individually. +// +// The only difference between this class and ScriptSourceInfo is that this +// class holds a copy of the filename. +struct NotableScriptSourceInfo : public ScriptSourceInfo +{ + NotableScriptSourceInfo(); + NotableScriptSourceInfo(const char *filename, const ScriptSourceInfo &info); + NotableScriptSourceInfo(NotableScriptSourceInfo &&info); + NotableScriptSourceInfo &operator=(NotableScriptSourceInfo &&info); + + ~NotableScriptSourceInfo() { + js_free(filename_); + } + + char *filename_; + + private: + NotableScriptSourceInfo(const NotableScriptSourceInfo& info) MOZ_DELETE; +}; + // These measurements relate directly to the JSRuntime, and not to zones and // compartments within it. struct RuntimeSizes @@ -292,81 +351,139 @@ struct RuntimeSizes macro(_, _, contexts) \ macro(_, _, dtoa) \ macro(_, _, temporary) \ - macro(_, _, regexpData) \ macro(_, _, interpreterStack) \ - macro(_, _, gcMarker) \ macro(_, _, mathCache) \ + macro(_, _, uncompressedSourceCache) \ + macro(_, _, compressedSourceSet) \ macro(_, _, scriptData) \ - macro(_, _, scriptSources) RuntimeSizes() : FOR_EACH_SIZE(ZERO_SIZE) - code() - {} + scriptSourceInfo(), + code(), + gc(), + notableScriptSources() + { + allScriptSources = js_new(); + if (!allScriptSources || !allScriptSources->init()) + MOZ_CRASH("oom"); + } + ~RuntimeSizes() { + // |allScriptSources| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allScriptSources); + } + + // The script source measurements in |scriptSourceInfo| are initially for + // all script sources. At the end, if the measurement granularity is + // FineGrained, we subtract the measurements of the notable script sources + // and move them into |notableScriptSources|. FOR_EACH_SIZE(DECL_SIZE) - CodeSizes code; + ScriptSourceInfo scriptSourceInfo; + CodeSizes code; + GCSizes gc; + + typedef js::HashMap ScriptSourcesHashMap; + + // |allScriptSources| is only used transiently. During the reporting phase + // it is filled with info about every script source in the runtime. It's + // then used to fill in |notableScriptSources| (which actually gets + // reported), and immediately discarded afterwards. + ScriptSourcesHashMap *allScriptSources; + js::Vector notableScriptSources; #undef FOR_EACH_SIZE }; -struct ZoneStats : js::ZoneStatsPod +struct ZoneStats { +#define FOR_EACH_SIZE(macro) \ + macro(Other, IsLiveGCThing, symbolsGCHeap) \ + macro(Other, NotLiveGCThing, gcHeapArenaAdmin) \ + macro(Other, NotLiveGCThing, unusedGCThings) \ + macro(Other, IsLiveGCThing, lazyScriptsGCHeap) \ + macro(Other, NotLiveGCThing, lazyScriptsMallocHeap) \ + macro(Other, IsLiveGCThing, jitCodesGCHeap) \ + macro(Other, IsLiveGCThing, typeObjectsGCHeap) \ + macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \ + macro(Other, NotLiveGCThing, typePool) \ + macro(Other, NotLiveGCThing, baselineStubsOptimized) \ + ZoneStats() - : strings(nullptr) + : FOR_EACH_SIZE(ZERO_SIZE) + stringInfo(), + extra(), + allStrings(nullptr), + notableStrings(), + isTotals(true) {} ZoneStats(ZoneStats &&other) - : ZoneStatsPod(mozilla::Move(other)), - strings(other.strings), - notableStrings(mozilla::Move(other.notableStrings)) + : FOR_EACH_SIZE(COPY_OTHER_SIZE) + stringInfo(mozilla::Move(other.stringInfo)), + extra(other.extra), + allStrings(other.allStrings), + notableStrings(mozilla::Move(other.notableStrings)), + isTotals(other.isTotals) { - other.strings = nullptr; + other.allStrings = nullptr; + MOZ_ASSERT(!other.isTotals); } - bool initStrings(JSRuntime *rt); - - // Add |other|'s numbers to this object's numbers. The strings data isn't - // touched. - void addIgnoringStrings(const ZoneStats &other) { - ZoneStatsPod::add(other); + ~ZoneStats() { + // |allStrings| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allStrings); } - // Add |other|'s strings data to this object's strings data. (We don't do - // anything with notableStrings.) - void addStrings(const ZoneStats &other) { - for (StringsHashMap::Range r = other.strings->all(); !r.empty(); r.popFront()) { - StringsHashMap::AddPtr p = strings->lookupForAdd(r.front().key()); - if (p) { - // We've seen this string before; add its size to our tally. - p->value().add(r.front().value()); - } else { - // We haven't seen this string before; add it to the hashtable. - strings->add(p, r.front().key(), r.front().value()); - } - } + bool initStrings(JSRuntime *rt); + + void addSizes(const ZoneStats &other) { + MOZ_ASSERT(isTotals); + FOR_EACH_SIZE(ADD_OTHER_SIZE) + stringInfo.add(other.stringInfo); } size_t sizeOfLiveGCThings() const { - size_t n = ZoneStatsPod::sizeOfLiveGCThings(); - for (size_t i = 0; i < notableStrings.length(); i++) { - const JS::NotableStringInfo& info = notableStrings[i]; - n += info.gcHeap; - } + MOZ_ASSERT(isTotals); + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + n += stringInfo.sizeOfLiveGCThings(); return n; } - typedef js::HashMap StringsHashMap; - // |strings| is only used transiently. During the zone traversal it is + // |allStrings| is only used transiently. During the zone traversal it is // filled with info about every string in the zone. It's then used to fill // in |notableStrings| (which actually gets reported), and immediately // discarded afterwards. - StringsHashMap *strings; + StringsHashMap *allStrings; js::Vector notableStrings; + bool isTotals; + +#undef FOR_EACH_SIZE }; struct CompartmentStats @@ -390,17 +507,16 @@ struct CompartmentStats macro(Other, NotLiveGCThing, scriptsMallocHeapData) \ macro(Other, NotLiveGCThing, baselineData) \ macro(Other, NotLiveGCThing, baselineStubsFallback) \ - macro(Other, NotLiveGCThing, baselineStubsOptimized) \ macro(Other, NotLiveGCThing, ionData) \ macro(Other, NotLiveGCThing, typeInferenceTypeScripts) \ - macro(Other, NotLiveGCThing, typeInferencePendingArrays) \ macro(Other, NotLiveGCThing, typeInferenceAllocationSiteTables) \ macro(Other, NotLiveGCThing, typeInferenceArrayTypeTables) \ macro(Other, NotLiveGCThing, typeInferenceObjectTypeTables) \ macro(Other, NotLiveGCThing, compartmentObject) \ macro(Other, NotLiveGCThing, crossCompartmentWrappersTable) \ macro(Other, NotLiveGCThing, regexpCompartment) \ - macro(Other, NotLiveGCThing, debuggeesSet) + macro(Other, NotLiveGCThing, debuggeesSet) \ + macro(Other, NotLiveGCThing, savedStacksSet) CompartmentStats() : FOR_EACH_SIZE(ZERO_SIZE) @@ -454,7 +570,7 @@ struct RuntimeStats macro(_, _, gcHeapChunkAdmin) \ macro(_, _, gcHeapGCThings) \ - RuntimeStats(mozilla::MallocSizeOf mallocSizeOf) + explicit RuntimeStats(mozilla::MallocSizeOf mallocSizeOf) : FOR_EACH_SIZE(ZERO_SIZE) runtime(), cTotals(), @@ -517,13 +633,13 @@ class ObjectPrivateVisitor typedef bool(*GetISupportsFun)(JSObject *obj, nsISupports **iface); GetISupportsFun getISupports_; - ObjectPrivateVisitor(GetISupportsFun getISupports) + explicit ObjectPrivateVisitor(GetISupportsFun getISupports) : getISupports_(getISupports) {} }; extern JS_PUBLIC_API(bool) -CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv); +CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv, bool anonymize); extern JS_PUBLIC_API(size_t) SystemCompartmentCount(JSRuntime *rt); @@ -544,6 +660,8 @@ AddSizeOfTab(JSRuntime *rt, JS::HandleObject obj, mozilla::MallocSizeOf mallocSi #undef ZERO_SIZE #undef COPY_OTHER_SIZE #undef ADD_OTHER_SIZE +#undef SUB_OTHER_SIZE +#undef ADD_SIZE_TO_N #undef ADD_SIZE_TO_N_IF_LIVE_GC_THING #undef ADD_TO_TAB_SIZES diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/OldDebugAPI.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/OldDebugAPI.h index 5e5bdf38d7..7117d754d9 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/OldDebugAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/OldDebugAPI.h @@ -12,47 +12,40 @@ */ #include "mozilla/NullPtr.h" - + +#include "jsapi.h" #include "jsbytecode.h" #include "js/CallArgs.h" #include "js/TypeDecls.h" class JSAtom; -class JSFreeOp; - -namespace js { class StackFrame; } +struct JSFreeOp; -namespace JS { - -struct FrameDescription -{ - JSScript *script; - unsigned lineno; - JSFunction *fun; -}; +namespace js { +class InterpreterFrame; +class FrameIter; +class ScriptSource; +} -struct StackDescription -{ - unsigned nframes; - FrameDescription *frames; -}; +// Raw JSScript* because this needs to be callable from a signal handler. +extern JS_PUBLIC_API(unsigned) +JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); -extern JS_PUBLIC_API(StackDescription *) -DescribeStack(JSContext *cx, unsigned maxFrames); +extern JS_PUBLIC_API(const char *) +JS_GetScriptFilename(JSScript *script); -extern JS_PUBLIC_API(void) -FreeStackDescription(JSContext *cx, StackDescription *desc); +namespace JS { extern JS_PUBLIC_API(char *) FormatStackDump(JSContext *cx, char *buf, bool showArgs, bool showLocals, bool showThisProps); -} +} // namespace JS -# ifdef DEBUG +# ifdef JS_DEBUG JS_FRIEND_API(void) js_DumpValue(const JS::Value &val); JS_FRIEND_API(void) js_DumpId(jsid id); -JS_FRIEND_API(void) js_DumpStackFrame(JSContext *cx, js::StackFrame *start = nullptr); +JS_FRIEND_API(void) js_DumpInterpreterFrame(JSContext *cx, js::InterpreterFrame *start = nullptr); # endif JS_FRIEND_API(void) @@ -70,48 +63,21 @@ typedef JSTrapStatus (* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, JS::Value closure); -typedef JSTrapStatus -(* JSInterruptHook)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, - void *closure); - typedef JSTrapStatus (* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, void *closure); -typedef JSTrapStatus -(* JSThrowHook)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, - void *closure); - typedef bool (* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, JS::Value old, JS::Value *newp, void *closure); -/* called just after script creation */ -typedef void -(* JSNewScriptHook)(JSContext *cx, - const char *filename, /* URL of script */ - unsigned lineno, /* first line */ - JSScript *script, - JSFunction *fun, - void *callerdata); - -/* called just before script destruction */ -typedef void -(* JSDestroyScriptHook)(JSFreeOp *fop, - JSScript *script, - void *callerdata); - -typedef void -(* JSSourceHandler)(const char *filename, unsigned lineno, const jschar *str, - size_t length, void **listenerTSData, void *closure); - extern JS_PUBLIC_API(JSCompartment *) JS_EnterCompartmentOfScript(JSContext *cx, JSScript *target); extern JS_PUBLIC_API(JSString *) -JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned indent); +JS_DecompileScript(JSContext *cx, JS::HandleScript script, const char *name, unsigned indent); /* * Currently, we only support runtime-wide debugging. In the future, we should @@ -157,12 +123,12 @@ JS_SetDebugMode(JSContext *cx, bool debug); /* Turn on single step mode. */ extern JS_PUBLIC_API(bool) -JS_SetSingleStepMode(JSContext *cx, JSScript *script, bool singleStep); +JS_SetSingleStepMode(JSContext *cx, JS::HandleScript script, bool singleStep); /* The closure argument will be marked. */ extern JS_PUBLIC_API(bool) -JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc, - JSTrapHandler handler, JS::Value closure); +JS_SetTrap(JSContext *cx, JS::HandleScript script, jsbytecode *pc, + JSTrapHandler handler, JS::HandleValue closure); extern JS_PUBLIC_API(void) JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc, @@ -174,17 +140,11 @@ JS_ClearScriptTraps(JSRuntime *rt, JSScript *script); extern JS_PUBLIC_API(void) JS_ClearAllTrapsForCompartment(JSContext *cx); -extern JS_PUBLIC_API(bool) -JS_SetInterrupt(JSRuntime *rt, JSInterruptHook handler, void *closure); - -extern JS_PUBLIC_API(bool) -JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *handlerp, void **closurep); - /************************************************************************/ extern JS_PUBLIC_API(bool) -JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsid id, - JSWatchPointHandler handler, JSObject *closure); +JS_SetWatchPoint(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JSWatchPointHandler handler, JS::HandleObject closure); extern JS_PUBLIC_API(bool) JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id, @@ -195,10 +155,6 @@ JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj); /************************************************************************/ -// Raw JSScript* because this needs to be callable from a signal handler. -extern JS_PUBLIC_API(unsigned) -JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); - extern JS_PUBLIC_API(jsbytecode *) JS_LineNumberToPC(JSContext *cx, JSScript *script, unsigned lineno); @@ -234,17 +190,11 @@ extern JS_PUBLIC_API(void) JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mark); extern JS_PUBLIC_API(JSScript *) -JS_GetFunctionScript(JSContext *cx, JSFunction *fun); +JS_GetFunctionScript(JSContext *cx, JS::HandleFunction fun); extern JS_PUBLIC_API(JSNative) JS_GetFunctionNative(JSContext *cx, JSFunction *fun); -extern JS_PUBLIC_API(JSPrincipals *) -JS_GetScriptPrincipals(JSScript *script); - -extern JS_PUBLIC_API(JSPrincipals *) -JS_GetScriptOriginPrincipals(JSScript *script); - JS_PUBLIC_API(JSFunction *) JS_GetScriptFunction(JSContext *cx, JSScript *script); @@ -264,9 +214,6 @@ JS_GetDebugClassName(JSObject *obj); /************************************************************************/ -extern JS_PUBLIC_API(const char *) -JS_GetScriptFilename(JSContext *cx, JSScript *script); - extern JS_PUBLIC_API(const jschar *) JS_GetScriptSourceMap(JSContext *cx, JSScript *script); @@ -284,22 +231,6 @@ JS_GetScriptIsSelfHosted(JSScript *script); /************************************************************************/ -/* - * Hook setters for script creation and destruction. These macros provide - * binary compatibility and newer, shorter synonyms. - */ -#define JS_SetNewScriptHook JS_SetNewScriptHookProc -#define JS_SetDestroyScriptHook JS_SetDestroyScriptHookProc - -extern JS_PUBLIC_API(void) -JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata); - -extern JS_PUBLIC_API(void) -JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook, - void *callerdata); - -/************************************************************************/ - typedef struct JSPropertyDesc { JS::Value id; /* primary id, atomized string, or int */ JS::Value value; /* property value */ @@ -325,7 +256,7 @@ typedef struct JSPropertyDescArray { typedef struct JSScopeProperty JSScopeProperty; extern JS_PUBLIC_API(bool) -JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda); +JS_GetPropertyDescArray(JSContext *cx, JS::HandleObject obj, JSPropertyDescArray *pda); extern JS_PUBLIC_API(void) JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); @@ -339,16 +270,18 @@ JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); class JS_PUBLIC_API(JSAbstractFramePtr) { uintptr_t ptr_; + jsbytecode *pc_; protected: JSAbstractFramePtr() - : ptr_(0) + : ptr_(0), pc_(nullptr) { } public: - explicit JSAbstractFramePtr(void *raw); + JSAbstractFramePtr(void *raw, jsbytecode *pc); uintptr_t raw() const { return ptr_; } + jsbytecode *pc() const { return pc_; } operator bool() const { return !!ptr_; } @@ -393,7 +326,7 @@ class JS_PUBLIC_API(JSBrokenFrameIterator) void *data_; public: - JSBrokenFrameIterator(JSContext *cx); + explicit JSBrokenFrameIterator(JSContext *cx); ~JSBrokenFrameIterator(); bool done() const; @@ -405,58 +338,13 @@ class JS_PUBLIC_API(JSBrokenFrameIterator) bool isConstructing() const; }; -/* - * This hook captures high level script execution and function calls (JS or - * native). It is used by JS_SetExecuteHook to hook top level scripts and by - * JS_SetCallHook to hook function calls. It will get called twice per script - * or function call: just before execution begins and just after it finishes. - * In both cases the 'current' frame is that of the executing code. - * - * The 'before' param is true for the hook invocation before the execution - * and false for the invocation after the code has run. - * - * The 'ok' param is significant only on the post execution invocation to - * signify whether or not the code completed 'normally'. - * - * The 'closure' param is as passed to JS_SetExecuteHook or JS_SetCallHook - * for the 'before'invocation, but is whatever value is returned from that - * invocation for the 'after' invocation. Thus, the hook implementor *could* - * allocate a structure in the 'before' invocation and return a pointer to that - * structure. The pointer would then be handed to the hook for the 'after' - * invocation. Alternately, the 'before' could just return the same value as - * in 'closure' to cause the 'after' invocation to be called with the same - * 'closure' value as the 'before'. - * - * Returning nullptr in the 'before' hook will cause the 'after' hook *not* to - * be called. - */ -typedef void * -(* JSInterpreterHook)(JSContext *cx, JSAbstractFramePtr frame, bool isConstructing, - bool before, bool *ok, void *closure); - typedef bool (* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report, void *closure); typedef struct JSDebugHooks { - JSInterruptHook interruptHook; - void *interruptHookData; - JSNewScriptHook newScriptHook; - void *newScriptHookData; - JSDestroyScriptHook destroyScriptHook; - void *destroyScriptHookData; JSDebuggerHandler debuggerHandler; void *debuggerHandlerData; - JSSourceHandler sourceHandler; - void *sourceHandlerData; - JSInterpreterHook executeHook; - void *executeHookData; - JSInterpreterHook callHook; - void *callHookData; - JSThrowHook throwHook; - void *throwHookData; - JSDebugErrorHook debugErrorHook; - void *debugErrorHookData; } JSDebugHooks; /************************************************************************/ @@ -464,21 +352,6 @@ typedef struct JSDebugHooks { extern JS_PUBLIC_API(bool) JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler hook, void *closure); -extern JS_PUBLIC_API(bool) -JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetThrowHook(JSRuntime *rt, JSThrowHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure); - /************************************************************************/ extern JS_PUBLIC_API(const JSDebugHooks *) @@ -492,16 +365,10 @@ JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj); /* Defined in vm/Debugger.cpp. */ extern JS_PUBLIC_API(bool) -JS_DefineDebuggerObject(JSContext *cx, JSObject *obj); - -extern JS_PUBLIC_API(void) -JS_DumpBytecode(JSContext *cx, JSScript *script); - -extern JS_PUBLIC_API(void) -JS_DumpCompartmentBytecode(JSContext *cx); +JS_DefineDebuggerObject(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(void) -JS_DumpPCCounts(JSContext *cx, JSScript *script); +JS_DumpPCCounts(JSContext *cx, JS::HandleScript script); extern JS_PUBLIC_API(void) JS_DumpCompartmentPCCounts(JSContext *cx); diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/Principals.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/Principals.h new file mode 100644 index 0000000000..78d8c7e893 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/Principals.h @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JSPrincipals and related interfaces. */ + +#ifndef js_Principals_h +#define js_Principals_h + +#include "mozilla/Atomics.h" + +#include + +#include "jspubtd.h" + +struct JSPrincipals { + /* Don't call "destroy"; use reference counting macros below. */ +#ifdef JS_THREADSAFE + mozilla::Atomic refcount; +#else + int32_t refcount; +#endif + +#ifdef JS_DEBUG + /* A helper to facilitate principals debugging. */ + uint32_t debugToken; +#endif + + void setDebugToken(uint32_t token) { +# ifdef JS_DEBUG + debugToken = token; +# endif + } + + /* + * This is not defined by the JS engine but should be provided by the + * embedding. + */ + JS_PUBLIC_API(void) dump(); +}; + +extern JS_PUBLIC_API(void) +JS_HoldPrincipals(JSPrincipals *principals); + +extern JS_PUBLIC_API(void) +JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals); + +// Return whether the first principal subsumes the second. The exact meaning of +// 'subsumes' is left up to the browser. Subsumption is checked inside the JS +// engine when determining, e.g., which stack frames to display in a backtrace. +typedef bool +(* JSSubsumesOp)(JSPrincipals *first, JSPrincipals *second); + +/* + * Used to check if a CSP instance wants to disable eval() and friends. + * See js_CheckCSPPermitsJSAction() in jsobj. + */ +typedef bool +(* JSCSPEvalChecker)(JSContext *cx); + +struct JSSecurityCallbacks { + JSCSPEvalChecker contentSecurityPolicyAllows; + JSSubsumesOp subsumes; +}; + +extern JS_PUBLIC_API(void) +JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks); + +extern JS_PUBLIC_API(const JSSecurityCallbacks *) +JS_GetSecurityCallbacks(JSRuntime *rt); + +/* + * Code running with "trusted" principals will be given a deeper stack + * allocation than ordinary scripts. This allows trusted script to run after + * untrusted script has exhausted the stack. This function sets the + * runtime-wide trusted principal. + * + * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since + * there is no available JSContext. Instead, the caller must ensure that the + * given principals stays valid for as long as 'rt' may point to it. If the + * principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be + * called again, passing nullptr for 'prin'. + */ +extern JS_PUBLIC_API(void) +JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin); + +typedef void +(* JSDestroyPrincipalsOp)(JSPrincipals *principals); + +/* + * Initialize the callback that is called to destroy JSPrincipals instance + * when its reference counter drops to zero. The initialization can be done + * only once per JS runtime. + */ +extern JS_PUBLIC_API(void) +JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals); + +#endif /* js_Principals_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/ProfilingStack.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/ProfilingStack.h index 213e47bb7d..e82ce1c9d8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/ProfilingStack.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/ProfilingStack.h @@ -8,7 +8,8 @@ #define js_ProfilingStack_h #include "mozilla/NullPtr.h" - +#include "mozilla/TypedEnum.h" + #include "jsbytecode.h" #include "jstypes.h" @@ -34,50 +35,120 @@ class ProfileEntry // If the size modification were somehow reordered before the stores, then // if a sample were taken it would be examining bogus information. // - // A ProfileEntry represents both a C++ profile entry and a JS one. Both use - // the string as a description, but JS uses the sp as nullptr to indicate - // that it is a JS entry. The script_ is then only ever examined for a JS - // entry, and the idx is used by both, but with different meanings. - // - const char * volatile string; // Descriptive string of this entry - void * volatile sp; // Relevant stack pointer for the entry - JSScript * volatile script_; // if js(), non-null script which is running - int32_t volatile idx; // if js(), idx of pc, otherwise line number + // A ProfileEntry represents both a C++ profile entry and a JS one. + + // Descriptive string of this entry. + const char * volatile string; + + // Stack pointer for non-JS entries, the script pointer otherwise. + void * volatile spOrScript; + + // Line number for non-JS entries, the bytecode offset otherwise. + int32_t volatile lineOrPc; + + // General purpose storage describing this frame. + uint32_t volatile flags_; public: + // These traits are bit masks. Make sure they're powers of 2. + enum Flags { + // Indicate whether a profile entry represents a CPP frame. If not set, + // a JS frame is assumed by default. You're not allowed to publicly + // change the frame type. Instead, call `setJsFrame` or `setCppFrame`. + IS_CPP_ENTRY = 0x01, + + // Indicate that copying the frame label is not necessary when taking a + // sample of the pseudostack. + FRAME_LABEL_COPY = 0x02, + + // Mask for removing all flags except the category information. + CATEGORY_MASK = ~IS_CPP_ENTRY & ~FRAME_LABEL_COPY + }; + + MOZ_BEGIN_NESTED_ENUM_CLASS(Category, uint32_t) + OTHER = 0x04, + CSS = 0x08, + JS = 0x10, + GC = 0x20, + CC = 0x40, + NETWORK = 0x80, + GRAPHICS = 0x100, + STORAGE = 0x200, + EVENTS = 0x400, + + FIRST = OTHER, + LAST = EVENTS + MOZ_END_NESTED_ENUM_CLASS(Category) + // All of these methods are marked with the 'volatile' keyword because SPS's // representation of the stack is stored such that all ProfileEntry // instances are volatile. These methods would not be available unless they // were marked as volatile as well. - bool js() const volatile { - JS_ASSERT_IF(sp == nullptr, script_ != nullptr); - return sp == nullptr; - } + bool isCpp() const volatile { return hasFlag(IS_CPP_ENTRY); } + bool isJs() const volatile { return !isCpp(); } - uint32_t line() const volatile { JS_ASSERT(!js()); return idx; } - JSScript *script() const volatile { JS_ASSERT(js()); return script_; } - void *stackAddress() const volatile { return sp; } - const char *label() const volatile { return string; } + bool isCopyLabel() const volatile { return hasFlag(FRAME_LABEL_COPY); }; - void setLine(uint32_t aLine) volatile { JS_ASSERT(!js()); idx = aLine; } void setLabel(const char *aString) volatile { string = aString; } - void setStackAddress(void *aSp) volatile { sp = aSp; } - void setScript(JSScript *aScript) volatile { script_ = aScript; } + const char *label() const volatile { return string; } + + void setJsFrame(JSScript *aScript, jsbytecode *aPc) volatile { + flags_ = 0; + spOrScript = aScript; + setPC(aPc); + } + void setCppFrame(void *aSp, uint32_t aLine) volatile { + flags_ = IS_CPP_ENTRY; + spOrScript = aSp; + lineOrPc = static_cast(aLine); + } + + void setFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ |= flag; + } + void unsetFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ &= ~flag; + } + bool hasFlag(uint32_t flag) const volatile { + return bool(flags_ & flag); + } + + uint32_t flags() const volatile { + return flags_; + } + uint32_t category() const volatile { + return flags_ & CATEGORY_MASK; + } + + void *stackAddress() const volatile { + MOZ_ASSERT(!isJs()); + return spOrScript; + } + JSScript *script() const volatile { + MOZ_ASSERT(isJs()); + return (JSScript *)spOrScript; + } + uint32_t line() const volatile { + MOZ_ASSERT(!isJs()); + return static_cast(lineOrPc); + } // We can't know the layout of JSScript, so look in vm/SPSProfiler.cpp. JS_FRIEND_API(jsbytecode *) pc() const volatile; JS_FRIEND_API(void) setPC(jsbytecode *pc) volatile; - static size_t offsetOfString() { return offsetof(ProfileEntry, string); } - static size_t offsetOfStackAddress() { return offsetof(ProfileEntry, sp); } - static size_t offsetOfPCIdx() { return offsetof(ProfileEntry, idx); } - static size_t offsetOfScript() { return offsetof(ProfileEntry, script_); } + // The offset of a pc into a script's code can actually be 0, so to + // signify a nullptr pc, use a -1 index. This is checked against in + // pc() and setPC() to set/get the right pc. + static const int32_t NullPCOffset = -1; - // The index used in the entry can either be a line number or the offset of - // a pc into a script's code. To signify a nullptr pc, use a -1 index. This - // is checked against in pc() and setPC() to set/get the right pc. - static const int32_t NullPCIndex = -1; + static size_t offsetOfLabel() { return offsetof(ProfileEntry, string); } + static size_t offsetOfSpOrScript() { return offsetof(ProfileEntry, spOrScript); } + static size_t offsetOfLineOrPc() { return offsetof(ProfileEntry, lineOrPc); } + static size_t offsetOfFlags() { return offsetof(ProfileEntry, flags_); } }; JS_FRIEND_API(void) @@ -87,6 +158,9 @@ SetRuntimeProfilingStack(JSRuntime *rt, ProfileEntry *stack, uint32_t *size, JS_FRIEND_API(void) EnableRuntimeProfilingStack(JSRuntime *rt, bool enabled); +JS_FRIEND_API(void) +RegisterRuntimeProfilingEventMarker(JSRuntime *rt, void (*fn)(const char *)); + JS_FRIEND_API(jsbytecode*) ProfilingGetPC(JSRuntime *rt, JSScript *script, void *ip); diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/RequiredDefines.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/RequiredDefines.h index 3c8f429132..308fd7d625 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/RequiredDefines.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/RequiredDefines.h @@ -28,4 +28,7 @@ #define __STDC_CONSTANT_MACROS #define __STDC_FORMAT_MACROS +/* Also define a char16_t type if not provided by the compiler. */ +#include "mozilla/Char16.h" + #endif /* js_RequiredDefines_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/RootingAPI.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/RootingAPI.h index 5b612660cd..621a1e4394 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/RootingAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/RootingAPI.h @@ -15,6 +15,8 @@ #include "jspubtd.h" +#include "js/GCAPI.h" +#include "js/HeapAPI.h" #include "js/TypeDecls.h" #include "js/Utility.h" @@ -138,6 +140,8 @@ struct NullPtr namespace gc { struct Cell; +template +struct PersistentRootedMarker; } /* namespace gc */ } /* namespace js */ @@ -150,11 +154,6 @@ template class PersistentRooted; /* This is exposing internal state of the GC for inlining purposes. */ JS_FRIEND_API(bool) isGCEnabled(); -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) -extern void -CheckStackRoots(JSContext *cx); -#endif - /* * JS::NullPtr acts like a nullptr pointer in contexts that require a Handle. * @@ -198,6 +197,13 @@ class Heap : public js::HeapBase init(js::GCMethods::initial()); } explicit Heap(T p) { init(p); } + + /* + * For Heap, move semantics are equivalent to copy semantics. In C++, a + * copy constructor taking const-ref is the way to get a single function + * that will be used for both lvalue and rvalue copies, so we can simply + * omit the rvalue variant. + */ explicit Heap(const Heap &p) { init(p.ptr); } ~Heap() { @@ -229,7 +235,7 @@ class Heap : public js::HeapBase } void set(T newPtr) { - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); if (js::GCMethods::needsPostBarrier(newPtr)) { ptr = newPtr; post(); @@ -241,9 +247,21 @@ class Heap : public js::HeapBase } } + /* + * Set the pointer to a value which will cause a crash if it is + * dereferenced. + */ + void setToCrashOnTouch() { + ptr = reinterpret_cast(crashOnTouchPointer); + } + + bool isSetToCrashOnTouch() { + return ptr == crashOnTouchPointer; + } + private: void init(T newPtr) { - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); ptr = newPtr; if (js::GCMethods::needsPostBarrier(ptr)) post(); @@ -251,7 +269,7 @@ class Heap : public js::HeapBase void post() { #ifdef JSGC_GENERATIONAL - JS_ASSERT(js::GCMethods::needsPostBarrier(ptr)); + MOZ_ASSERT(js::GCMethods::needsPostBarrier(ptr)); js::GCMethods::postBarrier(&ptr); #endif } @@ -262,10 +280,14 @@ class Heap : public js::HeapBase #endif } + enum { + crashOnTouchPointer = 1 + }; + T ptr; }; -#ifdef DEBUG +#ifdef JS_DEBUG /* * For generational GC, assert that an object is in the tenured generation as * opposed to being in the nursery. @@ -315,31 +337,31 @@ class TenuredHeap : public js::HeapBase "TenuredHeap must be binary compatible with T."); } explicit TenuredHeap(T p) : bits(0) { setPtr(p); } - explicit TenuredHeap(const TenuredHeap &p) : bits(0) { setPtr(p.ptr); } + explicit TenuredHeap(const TenuredHeap &p) : bits(0) { setPtr(p.getPtr()); } bool operator==(const TenuredHeap &other) { return bits == other.bits; } bool operator!=(const TenuredHeap &other) { return bits != other.bits; } void setPtr(T newPtr) { - JS_ASSERT((reinterpret_cast(newPtr) & flagsMask) == 0); - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT((reinterpret_cast(newPtr) & flagsMask) == 0); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); if (newPtr) AssertGCThingMustBeTenured(newPtr); bits = (bits & flagsMask) | reinterpret_cast(newPtr); } void setFlags(uintptr_t flagsToSet) { - JS_ASSERT((flagsToSet & ~flagsMask) == 0); + MOZ_ASSERT((flagsToSet & ~flagsMask) == 0); bits |= flagsToSet; } void unsetFlags(uintptr_t flagsToUnset) { - JS_ASSERT((flagsToUnset & ~flagsMask) == 0); + MOZ_ASSERT((flagsToUnset & ~flagsMask) == 0); bits &= ~flagsToUnset; } bool hasFlag(uintptr_t flag) const { - JS_ASSERT((flag & ~flagsMask) == 0); + MOZ_ASSERT((flag & ~flagsMask) == 0); return (bits & flag) != 0; } @@ -359,23 +381,10 @@ class TenuredHeap : public js::HeapBase return *this; } - /* - * Set the pointer to a value which will cause a crash if it is - * dereferenced. - */ - void setToCrashOnTouch() { - bits = (bits & flagsMask) | crashOnTouchPointer; - } - - bool isSetToCrashOnTouch() { - return (bits & ~flagsMask) == crashOnTouchPointer; - } - private: enum { maskBits = 3, flagsMask = (1 << maskBits) - 1, - crashOnTouchPointer = 1 << maskBits }; uintptr_t bits; @@ -406,20 +415,20 @@ class MOZ_NONHEAP_CLASS Handle : public js::HandleBase } /* Create a handle for a nullptr pointer. */ - Handle(js::NullPtr) { + MOZ_IMPLICIT Handle(js::NullPtr) { static_assert(mozilla::IsPointer::value, "js::NullPtr overload not valid for non-pointer types"); ptr = reinterpret_cast(&js::NullPtr::constNullValue); } /* Create a handle for a nullptr pointer. */ - Handle(JS::NullPtr) { + MOZ_IMPLICIT Handle(JS::NullPtr) { static_assert(mozilla::IsPointer::value, "JS::NullPtr overload not valid for non-pointer types"); ptr = reinterpret_cast(&JS::NullPtr::constNullValue); } - Handle(MutableHandle handle) { + MOZ_IMPLICIT Handle(MutableHandle handle) { ptr = handle.address(); } @@ -476,9 +485,6 @@ class MOZ_NONHEAP_CLASS Handle : public js::HandleBase bool operator!=(const T &other) const { return *ptr != other; } bool operator==(const T &other) const { return *ptr == other; } - /* Change this handle to point to the same rooted location RHS does. */ - void repoint(const Handle &rhs) { ptr = rhs.address(); } - private: Handle() {} @@ -504,15 +510,23 @@ template class MOZ_STACK_CLASS MutableHandle : public js::MutableHandleBase { public: - inline MutableHandle(Rooted *root); - inline MutableHandle(PersistentRooted *root); - MutableHandle(int) MOZ_DELETE; -#ifdef MOZ_HAVE_CXX11_NULLPTR - MutableHandle(decltype(nullptr)) MOZ_DELETE; -#endif + inline MOZ_IMPLICIT MutableHandle(Rooted *root); + inline MOZ_IMPLICIT MutableHandle(PersistentRooted *root); + + private: + // Disallow true nullptr and emulated nullptr (gcc 4.4/4.5, __null, appears + // as int/long [32/64-bit]) for overloading purposes. + template + MutableHandle(N, + typename mozilla::EnableIf::value || + mozilla::IsSame::value || + mozilla::IsSame::value, + int>::Type dummy = 0) + MOZ_DELETE; + public: void set(T v) { - JS_ASSERT(!js::GCMethods::poisoned(v)); + MOZ_ASSERT(!js::GCMethods::poisoned(v)); *ptr = v; } @@ -549,8 +563,8 @@ class MOZ_STACK_CLASS MutableHandle : public js::MutableHandleBase }; #ifdef JSGC_GENERATIONAL -JS_PUBLIC_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); -JS_PUBLIC_API(void) HeapCellRelocate(js::gc::Cell **cellp); +JS_FRIEND_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); +JS_FRIEND_API(void) HeapCellRelocate(js::gc::Cell **cellp); #endif } /* namespace JS */ @@ -612,7 +626,7 @@ class InternalHandle * Make this private to prevent accidental misuse; this is only for * fromMarkedLocation(). */ - InternalHandle(T *field) + explicit InternalHandle(T *field) : holder(reinterpret_cast(&js::NullPtr::constNullValue)), offset(uintptr_t(field)) {} @@ -621,10 +635,16 @@ class InternalHandle }; /* - * By default, pointers should use the inheritance hierarchy to find their + * By default, things should use the inheritance hierarchy to find their * ThingRootKind. Some pointer types are explicitly set in jspubtd.h so that * Rooted may be used without the class definition being available. */ +template +struct RootKind +{ + static ThingRootKind rootKind() { return T::rootKind(); } +}; + template struct RootKind { @@ -635,20 +655,51 @@ template struct GCMethods { static T *initial() { return nullptr; } - static ThingRootKind kind() { return RootKind::rootKind(); } static bool poisoned(T *v) { return JS::IsPoisonedPtr(v); } - static bool needsPostBarrier(T *v) { return v; } + static bool needsPostBarrier(T *v) { return false; } #ifdef JSGC_GENERATIONAL - static void postBarrier(T **vp) { + static void postBarrier(T **vp) {} + static void relocate(T **vp) {} +#endif +}; + +template <> +struct GCMethods +{ + static JSObject *initial() { return nullptr; } + static bool poisoned(JSObject *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSObject *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSObject **vp) { JS::HeapCellPostBarrier(reinterpret_cast(vp)); } - static void relocate(T **vp) { + static void relocate(JSObject **vp) { JS::HeapCellRelocate(reinterpret_cast(vp)); } #endif }; -#if defined(DEBUG) +template <> +struct GCMethods +{ + static JSFunction *initial() { return nullptr; } + static bool poisoned(JSFunction *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSFunction *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSFunction **vp) { + JS::HeapCellPostBarrier(reinterpret_cast(vp)); + } + static void relocate(JSFunction **vp) { + JS::HeapCellRelocate(reinterpret_cast(vp)); + } +#endif +}; + +#ifdef JS_DEBUG /* This helper allows us to assert that Rooted is scoped within a request. */ extern JS_PUBLIC_API(bool) IsInRequest(JSContext *cx); @@ -673,22 +724,24 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase template void init(CX *cx) { #ifdef JSGC_TRACK_EXACT_ROOTS - js::ThingRootKind kind = js::GCMethods::kind(); + js::ThingRootKind kind = js::RootKind::rootKind(); this->stack = &cx->thingGCRooters[kind]; this->prev = *stack; *stack = reinterpret_cast*>(this); - JS_ASSERT(!js::GCMethods::poisoned(ptr)); + MOZ_ASSERT(!js::GCMethods::poisoned(ptr)); #endif } public: - Rooted(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG MOZ_ASSERT(js::IsInRequest(cx)); +#endif init(js::ContextFriendFields::get(cx)); } @@ -697,12 +750,14 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase : ptr(initial) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG MOZ_ASSERT(js::IsInRequest(cx)); +#endif init(js::ContextFriendFields::get(cx)); } - Rooted(js::ContextFriendFields *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(js::ContextFriendFields *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -717,8 +772,8 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase init(cx); } - Rooted(js::PerThreadDataFriendFields *pt - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(js::PerThreadDataFriendFields *pt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -733,8 +788,8 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase init(pt); } - Rooted(JSRuntime *rt - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(JSRuntime *rt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -754,13 +809,13 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase // using MSVC, see bug 915735 for more details. #ifdef JSGC_TRACK_EXACT_ROOTS ~Rooted() { - JS_ASSERT(*stack == reinterpret_cast*>(this)); + MOZ_ASSERT(*stack == reinterpret_cast*>(this)); *stack = prev; } #endif #ifdef JSGC_TRACK_EXACT_ROOTS - Rooted *previous() { return prev; } + Rooted *previous() { return reinterpret_cast*>(prev); } #endif /* @@ -775,7 +830,7 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase const T &get() const { return ptr; } T &operator=(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; return ptr; } @@ -786,7 +841,7 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase } void set(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; } @@ -795,16 +850,12 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase private: #ifdef JSGC_TRACK_EXACT_ROOTS - Rooted **stack, *prev; -#endif - -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* Has the rooting analysis ever scanned this Rooted's stack location? */ - friend void JS::CheckStackRoots(JSContext*); -#endif - -#ifdef JSGC_ROOT_ANALYSIS - bool scanned; + /* + * These need to be templated on void* to avoid aliasing issues between, for + * example, Rooted and Rooted, which use the same + * stack head pointer for different classes. + */ + Rooted **stack, *prev; #endif /* @@ -818,90 +869,26 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase Rooted(const Rooted &) MOZ_DELETE; }; -#if !(defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)) -// Defined in vm/String.h. -template <> -class Rooted; -#endif - } /* namespace JS */ namespace js { /* - * Mark a stack location as a root for the rooting analysis, without actually - * rooting it in release builds. This should only be used for stack locations - * of GC things that cannot be relocated by a garbage collection, and that - * are definitely reachable via another path. + * Augment the generic Rooted interface when T = JSObject* with + * class-querying and downcasting operations. + * + * Given a Rooted obj, one can view + * Handle h = obj.as(); + * as an optimization of + * Rooted rooted(cx, &obj->as()); + * Handle h = rooted; */ -class SkipRoot +template <> +class RootedBase { -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - - SkipRoot **stack, *prev; - const uint8_t *start; - const uint8_t *end; - - template - void init(CX *cx, const T *ptr, size_t count) { - SkipRoot **head = &cx->skipGCRooters; - this->stack = head; - this->prev = *stack; - *stack = this; - this->start = (const uint8_t *) ptr; - this->end = this->start + (sizeof(T) * count); - } - public: - ~SkipRoot() { - JS_ASSERT(*stack == this); - *stack = prev; - } - - SkipRoot *previous() { return prev; } - - bool contains(const uint8_t *v, size_t len) { - return v >= start && v + len <= end; - } - -#else /* DEBUG && JSGC_ROOT_ANALYSIS */ - - template - void init(js::ContextFriendFields *cx, const T *ptr, size_t count) {} - - public: - ~SkipRoot() { - // An empty destructor is needed to avoid warnings from clang about - // unused local variables of this type. - } - -#endif /* DEBUG && JSGC_ROOT_ANALYSIS */ - - template - SkipRoot(JSContext *cx, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(ContextFriendFields::get(cx), ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - template - SkipRoot(ContextFriendFields *cx, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(cx, ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - template - SkipRoot(PerThreadData *pt, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(PerThreadDataFriendFields::get(pt), ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + template + JS::Handle as() const; }; /* Interface substitute for Rooted which does not root the variable's memory. */ @@ -933,13 +920,13 @@ class FakeRooted : public RootedBase const T &get() const { return ptr; } FakeRooted &operator=(T value) { - JS_ASSERT(!GCMethods::poisoned(value)); + MOZ_ASSERT(!GCMethods::poisoned(value)); ptr = value; return *this; } FakeRooted &operator=(const FakeRooted &other) { - JS_ASSERT(!GCMethods::poisoned(other.ptr)); + MOZ_ASSERT(!GCMethods::poisoned(other.ptr)); ptr = other.ptr; return *this; } @@ -960,16 +947,16 @@ template class FakeMutableHandle : public js::MutableHandleBase { public: - FakeMutableHandle(T *t) { + MOZ_IMPLICIT FakeMutableHandle(T *t) { ptr = t; } - FakeMutableHandle(FakeRooted *root) { + MOZ_IMPLICIT FakeMutableHandle(FakeRooted *root) { ptr = root->address(); } void set(T v) { - JS_ASSERT(!js::GCMethods::poisoned(v)); + MOZ_ASSERT(!js::GCMethods::poisoned(v)); *ptr = v; } @@ -992,7 +979,7 @@ class FakeMutableHandle : public js::MutableHandleBase /* * Types for a variable that either should or shouldn't be rooted, depending on - * the template parameter Rooted. Used for implementing functions that can + * the template parameter allowGC. Used for implementing functions that can * operate on either rooted or unrooted data. * * The toHandle() and toMutableHandle() functions are for calling functions @@ -1031,12 +1018,12 @@ template class MaybeRooted typedef FakeRooted RootType; typedef FakeMutableHandle MutableHandleType; - static inline JS::Handle toHandle(HandleType v) { - MOZ_ASSUME_UNREACHABLE("Bad conversion"); + static JS::Handle toHandle(HandleType v) { + MOZ_CRASH("Bad conversion"); } - static inline JS::MutableHandle toMutableHandle(MutableHandleType v) { - MOZ_ASSUME_UNREACHABLE("Bad conversion"); + static JS::MutableHandle toMutableHandle(MutableHandleType v) { + MOZ_CRASH("Bad conversion"); } }; @@ -1086,7 +1073,6 @@ MutableHandle::MutableHandle(PersistentRooted *root) ptr = root->address(); } - /* * A copyable, assignable global GC root type with arbitrary lifetime, an * infallible constructor, and automatic unrooting on destruction. @@ -1120,9 +1106,11 @@ MutableHandle::MutableHandle(PersistentRooted *root) * marked when the object itself is marked. */ template -class PersistentRooted : public mozilla::LinkedListElement > { - typedef mozilla::LinkedList List; - typedef mozilla::LinkedListElement Element; +class PersistentRooted : private mozilla::LinkedListElement > { + friend class mozilla::LinkedList; + friend class mozilla::LinkedListElement; + + friend struct js::gc::PersistentRootedMarker; void registerWithRuntime(JSRuntime *rt) { JS::shadow::Runtime *srt = JS::shadow::Runtime::asShadowRuntime(rt); @@ -1130,7 +1118,7 @@ class PersistentRooted : public mozilla::LinkedListElement > } public: - PersistentRooted(JSContext *cx) : ptr(js::GCMethods::initial()) + explicit PersistentRooted(JSContext *cx) : ptr(js::GCMethods::initial()) { registerWithRuntime(js::GetRuntime(cx)); } @@ -1140,7 +1128,7 @@ class PersistentRooted : public mozilla::LinkedListElement > registerWithRuntime(js::GetRuntime(cx)); } - PersistentRooted(JSRuntime *rt) : ptr(js::GCMethods::initial()) + explicit PersistentRooted(JSRuntime *rt) : ptr(js::GCMethods::initial()) { registerWithRuntime(rt); } @@ -1150,14 +1138,19 @@ class PersistentRooted : public mozilla::LinkedListElement > registerWithRuntime(rt); } - PersistentRooted(PersistentRooted &rhs) : ptr(rhs.ptr) + PersistentRooted(const PersistentRooted &rhs) + : mozilla::LinkedListElement >(), + ptr(rhs.ptr) { /* * Copy construction takes advantage of the fact that the original * is already inserted, and simply adds itself to whatever list the * original was on - no JSRuntime pointer needed. + * + * This requires mutating rhs's links, but those should be 'mutable' + * anyway. C++ doesn't let us declare mutable base classes. */ - rhs.setNext(this); + const_cast(rhs).setNext(this); } /* @@ -1172,7 +1165,7 @@ class PersistentRooted : public mozilla::LinkedListElement > const T &get() const { return ptr; } T &operator=(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; return ptr; } @@ -1183,7 +1176,7 @@ class PersistentRooted : public mozilla::LinkedListElement > } void set(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; } @@ -1194,26 +1187,56 @@ class PersistentRooted : public mozilla::LinkedListElement > T ptr; }; +class JS_PUBLIC_API(ObjectPtr) +{ + Heap value; + + public: + ObjectPtr() : value(nullptr) {} + + explicit ObjectPtr(JSObject *obj) : value(obj) {} + + /* Always call finalize before the destructor. */ + ~ObjectPtr() { MOZ_ASSERT(!value); } + + void finalize(JSRuntime *rt) { + if (IsIncrementalBarrierNeeded(rt)) + IncrementalObjectBarrier(value); + value = nullptr; + } + + void init(JSObject *obj) { value = obj; } + + JSObject *get() const { return value; } + + void writeBarrierPre(JSRuntime *rt) { + IncrementalObjectBarrier(value); + } + + bool isAboutToBeFinalized(); + + ObjectPtr &operator=(JSObject *obj) { + IncrementalObjectBarrier(value); + value = obj; + return *this; + } + + void trace(JSTracer *trc, const char *name); + + JSObject &operator*() const { return *value; } + JSObject *operator->() const { return value; } + operator JSObject *() const { return value; } +}; + } /* namespace JS */ namespace js { -/* - * Hook for dynamic root analysis. Checks the native stack and poisons - * references to GC things which have not been rooted. - */ -inline void MaybeCheckStackRoots(JSContext *cx) -{ -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - JS::CheckStackRoots(cx); -#endif -} - /* Base class for automatic read-only object rooting during compilation. */ class CompilerRootNode { protected: - CompilerRootNode(js::gc::Cell *ptr) : next(nullptr), ptr_(ptr) {} + explicit CompilerRootNode(js::gc::Cell *ptr) : next(nullptr), ptr_(ptr) {} public: void **address() { return (void **)&ptr_; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/SliceBudget.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/SliceBudget.h index ccade643b3..7c602c5572 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/SliceBudget.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/SliceBudget.h @@ -32,11 +32,11 @@ struct JS_PUBLIC_API(SliceBudget) SliceBudget(); /* Instantiate as SliceBudget(Time/WorkBudget(n)). */ - SliceBudget(int64_t budget); + explicit SliceBudget(int64_t budget); void reset() { - deadline = INT64_MAX; - counter = INTPTR_MAX; + deadline = unlimitedDeadline; + counter = unlimitedStartCounter; } void step(intptr_t amt = 1) { @@ -50,6 +50,15 @@ struct JS_PUBLIC_API(SliceBudget) return false; return checkOverBudget(); } + + bool isUnlimited() { + return deadline == unlimitedDeadline; + } + +private: + static const int64_t unlimitedDeadline = INT64_MAX; + static const intptr_t unlimitedStartCounter = INTPTR_MAX; + }; } // namespace js diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/StructuredClone.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/StructuredClone.h index d32bdd8dd6..fa48ce045a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/StructuredClone.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/StructuredClone.h @@ -23,6 +23,35 @@ struct JSStructuredCloneWriter; // API for the HTML5 internal structured cloning algorithm. +namespace JS { +enum TransferableOwnership { + // Transferable data has not been filled in yet + SCTAG_TMO_UNFILLED = 0, + + // Structured clone buffer does not yet own the data + SCTAG_TMO_UNOWNED = 1, + + // All values at least this large are owned by the clone buffer + SCTAG_TMO_FIRST_OWNED = 2, + + // Data is a pointer that can be freed + SCTAG_TMO_ALLOC_DATA = 2, + + // Data is a SharedArrayBufferObject's buffer + SCTAG_TMO_SHARED_BUFFER = 3, + + // Data is a memory mapped pointer + SCTAG_TMO_MAPPED_DATA = 4, + + // Data is embedding-specific. The engine can free it by calling the + // freeTransfer op. The embedding can also use SCTAG_TMO_USER_MIN and + // greater, up to 32 bits, to distinguish specific ownership variants. + SCTAG_TMO_CUSTOM = 5, + + SCTAG_TMO_USER_MIN +}; +} /* namespace JS */ + // Read structured data from the reader r. This hook is used to read a value // previously serialized by a call to the WriteStructuredCloneOp hook. // @@ -43,22 +72,64 @@ typedef JSObject *(*ReadStructuredCloneOp)(JSContext *cx, JSStructuredCloneReade // // Return true on success, false on error/exception. typedef bool (*WriteStructuredCloneOp)(JSContext *cx, JSStructuredCloneWriter *w, - JS::Handle obj, void *closure); + JS::HandleObject obj, void *closure); // This is called when JS_WriteStructuredClone is given an invalid transferable. // To follow HTML5, the application must throw a DATA_CLONE_ERR DOMException // with error set to one of the JS_SCERR_* values. typedef void (*StructuredCloneErrorOp)(JSContext *cx, uint32_t errorid); +// This is called when JS_ReadStructuredClone receives a transferable object +// not known to the engine. If this hook does not exist or returns false, the +// JS engine calls the reportError op if set, otherwise it throws a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback and must return a non-null object in returnObject on success. +typedef bool (*ReadTransferStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r, + uint32_t tag, void *content, uint64_t extraData, + void *closure, + JS::MutableHandleObject returnObject); + +// Called when JS_WriteStructuredClone receives a transferable object not +// handled by the engine. If this hook does not exist or returns false, the JS +// engine will call the reportError hook or fall back to throwing a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback. +// +// tag: indicates what type of transferable this is. Must be greater than +// 0xFFFF0201 (value of the internal SCTAG_TRANSFER_MAP_PENDING_ENTRY) +// +// ownership: see TransferableOwnership, above. Used to communicate any needed +// ownership info to the FreeTransferStructuredCloneOp. +// +// content, extraData: what the ReadTransferStructuredCloneOp will receive +// +typedef bool (*TransferStructuredCloneOp)(JSContext *cx, + JS::Handle obj, + void *closure, + // Output: + uint32_t *tag, + JS::TransferableOwnership *ownership, + void **content, + uint64_t *extraData); + +// Called when JS_ClearStructuredClone has to free an unknown transferable +// object. Note that it should never trigger a garbage collection (and will +// assert in a debug build if it does.) +typedef void (*FreeTransferStructuredCloneOp)(uint32_t tag, JS::TransferableOwnership ownership, + void *content, uint64_t extraData, void *closure); + // The maximum supported structured-clone serialization format version. Note // that this does not need to be bumped for Transferable-only changes, since // they are never saved to persistent storage. -#define JS_STRUCTURED_CLONE_VERSION 2 +#define JS_STRUCTURED_CLONE_VERSION 4 struct JSStructuredCloneCallbacks { ReadStructuredCloneOp read; WriteStructuredCloneOp write; StructuredCloneErrorOp reportError; + ReadTransferStructuredCloneOp readTransfer; + TransferStructuredCloneOp writeTransfer; + FreeTransferStructuredCloneOp freeTransfer; }; // Note: if the *data contains transferable objects, it can be read only once. @@ -68,14 +139,16 @@ JS_ReadStructuredClone(JSContext *cx, uint64_t *data, size_t nbytes, uint32_t ve const JSStructuredCloneCallbacks *optionalCallbacks, void *closure); // Note: On success, the caller is responsible for calling -// JS_ClearStructuredClone(*datap, nbytesp). +// JS_ClearStructuredClone(*datap, nbytes, optionalCallbacks, closure). JS_PUBLIC_API(bool) JS_WriteStructuredClone(JSContext *cx, JS::HandleValue v, uint64_t **datap, size_t *nbytesp, const JSStructuredCloneCallbacks *optionalCallbacks, void *closure, JS::HandleValue transferable); JS_PUBLIC_API(bool) -JS_ClearStructuredClone(const uint64_t *data, size_t nbytes); +JS_ClearStructuredClone(uint64_t *data, size_t nbytes, + const JSStructuredCloneCallbacks *optionalCallbacks, + void *closure); JS_PUBLIC_API(bool) JS_StructuredCloneHasTransferables(const uint64_t *data, size_t nbytes, bool *hasTransferable); @@ -89,10 +162,22 @@ class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) { uint64_t *data_; size_t nbytes_; uint32_t version_; + const JSStructuredCloneCallbacks *callbacks_; + void *closure_; public: JSAutoStructuredCloneBuffer() - : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION) {} + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(nullptr), closure_(nullptr) + {} + + JSAutoStructuredCloneBuffer(const JSStructuredCloneCallbacks *callbacks, void *closure) + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(callbacks), closure_(closure) + {} + + JSAutoStructuredCloneBuffer(JSAutoStructuredCloneBuffer &&other); + JSAutoStructuredCloneBuffer &operator=(JSAutoStructuredCloneBuffer &&other); ~JSAutoStructuredCloneBuffer() { clear(); } @@ -123,13 +208,10 @@ class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) { bool write(JSContext *cx, JS::HandleValue v, JS::HandleValue transferable, const JSStructuredCloneCallbacks *optionalCallbacks=nullptr, void *closure=nullptr); - // Swap ownership with another JSAutoStructuredCloneBuffer. - void swap(JSAutoStructuredCloneBuffer &other); - private: // Copy and assignment are not supported. - JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other); - JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other); + JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; + JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; }; // The range of tag values the application may use for its own custom object types. @@ -149,7 +231,7 @@ JS_PUBLIC_API(bool) JS_ReadBytes(JSStructuredCloneReader *r, void *p, size_t len); JS_PUBLIC_API(bool) -JS_ReadTypedArray(JSStructuredCloneReader *r, JS::Value *vp); +JS_ReadTypedArray(JSStructuredCloneReader *r, JS::MutableHandleValue vp); JS_PUBLIC_API(bool) JS_WriteUint32Pair(JSStructuredCloneWriter *w, uint32_t tag, uint32_t data); @@ -158,6 +240,6 @@ JS_PUBLIC_API(bool) JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len); JS_PUBLIC_API(bool) -JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::Value v); +JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::HandleValue v); #endif /* js_StructuredClone_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/Tracer.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/TracingAPI.h similarity index 53% rename from frameworks/js-bindings/external/spidermonkey/include/linux/js/Tracer.h rename to frameworks/js-bindings/external/spidermonkey/include/linux/js/TracingAPI.h index 89994612f6..3c7fdbe1b1 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/Tracer.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/TracingAPI.h @@ -4,14 +4,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef js_Tracer_h -#define js_Tracer_h +#ifndef js_TracingAPI_h +#define js_TracingAPI_h #include "mozilla/NullPtr.h" - + #include "jspubtd.h" -struct JSTracer; +class JS_PUBLIC_API(JSTracer); namespace JS { template class Heap; @@ -46,74 +46,101 @@ enum WeakMapTraceKind { TraceWeakMapKeysValues = 2 }; -struct JSTracer { - JSRuntime *runtime; - JSTraceCallback callback; - JSTraceNamePrinter debugPrinter; - const void *debugPrintArg; - size_t debugPrintIndex; - WeakMapTraceKind eagerlyTraceWeakMaps; -#ifdef JS_GC_ZEAL - void *realLocation; -#endif -}; +class JS_PUBLIC_API(JSTracer) +{ + public: + JSTracer(JSRuntime *rt, JSTraceCallback traceCallback, + WeakMapTraceKind weakTraceKind = TraceWeakMapValues); + + // Set debugging information about a reference to a traceable thing to prepare + // for the following call to JS_CallTracer. + // + // When printer is null, arg must be const char * or char * C string naming + // the reference and index must be either (size_t)-1 indicating that the name + // alone describes the reference or it must be an index into some array vector + // that stores the reference. + // + // When printer callback is not null, the arg and index arguments are + // available to the callback as debugPrintArg_ and debugPrintIndex_ fields + // of JSTracer. + // + // The storage for name or callback's arguments needs to live only until + // the following call to JS_CallTracer returns. + void setTracingDetails(JSTraceNamePrinter printer, const void *arg, size_t index) { + debugPrinter_ = printer; + debugPrintArg_ = arg; + debugPrintIndex_ = index; + } + + void setTracingIndex(const char *name, size_t index) { + setTracingDetails(nullptr, (void *)name, index); + } + + void setTracingName(const char *name) { + setTracingDetails(nullptr, (void *)name, size_t(-1)); + } + + // Remove the currently set tracing details. + void clearTracingDetails() { + debugPrinter_ = nullptr; + debugPrintArg_ = nullptr; + } + + // Return true if tracing details are currently set. + bool hasTracingDetails() const; + + // Get the string set with the most recent call to setTracingName or return + // fallback if a name printer function has been installed. + const char *tracingName(const char *fallback) const; + + // Build a description of this edge in the heap graph. This call may invoke + // the debug printer, which may inspect arbitrary areas of the heap. + const char *getTracingEdgeName(char *buffer, size_t bufferSize); + + // Access the currently active tracing details. + JSTraceNamePrinter debugPrinter() const; + const void *debugPrintArg() const; + size_t debugPrintIndex() const; + + // Return the runtime set on the tracer. + JSRuntime *runtime() const { return runtime_; } + + // Return the weak map tracing behavior set on this tracer. + WeakMapTraceKind eagerlyTraceWeakMaps() const { return eagerlyTraceWeakMaps_; } + + // Update the trace callback. + void setTraceCallback(JSTraceCallback traceCallback); -// Set debugging information about a reference to a traceable thing to prepare -// for the following call to JS_CallTracer. -// -// When printer is null, arg must be const char * or char * C string naming -// the reference and index must be either (size_t)-1 indicating that the name -// alone describes the reference or it must be an index into some array vector -// that stores the reference. -// -// When printer callback is not null, the arg and index arguments are -// available to the callback as debugPrintArg and debugPrintIndex fields -// of JSTracer. -// -// The storage for name or callback's arguments needs to live only until -// the following call to JS_CallTracer returns. -// -# define JS_SET_TRACING_DETAILS(trc, printer, arg, index) \ - JS_BEGIN_MACRO \ - (trc)->debugPrinter = (printer); \ - (trc)->debugPrintArg = (arg); \ - (trc)->debugPrintIndex = (index); \ - JS_END_MACRO - -// Sets the real location for a marked reference, when passing the address -// directly is not feasable. -// -// FIXME: This is currently overcomplicated by our need to nest calls for Values -// stored as keys in hash tables, but will get simplified once we can rekey -// in-place. -// #ifdef JS_GC_ZEAL -# define JS_SET_TRACING_LOCATION(trc, location) \ - JS_BEGIN_MACRO \ - if (!(trc)->realLocation || !(location)) \ - (trc)->realLocation = (location); \ - JS_END_MACRO -# define JS_UNSET_TRACING_LOCATION(trc) \ - JS_BEGIN_MACRO \ - (trc)->realLocation = nullptr; \ - JS_END_MACRO + // Sets the "real" location for a marked reference, when passing the address + // directly is not feasable. This address is used for matching against the + // store buffer when verifying the correctness of the entrees there. + // + // This is currently complicated by our need to nest calls for Values + // stored as keys in hash tables. + void setTracingLocation(void *location); + void unsetTracingLocation(); + void **tracingLocation(void **thingp); #else -# define JS_SET_TRACING_LOCATION(trc, location) \ - JS_BEGIN_MACRO \ - JS_END_MACRO -# define JS_UNSET_TRACING_LOCATION(trc) \ - JS_BEGIN_MACRO \ - JS_END_MACRO + void setTracingLocation(void *location) {} + void unsetTracingLocation() {} + void **tracingLocation(void **thingp) { return nullptr; } #endif -// Convenience macro to describe the argument of JS_CallTracer using C string -// and index. -# define JS_SET_TRACING_INDEX(trc, name, index) \ - JS_SET_TRACING_DETAILS(trc, nullptr, name, index) + // We expose |callback| directly so that IS_GC_MARKING_TRACER can compare + // it to GCMarker::GrayCallback. + JSTraceCallback callback; -// Convenience macro to describe the argument of JS_CallTracer using C string. -# define JS_SET_TRACING_NAME(trc, name) \ - JS_SET_TRACING_DETAILS(trc, nullptr, name, (size_t)-1) + private: + JSRuntime *runtime_; + JSTraceNamePrinter debugPrinter_; + const void *debugPrintArg_; + size_t debugPrintIndex_; + WeakMapTraceKind eagerlyTraceWeakMaps_; +#ifdef JS_GC_ZEAL + void *realLocation_; +#endif +}; // The JS_Call*Tracer family of functions traces the given GC thing reference. // This performs the tracing action configured on the given JSTracer: @@ -157,12 +184,15 @@ JS_CallHeapStringTracer(JSTracer *trc, JS::Heap *strp, const char *n extern JS_PUBLIC_API(void) JS_CallHeapScriptTracer(JSTracer *trc, JS::Heap *scriptp, const char *name); +extern JS_PUBLIC_API(void) +JS_CallHeapFunctionTracer(JSTracer *trc, JS::Heap *funp, const char *name); + template inline void JS_CallHashSetObjectTracer(JSTracer *trc, HashSetEnum &e, JSObject *const &key, const char *name) { JSObject *updated = key; - JS_SET_TRACING_LOCATION(trc, reinterpret_cast(&const_cast(key))); + trc->setTracingLocation(reinterpret_cast(&const_cast(key))); JS_CallObjectTracer(trc, &updated, name); if (updated != key) e.rekeyFront(key, updated); @@ -173,10 +203,6 @@ JS_CallHashSetObjectTracer(JSTracer *trc, HashSetEnum &e, JSObject *const &key, extern JS_PUBLIC_API(void) JS_CallTenuredObjectTracer(JSTracer *trc, JS::TenuredHeap *objp, const char *name); -// API for JSTraceCallback implementations. -extern JS_PUBLIC_API(void) -JS_TracerInit(JSTracer *trc, JSRuntime *rt, JSTraceCallback callback); - extern JS_PUBLIC_API(void) JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind); @@ -187,7 +213,4 @@ extern JS_PUBLIC_API(void) JS_GetTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc, void *thing, JSGCTraceKind kind, bool includeDetails); -extern JS_PUBLIC_API(const char *) -JS_GetTraceEdgeName(JSTracer *trc, char *buffer, int bufferSize); - -#endif /* js_Tracer_h */ +#endif /* js_TracingAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/TypeDecls.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/TypeDecls.h index 027d7b8fb7..3e1e8afc66 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/TypeDecls.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/TypeDecls.h @@ -20,44 +20,24 @@ #include #include +#include "js-config.h" + struct JSContext; class JSFunction; class JSObject; class JSScript; class JSString; +class JSAddonId; -// In release builds, jsid is defined to be an integral type. This -// prevents many bugs from being caught at compile time. E.g.: -// -// jsid id = ... -// if (id) // error -// ... -// -// size_t n = id; // error -// -// To catch more errors, jsid is given a struct type in C++ debug builds. -// Struct assignment and (in C++) operator== allow correct code to be mostly -// oblivious to the change. This feature can be explicitly disabled in debug -// builds by defining JS_NO_JSVAL_JSID_STRUCT_TYPES. -// - -// Needed for cocos2d-js -#define JS_NO_JSVAL_JSID_STRUCT_TYPES - -#if defined(DEBUG) && !defined(JS_NO_JSVAL_JSID_STRUCT_TYPES) -# define JS_USE_JSID_STRUCT_TYPES -#endif - -#ifdef JS_USE_JSID_STRUCT_TYPES struct jsid; -#else -typedef ptrdiff_t jsid; -#endif typedef char16_t jschar; namespace JS { +typedef unsigned char Latin1Char; + +class Symbol; class Value; template class Handle; template class MutableHandle; @@ -69,6 +49,7 @@ typedef Handle HandleId; typedef Handle HandleObject; typedef Handle HandleScript; typedef Handle HandleString; +typedef Handle HandleSymbol; typedef Handle HandleValue; typedef MutableHandle MutableHandleFunction; @@ -76,12 +57,14 @@ typedef MutableHandle MutableHandleId; typedef MutableHandle MutableHandleObject; typedef MutableHandle MutableHandleScript; typedef MutableHandle MutableHandleString; +typedef MutableHandle MutableHandleSymbol; typedef MutableHandle MutableHandleValue; typedef Rooted RootedObject; typedef Rooted RootedFunction; typedef Rooted RootedScript; typedef Rooted RootedString; +typedef Rooted RootedSymbol; typedef Rooted RootedId; typedef Rooted RootedValue; @@ -90,6 +73,7 @@ typedef PersistentRooted PersistentRootedId; typedef PersistentRooted PersistentRootedObject; typedef PersistentRooted PersistentRootedScript; typedef PersistentRooted PersistentRootedString; +typedef PersistentRooted PersistentRootedSymbol; typedef PersistentRooted PersistentRootedValue; } // namespace JS diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/UbiNode.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/UbiNode.h new file mode 100644 index 0000000000..d2acc2e242 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/UbiNode.h @@ -0,0 +1,462 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_UbiNode_h +#define js_UbiNode_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" + +#include "jspubtd.h" + +#include "js/GCAPI.h" +#include "js/HashTable.h" +#include "js/TypeDecls.h" + +// JS::ubi::Node +// +// JS::ubi::Node is a pointer-like type designed for internal use by heap +// analysis tools. A ubi::Node can refer to: +// +// - a JS value, like a string or object; +// - an internal SpiderMonkey structure, like a shape or a scope chain object +// - an instance of some embedding-provided type: in Firefox, an XPCOM +// object, or an internal DOM node class instance +// +// A ubi::Node instance provides metadata about its referent, and can +// enumerate its referent's outgoing edges, so you can implement heap analysis +// algorithms that walk the graph - finding paths between objects, or +// computing heap dominator trees, say - using ubi::Node, while remaining +// ignorant of the details of the types you're operating on. +// +// Of course, when it comes to presenting the results in a developer-facing +// tool, you'll need to stop being ignorant of those details, because you have +// to discuss the ubi::Nodes' referents with the developer. Here, ubi::Node +// can hand you dynamically checked, properly typed pointers to the original +// objects via the as method, or generate descriptions of the referent +// itself. +// +// ubi::Node instances are lightweight (two-word) value types. Instances: +// - compare equal if and only if they refer to the same object; +// - have hash values that respect their equality relation; and +// - have serializations that are only equal if the ubi::Nodes are equal. +// +// A ubi::Node is only valid for as long as its referent is alive; if its +// referent goes away, the ubi::Node becomes a dangling pointer. A ubi::Node +// that refers to a GC-managed object is not automatically a GC root; if the +// GC frees or relocates its referent, the ubi::Node becomes invalid. A +// ubi::Node that refers to a reference-counted object does not bump the +// reference count. +// +// ubi::Node values require no supporting data structures, making them +// feasible for use in memory-constrained devices --- ideally, the memory +// requirements of the algorithm which uses them will be the limiting factor, +// not the demands of ubi::Node itself. +// +// One can construct a ubi::Node value given a pointer to a type that ubi::Node +// supports. In the other direction, one can convert a ubi::Node back to a +// pointer; these downcasts are checked dynamically. In particular, one can +// convert a 'JSRuntime *' to a ubi::Node, yielding a node with an outgoing edge +// for every root registered with the runtime; starting from this, one can walk +// the entire heap. (Of course, one could also start traversal at any other kind +// of type to which one has a pointer.) +// +// +// Extending ubi::Node To Handle Your Embedding's Types +// +// To add support for a new ubi::Node referent type R, you must define a +// specialization of the ubi::Concrete template, ubi::Concrete, which +// inherits from ubi::Base. ubi::Node itself uses the specialization for +// compile-time information (i.e. the checked conversions between R * and +// ubi::Node), and the inheritance for run-time dispatching. +// +// +// ubi::Node Exposes Implementation Details +// +// In many cases, a JavaScript developer's view of their data differs +// substantially from its actual implementation. For example, while the +// ECMAScript specification describes objects as maps from property names to +// sets of attributes (like ECMAScript's [[Value]]), in practice many objects +// have only a pointer to a shape, shared with other similar objects, and +// indexed slots that contain the [[Value]] attributes. As another example, a +// string produced by concatenating two other strings may sometimes be +// represented by a "rope", a structure that points to the two original +// strings. +// + +// We intend to use ubi::Node to write tools that report memory usage, so it's +// important that ubi::Node accurately portray how much memory nodes consume. +// Thus, for example, when data that apparently belongs to multiple nodes is +// in fact shared in a common structure, ubi::Node's graph uses a separate +// node for that shared structure, and presents edges to it from the data's +// apparent owners. For example, ubi::Node exposes SpiderMonkey objects' +// shapes and base shapes, and exposes rope string and substring structure, +// because these optimizations become visible when a tool reports how much +// memory a structure consumes. +// +// However, fine granularity is not a goal. When a particular object is the +// exclusive owner of a separate block of memory, ubi::Node may present the +// object and its block as a single node, and add their sizes together when +// reporting the node's size, as there is no meaningful loss of data in this +// case. Thus, for example, a ubi::Node referring to a JavaScript object, when +// asked for the object's size in bytes, includes the object's slot and +// element arrays' sizes in the total. There is no separate ubi::Node value +// representing the slot and element arrays, since they are owned exclusively +// by the object. +// +// +// Presenting Analysis Results To JavaScript Developers +// +// If an analysis provides its results in terms of ubi::Node values, a user +// interface presenting those results will generally need to clean them up +// before they can be understood by JavaScript developers. For example, +// JavaScript developers should not need to understand shapes, only JavaScript +// objects. Similarly, they should not need to understand the distinction +// between DOM nodes and the JavaScript shadow objects that represent them. +// +// +// Rooting Restrictions +// +// At present there is no way to root ubi::Node instances, so instances can't be +// live across any operation that might GC. Analyses using ubi::Node must either +// run to completion and convert their results to some other rootable type, or +// save their intermediate state in some rooted structure if they must GC before +// they complete. (For algorithms like path-finding and dominator tree +// computation, we implement the algorithm avoiding any operation that could +// cause a GC --- and use AutoCheckCannotGC to verify this.) +// +// If this restriction prevents us from implementing interesting tools, we may +// teach the GC how to root ubi::Nodes, fix up hash tables that use them as +// keys, etc. + + +// Forward declarations of SpiderMonkey's ubi::Node reference types. +namespace js { +class LazyScript; +class Shape; +class BaseShape; +namespace jit { +class JitCode; +} +namespace types { +struct TypeObject; +} +} + + +namespace JS { +namespace ubi { + +class Edge; +class EdgeRange; + +// The base class implemented by each ubi::Node referent type. Subclasses must +// not add data members to this class. +class Base { + friend class Node; + + // For performance's sake, we'd prefer to avoid a virtual destructor; and + // an empty constructor seems consistent with the 'lightweight value type' + // visible behavior we're trying to achieve. But if the destructor isn't + // virtual, and a subclass overrides it, the subclass's destructor will be + // ignored. Is there a way to make the compiler catch that error? + + protected: + // Space for the actual pointer. Concrete subclasses should define a + // properly typed 'get' member function to access this. + void *ptr; + + Base(void *ptr) : ptr(ptr) { } + + public: + bool operator==(const Base &rhs) const { + // Some compilers will indeed place objects of different types at + // the same address, so technically, we should include the vtable + // in this comparison. But it seems unlikely to cause problems in + // practice. + return ptr == rhs.ptr; + } + bool operator!=(const Base &rhs) const { return !(*this == rhs); } + + // Return a human-readable name for the referent's type. The result should + // be statically allocated. (You can use MOZ_UTF16("strings") for this.) + // + // This must always return Concrete::concreteTypeName; we use that + // pointer as a tag for this particular referent type. + virtual const jschar *typeName() const = 0; + + // Return the size of this node, in bytes. Include any structures that this + // node owns exclusively that are not exposed as their own ubi::Nodes. + virtual size_t size() const = 0; + + // Return an EdgeRange that initially contains all the referent's outgoing + // edges. The EdgeRange should be freed with 'js_delete'. (You could use + // ScopedDJSeletePtr to manage it.) On OOM, report an exception + // on |cx| and return nullptr. + virtual EdgeRange *edges(JSContext *cx) const = 0; + + private: + Base(const Base &rhs) MOZ_DELETE; + Base &operator=(const Base &rhs) MOZ_DELETE; +}; + +// A traits template with a specialization for each referent type that +// ubi::Node supports. The specialization must be the concrete subclass of +// Base that represents a pointer to the referent type. It must also +// include the members described here. +template +struct Concrete { + // The specific jschar array returned by Concrete::typeName. + static const jschar concreteTypeName[]; + + // Construct an instance of this concrete class in |storage| referring + // to |referent|. Implementations typically use a placement 'new'. + // + // In some cases, |referent| will contain dynamic type information that + // identifies it a some more specific subclass of |Referent|. For example, + // when |Referent| is |JSObject|, then |referent->getClass()| could tell us + // that it's actually a JSFunction. Similarly, if |Referent| is + // |nsISupports|, we would like a ubi::Node that knows its final + // implementation type. + // + // So, we delegate the actual construction to this specialization, which + // knows Referent's details. + static void construct(void *storage, Referent *referent); +}; + +// A container for a Base instance; all members simply forward to the contained instance. +// This container allows us to pass ubi::Node instances by value. +class Node { + // Storage in which we allocate Base subclasses. + mozilla::AlignedStorage2 storage; + Base *base() { return storage.addr(); } + const Base *base() const { return storage.addr(); } + + template + void construct(T *ptr) { + static_assert(sizeof(Concrete) == sizeof(*base()), + "ubi::Base specializations must be the same size as ubi::Base"); + Concrete::construct(base(), ptr); + } + + typedef void (Node::* ConvertibleToBool)(); + void nonNull() {} + + public: + Node() { construct(nullptr); } + + template + Node(T *ptr) { + construct(ptr); + } + template + Node &operator=(T *ptr) { + construct(ptr); + return *this; + } + + // We can construct and assign from rooted forms of pointers. + template + Node(const Rooted &root) { + construct(root.get()); + } + template + Node &operator=(const Rooted &root) { + construct(root.get()); + return *this; + } + + // Constructors accepting SpiderMonkey's other generic-pointer-ish types. + Node(JS::Value value); + Node(JSGCTraceKind kind, void *ptr); + + // copy construction and copy assignment just use memcpy, since we know + // instances contain nothing but a vtable pointer and a data pointer. + // + // To be completely correct, concrete classes could provide a virtual + // 'construct' member function, which we could invoke on rhs to construct an + // instance in our storage. But this is good enough; there's no need to jump + // through vtables for copying and assignment that are just going to move + // two words around. The compiler knows how to optimize memcpy. + Node(const Node &rhs) { + memcpy(storage.u.mBytes, rhs.storage.u.mBytes, sizeof(storage.u)); + } + + Node &operator=(const Node &rhs) { + memcpy(storage.u.mBytes, rhs.storage.u.mBytes, sizeof(storage.u)); + return *this; + } + + bool operator==(const Node &rhs) const { return *base() == *rhs.base(); } + bool operator!=(const Node &rhs) const { return *base() != *rhs.base(); } + + operator ConvertibleToBool() const { + return base()->ptr ? &Node::nonNull : 0; + } + + template + bool is() const { + return base()->typeName() == Concrete::concreteTypeName; + } + + template + T *as() const { + MOZ_ASSERT(is()); + return static_cast(base()->ptr); + } + + template + T *asOrNull() const { + return is() ? static_cast(base()->ptr) : nullptr; + } + + // If this node refers to something that can be represented as a + // JavaScript value that is safe to expose to JavaScript code, return that + // value. Otherwise return UndefinedValue(). JSStrings and some (but not + // all!) JSObjects can be exposed. + JS::Value exposeToJS() const; + + const jschar *typeName() const { return base()->typeName(); } + size_t size() const { return base()->size(); } + EdgeRange *edges(JSContext *cx) const { return base()->edges(cx); } + + // A hash policy for ubi::Nodes. + // This simply uses the stock PointerHasher on the ubi::Node's pointer. + // We specialize DefaultHasher below to make this the default. + class HashPolicy { + typedef js::PointerHasher::value> PtrHash; + + public: + typedef Node Lookup; + + static js::HashNumber hash(const Lookup &l) { return PtrHash::hash(l.base()->ptr); } + static bool match(const Node &k, const Lookup &l) { return k == l; } + static void rekey(Node &k, const Node &newKey) { k = newKey; } + }; +}; + + +// Edge is the abstract base class representing an outgoing edge of a node. +// Edges are owned by EdgeRanges, and need not have assignment operators or copy +// constructors. +// +// Each Edge class should inherit from this base class, overriding as +// appropriate. +class Edge { + protected: + Edge() : name(nullptr), referent() { } + virtual ~Edge() { } + + public: + // This edge's name. + // + // The storage is owned by this Edge, and will be freed when this Edge is + // destructed. + // + // (In real life we'll want a better representation for names, to avoid + // creating tons of strings when the names follow a pattern; and we'll need + // to think about lifetimes carefully to ensure traversal stays cheap.) + const jschar *name; + + // This edge's referent. + Node referent; + + private: + Edge(const Edge &) MOZ_DELETE; + Edge &operator=(const Edge &) MOZ_DELETE; +}; + + +// EdgeRange is an abstract base class for iterating over a node's outgoing +// edges. (This is modeled after js::HashTable::Range.) +// +// Concrete instances of this class need not be as lightweight as Node itself, +// since they're usually only instantiated while iterating over a particular +// object's edges. For example, a dumb implementation for JS Cells might use +// JS_TraceChildren to to get the outgoing edges, and then store them in an +// array internal to the EdgeRange. +class EdgeRange { + protected: + // The current front edge of this range, or nullptr if this range is empty. + Edge *front_; + + EdgeRange() : front_(nullptr) { } + + public: + virtual ~EdgeRange() { }; + + // True if there are no more edges in this range. + bool empty() const { return !front_; } + + // The front edge of this range. This is owned by the EdgeRange, and is + // only guaranteed to live until the next call to popFront, or until + // the EdgeRange is destructed. + const Edge &front() { return *front_; } + + // Remove the front edge from this range. This should only be called if + // !empty(). + virtual void popFront() = 0; + + private: + EdgeRange(const EdgeRange &) MOZ_DELETE; + EdgeRange &operator=(const EdgeRange &) MOZ_DELETE; +}; + + +// Concrete classes for ubi::Node referent types. + +// A reusable ubi::Concrete specialization base class for types supported by +// JS_TraceChildren. +template +class TracerConcrete : public Base { + const jschar *typeName() const MOZ_OVERRIDE { return concreteTypeName; } + size_t size() const MOZ_OVERRIDE { return 0; } // not implemented yet; bug 1011300 + EdgeRange *edges(JSContext *) const MOZ_OVERRIDE; + + TracerConcrete(Referent *ptr) : Base(ptr) { } + + public: + static const jschar concreteTypeName[]; + static void construct(void *storage, Referent *ptr) { new (storage) TracerConcrete(ptr); }; +}; + +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; + +// The ubi::Node null pointer. Any attempt to operate on a null ubi::Node asserts. +template<> +class Concrete : public Base { + const jschar *typeName() const MOZ_OVERRIDE; + size_t size() const MOZ_OVERRIDE; + EdgeRange *edges(JSContext *cx) const MOZ_OVERRIDE; + + Concrete(void *ptr) : Base(ptr) { } + + public: + static void construct(void *storage, void *ptr) { new (storage) Concrete(ptr); } + static const jschar concreteTypeName[]; +}; + + +} // namespace ubi +} // namespace JS + +namespace js { + +// Make ubi::Node::HashPolicy the default hash policy for ubi::Node. +template<> struct DefaultHasher : JS::ubi::Node::HashPolicy { }; + +} // namespace js + +#endif // js_UbiNode_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/UbiNodeTraverse.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/UbiNodeTraverse.h new file mode 100644 index 0000000000..6072cbc489 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/UbiNodeTraverse.h @@ -0,0 +1,208 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_UbiNodeTraverse_h +#define js_UbiNodeTraverse_h + +#include "js/UbiNode.h" +#include "js/Utility.h" +#include "js/Vector.h" + +namespace JS { +namespace ubi { + +// A breadth-first traversal template for graphs of ubi::Nodes. +// +// No GC may occur while an instance of this template is live. +// +// The provided Handler type should have two members: +// +// typename NodeData; +// +// The value type of |BreadthFirst::visited|, the HashMap of +// ubi::Nodes that have been visited so far. Since the algorithm needs a +// hash table like this for its own use anyway, it is simple to let +// Handler store its own metadata about each node in the same table. +// +// For example, if you want to find a shortest path to each node from any +// traversal starting point, your |NodeData| type could record the first +// edge to reach each node, and the node from which it originates. Then, +// when the traversal is complete, you can walk backwards from any node +// to some starting point, and the path recorded will be a shortest path. +// +// This type must have a default constructor. If this type owns any other +// resources, move constructors and assignment operators are probably a +// good idea, too. +// +// bool operator() (BreadthFirst &traversal, +// Node origin, const Edge &edge, +// Handler::NodeData *referentData, bool first); +// +// The visitor function, called to report that we have traversed +// |edge| from |origin|. This is called once for each edge we traverse. +// As this is a breadth-first search, any prior calls to the visitor function +// were for origin nodes not further from the start nodes than |origin|. +// +// |traversal| is this traversal object, passed along for convenience. +// +// |referentData| is a pointer to the value of the entry in +// |traversal.visited| for |edge.referent|; the visitor function can +// store whatever metadata it likes about |edge.referent| there. +// +// |first| is true if this is the first time we have visited an edge +// leading to |edge.referent|. This could be stored in NodeData, but +// the algorithm knows whether it has just created the entry in +// |traversal.visited|, so it passes it along for convenience. +// +// The visitor function may call |traversal.stop()| if it doesn't want +// to visit any more nodes. +// +// The visitor function may consult |traversal.visited| for information +// about other nodes, but it should not add or remove entries. +// +// The visitor function should return true on success, or false if an +// error occurs. A false return value terminates the traversal +// immediately, and causes BreadthFirst::traverse to return +// false. +template +struct BreadthFirst { + + // Construct a breadth-first traversal object that reports the nodes it + // reaches to |handler|. The traversal object reports OOM on |cx|, and + // asserts that no GC happens in |cx|'s runtime during its lifetime. + // + // We do nothing with noGC, other than require it to exist, with a lifetime + // that encloses our own. + BreadthFirst(JSContext *cx, Handler &handler, const JS::AutoCheckCannotGC &noGC) + : cx(cx), visited(cx), handler(handler), pending(cx), + traversalBegun(false), stopRequested(false) + { } + + // Initialize this traversal object. Return false on OOM. + bool init() { return visited.init(); } + + // Add |node| as a starting point for the traversal. You may add + // as many starting points as you like. Return false on OOM. + bool addStart(Node node) { return pending.append(node); } + + // Traverse the graph in breadth-first order, starting at the given + // start nodes, applying |handler::operator()| for each edge traversed + // as described above. + // + // This should be called only once per instance of this class. + // + // Return false on OOM or error return from |handler::operator()|. + bool traverse() + { + MOZ_ASSERT(!traversalBegun); + traversalBegun = true; + + // While there are pending nodes, visit them, until we've found a path to the target. + while (!pending.empty()) { + Node origin = pending.front(); + pending.popFront(); + + // Get a range containing all origin's outgoing edges. + js::ScopedJSDeletePtr range(origin.edges(cx)); + if (!range) + return false; + + // Traverse each edge. + for (; !range->empty(); range->popFront()) { + MOZ_ASSERT(!stopRequested); + + const Edge &edge = range->front(); + typename NodeMap::AddPtr a = visited.lookupForAdd(edge.referent); + bool first = !a; + + if (first) { + // This is the first time we've reached |edge.referent|. + // Create an entry for it in |visited|, and arrange to + // traverse its outgoing edges later. + if (!visited.add(a, edge.referent, typename Handler::NodeData()) || + !pending.append(edge.referent)) { + return false; + } + } + + MOZ_ASSERT(a); + + // Report this edge to the visitor function. + if (!handler(*this, origin, edge, &a->value(), first)) + return false; + + if (stopRequested) + return true; + } + } + + return true; + } + + // Stop traversal, and return true from |traverse| without visiting any + // more nodes. Only |handler::operator()| should call this function; it + // may do so to stop the traversal early, without returning false and + // then making |traverse|'s caller disambiguate that result from a real + // error. + void stop() { stopRequested = true; } + + // The context with which we were constructed. + JSContext *cx; + + // A map associating each node N that we have reached with a + // Handler::NodeData, for |handler|'s use. This is public, so that + // |handler| can access it to see the traversal thus far. + typedef js::HashMap NodeMap; + NodeMap visited; + + private: + // Our handler object. + Handler &handler; + + // A queue template. Appending and popping the front are constant time. + // Wasted space is never more than some recent actual population plus the + // current population. + template + class Queue { + js::Vector head, tail; + size_t frontIndex; + public: + Queue(JSContext *cx) : head(cx), tail(cx), frontIndex(0) { } + bool empty() { return frontIndex >= head.length(); } + T &front() { + MOZ_ASSERT(!empty()); + return head[frontIndex]; + } + void popFront() { + MOZ_ASSERT(!empty()); + frontIndex++; + if (frontIndex >= head.length()) { + head.clearAndFree(); + head.swap(tail); + frontIndex = 0; + } + } + bool append(const T &elt) { + return frontIndex == 0 ? head.append(elt) : tail.append(elt); + } + }; + + // A queue of nodes that we have reached, but whose outgoing edges we + // have not yet traversed. Nodes reachable in fewer edges are enqueued + // earlier. + Queue pending; + + // True if our traverse function has been called. + bool traversalBegun; + + // True if we've been asked to stop the traversal. + bool stopRequested; +}; + +} // namespace ubi +} // namespace JS + +#endif // js_UbiNodeTraverse.h diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/Utility.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/Utility.h index adee3b15d8..89c495e411 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/Utility.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/Utility.h @@ -35,23 +35,22 @@ namespace mozilla {} namespace js {} /* - * Pattern used to overwrite freed memory. If you are accessing an object with - * this pattern, you probably have a dangling pointer. + * Patterns used by SpiderMonkey to overwrite unused memory. If you are + * accessing an object with one of these pattern, you probably have a dangling + * pointer. */ -#define JS_FREE_PATTERN 0xDA +#define JS_FRESH_NURSERY_PATTERN 0x2F +#define JS_SWEPT_NURSERY_PATTERN 0x2B +#define JS_ALLOCATED_NURSERY_PATTERN 0x2D +#define JS_FRESH_TENURED_PATTERN 0x4F +#define JS_SWEPT_TENURED_PATTERN 0x4B +#define JS_ALLOCATED_TENURED_PATTERN 0x4D +#define JS_SWEPT_CODE_PATTERN 0x3b +#define JS_SWEPT_FRAME_PATTERN 0x5b +#define JS_POISONED_FORKJOIN_CHUNK 0xBD #define JS_ASSERT(expr) MOZ_ASSERT(expr) #define JS_ASSERT_IF(cond, expr) MOZ_ASSERT_IF(cond, expr) -#define JS_ALWAYS_TRUE(expr) MOZ_ALWAYS_TRUE(expr) -#define JS_ALWAYS_FALSE(expr) MOZ_ALWAYS_FALSE(expr) - -#if defined(DEBUG) -# define JS_DIAGNOSTICS_ASSERT(expr) MOZ_ASSERT(expr) -#elif defined(JS_CRASH_DIAGNOSTICS) -# define JS_DIAGNOSTICS_ASSERT(expr) do { if (!(expr)) MOZ_CRASH(); } while(0) -#else -# define JS_DIAGNOSTICS_ASSERT(expr) ((void) 0) -#endif #define JS_STATIC_ASSERT(cond) static_assert(cond, "JS_STATIC_ASSERT") #define JS_STATIC_ASSERT_IF(cond, expr) MOZ_STATIC_ASSERT_IF(cond, expr, "JS_STATIC_ASSERT_IF") @@ -59,84 +58,40 @@ namespace js {} extern MOZ_NORETURN JS_PUBLIC_API(void) JS_Assert(const char *s, const char *file, int ln); -/* - * Abort the process in a non-graceful manner. This will cause a core file, - * call to the debugger or other moral equivalent as well as causing the - * entire process to stop. - */ -extern JS_PUBLIC_API(void) JS_Abort(void); - /* * Custom allocator support for SpiderMonkey */ #if defined JS_USE_CUSTOM_ALLOCATOR # include "jscustomallocator.h" #else -# ifdef DEBUG +# if defined(DEBUG) || defined(JS_OOM_BREAKPOINT) /* * In order to test OOM conditions, when the testing function * oomAfterAllocations COUNT is passed, we fail continuously after the NUM'th * allocation from now. */ -extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtins/TestingFunctions.cpp */ +extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtin/TestingFunctions.cpp */ extern JS_PUBLIC_DATA(uint32_t) OOM_counter; /* data race, who cares. */ -#ifdef JS_OOM_DO_BACKTRACES -#define JS_OOM_BACKTRACE_SIZE 32 -static JS_ALWAYS_INLINE void -PrintBacktrace() -{ - void* OOM_trace[JS_OOM_BACKTRACE_SIZE]; - char** OOM_traceSymbols = nullptr; - int32_t OOM_traceSize = 0; - int32_t OOM_traceIdx = 0; - OOM_traceSize = backtrace(OOM_trace, JS_OOM_BACKTRACE_SIZE); - OOM_traceSymbols = backtrace_symbols(OOM_trace, OOM_traceSize); - - if (!OOM_traceSymbols) - return; - - for (OOM_traceIdx = 0; OOM_traceIdx < OOM_traceSize; ++OOM_traceIdx) { - fprintf(stderr, "#%d %s\n", OOM_traceIdx, OOM_traceSymbols[OOM_traceIdx]); - } - - // This must be free(), not js_free(), because backtrace_symbols() - // allocates with malloc(). - free(OOM_traceSymbols); -} - -#define JS_OOM_EMIT_BACKTRACE() \ - do {\ - fprintf(stderr, "Forcing artificial memory allocation function failure:\n");\ - PrintBacktrace();\ - } while (0) -# else -# define JS_OOM_EMIT_BACKTRACE() do {} while(0) -#endif /* JS_OOM_DO_BACKTRACES */ +#ifdef JS_OOM_BREAKPOINT +static MOZ_NEVER_INLINE void js_failedAllocBreakpoint() { asm(""); } +#define JS_OOM_CALL_BP_FUNC() js_failedAllocBreakpoint() +#else +#define JS_OOM_CALL_BP_FUNC() do {} while(0) +#endif # define JS_OOM_POSSIBLY_FAIL() \ do \ { \ if (++OOM_counter > OOM_maxAllocations) { \ - JS_OOM_EMIT_BACKTRACE();\ - return nullptr; \ - } \ - } while (0) - -# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) \ - do \ - { \ - if (++OOM_counter > OOM_maxAllocations) { \ - JS_OOM_EMIT_BACKTRACE();\ - js_ReportOutOfMemory(cx);\ + JS_OOM_CALL_BP_FUNC();\ return nullptr; \ } \ } while (0) # else # define JS_OOM_POSSIBLY_FAIL() do {} while(0) -# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) do {} while(0) -# endif /* DEBUG */ +# endif /* DEBUG || JS_OOM_BREAKPOINT */ static inline void* js_malloc(size_t bytes) { @@ -168,26 +123,6 @@ static inline void js_free(void* p) } #endif/* JS_USE_CUSTOM_ALLOCATOR */ -/* - * JS_ROTATE_LEFT32 - * - * There is no rotate operation in the C Language so the construct (a << 4) | - * (a >> 28) is used instead. Most compilers convert this to a rotate - * instruction but some versions of MSVC don't without a little help. To get - * MSVC to generate a rotate instruction, we have to use the _rotl intrinsic - * and use a pragma to make _rotl inline. - * - * MSVC in VS2005 will do an inline rotate instruction on the above construct. - */ -#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || \ - defined(_M_X64)) -#include -#pragma intrinsic(_rotl) -#define JS_ROTATE_LEFT32(a, bits) _rotl(a, bits) -#else -#define JS_ROTATE_LEFT32(a, bits) (((a) << (bits)) | ((a) >> (32 - (bits)))) -#endif - #include /* @@ -235,6 +170,9 @@ static inline void js_free(void* p) #define JS_NEW_BODY(allocator, t, parms) \ void *memory = allocator(sizeof(t)); \ return memory ? new(memory) t parms : nullptr; +#define JS_MAKE_BODY(newname, T, parms) \ + T *ptr = newname parms; \ + return mozilla::UniquePtr>(ptr); /* * Given a class which should provide 'new' methods, add @@ -389,10 +327,191 @@ static inline void js_free(void* p) mozilla::Forward(p12)))\ }\ -JS_DECLARE_NEW_METHODS(js_new, js_malloc, static JS_ALWAYS_INLINE) +/* + * Given a class which should provide 'make' methods, add + * JS_DECLARE_MAKE_METHODS (see JSContext for a usage example). This method + * is functionally the same as JS_DECLARE_NEW_METHODS: it just declares methods + * that return mozilla::UniquePtr instances that will singly-manage ownership + * of the created object. This adds makes with up to 12 parameters. Add more + * versions below if you need more than 12 parameters. + * + * Note: Do not add a ; at the end of a use of JS_DECLARE_MAKE_METHODS, + * or the build will break. + */ +#define JS_DECLARE_MAKE_METHODS(MAKENAME, NEWNAME, QUALIFIERS)\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME() MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T, ())\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1)))\ + }\ +\ + template \ + QUALIFIERS \ +mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11, P12 &&p12) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11),\ + mozilla::Forward(p12)))\ + }\ + +JS_DECLARE_NEW_METHODS(js_new, js_malloc, static MOZ_ALWAYS_INLINE) template -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void js_delete(T *p) { if (p) { @@ -402,7 +521,7 @@ js_delete(T *p) } template -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void js_delete_poison(T *p) { if (p) { @@ -413,21 +532,21 @@ js_delete_poison(T *p) } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_malloc() { return (T *)js_malloc(sizeof(T)); } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_calloc() { return (T *)js_calloc(sizeof(T)); } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_malloc(size_t numElems) { if (numElems & mozilla::tl::MulOverflowMask::value) @@ -436,7 +555,7 @@ js_pod_malloc(size_t numElems) } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_calloc(size_t numElems) { if (numElems & mozilla::tl::MulOverflowMask::value) @@ -471,6 +590,25 @@ SCOPED_TEMPLATE(ScopedReleasePtr, ScopedReleasePtrTraits) } /* namespace js */ +namespace JS { + +template +struct DeletePolicy +{ + void operator()(T* ptr) { + js_delete(ptr); + } +}; + +struct FreePolicy +{ + void operator()(void* ptr) { + js_free(ptr); + } +}; + +} // namespace JS + namespace js { /* Integral types for all hash functions. */ @@ -535,7 +673,7 @@ namespace JS { inline void PoisonPtr(void *v) { -#if defined(JSGC_ROOT_ANALYSIS) && defined(DEBUG) +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) uint8_t *ptr = (uint8_t *) v + 3; *ptr = JS_FREE_PATTERN; #endif @@ -544,7 +682,7 @@ inline void PoisonPtr(void *v) template inline bool IsPoisonedPtr(T *v) { -#if defined(JSGC_ROOT_ANALYSIS) && defined(DEBUG) +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) uint32_t mask = uintptr_t(v) & 0xff000000; return mask == uint32_t(JS_FREE_PATTERN << 24); #else diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/Value.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/Value.h index ee4f3a64d3..e7b89e684d 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/Value.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/Value.h @@ -15,9 +15,11 @@ #include /* for std::numeric_limits */ +#include "js-config.h" #include "jstypes.h" #include "js/Anchor.h" +#include "js/GCAPI.h" #include "js/RootingAPI.h" #include "js/Utility.h" @@ -46,7 +48,7 @@ namespace JS { class Value; } # define JSVAL_ALIGNMENT #endif -#if JS_BITS_PER_WORD == 64 +#if defined(JS_PUNBOX64) # define JSVAL_TAG_SHIFT 47 #endif @@ -74,8 +76,9 @@ JS_ENUM_HEADER(JSValueType, uint8_t) JSVAL_TYPE_BOOLEAN = 0x03, JSVAL_TYPE_MAGIC = 0x04, JSVAL_TYPE_STRING = 0x05, - JSVAL_TYPE_NULL = 0x06, - JSVAL_TYPE_OBJECT = 0x07, + JSVAL_TYPE_SYMBOL = 0x06, + JSVAL_TYPE_NULL = 0x07, + JSVAL_TYPE_OBJECT = 0x08, /* These never appear in a jsval; they are only provided as an out-of-band value. */ JSVAL_TYPE_UNKNOWN = 0x20, @@ -84,7 +87,7 @@ JS_ENUM_HEADER(JSValueType, uint8_t) JS_STATIC_ASSERT(sizeof(JSValueType) == 1); -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) /* Remember to propagate changes to the C defines below. */ JS_ENUM_HEADER(JSValueTag, uint32_t) @@ -93,6 +96,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JSVAL_TAG_INT32 = JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32, JSVAL_TAG_UNDEFINED = JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED, JSVAL_TAG_STRING = JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL, JSVAL_TAG_BOOLEAN = JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN, JSVAL_TAG_MAGIC = JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC, JSVAL_TAG_NULL = JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL, @@ -101,7 +105,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JS_STATIC_ASSERT(sizeof(JSValueTag) == 4); -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) /* Remember to propagate changes to the C defines below. */ JS_ENUM_HEADER(JSValueTag, uint32_t) @@ -110,6 +114,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JSVAL_TAG_INT32 = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32, JSVAL_TAG_UNDEFINED = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED, JSVAL_TAG_STRING = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL, JSVAL_TAG_BOOLEAN = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN, JSVAL_TAG_MAGIC = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC, JSVAL_TAG_NULL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL, @@ -124,6 +129,7 @@ JS_ENUM_HEADER(JSValueShiftedTag, uint64_t) JSVAL_SHIFTED_TAG_INT32 = (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_UNDEFINED = (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_STRING = (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_SYMBOL = (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_BOOLEAN = (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_MAGIC = (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_NULL = (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT), @@ -143,29 +149,32 @@ typedef uint8_t JSValueType; #define JSVAL_TYPE_BOOLEAN ((uint8_t)0x03) #define JSVAL_TYPE_MAGIC ((uint8_t)0x04) #define JSVAL_TYPE_STRING ((uint8_t)0x05) -#define JSVAL_TYPE_NULL ((uint8_t)0x06) -#define JSVAL_TYPE_OBJECT ((uint8_t)0x07) +#define JSVAL_TYPE_SYMBOL ((uint8_t)0x06) +#define JSVAL_TYPE_NULL ((uint8_t)0x07) +#define JSVAL_TYPE_OBJECT ((uint8_t)0x08) #define JSVAL_TYPE_UNKNOWN ((uint8_t)0x20) -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) typedef uint32_t JSValueTag; #define JSVAL_TAG_CLEAR ((uint32_t)(0xFFFFFF80)) #define JSVAL_TAG_INT32 ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32)) #define JSVAL_TAG_UNDEFINED ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED)) #define JSVAL_TAG_STRING ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING)) +#define JSVAL_TAG_SYMBOL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL)) #define JSVAL_TAG_BOOLEAN ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN)) #define JSVAL_TAG_MAGIC ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC)) #define JSVAL_TAG_NULL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL)) #define JSVAL_TAG_OBJECT ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT)) -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) typedef uint32_t JSValueTag; #define JSVAL_TAG_MAX_DOUBLE ((uint32_t)(0x1FFF0)) #define JSVAL_TAG_INT32 (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32) #define JSVAL_TAG_UNDEFINED (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED) #define JSVAL_TAG_STRING (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING) +#define JSVAL_TAG_SYMBOL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL) #define JSVAL_TAG_BOOLEAN (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN) #define JSVAL_TAG_MAGIC (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC) #define JSVAL_TAG_NULL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL) @@ -176,20 +185,16 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_SHIFTED_TAG_INT32 (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_UNDEFINED (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_STRING (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_SYMBOL (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_BOOLEAN (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_MAGIC (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_NULL (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_OBJECT (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT) -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ #endif /* !defined(__SUNPRO_CC) && !defined(__xlC__) */ -#define JSVAL_LOWER_INCL_TYPE_OF_OBJ_OR_NULL_SET JSVAL_TYPE_NULL -#define JSVAL_UPPER_EXCL_TYPE_OF_PRIMITIVE_SET JSVAL_TYPE_OBJECT -#define JSVAL_UPPER_INCL_TYPE_OF_NUMBER_SET JSVAL_TYPE_INT32 -#define JSVAL_LOWER_INCL_TYPE_OF_PTR_PAYLOAD_SET JSVAL_TYPE_MAGIC - -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) #define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_CLEAR | (type))) @@ -198,7 +203,7 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32 #define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) #define JSVAL_PAYLOAD_MASK 0x00007FFFFFFFFFFFLL #define JSVAL_TAG_MASK 0xFFFF800000000000LL @@ -215,7 +220,7 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET JSVAL_SHIFTED_TAG_UNDEFINED #define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET JSVAL_SHIFTED_TAG_STRING -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ typedef enum JSWhyMagic { @@ -233,16 +238,16 @@ typedef enum JSWhyMagic JS_OPTIMIZED_ARGUMENTS, /* optimized-away 'arguments' value */ JS_IS_CONSTRUCTING, /* magic value passed to natives to indicate construction */ JS_OVERWRITTEN_CALLEE, /* arguments.callee has been overwritten */ - JS_FORWARD_TO_CALL_OBJECT, /* args object element stored in call object */ JS_BLOCK_NEEDS_CLONE, /* value of static block object slot */ JS_HASH_KEY_EMPTY, /* see class js::HashableValue */ JS_ION_ERROR, /* error while running Ion code */ - JS_ION_BAILOUT, /* status code to signal EnterIon will OSR into Interpret */ + JS_ION_BAILOUT, /* missing recover instruction result */ + JS_OPTIMIZED_OUT, /* optimized out slot */ JS_GENERIC_MAGIC /* for local use */ } JSWhyMagic; #if defined(IS_LITTLE_ENDIAN) -# if JS_BITS_PER_WORD == 32 +# if defined(JS_NUNBOX32) typedef union jsval_layout { uint64_t asBits; @@ -252,7 +257,9 @@ typedef union jsval_layout uint32_t u32; uint32_t boo; // Don't use |bool| -- it must be four bytes. JSString *str; + JS::Symbol *sym; JSObject *obj; + js::gc::Cell *cell; void *ptr; JSWhyMagic why; size_t word; @@ -263,7 +270,7 @@ typedef union jsval_layout double asDouble; void *asPtr; } JSVAL_ALIGNMENT jsval_layout; -# elif JS_BITS_PER_WORD == 64 +# elif defined(JS_PUNBOX64) typedef union jsval_layout { uint64_t asBits; @@ -286,9 +293,9 @@ typedef union jsval_layout size_t asWord; uintptr_t asUIntPtr; } JSVAL_ALIGNMENT jsval_layout; -# endif /* JS_BITS_PER_WORD */ +# endif /* JS_PUNBOX64 */ #else /* defined(IS_LITTLE_ENDIAN) */ -# if JS_BITS_PER_WORD == 32 +# if defined(JS_NUNBOX32) typedef union jsval_layout { uint64_t asBits; @@ -299,7 +306,9 @@ typedef union jsval_layout uint32_t u32; uint32_t boo; // Don't use |bool| -- it must be four bytes. JSString *str; + JS::Symbol *sym; JSObject *obj; + js::gc::Cell *cell; void *ptr; JSWhyMagic why; size_t word; @@ -309,7 +318,7 @@ typedef union jsval_layout double asDouble; void *asPtr; } JSVAL_ALIGNMENT jsval_layout; -# elif JS_BITS_PER_WORD == 64 +# elif defined(JS_PUNBOX64) typedef union jsval_layout { uint64_t asBits; @@ -330,7 +339,7 @@ typedef union jsval_layout size_t asWord; uintptr_t asUIntPtr; } JSVAL_ALIGNMENT jsval_layout; -# endif /* JS_BITS_PER_WORD */ +# endif /* JS_PUNBOX64 */ #endif /* defined(IS_LITTLE_ENDIAN) */ JS_STATIC_ASSERT(sizeof(jsval_layout) == 8); @@ -378,7 +387,7 @@ JS_STATIC_ASSERT(sizeof(jsval_layout) == 8); # define JS_VALUE_CONSTEXPR_VAR const #endif -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) /* * N.B. GCC, in some but not all cases, chooses to emit signed comparison of @@ -456,7 +465,7 @@ static inline jsval_layout STRING_TO_JSVAL_IMPL(JSString *str) { jsval_layout l; - MOZ_ASSERT(str); + MOZ_ASSERT(uintptr_t(str) > 0x1000); l.s.tag = JSVAL_TAG_STRING; l.s.payload.str = str; return l; @@ -468,6 +477,28 @@ JSVAL_TO_STRING_IMPL(jsval_layout l) return l.s.payload.str; } +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + l.s.tag = JSVAL_TAG_SYMBOL; + l.s.payload.sym = sym; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.payload.sym; +} + static inline bool JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) { @@ -524,7 +555,7 @@ static inline jsval_layout OBJECT_TO_JSVAL_IMPL(JSObject *obj) { jsval_layout l; - MOZ_ASSERT(obj); + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); l.s.tag = JSVAL_TAG_OBJECT; l.s.payload.obj = obj; return l; @@ -560,22 +591,22 @@ JSVAL_IS_GCTHING_IMPL(jsval_layout l) return (uint32_t)l.s.tag >= (uint32_t)JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET; } -static inline void * +static inline js::gc::Cell * JSVAL_TO_GCTHING_IMPL(jsval_layout l) { - return l.s.payload.ptr; -} - -static inline bool -JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) -{ - return l.s.tag == JSVAL_TAG_STRING || l.s.tag == JSVAL_TAG_OBJECT; + return l.s.payload.cell; } static inline uint32_t JSVAL_TRACE_KIND_IMPL(jsval_layout l) { - return (uint32_t)(bool)JSVAL_IS_STRING_IMPL(l); + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return l.s.tag & 0x03; } static inline bool @@ -585,7 +616,7 @@ JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) } static inline bool -JSVAL_IS_SPECIFIC_BOOLEAN(jsval_layout l, bool b) +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) { return (l.s.tag == JSVAL_TAG_BOOLEAN) && (l.s.payload.boo == uint32_t(b)); } @@ -599,6 +630,15 @@ MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) return l; } +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.s.tag = JSVAL_TAG_MAGIC; + l.s.payload.u32 = payload; + return l; +} + static inline bool JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) { @@ -614,7 +654,7 @@ JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) return (JSValueType)type; } -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) static inline JS_VALUE_CONSTEXPR jsval_layout BUILD_JSVAL(JSValueTag tag, uint64_t payload) @@ -678,7 +718,7 @@ STRING_TO_JSVAL_IMPL(JSString *str) { jsval_layout l; uint64_t strBits = (uint64_t)str; - MOZ_ASSERT(str); + MOZ_ASSERT(uintptr_t(str) > 0x1000); MOZ_ASSERT((strBits >> JSVAL_TAG_SHIFT) == 0); l.asBits = strBits | JSVAL_SHIFTED_TAG_STRING; return l; @@ -690,6 +730,29 @@ JSVAL_TO_STRING_IMPL(jsval_layout l) return (JSString *)(l.asBits & JSVAL_PAYLOAD_MASK); } +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + uint64_t symBits = (uint64_t)sym; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + MOZ_ASSERT((symBits >> JSVAL_TAG_SHIFT) == 0); + l.asBits = symBits | JSVAL_SHIFTED_TAG_SYMBOL; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return (JS::Symbol *)(l.asBits & JSVAL_PAYLOAD_MASK); +} + static inline bool JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) { @@ -725,7 +788,7 @@ JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l) static inline bool JSVAL_IS_OBJECT_IMPL(jsval_layout l) { - MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_SHIFTED_TAG_OBJECT); + MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_TAG_OBJECT); return l.asBits >= JSVAL_SHIFTED_TAG_OBJECT; } @@ -749,7 +812,7 @@ OBJECT_TO_JSVAL_IMPL(JSObject *obj) { jsval_layout l; uint64_t objBits = (uint64_t)obj; - MOZ_ASSERT(obj); + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); MOZ_ASSERT((objBits >> JSVAL_TAG_SHIFT) == 0); l.asBits = objBits | JSVAL_SHIFTED_TAG_OBJECT; return l; @@ -767,24 +830,24 @@ JSVAL_IS_GCTHING_IMPL(jsval_layout l) return l.asBits >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET; } -static inline void * +static inline js::gc::Cell * JSVAL_TO_GCTHING_IMPL(jsval_layout l) { uint64_t ptrBits = l.asBits & JSVAL_PAYLOAD_MASK; MOZ_ASSERT((ptrBits & 0x7) == 0); - return (void *)ptrBits; -} - -static inline bool -JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) -{ - return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l); + return reinterpret_cast(ptrBits); } static inline uint32_t JSVAL_TRACE_KIND_IMPL(jsval_layout l) { - return (uint32_t)(bool)!(JSVAL_IS_OBJECT_IMPL(l)); + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) & 0x03; } static inline jsval_layout @@ -812,7 +875,7 @@ JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) } static inline bool -JSVAL_IS_SPECIFIC_BOOLEAN(jsval_layout l, bool b) +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) { return l.asBits == (((uint64_t)(uint32_t)b) | JSVAL_SHIFTED_TAG_BOOLEAN); } @@ -825,6 +888,14 @@ MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) return l; } +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.asBits = ((uint64_t)payload) | JSVAL_SHIFTED_TAG_MAGIC; + return l; +} + static inline bool JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) { @@ -841,7 +912,13 @@ JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) return (JSValueType)type; } -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ + +static inline bool +JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) +{ + return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l); +} static inline jsval_layout JSVAL_TO_IMPL(JS::Value v); static inline JS_VALUE_CONSTEXPR JS::Value IMPL_TO_JSVAL(jsval_layout l); @@ -859,7 +936,7 @@ static inline JS_VALUE_CONSTEXPR JS::Value UndefinedValue(); static MOZ_ALWAYS_INLINE double GenericNaN() { - return mozilla::SpecificNaN(0, 0x8000000000000ULL); + return mozilla::SpecificNaN(0, 0x8000000000000ULL); } /* MSVC with PGO miscompiles this function. */ @@ -883,27 +960,23 @@ CanonicalizeNaN(double d) * * - JS::Value has setX() and isX() members for X in * - * { Int32, Double, String, Boolean, Undefined, Null, Object, Magic } + * { Int32, Double, String, Symbol, Boolean, Undefined, Null, Object, Magic } * * JS::Value also contains toX() for each of the non-singleton types. * - * - Magic is a singleton type whose payload contains a JSWhyMagic "reason" for - * the magic value. By providing JSWhyMagic values when creating and checking - * for magic values, it is possible to assert, at runtime, that only magic - * values with the expected reason flow through a particular value. For - * example, if cx->exception has a magic value, the reason must be - * JS_GENERATOR_CLOSING. + * - Magic is a singleton type whose payload contains either a JSWhyMagic "reason" for + * the magic value or a uint32_t value. By providing JSWhyMagic values when + * creating and checking for magic values, it is possible to assert, at + * runtime, that only magic values with the expected reason flow through a + * particular value. For example, if cx->exception has a magic value, the + * reason must be JS_GENERATOR_CLOSING. * * - The JS::Value operations are preferred. The JSVAL_* operations remain for * compatibility; they may be removed at some point. These operations mostly * provide similar functionality. But there are a few key differences. One - * is that JS::Value gives null a separate type. Thus - * - * JSVAL_IS_OBJECT(v) === v.isObjectOrNull() - * !JSVAL_IS_PRIMITIVE(v) === v.isObject() - * + * is that JS::Value gives null a separate type. * Also, to help prevent mistakenly boxing a nullable JSObject* as an object, - * Value::setObject takes a JSObject&. (Conversely, Value::asObject returns a + * Value::setObject takes a JSObject&. (Conversely, Value::toObject returns a * JSObject&.) A convenience member Value::setObjectOrNull is provided. * * - JSVAL_VOID is the same as the singleton value of the Undefined type. @@ -961,6 +1034,11 @@ class Value data = STRING_TO_JSVAL_IMPL(str); } + void setSymbol(JS::Symbol *sym) { + MOZ_ASSERT(!IsPoisonedPtr(sym)); + data = SYMBOL_TO_JSVAL_IMPL(sym); + } + void setObject(JSObject &obj) { MOZ_ASSERT(!IsPoisonedPtr(&obj)); data = OBJECT_TO_JSVAL_IMPL(&obj); @@ -974,6 +1052,10 @@ class Value data = MAGIC_TO_JSVAL_IMPL(why); } + void setMagicUint32(uint32_t payload) { + data = MAGIC_UINT32_TO_JSVAL_IMPL(payload); + } + bool setNumber(uint32_t ui) { if (ui > JSVAL_INT_MAX) { setDouble((double)ui); @@ -986,7 +1068,7 @@ class Value bool setNumber(double d) { int32_t i; - if (mozilla::DoubleIsInt32(d, &i)) { + if (mozilla::NumberIsInt32(d, &i)) { setInt32(i); return true; } @@ -1042,6 +1124,10 @@ class Value return JSVAL_IS_STRING_IMPL(data); } + bool isSymbol() const { + return JSVAL_IS_SYMBOL_IMPL(data); + } + bool isObject() const { return JSVAL_IS_OBJECT_IMPL(data); } @@ -1063,11 +1149,11 @@ class Value } bool isTrue() const { - return JSVAL_IS_SPECIFIC_BOOLEAN(data, true); + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, true); } bool isFalse() const { - return JSVAL_IS_SPECIFIC_BOOLEAN(data, false); + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, false); } bool isMagic() const { @@ -1093,6 +1179,11 @@ class Value return data.s.payload.why; } + uint32_t magicUint32() const { + MOZ_ASSERT(isMagic()); + return data.s.payload.u32; + } + /*** Comparison ***/ bool operator==(const Value &rhs) const { @@ -1127,6 +1218,11 @@ class Value return JSVAL_TO_STRING_IMPL(data); } + JS::Symbol *toSymbol() const { + MOZ_ASSERT(isSymbol()); + return JSVAL_TO_SYMBOL_IMPL(data); + } + JSObject &toObject() const { MOZ_ASSERT(isObject()); return *JSVAL_TO_OBJECT_IMPL(data); @@ -1137,7 +1233,7 @@ class Value return JSVAL_TO_OBJECT_IMPL(data); } - void *toGCThing() const { + js::gc::Cell *toGCThing() const { MOZ_ASSERT(isGCThing()); return JSVAL_TO_GCTHING_IMPL(data); } @@ -1202,17 +1298,17 @@ class Value } const size_t *payloadWord() const { -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) return &data.s.payload.word; -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) return &data.asWord; #endif } const uintptr_t *payloadUIntPtr() const { -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) return &data.s.payload.uintptr; -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) return &data.asUIntPtr; #endif } @@ -1228,7 +1324,7 @@ class Value private: #if defined(JS_VALUE_IS_CONSTEXPR) - JS_VALUE_CONSTEXPR Value(jsval_layout layout) : data(layout) {} + MOZ_IMPLICIT JS_VALUE_CONSTEXPR Value(jsval_layout layout) : data(layout) {} #endif void staticAssertions() { @@ -1248,11 +1344,30 @@ IsPoisonedValue(const Value &v) { if (v.isString()) return IsPoisonedPtr(v.toString()); + if (v.isSymbol()) + return IsPoisonedPtr(v.toSymbol()); if (v.isObject()) return IsPoisonedPtr(&v.toObject()); return false; } +inline bool +IsOptimizedPlaceholderMagicValue(const Value &v) +{ + if (v.isMagic()) { + MOZ_ASSERT(v.whyMagic() == JS_OPTIMIZED_ARGUMENTS || v.whyMagic() == JS_OPTIMIZED_OUT); + return true; + } + return false; +} + +static MOZ_ALWAYS_INLINE void +ExposeValueToActiveJS(const Value &v) +{ + if (v.isMarkable()) + ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); +} + /************************************************************************/ static inline Value @@ -1315,6 +1430,14 @@ StringValue(JSString *str) return v; } +static inline Value +SymbolValue(JS::Symbol *sym) +{ + Value v; + v.setSymbol(sym); + return v; +} + static inline Value BooleanValue(bool boo) { @@ -1363,6 +1486,14 @@ MagicValue(JSWhyMagic why) return v; } +static inline Value +MagicValueUint32(uint32_t payload) +{ + Value v; + v.setMagicUint32(payload); + return v; +} + static inline Value NumberValue(float f) { @@ -1507,16 +1638,16 @@ namespace js { template <> struct GCMethods { static JS::Value initial() { return JS::UndefinedValue(); } - static ThingRootKind kind() { return THING_ROOT_VALUE; } static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } }; template <> struct GCMethods { static JS::Value initial() { return JS::UndefinedValue(); } - static ThingRootKind kind() { return THING_ROOT_VALUE; } static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } - static bool needsPostBarrier(const JS::Value &v) { return v.isMarkable(); } + static bool needsPostBarrier(const JS::Value &v) { + return v.isObject() && gc::IsInsideNursery(reinterpret_cast(&v.toObject())); + } #ifdef JSGC_GENERATIONAL static void postBarrier(JS::Value *v) { JS::HeapValuePostBarrier(v); } static void relocate(JS::Value *v) { JS::HeapValueRelocate(v); } @@ -1548,6 +1679,7 @@ class ValueOperations bool isInt32() const { return value()->isInt32(); } bool isDouble() const { return value()->isDouble(); } bool isString() const { return value()->isString(); } + bool isSymbol() const { return value()->isSymbol(); } bool isObject() const { return value()->isObject(); } bool isMagic() const { return value()->isMagic(); } bool isMagic(JSWhyMagic why) const { return value()->isMagic(why); } @@ -1563,14 +1695,17 @@ class ValueOperations int32_t toInt32() const { return value()->toInt32(); } double toDouble() const { return value()->toDouble(); } JSString *toString() const { return value()->toString(); } + JS::Symbol *toSymbol() const { return value()->toSymbol(); } JSObject &toObject() const { return value()->toObject(); } JSObject *toObjectOrNull() const { return value()->toObjectOrNull(); } void *toGCThing() const { return value()->toGCThing(); } + uint64_t asRawBits() const { return value()->asRawBits(); } JSValueType extractNonDoubleType() const { return value()->extractNonDoubleType(); } uint32_t toPrivateUint32() const { return value()->toPrivateUint32(); } JSWhyMagic whyMagic() const { return value()->whyMagic(); } + uint32_t magicUint32() const { return value()->magicUint32(); } }; /* @@ -1595,6 +1730,7 @@ class MutableValueOperations : public ValueOperations bool setNumber(uint32_t ui) { return value()->setNumber(ui); } bool setNumber(double d) { return value()->setNumber(d); } void setString(JSString *str) { this->value()->setString(str); } + void setSymbol(JS::Symbol *sym) { this->value()->setSymbol(sym); } void setObject(JSObject &obj) { this->value()->setObject(obj); } void setObjectOrNull(JSObject *arg) { this->value()->setObjectOrNull(arg); } }; @@ -1625,6 +1761,7 @@ class HeapBase : public ValueOperations > void setBoolean(bool b) { setBarriered(JS::BooleanValue(b)); } void setMagic(JSWhyMagic why) { setBarriered(JS::MagicValue(why)); } void setString(JSString *str) { setBarriered(JS::StringValue(str)); } + void setSymbol(JS::Symbol *sym) { setBarriered(JS::SymbolValue(sym)); } void setObject(JSObject &obj) { setBarriered(JS::ObjectValue(obj)); } bool setNumber(uint32_t ui) { @@ -1639,7 +1776,7 @@ class HeapBase : public ValueOperations > bool setNumber(double d) { int32_t i; - if (mozilla::DoubleIsInt32(d, &i)) { + if (mozilla::NumberIsInt32(d, &i)) { setInt32(i); return true; } @@ -1747,7 +1884,7 @@ inline Anchor::~Anchor() } #endif -#ifdef DEBUG +#ifdef JS_DEBUG namespace detail { struct ValueAlignmentTester { char c; JS::Value v; }; @@ -1759,7 +1896,7 @@ static_assert(sizeof(LayoutAlignmentTester) == 16, "jsval_layout must be 16-byte-aligned"); } // namespace detail -#endif /* DEBUG */ +#endif /* JS_DEBUG */ } // namespace JS @@ -1775,52 +1912,12 @@ static_assert(sizeof(jsval_layout) == sizeof(JS::Value), /************************************************************************/ -static inline bool -JSVAL_IS_NULL(jsval v) -{ - return JSVAL_IS_NULL_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_VOID(jsval v) -{ - return JSVAL_IS_UNDEFINED_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_INT(jsval v) -{ - return JSVAL_IS_INT32_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline int32_t -JSVAL_TO_INT(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_INT(v)); - return JSVAL_TO_INT32_IMPL(JSVAL_TO_IMPL(v)); -} - static inline JS_VALUE_CONSTEXPR jsval INT_TO_JSVAL(int32_t i) { return IMPL_TO_JSVAL(INT32_TO_JSVAL_IMPL(i)); } -static inline bool -JSVAL_IS_DOUBLE(jsval v) -{ - return JSVAL_IS_DOUBLE_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline double -JSVAL_TO_DOUBLE(jsval v) -{ - jsval_layout l; - MOZ_ASSERT(JSVAL_IS_DOUBLE(v)); - l = JSVAL_TO_IMPL(v); - return l.asDouble; -} - static inline JS_VALUE_CONSTEXPR jsval DOUBLE_TO_JSVAL(double d) { @@ -1852,38 +1949,12 @@ UINT_TO_JSVAL(uint32_t i) : DOUBLE_TO_JSVAL((double)i)); } -static inline bool -JSVAL_IS_NUMBER(jsval v) -{ - return JSVAL_IS_NUMBER_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_STRING(jsval v) -{ - return JSVAL_IS_STRING_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline JSString * -JSVAL_TO_STRING(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_STRING(v)); - return JSVAL_TO_STRING_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval STRING_TO_JSVAL(JSString *str) { return IMPL_TO_JSVAL(STRING_TO_JSVAL_IMPL(str)); } -static inline JSObject * -JSVAL_TO_OBJECT(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_OBJECT_OR_NULL_IMPL(JSVAL_TO_IMPL(v))); - return JSVAL_TO_OBJECT_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval OBJECT_TO_JSVAL(JSObject *obj) { @@ -1892,44 +1963,12 @@ OBJECT_TO_JSVAL(JSObject *obj) return IMPL_TO_JSVAL(BUILD_JSVAL(JSVAL_TAG_NULL, 0)); } -static inline bool -JSVAL_IS_BOOLEAN(jsval v) -{ - return JSVAL_IS_BOOLEAN_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_TO_BOOLEAN(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_BOOLEAN(v)); - return JSVAL_TO_BOOLEAN_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval BOOLEAN_TO_JSVAL(bool b) { return IMPL_TO_JSVAL(BOOLEAN_TO_JSVAL_IMPL(b)); } -static inline bool -JSVAL_IS_PRIMITIVE(jsval v) -{ - return JSVAL_IS_PRIMITIVE_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_GCTHING(jsval v) -{ - return JSVAL_IS_GCTHING_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline void * -JSVAL_TO_GCTHING(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_GCTHING(v)); - return JSVAL_TO_GCTHING_IMPL(JSVAL_TO_IMPL(v)); -} - /* To be GC-safe, privates are tagged as doubles. */ static inline jsval @@ -1938,13 +1977,6 @@ PRIVATE_TO_JSVAL(void *ptr) return IMPL_TO_JSVAL(PRIVATE_PTR_TO_JSVAL_IMPL(ptr)); } -static inline void * -JSVAL_TO_PRIVATE(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_DOUBLE(v)); - return JSVAL_TO_PRIVATE_PTR_IMPL(JSVAL_TO_IMPL(v)); -} - // JS constants. For efficiency, prefer predicates (e.g. v.isNull()) and // constructing values from scratch (e.g. Int32Value(0)). These constants are // stored in memory and initialized at startup, so testing against them and @@ -1958,8 +1990,10 @@ extern JS_PUBLIC_DATA(const jsval) JSVAL_VOID; namespace JS { -extern JS_PUBLIC_DATA(const Handle) NullHandleValue; -extern JS_PUBLIC_DATA(const Handle) UndefinedHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) NullHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) TrueHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) FalseHandleValue; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/Vector.h index e8aef1713d..a2d24b10ed 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/js/Vector.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/Vector.h @@ -54,7 +54,7 @@ class Vector typedef typename mozilla::VectorBase Base; public: - Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} Vector(Vector &&vec) : Base(mozilla::Move(vec)) {} Vector &operator=(Vector &&vec) { return Base::operator=(mozilla::Move(vec)); diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/js/WeakMapPtr.h b/frameworks/js-bindings/external/spidermonkey/include/linux/js/WeakMapPtr.h new file mode 100644 index 0000000000..f5822bef4b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/js/WeakMapPtr.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_WeakMapPtr_h +#define js_WeakMapPtr_h + +#include "jspubtd.h" + +#include "js/TypeDecls.h" + +namespace JS { + +// A wrapper around the internal C++ representation of SpiderMonkey WeakMaps, +// usable outside the engine. +// +// The supported template specializations are enumerated in WeakMapPtr.cpp. If +// you want to use this class for a different key/value combination, add it to +// the list and the compiler will generate the relevant machinery. +template +class JS_PUBLIC_API(WeakMapPtr) +{ + public: + WeakMapPtr() : ptr(nullptr) {}; + bool init(JSContext *cx); + bool initialized() { return ptr != nullptr; }; + void destroy(); + virtual ~WeakMapPtr() { MOZ_ASSERT(!initialized()); } + void trace(JSTracer *tracer); + + V lookup(const K &key); + bool put(JSContext *cx, const K &key, const V &value); + + static void keyMarkCallback(JSTracer *trc, K key, void *data); + + private: + void *ptr; + + // WeakMapPtr is neither copyable nor assignable. + WeakMapPtr(const WeakMapPtr &wmp) MOZ_DELETE; + WeakMapPtr &operator=(const WeakMapPtr &wmp) MOZ_DELETE; +}; + +} /* namespace JS */ + +#endif /* js_WeakMapPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/jsalloc.h b/frameworks/js-bindings/external/spidermonkey/include/linux/jsalloc.h index 03b6b569e1..a1e547cec9 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/jsalloc.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/jsalloc.h @@ -4,7 +4,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/* JS allocation policies. */ +/* + * JS allocation policies. + * + * The allocators here are for system memory with lifetimes which are not + * managed by the GC. See the comment at the top of vm/MallocProvider.h. + */ #ifndef jsalloc_h #define jsalloc_h @@ -14,7 +19,7 @@ namespace js { -class ContextFriendFields; +struct ContextFriendFields; /* Policy for using system memory functions and doing no error reporting. */ class SystemAllocPolicy @@ -47,26 +52,26 @@ class TempAllocPolicy JS_FRIEND_API(void *) onOutOfMemory(void *p, size_t nbytes); public: - TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( - TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} + MOZ_IMPLICIT TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( + MOZ_IMPLICIT TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} void *malloc_(size_t bytes) { void *p = js_malloc(bytes); - if (JS_UNLIKELY(!p)) + if (MOZ_UNLIKELY(!p)) p = onOutOfMemory(nullptr, bytes); return p; } void *calloc_(size_t bytes) { void *p = js_calloc(bytes); - if (JS_UNLIKELY(!p)) + if (MOZ_UNLIKELY(!p)) p = onOutOfMemory(nullptr, bytes); return p; } void *realloc_(void *p, size_t oldBytes, size_t bytes) { void *p2 = js_realloc(p, bytes); - if (JS_UNLIKELY(!p2)) + if (MOZ_UNLIKELY(!p2)) p2 = onOutOfMemory(p2, bytes); return p2; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/jsapi.h b/frameworks/js-bindings/external/spidermonkey/include/linux/jsapi.h index 6d47488a33..4b5a4ce1ff 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/jsapi.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/jsapi.h @@ -9,10 +9,11 @@ #ifndef jsapi_h #define jsapi_h -#include "mozilla/Atomics.h" #include "mozilla/FloatingPoint.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/Range.h" #include "mozilla/RangedPtr.h" +#include "mozilla/TypedEnum.h" #include #include @@ -26,40 +27,28 @@ #include "js/Class.h" #include "js/HashTable.h" #include "js/Id.h" +#include "js/Principals.h" #include "js/RootingAPI.h" +#include "js/TracingAPI.h" #include "js/Utility.h" #include "js/Value.h" #include "js/Vector.h" /************************************************************************/ -struct JSTracer; - namespace JS { class Latin1CharsZ; class TwoByteChars; -typedef mozilla::RangedPtr CharPtr; - -class StableCharPtr : public CharPtr { - public: - StableCharPtr(const StableCharPtr &s) : CharPtr(s) {} - StableCharPtr(const mozilla::RangedPtr &s) : CharPtr(s) {} - StableCharPtr(const jschar *s, size_t len) : CharPtr(s, len) {} - StableCharPtr(const jschar *pos, const jschar *start, size_t len) - : CharPtr(pos, start, len) - {} -}; - -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG class JS_PUBLIC_API(AutoCheckRequestDepth) { JSContext *cx; public: - AutoCheckRequestDepth(JSContext *cx); - AutoCheckRequestDepth(js::ContextFriendFields *cx); + explicit AutoCheckRequestDepth(JSContext *cx); + explicit AutoCheckRequestDepth(js::ContextFriendFields *cx); ~AutoCheckRequestDepth(); }; @@ -71,155 +60,53 @@ class JS_PUBLIC_API(AutoCheckRequestDepth) # define CHECK_REQUEST(cx) \ ((void) 0) -#endif /* JS_THREADSAFE && DEBUG */ +#endif /* JS_THREADSAFE && JS_DEBUG */ -#ifdef DEBUG +#ifdef JS_DEBUG /* * Assert that we're not doing GC on cx, that we're in a request as * needed, and that the compartments for cx and v are correct. * Also check that GC would be safe at this point. */ JS_PUBLIC_API(void) -AssertArgumentsAreSane(JSContext *cx, JS::Handle v); +AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v); #else -inline void AssertArgumentsAreSane(JSContext *cx, JS::Handle v) { +inline void AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v) { /* Do nothing */ } -#endif /* DEBUG */ - -class JS_PUBLIC_API(AutoGCRooter) { - public: - AutoGCRooter(JSContext *cx, ptrdiff_t tag); - AutoGCRooter(js::ContextFriendFields *cx, ptrdiff_t tag); - - ~AutoGCRooter() { - JS_ASSERT(this == *stackTop); - *stackTop = down; - } - - /* Implemented in gc/RootMarking.cpp. */ - inline void trace(JSTracer *trc); - static void traceAll(JSTracer *trc); - static void traceAllWrappers(JSTracer *trc); - - protected: - AutoGCRooter * const down; - - /* - * Discriminates actual subclass of this being used. If non-negative, the - * subclass roots an array of values of the length stored in this field. - * If negative, meaning is indicated by the corresponding value in the enum - * below. Any other negative value indicates some deeper problem such as - * memory corruption. - */ - ptrdiff_t tag_; - - enum { - VALARRAY = -2, /* js::AutoValueArray */ - PARSER = -3, /* js::frontend::Parser */ - SHAPEVECTOR = -4, /* js::AutoShapeVector */ - IDARRAY = -6, /* js::AutoIdArray */ - DESCRIPTORS = -7, /* js::AutoPropDescArrayRooter */ - ID = -9, /* js::AutoIdRooter */ - VALVECTOR = -10, /* js::AutoValueVector */ - STRING = -12, /* js::AutoStringRooter */ - IDVECTOR = -13, /* js::AutoIdVector */ - OBJVECTOR = -14, /* js::AutoObjectVector */ - STRINGVECTOR =-15, /* js::AutoStringVector */ - SCRIPTVECTOR =-16, /* js::AutoScriptVector */ - NAMEVECTOR = -17, /* js::AutoNameVector */ - HASHABLEVALUE=-18, /* js::HashableValue */ - IONMASM = -19, /* js::jit::MacroAssembler */ - IONALLOC = -20, /* js::jit::AutoTempAllocatorRooter */ - WRAPVECTOR = -21, /* js::AutoWrapperVector */ - WRAPPER = -22, /* js::AutoWrapperRooter */ - OBJOBJHASHMAP=-23, /* js::AutoObjectObjectHashMap */ - OBJU32HASHMAP=-24, /* js::AutoObjectUnsigned32HashMap */ - OBJHASHSET = -25, /* js::AutoObjectHashSet */ - JSONPARSER = -26, /* js::JSONParser */ - CUSTOM = -27, /* js::CustomAutoRooter */ - FUNVECTOR = -28 /* js::AutoFunctionVector */ - }; - - private: - AutoGCRooter ** const stackTop; - - /* No copy or assignment semantics. */ - AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; - void operator=(AutoGCRooter &ida) MOZ_DELETE; -}; - -class AutoStringRooter : private AutoGCRooter { - public: - AutoStringRooter(JSContext *cx, JSString *str = nullptr - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, STRING), str_(str) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - void setString(JSString *str) { - str_ = str; - } - - JSString * string() const { - return str_; - } - - JSString ** addr() { - return &str_; - } - - JSString * const * addr() const { - return &str_; - } - - friend void AutoGCRooter::trace(JSTracer *trc); +#endif /* JS_DEBUG */ - private: - JSString *str_; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER -}; +/* AutoValueArray roots an internal fixed-size array of Values. */ +template +class AutoValueArray : public AutoGCRooter +{ + const size_t length_; + Value elements_[N]; -class AutoArrayRooter : private AutoGCRooter { public: - AutoArrayRooter(JSContext *cx, size_t len, Value *vec - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, len), array(vec), skip(cx, array, len) + explicit AutoValueArray(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, VALARRAY), length_(N) { + /* Always initialize in case we GC before assignment. */ + mozilla::PodArrayZero(elements_); MOZ_GUARD_OBJECT_NOTIFIER_INIT; - JS_ASSERT(tag_ >= 0); - } - - void changeLength(size_t newLength) { - tag_ = ptrdiff_t(newLength); - JS_ASSERT(tag_ >= 0); - } - - void changeArray(Value *newArray, size_t newLength) { - changeLength(newLength); - array = newArray; } - Value *array; + unsigned length() const { return length_; } + const Value *begin() const { return elements_; } + Value *begin() { return elements_; } - MutableHandle handleAt(size_t i) - { - JS_ASSERT(i < size_t(tag_)); - return MutableHandle::fromMarkedLocation(&array[i]); + HandleValue operator[](unsigned i) const { + JS_ASSERT(i < N); + return HandleValue::fromMarkedLocation(&elements_[i]); } - Handle handleAt(size_t i) const - { - JS_ASSERT(i < size_t(tag_)); - return Handle::fromMarkedLocation(&array[i]); + MutableHandleValue operator[](unsigned i) { + JS_ASSERT(i < N); + return MutableHandleValue::fromMarkedLocation(&elements_[i]); } - friend void AutoGCRooter::trace(JSTracer *trc); - - private: MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER - - js::SkipRoot skip; }; template @@ -228,20 +115,17 @@ class AutoVectorRooter : protected AutoGCRooter typedef js::Vector VectorImpl; VectorImpl vector; - /* Prevent overwriting of inline elements in vector. */ - js::SkipRoot vectorRoot; - public: explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, tag), vector(cx), vectorRoot(cx, &vector) + : AutoGCRooter(cx, tag), vector(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; } explicit AutoVectorRooter(js::ContextFriendFields *cx, ptrdiff_t tag MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, tag), vector(cx), vectorRoot(cx, &vector) + : AutoGCRooter(cx, tag), vector(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; } @@ -253,6 +137,7 @@ class AutoVectorRooter : protected AutoGCRooter bool empty() const { return vector.empty(); } bool append(const T &v) { return vector.append(v); } + bool append(const T *ptr, size_t len) { return vector.append(ptr, len); } bool appendAll(const AutoVectorRooter &other) { return vector.appendAll(other.vector); } @@ -291,13 +176,10 @@ class AutoVectorRooter : protected AutoGCRooter return vector.reserve(newLength); } - T &operator[](size_t i) { return vector[i]; } - const T &operator[](size_t i) const { return vector[i]; } - - JS::MutableHandle handleAt(size_t i) { + JS::MutableHandle operator[](size_t i) { return JS::MutableHandle::fromMarkedLocation(&vector[i]); } - JS::Handle handleAt(size_t i) const { + JS::Handle operator[](size_t i) const { return JS::Handle::fromMarkedLocation(&vector[i]); } @@ -408,7 +290,7 @@ class AutoHashMapRooter : protected AutoGCRooter return map.sizeOfIncludingThis(mallocSizeOf); } - unsigned generation() const { + uint32_t generation() const { return map.generation(); } @@ -523,7 +405,7 @@ class AutoHashSetRooter : protected AutoGCRooter return set.sizeOfIncludingThis(mallocSizeOf); } - unsigned generation() const { + uint32_t generation() const { return set.generation(); } @@ -629,7 +511,7 @@ class AutoScriptVector : public AutoVectorRooter }; /* - * Cutsom rooting behavior for internal and external clients. + * Custom rooting behavior for internal and external clients. */ class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter { @@ -651,6 +533,86 @@ class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER }; +/* + * RootedGeneric allows a class to instantiate its own Rooted type by + * including the method: + * + * void trace(JSTracer *trc); + * + * The trace() method must trace all of the class's fields. + */ +template +class RootedGeneric : private CustomAutoRooter +{ + public: + template + explicit RootedGeneric(CX *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + template + explicit RootedGeneric(CX *cx, const T& initial MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx), value(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + operator const T&() const { return value; } + T operator->() const { return value; } + + private: + virtual void trace(JSTracer *trc) { value->trace(trc); } + + T value; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* A handle to an array of rooted values. */ +class HandleValueArray +{ + const size_t length_; + const Value * const elements_; + + HandleValueArray(size_t len, const Value *elements) : length_(len), elements_(elements) {} + + public: + explicit HandleValueArray(const RootedValue& value) : length_(1), elements_(value.address()) {} + + MOZ_IMPLICIT HandleValueArray(const AutoValueVector& values) + : length_(values.length()), elements_(values.begin()) {} + + template + HandleValueArray(const AutoValueArray& values) : length_(N), elements_(values.begin()) {} + + /* CallArgs must already be rooted somewhere up the stack. */ + MOZ_IMPLICIT HandleValueArray(const JS::CallArgs& args) : length_(args.length()), elements_(args.array()) {} + + /* Use with care! Only call this if the data is guaranteed to be marked. */ + static HandleValueArray fromMarkedLocation(size_t len, const Value *elements) { + return HandleValueArray(len, elements); + } + + static HandleValueArray subarray(const HandleValueArray& values, size_t startIndex, size_t len) { + JS_ASSERT(startIndex + len <= values.length()); + return HandleValueArray(len, values.begin() + startIndex); + } + + static HandleValueArray empty() { + return HandleValueArray(0, nullptr); + } + + size_t length() const { return length_; } + const Value *begin() const { return elements_; } + + HandleValue operator[](size_t i) const { + JS_ASSERT(i < length_); + return HandleValue::fromMarkedLocation(&elements_[i]); + } +}; + } /* namespace JS */ /************************************************************************/ @@ -660,7 +622,7 @@ struct JSFreeOp { JSRuntime *runtime_; protected: - JSFreeOp(JSRuntime *rt) + explicit JSFreeOp(JSRuntime *rt) : runtime_(rt) { } public: @@ -725,10 +687,10 @@ typedef enum JSFinalizeStatus { } JSFinalizeStatus; typedef void -(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment); +(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment, void *data); typedef bool -(* JSOperationCallback)(JSContext *cx); +(* JSInterruptCallback)(JSContext *cx); typedef void (* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report); @@ -771,37 +733,20 @@ typedef struct JSErrorFormatString { } JSErrorFormatString; typedef const JSErrorFormatString * -(* JSErrorCallback)(void *userRef, const char *locale, - const unsigned errorNumber); +(* JSErrorCallback)(void *userRef, const unsigned errorNumber); typedef bool -(* JSLocaleToUpperCase)(JSContext *cx, JS::Handle src, - JS::MutableHandle rval); +(* JSLocaleToUpperCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); typedef bool -(* JSLocaleToLowerCase)(JSContext *cx, JS::Handle src, - JS::MutableHandle rval); +(* JSLocaleToLowerCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); typedef bool -(* JSLocaleCompare)(JSContext *cx, JS::Handle src1, JS::Handle src2, - JS::MutableHandle rval); - -typedef bool -(* JSLocaleToUnicode)(JSContext *cx, const char *src, JS::MutableHandle rval); - -/* - * Security protocol types. - */ - -typedef void -(* JSDestroyPrincipalsOp)(JSPrincipals *principals); +(* JSLocaleCompare)(JSContext *cx, JS::HandleString src1, JS::HandleString src2, + JS::MutableHandleValue rval); -/* - * Used to check if a CSP instance wants to disable eval() and friends. - * See js_CheckCSPPermitsJSAction() in jsobj. - */ typedef bool -(* JSCSPEvalChecker)(JSContext *cx); +(* JSLocaleToUnicode)(JSContext *cx, const char *src, JS::MutableHandleValue rval); /* * Callback used to ask the embedding for the cross compartment wrapper handler @@ -813,9 +758,8 @@ typedef bool * guaranteed not to wrap a function. */ typedef JSObject * -(* JSWrapObjectCallback)(JSContext *cx, JS::Handle existing, JS::Handle obj, - JS::Handle proto, JS::Handle parent, - unsigned flags); +(* JSWrapObjectCallback)(JSContext *cx, JS::HandleObject existing, JS::HandleObject obj, + JS::HandleObject parent, unsigned flags); /* * Callback used by the wrap hook to ask the embedding to prepare an object @@ -823,26 +767,12 @@ typedef JSObject * * or even finding a more suitable object for the new compartment. */ typedef JSObject * -(* JSPreWrapCallback)(JSContext *cx, JS::Handle scope, JS::Handle obj, +(* JSPreWrapCallback)(JSContext *cx, JS::HandleObject scope, JS::HandleObject obj, unsigned flags); -/* - * Callback used when wrapping determines that the underlying object is already - * in the compartment for which it is being wrapped. This allows consumers to - * maintain same-compartment wrapping invariants. - * - * |obj| is guaranteed to be same-compartment as |cx|, but it may (or may not) - * be a security or cross-compartment wrapper. This is an unfortunate contract, - * but is important for to avoid unnecessarily recomputing every cross- - * compartment wrapper that gets passed to wrap. - */ -typedef JSObject * -(* JSSameCompartmentWrapObjectCallback)(JSContext *cx, JS::Handle obj); - struct JSWrapObjectCallbacks { JSWrapObjectCallback wrap; - JSSameCompartmentWrapObjectCallback sameCompartmentWrap; JSPreWrapCallback preWrap; }; @@ -858,12 +788,12 @@ typedef void /************************************************************************/ -static JS_ALWAYS_INLINE jsval +static MOZ_ALWAYS_INLINE jsval JS_NumberValue(double d) { int32_t i; d = JS::CanonicalizeNaN(d); - if (mozilla::DoubleIsInt32(d, &i)) + if (mozilla::NumberIsInt32(d, &i)) return INT_TO_JSVAL(i); return DOUBLE_TO_JSVAL(d); } @@ -883,41 +813,91 @@ JS_StringHasBeenInterned(JSContext *cx, JSString *str); JS_PUBLIC_API(jsid) INTERNED_STRING_TO_JSID(JSContext *cx, JSString *str); -/* - * Returns true iff the given jsval is immune to GC and can be used across - * multiple JSRuntimes without requiring any conversion API. - */ -static JS_ALWAYS_INLINE bool -JSVAL_IS_UNIVERSAL(jsval v) -{ - return !JSVAL_IS_GCTHING(v); -} - namespace JS { -class AutoIdRooter : private AutoGCRooter +// Container class for passing in script source buffers to the JS engine. This +// not only groups the buffer and length values, it also provides a way to +// optionally pass ownership of the buffer to the JS engine without copying. +// Rules for use: +// +// 1) The data array must be allocated with js_malloc() or js_realloc() if +// ownership is being granted to the SourceBufferHolder. +// 2) If ownership is not given to the SourceBufferHolder, then the memory +// must be kept alive until the JS compilation is complete. +// 3) Any code calling SourceBufferHolder::take() must guarantee to keep the +// memory alive until JS compilation completes. Normally only the JS +// engine should be calling take(). +// +// Example use: +// +// size_t length = 512; +// jschar* chars = static_cast(js_malloc(sizeof(jschar) * length)); +// JS::SourceBufferHolder srcBuf(chars, length, JS::SourceBufferHolder::GiveOwnership); +// JS::Compile(cx, obj, options, srcBuf); +// +class MOZ_STACK_CLASS SourceBufferHolder MOZ_FINAL { public: - explicit AutoIdRooter(JSContext *cx, jsid aId = INT_TO_JSID(0) - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, ID), id_(aId) + enum Ownership { + NoOwnership, + GiveOwnership + }; + + SourceBufferHolder(const jschar *data, size_t dataLength, Ownership ownership) + : data_(data), + length_(dataLength), + ownsChars_(ownership == GiveOwnership) { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; + // Ensure that null buffers properly return an unowned, empty, + // null-terminated string. + static const jschar NullChar_ = 0; + if (!get()) { + data_ = &NullChar_; + length_ = 0; + ownsChars_ = false; + } } - jsid id() { - return id_; + ~SourceBufferHolder() { + if (ownsChars_) + js_free(const_cast(data_)); } - jsid * addr() { - return &id_; - } + // Access the underlying source buffer without affecting ownership. + const jschar *get() const { return data_; } - friend void AutoGCRooter::trace(JSTracer *trc); + // Length of the source buffer in jschars (not bytes) + size_t length() const { return length_; } + + // Returns true if the SourceBufferHolder owns the buffer and will free + // it upon destruction. If true, it is legal to call take(). + bool ownsChars() const { return ownsChars_; } + + // Retrieve and take ownership of the underlying data buffer. The caller + // is now responsible for calling js_free() on the returned value, *but only + // after JS script compilation has completed*. + // + // After the buffer has been taken the SourceBufferHolder functions as if + // it had been constructed on an unowned buffer; get() and length() still + // work. In order for this to be safe the taken buffer must be kept alive + // until after JS script compilation completes as noted above. + // + // Note, it's the caller's responsibility to check ownsChars() before taking + // the buffer. Taking and then free'ing an unowned buffer will have dire + // consequences. + jschar *take() { + JS_ASSERT(ownsChars_); + ownsChars_ = false; + return const_cast(data_); + } private: - jsid id_; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + SourceBufferHolder(SourceBufferHolder &) MOZ_DELETE; + SourceBufferHolder &operator=(SourceBufferHolder &) MOZ_DELETE; + + const jschar *data_; + size_t length_; + bool ownsChars_; }; } /* namespace JS */ @@ -941,8 +921,6 @@ class AutoIdRooter : private AutoGCRooter object that delegates to a prototype containing this property */ #define JSPROP_INDEX 0x80 /* name is actually (int) index */ -#define JSPROP_SHORTID 0x100 /* set in JS_DefineProperty attrs - if getters/setters use a shortid */ #define JSFUN_STUB_GSOPS 0x200 /* use JS_PropertyStub getter/setter instead of defaulting to class gsops @@ -1029,13 +1007,12 @@ JS_GetEmptyString(JSRuntime *rt); * unconverted arguments. */ extern JS_PUBLIC_API(bool) -JS_ConvertArguments(JSContext *cx, unsigned argc, jsval *argv, const char *format, - ...); +JS_ConvertArguments(JSContext *cx, const JS::CallArgs &args, const char *format, ...); #ifdef va_start extern JS_PUBLIC_API(bool) -JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv, - const char *format, va_list ap); +JS_ConvertArgumentsVA(JSContext *cx, const JS::CallArgs &args, const char *format, + va_list ap); #endif extern JS_PUBLIC_API(bool) @@ -1051,7 +1028,7 @@ extern JS_PUBLIC_API(JSFunction *) JS_ValueToConstructor(JSContext *cx, JS::HandleValue v); extern JS_PUBLIC_API(JSString *) -JS_ValueToSource(JSContext *cx, jsval v); +JS_ValueToSource(JSContext *cx, JS::Handle v); namespace js { /* @@ -1076,14 +1053,10 @@ ToStringSlow(JSContext *cx, JS::HandleValue v); namespace JS { /* ES5 9.3 ToNumber. */ -JS_ALWAYS_INLINE bool -ToNumber(JSContext *cx, Handle v, double *out) +MOZ_ALWAYS_INLINE bool +ToNumber(JSContext *cx, HandleValue v, double *out) { AssertArgumentsAreSane(cx, v); - { - js::SkipRoot root(cx, &v); - js::MaybeCheckStackRoots(cx); - } if (v.isNumber()) { *out = v.toNumber(); @@ -1092,7 +1065,7 @@ ToNumber(JSContext *cx, Handle v, double *out) return js::ToNumberSlow(cx, v, out); } -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool ToBoolean(HandleValue v) { if (v.isBoolean()) @@ -1105,12 +1078,14 @@ ToBoolean(HandleValue v) double d = v.toDouble(); return !mozilla::IsNaN(d) && d != 0; } + if (v.isSymbol()) + return true; /* The slow path handles strings and objects. */ return js::ToBooleanSlow(v); } -JS_ALWAYS_INLINE JSString* +MOZ_ALWAYS_INLINE JSString* ToString(JSContext *cx, HandleValue v) { if (v.isString()) @@ -1133,32 +1108,31 @@ JS_DoubleToUint32(double d); namespace js { /* DO NOT CALL THIS. Use JS::ToUint16. */ extern JS_PUBLIC_API(bool) -ToUint16Slow(JSContext *cx, JS::Handle v, uint16_t *out); +ToUint16Slow(JSContext *cx, JS::HandleValue v, uint16_t *out); /* DO NOT CALL THIS. Use JS::ToInt32. */ extern JS_PUBLIC_API(bool) -ToInt32Slow(JSContext *cx, JS::Handle v, int32_t *out); +ToInt32Slow(JSContext *cx, JS::HandleValue v, int32_t *out); /* DO NOT CALL THIS. Use JS::ToUint32. */ extern JS_PUBLIC_API(bool) -ToUint32Slow(JSContext *cx, JS::Handle v, uint32_t *out); +ToUint32Slow(JSContext *cx, JS::HandleValue v, uint32_t *out); /* DO NOT CALL THIS. Use JS::ToInt64. */ extern JS_PUBLIC_API(bool) -ToInt64Slow(JSContext *cx, JS::Handle v, int64_t *out); +ToInt64Slow(JSContext *cx, JS::HandleValue v, int64_t *out); /* DO NOT CALL THIS. Use JS::ToUint64. */ extern JS_PUBLIC_API(bool) -ToUint64Slow(JSContext *cx, JS::Handle v, uint64_t *out); +ToUint64Slow(JSContext *cx, JS::HandleValue v, uint64_t *out); } /* namespace js */ namespace JS { -JS_ALWAYS_INLINE bool -ToUint16(JSContext *cx, JS::Handle v, uint16_t *out) +MOZ_ALWAYS_INLINE bool +ToUint16(JSContext *cx, JS::HandleValue v, uint16_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = uint16_t(v.toInt32()); @@ -1167,11 +1141,10 @@ ToUint16(JSContext *cx, JS::Handle v, uint16_t *out) return js::ToUint16Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToInt32(JSContext *cx, JS::Handle v, int32_t *out) +MOZ_ALWAYS_INLINE bool +ToInt32(JSContext *cx, JS::HandleValue v, int32_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = v.toInt32(); @@ -1180,11 +1153,10 @@ ToInt32(JSContext *cx, JS::Handle v, int32_t *out) return js::ToInt32Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToUint32(JSContext *cx, JS::Handle v, uint32_t *out) +MOZ_ALWAYS_INLINE bool +ToUint32(JSContext *cx, JS::HandleValue v, uint32_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = uint32_t(v.toInt32()); @@ -1193,32 +1165,28 @@ ToUint32(JSContext *cx, JS::Handle v, uint32_t *out) return js::ToUint32Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToInt64(JSContext *cx, JS::Handle v, int64_t *out) +MOZ_ALWAYS_INLINE bool +ToInt64(JSContext *cx, JS::HandleValue v, int64_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = int64_t(v.toInt32()); return true; } - return js::ToInt64Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToUint64(JSContext *cx, JS::Handle v, uint64_t *out) +MOZ_ALWAYS_INLINE bool +ToUint64(JSContext *cx, JS::HandleValue v, uint64_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { /* Account for sign extension of negatives into the longer 64bit space. */ *out = uint64_t(int64_t(v.toInt32())); return true; } - return js::ToUint64Slow(cx, v, out); } @@ -1226,7 +1194,7 @@ ToUint64(JSContext *cx, JS::Handle v, uint64_t *out) } /* namespace JS */ extern JS_PUBLIC_API(JSType) -JS_TypeOfValue(JSContext *cx, jsval v); +JS_TypeOfValue(JSContext *cx, JS::Handle v); extern JS_PUBLIC_API(const char *) JS_GetTypeName(JSContext *cx, JSType type); @@ -1235,7 +1203,7 @@ extern JS_PUBLIC_API(bool) JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal); extern JS_PUBLIC_API(bool) -JS_LooselyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal); +JS_LooselyEqual(JSContext *cx, JS::Handle v1, JS::Handle v2, bool *equal); extern JS_PUBLIC_API(bool) JS_SameValue(JSContext *cx, jsval v1, jsval v2, bool *same); @@ -1258,12 +1226,6 @@ JS_IsBuiltinFunctionConstructor(JSFunction *fun); * See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference */ -typedef enum JSUseHelperThreads -{ - JS_NO_HELPER_THREADS, - JS_USE_HELPER_THREADS -} JSUseHelperThreads; - /** * Initialize SpiderMonkey, returning true only if initialization succeeded. * Once this method has succeeded, it is safe to call JS_NewRuntime and other @@ -1301,7 +1263,9 @@ extern JS_PUBLIC_API(void) JS_ShutDown(void); extern JS_PUBLIC_API(JSRuntime *) -JS_NewRuntime(uint32_t maxbytes, JSUseHelperThreads useHelperThreads); +JS_NewRuntime(uint32_t maxbytes, + uint32_t maxNurseryBytes = JS::DefaultNurseryBytes, + JSRuntime *parentRuntime = nullptr); extern JS_PUBLIC_API(void) JS_DestroyRuntime(JSRuntime *rt); @@ -1324,6 +1288,9 @@ JS_GetRuntimePrivate(JSRuntime *rt); extern JS_PUBLIC_API(JSRuntime *) JS_GetRuntime(JSContext *cx); +extern JS_PUBLIC_API(JSRuntime *) +JS_GetParentRuntime(JSContext *cx); + JS_PUBLIC_API(void) JS_SetRuntimePrivate(JSRuntime *rt, void *data); @@ -1349,8 +1316,8 @@ AssertHeapIsIdle(JSContext *cx); class JSAutoRequest { public: - JSAutoRequest(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit JSAutoRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : mContext(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -1374,10 +1341,10 @@ class JSAutoRequest class JSAutoCheckRequest { public: - JSAutoCheckRequest(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit JSAutoCheckRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) { -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG mContext = cx; JS_ASSERT(JS_IsInRequest(JS_GetRuntime(cx))); #endif @@ -1385,14 +1352,14 @@ class JSAutoCheckRequest } ~JSAutoCheckRequest() { -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG JS_ASSERT(JS_IsInRequest(JS_GetRuntime(mContext))); #endif } private: -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG JSContext *mContext; #endif MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER @@ -1448,54 +1415,122 @@ JS_StringToVersion(const char *string); namespace JS { -class JS_PUBLIC_API(ContextOptions) { +class JS_PUBLIC_API(RuntimeOptions) { public: - ContextOptions() - : extraWarnings_(false), + RuntimeOptions() + : baseline_(false), + ion_(false), + asmJS_(false), + nativeRegExp_(false), werror_(false), - varObjFix_(false), - privateIsNSISupports_(false), - dontReportUncaught_(false), - noDefaultCompartmentObject_(false), - noScriptRval_(false), strictMode_(false), - baseline_(false), - typeInference_(false), - ion_(false), - asmJS_(false) + varObjFix_(false) { } - bool extraWarnings() const { return extraWarnings_; } - ContextOptions &setExtraWarnings(bool flag) { - extraWarnings_ = flag; + bool baseline() const { return baseline_; } + RuntimeOptions &setBaseline(bool flag) { + baseline_ = flag; return *this; } - ContextOptions &toggleExtraWarnings() { - extraWarnings_ = !extraWarnings_; + RuntimeOptions &toggleBaseline() { + baseline_ = !baseline_; + return *this; + } + + bool ion() const { return ion_; } + RuntimeOptions &setIon(bool flag) { + ion_ = flag; + return *this; + } + RuntimeOptions &toggleIon() { + ion_ = !ion_; + return *this; + } + + bool asmJS() const { return asmJS_; } + RuntimeOptions &setAsmJS(bool flag) { + asmJS_ = flag; + return *this; + } + RuntimeOptions &toggleAsmJS() { + asmJS_ = !asmJS_; + return *this; + } + + bool nativeRegExp() const { return nativeRegExp_; } + RuntimeOptions &setNativeRegExp(bool flag) { + nativeRegExp_ = flag; return *this; } bool werror() const { return werror_; } - ContextOptions &setWerror(bool flag) { + RuntimeOptions &setWerror(bool flag) { werror_ = flag; return *this; } - ContextOptions &toggleWerror() { + RuntimeOptions &toggleWerror() { werror_ = !werror_; return *this; } + bool strictMode() const { return strictMode_; } + RuntimeOptions &setStrictMode(bool flag) { + strictMode_ = flag; + return *this; + } + RuntimeOptions &toggleStrictMode() { + strictMode_ = !strictMode_; + return *this; + } + bool varObjFix() const { return varObjFix_; } - ContextOptions &setVarObjFix(bool flag) { + RuntimeOptions &setVarObjFix(bool flag) { varObjFix_ = flag; return *this; } - ContextOptions &toggleVarObjFix() { + RuntimeOptions &toggleVarObjFix() { varObjFix_ = !varObjFix_; return *this; } + private: + bool baseline_ : 1; + bool ion_ : 1; + bool asmJS_ : 1; + bool nativeRegExp_ : 1; + bool werror_ : 1; + bool strictMode_ : 1; + bool varObjFix_ : 1; +}; + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSRuntime *rt); + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSContext *cx); + +class JS_PUBLIC_API(ContextOptions) { + public: + ContextOptions() + : extraWarnings_(false), + privateIsNSISupports_(false), + dontReportUncaught_(false), + noDefaultCompartmentObject_(false), + noScriptRval_(false) + { + } + + bool extraWarnings() const { return extraWarnings_; } + ContextOptions &setExtraWarnings(bool flag) { + extraWarnings_ = flag; + return *this; + } + ContextOptions &toggleExtraWarnings() { + extraWarnings_ = !extraWarnings_; + return *this; + } + bool privateIsNSISupports() const { return privateIsNSISupports_; } ContextOptions &setPrivateIsNSISupports(bool flag) { privateIsNSISupports_ = flag; @@ -1536,69 +1571,12 @@ class JS_PUBLIC_API(ContextOptions) { return *this; } - bool strictMode() const { return strictMode_; } - ContextOptions &setStrictMode(bool flag) { - strictMode_ = flag; - return *this; - } - ContextOptions &toggleStrictMode() { - strictMode_ = !strictMode_; - return *this; - } - - bool baseline() const { return baseline_; } - ContextOptions &setBaseline(bool flag) { - baseline_ = flag; - return *this; - } - ContextOptions &toggleBaseline() { - baseline_ = !baseline_; - return *this; - } - - bool typeInference() const { return typeInference_; } - ContextOptions &setTypeInference(bool flag) { - typeInference_ = flag; - return *this; - } - ContextOptions &toggleTypeInference() { - typeInference_ = !typeInference_; - return *this; - } - - bool ion() const { return ion_; } - ContextOptions &setIon(bool flag) { - ion_ = flag; - return *this; - } - ContextOptions &toggleIon() { - ion_ = !ion_; - return *this; - } - - bool asmJS() const { return asmJS_; } - ContextOptions &setAsmJS(bool flag) { - asmJS_ = flag; - return *this; - } - ContextOptions &toggleAsmJS() { - asmJS_ = !asmJS_; - return *this; - } - private: bool extraWarnings_ : 1; - bool werror_ : 1; - bool varObjFix_ : 1; bool privateIsNSISupports_ : 1; bool dontReportUncaught_ : 1; bool noDefaultCompartmentObject_ : 1; bool noScriptRval_ : 1; - bool strictMode_ : 1; - bool baseline_ : 1; - bool typeInference_ : 1; - bool ion_ : 1; - bool asmJS_ : 1; }; JS_PUBLIC_API(ContextOptions &) @@ -1606,7 +1584,7 @@ ContextOptionsRef(JSContext *cx); class JS_PUBLIC_API(AutoSaveContextOptions) { public: - AutoSaveContextOptions(JSContext *cx) + explicit AutoSaveContextOptions(JSContext *cx) : cx_(cx), oldOptions_(ContextOptionsRef(cx_)) { @@ -1624,9 +1602,6 @@ class JS_PUBLIC_API(AutoSaveContextOptions) { } /* namespace JS */ -extern JS_PUBLIC_API(void) -JS_SetJitHardening(JSRuntime *rt, bool enabled); - extern JS_PUBLIC_API(const char *) JS_GetImplementationVersion(void); @@ -1663,14 +1638,11 @@ JS_WrapObject(JSContext *cx, JS::MutableHandleObject objp); extern JS_PUBLIC_API(bool) JS_WrapValue(JSContext *cx, JS::MutableHandleValue vp); -extern JS_PUBLIC_API(bool) -JS_WrapId(JSContext *cx, jsid *idp); - extern JS_PUBLIC_API(JSObject *) -JS_TransplantObject(JSContext *cx, JS::Handle origobj, JS::Handle target); +JS_TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target); extern JS_PUBLIC_API(bool) -JS_RefreshCrossCompartmentWrappers(JSContext *cx, JSObject *ob); +JS_RefreshCrossCompartmentWrappers(JSContext *cx, JS::Handle obj); /* * At any time, a JSContext has a current (possibly-nullptr) compartment. @@ -1717,6 +1689,15 @@ class JS_PUBLIC_API(JSAutoCompartment) ~JSAutoCompartment(); }; +class JS_PUBLIC_API(JSAutoNullableCompartment) +{ + JSContext *cx_; + JSCompartment *oldCompartment_; + public: + explicit JSAutoNullableCompartment(JSContext *cx, JSObject *targetOrNull); + ~JSAutoNullableCompartment(); +}; + /* NB: This API is infallible; a nullptr return value does not indicate error. */ extern JS_PUBLIC_API(JSCompartment *) JS_EnterCompartment(JSContext *cx, JSObject *target); @@ -1743,7 +1724,7 @@ JS_IterateCompartments(JSRuntime *rt, void *data, * NB: This sets cx's global object to obj if it was null. */ extern JS_PUBLIC_API(bool) -JS_InitStandardClasses(JSContext *cx, JSObject *obj); +JS_InitStandardClasses(JSContext *cx, JS::Handle obj); /* * Resolve id, which must contain either a string or an int, to a standard @@ -1759,20 +1740,40 @@ JS_InitStandardClasses(JSContext *cx, JSObject *obj); * loops any classes not yet resolved lazily. */ extern JS_PUBLIC_API(bool) -JS_ResolveStandardClass(JSContext *cx, JS::Handle obj, JS::Handle id, - bool *resolved); +JS_ResolveStandardClass(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *resolved); extern JS_PUBLIC_API(bool) -JS_EnumerateStandardClasses(JSContext *cx, JS::Handle obj); +JS_EnumerateStandardClasses(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, JSObject **objp); +JS_GetClassObject(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); extern JS_PUBLIC_API(bool) -JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JSObject **objp); +JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); + +namespace JS { + +/* + * Determine if the given object is an instance/prototype/constructor for a standard + * class. If so, return the associated JSProtoKey. If not, return JSProto_Null. + */ + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstance(JSObject *obj); extern JS_PUBLIC_API(JSProtoKey) -JS_IdentifyClassPrototype(JSContext *cx, JSObject *obj); +IdentifyStandardPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstanceOrPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardConstructor(JSObject *obj); + +extern JS_PUBLIC_API(void) +ProtoKeyToId(JSContext *cx, JSProtoKey key, JS::MutableHandleId idp); + +} /* namespace JS */ extern JS_PUBLIC_API(JSProtoKey) JS_IdToProtoKey(JSContext *cx, JS::HandleId id); @@ -1782,21 +1783,28 @@ JS_IdToProtoKey(JSContext *cx, JS::HandleId id); * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetFunctionPrototype(JSContext *cx, JSObject *forObj); +JS_GetFunctionPrototype(JSContext *cx, JS::HandleObject forObj); /* * Returns the original value of |Object.prototype| from the global object in * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetObjectPrototype(JSContext *cx, JSObject *forObj); +JS_GetObjectPrototype(JSContext *cx, JS::HandleObject forObj); /* * Returns the original value of |Array.prototype| from the global object in * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetArrayPrototype(JSContext *cx, JSObject *forObj); +JS_GetArrayPrototype(JSContext *cx, JS::HandleObject forObj); + +/* + * Returns the original value of |Error.prototype| from the global + * object of the current compartment of cx. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetErrorPrototype(JSContext *cx); extern JS_PUBLIC_API(JSObject *) JS_GetGlobalForObject(JSContext *cx, JSObject *obj); @@ -1818,23 +1826,11 @@ CurrentGlobalOrNull(JSContext *cx); } -/* - * This method returns the global corresponding to the most recent scripted - * frame, which may not match the cx's current compartment. This is extremely - * dangerous, because it can bypass compartment security invariants in subtle - * ways. To use it safely, the caller must perform a subsequent security - * check. There is currently only one consumer of this function in Gecko, and - * it should probably stay that way. If you'd like to use it, please consult - * the XPConnect module owner first. - */ -extern JS_PUBLIC_API(JSObject *) -JS_GetScriptedGlobal(JSContext *cx); - /* * Initialize the 'Reflect' object on a global object. */ extern JS_PUBLIC_API(JSObject *) -JS_InitReflect(JSContext *cx, JSObject *global); +JS_InitReflect(JSContext *cx, JS::HandleObject global); #ifdef JS_HAS_CTYPES /* @@ -1842,7 +1838,7 @@ JS_InitReflect(JSContext *cx, JSObject *global); * object will be sealed. */ extern JS_PUBLIC_API(bool) -JS_InitCTypesClass(JSContext *cx, JSObject *global); +JS_InitCTypesClass(JSContext *cx, JS::HandleObject global); /* * Convert a unicode string 'source' of length 'slen' to the platform native @@ -1917,6 +1913,7 @@ JS_strdup(JSContext *cx, const char *s); extern JS_PUBLIC_API(char *) JS_strdup(JSRuntime *rt, const char *s); +namespace JS { /* * A GC root is a pointer to a jsval, JSObject * or JSString * that itself @@ -1944,52 +1941,54 @@ JS_strdup(JSRuntime *rt, const char *s); * before freeing structPtr's memory. */ extern JS_PUBLIC_API(bool) -JS_AddValueRoot(JSContext *cx, jsval *vp); +AddValueRoot(JSContext *cx, JS::Heap *vp); extern JS_PUBLIC_API(bool) -JS_AddStringRoot(JSContext *cx, JSString **rp); +AddStringRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(bool) -JS_AddObjectRoot(JSContext *cx, JSObject **rp); +AddObjectRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(bool) -JS_AddNamedValueRoot(JSContext *cx, jsval *vp, const char *name); +AddNamedValueRoot(JSContext *cx, JS::Heap *vp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedValueRootRT(JSRuntime *rt, jsval *vp, const char *name); +AddNamedValueRootRT(JSRuntime *rt, JS::Heap *vp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedStringRoot(JSContext *cx, JSString **rp, const char *name); +AddNamedStringRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedObjectRoot(JSContext *cx, JSObject **rp, const char *name); +AddNamedObjectRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedScriptRoot(JSContext *cx, JSScript **rp, const char *name); +AddNamedScriptRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(void) -JS_RemoveValueRoot(JSContext *cx, jsval *vp); +RemoveValueRoot(JSContext *cx, JS::Heap *vp); extern JS_PUBLIC_API(void) -JS_RemoveStringRoot(JSContext *cx, JSString **rp); +RemoveStringRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveObjectRoot(JSContext *cx, JSObject **rp); +RemoveObjectRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveScriptRoot(JSContext *cx, JSScript **rp); +RemoveScriptRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveValueRootRT(JSRuntime *rt, jsval *vp); +RemoveValueRootRT(JSRuntime *rt, JS::Heap *vp); extern JS_PUBLIC_API(void) -JS_RemoveStringRootRT(JSRuntime *rt, JSString **rp); +RemoveStringRootRT(JSRuntime *rt, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveObjectRootRT(JSRuntime *rt, JSObject **rp); +RemoveObjectRootRT(JSRuntime *rt, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveScriptRootRT(JSRuntime *rt, JSScript **rp); +RemoveScriptRootRT(JSRuntime *rt, JS::Heap *rp); + +} /* namespace JS */ /* * Register externally maintained GC roots. @@ -2005,42 +2004,10 @@ JS_AddExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); extern JS_PUBLIC_API(void) JS_RemoveExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); -/* - * JS_CallTracer API and related macros for implementors of JSTraceOp, to - * enumerate all references to traceable things reachable via a property or - * other strong ref identified for debugging purposes by name or index or - * a naming callback. - * - * See the JSTraceOp typedef. - */ +#ifdef JS_DEBUG /* - * Use the following macros to check if a particular jsval is a traceable - * thing and to extract the thing and its kind to pass to JS_CallTracer. - */ -static JS_ALWAYS_INLINE bool -JSVAL_IS_TRACEABLE(jsval v) -{ - return JSVAL_IS_TRACEABLE_IMPL(JSVAL_TO_IMPL(v)); -} - -static JS_ALWAYS_INLINE void * -JSVAL_TO_TRACEABLE(jsval v) -{ - return JSVAL_TO_GCTHING(v); -} - -static JS_ALWAYS_INLINE JSGCTraceKind -JSVAL_TRACE_KIND(jsval v) -{ - JS_ASSERT(JSVAL_IS_GCTHING(v)); - return (JSGCTraceKind) JSVAL_TRACE_KIND_IMPL(JSVAL_TO_IMPL(v)); -} - -#ifdef DEBUG - -/* - * DEBUG-only method to dump the object graph of heap-allocated things. + * Debug-only method to dump the object graph of heap-allocated things. * * fp: file for the dump output. * start: when non-null, dump only things reachable from start @@ -2072,14 +2039,17 @@ JS_MaybeGC(JSContext *cx); extern JS_PUBLIC_API(void) JS_SetGCCallback(JSRuntime *rt, JSGCCallback cb, void *data); +extern JS_PUBLIC_API(bool) +JS_AddFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb, void *data); + extern JS_PUBLIC_API(void) -JS_SetFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); +JS_RemoveFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); extern JS_PUBLIC_API(bool) JS_IsGCMarkingTracer(JSTracer *trc); /* For assertions only. */ -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_PUBLIC_API(bool) JS_IsMarkingGray(JSTracer *trc); #endif @@ -2175,22 +2145,17 @@ typedef enum JSGCParamKey { * available to be decommitted, then JS_MaybeGC will trigger a shrinking GC * to decommit it. */ - JSGC_DECOMMIT_THRESHOLD = 20 -} JSGCParamKey; - -typedef enum JSGCMode { - /* Perform only global GCs. */ - JSGC_MODE_GLOBAL = 0, - - /* Perform per-compartment GCs until too much garbage has accumulated. */ - JSGC_MODE_COMPARTMENT = 1, + JSGC_DECOMMIT_THRESHOLD = 20, /* - * Collect in short time slices rather than all at once. Implies - * JSGC_MODE_COMPARTMENT. + * We try to keep at least this many unused chunks in the free chunk pool at + * all times, even after a shrinking GC. */ - JSGC_MODE_INCREMENTAL = 2 -} JSGCMode; + JSGC_MIN_EMPTY_CHUNK_COUNT = 21, + + /* We never keep more than this many unused chunks in the free chunk pool. */ + JSGC_MAX_EMPTY_CHUNK_COUNT = 22 +} JSGCParamKey; extern JS_PUBLIC_API(void) JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32_t value); @@ -2204,6 +2169,9 @@ JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32_t value); extern JS_PUBLIC_API(uint32_t) JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key); +extern JS_PUBLIC_API(void) +JS_SetGCParametersBasedOnAvailableMemory(JSRuntime *rt, uint32_t availMem); + /* * Create a new JSString whose chars member refers to external memory, i.e., * memory requiring application-specific finalization. @@ -2252,7 +2220,7 @@ extern JS_PUBLIC_API(int) JS_IdArrayLength(JSContext *cx, JSIdArray *ida); extern JS_PUBLIC_API(jsid) -JS_IdArrayGet(JSContext *cx, JSIdArray *ida, int index); +JS_IdArrayGet(JSContext *cx, JSIdArray *ida, unsigned index); extern JS_PUBLIC_API(void) JS_DestroyIdArray(JSContext *cx, JSIdArray *ida); @@ -2272,13 +2240,12 @@ class AutoIdArray : private AutoGCRooter if (idArray) JS_DestroyIdArray(context, idArray); } - bool operator!() { + bool operator!() const { return !idArray; } jsid operator[](size_t i) const { JS_ASSERT(idArray); - JS_ASSERT(i < length()); - return JS_IdArrayGet(context, idArray, i); + return JS_IdArrayGet(context, idArray, unsigned(i)); } size_t length() const { return JS_IdArrayLength(context, idArray); @@ -2308,15 +2275,13 @@ class AutoIdArray : private AutoGCRooter } /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_ValueToId(JSContext *cx, jsval v, jsid *idp); +JS_ValueToId(JSContext *cx, JS::HandleValue v, JS::MutableHandleId idp); extern JS_PUBLIC_API(bool) -JS_IdToValue(JSContext *cx, jsid id, jsval *vp); +JS_StringToId(JSContext *cx, JS::HandleString s, JS::MutableHandleId idp); -/* - * JSNewResolveOp flag bits. - */ -#define JSRESOLVE_ASSIGNING 0x01 /* resolve on the left of assignment */ +extern JS_PUBLIC_API(bool) +JS_IdToValue(JSContext *cx, jsid id, JS::MutableHandle vp); /* * Invoke the [[DefaultValue]] hook (see ES5 8.6.2) with the provided hint on @@ -2325,29 +2290,30 @@ JS_IdToValue(JSContext *cx, jsid id, jsval *vp); * success the resulting value is stored in *vp. */ extern JS_PUBLIC_API(bool) -JS_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp); +JS_DefaultValue(JSContext *cx, JS::Handle obj, JSType hint, + JS::MutableHandle vp); extern JS_PUBLIC_API(bool) -JS_PropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, - JS::MutableHandle vp); +JS_PropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_StrictPropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, bool strict, - JS::MutableHandle vp); +JS_StrictPropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_DeletePropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, +JS_DeletePropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_EnumerateStub(JSContext *cx, JS::Handle obj); +JS_EnumerateStub(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_ResolveStub(JSContext *cx, JS::Handle obj, JS::Handle id); +JS_ResolveStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id); extern JS_PUBLIC_API(bool) -JS_ConvertStub(JSContext *cx, JS::Handle obj, JSType type, - JS::MutableHandle vp); +JS_ConvertStub(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); struct JSConstDoubleSpec { double dval; @@ -2385,7 +2351,7 @@ typedef struct JSNativeWrapper { * Macro static initializers which make it easy to pass no JSJitInfo as part of a * JSPropertySpec or JSFunctionSpec. */ -#define JSOP_WRAPPER(op) {op, nullptr} +#define JSOP_WRAPPER(op) { {op, nullptr} } #define JSOP_NULLWRAPPER JSOP_WRAPPER(nullptr) /* @@ -2394,13 +2360,29 @@ typedef struct JSNativeWrapper { * JSPROP_INDEX bit in flags. */ struct JSPropertySpec { + struct SelfHostedWrapper { + void *unused; + const char *funname; + }; + const char *name; - int8_t tinyid; uint8_t flags; - JSPropertyOpWrapper getter; - JSStrictPropertyOpWrapper setter; - const char *selfHostedGetter; - const char *selfHostedSetter; + union { + JSPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } getter; + union { + JSStrictPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } setter; + +private: + void StaticAsserts() { + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSPropertyOpWrapper)); + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSStrictPropertyOpWrapper)); + JS_STATIC_ASSERT(offsetof(SelfHostedWrapper, funname) == + offsetof(JSPropertyOpWrapper, info)); + } }; namespace JS { @@ -2409,6 +2391,11 @@ namespace detail { /* NEVER DEFINED, DON'T USE. For use by JS_CAST_NATIVE_TO only. */ inline int CheckIsNative(JSNative native); +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_STRING_TO only. */ +template +inline int +CheckIsCharacterLiteral(const char (&arr)[N]); + } // namespace detail } // namespace JS @@ -2416,6 +2403,10 @@ inline int CheckIsNative(JSNative native); (static_cast(sizeof(JS::detail::CheckIsNative(v))), \ reinterpret_cast(v)) +#define JS_CAST_STRING_TO(s, To) \ + (static_cast(sizeof(JS::detail::CheckIsCharacterLiteral(s))), \ + reinterpret_cast(s)) + #define JS_CHECK_ACCESSOR_FLAGS(flags) \ (static_cast::Type>(0), \ (flags)) @@ -2428,26 +2419,26 @@ inline int CheckIsNative(JSNative native); * JSNatives. */ #define JS_PSG(name, getter, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ - JSOP_NULLWRAPPER, nullptr, nullptr} + JSOP_NULLWRAPPER} #define JS_PSGS(name, getter, setter, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ - JSOP_WRAPPER(JS_CAST_NATIVE_TO(setter, JSStrictPropertyOp)), \ - nullptr, nullptr} + JSOP_WRAPPER(JS_CAST_NATIVE_TO(setter, JSStrictPropertyOp))} #define JS_SELF_HOSTED_GET(name, getterName, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER), \ - JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, getterName, nullptr} + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + JSOP_NULLWRAPPER } #define JS_SELF_HOSTED_GETSET(name, getterName, setterName, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER | JSPROP_SETTER), \ - JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, getterName, setterName} -#define JS_PS_END {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, \ - nullptr, nullptr} + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + { nullptr, JS_CAST_STRING_TO(setterName, const JSJitInfo *) } } +#define JS_PS_END { nullptr, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER } /* * To define a native function, set call to a JSNativeWrapper. To define a @@ -2487,7 +2478,7 @@ struct JSFunctionSpec { {name, {call, info}, nargs, flags, selfHostedName} extern JS_PUBLIC_API(JSObject *) -JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, +JS_InitClass(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent_proto, const JSClass *clasp, JSNative constructor, unsigned nargs, const JSPropertySpec *ps, const JSFunctionSpec *fs, const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs); @@ -2497,16 +2488,17 @@ JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, * right property flags. */ extern JS_PUBLIC_API(bool) -JS_LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor, JSObject *proto); +JS_LinkConstructorAndPrototype(JSContext *cx, JS::Handle ctor, + JS::Handle proto); extern JS_PUBLIC_API(const JSClass *) JS_GetClass(JSObject *obj); extern JS_PUBLIC_API(bool) -JS_InstanceOf(JSContext *cx, JSObject *obj, const JSClass *clasp, jsval *argv); +JS_InstanceOf(JSContext *cx, JS::Handle obj, const JSClass *clasp, JS::CallArgs *args); extern JS_PUBLIC_API(bool) -JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, bool *bp); +JS_HasInstance(JSContext *cx, JS::Handle obj, JS::Handle v, bool *bp); extern JS_PUBLIC_API(void *) JS_GetPrivate(JSObject *obj); @@ -2515,31 +2507,23 @@ extern JS_PUBLIC_API(void) JS_SetPrivate(JSObject *obj, void *data); extern JS_PUBLIC_API(void *) -JS_GetInstancePrivate(JSContext *cx, JSObject *obj, const JSClass *clasp, - jsval *argv); +JS_GetInstancePrivate(JSContext *cx, JS::Handle obj, const JSClass *clasp, + JS::CallArgs *args); extern JS_PUBLIC_API(bool) -JS_GetPrototype(JSContext *cx, JS::Handle obj, JS::MutableHandle protop); +JS_GetPrototype(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject protop); extern JS_PUBLIC_API(bool) -JS_SetPrototype(JSContext *cx, JS::Handle obj, JS::Handle proto); +JS_SetPrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); extern JS_PUBLIC_API(JSObject *) JS_GetParent(JSObject *obj); extern JS_PUBLIC_API(bool) -JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent); +JS_SetParent(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent); extern JS_PUBLIC_API(JSObject *) -JS_GetConstructor(JSContext *cx, JSObject *proto); - -/* - * Get a unique identifier for obj, good for the lifetime of obj (even if it - * is moved by a copying GC). Return false on failure (likely out of memory), - * and true with *idp containing the unique id on success. - */ -extern JS_PUBLIC_API(bool) -JS_GetObjectId(JSContext *cx, JSObject *obj, jsid *idp); +JS_GetConstructor(JSContext *cx, JS::Handle proto); namespace JS { @@ -2582,6 +2566,12 @@ class JS_PUBLIC_API(CompartmentOptions) explicit CompartmentOptions() : version_(JSVERSION_UNKNOWN) , invisibleToDebugger_(false) + , mergeable_(false) + , discardSource_(false) + , cloneSingletons_(false) + , traceGlobal_(nullptr) + , singletonsAsTemplates_(true) + , addonId_(nullptr) { zone_.spec = JS::FreshZone; } @@ -2597,23 +2587,36 @@ class JS_PUBLIC_API(CompartmentOptions) // of the embedding, and references to them should never leak out to script. // This flag causes the this compartment to skip firing onNewGlobalObject // and makes addDebuggee a no-op for this global. - bool invisibleToDebugger() { return invisibleToDebugger_; } + bool invisibleToDebugger() const { return invisibleToDebugger_; } CompartmentOptions &setInvisibleToDebugger(bool flag) { invisibleToDebugger_ = flag; return *this; } - bool baseline(JSContext *cx) const; - Override &baselineOverride() { return baselineOverride_; } + // Compartments used for off-thread compilation have their contents merged + // into a target compartment when the compilation is finished. This is only + // allowed if this flag is set. The invisibleToDebugger flag must also be + // set for such compartments. + bool mergeable() const { return mergeable_; } + CompartmentOptions &setMergeable(bool flag) { + mergeable_ = flag; + return *this; + } - bool typeInference(const js::ExclusiveContext *cx) const; - Override &typeInferenceOverride() { return typeInferenceOverride_; } + // For certain globals, we know enough about the code that will run in them + // that we can discard script source entirely. + bool discardSource() const { return discardSource_; } + CompartmentOptions &setDiscardSource(bool flag) { + discardSource_ = flag; + return *this; + } - bool ion(JSContext *cx) const; - Override &ionOverride() { return ionOverride_; } - bool asmJS(JSContext *cx) const; - Override &asmJSOverride() { return asmJSOverride_; } + bool cloneSingletons() const { return cloneSingletons_; } + CompartmentOptions &setCloneSingletons(bool flag) { + cloneSingletons_ = flag; + return *this; + } void *zonePointer() const { JS_ASSERT(uintptr_t(zone_.pointer) > uintptr_t(JS::SystemZone)); @@ -2623,22 +2626,55 @@ class JS_PUBLIC_API(CompartmentOptions) CompartmentOptions &setZone(ZoneSpecifier spec); CompartmentOptions &setSameZoneAs(JSObject *obj); + void setSingletonsAsValues() { + singletonsAsTemplates_ = false; + } + bool getSingletonsAsTemplates() const { + return singletonsAsTemplates_; + }; + + // A null add-on ID means that the compartment is not associated with an + // add-on. + JSAddonId *addonIdOrNull() const { return addonId_; } + CompartmentOptions &setAddonId(JSAddonId *id) { + addonId_ = id; + return *this; + } + + CompartmentOptions &setTrace(JSTraceOp op) { + traceGlobal_ = op; + return *this; + } + JSTraceOp getTrace() const { + return traceGlobal_; + } + private: JSVersion version_; bool invisibleToDebugger_; - Override baselineOverride_; - Override typeInferenceOverride_; - Override ionOverride_; - Override asmJSOverride_; + bool mergeable_; + bool discardSource_; + bool cloneSingletons_; union { ZoneSpecifier spec; void *pointer; // js::Zone* is not exposed in the API. } zone_; + JSTraceOp traceGlobal_; + + // To XDR singletons, we need to ensure that all singletons are all used as + // templates, by making JSOP_OBJECT return a clone of the JSScript + // singleton, instead of returning the value which is baked in the JSScript. + bool singletonsAsTemplates_; + + JSAddonId *addonId_; }; JS_PUBLIC_API(CompartmentOptions &) CompartmentOptionsRef(JSCompartment *compartment); +JS_PUBLIC_API(CompartmentOptions &) +CompartmentOptionsRef(JSObject *obj); + JS_PUBLIC_API(CompartmentOptions &) CompartmentOptionsRef(JSContext *cx); @@ -2673,16 +2709,28 @@ extern JS_PUBLIC_API(JSObject *) JS_NewGlobalObject(JSContext *cx, const JSClass *clasp, JSPrincipals *principals, JS::OnNewGlobalHookOption hookOption, const JS::CompartmentOptions &options = JS::CompartmentOptions()); +/* + * Spidermonkey does not have a good way of keeping track of what compartments should be marked on + * their own. We can mark the roots unconditionally, but marking GC things only relevant in live + * compartments is hard. To mitigate this, we create a static trace hook, installed on each global + * object, from which we can be sure the compartment is relevant, and mark it. + * + * It is still possible to specify custom trace hooks for global object classes. They can be + * provided via the CompartmentOptions passed to JS_NewGlobalObject. + */ +extern JS_PUBLIC_API(void) +JS_GlobalObjectTraceHook(JSTracer *trc, JSObject *global); extern JS_PUBLIC_API(void) JS_FireOnNewGlobalObject(JSContext *cx, JS::HandleObject global); extern JS_PUBLIC_API(JSObject *) -JS_NewObject(JSContext *cx, const JSClass *clasp, JSObject *proto, JSObject *parent); +JS_NewObject(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); /* Queries the [[Extensible]] property of the object. */ extern JS_PUBLIC_API(bool) -JS_IsExtensible(JSContext *cx, JS::Handle obj, bool *extensible); +JS_IsExtensible(JSContext *cx, JS::HandleObject obj, bool *extensible); extern JS_PUBLIC_API(bool) JS_IsNative(JSObject *obj); @@ -2695,8 +2743,8 @@ JS_GetObjectRuntime(JSObject *obj); * proto if proto's actual parameter value is null. */ extern JS_PUBLIC_API(JSObject *) -JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JSObject *proto, - JSObject *parent); +JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); /* * Freeze obj, and all objects it refers to, recursively. This will not recurse @@ -2704,88 +2752,126 @@ JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JSObject *proto, * deep-frozen. */ extern JS_PUBLIC_API(bool) -JS_DeepFreezeObject(JSContext *cx, JSObject *obj); +JS_DeepFreezeObject(JSContext *cx, JS::Handle obj); /* * Freezes an object; see ES5's Object.freeze(obj) method. */ extern JS_PUBLIC_API(bool) -JS_FreezeObject(JSContext *cx, JSObject *obj); +JS_FreezeObject(JSContext *cx, JS::Handle obj); extern JS_PUBLIC_API(bool) -JS_PreventExtensions(JSContext *cx, JS::Handle obj); +JS_PreventExtensions(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(JSObject *) -JS_New(JSContext *cx, JSObject *ctor, unsigned argc, jsval *argv); +JS_New(JSContext *cx, JS::HandleObject ctor, const JS::HandleValueArray& args); extern JS_PUBLIC_API(JSObject *) -JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, const JSClass *clasp, - JSObject *proto, unsigned attrs); +JS_DefineObject(JSContext *cx, JS::HandleObject obj, const char *name, + const JSClass *clasp = nullptr, JS::HandleObject proto = JS::NullPtr(), + unsigned attrs = 0); extern JS_PUBLIC_API(bool) -JS_DefineConstDoubles(JSContext *cx, JSObject *obj, const JSConstDoubleSpec *cds); +JS_DefineConstDoubles(JSContext *cx, JS::HandleObject obj, const JSConstDoubleSpec *cds); extern JS_PUBLIC_API(bool) -JS_DefineProperties(JSContext *cx, JSObject *obj, const JSPropertySpec *ps); +JS_DefineProperties(JSContext *cx, JS::HandleObject obj, const JSPropertySpec *ps); extern JS_PUBLIC_API(bool) -JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id, jsval descriptor, bool *bp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name, - int8_t tinyid, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name, - bool *foundp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnPropertyById(JSContext *cx, JSObject *obj, jsid id, - bool *foundp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, bool *foundp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, bool *foundp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name, - unsigned flags, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id, - unsigned flags, JSObject **objp, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnProperty(JSContext *cx, JS::HandleObject obj, const char *name, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasProperty(JSContext *cx, JS::HandleObject obj, const char *name, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_LookupPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); struct JSPropertyDescriptor { JSObject *obj; unsigned attrs; - unsigned shortid; JSPropertyOp getter; JSStrictPropertyOp setter; JS::Value value; - JSPropertyDescriptor() : obj(nullptr), attrs(0), shortid(0), getter(nullptr), - setter(nullptr), value(JSVAL_VOID) + JSPropertyDescriptor() + : obj(nullptr), attrs(0), getter(nullptr), setter(nullptr), value(JSVAL_VOID) {} void trace(JSTracer *trc); + + static js::ThingRootKind rootKind() { return js::THING_ROOT_PROPERTY_DESCRIPTOR; } }; namespace JS { @@ -2803,30 +2889,29 @@ class PropertyDescriptorOperations bool hasGetterObject() const { return desc()->attrs & JSPROP_GETTER; } bool hasSetterObject() const { return desc()->attrs & JSPROP_SETTER; } bool hasGetterOrSetterObject() const { return desc()->attrs & (JSPROP_GETTER | JSPROP_SETTER); } + bool hasGetterOrSetter() const { return desc()->getter || desc()->setter; } bool isShared() const { return desc()->attrs & JSPROP_SHARED; } bool isIndex() const { return desc()->attrs & JSPROP_INDEX; } - bool hasShortId() const { return desc()->attrs & JSPROP_SHORTID; } bool hasAttributes(unsigned attrs) const { return desc()->attrs & attrs; } - JS::Handle object() const { - return JS::Handle::fromMarkedLocation(&desc()->obj); + JS::HandleObject object() const { + return JS::HandleObject::fromMarkedLocation(&desc()->obj); } unsigned attributes() const { return desc()->attrs; } - unsigned shortid() const { return desc()->shortid; } JSPropertyOp getter() const { return desc()->getter; } JSStrictPropertyOp setter() const { return desc()->setter; } - JS::Handle getterObject() const { + JS::HandleObject getterObject() const { MOZ_ASSERT(hasGetterObject()); - return JS::Handle::fromMarkedLocation( + return JS::HandleObject::fromMarkedLocation( reinterpret_cast(&desc()->getter)); } - JS::Handle setterObject() const { + JS::HandleObject setterObject() const { MOZ_ASSERT(hasSetterObject()); - return JS::Handle::fromMarkedLocation( + return JS::HandleObject::fromMarkedLocation( reinterpret_cast(&desc()->setter)); } - JS::Handle value() const { - return JS::Handle::fromMarkedLocation(&desc()->value); + JS::HandleValue value() const { + return JS::HandleValue::fromMarkedLocation(&desc()->value); } }; @@ -2840,30 +2925,47 @@ class MutablePropertyDescriptorOperations : public PropertyDescriptorOperations< void clear() { object().set(nullptr); setAttributes(0); - setShortId(0); setGetter(nullptr); setSetter(nullptr); value().setUndefined(); } - JS::MutableHandle object() { - return JS::MutableHandle::fromMarkedLocation(&desc()->obj); + void assign(JSPropertyDescriptor &other) { + object().set(other.obj); + setAttributes(other.attrs); + setGetter(other.getter); + setSetter(other.setter); + value().set(other.value); + } + + JS::MutableHandleObject object() { + return JS::MutableHandleObject::fromMarkedLocation(&desc()->obj); } unsigned &attributesRef() { return desc()->attrs; } JSPropertyOp &getter() { return desc()->getter; } JSStrictPropertyOp &setter() { return desc()->setter; } - JS::MutableHandle value() { - return JS::MutableHandle::fromMarkedLocation(&desc()->value); + JS::MutableHandleValue value() { + return JS::MutableHandleValue::fromMarkedLocation(&desc()->value); } void setEnumerable() { desc()->attrs |= JSPROP_ENUMERATE; } void setAttributes(unsigned attrs) { desc()->attrs = attrs; } - void setShortId(unsigned id) { desc()->shortid = id; } void setGetter(JSPropertyOp op) { desc()->getter = op; } void setSetter(JSStrictPropertyOp op) { desc()->setter = op; } void setGetterObject(JSObject *obj) { desc()->getter = reinterpret_cast(obj); } void setSetterObject(JSObject *obj) { desc()->setter = reinterpret_cast(obj); } + + JS::MutableHandleObject getterObject() { + MOZ_ASSERT(this->hasGetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->getter)); + } + JS::MutableHandleObject setterObject() { + MOZ_ASSERT(this->hasSetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->setter)); + } }; } /* namespace JS */ @@ -2873,7 +2975,6 @@ namespace js { template <> struct GCMethods { static JSPropertyDescriptor initial() { return JSPropertyDescriptor(); } - static ThingRootKind kind() { return THING_ROOT_PROPERTY_DESCRIPTOR; } static bool poisoned(const JSPropertyDescriptor &desc) { return (desc.obj && JS::IsPoisonedPtr(desc.obj)) || (desc.attrs & JSPROP_GETTER && desc.getter && JS::IsPoisonedPtr(desc.getter)) || @@ -2922,12 +3023,22 @@ class MutableHandleBase } /* namespace js */ +namespace JS { + +extern JS_PUBLIC_API(bool) +ParsePropertyDescriptorObject(JSContext *cx, + JS::HandleObject obj, + JS::HandleValue descriptor, + JS::MutableHandle desc); + +} // namespace JS + extern JS_PUBLIC_API(bool) -JS_GetOwnPropertyDescriptorById(JSContext *cx, JSObject *objArg, jsid id, unsigned flags, +JS_GetOwnPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, const char *name, unsigned flags, +JS_GetOwnPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandle desc); /* @@ -2936,138 +3047,193 @@ JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, const char *name, u * then this property was not found on the prototype chain. */ extern JS_PUBLIC_API(bool) -JS_GetPropertyDescriptorById(JSContext *cx, JSObject *obj, jsid id, unsigned flags, +JS_GetPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetPropertyDescriptor(JSContext *cx, JSObject *obj, const char *name, unsigned flags, +JS_GetPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, JS::MutableHandle vp); +JS_GetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetPropertyTo(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject onBehalfOf, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); +JS_SetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_ForwardGetPropertyTo(JSContext *cx, JSObject *obj, jsid id, JSObject *onBehalfOf, - JS::MutableHandle vp); +JS_DeleteProperty(JSContext *cx, JS::HandleObject obj, const char *name); extern JS_PUBLIC_API(bool) -JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, JS::Handle v); +JS_DeleteProperty2(JSContext *cx, JS::HandleObject obj, const char *name, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_SetPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::Handle v); +JS_DeletePropertyById(JSContext *cx, JS::HandleObject obj, jsid id); extern JS_PUBLIC_API(bool) -JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name); +JS_DeletePropertyById2(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name, bool *succeeded); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleValue value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DeletePropertyById(JSContext *cx, JSObject *obj, jsid id); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleObject value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, bool *succeeded); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleString value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineUCProperty(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + int32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, - int8_t tinyid, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + uint32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnUCProperty(JSContext *cx, JSObject *obj, const jschar *name, +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + double value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *foundp); extern JS_PUBLIC_API(bool) -JS_HasUCProperty(JSContext *cx, JSObject *obj, +JS_HasUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *vp); extern JS_PUBLIC_API(bool) -JS_LookupUCProperty(JSContext *cx, JSObject *obj, +JS_LookupUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::MutableHandle vp); + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_GetUCProperty(JSContext *cx, JSObject *obj, +JS_GetUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::MutableHandle vp); + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_SetUCProperty(JSContext *cx, JSObject *obj, +JS_SetUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::Handle v); + JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_DeleteUCProperty2(JSContext *cx, JSObject *obj, const jschar *name, size_t namelen, +JS_DeleteUCProperty2(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *succeeded); extern JS_PUBLIC_API(JSObject *) -JS_NewArrayObject(JSContext *cx, int length, jsval *vector); +JS_NewArrayObject(JSContext *cx, const JS::HandleValueArray& contents); + +extern JS_PUBLIC_API(JSObject *) +JS_NewArrayObject(JSContext *cx, size_t length); extern JS_PUBLIC_API(bool) -JS_IsArrayObject(JSContext *cx, JSObject *obj); +JS_IsArrayObject(JSContext *cx, JS::HandleValue value); extern JS_PUBLIC_API(bool) -JS_GetArrayLength(JSContext *cx, JSObject *obj, uint32_t *lengthp); +JS_IsArrayObject(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_SetArrayLength(JSContext *cx, JSObject *obj, uint32_t length); +JS_GetArrayLength(JSContext *cx, JS::Handle obj, uint32_t *lengthp); extern JS_PUBLIC_API(bool) -JS_DefineElement(JSContext *cx, JSObject *obj, uint32_t index, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_SetArrayLength(JSContext *cx, JS::Handle obj, uint32_t length); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnElement(JSContext *cx, JSObject *obj, uint32_t index, bool *foundp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasElement(JSContext *cx, JSObject *obj, uint32_t index, bool *foundp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_GetElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_ForwardGetElementTo(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf, - JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetElementTo(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::HandleObject onBehalfOf, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t v); -/* - * Get the property with name given by |index|, if it has one. If - * not, |*present| will be set to false and the value of |vp| must not - * be relied on. - */ extern JS_PUBLIC_API(bool) -JS_GetElementIfPresent(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf, - JS::MutableHandle vp, bool* present); +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t v); extern JS_PUBLIC_API(bool) -JS_SetElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double v); extern JS_PUBLIC_API(bool) -JS_DeleteElement(JSContext *cx, JSObject *obj, uint32_t index); +JS_DeleteElement(JSContext *cx, JS::HandleObject obj, uint32_t index); extern JS_PUBLIC_API(bool) -JS_DeleteElement2(JSContext *cx, JSObject *obj, uint32_t index, bool *succeeded); +JS_DeleteElement2(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded); /* * Remove all configurable properties from the given (non-global) object and * assign undefined to all writable data properties. */ JS_PUBLIC_API(void) -JS_ClearNonGlobalObject(JSContext *cx, JSObject *objArg); +JS_ClearNonGlobalObject(JSContext *cx, JS::HandleObject obj); /* * Assign 'undefined' to all of the object's non-reserved slots. Note: this is @@ -3077,48 +3243,64 @@ JS_PUBLIC_API(void) JS_SetAllNonReservedSlotsToUndefined(JSContext *cx, JSObject *objArg); /* - * Create a new array buffer with the given contents, which must have been - * returned by JS_AllocateArrayBufferContents or JS_StealArrayBufferContents. - * The new array buffer takes ownership. After calling this function, do not - * free |contents| or use |contents| from another thread. + * Create a new array buffer with the given contents. On success, the ownership + * is transferred to the new array buffer. */ extern JS_PUBLIC_API(JSObject *) -JS_NewArrayBufferWithContents(JSContext *cx, void *contents); +JS_NewArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); /* * Steal the contents of the given array buffer. The array buffer has its * length set to 0 and its contents array cleared. The caller takes ownership - * of |*contents| and must free it or transfer ownership via + * of the return value and must free it or transfer ownership via * JS_NewArrayBufferWithContents when done using it. - * To free |*contents|, call free(). - * A pointer to the buffer's data is returned in |*data|. This pointer can - * be used until |*contents| is freed or has its ownership transferred. */ -extern JS_PUBLIC_API(bool) -JS_StealArrayBufferContents(JSContext *cx, JS::HandleObject obj, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_StealArrayBufferContents(JSContext *cx, JS::HandleObject obj); /* * Allocate memory that may be eventually passed to - * JS_NewArrayBufferWithContents. |nbytes| is the number of payload bytes - * required. The pointer to pass to JS_NewArrayBufferWithContents is returned - * in |contents|. The pointer to the |nbytes| of usable memory is returned in - * |data|. (*|contents| will contain a header before |data|.) The only legal - * operations on *|contents| is to free it, or pass it to - * JS_NewArrayBufferWithContents or JS_ReallocateArrayBufferContents. + * JS_NewArrayBufferWithContents. |maybecx| is optional; if a non-nullptr cx is + * given, it will be used for memory accounting and OOM reporting. |nbytes| is + * the number of payload bytes required. */ -extern JS_PUBLIC_API(bool) -JS_AllocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_AllocateArrayBufferContents(JSContext *maybecx, uint32_t nbytes); /* * Reallocate memory allocated by JS_AllocateArrayBufferContents, growing or - * shrinking it as appropriate. The new data pointer will be returned in data. - * If *contents is nullptr, behaves like JS_AllocateArrayBufferContents. + * shrinking it as appropriate. If oldContents is null then this behaves like + * JS_AllocateArrayBufferContents. */ -extern JS_PUBLIC_API(bool) -JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void *oldContents, uint32_t oldNbytes); + +/* + * Create a new mapped array buffer with the given memory mapped contents. On success, + * the ownership is transferred to the new mapped array buffer. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewMappedArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); + +/* + * Create memory mapped array buffer contents. + * Caller must take care of closing fd after calling this function. + */ +extern JS_PUBLIC_API(void *) +JS_CreateMappedArrayBufferContents(int fd, size_t offset, size_t length); + +/* + * Release the allocated resource of mapped array buffer contents before the + * object is created. + * If a new object has been created by JS_NewMappedArrayBufferWithContents() + * with this content, then JS_NeuterArrayBuffer() should be used instead to + * release the resource used by the object. + */ +extern JS_PUBLIC_API(void) +JS_ReleaseMappedArrayBufferContents(void *contents, size_t length); extern JS_PUBLIC_API(JSIdArray *) -JS_Enumerate(JSContext *cx, JSObject *obj); +JS_Enumerate(JSContext *cx, JS::HandleObject obj); /* * Create an object to iterate over enumerable properties of obj, in arbitrary @@ -3126,7 +3308,7 @@ JS_Enumerate(JSContext *cx, JSObject *obj); * order, which uses order of property definition in obj. */ extern JS_PUBLIC_API(JSObject *) -JS_NewPropertyIterator(JSContext *cx, JSObject *obj); +JS_NewPropertyIterator(JSContext *cx, JS::Handle obj); /* * Return true on success with *idp containing the id of the next enumerable @@ -3134,11 +3316,7 @@ JS_NewPropertyIterator(JSContext *cx, JSObject *obj); * left to visit. Return false on error. */ extern JS_PUBLIC_API(bool) -JS_NextProperty(JSContext *cx, JSObject *iterobj, jsid *idp); - -extern JS_PUBLIC_API(bool) -JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, - jsval *vp, unsigned *attrsp); +JS_NextProperty(JSContext *cx, JS::Handle iterobj, jsid *idp); extern JS_PUBLIC_API(jsval) JS_GetReservedSlot(JSObject *obj, uint32_t index); @@ -3148,84 +3326,12 @@ JS_SetReservedSlot(JSObject *obj, uint32_t index, jsval v); /************************************************************************/ -/* - * Security protocol. - */ -struct JSPrincipals { - /* Don't call "destroy"; use reference counting macros below. */ -#ifdef JS_THREADSAFE - mozilla::Atomic refcount; -#else - int32_t refcount; -#endif - -#ifdef DEBUG - /* A helper to facilitate principals debugging. */ - uint32_t debugToken; -#endif - - void setDebugToken(uint32_t token) { -# ifdef DEBUG - debugToken = token; -# endif - } - - /* - * This is not defined by the JS engine but should be provided by the - * embedding. - */ - JS_PUBLIC_API(void) dump(); -}; - -extern JS_PUBLIC_API(void) -JS_HoldPrincipals(JSPrincipals *principals); - -extern JS_PUBLIC_API(void) -JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals); - -struct JSSecurityCallbacks { - JSCheckAccessOp checkObjectAccess; - JSCSPEvalChecker contentSecurityPolicyAllows; - JSSubsumesOp subsumes; -}; - -extern JS_PUBLIC_API(void) -JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks); - -extern JS_PUBLIC_API(const JSSecurityCallbacks *) -JS_GetSecurityCallbacks(JSRuntime *rt); - -/* - * Code running with "trusted" principals will be given a deeper stack - * allocation than ordinary scripts. This allows trusted script to run after - * untrusted script has exhausted the stack. This function sets the - * runtime-wide trusted principal. - * - * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since - * there is no available JSContext. Instead, the caller must ensure that the - * given principals stays valid for as long as 'rt' may point to it. If the - * principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be - * called again, passing nullptr for 'prin'. - */ -extern JS_PUBLIC_API(void) -JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin); - -/* - * Initialize the callback that is called to destroy JSPrincipals instance - * when its reference counter drops to zero. The initialization can be done - * only once per JS runtime. - */ -extern JS_PUBLIC_API(void) -JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals); - -/************************************************************************/ - /* * Functions and scripts. */ extern JS_PUBLIC_API(JSFunction *) JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, - JSObject *parent, const char *name); + JS::Handle parent, const char *name); /* * Create the function with the name given by the id. JSID_IS_STRING(id) must @@ -3233,12 +3339,13 @@ JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, */ extern JS_PUBLIC_API(JSFunction *) JS_NewFunctionById(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, - JSObject *parent, jsid id); + JS::Handle parent, JS::Handle id); namespace JS { extern JS_PUBLIC_API(JSFunction *) -GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, jsid id, unsigned nargs); +GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, JS::Handle id, + unsigned nargs); } /* namespace JS */ @@ -3295,22 +3402,22 @@ JS_IsConstructor(JSFunction *fun); * If |callable| is not callable, will throw and return nullptr. */ extern JS_PUBLIC_API(JSObject*) -JS_BindCallable(JSContext *cx, JSObject *callable, JSObject *newThis); +JS_BindCallable(JSContext *cx, JS::Handle callable, JS::Handle newThis); extern JS_PUBLIC_API(bool) -JS_DefineFunctions(JSContext *cx, JSObject *obj, const JSFunctionSpec *fs); +JS_DefineFunctions(JSContext *cx, JS::Handle obj, const JSFunctionSpec *fs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call, +JS_DefineFunction(JSContext *cx, JS::Handle obj, const char *name, JSNative call, unsigned nargs, unsigned attrs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineUCFunction(JSContext *cx, JSObject *obj, +JS_DefineUCFunction(JSContext *cx, JS::Handle obj, const jschar *name, size_t namelen, JSNative call, unsigned nargs, unsigned attrs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call, +JS_DefineFunctionById(JSContext *cx, JS::Handle obj, JS::Handle id, JSNative call, unsigned nargs, unsigned attrs); /* @@ -3318,7 +3425,7 @@ JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call, * fail if funobj was lexically nested inside some other function. */ extern JS_PUBLIC_API(JSObject *) -JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent); +JS_CloneFunctionObject(JSContext *cx, JS::Handle funobj, JS::Handle parent); /* * Given a buffer, return false if the buffer might become a valid @@ -3328,32 +3435,49 @@ JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent); * the compiler. */ extern JS_PUBLIC_API(bool) -JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj, const char *utf8, size_t length); +JS_BufferIsCompilableUnit(JSContext *cx, JS::Handle obj, const char *utf8, + size_t length); -extern JS_PUBLIC_API(JSScript *) +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileScript(JSContext *cx, JS::HandleObject obj, const char *ascii, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileUCScript(JSContext *cx, JS::HandleObject obj, const jschar *chars, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleScript script); extern JS_PUBLIC_API(JSObject *) JS_GetGlobalFromScript(JSScript *script); -extern JS_PUBLIC_API(JSFunction *) +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileFunction(JSContext *cx, JS::HandleObject obj, const char *name, unsigned nargs, const char *const *argnames, const char *bytes, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); -extern JS_PUBLIC_API(JSFunction *) +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileUCFunction(JSContext *cx, JS::HandleObject obj, const char *name, unsigned nargs, const char *const *argnames, const jschar *chars, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); namespace JS { @@ -3401,12 +3525,14 @@ namespace JS { * is protected anyway); instead, create instances only of the derived classes: * CompileOptions and OwningCompileOptions. */ -class JS_PUBLIC_API(ReadOnlyCompileOptions) +class JS_FRIEND_API(ReadOnlyCompileOptions) { + friend class CompileOptions; + protected: - JSPrincipals *principals_; JSPrincipals *originPrincipals_; const char *filename_; + const char *introducerFilename_; const jschar *sourceMapURL_; // This constructor leaves 'version' set to JSVERSION_UNKNOWN. The structure @@ -3414,9 +3540,9 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) // classes' constructors take care of that, in ways appropriate to their // purpose. ReadOnlyCompileOptions() - : principals_(nullptr), - originPrincipals_(nullptr), + : originPrincipals_(nullptr), filename_(nullptr), + introducerFilename_(nullptr), sourceMapURL_(nullptr), version(JSVERSION_UNKNOWN), versionSet(false), @@ -3425,6 +3551,7 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) column(0), compileAndGo(false), forEval(false), + defineOnScope(true), noScriptRval(false), selfHostingMode(false), canLazilyParse(true), @@ -3433,7 +3560,12 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) werrorOption(false), asmJSOption(false), forceAsync(false), - sourcePolicy(SAVE_SOURCE) + installedFile(false), + sourceIsLazy(false), + introductionType(nullptr), + introductionLineno(0), + introductionOffset(0), + hasIntroductionInfo(false) { } // Set all POD options (those not requiring reference counts, copies, @@ -3443,12 +3575,13 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) public: // Read-only accessors for non-POD options. The proper way to set these // depends on the derived type. - JSPrincipals *principals() const { return principals_; } - JSPrincipals *originPrincipals() const; + JSPrincipals *originPrincipals(js::ExclusiveContext *cx) const; const char *filename() const { return filename_; } + const char *introducerFilename() const { return introducerFilename_; } const jschar *sourceMapURL() const { return sourceMapURL_; } virtual JSObject *element() const = 0; - virtual JSString *elementProperty() const = 0; + virtual JSString *elementAttributeName() const = 0; + virtual JSScript *introductionScript() const = 0; // POD options. JSVersion version; @@ -3458,6 +3591,7 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) unsigned column; bool compileAndGo; bool forEval; + bool defineOnScope; bool noScriptRval; bool selfHostingMode; bool canLazilyParse; @@ -3466,11 +3600,15 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) bool werrorOption; bool asmJSOption; bool forceAsync; - enum SourcePolicy { - NO_SOURCE, - LAZY_SOURCE, - SAVE_SOURCE - } sourcePolicy; + bool installedFile; // 'true' iff pre-compiling js file in packaged app + bool sourceIsLazy; + + // |introductionType| is a statically allocated C string: + // one of "eval", "Function", or "GeneratorFunction". + const char *introductionType; + unsigned introductionLineno; + uint32_t introductionOffset; + bool hasIntroductionInfo; private: static JSObject * const nullObjectPtr; @@ -3490,11 +3628,12 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) * comes to refer to the object that owns this, then the whole cycle, and * anything else it entrains, will never be freed. */ -class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions +class JS_FRIEND_API(OwningCompileOptions) : public ReadOnlyCompileOptions { JSRuntime *runtime; PersistentRootedObject elementRoot; - PersistentRootedString elementPropertyRoot; + PersistentRootedString elementAttributeNameRoot; + PersistentRootedScript introductionScriptRoot; public: // A minimal constructor, for use with OwningCompileOptions::copy. This @@ -3505,22 +3644,30 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions ~OwningCompileOptions(); JSObject *element() const MOZ_OVERRIDE { return elementRoot; } - JSString *elementProperty() const MOZ_OVERRIDE { return elementPropertyRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } // Set this to a copy of |rhs|. Return false on OOM. bool copy(JSContext *cx, const ReadOnlyCompileOptions &rhs); /* These setters make copies of their string arguments, and are fallible. */ + bool setFile(JSContext *cx, const char *f); bool setFileAndLine(JSContext *cx, const char *f, unsigned l); bool setSourceMapURL(JSContext *cx, const jschar *s); + bool setIntroducerFilename(JSContext *cx, const char *s); /* These setters are infallible, and can be chained. */ - OwningCompileOptions &setElement(JSObject *e) { elementRoot = e; return *this; } - OwningCompileOptions &setElementProperty(JSString *p) { elementPropertyRoot = p; return *this; } - OwningCompileOptions &setPrincipals(JSPrincipals *p) { - if (p) JS_HoldPrincipals(p); - if (principals_) JS_DropPrincipals(runtime, principals_); - principals_ = p; + OwningCompileOptions &setLine(unsigned l) { lineno = l; return *this; } + OwningCompileOptions &setElement(JSObject *e) { + elementRoot = e; + return *this; + } + OwningCompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + OwningCompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; return *this; } OwningCompileOptions &setOriginPrincipals(JSPrincipals *p) { @@ -3538,10 +3685,27 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions OwningCompileOptions &setColumn(unsigned c) { column = c; return *this; } OwningCompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } OwningCompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + OwningCompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } OwningCompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } OwningCompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } OwningCompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } - OwningCompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; } + OwningCompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + OwningCompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + bool setIntroductionInfo(JSContext *cx, const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + if (!setIntroducerFilename(cx, introducerFn)) + return false; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return true; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; }; /* @@ -3551,36 +3715,47 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions * create an instance of this type, it's up to you to guarantee that * everything you store in it will outlive it. */ -class MOZ_STACK_CLASS JS_PUBLIC_API(CompileOptions) : public ReadOnlyCompileOptions +class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOptions { RootedObject elementRoot; - RootedString elementPropertyRoot; + RootedString elementAttributeNameRoot; + RootedScript introductionScriptRoot; public: explicit CompileOptions(JSContext *cx, JSVersion version = JSVERSION_UNKNOWN); CompileOptions(js::ContextFriendFields *cx, const ReadOnlyCompileOptions &rhs) - : ReadOnlyCompileOptions(), elementRoot(cx), elementPropertyRoot(cx) + : ReadOnlyCompileOptions(), elementRoot(cx), elementAttributeNameRoot(cx), + introductionScriptRoot(cx) { copyPODOptions(rhs); - principals_ = rhs.principals(); - originPrincipals_ = rhs.originPrincipals(); + originPrincipals_ = rhs.originPrincipals_; filename_ = rhs.filename(); sourceMapURL_ = rhs.sourceMapURL(); elementRoot = rhs.element(); - elementPropertyRoot = rhs.elementProperty(); + elementAttributeNameRoot = rhs.elementAttributeName(); + introductionScriptRoot = rhs.introductionScript(); } JSObject *element() const MOZ_OVERRIDE { return elementRoot; } - JSString *elementProperty() const MOZ_OVERRIDE { return elementPropertyRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } + CompileOptions &setFile(const char *f) { filename_ = f; return *this; } + CompileOptions &setLine(unsigned l) { lineno = l; return *this; } CompileOptions &setFileAndLine(const char *f, unsigned l) { filename_ = f; lineno = l; return *this; } CompileOptions &setSourceMapURL(const jschar *s) { sourceMapURL_ = s; return *this; } CompileOptions &setElement(JSObject *e) { elementRoot = e; return *this; } - CompileOptions &setElementProperty(JSString *p) { elementPropertyRoot = p; return *this; } - CompileOptions &setPrincipals(JSPrincipals *p) { principals_ = p; return *this; } + CompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + CompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; + return *this; + } CompileOptions &setOriginPrincipals(JSPrincipals *p) { originPrincipals_ = p; return *this; @@ -3594,25 +3769,50 @@ class MOZ_STACK_CLASS JS_PUBLIC_API(CompileOptions) : public ReadOnlyCompileOpti CompileOptions &setColumn(unsigned c) { column = c; return *this; } CompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } CompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + CompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } CompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } CompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } CompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } - CompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; } + CompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + CompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + CompileOptions &setIntroductionInfo(const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + introducerFilename_ = introducerFn; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return *this; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; }; -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *bytes, size_t length); +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const jschar *chars, size_t length); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, FILE *file); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, const char *filename); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, FILE *file, + JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *filename, + JS::MutableHandleScript script); extern JS_PUBLIC_API(bool) CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t length); @@ -3625,8 +3825,8 @@ CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t * for the compilation. The callback will be invoked while off the main thread, * so must ensure that its operations are thread safe. Afterwards, * FinishOffThreadScript must be invoked on the main thread to get the result - * script or nullptr. If maybecx is specified, this method will also report - * any error or warnings generated during the parse. + * script or nullptr. If maybecx is not specified, the resources will be freed, + * but no script will be returned. * * The characters passed in to CompileOffThread must remain live until the * callback is invoked, and the resulting script will be rooted until the call @@ -3634,27 +3834,32 @@ CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t */ extern JS_PUBLIC_API(bool) -CompileOffThread(JSContext *cx, Handle obj, const ReadOnlyCompileOptions &options, +CompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, const jschar *chars, size_t length, OffThreadCompileCallback callback, void *callbackData); extern JS_PUBLIC_API(JSScript *) FinishOffThreadScript(JSContext *maybecx, JSRuntime *rt, void *token); -extern JS_PUBLIC_API(JSFunction *) -CompileFunction(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *name, unsigned nargs, const char *const *argnames, - const char *bytes, size_t length); + SourceBufferHolder &srcBuf, JS::MutableHandleFunction fun); -extern JS_PUBLIC_API(JSFunction *) -CompileFunction(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *name, unsigned nargs, const char *const *argnames, + const char *bytes, size_t length, JS::MutableHandleFunction fun); + +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *name, unsigned nargs, const char *const *argnames, - const jschar *chars, size_t length); + const jschar *chars, size_t length, JS::MutableHandleFunction fun); } /* namespace JS */ extern JS_PUBLIC_API(JSString *) -JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned indent); +JS_DecompileScript(JSContext *cx, JS::Handle script, const char *name, unsigned indent); /* * API extension: OR this into indent to avoid pretty-printing the decompiled @@ -3663,10 +3868,10 @@ JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned i #define JS_DONT_PRETTY_PRINT ((unsigned)0x8000) extern JS_PUBLIC_API(JSString *) -JS_DecompileFunction(JSContext *cx, JSFunction *fun, unsigned indent); +JS_DecompileFunction(JSContext *cx, JS::Handle fun, unsigned indent); extern JS_PUBLIC_API(JSString *) -JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, unsigned indent); +JS_DecompileFunctionBody(JSContext *cx, JS::Handle fun, unsigned indent); /* * NB: JS_ExecuteScript and the JS_Evaluate*Script* quadruplets use the obj @@ -3702,158 +3907,159 @@ JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, unsigned indent); * etc., entry points. */ extern JS_PUBLIC_API(bool) -JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval); +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval, - JSVersion version); +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script); + +namespace JS { /* - * Execute either the function-defining prolog of a script, or the script's - * main body, but not both. + * Like the above, but handles a cross-compartment script. If the script is + * cross-compartment, it is cloned into the current compartment before executing. */ -typedef enum JSExecPart { JSEXEC_PROLOG, JSEXEC_MAIN } JSExecPart; +extern JS_PUBLIC_API(bool) +CloneAndExecuteScript(JSContext *cx, JS::Handle obj, JS::Handle script); + +} /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_EvaluateScript(JSContext *cx, JSObject *obj, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleValue rval, JSVersion version); + +extern JS_PUBLIC_API(bool) +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JSVersion version); extern JS_PUBLIC_API(bool) -JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_EvaluateScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno); extern JS_PUBLIC_API(bool) -JS_EvaluateUCScript(JSContext *cx, JSObject *obj, +JS_EvaluateUCScript(JSContext *cx, JS::Handle obj, const jschar *chars, unsigned length, const char *filename, unsigned lineno, - jsval *rval); + JS::MutableHandle rval); + +namespace JS { extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleValue rval); -/* - * JSAPI clients may optionally specify the 'originPrincipals' of a script. - * A script's originPrincipals may be retrieved through the debug API (via - * JS_GetScriptOriginPrincipals) and the originPrincipals are transitively - * assigned to any nested scripts (including scripts dynamically created via - * eval and the Function constructor). If originPrincipals is null, then the - * value of principals is used as origin principals for the script. - */ extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipalsVersionOrigin(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - JSPrincipals *originPrincipals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleValue rval); -namespace JS { +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const jschar *chars, size_t length, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *bytes, size_t length, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *filename, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename); } /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunction(JSContext *cx, JS::HandleObject obj, JS::HandleFunction fun, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunctionName(JSContext *cx, JS::HandleObject obj, const char *name, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunctionValue(JSContext *cx, JS::HandleObject obj, JS::HandleValue fval, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); namespace JS { static inline bool -Call(JSContext *cx, JSObject *thisObj, JSFunction *fun, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleFunction fun, + const JS::HandleValueArray &args, MutableHandleValue rval) { - return !!JS_CallFunction(cx, thisObj, fun, argc, argv, rval.address()); + return !!JS_CallFunction(cx, thisObj, fun, args, rval); } static inline bool -Call(JSContext *cx, JSObject *thisObj, const char *name, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, const char *name, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return !!JS_CallFunctionName(cx, thisObj, name, argc, argv, rval.address()); + return !!JS_CallFunctionName(cx, thisObj, name, args, rval); } static inline bool -Call(JSContext *cx, JSObject *thisObj, jsval fun, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return !!JS_CallFunctionValue(cx, thisObj, fun, argc, argv, rval.address()); + return !!JS_CallFunctionValue(cx, thisObj, fun, args, rval); } extern JS_PUBLIC_API(bool) -Call(JSContext *cx, jsval thisv, jsval fun, unsigned argc, jsval *argv, MutableHandle rval); +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval); static inline bool -Call(JSContext *cx, jsval thisv, JSObject *funObj, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleObject funObj, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return Call(cx, thisv, OBJECT_TO_JSVAL(funObj), argc, argv, rval); + JS_ASSERT(funObj); + JS::RootedValue fun(cx, JS::ObjectValue(*funObj)); + return Call(cx, thisv, fun, args, rval); } +extern JS_PUBLIC_API(bool) +Construct(JSContext *cx, JS::HandleValue fun, + const JS::HandleValueArray& args, + MutableHandleValue rval); + } /* namespace JS */ /* - * These functions allow setting an operation callback that will be called + * These functions allow setting an interrupt callback that will be called * from the JS thread some time after any thread triggered the callback using - * JS_TriggerOperationCallback(rt). + * JS_RequestInterruptCallback(rt). * * To schedule the GC and for other activities the engine internally triggers - * operation callbacks. The embedding should thus not rely on callbacks being + * interrupt callbacks. The embedding should thus not rely on callbacks being * triggered through the external API only. * * Important note: Additional callbacks can occur inside the callback handler * if it re-enters the JS engine. The embedding must ensure that the callback * is disconnected before attempting such re-entry. */ -extern JS_PUBLIC_API(JSOperationCallback) -JS_SetOperationCallback(JSRuntime *rt, JSOperationCallback callback); +extern JS_PUBLIC_API(JSInterruptCallback) +JS_SetInterruptCallback(JSRuntime *rt, JSInterruptCallback callback); -extern JS_PUBLIC_API(JSOperationCallback) -JS_GetOperationCallback(JSRuntime *rt); +extern JS_PUBLIC_API(JSInterruptCallback) +JS_GetInterruptCallback(JSRuntime *rt); extern JS_PUBLIC_API(void) -JS_TriggerOperationCallback(JSRuntime *rt); +JS_RequestInterruptCallback(JSRuntime *rt); extern JS_PUBLIC_API(bool) JS_IsRunning(JSContext *cx); @@ -3878,7 +4084,7 @@ JS_RestoreFrameChain(JSContext *cx); #ifdef MOZ_TRACE_JSCALLS /* * The callback is expected to be quick and noninvasive. It should not - * trigger interrupts, turn on debugging, or produce uncaught JS + * request interrupts, turn on debugging, or produce uncaught JS * exceptions. The state of the stack and registers in the context * cannot be relied upon, since this callback may be invoked directly * from either JIT. The 'entering' field means we are entering a @@ -3953,15 +4159,16 @@ JS_FileEscapedString(FILE *fp, JSString *str, char quote); * special cases where getting the chars is infallible: * * The first case is interned strings, i.e., strings from JS_InternString or - * JSID_TO_STRING(id), using JS_GetInternedStringChars*. + * JSID_TO_STRING(id), using JS_GetLatin1InternedStringChars or + * JS_GetTwoByteInternedStringChars. * * The second case is "flat" strings that have been explicitly prepared in a * fallible context by JS_FlattenString. To catch errors, a separate opaque * JSFlatString type is returned by JS_FlattenString and expected by * JS_GetFlatStringChars. Note, though, that this is purely a syntactic * distinction: the input and output of JS_FlattenString are the same actual - * GC-thing so only one needs to be rooted. If a JSString is known to be flat, - * JS_ASSERT_STRING_IS_FLAT can be used to make a debug-checked cast. Example: + * GC-thing. If a JSString is known to be flat, JS_ASSERT_STRING_IS_FLAT can be + * used to make a debug-checked cast. Example: * * // in a fallible context * JSFlatString *fstr = JS_FlattenString(cx, str); @@ -3970,55 +4177,80 @@ JS_FileEscapedString(FILE *fp, JSString *str, char quote); * JS_ASSERT(fstr == JS_ASSERT_STRING_IS_FLAT(str)); * * // in an infallible context, for the same 'str' - * const jschar *chars = JS_GetFlatStringChars(fstr) + * AutoCheckCannotGC nogc; + * const jschar *chars = JS_GetTwoByteFlatStringChars(nogc, fstr) * JS_ASSERT(chars); * - * The CharsZ APIs guarantee that the returned array has a null character at - * chars[length]. This can require additional copying so clients should prefer - * APIs without CharsZ if possible. The infallible functions also return - * null-terminated arrays. (There is no additional cost or non-Z alternative - * for the infallible functions, so 'Z' is left out of the identifier.) + * Flat strings and interned strings are always null-terminated, so + * JS_FlattenString can be used to get a null-terminated string. + * + * Additionally, string characters are stored as either Latin1Char (8-bit) + * or jschar (16-bit). Clients can use JS_StringHasLatin1Chars and can then + * call either the Latin1* or TwoByte* functions. Some functions like + * JS_CopyStringChars and JS_GetStringCharAt accept both Latin1 and TwoByte + * strings. */ extern JS_PUBLIC_API(size_t) JS_GetStringLength(JSString *str); -extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsAndLength(JSContext *cx, JSString *str, size_t *length); +extern JS_PUBLIC_API(bool) +JS_StringIsFlat(JSString *str); -extern JS_PUBLIC_API(const jschar *) -JS_GetInternedStringChars(JSString *str); +/* Returns true iff the string's characters are stored as Latin1. */ +extern JS_PUBLIC_API(bool) +JS_StringHasLatin1Chars(JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1StringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); extern JS_PUBLIC_API(const jschar *) -JS_GetInternedStringCharsAndLength(JSString *str, size_t *length); +JS_GetTwoByteStringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); + +extern JS_PUBLIC_API(bool) +JS_GetStringCharAt(JSContext *cx, JSString *str, size_t index, jschar *res); + +extern JS_PUBLIC_API(jschar) +JS_GetFlatStringCharAt(JSFlatString *str, size_t index); extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsZ(JSContext *cx, JSString *str); +JS_GetTwoByteExternalStringChars(JSString *str); + +extern JS_PUBLIC_API(bool) +JS_CopyStringChars(JSContext *cx, mozilla::Range dest, JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1InternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsZAndLength(JSContext *cx, JSString *str, size_t *length); +JS_GetTwoByteInternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); extern JS_PUBLIC_API(JSFlatString *) JS_FlattenString(JSContext *cx, JSString *str); +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1FlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); + extern JS_PUBLIC_API(const jschar *) -JS_GetFlatStringChars(JSFlatString *str); +JS_GetTwoByteFlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); -static JS_ALWAYS_INLINE JSFlatString * +static MOZ_ALWAYS_INLINE JSFlatString * JSID_TO_FLAT_STRING(jsid id) { JS_ASSERT(JSID_IS_STRING(id)); return (JSFlatString *)(JSID_BITS(id)); } -static JS_ALWAYS_INLINE JSFlatString * +static MOZ_ALWAYS_INLINE JSFlatString * JS_ASSERT_STRING_IS_FLAT(JSString *str) { - JS_ASSERT(JS_GetFlatStringChars((JSFlatString *)str)); + JS_ASSERT(JS_StringIsFlat(str)); return (JSFlatString *)str; } -static JS_ALWAYS_INLINE JSString * +static MOZ_ALWAYS_INLINE JSString * JS_FORGET_STRING_FLATNESS(JSFlatString *fstr) { return (JSString *)fstr; @@ -4078,7 +4310,7 @@ JS_EncodeString(JSContext *cx, JSString *str); * Same behavior as JS_EncodeString(), but encode into UTF-8 string */ JS_PUBLIC_API(char *) -JS_EncodeStringToUTF8(JSContext *cx, JSString *str); +JS_EncodeStringToUTF8(JSContext *cx, JS::HandleString str); /* * Get number of bytes in the string encoding (without accounting for a @@ -4110,7 +4342,7 @@ class JSAutoByteString MOZ_GUARD_OBJECT_NOTIFIER_INIT; } - JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + explicit JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) : mBytes(nullptr) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -4135,7 +4367,7 @@ class JSAutoByteString char *encodeLatin1(js::ExclusiveContext *cx, JSString *str); - char *encodeUtf8(JSContext *cx, JSString *str) { + char *encodeUtf8(JSContext *cx, JS::HandleString str) { JS_ASSERT(!mBytes); JS_ASSERT(cx); mBytes = JS_EncodeStringToUTF8(cx, str); @@ -4170,6 +4402,84 @@ class JSAutoByteString JSAutoByteString &operator=(const JSAutoByteString &another); }; +namespace JS { + +extern JS_PUBLIC_API(JSAddonId *) +NewAddonId(JSContext *cx, JS::HandleString str); + +extern JS_PUBLIC_API(JSString *) +StringOfAddonId(JSAddonId *id); + +extern JS_PUBLIC_API(JSAddonId *) +AddonIdOfObject(JSObject *obj); + +} // namespace JS + +/************************************************************************/ +/* + * Symbols + */ + +namespace JS { + +/* + * Create a new Symbol with the given description. This function never returns + * a Symbol that is in the Runtime-wide symbol registry. + * + * If description is null, the new Symbol's [[Description]] attribute is + * undefined. + */ +JS_PUBLIC_API(Symbol *) +NewSymbol(JSContext *cx, HandleString description); + +/* + * Symbol.for as specified in ES6. + * + * Get a Symbol with the description 'key' from the Runtime-wide symbol registry. + * If there is not already a Symbol with that description in the registry, a new + * Symbol is created and registered. 'key' must not be null. + */ +JS_PUBLIC_API(Symbol *) +GetSymbolFor(JSContext *cx, HandleString key); + +/* + * Get the [[Description]] attribute of the given symbol. + * + * This function is infallible. If it returns null, that means the symbol's + * [[Description]] is undefined. + */ +JS_PUBLIC_API(JSString *) +GetSymbolDescription(HandleSymbol symbol); + +/* Well-known symbols. */ +MOZ_BEGIN_ENUM_CLASS(SymbolCode, uint32_t) + iterator, // well-known Symbol.iterator + InSymbolRegistry = 0xfffffffe, // created by Symbol.for() or JS::GetSymbolFor() + UniqueSymbol = 0xffffffff // created by Symbol() or JS::NewSymbol() +MOZ_END_ENUM_CLASS(SymbolCode) + +/* For use in loops that iterate over the well-known symbols. */ +const size_t WellKnownSymbolLimit = 1; + +/* + * Return the SymbolCode telling what sort of symbol `symbol` is. + * + * A symbol's SymbolCode never changes once it is created. + */ +JS_PUBLIC_API(SymbolCode) +GetSymbolCode(Handle symbol); + +/* + * Get one of the well-known symbols defined by ES6. A single set of well-known + * symbols is shared by all compartments in a JSRuntime. + * + * `which` must be in the range [0, WellKnownSymbolLimit). + */ +JS_PUBLIC_API(Symbol *) +GetWellKnownSymbol(JSContext *cx, SymbolCode which); + +} /* namespace JS */ + /************************************************************************/ /* * JSON functions @@ -4189,10 +4499,17 @@ JS_Stringify(JSContext *cx, JS::MutableHandleValue value, JS::HandleObject repla JS_PUBLIC_API(bool) JS_ParseJSON(JSContext *cx, const jschar *chars, uint32_t len, JS::MutableHandleValue vp); +JS_PUBLIC_API(bool) +JS_ParseJSON(JSContext *cx, JS::HandleString str, JS::MutableHandleValue vp); + JS_PUBLIC_API(bool) JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32_t len, JS::HandleValue reviver, JS::MutableHandleValue vp); +JS_PUBLIC_API(bool) +JS_ParseJSONWithReviver(JSContext *cx, JS::HandleString str, JS::HandleValue reviver, + JS::MutableHandleValue vp); + /************************************************************************/ /* @@ -4219,7 +4536,6 @@ struct JSLocaleCallbacks { JSLocaleToLowerCase localeToLowerCase; JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API JSLocaleToUnicode localeToUnicode; - JSErrorCallback localeGetErrorMessage; }; /* @@ -4357,8 +4673,35 @@ JS_GetErrorReporter(JSContext *cx); extern JS_PUBLIC_API(JSErrorReporter) JS_SetErrorReporter(JSContext *cx, JSErrorReporter er); +namespace JS { + +extern JS_PUBLIC_API(bool) +CreateError(JSContext *cx, JSExnType type, HandleString stack, + HandleString fileName, uint32_t lineNumber, uint32_t columnNumber, + JSErrorReport *report, HandleString message, MutableHandleValue rval); + /************************************************************************/ +/* + * Weak Maps. + */ + +extern JS_PUBLIC_API(JSObject *) +NewWeakMapObject(JSContext *cx); + +extern JS_PUBLIC_API(bool) +IsWeakMapObject(JSObject *obj); + +extern JS_PUBLIC_API(bool) +GetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::MutableHandleValue val); + +extern JS_PUBLIC_API(bool) +SetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::HandleValue val); + +} /* namespace JS */ + /* * Dates. */ @@ -4387,10 +4730,10 @@ JS_ClearDateCaches(JSContext *cx); /* * Regular Expressions. */ -#define JSREG_FOLD 0x01 /* fold uppercase to lowercase */ -#define JSREG_GLOB 0x02 /* global exec, creates array of matches */ -#define JSREG_MULTILINE 0x04 /* treat ^ and $ as begin and end of line */ -#define JSREG_STICKY 0x08 /* only match starting at lastIndex */ +#define JSREG_FOLD 0x01u /* fold uppercase to lowercase */ +#define JSREG_GLOB 0x02u /* global exec, creates array of matches */ +#define JSREG_MULTILINE 0x04u /* treat ^ and $ as begin and end of line */ +#define JSREG_STICKY 0x08u /* only match starting at lastIndex */ extern JS_PUBLIC_API(JSObject *) JS_NewRegExpObject(JSContext *cx, JS::HandleObject obj, char *bytes, size_t length, @@ -4400,11 +4743,11 @@ extern JS_PUBLIC_API(JSObject *) JS_NewUCRegExpObject(JSContext *cx, JS::HandleObject obj, jschar *chars, size_t length, unsigned flags); -extern JS_PUBLIC_API(void) +extern JS_PUBLIC_API(bool) JS_SetRegExpInput(JSContext *cx, JS::HandleObject obj, JS::HandleString input, bool multiline); -extern JS_PUBLIC_API(void) +extern JS_PUBLIC_API(bool) JS_ClearRegExpStatics(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) @@ -4450,17 +4793,62 @@ JS_ClearPendingException(JSContext *cx); extern JS_PUBLIC_API(bool) JS_ReportPendingException(JSContext *cx); +namespace JS { + /* - * Save the current exception state. This takes a snapshot of cx's current - * exception state without making any change to that state. + * Save and later restore the current exception state of a given JSContext. + * This is useful for implementing behavior in C++ that's like try/catch + * or try/finally in JS. * - * The returned state pointer MUST be passed later to JS_RestoreExceptionState - * (to restore that saved state, overriding any more recent state) or else to - * JS_DropExceptionState (to free the state struct in case it is not correct - * or desirable to restore it). Both Restore and Drop free the state struct, - * so callers must stop using the pointer returned from Save after calling the - * Release or Drop API. + * Typical usage: + * + * bool ok = JS_EvaluateScript(cx, ...); + * AutoSaveExceptionState savedExc(cx); + * ... cleanup that might re-enter JS ... + * return ok; */ +class JS_PUBLIC_API(AutoSaveExceptionState) +{ + private: + JSContext *context; + bool wasPropagatingForcedReturn; + bool wasThrowing; + RootedValue exceptionValue; + + public: + /* + * Take a snapshot of cx's current exception state. Then clear any current + * pending exception in cx. + */ + explicit AutoSaveExceptionState(JSContext *cx); + + /* + * If neither drop() nor restore() was called, restore the exception + * state only if no exception is currently pending on cx. + */ + ~AutoSaveExceptionState(); + + /* + * Discard any stored exception state. + * If this is called, the destructor is a no-op. + */ + void drop() { + wasPropagatingForcedReturn = false; + wasThrowing = false; + exceptionValue.setUndefined(); + } + + /* + * Replace cx's exception state with the stored exception state. Then + * discard the stored exception state. If this is called, the + * destructor is a no-op. + */ + void restore(); +}; + +} /* namespace JS */ + +/* Deprecated API. Use AutoSaveExceptionState instead. */ extern JS_PUBLIC_API(JSExceptionState *) JS_SaveExceptionState(JSContext *cx); @@ -4471,22 +4859,14 @@ extern JS_PUBLIC_API(void) JS_DropExceptionState(JSContext *cx, JSExceptionState *state); /* - * If the given value is an exception object that originated from an error, - * the exception will contain an error report struct, and this API will return - * the address of that struct. Otherwise, it returns nullptr. The lifetime + * If the given object is an exception object, the exception will have (or be + * able to lazily create) an error report struct, and this function will return + * the address of that struct. Otherwise, it returns nullptr. The lifetime * of the error report struct that might be returned is the same as the * lifetime of the exception object. */ extern JS_PUBLIC_API(JSErrorReport *) -JS_ErrorFromException(JSContext *cx, JS::HandleValue v); - -/* - * Given a reported error's message and JSErrorReport struct pointer, throw - * the corresponding exception on cx. - */ -extern JS_PUBLIC_API(bool) -JS_ThrowReportedError(JSContext *cx, const char *message, - JSErrorReport *reportp); +JS_ErrorFromException(JSContext *cx, JS::HandleObject obj); /* * Throws a StopIteration exception on cx. @@ -4521,7 +4901,7 @@ JS_AbortIfWrongThread(JSRuntime *rt); * [[Prototype]]. */ extern JS_PUBLIC_API(JSObject *) -JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const jsval *vp); +JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const JS::CallArgs& args); /************************************************************************/ @@ -4536,16 +4916,18 @@ JS_ScheduleGC(JSContext *cx, uint32_t count); #endif extern JS_PUBLIC_API(void) -JS_SetParallelParsingEnabled(JSContext *cx, bool enabled); +JS_SetParallelParsingEnabled(JSRuntime *rt, bool enabled); extern JS_PUBLIC_API(void) -JS_SetParallelIonCompilationEnabled(JSContext *cx, bool enabled); +JS_SetOffthreadIonCompilationEnabled(JSRuntime *rt, bool enabled); -#define JIT_COMPILER_OPTIONS(Register) \ - Register(BASELINE_USECOUNT_TRIGGER, "baseline.usecount.trigger") \ - Register(ION_USECOUNT_TRIGGER, "ion.usecount.trigger") \ - Register(ION_ENABLE, "ion.enable") \ - Register(BASELINE_ENABLE, "baseline.enable") +#define JIT_COMPILER_OPTIONS(Register) \ + Register(BASELINE_USECOUNT_TRIGGER, "baseline.usecount.trigger") \ + Register(ION_USECOUNT_TRIGGER, "ion.usecount.trigger") \ + Register(ION_ENABLE, "ion.enable") \ + Register(BASELINE_ENABLE, "baseline.enable") \ + Register(OFFTHREAD_COMPILATION_ENABLE, "offthread-compilation.enable") \ + Register(SIGNALS_ENABLE, "signals.enable") typedef enum JSJitCompilerOption { #define JIT_COMPILER_DECLARE(key, str) \ @@ -4558,7 +4940,9 @@ typedef enum JSJitCompilerOption { } JSJitCompilerOption; extern JS_PUBLIC_API(void) -JS_SetGlobalJitCompilerOption(JSContext *cx, JSJitCompilerOption opt, uint32_t value); +JS_SetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt, uint32_t value); +extern JS_PUBLIC_API(int) +JS_GetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt); /* * Convert a uint32_t index into a jsid. @@ -4580,13 +4964,80 @@ JS_CharsToId(JSContext* cx, JS::TwoByteChars chars, JS::MutableHandleId); extern JS_PUBLIC_API(bool) JS_IsIdentifier(JSContext *cx, JS::HandleString str, bool *isIdentifier); +namespace JS { + +/* + * AutoFilename encapsulates a pointer to a C-string and keeps the C-string + * alive for as long as the associated AutoFilename object is alive. + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(AutoFilename) +{ + void *scriptSource_; + + AutoFilename(const AutoFilename &) MOZ_DELETE; + void operator=(const AutoFilename &) MOZ_DELETE; + + public: + AutoFilename() : scriptSource_(nullptr) {} + ~AutoFilename() { reset(nullptr); } + + const char *get() const; + + void reset(void *newScriptSource); +}; + /* - * Return the current script and line number of the most currently running + * Return the current filename and line number of the most currently running * frame. Returns true if a scripted frame was found, false otherwise. + * + * If a the embedding has hidden the scripted caller for the topmost activation + * record, this will also return false. */ extern JS_PUBLIC_API(bool) -JS_DescribeScriptedCaller(JSContext *cx, JS::MutableHandleScript script, unsigned *lineno); +DescribeScriptedCaller(JSContext *cx, AutoFilename *filename = nullptr, + unsigned *lineno = nullptr); +extern JS_PUBLIC_API(JSObject *) +GetScriptedCallerGlobal(JSContext *cx); + +/* + * Informs the JS engine that the scripted caller should be hidden. This can be + * used by the embedding to maintain an override of the scripted caller in its + * calculations, by hiding the scripted caller in the JS engine and pushing data + * onto a separate stack, which it inspects when DescribeScriptedCaller returns + * null. + * + * We maintain a counter on each activation record. Add() increments the counter + * of the topmost activation, and Remove() decrements it. The count may never + * drop below zero, and must always be exactly zero when the activation is + * popped from the stack. + */ +extern JS_PUBLIC_API(void) +HideScriptedCaller(JSContext *cx); + +extern JS_PUBLIC_API(void) +UnhideScriptedCaller(JSContext *cx); + +class AutoHideScriptedCaller +{ + public: + explicit AutoHideScriptedCaller(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mContext(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + HideScriptedCaller(mContext); + } + ~AutoHideScriptedCaller() { + UnhideScriptedCaller(mContext); + } + + protected: + JSContext *mContext; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +} /* namespace JS */ /* * Encode/Decode interpreted scripts and functions to/from memory. @@ -4599,12 +5050,11 @@ extern JS_PUBLIC_API(void *) JS_EncodeInterpretedFunction(JSContext *cx, JS::HandleObject funobj, uint32_t *lengthp); extern JS_PUBLIC_API(JSScript *) -JS_DecodeScript(JSContext *cx, const void *data, uint32_t length, - JSPrincipals *principals, JSPrincipals *originPrincipals); +JS_DecodeScript(JSContext *cx, const void *data, uint32_t length, JSPrincipals *originPrincipals); extern JS_PUBLIC_API(JSObject *) JS_DecodeInterpretedFunction(JSContext *cx, const void *data, uint32_t length, - JSPrincipals *principals, JSPrincipals *originPrincipals); + JSPrincipals *originPrincipals); namespace JS { @@ -4621,8 +5071,7 @@ typedef bool (* OpenAsmJSCacheEntryForReadOp)(HandleObject global, const jschar *begin, const jschar *limit, size_t *size, const uint8_t **memory, intptr_t *handle); typedef void -(* CloseAsmJSCacheEntryForReadOp)(HandleObject global, size_t size, const uint8_t *memory, - intptr_t handle); +(* CloseAsmJSCacheEntryForReadOp)(size_t size, const uint8_t *memory, intptr_t handle); /* * This callback represents a request by the JS engine to open for writing a @@ -4632,21 +5081,30 @@ typedef void * outparams. If the callback returns 'true', the JS engine guarantees a call * to CloseAsmJSCacheEntryForWriteOp passing the same base address, size and * handle. + * + * If 'installed' is true, then the cache entry is associated with a permanently + * installed JS file (e.g., in a packaged webapp). This information allows the + * embedding to store the cache entry in a installed location associated with + * the principal of 'global' where it will not be evicted until the associated + * installed JS file is removed. */ typedef bool -(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, const jschar *begin, const jschar *end, +(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, bool installed, + const jschar *begin, const jschar *end, size_t size, uint8_t **memory, intptr_t *handle); typedef void -(* CloseAsmJSCacheEntryForWriteOp)(HandleObject global, size_t size, uint8_t *memory, - intptr_t handle); +(* CloseAsmJSCacheEntryForWriteOp)(size_t size, uint8_t *memory, intptr_t handle); + +typedef js::Vector BuildIdCharVector; // Return the buildId (represented as a sequence of characters) associated with // the currently-executing build. If the JS engine is embedded such that a // single cache entry can be observed by different compiled versions of the JS // engine, it is critical that the buildId shall change for each new build of // the JS engine. + typedef bool -(* BuildIdOp)(js::Vector *buildId); +(* BuildIdOp)(BuildIdCharVector *buildId); struct AsmJSCacheOps { @@ -4660,6 +5118,132 @@ struct AsmJSCacheOps extern JS_PUBLIC_API(void) SetAsmJSCacheOps(JSRuntime *rt, const AsmJSCacheOps *callbacks); +/* + * Convenience class for imitating a JS level for-of loop. Typical usage: + * + * ForOfIterator it(cx); + * if (!it.init(iterable)) + * return false; + * RootedValue val(cx); + * while (true) { + * bool done; + * if (!it.next(&val, &done)) + * return false; + * if (done) + * break; + * if (!DoStuff(cx, val)) + * return false; + * } + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(ForOfIterator) { + protected: + JSContext *cx_; + /* + * Use the ForOfPIC on the global object (see vm/GlobalObject.h) to try + * to optimize iteration across arrays. + * + * Case 1: Regular Iteration + * iterator - pointer to the iterator object. + * index - fixed to NOT_ARRAY (== UINT32_MAX) + * + * Case 2: Optimized Array Iteration + * iterator - pointer to the array object. + * index - current position in array. + * + * The cases are distinguished by whether or not |index| is equal to NOT_ARRAY. + */ + JS::RootedObject iterator; + uint32_t index; + + static const uint32_t NOT_ARRAY = UINT32_MAX; + + ForOfIterator(const ForOfIterator &) MOZ_DELETE; + ForOfIterator &operator=(const ForOfIterator &) MOZ_DELETE; + + public: + explicit ForOfIterator(JSContext *cx) : cx_(cx), iterator(cx_), index(NOT_ARRAY) { } + + enum NonIterableBehavior { + ThrowOnNonIterable, + AllowNonIterable + }; + + /* + * Initialize the iterator. If AllowNonIterable is passed then if iterable + * does not have a callable @@iterator init() will just return true instead + * of throwing. Callers should then check valueIsIterable() before + * continuing with the iteration. + */ + bool init(JS::HandleValue iterable, + NonIterableBehavior nonIterableBehavior = ThrowOnNonIterable); + + /* + * This method assumes that |iterator| is already an iterator. It will not + * check for, and call @@iterator. Callers should make sure that the passed + * in value is in fact an iterator. + */ + bool initWithIterator(JS::HandleValue aIterator); + + /* + * Get the next value from the iterator. If false *done is true + * after this call, do not examine val. + */ + bool next(JS::MutableHandleValue val, bool *done); + + /* + * If initialized with throwOnNonCallable = false, check whether + * the value is iterable. + */ + bool valueIsIterable() const { + return iterator; + } + + private: + inline bool nextFromOptimizedArray(MutableHandleValue val, bool *done); + bool materializeArrayIterator(); +}; + + +/* + * If a large allocation fails, the JS engine may call the large-allocation- + * failure callback, if set, to allow the embedding to flush caches, possibly + * perform shrinking GCs, etc. to make some room so that the allocation will + * succeed if retried. After the callback returns, the JS engine will try to + * allocate again and may be succesful. + */ + +typedef void +(* LargeAllocationFailureCallback)(void *data); + +extern JS_PUBLIC_API(void) +SetLargeAllocationFailureCallback(JSRuntime *rt, LargeAllocationFailureCallback afc, void *data); + +/* + * Unlike the error reporter, which is only called if the exception for an OOM + * bubbles up and is not caught, the OutOfMemoryCallback is called immediately + * at the OOM site to allow the embedding to capture the current state of heap + * allocation before anything is freed. If the large-allocation-failure callback + * is called at all (not all allocation sites call the large-allocation-failure + * callback on failure), it is called before the out-of-memory callback; the + * out-of-memory callback is only called if the allocation still fails after the + * large-allocation-failure callback has returned. + */ + +typedef void +(* OutOfMemoryCallback)(JSContext *cx, void *data); + +extern JS_PUBLIC_API(void) +SetOutOfMemoryCallback(JSRuntime *rt, OutOfMemoryCallback cb, void *data); + + +/* + * Capture the current call stack as a chain of SavedFrame objects, and set + * |stackp| to the SavedFrame for the newest stack frame. If |maxFrameCount| is + * non-zero, capture at most the youngest |maxFrameCount| frames. + */ +extern JS_PUBLIC_API(bool) +CaptureCurrentStack(JSContext *cx, MutableHandleObject stackp, unsigned maxFrameCount = 0); + } /* namespace JS */ #endif /* jsapi_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/jscpucfg.h b/frameworks/js-bindings/external/spidermonkey/include/linux/jscpucfg.h index e545d8329d..a7a00613bb 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/jscpucfg.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/jscpucfg.h @@ -18,7 +18,7 @@ # error "CPU type is unknown" # endif /* !(defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)) */ -#elif defined(_WIN32) || defined(XP_OS2) +#elif defined(_WIN32) # ifdef __WATCOMC__ # define HAVE_VA_LIST_AS_ARRAY 1 @@ -27,7 +27,7 @@ # define IS_LITTLE_ENDIAN 1 # undef IS_BIG_ENDIAN -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) # if __LITTLE_ENDIAN__ # define IS_LITTLE_ENDIAN 1 # undef IS_BIG_ENDIAN @@ -89,8 +89,7 @@ # endif #elif defined(__sparc) || defined(__sparc__) || \ - defined(_POWER) || defined(__powerpc__) || \ - defined(__ppc__) || defined(__hppa) || \ + defined(_POWER) || defined(__hppa) || \ defined(_MIPSEB) || defined(_BIG_ENDIAN) /* IA64 running HP-UX will have _BIG_ENDIAN defined. * IA64 running Linux will have endian.h and be handled above. diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/jsfriendapi.h b/frameworks/js-bindings/external/spidermonkey/include/linux/jsfriendapi.h index eb05652a5b..674999eb62 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/jsfriendapi.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/jsfriendapi.h @@ -7,8 +7,12 @@ #ifndef jsfriendapi_h #define jsfriendapi_h +#include "mozilla/Casting.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/TypedEnum.h" +#include "mozilla/UniquePtr.h" +#include "jsapi.h" // For JSAutoByteString. See bug 1033916. #include "jsbytecode.h" #include "jspubtd.h" @@ -19,14 +23,20 @@ /* * This macro checks if the stack pointer has exceeded a given limit. If * |tolerance| is non-zero, it returns true only if the stack pointer has - * exceeded the limit by more than |tolerance| bytes. + * exceeded the limit by more than |tolerance| bytes. The WITH_INTOLERANCE + * versions use a negative tolerance (i.e., the limit is reduced by + * |intolerance| bytes). */ #if JS_STACK_GROWTH_DIRECTION > 0 # define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ ((uintptr_t)(sp) < (limit)+(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) < (limit)-(intolerance)) #else # define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ ((uintptr_t)(sp) > (limit)-(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) > (limit)+(intolerance)) #endif #define JS_CHECK_STACK_SIZE(limit, lval) JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, lval, 0) @@ -35,33 +45,35 @@ class JSAtom; struct JSErrorFormatString; class JSLinearString; struct JSJitInfo; -class JSErrorReport; +struct JSErrorReport; namespace JS { template class Heap; } /* namespace JS */ +namespace js { +class JS_FRIEND_API(BaseProxyHandler); +} /* namespace js */ + extern JS_FRIEND_API(void) JS_SetGrayGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); extern JS_FRIEND_API(JSString *) JS_GetAnonymousString(JSRuntime *rt); -extern JS_FRIEND_API(void) -JS_SetIsWorkerRuntime(JSRuntime *rt); - extern JS_FRIEND_API(JSObject *) -JS_FindCompilationScope(JSContext *cx, JSObject *obj); +JS_FindCompilationScope(JSContext *cx, JS::HandleObject obj); extern JS_FRIEND_API(JSFunction *) JS_GetObjectFunction(JSObject *obj); extern JS_FRIEND_API(bool) -JS_SplicePrototype(JSContext *cx, JSObject *obj, JSObject *proto); +JS_SplicePrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); extern JS_FRIEND_API(JSObject *) -JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JSObject *proto, JSObject *parent); +JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JS::HandleObject proto, + JS::HandleObject parent); extern JS_FRIEND_API(uint32_t) JS_ObjectCountDynamicSlots(JS::HandleObject obj); @@ -73,7 +85,7 @@ extern JS_FRIEND_API(size_t) JS_GetCustomIteratorCount(JSContext *cx); extern JS_FRIEND_API(bool) -JS_NondeterministicGetWeakMapKeys(JSContext *cx, JSObject *obj, JSObject **ret); +JS_NondeterministicGetWeakMapKeys(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject ret); /* * Determine whether the given object is backed by a DeadObjectProxy. @@ -122,16 +134,23 @@ JS_GetCompartmentPrincipals(JSCompartment *compartment); extern JS_FRIEND_API(void) JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals); +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptPrincipals(JSScript *script); + +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptOriginPrincipals(JSScript *script); + /* Safe to call with input obj == nullptr. Returns non-nullptr iff obj != nullptr. */ extern JS_FRIEND_API(JSObject *) -JS_ObjectToInnerObject(JSContext *cx, JSObject *obj); +JS_ObjectToInnerObject(JSContext *cx, JS::HandleObject obj); /* Requires obj != nullptr. */ extern JS_FRIEND_API(JSObject *) -JS_ObjectToOuterObject(JSContext *cx, JSObject *obj); +JS_ObjectToOuterObject(JSContext *cx, JS::HandleObject obj); extern JS_FRIEND_API(JSObject *) -JS_CloneObject(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent); +JS_CloneObject(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto, + JS::HandleObject parent); extern JS_FRIEND_API(JSString *) JS_BasicObjectToString(JSContext *cx, JS::HandleObject obj); @@ -149,13 +168,17 @@ js_ObjectClassIs(JSContext *cx, JS::HandleObject obj, js::ESClassValue classValu JS_FRIEND_API(const char *) js_ObjectClassName(JSContext *cx, JS::HandleObject obj); +namespace js { + JS_FRIEND_API(bool) -js_AddObjectRoot(JSRuntime *rt, JSObject **objp); +AddRawValueRoot(JSContext *cx, JS::Value *vp, const char *name); JS_FRIEND_API(void) -js_RemoveObjectRoot(JSRuntime *rt, JSObject **objp); +RemoveRawValueRoot(JSContext *cx, JS::Value *vp); -#ifdef DEBUG +} /* namespace js */ + +#ifdef JS_DEBUG /* * Routines to print out values during debugging. These are FRIEND_API to help @@ -184,7 +207,7 @@ js_DumpChars(const jschar *s, size_t n); * restrictions on the compartment of |cx|. */ extern JS_FRIEND_API(bool) -JS_CopyPropertiesFrom(JSContext *cx, JSObject *target, JSObject *obj); +JS_CopyPropertiesFrom(JSContext *cx, JS::HandleObject target, JS::HandleObject obj); /* * Single-property version of the above. This function asserts that an |own| @@ -221,20 +244,164 @@ struct JSFunctionSpecWithHelp { {nullptr, nullptr, 0, 0, nullptr, nullptr} extern JS_FRIEND_API(bool) -JS_DefineFunctionsWithHelp(JSContext *cx, JSObject *obj, const JSFunctionSpecWithHelp *fs); +JS_DefineFunctionsWithHelp(JSContext *cx, JS::HandleObject obj, const JSFunctionSpecWithHelp *fs); namespace js { +/* + * Helper Macros for creating JSClasses that function as proxies. + * + * NB: The macro invocation must be surrounded by braces, so as to + * allow for potention JSClass extensions. + */ +#define PROXY_MAKE_EXT(outerObject, innerObject, iteratorObject, \ + isWrappedNative) \ + { \ + outerObject, \ + innerObject, \ + iteratorObject, \ + isWrappedNative, \ + js::proxy_WeakmapKeyDelegate \ + } + +#define PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, ext) \ + { \ + name, \ + js::Class::NON_NATIVE | \ + JSCLASS_IS_PROXY | \ + JSCLASS_IMPLEMENTS_BARRIERS | \ + JSCLASS_HAS_RESERVED_SLOTS(js::PROXY_MINIMUM_SLOTS + (extraSlots)) | \ + flags, \ + JS_PropertyStub, /* addProperty */ \ + JS_DeletePropertyStub, /* delProperty */ \ + JS_PropertyStub, /* getProperty */ \ + JS_StrictPropertyStub, /* setProperty */ \ + JS_EnumerateStub, \ + JS_ResolveStub, \ + js::proxy_Convert, \ + js::proxy_Finalize, /* finalize */ \ + callOp, /* call */ \ + js::proxy_HasInstance, /* hasInstance */ \ + constructOp, /* construct */ \ + js::proxy_Trace, /* trace */ \ + JS_NULL_CLASS_SPEC, \ + ext, \ + { \ + js::proxy_LookupGeneric, \ + js::proxy_LookupProperty, \ + js::proxy_LookupElement, \ + js::proxy_DefineGeneric, \ + js::proxy_DefineProperty, \ + js::proxy_DefineElement, \ + js::proxy_GetGeneric, \ + js::proxy_GetProperty, \ + js::proxy_GetElement, \ + js::proxy_SetGeneric, \ + js::proxy_SetProperty, \ + js::proxy_SetElement, \ + js::proxy_GetGenericAttributes, \ + js::proxy_SetGenericAttributes, \ + js::proxy_DeleteGeneric, \ + js::proxy_Watch, js::proxy_Unwatch, \ + js::proxy_Slice, \ + nullptr, /* enumerate */ \ + nullptr, /* thisObject */ \ + } \ + } + +#define PROXY_CLASS_DEF(name, extraSlots, flags, callOp, constructOp) \ + PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, \ + PROXY_MAKE_EXT( \ + nullptr, /* outerObject */ \ + nullptr, /* innerObject */ \ + nullptr, /* iteratorObject */ \ + false /* isWrappedNative */ \ + )) + +/* + * Proxy stubs, similar to JS_*Stub, for embedder proxy class definitions. + * + * NB: Should not be called directly. + */ + +extern JS_FRIEND_API(bool) +proxy_LookupGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleObject objp, JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_DefineGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, + unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_GetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetProperty(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, + JS::Handle name, JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetElement(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_SetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp, + bool strict); +extern JS_FRIEND_API(bool) +proxy_GetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_SetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_DeleteGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); + +extern JS_FRIEND_API(void) +proxy_Trace(JSTracer *trc, JSObject *obj); +extern JS_FRIEND_API(JSObject *) +proxy_WeakmapKeyDelegate(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Convert(JSContext *cx, JS::HandleObject proxy, JSType hint, JS::MutableHandleValue vp); +extern JS_FRIEND_API(void) +proxy_Finalize(FreeOp *fop, JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_HasInstance(JSContext *cx, JS::HandleObject proxy, JS::MutableHandleValue v, bool *bp); +extern JS_FRIEND_API(bool) +proxy_Call(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(bool) +proxy_Construct(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(JSObject *) +proxy_innerObject(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Watch(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); +extern JS_FRIEND_API(bool) +proxy_Unwatch(JSContext *cx, JS::HandleObject obj, JS::HandleId id); +extern JS_FRIEND_API(bool) +proxy_Slice(JSContext *cx, JS::HandleObject proxy, uint32_t begin, uint32_t end, + JS::HandleObject result); + /* * A class of objects that return source code on demand. * - * When code is compiled with CompileOptions::LAZY_SOURCE, SpiderMonkey - * doesn't retain the source code (and doesn't do lazy bytecode - * generation). If we ever need the source code, say, in response to a call - * to Function.prototype.toSource or Debugger.Source.prototype.text, then - * we call the 'load' member function of the instance of this class that - * has hopefully been registered with the runtime, passing the code's URL, - * and hope that it will be able to find the source. + * When code is compiled with setSourceIsLazy(true), SpiderMonkey doesn't + * retain the source code (and doesn't do lazy bytecode generation). If we ever + * need the source code, say, in response to a call to Function.prototype. + * toSource or Debugger.Source.prototype.text, then we call the 'load' member + * function of the instance of this class that has hopefully been registered + * with the runtime, passing the code's URL, and hope that it will be able to + * find the source. */ class SourceHook { public: @@ -249,18 +416,25 @@ class SourceHook { }; /* - * Have |rt| use |hook| to retrieve LAZY_SOURCE source code. See the + * Have |rt| use |hook| to retrieve lazily-retrieved source code. See the * comments for SourceHook. The runtime takes ownership of the hook, and * will delete it when the runtime itself is deleted, or when a new hook is * set. */ extern JS_FRIEND_API(void) -SetSourceHook(JSRuntime *rt, SourceHook *hook); +SetSourceHook(JSRuntime *rt, mozilla::UniquePtr hook); /* Remove |rt|'s source hook, and return it. The caller now owns the hook. */ -extern JS_FRIEND_API(SourceHook *) +extern JS_FRIEND_API(mozilla::UniquePtr) ForgetSourceHook(JSRuntime *rt); +#ifdef NIGHTLY_BUILD +typedef void (*AssertOnScriptEntryHook)(JSContext *cx, JS::HandleScript script); + +extern JS_FRIEND_API(void) +SetAssertOnScriptEntryHook(JSRuntime *rt, AssertOnScriptEntryHook hook); +#endif + extern JS_FRIEND_API(JS::Zone *) GetCompartmentZone(JSCompartment *comp); @@ -293,16 +467,6 @@ IsSystemZone(JS::Zone *zone); extern JS_FRIEND_API(bool) IsAtomsCompartment(JSCompartment *comp); -/* - * Check whether it is OK to assign an undeclared variable with the name - * |propname| at the current location in script. It is not an error if there is - * no current script location, or if that location is not an assignment to an - * undeclared variable. Reports an error if one needs to be reported (and, - * particularly, always reports when it returns false). - */ -extern JS_FRIEND_API(bool) -ReportIfUndeclaredVarAssignment(JSContext *cx, JS::HandleString propname); - /* * Returns whether we're in a non-strict property set (in that we're in a * non-strict script and the bytecode we're on is a property set). The return @@ -339,6 +503,9 @@ TraceWeakMaps(WeakMapTracer *trc); extern JS_FRIEND_API(bool) AreGCGrayBitsValid(JSRuntime *rt); +extern JS_FRIEND_API(bool) +ZoneGlobalsAreAllGray(JS::Zone *zone); + typedef void (*GCThingCallback)(void *closure, void *gcthing); @@ -379,7 +546,7 @@ struct TypeObject { }; struct BaseShape { - const js::Class *clasp; + const js::Class *clasp_; JSObject *parent; JSObject *_1; JSCompartment *compartment; @@ -427,10 +594,20 @@ struct Function { void *_1; }; -struct Atom { - static const size_t LENGTH_SHIFT = 4; - size_t lengthAndFlags; - const jschar *chars; +struct String +{ + static const uint32_t INLINE_CHARS_BIT = JS_BIT(2); + static const uint32_t LATIN1_CHARS_BIT = JS_BIT(6); + static const uint32_t ROPE_FLAGS = 0; + static const uint32_t TYPE_FLAGS_MASK = JS_BIT(6) - 1; + uint32_t flags; + uint32_t length; + union { + const JS::Latin1Char *nonInlineCharsLatin1; + const jschar *nonInlineCharsTwoByte; + JS::Latin1Char inlineStorageLatin1[1]; + jschar inlineStorageTwoByte[1]; + }; }; } /* namespace shadow */ @@ -451,6 +628,46 @@ GetObjectJSClass(JSObject *obj) return js::Jsvalify(GetObjectClass(obj)); } +JS_FRIEND_API(const Class *) +ProtoKeyToClass(JSProtoKey key); + +// Returns true if the standard class identified by |key| inherits from +// another standard class with the same js::Class. This basically means +// that the various properties described by our js::Class are intended +// to live higher up on the proto chain. +// +// In practice, this only returns true for Error subtypes. +inline bool +StandardClassIsDependent(JSProtoKey key) +{ + JSProtoKey keyFromClass = JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + MOZ_ASSERT(keyFromClass); + return key != keyFromClass; +} + +// Returns the key for the class inherited by a given standard class (that +// is to say, the prototype of this standard class's prototype). +// +// You must be sure that this corresponds to a standard class with a cached +// JSProtoKey before calling this function. In general |key| will match the +// cached proto key, except in cases where multiple JSProtoKeys share a +// JSClass. +inline JSProtoKey +ParentKeyForStandardClass(JSProtoKey key) +{ + // [Object] has nothing to inherit from. + if (key == JSProto_Object) + return JSProto_Null; + + // If we're dependent (i.e. an Error subtype), return the key of the class + // we depend on. + if (StandardClassIsDependent(key)) + return JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + + // Otherwise, we inherit [Object]. + return JSProto_Object; +} + inline bool IsInnerObject(JSObject *obj) { return !!GetObjectClass(obj)->ext.outerObject; @@ -477,7 +694,7 @@ GetObjectParent(JSObject *obj) return reinterpret_cast(obj)->shape->base->parent; } -static JS_ALWAYS_INLINE JSCompartment * +static MOZ_ALWAYS_INLINE JSCompartment * GetObjectCompartment(JSObject *obj) { return reinterpret_cast(obj)->shape->base->compartment; @@ -489,10 +706,15 @@ GetObjectParentMaybeScope(JSObject *obj); JS_FRIEND_API(JSObject *) GetGlobalForObjectCrossCompartment(JSObject *obj); +// Sidestep the activeContext checking implicitly performed in +// JS_SetPendingException. +JS_FRIEND_API(void) +SetPendingExceptionCrossContext(JSContext *cx, JS::HandleValue v); + JS_FRIEND_API(void) AssertSameCompartment(JSContext *cx, JSObject *obj); -#ifdef DEBUG +#ifdef JS_DEBUG JS_FRIEND_API(void) AssertSameCompartment(JSObject *objA, JSObject *objB); #else @@ -509,9 +731,6 @@ SetDefaultObjectForContext(JSContext *cx, JSObject *obj); JS_FRIEND_API(void) NotifyAnimationActivity(JSObject *obj); -JS_FRIEND_API(bool) -IsOriginalScriptFunction(JSFunction *fun); - /* * Return the outermost enclosing function (script) of the scripted caller. * This function returns nullptr in several cases: @@ -521,7 +740,7 @@ IsOriginalScriptFunction(JSFunction *fun); * thus it will really return the outermost enclosing function *since the * innermost eval*. */ -JS_FRIEND_API(JSScript *) +JS_FRIEND_API(JSFunction *) GetOutermostEnclosingFunctionOfScriptedCaller(JSContext *cx); JS_FRIEND_API(JSFunction *) @@ -536,12 +755,6 @@ JS_FRIEND_API(JSFunction *) NewFunctionByIdWithReserved(JSContext *cx, JSNative native, unsigned nargs, unsigned flags, JSObject *parent, jsid id); -JS_FRIEND_API(JSObject *) -InitClassWithReserved(JSContext *cx, JSObject *obj, JSObject *parent_proto, - const JSClass *clasp, JSNative constructor, unsigned nargs, - const JSPropertySpec *ps, const JSFunctionSpec *fs, - const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs); - JS_FRIEND_API(const JS::Value &) GetFunctionNativeReserved(JSObject *fun, size_t which); @@ -549,7 +762,7 @@ JS_FRIEND_API(void) SetFunctionNativeReserved(JSObject *fun, size_t which, const JS::Value &val); JS_FRIEND_API(bool) -GetObjectProto(JSContext *cx, JS::Handle obj, JS::MutableHandle proto); +GetObjectProto(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject proto); JS_FRIEND_API(bool) GetOriginalEval(JSContext *cx, JS::HandleObject scope, @@ -604,25 +817,142 @@ GetObjectSlot(JSObject *obj, size_t slot) return reinterpret_cast(obj)->slotRef(slot); } -inline const jschar * -GetAtomChars(JSAtom *atom) +MOZ_ALWAYS_INLINE size_t +GetAtomLength(JSAtom *atom) { - return reinterpret_cast(atom)->chars; + return reinterpret_cast(atom)->length; } -inline size_t -GetAtomLength(JSAtom *atom) +static const uint32_t MaxStringLength = (1 << 28) - 1; + +MOZ_ALWAYS_INLINE size_t +GetStringLength(JSString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetFlatStringLength(JSFlatString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetLinearStringLength(JSLinearString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE bool +LinearStringHasLatin1Chars(JSLinearString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE bool +AtomHasLatin1Chars(JSAtom *atom) { - using shadow::Atom; - return reinterpret_cast(atom)->lengthAndFlags >> Atom::LENGTH_SHIFT; + return reinterpret_cast(atom)->flags & shadow::String::LATIN1_CHARS_BIT; } -inline JSLinearString * +MOZ_ALWAYS_INLINE bool +StringHasLatin1Chars(JSString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1LinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageLatin1; + return s->nonInlineCharsLatin1; +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteLinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(!LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageTwoByte; + return s->nonInlineCharsTwoByte; +} + +MOZ_ALWAYS_INLINE JSLinearString * AtomToLinearString(JSAtom *atom) { return reinterpret_cast(atom); } +MOZ_ALWAYS_INLINE JSLinearString * +FlatStringToLinearString(JSFlatString *s) +{ + return reinterpret_cast(s); +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1AtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetLatin1LinearStringChars(nogc, AtomToLinearString(atom)); +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteAtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetTwoByteLinearStringChars(nogc, AtomToLinearString(atom)); +} + +JS_FRIEND_API(JSLinearString *) +StringToLinearStringSlow(JSContext *cx, JSString *str); + +MOZ_ALWAYS_INLINE JSLinearString * +StringToLinearString(JSContext *cx, JSString *str) +{ + using shadow::String; + String *s = reinterpret_cast(str); + if (MOZ_UNLIKELY((s->flags & String::TYPE_FLAGS_MASK) == String::ROPE_FLAGS)) + return StringToLinearStringSlow(cx, str); + return reinterpret_cast(str); +} + +MOZ_ALWAYS_INLINE void +CopyLinearStringChars(jschar *dest, JSLinearString *s, size_t len) +{ + JS::AutoCheckCannotGC nogc; + if (LinearStringHasLatin1Chars(s)) { + const JS::Latin1Char *src = GetLatin1LinearStringChars(nogc, s); + for (size_t i = 0; i < len; i++) + dest[i] = src[i]; + } else { + const jschar *src = GetTwoByteLinearStringChars(nogc, s); + mozilla::PodCopy(dest, src, len); + } +} + +inline bool +CopyStringChars(JSContext *cx, jschar *dest, JSString *s, size_t len) +{ + JSLinearString *linear = StringToLinearString(cx, s); + if (!linear) + return false; + + CopyLinearStringChars(dest, linear, len); + return true; +} + +inline void +CopyFlatStringChars(jschar *dest, JSFlatString *s, size_t len) +{ + CopyLinearStringChars(dest, FlatStringToLinearString(s), len); +} + JS_FRIEND_API(bool) GetPropertyNames(JSContext *cx, JSObject *obj, unsigned flags, JS::AutoIdVector *props); @@ -641,24 +971,18 @@ SetPreserveWrapperCallback(JSRuntime *rt, PreserveWrapperCallback callback); JS_FRIEND_API(bool) IsObjectInContextCompartment(JSObject *obj, const JSContext *cx); -/* - * ErrorFromException takes a raw Value so that it's possible to call it during - * GC/CC/whatever, when it may not be possible to get a JSContext to create a - * Rooted. It promises to never ever GC. - */ -JS_FRIEND_API(JSErrorReport*) -ErrorFromException(JS::Value val); - /* * NB: these flag bits are encoded into the bytecode stream in the immediate * operand of JSOP_ITER, so don't change them without advancing vm/Xdr.h's * XDR_BYTECODE_VERSION. */ #define JSITER_ENUMERATE 0x1 /* for-in compatible hidden default iterator */ -#define JSITER_FOREACH 0x2 /* return [key, value] pair rather than key */ -#define JSITER_KEYVALUE 0x4 /* destructuring for-in wants [key, value] */ +#define JSITER_FOREACH 0x2 /* get obj[key] for each property */ +#define JSITER_KEYVALUE 0x4 /* obsolete destructuring for-in wants [key, value] */ #define JSITER_OWNONLY 0x8 /* iterate over obj's own properties only */ #define JSITER_HIDDEN 0x10 /* also enumerate non-enumerable properties */ +#define JSITER_SYMBOLS 0x20 /* also include symbol property keys */ +#define JSITER_SYMBOLSONLY 0x40 /* exclude string property keys */ JS_FRIEND_API(bool) RunningWithTrustedPrincipals(JSContext *cx); @@ -677,6 +1001,7 @@ GetNativeStackLimit(JSContext *cx) * These macros report a stack overflow and run |onerror| if we are close to * using up the C stack. The JS_CHECK_CHROME_RECURSION variant gives us a little * extra space so that we can ensure that crucial code is able to run. + * JS_CHECK_RECURSION_CONSERVATIVE gives us a little less space. */ #define JS_CHECK_RECURSION(cx, onerror) \ @@ -723,6 +1048,18 @@ GetNativeStackLimit(JSContext *cx) } \ JS_END_MACRO +#define JS_CHECK_RECURSION_CONSERVATIVE(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(js::GetNativeStackLimit(cx), \ + &stackDummy_, \ + 1024 * sizeof(size_t))) \ + { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + JS_FRIEND_API(void) StartPCCountProfiling(JSContext *cx); @@ -764,9 +1101,10 @@ extern JS_FRIEND_API(bool) IsContextRunningJS(JSContext *cx); typedef bool -(* DOMInstanceClassMatchesProto)(JSObject *protoObject, uint32_t protoID, uint32_t depth); +(* DOMInstanceClassHasProtoAtDepth)(const Class *instanceClass, + uint32_t protoID, uint32_t depth); struct JSDOMCallbacks { - DOMInstanceClassMatchesProto instanceClassMatchesProto; + DOMInstanceClassHasProtoAtDepth instanceClassMatchesProto; }; typedef struct JSDOMCallbacks DOMCallbacks; @@ -796,10 +1134,10 @@ CastToJSFreeOp(FreeOp *fop) * Get an error type name from a JSExnType constant. * Returns nullptr for invalid arguments and JSEXN_INTERNALERR */ -extern JS_FRIEND_API(const jschar*) -GetErrorTypeName(JSRuntime* rt, int16_t exnType); +extern JS_FRIEND_API(JSFlatString *) +GetErrorTypeName(JSRuntime *rt, int16_t exnType); -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_FRIEND_API(unsigned) GetEnterCompartmentDepth(JSContext* cx); #endif @@ -836,13 +1174,13 @@ struct ChromeCompartmentsOnly : public CompartmentFilter { struct SingleCompartment : public CompartmentFilter { JSCompartment *ours; - SingleCompartment(JSCompartment *c) : ours(c) {} + explicit SingleCompartment(JSCompartment *c) : ours(c) {} virtual bool match(JSCompartment *c) const { return c == ours; } }; struct CompartmentsWithPrincipals : public CompartmentFilter { JSPrincipals *principals; - CompartmentsWithPrincipals(JSPrincipals *p) : principals(p) {} + explicit CompartmentsWithPrincipals(JSPrincipals *p) : principals(p) {} virtual bool match(JSCompartment *c) const { return JS_GetCompartmentPrincipals(c) == principals; } @@ -941,49 +1279,198 @@ typedef enum JSErrNum { } JSErrNum; extern JS_FRIEND_API(const JSErrorFormatString *) -js_GetErrorMessage(void *userRef, const char *locale, const unsigned errorNumber); +js_GetErrorMessage(void *userRef, const unsigned errorNumber); + +namespace js { + +// AutoStableStringChars is here so we can use it in ErrorReport. It +// should get moved out of here if we can manage it. See bug 1040316. + +/* + * This class provides safe access to a string's chars across a GC. Once + * we allocate strings and chars in the nursery (bug 903519), this class + * will have to make a copy of the string's chars if they are allocated + * in the nursery, so it's best to avoid using this class unless you really + * need it. It's usually more efficient to use the latin1Chars/twoByteChars + * JSString methods and often the code can be rewritten so that only indexes + * instead of char pointers are used in parts of the code that can GC. + */ +class MOZ_STACK_CLASS AutoStableStringChars +{ + /* Ensure the string is kept alive while we're using its chars. */ + JS::RootedString s_; + union { + const jschar *twoByteChars_; + const JS::Latin1Char *latin1Chars_; + }; + enum State { Uninitialized, Latin1, TwoByte }; + State state_; + bool ownsChars_; + + public: + AutoStableStringChars(JSContext *cx) + : s_(cx), state_(Uninitialized), ownsChars_(false) + {}; + ~AutoStableStringChars(); + + bool init(JSContext *cx, JSString *s); + + /* Like init(), but Latin1 chars are inflated to TwoByte. */ + bool initTwoByte(JSContext *cx, JSString *s); + + bool isLatin1() const { return state_ == Latin1; } + bool isTwoByte() const { return state_ == TwoByte; } + + const jschar *twoByteChars() const { + MOZ_ASSERT(state_ == TwoByte); + return twoByteChars_; + } + + mozilla::Range latin1Range() const { + MOZ_ASSERT(state_ == Latin1); + return mozilla::Range(latin1Chars_, + GetStringLength(s_)); + } + + mozilla::Range twoByteRange() const { + MOZ_ASSERT(state_ == TwoByte); + return mozilla::Range(twoByteChars_, + GetStringLength(s_)); + } + + /* If we own the chars, transfer ownership to the caller. */ + bool maybeGiveOwnershipToCaller() { + MOZ_ASSERT(state_ != Uninitialized); + if (!ownsChars_) + return false; + state_ = Uninitialized; + ownsChars_ = false; + return true; + } + + private: + AutoStableStringChars(const AutoStableStringChars &other) MOZ_DELETE; + void operator=(const AutoStableStringChars &other) MOZ_DELETE; +}; + +// Creates a string of the form |ErrorType: ErrorMessage| for a JSErrorReport, +// which generally matches the toString() behavior of an ErrorObject. +extern JS_FRIEND_API(JSString *) +ErrorReportToString(JSContext *cx, JSErrorReport *reportp); + +struct MOZ_STACK_CLASS JS_FRIEND_API(ErrorReport) +{ + ErrorReport(JSContext *cx); + ~ErrorReport(); + + bool init(JSContext *cx, JS::HandleValue exn); + + JSErrorReport *report() + { + return reportp; + } + + const char *message() + { + return message_; + } + + private: + // More or less an equivalent of JS_ReportErrorNumber/js_ReportErrorNumberVA + // but fills in an ErrorReport instead of reporting it. Uses varargs to + // make it simpler to call js_ExpandErrorArguments. + void populateUncaughtExceptionReport(JSContext *cx, ...); + void populateUncaughtExceptionReportVA(JSContext *cx, va_list ap); + + // We may have a provided JSErrorReport, so need a way to represent that. + JSErrorReport *reportp; + + // And we may have a message. + const char *message_; + + // Or we may need to synthesize a JSErrorReport one of our own. + JSErrorReport ownedReport; + + // Or a message of our own. If this is non-null, we need to clean up both + // it and ownedReport. + char *ownedMessage; + + // And we have a string to maybe keep alive that has pointers into + // it from ownedReport. + JS::RootedString str; + + // And keep its chars alive too. + AutoStableStringChars strChars; + + // And we need to root our exception value. + JS::RootedObject exnObject; + + // And possibly some byte storage for our message_. + JSAutoByteString bytesStorage; + + // And for our filename. + JSAutoByteString filename; + + // True if we need to free message_ and the stuff in ownedReport + bool ownsMessageAndReport; +}; + +} /* namespace js */ + /* Implemented in jsclone.cpp. */ extern JS_FRIEND_API(uint64_t) js_GetSCOffset(JSStructuredCloneWriter* writer); -/* Typed Array functions, implemented in jstypedarray.cpp */ - namespace js { -namespace ArrayBufferView { - -enum ViewType { - TYPE_INT8 = 0, - TYPE_UINT8, - TYPE_INT16, - TYPE_UINT16, - TYPE_INT32, - TYPE_UINT32, - TYPE_FLOAT32, - TYPE_FLOAT64, +namespace Scalar { + +/* Scalar types which can appear in typed arrays and typed objects. */ +enum Type { + Int8 = 0, + Uint8, + Int16, + Uint16, + Int32, + Uint32, + Float32, + Float64, /* * Special type that is a uint8_t, but assignments are clamped to [0, 256). * Treat the raw data type as a uint8_t. */ - TYPE_UINT8_CLAMPED, + Uint8Clamped, - /* - * Type returned for a DataView. Note that there is no single element type - * in this case. - */ - TYPE_DATAVIEW, - - TYPE_MAX + TypeMax }; -} /* namespace ArrayBufferView */ +static inline size_t +byteSize(Type atype) +{ + switch (atype) { + case Int8: + case Uint8: + case Uint8Clamped: + return 1; + case Int16: + case Uint16: + return 2; + case Int32: + case Uint32: + case Float32: + return 4; + case Float64: + return 8; + default: + MOZ_CRASH("invalid scalar type"); + } +} +} /* namespace Scalar */ } /* namespace js */ -typedef js::ArrayBufferView::ViewType JSArrayBufferViewType; - /* * Create a new typed array with nelements elements. * @@ -1019,23 +1506,23 @@ JS_NewFloat64Array(JSContext *cx, uint32_t nelements); */ extern JS_FRIEND_API(JSObject *) -JS_NewInt8ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt8ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint8ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ClampedArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint8ClampedArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewInt16ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt16ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint16ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint16ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewInt32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewFloat32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewFloat32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewFloat64ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewFloat64ArrayFromArray(JSContext *cx, JS::HandleObject array); /* * Create a new typed array using the given ArrayBuffer for storage. The @@ -1044,31 +1531,31 @@ JS_NewFloat64ArrayFromArray(JSContext *cx, JSObject *array); */ extern JS_FRIEND_API(JSObject *) -JS_NewInt8ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewInt16ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint16ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewInt32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewFloat32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewFloat32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewFloat64ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewFloat64ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); /* @@ -1119,6 +1606,93 @@ JS_IsFloat32Array(JSObject *obj); extern JS_FRIEND_API(bool) JS_IsFloat64Array(JSObject *obj); +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +namespace js { + +extern JS_FRIEND_API(JSObject *) +UnwrapInt8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8ClampedArray(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat64Array(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBuffer(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBufferView(JSObject *obj); + +namespace detail { + +extern JS_FRIEND_DATA(const Class* const) Int8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ClampedArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float64ArrayClassPtr; + +const size_t TypedArrayLengthSlot = 1; + +} // namespace detail + +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +#define JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Type, type) \ +inline void \ +Get ## Type ## ArrayLengthAndData(JSObject *obj, uint32_t *length, type **data) \ +{ \ + JS_ASSERT(GetObjectClass(obj) == detail::Type ## ArrayClassPtr); \ + const JS::Value &slot = GetReservedSlot(obj, detail::TypedArrayLengthSlot); \ + *length = mozilla::SafeCast(slot.toInt32()); \ + *data = static_cast(GetObjectPrivate(obj)); \ +} + +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int8, int8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8Clamped, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int16, int16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint16, uint16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int32, int32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint32, uint32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float32, float) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float64, double) + +#undef JS_DEFINE_DATA_AND_LENGTH_ACCESSOR + +// This one isn't inlined because it's rather tricky (by dint of having to deal +// with a dozen-plus classes and varying slot layouts. +extern JS_FRIEND_API(void) +GetArrayBufferViewLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +// This one isn't inlined because there are a bunch of different ArrayBuffer +// classes that would have to be individually handled here. +extern JS_FRIEND_API(void) +GetArrayBufferLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +} // namespace js + /* * Unwrap Typed arrays all at once. Return nullptr without throwing if the * object cannot be viewed as the correct typed array, or the typed array @@ -1148,13 +1722,13 @@ extern JS_FRIEND_API(JSObject *) JS_GetObjectAsArrayBuffer(JSObject *obj, uint32_t *length, uint8_t **data); /* - * Get the type of elements in a typed array, or TYPE_DATAVIEW if a DataView. + * Get the type of elements in a typed array, or TypeMax if a DataView. * * |obj| must have passed a JS_IsArrayBufferView/JS_Is*Array test, or somehow * be known that it would pass such a test: it is an ArrayBufferView or a * wrapper of an ArrayBufferView, and the unwrapping will succeed. */ -extern JS_FRIEND_API(JSArrayBufferViewType) +extern JS_FRIEND_API(js::Scalar::Type) JS_GetArrayBufferViewType(JSObject *obj); /* @@ -1177,16 +1751,12 @@ extern JS_FRIEND_API(uint32_t) JS_GetArrayBufferByteLength(JSObject *obj); /* - * Return a pointer to an array buffer's data. The buffer is still owned by the - * array buffer object, and should not be modified on another thread. The - * returned pointer is stable across GCs. - * - * |obj| must have passed a JS_IsArrayBufferObject test, or somehow be known - * that it would pass such a test: it is an ArrayBuffer or a wrapper of an - * ArrayBuffer, and the unwrapping will succeed. + * Check whether the obj is ArrayBufferObject and memory mapped. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. */ -extern JS_FRIEND_API(uint8_t *) -JS_GetArrayBufferData(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsMappedArrayBufferObject(JSObject *obj); /* * Return the number of elements in a typed array. @@ -1236,13 +1806,17 @@ JS_GetArrayBufferViewByteLength(JSObject *obj); /* * Return a pointer to the start of the data referenced by a typed array. The * data is still owned by the typed array, and should not be modified on - * another thread. + * another thread. Furthermore, the pointer can become invalid on GC (if the + * data is small and fits inside the array's GC header), so callers must take + * care not to hold on across anything that could GC. * * |obj| must have passed a JS_Is*Array test, or somehow be known that it would * pass such a test: it is a typed array or a wrapper of a typed array, and the * unwrapping will succeed. */ +extern JS_FRIEND_API(uint8_t *) +JS_GetArrayBufferData(JSObject *obj); extern JS_FRIEND_API(int8_t *) JS_GetInt8ArrayData(JSObject *obj); extern JS_FRIEND_API(uint8_t *) @@ -1262,6 +1836,13 @@ JS_GetFloat32ArrayData(JSObject *obj); extern JS_FRIEND_API(double *) JS_GetFloat64ArrayData(JSObject *obj); +/* + * Stable versions of the above functions where the buffer remains valid as long + * as the object is live. + */ +extern JS_FRIEND_API(uint8_t *) +JS_GetStableArrayBufferData(JSContext *cx, JS::HandleObject obj); + /* * Same as above, but for any kind of ArrayBufferView. Prefer the type-specific * versions when possible. @@ -1275,13 +1856,33 @@ JS_GetArrayBufferViewData(JSObject *obj); * object that would return true for JS_IsArrayBufferViewObject(). */ extern JS_FRIEND_API(JSObject *) -JS_GetArrayBufferViewBuffer(JSObject *obj); +JS_GetArrayBufferViewBuffer(JSContext *cx, JS::HandleObject obj); + +typedef enum { + ChangeData, + KeepData +} NeuterDataDisposition; /* * Set an ArrayBuffer's length to 0 and neuter all of its views. + * + * The |changeData| argument is a hint to inform internal behavior with respect + * to the internal pointer to the ArrayBuffer's data after being neutered. + * There is no guarantee it will be respected. But if it is respected, the + * ArrayBuffer's internal data pointer will, or will not, have changed + * accordingly. + */ +extern JS_FRIEND_API(bool) +JS_NeuterArrayBuffer(JSContext *cx, JS::HandleObject obj, + NeuterDataDisposition changeData); + +/* + * Check whether the obj is ArrayBufferObject and neutered. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. */ extern JS_FRIEND_API(bool) -JS_NeuterArrayBuffer(JSContext *cx, JS::HandleObject obj); +JS_IsNeuteredArrayBufferObject(JSObject *obj); /* * Check whether obj supports JS_GetDataView* APIs. @@ -1360,7 +1961,7 @@ class JSJitGetterCallArgs : protected JS::MutableHandleValue : JS::MutableHandleValue(args.rval()) {} - explicit JSJitGetterCallArgs(JS::Rooted* rooted) + explicit JSJitGetterCallArgs(JS::RootedValue* rooted) : JS::MutableHandleValue(rooted) {} @@ -1422,6 +2023,12 @@ class JSJitMethodCallArgs : protected JS::detail::CallArgsBaseusedRval_, which we don't have. + return argv_[-2].toObject(); + } + // Add get() as needed }; @@ -1451,7 +2058,10 @@ struct JSJitInfo { Getter, Setter, Method, - OpType_None + ParallelNative, + StaticMethod, + // Must be last + OpTypeCount }; enum ArgType { @@ -1475,6 +2085,13 @@ struct JSJitInfo { ArgTypeListEnd = (1 << 31) }; + static_assert(Any & String, "Any must include String."); + static_assert(Any & Integer, "Any must include Integer."); + static_assert(Any & Double, "Any must include Double."); + static_assert(Any & Boolean, "Any must include Boolean."); + static_assert(Any & Object, "Any must include Object."); + static_assert(Any & Null, "Any must include Null."); + enum AliasSet { // An enum that describes what this getter/setter/method aliases. This // determines what things can be hoisted past this call, and if this @@ -1490,69 +2107,172 @@ struct JSJitInfo { // Alias the world. Calling this can change arbitrary values anywhere // in the system. Most things fall in this bucket. - AliasEverything + AliasEverything, + + // Must be last. + AliasSetCount }; - bool isDOMJitInfo() const + bool hasParallelNative() const + { + return type() == ParallelNative; + } + + bool needsOuterizedThisObject() const + { + return type() != Getter && type() != Setter; + } + + bool isTypedMethodJitInfo() const { - return type != OpType_None; + return isTypedMethod; + } + + OpType type() const + { + return OpType(type_); + } + + AliasSet aliasSet() const + { + return AliasSet(aliasSet_); + } + + JSValueType returnType() const + { + return JSValueType(returnType_); } union { JSJitGetterOp getter; JSJitSetterOp setter; JSJitMethodOp method; + /* An alternative native that's safe to call in parallel mode. */ + JSParallelNative parallelNative; + /* A DOM static method, used for Promise wrappers */ + JSNative staticMethod; }; - uint32_t protoID; - uint32_t depth; - // type not being OpType_None means this is a DOM method. If you - // change that, come up with a different way of implementing - // isDOMJitInfo(). - OpType type; - bool isInfallible; /* Is op fallible? False in setters. */ - bool isMovable; /* Is op movable? To be movable the op must not - AliasEverything, but even that might not be - enough (e.g. in cases when it can throw). */ - AliasSet aliasSet; /* The alias set for this op. This is a _minimal_ - alias set; in particular for a method it does not - include whatever argument conversions might do. - That's covered by argTypes and runtime analysis - of the actual argument types being passed in. */ - // XXXbz should we have a JSGetterJitInfo subclass or something? + uint16_t protoID; + uint16_t depth; + + // These fields are carefully packed to take up 4 bytes. If you need more + // bits for whatever reason, please see if you can steal bits from existing + // fields before adding more members to this structure. + +#define JITINFO_OP_TYPE_BITS 4 +#define JITINFO_ALIAS_SET_BITS 4 +#define JITINFO_RETURN_TYPE_BITS 8 + + // The OpType that says what sort of function we are. + uint32_t type_ : JITINFO_OP_TYPE_BITS; + + // The alias set for this op. This is a _minimal_ alias set; in + // particular for a method it does not include whatever argument + // conversions might do. That's covered by argTypes and runtime + // analysis of the actual argument types being passed in. + uint32_t aliasSet_ : JITINFO_ALIAS_SET_BITS; + + // The return type tag. Might be JSVAL_TYPE_UNKNOWN. + uint32_t returnType_ : JITINFO_RETURN_TYPE_BITS; + + static_assert(OpTypeCount <= (1 << JITINFO_OP_TYPE_BITS), + "Not enough space for OpType"); + static_assert(AliasSetCount <= (1 << JITINFO_ALIAS_SET_BITS), + "Not enough space for AliasSet"); + static_assert((sizeof(JSValueType) * 8) <= JITINFO_RETURN_TYPE_BITS, + "Not enough space for JSValueType"); + +#undef JITINFO_RETURN_TYPE_BITS +#undef JITINFO_ALIAS_SET_BITS +#undef JITINFO_OP_TYPE_BITS + + uint32_t isInfallible : 1; /* Is op fallible? False in setters. */ + uint32_t isMovable : 1; /* Is op movable? To be movable the op must + not AliasEverything, but even that might + not be enough (e.g. in cases when it can + throw). */ // XXXbz should we have a JSValueType for the type of the member? - bool isInSlot; /* True if this is a getter that can get a member - from a slot of the "this" object directly. */ - size_t slotIndex; /* If isMember is true, the index of the slot to get - the value from. Otherwise 0. */ - JSValueType returnType; /* The return type tag. Might be JSVAL_TYPE_UNKNOWN */ - - const ArgType* const argTypes; /* For a method, a list of sets of types that - the function expects. This can be used, - for example, to figure out when argument - coercions can have side-effects. nullptr - if we have no type information for - arguments. */ - - /* An alternative native that's safe to call in parallel mode. */ - JSParallelNative parallelNative; - -private: - static void staticAsserts() - { - JS_STATIC_ASSERT(Any & String); - JS_STATIC_ASSERT(Any & Integer); - JS_STATIC_ASSERT(Any & Double); - JS_STATIC_ASSERT(Any & Boolean); - JS_STATIC_ASSERT(Any & Object); - JS_STATIC_ASSERT(Any & Null); - } + uint32_t isAlwaysInSlot : 1; /* True if this is a getter that can always + get the value from a slot of the "this" + object. */ + uint32_t isLazilyCachedInSlot : 1; /* True if this is a getter that can + sometimes (if the slot doesn't contain + UndefinedValue()) get the value from a + slot of the "this" object. */ + uint32_t isTypedMethod : 1; /* True if this is an instance of + JSTypedMethodJitInfo. */ + uint32_t slotIndex : 11; /* If isAlwaysInSlot or isSometimesInSlot is + true, the index of the slot to get the value + from. Otherwise 0. */ }; -#define JS_JITINFO_NATIVE_PARALLEL(op) \ - {{nullptr},0,0,JSJitInfo::OpType_None,false,false,JSJitInfo::AliasEverything,false,0,JSVAL_TYPE_MISSING,nullptr,op} +static_assert(sizeof(JSJitInfo) == (sizeof(void*) + 2 * sizeof(uint32_t)), + "There are several thousand instances of JSJitInfo stored in " + "a binary. Please don't increase its space requirements without " + "verifying that there is no other way forward (better packing, " + "smaller datatypes for fields, subclassing, etc.)."); -static JS_ALWAYS_INLINE const JSJitInfo * +struct JSTypedMethodJitInfo +{ + // We use C-style inheritance here, rather than C++ style inheritance + // because not all compilers support brace-initialization for non-aggregate + // classes. Using C++ style inheritance and constructors instead of + // brace-initialization would also force the creation of static + // constructors (on some compilers) when JSJitInfo and JSTypedMethodJitInfo + // structures are declared. Since there can be several thousand of these + // structures present and we want to have roughly equivalent performance + // across a range of compilers, we do things manually. + JSJitInfo base; + + const JSJitInfo::ArgType* const argTypes; /* For a method, a list of sets of + types that the function + expects. This can be used, + for example, to figure out + when argument coercions can + have side-effects. */ +}; + +namespace JS { +namespace detail { + +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_PARALLEL_NATIVE_TO only. */ +inline int CheckIsParallelNative(JSParallelNative parallelNative); + +} // namespace detail +} // namespace JS + +#define JS_CAST_PARALLEL_NATIVE_TO(v, To) \ + (static_cast(sizeof(JS::detail::CheckIsParallelNative(v))), \ + reinterpret_cast(v)) + +/* + * You may ask yourself: why do we define a wrapper around a wrapper here? + * The answer is that some compilers don't understand initializing a union + * as we do below with a construct like: + * + * reinterpret_cast(JSParallelNativeThreadSafeWrapper) + * + * (We need the reinterpret_cast because we must initialize the union with + * a datum of the type of the union's first member.) + * + * Presumably this has something to do with template instantiation. + * Initializing with a normal function pointer seems to work fine. Hence + * the ugliness that you see before you. + */ +#define JS_JITINFO_NATIVE_PARALLEL(infoName, parallelOp) \ + const JSJitInfo infoName = \ + {{JS_CAST_PARALLEL_NATIVE_TO(parallelOp, JSJitGetterOp)},0,0,JSJitInfo::ParallelNative,JSJitInfo::AliasEverything,JSVAL_TYPE_MISSING,false,false,false,false,false,0} + +#define JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(infoName, wrapperName, serialOp) \ + bool wrapperName##_ParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, \ + JS::Value *vp) \ + { \ + return JSParallelNativeThreadSafeWrapper(cx, argc, vp); \ + } \ + JS_JITINFO_NATIVE_PARALLEL(infoName, wrapperName##_ParallelNativeThreadSafeWrapper) + +static MOZ_ALWAYS_INLINE const JSJitInfo * FUNCTION_VALUE_TO_JITINFO(const JS::Value& v) { JS_ASSERT(js::GetObjectClass(&v.toObject()) == js::FunctionClassPtr); @@ -1562,7 +2282,7 @@ FUNCTION_VALUE_TO_JITINFO(const JS::Value& v) /* Statically asserted in jsfun.h. */ static const unsigned JS_FUNCTION_INTERPRETED_BIT = 0x1; -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void SET_JITINFO(JSFunction * func, const JSJitInfo *info) { js::shadow::Function *fun = reinterpret_cast(func); @@ -1575,7 +2295,7 @@ SET_JITINFO(JSFunction * func, const JSJitInfo *info) * eliminate Gecko's dependencies on it! */ -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid JSID_FROM_BITS(size_t bits) { jsid id; @@ -1610,7 +2330,7 @@ bool IdMatchesAtom(jsid id, JSAtom *atom); * Thus, it is only the rare third case which needs this function, which * handles any JSAtom* that is known not to be representable with an int jsid. */ -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid NON_INTEGER_ATOM_TO_JSID(JSAtom *atom) { JS_ASSERT(((size_t)atom & 0x7) == 0); @@ -1620,19 +2340,19 @@ NON_INTEGER_ATOM_TO_JSID(JSAtom *atom) } /* All strings stored in jsids are atomized, but are not necessarily property names. */ -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ATOM(jsid id) { return JSID_IS_STRING(id); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ATOM(jsid id, JSAtom *atom) { return id == JSID_FROM_BITS((size_t)atom); } -static JS_ALWAYS_INLINE JSAtom * +static MOZ_ALWAYS_INLINE JSAtom * JSID_TO_ATOM(jsid id) { return (JSAtom *)JSID_TO_STRING(id); @@ -1642,31 +2362,19 @@ JS_STATIC_ASSERT(sizeof(jsid) == sizeof(void*)); namespace js { -static JS_ALWAYS_INLINE JS::Value +static MOZ_ALWAYS_INLINE JS::Value IdToValue(jsid id) { if (JSID_IS_STRING(id)) return JS::StringValue(JSID_TO_STRING(id)); - if (JS_LIKELY(JSID_IS_INT(id))) + if (JSID_IS_INT(id)) return JS::Int32Value(JSID_TO_INT(id)); - if (JS_LIKELY(JSID_IS_OBJECT(id))) - return JS::ObjectValue(*JSID_TO_OBJECT(id)); + if (JSID_IS_SYMBOL(id)) + return JS::SymbolValue(JSID_TO_SYMBOL(id)); JS_ASSERT(JSID_IS_VOID(id)); return JS::UndefinedValue(); } -static JS_ALWAYS_INLINE jsval -IdToJsval(jsid id) -{ - return IdToValue(id); -} - -extern JS_FRIEND_API(bool) -IsReadOnlyDateMethod(JS::IsAcceptableThis test, JS::NativeImpl method); - -extern JS_FRIEND_API(bool) -IsTypedArrayThisCheck(JS::IsAcceptableThis test); - /* * If the embedder has registered a default JSContext callback, returns the * result of the callback. Otherwise, asserts that |rt| has exactly one @@ -1681,6 +2389,21 @@ typedef JSContext* JS_FRIEND_API(void) SetDefaultJSContextCallback(JSRuntime *rt, DefaultJSContextCallback cb); +/* + * To help embedders enforce their invariants, we allow them to specify in + * advance which JSContext should be passed to JSAPI calls. If this is set + * to a non-null value, the assertSameCompartment machinery does double- + * duty (in debug builds) to verify that it matches the cx being used. + */ +#ifdef DEBUG +JS_FRIEND_API(void) +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx); +#else +inline void +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx) {}; +#endif + + enum CTypesActivityType { CTYPES_CALL_BEGIN, CTYPES_CALL_END, @@ -1720,13 +2443,6 @@ class JS_FRIEND_API(AutoCTypesActivityCallback) { } }; -#ifdef DEBUG -extern JS_FRIEND_API(void) -assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id); -#else -inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id) {}; -#endif - typedef bool (* ObjectMetadataCallback)(JSContext *cx, JSObject **pmetadata); @@ -1747,6 +2463,13 @@ SetObjectMetadata(JSContext *cx, JS::HandleObject obj, JS::HandleObject metadata JS_FRIEND_API(JSObject *) GetObjectMetadata(JSObject *obj); +JS_FRIEND_API(void) +UnsafeDefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value); + +JS_FRIEND_API(bool) +SliceSlowly(JSContext* cx, JS::HandleObject obj, JS::HandleObject receiver, + uint32_t begin, uint32_t end, JS::HandleObject result); + /* ES5 8.12.8. */ extern JS_FRIEND_API(bool) DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandleValue vp); @@ -1766,7 +2489,43 @@ DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandle */ extern JS_FRIEND_API(bool) CheckDefineProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +/* + * Helper function for HTMLDocument and HTMLFormElement. + * + * These are the only two interfaces that have [OverrideBuiltins], a named + * getter, and no named setter. They're implemented as proxies with a custom + * getOwnPropertyDescriptor() method. Unfortunately, overriding + * getOwnPropertyDescriptor() automatically affects the behavior of set(), + * which normally is just common sense but is *not* desired for these two + * interfaces. + * + * The fix is for these two interfaces to override set() to ignore the + * getOwnPropertyDescriptor() override. + * + * SetPropertyIgnoringNamedGetter is exposed to make it easier to override + * set() in this way. It carries out all the steps of BaseProxyHandler::set() + * except the initial getOwnPropertyDescriptor()/getPropertyDescriptor() calls. + * The caller must supply those results as the 'desc' and 'descIsOwn' + * parameters. + * + * Implemented in jsproxy.cpp. + */ +JS_FRIEND_API(bool) +SetPropertyIgnoringNamedGetter(JSContext *cx, const BaseProxyHandler *handler, + JS::HandleObject proxy, JS::HandleObject receiver, + JS::HandleId id, JS::MutableHandle desc, + bool descIsOwn, bool strict, JS::MutableHandleValue vp); + +JS_FRIEND_API(void) +ReportErrorWithId(JSContext *cx, const char *msg, JS::HandleId id); + +// This function is for one specific use case, please don't use this for anything else! +extern JS_FRIEND_API(bool) +ExecuteInGlobalAndReturnScope(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleObject scope); } /* namespace js */ @@ -1775,27 +2534,27 @@ js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg, JS::Handle descriptor, bool *bp); extern JS_FRIEND_API(bool) -js_ReportIsNotFunction(JSContext *cx, const JS::Value& v); +js_ReportIsNotFunction(JSContext *cx, JS::HandleValue v); #ifdef JSGC_GENERATIONAL extern JS_FRIEND_API(void) JS_StoreObjectPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSObject *key, void *data), JSObject *key, void *data); extern JS_FRIEND_API(void) JS_StoreStringPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSString *key, void *data), JSString *key, void *data); #else inline void JS_StoreObjectPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSObject *key, void *data), JSObject *key, void *data) {} inline void JS_StoreStringPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSString *key, void *data), JSString *key, void *data) {} #endif /* JSGC_GENERATIONAL */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/jsperf.h b/frameworks/js-bindings/external/spidermonkey/include/linux/jsperf.h index e3cbc23143..60c572f559 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/jsperf.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/jsperf.h @@ -88,7 +88,7 @@ class JS_FRIEND_API(PerfMeasurement) * then the eventsMeasured bitmask will only include the subset of * |toMeasure| corresponding to the events that can be measured. */ - PerfMeasurement(EventMask toMeasure); + explicit PerfMeasurement(EventMask toMeasure); /* Done with this set of measurements, tear down OS-level state. */ ~PerfMeasurement(); @@ -118,7 +118,7 @@ class JS_FRIEND_API(PerfMeasurement) * global object). The JS-visible API is identical to the C++ API. */ extern JS_FRIEND_API(JSObject*) - RegisterPerfMeasurement(JSContext *cx, JSObject *global); + RegisterPerfMeasurement(JSContext *cx, JS::HandleObject global); /* * Given a Value which contains an instance of the aforementioned diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/jsprf.h b/frameworks/js-bindings/external/spidermonkey/include/linux/jsprf.h index b235f0b4fb..bfedf98ca8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/jsprf.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/jsprf.h @@ -57,23 +57,11 @@ extern JS_PUBLIC_API(void) JS_smprintf_free(char *mem); */ extern JS_PUBLIC_API(char*) JS_sprintf_append(char *last, const char *fmt, ...); -/* -** sprintf into a function. The function "f" is called with a string to -** place into the output. "arg" is an opaque pointer used by the stuff -** function to hold any state needed to do the storage of the output -** data. The return value is a count of the number of characters fed to -** the stuff function, or (uint32_t)-1 if an error occurs. -*/ -typedef int (*JSStuffFunc)(void *arg, const char *s, uint32_t slen); - -extern JS_PUBLIC_API(uint32_t) JS_sxprintf(JSStuffFunc f, void *arg, const char *fmt, ...); - /* ** va_list forms of the above. */ extern JS_PUBLIC_API(uint32_t) JS_vsnprintf(char *out, uint32_t outlen, const char *fmt, va_list ap); extern JS_PUBLIC_API(char*) JS_vsmprintf(const char *fmt, va_list ap); extern JS_PUBLIC_API(char*) JS_vsprintf_append(char *last, const char *fmt, va_list ap); -extern JS_PUBLIC_API(uint32_t) JS_vsxprintf(JSStuffFunc f, void *arg, const char *fmt, va_list ap); #endif /* jsprf_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/jsprototypes.h b/frameworks/js-bindings/external/spidermonkey/include/linux/jsprototypes.h index bc4a767033..1cb56bf8da 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/jsprototypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/jsprototypes.h @@ -34,7 +34,7 @@ #define CLASP(name) (&name##Class) #define OCLASP(name) (&name##Object::class_) -#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[ScalarTypeRepresentation::type]) +#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[Scalar::type]) #ifdef ENABLE_PARALLEL_JS #define IF_PJS(real,imaginary) real @@ -54,47 +54,61 @@ #define IF_BDATA(real,imaginary) imaginary #endif +#ifdef ENABLE_SHARED_ARRAY_BUFFER +#define IF_SAB(real,imaginary) real +#else +#define IF_SAB(real,imaginary) imaginary +#endif + +#ifdef JS_HAS_SYMBOLS +#define IF_SYMBOLS(real,imaginary) real +#else +#define IF_SYMBOLS(real,imaginary) imaginary +#endif + #define JS_FOR_PROTOTYPES(real,imaginary) \ imaginary(Null, 0, js_InitNullClass, dummy) \ - real(Object, 1, js_InitObjectClass, &JSObject::class_) \ - real(Function, 2, js_InitFunctionClass, &JSFunction::class_) \ - real(Array, 3, js_InitArrayClass, OCLASP(Array)) \ + real(Object, 1, js_InitViaClassSpec, &JSObject::class_) \ + real(Function, 2, js_InitViaClassSpec, &JSFunction::class_) \ + real(Array, 3, js_InitViaClassSpec, OCLASP(Array)) \ real(Boolean, 4, js_InitBooleanClass, OCLASP(Boolean)) \ real(JSON, 5, js_InitJSONClass, CLASP(JSON)) \ - real(Date, 6, js_InitDateClass, OCLASP(Date)) \ + real(Date, 6, js_InitViaClassSpec, OCLASP(Date)) \ real(Math, 7, js_InitMathClass, CLASP(Math)) \ real(Number, 8, js_InitNumberClass, OCLASP(Number)) \ real(String, 9, js_InitStringClass, OCLASP(String)) \ real(RegExp, 10, js_InitRegExpClass, OCLASP(RegExp)) \ - real(Error, 11, js_InitExceptionClasses, OCLASP(Error)) \ - real(InternalError, 12, js_InitExceptionClasses, OCLASP(Error)) \ - real(EvalError, 13, js_InitExceptionClasses, OCLASP(Error)) \ - real(RangeError, 14, js_InitExceptionClasses, OCLASP(Error)) \ - real(ReferenceError, 15, js_InitExceptionClasses, OCLASP(Error)) \ - real(SyntaxError, 16, js_InitExceptionClasses, OCLASP(Error)) \ - real(TypeError, 17, js_InitExceptionClasses, OCLASP(Error)) \ - real(URIError, 18, js_InitExceptionClasses, OCLASP(Error)) \ + real(Error, 11, js_InitViaClassSpec, OCLASP(Error)) \ + real(InternalError, 12, js_InitViaClassSpec, OCLASP(Error)) \ + real(EvalError, 13, js_InitViaClassSpec, OCLASP(Error)) \ + real(RangeError, 14, js_InitViaClassSpec, OCLASP(Error)) \ + real(ReferenceError, 15, js_InitViaClassSpec, OCLASP(Error)) \ + real(SyntaxError, 16, js_InitViaClassSpec, OCLASP(Error)) \ + real(TypeError, 17, js_InitViaClassSpec, OCLASP(Error)) \ + real(URIError, 18, js_InitViaClassSpec, OCLASP(Error)) \ real(Iterator, 19, js_InitIteratorClasses, OCLASP(PropertyIterator)) \ real(StopIteration, 20, js_InitIteratorClasses, OCLASP(StopIteration)) \ - real(ArrayBuffer, 21, js_InitTypedArrayClasses, &js::ArrayBufferObject::protoClass) \ - real(Int8Array, 22, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT8)) \ - real(Uint8Array, 23, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT8)) \ - real(Int16Array, 24, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT16)) \ - real(Uint16Array, 25, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT16)) \ - real(Int32Array, 26, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT32)) \ - real(Uint32Array, 27, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT32)) \ - real(Float32Array, 28, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_FLOAT32)) \ - real(Float64Array, 29, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_FLOAT64)) \ - real(Uint8ClampedArray, 30, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT8_CLAMPED)) \ + real(ArrayBuffer, 21, js_InitArrayBufferClass, &js::ArrayBufferObject::protoClass) \ + real(Int8Array, 22, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int8)) \ + real(Uint8Array, 23, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8)) \ + real(Int16Array, 24, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int16)) \ + real(Uint16Array, 25, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint16)) \ + real(Int32Array, 26, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int32)) \ + real(Uint32Array, 27, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint32)) \ + real(Float32Array, 28, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float32)) \ + real(Float64Array, 29, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float64)) \ + real(Uint8ClampedArray, 30, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8Clamped)) \ real(Proxy, 31, js_InitProxyClass, &ProxyObject::uncallableClass_) \ real(WeakMap, 32, js_InitWeakMapClass, OCLASP(WeakMap)) \ real(Map, 33, js_InitMapClass, OCLASP(Map)) \ real(Set, 34, js_InitSetClass, OCLASP(Set)) \ - real(DataView, 35, js_InitTypedArrayClasses, OCLASP(DataView)) \ -IF_PJS(real,imaginary) (ParallelArray, 36, js_InitParallelArrayClass, OCLASP(ParallelArray)) \ -IF_INTL(real,imaginary) (Intl, 37, js_InitIntlClass, CLASP(Intl)) \ -IF_BDATA(real,imaginary)(TypedObject, 38, js_InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \ - imaginary(GeneratorFunction, 39, js_InitIteratorClasses, dummy) \ + real(DataView, 35, js_InitDataViewClass, OCLASP(DataView)) \ +IF_SYMBOLS(real,imaginary)(Symbol, 36, js_InitSymbolClass, &js::SymbolObject::class_) \ +IF_SAB(real,imaginary)(SharedArrayBuffer, 37, js_InitSharedArrayBufferClass, &js::SharedArrayBufferObject::protoClass) \ +IF_INTL(real,imaginary) (Intl, 38, js_InitIntlClass, CLASP(Intl)) \ +IF_BDATA(real,imaginary)(TypedObject, 39, js_InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \ + imaginary(GeneratorFunction, 40, js_InitIteratorClasses, dummy) \ +IF_BDATA(real,imaginary)(SIMD, 41, js_InitSIMDClass, OCLASP(SIMD)) \ #define JS_FOR_EACH_PROTOTYPE(macro) JS_FOR_PROTOTYPES(macro,macro) diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/jsproxy.h b/frameworks/js-bindings/external/spidermonkey/include/linux/jsproxy.h index 3d2ea81cb3..b4588c4c2a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/jsproxy.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/jsproxy.h @@ -47,6 +47,22 @@ class JS_FRIEND_API(Wrapper); * BaseProxyHandler provides implementations of the derived traps in terms of * the (pure virtual) fundamental traps. * + * In addition to the normal traps, there are two models for proxy prototype + * chains. First, proxies may opt to use the standard prototype mechanism used + * throughout the engine. To do so, simply pass a prototype to NewProxyObject() + * at creation time. All prototype accesses will then "just work" to treat the + * proxy as a "normal" object. Alternatively, if instead the proxy wishes to + * implement more complicated prototype semantics (if, for example, it wants to + * delegate the prototype lookup to a wrapped object), it may pass Proxy::LazyProto + * as the prototype at create time and opt in to the trapped prototype system, + * which guarantees that their trap will be called on any and every prototype + * chain access of the object. + * + * This system is implemented with two traps: {get,set}PrototypeOf. The default + * implementation of setPrototypeOf throws a TypeError. Since it is not possible + * to create an object without a sense of prototype chain, handler implementors + * must provide a getPrototypeOf trap if opting in to the dynamic prototype system. + * * To minimize code duplication, a set of abstract proxy handler classes is * provided, from which other handlers may inherit. These abstract classes * are organized in the following hierarchy: @@ -72,37 +88,55 @@ class JS_FRIEND_API(Wrapper); class JS_FRIEND_API(BaseProxyHandler) { const void *mFamily; + + /* + * Proxy handlers can use mHasPrototype to request the following special + * treatment from the JS engine: + * + * - When mHasPrototype is true, the engine never calls these methods: + * getPropertyDescriptor, has, set, enumerate, iterate. Instead, for + * these operations, it calls the "own" traps like + * getOwnPropertyDescriptor, hasOwn, defineProperty, keys, etc., and + * consults the prototype chain if needed. + * + * - When mHasPrototype is true, the engine calls handler->get() only if + * handler->hasOwn() says an own property exists on the proxy. If not, + * it consults the prototype chain. + * + * This is useful because it frees the ProxyHandler from having to implement + * any behavior having to do with the prototype chain. + */ bool mHasPrototype; - bool mHasPolicy; - protected: - // Subclasses may set this in their constructor. - void setHasPrototype(bool aHasPrototype) { mHasPrototype = aHasPrototype; } - void setHasPolicy(bool aHasPolicy) { mHasPolicy = aHasPolicy; } + + /* + * All proxies indicate whether they have any sort of interesting security + * policy that might prevent the caller from doing something it wants to + * the object. In the case of wrappers, this distinction is used to + * determine whether the caller may strip off the wrapper if it so desires. + */ + bool mHasSecurityPolicy; public: - explicit BaseProxyHandler(const void *family); + explicit BaseProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); virtual ~BaseProxyHandler(); - bool hasPrototype() { + bool hasPrototype() const { return mHasPrototype; } - bool hasPolicy() { - return mHasPolicy; + bool hasSecurityPolicy() const { + return mHasSecurityPolicy; } - inline const void *family() { + inline const void *family() const { return mFamily; } static size_t offsetOfFamily() { return offsetof(BaseProxyHandler, mFamily); } - virtual bool isOuterWindow() { - return false; - } - - virtual bool finalizeInBackground(Value priv) { + virtual bool finalizeInBackground(Value priv) const { /* * Called on creation of a proxy to determine whether its finalize * method can be finalized on the background thread. @@ -119,66 +153,75 @@ class JS_FRIEND_API(BaseProxyHandler) * The |act| parameter to enter() specifies the action being performed. * If |bp| is false, the trap suggests that the caller throw (though it * may still decide to squelch the error). + * + * We make these OR-able so that assertEnteredPolicy can pass a union of them. + * For example, get{,Own}PropertyDescriptor is invoked by both calls to ::get() + * and ::set() (since we need to look up the accessor), so its + * assertEnteredPolicy would pass GET | SET. */ - enum Action { - GET, - SET, - CALL + typedef uint32_t Action; + enum { + NONE = 0x00, + GET = 0x01, + SET = 0x02, + CALL = 0x04, + ENUMERATE = 0x08 }; + virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Action act, - bool *bp); + bool *bp) const; /* ES5 Harmony fundamental proxy traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) = 0; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const = 0; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, - unsigned flags) = 0; + MutableHandle desc) const = 0; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, - HandleId id, MutableHandle desc, - unsigned flags) = 0; + HandleId id, MutableHandle desc) const = 0; virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc) = 0; + MutableHandle desc) const = 0; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, - AutoIdVector &props) = 0; - virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) = 0; - virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) = 0; + AutoIdVector &props) const = 0; + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const = 0; + virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) const = 0; /* ES5 Harmony derived proxy traps. */ - virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); - virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); + virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; + virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, MutableHandleValue vp); + HandleId id, MutableHandleValue vp) const; virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp); - virtual bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props); + HandleId id, bool strict, MutableHandleValue vp) const; + virtual bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props) const; virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, - MutableHandleValue vp); + MutableHandleValue vp) const; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) = 0; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args); - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args); - virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args); - virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp); - virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx); - virtual const char *className(JSContext *cx, HandleObject proxy); - virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent); - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g); - virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); - virtual void finalize(JSFreeOp *fop, JSObject *proxy); - virtual bool getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver, - uint32_t index, MutableHandleValue vp, bool *present); - virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const = 0; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args) const; + virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp) const; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx) const; + virtual const char *className(JSContext *cx, HandleObject proxy) const; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const; + virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp) const; + virtual void finalize(JSFreeOp *fop, JSObject *proxy) const; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop) const; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp) const; // These two hooks must be overridden, or not overridden, in tandem -- no // overriding just one! virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable); - virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id); + JS::HandleObject callable) const; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const; + + virtual bool slice(JSContext *cx, HandleObject proxy, uint32_t begin, uint32_t end, + HandleObject result) const; /* See comment for weakmapKeyDelegateOp in js/Class.h. */ - virtual JSObject *weakmapKeyDelegate(JSObject *proxy); - virtual bool isScripted() { return false; } + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const; + virtual bool isScripted() const { return false; } }; /* @@ -194,54 +237,58 @@ class JS_FRIEND_API(BaseProxyHandler) class JS_PUBLIC_API(DirectProxyHandler) : public BaseProxyHandler { public: - explicit DirectProxyHandler(const void *family); + explicit DirectProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); /* ES5 Harmony fundamental proxy traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags) MOZ_OVERRIDE; - virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, - HandleId id, MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool enumerate(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; /* ES5 Harmony derived proxy traps. */ virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool keys(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, - unsigned indent) MOZ_OVERRIDE; + unsigned indent) const MOZ_OVERRIDE; virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, - RegExpGuard *g) MOZ_OVERRIDE; - virtual JSObject *weakmapKeyDelegate(JSObject *proxy); + RegExpGuard *g) const MOZ_OVERRIDE; + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const MOZ_OVERRIDE; }; /* @@ -257,16 +304,15 @@ class Proxy /* ES5 Harmony fundamental proxy traps. */ static bool preventExtensions(JSContext *cx, HandleObject proxy); static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags); - static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, unsigned flags, HandleId id, + MutableHandle desc); + static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, MutableHandleValue vp); static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags); - static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, unsigned flags, HandleId id, + MutableHandle desc); + static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, MutableHandleValue vp); static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, MutableHandle desc); - static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, HandleValue v); static bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props); static bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); static bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props); @@ -276,8 +322,6 @@ class Proxy static bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); static bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, MutableHandleValue vp); - static bool getElementIfPresent(JSContext *cx, HandleObject proxy, HandleObject receiver, - uint32_t index, MutableHandleValue vp, bool *present); static bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, bool strict, MutableHandleValue vp); static bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props); @@ -295,44 +339,26 @@ class Proxy static bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g); static bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); static bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + static bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp); - static bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable); - static bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id); + static bool watch(JSContext *cx, HandleObject proxy, HandleId id, HandleObject callable); + static bool unwatch(JSContext *cx, HandleObject proxy, HandleId id); + + static bool slice(JSContext *cx, HandleObject obj, uint32_t begin, uint32_t end, + HandleObject result); /* IC entry path for handling __noSuchMethod__ on access. */ static bool callProp(JSContext *cx, HandleObject proxy, HandleObject reveiver, HandleId id, MutableHandleValue vp); - - static JSObject * const LazyProto; }; // Use these in places where you don't want to #include vm/ProxyObject.h. extern JS_FRIEND_DATA(const js::Class* const) CallableProxyClassPtr; extern JS_FRIEND_DATA(const js::Class* const) UncallableProxyClassPtr; -extern JS_FRIEND_DATA(const js::Class* const) OuterWindowProxyClassPtr; - -inline bool IsProxyClass(const Class *clasp) -{ - return clasp == CallableProxyClassPtr || - clasp == UncallableProxyClassPtr || - clasp == OuterWindowProxyClassPtr; -} inline bool IsProxy(JSObject *obj) { - return IsProxyClass(GetObjectClass(obj)); -} - -BaseProxyHandler * -GetProxyHandler(JSObject *obj); - -inline bool IsScriptedProxy(JSObject *obj) -{ - if (!IsProxy(obj)) - return false; - - return GetProxyHandler(obj)->isScripted(); + return GetObjectClass(obj)->isProxy(); } /* @@ -343,15 +369,16 @@ inline bool IsScriptedProxy(JSObject *obj) * needs to store one slot's worth of data doesn't need to branch on what sort * of object it has. */ -const uint32_t PROXY_PRIVATE_SLOT = 0; -const uint32_t PROXY_HANDLER_SLOT = 1; -const uint32_t PROXY_EXTRA_SLOT = 2; +const uint32_t PROXY_PRIVATE_SLOT = 0; +const uint32_t PROXY_HANDLER_SLOT = 1; +const uint32_t PROXY_EXTRA_SLOT = 2; +const uint32_t PROXY_MINIMUM_SLOTS = 4; -inline BaseProxyHandler * +inline const BaseProxyHandler * GetProxyHandler(JSObject *obj) { JS_ASSERT(IsProxy(obj)); - return (BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate(); + return (const BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate(); } inline const Value & @@ -390,17 +417,24 @@ SetProxyExtra(JSObject *obj, size_t n, const Value &extra) SetReservedSlot(obj, PROXY_EXTRA_SLOT + n, extra); } +inline bool +IsScriptedProxy(JSObject *obj) +{ + return IsProxy(obj) && GetProxyHandler(obj)->isScripted(); +} + class MOZ_STACK_CLASS ProxyOptions { - public: - ProxyOptions() : callable_(false), - singleton_(false) + protected: + /* protected constructor for subclass */ + ProxyOptions(bool singletonArg, const Class *claspArg) + : singleton_(singletonArg), + clasp_(claspArg) {} - bool callable() const { return callable_; } - ProxyOptions &setCallable(bool flag) { - callable_ = flag; - return *this; - } + public: + ProxyOptions() : singleton_(false), + clasp_(UncallableProxyClassPtr) + {} bool singleton() const { return singleton_; } ProxyOptions &setSingleton(bool flag) { @@ -408,13 +442,26 @@ class MOZ_STACK_CLASS ProxyOptions { return *this; } + const Class *clasp() const { + return clasp_; + } + ProxyOptions &setClass(const Class *claspArg) { + clasp_ = claspArg; + return *this; + } + ProxyOptions &selectDefaultClass(bool callable) { + const Class *classp = callable? CallableProxyClassPtr : + UncallableProxyClassPtr; + return setClass(classp); + } + private: - bool callable_; bool singleton_; + const Class *clasp_; }; JS_FRIEND_API(JSObject *) -NewProxyObject(JSContext *cx, BaseProxyHandler *handler, HandleValue priv, +NewProxyObject(JSContext *cx, const BaseProxyHandler *handler, HandleValue priv, JSObject *proto, JSObject *parent, const ProxyOptions &options = ProxyOptions()); JSObject * @@ -424,15 +471,15 @@ class JS_FRIEND_API(AutoEnterPolicy) { public: typedef BaseProxyHandler::Action Action; - AutoEnterPolicy(JSContext *cx, BaseProxyHandler *handler, + AutoEnterPolicy(JSContext *cx, const BaseProxyHandler *handler, HandleObject wrapper, HandleId id, Action act, bool mayThrow) -#ifdef DEBUG +#ifdef JS_DEBUG : context(nullptr) #endif { - allow = handler->hasPolicy() ? handler->enter(cx, wrapper, id, act, &rv) - : true; - recordEnter(cx, wrapper, id); + allow = handler->hasSecurityPolicy() ? handler->enter(cx, wrapper, id, act, &rv) + : true; + recordEnter(cx, wrapper, id, act); // We want to throw an exception if all of the following are true: // * The policy disallowed access. // * The policy set rv to false, indicating that we should throw. @@ -449,48 +496,65 @@ class JS_FRIEND_API(AutoEnterPolicy) protected: // no-op constructor for subclass AutoEnterPolicy() -#ifdef DEBUG +#ifdef JS_DEBUG : context(nullptr) + , enteredAction(BaseProxyHandler::NONE) #endif {}; void reportErrorIfExceptionIsNotPending(JSContext *cx, jsid id); bool allow; bool rv; -#ifdef DEBUG +#ifdef JS_DEBUG JSContext *context; mozilla::Maybe enteredProxy; mozilla::Maybe enteredId; + Action enteredAction; + // NB: We explicitly don't track the entered action here, because sometimes // SET traps do an implicit GET during their implementation, leading to // spurious assertions. AutoEnterPolicy *prev; - void recordEnter(JSContext *cx, HandleObject proxy, HandleId id); + void recordEnter(JSContext *cx, HandleObject proxy, HandleId id, Action act); void recordLeave(); - friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id); + friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id, Action act); #else - inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id) {} + inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id, Action act) {} inline void recordLeave() {} #endif }; -#ifdef DEBUG +#ifdef JS_DEBUG class JS_FRIEND_API(AutoWaivePolicy) : public AutoEnterPolicy { public: - AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id) + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) { allow = true; - recordEnter(cx, proxy, id); + recordEnter(cx, proxy, id, act); } }; #else class JS_FRIEND_API(AutoWaivePolicy) { - public: AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id) {}; + public: + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) + {} }; #endif +#ifdef JS_DEBUG +extern JS_FRIEND_API(void) +assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act); +#else +inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act) +{}; +#endif + } /* namespace js */ extern JS_FRIEND_API(JSObject *) diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/jspubtd.h b/frameworks/js-bindings/external/spidermonkey/include/linux/jspubtd.h index 9683c23ea4..ffd75e2e5c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/jspubtd.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/jspubtd.h @@ -11,6 +11,7 @@ * JS public API typedefs. */ +#include "mozilla/Assertions.h" #include "mozilla/LinkedList.h" #include "mozilla/NullPtr.h" #include "mozilla/PodOperations.h" @@ -20,7 +21,7 @@ #include "js/TypeDecls.h" -#if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING) || defined(DEBUG) +#if defined(JSGC_USE_EXACT_ROOTING) || defined(JS_DEBUG) # define JSGC_TRACK_EXACT_ROOTS #endif @@ -32,23 +33,25 @@ class CallArgs; template class Rooted; -class JS_PUBLIC_API(AutoGCRooter); - -class JS_PUBLIC_API(CompileOptions); -class JS_PUBLIC_API(ReadOnlyCompileOptions); -class JS_PUBLIC_API(OwningCompileOptions); +class JS_FRIEND_API(CompileOptions); +class JS_FRIEND_API(ReadOnlyCompileOptions); +class JS_FRIEND_API(OwningCompileOptions); class JS_PUBLIC_API(CompartmentOptions); struct Zone; } /* namespace JS */ +namespace js { +struct ContextFriendFields; +} // namespace js + /* * Run-time version enumeration. For compile-time version checking, please use * the JS_HAS_* macros in jsversion.h, or use MOZJS_MAJOR_VERSION, * MOZJS_MINOR_VERSION, MOZJS_PATCH_VERSION, and MOZJS_ALPHA definitions. */ -typedef enum JSVersion { +enum JSVersion { JSVERSION_ECMA_3 = 148, JSVERSION_1_6 = 160, JSVERSION_1_7 = 170, @@ -57,10 +60,10 @@ typedef enum JSVersion { JSVERSION_DEFAULT = 0, JSVERSION_UNKNOWN = -1, JSVERSION_LATEST = JSVERSION_ECMA_5 -} JSVersion; +}; /* Result of typeof operator enumeration. */ -typedef enum JSType { +enum JSType { JSTYPE_VOID, /* undefined */ JSTYPE_OBJECT, /* object */ JSTYPE_FUNCTION, /* function */ @@ -68,44 +71,23 @@ typedef enum JSType { JSTYPE_NUMBER, /* number */ JSTYPE_BOOLEAN, /* boolean */ JSTYPE_NULL, /* null */ + JSTYPE_SYMBOL, /* symbol */ JSTYPE_LIMIT -} JSType; +}; /* Dense index into cached prototypes and class atoms for standard objects. */ -typedef enum JSProtoKey { +enum JSProtoKey { #define PROTOKEY_AND_INITIALIZER(name,code,init,clasp) JSProto_##name = code, JS_FOR_EACH_PROTOTYPE(PROTOKEY_AND_INITIALIZER) #undef PROTOKEY_AND_INITIALIZER JSProto_LIMIT -} JSProtoKey; - -/* js_CheckAccess mode enumeration. */ -typedef enum JSAccessMode { - JSACC_PROTO = 0, /* XXXbe redundant w.r.t. id */ - - /* - * enum value #1 formerly called JSACC_PARENT, - * gap preserved for ABI compatibility. - */ - - /* - * enum value #2 formerly called JSACC_IMPORT, - * gap preserved for ABI compatibility. - */ - - JSACC_WATCH = 3, /* a watchpoint on object foo for id 'bar' */ - JSACC_READ = 4, /* a "get" of foo.bar */ - JSACC_WRITE = 8, /* a "set" of foo.bar = baz */ - JSACC_LIMIT -} JSAccessMode; - -#define JSACC_TYPEMASK (JSACC_WRITE - 1) +}; /* * This enum type is used to control the behavior of a JSObject property * iterator function that has type JSNewEnumerate. */ -typedef enum JSIterateOp { +enum JSIterateOp { /* Create new iterator state over enumerable properties. */ JSENUMERATE_INIT, @@ -117,12 +99,13 @@ typedef enum JSIterateOp { /* Destroy iterator state. */ JSENUMERATE_DESTROY -} JSIterateOp; +}; -/* See JSVAL_TRACE_KIND and JSTraceCallback in jsapi.h. */ -typedef enum { +/* See Value::gcKind() and JSTraceCallback in Tracer.h. */ +enum JSGCTraceKind { JSTRACE_OBJECT, JSTRACE_STRING, + JSTRACE_SYMBOL, JSTRACE_SCRIPT, /* @@ -130,37 +113,36 @@ typedef enum { * it implements JSTraceCallback. */ JSTRACE_LAZY_SCRIPT, - JSTRACE_IONCODE, + JSTRACE_JITCODE, JSTRACE_SHAPE, JSTRACE_BASE_SHAPE, JSTRACE_TYPE_OBJECT, JSTRACE_LAST = JSTRACE_TYPE_OBJECT -} JSGCTraceKind; - -/* Struct typedefs and class forward declarations. */ -typedef struct JSClass JSClass; -typedef struct JSCompartment JSCompartment; -typedef struct JSConstDoubleSpec JSConstDoubleSpec; -typedef struct JSCrossCompartmentCall JSCrossCompartmentCall; -typedef struct JSErrorReport JSErrorReport; -typedef struct JSExceptionState JSExceptionState; -typedef struct JSFunctionSpec JSFunctionSpec; -typedef struct JSIdArray JSIdArray; -typedef struct JSLocaleCallbacks JSLocaleCallbacks; -typedef struct JSObjectMap JSObjectMap; -typedef struct JSPrincipals JSPrincipals; -typedef struct JSPropertyDescriptor JSPropertyDescriptor; -typedef struct JSPropertyName JSPropertyName; -typedef struct JSPropertySpec JSPropertySpec; -typedef struct JSRuntime JSRuntime; -typedef struct JSSecurityCallbacks JSSecurityCallbacks; -typedef struct JSStructuredCloneCallbacks JSStructuredCloneCallbacks; -typedef struct JSStructuredCloneReader JSStructuredCloneReader; -typedef struct JSStructuredCloneWriter JSStructuredCloneWriter; -typedef struct JSTracer JSTracer; - -class JSFlatString; -class JSStableString; // long story +}; + +/* Struct forward declarations. */ +struct JSClass; +struct JSCompartment; +struct JSConstDoubleSpec; +struct JSCrossCompartmentCall; +struct JSErrorReport; +struct JSExceptionState; +struct JSFunctionSpec; +struct JSIdArray; +struct JSLocaleCallbacks; +struct JSObjectMap; +struct JSPrincipals; +struct JSPropertyDescriptor; +struct JSPropertyName; +struct JSPropertySpec; +struct JSRuntime; +struct JSSecurityCallbacks; +struct JSStructuredCloneCallbacks; +struct JSStructuredCloneReader; +struct JSStructuredCloneWriter; +class JS_PUBLIC_API(JSTracer); + +class JSFlatString; #ifdef JS_THREADSAFE typedef struct PRCallOnceType JSCallOnceType; @@ -182,6 +164,7 @@ namespace js { namespace gc { class StoreBuffer; void MarkPersistentRootedChains(JSTracer *); +void FinishPersistentRootedChains(JSRuntime *); } } @@ -197,24 +180,18 @@ struct Runtime bool needsBarrier_; #ifdef JSGC_GENERATIONAL - /* Allow inlining of Nursery::isInside. */ - uintptr_t gcNurseryStart_; - uintptr_t gcNurseryEnd_; - private: js::gc::StoreBuffer *gcStoreBufferPtr_; #endif public: - Runtime( + explicit Runtime( #ifdef JSGC_GENERATIONAL js::gc::StoreBuffer *storeBuffer #endif ) : needsBarrier_(false) #ifdef JSGC_GENERATIONAL - , gcNurseryStart_(0) - , gcNurseryEnd_(0) , gcStoreBufferPtr_(storeBuffer) #endif {} @@ -235,7 +212,7 @@ struct Runtime private: template friend class JS::PersistentRooted; friend void js::gc::MarkPersistentRootedChains(JSTracer *); - friend void ::js_FinishGC(JSRuntime *rt); + friend void js::gc::FinishPersistentRootedChains(JSRuntime *rt); mozilla::LinkedList functionPersistentRooteds; mozilla::LinkedList idPersistentRooteds; @@ -274,6 +251,75 @@ inline mozilla::LinkedList &Runtime::getPersistentRootedList() { return valuePersistentRooteds; } } /* namespace shadow */ + +class JS_PUBLIC_API(AutoGCRooter) +{ + public: + AutoGCRooter(JSContext *cx, ptrdiff_t tag); + AutoGCRooter(js::ContextFriendFields *cx, ptrdiff_t tag); + + ~AutoGCRooter() { + MOZ_ASSERT(this == *stackTop); + *stackTop = down; + } + + /* Implemented in gc/RootMarking.cpp. */ + inline void trace(JSTracer *trc); + static void traceAll(JSTracer *trc); + static void traceAllWrappers(JSTracer *trc); + + /* T must be a context type */ + template + static void traceAllInContext(T* cx, JSTracer *trc) { + for (AutoGCRooter *gcr = cx->autoGCRooters; gcr; gcr = gcr->down) + gcr->trace(trc); + } + + protected: + AutoGCRooter * const down; + + /* + * Discriminates actual subclass of this being used. If non-negative, the + * subclass roots an array of values of the length stored in this field. + * If negative, meaning is indicated by the corresponding value in the enum + * below. Any other negative value indicates some deeper problem such as + * memory corruption. + */ + ptrdiff_t tag_; + + enum { + VALARRAY = -2, /* js::AutoValueArray */ + PARSER = -3, /* js::frontend::Parser */ + SHAPEVECTOR = -4, /* js::AutoShapeVector */ + IDARRAY = -6, /* js::AutoIdArray */ + DESCVECTOR = -7, /* js::AutoPropDescVector */ + VALVECTOR = -10, /* js::AutoValueVector */ + IDVECTOR = -13, /* js::AutoIdVector */ + OBJVECTOR = -14, /* js::AutoObjectVector */ + STRINGVECTOR =-15, /* js::AutoStringVector */ + SCRIPTVECTOR =-16, /* js::AutoScriptVector */ + NAMEVECTOR = -17, /* js::AutoNameVector */ + HASHABLEVALUE=-18, /* js::HashableValue */ + IONMASM = -19, /* js::jit::MacroAssembler */ + IONALLOC = -20, /* js::jit::AutoTempAllocatorRooter */ + WRAPVECTOR = -21, /* js::AutoWrapperVector */ + WRAPPER = -22, /* js::AutoWrapperRooter */ + OBJOBJHASHMAP=-23, /* js::AutoObjectObjectHashMap */ + OBJU32HASHMAP=-24, /* js::AutoObjectUnsigned32HashMap */ + OBJHASHSET = -25, /* js::AutoObjectHashSet */ + JSONPARSER = -26, /* js::JSONParser */ + CUSTOM = -27, /* js::CustomAutoRooter */ + FUNVECTOR = -28 /* js::AutoFunctionVector */ + }; + + private: + AutoGCRooter ** const stackTop; + + /* No copy or assignment semantics. */ + AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; + void operator=(AutoGCRooter &ida) MOZ_DELETE; +}; + } /* namespace JS */ namespace js { @@ -287,13 +333,11 @@ namespace js { enum ParallelResult { TP_SUCCESS, TP_RETRY_SEQUENTIALLY, TP_RETRY_AFTER_GC, TP_FATAL }; struct ThreadSafeContext; -struct ForkJoinSlice; +class ForkJoinContext; class ExclusiveContext; class Allocator; -class SkipRoot; - enum ThingRootKind { THING_ROOT_OBJECT, @@ -301,14 +345,16 @@ enum ThingRootKind THING_ROOT_BASE_SHAPE, THING_ROOT_TYPE_OBJECT, THING_ROOT_STRING, - THING_ROOT_ION_CODE, + THING_ROOT_SYMBOL, + THING_ROOT_JIT_CODE, THING_ROOT_SCRIPT, + THING_ROOT_LAZY_SCRIPT, THING_ROOT_ID, - THING_ROOT_PROPERTY_ID, THING_ROOT_VALUE, THING_ROOT_TYPE, THING_ROOT_BINDINGS, THING_ROOT_PROPERTY_DESCRIPTOR, + THING_ROOT_PROP_DESC, THING_ROOT_LIMIT }; @@ -343,6 +389,7 @@ template <> struct RootKind : SpecificRootKind struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; @@ -364,9 +411,6 @@ struct ContextFriendFields { #ifdef JSGC_TRACK_EXACT_ROOTS mozilla::PodArrayZero(thingGCRooters); -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - skipGCRooters = nullptr; #endif } @@ -379,31 +423,31 @@ struct ContextFriendFields } #ifdef JSGC_TRACK_EXACT_ROOTS + private: /* * Stack allocated GC roots for stack GC heap pointers, which may be * overwritten if moved during a GC. */ JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* - * Stack allocated list of stack locations which hold non-relocatable - * GC heap pointers (where the target is rooted somewhere else) or integer - * values which may be confused for GC heap pointers. These are used to - * suppress false positives which occur when a rooting analysis treats the - * location as holding a relocatable pointer, but have no other effect on - * GC behavior. - */ - SkipRoot *skipGCRooters; + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } + #endif + void checkNoGCRooters(); + /* Stack of thread-stack-allocated GC roots. */ JS::AutoGCRooter *autoGCRooters; friend JSRuntime *GetRuntime(const JSContext *cx); friend JSCompartment *GetContextCompartment(const JSContext *cx); friend JS::Zone *GetContextZone(const JSContext *cx); + template friend class JS::Rooted; }; /* @@ -447,7 +491,7 @@ struct PerThreadDataFriendFields struct PerThreadDummy { void *field1; uintptr_t field2; -#ifdef DEBUG +#ifdef JS_DEBUG uint64_t field3; #endif } mainThread; @@ -458,23 +502,19 @@ struct PerThreadDataFriendFields PerThreadDataFriendFields(); #ifdef JSGC_TRACK_EXACT_ROOTS + private: /* * Stack allocated GC roots for stack GC heap pointers, which may be * overwritten if moved during a GC. */ JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* - * Stack allocated list of stack locations which hold non-relocatable - * GC heap pointers (where the target is rooted somewhere else) or integer - * values which may be confused for GC heap pointers. These are used to - * suppress false positives which occur when a rooting analysis treats the - * location as holding a relocatable pointer, but have no other effect on - * GC behavior. - */ - SkipRoot *skipGCRooters; + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } #endif /* Limit pointer for checking native stack consumption. */ @@ -499,6 +539,8 @@ struct PerThreadDataFriendFields return reinterpret_cast( reinterpret_cast(rt) + RuntimeMainThreadOffset); } + + template friend class JS::Rooted; }; } /* namespace js */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/jstypes.h b/frameworks/js-bindings/external/spidermonkey/include/linux/jstypes.h index d5b15ccb1d..e9927bca0d 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/jstypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/jstypes.h @@ -77,8 +77,13 @@ # define JS_PUBLIC_DATA(t) MOZ_IMPORT_DATA t #endif -#define JS_FRIEND_API(t) JS_PUBLIC_API(t) -#define JS_FRIEND_DATA(t) JS_PUBLIC_DATA(t) +#if defined(STATIC_JS_API) || defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API) +# define JS_FRIEND_API(t) MOZ_EXPORT t +# define JS_FRIEND_DATA(t) MOZ_EXPORT t +#else +# define JS_FRIEND_API(t) MOZ_IMPORT_API t +# define JS_FRIEND_DATA(t) MOZ_IMPORT_DATA t +#endif #if defined(_MSC_VER) && defined(_M_IX86) #define JS_FASTCALL __fastcall @@ -89,22 +94,6 @@ #define JS_NO_FASTCALL #endif -#ifndef JS_ALWAYS_INLINE -#define JS_ALWAYS_INLINE MOZ_ALWAYS_INLINE -#endif - -#ifndef JS_NEVER_INLINE -#define JS_NEVER_INLINE MOZ_NEVER_INLINE -#endif - -#ifndef JS_WARN_UNUSED_RESULT -# if defined __GNUC__ -# define JS_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -# else -# define JS_WARN_UNUSED_RESULT -# endif -#endif - /*********************************************************************** ** MACROS: JS_BEGIN_MACRO ** JS_END_MACRO @@ -122,15 +111,6 @@ # define JS_END_MACRO } while (0) #endif -/*********************************************************************** -** MACROS: JS_BEGIN_EXTERN_C -** JS_END_EXTERN_C -** DESCRIPTION: -** Macro shorthands for conditional C++ extern block delimiters. -***********************************************************************/ -#define JS_BEGIN_EXTERN_C MOZ_BEGIN_EXTERN_C -#define JS_END_EXTERN_C MOZ_END_EXTERN_C - /*********************************************************************** ** MACROS: JS_BIT ** JS_BITMASK @@ -143,8 +123,6 @@ /*********************************************************************** ** MACROS: JS_HOWMANY ** JS_ROUNDUP -** JS_MIN -** JS_MAX ** DESCRIPTION: ** Commonly used macros for operations on compatible types. ***********************************************************************/ @@ -183,34 +161,6 @@ # error "Implement me" #endif -/*********************************************************************** -** MACROS: JS_LIKELY -** JS_UNLIKELY -** DESCRIPTION: -** These macros allow you to give a hint to the compiler about branch -** probability so that it can better optimize. Use them like this: -** -** if (JS_LIKELY(v == 1)) { -** ... expected code path ... -** } -** -** if (JS_UNLIKELY(v == 0)) { -** ... non-expected code path ... -** } -** -***********************************************************************/ -#ifdef __GNUC__ - -# define JS_LIKELY(x) (__builtin_expect((x), 1)) -# define JS_UNLIKELY(x) (__builtin_expect((x), 0)) - -#else - -# define JS_LIKELY(x) (x) -# define JS_UNLIKELY(x) (x) - -#endif - /*********************************************************************** ** MACROS: JS_ARRAY_LENGTH ** JS_ARRAY_END diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/jsversion.h b/frameworks/js-bindings/external/spidermonkey/include/linux/jsversion.h index 827a56981d..1f31e40b5e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/jsversion.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/jsversion.h @@ -25,6 +25,9 @@ #define JS_HAS_DESTRUCTURING 2 /* has [a,b] = ... or {p:a,q:b} = ... */ #define JS_HAS_GENERATOR_EXPRS 1 /* has (expr for (lhs in iterable)) */ #define JS_HAS_EXPR_CLOSURES 1 /* has function (formals) listexpr */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_TEMPLATE_STRINGS 1 /* has template string support */ +#endif /* Support for JS_NewGlobalObject. */ #define JS_HAS_NEW_GLOBAL_OBJECT 1 @@ -41,14 +44,9 @@ */ #define JS_OLD_GETTER_SETTER_METHODS 1 -/* A kill-switch for bug 586842. Embedders shouldn't touch this! */ -#define JS_USE_NEW_OBJECT_REPRESENTATION 0 - -#if JS_USE_NEW_OBJECT_REPRESENTATION -# define JS_NEW_OBJECT_REPRESENTATION_ONLY() ((void)0) -#else -# define JS_NEW_OBJECT_REPRESENTATION_ONLY() \ - MOZ_ASSUME_UNREACHABLE("don't call this! to be used in the new object representation") +/* Support for Symbols - Nightly-only for now. */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_SYMBOLS 1 #endif #endif /* jsversion_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/jswrapper.h b/frameworks/js-bindings/external/spidermonkey/include/linux/jswrapper.h index 1bf1e16664..a8a510c4f7 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/jswrapper.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/jswrapper.h @@ -15,6 +15,35 @@ namespace js { class DummyFrameGuard; +/* + * Helper for Wrapper::New default options. + * + * Callers of Wrapper::New() who wish to specify a prototype for the created + * Wrapper, *MUST* construct a WrapperOptions with a JSContext. + */ +class MOZ_STACK_CLASS WrapperOptions : public ProxyOptions { + public: + WrapperOptions() : ProxyOptions(false, nullptr), + proto_() + {} + + explicit WrapperOptions(JSContext *cx) : ProxyOptions(false, nullptr), + proto_() + { + proto_.construct(cx); + } + + inline JSObject *proto() const; + WrapperOptions &setProto(JSObject *protoArg) { + JS_ASSERT(!proto_.empty()); + proto_.ref() = protoArg; + return *this; + } + + private: + mozilla::Maybe proto_; +}; + /* * A wrapper is a proxy with a target object to which it generally forwards * operations, but may restrict access to certain operations or instrument @@ -27,7 +56,6 @@ class DummyFrameGuard; class JS_FRIEND_API(Wrapper) : public DirectProxyHandler { unsigned mFlags; - bool mSafeToUnwrap; public: using BaseProxyHandler::Action; @@ -38,23 +66,14 @@ class JS_FRIEND_API(Wrapper) : public DirectProxyHandler }; virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; - /* - * Wrappers can explicitly specify that they are unsafe to unwrap from a - * security perspective (as is the case for SecurityWrappers). If a wrapper - * is not safe to unwrap, operations requiring full access to the underlying - * object (via CheckedUnwrap) will throw. Otherwise, they will succeed. - */ - void setSafeToUnwrap(bool safe) { mSafeToUnwrap = safe; } - bool isSafeToUnwrap() { return mSafeToUnwrap; } + static JSObject *New(JSContext *cx, JSObject *obj, JSObject *parent, const Wrapper *handler, + const WrapperOptions *options = nullptr); - static JSObject *New(JSContext *cx, JSObject *obj, JSObject *proto, - JSObject *parent, Wrapper *handler); + static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, const Wrapper *handler); - static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, Wrapper *handler); - - static Wrapper *wrapperHandler(JSObject *wrapper); + static const Wrapper *wrapperHandler(JSObject *wrapper); static JSObject *wrappedObject(JSObject *wrapper); @@ -62,68 +81,78 @@ class JS_FRIEND_API(Wrapper) : public DirectProxyHandler return mFlags; } - explicit Wrapper(unsigned flags, bool hasPrototype = false); + explicit Wrapper(unsigned flags, bool hasPrototype = false, bool hasSecurityPolicy = false); virtual ~Wrapper(); - virtual bool finalizeInBackground(Value priv) MOZ_OVERRIDE; + virtual bool finalizeInBackground(Value priv) const MOZ_OVERRIDE; + + static const Wrapper singleton; + static const Wrapper singletonWithPrototype; - static Wrapper singleton; - static Wrapper singletonWithPrototype; + static JSObject *defaultProto; }; +inline JSObject * +WrapperOptions::proto() const +{ + return proto_.empty() ? Wrapper::defaultProto : proto_.ref(); +} + /* Base class for all cross compartment wrapper handlers. */ class JS_FRIEND_API(CrossCompartmentWrapper) : public Wrapper { public: - CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false); + explicit CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false, + bool hasSecurityPolicy = false); virtual ~CrossCompartmentWrapper(); /* ES5 Harmony fundamental wrapper traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, - AutoIdVector &props) MOZ_OVERRIDE; - virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; /* ES5 Harmony derived wrapper traps. */ - virtual bool has(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool hasOwn(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; + virtual bool has(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool hasOwn(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; virtual bool get(JSContext *cx, HandleObject wrapper, HandleObject receiver, - HandleId id, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool set(JSContext *cx, HandleObject wrapper, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool keys(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool keys(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; virtual bool iterate(JSContext *cx, HandleObject wrapper, unsigned flags, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject wrapper, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject wrapper, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject wrapper, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual JSString *fun_toString(JSContext *cx, HandleObject wrapper, - unsigned indent) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; - static CrossCompartmentWrapper singleton; - static CrossCompartmentWrapper singletonWithPrototype; + static const CrossCompartmentWrapper singleton; + static const CrossCompartmentWrapper singletonWithPrototype; }; /* @@ -139,25 +168,28 @@ template class JS_FRIEND_API(SecurityWrapper) : public Base { public: - SecurityWrapper(unsigned flags); + explicit SecurityWrapper(unsigned flags, bool hasPrototype = false); - virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) MOZ_OVERRIDE; - virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Wrapper::Action act, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; + + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable) MOZ_OVERRIDE; - virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) MOZ_OVERRIDE; + JS::HandleObject callable) const MOZ_OVERRIDE; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const MOZ_OVERRIDE; /* * Allow our subclasses to select the superclass behavior they want without @@ -179,48 +211,42 @@ class JS_FRIEND_API(DeadObjectProxy) : public BaseProxyHandler explicit DeadObjectProxy(); /* ES5 Harmony fundamental wrapper traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, - AutoIdVector &props) MOZ_OVERRIDE; - virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; - virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver, - uint32_t index, MutableHandleValue vp, - bool *present) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, - MutableHandleObject protop) MOZ_OVERRIDE; + MutableHandleObject protop) const MOZ_OVERRIDE; - static DeadObjectProxy singleton; + static const DeadObjectProxy singleton; }; extern JSObject * TransparentObjectWrapper(JSContext *cx, HandleObject existing, HandleObject obj, - HandleObject wrappedProto, HandleObject parent, - unsigned flags); + HandleObject parent, unsigned flags); // Proxy family for wrappers. Public so that IsWrapper() can be fully inlined by // jsfriendapi users. @@ -295,8 +321,8 @@ RecomputeWrappers(JSContext *cx, const CompartmentFilter &sourceFilter, struct JS_FRIEND_API(AutoMaybeTouchDeadZones) { // The version that takes an object just uses it for its runtime. - AutoMaybeTouchDeadZones(JSContext *cx); - AutoMaybeTouchDeadZones(JSObject *obj); + explicit AutoMaybeTouchDeadZones(JSContext *cx); + explicit AutoMaybeTouchDeadZones(JSObject *obj); ~AutoMaybeTouchDeadZones(); private: diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Alignment.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Alignment.h index 29599d0ef1..0ac8a48779 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Alignment.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Alignment.h @@ -21,14 +21,14 @@ namespace mozilla { template class AlignmentFinder { - struct Aligner - { - char c; - T t; - }; - - public: - static const size_t alignment = sizeof(Aligner) - sizeof(T); + struct Aligner + { + char mChar; + T mT; + }; + +public: + static const size_t alignment = sizeof(Aligner) - sizeof(T); }; #define MOZ_ALIGNOF(T) mozilla::AlignmentFinder::alignment @@ -64,38 +64,38 @@ template struct AlignedElem; /* - * We have to specialize this template because GCC doesn't like __attribute__((aligned(foo))) where - * foo is a template parameter. + * We have to specialize this template because GCC doesn't like + * __attribute__((aligned(foo))) where foo is a template parameter. */ template<> struct AlignedElem<1> { - MOZ_ALIGNED_DECL(uint8_t elem, 1); + MOZ_ALIGNED_DECL(uint8_t elem, 1); }; template<> struct AlignedElem<2> { - MOZ_ALIGNED_DECL(uint8_t elem, 2); + MOZ_ALIGNED_DECL(uint8_t elem, 2); }; template<> struct AlignedElem<4> { - MOZ_ALIGNED_DECL(uint8_t elem, 4); + MOZ_ALIGNED_DECL(uint8_t elem, 4); }; template<> struct AlignedElem<8> { - MOZ_ALIGNED_DECL(uint8_t elem, 8); + MOZ_ALIGNED_DECL(uint8_t elem, 8); }; template<> struct AlignedElem<16> { - MOZ_ALIGNED_DECL(uint8_t elem, 16); + MOZ_ALIGNED_DECL(uint8_t elem, 16); }; /* @@ -111,25 +111,27 @@ struct AlignedElem<16> template struct AlignedStorage { - union U { - char bytes[Nbytes]; - uint64_t _; - } u; - - const void* addr() const { return u.bytes; } - void* addr() { return u.bytes; } + union U + { + char mBytes[Nbytes]; + uint64_t mDummy; + } u; + + const void* addr() const { return u.mBytes; } + void* addr() { return u.mBytes; } }; template struct AlignedStorage2 { - union U { - char bytes[sizeof(T)]; - uint64_t _; - } u; - - const T* addr() const { return reinterpret_cast(u.bytes); } - T* addr() { return static_cast(static_cast(u.bytes)); } + union U + { + char mBytes[sizeof(T)]; + uint64_t mDummy; + } u; + + const T* addr() const { return reinterpret_cast(u.mBytes); } + T* addr() { return static_cast(static_cast(u.mBytes)); } }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/AllocPolicy.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/AllocPolicy.h index 20087e93bb..357c632a02 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/AllocPolicy.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/AllocPolicy.h @@ -49,14 +49,31 @@ namespace mozilla { */ class MallocAllocPolicy { - public: - void* malloc_(size_t bytes) { return malloc(bytes); } - void* calloc_(size_t bytes) { return calloc(bytes, 1); } - void* realloc_(void* p, size_t oldBytes, size_t bytes) { return realloc(p, bytes); } - void free_(void* p) { free(p); } - void reportAllocOverflow() const {} -}; +public: + void* malloc_(size_t aBytes) + { + return malloc(aBytes); + } + + void* calloc_(size_t aBytes) + { + return calloc(aBytes, 1); + } + + void* realloc_(void* aPtr, size_t aOldBytes, size_t aBytes) + { + return realloc(aPtr, aBytes); + } + void free_(void* aPtr) + { + free(aPtr); + } + + void reportAllocOverflow() const + { + } +}; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Array.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Array.h index 5af9aaa133..b2ab578d4b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Array.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Array.h @@ -19,31 +19,35 @@ namespace mozilla { template class Array { - T arr[Length]; - - public: - T& operator[](size_t i) { - MOZ_ASSERT(i < Length); - return arr[i]; - } - - const T& operator[](size_t i) const { - MOZ_ASSERT(i < Length); - return arr[i]; - } + T mArr[Length]; + +public: + T& operator[](size_t aIndex) + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } + + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } }; template class Array { - public: - T& operator[](size_t i) { - MOZ_ASSUME_UNREACHABLE("indexing into zero-length array"); - } - - const T& operator[](size_t i) const { - MOZ_ASSUME_UNREACHABLE("indexing into zero-length array"); - } +public: + T& operator[](size_t aIndex) + { + MOZ_CRASH("indexing into zero-length array"); + } + + const T& operator[](size_t aIndex) const + { + MOZ_CRASH("indexing into zero-length array"); + } }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ArrayUtils.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ArrayUtils.h index e2226bf59d..44f5980c44 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ArrayUtils.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ArrayUtils.h @@ -18,22 +18,24 @@ #ifdef __cplusplus +#include "mozilla/Alignment.h" #include "mozilla/Array.h" +#include "mozilla/TypeTraits.h" namespace mozilla { /* - * Safely subtract two pointers when it is known that end >= begin. This avoids - * the common compiler bug that if (size_t(end) - size_t(begin)) has the MSB - * set, the unsigned subtraction followed by right shift will produce -1, or - * size_t(-1), instead of the real difference. + * Safely subtract two pointers when it is known that aEnd >= aBegin. This + * avoids the common compiler bug that if (size_t(aEnd) - size_t(aBegin)) has + * the MSB set, the unsigned subtraction followed by right shift will produce + * -1, or size_t(-1), instead of the real difference. */ template MOZ_ALWAYS_INLINE size_t -PointerRangeSize(T* begin, T* end) +PointerRangeSize(T* aBegin, T* aEnd) { - MOZ_ASSERT(end >= begin); - return (size_t(end) - size_t(begin)) / sizeof(T); + MOZ_ASSERT(aEnd >= aBegin); + return (size_t(aEnd) - size_t(aBegin)) / sizeof(T); } /* @@ -44,14 +46,14 @@ PointerRangeSize(T* begin, T* end) */ template MOZ_CONSTEXPR size_t -ArrayLength(T (&arr)[N]) +ArrayLength(T (&aArr)[N]) { return N; } template MOZ_CONSTEXPR size_t -ArrayLength(const Array& arr) +ArrayLength(const Array& aArr) { return N; } @@ -63,25 +65,100 @@ ArrayLength(const Array& arr) */ template MOZ_CONSTEXPR T* -ArrayEnd(T (&arr)[N]) +ArrayEnd(T (&aArr)[N]) { - return arr + ArrayLength(arr); + return aArr + ArrayLength(aArr); } template MOZ_CONSTEXPR T* -ArrayEnd(Array& arr) +ArrayEnd(Array& aArr) { - return &arr[0] + ArrayLength(arr); + return &aArr[0] + ArrayLength(aArr); } template MOZ_CONSTEXPR const T* -ArrayEnd(const Array& arr) +ArrayEnd(const Array& aArr) { - return &arr[0] + ArrayLength(arr); + return &aArr[0] + ArrayLength(aArr); } +namespace detail { + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % MOZ_ALIGNOF(AlignType)) == 0, + "performing a range-check with a misaligned pointer"); + } +}; + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + } +}; + +} // namespace detail + +/** + * Determines whether |aPtr| points at an object in the range [aBegin, aEnd). + * + * |aPtr| must have the same alignment as |aBegin| and |aEnd|. This usually + * should be achieved by ensuring |aPtr| points at a |U|, not just that it + * points at a |T|. + * + * It is a usage error for any argument to be misaligned. + * + * It's okay for T* to be void*, and if so U* may also be void*. In the latter + * case no argument is required to be aligned (obviously, as void* implies no + * particular alignment). + */ +template +inline typename EnableIf::value || + IsBaseOf::value || + IsVoid::value, + bool>::Type +IsInRange(T* aPtr, U* aBegin, U* aEnd) +{ + MOZ_ASSERT(aBegin <= aEnd); + detail::AlignedChecker::test(aPtr); + detail::AlignedChecker::test(aBegin); + detail::AlignedChecker::test(aEnd); + return aBegin <= static_cast(aPtr) && static_cast(aPtr) < aEnd; +} + +/** + * Convenience version of the above method when the valid range is specified as + * uintptr_t values. As above, |aPtr| must be aligned, and |aBegin| and |aEnd| + * must be aligned with respect to |T|. + */ +template +inline bool +IsInRange(T* aPtr, uintptr_t aBegin, uintptr_t aEnd) +{ + return IsInRange(aPtr, + reinterpret_cast(aBegin), reinterpret_cast(aEnd)); +} + +namespace detail { + +/* + * Helper for the MOZ_ARRAY_LENGTH() macro to make the length a typesafe + * compile-time constant even on compilers lacking constexpr support. + */ +template +char (&ArrayLengthHelper(T (&array)[N]))[N]; + +} /* namespace detail */ + } /* namespace mozilla */ #endif /* __cplusplus */ @@ -91,8 +168,8 @@ ArrayEnd(const Array& arr) * that can't use C++ template functions and for static_assert() calls that * can't call ArrayLength() when it is not a C++11 constexpr function. */ -#ifdef MOZ_HAVE_CXX11_CONSTEXPR -# define MOZ_ARRAY_LENGTH(array) mozilla::ArrayLength(array) +#ifdef __cplusplus +# define MOZ_ARRAY_LENGTH(array) sizeof(mozilla::detail::ArrayLengthHelper(array)) #else # define MOZ_ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0])) #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Assertions.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Assertions.h index 8a5fa205f9..a463b2768d 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Assertions.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Assertions.h @@ -9,9 +9,17 @@ #ifndef mozilla_Assertions_h #define mozilla_Assertions_h +#if defined(MOZILLA_INTERNAL_API) && defined(__cplusplus) +#define MOZ_DUMP_ASSERTION_STACK +#endif + #include "mozilla/Attributes.h" #include "mozilla/Compiler.h" #include "mozilla/Likely.h" +#include "mozilla/MacroArgs.h" +#ifdef MOZ_DUMP_ASSERTION_STACK +#include "nsTraceRefcnt.h" +#endif #include #include @@ -24,13 +32,13 @@ * number of undesired macros and symbols. */ # ifdef __cplusplus - extern "C" { +extern "C" { # endif - __declspec(dllimport) int __stdcall - TerminateProcess(void* hProcess, unsigned int uExitCode); - __declspec(dllimport) void* __stdcall GetCurrentProcess(void); +__declspec(dllimport) int __stdcall +TerminateProcess(void* hProcess, unsigned int uExitCode); +__declspec(dllimport) void* __stdcall GetCurrentProcess(void); # ifdef __cplusplus - } +} # endif #else # include @@ -116,33 +124,42 @@ extern "C" { #endif /* - * Prints |s| as an assertion failure (using file and ln as the location of the - * assertion) to the standard debug-output channel. + * Prints |aStr| as an assertion failure (using aFilename and aLine as the + * location of the assertion) to the standard debug-output channel. * * Usually you should use MOZ_ASSERT or MOZ_CRASH instead of this method. This * method is primarily for internal use in this header, and only secondarily * for use in implementing release-build assertions. */ static MOZ_ALWAYS_INLINE void -MOZ_ReportAssertionFailure(const char* s, const char* file, int ln) +MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS { #ifdef ANDROID __android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert", - "Assertion failure: %s, at %s:%d\n", s, file, ln); + "Assertion failure: %s, at %s:%d\n", + aStr, aFilename, aLine); #else - fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln); + fprintf(stderr, "Assertion failure: %s, at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif fflush(stderr); #endif } static MOZ_ALWAYS_INLINE void -MOZ_ReportCrash(const char* s, const char* file, int ln) +MOZ_ReportCrash(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS { #ifdef ANDROID - __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", - "Hit MOZ_CRASH(%s) at %s:%d\n", s, file, ln); + __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", + "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); #else - fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", s, file, ln); + fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif fflush(stderr); #endif } @@ -238,7 +255,7 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} do { \ MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \ MOZ_REALLY_CRASH(); \ - } while(0) + } while (0) #endif #ifdef __cplusplus @@ -279,52 +296,108 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} * MOZ_RELEASE_ASSERT, which applies to non-debug builds as well. */ +/* + * Implement MOZ_VALIDATE_ASSERT_CONDITION_TYPE, which is used to guard against + * accidentally passing something unintended in lieu of an assertion condition. + */ + +#ifdef __cplusplus +# if defined(__clang__) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# elif defined(__GNUC__) +// B2G GCC 4.4 has insufficient decltype support. +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# endif +# elif defined(_MSC_VER) +// Disabled for now because of insufficient decltype support. Bug 1004028. +# endif +#endif + +#ifdef MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# include "mozilla/TypeTraits.h" +namespace mozilla { +namespace detail { + +template +struct IsFunction +{ + static const bool value = false; +}; + +template +struct IsFunction +{ + static const bool value = true; +}; + +template +void ValidateAssertConditionType() +{ + typedef typename RemoveReference::Type ValueT; + static_assert(!IsArray::value, + "Expected boolean assertion condition, got an array or a " + "string!"); + static_assert(!IsFunction::value, + "Expected boolean assertion condition, got a function! Did " + "you intend to call that function?"); + static_assert(!IsFloatingPoint::value, + "It's often a bad idea to assert that a floating-point number " + "is nonzero, because such assertions tend to intermittently " + "fail. Shouldn't your code gracefully handle this case instead " + "of asserting? Anyway, if you really want to do that, write an " + "explicit boolean condition, like !!x or x!=0."); +} + +} // namespace detail +} // namespace mozilla +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) \ + mozilla::detail::ValidateAssertConditionType() +#else +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) +#endif + /* First the single-argument form. */ #define MOZ_ASSERT_HELPER1(expr) \ - do { \ - if (MOZ_UNLIKELY(!(expr))) { \ - MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } \ - } while (0) + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) /* Now the two-argument form. */ #define MOZ_ASSERT_HELPER2(expr, explain) \ - do { \ - if (MOZ_UNLIKELY(!(expr))) { \ - MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } \ - } while (0) -/* And now, helper macrology up the wazoo. */ -/* - * Count the number of arguments passed to MOZ_ASSERT, very carefully - * tiptoeing around an MSVC bug where it improperly expands __VA_ARGS__ as a - * single token in argument lists. See these URLs for details: - * - * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement - * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 - */ -#define MOZ_COUNT_ASSERT_ARGS_IMPL2(_1, _2, count, ...) \ - count -#define MOZ_COUNT_ASSERT_ARGS_IMPL(args) \ - MOZ_COUNT_ASSERT_ARGS_IMPL2 args -#define MOZ_COUNT_ASSERT_ARGS(...) \ - MOZ_COUNT_ASSERT_ARGS_IMPL((__VA_ARGS__, 2, 1, 0)) -/* Pick the right helper macro to invoke. */ -#define MOZ_ASSERT_CHOOSE_HELPER2(count) MOZ_ASSERT_HELPER##count -#define MOZ_ASSERT_CHOOSE_HELPER1(count) MOZ_ASSERT_CHOOSE_HELPER2(count) -#define MOZ_ASSERT_CHOOSE_HELPER(count) MOZ_ASSERT_CHOOSE_HELPER1(count) -/* The actual macros. */ -#define MOZ_ASSERT_GLUE(x, y) x y + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) + +#define MOZ_RELEASE_ASSERT_GLUE(a, b) a b #define MOZ_RELEASE_ASSERT(...) \ - MOZ_ASSERT_GLUE(MOZ_ASSERT_CHOOSE_HELPER(MOZ_COUNT_ASSERT_ARGS(__VA_ARGS__)), \ - (__VA_ARGS__)) + MOZ_RELEASE_ASSERT_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \ + (__VA_ARGS__)) + #ifdef DEBUG # define MOZ_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) #else -# define MOZ_ASSERT(...) do { } while(0) +# define MOZ_ASSERT(...) do { } while (0) #endif /* DEBUG */ +/* + * MOZ_NIGHTLY_ASSERT is defined for both debug and release builds on the + * Nightly channel, but only debug builds on Aurora, Beta, and Release. + */ +#if defined(NIGHTLY_BUILD) +# define MOZ_NIGHTLY_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) +#else +# define MOZ_NIGHTLY_ASSERT(...) MOZ_ASSERT(__VA_ARGS__) +#endif + /* * MOZ_ASSERT_IF(cond1, cond2) is equivalent to MOZ_ASSERT(cond2) if cond1 is * true. @@ -337,19 +410,20 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} #ifdef DEBUG # define MOZ_ASSERT_IF(cond, expr) \ do { \ - if (cond) \ + if (cond) { \ MOZ_ASSERT(expr); \ + } \ } while (0) #else # define MOZ_ASSERT_IF(cond, expr) do { } while (0) #endif /* - * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that it is - * undefined behavior for execution to reach this point. No guarantees are made - * about what will happen if this is reached at runtime. Most code should - * probably use the higher level MOZ_ASSUME_UNREACHABLE, which uses this when - * appropriate. + * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that + * it is undefined behavior for execution to reach this point. No guarantees + * are made about what will happen if this is reached at runtime. Most code + * should use MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE because it has extra + * asserts. */ #if defined(__clang__) # define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable() @@ -379,21 +453,22 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} #endif /* - * MOZ_ASSUME_UNREACHABLE([reason]) tells the compiler that it can assume that - * the macro call cannot be reached during execution. This lets the compiler - * generate better-optimized code under some circumstances, at the expense of - * the program's behavior being undefined if control reaches the - * MOZ_ASSUME_UNREACHABLE. + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE([reason]) tells the compiler that it + * can assume that the macro call cannot be reached during execution. This lets + * the compiler generate better-optimized code under some circumstances, at the + * expense of the program's behavior being undefined if control reaches the + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE. * * In Gecko, you probably should not use this macro outside of performance- or * size-critical code, because it's unsafe. If you don't care about code size * or performance, you should probably use MOZ_ASSERT or MOZ_CRASH. * * SpiderMonkey is a different beast, and there it's acceptable to use - * MOZ_ASSUME_UNREACHABLE more widely. + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE more widely. * - * Note that MOZ_ASSUME_UNREACHABLE is noreturn, so it's valid not to return a - * value following a MOZ_ASSUME_UNREACHABLE call. + * Note that MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE is noreturn, so it's valid + * not to return a value following a MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE + * call. * * Example usage: * @@ -413,19 +488,32 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} * case VALUE_FLOAT: * return (int) *(float*) value; * default: - * MOZ_ASSUME_UNREACHABLE("can only handle VALUE_INT and VALUE_FLOAT"); + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected ValueType"); * } * } */ -#if defined(DEBUG) -# define MOZ_ASSUME_UNREACHABLE(...) \ - do { \ - MOZ_ASSERT(false, "MOZ_ASSUME_UNREACHABLE(" __VA_ARGS__ ")"); \ - MOZ_ASSUME_UNREACHABLE_MARKER(); \ - } while (0) -#else -# define MOZ_ASSUME_UNREACHABLE(reason) MOZ_ASSUME_UNREACHABLE_MARKER() -#endif + +/* + * Assert in all debug builds plus the Nightly channel's release builds. Take + * this extra testing precaution because hitting MOZ_ASSUME_UNREACHABLE_MARKER + * could trigger exploitable undefined behavior. + */ +#define MOZ_ASSERT_UNREACHABLE(reason) \ + MOZ_NIGHTLY_ASSERT(false, "MOZ_ASSERT_UNREACHABLE: " reason) + +#define MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) \ + do { \ + MOZ_ASSERT_UNREACHABLE(reason); \ + MOZ_ASSUME_UNREACHABLE_MARKER(); \ + } while (0) + +/* + * TODO: Bug 990764: Audit all MOZ_ASSUME_UNREACHABLE calls and replace them + * with MOZ_ASSERT_UNREACHABLE, MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE, or + * MOZ_CRASH. For now, preserve the macro's same meaning of unreachable. + */ +#define MOZ_ASSUME_UNREACHABLE(reason) \ + MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) /* * MOZ_ALWAYS_TRUE(expr) and MOZ_ALWAYS_FALSE(expr) always evaluate the provided @@ -441,4 +529,6 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} # define MOZ_ALWAYS_FALSE(expr) ((void)(expr)) #endif +#undef MOZ_DUMP_ASSERTION_STACK + #endif /* mozilla_Assertions_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Atomics.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Atomics.h index 03ae7c34f3..71d95c61ba 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Atomics.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Atomics.h @@ -41,6 +41,13 @@ # define MOZ_HAVE_CXX11_ATOMICS # endif #elif defined(_MSC_VER) && _MSC_VER >= 1700 +# if defined(DEBUG) + /* + * Provide our own failure code since we're having trouble linking to + * std::_Debug_message (bug 982310). + */ +# define _INVALID_MEMORY_ORDER MOZ_CRASH("Invalid memory order") +# endif # define MOZ_HAVE_CXX11_ATOMICS #endif @@ -107,6 +114,7 @@ enum MemoryOrdering { * ordering if you can't easily test non-x86 architectures! */ Relaxed, + /* * When an atomic value is updated with ReleaseAcquire ordering, and * that new value is observed with ReleaseAcquire ordering, prior @@ -128,6 +136,7 @@ enum MemoryOrdering { * a good, hard look at actual lock or mutex primitives first. */ ReleaseAcquire, + /* * When an atomic value is updated with SequentiallyConsistent * ordering, all writes observable when the update is observed, just @@ -177,126 +186,154 @@ template struct AtomicOrderConstraints; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_relaxed; - static const std::memory_order LoadOrder = std::memory_order_relaxed; - static const std::memory_order StoreOrder = std::memory_order_relaxed; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_relaxed; + static const std::memory_order AtomicRMWOrder = std::memory_order_relaxed; + static const std::memory_order LoadOrder = std::memory_order_relaxed; + static const std::memory_order StoreOrder = std::memory_order_relaxed; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_relaxed; }; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_acq_rel; - static const std::memory_order LoadOrder = std::memory_order_acquire; - static const std::memory_order StoreOrder = std::memory_order_release; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_acquire; + static const std::memory_order AtomicRMWOrder = std::memory_order_acq_rel; + static const std::memory_order LoadOrder = std::memory_order_acquire; + static const std::memory_order StoreOrder = std::memory_order_release; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_acquire; }; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_seq_cst; - static const std::memory_order LoadOrder = std::memory_order_seq_cst; - static const std::memory_order StoreOrder = std::memory_order_seq_cst; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_seq_cst; + static const std::memory_order AtomicRMWOrder = std::memory_order_seq_cst; + static const std::memory_order LoadOrder = std::memory_order_seq_cst; + static const std::memory_order StoreOrder = std::memory_order_seq_cst; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_seq_cst; }; template struct IntrinsicBase { - typedef std::atomic ValueType; - typedef AtomicOrderConstraints OrderedOp; + typedef std::atomic ValueType; + typedef AtomicOrderConstraints OrderedOp; }; template struct IntrinsicMemoryOps : public IntrinsicBase { - typedef IntrinsicBase Base; - static T load(const typename Base::ValueType& ptr) { - return ptr.load(Base::OrderedOp::LoadOrder); - } - static void store(typename Base::ValueType& ptr, T val) { - ptr.store(val, Base::OrderedOp::StoreOrder); - } - static T exchange(typename Base::ValueType& ptr, T val) { - return ptr.exchange(val, Base::OrderedOp::AtomicRMWOrder); - } - static bool compareExchange(typename Base::ValueType& ptr, T oldVal, T newVal) { - return ptr.compare_exchange_strong(oldVal, newVal, - Base::OrderedOp::AtomicRMWOrder, - Base::OrderedOp::CompareExchangeFailureOrder); - } + typedef IntrinsicBase Base; + + static T load(const typename Base::ValueType& aPtr) + { + return aPtr.load(Base::OrderedOp::LoadOrder); + } + + static void store(typename Base::ValueType& aPtr, T aVal) + { + aPtr.store(aVal, Base::OrderedOp::StoreOrder); + } + + static T exchange(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.exchange(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static bool compareExchange(typename Base::ValueType& aPtr, + T aOldVal, T aNewVal) + { + return aPtr.compare_exchange_strong(aOldVal, aNewVal, + Base::OrderedOp::AtomicRMWOrder, + Base::OrderedOp::CompareExchangeFailureOrder); + } }; template struct IntrinsicAddSub : public IntrinsicBase { - typedef IntrinsicBase Base; - static T add(typename Base::ValueType& ptr, T val) { - return ptr.fetch_add(val, Base::OrderedOp::AtomicRMWOrder); - } - static T sub(typename Base::ValueType& ptr, T val) { - return ptr.fetch_sub(val, Base::OrderedOp::AtomicRMWOrder); - } + typedef IntrinsicBase Base; + + static T add(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_add(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T sub(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_sub(aVal, Base::OrderedOp::AtomicRMWOrder); + } }; template struct IntrinsicAddSub : public IntrinsicBase { - typedef IntrinsicBase Base; - static T* add(typename Base::ValueType& ptr, ptrdiff_t val) { - return ptr.fetch_add(fixupAddend(val), Base::OrderedOp::AtomicRMWOrder); - } - static T* sub(typename Base::ValueType& ptr, ptrdiff_t val) { - return ptr.fetch_sub(fixupAddend(val), Base::OrderedOp::AtomicRMWOrder); - } - private: - /* - * GCC 4.6's header has a bug where adding X to an - * atomic is not the same as adding X to a T*. Hence the need - * for this function to provide the correct addend. - */ - static ptrdiff_t fixupAddend(ptrdiff_t val) { + typedef IntrinsicBase Base; + + static T* add(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_add(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } + + static T* sub(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_sub(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } +private: + /* + * GCC 4.6's header has a bug where adding X to an + * atomic is not the same as adding X to a T*. Hence the need + * for this function to provide the correct addend. + */ + static ptrdiff_t fixupAddend(ptrdiff_t aVal) + { #if defined(__clang__) || defined(_MSC_VER) - return val; + return aVal; #elif defined(__GNUC__) && MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) && \ - !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) - return val * sizeof(T); + !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) + return aVal * sizeof(T); #else - return val; + return aVal; #endif - } + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - typedef IntrinsicBase Base; - static T inc(typename Base::ValueType& ptr) { - return IntrinsicAddSub::add(ptr, 1); - } - static T dec(typename Base::ValueType& ptr) { - return IntrinsicAddSub::sub(ptr, 1); - } + typedef IntrinsicBase Base; + + static T inc(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::add(aPtr, 1); + } + + static T dec(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::sub(aPtr, 1); + } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef IntrinsicBase Base; - static T or_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_or(val, Base::OrderedOp::AtomicRMWOrder); - } - static T xor_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_xor(val, Base::OrderedOp::AtomicRMWOrder); - } - static T and_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_and(val, Base::OrderedOp::AtomicRMWOrder); - } + typedef IntrinsicBase Base; + + static T or_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_or(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T xor_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_xor(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T and_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_and(aVal, Base::OrderedOp::AtomicRMWOrder); + } }; template @@ -345,111 +382,119 @@ template struct Barrier; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() {} - static void beforeStore() {} - static void afterStore() {} + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} + static void afterStore() {} }; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() { __sync_synchronize(); } - static void beforeStore() { __sync_synchronize(); } - static void afterStore() {} + static void beforeLoad() {} + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() {} }; template<> struct Barrier { - static void beforeLoad() { __sync_synchronize(); } - static void afterLoad() { __sync_synchronize(); } - static void beforeStore() { __sync_synchronize(); } - static void afterStore() { __sync_synchronize(); } + static void beforeLoad() { __sync_synchronize(); } + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() { __sync_synchronize(); } }; template struct IntrinsicMemoryOps { - static T load(const T& ptr) { - Barrier::beforeLoad(); - T val = ptr; - Barrier::afterLoad(); - return val; - } - static void store(T& ptr, T val) { - Barrier::beforeStore(); - ptr = val; - Barrier::afterStore(); - } - static T exchange(T& ptr, T val) { - // __sync_lock_test_and_set is only an acquire barrier; loads and stores - // can't be moved up from after to before it, but they can be moved down - // from before to after it. We may want a stricter ordering, so we need - // an explicit barrier. - - Barrier::beforeStore(); - return __sync_lock_test_and_set(&ptr, val); - } - static bool compareExchange(T& ptr, T oldVal, T newVal) { - return __sync_bool_compare_and_swap(&ptr, oldVal, newVal); - } + static T load(const T& aPtr) + { + Barrier::beforeLoad(); + T val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(T& aPtr, T aVal) + { + Barrier::beforeStore(); + aPtr = aVal; + Barrier::afterStore(); + } + + static T exchange(T& aPtr, T aVal) + { + // __sync_lock_test_and_set is only an acquire barrier; loads and stores + // can't be moved up from after to before it, but they can be moved down + // from before to after it. We may want a stricter ordering, so we need + // an explicit barrier. + Barrier::beforeStore(); + return __sync_lock_test_and_set(&aPtr, aVal); + } + + static bool compareExchange(T& aPtr, T aOldVal, T aNewVal) + { + return __sync_bool_compare_and_swap(&aPtr, aOldVal, aNewVal); + } }; template struct IntrinsicAddSub { - typedef T ValueType; - static T add(T& ptr, T val) { - return __sync_fetch_and_add(&ptr, val); - } - static T sub(T& ptr, T val) { - return __sync_fetch_and_sub(&ptr, val); - } + typedef T ValueType; + + static T add(T& aPtr, T aVal) + { + return __sync_fetch_and_add(&aPtr, aVal); + } + + static T sub(T& aPtr, T aVal) + { + return __sync_fetch_and_sub(&aPtr, aVal); + } }; template struct IntrinsicAddSub { - typedef T* ValueType; - /* - * The reinterpret_casts are needed so that - * __sync_fetch_and_{add,sub} will properly type-check. - * - * Also, these functions do not provide standard semantics for - * pointer types, so we need to adjust the addend. - */ - static ValueType add(ValueType& ptr, ptrdiff_t val) { - ValueType amount = reinterpret_cast(val * sizeof(T)); - return __sync_fetch_and_add(&ptr, amount); - } - static ValueType sub(ValueType& ptr, ptrdiff_t val) { - ValueType amount = reinterpret_cast(val * sizeof(T)); - return __sync_fetch_and_sub(&ptr, amount); - } + typedef T* ValueType; + + /* + * The reinterpret_casts are needed so that + * __sync_fetch_and_{add,sub} will properly type-check. + * + * Also, these functions do not provide standard semantics for + * pointer types, so we need to adjust the addend. + */ + static ValueType add(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_add(&aPtr, amount); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_sub(&aPtr, amount); + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - static T inc(T& ptr) { return IntrinsicAddSub::add(ptr, 1); } - static T dec(T& ptr) { return IntrinsicAddSub::sub(ptr, 1); } + static T inc(T& aPtr) { return IntrinsicAddSub::add(aPtr, 1); } + static T dec(T& aPtr) { return IntrinsicAddSub::sub(aPtr, 1); } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - static T or_(T& ptr, T val) { - return __sync_fetch_and_or(&ptr, val); - } - static T xor_(T& ptr, T val) { - return __sync_fetch_and_xor(&ptr, val); - } - static T and_(T& ptr, T val) { - return __sync_fetch_and_and(&ptr, val); - } + static T or_( T& aPtr, T aVal) { return __sync_fetch_and_or(&aPtr, aVal); } + static T xor_(T& aPtr, T aVal) { return __sync_fetch_and_xor(&aPtr, aVal); } + static T and_(T& aPtr, T aVal) { return __sync_fetch_and_and(&aPtr, aVal); } }; template @@ -470,19 +515,9 @@ struct AtomicIntrinsics : public IntrinsicMemoryOps, * version of Windows we support. Therefore, we only provide operations * on 32-bit datatypes for 32-bit Windows versions; for 64-bit Windows * versions, we support 64-bit datatypes as well. - * - * To avoid namespace pollution issues, we declare whatever functions we - * need ourselves. */ -extern "C" { -long __cdecl _InterlockedExchangeAdd(long volatile* dst, long value); -long __cdecl _InterlockedOr(long volatile* dst, long value); -long __cdecl _InterlockedXor(long volatile* dst, long value); -long __cdecl _InterlockedAnd(long volatile* dst, long value); -long __cdecl _InterlockedExchange(long volatile *dst, long value); -long __cdecl _InterlockedCompareExchange(long volatile *dst, long newVal, long oldVal); -} +# include # pragma intrinsic(_InterlockedExchangeAdd) # pragma intrinsic(_InterlockedOr) @@ -507,34 +542,34 @@ namespace detail { * The PrimitiveIntrinsics template should define |Type|, the datatype of size * DataSize upon which we operate, and the following eight functions. * - * static Type add(Type* ptr, Type val); - * static Type sub(Type* ptr, Type val); - * static Type or_(Type* ptr, Type val); - * static Type xor_(Type* ptr, Type val); - * static Type and_(Type* ptr, Type val); + * static Type add(Type* aPtr, Type aVal); + * static Type sub(Type* aPtr, Type aVal); + * static Type or_(Type* aPtr, Type aVal); + * static Type xor_(Type* aPtr, Type aVal); + * static Type and_(Type* aPtr, Type aVal); * * These functions perform the obvious operation on the value contained in - * |*ptr| combined with |val| and return the value previously stored in - * |*ptr|. + * |*aPtr| combined with |aVal| and return the value previously stored in + * |*aPtr|. * - * static void store(Type* ptr, Type val); + * static void store(Type* aPtr, Type aVal); * - * This function atomically stores |val| into |*ptr| and must provide a full + * This function atomically stores |aVal| into |*aPtr| and must provide a full * memory fence after the store to prevent compiler and hardware instruction * reordering. It should also act as a compiler barrier to prevent reads and * writes from moving to after the store. * - * static Type exchange(Type* ptr, Type val); + * static Type exchange(Type* aPtr, Type aVal); * - * This function atomically stores |val| into |*ptr| and returns the previous - * contents of *ptr; + * This function atomically stores |aVal| into |*aPtr| and returns the + * previous contents of |*aPtr|; * - * static bool compareExchange(Type* ptr, Type oldVal, Type newVal); + * static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal); * * This function atomically performs the following operation: * - * if (*ptr == oldVal) { - * *ptr = newVal; + * if (*aPtr == aOldVal) { + * *aPtr = aNewVal; * return true; * } else { * return false; @@ -546,56 +581,55 @@ template struct PrimitiveIntrinsics; template<> struct PrimitiveIntrinsics<4> { - typedef long Type; + typedef long Type; - static Type add(Type* ptr, Type val) { - return _InterlockedExchangeAdd(ptr, val); - } - static Type sub(Type* ptr, Type val) { - /* - * _InterlockedExchangeSubtract isn't available before Windows 7, - * and we must support Windows XP. - */ - return _InterlockedExchangeAdd(ptr, -val); - } - static Type or_(Type* ptr, Type val) { - return _InterlockedOr(ptr, val); - } - static Type xor_(Type* ptr, Type val) { - return _InterlockedXor(ptr, val); - } - static Type and_(Type* ptr, Type val) { - return _InterlockedAnd(ptr, val); - } - static void store(Type* ptr, Type val) { - _InterlockedExchange(ptr, val); - } - static Type exchange(Type* ptr, Type val) { - return _InterlockedExchange(ptr, val); - } - static bool compareExchange(Type* ptr, Type oldVal, Type newVal) { - return _InterlockedCompareExchange(ptr, newVal, oldVal) == oldVal; - } + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * _InterlockedExchangeSubtract isn't available before Windows 7, + * and we must support Windows XP. + */ + return _InterlockedExchangeAdd(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange(aPtr, aNewVal, aOldVal) == aOldVal; + } }; # if defined(_M_X64) -extern "C" { -long long __cdecl _InterlockedExchangeAdd64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedOr64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedXor64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedAnd64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedExchange64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedCompareExchange64(long long volatile* dst, - long long newVal, - long long oldVal); -} - # pragma intrinsic(_InterlockedExchangeAdd64) # pragma intrinsic(_InterlockedOr64) # pragma intrinsic(_InterlockedXor64) @@ -606,41 +640,54 @@ long long __cdecl _InterlockedCompareExchange64(long long volatile* dst, template <> struct PrimitiveIntrinsics<8> { - typedef __int64 Type; + typedef __int64 Type; - static Type add(Type* ptr, Type val) { - return _InterlockedExchangeAdd64(ptr, val); - } - static Type sub(Type* ptr, Type val) { - /* - * There is no _InterlockedExchangeSubtract64. - */ - return _InterlockedExchangeAdd64(ptr, -val); - } - static Type or_(Type* ptr, Type val) { - return _InterlockedOr64(ptr, val); - } - static Type xor_(Type* ptr, Type val) { - return _InterlockedXor64(ptr, val); - } - static Type and_(Type* ptr, Type val) { - return _InterlockedAnd64(ptr, val); - } - static void store(Type* ptr, Type val) { - _InterlockedExchange64(ptr, val); - } - static Type exchange(Type* ptr, Type val) { - return _InterlockedExchange64(ptr, val); - } - static bool compareExchange(Type* ptr, Type oldVal, Type newVal) { - return _InterlockedCompareExchange64(ptr, newVal, oldVal) == oldVal; - } + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd64(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * There is no _InterlockedExchangeSubtract64. + */ + return _InterlockedExchangeAdd64(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr64(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor64(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd64(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange64(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange64(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange64(aPtr, aNewVal, aOldVal) == aOldVal; + } }; # endif -extern "C" { void _ReadWriteBarrier(); } - # pragma intrinsic(_ReadWriteBarrier) template struct Barrier; @@ -654,168 +701,198 @@ template struct Barrier; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() {} - static void beforeStore() {} + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} }; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() { _ReadWriteBarrier(); } - static void beforeStore() { _ReadWriteBarrier(); } + static void beforeLoad() {} + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } }; template<> struct Barrier { - static void beforeLoad() { _ReadWriteBarrier(); } - static void afterLoad() { _ReadWriteBarrier(); } - static void beforeStore() { _ReadWriteBarrier(); } + static void beforeLoad() { _ReadWriteBarrier(); } + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } }; template struct CastHelper { - static PrimType toPrimType(T val) { return static_cast(val); } - static T fromPrimType(PrimType val) { return static_cast(val); } + static PrimType toPrimType(T aVal) { return static_cast(aVal); } + static T fromPrimType(PrimType aVal) { return static_cast(aVal); } }; template struct CastHelper { - static PrimType toPrimType(T* val) { return reinterpret_cast(val); } - static T* fromPrimType(PrimType val) { return reinterpret_cast(val); } + static PrimType toPrimType(T* aVal) { return reinterpret_cast(aVal); } + static T* fromPrimType(PrimType aVal) { return reinterpret_cast(aVal); } }; template struct IntrinsicBase { - typedef T ValueType; - typedef PrimitiveIntrinsics Primitives; - typedef typename Primitives::Type PrimType; - static_assert(sizeof(PrimType) == sizeof(T), - "Selection of PrimitiveIntrinsics was wrong"); - typedef CastHelper Cast; + typedef T ValueType; + typedef PrimitiveIntrinsics Primitives; + typedef typename Primitives::Type PrimType; + static_assert(sizeof(PrimType) == sizeof(T), + "Selection of PrimitiveIntrinsics was wrong"); + typedef CastHelper Cast; }; template struct IntrinsicMemoryOps : public IntrinsicBase { - typedef typename IntrinsicBase::ValueType ValueType; - typedef typename IntrinsicBase::Primitives Primitives; - typedef typename IntrinsicBase::PrimType PrimType; - typedef typename IntrinsicBase::Cast Cast; - static ValueType load(const ValueType& ptr) { - Barrier::beforeLoad(); - ValueType val = ptr; - Barrier::afterLoad(); - return val; - } - static void store(ValueType& ptr, ValueType val) { - // For SequentiallyConsistent, Primitives::store() will generate the - // proper memory fence. Everything else just needs a barrier before - // the store. - if (Order == SequentiallyConsistent) { - Primitives::store(reinterpret_cast(&ptr), - Cast::toPrimType(val)); - } else { - Barrier::beforeStore(); - ptr = val; - } - } - static ValueType exchange(ValueType& ptr, ValueType val) { - PrimType oldval = - Primitives::exchange(reinterpret_cast(&ptr), - Cast::toPrimType(val)); - return Cast::fromPrimType(oldval); - } - static bool compareExchange(ValueType& ptr, ValueType oldVal, ValueType newVal) { - return Primitives::compareExchange(reinterpret_cast(&ptr), - Cast::toPrimType(oldVal), - Cast::toPrimType(newVal)); + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + + static ValueType load(const ValueType& aPtr) + { + Barrier::beforeLoad(); + ValueType val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(ValueType& aPtr, ValueType aVal) + { + // For SequentiallyConsistent, Primitives::store() will generate the + // proper memory fence. Everything else just needs a barrier before + // the store. + if (Order == SequentiallyConsistent) { + Primitives::store(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + } else { + Barrier::beforeStore(); + aPtr = aVal; } + } + + static ValueType exchange(ValueType& aPtr, ValueType aVal) + { + PrimType oldval = + Primitives::exchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + return Cast::fromPrimType(oldval); + } + + static bool compareExchange(ValueType& aPtr, ValueType aOldVal, + ValueType aNewVal) + { + return Primitives::compareExchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aOldVal), + Cast::toPrimType(aNewVal)); + } }; template struct IntrinsicApplyHelper : public IntrinsicBase { - typedef typename IntrinsicBase::ValueType ValueType; - typedef typename IntrinsicBase::PrimType PrimType; - typedef typename IntrinsicBase::Cast Cast; - typedef PrimType (*BinaryOp)(PrimType*, PrimType); - typedef PrimType (*UnaryOp)(PrimType*); - - static ValueType applyBinaryFunction(BinaryOp op, ValueType& ptr, - ValueType val) { - PrimType* primTypePtr = reinterpret_cast(&ptr); - PrimType primTypeVal = Cast::toPrimType(val); - return Cast::fromPrimType(op(primTypePtr, primTypeVal)); - } - - static ValueType applyUnaryFunction(UnaryOp op, ValueType& ptr) { - PrimType* primTypePtr = reinterpret_cast(&ptr); - return Cast::fromPrimType(op(primTypePtr)); - } + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + typedef PrimType (*BinaryOp)(PrimType*, PrimType); + typedef PrimType (*UnaryOp)(PrimType*); + + static ValueType applyBinaryFunction(BinaryOp aOp, ValueType& aPtr, + ValueType aVal) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + PrimType primTypeVal = Cast::toPrimType(aVal); + return Cast::fromPrimType(aOp(primTypePtr, primTypeVal)); + } + + static ValueType applyUnaryFunction(UnaryOp aOp, ValueType& aPtr) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + return Cast::fromPrimType(aOp(primTypePtr)); + } }; template struct IntrinsicAddSub : public IntrinsicApplyHelper { - typedef typename IntrinsicApplyHelper::ValueType ValueType; - typedef typename IntrinsicBase::Primitives Primitives; - static ValueType add(ValueType& ptr, ValueType val) { - return applyBinaryFunction(&Primitives::add, ptr, val); - } - static ValueType sub(ValueType& ptr, ValueType val) { - return applyBinaryFunction(&Primitives::sub, ptr, val); - } + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::add, aPtr, aVal); + } + + static ValueType sub(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::sub, aPtr, aVal); + } }; template struct IntrinsicAddSub : public IntrinsicApplyHelper { - typedef typename IntrinsicApplyHelper::ValueType ValueType; - static ValueType add(ValueType& ptr, ptrdiff_t amount) { - return applyBinaryFunction(&Primitives::add, ptr, - (ValueType)(amount * sizeof(ValueType))); - } - static ValueType sub(ValueType& ptr, ptrdiff_t amount) { - return applyBinaryFunction(&Primitives::sub, ptr, - (ValueType)(amount * sizeof(ValueType))); - } + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::add, aPtr, + (ValueType)(aAmount * sizeof(T))); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::sub, aPtr, + (ValueType)(aAmount * sizeof(T))); + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - typedef typename IntrinsicAddSub::ValueType ValueType; - static ValueType inc(ValueType& ptr) { return add(ptr, 1); } - static ValueType dec(ValueType& ptr) { return sub(ptr, 1); } + typedef typename IntrinsicAddSub::ValueType ValueType; + static ValueType inc(ValueType& aPtr) { return add(aPtr, 1); } + static ValueType dec(ValueType& aPtr) { return sub(aPtr, 1); } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef typename IntrinsicIncDec::ValueType ValueType; - static ValueType or_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::or_, ptr, val); - } - static ValueType xor_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::xor_, ptr, val); - } - static ValueType and_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::and_, ptr, val); - } + typedef typename IntrinsicIncDec::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType or_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::or_, aPtr, aVal); + } + + static ValueType xor_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::xor_, aPtr, aVal); + } + + static ValueType and_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::and_, aPtr, aVal); + } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef typename IntrinsicMemoryOps::ValueType ValueType; + typedef typename IntrinsicMemoryOps::ValueType ValueType; + // This is required to make us be able to build with MSVC10, for unknown + // reasons. + typedef typename IntrinsicBase::Primitives Primitives; }; } // namespace detail @@ -832,73 +909,80 @@ namespace detail { template class AtomicBase { - // We only support 32-bit types on 32-bit Windows, which constrains our - // implementation elsewhere. But we support pointer-sized types everywhere. - static_assert(sizeof(T) == 4 || (sizeof(uintptr_t) == 8 && sizeof(T) == 8), - "mozilla/Atomics.h only supports 32-bit and pointer-sized types"); - - protected: - typedef typename detail::AtomicIntrinsics Intrinsics; - typename Intrinsics::ValueType mValue; - - public: - MOZ_CONSTEXPR AtomicBase() : mValue() {} - MOZ_CONSTEXPR AtomicBase(T aInit) : mValue(aInit) {} - - operator T() const { return Intrinsics::load(mValue); } - - T operator=(T aValue) { - Intrinsics::store(mValue, aValue); - return aValue; - } - - /** - * Performs an atomic swap operation. aValue is stored and the previous - * value of this variable is returned. - */ - T exchange(T aValue) { - return Intrinsics::exchange(mValue, aValue); - } - - /** - * Performs an atomic compare-and-swap operation and returns true if it - * succeeded. This is equivalent to atomically doing - * - * if (mValue == aOldValue) { - * mValue = aNewValue; - * return true; - * } else { - * return false; - * } - */ - bool compareExchange(T aOldValue, T aNewValue) { - return Intrinsics::compareExchange(mValue, aOldValue, aNewValue); - } - - private: - template - AtomicBase(const AtomicBase& aCopy) MOZ_DELETE; + // We only support 32-bit types on 32-bit Windows, which constrains our + // implementation elsewhere. But we support pointer-sized types everywhere. + static_assert(sizeof(T) == 4 || (sizeof(uintptr_t) == 8 && sizeof(T) == 8), + "mozilla/Atomics.h only supports 32-bit and pointer-sized types"); + +protected: + typedef typename detail::AtomicIntrinsics Intrinsics; + typename Intrinsics::ValueType mValue; + +public: + MOZ_CONSTEXPR AtomicBase() : mValue() {} + explicit MOZ_CONSTEXPR AtomicBase(T aInit) : mValue(aInit) {} + + // Note: we can't provide operator T() here because Atomic inherits + // from AtomcBase with T=uint32_t and not T=bool. If we implemented + // operator T() here, it would cause errors when comparing Atomic with + // a regular bool. + + T operator=(T aVal) + { + Intrinsics::store(mValue, aVal); + return aVal; + } + + /** + * Performs an atomic swap operation. aVal is stored and the previous + * value of this variable is returned. + */ + T exchange(T aVal) + { + return Intrinsics::exchange(mValue, aVal); + } + + /** + * Performs an atomic compare-and-swap operation and returns true if it + * succeeded. This is equivalent to atomically doing + * + * if (mValue == aOldValue) { + * mValue = aNewValue; + * return true; + * } else { + * return false; + * } + */ + bool compareExchange(T aOldValue, T aNewValue) + { + return Intrinsics::compareExchange(mValue, aOldValue, aNewValue); + } + +private: + template + AtomicBase(const AtomicBase& aCopy) MOZ_DELETE; }; template class AtomicBaseIncDec : public AtomicBase { - typedef typename detail::AtomicBase Base; + typedef typename detail::AtomicBase Base; - public: - MOZ_CONSTEXPR AtomicBaseIncDec() : Base() {} - MOZ_CONSTEXPR AtomicBaseIncDec(T aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR AtomicBaseIncDec() : Base() {} + explicit MOZ_CONSTEXPR AtomicBaseIncDec(T aInit) : Base(aInit) {} - using Base::operator=; + using Base::operator=; - T operator++(int) { return Base::Intrinsics::inc(Base::mValue); } - T operator--(int) { return Base::Intrinsics::dec(Base::mValue); } - T operator++() { return Base::Intrinsics::inc(Base::mValue) + 1; } - T operator--() { return Base::Intrinsics::dec(Base::mValue) - 1; } + operator T() const { return Base::Intrinsics::load(Base::mValue); } + T operator++(int) { return Base::Intrinsics::inc(Base::mValue); } + T operator--(int) { return Base::Intrinsics::dec(Base::mValue); } + T operator++() { return Base::Intrinsics::inc(Base::mValue) + 1; } + T operator--() { return Base::Intrinsics::dec(Base::mValue) - 1; } - private: - template - AtomicBaseIncDec(const AtomicBaseIncDec& aCopy) MOZ_DELETE; +private: + template + AtomicBaseIncDec(const AtomicBaseIncDec& aCopy) MOZ_DELETE; }; } // namespace detail @@ -934,25 +1018,45 @@ class Atomic; * swap method is provided. */ template -class Atomic::value>::Type> +class Atomic::value && + !IsSame::value>::Type> : public detail::AtomicBaseIncDec { - typedef typename detail::AtomicBaseIncDec Base; + typedef typename detail::AtomicBaseIncDec Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + + using Base::operator=; + + T operator+=(T aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + T operator-=(T aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } - using Base::operator=; + T operator|=(T aVal) + { + return Base::Intrinsics::or_(Base::mValue, aVal) | aVal; + } - T operator+=(T delta) { return Base::Intrinsics::add(Base::mValue, delta) + delta; } - T operator-=(T delta) { return Base::Intrinsics::sub(Base::mValue, delta) - delta; } - T operator|=(T val) { return Base::Intrinsics::or_(Base::mValue, val) | val; } - T operator^=(T val) { return Base::Intrinsics::xor_(Base::mValue, val) ^ val; } - T operator&=(T val) { return Base::Intrinsics::and_(Base::mValue, val) & val; } + T operator^=(T aVal) + { + return Base::Intrinsics::xor_(Base::mValue, aVal) ^ aVal; + } - private: - Atomic(Atomic& aOther) MOZ_DELETE; + T operator&=(T aVal) + { + return Base::Intrinsics::and_(Base::mValue, aVal) & aVal; + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; /** @@ -966,23 +1070,26 @@ class Atomic::value>::Type> template class Atomic : public detail::AtomicBaseIncDec { - typedef typename detail::AtomicBaseIncDec Base; + typedef typename detail::AtomicBaseIncDec Base; - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T* aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T* aInit) : Base(aInit) {} - using Base::operator=; + using Base::operator=; - T* operator+=(ptrdiff_t delta) { - return Base::Intrinsics::add(Base::mValue, delta) + delta; - } - T* operator-=(ptrdiff_t delta) { - return Base::Intrinsics::sub(Base::mValue, delta) - delta; - } + T* operator+=(ptrdiff_t aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } + + T* operator-=(ptrdiff_t aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } - private: - Atomic(Atomic& aOther) MOZ_DELETE; +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; /** @@ -994,16 +1101,69 @@ template class Atomic::value>::Type> : public detail::AtomicBase { - typedef typename detail::AtomicBase Base; + typedef typename detail::AtomicBase Base; - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} - using Base::operator=; + operator T() const { return Base::Intrinsics::load(Base::mValue); } - private: - Atomic(Atomic& aOther) MOZ_DELETE; + using Base::operator=; + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +/** + * Atomic implementation for boolean types. + * + * The atomic store and load operations and the atomic swap method is provided. + * + * Note: + * + * - sizeof(Atomic) != sizeof(bool) for some implementations of + * bool and/or some implementations of std::atomic. This is allowed in + * [atomic.types.generic]p9. + * + * - It's not obvious whether the 8-bit atomic functions on Windows are always + * inlined or not. If they are not inlined, the corresponding functions in the + * runtime library are not available on Windows XP. This is why we implement + * Atomic with an underlying type of uint32_t. + */ +template +class Atomic + : protected detail::AtomicBase +{ + typedef typename detail::AtomicBase Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(bool aInit) : Base(aInit) {} + + // We provide boolean wrappers for the underlying AtomicBase methods. + operator bool() const + { + return Base::Intrinsics::load(Base::mValue); + } + + bool operator=(bool aVal) + { + return Base::operator=(aVal); + } + + bool exchange(bool aVal) + { + return Base::exchange(aVal); + } + + bool compareExchange(bool aOldValue, bool aNewValue) + { + return Base::compareExchange(aOldValue, aNewValue); + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Attributes.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Attributes.h index 671f30cded..cdce8c7717 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Attributes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Attributes.h @@ -37,6 +37,7 @@ # define MOZ_ALWAYS_INLINE inline #endif +#if defined(_MSC_VER) /* * g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality * without warnings (functionality used by the macros below). These modes are @@ -44,8 +45,27 @@ * standardly, by checking whether __cplusplus has a C++11 or greater value. * Current versions of g++ do not correctly set __cplusplus, so we check both * for forward compatibility. + * + * Even though some versions of MSVC support explicit conversion operators, we + * don't indicate support for them here, due to + * http://stackoverflow.com/questions/20498142/visual-studio-2013-explicit-keyword-bug */ -#if defined(__clang__) +# if _MSC_VER >= 1800 +# define MOZ_HAVE_CXX11_DELETE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_FINAL final +# else +# if defined(__clang__) +# error Please do not try to use clang-cl with MSVC10 or below emulation! +# endif + /* MSVC <= 10 used to spell "final" as "sealed". */ +# define MOZ_HAVE_CXX11_FINAL sealed +# endif +# define MOZ_HAVE_CXX11_OVERRIDE +# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) +# define MOZ_HAVE_NORETURN __declspec(noreturn) +#elif defined(__clang__) /* * Per Clang documentation, "Note that marketing version numbers should not * be used to check for language features, as different vendors use different @@ -57,6 +77,9 @@ # if __has_extension(cxx_constexpr) # define MOZ_HAVE_CXX11_CONSTEXPR # endif +# if __has_extension(cxx_explicit_conversions) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif # if __has_extension(cxx_deleted_functions) # define MOZ_HAVE_CXX11_DELETE # endif @@ -79,6 +102,9 @@ # if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) # define MOZ_HAVE_CXX11_CONSTEXPR # endif +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif # define MOZ_HAVE_CXX11_DELETE # else /* __final is a non-C++11 GCC synonym for 'final', per GCC r176655. */ @@ -88,19 +114,16 @@ # endif # define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) # define MOZ_HAVE_NORETURN __attribute__((noreturn)) -#elif defined(_MSC_VER) -# if _MSC_VER >= 1800 -# define MOZ_HAVE_CXX11_DELETE -# endif -# if _MSC_VER >= 1700 -# define MOZ_HAVE_CXX11_FINAL final -# else - /* MSVC <= 10 used to spell "final" as "sealed". */ -# define MOZ_HAVE_CXX11_FINAL sealed +#endif + +/* + * When built with clang analyzer (a.k.a scan-build), define MOZ_HAVE_NORETURN + * to mark some false positives + */ +#ifdef __clang_analyzer__ +# if __has_extension(attribute_analyzer_noreturn) +# define MOZ_HAVE_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) # endif -# define MOZ_HAVE_CXX11_OVERRIDE -# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) -# define MOZ_HAVE_NORETURN __declspec(noreturn) #endif /* @@ -121,6 +144,31 @@ # define MOZ_CONSTEXPR_VAR const #endif +/* + * MOZ_EXPLICIT_CONVERSION is a specifier on a type conversion + * overloaded operator that declares that a C++11 compiler should restrict + * this operator to allow only explicit type conversions, disallowing + * implicit conversions. + * + * Example: + * + * template + * class Ptr + * { + * T* mPtr; + * MOZ_EXPLICIT_CONVERSION operator bool() const + * { + * return mPtr != nullptr; + * } + * }; + * + */ +#ifdef MOZ_HAVE_EXPLICIT_CONVERSION +# define MOZ_EXPLICIT_CONVERSION explicit +#else +# define MOZ_EXPLICIT_CONVERSION /* no support */ +#endif + /* * MOZ_NEVER_INLINE is a macro which expands to tell the compiler that the * method decorated with it must never be inlined, even if the compiler would @@ -153,18 +201,47 @@ # define MOZ_NORETURN /* no support */ #endif +/* + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS, specified at the end of a function + * declaration, indicates that for the purposes of static analysis, this + * function does not return. (The function definition does not need to be + * annotated.) + * + * MOZ_ReportCrash(const char* s, const char* file, int ln) + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS + * + * Some static analyzers, like scan-build from clang, can use this information + * to eliminate false positives. From the upstream documentation of scan-build: + * "This attribute is useful for annotating assertion handlers that actually + * can return, but for the purpose of using the analyzer we want to pretend + * that such functions do not return." + * + */ +#if defined(MOZ_HAVE_ANALYZER_NORETURN) +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS MOZ_HAVE_ANALYZER_NORETURN +#else +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS /* no support */ +#endif + /* * MOZ_ASAN_BLACKLIST is a macro to tell AddressSanitizer (a compile-time - * instrumentation shipped with Clang) to not instrument the annotated function. - * Furthermore, it will prevent the compiler from inlining the function because - * inlining currently breaks the blacklisting mechanism of AddressSanitizer. + * instrumentation shipped with Clang and GCC) to not instrument the annotated + * function. Furthermore, it will prevent the compiler from inlining the + * function because inlining currently breaks the blacklisting mechanism of + * AddressSanitizer. */ #if defined(__has_feature) # if __has_feature(address_sanitizer) -# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) -# else -# define MOZ_ASAN_BLACKLIST /* nothing */ +# define MOZ_HAVE_ASAN_BLACKLIST # endif +#elif defined(__GNUC__) +# if defined(__SANITIZE_ADDRESS__) +# define MOZ_HAVE_ASAN_BLACKLIST +# endif +#endif + +#if defined(MOZ_HAVE_ASAN_BLACKLIST) +# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) #else # define MOZ_ASAN_BLACKLIST /* nothing */ #endif @@ -197,9 +274,9 @@ * * struct NonCopyable * { - * private: - * NonCopyable(const NonCopyable& other) MOZ_DELETE; - * void operator=(const NonCopyable& other) MOZ_DELETE; + * private: + * NonCopyable(const NonCopyable& aOther) MOZ_DELETE; + * void operator=(const NonCopyable& aOther) MOZ_DELETE; * }; * * If MOZ_DELETE can't be implemented for the current compiler, use of the @@ -225,23 +302,23 @@ * * class Base * { - * public: - * virtual void f() = 0; + * public: + * virtual void f() = 0; * }; * class Derived1 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE; + * public: + * virtual void f() MOZ_OVERRIDE; * }; * class Derived2 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE = 0; + * public: + * virtual void f() MOZ_OVERRIDE = 0; * }; * class Derived3 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE { } + * public: + * virtual void f() MOZ_OVERRIDE { } * }; * * In compilers supporting C++11 override controls, MOZ_OVERRIDE *requires* that @@ -269,16 +346,16 @@ * * class Base MOZ_FINAL * { - * public: - * Base(); - * ~Base(); - * virtual void f() { } + * public: + * Base(); + * ~Base(); + * virtual void f() { } * }; * // This will be an error in some compilers: * class Derived : public Base * { - * public: - * ~Derived() { } + * public: + * ~Derived() { } * }; * * One particularly common reason to specify MOZ_FINAL upon a class is to tell @@ -305,14 +382,14 @@ * * class Base * { - * public: - * virtual void f() MOZ_FINAL; + * public: + * virtual void f() MOZ_FINAL; * }; * class Derived * { - * public: - * // This will be an error in some compilers: - * virtual void f(); + * public: + * // This will be an error in some compilers: + * virtual void f(); * }; * * In compilers implementing final controls, it is an error for a derived class @@ -372,13 +449,13 @@ * * typedef int MOZ_TYPE_ATTRIBUTE MagicInt; * int MOZ_TYPE_ATTRIBUTE someVariable; - * int * MOZ_TYPE_ATTRIBUTE magicPtrInt; - * int MOZ_TYPE_ATTRIBUTE * ptrToMagicInt; + * int* MOZ_TYPE_ATTRIBUTE magicPtrInt; + * int MOZ_TYPE_ATTRIBUTE* ptrToMagicInt; * * Attributes that apply to statements precede the statement: * * MOZ_IF_ATTRIBUTE if (x == 0) - * MOZ_DO_ATTRIBUTE do { } while(0); + * MOZ_DO_ATTRIBUTE do { } while (0); * * Attributes that apply to labels precede the label: * @@ -412,11 +489,16 @@ * MOZ_HEAP_ALLOCATOR: Applies to any function. This indicates that the return * value is allocated on the heap, and will as a result check such allocations * during MOZ_STACK_CLASS and MOZ_NONHEAP_CLASS annotation checking. + * MOZ_IMPLICIT: Applies to constructors. Implicit conversion constructors + * are disallowed by default unless they are marked as MOZ_IMPLICIT. This + * attribute must be used for constructors which intend to provide implicit + * conversions. */ #ifdef MOZ_CLANG_PLUGIN # define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override"))) # define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class"))) # define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class"))) +# define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) /* * It turns out that clang doesn't like void func() __attribute__ {} without a * warning, so use pragmas to disable the warning. This code won't work on GCC @@ -431,6 +513,7 @@ # define MOZ_MUST_OVERRIDE /* nothing */ # define MOZ_STACK_CLASS /* nothing */ # define MOZ_NONHEAP_CLASS /* nothing */ +# define MOZ_IMPLICIT /* nothing */ # define MOZ_HEAP_ALLOCATOR /* nothing */ #endif /* MOZ_CLANG_PLUGIN */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/BinarySearch.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/BinarySearch.h new file mode 100644 index 0000000000..c8f593d6a9 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/BinarySearch.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_BinarySearch_h +#define mozilla_BinarySearch_h + +#include "mozilla/Assertions.h" + +#include + +namespace mozilla { + +/* + * The algorithm searches the given container |aContainer| over the sorted + * index range [aBegin, aEnd) for an index |i| where |aContainer[i] == aTarget|. + * If such an index |i| is found, BinarySearch returns |true| and the index is + * returned via the outparam |aMatchOrInsertionPoint|. If no index is found, + * BinarySearch returns |false| and the outparam returns the first index in + * [aBegin, aEnd] where |aTarget| can be inserted to maintain sorted order. + * + * Example: + * + * Vector sortedInts = ... + * + * size_t match; + * if (BinarySearch(sortedInts, 0, sortedInts.length(), 13, &match)) { + * printf("found 13 at %lu\n", match); + * } + */ + +template +bool +BinarySearch(const Container& aContainer, size_t aBegin, size_t aEnd, + T aTarget, size_t* aMatchOrInsertionPoint) +{ + MOZ_ASSERT(aBegin <= aEnd); + + size_t low = aBegin; + size_t high = aEnd; + while (low != high) { + size_t middle = low + (high - low) / 2; + + // Allow any intermediate type so long as it provides a suitable ordering + // relation. + const auto& middleValue = aContainer[middle]; + + MOZ_ASSERT(aContainer[low] <= aContainer[middle]); + MOZ_ASSERT(aContainer[middle] <= aContainer[high - 1]); + MOZ_ASSERT(aContainer[low] <= aContainer[high - 1]); + + if (aTarget == middleValue) { + *aMatchOrInsertionPoint = middle; + return true; + } + + if (aTarget < middleValue) { + high = middle; + } else { + low = middle + 1; + } + } + + *aMatchOrInsertionPoint = low; + return false; +} + +} // namespace mozilla + +#endif // mozilla_BinarySearch_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/BloomFilter.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/BloomFilter.h index 8129c489d4..6757e41181 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/BloomFilter.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/BloomFilter.h @@ -55,177 +55,199 @@ namespace mozilla { template class BloomFilter { - /* - * A counting Bloom filter with 8-bit counters. For now we assume - * that having two hash functions is enough, but we may revisit that - * decision later. - * - * The filter uses an array with 2**KeySize entries. - * - * Assuming a well-distributed hash function, a Bloom filter with - * array size M containing N elements and - * using k hash function has expected false positive rate exactly - * - * $ (1 - (1 - 1/M)^{kN})^k $ - * - * because each array slot has a - * - * $ (1 - 1/M)^{kN} $ - * - * chance of being 0, and the expected false positive rate is the - * probability that all of the k hash functions will hit a nonzero - * slot. - * - * For reasonable assumptions (M large, kN large, which should both - * hold if we're worried about false positives) about M and kN this - * becomes approximately - * - * $$ (1 - \exp(-kN/M))^k $$ - * - * For our special case of k == 2, that's $(1 - \exp(-2N/M))^2$, - * or in other words - * - * $$ N/M = -0.5 * \ln(1 - \sqrt(r)) $$ - * - * where r is the false positive rate. This can be used to compute - * the desired KeySize for a given load N and false positive rate r. - * - * If N/M is assumed small, then the false positive rate can - * further be approximated as 4*N^2/M^2. So increasing KeySize by - * 1, which doubles M, reduces the false positive rate by about a - * factor of 4, and a false positive rate of 1% corresponds to - * about M/N == 20. - * - * What this means in practice is that for a few hundred keys using a - * KeySize of 12 gives false positive rates on the order of 0.25-4%. - * - * Similarly, using a KeySize of 10 would lead to a 4% false - * positive rate for N == 100 and to quite bad false positive - * rates for larger N. - */ - public: - BloomFilter() { - static_assert(KeySize <= keyShift, "KeySize too big"); - - // Should we have a custom operator new using calloc instead and - // require that we're allocated via the operator? - clear(); - } - - /* - * Clear the filter. This should be done before reusing it, because - * just removing all items doesn't clear counters that hit the upper - * bound. - */ - void clear(); - - /* - * Add an item to the filter. - */ - void add(const T* t); - - /* - * Remove an item from the filter. - */ - void remove(const T* t); - - /* - * Check whether the filter might contain an item. This can - * sometimes return true even if the item is not in the filter, - * but will never return false for items that are actually in the - * filter. - */ - bool mightContain(const T* t) const; - - /* - * Methods for add/remove/contain when we already have a hash computed - */ - void add(uint32_t hash); - void remove(uint32_t hash); - bool mightContain(uint32_t hash) const; - - private: - static const size_t arraySize = (1 << KeySize); - static const uint32_t keyMask = (1 << KeySize) - 1; - static const uint32_t keyShift = 16; - - static uint32_t hash1(uint32_t hash) { return hash & keyMask; } - static uint32_t hash2(uint32_t hash) { return (hash >> keyShift) & keyMask; } - - uint8_t& firstSlot(uint32_t hash) { return counters[hash1(hash)]; } - uint8_t& secondSlot(uint32_t hash) { return counters[hash2(hash)]; } - const uint8_t& firstSlot(uint32_t hash) const { return counters[hash1(hash)]; } - const uint8_t& secondSlot(uint32_t hash) const { return counters[hash2(hash)]; } - - static bool full(const uint8_t& slot) { return slot == UINT8_MAX; } - - uint8_t counters[arraySize]; + /* + * A counting Bloom filter with 8-bit counters. For now we assume + * that having two hash functions is enough, but we may revisit that + * decision later. + * + * The filter uses an array with 2**KeySize entries. + * + * Assuming a well-distributed hash function, a Bloom filter with + * array size M containing N elements and + * using k hash function has expected false positive rate exactly + * + * $ (1 - (1 - 1/M)^{kN})^k $ + * + * because each array slot has a + * + * $ (1 - 1/M)^{kN} $ + * + * chance of being 0, and the expected false positive rate is the + * probability that all of the k hash functions will hit a nonzero + * slot. + * + * For reasonable assumptions (M large, kN large, which should both + * hold if we're worried about false positives) about M and kN this + * becomes approximately + * + * $$ (1 - \exp(-kN/M))^k $$ + * + * For our special case of k == 2, that's $(1 - \exp(-2N/M))^2$, + * or in other words + * + * $$ N/M = -0.5 * \ln(1 - \sqrt(r)) $$ + * + * where r is the false positive rate. This can be used to compute + * the desired KeySize for a given load N and false positive rate r. + * + * If N/M is assumed small, then the false positive rate can + * further be approximated as 4*N^2/M^2. So increasing KeySize by + * 1, which doubles M, reduces the false positive rate by about a + * factor of 4, and a false positive rate of 1% corresponds to + * about M/N == 20. + * + * What this means in practice is that for a few hundred keys using a + * KeySize of 12 gives false positive rates on the order of 0.25-4%. + * + * Similarly, using a KeySize of 10 would lead to a 4% false + * positive rate for N == 100 and to quite bad false positive + * rates for larger N. + */ +public: + BloomFilter() + { + static_assert(KeySize <= kKeyShift, "KeySize too big"); + + // Should we have a custom operator new using calloc instead and + // require that we're allocated via the operator? + clear(); + } + + /* + * Clear the filter. This should be done before reusing it, because + * just removing all items doesn't clear counters that hit the upper + * bound. + */ + void clear(); + + /* + * Add an item to the filter. + */ + void add(const T* aValue); + + /* + * Remove an item from the filter. + */ + void remove(const T* aValue); + + /* + * Check whether the filter might contain an item. This can + * sometimes return true even if the item is not in the filter, + * but will never return false for items that are actually in the + * filter. + */ + bool mightContain(const T* aValue) const; + + /* + * Methods for add/remove/contain when we already have a hash computed + */ + void add(uint32_t aHash); + void remove(uint32_t aHash); + bool mightContain(uint32_t aHash) const; + +private: + static const size_t kArraySize = (1 << KeySize); + static const uint32_t kKeyMask = (1 << KeySize) - 1; + static const uint32_t kKeyShift = 16; + + static uint32_t hash1(uint32_t aHash) + { + return aHash & kKeyMask; + } + static uint32_t hash2(uint32_t aHash) + { + return (aHash >> kKeyShift) & kKeyMask; + } + + uint8_t& firstSlot(uint32_t aHash) + { + return mCounters[hash1(aHash)]; + } + uint8_t& secondSlot(uint32_t aHash) + { + return mCounters[hash2(aHash)]; + } + + const uint8_t& firstSlot(uint32_t aHash) const + { + return mCounters[hash1(aHash)]; + } + const uint8_t& secondSlot(uint32_t aHash) const + { + return mCounters[hash2(aHash)]; + } + + static bool full(const uint8_t& aSlot) { return aSlot == UINT8_MAX; } + + uint8_t mCounters[kArraySize]; }; template inline void BloomFilter::clear() { - memset(counters, 0, arraySize); + memset(mCounters, 0, kArraySize); } template inline void -BloomFilter::add(uint32_t hash) +BloomFilter::add(uint32_t aHash) { - uint8_t& slot1 = firstSlot(hash); - if (MOZ_LIKELY(!full(slot1))) + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { ++slot1; - - uint8_t& slot2 = secondSlot(hash); - if (MOZ_LIKELY(!full(slot2))) + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { ++slot2; + } } template MOZ_ALWAYS_INLINE void -BloomFilter::add(const T* t) +BloomFilter::add(const T* aValue) { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); return add(hash); } template inline void -BloomFilter::remove(uint32_t hash) +BloomFilter::remove(uint32_t aHash) { // If the slots are full, we don't know whether we bumped them to be // there when we added or not, so just leave them full. - uint8_t& slot1 = firstSlot(hash); - if (MOZ_LIKELY(!full(slot1))) + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { --slot1; - - uint8_t& slot2 = secondSlot(hash); - if (MOZ_LIKELY(!full(slot2))) + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { --slot2; + } } template MOZ_ALWAYS_INLINE void -BloomFilter::remove(const T* t) +BloomFilter::remove(const T* aValue) { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); remove(hash); } template MOZ_ALWAYS_INLINE bool -BloomFilter::mightContain(uint32_t hash) const +BloomFilter::mightContain(uint32_t aHash) const { // Check that all the slots for this hash contain something - return firstSlot(hash) && secondSlot(hash); + return firstSlot(aHash) && secondSlot(aHash); } template MOZ_ALWAYS_INLINE bool -BloomFilter::mightContain(const T* t) const +BloomFilter::mightContain(const T* aValue) const { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); return mightContain(hash); } diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Casting.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Casting.h index 76df0ef27e..dc449af6b6 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Casting.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Casting.h @@ -17,7 +17,8 @@ namespace mozilla { /** - * Return a value of type |To|, containing the underlying bit pattern of |from|. + * Return a value of type |To|, containing the underlying bit pattern of + * |aFrom|. * * |To| and |From| must be types of the same size; be careful of cross-platform * size differences, or this might fail to compile on some but not all @@ -25,16 +26,17 @@ namespace mozilla { */ template inline To -BitwiseCast(const From from) +BitwiseCast(const From aFrom) { static_assert(sizeof(From) == sizeof(To), "To and From must have the same size"); - union { - From from; - To to; + union + { + From mFrom; + To mTo; } u; - u.from = from; - return u.to; + u.mFrom = aFrom; + return u.mTo; } namespace detail { @@ -58,34 +60,39 @@ enum UUComparison { FromIsBigger, FromIsNotBigger }; // Unsigned-to-unsigned range check template sizeof(To)) ? FromIsBigger : FromIsNotBigger> + UUComparison = (sizeof(From) > sizeof(To)) + ? FromIsBigger + : FromIsNotBigger> struct UnsignedUnsignedCheck; template struct UnsignedUnsignedCheck { - public: - static bool checkBounds(const From from) { - return from <= From(To(-1)); - } +public: + static bool checkBounds(const From aFrom) + { + return aFrom <= From(To(-1)); + } }; template struct UnsignedUnsignedCheck { - public: - static bool checkBounds(const From from) { - return true; - } +public: + static bool checkBounds(const From aFrom) + { + return true; + } }; template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - return UnsignedUnsignedCheck::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return UnsignedUnsignedCheck::checkBounds(aFrom); + } }; // Signed-to-unsigned range check @@ -93,14 +100,17 @@ struct BoundsCheckImpl template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - if (from < 0) - return false; - if (sizeof(To) >= sizeof(From)) - return true; - return from <= From(To(-1)); +public: + static bool checkBounds(const From aFrom) + { + if (aFrom < 0) { + return false; + } + if (sizeof(To) >= sizeof(From)) { + return true; } + return aFrom <= From(To(-1)); + } }; // Unsigned-to-signed range check @@ -108,35 +118,40 @@ struct BoundsCheckImpl enum USComparison { FromIsSmaller, FromIsNotSmaller }; template + USComparison = (sizeof(From) < sizeof(To)) + ? FromIsSmaller + : FromIsNotSmaller> struct UnsignedSignedCheck; template struct UnsignedSignedCheck { - public: - static bool checkBounds(const From from) { - return true; - } +public: + static bool checkBounds(const From aFrom) + { + return true; + } }; template struct UnsignedSignedCheck { - public: - static bool checkBounds(const From from) { - const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); - return from <= From(MaxValue); - } +public: + static bool checkBounds(const From aFrom) + { + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + return aFrom <= From(MaxValue); + } }; template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - return UnsignedSignedCheck::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return UnsignedSignedCheck::checkBounds(aFrom); + } }; // Signed-to-signed range check @@ -144,42 +159,46 @@ struct BoundsCheckImpl template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - if (sizeof(From) <= sizeof(To)) - return true; - const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); - const To MinValue = -MaxValue - To(1); - return From(MinValue) <= from && - From(from) <= From(MaxValue); +public: + static bool checkBounds(const From aFrom) + { + if (sizeof(From) <= sizeof(To)) { + return true; } + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + const To MinValue = -MaxValue - To(1); + return From(MinValue) <= aFrom && + From(aFrom) <= From(MaxValue); + } }; template::value && IsIntegral::value> + bool TypesAreIntegral = IsIntegral::value && + IsIntegral::value> class BoundsChecker; template class BoundsChecker { - public: - static bool checkBounds(const From from) { return true; } +public: + static bool checkBounds(const From aFrom) { return true; } }; template class BoundsChecker { - public: - static bool checkBounds(const From from) { - return BoundsCheckImpl::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return BoundsCheckImpl::checkBounds(aFrom); + } }; template inline bool -IsInBounds(const From from) +IsInBounds(const From aFrom) { - return BoundsChecker::checkBounds(from); + return BoundsChecker::checkBounds(aFrom); } } // namespace detail @@ -191,10 +210,10 @@ IsInBounds(const From from) */ template inline To -SafeCast(const From from) +SafeCast(const From aFrom) { - MOZ_ASSERT((detail::IsInBounds(from))); - return static_cast(from); + MOZ_ASSERT((detail::IsInBounds(aFrom))); + return static_cast(aFrom); } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ChaosMode.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ChaosMode.h new file mode 100644 index 0000000000..ff59f2c6ec --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ChaosMode.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_ChaosMode_h +#define mozilla_ChaosMode_h + +#include +#include + +namespace mozilla { + +/** + * When "chaos mode" is activated, code that makes implicitly nondeterministic + * choices is encouraged to make random and extreme choices, to test more + * code paths and uncover bugs. + */ +class ChaosMode +{ +public: + static bool isActive() + { + // Flip this to true to activate chaos mode + return false; + } + + /** + * Returns a somewhat (but not uniformly) random uint32_t < aBound. + * Not to be used for anything except ChaosMode, since it's not very random. + */ + static uint32_t randomUint32LessThan(uint32_t aBound) + { + return uint32_t(rand()) % aBound; + } +}; + +} /* namespace mozilla */ + +#endif /* mozilla_ChaosMode_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Char16.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Char16.h index ba1acd8c76..e54eb0d5c8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Char16.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Char16.h @@ -9,11 +9,12 @@ #ifndef mozilla_Char16_h #define mozilla_Char16_h +#ifdef __cplusplus + /* - * C11 and C++11 introduce a char16_t type and support for UTF-16 string and - * character literals. C++11's char16_t is a distinct builtin type. C11's - * char16_t is a typedef for uint_least16_t. Technically, char16_t is a 16-bit - * code unit of a Unicode code point, not a "character". + * C++11 introduces a char16_t type and support for UTF-16 string and character + * literals. C++11's char16_t is a distinct builtin type. Technically, char16_t + * is a 16-bit code unit of a Unicode code point, not a "character". */ #ifdef _MSC_VER @@ -23,8 +24,7 @@ * to Windows's 16-bit wchar_t so we can declare UTF-16 literals as constant * expressions (and pass char16_t pointers to Windows APIs). We #define * _CHAR16T here in order to prevent yvals.h from overriding our char16_t - * typedefs, which we set to wchar_t for C++ code and to unsigned short for - * C code. + * typedefs, which we set to wchar_t for C++ code. * * In addition, #defining _CHAR16T will prevent yvals.h from defining a * char32_t type, so we have to undo that damage here and provide our own, @@ -32,14 +32,9 @@ */ # define MOZ_UTF16_HELPER(s) L##s # define _CHAR16T -# ifdef __cplusplus - typedef wchar_t char16_t; -# else - typedef unsigned short char16_t; -# endif - typedef unsigned int char32_t; -#elif defined(__cplusplus) && \ - (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)) +typedef wchar_t char16_t; +typedef unsigned int char32_t; +#else /* C++11 has a builtin char16_t type. */ # define MOZ_UTF16_HELPER(s) u##s /** @@ -50,20 +45,6 @@ # ifdef WIN32 # define MOZ_USE_CHAR16_WRAPPER # endif -#elif !defined(__cplusplus) -# if defined(WIN32) -# include - typedef wchar_t char16_t; -# else - /** - * We can't use the stdint.h uint16_t type here because including - * stdint.h will break building some of our C libraries, such as - * sqlite. - */ - typedef unsigned short char16_t; -# endif -#else -# error "Char16.h requires C++11 (or something like it) for UTF-16 support." #endif #ifdef MOZ_USE_CHAR16_WRAPPER @@ -80,86 +61,109 @@ */ class char16ptr_t { - private: - const char16_t* ptr; - static_assert(sizeof(char16_t) == sizeof(wchar_t), "char16_t and wchar_t sizes differ"); - - public: - char16ptr_t(const char16_t* ptr) : ptr(ptr) {} - char16ptr_t(const wchar_t* ptr) : ptr(reinterpret_cast(ptr)) {} - - /* Without this, nullptr assignment would be ambiguous. */ - constexpr char16ptr_t(decltype(nullptr)) : ptr(nullptr) {} - - operator const char16_t*() const { - return ptr; - } - operator const wchar_t*() const { - return reinterpret_cast(ptr); - } - operator const void*() const { - return ptr; - } - operator bool() const { - return ptr != nullptr; - } - operator std::wstring() const { - return std::wstring(static_cast(*this)); - } - - /* Explicit cast operators to allow things like (char16_t*)str. */ - explicit operator char16_t*() const { - return const_cast(ptr); - } - explicit operator wchar_t*() const { - return const_cast(static_cast(*this)); - } - - /** - * Some Windows API calls accept BYTE* but require that data actually be WCHAR*. - * Supporting this requires explicit operators to support the requisite explicit - * casts. - */ - explicit operator const char*() const { - return reinterpret_cast(ptr); - } - explicit operator const unsigned char*() const { - return reinterpret_cast(ptr); - } - explicit operator unsigned char*() const { - return const_cast(reinterpret_cast(ptr)); - } - explicit operator void*() const { - return const_cast(ptr); - } - - /* Some operators used on pointers. */ - char16_t operator[](size_t i) const { - return ptr[i]; - } - bool operator==(const char16ptr_t &x) const { - return ptr == x.ptr; - } - bool operator==(decltype(nullptr)) const { - return ptr == nullptr; - } - bool operator!=(const char16ptr_t &x) const { - return ptr != x.ptr; - } - bool operator!=(decltype(nullptr)) const { - return ptr != nullptr; - } - char16ptr_t operator+(size_t add) const { - return char16ptr_t(ptr + add); - } - ptrdiff_t operator-(const char16ptr_t &other) const { - return ptr - other.ptr; - } +private: + const char16_t* mPtr; + static_assert(sizeof(char16_t) == sizeof(wchar_t), + "char16_t and wchar_t sizes differ"); + +public: + char16ptr_t(const char16_t* aPtr) : mPtr(aPtr) {} + char16ptr_t(const wchar_t* aPtr) : + mPtr(reinterpret_cast(aPtr)) + {} + + /* Without this, nullptr assignment would be ambiguous. */ + constexpr char16ptr_t(decltype(nullptr)) : mPtr(nullptr) {} + + operator const char16_t*() const + { + return mPtr; + } + operator const wchar_t*() const + { + return reinterpret_cast(mPtr); + } + operator const void*() const + { + return mPtr; + } + operator bool() const + { + return mPtr != nullptr; + } + operator std::wstring() const + { + return std::wstring(static_cast(*this)); + } + + /* Explicit cast operators to allow things like (char16_t*)str. */ + explicit operator char16_t*() const + { + return const_cast(mPtr); + } + explicit operator wchar_t*() const + { + return const_cast(static_cast(*this)); + } + + /** + * Some Windows API calls accept BYTE* but require that data actually be + * WCHAR*. Supporting this requires explicit operators to support the + * requisite explicit casts. + */ + explicit operator const char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator const unsigned char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator unsigned char*() const + { + return + const_cast(reinterpret_cast(mPtr)); + } + explicit operator void*() const + { + return const_cast(mPtr); + } + + /* Some operators used on pointers. */ + char16_t operator[](size_t aIndex) const + { + return mPtr[aIndex]; + } + bool operator==(const char16ptr_t& aOther) const + { + return mPtr == aOther.mPtr; + } + bool operator==(decltype(nullptr)) const + { + return mPtr == nullptr; + } + bool operator!=(const char16ptr_t& aOther) const + { + return mPtr != aOther.mPtr; + } + bool operator!=(decltype(nullptr)) const + { + return mPtr != nullptr; + } + char16ptr_t operator+(size_t aValue) const + { + return char16ptr_t(mPtr + aValue); + } + ptrdiff_t operator-(const char16ptr_t& aOther) const + { + return mPtr - aOther.mPtr; + } }; inline decltype((char*)0-(char*)0) -operator-(const char16_t* x, const char16ptr_t y) { - return x - static_cast(y); +operator-(const char16_t* aX, const char16ptr_t aY) +{ + return aX - static_cast(aY); } #else @@ -168,10 +172,6 @@ typedef const char16_t* char16ptr_t; #endif -/* This is a temporary hack until bug 927728 is fixed. */ -#define __PRUNICHAR__ -typedef char16_t PRUnichar; - /* * Macro arguments used in concatenation or stringification won't be expanded. * Therefore, in order for |MOZ_UTF16(FOO)| to work as expected (which is to @@ -182,12 +182,11 @@ typedef char16_t PRUnichar; */ #define MOZ_UTF16(s) MOZ_UTF16_HELPER(s) -#if defined(__cplusplus) && \ - (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)) static_assert(sizeof(char16_t) == 2, "Is char16_t type 16 bits?"); static_assert(char16_t(-1) > char16_t(0), "Is char16_t type unsigned?"); static_assert(sizeof(MOZ_UTF16('A')) == 2, "Is char literal 16 bits?"); static_assert(sizeof(MOZ_UTF16("")[0]) == 2, "Is string char 16 bits?"); + #endif #endif /* mozilla_Char16_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/CheckedInt.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/CheckedInt.h index 050cef8ed8..ad4c5fef41 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/CheckedInt.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/CheckedInt.h @@ -9,21 +9,9 @@ #ifndef mozilla_CheckedInt_h #define mozilla_CheckedInt_h -// Enable relying of Mozilla's MFBT for possibly-available C++11 features -#define MOZ_CHECKEDINT_USE_MFBT - #include - -#ifdef MOZ_CHECKEDINT_USE_MFBT -# include "mozilla/Assertions.h" -#else -# include -# define MOZ_ASSERT(cond, reason) assert((cond) && reason) -# define MOZ_DELETE -#endif - -#include -#include +#include "mozilla/Assertions.h" +#include "mozilla/IntegerTypeTraits.h" namespace mozilla { @@ -47,13 +35,13 @@ struct UnsupportedType {}; template struct IsSupportedPass2 { - static const bool value = false; + static const bool value = false; }; template struct IsSupported { - static const bool value = IsSupportedPass2::value; + static const bool value = IsSupportedPass2::value; }; template<> @@ -134,133 +122,45 @@ struct IsSupportedPass2 { static const bool value = true; }; /* - * Step 2: some integer-traits kind of stuff. + * Step 2: Implement the actual validity checks. + * + * Ideas taken from IntegerLib, code different. */ -template -struct StdintTypeForSizeAndSignedness -{}; - -template<> -struct StdintTypeForSizeAndSignedness<1, true> -{ typedef int8_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<1, false> -{ typedef uint8_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<2, true> -{ typedef int16_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<2, false> -{ typedef uint16_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<4, true> -{ typedef int32_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<4, false> -{ typedef uint32_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<8, true> -{ typedef int64_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<8, false> -{ typedef uint64_t Type; }; - -template -struct UnsignedType -{ - typedef typename StdintTypeForSizeAndSignedness::Type Type; -}; - -template -struct IsSigned -{ - static const bool value = IntegerType(-1) <= IntegerType(0); -}; - template struct TwiceBiggerType { - typedef typename StdintTypeForSizeAndSignedness< - sizeof(IntegerType) * 2, - IsSigned::value - >::Type Type; + typedef typename detail::StdintTypeForSizeAndSignedness< + sizeof(IntegerType) * 2, + IsSigned::value + >::Type Type; }; template struct TwiceBiggerType { - typedef UnsupportedType Type; + typedef UnsupportedType Type; }; -template -struct PositionOfSignBit -{ - static const size_t value = CHAR_BIT * sizeof(IntegerType) - 1; -}; - -template -struct MinValue -{ - private: - typedef typename UnsignedType::Type UnsignedIntegerType; - static const size_t PosOfSignBit = PositionOfSignBit::value; - - public: - // Bitwise ops may return a larger type, that's why we cast explicitly. - // In C++, left bit shifts on signed values is undefined by the standard - // unless the shifted value is representable. - // Notice that signed-to-unsigned conversions are always well-defined in - // the standard as the value congruent to 2**n, as expected. By contrast, - // unsigned-to-signed is only well-defined if the value is representable. - static const IntegerType value = - IsSigned::value - ? IntegerType(UnsignedIntegerType(1) << PosOfSignBit) - : IntegerType(0); -}; - -template -struct MaxValue -{ - // Tricksy, but covered by the unit test. - // Relies heavily on the type of MinValue::value - // being IntegerType. - static const IntegerType value = ~MinValue::value; -}; - -/* - * Step 3: Implement the actual validity checks. - * - * Ideas taken from IntegerLib, code different. - */ - template inline bool -HasSignBit(T x) +HasSignBit(T aX) { // In C++, right bit shifts on negative values is undefined by the standard. // Notice that signed-to-unsigned conversions are always well-defined in the // standard, as the value congruent modulo 2**n as expected. By contrast, // unsigned-to-signed is only well-defined if the value is representable. - return bool(typename UnsignedType::Type(x) - >> PositionOfSignBit::value); + return bool(typename MakeUnsigned::Type(aX) >> + PositionOfSignBit::value); } // Bitwise ops may return a larger type, so it's good to use this inline // helper guaranteeing that the result is really of type T. template inline T -BinaryComplement(T x) +BinaryComplement(T aX) { - return ~x; + return ~aX; } template struct DoesRangeContainRange { - static const bool value = sizeof(T) >= sizeof(U); + static const bool value = sizeof(T) >= sizeof(U); }; template struct DoesRangeContainRange { - static const bool value = sizeof(T) > sizeof(U); + static const bool value = sizeof(T) > sizeof(U); }; template struct DoesRangeContainRange { - static const bool value = false; + static const bool value = false; }; template struct IsInRangeImpl { - static bool run(U) - { - return true; - } + static bool run(U) + { + return true; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return x <= MaxValue::value && x >= MinValue::value; - } + static bool run(U aX) + { + return aX <= MaxValue::value && aX >= MinValue::value; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return x <= MaxValue::value; - } + static bool run(U aX) + { + return aX <= MaxValue::value; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return sizeof(T) > sizeof(U) || x <= U(MaxValue::value); - } + static bool run(U aX) + { + return sizeof(T) > sizeof(U) || aX <= U(MaxValue::value); + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return sizeof(T) >= sizeof(U) - ? x >= 0 - : x >= 0 && x <= U(MaxValue::value); - } + static bool run(U aX) + { + return sizeof(T) >= sizeof(U) + ? aX >= 0 + : aX >= 0 && aX <= U(MaxValue::value); + } }; template inline bool -IsInRange(U x) +IsInRange(U aX) { - return IsInRangeImpl::run(x); + return IsInRangeImpl::run(aX); } template inline bool -IsAddValid(T x, T y) +IsAddValid(T aX, T aY) { - // Addition is valid if the sign of x+y is equal to either that of x or that - // of y. Since the value of x+y is undefined if we have a signed type, we - // compute it using the unsigned type of the same size. - // Beware! These bitwise operations can return a larger integer type, - // if T was a small type like int8_t, so we explicitly cast to T. + // Addition is valid if the sign of aX+aY is equal to either that of aX or + // that of aY. Since the value of aX+aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. Beware! + // These bitwise operations can return a larger integer type, if T was a + // small type like int8_t, so we explicitly cast to T. - typename UnsignedType::Type ux = x; - typename UnsignedType::Type uy = y; - typename UnsignedType::Type result = ux + uy; + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux + uy; return IsSigned::value - ? HasSignBit(BinaryComplement(T((result ^ x) & (result ^ y)))) - : BinaryComplement(x) >= y; + ? HasSignBit(BinaryComplement(T((result ^ aX) & (result ^ aY)))) + : BinaryComplement(aX) >= aY; } template inline bool -IsSubValid(T x, T y) +IsSubValid(T aX, T aY) { - // Subtraction is valid if either x and y have same sign, or x-y and x have - // same sign. Since the value of x-y is undefined if we have a signed type, - // we compute it using the unsigned type of the same size. - typename UnsignedType::Type ux = x; - typename UnsignedType::Type uy = y; - typename UnsignedType::Type result = ux - uy; + // Subtraction is valid if either aX and aY have same sign, or aX-aY and aX + // have same sign. Since the value of aX-aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux - uy; return IsSigned::value - ? HasSignBit(BinaryComplement(T((result ^ x) & (x ^ y)))) - : x >= y; + ? HasSignBit(BinaryComplement(T((result ^ aX) & (aX ^ aY)))) + : aX >= aY; } template struct IsMulValidImpl { - static bool run(T x, T y) - { - typedef typename TwiceBiggerType::Type TwiceBiggerType; - TwiceBiggerType product = TwiceBiggerType(x) * TwiceBiggerType(y); - return IsInRange(product); - } + static bool run(T aX, T aY) + { + typedef typename TwiceBiggerType::Type TwiceBiggerType; + TwiceBiggerType product = TwiceBiggerType(aX) * TwiceBiggerType(aY); + return IsInRange(product); + } }; template struct IsMulValidImpl { - static bool run(T x, T y) - { - const T max = MaxValue::value; - const T min = MinValue::value; - - if (x == 0 || y == 0) - return true; - - if (x > 0) { - return y > 0 - ? x <= max / y - : y >= min / x; - } + static bool run(T aX, T aY) + { + const T max = MaxValue::value; + const T min = MinValue::value; - // If we reach this point, we know that x < 0. - return y > 0 - ? x >= min / y - : y >= max / x; + if (aX == 0 || aY == 0) { + return true; } + if (aX > 0) { + return aY > 0 + ? aX <= max / aY + : aY >= min / aX; + } + + // If we reach this point, we know that aX < 0. + return aY > 0 + ? aX >= min / aY + : aY >= max / aX; + } }; template struct IsMulValidImpl { - static bool run(T x, T y) - { - return y == 0 || x <= MaxValue::value / y; - } + static bool run(T aX, T aY) + { + return aY == 0 || aX <= MaxValue::value / aY; + } }; template inline bool -IsMulValid(T x, T y) +IsMulValid(T aX, T aY) { - return IsMulValidImpl::run(x, y); + return IsMulValidImpl::run(aX, aY); } template inline bool -IsDivValid(T x, T y) +IsDivValid(T aX, T aY) { - // Keep in mind that in the signed case, min/-1 is invalid because abs(min)>max. - return y != 0 && - !(IsSigned::value && x == MinValue::value && y == T(-1)); + // Keep in mind that in the signed case, min/-1 is invalid because + // abs(min)>max. + return aY != 0 && + !(IsSigned::value && aX == MinValue::value && aY == T(-1)); } template::value> @@ -455,36 +356,40 @@ struct IsModValidImpl; template inline bool -IsModValid(T x, T y) +IsModValid(T aX, T aY) { - return IsModValidImpl::run(x, y); + return IsModValidImpl::run(aX, aY); } /* * Mod is pretty simple. * For now, let's just use the ANSI C definition: - * If x or y are negative, the results are implementation defined. + * If aX or aY are negative, the results are implementation defined. * Consider these invalid. - * Undefined for y=0. - * The result will never exceed either x or y. + * Undefined for aY=0. + * The result will never exceed either aX or aY. * - * Checking that x>=0 is a warning when T is unsigned. + * Checking that aX>=0 is a warning when T is unsigned. */ template -struct IsModValidImpl { - static inline bool run(T x, T y) { - return y >= 1; +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + return aY >= 1; } }; template -struct IsModValidImpl { - static inline bool run(T x, T y) { - if (x < 0) +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + if (aX < 0) { return false; - - return y >= 1; + } + return aY >= 1; } }; @@ -494,32 +399,33 @@ struct NegateImpl; template struct NegateImpl { - static CheckedInt negate(const CheckedInt& val) - { - // Handle negation separately for signed/unsigned, for simpler code and to - // avoid an MSVC warning negating an unsigned value. - return CheckedInt(0, val.isValid() && val.mValue == 0); - } + static CheckedInt negate(const CheckedInt& aVal) + { + // Handle negation separately for signed/unsigned, for simpler code and to + // avoid an MSVC warning negating an unsigned value. + return CheckedInt(0, aVal.isValid() && aVal.mValue == 0); + } }; template struct NegateImpl { - static CheckedInt negate(const CheckedInt& val) - { - // Watch out for the min-value, which (with twos-complement) can't be - // negated as -min-value is then (max-value + 1). - if (!val.isValid() || val.mValue == MinValue::value) - return CheckedInt(val.mValue, false); - return CheckedInt(-val.mValue, true); + static CheckedInt negate(const CheckedInt& aVal) + { + // Watch out for the min-value, which (with twos-complement) can't be + // negated as -min-value is then (max-value + 1). + if (!aVal.isValid() || aVal.mValue == MinValue::value) { + return CheckedInt(aVal.mValue, false); } + return CheckedInt(-aVal.mValue, true); + } }; } // namespace detail /* - * Step 4: Now define the CheckedInt class. + * Step 3: Now define the CheckedInt class. */ /** @@ -538,18 +444,18 @@ struct NegateImpl * (e.g. in case of a division by zero). * * For example, suppose that you want to implement a function that computes - * (x+y)/z, that doesn't crash if z==0, and that reports on error (divide by + * (aX+aY)/aZ, that doesn't crash if aZ==0, and that reports on error (divide by * zero or integer overflow). You could code it as follows: @code - bool computeXPlusYOverZ(int x, int y, int z, int *result) + bool computeXPlusYOverZ(int aX, int aY, int aZ, int* aResult) { - CheckedInt checkedResult = (CheckedInt(x) + y) / z; - if (checkedResult.isValid()) { - *result = checkedResult.value(); - return true; - } else { - return false; - } + CheckedInt checkedResult = (CheckedInt(aX) + aY) / aZ; + if (checkedResult.isValid()) { + *aResult = checkedResult.value(); + return true; + } else { + return false; + } } @endcode * @@ -592,193 +498,188 @@ struct NegateImpl template class CheckedInt { - protected: - T mValue; - bool mIsValid; +protected: + T mValue; + bool mIsValid; - template - CheckedInt(U value, bool isValid) : mValue(value), mIsValid(isValid) - { - static_assert(detail::IsSupported::value && - detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + template + CheckedInt(U aValue, bool aIsValid) : mValue(aValue), mIsValid(aIsValid) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - friend struct detail::NegateImpl; - - public: - /** - * Constructs a checked integer with given @a value. The checked integer is - * initialized as valid or invalid depending on whether the @a value - * is in range. - * - * This constructor is not explicit. Instead, the type of its argument is a - * separate template parameter, ensuring that no conversion is performed - * before this constructor is actually called. As explained in the above - * documentation for class CheckedInt, this constructor checks that its - * argument is valid. - */ - template - CheckedInt(U value) - : mValue(T(value)), - mIsValid(detail::IsInRange(value)) - { - static_assert(detail::IsSupported::value && - detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + friend struct detail::NegateImpl; + +public: + /** + * Constructs a checked integer with given @a value. The checked integer is + * initialized as valid or invalid depending on whether the @a value + * is in range. + * + * This constructor is not explicit. Instead, the type of its argument is a + * separate template parameter, ensuring that no conversion is performed + * before this constructor is actually called. As explained in the above + * documentation for class CheckedInt, this constructor checks that its + * argument is valid. + */ + template + CheckedInt(U aValue) + : mValue(T(aValue)), + mIsValid(detail::IsInRange(aValue)) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - template - friend class CheckedInt; + template + friend class CheckedInt; - template - CheckedInt toChecked() const - { - CheckedInt ret(mValue); - ret.mIsValid = ret.mIsValid && mIsValid; - return ret; - } + template + CheckedInt toChecked() const + { + CheckedInt ret(mValue); + ret.mIsValid = ret.mIsValid && mIsValid; + return ret; + } - /** Constructs a valid checked integer with initial value 0 */ - CheckedInt() : mValue(0), mIsValid(true) - { - static_assert(detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + /** Constructs a valid checked integer with initial value 0 */ + CheckedInt() : mValue(0), mIsValid(true) + { + static_assert(detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - /** @returns the actual value */ - T value() const - { - MOZ_ASSERT(mIsValid, "Invalid checked integer (division by zero or integer overflow)"); - return mValue; - } + /** @returns the actual value */ + T value() const + { + MOZ_ASSERT(mIsValid, "Invalid checked integer (division by zero or integer overflow)"); + return mValue; + } - /** - * @returns true if the checked integer is valid, i.e. is not the result - * of an invalid operation or of an operation involving an invalid checked - * integer - */ - bool isValid() const - { - return mIsValid; - } + /** + * @returns true if the checked integer is valid, i.e. is not the result + * of an invalid operation or of an operation involving an invalid checked + * integer + */ + bool isValid() const + { + return mIsValid; + } - template - friend CheckedInt operator +(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator +=(U rhs); - - template - friend CheckedInt operator -(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator -=(U rhs); - - template - friend CheckedInt operator *(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator *=(U rhs); - - template - friend CheckedInt operator /(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator /=(U rhs); - - template - friend CheckedInt operator %(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator %=(U rhs); - - CheckedInt operator -() const - { - return detail::NegateImpl::negate(*this); - } + template + friend CheckedInt operator +(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator +=(U aRhs); + + template + friend CheckedInt operator -(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator -=(U aRhs); + + template + friend CheckedInt operator *(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator *=(U aRhs); + + template + friend CheckedInt operator /(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator /=(U aRhs); + + template + friend CheckedInt operator %(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator %=(U aRhs); + + CheckedInt operator -() const + { + return detail::NegateImpl::negate(*this); + } - /** - * @returns true if the left and right hand sides are valid - * and have the same value. - * - * Note that these semantics are the reason why we don't offer - * a operator!=. Indeed, we'd want to have a!=b be equivalent to !(a==b) - * but that would mean that whenever a or b is invalid, a!=b - * is always true, which would be very confusing. - * - * For similar reasons, operators <, >, <=, >= would be very tricky to - * specify, so we just avoid offering them. - * - * Notice that these == semantics are made more reasonable by these facts: - * 1. a==b implies equality at the raw data level - * (the converse is false, as a==b is never true among invalids) - * 2. This is similar to the behavior of IEEE floats, where a==b - * means that a and b have the same value *and* neither is NaN. - */ - bool operator ==(const CheckedInt& other) const - { - return mIsValid && other.mIsValid && mValue == other.mValue; - } + /** + * @returns true if the left and right hand sides are valid + * and have the same value. + * + * Note that these semantics are the reason why we don't offer + * a operator!=. Indeed, we'd want to have a!=b be equivalent to !(a==b) + * but that would mean that whenever a or b is invalid, a!=b + * is always true, which would be very confusing. + * + * For similar reasons, operators <, >, <=, >= would be very tricky to + * specify, so we just avoid offering them. + * + * Notice that these == semantics are made more reasonable by these facts: + * 1. a==b implies equality at the raw data level + * (the converse is false, as a==b is never true among invalids) + * 2. This is similar to the behavior of IEEE floats, where a==b + * means that a and b have the same value *and* neither is NaN. + */ + bool operator ==(const CheckedInt& aOther) const + { + return mIsValid && aOther.mIsValid && mValue == aOther.mValue; + } - /** prefix ++ */ - CheckedInt& operator++() - { - *this += 1; - return *this; - } + /** prefix ++ */ + CheckedInt& operator++() + { + *this += 1; + return *this; + } - /** postfix ++ */ - CheckedInt operator++(int) - { - CheckedInt tmp = *this; - *this += 1; - return tmp; - } + /** postfix ++ */ + CheckedInt operator++(int) + { + CheckedInt tmp = *this; + *this += 1; + return tmp; + } - /** prefix -- */ - CheckedInt& operator--() - { - *this -= 1; - return *this; - } + /** prefix -- */ + CheckedInt& operator--() + { + *this -= 1; + return *this; + } - /** postfix -- */ - CheckedInt operator--(int) - { - CheckedInt tmp = *this; - *this -= 1; - return tmp; - } + /** postfix -- */ + CheckedInt operator--(int) + { + CheckedInt tmp = *this; + *this -= 1; + return tmp; + } - private: - /** - * The !=, <, <=, >, >= operators are disabled: - * see the comment on operator==. - */ - template - bool operator !=(U other) const MOZ_DELETE; - template - bool operator <(U other) const MOZ_DELETE; - template - bool operator <=(U other) const MOZ_DELETE; - template - bool operator >(U other) const MOZ_DELETE; - template - bool operator >=(U other) const MOZ_DELETE; +private: + /** + * The !=, <, <=, >, >= operators are disabled: + * see the comment on operator==. + */ + template bool operator !=(U aOther) const MOZ_DELETE; + template bool operator < (U aOther) const MOZ_DELETE; + template bool operator <=(U aOther) const MOZ_DELETE; + template bool operator > (U aOther) const MOZ_DELETE; + template bool operator >=(U aOther) const MOZ_DELETE; }; -#define MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP) \ -template \ -inline CheckedInt operator OP(const CheckedInt &lhs, \ - const CheckedInt &rhs) \ -{ \ - if (!detail::Is##NAME##Valid(lhs.mValue, rhs.mValue)) \ - return CheckedInt(0, false); \ - \ - return CheckedInt(lhs.mValue OP rhs.mValue, \ - lhs.mIsValid && rhs.mIsValid); \ -} +#define MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP) \ + template \ + inline CheckedInt \ + operator OP(const CheckedInt &aLhs, const CheckedInt &aRhs) \ + { \ + if (!detail::Is##NAME##Valid(aLhs.mValue, aRhs.mValue)) { \ + return CheckedInt(0, false); \ + } \ + return CheckedInt(aLhs.mValue OP aRhs.mValue, \ + aLhs.mIsValid && aRhs.mIsValid); \ + } MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Add, +) MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Sub, -) @@ -799,47 +700,47 @@ namespace detail { template struct CastToCheckedIntImpl { - typedef CheckedInt ReturnType; - static CheckedInt run(U u) { return u; } + typedef CheckedInt ReturnType; + static CheckedInt run(U aU) { return aU; } }; template struct CastToCheckedIntImpl > { - typedef const CheckedInt& ReturnType; - static const CheckedInt& run(const CheckedInt& u) { return u; } + typedef const CheckedInt& ReturnType; + static const CheckedInt& run(const CheckedInt& aU) { return aU; } }; } // namespace detail template inline typename detail::CastToCheckedIntImpl::ReturnType -castToCheckedInt(U u) +castToCheckedInt(U aU) { static_assert(detail::IsSupported::value && detail::IsSupported::value, "This type is not supported by CheckedInt"); - return detail::CastToCheckedIntImpl::run(u); + return detail::CastToCheckedIntImpl::run(aU); } -#define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP) \ -template \ -template \ -CheckedInt& CheckedInt::operator COMPOUND_OP(U rhs) \ -{ \ - *this = *this OP castToCheckedInt(rhs); \ - return *this; \ -} \ -template \ -inline CheckedInt operator OP(const CheckedInt &lhs, U rhs) \ -{ \ - return lhs OP castToCheckedInt(rhs); \ -} \ -template \ -inline CheckedInt operator OP(U lhs, const CheckedInt &rhs) \ -{ \ - return castToCheckedInt(lhs) OP rhs; \ -} +#define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP) \ + template \ + template \ + CheckedInt& CheckedInt::operator COMPOUND_OP(U aRhs) \ + { \ + *this = *this OP castToCheckedInt(aRhs); \ + return *this; \ + } \ + template \ + inline CheckedInt operator OP(const CheckedInt &aLhs, U aRhs) \ + { \ + return aLhs OP castToCheckedInt(aRhs); \ + } \ + template \ + inline CheckedInt operator OP(U aLhs, const CheckedInt &aRhs) \ + { \ + return castToCheckedInt(aLhs) OP aRhs; \ + } MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(+, +=) MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(*, *=) @@ -851,16 +752,16 @@ MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(%, %=) template inline bool -operator ==(const CheckedInt &lhs, U rhs) +operator ==(const CheckedInt &aLhs, U aRhs) { - return lhs == castToCheckedInt(rhs); + return aLhs == castToCheckedInt(aRhs); } template inline bool -operator ==(U lhs, const CheckedInt &rhs) +operator ==(U aLhs, const CheckedInt &aRhs) { - return castToCheckedInt(lhs) == rhs; + return castToCheckedInt(aLhs) == aRhs; } // Convenience typedefs. diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Compiler.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Compiler.h index fd5c98c98d..50f127da86 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Compiler.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Compiler.h @@ -9,23 +9,41 @@ #ifndef mozilla_Compiler_h #define mozilla_Compiler_h +#define MOZ_IS_GCC 0 +#define MOS_IS_MSVC 0 + #if !defined(__clang__) && defined(__GNUC__) -#define MOZ_IS_GCC 1 +# undef MOZ_IS_GCC +# define MOZ_IS_GCC 1 /* * This macro should simplify gcc version checking. For example, to check - * for gcc 4.5.1 or later, check `#ifdef MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`. + * for gcc 4.5.1 or later, check `#if MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`. */ # define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel) \ ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \ >= ((major) * 10000 + (minor) * 100 + (patchlevel))) -#if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0) -# error "mfbt (and Gecko) require at least gcc 4.4 to build." -#endif +# if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0) +# error "mfbt (and Gecko) require at least gcc 4.4 to build." +# endif -#else +#elif defined(_MSC_VER) -#define MOZ_IS_GCC 0 +# undef MOZ_IS_MSVC +# define MOZ_IS_MSVC 1 + /* + * This macro should simplify MSVC version checking. For example, to check + * for VC10 or later, check `#ifdef MOZ_MSVC_VERSION_AT_LEAST(10)`. + */ +# define MOZ_MSVC_VERSION_AT_LEAST(version) \ + (version == 10 ? _MSC_VER >= 1600 : \ + (version == 11 ? _MSC_VER >= 1700 : \ + (version == 12 ? _MSC_VER >= 1800 : \ + (version == 13 ? _MSC_VER >= 1900 : \ + 0)))) +# if !MOZ_MSVC_VERSION_AT_LEAST(10) +# error "mfbt (and Gecko) require at least MSVC 2010 RTM to build." +# endif #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Compression.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Compression.h index 2b8a7a7d8e..a764a1b5d5 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Compression.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Compression.h @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -22,41 +23,41 @@ namespace Compression { * * Compared to zlib it compresses at about 10x the speed, decompresses at about * 4x the speed and produces output of about 1.5x the size. - * */ class LZ4 { - public: - /** - * Compresses 'inputSize' bytes from 'source' into 'dest'. - * Destination buffer must be already allocated, - * and must be sized to handle worst cases situations (input data not compressible) - * Worst case size evaluation is provided by function LZ4_compressBound() + * Compresses |aInputSize| bytes from |aSource| into |aDest|. Destination + * buffer must be already allocated, and must be sized to handle worst cases + * situations (input data not compressible). Worst case size evaluation is + * provided by function maxCompressedSize() * - * @param inputSize is the input size. Max supported value is ~1.9GB - * @param return the number of bytes written in buffer dest + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return the number of bytes written in buffer |aDest| */ - static MFBT_API size_t compress(const char* source, size_t inputSize, char* dest); + static MFBT_API size_t + compress(const char* aSource, size_t aInputSize, char* aDest); /** - * Compress 'inputSize' bytes from 'source' into an output buffer - * 'dest' of maximum size 'maxOutputSize'. If it cannot achieve it, + * Compress |aInputSize| bytes from |aSource| into an output buffer + * |aDest| of maximum size |aMaxOutputSize|. If it cannot achieve it, * compression will stop, and result of the function will be zero, - * 'dest' will still be written to, but since the number of input + * |aDest| will still be written to, but since the number of input * bytes consumed is not returned the result is not usable. * * This function never writes outside of provided output buffer. * - * @param inputSize is the input size. Max supported value is ~1.9GB - * @param maxOutputSize is the size of the destination buffer (which must be already allocated) - * @return the number of bytes written in buffer 'dest' - or 0 if the compression fails - */ - static MFBT_API size_t compressLimitedOutput(const char* source, size_t inputSize, char* dest, - size_t maxOutputSize); + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @param aMaxOutputSize is the size of the destination buffer (which must + * be already allocated) + * @return the number of bytes written in buffer |aDest| or 0 if the + * compression fails + */ + static MFBT_API size_t + compressLimitedOutput(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize); /** * If the source stream is malformed, the function will stop decoding @@ -66,48 +67,50 @@ class LZ4 * This function never writes outside of provided buffers, and never * modifies input buffer. * - * note : destination buffer must be already allocated. - * its size must be a minimum of 'outputSize' bytes. - * @param outputSize is the output size, therefore the original size + * Note: destination buffer must be already allocated, and its size must be a + * minimum of |aOutputSize| bytes. + * + * @param aOutputSize is the output size, therefore the original size * @return the number of bytes read in the source buffer - */ - static MFBT_API bool decompress(const char* source, char* dest, size_t outputSize); + */ + static MFBT_API bool + decompress(const char* aSource, char* aDest, size_t aOutputSize); /** * If the source stream is malformed, the function will stop decoding * and return false. * - * This function never writes beyond dest + maxOutputSize, and is + * This function never writes beyond aDest + aMaxOutputSize, and is * therefore protected against malicious data packets. * - * note : Destination buffer must be already allocated. - * This version is slightly slower than the decompress - * without the maxOutputSize + * Note: Destination buffer must be already allocated. This version is + * slightly slower than the decompress without the aMaxOutputSize. * - * @param inputSize is the length of the input compressed data - * @param maxOutputSize is the size of the destination buffer (which must be already allocated) - * @param outputSize the actual number of bytes decoded in the destination buffer (necessarily <= maxOutputSize) - - */ - static MFBT_API bool decompress(const char* source, size_t inputSize, char* dest, - size_t maxOutputSize, size_t *outputSize); + * @param aInputSize is the length of the input compressed data + * @param aMaxOutputSize is the size of the destination buffer (which must be + * already allocated) + * @param aOutputSize the actual number of bytes decoded in the destination + * buffer (necessarily <= aMaxOutputSize) + */ + static MFBT_API bool + decompress(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize, size_t* aOutputSize); /* - Provides the maximum size that LZ4 may output in a "worst case" - scenario (input data not compressible) primarily useful for memory - allocation of output buffer. - note : this function is limited by "int" range (2^31-1) - - @param inputSize is the input size. Max supported value is ~1.9GB - @return maximum output size in a "worst case" scenario - */ - static inline size_t maxCompressedSize(size_t inputSize) + * Provides the maximum size that LZ4 may output in a "worst case" + * scenario (input data not compressible) primarily useful for memory + * allocation of output buffer. + * note : this function is limited by "int" range (2^31-1) + * + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return maximum output size in a "worst case" scenario + */ + static inline size_t maxCompressedSize(size_t aInputSize) { - size_t max = ((inputSize) + ((inputSize)/255) + 16); - MOZ_ASSERT(max > inputSize); - return max; + size_t max = (aInputSize + (aInputSize / 255) + 16); + MOZ_ASSERT(max > aInputSize); + return max; } - }; } /* namespace Compression */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/DebugOnly.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/DebugOnly.h index e5f0d729b5..5d0197b194 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/DebugOnly.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/DebugOnly.h @@ -12,6 +12,8 @@ #ifndef mozilla_DebugOnly_h #define mozilla_DebugOnly_h +#include "mozilla/Attributes.h" + namespace mozilla { /** @@ -27,50 +29,51 @@ namespace mozilla { * * DebugOnly instances can only be coerced to T in debug builds. In release * builds they don't have a value, so type coercion is not well defined. + * + * Note that DebugOnly instances still take up one byte of space, plus padding, + * when used as members of structs. */ template class DebugOnly { - public: +public: #ifdef DEBUG - T value; + T value; + + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T& aOther) : value(aOther) { } + DebugOnly(const DebugOnly& aOther) : value(aOther.value) { } + DebugOnly& operator=(const T& aRhs) { + value = aRhs; + return *this; + } - DebugOnly() { } - DebugOnly(const T& other) : value(other) { } - DebugOnly(const DebugOnly& other) : value(other.value) { } - DebugOnly& operator=(const T& rhs) { - value = rhs; - return *this; - } - void operator++(int) { - value++; - } - void operator--(int) { - value--; - } + void operator++(int) { value++; } + void operator--(int) { value--; } - T* operator&() { return &value; } + T* operator&() { return &value; } - operator T&() { return value; } - operator const T&() const { return value; } + operator T&() { return value; } + operator const T&() const { return value; } - T& operator->() { return value; } + T& operator->() { return value; } + const T& operator->() const { return value; } #else - DebugOnly() { } - DebugOnly(const T&) { } - DebugOnly(const DebugOnly&) { } - DebugOnly& operator=(const T&) { return *this; } - void operator++(int) { } - void operator--(int) { } + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T&) { } + DebugOnly(const DebugOnly&) { } + DebugOnly& operator=(const T&) { return *this; } + void operator++(int) { } + void operator--(int) { } #endif - /* - * DebugOnly must always have a destructor or else it will - * generate "unused variable" warnings, exactly what it's intended - * to avoid! - */ - ~DebugOnly() {} + /* + * DebugOnly must always have a destructor or else it will + * generate "unused variable" warnings, exactly what it's intended + * to avoid! + */ + ~DebugOnly() {} }; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Decimal.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Decimal.h index 3c67d784c9..9f4926bd06 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Decimal.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Decimal.h @@ -112,7 +112,7 @@ class Decimal { Sign m_sign; }; - MFBT_API Decimal(int32_t = 0); + MFBT_API explicit Decimal(int32_t = 0); MFBT_API Decimal(Sign, int exponent, uint64_t coefficient); MFBT_API Decimal(const Decimal&); @@ -185,7 +185,7 @@ class Decimal { int exponent; }; - MFBT_API Decimal(double); + MFBT_API explicit Decimal(double); MFBT_API Decimal compareTo(const Decimal&) const; static MFBT_API AlignedOperands alignOperands(const Decimal& lhs, const Decimal& rhs); diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Endian.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Endian.h index cb6bd27c05..e4e1ff8549 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Endian.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Endian.h @@ -42,21 +42,22 @@ * * class ExampleHeader * { - * private: - * uint32_t magic; - * uint32_t length; - * uint32_t totalRecords; - * uint64_t checksum; + * private: + * uint32_t mMagic; + * uint32_t mLength; + * uint32_t mTotalRecords; + * uint64_t mChecksum; * - * public: - * ExampleHeader(const void* data) { - * const uint8_t* ptr = static_cast(data); - * magic = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * length = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * totalRecords = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * checksum = BigEndian::readUint64(ptr); - * } - * ... + * public: + * ExampleHeader(const void* data) + * { + * const uint8_t* ptr = static_cast(data); + * mMagic = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mLength = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mTotalRecords = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mChecksum = BigEndian::readUint64(ptr); + * } + * ... * }; */ @@ -91,7 +92,7 @@ # else # error "CPU type is unknown" # endif -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) # if __LITTLE_ENDIAN__ # define MOZ_LITTLE_ENDIAN 1 # elif __BIG_ENDIAN__ @@ -119,17 +120,16 @@ * cases. */ #elif defined(__sparc) || defined(__sparc__) || \ - defined(_POWER) || defined(__powerpc__) || \ - defined(__ppc__) || defined(__hppa) || \ + defined(_POWER) || defined(__hppa) || \ defined(_MIPSEB) || defined(__ARMEB__) || \ - defined(__s390__) || \ + defined(__s390__) || defined(__AARCH64EB__) || \ (defined(__sh__) && defined(__LITTLE_ENDIAN__)) || \ (defined(__ia64) && defined(__BIG_ENDIAN__)) # define MOZ_BIG_ENDIAN 1 #elif defined(__i386) || defined(__i386__) || \ defined(__x86_64) || defined(__x86_64__) || \ defined(_MIPSEL) || defined(__ARMEL__) || \ - defined(__alpha__) || \ + defined(__alpha__) || defined(__AARCH64EL__) || \ (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ (defined(__ia64) && !defined(__BIG_ENDIAN__)) # define MOZ_LITTLE_ENDIAN 1 @@ -170,12 +170,12 @@ struct Swapper; template struct Swapper { - static T swap(T value) + static T swap(T aValue) { #if defined(MOZ_HAVE_BUILTIN_BYTESWAP16) - return MOZ_HAVE_BUILTIN_BYTESWAP16(value); + return MOZ_HAVE_BUILTIN_BYTESWAP16(aValue); #else - return T(((value & 0x00ff) << 8) | ((value & 0xff00) >> 8)); + return T(((aValue & 0x00ff) << 8) | ((aValue & 0xff00) >> 8)); #endif } }; @@ -183,17 +183,17 @@ struct Swapper template struct Swapper { - static T swap(T value) + static T swap(T aValue) { #if defined(__clang__) || defined(__GNUC__) - return T(__builtin_bswap32(value)); + return T(__builtin_bswap32(aValue)); #elif defined(_MSC_VER) - return T(_byteswap_ulong(value)); + return T(_byteswap_ulong(aValue)); #else - return T(((value & 0x000000ffU) << 24) | - ((value & 0x0000ff00U) << 8) | - ((value & 0x00ff0000U) >> 8) | - ((value & 0xff000000U) >> 24)); + return T(((aValue & 0x000000ffU) << 24) | + ((aValue & 0x0000ff00U) << 8) | + ((aValue & 0x00ff0000U) >> 8) | + ((aValue & 0xff000000U) >> 24)); #endif } }; @@ -201,21 +201,21 @@ struct Swapper template struct Swapper { - static inline T swap(T value) + static inline T swap(T aValue) { #if defined(__clang__) || defined(__GNUC__) - return T(__builtin_bswap64(value)); + return T(__builtin_bswap64(aValue)); #elif defined(_MSC_VER) - return T(_byteswap_uint64(value)); + return T(_byteswap_uint64(aValue)); #else - return T(((value & 0x00000000000000ffULL) << 56) | - ((value & 0x000000000000ff00ULL) << 40) | - ((value & 0x0000000000ff0000ULL) << 24) | - ((value & 0x00000000ff000000ULL) << 8) | - ((value & 0x000000ff00000000ULL) >> 8) | - ((value & 0x0000ff0000000000ULL) >> 24) | - ((value & 0x00ff000000000000ULL) >> 40) | - ((value & 0xff00000000000000ULL) >> 56)); + return T(((aValue & 0x00000000000000ffULL) << 56) | + ((aValue & 0x000000000000ff00ULL) << 40) | + ((aValue & 0x0000000000ff0000ULL) << 24) | + ((aValue & 0x00000000ff000000ULL) << 8) | + ((aValue & 0x000000ff00000000ULL) >> 8) | + ((aValue & 0x0000ff0000000000ULL) >> 24) | + ((aValue & 0x00ff000000000000ULL) >> 40) | + ((aValue & 0xff00000000000000ULL) >> 56)); #endif } }; @@ -230,360 +230,415 @@ enum Endianness { Little, Big }; class EndianUtils { - /** - * Assert that the memory regions [dest, dest+count) and [src, src+count] - * do not overlap. count is given in bytes. - */ - static void assertNoOverlap(const void* dest, const void* src, size_t count) - { - DebugOnly byteDestPtr = static_cast(dest); - DebugOnly byteSrcPtr = static_cast(src); - MOZ_ASSERT((byteDestPtr <= byteSrcPtr && - byteDestPtr + count <= byteSrcPtr) || - (byteSrcPtr <= byteDestPtr && - byteSrcPtr + count <= byteDestPtr)); - } + /** + * Assert that the memory regions [aDest, aDest+aCount) and + * [aSrc, aSrc+aCount] do not overlap. aCount is given in bytes. + */ + static void assertNoOverlap(const void* aDest, const void* aSrc, + size_t aCount) + { + DebugOnly byteDestPtr = static_cast(aDest); + DebugOnly byteSrcPtr = static_cast(aSrc); + MOZ_ASSERT((byteDestPtr <= byteSrcPtr && + byteDestPtr + aCount <= byteSrcPtr) || + (byteSrcPtr <= byteDestPtr && + byteSrcPtr + aCount <= byteDestPtr)); + } - template - static void assertAligned(T* ptr) - { - MOZ_ASSERT((uintptr_t(ptr) % sizeof(T)) == 0, "Unaligned pointer!"); + template + static void assertAligned(T* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % sizeof(T)) == 0, "Unaligned pointer!"); + } + +protected: + /** + * Return |aValue| converted from SourceEndian encoding to DestEndian + * encoding. + */ + template + static inline T maybeSwap(T aValue) + { + if (SourceEndian == DestEndian) { + return aValue; } + return Swapper::swap(aValue); + } - protected: - /** - * Return |value| converted from SourceEndian encoding to DestEndian - * encoding. - */ - template - static inline T maybeSwap(T value) - { - if (SourceEndian == DestEndian) - return value; + /** + * Convert |aCount| elements at |aPtr| from SourceEndian encoding to + * DestEndian encoding. + */ + template + static inline void maybeSwapInPlace(T* aPtr, size_t aCount) + { + assertAligned(aPtr); - return Swapper::swap(value); + if (SourceEndian == DestEndian) { + return; } + for (size_t i = 0; i < aCount; i++) { + aPtr[i] = Swapper::swap(aPtr[i]); + } + } - /** - * Convert |count| elements at |ptr| from SourceEndian encoding to - * DestEndian encoding. - */ - template - static inline void maybeSwapInPlace(T* ptr, size_t count) - { - assertAligned(ptr); + /** + * Write |aCount| elements to the unaligned address |aDest| in DestEndian + * format, using elements found at |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapTo(void* aDest, const T* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aSrc); - if (SourceEndian == DestEndian) - return; + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; + } - for (size_t i = 0; i < count; i++) - ptr[i] = Swapper::swap(ptr[i]); + uint8_t* byteDestPtr = static_cast(aDest); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + u.mVal = maybeSwap(aSrc[i]); + memcpy(byteDestPtr, u.mBuffer, sizeof(T)); + byteDestPtr += sizeof(T); } + } - /** - * Write |count| elements to the unaligned address |dest| in DestEndian - * format, using elements found at |src| in SourceEndian format. - */ - template - static void copyAndSwapTo(void* dest, const T* src, size_t count) - { - assertNoOverlap(dest, src, count * sizeof(T)); - assertAligned(src); - - if (SourceEndian == DestEndian) { - memcpy(dest, src, count * sizeof(T)); - return; - } - - uint8_t* byteDestPtr = static_cast(dest); - for (size_t i = 0; i < count; ++i) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - u.val = maybeSwap(src[i]); - memcpy(byteDestPtr, u.buffer, sizeof(T)); - byteDestPtr += sizeof(T); - } + /** + * Write |aCount| elements to |aDest| in DestEndian format, using elements + * found at the unaligned address |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapFrom(T* aDest, const void* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aDest); + + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; } - /** - * Write |count| elements to |dest| in DestEndian format, using elements - * found at the unaligned address |src| in SourceEndian format. - */ - template - static void copyAndSwapFrom(T* dest, const void* src, size_t count) - { - assertNoOverlap(dest, src, count * sizeof(T)); - assertAligned(dest); - - if (SourceEndian == DestEndian) { - memcpy(dest, src, count * sizeof(T)); - return; - } - - const uint8_t* byteSrcPtr = static_cast(src); - for (size_t i = 0; i < count; ++i) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - memcpy(u.buffer, byteSrcPtr, sizeof(T)); - dest[i] = maybeSwap(u.val); - byteSrcPtr += sizeof(T); - } + const uint8_t* byteSrcPtr = static_cast(aSrc); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, byteSrcPtr, sizeof(T)); + aDest[i] = maybeSwap(u.mVal); + byteSrcPtr += sizeof(T); } + } }; template class Endian : private EndianUtils { - protected: - /** Read a uint16_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint16_t readUint16(const void* p) { - return read(p); - } +protected: + /** Read a uint16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint16_t readUint16(const void* aPtr) + { + return read(aPtr); + } - /** Read a uint32_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint32_t readUint32(const void* p) { - return read(p); - } + /** Read a uint32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint32_t readUint32(const void* aPtr) + { + return read(aPtr); + } - /** Read a uint64_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint64_t readUint64(const void* p) { - return read(p); - } + /** Read a uint64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint64_t readUint64(const void* aPtr) + { + return read(aPtr); + } - /** Read an int16_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int16_t readInt16(const void* p) { - return read(p); - } + /** Read an int16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int16_t readInt16(const void* aPtr) + { + return read(aPtr); + } - /** Read an int32_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int32_t readInt32(const void* p) { - return read(p); - } + /** Read an int32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int32_t readInt32(const void* aPtr) + { + return read(aPtr); + } - /** Read an int64_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int64_t readInt64(const void* p) { - return read(p); - } + /** Read an int64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int64_t readInt64(const void* aPtr) + { + return read(aPtr); + } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint16(void* p, uint16_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint32(void* p, uint32_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint64(void* p, uint64_t val) { - write(p, val); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint16(void* aPtr, uint16_t aValue) + { + write(aPtr, aValue); + } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt16(void* p, int16_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt32(void* p, int32_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt64(void* p, int64_t val) { - write(p, val); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint32(void* aPtr, uint32_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T to little-endian format. - * - * This function is intended for cases where you have data in your - * native-endian format and you need it to appear in little-endian - * format for transmission. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToLittleEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to little-endian format if ThisEndian is Big. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapToLittleEndian(void* dest, const T* src, - size_t count) { - copyAndSwapTo(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapToLittleEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint64(void* aPtr, uint64_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T to big-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToBigEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to big-endian format if ThisEndian is Little. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapToBigEndian(void* dest, const T* src, size_t count) { - copyAndSwapTo(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapToBigEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt16(void* aPtr, int16_t aValue) + { + write(aPtr, aValue); + } - /* - * Synonyms for the big-endian functions, for better readability - * in network code. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToNetworkOrder(T value) { - return swapToBigEndian(value); - } - template - static void - copyAndSwapToNetworkOrder(void* dest, const T* src, size_t count) { - copyAndSwapToBigEndian(dest, src, count); - } - template - static void - swapToNetworkOrderInPlace(T* p, size_t count) { - swapToBigEndianInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt32(void* aPtr, int32_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T from little-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromLittleEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to little-endian format if ThisEndian is Big. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapFromLittleEndian(T* dest, const void* src, - size_t count) { - copyAndSwapFrom(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapFromLittleEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt64(void* aPtr, int64_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T from big-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromBigEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to big-endian format if ThisEndian is Little. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapFromBigEndian(T* dest, const void* src, - size_t count) { - copyAndSwapFrom(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapFromBigEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /* + * Converts a value of type T to little-endian format. + * + * This function is intended for cases where you have data in your + * native-endian format and you need it to appear in little-endian + * format for transmission. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToLittleEndian(T aValue) + { + return maybeSwap(aValue); + } - /* - * Synonyms for the big-endian functions, for better readability - * in network code. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromNetworkOrder(T value) { - return swapFromBigEndian(value); - } - template - static void copyAndSwapFromNetworkOrder(T* dest, const void* src, - size_t count) { - copyAndSwapFromBigEndian(dest, src, count); - } - template - static void swapFromNetworkOrderInPlace(T* p, size_t count) { - swapFromBigEndianInPlace(p, count); - } + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToLittleEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } - private: - /** - * Read a value of type T, encoded in endianness ThisEndian from |p|. - * Return that value encoded in native endianness. - */ - template - static T read(const void* p) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - memcpy(u.buffer, p, sizeof(T)); - return maybeSwap(u.val); - } + /* + * Likewise, but converts values in place. + */ + template + static void swapToLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } - /** - * Write a value of type T, in native endianness, to |p|, in ThisEndian - * endianness. - */ - template - static void write(void* p, T value) { - T tmp = maybeSwap(value); - memcpy(p, &tmp, sizeof(T)); - } + /* + * Converts a value of type T to big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToBigEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapToBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + + template + MOZ_WARN_UNUSED_RESULT static T swapToNetworkOrder(T aValue) + { + return swapToBigEndian(aValue); + } + + template + static void + copyAndSwapToNetworkOrder(void* aDest, const T* aSrc, size_t aCount) + { + copyAndSwapToBigEndian(aDest, aSrc, aCount); + } + + template + static void + swapToNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapToBigEndianInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from little-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromLittleEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromLittleEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromBigEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromNetworkOrder(T aValue) + { + return swapFromBigEndian(aValue); + } + + template + static void copyAndSwapFromNetworkOrder(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFromBigEndian(aDest, aSrc, aCount); + } + + template + static void swapFromNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapFromBigEndianInPlace(aPtr, aCount); + } + +private: + /** + * Read a value of type T, encoded in endianness ThisEndian from |aPtr|. + * Return that value encoded in native endianness. + */ + template + static T read(const void* aPtr) + { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, aPtr, sizeof(T)); + return maybeSwap(u.mVal); + } + + /** + * Write a value of type T, in native endianness, to |aPtr|, in ThisEndian + * endianness. + */ + template + static void write(void* aPtr, T aValue) + { + T tmp = maybeSwap(aValue); + memcpy(aPtr, &tmp, sizeof(T)); + } - Endian() MOZ_DELETE; - Endian(const Endian& other) MOZ_DELETE; - void operator=(const Endian& other) MOZ_DELETE; + Endian() MOZ_DELETE; + Endian(const Endian& aTther) MOZ_DELETE; + void operator=(const Endian& aOther) MOZ_DELETE; }; template class EndianReadWrite : public Endian { - private: - typedef Endian super; - - public: - using super::readUint16; - using super::readUint32; - using super::readUint64; - using super::readInt16; - using super::readInt32; - using super::readInt64; - using super::writeUint16; - using super::writeUint32; - using super::writeUint64; - using super::writeInt16; - using super::writeInt32; - using super::writeInt64; +private: + typedef Endian super; + +public: + using super::readUint16; + using super::readUint32; + using super::readUint64; + using super::readInt16; + using super::readInt32; + using super::readInt64; + using super::writeUint16; + using super::writeUint32; + using super::writeUint64; + using super::writeInt16; + using super::writeInt32; + using super::writeInt64; }; } /* namespace detail */ @@ -598,39 +653,39 @@ typedef BigEndian NetworkEndian; class NativeEndian MOZ_FINAL : public detail::Endian { - private: - typedef detail::Endian super; - - public: - /* - * These functions are intended for cases where you have data in your - * native-endian format and you need the data to appear in the appropriate - * endianness for transmission, serialization, etc. - */ - using super::swapToLittleEndian; - using super::copyAndSwapToLittleEndian; - using super::swapToLittleEndianInPlace; - using super::swapToBigEndian; - using super::copyAndSwapToBigEndian; - using super::swapToBigEndianInPlace; - using super::swapToNetworkOrder; - using super::copyAndSwapToNetworkOrder; - using super::swapToNetworkOrderInPlace; - - /* - * These functions are intended for cases where you have data in the - * given endianness (e.g. reading from disk or a file-format) and you - * need the data to appear in native-endian format for processing. - */ - using super::swapFromLittleEndian; - using super::copyAndSwapFromLittleEndian; - using super::swapFromLittleEndianInPlace; - using super::swapFromBigEndian; - using super::copyAndSwapFromBigEndian; - using super::swapFromBigEndianInPlace; - using super::swapFromNetworkOrder; - using super::copyAndSwapFromNetworkOrder; - using super::swapFromNetworkOrderInPlace; +private: + typedef detail::Endian super; + +public: + /* + * These functions are intended for cases where you have data in your + * native-endian format and you need the data to appear in the appropriate + * endianness for transmission, serialization, etc. + */ + using super::swapToLittleEndian; + using super::copyAndSwapToLittleEndian; + using super::swapToLittleEndianInPlace; + using super::swapToBigEndian; + using super::copyAndSwapToBigEndian; + using super::swapToBigEndianInPlace; + using super::swapToNetworkOrder; + using super::copyAndSwapToNetworkOrder; + using super::swapToNetworkOrderInPlace; + + /* + * These functions are intended for cases where you have data in the + * given endianness (e.g. reading from disk or a file-format) and you + * need the data to appear in native-endian format for processing. + */ + using super::swapFromLittleEndian; + using super::copyAndSwapFromLittleEndian; + using super::swapFromLittleEndianInPlace; + using super::swapFromBigEndian; + using super::copyAndSwapFromBigEndian; + using super::swapFromBigEndianInPlace; + using super::swapFromNetworkOrder; + using super::copyAndSwapFromNetworkOrder; + using super::swapFromNetworkOrderInPlace; }; #undef MOZ_NATIVE_ENDIANNESS diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/EnumSet.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/EnumSet.h index 95c5608cf4..8c78b2b442 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/EnumSet.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/EnumSet.h @@ -10,6 +10,7 @@ #define mozilla_EnumSet_h #include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" #include @@ -23,153 +24,181 @@ namespace mozilla { template class EnumSet { - public: - EnumSet() - : mBitField(0) - { } - - EnumSet(T aEnum) - : mBitField(aEnum) - { } - - EnumSet(T aEnum1, T aEnum2) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2)) - { } - - EnumSet(T aEnum1, T aEnum2, T aEnum3) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2) | - bitFor(aEnum3)) - { } - - EnumSet(T aEnum1, T aEnum2, T aEnum3, T aEnum4) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2) | - bitFor(aEnum3) | - bitFor(aEnum4)) - { } - - EnumSet(const EnumSet& aEnumSet) - : mBitField(aEnumSet.mBitField) - { } - - /** - * Add an element - */ - void operator+=(T aEnum) { - mBitField |= bitFor(aEnum); - } - - /** - * Add an element - */ - EnumSet operator+(T aEnum) const { - EnumSet result(*this); - result += aEnum; - return result; - } - - /** - * Union - */ - void operator+=(const EnumSet aEnumSet) { - mBitField |= aEnumSet.mBitField; - } - - /** - * Union - */ - EnumSet operator+(const EnumSet aEnumSet) const { - EnumSet result(*this); - result += aEnumSet; - return result; - } - - /** - * Remove an element - */ - void operator-=(T aEnum) { - mBitField &= ~(bitFor(aEnum)); - } - - /** - * Remove an element - */ - EnumSet operator-(T aEnum) const { - EnumSet result(*this); - result -= aEnum; - return result; - } - - /** - * Remove a set of elements - */ - void operator-=(const EnumSet aEnumSet) { - mBitField &= ~(aEnumSet.mBitField); - } - - /** - * Remove a set of elements - */ - EnumSet operator-(const EnumSet aEnumSet) const { - EnumSet result(*this); - result -= aEnumSet; - return result; - } - - /** - * Intersection - */ - void operator&=(const EnumSet aEnumSet) { - mBitField &= aEnumSet.mBitField; - } - - /** - * Intersection - */ - EnumSet operator&(const EnumSet aEnumSet) const { - EnumSet result(*this); - result &= aEnumSet; - return result; - } - - /** - * Equality - */ - - bool operator==(const EnumSet aEnumSet) const { - return mBitField == aEnumSet.mBitField; - } - - /** - * Test is an element is contained in the set - */ - bool contains(T aEnum) const { - return mBitField & bitFor(aEnum); - } - - /** - * Return the number of elements in the set - */ - - uint8_t size() { - uint8_t count = 0; - for (uint32_t bitField = mBitField; bitField; bitField >>= 1) { - if (bitField & 1) - count++; +public: + EnumSet() + : mBitField(0) + { } + + MOZ_IMPLICIT EnumSet(T aEnum) + : mBitField(bitFor(aEnum)) + { } + + EnumSet(T aEnum1, T aEnum2) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3, T aEnum4) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3) | + bitFor(aEnum4)) + { } + + EnumSet(const EnumSet& aEnumSet) + : mBitField(aEnumSet.mBitField) + { } + + /** + * Add an element + */ + void operator+=(T aEnum) + { + mBitField |= bitFor(aEnum); + } + + /** + * Add an element + */ + EnumSet operator+(T aEnum) const + { + EnumSet result(*this); + result += aEnum; + return result; + } + + /** + * Union + */ + void operator+=(const EnumSet aEnumSet) + { + mBitField |= aEnumSet.mBitField; + } + + /** + * Union + */ + EnumSet operator+(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result += aEnumSet; + return result; + } + + /** + * Remove an element + */ + void operator-=(T aEnum) + { + mBitField &= ~(bitFor(aEnum)); + } + + /** + * Remove an element + */ + EnumSet operator-(T aEnum) const + { + EnumSet result(*this); + result -= aEnum; + return result; + } + + /** + * Remove a set of elements + */ + void operator-=(const EnumSet aEnumSet) + { + mBitField &= ~(aEnumSet.mBitField); + } + + /** + * Remove a set of elements + */ + EnumSet operator-(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result -= aEnumSet; + return result; + } + + /** + * Intersection + */ + void operator&=(const EnumSet aEnumSet) + { + mBitField &= aEnumSet.mBitField; + } + + /** + * Intersection + */ + EnumSet operator&(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result &= aEnumSet; + return result; + } + + /** + * Equality + */ + bool operator==(const EnumSet aEnumSet) const + { + return mBitField == aEnumSet.mBitField; + } + + /** + * Test is an element is contained in the set. + */ + bool contains(T aEnum) const + { + return mBitField & bitFor(aEnum); + } + + /** + * Return the number of elements in the set. + */ + uint8_t size() + { + uint8_t count = 0; + for (uint32_t bitField = mBitField; bitField; bitField >>= 1) { + if (bitField & 1) { + count++; } - return count; } - - private: - static uint32_t bitFor(T aEnum) { - uint32_t bitNumber(aEnum); - MOZ_ASSERT(bitNumber < 32); - return 1U << bitNumber; - } - - uint32_t mBitField; + return count; + } + + bool isEmpty() const + { + return mBitField == 0; + } + + uint32_t serialize() const + { + return mBitField; + } + + void deserialize(uint32_t aValue) + { + mBitField = aValue; + } + +private: + static uint32_t bitFor(T aEnum) + { + uint32_t bitNumber = (uint32_t)aEnum; + MOZ_ASSERT(bitNumber < 32); + return 1U << bitNumber; + } + + uint32_t mBitField; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/EnumeratedArray.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/EnumeratedArray.h new file mode 100644 index 0000000000..7e8e89275f --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/EnumeratedArray.h @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* EnumeratedArray is like Array, but indexed by a typed enum. */ + +#ifndef mozilla_EnumeratedArray_h +#define mozilla_EnumeratedArray_h + +#include "mozilla/Array.h" +#include "mozilla/TypedEnum.h" + +namespace mozilla { + +/** + * EnumeratedArray is a fixed-size array container for use when an + * array is indexed by a specific enum class, as currently implemented + * by MOZ_BEGIN_ENUM_CLASS. + * + * This provides type safety by guarding at compile time against accidentally + * indexing such arrays with unrelated values. This also removes the need + * for manual casting when using a typed enum value to index arrays. + * + * Aside from the typing of indices, EnumeratedArray is similar to Array. + * + * Example: + * + * MOZ_BEGIN_ENUM_CLASS(AnimalSpecies) + * Cow, + * Sheep, + * Count + * MOZ_END_ENUM_CLASS(AnimalSpecies) + * + * EnumeratedArray headCount; + * + * headCount[AnimalSpecies::Cow] = 17; + * headCount[AnimalSpecies::Sheep] = 30; + * + */ +template +class EnumeratedArray +{ +public: + static const size_t kSize = size_t(SizeAsEnumValue); + +private: + Array mArray; + +public: + EnumeratedArray() {} + + explicit EnumeratedArray(const EnumeratedArray& aOther) + { + for (size_t i = 0; i < kSize; i++) { + mArray[i] = aOther.mArray[i]; + } + } + + ValueType& operator[](IndexType aIndex) + { + return mArray[size_t(aIndex)]; + } + + const ValueType& operator[](IndexType aIndex) const + { + return mArray[size_t(aIndex)]; + } +}; + +} // namespace mozilla + +#endif // mozilla_EnumeratedArray_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/FloatingPoint.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/FloatingPoint.h index 7d6b28b413..0ed567832b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/FloatingPoint.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/FloatingPoint.h @@ -12,6 +12,7 @@ #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/Casting.h" +#include "mozilla/MathAlgorithms.h" #include "mozilla/Types.h" #include @@ -33,211 +34,274 @@ namespace mozilla { * compiler bustage, particularly PGO-specific bustage. */ -/* - * These implementations all assume |double| is a 64-bit double format number - * type, compatible with the IEEE-754 standard. C/C++ don't require this to be - * the case. But we required this in implementations of these algorithms that - * preceded this header, so we shouldn't break anything if we continue doing so. - */ -static_assert(sizeof(double) == sizeof(uint64_t), "double must be 64 bits"); +struct FloatTypeTraits +{ + typedef uint32_t Bits; -const unsigned DoubleExponentBias = 1023; -const unsigned DoubleExponentShift = 52; + static const unsigned kExponentBias = 127; + static const unsigned kExponentShift = 23; -const uint64_t DoubleSignBit = 0x8000000000000000ULL; -const uint64_t DoubleExponentBits = 0x7ff0000000000000ULL; -const uint64_t DoubleSignificandBits = 0x000fffffffffffffULL; + static const Bits kSignBit = 0x80000000UL; + static const Bits kExponentBits = 0x7F800000UL; + static const Bits kSignificandBits = 0x007FFFFFUL; +}; + +struct DoubleTypeTraits +{ + typedef uint64_t Bits; -static_assert((DoubleSignBit & DoubleExponentBits) == 0, - "sign bit doesn't overlap exponent bits"); -static_assert((DoubleSignBit & DoubleSignificandBits) == 0, - "sign bit doesn't overlap significand bits"); -static_assert((DoubleExponentBits & DoubleSignificandBits) == 0, - "exponent bits don't overlap significand bits"); + static const unsigned kExponentBias = 1023; + static const unsigned kExponentShift = 52; -static_assert((DoubleSignBit | DoubleExponentBits | DoubleSignificandBits) == - ~uint64_t(0), - "all bits accounted for"); + static const Bits kSignBit = 0x8000000000000000ULL; + static const Bits kExponentBits = 0x7ff0000000000000ULL; + static const Bits kSignificandBits = 0x000fffffffffffffULL; +}; + +template struct SelectTrait; +template<> struct SelectTrait : public FloatTypeTraits {}; +template<> struct SelectTrait : public DoubleTypeTraits {}; /* - * Ditto for |float| that must be a 32-bit double format number type, compatible - * with the IEEE-754 standard. + * This struct contains details regarding the encoding of floating-point + * numbers that can be useful for direct bit manipulation. As of now, the + * template parameter has to be float or double. + * + * The nested typedef |Bits| is the unsigned integral type with the same size + * as T: uint32_t for float and uint64_t for double (static assertions + * double-check these assumptions). + * + * kExponentBias is the offset that is subtracted from the exponent when + * computing the value, i.e. one plus the opposite of the mininum possible + * exponent. + * kExponentShift is the shift that one needs to apply to retrieve the + * exponent component of the value. + * + * kSignBit contains a bits mask. Bit-and-ing with this mask will result in + * obtaining the sign bit. + * kExponentBits contains the mask needed for obtaining the exponent bits and + * kSignificandBits contains the mask needed for obtaining the significand + * bits. + * + * Full details of how floating point number formats are encoded are beyond + * the scope of this comment. For more information, see + * http://en.wikipedia.org/wiki/IEEE_floating_point + * http://en.wikipedia.org/wiki/Floating_point#IEEE_754:_floating_point_in_modern_computers */ -static_assert(sizeof(float) == sizeof(uint32_t), "float must be 32bits"); - -const unsigned FloatExponentBias = 127; -const unsigned FloatExponentShift = 23; +template +struct FloatingPoint : public SelectTrait +{ + typedef SelectTrait Base; + typedef typename Base::Bits Bits; -const uint32_t FloatSignBit = 0x80000000UL; -const uint32_t FloatExponentBits = 0x7F800000UL; -const uint32_t FloatSignificandBits = 0x007FFFFFUL; + static_assert((Base::kSignBit & Base::kExponentBits) == 0, + "sign bit shouldn't overlap exponent bits"); + static_assert((Base::kSignBit & Base::kSignificandBits) == 0, + "sign bit shouldn't overlap significand bits"); + static_assert((Base::kExponentBits & Base::kSignificandBits) == 0, + "exponent bits shouldn't overlap significand bits"); -static_assert((FloatSignBit & FloatExponentBits) == 0, - "sign bit doesn't overlap exponent bits"); -static_assert((FloatSignBit & FloatSignificandBits) == 0, - "sign bit doesn't overlap significand bits"); -static_assert((FloatExponentBits & FloatSignificandBits) == 0, - "exponent bits don't overlap significand bits"); + static_assert((Base::kSignBit | Base::kExponentBits | Base::kSignificandBits) == + ~Bits(0), + "all bits accounted for"); -static_assert((FloatSignBit | FloatExponentBits | FloatSignificandBits) == - ~uint32_t(0), - "all bits accounted for"); + /* + * These implementations assume float/double are 32/64-bit single/double + * format number types compatible with the IEEE-754 standard. C++ don't + * require this to be the case. But we required this in implementations of + * these algorithms that preceded this header, so we shouldn't break anything + * if we keep doing so. + */ + static_assert(sizeof(T) == sizeof(Bits), "Bits must be same size as T"); +}; /** Determines whether a double is NaN. */ +template static MOZ_ALWAYS_INLINE bool -IsNaN(double d) +IsNaN(T aValue) { /* - * A double is NaN if all exponent bits are 1 and the significand contains at - * least one non-zero bit. + * A float/double is NaN if all exponent bits are 1 and the significand + * contains at least one non-zero bit. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleExponentBits) == DoubleExponentBits && - (bits & DoubleSignificandBits) != 0; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) == Traits::kExponentBits && + (bits & Traits::kSignificandBits) != 0; } -/** Determines whether a double is +Infinity or -Infinity. */ +/** Determines whether a float/double is +Infinity or -Infinity. */ +template static MOZ_ALWAYS_INLINE bool -IsInfinite(double d) +IsInfinite(T aValue) { /* Infinities have all exponent bits set to 1 and an all-0 significand. */ - uint64_t bits = BitwiseCast(d); - return (bits & ~DoubleSignBit) == DoubleExponentBits; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & ~Traits::kSignBit) == Traits::kExponentBits; } -/** Determines whether a double is not NaN or infinite. */ +/** Determines whether a float/double is not NaN or infinite. */ +template static MOZ_ALWAYS_INLINE bool -IsFinite(double d) +IsFinite(T aValue) { /* - * NaN and Infinities are the only non-finite doubles, and both have all - * exponent bits set to 1. + * NaN and Infinities are the only non-finite floats/doubles, and both have + * all exponent bits set to 1. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleExponentBits) != DoubleExponentBits; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) != Traits::kExponentBits; } /** - * Determines whether a double is negative. It is an error to call this method - * on a double which is NaN. + * Determines whether a float/double is negative. It is an error to call this + * method on a float/double which is NaN. */ +template static MOZ_ALWAYS_INLINE bool -IsNegative(double d) +IsNegative(T aValue) { - MOZ_ASSERT(!IsNaN(d), "NaN does not have a sign"); + MOZ_ASSERT(!IsNaN(aValue), "NaN does not have a sign"); /* The sign bit is set if the double is negative. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleSignBit) != 0; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kSignBit) != 0; } -/** Determines whether a double represents -0. */ +/** Determines whether a float/double represents -0. */ +template static MOZ_ALWAYS_INLINE bool -IsNegativeZero(double d) +IsNegativeZero(T aValue) { - /* Only the sign bit is set if the double is -0. */ - uint64_t bits = BitwiseCast(d); - return bits == DoubleSignBit; + /* Only the sign bit is set if the value is -0. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return bits == Traits::kSignBit; } /** - * Returns the exponent portion of the double. + * Returns the exponent portion of the float/double. * * Zero is not special-cased, so ExponentComponent(0.0) is - * -int_fast16_t(DoubleExponentBias). + * -int_fast16_t(Traits::kExponentBias). */ +template static MOZ_ALWAYS_INLINE int_fast16_t -ExponentComponent(double d) +ExponentComponent(T aValue) { /* - * The exponent component of a double is an unsigned number, biased from its - * actual value. Subtract the bias to retrieve the actual exponent. + * The exponent component of a float/double is an unsigned number, biased + * from its actual value. Subtract the bias to retrieve the actual exponent. */ - uint64_t bits = BitwiseCast(d); - return int_fast16_t((bits & DoubleExponentBits) >> DoubleExponentShift) - - int_fast16_t(DoubleExponentBias); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return int_fast16_t((bits & Traits::kExponentBits) >> Traits::kExponentShift) - + int_fast16_t(Traits::kExponentBias); } /** Returns +Infinity. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T PositiveInfinity() { /* * Positive infinity has all exponent bits set, sign bit set to 0, and no * significand. */ - return BitwiseCast(DoubleExponentBits); + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kExponentBits); } /** Returns -Infinity. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T NegativeInfinity() { /* * Negative infinity has all exponent bits set, sign bit set to 1, and no * significand. */ - return BitwiseCast(DoubleSignBit | DoubleExponentBits); + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kSignBit | Traits::kExponentBits); } + /** Constructs a NaN value with the specified sign bit and significand bits. */ -static MOZ_ALWAYS_INLINE double -SpecificNaN(int signbit, uint64_t significand) +template +static MOZ_ALWAYS_INLINE T +SpecificNaN(int signbit, typename FloatingPoint::Bits significand) { + typedef FloatingPoint Traits; MOZ_ASSERT(signbit == 0 || signbit == 1); - MOZ_ASSERT((significand & ~DoubleSignificandBits) == 0); - MOZ_ASSERT(significand & DoubleSignificandBits); - - double d = BitwiseCast((signbit ? DoubleSignBit : 0) | - DoubleExponentBits | - significand); - MOZ_ASSERT(IsNaN(d)); - return d; + MOZ_ASSERT((significand & ~Traits::kSignificandBits) == 0); + MOZ_ASSERT(significand & Traits::kSignificandBits); + + T t = BitwiseCast((signbit ? Traits::kSignBit : 0) | + Traits::kExponentBits | + significand); + MOZ_ASSERT(IsNaN(t)); + return t; } -/** Computes the smallest non-zero positive double value. */ -static MOZ_ALWAYS_INLINE double -MinDoubleValue() +/** Computes the smallest non-zero positive float/double value. */ +template +static MOZ_ALWAYS_INLINE T +MinNumberValue() { - return BitwiseCast(uint64_t(1)); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + return BitwiseCast(Bits(1)); } /** - * If d is equal to some int32_t value, set *i to that value and return true; - * otherwise return false. + * If aValue is equal to some int32_t value, set *aInt32 to that value and + * return true; otherwise return false. * * Note that negative zero is "equal" to zero here. To test whether a value can - * be losslessly converted to int32_t and back, use DoubleIsInt32 instead. + * be losslessly converted to int32_t and back, use NumberIsInt32 instead. */ +template static MOZ_ALWAYS_INLINE bool -DoubleEqualsInt32(double d, int32_t* i) +NumberEqualsInt32(T aValue, int32_t* aInt32) { /* - * XXX Casting a double that doesn't truncate to int32_t, to int32_t, induces - * undefined behavior. We should definitely fix this (bug 744965), but as - * apparently it "works" in practice, it's not a pressing concern now. + * XXX Casting a floating-point value that doesn't truncate to int32_t, to + * int32_t, induces undefined behavior. We should definitely fix this + * (bug 744965), but as apparently it "works" in practice, it's not a + * pressing concern now. */ - return d == (*i = int32_t(d)); + return aValue == (*aInt32 = int32_t(aValue)); } /** * If d can be converted to int32_t and back to an identical double value, - * set *i to that value and return true; otherwise return false. + * set *aInt32 to that value and return true; otherwise return false. * - * The difference between this and DoubleEqualsInt32 is that this method returns + * The difference between this and NumberEqualsInt32 is that this method returns * false for negative zero. */ +template static MOZ_ALWAYS_INLINE bool -DoubleIsInt32(double d, int32_t* i) +NumberIsInt32(T aValue, int32_t* aInt32) { - return !IsNegativeZero(d) && DoubleEqualsInt32(d, i); + return !IsNegativeZero(aValue) && NumberEqualsInt32(aValue, aInt32); } /** * Computes a NaN value. Do not use this method if you depend upon a particular * NaN value being returned. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T UnspecifiedNaN() { /* @@ -246,7 +310,8 @@ UnspecifiedNaN() * this value can be represented in a 32-bit signed immediate field, allowing * it to be stored to memory in a single instruction). */ - return SpecificNaN(1, 0xfffffffffffffULL); + typedef FloatingPoint Traits; + return SpecificNaN(1, Traits::kSignificandBits); } /** @@ -254,40 +319,81 @@ UnspecifiedNaN() * any NaN value to any other NaN value. (The normal equality operators equate * -0 with +0, and they equate NaN to no other value.) */ +template static inline bool -DoublesAreIdentical(double d1, double d2) +NumbersAreIdentical(T aValue1, T aValue2) { - if (IsNaN(d1)) - return IsNaN(d2); - return BitwiseCast(d1) == BitwiseCast(d2); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + if (IsNaN(aValue1)) { + return IsNaN(aValue2); + } + return BitwiseCast(aValue1) == BitwiseCast(aValue2); } -/** Determines whether a float is NaN. */ +namespace detail { + +template +struct FuzzyEqualsEpsilon; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-5 that is exactly representable in a float. + static float value() { return 1.0f / (1 << 17); } +}; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-12 that is exactly representable in a double. + static double value() { return 1.0 / (1LL << 40); } +}; + +} // namespace detail + +/** + * Compare two floating point values for equality, modulo rounding error. That + * is, the two values are considered equal if they are both not NaN and if they + * are less than or equal to aEpsilon apart. The default value of aEpsilon is + * near 1e-5. + * + * For most scenarios you will want to use FuzzyEqualsMultiplicative instead, + * as it is more reasonable over the entire range of floating point numbers. + * This additive version should only be used if you know the range of the + * numbers you are dealing with is bounded and stays around the same order of + * magnitude. + */ +template static MOZ_ALWAYS_INLINE bool -IsFloatNaN(float f) +FuzzyEqualsAdditive(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) { - /* - * A float is NaN if all exponent bits are 1 and the significand contains at - * least one non-zero bit. - */ - uint32_t bits = BitwiseCast(f); - return (bits & FloatExponentBits) == FloatExponentBits && - (bits & FloatSignificandBits) != 0; + static_assert(IsFloatingPoint::value, "floating point type required"); + return Abs(aValue1 - aValue2) <= aEpsilon; } -/** Constructs a NaN value with the specified sign bit and significand bits. */ -static MOZ_ALWAYS_INLINE float -SpecificFloatNaN(int signbit, uint32_t significand) +/** + * Compare two floating point values for equality, allowing for rounding error + * relative to the magnitude of the values. That is, the two values are + * considered equal if they are both not NaN and they are less than or equal to + * some aEpsilon apart, where the aEpsilon is scaled by the smaller of the two + * argument values. + * + * In most cases you will want to use this rather than FuzzyEqualsAdditive, as + * this function effectively masks out differences in the bottom few bits of + * the floating point numbers being compared, regardless of what order of + * magnitude those numbers are at. + */ +template +static MOZ_ALWAYS_INLINE bool +FuzzyEqualsMultiplicative(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) { - MOZ_ASSERT(signbit == 0 || signbit == 1); - MOZ_ASSERT((significand & ~FloatSignificandBits) == 0); - MOZ_ASSERT(significand & FloatSignificandBits); - - float f = BitwiseCast((signbit ? FloatSignBit : 0) | - FloatExponentBits | - significand); - MOZ_ASSERT(IsFloatNaN(f)); - return f; + static_assert(IsFloatingPoint::value, "floating point type required"); + // can't use std::min because of bug 965340 + T smaller = Abs(aValue1) < Abs(aValue2) ? Abs(aValue1) : Abs(aValue2); + return Abs(aValue1 - aValue2) <= aEpsilon * smaller; } /** @@ -300,7 +406,7 @@ SpecificFloatNaN(int signbit, uint32_t significand) */ MOZ_WARN_UNUSED_RESULT extern MFBT_API bool -IsFloat32Representable(double x); +IsFloat32Representable(double aFloat32); } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/GuardObjects.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/GuardObjects.h index aeae7dcbc0..2cd950f314 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/GuardObjects.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/GuardObjects.h @@ -68,48 +68,49 @@ namespace detail { * For more details, and examples of using these macros, see * https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla */ -class MOZ_EXPORT GuardObjectNotifier +class GuardObjectNotifier { - private: - bool* statementDone; +private: + bool* mStatementDone; - public: - GuardObjectNotifier() : statementDone(nullptr) { } +public: + GuardObjectNotifier() : mStatementDone(nullptr) { } - ~GuardObjectNotifier() { - *statementDone = true; - } + ~GuardObjectNotifier() { *mStatementDone = true; } - void setStatementDone(bool* statementIsDone) { - statementDone = statementIsDone; - } + void setStatementDone(bool* aStatementIsDone) + { + mStatementDone = aStatementIsDone; + } }; -class MOZ_EXPORT GuardObjectNotificationReceiver +class GuardObjectNotificationReceiver { - private: - bool statementDone; - - public: - GuardObjectNotificationReceiver() : statementDone(false) { } - - ~GuardObjectNotificationReceiver() { - /* - * Assert that the guard object was not used as a temporary. (Note that - * this assert might also fire if init is not called because the guard - * object's implementation is not using the above macros correctly.) - */ - MOZ_ASSERT(statementDone); - } - - void init(const GuardObjectNotifier& constNotifier) { - /* - * constNotifier is passed as a const reference so that we can pass a - * temporary, but we really intend it as non-const. - */ - GuardObjectNotifier& notifier = const_cast(constNotifier); - notifier.setStatementDone(&statementDone); - } +private: + bool mStatementDone; + +public: + GuardObjectNotificationReceiver() : mStatementDone(false) { } + + ~GuardObjectNotificationReceiver() { + /* + * Assert that the guard object was not used as a temporary. (Note that + * this assert might also fire if init is not called because the guard + * object's implementation is not using the above macros correctly.) + */ + MOZ_ASSERT(mStatementDone); + } + + void init(const GuardObjectNotifier& aConstNotifier) + { + /* + * aConstNotifier is passed as a const reference so that we can pass a + * temporary, but we really intend it as non-const. + */ + GuardObjectNotifier& notifier = + const_cast(aConstNotifier); + notifier.setStatementDone(&mStatementDone); + } }; } /* namespace detail */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/HashFunctions.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/HashFunctions.h index b228955ce5..8b2c172bd1 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/HashFunctions.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/HashFunctions.h @@ -27,16 +27,17 @@ * * class ComplexObject * { - * char* str; - * uint32_t uint1, uint2; - * void (*callbackFn)(); + * char* mStr; + * uint32_t mUint1, mUint2; + * void (*mCallbackFn)(); * - * public: - * uint32_t hash() { - * uint32_t hash = HashString(str); - * hash = AddToHash(hash, uint1, uint2); - * return AddToHash(hash, callbackFn); - * } + * public: + * uint32_t hash() + * { + * uint32_t hash = HashString(mStr); + * hash = AddToHash(hash, mUint1, mUint2); + * return AddToHash(hash, mCallbackFn); + * } * }; * * If you want to hash an nsAString or nsACString, use the HashString functions @@ -59,19 +60,19 @@ namespace mozilla { /** * The golden ratio as a 32-bit fixed-point value. */ -static const uint32_t GoldenRatioU32 = 0x9E3779B9U; +static const uint32_t kGoldenRatioU32 = 0x9E3779B9U; inline uint32_t -RotateBitsLeft32(uint32_t value, uint8_t bits) +RotateBitsLeft32(uint32_t aValue, uint8_t aBits) { - MOZ_ASSERT(bits < 32); - return (value << bits) | (value >> (32 - bits)); + MOZ_ASSERT(aBits < 32); + return (aValue << aBits) | (aValue >> (32 - aBits)); } namespace detail { inline uint32_t -AddU32ToHash(uint32_t hash, uint32_t value) +AddU32ToHash(uint32_t aHash, uint32_t aValue) { /* * This is the meat of all our hash routines. This hash function is not @@ -91,12 +92,12 @@ AddU32ToHash(uint32_t hash, uint32_t value) * preferable so our hash explores the whole universe of possible rotations. * * Finally, we multiply by the golden ratio *after* xor'ing, not before. - * Otherwise, if |hash| is 0 (as it often is for the beginning of a message), - * the expression + * Otherwise, if |aHash| is 0 (as it often is for the beginning of a + * message), the expression * - * (GoldenRatioU32 * RotateBitsLeft(hash, 5)) |xor| value + * (kGoldenRatioU32 * RotateBitsLeft(aHash, 5)) |xor| aValue * - * evaluates to |value|. + * evaluates to |aValue|. * * (Number-theoretic aside: Because any odd number |m| is relatively prime to * our modulus (2^32), the list @@ -112,7 +113,7 @@ AddU32ToHash(uint32_t hash, uint32_t value) * multiplicative effect. Our golden ratio constant has order 2^29, which is * more than enough for our purposes.) */ - return GoldenRatioU32 * (RotateBitsLeft32(hash, 5) ^ value); + return kGoldenRatioU32 * (RotateBitsLeft32(aHash, 5) ^ aValue); } /** @@ -120,29 +121,29 @@ AddU32ToHash(uint32_t hash, uint32_t value) */ template inline uint32_t -AddUintptrToHash(uint32_t hash, uintptr_t value); +AddUintptrToHash(uint32_t aHash, uintptr_t aValue); template<> inline uint32_t -AddUintptrToHash<4>(uint32_t hash, uintptr_t value) +AddUintptrToHash<4>(uint32_t aHash, uintptr_t aValue) { - return AddU32ToHash(hash, static_cast(value)); + return AddU32ToHash(aHash, static_cast(aValue)); } template<> inline uint32_t -AddUintptrToHash<8>(uint32_t hash, uintptr_t value) +AddUintptrToHash<8>(uint32_t aHash, uintptr_t aValue) { /* * The static cast to uint64_t below is necessary because this function * sometimes gets compiled on 32-bit platforms (yes, even though it's a * template and we never call this particular override in a 32-bit build). If - * we do value >> 32 on a 32-bit machine, we're shifting a 32-bit uintptr_t + * we do aValue >> 32 on a 32-bit machine, we're shifting a 32-bit uintptr_t * right 32 bits, and the compiler throws an error. */ - uint32_t v1 = static_cast(value); - uint32_t v2 = static_cast(static_cast(value) >> 32); - return AddU32ToHash(AddU32ToHash(hash, v1), v2); + uint32_t v1 = static_cast(aValue); + uint32_t v2 = static_cast(static_cast(aValue) >> 32); + return AddU32ToHash(AddU32ToHash(aHash, v1), v2); } } /* namespace detail */ @@ -155,71 +156,63 @@ AddUintptrToHash<8>(uint32_t hash, uintptr_t value) * convert to uint32_t, data pointers, and function pointers. */ template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, A a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A aA) { /* * Try to convert |A| to uint32_t implicitly. If this works, great. If not, * we'll error out. */ - return detail::AddU32ToHash(hash, a); + return detail::AddU32ToHash(aHash, aA); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, A* a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A* aA) { /* * You might think this function should just take a void*. But then we'd only * catch data pointers and couldn't handle function pointers. */ - static_assert(sizeof(a) == sizeof(uintptr_t), - "Strange pointer!"); + static_assert(sizeof(aA) == sizeof(uintptr_t), "Strange pointer!"); - return detail::AddUintptrToHash(hash, uintptr_t(a)); + return detail::AddUintptrToHash(aHash, uintptr_t(aA)); } template<> -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, uintptr_t a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, uintptr_t aA) { - return detail::AddUintptrToHash(hash, a); + return detail::AddUintptrToHash(aHash, aA); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB) { - return AddToHash(AddToHash(hash, a), b); + return AddToHash(AddToHash(aHash, aA), aB); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC) { - return AddToHash(AddToHash(hash, a, b), c); + return AddToHash(AddToHash(aHash, aA, aB), aC); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c, D d) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD) { - return AddToHash(AddToHash(hash, a, b, c), d); + return AddToHash(AddToHash(aHash, aA, aB, aC), aD); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c, D d, E e) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD, E aE) { - return AddToHash(AddToHash(hash, a, b, c, d), e); + return AddToHash(AddToHash(aHash, aA, aB, aC, aD), aE); } /** @@ -230,64 +223,61 @@ AddToHash(uint32_t hash, A a, B b, C c, D d, E e) * that x has already been hashed. */ template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA) { - return AddToHash(0, a); + return AddToHash(0, aA); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB) { - return AddToHash(0, a, b); + return AddToHash(0, aA, aB); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC) { - return AddToHash(0, a, b, c); + return AddToHash(0, aA, aB, aC); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c, D d) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD) { - return AddToHash(0, a, b, c, d); + return AddToHash(0, aA, aB, aC, aD); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c, D d, E e) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD, E aE) { - return AddToHash(0, a, b, c, d, e); + return AddToHash(0, aA, aB, aC, aD, aE); } namespace detail { template uint32_t -HashUntilZero(const T* str) +HashUntilZero(const T* aStr) { uint32_t hash = 0; - for (T c; (c = *str); str++) + for (T c; (c = *aStr); aStr++) { hash = AddToHash(hash, c); + } return hash; } template uint32_t -HashKnownLength(const T* str, size_t length) +HashKnownLength(const T* aStr, size_t aLength) { uint32_t hash = 0; - for (size_t i = 0; i < length; i++) - hash = AddToHash(hash, str[i]); + for (size_t i = 0; i < aLength; i++) { + hash = AddToHash(hash, aStr[i]); + } return hash; } @@ -299,67 +289,66 @@ HashKnownLength(const T* str, size_t length) * If you have the string's length, you might as well call the overload which * includes the length. It may be marginally faster. */ -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } MOZ_WARN_UNUSED_RESULT inline uint32_t -HashString(const uint16_t* str) +HashString(const unsigned char* aStr, size_t aLength) { - return detail::HashUntilZero(str); + return detail::HashKnownLength(aStr, aLength); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const uint16_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr) { - return detail::HashKnownLength(str, length); + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); } #ifdef MOZ_CHAR16_IS_NOT_WCHAR -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char16_t* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char16_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } #endif /* - * On Windows, wchar_t (PRUnichar) is not the same as uint16_t, even though it's + * On Windows, wchar_t (char16_t) is not the same as uint16_t, even though it's * the same width! */ #ifdef WIN32 -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const wchar_t* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const wchar_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } #endif @@ -369,9 +358,8 @@ HashString(const wchar_t* str, size_t length) * This hash walks word-by-word, rather than byte-by-byte, so you won't get the * same result out of HashBytes as you would out of HashString. */ -MOZ_WARN_UNUSED_RESULT -extern MFBT_API uint32_t -HashBytes(const void* bytes, size_t length); +MOZ_WARN_UNUSED_RESULT extern MFBT_API uint32_t +HashBytes(const void* bytes, size_t aLength); } /* namespace mozilla */ #endif /* __cplusplus */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/IntegerPrintfMacros.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/IntegerPrintfMacros.h index 1ae60d618e..ff2415a86f 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/IntegerPrintfMacros.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/IntegerPrintfMacros.h @@ -1,7 +1,8 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* Implements the C99 interface, minus the SCN* format macros. */ @@ -37,4 +38,25 @@ # include #endif +/* + * Fix up Android's broken [u]intptr_t inttype macros. Android's PRI*PTR + * macros are defined as "ld", but sizeof(long) is 8 and sizeof(intptr_t) + * is 4 on 32-bit Android. TestTypeTraits.cpp asserts that these new macro + * definitions match the actual type sizes seen at compile time. + */ +#if defined(ANDROID) && !defined(__LP64__) +# undef PRIdPTR /* intptr_t */ +# define PRIdPTR "d" /* intptr_t */ +# undef PRIiPTR /* intptr_t */ +# define PRIiPTR "i" /* intptr_t */ +# undef PRIoPTR /* uintptr_t */ +# define PRIoPTR "o" /* uintptr_t */ +# undef PRIuPTR /* uintptr_t */ +# define PRIuPTR "u" /* uintptr_t */ +# undef PRIxPTR /* uintptr_t */ +# define PRIxPTR "x" /* uintptr_t */ +# undef PRIXPTR /* uintptr_t */ +# define PRIXPTR "X" /* uintptr_t */ +#endif + #endif /* mozilla_IntegerPrintfMacros_h_ */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/IntegerTypeTraits.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/IntegerTypeTraits.h new file mode 100644 index 0000000000..9414451f91 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/IntegerTypeTraits.h @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Helpers to manipulate integer types that don't fit in TypeTraits.h */ + +#ifndef mozilla_IntegerTypeTraits_h +#define mozilla_IntegerTypeTraits_h + +#include "mozilla/TypeTraits.h" +#include + +namespace mozilla { + +namespace detail { + +/** + * StdintTypeForSizeAndSignedness returns the stdint integer type + * of given size (can be 1, 2, 4 or 8) and given signedness + * (false means unsigned, true means signed). + */ +template +struct StdintTypeForSizeAndSignedness; + +template<> +struct StdintTypeForSizeAndSignedness<1, true> +{ + typedef int8_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<1, false> +{ + typedef uint8_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<2, true> +{ + typedef int16_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<2, false> +{ + typedef uint16_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<4, true> +{ + typedef int32_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<4, false> +{ + typedef uint32_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<8, true> +{ + typedef int64_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<8, false> +{ + typedef uint64_t Type; +}; + +} // namespace detail + +template +struct UnsignedStdintTypeForSize + : detail::StdintTypeForSizeAndSignedness +{}; + +template +struct PositionOfSignBit +{ + static_assert(IsIntegral::value, + "PositionOfSignBit is only for integral types"); + // 8 here should be CHAR_BIT from limits.h, but the world has moved on. + static const size_t value = 8 * sizeof(IntegerType) - 1; +}; + +/** + * MinValue returns the minimum value of the given integer type as a + * compile-time constant, which std::numeric_limits::min() + * cannot do in c++98. + */ +template +struct MinValue +{ +private: + static_assert(IsIntegral::value, + "MinValue is only for integral types"); + + typedef typename MakeUnsigned::Type UnsignedIntegerType; + static const size_t PosOfSignBit = PositionOfSignBit::value; + +public: + // Bitwise ops may return a larger type, that's why we cast explicitly. + // In C++, left bit shifts on signed values is undefined by the standard + // unless the shifted value is representable. + // Notice that signed-to-unsigned conversions are always well-defined in + // the standard as the value congruent to 2**n, as expected. By contrast, + // unsigned-to-signed is only well-defined if the value is representable. + static const IntegerType value = + IsSigned::value + ? IntegerType(UnsignedIntegerType(1) << PosOfSignBit) + : IntegerType(0); +}; + +/** + * MaxValue returns the maximum value of the given integer type as a + * compile-time constant, which std::numeric_limits::max() + * cannot do in c++98. + */ +template +struct MaxValue +{ + static_assert(IsIntegral::value, + "MaxValue is only for integral types"); + + // Tricksy, but covered by the CheckedInt unit test. + // Relies on the type of MinValue::value + // being IntegerType. + static const IntegerType value = ~MinValue::value; +}; + +} // namespace mozilla + +#endif // mozilla_IntegerTypeTraits_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/LinkedList.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/LinkedList.h index 3aee7cde45..693c019f92 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/LinkedList.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/LinkedList.h @@ -23,32 +23,36 @@ * * class Observer : public LinkedListElement * { - * public: - * void observe(char* topic) { ... } + * public: + * void observe(char* aTopic) { ... } * }; * * class ObserverContainer * { - * private: - * LinkedList list; + * private: + * LinkedList list; * - * public: - * void addObserver(Observer* observer) { - * // Will assert if |observer| is part of another list. - * list.insertBack(observer); - * } + * public: + * void addObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is part of another list. + * list.insertBack(aObserver); + * } * - * void removeObserver(Observer* observer) { - * // Will assert if |observer| is not part of some list. - * observer.remove(); - * // Or, will assert if |observer| is not part of |list| specifically. - * // observer.removeFrom(list); - * } + * void removeObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is not part of some list. + * aObserver.remove(); + * // Or, will assert if |aObserver| is not part of |list| specifically. + * // aObserver.removeFrom(list); + * } * - * void notifyObservers(char* topic) { - * for (Observer* o = list.getFirst(); o != nullptr; o = o->getNext()) - * o->observe(topic); + * void notifyObservers(char* aTopic) + * { + * for (Observer* o = list.getFirst(); o != nullptr; o = o->getNext()) { + * o->observe(aTopic); * } + * } * }; * */ @@ -72,411 +76,407 @@ class LinkedList; template class LinkedListElement { - /* - * It's convenient that we return nullptr when getNext() or getPrevious() - * hits the end of the list, but doing so costs an extra word of storage in - * each linked list node (to keep track of whether |this| is the sentinel - * node) and a branch on this value in getNext/getPrevious. - * - * We could get rid of the extra word of storage by shoving the "is - * sentinel" bit into one of the pointers, although this would, of course, - * have performance implications of its own. - * - * But the goal here isn't to win an award for the fastest or slimmest - * linked list; rather, we want a *convenient* linked list. So we won't - * waste time guessing which micro-optimization strategy is best. - * - * - * Speaking of unnecessary work, it's worth addressing here why we wrote - * mozilla::LinkedList in the first place, instead of using stl::list. - * - * The key difference between mozilla::LinkedList and stl::list is that - * mozilla::LinkedList stores the prev/next pointers in the object itself, - * while stl::list stores the prev/next pointers in a list element which - * itself points to the object being stored. - * - * mozilla::LinkedList's approach makes it harder to store an object in more - * than one list. But the upside is that you can call next() / prev() / - * remove() directly on the object. With stl::list, you'd need to store a - * pointer to its iterator in the object in order to accomplish this. Not - * only would this waste space, but you'd have to remember to update that - * pointer every time you added or removed the object from a list. - * - * In-place, constant-time removal is a killer feature of doubly-linked - * lists, and supporting this painlessly was a key design criterion. - */ - - private: - LinkedListElement* next; - LinkedListElement* prev; - const bool isSentinel; - - public: - LinkedListElement() - : next(MOZ_THIS_IN_INITIALIZER_LIST()), - prev(MOZ_THIS_IN_INITIALIZER_LIST()), - isSentinel(false) - { } - - LinkedListElement(LinkedListElement&& other) - : isSentinel(other.isSentinel) - { - if (!other.isInList()) { - next = this; - prev = this; - return; - } - - MOZ_ASSERT(other.next->prev == &other); - MOZ_ASSERT(other.prev->next == &other); - - /* - * Initialize |this| with |other|'s prev/next pointers, and adjust those - * element to point to this one. - */ - next = other.next; - prev = other.prev; - - next->prev = this; - prev->next = this; - - /* - * Adjust |other| so it doesn't think it's in a list. This makes it - * safely destructable. - */ - other.next = &other; - other.prev = &other; - } - - ~LinkedListElement() { - if (!isSentinel && isInList()) - remove(); - } - - /* - * Get the next element in the list, or nullptr if this is the last element - * in the list. - */ - T* getNext() { - return next->asT(); - } - const T* getNext() const { - return next->asT(); + /* + * It's convenient that we return nullptr when getNext() or getPrevious() + * hits the end of the list, but doing so costs an extra word of storage in + * each linked list node (to keep track of whether |this| is the sentinel + * node) and a branch on this value in getNext/getPrevious. + * + * We could get rid of the extra word of storage by shoving the "is + * sentinel" bit into one of the pointers, although this would, of course, + * have performance implications of its own. + * + * But the goal here isn't to win an award for the fastest or slimmest + * linked list; rather, we want a *convenient* linked list. So we won't + * waste time guessing which micro-optimization strategy is best. + * + * + * Speaking of unnecessary work, it's worth addressing here why we wrote + * mozilla::LinkedList in the first place, instead of using stl::list. + * + * The key difference between mozilla::LinkedList and stl::list is that + * mozilla::LinkedList stores the mPrev/mNext pointers in the object itself, + * while stl::list stores the mPrev/mNext pointers in a list element which + * itself points to the object being stored. + * + * mozilla::LinkedList's approach makes it harder to store an object in more + * than one list. But the upside is that you can call next() / prev() / + * remove() directly on the object. With stl::list, you'd need to store a + * pointer to its iterator in the object in order to accomplish this. Not + * only would this waste space, but you'd have to remember to update that + * pointer every time you added or removed the object from a list. + * + * In-place, constant-time removal is a killer feature of doubly-linked + * lists, and supporting this painlessly was a key design criterion. + */ + +private: + LinkedListElement* mNext; + LinkedListElement* mPrev; + const bool mIsSentinel; + +public: + LinkedListElement() + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(false) + { } + + LinkedListElement(LinkedListElement&& other) + : mIsSentinel(other.mIsSentinel) + { + if (!other.isInList()) { + mNext = this; + mPrev = this; + return; } - /* - * Get the previous element in the list, or nullptr if this is the first - * element in the list. - */ - T* getPrevious() { - return prev->asT(); - } - const T* getPrevious() const { - return prev->asT(); - } + MOZ_ASSERT(other.mNext->mPrev == &other); + MOZ_ASSERT(other.mPrev->mNext == &other); /* - * Insert elem after this element in the list. |this| must be part of a - * linked list when you call setNext(); otherwise, this method will assert. + * Initialize |this| with |other|'s mPrev/mNext pointers, and adjust those + * element to point to this one. */ - void setNext(T* elem) { - MOZ_ASSERT(isInList()); - setNextUnsafe(elem); - } + mNext = other.mNext; + mPrev = other.mPrev; - /* - * Insert elem before this element in the list. |this| must be part of a - * linked list when you call setPrevious(); otherwise, this method will - * assert. - */ - void setPrevious(T* elem) { - MOZ_ASSERT(isInList()); - setPreviousUnsafe(elem); - } + mNext->mPrev = this; + mPrev->mNext = this; /* - * Remove this element from the list which contains it. If this element is - * not currently part of a linked list, this method asserts. + * Adjust |other| so it doesn't think it's in a list. This makes it + * safely destructable. */ - void remove() { - MOZ_ASSERT(isInList()); - - prev->next = next; - next->prev = prev; - next = this; - prev = this; - } + other.mNext = &other; + other.mPrev = &other; + } - /* - * Identical to remove(), but also asserts in debug builds that this element - * is in list. - */ - void removeFrom(const LinkedList& list) { - list.assertContains(asT()); + ~LinkedListElement() + { + if (!mIsSentinel && isInList()) { remove(); } - - /* - * Return true if |this| part is of a linked list, and false otherwise. - */ - bool isInList() const { - MOZ_ASSERT((next == this) == (prev == this)); - return next != this; - } - - private: - friend class LinkedList; - - enum NodeKind { - NODE_KIND_NORMAL, - NODE_KIND_SENTINEL - }; - - LinkedListElement(NodeKind nodeKind) - : next(MOZ_THIS_IN_INITIALIZER_LIST()), - prev(MOZ_THIS_IN_INITIALIZER_LIST()), - isSentinel(nodeKind == NODE_KIND_SENTINEL) - { } - - /* - * Return |this| cast to T* if we're a normal node, or return nullptr if - * we're a sentinel node. - */ - T* asT() { - if (isSentinel) - return nullptr; - - return static_cast(this); - } - const T* asT() const { - if (isSentinel) - return nullptr; - - return static_cast(this); - } - - /* - * Insert elem after this element, but don't check that this element is in - * the list. This is called by LinkedList::insertFront(). - */ - void setNextUnsafe(T* elem) { - LinkedListElement *listElem = static_cast(elem); - MOZ_ASSERT(!listElem->isInList()); - - listElem->next = this->next; - listElem->prev = this; - this->next->prev = listElem; - this->next = listElem; - } - - /* - * Insert elem before this element, but don't check that this element is in - * the list. This is called by LinkedList::insertBack(). - */ - void setPreviousUnsafe(T* elem) { - LinkedListElement* listElem = static_cast*>(elem); - MOZ_ASSERT(!listElem->isInList()); - - listElem->next = this; - listElem->prev = this->prev; - this->prev->next = listElem; - this->prev = listElem; - } - - private: - LinkedListElement& operator=(const LinkedListElement& other) MOZ_DELETE; - LinkedListElement(const LinkedListElement& other) MOZ_DELETE; + } + + /* + * Get the next element in the list, or nullptr if this is the last element + * in the list. + */ + T* getNext() { return mNext->asT(); } + const T* getNext() const { return mNext->asT(); } + + /* + * Get the previous element in the list, or nullptr if this is the first + * element in the list. + */ + T* getPrevious() { return mPrev->asT(); } + const T* getPrevious() const { return mPrev->asT(); } + + /* + * Insert aElem after this element in the list. |this| must be part of a + * linked list when you call setNext(); otherwise, this method will assert. + */ + void setNext(T* aElem) + { + MOZ_ASSERT(isInList()); + setNextUnsafe(aElem); + } + + /* + * Insert aElem before this element in the list. |this| must be part of a + * linked list when you call setPrevious(); otherwise, this method will + * assert. + */ + void setPrevious(T* aElem) + { + MOZ_ASSERT(isInList()); + setPreviousUnsafe(aElem); + } + + /* + * Remove this element from the list which contains it. If this element is + * not currently part of a linked list, this method asserts. + */ + void remove() + { + MOZ_ASSERT(isInList()); + + mPrev->mNext = mNext; + mNext->mPrev = mPrev; + mNext = this; + mPrev = this; + } + + /* + * Identical to remove(), but also asserts in debug builds that this element + * is in aList. + */ + void removeFrom(const LinkedList& aList) + { + aList.assertContains(asT()); + remove(); + } + + /* + * Return true if |this| part is of a linked list, and false otherwise. + */ + bool isInList() const + { + MOZ_ASSERT((mNext == this) == (mPrev == this)); + return mNext != this; + } + +private: + friend class LinkedList; + + enum NodeKind { + NODE_KIND_NORMAL, + NODE_KIND_SENTINEL + }; + + explicit LinkedListElement(NodeKind nodeKind) + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(nodeKind == NODE_KIND_SENTINEL) + { } + + /* + * Return |this| cast to T* if we're a normal node, or return nullptr if + * we're a sentinel node. + */ + T* asT() + { + return mIsSentinel ? nullptr : static_cast(this); + } + const T* asT() const + { + return mIsSentinel ? nullptr : static_cast(this); + } + + /* + * Insert aElem after this element, but don't check that this element is in + * the list. This is called by LinkedList::insertFront(). + */ + void setNextUnsafe(T* aElem) + { + LinkedListElement *listElem = static_cast(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this->mNext; + listElem->mPrev = this; + this->mNext->mPrev = listElem; + this->mNext = listElem; + } + + /* + * Insert aElem before this element, but don't check that this element is in + * the list. This is called by LinkedList::insertBack(). + */ + void setPreviousUnsafe(T* aElem) + { + LinkedListElement* listElem = static_cast*>(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this; + listElem->mPrev = this->mPrev; + this->mPrev->mNext = listElem; + this->mPrev = listElem; + } + +private: + LinkedListElement& operator=(const LinkedListElement& aOther) MOZ_DELETE; + LinkedListElement(const LinkedListElement& aOther) MOZ_DELETE; }; template class LinkedList { - private: - LinkedListElement sentinel; - - public: - LinkedList() : sentinel(LinkedListElement::NODE_KIND_SENTINEL) { } - - LinkedList(LinkedList&& other) - : sentinel(mozilla::Move(other.sentinel)) - { } - - ~LinkedList() { - MOZ_ASSERT(isEmpty()); - } - - /* - * Add elem to the front of the list. - */ - void insertFront(T* elem) { - /* Bypass setNext()'s this->isInList() assertion. */ - sentinel.setNextUnsafe(elem); - } - - /* - * Add elem to the back of the list. - */ - void insertBack(T* elem) { - sentinel.setPreviousUnsafe(elem); - } - - /* - * Get the first element of the list, or nullptr if the list is empty. - */ - T* getFirst() { - return sentinel.getNext(); - } - const T* getFirst() const { - return sentinel.getNext(); +private: + LinkedListElement sentinel; + +public: + LinkedList() : sentinel(LinkedListElement::NODE_KIND_SENTINEL) { } + + LinkedList(LinkedList&& aOther) + : sentinel(mozilla::Move(aOther.sentinel)) + { } + + ~LinkedList() { MOZ_ASSERT(isEmpty()); } + + /* + * Add aElem to the front of the list. + */ + void insertFront(T* aElem) + { + /* Bypass setNext()'s this->isInList() assertion. */ + sentinel.setNextUnsafe(aElem); + } + + /* + * Add aElem to the back of the list. + */ + void insertBack(T* aElem) + { + sentinel.setPreviousUnsafe(aElem); + } + + /* + * Get the first element of the list, or nullptr if the list is empty. + */ + T* getFirst() { return sentinel.getNext(); } + const T* getFirst() const { return sentinel.getNext(); } + + /* + * Get the last element of the list, or nullptr if the list is empty. + */ + T* getLast() { return sentinel.getPrevious(); } + const T* getLast() const { return sentinel.getPrevious(); } + + /* + * Get and remove the first element of the list. If the list is empty, + * return nullptr. + */ + T* popFirst() + { + T* ret = sentinel.getNext(); + if (ret) { + static_cast*>(ret)->remove(); } - - /* - * Get the last element of the list, or nullptr if the list is empty. - */ - T* getLast() { - return sentinel.getPrevious(); - } - const T* getLast() const { - return sentinel.getPrevious(); - } - - /* - * Get and remove the first element of the list. If the list is empty, - * return nullptr. - */ - T* popFirst() { - T* ret = sentinel.getNext(); - if (ret) - static_cast*>(ret)->remove(); - return ret; + return ret; + } + + /* + * Get and remove the last element of the list. If the list is empty, + * return nullptr. + */ + T* popLast() + { + T* ret = sentinel.getPrevious(); + if (ret) { + static_cast*>(ret)->remove(); } - - /* - * Get and remove the last element of the list. If the list is empty, - * return nullptr. - */ - T* popLast() { - T* ret = sentinel.getPrevious(); - if (ret) - static_cast*>(ret)->remove(); - return ret; + return ret; + } + + /* + * Return true if the list is empty, or false otherwise. + */ + bool isEmpty() const + { + return !sentinel.isInList(); + } + + /* + * Remove all the elements from the list. + * + * This runs in time linear to the list's length, because we have to mark + * each element as not in the list. + */ + void clear() + { + while (popFirst()) { + continue; } - - /* - * Return true if the list is empty, or false otherwise. - */ - bool isEmpty() const { - return !sentinel.isInList(); + } + + /* + * Measures the memory consumption of the list excluding |this|. Note that + * it only measures the list elements themselves. If the list elements + * contain pointers to other memory blocks, those blocks must be measured + * separately during a subsequent iteration over the list. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const + { + size_t n = 0; + for (const T* t = getFirst(); t; t = t->getNext()) { + n += aMallocSizeOf(t); } + return n; + } + + /* + * Like sizeOfExcludingThis(), but measures |this| as well. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const + { + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); + } + + /* + * In a debug build, make sure that the list is sane (no cycles, consistent + * mNext/mPrev pointers, only one sentinel). Has no effect in release builds. + */ + void debugAssertIsSane() const + { +#ifdef DEBUG + const LinkedListElement* slow; + const LinkedListElement* fast1; + const LinkedListElement* fast2; /* - * Remove all the elements from the list. - * - * This runs in time linear to the list's length, because we have to mark - * each element as not in the list. + * Check for cycles in the forward singly-linked list using the + * tortoise/hare algorithm. */ - void clear() { - while (popFirst()) - continue; + for (slow = sentinel.mNext, + fast1 = sentinel.mNext->mNext, + fast2 = sentinel.mNext->mNext->mNext; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mNext, fast1 = fast2->mNext, fast2 = fast1->mNext) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); } - /* - * Measures the memory consumption of the list excluding |this|. Note that - * it only measures the list elements themselves. If the list elements - * contain pointers to other memory blocks, those blocks must be measured - * separately during a subsequent iteration over the list. - */ - size_t sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const { - size_t n = 0; - for (const T* t = getFirst(); t; t = t->getNext()) - n += mallocSizeOf(t); - return n; + /* Check for cycles in the backward singly-linked list. */ + for (slow = sentinel.mPrev, + fast1 = sentinel.mPrev->mPrev, + fast2 = sentinel.mPrev->mPrev->mPrev; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mPrev, fast1 = fast2->mPrev, fast2 = fast1->mPrev) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); } /* - * Like sizeOfExcludingThis(), but measures |this| as well. + * Check that |sentinel| is the only node in the list with + * mIsSentinel == true. */ - size_t sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const { - return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + for (const LinkedListElement* elem = sentinel.mNext; + elem != &sentinel; + elem = elem->mNext) { + MOZ_ASSERT(!elem->mIsSentinel); } - /* - * In a debug build, make sure that the list is sane (no cycles, consistent - * next/prev pointers, only one sentinel). Has no effect in release builds. - */ - void debugAssertIsSane() const { -#ifdef DEBUG - const LinkedListElement* slow; - const LinkedListElement* fast1; - const LinkedListElement* fast2; - - /* - * Check for cycles in the forward singly-linked list using the - * tortoise/hare algorithm. - */ - for (slow = sentinel.next, - fast1 = sentinel.next->next, - fast2 = sentinel.next->next->next; - slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; - slow = slow->next, fast1 = fast2->next, fast2 = fast1->next) - { - MOZ_ASSERT(slow != fast1); - MOZ_ASSERT(slow != fast2); - } - - /* Check for cycles in the backward singly-linked list. */ - for (slow = sentinel.prev, - fast1 = sentinel.prev->prev, - fast2 = sentinel.prev->prev->prev; - slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; - slow = slow->prev, fast1 = fast2->prev, fast2 = fast1->prev) - { - MOZ_ASSERT(slow != fast1); - MOZ_ASSERT(slow != fast2); - } - - /* - * Check that |sentinel| is the only node in the list with - * isSentinel == true. - */ - for (const LinkedListElement* elem = sentinel.next; - elem != &sentinel; - elem = elem->next) - { - MOZ_ASSERT(!elem->isSentinel); - } - - /* Check that the next/prev pointers match up. */ - const LinkedListElement* prev = &sentinel; - const LinkedListElement* cur = sentinel.next; - do { - MOZ_ASSERT(cur->prev == prev); - MOZ_ASSERT(prev->next == cur); + /* Check that the mNext/mPrev pointers match up. */ + const LinkedListElement* prev = &sentinel; + const LinkedListElement* cur = sentinel.mNext; + do { + MOZ_ASSERT(cur->mPrev == prev); + MOZ_ASSERT(prev->mNext == cur); - prev = cur; - cur = cur->next; - } while (cur != &sentinel); + prev = cur; + cur = cur->mNext; + } while (cur != &sentinel); #endif /* ifdef DEBUG */ - } + } - private: - friend class LinkedListElement; +private: + friend class LinkedListElement; - void assertContains(const T* t) const { + void assertContains(const T* aValue) const + { #ifdef DEBUG - for (const T* elem = getFirst(); - elem; - elem = elem->getNext()) - { - if (elem == t) - return; + for (const T* elem = getFirst(); elem; elem = elem->getNext()) { + if (elem == aValue) { + return; } - MOZ_CRASH("element wasn't found in this list!"); -#endif } + MOZ_CRASH("element wasn't found in this list!"); +#endif + } - LinkedList& operator=(const LinkedList& other) MOZ_DELETE; - LinkedList(const LinkedList& other) MOZ_DELETE; + LinkedList& operator=(const LinkedList& aOther) MOZ_DELETE; + LinkedList(const LinkedList& aOther) MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/LinuxSignal.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/LinuxSignal.h new file mode 100644 index 0000000000..9b8e1bbbbe --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/LinuxSignal.h @@ -0,0 +1,48 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_LinuxSignal_h +#define mozilla_LinuxSignal_h + +namespace mozilla { + +#if defined(__arm__) + +// Some (old) Linux kernels on ARM have a bug where a signal handler +// can be called without clearing the IT bits in CPSR first. The result +// is that the first few instructions of the handler could be skipped, +// ultimately resulting in crashes. To workaround this bug, the handler +// on ARM is a trampoline that starts with enough NOP instructions, so +// that even if the IT bits are not cleared, only the NOP instructions +// will be skipped over. + +template +__attribute__((naked)) void +SignalTrampoline(int aSignal, siginfo_t* aInfo, void* aContext) +{ + asm volatile ( + "nop; nop; nop; nop" + : : : "memory"); + + // Because the assembler may generate additional insturctions below, we + // need to ensure NOPs are inserted first by separating them out above. + + asm volatile ( + "bx %0" + : + : "r"(H), "l"(aSignal), "l"(aInfo), "l"(aContext) + : "memory"); +} + +# define MOZ_SIGNAL_TRAMPOLINE(h) (mozilla::SignalTrampoline) + +#else // __arm__ + +# define MOZ_SIGNAL_TRAMPOLINE(h) (h) + +#endif // __arm__ + +} // namespace mozilla + +#endif // mozilla_LinuxSignal_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MSIntTypes.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MSIntTypes.h index 3dfba55f58..4ce922fbc5 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MSIntTypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MSIntTypes.h @@ -1,32 +1,32 @@ // ISO C9x compliant inttypes.h for Microsoft Visual Studio -// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 -// +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// // Copyright (c) 2006 Alexander Chemeris -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: -// +// // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. -// +// // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. -// +// // 3. The name of the author may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// +// /////////////////////////////////////////////////////////////////////////////// #ifndef _MSC_VER // [ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MacroArgs.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MacroArgs.h new file mode 100644 index 0000000000..c8b7338210 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MacroArgs.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements various macros meant to ease the use of variadic macros. + */ + +#ifndef mozilla_MacroArgs_h +#define mozilla_MacroArgs_h + +/* + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) counts the number of variadic + * arguments and prefixes it with |aPrefix|. For example: + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(, foo, 42) expands to 2 + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(A, foo, 42, bar) expands to A3 + * + * You must pass in between 1 and 50 (inclusive) variadic arguments, past + * |aPrefix|. It is not legal to do + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(prefix) + * + * (that is, pass in 0 variadic arguments). To ensure that a compile-time + * error occurs when these constraints are violated, use the + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT macro with the same variaidc arguments + * wherever this macro is used. + * + * Passing (__VA_ARGS__, ) rather than simply calling + * MOZ_MACROARGS_ARG_COUNT_HELPER2(__VA_ARGS__, ) very + * carefully tiptoes around a MSVC bug where it improperly expands __VA_ARGS__ + * as a single token in argument lists. For details, see: + * + * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement + * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 + */ +#define MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) \ + MOZ_MACROARGS_ARG_COUNT_HELPER((__VA_ARGS__, \ + aPrefix##50, aPrefix##49, aPrefix##48, aPrefix##47, aPrefix##46, \ + aPrefix##45, aPrefix##44, aPrefix##43, aPrefix##42, aPrefix##41, \ + aPrefix##40, aPrefix##39, aPrefix##38, aPrefix##37, aPrefix##36, \ + aPrefix##35, aPrefix##34, aPrefix##33, aPrefix##32, aPrefix##31, \ + aPrefix##30, aPrefix##29, aPrefix##28, aPrefix##27, aPrefix##26, \ + aPrefix##25, aPrefix##24, aPrefix##23, aPrefix##22, aPrefix##21, \ + aPrefix##20, aPrefix##19, aPrefix##18, aPrefix##17, aPrefix##16, \ + aPrefix##15, aPrefix##14, aPrefix##13, aPrefix##12, aPrefix##11, \ + aPrefix##10, aPrefix##9, aPrefix##8, aPrefix##7, aPrefix##6, \ + aPrefix##5, aPrefix##4, aPrefix##3, aPrefix##2, aPrefix##1, aPrefix##0)) + +#define MOZ_MACROARGS_ARG_COUNT_HELPER(aArgs) \ + MOZ_MACROARGS_ARG_COUNT_HELPER2 aArgs + +#define MOZ_MACROARGS_ARG_COUNT_HELPER2( \ + a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, \ + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \ + a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \ + a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \ + a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \ + a51, ...) a51 + +/* + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT ensures that a compile-time error occurs + * when the argument count constraints of MOZ_PASTE_PREFIX_AND_ARG_COUNT are + * violated. Use this macro wherever MOZ_PASTE_PREFIX_AND_ARG_COUNT is used + * and pass it the same variadic arguments. + * + * This macro employs a few dirty tricks to function. To detect the zero + * argument case, |(__VA_ARGS__)| is stringified, sizeof-ed, and compared to + * what it should be in the absence of arguments. + * + * Detecting too many arguments is a little trickier. With a valid argument + * count and a prefix of 1, MOZ_PASTE_PREFIX_AND_ARG_COUNT expands to e.g. 14. + * With a prefix of 0.0, it expands to e.g. 0.04. If there are too many + * arguments, it expands to the first argument over the limit. If this + * exceeding argument is a number, the assertion will fail as there is no + * number than can simultaneously be both > 10 and == 0. If the exceeding + * argument is not a number, a compile-time error should still occur due to + * the operations performed on it. + */ +#define MOZ_MACROARGS_STRINGIFY_HELPER(x) #x +#define MOZ_STATIC_ASSERT_VALID_ARG_COUNT(...) \ + static_assert( \ + sizeof(MOZ_MACROARGS_STRINGIFY_HELPER((__VA_ARGS__))) != sizeof("()") && \ + (MOZ_PASTE_PREFIX_AND_ARG_COUNT(1, __VA_ARGS__)) > 10 && \ + (int)(MOZ_PASTE_PREFIX_AND_ARG_COUNT(0.0, __VA_ARGS__)) == 0, \ + "MOZ_STATIC_ASSERT_VALID_ARG_COUNT requires 1 to 50 arguments") /* ; */ + +/* + * MOZ_ARGS_AFTER_N expands to its arguments excluding the first |N| + * arguments. For example: + * + * MOZ_ARGS_AFTER_2(a, b, c, d) expands to: c, d + */ +#define MOZ_ARGS_AFTER_1(a1, ...) __VA_ARGS__ +#define MOZ_ARGS_AFTER_2(a1, a2, ...) __VA_ARGS__ + +/* + * MOZ_ARG_N expands to its |N|th argument. + */ +#define MOZ_ARG_1(a1, ...) a1 +#define MOZ_ARG_2(a1, a2, ...) a2 + +#endif /* mozilla_MacroArgs_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MacroForEach.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MacroForEach.h new file mode 100644 index 0000000000..ae1f4d0e99 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MacroForEach.h @@ -0,0 +1,158 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements a higher-order macro for iteratively calling another macro with + * fixed leading arguments, plus a trailing element picked from a second list + * of arguments. + */ + +#ifndef mozilla_MacroForEach_h +#define mozilla_MacroForEach_h + +#include "mozilla/MacroArgs.h" + +/* + * MOZ_FOR_EACH(aMacro, aFixedArgs, aArgs) expands to N calls to the macro + * |aMacro| where N is equal the number of items in the list |aArgs|. The + * arguments for each |aMacro| call are composed of *all* arguments in the list + * |aFixedArgs| as well as a single argument in the list |aArgs|. For example: + * + * #define MACRO_A(x) x + + * int a = MOZ_FOR_EACH(MACRO_A, (), (1, 2, 3)) 0; + * // Expands to: MACRO_A(1) MACRO_A(2) MACRO_A(3) 0; + * // And further to: 1 + 2 + 3 + 0; + * + * #define MACRO_B(k, x) (k + x) + + * int b = MOZ_FOR_EACH(MACRO_B, (5,), (1, 2)) 0; + * // Expands to: MACRO_B(5, 1) MACRO_B(5, 2) 0; + * + * #define MACRO_C(k1, k2, x) (k1 + k2 + x) + + * int c = MOZ_FOR_EACH(MACRO_C, (5, 8,), (1, 2)) 0; + * // Expands to: MACRO_B(5, 8, 1) MACRO_B(5, 8, 2) 0; + * + * If the |aFixedArgs| list is not empty, a trailing comma must be included. + * + * The |aArgs| list must be not be empty and may be up to 50 items long. Use + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT to ensure that violating this constraint + * results in a compile-time error. + */ +#define MOZ_FOR_EACH_EXPAND_HELPER(...) __VA_ARGS__ +#define MOZ_FOR_EACH_GLUE(a, b) a b +#define MOZ_FOR_EACH(aMacro, aFixedArgs, aArgs) \ + MOZ_FOR_EACH_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_FOR_EACH_, \ + MOZ_FOR_EACH_EXPAND_HELPER aArgs), \ + (aMacro, aFixedArgs, aArgs)) + +#define MOZ_FOR_EACH_HELPER_GLUE(a, b) a b +#define MOZ_FOR_EACH_HELPER(aMacro, aFixedArgs, aArgs) \ + MOZ_FOR_EACH_HELPER_GLUE( \ + aMacro, \ + (MOZ_FOR_EACH_EXPAND_HELPER aFixedArgs MOZ_ARG_1 aArgs)) + +#define MOZ_FOR_EACH_1(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) +#define MOZ_FOR_EACH_2(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_1(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_3(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_2(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_4(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_3(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_5(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_4(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_6(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_5(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_7(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_6(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_8(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_7(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_9(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_8(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_10(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_9(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_11(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_10(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_12(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_11(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_13(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_12(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_14(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_13(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_15(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_14(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_16(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_15(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_17(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_16(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_18(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_17(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_19(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_18(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_20(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_19(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_21(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_20(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_22(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_21(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_23(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_22(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_24(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_23(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_25(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_24(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_26(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_25(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_27(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_26(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_28(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_27(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_29(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_28(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_30(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_29(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_31(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_30(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_32(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_31(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_33(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_32(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_34(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_33(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_35(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_34(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_36(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_35(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_37(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_36(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_38(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_37(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_39(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_38(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_40(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_39(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_41(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_40(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_42(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_41(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_43(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_42(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_44(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_43(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_45(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_44(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_46(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_45(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_47(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_46(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_48(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_47(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_49(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_48(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_50(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_49(m, fa, (MOZ_ARGS_AFTER_1 a)) + +#endif /* mozilla_MacroForEach_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MathAlgorithms.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MathAlgorithms.h index 7b98c7fc19..cd71d19770 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MathAlgorithms.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MathAlgorithms.h @@ -21,31 +21,31 @@ namespace mozilla { // Greatest Common Divisor template MOZ_ALWAYS_INLINE IntegerType -EuclidGCD(IntegerType a, IntegerType b) +EuclidGCD(IntegerType aA, IntegerType aB) { // Euclid's algorithm; O(N) in the worst case. (There are better // ways, but we don't need them for the current use of this algo.) - MOZ_ASSERT(a > 0); - MOZ_ASSERT(b > 0); + MOZ_ASSERT(aA > IntegerType(0)); + MOZ_ASSERT(aB > IntegerType(0)); - while (a != b) { - if (a > b) { - a = a - b; + while (aA != aB) { + if (aA > aB) { + aA = aA - aB; } else { - b = b - a; + aB = aB - aA; } } - return a; + return aA; } // Least Common Multiple template MOZ_ALWAYS_INLINE IntegerType -EuclidLCM(IntegerType a, IntegerType b) +EuclidLCM(IntegerType aA, IntegerType aB) { // Divide first to reduce overflow risk. - return (a / EuclidGCD(a, b)) * b; + return (aA / EuclidGCD(aA, aB)) * aB; } namespace detail { @@ -68,7 +68,7 @@ template<> struct AllowDeprecatedAbs : TrueType {}; // to Abs below, and it will be removed when all callers have been changed. template inline typename mozilla::EnableIf::value, T>::Type -DeprecatedAbs(const T t) +DeprecatedAbs(const T aValue) { // The absolute value of the smallest possible value of a signed-integer type // won't fit in that type (on twos-complement systems -- and we're blithely @@ -79,10 +79,10 @@ DeprecatedAbs(const T t) // value in the range [-maxvalue, 0]), then negating (giving a value in the // range [0, maxvalue]), doesn't produce maxvalue (because in twos-complement, // (minvalue + 1) == -maxvalue). - MOZ_ASSERT(t >= 0 || - -(t + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1), + MOZ_ASSERT(aValue >= 0 || + -(aValue + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1), "You can't negate the smallest possible negative integer!"); - return t >= 0 ? t : -t; + return aValue >= 0 ? aValue : -aValue; } namespace detail { @@ -102,7 +102,8 @@ template<> struct AbsReturnTypeFixed { typedef uint64_t Type; }; template struct AbsReturnType : AbsReturnTypeFixed {}; -template<> struct AbsReturnType : EnableIf {}; +template<> struct AbsReturnType : + EnableIf {}; template<> struct AbsReturnType { typedef unsigned char Type; }; template<> struct AbsReturnType { typedef unsigned short Type; }; template<> struct AbsReturnType { typedef unsigned int Type; }; @@ -116,50 +117,46 @@ template<> struct AbsReturnType { typedef long double Type; }; template inline typename detail::AbsReturnType::Type -Abs(const T t) +Abs(const T aValue) { typedef typename detail::AbsReturnType::Type ReturnType; - return t >= 0 ? ReturnType(t) : ~ReturnType(t) + 1; + return aValue >= 0 ? ReturnType(aValue) : ~ReturnType(aValue) + 1; } template<> inline float -Abs(const float f) +Abs(const float aFloat) { - return std::fabs(f); + return std::fabs(aFloat); } template<> inline double -Abs(const double d) +Abs(const double aDouble) { - return std::fabs(d); + return std::fabs(aDouble); } template<> inline long double -Abs(const long double d) +Abs(const long double aLongDouble) { - return std::fabs(d); + return std::fabs(aLongDouble); } } // namespace mozilla -#if defined(_WIN32) && (_MSC_VER >= 1300) && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) +#if defined(_WIN32) && (_MSC_VER >= 1300) && \ + (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) # define MOZ_BITSCAN_WINDOWS - extern "C" { - unsigned char _BitScanForward(unsigned long* Index, unsigned long mask); - unsigned char _BitScanReverse(unsigned long* Index, unsigned long mask); +# include # pragma intrinsic(_BitScanForward, _BitScanReverse) # if defined(_M_AMD64) || defined(_M_X64) # define MOZ_BITSCAN_WINDOWS64 - unsigned char _BitScanForward64(unsigned long* index, unsigned __int64 mask); - unsigned char _BitScanReverse64(unsigned long* index, unsigned __int64 mask); # pragma intrinsic(_BitScanForward64, _BitScanReverse64) # endif - } // extern "C" #endif @@ -169,62 +166,68 @@ namespace detail { #if defined(MOZ_BITSCAN_WINDOWS) - inline uint_fast8_t - CountLeadingZeroes32(uint32_t u) - { - unsigned long index; - _BitScanReverse(&index, static_cast(u)); - return uint_fast8_t(31 - index); - } +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanReverse(&index, static_cast(aValue)); + return uint_fast8_t(31 - index); +} - inline uint_fast8_t - CountTrailingZeroes32(uint32_t u) - { - unsigned long index; - _BitScanForward(&index, static_cast(u)); - return uint_fast8_t(index); - } +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanForward(&index, static_cast(aValue)); + return uint_fast8_t(index); +} - inline uint_fast8_t - CountPopulation32(uint32_t u) - { - uint32_t sum2 = (u & 0x55555555) + ((u & 0xaaaaaaaa) >> 1); - uint32_t sum4 = (sum2 & 0x33333333) + ((sum2 & 0xcccccccc) >> 2); - uint32_t sum8 = (sum4 & 0x0f0f0f0f) + ((sum4 & 0xf0f0f0f0) >> 4); - uint32_t sum16 = (sum8 & 0x00ff00ff) + ((sum8 & 0xff00ff00) >> 8); - return sum16; - } +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + uint32_t x = aValue - ((aValue >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + return (((x + (x >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; +} +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return uint_fast8_t(CountPopulation32(aValue & 0xffffffff) + + CountPopulation32(aValue >> 32)); +} - inline uint_fast8_t - CountLeadingZeroes64(uint64_t u) - { -# if defined(MOZ_BITSCAN_WINDOWS64) - unsigned long index; - _BitScanReverse64(&index, static_cast(u)); - return uint_fast8_t(63 - index); -# else - uint32_t hi = uint32_t(u >> 32); - if (hi != 0) - return CountLeadingZeroes32(hi); - return 32 + CountLeadingZeroes32(uint32_t(u)); -# endif +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanReverse64(&index, static_cast(aValue)); + return uint_fast8_t(63 - index); +#else + uint32_t hi = uint32_t(aValue >> 32); + if (hi != 0) { + return CountLeadingZeroes32(hi); } + return 32u + CountLeadingZeroes32(uint32_t(aValue)); +#endif +} - inline uint_fast8_t - CountTrailingZeroes64(uint64_t u) - { -# if defined(MOZ_BITSCAN_WINDOWS64) - unsigned long index; - _BitScanForward64(&index, static_cast(u)); - return uint_fast8_t(index); -# else - uint32_t lo = uint32_t(u); - if (lo != 0) - return CountTrailingZeroes32(lo); - return 32 + CountTrailingZeroes32(uint32_t(u >> 32)); -# endif +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanForward64(&index, static_cast(aValue)); + return uint_fast8_t(index); +#else + uint32_t lo = uint32_t(aValue); + if (lo != 0) { + return CountTrailingZeroes32(lo); } + return 32u + CountTrailingZeroes32(uint32_t(aValue >> 32)); +#endif +} # ifdef MOZ_HAVE_BITSCAN64 # undef MOZ_HAVE_BITSCAN64 @@ -240,52 +243,59 @@ namespace detail { // gcc has had __builtin_clz and friends since 3.4: no need to check. # endif - inline uint_fast8_t - CountLeadingZeroes32(uint32_t u) - { - return __builtin_clz(u); - } +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + return __builtin_clz(aValue); +} - inline uint_fast8_t - CountTrailingZeroes32(uint32_t u) - { - return __builtin_ctz(u); - } +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + return __builtin_ctz(aValue); +} - inline uint_fast8_t - CountPopulation32(uint32_t u) - { - return __builtin_popcount(u); - } +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + return __builtin_popcount(aValue); +} - inline uint_fast8_t - CountLeadingZeroes64(uint64_t u) - { - return __builtin_clzll(u); - } +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return __builtin_popcountll(aValue); +} - inline uint_fast8_t - CountTrailingZeroes64(uint64_t u) - { - return __builtin_ctzll(u); - } +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ + return __builtin_clzll(aValue); +} + +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ + return __builtin_ctzll(aValue); +} #else # error "Implement these!" - inline uint_fast8_t CountLeadingZeroes32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountTrailingZeroes32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountPopulation32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountLeadingZeroes64(uint64_t u) MOZ_DELETE; - inline uint_fast8_t CountTrailingZeroes64(uint64_t u) MOZ_DELETE; +inline uint_fast8_t CountLeadingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountLeadingZeroes64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes64(uint64_t aValue) MOZ_DELETE; #endif } // namespace detail /** - * Compute the number of high-order zero bits in the NON-ZERO number |u|. That - * is, looking at the bitwise representation of the number, with the highest- - * valued bits at the start, return the number of zeroes before the first one - * is observed. + * Compute the number of high-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * highest- valued bits at the start, return the number of zeroes before the + * first one is observed. * * CountLeadingZeroes32(0xF0FF1000) is 0; * CountLeadingZeroes32(0x7F8F0001) is 1; @@ -293,17 +303,17 @@ namespace detail { * CountLeadingZeroes32(0x1FF50010) is 3; and so on. */ inline uint_fast8_t -CountLeadingZeroes32(uint32_t u) +CountLeadingZeroes32(uint32_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountLeadingZeroes32(u); + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes32(aValue); } /** - * Compute the number of low-order zero bits in the NON-ZERO number |u|. That - * is, looking at the bitwise representation of the number, with the lowest- - * valued bits at the start, return the number of zeroes before the first one - * is observed. + * Compute the number of low-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * lowest- valued bits at the start, return the number of zeroes before the + * first one is observed. * * CountTrailingZeroes32(0x0100FFFF) is 0; * CountTrailingZeroes32(0x7000FFFE) is 1; @@ -311,35 +321,42 @@ CountLeadingZeroes32(uint32_t u) * CountTrailingZeroes32(0x0080FFF8) is 3; and so on. */ inline uint_fast8_t -CountTrailingZeroes32(uint32_t u) +CountTrailingZeroes32(uint32_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountTrailingZeroes32(u); + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes32(aValue); } /** - * Compute the number of one bits in the number |u|, + * Compute the number of one bits in the number |aValue|, */ inline uint_fast8_t -CountPopulation32(uint32_t u) +CountPopulation32(uint32_t aValue) +{ + return detail::CountPopulation32(aValue); +} + +/** Analogous to CoutPopulation32, but for 64-bit numbers */ +inline uint_fast8_t +CountPopulation64(uint64_t aValue) { - return detail::CountPopulation32(u); + return detail::CountPopulation64(aValue); } /** Analogous to CountLeadingZeroes32, but for 64-bit numbers. */ inline uint_fast8_t -CountLeadingZeroes64(uint64_t u) +CountLeadingZeroes64(uint64_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountLeadingZeroes64(u); + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes64(aValue); } /** Analogous to CountTrailingZeroes32, but for 64-bit numbers. */ inline uint_fast8_t -CountTrailingZeroes64(uint64_t u) +CountTrailingZeroes64(uint64_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountTrailingZeroes64(u); + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes64(aValue); } namespace detail { @@ -350,27 +367,29 @@ class CeilingLog2; template class CeilingLog2 { - public: - static uint_fast8_t compute(const T t) { - // Check for <= 1 to avoid the == 0 undefined case. - return t <= 1 ? 0 : 32 - CountLeadingZeroes32(t - 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0u : 32u - CountLeadingZeroes32(aValue - 1); + } }; template class CeilingLog2 { - public: - static uint_fast8_t compute(const T t) { - // Check for <= 1 to avoid the == 0 undefined case. - return t <= 1 ? 0 : 64 - CountLeadingZeroes64(t - 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0 : 64 - CountLeadingZeroes64(aValue - 1); + } }; } // namespace detail /** - * Compute the log of the least power of 2 greater than or equal to |t|. + * Compute the log of the least power of 2 greater than or equal to |aValue|. * * CeilingLog2(0..1) is 0; * CeilingLog2(2) is 1; @@ -380,16 +399,16 @@ class CeilingLog2 */ template inline uint_fast8_t -CeilingLog2(const T t) +CeilingLog2(const T aValue) { - return detail::CeilingLog2::compute(t); + return detail::CeilingLog2::compute(aValue); } /** A CeilingLog2 variant that accepts only size_t. */ inline uint_fast8_t -CeilingLog2Size(size_t n) +CeilingLog2Size(size_t aValue) { - return CeilingLog2(n); + return CeilingLog2(aValue); } namespace detail { @@ -400,25 +419,27 @@ class FloorLog2; template class FloorLog2 { - public: - static uint_fast8_t compute(const T t) { - return 31 - CountLeadingZeroes32(t | 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + return 31u - CountLeadingZeroes32(aValue | 1); + } }; template class FloorLog2 { - public: - static uint_fast8_t compute(const T t) { - return 63 - CountLeadingZeroes64(t | 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + return 63u - CountLeadingZeroes64(aValue | 1); + } }; } // namespace detail /** - * Compute the log of the greatest power of 2 less than or equal to |t|. + * Compute the log of the greatest power of 2 less than or equal to |aValue|. * * FloorLog2(0..1) is 0; * FloorLog2(2..3) is 1; @@ -427,16 +448,16 @@ class FloorLog2 */ template inline uint_fast8_t -FloorLog2(const T t) +FloorLog2(const T aValue) { - return detail::FloorLog2::compute(t); + return detail::FloorLog2::compute(aValue); } /** A FloorLog2 variant that accepts only size_t. */ inline uint_fast8_t -FloorLog2Size(size_t n) +FloorLog2Size(size_t aValue) { - return FloorLog2(n); + return FloorLog2(aValue); } /* @@ -444,11 +465,11 @@ FloorLog2Size(size_t n) * be so great that the computed value would overflow |size_t|. */ inline size_t -RoundUpPow2(size_t x) +RoundUpPow2(size_t aValue) { - MOZ_ASSERT(x <= (size_t(1) << (sizeof(size_t) * CHAR_BIT - 1)), + MOZ_ASSERT(aValue <= (size_t(1) << (sizeof(size_t) * CHAR_BIT - 1)), "can't round up -- will overflow!"); - return size_t(1) << CeilingLog2(x); + return size_t(1) << CeilingLog2(aValue); } /** @@ -456,11 +477,11 @@ RoundUpPow2(size_t x) */ template inline T -RotateLeft(const T t, uint_fast8_t shift) +RotateLeft(const T aValue, uint_fast8_t aShift) { - MOZ_ASSERT(shift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); static_assert(IsUnsigned::value, "Rotates require unsigned values"); - return (t << shift) | (t >> (sizeof(T) * CHAR_BIT - shift)); + return (aValue << aShift) | (aValue >> (sizeof(T) * CHAR_BIT - aShift)); } /** @@ -468,11 +489,11 @@ RotateLeft(const T t, uint_fast8_t shift) */ template inline T -RotateRight(const T t, uint_fast8_t shift) +RotateRight(const T aValue, uint_fast8_t aShift) { - MOZ_ASSERT(shift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); static_assert(IsUnsigned::value, "Rotates require unsigned values"); - return (t >> shift) | (t << (sizeof(T) * CHAR_BIT - shift)); + return (aValue >> aShift) | (aValue << (sizeof(T) * CHAR_BIT - aShift)); } } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Maybe.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Maybe.h index 25683a28ab..4ba88f6771 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Maybe.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Maybe.h @@ -31,131 +31,150 @@ namespace mozilla { template class Maybe { - AlignedStorage2 storage; - bool constructed; - - T& asT() { return *storage.addr(); } - - public: - Maybe() { constructed = false; } - ~Maybe() { if (constructed) asT().~T(); } - - bool empty() const { return !constructed; } - - void construct() { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(); - constructed = true; - } - - template - void construct(const T1& t1) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8, const T9& t9) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8, t9); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); - constructed = true; - } - - T* addr() { - MOZ_ASSERT(constructed); - return &asT(); - } - - T& ref() { - MOZ_ASSERT(constructed); - return asT(); - } - - const T& ref() const { - MOZ_ASSERT(constructed); - return const_cast(this)->asT(); - } - - void destroy() { - ref().~T(); - constructed = false; - } - - void destroyIfConstructed() { - if (!empty()) - destroy(); - } - - private: - Maybe(const Maybe& other) MOZ_DELETE; - const Maybe& operator=(const Maybe& other) MOZ_DELETE; + AlignedStorage2 storage; + bool constructed; + + T& asT() { return *storage.addr(); } + +public: + Maybe() { constructed = false; } + ~Maybe() { if (constructed) { asT().~T(); } } + + bool empty() const { return !constructed; } + + void construct() + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(); + constructed = true; + } + + template + void construct(const T1& aT1) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9, const T10& aT10) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9, aT10); + constructed = true; + } + + T* addr() + { + MOZ_ASSERT(constructed); + return &asT(); + } + + T& ref() + { + MOZ_ASSERT(constructed); + return asT(); + } + + const T& ref() const + { + MOZ_ASSERT(constructed); + return const_cast(this)->asT(); + } + + void destroy() + { + ref().~T(); + constructed = false; + } + + void destroyIfConstructed() + { + if (!empty()) { + destroy(); + } + } + +private: + Maybe(const Maybe& aOther) MOZ_DELETE; + const Maybe& operator=(const Maybe& aOther) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MaybeOneOf.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MaybeOneOf.h new file mode 100644 index 0000000000..1c58f88253 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MaybeOneOf.h @@ -0,0 +1,144 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_MaybeOneOf_h +#define mozilla_MaybeOneOf_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" +#include "mozilla/Move.h" +#include "mozilla/TemplateLib.h" + +#include // For placement new + +namespace mozilla { + +/* + * MaybeOneOf is like Maybe, but it supports constructing either T1 + * or T2. When a MaybeOneOf is constructed, it is |empty()|, i.e., + * no value has been constructed and no destructor will be called when the + * MaybeOneOf is destroyed. Upon calling |construct()| or + * |construct()|, a T1 or T2 object will be constructed with the given + * arguments and that object will be destroyed when the owning MaybeOneOf is + * destroyed. + */ +template +class MaybeOneOf +{ + AlignedStorage::value> storage; + + enum State { None, SomeT1, SomeT2 } state; + template struct Type2State {}; + + template + T& as() + { + MOZ_ASSERT(state == Type2State::result); + return *(T*)storage.addr(); + } + + template + const T& as() const + { + MOZ_ASSERT(state == Type2State::result); + return *(T*)storage.addr(); + } + +public: + MaybeOneOf() : state(None) {} + ~MaybeOneOf() { destroyIfConstructed(); } + + bool empty() const { return state == None; } + + template + bool constructed() const { return state == Type2State::result; } + + template + void construct() + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(); + } + + template + void construct(U&& aU) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(Move(aU)); + } + + template + void construct(const U1& aU1) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(aU1); + } + + template + void construct(const U1& aU1, const U2& aU2) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(aU1, aU2); + } + + template + T& ref() + { + return as(); + } + + template + const T& ref() const + { + return as(); + } + + void destroy() + { + MOZ_ASSERT(state == SomeT1 || state == SomeT2); + if (state == SomeT1) { + as().~T1(); + } else if (state == SomeT2) { + as().~T2(); + } + state = None; + } + + void destroyIfConstructed() + { + if (!empty()) { + destroy(); + } + } + +private: + MaybeOneOf(const MaybeOneOf& aOther) MOZ_DELETE; + const MaybeOneOf& operator=(const MaybeOneOf& aOther) MOZ_DELETE; +}; + +template +template +struct MaybeOneOf::Type2State +{ + typedef MaybeOneOf Enclosing; + static const typename Enclosing::State result = Enclosing::SomeT1; +}; + +template +template +struct MaybeOneOf::Type2State +{ + typedef MaybeOneOf Enclosing; + static const typename Enclosing::State result = Enclosing::SomeT2; +}; + +} // namespace mozilla + +#endif /* mozilla_MaybeOneOf_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MemoryChecking.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MemoryChecking.h index 2130990c6b..0642d758c0 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MemoryChecking.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/MemoryChecking.h @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* - * Provides a common interface to the ASan (AddressSanitizer) and Valgrind + * Provides a common interface to the ASan (AddressSanitizer) and Valgrind * functions used to mark memory in certain ways. In detail, the following * three macros are provided: * @@ -34,14 +34,14 @@ #if defined(MOZ_ASAN) #include +#include "mozilla/Types.h" + extern "C" { - /* These definitions are usually provided through the - * sanitizer/asan_interface.h header installed by ASan. - */ - void __asan_poison_memory_region(void const volatile *addr, size_t size) - __attribute__((visibility("default"))); - void __asan_unpoison_memory_region(void const volatile *addr, size_t size) - __attribute__((visibility("default"))); +/* These definitions are usually provided through the + * sanitizer/asan_interface.h header installed by ASan. + */ +void MOZ_EXPORT __asan_poison_memory_region(void const volatile *addr, size_t size); +void MOZ_EXPORT __asan_unpoison_memory_region(void const volatile *addr, size_t size); #define MOZ_MAKE_MEM_NOACCESS(addr, size) \ __asan_poison_memory_region((addr), (size)) @@ -63,9 +63,9 @@ extern "C" { VALGRIND_MAKE_MEM_DEFINED((addr), (size)) #else -#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while(0) -#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while(0) -#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while(0) +#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while (0) #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Move.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Move.h index f7d39ffa9b..08ae86fa57 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Move.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Move.h @@ -105,7 +105,7 @@ namespace mozilla { * * c2 = Move(c1); * - * This destroys c1, moves c1's value to c2, and leaves c1 in an undefined but + * This destroys c2, moves c1's value to c2, and leaves c1 in an undefined but * destructible state. * * As we say, a move must leave the original in a "destructible" state. The @@ -132,7 +132,7 @@ namespace mozilla { * * To avoid this, C++11 has tweaks to make it possible to write what you mean. * The four constructor overloads above can be written as one constructor - * template like so: + * template like so[0]: * * template * C::C(XArg&& x, YArg&& y) : x(Forward(x)), y(Forward(y)) { } @@ -144,8 +144,8 @@ namespace mozilla { * - First, when a function template takes an argument that is an rvalue * reference to a template argument (like 'XArg&& x' and 'YArg&& y' above), * then when the argument is applied to an lvalue, the template argument - * resolves to 'T &'; and when it is applied to an rvalue, the template - * argument resolves to 'T &&'. Thus, in a call to C::C like: + * resolves to 'T&'; and when it is applied to an rvalue, the template + * argument resolves to 'T&&'. Thus, in a call to C::C like: * * X foo(int); * Y yy; @@ -180,6 +180,28 @@ namespace mozilla { * 'std::forward', which are just like our 'Move' and 'Forward'; but those * definitions aren't available in that header on all our platforms, so we * define them ourselves here.) + * + * 0. This pattern is known as "perfect forwarding". Interestingly, it is not + * actually perfect, and it can't forward all possible argument expressions! + * There are two issues: one that's a C++11 issue, and one that's a legacy + * compiler issue. + * + * The C++11 issue is that you can't form a reference to a bit-field. As a + * workaround, assign the bit-field to a local variable and use that: + * + * // C is as above + * struct S { int x : 1; } s; + * C(s.x, 0); // BAD: s.x is a reference to a bit-field, can't form those + * int tmp = s.x; + * C(tmp, 0); // OK: tmp not a bit-field + * + * The legacy issue is that when we don't have true nullptr and must emulate + * it (gcc 4.4/4.5), forwarding |nullptr| results in an |int| or |long| + * forwarded reference. But such a reference, even if its value is a null + * pointer constant expression, is not itself a null pointer constant + * expression. This causes -Werror=conversion-null errors and pointer-to- + * integer comparison errors. Until we always have true nullptr, users of + * forwarding methods must not pass |nullptr| to them. */ /** @@ -188,9 +210,9 @@ namespace mozilla { */ template inline typename RemoveReference::Type&& -Move(T&& a) +Move(T&& aX) { - return static_cast::Type&&>(a); + return static_cast::Type&&>(aX); } /** @@ -199,28 +221,28 @@ Move(T&& a) */ template inline T&& -Forward(typename RemoveReference::Type& a) +Forward(typename RemoveReference::Type& aX) { - return static_cast(a); + return static_cast(aX); } template inline T&& -Forward(typename RemoveReference::Type&& t) +Forward(typename RemoveReference::Type&& aX) { static_assert(!IsLvalueReference::value, "misuse of Forward detected! try the other overload"); - return static_cast(t); + return static_cast(aX); } -/** Swap |t| and |u| using move-construction if possible. */ +/** Swap |aX| and |aY| using move-construction if possible. */ template inline void -Swap(T& t, T& u) +Swap(T& aX, T& aY) { - T tmp(Move(t)); - t = Move(u); - u = Move(tmp); + T tmp(Move(aX)); + aX = Move(aY); + aY = Move(tmp); } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/NullPtr.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/NullPtr.h index 35faadc4c3..5963613c4b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/NullPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/NullPtr.h @@ -13,12 +13,10 @@ #define mozilla_NullPtr_h #if defined(__clang__) -# ifndef __has_extension -# define __has_extension __has_feature -# endif -# if __has_extension(cxx_nullptr) -# define MOZ_HAVE_CXX11_NULLPTR +# if !__has_extension(cxx_nullptr) +# error "clang version natively supporting nullptr is required." # endif +# define MOZ_HAVE_CXX11_NULLPTR #elif defined(__GNUC__) # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L # include "mozilla/Compiler.h" @@ -26,23 +24,89 @@ # define MOZ_HAVE_CXX11_NULLPTR # endif # endif -#elif _MSC_VER >= 1600 -# define MOZ_HAVE_CXX11_NULLPTR +#elif defined(_MSC_VER) + // The minimum supported MSVC (10, _MSC_VER 1600) supports nullptr. +# define MOZ_HAVE_CXX11_NULLPTR #endif +namespace mozilla { + /** - * Use C++11 nullptr if available; otherwise use __null for gcc, or a 0 literal - * with the correct size to match the size of a pointer on a given platform. + * IsNullPointer::value is true iff T is the type of C++11's nullptr. If + * nullptr is emulated, IsNullPointer::value is false for all T. + * + * IsNullPointer is useful to give an argument the true decltype(nullptr) type. + * decltype(nullptr) doesn't work when nullptr is emulated. The simplest + * workaround is to use template overloading and SFINAE to expose an overload + * only if an argument's type is decltype(nullptr). Some examples (that assume + * namespace mozilla has been opened, for simplicity): + * + * // foo(T*), foo(stuff that converts to T*), and foo(decltype(nullptr)) + * // (only invoked if nullptr is true nullptr, otherwise foo(T*) is invoked) + * // but nothing else + * void foo(T*) { } + * template + * void foo(N, + * typename EnableIf::value, int>::Type dummy = 0) + * { } + * + * // foo(T*) *exactly* and foo(decltype(nullptr)), nothing else + * void foo(T*) { } + * template + * void foo(U, + * typename EnableIf::value, int>::Type dummy = 0) + * MOZ_DELETE; + * + * The exact details of how set up the SFINAE bits vary on a case-by-case basis. + * If you need help with this (and unless you've internalized way more sadmaking + * nullptr-emulation knowledge than you should have, you do), feel free to poke + * the person with blame on this comment with questions. :-) + * + * Ideally this would be in TypeTraits.h, but C++11 omitted std::is_null_pointer + * (fixed in C++1y), so in the interests of easing a switch to , + * this trait lives elsewhere. */ +template +struct IsNullPointer { static const bool value = false; }; -#ifndef MOZ_HAVE_CXX11_NULLPTR -# if defined(__GNUC__) -# define nullptr __null -# elif defined(_WIN64) -# define nullptr 0LL -# else -# define nullptr 0L -# endif +} // namespace mozilla + +/** + * mozilla::NullptrT is a type that's sort of like decltype(nullptr). But it + * can't be identical, because emulated nullptr doesn't have a distinct type. + * Only with gcc 4.4/4.5, emulated nullptr is __null, and decltype(__null) is + * int or long. But passing __null to an int/long parameter triggers + * -Werror=conversion-null errors with gcc 4.5, or (depending on subsequent use + * inside the overloaded function) can trigger pointer-to-integer comparison + * compiler errors. So fairly often, actually, NullptrT is *not* what you want. + * + * Instead, often you should use template-based overloading in concert with + * SFINAE to add a nullptr overload -- see the comments by IsNullPointer. + * + * So when *should* you use NullptrT? Thus far, the only truly good use seems + * to be as an argument type for operator overloads (because C++ doesn't allow + * operator= to have more than one argument, operator== to have more than two, + * &c.). But even in such cases, it really only works if there are no other + * overloads of the operator that accept a pointer type. If you want both T* + * and nullptr_t overloads, you'll have to wait til we drop gcc 4.4/4.5 support. + * (Currently b2g is the only impediment to this.) + */ +#ifdef MOZ_HAVE_CXX11_NULLPTR +// decltype does the right thing for actual nullptr. +namespace mozilla { +typedef decltype(nullptr) NullptrT; +template<> +struct IsNullPointer { static const bool value = true; }; +} +# undef MOZ_HAVE_CXX11_NULLPTR +#elif MOZ_IS_GCC +# define nullptr __null +// void* sweeps up more than just nullptr, but compilers supporting true +// nullptr are the majority now, so they should detect mistakes. If you're +// feeling paranoid, check/assert that your NullptrT equals nullptr. +namespace mozilla { typedef void* NullptrT; } +#else +# error "No compiler support for nullptr or its emulation." #endif #endif /* mozilla_NullPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/NumericLimits.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/NumericLimits.h index d2ee29813e..730fcb410b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/NumericLimits.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/NumericLimits.h @@ -17,10 +17,10 @@ namespace mozilla { /** - * The NumericLimits class provides a compatibility layer with std::numeric_limits - * for char16_t, otherwise it is exactly the same as std::numeric_limits. - * Code which does not need std::numeric_limits should avoid using - * NumericLimits. + * The NumericLimits class provides a compatibility layer with + * std::numeric_limits for char16_t, otherwise it is exactly the same as + * std::numeric_limits. Code which does not need std::numeric_limits + * should avoid using NumericLimits. */ template class NumericLimits : public std::numeric_limits diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Pair.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Pair.h new file mode 100644 index 0000000000..e9e8a76938 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Pair.h @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A class holding a pair of objects that tries to conserve storage space. */ + +#ifndef mozilla_Pair_h +#define mozilla_Pair_h + +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +namespace detail { + +enum StorageType { AsBase, AsMember }; + +// Optimize storage using the Empty Base Optimization -- that empty base classes +// don't take up space -- to optimize size when one or the other class is +// stateless and can be used as a base class. +// +// The extra conditions on storage for B are necessary so that PairHelper won't +// ambiguously inherit from either A or B, such that one or the other base class +// would be inaccessible. +template::value ? detail::AsBase : detail::AsMember, + detail::StorageType = + IsEmpty::value && !IsBaseOf::value && !IsBaseOf::value + ? detail::AsBase + : detail::AsMember> +struct PairHelper; + +template +struct PairHelper +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : mFirstA(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(mSecondB, aOther.mSecondB); + } + +private: + A mFirstA; + B mSecondB; +}; + +template +struct PairHelper : private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : B(Forward(aB)), + mFirstA(Forward(aA)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return *this; } + const B& second() const { return *this; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(static_cast(*this), static_cast(aOther)); + } + +private: + A mFirstA; +}; + +template +struct PairHelper : private A +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return *this; } + const A& first() const { return *this; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(mSecondB, aOther.mSecondB); + } + +private: + B mSecondB; +}; + +template +struct PairHelper : private A, private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + B(Forward(aB)) + {} + + A& first() { return static_cast(*this); } + const A& first() const { return static_cast(*this); } + B& second() { return static_cast(*this); } + const B& second() const { return static_cast(*this); } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(static_cast(*this), static_cast(aOther)); + } +}; + +} // namespace detail + +/** + * Pair is the logical concatenation of an instance of A with an instance B. + * Space is conserved when possible. Neither A nor B may be a final class. + * + * It's typically clearer to have individual A and B member fields. Except if + * you want the space-conserving qualities of Pair, you're probably better off + * not using this! + * + * No guarantees are provided about the memory layout of A and B, the order of + * initialization or destruction of A and B, and so on. (This is approximately + * required to optimize space usage.) The first/second names are merely + * conceptual! + */ +template +struct Pair + : private detail::PairHelper +{ + typedef typename detail::PairHelper Base; + +public: + template + Pair(AArg&& aA, BArg&& aB) + : Base(Forward(aA), Forward(aB)) + {} + + /** The A instance. */ + using Base::first; + /** The B instance. */ + using Base::second; + + /** Swap this pair with another pair. */ + void swap(Pair& aOther) { Base::swap(aOther); } + +private: + Pair(const Pair&) MOZ_DELETE; +}; + +template +void +Swap(Pair& aX, Pair& aY) +{ + aX.swap(aY); +} + +} // namespace mozilla + +#endif /* mozilla_Pair_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/PodOperations.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/PodOperations.h index adbf2e699d..843e1311d3 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/PodOperations.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/PodOperations.h @@ -24,26 +24,27 @@ namespace mozilla { -/** Set the contents of |t| to 0. */ +/** Set the contents of |aT| to 0. */ template static MOZ_ALWAYS_INLINE void -PodZero(T* t) +PodZero(T* aT) { - memset(t, 0, sizeof(T)); + memset(aT, 0, sizeof(T)); } -/** Set the contents of |nelem| elements starting at |t| to 0. */ +/** Set the contents of |aNElem| elements starting at |aT| to 0. */ template static MOZ_ALWAYS_INLINE void -PodZero(T* t, size_t nelem) +PodZero(T* aT, size_t aNElem) { /* - * This function is often called with 'nelem' small; we use an inline loop + * This function is often called with 'aNElem' small; we use an inline loop * instead of calling 'memset' with a non-constant length. The compiler * should inline the memset call with constant size, though. */ - for (T* end = t + nelem; t < end; t++) - memset(t, 0, sizeof(T)); + for (T* end = aT + aNElem; aT < end; aT++) { + memset(aT, 0, sizeof(T)); + } } /* @@ -54,107 +55,116 @@ PodZero(T* t, size_t nelem) * compile error involving PodZero and array types, use PodArrayZero instead. */ template -static void PodZero(T (&t)[N]) MOZ_DELETE; +static void PodZero(T (&aT)[N]) MOZ_DELETE; template -static void PodZero(T (&t)[N], size_t nelem) MOZ_DELETE; +static void PodZero(T (&aT)[N], size_t aNElem) MOZ_DELETE; -/** Set the contents of the array |t| to zero. */ +/** Set the contents of the array |aT| to zero. */ template static MOZ_ALWAYS_INLINE void -PodArrayZero(T (&t)[N]) +PodArrayZero(T (&aT)[N]) { - memset(t, 0, N * sizeof(T)); + memset(aT, 0, N * sizeof(T)); } template static MOZ_ALWAYS_INLINE void -PodArrayZero(Array& arr) +PodArrayZero(Array& aArr) { - memset(&arr[0], 0, N * sizeof(T)); + memset(&aArr[0], 0, N * sizeof(T)); } /** - * Assign |*src| to |*dst|. The locations must not be the same and must not + * Assign |*aSrc| to |*aDst|. The locations must not be the same and must not * overlap. */ template static MOZ_ALWAYS_INLINE void -PodAssign(T* dst, const T* src) +PodAssign(T* aDst, const T* aSrc) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, PointerRangeSize(src, static_cast(dst)) >= 1); - MOZ_ASSERT_IF(dst < src, PointerRangeSize(static_cast(dst), src) >= 1); - memcpy(reinterpret_cast(dst), reinterpret_cast(src), sizeof(T)); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= 1); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= 1); + memcpy(reinterpret_cast(aDst), reinterpret_cast(aSrc), + sizeof(T)); } /** - * Copy |nelem| T elements from |src| to |dst|. The two memory ranges must not - * overlap! + * Copy |aNElem| T elements from |aSrc| to |aDst|. The two memory ranges must + * not overlap! */ template static MOZ_ALWAYS_INLINE void -PodCopy(T* dst, const T* src, size_t nelem) +PodCopy(T* aDst, const T* aSrc, size_t aNElem) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, PointerRangeSize(src, static_cast(dst)) >= nelem); - MOZ_ASSERT_IF(dst < src, PointerRangeSize(static_cast(dst), src) >= nelem); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); - if (nelem < 128) { + if (aNElem < 128) { /* * Avoid using operator= in this loop, as it may have been * intentionally deleted by the POD type. */ - for (const T* srcend = src + nelem; src < srcend; src++, dst++) - PodAssign(dst, src); + for (const T* srcend = aSrc + aNElem; aSrc < srcend; aSrc++, aDst++) { + PodAssign(aDst, aSrc); + } } else { - memcpy(dst, src, nelem * sizeof(T)); + memcpy(aDst, aSrc, aNElem * sizeof(T)); } } template static MOZ_ALWAYS_INLINE void -PodCopy(volatile T* dst, const volatile T* src, size_t nelem) +PodCopy(volatile T* aDst, const volatile T* aSrc, size_t aNElem) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, - PointerRangeSize(src, static_cast(dst)) >= nelem); - MOZ_ASSERT_IF(dst < src, - PointerRangeSize(static_cast(dst), src) >= nelem); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); /* - * Volatile |dst| requires extra work, because it's undefined behavior to + * Volatile |aDst| requires extra work, because it's undefined behavior to * modify volatile objects using the mem* functions. Just write out the * loops manually, using operator= rather than memcpy for the same reason, * and let the compiler optimize to the extent it can. */ - for (const volatile T* srcend = src + nelem; src < srcend; src++, dst++) - *dst = *src; + for (const volatile T* srcend = aSrc + aNElem; + aSrc < srcend; + aSrc++, aDst++) { + *aDst = *aSrc; + } } /* - * Copy the contents of the array |src| into the array |dst|, both of size N. + * Copy the contents of the array |aSrc| into the array |aDst|, both of size N. * The arrays must not overlap! */ template static MOZ_ALWAYS_INLINE void -PodArrayCopy(T (&dst)[N], const T (&src)[N]) +PodArrayCopy(T (&aDst)[N], const T (&aSrc)[N]) { - PodCopy(dst, src, N); + PodCopy(aDst, aSrc, N); } /** - * Copy the memory for |nelem| T elements from |src| to |dst|. If the two - * memory ranges overlap, then the effect is as if the |nelem| elements are - * first copied from |src| to a temporary array, and then from the temporary - * array to |dst|. + * Copy the memory for |aNElem| T elements from |aSrc| to |aDst|. If the two + * memory ranges overlap, then the effect is as if the |aNElem| elements are + * first copied from |aSrc| to a temporary array, and then from the temporary + * array to |aDst|. */ template static MOZ_ALWAYS_INLINE void -PodMove(T* dst, const T* src, size_t nelem) +PodMove(T* aDst, const T* aSrc, size_t aNElem) { - MOZ_ASSERT(nelem <= SIZE_MAX / sizeof(T), + MOZ_ASSERT(aNElem <= SIZE_MAX / sizeof(T), "trying to move an impossible number of elements"); - memmove(dst, src, nelem * sizeof(T)); + memmove(aDst, aSrc, aNElem * sizeof(T)); } /** @@ -170,8 +180,9 @@ PodEqual(const T* one, const T* two, size_t len) const T* p1 = one; const T* p2 = two; for (; p1 < p1end; p1++, p2++) { - if (*p1 != *p2) + if (*p1 != *p2) { return false; + } } return true; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Range.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Range.h index 4e02d962b5..814a2821ad 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Range.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Range.h @@ -18,32 +18,26 @@ namespace mozilla { template class Range { - RangedPtr mStart; - RangedPtr mEnd; + const RangedPtr mStart; + const RangedPtr mEnd; - typedef void (Range::* ConvertibleToBool)(); - void nonNull() {} + typedef void (Range::* ConvertibleToBool)(); + void nonNull() {} - public: - Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} - Range(T* p, size_t len) - : mStart(p, p, p + len), - mEnd(p + len, p, p + len) - {} +public: + Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} + Range(T* aPtr, size_t aLength) + : mStart(aPtr, aPtr, aPtr + aLength), + mEnd(aPtr + aLength, aPtr, aPtr + aLength) + {} - RangedPtr start() const { return mStart; } - RangedPtr end() const { return mEnd; } - size_t length() const { return mEnd - mStart; } + RangedPtr start() const { return mStart; } + RangedPtr end() const { return mEnd; } + size_t length() const { return mEnd - mStart; } - T& operator[](size_t offset) { - return mStart[offset]; - } + T& operator[](size_t aOffset) const { return mStart[aOffset]; } - const T& operator[](size_t offset) const { - return mStart[offset]; - } - - operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } + operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RangedPtr.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RangedPtr.h index 561e564ded..4d94035b90 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RangedPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RangedPtr.h @@ -43,214 +43,240 @@ namespace mozilla { template class RangedPtr { - T* ptr; + T* mPtr; #ifdef DEBUG - T* const rangeStart; - T* const rangeEnd; + T* const mRangeStart; + T* const mRangeEnd; #endif - typedef void (RangedPtr::* ConvertibleToBool)(); - void nonNull() {} + typedef void (RangedPtr::* ConvertibleToBool)(); + void nonNull() {} - void checkSanity() { - MOZ_ASSERT(rangeStart <= ptr); - MOZ_ASSERT(ptr <= rangeEnd); - } + void checkSanity() + { + MOZ_ASSERT(mRangeStart <= mPtr); + MOZ_ASSERT(mPtr <= mRangeEnd); + } - /* Creates a new pointer for |p|, restricted to this pointer's range. */ - RangedPtr create(T *p) const { + /* Creates a new pointer for |aPtr|, restricted to this pointer's range. */ + RangedPtr create(T* aPtr) const + { #ifdef DEBUG - return RangedPtr(p, rangeStart, rangeEnd); + return RangedPtr(aPtr, mRangeStart, mRangeEnd); #else - return RangedPtr(p, nullptr, size_t(0)); + return RangedPtr(aPtr, nullptr, size_t(0)); #endif - } + } - uintptr_t asUintptr() const { return uintptr_t(ptr); } + uintptr_t asUintptr() const { return reinterpret_cast(mPtr); } - public: - RangedPtr(T* p, T* start, T* end) - : ptr(p) +public: + RangedPtr(T* aPtr, T* aStart, T* aEnd) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(start), rangeEnd(end) + , mRangeStart(aStart), mRangeEnd(aEnd) #endif - { - MOZ_ASSERT(rangeStart <= rangeEnd); - checkSanity(); - } - RangedPtr(T* p, T* start, size_t length) - : ptr(p) + { + MOZ_ASSERT(mRangeStart <= mRangeEnd); + checkSanity(); + } + RangedPtr(T* aPtr, T* aStart, size_t aLength) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(start), rangeEnd(start + length) + , mRangeStart(aStart), mRangeEnd(aStart + aLength) #endif - { - MOZ_ASSERT(length <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(uintptr_t(rangeStart) + length * sizeof(T) >= uintptr_t(rangeStart)); - checkSanity(); - } - - /* Equivalent to RangedPtr(p, p, length). */ - RangedPtr(T* p, size_t length) - : ptr(p) + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aPtr, aPtr, aLength). */ + RangedPtr(T* aPtr, size_t aLength) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(p), rangeEnd(p + length) + , mRangeStart(aPtr), mRangeEnd(aPtr + aLength) #endif - { - MOZ_ASSERT(length <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(uintptr_t(rangeStart) + length * sizeof(T) >= uintptr_t(rangeStart)); - checkSanity(); - } - - /* Equivalent to RangedPtr(arr, arr, N). */ - template - RangedPtr(T (&arr)[N]) - : ptr(arr) + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aArr, aArr, N). */ + template + RangedPtr(T (&aArr)[N]) + : mPtr(aArr) #ifdef DEBUG - , rangeStart(arr), rangeEnd(arr + N) + , mRangeStart(aArr), mRangeEnd(aArr + N) #endif - { - checkSanity(); - } - - T* get() const { - return ptr; - } - - operator ConvertibleToBool() const { return ptr ? &RangedPtr::nonNull : 0; } - - /* - * You can only assign one RangedPtr into another if the two pointers have - * the same valid range: - * - * char arr1[] = "hi"; - * char arr2[] = "bye"; - * RangedPtr p1(arr1, 2); - * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works - * p1 = RangedPtr(arr2, 3); // asserts - */ - RangedPtr& operator=(const RangedPtr& other) { - MOZ_ASSERT(rangeStart == other.rangeStart); - MOZ_ASSERT(rangeEnd == other.rangeEnd); - ptr = other.ptr; - checkSanity(); - return *this; - } - - RangedPtr operator+(size_t inc) { - MOZ_ASSERT(inc <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(asUintptr() + inc * sizeof(T) >= asUintptr()); - return create(ptr + inc); - } - - RangedPtr operator-(size_t dec) { - MOZ_ASSERT(dec <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(asUintptr() - dec * sizeof(T) <= asUintptr()); - return create(ptr - dec); - } - - /* - * You can assign a raw pointer into a RangedPtr if the raw pointer is - * within the range specified at creation. - */ - template - RangedPtr& operator=(U* p) { - *this = create(p); - return *this; - } - - template - RangedPtr& operator=(const RangedPtr& p) { - MOZ_ASSERT(rangeStart <= p.ptr); - MOZ_ASSERT(p.ptr <= rangeEnd); - ptr = p.ptr; - checkSanity(); - return *this; - } - - RangedPtr& operator++() { - return (*this += 1); - } - - RangedPtr operator++(int) { - RangedPtr rcp = *this; - ++*this; - return rcp; - } - - RangedPtr& operator--() { - return (*this -= 1); - } - - RangedPtr operator--(int) { - RangedPtr rcp = *this; - --*this; - return rcp; - } - - RangedPtr& operator+=(size_t inc) { - *this = *this + inc; - return *this; - } - - RangedPtr& operator-=(size_t dec) { - *this = *this - dec; - return *this; - } - - T& operator[](int index) const { - MOZ_ASSERT(size_t(index > 0 ? index : -index) <= size_t(-1) / sizeof(T)); - return *create(ptr + index); - } - - T& operator*() const { - return *ptr; - } - - template - bool operator==(const RangedPtr& other) const { - return ptr == other.ptr; - } - template - bool operator!=(const RangedPtr& other) const { - return !(*this == other); - } - - template - bool operator==(const U* u) const { - return ptr == u; - } - template - bool operator!=(const U* u) const { - return !(*this == u); - } - - template - bool operator<(const RangedPtr& other) const { - return ptr < other.ptr; - } - template - bool operator<=(const RangedPtr& other) const { - return ptr <= other.ptr; - } - - template - bool operator>(const RangedPtr& other) const { - return ptr > other.ptr; - } - template - bool operator>=(const RangedPtr& other) const { - return ptr >= other.ptr; - } - - size_t operator-(const RangedPtr& other) const { - MOZ_ASSERT(ptr >= other.ptr); - return PointerRangeSize(other.ptr, ptr); - } - - private: - RangedPtr() MOZ_DELETE; - T* operator&() MOZ_DELETE; + { + checkSanity(); + } + + T* get() const { return mPtr; } + + operator ConvertibleToBool() const { return mPtr ? &RangedPtr::nonNull : 0; } + + /* + * You can only assign one RangedPtr into another if the two pointers have + * the same valid range: + * + * char arr1[] = "hi"; + * char arr2[] = "bye"; + * RangedPtr p1(arr1, 2); + * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works + * p1 = RangedPtr(arr2, 3); // asserts + */ + RangedPtr& operator=(const RangedPtr& aOther) + { + MOZ_ASSERT(mRangeStart == aOther.mRangeStart); + MOZ_ASSERT(mRangeEnd == aOther.mRangeEnd); + mPtr = aOther.mPtr; + checkSanity(); + return *this; + } + + RangedPtr operator+(size_t aInc) + { + MOZ_ASSERT(aInc <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() + aInc * sizeof(T) >= asUintptr()); + return create(mPtr + aInc); + } + + RangedPtr operator-(size_t aDec) + { + MOZ_ASSERT(aDec <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() - aDec * sizeof(T) <= asUintptr()); + return create(mPtr - aDec); + } + + /* + * You can assign a raw pointer into a RangedPtr if the raw pointer is + * within the range specified at creation. + */ + template + RangedPtr& operator=(U* aPtr) + { + *this = create(aPtr); + return *this; + } + + template + RangedPtr& operator=(const RangedPtr& aPtr) + { + MOZ_ASSERT(mRangeStart <= aPtr.mPtr); + MOZ_ASSERT(aPtr.mPtr <= mRangeEnd); + mPtr = aPtr.mPtr; + checkSanity(); + return *this; + } + + RangedPtr& operator++() + { + return (*this += 1); + } + + RangedPtr operator++(int) + { + RangedPtr rcp = *this; + ++*this; + return rcp; + } + + RangedPtr& operator--() + { + return (*this -= 1); + } + + RangedPtr operator--(int) + { + RangedPtr rcp = *this; + --*this; + return rcp; + } + + RangedPtr& operator+=(size_t aInc) + { + *this = *this + aInc; + return *this; + } + + RangedPtr& operator-=(size_t aDec) + { + *this = *this - aDec; + return *this; + } + + T& operator[](int aIndex) const + { + MOZ_ASSERT(size_t(aIndex > 0 ? aIndex : -aIndex) <= size_t(-1) / sizeof(T)); + return *create(mPtr + aIndex); + } + + T& operator*() const + { + MOZ_ASSERT(mPtr >= mRangeStart); + MOZ_ASSERT(mPtr < mRangeEnd); + return *mPtr; + } + + template + bool operator==(const RangedPtr& aOther) const + { + return mPtr == aOther.mPtr; + } + template + bool operator!=(const RangedPtr& aOther) const + { + return !(*this == aOther); + } + + template + bool operator==(const U* u) const + { + return mPtr == u; + } + template + bool operator!=(const U* u) const + { + return !(*this == u); + } + + template + bool operator<(const RangedPtr& aOther) const + { + return mPtr < aOther.mPtr; + } + template + bool operator<=(const RangedPtr& aOther) const + { + return mPtr <= aOther.mPtr; + } + + template + bool operator>(const RangedPtr& aOther) const + { + return mPtr > aOther.mPtr; + } + template + bool operator>=(const RangedPtr& aOther) const + { + return mPtr >= aOther.mPtr; + } + + size_t operator-(const RangedPtr& aOther) const + { + MOZ_ASSERT(mPtr >= aOther.mPtr); + return PointerRangeSize(aOther.mPtr, mPtr); + } + +private: + RangedPtr() MOZ_DELETE; + T* operator&() MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ReentrancyGuard.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ReentrancyGuard.h index d589f368a2..557c61015e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ReentrancyGuard.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ReentrancyGuard.h @@ -18,38 +18,38 @@ namespace mozilla { /* Useful for implementing containers that assert non-reentrancy */ class ReentrancyGuard { - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER #ifdef DEBUG - bool& entered; + bool& mEntered; #endif - public: - template +public: + template #ifdef DEBUG - ReentrancyGuard(T& obj - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : entered(obj.entered) + ReentrancyGuard(T& aObj + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mEntered(aObj.mEntered) #else - ReentrancyGuard(T& - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + ReentrancyGuard(T& + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) #endif - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; #ifdef DEBUG - MOZ_ASSERT(!entered); - entered = true; + MOZ_ASSERT(!mEntered); + mEntered = true; #endif - } - ~ReentrancyGuard() - { + } + ~ReentrancyGuard() + { #ifdef DEBUG - entered = false; + mEntered = false; #endif - } + } - private: - ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; - void operator=(const ReentrancyGuard&) MOZ_DELETE; +private: + ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; + void operator=(const ReentrancyGuard&) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RefCountType.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RefCountType.h new file mode 100644 index 0000000000..e95a22a0ca --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RefCountType.h @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_RefCountType_h +#define mozilla_RefCountType_h + +#include + +/** + * MozRefCountType is Mozilla's reference count type. + * + * We use the same type to represent the refcount of RefCounted objects + * as well, in order to be able to use the leak detection facilities + * that are implemented by XPCOM. + * + * Note that this type is not in the mozilla namespace so that it is + * usable for both C and C++ code. + */ +typedef uintptr_t MozRefCountType; + +/* + * This is the return type for AddRef() and Release() in nsISupports. + * IUnknown of COM returns an unsigned long from equivalent functions. + * + * The following ifdef exists to maintain binary compatibility with + * IUnknown, the base interface in Microsoft COM. + */ +#ifdef XP_WIN +typedef unsigned long MozExternalRefCountType; +#else +typedef uint32_t MozExternalRefCountType; +#endif + +#endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RefPtr.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RefPtr.h index 72c7904554..4901067b4c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RefPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RefPtr.h @@ -12,7 +12,17 @@ #include "mozilla/Assertions.h" #include "mozilla/Atomics.h" #include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" +#include "mozilla/RefCountType.h" #include "mozilla/TypeTraits.h" +#if defined(MOZILLA_INTERNAL_API) +#include "nsXPCOM.h" +#endif + +#if defined(MOZILLA_INTERNAL_API) && \ + (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) +#define MOZ_REFCOUNTED_LEAK_CHECKING +#endif namespace mozilla { @@ -42,10 +52,37 @@ template OutParamRef byRef(RefPtr&); * state is represented in DEBUG builds by refcount==0xffffdead. This * state distinguishes use-before-ref (refcount==0) from * use-after-destroy (refcount==0xffffdead). + * + * Note that when deriving from RefCounted or AtomicRefCounted, you + * should add MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public + * section of your class, where ClassName is the name of your class. */ namespace detail { #ifdef DEBUG -static const int DEAD = 0xffffdead; +const MozRefCountType DEAD = 0xffffdead; +#endif + +// When building code that gets compiled into Gecko, try to use the +// trace-refcount leak logging facilities. +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +class RefCountLogger +{ +public: + static void logAddRef(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName, uint32_t aInstanceSize) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogAddRef(const_cast(aPointer), aRefCount, aTypeName, + aInstanceSize); + } + + static void logRelease(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogRelease(const_cast(aPointer), aRefCount, aTypeName); + } +}; #endif // This is used WeakPtr.h as well as this file. @@ -58,70 +95,122 @@ enum RefCountAtomicity template class RefCounted { - friend class RefPtr; + friend class RefPtr; - protected: - RefCounted() : refCnt(0) { } - ~RefCounted() { - MOZ_ASSERT(refCnt == detail::DEAD); - } +protected: + RefCounted() : mRefCnt(0) {} + ~RefCounted() { MOZ_ASSERT(mRefCnt == detail::DEAD); } - public: - // Compatibility with nsRefPtr. - void AddRef() const { - MOZ_ASSERT(refCnt >= 0); - ++refCnt; - } +public: + // Compatibility with nsRefPtr. + void AddRef() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) >= 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + ++mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + uint32_t size = static_cast(this)->typeSize(); + const void* ptr = static_cast(this); + MozRefCountType cnt = ++mRefCnt; + detail::RefCountLogger::logAddRef(ptr, cnt, type, size); +#endif + } - void Release() const { - MOZ_ASSERT(refCnt > 0); - if (0 == --refCnt) { + void Release() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) > 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + MozRefCountType cnt = --mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + const void* ptr = static_cast(this); + MozRefCountType cnt = --mRefCnt; + // Note: it's not safe to touch |this| after decrementing the refcount, + // except for below. + detail::RefCountLogger::logRelease(ptr, cnt, type); +#endif + if (0 == cnt) { + // Because we have atomically decremented the refcount above, only + // one thread can get a 0 count here, so as long as we can assume that + // everything else in the system is accessing this object through + // RefPtrs, it's safe to access |this| here. #ifdef DEBUG - refCnt = detail::DEAD; + mRefCnt = detail::DEAD; #endif - delete static_cast(this); - } + delete static_cast(this); } + } - // Compatibility with wtf::RefPtr. - void ref() { AddRef(); } - void deref() { Release(); } - int refCount() const { return refCnt; } - bool hasOneRef() const { - MOZ_ASSERT(refCnt > 0); - return refCnt == 1; - } + // Compatibility with wtf::RefPtr. + void ref() { AddRef(); } + void deref() { Release(); } + MozRefCountType refCount() const { return mRefCnt; } + bool hasOneRef() const + { + MOZ_ASSERT(mRefCnt > 0); + return mRefCnt == 1; + } - private: - mutable typename Conditional, int>::Type refCnt; +private: + mutable typename Conditional, + MozRefCountType>::Type mRefCnt; }; -} +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) \ + virtual const char* typeName() const { return #T; } \ + virtual size_t typeSize() const { return sizeof(*this); } +#else +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) +#endif + +// Note that this macro is expanded unconditionally because it declares only +// two small inline functions which will hopefully get eliminated by the linker +// in non-leak-checking builds. +#define MOZ_DECLARE_REFCOUNTED_TYPENAME(T) \ + const char* typeName() const { return #T; } \ + size_t typeSize() const { return sizeof(*this); } + +} // namespace detail template class RefCounted : public detail::RefCounted { - public: - ~RefCounted() { - static_assert(IsBaseOf::value, - "T must derive from RefCounted"); - } +public: + ~RefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from RefCounted"); + } }; +namespace external { + /** * AtomicRefCounted is like RefCounted, with an atomically updated * reference counter. + * + * NOTE: Please do not use this class, use NS_INLINE_DECL_THREADSAFE_REFCOUNTING + * instead. */ template -class AtomicRefCounted : public detail::RefCounted +class AtomicRefCounted : + public mozilla::detail::RefCounted { - public: - ~AtomicRefCounted() { - static_assert(IsBaseOf::value, - "T must derive from AtomicRefCounted"); - } +public: + ~AtomicRefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from AtomicRefCounted"); + } }; +} // namespace external + /** * RefPtr points to a refcounted thing that has AddRef and Release * methods to increase/decrease the refcount, respectively. After a @@ -135,73 +224,83 @@ class AtomicRefCounted : public detail::RefCounted template class RefPtr { - // To allow them to use unref() - friend class TemporaryRef; - friend class OutParamRef; + // To allow them to use unref() + friend class TemporaryRef; + friend class OutParamRef; - struct DontRef {}; + struct DontRef {}; - public: - RefPtr() : ptr(0) { } - RefPtr(const RefPtr& o) : ptr(ref(o.ptr)) {} - RefPtr(const TemporaryRef& o) : ptr(o.drop()) {} - RefPtr(T* t) : ptr(ref(t)) {} +public: + RefPtr() : mPtr(0) {} + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.mPtr)) {} + MOZ_IMPLICIT RefPtr(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + MOZ_IMPLICIT RefPtr(T* aVal) : mPtr(ref(aVal)) {} - template - RefPtr(const RefPtr& o) : ptr(ref(o.get())) {} + template + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.get())) {} - ~RefPtr() { unref(ptr); } + ~RefPtr() { unref(mPtr); } - RefPtr& operator=(const RefPtr& o) { - assign(ref(o.ptr)); - return *this; - } - RefPtr& operator=(const TemporaryRef& o) { - assign(o.drop()); - return *this; - } - RefPtr& operator=(T* t) { - assign(ref(t)); - return *this; - } + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.mPtr)); + return *this; + } + RefPtr& operator=(const TemporaryRef& aOther) + { + assign(aOther.drop()); + return *this; + } + RefPtr& operator=(T* aVal) + { + assign(ref(aVal)); + return *this; + } - template - RefPtr& operator=(const RefPtr& o) { - assign(ref(o.get())); - return *this; - } + template + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.get())); + return *this; + } - TemporaryRef forget() { - T* tmp = ptr; - ptr = 0; - return TemporaryRef(tmp, DontRef()); - } + TemporaryRef forget() + { + T* tmp = mPtr; + mPtr = nullptr; + return TemporaryRef(tmp, DontRef()); + } - T* get() const { return ptr; } - operator T*() const { return ptr; } - T* operator->() const { return ptr; } - T& operator*() const { return *ptr; } - template - operator TemporaryRef() { return TemporaryRef(ptr); } - - private: - void assign(T* t) { - unref(ptr); - ptr = t; - } + T* get() const { return mPtr; } + operator T*() const { return mPtr; } + T* operator->() const { return mPtr; } + T& operator*() const { return *mPtr; } + template + operator TemporaryRef() { return TemporaryRef(mPtr); } + +private: + void assign(T* aVal) + { + unref(mPtr); + mPtr = aVal; + } - T* ptr; + T* mPtr; - static MOZ_ALWAYS_INLINE T* ref(T* t) { - if (t) - t->AddRef(); - return t; + static MOZ_ALWAYS_INLINE T* ref(T* aVal) + { + if (aVal) { + aVal->AddRef(); } + return aVal; + } - static MOZ_ALWAYS_INLINE void unref(T* t) { - if (t) - t->Release(); + static MOZ_ALWAYS_INLINE void unref(T* aVal) + { + if (aVal) { + aVal->Release(); } + } }; /** @@ -213,33 +312,34 @@ class RefPtr template class TemporaryRef { - // To allow it to construct TemporaryRef from a bare T* - friend class RefPtr; + // To allow it to construct TemporaryRef from a bare T* + friend class RefPtr; - typedef typename RefPtr::DontRef DontRef; + typedef typename RefPtr::DontRef DontRef; - public: - TemporaryRef(T* t) : ptr(RefPtr::ref(t)) {} - TemporaryRef(const TemporaryRef& o) : ptr(o.drop()) {} +public: + MOZ_IMPLICIT TemporaryRef(T* aVal) : mPtr(RefPtr::ref(aVal)) {} + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} - template - TemporaryRef(const TemporaryRef& o) : ptr(o.drop()) {} + template + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} - ~TemporaryRef() { RefPtr::unref(ptr); } + ~TemporaryRef() { RefPtr::unref(mPtr); } - T* drop() const { - T* tmp = ptr; - ptr = 0; - return tmp; - } + T* drop() const + { + T* tmp = mPtr; + mPtr = nullptr; + return tmp; + } - private: - TemporaryRef(T* t, const DontRef&) : ptr(t) {} +private: + TemporaryRef(T* aVal, const DontRef&) : mPtr(aVal) {} - mutable T* ptr; + mutable T* mPtr; - TemporaryRef() MOZ_DELETE; - void operator=(const TemporaryRef&) MOZ_DELETE; + TemporaryRef() MOZ_DELETE; + void operator=(const TemporaryRef&) MOZ_DELETE; }; /** @@ -259,24 +359,25 @@ class TemporaryRef template class OutParamRef { - friend OutParamRef byRef(RefPtr&); + friend OutParamRef byRef(RefPtr&); - public: - ~OutParamRef() { - RefPtr::unref(refPtr.ptr); - refPtr.ptr = tmp; - } +public: + ~OutParamRef() + { + RefPtr::unref(mRefPtr.mPtr); + mRefPtr.mPtr = mTmp; + } - operator T**() { return &tmp; } + operator T**() { return &mTmp; } - private: - OutParamRef(RefPtr& p) : refPtr(p), tmp(p.get()) {} +private: + explicit OutParamRef(RefPtr& p) : mRefPtr(p), mTmp(p.get()) {} - RefPtr& refPtr; - T* tmp; + RefPtr& mRefPtr; + T* mTmp; - OutParamRef() MOZ_DELETE; - OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; + OutParamRef() MOZ_DELETE; + OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; }; /** @@ -284,9 +385,9 @@ class OutParamRef */ template OutParamRef -byRef(RefPtr& ptr) +byRef(RefPtr& aPtr) { - return OutParamRef(ptr); + return OutParamRef(aPtr); } } // namespace mozilla @@ -301,19 +402,21 @@ using namespace mozilla; struct Foo : public RefCounted { - Foo() : dead(false) { } - ~Foo() { - MOZ_ASSERT(!dead); - dead = true; - numDestroyed++; + MOZ_DECLARE_REFCOUNTED_TYPENAME(Foo) + Foo() : mDead(false) {} + ~Foo() + { + MOZ_ASSERT(!mDead); + mDead = true; + sNumDestroyed++; } - bool dead; - static int numDestroyed; + bool mDead; + static int sNumDestroyed; }; -int Foo::numDestroyed; +int Foo::sNumDestroyed; -struct Bar : public Foo { }; +struct Bar : public Foo {}; TemporaryRef NewFoo() @@ -364,25 +467,25 @@ main(int argc, char** argv) // This should blow up // Foo* f = new Foo(); delete f; - MOZ_ASSERT(0 == Foo::numDestroyed); + MOZ_ASSERT(0 == Foo::sNumDestroyed); { RefPtr f = new Foo(); MOZ_ASSERT(f->refCount() == 1); } - MOZ_ASSERT(1 == Foo::numDestroyed); + MOZ_ASSERT(1 == Foo::sNumDestroyed); { RefPtr f1 = NewFoo(); RefPtr f2(NewFoo()); - MOZ_ASSERT(1 == Foo::numDestroyed); + MOZ_ASSERT(1 == Foo::sNumDestroyed); } - MOZ_ASSERT(3 == Foo::numDestroyed); + MOZ_ASSERT(3 == Foo::sNumDestroyed); { RefPtr b = NewBar(); - MOZ_ASSERT(3 == Foo::numDestroyed); + MOZ_ASSERT(3 == Foo::sNumDestroyed); } - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); { RefPtr f1; @@ -390,56 +493,56 @@ main(int argc, char** argv) f1 = new Foo(); RefPtr f2(f1); RefPtr f3 = f2; - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); } - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); } - MOZ_ASSERT(5 == Foo::numDestroyed); + MOZ_ASSERT(5 == Foo::sNumDestroyed); { RefPtr f = new Foo(); f.forget(); - MOZ_ASSERT(6 == Foo::numDestroyed); + MOZ_ASSERT(6 == Foo::sNumDestroyed); } { RefPtr f = new Foo(); GetNewFoo(byRef(f)); - MOZ_ASSERT(7 == Foo::numDestroyed); + MOZ_ASSERT(7 == Foo::sNumDestroyed); } - MOZ_ASSERT(8 == Foo::numDestroyed); + MOZ_ASSERT(8 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetPassedFoo(byRef(f)); - MOZ_ASSERT(8 == Foo::numDestroyed); + MOZ_ASSERT(8 == Foo::sNumDestroyed); } - MOZ_ASSERT(9 == Foo::numDestroyed); + MOZ_ASSERT(9 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetNewFoo(&f); - MOZ_ASSERT(10 == Foo::numDestroyed); + MOZ_ASSERT(10 == Foo::sNumDestroyed); } - MOZ_ASSERT(11 == Foo::numDestroyed); + MOZ_ASSERT(11 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetPassedFoo(&f); - MOZ_ASSERT(11 == Foo::numDestroyed); + MOZ_ASSERT(11 == Foo::sNumDestroyed); } - MOZ_ASSERT(12 == Foo::numDestroyed); + MOZ_ASSERT(12 == Foo::sNumDestroyed); { RefPtr f1 = new Bar(); } - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); { RefPtr f = GetNullFoo(); - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); } - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); return 0; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RollingMean.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RollingMean.h index 5caee3bc83..5add14c879 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RollingMean.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/RollingMean.h @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-w idth: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -12,9 +13,7 @@ #include "mozilla/TypeTraits.h" #include "mozilla/Vector.h" -#include #include -#include namespace mozilla { @@ -30,78 +29,85 @@ namespace mozilla { template class RollingMean { - private: - size_t mInsertIndex; - size_t mMaxValues; - Vector mValues; - S mTotal; - - public: - static_assert(!IsFloatingPoint::value, - "floating-point types are unsupported due to rounding " - "errors"); - - RollingMean(size_t aMaxValues) - : mInsertIndex(0), - mMaxValues(aMaxValues), - mTotal(0) - { - MOZ_ASSERT(aMaxValues > 0); - } - - RollingMean& operator=(RollingMean&& aOther) { - MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); - this->~RollingMean(); - new(this) RollingMean(aOther.mMaxValues); - mInsertIndex = aOther.mInsertIndex; - mTotal = aOther.mTotal; - mValues.swap(aOther.mValues); - return *this; - } - - /** - * Insert a value into the rolling mean. - */ - bool insert(T aValue) { - MOZ_ASSERT(mValues.length() <= mMaxValues); - - if (mValues.length() == mMaxValues) { - mTotal = mTotal - mValues[mInsertIndex] + aValue; - mValues[mInsertIndex] = aValue; - } else { - if (!mValues.append(aValue)) - return false; - mTotal = mTotal + aValue; +private: + size_t mInsertIndex; + size_t mMaxValues; + Vector mValues; + S mTotal; + +public: + static_assert(!IsFloatingPoint::value, + "floating-point types are unsupported due to rounding " + "errors"); + + explicit RollingMean(size_t aMaxValues) + : mInsertIndex(0), + mMaxValues(aMaxValues), + mTotal(0) + { + MOZ_ASSERT(aMaxValues > 0); + } + + RollingMean& operator=(RollingMean&& aOther) + { + MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); + this->~RollingMean(); + new(this) RollingMean(aOther.mMaxValues); + mInsertIndex = aOther.mInsertIndex; + mTotal = aOther.mTotal; + mValues.swap(aOther.mValues); + return *this; + } + + /** + * Insert a value into the rolling mean. + */ + bool insert(T aValue) + { + MOZ_ASSERT(mValues.length() <= mMaxValues); + + if (mValues.length() == mMaxValues) { + mTotal = mTotal - mValues[mInsertIndex] + aValue; + mValues[mInsertIndex] = aValue; + } else { + if (!mValues.append(aValue)) { + return false; } - - mInsertIndex = (mInsertIndex + 1) % mMaxValues; - return true; - } - - /** - * Calculate the rolling mean. - */ - T mean() { - MOZ_ASSERT(!empty()); - return T(mTotal / mValues.length()); - } - - bool empty() { - return mValues.empty(); + mTotal = mTotal + aValue; } - /** - * Remove all values from the rolling mean. - */ - void clear() { - mValues.clear(); - mInsertIndex = 0; - mTotal = T(0); - } - - size_t maxValues() { - return mMaxValues; - } + mInsertIndex = (mInsertIndex + 1) % mMaxValues; + return true; + } + + /** + * Calculate the rolling mean. + */ + T mean() + { + MOZ_ASSERT(!empty()); + return T(mTotal / mValues.length()); + } + + bool empty() + { + return mValues.empty(); + } + + /** + * Remove all values from the rolling mean. + */ + void clear() + { + mValues.clear(); + mInsertIndex = 0; + mTotal = T(0); + } + + size_t maxValues() + { + return mMaxValues; + } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/SHA1.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/SHA1.h index b167648540..ddccaa67e7 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/SHA1.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/SHA1.h @@ -36,25 +36,26 @@ namespace mozilla { */ class SHA1Sum { - union { - uint32_t w[16]; /* input buffer */ - uint8_t b[64]; - } u; - uint64_t size; /* count of hashed bytes. */ - unsigned H[22]; /* 5 state variables, 16 tmp values, 1 extra */ - bool mDone; - - public: - MFBT_API SHA1Sum(); - - static const size_t HashSize = 20; - typedef uint8_t Hash[HashSize]; - - /* Add len bytes of dataIn to the data sequence being hashed. */ - MFBT_API void update(const void* dataIn, uint32_t len); - - /* Compute the final hash of all data into hashOut. */ - MFBT_API void finish(SHA1Sum::Hash& hashOut); + union + { + uint32_t mW[16]; /* input buffer */ + uint8_t mB[64]; + } mU; + uint64_t mSize; /* count of hashed bytes. */ + unsigned mH[22]; /* 5 state variables, 16 tmp values, 1 extra */ + bool mDone; + +public: + MFBT_API SHA1Sum(); + + static const size_t kHashSize = 20; + typedef uint8_t Hash[kHashSize]; + + /* Add len bytes of dataIn to the data sequence being hashed. */ + MFBT_API void update(const void* aData, uint32_t aLength); + + /* Compute the final hash of all data into hashOut. */ + MFBT_API void finish(SHA1Sum::Hash& aHashOut); }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Scoped.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Scoped.h index fc48584b3e..3f854d6375 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Scoped.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Scoped.h @@ -52,8 +52,10 @@ * the scope, graphics contexts, etc. */ +#include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/GuardObjects.h" +#include "mozilla/Move.h" #include "mozilla/NullPtr.h" namespace mozilla { @@ -62,7 +64,8 @@ namespace mozilla { * Scoped is a helper to create RAII wrappers * Type argument |Traits| is expected to have the following structure: * - * struct Traits { + * struct Traits + * { * // Define the type of the value stored in the wrapper * typedef value_type type; * // Returns the value corresponding to the uninitialized or freed state @@ -75,84 +78,102 @@ namespace mozilla { template class Scoped { - public: - typedef typename Traits::type Resource; +public: + typedef typename Traits::type Resource; - explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) - : value(Traits::empty()) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - explicit Scoped(const Resource& v - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : value(v) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - ~Scoped() { - Traits::release(value); - } + explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + : mValue(Traits::empty()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } - // Constant getter - operator const Resource&() const { return value; } - const Resource& operator->() const { return value; } - const Resource& get() const { return value; } - // Non-constant getter. - Resource& rwget() { return value; } + explicit Scoped(const Resource& aValue + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(aValue) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } - /* - * Forget the resource. - * - * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will - * have no effect at destruction (unless it is reset to another resource by - * |operator=|). - * - * @return The original resource. - */ - Resource forget() { - Resource tmp = value; - value = Traits::empty(); - return tmp; - } + /* Move constructor. */ + explicit Scoped(Scoped&& aOther + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(Move(aOther.mValue)) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + aOther.mValue = Traits::empty(); + } - /* - * Perform immediate clean-up of this |Scoped|. - * - * If this |Scoped| is currently empty, this method has no effect. - */ - void dispose() { - Traits::release(value); - value = Traits::empty(); - } + ~Scoped() { Traits::release(mValue); } - bool operator==(const Resource& other) const { - return value == other; - } + // Constant getter + operator const Resource&() const { return mValue; } + const Resource& operator->() const { return mValue; } + const Resource& get() const { return mValue; } + // Non-constant getter. + Resource& rwget() { return mValue; } - /* - * Replace the resource with another resource. - * - * Calling |operator=| has the side-effect of triggering clean-up. If you do - * not want to trigger clean-up, you should first invoke |forget|. - * - * @return this - */ - Scoped& operator=(const Resource& other) { - return reset(other); - } - Scoped& reset(const Resource& other) { - Traits::release(value); - value = other; - return *this; - } + /* + * Forget the resource. + * + * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will + * have no effect at destruction (unless it is reset to another resource by + * |operator=|). + * + * @return The original resource. + */ + Resource forget() + { + Resource tmp = mValue; + mValue = Traits::empty(); + return tmp; + } + + /* + * Perform immediate clean-up of this |Scoped|. + * + * If this |Scoped| is currently empty, this method has no effect. + */ + void dispose() + { + Traits::release(mValue); + mValue = Traits::empty(); + } + + bool operator==(const Resource& aOther) const { return mValue == aOther; } + + /* + * Replace the resource with another resource. + * + * Calling |operator=| has the side-effect of triggering clean-up. If you do + * not want to trigger clean-up, you should first invoke |forget|. + * + * @return this + */ + Scoped& operator=(const Resource& aOther) { return reset(aOther); } + + Scoped& reset(const Resource& aOther) + { + Traits::release(mValue); + mValue = aOther; + return *this; + } + + /* Move assignment operator. */ + Scoped& operator=(Scoped&& aRhs) + { + MOZ_ASSERT(&aRhs != this, "self-move-assignment not allowed"); + this->~Scoped(); + new(this) Scoped(Move(aRhs)); + return *this; + } - private: - explicit Scoped(const Scoped& value) MOZ_DELETE; - Scoped& operator=(const Scoped& value) MOZ_DELETE; +private: + explicit Scoped(const Scoped& aValue) MOZ_DELETE; + Scoped& operator=(const Scoped& aValue) MOZ_DELETE; - private: - Resource value; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +private: + Resource mValue; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER }; /* @@ -163,26 +184,38 @@ class Scoped * @param Traits A struct implementing clean-up. See the implementations * for more details. */ -#define SCOPED_TEMPLATE(name, Traits) \ -template \ -struct name : public mozilla::Scoped > \ -{ \ - typedef mozilla::Scoped > Super; \ - typedef typename Super::Resource Resource; \ - name& operator=(Resource ptr) { \ - Super::operator=(ptr); \ - return *this; \ - } \ - explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ - : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ - {} \ - explicit name(Resource ptr \ - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ - : Super(ptr MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ - {} \ - private: \ - explicit name(name& source) MOZ_DELETE; \ - name& operator=(name& source) MOZ_DELETE; \ +#define SCOPED_TEMPLATE(name, Traits) \ +template \ +struct name : public mozilla::Scoped > \ +{ \ + typedef mozilla::Scoped > Super; \ + typedef typename Super::Resource Resource; \ + name& operator=(Resource aRhs) \ + { \ + Super::operator=(aRhs); \ + return *this; \ + } \ + name& operator=(name&& aRhs) \ + { \ + Super::operator=(Move(aRhs)); \ + return *this; \ + } \ + explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ + : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ + {} \ + explicit name(Resource aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ + explicit name(name&& aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(Move(aRhs) \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ +private: \ + explicit name(name&) MOZ_DELETE; \ + name& operator=(name&) MOZ_DELETE; \ }; /* @@ -195,9 +228,9 @@ struct name : public mozilla::Scoped > \ template struct ScopedFreePtrTraits { - typedef T* type; - static T* empty() { return nullptr; } - static void release(T* ptr) { free(ptr); } + typedef T* type; + static T* empty() { return nullptr; } + static void release(T* aPtr) { free(aPtr); } }; SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) @@ -210,7 +243,7 @@ SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) template struct ScopedDeletePtrTraits : public ScopedFreePtrTraits { - static void release(T* ptr) { delete ptr; } + static void release(T* aPtr) { delete aPtr; } }; SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) @@ -223,7 +256,7 @@ SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) template struct ScopedDeleteArrayTraits : public ScopedFreePtrTraits { - static void release(T* ptr) { delete [] ptr; } + static void release(T* aPtr) { delete [] aPtr; } }; SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) @@ -250,21 +283,22 @@ SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) * } // file is closed with PR_Close here */ #define MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(name, Type, Deleter) \ -template <> inline void TypeSpecificDelete(Type * value) { Deleter(value); } \ +template <> inline void TypeSpecificDelete(Type* aValue) { Deleter(aValue); } \ typedef ::mozilla::TypeSpecificScopedPointer name; -template void TypeSpecificDelete(T * value); +template void TypeSpecificDelete(T* aValue); template struct TypeSpecificScopedPointerTraits { - typedef T* type; - const static type empty() { return nullptr; } - const static void release(type value) - { - if (value) - TypeSpecificDelete(value); + typedef T* type; + static type empty() { return nullptr; } + static void release(type aValue) + { + if (aValue) { + TypeSpecificDelete(aValue); } + } }; SCOPED_TEMPLATE(TypeSpecificScopedPointer, TypeSpecificScopedPointerTraits) diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/SplayTree.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/SplayTree.h index 58ba5432b6..a6d692266f 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/SplayTree.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/SplayTree.h @@ -23,18 +23,20 @@ class SplayTree; template class SplayTreeNode { - public: - template - friend class SplayTree; - - SplayTreeNode() - : left(nullptr), right(nullptr), parent(nullptr) - {} - - private: - T* left; - T* right; - T* parent; +public: + template + friend class SplayTree; + + SplayTreeNode() + : mLeft(nullptr) + , mRight(nullptr) + , mParent(nullptr) + {} + +private: + T* mLeft; + T* mRight; + T* mParent; }; @@ -51,232 +53,242 @@ class SplayTreeNode template class SplayTree { - T* root; - T* freeList; + T* mRoot; - public: - SplayTree() - : root(nullptr), freeList(nullptr) - {} - - bool empty() const { - return !root; - } +public: + SplayTree() + : mRoot(nullptr) + {} - T* find(const T& v) - { - if (empty()) - return nullptr; + bool empty() const + { + return !mRoot; + } - T* last = lookup(v); - splay(last); - checkCoherency(root, nullptr); - return Comparator::compare(v, *last) == 0 ? last : nullptr; + T* find(const T& aValue) + { + if (empty()) { + return nullptr; } - bool insert(T* v) - { - MOZ_ASSERT(!find(*v), "Duplicate elements are not allowed."); - - if (!root) { - root = v; - return true; - } - T* last = lookup(*v); - int cmp = Comparator::compare(*v, *last); + T* last = lookup(aValue); + splay(last); + checkCoherency(mRoot, nullptr); + return Comparator::compare(aValue, *last) == 0 ? last : nullptr; + } - T** parentPointer = (cmp < 0) ? &last->left : &last->right; - MOZ_ASSERT(!*parentPointer); - *parentPointer = v; - v->parent = last; + bool insert(T* aValue) + { + MOZ_ASSERT(!find(*aValue), "Duplicate elements are not allowed."); - splay(v); - checkCoherency(root, nullptr); + if (!mRoot) { + mRoot = aValue; return true; } - - T* remove(const T& v) - { - T* last = lookup(v); - MOZ_ASSERT(last, "This tree must contain the element being removed."); - MOZ_ASSERT(Comparator::compare(v, *last) == 0); - - // Splay the tree so that the item to remove is the root. - splay(last); - MOZ_ASSERT(last == root); - - // Find another node which can be swapped in for the root: either the - // rightmost child of the root's left, or the leftmost child of the - // root's right. - T* swap; - T* swapChild; - if (root->left) { - swap = root->left; - while (swap->right) - swap = swap->right; - swapChild = swap->left; - } else if (root->right) { - swap = root->right; - while (swap->left) - swap = swap->left; - swapChild = swap->right; - } else { - T* result = root; - root = nullptr; - return result; - } - - // The selected node has at most one child, in swapChild. Detach it - // from the subtree by replacing it with that child. - if (swap == swap->parent->left) - swap->parent->left = swapChild; - else - swap->parent->right = swapChild; - if (swapChild) - swapChild->parent = swap->parent; - - // Make the selected node the new root. - root = swap; - root->parent = nullptr; - root->left = last->left; - root->right = last->right; - if (root->left) { - root->left->parent = root; + T* last = lookup(*aValue); + int cmp = Comparator::compare(*aValue, *last); + + T** parentPointer = (cmp < 0) ? &last->mLeft : &last->mRight; + MOZ_ASSERT(!*parentPointer); + *parentPointer = aValue; + aValue->mParent = last; + + splay(aValue); + checkCoherency(mRoot, nullptr); + return true; + } + + T* remove(const T& aValue) + { + T* last = lookup(aValue); + MOZ_ASSERT(last, "This tree must contain the element being removed."); + MOZ_ASSERT(Comparator::compare(aValue, *last) == 0); + + // Splay the tree so that the item to remove is the root. + splay(last); + MOZ_ASSERT(last == mRoot); + + // Find another node which can be swapped in for the root: either the + // rightmost child of the root's left, or the leftmost child of the + // root's right. + T* swap; + T* swapChild; + if (mRoot->mLeft) { + swap = mRoot->mLeft; + while (swap->mRight) { + swap = swap->mRight; } - if (root->right) { - root->right->parent = root; + swapChild = swap->mLeft; + } else if (mRoot->mRight) { + swap = mRoot->mRight; + while (swap->mLeft) { + swap = swap->mLeft; } - - checkCoherency(root, nullptr); - return last; + swapChild = swap->mRight; + } else { + T* result = mRoot; + mRoot = nullptr; + return result; } - T* removeMin() - { - MOZ_ASSERT(root, "No min to remove!"); - - T* min = root; - while (min->left) - min = min->left; - return remove(*min); + // The selected node has at most one child, in swapChild. Detach it + // from the subtree by replacing it with that child. + if (swap == swap->mParent->mLeft) { + swap->mParent->mLeft = swapChild; + } else { + swap->mParent->mRight = swapChild; } - - private: - /** - * Returns the node in this comparing equal to |v|, or a node just greater or - * just less than |v| if there is no such node. - */ - T* lookup(const T& v) - { - MOZ_ASSERT(!empty()); - - T* node = root; - T* parent; - do { - parent = node; - int c = Comparator::compare(v, *node); - if (c == 0) - return node; - else if (c < 0) - node = node->left; - else - node = node->right; - } while (node); - return parent; + if (swapChild) { + swapChild->mParent = swap->mParent; } - /** - * Rotate the tree until |node| is at the root of the tree. Performing - * the rotations in this fashion preserves the amortized balancing of - * the tree. - */ - void splay(T* node) - { - MOZ_ASSERT(node); - - while (node != root) { - T* parent = node->parent; - if (parent == root) { - // Zig rotation. - rotate(node); - MOZ_ASSERT(node == root); - return; - } - T* grandparent = parent->parent; - if ((parent->left == node) == (grandparent->left == parent)) { - // Zig-zig rotation. - rotate(parent); - rotate(node); - } else { - // Zig-zag rotation. - rotate(node); - rotate(node); - } - } + // Make the selected node the new root. + mRoot = swap; + mRoot->mParent = nullptr; + mRoot->mLeft = last->mLeft; + mRoot->mRight = last->mRight; + if (mRoot->mLeft) { + mRoot->mLeft->mParent = mRoot; } + if (mRoot->mRight) { + mRoot->mRight->mParent = mRoot; + } + + checkCoherency(mRoot, nullptr); + return last; + } - void rotate(T* node) - { - // Rearrange nodes so that node becomes the parent of its current - // parent, while preserving the sortedness of the tree. - T* parent = node->parent; - if (parent->left == node) { - // x y - // y c ==> a x - // a b b c - parent->left = node->right; - if (node->right) - node->right->parent = parent; - node->right = parent; + T* removeMin() + { + MOZ_ASSERT(mRoot, "No min to remove!"); + + T* min = mRoot; + while (min->mLeft) { + min = min->mLeft; + } + return remove(*min); + } + +private: + /** + * Returns the node in this comparing equal to |aValue|, or a node just + * greater or just less than |aValue| if there is no such node. + */ + T* lookup(const T& aValue) + { + MOZ_ASSERT(!empty()); + + T* node = mRoot; + T* parent; + do { + parent = node; + int c = Comparator::compare(aValue, *node); + if (c == 0) { + return node; + } else if (c < 0) { + node = node->mLeft; } else { - MOZ_ASSERT(parent->right == node); - // x y - // a y ==> x c - // b c a b - parent->right = node->left; - if (node->left) - node->left->parent = parent; - node->left = parent; + node = node->mRight; } - node->parent = parent->parent; - parent->parent = node; - if (T* grandparent = node->parent) { - if (grandparent->left == parent) - grandparent->left = node; - else - grandparent->right = node; + } while (node); + return parent; + } + + /** + * Rotate the tree until |node| is at the root of the tree. Performing + * the rotations in this fashion preserves the amortized balancing of + * the tree. + */ + void splay(T* aNode) + { + MOZ_ASSERT(aNode); + + while (aNode != mRoot) { + T* parent = aNode->mParent; + if (parent == mRoot) { + // Zig rotation. + rotate(aNode); + MOZ_ASSERT(aNode == mRoot); + return; + } + T* grandparent = parent->mParent; + if ((parent->mLeft == aNode) == (grandparent->mLeft == parent)) { + // Zig-zig rotation. + rotate(parent); + rotate(aNode); } else { - root = node; + // Zig-zag rotation. + rotate(aNode); + rotate(aNode); } } - - T* checkCoherency(T* node, T* minimum) - { -#ifdef DEBUG - MOZ_ASSERT_IF(root, !root->parent); - if (!node) { - MOZ_ASSERT(!root); - return nullptr; + } + + void rotate(T* aNode) + { + // Rearrange nodes so that aNode becomes the parent of its current + // parent, while preserving the sortedness of the tree. + T* parent = aNode->mParent; + if (parent->mLeft == aNode) { + // x y + // y c ==> a x + // a b b c + parent->mLeft = aNode->mRight; + if (aNode->mRight) { + aNode->mRight->mParent = parent; } - MOZ_ASSERT_IF(!node->parent, node == root); - MOZ_ASSERT_IF(minimum, Comparator::compare(*minimum, *node) < 0); - if (node->left) { - MOZ_ASSERT(node->left->parent == node); - T* leftMaximum = checkCoherency(node->left, minimum); - MOZ_ASSERT(Comparator::compare(*leftMaximum, *node) < 0); + aNode->mRight = parent; + } else { + MOZ_ASSERT(parent->mRight == aNode); + // x y + // a y ==> x c + // b c a b + parent->mRight = aNode->mLeft; + if (aNode->mLeft) { + aNode->mLeft->mParent = parent; } - if (node->right) { - MOZ_ASSERT(node->right->parent == node); - return checkCoherency(node->right, node); + aNode->mLeft = parent; + } + aNode->mParent = parent->mParent; + parent->mParent = aNode; + if (T* grandparent = aNode->mParent) { + if (grandparent->mLeft == parent) { + grandparent->mLeft = aNode; + } else { + grandparent->mRight = aNode; } - return node; -#else + } else { + mRoot = aNode; + } + } + + T* checkCoherency(T* aNode, T* aMinimum) + { +#ifdef DEBUG + MOZ_ASSERT_IF(mRoot, !mRoot->mParent); + if (!aNode) { + MOZ_ASSERT(!mRoot); return nullptr; -#endif } + MOZ_ASSERT_IF(!aNode->mParent, aNode == mRoot); + MOZ_ASSERT_IF(aMinimum, Comparator::compare(*aMinimum, *aNode) < 0); + if (aNode->mLeft) { + MOZ_ASSERT(aNode->mLeft->mParent == aNode); + T* leftMaximum = checkCoherency(aNode->mLeft, aMinimum); + MOZ_ASSERT(Comparator::compare(*leftMaximum, *aNode) < 0); + } + if (aNode->mRight) { + MOZ_ASSERT(aNode->mRight->mParent == aNode); + return checkCoherency(aNode->mRight, aNode); + } + return aNode; +#else + return nullptr; +#endif + } - SplayTree(const SplayTree&) MOZ_DELETE; - void operator=(const SplayTree&) MOZ_DELETE; + SplayTree(const SplayTree&) MOZ_DELETE; + void operator=(const SplayTree&) MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TaggedAnonymousMemory.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TaggedAnonymousMemory.h new file mode 100644 index 0000000000..d26b06dfb4 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TaggedAnonymousMemory.h @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Some Linux kernels -- specifically, newer versions of Android and +// some B2G devices -- have a feature for assigning names to ranges of +// anonymous memory (i.e., memory that doesn't have a "name" in the +// form of an underlying mapped file). These names are reported in +// /proc//smaps alongside system-level memory usage information +// such as Proportional Set Size (memory usage adjusted for sharing +// between processes), which allows reporting this information at a +// finer granularity than would otherwise be possible (e.g., +// separating malloc() heap from JS heap). +// +// Existing memory can be tagged with MozTagAnonymousMemory(); it will +// tag the range of complete pages containing the given interval, so +// the results may be inexact if the range isn't page-aligned. +// MozTaggedAnonymousMmap() can be used like mmap() with an extra +// parameter, and will tag the returned memory if the mapping was +// successful (and if it was in fact anonymous). +// +// NOTE: The pointer given as the "tag" argument MUST remain valid as +// long as the mapping exists. The referenced string is read when +// /proc//smaps or /proc//maps is read, not when the tag is +// established, so freeing it or changing its contents will have +// unexpected results. Using a static string is probably best. +// +// Also note that this header can be used by both C and C++ code. + +#ifndef mozilla_TaggedAnonymousMemory_h +#define mozilla_TaggedAnonymousMemory_h + +#ifndef XP_WIN + +#include +#include + +#include "mozilla/Types.h" + +#ifdef ANDROID + +#ifdef __cplusplus +extern "C" { +#endif + +MFBT_API void +MozTagAnonymousMemory(const void* aPtr, size_t aLength, const char* aTag); + +MFBT_API void* +MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt, int aFlags, + int aFd, off_t aOffset, const char* aTag); + +MFBT_API int +MozTaggedMemoryIsSupported(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#else // ANDROID + +static inline void +MozTagAnonymousMemory(const void* aPtr, size_t aLength, const char* aTag) +{ +} + +static inline void* +MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt, int aFlags, + int aFd, off_t aOffset, const char* aTag) +{ + return mmap(aAddr, aLength, aProt, aFlags, aFd, aOffset); +} + +static inline int +MozTaggedMemoryIsSupported(void) +{ + return 0; +} + +#endif // ANDROID + +#endif // !XP_WIN + +#endif // mozilla_TaggedAnonymousMemory_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TemplateLib.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TemplateLib.h index 50275fdadb..ea12c18b2b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TemplateLib.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TemplateLib.h @@ -28,19 +28,19 @@ namespace tl { template struct Min { - static const size_t value = I < J ? I : J; + static const size_t value = I < J ? I : J; }; template struct Max { - static const size_t value = I > J ? I : J; + static const size_t value = I > J ? I : J; }; /** Compute floor(log2(i)). */ template struct FloorLog2 { - static const size_t value = 1 + FloorLog2::value; + static const size_t value = 1 + FloorLog2::value; }; template<> struct FloorLog2<0> { /* Error */ }; template<> struct FloorLog2<1> { static const size_t value = 0; }; @@ -49,26 +49,26 @@ template<> struct FloorLog2<1> { static const size_t value = 0; }; template struct CeilingLog2 { - static const size_t value = FloorLog2<2 * I - 1>::value; + static const size_t value = FloorLog2<2 * I - 1>::value; }; /** Round up to the nearest power of 2. */ template struct RoundUpPow2 { - static const size_t value = size_t(1) << CeilingLog2::value; + static const size_t value = size_t(1) << CeilingLog2::value; }; template<> struct RoundUpPow2<0> { - static const size_t value = 1; + static const size_t value = 1; }; /** Compute the number of bits in the given unsigned type. */ template struct BitSize { - static const size_t value = sizeof(T) * CHAR_BIT; + static const size_t value = sizeof(T) * CHAR_BIT; }; /** @@ -78,17 +78,18 @@ struct BitSize template struct NBitMask { - // Assert the precondition. On success this evaluates to 0. Otherwise it - // triggers divide-by-zero at compile time: a guaranteed compile error in - // C++11, and usually one in C++98. Add this value to |value| to assure - // its computation. - static const size_t checkPrecondition = 0 / size_t(N < BitSize::value); - static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; + // Assert the precondition. On success this evaluates to 0. Otherwise it + // triggers divide-by-zero at compile time: a guaranteed compile error in + // C++11, and usually one in C++98. Add this value to |value| to assure + // its computation. + static const size_t checkPrecondition = + 0 / size_t(N < BitSize::value); + static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; }; template<> struct NBitMask::value> { - static const size_t value = size_t(-1); + static const size_t value = size_t(-1); }; /** @@ -98,8 +99,8 @@ struct NBitMask::value> template struct MulOverflowMask { - static const size_t value = - ~NBitMask::value - CeilingLog2::value>::value; + static const size_t value = + ~NBitMask::value - CeilingLog2::value>::value; }; template<> struct MulOverflowMask<0> { /* Error */ }; template<> struct MulOverflowMask<1> { static const size_t value = 0; }; diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ThreadLocal.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ThreadLocal.h index 6df109821f..28015de22e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ThreadLocal.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ThreadLocal.h @@ -54,7 +54,10 @@ typedef sig_atomic_t sig_safe_t; * * API usage: * - * // Create a TLS item + * // Create a TLS item. + * // + * // Note that init() should be invoked exactly once, before any usage of set() + * // or get(). * mozilla::ThreadLocal tlsKey; * if (!tlsKey.init()) { * // deal with the error @@ -70,30 +73,29 @@ template class ThreadLocal { #if defined(XP_WIN) - typedef unsigned long key_t; + typedef unsigned long key_t; #else - typedef pthread_key_t key_t; + typedef pthread_key_t key_t; #endif - union Helper { - void* ptr; - T value; - }; + union Helper + { + void* mPtr; + T mValue; + }; - public: - MOZ_WARN_UNUSED_RESULT inline bool init(); +public: + MOZ_WARN_UNUSED_RESULT inline bool init(); - inline T get() const; + inline T get() const; - inline void set(const T value); + inline void set(const T aValue); - bool initialized() const { - return inited; - } + bool initialized() const { return mInited; } - private: - key_t key; - bool inited; +private: + key_t mKey; + bool mInited; }; template @@ -105,12 +107,12 @@ ThreadLocal::init() "a pointer"); MOZ_ASSERT(!initialized()); #ifdef XP_WIN - key = TlsAlloc(); - inited = key != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES + mKey = TlsAlloc(); + mInited = mKey != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES #else - inited = !pthread_key_create(&key, nullptr); + mInited = !pthread_key_create(&mKey, nullptr); #endif - return inited; + return mInited; } template @@ -120,28 +122,28 @@ ThreadLocal::get() const MOZ_ASSERT(initialized()); Helper h; #ifdef XP_WIN - h.ptr = TlsGetValue(key); + h.mPtr = TlsGetValue(mKey); #else - h.ptr = pthread_getspecific(key); + h.mPtr = pthread_getspecific(mKey); #endif - return h.value; + return h.mValue; } template inline void -ThreadLocal::set(const T value) +ThreadLocal::set(const T aValue) { MOZ_ASSERT(initialized()); Helper h; - h.value = value; - bool succeeded; + h.mValue = aValue; #ifdef XP_WIN - succeeded = TlsSetValue(key, h.ptr); + bool succeeded = TlsSetValue(mKey, h.mPtr); #else - succeeded = !pthread_setspecific(key, h.ptr); + bool succeeded = !pthread_setspecific(mKey, h.mPtr); #endif - if (!succeeded) + if (!succeeded) { MOZ_CRASH(); + } } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ToString.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ToString.h new file mode 100644 index 0000000000..f11cad5cb6 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/ToString.h @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Utilities for converting an object to a string representation. */ + +#ifndef mozilla_ToString_h +#define mozilla_ToString_h + +#include +#include + +namespace mozilla { + +/** + * A convenience function for converting an object to a string representation. + * Supports any object which can be streamed to an std::ostream. + */ +template +std::string +ToString(const T& aValue) +{ + std::ostringstream stream; + stream << aValue; + return stream.str(); +} + +} // namespace mozilla + +#endif /* mozilla_ToString_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TypeTraits.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TypeTraits.h index 1ccd0c85d1..515c68d94e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TypeTraits.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TypeTraits.h @@ -9,6 +9,8 @@ #ifndef mozilla_TypeTraits_h #define mozilla_TypeTraits_h +#include "mozilla/Types.h" + /* * These traits are approximate copies of the traits and semantics from C++11's * header. Don't add traits not in that header! When all @@ -32,9 +34,9 @@ template struct RemoveCV; template struct IntegralConstant { - static const T value = Value; - typedef T ValueType; - typedef IntegralConstant Type; + static const T value = Value; + typedef T ValueType; + typedef IntegralConstant Type; }; /** Convenient aliases. */ @@ -47,6 +49,27 @@ typedef IntegralConstant FalseType; namespace detail { +template +struct IsVoidHelper : FalseType {}; + +template<> +struct IsVoidHelper : TrueType {}; + +} // namespace detail + +/** + * IsVoid determines whether a type is void. + * + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true; + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true. + */ +template +struct IsVoid : detail::IsVoidHelper::Type> {}; + +namespace detail { + template struct IsIntegralHelper : FalseType {}; @@ -114,6 +137,31 @@ struct IsFloatingPoint : detail::IsFloatingPointHelper::Type> {}; +namespace detail { + +template +struct IsArrayHelper : FalseType {}; + +template +struct IsArrayHelper : TrueType {}; + +template +struct IsArrayHelper : TrueType {}; + +} // namespace detail + +/** + * IsArray determines whether a type is an array type, of known or unknown + * length. + * + * mozilla::IsArray::value is false; + * mozilla::IsArray::value is true; + * mozilla::IsArray::value is true. + */ +template +struct IsArray : detail::IsArrayHelper::Type> +{}; + /** * IsPointer determines whether a type is a pointer type (but not a pointer-to- * member type). @@ -130,6 +178,40 @@ struct IsPointer : FalseType {}; template struct IsPointer : TrueType {}; +/** + * IsLvalueReference determines whether a type is an lvalue reference. + * + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is true; + * mozilla::IsLvalueReference::value is false. + */ +template +struct IsLvalueReference : FalseType {}; + +template +struct IsLvalueReference : TrueType {}; + +/** + * IsRvalueReference determines whether a type is an rvalue reference. + * + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is true. + */ +template +struct IsRvalueReference : FalseType {}; + +template +struct IsRvalueReference : TrueType {}; + namespace detail { // __is_enum is a supported extension across all of our supported compilers. @@ -152,8 +234,55 @@ struct IsEnum : detail::IsEnumHelper::Type> {}; +namespace detail { + +// __is_class is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx +template +struct IsClassHelper + : IntegralConstant +{}; + +} // namespace detail + +/** + * IsClass determines whether a type is a class type (but not a union). + * + * struct S {}; + * union U {}; + * mozilla::IsClass::value is false; + * mozilla::IsClass::value is true; + * mozilla::IsClass::value is false; + */ +template +struct IsClass + : detail::IsClassHelper::Type> +{}; + /* 20.9.4.2 Composite type traits [meta.unary.comp] */ +/** + * IsReference determines whether a type is an lvalue or rvalue reference. + * + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true. + */ +template +struct IsReference + : IntegralConstant::value || IsRvalueReference::value> +{}; + /** * IsArithmetic determines whether a type is arithmetic. A type is arithmetic * iff it is an integral type or a floating point type. @@ -228,26 +357,90 @@ template struct IsPod : TrueType {}; namespace detail { -template::value> -struct IsSignedHelper; - +// __is_empty is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx template -struct IsSignedHelper : TrueType {}; +struct IsEmptyHelper + : IntegralConstant::value && __is_empty(T)> +{}; +} // namespace detail + +/** + * IsEmpty determines whether a type is a class (but not a union) that is empty. + * + * A class is empty iff it and all its base classes have no non-static data + * members (except bit-fields of length 0) and no virtual member functions, and + * no base class is empty or a virtual base class. + * + * Intuitively, empty classes don't have any data that has to be stored in + * instances of those classes. (The size of the class must still be non-zero, + * because distinct array elements of any type must have different addresses. + * However, if the Empty Base Optimization is implemented by the compiler [most + * compilers implement it, and in certain cases C++11 requires it], the size of + * a class inheriting from an empty |Base| class need not be inflated by + * |sizeof(Base)|.) And intuitively, non-empty classes have data members and/or + * vtable pointers that must be stored in each instance for proper behavior. + * + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * union U1 { int x; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct E1 {}; + * struct E2 { int : 0 }; + * struct E3 : E1 {}; + * struct E4 : E2 {}; + * static_assert(mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value, + * "all empty"); + * union U2 { E1 e1; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct NE1 { int x; }; + * struct NE2 : virtual E1 {}; + * struct NE3 : E2 { virtual ~NE3() {} }; + * struct NE4 { virtual void f() {} }; + * static_assert(!mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value, + * "all empty"); + */ template -struct IsSignedHelper - : IntegralConstant::value && T(-1) < T(1)> +struct IsEmpty : detail::IsEmptyHelper::Type> {}; + +namespace detail { + +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> +struct IsSignedHelper; + +// Floating point is signed. +template +struct IsSignedHelper : TrueType {}; + +// Integral is conditionally signed. +template +struct IsSignedHelper + : IntegralConstant +{}; + +// Non-floating point, non-integral is not signed. +template +struct IsSignedHelper : FalseType {}; + } // namespace detail /** * IsSigned determines whether a type is a signed arithmetic type. |char| is * considered a signed type if it has the same representation as |signed char|. * - * Don't use this if the type might be user-defined! You might or might not get - * a compile error, depending. - * * mozilla::IsSigned::value is true; * mozilla::IsSigned::value is false; * mozilla::IsSigned::value is false; @@ -258,28 +451,32 @@ struct IsSigned : detail::IsSignedHelper {}; namespace detail { -template::value> +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> struct IsUnsignedHelper; -template -struct IsUnsignedHelper : FalseType {}; +// Floating point is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; -template -struct IsUnsignedHelper +// Integral is conditionally unsigned. +template +struct IsUnsignedHelper : IntegralConstant::value && - (IsSame::Type, bool>::value || - T(1) < T(-1))> + (IsSame::value || bool(NoCV(1) < NoCV(-1)))> {}; +// Non-floating point, non-integral is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; + } // namespace detail /** * IsUnsigned determines whether a type is an unsigned arithmetic type. * - * Don't use this if the type might be user-defined! You might or might not get - * a compile error, depending. - * * mozilla::IsUnsigned::value is false; * mozilla::IsUnsigned::value is true; * mozilla::IsUnsigned::value is true; @@ -310,6 +507,13 @@ struct IsSame : TrueType {}; namespace detail { +#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) + +template +struct BaseOfTester : IntegralConstant {}; + +#else + // The trickery used to implement IsBaseOf here makes it possible to use it for // the cases of private and multiple inheritance. This code was inspired by the // sample code here: @@ -318,35 +522,35 @@ namespace detail { template struct BaseOfHelper { - public: - operator Base*() const; - operator Derived*(); +public: + operator Base*() const; + operator Derived*(); }; template struct BaseOfTester { - private: - template - static char test(Derived*, T); - static int test(Base*, int); - - public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); }; template struct BaseOfTester { - private: - template - static char test(Derived*, T); - static int test(Base*, int); - - public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); }; template @@ -358,6 +562,8 @@ struct BaseOfTester : TrueType {}; template struct BaseOfTester : TrueType {}; +#endif + } /* namespace detail */ /* @@ -382,18 +588,18 @@ namespace detail { template struct ConvertibleTester { - private: - static From create(); +private: + static From create(); - template - static char test(To to); + template + static char test(To to); - template - static int test(...); + template + static int test(...); - public: - static const bool value = - sizeof(test(create())) == sizeof(char); +public: + static const bool value = + sizeof(test(create())) == sizeof(char); }; } // namespace detail @@ -424,16 +630,6 @@ struct IsConvertible : IntegralConstant::value> {}; -/** - * Is IsLvalueReference is true if its template param is T& and is false if - * its type is T or T&&. - */ -template -struct IsLvalueReference : FalseType {}; - -template -struct IsLvalueReference : TrueType {}; - /* 20.9.7 Transformations between types [meta.trans] */ /* 20.9.7.1 Const-volatile modifications [meta.trans.cv] */ @@ -449,13 +645,13 @@ struct IsLvalueReference : TrueType {}; template struct RemoveConst { - typedef T Type; + typedef T Type; }; template struct RemoveConst { - typedef T Type; + typedef T Type; }; /** @@ -469,13 +665,13 @@ struct RemoveConst template struct RemoveVolatile { - typedef T Type; + typedef T Type; }; template struct RemoveVolatile { - typedef T Type; + typedef T Type; }; /** @@ -489,7 +685,7 @@ struct RemoveVolatile template struct RemoveCV { - typedef typename RemoveConst::Type>::Type Type; + typedef typename RemoveConst::Type>::Type Type; }; /* 20.9.7.2 Reference modifications [meta.trans.ref] */ @@ -505,29 +701,69 @@ struct RemoveCV template struct RemoveReference { - typedef T Type; + typedef T Type; }; template struct RemoveReference { - typedef T Type; + typedef T Type; }; template struct RemoveReference { - typedef T Type; + typedef T Type; }; +template +struct Conditional; + +namespace detail { + +enum Voidness { TIsVoid, TIsNotVoid }; + +template::value ? TIsVoid : TIsNotVoid> +struct AddLvalueReferenceHelper; + +template +struct AddLvalueReferenceHelper +{ + typedef void Type; +}; + +template +struct AddLvalueReferenceHelper +{ + typedef T& Type; +}; + +} // namespace detail + +/** + * AddLvalueReference adds an lvalue & reference to T if one isn't already + * present. (Note: adding an lvalue reference to an rvalue && reference in + * essence replaces the && with a &&, per C+11 reference collapsing rules. For + * example, int&& would become int&.) + * + * The final computed type will only *not* be an lvalue reference if T is void. + * + * mozilla::AddLvalueReference::Type is int&; + * mozilla::AddLvalueRference::Type is volatile int&; + * mozilla::AddLvalueReference::Type is void*&; + * mozilla::AddLvalueReference::Type is void; + * mozilla::AddLvalueReference::Type is struct S&. + */ +template +struct AddLvalueReference + : detail::AddLvalueReferenceHelper +{}; + /* 20.9.7.3 Sign modifications [meta.trans.sign] */ template struct EnableIf; -template -struct Conditional; - namespace detail { template @@ -568,7 +804,7 @@ struct MakeSigned; template struct MakeSigned { - typedef T Type; + typedef T Type; }; template @@ -603,7 +839,8 @@ struct MakeSigned */ template struct MakeSigned - : EnableIf::value && !IsSame::Type>::value, + : EnableIf::value && + !IsSame::Type>::value, typename detail::MakeSigned >::Type {}; @@ -636,7 +873,7 @@ struct MakeUnsigned; template struct MakeUnsigned { - typedef T Type; + typedef T Type; }; template @@ -671,13 +908,41 @@ struct MakeUnsigned */ template struct MakeUnsigned - : EnableIf::value && !IsSame::Type>::value, + : EnableIf::value && + !IsSame::Type>::value, typename detail::MakeUnsigned >::Type {}; /* 20.9.7.4 Array modifications [meta.trans.arr] */ +/** + * RemoveExtent produces either the type of the elements of the array T, or T + * itself. + * + * mozilla::RemoveExtent::Type is int; + * mozilla::RemoveExtent::Type is const int; + * mozilla::RemoveExtent::Type is volatile int; + * mozilla::RemoveExtent::Type is long[17]. + */ +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + /* 20.9.7.5 Pointer modifications [meta.trans.ptr] */ /* 20.9.7.6 Other transformations [meta.trans.other] */ @@ -707,7 +972,7 @@ struct EnableIf template struct EnableIf { - typedef T Type; + typedef T Type; }; /** @@ -719,13 +984,13 @@ struct EnableIf template struct Conditional { - typedef A Type; + typedef A Type; }; template struct Conditional { - typedef B Type; + typedef B Type; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TypedEnum.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TypedEnum.h index e55365abb8..d84cd90257 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TypedEnum.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TypedEnum.h @@ -9,39 +9,11 @@ #ifndef mozilla_TypedEnum_h #define mozilla_TypedEnum_h -#include "mozilla/Attributes.h" +#include "mozilla/TypedEnumInternal.h" +#include "mozilla/MacroArgs.h" #if defined(__cplusplus) -#if defined(__clang__) - /* - * Per Clang documentation, "Note that marketing version numbers should not - * be used to check for language features, as different vendors use different - * numbering schemes. Instead, use the feature checking macros." - */ -# ifndef __has_extension -# define __has_extension __has_feature /* compatibility, for older versions of clang */ -# endif -# if __has_extension(cxx_strong_enums) -# define MOZ_HAVE_CXX11_ENUM_TYPE -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -#elif defined(__GNUC__) -# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L -# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3) -# define MOZ_HAVE_CXX11_ENUM_TYPE -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -# endif -#elif defined(_MSC_VER) -# if _MSC_VER >= 1400 -# define MOZ_HAVE_CXX11_ENUM_TYPE -# endif -# if _MSC_VER >= 1700 -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -#endif - /** * MOZ_ENUM_TYPE specifies the underlying numeric type for an enum. It's * specified by placing MOZ_ENUM_TYPE(type) immediately after the enum name in @@ -97,13 +69,12 @@ * in namespace scope to handle bits that can only be implemented with * namespace-scoped code. For example: * - * class FooBar { - * + * class FooBar + * { * MOZ_BEGIN_NESTED_ENUM_CLASS(Enum, int32_t) * A, * B = 6 * MOZ_END_NESTED_ENUM_CLASS(Enum) - * * }; * * MOZ_FINISH_NESTED_ENUM_CLASS(FooBar::Enum) @@ -131,6 +102,10 @@ * these are already integer types so there is nothing more to do. */ # define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name + /* + * See the comment below about MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) Name #else /** * We need Name to both name a type, and scope the provided enumerator @@ -172,24 +147,28 @@ # define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER1(Name) \ class Name \ { \ - public: \ - enum Enum \ - { + public: \ + enum Enum \ + { /* Two-argument form. */ # define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER2(Name, type) \ class Name \ { \ - public: \ - enum Enum MOZ_ENUM_TYPE(type) \ - { + public: \ + enum Enum MOZ_ENUM_TYPE(type) \ + { # define MOZ_END_NESTED_ENUM_CLASS(Name) \ - }; \ - Name() {} \ - Name(Enum aEnum) : mEnum(aEnum) {} \ - explicit Name(int num) : mEnum((Enum)num) {} \ - operator Enum() const { return mEnum; } \ - private: \ - Enum mEnum; \ + }; \ + Name() {} \ + MOZ_CONSTEXPR Name(Enum aEnum) : mEnum(aEnum) {} \ + template \ + explicit MOZ_CONSTEXPR Name(Other num) : mEnum((Enum)num) {} \ + MOZ_CONSTEXPR operator Enum() const { return mEnum; } \ + explicit MOZ_CONSTEXPR Name(const mozilla::CastableTypedEnumResult& aOther) \ + : mEnum(aOther.get()) \ + {} \ + private: \ + Enum mEnum; \ }; # define MOZ_FINISH_NESTED_ENUM_CLASS(Name) \ inline int operator+(const int&, const Name::Enum&) MOZ_DELETE; \ @@ -225,7 +204,6 @@ inline bool operator&&(const Name::Enum&, const bool&) MOZ_DELETE; \ inline bool operator||(const bool&, const Name::Enum&) MOZ_DELETE; \ inline bool operator||(const Name::Enum&, const bool&) MOZ_DELETE; \ - inline int operator~(const Name::Enum&) MOZ_DELETE; \ inline int operator&(const int&, const Name::Enum&) MOZ_DELETE; \ inline int operator&(const Name::Enum&, const int&) MOZ_DELETE; \ inline int operator|(const int&, const Name::Enum&) MOZ_DELETE; \ @@ -253,35 +231,45 @@ * In the present case, the integer type is the Enum nested type. */ # define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name::Enum + /* + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is a variant of MOZ_ENUM_CLASS_ENUM_TYPE + * to be used when the enum class at hand depends on template parameters. + * + * Indeed, if T depends on template parameters, in order to name a nested type + * in T, C++ does not allow to just write "T::NestedType". Instead, we have + * to write "typename T::NestedType". The role of this macro is to add + * this "typename" keywords where needed. + * + * Example: + * + * template + * struct S {}; + * + * MOZ_BEGIN_ENUM_CLASS(E) + * Foo, + * Bar + * MOZ_END_ENUM_CLASS(E) + * + * S s; + * + * In this example, the second template parameter to S is meant to be of type + * T, but on non-C++11 compilers, type T is a class type, not an integer + * type, so it is not accepted as the type of a constant template parameter. + * One would then want to use MOZ_ENUM_CLASS_ENUM_TYPE(T), but that doesn't + * work either as T depends on template parameters (more specifically here, T + * _is_ a template parameter) so as MOZ_ENUM_CLASS_ENUM_TYPE(T) expands to + * T::Enum, we are missing the required "typename" keyword. So here, + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is needed. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) typename Name::Enum #endif - /* - * Count the number of arguments passed to MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS, - * very carefully tiptoeing around an MSVC bug where it improperly expands - * __VA_ARGS__ as a single token in argument lists. See these URLs for - * details: - * - * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement - * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 - */ -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL2(_1, _2, count, ...) \ - count -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL(args) \ - MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL2 args -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS(...) \ - MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL((__VA_ARGS__, 2, 1, 0)) - /* Pick the right helper macro to invoke. */ -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER2(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER##count -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER1(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER2(count) -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER1(count) - /* The actual macro. */ -# define MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(x, y) x y +# define MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(a, b) a b # define MOZ_BEGIN_NESTED_ENUM_CLASS(...) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER(MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS(__VA_ARGS__)), \ - (__VA_ARGS__)) + MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER, \ + __VA_ARGS__), \ + (__VA_ARGS__)) # define MOZ_BEGIN_ENUM_CLASS(...) MOZ_BEGIN_NESTED_ENUM_CLASS(__VA_ARGS__) # define MOZ_END_ENUM_CLASS(Name) \ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TypedEnumBits.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TypedEnumBits.h new file mode 100644 index 0000000000..1f439f1239 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TypedEnumBits.h @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS allows using a typed enum as bit flags. + */ + +#ifndef mozilla_TypedEnumBits_h +#define mozilla_TypedEnumBits_h + +#include "mozilla/IntegerTypeTraits.h" +#include "mozilla/TypedEnumInternal.h" + +namespace mozilla { + +#define MOZ_CASTABLETYPEDENUMRESULT_BINOP(Op, OtherType, ReturnType) \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const OtherType& aE, const CastableTypedEnumResult& aR) \ +{ \ + return ReturnType(aE Op OtherType(aR)); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR, const OtherType& aE) \ +{ \ + return ReturnType(OtherType(aR) Op aE); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR1, \ + const CastableTypedEnumResult& aR2) \ +{ \ + return ReturnType(OtherType(aR1) Op OtherType(aR2)); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_BINOP(|, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(&, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(^, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(==, E, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(!=, E, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(||, bool, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(&&, bool, bool) + +template +MOZ_CONSTEXPR CastableTypedEnumResult +operator ~(const CastableTypedEnumResult& aR) +{ + return CastableTypedEnumResult(~(E(aR))); +} + +#define MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(Op) \ +template \ +E& \ +operator Op(E& aR1, \ + const CastableTypedEnumResult& aR2) \ +{ \ + return aR1 Op E(aR2); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(&=) +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(|=) +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(^=) + +#undef MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP + +#undef MOZ_CASTABLETYPEDENUMRESULT_BINOP + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS + +#define MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(Op, ReturnType) \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(typename E::Enum aE, const CastableTypedEnumResult& aR) \ +{ \ + return ReturnType(aE Op E(aR)); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR, typename E::Enum aE) \ +{ \ + return ReturnType(E(aR) Op aE); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(|, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(&, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(^, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(==, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(!=, bool) + +#undef MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11 + +#endif // not MOZ_HAVE_CXX11_STRONG_ENUMS + +namespace detail { +template +struct UnsignedIntegerTypeForEnum + : UnsignedStdintTypeForSize +{}; +} + +} // namespace mozilla + +#define MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, Op) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name a, Name b) \ + { \ + typedef mozilla::CastableTypedEnumResult Result; \ + typedef mozilla::detail::UnsignedIntegerTypeForEnum::Type U; \ + return Result(Name(U(a) Op U(b))); \ + } \ + \ + inline Name& \ + operator Op##=(Name& a, Name b) \ + { \ + return a = a Op b; \ + } + +#define MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, |) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, &) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, ^) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator~(Name a) \ + { \ + typedef mozilla::CastableTypedEnumResult Result; \ + typedef mozilla::detail::UnsignedIntegerTypeForEnum::Type U; \ + return Result(Name(~(U(a)))); \ + } + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS +# define MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, Op) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name a, Name::Enum b) \ + { \ + return a Op Name(b); \ + } \ + \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name::Enum a, Name b) \ + { \ + return Name(a) Op b; \ + } \ + \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name::Enum a, Name::Enum b) \ + { \ + return Name(a) Op Name(b); \ + } \ + \ + inline Name& \ + operator Op##=(Name& a, Name::Enum b) \ + { \ + return a = a Op Name(b); \ + } + +# define MOZ_MAKE_ENUM_CLASS_OPS_EXTRA_NON_CXX11(Name) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, |) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, &) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, ^) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator~(Name::Enum a) \ + { \ + return ~(Name(a)); \ + } +#endif + +/** + * MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS generates standard bitwise operators + * for the given enum type. Use this to enable using an enum type as bit-field. + */ +#ifdef MOZ_HAVE_CXX11_STRONG_ENUMS +# define MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) +#else +# define MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_EXTRA_NON_CXX11(Name) +#endif + +#endif // mozilla_TypedEnumBits_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TypedEnumInternal.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TypedEnumInternal.h new file mode 100644 index 0000000000..8c88cb589b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/TypedEnumInternal.h @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Internal stuff needed by TypedEnum.h and TypedEnumBits.h. */ + +// NOTE: When we can assume C++11 enum class support and TypedEnum.h goes away, +// we should then consider folding TypedEnumInternal.h into TypedEnumBits.h. + +#ifndef mozilla_TypedEnumInternal_h +#define mozilla_TypedEnumInternal_h + +#include "mozilla/Attributes.h" + +#if defined(__cplusplus) + +#if defined(__clang__) + /* + * Per Clang documentation, "Note that marketing version numbers should not + * be used to check for language features, as different vendors use different + * numbering schemes. Instead, use the feature checking macros." + */ +# ifndef __has_extension +# define __has_extension __has_feature /* compatibility, for older versions of clang */ +# endif +# if __has_extension(cxx_strong_enums) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#elif defined(__GNUC__) +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +# endif +#elif defined(_MSC_VER) +# if _MSC_VER >= 1400 +# define MOZ_HAVE_CXX11_ENUM_TYPE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#endif + +namespace mozilla { + +/* + * The problem that CastableTypedEnumResult aims to solve is that + * typed enums are not convertible to bool, and there is no way to make them + * be, yet user code wants to be able to write + * + * if (myFlags & Flags::SOME_PARTICULAR_FLAG) (1) + * + * There are different approaches to solving this. Most of them require + * adapting user code. For example, we could implement operator! and have + * the user write + * + * if (!!(myFlags & Flags::SOME_PARTICULAR_FLAG)) (2) + * + * Or we could supply a IsNonZero() or Any() function returning whether + * an enum value is nonzero, and have the user write + * + * if (Any(Flags & Flags::SOME_PARTICULAR_FLAG)) (3) + * + * But instead, we choose to preserve the original user syntax (1) as it + * is inherently more readable, and to ease porting existing code to typed + * enums. We achieve this by having operator& and other binary bitwise + * operators have as return type a class, CastableTypedEnumResult, + * that wraps a typed enum but adds bool convertibility. + */ +template +class CastableTypedEnumResult +{ +private: + const E mValue; + +public: + explicit MOZ_CONSTEXPR CastableTypedEnumResult(E aValue) + : mValue(aValue) + {} + + MOZ_CONSTEXPR operator E() const { return mValue; } + + template + MOZ_EXPLICIT_CONVERSION MOZ_CONSTEXPR + operator DestinationType() const { return DestinationType(mValue); } + + MOZ_CONSTEXPR bool operator !() const { return !bool(mValue); } + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS + // This get() method is used to implement a constructor in the + // non-c++11 fallback path for MOZ_BEGIN_ENUM_CLASS, taking a + // CastableTypedEnumResult. If we try to implement it using the + // above conversion operator E(), then at least clang 3.3 + // (when forced to take the non-c++11 fallback path) compiles + // this constructor to an infinite recursion. So we introduce this + // get() method, that does exactly the same as the conversion operator, + // to work around this. + MOZ_CONSTEXPR E get() const { return mValue; } +#endif +}; + +} // namespace mozilla + +#endif // __cplusplus + +#endif // mozilla_TypedEnumInternal_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Types.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Types.h index 5340b2b600..e7e18abb27 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Types.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Types.h @@ -37,7 +37,7 @@ * These macros are designed for use by library interfaces -- not for normal * methods or data used cross-file. */ -#if defined(WIN32) || defined(XP_OS2) +#if defined(WIN32) # define MOZ_EXPORT __declspec(dllexport) #else /* Unix */ # ifdef HAVE_VISIBILITY_ATTRIBUTE @@ -63,16 +63,12 @@ # else # define MOZ_IMPORT_API __declspec(dllimport) # endif -#elif defined(XP_OS2) -# define MOZ_IMPORT_API __declspec(dllimport) #else # define MOZ_IMPORT_API MOZ_EXPORT #endif #if defined(_WIN32) && !defined(__MWERKS__) # define MOZ_IMPORT_DATA __declspec(dllimport) -#elif defined(XP_OS2) -# define MOZ_IMPORT_DATA __declspec(dllimport) #else # define MOZ_IMPORT_DATA MOZ_EXPORT #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/UniquePtr.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/UniquePtr.h new file mode 100644 index 0000000000..9c873db90c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/UniquePtr.h @@ -0,0 +1,674 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Smart pointer managing sole ownership of a resource. */ + +#ifndef mozilla_UniquePtr_h +#define mozilla_UniquePtr_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/Pair.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +template class DefaultDelete; +template> class UniquePtr; + +} // namespace mozilla + +namespace mozilla { + +/** + * UniquePtr is a smart pointer that wholly owns a resource. Ownership may be + * transferred out of a UniquePtr through explicit action, but otherwise the + * resource is destroyed when the UniquePtr is destroyed. + * + * UniquePtr is similar to C++98's std::auto_ptr, but it improves upon auto_ptr + * in one crucial way: it's impossible to copy a UniquePtr. Copying an auto_ptr + * obviously *can't* copy ownership of its singly-owned resource. So what + * happens if you try to copy one? Bizarrely, ownership is implicitly + * *transferred*, preserving single ownership but breaking code that assumes a + * copy of an object is identical to the original. (This is why auto_ptr is + * prohibited in STL containers.) + * + * UniquePtr solves this problem by being *movable* rather than copyable. + * Instead of passing a |UniquePtr u| directly to the constructor or assignment + * operator, you pass |Move(u)|. In doing so you indicate that you're *moving* + * ownership out of |u|, into the target of the construction/assignment. After + * the transfer completes, |u| contains |nullptr| and may be safely destroyed. + * This preserves single ownership but also allows UniquePtr to be moved by + * algorithms that have been made move-safe. (Note: if |u| is instead a + * temporary expression, don't use |Move()|: just pass the expression, because + * it's already move-ready. For more information see Move.h.) + * + * UniquePtr is also better than std::auto_ptr in that the deletion operation is + * customizable. An optional second template parameter specifies a class that + * (through its operator()(T*)) implements the desired deletion policy. If no + * policy is specified, mozilla::DefaultDelete is used -- which will either + * |delete| or |delete[]| the resource, depending whether the resource is an + * array. Custom deletion policies ideally should be empty classes (no member + * fields, no member fields in base classes, no virtual methods/inheritance), + * because then UniquePtr can be just as efficient as a raw pointer. + * + * Use of UniquePtr proceeds like so: + * + * UniquePtr g1; // initializes to nullptr + * g1.reset(new int); // switch resources using reset() + * g1 = nullptr; // clears g1, deletes the int + * + * UniquePtr g2(new int); // owns that int + * int* p = g2.release(); // g2 leaks its int -- still requires deletion + * delete p; // now freed + * + * struct S { int x; S(int x) : x(x) {} }; + * UniquePtr g3, g4(new S(5)); + * g3 = Move(g4); // g3 owns the S, g4 cleared + * S* p = g3.get(); // g3 still owns |p| + * assert(g3->x == 5); // operator-> works (if .get() != nullptr) + * assert((*g3).x == 5); // also operator* (again, if not cleared) + * Swap(g3, g4); // g4 now owns the S, g3 cleared + * g3.swap(g4); // g3 now owns the S, g4 cleared + * UniquePtr g5(Move(g3)); // g5 owns the S, g3 cleared + * g5.reset(); // deletes the S, g5 cleared + * + * struct FreePolicy { void operator()(void* p) { free(p); } }; + * UniquePtr g6(static_cast(malloc(sizeof(int)))); + * int* ptr = g6.get(); + * g6 = nullptr; // calls free(ptr) + * + * Now, carefully note a few things you *can't* do: + * + * UniquePtr b1; + * b1 = new int; // BAD: can only assign another UniquePtr + * int* ptr = b1; // BAD: no auto-conversion to pointer, use get() + * + * UniquePtr b2(b1); // BAD: can't copy a UniquePtr + * UniquePtr b3 = b1; // BAD: can't copy-assign a UniquePtr + * + * A few miscellaneous notes: + * + * UniquePtr, when not instantiated for an array type, can be move-constructed + * and move-assigned, not only from itself but from "derived" UniquePtr + * instantiations where U converts to T and E converts to D. If you want to use + * this, you're going to have to specify a deletion policy for both UniquePtr + * instantations, and T pretty much has to have a virtual destructor. In other + * words, this doesn't work: + * + * struct Base { virtual ~Base() {} }; + * struct Derived : Base {}; + * + * UniquePtr b1; + * // BAD: DefaultDelete and DefaultDelete don't interconvert + * UniquePtr d1(Move(b)); + * + * UniquePtr b2; + * UniquePtr> d2(Move(b2)); // okay + * + * UniquePtr is specialized for array types. Specializing with an array type + * creates a smart-pointer version of that array -- not a pointer to such an + * array. + * + * UniquePtr arr(new int[5]); + * arr[0] = 4; + * + * What else is different? Deletion of course uses |delete[]|. An operator[] + * is provided. Functionality that doesn't make sense for arrays is removed. + * The constructors and mutating methods only accept array pointers (not T*, U* + * that converts to T*, or UniquePtr or UniquePtr) or |nullptr|. + * + * It's perfectly okay to return a UniquePtr from a method to assure the related + * resource is properly deleted. You'll need to use |Move()| when returning a + * local UniquePtr. Otherwise you can return |nullptr|, or you can return + * |UniquePtr(ptr)|. + * + * UniquePtr will commonly be a member of a class, with lifetime equivalent to + * that of that class. If you want to expose the related resource, you could + * expose a raw pointer via |get()|, but ownership of a raw pointer is + * inherently unclear. So it's better to expose a |const UniquePtr&| instead. + * This prohibits mutation but still allows use of |get()| when needed (but + * operator-> is preferred). Of course, you can only use this smart pointer as + * long as the enclosing class instance remains live -- no different than if you + * exposed the |get()| raw pointer. + * + * To pass a UniquePtr-managed resource as a pointer, use a |const UniquePtr&| + * argument. To specify an inout parameter (where the method may or may not + * take ownership of the resource, or reset it), or to specify an out parameter + * (where simply returning a |UniquePtr| isn't possible), use a |UniquePtr&| + * argument. To unconditionally transfer ownership of a UniquePtr + * into a method, use a |UniquePtr| argument. To conditionally transfer + * ownership of a resource into a method, should the method want it, use a + * |UniquePtr&&| argument. + */ +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + Pointer& ptr() { return tuple.first(); } + const Pointer& ptr() const { return tuple.first(); } + + DeleterType& del() { return tuple.second(); } + const DeleterType& del() const { return tuple.second(); } + + public: + /** + * Construct a UniquePtr containing |nullptr|. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! Ideally + // you should make deletion use the same function every time, using a + // deleter policy: + // + // // BAD, won't compile with MSVC10, deleter doesn't need to be a + // // variable at all + // typedef void (&FreeSignature)(void*); + // UniquePtr ptr((int*) malloc(sizeof(int)), free); + // + // // GOOD, compiles with MSVC10, deletion behavior statically known and + // // optimizable + // struct DeleteByFreeing + // { + // void operator()(void* ptr) { free(ptr); } + // }; + // + // If deletion really, truly, must be a variable: you might be able to work + // around this with a deleter class that contains the function reference. + // But this workaround is untried and untested, because variable deletion + // behavior really isn't something you should use. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + template + UniquePtr(UniquePtr&& other, + typename EnableIf::Pointer, + Pointer>::value && + !IsArray::value && + (IsReference::value + ? IsSame::value + : IsConvertible::value), + int>::Type dummy = 0) + : tuple(other.release(), Forward(other.getDeleter())) + { + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + template + UniquePtr& operator=(UniquePtr&& other) + { + static_assert(IsConvertible::Pointer, Pointer>::value, + "incompatible UniquePtr pointees"); + static_assert(!IsArray::value, + "can't assign from UniquePtr holding an array"); + + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT n) { + MOZ_ASSERT(n == nullptr); + reset(nullptr); + return *this; + } + + T& operator*() const { return *get(); } + Pointer operator->() const { + MOZ_ASSERT(get(), "dereferencing a UniquePtr containing nullptr"); + return get(); + } + + Pointer get() const { return ptr(); } + + DeleterType& getDeleter() { return del(); } + const DeleterType& getDeleter() const { return del(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = ptr(); + ptr() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = ptr(); + ptr() = p; + if (old != nullptr) + getDeleter()(old); + } + + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +// In case you didn't read the comment by the main definition (you should!): the +// UniquePtr specialization exists to manage array pointers. It deletes +// such pointers using delete[], it will reject construction and modification +// attempts using U* or U[]. Otherwise it works like the normal UniquePtr. +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + public: + /** + * Construct a UniquePtr containing nullptr. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + private: + // delete[] knows how to handle *only* an array of a single class type. For + // delete[] to work correctly, it must know the size of each element, the + // fields and base classes of each element requiring destruction, and so on. + // So forbid all overloads which would end up invoking delete[] on a pointer + // of the wrong type. + template + UniquePtr(U&& u, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! See the + // comment by this constructor in the non-T[] specialization above. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + private: + // Forbidden for the same reasons as stated above. + template + UniquePtr(U&& u, V&& v, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT) { + reset(); + return *this; + } + + T& operator[](decltype(sizeof(int)) i) const { return get()[i]; } + Pointer get() const { return tuple.first(); } + + DeleterType& getDeleter() { return tuple.second(); } + const DeleterType& getDeleter() const { return tuple.second(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = tuple.first(); + tuple.first() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = tuple.first(); + tuple.first() = p; + if (old != nullptr) + tuple.second()(old); + } + + private: + // Kill off all remaining overloads that aren't true nullptr (the overload + // above should handle that) or emulated nullptr (which acts like int/long + // on gcc 4.4/4.5). + template + void reset(U, + typename EnableIf::value && + !IsSame::Type>::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +/** A default deletion policy using plain old operator delete. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + template + DefaultDelete(const DefaultDelete& other, + typename EnableIf::value, + int>::Type dummy = 0) + {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete ptr; + } +}; + +/** A default deletion policy using operator delete[]. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete[] ptr; + } + + private: + template + void operator()(U* ptr) const MOZ_DELETE; +}; + +template +void +Swap(UniquePtr& x, UniquePtr& y) +{ + x.swap(y); +} + +template +bool +operator==(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() == y.get(); +} + +template +bool +operator!=(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() != y.get(); +} + +template +bool +operator==(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator==(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator!=(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +template +bool +operator!=(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +// No operator<, operator>, operator<=, operator>= for now because simplicity. + +namespace detail { + +template +struct UniqueSelector +{ + typedef UniquePtr SingleObject; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr UnknownBound; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr KnownBound; +}; + +} // namespace detail + +// We don't have variadic template support everywhere, so just hard-code arities +// 0-4 for now. If you need more arguments, feel free to add the extra +// overloads. +// +// Beware! Due to lack of true nullptr support in gcc 4.4 and 4.5, passing +// literal nullptr to MakeUnique will not work on some platforms. See Move.h +// for more details. + +template +typename detail::UniqueSelector::SingleObject +MakeUnique() +{ + return UniquePtr(new T()); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1) +{ + return UniquePtr(new T(Forward(a1))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2) +{ + return UniquePtr(new T(Forward(a1), Forward(a2))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4), Forward(a5))); +} + +template +typename detail::UniqueSelector::UnknownBound +MakeUnique(decltype(sizeof(int)) n) +{ + typedef typename RemoveExtent::Type ArrayType; + return UniquePtr(new ArrayType[n]()); +} + +template +typename detail::UniqueSelector::KnownBound +MakeUnique() MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) MOZ_DELETE; + +} // namespace mozilla + +#endif /* mozilla_UniquePtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Vector.h index c67467524f..8540caf476 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Vector.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/Vector.h @@ -39,14 +39,13 @@ namespace detail { /* * Check that the given capacity wastes the minimal amount of space if - * allocated on the heap. This means that cap*sizeof(T) is as close to a - * power-of-two as possible. growStorageBy() is responsible for ensuring - * this. + * allocated on the heap. This means that aCapacity*sizeof(T) is as close to a + * power-of-two as possible. growStorageBy() is responsible for ensuring this. */ template -static bool CapacityHasExcessSpace(size_t cap) +static bool CapacityHasExcessSpace(size_t aCapacity) { - size_t size = cap * sizeof(T); + size_t size = aCapacity * sizeof(T); return RoundUpPow2(size) - size >= sizeof(T); } @@ -57,72 +56,90 @@ static bool CapacityHasExcessSpace(size_t cap) template struct VectorImpl { - /* Destroys constructed objects in the range [begin, end). */ - static inline void destroy(T* begin, T* end) { - for (T* p = begin; p < end; ++p) - p->~T(); + /* Destroys constructed objects in the range [aBegin, aEnd). */ + static inline void destroy(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + p->~T(); } + } - /* Constructs objects in the uninitialized range [begin, end). */ - static inline void initialize(T* begin, T* end) { - for (T* p = begin; p < end; ++p) - new(p) T(); + /* Constructs objects in the uninitialized range [aBegin, aEnd). */ + static inline void initialize(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); } + } - /* - * Copy-constructs objects in the uninitialized range - * [dst, dst+(srcend-srcbeg)) from the range [srcbeg, srcend). - */ - template - static inline void copyConstruct(T* dst, const U* srcbeg, const U* srcend) { - for (const U* p = srcbeg; p < srcend; ++p, ++dst) - new(dst) T(*p); + /* + * Copy-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(*p); } + } - /* - * Move-constructs objects in the uninitialized range - * [dst, dst+(srcend-srcbeg)) from the range [srcbeg, srcend). - */ - template - static inline void moveConstruct(T* dst, U* srcbeg, U* srcend) { - for (U* p = srcbeg; p < srcend; ++p, ++dst) - new(dst) T(Move(*p)); + /* + * Move-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void moveConstruct(T* aDst, U* aSrcStart, U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(Move(*p)); } + } - /* - * Copy-constructs objects in the uninitialized range [dst, dst+n) from the - * same object u. - */ - template - static inline void copyConstructN(T* dst, size_t n, const U& u) { - for (T* end = dst + n; dst < end; ++dst) - new(dst) T(u); + /* + * Copy-constructs objects in the uninitialized range [aDst, aDst+aN) from + * the same object aU. + */ + template + static inline void copyConstructN(T* aDst, size_t aN, const U& aU) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + new(aDst) T(aU); } + } - /* - * Grows the given buffer to have capacity newCap, preserving the objects - * constructed in the range [begin, end) and updating v. Assumes that (1) - * newCap has not overflowed, and (2) multiplying newCap by sizeof(T) will - * not overflow. - */ - static inline bool - growTo(VectorBase& v, size_t newCap) { - MOZ_ASSERT(!v.usingInlineStorage()); - MOZ_ASSERT(!CapacityHasExcessSpace(newCap)); - T* newbuf = reinterpret_cast(v.malloc_(newCap * sizeof(T))); - if (!newbuf) - return false; - T* dst = newbuf; - T* src = v.beginNoCheck(); - for (; src < v.endNoCheck(); ++dst, ++src) - new(dst) T(Move(*src)); - VectorImpl::destroy(v.beginNoCheck(), v.endNoCheck()); - v.free_(v.mBegin); - v.mBegin = newbuf; - /* v.mLength is unchanged. */ - v.mCapacity = newCap; - return true; + /* + * Grows the given buffer to have capacity aNewCap, preserving the objects + * constructed in the range [begin, end) and updating aV. Assumes that (1) + * aNewCap has not overflowed, and (2) multiplying aNewCap by sizeof(T) will + * not overflow. + */ + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + T* newbuf = reinterpret_cast(aV.malloc_(aNewCap * sizeof(T))); + if (!newbuf) { + return false; + } + T* dst = newbuf; + T* src = aV.beginNoCheck(); + for (; src < aV.endNoCheck(); ++dst, ++src) { + new(dst) T(Move(*src)); } + VectorImpl::destroy(aV.beginNoCheck(), aV.endNoCheck()); + aV.free_(aV.mBegin); + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } }; /* @@ -133,58 +150,71 @@ struct VectorImpl template struct VectorImpl { - static inline void destroy(T*, T*) {} - - static inline void initialize(T* begin, T* end) { - /* - * You would think that memset would be a big win (or even break even) - * when we know T is a POD. But currently it's not. This is probably - * because |append| tends to be given small ranges and memset requires - * a function call that doesn't get inlined. - * - * memset(begin, 0, sizeof(T) * (end-begin)); - */ - for (T* p = begin; p < end; ++p) - new(p) T(); - } + static inline void destroy(T*, T*) {} - template - static inline void copyConstruct(T* dst, const U* srcbeg, const U* srcend) { - /* - * See above memset comment. Also, notice that copyConstruct is - * currently templated (T != U), so memcpy won't work without - * requiring T == U. - * - * memcpy(dst, srcbeg, sizeof(T) * (srcend - srcbeg)); - */ - for (const U* p = srcbeg; p < srcend; ++p, ++dst) - *dst = *p; + static inline void initialize(T* aBegin, T* aEnd) + { + /* + * You would think that memset would be a big win (or even break even) + * when we know T is a POD. But currently it's not. This is probably + * because |append| tends to be given small ranges and memset requires + * a function call that doesn't get inlined. + * + * memset(aBegin, 0, sizeof(T) * (aEnd - aBegin)); + */ + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); } + } - template - static inline void moveConstruct(T* dst, const U* srcbeg, const U* srcend) { - copyConstruct(dst, srcbeg, srcend); + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + /* + * See above memset comment. Also, notice that copyConstruct is + * currently templated (T != U), so memcpy won't work without + * requiring T == U. + * + * memcpy(aDst, aSrcStart, sizeof(T) * (aSrcEnd - aSrcStart)); + */ + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + *aDst = *p; } + } - static inline void copyConstructN(T* dst, size_t n, const T& t) { - for (T* end = dst + n; dst < end; ++dst) - *dst = t; + template + static inline void moveConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + copyConstruct(aDst, aSrcStart, aSrcEnd); + } + + static inline void copyConstructN(T* aDst, size_t aN, const T& aT) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + *aDst = aT; } + } - static inline bool - growTo(VectorBase& v, size_t newCap) { - MOZ_ASSERT(!v.usingInlineStorage()); - MOZ_ASSERT(!CapacityHasExcessSpace(newCap)); - size_t oldSize = sizeof(T) * v.mCapacity; - size_t newSize = sizeof(T) * newCap; - T* newbuf = reinterpret_cast(v.realloc_(v.mBegin, oldSize, newSize)); - if (!newbuf) - return false; - v.mBegin = newbuf; - /* v.mLength is unchanged. */ - v.mCapacity = newCap; - return true; + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + size_t oldSize = sizeof(T) * aV.mCapacity; + size_t newSize = sizeof(T) * aNewCap; + T* newbuf = reinterpret_cast(aV.realloc_(aV.mBegin, oldSize, newSize)); + if (!newbuf) { + return false; } + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } }; } // namespace detail @@ -199,368 +229,387 @@ struct VectorImpl template class VectorBase : private AllocPolicy { - /* utilities */ + /* utilities */ - static const bool sElemIsPod = IsPod::value; - typedef detail::VectorImpl Impl; - friend struct detail::VectorImpl; + static const bool kElemIsPod = IsPod::value; + typedef detail::VectorImpl Impl; + friend struct detail::VectorImpl; - bool growStorageBy(size_t incr); - bool convertToHeapStorage(size_t newCap); + bool growStorageBy(size_t aIncr); + bool convertToHeapStorage(size_t aNewCap); - /* magic constants */ + /* magic constants */ - static const int sMaxInlineBytes = 1024; + static const int kMaxInlineBytes = 1024; - /* compute constants */ + /* compute constants */ - /* - * Consider element size to be 1 for buffer sizing if there are 0 inline - * elements. This allows us to compile when the definition of the element - * type is not visible here. - * - * Explicit specialization is only allowed at namespace scope, so in order - * to keep everything here, we use a dummy template parameter with partial - * specialization. - */ - template - struct ElemSize - { - static const size_t value = sizeof(T); - }; - template - struct ElemSize<0, Dummy> - { - static const size_t value = 1; - }; - - static const size_t sInlineCapacity = - tl::Min::value>::value; - - /* Calculate inline buffer size; avoid 0-sized array. */ - static const size_t sInlineBytes = - tl::Max<1, sInlineCapacity * ElemSize::value>::value; - - /* member data */ + /* + * Consider element size to be 1 for buffer sizing if there are 0 inline + * elements. This allows us to compile when the definition of the element + * type is not visible here. + * + * Explicit specialization is only allowed at namespace scope, so in order + * to keep everything here, we use a dummy template parameter with partial + * specialization. + */ + template + struct ElemSize + { + static const size_t value = sizeof(T); + }; + template + struct ElemSize<0, Dummy> + { + static const size_t value = 1; + }; + + static const size_t kInlineCapacity = + tl::Min::value>::value; + + /* Calculate inline buffer size; avoid 0-sized array. */ + static const size_t kInlineBytes = + tl::Max<1, kInlineCapacity * ElemSize::value>::value; + + /* member data */ - /* - * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, - * mBegin + mLength) hold valid constructed T objects. The range [mBegin + - * mLength, mBegin + mCapacity) holds uninitialized memory. The range - * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory - * previously allocated by a call to reserve(). - */ - T* mBegin; + /* + * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, + * mBegin + mLength) hold valid constructed T objects. The range [mBegin + + * mLength, mBegin + mCapacity) holds uninitialized memory. The range + * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory + * previously allocated by a call to reserve(). + */ + T* mBegin; - /* Number of elements in the vector. */ - size_t mLength; + /* Number of elements in the vector. */ + size_t mLength; - /* Max number of elements storable in the vector without resizing. */ - size_t mCapacity; + /* Max number of elements storable in the vector without resizing. */ + size_t mCapacity; #ifdef DEBUG - /* Max elements of reserved or used space in this vector. */ - size_t mReserved; + /* Max elements of reserved or used space in this vector. */ + size_t mReserved; #endif - /* Memory used for inline storage. */ - AlignedStorage storage; + /* Memory used for inline storage. */ + AlignedStorage mStorage; #ifdef DEBUG - friend class ReentrancyGuard; - bool entered; + friend class ReentrancyGuard; + bool mEntered; #endif - /* private accessors */ + /* private accessors */ - bool usingInlineStorage() const { - return mBegin == const_cast(this)->inlineStorage(); - } + bool usingInlineStorage() const + { + return mBegin == const_cast(this)->inlineStorage(); + } - T* inlineStorage() { - return static_cast(storage.addr()); - } + T* inlineStorage() + { + return static_cast(mStorage.addr()); + } - T* beginNoCheck() const { - return mBegin; - } + T* beginNoCheck() const + { + return mBegin; + } - T* endNoCheck() { - return mBegin + mLength; - } + T* endNoCheck() + { + return mBegin + mLength; + } - const T* endNoCheck() const { - return mBegin + mLength; - } + const T* endNoCheck() const + { + return mBegin + mLength; + } #ifdef DEBUG - size_t reserved() const { - MOZ_ASSERT(mReserved <= mCapacity); - MOZ_ASSERT(mLength <= mReserved); - return mReserved; - } + size_t reserved() const + { + MOZ_ASSERT(mReserved <= mCapacity); + MOZ_ASSERT(mLength <= mReserved); + return mReserved; + } #endif - /* Append operations guaranteed to succeed due to pre-reserved space. */ - template void internalAppend(U&& u); - template - void internalAppendAll(const VectorBase& u); - void internalAppendN(const T& t, size_t n); - template void internalAppend(const U* begin, size_t length); + /* Append operations guaranteed to succeed due to pre-reserved space. */ + template void internalAppend(U&& aU); + template + void internalAppendAll(const VectorBase& aU); + void internalAppendN(const T& aT, size_t aN); + template void internalAppend(const U* aBegin, size_t aLength); - public: - static const size_t sMaxInlineStorage = N; +public: + static const size_t sMaxInlineStorage = N; - typedef T ElementType; + typedef T ElementType; - VectorBase(AllocPolicy = AllocPolicy()); - VectorBase(ThisVector&&); /* Move constructor. */ - ThisVector& operator=(ThisVector&&); /* Move assignment. */ - ~VectorBase(); + explicit VectorBase(AllocPolicy = AllocPolicy()); + explicit VectorBase(ThisVector&&); /* Move constructor. */ + ThisVector& operator=(ThisVector&&); /* Move assignment. */ + ~VectorBase(); - /* accessors */ + /* accessors */ - const AllocPolicy& allocPolicy() const { - return *this; - } + const AllocPolicy& allocPolicy() const { return *this; } - AllocPolicy& allocPolicy() { - return *this; - } + AllocPolicy& allocPolicy() { return *this; } - enum { InlineLength = N }; + enum { InlineLength = N }; - size_t length() const { - return mLength; - } + size_t length() const { return mLength; } - bool empty() const { - return mLength == 0; - } + bool empty() const { return mLength == 0; } - size_t capacity() const { - return mCapacity; - } + size_t capacity() const { return mCapacity; } - T* begin() { - MOZ_ASSERT(!entered); - return mBegin; - } + T* begin() + { + MOZ_ASSERT(!mEntered); + return mBegin; + } - const T* begin() const { - MOZ_ASSERT(!entered); - return mBegin; - } + const T* begin() const + { + MOZ_ASSERT(!mEntered); + return mBegin; + } - T* end() { - MOZ_ASSERT(!entered); - return mBegin + mLength; - } + T* end() + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } - const T* end() const { - MOZ_ASSERT(!entered); - return mBegin + mLength; - } + const T* end() const + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } - T& operator[](size_t i) { - MOZ_ASSERT(!entered); - MOZ_ASSERT(i < mLength); - return begin()[i]; - } + T& operator[](size_t aIndex) + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } - const T& operator[](size_t i) const { - MOZ_ASSERT(!entered); - MOZ_ASSERT(i < mLength); - return begin()[i]; - } + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } - T& back() { - MOZ_ASSERT(!entered); - MOZ_ASSERT(!empty()); - return *(end() - 1); - } + T& back() + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } - const T& back() const { - MOZ_ASSERT(!entered); - MOZ_ASSERT(!empty()); - return *(end() - 1); - } + const T& back() const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } - class Range + class Range + { + friend class VectorBase; + T* mCur; + T* mEnd; + Range(T* aCur, T* aEnd) + : mCur(aCur) + , mEnd(aEnd) { - friend class VectorBase; - T* cur_; - T* end_; - Range(T* cur, T* end) : cur_(cur), end_(end) {} - - public: - Range() {} - bool empty() const { return cur_ == end_; } - size_t remain() const { return end_ - cur_; } - T& front() const { return *cur_; } - void popFront() { MOZ_ASSERT(!empty()); ++cur_; } - T popCopyFront() { MOZ_ASSERT(!empty()); return *cur_++; } - }; - - Range all() { - return Range(begin(), end()); + MOZ_ASSERT(aCur <= aEnd); } - /* mutators */ + public: + Range() {} + bool empty() const { return mCur == mEnd; } + size_t remain() const { return PointerRangeSize(mCur, mEnd); } + T& front() const { MOZ_ASSERT(!empty()); return *mCur; } + void popFront() { MOZ_ASSERT(!empty()); ++mCur; } + T popCopyFront() { MOZ_ASSERT(!empty()); return *mCur++; } + }; - /** - * Given that the vector is empty and has no inline storage, grow to - * |capacity|. - */ - bool initCapacity(size_t request); + Range all() { return Range(begin(), end()); } - /** - * If reserve(length() + N) succeeds, the N next appends are guaranteed to - * succeed. - */ - bool reserve(size_t request); + /* mutators */ - /** - * Destroy elements in the range [end() - incr, end()). Does not deallocate - * or unreserve storage for those elements. - */ - void shrinkBy(size_t incr); + /** + * Given that the vector is empty and has no inline storage, grow to + * |capacity|. + */ + bool initCapacity(size_t aRequest); - /** Grow the vector by incr elements. */ - bool growBy(size_t incr); + /** + * If reserve(length() + N) succeeds, the N next appends are guaranteed to + * succeed. + */ + bool reserve(size_t aRequest); - /** Call shrinkBy or growBy based on whether newSize > length(). */ - bool resize(size_t newLength); + /** + * Destroy elements in the range [end() - aIncr, end()). Does not deallocate + * or unreserve storage for those elements. + */ + void shrinkBy(size_t aIncr); - /** - * Increase the length of the vector, but don't initialize the new elements - * -- leave them as uninitialized memory. - */ - bool growByUninitialized(size_t incr); - bool resizeUninitialized(size_t newLength); + /** Grow the vector by aIncr elements. */ + bool growBy(size_t aIncr); - /** Shorthand for shrinkBy(length()). */ - void clear(); + /** Call shrinkBy or growBy based on whether newSize > length(). */ + bool resize(size_t aNewLength); - /** Clears and releases any heap-allocated storage. */ - void clearAndFree(); + /** + * Increase the length of the vector, but don't initialize the new elements + * -- leave them as uninitialized memory. + */ + bool growByUninitialized(size_t aIncr); + bool resizeUninitialized(size_t aNewLength); - /** - * If true, appending |needed| elements won't reallocate elements storage. - * This *doesn't* mean that infallibleAppend may be used! You still must - * reserve the extra space, even if this method indicates that appends won't - * need to reallocate elements storage. - */ - bool canAppendWithoutRealloc(size_t needed) const; + /** Shorthand for shrinkBy(length()). */ + void clear(); - /** Potentially fallible append operations. */ + /** Clears and releases any heap-allocated storage. */ + void clearAndFree(); - /** - * This can take either a T& or a T&&. Given a T&&, it moves |u| into the - * vector, instead of copying it. If it fails, |u| is left unmoved. ("We are - * not amused.") - */ - template bool append(U&& u); + /** + * If true, appending |aNeeded| elements won't reallocate elements storage. + * This *doesn't* mean that infallibleAppend may be used! You still must + * reserve the extra space, even if this method indicates that appends won't + * need to reallocate elements storage. + */ + bool canAppendWithoutRealloc(size_t aNeeded) const; - template - bool appendAll(const VectorBase& u); - bool appendN(const T& t, size_t n); - template bool append(const U* begin, const U* end); - template bool append(const U* begin, size_t length); + /** Potentially fallible append operations. */ - /* - * Guaranteed-infallible append operations for use upon vectors whose - * memory has been pre-reserved. Don't use this if you haven't reserved the - * memory! - */ - template void infallibleAppend(U&& u) { - internalAppend(Forward(u)); - } - void infallibleAppendN(const T& t, size_t n) { - internalAppendN(t, n); - } - template void infallibleAppend(const U* aBegin, const U* aEnd) { - internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); - } - template void infallibleAppend(const U* aBegin, size_t aLength) { - internalAppend(aBegin, aLength); - } + /** + * This can take either a T& or a T&&. Given a T&&, it moves |aU| into the + * vector, instead of copying it. If it fails, |aU| is left unmoved. ("We are + * not amused.") + */ + template bool append(U&& aU); + + template + bool appendAll(const VectorBase& aU); + bool appendN(const T& aT, size_t aN); + template bool append(const U* aBegin, const U* aEnd); + template bool append(const U* aBegin, size_t aLength); - void popBack(); + /* + * Guaranteed-infallible append operations for use upon vectors whose + * memory has been pre-reserved. Don't use this if you haven't reserved the + * memory! + */ + template void infallibleAppend(U&& aU) + { + internalAppend(Forward(aU)); + } + void infallibleAppendN(const T& aT, size_t aN) + { + internalAppendN(aT, aN); + } + template void infallibleAppend(const U* aBegin, const U* aEnd) + { + internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); + } + template void infallibleAppend(const U* aBegin, size_t aLength) + { + internalAppend(aBegin, aLength); + } - T popCopy(); + void popBack(); - /** - * Transfers ownership of the internal buffer used by this vector to the - * caller. (It's the caller's responsibility to properly deallocate this - * buffer, in accordance with this vector's AllocPolicy.) After this call, - * the vector is empty. Since the returned buffer may need to be allocated - * (if the elements are currently stored in-place), the call can fail, - * returning nullptr. - * - * N.B. Although a T*, only the range [0, length()) is constructed. - */ - T* extractRawBuffer(); + T popCopy(); - /** - * Transfer ownership of an array of objects into the vector. The caller - * must have allocated the array in accordance with this vector's - * AllocPolicy. - * - * N.B. This call assumes that there are no uninitialized elements in the - * passed array. - */ - void replaceRawBuffer(T* p, size_t length); + /** + * Transfers ownership of the internal buffer used by this vector to the + * caller. (It's the caller's responsibility to properly deallocate this + * buffer, in accordance with this vector's AllocPolicy.) After this call, + * the vector is empty. Since the returned buffer may need to be allocated + * (if the elements are currently stored in-place), the call can fail, + * returning nullptr. + * + * N.B. Although a T*, only the range [0, length()) is constructed. + */ + T* extractRawBuffer(); + + /** + * Transfer ownership of an array of objects into the vector. The caller + * must have allocated the array in accordance with this vector's + * AllocPolicy. + * + * N.B. This call assumes that there are no uninitialized elements in the + * passed array. + */ + void replaceRawBuffer(T* aP, size_t aLength); + + /** + * Places |aVal| at position |aP|, shifting existing elements from |aP| onward + * one position higher. On success, |aP| should not be reused because it'll + * be a dangling pointer if reallocation of the vector storage occurred; the + * return value should be used instead. On failure, nullptr is returned. + * + * Example usage: + * + * if (!(p = vec.insert(p, val))) { + * + * } + * + * + * This is inherently a linear-time operation. Be careful! + */ + template + T* insert(T* aP, U&& aVal); - /** - * Places |val| at position |p|, shifting existing elements from |p| onward - * one position higher. On success, |p| should not be reused because it'll - * be a dangling pointer if reallocation of the vector storage occurred; the - * return value should be used instead. On failure, nullptr is returned. - * - * Example usage: - * - * if (!(p = vec.insert(p, val))) - * - * - * - * This is inherently a linear-time operation. Be careful! - */ - template - T* insert(T* p, U&& val); + /** + * Removes the element |aT|, which must fall in the bounds [begin, end), + * shifting existing elements from |aT + 1| onward one position lower. + */ + void erase(T* aT); - /** - * Removes the element |t|, which must fall in the bounds [begin, end), - * shifting existing elements from |t + 1| onward one position lower. - */ - void erase(T* t); + /** + * Removes the elements [|aBegin|, |aEnd|), which must fall in the bounds + * [begin, end), shifting existing elements from |aEnd + 1| onward to aBegin's + * old position. + */ + void erase(T* aBegin, T* aEnd); - /** - * Measure the size of the vector's heap-allocated storage. - */ - size_t sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const; + /** + * Measure the size of the vector's heap-allocated storage. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const; - /** - * Like sizeOfExcludingThis, but also measures the size of the vector - * object (which must be heap-allocated) itself. - */ - size_t sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const; + /** + * Like sizeOfExcludingThis, but also measures the size of the vector + * object (which must be heap-allocated) itself. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; - void swap(ThisVector& other); + void swap(ThisVector& aOther); - private: - VectorBase(const VectorBase&) MOZ_DELETE; - void operator=(const VectorBase&) MOZ_DELETE; +private: + VectorBase(const VectorBase&) MOZ_DELETE; + void operator=(const VectorBase&) MOZ_DELETE; - /* Move-construct/assign only from our derived class, ThisVector. */ - VectorBase(VectorBase&&) MOZ_DELETE; - void operator=(VectorBase&&) MOZ_DELETE; + /* Move-construct/assign only from our derived class, ThisVector. */ + VectorBase(VectorBase&&) MOZ_DELETE; + void operator=(VectorBase&&) MOZ_DELETE; }; /* This does the re-entrancy check plus several other sanity checks. */ #define MOZ_REENTRANCY_GUARD_ET_AL \ ReentrancyGuard g(*this); \ - MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == sInlineCapacity); \ + MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == kInlineCapacity); \ MOZ_ASSERT(reserved() <= mCapacity); \ MOZ_ASSERT(mLength <= reserved()); \ MOZ_ASSERT(mLength <= mCapacity) @@ -569,39 +618,39 @@ class VectorBase : private AllocPolicy template MOZ_ALWAYS_INLINE -VectorBase::VectorBase(AP ap) - : AP(ap), - mLength(0), - mCapacity(sInlineCapacity) +VectorBase::VectorBase(AP aAP) + : AP(aAP) + , mLength(0) + , mCapacity(kInlineCapacity) #ifdef DEBUG - , mReserved(sInlineCapacity), - entered(false) + , mReserved(kInlineCapacity) + , mEntered(false) #endif { - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); } /* Move constructor. */ template MOZ_ALWAYS_INLINE -VectorBase::VectorBase(TV&& rhs) - : AllocPolicy(Move(rhs)) +VectorBase::VectorBase(TV&& aRhs) + : AllocPolicy(Move(aRhs)) #ifdef DEBUG - , entered(false) + , mEntered(false) #endif { - mLength = rhs.mLength; - mCapacity = rhs.mCapacity; + mLength = aRhs.mLength; + mCapacity = aRhs.mCapacity; #ifdef DEBUG - mReserved = rhs.mReserved; + mReserved = aRhs.mReserved; #endif - if (rhs.usingInlineStorage()) { + if (aRhs.usingInlineStorage()) { /* We can't move the buffer over in this case, so copy elements. */ - mBegin = static_cast(storage.addr()); - Impl::moveConstruct(mBegin, rhs.beginNoCheck(), rhs.endNoCheck()); + mBegin = static_cast(mStorage.addr()); + Impl::moveConstruct(mBegin, aRhs.beginNoCheck(), aRhs.endNoCheck()); /* - * Leave rhs's mLength, mBegin, mCapacity, and mReserved as they are. + * Leave aRhs's mLength, mBegin, mCapacity, and mReserved as they are. * The elements in its in-line storage still need to be destroyed. */ } else { @@ -609,26 +658,25 @@ VectorBase::VectorBase(TV&& rhs) * Take src's buffer, and turn src into an empty vector using * in-line storage. */ - mBegin = rhs.mBegin; - rhs.mBegin = static_cast(rhs.storage.addr()); - rhs.mCapacity = sInlineCapacity; - rhs.mLength = 0; + mBegin = aRhs.mBegin; + aRhs.mBegin = static_cast(aRhs.mStorage.addr()); + aRhs.mCapacity = kInlineCapacity; + aRhs.mLength = 0; #ifdef DEBUG - rhs.mReserved = sInlineCapacity; + aRhs.mReserved = kInlineCapacity; #endif } } /* Move assignment. */ template -MOZ_ALWAYS_INLINE -TV& -VectorBase::operator=(TV&& rhs) +MOZ_ALWAYS_INLINE TV& +VectorBase::operator=(TV&& aRhs) { - MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + MOZ_ASSERT(this != &aRhs, "self-move assignment is prohibited"); TV* tv = static_cast(this); tv->~TV(); - new(tv) TV(Move(rhs)); + new(tv) TV(Move(aRhs)); return *tv; } @@ -638,26 +686,28 @@ VectorBase::~VectorBase() { MOZ_REENTRANCY_GUARD_ET_AL; Impl::destroy(beginNoCheck(), endNoCheck()); - if (!usingInlineStorage()) + if (!usingInlineStorage()) { this->free_(beginNoCheck()); + } } /* - * This function will create a new heap buffer with capacity newCap, + * This function will create a new heap buffer with capacity aNewCap, * move all elements in the inline buffer to this new buffer, * and fail on OOM. */ template inline bool -VectorBase::convertToHeapStorage(size_t newCap) +VectorBase::convertToHeapStorage(size_t aNewCap) { MOZ_ASSERT(usingInlineStorage()); /* Allocate buffer. */ - MOZ_ASSERT(!detail::CapacityHasExcessSpace(newCap)); - T* newBuf = reinterpret_cast(this->malloc_(newCap * sizeof(T))); - if (!newBuf) + MOZ_ASSERT(!detail::CapacityHasExcessSpace(aNewCap)); + T* newBuf = reinterpret_cast(this->malloc_(aNewCap * sizeof(T))); + if (!newBuf) { return false; + } /* Copy inline elements into heap buffer. */ Impl::moveConstruct(newBuf, beginNoCheck(), endNoCheck()); @@ -666,15 +716,15 @@ VectorBase::convertToHeapStorage(size_t newCap) /* Switch in heap buffer. */ mBegin = newBuf; /* mLength is unchanged. */ - mCapacity = newCap; + mCapacity = aNewCap; return true; } template MOZ_NEVER_INLINE bool -VectorBase::growStorageBy(size_t incr) +VectorBase::growStorageBy(size_t aIncr) { - MOZ_ASSERT(mLength + incr > mCapacity); + MOZ_ASSERT(mLength + aIncr > mCapacity); MOZ_ASSERT_IF(!usingInlineStorage(), !detail::CapacityHasExcessSpace(mCapacity)); @@ -688,11 +738,11 @@ VectorBase::growStorageBy(size_t incr) size_t newCap; - if (incr == 1) { + if (aIncr == 1) { if (usingInlineStorage()) { /* This case occurs in ~70--80% of the calls to this function. */ size_t newSize = - tl::RoundUpPow2<(sInlineCapacity + 1) * sizeof(T)>::value; + tl::RoundUpPow2<(kInlineCapacity + 1) * sizeof(T)>::value; newCap = newSize / sizeof(T); goto convert; } @@ -725,13 +775,14 @@ VectorBase::growStorageBy(size_t incr) * then there might be space for one more element. */ newCap = mLength * 2; - if (detail::CapacityHasExcessSpace(newCap)) + if (detail::CapacityHasExcessSpace(newCap)) { newCap += 1; + } } else { /* This case occurs in ~2% of the calls to this function. */ - size_t newMinCap = mLength + incr; + size_t newMinCap = mLength + aIncr; - /* Did mLength + incr overflow? Will newCap * sizeof(T) overflow? */ + /* Did mLength + aIncr overflow? Will newCap * sizeof(T) overflow? */ if (newMinCap < mLength || newMinCap & tl::MulOverflowMask<2 * sizeof(T)>::value) { @@ -745,7 +796,7 @@ VectorBase::growStorageBy(size_t incr) } if (usingInlineStorage()) { - convert: +convert: return convertToHeapStorage(newCap); } @@ -755,34 +806,37 @@ VectorBase::growStorageBy(size_t incr) template inline bool -VectorBase::initCapacity(size_t request) +VectorBase::initCapacity(size_t aRequest) { MOZ_ASSERT(empty()); MOZ_ASSERT(usingInlineStorage()); - if (request == 0) + if (aRequest == 0) { return true; - T* newbuf = reinterpret_cast(this->malloc_(request * sizeof(T))); - if (!newbuf) + } + T* newbuf = reinterpret_cast(this->malloc_(aRequest * sizeof(T))); + if (!newbuf) { return false; + } mBegin = newbuf; - mCapacity = request; + mCapacity = aRequest; #ifdef DEBUG - mReserved = request; + mReserved = aRequest; #endif return true; } template inline bool -VectorBase::reserve(size_t request) +VectorBase::reserve(size_t aRequest) { MOZ_REENTRANCY_GUARD_ET_AL; - if (request > mCapacity && !growStorageBy(request - mLength)) + if (aRequest > mCapacity && !growStorageBy(aRequest - mLength)) { return false; - + } #ifdef DEBUG - if (request > mReserved) - mReserved = request; + if (aRequest > mReserved) { + mReserved = aRequest; + } MOZ_ASSERT(mLength <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); #endif @@ -791,69 +845,73 @@ VectorBase::reserve(size_t request) template inline void -VectorBase::shrinkBy(size_t incr) +VectorBase::shrinkBy(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - MOZ_ASSERT(incr <= mLength); - Impl::destroy(endNoCheck() - incr, endNoCheck()); - mLength -= incr; + MOZ_ASSERT(aIncr <= mLength); + Impl::destroy(endNoCheck() - aIncr, endNoCheck()); + mLength -= aIncr; } template MOZ_ALWAYS_INLINE bool -VectorBase::growBy(size_t incr) +VectorBase::growBy(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - if (incr > mCapacity - mLength && !growStorageBy(incr)) + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { return false; - - MOZ_ASSERT(mLength + incr <= mCapacity); - T* newend = endNoCheck() + incr; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + T* newend = endNoCheck() + aIncr; Impl::initialize(endNoCheck(), newend); - mLength += incr; + mLength += aIncr; #ifdef DEBUG - if (mLength > mReserved) + if (mLength > mReserved) { mReserved = mLength; + } #endif return true; } template MOZ_ALWAYS_INLINE bool -VectorBase::growByUninitialized(size_t incr) +VectorBase::growByUninitialized(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - if (incr > mCapacity - mLength && !growStorageBy(incr)) + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { return false; - - MOZ_ASSERT(mLength + incr <= mCapacity); - mLength += incr; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + mLength += aIncr; #ifdef DEBUG - if (mLength > mReserved) + if (mLength > mReserved) { mReserved = mLength; + } #endif return true; } template inline bool -VectorBase::resize(size_t newLength) +VectorBase::resize(size_t aNewLength) { size_t curLength = mLength; - if (newLength > curLength) - return growBy(newLength - curLength); - shrinkBy(curLength - newLength); + if (aNewLength > curLength) { + return growBy(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); return true; } template MOZ_ALWAYS_INLINE bool -VectorBase::resizeUninitialized(size_t newLength) +VectorBase::resizeUninitialized(size_t aNewLength) { size_t curLength = mLength; - if (newLength > curLength) - return growByUninitialized(newLength - curLength); - shrinkBy(curLength - newLength); + if (aNewLength > curLength) { + return growByUninitialized(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); return true; } @@ -872,166 +930,186 @@ VectorBase::clearAndFree() { clear(); - if (usingInlineStorage()) + if (usingInlineStorage()) { return; - + } this->free_(beginNoCheck()); - mBegin = static_cast(storage.addr()); - mCapacity = sInlineCapacity; + mBegin = static_cast(mStorage.addr()); + mCapacity = kInlineCapacity; #ifdef DEBUG - mReserved = sInlineCapacity; + mReserved = kInlineCapacity; #endif } template inline bool -VectorBase::canAppendWithoutRealloc(size_t needed) const +VectorBase::canAppendWithoutRealloc(size_t aNeeded) const { - return mLength + needed <= mCapacity; + return mLength + aNeeded <= mCapacity; } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppendAll(const VectorBase& other) +VectorBase::internalAppendAll( + const VectorBase& aOther) { - internalAppend(other.begin(), other.length()); + internalAppend(aOther.begin(), aOther.length()); } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppend(U&& u) +VectorBase::internalAppend(U&& aU) { MOZ_ASSERT(mLength + 1 <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - new(endNoCheck()) T(Forward(u)); + new(endNoCheck()) T(Forward(aU)); ++mLength; } template MOZ_ALWAYS_INLINE bool -VectorBase::appendN(const T& t, size_t needed) +VectorBase::appendN(const T& aT, size_t aNeeded) { MOZ_REENTRANCY_GUARD_ET_AL; - if (mLength + needed > mCapacity && !growStorageBy(needed)) + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { return false; - + } #ifdef DEBUG - if (mLength + needed > mReserved) - mReserved = mLength + needed; + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } #endif - internalAppendN(t, needed); + internalAppendN(aT, aNeeded); return true; } template MOZ_ALWAYS_INLINE void -VectorBase::internalAppendN(const T& t, size_t needed) +VectorBase::internalAppendN(const T& aT, size_t aNeeded) { - MOZ_ASSERT(mLength + needed <= mReserved); + MOZ_ASSERT(mLength + aNeeded <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - Impl::copyConstructN(endNoCheck(), needed, t); - mLength += needed; + Impl::copyConstructN(endNoCheck(), aNeeded, aT); + mLength += aNeeded; } template template inline T* -VectorBase::insert(T* p, U&& val) +VectorBase::insert(T* aP, U&& aVal) { - MOZ_ASSERT(begin() <= p); - MOZ_ASSERT(p <= end()); - size_t pos = p - begin(); + MOZ_ASSERT(begin() <= aP); + MOZ_ASSERT(aP <= end()); + size_t pos = aP - begin(); MOZ_ASSERT(pos <= mLength); size_t oldLength = mLength; if (pos == oldLength) { - if (!append(Forward(val))) + if (!append(Forward(aVal))) { return nullptr; + } } else { T oldBack = Move(back()); - if (!append(Move(oldBack))) /* Dup the last element. */ + if (!append(Move(oldBack))) { /* Dup the last element. */ return nullptr; - for (size_t i = oldLength; i > pos; --i) + } + for (size_t i = oldLength; i > pos; --i) { (*this)[i] = Move((*this)[i - 1]); - (*this)[pos] = Forward(val); + } + (*this)[pos] = Forward(aVal); } return begin() + pos; } template inline void -VectorBase::erase(T* it) +VectorBase::erase(T* aIt) { - MOZ_ASSERT(begin() <= it); - MOZ_ASSERT(it < end()); - while (it + 1 < end()) { - *it = *(it + 1); - ++it; + MOZ_ASSERT(begin() <= aIt); + MOZ_ASSERT(aIt < end()); + while (aIt + 1 < end()) { + *aIt = Move(*(aIt + 1)); + ++aIt; } - popBack(); + popBack(); +} + +template +inline void +VectorBase::erase(T* aBegin, T* aEnd) +{ + MOZ_ASSERT(begin() <= aBegin); + MOZ_ASSERT(aBegin <= aEnd); + MOZ_ASSERT(aEnd <= end()); + while (aEnd < end()) { + *aBegin++ = Move(*aEnd++); + } + shrinkBy(aEnd - aBegin); } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(const U* insBegin, const U* insEnd) +VectorBase::append(const U* aInsBegin, const U* aInsEnd) { MOZ_REENTRANCY_GUARD_ET_AL; - size_t needed = PointerRangeSize(insBegin, insEnd); - if (mLength + needed > mCapacity && !growStorageBy(needed)) + size_t aNeeded = PointerRangeSize(aInsBegin, aInsEnd); + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { return false; - + } #ifdef DEBUG - if (mLength + needed > mReserved) - mReserved = mLength + needed; + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } #endif - internalAppend(insBegin, needed); + internalAppend(aInsBegin, aNeeded); return true; } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppend(const U* insBegin, size_t insLength) +VectorBase::internalAppend(const U* aInsBegin, size_t aInsLength) { - MOZ_ASSERT(mLength + insLength <= mReserved); + MOZ_ASSERT(mLength + aInsLength <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - Impl::copyConstruct(endNoCheck(), insBegin, insBegin + insLength); - mLength += insLength; + Impl::copyConstruct(endNoCheck(), aInsBegin, aInsBegin + aInsLength); + mLength += aInsLength; } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(U&& u) +VectorBase::append(U&& aU) { MOZ_REENTRANCY_GUARD_ET_AL; - if (mLength == mCapacity && !growStorageBy(1)) + if (mLength == mCapacity && !growStorageBy(1)) { return false; - + } #ifdef DEBUG - if (mLength + 1 > mReserved) + if (mLength + 1 > mReserved) { mReserved = mLength + 1; + } #endif - internalAppend(Forward(u)); + internalAppend(Forward(aU)); return true; } template template MOZ_ALWAYS_INLINE bool -VectorBase::appendAll(const VectorBase& other) +VectorBase::appendAll(const VectorBase& aOther) { - return append(other.begin(), other.length()); + return append(aOther.begin(), aOther.length()); } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(const U *insBegin, size_t insLength) +VectorBase::append(const U* aInsBegin, size_t aInsLength) { - return append(insBegin, insBegin + insLength); + return append(aInsBegin, aInsBegin + aInsLength); } template @@ -1060,19 +1138,20 @@ VectorBase::extractRawBuffer() T* ret; if (usingInlineStorage()) { ret = reinterpret_cast(this->malloc_(mLength * sizeof(T))); - if (!ret) + if (!ret) { return nullptr; + } Impl::copyConstruct(ret, beginNoCheck(), endNoCheck()); Impl::destroy(beginNoCheck(), endNoCheck()); /* mBegin, mCapacity are unchanged. */ mLength = 0; } else { ret = mBegin; - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); mLength = 0; - mCapacity = sInlineCapacity; + mCapacity = kInlineCapacity; #ifdef DEBUG - mReserved = sInlineCapacity; + mReserved = kInlineCapacity; #endif } return ret; @@ -1080,30 +1159,31 @@ VectorBase::extractRawBuffer() template inline void -VectorBase::replaceRawBuffer(T* p, size_t aLength) +VectorBase::replaceRawBuffer(T* aP, size_t aLength) { MOZ_REENTRANCY_GUARD_ET_AL; /* Destroy what we have. */ Impl::destroy(beginNoCheck(), endNoCheck()); - if (!usingInlineStorage()) + if (!usingInlineStorage()) { this->free_(beginNoCheck()); + } /* Take in the new buffer. */ - if (aLength <= sInlineCapacity) { + if (aLength <= kInlineCapacity) { /* - * We convert to inline storage if possible, even though p might + * We convert to inline storage if possible, even though aP might * otherwise be acceptable. Maybe this behaviour should be * specifiable with an argument to this function. */ - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); mLength = aLength; - mCapacity = sInlineCapacity; - Impl::moveConstruct(mBegin, p, p + aLength); - Impl::destroy(p, p + aLength); - this->free_(p); + mCapacity = kInlineCapacity; + Impl::moveConstruct(mBegin, aP, aP + aLength); + Impl::destroy(aP, aP + aLength); + this->free_(aP); } else { - mBegin = p; + mBegin = aP; mLength = aLength; mCapacity = aLength; } @@ -1114,42 +1194,42 @@ VectorBase::replaceRawBuffer(T* p, size_t aLength) template inline size_t -VectorBase::sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const +VectorBase::sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { - return usingInlineStorage() ? 0 : mallocSizeOf(beginNoCheck()); + return usingInlineStorage() ? 0 : aMallocSizeOf(beginNoCheck()); } template inline size_t -VectorBase::sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const +VectorBase::sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { - return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); } template inline void -VectorBase::swap(TV& other) +VectorBase::swap(TV& aOther) { static_assert(N == 0, "still need to implement this for N != 0"); // This only works when inline storage is always empty. - if (!usingInlineStorage() && other.usingInlineStorage()) { - other.mBegin = mBegin; + if (!usingInlineStorage() && aOther.usingInlineStorage()) { + aOther.mBegin = mBegin; mBegin = inlineStorage(); - } else if (usingInlineStorage() && !other.usingInlineStorage()) { - mBegin = other.mBegin; - other.mBegin = other.inlineStorage(); - } else if (!usingInlineStorage() && !other.usingInlineStorage()) { - Swap(mBegin, other.mBegin); + } else if (usingInlineStorage() && !aOther.usingInlineStorage()) { + mBegin = aOther.mBegin; + aOther.mBegin = aOther.inlineStorage(); + } else if (!usingInlineStorage() && !aOther.usingInlineStorage()) { + Swap(mBegin, aOther.mBegin); } else { // This case is a no-op, since we'd set both to use their inline storage. } - Swap(mLength, other.mLength); - Swap(mCapacity, other.mCapacity); + Swap(mLength, aOther.mLength); + Swap(mCapacity, aOther.mCapacity); #ifdef DEBUG - Swap(mReserved, other.mReserved); + Swap(mReserved, aOther.mReserved); #endif } @@ -1180,14 +1260,15 @@ class Vector AllocPolicy, Vector > { - typedef VectorBase Base; - - public: - Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} - Vector(Vector&& vec) : Base(Move(vec)) {} - Vector& operator=(Vector&& vec) { - return Base::operator=(Move(vec)); - } + typedef VectorBase Base; + +public: + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + Vector(Vector&& vec) : Base(Move(vec)) {} + Vector& operator=(Vector&& aOther) + { + return Base::operator=(Move(aOther)); + } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/WeakPtr.h b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/WeakPtr.h index 0165e3a017..07f00bc295 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/WeakPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/linux/mozilla/WeakPtr.h @@ -14,21 +14,29 @@ * the WeakPtrs to it and allows the WeakReference to live beyond the lifetime * of 'Foo'. * + * PLEASE NOTE: This weak pointer implementation is not thread-safe. + * + * Note that when deriving from SupportsWeakPtr you should add + * MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public section of your + * class, where ClassName is the name of your class. + * * The overhead of WeakPtr is that accesses to 'Foo' becomes an additional * dereference, and an additional heap allocated pointer sized object shared * between all of the WeakPtrs. * * Example of usage: * - * // To have a class C support weak pointers, inherit from SupportsWeakPtr. + * // To have a class C support weak pointers, inherit from + * // SupportsWeakPtr. * class C : public SupportsWeakPtr * { - * public: - * int num; - * void act(); + * public: + * MOZ_DECLARE_REFCOUNTED_TYPENAME(C) + * int mNum; + * void act(); * }; * - * C* ptr = new C(); + * C* ptr = new C(); * * // Get weak pointers to ptr. The first time asWeakPtr is called * // a reference counted WeakReference object is created that @@ -39,7 +47,7 @@ * * // Test a weak pointer for validity before using it. * if (weak) { - * weak->num = 17; + * weak->mNum = 17; * weak->act(); * } * @@ -59,11 +67,14 @@ #ifndef mozilla_WeakPtr_h #define mozilla_WeakPtr_h +#include "mozilla/ArrayUtils.h" #include "mozilla/Assertions.h" #include "mozilla/NullPtr.h" #include "mozilla/RefPtr.h" #include "mozilla/TypeTraits.h" +#include + namespace mozilla { template class WeakPtrBase; @@ -71,23 +82,48 @@ template class SupportsWeakPtrBase; namespace detail { -// This can live beyond the lifetime of the class derived from SupportsWeakPtrBase. +// This can live beyond the lifetime of the class derived from +// SupportsWeakPtrBase. template class WeakReference : public ::mozilla::RefCounted > { - public: - explicit WeakReference(T* p) : ptr(p) {} - T* get() const { - return ptr; - } - - private: - friend class WeakPtrBase >; - friend class SupportsWeakPtrBase >; - void detach() { - ptr = nullptr; - } - T* ptr; +public: + explicit WeakReference(T* p) : mPtr(p) {} + + T* get() const { return mPtr; } + +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#ifdef XP_WIN +#define snprintf _snprintf +#endif + const char* typeName() const + { + static char nameBuffer[1024]; + const char* innerType = mPtr->typeName(); + // We could do fancier length checks at runtime, but innerType is + // controlled by us so we can ensure that this never causes a buffer + // overflow by this assertion. + MOZ_ASSERT(strlen(innerType) + sizeof("WeakReference<>") < + ArrayLength(nameBuffer), + "Exceedingly large type name"); + snprintf(nameBuffer, ArrayLength(nameBuffer), "WeakReference<%s>", + innerType); + // This is usually not OK, but here we are returning a pointer to a static + // buffer which will immediately be used by the caller. + return nameBuffer; + } + + size_t typeSize() const { return sizeof(*this); } +#undef snprintf +#endif + +private: + friend class WeakPtrBase >; + friend class SupportsWeakPtrBase >; + + void detach() { mPtr = nullptr; } + + T* mPtr; }; } // namespace detail @@ -95,25 +131,29 @@ class WeakReference : public ::mozilla::RefCounted > template class SupportsWeakPtrBase { - public: - WeakPtrBase asWeakPtr() { - if (!weakRef) - weakRef = new WeakReference(static_cast(this)); - return WeakPtrBase(weakRef); +public: + WeakPtrBase asWeakPtr() + { + if (!weakRef) { + weakRef = new WeakReference(static_cast(this)); } - - protected: - ~SupportsWeakPtrBase() { - static_assert(IsBaseOf, T>::value, - "T must derive from SupportsWeakPtrBase"); - if (weakRef) - weakRef->detach(); + return WeakPtrBase(weakRef); + } + +protected: + ~SupportsWeakPtrBase() + { + static_assert(IsBaseOf, T>::value, + "T must derive from SupportsWeakPtrBase"); + if (weakRef) { + weakRef->detach(); } + } - private: - friend class WeakPtrBase; +private: + friend class WeakPtrBase; - RefPtr weakRef; + RefPtr weakRef; }; template @@ -124,42 +164,37 @@ class SupportsWeakPtr : public SupportsWeakPtrBase > template class WeakPtrBase { - public: - WeakPtrBase(const WeakPtrBase& o) : ref(o.ref) {} - // Ensure that ref is dereferenceable in the uninitialized state - WeakPtrBase() : ref(new WeakReference(nullptr)) {} +public: + WeakPtrBase(const WeakPtrBase& aOther) + : mRef(aOther.mRef) + {} - operator T*() const { - return ref->get(); - } - T& operator*() const { - return *ref->get(); - } + // Ensure that mRef is dereferenceable in the uninitialized state. + WeakPtrBase() : mRef(new WeakReference(nullptr)) {} - T* operator->() const { - return ref->get(); - } + operator T*() const { return mRef->get(); } + T& operator*() const { return *mRef->get(); } - T* get() const { - return ref->get(); - } + T* operator->() const { return mRef->get(); } + + T* get() const { return mRef->get(); } - private: - friend class SupportsWeakPtrBase; +private: + friend class SupportsWeakPtrBase; - explicit WeakPtrBase(const RefPtr &o) : ref(o) {} + explicit WeakPtrBase(const RefPtr &aOther) : mRef(aOther) {} - RefPtr ref; + RefPtr mRef; }; template class WeakPtr : public WeakPtrBase > { - typedef WeakPtrBase > Base; - public: - WeakPtr(const WeakPtr& o) : Base(o) {} - WeakPtr(const Base& o) : Base(o) {} - WeakPtr() {} + typedef WeakPtrBase > Base; +public: + WeakPtr(const WeakPtr& aOther) : Base(aOther) {} + MOZ_IMPLICIT WeakPtr(const Base& aOther) : Base(aOther) {} + WeakPtr() {} }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js-config.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js-config.h index b1bf1f80ee..d1974254e0 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js-config.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js-config.h @@ -12,6 +12,12 @@ This header file is generated by the SpiderMonkey configure script, and installed along with jsapi.h. */ +/* Define to 1 if SpiderMonkey is in debug mode. */ +/* #undef JS_DEBUG */ + +/* Define to 1 if SpiderMonkey should not use struct types in debug builds. */ +/* #undef JS_NO_JSVAL_JSID_STRUCT_TYPES */ + /* Define to 1 if SpiderMonkey should support multi-threaded clients. */ /* #undef JS_THREADSAFE */ @@ -34,8 +40,14 @@ useable. See jscpucfg.h. */ /* #undef JS_HAVE_SYS_ISA_DEFS_H */ +/* Define to 1 if SpiderMonkey is in NUNBOX32 mode. */ +/* #undef JS_NUNBOX32 */ + +/* Define to 1 if SpiderMonkey is in PUNBOX64 mode. */ +#define JS_PUNBOX64 1 + /* MOZILLA JSAPI version number components */ -#define MOZJS_MAJOR_VERSION 28 -#define MOZJS_MINOR_VERSION 0 +#define MOZJS_MAJOR_VERSION 33 +#define MOZJS_MINOR_VERSION 1 #endif /* js_config_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js.msg b/frameworks/js-bindings/external/spidermonkey/include/mac/js.msg index 5a8344163b..d342ad4506 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js.msg +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js.msg @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -105,7 +105,7 @@ MSG_DEF(JSMSG_BAD_DESTRUCT_ASS, 51, 0, JSEXN_REFERENCEERR, "invalid destr MSG_DEF(JSMSG_PAREN_AFTER_LET, 52, 0, JSEXN_SYNTAXERR, "missing ) after let head") MSG_DEF(JSMSG_CURLY_AFTER_LET, 53, 0, JSEXN_SYNTAXERR, "missing } after let block") MSG_DEF(JSMSG_MISSING_PAREN, 54, 0, JSEXN_SYNTAXERR, "unterminated parenthetical") -MSG_DEF(JSMSG_UNTERM_CLASS, 55, 1, JSEXN_SYNTAXERR, "unterminated character class {0}") +MSG_DEF(JSMSG_UNTERM_CLASS, 55, 0, JSEXN_SYNTAXERR, "unterminated character class") MSG_DEF(JSMSG_TRAILING_SLASH, 56, 0, JSEXN_SYNTAXERR, "trailing \\ in regular expression") MSG_DEF(JSMSG_BAD_CLASS_RANGE, 57, 0, JSEXN_SYNTAXERR, "invalid range in character class") MSG_DEF(JSMSG_BAD_REGEXP_FLAG, 58, 1, JSEXN_SYNTAXERR, "invalid regular expression flag {0}") @@ -223,30 +223,30 @@ MSG_DEF(JSMSG_TOO_MANY_CATCH_VARS, 169, 0, JSEXN_SYNTAXERR, "too many catch v MSG_DEF(JSMSG_NEGATIVE_REPETITION_COUNT, 170, 0, JSEXN_RANGEERR, "repeat count must be non-negative") MSG_DEF(JSMSG_INVALID_FOR_OF_INIT, 171, 0, JSEXN_SYNTAXERR, "for-of loop variable declaration may not have an initializer") MSG_DEF(JSMSG_INVALID_MAP_ITERABLE, 172, 0, JSEXN_TYPEERR, "iterable for map should have array-like objects") -MSG_DEF(JSMSG_UNUSED173, 173, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED174, 174, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_NOT_A_CODEPOINT, 173, 1, JSEXN_RANGEERR, "{0} is not a valid code point") +MSG_DEF(JSMSG_BRACKET_AFTER_ARRAY_COMPREHENSION, 174, 0, JSEXN_SYNTAXERR, "missing ] after array comprehension") MSG_DEF(JSMSG_NESTING_GENERATOR, 175, 0, JSEXN_TYPEERR, "already executing generator") -MSG_DEF(JSMSG_UNUSED176, 176, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED177, 177, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED178, 178, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED179, 179, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED180, 180, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED181, 181, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_PAREN_AFTER_FOR_OF_ITERABLE, 176, 0, JSEXN_SYNTAXERR, "missing ) after for-of iterable") +MSG_DEF(JSMSG_INVALID_NORMALIZE_FORM, 177, 0, JSEXN_RANGEERR, "form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD'") +MSG_DEF(JSMSG_NOTHING_TO_REPEAT, 178, 0, JSEXN_SYNTAXERR, "nothing to repeat") +MSG_DEF(JSMSG_INVALID_GROUP, 179, 0, JSEXN_SYNTAXERR, "invalid regexp group") +MSG_DEF(JSMSG_ESCAPE_AT_END_OF_REGEXP, 180, 0, JSEXN_SYNTAXERR, "\\ at end of pattern") +MSG_DEF(JSMSG_NUMBERS_OUT_OF_ORDER, 181, 0, JSEXN_SYNTAXERR, "numbers out of order in {} quantifier.") MSG_DEF(JSMSG_BAD_GENERATOR_SEND, 182, 1, JSEXN_TYPEERR, "attempt to send {0} to newborn generator") MSG_DEF(JSMSG_SC_NOT_TRANSFERABLE, 183, 0, JSEXN_TYPEERR, "invalid transferable array for structured clone") MSG_DEF(JSMSG_SC_DUP_TRANSFERABLE, 184, 0, JSEXN_TYPEERR, "duplicate transferable for structured clone") MSG_DEF(JSMSG_CANT_REPORT_AS_NON_EXTENSIBLE, 185, 0, JSEXN_TYPEERR, "proxy can't report an extensible object as non-extensible") -MSG_DEF(JSMSG_UNUSED186, 186, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_SYMBOL_TO_STRING, 186, 0, JSEXN_TYPEERR, "can't convert symbol to string") MSG_DEF(JSMSG_UNUSED187, 187, 0, JSEXN_NONE, "") MSG_DEF(JSMSG_INCOMPATIBLE_METHOD, 188, 3, JSEXN_TYPEERR, "{0} {1} called on incompatible {2}") -MSG_DEF(JSMSG_UNUSED189, 189, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_SYMBOL_TO_PRIMITIVE, 189, 0, JSEXN_TYPEERR, "can't convert symbol object to primitive") MSG_DEF(JSMSG_UNUSED190, 190, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED191, 191, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED192, 192, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_BAD_INDEX, 191, 0, JSEXN_RANGEERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_SELFHOSTED_TOP_LEVEL_LET,192,0, JSEXN_SYNTAXERR, "self-hosted code cannot contain top-level 'let' declarations") MSG_DEF(JSMSG_BAD_FOR_EACH_LOOP, 193, 0, JSEXN_SYNTAXERR, "invalid for each loop") -MSG_DEF(JSMSG_OBJECT_WATCH_DEPRECATED,194, 0, JSEXN_TYPEERR, "Object.prototype.watch and unwatch are very slow, non-standard, and deprecated; use a getter/setter instead") -MSG_DEF(JSMSG_UNUSED195, 195, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED196, 196, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_OBJECT_WATCH_DEPRECATED,194, 0, JSEXN_NONE, "Object.prototype.watch and unwatch are very slow, non-standard, and deprecated; use a getter/setter instead") +MSG_DEF(JSMSG_TYPE_ERR_BAD_ARGS, 195, 0, JSEXN_TYPEERR, "invalid arguments") +MSG_DEF(JSMSG_REDECLARED_CATCH_IDENTIFIER, 196, 1, JSEXN_TYPEERR, "redeclaration of identifier '{0}' in catch") MSG_DEF(JSMSG_INTERNAL_INTL_ERROR, 197, 0, JSEXN_ERR, "internal error while computing Intl data") MSG_DEF(JSMSG_DEFAULT_LOCALE_ERROR, 198, 0, JSEXN_ERR, "internal error getting the default locale") MSG_DEF(JSMSG_TOO_MANY_LOCALS, 199, 0, JSEXN_SYNTAXERR, "too many local variables") @@ -260,25 +260,25 @@ MSG_DEF(JSMSG_USER_DEFINED_ERROR, 206, 0, JSEXN_ERR, "JS_ReportError was cal MSG_DEF(JSMSG_WRONG_CONSTRUCTOR, 207, 1, JSEXN_TYPEERR, "wrong constructor called for {0}") MSG_DEF(JSMSG_BAD_GENERATOR_RETURN, 208, 1, JSEXN_TYPEERR, "generator function {0} returns a value") MSG_DEF(JSMSG_BAD_ANON_GENERATOR_RETURN, 209, 0, JSEXN_TYPEERR, "anonymous generator function returns a value") -MSG_DEF(JSMSG_UNUSED210, 210, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_PROTO_SETTING_SLOW, 210, 0, JSEXN_NONE, "mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create") MSG_DEF(JSMSG_IN_AFTER_FOR_NAME, 211, 0, JSEXN_SYNTAXERR, "missing 'in' or 'of' after for") MSG_DEF(JSMSG_BAD_TRAP_RETURN_VALUE, 212, 2, JSEXN_TYPEERR,"trap {1} for {0} returned a primitive value") -MSG_DEF(JSMSG_UNUSED213, 213, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_OF_AFTER_FOR_NAME, 213, 0, JSEXN_SYNTAXERR, "missing 'of' after for") MSG_DEF(JSMSG_BAD_GENERATOR_YIELD, 214, 1, JSEXN_TYPEERR, "yield from closing generator {0}") MSG_DEF(JSMSG_BAD_GENERATOR_SYNTAX, 215, 1, JSEXN_SYNTAXERR, "{0} expression must be parenthesized") MSG_DEF(JSMSG_ARRAY_COMP_LEFTSIDE, 216, 0, JSEXN_SYNTAXERR, "invalid array comprehension left-hand side") -MSG_DEF(JSMSG_UNUSED217, 217, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_LET_COMP_BINDING, 217, 0, JSEXN_SYNTAXERR, "'let' is not a valid name for a comprehension variable") MSG_DEF(JSMSG_EMPTY_ARRAY_REDUCE, 218, 0, JSEXN_TYPEERR, "reduce of empty array with no initial value") MSG_DEF(JSMSG_BAD_SYMBOL, 219, 1, JSEXN_TYPEERR, "{0} is not a well-known @@-symbol") MSG_DEF(JSMSG_BAD_DELETE_OPERAND, 220, 0, JSEXN_REFERENCEERR, "invalid delete operand") MSG_DEF(JSMSG_BAD_INCOP_OPERAND, 221, 0, JSEXN_REFERENCEERR, "invalid increment/decrement operand") MSG_DEF(JSMSG_UNEXPECTED_TYPE, 222, 2, JSEXN_TYPEERR, "{0} is {1}") MSG_DEF(JSMSG_LET_DECL_NOT_IN_BLOCK, 223, 0, JSEXN_SYNTAXERR, "let declaration not directly within block") -MSG_DEF(JSMSG_BAD_OBJECT_INIT, 224, 0, JSEXN_SYNTAXERR, "invalid object initializer") +MSG_DEF(JSMSG_UNUSED224, 224, 0, JSEXN_NONE, "") MSG_DEF(JSMSG_CANT_SET_ARRAY_ATTRS, 225, 0, JSEXN_INTERNALERR, "can't set attributes on indexed array properties") MSG_DEF(JSMSG_EVAL_ARITY, 226, 0, JSEXN_TYPEERR, "eval accepts only one parameter") MSG_DEF(JSMSG_MISSING_FUN_ARG, 227, 2, JSEXN_TYPEERR, "missing argument {0} when calling function {1}") -MSG_DEF(JSMSG_JSON_BAD_PARSE, 228, 1, JSEXN_SYNTAXERR, "JSON.parse: {0}") +MSG_DEF(JSMSG_JSON_BAD_PARSE, 228, 3, JSEXN_SYNTAXERR, "JSON.parse: {0} at line {1} column {2} of the JSON data") MSG_DEF(JSMSG_JSON_BAD_STRINGIFY, 229, 0, JSEXN_ERR, "JSON.stringify") MSG_DEF(JSMSG_NOT_CALLABLE_OR_UNDEFINED, 230, 0, JSEXN_TYPEERR, "value is not a function or undefined") MSG_DEF(JSMSG_NOT_NONNULL_OBJECT, 231, 0, JSEXN_TYPEERR, "value is not a non-null object") @@ -353,11 +353,11 @@ MSG_DEF(JSMSG_REST_WITH_DEFAULT, 299, 0, JSEXN_SYNTAXERR, "rest parameter m MSG_DEF(JSMSG_NONDEFAULT_FORMAL_AFTER_DEFAULT, 300, 0, JSEXN_SYNTAXERR, "parameter(s) with default followed by parameter without default") MSG_DEF(JSMSG_YIELD_IN_DEFAULT, 301, 0, JSEXN_SYNTAXERR, "yield in default expression") MSG_DEF(JSMSG_INTRINSIC_NOT_DEFINED, 302, 1, JSEXN_REFERENCEERR, "no intrinsic function {0}") -MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 303, 2, JSEXN_ERR, "{0} is being assigned a {1}, but already has one") -MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 304, 1, JSEXN_RANGEERR, "invalid ParallelArray{0} argument") -MSG_DEF(JSMSG_PAR_ARRAY_BAD_PARTITION, 305, 0, JSEXN_ERR, "argument must be divisible by outermost dimension") -MSG_DEF(JSMSG_PAR_ARRAY_REDUCE_EMPTY, 306, 0, JSEXN_ERR, "cannot reduce ParallelArray object whose outermost dimension is empty") -MSG_DEF(JSMSG_PAR_ARRAY_ALREADY_FLAT, 307, 0, JSEXN_ERR, "cannot flatten 1-dimensional ParallelArray object") +MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 303, 2, JSEXN_NONE, "{0} is being assigned a {1}, but already has one") +MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 304, 0, JSEXN_RANGEERR, "invalid parallel method argument") +MSG_DEF(JSMSG_REGEXP_RUNTIME_ERROR, 305, 0, JSEXN_INTERNALERR, "an error occurred while executing regular expression") +MSG_DEF(JSMSG_DEBUG_OPTIMIZED_OUT, 306, 0, JSEXN_ERR, "variable has been optimized out") +MSG_DEF(JSMSG_NEXT_RETURNED_PRIMITIVE,307, 0, JSEXN_TYPEERR, "iterator.next() returned a non-object value") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_CONFLICT, 308, 0, JSEXN_ERR, "no conflict resolution function provided") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BOUNDS, 309, 0, JSEXN_ERR, "index in scatter vector out of bounds") MSG_DEF(JSMSG_CANT_REPORT_NC_AS_NE, 310, 0, JSEXN_TYPEERR, "proxy can't report a non-configurable own property as non-existent") @@ -391,13 +391,13 @@ MSG_DEF(JSMSG_DATE_NOT_FINITE, 337, 0, JSEXN_RANGEERR, "date value is not MSG_DEF(JSMSG_USE_ASM_DIRECTIVE_FAIL, 338, 0, JSEXN_SYNTAXERR, "\"use asm\" is only meaningful in the Directive Prologue of a function body") MSG_DEF(JSMSG_USE_ASM_TYPE_FAIL, 339, 1, JSEXN_TYPEERR, "asm.js type error: {0}") MSG_DEF(JSMSG_USE_ASM_LINK_FAIL, 340, 1, JSEXN_TYPEERR, "asm.js link error: {0}") -MSG_DEF(JSMSG_USE_ASM_TYPE_OK, 341, 1, JSEXN_ERR, "successfully compiled asm.js code ({0})") +MSG_DEF(JSMSG_USE_ASM_TYPE_OK, 341, 1, JSEXN_NONE, "Successfully compiled asm.js code ({0})") MSG_DEF(JSMSG_BAD_ARROW_ARGS, 342, 0, JSEXN_SYNTAXERR, "invalid arrow-function arguments (parentheses around the arrow-function may help)") MSG_DEF(JSMSG_YIELD_IN_ARROW, 343, 0, JSEXN_SYNTAXERR, "arrow function may not contain yield") MSG_DEF(JSMSG_WRONG_VALUE, 344, 2, JSEXN_ERR, "expected {0} but found {1}") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BAD_TARGET, 345, 1, JSEXN_ERR, "target for index {0} is not an integer") MSG_DEF(JSMSG_SELFHOSTED_UNBOUND_NAME,346, 0, JSEXN_TYPEERR, "self-hosted code may not contain unbound name lookups") -MSG_DEF(JSMSG_DEPRECATED_PRAGMA, 347, 1, JSEXN_SYNTAXERR, "Using //@ to indicate {0} pragmas is deprecated. Use //# instead") +MSG_DEF(JSMSG_DEPRECATED_PRAGMA, 347, 1, JSEXN_NONE, "Using //@ to indicate {0} pragmas is deprecated. Use //# instead") MSG_DEF(JSMSG_BAD_DESTRUCT_ASSIGN, 348, 1, JSEXN_SYNTAXERR, "can't assign to {0} using destructuring assignment") MSG_DEF(JSMSG_TYPEDOBJECT_ARRAYTYPE_BAD_ARGS, 349, 0, JSEXN_ERR, "Invalid arguments") MSG_DEF(JSMSG_TYPEDOBJECT_BINARYARRAY_BAD_INDEX, 350, 0, JSEXN_RANGEERR, "invalid or out-of-range index") @@ -414,7 +414,7 @@ MSG_DEF(JSMSG_TOO_MANY_FUN_SPREADARGS, 360, 0, JSEXN_RANGEERR, "too many functio MSG_DEF(JSMSG_DEBUG_NOT_DEBUGGEE, 361, 2, JSEXN_ERR, "{0} is not a debuggee {1}") MSG_DEF(JSMSG_TYPEDOBJECT_NOT_TYPED_OBJECT, 362, 0, JSEXN_ERR, "Expected a typed object") MSG_DEF(JSMSG_TYPEDOBJECT_NO_SUCH_PROP, 363, 1, JSEXN_TYPEERR, "No such property: {0}") -MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_BAD_ARGS, 364, 2, JSEXN_TYPEERR, "argument {0} invalid: expected {1}") +MSG_DEF(JSMSG_TYPEDOBJECT_BAD_ARGS, 364, 0, JSEXN_TYPEERR, "invalid arguments") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_UNATTACHED, 365, 0, JSEXN_TYPEERR, "handle unattached") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_BAD_TYPE, 366, 0, JSEXN_TYPEERR, "handle moved to destination of incorrect type") @@ -433,3 +433,11 @@ MSG_DEF(JSMSG_NO_EXPORT_NAME, 378, 0, JSEXN_SYNTAXERR, "missing export MSG_DEF(JSMSG_DECLARATION_AFTER_EXPORT, 379, 0, JSEXN_SYNTAXERR, "missing declaration after 'export' keyword") MSG_DEF(JSMSG_INVALID_PROTOTYPE, 380, 0, JSEXN_TYPEERR, "prototype field is not an object") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_TO_UNSIZED, 381, 0, JSEXN_TYPEERR, "cannot create a handle to an unsized type") +MSG_DEF(JSMSG_SETPROTOTYPEOF_FAIL, 382, 1, JSEXN_TYPEERR, "[[SetPrototypeOf]] failed on {0}") +MSG_DEF(JSMSG_INVALID_ARG_TYPE, 383, 3, JSEXN_TYPEERR, "Invalid type: {0} can't be a{1} {2}") +MSG_DEF(JSMSG_TERMINATED, 384, 1, JSEXN_ERR, "Script terminated by timeout at:\n{0}") +MSG_DEF(JSMSG_NO_SUCH_SELF_HOSTED_PROP, 385, 1, JSEXN_ERR, "No such property on self-hosted object: {0}") +MSG_DEF(JSMSG_PROXY_EXTENSIBILITY, 386, 0, JSEXN_TYPEERR, "proxy must report same extensiblitity as target") +MSG_DEF(JSMSG_PROXY_CONSTRUCT_OBJECT, 387, 0, JSEXN_TYPEERR, "proxy [[Construct]] must return an object") +MSG_DEF(JSMSG_PROXY_GETOWN_OBJORUNDEF, 388, 0, JSEXN_TYPEERR, "proxy [[GetOwnProperty]] must return an object or undefined") +MSG_DEF(JSMSG_CANT_REPORT_C_AS_NC, 389, 0, JSEXN_TYPEERR, "proxy can't report existing configurable property as non-configurable") diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/CallArgs.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/CallArgs.h index 5c7a201101..3be3f1575a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/CallArgs.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/CallArgs.h @@ -44,7 +44,7 @@ typedef bool /* Typedef for native functions that may be called in parallel. */ typedef bool -(* JSParallelNative)(js::ForkJoinSlice *slice, unsigned argc, JS::Value *vp); +(* JSParallelNative)(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); /* * Typedef for native functions that may be called either in parallel or @@ -63,7 +63,7 @@ JSNativeThreadSafeWrapper(JSContext *cx, unsigned argc, JS::Value *vp); template inline bool -JSParallelNativeThreadSafeWrapper(js::ForkJoinSlice *slice, unsigned argc, JS::Value *vp); +JSParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); /* * Compute |this| for the |vp| inside a JSNative, either boxing primitives or @@ -118,7 +118,7 @@ extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; namespace detail { -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_PUBLIC_API(void) CheckIsValidConstructible(Value v); #endif @@ -147,7 +147,7 @@ class MOZ_STACK_CLASS UsedRvalBase template class MOZ_STACK_CLASS CallReceiverBase : public UsedRvalBase< -#ifdef DEBUG +#ifdef JS_DEBUG WantUsedRval #else NoUsedRval @@ -197,7 +197,7 @@ class MOZ_STACK_CLASS CallReceiverBase : public UsedRvalBase< } bool isConstructing() const { -#ifdef DEBUG +#ifdef JS_DEBUG if (this->usedRval_) CheckIsValidConstructible(calleev()); #endif @@ -388,11 +388,7 @@ CallArgsFromSp(unsigned argc, Value *sp) * take a const JS::CallArgs&. */ -#define JS_CALLEE(cx,vp) ((vp)[0]) -#define JS_THIS_OBJECT(cx,vp) (JSVAL_TO_OBJECT(JS_THIS(cx,vp))) -#define JS_ARGV(cx,vp) ((vp) + 2) -#define JS_RVAL(cx,vp) (*(vp)) -#define JS_SET_RVAL(cx,vp,v) (*(vp) = (v)) +#define JS_THIS_OBJECT(cx,vp) (JS_THIS(cx,vp).toObjectOrNull()) /* * Note: if this method returns null, an error has occurred and must be @@ -401,7 +397,7 @@ CallArgsFromSp(unsigned argc, Value *sp) MOZ_ALWAYS_INLINE JS::Value JS_THIS(JSContext *cx, JS::Value *vp) { - return JSVAL_IS_PRIMITIVE(vp[1]) ? JS_ComputeThis(cx, vp) : vp[1]; + return vp[1].isPrimitive() ? JS_ComputeThis(cx, vp) : vp[1]; } /* diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/CallNonGenericMethod.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/CallNonGenericMethod.h index 05097f0294..ad9a7f708c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/CallNonGenericMethod.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/CallNonGenericMethod.h @@ -14,7 +14,7 @@ namespace JS { // Returns true if |v| is considered an acceptable this-value. -typedef bool (*IsAcceptableThis)(Handle v); +typedef bool (*IsAcceptableThis)(HandleValue v); // Implements the guts of a method; guaranteed to be provided an acceptable // this-value, as determined by a corresponding IsAcceptableThis method. @@ -92,7 +92,7 @@ CallMethodIfWrapped(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallA // tail position in a JSNative. Do not call it from any other place. // template -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool CallNonGenericMethod(JSContext *cx, CallArgs args) { HandleValue thisv = args.thisv(); @@ -102,7 +102,7 @@ CallNonGenericMethod(JSContext *cx, CallArgs args) return detail::CallMethodIfWrapped(cx, Test, Impl, args); } -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool CallNonGenericMethod(JSContext *cx, IsAcceptableThis Test, NativeImpl Impl, CallArgs args) { HandleValue thisv = args.thisv(); diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/CharacterEncoding.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/CharacterEncoding.h index 7918b83484..45c77761b3 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/CharacterEncoding.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/CharacterEncoding.h @@ -17,6 +17,8 @@ namespace js { struct ThreadSafeContext; } +class JSFlatString; + namespace JS { /* @@ -25,40 +27,45 @@ namespace JS { * byte is treated as a 2-byte character, and there is no way to pass in a * string containing characters beyond U+00FF. */ -class Latin1Chars : public mozilla::Range +class Latin1Chars : public mozilla::Range { - typedef mozilla::Range Base; + typedef mozilla::Range Base; public: Latin1Chars() : Base() {} - Latin1Chars(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) {} + Latin1Chars(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) {} + Latin1Chars(const Latin1Char *aBytes, size_t aLength) + : Base(const_cast(aBytes), aLength) + {} Latin1Chars(const char *aBytes, size_t aLength) - : Base(reinterpret_cast(const_cast(aBytes)), aLength) + : Base(reinterpret_cast(const_cast(aBytes)), aLength) {} }; /* * A Latin1Chars, but with \0 termination for C compatibility. */ -class Latin1CharsZ : public mozilla::RangedPtr +class Latin1CharsZ : public mozilla::RangedPtr { - typedef mozilla::RangedPtr Base; + typedef mozilla::RangedPtr Base; public: Latin1CharsZ() : Base(nullptr, 0) {} Latin1CharsZ(char *aBytes, size_t aLength) - : Base(reinterpret_cast(aBytes), aLength) + : Base(reinterpret_cast(aBytes), aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } - Latin1CharsZ(unsigned char *aBytes, size_t aLength) + Latin1CharsZ(Latin1Char *aBytes, size_t aLength) : Base(aBytes, aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } + using Base::operator=; + char *c_str() { return reinterpret_cast(get()); } }; @@ -89,15 +96,17 @@ class UTF8CharsZ : public mozilla::RangedPtr UTF8CharsZ(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } UTF8CharsZ(unsigned char *aBytes, size_t aLength) : Base(aBytes, aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } + using Base::operator=; + char *c_str() { return reinterpret_cast(get()); } }; @@ -119,21 +128,6 @@ class TwoByteChars : public mozilla::Range TwoByteChars(const jschar *aChars, size_t aLength) : Base(const_cast(aChars), aLength) {} }; -/* - * A non-convertible variant of TwoByteChars that does not refer to characters - * inlined inside a JSShortString or a JSInlineString. StableTwoByteChars are - * thus safe to hold across a GC. - */ -class StableTwoByteChars : public mozilla::Range -{ - typedef mozilla::Range Base; - - public: - StableTwoByteChars() : Base() {} - StableTwoByteChars(jschar *aChars, size_t aLength) : Base(aChars, aLength) {} - StableTwoByteChars(const jschar *aChars, size_t aLength) : Base(const_cast(aChars), aLength) {} -}; - /* * A TwoByteChars, but \0 terminated for compatibility with JSFlatString. */ @@ -147,10 +141,31 @@ class TwoByteCharsZ : public mozilla::RangedPtr TwoByteCharsZ(jschar *chars, size_t length) : Base(chars, length) { - JS_ASSERT(chars[length] == '\0'); + MOZ_ASSERT(chars[length] == '\0'); } + + using Base::operator=; }; +typedef mozilla::RangedPtr ConstCharPtr; + +/* + * Like TwoByteChars, but the chars are const. + */ +class ConstTwoByteChars : public mozilla::RangedPtr +{ + public: + ConstTwoByteChars(const ConstTwoByteChars &s) : ConstCharPtr(s) {} + MOZ_IMPLICIT ConstTwoByteChars(const mozilla::RangedPtr &s) : ConstCharPtr(s) {} + ConstTwoByteChars(const jschar *s, size_t len) : ConstCharPtr(s, len) {} + ConstTwoByteChars(const jschar *pos, const jschar *start, size_t len) + : ConstCharPtr(pos, start, len) + {} + + using ConstCharPtr::operator=; +}; + + /* * Convert a 2-byte character sequence to "ISO-Latin-1". This works by * truncating each 2-byte pair in the sequence to a 1-byte pair. If the source @@ -162,10 +177,12 @@ class TwoByteCharsZ : public mozilla::RangedPtr * This method cannot trigger GC. */ extern Latin1CharsZ -LossyTwoByteCharsToNewLatin1CharsZ(js::ThreadSafeContext *cx, TwoByteChars tbchars); +LossyTwoByteCharsToNewLatin1CharsZ(js::ThreadSafeContext *cx, + const mozilla::Range tbchars); +template extern UTF8CharsZ -TwoByteCharsToNewUTF8CharsZ(js::ThreadSafeContext *cx, TwoByteChars tbchars); +CharsToNewUTF8CharsZ(js::ThreadSafeContext *cx, const mozilla::Range chars); uint32_t Utf8ToOneUcs4Char(const uint8_t *utf8Buffer, int utf8Length); @@ -187,6 +204,20 @@ UTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen) extern TwoByteCharsZ LossyUTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen); +/* + * Returns the length of the char buffer required to encode |s| as UTF8. + * Does not include the null-terminator. + */ +JS_PUBLIC_API(size_t) +GetDeflatedUTF8StringLength(JSFlatString *s); + +/* + * Encode |src| as UTF8. The caller must ensure |dst| has enough space. + * Does not write the null terminator. + */ +JS_PUBLIC_API(void) +DeflateStringToUTF8Buffer(JSFlatString *src, mozilla::RangedPtr dst); + } // namespace JS inline void JS_free(JS::Latin1CharsZ &ptr) { js_free((void*)ptr.get()); } diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/Class.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/Class.h index b908fe1604..559cc65c85 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/Class.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/Class.h @@ -24,126 +24,20 @@ * object behavior and, e.g., allows custom slow layout. */ -class JSFreeOp; +struct JSFreeOp; +struct JSFunctionSpec; namespace js { -class Class; +struct Class; class FreeOp; -class PropertyId; class PropertyName; class Shape; -class SpecialId; // This is equal to JSFunction::class_. Use it in places where you don't want // to #include jsfun.h. extern JS_FRIEND_DATA(const js::Class* const) FunctionClassPtr; -static JS_ALWAYS_INLINE jsid -SPECIALID_TO_JSID(const SpecialId &sid); - -/* - * We partition the ways to refer to a property into three: by an index - * (uint32_t); by a string whose characters do not represent an index - * (PropertyName, see vm/String.h); and by various special values. - * - * Special values are encoded using SpecialId, which is layout-compatible but - * non-interconvertible with jsid. A SpecialId is used for JSID_VOID, which - * does not occur in JS scripts but may be used to indicate the absence of a - * valid identifier. In the future, a SpecialId may also be an object used by - * Harmony-proposed private names. - */ -class SpecialId -{ - uintptr_t bits_; - - /* Needs access to raw bits. */ - friend JS_ALWAYS_INLINE jsid SPECIALID_TO_JSID(const SpecialId &sid); - friend class PropertyId; - - static const uintptr_t TYPE_VOID = JSID_TYPE_VOID; - static const uintptr_t TYPE_OBJECT = JSID_TYPE_OBJECT; - static const uintptr_t TYPE_MASK = JSID_TYPE_MASK; - - SpecialId(uintptr_t bits) : bits_(bits) { } - - public: - SpecialId() : bits_(TYPE_VOID) { } - - /* Object-valued */ - - SpecialId(JSObject &obj) - : bits_(uintptr_t(&obj) | TYPE_OBJECT) - { - JS_ASSERT(&obj != nullptr); - JS_ASSERT((uintptr_t(&obj) & TYPE_MASK) == 0); - } - - bool isObject() const { - return (bits_ & TYPE_MASK) == TYPE_OBJECT && bits_ != TYPE_OBJECT; - } - - JSObject *toObject() const { - JS_ASSERT(isObject()); - return reinterpret_cast(bits_ & ~TYPE_MASK); - } - - /* Empty */ - - static SpecialId empty() { - SpecialId sid(TYPE_OBJECT); - JS_ASSERT(sid.isEmpty()); - return sid; - } - - bool isEmpty() const { - return bits_ == TYPE_OBJECT; - } - - /* Void */ - - static SpecialId voidId() { - SpecialId sid(TYPE_VOID); - JS_ASSERT(sid.isVoid()); - return sid; - } - - bool isVoid() const { - return bits_ == TYPE_VOID; - } -}; - -static JS_ALWAYS_INLINE jsid -SPECIALID_TO_JSID(const SpecialId &sid) -{ - jsid id; - JSID_BITS(id) = sid.bits_; - JS_ASSERT_IF(sid.isObject(), JSID_IS_OBJECT(id) && JSID_TO_OBJECT(id) == sid.toObject()); - JS_ASSERT_IF(sid.isVoid(), JSID_IS_VOID(id)); - JS_ASSERT_IF(sid.isEmpty(), JSID_IS_EMPTY(id)); - return id; -} - -static JS_ALWAYS_INLINE bool -JSID_IS_SPECIAL(jsid id) -{ - return JSID_IS_OBJECT(id) || JSID_IS_EMPTY(id) || JSID_IS_VOID(id); -} - -static JS_ALWAYS_INLINE SpecialId -JSID_TO_SPECIALID(jsid id) -{ - JS_ASSERT(JSID_IS_SPECIAL(id)); - if (JSID_IS_OBJECT(id)) - return SpecialId(*JSID_TO_OBJECT(id)); - if (JSID_IS_EMPTY(id)) - return SpecialId::empty(); - JS_ASSERT(JSID_IS_VOID(id)); - return SpecialId::voidId(); -} - -typedef JS::Handle HandleSpecialId; - } // namespace js // JSClass operation signatures. @@ -152,8 +46,8 @@ typedef JS::Handle HandleSpecialId; // be a string (Unicode property identifier) or an int (element index). The // *vp out parameter, on success, is the new property value after the action. typedef bool -(* JSPropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - JS::MutableHandle vp); +(* JSPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); // Set a property named by id in obj, treating the assignment as strict // mode code if strict is true. Note the jsid id type -- id may be a string @@ -161,8 +55,8 @@ typedef bool // parameter, on success, is the new property value after the // set. typedef bool -(* JSStrictPropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - bool strict, JS::MutableHandle vp); +(* JSStrictPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool strict, JS::MutableHandleValue vp); // Delete a property named by id in obj. // @@ -178,7 +72,7 @@ typedef bool // property, or an inherited property, is allowed -- it's just pointless), // set *succeeded to true and return true. typedef bool -(* JSDeletePropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, +(* JSDeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); // This function type is used for callbacks that enumerate the properties of @@ -212,13 +106,13 @@ typedef bool // The return value is used to indicate success, with a value of false // indicating failure. typedef bool -(* JSNewEnumerateOp)(JSContext *cx, JS::Handle obj, JSIterateOp enum_op, - JS::MutableHandle statep, JS::MutableHandle idp); +(* JSNewEnumerateOp)(JSContext *cx, JS::HandleObject obj, JSIterateOp enum_op, + JS::MutableHandleValue statep, JS::MutableHandleId idp); // The old-style JSClass.enumerate op should define all lazy properties not // yet reflected in obj. typedef bool -(* JSEnumerateOp)(JSContext *cx, JS::Handle obj); +(* JSEnumerateOp)(JSContext *cx, JS::HandleObject obj); // Resolve a lazy property named by id in obj by defining it directly in obj. // Lazy properties are those reflected from some peer native property space @@ -231,27 +125,24 @@ typedef bool // // NB: JSNewResolveOp provides a cheaper way to resolve lazy properties. typedef bool -(* JSResolveOp)(JSContext *cx, JS::Handle obj, JS::Handle id); +(* JSResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); -// Like JSResolveOp, but flags provide contextual information as follows: -// -// JSRESOLVE_ASSIGNING obj[id] is on the left-hand side of an assignment -// -// The *objp out parameter, on success, should be null to indicate that id -// was not resolved; and non-null, referring to obj or one of its prototypes, -// if id was resolved. The hook may assume *objp is null on entry. +// Like JSResolveOp, except the *objp out parameter, on success, should be null +// to indicate that id was not resolved; and non-null, referring to obj or one +// of its prototypes, if id was resolved. The hook may assume *objp is null on +// entry. // // This hook instead of JSResolveOp is called via the JSClass.resolve member // if JSCLASS_NEW_RESOLVE is set in JSClass.flags. typedef bool -(* JSNewResolveOp)(JSContext *cx, JS::Handle obj, JS::Handle id, unsigned flags, - JS::MutableHandle objp); +(* JSNewResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleObject objp); // Convert obj to the given type, returning true with the resulting value in // *vp on success, and returning false on error or exception. typedef bool -(* JSConvertOp)(JSContext *cx, JS::Handle obj, JSType type, - JS::MutableHandle vp); +(* JSConvertOp)(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); // Finalize obj, which the garbage collector has determined to be unreachable // from other live objects or from GC roots. Obviously, finalizers must never @@ -264,25 +155,11 @@ struct JSStringFinalizer { void (*finalize)(const JSStringFinalizer *fin, jschar *chars); }; -// JSClass.checkAccess type: check whether obj[id] may be accessed per mode, -// returning false on error/exception, true on success with obj[id]'s last-got -// value in *vp, and its attributes in *attrsp. As for JSPropertyOp above, id -// is either a string or an int jsval. -typedef bool -(* JSCheckAccessOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - JSAccessMode mode, JS::MutableHandle vp); - -// Return whether the first principal subsumes the second. The exact meaning of -// 'subsumes' is left up to the browser. Subsumption is checked inside the JS -// engine when determining, e.g., which stack frames to display in a backtrace. -typedef bool -(* JSSubsumesOp)(JSPrincipals *first, JSPrincipals *second); - // Check whether v is an instance of obj. Return false on error or exception, // true on success with true in *bp if v is an instance of obj, false in // *bp otherwise. typedef bool -(* JSHasInstanceOp)(JSContext *cx, JS::Handle obj, JS::MutableHandle vp, +(* JSHasInstanceOp)(JSContext *cx, JS::HandleObject obj, JS::MutableHandleValue vp, bool *bp); // Function type for trace operation of the class called to enumerate all @@ -300,11 +177,6 @@ typedef bool typedef void (* JSTraceOp)(JSTracer *trc, JSObject *obj); -// A generic type for functions mapping an object to another object, or null -// if an error or exception was thrown on cx. -typedef JSObject * -(* JSObjectOp)(JSContext *cx, JS::Handle obj); - // Hook that creates an iterator object for a given object. Returns the // iterator object or null if an error or exception was thrown on cx. typedef JSObject * @@ -327,9 +199,6 @@ typedef bool (* LookupElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleObject objp, JS::MutableHandle propp); typedef bool -(* LookupSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::MutableHandleObject objp, JS::MutableHandle propp); -typedef bool (* DefineGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); typedef bool @@ -340,10 +209,6 @@ typedef bool (* DefineElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); typedef bool -(* DefineSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); -typedef bool (* GenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, JS::MutableHandleValue vp); typedef bool @@ -353,12 +218,6 @@ typedef bool (* ElementIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, JS::MutableHandleValue vp); typedef bool -(* ElementIfPresentOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, - uint32_t index, JS::MutableHandleValue vp, bool* present); -typedef bool -(* SpecialIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, - HandleSpecialId sid, JS::MutableHandleValue vp); -typedef bool (* StrictGenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, bool strict); typedef bool @@ -368,20 +227,12 @@ typedef bool (* StrictElementIdOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp, bool strict); typedef bool -(* StrictSpecialIdOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::MutableHandleValue vp, bool strict); -typedef bool (* GenericAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); typedef bool (* PropertyAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, unsigned *attrsp); typedef bool -(* DeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, - bool *succeeded); -typedef bool -(* DeleteElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded); -typedef bool -(* DeleteSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, bool *succeeded); +(* DeleteGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); typedef bool (* WatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); @@ -389,12 +240,23 @@ typedef bool typedef bool (* UnwatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); +typedef bool +(* SliceOp)(JSContext *cx, JS::HandleObject obj, uint32_t begin, uint32_t end, + JS::HandleObject result); // result is actually preallocted. + +// A generic type for functions mapping an object to another object, or null +// if an error or exception was thrown on cx. typedef JSObject * (* ObjectOp)(JSContext *cx, JS::HandleObject obj); + +// Hook to map an object to its inner object. Infallible. +typedef JSObject * +(* InnerObjectOp)(JSObject *obj); + typedef void (* FinalizeOp)(FreeOp *fop, JSObject *obj); -#define JS_CLASS_MEMBERS \ +#define JS_CLASS_MEMBERS(FinalizeOpType) \ const char *name; \ uint32_t flags; \ \ @@ -408,26 +270,34 @@ typedef void JSConvertOp convert; \ \ /* Optional members (may be null). */ \ - FinalizeOp finalize; \ - JSCheckAccessOp checkAccess; \ + FinalizeOpType finalize; \ JSNative call; \ JSHasInstanceOp hasInstance; \ JSNative construct; \ JSTraceOp trace -/* - * The helper struct to measure the size of JS_CLASS_MEMBERS to know how much - * we have to pad js::Class to match the size of JSClass. - */ -struct ClassSizeMeasurement +// Callback for the creation of constructor and prototype objects. +typedef JSObject *(*ClassObjectCreationOp)(JSContext *cx, JSProtoKey key); + +// Callback for custom post-processing after class initialization via ClassSpec. +typedef bool (*FinishClassInitOp)(JSContext *cx, JS::HandleObject ctor, + JS::HandleObject proto); + +struct ClassSpec { - JS_CLASS_MEMBERS; + ClassObjectCreationOp createConstructor; + ClassObjectCreationOp createPrototype; + const JSFunctionSpec *constructorFunctions; + const JSFunctionSpec *prototypeFunctions; + const JSPropertySpec *prototypeProperties; + FinishClassInitOp finishInit; + bool defined() const { return !!createConstructor; } }; struct ClassExtension { - JSObjectOp outerObject; - JSObjectOp innerObject; + ObjectOp outerObject; + InnerObjectOp innerObject; JSIteratorOp iteratorObject; /* @@ -450,6 +320,7 @@ struct ClassExtension JSWeakmapKeyDelegateOp weakmapKeyDelegateOp; }; +#define JS_NULL_CLASS_SPEC {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr} #define JS_NULL_CLASS_EXT {nullptr,nullptr,nullptr,false,nullptr} struct ObjectOps @@ -457,36 +328,29 @@ struct ObjectOps LookupGenericOp lookupGeneric; LookupPropOp lookupProperty; LookupElementOp lookupElement; - LookupSpecialOp lookupSpecial; DefineGenericOp defineGeneric; DefinePropOp defineProperty; DefineElementOp defineElement; - DefineSpecialOp defineSpecial; GenericIdOp getGeneric; PropertyIdOp getProperty; ElementIdOp getElement; - ElementIfPresentOp getElementIfPresent; /* can be null */ - SpecialIdOp getSpecial; StrictGenericIdOp setGeneric; StrictPropertyIdOp setProperty; StrictElementIdOp setElement; - StrictSpecialIdOp setSpecial; GenericAttributesOp getGenericAttributes; GenericAttributesOp setGenericAttributes; - DeletePropertyOp deleteProperty; - DeleteElementOp deleteElement; - DeleteSpecialOp deleteSpecial; + DeleteGenericOp deleteGeneric; WatchOp watch; UnwatchOp unwatch; - + SliceOp slice; // Optimized slice, can be null. JSNewEnumerateOp enumerate; ObjectOp thisObject; }; #define JS_NULL_OBJECT_OPS \ - {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, \ - nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, \ - nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr} + {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr} } // namespace js @@ -495,27 +359,9 @@ struct ObjectOps typedef void (*JSClassInternal)(); struct JSClass { - const char *name; - uint32_t flags; - - // Mandatory function pointer members. - JSPropertyOp addProperty; - JSDeletePropertyOp delProperty; - JSPropertyOp getProperty; - JSStrictPropertyOp setProperty; - JSEnumerateOp enumerate; - JSResolveOp resolve; - JSConvertOp convert; - - // Optional members (may be null). - JSFinalizeOp finalize; - JSCheckAccessOp checkAccess; - JSNative call; - JSHasInstanceOp hasInstance; - JSNative construct; - JSTraceOp trace; - - void *reserved[42]; + JS_CLASS_MEMBERS(JSFinalizeOp); + + void *reserved[31]; }; #define JSCLASS_HAS_PRIVATE (1<<0) // objects have private slot @@ -550,9 +396,9 @@ struct JSClass { #define JSCLASS_INTERNAL_FLAG2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2)) #define JSCLASS_INTERNAL_FLAG3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3)) -// Indicate whether the proto or ctor should be frozen. -#define JSCLASS_FREEZE_PROTO (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4)) -#define JSCLASS_FREEZE_CTOR (1<<(JSCLASS_HIGH_FLAGS_SHIFT+5)) +#define JSCLASS_IS_PROXY (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4)) + +// Bit 22 unused. // Reserved for embeddings. #define JSCLASS_USERBIT2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+6)) @@ -573,7 +419,11 @@ struct JSClass { // with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS was // previously allowed, but is now an ES5 violation and thus unsupported. // -#define JSCLASS_GLOBAL_SLOT_COUNT (3 + JSProto_LIMIT * 3 + 27) +// JSCLASS_GLOBAL_APPLICATION_SLOTS is the number of slots reserved at +// the beginning of every global object's slots for use by the +// application. +#define JSCLASS_GLOBAL_APPLICATION_SLOTS 3 +#define JSCLASS_GLOBAL_SLOT_COUNT (JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 3 + 30) #define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n) \ (JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + (n))) #define JSCLASS_GLOBAL_FLAGS \ @@ -600,11 +450,10 @@ namespace js { struct Class { - JS_CLASS_MEMBERS; + JS_CLASS_MEMBERS(FinalizeOp); + ClassSpec spec; ClassExtension ext; ObjectOps ops; - uint8_t pad[sizeof(JSClass) - sizeof(ClassSizeMeasurement) - - sizeof(ClassExtension) - sizeof(ObjectOps)]; /* Class is not native and its map is not a scope. */ static const uint32_t NON_NATIVE = JSCLASS_INTERNAL_FLAG2; @@ -621,8 +470,20 @@ struct Class return flags & JSCLASS_EMULATES_UNDEFINED; } + bool isJSFunction() const { + return this == js::FunctionClassPtr; + } + bool isCallable() const { - return this == js::FunctionClassPtr || call; + return isJSFunction() || call; + } + + bool isProxy() const { + return flags & JSCLASS_IS_PROXY; + } + + bool isDOMClass() const { + return flags & JSCLASS_IS_DOMJSCLASS; } static size_t offsetOfFlags() { return offsetof(Class, flags); } @@ -638,20 +499,19 @@ JS_STATIC_ASSERT(offsetof(JSClass, enumerate) == offsetof(Class, enumerate)); JS_STATIC_ASSERT(offsetof(JSClass, resolve) == offsetof(Class, resolve)); JS_STATIC_ASSERT(offsetof(JSClass, convert) == offsetof(Class, convert)); JS_STATIC_ASSERT(offsetof(JSClass, finalize) == offsetof(Class, finalize)); -JS_STATIC_ASSERT(offsetof(JSClass, checkAccess) == offsetof(Class, checkAccess)); JS_STATIC_ASSERT(offsetof(JSClass, call) == offsetof(Class, call)); JS_STATIC_ASSERT(offsetof(JSClass, construct) == offsetof(Class, construct)); JS_STATIC_ASSERT(offsetof(JSClass, hasInstance) == offsetof(Class, hasInstance)); JS_STATIC_ASSERT(offsetof(JSClass, trace) == offsetof(Class, trace)); JS_STATIC_ASSERT(sizeof(JSClass) == sizeof(Class)); -static JS_ALWAYS_INLINE const JSClass * +static MOZ_ALWAYS_INLINE const JSClass * Jsvalify(const Class *c) { return (const JSClass *)c; } -static JS_ALWAYS_INLINE const Class * +static MOZ_ALWAYS_INLINE const Class * Valueify(const JSClass *c) { return (const Class *)c; @@ -679,21 +539,6 @@ ObjectClassIs(JSObject &obj, ESClassValue classValue, JSContext *cx); inline bool IsObjectWithClass(const JS::Value &v, ESClassValue classValue, JSContext *cx); -inline bool -IsPoisonedSpecialId(js::SpecialId iden) -{ - if (iden.isObject()) - return JS::IsPoisonedPtr(iden.toObject()); - return false; -} - -template <> struct GCMethods -{ - static SpecialId initial() { return SpecialId(); } - static ThingRootKind kind() { return THING_ROOT_ID; } - static bool poisoned(SpecialId id) { return IsPoisonedSpecialId(id); } -}; - } /* namespace js */ #endif /* js_Class_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/GCAPI.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/GCAPI.h index 190b781060..c58d62d029 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/GCAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/GCAPI.h @@ -10,8 +10,26 @@ #include "mozilla/NullPtr.h" #include "js/HeapAPI.h" -#include "js/RootingAPI.h" -#include "js/Value.h" + +namespace js { +namespace gc { +class GCRuntime; +} +} + +typedef enum JSGCMode { + /* Perform only global GCs. */ + JSGC_MODE_GLOBAL = 0, + + /* Perform per-compartment GCs until too much garbage has accumulated. */ + JSGC_MODE_COMPARTMENT = 1, + + /* + * Collect in short time slices rather than all at once. Implies + * JSGC_MODE_COMPARTMENT. + */ + JSGC_MODE_INCREMENTAL = 2 +} JSGCMode; namespace JS { @@ -95,40 +113,117 @@ enum Reason { } /* namespace gcreason */ +/* + * Zone GC: + * + * SpiderMonkey's GC is capable of performing a collection on an arbitrary + * subset of the zones in the system. This allows an embedding to minimize + * collection time by only collecting zones that have run code recently, + * ignoring the parts of the heap that are unlikely to have changed. + * + * When triggering a GC using one of the functions below, it is first necessary + * to select the zones to be collected. To do this, you can call + * PrepareZoneForGC on each zone, or you can call PrepareForFullGC to select + * all zones. Failing to select any zone is an error. + */ + +/* + * Schedule the given zone to be collected as part of the next GC. + */ extern JS_FRIEND_API(void) PrepareZoneForGC(Zone *zone); +/* + * Schedule all zones to be collected in the next GC. + */ extern JS_FRIEND_API(void) PrepareForFullGC(JSRuntime *rt); +/* + * When performing an incremental GC, the zones that were selected for the + * previous incremental slice must be selected in subsequent slices as well. + * This function selects those slices automatically. + */ extern JS_FRIEND_API(void) PrepareForIncrementalGC(JSRuntime *rt); +/* + * Returns true if any zone in the system has been scheduled for GC with one of + * the functions above or by the JS engine. + */ extern JS_FRIEND_API(bool) IsGCScheduled(JSRuntime *rt); +/* + * Undoes the effect of the Prepare methods above. The given zone will not be + * collected in the next GC. + */ extern JS_FRIEND_API(void) SkipZoneForGC(Zone *zone); /* - * When triggering a GC using one of the functions below, it is first necessary - * to select the compartments to be collected. To do this, you can call - * PrepareZoneForGC on each compartment, or you can call PrepareForFullGC - * to select all compartments. Failing to select any compartment is an error. + * Non-Incremental GC: + * + * The following functions perform a non-incremental GC. */ +/* + * Performs a non-incremental collection of all selected zones. Some objects + * that are unreachable from the program may still be alive afterwards because + * of internal references. + */ extern JS_FRIEND_API(void) GCForReason(JSRuntime *rt, gcreason::Reason reason); +/* + * Perform a non-incremental collection after clearing caches and other + * temporary references to objects. This will remove all unreferenced objects + * in the system. + */ extern JS_FRIEND_API(void) ShrinkingGC(JSRuntime *rt, gcreason::Reason reason); -extern JS_FRIEND_API(void) -ShrinkGCBuffers(JSRuntime *rt); +/* + * Incremental GC: + * + * Incremental GC divides the full mark-and-sweep collection into multiple + * slices, allowing client JavaScript code to run between each slice. This + * allows interactive apps to avoid long collection pauses. Incremental GC does + * not make collection take less time, it merely spreads that time out so that + * the pauses are less noticable. + * + * For a collection to be carried out incrementally the following conditions + * must be met: + * - The collection must be run by calling JS::IncrementalGC() rather than + * JS_GC(). + * - The GC mode must have been set to JSGC_MODE_INCREMENTAL with + * JS_SetGCParameter(). + * - All native objects that have their own trace hook must indicate that they + * implement read and write barriers with the JSCLASS_IMPLEMENTS_BARRIERS + * flag. + * + * Note: Even if incremental GC is enabled and working correctly, + * non-incremental collections can still happen when low on memory. + */ +/* + * Begin an incremental collection and perform one slice worth of work or + * perform a slice of an ongoing incremental collection. When this function + * returns, the collection is not complete. This function must be called + * repeatedly until !IsIncrementalGCInProgress(rt). + * + * Note: SpiderMonkey's GC is not realtime. Slices in practice may be longer or + * shorter than the requested interval. + */ extern JS_FRIEND_API(void) IncrementalGC(JSRuntime *rt, gcreason::Reason reason, int64_t millis = 0); +/* + * If IsIncrementalGCInProgress(rt), this call finishes the ongoing collection + * by performing an arbitrarily long slice. If !IsIncrementalGCInProgress(rt), + * this is equivalent to GCForReason. When this function returns, + * IsIncrementalGCInProgress(rt) will always be false. + */ extern JS_FRIEND_API(void) FinishIncrementalGC(JSRuntime *rt, gcreason::Reason reason); @@ -152,7 +247,7 @@ enum GCProgress { struct JS_FRIEND_API(GCDescription) { bool isCompartment_; - GCDescription(bool isCompartment) + explicit GCDescription(bool isCompartment) : isCompartment_(isCompartment) {} jschar *formatMessage(JSRuntime *rt) const; @@ -162,37 +257,56 @@ struct JS_FRIEND_API(GCDescription) { typedef void (* GCSliceCallback)(JSRuntime *rt, GCProgress progress, const GCDescription &desc); +/* + * The GC slice callback is called at the beginning and end of each slice. This + * callback may be used for GC notifications as well as to perform additional + * marking. + */ extern JS_FRIEND_API(GCSliceCallback) SetGCSliceCallback(JSRuntime *rt, GCSliceCallback callback); /* - * Signals a good place to do an incremental slice, because the browser is - * drawing a frame. + * Incremental GC defaults to enabled, but may be disabled for testing or in + * embeddings that have not yet implemented barriers on their native classes. + * There is not currently a way to re-enable incremental GC once it has been + * disabled on the runtime. */ extern JS_FRIEND_API(void) -NotifyDidPaint(JSRuntime *rt); +DisableIncrementalGC(JSRuntime *rt); +/* + * Returns true if incremental GC is enabled. Simply having incremental GC + * enabled is not sufficient to ensure incremental collections are happening. + * See the comment "Incremental GC" above for reasons why incremental GC may be + * suppressed. Inspection of the "nonincremental reason" field of the + * GCDescription returned by GCSliceCallback may help narrow down the cause if + * collections are not happening incrementally when expected. + */ extern JS_FRIEND_API(bool) IsIncrementalGCEnabled(JSRuntime *rt); +/* + * Returns true while an incremental GC is ongoing, both when actively + * collecting and between slices. + */ JS_FRIEND_API(bool) IsIncrementalGCInProgress(JSRuntime *rt); -extern JS_FRIEND_API(void) -DisableIncrementalGC(JSRuntime *rt); - -extern JS_FRIEND_API(void) -DisableGenerationalGC(JSRuntime *rt); - -extern JS_FRIEND_API(void) -EnableGenerationalGC(JSRuntime *rt); - +/* + * Returns true when writes to GC things must call an incremental (pre) barrier. + * This is generally only true when running mutator code in-between GC slices. + * At other times, the barrier may be elided for performance. + */ extern JS_FRIEND_API(bool) IsIncrementalBarrierNeeded(JSRuntime *rt); extern JS_FRIEND_API(bool) IsIncrementalBarrierNeeded(JSContext *cx); +/* + * Notify the GC that a reference to a GC thing is about to be overwritten. + * These methods must be called if IsIncrementalBarrierNeeded. + */ extern JS_FRIEND_API(void) IncrementalReferenceBarrier(void *ptr, JSGCTraceKind kind); @@ -202,73 +316,118 @@ IncrementalValueBarrier(const Value &v); extern JS_FRIEND_API(void) IncrementalObjectBarrier(JSObject *obj); -extern JS_FRIEND_API(void) -PokeGC(JSRuntime *rt); - -/* Was the most recent GC run incrementally? */ +/* + * Returns true if the most recent GC ran incrementally. + */ extern JS_FRIEND_API(bool) WasIncrementalGC(JSRuntime *rt); +/* + * Generational GC: + * + * Note: Generational GC is not yet enabled by default. The following class + * is non-functional unless SpiderMonkey was configured with + * --enable-gcgenerational. + */ + +/* Ensure that generational GC is disabled within some scope. */ +class JS_FRIEND_API(AutoDisableGenerationalGC) +{ + js::gc::GCRuntime *gc; +#if defined(JSGC_GENERATIONAL) && defined(JS_GC_ZEAL) + bool restartVerifier; +#endif + + public: + explicit AutoDisableGenerationalGC(JSRuntime *rt); + ~AutoDisableGenerationalGC(); +}; + +/* + * Returns true if generational allocation and collection is currently enabled + * on the given runtime. + */ +extern JS_FRIEND_API(bool) +IsGenerationalGCEnabled(JSRuntime *rt); + +/* + * Returns the GC's "number". This does not correspond directly to the number + * of GCs that have been run, but is guaranteed to be monotonically increasing + * with GC activity. + */ extern JS_FRIEND_API(size_t) GetGCNumber(); -class JS_PUBLIC_API(AutoAssertNoGC) +/* + * The GC does not immediately return the unused memory freed by a collection + * back to the system incase it is needed soon afterwards. This call forces the + * GC to return this memory immediately. + */ +extern JS_FRIEND_API(void) +ShrinkGCBuffers(JSRuntime *rt); + +/* + * Assert if a GC occurs while this class is live. This class does not disable + * the static rooting hazard analysis. + */ +class JS_PUBLIC_API(AutoAssertOnGC) { #ifdef DEBUG - JSRuntime *runtime; + js::gc::GCRuntime *gc; size_t gcNumber; public: - AutoAssertNoGC(); - AutoAssertNoGC(JSRuntime *rt); - ~AutoAssertNoGC(); + AutoAssertOnGC(); + explicit AutoAssertOnGC(JSRuntime *rt); + ~AutoAssertOnGC(); + + static void VerifyIsSafeToGC(JSRuntime *rt); #else public: - /* Prevent unreferenced local warnings in opt builds. */ - AutoAssertNoGC() {} - AutoAssertNoGC(JSRuntime *) {} + AutoAssertOnGC() {} + explicit AutoAssertOnGC(JSRuntime *rt) {} + ~AutoAssertOnGC() {} + + static void VerifyIsSafeToGC(JSRuntime *rt) {} #endif }; -class JS_PUBLIC_API(ObjectPtr) +/* + * Disable the static rooting hazard analysis in the live region, but assert if + * any GC occurs while this guard object is live. This is most useful to help + * the exact rooting hazard analysis in complex regions, since it cannot + * understand dataflow. + * + * Note: GC behavior is unpredictable even when deterministice and is generally + * non-deterministic in practice. The fact that this guard has not + * asserted is not a guarantee that a GC cannot happen in the guarded + * region. As a rule, anyone performing a GC unsafe action should + * understand the GC properties of all code in that region and ensure + * that the hazard analysis is correct for that code, rather than relying + * on this class. + */ +class JS_PUBLIC_API(AutoSuppressGCAnalysis) : public AutoAssertOnGC { - Heap value; - public: - ObjectPtr() : value(nullptr) {} - - ObjectPtr(JSObject *obj) : value(obj) {} - - /* Always call finalize before the destructor. */ - ~ObjectPtr() { JS_ASSERT(!value); } - - void finalize(JSRuntime *rt) { - if (IsIncrementalBarrierNeeded(rt)) - IncrementalObjectBarrier(value); - value = nullptr; - } - - void init(JSObject *obj) { value = obj; } - - JSObject *get() const { return value; } - - void writeBarrierPre(JSRuntime *rt) { - IncrementalObjectBarrier(value); - } - - bool isAboutToBeFinalized(); - - ObjectPtr &operator=(JSObject *obj) { - IncrementalObjectBarrier(value); - value = obj; - return *this; - } - - void trace(JSTracer *trc, const char *name); + AutoSuppressGCAnalysis() : AutoAssertOnGC() {} + explicit AutoSuppressGCAnalysis(JSRuntime *rt) : AutoAssertOnGC(rt) {} +}; - JSObject &operator*() const { return *value; } - JSObject *operator->() const { return value; } - operator JSObject *() const { return value; } +/* + * Place AutoCheckCannotGC in scopes that you believe can never GC. These + * annotations will be verified both dynamically via AutoAssertOnGC, and + * statically with the rooting hazard analysis (implemented by making the + * analysis consider AutoCheckCannotGC to be a GC pointer, and therefore + * complain if it is live across a GC call.) It is useful when dealing with + * internal pointers to GC things where the GC thing itself may not be present + * for the static analysis: e.g. acquiring inline chars from a JSString* on the + * heap. + */ +class JS_PUBLIC_API(AutoCheckCannotGC) : public AutoAssertOnGC +{ + public: + AutoCheckCannotGC() : AutoAssertOnGC() {} + explicit AutoCheckCannotGC(JSRuntime *rt) : AutoAssertOnGC(rt) {} }; /* @@ -284,10 +443,10 @@ UnmarkGrayGCThingRecursively(void *thing, JSGCTraceKind kind); * data). During incremental GC, since the gray bits haven't been computed yet, * we conservatively mark the object black. */ -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) { - JS_ASSERT(kind != JSTRACE_SHAPE); + MOZ_ASSERT(kind != JSTRACE_SHAPE); shadow::Runtime *rt = js::gc::GetGCThingRuntime(thing); #ifdef JSGC_GENERATIONAL @@ -296,7 +455,7 @@ ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) * All live objects in the nursery are moved to tenured at the beginning of * each GC slice, so the gray marker never sees nursery things. */ - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return; #endif if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) @@ -305,14 +464,7 @@ ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) UnmarkGrayGCThingRecursively(thing, kind); } -static JS_ALWAYS_INLINE void -ExposeValueToActiveJS(const Value &v) -{ - if (v.isMarkable()) - ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); -} - -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void ExposeObjectToActiveJS(JSObject *obj) { ExposeGCThingToActiveJS(obj, JSTRACE_OBJECT); @@ -321,7 +473,7 @@ ExposeObjectToActiveJS(JSObject *obj) /* * If a GC is currently marking, mark the object black. */ -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void MarkGCThingAsLive(JSRuntime *rt_, void *thing, JSGCTraceKind kind) { shadow::Runtime *rt = shadow::Runtime::asShadowRuntime(rt_); @@ -329,20 +481,34 @@ MarkGCThingAsLive(JSRuntime *rt_, void *thing, JSGCTraceKind kind) /* * Any object in the nursery will not be freed during any GC running at that time. */ - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return; #endif if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) IncrementalReferenceBarrier(thing, kind); } -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void MarkStringAsLive(Zone *zone, JSString *string) { JSRuntime *rt = JS::shadow::Zone::asShadowZone(zone)->runtimeFromMainThread(); MarkGCThingAsLive(rt, string, JSTRACE_STRING); } +/* + * Internal to Firefox. + * + * Note: this is not related to the PokeGC in nsJSEnvironment. + */ +extern JS_FRIEND_API(void) +PokeGC(JSRuntime *rt); + +/* + * Internal to Firefox. + */ +extern JS_FRIEND_API(void) +NotifyDidPaint(JSRuntime *rt); + } /* namespace JS */ #endif /* js_GCAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/HashTable.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/HashTable.h index eb98804c8e..4c27308b5e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/HashTable.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/HashTable.h @@ -73,7 +73,7 @@ class HashMap // HashMap construction is fallible (due to OOM); thus the user must call // init after constructing a HashMap and check the return value. - HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} + explicit HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} bool init(uint32_t len = 16) { return impl.init(len); } bool initialized() const { return impl.initialized(); } @@ -159,7 +159,7 @@ class HashMap // typedef HashMap HM; // HM h; // for (HM::Range r = h.all(); !r.empty(); r.popFront()) - // char c = r.front().value; + // char c = r.front().value(); // // Also see the definition of Range in HashTable above (with T = Entry). typedef typename Impl::Range Range; @@ -171,7 +171,7 @@ class HashMap // typedef HashMap HM; // HM s; // for (HM::Enum e(s); !e.empty(); e.popFront()) - // if (e.front().value == 'l') + // if (e.front().value() == 'l') // e.removeFront(); // // Table resize may occur in Enum's destructor. Also see the definition of @@ -182,9 +182,6 @@ class HashMap // using the finish() method. void clear() { impl.clear(); } - // Remove all entries without triggering destructors. This method is unsafe. - void clearWithoutCallingDestructors() { impl.clearWithoutCallingDestructors(); } - // Remove all the entries and release all internal buffers. The map must // be initialized again before any use. void finish() { impl.finish(); } @@ -210,7 +207,7 @@ class HashMap // If |generation()| is the same before and after a HashMap operation, // pointers into the table remain valid. - unsigned generation() const { return impl.generation(); } + uint32_t generation() const { return impl.generation(); } /************************************************** Shorthand operations */ @@ -317,7 +314,7 @@ class HashSet // HashSet construction is fallible (due to OOM); thus the user must call // init after constructing a HashSet and check the return value. - HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} + explicit HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} bool init(uint32_t len = 16) { return impl.init(len); } bool initialized() const { return impl.initialized(); } @@ -438,7 +435,7 @@ class HashSet // If |generation()| is the same before and after a HashSet operation, // pointers into the table remain valid. - unsigned generation() const { return impl.generation(); } + uint32_t generation() const { return impl.generation(); } /************************************************** Shorthand operations */ @@ -482,6 +479,13 @@ class HashSet impl.rekeyAndMaybeRehash(p, new_lookup, new_value); } + // Infallibly rekey one entry with a new key that is equivalent. + void rekeyInPlace(Ptr p, const T &new_value) + { + MOZ_ASSERT(HashPolicy::match(*p, new_value)); + impl.rekeyInPlace(p, new_value); + } + // HashSet is movable HashSet(HashSet &&rhs) : impl(mozilla::Move(rhs.impl)) {} void operator=(HashSet &&rhs) { @@ -531,7 +535,7 @@ struct PointerHasher { typedef Key Lookup; static HashNumber hash(const Lookup &l) { - JS_ASSERT(!JS::IsPoisonedPtr(l)); + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); size_t word = reinterpret_cast(l) >> zeroBits; JS_STATIC_ASSERT(sizeof(HashNumber) == 4); #if JS_BITS_PER_WORD == 32 @@ -542,8 +546,8 @@ struct PointerHasher #endif } static bool match(const Key &k, const Lookup &l) { - JS_ASSERT(!JS::IsPoisonedPtr(k)); - JS_ASSERT(!JS::IsPoisonedPtr(l)); + MOZ_ASSERT(!JS::IsPoisonedPtr(k)); + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); return k == l; } static void rekey(Key &k, const Key& newKey) { @@ -701,7 +705,7 @@ class HashTableEntry } void destroy() { - JS_ASSERT(isLive()); + MOZ_ASSERT(isLive()); mem.addr()->~T(); } @@ -710,16 +714,16 @@ class HashTableEntry mozilla::Swap(mem, other->mem); } - T &get() { JS_ASSERT(isLive()); return *mem.addr(); } + T &get() { MOZ_ASSERT(isLive()); return *mem.addr(); } bool isFree() const { return keyHash == sFreeKey; } - void clearLive() { JS_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); } + void clearLive() { MOZ_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); } void clear() { if (isLive()) mem.addr()->~T(); keyHash = sFreeKey; } bool isRemoved() const { return keyHash == sRemovedKey; } - void removeLive() { JS_ASSERT(isLive()); keyHash = sRemovedKey; mem.addr()->~T(); } + void removeLive() { MOZ_ASSERT(isLive()); keyHash = sRemovedKey; mem.addr()->~T(); } bool isLive() const { return isLiveHash(keyHash); } - void setCollision() { JS_ASSERT(isLive()); keyHash |= sCollisionBit; } - void setCollision(HashNumber bit) { JS_ASSERT(isLive()); keyHash |= bit; } + void setCollision() { MOZ_ASSERT(isLive()); keyHash |= sCollisionBit; } + void setCollision(HashNumber bit) { MOZ_ASSERT(isLive()); keyHash |= bit; } void unsetCollision() { keyHash &= ~sCollisionBit; } bool hasCollision() const { return keyHash & sCollisionBit; } bool matchHash(HashNumber hn) { return (keyHash & ~sCollisionBit) == hn; } @@ -728,16 +732,18 @@ class HashTableEntry template void setLive(HashNumber hn, U &&u) { - JS_ASSERT(!isLive()); + MOZ_ASSERT(!isLive()); keyHash = hn; new(mem.addr()) T(mozilla::Forward(u)); - JS_ASSERT(isLive()); + MOZ_ASSERT(isLive()); } }; template class HashTable : private AllocPolicy { + friend class mozilla::ReentrancyGuard; + typedef typename mozilla::RemoveConst::Type NonConstT; typedef typename HashPolicy::KeyType Key; typedef typename HashPolicy::Lookup Lookup; @@ -756,25 +762,56 @@ class HashTable : private AllocPolicy void nonNull() {} Entry *entry_; +#ifdef DEBUG + const HashTable *table_; + uint32_t generation; +#endif protected: - Ptr(Entry &entry) : entry_(&entry) {} + Ptr(Entry &entry, const HashTable &tableArg) + : entry_(&entry) +#ifdef DEBUG + , table_(&tableArg) + , generation(tableArg.generation()) +#endif + {} public: // Leaves Ptr uninitialized. Ptr() { -#ifdef DEBUG +#ifdef JS_DEBUG entry_ = (Entry *)0xbad; #endif } - bool found() const { return entry_->isLive(); } - operator ConvertibleToBool() const { return found() ? &Ptr::nonNull : 0; } - bool operator==(const Ptr &rhs) const { JS_ASSERT(found() && rhs.found()); return entry_ == rhs.entry_; } - bool operator!=(const Ptr &rhs) const { return !(*this == rhs); } + bool found() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->isLive(); + } - T &operator*() const { return entry_->get(); } - T *operator->() const { return &entry_->get(); } + operator ConvertibleToBool() const { + return found() ? &Ptr::nonNull : 0; + } + + bool operator==(const Ptr &rhs) const { + MOZ_ASSERT(found() && rhs.found()); + return entry_ == rhs.entry_; + } + + bool operator!=(const Ptr &rhs) const { + MOZ_ASSERT(generation == table_->generation()); + return !(*this == rhs); + } + + T &operator*() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->get(); + } + + T *operator->() const { + MOZ_ASSERT(generation == table_->generation()); + return &entry_->get(); + } }; // A Ptr that can be used to add a key after a failed lookup. @@ -782,9 +819,18 @@ class HashTable : private AllocPolicy { friend class HashTable; HashNumber keyHash; - mozilla::DebugOnly mutationCount; +#ifdef DEBUG + uint64_t mutationCount; +#endif + + AddPtr(Entry &entry, const HashTable &tableArg, HashNumber hn) + : Ptr(entry, tableArg) + , keyHash(hn) +#ifdef DEBUG + , mutationCount(tableArg.mutationCount) +#endif + {} - AddPtr(Entry &entry, HashNumber hn) : Ptr(entry), keyHash(hn) {} public: // Leaves AddPtr uninitialized. AddPtr() {} @@ -799,32 +845,63 @@ class HashTable : private AllocPolicy protected: friend class HashTable; - Range(Entry *c, Entry *e) : cur(c), end(e), validEntry(true) { + Range(const HashTable &tableArg, Entry *c, Entry *e) + : cur(c) + , end(e) +#ifdef DEBUG + , table_(&tableArg) + , mutationCount(tableArg.mutationCount) + , generation(tableArg.generation()) + , validEntry(true) +#endif + { while (cur < end && !cur->isLive()) ++cur; } Entry *cur, *end; - mozilla::DebugOnly validEntry; +#ifdef DEBUG + const HashTable *table_; + uint64_t mutationCount; + uint32_t generation; + bool validEntry; +#endif public: - Range() : cur(nullptr), end(nullptr), validEntry(false) {} + Range() + : cur(nullptr) + , end(nullptr) +#ifdef DEBUG + , table_(nullptr) + , mutationCount(0) + , generation(0) + , validEntry(false) +#endif + {} bool empty() const { + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); return cur == end; } T &front() const { - JS_ASSERT(validEntry); - JS_ASSERT(!empty()); + MOZ_ASSERT(validEntry); + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); return cur->get(); } void popFront() { - JS_ASSERT(!empty()); + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); while (++cur < end && !cur->isLive()) continue; +#ifdef DEBUG validEntry = true; +#endif } }; @@ -837,17 +914,17 @@ class HashTable : private AllocPolicy { friend class HashTable; - HashTable &table; + HashTable &table_; bool rekeyed; bool removed; /* Not copyable. */ - Enum(const Enum &); - void operator=(const Enum &); + Enum(const Enum &) MOZ_DELETE; + void operator=(const Enum &) MOZ_DELETE; public: template explicit - Enum(Map &map) : Range(map.all()), table(map.impl), rekeyed(false), removed(false) {} + Enum(Map &map) : Range(map.all()), table_(map.impl), rekeyed(false), removed(false) {} // Removes the |front()| element from the table, leaving |front()| // invalid until the next call to |popFront()|. For example: @@ -857,18 +934,25 @@ class HashTable : private AllocPolicy // if (e.front() == 42) // e.removeFront(); void removeFront() { - table.remove(*this->cur); + table_.remove(*this->cur); removed = true; +#ifdef DEBUG this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif } // Removes the |front()| element and re-inserts it into the table with // a new key at the new Lookup position. |front()| is invalid after // this operation until the next call to |popFront()|. void rekeyFront(const Lookup &l, const Key &k) { - table.rekeyWithoutRehash(*this->cur, l, k); + Ptr p(*this->cur, table_); + table_.rekeyWithoutRehash(p, l, k); rekeyed = true; +#ifdef DEBUG this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif } void rekeyFront(const Key &k) { @@ -878,12 +962,12 @@ class HashTable : private AllocPolicy // Potentially rehashes the table. ~Enum() { if (rekeyed) { - table.gen++; - table.checkOverRemoved(); + table_.gen++; + table_.checkOverRemoved(); } if (removed) - table.compactIfUnderloaded(); + table_.compactIfUnderloaded(); } }; @@ -908,18 +992,18 @@ class HashTable : private AllocPolicy void operator=(const HashTable &) MOZ_DELETE; private: - uint32_t hashShift; // multiplicative hash shift - uint32_t entryCount; // number of entries in table - uint32_t gen; // entry storage generation number - uint32_t removedCount; // removed entry sentinels in table - Entry *table; // entry storage + static const size_t CAP_BITS = 24; - void setTableSizeLog2(unsigned sizeLog2) - { - hashShift = sHashBits - sizeLog2; - } + public: + Entry *table; // entry storage + uint32_t gen; // entry storage generation number + uint32_t entryCount; // number of entries in table + uint32_t removedCount:CAP_BITS; // removed entry sentinels in table + uint32_t hashShift:8; // multiplicative hash shift -#ifdef DEBUG +#ifdef JS_DEBUG + mozilla::DebugOnly mutationCount; + mutable mozilla::DebugOnly mEntered; mutable struct Stats { uint32_t searches; // total number of table searches @@ -939,16 +1023,12 @@ class HashTable : private AllocPolicy # define METER(x) #endif - friend class mozilla::ReentrancyGuard; - mutable mozilla::DebugOnly entered; - mozilla::DebugOnly mutationCount; - // The default initial capacity is 32 (enough to hold 16 elements), but it // can be as low as 4. static const unsigned sMinCapacityLog2 = 2; static const unsigned sMinCapacity = 1 << sMinCapacityLog2; - static const unsigned sMaxInit = JS_BIT(23); - static const unsigned sMaxCapacity = JS_BIT(24); + static const unsigned sMaxInit = JS_BIT(CAP_BITS - 1); + static const unsigned sMaxCapacity = JS_BIT(CAP_BITS); static const unsigned sHashBits = mozilla::tl::BitSize::value; // Hash-table alpha is conceptually a fraction, but to avoid floating-point @@ -961,6 +1041,11 @@ class HashTable : private AllocPolicy static const HashNumber sRemovedKey = Entry::sRemovedKey; static const HashNumber sCollisionBit = Entry::sCollisionBit; + void setTableSizeLog2(unsigned sizeLog2) + { + hashShift = sHashBits - sizeLog2; + } + static bool isLiveHash(HashNumber hash) { return Entry::isLiveHash(hash); @@ -993,20 +1078,22 @@ class HashTable : private AllocPolicy } public: - HashTable(AllocPolicy ap) - : AllocPolicy(ap), - hashShift(sHashBits), - entryCount(0), - gen(0), - removedCount(0), - table(nullptr), - entered(false), - mutationCount(0) + explicit HashTable(AllocPolicy ap) + : AllocPolicy(ap) + , table(nullptr) + , gen(0) + , entryCount(0) + , removedCount(0) + , hashShift(sHashBits) +#ifdef DEBUG + , mutationCount(0) + , mEntered(false) +#endif {} MOZ_WARN_UNUSED_RESULT bool init(uint32_t length) { - JS_ASSERT(!initialized()); + MOZ_ASSERT(!initialized()); // Reject all lengths whose initial computed capacity would exceed // sMaxCapacity. Round that maximum length down to the nearest power @@ -1116,10 +1203,10 @@ class HashTable : private AllocPolicy Entry &lookup(const Lookup &l, HashNumber keyHash, unsigned collisionBit) const { - JS_ASSERT(isLiveHash(keyHash)); - JS_ASSERT(!(keyHash & sCollisionBit)); - JS_ASSERT(collisionBit == 0 || collisionBit == sCollisionBit); - JS_ASSERT(table); + MOZ_ASSERT(isLiveHash(keyHash)); + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(collisionBit == 0 || collisionBit == sCollisionBit); + MOZ_ASSERT(table); METER(stats.searches++); // Compute the primary hash address. @@ -1145,7 +1232,7 @@ class HashTable : private AllocPolicy Entry *firstRemoved = nullptr; while(true) { - if (JS_UNLIKELY(entry->isRemoved())) { + if (MOZ_UNLIKELY(entry->isRemoved())) { if (!firstRemoved) firstRemoved = entry; } else { @@ -1176,8 +1263,8 @@ class HashTable : private AllocPolicy // from entries, which allows more flexible Lookup/Key types. Entry &findFreeEntry(HashNumber keyHash) { - JS_ASSERT(!(keyHash & sCollisionBit)); - JS_ASSERT(table); + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(table); METER(stats.searches++); // We assume 'keyHash' has already been distributed. @@ -1196,7 +1283,7 @@ class HashTable : private AllocPolicy DoubleHash dh = hash2(keyHash); while(true) { - JS_ASSERT(!entry->isRemoved()); + MOZ_ASSERT(!entry->isRemoved()); entry->setCollision(); METER(stats.steps++); @@ -1277,7 +1364,7 @@ class HashTable : private AllocPolicy void remove(Entry &e) { - JS_ASSERT(table); + MOZ_ASSERT(table); METER(stats.removes++); if (e.hasCollision()) { @@ -1288,7 +1375,9 @@ class HashTable : private AllocPolicy e.clearLive(); } entryCount--; +#ifdef DEBUG mutationCount++; +#endif } void checkUnderloaded() @@ -1371,12 +1460,14 @@ class HashTable : private AllocPolicy } removedCount = 0; entryCount = 0; +#ifdef DEBUG mutationCount++; +#endif } void finish() { - JS_ASSERT(!entered); + MOZ_ASSERT(!mEntered); if (!table) return; @@ -1386,36 +1477,38 @@ class HashTable : private AllocPolicy gen++; entryCount = 0; removedCount = 0; +#ifdef DEBUG mutationCount++; +#endif } Range all() const { - JS_ASSERT(table); - return Range(table, table + capacity()); + MOZ_ASSERT(table); + return Range(*this, table, table + capacity()); } bool empty() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return !entryCount; } uint32_t count() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return entryCount; } uint32_t capacity() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return JS_BIT(sHashBits - hashShift); } uint32_t generation() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return gen; } @@ -1433,13 +1526,13 @@ class HashTable : private AllocPolicy { mozilla::ReentrancyGuard g(*this); HashNumber keyHash = prepareHash(l); - return Ptr(lookup(l, keyHash, 0)); + return Ptr(lookup(l, keyHash, 0), *this); } Ptr readonlyThreadsafeLookup(const Lookup &l) const { HashNumber keyHash = prepareHash(l); - return Ptr(lookup(l, keyHash, 0)); + return Ptr(lookup(l, keyHash, 0), *this); } AddPtr lookupForAdd(const Lookup &l) const @@ -1447,8 +1540,7 @@ class HashTable : private AllocPolicy mozilla::ReentrancyGuard g(*this); HashNumber keyHash = prepareHash(l); Entry &entry = lookup(l, keyHash, sCollisionBit); - AddPtr p(entry, keyHash); - p.mutationCount = mutationCount; + AddPtr p(entry, *this, keyHash); return p; } @@ -1456,10 +1548,9 @@ class HashTable : private AllocPolicy bool add(AddPtr &p, U &&u) { mozilla::ReentrancyGuard g(*this); - JS_ASSERT(mutationCount == p.mutationCount); - JS_ASSERT(table); - JS_ASSERT(!p.found()); - JS_ASSERT(!(p.keyHash & sCollisionBit)); + MOZ_ASSERT(table); + MOZ_ASSERT(!p.found()); + MOZ_ASSERT(!(p.keyHash & sCollisionBit)); // Changing an entry from removed to live does not affect whether we // are overloaded and can be handled separately. @@ -1478,7 +1569,11 @@ class HashTable : private AllocPolicy p.entry_->setLive(p.keyHash, mozilla::Forward(u)); entryCount++; +#ifdef DEBUG mutationCount++; + p.generation = generation(); + p.mutationCount = mutationCount; +#endif return true; } @@ -1487,7 +1582,7 @@ class HashTable : private AllocPolicy template void putNewInfallible(const Lookup &l, U &&u) { - JS_ASSERT(table); + MOZ_ASSERT(table); HashNumber keyHash = prepareHash(l); Entry *entry = &findFreeEntry(keyHash); @@ -1500,7 +1595,9 @@ class HashTable : private AllocPolicy entry->setLive(keyHash, mozilla::Forward(u)); entryCount++; +#ifdef DEBUG mutationCount++; +#endif } // Note: |l| may be a reference to a piece of |u|, so this function @@ -1520,10 +1617,13 @@ class HashTable : private AllocPolicy template bool relookupOrAdd(AddPtr& p, const Lookup &l, U &&u) { +#ifdef DEBUG + p.generation = generation(); p.mutationCount = mutationCount; +#endif { mozilla::ReentrancyGuard g(*this); - JS_ASSERT(prepareHash(l) == p.keyHash); // l has not been destroyed + MOZ_ASSERT(prepareHash(l) == p.keyHash); // l has not been destroyed p.entry_ = &lookup(l, p.keyHash, sCollisionBit); } return p.found() || add(p, mozilla::Forward(u)); @@ -1531,18 +1631,18 @@ class HashTable : private AllocPolicy void remove(Ptr p) { - JS_ASSERT(table); + MOZ_ASSERT(table); mozilla::ReentrancyGuard g(*this); - JS_ASSERT(p.found()); + MOZ_ASSERT(p.found()); remove(*p.entry_); checkUnderloaded(); } void rekeyWithoutRehash(Ptr p, const Lookup &l, const Key &k) { - JS_ASSERT(table); + MOZ_ASSERT(table); mozilla::ReentrancyGuard g(*this); - JS_ASSERT(p.found()); + MOZ_ASSERT(p.found()); typename HashTableEntry::NonConstT t(mozilla::Move(*p)); HashPolicy::setKey(t, const_cast(k)); remove(*p.entry_); @@ -1555,6 +1655,14 @@ class HashTable : private AllocPolicy checkOverRemoved(); } + void rekeyInPlace(Ptr p, const Key &k) + { + MOZ_ASSERT(table); + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(p.found()); + HashPolicy::rekey(const_cast(*p), const_cast(k)); + } + #undef METER }; diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/HeapAPI.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/HeapAPI.h index 9993751d46..bdd63c1937 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/HeapAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/HeapAPI.h @@ -26,11 +26,17 @@ CurrentThreadCanAccessZone(JS::Zone *zone); namespace gc { +struct Cell; + const size_t ArenaShift = 12; const size_t ArenaSize = size_t(1) << ArenaShift; const size_t ArenaMask = ArenaSize - 1; +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkShift = 18; +#else const size_t ChunkShift = 20; +#endif const size_t ChunkSize = size_t(1) << ChunkShift; const size_t ChunkMask = ChunkSize - 1; @@ -39,9 +45,15 @@ const size_t CellSize = size_t(1) << CellShift; const size_t CellMask = CellSize - 1; /* These are magic constants derived from actual offsets in gc/Heap.h. */ -const size_t ChunkMarkBitmapOffset = 1032368; +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkMarkBitmapOffset = 258104; +const size_t ChunkMarkBitmapBits = 31744; +#else +const size_t ChunkMarkBitmapOffset = 1032352; const size_t ChunkMarkBitmapBits = 129024; +#endif const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*); +const size_t ChunkLocationOffset = ChunkSize - 2 * sizeof(void*) - sizeof(uint64_t); /* * Live objects are marked black. How many other additional colors are available @@ -51,14 +63,98 @@ const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*); static const uint32_t BLACK = 0; static const uint32_t GRAY = 1; +/* + * The "location" field in the Chunk trailer is a bit vector indicting various + * roles of the chunk. + * + * The value 0 for the "location" field is invalid, at least one bit must be + * set. + * + * Some bits preclude others, for example, any "nursery" bit precludes any + * "tenured" or "middle generation" bit. + */ +const uintptr_t ChunkLocationBitNursery = 1; // Standard GGC nursery +const uintptr_t ChunkLocationBitTenuredHeap = 2; // Standard GGC tenured generation +const uintptr_t ChunkLocationBitPJSNewspace = 4; // The PJS generational GC's allocation space +const uintptr_t ChunkLocationBitPJSFromspace = 8; // The PJS generational GC's fromspace (during GC) + +const uintptr_t ChunkLocationAnyNursery = ChunkLocationBitNursery | + ChunkLocationBitPJSNewspace | + ChunkLocationBitPJSFromspace; + +#ifdef JS_DEBUG +/* When downcasting, ensure we are actually the right type. */ +extern JS_FRIEND_API(void) +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind); +#else +inline void +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind) {} +#endif + } /* namespace gc */ } /* namespace js */ namespace JS { struct Zone; -} /* namespace JS */ -namespace JS { +/* Default size for the generational nursery in bytes. */ +const uint32_t DefaultNurseryBytes = 16 * 1024 * 1024; + +/* Default maximum heap size in bytes to pass to JS_NewRuntime(). */ +const uint32_t DefaultHeapMaxBytes = 32 * 1024 * 1024; + +/* + * We cannot expose the class hierarchy: the implementation is hidden. Instead + * we provide cast functions with strong debug-mode assertions. + */ +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSObject *obj) +{ + js::gc::Cell *cell = reinterpret_cast(obj); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFunction *fun) +{ + js::gc::Cell *cell = reinterpret_cast(fun); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSString *str) +{ + js::gc::Cell *cell = reinterpret_cast(str); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFlatString *flat) +{ + js::gc::Cell *cell = reinterpret_cast(flat); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JS::Symbol *sym) +{ + js::gc::Cell *cell = reinterpret_cast(sym); + AssertGCThingHasType(cell, JSTRACE_SYMBOL); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSScript *script) +{ + js::gc::Cell *cell = reinterpret_cast(script); + AssertGCThingHasType(cell, JSTRACE_SCRIPT); + return cell; +} + namespace shadow { struct ArenaHeader @@ -86,13 +182,13 @@ struct Zone } JSTracer *barrierTracer() { - JS_ASSERT(needsBarrier_); - JS_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + MOZ_ASSERT(needsBarrier_); + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); return barrierTracer_; } JSRuntime *runtimeFromMainThread() const { - JS_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); return runtime_; } @@ -113,40 +209,40 @@ struct Zone namespace js { namespace gc { -static JS_ALWAYS_INLINE uintptr_t * +static MOZ_ALWAYS_INLINE uintptr_t * GetGCThingMarkBitmap(const void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); uintptr_t addr = uintptr_t(thing); addr &= ~js::gc::ChunkMask; addr |= js::gc::ChunkMarkBitmapOffset; return reinterpret_cast(addr); } -static JS_ALWAYS_INLINE JS::shadow::Runtime * +static MOZ_ALWAYS_INLINE JS::shadow::Runtime * GetGCThingRuntime(const void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); uintptr_t addr = uintptr_t(thing); addr &= ~js::gc::ChunkMask; addr |= js::gc::ChunkRuntimeOffset; return *reinterpret_cast(addr); } -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void GetGCThingMarkWordAndMask(const void *thing, uint32_t color, uintptr_t **wordp, uintptr_t *maskp) { uintptr_t addr = uintptr_t(thing); size_t bit = (addr & js::gc::ChunkMask) / js::gc::CellSize + color; - JS_ASSERT(bit < js::gc::ChunkMarkBitmapBits); + MOZ_ASSERT(bit < js::gc::ChunkMarkBitmapBits); uintptr_t *bitmap = GetGCThingMarkBitmap(thing); const uintptr_t nbits = sizeof(*bitmap) * CHAR_BIT; *maskp = uintptr_t(1) << (bit % nbits); *wordp = &bitmap[bit / nbits]; } -static JS_ALWAYS_INLINE JS::shadow::ArenaHeader * +static MOZ_ALWAYS_INLINE JS::shadow::ArenaHeader * GetGCThingArena(void *thing) { uintptr_t addr = uintptr_t(thing); @@ -154,11 +250,18 @@ GetGCThingArena(void *thing) return reinterpret_cast(addr); } -JS_ALWAYS_INLINE bool -IsInsideNursery(const JS::shadow::Runtime *runtime, const void *p) +MOZ_ALWAYS_INLINE bool +IsInsideNursery(const js::gc::Cell *cell) { #ifdef JSGC_GENERATIONAL - return uintptr_t(p) >= runtime->gcNurseryStart_ && uintptr_t(p) < runtime->gcNurseryEnd_; + if (!cell) + return false; + uintptr_t addr = uintptr_t(cell); + addr &= ~js::gc::ChunkMask; + addr |= js::gc::ChunkLocationOffset; + uint32_t location = *reinterpret_cast(addr); + JS_ASSERT(location != 0); + return location & ChunkLocationAnyNursery; #else return false; #endif @@ -170,20 +273,20 @@ IsInsideNursery(const JS::shadow::Runtime *runtime, const void *p) namespace JS { -static JS_ALWAYS_INLINE Zone * +static MOZ_ALWAYS_INLINE Zone * GetGCThingZone(void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); return js::gc::GetGCThingArena(thing)->zone; } -static JS_ALWAYS_INLINE Zone * +static MOZ_ALWAYS_INLINE Zone * GetObjectZone(JSObject *obj) { return GetGCThingZone(obj); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool GCThingIsMarkedGray(void *thing) { #ifdef JSGC_GENERATIONAL @@ -192,8 +295,7 @@ GCThingIsMarkedGray(void *thing) * All live objects in the nursery are moved to tenured at the beginning of * each GC slice, so the gray marker never sees nursery things. */ - JS::shadow::Runtime *rt = js::gc::GetGCThingRuntime(thing); - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return false; #endif uintptr_t *word, mask; @@ -201,7 +303,7 @@ GCThingIsMarkedGray(void *thing) return *word & mask; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool IsIncrementalBarrierNeededOnGCThing(shadow::Runtime *rt, void *thing, JSGCTraceKind kind) { if (!rt->needsBarrier_) diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/Id.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/Id.h index 447deb62e6..11116f2efe 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/Id.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/Id.h @@ -21,164 +21,155 @@ // JS_IdToValue must be used instead. #include "mozilla/NullPtr.h" - + #include "jstypes.h" +#include "js/HeapAPI.h" #include "js/RootingAPI.h" #include "js/TypeDecls.h" #include "js/Utility.h" -#ifdef JS_USE_JSID_STRUCT_TYPES struct jsid { size_t asBits; bool operator==(jsid rhs) const { return asBits == rhs.asBits; } bool operator!=(jsid rhs) const { return asBits != rhs.asBits; } }; -# define JSID_BITS(id) (id.asBits) -#else -# define JSID_BITS(id) (id) -#endif +#define JSID_BITS(id) (id.asBits) #define JSID_TYPE_STRING 0x0 #define JSID_TYPE_INT 0x1 #define JSID_TYPE_VOID 0x2 -#define JSID_TYPE_OBJECT 0x4 +#define JSID_TYPE_SYMBOL 0x4 #define JSID_TYPE_MASK 0x7 // Avoid using canonical 'id' for jsid parameters since this is a magic word in // Objective-C++ which, apparently, wants to be able to #include jsapi.h. #define id iden -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_STRING(jsid id) { return (JSID_BITS(id) & JSID_TYPE_MASK) == 0; } -static JS_ALWAYS_INLINE JSString * +static MOZ_ALWAYS_INLINE JSString * JSID_TO_STRING(jsid id) { - JS_ASSERT(JSID_IS_STRING(id)); + MOZ_ASSERT(JSID_IS_STRING(id)); return (JSString *)JSID_BITS(id); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ZERO(jsid id) { return JSID_BITS(id) == 0; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_INT(jsid id) { return !!(JSID_BITS(id) & JSID_TYPE_INT); } -static JS_ALWAYS_INLINE int32_t +static MOZ_ALWAYS_INLINE int32_t JSID_TO_INT(jsid id) { - JS_ASSERT(JSID_IS_INT(id)); + MOZ_ASSERT(JSID_IS_INT(id)); return ((uint32_t)JSID_BITS(id)) >> 1; } #define JSID_INT_MIN 0 #define JSID_INT_MAX INT32_MAX -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool INT_FITS_IN_JSID(int32_t i) { return i >= 0; } -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid INT_TO_JSID(int32_t i) { jsid id; - JS_ASSERT(INT_FITS_IN_JSID(i)); + MOZ_ASSERT(INT_FITS_IN_JSID(i)); JSID_BITS(id) = ((i << 1) | JSID_TYPE_INT); return id; } -static JS_ALWAYS_INLINE bool -JSID_IS_OBJECT(jsid id) +static MOZ_ALWAYS_INLINE bool +JSID_IS_SYMBOL(jsid id) { - return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_OBJECT && - (size_t)JSID_BITS(id) != JSID_TYPE_OBJECT; + return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_SYMBOL && + JSID_BITS(id) != JSID_TYPE_SYMBOL; } -static JS_ALWAYS_INLINE JSObject * -JSID_TO_OBJECT(jsid id) +static MOZ_ALWAYS_INLINE JS::Symbol * +JSID_TO_SYMBOL(jsid id) { - JS_ASSERT(JSID_IS_OBJECT(id)); - return (JSObject *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); + MOZ_ASSERT(JSID_IS_SYMBOL(id)); + return (JS::Symbol *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); } -static JS_ALWAYS_INLINE jsid -OBJECT_TO_JSID(JSObject *obj) +static MOZ_ALWAYS_INLINE jsid +SYMBOL_TO_JSID(JS::Symbol *sym) { jsid id; - JS_ASSERT(obj != nullptr); - JS_ASSERT(((size_t)obj & JSID_TYPE_MASK) == 0); - JSID_BITS(id) = ((size_t)obj | JSID_TYPE_OBJECT); + MOZ_ASSERT(sym != nullptr); + MOZ_ASSERT((size_t(sym) & JSID_TYPE_MASK) == 0); + JS_ASSERT(!js::gc::IsInsideNursery(JS::AsCell(sym))); + JS_ASSERT(!JS::IsPoisonedPtr(sym)); + JSID_BITS(id) = (size_t(sym) | JSID_TYPE_SYMBOL); return id; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_GCTHING(jsid id) { - return JSID_IS_STRING(id) || JSID_IS_OBJECT(id); + return JSID_IS_STRING(id) || JSID_IS_SYMBOL(id); } -static JS_ALWAYS_INLINE void * +static MOZ_ALWAYS_INLINE void * JSID_TO_GCTHING(jsid id) { return (void *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_VOID(const jsid id) { - JS_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID, + MOZ_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID, JSID_BITS(id) == JSID_TYPE_VOID); return ((size_t)JSID_BITS(id) == JSID_TYPE_VOID); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_EMPTY(const jsid id) { - return ((size_t)JSID_BITS(id) == JSID_TYPE_OBJECT); + return ((size_t)JSID_BITS(id) == JSID_TYPE_SYMBOL); } -#undef id - -#ifdef JS_USE_JSID_STRUCT_TYPES extern JS_PUBLIC_DATA(const jsid) JSID_VOID; extern JS_PUBLIC_DATA(const jsid) JSID_EMPTY; -#else -# define JSID_VOID ((jsid)JSID_TYPE_VOID) -# define JSID_EMPTY ((jsid)JSID_TYPE_OBJECT) -#endif -extern JS_PUBLIC_DATA(const JS::Handle) JSID_VOIDHANDLE; -extern JS_PUBLIC_DATA(const JS::Handle) JSID_EMPTYHANDLE; +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_VOIDHANDLE; +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_EMPTYHANDLE; namespace js { inline bool -IsPoisonedId(jsid iden) +IsPoisonedId(jsid id) { - if (JSID_IS_STRING(iden)) - return JS::IsPoisonedPtr(JSID_TO_STRING(iden)); - if (JSID_IS_OBJECT(iden)) - return JS::IsPoisonedPtr(JSID_TO_OBJECT(iden)); + if (JSID_IS_STRING(id)) + return JS::IsPoisonedPtr(JSID_TO_STRING(id)); + if (JSID_IS_SYMBOL(id)) + return JS::IsPoisonedPtr(JSID_TO_SYMBOL(id)); return false; } template <> struct GCMethods { static jsid initial() { return JSID_VOID; } - static ThingRootKind kind() { return THING_ROOT_ID; } static bool poisoned(jsid id) { return IsPoisonedId(id); } static bool needsPostBarrier(jsid id) { return false; } #ifdef JSGC_GENERATIONAL @@ -187,6 +178,8 @@ template <> struct GCMethods #endif }; +#undef id + } #endif /* js_Id_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/MemoryMetrics.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/MemoryMetrics.h index 95ac91b9f6..31e456baba 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/MemoryMetrics.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/MemoryMetrics.h @@ -77,6 +77,13 @@ struct InefficientNonFlatteningStringHashPolicy static bool match(const JSString *const &k, const Lookup &l); }; +struct CStringHashPolicy +{ + typedef const char *Lookup; + static HashNumber hash(const Lookup &l); + static bool match(const char *const &k, const Lookup &l); +}; + // This file features many classes with numerous size_t fields, and each such // class has one or more methods that need to operate on all of these fields. // Writing these individually is error-prone -- it's easy to add a new field @@ -92,6 +99,9 @@ struct InefficientNonFlatteningStringHashPolicy #define ZERO_SIZE(kind, gc, mSize) mSize(0), #define COPY_OTHER_SIZE(kind, gc, mSize) mSize(other.mSize), #define ADD_OTHER_SIZE(kind, gc, mSize) mSize += other.mSize; +#define SUB_OTHER_SIZE(kind, gc, mSize) MOZ_ASSERT(mSize >= other.mSize); \ + mSize -= other.mSize; +#define ADD_SIZE_TO_N(kind, gc, mSize) n += mSize; #define ADD_SIZE_TO_N_IF_LIVE_GC_THING(kind, gc, mSize) n += (js::gc) ? mSize : 0; #define ADD_TO_TAB_SIZES(kind, gc, mSize) sizes->add(JS::TabSizes::kind, mSize); @@ -101,49 +111,6 @@ enum { IsLiveGCThing = true }; -struct ZoneStatsPod -{ -#define FOR_EACH_SIZE(macro) \ - macro(Other, NotLiveGCThing, gcHeapArenaAdmin) \ - macro(Other, NotLiveGCThing, unusedGCThings) \ - macro(Other, IsLiveGCThing, lazyScriptsGCHeap) \ - macro(Other, NotLiveGCThing, lazyScriptsMallocHeap) \ - macro(Other, IsLiveGCThing, ionCodesGCHeap) \ - macro(Other, IsLiveGCThing, typeObjectsGCHeap) \ - macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \ - macro(Other, NotLiveGCThing, typePool) \ - macro(Strings, IsLiveGCThing, stringsShortGCHeap) \ - macro(Strings, IsLiveGCThing, stringsNormalGCHeap) \ - macro(Strings, NotLiveGCThing, stringsNormalMallocHeap) - - ZoneStatsPod() - : FOR_EACH_SIZE(ZERO_SIZE) - extra() - {} - - void add(const ZoneStatsPod &other) { - FOR_EACH_SIZE(ADD_OTHER_SIZE) - // Do nothing with |extra|. - } - - size_t sizeOfLiveGCThings() const { - size_t n = 0; - FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) - // Do nothing with |extra|. - return n; - } - - void addToTabSizes(JS::TabSizes *sizes) const { - FOR_EACH_SIZE(ADD_TO_TAB_SIZES) - // Do nothing with |extra|. - } - - FOR_EACH_SIZE(DECL_SIZE) - void *extra; // This field can be used by embedders. - -#undef FOR_EACH_SIZE -}; - } // namespace js namespace JS { @@ -156,6 +123,7 @@ struct ObjectsExtraSizes macro(Objects, NotLiveGCThing, mallocHeapElementsNonAsmJS) \ macro(Objects, NotLiveGCThing, mallocHeapElementsAsmJS) \ macro(Objects, NotLiveGCThing, nonHeapElementsAsmJS) \ + macro(Objects, NotLiveGCThing, nonHeapElementsMapped) \ macro(Objects, NotLiveGCThing, nonHeapCodeAsmJS) \ macro(Objects, NotLiveGCThing, mallocHeapAsmJSModuleData) \ macro(Objects, NotLiveGCThing, mallocHeapArgumentsData) \ @@ -209,6 +177,33 @@ struct CodeSizes #undef FOR_EACH_SIZE }; +// Data for tracking GC memory usage. +struct GCSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, marker) \ + macro(_, _, nurseryCommitted) \ + macro(_, _, nurseryDecommitted) \ + macro(_, _, nurseryHugeSlots) \ + macro(_, _, storeBufferVals) \ + macro(_, _, storeBufferCells) \ + macro(_, _, storeBufferSlots) \ + macro(_, _, storeBufferWholeCells) \ + macro(_, _, storeBufferRelocVals) \ + macro(_, _, storeBufferRelocCells) \ + macro(_, _, storeBufferGenerics) + + GCSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + dummy() + {} + + FOR_EACH_SIZE(DECL_SIZE) + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) + +#undef FOR_EACH_SIZE +}; + // This class holds information about the memory taken up by identical copies of // a particular string. Multiple JSStrings may have their sizes aggregated // together into one StringInfo object. Note that two strings with identical @@ -216,50 +211,59 @@ struct CodeSizes // is not. struct StringInfo { - StringInfo() - : numCopies(0), - isShort(0), - gcHeap(0), - mallocHeap(0) - {} +#define FOR_EACH_SIZE(macro) \ + macro(Strings, IsLiveGCThing, gcHeapLatin1) \ + macro(Strings, IsLiveGCThing, gcHeapTwoByte) \ + macro(Strings, NotLiveGCThing, mallocHeapLatin1) \ + macro(Strings, NotLiveGCThing, mallocHeapTwoByte) - StringInfo(bool isShort, size_t gcSize, size_t mallocSize) - : numCopies(1), - isShort(isShort), - gcHeap(gcSize), - mallocHeap(mallocSize) + StringInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numCopies(0) {} - void add(bool isShort, size_t gcSize, size_t mallocSize) { + void add(const StringInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE); numCopies++; - MOZ_ASSERT(isShort == this->isShort); - gcHeap += gcSize; - mallocHeap += mallocSize; } - void add(const StringInfo& info) { - numCopies += info.numCopies; - MOZ_ASSERT(info.isShort == isShort); - gcHeap += info.gcHeap; - mallocHeap += info.mallocHeap; + void subtract(const StringInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE); + numCopies--; } - uint32_t numCopies:31; // How many copies of the string have we seen? - uint32_t isShort:1; // Is it a short string? + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + size_t sizeOfLiveGCThings() const { + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + return n; + } + + void addToTabSizes(TabSizes *sizes) const { + FOR_EACH_SIZE(ADD_TO_TAB_SIZES) + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numCopies; // How many copies of the string have we seen? - // These are all totals across all copies of the string we've seen. - size_t gcHeap; - size_t mallocHeap; +#undef FOR_EACH_SIZE }; -// Holds data about a notable string (one which uses more than -// NotableStringInfo::notableSize() bytes of memory), so we can report it -// individually. +// Holds data about a notable string (one which, counting all duplicates, uses +// more than a certain amount of memory) so we can report it individually. // -// Essentially the only difference between this class and StringInfo is that -// NotableStringInfo holds a copy of the string's chars. +// The only difference between this class and StringInfo is that +// NotableStringInfo holds a copy of some or all of the string's chars. struct NotableStringInfo : public StringInfo { + static const size_t MAX_SAVED_CHARS = 1024; + NotableStringInfo(); NotableStringInfo(JSString *str, const StringInfo &info); NotableStringInfo(NotableStringInfo &&info); @@ -269,12 +273,6 @@ struct NotableStringInfo : public StringInfo js_free(buffer); } - // A string needs to take up this many bytes of storage before we consider - // it to be "notable". - static size_t notableSize() { - return js::MemoryReportingSundriesThreshold(); - } - char *buffer; size_t length; @@ -282,6 +280,67 @@ struct NotableStringInfo : public StringInfo NotableStringInfo(const NotableStringInfo& info) MOZ_DELETE; }; +// This class holds information about the memory taken up by script sources +// from a particular file. +struct ScriptSourceInfo +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, compressed) \ + macro(_, _, uncompressed) \ + macro(_, _, misc) + + ScriptSourceInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numScripts(0) + {} + + void add(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE) + numScripts++; + } + + void subtract(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE) + numScripts--; + } + + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numScripts; // How many ScriptSources come from this file? (It + // can be more than one in XML files that have + // multiple scripts in CDATA sections.) +#undef FOR_EACH_SIZE +}; + +// Holds data about a notable script source file (one whose combined +// script sources use more than a certain amount of memory) so we can report it +// individually. +// +// The only difference between this class and ScriptSourceInfo is that this +// class holds a copy of the filename. +struct NotableScriptSourceInfo : public ScriptSourceInfo +{ + NotableScriptSourceInfo(); + NotableScriptSourceInfo(const char *filename, const ScriptSourceInfo &info); + NotableScriptSourceInfo(NotableScriptSourceInfo &&info); + NotableScriptSourceInfo &operator=(NotableScriptSourceInfo &&info); + + ~NotableScriptSourceInfo() { + js_free(filename_); + } + + char *filename_; + + private: + NotableScriptSourceInfo(const NotableScriptSourceInfo& info) MOZ_DELETE; +}; + // These measurements relate directly to the JSRuntime, and not to zones and // compartments within it. struct RuntimeSizes @@ -292,81 +351,139 @@ struct RuntimeSizes macro(_, _, contexts) \ macro(_, _, dtoa) \ macro(_, _, temporary) \ - macro(_, _, regexpData) \ macro(_, _, interpreterStack) \ - macro(_, _, gcMarker) \ macro(_, _, mathCache) \ + macro(_, _, uncompressedSourceCache) \ + macro(_, _, compressedSourceSet) \ macro(_, _, scriptData) \ - macro(_, _, scriptSources) RuntimeSizes() : FOR_EACH_SIZE(ZERO_SIZE) - code() - {} + scriptSourceInfo(), + code(), + gc(), + notableScriptSources() + { + allScriptSources = js_new(); + if (!allScriptSources || !allScriptSources->init()) + MOZ_CRASH("oom"); + } + ~RuntimeSizes() { + // |allScriptSources| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allScriptSources); + } + + // The script source measurements in |scriptSourceInfo| are initially for + // all script sources. At the end, if the measurement granularity is + // FineGrained, we subtract the measurements of the notable script sources + // and move them into |notableScriptSources|. FOR_EACH_SIZE(DECL_SIZE) - CodeSizes code; + ScriptSourceInfo scriptSourceInfo; + CodeSizes code; + GCSizes gc; + + typedef js::HashMap ScriptSourcesHashMap; + + // |allScriptSources| is only used transiently. During the reporting phase + // it is filled with info about every script source in the runtime. It's + // then used to fill in |notableScriptSources| (which actually gets + // reported), and immediately discarded afterwards. + ScriptSourcesHashMap *allScriptSources; + js::Vector notableScriptSources; #undef FOR_EACH_SIZE }; -struct ZoneStats : js::ZoneStatsPod +struct ZoneStats { +#define FOR_EACH_SIZE(macro) \ + macro(Other, IsLiveGCThing, symbolsGCHeap) \ + macro(Other, NotLiveGCThing, gcHeapArenaAdmin) \ + macro(Other, NotLiveGCThing, unusedGCThings) \ + macro(Other, IsLiveGCThing, lazyScriptsGCHeap) \ + macro(Other, NotLiveGCThing, lazyScriptsMallocHeap) \ + macro(Other, IsLiveGCThing, jitCodesGCHeap) \ + macro(Other, IsLiveGCThing, typeObjectsGCHeap) \ + macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \ + macro(Other, NotLiveGCThing, typePool) \ + macro(Other, NotLiveGCThing, baselineStubsOptimized) \ + ZoneStats() - : strings(nullptr) + : FOR_EACH_SIZE(ZERO_SIZE) + stringInfo(), + extra(), + allStrings(nullptr), + notableStrings(), + isTotals(true) {} ZoneStats(ZoneStats &&other) - : ZoneStatsPod(mozilla::Move(other)), - strings(other.strings), - notableStrings(mozilla::Move(other.notableStrings)) + : FOR_EACH_SIZE(COPY_OTHER_SIZE) + stringInfo(mozilla::Move(other.stringInfo)), + extra(other.extra), + allStrings(other.allStrings), + notableStrings(mozilla::Move(other.notableStrings)), + isTotals(other.isTotals) { - other.strings = nullptr; + other.allStrings = nullptr; + MOZ_ASSERT(!other.isTotals); } - bool initStrings(JSRuntime *rt); - - // Add |other|'s numbers to this object's numbers. The strings data isn't - // touched. - void addIgnoringStrings(const ZoneStats &other) { - ZoneStatsPod::add(other); + ~ZoneStats() { + // |allStrings| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allStrings); } - // Add |other|'s strings data to this object's strings data. (We don't do - // anything with notableStrings.) - void addStrings(const ZoneStats &other) { - for (StringsHashMap::Range r = other.strings->all(); !r.empty(); r.popFront()) { - StringsHashMap::AddPtr p = strings->lookupForAdd(r.front().key()); - if (p) { - // We've seen this string before; add its size to our tally. - p->value().add(r.front().value()); - } else { - // We haven't seen this string before; add it to the hashtable. - strings->add(p, r.front().key(), r.front().value()); - } - } + bool initStrings(JSRuntime *rt); + + void addSizes(const ZoneStats &other) { + MOZ_ASSERT(isTotals); + FOR_EACH_SIZE(ADD_OTHER_SIZE) + stringInfo.add(other.stringInfo); } size_t sizeOfLiveGCThings() const { - size_t n = ZoneStatsPod::sizeOfLiveGCThings(); - for (size_t i = 0; i < notableStrings.length(); i++) { - const JS::NotableStringInfo& info = notableStrings[i]; - n += info.gcHeap; - } + MOZ_ASSERT(isTotals); + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + n += stringInfo.sizeOfLiveGCThings(); return n; } - typedef js::HashMap StringsHashMap; - // |strings| is only used transiently. During the zone traversal it is + // |allStrings| is only used transiently. During the zone traversal it is // filled with info about every string in the zone. It's then used to fill // in |notableStrings| (which actually gets reported), and immediately // discarded afterwards. - StringsHashMap *strings; + StringsHashMap *allStrings; js::Vector notableStrings; + bool isTotals; + +#undef FOR_EACH_SIZE }; struct CompartmentStats @@ -390,17 +507,16 @@ struct CompartmentStats macro(Other, NotLiveGCThing, scriptsMallocHeapData) \ macro(Other, NotLiveGCThing, baselineData) \ macro(Other, NotLiveGCThing, baselineStubsFallback) \ - macro(Other, NotLiveGCThing, baselineStubsOptimized) \ macro(Other, NotLiveGCThing, ionData) \ macro(Other, NotLiveGCThing, typeInferenceTypeScripts) \ - macro(Other, NotLiveGCThing, typeInferencePendingArrays) \ macro(Other, NotLiveGCThing, typeInferenceAllocationSiteTables) \ macro(Other, NotLiveGCThing, typeInferenceArrayTypeTables) \ macro(Other, NotLiveGCThing, typeInferenceObjectTypeTables) \ macro(Other, NotLiveGCThing, compartmentObject) \ macro(Other, NotLiveGCThing, crossCompartmentWrappersTable) \ macro(Other, NotLiveGCThing, regexpCompartment) \ - macro(Other, NotLiveGCThing, debuggeesSet) + macro(Other, NotLiveGCThing, debuggeesSet) \ + macro(Other, NotLiveGCThing, savedStacksSet) CompartmentStats() : FOR_EACH_SIZE(ZERO_SIZE) @@ -454,7 +570,7 @@ struct RuntimeStats macro(_, _, gcHeapChunkAdmin) \ macro(_, _, gcHeapGCThings) \ - RuntimeStats(mozilla::MallocSizeOf mallocSizeOf) + explicit RuntimeStats(mozilla::MallocSizeOf mallocSizeOf) : FOR_EACH_SIZE(ZERO_SIZE) runtime(), cTotals(), @@ -517,13 +633,13 @@ class ObjectPrivateVisitor typedef bool(*GetISupportsFun)(JSObject *obj, nsISupports **iface); GetISupportsFun getISupports_; - ObjectPrivateVisitor(GetISupportsFun getISupports) + explicit ObjectPrivateVisitor(GetISupportsFun getISupports) : getISupports_(getISupports) {} }; extern JS_PUBLIC_API(bool) -CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv); +CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv, bool anonymize); extern JS_PUBLIC_API(size_t) SystemCompartmentCount(JSRuntime *rt); @@ -544,6 +660,8 @@ AddSizeOfTab(JSRuntime *rt, JS::HandleObject obj, mozilla::MallocSizeOf mallocSi #undef ZERO_SIZE #undef COPY_OTHER_SIZE #undef ADD_OTHER_SIZE +#undef SUB_OTHER_SIZE +#undef ADD_SIZE_TO_N #undef ADD_SIZE_TO_N_IF_LIVE_GC_THING #undef ADD_TO_TAB_SIZES diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/OldDebugAPI.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/OldDebugAPI.h index 5e5bdf38d7..7117d754d9 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/OldDebugAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/OldDebugAPI.h @@ -12,47 +12,40 @@ */ #include "mozilla/NullPtr.h" - + +#include "jsapi.h" #include "jsbytecode.h" #include "js/CallArgs.h" #include "js/TypeDecls.h" class JSAtom; -class JSFreeOp; - -namespace js { class StackFrame; } +struct JSFreeOp; -namespace JS { - -struct FrameDescription -{ - JSScript *script; - unsigned lineno; - JSFunction *fun; -}; +namespace js { +class InterpreterFrame; +class FrameIter; +class ScriptSource; +} -struct StackDescription -{ - unsigned nframes; - FrameDescription *frames; -}; +// Raw JSScript* because this needs to be callable from a signal handler. +extern JS_PUBLIC_API(unsigned) +JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); -extern JS_PUBLIC_API(StackDescription *) -DescribeStack(JSContext *cx, unsigned maxFrames); +extern JS_PUBLIC_API(const char *) +JS_GetScriptFilename(JSScript *script); -extern JS_PUBLIC_API(void) -FreeStackDescription(JSContext *cx, StackDescription *desc); +namespace JS { extern JS_PUBLIC_API(char *) FormatStackDump(JSContext *cx, char *buf, bool showArgs, bool showLocals, bool showThisProps); -} +} // namespace JS -# ifdef DEBUG +# ifdef JS_DEBUG JS_FRIEND_API(void) js_DumpValue(const JS::Value &val); JS_FRIEND_API(void) js_DumpId(jsid id); -JS_FRIEND_API(void) js_DumpStackFrame(JSContext *cx, js::StackFrame *start = nullptr); +JS_FRIEND_API(void) js_DumpInterpreterFrame(JSContext *cx, js::InterpreterFrame *start = nullptr); # endif JS_FRIEND_API(void) @@ -70,48 +63,21 @@ typedef JSTrapStatus (* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, JS::Value closure); -typedef JSTrapStatus -(* JSInterruptHook)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, - void *closure); - typedef JSTrapStatus (* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, void *closure); -typedef JSTrapStatus -(* JSThrowHook)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, - void *closure); - typedef bool (* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, JS::Value old, JS::Value *newp, void *closure); -/* called just after script creation */ -typedef void -(* JSNewScriptHook)(JSContext *cx, - const char *filename, /* URL of script */ - unsigned lineno, /* first line */ - JSScript *script, - JSFunction *fun, - void *callerdata); - -/* called just before script destruction */ -typedef void -(* JSDestroyScriptHook)(JSFreeOp *fop, - JSScript *script, - void *callerdata); - -typedef void -(* JSSourceHandler)(const char *filename, unsigned lineno, const jschar *str, - size_t length, void **listenerTSData, void *closure); - extern JS_PUBLIC_API(JSCompartment *) JS_EnterCompartmentOfScript(JSContext *cx, JSScript *target); extern JS_PUBLIC_API(JSString *) -JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned indent); +JS_DecompileScript(JSContext *cx, JS::HandleScript script, const char *name, unsigned indent); /* * Currently, we only support runtime-wide debugging. In the future, we should @@ -157,12 +123,12 @@ JS_SetDebugMode(JSContext *cx, bool debug); /* Turn on single step mode. */ extern JS_PUBLIC_API(bool) -JS_SetSingleStepMode(JSContext *cx, JSScript *script, bool singleStep); +JS_SetSingleStepMode(JSContext *cx, JS::HandleScript script, bool singleStep); /* The closure argument will be marked. */ extern JS_PUBLIC_API(bool) -JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc, - JSTrapHandler handler, JS::Value closure); +JS_SetTrap(JSContext *cx, JS::HandleScript script, jsbytecode *pc, + JSTrapHandler handler, JS::HandleValue closure); extern JS_PUBLIC_API(void) JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc, @@ -174,17 +140,11 @@ JS_ClearScriptTraps(JSRuntime *rt, JSScript *script); extern JS_PUBLIC_API(void) JS_ClearAllTrapsForCompartment(JSContext *cx); -extern JS_PUBLIC_API(bool) -JS_SetInterrupt(JSRuntime *rt, JSInterruptHook handler, void *closure); - -extern JS_PUBLIC_API(bool) -JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *handlerp, void **closurep); - /************************************************************************/ extern JS_PUBLIC_API(bool) -JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsid id, - JSWatchPointHandler handler, JSObject *closure); +JS_SetWatchPoint(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JSWatchPointHandler handler, JS::HandleObject closure); extern JS_PUBLIC_API(bool) JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id, @@ -195,10 +155,6 @@ JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj); /************************************************************************/ -// Raw JSScript* because this needs to be callable from a signal handler. -extern JS_PUBLIC_API(unsigned) -JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); - extern JS_PUBLIC_API(jsbytecode *) JS_LineNumberToPC(JSContext *cx, JSScript *script, unsigned lineno); @@ -234,17 +190,11 @@ extern JS_PUBLIC_API(void) JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mark); extern JS_PUBLIC_API(JSScript *) -JS_GetFunctionScript(JSContext *cx, JSFunction *fun); +JS_GetFunctionScript(JSContext *cx, JS::HandleFunction fun); extern JS_PUBLIC_API(JSNative) JS_GetFunctionNative(JSContext *cx, JSFunction *fun); -extern JS_PUBLIC_API(JSPrincipals *) -JS_GetScriptPrincipals(JSScript *script); - -extern JS_PUBLIC_API(JSPrincipals *) -JS_GetScriptOriginPrincipals(JSScript *script); - JS_PUBLIC_API(JSFunction *) JS_GetScriptFunction(JSContext *cx, JSScript *script); @@ -264,9 +214,6 @@ JS_GetDebugClassName(JSObject *obj); /************************************************************************/ -extern JS_PUBLIC_API(const char *) -JS_GetScriptFilename(JSContext *cx, JSScript *script); - extern JS_PUBLIC_API(const jschar *) JS_GetScriptSourceMap(JSContext *cx, JSScript *script); @@ -284,22 +231,6 @@ JS_GetScriptIsSelfHosted(JSScript *script); /************************************************************************/ -/* - * Hook setters for script creation and destruction. These macros provide - * binary compatibility and newer, shorter synonyms. - */ -#define JS_SetNewScriptHook JS_SetNewScriptHookProc -#define JS_SetDestroyScriptHook JS_SetDestroyScriptHookProc - -extern JS_PUBLIC_API(void) -JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata); - -extern JS_PUBLIC_API(void) -JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook, - void *callerdata); - -/************************************************************************/ - typedef struct JSPropertyDesc { JS::Value id; /* primary id, atomized string, or int */ JS::Value value; /* property value */ @@ -325,7 +256,7 @@ typedef struct JSPropertyDescArray { typedef struct JSScopeProperty JSScopeProperty; extern JS_PUBLIC_API(bool) -JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda); +JS_GetPropertyDescArray(JSContext *cx, JS::HandleObject obj, JSPropertyDescArray *pda); extern JS_PUBLIC_API(void) JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); @@ -339,16 +270,18 @@ JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); class JS_PUBLIC_API(JSAbstractFramePtr) { uintptr_t ptr_; + jsbytecode *pc_; protected: JSAbstractFramePtr() - : ptr_(0) + : ptr_(0), pc_(nullptr) { } public: - explicit JSAbstractFramePtr(void *raw); + JSAbstractFramePtr(void *raw, jsbytecode *pc); uintptr_t raw() const { return ptr_; } + jsbytecode *pc() const { return pc_; } operator bool() const { return !!ptr_; } @@ -393,7 +326,7 @@ class JS_PUBLIC_API(JSBrokenFrameIterator) void *data_; public: - JSBrokenFrameIterator(JSContext *cx); + explicit JSBrokenFrameIterator(JSContext *cx); ~JSBrokenFrameIterator(); bool done() const; @@ -405,58 +338,13 @@ class JS_PUBLIC_API(JSBrokenFrameIterator) bool isConstructing() const; }; -/* - * This hook captures high level script execution and function calls (JS or - * native). It is used by JS_SetExecuteHook to hook top level scripts and by - * JS_SetCallHook to hook function calls. It will get called twice per script - * or function call: just before execution begins and just after it finishes. - * In both cases the 'current' frame is that of the executing code. - * - * The 'before' param is true for the hook invocation before the execution - * and false for the invocation after the code has run. - * - * The 'ok' param is significant only on the post execution invocation to - * signify whether or not the code completed 'normally'. - * - * The 'closure' param is as passed to JS_SetExecuteHook or JS_SetCallHook - * for the 'before'invocation, but is whatever value is returned from that - * invocation for the 'after' invocation. Thus, the hook implementor *could* - * allocate a structure in the 'before' invocation and return a pointer to that - * structure. The pointer would then be handed to the hook for the 'after' - * invocation. Alternately, the 'before' could just return the same value as - * in 'closure' to cause the 'after' invocation to be called with the same - * 'closure' value as the 'before'. - * - * Returning nullptr in the 'before' hook will cause the 'after' hook *not* to - * be called. - */ -typedef void * -(* JSInterpreterHook)(JSContext *cx, JSAbstractFramePtr frame, bool isConstructing, - bool before, bool *ok, void *closure); - typedef bool (* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report, void *closure); typedef struct JSDebugHooks { - JSInterruptHook interruptHook; - void *interruptHookData; - JSNewScriptHook newScriptHook; - void *newScriptHookData; - JSDestroyScriptHook destroyScriptHook; - void *destroyScriptHookData; JSDebuggerHandler debuggerHandler; void *debuggerHandlerData; - JSSourceHandler sourceHandler; - void *sourceHandlerData; - JSInterpreterHook executeHook; - void *executeHookData; - JSInterpreterHook callHook; - void *callHookData; - JSThrowHook throwHook; - void *throwHookData; - JSDebugErrorHook debugErrorHook; - void *debugErrorHookData; } JSDebugHooks; /************************************************************************/ @@ -464,21 +352,6 @@ typedef struct JSDebugHooks { extern JS_PUBLIC_API(bool) JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler hook, void *closure); -extern JS_PUBLIC_API(bool) -JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetThrowHook(JSRuntime *rt, JSThrowHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure); - /************************************************************************/ extern JS_PUBLIC_API(const JSDebugHooks *) @@ -492,16 +365,10 @@ JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj); /* Defined in vm/Debugger.cpp. */ extern JS_PUBLIC_API(bool) -JS_DefineDebuggerObject(JSContext *cx, JSObject *obj); - -extern JS_PUBLIC_API(void) -JS_DumpBytecode(JSContext *cx, JSScript *script); - -extern JS_PUBLIC_API(void) -JS_DumpCompartmentBytecode(JSContext *cx); +JS_DefineDebuggerObject(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(void) -JS_DumpPCCounts(JSContext *cx, JSScript *script); +JS_DumpPCCounts(JSContext *cx, JS::HandleScript script); extern JS_PUBLIC_API(void) JS_DumpCompartmentPCCounts(JSContext *cx); diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/Principals.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/Principals.h new file mode 100644 index 0000000000..78d8c7e893 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/Principals.h @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JSPrincipals and related interfaces. */ + +#ifndef js_Principals_h +#define js_Principals_h + +#include "mozilla/Atomics.h" + +#include + +#include "jspubtd.h" + +struct JSPrincipals { + /* Don't call "destroy"; use reference counting macros below. */ +#ifdef JS_THREADSAFE + mozilla::Atomic refcount; +#else + int32_t refcount; +#endif + +#ifdef JS_DEBUG + /* A helper to facilitate principals debugging. */ + uint32_t debugToken; +#endif + + void setDebugToken(uint32_t token) { +# ifdef JS_DEBUG + debugToken = token; +# endif + } + + /* + * This is not defined by the JS engine but should be provided by the + * embedding. + */ + JS_PUBLIC_API(void) dump(); +}; + +extern JS_PUBLIC_API(void) +JS_HoldPrincipals(JSPrincipals *principals); + +extern JS_PUBLIC_API(void) +JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals); + +// Return whether the first principal subsumes the second. The exact meaning of +// 'subsumes' is left up to the browser. Subsumption is checked inside the JS +// engine when determining, e.g., which stack frames to display in a backtrace. +typedef bool +(* JSSubsumesOp)(JSPrincipals *first, JSPrincipals *second); + +/* + * Used to check if a CSP instance wants to disable eval() and friends. + * See js_CheckCSPPermitsJSAction() in jsobj. + */ +typedef bool +(* JSCSPEvalChecker)(JSContext *cx); + +struct JSSecurityCallbacks { + JSCSPEvalChecker contentSecurityPolicyAllows; + JSSubsumesOp subsumes; +}; + +extern JS_PUBLIC_API(void) +JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks); + +extern JS_PUBLIC_API(const JSSecurityCallbacks *) +JS_GetSecurityCallbacks(JSRuntime *rt); + +/* + * Code running with "trusted" principals will be given a deeper stack + * allocation than ordinary scripts. This allows trusted script to run after + * untrusted script has exhausted the stack. This function sets the + * runtime-wide trusted principal. + * + * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since + * there is no available JSContext. Instead, the caller must ensure that the + * given principals stays valid for as long as 'rt' may point to it. If the + * principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be + * called again, passing nullptr for 'prin'. + */ +extern JS_PUBLIC_API(void) +JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin); + +typedef void +(* JSDestroyPrincipalsOp)(JSPrincipals *principals); + +/* + * Initialize the callback that is called to destroy JSPrincipals instance + * when its reference counter drops to zero. The initialization can be done + * only once per JS runtime. + */ +extern JS_PUBLIC_API(void) +JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals); + +#endif /* js_Principals_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/ProfilingStack.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/ProfilingStack.h index 213e47bb7d..e82ce1c9d8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/ProfilingStack.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/ProfilingStack.h @@ -8,7 +8,8 @@ #define js_ProfilingStack_h #include "mozilla/NullPtr.h" - +#include "mozilla/TypedEnum.h" + #include "jsbytecode.h" #include "jstypes.h" @@ -34,50 +35,120 @@ class ProfileEntry // If the size modification were somehow reordered before the stores, then // if a sample were taken it would be examining bogus information. // - // A ProfileEntry represents both a C++ profile entry and a JS one. Both use - // the string as a description, but JS uses the sp as nullptr to indicate - // that it is a JS entry. The script_ is then only ever examined for a JS - // entry, and the idx is used by both, but with different meanings. - // - const char * volatile string; // Descriptive string of this entry - void * volatile sp; // Relevant stack pointer for the entry - JSScript * volatile script_; // if js(), non-null script which is running - int32_t volatile idx; // if js(), idx of pc, otherwise line number + // A ProfileEntry represents both a C++ profile entry and a JS one. + + // Descriptive string of this entry. + const char * volatile string; + + // Stack pointer for non-JS entries, the script pointer otherwise. + void * volatile spOrScript; + + // Line number for non-JS entries, the bytecode offset otherwise. + int32_t volatile lineOrPc; + + // General purpose storage describing this frame. + uint32_t volatile flags_; public: + // These traits are bit masks. Make sure they're powers of 2. + enum Flags { + // Indicate whether a profile entry represents a CPP frame. If not set, + // a JS frame is assumed by default. You're not allowed to publicly + // change the frame type. Instead, call `setJsFrame` or `setCppFrame`. + IS_CPP_ENTRY = 0x01, + + // Indicate that copying the frame label is not necessary when taking a + // sample of the pseudostack. + FRAME_LABEL_COPY = 0x02, + + // Mask for removing all flags except the category information. + CATEGORY_MASK = ~IS_CPP_ENTRY & ~FRAME_LABEL_COPY + }; + + MOZ_BEGIN_NESTED_ENUM_CLASS(Category, uint32_t) + OTHER = 0x04, + CSS = 0x08, + JS = 0x10, + GC = 0x20, + CC = 0x40, + NETWORK = 0x80, + GRAPHICS = 0x100, + STORAGE = 0x200, + EVENTS = 0x400, + + FIRST = OTHER, + LAST = EVENTS + MOZ_END_NESTED_ENUM_CLASS(Category) + // All of these methods are marked with the 'volatile' keyword because SPS's // representation of the stack is stored such that all ProfileEntry // instances are volatile. These methods would not be available unless they // were marked as volatile as well. - bool js() const volatile { - JS_ASSERT_IF(sp == nullptr, script_ != nullptr); - return sp == nullptr; - } + bool isCpp() const volatile { return hasFlag(IS_CPP_ENTRY); } + bool isJs() const volatile { return !isCpp(); } - uint32_t line() const volatile { JS_ASSERT(!js()); return idx; } - JSScript *script() const volatile { JS_ASSERT(js()); return script_; } - void *stackAddress() const volatile { return sp; } - const char *label() const volatile { return string; } + bool isCopyLabel() const volatile { return hasFlag(FRAME_LABEL_COPY); }; - void setLine(uint32_t aLine) volatile { JS_ASSERT(!js()); idx = aLine; } void setLabel(const char *aString) volatile { string = aString; } - void setStackAddress(void *aSp) volatile { sp = aSp; } - void setScript(JSScript *aScript) volatile { script_ = aScript; } + const char *label() const volatile { return string; } + + void setJsFrame(JSScript *aScript, jsbytecode *aPc) volatile { + flags_ = 0; + spOrScript = aScript; + setPC(aPc); + } + void setCppFrame(void *aSp, uint32_t aLine) volatile { + flags_ = IS_CPP_ENTRY; + spOrScript = aSp; + lineOrPc = static_cast(aLine); + } + + void setFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ |= flag; + } + void unsetFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ &= ~flag; + } + bool hasFlag(uint32_t flag) const volatile { + return bool(flags_ & flag); + } + + uint32_t flags() const volatile { + return flags_; + } + uint32_t category() const volatile { + return flags_ & CATEGORY_MASK; + } + + void *stackAddress() const volatile { + MOZ_ASSERT(!isJs()); + return spOrScript; + } + JSScript *script() const volatile { + MOZ_ASSERT(isJs()); + return (JSScript *)spOrScript; + } + uint32_t line() const volatile { + MOZ_ASSERT(!isJs()); + return static_cast(lineOrPc); + } // We can't know the layout of JSScript, so look in vm/SPSProfiler.cpp. JS_FRIEND_API(jsbytecode *) pc() const volatile; JS_FRIEND_API(void) setPC(jsbytecode *pc) volatile; - static size_t offsetOfString() { return offsetof(ProfileEntry, string); } - static size_t offsetOfStackAddress() { return offsetof(ProfileEntry, sp); } - static size_t offsetOfPCIdx() { return offsetof(ProfileEntry, idx); } - static size_t offsetOfScript() { return offsetof(ProfileEntry, script_); } + // The offset of a pc into a script's code can actually be 0, so to + // signify a nullptr pc, use a -1 index. This is checked against in + // pc() and setPC() to set/get the right pc. + static const int32_t NullPCOffset = -1; - // The index used in the entry can either be a line number or the offset of - // a pc into a script's code. To signify a nullptr pc, use a -1 index. This - // is checked against in pc() and setPC() to set/get the right pc. - static const int32_t NullPCIndex = -1; + static size_t offsetOfLabel() { return offsetof(ProfileEntry, string); } + static size_t offsetOfSpOrScript() { return offsetof(ProfileEntry, spOrScript); } + static size_t offsetOfLineOrPc() { return offsetof(ProfileEntry, lineOrPc); } + static size_t offsetOfFlags() { return offsetof(ProfileEntry, flags_); } }; JS_FRIEND_API(void) @@ -87,6 +158,9 @@ SetRuntimeProfilingStack(JSRuntime *rt, ProfileEntry *stack, uint32_t *size, JS_FRIEND_API(void) EnableRuntimeProfilingStack(JSRuntime *rt, bool enabled); +JS_FRIEND_API(void) +RegisterRuntimeProfilingEventMarker(JSRuntime *rt, void (*fn)(const char *)); + JS_FRIEND_API(jsbytecode*) ProfilingGetPC(JSRuntime *rt, JSScript *script, void *ip); diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/RequiredDefines.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/RequiredDefines.h index 3c8f429132..308fd7d625 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/RequiredDefines.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/RequiredDefines.h @@ -28,4 +28,7 @@ #define __STDC_CONSTANT_MACROS #define __STDC_FORMAT_MACROS +/* Also define a char16_t type if not provided by the compiler. */ +#include "mozilla/Char16.h" + #endif /* js_RequiredDefines_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/RootingAPI.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/RootingAPI.h index 5b612660cd..621a1e4394 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/RootingAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/RootingAPI.h @@ -15,6 +15,8 @@ #include "jspubtd.h" +#include "js/GCAPI.h" +#include "js/HeapAPI.h" #include "js/TypeDecls.h" #include "js/Utility.h" @@ -138,6 +140,8 @@ struct NullPtr namespace gc { struct Cell; +template +struct PersistentRootedMarker; } /* namespace gc */ } /* namespace js */ @@ -150,11 +154,6 @@ template class PersistentRooted; /* This is exposing internal state of the GC for inlining purposes. */ JS_FRIEND_API(bool) isGCEnabled(); -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) -extern void -CheckStackRoots(JSContext *cx); -#endif - /* * JS::NullPtr acts like a nullptr pointer in contexts that require a Handle. * @@ -198,6 +197,13 @@ class Heap : public js::HeapBase init(js::GCMethods::initial()); } explicit Heap(T p) { init(p); } + + /* + * For Heap, move semantics are equivalent to copy semantics. In C++, a + * copy constructor taking const-ref is the way to get a single function + * that will be used for both lvalue and rvalue copies, so we can simply + * omit the rvalue variant. + */ explicit Heap(const Heap &p) { init(p.ptr); } ~Heap() { @@ -229,7 +235,7 @@ class Heap : public js::HeapBase } void set(T newPtr) { - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); if (js::GCMethods::needsPostBarrier(newPtr)) { ptr = newPtr; post(); @@ -241,9 +247,21 @@ class Heap : public js::HeapBase } } + /* + * Set the pointer to a value which will cause a crash if it is + * dereferenced. + */ + void setToCrashOnTouch() { + ptr = reinterpret_cast(crashOnTouchPointer); + } + + bool isSetToCrashOnTouch() { + return ptr == crashOnTouchPointer; + } + private: void init(T newPtr) { - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); ptr = newPtr; if (js::GCMethods::needsPostBarrier(ptr)) post(); @@ -251,7 +269,7 @@ class Heap : public js::HeapBase void post() { #ifdef JSGC_GENERATIONAL - JS_ASSERT(js::GCMethods::needsPostBarrier(ptr)); + MOZ_ASSERT(js::GCMethods::needsPostBarrier(ptr)); js::GCMethods::postBarrier(&ptr); #endif } @@ -262,10 +280,14 @@ class Heap : public js::HeapBase #endif } + enum { + crashOnTouchPointer = 1 + }; + T ptr; }; -#ifdef DEBUG +#ifdef JS_DEBUG /* * For generational GC, assert that an object is in the tenured generation as * opposed to being in the nursery. @@ -315,31 +337,31 @@ class TenuredHeap : public js::HeapBase "TenuredHeap must be binary compatible with T."); } explicit TenuredHeap(T p) : bits(0) { setPtr(p); } - explicit TenuredHeap(const TenuredHeap &p) : bits(0) { setPtr(p.ptr); } + explicit TenuredHeap(const TenuredHeap &p) : bits(0) { setPtr(p.getPtr()); } bool operator==(const TenuredHeap &other) { return bits == other.bits; } bool operator!=(const TenuredHeap &other) { return bits != other.bits; } void setPtr(T newPtr) { - JS_ASSERT((reinterpret_cast(newPtr) & flagsMask) == 0); - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT((reinterpret_cast(newPtr) & flagsMask) == 0); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); if (newPtr) AssertGCThingMustBeTenured(newPtr); bits = (bits & flagsMask) | reinterpret_cast(newPtr); } void setFlags(uintptr_t flagsToSet) { - JS_ASSERT((flagsToSet & ~flagsMask) == 0); + MOZ_ASSERT((flagsToSet & ~flagsMask) == 0); bits |= flagsToSet; } void unsetFlags(uintptr_t flagsToUnset) { - JS_ASSERT((flagsToUnset & ~flagsMask) == 0); + MOZ_ASSERT((flagsToUnset & ~flagsMask) == 0); bits &= ~flagsToUnset; } bool hasFlag(uintptr_t flag) const { - JS_ASSERT((flag & ~flagsMask) == 0); + MOZ_ASSERT((flag & ~flagsMask) == 0); return (bits & flag) != 0; } @@ -359,23 +381,10 @@ class TenuredHeap : public js::HeapBase return *this; } - /* - * Set the pointer to a value which will cause a crash if it is - * dereferenced. - */ - void setToCrashOnTouch() { - bits = (bits & flagsMask) | crashOnTouchPointer; - } - - bool isSetToCrashOnTouch() { - return (bits & ~flagsMask) == crashOnTouchPointer; - } - private: enum { maskBits = 3, flagsMask = (1 << maskBits) - 1, - crashOnTouchPointer = 1 << maskBits }; uintptr_t bits; @@ -406,20 +415,20 @@ class MOZ_NONHEAP_CLASS Handle : public js::HandleBase } /* Create a handle for a nullptr pointer. */ - Handle(js::NullPtr) { + MOZ_IMPLICIT Handle(js::NullPtr) { static_assert(mozilla::IsPointer::value, "js::NullPtr overload not valid for non-pointer types"); ptr = reinterpret_cast(&js::NullPtr::constNullValue); } /* Create a handle for a nullptr pointer. */ - Handle(JS::NullPtr) { + MOZ_IMPLICIT Handle(JS::NullPtr) { static_assert(mozilla::IsPointer::value, "JS::NullPtr overload not valid for non-pointer types"); ptr = reinterpret_cast(&JS::NullPtr::constNullValue); } - Handle(MutableHandle handle) { + MOZ_IMPLICIT Handle(MutableHandle handle) { ptr = handle.address(); } @@ -476,9 +485,6 @@ class MOZ_NONHEAP_CLASS Handle : public js::HandleBase bool operator!=(const T &other) const { return *ptr != other; } bool operator==(const T &other) const { return *ptr == other; } - /* Change this handle to point to the same rooted location RHS does. */ - void repoint(const Handle &rhs) { ptr = rhs.address(); } - private: Handle() {} @@ -504,15 +510,23 @@ template class MOZ_STACK_CLASS MutableHandle : public js::MutableHandleBase { public: - inline MutableHandle(Rooted *root); - inline MutableHandle(PersistentRooted *root); - MutableHandle(int) MOZ_DELETE; -#ifdef MOZ_HAVE_CXX11_NULLPTR - MutableHandle(decltype(nullptr)) MOZ_DELETE; -#endif + inline MOZ_IMPLICIT MutableHandle(Rooted *root); + inline MOZ_IMPLICIT MutableHandle(PersistentRooted *root); + + private: + // Disallow true nullptr and emulated nullptr (gcc 4.4/4.5, __null, appears + // as int/long [32/64-bit]) for overloading purposes. + template + MutableHandle(N, + typename mozilla::EnableIf::value || + mozilla::IsSame::value || + mozilla::IsSame::value, + int>::Type dummy = 0) + MOZ_DELETE; + public: void set(T v) { - JS_ASSERT(!js::GCMethods::poisoned(v)); + MOZ_ASSERT(!js::GCMethods::poisoned(v)); *ptr = v; } @@ -549,8 +563,8 @@ class MOZ_STACK_CLASS MutableHandle : public js::MutableHandleBase }; #ifdef JSGC_GENERATIONAL -JS_PUBLIC_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); -JS_PUBLIC_API(void) HeapCellRelocate(js::gc::Cell **cellp); +JS_FRIEND_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); +JS_FRIEND_API(void) HeapCellRelocate(js::gc::Cell **cellp); #endif } /* namespace JS */ @@ -612,7 +626,7 @@ class InternalHandle * Make this private to prevent accidental misuse; this is only for * fromMarkedLocation(). */ - InternalHandle(T *field) + explicit InternalHandle(T *field) : holder(reinterpret_cast(&js::NullPtr::constNullValue)), offset(uintptr_t(field)) {} @@ -621,10 +635,16 @@ class InternalHandle }; /* - * By default, pointers should use the inheritance hierarchy to find their + * By default, things should use the inheritance hierarchy to find their * ThingRootKind. Some pointer types are explicitly set in jspubtd.h so that * Rooted may be used without the class definition being available. */ +template +struct RootKind +{ + static ThingRootKind rootKind() { return T::rootKind(); } +}; + template struct RootKind { @@ -635,20 +655,51 @@ template struct GCMethods { static T *initial() { return nullptr; } - static ThingRootKind kind() { return RootKind::rootKind(); } static bool poisoned(T *v) { return JS::IsPoisonedPtr(v); } - static bool needsPostBarrier(T *v) { return v; } + static bool needsPostBarrier(T *v) { return false; } #ifdef JSGC_GENERATIONAL - static void postBarrier(T **vp) { + static void postBarrier(T **vp) {} + static void relocate(T **vp) {} +#endif +}; + +template <> +struct GCMethods +{ + static JSObject *initial() { return nullptr; } + static bool poisoned(JSObject *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSObject *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSObject **vp) { JS::HeapCellPostBarrier(reinterpret_cast(vp)); } - static void relocate(T **vp) { + static void relocate(JSObject **vp) { JS::HeapCellRelocate(reinterpret_cast(vp)); } #endif }; -#if defined(DEBUG) +template <> +struct GCMethods +{ + static JSFunction *initial() { return nullptr; } + static bool poisoned(JSFunction *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSFunction *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSFunction **vp) { + JS::HeapCellPostBarrier(reinterpret_cast(vp)); + } + static void relocate(JSFunction **vp) { + JS::HeapCellRelocate(reinterpret_cast(vp)); + } +#endif +}; + +#ifdef JS_DEBUG /* This helper allows us to assert that Rooted is scoped within a request. */ extern JS_PUBLIC_API(bool) IsInRequest(JSContext *cx); @@ -673,22 +724,24 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase template void init(CX *cx) { #ifdef JSGC_TRACK_EXACT_ROOTS - js::ThingRootKind kind = js::GCMethods::kind(); + js::ThingRootKind kind = js::RootKind::rootKind(); this->stack = &cx->thingGCRooters[kind]; this->prev = *stack; *stack = reinterpret_cast*>(this); - JS_ASSERT(!js::GCMethods::poisoned(ptr)); + MOZ_ASSERT(!js::GCMethods::poisoned(ptr)); #endif } public: - Rooted(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG MOZ_ASSERT(js::IsInRequest(cx)); +#endif init(js::ContextFriendFields::get(cx)); } @@ -697,12 +750,14 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase : ptr(initial) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG MOZ_ASSERT(js::IsInRequest(cx)); +#endif init(js::ContextFriendFields::get(cx)); } - Rooted(js::ContextFriendFields *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(js::ContextFriendFields *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -717,8 +772,8 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase init(cx); } - Rooted(js::PerThreadDataFriendFields *pt - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(js::PerThreadDataFriendFields *pt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -733,8 +788,8 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase init(pt); } - Rooted(JSRuntime *rt - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(JSRuntime *rt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -754,13 +809,13 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase // using MSVC, see bug 915735 for more details. #ifdef JSGC_TRACK_EXACT_ROOTS ~Rooted() { - JS_ASSERT(*stack == reinterpret_cast*>(this)); + MOZ_ASSERT(*stack == reinterpret_cast*>(this)); *stack = prev; } #endif #ifdef JSGC_TRACK_EXACT_ROOTS - Rooted *previous() { return prev; } + Rooted *previous() { return reinterpret_cast*>(prev); } #endif /* @@ -775,7 +830,7 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase const T &get() const { return ptr; } T &operator=(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; return ptr; } @@ -786,7 +841,7 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase } void set(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; } @@ -795,16 +850,12 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase private: #ifdef JSGC_TRACK_EXACT_ROOTS - Rooted **stack, *prev; -#endif - -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* Has the rooting analysis ever scanned this Rooted's stack location? */ - friend void JS::CheckStackRoots(JSContext*); -#endif - -#ifdef JSGC_ROOT_ANALYSIS - bool scanned; + /* + * These need to be templated on void* to avoid aliasing issues between, for + * example, Rooted and Rooted, which use the same + * stack head pointer for different classes. + */ + Rooted **stack, *prev; #endif /* @@ -818,90 +869,26 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase Rooted(const Rooted &) MOZ_DELETE; }; -#if !(defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)) -// Defined in vm/String.h. -template <> -class Rooted; -#endif - } /* namespace JS */ namespace js { /* - * Mark a stack location as a root for the rooting analysis, without actually - * rooting it in release builds. This should only be used for stack locations - * of GC things that cannot be relocated by a garbage collection, and that - * are definitely reachable via another path. + * Augment the generic Rooted interface when T = JSObject* with + * class-querying and downcasting operations. + * + * Given a Rooted obj, one can view + * Handle h = obj.as(); + * as an optimization of + * Rooted rooted(cx, &obj->as()); + * Handle h = rooted; */ -class SkipRoot +template <> +class RootedBase { -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - - SkipRoot **stack, *prev; - const uint8_t *start; - const uint8_t *end; - - template - void init(CX *cx, const T *ptr, size_t count) { - SkipRoot **head = &cx->skipGCRooters; - this->stack = head; - this->prev = *stack; - *stack = this; - this->start = (const uint8_t *) ptr; - this->end = this->start + (sizeof(T) * count); - } - public: - ~SkipRoot() { - JS_ASSERT(*stack == this); - *stack = prev; - } - - SkipRoot *previous() { return prev; } - - bool contains(const uint8_t *v, size_t len) { - return v >= start && v + len <= end; - } - -#else /* DEBUG && JSGC_ROOT_ANALYSIS */ - - template - void init(js::ContextFriendFields *cx, const T *ptr, size_t count) {} - - public: - ~SkipRoot() { - // An empty destructor is needed to avoid warnings from clang about - // unused local variables of this type. - } - -#endif /* DEBUG && JSGC_ROOT_ANALYSIS */ - - template - SkipRoot(JSContext *cx, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(ContextFriendFields::get(cx), ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - template - SkipRoot(ContextFriendFields *cx, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(cx, ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - template - SkipRoot(PerThreadData *pt, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(PerThreadDataFriendFields::get(pt), ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + template + JS::Handle as() const; }; /* Interface substitute for Rooted which does not root the variable's memory. */ @@ -933,13 +920,13 @@ class FakeRooted : public RootedBase const T &get() const { return ptr; } FakeRooted &operator=(T value) { - JS_ASSERT(!GCMethods::poisoned(value)); + MOZ_ASSERT(!GCMethods::poisoned(value)); ptr = value; return *this; } FakeRooted &operator=(const FakeRooted &other) { - JS_ASSERT(!GCMethods::poisoned(other.ptr)); + MOZ_ASSERT(!GCMethods::poisoned(other.ptr)); ptr = other.ptr; return *this; } @@ -960,16 +947,16 @@ template class FakeMutableHandle : public js::MutableHandleBase { public: - FakeMutableHandle(T *t) { + MOZ_IMPLICIT FakeMutableHandle(T *t) { ptr = t; } - FakeMutableHandle(FakeRooted *root) { + MOZ_IMPLICIT FakeMutableHandle(FakeRooted *root) { ptr = root->address(); } void set(T v) { - JS_ASSERT(!js::GCMethods::poisoned(v)); + MOZ_ASSERT(!js::GCMethods::poisoned(v)); *ptr = v; } @@ -992,7 +979,7 @@ class FakeMutableHandle : public js::MutableHandleBase /* * Types for a variable that either should or shouldn't be rooted, depending on - * the template parameter Rooted. Used for implementing functions that can + * the template parameter allowGC. Used for implementing functions that can * operate on either rooted or unrooted data. * * The toHandle() and toMutableHandle() functions are for calling functions @@ -1031,12 +1018,12 @@ template class MaybeRooted typedef FakeRooted RootType; typedef FakeMutableHandle MutableHandleType; - static inline JS::Handle toHandle(HandleType v) { - MOZ_ASSUME_UNREACHABLE("Bad conversion"); + static JS::Handle toHandle(HandleType v) { + MOZ_CRASH("Bad conversion"); } - static inline JS::MutableHandle toMutableHandle(MutableHandleType v) { - MOZ_ASSUME_UNREACHABLE("Bad conversion"); + static JS::MutableHandle toMutableHandle(MutableHandleType v) { + MOZ_CRASH("Bad conversion"); } }; @@ -1086,7 +1073,6 @@ MutableHandle::MutableHandle(PersistentRooted *root) ptr = root->address(); } - /* * A copyable, assignable global GC root type with arbitrary lifetime, an * infallible constructor, and automatic unrooting on destruction. @@ -1120,9 +1106,11 @@ MutableHandle::MutableHandle(PersistentRooted *root) * marked when the object itself is marked. */ template -class PersistentRooted : public mozilla::LinkedListElement > { - typedef mozilla::LinkedList List; - typedef mozilla::LinkedListElement Element; +class PersistentRooted : private mozilla::LinkedListElement > { + friend class mozilla::LinkedList; + friend class mozilla::LinkedListElement; + + friend struct js::gc::PersistentRootedMarker; void registerWithRuntime(JSRuntime *rt) { JS::shadow::Runtime *srt = JS::shadow::Runtime::asShadowRuntime(rt); @@ -1130,7 +1118,7 @@ class PersistentRooted : public mozilla::LinkedListElement > } public: - PersistentRooted(JSContext *cx) : ptr(js::GCMethods::initial()) + explicit PersistentRooted(JSContext *cx) : ptr(js::GCMethods::initial()) { registerWithRuntime(js::GetRuntime(cx)); } @@ -1140,7 +1128,7 @@ class PersistentRooted : public mozilla::LinkedListElement > registerWithRuntime(js::GetRuntime(cx)); } - PersistentRooted(JSRuntime *rt) : ptr(js::GCMethods::initial()) + explicit PersistentRooted(JSRuntime *rt) : ptr(js::GCMethods::initial()) { registerWithRuntime(rt); } @@ -1150,14 +1138,19 @@ class PersistentRooted : public mozilla::LinkedListElement > registerWithRuntime(rt); } - PersistentRooted(PersistentRooted &rhs) : ptr(rhs.ptr) + PersistentRooted(const PersistentRooted &rhs) + : mozilla::LinkedListElement >(), + ptr(rhs.ptr) { /* * Copy construction takes advantage of the fact that the original * is already inserted, and simply adds itself to whatever list the * original was on - no JSRuntime pointer needed. + * + * This requires mutating rhs's links, but those should be 'mutable' + * anyway. C++ doesn't let us declare mutable base classes. */ - rhs.setNext(this); + const_cast(rhs).setNext(this); } /* @@ -1172,7 +1165,7 @@ class PersistentRooted : public mozilla::LinkedListElement > const T &get() const { return ptr; } T &operator=(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; return ptr; } @@ -1183,7 +1176,7 @@ class PersistentRooted : public mozilla::LinkedListElement > } void set(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; } @@ -1194,26 +1187,56 @@ class PersistentRooted : public mozilla::LinkedListElement > T ptr; }; +class JS_PUBLIC_API(ObjectPtr) +{ + Heap value; + + public: + ObjectPtr() : value(nullptr) {} + + explicit ObjectPtr(JSObject *obj) : value(obj) {} + + /* Always call finalize before the destructor. */ + ~ObjectPtr() { MOZ_ASSERT(!value); } + + void finalize(JSRuntime *rt) { + if (IsIncrementalBarrierNeeded(rt)) + IncrementalObjectBarrier(value); + value = nullptr; + } + + void init(JSObject *obj) { value = obj; } + + JSObject *get() const { return value; } + + void writeBarrierPre(JSRuntime *rt) { + IncrementalObjectBarrier(value); + } + + bool isAboutToBeFinalized(); + + ObjectPtr &operator=(JSObject *obj) { + IncrementalObjectBarrier(value); + value = obj; + return *this; + } + + void trace(JSTracer *trc, const char *name); + + JSObject &operator*() const { return *value; } + JSObject *operator->() const { return value; } + operator JSObject *() const { return value; } +}; + } /* namespace JS */ namespace js { -/* - * Hook for dynamic root analysis. Checks the native stack and poisons - * references to GC things which have not been rooted. - */ -inline void MaybeCheckStackRoots(JSContext *cx) -{ -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - JS::CheckStackRoots(cx); -#endif -} - /* Base class for automatic read-only object rooting during compilation. */ class CompilerRootNode { protected: - CompilerRootNode(js::gc::Cell *ptr) : next(nullptr), ptr_(ptr) {} + explicit CompilerRootNode(js::gc::Cell *ptr) : next(nullptr), ptr_(ptr) {} public: void **address() { return (void **)&ptr_; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/SliceBudget.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/SliceBudget.h index ccade643b3..7c602c5572 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/SliceBudget.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/SliceBudget.h @@ -32,11 +32,11 @@ struct JS_PUBLIC_API(SliceBudget) SliceBudget(); /* Instantiate as SliceBudget(Time/WorkBudget(n)). */ - SliceBudget(int64_t budget); + explicit SliceBudget(int64_t budget); void reset() { - deadline = INT64_MAX; - counter = INTPTR_MAX; + deadline = unlimitedDeadline; + counter = unlimitedStartCounter; } void step(intptr_t amt = 1) { @@ -50,6 +50,15 @@ struct JS_PUBLIC_API(SliceBudget) return false; return checkOverBudget(); } + + bool isUnlimited() { + return deadline == unlimitedDeadline; + } + +private: + static const int64_t unlimitedDeadline = INT64_MAX; + static const intptr_t unlimitedStartCounter = INTPTR_MAX; + }; } // namespace js diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/StructuredClone.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/StructuredClone.h index d32bdd8dd6..fa48ce045a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/StructuredClone.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/StructuredClone.h @@ -23,6 +23,35 @@ struct JSStructuredCloneWriter; // API for the HTML5 internal structured cloning algorithm. +namespace JS { +enum TransferableOwnership { + // Transferable data has not been filled in yet + SCTAG_TMO_UNFILLED = 0, + + // Structured clone buffer does not yet own the data + SCTAG_TMO_UNOWNED = 1, + + // All values at least this large are owned by the clone buffer + SCTAG_TMO_FIRST_OWNED = 2, + + // Data is a pointer that can be freed + SCTAG_TMO_ALLOC_DATA = 2, + + // Data is a SharedArrayBufferObject's buffer + SCTAG_TMO_SHARED_BUFFER = 3, + + // Data is a memory mapped pointer + SCTAG_TMO_MAPPED_DATA = 4, + + // Data is embedding-specific. The engine can free it by calling the + // freeTransfer op. The embedding can also use SCTAG_TMO_USER_MIN and + // greater, up to 32 bits, to distinguish specific ownership variants. + SCTAG_TMO_CUSTOM = 5, + + SCTAG_TMO_USER_MIN +}; +} /* namespace JS */ + // Read structured data from the reader r. This hook is used to read a value // previously serialized by a call to the WriteStructuredCloneOp hook. // @@ -43,22 +72,64 @@ typedef JSObject *(*ReadStructuredCloneOp)(JSContext *cx, JSStructuredCloneReade // // Return true on success, false on error/exception. typedef bool (*WriteStructuredCloneOp)(JSContext *cx, JSStructuredCloneWriter *w, - JS::Handle obj, void *closure); + JS::HandleObject obj, void *closure); // This is called when JS_WriteStructuredClone is given an invalid transferable. // To follow HTML5, the application must throw a DATA_CLONE_ERR DOMException // with error set to one of the JS_SCERR_* values. typedef void (*StructuredCloneErrorOp)(JSContext *cx, uint32_t errorid); +// This is called when JS_ReadStructuredClone receives a transferable object +// not known to the engine. If this hook does not exist or returns false, the +// JS engine calls the reportError op if set, otherwise it throws a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback and must return a non-null object in returnObject on success. +typedef bool (*ReadTransferStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r, + uint32_t tag, void *content, uint64_t extraData, + void *closure, + JS::MutableHandleObject returnObject); + +// Called when JS_WriteStructuredClone receives a transferable object not +// handled by the engine. If this hook does not exist or returns false, the JS +// engine will call the reportError hook or fall back to throwing a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback. +// +// tag: indicates what type of transferable this is. Must be greater than +// 0xFFFF0201 (value of the internal SCTAG_TRANSFER_MAP_PENDING_ENTRY) +// +// ownership: see TransferableOwnership, above. Used to communicate any needed +// ownership info to the FreeTransferStructuredCloneOp. +// +// content, extraData: what the ReadTransferStructuredCloneOp will receive +// +typedef bool (*TransferStructuredCloneOp)(JSContext *cx, + JS::Handle obj, + void *closure, + // Output: + uint32_t *tag, + JS::TransferableOwnership *ownership, + void **content, + uint64_t *extraData); + +// Called when JS_ClearStructuredClone has to free an unknown transferable +// object. Note that it should never trigger a garbage collection (and will +// assert in a debug build if it does.) +typedef void (*FreeTransferStructuredCloneOp)(uint32_t tag, JS::TransferableOwnership ownership, + void *content, uint64_t extraData, void *closure); + // The maximum supported structured-clone serialization format version. Note // that this does not need to be bumped for Transferable-only changes, since // they are never saved to persistent storage. -#define JS_STRUCTURED_CLONE_VERSION 2 +#define JS_STRUCTURED_CLONE_VERSION 4 struct JSStructuredCloneCallbacks { ReadStructuredCloneOp read; WriteStructuredCloneOp write; StructuredCloneErrorOp reportError; + ReadTransferStructuredCloneOp readTransfer; + TransferStructuredCloneOp writeTransfer; + FreeTransferStructuredCloneOp freeTransfer; }; // Note: if the *data contains transferable objects, it can be read only once. @@ -68,14 +139,16 @@ JS_ReadStructuredClone(JSContext *cx, uint64_t *data, size_t nbytes, uint32_t ve const JSStructuredCloneCallbacks *optionalCallbacks, void *closure); // Note: On success, the caller is responsible for calling -// JS_ClearStructuredClone(*datap, nbytesp). +// JS_ClearStructuredClone(*datap, nbytes, optionalCallbacks, closure). JS_PUBLIC_API(bool) JS_WriteStructuredClone(JSContext *cx, JS::HandleValue v, uint64_t **datap, size_t *nbytesp, const JSStructuredCloneCallbacks *optionalCallbacks, void *closure, JS::HandleValue transferable); JS_PUBLIC_API(bool) -JS_ClearStructuredClone(const uint64_t *data, size_t nbytes); +JS_ClearStructuredClone(uint64_t *data, size_t nbytes, + const JSStructuredCloneCallbacks *optionalCallbacks, + void *closure); JS_PUBLIC_API(bool) JS_StructuredCloneHasTransferables(const uint64_t *data, size_t nbytes, bool *hasTransferable); @@ -89,10 +162,22 @@ class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) { uint64_t *data_; size_t nbytes_; uint32_t version_; + const JSStructuredCloneCallbacks *callbacks_; + void *closure_; public: JSAutoStructuredCloneBuffer() - : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION) {} + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(nullptr), closure_(nullptr) + {} + + JSAutoStructuredCloneBuffer(const JSStructuredCloneCallbacks *callbacks, void *closure) + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(callbacks), closure_(closure) + {} + + JSAutoStructuredCloneBuffer(JSAutoStructuredCloneBuffer &&other); + JSAutoStructuredCloneBuffer &operator=(JSAutoStructuredCloneBuffer &&other); ~JSAutoStructuredCloneBuffer() { clear(); } @@ -123,13 +208,10 @@ class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) { bool write(JSContext *cx, JS::HandleValue v, JS::HandleValue transferable, const JSStructuredCloneCallbacks *optionalCallbacks=nullptr, void *closure=nullptr); - // Swap ownership with another JSAutoStructuredCloneBuffer. - void swap(JSAutoStructuredCloneBuffer &other); - private: // Copy and assignment are not supported. - JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other); - JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other); + JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; + JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; }; // The range of tag values the application may use for its own custom object types. @@ -149,7 +231,7 @@ JS_PUBLIC_API(bool) JS_ReadBytes(JSStructuredCloneReader *r, void *p, size_t len); JS_PUBLIC_API(bool) -JS_ReadTypedArray(JSStructuredCloneReader *r, JS::Value *vp); +JS_ReadTypedArray(JSStructuredCloneReader *r, JS::MutableHandleValue vp); JS_PUBLIC_API(bool) JS_WriteUint32Pair(JSStructuredCloneWriter *w, uint32_t tag, uint32_t data); @@ -158,6 +240,6 @@ JS_PUBLIC_API(bool) JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len); JS_PUBLIC_API(bool) -JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::Value v); +JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::HandleValue v); #endif /* js_StructuredClone_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/Tracer.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/TracingAPI.h similarity index 53% rename from frameworks/js-bindings/external/spidermonkey/include/mac/js/Tracer.h rename to frameworks/js-bindings/external/spidermonkey/include/mac/js/TracingAPI.h index 89994612f6..3c7fdbe1b1 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/Tracer.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/TracingAPI.h @@ -4,14 +4,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef js_Tracer_h -#define js_Tracer_h +#ifndef js_TracingAPI_h +#define js_TracingAPI_h #include "mozilla/NullPtr.h" - + #include "jspubtd.h" -struct JSTracer; +class JS_PUBLIC_API(JSTracer); namespace JS { template class Heap; @@ -46,74 +46,101 @@ enum WeakMapTraceKind { TraceWeakMapKeysValues = 2 }; -struct JSTracer { - JSRuntime *runtime; - JSTraceCallback callback; - JSTraceNamePrinter debugPrinter; - const void *debugPrintArg; - size_t debugPrintIndex; - WeakMapTraceKind eagerlyTraceWeakMaps; -#ifdef JS_GC_ZEAL - void *realLocation; -#endif -}; +class JS_PUBLIC_API(JSTracer) +{ + public: + JSTracer(JSRuntime *rt, JSTraceCallback traceCallback, + WeakMapTraceKind weakTraceKind = TraceWeakMapValues); + + // Set debugging information about a reference to a traceable thing to prepare + // for the following call to JS_CallTracer. + // + // When printer is null, arg must be const char * or char * C string naming + // the reference and index must be either (size_t)-1 indicating that the name + // alone describes the reference or it must be an index into some array vector + // that stores the reference. + // + // When printer callback is not null, the arg and index arguments are + // available to the callback as debugPrintArg_ and debugPrintIndex_ fields + // of JSTracer. + // + // The storage for name or callback's arguments needs to live only until + // the following call to JS_CallTracer returns. + void setTracingDetails(JSTraceNamePrinter printer, const void *arg, size_t index) { + debugPrinter_ = printer; + debugPrintArg_ = arg; + debugPrintIndex_ = index; + } + + void setTracingIndex(const char *name, size_t index) { + setTracingDetails(nullptr, (void *)name, index); + } + + void setTracingName(const char *name) { + setTracingDetails(nullptr, (void *)name, size_t(-1)); + } + + // Remove the currently set tracing details. + void clearTracingDetails() { + debugPrinter_ = nullptr; + debugPrintArg_ = nullptr; + } + + // Return true if tracing details are currently set. + bool hasTracingDetails() const; + + // Get the string set with the most recent call to setTracingName or return + // fallback if a name printer function has been installed. + const char *tracingName(const char *fallback) const; + + // Build a description of this edge in the heap graph. This call may invoke + // the debug printer, which may inspect arbitrary areas of the heap. + const char *getTracingEdgeName(char *buffer, size_t bufferSize); + + // Access the currently active tracing details. + JSTraceNamePrinter debugPrinter() const; + const void *debugPrintArg() const; + size_t debugPrintIndex() const; + + // Return the runtime set on the tracer. + JSRuntime *runtime() const { return runtime_; } + + // Return the weak map tracing behavior set on this tracer. + WeakMapTraceKind eagerlyTraceWeakMaps() const { return eagerlyTraceWeakMaps_; } + + // Update the trace callback. + void setTraceCallback(JSTraceCallback traceCallback); -// Set debugging information about a reference to a traceable thing to prepare -// for the following call to JS_CallTracer. -// -// When printer is null, arg must be const char * or char * C string naming -// the reference and index must be either (size_t)-1 indicating that the name -// alone describes the reference or it must be an index into some array vector -// that stores the reference. -// -// When printer callback is not null, the arg and index arguments are -// available to the callback as debugPrintArg and debugPrintIndex fields -// of JSTracer. -// -// The storage for name or callback's arguments needs to live only until -// the following call to JS_CallTracer returns. -// -# define JS_SET_TRACING_DETAILS(trc, printer, arg, index) \ - JS_BEGIN_MACRO \ - (trc)->debugPrinter = (printer); \ - (trc)->debugPrintArg = (arg); \ - (trc)->debugPrintIndex = (index); \ - JS_END_MACRO - -// Sets the real location for a marked reference, when passing the address -// directly is not feasable. -// -// FIXME: This is currently overcomplicated by our need to nest calls for Values -// stored as keys in hash tables, but will get simplified once we can rekey -// in-place. -// #ifdef JS_GC_ZEAL -# define JS_SET_TRACING_LOCATION(trc, location) \ - JS_BEGIN_MACRO \ - if (!(trc)->realLocation || !(location)) \ - (trc)->realLocation = (location); \ - JS_END_MACRO -# define JS_UNSET_TRACING_LOCATION(trc) \ - JS_BEGIN_MACRO \ - (trc)->realLocation = nullptr; \ - JS_END_MACRO + // Sets the "real" location for a marked reference, when passing the address + // directly is not feasable. This address is used for matching against the + // store buffer when verifying the correctness of the entrees there. + // + // This is currently complicated by our need to nest calls for Values + // stored as keys in hash tables. + void setTracingLocation(void *location); + void unsetTracingLocation(); + void **tracingLocation(void **thingp); #else -# define JS_SET_TRACING_LOCATION(trc, location) \ - JS_BEGIN_MACRO \ - JS_END_MACRO -# define JS_UNSET_TRACING_LOCATION(trc) \ - JS_BEGIN_MACRO \ - JS_END_MACRO + void setTracingLocation(void *location) {} + void unsetTracingLocation() {} + void **tracingLocation(void **thingp) { return nullptr; } #endif -// Convenience macro to describe the argument of JS_CallTracer using C string -// and index. -# define JS_SET_TRACING_INDEX(trc, name, index) \ - JS_SET_TRACING_DETAILS(trc, nullptr, name, index) + // We expose |callback| directly so that IS_GC_MARKING_TRACER can compare + // it to GCMarker::GrayCallback. + JSTraceCallback callback; -// Convenience macro to describe the argument of JS_CallTracer using C string. -# define JS_SET_TRACING_NAME(trc, name) \ - JS_SET_TRACING_DETAILS(trc, nullptr, name, (size_t)-1) + private: + JSRuntime *runtime_; + JSTraceNamePrinter debugPrinter_; + const void *debugPrintArg_; + size_t debugPrintIndex_; + WeakMapTraceKind eagerlyTraceWeakMaps_; +#ifdef JS_GC_ZEAL + void *realLocation_; +#endif +}; // The JS_Call*Tracer family of functions traces the given GC thing reference. // This performs the tracing action configured on the given JSTracer: @@ -157,12 +184,15 @@ JS_CallHeapStringTracer(JSTracer *trc, JS::Heap *strp, const char *n extern JS_PUBLIC_API(void) JS_CallHeapScriptTracer(JSTracer *trc, JS::Heap *scriptp, const char *name); +extern JS_PUBLIC_API(void) +JS_CallHeapFunctionTracer(JSTracer *trc, JS::Heap *funp, const char *name); + template inline void JS_CallHashSetObjectTracer(JSTracer *trc, HashSetEnum &e, JSObject *const &key, const char *name) { JSObject *updated = key; - JS_SET_TRACING_LOCATION(trc, reinterpret_cast(&const_cast(key))); + trc->setTracingLocation(reinterpret_cast(&const_cast(key))); JS_CallObjectTracer(trc, &updated, name); if (updated != key) e.rekeyFront(key, updated); @@ -173,10 +203,6 @@ JS_CallHashSetObjectTracer(JSTracer *trc, HashSetEnum &e, JSObject *const &key, extern JS_PUBLIC_API(void) JS_CallTenuredObjectTracer(JSTracer *trc, JS::TenuredHeap *objp, const char *name); -// API for JSTraceCallback implementations. -extern JS_PUBLIC_API(void) -JS_TracerInit(JSTracer *trc, JSRuntime *rt, JSTraceCallback callback); - extern JS_PUBLIC_API(void) JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind); @@ -187,7 +213,4 @@ extern JS_PUBLIC_API(void) JS_GetTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc, void *thing, JSGCTraceKind kind, bool includeDetails); -extern JS_PUBLIC_API(const char *) -JS_GetTraceEdgeName(JSTracer *trc, char *buffer, int bufferSize); - -#endif /* js_Tracer_h */ +#endif /* js_TracingAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/TypeDecls.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/TypeDecls.h index 027d7b8fb7..3e1e8afc66 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/TypeDecls.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/TypeDecls.h @@ -20,44 +20,24 @@ #include #include +#include "js-config.h" + struct JSContext; class JSFunction; class JSObject; class JSScript; class JSString; +class JSAddonId; -// In release builds, jsid is defined to be an integral type. This -// prevents many bugs from being caught at compile time. E.g.: -// -// jsid id = ... -// if (id) // error -// ... -// -// size_t n = id; // error -// -// To catch more errors, jsid is given a struct type in C++ debug builds. -// Struct assignment and (in C++) operator== allow correct code to be mostly -// oblivious to the change. This feature can be explicitly disabled in debug -// builds by defining JS_NO_JSVAL_JSID_STRUCT_TYPES. -// - -// Needed for cocos2d-js -#define JS_NO_JSVAL_JSID_STRUCT_TYPES - -#if defined(DEBUG) && !defined(JS_NO_JSVAL_JSID_STRUCT_TYPES) -# define JS_USE_JSID_STRUCT_TYPES -#endif - -#ifdef JS_USE_JSID_STRUCT_TYPES struct jsid; -#else -typedef ptrdiff_t jsid; -#endif typedef char16_t jschar; namespace JS { +typedef unsigned char Latin1Char; + +class Symbol; class Value; template class Handle; template class MutableHandle; @@ -69,6 +49,7 @@ typedef Handle HandleId; typedef Handle HandleObject; typedef Handle HandleScript; typedef Handle HandleString; +typedef Handle HandleSymbol; typedef Handle HandleValue; typedef MutableHandle MutableHandleFunction; @@ -76,12 +57,14 @@ typedef MutableHandle MutableHandleId; typedef MutableHandle MutableHandleObject; typedef MutableHandle MutableHandleScript; typedef MutableHandle MutableHandleString; +typedef MutableHandle MutableHandleSymbol; typedef MutableHandle MutableHandleValue; typedef Rooted RootedObject; typedef Rooted RootedFunction; typedef Rooted RootedScript; typedef Rooted RootedString; +typedef Rooted RootedSymbol; typedef Rooted RootedId; typedef Rooted RootedValue; @@ -90,6 +73,7 @@ typedef PersistentRooted PersistentRootedId; typedef PersistentRooted PersistentRootedObject; typedef PersistentRooted PersistentRootedScript; typedef PersistentRooted PersistentRootedString; +typedef PersistentRooted PersistentRootedSymbol; typedef PersistentRooted PersistentRootedValue; } // namespace JS diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/UbiNode.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/UbiNode.h new file mode 100644 index 0000000000..d2acc2e242 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/UbiNode.h @@ -0,0 +1,462 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_UbiNode_h +#define js_UbiNode_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" + +#include "jspubtd.h" + +#include "js/GCAPI.h" +#include "js/HashTable.h" +#include "js/TypeDecls.h" + +// JS::ubi::Node +// +// JS::ubi::Node is a pointer-like type designed for internal use by heap +// analysis tools. A ubi::Node can refer to: +// +// - a JS value, like a string or object; +// - an internal SpiderMonkey structure, like a shape or a scope chain object +// - an instance of some embedding-provided type: in Firefox, an XPCOM +// object, or an internal DOM node class instance +// +// A ubi::Node instance provides metadata about its referent, and can +// enumerate its referent's outgoing edges, so you can implement heap analysis +// algorithms that walk the graph - finding paths between objects, or +// computing heap dominator trees, say - using ubi::Node, while remaining +// ignorant of the details of the types you're operating on. +// +// Of course, when it comes to presenting the results in a developer-facing +// tool, you'll need to stop being ignorant of those details, because you have +// to discuss the ubi::Nodes' referents with the developer. Here, ubi::Node +// can hand you dynamically checked, properly typed pointers to the original +// objects via the as method, or generate descriptions of the referent +// itself. +// +// ubi::Node instances are lightweight (two-word) value types. Instances: +// - compare equal if and only if they refer to the same object; +// - have hash values that respect their equality relation; and +// - have serializations that are only equal if the ubi::Nodes are equal. +// +// A ubi::Node is only valid for as long as its referent is alive; if its +// referent goes away, the ubi::Node becomes a dangling pointer. A ubi::Node +// that refers to a GC-managed object is not automatically a GC root; if the +// GC frees or relocates its referent, the ubi::Node becomes invalid. A +// ubi::Node that refers to a reference-counted object does not bump the +// reference count. +// +// ubi::Node values require no supporting data structures, making them +// feasible for use in memory-constrained devices --- ideally, the memory +// requirements of the algorithm which uses them will be the limiting factor, +// not the demands of ubi::Node itself. +// +// One can construct a ubi::Node value given a pointer to a type that ubi::Node +// supports. In the other direction, one can convert a ubi::Node back to a +// pointer; these downcasts are checked dynamically. In particular, one can +// convert a 'JSRuntime *' to a ubi::Node, yielding a node with an outgoing edge +// for every root registered with the runtime; starting from this, one can walk +// the entire heap. (Of course, one could also start traversal at any other kind +// of type to which one has a pointer.) +// +// +// Extending ubi::Node To Handle Your Embedding's Types +// +// To add support for a new ubi::Node referent type R, you must define a +// specialization of the ubi::Concrete template, ubi::Concrete, which +// inherits from ubi::Base. ubi::Node itself uses the specialization for +// compile-time information (i.e. the checked conversions between R * and +// ubi::Node), and the inheritance for run-time dispatching. +// +// +// ubi::Node Exposes Implementation Details +// +// In many cases, a JavaScript developer's view of their data differs +// substantially from its actual implementation. For example, while the +// ECMAScript specification describes objects as maps from property names to +// sets of attributes (like ECMAScript's [[Value]]), in practice many objects +// have only a pointer to a shape, shared with other similar objects, and +// indexed slots that contain the [[Value]] attributes. As another example, a +// string produced by concatenating two other strings may sometimes be +// represented by a "rope", a structure that points to the two original +// strings. +// + +// We intend to use ubi::Node to write tools that report memory usage, so it's +// important that ubi::Node accurately portray how much memory nodes consume. +// Thus, for example, when data that apparently belongs to multiple nodes is +// in fact shared in a common structure, ubi::Node's graph uses a separate +// node for that shared structure, and presents edges to it from the data's +// apparent owners. For example, ubi::Node exposes SpiderMonkey objects' +// shapes and base shapes, and exposes rope string and substring structure, +// because these optimizations become visible when a tool reports how much +// memory a structure consumes. +// +// However, fine granularity is not a goal. When a particular object is the +// exclusive owner of a separate block of memory, ubi::Node may present the +// object and its block as a single node, and add their sizes together when +// reporting the node's size, as there is no meaningful loss of data in this +// case. Thus, for example, a ubi::Node referring to a JavaScript object, when +// asked for the object's size in bytes, includes the object's slot and +// element arrays' sizes in the total. There is no separate ubi::Node value +// representing the slot and element arrays, since they are owned exclusively +// by the object. +// +// +// Presenting Analysis Results To JavaScript Developers +// +// If an analysis provides its results in terms of ubi::Node values, a user +// interface presenting those results will generally need to clean them up +// before they can be understood by JavaScript developers. For example, +// JavaScript developers should not need to understand shapes, only JavaScript +// objects. Similarly, they should not need to understand the distinction +// between DOM nodes and the JavaScript shadow objects that represent them. +// +// +// Rooting Restrictions +// +// At present there is no way to root ubi::Node instances, so instances can't be +// live across any operation that might GC. Analyses using ubi::Node must either +// run to completion and convert their results to some other rootable type, or +// save their intermediate state in some rooted structure if they must GC before +// they complete. (For algorithms like path-finding and dominator tree +// computation, we implement the algorithm avoiding any operation that could +// cause a GC --- and use AutoCheckCannotGC to verify this.) +// +// If this restriction prevents us from implementing interesting tools, we may +// teach the GC how to root ubi::Nodes, fix up hash tables that use them as +// keys, etc. + + +// Forward declarations of SpiderMonkey's ubi::Node reference types. +namespace js { +class LazyScript; +class Shape; +class BaseShape; +namespace jit { +class JitCode; +} +namespace types { +struct TypeObject; +} +} + + +namespace JS { +namespace ubi { + +class Edge; +class EdgeRange; + +// The base class implemented by each ubi::Node referent type. Subclasses must +// not add data members to this class. +class Base { + friend class Node; + + // For performance's sake, we'd prefer to avoid a virtual destructor; and + // an empty constructor seems consistent with the 'lightweight value type' + // visible behavior we're trying to achieve. But if the destructor isn't + // virtual, and a subclass overrides it, the subclass's destructor will be + // ignored. Is there a way to make the compiler catch that error? + + protected: + // Space for the actual pointer. Concrete subclasses should define a + // properly typed 'get' member function to access this. + void *ptr; + + Base(void *ptr) : ptr(ptr) { } + + public: + bool operator==(const Base &rhs) const { + // Some compilers will indeed place objects of different types at + // the same address, so technically, we should include the vtable + // in this comparison. But it seems unlikely to cause problems in + // practice. + return ptr == rhs.ptr; + } + bool operator!=(const Base &rhs) const { return !(*this == rhs); } + + // Return a human-readable name for the referent's type. The result should + // be statically allocated. (You can use MOZ_UTF16("strings") for this.) + // + // This must always return Concrete::concreteTypeName; we use that + // pointer as a tag for this particular referent type. + virtual const jschar *typeName() const = 0; + + // Return the size of this node, in bytes. Include any structures that this + // node owns exclusively that are not exposed as their own ubi::Nodes. + virtual size_t size() const = 0; + + // Return an EdgeRange that initially contains all the referent's outgoing + // edges. The EdgeRange should be freed with 'js_delete'. (You could use + // ScopedDJSeletePtr to manage it.) On OOM, report an exception + // on |cx| and return nullptr. + virtual EdgeRange *edges(JSContext *cx) const = 0; + + private: + Base(const Base &rhs) MOZ_DELETE; + Base &operator=(const Base &rhs) MOZ_DELETE; +}; + +// A traits template with a specialization for each referent type that +// ubi::Node supports. The specialization must be the concrete subclass of +// Base that represents a pointer to the referent type. It must also +// include the members described here. +template +struct Concrete { + // The specific jschar array returned by Concrete::typeName. + static const jschar concreteTypeName[]; + + // Construct an instance of this concrete class in |storage| referring + // to |referent|. Implementations typically use a placement 'new'. + // + // In some cases, |referent| will contain dynamic type information that + // identifies it a some more specific subclass of |Referent|. For example, + // when |Referent| is |JSObject|, then |referent->getClass()| could tell us + // that it's actually a JSFunction. Similarly, if |Referent| is + // |nsISupports|, we would like a ubi::Node that knows its final + // implementation type. + // + // So, we delegate the actual construction to this specialization, which + // knows Referent's details. + static void construct(void *storage, Referent *referent); +}; + +// A container for a Base instance; all members simply forward to the contained instance. +// This container allows us to pass ubi::Node instances by value. +class Node { + // Storage in which we allocate Base subclasses. + mozilla::AlignedStorage2 storage; + Base *base() { return storage.addr(); } + const Base *base() const { return storage.addr(); } + + template + void construct(T *ptr) { + static_assert(sizeof(Concrete) == sizeof(*base()), + "ubi::Base specializations must be the same size as ubi::Base"); + Concrete::construct(base(), ptr); + } + + typedef void (Node::* ConvertibleToBool)(); + void nonNull() {} + + public: + Node() { construct(nullptr); } + + template + Node(T *ptr) { + construct(ptr); + } + template + Node &operator=(T *ptr) { + construct(ptr); + return *this; + } + + // We can construct and assign from rooted forms of pointers. + template + Node(const Rooted &root) { + construct(root.get()); + } + template + Node &operator=(const Rooted &root) { + construct(root.get()); + return *this; + } + + // Constructors accepting SpiderMonkey's other generic-pointer-ish types. + Node(JS::Value value); + Node(JSGCTraceKind kind, void *ptr); + + // copy construction and copy assignment just use memcpy, since we know + // instances contain nothing but a vtable pointer and a data pointer. + // + // To be completely correct, concrete classes could provide a virtual + // 'construct' member function, which we could invoke on rhs to construct an + // instance in our storage. But this is good enough; there's no need to jump + // through vtables for copying and assignment that are just going to move + // two words around. The compiler knows how to optimize memcpy. + Node(const Node &rhs) { + memcpy(storage.u.mBytes, rhs.storage.u.mBytes, sizeof(storage.u)); + } + + Node &operator=(const Node &rhs) { + memcpy(storage.u.mBytes, rhs.storage.u.mBytes, sizeof(storage.u)); + return *this; + } + + bool operator==(const Node &rhs) const { return *base() == *rhs.base(); } + bool operator!=(const Node &rhs) const { return *base() != *rhs.base(); } + + operator ConvertibleToBool() const { + return base()->ptr ? &Node::nonNull : 0; + } + + template + bool is() const { + return base()->typeName() == Concrete::concreteTypeName; + } + + template + T *as() const { + MOZ_ASSERT(is()); + return static_cast(base()->ptr); + } + + template + T *asOrNull() const { + return is() ? static_cast(base()->ptr) : nullptr; + } + + // If this node refers to something that can be represented as a + // JavaScript value that is safe to expose to JavaScript code, return that + // value. Otherwise return UndefinedValue(). JSStrings and some (but not + // all!) JSObjects can be exposed. + JS::Value exposeToJS() const; + + const jschar *typeName() const { return base()->typeName(); } + size_t size() const { return base()->size(); } + EdgeRange *edges(JSContext *cx) const { return base()->edges(cx); } + + // A hash policy for ubi::Nodes. + // This simply uses the stock PointerHasher on the ubi::Node's pointer. + // We specialize DefaultHasher below to make this the default. + class HashPolicy { + typedef js::PointerHasher::value> PtrHash; + + public: + typedef Node Lookup; + + static js::HashNumber hash(const Lookup &l) { return PtrHash::hash(l.base()->ptr); } + static bool match(const Node &k, const Lookup &l) { return k == l; } + static void rekey(Node &k, const Node &newKey) { k = newKey; } + }; +}; + + +// Edge is the abstract base class representing an outgoing edge of a node. +// Edges are owned by EdgeRanges, and need not have assignment operators or copy +// constructors. +// +// Each Edge class should inherit from this base class, overriding as +// appropriate. +class Edge { + protected: + Edge() : name(nullptr), referent() { } + virtual ~Edge() { } + + public: + // This edge's name. + // + // The storage is owned by this Edge, and will be freed when this Edge is + // destructed. + // + // (In real life we'll want a better representation for names, to avoid + // creating tons of strings when the names follow a pattern; and we'll need + // to think about lifetimes carefully to ensure traversal stays cheap.) + const jschar *name; + + // This edge's referent. + Node referent; + + private: + Edge(const Edge &) MOZ_DELETE; + Edge &operator=(const Edge &) MOZ_DELETE; +}; + + +// EdgeRange is an abstract base class for iterating over a node's outgoing +// edges. (This is modeled after js::HashTable::Range.) +// +// Concrete instances of this class need not be as lightweight as Node itself, +// since they're usually only instantiated while iterating over a particular +// object's edges. For example, a dumb implementation for JS Cells might use +// JS_TraceChildren to to get the outgoing edges, and then store them in an +// array internal to the EdgeRange. +class EdgeRange { + protected: + // The current front edge of this range, or nullptr if this range is empty. + Edge *front_; + + EdgeRange() : front_(nullptr) { } + + public: + virtual ~EdgeRange() { }; + + // True if there are no more edges in this range. + bool empty() const { return !front_; } + + // The front edge of this range. This is owned by the EdgeRange, and is + // only guaranteed to live until the next call to popFront, or until + // the EdgeRange is destructed. + const Edge &front() { return *front_; } + + // Remove the front edge from this range. This should only be called if + // !empty(). + virtual void popFront() = 0; + + private: + EdgeRange(const EdgeRange &) MOZ_DELETE; + EdgeRange &operator=(const EdgeRange &) MOZ_DELETE; +}; + + +// Concrete classes for ubi::Node referent types. + +// A reusable ubi::Concrete specialization base class for types supported by +// JS_TraceChildren. +template +class TracerConcrete : public Base { + const jschar *typeName() const MOZ_OVERRIDE { return concreteTypeName; } + size_t size() const MOZ_OVERRIDE { return 0; } // not implemented yet; bug 1011300 + EdgeRange *edges(JSContext *) const MOZ_OVERRIDE; + + TracerConcrete(Referent *ptr) : Base(ptr) { } + + public: + static const jschar concreteTypeName[]; + static void construct(void *storage, Referent *ptr) { new (storage) TracerConcrete(ptr); }; +}; + +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; + +// The ubi::Node null pointer. Any attempt to operate on a null ubi::Node asserts. +template<> +class Concrete : public Base { + const jschar *typeName() const MOZ_OVERRIDE; + size_t size() const MOZ_OVERRIDE; + EdgeRange *edges(JSContext *cx) const MOZ_OVERRIDE; + + Concrete(void *ptr) : Base(ptr) { } + + public: + static void construct(void *storage, void *ptr) { new (storage) Concrete(ptr); } + static const jschar concreteTypeName[]; +}; + + +} // namespace ubi +} // namespace JS + +namespace js { + +// Make ubi::Node::HashPolicy the default hash policy for ubi::Node. +template<> struct DefaultHasher : JS::ubi::Node::HashPolicy { }; + +} // namespace js + +#endif // js_UbiNode_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/UbiNodeTraverse.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/UbiNodeTraverse.h new file mode 100644 index 0000000000..6072cbc489 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/UbiNodeTraverse.h @@ -0,0 +1,208 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_UbiNodeTraverse_h +#define js_UbiNodeTraverse_h + +#include "js/UbiNode.h" +#include "js/Utility.h" +#include "js/Vector.h" + +namespace JS { +namespace ubi { + +// A breadth-first traversal template for graphs of ubi::Nodes. +// +// No GC may occur while an instance of this template is live. +// +// The provided Handler type should have two members: +// +// typename NodeData; +// +// The value type of |BreadthFirst::visited|, the HashMap of +// ubi::Nodes that have been visited so far. Since the algorithm needs a +// hash table like this for its own use anyway, it is simple to let +// Handler store its own metadata about each node in the same table. +// +// For example, if you want to find a shortest path to each node from any +// traversal starting point, your |NodeData| type could record the first +// edge to reach each node, and the node from which it originates. Then, +// when the traversal is complete, you can walk backwards from any node +// to some starting point, and the path recorded will be a shortest path. +// +// This type must have a default constructor. If this type owns any other +// resources, move constructors and assignment operators are probably a +// good idea, too. +// +// bool operator() (BreadthFirst &traversal, +// Node origin, const Edge &edge, +// Handler::NodeData *referentData, bool first); +// +// The visitor function, called to report that we have traversed +// |edge| from |origin|. This is called once for each edge we traverse. +// As this is a breadth-first search, any prior calls to the visitor function +// were for origin nodes not further from the start nodes than |origin|. +// +// |traversal| is this traversal object, passed along for convenience. +// +// |referentData| is a pointer to the value of the entry in +// |traversal.visited| for |edge.referent|; the visitor function can +// store whatever metadata it likes about |edge.referent| there. +// +// |first| is true if this is the first time we have visited an edge +// leading to |edge.referent|. This could be stored in NodeData, but +// the algorithm knows whether it has just created the entry in +// |traversal.visited|, so it passes it along for convenience. +// +// The visitor function may call |traversal.stop()| if it doesn't want +// to visit any more nodes. +// +// The visitor function may consult |traversal.visited| for information +// about other nodes, but it should not add or remove entries. +// +// The visitor function should return true on success, or false if an +// error occurs. A false return value terminates the traversal +// immediately, and causes BreadthFirst::traverse to return +// false. +template +struct BreadthFirst { + + // Construct a breadth-first traversal object that reports the nodes it + // reaches to |handler|. The traversal object reports OOM on |cx|, and + // asserts that no GC happens in |cx|'s runtime during its lifetime. + // + // We do nothing with noGC, other than require it to exist, with a lifetime + // that encloses our own. + BreadthFirst(JSContext *cx, Handler &handler, const JS::AutoCheckCannotGC &noGC) + : cx(cx), visited(cx), handler(handler), pending(cx), + traversalBegun(false), stopRequested(false) + { } + + // Initialize this traversal object. Return false on OOM. + bool init() { return visited.init(); } + + // Add |node| as a starting point for the traversal. You may add + // as many starting points as you like. Return false on OOM. + bool addStart(Node node) { return pending.append(node); } + + // Traverse the graph in breadth-first order, starting at the given + // start nodes, applying |handler::operator()| for each edge traversed + // as described above. + // + // This should be called only once per instance of this class. + // + // Return false on OOM or error return from |handler::operator()|. + bool traverse() + { + MOZ_ASSERT(!traversalBegun); + traversalBegun = true; + + // While there are pending nodes, visit them, until we've found a path to the target. + while (!pending.empty()) { + Node origin = pending.front(); + pending.popFront(); + + // Get a range containing all origin's outgoing edges. + js::ScopedJSDeletePtr range(origin.edges(cx)); + if (!range) + return false; + + // Traverse each edge. + for (; !range->empty(); range->popFront()) { + MOZ_ASSERT(!stopRequested); + + const Edge &edge = range->front(); + typename NodeMap::AddPtr a = visited.lookupForAdd(edge.referent); + bool first = !a; + + if (first) { + // This is the first time we've reached |edge.referent|. + // Create an entry for it in |visited|, and arrange to + // traverse its outgoing edges later. + if (!visited.add(a, edge.referent, typename Handler::NodeData()) || + !pending.append(edge.referent)) { + return false; + } + } + + MOZ_ASSERT(a); + + // Report this edge to the visitor function. + if (!handler(*this, origin, edge, &a->value(), first)) + return false; + + if (stopRequested) + return true; + } + } + + return true; + } + + // Stop traversal, and return true from |traverse| without visiting any + // more nodes. Only |handler::operator()| should call this function; it + // may do so to stop the traversal early, without returning false and + // then making |traverse|'s caller disambiguate that result from a real + // error. + void stop() { stopRequested = true; } + + // The context with which we were constructed. + JSContext *cx; + + // A map associating each node N that we have reached with a + // Handler::NodeData, for |handler|'s use. This is public, so that + // |handler| can access it to see the traversal thus far. + typedef js::HashMap NodeMap; + NodeMap visited; + + private: + // Our handler object. + Handler &handler; + + // A queue template. Appending and popping the front are constant time. + // Wasted space is never more than some recent actual population plus the + // current population. + template + class Queue { + js::Vector head, tail; + size_t frontIndex; + public: + Queue(JSContext *cx) : head(cx), tail(cx), frontIndex(0) { } + bool empty() { return frontIndex >= head.length(); } + T &front() { + MOZ_ASSERT(!empty()); + return head[frontIndex]; + } + void popFront() { + MOZ_ASSERT(!empty()); + frontIndex++; + if (frontIndex >= head.length()) { + head.clearAndFree(); + head.swap(tail); + frontIndex = 0; + } + } + bool append(const T &elt) { + return frontIndex == 0 ? head.append(elt) : tail.append(elt); + } + }; + + // A queue of nodes that we have reached, but whose outgoing edges we + // have not yet traversed. Nodes reachable in fewer edges are enqueued + // earlier. + Queue pending; + + // True if our traverse function has been called. + bool traversalBegun; + + // True if we've been asked to stop the traversal. + bool stopRequested; +}; + +} // namespace ubi +} // namespace JS + +#endif // js_UbiNodeTraverse.h diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/Utility.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/Utility.h index adee3b15d8..89c495e411 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/Utility.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/Utility.h @@ -35,23 +35,22 @@ namespace mozilla {} namespace js {} /* - * Pattern used to overwrite freed memory. If you are accessing an object with - * this pattern, you probably have a dangling pointer. + * Patterns used by SpiderMonkey to overwrite unused memory. If you are + * accessing an object with one of these pattern, you probably have a dangling + * pointer. */ -#define JS_FREE_PATTERN 0xDA +#define JS_FRESH_NURSERY_PATTERN 0x2F +#define JS_SWEPT_NURSERY_PATTERN 0x2B +#define JS_ALLOCATED_NURSERY_PATTERN 0x2D +#define JS_FRESH_TENURED_PATTERN 0x4F +#define JS_SWEPT_TENURED_PATTERN 0x4B +#define JS_ALLOCATED_TENURED_PATTERN 0x4D +#define JS_SWEPT_CODE_PATTERN 0x3b +#define JS_SWEPT_FRAME_PATTERN 0x5b +#define JS_POISONED_FORKJOIN_CHUNK 0xBD #define JS_ASSERT(expr) MOZ_ASSERT(expr) #define JS_ASSERT_IF(cond, expr) MOZ_ASSERT_IF(cond, expr) -#define JS_ALWAYS_TRUE(expr) MOZ_ALWAYS_TRUE(expr) -#define JS_ALWAYS_FALSE(expr) MOZ_ALWAYS_FALSE(expr) - -#if defined(DEBUG) -# define JS_DIAGNOSTICS_ASSERT(expr) MOZ_ASSERT(expr) -#elif defined(JS_CRASH_DIAGNOSTICS) -# define JS_DIAGNOSTICS_ASSERT(expr) do { if (!(expr)) MOZ_CRASH(); } while(0) -#else -# define JS_DIAGNOSTICS_ASSERT(expr) ((void) 0) -#endif #define JS_STATIC_ASSERT(cond) static_assert(cond, "JS_STATIC_ASSERT") #define JS_STATIC_ASSERT_IF(cond, expr) MOZ_STATIC_ASSERT_IF(cond, expr, "JS_STATIC_ASSERT_IF") @@ -59,84 +58,40 @@ namespace js {} extern MOZ_NORETURN JS_PUBLIC_API(void) JS_Assert(const char *s, const char *file, int ln); -/* - * Abort the process in a non-graceful manner. This will cause a core file, - * call to the debugger or other moral equivalent as well as causing the - * entire process to stop. - */ -extern JS_PUBLIC_API(void) JS_Abort(void); - /* * Custom allocator support for SpiderMonkey */ #if defined JS_USE_CUSTOM_ALLOCATOR # include "jscustomallocator.h" #else -# ifdef DEBUG +# if defined(DEBUG) || defined(JS_OOM_BREAKPOINT) /* * In order to test OOM conditions, when the testing function * oomAfterAllocations COUNT is passed, we fail continuously after the NUM'th * allocation from now. */ -extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtins/TestingFunctions.cpp */ +extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtin/TestingFunctions.cpp */ extern JS_PUBLIC_DATA(uint32_t) OOM_counter; /* data race, who cares. */ -#ifdef JS_OOM_DO_BACKTRACES -#define JS_OOM_BACKTRACE_SIZE 32 -static JS_ALWAYS_INLINE void -PrintBacktrace() -{ - void* OOM_trace[JS_OOM_BACKTRACE_SIZE]; - char** OOM_traceSymbols = nullptr; - int32_t OOM_traceSize = 0; - int32_t OOM_traceIdx = 0; - OOM_traceSize = backtrace(OOM_trace, JS_OOM_BACKTRACE_SIZE); - OOM_traceSymbols = backtrace_symbols(OOM_trace, OOM_traceSize); - - if (!OOM_traceSymbols) - return; - - for (OOM_traceIdx = 0; OOM_traceIdx < OOM_traceSize; ++OOM_traceIdx) { - fprintf(stderr, "#%d %s\n", OOM_traceIdx, OOM_traceSymbols[OOM_traceIdx]); - } - - // This must be free(), not js_free(), because backtrace_symbols() - // allocates with malloc(). - free(OOM_traceSymbols); -} - -#define JS_OOM_EMIT_BACKTRACE() \ - do {\ - fprintf(stderr, "Forcing artificial memory allocation function failure:\n");\ - PrintBacktrace();\ - } while (0) -# else -# define JS_OOM_EMIT_BACKTRACE() do {} while(0) -#endif /* JS_OOM_DO_BACKTRACES */ +#ifdef JS_OOM_BREAKPOINT +static MOZ_NEVER_INLINE void js_failedAllocBreakpoint() { asm(""); } +#define JS_OOM_CALL_BP_FUNC() js_failedAllocBreakpoint() +#else +#define JS_OOM_CALL_BP_FUNC() do {} while(0) +#endif # define JS_OOM_POSSIBLY_FAIL() \ do \ { \ if (++OOM_counter > OOM_maxAllocations) { \ - JS_OOM_EMIT_BACKTRACE();\ - return nullptr; \ - } \ - } while (0) - -# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) \ - do \ - { \ - if (++OOM_counter > OOM_maxAllocations) { \ - JS_OOM_EMIT_BACKTRACE();\ - js_ReportOutOfMemory(cx);\ + JS_OOM_CALL_BP_FUNC();\ return nullptr; \ } \ } while (0) # else # define JS_OOM_POSSIBLY_FAIL() do {} while(0) -# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) do {} while(0) -# endif /* DEBUG */ +# endif /* DEBUG || JS_OOM_BREAKPOINT */ static inline void* js_malloc(size_t bytes) { @@ -168,26 +123,6 @@ static inline void js_free(void* p) } #endif/* JS_USE_CUSTOM_ALLOCATOR */ -/* - * JS_ROTATE_LEFT32 - * - * There is no rotate operation in the C Language so the construct (a << 4) | - * (a >> 28) is used instead. Most compilers convert this to a rotate - * instruction but some versions of MSVC don't without a little help. To get - * MSVC to generate a rotate instruction, we have to use the _rotl intrinsic - * and use a pragma to make _rotl inline. - * - * MSVC in VS2005 will do an inline rotate instruction on the above construct. - */ -#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || \ - defined(_M_X64)) -#include -#pragma intrinsic(_rotl) -#define JS_ROTATE_LEFT32(a, bits) _rotl(a, bits) -#else -#define JS_ROTATE_LEFT32(a, bits) (((a) << (bits)) | ((a) >> (32 - (bits)))) -#endif - #include /* @@ -235,6 +170,9 @@ static inline void js_free(void* p) #define JS_NEW_BODY(allocator, t, parms) \ void *memory = allocator(sizeof(t)); \ return memory ? new(memory) t parms : nullptr; +#define JS_MAKE_BODY(newname, T, parms) \ + T *ptr = newname parms; \ + return mozilla::UniquePtr>(ptr); /* * Given a class which should provide 'new' methods, add @@ -389,10 +327,191 @@ static inline void js_free(void* p) mozilla::Forward(p12)))\ }\ -JS_DECLARE_NEW_METHODS(js_new, js_malloc, static JS_ALWAYS_INLINE) +/* + * Given a class which should provide 'make' methods, add + * JS_DECLARE_MAKE_METHODS (see JSContext for a usage example). This method + * is functionally the same as JS_DECLARE_NEW_METHODS: it just declares methods + * that return mozilla::UniquePtr instances that will singly-manage ownership + * of the created object. This adds makes with up to 12 parameters. Add more + * versions below if you need more than 12 parameters. + * + * Note: Do not add a ; at the end of a use of JS_DECLARE_MAKE_METHODS, + * or the build will break. + */ +#define JS_DECLARE_MAKE_METHODS(MAKENAME, NEWNAME, QUALIFIERS)\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME() MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T, ())\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1)))\ + }\ +\ + template \ + QUALIFIERS \ +mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11, P12 &&p12) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11),\ + mozilla::Forward(p12)))\ + }\ + +JS_DECLARE_NEW_METHODS(js_new, js_malloc, static MOZ_ALWAYS_INLINE) template -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void js_delete(T *p) { if (p) { @@ -402,7 +521,7 @@ js_delete(T *p) } template -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void js_delete_poison(T *p) { if (p) { @@ -413,21 +532,21 @@ js_delete_poison(T *p) } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_malloc() { return (T *)js_malloc(sizeof(T)); } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_calloc() { return (T *)js_calloc(sizeof(T)); } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_malloc(size_t numElems) { if (numElems & mozilla::tl::MulOverflowMask::value) @@ -436,7 +555,7 @@ js_pod_malloc(size_t numElems) } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_calloc(size_t numElems) { if (numElems & mozilla::tl::MulOverflowMask::value) @@ -471,6 +590,25 @@ SCOPED_TEMPLATE(ScopedReleasePtr, ScopedReleasePtrTraits) } /* namespace js */ +namespace JS { + +template +struct DeletePolicy +{ + void operator()(T* ptr) { + js_delete(ptr); + } +}; + +struct FreePolicy +{ + void operator()(void* ptr) { + js_free(ptr); + } +}; + +} // namespace JS + namespace js { /* Integral types for all hash functions. */ @@ -535,7 +673,7 @@ namespace JS { inline void PoisonPtr(void *v) { -#if defined(JSGC_ROOT_ANALYSIS) && defined(DEBUG) +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) uint8_t *ptr = (uint8_t *) v + 3; *ptr = JS_FREE_PATTERN; #endif @@ -544,7 +682,7 @@ inline void PoisonPtr(void *v) template inline bool IsPoisonedPtr(T *v) { -#if defined(JSGC_ROOT_ANALYSIS) && defined(DEBUG) +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) uint32_t mask = uintptr_t(v) & 0xff000000; return mask == uint32_t(JS_FREE_PATTERN << 24); #else diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/Value.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/Value.h index ee4f3a64d3..e7b89e684d 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/Value.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/Value.h @@ -15,9 +15,11 @@ #include /* for std::numeric_limits */ +#include "js-config.h" #include "jstypes.h" #include "js/Anchor.h" +#include "js/GCAPI.h" #include "js/RootingAPI.h" #include "js/Utility.h" @@ -46,7 +48,7 @@ namespace JS { class Value; } # define JSVAL_ALIGNMENT #endif -#if JS_BITS_PER_WORD == 64 +#if defined(JS_PUNBOX64) # define JSVAL_TAG_SHIFT 47 #endif @@ -74,8 +76,9 @@ JS_ENUM_HEADER(JSValueType, uint8_t) JSVAL_TYPE_BOOLEAN = 0x03, JSVAL_TYPE_MAGIC = 0x04, JSVAL_TYPE_STRING = 0x05, - JSVAL_TYPE_NULL = 0x06, - JSVAL_TYPE_OBJECT = 0x07, + JSVAL_TYPE_SYMBOL = 0x06, + JSVAL_TYPE_NULL = 0x07, + JSVAL_TYPE_OBJECT = 0x08, /* These never appear in a jsval; they are only provided as an out-of-band value. */ JSVAL_TYPE_UNKNOWN = 0x20, @@ -84,7 +87,7 @@ JS_ENUM_HEADER(JSValueType, uint8_t) JS_STATIC_ASSERT(sizeof(JSValueType) == 1); -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) /* Remember to propagate changes to the C defines below. */ JS_ENUM_HEADER(JSValueTag, uint32_t) @@ -93,6 +96,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JSVAL_TAG_INT32 = JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32, JSVAL_TAG_UNDEFINED = JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED, JSVAL_TAG_STRING = JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL, JSVAL_TAG_BOOLEAN = JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN, JSVAL_TAG_MAGIC = JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC, JSVAL_TAG_NULL = JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL, @@ -101,7 +105,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JS_STATIC_ASSERT(sizeof(JSValueTag) == 4); -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) /* Remember to propagate changes to the C defines below. */ JS_ENUM_HEADER(JSValueTag, uint32_t) @@ -110,6 +114,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JSVAL_TAG_INT32 = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32, JSVAL_TAG_UNDEFINED = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED, JSVAL_TAG_STRING = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL, JSVAL_TAG_BOOLEAN = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN, JSVAL_TAG_MAGIC = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC, JSVAL_TAG_NULL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL, @@ -124,6 +129,7 @@ JS_ENUM_HEADER(JSValueShiftedTag, uint64_t) JSVAL_SHIFTED_TAG_INT32 = (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_UNDEFINED = (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_STRING = (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_SYMBOL = (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_BOOLEAN = (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_MAGIC = (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_NULL = (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT), @@ -143,29 +149,32 @@ typedef uint8_t JSValueType; #define JSVAL_TYPE_BOOLEAN ((uint8_t)0x03) #define JSVAL_TYPE_MAGIC ((uint8_t)0x04) #define JSVAL_TYPE_STRING ((uint8_t)0x05) -#define JSVAL_TYPE_NULL ((uint8_t)0x06) -#define JSVAL_TYPE_OBJECT ((uint8_t)0x07) +#define JSVAL_TYPE_SYMBOL ((uint8_t)0x06) +#define JSVAL_TYPE_NULL ((uint8_t)0x07) +#define JSVAL_TYPE_OBJECT ((uint8_t)0x08) #define JSVAL_TYPE_UNKNOWN ((uint8_t)0x20) -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) typedef uint32_t JSValueTag; #define JSVAL_TAG_CLEAR ((uint32_t)(0xFFFFFF80)) #define JSVAL_TAG_INT32 ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32)) #define JSVAL_TAG_UNDEFINED ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED)) #define JSVAL_TAG_STRING ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING)) +#define JSVAL_TAG_SYMBOL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL)) #define JSVAL_TAG_BOOLEAN ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN)) #define JSVAL_TAG_MAGIC ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC)) #define JSVAL_TAG_NULL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL)) #define JSVAL_TAG_OBJECT ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT)) -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) typedef uint32_t JSValueTag; #define JSVAL_TAG_MAX_DOUBLE ((uint32_t)(0x1FFF0)) #define JSVAL_TAG_INT32 (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32) #define JSVAL_TAG_UNDEFINED (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED) #define JSVAL_TAG_STRING (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING) +#define JSVAL_TAG_SYMBOL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL) #define JSVAL_TAG_BOOLEAN (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN) #define JSVAL_TAG_MAGIC (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC) #define JSVAL_TAG_NULL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL) @@ -176,20 +185,16 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_SHIFTED_TAG_INT32 (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_UNDEFINED (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_STRING (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_SYMBOL (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_BOOLEAN (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_MAGIC (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_NULL (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_OBJECT (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT) -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ #endif /* !defined(__SUNPRO_CC) && !defined(__xlC__) */ -#define JSVAL_LOWER_INCL_TYPE_OF_OBJ_OR_NULL_SET JSVAL_TYPE_NULL -#define JSVAL_UPPER_EXCL_TYPE_OF_PRIMITIVE_SET JSVAL_TYPE_OBJECT -#define JSVAL_UPPER_INCL_TYPE_OF_NUMBER_SET JSVAL_TYPE_INT32 -#define JSVAL_LOWER_INCL_TYPE_OF_PTR_PAYLOAD_SET JSVAL_TYPE_MAGIC - -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) #define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_CLEAR | (type))) @@ -198,7 +203,7 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32 #define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) #define JSVAL_PAYLOAD_MASK 0x00007FFFFFFFFFFFLL #define JSVAL_TAG_MASK 0xFFFF800000000000LL @@ -215,7 +220,7 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET JSVAL_SHIFTED_TAG_UNDEFINED #define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET JSVAL_SHIFTED_TAG_STRING -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ typedef enum JSWhyMagic { @@ -233,16 +238,16 @@ typedef enum JSWhyMagic JS_OPTIMIZED_ARGUMENTS, /* optimized-away 'arguments' value */ JS_IS_CONSTRUCTING, /* magic value passed to natives to indicate construction */ JS_OVERWRITTEN_CALLEE, /* arguments.callee has been overwritten */ - JS_FORWARD_TO_CALL_OBJECT, /* args object element stored in call object */ JS_BLOCK_NEEDS_CLONE, /* value of static block object slot */ JS_HASH_KEY_EMPTY, /* see class js::HashableValue */ JS_ION_ERROR, /* error while running Ion code */ - JS_ION_BAILOUT, /* status code to signal EnterIon will OSR into Interpret */ + JS_ION_BAILOUT, /* missing recover instruction result */ + JS_OPTIMIZED_OUT, /* optimized out slot */ JS_GENERIC_MAGIC /* for local use */ } JSWhyMagic; #if defined(IS_LITTLE_ENDIAN) -# if JS_BITS_PER_WORD == 32 +# if defined(JS_NUNBOX32) typedef union jsval_layout { uint64_t asBits; @@ -252,7 +257,9 @@ typedef union jsval_layout uint32_t u32; uint32_t boo; // Don't use |bool| -- it must be four bytes. JSString *str; + JS::Symbol *sym; JSObject *obj; + js::gc::Cell *cell; void *ptr; JSWhyMagic why; size_t word; @@ -263,7 +270,7 @@ typedef union jsval_layout double asDouble; void *asPtr; } JSVAL_ALIGNMENT jsval_layout; -# elif JS_BITS_PER_WORD == 64 +# elif defined(JS_PUNBOX64) typedef union jsval_layout { uint64_t asBits; @@ -286,9 +293,9 @@ typedef union jsval_layout size_t asWord; uintptr_t asUIntPtr; } JSVAL_ALIGNMENT jsval_layout; -# endif /* JS_BITS_PER_WORD */ +# endif /* JS_PUNBOX64 */ #else /* defined(IS_LITTLE_ENDIAN) */ -# if JS_BITS_PER_WORD == 32 +# if defined(JS_NUNBOX32) typedef union jsval_layout { uint64_t asBits; @@ -299,7 +306,9 @@ typedef union jsval_layout uint32_t u32; uint32_t boo; // Don't use |bool| -- it must be four bytes. JSString *str; + JS::Symbol *sym; JSObject *obj; + js::gc::Cell *cell; void *ptr; JSWhyMagic why; size_t word; @@ -309,7 +318,7 @@ typedef union jsval_layout double asDouble; void *asPtr; } JSVAL_ALIGNMENT jsval_layout; -# elif JS_BITS_PER_WORD == 64 +# elif defined(JS_PUNBOX64) typedef union jsval_layout { uint64_t asBits; @@ -330,7 +339,7 @@ typedef union jsval_layout size_t asWord; uintptr_t asUIntPtr; } JSVAL_ALIGNMENT jsval_layout; -# endif /* JS_BITS_PER_WORD */ +# endif /* JS_PUNBOX64 */ #endif /* defined(IS_LITTLE_ENDIAN) */ JS_STATIC_ASSERT(sizeof(jsval_layout) == 8); @@ -378,7 +387,7 @@ JS_STATIC_ASSERT(sizeof(jsval_layout) == 8); # define JS_VALUE_CONSTEXPR_VAR const #endif -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) /* * N.B. GCC, in some but not all cases, chooses to emit signed comparison of @@ -456,7 +465,7 @@ static inline jsval_layout STRING_TO_JSVAL_IMPL(JSString *str) { jsval_layout l; - MOZ_ASSERT(str); + MOZ_ASSERT(uintptr_t(str) > 0x1000); l.s.tag = JSVAL_TAG_STRING; l.s.payload.str = str; return l; @@ -468,6 +477,28 @@ JSVAL_TO_STRING_IMPL(jsval_layout l) return l.s.payload.str; } +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + l.s.tag = JSVAL_TAG_SYMBOL; + l.s.payload.sym = sym; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.payload.sym; +} + static inline bool JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) { @@ -524,7 +555,7 @@ static inline jsval_layout OBJECT_TO_JSVAL_IMPL(JSObject *obj) { jsval_layout l; - MOZ_ASSERT(obj); + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); l.s.tag = JSVAL_TAG_OBJECT; l.s.payload.obj = obj; return l; @@ -560,22 +591,22 @@ JSVAL_IS_GCTHING_IMPL(jsval_layout l) return (uint32_t)l.s.tag >= (uint32_t)JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET; } -static inline void * +static inline js::gc::Cell * JSVAL_TO_GCTHING_IMPL(jsval_layout l) { - return l.s.payload.ptr; -} - -static inline bool -JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) -{ - return l.s.tag == JSVAL_TAG_STRING || l.s.tag == JSVAL_TAG_OBJECT; + return l.s.payload.cell; } static inline uint32_t JSVAL_TRACE_KIND_IMPL(jsval_layout l) { - return (uint32_t)(bool)JSVAL_IS_STRING_IMPL(l); + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return l.s.tag & 0x03; } static inline bool @@ -585,7 +616,7 @@ JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) } static inline bool -JSVAL_IS_SPECIFIC_BOOLEAN(jsval_layout l, bool b) +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) { return (l.s.tag == JSVAL_TAG_BOOLEAN) && (l.s.payload.boo == uint32_t(b)); } @@ -599,6 +630,15 @@ MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) return l; } +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.s.tag = JSVAL_TAG_MAGIC; + l.s.payload.u32 = payload; + return l; +} + static inline bool JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) { @@ -614,7 +654,7 @@ JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) return (JSValueType)type; } -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) static inline JS_VALUE_CONSTEXPR jsval_layout BUILD_JSVAL(JSValueTag tag, uint64_t payload) @@ -678,7 +718,7 @@ STRING_TO_JSVAL_IMPL(JSString *str) { jsval_layout l; uint64_t strBits = (uint64_t)str; - MOZ_ASSERT(str); + MOZ_ASSERT(uintptr_t(str) > 0x1000); MOZ_ASSERT((strBits >> JSVAL_TAG_SHIFT) == 0); l.asBits = strBits | JSVAL_SHIFTED_TAG_STRING; return l; @@ -690,6 +730,29 @@ JSVAL_TO_STRING_IMPL(jsval_layout l) return (JSString *)(l.asBits & JSVAL_PAYLOAD_MASK); } +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + uint64_t symBits = (uint64_t)sym; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + MOZ_ASSERT((symBits >> JSVAL_TAG_SHIFT) == 0); + l.asBits = symBits | JSVAL_SHIFTED_TAG_SYMBOL; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return (JS::Symbol *)(l.asBits & JSVAL_PAYLOAD_MASK); +} + static inline bool JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) { @@ -725,7 +788,7 @@ JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l) static inline bool JSVAL_IS_OBJECT_IMPL(jsval_layout l) { - MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_SHIFTED_TAG_OBJECT); + MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_TAG_OBJECT); return l.asBits >= JSVAL_SHIFTED_TAG_OBJECT; } @@ -749,7 +812,7 @@ OBJECT_TO_JSVAL_IMPL(JSObject *obj) { jsval_layout l; uint64_t objBits = (uint64_t)obj; - MOZ_ASSERT(obj); + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); MOZ_ASSERT((objBits >> JSVAL_TAG_SHIFT) == 0); l.asBits = objBits | JSVAL_SHIFTED_TAG_OBJECT; return l; @@ -767,24 +830,24 @@ JSVAL_IS_GCTHING_IMPL(jsval_layout l) return l.asBits >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET; } -static inline void * +static inline js::gc::Cell * JSVAL_TO_GCTHING_IMPL(jsval_layout l) { uint64_t ptrBits = l.asBits & JSVAL_PAYLOAD_MASK; MOZ_ASSERT((ptrBits & 0x7) == 0); - return (void *)ptrBits; -} - -static inline bool -JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) -{ - return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l); + return reinterpret_cast(ptrBits); } static inline uint32_t JSVAL_TRACE_KIND_IMPL(jsval_layout l) { - return (uint32_t)(bool)!(JSVAL_IS_OBJECT_IMPL(l)); + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) & 0x03; } static inline jsval_layout @@ -812,7 +875,7 @@ JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) } static inline bool -JSVAL_IS_SPECIFIC_BOOLEAN(jsval_layout l, bool b) +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) { return l.asBits == (((uint64_t)(uint32_t)b) | JSVAL_SHIFTED_TAG_BOOLEAN); } @@ -825,6 +888,14 @@ MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) return l; } +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.asBits = ((uint64_t)payload) | JSVAL_SHIFTED_TAG_MAGIC; + return l; +} + static inline bool JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) { @@ -841,7 +912,13 @@ JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) return (JSValueType)type; } -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ + +static inline bool +JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) +{ + return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l); +} static inline jsval_layout JSVAL_TO_IMPL(JS::Value v); static inline JS_VALUE_CONSTEXPR JS::Value IMPL_TO_JSVAL(jsval_layout l); @@ -859,7 +936,7 @@ static inline JS_VALUE_CONSTEXPR JS::Value UndefinedValue(); static MOZ_ALWAYS_INLINE double GenericNaN() { - return mozilla::SpecificNaN(0, 0x8000000000000ULL); + return mozilla::SpecificNaN(0, 0x8000000000000ULL); } /* MSVC with PGO miscompiles this function. */ @@ -883,27 +960,23 @@ CanonicalizeNaN(double d) * * - JS::Value has setX() and isX() members for X in * - * { Int32, Double, String, Boolean, Undefined, Null, Object, Magic } + * { Int32, Double, String, Symbol, Boolean, Undefined, Null, Object, Magic } * * JS::Value also contains toX() for each of the non-singleton types. * - * - Magic is a singleton type whose payload contains a JSWhyMagic "reason" for - * the magic value. By providing JSWhyMagic values when creating and checking - * for magic values, it is possible to assert, at runtime, that only magic - * values with the expected reason flow through a particular value. For - * example, if cx->exception has a magic value, the reason must be - * JS_GENERATOR_CLOSING. + * - Magic is a singleton type whose payload contains either a JSWhyMagic "reason" for + * the magic value or a uint32_t value. By providing JSWhyMagic values when + * creating and checking for magic values, it is possible to assert, at + * runtime, that only magic values with the expected reason flow through a + * particular value. For example, if cx->exception has a magic value, the + * reason must be JS_GENERATOR_CLOSING. * * - The JS::Value operations are preferred. The JSVAL_* operations remain for * compatibility; they may be removed at some point. These operations mostly * provide similar functionality. But there are a few key differences. One - * is that JS::Value gives null a separate type. Thus - * - * JSVAL_IS_OBJECT(v) === v.isObjectOrNull() - * !JSVAL_IS_PRIMITIVE(v) === v.isObject() - * + * is that JS::Value gives null a separate type. * Also, to help prevent mistakenly boxing a nullable JSObject* as an object, - * Value::setObject takes a JSObject&. (Conversely, Value::asObject returns a + * Value::setObject takes a JSObject&. (Conversely, Value::toObject returns a * JSObject&.) A convenience member Value::setObjectOrNull is provided. * * - JSVAL_VOID is the same as the singleton value of the Undefined type. @@ -961,6 +1034,11 @@ class Value data = STRING_TO_JSVAL_IMPL(str); } + void setSymbol(JS::Symbol *sym) { + MOZ_ASSERT(!IsPoisonedPtr(sym)); + data = SYMBOL_TO_JSVAL_IMPL(sym); + } + void setObject(JSObject &obj) { MOZ_ASSERT(!IsPoisonedPtr(&obj)); data = OBJECT_TO_JSVAL_IMPL(&obj); @@ -974,6 +1052,10 @@ class Value data = MAGIC_TO_JSVAL_IMPL(why); } + void setMagicUint32(uint32_t payload) { + data = MAGIC_UINT32_TO_JSVAL_IMPL(payload); + } + bool setNumber(uint32_t ui) { if (ui > JSVAL_INT_MAX) { setDouble((double)ui); @@ -986,7 +1068,7 @@ class Value bool setNumber(double d) { int32_t i; - if (mozilla::DoubleIsInt32(d, &i)) { + if (mozilla::NumberIsInt32(d, &i)) { setInt32(i); return true; } @@ -1042,6 +1124,10 @@ class Value return JSVAL_IS_STRING_IMPL(data); } + bool isSymbol() const { + return JSVAL_IS_SYMBOL_IMPL(data); + } + bool isObject() const { return JSVAL_IS_OBJECT_IMPL(data); } @@ -1063,11 +1149,11 @@ class Value } bool isTrue() const { - return JSVAL_IS_SPECIFIC_BOOLEAN(data, true); + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, true); } bool isFalse() const { - return JSVAL_IS_SPECIFIC_BOOLEAN(data, false); + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, false); } bool isMagic() const { @@ -1093,6 +1179,11 @@ class Value return data.s.payload.why; } + uint32_t magicUint32() const { + MOZ_ASSERT(isMagic()); + return data.s.payload.u32; + } + /*** Comparison ***/ bool operator==(const Value &rhs) const { @@ -1127,6 +1218,11 @@ class Value return JSVAL_TO_STRING_IMPL(data); } + JS::Symbol *toSymbol() const { + MOZ_ASSERT(isSymbol()); + return JSVAL_TO_SYMBOL_IMPL(data); + } + JSObject &toObject() const { MOZ_ASSERT(isObject()); return *JSVAL_TO_OBJECT_IMPL(data); @@ -1137,7 +1233,7 @@ class Value return JSVAL_TO_OBJECT_IMPL(data); } - void *toGCThing() const { + js::gc::Cell *toGCThing() const { MOZ_ASSERT(isGCThing()); return JSVAL_TO_GCTHING_IMPL(data); } @@ -1202,17 +1298,17 @@ class Value } const size_t *payloadWord() const { -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) return &data.s.payload.word; -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) return &data.asWord; #endif } const uintptr_t *payloadUIntPtr() const { -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) return &data.s.payload.uintptr; -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) return &data.asUIntPtr; #endif } @@ -1228,7 +1324,7 @@ class Value private: #if defined(JS_VALUE_IS_CONSTEXPR) - JS_VALUE_CONSTEXPR Value(jsval_layout layout) : data(layout) {} + MOZ_IMPLICIT JS_VALUE_CONSTEXPR Value(jsval_layout layout) : data(layout) {} #endif void staticAssertions() { @@ -1248,11 +1344,30 @@ IsPoisonedValue(const Value &v) { if (v.isString()) return IsPoisonedPtr(v.toString()); + if (v.isSymbol()) + return IsPoisonedPtr(v.toSymbol()); if (v.isObject()) return IsPoisonedPtr(&v.toObject()); return false; } +inline bool +IsOptimizedPlaceholderMagicValue(const Value &v) +{ + if (v.isMagic()) { + MOZ_ASSERT(v.whyMagic() == JS_OPTIMIZED_ARGUMENTS || v.whyMagic() == JS_OPTIMIZED_OUT); + return true; + } + return false; +} + +static MOZ_ALWAYS_INLINE void +ExposeValueToActiveJS(const Value &v) +{ + if (v.isMarkable()) + ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); +} + /************************************************************************/ static inline Value @@ -1315,6 +1430,14 @@ StringValue(JSString *str) return v; } +static inline Value +SymbolValue(JS::Symbol *sym) +{ + Value v; + v.setSymbol(sym); + return v; +} + static inline Value BooleanValue(bool boo) { @@ -1363,6 +1486,14 @@ MagicValue(JSWhyMagic why) return v; } +static inline Value +MagicValueUint32(uint32_t payload) +{ + Value v; + v.setMagicUint32(payload); + return v; +} + static inline Value NumberValue(float f) { @@ -1507,16 +1638,16 @@ namespace js { template <> struct GCMethods { static JS::Value initial() { return JS::UndefinedValue(); } - static ThingRootKind kind() { return THING_ROOT_VALUE; } static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } }; template <> struct GCMethods { static JS::Value initial() { return JS::UndefinedValue(); } - static ThingRootKind kind() { return THING_ROOT_VALUE; } static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } - static bool needsPostBarrier(const JS::Value &v) { return v.isMarkable(); } + static bool needsPostBarrier(const JS::Value &v) { + return v.isObject() && gc::IsInsideNursery(reinterpret_cast(&v.toObject())); + } #ifdef JSGC_GENERATIONAL static void postBarrier(JS::Value *v) { JS::HeapValuePostBarrier(v); } static void relocate(JS::Value *v) { JS::HeapValueRelocate(v); } @@ -1548,6 +1679,7 @@ class ValueOperations bool isInt32() const { return value()->isInt32(); } bool isDouble() const { return value()->isDouble(); } bool isString() const { return value()->isString(); } + bool isSymbol() const { return value()->isSymbol(); } bool isObject() const { return value()->isObject(); } bool isMagic() const { return value()->isMagic(); } bool isMagic(JSWhyMagic why) const { return value()->isMagic(why); } @@ -1563,14 +1695,17 @@ class ValueOperations int32_t toInt32() const { return value()->toInt32(); } double toDouble() const { return value()->toDouble(); } JSString *toString() const { return value()->toString(); } + JS::Symbol *toSymbol() const { return value()->toSymbol(); } JSObject &toObject() const { return value()->toObject(); } JSObject *toObjectOrNull() const { return value()->toObjectOrNull(); } void *toGCThing() const { return value()->toGCThing(); } + uint64_t asRawBits() const { return value()->asRawBits(); } JSValueType extractNonDoubleType() const { return value()->extractNonDoubleType(); } uint32_t toPrivateUint32() const { return value()->toPrivateUint32(); } JSWhyMagic whyMagic() const { return value()->whyMagic(); } + uint32_t magicUint32() const { return value()->magicUint32(); } }; /* @@ -1595,6 +1730,7 @@ class MutableValueOperations : public ValueOperations bool setNumber(uint32_t ui) { return value()->setNumber(ui); } bool setNumber(double d) { return value()->setNumber(d); } void setString(JSString *str) { this->value()->setString(str); } + void setSymbol(JS::Symbol *sym) { this->value()->setSymbol(sym); } void setObject(JSObject &obj) { this->value()->setObject(obj); } void setObjectOrNull(JSObject *arg) { this->value()->setObjectOrNull(arg); } }; @@ -1625,6 +1761,7 @@ class HeapBase : public ValueOperations > void setBoolean(bool b) { setBarriered(JS::BooleanValue(b)); } void setMagic(JSWhyMagic why) { setBarriered(JS::MagicValue(why)); } void setString(JSString *str) { setBarriered(JS::StringValue(str)); } + void setSymbol(JS::Symbol *sym) { setBarriered(JS::SymbolValue(sym)); } void setObject(JSObject &obj) { setBarriered(JS::ObjectValue(obj)); } bool setNumber(uint32_t ui) { @@ -1639,7 +1776,7 @@ class HeapBase : public ValueOperations > bool setNumber(double d) { int32_t i; - if (mozilla::DoubleIsInt32(d, &i)) { + if (mozilla::NumberIsInt32(d, &i)) { setInt32(i); return true; } @@ -1747,7 +1884,7 @@ inline Anchor::~Anchor() } #endif -#ifdef DEBUG +#ifdef JS_DEBUG namespace detail { struct ValueAlignmentTester { char c; JS::Value v; }; @@ -1759,7 +1896,7 @@ static_assert(sizeof(LayoutAlignmentTester) == 16, "jsval_layout must be 16-byte-aligned"); } // namespace detail -#endif /* DEBUG */ +#endif /* JS_DEBUG */ } // namespace JS @@ -1775,52 +1912,12 @@ static_assert(sizeof(jsval_layout) == sizeof(JS::Value), /************************************************************************/ -static inline bool -JSVAL_IS_NULL(jsval v) -{ - return JSVAL_IS_NULL_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_VOID(jsval v) -{ - return JSVAL_IS_UNDEFINED_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_INT(jsval v) -{ - return JSVAL_IS_INT32_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline int32_t -JSVAL_TO_INT(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_INT(v)); - return JSVAL_TO_INT32_IMPL(JSVAL_TO_IMPL(v)); -} - static inline JS_VALUE_CONSTEXPR jsval INT_TO_JSVAL(int32_t i) { return IMPL_TO_JSVAL(INT32_TO_JSVAL_IMPL(i)); } -static inline bool -JSVAL_IS_DOUBLE(jsval v) -{ - return JSVAL_IS_DOUBLE_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline double -JSVAL_TO_DOUBLE(jsval v) -{ - jsval_layout l; - MOZ_ASSERT(JSVAL_IS_DOUBLE(v)); - l = JSVAL_TO_IMPL(v); - return l.asDouble; -} - static inline JS_VALUE_CONSTEXPR jsval DOUBLE_TO_JSVAL(double d) { @@ -1852,38 +1949,12 @@ UINT_TO_JSVAL(uint32_t i) : DOUBLE_TO_JSVAL((double)i)); } -static inline bool -JSVAL_IS_NUMBER(jsval v) -{ - return JSVAL_IS_NUMBER_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_STRING(jsval v) -{ - return JSVAL_IS_STRING_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline JSString * -JSVAL_TO_STRING(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_STRING(v)); - return JSVAL_TO_STRING_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval STRING_TO_JSVAL(JSString *str) { return IMPL_TO_JSVAL(STRING_TO_JSVAL_IMPL(str)); } -static inline JSObject * -JSVAL_TO_OBJECT(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_OBJECT_OR_NULL_IMPL(JSVAL_TO_IMPL(v))); - return JSVAL_TO_OBJECT_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval OBJECT_TO_JSVAL(JSObject *obj) { @@ -1892,44 +1963,12 @@ OBJECT_TO_JSVAL(JSObject *obj) return IMPL_TO_JSVAL(BUILD_JSVAL(JSVAL_TAG_NULL, 0)); } -static inline bool -JSVAL_IS_BOOLEAN(jsval v) -{ - return JSVAL_IS_BOOLEAN_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_TO_BOOLEAN(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_BOOLEAN(v)); - return JSVAL_TO_BOOLEAN_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval BOOLEAN_TO_JSVAL(bool b) { return IMPL_TO_JSVAL(BOOLEAN_TO_JSVAL_IMPL(b)); } -static inline bool -JSVAL_IS_PRIMITIVE(jsval v) -{ - return JSVAL_IS_PRIMITIVE_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_GCTHING(jsval v) -{ - return JSVAL_IS_GCTHING_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline void * -JSVAL_TO_GCTHING(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_GCTHING(v)); - return JSVAL_TO_GCTHING_IMPL(JSVAL_TO_IMPL(v)); -} - /* To be GC-safe, privates are tagged as doubles. */ static inline jsval @@ -1938,13 +1977,6 @@ PRIVATE_TO_JSVAL(void *ptr) return IMPL_TO_JSVAL(PRIVATE_PTR_TO_JSVAL_IMPL(ptr)); } -static inline void * -JSVAL_TO_PRIVATE(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_DOUBLE(v)); - return JSVAL_TO_PRIVATE_PTR_IMPL(JSVAL_TO_IMPL(v)); -} - // JS constants. For efficiency, prefer predicates (e.g. v.isNull()) and // constructing values from scratch (e.g. Int32Value(0)). These constants are // stored in memory and initialized at startup, so testing against them and @@ -1958,8 +1990,10 @@ extern JS_PUBLIC_DATA(const jsval) JSVAL_VOID; namespace JS { -extern JS_PUBLIC_DATA(const Handle) NullHandleValue; -extern JS_PUBLIC_DATA(const Handle) UndefinedHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) NullHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) TrueHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) FalseHandleValue; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/Vector.h index e8aef1713d..a2d24b10ed 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/js/Vector.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/Vector.h @@ -54,7 +54,7 @@ class Vector typedef typename mozilla::VectorBase Base; public: - Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} Vector(Vector &&vec) : Base(mozilla::Move(vec)) {} Vector &operator=(Vector &&vec) { return Base::operator=(mozilla::Move(vec)); diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/js/WeakMapPtr.h b/frameworks/js-bindings/external/spidermonkey/include/mac/js/WeakMapPtr.h new file mode 100644 index 0000000000..f5822bef4b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/js/WeakMapPtr.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_WeakMapPtr_h +#define js_WeakMapPtr_h + +#include "jspubtd.h" + +#include "js/TypeDecls.h" + +namespace JS { + +// A wrapper around the internal C++ representation of SpiderMonkey WeakMaps, +// usable outside the engine. +// +// The supported template specializations are enumerated in WeakMapPtr.cpp. If +// you want to use this class for a different key/value combination, add it to +// the list and the compiler will generate the relevant machinery. +template +class JS_PUBLIC_API(WeakMapPtr) +{ + public: + WeakMapPtr() : ptr(nullptr) {}; + bool init(JSContext *cx); + bool initialized() { return ptr != nullptr; }; + void destroy(); + virtual ~WeakMapPtr() { MOZ_ASSERT(!initialized()); } + void trace(JSTracer *tracer); + + V lookup(const K &key); + bool put(JSContext *cx, const K &key, const V &value); + + static void keyMarkCallback(JSTracer *trc, K key, void *data); + + private: + void *ptr; + + // WeakMapPtr is neither copyable nor assignable. + WeakMapPtr(const WeakMapPtr &wmp) MOZ_DELETE; + WeakMapPtr &operator=(const WeakMapPtr &wmp) MOZ_DELETE; +}; + +} /* namespace JS */ + +#endif /* js_WeakMapPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/jsalloc.h b/frameworks/js-bindings/external/spidermonkey/include/mac/jsalloc.h index 03b6b569e1..a1e547cec9 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/jsalloc.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/jsalloc.h @@ -4,7 +4,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/* JS allocation policies. */ +/* + * JS allocation policies. + * + * The allocators here are for system memory with lifetimes which are not + * managed by the GC. See the comment at the top of vm/MallocProvider.h. + */ #ifndef jsalloc_h #define jsalloc_h @@ -14,7 +19,7 @@ namespace js { -class ContextFriendFields; +struct ContextFriendFields; /* Policy for using system memory functions and doing no error reporting. */ class SystemAllocPolicy @@ -47,26 +52,26 @@ class TempAllocPolicy JS_FRIEND_API(void *) onOutOfMemory(void *p, size_t nbytes); public: - TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( - TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} + MOZ_IMPLICIT TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( + MOZ_IMPLICIT TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} void *malloc_(size_t bytes) { void *p = js_malloc(bytes); - if (JS_UNLIKELY(!p)) + if (MOZ_UNLIKELY(!p)) p = onOutOfMemory(nullptr, bytes); return p; } void *calloc_(size_t bytes) { void *p = js_calloc(bytes); - if (JS_UNLIKELY(!p)) + if (MOZ_UNLIKELY(!p)) p = onOutOfMemory(nullptr, bytes); return p; } void *realloc_(void *p, size_t oldBytes, size_t bytes) { void *p2 = js_realloc(p, bytes); - if (JS_UNLIKELY(!p2)) + if (MOZ_UNLIKELY(!p2)) p2 = onOutOfMemory(p2, bytes); return p2; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/jsapi.h b/frameworks/js-bindings/external/spidermonkey/include/mac/jsapi.h index 6d47488a33..4b5a4ce1ff 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/jsapi.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/jsapi.h @@ -9,10 +9,11 @@ #ifndef jsapi_h #define jsapi_h -#include "mozilla/Atomics.h" #include "mozilla/FloatingPoint.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/Range.h" #include "mozilla/RangedPtr.h" +#include "mozilla/TypedEnum.h" #include #include @@ -26,40 +27,28 @@ #include "js/Class.h" #include "js/HashTable.h" #include "js/Id.h" +#include "js/Principals.h" #include "js/RootingAPI.h" +#include "js/TracingAPI.h" #include "js/Utility.h" #include "js/Value.h" #include "js/Vector.h" /************************************************************************/ -struct JSTracer; - namespace JS { class Latin1CharsZ; class TwoByteChars; -typedef mozilla::RangedPtr CharPtr; - -class StableCharPtr : public CharPtr { - public: - StableCharPtr(const StableCharPtr &s) : CharPtr(s) {} - StableCharPtr(const mozilla::RangedPtr &s) : CharPtr(s) {} - StableCharPtr(const jschar *s, size_t len) : CharPtr(s, len) {} - StableCharPtr(const jschar *pos, const jschar *start, size_t len) - : CharPtr(pos, start, len) - {} -}; - -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG class JS_PUBLIC_API(AutoCheckRequestDepth) { JSContext *cx; public: - AutoCheckRequestDepth(JSContext *cx); - AutoCheckRequestDepth(js::ContextFriendFields *cx); + explicit AutoCheckRequestDepth(JSContext *cx); + explicit AutoCheckRequestDepth(js::ContextFriendFields *cx); ~AutoCheckRequestDepth(); }; @@ -71,155 +60,53 @@ class JS_PUBLIC_API(AutoCheckRequestDepth) # define CHECK_REQUEST(cx) \ ((void) 0) -#endif /* JS_THREADSAFE && DEBUG */ +#endif /* JS_THREADSAFE && JS_DEBUG */ -#ifdef DEBUG +#ifdef JS_DEBUG /* * Assert that we're not doing GC on cx, that we're in a request as * needed, and that the compartments for cx and v are correct. * Also check that GC would be safe at this point. */ JS_PUBLIC_API(void) -AssertArgumentsAreSane(JSContext *cx, JS::Handle v); +AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v); #else -inline void AssertArgumentsAreSane(JSContext *cx, JS::Handle v) { +inline void AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v) { /* Do nothing */ } -#endif /* DEBUG */ - -class JS_PUBLIC_API(AutoGCRooter) { - public: - AutoGCRooter(JSContext *cx, ptrdiff_t tag); - AutoGCRooter(js::ContextFriendFields *cx, ptrdiff_t tag); - - ~AutoGCRooter() { - JS_ASSERT(this == *stackTop); - *stackTop = down; - } - - /* Implemented in gc/RootMarking.cpp. */ - inline void trace(JSTracer *trc); - static void traceAll(JSTracer *trc); - static void traceAllWrappers(JSTracer *trc); - - protected: - AutoGCRooter * const down; - - /* - * Discriminates actual subclass of this being used. If non-negative, the - * subclass roots an array of values of the length stored in this field. - * If negative, meaning is indicated by the corresponding value in the enum - * below. Any other negative value indicates some deeper problem such as - * memory corruption. - */ - ptrdiff_t tag_; - - enum { - VALARRAY = -2, /* js::AutoValueArray */ - PARSER = -3, /* js::frontend::Parser */ - SHAPEVECTOR = -4, /* js::AutoShapeVector */ - IDARRAY = -6, /* js::AutoIdArray */ - DESCRIPTORS = -7, /* js::AutoPropDescArrayRooter */ - ID = -9, /* js::AutoIdRooter */ - VALVECTOR = -10, /* js::AutoValueVector */ - STRING = -12, /* js::AutoStringRooter */ - IDVECTOR = -13, /* js::AutoIdVector */ - OBJVECTOR = -14, /* js::AutoObjectVector */ - STRINGVECTOR =-15, /* js::AutoStringVector */ - SCRIPTVECTOR =-16, /* js::AutoScriptVector */ - NAMEVECTOR = -17, /* js::AutoNameVector */ - HASHABLEVALUE=-18, /* js::HashableValue */ - IONMASM = -19, /* js::jit::MacroAssembler */ - IONALLOC = -20, /* js::jit::AutoTempAllocatorRooter */ - WRAPVECTOR = -21, /* js::AutoWrapperVector */ - WRAPPER = -22, /* js::AutoWrapperRooter */ - OBJOBJHASHMAP=-23, /* js::AutoObjectObjectHashMap */ - OBJU32HASHMAP=-24, /* js::AutoObjectUnsigned32HashMap */ - OBJHASHSET = -25, /* js::AutoObjectHashSet */ - JSONPARSER = -26, /* js::JSONParser */ - CUSTOM = -27, /* js::CustomAutoRooter */ - FUNVECTOR = -28 /* js::AutoFunctionVector */ - }; - - private: - AutoGCRooter ** const stackTop; - - /* No copy or assignment semantics. */ - AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; - void operator=(AutoGCRooter &ida) MOZ_DELETE; -}; - -class AutoStringRooter : private AutoGCRooter { - public: - AutoStringRooter(JSContext *cx, JSString *str = nullptr - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, STRING), str_(str) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - void setString(JSString *str) { - str_ = str; - } - - JSString * string() const { - return str_; - } - - JSString ** addr() { - return &str_; - } - - JSString * const * addr() const { - return &str_; - } - - friend void AutoGCRooter::trace(JSTracer *trc); +#endif /* JS_DEBUG */ - private: - JSString *str_; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER -}; +/* AutoValueArray roots an internal fixed-size array of Values. */ +template +class AutoValueArray : public AutoGCRooter +{ + const size_t length_; + Value elements_[N]; -class AutoArrayRooter : private AutoGCRooter { public: - AutoArrayRooter(JSContext *cx, size_t len, Value *vec - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, len), array(vec), skip(cx, array, len) + explicit AutoValueArray(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, VALARRAY), length_(N) { + /* Always initialize in case we GC before assignment. */ + mozilla::PodArrayZero(elements_); MOZ_GUARD_OBJECT_NOTIFIER_INIT; - JS_ASSERT(tag_ >= 0); - } - - void changeLength(size_t newLength) { - tag_ = ptrdiff_t(newLength); - JS_ASSERT(tag_ >= 0); - } - - void changeArray(Value *newArray, size_t newLength) { - changeLength(newLength); - array = newArray; } - Value *array; + unsigned length() const { return length_; } + const Value *begin() const { return elements_; } + Value *begin() { return elements_; } - MutableHandle handleAt(size_t i) - { - JS_ASSERT(i < size_t(tag_)); - return MutableHandle::fromMarkedLocation(&array[i]); + HandleValue operator[](unsigned i) const { + JS_ASSERT(i < N); + return HandleValue::fromMarkedLocation(&elements_[i]); } - Handle handleAt(size_t i) const - { - JS_ASSERT(i < size_t(tag_)); - return Handle::fromMarkedLocation(&array[i]); + MutableHandleValue operator[](unsigned i) { + JS_ASSERT(i < N); + return MutableHandleValue::fromMarkedLocation(&elements_[i]); } - friend void AutoGCRooter::trace(JSTracer *trc); - - private: MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER - - js::SkipRoot skip; }; template @@ -228,20 +115,17 @@ class AutoVectorRooter : protected AutoGCRooter typedef js::Vector VectorImpl; VectorImpl vector; - /* Prevent overwriting of inline elements in vector. */ - js::SkipRoot vectorRoot; - public: explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, tag), vector(cx), vectorRoot(cx, &vector) + : AutoGCRooter(cx, tag), vector(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; } explicit AutoVectorRooter(js::ContextFriendFields *cx, ptrdiff_t tag MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, tag), vector(cx), vectorRoot(cx, &vector) + : AutoGCRooter(cx, tag), vector(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; } @@ -253,6 +137,7 @@ class AutoVectorRooter : protected AutoGCRooter bool empty() const { return vector.empty(); } bool append(const T &v) { return vector.append(v); } + bool append(const T *ptr, size_t len) { return vector.append(ptr, len); } bool appendAll(const AutoVectorRooter &other) { return vector.appendAll(other.vector); } @@ -291,13 +176,10 @@ class AutoVectorRooter : protected AutoGCRooter return vector.reserve(newLength); } - T &operator[](size_t i) { return vector[i]; } - const T &operator[](size_t i) const { return vector[i]; } - - JS::MutableHandle handleAt(size_t i) { + JS::MutableHandle operator[](size_t i) { return JS::MutableHandle::fromMarkedLocation(&vector[i]); } - JS::Handle handleAt(size_t i) const { + JS::Handle operator[](size_t i) const { return JS::Handle::fromMarkedLocation(&vector[i]); } @@ -408,7 +290,7 @@ class AutoHashMapRooter : protected AutoGCRooter return map.sizeOfIncludingThis(mallocSizeOf); } - unsigned generation() const { + uint32_t generation() const { return map.generation(); } @@ -523,7 +405,7 @@ class AutoHashSetRooter : protected AutoGCRooter return set.sizeOfIncludingThis(mallocSizeOf); } - unsigned generation() const { + uint32_t generation() const { return set.generation(); } @@ -629,7 +511,7 @@ class AutoScriptVector : public AutoVectorRooter }; /* - * Cutsom rooting behavior for internal and external clients. + * Custom rooting behavior for internal and external clients. */ class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter { @@ -651,6 +533,86 @@ class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER }; +/* + * RootedGeneric allows a class to instantiate its own Rooted type by + * including the method: + * + * void trace(JSTracer *trc); + * + * The trace() method must trace all of the class's fields. + */ +template +class RootedGeneric : private CustomAutoRooter +{ + public: + template + explicit RootedGeneric(CX *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + template + explicit RootedGeneric(CX *cx, const T& initial MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx), value(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + operator const T&() const { return value; } + T operator->() const { return value; } + + private: + virtual void trace(JSTracer *trc) { value->trace(trc); } + + T value; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* A handle to an array of rooted values. */ +class HandleValueArray +{ + const size_t length_; + const Value * const elements_; + + HandleValueArray(size_t len, const Value *elements) : length_(len), elements_(elements) {} + + public: + explicit HandleValueArray(const RootedValue& value) : length_(1), elements_(value.address()) {} + + MOZ_IMPLICIT HandleValueArray(const AutoValueVector& values) + : length_(values.length()), elements_(values.begin()) {} + + template + HandleValueArray(const AutoValueArray& values) : length_(N), elements_(values.begin()) {} + + /* CallArgs must already be rooted somewhere up the stack. */ + MOZ_IMPLICIT HandleValueArray(const JS::CallArgs& args) : length_(args.length()), elements_(args.array()) {} + + /* Use with care! Only call this if the data is guaranteed to be marked. */ + static HandleValueArray fromMarkedLocation(size_t len, const Value *elements) { + return HandleValueArray(len, elements); + } + + static HandleValueArray subarray(const HandleValueArray& values, size_t startIndex, size_t len) { + JS_ASSERT(startIndex + len <= values.length()); + return HandleValueArray(len, values.begin() + startIndex); + } + + static HandleValueArray empty() { + return HandleValueArray(0, nullptr); + } + + size_t length() const { return length_; } + const Value *begin() const { return elements_; } + + HandleValue operator[](size_t i) const { + JS_ASSERT(i < length_); + return HandleValue::fromMarkedLocation(&elements_[i]); + } +}; + } /* namespace JS */ /************************************************************************/ @@ -660,7 +622,7 @@ struct JSFreeOp { JSRuntime *runtime_; protected: - JSFreeOp(JSRuntime *rt) + explicit JSFreeOp(JSRuntime *rt) : runtime_(rt) { } public: @@ -725,10 +687,10 @@ typedef enum JSFinalizeStatus { } JSFinalizeStatus; typedef void -(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment); +(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment, void *data); typedef bool -(* JSOperationCallback)(JSContext *cx); +(* JSInterruptCallback)(JSContext *cx); typedef void (* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report); @@ -771,37 +733,20 @@ typedef struct JSErrorFormatString { } JSErrorFormatString; typedef const JSErrorFormatString * -(* JSErrorCallback)(void *userRef, const char *locale, - const unsigned errorNumber); +(* JSErrorCallback)(void *userRef, const unsigned errorNumber); typedef bool -(* JSLocaleToUpperCase)(JSContext *cx, JS::Handle src, - JS::MutableHandle rval); +(* JSLocaleToUpperCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); typedef bool -(* JSLocaleToLowerCase)(JSContext *cx, JS::Handle src, - JS::MutableHandle rval); +(* JSLocaleToLowerCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); typedef bool -(* JSLocaleCompare)(JSContext *cx, JS::Handle src1, JS::Handle src2, - JS::MutableHandle rval); - -typedef bool -(* JSLocaleToUnicode)(JSContext *cx, const char *src, JS::MutableHandle rval); - -/* - * Security protocol types. - */ - -typedef void -(* JSDestroyPrincipalsOp)(JSPrincipals *principals); +(* JSLocaleCompare)(JSContext *cx, JS::HandleString src1, JS::HandleString src2, + JS::MutableHandleValue rval); -/* - * Used to check if a CSP instance wants to disable eval() and friends. - * See js_CheckCSPPermitsJSAction() in jsobj. - */ typedef bool -(* JSCSPEvalChecker)(JSContext *cx); +(* JSLocaleToUnicode)(JSContext *cx, const char *src, JS::MutableHandleValue rval); /* * Callback used to ask the embedding for the cross compartment wrapper handler @@ -813,9 +758,8 @@ typedef bool * guaranteed not to wrap a function. */ typedef JSObject * -(* JSWrapObjectCallback)(JSContext *cx, JS::Handle existing, JS::Handle obj, - JS::Handle proto, JS::Handle parent, - unsigned flags); +(* JSWrapObjectCallback)(JSContext *cx, JS::HandleObject existing, JS::HandleObject obj, + JS::HandleObject parent, unsigned flags); /* * Callback used by the wrap hook to ask the embedding to prepare an object @@ -823,26 +767,12 @@ typedef JSObject * * or even finding a more suitable object for the new compartment. */ typedef JSObject * -(* JSPreWrapCallback)(JSContext *cx, JS::Handle scope, JS::Handle obj, +(* JSPreWrapCallback)(JSContext *cx, JS::HandleObject scope, JS::HandleObject obj, unsigned flags); -/* - * Callback used when wrapping determines that the underlying object is already - * in the compartment for which it is being wrapped. This allows consumers to - * maintain same-compartment wrapping invariants. - * - * |obj| is guaranteed to be same-compartment as |cx|, but it may (or may not) - * be a security or cross-compartment wrapper. This is an unfortunate contract, - * but is important for to avoid unnecessarily recomputing every cross- - * compartment wrapper that gets passed to wrap. - */ -typedef JSObject * -(* JSSameCompartmentWrapObjectCallback)(JSContext *cx, JS::Handle obj); - struct JSWrapObjectCallbacks { JSWrapObjectCallback wrap; - JSSameCompartmentWrapObjectCallback sameCompartmentWrap; JSPreWrapCallback preWrap; }; @@ -858,12 +788,12 @@ typedef void /************************************************************************/ -static JS_ALWAYS_INLINE jsval +static MOZ_ALWAYS_INLINE jsval JS_NumberValue(double d) { int32_t i; d = JS::CanonicalizeNaN(d); - if (mozilla::DoubleIsInt32(d, &i)) + if (mozilla::NumberIsInt32(d, &i)) return INT_TO_JSVAL(i); return DOUBLE_TO_JSVAL(d); } @@ -883,41 +813,91 @@ JS_StringHasBeenInterned(JSContext *cx, JSString *str); JS_PUBLIC_API(jsid) INTERNED_STRING_TO_JSID(JSContext *cx, JSString *str); -/* - * Returns true iff the given jsval is immune to GC and can be used across - * multiple JSRuntimes without requiring any conversion API. - */ -static JS_ALWAYS_INLINE bool -JSVAL_IS_UNIVERSAL(jsval v) -{ - return !JSVAL_IS_GCTHING(v); -} - namespace JS { -class AutoIdRooter : private AutoGCRooter +// Container class for passing in script source buffers to the JS engine. This +// not only groups the buffer and length values, it also provides a way to +// optionally pass ownership of the buffer to the JS engine without copying. +// Rules for use: +// +// 1) The data array must be allocated with js_malloc() or js_realloc() if +// ownership is being granted to the SourceBufferHolder. +// 2) If ownership is not given to the SourceBufferHolder, then the memory +// must be kept alive until the JS compilation is complete. +// 3) Any code calling SourceBufferHolder::take() must guarantee to keep the +// memory alive until JS compilation completes. Normally only the JS +// engine should be calling take(). +// +// Example use: +// +// size_t length = 512; +// jschar* chars = static_cast(js_malloc(sizeof(jschar) * length)); +// JS::SourceBufferHolder srcBuf(chars, length, JS::SourceBufferHolder::GiveOwnership); +// JS::Compile(cx, obj, options, srcBuf); +// +class MOZ_STACK_CLASS SourceBufferHolder MOZ_FINAL { public: - explicit AutoIdRooter(JSContext *cx, jsid aId = INT_TO_JSID(0) - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, ID), id_(aId) + enum Ownership { + NoOwnership, + GiveOwnership + }; + + SourceBufferHolder(const jschar *data, size_t dataLength, Ownership ownership) + : data_(data), + length_(dataLength), + ownsChars_(ownership == GiveOwnership) { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; + // Ensure that null buffers properly return an unowned, empty, + // null-terminated string. + static const jschar NullChar_ = 0; + if (!get()) { + data_ = &NullChar_; + length_ = 0; + ownsChars_ = false; + } } - jsid id() { - return id_; + ~SourceBufferHolder() { + if (ownsChars_) + js_free(const_cast(data_)); } - jsid * addr() { - return &id_; - } + // Access the underlying source buffer without affecting ownership. + const jschar *get() const { return data_; } - friend void AutoGCRooter::trace(JSTracer *trc); + // Length of the source buffer in jschars (not bytes) + size_t length() const { return length_; } + + // Returns true if the SourceBufferHolder owns the buffer and will free + // it upon destruction. If true, it is legal to call take(). + bool ownsChars() const { return ownsChars_; } + + // Retrieve and take ownership of the underlying data buffer. The caller + // is now responsible for calling js_free() on the returned value, *but only + // after JS script compilation has completed*. + // + // After the buffer has been taken the SourceBufferHolder functions as if + // it had been constructed on an unowned buffer; get() and length() still + // work. In order for this to be safe the taken buffer must be kept alive + // until after JS script compilation completes as noted above. + // + // Note, it's the caller's responsibility to check ownsChars() before taking + // the buffer. Taking and then free'ing an unowned buffer will have dire + // consequences. + jschar *take() { + JS_ASSERT(ownsChars_); + ownsChars_ = false; + return const_cast(data_); + } private: - jsid id_; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + SourceBufferHolder(SourceBufferHolder &) MOZ_DELETE; + SourceBufferHolder &operator=(SourceBufferHolder &) MOZ_DELETE; + + const jschar *data_; + size_t length_; + bool ownsChars_; }; } /* namespace JS */ @@ -941,8 +921,6 @@ class AutoIdRooter : private AutoGCRooter object that delegates to a prototype containing this property */ #define JSPROP_INDEX 0x80 /* name is actually (int) index */ -#define JSPROP_SHORTID 0x100 /* set in JS_DefineProperty attrs - if getters/setters use a shortid */ #define JSFUN_STUB_GSOPS 0x200 /* use JS_PropertyStub getter/setter instead of defaulting to class gsops @@ -1029,13 +1007,12 @@ JS_GetEmptyString(JSRuntime *rt); * unconverted arguments. */ extern JS_PUBLIC_API(bool) -JS_ConvertArguments(JSContext *cx, unsigned argc, jsval *argv, const char *format, - ...); +JS_ConvertArguments(JSContext *cx, const JS::CallArgs &args, const char *format, ...); #ifdef va_start extern JS_PUBLIC_API(bool) -JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv, - const char *format, va_list ap); +JS_ConvertArgumentsVA(JSContext *cx, const JS::CallArgs &args, const char *format, + va_list ap); #endif extern JS_PUBLIC_API(bool) @@ -1051,7 +1028,7 @@ extern JS_PUBLIC_API(JSFunction *) JS_ValueToConstructor(JSContext *cx, JS::HandleValue v); extern JS_PUBLIC_API(JSString *) -JS_ValueToSource(JSContext *cx, jsval v); +JS_ValueToSource(JSContext *cx, JS::Handle v); namespace js { /* @@ -1076,14 +1053,10 @@ ToStringSlow(JSContext *cx, JS::HandleValue v); namespace JS { /* ES5 9.3 ToNumber. */ -JS_ALWAYS_INLINE bool -ToNumber(JSContext *cx, Handle v, double *out) +MOZ_ALWAYS_INLINE bool +ToNumber(JSContext *cx, HandleValue v, double *out) { AssertArgumentsAreSane(cx, v); - { - js::SkipRoot root(cx, &v); - js::MaybeCheckStackRoots(cx); - } if (v.isNumber()) { *out = v.toNumber(); @@ -1092,7 +1065,7 @@ ToNumber(JSContext *cx, Handle v, double *out) return js::ToNumberSlow(cx, v, out); } -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool ToBoolean(HandleValue v) { if (v.isBoolean()) @@ -1105,12 +1078,14 @@ ToBoolean(HandleValue v) double d = v.toDouble(); return !mozilla::IsNaN(d) && d != 0; } + if (v.isSymbol()) + return true; /* The slow path handles strings and objects. */ return js::ToBooleanSlow(v); } -JS_ALWAYS_INLINE JSString* +MOZ_ALWAYS_INLINE JSString* ToString(JSContext *cx, HandleValue v) { if (v.isString()) @@ -1133,32 +1108,31 @@ JS_DoubleToUint32(double d); namespace js { /* DO NOT CALL THIS. Use JS::ToUint16. */ extern JS_PUBLIC_API(bool) -ToUint16Slow(JSContext *cx, JS::Handle v, uint16_t *out); +ToUint16Slow(JSContext *cx, JS::HandleValue v, uint16_t *out); /* DO NOT CALL THIS. Use JS::ToInt32. */ extern JS_PUBLIC_API(bool) -ToInt32Slow(JSContext *cx, JS::Handle v, int32_t *out); +ToInt32Slow(JSContext *cx, JS::HandleValue v, int32_t *out); /* DO NOT CALL THIS. Use JS::ToUint32. */ extern JS_PUBLIC_API(bool) -ToUint32Slow(JSContext *cx, JS::Handle v, uint32_t *out); +ToUint32Slow(JSContext *cx, JS::HandleValue v, uint32_t *out); /* DO NOT CALL THIS. Use JS::ToInt64. */ extern JS_PUBLIC_API(bool) -ToInt64Slow(JSContext *cx, JS::Handle v, int64_t *out); +ToInt64Slow(JSContext *cx, JS::HandleValue v, int64_t *out); /* DO NOT CALL THIS. Use JS::ToUint64. */ extern JS_PUBLIC_API(bool) -ToUint64Slow(JSContext *cx, JS::Handle v, uint64_t *out); +ToUint64Slow(JSContext *cx, JS::HandleValue v, uint64_t *out); } /* namespace js */ namespace JS { -JS_ALWAYS_INLINE bool -ToUint16(JSContext *cx, JS::Handle v, uint16_t *out) +MOZ_ALWAYS_INLINE bool +ToUint16(JSContext *cx, JS::HandleValue v, uint16_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = uint16_t(v.toInt32()); @@ -1167,11 +1141,10 @@ ToUint16(JSContext *cx, JS::Handle v, uint16_t *out) return js::ToUint16Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToInt32(JSContext *cx, JS::Handle v, int32_t *out) +MOZ_ALWAYS_INLINE bool +ToInt32(JSContext *cx, JS::HandleValue v, int32_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = v.toInt32(); @@ -1180,11 +1153,10 @@ ToInt32(JSContext *cx, JS::Handle v, int32_t *out) return js::ToInt32Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToUint32(JSContext *cx, JS::Handle v, uint32_t *out) +MOZ_ALWAYS_INLINE bool +ToUint32(JSContext *cx, JS::HandleValue v, uint32_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = uint32_t(v.toInt32()); @@ -1193,32 +1165,28 @@ ToUint32(JSContext *cx, JS::Handle v, uint32_t *out) return js::ToUint32Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToInt64(JSContext *cx, JS::Handle v, int64_t *out) +MOZ_ALWAYS_INLINE bool +ToInt64(JSContext *cx, JS::HandleValue v, int64_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = int64_t(v.toInt32()); return true; } - return js::ToInt64Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToUint64(JSContext *cx, JS::Handle v, uint64_t *out) +MOZ_ALWAYS_INLINE bool +ToUint64(JSContext *cx, JS::HandleValue v, uint64_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { /* Account for sign extension of negatives into the longer 64bit space. */ *out = uint64_t(int64_t(v.toInt32())); return true; } - return js::ToUint64Slow(cx, v, out); } @@ -1226,7 +1194,7 @@ ToUint64(JSContext *cx, JS::Handle v, uint64_t *out) } /* namespace JS */ extern JS_PUBLIC_API(JSType) -JS_TypeOfValue(JSContext *cx, jsval v); +JS_TypeOfValue(JSContext *cx, JS::Handle v); extern JS_PUBLIC_API(const char *) JS_GetTypeName(JSContext *cx, JSType type); @@ -1235,7 +1203,7 @@ extern JS_PUBLIC_API(bool) JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal); extern JS_PUBLIC_API(bool) -JS_LooselyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal); +JS_LooselyEqual(JSContext *cx, JS::Handle v1, JS::Handle v2, bool *equal); extern JS_PUBLIC_API(bool) JS_SameValue(JSContext *cx, jsval v1, jsval v2, bool *same); @@ -1258,12 +1226,6 @@ JS_IsBuiltinFunctionConstructor(JSFunction *fun); * See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference */ -typedef enum JSUseHelperThreads -{ - JS_NO_HELPER_THREADS, - JS_USE_HELPER_THREADS -} JSUseHelperThreads; - /** * Initialize SpiderMonkey, returning true only if initialization succeeded. * Once this method has succeeded, it is safe to call JS_NewRuntime and other @@ -1301,7 +1263,9 @@ extern JS_PUBLIC_API(void) JS_ShutDown(void); extern JS_PUBLIC_API(JSRuntime *) -JS_NewRuntime(uint32_t maxbytes, JSUseHelperThreads useHelperThreads); +JS_NewRuntime(uint32_t maxbytes, + uint32_t maxNurseryBytes = JS::DefaultNurseryBytes, + JSRuntime *parentRuntime = nullptr); extern JS_PUBLIC_API(void) JS_DestroyRuntime(JSRuntime *rt); @@ -1324,6 +1288,9 @@ JS_GetRuntimePrivate(JSRuntime *rt); extern JS_PUBLIC_API(JSRuntime *) JS_GetRuntime(JSContext *cx); +extern JS_PUBLIC_API(JSRuntime *) +JS_GetParentRuntime(JSContext *cx); + JS_PUBLIC_API(void) JS_SetRuntimePrivate(JSRuntime *rt, void *data); @@ -1349,8 +1316,8 @@ AssertHeapIsIdle(JSContext *cx); class JSAutoRequest { public: - JSAutoRequest(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit JSAutoRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : mContext(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -1374,10 +1341,10 @@ class JSAutoRequest class JSAutoCheckRequest { public: - JSAutoCheckRequest(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit JSAutoCheckRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) { -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG mContext = cx; JS_ASSERT(JS_IsInRequest(JS_GetRuntime(cx))); #endif @@ -1385,14 +1352,14 @@ class JSAutoCheckRequest } ~JSAutoCheckRequest() { -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG JS_ASSERT(JS_IsInRequest(JS_GetRuntime(mContext))); #endif } private: -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG JSContext *mContext; #endif MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER @@ -1448,54 +1415,122 @@ JS_StringToVersion(const char *string); namespace JS { -class JS_PUBLIC_API(ContextOptions) { +class JS_PUBLIC_API(RuntimeOptions) { public: - ContextOptions() - : extraWarnings_(false), + RuntimeOptions() + : baseline_(false), + ion_(false), + asmJS_(false), + nativeRegExp_(false), werror_(false), - varObjFix_(false), - privateIsNSISupports_(false), - dontReportUncaught_(false), - noDefaultCompartmentObject_(false), - noScriptRval_(false), strictMode_(false), - baseline_(false), - typeInference_(false), - ion_(false), - asmJS_(false) + varObjFix_(false) { } - bool extraWarnings() const { return extraWarnings_; } - ContextOptions &setExtraWarnings(bool flag) { - extraWarnings_ = flag; + bool baseline() const { return baseline_; } + RuntimeOptions &setBaseline(bool flag) { + baseline_ = flag; return *this; } - ContextOptions &toggleExtraWarnings() { - extraWarnings_ = !extraWarnings_; + RuntimeOptions &toggleBaseline() { + baseline_ = !baseline_; + return *this; + } + + bool ion() const { return ion_; } + RuntimeOptions &setIon(bool flag) { + ion_ = flag; + return *this; + } + RuntimeOptions &toggleIon() { + ion_ = !ion_; + return *this; + } + + bool asmJS() const { return asmJS_; } + RuntimeOptions &setAsmJS(bool flag) { + asmJS_ = flag; + return *this; + } + RuntimeOptions &toggleAsmJS() { + asmJS_ = !asmJS_; + return *this; + } + + bool nativeRegExp() const { return nativeRegExp_; } + RuntimeOptions &setNativeRegExp(bool flag) { + nativeRegExp_ = flag; return *this; } bool werror() const { return werror_; } - ContextOptions &setWerror(bool flag) { + RuntimeOptions &setWerror(bool flag) { werror_ = flag; return *this; } - ContextOptions &toggleWerror() { + RuntimeOptions &toggleWerror() { werror_ = !werror_; return *this; } + bool strictMode() const { return strictMode_; } + RuntimeOptions &setStrictMode(bool flag) { + strictMode_ = flag; + return *this; + } + RuntimeOptions &toggleStrictMode() { + strictMode_ = !strictMode_; + return *this; + } + bool varObjFix() const { return varObjFix_; } - ContextOptions &setVarObjFix(bool flag) { + RuntimeOptions &setVarObjFix(bool flag) { varObjFix_ = flag; return *this; } - ContextOptions &toggleVarObjFix() { + RuntimeOptions &toggleVarObjFix() { varObjFix_ = !varObjFix_; return *this; } + private: + bool baseline_ : 1; + bool ion_ : 1; + bool asmJS_ : 1; + bool nativeRegExp_ : 1; + bool werror_ : 1; + bool strictMode_ : 1; + bool varObjFix_ : 1; +}; + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSRuntime *rt); + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSContext *cx); + +class JS_PUBLIC_API(ContextOptions) { + public: + ContextOptions() + : extraWarnings_(false), + privateIsNSISupports_(false), + dontReportUncaught_(false), + noDefaultCompartmentObject_(false), + noScriptRval_(false) + { + } + + bool extraWarnings() const { return extraWarnings_; } + ContextOptions &setExtraWarnings(bool flag) { + extraWarnings_ = flag; + return *this; + } + ContextOptions &toggleExtraWarnings() { + extraWarnings_ = !extraWarnings_; + return *this; + } + bool privateIsNSISupports() const { return privateIsNSISupports_; } ContextOptions &setPrivateIsNSISupports(bool flag) { privateIsNSISupports_ = flag; @@ -1536,69 +1571,12 @@ class JS_PUBLIC_API(ContextOptions) { return *this; } - bool strictMode() const { return strictMode_; } - ContextOptions &setStrictMode(bool flag) { - strictMode_ = flag; - return *this; - } - ContextOptions &toggleStrictMode() { - strictMode_ = !strictMode_; - return *this; - } - - bool baseline() const { return baseline_; } - ContextOptions &setBaseline(bool flag) { - baseline_ = flag; - return *this; - } - ContextOptions &toggleBaseline() { - baseline_ = !baseline_; - return *this; - } - - bool typeInference() const { return typeInference_; } - ContextOptions &setTypeInference(bool flag) { - typeInference_ = flag; - return *this; - } - ContextOptions &toggleTypeInference() { - typeInference_ = !typeInference_; - return *this; - } - - bool ion() const { return ion_; } - ContextOptions &setIon(bool flag) { - ion_ = flag; - return *this; - } - ContextOptions &toggleIon() { - ion_ = !ion_; - return *this; - } - - bool asmJS() const { return asmJS_; } - ContextOptions &setAsmJS(bool flag) { - asmJS_ = flag; - return *this; - } - ContextOptions &toggleAsmJS() { - asmJS_ = !asmJS_; - return *this; - } - private: bool extraWarnings_ : 1; - bool werror_ : 1; - bool varObjFix_ : 1; bool privateIsNSISupports_ : 1; bool dontReportUncaught_ : 1; bool noDefaultCompartmentObject_ : 1; bool noScriptRval_ : 1; - bool strictMode_ : 1; - bool baseline_ : 1; - bool typeInference_ : 1; - bool ion_ : 1; - bool asmJS_ : 1; }; JS_PUBLIC_API(ContextOptions &) @@ -1606,7 +1584,7 @@ ContextOptionsRef(JSContext *cx); class JS_PUBLIC_API(AutoSaveContextOptions) { public: - AutoSaveContextOptions(JSContext *cx) + explicit AutoSaveContextOptions(JSContext *cx) : cx_(cx), oldOptions_(ContextOptionsRef(cx_)) { @@ -1624,9 +1602,6 @@ class JS_PUBLIC_API(AutoSaveContextOptions) { } /* namespace JS */ -extern JS_PUBLIC_API(void) -JS_SetJitHardening(JSRuntime *rt, bool enabled); - extern JS_PUBLIC_API(const char *) JS_GetImplementationVersion(void); @@ -1663,14 +1638,11 @@ JS_WrapObject(JSContext *cx, JS::MutableHandleObject objp); extern JS_PUBLIC_API(bool) JS_WrapValue(JSContext *cx, JS::MutableHandleValue vp); -extern JS_PUBLIC_API(bool) -JS_WrapId(JSContext *cx, jsid *idp); - extern JS_PUBLIC_API(JSObject *) -JS_TransplantObject(JSContext *cx, JS::Handle origobj, JS::Handle target); +JS_TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target); extern JS_PUBLIC_API(bool) -JS_RefreshCrossCompartmentWrappers(JSContext *cx, JSObject *ob); +JS_RefreshCrossCompartmentWrappers(JSContext *cx, JS::Handle obj); /* * At any time, a JSContext has a current (possibly-nullptr) compartment. @@ -1717,6 +1689,15 @@ class JS_PUBLIC_API(JSAutoCompartment) ~JSAutoCompartment(); }; +class JS_PUBLIC_API(JSAutoNullableCompartment) +{ + JSContext *cx_; + JSCompartment *oldCompartment_; + public: + explicit JSAutoNullableCompartment(JSContext *cx, JSObject *targetOrNull); + ~JSAutoNullableCompartment(); +}; + /* NB: This API is infallible; a nullptr return value does not indicate error. */ extern JS_PUBLIC_API(JSCompartment *) JS_EnterCompartment(JSContext *cx, JSObject *target); @@ -1743,7 +1724,7 @@ JS_IterateCompartments(JSRuntime *rt, void *data, * NB: This sets cx's global object to obj if it was null. */ extern JS_PUBLIC_API(bool) -JS_InitStandardClasses(JSContext *cx, JSObject *obj); +JS_InitStandardClasses(JSContext *cx, JS::Handle obj); /* * Resolve id, which must contain either a string or an int, to a standard @@ -1759,20 +1740,40 @@ JS_InitStandardClasses(JSContext *cx, JSObject *obj); * loops any classes not yet resolved lazily. */ extern JS_PUBLIC_API(bool) -JS_ResolveStandardClass(JSContext *cx, JS::Handle obj, JS::Handle id, - bool *resolved); +JS_ResolveStandardClass(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *resolved); extern JS_PUBLIC_API(bool) -JS_EnumerateStandardClasses(JSContext *cx, JS::Handle obj); +JS_EnumerateStandardClasses(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, JSObject **objp); +JS_GetClassObject(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); extern JS_PUBLIC_API(bool) -JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JSObject **objp); +JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); + +namespace JS { + +/* + * Determine if the given object is an instance/prototype/constructor for a standard + * class. If so, return the associated JSProtoKey. If not, return JSProto_Null. + */ + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstance(JSObject *obj); extern JS_PUBLIC_API(JSProtoKey) -JS_IdentifyClassPrototype(JSContext *cx, JSObject *obj); +IdentifyStandardPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstanceOrPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardConstructor(JSObject *obj); + +extern JS_PUBLIC_API(void) +ProtoKeyToId(JSContext *cx, JSProtoKey key, JS::MutableHandleId idp); + +} /* namespace JS */ extern JS_PUBLIC_API(JSProtoKey) JS_IdToProtoKey(JSContext *cx, JS::HandleId id); @@ -1782,21 +1783,28 @@ JS_IdToProtoKey(JSContext *cx, JS::HandleId id); * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetFunctionPrototype(JSContext *cx, JSObject *forObj); +JS_GetFunctionPrototype(JSContext *cx, JS::HandleObject forObj); /* * Returns the original value of |Object.prototype| from the global object in * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetObjectPrototype(JSContext *cx, JSObject *forObj); +JS_GetObjectPrototype(JSContext *cx, JS::HandleObject forObj); /* * Returns the original value of |Array.prototype| from the global object in * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetArrayPrototype(JSContext *cx, JSObject *forObj); +JS_GetArrayPrototype(JSContext *cx, JS::HandleObject forObj); + +/* + * Returns the original value of |Error.prototype| from the global + * object of the current compartment of cx. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetErrorPrototype(JSContext *cx); extern JS_PUBLIC_API(JSObject *) JS_GetGlobalForObject(JSContext *cx, JSObject *obj); @@ -1818,23 +1826,11 @@ CurrentGlobalOrNull(JSContext *cx); } -/* - * This method returns the global corresponding to the most recent scripted - * frame, which may not match the cx's current compartment. This is extremely - * dangerous, because it can bypass compartment security invariants in subtle - * ways. To use it safely, the caller must perform a subsequent security - * check. There is currently only one consumer of this function in Gecko, and - * it should probably stay that way. If you'd like to use it, please consult - * the XPConnect module owner first. - */ -extern JS_PUBLIC_API(JSObject *) -JS_GetScriptedGlobal(JSContext *cx); - /* * Initialize the 'Reflect' object on a global object. */ extern JS_PUBLIC_API(JSObject *) -JS_InitReflect(JSContext *cx, JSObject *global); +JS_InitReflect(JSContext *cx, JS::HandleObject global); #ifdef JS_HAS_CTYPES /* @@ -1842,7 +1838,7 @@ JS_InitReflect(JSContext *cx, JSObject *global); * object will be sealed. */ extern JS_PUBLIC_API(bool) -JS_InitCTypesClass(JSContext *cx, JSObject *global); +JS_InitCTypesClass(JSContext *cx, JS::HandleObject global); /* * Convert a unicode string 'source' of length 'slen' to the platform native @@ -1917,6 +1913,7 @@ JS_strdup(JSContext *cx, const char *s); extern JS_PUBLIC_API(char *) JS_strdup(JSRuntime *rt, const char *s); +namespace JS { /* * A GC root is a pointer to a jsval, JSObject * or JSString * that itself @@ -1944,52 +1941,54 @@ JS_strdup(JSRuntime *rt, const char *s); * before freeing structPtr's memory. */ extern JS_PUBLIC_API(bool) -JS_AddValueRoot(JSContext *cx, jsval *vp); +AddValueRoot(JSContext *cx, JS::Heap *vp); extern JS_PUBLIC_API(bool) -JS_AddStringRoot(JSContext *cx, JSString **rp); +AddStringRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(bool) -JS_AddObjectRoot(JSContext *cx, JSObject **rp); +AddObjectRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(bool) -JS_AddNamedValueRoot(JSContext *cx, jsval *vp, const char *name); +AddNamedValueRoot(JSContext *cx, JS::Heap *vp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedValueRootRT(JSRuntime *rt, jsval *vp, const char *name); +AddNamedValueRootRT(JSRuntime *rt, JS::Heap *vp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedStringRoot(JSContext *cx, JSString **rp, const char *name); +AddNamedStringRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedObjectRoot(JSContext *cx, JSObject **rp, const char *name); +AddNamedObjectRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedScriptRoot(JSContext *cx, JSScript **rp, const char *name); +AddNamedScriptRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(void) -JS_RemoveValueRoot(JSContext *cx, jsval *vp); +RemoveValueRoot(JSContext *cx, JS::Heap *vp); extern JS_PUBLIC_API(void) -JS_RemoveStringRoot(JSContext *cx, JSString **rp); +RemoveStringRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveObjectRoot(JSContext *cx, JSObject **rp); +RemoveObjectRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveScriptRoot(JSContext *cx, JSScript **rp); +RemoveScriptRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveValueRootRT(JSRuntime *rt, jsval *vp); +RemoveValueRootRT(JSRuntime *rt, JS::Heap *vp); extern JS_PUBLIC_API(void) -JS_RemoveStringRootRT(JSRuntime *rt, JSString **rp); +RemoveStringRootRT(JSRuntime *rt, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveObjectRootRT(JSRuntime *rt, JSObject **rp); +RemoveObjectRootRT(JSRuntime *rt, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveScriptRootRT(JSRuntime *rt, JSScript **rp); +RemoveScriptRootRT(JSRuntime *rt, JS::Heap *rp); + +} /* namespace JS */ /* * Register externally maintained GC roots. @@ -2005,42 +2004,10 @@ JS_AddExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); extern JS_PUBLIC_API(void) JS_RemoveExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); -/* - * JS_CallTracer API and related macros for implementors of JSTraceOp, to - * enumerate all references to traceable things reachable via a property or - * other strong ref identified for debugging purposes by name or index or - * a naming callback. - * - * See the JSTraceOp typedef. - */ +#ifdef JS_DEBUG /* - * Use the following macros to check if a particular jsval is a traceable - * thing and to extract the thing and its kind to pass to JS_CallTracer. - */ -static JS_ALWAYS_INLINE bool -JSVAL_IS_TRACEABLE(jsval v) -{ - return JSVAL_IS_TRACEABLE_IMPL(JSVAL_TO_IMPL(v)); -} - -static JS_ALWAYS_INLINE void * -JSVAL_TO_TRACEABLE(jsval v) -{ - return JSVAL_TO_GCTHING(v); -} - -static JS_ALWAYS_INLINE JSGCTraceKind -JSVAL_TRACE_KIND(jsval v) -{ - JS_ASSERT(JSVAL_IS_GCTHING(v)); - return (JSGCTraceKind) JSVAL_TRACE_KIND_IMPL(JSVAL_TO_IMPL(v)); -} - -#ifdef DEBUG - -/* - * DEBUG-only method to dump the object graph of heap-allocated things. + * Debug-only method to dump the object graph of heap-allocated things. * * fp: file for the dump output. * start: when non-null, dump only things reachable from start @@ -2072,14 +2039,17 @@ JS_MaybeGC(JSContext *cx); extern JS_PUBLIC_API(void) JS_SetGCCallback(JSRuntime *rt, JSGCCallback cb, void *data); +extern JS_PUBLIC_API(bool) +JS_AddFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb, void *data); + extern JS_PUBLIC_API(void) -JS_SetFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); +JS_RemoveFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); extern JS_PUBLIC_API(bool) JS_IsGCMarkingTracer(JSTracer *trc); /* For assertions only. */ -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_PUBLIC_API(bool) JS_IsMarkingGray(JSTracer *trc); #endif @@ -2175,22 +2145,17 @@ typedef enum JSGCParamKey { * available to be decommitted, then JS_MaybeGC will trigger a shrinking GC * to decommit it. */ - JSGC_DECOMMIT_THRESHOLD = 20 -} JSGCParamKey; - -typedef enum JSGCMode { - /* Perform only global GCs. */ - JSGC_MODE_GLOBAL = 0, - - /* Perform per-compartment GCs until too much garbage has accumulated. */ - JSGC_MODE_COMPARTMENT = 1, + JSGC_DECOMMIT_THRESHOLD = 20, /* - * Collect in short time slices rather than all at once. Implies - * JSGC_MODE_COMPARTMENT. + * We try to keep at least this many unused chunks in the free chunk pool at + * all times, even after a shrinking GC. */ - JSGC_MODE_INCREMENTAL = 2 -} JSGCMode; + JSGC_MIN_EMPTY_CHUNK_COUNT = 21, + + /* We never keep more than this many unused chunks in the free chunk pool. */ + JSGC_MAX_EMPTY_CHUNK_COUNT = 22 +} JSGCParamKey; extern JS_PUBLIC_API(void) JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32_t value); @@ -2204,6 +2169,9 @@ JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32_t value); extern JS_PUBLIC_API(uint32_t) JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key); +extern JS_PUBLIC_API(void) +JS_SetGCParametersBasedOnAvailableMemory(JSRuntime *rt, uint32_t availMem); + /* * Create a new JSString whose chars member refers to external memory, i.e., * memory requiring application-specific finalization. @@ -2252,7 +2220,7 @@ extern JS_PUBLIC_API(int) JS_IdArrayLength(JSContext *cx, JSIdArray *ida); extern JS_PUBLIC_API(jsid) -JS_IdArrayGet(JSContext *cx, JSIdArray *ida, int index); +JS_IdArrayGet(JSContext *cx, JSIdArray *ida, unsigned index); extern JS_PUBLIC_API(void) JS_DestroyIdArray(JSContext *cx, JSIdArray *ida); @@ -2272,13 +2240,12 @@ class AutoIdArray : private AutoGCRooter if (idArray) JS_DestroyIdArray(context, idArray); } - bool operator!() { + bool operator!() const { return !idArray; } jsid operator[](size_t i) const { JS_ASSERT(idArray); - JS_ASSERT(i < length()); - return JS_IdArrayGet(context, idArray, i); + return JS_IdArrayGet(context, idArray, unsigned(i)); } size_t length() const { return JS_IdArrayLength(context, idArray); @@ -2308,15 +2275,13 @@ class AutoIdArray : private AutoGCRooter } /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_ValueToId(JSContext *cx, jsval v, jsid *idp); +JS_ValueToId(JSContext *cx, JS::HandleValue v, JS::MutableHandleId idp); extern JS_PUBLIC_API(bool) -JS_IdToValue(JSContext *cx, jsid id, jsval *vp); +JS_StringToId(JSContext *cx, JS::HandleString s, JS::MutableHandleId idp); -/* - * JSNewResolveOp flag bits. - */ -#define JSRESOLVE_ASSIGNING 0x01 /* resolve on the left of assignment */ +extern JS_PUBLIC_API(bool) +JS_IdToValue(JSContext *cx, jsid id, JS::MutableHandle vp); /* * Invoke the [[DefaultValue]] hook (see ES5 8.6.2) with the provided hint on @@ -2325,29 +2290,30 @@ JS_IdToValue(JSContext *cx, jsid id, jsval *vp); * success the resulting value is stored in *vp. */ extern JS_PUBLIC_API(bool) -JS_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp); +JS_DefaultValue(JSContext *cx, JS::Handle obj, JSType hint, + JS::MutableHandle vp); extern JS_PUBLIC_API(bool) -JS_PropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, - JS::MutableHandle vp); +JS_PropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_StrictPropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, bool strict, - JS::MutableHandle vp); +JS_StrictPropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_DeletePropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, +JS_DeletePropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_EnumerateStub(JSContext *cx, JS::Handle obj); +JS_EnumerateStub(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_ResolveStub(JSContext *cx, JS::Handle obj, JS::Handle id); +JS_ResolveStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id); extern JS_PUBLIC_API(bool) -JS_ConvertStub(JSContext *cx, JS::Handle obj, JSType type, - JS::MutableHandle vp); +JS_ConvertStub(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); struct JSConstDoubleSpec { double dval; @@ -2385,7 +2351,7 @@ typedef struct JSNativeWrapper { * Macro static initializers which make it easy to pass no JSJitInfo as part of a * JSPropertySpec or JSFunctionSpec. */ -#define JSOP_WRAPPER(op) {op, nullptr} +#define JSOP_WRAPPER(op) { {op, nullptr} } #define JSOP_NULLWRAPPER JSOP_WRAPPER(nullptr) /* @@ -2394,13 +2360,29 @@ typedef struct JSNativeWrapper { * JSPROP_INDEX bit in flags. */ struct JSPropertySpec { + struct SelfHostedWrapper { + void *unused; + const char *funname; + }; + const char *name; - int8_t tinyid; uint8_t flags; - JSPropertyOpWrapper getter; - JSStrictPropertyOpWrapper setter; - const char *selfHostedGetter; - const char *selfHostedSetter; + union { + JSPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } getter; + union { + JSStrictPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } setter; + +private: + void StaticAsserts() { + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSPropertyOpWrapper)); + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSStrictPropertyOpWrapper)); + JS_STATIC_ASSERT(offsetof(SelfHostedWrapper, funname) == + offsetof(JSPropertyOpWrapper, info)); + } }; namespace JS { @@ -2409,6 +2391,11 @@ namespace detail { /* NEVER DEFINED, DON'T USE. For use by JS_CAST_NATIVE_TO only. */ inline int CheckIsNative(JSNative native); +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_STRING_TO only. */ +template +inline int +CheckIsCharacterLiteral(const char (&arr)[N]); + } // namespace detail } // namespace JS @@ -2416,6 +2403,10 @@ inline int CheckIsNative(JSNative native); (static_cast(sizeof(JS::detail::CheckIsNative(v))), \ reinterpret_cast(v)) +#define JS_CAST_STRING_TO(s, To) \ + (static_cast(sizeof(JS::detail::CheckIsCharacterLiteral(s))), \ + reinterpret_cast(s)) + #define JS_CHECK_ACCESSOR_FLAGS(flags) \ (static_cast::Type>(0), \ (flags)) @@ -2428,26 +2419,26 @@ inline int CheckIsNative(JSNative native); * JSNatives. */ #define JS_PSG(name, getter, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ - JSOP_NULLWRAPPER, nullptr, nullptr} + JSOP_NULLWRAPPER} #define JS_PSGS(name, getter, setter, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ - JSOP_WRAPPER(JS_CAST_NATIVE_TO(setter, JSStrictPropertyOp)), \ - nullptr, nullptr} + JSOP_WRAPPER(JS_CAST_NATIVE_TO(setter, JSStrictPropertyOp))} #define JS_SELF_HOSTED_GET(name, getterName, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER), \ - JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, getterName, nullptr} + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + JSOP_NULLWRAPPER } #define JS_SELF_HOSTED_GETSET(name, getterName, setterName, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER | JSPROP_SETTER), \ - JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, getterName, setterName} -#define JS_PS_END {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, \ - nullptr, nullptr} + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + { nullptr, JS_CAST_STRING_TO(setterName, const JSJitInfo *) } } +#define JS_PS_END { nullptr, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER } /* * To define a native function, set call to a JSNativeWrapper. To define a @@ -2487,7 +2478,7 @@ struct JSFunctionSpec { {name, {call, info}, nargs, flags, selfHostedName} extern JS_PUBLIC_API(JSObject *) -JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, +JS_InitClass(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent_proto, const JSClass *clasp, JSNative constructor, unsigned nargs, const JSPropertySpec *ps, const JSFunctionSpec *fs, const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs); @@ -2497,16 +2488,17 @@ JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, * right property flags. */ extern JS_PUBLIC_API(bool) -JS_LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor, JSObject *proto); +JS_LinkConstructorAndPrototype(JSContext *cx, JS::Handle ctor, + JS::Handle proto); extern JS_PUBLIC_API(const JSClass *) JS_GetClass(JSObject *obj); extern JS_PUBLIC_API(bool) -JS_InstanceOf(JSContext *cx, JSObject *obj, const JSClass *clasp, jsval *argv); +JS_InstanceOf(JSContext *cx, JS::Handle obj, const JSClass *clasp, JS::CallArgs *args); extern JS_PUBLIC_API(bool) -JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, bool *bp); +JS_HasInstance(JSContext *cx, JS::Handle obj, JS::Handle v, bool *bp); extern JS_PUBLIC_API(void *) JS_GetPrivate(JSObject *obj); @@ -2515,31 +2507,23 @@ extern JS_PUBLIC_API(void) JS_SetPrivate(JSObject *obj, void *data); extern JS_PUBLIC_API(void *) -JS_GetInstancePrivate(JSContext *cx, JSObject *obj, const JSClass *clasp, - jsval *argv); +JS_GetInstancePrivate(JSContext *cx, JS::Handle obj, const JSClass *clasp, + JS::CallArgs *args); extern JS_PUBLIC_API(bool) -JS_GetPrototype(JSContext *cx, JS::Handle obj, JS::MutableHandle protop); +JS_GetPrototype(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject protop); extern JS_PUBLIC_API(bool) -JS_SetPrototype(JSContext *cx, JS::Handle obj, JS::Handle proto); +JS_SetPrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); extern JS_PUBLIC_API(JSObject *) JS_GetParent(JSObject *obj); extern JS_PUBLIC_API(bool) -JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent); +JS_SetParent(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent); extern JS_PUBLIC_API(JSObject *) -JS_GetConstructor(JSContext *cx, JSObject *proto); - -/* - * Get a unique identifier for obj, good for the lifetime of obj (even if it - * is moved by a copying GC). Return false on failure (likely out of memory), - * and true with *idp containing the unique id on success. - */ -extern JS_PUBLIC_API(bool) -JS_GetObjectId(JSContext *cx, JSObject *obj, jsid *idp); +JS_GetConstructor(JSContext *cx, JS::Handle proto); namespace JS { @@ -2582,6 +2566,12 @@ class JS_PUBLIC_API(CompartmentOptions) explicit CompartmentOptions() : version_(JSVERSION_UNKNOWN) , invisibleToDebugger_(false) + , mergeable_(false) + , discardSource_(false) + , cloneSingletons_(false) + , traceGlobal_(nullptr) + , singletonsAsTemplates_(true) + , addonId_(nullptr) { zone_.spec = JS::FreshZone; } @@ -2597,23 +2587,36 @@ class JS_PUBLIC_API(CompartmentOptions) // of the embedding, and references to them should never leak out to script. // This flag causes the this compartment to skip firing onNewGlobalObject // and makes addDebuggee a no-op for this global. - bool invisibleToDebugger() { return invisibleToDebugger_; } + bool invisibleToDebugger() const { return invisibleToDebugger_; } CompartmentOptions &setInvisibleToDebugger(bool flag) { invisibleToDebugger_ = flag; return *this; } - bool baseline(JSContext *cx) const; - Override &baselineOverride() { return baselineOverride_; } + // Compartments used for off-thread compilation have their contents merged + // into a target compartment when the compilation is finished. This is only + // allowed if this flag is set. The invisibleToDebugger flag must also be + // set for such compartments. + bool mergeable() const { return mergeable_; } + CompartmentOptions &setMergeable(bool flag) { + mergeable_ = flag; + return *this; + } - bool typeInference(const js::ExclusiveContext *cx) const; - Override &typeInferenceOverride() { return typeInferenceOverride_; } + // For certain globals, we know enough about the code that will run in them + // that we can discard script source entirely. + bool discardSource() const { return discardSource_; } + CompartmentOptions &setDiscardSource(bool flag) { + discardSource_ = flag; + return *this; + } - bool ion(JSContext *cx) const; - Override &ionOverride() { return ionOverride_; } - bool asmJS(JSContext *cx) const; - Override &asmJSOverride() { return asmJSOverride_; } + bool cloneSingletons() const { return cloneSingletons_; } + CompartmentOptions &setCloneSingletons(bool flag) { + cloneSingletons_ = flag; + return *this; + } void *zonePointer() const { JS_ASSERT(uintptr_t(zone_.pointer) > uintptr_t(JS::SystemZone)); @@ -2623,22 +2626,55 @@ class JS_PUBLIC_API(CompartmentOptions) CompartmentOptions &setZone(ZoneSpecifier spec); CompartmentOptions &setSameZoneAs(JSObject *obj); + void setSingletonsAsValues() { + singletonsAsTemplates_ = false; + } + bool getSingletonsAsTemplates() const { + return singletonsAsTemplates_; + }; + + // A null add-on ID means that the compartment is not associated with an + // add-on. + JSAddonId *addonIdOrNull() const { return addonId_; } + CompartmentOptions &setAddonId(JSAddonId *id) { + addonId_ = id; + return *this; + } + + CompartmentOptions &setTrace(JSTraceOp op) { + traceGlobal_ = op; + return *this; + } + JSTraceOp getTrace() const { + return traceGlobal_; + } + private: JSVersion version_; bool invisibleToDebugger_; - Override baselineOverride_; - Override typeInferenceOverride_; - Override ionOverride_; - Override asmJSOverride_; + bool mergeable_; + bool discardSource_; + bool cloneSingletons_; union { ZoneSpecifier spec; void *pointer; // js::Zone* is not exposed in the API. } zone_; + JSTraceOp traceGlobal_; + + // To XDR singletons, we need to ensure that all singletons are all used as + // templates, by making JSOP_OBJECT return a clone of the JSScript + // singleton, instead of returning the value which is baked in the JSScript. + bool singletonsAsTemplates_; + + JSAddonId *addonId_; }; JS_PUBLIC_API(CompartmentOptions &) CompartmentOptionsRef(JSCompartment *compartment); +JS_PUBLIC_API(CompartmentOptions &) +CompartmentOptionsRef(JSObject *obj); + JS_PUBLIC_API(CompartmentOptions &) CompartmentOptionsRef(JSContext *cx); @@ -2673,16 +2709,28 @@ extern JS_PUBLIC_API(JSObject *) JS_NewGlobalObject(JSContext *cx, const JSClass *clasp, JSPrincipals *principals, JS::OnNewGlobalHookOption hookOption, const JS::CompartmentOptions &options = JS::CompartmentOptions()); +/* + * Spidermonkey does not have a good way of keeping track of what compartments should be marked on + * their own. We can mark the roots unconditionally, but marking GC things only relevant in live + * compartments is hard. To mitigate this, we create a static trace hook, installed on each global + * object, from which we can be sure the compartment is relevant, and mark it. + * + * It is still possible to specify custom trace hooks for global object classes. They can be + * provided via the CompartmentOptions passed to JS_NewGlobalObject. + */ +extern JS_PUBLIC_API(void) +JS_GlobalObjectTraceHook(JSTracer *trc, JSObject *global); extern JS_PUBLIC_API(void) JS_FireOnNewGlobalObject(JSContext *cx, JS::HandleObject global); extern JS_PUBLIC_API(JSObject *) -JS_NewObject(JSContext *cx, const JSClass *clasp, JSObject *proto, JSObject *parent); +JS_NewObject(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); /* Queries the [[Extensible]] property of the object. */ extern JS_PUBLIC_API(bool) -JS_IsExtensible(JSContext *cx, JS::Handle obj, bool *extensible); +JS_IsExtensible(JSContext *cx, JS::HandleObject obj, bool *extensible); extern JS_PUBLIC_API(bool) JS_IsNative(JSObject *obj); @@ -2695,8 +2743,8 @@ JS_GetObjectRuntime(JSObject *obj); * proto if proto's actual parameter value is null. */ extern JS_PUBLIC_API(JSObject *) -JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JSObject *proto, - JSObject *parent); +JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); /* * Freeze obj, and all objects it refers to, recursively. This will not recurse @@ -2704,88 +2752,126 @@ JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JSObject *proto, * deep-frozen. */ extern JS_PUBLIC_API(bool) -JS_DeepFreezeObject(JSContext *cx, JSObject *obj); +JS_DeepFreezeObject(JSContext *cx, JS::Handle obj); /* * Freezes an object; see ES5's Object.freeze(obj) method. */ extern JS_PUBLIC_API(bool) -JS_FreezeObject(JSContext *cx, JSObject *obj); +JS_FreezeObject(JSContext *cx, JS::Handle obj); extern JS_PUBLIC_API(bool) -JS_PreventExtensions(JSContext *cx, JS::Handle obj); +JS_PreventExtensions(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(JSObject *) -JS_New(JSContext *cx, JSObject *ctor, unsigned argc, jsval *argv); +JS_New(JSContext *cx, JS::HandleObject ctor, const JS::HandleValueArray& args); extern JS_PUBLIC_API(JSObject *) -JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, const JSClass *clasp, - JSObject *proto, unsigned attrs); +JS_DefineObject(JSContext *cx, JS::HandleObject obj, const char *name, + const JSClass *clasp = nullptr, JS::HandleObject proto = JS::NullPtr(), + unsigned attrs = 0); extern JS_PUBLIC_API(bool) -JS_DefineConstDoubles(JSContext *cx, JSObject *obj, const JSConstDoubleSpec *cds); +JS_DefineConstDoubles(JSContext *cx, JS::HandleObject obj, const JSConstDoubleSpec *cds); extern JS_PUBLIC_API(bool) -JS_DefineProperties(JSContext *cx, JSObject *obj, const JSPropertySpec *ps); +JS_DefineProperties(JSContext *cx, JS::HandleObject obj, const JSPropertySpec *ps); extern JS_PUBLIC_API(bool) -JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id, jsval descriptor, bool *bp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name, - int8_t tinyid, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name, - bool *foundp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnPropertyById(JSContext *cx, JSObject *obj, jsid id, - bool *foundp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, bool *foundp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, bool *foundp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name, - unsigned flags, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id, - unsigned flags, JSObject **objp, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnProperty(JSContext *cx, JS::HandleObject obj, const char *name, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasProperty(JSContext *cx, JS::HandleObject obj, const char *name, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_LookupPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); struct JSPropertyDescriptor { JSObject *obj; unsigned attrs; - unsigned shortid; JSPropertyOp getter; JSStrictPropertyOp setter; JS::Value value; - JSPropertyDescriptor() : obj(nullptr), attrs(0), shortid(0), getter(nullptr), - setter(nullptr), value(JSVAL_VOID) + JSPropertyDescriptor() + : obj(nullptr), attrs(0), getter(nullptr), setter(nullptr), value(JSVAL_VOID) {} void trace(JSTracer *trc); + + static js::ThingRootKind rootKind() { return js::THING_ROOT_PROPERTY_DESCRIPTOR; } }; namespace JS { @@ -2803,30 +2889,29 @@ class PropertyDescriptorOperations bool hasGetterObject() const { return desc()->attrs & JSPROP_GETTER; } bool hasSetterObject() const { return desc()->attrs & JSPROP_SETTER; } bool hasGetterOrSetterObject() const { return desc()->attrs & (JSPROP_GETTER | JSPROP_SETTER); } + bool hasGetterOrSetter() const { return desc()->getter || desc()->setter; } bool isShared() const { return desc()->attrs & JSPROP_SHARED; } bool isIndex() const { return desc()->attrs & JSPROP_INDEX; } - bool hasShortId() const { return desc()->attrs & JSPROP_SHORTID; } bool hasAttributes(unsigned attrs) const { return desc()->attrs & attrs; } - JS::Handle object() const { - return JS::Handle::fromMarkedLocation(&desc()->obj); + JS::HandleObject object() const { + return JS::HandleObject::fromMarkedLocation(&desc()->obj); } unsigned attributes() const { return desc()->attrs; } - unsigned shortid() const { return desc()->shortid; } JSPropertyOp getter() const { return desc()->getter; } JSStrictPropertyOp setter() const { return desc()->setter; } - JS::Handle getterObject() const { + JS::HandleObject getterObject() const { MOZ_ASSERT(hasGetterObject()); - return JS::Handle::fromMarkedLocation( + return JS::HandleObject::fromMarkedLocation( reinterpret_cast(&desc()->getter)); } - JS::Handle setterObject() const { + JS::HandleObject setterObject() const { MOZ_ASSERT(hasSetterObject()); - return JS::Handle::fromMarkedLocation( + return JS::HandleObject::fromMarkedLocation( reinterpret_cast(&desc()->setter)); } - JS::Handle value() const { - return JS::Handle::fromMarkedLocation(&desc()->value); + JS::HandleValue value() const { + return JS::HandleValue::fromMarkedLocation(&desc()->value); } }; @@ -2840,30 +2925,47 @@ class MutablePropertyDescriptorOperations : public PropertyDescriptorOperations< void clear() { object().set(nullptr); setAttributes(0); - setShortId(0); setGetter(nullptr); setSetter(nullptr); value().setUndefined(); } - JS::MutableHandle object() { - return JS::MutableHandle::fromMarkedLocation(&desc()->obj); + void assign(JSPropertyDescriptor &other) { + object().set(other.obj); + setAttributes(other.attrs); + setGetter(other.getter); + setSetter(other.setter); + value().set(other.value); + } + + JS::MutableHandleObject object() { + return JS::MutableHandleObject::fromMarkedLocation(&desc()->obj); } unsigned &attributesRef() { return desc()->attrs; } JSPropertyOp &getter() { return desc()->getter; } JSStrictPropertyOp &setter() { return desc()->setter; } - JS::MutableHandle value() { - return JS::MutableHandle::fromMarkedLocation(&desc()->value); + JS::MutableHandleValue value() { + return JS::MutableHandleValue::fromMarkedLocation(&desc()->value); } void setEnumerable() { desc()->attrs |= JSPROP_ENUMERATE; } void setAttributes(unsigned attrs) { desc()->attrs = attrs; } - void setShortId(unsigned id) { desc()->shortid = id; } void setGetter(JSPropertyOp op) { desc()->getter = op; } void setSetter(JSStrictPropertyOp op) { desc()->setter = op; } void setGetterObject(JSObject *obj) { desc()->getter = reinterpret_cast(obj); } void setSetterObject(JSObject *obj) { desc()->setter = reinterpret_cast(obj); } + + JS::MutableHandleObject getterObject() { + MOZ_ASSERT(this->hasGetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->getter)); + } + JS::MutableHandleObject setterObject() { + MOZ_ASSERT(this->hasSetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->setter)); + } }; } /* namespace JS */ @@ -2873,7 +2975,6 @@ namespace js { template <> struct GCMethods { static JSPropertyDescriptor initial() { return JSPropertyDescriptor(); } - static ThingRootKind kind() { return THING_ROOT_PROPERTY_DESCRIPTOR; } static bool poisoned(const JSPropertyDescriptor &desc) { return (desc.obj && JS::IsPoisonedPtr(desc.obj)) || (desc.attrs & JSPROP_GETTER && desc.getter && JS::IsPoisonedPtr(desc.getter)) || @@ -2922,12 +3023,22 @@ class MutableHandleBase } /* namespace js */ +namespace JS { + +extern JS_PUBLIC_API(bool) +ParsePropertyDescriptorObject(JSContext *cx, + JS::HandleObject obj, + JS::HandleValue descriptor, + JS::MutableHandle desc); + +} // namespace JS + extern JS_PUBLIC_API(bool) -JS_GetOwnPropertyDescriptorById(JSContext *cx, JSObject *objArg, jsid id, unsigned flags, +JS_GetOwnPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, const char *name, unsigned flags, +JS_GetOwnPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandle desc); /* @@ -2936,138 +3047,193 @@ JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, const char *name, u * then this property was not found on the prototype chain. */ extern JS_PUBLIC_API(bool) -JS_GetPropertyDescriptorById(JSContext *cx, JSObject *obj, jsid id, unsigned flags, +JS_GetPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetPropertyDescriptor(JSContext *cx, JSObject *obj, const char *name, unsigned flags, +JS_GetPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, JS::MutableHandle vp); +JS_GetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetPropertyTo(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject onBehalfOf, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); +JS_SetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_ForwardGetPropertyTo(JSContext *cx, JSObject *obj, jsid id, JSObject *onBehalfOf, - JS::MutableHandle vp); +JS_DeleteProperty(JSContext *cx, JS::HandleObject obj, const char *name); extern JS_PUBLIC_API(bool) -JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, JS::Handle v); +JS_DeleteProperty2(JSContext *cx, JS::HandleObject obj, const char *name, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_SetPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::Handle v); +JS_DeletePropertyById(JSContext *cx, JS::HandleObject obj, jsid id); extern JS_PUBLIC_API(bool) -JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name); +JS_DeletePropertyById2(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name, bool *succeeded); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleValue value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DeletePropertyById(JSContext *cx, JSObject *obj, jsid id); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleObject value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, bool *succeeded); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleString value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineUCProperty(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + int32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, - int8_t tinyid, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + uint32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnUCProperty(JSContext *cx, JSObject *obj, const jschar *name, +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + double value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *foundp); extern JS_PUBLIC_API(bool) -JS_HasUCProperty(JSContext *cx, JSObject *obj, +JS_HasUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *vp); extern JS_PUBLIC_API(bool) -JS_LookupUCProperty(JSContext *cx, JSObject *obj, +JS_LookupUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::MutableHandle vp); + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_GetUCProperty(JSContext *cx, JSObject *obj, +JS_GetUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::MutableHandle vp); + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_SetUCProperty(JSContext *cx, JSObject *obj, +JS_SetUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::Handle v); + JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_DeleteUCProperty2(JSContext *cx, JSObject *obj, const jschar *name, size_t namelen, +JS_DeleteUCProperty2(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *succeeded); extern JS_PUBLIC_API(JSObject *) -JS_NewArrayObject(JSContext *cx, int length, jsval *vector); +JS_NewArrayObject(JSContext *cx, const JS::HandleValueArray& contents); + +extern JS_PUBLIC_API(JSObject *) +JS_NewArrayObject(JSContext *cx, size_t length); extern JS_PUBLIC_API(bool) -JS_IsArrayObject(JSContext *cx, JSObject *obj); +JS_IsArrayObject(JSContext *cx, JS::HandleValue value); extern JS_PUBLIC_API(bool) -JS_GetArrayLength(JSContext *cx, JSObject *obj, uint32_t *lengthp); +JS_IsArrayObject(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_SetArrayLength(JSContext *cx, JSObject *obj, uint32_t length); +JS_GetArrayLength(JSContext *cx, JS::Handle obj, uint32_t *lengthp); extern JS_PUBLIC_API(bool) -JS_DefineElement(JSContext *cx, JSObject *obj, uint32_t index, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_SetArrayLength(JSContext *cx, JS::Handle obj, uint32_t length); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnElement(JSContext *cx, JSObject *obj, uint32_t index, bool *foundp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasElement(JSContext *cx, JSObject *obj, uint32_t index, bool *foundp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_GetElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_ForwardGetElementTo(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf, - JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetElementTo(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::HandleObject onBehalfOf, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t v); -/* - * Get the property with name given by |index|, if it has one. If - * not, |*present| will be set to false and the value of |vp| must not - * be relied on. - */ extern JS_PUBLIC_API(bool) -JS_GetElementIfPresent(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf, - JS::MutableHandle vp, bool* present); +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t v); extern JS_PUBLIC_API(bool) -JS_SetElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double v); extern JS_PUBLIC_API(bool) -JS_DeleteElement(JSContext *cx, JSObject *obj, uint32_t index); +JS_DeleteElement(JSContext *cx, JS::HandleObject obj, uint32_t index); extern JS_PUBLIC_API(bool) -JS_DeleteElement2(JSContext *cx, JSObject *obj, uint32_t index, bool *succeeded); +JS_DeleteElement2(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded); /* * Remove all configurable properties from the given (non-global) object and * assign undefined to all writable data properties. */ JS_PUBLIC_API(void) -JS_ClearNonGlobalObject(JSContext *cx, JSObject *objArg); +JS_ClearNonGlobalObject(JSContext *cx, JS::HandleObject obj); /* * Assign 'undefined' to all of the object's non-reserved slots. Note: this is @@ -3077,48 +3243,64 @@ JS_PUBLIC_API(void) JS_SetAllNonReservedSlotsToUndefined(JSContext *cx, JSObject *objArg); /* - * Create a new array buffer with the given contents, which must have been - * returned by JS_AllocateArrayBufferContents or JS_StealArrayBufferContents. - * The new array buffer takes ownership. After calling this function, do not - * free |contents| or use |contents| from another thread. + * Create a new array buffer with the given contents. On success, the ownership + * is transferred to the new array buffer. */ extern JS_PUBLIC_API(JSObject *) -JS_NewArrayBufferWithContents(JSContext *cx, void *contents); +JS_NewArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); /* * Steal the contents of the given array buffer. The array buffer has its * length set to 0 and its contents array cleared. The caller takes ownership - * of |*contents| and must free it or transfer ownership via + * of the return value and must free it or transfer ownership via * JS_NewArrayBufferWithContents when done using it. - * To free |*contents|, call free(). - * A pointer to the buffer's data is returned in |*data|. This pointer can - * be used until |*contents| is freed or has its ownership transferred. */ -extern JS_PUBLIC_API(bool) -JS_StealArrayBufferContents(JSContext *cx, JS::HandleObject obj, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_StealArrayBufferContents(JSContext *cx, JS::HandleObject obj); /* * Allocate memory that may be eventually passed to - * JS_NewArrayBufferWithContents. |nbytes| is the number of payload bytes - * required. The pointer to pass to JS_NewArrayBufferWithContents is returned - * in |contents|. The pointer to the |nbytes| of usable memory is returned in - * |data|. (*|contents| will contain a header before |data|.) The only legal - * operations on *|contents| is to free it, or pass it to - * JS_NewArrayBufferWithContents or JS_ReallocateArrayBufferContents. + * JS_NewArrayBufferWithContents. |maybecx| is optional; if a non-nullptr cx is + * given, it will be used for memory accounting and OOM reporting. |nbytes| is + * the number of payload bytes required. */ -extern JS_PUBLIC_API(bool) -JS_AllocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_AllocateArrayBufferContents(JSContext *maybecx, uint32_t nbytes); /* * Reallocate memory allocated by JS_AllocateArrayBufferContents, growing or - * shrinking it as appropriate. The new data pointer will be returned in data. - * If *contents is nullptr, behaves like JS_AllocateArrayBufferContents. + * shrinking it as appropriate. If oldContents is null then this behaves like + * JS_AllocateArrayBufferContents. */ -extern JS_PUBLIC_API(bool) -JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void *oldContents, uint32_t oldNbytes); + +/* + * Create a new mapped array buffer with the given memory mapped contents. On success, + * the ownership is transferred to the new mapped array buffer. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewMappedArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); + +/* + * Create memory mapped array buffer contents. + * Caller must take care of closing fd after calling this function. + */ +extern JS_PUBLIC_API(void *) +JS_CreateMappedArrayBufferContents(int fd, size_t offset, size_t length); + +/* + * Release the allocated resource of mapped array buffer contents before the + * object is created. + * If a new object has been created by JS_NewMappedArrayBufferWithContents() + * with this content, then JS_NeuterArrayBuffer() should be used instead to + * release the resource used by the object. + */ +extern JS_PUBLIC_API(void) +JS_ReleaseMappedArrayBufferContents(void *contents, size_t length); extern JS_PUBLIC_API(JSIdArray *) -JS_Enumerate(JSContext *cx, JSObject *obj); +JS_Enumerate(JSContext *cx, JS::HandleObject obj); /* * Create an object to iterate over enumerable properties of obj, in arbitrary @@ -3126,7 +3308,7 @@ JS_Enumerate(JSContext *cx, JSObject *obj); * order, which uses order of property definition in obj. */ extern JS_PUBLIC_API(JSObject *) -JS_NewPropertyIterator(JSContext *cx, JSObject *obj); +JS_NewPropertyIterator(JSContext *cx, JS::Handle obj); /* * Return true on success with *idp containing the id of the next enumerable @@ -3134,11 +3316,7 @@ JS_NewPropertyIterator(JSContext *cx, JSObject *obj); * left to visit. Return false on error. */ extern JS_PUBLIC_API(bool) -JS_NextProperty(JSContext *cx, JSObject *iterobj, jsid *idp); - -extern JS_PUBLIC_API(bool) -JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, - jsval *vp, unsigned *attrsp); +JS_NextProperty(JSContext *cx, JS::Handle iterobj, jsid *idp); extern JS_PUBLIC_API(jsval) JS_GetReservedSlot(JSObject *obj, uint32_t index); @@ -3148,84 +3326,12 @@ JS_SetReservedSlot(JSObject *obj, uint32_t index, jsval v); /************************************************************************/ -/* - * Security protocol. - */ -struct JSPrincipals { - /* Don't call "destroy"; use reference counting macros below. */ -#ifdef JS_THREADSAFE - mozilla::Atomic refcount; -#else - int32_t refcount; -#endif - -#ifdef DEBUG - /* A helper to facilitate principals debugging. */ - uint32_t debugToken; -#endif - - void setDebugToken(uint32_t token) { -# ifdef DEBUG - debugToken = token; -# endif - } - - /* - * This is not defined by the JS engine but should be provided by the - * embedding. - */ - JS_PUBLIC_API(void) dump(); -}; - -extern JS_PUBLIC_API(void) -JS_HoldPrincipals(JSPrincipals *principals); - -extern JS_PUBLIC_API(void) -JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals); - -struct JSSecurityCallbacks { - JSCheckAccessOp checkObjectAccess; - JSCSPEvalChecker contentSecurityPolicyAllows; - JSSubsumesOp subsumes; -}; - -extern JS_PUBLIC_API(void) -JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks); - -extern JS_PUBLIC_API(const JSSecurityCallbacks *) -JS_GetSecurityCallbacks(JSRuntime *rt); - -/* - * Code running with "trusted" principals will be given a deeper stack - * allocation than ordinary scripts. This allows trusted script to run after - * untrusted script has exhausted the stack. This function sets the - * runtime-wide trusted principal. - * - * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since - * there is no available JSContext. Instead, the caller must ensure that the - * given principals stays valid for as long as 'rt' may point to it. If the - * principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be - * called again, passing nullptr for 'prin'. - */ -extern JS_PUBLIC_API(void) -JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin); - -/* - * Initialize the callback that is called to destroy JSPrincipals instance - * when its reference counter drops to zero. The initialization can be done - * only once per JS runtime. - */ -extern JS_PUBLIC_API(void) -JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals); - -/************************************************************************/ - /* * Functions and scripts. */ extern JS_PUBLIC_API(JSFunction *) JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, - JSObject *parent, const char *name); + JS::Handle parent, const char *name); /* * Create the function with the name given by the id. JSID_IS_STRING(id) must @@ -3233,12 +3339,13 @@ JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, */ extern JS_PUBLIC_API(JSFunction *) JS_NewFunctionById(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, - JSObject *parent, jsid id); + JS::Handle parent, JS::Handle id); namespace JS { extern JS_PUBLIC_API(JSFunction *) -GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, jsid id, unsigned nargs); +GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, JS::Handle id, + unsigned nargs); } /* namespace JS */ @@ -3295,22 +3402,22 @@ JS_IsConstructor(JSFunction *fun); * If |callable| is not callable, will throw and return nullptr. */ extern JS_PUBLIC_API(JSObject*) -JS_BindCallable(JSContext *cx, JSObject *callable, JSObject *newThis); +JS_BindCallable(JSContext *cx, JS::Handle callable, JS::Handle newThis); extern JS_PUBLIC_API(bool) -JS_DefineFunctions(JSContext *cx, JSObject *obj, const JSFunctionSpec *fs); +JS_DefineFunctions(JSContext *cx, JS::Handle obj, const JSFunctionSpec *fs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call, +JS_DefineFunction(JSContext *cx, JS::Handle obj, const char *name, JSNative call, unsigned nargs, unsigned attrs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineUCFunction(JSContext *cx, JSObject *obj, +JS_DefineUCFunction(JSContext *cx, JS::Handle obj, const jschar *name, size_t namelen, JSNative call, unsigned nargs, unsigned attrs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call, +JS_DefineFunctionById(JSContext *cx, JS::Handle obj, JS::Handle id, JSNative call, unsigned nargs, unsigned attrs); /* @@ -3318,7 +3425,7 @@ JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call, * fail if funobj was lexically nested inside some other function. */ extern JS_PUBLIC_API(JSObject *) -JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent); +JS_CloneFunctionObject(JSContext *cx, JS::Handle funobj, JS::Handle parent); /* * Given a buffer, return false if the buffer might become a valid @@ -3328,32 +3435,49 @@ JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent); * the compiler. */ extern JS_PUBLIC_API(bool) -JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj, const char *utf8, size_t length); +JS_BufferIsCompilableUnit(JSContext *cx, JS::Handle obj, const char *utf8, + size_t length); -extern JS_PUBLIC_API(JSScript *) +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileScript(JSContext *cx, JS::HandleObject obj, const char *ascii, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileUCScript(JSContext *cx, JS::HandleObject obj, const jschar *chars, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleScript script); extern JS_PUBLIC_API(JSObject *) JS_GetGlobalFromScript(JSScript *script); -extern JS_PUBLIC_API(JSFunction *) +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileFunction(JSContext *cx, JS::HandleObject obj, const char *name, unsigned nargs, const char *const *argnames, const char *bytes, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); -extern JS_PUBLIC_API(JSFunction *) +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileUCFunction(JSContext *cx, JS::HandleObject obj, const char *name, unsigned nargs, const char *const *argnames, const jschar *chars, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); namespace JS { @@ -3401,12 +3525,14 @@ namespace JS { * is protected anyway); instead, create instances only of the derived classes: * CompileOptions and OwningCompileOptions. */ -class JS_PUBLIC_API(ReadOnlyCompileOptions) +class JS_FRIEND_API(ReadOnlyCompileOptions) { + friend class CompileOptions; + protected: - JSPrincipals *principals_; JSPrincipals *originPrincipals_; const char *filename_; + const char *introducerFilename_; const jschar *sourceMapURL_; // This constructor leaves 'version' set to JSVERSION_UNKNOWN. The structure @@ -3414,9 +3540,9 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) // classes' constructors take care of that, in ways appropriate to their // purpose. ReadOnlyCompileOptions() - : principals_(nullptr), - originPrincipals_(nullptr), + : originPrincipals_(nullptr), filename_(nullptr), + introducerFilename_(nullptr), sourceMapURL_(nullptr), version(JSVERSION_UNKNOWN), versionSet(false), @@ -3425,6 +3551,7 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) column(0), compileAndGo(false), forEval(false), + defineOnScope(true), noScriptRval(false), selfHostingMode(false), canLazilyParse(true), @@ -3433,7 +3560,12 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) werrorOption(false), asmJSOption(false), forceAsync(false), - sourcePolicy(SAVE_SOURCE) + installedFile(false), + sourceIsLazy(false), + introductionType(nullptr), + introductionLineno(0), + introductionOffset(0), + hasIntroductionInfo(false) { } // Set all POD options (those not requiring reference counts, copies, @@ -3443,12 +3575,13 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) public: // Read-only accessors for non-POD options. The proper way to set these // depends on the derived type. - JSPrincipals *principals() const { return principals_; } - JSPrincipals *originPrincipals() const; + JSPrincipals *originPrincipals(js::ExclusiveContext *cx) const; const char *filename() const { return filename_; } + const char *introducerFilename() const { return introducerFilename_; } const jschar *sourceMapURL() const { return sourceMapURL_; } virtual JSObject *element() const = 0; - virtual JSString *elementProperty() const = 0; + virtual JSString *elementAttributeName() const = 0; + virtual JSScript *introductionScript() const = 0; // POD options. JSVersion version; @@ -3458,6 +3591,7 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) unsigned column; bool compileAndGo; bool forEval; + bool defineOnScope; bool noScriptRval; bool selfHostingMode; bool canLazilyParse; @@ -3466,11 +3600,15 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) bool werrorOption; bool asmJSOption; bool forceAsync; - enum SourcePolicy { - NO_SOURCE, - LAZY_SOURCE, - SAVE_SOURCE - } sourcePolicy; + bool installedFile; // 'true' iff pre-compiling js file in packaged app + bool sourceIsLazy; + + // |introductionType| is a statically allocated C string: + // one of "eval", "Function", or "GeneratorFunction". + const char *introductionType; + unsigned introductionLineno; + uint32_t introductionOffset; + bool hasIntroductionInfo; private: static JSObject * const nullObjectPtr; @@ -3490,11 +3628,12 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) * comes to refer to the object that owns this, then the whole cycle, and * anything else it entrains, will never be freed. */ -class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions +class JS_FRIEND_API(OwningCompileOptions) : public ReadOnlyCompileOptions { JSRuntime *runtime; PersistentRootedObject elementRoot; - PersistentRootedString elementPropertyRoot; + PersistentRootedString elementAttributeNameRoot; + PersistentRootedScript introductionScriptRoot; public: // A minimal constructor, for use with OwningCompileOptions::copy. This @@ -3505,22 +3644,30 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions ~OwningCompileOptions(); JSObject *element() const MOZ_OVERRIDE { return elementRoot; } - JSString *elementProperty() const MOZ_OVERRIDE { return elementPropertyRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } // Set this to a copy of |rhs|. Return false on OOM. bool copy(JSContext *cx, const ReadOnlyCompileOptions &rhs); /* These setters make copies of their string arguments, and are fallible. */ + bool setFile(JSContext *cx, const char *f); bool setFileAndLine(JSContext *cx, const char *f, unsigned l); bool setSourceMapURL(JSContext *cx, const jschar *s); + bool setIntroducerFilename(JSContext *cx, const char *s); /* These setters are infallible, and can be chained. */ - OwningCompileOptions &setElement(JSObject *e) { elementRoot = e; return *this; } - OwningCompileOptions &setElementProperty(JSString *p) { elementPropertyRoot = p; return *this; } - OwningCompileOptions &setPrincipals(JSPrincipals *p) { - if (p) JS_HoldPrincipals(p); - if (principals_) JS_DropPrincipals(runtime, principals_); - principals_ = p; + OwningCompileOptions &setLine(unsigned l) { lineno = l; return *this; } + OwningCompileOptions &setElement(JSObject *e) { + elementRoot = e; + return *this; + } + OwningCompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + OwningCompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; return *this; } OwningCompileOptions &setOriginPrincipals(JSPrincipals *p) { @@ -3538,10 +3685,27 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions OwningCompileOptions &setColumn(unsigned c) { column = c; return *this; } OwningCompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } OwningCompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + OwningCompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } OwningCompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } OwningCompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } OwningCompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } - OwningCompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; } + OwningCompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + OwningCompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + bool setIntroductionInfo(JSContext *cx, const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + if (!setIntroducerFilename(cx, introducerFn)) + return false; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return true; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; }; /* @@ -3551,36 +3715,47 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions * create an instance of this type, it's up to you to guarantee that * everything you store in it will outlive it. */ -class MOZ_STACK_CLASS JS_PUBLIC_API(CompileOptions) : public ReadOnlyCompileOptions +class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOptions { RootedObject elementRoot; - RootedString elementPropertyRoot; + RootedString elementAttributeNameRoot; + RootedScript introductionScriptRoot; public: explicit CompileOptions(JSContext *cx, JSVersion version = JSVERSION_UNKNOWN); CompileOptions(js::ContextFriendFields *cx, const ReadOnlyCompileOptions &rhs) - : ReadOnlyCompileOptions(), elementRoot(cx), elementPropertyRoot(cx) + : ReadOnlyCompileOptions(), elementRoot(cx), elementAttributeNameRoot(cx), + introductionScriptRoot(cx) { copyPODOptions(rhs); - principals_ = rhs.principals(); - originPrincipals_ = rhs.originPrincipals(); + originPrincipals_ = rhs.originPrincipals_; filename_ = rhs.filename(); sourceMapURL_ = rhs.sourceMapURL(); elementRoot = rhs.element(); - elementPropertyRoot = rhs.elementProperty(); + elementAttributeNameRoot = rhs.elementAttributeName(); + introductionScriptRoot = rhs.introductionScript(); } JSObject *element() const MOZ_OVERRIDE { return elementRoot; } - JSString *elementProperty() const MOZ_OVERRIDE { return elementPropertyRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } + CompileOptions &setFile(const char *f) { filename_ = f; return *this; } + CompileOptions &setLine(unsigned l) { lineno = l; return *this; } CompileOptions &setFileAndLine(const char *f, unsigned l) { filename_ = f; lineno = l; return *this; } CompileOptions &setSourceMapURL(const jschar *s) { sourceMapURL_ = s; return *this; } CompileOptions &setElement(JSObject *e) { elementRoot = e; return *this; } - CompileOptions &setElementProperty(JSString *p) { elementPropertyRoot = p; return *this; } - CompileOptions &setPrincipals(JSPrincipals *p) { principals_ = p; return *this; } + CompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + CompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; + return *this; + } CompileOptions &setOriginPrincipals(JSPrincipals *p) { originPrincipals_ = p; return *this; @@ -3594,25 +3769,50 @@ class MOZ_STACK_CLASS JS_PUBLIC_API(CompileOptions) : public ReadOnlyCompileOpti CompileOptions &setColumn(unsigned c) { column = c; return *this; } CompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } CompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + CompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } CompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } CompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } CompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } - CompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; } + CompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + CompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + CompileOptions &setIntroductionInfo(const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + introducerFilename_ = introducerFn; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return *this; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; }; -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *bytes, size_t length); +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const jschar *chars, size_t length); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, FILE *file); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, const char *filename); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, FILE *file, + JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *filename, + JS::MutableHandleScript script); extern JS_PUBLIC_API(bool) CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t length); @@ -3625,8 +3825,8 @@ CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t * for the compilation. The callback will be invoked while off the main thread, * so must ensure that its operations are thread safe. Afterwards, * FinishOffThreadScript must be invoked on the main thread to get the result - * script or nullptr. If maybecx is specified, this method will also report - * any error or warnings generated during the parse. + * script or nullptr. If maybecx is not specified, the resources will be freed, + * but no script will be returned. * * The characters passed in to CompileOffThread must remain live until the * callback is invoked, and the resulting script will be rooted until the call @@ -3634,27 +3834,32 @@ CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t */ extern JS_PUBLIC_API(bool) -CompileOffThread(JSContext *cx, Handle obj, const ReadOnlyCompileOptions &options, +CompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, const jschar *chars, size_t length, OffThreadCompileCallback callback, void *callbackData); extern JS_PUBLIC_API(JSScript *) FinishOffThreadScript(JSContext *maybecx, JSRuntime *rt, void *token); -extern JS_PUBLIC_API(JSFunction *) -CompileFunction(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *name, unsigned nargs, const char *const *argnames, - const char *bytes, size_t length); + SourceBufferHolder &srcBuf, JS::MutableHandleFunction fun); -extern JS_PUBLIC_API(JSFunction *) -CompileFunction(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *name, unsigned nargs, const char *const *argnames, + const char *bytes, size_t length, JS::MutableHandleFunction fun); + +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *name, unsigned nargs, const char *const *argnames, - const jschar *chars, size_t length); + const jschar *chars, size_t length, JS::MutableHandleFunction fun); } /* namespace JS */ extern JS_PUBLIC_API(JSString *) -JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned indent); +JS_DecompileScript(JSContext *cx, JS::Handle script, const char *name, unsigned indent); /* * API extension: OR this into indent to avoid pretty-printing the decompiled @@ -3663,10 +3868,10 @@ JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned i #define JS_DONT_PRETTY_PRINT ((unsigned)0x8000) extern JS_PUBLIC_API(JSString *) -JS_DecompileFunction(JSContext *cx, JSFunction *fun, unsigned indent); +JS_DecompileFunction(JSContext *cx, JS::Handle fun, unsigned indent); extern JS_PUBLIC_API(JSString *) -JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, unsigned indent); +JS_DecompileFunctionBody(JSContext *cx, JS::Handle fun, unsigned indent); /* * NB: JS_ExecuteScript and the JS_Evaluate*Script* quadruplets use the obj @@ -3702,158 +3907,159 @@ JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, unsigned indent); * etc., entry points. */ extern JS_PUBLIC_API(bool) -JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval); +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval, - JSVersion version); +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script); + +namespace JS { /* - * Execute either the function-defining prolog of a script, or the script's - * main body, but not both. + * Like the above, but handles a cross-compartment script. If the script is + * cross-compartment, it is cloned into the current compartment before executing. */ -typedef enum JSExecPart { JSEXEC_PROLOG, JSEXEC_MAIN } JSExecPart; +extern JS_PUBLIC_API(bool) +CloneAndExecuteScript(JSContext *cx, JS::Handle obj, JS::Handle script); + +} /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_EvaluateScript(JSContext *cx, JSObject *obj, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleValue rval, JSVersion version); + +extern JS_PUBLIC_API(bool) +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JSVersion version); extern JS_PUBLIC_API(bool) -JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_EvaluateScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno); extern JS_PUBLIC_API(bool) -JS_EvaluateUCScript(JSContext *cx, JSObject *obj, +JS_EvaluateUCScript(JSContext *cx, JS::Handle obj, const jschar *chars, unsigned length, const char *filename, unsigned lineno, - jsval *rval); + JS::MutableHandle rval); + +namespace JS { extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleValue rval); -/* - * JSAPI clients may optionally specify the 'originPrincipals' of a script. - * A script's originPrincipals may be retrieved through the debug API (via - * JS_GetScriptOriginPrincipals) and the originPrincipals are transitively - * assigned to any nested scripts (including scripts dynamically created via - * eval and the Function constructor). If originPrincipals is null, then the - * value of principals is used as origin principals for the script. - */ extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipalsVersionOrigin(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - JSPrincipals *originPrincipals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleValue rval); -namespace JS { +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const jschar *chars, size_t length, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *bytes, size_t length, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *filename, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename); } /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunction(JSContext *cx, JS::HandleObject obj, JS::HandleFunction fun, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunctionName(JSContext *cx, JS::HandleObject obj, const char *name, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunctionValue(JSContext *cx, JS::HandleObject obj, JS::HandleValue fval, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); namespace JS { static inline bool -Call(JSContext *cx, JSObject *thisObj, JSFunction *fun, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleFunction fun, + const JS::HandleValueArray &args, MutableHandleValue rval) { - return !!JS_CallFunction(cx, thisObj, fun, argc, argv, rval.address()); + return !!JS_CallFunction(cx, thisObj, fun, args, rval); } static inline bool -Call(JSContext *cx, JSObject *thisObj, const char *name, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, const char *name, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return !!JS_CallFunctionName(cx, thisObj, name, argc, argv, rval.address()); + return !!JS_CallFunctionName(cx, thisObj, name, args, rval); } static inline bool -Call(JSContext *cx, JSObject *thisObj, jsval fun, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return !!JS_CallFunctionValue(cx, thisObj, fun, argc, argv, rval.address()); + return !!JS_CallFunctionValue(cx, thisObj, fun, args, rval); } extern JS_PUBLIC_API(bool) -Call(JSContext *cx, jsval thisv, jsval fun, unsigned argc, jsval *argv, MutableHandle rval); +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval); static inline bool -Call(JSContext *cx, jsval thisv, JSObject *funObj, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleObject funObj, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return Call(cx, thisv, OBJECT_TO_JSVAL(funObj), argc, argv, rval); + JS_ASSERT(funObj); + JS::RootedValue fun(cx, JS::ObjectValue(*funObj)); + return Call(cx, thisv, fun, args, rval); } +extern JS_PUBLIC_API(bool) +Construct(JSContext *cx, JS::HandleValue fun, + const JS::HandleValueArray& args, + MutableHandleValue rval); + } /* namespace JS */ /* - * These functions allow setting an operation callback that will be called + * These functions allow setting an interrupt callback that will be called * from the JS thread some time after any thread triggered the callback using - * JS_TriggerOperationCallback(rt). + * JS_RequestInterruptCallback(rt). * * To schedule the GC and for other activities the engine internally triggers - * operation callbacks. The embedding should thus not rely on callbacks being + * interrupt callbacks. The embedding should thus not rely on callbacks being * triggered through the external API only. * * Important note: Additional callbacks can occur inside the callback handler * if it re-enters the JS engine. The embedding must ensure that the callback * is disconnected before attempting such re-entry. */ -extern JS_PUBLIC_API(JSOperationCallback) -JS_SetOperationCallback(JSRuntime *rt, JSOperationCallback callback); +extern JS_PUBLIC_API(JSInterruptCallback) +JS_SetInterruptCallback(JSRuntime *rt, JSInterruptCallback callback); -extern JS_PUBLIC_API(JSOperationCallback) -JS_GetOperationCallback(JSRuntime *rt); +extern JS_PUBLIC_API(JSInterruptCallback) +JS_GetInterruptCallback(JSRuntime *rt); extern JS_PUBLIC_API(void) -JS_TriggerOperationCallback(JSRuntime *rt); +JS_RequestInterruptCallback(JSRuntime *rt); extern JS_PUBLIC_API(bool) JS_IsRunning(JSContext *cx); @@ -3878,7 +4084,7 @@ JS_RestoreFrameChain(JSContext *cx); #ifdef MOZ_TRACE_JSCALLS /* * The callback is expected to be quick and noninvasive. It should not - * trigger interrupts, turn on debugging, or produce uncaught JS + * request interrupts, turn on debugging, or produce uncaught JS * exceptions. The state of the stack and registers in the context * cannot be relied upon, since this callback may be invoked directly * from either JIT. The 'entering' field means we are entering a @@ -3953,15 +4159,16 @@ JS_FileEscapedString(FILE *fp, JSString *str, char quote); * special cases where getting the chars is infallible: * * The first case is interned strings, i.e., strings from JS_InternString or - * JSID_TO_STRING(id), using JS_GetInternedStringChars*. + * JSID_TO_STRING(id), using JS_GetLatin1InternedStringChars or + * JS_GetTwoByteInternedStringChars. * * The second case is "flat" strings that have been explicitly prepared in a * fallible context by JS_FlattenString. To catch errors, a separate opaque * JSFlatString type is returned by JS_FlattenString and expected by * JS_GetFlatStringChars. Note, though, that this is purely a syntactic * distinction: the input and output of JS_FlattenString are the same actual - * GC-thing so only one needs to be rooted. If a JSString is known to be flat, - * JS_ASSERT_STRING_IS_FLAT can be used to make a debug-checked cast. Example: + * GC-thing. If a JSString is known to be flat, JS_ASSERT_STRING_IS_FLAT can be + * used to make a debug-checked cast. Example: * * // in a fallible context * JSFlatString *fstr = JS_FlattenString(cx, str); @@ -3970,55 +4177,80 @@ JS_FileEscapedString(FILE *fp, JSString *str, char quote); * JS_ASSERT(fstr == JS_ASSERT_STRING_IS_FLAT(str)); * * // in an infallible context, for the same 'str' - * const jschar *chars = JS_GetFlatStringChars(fstr) + * AutoCheckCannotGC nogc; + * const jschar *chars = JS_GetTwoByteFlatStringChars(nogc, fstr) * JS_ASSERT(chars); * - * The CharsZ APIs guarantee that the returned array has a null character at - * chars[length]. This can require additional copying so clients should prefer - * APIs without CharsZ if possible. The infallible functions also return - * null-terminated arrays. (There is no additional cost or non-Z alternative - * for the infallible functions, so 'Z' is left out of the identifier.) + * Flat strings and interned strings are always null-terminated, so + * JS_FlattenString can be used to get a null-terminated string. + * + * Additionally, string characters are stored as either Latin1Char (8-bit) + * or jschar (16-bit). Clients can use JS_StringHasLatin1Chars and can then + * call either the Latin1* or TwoByte* functions. Some functions like + * JS_CopyStringChars and JS_GetStringCharAt accept both Latin1 and TwoByte + * strings. */ extern JS_PUBLIC_API(size_t) JS_GetStringLength(JSString *str); -extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsAndLength(JSContext *cx, JSString *str, size_t *length); +extern JS_PUBLIC_API(bool) +JS_StringIsFlat(JSString *str); -extern JS_PUBLIC_API(const jschar *) -JS_GetInternedStringChars(JSString *str); +/* Returns true iff the string's characters are stored as Latin1. */ +extern JS_PUBLIC_API(bool) +JS_StringHasLatin1Chars(JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1StringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); extern JS_PUBLIC_API(const jschar *) -JS_GetInternedStringCharsAndLength(JSString *str, size_t *length); +JS_GetTwoByteStringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); + +extern JS_PUBLIC_API(bool) +JS_GetStringCharAt(JSContext *cx, JSString *str, size_t index, jschar *res); + +extern JS_PUBLIC_API(jschar) +JS_GetFlatStringCharAt(JSFlatString *str, size_t index); extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsZ(JSContext *cx, JSString *str); +JS_GetTwoByteExternalStringChars(JSString *str); + +extern JS_PUBLIC_API(bool) +JS_CopyStringChars(JSContext *cx, mozilla::Range dest, JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1InternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsZAndLength(JSContext *cx, JSString *str, size_t *length); +JS_GetTwoByteInternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); extern JS_PUBLIC_API(JSFlatString *) JS_FlattenString(JSContext *cx, JSString *str); +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1FlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); + extern JS_PUBLIC_API(const jschar *) -JS_GetFlatStringChars(JSFlatString *str); +JS_GetTwoByteFlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); -static JS_ALWAYS_INLINE JSFlatString * +static MOZ_ALWAYS_INLINE JSFlatString * JSID_TO_FLAT_STRING(jsid id) { JS_ASSERT(JSID_IS_STRING(id)); return (JSFlatString *)(JSID_BITS(id)); } -static JS_ALWAYS_INLINE JSFlatString * +static MOZ_ALWAYS_INLINE JSFlatString * JS_ASSERT_STRING_IS_FLAT(JSString *str) { - JS_ASSERT(JS_GetFlatStringChars((JSFlatString *)str)); + JS_ASSERT(JS_StringIsFlat(str)); return (JSFlatString *)str; } -static JS_ALWAYS_INLINE JSString * +static MOZ_ALWAYS_INLINE JSString * JS_FORGET_STRING_FLATNESS(JSFlatString *fstr) { return (JSString *)fstr; @@ -4078,7 +4310,7 @@ JS_EncodeString(JSContext *cx, JSString *str); * Same behavior as JS_EncodeString(), but encode into UTF-8 string */ JS_PUBLIC_API(char *) -JS_EncodeStringToUTF8(JSContext *cx, JSString *str); +JS_EncodeStringToUTF8(JSContext *cx, JS::HandleString str); /* * Get number of bytes in the string encoding (without accounting for a @@ -4110,7 +4342,7 @@ class JSAutoByteString MOZ_GUARD_OBJECT_NOTIFIER_INIT; } - JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + explicit JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) : mBytes(nullptr) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -4135,7 +4367,7 @@ class JSAutoByteString char *encodeLatin1(js::ExclusiveContext *cx, JSString *str); - char *encodeUtf8(JSContext *cx, JSString *str) { + char *encodeUtf8(JSContext *cx, JS::HandleString str) { JS_ASSERT(!mBytes); JS_ASSERT(cx); mBytes = JS_EncodeStringToUTF8(cx, str); @@ -4170,6 +4402,84 @@ class JSAutoByteString JSAutoByteString &operator=(const JSAutoByteString &another); }; +namespace JS { + +extern JS_PUBLIC_API(JSAddonId *) +NewAddonId(JSContext *cx, JS::HandleString str); + +extern JS_PUBLIC_API(JSString *) +StringOfAddonId(JSAddonId *id); + +extern JS_PUBLIC_API(JSAddonId *) +AddonIdOfObject(JSObject *obj); + +} // namespace JS + +/************************************************************************/ +/* + * Symbols + */ + +namespace JS { + +/* + * Create a new Symbol with the given description. This function never returns + * a Symbol that is in the Runtime-wide symbol registry. + * + * If description is null, the new Symbol's [[Description]] attribute is + * undefined. + */ +JS_PUBLIC_API(Symbol *) +NewSymbol(JSContext *cx, HandleString description); + +/* + * Symbol.for as specified in ES6. + * + * Get a Symbol with the description 'key' from the Runtime-wide symbol registry. + * If there is not already a Symbol with that description in the registry, a new + * Symbol is created and registered. 'key' must not be null. + */ +JS_PUBLIC_API(Symbol *) +GetSymbolFor(JSContext *cx, HandleString key); + +/* + * Get the [[Description]] attribute of the given symbol. + * + * This function is infallible. If it returns null, that means the symbol's + * [[Description]] is undefined. + */ +JS_PUBLIC_API(JSString *) +GetSymbolDescription(HandleSymbol symbol); + +/* Well-known symbols. */ +MOZ_BEGIN_ENUM_CLASS(SymbolCode, uint32_t) + iterator, // well-known Symbol.iterator + InSymbolRegistry = 0xfffffffe, // created by Symbol.for() or JS::GetSymbolFor() + UniqueSymbol = 0xffffffff // created by Symbol() or JS::NewSymbol() +MOZ_END_ENUM_CLASS(SymbolCode) + +/* For use in loops that iterate over the well-known symbols. */ +const size_t WellKnownSymbolLimit = 1; + +/* + * Return the SymbolCode telling what sort of symbol `symbol` is. + * + * A symbol's SymbolCode never changes once it is created. + */ +JS_PUBLIC_API(SymbolCode) +GetSymbolCode(Handle symbol); + +/* + * Get one of the well-known symbols defined by ES6. A single set of well-known + * symbols is shared by all compartments in a JSRuntime. + * + * `which` must be in the range [0, WellKnownSymbolLimit). + */ +JS_PUBLIC_API(Symbol *) +GetWellKnownSymbol(JSContext *cx, SymbolCode which); + +} /* namespace JS */ + /************************************************************************/ /* * JSON functions @@ -4189,10 +4499,17 @@ JS_Stringify(JSContext *cx, JS::MutableHandleValue value, JS::HandleObject repla JS_PUBLIC_API(bool) JS_ParseJSON(JSContext *cx, const jschar *chars, uint32_t len, JS::MutableHandleValue vp); +JS_PUBLIC_API(bool) +JS_ParseJSON(JSContext *cx, JS::HandleString str, JS::MutableHandleValue vp); + JS_PUBLIC_API(bool) JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32_t len, JS::HandleValue reviver, JS::MutableHandleValue vp); +JS_PUBLIC_API(bool) +JS_ParseJSONWithReviver(JSContext *cx, JS::HandleString str, JS::HandleValue reviver, + JS::MutableHandleValue vp); + /************************************************************************/ /* @@ -4219,7 +4536,6 @@ struct JSLocaleCallbacks { JSLocaleToLowerCase localeToLowerCase; JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API JSLocaleToUnicode localeToUnicode; - JSErrorCallback localeGetErrorMessage; }; /* @@ -4357,8 +4673,35 @@ JS_GetErrorReporter(JSContext *cx); extern JS_PUBLIC_API(JSErrorReporter) JS_SetErrorReporter(JSContext *cx, JSErrorReporter er); +namespace JS { + +extern JS_PUBLIC_API(bool) +CreateError(JSContext *cx, JSExnType type, HandleString stack, + HandleString fileName, uint32_t lineNumber, uint32_t columnNumber, + JSErrorReport *report, HandleString message, MutableHandleValue rval); + /************************************************************************/ +/* + * Weak Maps. + */ + +extern JS_PUBLIC_API(JSObject *) +NewWeakMapObject(JSContext *cx); + +extern JS_PUBLIC_API(bool) +IsWeakMapObject(JSObject *obj); + +extern JS_PUBLIC_API(bool) +GetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::MutableHandleValue val); + +extern JS_PUBLIC_API(bool) +SetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::HandleValue val); + +} /* namespace JS */ + /* * Dates. */ @@ -4387,10 +4730,10 @@ JS_ClearDateCaches(JSContext *cx); /* * Regular Expressions. */ -#define JSREG_FOLD 0x01 /* fold uppercase to lowercase */ -#define JSREG_GLOB 0x02 /* global exec, creates array of matches */ -#define JSREG_MULTILINE 0x04 /* treat ^ and $ as begin and end of line */ -#define JSREG_STICKY 0x08 /* only match starting at lastIndex */ +#define JSREG_FOLD 0x01u /* fold uppercase to lowercase */ +#define JSREG_GLOB 0x02u /* global exec, creates array of matches */ +#define JSREG_MULTILINE 0x04u /* treat ^ and $ as begin and end of line */ +#define JSREG_STICKY 0x08u /* only match starting at lastIndex */ extern JS_PUBLIC_API(JSObject *) JS_NewRegExpObject(JSContext *cx, JS::HandleObject obj, char *bytes, size_t length, @@ -4400,11 +4743,11 @@ extern JS_PUBLIC_API(JSObject *) JS_NewUCRegExpObject(JSContext *cx, JS::HandleObject obj, jschar *chars, size_t length, unsigned flags); -extern JS_PUBLIC_API(void) +extern JS_PUBLIC_API(bool) JS_SetRegExpInput(JSContext *cx, JS::HandleObject obj, JS::HandleString input, bool multiline); -extern JS_PUBLIC_API(void) +extern JS_PUBLIC_API(bool) JS_ClearRegExpStatics(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) @@ -4450,17 +4793,62 @@ JS_ClearPendingException(JSContext *cx); extern JS_PUBLIC_API(bool) JS_ReportPendingException(JSContext *cx); +namespace JS { + /* - * Save the current exception state. This takes a snapshot of cx's current - * exception state without making any change to that state. + * Save and later restore the current exception state of a given JSContext. + * This is useful for implementing behavior in C++ that's like try/catch + * or try/finally in JS. * - * The returned state pointer MUST be passed later to JS_RestoreExceptionState - * (to restore that saved state, overriding any more recent state) or else to - * JS_DropExceptionState (to free the state struct in case it is not correct - * or desirable to restore it). Both Restore and Drop free the state struct, - * so callers must stop using the pointer returned from Save after calling the - * Release or Drop API. + * Typical usage: + * + * bool ok = JS_EvaluateScript(cx, ...); + * AutoSaveExceptionState savedExc(cx); + * ... cleanup that might re-enter JS ... + * return ok; */ +class JS_PUBLIC_API(AutoSaveExceptionState) +{ + private: + JSContext *context; + bool wasPropagatingForcedReturn; + bool wasThrowing; + RootedValue exceptionValue; + + public: + /* + * Take a snapshot of cx's current exception state. Then clear any current + * pending exception in cx. + */ + explicit AutoSaveExceptionState(JSContext *cx); + + /* + * If neither drop() nor restore() was called, restore the exception + * state only if no exception is currently pending on cx. + */ + ~AutoSaveExceptionState(); + + /* + * Discard any stored exception state. + * If this is called, the destructor is a no-op. + */ + void drop() { + wasPropagatingForcedReturn = false; + wasThrowing = false; + exceptionValue.setUndefined(); + } + + /* + * Replace cx's exception state with the stored exception state. Then + * discard the stored exception state. If this is called, the + * destructor is a no-op. + */ + void restore(); +}; + +} /* namespace JS */ + +/* Deprecated API. Use AutoSaveExceptionState instead. */ extern JS_PUBLIC_API(JSExceptionState *) JS_SaveExceptionState(JSContext *cx); @@ -4471,22 +4859,14 @@ extern JS_PUBLIC_API(void) JS_DropExceptionState(JSContext *cx, JSExceptionState *state); /* - * If the given value is an exception object that originated from an error, - * the exception will contain an error report struct, and this API will return - * the address of that struct. Otherwise, it returns nullptr. The lifetime + * If the given object is an exception object, the exception will have (or be + * able to lazily create) an error report struct, and this function will return + * the address of that struct. Otherwise, it returns nullptr. The lifetime * of the error report struct that might be returned is the same as the * lifetime of the exception object. */ extern JS_PUBLIC_API(JSErrorReport *) -JS_ErrorFromException(JSContext *cx, JS::HandleValue v); - -/* - * Given a reported error's message and JSErrorReport struct pointer, throw - * the corresponding exception on cx. - */ -extern JS_PUBLIC_API(bool) -JS_ThrowReportedError(JSContext *cx, const char *message, - JSErrorReport *reportp); +JS_ErrorFromException(JSContext *cx, JS::HandleObject obj); /* * Throws a StopIteration exception on cx. @@ -4521,7 +4901,7 @@ JS_AbortIfWrongThread(JSRuntime *rt); * [[Prototype]]. */ extern JS_PUBLIC_API(JSObject *) -JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const jsval *vp); +JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const JS::CallArgs& args); /************************************************************************/ @@ -4536,16 +4916,18 @@ JS_ScheduleGC(JSContext *cx, uint32_t count); #endif extern JS_PUBLIC_API(void) -JS_SetParallelParsingEnabled(JSContext *cx, bool enabled); +JS_SetParallelParsingEnabled(JSRuntime *rt, bool enabled); extern JS_PUBLIC_API(void) -JS_SetParallelIonCompilationEnabled(JSContext *cx, bool enabled); +JS_SetOffthreadIonCompilationEnabled(JSRuntime *rt, bool enabled); -#define JIT_COMPILER_OPTIONS(Register) \ - Register(BASELINE_USECOUNT_TRIGGER, "baseline.usecount.trigger") \ - Register(ION_USECOUNT_TRIGGER, "ion.usecount.trigger") \ - Register(ION_ENABLE, "ion.enable") \ - Register(BASELINE_ENABLE, "baseline.enable") +#define JIT_COMPILER_OPTIONS(Register) \ + Register(BASELINE_USECOUNT_TRIGGER, "baseline.usecount.trigger") \ + Register(ION_USECOUNT_TRIGGER, "ion.usecount.trigger") \ + Register(ION_ENABLE, "ion.enable") \ + Register(BASELINE_ENABLE, "baseline.enable") \ + Register(OFFTHREAD_COMPILATION_ENABLE, "offthread-compilation.enable") \ + Register(SIGNALS_ENABLE, "signals.enable") typedef enum JSJitCompilerOption { #define JIT_COMPILER_DECLARE(key, str) \ @@ -4558,7 +4940,9 @@ typedef enum JSJitCompilerOption { } JSJitCompilerOption; extern JS_PUBLIC_API(void) -JS_SetGlobalJitCompilerOption(JSContext *cx, JSJitCompilerOption opt, uint32_t value); +JS_SetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt, uint32_t value); +extern JS_PUBLIC_API(int) +JS_GetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt); /* * Convert a uint32_t index into a jsid. @@ -4580,13 +4964,80 @@ JS_CharsToId(JSContext* cx, JS::TwoByteChars chars, JS::MutableHandleId); extern JS_PUBLIC_API(bool) JS_IsIdentifier(JSContext *cx, JS::HandleString str, bool *isIdentifier); +namespace JS { + +/* + * AutoFilename encapsulates a pointer to a C-string and keeps the C-string + * alive for as long as the associated AutoFilename object is alive. + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(AutoFilename) +{ + void *scriptSource_; + + AutoFilename(const AutoFilename &) MOZ_DELETE; + void operator=(const AutoFilename &) MOZ_DELETE; + + public: + AutoFilename() : scriptSource_(nullptr) {} + ~AutoFilename() { reset(nullptr); } + + const char *get() const; + + void reset(void *newScriptSource); +}; + /* - * Return the current script and line number of the most currently running + * Return the current filename and line number of the most currently running * frame. Returns true if a scripted frame was found, false otherwise. + * + * If a the embedding has hidden the scripted caller for the topmost activation + * record, this will also return false. */ extern JS_PUBLIC_API(bool) -JS_DescribeScriptedCaller(JSContext *cx, JS::MutableHandleScript script, unsigned *lineno); +DescribeScriptedCaller(JSContext *cx, AutoFilename *filename = nullptr, + unsigned *lineno = nullptr); +extern JS_PUBLIC_API(JSObject *) +GetScriptedCallerGlobal(JSContext *cx); + +/* + * Informs the JS engine that the scripted caller should be hidden. This can be + * used by the embedding to maintain an override of the scripted caller in its + * calculations, by hiding the scripted caller in the JS engine and pushing data + * onto a separate stack, which it inspects when DescribeScriptedCaller returns + * null. + * + * We maintain a counter on each activation record. Add() increments the counter + * of the topmost activation, and Remove() decrements it. The count may never + * drop below zero, and must always be exactly zero when the activation is + * popped from the stack. + */ +extern JS_PUBLIC_API(void) +HideScriptedCaller(JSContext *cx); + +extern JS_PUBLIC_API(void) +UnhideScriptedCaller(JSContext *cx); + +class AutoHideScriptedCaller +{ + public: + explicit AutoHideScriptedCaller(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mContext(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + HideScriptedCaller(mContext); + } + ~AutoHideScriptedCaller() { + UnhideScriptedCaller(mContext); + } + + protected: + JSContext *mContext; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +} /* namespace JS */ /* * Encode/Decode interpreted scripts and functions to/from memory. @@ -4599,12 +5050,11 @@ extern JS_PUBLIC_API(void *) JS_EncodeInterpretedFunction(JSContext *cx, JS::HandleObject funobj, uint32_t *lengthp); extern JS_PUBLIC_API(JSScript *) -JS_DecodeScript(JSContext *cx, const void *data, uint32_t length, - JSPrincipals *principals, JSPrincipals *originPrincipals); +JS_DecodeScript(JSContext *cx, const void *data, uint32_t length, JSPrincipals *originPrincipals); extern JS_PUBLIC_API(JSObject *) JS_DecodeInterpretedFunction(JSContext *cx, const void *data, uint32_t length, - JSPrincipals *principals, JSPrincipals *originPrincipals); + JSPrincipals *originPrincipals); namespace JS { @@ -4621,8 +5071,7 @@ typedef bool (* OpenAsmJSCacheEntryForReadOp)(HandleObject global, const jschar *begin, const jschar *limit, size_t *size, const uint8_t **memory, intptr_t *handle); typedef void -(* CloseAsmJSCacheEntryForReadOp)(HandleObject global, size_t size, const uint8_t *memory, - intptr_t handle); +(* CloseAsmJSCacheEntryForReadOp)(size_t size, const uint8_t *memory, intptr_t handle); /* * This callback represents a request by the JS engine to open for writing a @@ -4632,21 +5081,30 @@ typedef void * outparams. If the callback returns 'true', the JS engine guarantees a call * to CloseAsmJSCacheEntryForWriteOp passing the same base address, size and * handle. + * + * If 'installed' is true, then the cache entry is associated with a permanently + * installed JS file (e.g., in a packaged webapp). This information allows the + * embedding to store the cache entry in a installed location associated with + * the principal of 'global' where it will not be evicted until the associated + * installed JS file is removed. */ typedef bool -(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, const jschar *begin, const jschar *end, +(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, bool installed, + const jschar *begin, const jschar *end, size_t size, uint8_t **memory, intptr_t *handle); typedef void -(* CloseAsmJSCacheEntryForWriteOp)(HandleObject global, size_t size, uint8_t *memory, - intptr_t handle); +(* CloseAsmJSCacheEntryForWriteOp)(size_t size, uint8_t *memory, intptr_t handle); + +typedef js::Vector BuildIdCharVector; // Return the buildId (represented as a sequence of characters) associated with // the currently-executing build. If the JS engine is embedded such that a // single cache entry can be observed by different compiled versions of the JS // engine, it is critical that the buildId shall change for each new build of // the JS engine. + typedef bool -(* BuildIdOp)(js::Vector *buildId); +(* BuildIdOp)(BuildIdCharVector *buildId); struct AsmJSCacheOps { @@ -4660,6 +5118,132 @@ struct AsmJSCacheOps extern JS_PUBLIC_API(void) SetAsmJSCacheOps(JSRuntime *rt, const AsmJSCacheOps *callbacks); +/* + * Convenience class for imitating a JS level for-of loop. Typical usage: + * + * ForOfIterator it(cx); + * if (!it.init(iterable)) + * return false; + * RootedValue val(cx); + * while (true) { + * bool done; + * if (!it.next(&val, &done)) + * return false; + * if (done) + * break; + * if (!DoStuff(cx, val)) + * return false; + * } + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(ForOfIterator) { + protected: + JSContext *cx_; + /* + * Use the ForOfPIC on the global object (see vm/GlobalObject.h) to try + * to optimize iteration across arrays. + * + * Case 1: Regular Iteration + * iterator - pointer to the iterator object. + * index - fixed to NOT_ARRAY (== UINT32_MAX) + * + * Case 2: Optimized Array Iteration + * iterator - pointer to the array object. + * index - current position in array. + * + * The cases are distinguished by whether or not |index| is equal to NOT_ARRAY. + */ + JS::RootedObject iterator; + uint32_t index; + + static const uint32_t NOT_ARRAY = UINT32_MAX; + + ForOfIterator(const ForOfIterator &) MOZ_DELETE; + ForOfIterator &operator=(const ForOfIterator &) MOZ_DELETE; + + public: + explicit ForOfIterator(JSContext *cx) : cx_(cx), iterator(cx_), index(NOT_ARRAY) { } + + enum NonIterableBehavior { + ThrowOnNonIterable, + AllowNonIterable + }; + + /* + * Initialize the iterator. If AllowNonIterable is passed then if iterable + * does not have a callable @@iterator init() will just return true instead + * of throwing. Callers should then check valueIsIterable() before + * continuing with the iteration. + */ + bool init(JS::HandleValue iterable, + NonIterableBehavior nonIterableBehavior = ThrowOnNonIterable); + + /* + * This method assumes that |iterator| is already an iterator. It will not + * check for, and call @@iterator. Callers should make sure that the passed + * in value is in fact an iterator. + */ + bool initWithIterator(JS::HandleValue aIterator); + + /* + * Get the next value from the iterator. If false *done is true + * after this call, do not examine val. + */ + bool next(JS::MutableHandleValue val, bool *done); + + /* + * If initialized with throwOnNonCallable = false, check whether + * the value is iterable. + */ + bool valueIsIterable() const { + return iterator; + } + + private: + inline bool nextFromOptimizedArray(MutableHandleValue val, bool *done); + bool materializeArrayIterator(); +}; + + +/* + * If a large allocation fails, the JS engine may call the large-allocation- + * failure callback, if set, to allow the embedding to flush caches, possibly + * perform shrinking GCs, etc. to make some room so that the allocation will + * succeed if retried. After the callback returns, the JS engine will try to + * allocate again and may be succesful. + */ + +typedef void +(* LargeAllocationFailureCallback)(void *data); + +extern JS_PUBLIC_API(void) +SetLargeAllocationFailureCallback(JSRuntime *rt, LargeAllocationFailureCallback afc, void *data); + +/* + * Unlike the error reporter, which is only called if the exception for an OOM + * bubbles up and is not caught, the OutOfMemoryCallback is called immediately + * at the OOM site to allow the embedding to capture the current state of heap + * allocation before anything is freed. If the large-allocation-failure callback + * is called at all (not all allocation sites call the large-allocation-failure + * callback on failure), it is called before the out-of-memory callback; the + * out-of-memory callback is only called if the allocation still fails after the + * large-allocation-failure callback has returned. + */ + +typedef void +(* OutOfMemoryCallback)(JSContext *cx, void *data); + +extern JS_PUBLIC_API(void) +SetOutOfMemoryCallback(JSRuntime *rt, OutOfMemoryCallback cb, void *data); + + +/* + * Capture the current call stack as a chain of SavedFrame objects, and set + * |stackp| to the SavedFrame for the newest stack frame. If |maxFrameCount| is + * non-zero, capture at most the youngest |maxFrameCount| frames. + */ +extern JS_PUBLIC_API(bool) +CaptureCurrentStack(JSContext *cx, MutableHandleObject stackp, unsigned maxFrameCount = 0); + } /* namespace JS */ #endif /* jsapi_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/jscpucfg.h b/frameworks/js-bindings/external/spidermonkey/include/mac/jscpucfg.h index e545d8329d..a7a00613bb 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/jscpucfg.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/jscpucfg.h @@ -18,7 +18,7 @@ # error "CPU type is unknown" # endif /* !(defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)) */ -#elif defined(_WIN32) || defined(XP_OS2) +#elif defined(_WIN32) # ifdef __WATCOMC__ # define HAVE_VA_LIST_AS_ARRAY 1 @@ -27,7 +27,7 @@ # define IS_LITTLE_ENDIAN 1 # undef IS_BIG_ENDIAN -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) # if __LITTLE_ENDIAN__ # define IS_LITTLE_ENDIAN 1 # undef IS_BIG_ENDIAN @@ -89,8 +89,7 @@ # endif #elif defined(__sparc) || defined(__sparc__) || \ - defined(_POWER) || defined(__powerpc__) || \ - defined(__ppc__) || defined(__hppa) || \ + defined(_POWER) || defined(__hppa) || \ defined(_MIPSEB) || defined(_BIG_ENDIAN) /* IA64 running HP-UX will have _BIG_ENDIAN defined. * IA64 running Linux will have endian.h and be handled above. diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/jsfriendapi.h b/frameworks/js-bindings/external/spidermonkey/include/mac/jsfriendapi.h index eb05652a5b..674999eb62 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/jsfriendapi.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/jsfriendapi.h @@ -7,8 +7,12 @@ #ifndef jsfriendapi_h #define jsfriendapi_h +#include "mozilla/Casting.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/TypedEnum.h" +#include "mozilla/UniquePtr.h" +#include "jsapi.h" // For JSAutoByteString. See bug 1033916. #include "jsbytecode.h" #include "jspubtd.h" @@ -19,14 +23,20 @@ /* * This macro checks if the stack pointer has exceeded a given limit. If * |tolerance| is non-zero, it returns true only if the stack pointer has - * exceeded the limit by more than |tolerance| bytes. + * exceeded the limit by more than |tolerance| bytes. The WITH_INTOLERANCE + * versions use a negative tolerance (i.e., the limit is reduced by + * |intolerance| bytes). */ #if JS_STACK_GROWTH_DIRECTION > 0 # define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ ((uintptr_t)(sp) < (limit)+(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) < (limit)-(intolerance)) #else # define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ ((uintptr_t)(sp) > (limit)-(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) > (limit)+(intolerance)) #endif #define JS_CHECK_STACK_SIZE(limit, lval) JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, lval, 0) @@ -35,33 +45,35 @@ class JSAtom; struct JSErrorFormatString; class JSLinearString; struct JSJitInfo; -class JSErrorReport; +struct JSErrorReport; namespace JS { template class Heap; } /* namespace JS */ +namespace js { +class JS_FRIEND_API(BaseProxyHandler); +} /* namespace js */ + extern JS_FRIEND_API(void) JS_SetGrayGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); extern JS_FRIEND_API(JSString *) JS_GetAnonymousString(JSRuntime *rt); -extern JS_FRIEND_API(void) -JS_SetIsWorkerRuntime(JSRuntime *rt); - extern JS_FRIEND_API(JSObject *) -JS_FindCompilationScope(JSContext *cx, JSObject *obj); +JS_FindCompilationScope(JSContext *cx, JS::HandleObject obj); extern JS_FRIEND_API(JSFunction *) JS_GetObjectFunction(JSObject *obj); extern JS_FRIEND_API(bool) -JS_SplicePrototype(JSContext *cx, JSObject *obj, JSObject *proto); +JS_SplicePrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); extern JS_FRIEND_API(JSObject *) -JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JSObject *proto, JSObject *parent); +JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JS::HandleObject proto, + JS::HandleObject parent); extern JS_FRIEND_API(uint32_t) JS_ObjectCountDynamicSlots(JS::HandleObject obj); @@ -73,7 +85,7 @@ extern JS_FRIEND_API(size_t) JS_GetCustomIteratorCount(JSContext *cx); extern JS_FRIEND_API(bool) -JS_NondeterministicGetWeakMapKeys(JSContext *cx, JSObject *obj, JSObject **ret); +JS_NondeterministicGetWeakMapKeys(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject ret); /* * Determine whether the given object is backed by a DeadObjectProxy. @@ -122,16 +134,23 @@ JS_GetCompartmentPrincipals(JSCompartment *compartment); extern JS_FRIEND_API(void) JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals); +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptPrincipals(JSScript *script); + +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptOriginPrincipals(JSScript *script); + /* Safe to call with input obj == nullptr. Returns non-nullptr iff obj != nullptr. */ extern JS_FRIEND_API(JSObject *) -JS_ObjectToInnerObject(JSContext *cx, JSObject *obj); +JS_ObjectToInnerObject(JSContext *cx, JS::HandleObject obj); /* Requires obj != nullptr. */ extern JS_FRIEND_API(JSObject *) -JS_ObjectToOuterObject(JSContext *cx, JSObject *obj); +JS_ObjectToOuterObject(JSContext *cx, JS::HandleObject obj); extern JS_FRIEND_API(JSObject *) -JS_CloneObject(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent); +JS_CloneObject(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto, + JS::HandleObject parent); extern JS_FRIEND_API(JSString *) JS_BasicObjectToString(JSContext *cx, JS::HandleObject obj); @@ -149,13 +168,17 @@ js_ObjectClassIs(JSContext *cx, JS::HandleObject obj, js::ESClassValue classValu JS_FRIEND_API(const char *) js_ObjectClassName(JSContext *cx, JS::HandleObject obj); +namespace js { + JS_FRIEND_API(bool) -js_AddObjectRoot(JSRuntime *rt, JSObject **objp); +AddRawValueRoot(JSContext *cx, JS::Value *vp, const char *name); JS_FRIEND_API(void) -js_RemoveObjectRoot(JSRuntime *rt, JSObject **objp); +RemoveRawValueRoot(JSContext *cx, JS::Value *vp); -#ifdef DEBUG +} /* namespace js */ + +#ifdef JS_DEBUG /* * Routines to print out values during debugging. These are FRIEND_API to help @@ -184,7 +207,7 @@ js_DumpChars(const jschar *s, size_t n); * restrictions on the compartment of |cx|. */ extern JS_FRIEND_API(bool) -JS_CopyPropertiesFrom(JSContext *cx, JSObject *target, JSObject *obj); +JS_CopyPropertiesFrom(JSContext *cx, JS::HandleObject target, JS::HandleObject obj); /* * Single-property version of the above. This function asserts that an |own| @@ -221,20 +244,164 @@ struct JSFunctionSpecWithHelp { {nullptr, nullptr, 0, 0, nullptr, nullptr} extern JS_FRIEND_API(bool) -JS_DefineFunctionsWithHelp(JSContext *cx, JSObject *obj, const JSFunctionSpecWithHelp *fs); +JS_DefineFunctionsWithHelp(JSContext *cx, JS::HandleObject obj, const JSFunctionSpecWithHelp *fs); namespace js { +/* + * Helper Macros for creating JSClasses that function as proxies. + * + * NB: The macro invocation must be surrounded by braces, so as to + * allow for potention JSClass extensions. + */ +#define PROXY_MAKE_EXT(outerObject, innerObject, iteratorObject, \ + isWrappedNative) \ + { \ + outerObject, \ + innerObject, \ + iteratorObject, \ + isWrappedNative, \ + js::proxy_WeakmapKeyDelegate \ + } + +#define PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, ext) \ + { \ + name, \ + js::Class::NON_NATIVE | \ + JSCLASS_IS_PROXY | \ + JSCLASS_IMPLEMENTS_BARRIERS | \ + JSCLASS_HAS_RESERVED_SLOTS(js::PROXY_MINIMUM_SLOTS + (extraSlots)) | \ + flags, \ + JS_PropertyStub, /* addProperty */ \ + JS_DeletePropertyStub, /* delProperty */ \ + JS_PropertyStub, /* getProperty */ \ + JS_StrictPropertyStub, /* setProperty */ \ + JS_EnumerateStub, \ + JS_ResolveStub, \ + js::proxy_Convert, \ + js::proxy_Finalize, /* finalize */ \ + callOp, /* call */ \ + js::proxy_HasInstance, /* hasInstance */ \ + constructOp, /* construct */ \ + js::proxy_Trace, /* trace */ \ + JS_NULL_CLASS_SPEC, \ + ext, \ + { \ + js::proxy_LookupGeneric, \ + js::proxy_LookupProperty, \ + js::proxy_LookupElement, \ + js::proxy_DefineGeneric, \ + js::proxy_DefineProperty, \ + js::proxy_DefineElement, \ + js::proxy_GetGeneric, \ + js::proxy_GetProperty, \ + js::proxy_GetElement, \ + js::proxy_SetGeneric, \ + js::proxy_SetProperty, \ + js::proxy_SetElement, \ + js::proxy_GetGenericAttributes, \ + js::proxy_SetGenericAttributes, \ + js::proxy_DeleteGeneric, \ + js::proxy_Watch, js::proxy_Unwatch, \ + js::proxy_Slice, \ + nullptr, /* enumerate */ \ + nullptr, /* thisObject */ \ + } \ + } + +#define PROXY_CLASS_DEF(name, extraSlots, flags, callOp, constructOp) \ + PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, \ + PROXY_MAKE_EXT( \ + nullptr, /* outerObject */ \ + nullptr, /* innerObject */ \ + nullptr, /* iteratorObject */ \ + false /* isWrappedNative */ \ + )) + +/* + * Proxy stubs, similar to JS_*Stub, for embedder proxy class definitions. + * + * NB: Should not be called directly. + */ + +extern JS_FRIEND_API(bool) +proxy_LookupGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleObject objp, JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_DefineGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, + unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_GetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetProperty(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, + JS::Handle name, JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetElement(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_SetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp, + bool strict); +extern JS_FRIEND_API(bool) +proxy_GetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_SetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_DeleteGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); + +extern JS_FRIEND_API(void) +proxy_Trace(JSTracer *trc, JSObject *obj); +extern JS_FRIEND_API(JSObject *) +proxy_WeakmapKeyDelegate(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Convert(JSContext *cx, JS::HandleObject proxy, JSType hint, JS::MutableHandleValue vp); +extern JS_FRIEND_API(void) +proxy_Finalize(FreeOp *fop, JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_HasInstance(JSContext *cx, JS::HandleObject proxy, JS::MutableHandleValue v, bool *bp); +extern JS_FRIEND_API(bool) +proxy_Call(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(bool) +proxy_Construct(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(JSObject *) +proxy_innerObject(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Watch(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); +extern JS_FRIEND_API(bool) +proxy_Unwatch(JSContext *cx, JS::HandleObject obj, JS::HandleId id); +extern JS_FRIEND_API(bool) +proxy_Slice(JSContext *cx, JS::HandleObject proxy, uint32_t begin, uint32_t end, + JS::HandleObject result); + /* * A class of objects that return source code on demand. * - * When code is compiled with CompileOptions::LAZY_SOURCE, SpiderMonkey - * doesn't retain the source code (and doesn't do lazy bytecode - * generation). If we ever need the source code, say, in response to a call - * to Function.prototype.toSource or Debugger.Source.prototype.text, then - * we call the 'load' member function of the instance of this class that - * has hopefully been registered with the runtime, passing the code's URL, - * and hope that it will be able to find the source. + * When code is compiled with setSourceIsLazy(true), SpiderMonkey doesn't + * retain the source code (and doesn't do lazy bytecode generation). If we ever + * need the source code, say, in response to a call to Function.prototype. + * toSource or Debugger.Source.prototype.text, then we call the 'load' member + * function of the instance of this class that has hopefully been registered + * with the runtime, passing the code's URL, and hope that it will be able to + * find the source. */ class SourceHook { public: @@ -249,18 +416,25 @@ class SourceHook { }; /* - * Have |rt| use |hook| to retrieve LAZY_SOURCE source code. See the + * Have |rt| use |hook| to retrieve lazily-retrieved source code. See the * comments for SourceHook. The runtime takes ownership of the hook, and * will delete it when the runtime itself is deleted, or when a new hook is * set. */ extern JS_FRIEND_API(void) -SetSourceHook(JSRuntime *rt, SourceHook *hook); +SetSourceHook(JSRuntime *rt, mozilla::UniquePtr hook); /* Remove |rt|'s source hook, and return it. The caller now owns the hook. */ -extern JS_FRIEND_API(SourceHook *) +extern JS_FRIEND_API(mozilla::UniquePtr) ForgetSourceHook(JSRuntime *rt); +#ifdef NIGHTLY_BUILD +typedef void (*AssertOnScriptEntryHook)(JSContext *cx, JS::HandleScript script); + +extern JS_FRIEND_API(void) +SetAssertOnScriptEntryHook(JSRuntime *rt, AssertOnScriptEntryHook hook); +#endif + extern JS_FRIEND_API(JS::Zone *) GetCompartmentZone(JSCompartment *comp); @@ -293,16 +467,6 @@ IsSystemZone(JS::Zone *zone); extern JS_FRIEND_API(bool) IsAtomsCompartment(JSCompartment *comp); -/* - * Check whether it is OK to assign an undeclared variable with the name - * |propname| at the current location in script. It is not an error if there is - * no current script location, or if that location is not an assignment to an - * undeclared variable. Reports an error if one needs to be reported (and, - * particularly, always reports when it returns false). - */ -extern JS_FRIEND_API(bool) -ReportIfUndeclaredVarAssignment(JSContext *cx, JS::HandleString propname); - /* * Returns whether we're in a non-strict property set (in that we're in a * non-strict script and the bytecode we're on is a property set). The return @@ -339,6 +503,9 @@ TraceWeakMaps(WeakMapTracer *trc); extern JS_FRIEND_API(bool) AreGCGrayBitsValid(JSRuntime *rt); +extern JS_FRIEND_API(bool) +ZoneGlobalsAreAllGray(JS::Zone *zone); + typedef void (*GCThingCallback)(void *closure, void *gcthing); @@ -379,7 +546,7 @@ struct TypeObject { }; struct BaseShape { - const js::Class *clasp; + const js::Class *clasp_; JSObject *parent; JSObject *_1; JSCompartment *compartment; @@ -427,10 +594,20 @@ struct Function { void *_1; }; -struct Atom { - static const size_t LENGTH_SHIFT = 4; - size_t lengthAndFlags; - const jschar *chars; +struct String +{ + static const uint32_t INLINE_CHARS_BIT = JS_BIT(2); + static const uint32_t LATIN1_CHARS_BIT = JS_BIT(6); + static const uint32_t ROPE_FLAGS = 0; + static const uint32_t TYPE_FLAGS_MASK = JS_BIT(6) - 1; + uint32_t flags; + uint32_t length; + union { + const JS::Latin1Char *nonInlineCharsLatin1; + const jschar *nonInlineCharsTwoByte; + JS::Latin1Char inlineStorageLatin1[1]; + jschar inlineStorageTwoByte[1]; + }; }; } /* namespace shadow */ @@ -451,6 +628,46 @@ GetObjectJSClass(JSObject *obj) return js::Jsvalify(GetObjectClass(obj)); } +JS_FRIEND_API(const Class *) +ProtoKeyToClass(JSProtoKey key); + +// Returns true if the standard class identified by |key| inherits from +// another standard class with the same js::Class. This basically means +// that the various properties described by our js::Class are intended +// to live higher up on the proto chain. +// +// In practice, this only returns true for Error subtypes. +inline bool +StandardClassIsDependent(JSProtoKey key) +{ + JSProtoKey keyFromClass = JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + MOZ_ASSERT(keyFromClass); + return key != keyFromClass; +} + +// Returns the key for the class inherited by a given standard class (that +// is to say, the prototype of this standard class's prototype). +// +// You must be sure that this corresponds to a standard class with a cached +// JSProtoKey before calling this function. In general |key| will match the +// cached proto key, except in cases where multiple JSProtoKeys share a +// JSClass. +inline JSProtoKey +ParentKeyForStandardClass(JSProtoKey key) +{ + // [Object] has nothing to inherit from. + if (key == JSProto_Object) + return JSProto_Null; + + // If we're dependent (i.e. an Error subtype), return the key of the class + // we depend on. + if (StandardClassIsDependent(key)) + return JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + + // Otherwise, we inherit [Object]. + return JSProto_Object; +} + inline bool IsInnerObject(JSObject *obj) { return !!GetObjectClass(obj)->ext.outerObject; @@ -477,7 +694,7 @@ GetObjectParent(JSObject *obj) return reinterpret_cast(obj)->shape->base->parent; } -static JS_ALWAYS_INLINE JSCompartment * +static MOZ_ALWAYS_INLINE JSCompartment * GetObjectCompartment(JSObject *obj) { return reinterpret_cast(obj)->shape->base->compartment; @@ -489,10 +706,15 @@ GetObjectParentMaybeScope(JSObject *obj); JS_FRIEND_API(JSObject *) GetGlobalForObjectCrossCompartment(JSObject *obj); +// Sidestep the activeContext checking implicitly performed in +// JS_SetPendingException. +JS_FRIEND_API(void) +SetPendingExceptionCrossContext(JSContext *cx, JS::HandleValue v); + JS_FRIEND_API(void) AssertSameCompartment(JSContext *cx, JSObject *obj); -#ifdef DEBUG +#ifdef JS_DEBUG JS_FRIEND_API(void) AssertSameCompartment(JSObject *objA, JSObject *objB); #else @@ -509,9 +731,6 @@ SetDefaultObjectForContext(JSContext *cx, JSObject *obj); JS_FRIEND_API(void) NotifyAnimationActivity(JSObject *obj); -JS_FRIEND_API(bool) -IsOriginalScriptFunction(JSFunction *fun); - /* * Return the outermost enclosing function (script) of the scripted caller. * This function returns nullptr in several cases: @@ -521,7 +740,7 @@ IsOriginalScriptFunction(JSFunction *fun); * thus it will really return the outermost enclosing function *since the * innermost eval*. */ -JS_FRIEND_API(JSScript *) +JS_FRIEND_API(JSFunction *) GetOutermostEnclosingFunctionOfScriptedCaller(JSContext *cx); JS_FRIEND_API(JSFunction *) @@ -536,12 +755,6 @@ JS_FRIEND_API(JSFunction *) NewFunctionByIdWithReserved(JSContext *cx, JSNative native, unsigned nargs, unsigned flags, JSObject *parent, jsid id); -JS_FRIEND_API(JSObject *) -InitClassWithReserved(JSContext *cx, JSObject *obj, JSObject *parent_proto, - const JSClass *clasp, JSNative constructor, unsigned nargs, - const JSPropertySpec *ps, const JSFunctionSpec *fs, - const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs); - JS_FRIEND_API(const JS::Value &) GetFunctionNativeReserved(JSObject *fun, size_t which); @@ -549,7 +762,7 @@ JS_FRIEND_API(void) SetFunctionNativeReserved(JSObject *fun, size_t which, const JS::Value &val); JS_FRIEND_API(bool) -GetObjectProto(JSContext *cx, JS::Handle obj, JS::MutableHandle proto); +GetObjectProto(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject proto); JS_FRIEND_API(bool) GetOriginalEval(JSContext *cx, JS::HandleObject scope, @@ -604,25 +817,142 @@ GetObjectSlot(JSObject *obj, size_t slot) return reinterpret_cast(obj)->slotRef(slot); } -inline const jschar * -GetAtomChars(JSAtom *atom) +MOZ_ALWAYS_INLINE size_t +GetAtomLength(JSAtom *atom) { - return reinterpret_cast(atom)->chars; + return reinterpret_cast(atom)->length; } -inline size_t -GetAtomLength(JSAtom *atom) +static const uint32_t MaxStringLength = (1 << 28) - 1; + +MOZ_ALWAYS_INLINE size_t +GetStringLength(JSString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetFlatStringLength(JSFlatString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetLinearStringLength(JSLinearString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE bool +LinearStringHasLatin1Chars(JSLinearString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE bool +AtomHasLatin1Chars(JSAtom *atom) { - using shadow::Atom; - return reinterpret_cast(atom)->lengthAndFlags >> Atom::LENGTH_SHIFT; + return reinterpret_cast(atom)->flags & shadow::String::LATIN1_CHARS_BIT; } -inline JSLinearString * +MOZ_ALWAYS_INLINE bool +StringHasLatin1Chars(JSString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1LinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageLatin1; + return s->nonInlineCharsLatin1; +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteLinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(!LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageTwoByte; + return s->nonInlineCharsTwoByte; +} + +MOZ_ALWAYS_INLINE JSLinearString * AtomToLinearString(JSAtom *atom) { return reinterpret_cast(atom); } +MOZ_ALWAYS_INLINE JSLinearString * +FlatStringToLinearString(JSFlatString *s) +{ + return reinterpret_cast(s); +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1AtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetLatin1LinearStringChars(nogc, AtomToLinearString(atom)); +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteAtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetTwoByteLinearStringChars(nogc, AtomToLinearString(atom)); +} + +JS_FRIEND_API(JSLinearString *) +StringToLinearStringSlow(JSContext *cx, JSString *str); + +MOZ_ALWAYS_INLINE JSLinearString * +StringToLinearString(JSContext *cx, JSString *str) +{ + using shadow::String; + String *s = reinterpret_cast(str); + if (MOZ_UNLIKELY((s->flags & String::TYPE_FLAGS_MASK) == String::ROPE_FLAGS)) + return StringToLinearStringSlow(cx, str); + return reinterpret_cast(str); +} + +MOZ_ALWAYS_INLINE void +CopyLinearStringChars(jschar *dest, JSLinearString *s, size_t len) +{ + JS::AutoCheckCannotGC nogc; + if (LinearStringHasLatin1Chars(s)) { + const JS::Latin1Char *src = GetLatin1LinearStringChars(nogc, s); + for (size_t i = 0; i < len; i++) + dest[i] = src[i]; + } else { + const jschar *src = GetTwoByteLinearStringChars(nogc, s); + mozilla::PodCopy(dest, src, len); + } +} + +inline bool +CopyStringChars(JSContext *cx, jschar *dest, JSString *s, size_t len) +{ + JSLinearString *linear = StringToLinearString(cx, s); + if (!linear) + return false; + + CopyLinearStringChars(dest, linear, len); + return true; +} + +inline void +CopyFlatStringChars(jschar *dest, JSFlatString *s, size_t len) +{ + CopyLinearStringChars(dest, FlatStringToLinearString(s), len); +} + JS_FRIEND_API(bool) GetPropertyNames(JSContext *cx, JSObject *obj, unsigned flags, JS::AutoIdVector *props); @@ -641,24 +971,18 @@ SetPreserveWrapperCallback(JSRuntime *rt, PreserveWrapperCallback callback); JS_FRIEND_API(bool) IsObjectInContextCompartment(JSObject *obj, const JSContext *cx); -/* - * ErrorFromException takes a raw Value so that it's possible to call it during - * GC/CC/whatever, when it may not be possible to get a JSContext to create a - * Rooted. It promises to never ever GC. - */ -JS_FRIEND_API(JSErrorReport*) -ErrorFromException(JS::Value val); - /* * NB: these flag bits are encoded into the bytecode stream in the immediate * operand of JSOP_ITER, so don't change them without advancing vm/Xdr.h's * XDR_BYTECODE_VERSION. */ #define JSITER_ENUMERATE 0x1 /* for-in compatible hidden default iterator */ -#define JSITER_FOREACH 0x2 /* return [key, value] pair rather than key */ -#define JSITER_KEYVALUE 0x4 /* destructuring for-in wants [key, value] */ +#define JSITER_FOREACH 0x2 /* get obj[key] for each property */ +#define JSITER_KEYVALUE 0x4 /* obsolete destructuring for-in wants [key, value] */ #define JSITER_OWNONLY 0x8 /* iterate over obj's own properties only */ #define JSITER_HIDDEN 0x10 /* also enumerate non-enumerable properties */ +#define JSITER_SYMBOLS 0x20 /* also include symbol property keys */ +#define JSITER_SYMBOLSONLY 0x40 /* exclude string property keys */ JS_FRIEND_API(bool) RunningWithTrustedPrincipals(JSContext *cx); @@ -677,6 +1001,7 @@ GetNativeStackLimit(JSContext *cx) * These macros report a stack overflow and run |onerror| if we are close to * using up the C stack. The JS_CHECK_CHROME_RECURSION variant gives us a little * extra space so that we can ensure that crucial code is able to run. + * JS_CHECK_RECURSION_CONSERVATIVE gives us a little less space. */ #define JS_CHECK_RECURSION(cx, onerror) \ @@ -723,6 +1048,18 @@ GetNativeStackLimit(JSContext *cx) } \ JS_END_MACRO +#define JS_CHECK_RECURSION_CONSERVATIVE(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(js::GetNativeStackLimit(cx), \ + &stackDummy_, \ + 1024 * sizeof(size_t))) \ + { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + JS_FRIEND_API(void) StartPCCountProfiling(JSContext *cx); @@ -764,9 +1101,10 @@ extern JS_FRIEND_API(bool) IsContextRunningJS(JSContext *cx); typedef bool -(* DOMInstanceClassMatchesProto)(JSObject *protoObject, uint32_t protoID, uint32_t depth); +(* DOMInstanceClassHasProtoAtDepth)(const Class *instanceClass, + uint32_t protoID, uint32_t depth); struct JSDOMCallbacks { - DOMInstanceClassMatchesProto instanceClassMatchesProto; + DOMInstanceClassHasProtoAtDepth instanceClassMatchesProto; }; typedef struct JSDOMCallbacks DOMCallbacks; @@ -796,10 +1134,10 @@ CastToJSFreeOp(FreeOp *fop) * Get an error type name from a JSExnType constant. * Returns nullptr for invalid arguments and JSEXN_INTERNALERR */ -extern JS_FRIEND_API(const jschar*) -GetErrorTypeName(JSRuntime* rt, int16_t exnType); +extern JS_FRIEND_API(JSFlatString *) +GetErrorTypeName(JSRuntime *rt, int16_t exnType); -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_FRIEND_API(unsigned) GetEnterCompartmentDepth(JSContext* cx); #endif @@ -836,13 +1174,13 @@ struct ChromeCompartmentsOnly : public CompartmentFilter { struct SingleCompartment : public CompartmentFilter { JSCompartment *ours; - SingleCompartment(JSCompartment *c) : ours(c) {} + explicit SingleCompartment(JSCompartment *c) : ours(c) {} virtual bool match(JSCompartment *c) const { return c == ours; } }; struct CompartmentsWithPrincipals : public CompartmentFilter { JSPrincipals *principals; - CompartmentsWithPrincipals(JSPrincipals *p) : principals(p) {} + explicit CompartmentsWithPrincipals(JSPrincipals *p) : principals(p) {} virtual bool match(JSCompartment *c) const { return JS_GetCompartmentPrincipals(c) == principals; } @@ -941,49 +1279,198 @@ typedef enum JSErrNum { } JSErrNum; extern JS_FRIEND_API(const JSErrorFormatString *) -js_GetErrorMessage(void *userRef, const char *locale, const unsigned errorNumber); +js_GetErrorMessage(void *userRef, const unsigned errorNumber); + +namespace js { + +// AutoStableStringChars is here so we can use it in ErrorReport. It +// should get moved out of here if we can manage it. See bug 1040316. + +/* + * This class provides safe access to a string's chars across a GC. Once + * we allocate strings and chars in the nursery (bug 903519), this class + * will have to make a copy of the string's chars if they are allocated + * in the nursery, so it's best to avoid using this class unless you really + * need it. It's usually more efficient to use the latin1Chars/twoByteChars + * JSString methods and often the code can be rewritten so that only indexes + * instead of char pointers are used in parts of the code that can GC. + */ +class MOZ_STACK_CLASS AutoStableStringChars +{ + /* Ensure the string is kept alive while we're using its chars. */ + JS::RootedString s_; + union { + const jschar *twoByteChars_; + const JS::Latin1Char *latin1Chars_; + }; + enum State { Uninitialized, Latin1, TwoByte }; + State state_; + bool ownsChars_; + + public: + AutoStableStringChars(JSContext *cx) + : s_(cx), state_(Uninitialized), ownsChars_(false) + {}; + ~AutoStableStringChars(); + + bool init(JSContext *cx, JSString *s); + + /* Like init(), but Latin1 chars are inflated to TwoByte. */ + bool initTwoByte(JSContext *cx, JSString *s); + + bool isLatin1() const { return state_ == Latin1; } + bool isTwoByte() const { return state_ == TwoByte; } + + const jschar *twoByteChars() const { + MOZ_ASSERT(state_ == TwoByte); + return twoByteChars_; + } + + mozilla::Range latin1Range() const { + MOZ_ASSERT(state_ == Latin1); + return mozilla::Range(latin1Chars_, + GetStringLength(s_)); + } + + mozilla::Range twoByteRange() const { + MOZ_ASSERT(state_ == TwoByte); + return mozilla::Range(twoByteChars_, + GetStringLength(s_)); + } + + /* If we own the chars, transfer ownership to the caller. */ + bool maybeGiveOwnershipToCaller() { + MOZ_ASSERT(state_ != Uninitialized); + if (!ownsChars_) + return false; + state_ = Uninitialized; + ownsChars_ = false; + return true; + } + + private: + AutoStableStringChars(const AutoStableStringChars &other) MOZ_DELETE; + void operator=(const AutoStableStringChars &other) MOZ_DELETE; +}; + +// Creates a string of the form |ErrorType: ErrorMessage| for a JSErrorReport, +// which generally matches the toString() behavior of an ErrorObject. +extern JS_FRIEND_API(JSString *) +ErrorReportToString(JSContext *cx, JSErrorReport *reportp); + +struct MOZ_STACK_CLASS JS_FRIEND_API(ErrorReport) +{ + ErrorReport(JSContext *cx); + ~ErrorReport(); + + bool init(JSContext *cx, JS::HandleValue exn); + + JSErrorReport *report() + { + return reportp; + } + + const char *message() + { + return message_; + } + + private: + // More or less an equivalent of JS_ReportErrorNumber/js_ReportErrorNumberVA + // but fills in an ErrorReport instead of reporting it. Uses varargs to + // make it simpler to call js_ExpandErrorArguments. + void populateUncaughtExceptionReport(JSContext *cx, ...); + void populateUncaughtExceptionReportVA(JSContext *cx, va_list ap); + + // We may have a provided JSErrorReport, so need a way to represent that. + JSErrorReport *reportp; + + // And we may have a message. + const char *message_; + + // Or we may need to synthesize a JSErrorReport one of our own. + JSErrorReport ownedReport; + + // Or a message of our own. If this is non-null, we need to clean up both + // it and ownedReport. + char *ownedMessage; + + // And we have a string to maybe keep alive that has pointers into + // it from ownedReport. + JS::RootedString str; + + // And keep its chars alive too. + AutoStableStringChars strChars; + + // And we need to root our exception value. + JS::RootedObject exnObject; + + // And possibly some byte storage for our message_. + JSAutoByteString bytesStorage; + + // And for our filename. + JSAutoByteString filename; + + // True if we need to free message_ and the stuff in ownedReport + bool ownsMessageAndReport; +}; + +} /* namespace js */ + /* Implemented in jsclone.cpp. */ extern JS_FRIEND_API(uint64_t) js_GetSCOffset(JSStructuredCloneWriter* writer); -/* Typed Array functions, implemented in jstypedarray.cpp */ - namespace js { -namespace ArrayBufferView { - -enum ViewType { - TYPE_INT8 = 0, - TYPE_UINT8, - TYPE_INT16, - TYPE_UINT16, - TYPE_INT32, - TYPE_UINT32, - TYPE_FLOAT32, - TYPE_FLOAT64, +namespace Scalar { + +/* Scalar types which can appear in typed arrays and typed objects. */ +enum Type { + Int8 = 0, + Uint8, + Int16, + Uint16, + Int32, + Uint32, + Float32, + Float64, /* * Special type that is a uint8_t, but assignments are clamped to [0, 256). * Treat the raw data type as a uint8_t. */ - TYPE_UINT8_CLAMPED, + Uint8Clamped, - /* - * Type returned for a DataView. Note that there is no single element type - * in this case. - */ - TYPE_DATAVIEW, - - TYPE_MAX + TypeMax }; -} /* namespace ArrayBufferView */ +static inline size_t +byteSize(Type atype) +{ + switch (atype) { + case Int8: + case Uint8: + case Uint8Clamped: + return 1; + case Int16: + case Uint16: + return 2; + case Int32: + case Uint32: + case Float32: + return 4; + case Float64: + return 8; + default: + MOZ_CRASH("invalid scalar type"); + } +} +} /* namespace Scalar */ } /* namespace js */ -typedef js::ArrayBufferView::ViewType JSArrayBufferViewType; - /* * Create a new typed array with nelements elements. * @@ -1019,23 +1506,23 @@ JS_NewFloat64Array(JSContext *cx, uint32_t nelements); */ extern JS_FRIEND_API(JSObject *) -JS_NewInt8ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt8ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint8ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ClampedArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint8ClampedArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewInt16ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt16ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint16ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint16ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewInt32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewFloat32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewFloat32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewFloat64ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewFloat64ArrayFromArray(JSContext *cx, JS::HandleObject array); /* * Create a new typed array using the given ArrayBuffer for storage. The @@ -1044,31 +1531,31 @@ JS_NewFloat64ArrayFromArray(JSContext *cx, JSObject *array); */ extern JS_FRIEND_API(JSObject *) -JS_NewInt8ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewInt16ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint16ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewInt32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewFloat32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewFloat32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewFloat64ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewFloat64ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); /* @@ -1119,6 +1606,93 @@ JS_IsFloat32Array(JSObject *obj); extern JS_FRIEND_API(bool) JS_IsFloat64Array(JSObject *obj); +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +namespace js { + +extern JS_FRIEND_API(JSObject *) +UnwrapInt8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8ClampedArray(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat64Array(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBuffer(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBufferView(JSObject *obj); + +namespace detail { + +extern JS_FRIEND_DATA(const Class* const) Int8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ClampedArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float64ArrayClassPtr; + +const size_t TypedArrayLengthSlot = 1; + +} // namespace detail + +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +#define JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Type, type) \ +inline void \ +Get ## Type ## ArrayLengthAndData(JSObject *obj, uint32_t *length, type **data) \ +{ \ + JS_ASSERT(GetObjectClass(obj) == detail::Type ## ArrayClassPtr); \ + const JS::Value &slot = GetReservedSlot(obj, detail::TypedArrayLengthSlot); \ + *length = mozilla::SafeCast(slot.toInt32()); \ + *data = static_cast(GetObjectPrivate(obj)); \ +} + +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int8, int8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8Clamped, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int16, int16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint16, uint16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int32, int32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint32, uint32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float32, float) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float64, double) + +#undef JS_DEFINE_DATA_AND_LENGTH_ACCESSOR + +// This one isn't inlined because it's rather tricky (by dint of having to deal +// with a dozen-plus classes and varying slot layouts. +extern JS_FRIEND_API(void) +GetArrayBufferViewLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +// This one isn't inlined because there are a bunch of different ArrayBuffer +// classes that would have to be individually handled here. +extern JS_FRIEND_API(void) +GetArrayBufferLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +} // namespace js + /* * Unwrap Typed arrays all at once. Return nullptr without throwing if the * object cannot be viewed as the correct typed array, or the typed array @@ -1148,13 +1722,13 @@ extern JS_FRIEND_API(JSObject *) JS_GetObjectAsArrayBuffer(JSObject *obj, uint32_t *length, uint8_t **data); /* - * Get the type of elements in a typed array, or TYPE_DATAVIEW if a DataView. + * Get the type of elements in a typed array, or TypeMax if a DataView. * * |obj| must have passed a JS_IsArrayBufferView/JS_Is*Array test, or somehow * be known that it would pass such a test: it is an ArrayBufferView or a * wrapper of an ArrayBufferView, and the unwrapping will succeed. */ -extern JS_FRIEND_API(JSArrayBufferViewType) +extern JS_FRIEND_API(js::Scalar::Type) JS_GetArrayBufferViewType(JSObject *obj); /* @@ -1177,16 +1751,12 @@ extern JS_FRIEND_API(uint32_t) JS_GetArrayBufferByteLength(JSObject *obj); /* - * Return a pointer to an array buffer's data. The buffer is still owned by the - * array buffer object, and should not be modified on another thread. The - * returned pointer is stable across GCs. - * - * |obj| must have passed a JS_IsArrayBufferObject test, or somehow be known - * that it would pass such a test: it is an ArrayBuffer or a wrapper of an - * ArrayBuffer, and the unwrapping will succeed. + * Check whether the obj is ArrayBufferObject and memory mapped. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. */ -extern JS_FRIEND_API(uint8_t *) -JS_GetArrayBufferData(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsMappedArrayBufferObject(JSObject *obj); /* * Return the number of elements in a typed array. @@ -1236,13 +1806,17 @@ JS_GetArrayBufferViewByteLength(JSObject *obj); /* * Return a pointer to the start of the data referenced by a typed array. The * data is still owned by the typed array, and should not be modified on - * another thread. + * another thread. Furthermore, the pointer can become invalid on GC (if the + * data is small and fits inside the array's GC header), so callers must take + * care not to hold on across anything that could GC. * * |obj| must have passed a JS_Is*Array test, or somehow be known that it would * pass such a test: it is a typed array or a wrapper of a typed array, and the * unwrapping will succeed. */ +extern JS_FRIEND_API(uint8_t *) +JS_GetArrayBufferData(JSObject *obj); extern JS_FRIEND_API(int8_t *) JS_GetInt8ArrayData(JSObject *obj); extern JS_FRIEND_API(uint8_t *) @@ -1262,6 +1836,13 @@ JS_GetFloat32ArrayData(JSObject *obj); extern JS_FRIEND_API(double *) JS_GetFloat64ArrayData(JSObject *obj); +/* + * Stable versions of the above functions where the buffer remains valid as long + * as the object is live. + */ +extern JS_FRIEND_API(uint8_t *) +JS_GetStableArrayBufferData(JSContext *cx, JS::HandleObject obj); + /* * Same as above, but for any kind of ArrayBufferView. Prefer the type-specific * versions when possible. @@ -1275,13 +1856,33 @@ JS_GetArrayBufferViewData(JSObject *obj); * object that would return true for JS_IsArrayBufferViewObject(). */ extern JS_FRIEND_API(JSObject *) -JS_GetArrayBufferViewBuffer(JSObject *obj); +JS_GetArrayBufferViewBuffer(JSContext *cx, JS::HandleObject obj); + +typedef enum { + ChangeData, + KeepData +} NeuterDataDisposition; /* * Set an ArrayBuffer's length to 0 and neuter all of its views. + * + * The |changeData| argument is a hint to inform internal behavior with respect + * to the internal pointer to the ArrayBuffer's data after being neutered. + * There is no guarantee it will be respected. But if it is respected, the + * ArrayBuffer's internal data pointer will, or will not, have changed + * accordingly. + */ +extern JS_FRIEND_API(bool) +JS_NeuterArrayBuffer(JSContext *cx, JS::HandleObject obj, + NeuterDataDisposition changeData); + +/* + * Check whether the obj is ArrayBufferObject and neutered. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. */ extern JS_FRIEND_API(bool) -JS_NeuterArrayBuffer(JSContext *cx, JS::HandleObject obj); +JS_IsNeuteredArrayBufferObject(JSObject *obj); /* * Check whether obj supports JS_GetDataView* APIs. @@ -1360,7 +1961,7 @@ class JSJitGetterCallArgs : protected JS::MutableHandleValue : JS::MutableHandleValue(args.rval()) {} - explicit JSJitGetterCallArgs(JS::Rooted* rooted) + explicit JSJitGetterCallArgs(JS::RootedValue* rooted) : JS::MutableHandleValue(rooted) {} @@ -1422,6 +2023,12 @@ class JSJitMethodCallArgs : protected JS::detail::CallArgsBaseusedRval_, which we don't have. + return argv_[-2].toObject(); + } + // Add get() as needed }; @@ -1451,7 +2058,10 @@ struct JSJitInfo { Getter, Setter, Method, - OpType_None + ParallelNative, + StaticMethod, + // Must be last + OpTypeCount }; enum ArgType { @@ -1475,6 +2085,13 @@ struct JSJitInfo { ArgTypeListEnd = (1 << 31) }; + static_assert(Any & String, "Any must include String."); + static_assert(Any & Integer, "Any must include Integer."); + static_assert(Any & Double, "Any must include Double."); + static_assert(Any & Boolean, "Any must include Boolean."); + static_assert(Any & Object, "Any must include Object."); + static_assert(Any & Null, "Any must include Null."); + enum AliasSet { // An enum that describes what this getter/setter/method aliases. This // determines what things can be hoisted past this call, and if this @@ -1490,69 +2107,172 @@ struct JSJitInfo { // Alias the world. Calling this can change arbitrary values anywhere // in the system. Most things fall in this bucket. - AliasEverything + AliasEverything, + + // Must be last. + AliasSetCount }; - bool isDOMJitInfo() const + bool hasParallelNative() const + { + return type() == ParallelNative; + } + + bool needsOuterizedThisObject() const + { + return type() != Getter && type() != Setter; + } + + bool isTypedMethodJitInfo() const { - return type != OpType_None; + return isTypedMethod; + } + + OpType type() const + { + return OpType(type_); + } + + AliasSet aliasSet() const + { + return AliasSet(aliasSet_); + } + + JSValueType returnType() const + { + return JSValueType(returnType_); } union { JSJitGetterOp getter; JSJitSetterOp setter; JSJitMethodOp method; + /* An alternative native that's safe to call in parallel mode. */ + JSParallelNative parallelNative; + /* A DOM static method, used for Promise wrappers */ + JSNative staticMethod; }; - uint32_t protoID; - uint32_t depth; - // type not being OpType_None means this is a DOM method. If you - // change that, come up with a different way of implementing - // isDOMJitInfo(). - OpType type; - bool isInfallible; /* Is op fallible? False in setters. */ - bool isMovable; /* Is op movable? To be movable the op must not - AliasEverything, but even that might not be - enough (e.g. in cases when it can throw). */ - AliasSet aliasSet; /* The alias set for this op. This is a _minimal_ - alias set; in particular for a method it does not - include whatever argument conversions might do. - That's covered by argTypes and runtime analysis - of the actual argument types being passed in. */ - // XXXbz should we have a JSGetterJitInfo subclass or something? + uint16_t protoID; + uint16_t depth; + + // These fields are carefully packed to take up 4 bytes. If you need more + // bits for whatever reason, please see if you can steal bits from existing + // fields before adding more members to this structure. + +#define JITINFO_OP_TYPE_BITS 4 +#define JITINFO_ALIAS_SET_BITS 4 +#define JITINFO_RETURN_TYPE_BITS 8 + + // The OpType that says what sort of function we are. + uint32_t type_ : JITINFO_OP_TYPE_BITS; + + // The alias set for this op. This is a _minimal_ alias set; in + // particular for a method it does not include whatever argument + // conversions might do. That's covered by argTypes and runtime + // analysis of the actual argument types being passed in. + uint32_t aliasSet_ : JITINFO_ALIAS_SET_BITS; + + // The return type tag. Might be JSVAL_TYPE_UNKNOWN. + uint32_t returnType_ : JITINFO_RETURN_TYPE_BITS; + + static_assert(OpTypeCount <= (1 << JITINFO_OP_TYPE_BITS), + "Not enough space for OpType"); + static_assert(AliasSetCount <= (1 << JITINFO_ALIAS_SET_BITS), + "Not enough space for AliasSet"); + static_assert((sizeof(JSValueType) * 8) <= JITINFO_RETURN_TYPE_BITS, + "Not enough space for JSValueType"); + +#undef JITINFO_RETURN_TYPE_BITS +#undef JITINFO_ALIAS_SET_BITS +#undef JITINFO_OP_TYPE_BITS + + uint32_t isInfallible : 1; /* Is op fallible? False in setters. */ + uint32_t isMovable : 1; /* Is op movable? To be movable the op must + not AliasEverything, but even that might + not be enough (e.g. in cases when it can + throw). */ // XXXbz should we have a JSValueType for the type of the member? - bool isInSlot; /* True if this is a getter that can get a member - from a slot of the "this" object directly. */ - size_t slotIndex; /* If isMember is true, the index of the slot to get - the value from. Otherwise 0. */ - JSValueType returnType; /* The return type tag. Might be JSVAL_TYPE_UNKNOWN */ - - const ArgType* const argTypes; /* For a method, a list of sets of types that - the function expects. This can be used, - for example, to figure out when argument - coercions can have side-effects. nullptr - if we have no type information for - arguments. */ - - /* An alternative native that's safe to call in parallel mode. */ - JSParallelNative parallelNative; - -private: - static void staticAsserts() - { - JS_STATIC_ASSERT(Any & String); - JS_STATIC_ASSERT(Any & Integer); - JS_STATIC_ASSERT(Any & Double); - JS_STATIC_ASSERT(Any & Boolean); - JS_STATIC_ASSERT(Any & Object); - JS_STATIC_ASSERT(Any & Null); - } + uint32_t isAlwaysInSlot : 1; /* True if this is a getter that can always + get the value from a slot of the "this" + object. */ + uint32_t isLazilyCachedInSlot : 1; /* True if this is a getter that can + sometimes (if the slot doesn't contain + UndefinedValue()) get the value from a + slot of the "this" object. */ + uint32_t isTypedMethod : 1; /* True if this is an instance of + JSTypedMethodJitInfo. */ + uint32_t slotIndex : 11; /* If isAlwaysInSlot or isSometimesInSlot is + true, the index of the slot to get the value + from. Otherwise 0. */ }; -#define JS_JITINFO_NATIVE_PARALLEL(op) \ - {{nullptr},0,0,JSJitInfo::OpType_None,false,false,JSJitInfo::AliasEverything,false,0,JSVAL_TYPE_MISSING,nullptr,op} +static_assert(sizeof(JSJitInfo) == (sizeof(void*) + 2 * sizeof(uint32_t)), + "There are several thousand instances of JSJitInfo stored in " + "a binary. Please don't increase its space requirements without " + "verifying that there is no other way forward (better packing, " + "smaller datatypes for fields, subclassing, etc.)."); -static JS_ALWAYS_INLINE const JSJitInfo * +struct JSTypedMethodJitInfo +{ + // We use C-style inheritance here, rather than C++ style inheritance + // because not all compilers support brace-initialization for non-aggregate + // classes. Using C++ style inheritance and constructors instead of + // brace-initialization would also force the creation of static + // constructors (on some compilers) when JSJitInfo and JSTypedMethodJitInfo + // structures are declared. Since there can be several thousand of these + // structures present and we want to have roughly equivalent performance + // across a range of compilers, we do things manually. + JSJitInfo base; + + const JSJitInfo::ArgType* const argTypes; /* For a method, a list of sets of + types that the function + expects. This can be used, + for example, to figure out + when argument coercions can + have side-effects. */ +}; + +namespace JS { +namespace detail { + +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_PARALLEL_NATIVE_TO only. */ +inline int CheckIsParallelNative(JSParallelNative parallelNative); + +} // namespace detail +} // namespace JS + +#define JS_CAST_PARALLEL_NATIVE_TO(v, To) \ + (static_cast(sizeof(JS::detail::CheckIsParallelNative(v))), \ + reinterpret_cast(v)) + +/* + * You may ask yourself: why do we define a wrapper around a wrapper here? + * The answer is that some compilers don't understand initializing a union + * as we do below with a construct like: + * + * reinterpret_cast(JSParallelNativeThreadSafeWrapper) + * + * (We need the reinterpret_cast because we must initialize the union with + * a datum of the type of the union's first member.) + * + * Presumably this has something to do with template instantiation. + * Initializing with a normal function pointer seems to work fine. Hence + * the ugliness that you see before you. + */ +#define JS_JITINFO_NATIVE_PARALLEL(infoName, parallelOp) \ + const JSJitInfo infoName = \ + {{JS_CAST_PARALLEL_NATIVE_TO(parallelOp, JSJitGetterOp)},0,0,JSJitInfo::ParallelNative,JSJitInfo::AliasEverything,JSVAL_TYPE_MISSING,false,false,false,false,false,0} + +#define JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(infoName, wrapperName, serialOp) \ + bool wrapperName##_ParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, \ + JS::Value *vp) \ + { \ + return JSParallelNativeThreadSafeWrapper(cx, argc, vp); \ + } \ + JS_JITINFO_NATIVE_PARALLEL(infoName, wrapperName##_ParallelNativeThreadSafeWrapper) + +static MOZ_ALWAYS_INLINE const JSJitInfo * FUNCTION_VALUE_TO_JITINFO(const JS::Value& v) { JS_ASSERT(js::GetObjectClass(&v.toObject()) == js::FunctionClassPtr); @@ -1562,7 +2282,7 @@ FUNCTION_VALUE_TO_JITINFO(const JS::Value& v) /* Statically asserted in jsfun.h. */ static const unsigned JS_FUNCTION_INTERPRETED_BIT = 0x1; -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void SET_JITINFO(JSFunction * func, const JSJitInfo *info) { js::shadow::Function *fun = reinterpret_cast(func); @@ -1575,7 +2295,7 @@ SET_JITINFO(JSFunction * func, const JSJitInfo *info) * eliminate Gecko's dependencies on it! */ -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid JSID_FROM_BITS(size_t bits) { jsid id; @@ -1610,7 +2330,7 @@ bool IdMatchesAtom(jsid id, JSAtom *atom); * Thus, it is only the rare third case which needs this function, which * handles any JSAtom* that is known not to be representable with an int jsid. */ -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid NON_INTEGER_ATOM_TO_JSID(JSAtom *atom) { JS_ASSERT(((size_t)atom & 0x7) == 0); @@ -1620,19 +2340,19 @@ NON_INTEGER_ATOM_TO_JSID(JSAtom *atom) } /* All strings stored in jsids are atomized, but are not necessarily property names. */ -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ATOM(jsid id) { return JSID_IS_STRING(id); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ATOM(jsid id, JSAtom *atom) { return id == JSID_FROM_BITS((size_t)atom); } -static JS_ALWAYS_INLINE JSAtom * +static MOZ_ALWAYS_INLINE JSAtom * JSID_TO_ATOM(jsid id) { return (JSAtom *)JSID_TO_STRING(id); @@ -1642,31 +2362,19 @@ JS_STATIC_ASSERT(sizeof(jsid) == sizeof(void*)); namespace js { -static JS_ALWAYS_INLINE JS::Value +static MOZ_ALWAYS_INLINE JS::Value IdToValue(jsid id) { if (JSID_IS_STRING(id)) return JS::StringValue(JSID_TO_STRING(id)); - if (JS_LIKELY(JSID_IS_INT(id))) + if (JSID_IS_INT(id)) return JS::Int32Value(JSID_TO_INT(id)); - if (JS_LIKELY(JSID_IS_OBJECT(id))) - return JS::ObjectValue(*JSID_TO_OBJECT(id)); + if (JSID_IS_SYMBOL(id)) + return JS::SymbolValue(JSID_TO_SYMBOL(id)); JS_ASSERT(JSID_IS_VOID(id)); return JS::UndefinedValue(); } -static JS_ALWAYS_INLINE jsval -IdToJsval(jsid id) -{ - return IdToValue(id); -} - -extern JS_FRIEND_API(bool) -IsReadOnlyDateMethod(JS::IsAcceptableThis test, JS::NativeImpl method); - -extern JS_FRIEND_API(bool) -IsTypedArrayThisCheck(JS::IsAcceptableThis test); - /* * If the embedder has registered a default JSContext callback, returns the * result of the callback. Otherwise, asserts that |rt| has exactly one @@ -1681,6 +2389,21 @@ typedef JSContext* JS_FRIEND_API(void) SetDefaultJSContextCallback(JSRuntime *rt, DefaultJSContextCallback cb); +/* + * To help embedders enforce their invariants, we allow them to specify in + * advance which JSContext should be passed to JSAPI calls. If this is set + * to a non-null value, the assertSameCompartment machinery does double- + * duty (in debug builds) to verify that it matches the cx being used. + */ +#ifdef DEBUG +JS_FRIEND_API(void) +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx); +#else +inline void +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx) {}; +#endif + + enum CTypesActivityType { CTYPES_CALL_BEGIN, CTYPES_CALL_END, @@ -1720,13 +2443,6 @@ class JS_FRIEND_API(AutoCTypesActivityCallback) { } }; -#ifdef DEBUG -extern JS_FRIEND_API(void) -assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id); -#else -inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id) {}; -#endif - typedef bool (* ObjectMetadataCallback)(JSContext *cx, JSObject **pmetadata); @@ -1747,6 +2463,13 @@ SetObjectMetadata(JSContext *cx, JS::HandleObject obj, JS::HandleObject metadata JS_FRIEND_API(JSObject *) GetObjectMetadata(JSObject *obj); +JS_FRIEND_API(void) +UnsafeDefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value); + +JS_FRIEND_API(bool) +SliceSlowly(JSContext* cx, JS::HandleObject obj, JS::HandleObject receiver, + uint32_t begin, uint32_t end, JS::HandleObject result); + /* ES5 8.12.8. */ extern JS_FRIEND_API(bool) DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandleValue vp); @@ -1766,7 +2489,43 @@ DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandle */ extern JS_FRIEND_API(bool) CheckDefineProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +/* + * Helper function for HTMLDocument and HTMLFormElement. + * + * These are the only two interfaces that have [OverrideBuiltins], a named + * getter, and no named setter. They're implemented as proxies with a custom + * getOwnPropertyDescriptor() method. Unfortunately, overriding + * getOwnPropertyDescriptor() automatically affects the behavior of set(), + * which normally is just common sense but is *not* desired for these two + * interfaces. + * + * The fix is for these two interfaces to override set() to ignore the + * getOwnPropertyDescriptor() override. + * + * SetPropertyIgnoringNamedGetter is exposed to make it easier to override + * set() in this way. It carries out all the steps of BaseProxyHandler::set() + * except the initial getOwnPropertyDescriptor()/getPropertyDescriptor() calls. + * The caller must supply those results as the 'desc' and 'descIsOwn' + * parameters. + * + * Implemented in jsproxy.cpp. + */ +JS_FRIEND_API(bool) +SetPropertyIgnoringNamedGetter(JSContext *cx, const BaseProxyHandler *handler, + JS::HandleObject proxy, JS::HandleObject receiver, + JS::HandleId id, JS::MutableHandle desc, + bool descIsOwn, bool strict, JS::MutableHandleValue vp); + +JS_FRIEND_API(void) +ReportErrorWithId(JSContext *cx, const char *msg, JS::HandleId id); + +// This function is for one specific use case, please don't use this for anything else! +extern JS_FRIEND_API(bool) +ExecuteInGlobalAndReturnScope(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleObject scope); } /* namespace js */ @@ -1775,27 +2534,27 @@ js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg, JS::Handle descriptor, bool *bp); extern JS_FRIEND_API(bool) -js_ReportIsNotFunction(JSContext *cx, const JS::Value& v); +js_ReportIsNotFunction(JSContext *cx, JS::HandleValue v); #ifdef JSGC_GENERATIONAL extern JS_FRIEND_API(void) JS_StoreObjectPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSObject *key, void *data), JSObject *key, void *data); extern JS_FRIEND_API(void) JS_StoreStringPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSString *key, void *data), JSString *key, void *data); #else inline void JS_StoreObjectPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSObject *key, void *data), JSObject *key, void *data) {} inline void JS_StoreStringPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSString *key, void *data), JSString *key, void *data) {} #endif /* JSGC_GENERATIONAL */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/jsperf.h b/frameworks/js-bindings/external/spidermonkey/include/mac/jsperf.h index e3cbc23143..60c572f559 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/jsperf.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/jsperf.h @@ -88,7 +88,7 @@ class JS_FRIEND_API(PerfMeasurement) * then the eventsMeasured bitmask will only include the subset of * |toMeasure| corresponding to the events that can be measured. */ - PerfMeasurement(EventMask toMeasure); + explicit PerfMeasurement(EventMask toMeasure); /* Done with this set of measurements, tear down OS-level state. */ ~PerfMeasurement(); @@ -118,7 +118,7 @@ class JS_FRIEND_API(PerfMeasurement) * global object). The JS-visible API is identical to the C++ API. */ extern JS_FRIEND_API(JSObject*) - RegisterPerfMeasurement(JSContext *cx, JSObject *global); + RegisterPerfMeasurement(JSContext *cx, JS::HandleObject global); /* * Given a Value which contains an instance of the aforementioned diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/jsprf.h b/frameworks/js-bindings/external/spidermonkey/include/mac/jsprf.h index b235f0b4fb..bfedf98ca8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/jsprf.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/jsprf.h @@ -57,23 +57,11 @@ extern JS_PUBLIC_API(void) JS_smprintf_free(char *mem); */ extern JS_PUBLIC_API(char*) JS_sprintf_append(char *last, const char *fmt, ...); -/* -** sprintf into a function. The function "f" is called with a string to -** place into the output. "arg" is an opaque pointer used by the stuff -** function to hold any state needed to do the storage of the output -** data. The return value is a count of the number of characters fed to -** the stuff function, or (uint32_t)-1 if an error occurs. -*/ -typedef int (*JSStuffFunc)(void *arg, const char *s, uint32_t slen); - -extern JS_PUBLIC_API(uint32_t) JS_sxprintf(JSStuffFunc f, void *arg, const char *fmt, ...); - /* ** va_list forms of the above. */ extern JS_PUBLIC_API(uint32_t) JS_vsnprintf(char *out, uint32_t outlen, const char *fmt, va_list ap); extern JS_PUBLIC_API(char*) JS_vsmprintf(const char *fmt, va_list ap); extern JS_PUBLIC_API(char*) JS_vsprintf_append(char *last, const char *fmt, va_list ap); -extern JS_PUBLIC_API(uint32_t) JS_vsxprintf(JSStuffFunc f, void *arg, const char *fmt, va_list ap); #endif /* jsprf_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/jsprototypes.h b/frameworks/js-bindings/external/spidermonkey/include/mac/jsprototypes.h index bc4a767033..1cb56bf8da 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/jsprototypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/jsprototypes.h @@ -34,7 +34,7 @@ #define CLASP(name) (&name##Class) #define OCLASP(name) (&name##Object::class_) -#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[ScalarTypeRepresentation::type]) +#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[Scalar::type]) #ifdef ENABLE_PARALLEL_JS #define IF_PJS(real,imaginary) real @@ -54,47 +54,61 @@ #define IF_BDATA(real,imaginary) imaginary #endif +#ifdef ENABLE_SHARED_ARRAY_BUFFER +#define IF_SAB(real,imaginary) real +#else +#define IF_SAB(real,imaginary) imaginary +#endif + +#ifdef JS_HAS_SYMBOLS +#define IF_SYMBOLS(real,imaginary) real +#else +#define IF_SYMBOLS(real,imaginary) imaginary +#endif + #define JS_FOR_PROTOTYPES(real,imaginary) \ imaginary(Null, 0, js_InitNullClass, dummy) \ - real(Object, 1, js_InitObjectClass, &JSObject::class_) \ - real(Function, 2, js_InitFunctionClass, &JSFunction::class_) \ - real(Array, 3, js_InitArrayClass, OCLASP(Array)) \ + real(Object, 1, js_InitViaClassSpec, &JSObject::class_) \ + real(Function, 2, js_InitViaClassSpec, &JSFunction::class_) \ + real(Array, 3, js_InitViaClassSpec, OCLASP(Array)) \ real(Boolean, 4, js_InitBooleanClass, OCLASP(Boolean)) \ real(JSON, 5, js_InitJSONClass, CLASP(JSON)) \ - real(Date, 6, js_InitDateClass, OCLASP(Date)) \ + real(Date, 6, js_InitViaClassSpec, OCLASP(Date)) \ real(Math, 7, js_InitMathClass, CLASP(Math)) \ real(Number, 8, js_InitNumberClass, OCLASP(Number)) \ real(String, 9, js_InitStringClass, OCLASP(String)) \ real(RegExp, 10, js_InitRegExpClass, OCLASP(RegExp)) \ - real(Error, 11, js_InitExceptionClasses, OCLASP(Error)) \ - real(InternalError, 12, js_InitExceptionClasses, OCLASP(Error)) \ - real(EvalError, 13, js_InitExceptionClasses, OCLASP(Error)) \ - real(RangeError, 14, js_InitExceptionClasses, OCLASP(Error)) \ - real(ReferenceError, 15, js_InitExceptionClasses, OCLASP(Error)) \ - real(SyntaxError, 16, js_InitExceptionClasses, OCLASP(Error)) \ - real(TypeError, 17, js_InitExceptionClasses, OCLASP(Error)) \ - real(URIError, 18, js_InitExceptionClasses, OCLASP(Error)) \ + real(Error, 11, js_InitViaClassSpec, OCLASP(Error)) \ + real(InternalError, 12, js_InitViaClassSpec, OCLASP(Error)) \ + real(EvalError, 13, js_InitViaClassSpec, OCLASP(Error)) \ + real(RangeError, 14, js_InitViaClassSpec, OCLASP(Error)) \ + real(ReferenceError, 15, js_InitViaClassSpec, OCLASP(Error)) \ + real(SyntaxError, 16, js_InitViaClassSpec, OCLASP(Error)) \ + real(TypeError, 17, js_InitViaClassSpec, OCLASP(Error)) \ + real(URIError, 18, js_InitViaClassSpec, OCLASP(Error)) \ real(Iterator, 19, js_InitIteratorClasses, OCLASP(PropertyIterator)) \ real(StopIteration, 20, js_InitIteratorClasses, OCLASP(StopIteration)) \ - real(ArrayBuffer, 21, js_InitTypedArrayClasses, &js::ArrayBufferObject::protoClass) \ - real(Int8Array, 22, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT8)) \ - real(Uint8Array, 23, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT8)) \ - real(Int16Array, 24, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT16)) \ - real(Uint16Array, 25, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT16)) \ - real(Int32Array, 26, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT32)) \ - real(Uint32Array, 27, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT32)) \ - real(Float32Array, 28, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_FLOAT32)) \ - real(Float64Array, 29, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_FLOAT64)) \ - real(Uint8ClampedArray, 30, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT8_CLAMPED)) \ + real(ArrayBuffer, 21, js_InitArrayBufferClass, &js::ArrayBufferObject::protoClass) \ + real(Int8Array, 22, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int8)) \ + real(Uint8Array, 23, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8)) \ + real(Int16Array, 24, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int16)) \ + real(Uint16Array, 25, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint16)) \ + real(Int32Array, 26, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int32)) \ + real(Uint32Array, 27, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint32)) \ + real(Float32Array, 28, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float32)) \ + real(Float64Array, 29, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float64)) \ + real(Uint8ClampedArray, 30, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8Clamped)) \ real(Proxy, 31, js_InitProxyClass, &ProxyObject::uncallableClass_) \ real(WeakMap, 32, js_InitWeakMapClass, OCLASP(WeakMap)) \ real(Map, 33, js_InitMapClass, OCLASP(Map)) \ real(Set, 34, js_InitSetClass, OCLASP(Set)) \ - real(DataView, 35, js_InitTypedArrayClasses, OCLASP(DataView)) \ -IF_PJS(real,imaginary) (ParallelArray, 36, js_InitParallelArrayClass, OCLASP(ParallelArray)) \ -IF_INTL(real,imaginary) (Intl, 37, js_InitIntlClass, CLASP(Intl)) \ -IF_BDATA(real,imaginary)(TypedObject, 38, js_InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \ - imaginary(GeneratorFunction, 39, js_InitIteratorClasses, dummy) \ + real(DataView, 35, js_InitDataViewClass, OCLASP(DataView)) \ +IF_SYMBOLS(real,imaginary)(Symbol, 36, js_InitSymbolClass, &js::SymbolObject::class_) \ +IF_SAB(real,imaginary)(SharedArrayBuffer, 37, js_InitSharedArrayBufferClass, &js::SharedArrayBufferObject::protoClass) \ +IF_INTL(real,imaginary) (Intl, 38, js_InitIntlClass, CLASP(Intl)) \ +IF_BDATA(real,imaginary)(TypedObject, 39, js_InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \ + imaginary(GeneratorFunction, 40, js_InitIteratorClasses, dummy) \ +IF_BDATA(real,imaginary)(SIMD, 41, js_InitSIMDClass, OCLASP(SIMD)) \ #define JS_FOR_EACH_PROTOTYPE(macro) JS_FOR_PROTOTYPES(macro,macro) diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/jsproxy.h b/frameworks/js-bindings/external/spidermonkey/include/mac/jsproxy.h index 3d2ea81cb3..b4588c4c2a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/jsproxy.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/jsproxy.h @@ -47,6 +47,22 @@ class JS_FRIEND_API(Wrapper); * BaseProxyHandler provides implementations of the derived traps in terms of * the (pure virtual) fundamental traps. * + * In addition to the normal traps, there are two models for proxy prototype + * chains. First, proxies may opt to use the standard prototype mechanism used + * throughout the engine. To do so, simply pass a prototype to NewProxyObject() + * at creation time. All prototype accesses will then "just work" to treat the + * proxy as a "normal" object. Alternatively, if instead the proxy wishes to + * implement more complicated prototype semantics (if, for example, it wants to + * delegate the prototype lookup to a wrapped object), it may pass Proxy::LazyProto + * as the prototype at create time and opt in to the trapped prototype system, + * which guarantees that their trap will be called on any and every prototype + * chain access of the object. + * + * This system is implemented with two traps: {get,set}PrototypeOf. The default + * implementation of setPrototypeOf throws a TypeError. Since it is not possible + * to create an object without a sense of prototype chain, handler implementors + * must provide a getPrototypeOf trap if opting in to the dynamic prototype system. + * * To minimize code duplication, a set of abstract proxy handler classes is * provided, from which other handlers may inherit. These abstract classes * are organized in the following hierarchy: @@ -72,37 +88,55 @@ class JS_FRIEND_API(Wrapper); class JS_FRIEND_API(BaseProxyHandler) { const void *mFamily; + + /* + * Proxy handlers can use mHasPrototype to request the following special + * treatment from the JS engine: + * + * - When mHasPrototype is true, the engine never calls these methods: + * getPropertyDescriptor, has, set, enumerate, iterate. Instead, for + * these operations, it calls the "own" traps like + * getOwnPropertyDescriptor, hasOwn, defineProperty, keys, etc., and + * consults the prototype chain if needed. + * + * - When mHasPrototype is true, the engine calls handler->get() only if + * handler->hasOwn() says an own property exists on the proxy. If not, + * it consults the prototype chain. + * + * This is useful because it frees the ProxyHandler from having to implement + * any behavior having to do with the prototype chain. + */ bool mHasPrototype; - bool mHasPolicy; - protected: - // Subclasses may set this in their constructor. - void setHasPrototype(bool aHasPrototype) { mHasPrototype = aHasPrototype; } - void setHasPolicy(bool aHasPolicy) { mHasPolicy = aHasPolicy; } + + /* + * All proxies indicate whether they have any sort of interesting security + * policy that might prevent the caller from doing something it wants to + * the object. In the case of wrappers, this distinction is used to + * determine whether the caller may strip off the wrapper if it so desires. + */ + bool mHasSecurityPolicy; public: - explicit BaseProxyHandler(const void *family); + explicit BaseProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); virtual ~BaseProxyHandler(); - bool hasPrototype() { + bool hasPrototype() const { return mHasPrototype; } - bool hasPolicy() { - return mHasPolicy; + bool hasSecurityPolicy() const { + return mHasSecurityPolicy; } - inline const void *family() { + inline const void *family() const { return mFamily; } static size_t offsetOfFamily() { return offsetof(BaseProxyHandler, mFamily); } - virtual bool isOuterWindow() { - return false; - } - - virtual bool finalizeInBackground(Value priv) { + virtual bool finalizeInBackground(Value priv) const { /* * Called on creation of a proxy to determine whether its finalize * method can be finalized on the background thread. @@ -119,66 +153,75 @@ class JS_FRIEND_API(BaseProxyHandler) * The |act| parameter to enter() specifies the action being performed. * If |bp| is false, the trap suggests that the caller throw (though it * may still decide to squelch the error). + * + * We make these OR-able so that assertEnteredPolicy can pass a union of them. + * For example, get{,Own}PropertyDescriptor is invoked by both calls to ::get() + * and ::set() (since we need to look up the accessor), so its + * assertEnteredPolicy would pass GET | SET. */ - enum Action { - GET, - SET, - CALL + typedef uint32_t Action; + enum { + NONE = 0x00, + GET = 0x01, + SET = 0x02, + CALL = 0x04, + ENUMERATE = 0x08 }; + virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Action act, - bool *bp); + bool *bp) const; /* ES5 Harmony fundamental proxy traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) = 0; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const = 0; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, - unsigned flags) = 0; + MutableHandle desc) const = 0; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, - HandleId id, MutableHandle desc, - unsigned flags) = 0; + HandleId id, MutableHandle desc) const = 0; virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc) = 0; + MutableHandle desc) const = 0; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, - AutoIdVector &props) = 0; - virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) = 0; - virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) = 0; + AutoIdVector &props) const = 0; + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const = 0; + virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) const = 0; /* ES5 Harmony derived proxy traps. */ - virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); - virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); + virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; + virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, MutableHandleValue vp); + HandleId id, MutableHandleValue vp) const; virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp); - virtual bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props); + HandleId id, bool strict, MutableHandleValue vp) const; + virtual bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props) const; virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, - MutableHandleValue vp); + MutableHandleValue vp) const; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) = 0; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args); - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args); - virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args); - virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp); - virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx); - virtual const char *className(JSContext *cx, HandleObject proxy); - virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent); - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g); - virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); - virtual void finalize(JSFreeOp *fop, JSObject *proxy); - virtual bool getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver, - uint32_t index, MutableHandleValue vp, bool *present); - virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const = 0; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args) const; + virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp) const; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx) const; + virtual const char *className(JSContext *cx, HandleObject proxy) const; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const; + virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp) const; + virtual void finalize(JSFreeOp *fop, JSObject *proxy) const; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop) const; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp) const; // These two hooks must be overridden, or not overridden, in tandem -- no // overriding just one! virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable); - virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id); + JS::HandleObject callable) const; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const; + + virtual bool slice(JSContext *cx, HandleObject proxy, uint32_t begin, uint32_t end, + HandleObject result) const; /* See comment for weakmapKeyDelegateOp in js/Class.h. */ - virtual JSObject *weakmapKeyDelegate(JSObject *proxy); - virtual bool isScripted() { return false; } + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const; + virtual bool isScripted() const { return false; } }; /* @@ -194,54 +237,58 @@ class JS_FRIEND_API(BaseProxyHandler) class JS_PUBLIC_API(DirectProxyHandler) : public BaseProxyHandler { public: - explicit DirectProxyHandler(const void *family); + explicit DirectProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); /* ES5 Harmony fundamental proxy traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags) MOZ_OVERRIDE; - virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, - HandleId id, MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool enumerate(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; /* ES5 Harmony derived proxy traps. */ virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool keys(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, - unsigned indent) MOZ_OVERRIDE; + unsigned indent) const MOZ_OVERRIDE; virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, - RegExpGuard *g) MOZ_OVERRIDE; - virtual JSObject *weakmapKeyDelegate(JSObject *proxy); + RegExpGuard *g) const MOZ_OVERRIDE; + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const MOZ_OVERRIDE; }; /* @@ -257,16 +304,15 @@ class Proxy /* ES5 Harmony fundamental proxy traps. */ static bool preventExtensions(JSContext *cx, HandleObject proxy); static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags); - static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, unsigned flags, HandleId id, + MutableHandle desc); + static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, MutableHandleValue vp); static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags); - static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, unsigned flags, HandleId id, + MutableHandle desc); + static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, MutableHandleValue vp); static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, MutableHandle desc); - static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, HandleValue v); static bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props); static bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); static bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props); @@ -276,8 +322,6 @@ class Proxy static bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); static bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, MutableHandleValue vp); - static bool getElementIfPresent(JSContext *cx, HandleObject proxy, HandleObject receiver, - uint32_t index, MutableHandleValue vp, bool *present); static bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, bool strict, MutableHandleValue vp); static bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props); @@ -295,44 +339,26 @@ class Proxy static bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g); static bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); static bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + static bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp); - static bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable); - static bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id); + static bool watch(JSContext *cx, HandleObject proxy, HandleId id, HandleObject callable); + static bool unwatch(JSContext *cx, HandleObject proxy, HandleId id); + + static bool slice(JSContext *cx, HandleObject obj, uint32_t begin, uint32_t end, + HandleObject result); /* IC entry path for handling __noSuchMethod__ on access. */ static bool callProp(JSContext *cx, HandleObject proxy, HandleObject reveiver, HandleId id, MutableHandleValue vp); - - static JSObject * const LazyProto; }; // Use these in places where you don't want to #include vm/ProxyObject.h. extern JS_FRIEND_DATA(const js::Class* const) CallableProxyClassPtr; extern JS_FRIEND_DATA(const js::Class* const) UncallableProxyClassPtr; -extern JS_FRIEND_DATA(const js::Class* const) OuterWindowProxyClassPtr; - -inline bool IsProxyClass(const Class *clasp) -{ - return clasp == CallableProxyClassPtr || - clasp == UncallableProxyClassPtr || - clasp == OuterWindowProxyClassPtr; -} inline bool IsProxy(JSObject *obj) { - return IsProxyClass(GetObjectClass(obj)); -} - -BaseProxyHandler * -GetProxyHandler(JSObject *obj); - -inline bool IsScriptedProxy(JSObject *obj) -{ - if (!IsProxy(obj)) - return false; - - return GetProxyHandler(obj)->isScripted(); + return GetObjectClass(obj)->isProxy(); } /* @@ -343,15 +369,16 @@ inline bool IsScriptedProxy(JSObject *obj) * needs to store one slot's worth of data doesn't need to branch on what sort * of object it has. */ -const uint32_t PROXY_PRIVATE_SLOT = 0; -const uint32_t PROXY_HANDLER_SLOT = 1; -const uint32_t PROXY_EXTRA_SLOT = 2; +const uint32_t PROXY_PRIVATE_SLOT = 0; +const uint32_t PROXY_HANDLER_SLOT = 1; +const uint32_t PROXY_EXTRA_SLOT = 2; +const uint32_t PROXY_MINIMUM_SLOTS = 4; -inline BaseProxyHandler * +inline const BaseProxyHandler * GetProxyHandler(JSObject *obj) { JS_ASSERT(IsProxy(obj)); - return (BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate(); + return (const BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate(); } inline const Value & @@ -390,17 +417,24 @@ SetProxyExtra(JSObject *obj, size_t n, const Value &extra) SetReservedSlot(obj, PROXY_EXTRA_SLOT + n, extra); } +inline bool +IsScriptedProxy(JSObject *obj) +{ + return IsProxy(obj) && GetProxyHandler(obj)->isScripted(); +} + class MOZ_STACK_CLASS ProxyOptions { - public: - ProxyOptions() : callable_(false), - singleton_(false) + protected: + /* protected constructor for subclass */ + ProxyOptions(bool singletonArg, const Class *claspArg) + : singleton_(singletonArg), + clasp_(claspArg) {} - bool callable() const { return callable_; } - ProxyOptions &setCallable(bool flag) { - callable_ = flag; - return *this; - } + public: + ProxyOptions() : singleton_(false), + clasp_(UncallableProxyClassPtr) + {} bool singleton() const { return singleton_; } ProxyOptions &setSingleton(bool flag) { @@ -408,13 +442,26 @@ class MOZ_STACK_CLASS ProxyOptions { return *this; } + const Class *clasp() const { + return clasp_; + } + ProxyOptions &setClass(const Class *claspArg) { + clasp_ = claspArg; + return *this; + } + ProxyOptions &selectDefaultClass(bool callable) { + const Class *classp = callable? CallableProxyClassPtr : + UncallableProxyClassPtr; + return setClass(classp); + } + private: - bool callable_; bool singleton_; + const Class *clasp_; }; JS_FRIEND_API(JSObject *) -NewProxyObject(JSContext *cx, BaseProxyHandler *handler, HandleValue priv, +NewProxyObject(JSContext *cx, const BaseProxyHandler *handler, HandleValue priv, JSObject *proto, JSObject *parent, const ProxyOptions &options = ProxyOptions()); JSObject * @@ -424,15 +471,15 @@ class JS_FRIEND_API(AutoEnterPolicy) { public: typedef BaseProxyHandler::Action Action; - AutoEnterPolicy(JSContext *cx, BaseProxyHandler *handler, + AutoEnterPolicy(JSContext *cx, const BaseProxyHandler *handler, HandleObject wrapper, HandleId id, Action act, bool mayThrow) -#ifdef DEBUG +#ifdef JS_DEBUG : context(nullptr) #endif { - allow = handler->hasPolicy() ? handler->enter(cx, wrapper, id, act, &rv) - : true; - recordEnter(cx, wrapper, id); + allow = handler->hasSecurityPolicy() ? handler->enter(cx, wrapper, id, act, &rv) + : true; + recordEnter(cx, wrapper, id, act); // We want to throw an exception if all of the following are true: // * The policy disallowed access. // * The policy set rv to false, indicating that we should throw. @@ -449,48 +496,65 @@ class JS_FRIEND_API(AutoEnterPolicy) protected: // no-op constructor for subclass AutoEnterPolicy() -#ifdef DEBUG +#ifdef JS_DEBUG : context(nullptr) + , enteredAction(BaseProxyHandler::NONE) #endif {}; void reportErrorIfExceptionIsNotPending(JSContext *cx, jsid id); bool allow; bool rv; -#ifdef DEBUG +#ifdef JS_DEBUG JSContext *context; mozilla::Maybe enteredProxy; mozilla::Maybe enteredId; + Action enteredAction; + // NB: We explicitly don't track the entered action here, because sometimes // SET traps do an implicit GET during their implementation, leading to // spurious assertions. AutoEnterPolicy *prev; - void recordEnter(JSContext *cx, HandleObject proxy, HandleId id); + void recordEnter(JSContext *cx, HandleObject proxy, HandleId id, Action act); void recordLeave(); - friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id); + friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id, Action act); #else - inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id) {} + inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id, Action act) {} inline void recordLeave() {} #endif }; -#ifdef DEBUG +#ifdef JS_DEBUG class JS_FRIEND_API(AutoWaivePolicy) : public AutoEnterPolicy { public: - AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id) + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) { allow = true; - recordEnter(cx, proxy, id); + recordEnter(cx, proxy, id, act); } }; #else class JS_FRIEND_API(AutoWaivePolicy) { - public: AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id) {}; + public: + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) + {} }; #endif +#ifdef JS_DEBUG +extern JS_FRIEND_API(void) +assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act); +#else +inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act) +{}; +#endif + } /* namespace js */ extern JS_FRIEND_API(JSObject *) diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/jspubtd.h b/frameworks/js-bindings/external/spidermonkey/include/mac/jspubtd.h index 9683c23ea4..ffd75e2e5c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/jspubtd.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/jspubtd.h @@ -11,6 +11,7 @@ * JS public API typedefs. */ +#include "mozilla/Assertions.h" #include "mozilla/LinkedList.h" #include "mozilla/NullPtr.h" #include "mozilla/PodOperations.h" @@ -20,7 +21,7 @@ #include "js/TypeDecls.h" -#if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING) || defined(DEBUG) +#if defined(JSGC_USE_EXACT_ROOTING) || defined(JS_DEBUG) # define JSGC_TRACK_EXACT_ROOTS #endif @@ -32,23 +33,25 @@ class CallArgs; template class Rooted; -class JS_PUBLIC_API(AutoGCRooter); - -class JS_PUBLIC_API(CompileOptions); -class JS_PUBLIC_API(ReadOnlyCompileOptions); -class JS_PUBLIC_API(OwningCompileOptions); +class JS_FRIEND_API(CompileOptions); +class JS_FRIEND_API(ReadOnlyCompileOptions); +class JS_FRIEND_API(OwningCompileOptions); class JS_PUBLIC_API(CompartmentOptions); struct Zone; } /* namespace JS */ +namespace js { +struct ContextFriendFields; +} // namespace js + /* * Run-time version enumeration. For compile-time version checking, please use * the JS_HAS_* macros in jsversion.h, or use MOZJS_MAJOR_VERSION, * MOZJS_MINOR_VERSION, MOZJS_PATCH_VERSION, and MOZJS_ALPHA definitions. */ -typedef enum JSVersion { +enum JSVersion { JSVERSION_ECMA_3 = 148, JSVERSION_1_6 = 160, JSVERSION_1_7 = 170, @@ -57,10 +60,10 @@ typedef enum JSVersion { JSVERSION_DEFAULT = 0, JSVERSION_UNKNOWN = -1, JSVERSION_LATEST = JSVERSION_ECMA_5 -} JSVersion; +}; /* Result of typeof operator enumeration. */ -typedef enum JSType { +enum JSType { JSTYPE_VOID, /* undefined */ JSTYPE_OBJECT, /* object */ JSTYPE_FUNCTION, /* function */ @@ -68,44 +71,23 @@ typedef enum JSType { JSTYPE_NUMBER, /* number */ JSTYPE_BOOLEAN, /* boolean */ JSTYPE_NULL, /* null */ + JSTYPE_SYMBOL, /* symbol */ JSTYPE_LIMIT -} JSType; +}; /* Dense index into cached prototypes and class atoms for standard objects. */ -typedef enum JSProtoKey { +enum JSProtoKey { #define PROTOKEY_AND_INITIALIZER(name,code,init,clasp) JSProto_##name = code, JS_FOR_EACH_PROTOTYPE(PROTOKEY_AND_INITIALIZER) #undef PROTOKEY_AND_INITIALIZER JSProto_LIMIT -} JSProtoKey; - -/* js_CheckAccess mode enumeration. */ -typedef enum JSAccessMode { - JSACC_PROTO = 0, /* XXXbe redundant w.r.t. id */ - - /* - * enum value #1 formerly called JSACC_PARENT, - * gap preserved for ABI compatibility. - */ - - /* - * enum value #2 formerly called JSACC_IMPORT, - * gap preserved for ABI compatibility. - */ - - JSACC_WATCH = 3, /* a watchpoint on object foo for id 'bar' */ - JSACC_READ = 4, /* a "get" of foo.bar */ - JSACC_WRITE = 8, /* a "set" of foo.bar = baz */ - JSACC_LIMIT -} JSAccessMode; - -#define JSACC_TYPEMASK (JSACC_WRITE - 1) +}; /* * This enum type is used to control the behavior of a JSObject property * iterator function that has type JSNewEnumerate. */ -typedef enum JSIterateOp { +enum JSIterateOp { /* Create new iterator state over enumerable properties. */ JSENUMERATE_INIT, @@ -117,12 +99,13 @@ typedef enum JSIterateOp { /* Destroy iterator state. */ JSENUMERATE_DESTROY -} JSIterateOp; +}; -/* See JSVAL_TRACE_KIND and JSTraceCallback in jsapi.h. */ -typedef enum { +/* See Value::gcKind() and JSTraceCallback in Tracer.h. */ +enum JSGCTraceKind { JSTRACE_OBJECT, JSTRACE_STRING, + JSTRACE_SYMBOL, JSTRACE_SCRIPT, /* @@ -130,37 +113,36 @@ typedef enum { * it implements JSTraceCallback. */ JSTRACE_LAZY_SCRIPT, - JSTRACE_IONCODE, + JSTRACE_JITCODE, JSTRACE_SHAPE, JSTRACE_BASE_SHAPE, JSTRACE_TYPE_OBJECT, JSTRACE_LAST = JSTRACE_TYPE_OBJECT -} JSGCTraceKind; - -/* Struct typedefs and class forward declarations. */ -typedef struct JSClass JSClass; -typedef struct JSCompartment JSCompartment; -typedef struct JSConstDoubleSpec JSConstDoubleSpec; -typedef struct JSCrossCompartmentCall JSCrossCompartmentCall; -typedef struct JSErrorReport JSErrorReport; -typedef struct JSExceptionState JSExceptionState; -typedef struct JSFunctionSpec JSFunctionSpec; -typedef struct JSIdArray JSIdArray; -typedef struct JSLocaleCallbacks JSLocaleCallbacks; -typedef struct JSObjectMap JSObjectMap; -typedef struct JSPrincipals JSPrincipals; -typedef struct JSPropertyDescriptor JSPropertyDescriptor; -typedef struct JSPropertyName JSPropertyName; -typedef struct JSPropertySpec JSPropertySpec; -typedef struct JSRuntime JSRuntime; -typedef struct JSSecurityCallbacks JSSecurityCallbacks; -typedef struct JSStructuredCloneCallbacks JSStructuredCloneCallbacks; -typedef struct JSStructuredCloneReader JSStructuredCloneReader; -typedef struct JSStructuredCloneWriter JSStructuredCloneWriter; -typedef struct JSTracer JSTracer; - -class JSFlatString; -class JSStableString; // long story +}; + +/* Struct forward declarations. */ +struct JSClass; +struct JSCompartment; +struct JSConstDoubleSpec; +struct JSCrossCompartmentCall; +struct JSErrorReport; +struct JSExceptionState; +struct JSFunctionSpec; +struct JSIdArray; +struct JSLocaleCallbacks; +struct JSObjectMap; +struct JSPrincipals; +struct JSPropertyDescriptor; +struct JSPropertyName; +struct JSPropertySpec; +struct JSRuntime; +struct JSSecurityCallbacks; +struct JSStructuredCloneCallbacks; +struct JSStructuredCloneReader; +struct JSStructuredCloneWriter; +class JS_PUBLIC_API(JSTracer); + +class JSFlatString; #ifdef JS_THREADSAFE typedef struct PRCallOnceType JSCallOnceType; @@ -182,6 +164,7 @@ namespace js { namespace gc { class StoreBuffer; void MarkPersistentRootedChains(JSTracer *); +void FinishPersistentRootedChains(JSRuntime *); } } @@ -197,24 +180,18 @@ struct Runtime bool needsBarrier_; #ifdef JSGC_GENERATIONAL - /* Allow inlining of Nursery::isInside. */ - uintptr_t gcNurseryStart_; - uintptr_t gcNurseryEnd_; - private: js::gc::StoreBuffer *gcStoreBufferPtr_; #endif public: - Runtime( + explicit Runtime( #ifdef JSGC_GENERATIONAL js::gc::StoreBuffer *storeBuffer #endif ) : needsBarrier_(false) #ifdef JSGC_GENERATIONAL - , gcNurseryStart_(0) - , gcNurseryEnd_(0) , gcStoreBufferPtr_(storeBuffer) #endif {} @@ -235,7 +212,7 @@ struct Runtime private: template friend class JS::PersistentRooted; friend void js::gc::MarkPersistentRootedChains(JSTracer *); - friend void ::js_FinishGC(JSRuntime *rt); + friend void js::gc::FinishPersistentRootedChains(JSRuntime *rt); mozilla::LinkedList functionPersistentRooteds; mozilla::LinkedList idPersistentRooteds; @@ -274,6 +251,75 @@ inline mozilla::LinkedList &Runtime::getPersistentRootedList() { return valuePersistentRooteds; } } /* namespace shadow */ + +class JS_PUBLIC_API(AutoGCRooter) +{ + public: + AutoGCRooter(JSContext *cx, ptrdiff_t tag); + AutoGCRooter(js::ContextFriendFields *cx, ptrdiff_t tag); + + ~AutoGCRooter() { + MOZ_ASSERT(this == *stackTop); + *stackTop = down; + } + + /* Implemented in gc/RootMarking.cpp. */ + inline void trace(JSTracer *trc); + static void traceAll(JSTracer *trc); + static void traceAllWrappers(JSTracer *trc); + + /* T must be a context type */ + template + static void traceAllInContext(T* cx, JSTracer *trc) { + for (AutoGCRooter *gcr = cx->autoGCRooters; gcr; gcr = gcr->down) + gcr->trace(trc); + } + + protected: + AutoGCRooter * const down; + + /* + * Discriminates actual subclass of this being used. If non-negative, the + * subclass roots an array of values of the length stored in this field. + * If negative, meaning is indicated by the corresponding value in the enum + * below. Any other negative value indicates some deeper problem such as + * memory corruption. + */ + ptrdiff_t tag_; + + enum { + VALARRAY = -2, /* js::AutoValueArray */ + PARSER = -3, /* js::frontend::Parser */ + SHAPEVECTOR = -4, /* js::AutoShapeVector */ + IDARRAY = -6, /* js::AutoIdArray */ + DESCVECTOR = -7, /* js::AutoPropDescVector */ + VALVECTOR = -10, /* js::AutoValueVector */ + IDVECTOR = -13, /* js::AutoIdVector */ + OBJVECTOR = -14, /* js::AutoObjectVector */ + STRINGVECTOR =-15, /* js::AutoStringVector */ + SCRIPTVECTOR =-16, /* js::AutoScriptVector */ + NAMEVECTOR = -17, /* js::AutoNameVector */ + HASHABLEVALUE=-18, /* js::HashableValue */ + IONMASM = -19, /* js::jit::MacroAssembler */ + IONALLOC = -20, /* js::jit::AutoTempAllocatorRooter */ + WRAPVECTOR = -21, /* js::AutoWrapperVector */ + WRAPPER = -22, /* js::AutoWrapperRooter */ + OBJOBJHASHMAP=-23, /* js::AutoObjectObjectHashMap */ + OBJU32HASHMAP=-24, /* js::AutoObjectUnsigned32HashMap */ + OBJHASHSET = -25, /* js::AutoObjectHashSet */ + JSONPARSER = -26, /* js::JSONParser */ + CUSTOM = -27, /* js::CustomAutoRooter */ + FUNVECTOR = -28 /* js::AutoFunctionVector */ + }; + + private: + AutoGCRooter ** const stackTop; + + /* No copy or assignment semantics. */ + AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; + void operator=(AutoGCRooter &ida) MOZ_DELETE; +}; + } /* namespace JS */ namespace js { @@ -287,13 +333,11 @@ namespace js { enum ParallelResult { TP_SUCCESS, TP_RETRY_SEQUENTIALLY, TP_RETRY_AFTER_GC, TP_FATAL }; struct ThreadSafeContext; -struct ForkJoinSlice; +class ForkJoinContext; class ExclusiveContext; class Allocator; -class SkipRoot; - enum ThingRootKind { THING_ROOT_OBJECT, @@ -301,14 +345,16 @@ enum ThingRootKind THING_ROOT_BASE_SHAPE, THING_ROOT_TYPE_OBJECT, THING_ROOT_STRING, - THING_ROOT_ION_CODE, + THING_ROOT_SYMBOL, + THING_ROOT_JIT_CODE, THING_ROOT_SCRIPT, + THING_ROOT_LAZY_SCRIPT, THING_ROOT_ID, - THING_ROOT_PROPERTY_ID, THING_ROOT_VALUE, THING_ROOT_TYPE, THING_ROOT_BINDINGS, THING_ROOT_PROPERTY_DESCRIPTOR, + THING_ROOT_PROP_DESC, THING_ROOT_LIMIT }; @@ -343,6 +389,7 @@ template <> struct RootKind : SpecificRootKind struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; @@ -364,9 +411,6 @@ struct ContextFriendFields { #ifdef JSGC_TRACK_EXACT_ROOTS mozilla::PodArrayZero(thingGCRooters); -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - skipGCRooters = nullptr; #endif } @@ -379,31 +423,31 @@ struct ContextFriendFields } #ifdef JSGC_TRACK_EXACT_ROOTS + private: /* * Stack allocated GC roots for stack GC heap pointers, which may be * overwritten if moved during a GC. */ JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* - * Stack allocated list of stack locations which hold non-relocatable - * GC heap pointers (where the target is rooted somewhere else) or integer - * values which may be confused for GC heap pointers. These are used to - * suppress false positives which occur when a rooting analysis treats the - * location as holding a relocatable pointer, but have no other effect on - * GC behavior. - */ - SkipRoot *skipGCRooters; + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } + #endif + void checkNoGCRooters(); + /* Stack of thread-stack-allocated GC roots. */ JS::AutoGCRooter *autoGCRooters; friend JSRuntime *GetRuntime(const JSContext *cx); friend JSCompartment *GetContextCompartment(const JSContext *cx); friend JS::Zone *GetContextZone(const JSContext *cx); + template friend class JS::Rooted; }; /* @@ -447,7 +491,7 @@ struct PerThreadDataFriendFields struct PerThreadDummy { void *field1; uintptr_t field2; -#ifdef DEBUG +#ifdef JS_DEBUG uint64_t field3; #endif } mainThread; @@ -458,23 +502,19 @@ struct PerThreadDataFriendFields PerThreadDataFriendFields(); #ifdef JSGC_TRACK_EXACT_ROOTS + private: /* * Stack allocated GC roots for stack GC heap pointers, which may be * overwritten if moved during a GC. */ JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* - * Stack allocated list of stack locations which hold non-relocatable - * GC heap pointers (where the target is rooted somewhere else) or integer - * values which may be confused for GC heap pointers. These are used to - * suppress false positives which occur when a rooting analysis treats the - * location as holding a relocatable pointer, but have no other effect on - * GC behavior. - */ - SkipRoot *skipGCRooters; + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } #endif /* Limit pointer for checking native stack consumption. */ @@ -499,6 +539,8 @@ struct PerThreadDataFriendFields return reinterpret_cast( reinterpret_cast(rt) + RuntimeMainThreadOffset); } + + template friend class JS::Rooted; }; } /* namespace js */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/jstypes.h b/frameworks/js-bindings/external/spidermonkey/include/mac/jstypes.h index d5b15ccb1d..e9927bca0d 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/jstypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/jstypes.h @@ -77,8 +77,13 @@ # define JS_PUBLIC_DATA(t) MOZ_IMPORT_DATA t #endif -#define JS_FRIEND_API(t) JS_PUBLIC_API(t) -#define JS_FRIEND_DATA(t) JS_PUBLIC_DATA(t) +#if defined(STATIC_JS_API) || defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API) +# define JS_FRIEND_API(t) MOZ_EXPORT t +# define JS_FRIEND_DATA(t) MOZ_EXPORT t +#else +# define JS_FRIEND_API(t) MOZ_IMPORT_API t +# define JS_FRIEND_DATA(t) MOZ_IMPORT_DATA t +#endif #if defined(_MSC_VER) && defined(_M_IX86) #define JS_FASTCALL __fastcall @@ -89,22 +94,6 @@ #define JS_NO_FASTCALL #endif -#ifndef JS_ALWAYS_INLINE -#define JS_ALWAYS_INLINE MOZ_ALWAYS_INLINE -#endif - -#ifndef JS_NEVER_INLINE -#define JS_NEVER_INLINE MOZ_NEVER_INLINE -#endif - -#ifndef JS_WARN_UNUSED_RESULT -# if defined __GNUC__ -# define JS_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -# else -# define JS_WARN_UNUSED_RESULT -# endif -#endif - /*********************************************************************** ** MACROS: JS_BEGIN_MACRO ** JS_END_MACRO @@ -122,15 +111,6 @@ # define JS_END_MACRO } while (0) #endif -/*********************************************************************** -** MACROS: JS_BEGIN_EXTERN_C -** JS_END_EXTERN_C -** DESCRIPTION: -** Macro shorthands for conditional C++ extern block delimiters. -***********************************************************************/ -#define JS_BEGIN_EXTERN_C MOZ_BEGIN_EXTERN_C -#define JS_END_EXTERN_C MOZ_END_EXTERN_C - /*********************************************************************** ** MACROS: JS_BIT ** JS_BITMASK @@ -143,8 +123,6 @@ /*********************************************************************** ** MACROS: JS_HOWMANY ** JS_ROUNDUP -** JS_MIN -** JS_MAX ** DESCRIPTION: ** Commonly used macros for operations on compatible types. ***********************************************************************/ @@ -183,34 +161,6 @@ # error "Implement me" #endif -/*********************************************************************** -** MACROS: JS_LIKELY -** JS_UNLIKELY -** DESCRIPTION: -** These macros allow you to give a hint to the compiler about branch -** probability so that it can better optimize. Use them like this: -** -** if (JS_LIKELY(v == 1)) { -** ... expected code path ... -** } -** -** if (JS_UNLIKELY(v == 0)) { -** ... non-expected code path ... -** } -** -***********************************************************************/ -#ifdef __GNUC__ - -# define JS_LIKELY(x) (__builtin_expect((x), 1)) -# define JS_UNLIKELY(x) (__builtin_expect((x), 0)) - -#else - -# define JS_LIKELY(x) (x) -# define JS_UNLIKELY(x) (x) - -#endif - /*********************************************************************** ** MACROS: JS_ARRAY_LENGTH ** JS_ARRAY_END diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/jsversion.h b/frameworks/js-bindings/external/spidermonkey/include/mac/jsversion.h index 827a56981d..1f31e40b5e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/jsversion.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/jsversion.h @@ -25,6 +25,9 @@ #define JS_HAS_DESTRUCTURING 2 /* has [a,b] = ... or {p:a,q:b} = ... */ #define JS_HAS_GENERATOR_EXPRS 1 /* has (expr for (lhs in iterable)) */ #define JS_HAS_EXPR_CLOSURES 1 /* has function (formals) listexpr */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_TEMPLATE_STRINGS 1 /* has template string support */ +#endif /* Support for JS_NewGlobalObject. */ #define JS_HAS_NEW_GLOBAL_OBJECT 1 @@ -41,14 +44,9 @@ */ #define JS_OLD_GETTER_SETTER_METHODS 1 -/* A kill-switch for bug 586842. Embedders shouldn't touch this! */ -#define JS_USE_NEW_OBJECT_REPRESENTATION 0 - -#if JS_USE_NEW_OBJECT_REPRESENTATION -# define JS_NEW_OBJECT_REPRESENTATION_ONLY() ((void)0) -#else -# define JS_NEW_OBJECT_REPRESENTATION_ONLY() \ - MOZ_ASSUME_UNREACHABLE("don't call this! to be used in the new object representation") +/* Support for Symbols - Nightly-only for now. */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_SYMBOLS 1 #endif #endif /* jsversion_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/jswrapper.h b/frameworks/js-bindings/external/spidermonkey/include/mac/jswrapper.h index 1bf1e16664..a8a510c4f7 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/jswrapper.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/jswrapper.h @@ -15,6 +15,35 @@ namespace js { class DummyFrameGuard; +/* + * Helper for Wrapper::New default options. + * + * Callers of Wrapper::New() who wish to specify a prototype for the created + * Wrapper, *MUST* construct a WrapperOptions with a JSContext. + */ +class MOZ_STACK_CLASS WrapperOptions : public ProxyOptions { + public: + WrapperOptions() : ProxyOptions(false, nullptr), + proto_() + {} + + explicit WrapperOptions(JSContext *cx) : ProxyOptions(false, nullptr), + proto_() + { + proto_.construct(cx); + } + + inline JSObject *proto() const; + WrapperOptions &setProto(JSObject *protoArg) { + JS_ASSERT(!proto_.empty()); + proto_.ref() = protoArg; + return *this; + } + + private: + mozilla::Maybe proto_; +}; + /* * A wrapper is a proxy with a target object to which it generally forwards * operations, but may restrict access to certain operations or instrument @@ -27,7 +56,6 @@ class DummyFrameGuard; class JS_FRIEND_API(Wrapper) : public DirectProxyHandler { unsigned mFlags; - bool mSafeToUnwrap; public: using BaseProxyHandler::Action; @@ -38,23 +66,14 @@ class JS_FRIEND_API(Wrapper) : public DirectProxyHandler }; virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; - /* - * Wrappers can explicitly specify that they are unsafe to unwrap from a - * security perspective (as is the case for SecurityWrappers). If a wrapper - * is not safe to unwrap, operations requiring full access to the underlying - * object (via CheckedUnwrap) will throw. Otherwise, they will succeed. - */ - void setSafeToUnwrap(bool safe) { mSafeToUnwrap = safe; } - bool isSafeToUnwrap() { return mSafeToUnwrap; } + static JSObject *New(JSContext *cx, JSObject *obj, JSObject *parent, const Wrapper *handler, + const WrapperOptions *options = nullptr); - static JSObject *New(JSContext *cx, JSObject *obj, JSObject *proto, - JSObject *parent, Wrapper *handler); + static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, const Wrapper *handler); - static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, Wrapper *handler); - - static Wrapper *wrapperHandler(JSObject *wrapper); + static const Wrapper *wrapperHandler(JSObject *wrapper); static JSObject *wrappedObject(JSObject *wrapper); @@ -62,68 +81,78 @@ class JS_FRIEND_API(Wrapper) : public DirectProxyHandler return mFlags; } - explicit Wrapper(unsigned flags, bool hasPrototype = false); + explicit Wrapper(unsigned flags, bool hasPrototype = false, bool hasSecurityPolicy = false); virtual ~Wrapper(); - virtual bool finalizeInBackground(Value priv) MOZ_OVERRIDE; + virtual bool finalizeInBackground(Value priv) const MOZ_OVERRIDE; + + static const Wrapper singleton; + static const Wrapper singletonWithPrototype; - static Wrapper singleton; - static Wrapper singletonWithPrototype; + static JSObject *defaultProto; }; +inline JSObject * +WrapperOptions::proto() const +{ + return proto_.empty() ? Wrapper::defaultProto : proto_.ref(); +} + /* Base class for all cross compartment wrapper handlers. */ class JS_FRIEND_API(CrossCompartmentWrapper) : public Wrapper { public: - CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false); + explicit CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false, + bool hasSecurityPolicy = false); virtual ~CrossCompartmentWrapper(); /* ES5 Harmony fundamental wrapper traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, - AutoIdVector &props) MOZ_OVERRIDE; - virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; /* ES5 Harmony derived wrapper traps. */ - virtual bool has(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool hasOwn(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; + virtual bool has(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool hasOwn(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; virtual bool get(JSContext *cx, HandleObject wrapper, HandleObject receiver, - HandleId id, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool set(JSContext *cx, HandleObject wrapper, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool keys(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool keys(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; virtual bool iterate(JSContext *cx, HandleObject wrapper, unsigned flags, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject wrapper, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject wrapper, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject wrapper, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual JSString *fun_toString(JSContext *cx, HandleObject wrapper, - unsigned indent) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; - static CrossCompartmentWrapper singleton; - static CrossCompartmentWrapper singletonWithPrototype; + static const CrossCompartmentWrapper singleton; + static const CrossCompartmentWrapper singletonWithPrototype; }; /* @@ -139,25 +168,28 @@ template class JS_FRIEND_API(SecurityWrapper) : public Base { public: - SecurityWrapper(unsigned flags); + explicit SecurityWrapper(unsigned flags, bool hasPrototype = false); - virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) MOZ_OVERRIDE; - virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Wrapper::Action act, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; + + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable) MOZ_OVERRIDE; - virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) MOZ_OVERRIDE; + JS::HandleObject callable) const MOZ_OVERRIDE; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const MOZ_OVERRIDE; /* * Allow our subclasses to select the superclass behavior they want without @@ -179,48 +211,42 @@ class JS_FRIEND_API(DeadObjectProxy) : public BaseProxyHandler explicit DeadObjectProxy(); /* ES5 Harmony fundamental wrapper traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, - AutoIdVector &props) MOZ_OVERRIDE; - virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; - virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver, - uint32_t index, MutableHandleValue vp, - bool *present) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, - MutableHandleObject protop) MOZ_OVERRIDE; + MutableHandleObject protop) const MOZ_OVERRIDE; - static DeadObjectProxy singleton; + static const DeadObjectProxy singleton; }; extern JSObject * TransparentObjectWrapper(JSContext *cx, HandleObject existing, HandleObject obj, - HandleObject wrappedProto, HandleObject parent, - unsigned flags); + HandleObject parent, unsigned flags); // Proxy family for wrappers. Public so that IsWrapper() can be fully inlined by // jsfriendapi users. @@ -295,8 +321,8 @@ RecomputeWrappers(JSContext *cx, const CompartmentFilter &sourceFilter, struct JS_FRIEND_API(AutoMaybeTouchDeadZones) { // The version that takes an object just uses it for its runtime. - AutoMaybeTouchDeadZones(JSContext *cx); - AutoMaybeTouchDeadZones(JSObject *obj); + explicit AutoMaybeTouchDeadZones(JSContext *cx); + explicit AutoMaybeTouchDeadZones(JSObject *obj); ~AutoMaybeTouchDeadZones(); private: diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Alignment.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Alignment.h index 29599d0ef1..0ac8a48779 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Alignment.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Alignment.h @@ -21,14 +21,14 @@ namespace mozilla { template class AlignmentFinder { - struct Aligner - { - char c; - T t; - }; - - public: - static const size_t alignment = sizeof(Aligner) - sizeof(T); + struct Aligner + { + char mChar; + T mT; + }; + +public: + static const size_t alignment = sizeof(Aligner) - sizeof(T); }; #define MOZ_ALIGNOF(T) mozilla::AlignmentFinder::alignment @@ -64,38 +64,38 @@ template struct AlignedElem; /* - * We have to specialize this template because GCC doesn't like __attribute__((aligned(foo))) where - * foo is a template parameter. + * We have to specialize this template because GCC doesn't like + * __attribute__((aligned(foo))) where foo is a template parameter. */ template<> struct AlignedElem<1> { - MOZ_ALIGNED_DECL(uint8_t elem, 1); + MOZ_ALIGNED_DECL(uint8_t elem, 1); }; template<> struct AlignedElem<2> { - MOZ_ALIGNED_DECL(uint8_t elem, 2); + MOZ_ALIGNED_DECL(uint8_t elem, 2); }; template<> struct AlignedElem<4> { - MOZ_ALIGNED_DECL(uint8_t elem, 4); + MOZ_ALIGNED_DECL(uint8_t elem, 4); }; template<> struct AlignedElem<8> { - MOZ_ALIGNED_DECL(uint8_t elem, 8); + MOZ_ALIGNED_DECL(uint8_t elem, 8); }; template<> struct AlignedElem<16> { - MOZ_ALIGNED_DECL(uint8_t elem, 16); + MOZ_ALIGNED_DECL(uint8_t elem, 16); }; /* @@ -111,25 +111,27 @@ struct AlignedElem<16> template struct AlignedStorage { - union U { - char bytes[Nbytes]; - uint64_t _; - } u; - - const void* addr() const { return u.bytes; } - void* addr() { return u.bytes; } + union U + { + char mBytes[Nbytes]; + uint64_t mDummy; + } u; + + const void* addr() const { return u.mBytes; } + void* addr() { return u.mBytes; } }; template struct AlignedStorage2 { - union U { - char bytes[sizeof(T)]; - uint64_t _; - } u; - - const T* addr() const { return reinterpret_cast(u.bytes); } - T* addr() { return static_cast(static_cast(u.bytes)); } + union U + { + char mBytes[sizeof(T)]; + uint64_t mDummy; + } u; + + const T* addr() const { return reinterpret_cast(u.mBytes); } + T* addr() { return static_cast(static_cast(u.mBytes)); } }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/AllocPolicy.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/AllocPolicy.h index 20087e93bb..357c632a02 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/AllocPolicy.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/AllocPolicy.h @@ -49,14 +49,31 @@ namespace mozilla { */ class MallocAllocPolicy { - public: - void* malloc_(size_t bytes) { return malloc(bytes); } - void* calloc_(size_t bytes) { return calloc(bytes, 1); } - void* realloc_(void* p, size_t oldBytes, size_t bytes) { return realloc(p, bytes); } - void free_(void* p) { free(p); } - void reportAllocOverflow() const {} -}; +public: + void* malloc_(size_t aBytes) + { + return malloc(aBytes); + } + + void* calloc_(size_t aBytes) + { + return calloc(aBytes, 1); + } + + void* realloc_(void* aPtr, size_t aOldBytes, size_t aBytes) + { + return realloc(aPtr, aBytes); + } + void free_(void* aPtr) + { + free(aPtr); + } + + void reportAllocOverflow() const + { + } +}; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Array.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Array.h index 5af9aaa133..b2ab578d4b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Array.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Array.h @@ -19,31 +19,35 @@ namespace mozilla { template class Array { - T arr[Length]; - - public: - T& operator[](size_t i) { - MOZ_ASSERT(i < Length); - return arr[i]; - } - - const T& operator[](size_t i) const { - MOZ_ASSERT(i < Length); - return arr[i]; - } + T mArr[Length]; + +public: + T& operator[](size_t aIndex) + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } + + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } }; template class Array { - public: - T& operator[](size_t i) { - MOZ_ASSUME_UNREACHABLE("indexing into zero-length array"); - } - - const T& operator[](size_t i) const { - MOZ_ASSUME_UNREACHABLE("indexing into zero-length array"); - } +public: + T& operator[](size_t aIndex) + { + MOZ_CRASH("indexing into zero-length array"); + } + + const T& operator[](size_t aIndex) const + { + MOZ_CRASH("indexing into zero-length array"); + } }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ArrayUtils.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ArrayUtils.h index e2226bf59d..44f5980c44 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ArrayUtils.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ArrayUtils.h @@ -18,22 +18,24 @@ #ifdef __cplusplus +#include "mozilla/Alignment.h" #include "mozilla/Array.h" +#include "mozilla/TypeTraits.h" namespace mozilla { /* - * Safely subtract two pointers when it is known that end >= begin. This avoids - * the common compiler bug that if (size_t(end) - size_t(begin)) has the MSB - * set, the unsigned subtraction followed by right shift will produce -1, or - * size_t(-1), instead of the real difference. + * Safely subtract two pointers when it is known that aEnd >= aBegin. This + * avoids the common compiler bug that if (size_t(aEnd) - size_t(aBegin)) has + * the MSB set, the unsigned subtraction followed by right shift will produce + * -1, or size_t(-1), instead of the real difference. */ template MOZ_ALWAYS_INLINE size_t -PointerRangeSize(T* begin, T* end) +PointerRangeSize(T* aBegin, T* aEnd) { - MOZ_ASSERT(end >= begin); - return (size_t(end) - size_t(begin)) / sizeof(T); + MOZ_ASSERT(aEnd >= aBegin); + return (size_t(aEnd) - size_t(aBegin)) / sizeof(T); } /* @@ -44,14 +46,14 @@ PointerRangeSize(T* begin, T* end) */ template MOZ_CONSTEXPR size_t -ArrayLength(T (&arr)[N]) +ArrayLength(T (&aArr)[N]) { return N; } template MOZ_CONSTEXPR size_t -ArrayLength(const Array& arr) +ArrayLength(const Array& aArr) { return N; } @@ -63,25 +65,100 @@ ArrayLength(const Array& arr) */ template MOZ_CONSTEXPR T* -ArrayEnd(T (&arr)[N]) +ArrayEnd(T (&aArr)[N]) { - return arr + ArrayLength(arr); + return aArr + ArrayLength(aArr); } template MOZ_CONSTEXPR T* -ArrayEnd(Array& arr) +ArrayEnd(Array& aArr) { - return &arr[0] + ArrayLength(arr); + return &aArr[0] + ArrayLength(aArr); } template MOZ_CONSTEXPR const T* -ArrayEnd(const Array& arr) +ArrayEnd(const Array& aArr) { - return &arr[0] + ArrayLength(arr); + return &aArr[0] + ArrayLength(aArr); } +namespace detail { + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % MOZ_ALIGNOF(AlignType)) == 0, + "performing a range-check with a misaligned pointer"); + } +}; + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + } +}; + +} // namespace detail + +/** + * Determines whether |aPtr| points at an object in the range [aBegin, aEnd). + * + * |aPtr| must have the same alignment as |aBegin| and |aEnd|. This usually + * should be achieved by ensuring |aPtr| points at a |U|, not just that it + * points at a |T|. + * + * It is a usage error for any argument to be misaligned. + * + * It's okay for T* to be void*, and if so U* may also be void*. In the latter + * case no argument is required to be aligned (obviously, as void* implies no + * particular alignment). + */ +template +inline typename EnableIf::value || + IsBaseOf::value || + IsVoid::value, + bool>::Type +IsInRange(T* aPtr, U* aBegin, U* aEnd) +{ + MOZ_ASSERT(aBegin <= aEnd); + detail::AlignedChecker::test(aPtr); + detail::AlignedChecker::test(aBegin); + detail::AlignedChecker::test(aEnd); + return aBegin <= static_cast(aPtr) && static_cast(aPtr) < aEnd; +} + +/** + * Convenience version of the above method when the valid range is specified as + * uintptr_t values. As above, |aPtr| must be aligned, and |aBegin| and |aEnd| + * must be aligned with respect to |T|. + */ +template +inline bool +IsInRange(T* aPtr, uintptr_t aBegin, uintptr_t aEnd) +{ + return IsInRange(aPtr, + reinterpret_cast(aBegin), reinterpret_cast(aEnd)); +} + +namespace detail { + +/* + * Helper for the MOZ_ARRAY_LENGTH() macro to make the length a typesafe + * compile-time constant even on compilers lacking constexpr support. + */ +template +char (&ArrayLengthHelper(T (&array)[N]))[N]; + +} /* namespace detail */ + } /* namespace mozilla */ #endif /* __cplusplus */ @@ -91,8 +168,8 @@ ArrayEnd(const Array& arr) * that can't use C++ template functions and for static_assert() calls that * can't call ArrayLength() when it is not a C++11 constexpr function. */ -#ifdef MOZ_HAVE_CXX11_CONSTEXPR -# define MOZ_ARRAY_LENGTH(array) mozilla::ArrayLength(array) +#ifdef __cplusplus +# define MOZ_ARRAY_LENGTH(array) sizeof(mozilla::detail::ArrayLengthHelper(array)) #else # define MOZ_ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0])) #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Assertions.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Assertions.h index 8a5fa205f9..a463b2768d 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Assertions.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Assertions.h @@ -9,9 +9,17 @@ #ifndef mozilla_Assertions_h #define mozilla_Assertions_h +#if defined(MOZILLA_INTERNAL_API) && defined(__cplusplus) +#define MOZ_DUMP_ASSERTION_STACK +#endif + #include "mozilla/Attributes.h" #include "mozilla/Compiler.h" #include "mozilla/Likely.h" +#include "mozilla/MacroArgs.h" +#ifdef MOZ_DUMP_ASSERTION_STACK +#include "nsTraceRefcnt.h" +#endif #include #include @@ -24,13 +32,13 @@ * number of undesired macros and symbols. */ # ifdef __cplusplus - extern "C" { +extern "C" { # endif - __declspec(dllimport) int __stdcall - TerminateProcess(void* hProcess, unsigned int uExitCode); - __declspec(dllimport) void* __stdcall GetCurrentProcess(void); +__declspec(dllimport) int __stdcall +TerminateProcess(void* hProcess, unsigned int uExitCode); +__declspec(dllimport) void* __stdcall GetCurrentProcess(void); # ifdef __cplusplus - } +} # endif #else # include @@ -116,33 +124,42 @@ extern "C" { #endif /* - * Prints |s| as an assertion failure (using file and ln as the location of the - * assertion) to the standard debug-output channel. + * Prints |aStr| as an assertion failure (using aFilename and aLine as the + * location of the assertion) to the standard debug-output channel. * * Usually you should use MOZ_ASSERT or MOZ_CRASH instead of this method. This * method is primarily for internal use in this header, and only secondarily * for use in implementing release-build assertions. */ static MOZ_ALWAYS_INLINE void -MOZ_ReportAssertionFailure(const char* s, const char* file, int ln) +MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS { #ifdef ANDROID __android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert", - "Assertion failure: %s, at %s:%d\n", s, file, ln); + "Assertion failure: %s, at %s:%d\n", + aStr, aFilename, aLine); #else - fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln); + fprintf(stderr, "Assertion failure: %s, at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif fflush(stderr); #endif } static MOZ_ALWAYS_INLINE void -MOZ_ReportCrash(const char* s, const char* file, int ln) +MOZ_ReportCrash(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS { #ifdef ANDROID - __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", - "Hit MOZ_CRASH(%s) at %s:%d\n", s, file, ln); + __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", + "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); #else - fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", s, file, ln); + fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif fflush(stderr); #endif } @@ -238,7 +255,7 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} do { \ MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \ MOZ_REALLY_CRASH(); \ - } while(0) + } while (0) #endif #ifdef __cplusplus @@ -279,52 +296,108 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} * MOZ_RELEASE_ASSERT, which applies to non-debug builds as well. */ +/* + * Implement MOZ_VALIDATE_ASSERT_CONDITION_TYPE, which is used to guard against + * accidentally passing something unintended in lieu of an assertion condition. + */ + +#ifdef __cplusplus +# if defined(__clang__) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# elif defined(__GNUC__) +// B2G GCC 4.4 has insufficient decltype support. +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# endif +# elif defined(_MSC_VER) +// Disabled for now because of insufficient decltype support. Bug 1004028. +# endif +#endif + +#ifdef MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# include "mozilla/TypeTraits.h" +namespace mozilla { +namespace detail { + +template +struct IsFunction +{ + static const bool value = false; +}; + +template +struct IsFunction +{ + static const bool value = true; +}; + +template +void ValidateAssertConditionType() +{ + typedef typename RemoveReference::Type ValueT; + static_assert(!IsArray::value, + "Expected boolean assertion condition, got an array or a " + "string!"); + static_assert(!IsFunction::value, + "Expected boolean assertion condition, got a function! Did " + "you intend to call that function?"); + static_assert(!IsFloatingPoint::value, + "It's often a bad idea to assert that a floating-point number " + "is nonzero, because such assertions tend to intermittently " + "fail. Shouldn't your code gracefully handle this case instead " + "of asserting? Anyway, if you really want to do that, write an " + "explicit boolean condition, like !!x or x!=0."); +} + +} // namespace detail +} // namespace mozilla +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) \ + mozilla::detail::ValidateAssertConditionType() +#else +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) +#endif + /* First the single-argument form. */ #define MOZ_ASSERT_HELPER1(expr) \ - do { \ - if (MOZ_UNLIKELY(!(expr))) { \ - MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } \ - } while (0) + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) /* Now the two-argument form. */ #define MOZ_ASSERT_HELPER2(expr, explain) \ - do { \ - if (MOZ_UNLIKELY(!(expr))) { \ - MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } \ - } while (0) -/* And now, helper macrology up the wazoo. */ -/* - * Count the number of arguments passed to MOZ_ASSERT, very carefully - * tiptoeing around an MSVC bug where it improperly expands __VA_ARGS__ as a - * single token in argument lists. See these URLs for details: - * - * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement - * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 - */ -#define MOZ_COUNT_ASSERT_ARGS_IMPL2(_1, _2, count, ...) \ - count -#define MOZ_COUNT_ASSERT_ARGS_IMPL(args) \ - MOZ_COUNT_ASSERT_ARGS_IMPL2 args -#define MOZ_COUNT_ASSERT_ARGS(...) \ - MOZ_COUNT_ASSERT_ARGS_IMPL((__VA_ARGS__, 2, 1, 0)) -/* Pick the right helper macro to invoke. */ -#define MOZ_ASSERT_CHOOSE_HELPER2(count) MOZ_ASSERT_HELPER##count -#define MOZ_ASSERT_CHOOSE_HELPER1(count) MOZ_ASSERT_CHOOSE_HELPER2(count) -#define MOZ_ASSERT_CHOOSE_HELPER(count) MOZ_ASSERT_CHOOSE_HELPER1(count) -/* The actual macros. */ -#define MOZ_ASSERT_GLUE(x, y) x y + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) + +#define MOZ_RELEASE_ASSERT_GLUE(a, b) a b #define MOZ_RELEASE_ASSERT(...) \ - MOZ_ASSERT_GLUE(MOZ_ASSERT_CHOOSE_HELPER(MOZ_COUNT_ASSERT_ARGS(__VA_ARGS__)), \ - (__VA_ARGS__)) + MOZ_RELEASE_ASSERT_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \ + (__VA_ARGS__)) + #ifdef DEBUG # define MOZ_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) #else -# define MOZ_ASSERT(...) do { } while(0) +# define MOZ_ASSERT(...) do { } while (0) #endif /* DEBUG */ +/* + * MOZ_NIGHTLY_ASSERT is defined for both debug and release builds on the + * Nightly channel, but only debug builds on Aurora, Beta, and Release. + */ +#if defined(NIGHTLY_BUILD) +# define MOZ_NIGHTLY_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) +#else +# define MOZ_NIGHTLY_ASSERT(...) MOZ_ASSERT(__VA_ARGS__) +#endif + /* * MOZ_ASSERT_IF(cond1, cond2) is equivalent to MOZ_ASSERT(cond2) if cond1 is * true. @@ -337,19 +410,20 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} #ifdef DEBUG # define MOZ_ASSERT_IF(cond, expr) \ do { \ - if (cond) \ + if (cond) { \ MOZ_ASSERT(expr); \ + } \ } while (0) #else # define MOZ_ASSERT_IF(cond, expr) do { } while (0) #endif /* - * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that it is - * undefined behavior for execution to reach this point. No guarantees are made - * about what will happen if this is reached at runtime. Most code should - * probably use the higher level MOZ_ASSUME_UNREACHABLE, which uses this when - * appropriate. + * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that + * it is undefined behavior for execution to reach this point. No guarantees + * are made about what will happen if this is reached at runtime. Most code + * should use MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE because it has extra + * asserts. */ #if defined(__clang__) # define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable() @@ -379,21 +453,22 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} #endif /* - * MOZ_ASSUME_UNREACHABLE([reason]) tells the compiler that it can assume that - * the macro call cannot be reached during execution. This lets the compiler - * generate better-optimized code under some circumstances, at the expense of - * the program's behavior being undefined if control reaches the - * MOZ_ASSUME_UNREACHABLE. + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE([reason]) tells the compiler that it + * can assume that the macro call cannot be reached during execution. This lets + * the compiler generate better-optimized code under some circumstances, at the + * expense of the program's behavior being undefined if control reaches the + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE. * * In Gecko, you probably should not use this macro outside of performance- or * size-critical code, because it's unsafe. If you don't care about code size * or performance, you should probably use MOZ_ASSERT or MOZ_CRASH. * * SpiderMonkey is a different beast, and there it's acceptable to use - * MOZ_ASSUME_UNREACHABLE more widely. + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE more widely. * - * Note that MOZ_ASSUME_UNREACHABLE is noreturn, so it's valid not to return a - * value following a MOZ_ASSUME_UNREACHABLE call. + * Note that MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE is noreturn, so it's valid + * not to return a value following a MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE + * call. * * Example usage: * @@ -413,19 +488,32 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} * case VALUE_FLOAT: * return (int) *(float*) value; * default: - * MOZ_ASSUME_UNREACHABLE("can only handle VALUE_INT and VALUE_FLOAT"); + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected ValueType"); * } * } */ -#if defined(DEBUG) -# define MOZ_ASSUME_UNREACHABLE(...) \ - do { \ - MOZ_ASSERT(false, "MOZ_ASSUME_UNREACHABLE(" __VA_ARGS__ ")"); \ - MOZ_ASSUME_UNREACHABLE_MARKER(); \ - } while (0) -#else -# define MOZ_ASSUME_UNREACHABLE(reason) MOZ_ASSUME_UNREACHABLE_MARKER() -#endif + +/* + * Assert in all debug builds plus the Nightly channel's release builds. Take + * this extra testing precaution because hitting MOZ_ASSUME_UNREACHABLE_MARKER + * could trigger exploitable undefined behavior. + */ +#define MOZ_ASSERT_UNREACHABLE(reason) \ + MOZ_NIGHTLY_ASSERT(false, "MOZ_ASSERT_UNREACHABLE: " reason) + +#define MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) \ + do { \ + MOZ_ASSERT_UNREACHABLE(reason); \ + MOZ_ASSUME_UNREACHABLE_MARKER(); \ + } while (0) + +/* + * TODO: Bug 990764: Audit all MOZ_ASSUME_UNREACHABLE calls and replace them + * with MOZ_ASSERT_UNREACHABLE, MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE, or + * MOZ_CRASH. For now, preserve the macro's same meaning of unreachable. + */ +#define MOZ_ASSUME_UNREACHABLE(reason) \ + MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) /* * MOZ_ALWAYS_TRUE(expr) and MOZ_ALWAYS_FALSE(expr) always evaluate the provided @@ -441,4 +529,6 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} # define MOZ_ALWAYS_FALSE(expr) ((void)(expr)) #endif +#undef MOZ_DUMP_ASSERTION_STACK + #endif /* mozilla_Assertions_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Atomics.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Atomics.h index 03ae7c34f3..71d95c61ba 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Atomics.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Atomics.h @@ -41,6 +41,13 @@ # define MOZ_HAVE_CXX11_ATOMICS # endif #elif defined(_MSC_VER) && _MSC_VER >= 1700 +# if defined(DEBUG) + /* + * Provide our own failure code since we're having trouble linking to + * std::_Debug_message (bug 982310). + */ +# define _INVALID_MEMORY_ORDER MOZ_CRASH("Invalid memory order") +# endif # define MOZ_HAVE_CXX11_ATOMICS #endif @@ -107,6 +114,7 @@ enum MemoryOrdering { * ordering if you can't easily test non-x86 architectures! */ Relaxed, + /* * When an atomic value is updated with ReleaseAcquire ordering, and * that new value is observed with ReleaseAcquire ordering, prior @@ -128,6 +136,7 @@ enum MemoryOrdering { * a good, hard look at actual lock or mutex primitives first. */ ReleaseAcquire, + /* * When an atomic value is updated with SequentiallyConsistent * ordering, all writes observable when the update is observed, just @@ -177,126 +186,154 @@ template struct AtomicOrderConstraints; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_relaxed; - static const std::memory_order LoadOrder = std::memory_order_relaxed; - static const std::memory_order StoreOrder = std::memory_order_relaxed; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_relaxed; + static const std::memory_order AtomicRMWOrder = std::memory_order_relaxed; + static const std::memory_order LoadOrder = std::memory_order_relaxed; + static const std::memory_order StoreOrder = std::memory_order_relaxed; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_relaxed; }; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_acq_rel; - static const std::memory_order LoadOrder = std::memory_order_acquire; - static const std::memory_order StoreOrder = std::memory_order_release; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_acquire; + static const std::memory_order AtomicRMWOrder = std::memory_order_acq_rel; + static const std::memory_order LoadOrder = std::memory_order_acquire; + static const std::memory_order StoreOrder = std::memory_order_release; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_acquire; }; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_seq_cst; - static const std::memory_order LoadOrder = std::memory_order_seq_cst; - static const std::memory_order StoreOrder = std::memory_order_seq_cst; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_seq_cst; + static const std::memory_order AtomicRMWOrder = std::memory_order_seq_cst; + static const std::memory_order LoadOrder = std::memory_order_seq_cst; + static const std::memory_order StoreOrder = std::memory_order_seq_cst; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_seq_cst; }; template struct IntrinsicBase { - typedef std::atomic ValueType; - typedef AtomicOrderConstraints OrderedOp; + typedef std::atomic ValueType; + typedef AtomicOrderConstraints OrderedOp; }; template struct IntrinsicMemoryOps : public IntrinsicBase { - typedef IntrinsicBase Base; - static T load(const typename Base::ValueType& ptr) { - return ptr.load(Base::OrderedOp::LoadOrder); - } - static void store(typename Base::ValueType& ptr, T val) { - ptr.store(val, Base::OrderedOp::StoreOrder); - } - static T exchange(typename Base::ValueType& ptr, T val) { - return ptr.exchange(val, Base::OrderedOp::AtomicRMWOrder); - } - static bool compareExchange(typename Base::ValueType& ptr, T oldVal, T newVal) { - return ptr.compare_exchange_strong(oldVal, newVal, - Base::OrderedOp::AtomicRMWOrder, - Base::OrderedOp::CompareExchangeFailureOrder); - } + typedef IntrinsicBase Base; + + static T load(const typename Base::ValueType& aPtr) + { + return aPtr.load(Base::OrderedOp::LoadOrder); + } + + static void store(typename Base::ValueType& aPtr, T aVal) + { + aPtr.store(aVal, Base::OrderedOp::StoreOrder); + } + + static T exchange(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.exchange(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static bool compareExchange(typename Base::ValueType& aPtr, + T aOldVal, T aNewVal) + { + return aPtr.compare_exchange_strong(aOldVal, aNewVal, + Base::OrderedOp::AtomicRMWOrder, + Base::OrderedOp::CompareExchangeFailureOrder); + } }; template struct IntrinsicAddSub : public IntrinsicBase { - typedef IntrinsicBase Base; - static T add(typename Base::ValueType& ptr, T val) { - return ptr.fetch_add(val, Base::OrderedOp::AtomicRMWOrder); - } - static T sub(typename Base::ValueType& ptr, T val) { - return ptr.fetch_sub(val, Base::OrderedOp::AtomicRMWOrder); - } + typedef IntrinsicBase Base; + + static T add(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_add(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T sub(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_sub(aVal, Base::OrderedOp::AtomicRMWOrder); + } }; template struct IntrinsicAddSub : public IntrinsicBase { - typedef IntrinsicBase Base; - static T* add(typename Base::ValueType& ptr, ptrdiff_t val) { - return ptr.fetch_add(fixupAddend(val), Base::OrderedOp::AtomicRMWOrder); - } - static T* sub(typename Base::ValueType& ptr, ptrdiff_t val) { - return ptr.fetch_sub(fixupAddend(val), Base::OrderedOp::AtomicRMWOrder); - } - private: - /* - * GCC 4.6's header has a bug where adding X to an - * atomic is not the same as adding X to a T*. Hence the need - * for this function to provide the correct addend. - */ - static ptrdiff_t fixupAddend(ptrdiff_t val) { + typedef IntrinsicBase Base; + + static T* add(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_add(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } + + static T* sub(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_sub(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } +private: + /* + * GCC 4.6's header has a bug where adding X to an + * atomic is not the same as adding X to a T*. Hence the need + * for this function to provide the correct addend. + */ + static ptrdiff_t fixupAddend(ptrdiff_t aVal) + { #if defined(__clang__) || defined(_MSC_VER) - return val; + return aVal; #elif defined(__GNUC__) && MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) && \ - !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) - return val * sizeof(T); + !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) + return aVal * sizeof(T); #else - return val; + return aVal; #endif - } + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - typedef IntrinsicBase Base; - static T inc(typename Base::ValueType& ptr) { - return IntrinsicAddSub::add(ptr, 1); - } - static T dec(typename Base::ValueType& ptr) { - return IntrinsicAddSub::sub(ptr, 1); - } + typedef IntrinsicBase Base; + + static T inc(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::add(aPtr, 1); + } + + static T dec(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::sub(aPtr, 1); + } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef IntrinsicBase Base; - static T or_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_or(val, Base::OrderedOp::AtomicRMWOrder); - } - static T xor_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_xor(val, Base::OrderedOp::AtomicRMWOrder); - } - static T and_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_and(val, Base::OrderedOp::AtomicRMWOrder); - } + typedef IntrinsicBase Base; + + static T or_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_or(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T xor_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_xor(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T and_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_and(aVal, Base::OrderedOp::AtomicRMWOrder); + } }; template @@ -345,111 +382,119 @@ template struct Barrier; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() {} - static void beforeStore() {} - static void afterStore() {} + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} + static void afterStore() {} }; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() { __sync_synchronize(); } - static void beforeStore() { __sync_synchronize(); } - static void afterStore() {} + static void beforeLoad() {} + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() {} }; template<> struct Barrier { - static void beforeLoad() { __sync_synchronize(); } - static void afterLoad() { __sync_synchronize(); } - static void beforeStore() { __sync_synchronize(); } - static void afterStore() { __sync_synchronize(); } + static void beforeLoad() { __sync_synchronize(); } + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() { __sync_synchronize(); } }; template struct IntrinsicMemoryOps { - static T load(const T& ptr) { - Barrier::beforeLoad(); - T val = ptr; - Barrier::afterLoad(); - return val; - } - static void store(T& ptr, T val) { - Barrier::beforeStore(); - ptr = val; - Barrier::afterStore(); - } - static T exchange(T& ptr, T val) { - // __sync_lock_test_and_set is only an acquire barrier; loads and stores - // can't be moved up from after to before it, but they can be moved down - // from before to after it. We may want a stricter ordering, so we need - // an explicit barrier. - - Barrier::beforeStore(); - return __sync_lock_test_and_set(&ptr, val); - } - static bool compareExchange(T& ptr, T oldVal, T newVal) { - return __sync_bool_compare_and_swap(&ptr, oldVal, newVal); - } + static T load(const T& aPtr) + { + Barrier::beforeLoad(); + T val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(T& aPtr, T aVal) + { + Barrier::beforeStore(); + aPtr = aVal; + Barrier::afterStore(); + } + + static T exchange(T& aPtr, T aVal) + { + // __sync_lock_test_and_set is only an acquire barrier; loads and stores + // can't be moved up from after to before it, but they can be moved down + // from before to after it. We may want a stricter ordering, so we need + // an explicit barrier. + Barrier::beforeStore(); + return __sync_lock_test_and_set(&aPtr, aVal); + } + + static bool compareExchange(T& aPtr, T aOldVal, T aNewVal) + { + return __sync_bool_compare_and_swap(&aPtr, aOldVal, aNewVal); + } }; template struct IntrinsicAddSub { - typedef T ValueType; - static T add(T& ptr, T val) { - return __sync_fetch_and_add(&ptr, val); - } - static T sub(T& ptr, T val) { - return __sync_fetch_and_sub(&ptr, val); - } + typedef T ValueType; + + static T add(T& aPtr, T aVal) + { + return __sync_fetch_and_add(&aPtr, aVal); + } + + static T sub(T& aPtr, T aVal) + { + return __sync_fetch_and_sub(&aPtr, aVal); + } }; template struct IntrinsicAddSub { - typedef T* ValueType; - /* - * The reinterpret_casts are needed so that - * __sync_fetch_and_{add,sub} will properly type-check. - * - * Also, these functions do not provide standard semantics for - * pointer types, so we need to adjust the addend. - */ - static ValueType add(ValueType& ptr, ptrdiff_t val) { - ValueType amount = reinterpret_cast(val * sizeof(T)); - return __sync_fetch_and_add(&ptr, amount); - } - static ValueType sub(ValueType& ptr, ptrdiff_t val) { - ValueType amount = reinterpret_cast(val * sizeof(T)); - return __sync_fetch_and_sub(&ptr, amount); - } + typedef T* ValueType; + + /* + * The reinterpret_casts are needed so that + * __sync_fetch_and_{add,sub} will properly type-check. + * + * Also, these functions do not provide standard semantics for + * pointer types, so we need to adjust the addend. + */ + static ValueType add(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_add(&aPtr, amount); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_sub(&aPtr, amount); + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - static T inc(T& ptr) { return IntrinsicAddSub::add(ptr, 1); } - static T dec(T& ptr) { return IntrinsicAddSub::sub(ptr, 1); } + static T inc(T& aPtr) { return IntrinsicAddSub::add(aPtr, 1); } + static T dec(T& aPtr) { return IntrinsicAddSub::sub(aPtr, 1); } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - static T or_(T& ptr, T val) { - return __sync_fetch_and_or(&ptr, val); - } - static T xor_(T& ptr, T val) { - return __sync_fetch_and_xor(&ptr, val); - } - static T and_(T& ptr, T val) { - return __sync_fetch_and_and(&ptr, val); - } + static T or_( T& aPtr, T aVal) { return __sync_fetch_and_or(&aPtr, aVal); } + static T xor_(T& aPtr, T aVal) { return __sync_fetch_and_xor(&aPtr, aVal); } + static T and_(T& aPtr, T aVal) { return __sync_fetch_and_and(&aPtr, aVal); } }; template @@ -470,19 +515,9 @@ struct AtomicIntrinsics : public IntrinsicMemoryOps, * version of Windows we support. Therefore, we only provide operations * on 32-bit datatypes for 32-bit Windows versions; for 64-bit Windows * versions, we support 64-bit datatypes as well. - * - * To avoid namespace pollution issues, we declare whatever functions we - * need ourselves. */ -extern "C" { -long __cdecl _InterlockedExchangeAdd(long volatile* dst, long value); -long __cdecl _InterlockedOr(long volatile* dst, long value); -long __cdecl _InterlockedXor(long volatile* dst, long value); -long __cdecl _InterlockedAnd(long volatile* dst, long value); -long __cdecl _InterlockedExchange(long volatile *dst, long value); -long __cdecl _InterlockedCompareExchange(long volatile *dst, long newVal, long oldVal); -} +# include # pragma intrinsic(_InterlockedExchangeAdd) # pragma intrinsic(_InterlockedOr) @@ -507,34 +542,34 @@ namespace detail { * The PrimitiveIntrinsics template should define |Type|, the datatype of size * DataSize upon which we operate, and the following eight functions. * - * static Type add(Type* ptr, Type val); - * static Type sub(Type* ptr, Type val); - * static Type or_(Type* ptr, Type val); - * static Type xor_(Type* ptr, Type val); - * static Type and_(Type* ptr, Type val); + * static Type add(Type* aPtr, Type aVal); + * static Type sub(Type* aPtr, Type aVal); + * static Type or_(Type* aPtr, Type aVal); + * static Type xor_(Type* aPtr, Type aVal); + * static Type and_(Type* aPtr, Type aVal); * * These functions perform the obvious operation on the value contained in - * |*ptr| combined with |val| and return the value previously stored in - * |*ptr|. + * |*aPtr| combined with |aVal| and return the value previously stored in + * |*aPtr|. * - * static void store(Type* ptr, Type val); + * static void store(Type* aPtr, Type aVal); * - * This function atomically stores |val| into |*ptr| and must provide a full + * This function atomically stores |aVal| into |*aPtr| and must provide a full * memory fence after the store to prevent compiler and hardware instruction * reordering. It should also act as a compiler barrier to prevent reads and * writes from moving to after the store. * - * static Type exchange(Type* ptr, Type val); + * static Type exchange(Type* aPtr, Type aVal); * - * This function atomically stores |val| into |*ptr| and returns the previous - * contents of *ptr; + * This function atomically stores |aVal| into |*aPtr| and returns the + * previous contents of |*aPtr|; * - * static bool compareExchange(Type* ptr, Type oldVal, Type newVal); + * static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal); * * This function atomically performs the following operation: * - * if (*ptr == oldVal) { - * *ptr = newVal; + * if (*aPtr == aOldVal) { + * *aPtr = aNewVal; * return true; * } else { * return false; @@ -546,56 +581,55 @@ template struct PrimitiveIntrinsics; template<> struct PrimitiveIntrinsics<4> { - typedef long Type; + typedef long Type; - static Type add(Type* ptr, Type val) { - return _InterlockedExchangeAdd(ptr, val); - } - static Type sub(Type* ptr, Type val) { - /* - * _InterlockedExchangeSubtract isn't available before Windows 7, - * and we must support Windows XP. - */ - return _InterlockedExchangeAdd(ptr, -val); - } - static Type or_(Type* ptr, Type val) { - return _InterlockedOr(ptr, val); - } - static Type xor_(Type* ptr, Type val) { - return _InterlockedXor(ptr, val); - } - static Type and_(Type* ptr, Type val) { - return _InterlockedAnd(ptr, val); - } - static void store(Type* ptr, Type val) { - _InterlockedExchange(ptr, val); - } - static Type exchange(Type* ptr, Type val) { - return _InterlockedExchange(ptr, val); - } - static bool compareExchange(Type* ptr, Type oldVal, Type newVal) { - return _InterlockedCompareExchange(ptr, newVal, oldVal) == oldVal; - } + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * _InterlockedExchangeSubtract isn't available before Windows 7, + * and we must support Windows XP. + */ + return _InterlockedExchangeAdd(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange(aPtr, aNewVal, aOldVal) == aOldVal; + } }; # if defined(_M_X64) -extern "C" { -long long __cdecl _InterlockedExchangeAdd64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedOr64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedXor64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedAnd64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedExchange64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedCompareExchange64(long long volatile* dst, - long long newVal, - long long oldVal); -} - # pragma intrinsic(_InterlockedExchangeAdd64) # pragma intrinsic(_InterlockedOr64) # pragma intrinsic(_InterlockedXor64) @@ -606,41 +640,54 @@ long long __cdecl _InterlockedCompareExchange64(long long volatile* dst, template <> struct PrimitiveIntrinsics<8> { - typedef __int64 Type; + typedef __int64 Type; - static Type add(Type* ptr, Type val) { - return _InterlockedExchangeAdd64(ptr, val); - } - static Type sub(Type* ptr, Type val) { - /* - * There is no _InterlockedExchangeSubtract64. - */ - return _InterlockedExchangeAdd64(ptr, -val); - } - static Type or_(Type* ptr, Type val) { - return _InterlockedOr64(ptr, val); - } - static Type xor_(Type* ptr, Type val) { - return _InterlockedXor64(ptr, val); - } - static Type and_(Type* ptr, Type val) { - return _InterlockedAnd64(ptr, val); - } - static void store(Type* ptr, Type val) { - _InterlockedExchange64(ptr, val); - } - static Type exchange(Type* ptr, Type val) { - return _InterlockedExchange64(ptr, val); - } - static bool compareExchange(Type* ptr, Type oldVal, Type newVal) { - return _InterlockedCompareExchange64(ptr, newVal, oldVal) == oldVal; - } + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd64(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * There is no _InterlockedExchangeSubtract64. + */ + return _InterlockedExchangeAdd64(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr64(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor64(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd64(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange64(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange64(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange64(aPtr, aNewVal, aOldVal) == aOldVal; + } }; # endif -extern "C" { void _ReadWriteBarrier(); } - # pragma intrinsic(_ReadWriteBarrier) template struct Barrier; @@ -654,168 +701,198 @@ template struct Barrier; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() {} - static void beforeStore() {} + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} }; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() { _ReadWriteBarrier(); } - static void beforeStore() { _ReadWriteBarrier(); } + static void beforeLoad() {} + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } }; template<> struct Barrier { - static void beforeLoad() { _ReadWriteBarrier(); } - static void afterLoad() { _ReadWriteBarrier(); } - static void beforeStore() { _ReadWriteBarrier(); } + static void beforeLoad() { _ReadWriteBarrier(); } + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } }; template struct CastHelper { - static PrimType toPrimType(T val) { return static_cast(val); } - static T fromPrimType(PrimType val) { return static_cast(val); } + static PrimType toPrimType(T aVal) { return static_cast(aVal); } + static T fromPrimType(PrimType aVal) { return static_cast(aVal); } }; template struct CastHelper { - static PrimType toPrimType(T* val) { return reinterpret_cast(val); } - static T* fromPrimType(PrimType val) { return reinterpret_cast(val); } + static PrimType toPrimType(T* aVal) { return reinterpret_cast(aVal); } + static T* fromPrimType(PrimType aVal) { return reinterpret_cast(aVal); } }; template struct IntrinsicBase { - typedef T ValueType; - typedef PrimitiveIntrinsics Primitives; - typedef typename Primitives::Type PrimType; - static_assert(sizeof(PrimType) == sizeof(T), - "Selection of PrimitiveIntrinsics was wrong"); - typedef CastHelper Cast; + typedef T ValueType; + typedef PrimitiveIntrinsics Primitives; + typedef typename Primitives::Type PrimType; + static_assert(sizeof(PrimType) == sizeof(T), + "Selection of PrimitiveIntrinsics was wrong"); + typedef CastHelper Cast; }; template struct IntrinsicMemoryOps : public IntrinsicBase { - typedef typename IntrinsicBase::ValueType ValueType; - typedef typename IntrinsicBase::Primitives Primitives; - typedef typename IntrinsicBase::PrimType PrimType; - typedef typename IntrinsicBase::Cast Cast; - static ValueType load(const ValueType& ptr) { - Barrier::beforeLoad(); - ValueType val = ptr; - Barrier::afterLoad(); - return val; - } - static void store(ValueType& ptr, ValueType val) { - // For SequentiallyConsistent, Primitives::store() will generate the - // proper memory fence. Everything else just needs a barrier before - // the store. - if (Order == SequentiallyConsistent) { - Primitives::store(reinterpret_cast(&ptr), - Cast::toPrimType(val)); - } else { - Barrier::beforeStore(); - ptr = val; - } - } - static ValueType exchange(ValueType& ptr, ValueType val) { - PrimType oldval = - Primitives::exchange(reinterpret_cast(&ptr), - Cast::toPrimType(val)); - return Cast::fromPrimType(oldval); - } - static bool compareExchange(ValueType& ptr, ValueType oldVal, ValueType newVal) { - return Primitives::compareExchange(reinterpret_cast(&ptr), - Cast::toPrimType(oldVal), - Cast::toPrimType(newVal)); + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + + static ValueType load(const ValueType& aPtr) + { + Barrier::beforeLoad(); + ValueType val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(ValueType& aPtr, ValueType aVal) + { + // For SequentiallyConsistent, Primitives::store() will generate the + // proper memory fence. Everything else just needs a barrier before + // the store. + if (Order == SequentiallyConsistent) { + Primitives::store(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + } else { + Barrier::beforeStore(); + aPtr = aVal; } + } + + static ValueType exchange(ValueType& aPtr, ValueType aVal) + { + PrimType oldval = + Primitives::exchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + return Cast::fromPrimType(oldval); + } + + static bool compareExchange(ValueType& aPtr, ValueType aOldVal, + ValueType aNewVal) + { + return Primitives::compareExchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aOldVal), + Cast::toPrimType(aNewVal)); + } }; template struct IntrinsicApplyHelper : public IntrinsicBase { - typedef typename IntrinsicBase::ValueType ValueType; - typedef typename IntrinsicBase::PrimType PrimType; - typedef typename IntrinsicBase::Cast Cast; - typedef PrimType (*BinaryOp)(PrimType*, PrimType); - typedef PrimType (*UnaryOp)(PrimType*); - - static ValueType applyBinaryFunction(BinaryOp op, ValueType& ptr, - ValueType val) { - PrimType* primTypePtr = reinterpret_cast(&ptr); - PrimType primTypeVal = Cast::toPrimType(val); - return Cast::fromPrimType(op(primTypePtr, primTypeVal)); - } - - static ValueType applyUnaryFunction(UnaryOp op, ValueType& ptr) { - PrimType* primTypePtr = reinterpret_cast(&ptr); - return Cast::fromPrimType(op(primTypePtr)); - } + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + typedef PrimType (*BinaryOp)(PrimType*, PrimType); + typedef PrimType (*UnaryOp)(PrimType*); + + static ValueType applyBinaryFunction(BinaryOp aOp, ValueType& aPtr, + ValueType aVal) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + PrimType primTypeVal = Cast::toPrimType(aVal); + return Cast::fromPrimType(aOp(primTypePtr, primTypeVal)); + } + + static ValueType applyUnaryFunction(UnaryOp aOp, ValueType& aPtr) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + return Cast::fromPrimType(aOp(primTypePtr)); + } }; template struct IntrinsicAddSub : public IntrinsicApplyHelper { - typedef typename IntrinsicApplyHelper::ValueType ValueType; - typedef typename IntrinsicBase::Primitives Primitives; - static ValueType add(ValueType& ptr, ValueType val) { - return applyBinaryFunction(&Primitives::add, ptr, val); - } - static ValueType sub(ValueType& ptr, ValueType val) { - return applyBinaryFunction(&Primitives::sub, ptr, val); - } + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::add, aPtr, aVal); + } + + static ValueType sub(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::sub, aPtr, aVal); + } }; template struct IntrinsicAddSub : public IntrinsicApplyHelper { - typedef typename IntrinsicApplyHelper::ValueType ValueType; - static ValueType add(ValueType& ptr, ptrdiff_t amount) { - return applyBinaryFunction(&Primitives::add, ptr, - (ValueType)(amount * sizeof(ValueType))); - } - static ValueType sub(ValueType& ptr, ptrdiff_t amount) { - return applyBinaryFunction(&Primitives::sub, ptr, - (ValueType)(amount * sizeof(ValueType))); - } + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::add, aPtr, + (ValueType)(aAmount * sizeof(T))); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::sub, aPtr, + (ValueType)(aAmount * sizeof(T))); + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - typedef typename IntrinsicAddSub::ValueType ValueType; - static ValueType inc(ValueType& ptr) { return add(ptr, 1); } - static ValueType dec(ValueType& ptr) { return sub(ptr, 1); } + typedef typename IntrinsicAddSub::ValueType ValueType; + static ValueType inc(ValueType& aPtr) { return add(aPtr, 1); } + static ValueType dec(ValueType& aPtr) { return sub(aPtr, 1); } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef typename IntrinsicIncDec::ValueType ValueType; - static ValueType or_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::or_, ptr, val); - } - static ValueType xor_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::xor_, ptr, val); - } - static ValueType and_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::and_, ptr, val); - } + typedef typename IntrinsicIncDec::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType or_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::or_, aPtr, aVal); + } + + static ValueType xor_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::xor_, aPtr, aVal); + } + + static ValueType and_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::and_, aPtr, aVal); + } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef typename IntrinsicMemoryOps::ValueType ValueType; + typedef typename IntrinsicMemoryOps::ValueType ValueType; + // This is required to make us be able to build with MSVC10, for unknown + // reasons. + typedef typename IntrinsicBase::Primitives Primitives; }; } // namespace detail @@ -832,73 +909,80 @@ namespace detail { template class AtomicBase { - // We only support 32-bit types on 32-bit Windows, which constrains our - // implementation elsewhere. But we support pointer-sized types everywhere. - static_assert(sizeof(T) == 4 || (sizeof(uintptr_t) == 8 && sizeof(T) == 8), - "mozilla/Atomics.h only supports 32-bit and pointer-sized types"); - - protected: - typedef typename detail::AtomicIntrinsics Intrinsics; - typename Intrinsics::ValueType mValue; - - public: - MOZ_CONSTEXPR AtomicBase() : mValue() {} - MOZ_CONSTEXPR AtomicBase(T aInit) : mValue(aInit) {} - - operator T() const { return Intrinsics::load(mValue); } - - T operator=(T aValue) { - Intrinsics::store(mValue, aValue); - return aValue; - } - - /** - * Performs an atomic swap operation. aValue is stored and the previous - * value of this variable is returned. - */ - T exchange(T aValue) { - return Intrinsics::exchange(mValue, aValue); - } - - /** - * Performs an atomic compare-and-swap operation and returns true if it - * succeeded. This is equivalent to atomically doing - * - * if (mValue == aOldValue) { - * mValue = aNewValue; - * return true; - * } else { - * return false; - * } - */ - bool compareExchange(T aOldValue, T aNewValue) { - return Intrinsics::compareExchange(mValue, aOldValue, aNewValue); - } - - private: - template - AtomicBase(const AtomicBase& aCopy) MOZ_DELETE; + // We only support 32-bit types on 32-bit Windows, which constrains our + // implementation elsewhere. But we support pointer-sized types everywhere. + static_assert(sizeof(T) == 4 || (sizeof(uintptr_t) == 8 && sizeof(T) == 8), + "mozilla/Atomics.h only supports 32-bit and pointer-sized types"); + +protected: + typedef typename detail::AtomicIntrinsics Intrinsics; + typename Intrinsics::ValueType mValue; + +public: + MOZ_CONSTEXPR AtomicBase() : mValue() {} + explicit MOZ_CONSTEXPR AtomicBase(T aInit) : mValue(aInit) {} + + // Note: we can't provide operator T() here because Atomic inherits + // from AtomcBase with T=uint32_t and not T=bool. If we implemented + // operator T() here, it would cause errors when comparing Atomic with + // a regular bool. + + T operator=(T aVal) + { + Intrinsics::store(mValue, aVal); + return aVal; + } + + /** + * Performs an atomic swap operation. aVal is stored and the previous + * value of this variable is returned. + */ + T exchange(T aVal) + { + return Intrinsics::exchange(mValue, aVal); + } + + /** + * Performs an atomic compare-and-swap operation and returns true if it + * succeeded. This is equivalent to atomically doing + * + * if (mValue == aOldValue) { + * mValue = aNewValue; + * return true; + * } else { + * return false; + * } + */ + bool compareExchange(T aOldValue, T aNewValue) + { + return Intrinsics::compareExchange(mValue, aOldValue, aNewValue); + } + +private: + template + AtomicBase(const AtomicBase& aCopy) MOZ_DELETE; }; template class AtomicBaseIncDec : public AtomicBase { - typedef typename detail::AtomicBase Base; + typedef typename detail::AtomicBase Base; - public: - MOZ_CONSTEXPR AtomicBaseIncDec() : Base() {} - MOZ_CONSTEXPR AtomicBaseIncDec(T aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR AtomicBaseIncDec() : Base() {} + explicit MOZ_CONSTEXPR AtomicBaseIncDec(T aInit) : Base(aInit) {} - using Base::operator=; + using Base::operator=; - T operator++(int) { return Base::Intrinsics::inc(Base::mValue); } - T operator--(int) { return Base::Intrinsics::dec(Base::mValue); } - T operator++() { return Base::Intrinsics::inc(Base::mValue) + 1; } - T operator--() { return Base::Intrinsics::dec(Base::mValue) - 1; } + operator T() const { return Base::Intrinsics::load(Base::mValue); } + T operator++(int) { return Base::Intrinsics::inc(Base::mValue); } + T operator--(int) { return Base::Intrinsics::dec(Base::mValue); } + T operator++() { return Base::Intrinsics::inc(Base::mValue) + 1; } + T operator--() { return Base::Intrinsics::dec(Base::mValue) - 1; } - private: - template - AtomicBaseIncDec(const AtomicBaseIncDec& aCopy) MOZ_DELETE; +private: + template + AtomicBaseIncDec(const AtomicBaseIncDec& aCopy) MOZ_DELETE; }; } // namespace detail @@ -934,25 +1018,45 @@ class Atomic; * swap method is provided. */ template -class Atomic::value>::Type> +class Atomic::value && + !IsSame::value>::Type> : public detail::AtomicBaseIncDec { - typedef typename detail::AtomicBaseIncDec Base; + typedef typename detail::AtomicBaseIncDec Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + + using Base::operator=; + + T operator+=(T aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + T operator-=(T aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } - using Base::operator=; + T operator|=(T aVal) + { + return Base::Intrinsics::or_(Base::mValue, aVal) | aVal; + } - T operator+=(T delta) { return Base::Intrinsics::add(Base::mValue, delta) + delta; } - T operator-=(T delta) { return Base::Intrinsics::sub(Base::mValue, delta) - delta; } - T operator|=(T val) { return Base::Intrinsics::or_(Base::mValue, val) | val; } - T operator^=(T val) { return Base::Intrinsics::xor_(Base::mValue, val) ^ val; } - T operator&=(T val) { return Base::Intrinsics::and_(Base::mValue, val) & val; } + T operator^=(T aVal) + { + return Base::Intrinsics::xor_(Base::mValue, aVal) ^ aVal; + } - private: - Atomic(Atomic& aOther) MOZ_DELETE; + T operator&=(T aVal) + { + return Base::Intrinsics::and_(Base::mValue, aVal) & aVal; + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; /** @@ -966,23 +1070,26 @@ class Atomic::value>::Type> template class Atomic : public detail::AtomicBaseIncDec { - typedef typename detail::AtomicBaseIncDec Base; + typedef typename detail::AtomicBaseIncDec Base; - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T* aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T* aInit) : Base(aInit) {} - using Base::operator=; + using Base::operator=; - T* operator+=(ptrdiff_t delta) { - return Base::Intrinsics::add(Base::mValue, delta) + delta; - } - T* operator-=(ptrdiff_t delta) { - return Base::Intrinsics::sub(Base::mValue, delta) - delta; - } + T* operator+=(ptrdiff_t aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } + + T* operator-=(ptrdiff_t aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } - private: - Atomic(Atomic& aOther) MOZ_DELETE; +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; /** @@ -994,16 +1101,69 @@ template class Atomic::value>::Type> : public detail::AtomicBase { - typedef typename detail::AtomicBase Base; + typedef typename detail::AtomicBase Base; - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} - using Base::operator=; + operator T() const { return Base::Intrinsics::load(Base::mValue); } - private: - Atomic(Atomic& aOther) MOZ_DELETE; + using Base::operator=; + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +/** + * Atomic implementation for boolean types. + * + * The atomic store and load operations and the atomic swap method is provided. + * + * Note: + * + * - sizeof(Atomic) != sizeof(bool) for some implementations of + * bool and/or some implementations of std::atomic. This is allowed in + * [atomic.types.generic]p9. + * + * - It's not obvious whether the 8-bit atomic functions on Windows are always + * inlined or not. If they are not inlined, the corresponding functions in the + * runtime library are not available on Windows XP. This is why we implement + * Atomic with an underlying type of uint32_t. + */ +template +class Atomic + : protected detail::AtomicBase +{ + typedef typename detail::AtomicBase Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(bool aInit) : Base(aInit) {} + + // We provide boolean wrappers for the underlying AtomicBase methods. + operator bool() const + { + return Base::Intrinsics::load(Base::mValue); + } + + bool operator=(bool aVal) + { + return Base::operator=(aVal); + } + + bool exchange(bool aVal) + { + return Base::exchange(aVal); + } + + bool compareExchange(bool aOldValue, bool aNewValue) + { + return Base::compareExchange(aOldValue, aNewValue); + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Attributes.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Attributes.h index 671f30cded..cdce8c7717 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Attributes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Attributes.h @@ -37,6 +37,7 @@ # define MOZ_ALWAYS_INLINE inline #endif +#if defined(_MSC_VER) /* * g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality * without warnings (functionality used by the macros below). These modes are @@ -44,8 +45,27 @@ * standardly, by checking whether __cplusplus has a C++11 or greater value. * Current versions of g++ do not correctly set __cplusplus, so we check both * for forward compatibility. + * + * Even though some versions of MSVC support explicit conversion operators, we + * don't indicate support for them here, due to + * http://stackoverflow.com/questions/20498142/visual-studio-2013-explicit-keyword-bug */ -#if defined(__clang__) +# if _MSC_VER >= 1800 +# define MOZ_HAVE_CXX11_DELETE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_FINAL final +# else +# if defined(__clang__) +# error Please do not try to use clang-cl with MSVC10 or below emulation! +# endif + /* MSVC <= 10 used to spell "final" as "sealed". */ +# define MOZ_HAVE_CXX11_FINAL sealed +# endif +# define MOZ_HAVE_CXX11_OVERRIDE +# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) +# define MOZ_HAVE_NORETURN __declspec(noreturn) +#elif defined(__clang__) /* * Per Clang documentation, "Note that marketing version numbers should not * be used to check for language features, as different vendors use different @@ -57,6 +77,9 @@ # if __has_extension(cxx_constexpr) # define MOZ_HAVE_CXX11_CONSTEXPR # endif +# if __has_extension(cxx_explicit_conversions) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif # if __has_extension(cxx_deleted_functions) # define MOZ_HAVE_CXX11_DELETE # endif @@ -79,6 +102,9 @@ # if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) # define MOZ_HAVE_CXX11_CONSTEXPR # endif +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif # define MOZ_HAVE_CXX11_DELETE # else /* __final is a non-C++11 GCC synonym for 'final', per GCC r176655. */ @@ -88,19 +114,16 @@ # endif # define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) # define MOZ_HAVE_NORETURN __attribute__((noreturn)) -#elif defined(_MSC_VER) -# if _MSC_VER >= 1800 -# define MOZ_HAVE_CXX11_DELETE -# endif -# if _MSC_VER >= 1700 -# define MOZ_HAVE_CXX11_FINAL final -# else - /* MSVC <= 10 used to spell "final" as "sealed". */ -# define MOZ_HAVE_CXX11_FINAL sealed +#endif + +/* + * When built with clang analyzer (a.k.a scan-build), define MOZ_HAVE_NORETURN + * to mark some false positives + */ +#ifdef __clang_analyzer__ +# if __has_extension(attribute_analyzer_noreturn) +# define MOZ_HAVE_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) # endif -# define MOZ_HAVE_CXX11_OVERRIDE -# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) -# define MOZ_HAVE_NORETURN __declspec(noreturn) #endif /* @@ -121,6 +144,31 @@ # define MOZ_CONSTEXPR_VAR const #endif +/* + * MOZ_EXPLICIT_CONVERSION is a specifier on a type conversion + * overloaded operator that declares that a C++11 compiler should restrict + * this operator to allow only explicit type conversions, disallowing + * implicit conversions. + * + * Example: + * + * template + * class Ptr + * { + * T* mPtr; + * MOZ_EXPLICIT_CONVERSION operator bool() const + * { + * return mPtr != nullptr; + * } + * }; + * + */ +#ifdef MOZ_HAVE_EXPLICIT_CONVERSION +# define MOZ_EXPLICIT_CONVERSION explicit +#else +# define MOZ_EXPLICIT_CONVERSION /* no support */ +#endif + /* * MOZ_NEVER_INLINE is a macro which expands to tell the compiler that the * method decorated with it must never be inlined, even if the compiler would @@ -153,18 +201,47 @@ # define MOZ_NORETURN /* no support */ #endif +/* + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS, specified at the end of a function + * declaration, indicates that for the purposes of static analysis, this + * function does not return. (The function definition does not need to be + * annotated.) + * + * MOZ_ReportCrash(const char* s, const char* file, int ln) + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS + * + * Some static analyzers, like scan-build from clang, can use this information + * to eliminate false positives. From the upstream documentation of scan-build: + * "This attribute is useful for annotating assertion handlers that actually + * can return, but for the purpose of using the analyzer we want to pretend + * that such functions do not return." + * + */ +#if defined(MOZ_HAVE_ANALYZER_NORETURN) +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS MOZ_HAVE_ANALYZER_NORETURN +#else +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS /* no support */ +#endif + /* * MOZ_ASAN_BLACKLIST is a macro to tell AddressSanitizer (a compile-time - * instrumentation shipped with Clang) to not instrument the annotated function. - * Furthermore, it will prevent the compiler from inlining the function because - * inlining currently breaks the blacklisting mechanism of AddressSanitizer. + * instrumentation shipped with Clang and GCC) to not instrument the annotated + * function. Furthermore, it will prevent the compiler from inlining the + * function because inlining currently breaks the blacklisting mechanism of + * AddressSanitizer. */ #if defined(__has_feature) # if __has_feature(address_sanitizer) -# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) -# else -# define MOZ_ASAN_BLACKLIST /* nothing */ +# define MOZ_HAVE_ASAN_BLACKLIST # endif +#elif defined(__GNUC__) +# if defined(__SANITIZE_ADDRESS__) +# define MOZ_HAVE_ASAN_BLACKLIST +# endif +#endif + +#if defined(MOZ_HAVE_ASAN_BLACKLIST) +# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) #else # define MOZ_ASAN_BLACKLIST /* nothing */ #endif @@ -197,9 +274,9 @@ * * struct NonCopyable * { - * private: - * NonCopyable(const NonCopyable& other) MOZ_DELETE; - * void operator=(const NonCopyable& other) MOZ_DELETE; + * private: + * NonCopyable(const NonCopyable& aOther) MOZ_DELETE; + * void operator=(const NonCopyable& aOther) MOZ_DELETE; * }; * * If MOZ_DELETE can't be implemented for the current compiler, use of the @@ -225,23 +302,23 @@ * * class Base * { - * public: - * virtual void f() = 0; + * public: + * virtual void f() = 0; * }; * class Derived1 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE; + * public: + * virtual void f() MOZ_OVERRIDE; * }; * class Derived2 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE = 0; + * public: + * virtual void f() MOZ_OVERRIDE = 0; * }; * class Derived3 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE { } + * public: + * virtual void f() MOZ_OVERRIDE { } * }; * * In compilers supporting C++11 override controls, MOZ_OVERRIDE *requires* that @@ -269,16 +346,16 @@ * * class Base MOZ_FINAL * { - * public: - * Base(); - * ~Base(); - * virtual void f() { } + * public: + * Base(); + * ~Base(); + * virtual void f() { } * }; * // This will be an error in some compilers: * class Derived : public Base * { - * public: - * ~Derived() { } + * public: + * ~Derived() { } * }; * * One particularly common reason to specify MOZ_FINAL upon a class is to tell @@ -305,14 +382,14 @@ * * class Base * { - * public: - * virtual void f() MOZ_FINAL; + * public: + * virtual void f() MOZ_FINAL; * }; * class Derived * { - * public: - * // This will be an error in some compilers: - * virtual void f(); + * public: + * // This will be an error in some compilers: + * virtual void f(); * }; * * In compilers implementing final controls, it is an error for a derived class @@ -372,13 +449,13 @@ * * typedef int MOZ_TYPE_ATTRIBUTE MagicInt; * int MOZ_TYPE_ATTRIBUTE someVariable; - * int * MOZ_TYPE_ATTRIBUTE magicPtrInt; - * int MOZ_TYPE_ATTRIBUTE * ptrToMagicInt; + * int* MOZ_TYPE_ATTRIBUTE magicPtrInt; + * int MOZ_TYPE_ATTRIBUTE* ptrToMagicInt; * * Attributes that apply to statements precede the statement: * * MOZ_IF_ATTRIBUTE if (x == 0) - * MOZ_DO_ATTRIBUTE do { } while(0); + * MOZ_DO_ATTRIBUTE do { } while (0); * * Attributes that apply to labels precede the label: * @@ -412,11 +489,16 @@ * MOZ_HEAP_ALLOCATOR: Applies to any function. This indicates that the return * value is allocated on the heap, and will as a result check such allocations * during MOZ_STACK_CLASS and MOZ_NONHEAP_CLASS annotation checking. + * MOZ_IMPLICIT: Applies to constructors. Implicit conversion constructors + * are disallowed by default unless they are marked as MOZ_IMPLICIT. This + * attribute must be used for constructors which intend to provide implicit + * conversions. */ #ifdef MOZ_CLANG_PLUGIN # define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override"))) # define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class"))) # define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class"))) +# define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) /* * It turns out that clang doesn't like void func() __attribute__ {} without a * warning, so use pragmas to disable the warning. This code won't work on GCC @@ -431,6 +513,7 @@ # define MOZ_MUST_OVERRIDE /* nothing */ # define MOZ_STACK_CLASS /* nothing */ # define MOZ_NONHEAP_CLASS /* nothing */ +# define MOZ_IMPLICIT /* nothing */ # define MOZ_HEAP_ALLOCATOR /* nothing */ #endif /* MOZ_CLANG_PLUGIN */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/BinarySearch.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/BinarySearch.h new file mode 100644 index 0000000000..c8f593d6a9 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/BinarySearch.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_BinarySearch_h +#define mozilla_BinarySearch_h + +#include "mozilla/Assertions.h" + +#include + +namespace mozilla { + +/* + * The algorithm searches the given container |aContainer| over the sorted + * index range [aBegin, aEnd) for an index |i| where |aContainer[i] == aTarget|. + * If such an index |i| is found, BinarySearch returns |true| and the index is + * returned via the outparam |aMatchOrInsertionPoint|. If no index is found, + * BinarySearch returns |false| and the outparam returns the first index in + * [aBegin, aEnd] where |aTarget| can be inserted to maintain sorted order. + * + * Example: + * + * Vector sortedInts = ... + * + * size_t match; + * if (BinarySearch(sortedInts, 0, sortedInts.length(), 13, &match)) { + * printf("found 13 at %lu\n", match); + * } + */ + +template +bool +BinarySearch(const Container& aContainer, size_t aBegin, size_t aEnd, + T aTarget, size_t* aMatchOrInsertionPoint) +{ + MOZ_ASSERT(aBegin <= aEnd); + + size_t low = aBegin; + size_t high = aEnd; + while (low != high) { + size_t middle = low + (high - low) / 2; + + // Allow any intermediate type so long as it provides a suitable ordering + // relation. + const auto& middleValue = aContainer[middle]; + + MOZ_ASSERT(aContainer[low] <= aContainer[middle]); + MOZ_ASSERT(aContainer[middle] <= aContainer[high - 1]); + MOZ_ASSERT(aContainer[low] <= aContainer[high - 1]); + + if (aTarget == middleValue) { + *aMatchOrInsertionPoint = middle; + return true; + } + + if (aTarget < middleValue) { + high = middle; + } else { + low = middle + 1; + } + } + + *aMatchOrInsertionPoint = low; + return false; +} + +} // namespace mozilla + +#endif // mozilla_BinarySearch_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/BloomFilter.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/BloomFilter.h index 8129c489d4..6757e41181 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/BloomFilter.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/BloomFilter.h @@ -55,177 +55,199 @@ namespace mozilla { template class BloomFilter { - /* - * A counting Bloom filter with 8-bit counters. For now we assume - * that having two hash functions is enough, but we may revisit that - * decision later. - * - * The filter uses an array with 2**KeySize entries. - * - * Assuming a well-distributed hash function, a Bloom filter with - * array size M containing N elements and - * using k hash function has expected false positive rate exactly - * - * $ (1 - (1 - 1/M)^{kN})^k $ - * - * because each array slot has a - * - * $ (1 - 1/M)^{kN} $ - * - * chance of being 0, and the expected false positive rate is the - * probability that all of the k hash functions will hit a nonzero - * slot. - * - * For reasonable assumptions (M large, kN large, which should both - * hold if we're worried about false positives) about M and kN this - * becomes approximately - * - * $$ (1 - \exp(-kN/M))^k $$ - * - * For our special case of k == 2, that's $(1 - \exp(-2N/M))^2$, - * or in other words - * - * $$ N/M = -0.5 * \ln(1 - \sqrt(r)) $$ - * - * where r is the false positive rate. This can be used to compute - * the desired KeySize for a given load N and false positive rate r. - * - * If N/M is assumed small, then the false positive rate can - * further be approximated as 4*N^2/M^2. So increasing KeySize by - * 1, which doubles M, reduces the false positive rate by about a - * factor of 4, and a false positive rate of 1% corresponds to - * about M/N == 20. - * - * What this means in practice is that for a few hundred keys using a - * KeySize of 12 gives false positive rates on the order of 0.25-4%. - * - * Similarly, using a KeySize of 10 would lead to a 4% false - * positive rate for N == 100 and to quite bad false positive - * rates for larger N. - */ - public: - BloomFilter() { - static_assert(KeySize <= keyShift, "KeySize too big"); - - // Should we have a custom operator new using calloc instead and - // require that we're allocated via the operator? - clear(); - } - - /* - * Clear the filter. This should be done before reusing it, because - * just removing all items doesn't clear counters that hit the upper - * bound. - */ - void clear(); - - /* - * Add an item to the filter. - */ - void add(const T* t); - - /* - * Remove an item from the filter. - */ - void remove(const T* t); - - /* - * Check whether the filter might contain an item. This can - * sometimes return true even if the item is not in the filter, - * but will never return false for items that are actually in the - * filter. - */ - bool mightContain(const T* t) const; - - /* - * Methods for add/remove/contain when we already have a hash computed - */ - void add(uint32_t hash); - void remove(uint32_t hash); - bool mightContain(uint32_t hash) const; - - private: - static const size_t arraySize = (1 << KeySize); - static const uint32_t keyMask = (1 << KeySize) - 1; - static const uint32_t keyShift = 16; - - static uint32_t hash1(uint32_t hash) { return hash & keyMask; } - static uint32_t hash2(uint32_t hash) { return (hash >> keyShift) & keyMask; } - - uint8_t& firstSlot(uint32_t hash) { return counters[hash1(hash)]; } - uint8_t& secondSlot(uint32_t hash) { return counters[hash2(hash)]; } - const uint8_t& firstSlot(uint32_t hash) const { return counters[hash1(hash)]; } - const uint8_t& secondSlot(uint32_t hash) const { return counters[hash2(hash)]; } - - static bool full(const uint8_t& slot) { return slot == UINT8_MAX; } - - uint8_t counters[arraySize]; + /* + * A counting Bloom filter with 8-bit counters. For now we assume + * that having two hash functions is enough, but we may revisit that + * decision later. + * + * The filter uses an array with 2**KeySize entries. + * + * Assuming a well-distributed hash function, a Bloom filter with + * array size M containing N elements and + * using k hash function has expected false positive rate exactly + * + * $ (1 - (1 - 1/M)^{kN})^k $ + * + * because each array slot has a + * + * $ (1 - 1/M)^{kN} $ + * + * chance of being 0, and the expected false positive rate is the + * probability that all of the k hash functions will hit a nonzero + * slot. + * + * For reasonable assumptions (M large, kN large, which should both + * hold if we're worried about false positives) about M and kN this + * becomes approximately + * + * $$ (1 - \exp(-kN/M))^k $$ + * + * For our special case of k == 2, that's $(1 - \exp(-2N/M))^2$, + * or in other words + * + * $$ N/M = -0.5 * \ln(1 - \sqrt(r)) $$ + * + * where r is the false positive rate. This can be used to compute + * the desired KeySize for a given load N and false positive rate r. + * + * If N/M is assumed small, then the false positive rate can + * further be approximated as 4*N^2/M^2. So increasing KeySize by + * 1, which doubles M, reduces the false positive rate by about a + * factor of 4, and a false positive rate of 1% corresponds to + * about M/N == 20. + * + * What this means in practice is that for a few hundred keys using a + * KeySize of 12 gives false positive rates on the order of 0.25-4%. + * + * Similarly, using a KeySize of 10 would lead to a 4% false + * positive rate for N == 100 and to quite bad false positive + * rates for larger N. + */ +public: + BloomFilter() + { + static_assert(KeySize <= kKeyShift, "KeySize too big"); + + // Should we have a custom operator new using calloc instead and + // require that we're allocated via the operator? + clear(); + } + + /* + * Clear the filter. This should be done before reusing it, because + * just removing all items doesn't clear counters that hit the upper + * bound. + */ + void clear(); + + /* + * Add an item to the filter. + */ + void add(const T* aValue); + + /* + * Remove an item from the filter. + */ + void remove(const T* aValue); + + /* + * Check whether the filter might contain an item. This can + * sometimes return true even if the item is not in the filter, + * but will never return false for items that are actually in the + * filter. + */ + bool mightContain(const T* aValue) const; + + /* + * Methods for add/remove/contain when we already have a hash computed + */ + void add(uint32_t aHash); + void remove(uint32_t aHash); + bool mightContain(uint32_t aHash) const; + +private: + static const size_t kArraySize = (1 << KeySize); + static const uint32_t kKeyMask = (1 << KeySize) - 1; + static const uint32_t kKeyShift = 16; + + static uint32_t hash1(uint32_t aHash) + { + return aHash & kKeyMask; + } + static uint32_t hash2(uint32_t aHash) + { + return (aHash >> kKeyShift) & kKeyMask; + } + + uint8_t& firstSlot(uint32_t aHash) + { + return mCounters[hash1(aHash)]; + } + uint8_t& secondSlot(uint32_t aHash) + { + return mCounters[hash2(aHash)]; + } + + const uint8_t& firstSlot(uint32_t aHash) const + { + return mCounters[hash1(aHash)]; + } + const uint8_t& secondSlot(uint32_t aHash) const + { + return mCounters[hash2(aHash)]; + } + + static bool full(const uint8_t& aSlot) { return aSlot == UINT8_MAX; } + + uint8_t mCounters[kArraySize]; }; template inline void BloomFilter::clear() { - memset(counters, 0, arraySize); + memset(mCounters, 0, kArraySize); } template inline void -BloomFilter::add(uint32_t hash) +BloomFilter::add(uint32_t aHash) { - uint8_t& slot1 = firstSlot(hash); - if (MOZ_LIKELY(!full(slot1))) + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { ++slot1; - - uint8_t& slot2 = secondSlot(hash); - if (MOZ_LIKELY(!full(slot2))) + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { ++slot2; + } } template MOZ_ALWAYS_INLINE void -BloomFilter::add(const T* t) +BloomFilter::add(const T* aValue) { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); return add(hash); } template inline void -BloomFilter::remove(uint32_t hash) +BloomFilter::remove(uint32_t aHash) { // If the slots are full, we don't know whether we bumped them to be // there when we added or not, so just leave them full. - uint8_t& slot1 = firstSlot(hash); - if (MOZ_LIKELY(!full(slot1))) + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { --slot1; - - uint8_t& slot2 = secondSlot(hash); - if (MOZ_LIKELY(!full(slot2))) + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { --slot2; + } } template MOZ_ALWAYS_INLINE void -BloomFilter::remove(const T* t) +BloomFilter::remove(const T* aValue) { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); remove(hash); } template MOZ_ALWAYS_INLINE bool -BloomFilter::mightContain(uint32_t hash) const +BloomFilter::mightContain(uint32_t aHash) const { // Check that all the slots for this hash contain something - return firstSlot(hash) && secondSlot(hash); + return firstSlot(aHash) && secondSlot(aHash); } template MOZ_ALWAYS_INLINE bool -BloomFilter::mightContain(const T* t) const +BloomFilter::mightContain(const T* aValue) const { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); return mightContain(hash); } diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Casting.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Casting.h index 76df0ef27e..dc449af6b6 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Casting.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Casting.h @@ -17,7 +17,8 @@ namespace mozilla { /** - * Return a value of type |To|, containing the underlying bit pattern of |from|. + * Return a value of type |To|, containing the underlying bit pattern of + * |aFrom|. * * |To| and |From| must be types of the same size; be careful of cross-platform * size differences, or this might fail to compile on some but not all @@ -25,16 +26,17 @@ namespace mozilla { */ template inline To -BitwiseCast(const From from) +BitwiseCast(const From aFrom) { static_assert(sizeof(From) == sizeof(To), "To and From must have the same size"); - union { - From from; - To to; + union + { + From mFrom; + To mTo; } u; - u.from = from; - return u.to; + u.mFrom = aFrom; + return u.mTo; } namespace detail { @@ -58,34 +60,39 @@ enum UUComparison { FromIsBigger, FromIsNotBigger }; // Unsigned-to-unsigned range check template sizeof(To)) ? FromIsBigger : FromIsNotBigger> + UUComparison = (sizeof(From) > sizeof(To)) + ? FromIsBigger + : FromIsNotBigger> struct UnsignedUnsignedCheck; template struct UnsignedUnsignedCheck { - public: - static bool checkBounds(const From from) { - return from <= From(To(-1)); - } +public: + static bool checkBounds(const From aFrom) + { + return aFrom <= From(To(-1)); + } }; template struct UnsignedUnsignedCheck { - public: - static bool checkBounds(const From from) { - return true; - } +public: + static bool checkBounds(const From aFrom) + { + return true; + } }; template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - return UnsignedUnsignedCheck::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return UnsignedUnsignedCheck::checkBounds(aFrom); + } }; // Signed-to-unsigned range check @@ -93,14 +100,17 @@ struct BoundsCheckImpl template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - if (from < 0) - return false; - if (sizeof(To) >= sizeof(From)) - return true; - return from <= From(To(-1)); +public: + static bool checkBounds(const From aFrom) + { + if (aFrom < 0) { + return false; + } + if (sizeof(To) >= sizeof(From)) { + return true; } + return aFrom <= From(To(-1)); + } }; // Unsigned-to-signed range check @@ -108,35 +118,40 @@ struct BoundsCheckImpl enum USComparison { FromIsSmaller, FromIsNotSmaller }; template + USComparison = (sizeof(From) < sizeof(To)) + ? FromIsSmaller + : FromIsNotSmaller> struct UnsignedSignedCheck; template struct UnsignedSignedCheck { - public: - static bool checkBounds(const From from) { - return true; - } +public: + static bool checkBounds(const From aFrom) + { + return true; + } }; template struct UnsignedSignedCheck { - public: - static bool checkBounds(const From from) { - const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); - return from <= From(MaxValue); - } +public: + static bool checkBounds(const From aFrom) + { + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + return aFrom <= From(MaxValue); + } }; template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - return UnsignedSignedCheck::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return UnsignedSignedCheck::checkBounds(aFrom); + } }; // Signed-to-signed range check @@ -144,42 +159,46 @@ struct BoundsCheckImpl template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - if (sizeof(From) <= sizeof(To)) - return true; - const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); - const To MinValue = -MaxValue - To(1); - return From(MinValue) <= from && - From(from) <= From(MaxValue); +public: + static bool checkBounds(const From aFrom) + { + if (sizeof(From) <= sizeof(To)) { + return true; } + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + const To MinValue = -MaxValue - To(1); + return From(MinValue) <= aFrom && + From(aFrom) <= From(MaxValue); + } }; template::value && IsIntegral::value> + bool TypesAreIntegral = IsIntegral::value && + IsIntegral::value> class BoundsChecker; template class BoundsChecker { - public: - static bool checkBounds(const From from) { return true; } +public: + static bool checkBounds(const From aFrom) { return true; } }; template class BoundsChecker { - public: - static bool checkBounds(const From from) { - return BoundsCheckImpl::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return BoundsCheckImpl::checkBounds(aFrom); + } }; template inline bool -IsInBounds(const From from) +IsInBounds(const From aFrom) { - return BoundsChecker::checkBounds(from); + return BoundsChecker::checkBounds(aFrom); } } // namespace detail @@ -191,10 +210,10 @@ IsInBounds(const From from) */ template inline To -SafeCast(const From from) +SafeCast(const From aFrom) { - MOZ_ASSERT((detail::IsInBounds(from))); - return static_cast(from); + MOZ_ASSERT((detail::IsInBounds(aFrom))); + return static_cast(aFrom); } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ChaosMode.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ChaosMode.h new file mode 100644 index 0000000000..ff59f2c6ec --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ChaosMode.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_ChaosMode_h +#define mozilla_ChaosMode_h + +#include +#include + +namespace mozilla { + +/** + * When "chaos mode" is activated, code that makes implicitly nondeterministic + * choices is encouraged to make random and extreme choices, to test more + * code paths and uncover bugs. + */ +class ChaosMode +{ +public: + static bool isActive() + { + // Flip this to true to activate chaos mode + return false; + } + + /** + * Returns a somewhat (but not uniformly) random uint32_t < aBound. + * Not to be used for anything except ChaosMode, since it's not very random. + */ + static uint32_t randomUint32LessThan(uint32_t aBound) + { + return uint32_t(rand()) % aBound; + } +}; + +} /* namespace mozilla */ + +#endif /* mozilla_ChaosMode_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Char16.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Char16.h index ba1acd8c76..e54eb0d5c8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Char16.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Char16.h @@ -9,11 +9,12 @@ #ifndef mozilla_Char16_h #define mozilla_Char16_h +#ifdef __cplusplus + /* - * C11 and C++11 introduce a char16_t type and support for UTF-16 string and - * character literals. C++11's char16_t is a distinct builtin type. C11's - * char16_t is a typedef for uint_least16_t. Technically, char16_t is a 16-bit - * code unit of a Unicode code point, not a "character". + * C++11 introduces a char16_t type and support for UTF-16 string and character + * literals. C++11's char16_t is a distinct builtin type. Technically, char16_t + * is a 16-bit code unit of a Unicode code point, not a "character". */ #ifdef _MSC_VER @@ -23,8 +24,7 @@ * to Windows's 16-bit wchar_t so we can declare UTF-16 literals as constant * expressions (and pass char16_t pointers to Windows APIs). We #define * _CHAR16T here in order to prevent yvals.h from overriding our char16_t - * typedefs, which we set to wchar_t for C++ code and to unsigned short for - * C code. + * typedefs, which we set to wchar_t for C++ code. * * In addition, #defining _CHAR16T will prevent yvals.h from defining a * char32_t type, so we have to undo that damage here and provide our own, @@ -32,14 +32,9 @@ */ # define MOZ_UTF16_HELPER(s) L##s # define _CHAR16T -# ifdef __cplusplus - typedef wchar_t char16_t; -# else - typedef unsigned short char16_t; -# endif - typedef unsigned int char32_t; -#elif defined(__cplusplus) && \ - (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)) +typedef wchar_t char16_t; +typedef unsigned int char32_t; +#else /* C++11 has a builtin char16_t type. */ # define MOZ_UTF16_HELPER(s) u##s /** @@ -50,20 +45,6 @@ # ifdef WIN32 # define MOZ_USE_CHAR16_WRAPPER # endif -#elif !defined(__cplusplus) -# if defined(WIN32) -# include - typedef wchar_t char16_t; -# else - /** - * We can't use the stdint.h uint16_t type here because including - * stdint.h will break building some of our C libraries, such as - * sqlite. - */ - typedef unsigned short char16_t; -# endif -#else -# error "Char16.h requires C++11 (or something like it) for UTF-16 support." #endif #ifdef MOZ_USE_CHAR16_WRAPPER @@ -80,86 +61,109 @@ */ class char16ptr_t { - private: - const char16_t* ptr; - static_assert(sizeof(char16_t) == sizeof(wchar_t), "char16_t and wchar_t sizes differ"); - - public: - char16ptr_t(const char16_t* ptr) : ptr(ptr) {} - char16ptr_t(const wchar_t* ptr) : ptr(reinterpret_cast(ptr)) {} - - /* Without this, nullptr assignment would be ambiguous. */ - constexpr char16ptr_t(decltype(nullptr)) : ptr(nullptr) {} - - operator const char16_t*() const { - return ptr; - } - operator const wchar_t*() const { - return reinterpret_cast(ptr); - } - operator const void*() const { - return ptr; - } - operator bool() const { - return ptr != nullptr; - } - operator std::wstring() const { - return std::wstring(static_cast(*this)); - } - - /* Explicit cast operators to allow things like (char16_t*)str. */ - explicit operator char16_t*() const { - return const_cast(ptr); - } - explicit operator wchar_t*() const { - return const_cast(static_cast(*this)); - } - - /** - * Some Windows API calls accept BYTE* but require that data actually be WCHAR*. - * Supporting this requires explicit operators to support the requisite explicit - * casts. - */ - explicit operator const char*() const { - return reinterpret_cast(ptr); - } - explicit operator const unsigned char*() const { - return reinterpret_cast(ptr); - } - explicit operator unsigned char*() const { - return const_cast(reinterpret_cast(ptr)); - } - explicit operator void*() const { - return const_cast(ptr); - } - - /* Some operators used on pointers. */ - char16_t operator[](size_t i) const { - return ptr[i]; - } - bool operator==(const char16ptr_t &x) const { - return ptr == x.ptr; - } - bool operator==(decltype(nullptr)) const { - return ptr == nullptr; - } - bool operator!=(const char16ptr_t &x) const { - return ptr != x.ptr; - } - bool operator!=(decltype(nullptr)) const { - return ptr != nullptr; - } - char16ptr_t operator+(size_t add) const { - return char16ptr_t(ptr + add); - } - ptrdiff_t operator-(const char16ptr_t &other) const { - return ptr - other.ptr; - } +private: + const char16_t* mPtr; + static_assert(sizeof(char16_t) == sizeof(wchar_t), + "char16_t and wchar_t sizes differ"); + +public: + char16ptr_t(const char16_t* aPtr) : mPtr(aPtr) {} + char16ptr_t(const wchar_t* aPtr) : + mPtr(reinterpret_cast(aPtr)) + {} + + /* Without this, nullptr assignment would be ambiguous. */ + constexpr char16ptr_t(decltype(nullptr)) : mPtr(nullptr) {} + + operator const char16_t*() const + { + return mPtr; + } + operator const wchar_t*() const + { + return reinterpret_cast(mPtr); + } + operator const void*() const + { + return mPtr; + } + operator bool() const + { + return mPtr != nullptr; + } + operator std::wstring() const + { + return std::wstring(static_cast(*this)); + } + + /* Explicit cast operators to allow things like (char16_t*)str. */ + explicit operator char16_t*() const + { + return const_cast(mPtr); + } + explicit operator wchar_t*() const + { + return const_cast(static_cast(*this)); + } + + /** + * Some Windows API calls accept BYTE* but require that data actually be + * WCHAR*. Supporting this requires explicit operators to support the + * requisite explicit casts. + */ + explicit operator const char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator const unsigned char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator unsigned char*() const + { + return + const_cast(reinterpret_cast(mPtr)); + } + explicit operator void*() const + { + return const_cast(mPtr); + } + + /* Some operators used on pointers. */ + char16_t operator[](size_t aIndex) const + { + return mPtr[aIndex]; + } + bool operator==(const char16ptr_t& aOther) const + { + return mPtr == aOther.mPtr; + } + bool operator==(decltype(nullptr)) const + { + return mPtr == nullptr; + } + bool operator!=(const char16ptr_t& aOther) const + { + return mPtr != aOther.mPtr; + } + bool operator!=(decltype(nullptr)) const + { + return mPtr != nullptr; + } + char16ptr_t operator+(size_t aValue) const + { + return char16ptr_t(mPtr + aValue); + } + ptrdiff_t operator-(const char16ptr_t& aOther) const + { + return mPtr - aOther.mPtr; + } }; inline decltype((char*)0-(char*)0) -operator-(const char16_t* x, const char16ptr_t y) { - return x - static_cast(y); +operator-(const char16_t* aX, const char16ptr_t aY) +{ + return aX - static_cast(aY); } #else @@ -168,10 +172,6 @@ typedef const char16_t* char16ptr_t; #endif -/* This is a temporary hack until bug 927728 is fixed. */ -#define __PRUNICHAR__ -typedef char16_t PRUnichar; - /* * Macro arguments used in concatenation or stringification won't be expanded. * Therefore, in order for |MOZ_UTF16(FOO)| to work as expected (which is to @@ -182,12 +182,11 @@ typedef char16_t PRUnichar; */ #define MOZ_UTF16(s) MOZ_UTF16_HELPER(s) -#if defined(__cplusplus) && \ - (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)) static_assert(sizeof(char16_t) == 2, "Is char16_t type 16 bits?"); static_assert(char16_t(-1) > char16_t(0), "Is char16_t type unsigned?"); static_assert(sizeof(MOZ_UTF16('A')) == 2, "Is char literal 16 bits?"); static_assert(sizeof(MOZ_UTF16("")[0]) == 2, "Is string char 16 bits?"); + #endif #endif /* mozilla_Char16_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/CheckedInt.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/CheckedInt.h index 050cef8ed8..ad4c5fef41 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/CheckedInt.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/CheckedInt.h @@ -9,21 +9,9 @@ #ifndef mozilla_CheckedInt_h #define mozilla_CheckedInt_h -// Enable relying of Mozilla's MFBT for possibly-available C++11 features -#define MOZ_CHECKEDINT_USE_MFBT - #include - -#ifdef MOZ_CHECKEDINT_USE_MFBT -# include "mozilla/Assertions.h" -#else -# include -# define MOZ_ASSERT(cond, reason) assert((cond) && reason) -# define MOZ_DELETE -#endif - -#include -#include +#include "mozilla/Assertions.h" +#include "mozilla/IntegerTypeTraits.h" namespace mozilla { @@ -47,13 +35,13 @@ struct UnsupportedType {}; template struct IsSupportedPass2 { - static const bool value = false; + static const bool value = false; }; template struct IsSupported { - static const bool value = IsSupportedPass2::value; + static const bool value = IsSupportedPass2::value; }; template<> @@ -134,133 +122,45 @@ struct IsSupportedPass2 { static const bool value = true; }; /* - * Step 2: some integer-traits kind of stuff. + * Step 2: Implement the actual validity checks. + * + * Ideas taken from IntegerLib, code different. */ -template -struct StdintTypeForSizeAndSignedness -{}; - -template<> -struct StdintTypeForSizeAndSignedness<1, true> -{ typedef int8_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<1, false> -{ typedef uint8_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<2, true> -{ typedef int16_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<2, false> -{ typedef uint16_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<4, true> -{ typedef int32_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<4, false> -{ typedef uint32_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<8, true> -{ typedef int64_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<8, false> -{ typedef uint64_t Type; }; - -template -struct UnsignedType -{ - typedef typename StdintTypeForSizeAndSignedness::Type Type; -}; - -template -struct IsSigned -{ - static const bool value = IntegerType(-1) <= IntegerType(0); -}; - template struct TwiceBiggerType { - typedef typename StdintTypeForSizeAndSignedness< - sizeof(IntegerType) * 2, - IsSigned::value - >::Type Type; + typedef typename detail::StdintTypeForSizeAndSignedness< + sizeof(IntegerType) * 2, + IsSigned::value + >::Type Type; }; template struct TwiceBiggerType { - typedef UnsupportedType Type; + typedef UnsupportedType Type; }; -template -struct PositionOfSignBit -{ - static const size_t value = CHAR_BIT * sizeof(IntegerType) - 1; -}; - -template -struct MinValue -{ - private: - typedef typename UnsignedType::Type UnsignedIntegerType; - static const size_t PosOfSignBit = PositionOfSignBit::value; - - public: - // Bitwise ops may return a larger type, that's why we cast explicitly. - // In C++, left bit shifts on signed values is undefined by the standard - // unless the shifted value is representable. - // Notice that signed-to-unsigned conversions are always well-defined in - // the standard as the value congruent to 2**n, as expected. By contrast, - // unsigned-to-signed is only well-defined if the value is representable. - static const IntegerType value = - IsSigned::value - ? IntegerType(UnsignedIntegerType(1) << PosOfSignBit) - : IntegerType(0); -}; - -template -struct MaxValue -{ - // Tricksy, but covered by the unit test. - // Relies heavily on the type of MinValue::value - // being IntegerType. - static const IntegerType value = ~MinValue::value; -}; - -/* - * Step 3: Implement the actual validity checks. - * - * Ideas taken from IntegerLib, code different. - */ - template inline bool -HasSignBit(T x) +HasSignBit(T aX) { // In C++, right bit shifts on negative values is undefined by the standard. // Notice that signed-to-unsigned conversions are always well-defined in the // standard, as the value congruent modulo 2**n as expected. By contrast, // unsigned-to-signed is only well-defined if the value is representable. - return bool(typename UnsignedType::Type(x) - >> PositionOfSignBit::value); + return bool(typename MakeUnsigned::Type(aX) >> + PositionOfSignBit::value); } // Bitwise ops may return a larger type, so it's good to use this inline // helper guaranteeing that the result is really of type T. template inline T -BinaryComplement(T x) +BinaryComplement(T aX) { - return ~x; + return ~aX; } template struct DoesRangeContainRange { - static const bool value = sizeof(T) >= sizeof(U); + static const bool value = sizeof(T) >= sizeof(U); }; template struct DoesRangeContainRange { - static const bool value = sizeof(T) > sizeof(U); + static const bool value = sizeof(T) > sizeof(U); }; template struct DoesRangeContainRange { - static const bool value = false; + static const bool value = false; }; template struct IsInRangeImpl { - static bool run(U) - { - return true; - } + static bool run(U) + { + return true; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return x <= MaxValue::value && x >= MinValue::value; - } + static bool run(U aX) + { + return aX <= MaxValue::value && aX >= MinValue::value; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return x <= MaxValue::value; - } + static bool run(U aX) + { + return aX <= MaxValue::value; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return sizeof(T) > sizeof(U) || x <= U(MaxValue::value); - } + static bool run(U aX) + { + return sizeof(T) > sizeof(U) || aX <= U(MaxValue::value); + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return sizeof(T) >= sizeof(U) - ? x >= 0 - : x >= 0 && x <= U(MaxValue::value); - } + static bool run(U aX) + { + return sizeof(T) >= sizeof(U) + ? aX >= 0 + : aX >= 0 && aX <= U(MaxValue::value); + } }; template inline bool -IsInRange(U x) +IsInRange(U aX) { - return IsInRangeImpl::run(x); + return IsInRangeImpl::run(aX); } template inline bool -IsAddValid(T x, T y) +IsAddValid(T aX, T aY) { - // Addition is valid if the sign of x+y is equal to either that of x or that - // of y. Since the value of x+y is undefined if we have a signed type, we - // compute it using the unsigned type of the same size. - // Beware! These bitwise operations can return a larger integer type, - // if T was a small type like int8_t, so we explicitly cast to T. + // Addition is valid if the sign of aX+aY is equal to either that of aX or + // that of aY. Since the value of aX+aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. Beware! + // These bitwise operations can return a larger integer type, if T was a + // small type like int8_t, so we explicitly cast to T. - typename UnsignedType::Type ux = x; - typename UnsignedType::Type uy = y; - typename UnsignedType::Type result = ux + uy; + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux + uy; return IsSigned::value - ? HasSignBit(BinaryComplement(T((result ^ x) & (result ^ y)))) - : BinaryComplement(x) >= y; + ? HasSignBit(BinaryComplement(T((result ^ aX) & (result ^ aY)))) + : BinaryComplement(aX) >= aY; } template inline bool -IsSubValid(T x, T y) +IsSubValid(T aX, T aY) { - // Subtraction is valid if either x and y have same sign, or x-y and x have - // same sign. Since the value of x-y is undefined if we have a signed type, - // we compute it using the unsigned type of the same size. - typename UnsignedType::Type ux = x; - typename UnsignedType::Type uy = y; - typename UnsignedType::Type result = ux - uy; + // Subtraction is valid if either aX and aY have same sign, or aX-aY and aX + // have same sign. Since the value of aX-aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux - uy; return IsSigned::value - ? HasSignBit(BinaryComplement(T((result ^ x) & (x ^ y)))) - : x >= y; + ? HasSignBit(BinaryComplement(T((result ^ aX) & (aX ^ aY)))) + : aX >= aY; } template struct IsMulValidImpl { - static bool run(T x, T y) - { - typedef typename TwiceBiggerType::Type TwiceBiggerType; - TwiceBiggerType product = TwiceBiggerType(x) * TwiceBiggerType(y); - return IsInRange(product); - } + static bool run(T aX, T aY) + { + typedef typename TwiceBiggerType::Type TwiceBiggerType; + TwiceBiggerType product = TwiceBiggerType(aX) * TwiceBiggerType(aY); + return IsInRange(product); + } }; template struct IsMulValidImpl { - static bool run(T x, T y) - { - const T max = MaxValue::value; - const T min = MinValue::value; - - if (x == 0 || y == 0) - return true; - - if (x > 0) { - return y > 0 - ? x <= max / y - : y >= min / x; - } + static bool run(T aX, T aY) + { + const T max = MaxValue::value; + const T min = MinValue::value; - // If we reach this point, we know that x < 0. - return y > 0 - ? x >= min / y - : y >= max / x; + if (aX == 0 || aY == 0) { + return true; } + if (aX > 0) { + return aY > 0 + ? aX <= max / aY + : aY >= min / aX; + } + + // If we reach this point, we know that aX < 0. + return aY > 0 + ? aX >= min / aY + : aY >= max / aX; + } }; template struct IsMulValidImpl { - static bool run(T x, T y) - { - return y == 0 || x <= MaxValue::value / y; - } + static bool run(T aX, T aY) + { + return aY == 0 || aX <= MaxValue::value / aY; + } }; template inline bool -IsMulValid(T x, T y) +IsMulValid(T aX, T aY) { - return IsMulValidImpl::run(x, y); + return IsMulValidImpl::run(aX, aY); } template inline bool -IsDivValid(T x, T y) +IsDivValid(T aX, T aY) { - // Keep in mind that in the signed case, min/-1 is invalid because abs(min)>max. - return y != 0 && - !(IsSigned::value && x == MinValue::value && y == T(-1)); + // Keep in mind that in the signed case, min/-1 is invalid because + // abs(min)>max. + return aY != 0 && + !(IsSigned::value && aX == MinValue::value && aY == T(-1)); } template::value> @@ -455,36 +356,40 @@ struct IsModValidImpl; template inline bool -IsModValid(T x, T y) +IsModValid(T aX, T aY) { - return IsModValidImpl::run(x, y); + return IsModValidImpl::run(aX, aY); } /* * Mod is pretty simple. * For now, let's just use the ANSI C definition: - * If x or y are negative, the results are implementation defined. + * If aX or aY are negative, the results are implementation defined. * Consider these invalid. - * Undefined for y=0. - * The result will never exceed either x or y. + * Undefined for aY=0. + * The result will never exceed either aX or aY. * - * Checking that x>=0 is a warning when T is unsigned. + * Checking that aX>=0 is a warning when T is unsigned. */ template -struct IsModValidImpl { - static inline bool run(T x, T y) { - return y >= 1; +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + return aY >= 1; } }; template -struct IsModValidImpl { - static inline bool run(T x, T y) { - if (x < 0) +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + if (aX < 0) { return false; - - return y >= 1; + } + return aY >= 1; } }; @@ -494,32 +399,33 @@ struct NegateImpl; template struct NegateImpl { - static CheckedInt negate(const CheckedInt& val) - { - // Handle negation separately for signed/unsigned, for simpler code and to - // avoid an MSVC warning negating an unsigned value. - return CheckedInt(0, val.isValid() && val.mValue == 0); - } + static CheckedInt negate(const CheckedInt& aVal) + { + // Handle negation separately for signed/unsigned, for simpler code and to + // avoid an MSVC warning negating an unsigned value. + return CheckedInt(0, aVal.isValid() && aVal.mValue == 0); + } }; template struct NegateImpl { - static CheckedInt negate(const CheckedInt& val) - { - // Watch out for the min-value, which (with twos-complement) can't be - // negated as -min-value is then (max-value + 1). - if (!val.isValid() || val.mValue == MinValue::value) - return CheckedInt(val.mValue, false); - return CheckedInt(-val.mValue, true); + static CheckedInt negate(const CheckedInt& aVal) + { + // Watch out for the min-value, which (with twos-complement) can't be + // negated as -min-value is then (max-value + 1). + if (!aVal.isValid() || aVal.mValue == MinValue::value) { + return CheckedInt(aVal.mValue, false); } + return CheckedInt(-aVal.mValue, true); + } }; } // namespace detail /* - * Step 4: Now define the CheckedInt class. + * Step 3: Now define the CheckedInt class. */ /** @@ -538,18 +444,18 @@ struct NegateImpl * (e.g. in case of a division by zero). * * For example, suppose that you want to implement a function that computes - * (x+y)/z, that doesn't crash if z==0, and that reports on error (divide by + * (aX+aY)/aZ, that doesn't crash if aZ==0, and that reports on error (divide by * zero or integer overflow). You could code it as follows: @code - bool computeXPlusYOverZ(int x, int y, int z, int *result) + bool computeXPlusYOverZ(int aX, int aY, int aZ, int* aResult) { - CheckedInt checkedResult = (CheckedInt(x) + y) / z; - if (checkedResult.isValid()) { - *result = checkedResult.value(); - return true; - } else { - return false; - } + CheckedInt checkedResult = (CheckedInt(aX) + aY) / aZ; + if (checkedResult.isValid()) { + *aResult = checkedResult.value(); + return true; + } else { + return false; + } } @endcode * @@ -592,193 +498,188 @@ struct NegateImpl template class CheckedInt { - protected: - T mValue; - bool mIsValid; +protected: + T mValue; + bool mIsValid; - template - CheckedInt(U value, bool isValid) : mValue(value), mIsValid(isValid) - { - static_assert(detail::IsSupported::value && - detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + template + CheckedInt(U aValue, bool aIsValid) : mValue(aValue), mIsValid(aIsValid) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - friend struct detail::NegateImpl; - - public: - /** - * Constructs a checked integer with given @a value. The checked integer is - * initialized as valid or invalid depending on whether the @a value - * is in range. - * - * This constructor is not explicit. Instead, the type of its argument is a - * separate template parameter, ensuring that no conversion is performed - * before this constructor is actually called. As explained in the above - * documentation for class CheckedInt, this constructor checks that its - * argument is valid. - */ - template - CheckedInt(U value) - : mValue(T(value)), - mIsValid(detail::IsInRange(value)) - { - static_assert(detail::IsSupported::value && - detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + friend struct detail::NegateImpl; + +public: + /** + * Constructs a checked integer with given @a value. The checked integer is + * initialized as valid or invalid depending on whether the @a value + * is in range. + * + * This constructor is not explicit. Instead, the type of its argument is a + * separate template parameter, ensuring that no conversion is performed + * before this constructor is actually called. As explained in the above + * documentation for class CheckedInt, this constructor checks that its + * argument is valid. + */ + template + CheckedInt(U aValue) + : mValue(T(aValue)), + mIsValid(detail::IsInRange(aValue)) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - template - friend class CheckedInt; + template + friend class CheckedInt; - template - CheckedInt toChecked() const - { - CheckedInt ret(mValue); - ret.mIsValid = ret.mIsValid && mIsValid; - return ret; - } + template + CheckedInt toChecked() const + { + CheckedInt ret(mValue); + ret.mIsValid = ret.mIsValid && mIsValid; + return ret; + } - /** Constructs a valid checked integer with initial value 0 */ - CheckedInt() : mValue(0), mIsValid(true) - { - static_assert(detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + /** Constructs a valid checked integer with initial value 0 */ + CheckedInt() : mValue(0), mIsValid(true) + { + static_assert(detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - /** @returns the actual value */ - T value() const - { - MOZ_ASSERT(mIsValid, "Invalid checked integer (division by zero or integer overflow)"); - return mValue; - } + /** @returns the actual value */ + T value() const + { + MOZ_ASSERT(mIsValid, "Invalid checked integer (division by zero or integer overflow)"); + return mValue; + } - /** - * @returns true if the checked integer is valid, i.e. is not the result - * of an invalid operation or of an operation involving an invalid checked - * integer - */ - bool isValid() const - { - return mIsValid; - } + /** + * @returns true if the checked integer is valid, i.e. is not the result + * of an invalid operation or of an operation involving an invalid checked + * integer + */ + bool isValid() const + { + return mIsValid; + } - template - friend CheckedInt operator +(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator +=(U rhs); - - template - friend CheckedInt operator -(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator -=(U rhs); - - template - friend CheckedInt operator *(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator *=(U rhs); - - template - friend CheckedInt operator /(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator /=(U rhs); - - template - friend CheckedInt operator %(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator %=(U rhs); - - CheckedInt operator -() const - { - return detail::NegateImpl::negate(*this); - } + template + friend CheckedInt operator +(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator +=(U aRhs); + + template + friend CheckedInt operator -(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator -=(U aRhs); + + template + friend CheckedInt operator *(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator *=(U aRhs); + + template + friend CheckedInt operator /(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator /=(U aRhs); + + template + friend CheckedInt operator %(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator %=(U aRhs); + + CheckedInt operator -() const + { + return detail::NegateImpl::negate(*this); + } - /** - * @returns true if the left and right hand sides are valid - * and have the same value. - * - * Note that these semantics are the reason why we don't offer - * a operator!=. Indeed, we'd want to have a!=b be equivalent to !(a==b) - * but that would mean that whenever a or b is invalid, a!=b - * is always true, which would be very confusing. - * - * For similar reasons, operators <, >, <=, >= would be very tricky to - * specify, so we just avoid offering them. - * - * Notice that these == semantics are made more reasonable by these facts: - * 1. a==b implies equality at the raw data level - * (the converse is false, as a==b is never true among invalids) - * 2. This is similar to the behavior of IEEE floats, where a==b - * means that a and b have the same value *and* neither is NaN. - */ - bool operator ==(const CheckedInt& other) const - { - return mIsValid && other.mIsValid && mValue == other.mValue; - } + /** + * @returns true if the left and right hand sides are valid + * and have the same value. + * + * Note that these semantics are the reason why we don't offer + * a operator!=. Indeed, we'd want to have a!=b be equivalent to !(a==b) + * but that would mean that whenever a or b is invalid, a!=b + * is always true, which would be very confusing. + * + * For similar reasons, operators <, >, <=, >= would be very tricky to + * specify, so we just avoid offering them. + * + * Notice that these == semantics are made more reasonable by these facts: + * 1. a==b implies equality at the raw data level + * (the converse is false, as a==b is never true among invalids) + * 2. This is similar to the behavior of IEEE floats, where a==b + * means that a and b have the same value *and* neither is NaN. + */ + bool operator ==(const CheckedInt& aOther) const + { + return mIsValid && aOther.mIsValid && mValue == aOther.mValue; + } - /** prefix ++ */ - CheckedInt& operator++() - { - *this += 1; - return *this; - } + /** prefix ++ */ + CheckedInt& operator++() + { + *this += 1; + return *this; + } - /** postfix ++ */ - CheckedInt operator++(int) - { - CheckedInt tmp = *this; - *this += 1; - return tmp; - } + /** postfix ++ */ + CheckedInt operator++(int) + { + CheckedInt tmp = *this; + *this += 1; + return tmp; + } - /** prefix -- */ - CheckedInt& operator--() - { - *this -= 1; - return *this; - } + /** prefix -- */ + CheckedInt& operator--() + { + *this -= 1; + return *this; + } - /** postfix -- */ - CheckedInt operator--(int) - { - CheckedInt tmp = *this; - *this -= 1; - return tmp; - } + /** postfix -- */ + CheckedInt operator--(int) + { + CheckedInt tmp = *this; + *this -= 1; + return tmp; + } - private: - /** - * The !=, <, <=, >, >= operators are disabled: - * see the comment on operator==. - */ - template - bool operator !=(U other) const MOZ_DELETE; - template - bool operator <(U other) const MOZ_DELETE; - template - bool operator <=(U other) const MOZ_DELETE; - template - bool operator >(U other) const MOZ_DELETE; - template - bool operator >=(U other) const MOZ_DELETE; +private: + /** + * The !=, <, <=, >, >= operators are disabled: + * see the comment on operator==. + */ + template bool operator !=(U aOther) const MOZ_DELETE; + template bool operator < (U aOther) const MOZ_DELETE; + template bool operator <=(U aOther) const MOZ_DELETE; + template bool operator > (U aOther) const MOZ_DELETE; + template bool operator >=(U aOther) const MOZ_DELETE; }; -#define MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP) \ -template \ -inline CheckedInt operator OP(const CheckedInt &lhs, \ - const CheckedInt &rhs) \ -{ \ - if (!detail::Is##NAME##Valid(lhs.mValue, rhs.mValue)) \ - return CheckedInt(0, false); \ - \ - return CheckedInt(lhs.mValue OP rhs.mValue, \ - lhs.mIsValid && rhs.mIsValid); \ -} +#define MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP) \ + template \ + inline CheckedInt \ + operator OP(const CheckedInt &aLhs, const CheckedInt &aRhs) \ + { \ + if (!detail::Is##NAME##Valid(aLhs.mValue, aRhs.mValue)) { \ + return CheckedInt(0, false); \ + } \ + return CheckedInt(aLhs.mValue OP aRhs.mValue, \ + aLhs.mIsValid && aRhs.mIsValid); \ + } MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Add, +) MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Sub, -) @@ -799,47 +700,47 @@ namespace detail { template struct CastToCheckedIntImpl { - typedef CheckedInt ReturnType; - static CheckedInt run(U u) { return u; } + typedef CheckedInt ReturnType; + static CheckedInt run(U aU) { return aU; } }; template struct CastToCheckedIntImpl > { - typedef const CheckedInt& ReturnType; - static const CheckedInt& run(const CheckedInt& u) { return u; } + typedef const CheckedInt& ReturnType; + static const CheckedInt& run(const CheckedInt& aU) { return aU; } }; } // namespace detail template inline typename detail::CastToCheckedIntImpl::ReturnType -castToCheckedInt(U u) +castToCheckedInt(U aU) { static_assert(detail::IsSupported::value && detail::IsSupported::value, "This type is not supported by CheckedInt"); - return detail::CastToCheckedIntImpl::run(u); + return detail::CastToCheckedIntImpl::run(aU); } -#define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP) \ -template \ -template \ -CheckedInt& CheckedInt::operator COMPOUND_OP(U rhs) \ -{ \ - *this = *this OP castToCheckedInt(rhs); \ - return *this; \ -} \ -template \ -inline CheckedInt operator OP(const CheckedInt &lhs, U rhs) \ -{ \ - return lhs OP castToCheckedInt(rhs); \ -} \ -template \ -inline CheckedInt operator OP(U lhs, const CheckedInt &rhs) \ -{ \ - return castToCheckedInt(lhs) OP rhs; \ -} +#define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP) \ + template \ + template \ + CheckedInt& CheckedInt::operator COMPOUND_OP(U aRhs) \ + { \ + *this = *this OP castToCheckedInt(aRhs); \ + return *this; \ + } \ + template \ + inline CheckedInt operator OP(const CheckedInt &aLhs, U aRhs) \ + { \ + return aLhs OP castToCheckedInt(aRhs); \ + } \ + template \ + inline CheckedInt operator OP(U aLhs, const CheckedInt &aRhs) \ + { \ + return castToCheckedInt(aLhs) OP aRhs; \ + } MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(+, +=) MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(*, *=) @@ -851,16 +752,16 @@ MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(%, %=) template inline bool -operator ==(const CheckedInt &lhs, U rhs) +operator ==(const CheckedInt &aLhs, U aRhs) { - return lhs == castToCheckedInt(rhs); + return aLhs == castToCheckedInt(aRhs); } template inline bool -operator ==(U lhs, const CheckedInt &rhs) +operator ==(U aLhs, const CheckedInt &aRhs) { - return castToCheckedInt(lhs) == rhs; + return castToCheckedInt(aLhs) == aRhs; } // Convenience typedefs. diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Compiler.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Compiler.h index fd5c98c98d..50f127da86 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Compiler.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Compiler.h @@ -9,23 +9,41 @@ #ifndef mozilla_Compiler_h #define mozilla_Compiler_h +#define MOZ_IS_GCC 0 +#define MOS_IS_MSVC 0 + #if !defined(__clang__) && defined(__GNUC__) -#define MOZ_IS_GCC 1 +# undef MOZ_IS_GCC +# define MOZ_IS_GCC 1 /* * This macro should simplify gcc version checking. For example, to check - * for gcc 4.5.1 or later, check `#ifdef MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`. + * for gcc 4.5.1 or later, check `#if MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`. */ # define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel) \ ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \ >= ((major) * 10000 + (minor) * 100 + (patchlevel))) -#if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0) -# error "mfbt (and Gecko) require at least gcc 4.4 to build." -#endif +# if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0) +# error "mfbt (and Gecko) require at least gcc 4.4 to build." +# endif -#else +#elif defined(_MSC_VER) -#define MOZ_IS_GCC 0 +# undef MOZ_IS_MSVC +# define MOZ_IS_MSVC 1 + /* + * This macro should simplify MSVC version checking. For example, to check + * for VC10 or later, check `#ifdef MOZ_MSVC_VERSION_AT_LEAST(10)`. + */ +# define MOZ_MSVC_VERSION_AT_LEAST(version) \ + (version == 10 ? _MSC_VER >= 1600 : \ + (version == 11 ? _MSC_VER >= 1700 : \ + (version == 12 ? _MSC_VER >= 1800 : \ + (version == 13 ? _MSC_VER >= 1900 : \ + 0)))) +# if !MOZ_MSVC_VERSION_AT_LEAST(10) +# error "mfbt (and Gecko) require at least MSVC 2010 RTM to build." +# endif #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Compression.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Compression.h index 2b8a7a7d8e..a764a1b5d5 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Compression.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Compression.h @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -22,41 +23,41 @@ namespace Compression { * * Compared to zlib it compresses at about 10x the speed, decompresses at about * 4x the speed and produces output of about 1.5x the size. - * */ class LZ4 { - public: - /** - * Compresses 'inputSize' bytes from 'source' into 'dest'. - * Destination buffer must be already allocated, - * and must be sized to handle worst cases situations (input data not compressible) - * Worst case size evaluation is provided by function LZ4_compressBound() + * Compresses |aInputSize| bytes from |aSource| into |aDest|. Destination + * buffer must be already allocated, and must be sized to handle worst cases + * situations (input data not compressible). Worst case size evaluation is + * provided by function maxCompressedSize() * - * @param inputSize is the input size. Max supported value is ~1.9GB - * @param return the number of bytes written in buffer dest + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return the number of bytes written in buffer |aDest| */ - static MFBT_API size_t compress(const char* source, size_t inputSize, char* dest); + static MFBT_API size_t + compress(const char* aSource, size_t aInputSize, char* aDest); /** - * Compress 'inputSize' bytes from 'source' into an output buffer - * 'dest' of maximum size 'maxOutputSize'. If it cannot achieve it, + * Compress |aInputSize| bytes from |aSource| into an output buffer + * |aDest| of maximum size |aMaxOutputSize|. If it cannot achieve it, * compression will stop, and result of the function will be zero, - * 'dest' will still be written to, but since the number of input + * |aDest| will still be written to, but since the number of input * bytes consumed is not returned the result is not usable. * * This function never writes outside of provided output buffer. * - * @param inputSize is the input size. Max supported value is ~1.9GB - * @param maxOutputSize is the size of the destination buffer (which must be already allocated) - * @return the number of bytes written in buffer 'dest' - or 0 if the compression fails - */ - static MFBT_API size_t compressLimitedOutput(const char* source, size_t inputSize, char* dest, - size_t maxOutputSize); + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @param aMaxOutputSize is the size of the destination buffer (which must + * be already allocated) + * @return the number of bytes written in buffer |aDest| or 0 if the + * compression fails + */ + static MFBT_API size_t + compressLimitedOutput(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize); /** * If the source stream is malformed, the function will stop decoding @@ -66,48 +67,50 @@ class LZ4 * This function never writes outside of provided buffers, and never * modifies input buffer. * - * note : destination buffer must be already allocated. - * its size must be a minimum of 'outputSize' bytes. - * @param outputSize is the output size, therefore the original size + * Note: destination buffer must be already allocated, and its size must be a + * minimum of |aOutputSize| bytes. + * + * @param aOutputSize is the output size, therefore the original size * @return the number of bytes read in the source buffer - */ - static MFBT_API bool decompress(const char* source, char* dest, size_t outputSize); + */ + static MFBT_API bool + decompress(const char* aSource, char* aDest, size_t aOutputSize); /** * If the source stream is malformed, the function will stop decoding * and return false. * - * This function never writes beyond dest + maxOutputSize, and is + * This function never writes beyond aDest + aMaxOutputSize, and is * therefore protected against malicious data packets. * - * note : Destination buffer must be already allocated. - * This version is slightly slower than the decompress - * without the maxOutputSize + * Note: Destination buffer must be already allocated. This version is + * slightly slower than the decompress without the aMaxOutputSize. * - * @param inputSize is the length of the input compressed data - * @param maxOutputSize is the size of the destination buffer (which must be already allocated) - * @param outputSize the actual number of bytes decoded in the destination buffer (necessarily <= maxOutputSize) - - */ - static MFBT_API bool decompress(const char* source, size_t inputSize, char* dest, - size_t maxOutputSize, size_t *outputSize); + * @param aInputSize is the length of the input compressed data + * @param aMaxOutputSize is the size of the destination buffer (which must be + * already allocated) + * @param aOutputSize the actual number of bytes decoded in the destination + * buffer (necessarily <= aMaxOutputSize) + */ + static MFBT_API bool + decompress(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize, size_t* aOutputSize); /* - Provides the maximum size that LZ4 may output in a "worst case" - scenario (input data not compressible) primarily useful for memory - allocation of output buffer. - note : this function is limited by "int" range (2^31-1) - - @param inputSize is the input size. Max supported value is ~1.9GB - @return maximum output size in a "worst case" scenario - */ - static inline size_t maxCompressedSize(size_t inputSize) + * Provides the maximum size that LZ4 may output in a "worst case" + * scenario (input data not compressible) primarily useful for memory + * allocation of output buffer. + * note : this function is limited by "int" range (2^31-1) + * + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return maximum output size in a "worst case" scenario + */ + static inline size_t maxCompressedSize(size_t aInputSize) { - size_t max = ((inputSize) + ((inputSize)/255) + 16); - MOZ_ASSERT(max > inputSize); - return max; + size_t max = (aInputSize + (aInputSize / 255) + 16); + MOZ_ASSERT(max > aInputSize); + return max; } - }; } /* namespace Compression */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/DebugOnly.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/DebugOnly.h index e5f0d729b5..5d0197b194 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/DebugOnly.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/DebugOnly.h @@ -12,6 +12,8 @@ #ifndef mozilla_DebugOnly_h #define mozilla_DebugOnly_h +#include "mozilla/Attributes.h" + namespace mozilla { /** @@ -27,50 +29,51 @@ namespace mozilla { * * DebugOnly instances can only be coerced to T in debug builds. In release * builds they don't have a value, so type coercion is not well defined. + * + * Note that DebugOnly instances still take up one byte of space, plus padding, + * when used as members of structs. */ template class DebugOnly { - public: +public: #ifdef DEBUG - T value; + T value; + + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T& aOther) : value(aOther) { } + DebugOnly(const DebugOnly& aOther) : value(aOther.value) { } + DebugOnly& operator=(const T& aRhs) { + value = aRhs; + return *this; + } - DebugOnly() { } - DebugOnly(const T& other) : value(other) { } - DebugOnly(const DebugOnly& other) : value(other.value) { } - DebugOnly& operator=(const T& rhs) { - value = rhs; - return *this; - } - void operator++(int) { - value++; - } - void operator--(int) { - value--; - } + void operator++(int) { value++; } + void operator--(int) { value--; } - T* operator&() { return &value; } + T* operator&() { return &value; } - operator T&() { return value; } - operator const T&() const { return value; } + operator T&() { return value; } + operator const T&() const { return value; } - T& operator->() { return value; } + T& operator->() { return value; } + const T& operator->() const { return value; } #else - DebugOnly() { } - DebugOnly(const T&) { } - DebugOnly(const DebugOnly&) { } - DebugOnly& operator=(const T&) { return *this; } - void operator++(int) { } - void operator--(int) { } + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T&) { } + DebugOnly(const DebugOnly&) { } + DebugOnly& operator=(const T&) { return *this; } + void operator++(int) { } + void operator--(int) { } #endif - /* - * DebugOnly must always have a destructor or else it will - * generate "unused variable" warnings, exactly what it's intended - * to avoid! - */ - ~DebugOnly() {} + /* + * DebugOnly must always have a destructor or else it will + * generate "unused variable" warnings, exactly what it's intended + * to avoid! + */ + ~DebugOnly() {} }; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Decimal.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Decimal.h index 3c67d784c9..9f4926bd06 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Decimal.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Decimal.h @@ -112,7 +112,7 @@ class Decimal { Sign m_sign; }; - MFBT_API Decimal(int32_t = 0); + MFBT_API explicit Decimal(int32_t = 0); MFBT_API Decimal(Sign, int exponent, uint64_t coefficient); MFBT_API Decimal(const Decimal&); @@ -185,7 +185,7 @@ class Decimal { int exponent; }; - MFBT_API Decimal(double); + MFBT_API explicit Decimal(double); MFBT_API Decimal compareTo(const Decimal&) const; static MFBT_API AlignedOperands alignOperands(const Decimal& lhs, const Decimal& rhs); diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Endian.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Endian.h index cb6bd27c05..e4e1ff8549 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Endian.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Endian.h @@ -42,21 +42,22 @@ * * class ExampleHeader * { - * private: - * uint32_t magic; - * uint32_t length; - * uint32_t totalRecords; - * uint64_t checksum; + * private: + * uint32_t mMagic; + * uint32_t mLength; + * uint32_t mTotalRecords; + * uint64_t mChecksum; * - * public: - * ExampleHeader(const void* data) { - * const uint8_t* ptr = static_cast(data); - * magic = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * length = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * totalRecords = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * checksum = BigEndian::readUint64(ptr); - * } - * ... + * public: + * ExampleHeader(const void* data) + * { + * const uint8_t* ptr = static_cast(data); + * mMagic = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mLength = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mTotalRecords = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mChecksum = BigEndian::readUint64(ptr); + * } + * ... * }; */ @@ -91,7 +92,7 @@ # else # error "CPU type is unknown" # endif -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) # if __LITTLE_ENDIAN__ # define MOZ_LITTLE_ENDIAN 1 # elif __BIG_ENDIAN__ @@ -119,17 +120,16 @@ * cases. */ #elif defined(__sparc) || defined(__sparc__) || \ - defined(_POWER) || defined(__powerpc__) || \ - defined(__ppc__) || defined(__hppa) || \ + defined(_POWER) || defined(__hppa) || \ defined(_MIPSEB) || defined(__ARMEB__) || \ - defined(__s390__) || \ + defined(__s390__) || defined(__AARCH64EB__) || \ (defined(__sh__) && defined(__LITTLE_ENDIAN__)) || \ (defined(__ia64) && defined(__BIG_ENDIAN__)) # define MOZ_BIG_ENDIAN 1 #elif defined(__i386) || defined(__i386__) || \ defined(__x86_64) || defined(__x86_64__) || \ defined(_MIPSEL) || defined(__ARMEL__) || \ - defined(__alpha__) || \ + defined(__alpha__) || defined(__AARCH64EL__) || \ (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ (defined(__ia64) && !defined(__BIG_ENDIAN__)) # define MOZ_LITTLE_ENDIAN 1 @@ -170,12 +170,12 @@ struct Swapper; template struct Swapper { - static T swap(T value) + static T swap(T aValue) { #if defined(MOZ_HAVE_BUILTIN_BYTESWAP16) - return MOZ_HAVE_BUILTIN_BYTESWAP16(value); + return MOZ_HAVE_BUILTIN_BYTESWAP16(aValue); #else - return T(((value & 0x00ff) << 8) | ((value & 0xff00) >> 8)); + return T(((aValue & 0x00ff) << 8) | ((aValue & 0xff00) >> 8)); #endif } }; @@ -183,17 +183,17 @@ struct Swapper template struct Swapper { - static T swap(T value) + static T swap(T aValue) { #if defined(__clang__) || defined(__GNUC__) - return T(__builtin_bswap32(value)); + return T(__builtin_bswap32(aValue)); #elif defined(_MSC_VER) - return T(_byteswap_ulong(value)); + return T(_byteswap_ulong(aValue)); #else - return T(((value & 0x000000ffU) << 24) | - ((value & 0x0000ff00U) << 8) | - ((value & 0x00ff0000U) >> 8) | - ((value & 0xff000000U) >> 24)); + return T(((aValue & 0x000000ffU) << 24) | + ((aValue & 0x0000ff00U) << 8) | + ((aValue & 0x00ff0000U) >> 8) | + ((aValue & 0xff000000U) >> 24)); #endif } }; @@ -201,21 +201,21 @@ struct Swapper template struct Swapper { - static inline T swap(T value) + static inline T swap(T aValue) { #if defined(__clang__) || defined(__GNUC__) - return T(__builtin_bswap64(value)); + return T(__builtin_bswap64(aValue)); #elif defined(_MSC_VER) - return T(_byteswap_uint64(value)); + return T(_byteswap_uint64(aValue)); #else - return T(((value & 0x00000000000000ffULL) << 56) | - ((value & 0x000000000000ff00ULL) << 40) | - ((value & 0x0000000000ff0000ULL) << 24) | - ((value & 0x00000000ff000000ULL) << 8) | - ((value & 0x000000ff00000000ULL) >> 8) | - ((value & 0x0000ff0000000000ULL) >> 24) | - ((value & 0x00ff000000000000ULL) >> 40) | - ((value & 0xff00000000000000ULL) >> 56)); + return T(((aValue & 0x00000000000000ffULL) << 56) | + ((aValue & 0x000000000000ff00ULL) << 40) | + ((aValue & 0x0000000000ff0000ULL) << 24) | + ((aValue & 0x00000000ff000000ULL) << 8) | + ((aValue & 0x000000ff00000000ULL) >> 8) | + ((aValue & 0x0000ff0000000000ULL) >> 24) | + ((aValue & 0x00ff000000000000ULL) >> 40) | + ((aValue & 0xff00000000000000ULL) >> 56)); #endif } }; @@ -230,360 +230,415 @@ enum Endianness { Little, Big }; class EndianUtils { - /** - * Assert that the memory regions [dest, dest+count) and [src, src+count] - * do not overlap. count is given in bytes. - */ - static void assertNoOverlap(const void* dest, const void* src, size_t count) - { - DebugOnly byteDestPtr = static_cast(dest); - DebugOnly byteSrcPtr = static_cast(src); - MOZ_ASSERT((byteDestPtr <= byteSrcPtr && - byteDestPtr + count <= byteSrcPtr) || - (byteSrcPtr <= byteDestPtr && - byteSrcPtr + count <= byteDestPtr)); - } + /** + * Assert that the memory regions [aDest, aDest+aCount) and + * [aSrc, aSrc+aCount] do not overlap. aCount is given in bytes. + */ + static void assertNoOverlap(const void* aDest, const void* aSrc, + size_t aCount) + { + DebugOnly byteDestPtr = static_cast(aDest); + DebugOnly byteSrcPtr = static_cast(aSrc); + MOZ_ASSERT((byteDestPtr <= byteSrcPtr && + byteDestPtr + aCount <= byteSrcPtr) || + (byteSrcPtr <= byteDestPtr && + byteSrcPtr + aCount <= byteDestPtr)); + } - template - static void assertAligned(T* ptr) - { - MOZ_ASSERT((uintptr_t(ptr) % sizeof(T)) == 0, "Unaligned pointer!"); + template + static void assertAligned(T* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % sizeof(T)) == 0, "Unaligned pointer!"); + } + +protected: + /** + * Return |aValue| converted from SourceEndian encoding to DestEndian + * encoding. + */ + template + static inline T maybeSwap(T aValue) + { + if (SourceEndian == DestEndian) { + return aValue; } + return Swapper::swap(aValue); + } - protected: - /** - * Return |value| converted from SourceEndian encoding to DestEndian - * encoding. - */ - template - static inline T maybeSwap(T value) - { - if (SourceEndian == DestEndian) - return value; + /** + * Convert |aCount| elements at |aPtr| from SourceEndian encoding to + * DestEndian encoding. + */ + template + static inline void maybeSwapInPlace(T* aPtr, size_t aCount) + { + assertAligned(aPtr); - return Swapper::swap(value); + if (SourceEndian == DestEndian) { + return; } + for (size_t i = 0; i < aCount; i++) { + aPtr[i] = Swapper::swap(aPtr[i]); + } + } - /** - * Convert |count| elements at |ptr| from SourceEndian encoding to - * DestEndian encoding. - */ - template - static inline void maybeSwapInPlace(T* ptr, size_t count) - { - assertAligned(ptr); + /** + * Write |aCount| elements to the unaligned address |aDest| in DestEndian + * format, using elements found at |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapTo(void* aDest, const T* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aSrc); - if (SourceEndian == DestEndian) - return; + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; + } - for (size_t i = 0; i < count; i++) - ptr[i] = Swapper::swap(ptr[i]); + uint8_t* byteDestPtr = static_cast(aDest); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + u.mVal = maybeSwap(aSrc[i]); + memcpy(byteDestPtr, u.mBuffer, sizeof(T)); + byteDestPtr += sizeof(T); } + } - /** - * Write |count| elements to the unaligned address |dest| in DestEndian - * format, using elements found at |src| in SourceEndian format. - */ - template - static void copyAndSwapTo(void* dest, const T* src, size_t count) - { - assertNoOverlap(dest, src, count * sizeof(T)); - assertAligned(src); - - if (SourceEndian == DestEndian) { - memcpy(dest, src, count * sizeof(T)); - return; - } - - uint8_t* byteDestPtr = static_cast(dest); - for (size_t i = 0; i < count; ++i) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - u.val = maybeSwap(src[i]); - memcpy(byteDestPtr, u.buffer, sizeof(T)); - byteDestPtr += sizeof(T); - } + /** + * Write |aCount| elements to |aDest| in DestEndian format, using elements + * found at the unaligned address |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapFrom(T* aDest, const void* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aDest); + + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; } - /** - * Write |count| elements to |dest| in DestEndian format, using elements - * found at the unaligned address |src| in SourceEndian format. - */ - template - static void copyAndSwapFrom(T* dest, const void* src, size_t count) - { - assertNoOverlap(dest, src, count * sizeof(T)); - assertAligned(dest); - - if (SourceEndian == DestEndian) { - memcpy(dest, src, count * sizeof(T)); - return; - } - - const uint8_t* byteSrcPtr = static_cast(src); - for (size_t i = 0; i < count; ++i) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - memcpy(u.buffer, byteSrcPtr, sizeof(T)); - dest[i] = maybeSwap(u.val); - byteSrcPtr += sizeof(T); - } + const uint8_t* byteSrcPtr = static_cast(aSrc); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, byteSrcPtr, sizeof(T)); + aDest[i] = maybeSwap(u.mVal); + byteSrcPtr += sizeof(T); } + } }; template class Endian : private EndianUtils { - protected: - /** Read a uint16_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint16_t readUint16(const void* p) { - return read(p); - } +protected: + /** Read a uint16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint16_t readUint16(const void* aPtr) + { + return read(aPtr); + } - /** Read a uint32_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint32_t readUint32(const void* p) { - return read(p); - } + /** Read a uint32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint32_t readUint32(const void* aPtr) + { + return read(aPtr); + } - /** Read a uint64_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint64_t readUint64(const void* p) { - return read(p); - } + /** Read a uint64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint64_t readUint64(const void* aPtr) + { + return read(aPtr); + } - /** Read an int16_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int16_t readInt16(const void* p) { - return read(p); - } + /** Read an int16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int16_t readInt16(const void* aPtr) + { + return read(aPtr); + } - /** Read an int32_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int32_t readInt32(const void* p) { - return read(p); - } + /** Read an int32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int32_t readInt32(const void* aPtr) + { + return read(aPtr); + } - /** Read an int64_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int64_t readInt64(const void* p) { - return read(p); - } + /** Read an int64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int64_t readInt64(const void* aPtr) + { + return read(aPtr); + } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint16(void* p, uint16_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint32(void* p, uint32_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint64(void* p, uint64_t val) { - write(p, val); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint16(void* aPtr, uint16_t aValue) + { + write(aPtr, aValue); + } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt16(void* p, int16_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt32(void* p, int32_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt64(void* p, int64_t val) { - write(p, val); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint32(void* aPtr, uint32_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T to little-endian format. - * - * This function is intended for cases where you have data in your - * native-endian format and you need it to appear in little-endian - * format for transmission. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToLittleEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to little-endian format if ThisEndian is Big. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapToLittleEndian(void* dest, const T* src, - size_t count) { - copyAndSwapTo(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapToLittleEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint64(void* aPtr, uint64_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T to big-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToBigEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to big-endian format if ThisEndian is Little. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapToBigEndian(void* dest, const T* src, size_t count) { - copyAndSwapTo(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapToBigEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt16(void* aPtr, int16_t aValue) + { + write(aPtr, aValue); + } - /* - * Synonyms for the big-endian functions, for better readability - * in network code. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToNetworkOrder(T value) { - return swapToBigEndian(value); - } - template - static void - copyAndSwapToNetworkOrder(void* dest, const T* src, size_t count) { - copyAndSwapToBigEndian(dest, src, count); - } - template - static void - swapToNetworkOrderInPlace(T* p, size_t count) { - swapToBigEndianInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt32(void* aPtr, int32_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T from little-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromLittleEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to little-endian format if ThisEndian is Big. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapFromLittleEndian(T* dest, const void* src, - size_t count) { - copyAndSwapFrom(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapFromLittleEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt64(void* aPtr, int64_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T from big-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromBigEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to big-endian format if ThisEndian is Little. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapFromBigEndian(T* dest, const void* src, - size_t count) { - copyAndSwapFrom(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapFromBigEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /* + * Converts a value of type T to little-endian format. + * + * This function is intended for cases where you have data in your + * native-endian format and you need it to appear in little-endian + * format for transmission. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToLittleEndian(T aValue) + { + return maybeSwap(aValue); + } - /* - * Synonyms for the big-endian functions, for better readability - * in network code. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromNetworkOrder(T value) { - return swapFromBigEndian(value); - } - template - static void copyAndSwapFromNetworkOrder(T* dest, const void* src, - size_t count) { - copyAndSwapFromBigEndian(dest, src, count); - } - template - static void swapFromNetworkOrderInPlace(T* p, size_t count) { - swapFromBigEndianInPlace(p, count); - } + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToLittleEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } - private: - /** - * Read a value of type T, encoded in endianness ThisEndian from |p|. - * Return that value encoded in native endianness. - */ - template - static T read(const void* p) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - memcpy(u.buffer, p, sizeof(T)); - return maybeSwap(u.val); - } + /* + * Likewise, but converts values in place. + */ + template + static void swapToLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } - /** - * Write a value of type T, in native endianness, to |p|, in ThisEndian - * endianness. - */ - template - static void write(void* p, T value) { - T tmp = maybeSwap(value); - memcpy(p, &tmp, sizeof(T)); - } + /* + * Converts a value of type T to big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToBigEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapToBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + + template + MOZ_WARN_UNUSED_RESULT static T swapToNetworkOrder(T aValue) + { + return swapToBigEndian(aValue); + } + + template + static void + copyAndSwapToNetworkOrder(void* aDest, const T* aSrc, size_t aCount) + { + copyAndSwapToBigEndian(aDest, aSrc, aCount); + } + + template + static void + swapToNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapToBigEndianInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from little-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromLittleEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromLittleEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromBigEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromNetworkOrder(T aValue) + { + return swapFromBigEndian(aValue); + } + + template + static void copyAndSwapFromNetworkOrder(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFromBigEndian(aDest, aSrc, aCount); + } + + template + static void swapFromNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapFromBigEndianInPlace(aPtr, aCount); + } + +private: + /** + * Read a value of type T, encoded in endianness ThisEndian from |aPtr|. + * Return that value encoded in native endianness. + */ + template + static T read(const void* aPtr) + { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, aPtr, sizeof(T)); + return maybeSwap(u.mVal); + } + + /** + * Write a value of type T, in native endianness, to |aPtr|, in ThisEndian + * endianness. + */ + template + static void write(void* aPtr, T aValue) + { + T tmp = maybeSwap(aValue); + memcpy(aPtr, &tmp, sizeof(T)); + } - Endian() MOZ_DELETE; - Endian(const Endian& other) MOZ_DELETE; - void operator=(const Endian& other) MOZ_DELETE; + Endian() MOZ_DELETE; + Endian(const Endian& aTther) MOZ_DELETE; + void operator=(const Endian& aOther) MOZ_DELETE; }; template class EndianReadWrite : public Endian { - private: - typedef Endian super; - - public: - using super::readUint16; - using super::readUint32; - using super::readUint64; - using super::readInt16; - using super::readInt32; - using super::readInt64; - using super::writeUint16; - using super::writeUint32; - using super::writeUint64; - using super::writeInt16; - using super::writeInt32; - using super::writeInt64; +private: + typedef Endian super; + +public: + using super::readUint16; + using super::readUint32; + using super::readUint64; + using super::readInt16; + using super::readInt32; + using super::readInt64; + using super::writeUint16; + using super::writeUint32; + using super::writeUint64; + using super::writeInt16; + using super::writeInt32; + using super::writeInt64; }; } /* namespace detail */ @@ -598,39 +653,39 @@ typedef BigEndian NetworkEndian; class NativeEndian MOZ_FINAL : public detail::Endian { - private: - typedef detail::Endian super; - - public: - /* - * These functions are intended for cases where you have data in your - * native-endian format and you need the data to appear in the appropriate - * endianness for transmission, serialization, etc. - */ - using super::swapToLittleEndian; - using super::copyAndSwapToLittleEndian; - using super::swapToLittleEndianInPlace; - using super::swapToBigEndian; - using super::copyAndSwapToBigEndian; - using super::swapToBigEndianInPlace; - using super::swapToNetworkOrder; - using super::copyAndSwapToNetworkOrder; - using super::swapToNetworkOrderInPlace; - - /* - * These functions are intended for cases where you have data in the - * given endianness (e.g. reading from disk or a file-format) and you - * need the data to appear in native-endian format for processing. - */ - using super::swapFromLittleEndian; - using super::copyAndSwapFromLittleEndian; - using super::swapFromLittleEndianInPlace; - using super::swapFromBigEndian; - using super::copyAndSwapFromBigEndian; - using super::swapFromBigEndianInPlace; - using super::swapFromNetworkOrder; - using super::copyAndSwapFromNetworkOrder; - using super::swapFromNetworkOrderInPlace; +private: + typedef detail::Endian super; + +public: + /* + * These functions are intended for cases where you have data in your + * native-endian format and you need the data to appear in the appropriate + * endianness for transmission, serialization, etc. + */ + using super::swapToLittleEndian; + using super::copyAndSwapToLittleEndian; + using super::swapToLittleEndianInPlace; + using super::swapToBigEndian; + using super::copyAndSwapToBigEndian; + using super::swapToBigEndianInPlace; + using super::swapToNetworkOrder; + using super::copyAndSwapToNetworkOrder; + using super::swapToNetworkOrderInPlace; + + /* + * These functions are intended for cases where you have data in the + * given endianness (e.g. reading from disk or a file-format) and you + * need the data to appear in native-endian format for processing. + */ + using super::swapFromLittleEndian; + using super::copyAndSwapFromLittleEndian; + using super::swapFromLittleEndianInPlace; + using super::swapFromBigEndian; + using super::copyAndSwapFromBigEndian; + using super::swapFromBigEndianInPlace; + using super::swapFromNetworkOrder; + using super::copyAndSwapFromNetworkOrder; + using super::swapFromNetworkOrderInPlace; }; #undef MOZ_NATIVE_ENDIANNESS diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/EnumSet.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/EnumSet.h index 95c5608cf4..8c78b2b442 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/EnumSet.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/EnumSet.h @@ -10,6 +10,7 @@ #define mozilla_EnumSet_h #include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" #include @@ -23,153 +24,181 @@ namespace mozilla { template class EnumSet { - public: - EnumSet() - : mBitField(0) - { } - - EnumSet(T aEnum) - : mBitField(aEnum) - { } - - EnumSet(T aEnum1, T aEnum2) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2)) - { } - - EnumSet(T aEnum1, T aEnum2, T aEnum3) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2) | - bitFor(aEnum3)) - { } - - EnumSet(T aEnum1, T aEnum2, T aEnum3, T aEnum4) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2) | - bitFor(aEnum3) | - bitFor(aEnum4)) - { } - - EnumSet(const EnumSet& aEnumSet) - : mBitField(aEnumSet.mBitField) - { } - - /** - * Add an element - */ - void operator+=(T aEnum) { - mBitField |= bitFor(aEnum); - } - - /** - * Add an element - */ - EnumSet operator+(T aEnum) const { - EnumSet result(*this); - result += aEnum; - return result; - } - - /** - * Union - */ - void operator+=(const EnumSet aEnumSet) { - mBitField |= aEnumSet.mBitField; - } - - /** - * Union - */ - EnumSet operator+(const EnumSet aEnumSet) const { - EnumSet result(*this); - result += aEnumSet; - return result; - } - - /** - * Remove an element - */ - void operator-=(T aEnum) { - mBitField &= ~(bitFor(aEnum)); - } - - /** - * Remove an element - */ - EnumSet operator-(T aEnum) const { - EnumSet result(*this); - result -= aEnum; - return result; - } - - /** - * Remove a set of elements - */ - void operator-=(const EnumSet aEnumSet) { - mBitField &= ~(aEnumSet.mBitField); - } - - /** - * Remove a set of elements - */ - EnumSet operator-(const EnumSet aEnumSet) const { - EnumSet result(*this); - result -= aEnumSet; - return result; - } - - /** - * Intersection - */ - void operator&=(const EnumSet aEnumSet) { - mBitField &= aEnumSet.mBitField; - } - - /** - * Intersection - */ - EnumSet operator&(const EnumSet aEnumSet) const { - EnumSet result(*this); - result &= aEnumSet; - return result; - } - - /** - * Equality - */ - - bool operator==(const EnumSet aEnumSet) const { - return mBitField == aEnumSet.mBitField; - } - - /** - * Test is an element is contained in the set - */ - bool contains(T aEnum) const { - return mBitField & bitFor(aEnum); - } - - /** - * Return the number of elements in the set - */ - - uint8_t size() { - uint8_t count = 0; - for (uint32_t bitField = mBitField; bitField; bitField >>= 1) { - if (bitField & 1) - count++; +public: + EnumSet() + : mBitField(0) + { } + + MOZ_IMPLICIT EnumSet(T aEnum) + : mBitField(bitFor(aEnum)) + { } + + EnumSet(T aEnum1, T aEnum2) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3, T aEnum4) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3) | + bitFor(aEnum4)) + { } + + EnumSet(const EnumSet& aEnumSet) + : mBitField(aEnumSet.mBitField) + { } + + /** + * Add an element + */ + void operator+=(T aEnum) + { + mBitField |= bitFor(aEnum); + } + + /** + * Add an element + */ + EnumSet operator+(T aEnum) const + { + EnumSet result(*this); + result += aEnum; + return result; + } + + /** + * Union + */ + void operator+=(const EnumSet aEnumSet) + { + mBitField |= aEnumSet.mBitField; + } + + /** + * Union + */ + EnumSet operator+(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result += aEnumSet; + return result; + } + + /** + * Remove an element + */ + void operator-=(T aEnum) + { + mBitField &= ~(bitFor(aEnum)); + } + + /** + * Remove an element + */ + EnumSet operator-(T aEnum) const + { + EnumSet result(*this); + result -= aEnum; + return result; + } + + /** + * Remove a set of elements + */ + void operator-=(const EnumSet aEnumSet) + { + mBitField &= ~(aEnumSet.mBitField); + } + + /** + * Remove a set of elements + */ + EnumSet operator-(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result -= aEnumSet; + return result; + } + + /** + * Intersection + */ + void operator&=(const EnumSet aEnumSet) + { + mBitField &= aEnumSet.mBitField; + } + + /** + * Intersection + */ + EnumSet operator&(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result &= aEnumSet; + return result; + } + + /** + * Equality + */ + bool operator==(const EnumSet aEnumSet) const + { + return mBitField == aEnumSet.mBitField; + } + + /** + * Test is an element is contained in the set. + */ + bool contains(T aEnum) const + { + return mBitField & bitFor(aEnum); + } + + /** + * Return the number of elements in the set. + */ + uint8_t size() + { + uint8_t count = 0; + for (uint32_t bitField = mBitField; bitField; bitField >>= 1) { + if (bitField & 1) { + count++; } - return count; } - - private: - static uint32_t bitFor(T aEnum) { - uint32_t bitNumber(aEnum); - MOZ_ASSERT(bitNumber < 32); - return 1U << bitNumber; - } - - uint32_t mBitField; + return count; + } + + bool isEmpty() const + { + return mBitField == 0; + } + + uint32_t serialize() const + { + return mBitField; + } + + void deserialize(uint32_t aValue) + { + mBitField = aValue; + } + +private: + static uint32_t bitFor(T aEnum) + { + uint32_t bitNumber = (uint32_t)aEnum; + MOZ_ASSERT(bitNumber < 32); + return 1U << bitNumber; + } + + uint32_t mBitField; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/EnumeratedArray.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/EnumeratedArray.h new file mode 100644 index 0000000000..7e8e89275f --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/EnumeratedArray.h @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* EnumeratedArray is like Array, but indexed by a typed enum. */ + +#ifndef mozilla_EnumeratedArray_h +#define mozilla_EnumeratedArray_h + +#include "mozilla/Array.h" +#include "mozilla/TypedEnum.h" + +namespace mozilla { + +/** + * EnumeratedArray is a fixed-size array container for use when an + * array is indexed by a specific enum class, as currently implemented + * by MOZ_BEGIN_ENUM_CLASS. + * + * This provides type safety by guarding at compile time against accidentally + * indexing such arrays with unrelated values. This also removes the need + * for manual casting when using a typed enum value to index arrays. + * + * Aside from the typing of indices, EnumeratedArray is similar to Array. + * + * Example: + * + * MOZ_BEGIN_ENUM_CLASS(AnimalSpecies) + * Cow, + * Sheep, + * Count + * MOZ_END_ENUM_CLASS(AnimalSpecies) + * + * EnumeratedArray headCount; + * + * headCount[AnimalSpecies::Cow] = 17; + * headCount[AnimalSpecies::Sheep] = 30; + * + */ +template +class EnumeratedArray +{ +public: + static const size_t kSize = size_t(SizeAsEnumValue); + +private: + Array mArray; + +public: + EnumeratedArray() {} + + explicit EnumeratedArray(const EnumeratedArray& aOther) + { + for (size_t i = 0; i < kSize; i++) { + mArray[i] = aOther.mArray[i]; + } + } + + ValueType& operator[](IndexType aIndex) + { + return mArray[size_t(aIndex)]; + } + + const ValueType& operator[](IndexType aIndex) const + { + return mArray[size_t(aIndex)]; + } +}; + +} // namespace mozilla + +#endif // mozilla_EnumeratedArray_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/FloatingPoint.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/FloatingPoint.h index 7d6b28b413..0ed567832b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/FloatingPoint.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/FloatingPoint.h @@ -12,6 +12,7 @@ #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/Casting.h" +#include "mozilla/MathAlgorithms.h" #include "mozilla/Types.h" #include @@ -33,211 +34,274 @@ namespace mozilla { * compiler bustage, particularly PGO-specific bustage. */ -/* - * These implementations all assume |double| is a 64-bit double format number - * type, compatible with the IEEE-754 standard. C/C++ don't require this to be - * the case. But we required this in implementations of these algorithms that - * preceded this header, so we shouldn't break anything if we continue doing so. - */ -static_assert(sizeof(double) == sizeof(uint64_t), "double must be 64 bits"); +struct FloatTypeTraits +{ + typedef uint32_t Bits; -const unsigned DoubleExponentBias = 1023; -const unsigned DoubleExponentShift = 52; + static const unsigned kExponentBias = 127; + static const unsigned kExponentShift = 23; -const uint64_t DoubleSignBit = 0x8000000000000000ULL; -const uint64_t DoubleExponentBits = 0x7ff0000000000000ULL; -const uint64_t DoubleSignificandBits = 0x000fffffffffffffULL; + static const Bits kSignBit = 0x80000000UL; + static const Bits kExponentBits = 0x7F800000UL; + static const Bits kSignificandBits = 0x007FFFFFUL; +}; + +struct DoubleTypeTraits +{ + typedef uint64_t Bits; -static_assert((DoubleSignBit & DoubleExponentBits) == 0, - "sign bit doesn't overlap exponent bits"); -static_assert((DoubleSignBit & DoubleSignificandBits) == 0, - "sign bit doesn't overlap significand bits"); -static_assert((DoubleExponentBits & DoubleSignificandBits) == 0, - "exponent bits don't overlap significand bits"); + static const unsigned kExponentBias = 1023; + static const unsigned kExponentShift = 52; -static_assert((DoubleSignBit | DoubleExponentBits | DoubleSignificandBits) == - ~uint64_t(0), - "all bits accounted for"); + static const Bits kSignBit = 0x8000000000000000ULL; + static const Bits kExponentBits = 0x7ff0000000000000ULL; + static const Bits kSignificandBits = 0x000fffffffffffffULL; +}; + +template struct SelectTrait; +template<> struct SelectTrait : public FloatTypeTraits {}; +template<> struct SelectTrait : public DoubleTypeTraits {}; /* - * Ditto for |float| that must be a 32-bit double format number type, compatible - * with the IEEE-754 standard. + * This struct contains details regarding the encoding of floating-point + * numbers that can be useful for direct bit manipulation. As of now, the + * template parameter has to be float or double. + * + * The nested typedef |Bits| is the unsigned integral type with the same size + * as T: uint32_t for float and uint64_t for double (static assertions + * double-check these assumptions). + * + * kExponentBias is the offset that is subtracted from the exponent when + * computing the value, i.e. one plus the opposite of the mininum possible + * exponent. + * kExponentShift is the shift that one needs to apply to retrieve the + * exponent component of the value. + * + * kSignBit contains a bits mask. Bit-and-ing with this mask will result in + * obtaining the sign bit. + * kExponentBits contains the mask needed for obtaining the exponent bits and + * kSignificandBits contains the mask needed for obtaining the significand + * bits. + * + * Full details of how floating point number formats are encoded are beyond + * the scope of this comment. For more information, see + * http://en.wikipedia.org/wiki/IEEE_floating_point + * http://en.wikipedia.org/wiki/Floating_point#IEEE_754:_floating_point_in_modern_computers */ -static_assert(sizeof(float) == sizeof(uint32_t), "float must be 32bits"); - -const unsigned FloatExponentBias = 127; -const unsigned FloatExponentShift = 23; +template +struct FloatingPoint : public SelectTrait +{ + typedef SelectTrait Base; + typedef typename Base::Bits Bits; -const uint32_t FloatSignBit = 0x80000000UL; -const uint32_t FloatExponentBits = 0x7F800000UL; -const uint32_t FloatSignificandBits = 0x007FFFFFUL; + static_assert((Base::kSignBit & Base::kExponentBits) == 0, + "sign bit shouldn't overlap exponent bits"); + static_assert((Base::kSignBit & Base::kSignificandBits) == 0, + "sign bit shouldn't overlap significand bits"); + static_assert((Base::kExponentBits & Base::kSignificandBits) == 0, + "exponent bits shouldn't overlap significand bits"); -static_assert((FloatSignBit & FloatExponentBits) == 0, - "sign bit doesn't overlap exponent bits"); -static_assert((FloatSignBit & FloatSignificandBits) == 0, - "sign bit doesn't overlap significand bits"); -static_assert((FloatExponentBits & FloatSignificandBits) == 0, - "exponent bits don't overlap significand bits"); + static_assert((Base::kSignBit | Base::kExponentBits | Base::kSignificandBits) == + ~Bits(0), + "all bits accounted for"); -static_assert((FloatSignBit | FloatExponentBits | FloatSignificandBits) == - ~uint32_t(0), - "all bits accounted for"); + /* + * These implementations assume float/double are 32/64-bit single/double + * format number types compatible with the IEEE-754 standard. C++ don't + * require this to be the case. But we required this in implementations of + * these algorithms that preceded this header, so we shouldn't break anything + * if we keep doing so. + */ + static_assert(sizeof(T) == sizeof(Bits), "Bits must be same size as T"); +}; /** Determines whether a double is NaN. */ +template static MOZ_ALWAYS_INLINE bool -IsNaN(double d) +IsNaN(T aValue) { /* - * A double is NaN if all exponent bits are 1 and the significand contains at - * least one non-zero bit. + * A float/double is NaN if all exponent bits are 1 and the significand + * contains at least one non-zero bit. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleExponentBits) == DoubleExponentBits && - (bits & DoubleSignificandBits) != 0; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) == Traits::kExponentBits && + (bits & Traits::kSignificandBits) != 0; } -/** Determines whether a double is +Infinity or -Infinity. */ +/** Determines whether a float/double is +Infinity or -Infinity. */ +template static MOZ_ALWAYS_INLINE bool -IsInfinite(double d) +IsInfinite(T aValue) { /* Infinities have all exponent bits set to 1 and an all-0 significand. */ - uint64_t bits = BitwiseCast(d); - return (bits & ~DoubleSignBit) == DoubleExponentBits; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & ~Traits::kSignBit) == Traits::kExponentBits; } -/** Determines whether a double is not NaN or infinite. */ +/** Determines whether a float/double is not NaN or infinite. */ +template static MOZ_ALWAYS_INLINE bool -IsFinite(double d) +IsFinite(T aValue) { /* - * NaN and Infinities are the only non-finite doubles, and both have all - * exponent bits set to 1. + * NaN and Infinities are the only non-finite floats/doubles, and both have + * all exponent bits set to 1. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleExponentBits) != DoubleExponentBits; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) != Traits::kExponentBits; } /** - * Determines whether a double is negative. It is an error to call this method - * on a double which is NaN. + * Determines whether a float/double is negative. It is an error to call this + * method on a float/double which is NaN. */ +template static MOZ_ALWAYS_INLINE bool -IsNegative(double d) +IsNegative(T aValue) { - MOZ_ASSERT(!IsNaN(d), "NaN does not have a sign"); + MOZ_ASSERT(!IsNaN(aValue), "NaN does not have a sign"); /* The sign bit is set if the double is negative. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleSignBit) != 0; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kSignBit) != 0; } -/** Determines whether a double represents -0. */ +/** Determines whether a float/double represents -0. */ +template static MOZ_ALWAYS_INLINE bool -IsNegativeZero(double d) +IsNegativeZero(T aValue) { - /* Only the sign bit is set if the double is -0. */ - uint64_t bits = BitwiseCast(d); - return bits == DoubleSignBit; + /* Only the sign bit is set if the value is -0. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return bits == Traits::kSignBit; } /** - * Returns the exponent portion of the double. + * Returns the exponent portion of the float/double. * * Zero is not special-cased, so ExponentComponent(0.0) is - * -int_fast16_t(DoubleExponentBias). + * -int_fast16_t(Traits::kExponentBias). */ +template static MOZ_ALWAYS_INLINE int_fast16_t -ExponentComponent(double d) +ExponentComponent(T aValue) { /* - * The exponent component of a double is an unsigned number, biased from its - * actual value. Subtract the bias to retrieve the actual exponent. + * The exponent component of a float/double is an unsigned number, biased + * from its actual value. Subtract the bias to retrieve the actual exponent. */ - uint64_t bits = BitwiseCast(d); - return int_fast16_t((bits & DoubleExponentBits) >> DoubleExponentShift) - - int_fast16_t(DoubleExponentBias); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return int_fast16_t((bits & Traits::kExponentBits) >> Traits::kExponentShift) - + int_fast16_t(Traits::kExponentBias); } /** Returns +Infinity. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T PositiveInfinity() { /* * Positive infinity has all exponent bits set, sign bit set to 0, and no * significand. */ - return BitwiseCast(DoubleExponentBits); + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kExponentBits); } /** Returns -Infinity. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T NegativeInfinity() { /* * Negative infinity has all exponent bits set, sign bit set to 1, and no * significand. */ - return BitwiseCast(DoubleSignBit | DoubleExponentBits); + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kSignBit | Traits::kExponentBits); } + /** Constructs a NaN value with the specified sign bit and significand bits. */ -static MOZ_ALWAYS_INLINE double -SpecificNaN(int signbit, uint64_t significand) +template +static MOZ_ALWAYS_INLINE T +SpecificNaN(int signbit, typename FloatingPoint::Bits significand) { + typedef FloatingPoint Traits; MOZ_ASSERT(signbit == 0 || signbit == 1); - MOZ_ASSERT((significand & ~DoubleSignificandBits) == 0); - MOZ_ASSERT(significand & DoubleSignificandBits); - - double d = BitwiseCast((signbit ? DoubleSignBit : 0) | - DoubleExponentBits | - significand); - MOZ_ASSERT(IsNaN(d)); - return d; + MOZ_ASSERT((significand & ~Traits::kSignificandBits) == 0); + MOZ_ASSERT(significand & Traits::kSignificandBits); + + T t = BitwiseCast((signbit ? Traits::kSignBit : 0) | + Traits::kExponentBits | + significand); + MOZ_ASSERT(IsNaN(t)); + return t; } -/** Computes the smallest non-zero positive double value. */ -static MOZ_ALWAYS_INLINE double -MinDoubleValue() +/** Computes the smallest non-zero positive float/double value. */ +template +static MOZ_ALWAYS_INLINE T +MinNumberValue() { - return BitwiseCast(uint64_t(1)); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + return BitwiseCast(Bits(1)); } /** - * If d is equal to some int32_t value, set *i to that value and return true; - * otherwise return false. + * If aValue is equal to some int32_t value, set *aInt32 to that value and + * return true; otherwise return false. * * Note that negative zero is "equal" to zero here. To test whether a value can - * be losslessly converted to int32_t and back, use DoubleIsInt32 instead. + * be losslessly converted to int32_t and back, use NumberIsInt32 instead. */ +template static MOZ_ALWAYS_INLINE bool -DoubleEqualsInt32(double d, int32_t* i) +NumberEqualsInt32(T aValue, int32_t* aInt32) { /* - * XXX Casting a double that doesn't truncate to int32_t, to int32_t, induces - * undefined behavior. We should definitely fix this (bug 744965), but as - * apparently it "works" in practice, it's not a pressing concern now. + * XXX Casting a floating-point value that doesn't truncate to int32_t, to + * int32_t, induces undefined behavior. We should definitely fix this + * (bug 744965), but as apparently it "works" in practice, it's not a + * pressing concern now. */ - return d == (*i = int32_t(d)); + return aValue == (*aInt32 = int32_t(aValue)); } /** * If d can be converted to int32_t and back to an identical double value, - * set *i to that value and return true; otherwise return false. + * set *aInt32 to that value and return true; otherwise return false. * - * The difference between this and DoubleEqualsInt32 is that this method returns + * The difference between this and NumberEqualsInt32 is that this method returns * false for negative zero. */ +template static MOZ_ALWAYS_INLINE bool -DoubleIsInt32(double d, int32_t* i) +NumberIsInt32(T aValue, int32_t* aInt32) { - return !IsNegativeZero(d) && DoubleEqualsInt32(d, i); + return !IsNegativeZero(aValue) && NumberEqualsInt32(aValue, aInt32); } /** * Computes a NaN value. Do not use this method if you depend upon a particular * NaN value being returned. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T UnspecifiedNaN() { /* @@ -246,7 +310,8 @@ UnspecifiedNaN() * this value can be represented in a 32-bit signed immediate field, allowing * it to be stored to memory in a single instruction). */ - return SpecificNaN(1, 0xfffffffffffffULL); + typedef FloatingPoint Traits; + return SpecificNaN(1, Traits::kSignificandBits); } /** @@ -254,40 +319,81 @@ UnspecifiedNaN() * any NaN value to any other NaN value. (The normal equality operators equate * -0 with +0, and they equate NaN to no other value.) */ +template static inline bool -DoublesAreIdentical(double d1, double d2) +NumbersAreIdentical(T aValue1, T aValue2) { - if (IsNaN(d1)) - return IsNaN(d2); - return BitwiseCast(d1) == BitwiseCast(d2); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + if (IsNaN(aValue1)) { + return IsNaN(aValue2); + } + return BitwiseCast(aValue1) == BitwiseCast(aValue2); } -/** Determines whether a float is NaN. */ +namespace detail { + +template +struct FuzzyEqualsEpsilon; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-5 that is exactly representable in a float. + static float value() { return 1.0f / (1 << 17); } +}; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-12 that is exactly representable in a double. + static double value() { return 1.0 / (1LL << 40); } +}; + +} // namespace detail + +/** + * Compare two floating point values for equality, modulo rounding error. That + * is, the two values are considered equal if they are both not NaN and if they + * are less than or equal to aEpsilon apart. The default value of aEpsilon is + * near 1e-5. + * + * For most scenarios you will want to use FuzzyEqualsMultiplicative instead, + * as it is more reasonable over the entire range of floating point numbers. + * This additive version should only be used if you know the range of the + * numbers you are dealing with is bounded and stays around the same order of + * magnitude. + */ +template static MOZ_ALWAYS_INLINE bool -IsFloatNaN(float f) +FuzzyEqualsAdditive(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) { - /* - * A float is NaN if all exponent bits are 1 and the significand contains at - * least one non-zero bit. - */ - uint32_t bits = BitwiseCast(f); - return (bits & FloatExponentBits) == FloatExponentBits && - (bits & FloatSignificandBits) != 0; + static_assert(IsFloatingPoint::value, "floating point type required"); + return Abs(aValue1 - aValue2) <= aEpsilon; } -/** Constructs a NaN value with the specified sign bit and significand bits. */ -static MOZ_ALWAYS_INLINE float -SpecificFloatNaN(int signbit, uint32_t significand) +/** + * Compare two floating point values for equality, allowing for rounding error + * relative to the magnitude of the values. That is, the two values are + * considered equal if they are both not NaN and they are less than or equal to + * some aEpsilon apart, where the aEpsilon is scaled by the smaller of the two + * argument values. + * + * In most cases you will want to use this rather than FuzzyEqualsAdditive, as + * this function effectively masks out differences in the bottom few bits of + * the floating point numbers being compared, regardless of what order of + * magnitude those numbers are at. + */ +template +static MOZ_ALWAYS_INLINE bool +FuzzyEqualsMultiplicative(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) { - MOZ_ASSERT(signbit == 0 || signbit == 1); - MOZ_ASSERT((significand & ~FloatSignificandBits) == 0); - MOZ_ASSERT(significand & FloatSignificandBits); - - float f = BitwiseCast((signbit ? FloatSignBit : 0) | - FloatExponentBits | - significand); - MOZ_ASSERT(IsFloatNaN(f)); - return f; + static_assert(IsFloatingPoint::value, "floating point type required"); + // can't use std::min because of bug 965340 + T smaller = Abs(aValue1) < Abs(aValue2) ? Abs(aValue1) : Abs(aValue2); + return Abs(aValue1 - aValue2) <= aEpsilon * smaller; } /** @@ -300,7 +406,7 @@ SpecificFloatNaN(int signbit, uint32_t significand) */ MOZ_WARN_UNUSED_RESULT extern MFBT_API bool -IsFloat32Representable(double x); +IsFloat32Representable(double aFloat32); } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/GuardObjects.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/GuardObjects.h index aeae7dcbc0..2cd950f314 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/GuardObjects.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/GuardObjects.h @@ -68,48 +68,49 @@ namespace detail { * For more details, and examples of using these macros, see * https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla */ -class MOZ_EXPORT GuardObjectNotifier +class GuardObjectNotifier { - private: - bool* statementDone; +private: + bool* mStatementDone; - public: - GuardObjectNotifier() : statementDone(nullptr) { } +public: + GuardObjectNotifier() : mStatementDone(nullptr) { } - ~GuardObjectNotifier() { - *statementDone = true; - } + ~GuardObjectNotifier() { *mStatementDone = true; } - void setStatementDone(bool* statementIsDone) { - statementDone = statementIsDone; - } + void setStatementDone(bool* aStatementIsDone) + { + mStatementDone = aStatementIsDone; + } }; -class MOZ_EXPORT GuardObjectNotificationReceiver +class GuardObjectNotificationReceiver { - private: - bool statementDone; - - public: - GuardObjectNotificationReceiver() : statementDone(false) { } - - ~GuardObjectNotificationReceiver() { - /* - * Assert that the guard object was not used as a temporary. (Note that - * this assert might also fire if init is not called because the guard - * object's implementation is not using the above macros correctly.) - */ - MOZ_ASSERT(statementDone); - } - - void init(const GuardObjectNotifier& constNotifier) { - /* - * constNotifier is passed as a const reference so that we can pass a - * temporary, but we really intend it as non-const. - */ - GuardObjectNotifier& notifier = const_cast(constNotifier); - notifier.setStatementDone(&statementDone); - } +private: + bool mStatementDone; + +public: + GuardObjectNotificationReceiver() : mStatementDone(false) { } + + ~GuardObjectNotificationReceiver() { + /* + * Assert that the guard object was not used as a temporary. (Note that + * this assert might also fire if init is not called because the guard + * object's implementation is not using the above macros correctly.) + */ + MOZ_ASSERT(mStatementDone); + } + + void init(const GuardObjectNotifier& aConstNotifier) + { + /* + * aConstNotifier is passed as a const reference so that we can pass a + * temporary, but we really intend it as non-const. + */ + GuardObjectNotifier& notifier = + const_cast(aConstNotifier); + notifier.setStatementDone(&mStatementDone); + } }; } /* namespace detail */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/HashFunctions.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/HashFunctions.h index b228955ce5..8b2c172bd1 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/HashFunctions.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/HashFunctions.h @@ -27,16 +27,17 @@ * * class ComplexObject * { - * char* str; - * uint32_t uint1, uint2; - * void (*callbackFn)(); + * char* mStr; + * uint32_t mUint1, mUint2; + * void (*mCallbackFn)(); * - * public: - * uint32_t hash() { - * uint32_t hash = HashString(str); - * hash = AddToHash(hash, uint1, uint2); - * return AddToHash(hash, callbackFn); - * } + * public: + * uint32_t hash() + * { + * uint32_t hash = HashString(mStr); + * hash = AddToHash(hash, mUint1, mUint2); + * return AddToHash(hash, mCallbackFn); + * } * }; * * If you want to hash an nsAString or nsACString, use the HashString functions @@ -59,19 +60,19 @@ namespace mozilla { /** * The golden ratio as a 32-bit fixed-point value. */ -static const uint32_t GoldenRatioU32 = 0x9E3779B9U; +static const uint32_t kGoldenRatioU32 = 0x9E3779B9U; inline uint32_t -RotateBitsLeft32(uint32_t value, uint8_t bits) +RotateBitsLeft32(uint32_t aValue, uint8_t aBits) { - MOZ_ASSERT(bits < 32); - return (value << bits) | (value >> (32 - bits)); + MOZ_ASSERT(aBits < 32); + return (aValue << aBits) | (aValue >> (32 - aBits)); } namespace detail { inline uint32_t -AddU32ToHash(uint32_t hash, uint32_t value) +AddU32ToHash(uint32_t aHash, uint32_t aValue) { /* * This is the meat of all our hash routines. This hash function is not @@ -91,12 +92,12 @@ AddU32ToHash(uint32_t hash, uint32_t value) * preferable so our hash explores the whole universe of possible rotations. * * Finally, we multiply by the golden ratio *after* xor'ing, not before. - * Otherwise, if |hash| is 0 (as it often is for the beginning of a message), - * the expression + * Otherwise, if |aHash| is 0 (as it often is for the beginning of a + * message), the expression * - * (GoldenRatioU32 * RotateBitsLeft(hash, 5)) |xor| value + * (kGoldenRatioU32 * RotateBitsLeft(aHash, 5)) |xor| aValue * - * evaluates to |value|. + * evaluates to |aValue|. * * (Number-theoretic aside: Because any odd number |m| is relatively prime to * our modulus (2^32), the list @@ -112,7 +113,7 @@ AddU32ToHash(uint32_t hash, uint32_t value) * multiplicative effect. Our golden ratio constant has order 2^29, which is * more than enough for our purposes.) */ - return GoldenRatioU32 * (RotateBitsLeft32(hash, 5) ^ value); + return kGoldenRatioU32 * (RotateBitsLeft32(aHash, 5) ^ aValue); } /** @@ -120,29 +121,29 @@ AddU32ToHash(uint32_t hash, uint32_t value) */ template inline uint32_t -AddUintptrToHash(uint32_t hash, uintptr_t value); +AddUintptrToHash(uint32_t aHash, uintptr_t aValue); template<> inline uint32_t -AddUintptrToHash<4>(uint32_t hash, uintptr_t value) +AddUintptrToHash<4>(uint32_t aHash, uintptr_t aValue) { - return AddU32ToHash(hash, static_cast(value)); + return AddU32ToHash(aHash, static_cast(aValue)); } template<> inline uint32_t -AddUintptrToHash<8>(uint32_t hash, uintptr_t value) +AddUintptrToHash<8>(uint32_t aHash, uintptr_t aValue) { /* * The static cast to uint64_t below is necessary because this function * sometimes gets compiled on 32-bit platforms (yes, even though it's a * template and we never call this particular override in a 32-bit build). If - * we do value >> 32 on a 32-bit machine, we're shifting a 32-bit uintptr_t + * we do aValue >> 32 on a 32-bit machine, we're shifting a 32-bit uintptr_t * right 32 bits, and the compiler throws an error. */ - uint32_t v1 = static_cast(value); - uint32_t v2 = static_cast(static_cast(value) >> 32); - return AddU32ToHash(AddU32ToHash(hash, v1), v2); + uint32_t v1 = static_cast(aValue); + uint32_t v2 = static_cast(static_cast(aValue) >> 32); + return AddU32ToHash(AddU32ToHash(aHash, v1), v2); } } /* namespace detail */ @@ -155,71 +156,63 @@ AddUintptrToHash<8>(uint32_t hash, uintptr_t value) * convert to uint32_t, data pointers, and function pointers. */ template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, A a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A aA) { /* * Try to convert |A| to uint32_t implicitly. If this works, great. If not, * we'll error out. */ - return detail::AddU32ToHash(hash, a); + return detail::AddU32ToHash(aHash, aA); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, A* a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A* aA) { /* * You might think this function should just take a void*. But then we'd only * catch data pointers and couldn't handle function pointers. */ - static_assert(sizeof(a) == sizeof(uintptr_t), - "Strange pointer!"); + static_assert(sizeof(aA) == sizeof(uintptr_t), "Strange pointer!"); - return detail::AddUintptrToHash(hash, uintptr_t(a)); + return detail::AddUintptrToHash(aHash, uintptr_t(aA)); } template<> -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, uintptr_t a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, uintptr_t aA) { - return detail::AddUintptrToHash(hash, a); + return detail::AddUintptrToHash(aHash, aA); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB) { - return AddToHash(AddToHash(hash, a), b); + return AddToHash(AddToHash(aHash, aA), aB); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC) { - return AddToHash(AddToHash(hash, a, b), c); + return AddToHash(AddToHash(aHash, aA, aB), aC); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c, D d) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD) { - return AddToHash(AddToHash(hash, a, b, c), d); + return AddToHash(AddToHash(aHash, aA, aB, aC), aD); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c, D d, E e) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD, E aE) { - return AddToHash(AddToHash(hash, a, b, c, d), e); + return AddToHash(AddToHash(aHash, aA, aB, aC, aD), aE); } /** @@ -230,64 +223,61 @@ AddToHash(uint32_t hash, A a, B b, C c, D d, E e) * that x has already been hashed. */ template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA) { - return AddToHash(0, a); + return AddToHash(0, aA); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB) { - return AddToHash(0, a, b); + return AddToHash(0, aA, aB); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC) { - return AddToHash(0, a, b, c); + return AddToHash(0, aA, aB, aC); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c, D d) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD) { - return AddToHash(0, a, b, c, d); + return AddToHash(0, aA, aB, aC, aD); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c, D d, E e) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD, E aE) { - return AddToHash(0, a, b, c, d, e); + return AddToHash(0, aA, aB, aC, aD, aE); } namespace detail { template uint32_t -HashUntilZero(const T* str) +HashUntilZero(const T* aStr) { uint32_t hash = 0; - for (T c; (c = *str); str++) + for (T c; (c = *aStr); aStr++) { hash = AddToHash(hash, c); + } return hash; } template uint32_t -HashKnownLength(const T* str, size_t length) +HashKnownLength(const T* aStr, size_t aLength) { uint32_t hash = 0; - for (size_t i = 0; i < length; i++) - hash = AddToHash(hash, str[i]); + for (size_t i = 0; i < aLength; i++) { + hash = AddToHash(hash, aStr[i]); + } return hash; } @@ -299,67 +289,66 @@ HashKnownLength(const T* str, size_t length) * If you have the string's length, you might as well call the overload which * includes the length. It may be marginally faster. */ -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } MOZ_WARN_UNUSED_RESULT inline uint32_t -HashString(const uint16_t* str) +HashString(const unsigned char* aStr, size_t aLength) { - return detail::HashUntilZero(str); + return detail::HashKnownLength(aStr, aLength); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const uint16_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr) { - return detail::HashKnownLength(str, length); + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); } #ifdef MOZ_CHAR16_IS_NOT_WCHAR -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char16_t* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char16_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } #endif /* - * On Windows, wchar_t (PRUnichar) is not the same as uint16_t, even though it's + * On Windows, wchar_t (char16_t) is not the same as uint16_t, even though it's * the same width! */ #ifdef WIN32 -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const wchar_t* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const wchar_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } #endif @@ -369,9 +358,8 @@ HashString(const wchar_t* str, size_t length) * This hash walks word-by-word, rather than byte-by-byte, so you won't get the * same result out of HashBytes as you would out of HashString. */ -MOZ_WARN_UNUSED_RESULT -extern MFBT_API uint32_t -HashBytes(const void* bytes, size_t length); +MOZ_WARN_UNUSED_RESULT extern MFBT_API uint32_t +HashBytes(const void* bytes, size_t aLength); } /* namespace mozilla */ #endif /* __cplusplus */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/IntegerPrintfMacros.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/IntegerPrintfMacros.h index 1ae60d618e..ff2415a86f 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/IntegerPrintfMacros.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/IntegerPrintfMacros.h @@ -1,7 +1,8 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* Implements the C99 interface, minus the SCN* format macros. */ @@ -37,4 +38,25 @@ # include #endif +/* + * Fix up Android's broken [u]intptr_t inttype macros. Android's PRI*PTR + * macros are defined as "ld", but sizeof(long) is 8 and sizeof(intptr_t) + * is 4 on 32-bit Android. TestTypeTraits.cpp asserts that these new macro + * definitions match the actual type sizes seen at compile time. + */ +#if defined(ANDROID) && !defined(__LP64__) +# undef PRIdPTR /* intptr_t */ +# define PRIdPTR "d" /* intptr_t */ +# undef PRIiPTR /* intptr_t */ +# define PRIiPTR "i" /* intptr_t */ +# undef PRIoPTR /* uintptr_t */ +# define PRIoPTR "o" /* uintptr_t */ +# undef PRIuPTR /* uintptr_t */ +# define PRIuPTR "u" /* uintptr_t */ +# undef PRIxPTR /* uintptr_t */ +# define PRIxPTR "x" /* uintptr_t */ +# undef PRIXPTR /* uintptr_t */ +# define PRIXPTR "X" /* uintptr_t */ +#endif + #endif /* mozilla_IntegerPrintfMacros_h_ */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/IntegerTypeTraits.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/IntegerTypeTraits.h new file mode 100644 index 0000000000..9414451f91 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/IntegerTypeTraits.h @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Helpers to manipulate integer types that don't fit in TypeTraits.h */ + +#ifndef mozilla_IntegerTypeTraits_h +#define mozilla_IntegerTypeTraits_h + +#include "mozilla/TypeTraits.h" +#include + +namespace mozilla { + +namespace detail { + +/** + * StdintTypeForSizeAndSignedness returns the stdint integer type + * of given size (can be 1, 2, 4 or 8) and given signedness + * (false means unsigned, true means signed). + */ +template +struct StdintTypeForSizeAndSignedness; + +template<> +struct StdintTypeForSizeAndSignedness<1, true> +{ + typedef int8_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<1, false> +{ + typedef uint8_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<2, true> +{ + typedef int16_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<2, false> +{ + typedef uint16_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<4, true> +{ + typedef int32_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<4, false> +{ + typedef uint32_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<8, true> +{ + typedef int64_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<8, false> +{ + typedef uint64_t Type; +}; + +} // namespace detail + +template +struct UnsignedStdintTypeForSize + : detail::StdintTypeForSizeAndSignedness +{}; + +template +struct PositionOfSignBit +{ + static_assert(IsIntegral::value, + "PositionOfSignBit is only for integral types"); + // 8 here should be CHAR_BIT from limits.h, but the world has moved on. + static const size_t value = 8 * sizeof(IntegerType) - 1; +}; + +/** + * MinValue returns the minimum value of the given integer type as a + * compile-time constant, which std::numeric_limits::min() + * cannot do in c++98. + */ +template +struct MinValue +{ +private: + static_assert(IsIntegral::value, + "MinValue is only for integral types"); + + typedef typename MakeUnsigned::Type UnsignedIntegerType; + static const size_t PosOfSignBit = PositionOfSignBit::value; + +public: + // Bitwise ops may return a larger type, that's why we cast explicitly. + // In C++, left bit shifts on signed values is undefined by the standard + // unless the shifted value is representable. + // Notice that signed-to-unsigned conversions are always well-defined in + // the standard as the value congruent to 2**n, as expected. By contrast, + // unsigned-to-signed is only well-defined if the value is representable. + static const IntegerType value = + IsSigned::value + ? IntegerType(UnsignedIntegerType(1) << PosOfSignBit) + : IntegerType(0); +}; + +/** + * MaxValue returns the maximum value of the given integer type as a + * compile-time constant, which std::numeric_limits::max() + * cannot do in c++98. + */ +template +struct MaxValue +{ + static_assert(IsIntegral::value, + "MaxValue is only for integral types"); + + // Tricksy, but covered by the CheckedInt unit test. + // Relies on the type of MinValue::value + // being IntegerType. + static const IntegerType value = ~MinValue::value; +}; + +} // namespace mozilla + +#endif // mozilla_IntegerTypeTraits_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/LinkedList.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/LinkedList.h index 3aee7cde45..693c019f92 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/LinkedList.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/LinkedList.h @@ -23,32 +23,36 @@ * * class Observer : public LinkedListElement * { - * public: - * void observe(char* topic) { ... } + * public: + * void observe(char* aTopic) { ... } * }; * * class ObserverContainer * { - * private: - * LinkedList list; + * private: + * LinkedList list; * - * public: - * void addObserver(Observer* observer) { - * // Will assert if |observer| is part of another list. - * list.insertBack(observer); - * } + * public: + * void addObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is part of another list. + * list.insertBack(aObserver); + * } * - * void removeObserver(Observer* observer) { - * // Will assert if |observer| is not part of some list. - * observer.remove(); - * // Or, will assert if |observer| is not part of |list| specifically. - * // observer.removeFrom(list); - * } + * void removeObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is not part of some list. + * aObserver.remove(); + * // Or, will assert if |aObserver| is not part of |list| specifically. + * // aObserver.removeFrom(list); + * } * - * void notifyObservers(char* topic) { - * for (Observer* o = list.getFirst(); o != nullptr; o = o->getNext()) - * o->observe(topic); + * void notifyObservers(char* aTopic) + * { + * for (Observer* o = list.getFirst(); o != nullptr; o = o->getNext()) { + * o->observe(aTopic); * } + * } * }; * */ @@ -72,411 +76,407 @@ class LinkedList; template class LinkedListElement { - /* - * It's convenient that we return nullptr when getNext() or getPrevious() - * hits the end of the list, but doing so costs an extra word of storage in - * each linked list node (to keep track of whether |this| is the sentinel - * node) and a branch on this value in getNext/getPrevious. - * - * We could get rid of the extra word of storage by shoving the "is - * sentinel" bit into one of the pointers, although this would, of course, - * have performance implications of its own. - * - * But the goal here isn't to win an award for the fastest or slimmest - * linked list; rather, we want a *convenient* linked list. So we won't - * waste time guessing which micro-optimization strategy is best. - * - * - * Speaking of unnecessary work, it's worth addressing here why we wrote - * mozilla::LinkedList in the first place, instead of using stl::list. - * - * The key difference between mozilla::LinkedList and stl::list is that - * mozilla::LinkedList stores the prev/next pointers in the object itself, - * while stl::list stores the prev/next pointers in a list element which - * itself points to the object being stored. - * - * mozilla::LinkedList's approach makes it harder to store an object in more - * than one list. But the upside is that you can call next() / prev() / - * remove() directly on the object. With stl::list, you'd need to store a - * pointer to its iterator in the object in order to accomplish this. Not - * only would this waste space, but you'd have to remember to update that - * pointer every time you added or removed the object from a list. - * - * In-place, constant-time removal is a killer feature of doubly-linked - * lists, and supporting this painlessly was a key design criterion. - */ - - private: - LinkedListElement* next; - LinkedListElement* prev; - const bool isSentinel; - - public: - LinkedListElement() - : next(MOZ_THIS_IN_INITIALIZER_LIST()), - prev(MOZ_THIS_IN_INITIALIZER_LIST()), - isSentinel(false) - { } - - LinkedListElement(LinkedListElement&& other) - : isSentinel(other.isSentinel) - { - if (!other.isInList()) { - next = this; - prev = this; - return; - } - - MOZ_ASSERT(other.next->prev == &other); - MOZ_ASSERT(other.prev->next == &other); - - /* - * Initialize |this| with |other|'s prev/next pointers, and adjust those - * element to point to this one. - */ - next = other.next; - prev = other.prev; - - next->prev = this; - prev->next = this; - - /* - * Adjust |other| so it doesn't think it's in a list. This makes it - * safely destructable. - */ - other.next = &other; - other.prev = &other; - } - - ~LinkedListElement() { - if (!isSentinel && isInList()) - remove(); - } - - /* - * Get the next element in the list, or nullptr if this is the last element - * in the list. - */ - T* getNext() { - return next->asT(); - } - const T* getNext() const { - return next->asT(); + /* + * It's convenient that we return nullptr when getNext() or getPrevious() + * hits the end of the list, but doing so costs an extra word of storage in + * each linked list node (to keep track of whether |this| is the sentinel + * node) and a branch on this value in getNext/getPrevious. + * + * We could get rid of the extra word of storage by shoving the "is + * sentinel" bit into one of the pointers, although this would, of course, + * have performance implications of its own. + * + * But the goal here isn't to win an award for the fastest or slimmest + * linked list; rather, we want a *convenient* linked list. So we won't + * waste time guessing which micro-optimization strategy is best. + * + * + * Speaking of unnecessary work, it's worth addressing here why we wrote + * mozilla::LinkedList in the first place, instead of using stl::list. + * + * The key difference between mozilla::LinkedList and stl::list is that + * mozilla::LinkedList stores the mPrev/mNext pointers in the object itself, + * while stl::list stores the mPrev/mNext pointers in a list element which + * itself points to the object being stored. + * + * mozilla::LinkedList's approach makes it harder to store an object in more + * than one list. But the upside is that you can call next() / prev() / + * remove() directly on the object. With stl::list, you'd need to store a + * pointer to its iterator in the object in order to accomplish this. Not + * only would this waste space, but you'd have to remember to update that + * pointer every time you added or removed the object from a list. + * + * In-place, constant-time removal is a killer feature of doubly-linked + * lists, and supporting this painlessly was a key design criterion. + */ + +private: + LinkedListElement* mNext; + LinkedListElement* mPrev; + const bool mIsSentinel; + +public: + LinkedListElement() + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(false) + { } + + LinkedListElement(LinkedListElement&& other) + : mIsSentinel(other.mIsSentinel) + { + if (!other.isInList()) { + mNext = this; + mPrev = this; + return; } - /* - * Get the previous element in the list, or nullptr if this is the first - * element in the list. - */ - T* getPrevious() { - return prev->asT(); - } - const T* getPrevious() const { - return prev->asT(); - } + MOZ_ASSERT(other.mNext->mPrev == &other); + MOZ_ASSERT(other.mPrev->mNext == &other); /* - * Insert elem after this element in the list. |this| must be part of a - * linked list when you call setNext(); otherwise, this method will assert. + * Initialize |this| with |other|'s mPrev/mNext pointers, and adjust those + * element to point to this one. */ - void setNext(T* elem) { - MOZ_ASSERT(isInList()); - setNextUnsafe(elem); - } + mNext = other.mNext; + mPrev = other.mPrev; - /* - * Insert elem before this element in the list. |this| must be part of a - * linked list when you call setPrevious(); otherwise, this method will - * assert. - */ - void setPrevious(T* elem) { - MOZ_ASSERT(isInList()); - setPreviousUnsafe(elem); - } + mNext->mPrev = this; + mPrev->mNext = this; /* - * Remove this element from the list which contains it. If this element is - * not currently part of a linked list, this method asserts. + * Adjust |other| so it doesn't think it's in a list. This makes it + * safely destructable. */ - void remove() { - MOZ_ASSERT(isInList()); - - prev->next = next; - next->prev = prev; - next = this; - prev = this; - } + other.mNext = &other; + other.mPrev = &other; + } - /* - * Identical to remove(), but also asserts in debug builds that this element - * is in list. - */ - void removeFrom(const LinkedList& list) { - list.assertContains(asT()); + ~LinkedListElement() + { + if (!mIsSentinel && isInList()) { remove(); } - - /* - * Return true if |this| part is of a linked list, and false otherwise. - */ - bool isInList() const { - MOZ_ASSERT((next == this) == (prev == this)); - return next != this; - } - - private: - friend class LinkedList; - - enum NodeKind { - NODE_KIND_NORMAL, - NODE_KIND_SENTINEL - }; - - LinkedListElement(NodeKind nodeKind) - : next(MOZ_THIS_IN_INITIALIZER_LIST()), - prev(MOZ_THIS_IN_INITIALIZER_LIST()), - isSentinel(nodeKind == NODE_KIND_SENTINEL) - { } - - /* - * Return |this| cast to T* if we're a normal node, or return nullptr if - * we're a sentinel node. - */ - T* asT() { - if (isSentinel) - return nullptr; - - return static_cast(this); - } - const T* asT() const { - if (isSentinel) - return nullptr; - - return static_cast(this); - } - - /* - * Insert elem after this element, but don't check that this element is in - * the list. This is called by LinkedList::insertFront(). - */ - void setNextUnsafe(T* elem) { - LinkedListElement *listElem = static_cast(elem); - MOZ_ASSERT(!listElem->isInList()); - - listElem->next = this->next; - listElem->prev = this; - this->next->prev = listElem; - this->next = listElem; - } - - /* - * Insert elem before this element, but don't check that this element is in - * the list. This is called by LinkedList::insertBack(). - */ - void setPreviousUnsafe(T* elem) { - LinkedListElement* listElem = static_cast*>(elem); - MOZ_ASSERT(!listElem->isInList()); - - listElem->next = this; - listElem->prev = this->prev; - this->prev->next = listElem; - this->prev = listElem; - } - - private: - LinkedListElement& operator=(const LinkedListElement& other) MOZ_DELETE; - LinkedListElement(const LinkedListElement& other) MOZ_DELETE; + } + + /* + * Get the next element in the list, or nullptr if this is the last element + * in the list. + */ + T* getNext() { return mNext->asT(); } + const T* getNext() const { return mNext->asT(); } + + /* + * Get the previous element in the list, or nullptr if this is the first + * element in the list. + */ + T* getPrevious() { return mPrev->asT(); } + const T* getPrevious() const { return mPrev->asT(); } + + /* + * Insert aElem after this element in the list. |this| must be part of a + * linked list when you call setNext(); otherwise, this method will assert. + */ + void setNext(T* aElem) + { + MOZ_ASSERT(isInList()); + setNextUnsafe(aElem); + } + + /* + * Insert aElem before this element in the list. |this| must be part of a + * linked list when you call setPrevious(); otherwise, this method will + * assert. + */ + void setPrevious(T* aElem) + { + MOZ_ASSERT(isInList()); + setPreviousUnsafe(aElem); + } + + /* + * Remove this element from the list which contains it. If this element is + * not currently part of a linked list, this method asserts. + */ + void remove() + { + MOZ_ASSERT(isInList()); + + mPrev->mNext = mNext; + mNext->mPrev = mPrev; + mNext = this; + mPrev = this; + } + + /* + * Identical to remove(), but also asserts in debug builds that this element + * is in aList. + */ + void removeFrom(const LinkedList& aList) + { + aList.assertContains(asT()); + remove(); + } + + /* + * Return true if |this| part is of a linked list, and false otherwise. + */ + bool isInList() const + { + MOZ_ASSERT((mNext == this) == (mPrev == this)); + return mNext != this; + } + +private: + friend class LinkedList; + + enum NodeKind { + NODE_KIND_NORMAL, + NODE_KIND_SENTINEL + }; + + explicit LinkedListElement(NodeKind nodeKind) + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(nodeKind == NODE_KIND_SENTINEL) + { } + + /* + * Return |this| cast to T* if we're a normal node, or return nullptr if + * we're a sentinel node. + */ + T* asT() + { + return mIsSentinel ? nullptr : static_cast(this); + } + const T* asT() const + { + return mIsSentinel ? nullptr : static_cast(this); + } + + /* + * Insert aElem after this element, but don't check that this element is in + * the list. This is called by LinkedList::insertFront(). + */ + void setNextUnsafe(T* aElem) + { + LinkedListElement *listElem = static_cast(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this->mNext; + listElem->mPrev = this; + this->mNext->mPrev = listElem; + this->mNext = listElem; + } + + /* + * Insert aElem before this element, but don't check that this element is in + * the list. This is called by LinkedList::insertBack(). + */ + void setPreviousUnsafe(T* aElem) + { + LinkedListElement* listElem = static_cast*>(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this; + listElem->mPrev = this->mPrev; + this->mPrev->mNext = listElem; + this->mPrev = listElem; + } + +private: + LinkedListElement& operator=(const LinkedListElement& aOther) MOZ_DELETE; + LinkedListElement(const LinkedListElement& aOther) MOZ_DELETE; }; template class LinkedList { - private: - LinkedListElement sentinel; - - public: - LinkedList() : sentinel(LinkedListElement::NODE_KIND_SENTINEL) { } - - LinkedList(LinkedList&& other) - : sentinel(mozilla::Move(other.sentinel)) - { } - - ~LinkedList() { - MOZ_ASSERT(isEmpty()); - } - - /* - * Add elem to the front of the list. - */ - void insertFront(T* elem) { - /* Bypass setNext()'s this->isInList() assertion. */ - sentinel.setNextUnsafe(elem); - } - - /* - * Add elem to the back of the list. - */ - void insertBack(T* elem) { - sentinel.setPreviousUnsafe(elem); - } - - /* - * Get the first element of the list, or nullptr if the list is empty. - */ - T* getFirst() { - return sentinel.getNext(); - } - const T* getFirst() const { - return sentinel.getNext(); +private: + LinkedListElement sentinel; + +public: + LinkedList() : sentinel(LinkedListElement::NODE_KIND_SENTINEL) { } + + LinkedList(LinkedList&& aOther) + : sentinel(mozilla::Move(aOther.sentinel)) + { } + + ~LinkedList() { MOZ_ASSERT(isEmpty()); } + + /* + * Add aElem to the front of the list. + */ + void insertFront(T* aElem) + { + /* Bypass setNext()'s this->isInList() assertion. */ + sentinel.setNextUnsafe(aElem); + } + + /* + * Add aElem to the back of the list. + */ + void insertBack(T* aElem) + { + sentinel.setPreviousUnsafe(aElem); + } + + /* + * Get the first element of the list, or nullptr if the list is empty. + */ + T* getFirst() { return sentinel.getNext(); } + const T* getFirst() const { return sentinel.getNext(); } + + /* + * Get the last element of the list, or nullptr if the list is empty. + */ + T* getLast() { return sentinel.getPrevious(); } + const T* getLast() const { return sentinel.getPrevious(); } + + /* + * Get and remove the first element of the list. If the list is empty, + * return nullptr. + */ + T* popFirst() + { + T* ret = sentinel.getNext(); + if (ret) { + static_cast*>(ret)->remove(); } - - /* - * Get the last element of the list, or nullptr if the list is empty. - */ - T* getLast() { - return sentinel.getPrevious(); - } - const T* getLast() const { - return sentinel.getPrevious(); - } - - /* - * Get and remove the first element of the list. If the list is empty, - * return nullptr. - */ - T* popFirst() { - T* ret = sentinel.getNext(); - if (ret) - static_cast*>(ret)->remove(); - return ret; + return ret; + } + + /* + * Get and remove the last element of the list. If the list is empty, + * return nullptr. + */ + T* popLast() + { + T* ret = sentinel.getPrevious(); + if (ret) { + static_cast*>(ret)->remove(); } - - /* - * Get and remove the last element of the list. If the list is empty, - * return nullptr. - */ - T* popLast() { - T* ret = sentinel.getPrevious(); - if (ret) - static_cast*>(ret)->remove(); - return ret; + return ret; + } + + /* + * Return true if the list is empty, or false otherwise. + */ + bool isEmpty() const + { + return !sentinel.isInList(); + } + + /* + * Remove all the elements from the list. + * + * This runs in time linear to the list's length, because we have to mark + * each element as not in the list. + */ + void clear() + { + while (popFirst()) { + continue; } - - /* - * Return true if the list is empty, or false otherwise. - */ - bool isEmpty() const { - return !sentinel.isInList(); + } + + /* + * Measures the memory consumption of the list excluding |this|. Note that + * it only measures the list elements themselves. If the list elements + * contain pointers to other memory blocks, those blocks must be measured + * separately during a subsequent iteration over the list. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const + { + size_t n = 0; + for (const T* t = getFirst(); t; t = t->getNext()) { + n += aMallocSizeOf(t); } + return n; + } + + /* + * Like sizeOfExcludingThis(), but measures |this| as well. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const + { + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); + } + + /* + * In a debug build, make sure that the list is sane (no cycles, consistent + * mNext/mPrev pointers, only one sentinel). Has no effect in release builds. + */ + void debugAssertIsSane() const + { +#ifdef DEBUG + const LinkedListElement* slow; + const LinkedListElement* fast1; + const LinkedListElement* fast2; /* - * Remove all the elements from the list. - * - * This runs in time linear to the list's length, because we have to mark - * each element as not in the list. + * Check for cycles in the forward singly-linked list using the + * tortoise/hare algorithm. */ - void clear() { - while (popFirst()) - continue; + for (slow = sentinel.mNext, + fast1 = sentinel.mNext->mNext, + fast2 = sentinel.mNext->mNext->mNext; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mNext, fast1 = fast2->mNext, fast2 = fast1->mNext) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); } - /* - * Measures the memory consumption of the list excluding |this|. Note that - * it only measures the list elements themselves. If the list elements - * contain pointers to other memory blocks, those blocks must be measured - * separately during a subsequent iteration over the list. - */ - size_t sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const { - size_t n = 0; - for (const T* t = getFirst(); t; t = t->getNext()) - n += mallocSizeOf(t); - return n; + /* Check for cycles in the backward singly-linked list. */ + for (slow = sentinel.mPrev, + fast1 = sentinel.mPrev->mPrev, + fast2 = sentinel.mPrev->mPrev->mPrev; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mPrev, fast1 = fast2->mPrev, fast2 = fast1->mPrev) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); } /* - * Like sizeOfExcludingThis(), but measures |this| as well. + * Check that |sentinel| is the only node in the list with + * mIsSentinel == true. */ - size_t sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const { - return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + for (const LinkedListElement* elem = sentinel.mNext; + elem != &sentinel; + elem = elem->mNext) { + MOZ_ASSERT(!elem->mIsSentinel); } - /* - * In a debug build, make sure that the list is sane (no cycles, consistent - * next/prev pointers, only one sentinel). Has no effect in release builds. - */ - void debugAssertIsSane() const { -#ifdef DEBUG - const LinkedListElement* slow; - const LinkedListElement* fast1; - const LinkedListElement* fast2; - - /* - * Check for cycles in the forward singly-linked list using the - * tortoise/hare algorithm. - */ - for (slow = sentinel.next, - fast1 = sentinel.next->next, - fast2 = sentinel.next->next->next; - slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; - slow = slow->next, fast1 = fast2->next, fast2 = fast1->next) - { - MOZ_ASSERT(slow != fast1); - MOZ_ASSERT(slow != fast2); - } - - /* Check for cycles in the backward singly-linked list. */ - for (slow = sentinel.prev, - fast1 = sentinel.prev->prev, - fast2 = sentinel.prev->prev->prev; - slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; - slow = slow->prev, fast1 = fast2->prev, fast2 = fast1->prev) - { - MOZ_ASSERT(slow != fast1); - MOZ_ASSERT(slow != fast2); - } - - /* - * Check that |sentinel| is the only node in the list with - * isSentinel == true. - */ - for (const LinkedListElement* elem = sentinel.next; - elem != &sentinel; - elem = elem->next) - { - MOZ_ASSERT(!elem->isSentinel); - } - - /* Check that the next/prev pointers match up. */ - const LinkedListElement* prev = &sentinel; - const LinkedListElement* cur = sentinel.next; - do { - MOZ_ASSERT(cur->prev == prev); - MOZ_ASSERT(prev->next == cur); + /* Check that the mNext/mPrev pointers match up. */ + const LinkedListElement* prev = &sentinel; + const LinkedListElement* cur = sentinel.mNext; + do { + MOZ_ASSERT(cur->mPrev == prev); + MOZ_ASSERT(prev->mNext == cur); - prev = cur; - cur = cur->next; - } while (cur != &sentinel); + prev = cur; + cur = cur->mNext; + } while (cur != &sentinel); #endif /* ifdef DEBUG */ - } + } - private: - friend class LinkedListElement; +private: + friend class LinkedListElement; - void assertContains(const T* t) const { + void assertContains(const T* aValue) const + { #ifdef DEBUG - for (const T* elem = getFirst(); - elem; - elem = elem->getNext()) - { - if (elem == t) - return; + for (const T* elem = getFirst(); elem; elem = elem->getNext()) { + if (elem == aValue) { + return; } - MOZ_CRASH("element wasn't found in this list!"); -#endif } + MOZ_CRASH("element wasn't found in this list!"); +#endif + } - LinkedList& operator=(const LinkedList& other) MOZ_DELETE; - LinkedList(const LinkedList& other) MOZ_DELETE; + LinkedList& operator=(const LinkedList& aOther) MOZ_DELETE; + LinkedList(const LinkedList& aOther) MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MSIntTypes.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MSIntTypes.h index 3dfba55f58..4ce922fbc5 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MSIntTypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MSIntTypes.h @@ -1,32 +1,32 @@ // ISO C9x compliant inttypes.h for Microsoft Visual Studio -// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 -// +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// // Copyright (c) 2006 Alexander Chemeris -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: -// +// // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. -// +// // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. -// +// // 3. The name of the author may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// +// /////////////////////////////////////////////////////////////////////////////// #ifndef _MSC_VER // [ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MacroArgs.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MacroArgs.h new file mode 100644 index 0000000000..c8b7338210 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MacroArgs.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements various macros meant to ease the use of variadic macros. + */ + +#ifndef mozilla_MacroArgs_h +#define mozilla_MacroArgs_h + +/* + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) counts the number of variadic + * arguments and prefixes it with |aPrefix|. For example: + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(, foo, 42) expands to 2 + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(A, foo, 42, bar) expands to A3 + * + * You must pass in between 1 and 50 (inclusive) variadic arguments, past + * |aPrefix|. It is not legal to do + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(prefix) + * + * (that is, pass in 0 variadic arguments). To ensure that a compile-time + * error occurs when these constraints are violated, use the + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT macro with the same variaidc arguments + * wherever this macro is used. + * + * Passing (__VA_ARGS__, ) rather than simply calling + * MOZ_MACROARGS_ARG_COUNT_HELPER2(__VA_ARGS__, ) very + * carefully tiptoes around a MSVC bug where it improperly expands __VA_ARGS__ + * as a single token in argument lists. For details, see: + * + * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement + * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 + */ +#define MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) \ + MOZ_MACROARGS_ARG_COUNT_HELPER((__VA_ARGS__, \ + aPrefix##50, aPrefix##49, aPrefix##48, aPrefix##47, aPrefix##46, \ + aPrefix##45, aPrefix##44, aPrefix##43, aPrefix##42, aPrefix##41, \ + aPrefix##40, aPrefix##39, aPrefix##38, aPrefix##37, aPrefix##36, \ + aPrefix##35, aPrefix##34, aPrefix##33, aPrefix##32, aPrefix##31, \ + aPrefix##30, aPrefix##29, aPrefix##28, aPrefix##27, aPrefix##26, \ + aPrefix##25, aPrefix##24, aPrefix##23, aPrefix##22, aPrefix##21, \ + aPrefix##20, aPrefix##19, aPrefix##18, aPrefix##17, aPrefix##16, \ + aPrefix##15, aPrefix##14, aPrefix##13, aPrefix##12, aPrefix##11, \ + aPrefix##10, aPrefix##9, aPrefix##8, aPrefix##7, aPrefix##6, \ + aPrefix##5, aPrefix##4, aPrefix##3, aPrefix##2, aPrefix##1, aPrefix##0)) + +#define MOZ_MACROARGS_ARG_COUNT_HELPER(aArgs) \ + MOZ_MACROARGS_ARG_COUNT_HELPER2 aArgs + +#define MOZ_MACROARGS_ARG_COUNT_HELPER2( \ + a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, \ + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \ + a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \ + a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \ + a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \ + a51, ...) a51 + +/* + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT ensures that a compile-time error occurs + * when the argument count constraints of MOZ_PASTE_PREFIX_AND_ARG_COUNT are + * violated. Use this macro wherever MOZ_PASTE_PREFIX_AND_ARG_COUNT is used + * and pass it the same variadic arguments. + * + * This macro employs a few dirty tricks to function. To detect the zero + * argument case, |(__VA_ARGS__)| is stringified, sizeof-ed, and compared to + * what it should be in the absence of arguments. + * + * Detecting too many arguments is a little trickier. With a valid argument + * count and a prefix of 1, MOZ_PASTE_PREFIX_AND_ARG_COUNT expands to e.g. 14. + * With a prefix of 0.0, it expands to e.g. 0.04. If there are too many + * arguments, it expands to the first argument over the limit. If this + * exceeding argument is a number, the assertion will fail as there is no + * number than can simultaneously be both > 10 and == 0. If the exceeding + * argument is not a number, a compile-time error should still occur due to + * the operations performed on it. + */ +#define MOZ_MACROARGS_STRINGIFY_HELPER(x) #x +#define MOZ_STATIC_ASSERT_VALID_ARG_COUNT(...) \ + static_assert( \ + sizeof(MOZ_MACROARGS_STRINGIFY_HELPER((__VA_ARGS__))) != sizeof("()") && \ + (MOZ_PASTE_PREFIX_AND_ARG_COUNT(1, __VA_ARGS__)) > 10 && \ + (int)(MOZ_PASTE_PREFIX_AND_ARG_COUNT(0.0, __VA_ARGS__)) == 0, \ + "MOZ_STATIC_ASSERT_VALID_ARG_COUNT requires 1 to 50 arguments") /* ; */ + +/* + * MOZ_ARGS_AFTER_N expands to its arguments excluding the first |N| + * arguments. For example: + * + * MOZ_ARGS_AFTER_2(a, b, c, d) expands to: c, d + */ +#define MOZ_ARGS_AFTER_1(a1, ...) __VA_ARGS__ +#define MOZ_ARGS_AFTER_2(a1, a2, ...) __VA_ARGS__ + +/* + * MOZ_ARG_N expands to its |N|th argument. + */ +#define MOZ_ARG_1(a1, ...) a1 +#define MOZ_ARG_2(a1, a2, ...) a2 + +#endif /* mozilla_MacroArgs_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MacroForEach.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MacroForEach.h new file mode 100644 index 0000000000..ae1f4d0e99 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MacroForEach.h @@ -0,0 +1,158 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements a higher-order macro for iteratively calling another macro with + * fixed leading arguments, plus a trailing element picked from a second list + * of arguments. + */ + +#ifndef mozilla_MacroForEach_h +#define mozilla_MacroForEach_h + +#include "mozilla/MacroArgs.h" + +/* + * MOZ_FOR_EACH(aMacro, aFixedArgs, aArgs) expands to N calls to the macro + * |aMacro| where N is equal the number of items in the list |aArgs|. The + * arguments for each |aMacro| call are composed of *all* arguments in the list + * |aFixedArgs| as well as a single argument in the list |aArgs|. For example: + * + * #define MACRO_A(x) x + + * int a = MOZ_FOR_EACH(MACRO_A, (), (1, 2, 3)) 0; + * // Expands to: MACRO_A(1) MACRO_A(2) MACRO_A(3) 0; + * // And further to: 1 + 2 + 3 + 0; + * + * #define MACRO_B(k, x) (k + x) + + * int b = MOZ_FOR_EACH(MACRO_B, (5,), (1, 2)) 0; + * // Expands to: MACRO_B(5, 1) MACRO_B(5, 2) 0; + * + * #define MACRO_C(k1, k2, x) (k1 + k2 + x) + + * int c = MOZ_FOR_EACH(MACRO_C, (5, 8,), (1, 2)) 0; + * // Expands to: MACRO_B(5, 8, 1) MACRO_B(5, 8, 2) 0; + * + * If the |aFixedArgs| list is not empty, a trailing comma must be included. + * + * The |aArgs| list must be not be empty and may be up to 50 items long. Use + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT to ensure that violating this constraint + * results in a compile-time error. + */ +#define MOZ_FOR_EACH_EXPAND_HELPER(...) __VA_ARGS__ +#define MOZ_FOR_EACH_GLUE(a, b) a b +#define MOZ_FOR_EACH(aMacro, aFixedArgs, aArgs) \ + MOZ_FOR_EACH_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_FOR_EACH_, \ + MOZ_FOR_EACH_EXPAND_HELPER aArgs), \ + (aMacro, aFixedArgs, aArgs)) + +#define MOZ_FOR_EACH_HELPER_GLUE(a, b) a b +#define MOZ_FOR_EACH_HELPER(aMacro, aFixedArgs, aArgs) \ + MOZ_FOR_EACH_HELPER_GLUE( \ + aMacro, \ + (MOZ_FOR_EACH_EXPAND_HELPER aFixedArgs MOZ_ARG_1 aArgs)) + +#define MOZ_FOR_EACH_1(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) +#define MOZ_FOR_EACH_2(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_1(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_3(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_2(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_4(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_3(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_5(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_4(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_6(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_5(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_7(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_6(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_8(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_7(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_9(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_8(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_10(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_9(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_11(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_10(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_12(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_11(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_13(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_12(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_14(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_13(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_15(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_14(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_16(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_15(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_17(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_16(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_18(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_17(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_19(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_18(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_20(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_19(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_21(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_20(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_22(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_21(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_23(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_22(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_24(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_23(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_25(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_24(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_26(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_25(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_27(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_26(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_28(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_27(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_29(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_28(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_30(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_29(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_31(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_30(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_32(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_31(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_33(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_32(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_34(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_33(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_35(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_34(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_36(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_35(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_37(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_36(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_38(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_37(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_39(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_38(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_40(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_39(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_41(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_40(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_42(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_41(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_43(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_42(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_44(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_43(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_45(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_44(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_46(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_45(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_47(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_46(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_48(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_47(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_49(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_48(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_50(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_49(m, fa, (MOZ_ARGS_AFTER_1 a)) + +#endif /* mozilla_MacroForEach_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MathAlgorithms.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MathAlgorithms.h index 7b98c7fc19..cd71d19770 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MathAlgorithms.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MathAlgorithms.h @@ -21,31 +21,31 @@ namespace mozilla { // Greatest Common Divisor template MOZ_ALWAYS_INLINE IntegerType -EuclidGCD(IntegerType a, IntegerType b) +EuclidGCD(IntegerType aA, IntegerType aB) { // Euclid's algorithm; O(N) in the worst case. (There are better // ways, but we don't need them for the current use of this algo.) - MOZ_ASSERT(a > 0); - MOZ_ASSERT(b > 0); + MOZ_ASSERT(aA > IntegerType(0)); + MOZ_ASSERT(aB > IntegerType(0)); - while (a != b) { - if (a > b) { - a = a - b; + while (aA != aB) { + if (aA > aB) { + aA = aA - aB; } else { - b = b - a; + aB = aB - aA; } } - return a; + return aA; } // Least Common Multiple template MOZ_ALWAYS_INLINE IntegerType -EuclidLCM(IntegerType a, IntegerType b) +EuclidLCM(IntegerType aA, IntegerType aB) { // Divide first to reduce overflow risk. - return (a / EuclidGCD(a, b)) * b; + return (aA / EuclidGCD(aA, aB)) * aB; } namespace detail { @@ -68,7 +68,7 @@ template<> struct AllowDeprecatedAbs : TrueType {}; // to Abs below, and it will be removed when all callers have been changed. template inline typename mozilla::EnableIf::value, T>::Type -DeprecatedAbs(const T t) +DeprecatedAbs(const T aValue) { // The absolute value of the smallest possible value of a signed-integer type // won't fit in that type (on twos-complement systems -- and we're blithely @@ -79,10 +79,10 @@ DeprecatedAbs(const T t) // value in the range [-maxvalue, 0]), then negating (giving a value in the // range [0, maxvalue]), doesn't produce maxvalue (because in twos-complement, // (minvalue + 1) == -maxvalue). - MOZ_ASSERT(t >= 0 || - -(t + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1), + MOZ_ASSERT(aValue >= 0 || + -(aValue + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1), "You can't negate the smallest possible negative integer!"); - return t >= 0 ? t : -t; + return aValue >= 0 ? aValue : -aValue; } namespace detail { @@ -102,7 +102,8 @@ template<> struct AbsReturnTypeFixed { typedef uint64_t Type; }; template struct AbsReturnType : AbsReturnTypeFixed {}; -template<> struct AbsReturnType : EnableIf {}; +template<> struct AbsReturnType : + EnableIf {}; template<> struct AbsReturnType { typedef unsigned char Type; }; template<> struct AbsReturnType { typedef unsigned short Type; }; template<> struct AbsReturnType { typedef unsigned int Type; }; @@ -116,50 +117,46 @@ template<> struct AbsReturnType { typedef long double Type; }; template inline typename detail::AbsReturnType::Type -Abs(const T t) +Abs(const T aValue) { typedef typename detail::AbsReturnType::Type ReturnType; - return t >= 0 ? ReturnType(t) : ~ReturnType(t) + 1; + return aValue >= 0 ? ReturnType(aValue) : ~ReturnType(aValue) + 1; } template<> inline float -Abs(const float f) +Abs(const float aFloat) { - return std::fabs(f); + return std::fabs(aFloat); } template<> inline double -Abs(const double d) +Abs(const double aDouble) { - return std::fabs(d); + return std::fabs(aDouble); } template<> inline long double -Abs(const long double d) +Abs(const long double aLongDouble) { - return std::fabs(d); + return std::fabs(aLongDouble); } } // namespace mozilla -#if defined(_WIN32) && (_MSC_VER >= 1300) && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) +#if defined(_WIN32) && (_MSC_VER >= 1300) && \ + (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) # define MOZ_BITSCAN_WINDOWS - extern "C" { - unsigned char _BitScanForward(unsigned long* Index, unsigned long mask); - unsigned char _BitScanReverse(unsigned long* Index, unsigned long mask); +# include # pragma intrinsic(_BitScanForward, _BitScanReverse) # if defined(_M_AMD64) || defined(_M_X64) # define MOZ_BITSCAN_WINDOWS64 - unsigned char _BitScanForward64(unsigned long* index, unsigned __int64 mask); - unsigned char _BitScanReverse64(unsigned long* index, unsigned __int64 mask); # pragma intrinsic(_BitScanForward64, _BitScanReverse64) # endif - } // extern "C" #endif @@ -169,62 +166,68 @@ namespace detail { #if defined(MOZ_BITSCAN_WINDOWS) - inline uint_fast8_t - CountLeadingZeroes32(uint32_t u) - { - unsigned long index; - _BitScanReverse(&index, static_cast(u)); - return uint_fast8_t(31 - index); - } +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanReverse(&index, static_cast(aValue)); + return uint_fast8_t(31 - index); +} - inline uint_fast8_t - CountTrailingZeroes32(uint32_t u) - { - unsigned long index; - _BitScanForward(&index, static_cast(u)); - return uint_fast8_t(index); - } +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanForward(&index, static_cast(aValue)); + return uint_fast8_t(index); +} - inline uint_fast8_t - CountPopulation32(uint32_t u) - { - uint32_t sum2 = (u & 0x55555555) + ((u & 0xaaaaaaaa) >> 1); - uint32_t sum4 = (sum2 & 0x33333333) + ((sum2 & 0xcccccccc) >> 2); - uint32_t sum8 = (sum4 & 0x0f0f0f0f) + ((sum4 & 0xf0f0f0f0) >> 4); - uint32_t sum16 = (sum8 & 0x00ff00ff) + ((sum8 & 0xff00ff00) >> 8); - return sum16; - } +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + uint32_t x = aValue - ((aValue >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + return (((x + (x >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; +} +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return uint_fast8_t(CountPopulation32(aValue & 0xffffffff) + + CountPopulation32(aValue >> 32)); +} - inline uint_fast8_t - CountLeadingZeroes64(uint64_t u) - { -# if defined(MOZ_BITSCAN_WINDOWS64) - unsigned long index; - _BitScanReverse64(&index, static_cast(u)); - return uint_fast8_t(63 - index); -# else - uint32_t hi = uint32_t(u >> 32); - if (hi != 0) - return CountLeadingZeroes32(hi); - return 32 + CountLeadingZeroes32(uint32_t(u)); -# endif +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanReverse64(&index, static_cast(aValue)); + return uint_fast8_t(63 - index); +#else + uint32_t hi = uint32_t(aValue >> 32); + if (hi != 0) { + return CountLeadingZeroes32(hi); } + return 32u + CountLeadingZeroes32(uint32_t(aValue)); +#endif +} - inline uint_fast8_t - CountTrailingZeroes64(uint64_t u) - { -# if defined(MOZ_BITSCAN_WINDOWS64) - unsigned long index; - _BitScanForward64(&index, static_cast(u)); - return uint_fast8_t(index); -# else - uint32_t lo = uint32_t(u); - if (lo != 0) - return CountTrailingZeroes32(lo); - return 32 + CountTrailingZeroes32(uint32_t(u >> 32)); -# endif +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanForward64(&index, static_cast(aValue)); + return uint_fast8_t(index); +#else + uint32_t lo = uint32_t(aValue); + if (lo != 0) { + return CountTrailingZeroes32(lo); } + return 32u + CountTrailingZeroes32(uint32_t(aValue >> 32)); +#endif +} # ifdef MOZ_HAVE_BITSCAN64 # undef MOZ_HAVE_BITSCAN64 @@ -240,52 +243,59 @@ namespace detail { // gcc has had __builtin_clz and friends since 3.4: no need to check. # endif - inline uint_fast8_t - CountLeadingZeroes32(uint32_t u) - { - return __builtin_clz(u); - } +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + return __builtin_clz(aValue); +} - inline uint_fast8_t - CountTrailingZeroes32(uint32_t u) - { - return __builtin_ctz(u); - } +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + return __builtin_ctz(aValue); +} - inline uint_fast8_t - CountPopulation32(uint32_t u) - { - return __builtin_popcount(u); - } +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + return __builtin_popcount(aValue); +} - inline uint_fast8_t - CountLeadingZeroes64(uint64_t u) - { - return __builtin_clzll(u); - } +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return __builtin_popcountll(aValue); +} - inline uint_fast8_t - CountTrailingZeroes64(uint64_t u) - { - return __builtin_ctzll(u); - } +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ + return __builtin_clzll(aValue); +} + +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ + return __builtin_ctzll(aValue); +} #else # error "Implement these!" - inline uint_fast8_t CountLeadingZeroes32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountTrailingZeroes32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountPopulation32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountLeadingZeroes64(uint64_t u) MOZ_DELETE; - inline uint_fast8_t CountTrailingZeroes64(uint64_t u) MOZ_DELETE; +inline uint_fast8_t CountLeadingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountLeadingZeroes64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes64(uint64_t aValue) MOZ_DELETE; #endif } // namespace detail /** - * Compute the number of high-order zero bits in the NON-ZERO number |u|. That - * is, looking at the bitwise representation of the number, with the highest- - * valued bits at the start, return the number of zeroes before the first one - * is observed. + * Compute the number of high-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * highest- valued bits at the start, return the number of zeroes before the + * first one is observed. * * CountLeadingZeroes32(0xF0FF1000) is 0; * CountLeadingZeroes32(0x7F8F0001) is 1; @@ -293,17 +303,17 @@ namespace detail { * CountLeadingZeroes32(0x1FF50010) is 3; and so on. */ inline uint_fast8_t -CountLeadingZeroes32(uint32_t u) +CountLeadingZeroes32(uint32_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountLeadingZeroes32(u); + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes32(aValue); } /** - * Compute the number of low-order zero bits in the NON-ZERO number |u|. That - * is, looking at the bitwise representation of the number, with the lowest- - * valued bits at the start, return the number of zeroes before the first one - * is observed. + * Compute the number of low-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * lowest- valued bits at the start, return the number of zeroes before the + * first one is observed. * * CountTrailingZeroes32(0x0100FFFF) is 0; * CountTrailingZeroes32(0x7000FFFE) is 1; @@ -311,35 +321,42 @@ CountLeadingZeroes32(uint32_t u) * CountTrailingZeroes32(0x0080FFF8) is 3; and so on. */ inline uint_fast8_t -CountTrailingZeroes32(uint32_t u) +CountTrailingZeroes32(uint32_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountTrailingZeroes32(u); + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes32(aValue); } /** - * Compute the number of one bits in the number |u|, + * Compute the number of one bits in the number |aValue|, */ inline uint_fast8_t -CountPopulation32(uint32_t u) +CountPopulation32(uint32_t aValue) +{ + return detail::CountPopulation32(aValue); +} + +/** Analogous to CoutPopulation32, but for 64-bit numbers */ +inline uint_fast8_t +CountPopulation64(uint64_t aValue) { - return detail::CountPopulation32(u); + return detail::CountPopulation64(aValue); } /** Analogous to CountLeadingZeroes32, but for 64-bit numbers. */ inline uint_fast8_t -CountLeadingZeroes64(uint64_t u) +CountLeadingZeroes64(uint64_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountLeadingZeroes64(u); + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes64(aValue); } /** Analogous to CountTrailingZeroes32, but for 64-bit numbers. */ inline uint_fast8_t -CountTrailingZeroes64(uint64_t u) +CountTrailingZeroes64(uint64_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountTrailingZeroes64(u); + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes64(aValue); } namespace detail { @@ -350,27 +367,29 @@ class CeilingLog2; template class CeilingLog2 { - public: - static uint_fast8_t compute(const T t) { - // Check for <= 1 to avoid the == 0 undefined case. - return t <= 1 ? 0 : 32 - CountLeadingZeroes32(t - 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0u : 32u - CountLeadingZeroes32(aValue - 1); + } }; template class CeilingLog2 { - public: - static uint_fast8_t compute(const T t) { - // Check for <= 1 to avoid the == 0 undefined case. - return t <= 1 ? 0 : 64 - CountLeadingZeroes64(t - 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0 : 64 - CountLeadingZeroes64(aValue - 1); + } }; } // namespace detail /** - * Compute the log of the least power of 2 greater than or equal to |t|. + * Compute the log of the least power of 2 greater than or equal to |aValue|. * * CeilingLog2(0..1) is 0; * CeilingLog2(2) is 1; @@ -380,16 +399,16 @@ class CeilingLog2 */ template inline uint_fast8_t -CeilingLog2(const T t) +CeilingLog2(const T aValue) { - return detail::CeilingLog2::compute(t); + return detail::CeilingLog2::compute(aValue); } /** A CeilingLog2 variant that accepts only size_t. */ inline uint_fast8_t -CeilingLog2Size(size_t n) +CeilingLog2Size(size_t aValue) { - return CeilingLog2(n); + return CeilingLog2(aValue); } namespace detail { @@ -400,25 +419,27 @@ class FloorLog2; template class FloorLog2 { - public: - static uint_fast8_t compute(const T t) { - return 31 - CountLeadingZeroes32(t | 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + return 31u - CountLeadingZeroes32(aValue | 1); + } }; template class FloorLog2 { - public: - static uint_fast8_t compute(const T t) { - return 63 - CountLeadingZeroes64(t | 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + return 63u - CountLeadingZeroes64(aValue | 1); + } }; } // namespace detail /** - * Compute the log of the greatest power of 2 less than or equal to |t|. + * Compute the log of the greatest power of 2 less than or equal to |aValue|. * * FloorLog2(0..1) is 0; * FloorLog2(2..3) is 1; @@ -427,16 +448,16 @@ class FloorLog2 */ template inline uint_fast8_t -FloorLog2(const T t) +FloorLog2(const T aValue) { - return detail::FloorLog2::compute(t); + return detail::FloorLog2::compute(aValue); } /** A FloorLog2 variant that accepts only size_t. */ inline uint_fast8_t -FloorLog2Size(size_t n) +FloorLog2Size(size_t aValue) { - return FloorLog2(n); + return FloorLog2(aValue); } /* @@ -444,11 +465,11 @@ FloorLog2Size(size_t n) * be so great that the computed value would overflow |size_t|. */ inline size_t -RoundUpPow2(size_t x) +RoundUpPow2(size_t aValue) { - MOZ_ASSERT(x <= (size_t(1) << (sizeof(size_t) * CHAR_BIT - 1)), + MOZ_ASSERT(aValue <= (size_t(1) << (sizeof(size_t) * CHAR_BIT - 1)), "can't round up -- will overflow!"); - return size_t(1) << CeilingLog2(x); + return size_t(1) << CeilingLog2(aValue); } /** @@ -456,11 +477,11 @@ RoundUpPow2(size_t x) */ template inline T -RotateLeft(const T t, uint_fast8_t shift) +RotateLeft(const T aValue, uint_fast8_t aShift) { - MOZ_ASSERT(shift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); static_assert(IsUnsigned::value, "Rotates require unsigned values"); - return (t << shift) | (t >> (sizeof(T) * CHAR_BIT - shift)); + return (aValue << aShift) | (aValue >> (sizeof(T) * CHAR_BIT - aShift)); } /** @@ -468,11 +489,11 @@ RotateLeft(const T t, uint_fast8_t shift) */ template inline T -RotateRight(const T t, uint_fast8_t shift) +RotateRight(const T aValue, uint_fast8_t aShift) { - MOZ_ASSERT(shift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); static_assert(IsUnsigned::value, "Rotates require unsigned values"); - return (t >> shift) | (t << (sizeof(T) * CHAR_BIT - shift)); + return (aValue >> aShift) | (aValue << (sizeof(T) * CHAR_BIT - aShift)); } } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Maybe.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Maybe.h index 25683a28ab..4ba88f6771 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Maybe.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Maybe.h @@ -31,131 +31,150 @@ namespace mozilla { template class Maybe { - AlignedStorage2 storage; - bool constructed; - - T& asT() { return *storage.addr(); } - - public: - Maybe() { constructed = false; } - ~Maybe() { if (constructed) asT().~T(); } - - bool empty() const { return !constructed; } - - void construct() { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(); - constructed = true; - } - - template - void construct(const T1& t1) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8, const T9& t9) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8, t9); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); - constructed = true; - } - - T* addr() { - MOZ_ASSERT(constructed); - return &asT(); - } - - T& ref() { - MOZ_ASSERT(constructed); - return asT(); - } - - const T& ref() const { - MOZ_ASSERT(constructed); - return const_cast(this)->asT(); - } - - void destroy() { - ref().~T(); - constructed = false; - } - - void destroyIfConstructed() { - if (!empty()) - destroy(); - } - - private: - Maybe(const Maybe& other) MOZ_DELETE; - const Maybe& operator=(const Maybe& other) MOZ_DELETE; + AlignedStorage2 storage; + bool constructed; + + T& asT() { return *storage.addr(); } + +public: + Maybe() { constructed = false; } + ~Maybe() { if (constructed) { asT().~T(); } } + + bool empty() const { return !constructed; } + + void construct() + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(); + constructed = true; + } + + template + void construct(const T1& aT1) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9, const T10& aT10) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9, aT10); + constructed = true; + } + + T* addr() + { + MOZ_ASSERT(constructed); + return &asT(); + } + + T& ref() + { + MOZ_ASSERT(constructed); + return asT(); + } + + const T& ref() const + { + MOZ_ASSERT(constructed); + return const_cast(this)->asT(); + } + + void destroy() + { + ref().~T(); + constructed = false; + } + + void destroyIfConstructed() + { + if (!empty()) { + destroy(); + } + } + +private: + Maybe(const Maybe& aOther) MOZ_DELETE; + const Maybe& operator=(const Maybe& aOther) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MaybeOneOf.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MaybeOneOf.h new file mode 100644 index 0000000000..1c58f88253 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MaybeOneOf.h @@ -0,0 +1,144 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_MaybeOneOf_h +#define mozilla_MaybeOneOf_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" +#include "mozilla/Move.h" +#include "mozilla/TemplateLib.h" + +#include // For placement new + +namespace mozilla { + +/* + * MaybeOneOf is like Maybe, but it supports constructing either T1 + * or T2. When a MaybeOneOf is constructed, it is |empty()|, i.e., + * no value has been constructed and no destructor will be called when the + * MaybeOneOf is destroyed. Upon calling |construct()| or + * |construct()|, a T1 or T2 object will be constructed with the given + * arguments and that object will be destroyed when the owning MaybeOneOf is + * destroyed. + */ +template +class MaybeOneOf +{ + AlignedStorage::value> storage; + + enum State { None, SomeT1, SomeT2 } state; + template struct Type2State {}; + + template + T& as() + { + MOZ_ASSERT(state == Type2State::result); + return *(T*)storage.addr(); + } + + template + const T& as() const + { + MOZ_ASSERT(state == Type2State::result); + return *(T*)storage.addr(); + } + +public: + MaybeOneOf() : state(None) {} + ~MaybeOneOf() { destroyIfConstructed(); } + + bool empty() const { return state == None; } + + template + bool constructed() const { return state == Type2State::result; } + + template + void construct() + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(); + } + + template + void construct(U&& aU) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(Move(aU)); + } + + template + void construct(const U1& aU1) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(aU1); + } + + template + void construct(const U1& aU1, const U2& aU2) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(aU1, aU2); + } + + template + T& ref() + { + return as(); + } + + template + const T& ref() const + { + return as(); + } + + void destroy() + { + MOZ_ASSERT(state == SomeT1 || state == SomeT2); + if (state == SomeT1) { + as().~T1(); + } else if (state == SomeT2) { + as().~T2(); + } + state = None; + } + + void destroyIfConstructed() + { + if (!empty()) { + destroy(); + } + } + +private: + MaybeOneOf(const MaybeOneOf& aOther) MOZ_DELETE; + const MaybeOneOf& operator=(const MaybeOneOf& aOther) MOZ_DELETE; +}; + +template +template +struct MaybeOneOf::Type2State +{ + typedef MaybeOneOf Enclosing; + static const typename Enclosing::State result = Enclosing::SomeT1; +}; + +template +template +struct MaybeOneOf::Type2State +{ + typedef MaybeOneOf Enclosing; + static const typename Enclosing::State result = Enclosing::SomeT2; +}; + +} // namespace mozilla + +#endif /* mozilla_MaybeOneOf_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MemoryChecking.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MemoryChecking.h index 2130990c6b..0642d758c0 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MemoryChecking.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/MemoryChecking.h @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* - * Provides a common interface to the ASan (AddressSanitizer) and Valgrind + * Provides a common interface to the ASan (AddressSanitizer) and Valgrind * functions used to mark memory in certain ways. In detail, the following * three macros are provided: * @@ -34,14 +34,14 @@ #if defined(MOZ_ASAN) #include +#include "mozilla/Types.h" + extern "C" { - /* These definitions are usually provided through the - * sanitizer/asan_interface.h header installed by ASan. - */ - void __asan_poison_memory_region(void const volatile *addr, size_t size) - __attribute__((visibility("default"))); - void __asan_unpoison_memory_region(void const volatile *addr, size_t size) - __attribute__((visibility("default"))); +/* These definitions are usually provided through the + * sanitizer/asan_interface.h header installed by ASan. + */ +void MOZ_EXPORT __asan_poison_memory_region(void const volatile *addr, size_t size); +void MOZ_EXPORT __asan_unpoison_memory_region(void const volatile *addr, size_t size); #define MOZ_MAKE_MEM_NOACCESS(addr, size) \ __asan_poison_memory_region((addr), (size)) @@ -63,9 +63,9 @@ extern "C" { VALGRIND_MAKE_MEM_DEFINED((addr), (size)) #else -#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while(0) -#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while(0) -#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while(0) +#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while (0) #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Move.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Move.h index f7d39ffa9b..08ae86fa57 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Move.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Move.h @@ -105,7 +105,7 @@ namespace mozilla { * * c2 = Move(c1); * - * This destroys c1, moves c1's value to c2, and leaves c1 in an undefined but + * This destroys c2, moves c1's value to c2, and leaves c1 in an undefined but * destructible state. * * As we say, a move must leave the original in a "destructible" state. The @@ -132,7 +132,7 @@ namespace mozilla { * * To avoid this, C++11 has tweaks to make it possible to write what you mean. * The four constructor overloads above can be written as one constructor - * template like so: + * template like so[0]: * * template * C::C(XArg&& x, YArg&& y) : x(Forward(x)), y(Forward(y)) { } @@ -144,8 +144,8 @@ namespace mozilla { * - First, when a function template takes an argument that is an rvalue * reference to a template argument (like 'XArg&& x' and 'YArg&& y' above), * then when the argument is applied to an lvalue, the template argument - * resolves to 'T &'; and when it is applied to an rvalue, the template - * argument resolves to 'T &&'. Thus, in a call to C::C like: + * resolves to 'T&'; and when it is applied to an rvalue, the template + * argument resolves to 'T&&'. Thus, in a call to C::C like: * * X foo(int); * Y yy; @@ -180,6 +180,28 @@ namespace mozilla { * 'std::forward', which are just like our 'Move' and 'Forward'; but those * definitions aren't available in that header on all our platforms, so we * define them ourselves here.) + * + * 0. This pattern is known as "perfect forwarding". Interestingly, it is not + * actually perfect, and it can't forward all possible argument expressions! + * There are two issues: one that's a C++11 issue, and one that's a legacy + * compiler issue. + * + * The C++11 issue is that you can't form a reference to a bit-field. As a + * workaround, assign the bit-field to a local variable and use that: + * + * // C is as above + * struct S { int x : 1; } s; + * C(s.x, 0); // BAD: s.x is a reference to a bit-field, can't form those + * int tmp = s.x; + * C(tmp, 0); // OK: tmp not a bit-field + * + * The legacy issue is that when we don't have true nullptr and must emulate + * it (gcc 4.4/4.5), forwarding |nullptr| results in an |int| or |long| + * forwarded reference. But such a reference, even if its value is a null + * pointer constant expression, is not itself a null pointer constant + * expression. This causes -Werror=conversion-null errors and pointer-to- + * integer comparison errors. Until we always have true nullptr, users of + * forwarding methods must not pass |nullptr| to them. */ /** @@ -188,9 +210,9 @@ namespace mozilla { */ template inline typename RemoveReference::Type&& -Move(T&& a) +Move(T&& aX) { - return static_cast::Type&&>(a); + return static_cast::Type&&>(aX); } /** @@ -199,28 +221,28 @@ Move(T&& a) */ template inline T&& -Forward(typename RemoveReference::Type& a) +Forward(typename RemoveReference::Type& aX) { - return static_cast(a); + return static_cast(aX); } template inline T&& -Forward(typename RemoveReference::Type&& t) +Forward(typename RemoveReference::Type&& aX) { static_assert(!IsLvalueReference::value, "misuse of Forward detected! try the other overload"); - return static_cast(t); + return static_cast(aX); } -/** Swap |t| and |u| using move-construction if possible. */ +/** Swap |aX| and |aY| using move-construction if possible. */ template inline void -Swap(T& t, T& u) +Swap(T& aX, T& aY) { - T tmp(Move(t)); - t = Move(u); - u = Move(tmp); + T tmp(Move(aX)); + aX = Move(aY); + aY = Move(tmp); } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/NullPtr.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/NullPtr.h index 35faadc4c3..5963613c4b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/NullPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/NullPtr.h @@ -13,12 +13,10 @@ #define mozilla_NullPtr_h #if defined(__clang__) -# ifndef __has_extension -# define __has_extension __has_feature -# endif -# if __has_extension(cxx_nullptr) -# define MOZ_HAVE_CXX11_NULLPTR +# if !__has_extension(cxx_nullptr) +# error "clang version natively supporting nullptr is required." # endif +# define MOZ_HAVE_CXX11_NULLPTR #elif defined(__GNUC__) # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L # include "mozilla/Compiler.h" @@ -26,23 +24,89 @@ # define MOZ_HAVE_CXX11_NULLPTR # endif # endif -#elif _MSC_VER >= 1600 -# define MOZ_HAVE_CXX11_NULLPTR +#elif defined(_MSC_VER) + // The minimum supported MSVC (10, _MSC_VER 1600) supports nullptr. +# define MOZ_HAVE_CXX11_NULLPTR #endif +namespace mozilla { + /** - * Use C++11 nullptr if available; otherwise use __null for gcc, or a 0 literal - * with the correct size to match the size of a pointer on a given platform. + * IsNullPointer::value is true iff T is the type of C++11's nullptr. If + * nullptr is emulated, IsNullPointer::value is false for all T. + * + * IsNullPointer is useful to give an argument the true decltype(nullptr) type. + * decltype(nullptr) doesn't work when nullptr is emulated. The simplest + * workaround is to use template overloading and SFINAE to expose an overload + * only if an argument's type is decltype(nullptr). Some examples (that assume + * namespace mozilla has been opened, for simplicity): + * + * // foo(T*), foo(stuff that converts to T*), and foo(decltype(nullptr)) + * // (only invoked if nullptr is true nullptr, otherwise foo(T*) is invoked) + * // but nothing else + * void foo(T*) { } + * template + * void foo(N, + * typename EnableIf::value, int>::Type dummy = 0) + * { } + * + * // foo(T*) *exactly* and foo(decltype(nullptr)), nothing else + * void foo(T*) { } + * template + * void foo(U, + * typename EnableIf::value, int>::Type dummy = 0) + * MOZ_DELETE; + * + * The exact details of how set up the SFINAE bits vary on a case-by-case basis. + * If you need help with this (and unless you've internalized way more sadmaking + * nullptr-emulation knowledge than you should have, you do), feel free to poke + * the person with blame on this comment with questions. :-) + * + * Ideally this would be in TypeTraits.h, but C++11 omitted std::is_null_pointer + * (fixed in C++1y), so in the interests of easing a switch to , + * this trait lives elsewhere. */ +template +struct IsNullPointer { static const bool value = false; }; -#ifndef MOZ_HAVE_CXX11_NULLPTR -# if defined(__GNUC__) -# define nullptr __null -# elif defined(_WIN64) -# define nullptr 0LL -# else -# define nullptr 0L -# endif +} // namespace mozilla + +/** + * mozilla::NullptrT is a type that's sort of like decltype(nullptr). But it + * can't be identical, because emulated nullptr doesn't have a distinct type. + * Only with gcc 4.4/4.5, emulated nullptr is __null, and decltype(__null) is + * int or long. But passing __null to an int/long parameter triggers + * -Werror=conversion-null errors with gcc 4.5, or (depending on subsequent use + * inside the overloaded function) can trigger pointer-to-integer comparison + * compiler errors. So fairly often, actually, NullptrT is *not* what you want. + * + * Instead, often you should use template-based overloading in concert with + * SFINAE to add a nullptr overload -- see the comments by IsNullPointer. + * + * So when *should* you use NullptrT? Thus far, the only truly good use seems + * to be as an argument type for operator overloads (because C++ doesn't allow + * operator= to have more than one argument, operator== to have more than two, + * &c.). But even in such cases, it really only works if there are no other + * overloads of the operator that accept a pointer type. If you want both T* + * and nullptr_t overloads, you'll have to wait til we drop gcc 4.4/4.5 support. + * (Currently b2g is the only impediment to this.) + */ +#ifdef MOZ_HAVE_CXX11_NULLPTR +// decltype does the right thing for actual nullptr. +namespace mozilla { +typedef decltype(nullptr) NullptrT; +template<> +struct IsNullPointer { static const bool value = true; }; +} +# undef MOZ_HAVE_CXX11_NULLPTR +#elif MOZ_IS_GCC +# define nullptr __null +// void* sweeps up more than just nullptr, but compilers supporting true +// nullptr are the majority now, so they should detect mistakes. If you're +// feeling paranoid, check/assert that your NullptrT equals nullptr. +namespace mozilla { typedef void* NullptrT; } +#else +# error "No compiler support for nullptr or its emulation." #endif #endif /* mozilla_NullPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/NumericLimits.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/NumericLimits.h index d2ee29813e..730fcb410b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/NumericLimits.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/NumericLimits.h @@ -17,10 +17,10 @@ namespace mozilla { /** - * The NumericLimits class provides a compatibility layer with std::numeric_limits - * for char16_t, otherwise it is exactly the same as std::numeric_limits. - * Code which does not need std::numeric_limits should avoid using - * NumericLimits. + * The NumericLimits class provides a compatibility layer with + * std::numeric_limits for char16_t, otherwise it is exactly the same as + * std::numeric_limits. Code which does not need std::numeric_limits + * should avoid using NumericLimits. */ template class NumericLimits : public std::numeric_limits diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Pair.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Pair.h new file mode 100644 index 0000000000..e9e8a76938 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Pair.h @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A class holding a pair of objects that tries to conserve storage space. */ + +#ifndef mozilla_Pair_h +#define mozilla_Pair_h + +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +namespace detail { + +enum StorageType { AsBase, AsMember }; + +// Optimize storage using the Empty Base Optimization -- that empty base classes +// don't take up space -- to optimize size when one or the other class is +// stateless and can be used as a base class. +// +// The extra conditions on storage for B are necessary so that PairHelper won't +// ambiguously inherit from either A or B, such that one or the other base class +// would be inaccessible. +template::value ? detail::AsBase : detail::AsMember, + detail::StorageType = + IsEmpty::value && !IsBaseOf::value && !IsBaseOf::value + ? detail::AsBase + : detail::AsMember> +struct PairHelper; + +template +struct PairHelper +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : mFirstA(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(mSecondB, aOther.mSecondB); + } + +private: + A mFirstA; + B mSecondB; +}; + +template +struct PairHelper : private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : B(Forward(aB)), + mFirstA(Forward(aA)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return *this; } + const B& second() const { return *this; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(static_cast(*this), static_cast(aOther)); + } + +private: + A mFirstA; +}; + +template +struct PairHelper : private A +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return *this; } + const A& first() const { return *this; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(mSecondB, aOther.mSecondB); + } + +private: + B mSecondB; +}; + +template +struct PairHelper : private A, private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + B(Forward(aB)) + {} + + A& first() { return static_cast(*this); } + const A& first() const { return static_cast(*this); } + B& second() { return static_cast(*this); } + const B& second() const { return static_cast(*this); } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(static_cast(*this), static_cast(aOther)); + } +}; + +} // namespace detail + +/** + * Pair is the logical concatenation of an instance of A with an instance B. + * Space is conserved when possible. Neither A nor B may be a final class. + * + * It's typically clearer to have individual A and B member fields. Except if + * you want the space-conserving qualities of Pair, you're probably better off + * not using this! + * + * No guarantees are provided about the memory layout of A and B, the order of + * initialization or destruction of A and B, and so on. (This is approximately + * required to optimize space usage.) The first/second names are merely + * conceptual! + */ +template +struct Pair + : private detail::PairHelper +{ + typedef typename detail::PairHelper Base; + +public: + template + Pair(AArg&& aA, BArg&& aB) + : Base(Forward(aA), Forward(aB)) + {} + + /** The A instance. */ + using Base::first; + /** The B instance. */ + using Base::second; + + /** Swap this pair with another pair. */ + void swap(Pair& aOther) { Base::swap(aOther); } + +private: + Pair(const Pair&) MOZ_DELETE; +}; + +template +void +Swap(Pair& aX, Pair& aY) +{ + aX.swap(aY); +} + +} // namespace mozilla + +#endif /* mozilla_Pair_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/PodOperations.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/PodOperations.h index adbf2e699d..843e1311d3 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/PodOperations.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/PodOperations.h @@ -24,26 +24,27 @@ namespace mozilla { -/** Set the contents of |t| to 0. */ +/** Set the contents of |aT| to 0. */ template static MOZ_ALWAYS_INLINE void -PodZero(T* t) +PodZero(T* aT) { - memset(t, 0, sizeof(T)); + memset(aT, 0, sizeof(T)); } -/** Set the contents of |nelem| elements starting at |t| to 0. */ +/** Set the contents of |aNElem| elements starting at |aT| to 0. */ template static MOZ_ALWAYS_INLINE void -PodZero(T* t, size_t nelem) +PodZero(T* aT, size_t aNElem) { /* - * This function is often called with 'nelem' small; we use an inline loop + * This function is often called with 'aNElem' small; we use an inline loop * instead of calling 'memset' with a non-constant length. The compiler * should inline the memset call with constant size, though. */ - for (T* end = t + nelem; t < end; t++) - memset(t, 0, sizeof(T)); + for (T* end = aT + aNElem; aT < end; aT++) { + memset(aT, 0, sizeof(T)); + } } /* @@ -54,107 +55,116 @@ PodZero(T* t, size_t nelem) * compile error involving PodZero and array types, use PodArrayZero instead. */ template -static void PodZero(T (&t)[N]) MOZ_DELETE; +static void PodZero(T (&aT)[N]) MOZ_DELETE; template -static void PodZero(T (&t)[N], size_t nelem) MOZ_DELETE; +static void PodZero(T (&aT)[N], size_t aNElem) MOZ_DELETE; -/** Set the contents of the array |t| to zero. */ +/** Set the contents of the array |aT| to zero. */ template static MOZ_ALWAYS_INLINE void -PodArrayZero(T (&t)[N]) +PodArrayZero(T (&aT)[N]) { - memset(t, 0, N * sizeof(T)); + memset(aT, 0, N * sizeof(T)); } template static MOZ_ALWAYS_INLINE void -PodArrayZero(Array& arr) +PodArrayZero(Array& aArr) { - memset(&arr[0], 0, N * sizeof(T)); + memset(&aArr[0], 0, N * sizeof(T)); } /** - * Assign |*src| to |*dst|. The locations must not be the same and must not + * Assign |*aSrc| to |*aDst|. The locations must not be the same and must not * overlap. */ template static MOZ_ALWAYS_INLINE void -PodAssign(T* dst, const T* src) +PodAssign(T* aDst, const T* aSrc) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, PointerRangeSize(src, static_cast(dst)) >= 1); - MOZ_ASSERT_IF(dst < src, PointerRangeSize(static_cast(dst), src) >= 1); - memcpy(reinterpret_cast(dst), reinterpret_cast(src), sizeof(T)); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= 1); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= 1); + memcpy(reinterpret_cast(aDst), reinterpret_cast(aSrc), + sizeof(T)); } /** - * Copy |nelem| T elements from |src| to |dst|. The two memory ranges must not - * overlap! + * Copy |aNElem| T elements from |aSrc| to |aDst|. The two memory ranges must + * not overlap! */ template static MOZ_ALWAYS_INLINE void -PodCopy(T* dst, const T* src, size_t nelem) +PodCopy(T* aDst, const T* aSrc, size_t aNElem) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, PointerRangeSize(src, static_cast(dst)) >= nelem); - MOZ_ASSERT_IF(dst < src, PointerRangeSize(static_cast(dst), src) >= nelem); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); - if (nelem < 128) { + if (aNElem < 128) { /* * Avoid using operator= in this loop, as it may have been * intentionally deleted by the POD type. */ - for (const T* srcend = src + nelem; src < srcend; src++, dst++) - PodAssign(dst, src); + for (const T* srcend = aSrc + aNElem; aSrc < srcend; aSrc++, aDst++) { + PodAssign(aDst, aSrc); + } } else { - memcpy(dst, src, nelem * sizeof(T)); + memcpy(aDst, aSrc, aNElem * sizeof(T)); } } template static MOZ_ALWAYS_INLINE void -PodCopy(volatile T* dst, const volatile T* src, size_t nelem) +PodCopy(volatile T* aDst, const volatile T* aSrc, size_t aNElem) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, - PointerRangeSize(src, static_cast(dst)) >= nelem); - MOZ_ASSERT_IF(dst < src, - PointerRangeSize(static_cast(dst), src) >= nelem); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); /* - * Volatile |dst| requires extra work, because it's undefined behavior to + * Volatile |aDst| requires extra work, because it's undefined behavior to * modify volatile objects using the mem* functions. Just write out the * loops manually, using operator= rather than memcpy for the same reason, * and let the compiler optimize to the extent it can. */ - for (const volatile T* srcend = src + nelem; src < srcend; src++, dst++) - *dst = *src; + for (const volatile T* srcend = aSrc + aNElem; + aSrc < srcend; + aSrc++, aDst++) { + *aDst = *aSrc; + } } /* - * Copy the contents of the array |src| into the array |dst|, both of size N. + * Copy the contents of the array |aSrc| into the array |aDst|, both of size N. * The arrays must not overlap! */ template static MOZ_ALWAYS_INLINE void -PodArrayCopy(T (&dst)[N], const T (&src)[N]) +PodArrayCopy(T (&aDst)[N], const T (&aSrc)[N]) { - PodCopy(dst, src, N); + PodCopy(aDst, aSrc, N); } /** - * Copy the memory for |nelem| T elements from |src| to |dst|. If the two - * memory ranges overlap, then the effect is as if the |nelem| elements are - * first copied from |src| to a temporary array, and then from the temporary - * array to |dst|. + * Copy the memory for |aNElem| T elements from |aSrc| to |aDst|. If the two + * memory ranges overlap, then the effect is as if the |aNElem| elements are + * first copied from |aSrc| to a temporary array, and then from the temporary + * array to |aDst|. */ template static MOZ_ALWAYS_INLINE void -PodMove(T* dst, const T* src, size_t nelem) +PodMove(T* aDst, const T* aSrc, size_t aNElem) { - MOZ_ASSERT(nelem <= SIZE_MAX / sizeof(T), + MOZ_ASSERT(aNElem <= SIZE_MAX / sizeof(T), "trying to move an impossible number of elements"); - memmove(dst, src, nelem * sizeof(T)); + memmove(aDst, aSrc, aNElem * sizeof(T)); } /** @@ -170,8 +180,9 @@ PodEqual(const T* one, const T* two, size_t len) const T* p1 = one; const T* p2 = two; for (; p1 < p1end; p1++, p2++) { - if (*p1 != *p2) + if (*p1 != *p2) { return false; + } } return true; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Range.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Range.h index 4e02d962b5..814a2821ad 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Range.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Range.h @@ -18,32 +18,26 @@ namespace mozilla { template class Range { - RangedPtr mStart; - RangedPtr mEnd; + const RangedPtr mStart; + const RangedPtr mEnd; - typedef void (Range::* ConvertibleToBool)(); - void nonNull() {} + typedef void (Range::* ConvertibleToBool)(); + void nonNull() {} - public: - Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} - Range(T* p, size_t len) - : mStart(p, p, p + len), - mEnd(p + len, p, p + len) - {} +public: + Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} + Range(T* aPtr, size_t aLength) + : mStart(aPtr, aPtr, aPtr + aLength), + mEnd(aPtr + aLength, aPtr, aPtr + aLength) + {} - RangedPtr start() const { return mStart; } - RangedPtr end() const { return mEnd; } - size_t length() const { return mEnd - mStart; } + RangedPtr start() const { return mStart; } + RangedPtr end() const { return mEnd; } + size_t length() const { return mEnd - mStart; } - T& operator[](size_t offset) { - return mStart[offset]; - } + T& operator[](size_t aOffset) const { return mStart[aOffset]; } - const T& operator[](size_t offset) const { - return mStart[offset]; - } - - operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } + operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RangedPtr.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RangedPtr.h index 561e564ded..4d94035b90 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RangedPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RangedPtr.h @@ -43,214 +43,240 @@ namespace mozilla { template class RangedPtr { - T* ptr; + T* mPtr; #ifdef DEBUG - T* const rangeStart; - T* const rangeEnd; + T* const mRangeStart; + T* const mRangeEnd; #endif - typedef void (RangedPtr::* ConvertibleToBool)(); - void nonNull() {} + typedef void (RangedPtr::* ConvertibleToBool)(); + void nonNull() {} - void checkSanity() { - MOZ_ASSERT(rangeStart <= ptr); - MOZ_ASSERT(ptr <= rangeEnd); - } + void checkSanity() + { + MOZ_ASSERT(mRangeStart <= mPtr); + MOZ_ASSERT(mPtr <= mRangeEnd); + } - /* Creates a new pointer for |p|, restricted to this pointer's range. */ - RangedPtr create(T *p) const { + /* Creates a new pointer for |aPtr|, restricted to this pointer's range. */ + RangedPtr create(T* aPtr) const + { #ifdef DEBUG - return RangedPtr(p, rangeStart, rangeEnd); + return RangedPtr(aPtr, mRangeStart, mRangeEnd); #else - return RangedPtr(p, nullptr, size_t(0)); + return RangedPtr(aPtr, nullptr, size_t(0)); #endif - } + } - uintptr_t asUintptr() const { return uintptr_t(ptr); } + uintptr_t asUintptr() const { return reinterpret_cast(mPtr); } - public: - RangedPtr(T* p, T* start, T* end) - : ptr(p) +public: + RangedPtr(T* aPtr, T* aStart, T* aEnd) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(start), rangeEnd(end) + , mRangeStart(aStart), mRangeEnd(aEnd) #endif - { - MOZ_ASSERT(rangeStart <= rangeEnd); - checkSanity(); - } - RangedPtr(T* p, T* start, size_t length) - : ptr(p) + { + MOZ_ASSERT(mRangeStart <= mRangeEnd); + checkSanity(); + } + RangedPtr(T* aPtr, T* aStart, size_t aLength) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(start), rangeEnd(start + length) + , mRangeStart(aStart), mRangeEnd(aStart + aLength) #endif - { - MOZ_ASSERT(length <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(uintptr_t(rangeStart) + length * sizeof(T) >= uintptr_t(rangeStart)); - checkSanity(); - } - - /* Equivalent to RangedPtr(p, p, length). */ - RangedPtr(T* p, size_t length) - : ptr(p) + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aPtr, aPtr, aLength). */ + RangedPtr(T* aPtr, size_t aLength) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(p), rangeEnd(p + length) + , mRangeStart(aPtr), mRangeEnd(aPtr + aLength) #endif - { - MOZ_ASSERT(length <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(uintptr_t(rangeStart) + length * sizeof(T) >= uintptr_t(rangeStart)); - checkSanity(); - } - - /* Equivalent to RangedPtr(arr, arr, N). */ - template - RangedPtr(T (&arr)[N]) - : ptr(arr) + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aArr, aArr, N). */ + template + RangedPtr(T (&aArr)[N]) + : mPtr(aArr) #ifdef DEBUG - , rangeStart(arr), rangeEnd(arr + N) + , mRangeStart(aArr), mRangeEnd(aArr + N) #endif - { - checkSanity(); - } - - T* get() const { - return ptr; - } - - operator ConvertibleToBool() const { return ptr ? &RangedPtr::nonNull : 0; } - - /* - * You can only assign one RangedPtr into another if the two pointers have - * the same valid range: - * - * char arr1[] = "hi"; - * char arr2[] = "bye"; - * RangedPtr p1(arr1, 2); - * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works - * p1 = RangedPtr(arr2, 3); // asserts - */ - RangedPtr& operator=(const RangedPtr& other) { - MOZ_ASSERT(rangeStart == other.rangeStart); - MOZ_ASSERT(rangeEnd == other.rangeEnd); - ptr = other.ptr; - checkSanity(); - return *this; - } - - RangedPtr operator+(size_t inc) { - MOZ_ASSERT(inc <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(asUintptr() + inc * sizeof(T) >= asUintptr()); - return create(ptr + inc); - } - - RangedPtr operator-(size_t dec) { - MOZ_ASSERT(dec <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(asUintptr() - dec * sizeof(T) <= asUintptr()); - return create(ptr - dec); - } - - /* - * You can assign a raw pointer into a RangedPtr if the raw pointer is - * within the range specified at creation. - */ - template - RangedPtr& operator=(U* p) { - *this = create(p); - return *this; - } - - template - RangedPtr& operator=(const RangedPtr& p) { - MOZ_ASSERT(rangeStart <= p.ptr); - MOZ_ASSERT(p.ptr <= rangeEnd); - ptr = p.ptr; - checkSanity(); - return *this; - } - - RangedPtr& operator++() { - return (*this += 1); - } - - RangedPtr operator++(int) { - RangedPtr rcp = *this; - ++*this; - return rcp; - } - - RangedPtr& operator--() { - return (*this -= 1); - } - - RangedPtr operator--(int) { - RangedPtr rcp = *this; - --*this; - return rcp; - } - - RangedPtr& operator+=(size_t inc) { - *this = *this + inc; - return *this; - } - - RangedPtr& operator-=(size_t dec) { - *this = *this - dec; - return *this; - } - - T& operator[](int index) const { - MOZ_ASSERT(size_t(index > 0 ? index : -index) <= size_t(-1) / sizeof(T)); - return *create(ptr + index); - } - - T& operator*() const { - return *ptr; - } - - template - bool operator==(const RangedPtr& other) const { - return ptr == other.ptr; - } - template - bool operator!=(const RangedPtr& other) const { - return !(*this == other); - } - - template - bool operator==(const U* u) const { - return ptr == u; - } - template - bool operator!=(const U* u) const { - return !(*this == u); - } - - template - bool operator<(const RangedPtr& other) const { - return ptr < other.ptr; - } - template - bool operator<=(const RangedPtr& other) const { - return ptr <= other.ptr; - } - - template - bool operator>(const RangedPtr& other) const { - return ptr > other.ptr; - } - template - bool operator>=(const RangedPtr& other) const { - return ptr >= other.ptr; - } - - size_t operator-(const RangedPtr& other) const { - MOZ_ASSERT(ptr >= other.ptr); - return PointerRangeSize(other.ptr, ptr); - } - - private: - RangedPtr() MOZ_DELETE; - T* operator&() MOZ_DELETE; + { + checkSanity(); + } + + T* get() const { return mPtr; } + + operator ConvertibleToBool() const { return mPtr ? &RangedPtr::nonNull : 0; } + + /* + * You can only assign one RangedPtr into another if the two pointers have + * the same valid range: + * + * char arr1[] = "hi"; + * char arr2[] = "bye"; + * RangedPtr p1(arr1, 2); + * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works + * p1 = RangedPtr(arr2, 3); // asserts + */ + RangedPtr& operator=(const RangedPtr& aOther) + { + MOZ_ASSERT(mRangeStart == aOther.mRangeStart); + MOZ_ASSERT(mRangeEnd == aOther.mRangeEnd); + mPtr = aOther.mPtr; + checkSanity(); + return *this; + } + + RangedPtr operator+(size_t aInc) + { + MOZ_ASSERT(aInc <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() + aInc * sizeof(T) >= asUintptr()); + return create(mPtr + aInc); + } + + RangedPtr operator-(size_t aDec) + { + MOZ_ASSERT(aDec <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() - aDec * sizeof(T) <= asUintptr()); + return create(mPtr - aDec); + } + + /* + * You can assign a raw pointer into a RangedPtr if the raw pointer is + * within the range specified at creation. + */ + template + RangedPtr& operator=(U* aPtr) + { + *this = create(aPtr); + return *this; + } + + template + RangedPtr& operator=(const RangedPtr& aPtr) + { + MOZ_ASSERT(mRangeStart <= aPtr.mPtr); + MOZ_ASSERT(aPtr.mPtr <= mRangeEnd); + mPtr = aPtr.mPtr; + checkSanity(); + return *this; + } + + RangedPtr& operator++() + { + return (*this += 1); + } + + RangedPtr operator++(int) + { + RangedPtr rcp = *this; + ++*this; + return rcp; + } + + RangedPtr& operator--() + { + return (*this -= 1); + } + + RangedPtr operator--(int) + { + RangedPtr rcp = *this; + --*this; + return rcp; + } + + RangedPtr& operator+=(size_t aInc) + { + *this = *this + aInc; + return *this; + } + + RangedPtr& operator-=(size_t aDec) + { + *this = *this - aDec; + return *this; + } + + T& operator[](int aIndex) const + { + MOZ_ASSERT(size_t(aIndex > 0 ? aIndex : -aIndex) <= size_t(-1) / sizeof(T)); + return *create(mPtr + aIndex); + } + + T& operator*() const + { + MOZ_ASSERT(mPtr >= mRangeStart); + MOZ_ASSERT(mPtr < mRangeEnd); + return *mPtr; + } + + template + bool operator==(const RangedPtr& aOther) const + { + return mPtr == aOther.mPtr; + } + template + bool operator!=(const RangedPtr& aOther) const + { + return !(*this == aOther); + } + + template + bool operator==(const U* u) const + { + return mPtr == u; + } + template + bool operator!=(const U* u) const + { + return !(*this == u); + } + + template + bool operator<(const RangedPtr& aOther) const + { + return mPtr < aOther.mPtr; + } + template + bool operator<=(const RangedPtr& aOther) const + { + return mPtr <= aOther.mPtr; + } + + template + bool operator>(const RangedPtr& aOther) const + { + return mPtr > aOther.mPtr; + } + template + bool operator>=(const RangedPtr& aOther) const + { + return mPtr >= aOther.mPtr; + } + + size_t operator-(const RangedPtr& aOther) const + { + MOZ_ASSERT(mPtr >= aOther.mPtr); + return PointerRangeSize(aOther.mPtr, mPtr); + } + +private: + RangedPtr() MOZ_DELETE; + T* operator&() MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ReentrancyGuard.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ReentrancyGuard.h index d589f368a2..557c61015e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ReentrancyGuard.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ReentrancyGuard.h @@ -18,38 +18,38 @@ namespace mozilla { /* Useful for implementing containers that assert non-reentrancy */ class ReentrancyGuard { - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER #ifdef DEBUG - bool& entered; + bool& mEntered; #endif - public: - template +public: + template #ifdef DEBUG - ReentrancyGuard(T& obj - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : entered(obj.entered) + ReentrancyGuard(T& aObj + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mEntered(aObj.mEntered) #else - ReentrancyGuard(T& - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + ReentrancyGuard(T& + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) #endif - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; #ifdef DEBUG - MOZ_ASSERT(!entered); - entered = true; + MOZ_ASSERT(!mEntered); + mEntered = true; #endif - } - ~ReentrancyGuard() - { + } + ~ReentrancyGuard() + { #ifdef DEBUG - entered = false; + mEntered = false; #endif - } + } - private: - ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; - void operator=(const ReentrancyGuard&) MOZ_DELETE; +private: + ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; + void operator=(const ReentrancyGuard&) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RefCountType.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RefCountType.h new file mode 100644 index 0000000000..e95a22a0ca --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RefCountType.h @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_RefCountType_h +#define mozilla_RefCountType_h + +#include + +/** + * MozRefCountType is Mozilla's reference count type. + * + * We use the same type to represent the refcount of RefCounted objects + * as well, in order to be able to use the leak detection facilities + * that are implemented by XPCOM. + * + * Note that this type is not in the mozilla namespace so that it is + * usable for both C and C++ code. + */ +typedef uintptr_t MozRefCountType; + +/* + * This is the return type for AddRef() and Release() in nsISupports. + * IUnknown of COM returns an unsigned long from equivalent functions. + * + * The following ifdef exists to maintain binary compatibility with + * IUnknown, the base interface in Microsoft COM. + */ +#ifdef XP_WIN +typedef unsigned long MozExternalRefCountType; +#else +typedef uint32_t MozExternalRefCountType; +#endif + +#endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RefPtr.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RefPtr.h index 72c7904554..4901067b4c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RefPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RefPtr.h @@ -12,7 +12,17 @@ #include "mozilla/Assertions.h" #include "mozilla/Atomics.h" #include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" +#include "mozilla/RefCountType.h" #include "mozilla/TypeTraits.h" +#if defined(MOZILLA_INTERNAL_API) +#include "nsXPCOM.h" +#endif + +#if defined(MOZILLA_INTERNAL_API) && \ + (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) +#define MOZ_REFCOUNTED_LEAK_CHECKING +#endif namespace mozilla { @@ -42,10 +52,37 @@ template OutParamRef byRef(RefPtr&); * state is represented in DEBUG builds by refcount==0xffffdead. This * state distinguishes use-before-ref (refcount==0) from * use-after-destroy (refcount==0xffffdead). + * + * Note that when deriving from RefCounted or AtomicRefCounted, you + * should add MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public + * section of your class, where ClassName is the name of your class. */ namespace detail { #ifdef DEBUG -static const int DEAD = 0xffffdead; +const MozRefCountType DEAD = 0xffffdead; +#endif + +// When building code that gets compiled into Gecko, try to use the +// trace-refcount leak logging facilities. +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +class RefCountLogger +{ +public: + static void logAddRef(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName, uint32_t aInstanceSize) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogAddRef(const_cast(aPointer), aRefCount, aTypeName, + aInstanceSize); + } + + static void logRelease(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogRelease(const_cast(aPointer), aRefCount, aTypeName); + } +}; #endif // This is used WeakPtr.h as well as this file. @@ -58,70 +95,122 @@ enum RefCountAtomicity template class RefCounted { - friend class RefPtr; + friend class RefPtr; - protected: - RefCounted() : refCnt(0) { } - ~RefCounted() { - MOZ_ASSERT(refCnt == detail::DEAD); - } +protected: + RefCounted() : mRefCnt(0) {} + ~RefCounted() { MOZ_ASSERT(mRefCnt == detail::DEAD); } - public: - // Compatibility with nsRefPtr. - void AddRef() const { - MOZ_ASSERT(refCnt >= 0); - ++refCnt; - } +public: + // Compatibility with nsRefPtr. + void AddRef() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) >= 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + ++mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + uint32_t size = static_cast(this)->typeSize(); + const void* ptr = static_cast(this); + MozRefCountType cnt = ++mRefCnt; + detail::RefCountLogger::logAddRef(ptr, cnt, type, size); +#endif + } - void Release() const { - MOZ_ASSERT(refCnt > 0); - if (0 == --refCnt) { + void Release() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) > 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + MozRefCountType cnt = --mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + const void* ptr = static_cast(this); + MozRefCountType cnt = --mRefCnt; + // Note: it's not safe to touch |this| after decrementing the refcount, + // except for below. + detail::RefCountLogger::logRelease(ptr, cnt, type); +#endif + if (0 == cnt) { + // Because we have atomically decremented the refcount above, only + // one thread can get a 0 count here, so as long as we can assume that + // everything else in the system is accessing this object through + // RefPtrs, it's safe to access |this| here. #ifdef DEBUG - refCnt = detail::DEAD; + mRefCnt = detail::DEAD; #endif - delete static_cast(this); - } + delete static_cast(this); } + } - // Compatibility with wtf::RefPtr. - void ref() { AddRef(); } - void deref() { Release(); } - int refCount() const { return refCnt; } - bool hasOneRef() const { - MOZ_ASSERT(refCnt > 0); - return refCnt == 1; - } + // Compatibility with wtf::RefPtr. + void ref() { AddRef(); } + void deref() { Release(); } + MozRefCountType refCount() const { return mRefCnt; } + bool hasOneRef() const + { + MOZ_ASSERT(mRefCnt > 0); + return mRefCnt == 1; + } - private: - mutable typename Conditional, int>::Type refCnt; +private: + mutable typename Conditional, + MozRefCountType>::Type mRefCnt; }; -} +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) \ + virtual const char* typeName() const { return #T; } \ + virtual size_t typeSize() const { return sizeof(*this); } +#else +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) +#endif + +// Note that this macro is expanded unconditionally because it declares only +// two small inline functions which will hopefully get eliminated by the linker +// in non-leak-checking builds. +#define MOZ_DECLARE_REFCOUNTED_TYPENAME(T) \ + const char* typeName() const { return #T; } \ + size_t typeSize() const { return sizeof(*this); } + +} // namespace detail template class RefCounted : public detail::RefCounted { - public: - ~RefCounted() { - static_assert(IsBaseOf::value, - "T must derive from RefCounted"); - } +public: + ~RefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from RefCounted"); + } }; +namespace external { + /** * AtomicRefCounted is like RefCounted, with an atomically updated * reference counter. + * + * NOTE: Please do not use this class, use NS_INLINE_DECL_THREADSAFE_REFCOUNTING + * instead. */ template -class AtomicRefCounted : public detail::RefCounted +class AtomicRefCounted : + public mozilla::detail::RefCounted { - public: - ~AtomicRefCounted() { - static_assert(IsBaseOf::value, - "T must derive from AtomicRefCounted"); - } +public: + ~AtomicRefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from AtomicRefCounted"); + } }; +} // namespace external + /** * RefPtr points to a refcounted thing that has AddRef and Release * methods to increase/decrease the refcount, respectively. After a @@ -135,73 +224,83 @@ class AtomicRefCounted : public detail::RefCounted template class RefPtr { - // To allow them to use unref() - friend class TemporaryRef; - friend class OutParamRef; + // To allow them to use unref() + friend class TemporaryRef; + friend class OutParamRef; - struct DontRef {}; + struct DontRef {}; - public: - RefPtr() : ptr(0) { } - RefPtr(const RefPtr& o) : ptr(ref(o.ptr)) {} - RefPtr(const TemporaryRef& o) : ptr(o.drop()) {} - RefPtr(T* t) : ptr(ref(t)) {} +public: + RefPtr() : mPtr(0) {} + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.mPtr)) {} + MOZ_IMPLICIT RefPtr(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + MOZ_IMPLICIT RefPtr(T* aVal) : mPtr(ref(aVal)) {} - template - RefPtr(const RefPtr& o) : ptr(ref(o.get())) {} + template + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.get())) {} - ~RefPtr() { unref(ptr); } + ~RefPtr() { unref(mPtr); } - RefPtr& operator=(const RefPtr& o) { - assign(ref(o.ptr)); - return *this; - } - RefPtr& operator=(const TemporaryRef& o) { - assign(o.drop()); - return *this; - } - RefPtr& operator=(T* t) { - assign(ref(t)); - return *this; - } + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.mPtr)); + return *this; + } + RefPtr& operator=(const TemporaryRef& aOther) + { + assign(aOther.drop()); + return *this; + } + RefPtr& operator=(T* aVal) + { + assign(ref(aVal)); + return *this; + } - template - RefPtr& operator=(const RefPtr& o) { - assign(ref(o.get())); - return *this; - } + template + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.get())); + return *this; + } - TemporaryRef forget() { - T* tmp = ptr; - ptr = 0; - return TemporaryRef(tmp, DontRef()); - } + TemporaryRef forget() + { + T* tmp = mPtr; + mPtr = nullptr; + return TemporaryRef(tmp, DontRef()); + } - T* get() const { return ptr; } - operator T*() const { return ptr; } - T* operator->() const { return ptr; } - T& operator*() const { return *ptr; } - template - operator TemporaryRef() { return TemporaryRef(ptr); } - - private: - void assign(T* t) { - unref(ptr); - ptr = t; - } + T* get() const { return mPtr; } + operator T*() const { return mPtr; } + T* operator->() const { return mPtr; } + T& operator*() const { return *mPtr; } + template + operator TemporaryRef() { return TemporaryRef(mPtr); } + +private: + void assign(T* aVal) + { + unref(mPtr); + mPtr = aVal; + } - T* ptr; + T* mPtr; - static MOZ_ALWAYS_INLINE T* ref(T* t) { - if (t) - t->AddRef(); - return t; + static MOZ_ALWAYS_INLINE T* ref(T* aVal) + { + if (aVal) { + aVal->AddRef(); } + return aVal; + } - static MOZ_ALWAYS_INLINE void unref(T* t) { - if (t) - t->Release(); + static MOZ_ALWAYS_INLINE void unref(T* aVal) + { + if (aVal) { + aVal->Release(); } + } }; /** @@ -213,33 +312,34 @@ class RefPtr template class TemporaryRef { - // To allow it to construct TemporaryRef from a bare T* - friend class RefPtr; + // To allow it to construct TemporaryRef from a bare T* + friend class RefPtr; - typedef typename RefPtr::DontRef DontRef; + typedef typename RefPtr::DontRef DontRef; - public: - TemporaryRef(T* t) : ptr(RefPtr::ref(t)) {} - TemporaryRef(const TemporaryRef& o) : ptr(o.drop()) {} +public: + MOZ_IMPLICIT TemporaryRef(T* aVal) : mPtr(RefPtr::ref(aVal)) {} + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} - template - TemporaryRef(const TemporaryRef& o) : ptr(o.drop()) {} + template + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} - ~TemporaryRef() { RefPtr::unref(ptr); } + ~TemporaryRef() { RefPtr::unref(mPtr); } - T* drop() const { - T* tmp = ptr; - ptr = 0; - return tmp; - } + T* drop() const + { + T* tmp = mPtr; + mPtr = nullptr; + return tmp; + } - private: - TemporaryRef(T* t, const DontRef&) : ptr(t) {} +private: + TemporaryRef(T* aVal, const DontRef&) : mPtr(aVal) {} - mutable T* ptr; + mutable T* mPtr; - TemporaryRef() MOZ_DELETE; - void operator=(const TemporaryRef&) MOZ_DELETE; + TemporaryRef() MOZ_DELETE; + void operator=(const TemporaryRef&) MOZ_DELETE; }; /** @@ -259,24 +359,25 @@ class TemporaryRef template class OutParamRef { - friend OutParamRef byRef(RefPtr&); + friend OutParamRef byRef(RefPtr&); - public: - ~OutParamRef() { - RefPtr::unref(refPtr.ptr); - refPtr.ptr = tmp; - } +public: + ~OutParamRef() + { + RefPtr::unref(mRefPtr.mPtr); + mRefPtr.mPtr = mTmp; + } - operator T**() { return &tmp; } + operator T**() { return &mTmp; } - private: - OutParamRef(RefPtr& p) : refPtr(p), tmp(p.get()) {} +private: + explicit OutParamRef(RefPtr& p) : mRefPtr(p), mTmp(p.get()) {} - RefPtr& refPtr; - T* tmp; + RefPtr& mRefPtr; + T* mTmp; - OutParamRef() MOZ_DELETE; - OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; + OutParamRef() MOZ_DELETE; + OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; }; /** @@ -284,9 +385,9 @@ class OutParamRef */ template OutParamRef -byRef(RefPtr& ptr) +byRef(RefPtr& aPtr) { - return OutParamRef(ptr); + return OutParamRef(aPtr); } } // namespace mozilla @@ -301,19 +402,21 @@ using namespace mozilla; struct Foo : public RefCounted { - Foo() : dead(false) { } - ~Foo() { - MOZ_ASSERT(!dead); - dead = true; - numDestroyed++; + MOZ_DECLARE_REFCOUNTED_TYPENAME(Foo) + Foo() : mDead(false) {} + ~Foo() + { + MOZ_ASSERT(!mDead); + mDead = true; + sNumDestroyed++; } - bool dead; - static int numDestroyed; + bool mDead; + static int sNumDestroyed; }; -int Foo::numDestroyed; +int Foo::sNumDestroyed; -struct Bar : public Foo { }; +struct Bar : public Foo {}; TemporaryRef NewFoo() @@ -364,25 +467,25 @@ main(int argc, char** argv) // This should blow up // Foo* f = new Foo(); delete f; - MOZ_ASSERT(0 == Foo::numDestroyed); + MOZ_ASSERT(0 == Foo::sNumDestroyed); { RefPtr f = new Foo(); MOZ_ASSERT(f->refCount() == 1); } - MOZ_ASSERT(1 == Foo::numDestroyed); + MOZ_ASSERT(1 == Foo::sNumDestroyed); { RefPtr f1 = NewFoo(); RefPtr f2(NewFoo()); - MOZ_ASSERT(1 == Foo::numDestroyed); + MOZ_ASSERT(1 == Foo::sNumDestroyed); } - MOZ_ASSERT(3 == Foo::numDestroyed); + MOZ_ASSERT(3 == Foo::sNumDestroyed); { RefPtr b = NewBar(); - MOZ_ASSERT(3 == Foo::numDestroyed); + MOZ_ASSERT(3 == Foo::sNumDestroyed); } - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); { RefPtr f1; @@ -390,56 +493,56 @@ main(int argc, char** argv) f1 = new Foo(); RefPtr f2(f1); RefPtr f3 = f2; - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); } - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); } - MOZ_ASSERT(5 == Foo::numDestroyed); + MOZ_ASSERT(5 == Foo::sNumDestroyed); { RefPtr f = new Foo(); f.forget(); - MOZ_ASSERT(6 == Foo::numDestroyed); + MOZ_ASSERT(6 == Foo::sNumDestroyed); } { RefPtr f = new Foo(); GetNewFoo(byRef(f)); - MOZ_ASSERT(7 == Foo::numDestroyed); + MOZ_ASSERT(7 == Foo::sNumDestroyed); } - MOZ_ASSERT(8 == Foo::numDestroyed); + MOZ_ASSERT(8 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetPassedFoo(byRef(f)); - MOZ_ASSERT(8 == Foo::numDestroyed); + MOZ_ASSERT(8 == Foo::sNumDestroyed); } - MOZ_ASSERT(9 == Foo::numDestroyed); + MOZ_ASSERT(9 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetNewFoo(&f); - MOZ_ASSERT(10 == Foo::numDestroyed); + MOZ_ASSERT(10 == Foo::sNumDestroyed); } - MOZ_ASSERT(11 == Foo::numDestroyed); + MOZ_ASSERT(11 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetPassedFoo(&f); - MOZ_ASSERT(11 == Foo::numDestroyed); + MOZ_ASSERT(11 == Foo::sNumDestroyed); } - MOZ_ASSERT(12 == Foo::numDestroyed); + MOZ_ASSERT(12 == Foo::sNumDestroyed); { RefPtr f1 = new Bar(); } - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); { RefPtr f = GetNullFoo(); - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); } - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); return 0; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RollingMean.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RollingMean.h index 5caee3bc83..5add14c879 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RollingMean.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/RollingMean.h @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-w idth: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -12,9 +13,7 @@ #include "mozilla/TypeTraits.h" #include "mozilla/Vector.h" -#include #include -#include namespace mozilla { @@ -30,78 +29,85 @@ namespace mozilla { template class RollingMean { - private: - size_t mInsertIndex; - size_t mMaxValues; - Vector mValues; - S mTotal; - - public: - static_assert(!IsFloatingPoint::value, - "floating-point types are unsupported due to rounding " - "errors"); - - RollingMean(size_t aMaxValues) - : mInsertIndex(0), - mMaxValues(aMaxValues), - mTotal(0) - { - MOZ_ASSERT(aMaxValues > 0); - } - - RollingMean& operator=(RollingMean&& aOther) { - MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); - this->~RollingMean(); - new(this) RollingMean(aOther.mMaxValues); - mInsertIndex = aOther.mInsertIndex; - mTotal = aOther.mTotal; - mValues.swap(aOther.mValues); - return *this; - } - - /** - * Insert a value into the rolling mean. - */ - bool insert(T aValue) { - MOZ_ASSERT(mValues.length() <= mMaxValues); - - if (mValues.length() == mMaxValues) { - mTotal = mTotal - mValues[mInsertIndex] + aValue; - mValues[mInsertIndex] = aValue; - } else { - if (!mValues.append(aValue)) - return false; - mTotal = mTotal + aValue; +private: + size_t mInsertIndex; + size_t mMaxValues; + Vector mValues; + S mTotal; + +public: + static_assert(!IsFloatingPoint::value, + "floating-point types are unsupported due to rounding " + "errors"); + + explicit RollingMean(size_t aMaxValues) + : mInsertIndex(0), + mMaxValues(aMaxValues), + mTotal(0) + { + MOZ_ASSERT(aMaxValues > 0); + } + + RollingMean& operator=(RollingMean&& aOther) + { + MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); + this->~RollingMean(); + new(this) RollingMean(aOther.mMaxValues); + mInsertIndex = aOther.mInsertIndex; + mTotal = aOther.mTotal; + mValues.swap(aOther.mValues); + return *this; + } + + /** + * Insert a value into the rolling mean. + */ + bool insert(T aValue) + { + MOZ_ASSERT(mValues.length() <= mMaxValues); + + if (mValues.length() == mMaxValues) { + mTotal = mTotal - mValues[mInsertIndex] + aValue; + mValues[mInsertIndex] = aValue; + } else { + if (!mValues.append(aValue)) { + return false; } - - mInsertIndex = (mInsertIndex + 1) % mMaxValues; - return true; - } - - /** - * Calculate the rolling mean. - */ - T mean() { - MOZ_ASSERT(!empty()); - return T(mTotal / mValues.length()); - } - - bool empty() { - return mValues.empty(); + mTotal = mTotal + aValue; } - /** - * Remove all values from the rolling mean. - */ - void clear() { - mValues.clear(); - mInsertIndex = 0; - mTotal = T(0); - } - - size_t maxValues() { - return mMaxValues; - } + mInsertIndex = (mInsertIndex + 1) % mMaxValues; + return true; + } + + /** + * Calculate the rolling mean. + */ + T mean() + { + MOZ_ASSERT(!empty()); + return T(mTotal / mValues.length()); + } + + bool empty() + { + return mValues.empty(); + } + + /** + * Remove all values from the rolling mean. + */ + void clear() + { + mValues.clear(); + mInsertIndex = 0; + mTotal = T(0); + } + + size_t maxValues() + { + return mMaxValues; + } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/SHA1.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/SHA1.h index b167648540..ddccaa67e7 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/SHA1.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/SHA1.h @@ -36,25 +36,26 @@ namespace mozilla { */ class SHA1Sum { - union { - uint32_t w[16]; /* input buffer */ - uint8_t b[64]; - } u; - uint64_t size; /* count of hashed bytes. */ - unsigned H[22]; /* 5 state variables, 16 tmp values, 1 extra */ - bool mDone; - - public: - MFBT_API SHA1Sum(); - - static const size_t HashSize = 20; - typedef uint8_t Hash[HashSize]; - - /* Add len bytes of dataIn to the data sequence being hashed. */ - MFBT_API void update(const void* dataIn, uint32_t len); - - /* Compute the final hash of all data into hashOut. */ - MFBT_API void finish(SHA1Sum::Hash& hashOut); + union + { + uint32_t mW[16]; /* input buffer */ + uint8_t mB[64]; + } mU; + uint64_t mSize; /* count of hashed bytes. */ + unsigned mH[22]; /* 5 state variables, 16 tmp values, 1 extra */ + bool mDone; + +public: + MFBT_API SHA1Sum(); + + static const size_t kHashSize = 20; + typedef uint8_t Hash[kHashSize]; + + /* Add len bytes of dataIn to the data sequence being hashed. */ + MFBT_API void update(const void* aData, uint32_t aLength); + + /* Compute the final hash of all data into hashOut. */ + MFBT_API void finish(SHA1Sum::Hash& aHashOut); }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Scoped.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Scoped.h index fc48584b3e..3f854d6375 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Scoped.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Scoped.h @@ -52,8 +52,10 @@ * the scope, graphics contexts, etc. */ +#include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/GuardObjects.h" +#include "mozilla/Move.h" #include "mozilla/NullPtr.h" namespace mozilla { @@ -62,7 +64,8 @@ namespace mozilla { * Scoped is a helper to create RAII wrappers * Type argument |Traits| is expected to have the following structure: * - * struct Traits { + * struct Traits + * { * // Define the type of the value stored in the wrapper * typedef value_type type; * // Returns the value corresponding to the uninitialized or freed state @@ -75,84 +78,102 @@ namespace mozilla { template class Scoped { - public: - typedef typename Traits::type Resource; +public: + typedef typename Traits::type Resource; - explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) - : value(Traits::empty()) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - explicit Scoped(const Resource& v - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : value(v) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - ~Scoped() { - Traits::release(value); - } + explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + : mValue(Traits::empty()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } - // Constant getter - operator const Resource&() const { return value; } - const Resource& operator->() const { return value; } - const Resource& get() const { return value; } - // Non-constant getter. - Resource& rwget() { return value; } + explicit Scoped(const Resource& aValue + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(aValue) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } - /* - * Forget the resource. - * - * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will - * have no effect at destruction (unless it is reset to another resource by - * |operator=|). - * - * @return The original resource. - */ - Resource forget() { - Resource tmp = value; - value = Traits::empty(); - return tmp; - } + /* Move constructor. */ + explicit Scoped(Scoped&& aOther + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(Move(aOther.mValue)) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + aOther.mValue = Traits::empty(); + } - /* - * Perform immediate clean-up of this |Scoped|. - * - * If this |Scoped| is currently empty, this method has no effect. - */ - void dispose() { - Traits::release(value); - value = Traits::empty(); - } + ~Scoped() { Traits::release(mValue); } - bool operator==(const Resource& other) const { - return value == other; - } + // Constant getter + operator const Resource&() const { return mValue; } + const Resource& operator->() const { return mValue; } + const Resource& get() const { return mValue; } + // Non-constant getter. + Resource& rwget() { return mValue; } - /* - * Replace the resource with another resource. - * - * Calling |operator=| has the side-effect of triggering clean-up. If you do - * not want to trigger clean-up, you should first invoke |forget|. - * - * @return this - */ - Scoped& operator=(const Resource& other) { - return reset(other); - } - Scoped& reset(const Resource& other) { - Traits::release(value); - value = other; - return *this; - } + /* + * Forget the resource. + * + * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will + * have no effect at destruction (unless it is reset to another resource by + * |operator=|). + * + * @return The original resource. + */ + Resource forget() + { + Resource tmp = mValue; + mValue = Traits::empty(); + return tmp; + } + + /* + * Perform immediate clean-up of this |Scoped|. + * + * If this |Scoped| is currently empty, this method has no effect. + */ + void dispose() + { + Traits::release(mValue); + mValue = Traits::empty(); + } + + bool operator==(const Resource& aOther) const { return mValue == aOther; } + + /* + * Replace the resource with another resource. + * + * Calling |operator=| has the side-effect of triggering clean-up. If you do + * not want to trigger clean-up, you should first invoke |forget|. + * + * @return this + */ + Scoped& operator=(const Resource& aOther) { return reset(aOther); } + + Scoped& reset(const Resource& aOther) + { + Traits::release(mValue); + mValue = aOther; + return *this; + } + + /* Move assignment operator. */ + Scoped& operator=(Scoped&& aRhs) + { + MOZ_ASSERT(&aRhs != this, "self-move-assignment not allowed"); + this->~Scoped(); + new(this) Scoped(Move(aRhs)); + return *this; + } - private: - explicit Scoped(const Scoped& value) MOZ_DELETE; - Scoped& operator=(const Scoped& value) MOZ_DELETE; +private: + explicit Scoped(const Scoped& aValue) MOZ_DELETE; + Scoped& operator=(const Scoped& aValue) MOZ_DELETE; - private: - Resource value; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +private: + Resource mValue; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER }; /* @@ -163,26 +184,38 @@ class Scoped * @param Traits A struct implementing clean-up. See the implementations * for more details. */ -#define SCOPED_TEMPLATE(name, Traits) \ -template \ -struct name : public mozilla::Scoped > \ -{ \ - typedef mozilla::Scoped > Super; \ - typedef typename Super::Resource Resource; \ - name& operator=(Resource ptr) { \ - Super::operator=(ptr); \ - return *this; \ - } \ - explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ - : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ - {} \ - explicit name(Resource ptr \ - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ - : Super(ptr MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ - {} \ - private: \ - explicit name(name& source) MOZ_DELETE; \ - name& operator=(name& source) MOZ_DELETE; \ +#define SCOPED_TEMPLATE(name, Traits) \ +template \ +struct name : public mozilla::Scoped > \ +{ \ + typedef mozilla::Scoped > Super; \ + typedef typename Super::Resource Resource; \ + name& operator=(Resource aRhs) \ + { \ + Super::operator=(aRhs); \ + return *this; \ + } \ + name& operator=(name&& aRhs) \ + { \ + Super::operator=(Move(aRhs)); \ + return *this; \ + } \ + explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ + : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ + {} \ + explicit name(Resource aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ + explicit name(name&& aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(Move(aRhs) \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ +private: \ + explicit name(name&) MOZ_DELETE; \ + name& operator=(name&) MOZ_DELETE; \ }; /* @@ -195,9 +228,9 @@ struct name : public mozilla::Scoped > \ template struct ScopedFreePtrTraits { - typedef T* type; - static T* empty() { return nullptr; } - static void release(T* ptr) { free(ptr); } + typedef T* type; + static T* empty() { return nullptr; } + static void release(T* aPtr) { free(aPtr); } }; SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) @@ -210,7 +243,7 @@ SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) template struct ScopedDeletePtrTraits : public ScopedFreePtrTraits { - static void release(T* ptr) { delete ptr; } + static void release(T* aPtr) { delete aPtr; } }; SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) @@ -223,7 +256,7 @@ SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) template struct ScopedDeleteArrayTraits : public ScopedFreePtrTraits { - static void release(T* ptr) { delete [] ptr; } + static void release(T* aPtr) { delete [] aPtr; } }; SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) @@ -250,21 +283,22 @@ SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) * } // file is closed with PR_Close here */ #define MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(name, Type, Deleter) \ -template <> inline void TypeSpecificDelete(Type * value) { Deleter(value); } \ +template <> inline void TypeSpecificDelete(Type* aValue) { Deleter(aValue); } \ typedef ::mozilla::TypeSpecificScopedPointer name; -template void TypeSpecificDelete(T * value); +template void TypeSpecificDelete(T* aValue); template struct TypeSpecificScopedPointerTraits { - typedef T* type; - const static type empty() { return nullptr; } - const static void release(type value) - { - if (value) - TypeSpecificDelete(value); + typedef T* type; + static type empty() { return nullptr; } + static void release(type aValue) + { + if (aValue) { + TypeSpecificDelete(aValue); } + } }; SCOPED_TEMPLATE(TypeSpecificScopedPointer, TypeSpecificScopedPointerTraits) diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/SplayTree.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/SplayTree.h index 58ba5432b6..a6d692266f 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/SplayTree.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/SplayTree.h @@ -23,18 +23,20 @@ class SplayTree; template class SplayTreeNode { - public: - template - friend class SplayTree; - - SplayTreeNode() - : left(nullptr), right(nullptr), parent(nullptr) - {} - - private: - T* left; - T* right; - T* parent; +public: + template + friend class SplayTree; + + SplayTreeNode() + : mLeft(nullptr) + , mRight(nullptr) + , mParent(nullptr) + {} + +private: + T* mLeft; + T* mRight; + T* mParent; }; @@ -51,232 +53,242 @@ class SplayTreeNode template class SplayTree { - T* root; - T* freeList; + T* mRoot; - public: - SplayTree() - : root(nullptr), freeList(nullptr) - {} - - bool empty() const { - return !root; - } +public: + SplayTree() + : mRoot(nullptr) + {} - T* find(const T& v) - { - if (empty()) - return nullptr; + bool empty() const + { + return !mRoot; + } - T* last = lookup(v); - splay(last); - checkCoherency(root, nullptr); - return Comparator::compare(v, *last) == 0 ? last : nullptr; + T* find(const T& aValue) + { + if (empty()) { + return nullptr; } - bool insert(T* v) - { - MOZ_ASSERT(!find(*v), "Duplicate elements are not allowed."); - - if (!root) { - root = v; - return true; - } - T* last = lookup(*v); - int cmp = Comparator::compare(*v, *last); + T* last = lookup(aValue); + splay(last); + checkCoherency(mRoot, nullptr); + return Comparator::compare(aValue, *last) == 0 ? last : nullptr; + } - T** parentPointer = (cmp < 0) ? &last->left : &last->right; - MOZ_ASSERT(!*parentPointer); - *parentPointer = v; - v->parent = last; + bool insert(T* aValue) + { + MOZ_ASSERT(!find(*aValue), "Duplicate elements are not allowed."); - splay(v); - checkCoherency(root, nullptr); + if (!mRoot) { + mRoot = aValue; return true; } - - T* remove(const T& v) - { - T* last = lookup(v); - MOZ_ASSERT(last, "This tree must contain the element being removed."); - MOZ_ASSERT(Comparator::compare(v, *last) == 0); - - // Splay the tree so that the item to remove is the root. - splay(last); - MOZ_ASSERT(last == root); - - // Find another node which can be swapped in for the root: either the - // rightmost child of the root's left, or the leftmost child of the - // root's right. - T* swap; - T* swapChild; - if (root->left) { - swap = root->left; - while (swap->right) - swap = swap->right; - swapChild = swap->left; - } else if (root->right) { - swap = root->right; - while (swap->left) - swap = swap->left; - swapChild = swap->right; - } else { - T* result = root; - root = nullptr; - return result; - } - - // The selected node has at most one child, in swapChild. Detach it - // from the subtree by replacing it with that child. - if (swap == swap->parent->left) - swap->parent->left = swapChild; - else - swap->parent->right = swapChild; - if (swapChild) - swapChild->parent = swap->parent; - - // Make the selected node the new root. - root = swap; - root->parent = nullptr; - root->left = last->left; - root->right = last->right; - if (root->left) { - root->left->parent = root; + T* last = lookup(*aValue); + int cmp = Comparator::compare(*aValue, *last); + + T** parentPointer = (cmp < 0) ? &last->mLeft : &last->mRight; + MOZ_ASSERT(!*parentPointer); + *parentPointer = aValue; + aValue->mParent = last; + + splay(aValue); + checkCoherency(mRoot, nullptr); + return true; + } + + T* remove(const T& aValue) + { + T* last = lookup(aValue); + MOZ_ASSERT(last, "This tree must contain the element being removed."); + MOZ_ASSERT(Comparator::compare(aValue, *last) == 0); + + // Splay the tree so that the item to remove is the root. + splay(last); + MOZ_ASSERT(last == mRoot); + + // Find another node which can be swapped in for the root: either the + // rightmost child of the root's left, or the leftmost child of the + // root's right. + T* swap; + T* swapChild; + if (mRoot->mLeft) { + swap = mRoot->mLeft; + while (swap->mRight) { + swap = swap->mRight; } - if (root->right) { - root->right->parent = root; + swapChild = swap->mLeft; + } else if (mRoot->mRight) { + swap = mRoot->mRight; + while (swap->mLeft) { + swap = swap->mLeft; } - - checkCoherency(root, nullptr); - return last; + swapChild = swap->mRight; + } else { + T* result = mRoot; + mRoot = nullptr; + return result; } - T* removeMin() - { - MOZ_ASSERT(root, "No min to remove!"); - - T* min = root; - while (min->left) - min = min->left; - return remove(*min); + // The selected node has at most one child, in swapChild. Detach it + // from the subtree by replacing it with that child. + if (swap == swap->mParent->mLeft) { + swap->mParent->mLeft = swapChild; + } else { + swap->mParent->mRight = swapChild; } - - private: - /** - * Returns the node in this comparing equal to |v|, or a node just greater or - * just less than |v| if there is no such node. - */ - T* lookup(const T& v) - { - MOZ_ASSERT(!empty()); - - T* node = root; - T* parent; - do { - parent = node; - int c = Comparator::compare(v, *node); - if (c == 0) - return node; - else if (c < 0) - node = node->left; - else - node = node->right; - } while (node); - return parent; + if (swapChild) { + swapChild->mParent = swap->mParent; } - /** - * Rotate the tree until |node| is at the root of the tree. Performing - * the rotations in this fashion preserves the amortized balancing of - * the tree. - */ - void splay(T* node) - { - MOZ_ASSERT(node); - - while (node != root) { - T* parent = node->parent; - if (parent == root) { - // Zig rotation. - rotate(node); - MOZ_ASSERT(node == root); - return; - } - T* grandparent = parent->parent; - if ((parent->left == node) == (grandparent->left == parent)) { - // Zig-zig rotation. - rotate(parent); - rotate(node); - } else { - // Zig-zag rotation. - rotate(node); - rotate(node); - } - } + // Make the selected node the new root. + mRoot = swap; + mRoot->mParent = nullptr; + mRoot->mLeft = last->mLeft; + mRoot->mRight = last->mRight; + if (mRoot->mLeft) { + mRoot->mLeft->mParent = mRoot; } + if (mRoot->mRight) { + mRoot->mRight->mParent = mRoot; + } + + checkCoherency(mRoot, nullptr); + return last; + } - void rotate(T* node) - { - // Rearrange nodes so that node becomes the parent of its current - // parent, while preserving the sortedness of the tree. - T* parent = node->parent; - if (parent->left == node) { - // x y - // y c ==> a x - // a b b c - parent->left = node->right; - if (node->right) - node->right->parent = parent; - node->right = parent; + T* removeMin() + { + MOZ_ASSERT(mRoot, "No min to remove!"); + + T* min = mRoot; + while (min->mLeft) { + min = min->mLeft; + } + return remove(*min); + } + +private: + /** + * Returns the node in this comparing equal to |aValue|, or a node just + * greater or just less than |aValue| if there is no such node. + */ + T* lookup(const T& aValue) + { + MOZ_ASSERT(!empty()); + + T* node = mRoot; + T* parent; + do { + parent = node; + int c = Comparator::compare(aValue, *node); + if (c == 0) { + return node; + } else if (c < 0) { + node = node->mLeft; } else { - MOZ_ASSERT(parent->right == node); - // x y - // a y ==> x c - // b c a b - parent->right = node->left; - if (node->left) - node->left->parent = parent; - node->left = parent; + node = node->mRight; } - node->parent = parent->parent; - parent->parent = node; - if (T* grandparent = node->parent) { - if (grandparent->left == parent) - grandparent->left = node; - else - grandparent->right = node; + } while (node); + return parent; + } + + /** + * Rotate the tree until |node| is at the root of the tree. Performing + * the rotations in this fashion preserves the amortized balancing of + * the tree. + */ + void splay(T* aNode) + { + MOZ_ASSERT(aNode); + + while (aNode != mRoot) { + T* parent = aNode->mParent; + if (parent == mRoot) { + // Zig rotation. + rotate(aNode); + MOZ_ASSERT(aNode == mRoot); + return; + } + T* grandparent = parent->mParent; + if ((parent->mLeft == aNode) == (grandparent->mLeft == parent)) { + // Zig-zig rotation. + rotate(parent); + rotate(aNode); } else { - root = node; + // Zig-zag rotation. + rotate(aNode); + rotate(aNode); } } - - T* checkCoherency(T* node, T* minimum) - { -#ifdef DEBUG - MOZ_ASSERT_IF(root, !root->parent); - if (!node) { - MOZ_ASSERT(!root); - return nullptr; + } + + void rotate(T* aNode) + { + // Rearrange nodes so that aNode becomes the parent of its current + // parent, while preserving the sortedness of the tree. + T* parent = aNode->mParent; + if (parent->mLeft == aNode) { + // x y + // y c ==> a x + // a b b c + parent->mLeft = aNode->mRight; + if (aNode->mRight) { + aNode->mRight->mParent = parent; } - MOZ_ASSERT_IF(!node->parent, node == root); - MOZ_ASSERT_IF(minimum, Comparator::compare(*minimum, *node) < 0); - if (node->left) { - MOZ_ASSERT(node->left->parent == node); - T* leftMaximum = checkCoherency(node->left, minimum); - MOZ_ASSERT(Comparator::compare(*leftMaximum, *node) < 0); + aNode->mRight = parent; + } else { + MOZ_ASSERT(parent->mRight == aNode); + // x y + // a y ==> x c + // b c a b + parent->mRight = aNode->mLeft; + if (aNode->mLeft) { + aNode->mLeft->mParent = parent; } - if (node->right) { - MOZ_ASSERT(node->right->parent == node); - return checkCoherency(node->right, node); + aNode->mLeft = parent; + } + aNode->mParent = parent->mParent; + parent->mParent = aNode; + if (T* grandparent = aNode->mParent) { + if (grandparent->mLeft == parent) { + grandparent->mLeft = aNode; + } else { + grandparent->mRight = aNode; } - return node; -#else + } else { + mRoot = aNode; + } + } + + T* checkCoherency(T* aNode, T* aMinimum) + { +#ifdef DEBUG + MOZ_ASSERT_IF(mRoot, !mRoot->mParent); + if (!aNode) { + MOZ_ASSERT(!mRoot); return nullptr; -#endif } + MOZ_ASSERT_IF(!aNode->mParent, aNode == mRoot); + MOZ_ASSERT_IF(aMinimum, Comparator::compare(*aMinimum, *aNode) < 0); + if (aNode->mLeft) { + MOZ_ASSERT(aNode->mLeft->mParent == aNode); + T* leftMaximum = checkCoherency(aNode->mLeft, aMinimum); + MOZ_ASSERT(Comparator::compare(*leftMaximum, *aNode) < 0); + } + if (aNode->mRight) { + MOZ_ASSERT(aNode->mRight->mParent == aNode); + return checkCoherency(aNode->mRight, aNode); + } + return aNode; +#else + return nullptr; +#endif + } - SplayTree(const SplayTree&) MOZ_DELETE; - void operator=(const SplayTree&) MOZ_DELETE; + SplayTree(const SplayTree&) MOZ_DELETE; + void operator=(const SplayTree&) MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TaggedAnonymousMemory.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TaggedAnonymousMemory.h new file mode 100644 index 0000000000..d26b06dfb4 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TaggedAnonymousMemory.h @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Some Linux kernels -- specifically, newer versions of Android and +// some B2G devices -- have a feature for assigning names to ranges of +// anonymous memory (i.e., memory that doesn't have a "name" in the +// form of an underlying mapped file). These names are reported in +// /proc//smaps alongside system-level memory usage information +// such as Proportional Set Size (memory usage adjusted for sharing +// between processes), which allows reporting this information at a +// finer granularity than would otherwise be possible (e.g., +// separating malloc() heap from JS heap). +// +// Existing memory can be tagged with MozTagAnonymousMemory(); it will +// tag the range of complete pages containing the given interval, so +// the results may be inexact if the range isn't page-aligned. +// MozTaggedAnonymousMmap() can be used like mmap() with an extra +// parameter, and will tag the returned memory if the mapping was +// successful (and if it was in fact anonymous). +// +// NOTE: The pointer given as the "tag" argument MUST remain valid as +// long as the mapping exists. The referenced string is read when +// /proc//smaps or /proc//maps is read, not when the tag is +// established, so freeing it or changing its contents will have +// unexpected results. Using a static string is probably best. +// +// Also note that this header can be used by both C and C++ code. + +#ifndef mozilla_TaggedAnonymousMemory_h +#define mozilla_TaggedAnonymousMemory_h + +#ifndef XP_WIN + +#include +#include + +#include "mozilla/Types.h" + +#ifdef ANDROID + +#ifdef __cplusplus +extern "C" { +#endif + +MFBT_API void +MozTagAnonymousMemory(const void* aPtr, size_t aLength, const char* aTag); + +MFBT_API void* +MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt, int aFlags, + int aFd, off_t aOffset, const char* aTag); + +MFBT_API int +MozTaggedMemoryIsSupported(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#else // ANDROID + +static inline void +MozTagAnonymousMemory(const void* aPtr, size_t aLength, const char* aTag) +{ +} + +static inline void* +MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt, int aFlags, + int aFd, off_t aOffset, const char* aTag) +{ + return mmap(aAddr, aLength, aProt, aFlags, aFd, aOffset); +} + +static inline int +MozTaggedMemoryIsSupported(void) +{ + return 0; +} + +#endif // ANDROID + +#endif // !XP_WIN + +#endif // mozilla_TaggedAnonymousMemory_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TemplateLib.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TemplateLib.h index 50275fdadb..ea12c18b2b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TemplateLib.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TemplateLib.h @@ -28,19 +28,19 @@ namespace tl { template struct Min { - static const size_t value = I < J ? I : J; + static const size_t value = I < J ? I : J; }; template struct Max { - static const size_t value = I > J ? I : J; + static const size_t value = I > J ? I : J; }; /** Compute floor(log2(i)). */ template struct FloorLog2 { - static const size_t value = 1 + FloorLog2::value; + static const size_t value = 1 + FloorLog2::value; }; template<> struct FloorLog2<0> { /* Error */ }; template<> struct FloorLog2<1> { static const size_t value = 0; }; @@ -49,26 +49,26 @@ template<> struct FloorLog2<1> { static const size_t value = 0; }; template struct CeilingLog2 { - static const size_t value = FloorLog2<2 * I - 1>::value; + static const size_t value = FloorLog2<2 * I - 1>::value; }; /** Round up to the nearest power of 2. */ template struct RoundUpPow2 { - static const size_t value = size_t(1) << CeilingLog2::value; + static const size_t value = size_t(1) << CeilingLog2::value; }; template<> struct RoundUpPow2<0> { - static const size_t value = 1; + static const size_t value = 1; }; /** Compute the number of bits in the given unsigned type. */ template struct BitSize { - static const size_t value = sizeof(T) * CHAR_BIT; + static const size_t value = sizeof(T) * CHAR_BIT; }; /** @@ -78,17 +78,18 @@ struct BitSize template struct NBitMask { - // Assert the precondition. On success this evaluates to 0. Otherwise it - // triggers divide-by-zero at compile time: a guaranteed compile error in - // C++11, and usually one in C++98. Add this value to |value| to assure - // its computation. - static const size_t checkPrecondition = 0 / size_t(N < BitSize::value); - static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; + // Assert the precondition. On success this evaluates to 0. Otherwise it + // triggers divide-by-zero at compile time: a guaranteed compile error in + // C++11, and usually one in C++98. Add this value to |value| to assure + // its computation. + static const size_t checkPrecondition = + 0 / size_t(N < BitSize::value); + static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; }; template<> struct NBitMask::value> { - static const size_t value = size_t(-1); + static const size_t value = size_t(-1); }; /** @@ -98,8 +99,8 @@ struct NBitMask::value> template struct MulOverflowMask { - static const size_t value = - ~NBitMask::value - CeilingLog2::value>::value; + static const size_t value = + ~NBitMask::value - CeilingLog2::value>::value; }; template<> struct MulOverflowMask<0> { /* Error */ }; template<> struct MulOverflowMask<1> { static const size_t value = 0; }; diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ThreadLocal.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ThreadLocal.h index 6df109821f..28015de22e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ThreadLocal.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ThreadLocal.h @@ -54,7 +54,10 @@ typedef sig_atomic_t sig_safe_t; * * API usage: * - * // Create a TLS item + * // Create a TLS item. + * // + * // Note that init() should be invoked exactly once, before any usage of set() + * // or get(). * mozilla::ThreadLocal tlsKey; * if (!tlsKey.init()) { * // deal with the error @@ -70,30 +73,29 @@ template class ThreadLocal { #if defined(XP_WIN) - typedef unsigned long key_t; + typedef unsigned long key_t; #else - typedef pthread_key_t key_t; + typedef pthread_key_t key_t; #endif - union Helper { - void* ptr; - T value; - }; + union Helper + { + void* mPtr; + T mValue; + }; - public: - MOZ_WARN_UNUSED_RESULT inline bool init(); +public: + MOZ_WARN_UNUSED_RESULT inline bool init(); - inline T get() const; + inline T get() const; - inline void set(const T value); + inline void set(const T aValue); - bool initialized() const { - return inited; - } + bool initialized() const { return mInited; } - private: - key_t key; - bool inited; +private: + key_t mKey; + bool mInited; }; template @@ -105,12 +107,12 @@ ThreadLocal::init() "a pointer"); MOZ_ASSERT(!initialized()); #ifdef XP_WIN - key = TlsAlloc(); - inited = key != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES + mKey = TlsAlloc(); + mInited = mKey != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES #else - inited = !pthread_key_create(&key, nullptr); + mInited = !pthread_key_create(&mKey, nullptr); #endif - return inited; + return mInited; } template @@ -120,28 +122,28 @@ ThreadLocal::get() const MOZ_ASSERT(initialized()); Helper h; #ifdef XP_WIN - h.ptr = TlsGetValue(key); + h.mPtr = TlsGetValue(mKey); #else - h.ptr = pthread_getspecific(key); + h.mPtr = pthread_getspecific(mKey); #endif - return h.value; + return h.mValue; } template inline void -ThreadLocal::set(const T value) +ThreadLocal::set(const T aValue) { MOZ_ASSERT(initialized()); Helper h; - h.value = value; - bool succeeded; + h.mValue = aValue; #ifdef XP_WIN - succeeded = TlsSetValue(key, h.ptr); + bool succeeded = TlsSetValue(mKey, h.mPtr); #else - succeeded = !pthread_setspecific(key, h.ptr); + bool succeeded = !pthread_setspecific(mKey, h.mPtr); #endif - if (!succeeded) + if (!succeeded) { MOZ_CRASH(); + } } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ToString.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ToString.h new file mode 100644 index 0000000000..f11cad5cb6 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/ToString.h @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Utilities for converting an object to a string representation. */ + +#ifndef mozilla_ToString_h +#define mozilla_ToString_h + +#include +#include + +namespace mozilla { + +/** + * A convenience function for converting an object to a string representation. + * Supports any object which can be streamed to an std::ostream. + */ +template +std::string +ToString(const T& aValue) +{ + std::ostringstream stream; + stream << aValue; + return stream.str(); +} + +} // namespace mozilla + +#endif /* mozilla_ToString_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TypeTraits.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TypeTraits.h index 1ccd0c85d1..515c68d94e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TypeTraits.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TypeTraits.h @@ -9,6 +9,8 @@ #ifndef mozilla_TypeTraits_h #define mozilla_TypeTraits_h +#include "mozilla/Types.h" + /* * These traits are approximate copies of the traits and semantics from C++11's * header. Don't add traits not in that header! When all @@ -32,9 +34,9 @@ template struct RemoveCV; template struct IntegralConstant { - static const T value = Value; - typedef T ValueType; - typedef IntegralConstant Type; + static const T value = Value; + typedef T ValueType; + typedef IntegralConstant Type; }; /** Convenient aliases. */ @@ -47,6 +49,27 @@ typedef IntegralConstant FalseType; namespace detail { +template +struct IsVoidHelper : FalseType {}; + +template<> +struct IsVoidHelper : TrueType {}; + +} // namespace detail + +/** + * IsVoid determines whether a type is void. + * + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true; + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true. + */ +template +struct IsVoid : detail::IsVoidHelper::Type> {}; + +namespace detail { + template struct IsIntegralHelper : FalseType {}; @@ -114,6 +137,31 @@ struct IsFloatingPoint : detail::IsFloatingPointHelper::Type> {}; +namespace detail { + +template +struct IsArrayHelper : FalseType {}; + +template +struct IsArrayHelper : TrueType {}; + +template +struct IsArrayHelper : TrueType {}; + +} // namespace detail + +/** + * IsArray determines whether a type is an array type, of known or unknown + * length. + * + * mozilla::IsArray::value is false; + * mozilla::IsArray::value is true; + * mozilla::IsArray::value is true. + */ +template +struct IsArray : detail::IsArrayHelper::Type> +{}; + /** * IsPointer determines whether a type is a pointer type (but not a pointer-to- * member type). @@ -130,6 +178,40 @@ struct IsPointer : FalseType {}; template struct IsPointer : TrueType {}; +/** + * IsLvalueReference determines whether a type is an lvalue reference. + * + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is true; + * mozilla::IsLvalueReference::value is false. + */ +template +struct IsLvalueReference : FalseType {}; + +template +struct IsLvalueReference : TrueType {}; + +/** + * IsRvalueReference determines whether a type is an rvalue reference. + * + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is true. + */ +template +struct IsRvalueReference : FalseType {}; + +template +struct IsRvalueReference : TrueType {}; + namespace detail { // __is_enum is a supported extension across all of our supported compilers. @@ -152,8 +234,55 @@ struct IsEnum : detail::IsEnumHelper::Type> {}; +namespace detail { + +// __is_class is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx +template +struct IsClassHelper + : IntegralConstant +{}; + +} // namespace detail + +/** + * IsClass determines whether a type is a class type (but not a union). + * + * struct S {}; + * union U {}; + * mozilla::IsClass::value is false; + * mozilla::IsClass::value is true; + * mozilla::IsClass::value is false; + */ +template +struct IsClass + : detail::IsClassHelper::Type> +{}; + /* 20.9.4.2 Composite type traits [meta.unary.comp] */ +/** + * IsReference determines whether a type is an lvalue or rvalue reference. + * + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true. + */ +template +struct IsReference + : IntegralConstant::value || IsRvalueReference::value> +{}; + /** * IsArithmetic determines whether a type is arithmetic. A type is arithmetic * iff it is an integral type or a floating point type. @@ -228,26 +357,90 @@ template struct IsPod : TrueType {}; namespace detail { -template::value> -struct IsSignedHelper; - +// __is_empty is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx template -struct IsSignedHelper : TrueType {}; +struct IsEmptyHelper + : IntegralConstant::value && __is_empty(T)> +{}; +} // namespace detail + +/** + * IsEmpty determines whether a type is a class (but not a union) that is empty. + * + * A class is empty iff it and all its base classes have no non-static data + * members (except bit-fields of length 0) and no virtual member functions, and + * no base class is empty or a virtual base class. + * + * Intuitively, empty classes don't have any data that has to be stored in + * instances of those classes. (The size of the class must still be non-zero, + * because distinct array elements of any type must have different addresses. + * However, if the Empty Base Optimization is implemented by the compiler [most + * compilers implement it, and in certain cases C++11 requires it], the size of + * a class inheriting from an empty |Base| class need not be inflated by + * |sizeof(Base)|.) And intuitively, non-empty classes have data members and/or + * vtable pointers that must be stored in each instance for proper behavior. + * + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * union U1 { int x; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct E1 {}; + * struct E2 { int : 0 }; + * struct E3 : E1 {}; + * struct E4 : E2 {}; + * static_assert(mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value, + * "all empty"); + * union U2 { E1 e1; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct NE1 { int x; }; + * struct NE2 : virtual E1 {}; + * struct NE3 : E2 { virtual ~NE3() {} }; + * struct NE4 { virtual void f() {} }; + * static_assert(!mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value, + * "all empty"); + */ template -struct IsSignedHelper - : IntegralConstant::value && T(-1) < T(1)> +struct IsEmpty : detail::IsEmptyHelper::Type> {}; + +namespace detail { + +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> +struct IsSignedHelper; + +// Floating point is signed. +template +struct IsSignedHelper : TrueType {}; + +// Integral is conditionally signed. +template +struct IsSignedHelper + : IntegralConstant +{}; + +// Non-floating point, non-integral is not signed. +template +struct IsSignedHelper : FalseType {}; + } // namespace detail /** * IsSigned determines whether a type is a signed arithmetic type. |char| is * considered a signed type if it has the same representation as |signed char|. * - * Don't use this if the type might be user-defined! You might or might not get - * a compile error, depending. - * * mozilla::IsSigned::value is true; * mozilla::IsSigned::value is false; * mozilla::IsSigned::value is false; @@ -258,28 +451,32 @@ struct IsSigned : detail::IsSignedHelper {}; namespace detail { -template::value> +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> struct IsUnsignedHelper; -template -struct IsUnsignedHelper : FalseType {}; +// Floating point is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; -template -struct IsUnsignedHelper +// Integral is conditionally unsigned. +template +struct IsUnsignedHelper : IntegralConstant::value && - (IsSame::Type, bool>::value || - T(1) < T(-1))> + (IsSame::value || bool(NoCV(1) < NoCV(-1)))> {}; +// Non-floating point, non-integral is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; + } // namespace detail /** * IsUnsigned determines whether a type is an unsigned arithmetic type. * - * Don't use this if the type might be user-defined! You might or might not get - * a compile error, depending. - * * mozilla::IsUnsigned::value is false; * mozilla::IsUnsigned::value is true; * mozilla::IsUnsigned::value is true; @@ -310,6 +507,13 @@ struct IsSame : TrueType {}; namespace detail { +#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) + +template +struct BaseOfTester : IntegralConstant {}; + +#else + // The trickery used to implement IsBaseOf here makes it possible to use it for // the cases of private and multiple inheritance. This code was inspired by the // sample code here: @@ -318,35 +522,35 @@ namespace detail { template struct BaseOfHelper { - public: - operator Base*() const; - operator Derived*(); +public: + operator Base*() const; + operator Derived*(); }; template struct BaseOfTester { - private: - template - static char test(Derived*, T); - static int test(Base*, int); - - public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); }; template struct BaseOfTester { - private: - template - static char test(Derived*, T); - static int test(Base*, int); - - public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); }; template @@ -358,6 +562,8 @@ struct BaseOfTester : TrueType {}; template struct BaseOfTester : TrueType {}; +#endif + } /* namespace detail */ /* @@ -382,18 +588,18 @@ namespace detail { template struct ConvertibleTester { - private: - static From create(); +private: + static From create(); - template - static char test(To to); + template + static char test(To to); - template - static int test(...); + template + static int test(...); - public: - static const bool value = - sizeof(test(create())) == sizeof(char); +public: + static const bool value = + sizeof(test(create())) == sizeof(char); }; } // namespace detail @@ -424,16 +630,6 @@ struct IsConvertible : IntegralConstant::value> {}; -/** - * Is IsLvalueReference is true if its template param is T& and is false if - * its type is T or T&&. - */ -template -struct IsLvalueReference : FalseType {}; - -template -struct IsLvalueReference : TrueType {}; - /* 20.9.7 Transformations between types [meta.trans] */ /* 20.9.7.1 Const-volatile modifications [meta.trans.cv] */ @@ -449,13 +645,13 @@ struct IsLvalueReference : TrueType {}; template struct RemoveConst { - typedef T Type; + typedef T Type; }; template struct RemoveConst { - typedef T Type; + typedef T Type; }; /** @@ -469,13 +665,13 @@ struct RemoveConst template struct RemoveVolatile { - typedef T Type; + typedef T Type; }; template struct RemoveVolatile { - typedef T Type; + typedef T Type; }; /** @@ -489,7 +685,7 @@ struct RemoveVolatile template struct RemoveCV { - typedef typename RemoveConst::Type>::Type Type; + typedef typename RemoveConst::Type>::Type Type; }; /* 20.9.7.2 Reference modifications [meta.trans.ref] */ @@ -505,29 +701,69 @@ struct RemoveCV template struct RemoveReference { - typedef T Type; + typedef T Type; }; template struct RemoveReference { - typedef T Type; + typedef T Type; }; template struct RemoveReference { - typedef T Type; + typedef T Type; }; +template +struct Conditional; + +namespace detail { + +enum Voidness { TIsVoid, TIsNotVoid }; + +template::value ? TIsVoid : TIsNotVoid> +struct AddLvalueReferenceHelper; + +template +struct AddLvalueReferenceHelper +{ + typedef void Type; +}; + +template +struct AddLvalueReferenceHelper +{ + typedef T& Type; +}; + +} // namespace detail + +/** + * AddLvalueReference adds an lvalue & reference to T if one isn't already + * present. (Note: adding an lvalue reference to an rvalue && reference in + * essence replaces the && with a &&, per C+11 reference collapsing rules. For + * example, int&& would become int&.) + * + * The final computed type will only *not* be an lvalue reference if T is void. + * + * mozilla::AddLvalueReference::Type is int&; + * mozilla::AddLvalueRference::Type is volatile int&; + * mozilla::AddLvalueReference::Type is void*&; + * mozilla::AddLvalueReference::Type is void; + * mozilla::AddLvalueReference::Type is struct S&. + */ +template +struct AddLvalueReference + : detail::AddLvalueReferenceHelper +{}; + /* 20.9.7.3 Sign modifications [meta.trans.sign] */ template struct EnableIf; -template -struct Conditional; - namespace detail { template @@ -568,7 +804,7 @@ struct MakeSigned; template struct MakeSigned { - typedef T Type; + typedef T Type; }; template @@ -603,7 +839,8 @@ struct MakeSigned */ template struct MakeSigned - : EnableIf::value && !IsSame::Type>::value, + : EnableIf::value && + !IsSame::Type>::value, typename detail::MakeSigned >::Type {}; @@ -636,7 +873,7 @@ struct MakeUnsigned; template struct MakeUnsigned { - typedef T Type; + typedef T Type; }; template @@ -671,13 +908,41 @@ struct MakeUnsigned */ template struct MakeUnsigned - : EnableIf::value && !IsSame::Type>::value, + : EnableIf::value && + !IsSame::Type>::value, typename detail::MakeUnsigned >::Type {}; /* 20.9.7.4 Array modifications [meta.trans.arr] */ +/** + * RemoveExtent produces either the type of the elements of the array T, or T + * itself. + * + * mozilla::RemoveExtent::Type is int; + * mozilla::RemoveExtent::Type is const int; + * mozilla::RemoveExtent::Type is volatile int; + * mozilla::RemoveExtent::Type is long[17]. + */ +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + /* 20.9.7.5 Pointer modifications [meta.trans.ptr] */ /* 20.9.7.6 Other transformations [meta.trans.other] */ @@ -707,7 +972,7 @@ struct EnableIf template struct EnableIf { - typedef T Type; + typedef T Type; }; /** @@ -719,13 +984,13 @@ struct EnableIf template struct Conditional { - typedef A Type; + typedef A Type; }; template struct Conditional { - typedef B Type; + typedef B Type; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TypedEnum.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TypedEnum.h index e55365abb8..d84cd90257 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TypedEnum.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TypedEnum.h @@ -9,39 +9,11 @@ #ifndef mozilla_TypedEnum_h #define mozilla_TypedEnum_h -#include "mozilla/Attributes.h" +#include "mozilla/TypedEnumInternal.h" +#include "mozilla/MacroArgs.h" #if defined(__cplusplus) -#if defined(__clang__) - /* - * Per Clang documentation, "Note that marketing version numbers should not - * be used to check for language features, as different vendors use different - * numbering schemes. Instead, use the feature checking macros." - */ -# ifndef __has_extension -# define __has_extension __has_feature /* compatibility, for older versions of clang */ -# endif -# if __has_extension(cxx_strong_enums) -# define MOZ_HAVE_CXX11_ENUM_TYPE -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -#elif defined(__GNUC__) -# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L -# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3) -# define MOZ_HAVE_CXX11_ENUM_TYPE -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -# endif -#elif defined(_MSC_VER) -# if _MSC_VER >= 1400 -# define MOZ_HAVE_CXX11_ENUM_TYPE -# endif -# if _MSC_VER >= 1700 -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -#endif - /** * MOZ_ENUM_TYPE specifies the underlying numeric type for an enum. It's * specified by placing MOZ_ENUM_TYPE(type) immediately after the enum name in @@ -97,13 +69,12 @@ * in namespace scope to handle bits that can only be implemented with * namespace-scoped code. For example: * - * class FooBar { - * + * class FooBar + * { * MOZ_BEGIN_NESTED_ENUM_CLASS(Enum, int32_t) * A, * B = 6 * MOZ_END_NESTED_ENUM_CLASS(Enum) - * * }; * * MOZ_FINISH_NESTED_ENUM_CLASS(FooBar::Enum) @@ -131,6 +102,10 @@ * these are already integer types so there is nothing more to do. */ # define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name + /* + * See the comment below about MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) Name #else /** * We need Name to both name a type, and scope the provided enumerator @@ -172,24 +147,28 @@ # define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER1(Name) \ class Name \ { \ - public: \ - enum Enum \ - { + public: \ + enum Enum \ + { /* Two-argument form. */ # define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER2(Name, type) \ class Name \ { \ - public: \ - enum Enum MOZ_ENUM_TYPE(type) \ - { + public: \ + enum Enum MOZ_ENUM_TYPE(type) \ + { # define MOZ_END_NESTED_ENUM_CLASS(Name) \ - }; \ - Name() {} \ - Name(Enum aEnum) : mEnum(aEnum) {} \ - explicit Name(int num) : mEnum((Enum)num) {} \ - operator Enum() const { return mEnum; } \ - private: \ - Enum mEnum; \ + }; \ + Name() {} \ + MOZ_CONSTEXPR Name(Enum aEnum) : mEnum(aEnum) {} \ + template \ + explicit MOZ_CONSTEXPR Name(Other num) : mEnum((Enum)num) {} \ + MOZ_CONSTEXPR operator Enum() const { return mEnum; } \ + explicit MOZ_CONSTEXPR Name(const mozilla::CastableTypedEnumResult& aOther) \ + : mEnum(aOther.get()) \ + {} \ + private: \ + Enum mEnum; \ }; # define MOZ_FINISH_NESTED_ENUM_CLASS(Name) \ inline int operator+(const int&, const Name::Enum&) MOZ_DELETE; \ @@ -225,7 +204,6 @@ inline bool operator&&(const Name::Enum&, const bool&) MOZ_DELETE; \ inline bool operator||(const bool&, const Name::Enum&) MOZ_DELETE; \ inline bool operator||(const Name::Enum&, const bool&) MOZ_DELETE; \ - inline int operator~(const Name::Enum&) MOZ_DELETE; \ inline int operator&(const int&, const Name::Enum&) MOZ_DELETE; \ inline int operator&(const Name::Enum&, const int&) MOZ_DELETE; \ inline int operator|(const int&, const Name::Enum&) MOZ_DELETE; \ @@ -253,35 +231,45 @@ * In the present case, the integer type is the Enum nested type. */ # define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name::Enum + /* + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is a variant of MOZ_ENUM_CLASS_ENUM_TYPE + * to be used when the enum class at hand depends on template parameters. + * + * Indeed, if T depends on template parameters, in order to name a nested type + * in T, C++ does not allow to just write "T::NestedType". Instead, we have + * to write "typename T::NestedType". The role of this macro is to add + * this "typename" keywords where needed. + * + * Example: + * + * template + * struct S {}; + * + * MOZ_BEGIN_ENUM_CLASS(E) + * Foo, + * Bar + * MOZ_END_ENUM_CLASS(E) + * + * S s; + * + * In this example, the second template parameter to S is meant to be of type + * T, but on non-C++11 compilers, type T is a class type, not an integer + * type, so it is not accepted as the type of a constant template parameter. + * One would then want to use MOZ_ENUM_CLASS_ENUM_TYPE(T), but that doesn't + * work either as T depends on template parameters (more specifically here, T + * _is_ a template parameter) so as MOZ_ENUM_CLASS_ENUM_TYPE(T) expands to + * T::Enum, we are missing the required "typename" keyword. So here, + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is needed. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) typename Name::Enum #endif - /* - * Count the number of arguments passed to MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS, - * very carefully tiptoeing around an MSVC bug where it improperly expands - * __VA_ARGS__ as a single token in argument lists. See these URLs for - * details: - * - * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement - * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 - */ -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL2(_1, _2, count, ...) \ - count -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL(args) \ - MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL2 args -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS(...) \ - MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL((__VA_ARGS__, 2, 1, 0)) - /* Pick the right helper macro to invoke. */ -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER2(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER##count -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER1(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER2(count) -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER1(count) - /* The actual macro. */ -# define MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(x, y) x y +# define MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(a, b) a b # define MOZ_BEGIN_NESTED_ENUM_CLASS(...) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER(MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS(__VA_ARGS__)), \ - (__VA_ARGS__)) + MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER, \ + __VA_ARGS__), \ + (__VA_ARGS__)) # define MOZ_BEGIN_ENUM_CLASS(...) MOZ_BEGIN_NESTED_ENUM_CLASS(__VA_ARGS__) # define MOZ_END_ENUM_CLASS(Name) \ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TypedEnumBits.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TypedEnumBits.h new file mode 100644 index 0000000000..1f439f1239 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TypedEnumBits.h @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS allows using a typed enum as bit flags. + */ + +#ifndef mozilla_TypedEnumBits_h +#define mozilla_TypedEnumBits_h + +#include "mozilla/IntegerTypeTraits.h" +#include "mozilla/TypedEnumInternal.h" + +namespace mozilla { + +#define MOZ_CASTABLETYPEDENUMRESULT_BINOP(Op, OtherType, ReturnType) \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const OtherType& aE, const CastableTypedEnumResult& aR) \ +{ \ + return ReturnType(aE Op OtherType(aR)); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR, const OtherType& aE) \ +{ \ + return ReturnType(OtherType(aR) Op aE); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR1, \ + const CastableTypedEnumResult& aR2) \ +{ \ + return ReturnType(OtherType(aR1) Op OtherType(aR2)); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_BINOP(|, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(&, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(^, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(==, E, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(!=, E, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(||, bool, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(&&, bool, bool) + +template +MOZ_CONSTEXPR CastableTypedEnumResult +operator ~(const CastableTypedEnumResult& aR) +{ + return CastableTypedEnumResult(~(E(aR))); +} + +#define MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(Op) \ +template \ +E& \ +operator Op(E& aR1, \ + const CastableTypedEnumResult& aR2) \ +{ \ + return aR1 Op E(aR2); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(&=) +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(|=) +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(^=) + +#undef MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP + +#undef MOZ_CASTABLETYPEDENUMRESULT_BINOP + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS + +#define MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(Op, ReturnType) \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(typename E::Enum aE, const CastableTypedEnumResult& aR) \ +{ \ + return ReturnType(aE Op E(aR)); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR, typename E::Enum aE) \ +{ \ + return ReturnType(E(aR) Op aE); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(|, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(&, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(^, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(==, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(!=, bool) + +#undef MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11 + +#endif // not MOZ_HAVE_CXX11_STRONG_ENUMS + +namespace detail { +template +struct UnsignedIntegerTypeForEnum + : UnsignedStdintTypeForSize +{}; +} + +} // namespace mozilla + +#define MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, Op) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name a, Name b) \ + { \ + typedef mozilla::CastableTypedEnumResult Result; \ + typedef mozilla::detail::UnsignedIntegerTypeForEnum::Type U; \ + return Result(Name(U(a) Op U(b))); \ + } \ + \ + inline Name& \ + operator Op##=(Name& a, Name b) \ + { \ + return a = a Op b; \ + } + +#define MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, |) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, &) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, ^) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator~(Name a) \ + { \ + typedef mozilla::CastableTypedEnumResult Result; \ + typedef mozilla::detail::UnsignedIntegerTypeForEnum::Type U; \ + return Result(Name(~(U(a)))); \ + } + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS +# define MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, Op) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name a, Name::Enum b) \ + { \ + return a Op Name(b); \ + } \ + \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name::Enum a, Name b) \ + { \ + return Name(a) Op b; \ + } \ + \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name::Enum a, Name::Enum b) \ + { \ + return Name(a) Op Name(b); \ + } \ + \ + inline Name& \ + operator Op##=(Name& a, Name::Enum b) \ + { \ + return a = a Op Name(b); \ + } + +# define MOZ_MAKE_ENUM_CLASS_OPS_EXTRA_NON_CXX11(Name) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, |) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, &) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, ^) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator~(Name::Enum a) \ + { \ + return ~(Name(a)); \ + } +#endif + +/** + * MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS generates standard bitwise operators + * for the given enum type. Use this to enable using an enum type as bit-field. + */ +#ifdef MOZ_HAVE_CXX11_STRONG_ENUMS +# define MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) +#else +# define MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_EXTRA_NON_CXX11(Name) +#endif + +#endif // mozilla_TypedEnumBits_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TypedEnumInternal.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TypedEnumInternal.h new file mode 100644 index 0000000000..8c88cb589b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/TypedEnumInternal.h @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Internal stuff needed by TypedEnum.h and TypedEnumBits.h. */ + +// NOTE: When we can assume C++11 enum class support and TypedEnum.h goes away, +// we should then consider folding TypedEnumInternal.h into TypedEnumBits.h. + +#ifndef mozilla_TypedEnumInternal_h +#define mozilla_TypedEnumInternal_h + +#include "mozilla/Attributes.h" + +#if defined(__cplusplus) + +#if defined(__clang__) + /* + * Per Clang documentation, "Note that marketing version numbers should not + * be used to check for language features, as different vendors use different + * numbering schemes. Instead, use the feature checking macros." + */ +# ifndef __has_extension +# define __has_extension __has_feature /* compatibility, for older versions of clang */ +# endif +# if __has_extension(cxx_strong_enums) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#elif defined(__GNUC__) +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +# endif +#elif defined(_MSC_VER) +# if _MSC_VER >= 1400 +# define MOZ_HAVE_CXX11_ENUM_TYPE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#endif + +namespace mozilla { + +/* + * The problem that CastableTypedEnumResult aims to solve is that + * typed enums are not convertible to bool, and there is no way to make them + * be, yet user code wants to be able to write + * + * if (myFlags & Flags::SOME_PARTICULAR_FLAG) (1) + * + * There are different approaches to solving this. Most of them require + * adapting user code. For example, we could implement operator! and have + * the user write + * + * if (!!(myFlags & Flags::SOME_PARTICULAR_FLAG)) (2) + * + * Or we could supply a IsNonZero() or Any() function returning whether + * an enum value is nonzero, and have the user write + * + * if (Any(Flags & Flags::SOME_PARTICULAR_FLAG)) (3) + * + * But instead, we choose to preserve the original user syntax (1) as it + * is inherently more readable, and to ease porting existing code to typed + * enums. We achieve this by having operator& and other binary bitwise + * operators have as return type a class, CastableTypedEnumResult, + * that wraps a typed enum but adds bool convertibility. + */ +template +class CastableTypedEnumResult +{ +private: + const E mValue; + +public: + explicit MOZ_CONSTEXPR CastableTypedEnumResult(E aValue) + : mValue(aValue) + {} + + MOZ_CONSTEXPR operator E() const { return mValue; } + + template + MOZ_EXPLICIT_CONVERSION MOZ_CONSTEXPR + operator DestinationType() const { return DestinationType(mValue); } + + MOZ_CONSTEXPR bool operator !() const { return !bool(mValue); } + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS + // This get() method is used to implement a constructor in the + // non-c++11 fallback path for MOZ_BEGIN_ENUM_CLASS, taking a + // CastableTypedEnumResult. If we try to implement it using the + // above conversion operator E(), then at least clang 3.3 + // (when forced to take the non-c++11 fallback path) compiles + // this constructor to an infinite recursion. So we introduce this + // get() method, that does exactly the same as the conversion operator, + // to work around this. + MOZ_CONSTEXPR E get() const { return mValue; } +#endif +}; + +} // namespace mozilla + +#endif // __cplusplus + +#endif // mozilla_TypedEnumInternal_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Types.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Types.h index 5340b2b600..e7e18abb27 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Types.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Types.h @@ -37,7 +37,7 @@ * These macros are designed for use by library interfaces -- not for normal * methods or data used cross-file. */ -#if defined(WIN32) || defined(XP_OS2) +#if defined(WIN32) # define MOZ_EXPORT __declspec(dllexport) #else /* Unix */ # ifdef HAVE_VISIBILITY_ATTRIBUTE @@ -63,16 +63,12 @@ # else # define MOZ_IMPORT_API __declspec(dllimport) # endif -#elif defined(XP_OS2) -# define MOZ_IMPORT_API __declspec(dllimport) #else # define MOZ_IMPORT_API MOZ_EXPORT #endif #if defined(_WIN32) && !defined(__MWERKS__) # define MOZ_IMPORT_DATA __declspec(dllimport) -#elif defined(XP_OS2) -# define MOZ_IMPORT_DATA __declspec(dllimport) #else # define MOZ_IMPORT_DATA MOZ_EXPORT #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/UniquePtr.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/UniquePtr.h new file mode 100644 index 0000000000..9c873db90c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/UniquePtr.h @@ -0,0 +1,674 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Smart pointer managing sole ownership of a resource. */ + +#ifndef mozilla_UniquePtr_h +#define mozilla_UniquePtr_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/Pair.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +template class DefaultDelete; +template> class UniquePtr; + +} // namespace mozilla + +namespace mozilla { + +/** + * UniquePtr is a smart pointer that wholly owns a resource. Ownership may be + * transferred out of a UniquePtr through explicit action, but otherwise the + * resource is destroyed when the UniquePtr is destroyed. + * + * UniquePtr is similar to C++98's std::auto_ptr, but it improves upon auto_ptr + * in one crucial way: it's impossible to copy a UniquePtr. Copying an auto_ptr + * obviously *can't* copy ownership of its singly-owned resource. So what + * happens if you try to copy one? Bizarrely, ownership is implicitly + * *transferred*, preserving single ownership but breaking code that assumes a + * copy of an object is identical to the original. (This is why auto_ptr is + * prohibited in STL containers.) + * + * UniquePtr solves this problem by being *movable* rather than copyable. + * Instead of passing a |UniquePtr u| directly to the constructor or assignment + * operator, you pass |Move(u)|. In doing so you indicate that you're *moving* + * ownership out of |u|, into the target of the construction/assignment. After + * the transfer completes, |u| contains |nullptr| and may be safely destroyed. + * This preserves single ownership but also allows UniquePtr to be moved by + * algorithms that have been made move-safe. (Note: if |u| is instead a + * temporary expression, don't use |Move()|: just pass the expression, because + * it's already move-ready. For more information see Move.h.) + * + * UniquePtr is also better than std::auto_ptr in that the deletion operation is + * customizable. An optional second template parameter specifies a class that + * (through its operator()(T*)) implements the desired deletion policy. If no + * policy is specified, mozilla::DefaultDelete is used -- which will either + * |delete| or |delete[]| the resource, depending whether the resource is an + * array. Custom deletion policies ideally should be empty classes (no member + * fields, no member fields in base classes, no virtual methods/inheritance), + * because then UniquePtr can be just as efficient as a raw pointer. + * + * Use of UniquePtr proceeds like so: + * + * UniquePtr g1; // initializes to nullptr + * g1.reset(new int); // switch resources using reset() + * g1 = nullptr; // clears g1, deletes the int + * + * UniquePtr g2(new int); // owns that int + * int* p = g2.release(); // g2 leaks its int -- still requires deletion + * delete p; // now freed + * + * struct S { int x; S(int x) : x(x) {} }; + * UniquePtr g3, g4(new S(5)); + * g3 = Move(g4); // g3 owns the S, g4 cleared + * S* p = g3.get(); // g3 still owns |p| + * assert(g3->x == 5); // operator-> works (if .get() != nullptr) + * assert((*g3).x == 5); // also operator* (again, if not cleared) + * Swap(g3, g4); // g4 now owns the S, g3 cleared + * g3.swap(g4); // g3 now owns the S, g4 cleared + * UniquePtr g5(Move(g3)); // g5 owns the S, g3 cleared + * g5.reset(); // deletes the S, g5 cleared + * + * struct FreePolicy { void operator()(void* p) { free(p); } }; + * UniquePtr g6(static_cast(malloc(sizeof(int)))); + * int* ptr = g6.get(); + * g6 = nullptr; // calls free(ptr) + * + * Now, carefully note a few things you *can't* do: + * + * UniquePtr b1; + * b1 = new int; // BAD: can only assign another UniquePtr + * int* ptr = b1; // BAD: no auto-conversion to pointer, use get() + * + * UniquePtr b2(b1); // BAD: can't copy a UniquePtr + * UniquePtr b3 = b1; // BAD: can't copy-assign a UniquePtr + * + * A few miscellaneous notes: + * + * UniquePtr, when not instantiated for an array type, can be move-constructed + * and move-assigned, not only from itself but from "derived" UniquePtr + * instantiations where U converts to T and E converts to D. If you want to use + * this, you're going to have to specify a deletion policy for both UniquePtr + * instantations, and T pretty much has to have a virtual destructor. In other + * words, this doesn't work: + * + * struct Base { virtual ~Base() {} }; + * struct Derived : Base {}; + * + * UniquePtr b1; + * // BAD: DefaultDelete and DefaultDelete don't interconvert + * UniquePtr d1(Move(b)); + * + * UniquePtr b2; + * UniquePtr> d2(Move(b2)); // okay + * + * UniquePtr is specialized for array types. Specializing with an array type + * creates a smart-pointer version of that array -- not a pointer to such an + * array. + * + * UniquePtr arr(new int[5]); + * arr[0] = 4; + * + * What else is different? Deletion of course uses |delete[]|. An operator[] + * is provided. Functionality that doesn't make sense for arrays is removed. + * The constructors and mutating methods only accept array pointers (not T*, U* + * that converts to T*, or UniquePtr or UniquePtr) or |nullptr|. + * + * It's perfectly okay to return a UniquePtr from a method to assure the related + * resource is properly deleted. You'll need to use |Move()| when returning a + * local UniquePtr. Otherwise you can return |nullptr|, or you can return + * |UniquePtr(ptr)|. + * + * UniquePtr will commonly be a member of a class, with lifetime equivalent to + * that of that class. If you want to expose the related resource, you could + * expose a raw pointer via |get()|, but ownership of a raw pointer is + * inherently unclear. So it's better to expose a |const UniquePtr&| instead. + * This prohibits mutation but still allows use of |get()| when needed (but + * operator-> is preferred). Of course, you can only use this smart pointer as + * long as the enclosing class instance remains live -- no different than if you + * exposed the |get()| raw pointer. + * + * To pass a UniquePtr-managed resource as a pointer, use a |const UniquePtr&| + * argument. To specify an inout parameter (where the method may or may not + * take ownership of the resource, or reset it), or to specify an out parameter + * (where simply returning a |UniquePtr| isn't possible), use a |UniquePtr&| + * argument. To unconditionally transfer ownership of a UniquePtr + * into a method, use a |UniquePtr| argument. To conditionally transfer + * ownership of a resource into a method, should the method want it, use a + * |UniquePtr&&| argument. + */ +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + Pointer& ptr() { return tuple.first(); } + const Pointer& ptr() const { return tuple.first(); } + + DeleterType& del() { return tuple.second(); } + const DeleterType& del() const { return tuple.second(); } + + public: + /** + * Construct a UniquePtr containing |nullptr|. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! Ideally + // you should make deletion use the same function every time, using a + // deleter policy: + // + // // BAD, won't compile with MSVC10, deleter doesn't need to be a + // // variable at all + // typedef void (&FreeSignature)(void*); + // UniquePtr ptr((int*) malloc(sizeof(int)), free); + // + // // GOOD, compiles with MSVC10, deletion behavior statically known and + // // optimizable + // struct DeleteByFreeing + // { + // void operator()(void* ptr) { free(ptr); } + // }; + // + // If deletion really, truly, must be a variable: you might be able to work + // around this with a deleter class that contains the function reference. + // But this workaround is untried and untested, because variable deletion + // behavior really isn't something you should use. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + template + UniquePtr(UniquePtr&& other, + typename EnableIf::Pointer, + Pointer>::value && + !IsArray::value && + (IsReference::value + ? IsSame::value + : IsConvertible::value), + int>::Type dummy = 0) + : tuple(other.release(), Forward(other.getDeleter())) + { + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + template + UniquePtr& operator=(UniquePtr&& other) + { + static_assert(IsConvertible::Pointer, Pointer>::value, + "incompatible UniquePtr pointees"); + static_assert(!IsArray::value, + "can't assign from UniquePtr holding an array"); + + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT n) { + MOZ_ASSERT(n == nullptr); + reset(nullptr); + return *this; + } + + T& operator*() const { return *get(); } + Pointer operator->() const { + MOZ_ASSERT(get(), "dereferencing a UniquePtr containing nullptr"); + return get(); + } + + Pointer get() const { return ptr(); } + + DeleterType& getDeleter() { return del(); } + const DeleterType& getDeleter() const { return del(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = ptr(); + ptr() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = ptr(); + ptr() = p; + if (old != nullptr) + getDeleter()(old); + } + + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +// In case you didn't read the comment by the main definition (you should!): the +// UniquePtr specialization exists to manage array pointers. It deletes +// such pointers using delete[], it will reject construction and modification +// attempts using U* or U[]. Otherwise it works like the normal UniquePtr. +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + public: + /** + * Construct a UniquePtr containing nullptr. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + private: + // delete[] knows how to handle *only* an array of a single class type. For + // delete[] to work correctly, it must know the size of each element, the + // fields and base classes of each element requiring destruction, and so on. + // So forbid all overloads which would end up invoking delete[] on a pointer + // of the wrong type. + template + UniquePtr(U&& u, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! See the + // comment by this constructor in the non-T[] specialization above. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + private: + // Forbidden for the same reasons as stated above. + template + UniquePtr(U&& u, V&& v, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT) { + reset(); + return *this; + } + + T& operator[](decltype(sizeof(int)) i) const { return get()[i]; } + Pointer get() const { return tuple.first(); } + + DeleterType& getDeleter() { return tuple.second(); } + const DeleterType& getDeleter() const { return tuple.second(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = tuple.first(); + tuple.first() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = tuple.first(); + tuple.first() = p; + if (old != nullptr) + tuple.second()(old); + } + + private: + // Kill off all remaining overloads that aren't true nullptr (the overload + // above should handle that) or emulated nullptr (which acts like int/long + // on gcc 4.4/4.5). + template + void reset(U, + typename EnableIf::value && + !IsSame::Type>::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +/** A default deletion policy using plain old operator delete. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + template + DefaultDelete(const DefaultDelete& other, + typename EnableIf::value, + int>::Type dummy = 0) + {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete ptr; + } +}; + +/** A default deletion policy using operator delete[]. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete[] ptr; + } + + private: + template + void operator()(U* ptr) const MOZ_DELETE; +}; + +template +void +Swap(UniquePtr& x, UniquePtr& y) +{ + x.swap(y); +} + +template +bool +operator==(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() == y.get(); +} + +template +bool +operator!=(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() != y.get(); +} + +template +bool +operator==(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator==(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator!=(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +template +bool +operator!=(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +// No operator<, operator>, operator<=, operator>= for now because simplicity. + +namespace detail { + +template +struct UniqueSelector +{ + typedef UniquePtr SingleObject; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr UnknownBound; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr KnownBound; +}; + +} // namespace detail + +// We don't have variadic template support everywhere, so just hard-code arities +// 0-4 for now. If you need more arguments, feel free to add the extra +// overloads. +// +// Beware! Due to lack of true nullptr support in gcc 4.4 and 4.5, passing +// literal nullptr to MakeUnique will not work on some platforms. See Move.h +// for more details. + +template +typename detail::UniqueSelector::SingleObject +MakeUnique() +{ + return UniquePtr(new T()); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1) +{ + return UniquePtr(new T(Forward(a1))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2) +{ + return UniquePtr(new T(Forward(a1), Forward(a2))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4), Forward(a5))); +} + +template +typename detail::UniqueSelector::UnknownBound +MakeUnique(decltype(sizeof(int)) n) +{ + typedef typename RemoveExtent::Type ArrayType; + return UniquePtr(new ArrayType[n]()); +} + +template +typename detail::UniqueSelector::KnownBound +MakeUnique() MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) MOZ_DELETE; + +} // namespace mozilla + +#endif /* mozilla_UniquePtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Vector.h index c67467524f..8540caf476 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Vector.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/Vector.h @@ -39,14 +39,13 @@ namespace detail { /* * Check that the given capacity wastes the minimal amount of space if - * allocated on the heap. This means that cap*sizeof(T) is as close to a - * power-of-two as possible. growStorageBy() is responsible for ensuring - * this. + * allocated on the heap. This means that aCapacity*sizeof(T) is as close to a + * power-of-two as possible. growStorageBy() is responsible for ensuring this. */ template -static bool CapacityHasExcessSpace(size_t cap) +static bool CapacityHasExcessSpace(size_t aCapacity) { - size_t size = cap * sizeof(T); + size_t size = aCapacity * sizeof(T); return RoundUpPow2(size) - size >= sizeof(T); } @@ -57,72 +56,90 @@ static bool CapacityHasExcessSpace(size_t cap) template struct VectorImpl { - /* Destroys constructed objects in the range [begin, end). */ - static inline void destroy(T* begin, T* end) { - for (T* p = begin; p < end; ++p) - p->~T(); + /* Destroys constructed objects in the range [aBegin, aEnd). */ + static inline void destroy(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + p->~T(); } + } - /* Constructs objects in the uninitialized range [begin, end). */ - static inline void initialize(T* begin, T* end) { - for (T* p = begin; p < end; ++p) - new(p) T(); + /* Constructs objects in the uninitialized range [aBegin, aEnd). */ + static inline void initialize(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); } + } - /* - * Copy-constructs objects in the uninitialized range - * [dst, dst+(srcend-srcbeg)) from the range [srcbeg, srcend). - */ - template - static inline void copyConstruct(T* dst, const U* srcbeg, const U* srcend) { - for (const U* p = srcbeg; p < srcend; ++p, ++dst) - new(dst) T(*p); + /* + * Copy-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(*p); } + } - /* - * Move-constructs objects in the uninitialized range - * [dst, dst+(srcend-srcbeg)) from the range [srcbeg, srcend). - */ - template - static inline void moveConstruct(T* dst, U* srcbeg, U* srcend) { - for (U* p = srcbeg; p < srcend; ++p, ++dst) - new(dst) T(Move(*p)); + /* + * Move-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void moveConstruct(T* aDst, U* aSrcStart, U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(Move(*p)); } + } - /* - * Copy-constructs objects in the uninitialized range [dst, dst+n) from the - * same object u. - */ - template - static inline void copyConstructN(T* dst, size_t n, const U& u) { - for (T* end = dst + n; dst < end; ++dst) - new(dst) T(u); + /* + * Copy-constructs objects in the uninitialized range [aDst, aDst+aN) from + * the same object aU. + */ + template + static inline void copyConstructN(T* aDst, size_t aN, const U& aU) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + new(aDst) T(aU); } + } - /* - * Grows the given buffer to have capacity newCap, preserving the objects - * constructed in the range [begin, end) and updating v. Assumes that (1) - * newCap has not overflowed, and (2) multiplying newCap by sizeof(T) will - * not overflow. - */ - static inline bool - growTo(VectorBase& v, size_t newCap) { - MOZ_ASSERT(!v.usingInlineStorage()); - MOZ_ASSERT(!CapacityHasExcessSpace(newCap)); - T* newbuf = reinterpret_cast(v.malloc_(newCap * sizeof(T))); - if (!newbuf) - return false; - T* dst = newbuf; - T* src = v.beginNoCheck(); - for (; src < v.endNoCheck(); ++dst, ++src) - new(dst) T(Move(*src)); - VectorImpl::destroy(v.beginNoCheck(), v.endNoCheck()); - v.free_(v.mBegin); - v.mBegin = newbuf; - /* v.mLength is unchanged. */ - v.mCapacity = newCap; - return true; + /* + * Grows the given buffer to have capacity aNewCap, preserving the objects + * constructed in the range [begin, end) and updating aV. Assumes that (1) + * aNewCap has not overflowed, and (2) multiplying aNewCap by sizeof(T) will + * not overflow. + */ + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + T* newbuf = reinterpret_cast(aV.malloc_(aNewCap * sizeof(T))); + if (!newbuf) { + return false; + } + T* dst = newbuf; + T* src = aV.beginNoCheck(); + for (; src < aV.endNoCheck(); ++dst, ++src) { + new(dst) T(Move(*src)); } + VectorImpl::destroy(aV.beginNoCheck(), aV.endNoCheck()); + aV.free_(aV.mBegin); + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } }; /* @@ -133,58 +150,71 @@ struct VectorImpl template struct VectorImpl { - static inline void destroy(T*, T*) {} - - static inline void initialize(T* begin, T* end) { - /* - * You would think that memset would be a big win (or even break even) - * when we know T is a POD. But currently it's not. This is probably - * because |append| tends to be given small ranges and memset requires - * a function call that doesn't get inlined. - * - * memset(begin, 0, sizeof(T) * (end-begin)); - */ - for (T* p = begin; p < end; ++p) - new(p) T(); - } + static inline void destroy(T*, T*) {} - template - static inline void copyConstruct(T* dst, const U* srcbeg, const U* srcend) { - /* - * See above memset comment. Also, notice that copyConstruct is - * currently templated (T != U), so memcpy won't work without - * requiring T == U. - * - * memcpy(dst, srcbeg, sizeof(T) * (srcend - srcbeg)); - */ - for (const U* p = srcbeg; p < srcend; ++p, ++dst) - *dst = *p; + static inline void initialize(T* aBegin, T* aEnd) + { + /* + * You would think that memset would be a big win (or even break even) + * when we know T is a POD. But currently it's not. This is probably + * because |append| tends to be given small ranges and memset requires + * a function call that doesn't get inlined. + * + * memset(aBegin, 0, sizeof(T) * (aEnd - aBegin)); + */ + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); } + } - template - static inline void moveConstruct(T* dst, const U* srcbeg, const U* srcend) { - copyConstruct(dst, srcbeg, srcend); + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + /* + * See above memset comment. Also, notice that copyConstruct is + * currently templated (T != U), so memcpy won't work without + * requiring T == U. + * + * memcpy(aDst, aSrcStart, sizeof(T) * (aSrcEnd - aSrcStart)); + */ + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + *aDst = *p; } + } - static inline void copyConstructN(T* dst, size_t n, const T& t) { - for (T* end = dst + n; dst < end; ++dst) - *dst = t; + template + static inline void moveConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + copyConstruct(aDst, aSrcStart, aSrcEnd); + } + + static inline void copyConstructN(T* aDst, size_t aN, const T& aT) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + *aDst = aT; } + } - static inline bool - growTo(VectorBase& v, size_t newCap) { - MOZ_ASSERT(!v.usingInlineStorage()); - MOZ_ASSERT(!CapacityHasExcessSpace(newCap)); - size_t oldSize = sizeof(T) * v.mCapacity; - size_t newSize = sizeof(T) * newCap; - T* newbuf = reinterpret_cast(v.realloc_(v.mBegin, oldSize, newSize)); - if (!newbuf) - return false; - v.mBegin = newbuf; - /* v.mLength is unchanged. */ - v.mCapacity = newCap; - return true; + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + size_t oldSize = sizeof(T) * aV.mCapacity; + size_t newSize = sizeof(T) * aNewCap; + T* newbuf = reinterpret_cast(aV.realloc_(aV.mBegin, oldSize, newSize)); + if (!newbuf) { + return false; } + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } }; } // namespace detail @@ -199,368 +229,387 @@ struct VectorImpl template class VectorBase : private AllocPolicy { - /* utilities */ + /* utilities */ - static const bool sElemIsPod = IsPod::value; - typedef detail::VectorImpl Impl; - friend struct detail::VectorImpl; + static const bool kElemIsPod = IsPod::value; + typedef detail::VectorImpl Impl; + friend struct detail::VectorImpl; - bool growStorageBy(size_t incr); - bool convertToHeapStorage(size_t newCap); + bool growStorageBy(size_t aIncr); + bool convertToHeapStorage(size_t aNewCap); - /* magic constants */ + /* magic constants */ - static const int sMaxInlineBytes = 1024; + static const int kMaxInlineBytes = 1024; - /* compute constants */ + /* compute constants */ - /* - * Consider element size to be 1 for buffer sizing if there are 0 inline - * elements. This allows us to compile when the definition of the element - * type is not visible here. - * - * Explicit specialization is only allowed at namespace scope, so in order - * to keep everything here, we use a dummy template parameter with partial - * specialization. - */ - template - struct ElemSize - { - static const size_t value = sizeof(T); - }; - template - struct ElemSize<0, Dummy> - { - static const size_t value = 1; - }; - - static const size_t sInlineCapacity = - tl::Min::value>::value; - - /* Calculate inline buffer size; avoid 0-sized array. */ - static const size_t sInlineBytes = - tl::Max<1, sInlineCapacity * ElemSize::value>::value; - - /* member data */ + /* + * Consider element size to be 1 for buffer sizing if there are 0 inline + * elements. This allows us to compile when the definition of the element + * type is not visible here. + * + * Explicit specialization is only allowed at namespace scope, so in order + * to keep everything here, we use a dummy template parameter with partial + * specialization. + */ + template + struct ElemSize + { + static const size_t value = sizeof(T); + }; + template + struct ElemSize<0, Dummy> + { + static const size_t value = 1; + }; + + static const size_t kInlineCapacity = + tl::Min::value>::value; + + /* Calculate inline buffer size; avoid 0-sized array. */ + static const size_t kInlineBytes = + tl::Max<1, kInlineCapacity * ElemSize::value>::value; + + /* member data */ - /* - * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, - * mBegin + mLength) hold valid constructed T objects. The range [mBegin + - * mLength, mBegin + mCapacity) holds uninitialized memory. The range - * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory - * previously allocated by a call to reserve(). - */ - T* mBegin; + /* + * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, + * mBegin + mLength) hold valid constructed T objects. The range [mBegin + + * mLength, mBegin + mCapacity) holds uninitialized memory. The range + * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory + * previously allocated by a call to reserve(). + */ + T* mBegin; - /* Number of elements in the vector. */ - size_t mLength; + /* Number of elements in the vector. */ + size_t mLength; - /* Max number of elements storable in the vector without resizing. */ - size_t mCapacity; + /* Max number of elements storable in the vector without resizing. */ + size_t mCapacity; #ifdef DEBUG - /* Max elements of reserved or used space in this vector. */ - size_t mReserved; + /* Max elements of reserved or used space in this vector. */ + size_t mReserved; #endif - /* Memory used for inline storage. */ - AlignedStorage storage; + /* Memory used for inline storage. */ + AlignedStorage mStorage; #ifdef DEBUG - friend class ReentrancyGuard; - bool entered; + friend class ReentrancyGuard; + bool mEntered; #endif - /* private accessors */ + /* private accessors */ - bool usingInlineStorage() const { - return mBegin == const_cast(this)->inlineStorage(); - } + bool usingInlineStorage() const + { + return mBegin == const_cast(this)->inlineStorage(); + } - T* inlineStorage() { - return static_cast(storage.addr()); - } + T* inlineStorage() + { + return static_cast(mStorage.addr()); + } - T* beginNoCheck() const { - return mBegin; - } + T* beginNoCheck() const + { + return mBegin; + } - T* endNoCheck() { - return mBegin + mLength; - } + T* endNoCheck() + { + return mBegin + mLength; + } - const T* endNoCheck() const { - return mBegin + mLength; - } + const T* endNoCheck() const + { + return mBegin + mLength; + } #ifdef DEBUG - size_t reserved() const { - MOZ_ASSERT(mReserved <= mCapacity); - MOZ_ASSERT(mLength <= mReserved); - return mReserved; - } + size_t reserved() const + { + MOZ_ASSERT(mReserved <= mCapacity); + MOZ_ASSERT(mLength <= mReserved); + return mReserved; + } #endif - /* Append operations guaranteed to succeed due to pre-reserved space. */ - template void internalAppend(U&& u); - template - void internalAppendAll(const VectorBase& u); - void internalAppendN(const T& t, size_t n); - template void internalAppend(const U* begin, size_t length); + /* Append operations guaranteed to succeed due to pre-reserved space. */ + template void internalAppend(U&& aU); + template + void internalAppendAll(const VectorBase& aU); + void internalAppendN(const T& aT, size_t aN); + template void internalAppend(const U* aBegin, size_t aLength); - public: - static const size_t sMaxInlineStorage = N; +public: + static const size_t sMaxInlineStorage = N; - typedef T ElementType; + typedef T ElementType; - VectorBase(AllocPolicy = AllocPolicy()); - VectorBase(ThisVector&&); /* Move constructor. */ - ThisVector& operator=(ThisVector&&); /* Move assignment. */ - ~VectorBase(); + explicit VectorBase(AllocPolicy = AllocPolicy()); + explicit VectorBase(ThisVector&&); /* Move constructor. */ + ThisVector& operator=(ThisVector&&); /* Move assignment. */ + ~VectorBase(); - /* accessors */ + /* accessors */ - const AllocPolicy& allocPolicy() const { - return *this; - } + const AllocPolicy& allocPolicy() const { return *this; } - AllocPolicy& allocPolicy() { - return *this; - } + AllocPolicy& allocPolicy() { return *this; } - enum { InlineLength = N }; + enum { InlineLength = N }; - size_t length() const { - return mLength; - } + size_t length() const { return mLength; } - bool empty() const { - return mLength == 0; - } + bool empty() const { return mLength == 0; } - size_t capacity() const { - return mCapacity; - } + size_t capacity() const { return mCapacity; } - T* begin() { - MOZ_ASSERT(!entered); - return mBegin; - } + T* begin() + { + MOZ_ASSERT(!mEntered); + return mBegin; + } - const T* begin() const { - MOZ_ASSERT(!entered); - return mBegin; - } + const T* begin() const + { + MOZ_ASSERT(!mEntered); + return mBegin; + } - T* end() { - MOZ_ASSERT(!entered); - return mBegin + mLength; - } + T* end() + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } - const T* end() const { - MOZ_ASSERT(!entered); - return mBegin + mLength; - } + const T* end() const + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } - T& operator[](size_t i) { - MOZ_ASSERT(!entered); - MOZ_ASSERT(i < mLength); - return begin()[i]; - } + T& operator[](size_t aIndex) + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } - const T& operator[](size_t i) const { - MOZ_ASSERT(!entered); - MOZ_ASSERT(i < mLength); - return begin()[i]; - } + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } - T& back() { - MOZ_ASSERT(!entered); - MOZ_ASSERT(!empty()); - return *(end() - 1); - } + T& back() + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } - const T& back() const { - MOZ_ASSERT(!entered); - MOZ_ASSERT(!empty()); - return *(end() - 1); - } + const T& back() const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } - class Range + class Range + { + friend class VectorBase; + T* mCur; + T* mEnd; + Range(T* aCur, T* aEnd) + : mCur(aCur) + , mEnd(aEnd) { - friend class VectorBase; - T* cur_; - T* end_; - Range(T* cur, T* end) : cur_(cur), end_(end) {} - - public: - Range() {} - bool empty() const { return cur_ == end_; } - size_t remain() const { return end_ - cur_; } - T& front() const { return *cur_; } - void popFront() { MOZ_ASSERT(!empty()); ++cur_; } - T popCopyFront() { MOZ_ASSERT(!empty()); return *cur_++; } - }; - - Range all() { - return Range(begin(), end()); + MOZ_ASSERT(aCur <= aEnd); } - /* mutators */ + public: + Range() {} + bool empty() const { return mCur == mEnd; } + size_t remain() const { return PointerRangeSize(mCur, mEnd); } + T& front() const { MOZ_ASSERT(!empty()); return *mCur; } + void popFront() { MOZ_ASSERT(!empty()); ++mCur; } + T popCopyFront() { MOZ_ASSERT(!empty()); return *mCur++; } + }; - /** - * Given that the vector is empty and has no inline storage, grow to - * |capacity|. - */ - bool initCapacity(size_t request); + Range all() { return Range(begin(), end()); } - /** - * If reserve(length() + N) succeeds, the N next appends are guaranteed to - * succeed. - */ - bool reserve(size_t request); + /* mutators */ - /** - * Destroy elements in the range [end() - incr, end()). Does not deallocate - * or unreserve storage for those elements. - */ - void shrinkBy(size_t incr); + /** + * Given that the vector is empty and has no inline storage, grow to + * |capacity|. + */ + bool initCapacity(size_t aRequest); - /** Grow the vector by incr elements. */ - bool growBy(size_t incr); + /** + * If reserve(length() + N) succeeds, the N next appends are guaranteed to + * succeed. + */ + bool reserve(size_t aRequest); - /** Call shrinkBy or growBy based on whether newSize > length(). */ - bool resize(size_t newLength); + /** + * Destroy elements in the range [end() - aIncr, end()). Does not deallocate + * or unreserve storage for those elements. + */ + void shrinkBy(size_t aIncr); - /** - * Increase the length of the vector, but don't initialize the new elements - * -- leave them as uninitialized memory. - */ - bool growByUninitialized(size_t incr); - bool resizeUninitialized(size_t newLength); + /** Grow the vector by aIncr elements. */ + bool growBy(size_t aIncr); - /** Shorthand for shrinkBy(length()). */ - void clear(); + /** Call shrinkBy or growBy based on whether newSize > length(). */ + bool resize(size_t aNewLength); - /** Clears and releases any heap-allocated storage. */ - void clearAndFree(); + /** + * Increase the length of the vector, but don't initialize the new elements + * -- leave them as uninitialized memory. + */ + bool growByUninitialized(size_t aIncr); + bool resizeUninitialized(size_t aNewLength); - /** - * If true, appending |needed| elements won't reallocate elements storage. - * This *doesn't* mean that infallibleAppend may be used! You still must - * reserve the extra space, even if this method indicates that appends won't - * need to reallocate elements storage. - */ - bool canAppendWithoutRealloc(size_t needed) const; + /** Shorthand for shrinkBy(length()). */ + void clear(); - /** Potentially fallible append operations. */ + /** Clears and releases any heap-allocated storage. */ + void clearAndFree(); - /** - * This can take either a T& or a T&&. Given a T&&, it moves |u| into the - * vector, instead of copying it. If it fails, |u| is left unmoved. ("We are - * not amused.") - */ - template bool append(U&& u); + /** + * If true, appending |aNeeded| elements won't reallocate elements storage. + * This *doesn't* mean that infallibleAppend may be used! You still must + * reserve the extra space, even if this method indicates that appends won't + * need to reallocate elements storage. + */ + bool canAppendWithoutRealloc(size_t aNeeded) const; - template - bool appendAll(const VectorBase& u); - bool appendN(const T& t, size_t n); - template bool append(const U* begin, const U* end); - template bool append(const U* begin, size_t length); + /** Potentially fallible append operations. */ - /* - * Guaranteed-infallible append operations for use upon vectors whose - * memory has been pre-reserved. Don't use this if you haven't reserved the - * memory! - */ - template void infallibleAppend(U&& u) { - internalAppend(Forward(u)); - } - void infallibleAppendN(const T& t, size_t n) { - internalAppendN(t, n); - } - template void infallibleAppend(const U* aBegin, const U* aEnd) { - internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); - } - template void infallibleAppend(const U* aBegin, size_t aLength) { - internalAppend(aBegin, aLength); - } + /** + * This can take either a T& or a T&&. Given a T&&, it moves |aU| into the + * vector, instead of copying it. If it fails, |aU| is left unmoved. ("We are + * not amused.") + */ + template bool append(U&& aU); + + template + bool appendAll(const VectorBase& aU); + bool appendN(const T& aT, size_t aN); + template bool append(const U* aBegin, const U* aEnd); + template bool append(const U* aBegin, size_t aLength); - void popBack(); + /* + * Guaranteed-infallible append operations for use upon vectors whose + * memory has been pre-reserved. Don't use this if you haven't reserved the + * memory! + */ + template void infallibleAppend(U&& aU) + { + internalAppend(Forward(aU)); + } + void infallibleAppendN(const T& aT, size_t aN) + { + internalAppendN(aT, aN); + } + template void infallibleAppend(const U* aBegin, const U* aEnd) + { + internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); + } + template void infallibleAppend(const U* aBegin, size_t aLength) + { + internalAppend(aBegin, aLength); + } - T popCopy(); + void popBack(); - /** - * Transfers ownership of the internal buffer used by this vector to the - * caller. (It's the caller's responsibility to properly deallocate this - * buffer, in accordance with this vector's AllocPolicy.) After this call, - * the vector is empty. Since the returned buffer may need to be allocated - * (if the elements are currently stored in-place), the call can fail, - * returning nullptr. - * - * N.B. Although a T*, only the range [0, length()) is constructed. - */ - T* extractRawBuffer(); + T popCopy(); - /** - * Transfer ownership of an array of objects into the vector. The caller - * must have allocated the array in accordance with this vector's - * AllocPolicy. - * - * N.B. This call assumes that there are no uninitialized elements in the - * passed array. - */ - void replaceRawBuffer(T* p, size_t length); + /** + * Transfers ownership of the internal buffer used by this vector to the + * caller. (It's the caller's responsibility to properly deallocate this + * buffer, in accordance with this vector's AllocPolicy.) After this call, + * the vector is empty. Since the returned buffer may need to be allocated + * (if the elements are currently stored in-place), the call can fail, + * returning nullptr. + * + * N.B. Although a T*, only the range [0, length()) is constructed. + */ + T* extractRawBuffer(); + + /** + * Transfer ownership of an array of objects into the vector. The caller + * must have allocated the array in accordance with this vector's + * AllocPolicy. + * + * N.B. This call assumes that there are no uninitialized elements in the + * passed array. + */ + void replaceRawBuffer(T* aP, size_t aLength); + + /** + * Places |aVal| at position |aP|, shifting existing elements from |aP| onward + * one position higher. On success, |aP| should not be reused because it'll + * be a dangling pointer if reallocation of the vector storage occurred; the + * return value should be used instead. On failure, nullptr is returned. + * + * Example usage: + * + * if (!(p = vec.insert(p, val))) { + * + * } + * + * + * This is inherently a linear-time operation. Be careful! + */ + template + T* insert(T* aP, U&& aVal); - /** - * Places |val| at position |p|, shifting existing elements from |p| onward - * one position higher. On success, |p| should not be reused because it'll - * be a dangling pointer if reallocation of the vector storage occurred; the - * return value should be used instead. On failure, nullptr is returned. - * - * Example usage: - * - * if (!(p = vec.insert(p, val))) - * - * - * - * This is inherently a linear-time operation. Be careful! - */ - template - T* insert(T* p, U&& val); + /** + * Removes the element |aT|, which must fall in the bounds [begin, end), + * shifting existing elements from |aT + 1| onward one position lower. + */ + void erase(T* aT); - /** - * Removes the element |t|, which must fall in the bounds [begin, end), - * shifting existing elements from |t + 1| onward one position lower. - */ - void erase(T* t); + /** + * Removes the elements [|aBegin|, |aEnd|), which must fall in the bounds + * [begin, end), shifting existing elements from |aEnd + 1| onward to aBegin's + * old position. + */ + void erase(T* aBegin, T* aEnd); - /** - * Measure the size of the vector's heap-allocated storage. - */ - size_t sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const; + /** + * Measure the size of the vector's heap-allocated storage. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const; - /** - * Like sizeOfExcludingThis, but also measures the size of the vector - * object (which must be heap-allocated) itself. - */ - size_t sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const; + /** + * Like sizeOfExcludingThis, but also measures the size of the vector + * object (which must be heap-allocated) itself. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; - void swap(ThisVector& other); + void swap(ThisVector& aOther); - private: - VectorBase(const VectorBase&) MOZ_DELETE; - void operator=(const VectorBase&) MOZ_DELETE; +private: + VectorBase(const VectorBase&) MOZ_DELETE; + void operator=(const VectorBase&) MOZ_DELETE; - /* Move-construct/assign only from our derived class, ThisVector. */ - VectorBase(VectorBase&&) MOZ_DELETE; - void operator=(VectorBase&&) MOZ_DELETE; + /* Move-construct/assign only from our derived class, ThisVector. */ + VectorBase(VectorBase&&) MOZ_DELETE; + void operator=(VectorBase&&) MOZ_DELETE; }; /* This does the re-entrancy check plus several other sanity checks. */ #define MOZ_REENTRANCY_GUARD_ET_AL \ ReentrancyGuard g(*this); \ - MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == sInlineCapacity); \ + MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == kInlineCapacity); \ MOZ_ASSERT(reserved() <= mCapacity); \ MOZ_ASSERT(mLength <= reserved()); \ MOZ_ASSERT(mLength <= mCapacity) @@ -569,39 +618,39 @@ class VectorBase : private AllocPolicy template MOZ_ALWAYS_INLINE -VectorBase::VectorBase(AP ap) - : AP(ap), - mLength(0), - mCapacity(sInlineCapacity) +VectorBase::VectorBase(AP aAP) + : AP(aAP) + , mLength(0) + , mCapacity(kInlineCapacity) #ifdef DEBUG - , mReserved(sInlineCapacity), - entered(false) + , mReserved(kInlineCapacity) + , mEntered(false) #endif { - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); } /* Move constructor. */ template MOZ_ALWAYS_INLINE -VectorBase::VectorBase(TV&& rhs) - : AllocPolicy(Move(rhs)) +VectorBase::VectorBase(TV&& aRhs) + : AllocPolicy(Move(aRhs)) #ifdef DEBUG - , entered(false) + , mEntered(false) #endif { - mLength = rhs.mLength; - mCapacity = rhs.mCapacity; + mLength = aRhs.mLength; + mCapacity = aRhs.mCapacity; #ifdef DEBUG - mReserved = rhs.mReserved; + mReserved = aRhs.mReserved; #endif - if (rhs.usingInlineStorage()) { + if (aRhs.usingInlineStorage()) { /* We can't move the buffer over in this case, so copy elements. */ - mBegin = static_cast(storage.addr()); - Impl::moveConstruct(mBegin, rhs.beginNoCheck(), rhs.endNoCheck()); + mBegin = static_cast(mStorage.addr()); + Impl::moveConstruct(mBegin, aRhs.beginNoCheck(), aRhs.endNoCheck()); /* - * Leave rhs's mLength, mBegin, mCapacity, and mReserved as they are. + * Leave aRhs's mLength, mBegin, mCapacity, and mReserved as they are. * The elements in its in-line storage still need to be destroyed. */ } else { @@ -609,26 +658,25 @@ VectorBase::VectorBase(TV&& rhs) * Take src's buffer, and turn src into an empty vector using * in-line storage. */ - mBegin = rhs.mBegin; - rhs.mBegin = static_cast(rhs.storage.addr()); - rhs.mCapacity = sInlineCapacity; - rhs.mLength = 0; + mBegin = aRhs.mBegin; + aRhs.mBegin = static_cast(aRhs.mStorage.addr()); + aRhs.mCapacity = kInlineCapacity; + aRhs.mLength = 0; #ifdef DEBUG - rhs.mReserved = sInlineCapacity; + aRhs.mReserved = kInlineCapacity; #endif } } /* Move assignment. */ template -MOZ_ALWAYS_INLINE -TV& -VectorBase::operator=(TV&& rhs) +MOZ_ALWAYS_INLINE TV& +VectorBase::operator=(TV&& aRhs) { - MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + MOZ_ASSERT(this != &aRhs, "self-move assignment is prohibited"); TV* tv = static_cast(this); tv->~TV(); - new(tv) TV(Move(rhs)); + new(tv) TV(Move(aRhs)); return *tv; } @@ -638,26 +686,28 @@ VectorBase::~VectorBase() { MOZ_REENTRANCY_GUARD_ET_AL; Impl::destroy(beginNoCheck(), endNoCheck()); - if (!usingInlineStorage()) + if (!usingInlineStorage()) { this->free_(beginNoCheck()); + } } /* - * This function will create a new heap buffer with capacity newCap, + * This function will create a new heap buffer with capacity aNewCap, * move all elements in the inline buffer to this new buffer, * and fail on OOM. */ template inline bool -VectorBase::convertToHeapStorage(size_t newCap) +VectorBase::convertToHeapStorage(size_t aNewCap) { MOZ_ASSERT(usingInlineStorage()); /* Allocate buffer. */ - MOZ_ASSERT(!detail::CapacityHasExcessSpace(newCap)); - T* newBuf = reinterpret_cast(this->malloc_(newCap * sizeof(T))); - if (!newBuf) + MOZ_ASSERT(!detail::CapacityHasExcessSpace(aNewCap)); + T* newBuf = reinterpret_cast(this->malloc_(aNewCap * sizeof(T))); + if (!newBuf) { return false; + } /* Copy inline elements into heap buffer. */ Impl::moveConstruct(newBuf, beginNoCheck(), endNoCheck()); @@ -666,15 +716,15 @@ VectorBase::convertToHeapStorage(size_t newCap) /* Switch in heap buffer. */ mBegin = newBuf; /* mLength is unchanged. */ - mCapacity = newCap; + mCapacity = aNewCap; return true; } template MOZ_NEVER_INLINE bool -VectorBase::growStorageBy(size_t incr) +VectorBase::growStorageBy(size_t aIncr) { - MOZ_ASSERT(mLength + incr > mCapacity); + MOZ_ASSERT(mLength + aIncr > mCapacity); MOZ_ASSERT_IF(!usingInlineStorage(), !detail::CapacityHasExcessSpace(mCapacity)); @@ -688,11 +738,11 @@ VectorBase::growStorageBy(size_t incr) size_t newCap; - if (incr == 1) { + if (aIncr == 1) { if (usingInlineStorage()) { /* This case occurs in ~70--80% of the calls to this function. */ size_t newSize = - tl::RoundUpPow2<(sInlineCapacity + 1) * sizeof(T)>::value; + tl::RoundUpPow2<(kInlineCapacity + 1) * sizeof(T)>::value; newCap = newSize / sizeof(T); goto convert; } @@ -725,13 +775,14 @@ VectorBase::growStorageBy(size_t incr) * then there might be space for one more element. */ newCap = mLength * 2; - if (detail::CapacityHasExcessSpace(newCap)) + if (detail::CapacityHasExcessSpace(newCap)) { newCap += 1; + } } else { /* This case occurs in ~2% of the calls to this function. */ - size_t newMinCap = mLength + incr; + size_t newMinCap = mLength + aIncr; - /* Did mLength + incr overflow? Will newCap * sizeof(T) overflow? */ + /* Did mLength + aIncr overflow? Will newCap * sizeof(T) overflow? */ if (newMinCap < mLength || newMinCap & tl::MulOverflowMask<2 * sizeof(T)>::value) { @@ -745,7 +796,7 @@ VectorBase::growStorageBy(size_t incr) } if (usingInlineStorage()) { - convert: +convert: return convertToHeapStorage(newCap); } @@ -755,34 +806,37 @@ VectorBase::growStorageBy(size_t incr) template inline bool -VectorBase::initCapacity(size_t request) +VectorBase::initCapacity(size_t aRequest) { MOZ_ASSERT(empty()); MOZ_ASSERT(usingInlineStorage()); - if (request == 0) + if (aRequest == 0) { return true; - T* newbuf = reinterpret_cast(this->malloc_(request * sizeof(T))); - if (!newbuf) + } + T* newbuf = reinterpret_cast(this->malloc_(aRequest * sizeof(T))); + if (!newbuf) { return false; + } mBegin = newbuf; - mCapacity = request; + mCapacity = aRequest; #ifdef DEBUG - mReserved = request; + mReserved = aRequest; #endif return true; } template inline bool -VectorBase::reserve(size_t request) +VectorBase::reserve(size_t aRequest) { MOZ_REENTRANCY_GUARD_ET_AL; - if (request > mCapacity && !growStorageBy(request - mLength)) + if (aRequest > mCapacity && !growStorageBy(aRequest - mLength)) { return false; - + } #ifdef DEBUG - if (request > mReserved) - mReserved = request; + if (aRequest > mReserved) { + mReserved = aRequest; + } MOZ_ASSERT(mLength <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); #endif @@ -791,69 +845,73 @@ VectorBase::reserve(size_t request) template inline void -VectorBase::shrinkBy(size_t incr) +VectorBase::shrinkBy(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - MOZ_ASSERT(incr <= mLength); - Impl::destroy(endNoCheck() - incr, endNoCheck()); - mLength -= incr; + MOZ_ASSERT(aIncr <= mLength); + Impl::destroy(endNoCheck() - aIncr, endNoCheck()); + mLength -= aIncr; } template MOZ_ALWAYS_INLINE bool -VectorBase::growBy(size_t incr) +VectorBase::growBy(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - if (incr > mCapacity - mLength && !growStorageBy(incr)) + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { return false; - - MOZ_ASSERT(mLength + incr <= mCapacity); - T* newend = endNoCheck() + incr; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + T* newend = endNoCheck() + aIncr; Impl::initialize(endNoCheck(), newend); - mLength += incr; + mLength += aIncr; #ifdef DEBUG - if (mLength > mReserved) + if (mLength > mReserved) { mReserved = mLength; + } #endif return true; } template MOZ_ALWAYS_INLINE bool -VectorBase::growByUninitialized(size_t incr) +VectorBase::growByUninitialized(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - if (incr > mCapacity - mLength && !growStorageBy(incr)) + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { return false; - - MOZ_ASSERT(mLength + incr <= mCapacity); - mLength += incr; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + mLength += aIncr; #ifdef DEBUG - if (mLength > mReserved) + if (mLength > mReserved) { mReserved = mLength; + } #endif return true; } template inline bool -VectorBase::resize(size_t newLength) +VectorBase::resize(size_t aNewLength) { size_t curLength = mLength; - if (newLength > curLength) - return growBy(newLength - curLength); - shrinkBy(curLength - newLength); + if (aNewLength > curLength) { + return growBy(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); return true; } template MOZ_ALWAYS_INLINE bool -VectorBase::resizeUninitialized(size_t newLength) +VectorBase::resizeUninitialized(size_t aNewLength) { size_t curLength = mLength; - if (newLength > curLength) - return growByUninitialized(newLength - curLength); - shrinkBy(curLength - newLength); + if (aNewLength > curLength) { + return growByUninitialized(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); return true; } @@ -872,166 +930,186 @@ VectorBase::clearAndFree() { clear(); - if (usingInlineStorage()) + if (usingInlineStorage()) { return; - + } this->free_(beginNoCheck()); - mBegin = static_cast(storage.addr()); - mCapacity = sInlineCapacity; + mBegin = static_cast(mStorage.addr()); + mCapacity = kInlineCapacity; #ifdef DEBUG - mReserved = sInlineCapacity; + mReserved = kInlineCapacity; #endif } template inline bool -VectorBase::canAppendWithoutRealloc(size_t needed) const +VectorBase::canAppendWithoutRealloc(size_t aNeeded) const { - return mLength + needed <= mCapacity; + return mLength + aNeeded <= mCapacity; } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppendAll(const VectorBase& other) +VectorBase::internalAppendAll( + const VectorBase& aOther) { - internalAppend(other.begin(), other.length()); + internalAppend(aOther.begin(), aOther.length()); } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppend(U&& u) +VectorBase::internalAppend(U&& aU) { MOZ_ASSERT(mLength + 1 <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - new(endNoCheck()) T(Forward(u)); + new(endNoCheck()) T(Forward(aU)); ++mLength; } template MOZ_ALWAYS_INLINE bool -VectorBase::appendN(const T& t, size_t needed) +VectorBase::appendN(const T& aT, size_t aNeeded) { MOZ_REENTRANCY_GUARD_ET_AL; - if (mLength + needed > mCapacity && !growStorageBy(needed)) + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { return false; - + } #ifdef DEBUG - if (mLength + needed > mReserved) - mReserved = mLength + needed; + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } #endif - internalAppendN(t, needed); + internalAppendN(aT, aNeeded); return true; } template MOZ_ALWAYS_INLINE void -VectorBase::internalAppendN(const T& t, size_t needed) +VectorBase::internalAppendN(const T& aT, size_t aNeeded) { - MOZ_ASSERT(mLength + needed <= mReserved); + MOZ_ASSERT(mLength + aNeeded <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - Impl::copyConstructN(endNoCheck(), needed, t); - mLength += needed; + Impl::copyConstructN(endNoCheck(), aNeeded, aT); + mLength += aNeeded; } template template inline T* -VectorBase::insert(T* p, U&& val) +VectorBase::insert(T* aP, U&& aVal) { - MOZ_ASSERT(begin() <= p); - MOZ_ASSERT(p <= end()); - size_t pos = p - begin(); + MOZ_ASSERT(begin() <= aP); + MOZ_ASSERT(aP <= end()); + size_t pos = aP - begin(); MOZ_ASSERT(pos <= mLength); size_t oldLength = mLength; if (pos == oldLength) { - if (!append(Forward(val))) + if (!append(Forward(aVal))) { return nullptr; + } } else { T oldBack = Move(back()); - if (!append(Move(oldBack))) /* Dup the last element. */ + if (!append(Move(oldBack))) { /* Dup the last element. */ return nullptr; - for (size_t i = oldLength; i > pos; --i) + } + for (size_t i = oldLength; i > pos; --i) { (*this)[i] = Move((*this)[i - 1]); - (*this)[pos] = Forward(val); + } + (*this)[pos] = Forward(aVal); } return begin() + pos; } template inline void -VectorBase::erase(T* it) +VectorBase::erase(T* aIt) { - MOZ_ASSERT(begin() <= it); - MOZ_ASSERT(it < end()); - while (it + 1 < end()) { - *it = *(it + 1); - ++it; + MOZ_ASSERT(begin() <= aIt); + MOZ_ASSERT(aIt < end()); + while (aIt + 1 < end()) { + *aIt = Move(*(aIt + 1)); + ++aIt; } - popBack(); + popBack(); +} + +template +inline void +VectorBase::erase(T* aBegin, T* aEnd) +{ + MOZ_ASSERT(begin() <= aBegin); + MOZ_ASSERT(aBegin <= aEnd); + MOZ_ASSERT(aEnd <= end()); + while (aEnd < end()) { + *aBegin++ = Move(*aEnd++); + } + shrinkBy(aEnd - aBegin); } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(const U* insBegin, const U* insEnd) +VectorBase::append(const U* aInsBegin, const U* aInsEnd) { MOZ_REENTRANCY_GUARD_ET_AL; - size_t needed = PointerRangeSize(insBegin, insEnd); - if (mLength + needed > mCapacity && !growStorageBy(needed)) + size_t aNeeded = PointerRangeSize(aInsBegin, aInsEnd); + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { return false; - + } #ifdef DEBUG - if (mLength + needed > mReserved) - mReserved = mLength + needed; + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } #endif - internalAppend(insBegin, needed); + internalAppend(aInsBegin, aNeeded); return true; } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppend(const U* insBegin, size_t insLength) +VectorBase::internalAppend(const U* aInsBegin, size_t aInsLength) { - MOZ_ASSERT(mLength + insLength <= mReserved); + MOZ_ASSERT(mLength + aInsLength <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - Impl::copyConstruct(endNoCheck(), insBegin, insBegin + insLength); - mLength += insLength; + Impl::copyConstruct(endNoCheck(), aInsBegin, aInsBegin + aInsLength); + mLength += aInsLength; } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(U&& u) +VectorBase::append(U&& aU) { MOZ_REENTRANCY_GUARD_ET_AL; - if (mLength == mCapacity && !growStorageBy(1)) + if (mLength == mCapacity && !growStorageBy(1)) { return false; - + } #ifdef DEBUG - if (mLength + 1 > mReserved) + if (mLength + 1 > mReserved) { mReserved = mLength + 1; + } #endif - internalAppend(Forward(u)); + internalAppend(Forward(aU)); return true; } template template MOZ_ALWAYS_INLINE bool -VectorBase::appendAll(const VectorBase& other) +VectorBase::appendAll(const VectorBase& aOther) { - return append(other.begin(), other.length()); + return append(aOther.begin(), aOther.length()); } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(const U *insBegin, size_t insLength) +VectorBase::append(const U* aInsBegin, size_t aInsLength) { - return append(insBegin, insBegin + insLength); + return append(aInsBegin, aInsBegin + aInsLength); } template @@ -1060,19 +1138,20 @@ VectorBase::extractRawBuffer() T* ret; if (usingInlineStorage()) { ret = reinterpret_cast(this->malloc_(mLength * sizeof(T))); - if (!ret) + if (!ret) { return nullptr; + } Impl::copyConstruct(ret, beginNoCheck(), endNoCheck()); Impl::destroy(beginNoCheck(), endNoCheck()); /* mBegin, mCapacity are unchanged. */ mLength = 0; } else { ret = mBegin; - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); mLength = 0; - mCapacity = sInlineCapacity; + mCapacity = kInlineCapacity; #ifdef DEBUG - mReserved = sInlineCapacity; + mReserved = kInlineCapacity; #endif } return ret; @@ -1080,30 +1159,31 @@ VectorBase::extractRawBuffer() template inline void -VectorBase::replaceRawBuffer(T* p, size_t aLength) +VectorBase::replaceRawBuffer(T* aP, size_t aLength) { MOZ_REENTRANCY_GUARD_ET_AL; /* Destroy what we have. */ Impl::destroy(beginNoCheck(), endNoCheck()); - if (!usingInlineStorage()) + if (!usingInlineStorage()) { this->free_(beginNoCheck()); + } /* Take in the new buffer. */ - if (aLength <= sInlineCapacity) { + if (aLength <= kInlineCapacity) { /* - * We convert to inline storage if possible, even though p might + * We convert to inline storage if possible, even though aP might * otherwise be acceptable. Maybe this behaviour should be * specifiable with an argument to this function. */ - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); mLength = aLength; - mCapacity = sInlineCapacity; - Impl::moveConstruct(mBegin, p, p + aLength); - Impl::destroy(p, p + aLength); - this->free_(p); + mCapacity = kInlineCapacity; + Impl::moveConstruct(mBegin, aP, aP + aLength); + Impl::destroy(aP, aP + aLength); + this->free_(aP); } else { - mBegin = p; + mBegin = aP; mLength = aLength; mCapacity = aLength; } @@ -1114,42 +1194,42 @@ VectorBase::replaceRawBuffer(T* p, size_t aLength) template inline size_t -VectorBase::sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const +VectorBase::sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { - return usingInlineStorage() ? 0 : mallocSizeOf(beginNoCheck()); + return usingInlineStorage() ? 0 : aMallocSizeOf(beginNoCheck()); } template inline size_t -VectorBase::sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const +VectorBase::sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { - return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); } template inline void -VectorBase::swap(TV& other) +VectorBase::swap(TV& aOther) { static_assert(N == 0, "still need to implement this for N != 0"); // This only works when inline storage is always empty. - if (!usingInlineStorage() && other.usingInlineStorage()) { - other.mBegin = mBegin; + if (!usingInlineStorage() && aOther.usingInlineStorage()) { + aOther.mBegin = mBegin; mBegin = inlineStorage(); - } else if (usingInlineStorage() && !other.usingInlineStorage()) { - mBegin = other.mBegin; - other.mBegin = other.inlineStorage(); - } else if (!usingInlineStorage() && !other.usingInlineStorage()) { - Swap(mBegin, other.mBegin); + } else if (usingInlineStorage() && !aOther.usingInlineStorage()) { + mBegin = aOther.mBegin; + aOther.mBegin = aOther.inlineStorage(); + } else if (!usingInlineStorage() && !aOther.usingInlineStorage()) { + Swap(mBegin, aOther.mBegin); } else { // This case is a no-op, since we'd set both to use their inline storage. } - Swap(mLength, other.mLength); - Swap(mCapacity, other.mCapacity); + Swap(mLength, aOther.mLength); + Swap(mCapacity, aOther.mCapacity); #ifdef DEBUG - Swap(mReserved, other.mReserved); + Swap(mReserved, aOther.mReserved); #endif } @@ -1180,14 +1260,15 @@ class Vector AllocPolicy, Vector > { - typedef VectorBase Base; - - public: - Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} - Vector(Vector&& vec) : Base(Move(vec)) {} - Vector& operator=(Vector&& vec) { - return Base::operator=(Move(vec)); - } + typedef VectorBase Base; + +public: + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + Vector(Vector&& vec) : Base(Move(vec)) {} + Vector& operator=(Vector&& aOther) + { + return Base::operator=(Move(aOther)); + } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/WeakPtr.h b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/WeakPtr.h index 0165e3a017..07f00bc295 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/WeakPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/mac/mozilla/WeakPtr.h @@ -14,21 +14,29 @@ * the WeakPtrs to it and allows the WeakReference to live beyond the lifetime * of 'Foo'. * + * PLEASE NOTE: This weak pointer implementation is not thread-safe. + * + * Note that when deriving from SupportsWeakPtr you should add + * MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public section of your + * class, where ClassName is the name of your class. + * * The overhead of WeakPtr is that accesses to 'Foo' becomes an additional * dereference, and an additional heap allocated pointer sized object shared * between all of the WeakPtrs. * * Example of usage: * - * // To have a class C support weak pointers, inherit from SupportsWeakPtr. + * // To have a class C support weak pointers, inherit from + * // SupportsWeakPtr. * class C : public SupportsWeakPtr * { - * public: - * int num; - * void act(); + * public: + * MOZ_DECLARE_REFCOUNTED_TYPENAME(C) + * int mNum; + * void act(); * }; * - * C* ptr = new C(); + * C* ptr = new C(); * * // Get weak pointers to ptr. The first time asWeakPtr is called * // a reference counted WeakReference object is created that @@ -39,7 +47,7 @@ * * // Test a weak pointer for validity before using it. * if (weak) { - * weak->num = 17; + * weak->mNum = 17; * weak->act(); * } * @@ -59,11 +67,14 @@ #ifndef mozilla_WeakPtr_h #define mozilla_WeakPtr_h +#include "mozilla/ArrayUtils.h" #include "mozilla/Assertions.h" #include "mozilla/NullPtr.h" #include "mozilla/RefPtr.h" #include "mozilla/TypeTraits.h" +#include + namespace mozilla { template class WeakPtrBase; @@ -71,23 +82,48 @@ template class SupportsWeakPtrBase; namespace detail { -// This can live beyond the lifetime of the class derived from SupportsWeakPtrBase. +// This can live beyond the lifetime of the class derived from +// SupportsWeakPtrBase. template class WeakReference : public ::mozilla::RefCounted > { - public: - explicit WeakReference(T* p) : ptr(p) {} - T* get() const { - return ptr; - } - - private: - friend class WeakPtrBase >; - friend class SupportsWeakPtrBase >; - void detach() { - ptr = nullptr; - } - T* ptr; +public: + explicit WeakReference(T* p) : mPtr(p) {} + + T* get() const { return mPtr; } + +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#ifdef XP_WIN +#define snprintf _snprintf +#endif + const char* typeName() const + { + static char nameBuffer[1024]; + const char* innerType = mPtr->typeName(); + // We could do fancier length checks at runtime, but innerType is + // controlled by us so we can ensure that this never causes a buffer + // overflow by this assertion. + MOZ_ASSERT(strlen(innerType) + sizeof("WeakReference<>") < + ArrayLength(nameBuffer), + "Exceedingly large type name"); + snprintf(nameBuffer, ArrayLength(nameBuffer), "WeakReference<%s>", + innerType); + // This is usually not OK, but here we are returning a pointer to a static + // buffer which will immediately be used by the caller. + return nameBuffer; + } + + size_t typeSize() const { return sizeof(*this); } +#undef snprintf +#endif + +private: + friend class WeakPtrBase >; + friend class SupportsWeakPtrBase >; + + void detach() { mPtr = nullptr; } + + T* mPtr; }; } // namespace detail @@ -95,25 +131,29 @@ class WeakReference : public ::mozilla::RefCounted > template class SupportsWeakPtrBase { - public: - WeakPtrBase asWeakPtr() { - if (!weakRef) - weakRef = new WeakReference(static_cast(this)); - return WeakPtrBase(weakRef); +public: + WeakPtrBase asWeakPtr() + { + if (!weakRef) { + weakRef = new WeakReference(static_cast(this)); } - - protected: - ~SupportsWeakPtrBase() { - static_assert(IsBaseOf, T>::value, - "T must derive from SupportsWeakPtrBase"); - if (weakRef) - weakRef->detach(); + return WeakPtrBase(weakRef); + } + +protected: + ~SupportsWeakPtrBase() + { + static_assert(IsBaseOf, T>::value, + "T must derive from SupportsWeakPtrBase"); + if (weakRef) { + weakRef->detach(); } + } - private: - friend class WeakPtrBase; +private: + friend class WeakPtrBase; - RefPtr weakRef; + RefPtr weakRef; }; template @@ -124,42 +164,37 @@ class SupportsWeakPtr : public SupportsWeakPtrBase > template class WeakPtrBase { - public: - WeakPtrBase(const WeakPtrBase& o) : ref(o.ref) {} - // Ensure that ref is dereferenceable in the uninitialized state - WeakPtrBase() : ref(new WeakReference(nullptr)) {} +public: + WeakPtrBase(const WeakPtrBase& aOther) + : mRef(aOther.mRef) + {} - operator T*() const { - return ref->get(); - } - T& operator*() const { - return *ref->get(); - } + // Ensure that mRef is dereferenceable in the uninitialized state. + WeakPtrBase() : mRef(new WeakReference(nullptr)) {} - T* operator->() const { - return ref->get(); - } + operator T*() const { return mRef->get(); } + T& operator*() const { return *mRef->get(); } - T* get() const { - return ref->get(); - } + T* operator->() const { return mRef->get(); } + + T* get() const { return mRef->get(); } - private: - friend class SupportsWeakPtrBase; +private: + friend class SupportsWeakPtrBase; - explicit WeakPtrBase(const RefPtr &o) : ref(o) {} + explicit WeakPtrBase(const RefPtr &aOther) : mRef(aOther) {} - RefPtr ref; + RefPtr mRef; }; template class WeakPtr : public WeakPtrBase > { - typedef WeakPtrBase > Base; - public: - WeakPtr(const WeakPtr& o) : Base(o) {} - WeakPtr(const Base& o) : Base(o) {} - WeakPtr() {} + typedef WeakPtrBase > Base; +public: + WeakPtr(const WeakPtr& aOther) : Base(aOther) {} + MOZ_IMPLICIT WeakPtr(const Base& aOther) : Base(aOther) {} + WeakPtr() {} }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js-config.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js-config.h index 482dad05dc..e3d4501032 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js-config.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js-config.h @@ -12,6 +12,12 @@ This header file is generated by the SpiderMonkey configure script, and installed along with jsapi.h. */ +/* Define to 1 if SpiderMonkey is in debug mode. */ +/* #undef JS_DEBUG */ + +/* Define to 1 if SpiderMonkey should not use struct types in debug builds. */ +/* #undef JS_NO_JSVAL_JSID_STRUCT_TYPES */ + /* Define to 1 if SpiderMonkey should support multi-threaded clients. */ /* #undef JS_THREADSAFE */ @@ -34,8 +40,14 @@ useable. See jscpucfg.h. */ /* #undef JS_HAVE_SYS_ISA_DEFS_H */ +/* Define to 1 if SpiderMonkey is in NUNBOX32 mode. */ +#define JS_NUNBOX32 1 + +/* Define to 1 if SpiderMonkey is in PUNBOX64 mode. */ +/* #undef JS_PUNBOX64 */ + /* MOZILLA JSAPI version number components */ -#define MOZJS_MAJOR_VERSION 28 -#define MOZJS_MINOR_VERSION 0 +#define MOZJS_MAJOR_VERSION 33 +#define MOZJS_MINOR_VERSION 1 #endif /* js_config_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js.msg b/frameworks/js-bindings/external/spidermonkey/include/win32/js.msg index 5a8344163b..d342ad4506 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js.msg +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js.msg @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -105,7 +105,7 @@ MSG_DEF(JSMSG_BAD_DESTRUCT_ASS, 51, 0, JSEXN_REFERENCEERR, "invalid destr MSG_DEF(JSMSG_PAREN_AFTER_LET, 52, 0, JSEXN_SYNTAXERR, "missing ) after let head") MSG_DEF(JSMSG_CURLY_AFTER_LET, 53, 0, JSEXN_SYNTAXERR, "missing } after let block") MSG_DEF(JSMSG_MISSING_PAREN, 54, 0, JSEXN_SYNTAXERR, "unterminated parenthetical") -MSG_DEF(JSMSG_UNTERM_CLASS, 55, 1, JSEXN_SYNTAXERR, "unterminated character class {0}") +MSG_DEF(JSMSG_UNTERM_CLASS, 55, 0, JSEXN_SYNTAXERR, "unterminated character class") MSG_DEF(JSMSG_TRAILING_SLASH, 56, 0, JSEXN_SYNTAXERR, "trailing \\ in regular expression") MSG_DEF(JSMSG_BAD_CLASS_RANGE, 57, 0, JSEXN_SYNTAXERR, "invalid range in character class") MSG_DEF(JSMSG_BAD_REGEXP_FLAG, 58, 1, JSEXN_SYNTAXERR, "invalid regular expression flag {0}") @@ -223,30 +223,30 @@ MSG_DEF(JSMSG_TOO_MANY_CATCH_VARS, 169, 0, JSEXN_SYNTAXERR, "too many catch v MSG_DEF(JSMSG_NEGATIVE_REPETITION_COUNT, 170, 0, JSEXN_RANGEERR, "repeat count must be non-negative") MSG_DEF(JSMSG_INVALID_FOR_OF_INIT, 171, 0, JSEXN_SYNTAXERR, "for-of loop variable declaration may not have an initializer") MSG_DEF(JSMSG_INVALID_MAP_ITERABLE, 172, 0, JSEXN_TYPEERR, "iterable for map should have array-like objects") -MSG_DEF(JSMSG_UNUSED173, 173, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED174, 174, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_NOT_A_CODEPOINT, 173, 1, JSEXN_RANGEERR, "{0} is not a valid code point") +MSG_DEF(JSMSG_BRACKET_AFTER_ARRAY_COMPREHENSION, 174, 0, JSEXN_SYNTAXERR, "missing ] after array comprehension") MSG_DEF(JSMSG_NESTING_GENERATOR, 175, 0, JSEXN_TYPEERR, "already executing generator") -MSG_DEF(JSMSG_UNUSED176, 176, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED177, 177, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED178, 178, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED179, 179, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED180, 180, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED181, 181, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_PAREN_AFTER_FOR_OF_ITERABLE, 176, 0, JSEXN_SYNTAXERR, "missing ) after for-of iterable") +MSG_DEF(JSMSG_INVALID_NORMALIZE_FORM, 177, 0, JSEXN_RANGEERR, "form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD'") +MSG_DEF(JSMSG_NOTHING_TO_REPEAT, 178, 0, JSEXN_SYNTAXERR, "nothing to repeat") +MSG_DEF(JSMSG_INVALID_GROUP, 179, 0, JSEXN_SYNTAXERR, "invalid regexp group") +MSG_DEF(JSMSG_ESCAPE_AT_END_OF_REGEXP, 180, 0, JSEXN_SYNTAXERR, "\\ at end of pattern") +MSG_DEF(JSMSG_NUMBERS_OUT_OF_ORDER, 181, 0, JSEXN_SYNTAXERR, "numbers out of order in {} quantifier.") MSG_DEF(JSMSG_BAD_GENERATOR_SEND, 182, 1, JSEXN_TYPEERR, "attempt to send {0} to newborn generator") MSG_DEF(JSMSG_SC_NOT_TRANSFERABLE, 183, 0, JSEXN_TYPEERR, "invalid transferable array for structured clone") MSG_DEF(JSMSG_SC_DUP_TRANSFERABLE, 184, 0, JSEXN_TYPEERR, "duplicate transferable for structured clone") MSG_DEF(JSMSG_CANT_REPORT_AS_NON_EXTENSIBLE, 185, 0, JSEXN_TYPEERR, "proxy can't report an extensible object as non-extensible") -MSG_DEF(JSMSG_UNUSED186, 186, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_SYMBOL_TO_STRING, 186, 0, JSEXN_TYPEERR, "can't convert symbol to string") MSG_DEF(JSMSG_UNUSED187, 187, 0, JSEXN_NONE, "") MSG_DEF(JSMSG_INCOMPATIBLE_METHOD, 188, 3, JSEXN_TYPEERR, "{0} {1} called on incompatible {2}") -MSG_DEF(JSMSG_UNUSED189, 189, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_SYMBOL_TO_PRIMITIVE, 189, 0, JSEXN_TYPEERR, "can't convert symbol object to primitive") MSG_DEF(JSMSG_UNUSED190, 190, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED191, 191, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED192, 192, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_BAD_INDEX, 191, 0, JSEXN_RANGEERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_SELFHOSTED_TOP_LEVEL_LET,192,0, JSEXN_SYNTAXERR, "self-hosted code cannot contain top-level 'let' declarations") MSG_DEF(JSMSG_BAD_FOR_EACH_LOOP, 193, 0, JSEXN_SYNTAXERR, "invalid for each loop") -MSG_DEF(JSMSG_OBJECT_WATCH_DEPRECATED,194, 0, JSEXN_TYPEERR, "Object.prototype.watch and unwatch are very slow, non-standard, and deprecated; use a getter/setter instead") -MSG_DEF(JSMSG_UNUSED195, 195, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED196, 196, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_OBJECT_WATCH_DEPRECATED,194, 0, JSEXN_NONE, "Object.prototype.watch and unwatch are very slow, non-standard, and deprecated; use a getter/setter instead") +MSG_DEF(JSMSG_TYPE_ERR_BAD_ARGS, 195, 0, JSEXN_TYPEERR, "invalid arguments") +MSG_DEF(JSMSG_REDECLARED_CATCH_IDENTIFIER, 196, 1, JSEXN_TYPEERR, "redeclaration of identifier '{0}' in catch") MSG_DEF(JSMSG_INTERNAL_INTL_ERROR, 197, 0, JSEXN_ERR, "internal error while computing Intl data") MSG_DEF(JSMSG_DEFAULT_LOCALE_ERROR, 198, 0, JSEXN_ERR, "internal error getting the default locale") MSG_DEF(JSMSG_TOO_MANY_LOCALS, 199, 0, JSEXN_SYNTAXERR, "too many local variables") @@ -260,25 +260,25 @@ MSG_DEF(JSMSG_USER_DEFINED_ERROR, 206, 0, JSEXN_ERR, "JS_ReportError was cal MSG_DEF(JSMSG_WRONG_CONSTRUCTOR, 207, 1, JSEXN_TYPEERR, "wrong constructor called for {0}") MSG_DEF(JSMSG_BAD_GENERATOR_RETURN, 208, 1, JSEXN_TYPEERR, "generator function {0} returns a value") MSG_DEF(JSMSG_BAD_ANON_GENERATOR_RETURN, 209, 0, JSEXN_TYPEERR, "anonymous generator function returns a value") -MSG_DEF(JSMSG_UNUSED210, 210, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_PROTO_SETTING_SLOW, 210, 0, JSEXN_NONE, "mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create") MSG_DEF(JSMSG_IN_AFTER_FOR_NAME, 211, 0, JSEXN_SYNTAXERR, "missing 'in' or 'of' after for") MSG_DEF(JSMSG_BAD_TRAP_RETURN_VALUE, 212, 2, JSEXN_TYPEERR,"trap {1} for {0} returned a primitive value") -MSG_DEF(JSMSG_UNUSED213, 213, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_OF_AFTER_FOR_NAME, 213, 0, JSEXN_SYNTAXERR, "missing 'of' after for") MSG_DEF(JSMSG_BAD_GENERATOR_YIELD, 214, 1, JSEXN_TYPEERR, "yield from closing generator {0}") MSG_DEF(JSMSG_BAD_GENERATOR_SYNTAX, 215, 1, JSEXN_SYNTAXERR, "{0} expression must be parenthesized") MSG_DEF(JSMSG_ARRAY_COMP_LEFTSIDE, 216, 0, JSEXN_SYNTAXERR, "invalid array comprehension left-hand side") -MSG_DEF(JSMSG_UNUSED217, 217, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_LET_COMP_BINDING, 217, 0, JSEXN_SYNTAXERR, "'let' is not a valid name for a comprehension variable") MSG_DEF(JSMSG_EMPTY_ARRAY_REDUCE, 218, 0, JSEXN_TYPEERR, "reduce of empty array with no initial value") MSG_DEF(JSMSG_BAD_SYMBOL, 219, 1, JSEXN_TYPEERR, "{0} is not a well-known @@-symbol") MSG_DEF(JSMSG_BAD_DELETE_OPERAND, 220, 0, JSEXN_REFERENCEERR, "invalid delete operand") MSG_DEF(JSMSG_BAD_INCOP_OPERAND, 221, 0, JSEXN_REFERENCEERR, "invalid increment/decrement operand") MSG_DEF(JSMSG_UNEXPECTED_TYPE, 222, 2, JSEXN_TYPEERR, "{0} is {1}") MSG_DEF(JSMSG_LET_DECL_NOT_IN_BLOCK, 223, 0, JSEXN_SYNTAXERR, "let declaration not directly within block") -MSG_DEF(JSMSG_BAD_OBJECT_INIT, 224, 0, JSEXN_SYNTAXERR, "invalid object initializer") +MSG_DEF(JSMSG_UNUSED224, 224, 0, JSEXN_NONE, "") MSG_DEF(JSMSG_CANT_SET_ARRAY_ATTRS, 225, 0, JSEXN_INTERNALERR, "can't set attributes on indexed array properties") MSG_DEF(JSMSG_EVAL_ARITY, 226, 0, JSEXN_TYPEERR, "eval accepts only one parameter") MSG_DEF(JSMSG_MISSING_FUN_ARG, 227, 2, JSEXN_TYPEERR, "missing argument {0} when calling function {1}") -MSG_DEF(JSMSG_JSON_BAD_PARSE, 228, 1, JSEXN_SYNTAXERR, "JSON.parse: {0}") +MSG_DEF(JSMSG_JSON_BAD_PARSE, 228, 3, JSEXN_SYNTAXERR, "JSON.parse: {0} at line {1} column {2} of the JSON data") MSG_DEF(JSMSG_JSON_BAD_STRINGIFY, 229, 0, JSEXN_ERR, "JSON.stringify") MSG_DEF(JSMSG_NOT_CALLABLE_OR_UNDEFINED, 230, 0, JSEXN_TYPEERR, "value is not a function or undefined") MSG_DEF(JSMSG_NOT_NONNULL_OBJECT, 231, 0, JSEXN_TYPEERR, "value is not a non-null object") @@ -353,11 +353,11 @@ MSG_DEF(JSMSG_REST_WITH_DEFAULT, 299, 0, JSEXN_SYNTAXERR, "rest parameter m MSG_DEF(JSMSG_NONDEFAULT_FORMAL_AFTER_DEFAULT, 300, 0, JSEXN_SYNTAXERR, "parameter(s) with default followed by parameter without default") MSG_DEF(JSMSG_YIELD_IN_DEFAULT, 301, 0, JSEXN_SYNTAXERR, "yield in default expression") MSG_DEF(JSMSG_INTRINSIC_NOT_DEFINED, 302, 1, JSEXN_REFERENCEERR, "no intrinsic function {0}") -MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 303, 2, JSEXN_ERR, "{0} is being assigned a {1}, but already has one") -MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 304, 1, JSEXN_RANGEERR, "invalid ParallelArray{0} argument") -MSG_DEF(JSMSG_PAR_ARRAY_BAD_PARTITION, 305, 0, JSEXN_ERR, "argument must be divisible by outermost dimension") -MSG_DEF(JSMSG_PAR_ARRAY_REDUCE_EMPTY, 306, 0, JSEXN_ERR, "cannot reduce ParallelArray object whose outermost dimension is empty") -MSG_DEF(JSMSG_PAR_ARRAY_ALREADY_FLAT, 307, 0, JSEXN_ERR, "cannot flatten 1-dimensional ParallelArray object") +MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 303, 2, JSEXN_NONE, "{0} is being assigned a {1}, but already has one") +MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 304, 0, JSEXN_RANGEERR, "invalid parallel method argument") +MSG_DEF(JSMSG_REGEXP_RUNTIME_ERROR, 305, 0, JSEXN_INTERNALERR, "an error occurred while executing regular expression") +MSG_DEF(JSMSG_DEBUG_OPTIMIZED_OUT, 306, 0, JSEXN_ERR, "variable has been optimized out") +MSG_DEF(JSMSG_NEXT_RETURNED_PRIMITIVE,307, 0, JSEXN_TYPEERR, "iterator.next() returned a non-object value") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_CONFLICT, 308, 0, JSEXN_ERR, "no conflict resolution function provided") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BOUNDS, 309, 0, JSEXN_ERR, "index in scatter vector out of bounds") MSG_DEF(JSMSG_CANT_REPORT_NC_AS_NE, 310, 0, JSEXN_TYPEERR, "proxy can't report a non-configurable own property as non-existent") @@ -391,13 +391,13 @@ MSG_DEF(JSMSG_DATE_NOT_FINITE, 337, 0, JSEXN_RANGEERR, "date value is not MSG_DEF(JSMSG_USE_ASM_DIRECTIVE_FAIL, 338, 0, JSEXN_SYNTAXERR, "\"use asm\" is only meaningful in the Directive Prologue of a function body") MSG_DEF(JSMSG_USE_ASM_TYPE_FAIL, 339, 1, JSEXN_TYPEERR, "asm.js type error: {0}") MSG_DEF(JSMSG_USE_ASM_LINK_FAIL, 340, 1, JSEXN_TYPEERR, "asm.js link error: {0}") -MSG_DEF(JSMSG_USE_ASM_TYPE_OK, 341, 1, JSEXN_ERR, "successfully compiled asm.js code ({0})") +MSG_DEF(JSMSG_USE_ASM_TYPE_OK, 341, 1, JSEXN_NONE, "Successfully compiled asm.js code ({0})") MSG_DEF(JSMSG_BAD_ARROW_ARGS, 342, 0, JSEXN_SYNTAXERR, "invalid arrow-function arguments (parentheses around the arrow-function may help)") MSG_DEF(JSMSG_YIELD_IN_ARROW, 343, 0, JSEXN_SYNTAXERR, "arrow function may not contain yield") MSG_DEF(JSMSG_WRONG_VALUE, 344, 2, JSEXN_ERR, "expected {0} but found {1}") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BAD_TARGET, 345, 1, JSEXN_ERR, "target for index {0} is not an integer") MSG_DEF(JSMSG_SELFHOSTED_UNBOUND_NAME,346, 0, JSEXN_TYPEERR, "self-hosted code may not contain unbound name lookups") -MSG_DEF(JSMSG_DEPRECATED_PRAGMA, 347, 1, JSEXN_SYNTAXERR, "Using //@ to indicate {0} pragmas is deprecated. Use //# instead") +MSG_DEF(JSMSG_DEPRECATED_PRAGMA, 347, 1, JSEXN_NONE, "Using //@ to indicate {0} pragmas is deprecated. Use //# instead") MSG_DEF(JSMSG_BAD_DESTRUCT_ASSIGN, 348, 1, JSEXN_SYNTAXERR, "can't assign to {0} using destructuring assignment") MSG_DEF(JSMSG_TYPEDOBJECT_ARRAYTYPE_BAD_ARGS, 349, 0, JSEXN_ERR, "Invalid arguments") MSG_DEF(JSMSG_TYPEDOBJECT_BINARYARRAY_BAD_INDEX, 350, 0, JSEXN_RANGEERR, "invalid or out-of-range index") @@ -414,7 +414,7 @@ MSG_DEF(JSMSG_TOO_MANY_FUN_SPREADARGS, 360, 0, JSEXN_RANGEERR, "too many functio MSG_DEF(JSMSG_DEBUG_NOT_DEBUGGEE, 361, 2, JSEXN_ERR, "{0} is not a debuggee {1}") MSG_DEF(JSMSG_TYPEDOBJECT_NOT_TYPED_OBJECT, 362, 0, JSEXN_ERR, "Expected a typed object") MSG_DEF(JSMSG_TYPEDOBJECT_NO_SUCH_PROP, 363, 1, JSEXN_TYPEERR, "No such property: {0}") -MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_BAD_ARGS, 364, 2, JSEXN_TYPEERR, "argument {0} invalid: expected {1}") +MSG_DEF(JSMSG_TYPEDOBJECT_BAD_ARGS, 364, 0, JSEXN_TYPEERR, "invalid arguments") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_UNATTACHED, 365, 0, JSEXN_TYPEERR, "handle unattached") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_BAD_TYPE, 366, 0, JSEXN_TYPEERR, "handle moved to destination of incorrect type") @@ -433,3 +433,11 @@ MSG_DEF(JSMSG_NO_EXPORT_NAME, 378, 0, JSEXN_SYNTAXERR, "missing export MSG_DEF(JSMSG_DECLARATION_AFTER_EXPORT, 379, 0, JSEXN_SYNTAXERR, "missing declaration after 'export' keyword") MSG_DEF(JSMSG_INVALID_PROTOTYPE, 380, 0, JSEXN_TYPEERR, "prototype field is not an object") MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_TO_UNSIZED, 381, 0, JSEXN_TYPEERR, "cannot create a handle to an unsized type") +MSG_DEF(JSMSG_SETPROTOTYPEOF_FAIL, 382, 1, JSEXN_TYPEERR, "[[SetPrototypeOf]] failed on {0}") +MSG_DEF(JSMSG_INVALID_ARG_TYPE, 383, 3, JSEXN_TYPEERR, "Invalid type: {0} can't be a{1} {2}") +MSG_DEF(JSMSG_TERMINATED, 384, 1, JSEXN_ERR, "Script terminated by timeout at:\n{0}") +MSG_DEF(JSMSG_NO_SUCH_SELF_HOSTED_PROP, 385, 1, JSEXN_ERR, "No such property on self-hosted object: {0}") +MSG_DEF(JSMSG_PROXY_EXTENSIBILITY, 386, 0, JSEXN_TYPEERR, "proxy must report same extensiblitity as target") +MSG_DEF(JSMSG_PROXY_CONSTRUCT_OBJECT, 387, 0, JSEXN_TYPEERR, "proxy [[Construct]] must return an object") +MSG_DEF(JSMSG_PROXY_GETOWN_OBJORUNDEF, 388, 0, JSEXN_TYPEERR, "proxy [[GetOwnProperty]] must return an object or undefined") +MSG_DEF(JSMSG_CANT_REPORT_C_AS_NC, 389, 0, JSEXN_TYPEERR, "proxy can't report existing configurable property as non-configurable") diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/CallArgs.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/CallArgs.h index 5c7a201101..3be3f1575a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/CallArgs.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/CallArgs.h @@ -44,7 +44,7 @@ typedef bool /* Typedef for native functions that may be called in parallel. */ typedef bool -(* JSParallelNative)(js::ForkJoinSlice *slice, unsigned argc, JS::Value *vp); +(* JSParallelNative)(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); /* * Typedef for native functions that may be called either in parallel or @@ -63,7 +63,7 @@ JSNativeThreadSafeWrapper(JSContext *cx, unsigned argc, JS::Value *vp); template inline bool -JSParallelNativeThreadSafeWrapper(js::ForkJoinSlice *slice, unsigned argc, JS::Value *vp); +JSParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); /* * Compute |this| for the |vp| inside a JSNative, either boxing primitives or @@ -118,7 +118,7 @@ extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; namespace detail { -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_PUBLIC_API(void) CheckIsValidConstructible(Value v); #endif @@ -147,7 +147,7 @@ class MOZ_STACK_CLASS UsedRvalBase template class MOZ_STACK_CLASS CallReceiverBase : public UsedRvalBase< -#ifdef DEBUG +#ifdef JS_DEBUG WantUsedRval #else NoUsedRval @@ -197,7 +197,7 @@ class MOZ_STACK_CLASS CallReceiverBase : public UsedRvalBase< } bool isConstructing() const { -#ifdef DEBUG +#ifdef JS_DEBUG if (this->usedRval_) CheckIsValidConstructible(calleev()); #endif @@ -388,11 +388,7 @@ CallArgsFromSp(unsigned argc, Value *sp) * take a const JS::CallArgs&. */ -#define JS_CALLEE(cx,vp) ((vp)[0]) -#define JS_THIS_OBJECT(cx,vp) (JSVAL_TO_OBJECT(JS_THIS(cx,vp))) -#define JS_ARGV(cx,vp) ((vp) + 2) -#define JS_RVAL(cx,vp) (*(vp)) -#define JS_SET_RVAL(cx,vp,v) (*(vp) = (v)) +#define JS_THIS_OBJECT(cx,vp) (JS_THIS(cx,vp).toObjectOrNull()) /* * Note: if this method returns null, an error has occurred and must be @@ -401,7 +397,7 @@ CallArgsFromSp(unsigned argc, Value *sp) MOZ_ALWAYS_INLINE JS::Value JS_THIS(JSContext *cx, JS::Value *vp) { - return JSVAL_IS_PRIMITIVE(vp[1]) ? JS_ComputeThis(cx, vp) : vp[1]; + return vp[1].isPrimitive() ? JS_ComputeThis(cx, vp) : vp[1]; } /* diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/CallNonGenericMethod.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/CallNonGenericMethod.h index 05097f0294..ad9a7f708c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/CallNonGenericMethod.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/CallNonGenericMethod.h @@ -14,7 +14,7 @@ namespace JS { // Returns true if |v| is considered an acceptable this-value. -typedef bool (*IsAcceptableThis)(Handle v); +typedef bool (*IsAcceptableThis)(HandleValue v); // Implements the guts of a method; guaranteed to be provided an acceptable // this-value, as determined by a corresponding IsAcceptableThis method. @@ -92,7 +92,7 @@ CallMethodIfWrapped(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallA // tail position in a JSNative. Do not call it from any other place. // template -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool CallNonGenericMethod(JSContext *cx, CallArgs args) { HandleValue thisv = args.thisv(); @@ -102,7 +102,7 @@ CallNonGenericMethod(JSContext *cx, CallArgs args) return detail::CallMethodIfWrapped(cx, Test, Impl, args); } -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool CallNonGenericMethod(JSContext *cx, IsAcceptableThis Test, NativeImpl Impl, CallArgs args) { HandleValue thisv = args.thisv(); diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/CharacterEncoding.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/CharacterEncoding.h index 7918b83484..45c77761b3 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/CharacterEncoding.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/CharacterEncoding.h @@ -17,6 +17,8 @@ namespace js { struct ThreadSafeContext; } +class JSFlatString; + namespace JS { /* @@ -25,40 +27,45 @@ namespace JS { * byte is treated as a 2-byte character, and there is no way to pass in a * string containing characters beyond U+00FF. */ -class Latin1Chars : public mozilla::Range +class Latin1Chars : public mozilla::Range { - typedef mozilla::Range Base; + typedef mozilla::Range Base; public: Latin1Chars() : Base() {} - Latin1Chars(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) {} + Latin1Chars(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) {} + Latin1Chars(const Latin1Char *aBytes, size_t aLength) + : Base(const_cast(aBytes), aLength) + {} Latin1Chars(const char *aBytes, size_t aLength) - : Base(reinterpret_cast(const_cast(aBytes)), aLength) + : Base(reinterpret_cast(const_cast(aBytes)), aLength) {} }; /* * A Latin1Chars, but with \0 termination for C compatibility. */ -class Latin1CharsZ : public mozilla::RangedPtr +class Latin1CharsZ : public mozilla::RangedPtr { - typedef mozilla::RangedPtr Base; + typedef mozilla::RangedPtr Base; public: Latin1CharsZ() : Base(nullptr, 0) {} Latin1CharsZ(char *aBytes, size_t aLength) - : Base(reinterpret_cast(aBytes), aLength) + : Base(reinterpret_cast(aBytes), aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } - Latin1CharsZ(unsigned char *aBytes, size_t aLength) + Latin1CharsZ(Latin1Char *aBytes, size_t aLength) : Base(aBytes, aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } + using Base::operator=; + char *c_str() { return reinterpret_cast(get()); } }; @@ -89,15 +96,17 @@ class UTF8CharsZ : public mozilla::RangedPtr UTF8CharsZ(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } UTF8CharsZ(unsigned char *aBytes, size_t aLength) : Base(aBytes, aLength) { - JS_ASSERT(aBytes[aLength] == '\0'); + MOZ_ASSERT(aBytes[aLength] == '\0'); } + using Base::operator=; + char *c_str() { return reinterpret_cast(get()); } }; @@ -119,21 +128,6 @@ class TwoByteChars : public mozilla::Range TwoByteChars(const jschar *aChars, size_t aLength) : Base(const_cast(aChars), aLength) {} }; -/* - * A non-convertible variant of TwoByteChars that does not refer to characters - * inlined inside a JSShortString or a JSInlineString. StableTwoByteChars are - * thus safe to hold across a GC. - */ -class StableTwoByteChars : public mozilla::Range -{ - typedef mozilla::Range Base; - - public: - StableTwoByteChars() : Base() {} - StableTwoByteChars(jschar *aChars, size_t aLength) : Base(aChars, aLength) {} - StableTwoByteChars(const jschar *aChars, size_t aLength) : Base(const_cast(aChars), aLength) {} -}; - /* * A TwoByteChars, but \0 terminated for compatibility with JSFlatString. */ @@ -147,10 +141,31 @@ class TwoByteCharsZ : public mozilla::RangedPtr TwoByteCharsZ(jschar *chars, size_t length) : Base(chars, length) { - JS_ASSERT(chars[length] == '\0'); + MOZ_ASSERT(chars[length] == '\0'); } + + using Base::operator=; }; +typedef mozilla::RangedPtr ConstCharPtr; + +/* + * Like TwoByteChars, but the chars are const. + */ +class ConstTwoByteChars : public mozilla::RangedPtr +{ + public: + ConstTwoByteChars(const ConstTwoByteChars &s) : ConstCharPtr(s) {} + MOZ_IMPLICIT ConstTwoByteChars(const mozilla::RangedPtr &s) : ConstCharPtr(s) {} + ConstTwoByteChars(const jschar *s, size_t len) : ConstCharPtr(s, len) {} + ConstTwoByteChars(const jschar *pos, const jschar *start, size_t len) + : ConstCharPtr(pos, start, len) + {} + + using ConstCharPtr::operator=; +}; + + /* * Convert a 2-byte character sequence to "ISO-Latin-1". This works by * truncating each 2-byte pair in the sequence to a 1-byte pair. If the source @@ -162,10 +177,12 @@ class TwoByteCharsZ : public mozilla::RangedPtr * This method cannot trigger GC. */ extern Latin1CharsZ -LossyTwoByteCharsToNewLatin1CharsZ(js::ThreadSafeContext *cx, TwoByteChars tbchars); +LossyTwoByteCharsToNewLatin1CharsZ(js::ThreadSafeContext *cx, + const mozilla::Range tbchars); +template extern UTF8CharsZ -TwoByteCharsToNewUTF8CharsZ(js::ThreadSafeContext *cx, TwoByteChars tbchars); +CharsToNewUTF8CharsZ(js::ThreadSafeContext *cx, const mozilla::Range chars); uint32_t Utf8ToOneUcs4Char(const uint8_t *utf8Buffer, int utf8Length); @@ -187,6 +204,20 @@ UTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen) extern TwoByteCharsZ LossyUTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen); +/* + * Returns the length of the char buffer required to encode |s| as UTF8. + * Does not include the null-terminator. + */ +JS_PUBLIC_API(size_t) +GetDeflatedUTF8StringLength(JSFlatString *s); + +/* + * Encode |src| as UTF8. The caller must ensure |dst| has enough space. + * Does not write the null terminator. + */ +JS_PUBLIC_API(void) +DeflateStringToUTF8Buffer(JSFlatString *src, mozilla::RangedPtr dst); + } // namespace JS inline void JS_free(JS::Latin1CharsZ &ptr) { js_free((void*)ptr.get()); } diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/Class.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/Class.h index b908fe1604..559cc65c85 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/Class.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/Class.h @@ -24,126 +24,20 @@ * object behavior and, e.g., allows custom slow layout. */ -class JSFreeOp; +struct JSFreeOp; +struct JSFunctionSpec; namespace js { -class Class; +struct Class; class FreeOp; -class PropertyId; class PropertyName; class Shape; -class SpecialId; // This is equal to JSFunction::class_. Use it in places where you don't want // to #include jsfun.h. extern JS_FRIEND_DATA(const js::Class* const) FunctionClassPtr; -static JS_ALWAYS_INLINE jsid -SPECIALID_TO_JSID(const SpecialId &sid); - -/* - * We partition the ways to refer to a property into three: by an index - * (uint32_t); by a string whose characters do not represent an index - * (PropertyName, see vm/String.h); and by various special values. - * - * Special values are encoded using SpecialId, which is layout-compatible but - * non-interconvertible with jsid. A SpecialId is used for JSID_VOID, which - * does not occur in JS scripts but may be used to indicate the absence of a - * valid identifier. In the future, a SpecialId may also be an object used by - * Harmony-proposed private names. - */ -class SpecialId -{ - uintptr_t bits_; - - /* Needs access to raw bits. */ - friend JS_ALWAYS_INLINE jsid SPECIALID_TO_JSID(const SpecialId &sid); - friend class PropertyId; - - static const uintptr_t TYPE_VOID = JSID_TYPE_VOID; - static const uintptr_t TYPE_OBJECT = JSID_TYPE_OBJECT; - static const uintptr_t TYPE_MASK = JSID_TYPE_MASK; - - SpecialId(uintptr_t bits) : bits_(bits) { } - - public: - SpecialId() : bits_(TYPE_VOID) { } - - /* Object-valued */ - - SpecialId(JSObject &obj) - : bits_(uintptr_t(&obj) | TYPE_OBJECT) - { - JS_ASSERT(&obj != nullptr); - JS_ASSERT((uintptr_t(&obj) & TYPE_MASK) == 0); - } - - bool isObject() const { - return (bits_ & TYPE_MASK) == TYPE_OBJECT && bits_ != TYPE_OBJECT; - } - - JSObject *toObject() const { - JS_ASSERT(isObject()); - return reinterpret_cast(bits_ & ~TYPE_MASK); - } - - /* Empty */ - - static SpecialId empty() { - SpecialId sid(TYPE_OBJECT); - JS_ASSERT(sid.isEmpty()); - return sid; - } - - bool isEmpty() const { - return bits_ == TYPE_OBJECT; - } - - /* Void */ - - static SpecialId voidId() { - SpecialId sid(TYPE_VOID); - JS_ASSERT(sid.isVoid()); - return sid; - } - - bool isVoid() const { - return bits_ == TYPE_VOID; - } -}; - -static JS_ALWAYS_INLINE jsid -SPECIALID_TO_JSID(const SpecialId &sid) -{ - jsid id; - JSID_BITS(id) = sid.bits_; - JS_ASSERT_IF(sid.isObject(), JSID_IS_OBJECT(id) && JSID_TO_OBJECT(id) == sid.toObject()); - JS_ASSERT_IF(sid.isVoid(), JSID_IS_VOID(id)); - JS_ASSERT_IF(sid.isEmpty(), JSID_IS_EMPTY(id)); - return id; -} - -static JS_ALWAYS_INLINE bool -JSID_IS_SPECIAL(jsid id) -{ - return JSID_IS_OBJECT(id) || JSID_IS_EMPTY(id) || JSID_IS_VOID(id); -} - -static JS_ALWAYS_INLINE SpecialId -JSID_TO_SPECIALID(jsid id) -{ - JS_ASSERT(JSID_IS_SPECIAL(id)); - if (JSID_IS_OBJECT(id)) - return SpecialId(*JSID_TO_OBJECT(id)); - if (JSID_IS_EMPTY(id)) - return SpecialId::empty(); - JS_ASSERT(JSID_IS_VOID(id)); - return SpecialId::voidId(); -} - -typedef JS::Handle HandleSpecialId; - } // namespace js // JSClass operation signatures. @@ -152,8 +46,8 @@ typedef JS::Handle HandleSpecialId; // be a string (Unicode property identifier) or an int (element index). The // *vp out parameter, on success, is the new property value after the action. typedef bool -(* JSPropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - JS::MutableHandle vp); +(* JSPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); // Set a property named by id in obj, treating the assignment as strict // mode code if strict is true. Note the jsid id type -- id may be a string @@ -161,8 +55,8 @@ typedef bool // parameter, on success, is the new property value after the // set. typedef bool -(* JSStrictPropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - bool strict, JS::MutableHandle vp); +(* JSStrictPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool strict, JS::MutableHandleValue vp); // Delete a property named by id in obj. // @@ -178,7 +72,7 @@ typedef bool // property, or an inherited property, is allowed -- it's just pointless), // set *succeeded to true and return true. typedef bool -(* JSDeletePropertyOp)(JSContext *cx, JS::Handle obj, JS::Handle id, +(* JSDeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); // This function type is used for callbacks that enumerate the properties of @@ -212,13 +106,13 @@ typedef bool // The return value is used to indicate success, with a value of false // indicating failure. typedef bool -(* JSNewEnumerateOp)(JSContext *cx, JS::Handle obj, JSIterateOp enum_op, - JS::MutableHandle statep, JS::MutableHandle idp); +(* JSNewEnumerateOp)(JSContext *cx, JS::HandleObject obj, JSIterateOp enum_op, + JS::MutableHandleValue statep, JS::MutableHandleId idp); // The old-style JSClass.enumerate op should define all lazy properties not // yet reflected in obj. typedef bool -(* JSEnumerateOp)(JSContext *cx, JS::Handle obj); +(* JSEnumerateOp)(JSContext *cx, JS::HandleObject obj); // Resolve a lazy property named by id in obj by defining it directly in obj. // Lazy properties are those reflected from some peer native property space @@ -231,27 +125,24 @@ typedef bool // // NB: JSNewResolveOp provides a cheaper way to resolve lazy properties. typedef bool -(* JSResolveOp)(JSContext *cx, JS::Handle obj, JS::Handle id); +(* JSResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); -// Like JSResolveOp, but flags provide contextual information as follows: -// -// JSRESOLVE_ASSIGNING obj[id] is on the left-hand side of an assignment -// -// The *objp out parameter, on success, should be null to indicate that id -// was not resolved; and non-null, referring to obj or one of its prototypes, -// if id was resolved. The hook may assume *objp is null on entry. +// Like JSResolveOp, except the *objp out parameter, on success, should be null +// to indicate that id was not resolved; and non-null, referring to obj or one +// of its prototypes, if id was resolved. The hook may assume *objp is null on +// entry. // // This hook instead of JSResolveOp is called via the JSClass.resolve member // if JSCLASS_NEW_RESOLVE is set in JSClass.flags. typedef bool -(* JSNewResolveOp)(JSContext *cx, JS::Handle obj, JS::Handle id, unsigned flags, - JS::MutableHandle objp); +(* JSNewResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleObject objp); // Convert obj to the given type, returning true with the resulting value in // *vp on success, and returning false on error or exception. typedef bool -(* JSConvertOp)(JSContext *cx, JS::Handle obj, JSType type, - JS::MutableHandle vp); +(* JSConvertOp)(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); // Finalize obj, which the garbage collector has determined to be unreachable // from other live objects or from GC roots. Obviously, finalizers must never @@ -264,25 +155,11 @@ struct JSStringFinalizer { void (*finalize)(const JSStringFinalizer *fin, jschar *chars); }; -// JSClass.checkAccess type: check whether obj[id] may be accessed per mode, -// returning false on error/exception, true on success with obj[id]'s last-got -// value in *vp, and its attributes in *attrsp. As for JSPropertyOp above, id -// is either a string or an int jsval. -typedef bool -(* JSCheckAccessOp)(JSContext *cx, JS::Handle obj, JS::Handle id, - JSAccessMode mode, JS::MutableHandle vp); - -// Return whether the first principal subsumes the second. The exact meaning of -// 'subsumes' is left up to the browser. Subsumption is checked inside the JS -// engine when determining, e.g., which stack frames to display in a backtrace. -typedef bool -(* JSSubsumesOp)(JSPrincipals *first, JSPrincipals *second); - // Check whether v is an instance of obj. Return false on error or exception, // true on success with true in *bp if v is an instance of obj, false in // *bp otherwise. typedef bool -(* JSHasInstanceOp)(JSContext *cx, JS::Handle obj, JS::MutableHandle vp, +(* JSHasInstanceOp)(JSContext *cx, JS::HandleObject obj, JS::MutableHandleValue vp, bool *bp); // Function type for trace operation of the class called to enumerate all @@ -300,11 +177,6 @@ typedef bool typedef void (* JSTraceOp)(JSTracer *trc, JSObject *obj); -// A generic type for functions mapping an object to another object, or null -// if an error or exception was thrown on cx. -typedef JSObject * -(* JSObjectOp)(JSContext *cx, JS::Handle obj); - // Hook that creates an iterator object for a given object. Returns the // iterator object or null if an error or exception was thrown on cx. typedef JSObject * @@ -327,9 +199,6 @@ typedef bool (* LookupElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleObject objp, JS::MutableHandle propp); typedef bool -(* LookupSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::MutableHandleObject objp, JS::MutableHandle propp); -typedef bool (* DefineGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); typedef bool @@ -340,10 +209,6 @@ typedef bool (* DefineElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); typedef bool -(* DefineSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); -typedef bool (* GenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, JS::MutableHandleValue vp); typedef bool @@ -353,12 +218,6 @@ typedef bool (* ElementIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, JS::MutableHandleValue vp); typedef bool -(* ElementIfPresentOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, - uint32_t index, JS::MutableHandleValue vp, bool* present); -typedef bool -(* SpecialIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, - HandleSpecialId sid, JS::MutableHandleValue vp); -typedef bool (* StrictGenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, bool strict); typedef bool @@ -368,20 +227,12 @@ typedef bool (* StrictElementIdOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp, bool strict); typedef bool -(* StrictSpecialIdOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, - JS::MutableHandleValue vp, bool strict); -typedef bool (* GenericAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); typedef bool (* PropertyAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, unsigned *attrsp); typedef bool -(* DeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, - bool *succeeded); -typedef bool -(* DeleteElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded); -typedef bool -(* DeleteSpecialOp)(JSContext *cx, JS::HandleObject obj, HandleSpecialId sid, bool *succeeded); +(* DeleteGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); typedef bool (* WatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); @@ -389,12 +240,23 @@ typedef bool typedef bool (* UnwatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); +typedef bool +(* SliceOp)(JSContext *cx, JS::HandleObject obj, uint32_t begin, uint32_t end, + JS::HandleObject result); // result is actually preallocted. + +// A generic type for functions mapping an object to another object, or null +// if an error or exception was thrown on cx. typedef JSObject * (* ObjectOp)(JSContext *cx, JS::HandleObject obj); + +// Hook to map an object to its inner object. Infallible. +typedef JSObject * +(* InnerObjectOp)(JSObject *obj); + typedef void (* FinalizeOp)(FreeOp *fop, JSObject *obj); -#define JS_CLASS_MEMBERS \ +#define JS_CLASS_MEMBERS(FinalizeOpType) \ const char *name; \ uint32_t flags; \ \ @@ -408,26 +270,34 @@ typedef void JSConvertOp convert; \ \ /* Optional members (may be null). */ \ - FinalizeOp finalize; \ - JSCheckAccessOp checkAccess; \ + FinalizeOpType finalize; \ JSNative call; \ JSHasInstanceOp hasInstance; \ JSNative construct; \ JSTraceOp trace -/* - * The helper struct to measure the size of JS_CLASS_MEMBERS to know how much - * we have to pad js::Class to match the size of JSClass. - */ -struct ClassSizeMeasurement +// Callback for the creation of constructor and prototype objects. +typedef JSObject *(*ClassObjectCreationOp)(JSContext *cx, JSProtoKey key); + +// Callback for custom post-processing after class initialization via ClassSpec. +typedef bool (*FinishClassInitOp)(JSContext *cx, JS::HandleObject ctor, + JS::HandleObject proto); + +struct ClassSpec { - JS_CLASS_MEMBERS; + ClassObjectCreationOp createConstructor; + ClassObjectCreationOp createPrototype; + const JSFunctionSpec *constructorFunctions; + const JSFunctionSpec *prototypeFunctions; + const JSPropertySpec *prototypeProperties; + FinishClassInitOp finishInit; + bool defined() const { return !!createConstructor; } }; struct ClassExtension { - JSObjectOp outerObject; - JSObjectOp innerObject; + ObjectOp outerObject; + InnerObjectOp innerObject; JSIteratorOp iteratorObject; /* @@ -450,6 +320,7 @@ struct ClassExtension JSWeakmapKeyDelegateOp weakmapKeyDelegateOp; }; +#define JS_NULL_CLASS_SPEC {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr} #define JS_NULL_CLASS_EXT {nullptr,nullptr,nullptr,false,nullptr} struct ObjectOps @@ -457,36 +328,29 @@ struct ObjectOps LookupGenericOp lookupGeneric; LookupPropOp lookupProperty; LookupElementOp lookupElement; - LookupSpecialOp lookupSpecial; DefineGenericOp defineGeneric; DefinePropOp defineProperty; DefineElementOp defineElement; - DefineSpecialOp defineSpecial; GenericIdOp getGeneric; PropertyIdOp getProperty; ElementIdOp getElement; - ElementIfPresentOp getElementIfPresent; /* can be null */ - SpecialIdOp getSpecial; StrictGenericIdOp setGeneric; StrictPropertyIdOp setProperty; StrictElementIdOp setElement; - StrictSpecialIdOp setSpecial; GenericAttributesOp getGenericAttributes; GenericAttributesOp setGenericAttributes; - DeletePropertyOp deleteProperty; - DeleteElementOp deleteElement; - DeleteSpecialOp deleteSpecial; + DeleteGenericOp deleteGeneric; WatchOp watch; UnwatchOp unwatch; - + SliceOp slice; // Optimized slice, can be null. JSNewEnumerateOp enumerate; ObjectOp thisObject; }; #define JS_NULL_OBJECT_OPS \ - {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, \ - nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, \ - nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr} + {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr} } // namespace js @@ -495,27 +359,9 @@ struct ObjectOps typedef void (*JSClassInternal)(); struct JSClass { - const char *name; - uint32_t flags; - - // Mandatory function pointer members. - JSPropertyOp addProperty; - JSDeletePropertyOp delProperty; - JSPropertyOp getProperty; - JSStrictPropertyOp setProperty; - JSEnumerateOp enumerate; - JSResolveOp resolve; - JSConvertOp convert; - - // Optional members (may be null). - JSFinalizeOp finalize; - JSCheckAccessOp checkAccess; - JSNative call; - JSHasInstanceOp hasInstance; - JSNative construct; - JSTraceOp trace; - - void *reserved[42]; + JS_CLASS_MEMBERS(JSFinalizeOp); + + void *reserved[31]; }; #define JSCLASS_HAS_PRIVATE (1<<0) // objects have private slot @@ -550,9 +396,9 @@ struct JSClass { #define JSCLASS_INTERNAL_FLAG2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2)) #define JSCLASS_INTERNAL_FLAG3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3)) -// Indicate whether the proto or ctor should be frozen. -#define JSCLASS_FREEZE_PROTO (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4)) -#define JSCLASS_FREEZE_CTOR (1<<(JSCLASS_HIGH_FLAGS_SHIFT+5)) +#define JSCLASS_IS_PROXY (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4)) + +// Bit 22 unused. // Reserved for embeddings. #define JSCLASS_USERBIT2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+6)) @@ -573,7 +419,11 @@ struct JSClass { // with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS was // previously allowed, but is now an ES5 violation and thus unsupported. // -#define JSCLASS_GLOBAL_SLOT_COUNT (3 + JSProto_LIMIT * 3 + 27) +// JSCLASS_GLOBAL_APPLICATION_SLOTS is the number of slots reserved at +// the beginning of every global object's slots for use by the +// application. +#define JSCLASS_GLOBAL_APPLICATION_SLOTS 3 +#define JSCLASS_GLOBAL_SLOT_COUNT (JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 3 + 30) #define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n) \ (JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + (n))) #define JSCLASS_GLOBAL_FLAGS \ @@ -600,11 +450,10 @@ namespace js { struct Class { - JS_CLASS_MEMBERS; + JS_CLASS_MEMBERS(FinalizeOp); + ClassSpec spec; ClassExtension ext; ObjectOps ops; - uint8_t pad[sizeof(JSClass) - sizeof(ClassSizeMeasurement) - - sizeof(ClassExtension) - sizeof(ObjectOps)]; /* Class is not native and its map is not a scope. */ static const uint32_t NON_NATIVE = JSCLASS_INTERNAL_FLAG2; @@ -621,8 +470,20 @@ struct Class return flags & JSCLASS_EMULATES_UNDEFINED; } + bool isJSFunction() const { + return this == js::FunctionClassPtr; + } + bool isCallable() const { - return this == js::FunctionClassPtr || call; + return isJSFunction() || call; + } + + bool isProxy() const { + return flags & JSCLASS_IS_PROXY; + } + + bool isDOMClass() const { + return flags & JSCLASS_IS_DOMJSCLASS; } static size_t offsetOfFlags() { return offsetof(Class, flags); } @@ -638,20 +499,19 @@ JS_STATIC_ASSERT(offsetof(JSClass, enumerate) == offsetof(Class, enumerate)); JS_STATIC_ASSERT(offsetof(JSClass, resolve) == offsetof(Class, resolve)); JS_STATIC_ASSERT(offsetof(JSClass, convert) == offsetof(Class, convert)); JS_STATIC_ASSERT(offsetof(JSClass, finalize) == offsetof(Class, finalize)); -JS_STATIC_ASSERT(offsetof(JSClass, checkAccess) == offsetof(Class, checkAccess)); JS_STATIC_ASSERT(offsetof(JSClass, call) == offsetof(Class, call)); JS_STATIC_ASSERT(offsetof(JSClass, construct) == offsetof(Class, construct)); JS_STATIC_ASSERT(offsetof(JSClass, hasInstance) == offsetof(Class, hasInstance)); JS_STATIC_ASSERT(offsetof(JSClass, trace) == offsetof(Class, trace)); JS_STATIC_ASSERT(sizeof(JSClass) == sizeof(Class)); -static JS_ALWAYS_INLINE const JSClass * +static MOZ_ALWAYS_INLINE const JSClass * Jsvalify(const Class *c) { return (const JSClass *)c; } -static JS_ALWAYS_INLINE const Class * +static MOZ_ALWAYS_INLINE const Class * Valueify(const JSClass *c) { return (const Class *)c; @@ -679,21 +539,6 @@ ObjectClassIs(JSObject &obj, ESClassValue classValue, JSContext *cx); inline bool IsObjectWithClass(const JS::Value &v, ESClassValue classValue, JSContext *cx); -inline bool -IsPoisonedSpecialId(js::SpecialId iden) -{ - if (iden.isObject()) - return JS::IsPoisonedPtr(iden.toObject()); - return false; -} - -template <> struct GCMethods -{ - static SpecialId initial() { return SpecialId(); } - static ThingRootKind kind() { return THING_ROOT_ID; } - static bool poisoned(SpecialId id) { return IsPoisonedSpecialId(id); } -}; - } /* namespace js */ #endif /* js_Class_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/GCAPI.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/GCAPI.h index 190b781060..c58d62d029 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/GCAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/GCAPI.h @@ -10,8 +10,26 @@ #include "mozilla/NullPtr.h" #include "js/HeapAPI.h" -#include "js/RootingAPI.h" -#include "js/Value.h" + +namespace js { +namespace gc { +class GCRuntime; +} +} + +typedef enum JSGCMode { + /* Perform only global GCs. */ + JSGC_MODE_GLOBAL = 0, + + /* Perform per-compartment GCs until too much garbage has accumulated. */ + JSGC_MODE_COMPARTMENT = 1, + + /* + * Collect in short time slices rather than all at once. Implies + * JSGC_MODE_COMPARTMENT. + */ + JSGC_MODE_INCREMENTAL = 2 +} JSGCMode; namespace JS { @@ -95,40 +113,117 @@ enum Reason { } /* namespace gcreason */ +/* + * Zone GC: + * + * SpiderMonkey's GC is capable of performing a collection on an arbitrary + * subset of the zones in the system. This allows an embedding to minimize + * collection time by only collecting zones that have run code recently, + * ignoring the parts of the heap that are unlikely to have changed. + * + * When triggering a GC using one of the functions below, it is first necessary + * to select the zones to be collected. To do this, you can call + * PrepareZoneForGC on each zone, or you can call PrepareForFullGC to select + * all zones. Failing to select any zone is an error. + */ + +/* + * Schedule the given zone to be collected as part of the next GC. + */ extern JS_FRIEND_API(void) PrepareZoneForGC(Zone *zone); +/* + * Schedule all zones to be collected in the next GC. + */ extern JS_FRIEND_API(void) PrepareForFullGC(JSRuntime *rt); +/* + * When performing an incremental GC, the zones that were selected for the + * previous incremental slice must be selected in subsequent slices as well. + * This function selects those slices automatically. + */ extern JS_FRIEND_API(void) PrepareForIncrementalGC(JSRuntime *rt); +/* + * Returns true if any zone in the system has been scheduled for GC with one of + * the functions above or by the JS engine. + */ extern JS_FRIEND_API(bool) IsGCScheduled(JSRuntime *rt); +/* + * Undoes the effect of the Prepare methods above. The given zone will not be + * collected in the next GC. + */ extern JS_FRIEND_API(void) SkipZoneForGC(Zone *zone); /* - * When triggering a GC using one of the functions below, it is first necessary - * to select the compartments to be collected. To do this, you can call - * PrepareZoneForGC on each compartment, or you can call PrepareForFullGC - * to select all compartments. Failing to select any compartment is an error. + * Non-Incremental GC: + * + * The following functions perform a non-incremental GC. */ +/* + * Performs a non-incremental collection of all selected zones. Some objects + * that are unreachable from the program may still be alive afterwards because + * of internal references. + */ extern JS_FRIEND_API(void) GCForReason(JSRuntime *rt, gcreason::Reason reason); +/* + * Perform a non-incremental collection after clearing caches and other + * temporary references to objects. This will remove all unreferenced objects + * in the system. + */ extern JS_FRIEND_API(void) ShrinkingGC(JSRuntime *rt, gcreason::Reason reason); -extern JS_FRIEND_API(void) -ShrinkGCBuffers(JSRuntime *rt); +/* + * Incremental GC: + * + * Incremental GC divides the full mark-and-sweep collection into multiple + * slices, allowing client JavaScript code to run between each slice. This + * allows interactive apps to avoid long collection pauses. Incremental GC does + * not make collection take less time, it merely spreads that time out so that + * the pauses are less noticable. + * + * For a collection to be carried out incrementally the following conditions + * must be met: + * - The collection must be run by calling JS::IncrementalGC() rather than + * JS_GC(). + * - The GC mode must have been set to JSGC_MODE_INCREMENTAL with + * JS_SetGCParameter(). + * - All native objects that have their own trace hook must indicate that they + * implement read and write barriers with the JSCLASS_IMPLEMENTS_BARRIERS + * flag. + * + * Note: Even if incremental GC is enabled and working correctly, + * non-incremental collections can still happen when low on memory. + */ +/* + * Begin an incremental collection and perform one slice worth of work or + * perform a slice of an ongoing incremental collection. When this function + * returns, the collection is not complete. This function must be called + * repeatedly until !IsIncrementalGCInProgress(rt). + * + * Note: SpiderMonkey's GC is not realtime. Slices in practice may be longer or + * shorter than the requested interval. + */ extern JS_FRIEND_API(void) IncrementalGC(JSRuntime *rt, gcreason::Reason reason, int64_t millis = 0); +/* + * If IsIncrementalGCInProgress(rt), this call finishes the ongoing collection + * by performing an arbitrarily long slice. If !IsIncrementalGCInProgress(rt), + * this is equivalent to GCForReason. When this function returns, + * IsIncrementalGCInProgress(rt) will always be false. + */ extern JS_FRIEND_API(void) FinishIncrementalGC(JSRuntime *rt, gcreason::Reason reason); @@ -152,7 +247,7 @@ enum GCProgress { struct JS_FRIEND_API(GCDescription) { bool isCompartment_; - GCDescription(bool isCompartment) + explicit GCDescription(bool isCompartment) : isCompartment_(isCompartment) {} jschar *formatMessage(JSRuntime *rt) const; @@ -162,37 +257,56 @@ struct JS_FRIEND_API(GCDescription) { typedef void (* GCSliceCallback)(JSRuntime *rt, GCProgress progress, const GCDescription &desc); +/* + * The GC slice callback is called at the beginning and end of each slice. This + * callback may be used for GC notifications as well as to perform additional + * marking. + */ extern JS_FRIEND_API(GCSliceCallback) SetGCSliceCallback(JSRuntime *rt, GCSliceCallback callback); /* - * Signals a good place to do an incremental slice, because the browser is - * drawing a frame. + * Incremental GC defaults to enabled, but may be disabled for testing or in + * embeddings that have not yet implemented barriers on their native classes. + * There is not currently a way to re-enable incremental GC once it has been + * disabled on the runtime. */ extern JS_FRIEND_API(void) -NotifyDidPaint(JSRuntime *rt); +DisableIncrementalGC(JSRuntime *rt); +/* + * Returns true if incremental GC is enabled. Simply having incremental GC + * enabled is not sufficient to ensure incremental collections are happening. + * See the comment "Incremental GC" above for reasons why incremental GC may be + * suppressed. Inspection of the "nonincremental reason" field of the + * GCDescription returned by GCSliceCallback may help narrow down the cause if + * collections are not happening incrementally when expected. + */ extern JS_FRIEND_API(bool) IsIncrementalGCEnabled(JSRuntime *rt); +/* + * Returns true while an incremental GC is ongoing, both when actively + * collecting and between slices. + */ JS_FRIEND_API(bool) IsIncrementalGCInProgress(JSRuntime *rt); -extern JS_FRIEND_API(void) -DisableIncrementalGC(JSRuntime *rt); - -extern JS_FRIEND_API(void) -DisableGenerationalGC(JSRuntime *rt); - -extern JS_FRIEND_API(void) -EnableGenerationalGC(JSRuntime *rt); - +/* + * Returns true when writes to GC things must call an incremental (pre) barrier. + * This is generally only true when running mutator code in-between GC slices. + * At other times, the barrier may be elided for performance. + */ extern JS_FRIEND_API(bool) IsIncrementalBarrierNeeded(JSRuntime *rt); extern JS_FRIEND_API(bool) IsIncrementalBarrierNeeded(JSContext *cx); +/* + * Notify the GC that a reference to a GC thing is about to be overwritten. + * These methods must be called if IsIncrementalBarrierNeeded. + */ extern JS_FRIEND_API(void) IncrementalReferenceBarrier(void *ptr, JSGCTraceKind kind); @@ -202,73 +316,118 @@ IncrementalValueBarrier(const Value &v); extern JS_FRIEND_API(void) IncrementalObjectBarrier(JSObject *obj); -extern JS_FRIEND_API(void) -PokeGC(JSRuntime *rt); - -/* Was the most recent GC run incrementally? */ +/* + * Returns true if the most recent GC ran incrementally. + */ extern JS_FRIEND_API(bool) WasIncrementalGC(JSRuntime *rt); +/* + * Generational GC: + * + * Note: Generational GC is not yet enabled by default. The following class + * is non-functional unless SpiderMonkey was configured with + * --enable-gcgenerational. + */ + +/* Ensure that generational GC is disabled within some scope. */ +class JS_FRIEND_API(AutoDisableGenerationalGC) +{ + js::gc::GCRuntime *gc; +#if defined(JSGC_GENERATIONAL) && defined(JS_GC_ZEAL) + bool restartVerifier; +#endif + + public: + explicit AutoDisableGenerationalGC(JSRuntime *rt); + ~AutoDisableGenerationalGC(); +}; + +/* + * Returns true if generational allocation and collection is currently enabled + * on the given runtime. + */ +extern JS_FRIEND_API(bool) +IsGenerationalGCEnabled(JSRuntime *rt); + +/* + * Returns the GC's "number". This does not correspond directly to the number + * of GCs that have been run, but is guaranteed to be monotonically increasing + * with GC activity. + */ extern JS_FRIEND_API(size_t) GetGCNumber(); -class JS_PUBLIC_API(AutoAssertNoGC) +/* + * The GC does not immediately return the unused memory freed by a collection + * back to the system incase it is needed soon afterwards. This call forces the + * GC to return this memory immediately. + */ +extern JS_FRIEND_API(void) +ShrinkGCBuffers(JSRuntime *rt); + +/* + * Assert if a GC occurs while this class is live. This class does not disable + * the static rooting hazard analysis. + */ +class JS_PUBLIC_API(AutoAssertOnGC) { #ifdef DEBUG - JSRuntime *runtime; + js::gc::GCRuntime *gc; size_t gcNumber; public: - AutoAssertNoGC(); - AutoAssertNoGC(JSRuntime *rt); - ~AutoAssertNoGC(); + AutoAssertOnGC(); + explicit AutoAssertOnGC(JSRuntime *rt); + ~AutoAssertOnGC(); + + static void VerifyIsSafeToGC(JSRuntime *rt); #else public: - /* Prevent unreferenced local warnings in opt builds. */ - AutoAssertNoGC() {} - AutoAssertNoGC(JSRuntime *) {} + AutoAssertOnGC() {} + explicit AutoAssertOnGC(JSRuntime *rt) {} + ~AutoAssertOnGC() {} + + static void VerifyIsSafeToGC(JSRuntime *rt) {} #endif }; -class JS_PUBLIC_API(ObjectPtr) +/* + * Disable the static rooting hazard analysis in the live region, but assert if + * any GC occurs while this guard object is live. This is most useful to help + * the exact rooting hazard analysis in complex regions, since it cannot + * understand dataflow. + * + * Note: GC behavior is unpredictable even when deterministice and is generally + * non-deterministic in practice. The fact that this guard has not + * asserted is not a guarantee that a GC cannot happen in the guarded + * region. As a rule, anyone performing a GC unsafe action should + * understand the GC properties of all code in that region and ensure + * that the hazard analysis is correct for that code, rather than relying + * on this class. + */ +class JS_PUBLIC_API(AutoSuppressGCAnalysis) : public AutoAssertOnGC { - Heap value; - public: - ObjectPtr() : value(nullptr) {} - - ObjectPtr(JSObject *obj) : value(obj) {} - - /* Always call finalize before the destructor. */ - ~ObjectPtr() { JS_ASSERT(!value); } - - void finalize(JSRuntime *rt) { - if (IsIncrementalBarrierNeeded(rt)) - IncrementalObjectBarrier(value); - value = nullptr; - } - - void init(JSObject *obj) { value = obj; } - - JSObject *get() const { return value; } - - void writeBarrierPre(JSRuntime *rt) { - IncrementalObjectBarrier(value); - } - - bool isAboutToBeFinalized(); - - ObjectPtr &operator=(JSObject *obj) { - IncrementalObjectBarrier(value); - value = obj; - return *this; - } - - void trace(JSTracer *trc, const char *name); + AutoSuppressGCAnalysis() : AutoAssertOnGC() {} + explicit AutoSuppressGCAnalysis(JSRuntime *rt) : AutoAssertOnGC(rt) {} +}; - JSObject &operator*() const { return *value; } - JSObject *operator->() const { return value; } - operator JSObject *() const { return value; } +/* + * Place AutoCheckCannotGC in scopes that you believe can never GC. These + * annotations will be verified both dynamically via AutoAssertOnGC, and + * statically with the rooting hazard analysis (implemented by making the + * analysis consider AutoCheckCannotGC to be a GC pointer, and therefore + * complain if it is live across a GC call.) It is useful when dealing with + * internal pointers to GC things where the GC thing itself may not be present + * for the static analysis: e.g. acquiring inline chars from a JSString* on the + * heap. + */ +class JS_PUBLIC_API(AutoCheckCannotGC) : public AutoAssertOnGC +{ + public: + AutoCheckCannotGC() : AutoAssertOnGC() {} + explicit AutoCheckCannotGC(JSRuntime *rt) : AutoAssertOnGC(rt) {} }; /* @@ -284,10 +443,10 @@ UnmarkGrayGCThingRecursively(void *thing, JSGCTraceKind kind); * data). During incremental GC, since the gray bits haven't been computed yet, * we conservatively mark the object black. */ -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) { - JS_ASSERT(kind != JSTRACE_SHAPE); + MOZ_ASSERT(kind != JSTRACE_SHAPE); shadow::Runtime *rt = js::gc::GetGCThingRuntime(thing); #ifdef JSGC_GENERATIONAL @@ -296,7 +455,7 @@ ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) * All live objects in the nursery are moved to tenured at the beginning of * each GC slice, so the gray marker never sees nursery things. */ - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return; #endif if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) @@ -305,14 +464,7 @@ ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) UnmarkGrayGCThingRecursively(thing, kind); } -static JS_ALWAYS_INLINE void -ExposeValueToActiveJS(const Value &v) -{ - if (v.isMarkable()) - ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); -} - -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void ExposeObjectToActiveJS(JSObject *obj) { ExposeGCThingToActiveJS(obj, JSTRACE_OBJECT); @@ -321,7 +473,7 @@ ExposeObjectToActiveJS(JSObject *obj) /* * If a GC is currently marking, mark the object black. */ -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void MarkGCThingAsLive(JSRuntime *rt_, void *thing, JSGCTraceKind kind) { shadow::Runtime *rt = shadow::Runtime::asShadowRuntime(rt_); @@ -329,20 +481,34 @@ MarkGCThingAsLive(JSRuntime *rt_, void *thing, JSGCTraceKind kind) /* * Any object in the nursery will not be freed during any GC running at that time. */ - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return; #endif if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) IncrementalReferenceBarrier(thing, kind); } -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void MarkStringAsLive(Zone *zone, JSString *string) { JSRuntime *rt = JS::shadow::Zone::asShadowZone(zone)->runtimeFromMainThread(); MarkGCThingAsLive(rt, string, JSTRACE_STRING); } +/* + * Internal to Firefox. + * + * Note: this is not related to the PokeGC in nsJSEnvironment. + */ +extern JS_FRIEND_API(void) +PokeGC(JSRuntime *rt); + +/* + * Internal to Firefox. + */ +extern JS_FRIEND_API(void) +NotifyDidPaint(JSRuntime *rt); + } /* namespace JS */ #endif /* js_GCAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/HashTable.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/HashTable.h index eb98804c8e..4c27308b5e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/HashTable.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/HashTable.h @@ -73,7 +73,7 @@ class HashMap // HashMap construction is fallible (due to OOM); thus the user must call // init after constructing a HashMap and check the return value. - HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} + explicit HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} bool init(uint32_t len = 16) { return impl.init(len); } bool initialized() const { return impl.initialized(); } @@ -159,7 +159,7 @@ class HashMap // typedef HashMap HM; // HM h; // for (HM::Range r = h.all(); !r.empty(); r.popFront()) - // char c = r.front().value; + // char c = r.front().value(); // // Also see the definition of Range in HashTable above (with T = Entry). typedef typename Impl::Range Range; @@ -171,7 +171,7 @@ class HashMap // typedef HashMap HM; // HM s; // for (HM::Enum e(s); !e.empty(); e.popFront()) - // if (e.front().value == 'l') + // if (e.front().value() == 'l') // e.removeFront(); // // Table resize may occur in Enum's destructor. Also see the definition of @@ -182,9 +182,6 @@ class HashMap // using the finish() method. void clear() { impl.clear(); } - // Remove all entries without triggering destructors. This method is unsafe. - void clearWithoutCallingDestructors() { impl.clearWithoutCallingDestructors(); } - // Remove all the entries and release all internal buffers. The map must // be initialized again before any use. void finish() { impl.finish(); } @@ -210,7 +207,7 @@ class HashMap // If |generation()| is the same before and after a HashMap operation, // pointers into the table remain valid. - unsigned generation() const { return impl.generation(); } + uint32_t generation() const { return impl.generation(); } /************************************************** Shorthand operations */ @@ -317,7 +314,7 @@ class HashSet // HashSet construction is fallible (due to OOM); thus the user must call // init after constructing a HashSet and check the return value. - HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} + explicit HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} bool init(uint32_t len = 16) { return impl.init(len); } bool initialized() const { return impl.initialized(); } @@ -438,7 +435,7 @@ class HashSet // If |generation()| is the same before and after a HashSet operation, // pointers into the table remain valid. - unsigned generation() const { return impl.generation(); } + uint32_t generation() const { return impl.generation(); } /************************************************** Shorthand operations */ @@ -482,6 +479,13 @@ class HashSet impl.rekeyAndMaybeRehash(p, new_lookup, new_value); } + // Infallibly rekey one entry with a new key that is equivalent. + void rekeyInPlace(Ptr p, const T &new_value) + { + MOZ_ASSERT(HashPolicy::match(*p, new_value)); + impl.rekeyInPlace(p, new_value); + } + // HashSet is movable HashSet(HashSet &&rhs) : impl(mozilla::Move(rhs.impl)) {} void operator=(HashSet &&rhs) { @@ -531,7 +535,7 @@ struct PointerHasher { typedef Key Lookup; static HashNumber hash(const Lookup &l) { - JS_ASSERT(!JS::IsPoisonedPtr(l)); + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); size_t word = reinterpret_cast(l) >> zeroBits; JS_STATIC_ASSERT(sizeof(HashNumber) == 4); #if JS_BITS_PER_WORD == 32 @@ -542,8 +546,8 @@ struct PointerHasher #endif } static bool match(const Key &k, const Lookup &l) { - JS_ASSERT(!JS::IsPoisonedPtr(k)); - JS_ASSERT(!JS::IsPoisonedPtr(l)); + MOZ_ASSERT(!JS::IsPoisonedPtr(k)); + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); return k == l; } static void rekey(Key &k, const Key& newKey) { @@ -701,7 +705,7 @@ class HashTableEntry } void destroy() { - JS_ASSERT(isLive()); + MOZ_ASSERT(isLive()); mem.addr()->~T(); } @@ -710,16 +714,16 @@ class HashTableEntry mozilla::Swap(mem, other->mem); } - T &get() { JS_ASSERT(isLive()); return *mem.addr(); } + T &get() { MOZ_ASSERT(isLive()); return *mem.addr(); } bool isFree() const { return keyHash == sFreeKey; } - void clearLive() { JS_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); } + void clearLive() { MOZ_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); } void clear() { if (isLive()) mem.addr()->~T(); keyHash = sFreeKey; } bool isRemoved() const { return keyHash == sRemovedKey; } - void removeLive() { JS_ASSERT(isLive()); keyHash = sRemovedKey; mem.addr()->~T(); } + void removeLive() { MOZ_ASSERT(isLive()); keyHash = sRemovedKey; mem.addr()->~T(); } bool isLive() const { return isLiveHash(keyHash); } - void setCollision() { JS_ASSERT(isLive()); keyHash |= sCollisionBit; } - void setCollision(HashNumber bit) { JS_ASSERT(isLive()); keyHash |= bit; } + void setCollision() { MOZ_ASSERT(isLive()); keyHash |= sCollisionBit; } + void setCollision(HashNumber bit) { MOZ_ASSERT(isLive()); keyHash |= bit; } void unsetCollision() { keyHash &= ~sCollisionBit; } bool hasCollision() const { return keyHash & sCollisionBit; } bool matchHash(HashNumber hn) { return (keyHash & ~sCollisionBit) == hn; } @@ -728,16 +732,18 @@ class HashTableEntry template void setLive(HashNumber hn, U &&u) { - JS_ASSERT(!isLive()); + MOZ_ASSERT(!isLive()); keyHash = hn; new(mem.addr()) T(mozilla::Forward(u)); - JS_ASSERT(isLive()); + MOZ_ASSERT(isLive()); } }; template class HashTable : private AllocPolicy { + friend class mozilla::ReentrancyGuard; + typedef typename mozilla::RemoveConst::Type NonConstT; typedef typename HashPolicy::KeyType Key; typedef typename HashPolicy::Lookup Lookup; @@ -756,25 +762,56 @@ class HashTable : private AllocPolicy void nonNull() {} Entry *entry_; +#ifdef DEBUG + const HashTable *table_; + uint32_t generation; +#endif protected: - Ptr(Entry &entry) : entry_(&entry) {} + Ptr(Entry &entry, const HashTable &tableArg) + : entry_(&entry) +#ifdef DEBUG + , table_(&tableArg) + , generation(tableArg.generation()) +#endif + {} public: // Leaves Ptr uninitialized. Ptr() { -#ifdef DEBUG +#ifdef JS_DEBUG entry_ = (Entry *)0xbad; #endif } - bool found() const { return entry_->isLive(); } - operator ConvertibleToBool() const { return found() ? &Ptr::nonNull : 0; } - bool operator==(const Ptr &rhs) const { JS_ASSERT(found() && rhs.found()); return entry_ == rhs.entry_; } - bool operator!=(const Ptr &rhs) const { return !(*this == rhs); } + bool found() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->isLive(); + } - T &operator*() const { return entry_->get(); } - T *operator->() const { return &entry_->get(); } + operator ConvertibleToBool() const { + return found() ? &Ptr::nonNull : 0; + } + + bool operator==(const Ptr &rhs) const { + MOZ_ASSERT(found() && rhs.found()); + return entry_ == rhs.entry_; + } + + bool operator!=(const Ptr &rhs) const { + MOZ_ASSERT(generation == table_->generation()); + return !(*this == rhs); + } + + T &operator*() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->get(); + } + + T *operator->() const { + MOZ_ASSERT(generation == table_->generation()); + return &entry_->get(); + } }; // A Ptr that can be used to add a key after a failed lookup. @@ -782,9 +819,18 @@ class HashTable : private AllocPolicy { friend class HashTable; HashNumber keyHash; - mozilla::DebugOnly mutationCount; +#ifdef DEBUG + uint64_t mutationCount; +#endif + + AddPtr(Entry &entry, const HashTable &tableArg, HashNumber hn) + : Ptr(entry, tableArg) + , keyHash(hn) +#ifdef DEBUG + , mutationCount(tableArg.mutationCount) +#endif + {} - AddPtr(Entry &entry, HashNumber hn) : Ptr(entry), keyHash(hn) {} public: // Leaves AddPtr uninitialized. AddPtr() {} @@ -799,32 +845,63 @@ class HashTable : private AllocPolicy protected: friend class HashTable; - Range(Entry *c, Entry *e) : cur(c), end(e), validEntry(true) { + Range(const HashTable &tableArg, Entry *c, Entry *e) + : cur(c) + , end(e) +#ifdef DEBUG + , table_(&tableArg) + , mutationCount(tableArg.mutationCount) + , generation(tableArg.generation()) + , validEntry(true) +#endif + { while (cur < end && !cur->isLive()) ++cur; } Entry *cur, *end; - mozilla::DebugOnly validEntry; +#ifdef DEBUG + const HashTable *table_; + uint64_t mutationCount; + uint32_t generation; + bool validEntry; +#endif public: - Range() : cur(nullptr), end(nullptr), validEntry(false) {} + Range() + : cur(nullptr) + , end(nullptr) +#ifdef DEBUG + , table_(nullptr) + , mutationCount(0) + , generation(0) + , validEntry(false) +#endif + {} bool empty() const { + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); return cur == end; } T &front() const { - JS_ASSERT(validEntry); - JS_ASSERT(!empty()); + MOZ_ASSERT(validEntry); + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); return cur->get(); } void popFront() { - JS_ASSERT(!empty()); + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); while (++cur < end && !cur->isLive()) continue; +#ifdef DEBUG validEntry = true; +#endif } }; @@ -837,17 +914,17 @@ class HashTable : private AllocPolicy { friend class HashTable; - HashTable &table; + HashTable &table_; bool rekeyed; bool removed; /* Not copyable. */ - Enum(const Enum &); - void operator=(const Enum &); + Enum(const Enum &) MOZ_DELETE; + void operator=(const Enum &) MOZ_DELETE; public: template explicit - Enum(Map &map) : Range(map.all()), table(map.impl), rekeyed(false), removed(false) {} + Enum(Map &map) : Range(map.all()), table_(map.impl), rekeyed(false), removed(false) {} // Removes the |front()| element from the table, leaving |front()| // invalid until the next call to |popFront()|. For example: @@ -857,18 +934,25 @@ class HashTable : private AllocPolicy // if (e.front() == 42) // e.removeFront(); void removeFront() { - table.remove(*this->cur); + table_.remove(*this->cur); removed = true; +#ifdef DEBUG this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif } // Removes the |front()| element and re-inserts it into the table with // a new key at the new Lookup position. |front()| is invalid after // this operation until the next call to |popFront()|. void rekeyFront(const Lookup &l, const Key &k) { - table.rekeyWithoutRehash(*this->cur, l, k); + Ptr p(*this->cur, table_); + table_.rekeyWithoutRehash(p, l, k); rekeyed = true; +#ifdef DEBUG this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif } void rekeyFront(const Key &k) { @@ -878,12 +962,12 @@ class HashTable : private AllocPolicy // Potentially rehashes the table. ~Enum() { if (rekeyed) { - table.gen++; - table.checkOverRemoved(); + table_.gen++; + table_.checkOverRemoved(); } if (removed) - table.compactIfUnderloaded(); + table_.compactIfUnderloaded(); } }; @@ -908,18 +992,18 @@ class HashTable : private AllocPolicy void operator=(const HashTable &) MOZ_DELETE; private: - uint32_t hashShift; // multiplicative hash shift - uint32_t entryCount; // number of entries in table - uint32_t gen; // entry storage generation number - uint32_t removedCount; // removed entry sentinels in table - Entry *table; // entry storage + static const size_t CAP_BITS = 24; - void setTableSizeLog2(unsigned sizeLog2) - { - hashShift = sHashBits - sizeLog2; - } + public: + Entry *table; // entry storage + uint32_t gen; // entry storage generation number + uint32_t entryCount; // number of entries in table + uint32_t removedCount:CAP_BITS; // removed entry sentinels in table + uint32_t hashShift:8; // multiplicative hash shift -#ifdef DEBUG +#ifdef JS_DEBUG + mozilla::DebugOnly mutationCount; + mutable mozilla::DebugOnly mEntered; mutable struct Stats { uint32_t searches; // total number of table searches @@ -939,16 +1023,12 @@ class HashTable : private AllocPolicy # define METER(x) #endif - friend class mozilla::ReentrancyGuard; - mutable mozilla::DebugOnly entered; - mozilla::DebugOnly mutationCount; - // The default initial capacity is 32 (enough to hold 16 elements), but it // can be as low as 4. static const unsigned sMinCapacityLog2 = 2; static const unsigned sMinCapacity = 1 << sMinCapacityLog2; - static const unsigned sMaxInit = JS_BIT(23); - static const unsigned sMaxCapacity = JS_BIT(24); + static const unsigned sMaxInit = JS_BIT(CAP_BITS - 1); + static const unsigned sMaxCapacity = JS_BIT(CAP_BITS); static const unsigned sHashBits = mozilla::tl::BitSize::value; // Hash-table alpha is conceptually a fraction, but to avoid floating-point @@ -961,6 +1041,11 @@ class HashTable : private AllocPolicy static const HashNumber sRemovedKey = Entry::sRemovedKey; static const HashNumber sCollisionBit = Entry::sCollisionBit; + void setTableSizeLog2(unsigned sizeLog2) + { + hashShift = sHashBits - sizeLog2; + } + static bool isLiveHash(HashNumber hash) { return Entry::isLiveHash(hash); @@ -993,20 +1078,22 @@ class HashTable : private AllocPolicy } public: - HashTable(AllocPolicy ap) - : AllocPolicy(ap), - hashShift(sHashBits), - entryCount(0), - gen(0), - removedCount(0), - table(nullptr), - entered(false), - mutationCount(0) + explicit HashTable(AllocPolicy ap) + : AllocPolicy(ap) + , table(nullptr) + , gen(0) + , entryCount(0) + , removedCount(0) + , hashShift(sHashBits) +#ifdef DEBUG + , mutationCount(0) + , mEntered(false) +#endif {} MOZ_WARN_UNUSED_RESULT bool init(uint32_t length) { - JS_ASSERT(!initialized()); + MOZ_ASSERT(!initialized()); // Reject all lengths whose initial computed capacity would exceed // sMaxCapacity. Round that maximum length down to the nearest power @@ -1116,10 +1203,10 @@ class HashTable : private AllocPolicy Entry &lookup(const Lookup &l, HashNumber keyHash, unsigned collisionBit) const { - JS_ASSERT(isLiveHash(keyHash)); - JS_ASSERT(!(keyHash & sCollisionBit)); - JS_ASSERT(collisionBit == 0 || collisionBit == sCollisionBit); - JS_ASSERT(table); + MOZ_ASSERT(isLiveHash(keyHash)); + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(collisionBit == 0 || collisionBit == sCollisionBit); + MOZ_ASSERT(table); METER(stats.searches++); // Compute the primary hash address. @@ -1145,7 +1232,7 @@ class HashTable : private AllocPolicy Entry *firstRemoved = nullptr; while(true) { - if (JS_UNLIKELY(entry->isRemoved())) { + if (MOZ_UNLIKELY(entry->isRemoved())) { if (!firstRemoved) firstRemoved = entry; } else { @@ -1176,8 +1263,8 @@ class HashTable : private AllocPolicy // from entries, which allows more flexible Lookup/Key types. Entry &findFreeEntry(HashNumber keyHash) { - JS_ASSERT(!(keyHash & sCollisionBit)); - JS_ASSERT(table); + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(table); METER(stats.searches++); // We assume 'keyHash' has already been distributed. @@ -1196,7 +1283,7 @@ class HashTable : private AllocPolicy DoubleHash dh = hash2(keyHash); while(true) { - JS_ASSERT(!entry->isRemoved()); + MOZ_ASSERT(!entry->isRemoved()); entry->setCollision(); METER(stats.steps++); @@ -1277,7 +1364,7 @@ class HashTable : private AllocPolicy void remove(Entry &e) { - JS_ASSERT(table); + MOZ_ASSERT(table); METER(stats.removes++); if (e.hasCollision()) { @@ -1288,7 +1375,9 @@ class HashTable : private AllocPolicy e.clearLive(); } entryCount--; +#ifdef DEBUG mutationCount++; +#endif } void checkUnderloaded() @@ -1371,12 +1460,14 @@ class HashTable : private AllocPolicy } removedCount = 0; entryCount = 0; +#ifdef DEBUG mutationCount++; +#endif } void finish() { - JS_ASSERT(!entered); + MOZ_ASSERT(!mEntered); if (!table) return; @@ -1386,36 +1477,38 @@ class HashTable : private AllocPolicy gen++; entryCount = 0; removedCount = 0; +#ifdef DEBUG mutationCount++; +#endif } Range all() const { - JS_ASSERT(table); - return Range(table, table + capacity()); + MOZ_ASSERT(table); + return Range(*this, table, table + capacity()); } bool empty() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return !entryCount; } uint32_t count() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return entryCount; } uint32_t capacity() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return JS_BIT(sHashBits - hashShift); } uint32_t generation() const { - JS_ASSERT(table); + MOZ_ASSERT(table); return gen; } @@ -1433,13 +1526,13 @@ class HashTable : private AllocPolicy { mozilla::ReentrancyGuard g(*this); HashNumber keyHash = prepareHash(l); - return Ptr(lookup(l, keyHash, 0)); + return Ptr(lookup(l, keyHash, 0), *this); } Ptr readonlyThreadsafeLookup(const Lookup &l) const { HashNumber keyHash = prepareHash(l); - return Ptr(lookup(l, keyHash, 0)); + return Ptr(lookup(l, keyHash, 0), *this); } AddPtr lookupForAdd(const Lookup &l) const @@ -1447,8 +1540,7 @@ class HashTable : private AllocPolicy mozilla::ReentrancyGuard g(*this); HashNumber keyHash = prepareHash(l); Entry &entry = lookup(l, keyHash, sCollisionBit); - AddPtr p(entry, keyHash); - p.mutationCount = mutationCount; + AddPtr p(entry, *this, keyHash); return p; } @@ -1456,10 +1548,9 @@ class HashTable : private AllocPolicy bool add(AddPtr &p, U &&u) { mozilla::ReentrancyGuard g(*this); - JS_ASSERT(mutationCount == p.mutationCount); - JS_ASSERT(table); - JS_ASSERT(!p.found()); - JS_ASSERT(!(p.keyHash & sCollisionBit)); + MOZ_ASSERT(table); + MOZ_ASSERT(!p.found()); + MOZ_ASSERT(!(p.keyHash & sCollisionBit)); // Changing an entry from removed to live does not affect whether we // are overloaded and can be handled separately. @@ -1478,7 +1569,11 @@ class HashTable : private AllocPolicy p.entry_->setLive(p.keyHash, mozilla::Forward(u)); entryCount++; +#ifdef DEBUG mutationCount++; + p.generation = generation(); + p.mutationCount = mutationCount; +#endif return true; } @@ -1487,7 +1582,7 @@ class HashTable : private AllocPolicy template void putNewInfallible(const Lookup &l, U &&u) { - JS_ASSERT(table); + MOZ_ASSERT(table); HashNumber keyHash = prepareHash(l); Entry *entry = &findFreeEntry(keyHash); @@ -1500,7 +1595,9 @@ class HashTable : private AllocPolicy entry->setLive(keyHash, mozilla::Forward(u)); entryCount++; +#ifdef DEBUG mutationCount++; +#endif } // Note: |l| may be a reference to a piece of |u|, so this function @@ -1520,10 +1617,13 @@ class HashTable : private AllocPolicy template bool relookupOrAdd(AddPtr& p, const Lookup &l, U &&u) { +#ifdef DEBUG + p.generation = generation(); p.mutationCount = mutationCount; +#endif { mozilla::ReentrancyGuard g(*this); - JS_ASSERT(prepareHash(l) == p.keyHash); // l has not been destroyed + MOZ_ASSERT(prepareHash(l) == p.keyHash); // l has not been destroyed p.entry_ = &lookup(l, p.keyHash, sCollisionBit); } return p.found() || add(p, mozilla::Forward(u)); @@ -1531,18 +1631,18 @@ class HashTable : private AllocPolicy void remove(Ptr p) { - JS_ASSERT(table); + MOZ_ASSERT(table); mozilla::ReentrancyGuard g(*this); - JS_ASSERT(p.found()); + MOZ_ASSERT(p.found()); remove(*p.entry_); checkUnderloaded(); } void rekeyWithoutRehash(Ptr p, const Lookup &l, const Key &k) { - JS_ASSERT(table); + MOZ_ASSERT(table); mozilla::ReentrancyGuard g(*this); - JS_ASSERT(p.found()); + MOZ_ASSERT(p.found()); typename HashTableEntry::NonConstT t(mozilla::Move(*p)); HashPolicy::setKey(t, const_cast(k)); remove(*p.entry_); @@ -1555,6 +1655,14 @@ class HashTable : private AllocPolicy checkOverRemoved(); } + void rekeyInPlace(Ptr p, const Key &k) + { + MOZ_ASSERT(table); + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(p.found()); + HashPolicy::rekey(const_cast(*p), const_cast(k)); + } + #undef METER }; diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/HeapAPI.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/HeapAPI.h index 9993751d46..bdd63c1937 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/HeapAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/HeapAPI.h @@ -26,11 +26,17 @@ CurrentThreadCanAccessZone(JS::Zone *zone); namespace gc { +struct Cell; + const size_t ArenaShift = 12; const size_t ArenaSize = size_t(1) << ArenaShift; const size_t ArenaMask = ArenaSize - 1; +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkShift = 18; +#else const size_t ChunkShift = 20; +#endif const size_t ChunkSize = size_t(1) << ChunkShift; const size_t ChunkMask = ChunkSize - 1; @@ -39,9 +45,15 @@ const size_t CellSize = size_t(1) << CellShift; const size_t CellMask = CellSize - 1; /* These are magic constants derived from actual offsets in gc/Heap.h. */ -const size_t ChunkMarkBitmapOffset = 1032368; +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkMarkBitmapOffset = 258104; +const size_t ChunkMarkBitmapBits = 31744; +#else +const size_t ChunkMarkBitmapOffset = 1032352; const size_t ChunkMarkBitmapBits = 129024; +#endif const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*); +const size_t ChunkLocationOffset = ChunkSize - 2 * sizeof(void*) - sizeof(uint64_t); /* * Live objects are marked black. How many other additional colors are available @@ -51,14 +63,98 @@ const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*); static const uint32_t BLACK = 0; static const uint32_t GRAY = 1; +/* + * The "location" field in the Chunk trailer is a bit vector indicting various + * roles of the chunk. + * + * The value 0 for the "location" field is invalid, at least one bit must be + * set. + * + * Some bits preclude others, for example, any "nursery" bit precludes any + * "tenured" or "middle generation" bit. + */ +const uintptr_t ChunkLocationBitNursery = 1; // Standard GGC nursery +const uintptr_t ChunkLocationBitTenuredHeap = 2; // Standard GGC tenured generation +const uintptr_t ChunkLocationBitPJSNewspace = 4; // The PJS generational GC's allocation space +const uintptr_t ChunkLocationBitPJSFromspace = 8; // The PJS generational GC's fromspace (during GC) + +const uintptr_t ChunkLocationAnyNursery = ChunkLocationBitNursery | + ChunkLocationBitPJSNewspace | + ChunkLocationBitPJSFromspace; + +#ifdef JS_DEBUG +/* When downcasting, ensure we are actually the right type. */ +extern JS_FRIEND_API(void) +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind); +#else +inline void +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind) {} +#endif + } /* namespace gc */ } /* namespace js */ namespace JS { struct Zone; -} /* namespace JS */ -namespace JS { +/* Default size for the generational nursery in bytes. */ +const uint32_t DefaultNurseryBytes = 16 * 1024 * 1024; + +/* Default maximum heap size in bytes to pass to JS_NewRuntime(). */ +const uint32_t DefaultHeapMaxBytes = 32 * 1024 * 1024; + +/* + * We cannot expose the class hierarchy: the implementation is hidden. Instead + * we provide cast functions with strong debug-mode assertions. + */ +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSObject *obj) +{ + js::gc::Cell *cell = reinterpret_cast(obj); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFunction *fun) +{ + js::gc::Cell *cell = reinterpret_cast(fun); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSString *str) +{ + js::gc::Cell *cell = reinterpret_cast(str); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFlatString *flat) +{ + js::gc::Cell *cell = reinterpret_cast(flat); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JS::Symbol *sym) +{ + js::gc::Cell *cell = reinterpret_cast(sym); + AssertGCThingHasType(cell, JSTRACE_SYMBOL); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSScript *script) +{ + js::gc::Cell *cell = reinterpret_cast(script); + AssertGCThingHasType(cell, JSTRACE_SCRIPT); + return cell; +} + namespace shadow { struct ArenaHeader @@ -86,13 +182,13 @@ struct Zone } JSTracer *barrierTracer() { - JS_ASSERT(needsBarrier_); - JS_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + MOZ_ASSERT(needsBarrier_); + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); return barrierTracer_; } JSRuntime *runtimeFromMainThread() const { - JS_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); return runtime_; } @@ -113,40 +209,40 @@ struct Zone namespace js { namespace gc { -static JS_ALWAYS_INLINE uintptr_t * +static MOZ_ALWAYS_INLINE uintptr_t * GetGCThingMarkBitmap(const void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); uintptr_t addr = uintptr_t(thing); addr &= ~js::gc::ChunkMask; addr |= js::gc::ChunkMarkBitmapOffset; return reinterpret_cast(addr); } -static JS_ALWAYS_INLINE JS::shadow::Runtime * +static MOZ_ALWAYS_INLINE JS::shadow::Runtime * GetGCThingRuntime(const void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); uintptr_t addr = uintptr_t(thing); addr &= ~js::gc::ChunkMask; addr |= js::gc::ChunkRuntimeOffset; return *reinterpret_cast(addr); } -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void GetGCThingMarkWordAndMask(const void *thing, uint32_t color, uintptr_t **wordp, uintptr_t *maskp) { uintptr_t addr = uintptr_t(thing); size_t bit = (addr & js::gc::ChunkMask) / js::gc::CellSize + color; - JS_ASSERT(bit < js::gc::ChunkMarkBitmapBits); + MOZ_ASSERT(bit < js::gc::ChunkMarkBitmapBits); uintptr_t *bitmap = GetGCThingMarkBitmap(thing); const uintptr_t nbits = sizeof(*bitmap) * CHAR_BIT; *maskp = uintptr_t(1) << (bit % nbits); *wordp = &bitmap[bit / nbits]; } -static JS_ALWAYS_INLINE JS::shadow::ArenaHeader * +static MOZ_ALWAYS_INLINE JS::shadow::ArenaHeader * GetGCThingArena(void *thing) { uintptr_t addr = uintptr_t(thing); @@ -154,11 +250,18 @@ GetGCThingArena(void *thing) return reinterpret_cast(addr); } -JS_ALWAYS_INLINE bool -IsInsideNursery(const JS::shadow::Runtime *runtime, const void *p) +MOZ_ALWAYS_INLINE bool +IsInsideNursery(const js::gc::Cell *cell) { #ifdef JSGC_GENERATIONAL - return uintptr_t(p) >= runtime->gcNurseryStart_ && uintptr_t(p) < runtime->gcNurseryEnd_; + if (!cell) + return false; + uintptr_t addr = uintptr_t(cell); + addr &= ~js::gc::ChunkMask; + addr |= js::gc::ChunkLocationOffset; + uint32_t location = *reinterpret_cast(addr); + JS_ASSERT(location != 0); + return location & ChunkLocationAnyNursery; #else return false; #endif @@ -170,20 +273,20 @@ IsInsideNursery(const JS::shadow::Runtime *runtime, const void *p) namespace JS { -static JS_ALWAYS_INLINE Zone * +static MOZ_ALWAYS_INLINE Zone * GetGCThingZone(void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); return js::gc::GetGCThingArena(thing)->zone; } -static JS_ALWAYS_INLINE Zone * +static MOZ_ALWAYS_INLINE Zone * GetObjectZone(JSObject *obj) { return GetGCThingZone(obj); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool GCThingIsMarkedGray(void *thing) { #ifdef JSGC_GENERATIONAL @@ -192,8 +295,7 @@ GCThingIsMarkedGray(void *thing) * All live objects in the nursery are moved to tenured at the beginning of * each GC slice, so the gray marker never sees nursery things. */ - JS::shadow::Runtime *rt = js::gc::GetGCThingRuntime(thing); - if (js::gc::IsInsideNursery(rt, thing)) + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) return false; #endif uintptr_t *word, mask; @@ -201,7 +303,7 @@ GCThingIsMarkedGray(void *thing) return *word & mask; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool IsIncrementalBarrierNeededOnGCThing(shadow::Runtime *rt, void *thing, JSGCTraceKind kind) { if (!rt->needsBarrier_) diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/Id.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/Id.h index 447deb62e6..11116f2efe 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/Id.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/Id.h @@ -21,164 +21,155 @@ // JS_IdToValue must be used instead. #include "mozilla/NullPtr.h" - + #include "jstypes.h" +#include "js/HeapAPI.h" #include "js/RootingAPI.h" #include "js/TypeDecls.h" #include "js/Utility.h" -#ifdef JS_USE_JSID_STRUCT_TYPES struct jsid { size_t asBits; bool operator==(jsid rhs) const { return asBits == rhs.asBits; } bool operator!=(jsid rhs) const { return asBits != rhs.asBits; } }; -# define JSID_BITS(id) (id.asBits) -#else -# define JSID_BITS(id) (id) -#endif +#define JSID_BITS(id) (id.asBits) #define JSID_TYPE_STRING 0x0 #define JSID_TYPE_INT 0x1 #define JSID_TYPE_VOID 0x2 -#define JSID_TYPE_OBJECT 0x4 +#define JSID_TYPE_SYMBOL 0x4 #define JSID_TYPE_MASK 0x7 // Avoid using canonical 'id' for jsid parameters since this is a magic word in // Objective-C++ which, apparently, wants to be able to #include jsapi.h. #define id iden -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_STRING(jsid id) { return (JSID_BITS(id) & JSID_TYPE_MASK) == 0; } -static JS_ALWAYS_INLINE JSString * +static MOZ_ALWAYS_INLINE JSString * JSID_TO_STRING(jsid id) { - JS_ASSERT(JSID_IS_STRING(id)); + MOZ_ASSERT(JSID_IS_STRING(id)); return (JSString *)JSID_BITS(id); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ZERO(jsid id) { return JSID_BITS(id) == 0; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_INT(jsid id) { return !!(JSID_BITS(id) & JSID_TYPE_INT); } -static JS_ALWAYS_INLINE int32_t +static MOZ_ALWAYS_INLINE int32_t JSID_TO_INT(jsid id) { - JS_ASSERT(JSID_IS_INT(id)); + MOZ_ASSERT(JSID_IS_INT(id)); return ((uint32_t)JSID_BITS(id)) >> 1; } #define JSID_INT_MIN 0 #define JSID_INT_MAX INT32_MAX -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool INT_FITS_IN_JSID(int32_t i) { return i >= 0; } -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid INT_TO_JSID(int32_t i) { jsid id; - JS_ASSERT(INT_FITS_IN_JSID(i)); + MOZ_ASSERT(INT_FITS_IN_JSID(i)); JSID_BITS(id) = ((i << 1) | JSID_TYPE_INT); return id; } -static JS_ALWAYS_INLINE bool -JSID_IS_OBJECT(jsid id) +static MOZ_ALWAYS_INLINE bool +JSID_IS_SYMBOL(jsid id) { - return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_OBJECT && - (size_t)JSID_BITS(id) != JSID_TYPE_OBJECT; + return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_SYMBOL && + JSID_BITS(id) != JSID_TYPE_SYMBOL; } -static JS_ALWAYS_INLINE JSObject * -JSID_TO_OBJECT(jsid id) +static MOZ_ALWAYS_INLINE JS::Symbol * +JSID_TO_SYMBOL(jsid id) { - JS_ASSERT(JSID_IS_OBJECT(id)); - return (JSObject *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); + MOZ_ASSERT(JSID_IS_SYMBOL(id)); + return (JS::Symbol *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); } -static JS_ALWAYS_INLINE jsid -OBJECT_TO_JSID(JSObject *obj) +static MOZ_ALWAYS_INLINE jsid +SYMBOL_TO_JSID(JS::Symbol *sym) { jsid id; - JS_ASSERT(obj != nullptr); - JS_ASSERT(((size_t)obj & JSID_TYPE_MASK) == 0); - JSID_BITS(id) = ((size_t)obj | JSID_TYPE_OBJECT); + MOZ_ASSERT(sym != nullptr); + MOZ_ASSERT((size_t(sym) & JSID_TYPE_MASK) == 0); + JS_ASSERT(!js::gc::IsInsideNursery(JS::AsCell(sym))); + JS_ASSERT(!JS::IsPoisonedPtr(sym)); + JSID_BITS(id) = (size_t(sym) | JSID_TYPE_SYMBOL); return id; } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_GCTHING(jsid id) { - return JSID_IS_STRING(id) || JSID_IS_OBJECT(id); + return JSID_IS_STRING(id) || JSID_IS_SYMBOL(id); } -static JS_ALWAYS_INLINE void * +static MOZ_ALWAYS_INLINE void * JSID_TO_GCTHING(jsid id) { return (void *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_VOID(const jsid id) { - JS_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID, + MOZ_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID, JSID_BITS(id) == JSID_TYPE_VOID); return ((size_t)JSID_BITS(id) == JSID_TYPE_VOID); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_EMPTY(const jsid id) { - return ((size_t)JSID_BITS(id) == JSID_TYPE_OBJECT); + return ((size_t)JSID_BITS(id) == JSID_TYPE_SYMBOL); } -#undef id - -#ifdef JS_USE_JSID_STRUCT_TYPES extern JS_PUBLIC_DATA(const jsid) JSID_VOID; extern JS_PUBLIC_DATA(const jsid) JSID_EMPTY; -#else -# define JSID_VOID ((jsid)JSID_TYPE_VOID) -# define JSID_EMPTY ((jsid)JSID_TYPE_OBJECT) -#endif -extern JS_PUBLIC_DATA(const JS::Handle) JSID_VOIDHANDLE; -extern JS_PUBLIC_DATA(const JS::Handle) JSID_EMPTYHANDLE; +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_VOIDHANDLE; +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_EMPTYHANDLE; namespace js { inline bool -IsPoisonedId(jsid iden) +IsPoisonedId(jsid id) { - if (JSID_IS_STRING(iden)) - return JS::IsPoisonedPtr(JSID_TO_STRING(iden)); - if (JSID_IS_OBJECT(iden)) - return JS::IsPoisonedPtr(JSID_TO_OBJECT(iden)); + if (JSID_IS_STRING(id)) + return JS::IsPoisonedPtr(JSID_TO_STRING(id)); + if (JSID_IS_SYMBOL(id)) + return JS::IsPoisonedPtr(JSID_TO_SYMBOL(id)); return false; } template <> struct GCMethods { static jsid initial() { return JSID_VOID; } - static ThingRootKind kind() { return THING_ROOT_ID; } static bool poisoned(jsid id) { return IsPoisonedId(id); } static bool needsPostBarrier(jsid id) { return false; } #ifdef JSGC_GENERATIONAL @@ -187,6 +178,8 @@ template <> struct GCMethods #endif }; +#undef id + } #endif /* js_Id_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/MemoryMetrics.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/MemoryMetrics.h index 95ac91b9f6..31e456baba 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/MemoryMetrics.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/MemoryMetrics.h @@ -77,6 +77,13 @@ struct InefficientNonFlatteningStringHashPolicy static bool match(const JSString *const &k, const Lookup &l); }; +struct CStringHashPolicy +{ + typedef const char *Lookup; + static HashNumber hash(const Lookup &l); + static bool match(const char *const &k, const Lookup &l); +}; + // This file features many classes with numerous size_t fields, and each such // class has one or more methods that need to operate on all of these fields. // Writing these individually is error-prone -- it's easy to add a new field @@ -92,6 +99,9 @@ struct InefficientNonFlatteningStringHashPolicy #define ZERO_SIZE(kind, gc, mSize) mSize(0), #define COPY_OTHER_SIZE(kind, gc, mSize) mSize(other.mSize), #define ADD_OTHER_SIZE(kind, gc, mSize) mSize += other.mSize; +#define SUB_OTHER_SIZE(kind, gc, mSize) MOZ_ASSERT(mSize >= other.mSize); \ + mSize -= other.mSize; +#define ADD_SIZE_TO_N(kind, gc, mSize) n += mSize; #define ADD_SIZE_TO_N_IF_LIVE_GC_THING(kind, gc, mSize) n += (js::gc) ? mSize : 0; #define ADD_TO_TAB_SIZES(kind, gc, mSize) sizes->add(JS::TabSizes::kind, mSize); @@ -101,49 +111,6 @@ enum { IsLiveGCThing = true }; -struct ZoneStatsPod -{ -#define FOR_EACH_SIZE(macro) \ - macro(Other, NotLiveGCThing, gcHeapArenaAdmin) \ - macro(Other, NotLiveGCThing, unusedGCThings) \ - macro(Other, IsLiveGCThing, lazyScriptsGCHeap) \ - macro(Other, NotLiveGCThing, lazyScriptsMallocHeap) \ - macro(Other, IsLiveGCThing, ionCodesGCHeap) \ - macro(Other, IsLiveGCThing, typeObjectsGCHeap) \ - macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \ - macro(Other, NotLiveGCThing, typePool) \ - macro(Strings, IsLiveGCThing, stringsShortGCHeap) \ - macro(Strings, IsLiveGCThing, stringsNormalGCHeap) \ - macro(Strings, NotLiveGCThing, stringsNormalMallocHeap) - - ZoneStatsPod() - : FOR_EACH_SIZE(ZERO_SIZE) - extra() - {} - - void add(const ZoneStatsPod &other) { - FOR_EACH_SIZE(ADD_OTHER_SIZE) - // Do nothing with |extra|. - } - - size_t sizeOfLiveGCThings() const { - size_t n = 0; - FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) - // Do nothing with |extra|. - return n; - } - - void addToTabSizes(JS::TabSizes *sizes) const { - FOR_EACH_SIZE(ADD_TO_TAB_SIZES) - // Do nothing with |extra|. - } - - FOR_EACH_SIZE(DECL_SIZE) - void *extra; // This field can be used by embedders. - -#undef FOR_EACH_SIZE -}; - } // namespace js namespace JS { @@ -156,6 +123,7 @@ struct ObjectsExtraSizes macro(Objects, NotLiveGCThing, mallocHeapElementsNonAsmJS) \ macro(Objects, NotLiveGCThing, mallocHeapElementsAsmJS) \ macro(Objects, NotLiveGCThing, nonHeapElementsAsmJS) \ + macro(Objects, NotLiveGCThing, nonHeapElementsMapped) \ macro(Objects, NotLiveGCThing, nonHeapCodeAsmJS) \ macro(Objects, NotLiveGCThing, mallocHeapAsmJSModuleData) \ macro(Objects, NotLiveGCThing, mallocHeapArgumentsData) \ @@ -209,6 +177,33 @@ struct CodeSizes #undef FOR_EACH_SIZE }; +// Data for tracking GC memory usage. +struct GCSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, marker) \ + macro(_, _, nurseryCommitted) \ + macro(_, _, nurseryDecommitted) \ + macro(_, _, nurseryHugeSlots) \ + macro(_, _, storeBufferVals) \ + macro(_, _, storeBufferCells) \ + macro(_, _, storeBufferSlots) \ + macro(_, _, storeBufferWholeCells) \ + macro(_, _, storeBufferRelocVals) \ + macro(_, _, storeBufferRelocCells) \ + macro(_, _, storeBufferGenerics) + + GCSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + dummy() + {} + + FOR_EACH_SIZE(DECL_SIZE) + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) + +#undef FOR_EACH_SIZE +}; + // This class holds information about the memory taken up by identical copies of // a particular string. Multiple JSStrings may have their sizes aggregated // together into one StringInfo object. Note that two strings with identical @@ -216,50 +211,59 @@ struct CodeSizes // is not. struct StringInfo { - StringInfo() - : numCopies(0), - isShort(0), - gcHeap(0), - mallocHeap(0) - {} +#define FOR_EACH_SIZE(macro) \ + macro(Strings, IsLiveGCThing, gcHeapLatin1) \ + macro(Strings, IsLiveGCThing, gcHeapTwoByte) \ + macro(Strings, NotLiveGCThing, mallocHeapLatin1) \ + macro(Strings, NotLiveGCThing, mallocHeapTwoByte) - StringInfo(bool isShort, size_t gcSize, size_t mallocSize) - : numCopies(1), - isShort(isShort), - gcHeap(gcSize), - mallocHeap(mallocSize) + StringInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numCopies(0) {} - void add(bool isShort, size_t gcSize, size_t mallocSize) { + void add(const StringInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE); numCopies++; - MOZ_ASSERT(isShort == this->isShort); - gcHeap += gcSize; - mallocHeap += mallocSize; } - void add(const StringInfo& info) { - numCopies += info.numCopies; - MOZ_ASSERT(info.isShort == isShort); - gcHeap += info.gcHeap; - mallocHeap += info.mallocHeap; + void subtract(const StringInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE); + numCopies--; } - uint32_t numCopies:31; // How many copies of the string have we seen? - uint32_t isShort:1; // Is it a short string? + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + size_t sizeOfLiveGCThings() const { + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + return n; + } + + void addToTabSizes(TabSizes *sizes) const { + FOR_EACH_SIZE(ADD_TO_TAB_SIZES) + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numCopies; // How many copies of the string have we seen? - // These are all totals across all copies of the string we've seen. - size_t gcHeap; - size_t mallocHeap; +#undef FOR_EACH_SIZE }; -// Holds data about a notable string (one which uses more than -// NotableStringInfo::notableSize() bytes of memory), so we can report it -// individually. +// Holds data about a notable string (one which, counting all duplicates, uses +// more than a certain amount of memory) so we can report it individually. // -// Essentially the only difference between this class and StringInfo is that -// NotableStringInfo holds a copy of the string's chars. +// The only difference between this class and StringInfo is that +// NotableStringInfo holds a copy of some or all of the string's chars. struct NotableStringInfo : public StringInfo { + static const size_t MAX_SAVED_CHARS = 1024; + NotableStringInfo(); NotableStringInfo(JSString *str, const StringInfo &info); NotableStringInfo(NotableStringInfo &&info); @@ -269,12 +273,6 @@ struct NotableStringInfo : public StringInfo js_free(buffer); } - // A string needs to take up this many bytes of storage before we consider - // it to be "notable". - static size_t notableSize() { - return js::MemoryReportingSundriesThreshold(); - } - char *buffer; size_t length; @@ -282,6 +280,67 @@ struct NotableStringInfo : public StringInfo NotableStringInfo(const NotableStringInfo& info) MOZ_DELETE; }; +// This class holds information about the memory taken up by script sources +// from a particular file. +struct ScriptSourceInfo +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, compressed) \ + macro(_, _, uncompressed) \ + macro(_, _, misc) + + ScriptSourceInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numScripts(0) + {} + + void add(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE) + numScripts++; + } + + void subtract(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE) + numScripts--; + } + + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numScripts; // How many ScriptSources come from this file? (It + // can be more than one in XML files that have + // multiple scripts in CDATA sections.) +#undef FOR_EACH_SIZE +}; + +// Holds data about a notable script source file (one whose combined +// script sources use more than a certain amount of memory) so we can report it +// individually. +// +// The only difference between this class and ScriptSourceInfo is that this +// class holds a copy of the filename. +struct NotableScriptSourceInfo : public ScriptSourceInfo +{ + NotableScriptSourceInfo(); + NotableScriptSourceInfo(const char *filename, const ScriptSourceInfo &info); + NotableScriptSourceInfo(NotableScriptSourceInfo &&info); + NotableScriptSourceInfo &operator=(NotableScriptSourceInfo &&info); + + ~NotableScriptSourceInfo() { + js_free(filename_); + } + + char *filename_; + + private: + NotableScriptSourceInfo(const NotableScriptSourceInfo& info) MOZ_DELETE; +}; + // These measurements relate directly to the JSRuntime, and not to zones and // compartments within it. struct RuntimeSizes @@ -292,81 +351,139 @@ struct RuntimeSizes macro(_, _, contexts) \ macro(_, _, dtoa) \ macro(_, _, temporary) \ - macro(_, _, regexpData) \ macro(_, _, interpreterStack) \ - macro(_, _, gcMarker) \ macro(_, _, mathCache) \ + macro(_, _, uncompressedSourceCache) \ + macro(_, _, compressedSourceSet) \ macro(_, _, scriptData) \ - macro(_, _, scriptSources) RuntimeSizes() : FOR_EACH_SIZE(ZERO_SIZE) - code() - {} + scriptSourceInfo(), + code(), + gc(), + notableScriptSources() + { + allScriptSources = js_new(); + if (!allScriptSources || !allScriptSources->init()) + MOZ_CRASH("oom"); + } + ~RuntimeSizes() { + // |allScriptSources| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allScriptSources); + } + + // The script source measurements in |scriptSourceInfo| are initially for + // all script sources. At the end, if the measurement granularity is + // FineGrained, we subtract the measurements of the notable script sources + // and move them into |notableScriptSources|. FOR_EACH_SIZE(DECL_SIZE) - CodeSizes code; + ScriptSourceInfo scriptSourceInfo; + CodeSizes code; + GCSizes gc; + + typedef js::HashMap ScriptSourcesHashMap; + + // |allScriptSources| is only used transiently. During the reporting phase + // it is filled with info about every script source in the runtime. It's + // then used to fill in |notableScriptSources| (which actually gets + // reported), and immediately discarded afterwards. + ScriptSourcesHashMap *allScriptSources; + js::Vector notableScriptSources; #undef FOR_EACH_SIZE }; -struct ZoneStats : js::ZoneStatsPod +struct ZoneStats { +#define FOR_EACH_SIZE(macro) \ + macro(Other, IsLiveGCThing, symbolsGCHeap) \ + macro(Other, NotLiveGCThing, gcHeapArenaAdmin) \ + macro(Other, NotLiveGCThing, unusedGCThings) \ + macro(Other, IsLiveGCThing, lazyScriptsGCHeap) \ + macro(Other, NotLiveGCThing, lazyScriptsMallocHeap) \ + macro(Other, IsLiveGCThing, jitCodesGCHeap) \ + macro(Other, IsLiveGCThing, typeObjectsGCHeap) \ + macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \ + macro(Other, NotLiveGCThing, typePool) \ + macro(Other, NotLiveGCThing, baselineStubsOptimized) \ + ZoneStats() - : strings(nullptr) + : FOR_EACH_SIZE(ZERO_SIZE) + stringInfo(), + extra(), + allStrings(nullptr), + notableStrings(), + isTotals(true) {} ZoneStats(ZoneStats &&other) - : ZoneStatsPod(mozilla::Move(other)), - strings(other.strings), - notableStrings(mozilla::Move(other.notableStrings)) + : FOR_EACH_SIZE(COPY_OTHER_SIZE) + stringInfo(mozilla::Move(other.stringInfo)), + extra(other.extra), + allStrings(other.allStrings), + notableStrings(mozilla::Move(other.notableStrings)), + isTotals(other.isTotals) { - other.strings = nullptr; + other.allStrings = nullptr; + MOZ_ASSERT(!other.isTotals); } - bool initStrings(JSRuntime *rt); - - // Add |other|'s numbers to this object's numbers. The strings data isn't - // touched. - void addIgnoringStrings(const ZoneStats &other) { - ZoneStatsPod::add(other); + ~ZoneStats() { + // |allStrings| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allStrings); } - // Add |other|'s strings data to this object's strings data. (We don't do - // anything with notableStrings.) - void addStrings(const ZoneStats &other) { - for (StringsHashMap::Range r = other.strings->all(); !r.empty(); r.popFront()) { - StringsHashMap::AddPtr p = strings->lookupForAdd(r.front().key()); - if (p) { - // We've seen this string before; add its size to our tally. - p->value().add(r.front().value()); - } else { - // We haven't seen this string before; add it to the hashtable. - strings->add(p, r.front().key(), r.front().value()); - } - } + bool initStrings(JSRuntime *rt); + + void addSizes(const ZoneStats &other) { + MOZ_ASSERT(isTotals); + FOR_EACH_SIZE(ADD_OTHER_SIZE) + stringInfo.add(other.stringInfo); } size_t sizeOfLiveGCThings() const { - size_t n = ZoneStatsPod::sizeOfLiveGCThings(); - for (size_t i = 0; i < notableStrings.length(); i++) { - const JS::NotableStringInfo& info = notableStrings[i]; - n += info.gcHeap; - } + MOZ_ASSERT(isTotals); + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + n += stringInfo.sizeOfLiveGCThings(); return n; } - typedef js::HashMap StringsHashMap; - // |strings| is only used transiently. During the zone traversal it is + // |allStrings| is only used transiently. During the zone traversal it is // filled with info about every string in the zone. It's then used to fill // in |notableStrings| (which actually gets reported), and immediately // discarded afterwards. - StringsHashMap *strings; + StringsHashMap *allStrings; js::Vector notableStrings; + bool isTotals; + +#undef FOR_EACH_SIZE }; struct CompartmentStats @@ -390,17 +507,16 @@ struct CompartmentStats macro(Other, NotLiveGCThing, scriptsMallocHeapData) \ macro(Other, NotLiveGCThing, baselineData) \ macro(Other, NotLiveGCThing, baselineStubsFallback) \ - macro(Other, NotLiveGCThing, baselineStubsOptimized) \ macro(Other, NotLiveGCThing, ionData) \ macro(Other, NotLiveGCThing, typeInferenceTypeScripts) \ - macro(Other, NotLiveGCThing, typeInferencePendingArrays) \ macro(Other, NotLiveGCThing, typeInferenceAllocationSiteTables) \ macro(Other, NotLiveGCThing, typeInferenceArrayTypeTables) \ macro(Other, NotLiveGCThing, typeInferenceObjectTypeTables) \ macro(Other, NotLiveGCThing, compartmentObject) \ macro(Other, NotLiveGCThing, crossCompartmentWrappersTable) \ macro(Other, NotLiveGCThing, regexpCompartment) \ - macro(Other, NotLiveGCThing, debuggeesSet) + macro(Other, NotLiveGCThing, debuggeesSet) \ + macro(Other, NotLiveGCThing, savedStacksSet) CompartmentStats() : FOR_EACH_SIZE(ZERO_SIZE) @@ -454,7 +570,7 @@ struct RuntimeStats macro(_, _, gcHeapChunkAdmin) \ macro(_, _, gcHeapGCThings) \ - RuntimeStats(mozilla::MallocSizeOf mallocSizeOf) + explicit RuntimeStats(mozilla::MallocSizeOf mallocSizeOf) : FOR_EACH_SIZE(ZERO_SIZE) runtime(), cTotals(), @@ -517,13 +633,13 @@ class ObjectPrivateVisitor typedef bool(*GetISupportsFun)(JSObject *obj, nsISupports **iface); GetISupportsFun getISupports_; - ObjectPrivateVisitor(GetISupportsFun getISupports) + explicit ObjectPrivateVisitor(GetISupportsFun getISupports) : getISupports_(getISupports) {} }; extern JS_PUBLIC_API(bool) -CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv); +CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv, bool anonymize); extern JS_PUBLIC_API(size_t) SystemCompartmentCount(JSRuntime *rt); @@ -544,6 +660,8 @@ AddSizeOfTab(JSRuntime *rt, JS::HandleObject obj, mozilla::MallocSizeOf mallocSi #undef ZERO_SIZE #undef COPY_OTHER_SIZE #undef ADD_OTHER_SIZE +#undef SUB_OTHER_SIZE +#undef ADD_SIZE_TO_N #undef ADD_SIZE_TO_N_IF_LIVE_GC_THING #undef ADD_TO_TAB_SIZES diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/OldDebugAPI.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/OldDebugAPI.h index 5e5bdf38d7..7117d754d9 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/OldDebugAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/OldDebugAPI.h @@ -12,47 +12,40 @@ */ #include "mozilla/NullPtr.h" - + +#include "jsapi.h" #include "jsbytecode.h" #include "js/CallArgs.h" #include "js/TypeDecls.h" class JSAtom; -class JSFreeOp; - -namespace js { class StackFrame; } +struct JSFreeOp; -namespace JS { - -struct FrameDescription -{ - JSScript *script; - unsigned lineno; - JSFunction *fun; -}; +namespace js { +class InterpreterFrame; +class FrameIter; +class ScriptSource; +} -struct StackDescription -{ - unsigned nframes; - FrameDescription *frames; -}; +// Raw JSScript* because this needs to be callable from a signal handler. +extern JS_PUBLIC_API(unsigned) +JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); -extern JS_PUBLIC_API(StackDescription *) -DescribeStack(JSContext *cx, unsigned maxFrames); +extern JS_PUBLIC_API(const char *) +JS_GetScriptFilename(JSScript *script); -extern JS_PUBLIC_API(void) -FreeStackDescription(JSContext *cx, StackDescription *desc); +namespace JS { extern JS_PUBLIC_API(char *) FormatStackDump(JSContext *cx, char *buf, bool showArgs, bool showLocals, bool showThisProps); -} +} // namespace JS -# ifdef DEBUG +# ifdef JS_DEBUG JS_FRIEND_API(void) js_DumpValue(const JS::Value &val); JS_FRIEND_API(void) js_DumpId(jsid id); -JS_FRIEND_API(void) js_DumpStackFrame(JSContext *cx, js::StackFrame *start = nullptr); +JS_FRIEND_API(void) js_DumpInterpreterFrame(JSContext *cx, js::InterpreterFrame *start = nullptr); # endif JS_FRIEND_API(void) @@ -70,48 +63,21 @@ typedef JSTrapStatus (* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, JS::Value closure); -typedef JSTrapStatus -(* JSInterruptHook)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, - void *closure); - typedef JSTrapStatus (* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, void *closure); -typedef JSTrapStatus -(* JSThrowHook)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, - void *closure); - typedef bool (* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, JS::Value old, JS::Value *newp, void *closure); -/* called just after script creation */ -typedef void -(* JSNewScriptHook)(JSContext *cx, - const char *filename, /* URL of script */ - unsigned lineno, /* first line */ - JSScript *script, - JSFunction *fun, - void *callerdata); - -/* called just before script destruction */ -typedef void -(* JSDestroyScriptHook)(JSFreeOp *fop, - JSScript *script, - void *callerdata); - -typedef void -(* JSSourceHandler)(const char *filename, unsigned lineno, const jschar *str, - size_t length, void **listenerTSData, void *closure); - extern JS_PUBLIC_API(JSCompartment *) JS_EnterCompartmentOfScript(JSContext *cx, JSScript *target); extern JS_PUBLIC_API(JSString *) -JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned indent); +JS_DecompileScript(JSContext *cx, JS::HandleScript script, const char *name, unsigned indent); /* * Currently, we only support runtime-wide debugging. In the future, we should @@ -157,12 +123,12 @@ JS_SetDebugMode(JSContext *cx, bool debug); /* Turn on single step mode. */ extern JS_PUBLIC_API(bool) -JS_SetSingleStepMode(JSContext *cx, JSScript *script, bool singleStep); +JS_SetSingleStepMode(JSContext *cx, JS::HandleScript script, bool singleStep); /* The closure argument will be marked. */ extern JS_PUBLIC_API(bool) -JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc, - JSTrapHandler handler, JS::Value closure); +JS_SetTrap(JSContext *cx, JS::HandleScript script, jsbytecode *pc, + JSTrapHandler handler, JS::HandleValue closure); extern JS_PUBLIC_API(void) JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc, @@ -174,17 +140,11 @@ JS_ClearScriptTraps(JSRuntime *rt, JSScript *script); extern JS_PUBLIC_API(void) JS_ClearAllTrapsForCompartment(JSContext *cx); -extern JS_PUBLIC_API(bool) -JS_SetInterrupt(JSRuntime *rt, JSInterruptHook handler, void *closure); - -extern JS_PUBLIC_API(bool) -JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *handlerp, void **closurep); - /************************************************************************/ extern JS_PUBLIC_API(bool) -JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsid id, - JSWatchPointHandler handler, JSObject *closure); +JS_SetWatchPoint(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JSWatchPointHandler handler, JS::HandleObject closure); extern JS_PUBLIC_API(bool) JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id, @@ -195,10 +155,6 @@ JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj); /************************************************************************/ -// Raw JSScript* because this needs to be callable from a signal handler. -extern JS_PUBLIC_API(unsigned) -JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); - extern JS_PUBLIC_API(jsbytecode *) JS_LineNumberToPC(JSContext *cx, JSScript *script, unsigned lineno); @@ -234,17 +190,11 @@ extern JS_PUBLIC_API(void) JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mark); extern JS_PUBLIC_API(JSScript *) -JS_GetFunctionScript(JSContext *cx, JSFunction *fun); +JS_GetFunctionScript(JSContext *cx, JS::HandleFunction fun); extern JS_PUBLIC_API(JSNative) JS_GetFunctionNative(JSContext *cx, JSFunction *fun); -extern JS_PUBLIC_API(JSPrincipals *) -JS_GetScriptPrincipals(JSScript *script); - -extern JS_PUBLIC_API(JSPrincipals *) -JS_GetScriptOriginPrincipals(JSScript *script); - JS_PUBLIC_API(JSFunction *) JS_GetScriptFunction(JSContext *cx, JSScript *script); @@ -264,9 +214,6 @@ JS_GetDebugClassName(JSObject *obj); /************************************************************************/ -extern JS_PUBLIC_API(const char *) -JS_GetScriptFilename(JSContext *cx, JSScript *script); - extern JS_PUBLIC_API(const jschar *) JS_GetScriptSourceMap(JSContext *cx, JSScript *script); @@ -284,22 +231,6 @@ JS_GetScriptIsSelfHosted(JSScript *script); /************************************************************************/ -/* - * Hook setters for script creation and destruction. These macros provide - * binary compatibility and newer, shorter synonyms. - */ -#define JS_SetNewScriptHook JS_SetNewScriptHookProc -#define JS_SetDestroyScriptHook JS_SetDestroyScriptHookProc - -extern JS_PUBLIC_API(void) -JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata); - -extern JS_PUBLIC_API(void) -JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook, - void *callerdata); - -/************************************************************************/ - typedef struct JSPropertyDesc { JS::Value id; /* primary id, atomized string, or int */ JS::Value value; /* property value */ @@ -325,7 +256,7 @@ typedef struct JSPropertyDescArray { typedef struct JSScopeProperty JSScopeProperty; extern JS_PUBLIC_API(bool) -JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda); +JS_GetPropertyDescArray(JSContext *cx, JS::HandleObject obj, JSPropertyDescArray *pda); extern JS_PUBLIC_API(void) JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); @@ -339,16 +270,18 @@ JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); class JS_PUBLIC_API(JSAbstractFramePtr) { uintptr_t ptr_; + jsbytecode *pc_; protected: JSAbstractFramePtr() - : ptr_(0) + : ptr_(0), pc_(nullptr) { } public: - explicit JSAbstractFramePtr(void *raw); + JSAbstractFramePtr(void *raw, jsbytecode *pc); uintptr_t raw() const { return ptr_; } + jsbytecode *pc() const { return pc_; } operator bool() const { return !!ptr_; } @@ -393,7 +326,7 @@ class JS_PUBLIC_API(JSBrokenFrameIterator) void *data_; public: - JSBrokenFrameIterator(JSContext *cx); + explicit JSBrokenFrameIterator(JSContext *cx); ~JSBrokenFrameIterator(); bool done() const; @@ -405,58 +338,13 @@ class JS_PUBLIC_API(JSBrokenFrameIterator) bool isConstructing() const; }; -/* - * This hook captures high level script execution and function calls (JS or - * native). It is used by JS_SetExecuteHook to hook top level scripts and by - * JS_SetCallHook to hook function calls. It will get called twice per script - * or function call: just before execution begins and just after it finishes. - * In both cases the 'current' frame is that of the executing code. - * - * The 'before' param is true for the hook invocation before the execution - * and false for the invocation after the code has run. - * - * The 'ok' param is significant only on the post execution invocation to - * signify whether or not the code completed 'normally'. - * - * The 'closure' param is as passed to JS_SetExecuteHook or JS_SetCallHook - * for the 'before'invocation, but is whatever value is returned from that - * invocation for the 'after' invocation. Thus, the hook implementor *could* - * allocate a structure in the 'before' invocation and return a pointer to that - * structure. The pointer would then be handed to the hook for the 'after' - * invocation. Alternately, the 'before' could just return the same value as - * in 'closure' to cause the 'after' invocation to be called with the same - * 'closure' value as the 'before'. - * - * Returning nullptr in the 'before' hook will cause the 'after' hook *not* to - * be called. - */ -typedef void * -(* JSInterpreterHook)(JSContext *cx, JSAbstractFramePtr frame, bool isConstructing, - bool before, bool *ok, void *closure); - typedef bool (* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report, void *closure); typedef struct JSDebugHooks { - JSInterruptHook interruptHook; - void *interruptHookData; - JSNewScriptHook newScriptHook; - void *newScriptHookData; - JSDestroyScriptHook destroyScriptHook; - void *destroyScriptHookData; JSDebuggerHandler debuggerHandler; void *debuggerHandlerData; - JSSourceHandler sourceHandler; - void *sourceHandlerData; - JSInterpreterHook executeHook; - void *executeHookData; - JSInterpreterHook callHook; - void *callHookData; - JSThrowHook throwHook; - void *throwHookData; - JSDebugErrorHook debugErrorHook; - void *debugErrorHookData; } JSDebugHooks; /************************************************************************/ @@ -464,21 +352,6 @@ typedef struct JSDebugHooks { extern JS_PUBLIC_API(bool) JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler hook, void *closure); -extern JS_PUBLIC_API(bool) -JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetThrowHook(JSRuntime *rt, JSThrowHook hook, void *closure); - -extern JS_PUBLIC_API(bool) -JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure); - /************************************************************************/ extern JS_PUBLIC_API(const JSDebugHooks *) @@ -492,16 +365,10 @@ JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj); /* Defined in vm/Debugger.cpp. */ extern JS_PUBLIC_API(bool) -JS_DefineDebuggerObject(JSContext *cx, JSObject *obj); - -extern JS_PUBLIC_API(void) -JS_DumpBytecode(JSContext *cx, JSScript *script); - -extern JS_PUBLIC_API(void) -JS_DumpCompartmentBytecode(JSContext *cx); +JS_DefineDebuggerObject(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(void) -JS_DumpPCCounts(JSContext *cx, JSScript *script); +JS_DumpPCCounts(JSContext *cx, JS::HandleScript script); extern JS_PUBLIC_API(void) JS_DumpCompartmentPCCounts(JSContext *cx); diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/Principals.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/Principals.h new file mode 100644 index 0000000000..78d8c7e893 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/Principals.h @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JSPrincipals and related interfaces. */ + +#ifndef js_Principals_h +#define js_Principals_h + +#include "mozilla/Atomics.h" + +#include + +#include "jspubtd.h" + +struct JSPrincipals { + /* Don't call "destroy"; use reference counting macros below. */ +#ifdef JS_THREADSAFE + mozilla::Atomic refcount; +#else + int32_t refcount; +#endif + +#ifdef JS_DEBUG + /* A helper to facilitate principals debugging. */ + uint32_t debugToken; +#endif + + void setDebugToken(uint32_t token) { +# ifdef JS_DEBUG + debugToken = token; +# endif + } + + /* + * This is not defined by the JS engine but should be provided by the + * embedding. + */ + JS_PUBLIC_API(void) dump(); +}; + +extern JS_PUBLIC_API(void) +JS_HoldPrincipals(JSPrincipals *principals); + +extern JS_PUBLIC_API(void) +JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals); + +// Return whether the first principal subsumes the second. The exact meaning of +// 'subsumes' is left up to the browser. Subsumption is checked inside the JS +// engine when determining, e.g., which stack frames to display in a backtrace. +typedef bool +(* JSSubsumesOp)(JSPrincipals *first, JSPrincipals *second); + +/* + * Used to check if a CSP instance wants to disable eval() and friends. + * See js_CheckCSPPermitsJSAction() in jsobj. + */ +typedef bool +(* JSCSPEvalChecker)(JSContext *cx); + +struct JSSecurityCallbacks { + JSCSPEvalChecker contentSecurityPolicyAllows; + JSSubsumesOp subsumes; +}; + +extern JS_PUBLIC_API(void) +JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks); + +extern JS_PUBLIC_API(const JSSecurityCallbacks *) +JS_GetSecurityCallbacks(JSRuntime *rt); + +/* + * Code running with "trusted" principals will be given a deeper stack + * allocation than ordinary scripts. This allows trusted script to run after + * untrusted script has exhausted the stack. This function sets the + * runtime-wide trusted principal. + * + * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since + * there is no available JSContext. Instead, the caller must ensure that the + * given principals stays valid for as long as 'rt' may point to it. If the + * principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be + * called again, passing nullptr for 'prin'. + */ +extern JS_PUBLIC_API(void) +JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin); + +typedef void +(* JSDestroyPrincipalsOp)(JSPrincipals *principals); + +/* + * Initialize the callback that is called to destroy JSPrincipals instance + * when its reference counter drops to zero. The initialization can be done + * only once per JS runtime. + */ +extern JS_PUBLIC_API(void) +JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals); + +#endif /* js_Principals_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/ProfilingStack.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/ProfilingStack.h index 213e47bb7d..e82ce1c9d8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/ProfilingStack.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/ProfilingStack.h @@ -8,7 +8,8 @@ #define js_ProfilingStack_h #include "mozilla/NullPtr.h" - +#include "mozilla/TypedEnum.h" + #include "jsbytecode.h" #include "jstypes.h" @@ -34,50 +35,120 @@ class ProfileEntry // If the size modification were somehow reordered before the stores, then // if a sample were taken it would be examining bogus information. // - // A ProfileEntry represents both a C++ profile entry and a JS one. Both use - // the string as a description, but JS uses the sp as nullptr to indicate - // that it is a JS entry. The script_ is then only ever examined for a JS - // entry, and the idx is used by both, but with different meanings. - // - const char * volatile string; // Descriptive string of this entry - void * volatile sp; // Relevant stack pointer for the entry - JSScript * volatile script_; // if js(), non-null script which is running - int32_t volatile idx; // if js(), idx of pc, otherwise line number + // A ProfileEntry represents both a C++ profile entry and a JS one. + + // Descriptive string of this entry. + const char * volatile string; + + // Stack pointer for non-JS entries, the script pointer otherwise. + void * volatile spOrScript; + + // Line number for non-JS entries, the bytecode offset otherwise. + int32_t volatile lineOrPc; + + // General purpose storage describing this frame. + uint32_t volatile flags_; public: + // These traits are bit masks. Make sure they're powers of 2. + enum Flags { + // Indicate whether a profile entry represents a CPP frame. If not set, + // a JS frame is assumed by default. You're not allowed to publicly + // change the frame type. Instead, call `setJsFrame` or `setCppFrame`. + IS_CPP_ENTRY = 0x01, + + // Indicate that copying the frame label is not necessary when taking a + // sample of the pseudostack. + FRAME_LABEL_COPY = 0x02, + + // Mask for removing all flags except the category information. + CATEGORY_MASK = ~IS_CPP_ENTRY & ~FRAME_LABEL_COPY + }; + + MOZ_BEGIN_NESTED_ENUM_CLASS(Category, uint32_t) + OTHER = 0x04, + CSS = 0x08, + JS = 0x10, + GC = 0x20, + CC = 0x40, + NETWORK = 0x80, + GRAPHICS = 0x100, + STORAGE = 0x200, + EVENTS = 0x400, + + FIRST = OTHER, + LAST = EVENTS + MOZ_END_NESTED_ENUM_CLASS(Category) + // All of these methods are marked with the 'volatile' keyword because SPS's // representation of the stack is stored such that all ProfileEntry // instances are volatile. These methods would not be available unless they // were marked as volatile as well. - bool js() const volatile { - JS_ASSERT_IF(sp == nullptr, script_ != nullptr); - return sp == nullptr; - } + bool isCpp() const volatile { return hasFlag(IS_CPP_ENTRY); } + bool isJs() const volatile { return !isCpp(); } - uint32_t line() const volatile { JS_ASSERT(!js()); return idx; } - JSScript *script() const volatile { JS_ASSERT(js()); return script_; } - void *stackAddress() const volatile { return sp; } - const char *label() const volatile { return string; } + bool isCopyLabel() const volatile { return hasFlag(FRAME_LABEL_COPY); }; - void setLine(uint32_t aLine) volatile { JS_ASSERT(!js()); idx = aLine; } void setLabel(const char *aString) volatile { string = aString; } - void setStackAddress(void *aSp) volatile { sp = aSp; } - void setScript(JSScript *aScript) volatile { script_ = aScript; } + const char *label() const volatile { return string; } + + void setJsFrame(JSScript *aScript, jsbytecode *aPc) volatile { + flags_ = 0; + spOrScript = aScript; + setPC(aPc); + } + void setCppFrame(void *aSp, uint32_t aLine) volatile { + flags_ = IS_CPP_ENTRY; + spOrScript = aSp; + lineOrPc = static_cast(aLine); + } + + void setFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ |= flag; + } + void unsetFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ &= ~flag; + } + bool hasFlag(uint32_t flag) const volatile { + return bool(flags_ & flag); + } + + uint32_t flags() const volatile { + return flags_; + } + uint32_t category() const volatile { + return flags_ & CATEGORY_MASK; + } + + void *stackAddress() const volatile { + MOZ_ASSERT(!isJs()); + return spOrScript; + } + JSScript *script() const volatile { + MOZ_ASSERT(isJs()); + return (JSScript *)spOrScript; + } + uint32_t line() const volatile { + MOZ_ASSERT(!isJs()); + return static_cast(lineOrPc); + } // We can't know the layout of JSScript, so look in vm/SPSProfiler.cpp. JS_FRIEND_API(jsbytecode *) pc() const volatile; JS_FRIEND_API(void) setPC(jsbytecode *pc) volatile; - static size_t offsetOfString() { return offsetof(ProfileEntry, string); } - static size_t offsetOfStackAddress() { return offsetof(ProfileEntry, sp); } - static size_t offsetOfPCIdx() { return offsetof(ProfileEntry, idx); } - static size_t offsetOfScript() { return offsetof(ProfileEntry, script_); } + // The offset of a pc into a script's code can actually be 0, so to + // signify a nullptr pc, use a -1 index. This is checked against in + // pc() and setPC() to set/get the right pc. + static const int32_t NullPCOffset = -1; - // The index used in the entry can either be a line number or the offset of - // a pc into a script's code. To signify a nullptr pc, use a -1 index. This - // is checked against in pc() and setPC() to set/get the right pc. - static const int32_t NullPCIndex = -1; + static size_t offsetOfLabel() { return offsetof(ProfileEntry, string); } + static size_t offsetOfSpOrScript() { return offsetof(ProfileEntry, spOrScript); } + static size_t offsetOfLineOrPc() { return offsetof(ProfileEntry, lineOrPc); } + static size_t offsetOfFlags() { return offsetof(ProfileEntry, flags_); } }; JS_FRIEND_API(void) @@ -87,6 +158,9 @@ SetRuntimeProfilingStack(JSRuntime *rt, ProfileEntry *stack, uint32_t *size, JS_FRIEND_API(void) EnableRuntimeProfilingStack(JSRuntime *rt, bool enabled); +JS_FRIEND_API(void) +RegisterRuntimeProfilingEventMarker(JSRuntime *rt, void (*fn)(const char *)); + JS_FRIEND_API(jsbytecode*) ProfilingGetPC(JSRuntime *rt, JSScript *script, void *ip); diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/RequiredDefines.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/RequiredDefines.h index 3c8f429132..308fd7d625 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/RequiredDefines.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/RequiredDefines.h @@ -28,4 +28,7 @@ #define __STDC_CONSTANT_MACROS #define __STDC_FORMAT_MACROS +/* Also define a char16_t type if not provided by the compiler. */ +#include "mozilla/Char16.h" + #endif /* js_RequiredDefines_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/RootingAPI.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/RootingAPI.h index 5b612660cd..621a1e4394 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/RootingAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/RootingAPI.h @@ -15,6 +15,8 @@ #include "jspubtd.h" +#include "js/GCAPI.h" +#include "js/HeapAPI.h" #include "js/TypeDecls.h" #include "js/Utility.h" @@ -138,6 +140,8 @@ struct NullPtr namespace gc { struct Cell; +template +struct PersistentRootedMarker; } /* namespace gc */ } /* namespace js */ @@ -150,11 +154,6 @@ template class PersistentRooted; /* This is exposing internal state of the GC for inlining purposes. */ JS_FRIEND_API(bool) isGCEnabled(); -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) -extern void -CheckStackRoots(JSContext *cx); -#endif - /* * JS::NullPtr acts like a nullptr pointer in contexts that require a Handle. * @@ -198,6 +197,13 @@ class Heap : public js::HeapBase init(js::GCMethods::initial()); } explicit Heap(T p) { init(p); } + + /* + * For Heap, move semantics are equivalent to copy semantics. In C++, a + * copy constructor taking const-ref is the way to get a single function + * that will be used for both lvalue and rvalue copies, so we can simply + * omit the rvalue variant. + */ explicit Heap(const Heap &p) { init(p.ptr); } ~Heap() { @@ -229,7 +235,7 @@ class Heap : public js::HeapBase } void set(T newPtr) { - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); if (js::GCMethods::needsPostBarrier(newPtr)) { ptr = newPtr; post(); @@ -241,9 +247,21 @@ class Heap : public js::HeapBase } } + /* + * Set the pointer to a value which will cause a crash if it is + * dereferenced. + */ + void setToCrashOnTouch() { + ptr = reinterpret_cast(crashOnTouchPointer); + } + + bool isSetToCrashOnTouch() { + return ptr == crashOnTouchPointer; + } + private: void init(T newPtr) { - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); ptr = newPtr; if (js::GCMethods::needsPostBarrier(ptr)) post(); @@ -251,7 +269,7 @@ class Heap : public js::HeapBase void post() { #ifdef JSGC_GENERATIONAL - JS_ASSERT(js::GCMethods::needsPostBarrier(ptr)); + MOZ_ASSERT(js::GCMethods::needsPostBarrier(ptr)); js::GCMethods::postBarrier(&ptr); #endif } @@ -262,10 +280,14 @@ class Heap : public js::HeapBase #endif } + enum { + crashOnTouchPointer = 1 + }; + T ptr; }; -#ifdef DEBUG +#ifdef JS_DEBUG /* * For generational GC, assert that an object is in the tenured generation as * opposed to being in the nursery. @@ -315,31 +337,31 @@ class TenuredHeap : public js::HeapBase "TenuredHeap must be binary compatible with T."); } explicit TenuredHeap(T p) : bits(0) { setPtr(p); } - explicit TenuredHeap(const TenuredHeap &p) : bits(0) { setPtr(p.ptr); } + explicit TenuredHeap(const TenuredHeap &p) : bits(0) { setPtr(p.getPtr()); } bool operator==(const TenuredHeap &other) { return bits == other.bits; } bool operator!=(const TenuredHeap &other) { return bits != other.bits; } void setPtr(T newPtr) { - JS_ASSERT((reinterpret_cast(newPtr) & flagsMask) == 0); - JS_ASSERT(!js::GCMethods::poisoned(newPtr)); + MOZ_ASSERT((reinterpret_cast(newPtr) & flagsMask) == 0); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); if (newPtr) AssertGCThingMustBeTenured(newPtr); bits = (bits & flagsMask) | reinterpret_cast(newPtr); } void setFlags(uintptr_t flagsToSet) { - JS_ASSERT((flagsToSet & ~flagsMask) == 0); + MOZ_ASSERT((flagsToSet & ~flagsMask) == 0); bits |= flagsToSet; } void unsetFlags(uintptr_t flagsToUnset) { - JS_ASSERT((flagsToUnset & ~flagsMask) == 0); + MOZ_ASSERT((flagsToUnset & ~flagsMask) == 0); bits &= ~flagsToUnset; } bool hasFlag(uintptr_t flag) const { - JS_ASSERT((flag & ~flagsMask) == 0); + MOZ_ASSERT((flag & ~flagsMask) == 0); return (bits & flag) != 0; } @@ -359,23 +381,10 @@ class TenuredHeap : public js::HeapBase return *this; } - /* - * Set the pointer to a value which will cause a crash if it is - * dereferenced. - */ - void setToCrashOnTouch() { - bits = (bits & flagsMask) | crashOnTouchPointer; - } - - bool isSetToCrashOnTouch() { - return (bits & ~flagsMask) == crashOnTouchPointer; - } - private: enum { maskBits = 3, flagsMask = (1 << maskBits) - 1, - crashOnTouchPointer = 1 << maskBits }; uintptr_t bits; @@ -406,20 +415,20 @@ class MOZ_NONHEAP_CLASS Handle : public js::HandleBase } /* Create a handle for a nullptr pointer. */ - Handle(js::NullPtr) { + MOZ_IMPLICIT Handle(js::NullPtr) { static_assert(mozilla::IsPointer::value, "js::NullPtr overload not valid for non-pointer types"); ptr = reinterpret_cast(&js::NullPtr::constNullValue); } /* Create a handle for a nullptr pointer. */ - Handle(JS::NullPtr) { + MOZ_IMPLICIT Handle(JS::NullPtr) { static_assert(mozilla::IsPointer::value, "JS::NullPtr overload not valid for non-pointer types"); ptr = reinterpret_cast(&JS::NullPtr::constNullValue); } - Handle(MutableHandle handle) { + MOZ_IMPLICIT Handle(MutableHandle handle) { ptr = handle.address(); } @@ -476,9 +485,6 @@ class MOZ_NONHEAP_CLASS Handle : public js::HandleBase bool operator!=(const T &other) const { return *ptr != other; } bool operator==(const T &other) const { return *ptr == other; } - /* Change this handle to point to the same rooted location RHS does. */ - void repoint(const Handle &rhs) { ptr = rhs.address(); } - private: Handle() {} @@ -504,15 +510,23 @@ template class MOZ_STACK_CLASS MutableHandle : public js::MutableHandleBase { public: - inline MutableHandle(Rooted *root); - inline MutableHandle(PersistentRooted *root); - MutableHandle(int) MOZ_DELETE; -#ifdef MOZ_HAVE_CXX11_NULLPTR - MutableHandle(decltype(nullptr)) MOZ_DELETE; -#endif + inline MOZ_IMPLICIT MutableHandle(Rooted *root); + inline MOZ_IMPLICIT MutableHandle(PersistentRooted *root); + + private: + // Disallow true nullptr and emulated nullptr (gcc 4.4/4.5, __null, appears + // as int/long [32/64-bit]) for overloading purposes. + template + MutableHandle(N, + typename mozilla::EnableIf::value || + mozilla::IsSame::value || + mozilla::IsSame::value, + int>::Type dummy = 0) + MOZ_DELETE; + public: void set(T v) { - JS_ASSERT(!js::GCMethods::poisoned(v)); + MOZ_ASSERT(!js::GCMethods::poisoned(v)); *ptr = v; } @@ -549,8 +563,8 @@ class MOZ_STACK_CLASS MutableHandle : public js::MutableHandleBase }; #ifdef JSGC_GENERATIONAL -JS_PUBLIC_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); -JS_PUBLIC_API(void) HeapCellRelocate(js::gc::Cell **cellp); +JS_FRIEND_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); +JS_FRIEND_API(void) HeapCellRelocate(js::gc::Cell **cellp); #endif } /* namespace JS */ @@ -612,7 +626,7 @@ class InternalHandle * Make this private to prevent accidental misuse; this is only for * fromMarkedLocation(). */ - InternalHandle(T *field) + explicit InternalHandle(T *field) : holder(reinterpret_cast(&js::NullPtr::constNullValue)), offset(uintptr_t(field)) {} @@ -621,10 +635,16 @@ class InternalHandle }; /* - * By default, pointers should use the inheritance hierarchy to find their + * By default, things should use the inheritance hierarchy to find their * ThingRootKind. Some pointer types are explicitly set in jspubtd.h so that * Rooted may be used without the class definition being available. */ +template +struct RootKind +{ + static ThingRootKind rootKind() { return T::rootKind(); } +}; + template struct RootKind { @@ -635,20 +655,51 @@ template struct GCMethods { static T *initial() { return nullptr; } - static ThingRootKind kind() { return RootKind::rootKind(); } static bool poisoned(T *v) { return JS::IsPoisonedPtr(v); } - static bool needsPostBarrier(T *v) { return v; } + static bool needsPostBarrier(T *v) { return false; } #ifdef JSGC_GENERATIONAL - static void postBarrier(T **vp) { + static void postBarrier(T **vp) {} + static void relocate(T **vp) {} +#endif +}; + +template <> +struct GCMethods +{ + static JSObject *initial() { return nullptr; } + static bool poisoned(JSObject *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSObject *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSObject **vp) { JS::HeapCellPostBarrier(reinterpret_cast(vp)); } - static void relocate(T **vp) { + static void relocate(JSObject **vp) { JS::HeapCellRelocate(reinterpret_cast(vp)); } #endif }; -#if defined(DEBUG) +template <> +struct GCMethods +{ + static JSFunction *initial() { return nullptr; } + static bool poisoned(JSFunction *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSFunction *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSFunction **vp) { + JS::HeapCellPostBarrier(reinterpret_cast(vp)); + } + static void relocate(JSFunction **vp) { + JS::HeapCellRelocate(reinterpret_cast(vp)); + } +#endif +}; + +#ifdef JS_DEBUG /* This helper allows us to assert that Rooted is scoped within a request. */ extern JS_PUBLIC_API(bool) IsInRequest(JSContext *cx); @@ -673,22 +724,24 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase template void init(CX *cx) { #ifdef JSGC_TRACK_EXACT_ROOTS - js::ThingRootKind kind = js::GCMethods::kind(); + js::ThingRootKind kind = js::RootKind::rootKind(); this->stack = &cx->thingGCRooters[kind]; this->prev = *stack; *stack = reinterpret_cast*>(this); - JS_ASSERT(!js::GCMethods::poisoned(ptr)); + MOZ_ASSERT(!js::GCMethods::poisoned(ptr)); #endif } public: - Rooted(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG MOZ_ASSERT(js::IsInRequest(cx)); +#endif init(js::ContextFriendFields::get(cx)); } @@ -697,12 +750,14 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase : ptr(initial) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG MOZ_ASSERT(js::IsInRequest(cx)); +#endif init(js::ContextFriendFields::get(cx)); } - Rooted(js::ContextFriendFields *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(js::ContextFriendFields *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -717,8 +772,8 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase init(cx); } - Rooted(js::PerThreadDataFriendFields *pt - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(js::PerThreadDataFriendFields *pt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -733,8 +788,8 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase init(pt); } - Rooted(JSRuntime *rt - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit Rooted(JSRuntime *rt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : ptr(js::GCMethods::initial()) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -754,13 +809,13 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase // using MSVC, see bug 915735 for more details. #ifdef JSGC_TRACK_EXACT_ROOTS ~Rooted() { - JS_ASSERT(*stack == reinterpret_cast*>(this)); + MOZ_ASSERT(*stack == reinterpret_cast*>(this)); *stack = prev; } #endif #ifdef JSGC_TRACK_EXACT_ROOTS - Rooted *previous() { return prev; } + Rooted *previous() { return reinterpret_cast*>(prev); } #endif /* @@ -775,7 +830,7 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase const T &get() const { return ptr; } T &operator=(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; return ptr; } @@ -786,7 +841,7 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase } void set(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; } @@ -795,16 +850,12 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase private: #ifdef JSGC_TRACK_EXACT_ROOTS - Rooted **stack, *prev; -#endif - -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* Has the rooting analysis ever scanned this Rooted's stack location? */ - friend void JS::CheckStackRoots(JSContext*); -#endif - -#ifdef JSGC_ROOT_ANALYSIS - bool scanned; + /* + * These need to be templated on void* to avoid aliasing issues between, for + * example, Rooted and Rooted, which use the same + * stack head pointer for different classes. + */ + Rooted **stack, *prev; #endif /* @@ -818,90 +869,26 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase Rooted(const Rooted &) MOZ_DELETE; }; -#if !(defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)) -// Defined in vm/String.h. -template <> -class Rooted; -#endif - } /* namespace JS */ namespace js { /* - * Mark a stack location as a root for the rooting analysis, without actually - * rooting it in release builds. This should only be used for stack locations - * of GC things that cannot be relocated by a garbage collection, and that - * are definitely reachable via another path. + * Augment the generic Rooted interface when T = JSObject* with + * class-querying and downcasting operations. + * + * Given a Rooted obj, one can view + * Handle h = obj.as(); + * as an optimization of + * Rooted rooted(cx, &obj->as()); + * Handle h = rooted; */ -class SkipRoot +template <> +class RootedBase { -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - - SkipRoot **stack, *prev; - const uint8_t *start; - const uint8_t *end; - - template - void init(CX *cx, const T *ptr, size_t count) { - SkipRoot **head = &cx->skipGCRooters; - this->stack = head; - this->prev = *stack; - *stack = this; - this->start = (const uint8_t *) ptr; - this->end = this->start + (sizeof(T) * count); - } - public: - ~SkipRoot() { - JS_ASSERT(*stack == this); - *stack = prev; - } - - SkipRoot *previous() { return prev; } - - bool contains(const uint8_t *v, size_t len) { - return v >= start && v + len <= end; - } - -#else /* DEBUG && JSGC_ROOT_ANALYSIS */ - - template - void init(js::ContextFriendFields *cx, const T *ptr, size_t count) {} - - public: - ~SkipRoot() { - // An empty destructor is needed to avoid warnings from clang about - // unused local variables of this type. - } - -#endif /* DEBUG && JSGC_ROOT_ANALYSIS */ - - template - SkipRoot(JSContext *cx, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(ContextFriendFields::get(cx), ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - template - SkipRoot(ContextFriendFields *cx, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(cx, ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - template - SkipRoot(PerThreadData *pt, const T *ptr, size_t count = 1 - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - { - init(PerThreadDataFriendFields::get(pt), ptr, count); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + template + JS::Handle as() const; }; /* Interface substitute for Rooted which does not root the variable's memory. */ @@ -933,13 +920,13 @@ class FakeRooted : public RootedBase const T &get() const { return ptr; } FakeRooted &operator=(T value) { - JS_ASSERT(!GCMethods::poisoned(value)); + MOZ_ASSERT(!GCMethods::poisoned(value)); ptr = value; return *this; } FakeRooted &operator=(const FakeRooted &other) { - JS_ASSERT(!GCMethods::poisoned(other.ptr)); + MOZ_ASSERT(!GCMethods::poisoned(other.ptr)); ptr = other.ptr; return *this; } @@ -960,16 +947,16 @@ template class FakeMutableHandle : public js::MutableHandleBase { public: - FakeMutableHandle(T *t) { + MOZ_IMPLICIT FakeMutableHandle(T *t) { ptr = t; } - FakeMutableHandle(FakeRooted *root) { + MOZ_IMPLICIT FakeMutableHandle(FakeRooted *root) { ptr = root->address(); } void set(T v) { - JS_ASSERT(!js::GCMethods::poisoned(v)); + MOZ_ASSERT(!js::GCMethods::poisoned(v)); *ptr = v; } @@ -992,7 +979,7 @@ class FakeMutableHandle : public js::MutableHandleBase /* * Types for a variable that either should or shouldn't be rooted, depending on - * the template parameter Rooted. Used for implementing functions that can + * the template parameter allowGC. Used for implementing functions that can * operate on either rooted or unrooted data. * * The toHandle() and toMutableHandle() functions are for calling functions @@ -1031,12 +1018,12 @@ template class MaybeRooted typedef FakeRooted RootType; typedef FakeMutableHandle MutableHandleType; - static inline JS::Handle toHandle(HandleType v) { - MOZ_ASSUME_UNREACHABLE("Bad conversion"); + static JS::Handle toHandle(HandleType v) { + MOZ_CRASH("Bad conversion"); } - static inline JS::MutableHandle toMutableHandle(MutableHandleType v) { - MOZ_ASSUME_UNREACHABLE("Bad conversion"); + static JS::MutableHandle toMutableHandle(MutableHandleType v) { + MOZ_CRASH("Bad conversion"); } }; @@ -1086,7 +1073,6 @@ MutableHandle::MutableHandle(PersistentRooted *root) ptr = root->address(); } - /* * A copyable, assignable global GC root type with arbitrary lifetime, an * infallible constructor, and automatic unrooting on destruction. @@ -1120,9 +1106,11 @@ MutableHandle::MutableHandle(PersistentRooted *root) * marked when the object itself is marked. */ template -class PersistentRooted : public mozilla::LinkedListElement > { - typedef mozilla::LinkedList List; - typedef mozilla::LinkedListElement Element; +class PersistentRooted : private mozilla::LinkedListElement > { + friend class mozilla::LinkedList; + friend class mozilla::LinkedListElement; + + friend struct js::gc::PersistentRootedMarker; void registerWithRuntime(JSRuntime *rt) { JS::shadow::Runtime *srt = JS::shadow::Runtime::asShadowRuntime(rt); @@ -1130,7 +1118,7 @@ class PersistentRooted : public mozilla::LinkedListElement > } public: - PersistentRooted(JSContext *cx) : ptr(js::GCMethods::initial()) + explicit PersistentRooted(JSContext *cx) : ptr(js::GCMethods::initial()) { registerWithRuntime(js::GetRuntime(cx)); } @@ -1140,7 +1128,7 @@ class PersistentRooted : public mozilla::LinkedListElement > registerWithRuntime(js::GetRuntime(cx)); } - PersistentRooted(JSRuntime *rt) : ptr(js::GCMethods::initial()) + explicit PersistentRooted(JSRuntime *rt) : ptr(js::GCMethods::initial()) { registerWithRuntime(rt); } @@ -1150,14 +1138,19 @@ class PersistentRooted : public mozilla::LinkedListElement > registerWithRuntime(rt); } - PersistentRooted(PersistentRooted &rhs) : ptr(rhs.ptr) + PersistentRooted(const PersistentRooted &rhs) + : mozilla::LinkedListElement >(), + ptr(rhs.ptr) { /* * Copy construction takes advantage of the fact that the original * is already inserted, and simply adds itself to whatever list the * original was on - no JSRuntime pointer needed. + * + * This requires mutating rhs's links, but those should be 'mutable' + * anyway. C++ doesn't let us declare mutable base classes. */ - rhs.setNext(this); + const_cast(rhs).setNext(this); } /* @@ -1172,7 +1165,7 @@ class PersistentRooted : public mozilla::LinkedListElement > const T &get() const { return ptr; } T &operator=(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; return ptr; } @@ -1183,7 +1176,7 @@ class PersistentRooted : public mozilla::LinkedListElement > } void set(T value) { - JS_ASSERT(!js::GCMethods::poisoned(value)); + MOZ_ASSERT(!js::GCMethods::poisoned(value)); ptr = value; } @@ -1194,26 +1187,56 @@ class PersistentRooted : public mozilla::LinkedListElement > T ptr; }; +class JS_PUBLIC_API(ObjectPtr) +{ + Heap value; + + public: + ObjectPtr() : value(nullptr) {} + + explicit ObjectPtr(JSObject *obj) : value(obj) {} + + /* Always call finalize before the destructor. */ + ~ObjectPtr() { MOZ_ASSERT(!value); } + + void finalize(JSRuntime *rt) { + if (IsIncrementalBarrierNeeded(rt)) + IncrementalObjectBarrier(value); + value = nullptr; + } + + void init(JSObject *obj) { value = obj; } + + JSObject *get() const { return value; } + + void writeBarrierPre(JSRuntime *rt) { + IncrementalObjectBarrier(value); + } + + bool isAboutToBeFinalized(); + + ObjectPtr &operator=(JSObject *obj) { + IncrementalObjectBarrier(value); + value = obj; + return *this; + } + + void trace(JSTracer *trc, const char *name); + + JSObject &operator*() const { return *value; } + JSObject *operator->() const { return value; } + operator JSObject *() const { return value; } +}; + } /* namespace JS */ namespace js { -/* - * Hook for dynamic root analysis. Checks the native stack and poisons - * references to GC things which have not been rooted. - */ -inline void MaybeCheckStackRoots(JSContext *cx) -{ -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - JS::CheckStackRoots(cx); -#endif -} - /* Base class for automatic read-only object rooting during compilation. */ class CompilerRootNode { protected: - CompilerRootNode(js::gc::Cell *ptr) : next(nullptr), ptr_(ptr) {} + explicit CompilerRootNode(js::gc::Cell *ptr) : next(nullptr), ptr_(ptr) {} public: void **address() { return (void **)&ptr_; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/SliceBudget.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/SliceBudget.h index ccade643b3..7c602c5572 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/SliceBudget.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/SliceBudget.h @@ -32,11 +32,11 @@ struct JS_PUBLIC_API(SliceBudget) SliceBudget(); /* Instantiate as SliceBudget(Time/WorkBudget(n)). */ - SliceBudget(int64_t budget); + explicit SliceBudget(int64_t budget); void reset() { - deadline = INT64_MAX; - counter = INTPTR_MAX; + deadline = unlimitedDeadline; + counter = unlimitedStartCounter; } void step(intptr_t amt = 1) { @@ -50,6 +50,15 @@ struct JS_PUBLIC_API(SliceBudget) return false; return checkOverBudget(); } + + bool isUnlimited() { + return deadline == unlimitedDeadline; + } + +private: + static const int64_t unlimitedDeadline = INT64_MAX; + static const intptr_t unlimitedStartCounter = INTPTR_MAX; + }; } // namespace js diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/StructuredClone.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/StructuredClone.h index d32bdd8dd6..fa48ce045a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/StructuredClone.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/StructuredClone.h @@ -23,6 +23,35 @@ struct JSStructuredCloneWriter; // API for the HTML5 internal structured cloning algorithm. +namespace JS { +enum TransferableOwnership { + // Transferable data has not been filled in yet + SCTAG_TMO_UNFILLED = 0, + + // Structured clone buffer does not yet own the data + SCTAG_TMO_UNOWNED = 1, + + // All values at least this large are owned by the clone buffer + SCTAG_TMO_FIRST_OWNED = 2, + + // Data is a pointer that can be freed + SCTAG_TMO_ALLOC_DATA = 2, + + // Data is a SharedArrayBufferObject's buffer + SCTAG_TMO_SHARED_BUFFER = 3, + + // Data is a memory mapped pointer + SCTAG_TMO_MAPPED_DATA = 4, + + // Data is embedding-specific. The engine can free it by calling the + // freeTransfer op. The embedding can also use SCTAG_TMO_USER_MIN and + // greater, up to 32 bits, to distinguish specific ownership variants. + SCTAG_TMO_CUSTOM = 5, + + SCTAG_TMO_USER_MIN +}; +} /* namespace JS */ + // Read structured data from the reader r. This hook is used to read a value // previously serialized by a call to the WriteStructuredCloneOp hook. // @@ -43,22 +72,64 @@ typedef JSObject *(*ReadStructuredCloneOp)(JSContext *cx, JSStructuredCloneReade // // Return true on success, false on error/exception. typedef bool (*WriteStructuredCloneOp)(JSContext *cx, JSStructuredCloneWriter *w, - JS::Handle obj, void *closure); + JS::HandleObject obj, void *closure); // This is called when JS_WriteStructuredClone is given an invalid transferable. // To follow HTML5, the application must throw a DATA_CLONE_ERR DOMException // with error set to one of the JS_SCERR_* values. typedef void (*StructuredCloneErrorOp)(JSContext *cx, uint32_t errorid); +// This is called when JS_ReadStructuredClone receives a transferable object +// not known to the engine. If this hook does not exist or returns false, the +// JS engine calls the reportError op if set, otherwise it throws a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback and must return a non-null object in returnObject on success. +typedef bool (*ReadTransferStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r, + uint32_t tag, void *content, uint64_t extraData, + void *closure, + JS::MutableHandleObject returnObject); + +// Called when JS_WriteStructuredClone receives a transferable object not +// handled by the engine. If this hook does not exist or returns false, the JS +// engine will call the reportError hook or fall back to throwing a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback. +// +// tag: indicates what type of transferable this is. Must be greater than +// 0xFFFF0201 (value of the internal SCTAG_TRANSFER_MAP_PENDING_ENTRY) +// +// ownership: see TransferableOwnership, above. Used to communicate any needed +// ownership info to the FreeTransferStructuredCloneOp. +// +// content, extraData: what the ReadTransferStructuredCloneOp will receive +// +typedef bool (*TransferStructuredCloneOp)(JSContext *cx, + JS::Handle obj, + void *closure, + // Output: + uint32_t *tag, + JS::TransferableOwnership *ownership, + void **content, + uint64_t *extraData); + +// Called when JS_ClearStructuredClone has to free an unknown transferable +// object. Note that it should never trigger a garbage collection (and will +// assert in a debug build if it does.) +typedef void (*FreeTransferStructuredCloneOp)(uint32_t tag, JS::TransferableOwnership ownership, + void *content, uint64_t extraData, void *closure); + // The maximum supported structured-clone serialization format version. Note // that this does not need to be bumped for Transferable-only changes, since // they are never saved to persistent storage. -#define JS_STRUCTURED_CLONE_VERSION 2 +#define JS_STRUCTURED_CLONE_VERSION 4 struct JSStructuredCloneCallbacks { ReadStructuredCloneOp read; WriteStructuredCloneOp write; StructuredCloneErrorOp reportError; + ReadTransferStructuredCloneOp readTransfer; + TransferStructuredCloneOp writeTransfer; + FreeTransferStructuredCloneOp freeTransfer; }; // Note: if the *data contains transferable objects, it can be read only once. @@ -68,14 +139,16 @@ JS_ReadStructuredClone(JSContext *cx, uint64_t *data, size_t nbytes, uint32_t ve const JSStructuredCloneCallbacks *optionalCallbacks, void *closure); // Note: On success, the caller is responsible for calling -// JS_ClearStructuredClone(*datap, nbytesp). +// JS_ClearStructuredClone(*datap, nbytes, optionalCallbacks, closure). JS_PUBLIC_API(bool) JS_WriteStructuredClone(JSContext *cx, JS::HandleValue v, uint64_t **datap, size_t *nbytesp, const JSStructuredCloneCallbacks *optionalCallbacks, void *closure, JS::HandleValue transferable); JS_PUBLIC_API(bool) -JS_ClearStructuredClone(const uint64_t *data, size_t nbytes); +JS_ClearStructuredClone(uint64_t *data, size_t nbytes, + const JSStructuredCloneCallbacks *optionalCallbacks, + void *closure); JS_PUBLIC_API(bool) JS_StructuredCloneHasTransferables(const uint64_t *data, size_t nbytes, bool *hasTransferable); @@ -89,10 +162,22 @@ class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) { uint64_t *data_; size_t nbytes_; uint32_t version_; + const JSStructuredCloneCallbacks *callbacks_; + void *closure_; public: JSAutoStructuredCloneBuffer() - : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION) {} + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(nullptr), closure_(nullptr) + {} + + JSAutoStructuredCloneBuffer(const JSStructuredCloneCallbacks *callbacks, void *closure) + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(callbacks), closure_(closure) + {} + + JSAutoStructuredCloneBuffer(JSAutoStructuredCloneBuffer &&other); + JSAutoStructuredCloneBuffer &operator=(JSAutoStructuredCloneBuffer &&other); ~JSAutoStructuredCloneBuffer() { clear(); } @@ -123,13 +208,10 @@ class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) { bool write(JSContext *cx, JS::HandleValue v, JS::HandleValue transferable, const JSStructuredCloneCallbacks *optionalCallbacks=nullptr, void *closure=nullptr); - // Swap ownership with another JSAutoStructuredCloneBuffer. - void swap(JSAutoStructuredCloneBuffer &other); - private: // Copy and assignment are not supported. - JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other); - JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other); + JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; + JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; }; // The range of tag values the application may use for its own custom object types. @@ -149,7 +231,7 @@ JS_PUBLIC_API(bool) JS_ReadBytes(JSStructuredCloneReader *r, void *p, size_t len); JS_PUBLIC_API(bool) -JS_ReadTypedArray(JSStructuredCloneReader *r, JS::Value *vp); +JS_ReadTypedArray(JSStructuredCloneReader *r, JS::MutableHandleValue vp); JS_PUBLIC_API(bool) JS_WriteUint32Pair(JSStructuredCloneWriter *w, uint32_t tag, uint32_t data); @@ -158,6 +240,6 @@ JS_PUBLIC_API(bool) JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len); JS_PUBLIC_API(bool) -JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::Value v); +JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::HandleValue v); #endif /* js_StructuredClone_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/Tracer.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/Tracer.h deleted file mode 100644 index 89994612f6..0000000000 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/Tracer.h +++ /dev/null @@ -1,193 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * vim: set ts=8 sts=4 et sw=4 tw=99: - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef js_Tracer_h -#define js_Tracer_h - -#include "mozilla/NullPtr.h" - -#include "jspubtd.h" - -struct JSTracer; - -namespace JS { -template class Heap; -template class TenuredHeap; -} - -// Tracer callback, called for each traceable thing directly referenced by a -// particular object or runtime structure. It is the callback responsibility -// to ensure the traversal of the full object graph via calling eventually -// JS_TraceChildren on the passed thing. In this case the callback must be -// prepared to deal with cycles in the traversal graph. -// -// kind argument is one of JSTRACE_OBJECT, JSTRACE_STRING or a tag denoting -// internal implementation-specific traversal kind. In the latter case the only -// operations on thing that the callback can do is to call JS_TraceChildren or -// JS_GetTraceThingInfo. -// -// If eagerlyTraceWeakMaps is true, when we trace a WeakMap visit all -// of its mappings. This should be used in cases where the tracer -// wants to use the existing liveness of entries. -typedef void -(* JSTraceCallback)(JSTracer *trc, void **thingp, JSGCTraceKind kind); - -// Callback that JSTraceOp implementation can provide to return a string -// describing the reference traced with JS_CallTracer. -typedef void -(* JSTraceNamePrinter)(JSTracer *trc, char *buf, size_t bufsize); - -enum WeakMapTraceKind { - DoNotTraceWeakMaps = 0, - TraceWeakMapValues = 1, - TraceWeakMapKeysValues = 2 -}; - -struct JSTracer { - JSRuntime *runtime; - JSTraceCallback callback; - JSTraceNamePrinter debugPrinter; - const void *debugPrintArg; - size_t debugPrintIndex; - WeakMapTraceKind eagerlyTraceWeakMaps; -#ifdef JS_GC_ZEAL - void *realLocation; -#endif -}; - -// Set debugging information about a reference to a traceable thing to prepare -// for the following call to JS_CallTracer. -// -// When printer is null, arg must be const char * or char * C string naming -// the reference and index must be either (size_t)-1 indicating that the name -// alone describes the reference or it must be an index into some array vector -// that stores the reference. -// -// When printer callback is not null, the arg and index arguments are -// available to the callback as debugPrintArg and debugPrintIndex fields -// of JSTracer. -// -// The storage for name or callback's arguments needs to live only until -// the following call to JS_CallTracer returns. -// -# define JS_SET_TRACING_DETAILS(trc, printer, arg, index) \ - JS_BEGIN_MACRO \ - (trc)->debugPrinter = (printer); \ - (trc)->debugPrintArg = (arg); \ - (trc)->debugPrintIndex = (index); \ - JS_END_MACRO - -// Sets the real location for a marked reference, when passing the address -// directly is not feasable. -// -// FIXME: This is currently overcomplicated by our need to nest calls for Values -// stored as keys in hash tables, but will get simplified once we can rekey -// in-place. -// -#ifdef JS_GC_ZEAL -# define JS_SET_TRACING_LOCATION(trc, location) \ - JS_BEGIN_MACRO \ - if (!(trc)->realLocation || !(location)) \ - (trc)->realLocation = (location); \ - JS_END_MACRO -# define JS_UNSET_TRACING_LOCATION(trc) \ - JS_BEGIN_MACRO \ - (trc)->realLocation = nullptr; \ - JS_END_MACRO -#else -# define JS_SET_TRACING_LOCATION(trc, location) \ - JS_BEGIN_MACRO \ - JS_END_MACRO -# define JS_UNSET_TRACING_LOCATION(trc) \ - JS_BEGIN_MACRO \ - JS_END_MACRO -#endif - -// Convenience macro to describe the argument of JS_CallTracer using C string -// and index. -# define JS_SET_TRACING_INDEX(trc, name, index) \ - JS_SET_TRACING_DETAILS(trc, nullptr, name, index) - -// Convenience macro to describe the argument of JS_CallTracer using C string. -# define JS_SET_TRACING_NAME(trc, name) \ - JS_SET_TRACING_DETAILS(trc, nullptr, name, (size_t)-1) - -// The JS_Call*Tracer family of functions traces the given GC thing reference. -// This performs the tracing action configured on the given JSTracer: -// typically calling the JSTracer::callback or marking the thing as live. -// -// The argument to JS_Call*Tracer is an in-out param: when the function -// returns, the garbage collector might have moved the GC thing. In this case, -// the reference passed to JS_Call*Tracer will be updated to the object's new -// location. Callers of this method are responsible for updating any state -// that is dependent on the object's address. For example, if the object's -// address is used as a key in a hashtable, then the object must be removed -// and re-inserted with the correct hash. -// -extern JS_PUBLIC_API(void) -JS_CallValueTracer(JSTracer *trc, JS::Value *valuep, const char *name); - -extern JS_PUBLIC_API(void) -JS_CallIdTracer(JSTracer *trc, jsid *idp, const char *name); - -extern JS_PUBLIC_API(void) -JS_CallObjectTracer(JSTracer *trc, JSObject **objp, const char *name); - -extern JS_PUBLIC_API(void) -JS_CallStringTracer(JSTracer *trc, JSString **strp, const char *name); - -extern JS_PUBLIC_API(void) -JS_CallScriptTracer(JSTracer *trc, JSScript **scriptp, const char *name); - -extern JS_PUBLIC_API(void) -JS_CallHeapValueTracer(JSTracer *trc, JS::Heap *valuep, const char *name); - -extern JS_PUBLIC_API(void) -JS_CallHeapIdTracer(JSTracer *trc, JS::Heap *idp, const char *name); - -extern JS_PUBLIC_API(void) -JS_CallHeapObjectTracer(JSTracer *trc, JS::Heap *objp, const char *name); - -extern JS_PUBLIC_API(void) -JS_CallHeapStringTracer(JSTracer *trc, JS::Heap *strp, const char *name); - -extern JS_PUBLIC_API(void) -JS_CallHeapScriptTracer(JSTracer *trc, JS::Heap *scriptp, const char *name); - -template -inline void -JS_CallHashSetObjectTracer(JSTracer *trc, HashSetEnum &e, JSObject *const &key, const char *name) -{ - JSObject *updated = key; - JS_SET_TRACING_LOCATION(trc, reinterpret_cast(&const_cast(key))); - JS_CallObjectTracer(trc, &updated, name); - if (updated != key) - e.rekeyFront(key, updated); -} - -// Trace an object that is known to always be tenured. No post barriers are -// required in this case. -extern JS_PUBLIC_API(void) -JS_CallTenuredObjectTracer(JSTracer *trc, JS::TenuredHeap *objp, const char *name); - -// API for JSTraceCallback implementations. -extern JS_PUBLIC_API(void) -JS_TracerInit(JSTracer *trc, JSRuntime *rt, JSTraceCallback callback); - -extern JS_PUBLIC_API(void) -JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind); - -extern JS_PUBLIC_API(void) -JS_TraceRuntime(JSTracer *trc); - -extern JS_PUBLIC_API(void) -JS_GetTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc, - void *thing, JSGCTraceKind kind, bool includeDetails); - -extern JS_PUBLIC_API(const char *) -JS_GetTraceEdgeName(JSTracer *trc, char *buffer, int bufferSize); - -#endif /* js_Tracer_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/TracingAPI.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/TracingAPI.h new file mode 100644 index 0000000000..3c7fdbe1b1 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/TracingAPI.h @@ -0,0 +1,216 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_TracingAPI_h +#define js_TracingAPI_h + +#include "mozilla/NullPtr.h" + +#include "jspubtd.h" + +class JS_PUBLIC_API(JSTracer); + +namespace JS { +template class Heap; +template class TenuredHeap; +} + +// Tracer callback, called for each traceable thing directly referenced by a +// particular object or runtime structure. It is the callback responsibility +// to ensure the traversal of the full object graph via calling eventually +// JS_TraceChildren on the passed thing. In this case the callback must be +// prepared to deal with cycles in the traversal graph. +// +// kind argument is one of JSTRACE_OBJECT, JSTRACE_STRING or a tag denoting +// internal implementation-specific traversal kind. In the latter case the only +// operations on thing that the callback can do is to call JS_TraceChildren or +// JS_GetTraceThingInfo. +// +// If eagerlyTraceWeakMaps is true, when we trace a WeakMap visit all +// of its mappings. This should be used in cases where the tracer +// wants to use the existing liveness of entries. +typedef void +(* JSTraceCallback)(JSTracer *trc, void **thingp, JSGCTraceKind kind); + +// Callback that JSTraceOp implementation can provide to return a string +// describing the reference traced with JS_CallTracer. +typedef void +(* JSTraceNamePrinter)(JSTracer *trc, char *buf, size_t bufsize); + +enum WeakMapTraceKind { + DoNotTraceWeakMaps = 0, + TraceWeakMapValues = 1, + TraceWeakMapKeysValues = 2 +}; + +class JS_PUBLIC_API(JSTracer) +{ + public: + JSTracer(JSRuntime *rt, JSTraceCallback traceCallback, + WeakMapTraceKind weakTraceKind = TraceWeakMapValues); + + // Set debugging information about a reference to a traceable thing to prepare + // for the following call to JS_CallTracer. + // + // When printer is null, arg must be const char * or char * C string naming + // the reference and index must be either (size_t)-1 indicating that the name + // alone describes the reference or it must be an index into some array vector + // that stores the reference. + // + // When printer callback is not null, the arg and index arguments are + // available to the callback as debugPrintArg_ and debugPrintIndex_ fields + // of JSTracer. + // + // The storage for name or callback's arguments needs to live only until + // the following call to JS_CallTracer returns. + void setTracingDetails(JSTraceNamePrinter printer, const void *arg, size_t index) { + debugPrinter_ = printer; + debugPrintArg_ = arg; + debugPrintIndex_ = index; + } + + void setTracingIndex(const char *name, size_t index) { + setTracingDetails(nullptr, (void *)name, index); + } + + void setTracingName(const char *name) { + setTracingDetails(nullptr, (void *)name, size_t(-1)); + } + + // Remove the currently set tracing details. + void clearTracingDetails() { + debugPrinter_ = nullptr; + debugPrintArg_ = nullptr; + } + + // Return true if tracing details are currently set. + bool hasTracingDetails() const; + + // Get the string set with the most recent call to setTracingName or return + // fallback if a name printer function has been installed. + const char *tracingName(const char *fallback) const; + + // Build a description of this edge in the heap graph. This call may invoke + // the debug printer, which may inspect arbitrary areas of the heap. + const char *getTracingEdgeName(char *buffer, size_t bufferSize); + + // Access the currently active tracing details. + JSTraceNamePrinter debugPrinter() const; + const void *debugPrintArg() const; + size_t debugPrintIndex() const; + + // Return the runtime set on the tracer. + JSRuntime *runtime() const { return runtime_; } + + // Return the weak map tracing behavior set on this tracer. + WeakMapTraceKind eagerlyTraceWeakMaps() const { return eagerlyTraceWeakMaps_; } + + // Update the trace callback. + void setTraceCallback(JSTraceCallback traceCallback); + +#ifdef JS_GC_ZEAL + // Sets the "real" location for a marked reference, when passing the address + // directly is not feasable. This address is used for matching against the + // store buffer when verifying the correctness of the entrees there. + // + // This is currently complicated by our need to nest calls for Values + // stored as keys in hash tables. + void setTracingLocation(void *location); + void unsetTracingLocation(); + void **tracingLocation(void **thingp); +#else + void setTracingLocation(void *location) {} + void unsetTracingLocation() {} + void **tracingLocation(void **thingp) { return nullptr; } +#endif + + // We expose |callback| directly so that IS_GC_MARKING_TRACER can compare + // it to GCMarker::GrayCallback. + JSTraceCallback callback; + + private: + JSRuntime *runtime_; + JSTraceNamePrinter debugPrinter_; + const void *debugPrintArg_; + size_t debugPrintIndex_; + WeakMapTraceKind eagerlyTraceWeakMaps_; +#ifdef JS_GC_ZEAL + void *realLocation_; +#endif +}; + +// The JS_Call*Tracer family of functions traces the given GC thing reference. +// This performs the tracing action configured on the given JSTracer: +// typically calling the JSTracer::callback or marking the thing as live. +// +// The argument to JS_Call*Tracer is an in-out param: when the function +// returns, the garbage collector might have moved the GC thing. In this case, +// the reference passed to JS_Call*Tracer will be updated to the object's new +// location. Callers of this method are responsible for updating any state +// that is dependent on the object's address. For example, if the object's +// address is used as a key in a hashtable, then the object must be removed +// and re-inserted with the correct hash. +// +extern JS_PUBLIC_API(void) +JS_CallValueTracer(JSTracer *trc, JS::Value *valuep, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallIdTracer(JSTracer *trc, jsid *idp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallObjectTracer(JSTracer *trc, JSObject **objp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallStringTracer(JSTracer *trc, JSString **strp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallScriptTracer(JSTracer *trc, JSScript **scriptp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapValueTracer(JSTracer *trc, JS::Heap *valuep, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapIdTracer(JSTracer *trc, JS::Heap *idp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapObjectTracer(JSTracer *trc, JS::Heap *objp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapStringTracer(JSTracer *trc, JS::Heap *strp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapScriptTracer(JSTracer *trc, JS::Heap *scriptp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapFunctionTracer(JSTracer *trc, JS::Heap *funp, const char *name); + +template +inline void +JS_CallHashSetObjectTracer(JSTracer *trc, HashSetEnum &e, JSObject *const &key, const char *name) +{ + JSObject *updated = key; + trc->setTracingLocation(reinterpret_cast(&const_cast(key))); + JS_CallObjectTracer(trc, &updated, name); + if (updated != key) + e.rekeyFront(key, updated); +} + +// Trace an object that is known to always be tenured. No post barriers are +// required in this case. +extern JS_PUBLIC_API(void) +JS_CallTenuredObjectTracer(JSTracer *trc, JS::TenuredHeap *objp, const char *name); + +extern JS_PUBLIC_API(void) +JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind); + +extern JS_PUBLIC_API(void) +JS_TraceRuntime(JSTracer *trc); + +extern JS_PUBLIC_API(void) +JS_GetTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc, + void *thing, JSGCTraceKind kind, bool includeDetails); + +#endif /* js_TracingAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/TypeDecls.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/TypeDecls.h index 027d7b8fb7..3e1e8afc66 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/TypeDecls.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/TypeDecls.h @@ -20,44 +20,24 @@ #include #include +#include "js-config.h" + struct JSContext; class JSFunction; class JSObject; class JSScript; class JSString; +class JSAddonId; -// In release builds, jsid is defined to be an integral type. This -// prevents many bugs from being caught at compile time. E.g.: -// -// jsid id = ... -// if (id) // error -// ... -// -// size_t n = id; // error -// -// To catch more errors, jsid is given a struct type in C++ debug builds. -// Struct assignment and (in C++) operator== allow correct code to be mostly -// oblivious to the change. This feature can be explicitly disabled in debug -// builds by defining JS_NO_JSVAL_JSID_STRUCT_TYPES. -// - -// Needed for cocos2d-js -#define JS_NO_JSVAL_JSID_STRUCT_TYPES - -#if defined(DEBUG) && !defined(JS_NO_JSVAL_JSID_STRUCT_TYPES) -# define JS_USE_JSID_STRUCT_TYPES -#endif - -#ifdef JS_USE_JSID_STRUCT_TYPES struct jsid; -#else -typedef ptrdiff_t jsid; -#endif typedef char16_t jschar; namespace JS { +typedef unsigned char Latin1Char; + +class Symbol; class Value; template class Handle; template class MutableHandle; @@ -69,6 +49,7 @@ typedef Handle HandleId; typedef Handle HandleObject; typedef Handle HandleScript; typedef Handle HandleString; +typedef Handle HandleSymbol; typedef Handle HandleValue; typedef MutableHandle MutableHandleFunction; @@ -76,12 +57,14 @@ typedef MutableHandle MutableHandleId; typedef MutableHandle MutableHandleObject; typedef MutableHandle MutableHandleScript; typedef MutableHandle MutableHandleString; +typedef MutableHandle MutableHandleSymbol; typedef MutableHandle MutableHandleValue; typedef Rooted RootedObject; typedef Rooted RootedFunction; typedef Rooted RootedScript; typedef Rooted RootedString; +typedef Rooted RootedSymbol; typedef Rooted RootedId; typedef Rooted RootedValue; @@ -90,6 +73,7 @@ typedef PersistentRooted PersistentRootedId; typedef PersistentRooted PersistentRootedObject; typedef PersistentRooted PersistentRootedScript; typedef PersistentRooted PersistentRootedString; +typedef PersistentRooted PersistentRootedSymbol; typedef PersistentRooted PersistentRootedValue; } // namespace JS diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/UbiNode.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/UbiNode.h new file mode 100644 index 0000000000..d2acc2e242 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/UbiNode.h @@ -0,0 +1,462 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_UbiNode_h +#define js_UbiNode_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" + +#include "jspubtd.h" + +#include "js/GCAPI.h" +#include "js/HashTable.h" +#include "js/TypeDecls.h" + +// JS::ubi::Node +// +// JS::ubi::Node is a pointer-like type designed for internal use by heap +// analysis tools. A ubi::Node can refer to: +// +// - a JS value, like a string or object; +// - an internal SpiderMonkey structure, like a shape or a scope chain object +// - an instance of some embedding-provided type: in Firefox, an XPCOM +// object, or an internal DOM node class instance +// +// A ubi::Node instance provides metadata about its referent, and can +// enumerate its referent's outgoing edges, so you can implement heap analysis +// algorithms that walk the graph - finding paths between objects, or +// computing heap dominator trees, say - using ubi::Node, while remaining +// ignorant of the details of the types you're operating on. +// +// Of course, when it comes to presenting the results in a developer-facing +// tool, you'll need to stop being ignorant of those details, because you have +// to discuss the ubi::Nodes' referents with the developer. Here, ubi::Node +// can hand you dynamically checked, properly typed pointers to the original +// objects via the as method, or generate descriptions of the referent +// itself. +// +// ubi::Node instances are lightweight (two-word) value types. Instances: +// - compare equal if and only if they refer to the same object; +// - have hash values that respect their equality relation; and +// - have serializations that are only equal if the ubi::Nodes are equal. +// +// A ubi::Node is only valid for as long as its referent is alive; if its +// referent goes away, the ubi::Node becomes a dangling pointer. A ubi::Node +// that refers to a GC-managed object is not automatically a GC root; if the +// GC frees or relocates its referent, the ubi::Node becomes invalid. A +// ubi::Node that refers to a reference-counted object does not bump the +// reference count. +// +// ubi::Node values require no supporting data structures, making them +// feasible for use in memory-constrained devices --- ideally, the memory +// requirements of the algorithm which uses them will be the limiting factor, +// not the demands of ubi::Node itself. +// +// One can construct a ubi::Node value given a pointer to a type that ubi::Node +// supports. In the other direction, one can convert a ubi::Node back to a +// pointer; these downcasts are checked dynamically. In particular, one can +// convert a 'JSRuntime *' to a ubi::Node, yielding a node with an outgoing edge +// for every root registered with the runtime; starting from this, one can walk +// the entire heap. (Of course, one could also start traversal at any other kind +// of type to which one has a pointer.) +// +// +// Extending ubi::Node To Handle Your Embedding's Types +// +// To add support for a new ubi::Node referent type R, you must define a +// specialization of the ubi::Concrete template, ubi::Concrete, which +// inherits from ubi::Base. ubi::Node itself uses the specialization for +// compile-time information (i.e. the checked conversions between R * and +// ubi::Node), and the inheritance for run-time dispatching. +// +// +// ubi::Node Exposes Implementation Details +// +// In many cases, a JavaScript developer's view of their data differs +// substantially from its actual implementation. For example, while the +// ECMAScript specification describes objects as maps from property names to +// sets of attributes (like ECMAScript's [[Value]]), in practice many objects +// have only a pointer to a shape, shared with other similar objects, and +// indexed slots that contain the [[Value]] attributes. As another example, a +// string produced by concatenating two other strings may sometimes be +// represented by a "rope", a structure that points to the two original +// strings. +// + +// We intend to use ubi::Node to write tools that report memory usage, so it's +// important that ubi::Node accurately portray how much memory nodes consume. +// Thus, for example, when data that apparently belongs to multiple nodes is +// in fact shared in a common structure, ubi::Node's graph uses a separate +// node for that shared structure, and presents edges to it from the data's +// apparent owners. For example, ubi::Node exposes SpiderMonkey objects' +// shapes and base shapes, and exposes rope string and substring structure, +// because these optimizations become visible when a tool reports how much +// memory a structure consumes. +// +// However, fine granularity is not a goal. When a particular object is the +// exclusive owner of a separate block of memory, ubi::Node may present the +// object and its block as a single node, and add their sizes together when +// reporting the node's size, as there is no meaningful loss of data in this +// case. Thus, for example, a ubi::Node referring to a JavaScript object, when +// asked for the object's size in bytes, includes the object's slot and +// element arrays' sizes in the total. There is no separate ubi::Node value +// representing the slot and element arrays, since they are owned exclusively +// by the object. +// +// +// Presenting Analysis Results To JavaScript Developers +// +// If an analysis provides its results in terms of ubi::Node values, a user +// interface presenting those results will generally need to clean them up +// before they can be understood by JavaScript developers. For example, +// JavaScript developers should not need to understand shapes, only JavaScript +// objects. Similarly, they should not need to understand the distinction +// between DOM nodes and the JavaScript shadow objects that represent them. +// +// +// Rooting Restrictions +// +// At present there is no way to root ubi::Node instances, so instances can't be +// live across any operation that might GC. Analyses using ubi::Node must either +// run to completion and convert their results to some other rootable type, or +// save their intermediate state in some rooted structure if they must GC before +// they complete. (For algorithms like path-finding and dominator tree +// computation, we implement the algorithm avoiding any operation that could +// cause a GC --- and use AutoCheckCannotGC to verify this.) +// +// If this restriction prevents us from implementing interesting tools, we may +// teach the GC how to root ubi::Nodes, fix up hash tables that use them as +// keys, etc. + + +// Forward declarations of SpiderMonkey's ubi::Node reference types. +namespace js { +class LazyScript; +class Shape; +class BaseShape; +namespace jit { +class JitCode; +} +namespace types { +struct TypeObject; +} +} + + +namespace JS { +namespace ubi { + +class Edge; +class EdgeRange; + +// The base class implemented by each ubi::Node referent type. Subclasses must +// not add data members to this class. +class Base { + friend class Node; + + // For performance's sake, we'd prefer to avoid a virtual destructor; and + // an empty constructor seems consistent with the 'lightweight value type' + // visible behavior we're trying to achieve. But if the destructor isn't + // virtual, and a subclass overrides it, the subclass's destructor will be + // ignored. Is there a way to make the compiler catch that error? + + protected: + // Space for the actual pointer. Concrete subclasses should define a + // properly typed 'get' member function to access this. + void *ptr; + + Base(void *ptr) : ptr(ptr) { } + + public: + bool operator==(const Base &rhs) const { + // Some compilers will indeed place objects of different types at + // the same address, so technically, we should include the vtable + // in this comparison. But it seems unlikely to cause problems in + // practice. + return ptr == rhs.ptr; + } + bool operator!=(const Base &rhs) const { return !(*this == rhs); } + + // Return a human-readable name for the referent's type. The result should + // be statically allocated. (You can use MOZ_UTF16("strings") for this.) + // + // This must always return Concrete::concreteTypeName; we use that + // pointer as a tag for this particular referent type. + virtual const jschar *typeName() const = 0; + + // Return the size of this node, in bytes. Include any structures that this + // node owns exclusively that are not exposed as their own ubi::Nodes. + virtual size_t size() const = 0; + + // Return an EdgeRange that initially contains all the referent's outgoing + // edges. The EdgeRange should be freed with 'js_delete'. (You could use + // ScopedDJSeletePtr to manage it.) On OOM, report an exception + // on |cx| and return nullptr. + virtual EdgeRange *edges(JSContext *cx) const = 0; + + private: + Base(const Base &rhs) MOZ_DELETE; + Base &operator=(const Base &rhs) MOZ_DELETE; +}; + +// A traits template with a specialization for each referent type that +// ubi::Node supports. The specialization must be the concrete subclass of +// Base that represents a pointer to the referent type. It must also +// include the members described here. +template +struct Concrete { + // The specific jschar array returned by Concrete::typeName. + static const jschar concreteTypeName[]; + + // Construct an instance of this concrete class in |storage| referring + // to |referent|. Implementations typically use a placement 'new'. + // + // In some cases, |referent| will contain dynamic type information that + // identifies it a some more specific subclass of |Referent|. For example, + // when |Referent| is |JSObject|, then |referent->getClass()| could tell us + // that it's actually a JSFunction. Similarly, if |Referent| is + // |nsISupports|, we would like a ubi::Node that knows its final + // implementation type. + // + // So, we delegate the actual construction to this specialization, which + // knows Referent's details. + static void construct(void *storage, Referent *referent); +}; + +// A container for a Base instance; all members simply forward to the contained instance. +// This container allows us to pass ubi::Node instances by value. +class Node { + // Storage in which we allocate Base subclasses. + mozilla::AlignedStorage2 storage; + Base *base() { return storage.addr(); } + const Base *base() const { return storage.addr(); } + + template + void construct(T *ptr) { + static_assert(sizeof(Concrete) == sizeof(*base()), + "ubi::Base specializations must be the same size as ubi::Base"); + Concrete::construct(base(), ptr); + } + + typedef void (Node::* ConvertibleToBool)(); + void nonNull() {} + + public: + Node() { construct(nullptr); } + + template + Node(T *ptr) { + construct(ptr); + } + template + Node &operator=(T *ptr) { + construct(ptr); + return *this; + } + + // We can construct and assign from rooted forms of pointers. + template + Node(const Rooted &root) { + construct(root.get()); + } + template + Node &operator=(const Rooted &root) { + construct(root.get()); + return *this; + } + + // Constructors accepting SpiderMonkey's other generic-pointer-ish types. + Node(JS::Value value); + Node(JSGCTraceKind kind, void *ptr); + + // copy construction and copy assignment just use memcpy, since we know + // instances contain nothing but a vtable pointer and a data pointer. + // + // To be completely correct, concrete classes could provide a virtual + // 'construct' member function, which we could invoke on rhs to construct an + // instance in our storage. But this is good enough; there's no need to jump + // through vtables for copying and assignment that are just going to move + // two words around. The compiler knows how to optimize memcpy. + Node(const Node &rhs) { + memcpy(storage.u.mBytes, rhs.storage.u.mBytes, sizeof(storage.u)); + } + + Node &operator=(const Node &rhs) { + memcpy(storage.u.mBytes, rhs.storage.u.mBytes, sizeof(storage.u)); + return *this; + } + + bool operator==(const Node &rhs) const { return *base() == *rhs.base(); } + bool operator!=(const Node &rhs) const { return *base() != *rhs.base(); } + + operator ConvertibleToBool() const { + return base()->ptr ? &Node::nonNull : 0; + } + + template + bool is() const { + return base()->typeName() == Concrete::concreteTypeName; + } + + template + T *as() const { + MOZ_ASSERT(is()); + return static_cast(base()->ptr); + } + + template + T *asOrNull() const { + return is() ? static_cast(base()->ptr) : nullptr; + } + + // If this node refers to something that can be represented as a + // JavaScript value that is safe to expose to JavaScript code, return that + // value. Otherwise return UndefinedValue(). JSStrings and some (but not + // all!) JSObjects can be exposed. + JS::Value exposeToJS() const; + + const jschar *typeName() const { return base()->typeName(); } + size_t size() const { return base()->size(); } + EdgeRange *edges(JSContext *cx) const { return base()->edges(cx); } + + // A hash policy for ubi::Nodes. + // This simply uses the stock PointerHasher on the ubi::Node's pointer. + // We specialize DefaultHasher below to make this the default. + class HashPolicy { + typedef js::PointerHasher::value> PtrHash; + + public: + typedef Node Lookup; + + static js::HashNumber hash(const Lookup &l) { return PtrHash::hash(l.base()->ptr); } + static bool match(const Node &k, const Lookup &l) { return k == l; } + static void rekey(Node &k, const Node &newKey) { k = newKey; } + }; +}; + + +// Edge is the abstract base class representing an outgoing edge of a node. +// Edges are owned by EdgeRanges, and need not have assignment operators or copy +// constructors. +// +// Each Edge class should inherit from this base class, overriding as +// appropriate. +class Edge { + protected: + Edge() : name(nullptr), referent() { } + virtual ~Edge() { } + + public: + // This edge's name. + // + // The storage is owned by this Edge, and will be freed when this Edge is + // destructed. + // + // (In real life we'll want a better representation for names, to avoid + // creating tons of strings when the names follow a pattern; and we'll need + // to think about lifetimes carefully to ensure traversal stays cheap.) + const jschar *name; + + // This edge's referent. + Node referent; + + private: + Edge(const Edge &) MOZ_DELETE; + Edge &operator=(const Edge &) MOZ_DELETE; +}; + + +// EdgeRange is an abstract base class for iterating over a node's outgoing +// edges. (This is modeled after js::HashTable::Range.) +// +// Concrete instances of this class need not be as lightweight as Node itself, +// since they're usually only instantiated while iterating over a particular +// object's edges. For example, a dumb implementation for JS Cells might use +// JS_TraceChildren to to get the outgoing edges, and then store them in an +// array internal to the EdgeRange. +class EdgeRange { + protected: + // The current front edge of this range, or nullptr if this range is empty. + Edge *front_; + + EdgeRange() : front_(nullptr) { } + + public: + virtual ~EdgeRange() { }; + + // True if there are no more edges in this range. + bool empty() const { return !front_; } + + // The front edge of this range. This is owned by the EdgeRange, and is + // only guaranteed to live until the next call to popFront, or until + // the EdgeRange is destructed. + const Edge &front() { return *front_; } + + // Remove the front edge from this range. This should only be called if + // !empty(). + virtual void popFront() = 0; + + private: + EdgeRange(const EdgeRange &) MOZ_DELETE; + EdgeRange &operator=(const EdgeRange &) MOZ_DELETE; +}; + + +// Concrete classes for ubi::Node referent types. + +// A reusable ubi::Concrete specialization base class for types supported by +// JS_TraceChildren. +template +class TracerConcrete : public Base { + const jschar *typeName() const MOZ_OVERRIDE { return concreteTypeName; } + size_t size() const MOZ_OVERRIDE { return 0; } // not implemented yet; bug 1011300 + EdgeRange *edges(JSContext *) const MOZ_OVERRIDE; + + TracerConcrete(Referent *ptr) : Base(ptr) { } + + public: + static const jschar concreteTypeName[]; + static void construct(void *storage, Referent *ptr) { new (storage) TracerConcrete(ptr); }; +}; + +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; + +// The ubi::Node null pointer. Any attempt to operate on a null ubi::Node asserts. +template<> +class Concrete : public Base { + const jschar *typeName() const MOZ_OVERRIDE; + size_t size() const MOZ_OVERRIDE; + EdgeRange *edges(JSContext *cx) const MOZ_OVERRIDE; + + Concrete(void *ptr) : Base(ptr) { } + + public: + static void construct(void *storage, void *ptr) { new (storage) Concrete(ptr); } + static const jschar concreteTypeName[]; +}; + + +} // namespace ubi +} // namespace JS + +namespace js { + +// Make ubi::Node::HashPolicy the default hash policy for ubi::Node. +template<> struct DefaultHasher : JS::ubi::Node::HashPolicy { }; + +} // namespace js + +#endif // js_UbiNode_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/UbiNodeTraverse.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/UbiNodeTraverse.h new file mode 100644 index 0000000000..6072cbc489 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/UbiNodeTraverse.h @@ -0,0 +1,208 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_UbiNodeTraverse_h +#define js_UbiNodeTraverse_h + +#include "js/UbiNode.h" +#include "js/Utility.h" +#include "js/Vector.h" + +namespace JS { +namespace ubi { + +// A breadth-first traversal template for graphs of ubi::Nodes. +// +// No GC may occur while an instance of this template is live. +// +// The provided Handler type should have two members: +// +// typename NodeData; +// +// The value type of |BreadthFirst::visited|, the HashMap of +// ubi::Nodes that have been visited so far. Since the algorithm needs a +// hash table like this for its own use anyway, it is simple to let +// Handler store its own metadata about each node in the same table. +// +// For example, if you want to find a shortest path to each node from any +// traversal starting point, your |NodeData| type could record the first +// edge to reach each node, and the node from which it originates. Then, +// when the traversal is complete, you can walk backwards from any node +// to some starting point, and the path recorded will be a shortest path. +// +// This type must have a default constructor. If this type owns any other +// resources, move constructors and assignment operators are probably a +// good idea, too. +// +// bool operator() (BreadthFirst &traversal, +// Node origin, const Edge &edge, +// Handler::NodeData *referentData, bool first); +// +// The visitor function, called to report that we have traversed +// |edge| from |origin|. This is called once for each edge we traverse. +// As this is a breadth-first search, any prior calls to the visitor function +// were for origin nodes not further from the start nodes than |origin|. +// +// |traversal| is this traversal object, passed along for convenience. +// +// |referentData| is a pointer to the value of the entry in +// |traversal.visited| for |edge.referent|; the visitor function can +// store whatever metadata it likes about |edge.referent| there. +// +// |first| is true if this is the first time we have visited an edge +// leading to |edge.referent|. This could be stored in NodeData, but +// the algorithm knows whether it has just created the entry in +// |traversal.visited|, so it passes it along for convenience. +// +// The visitor function may call |traversal.stop()| if it doesn't want +// to visit any more nodes. +// +// The visitor function may consult |traversal.visited| for information +// about other nodes, but it should not add or remove entries. +// +// The visitor function should return true on success, or false if an +// error occurs. A false return value terminates the traversal +// immediately, and causes BreadthFirst::traverse to return +// false. +template +struct BreadthFirst { + + // Construct a breadth-first traversal object that reports the nodes it + // reaches to |handler|. The traversal object reports OOM on |cx|, and + // asserts that no GC happens in |cx|'s runtime during its lifetime. + // + // We do nothing with noGC, other than require it to exist, with a lifetime + // that encloses our own. + BreadthFirst(JSContext *cx, Handler &handler, const JS::AutoCheckCannotGC &noGC) + : cx(cx), visited(cx), handler(handler), pending(cx), + traversalBegun(false), stopRequested(false) + { } + + // Initialize this traversal object. Return false on OOM. + bool init() { return visited.init(); } + + // Add |node| as a starting point for the traversal. You may add + // as many starting points as you like. Return false on OOM. + bool addStart(Node node) { return pending.append(node); } + + // Traverse the graph in breadth-first order, starting at the given + // start nodes, applying |handler::operator()| for each edge traversed + // as described above. + // + // This should be called only once per instance of this class. + // + // Return false on OOM or error return from |handler::operator()|. + bool traverse() + { + MOZ_ASSERT(!traversalBegun); + traversalBegun = true; + + // While there are pending nodes, visit them, until we've found a path to the target. + while (!pending.empty()) { + Node origin = pending.front(); + pending.popFront(); + + // Get a range containing all origin's outgoing edges. + js::ScopedJSDeletePtr range(origin.edges(cx)); + if (!range) + return false; + + // Traverse each edge. + for (; !range->empty(); range->popFront()) { + MOZ_ASSERT(!stopRequested); + + const Edge &edge = range->front(); + typename NodeMap::AddPtr a = visited.lookupForAdd(edge.referent); + bool first = !a; + + if (first) { + // This is the first time we've reached |edge.referent|. + // Create an entry for it in |visited|, and arrange to + // traverse its outgoing edges later. + if (!visited.add(a, edge.referent, typename Handler::NodeData()) || + !pending.append(edge.referent)) { + return false; + } + } + + MOZ_ASSERT(a); + + // Report this edge to the visitor function. + if (!handler(*this, origin, edge, &a->value(), first)) + return false; + + if (stopRequested) + return true; + } + } + + return true; + } + + // Stop traversal, and return true from |traverse| without visiting any + // more nodes. Only |handler::operator()| should call this function; it + // may do so to stop the traversal early, without returning false and + // then making |traverse|'s caller disambiguate that result from a real + // error. + void stop() { stopRequested = true; } + + // The context with which we were constructed. + JSContext *cx; + + // A map associating each node N that we have reached with a + // Handler::NodeData, for |handler|'s use. This is public, so that + // |handler| can access it to see the traversal thus far. + typedef js::HashMap NodeMap; + NodeMap visited; + + private: + // Our handler object. + Handler &handler; + + // A queue template. Appending and popping the front are constant time. + // Wasted space is never more than some recent actual population plus the + // current population. + template + class Queue { + js::Vector head, tail; + size_t frontIndex; + public: + Queue(JSContext *cx) : head(cx), tail(cx), frontIndex(0) { } + bool empty() { return frontIndex >= head.length(); } + T &front() { + MOZ_ASSERT(!empty()); + return head[frontIndex]; + } + void popFront() { + MOZ_ASSERT(!empty()); + frontIndex++; + if (frontIndex >= head.length()) { + head.clearAndFree(); + head.swap(tail); + frontIndex = 0; + } + } + bool append(const T &elt) { + return frontIndex == 0 ? head.append(elt) : tail.append(elt); + } + }; + + // A queue of nodes that we have reached, but whose outgoing edges we + // have not yet traversed. Nodes reachable in fewer edges are enqueued + // earlier. + Queue pending; + + // True if our traverse function has been called. + bool traversalBegun; + + // True if we've been asked to stop the traversal. + bool stopRequested; +}; + +} // namespace ubi +} // namespace JS + +#endif // js_UbiNodeTraverse.h diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/Utility.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/Utility.h index adee3b15d8..89c495e411 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/Utility.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/Utility.h @@ -35,23 +35,22 @@ namespace mozilla {} namespace js {} /* - * Pattern used to overwrite freed memory. If you are accessing an object with - * this pattern, you probably have a dangling pointer. + * Patterns used by SpiderMonkey to overwrite unused memory. If you are + * accessing an object with one of these pattern, you probably have a dangling + * pointer. */ -#define JS_FREE_PATTERN 0xDA +#define JS_FRESH_NURSERY_PATTERN 0x2F +#define JS_SWEPT_NURSERY_PATTERN 0x2B +#define JS_ALLOCATED_NURSERY_PATTERN 0x2D +#define JS_FRESH_TENURED_PATTERN 0x4F +#define JS_SWEPT_TENURED_PATTERN 0x4B +#define JS_ALLOCATED_TENURED_PATTERN 0x4D +#define JS_SWEPT_CODE_PATTERN 0x3b +#define JS_SWEPT_FRAME_PATTERN 0x5b +#define JS_POISONED_FORKJOIN_CHUNK 0xBD #define JS_ASSERT(expr) MOZ_ASSERT(expr) #define JS_ASSERT_IF(cond, expr) MOZ_ASSERT_IF(cond, expr) -#define JS_ALWAYS_TRUE(expr) MOZ_ALWAYS_TRUE(expr) -#define JS_ALWAYS_FALSE(expr) MOZ_ALWAYS_FALSE(expr) - -#if defined(DEBUG) -# define JS_DIAGNOSTICS_ASSERT(expr) MOZ_ASSERT(expr) -#elif defined(JS_CRASH_DIAGNOSTICS) -# define JS_DIAGNOSTICS_ASSERT(expr) do { if (!(expr)) MOZ_CRASH(); } while(0) -#else -# define JS_DIAGNOSTICS_ASSERT(expr) ((void) 0) -#endif #define JS_STATIC_ASSERT(cond) static_assert(cond, "JS_STATIC_ASSERT") #define JS_STATIC_ASSERT_IF(cond, expr) MOZ_STATIC_ASSERT_IF(cond, expr, "JS_STATIC_ASSERT_IF") @@ -59,84 +58,40 @@ namespace js {} extern MOZ_NORETURN JS_PUBLIC_API(void) JS_Assert(const char *s, const char *file, int ln); -/* - * Abort the process in a non-graceful manner. This will cause a core file, - * call to the debugger or other moral equivalent as well as causing the - * entire process to stop. - */ -extern JS_PUBLIC_API(void) JS_Abort(void); - /* * Custom allocator support for SpiderMonkey */ #if defined JS_USE_CUSTOM_ALLOCATOR # include "jscustomallocator.h" #else -# ifdef DEBUG +# if defined(DEBUG) || defined(JS_OOM_BREAKPOINT) /* * In order to test OOM conditions, when the testing function * oomAfterAllocations COUNT is passed, we fail continuously after the NUM'th * allocation from now. */ -extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtins/TestingFunctions.cpp */ +extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtin/TestingFunctions.cpp */ extern JS_PUBLIC_DATA(uint32_t) OOM_counter; /* data race, who cares. */ -#ifdef JS_OOM_DO_BACKTRACES -#define JS_OOM_BACKTRACE_SIZE 32 -static JS_ALWAYS_INLINE void -PrintBacktrace() -{ - void* OOM_trace[JS_OOM_BACKTRACE_SIZE]; - char** OOM_traceSymbols = nullptr; - int32_t OOM_traceSize = 0; - int32_t OOM_traceIdx = 0; - OOM_traceSize = backtrace(OOM_trace, JS_OOM_BACKTRACE_SIZE); - OOM_traceSymbols = backtrace_symbols(OOM_trace, OOM_traceSize); - - if (!OOM_traceSymbols) - return; - - for (OOM_traceIdx = 0; OOM_traceIdx < OOM_traceSize; ++OOM_traceIdx) { - fprintf(stderr, "#%d %s\n", OOM_traceIdx, OOM_traceSymbols[OOM_traceIdx]); - } - - // This must be free(), not js_free(), because backtrace_symbols() - // allocates with malloc(). - free(OOM_traceSymbols); -} - -#define JS_OOM_EMIT_BACKTRACE() \ - do {\ - fprintf(stderr, "Forcing artificial memory allocation function failure:\n");\ - PrintBacktrace();\ - } while (0) -# else -# define JS_OOM_EMIT_BACKTRACE() do {} while(0) -#endif /* JS_OOM_DO_BACKTRACES */ +#ifdef JS_OOM_BREAKPOINT +static MOZ_NEVER_INLINE void js_failedAllocBreakpoint() { asm(""); } +#define JS_OOM_CALL_BP_FUNC() js_failedAllocBreakpoint() +#else +#define JS_OOM_CALL_BP_FUNC() do {} while(0) +#endif # define JS_OOM_POSSIBLY_FAIL() \ do \ { \ if (++OOM_counter > OOM_maxAllocations) { \ - JS_OOM_EMIT_BACKTRACE();\ - return nullptr; \ - } \ - } while (0) - -# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) \ - do \ - { \ - if (++OOM_counter > OOM_maxAllocations) { \ - JS_OOM_EMIT_BACKTRACE();\ - js_ReportOutOfMemory(cx);\ + JS_OOM_CALL_BP_FUNC();\ return nullptr; \ } \ } while (0) # else # define JS_OOM_POSSIBLY_FAIL() do {} while(0) -# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) do {} while(0) -# endif /* DEBUG */ +# endif /* DEBUG || JS_OOM_BREAKPOINT */ static inline void* js_malloc(size_t bytes) { @@ -168,26 +123,6 @@ static inline void js_free(void* p) } #endif/* JS_USE_CUSTOM_ALLOCATOR */ -/* - * JS_ROTATE_LEFT32 - * - * There is no rotate operation in the C Language so the construct (a << 4) | - * (a >> 28) is used instead. Most compilers convert this to a rotate - * instruction but some versions of MSVC don't without a little help. To get - * MSVC to generate a rotate instruction, we have to use the _rotl intrinsic - * and use a pragma to make _rotl inline. - * - * MSVC in VS2005 will do an inline rotate instruction on the above construct. - */ -#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || \ - defined(_M_X64)) -#include -#pragma intrinsic(_rotl) -#define JS_ROTATE_LEFT32(a, bits) _rotl(a, bits) -#else -#define JS_ROTATE_LEFT32(a, bits) (((a) << (bits)) | ((a) >> (32 - (bits)))) -#endif - #include /* @@ -235,6 +170,9 @@ static inline void js_free(void* p) #define JS_NEW_BODY(allocator, t, parms) \ void *memory = allocator(sizeof(t)); \ return memory ? new(memory) t parms : nullptr; +#define JS_MAKE_BODY(newname, T, parms) \ + T *ptr = newname parms; \ + return mozilla::UniquePtr>(ptr); /* * Given a class which should provide 'new' methods, add @@ -389,10 +327,191 @@ static inline void js_free(void* p) mozilla::Forward(p12)))\ }\ -JS_DECLARE_NEW_METHODS(js_new, js_malloc, static JS_ALWAYS_INLINE) +/* + * Given a class which should provide 'make' methods, add + * JS_DECLARE_MAKE_METHODS (see JSContext for a usage example). This method + * is functionally the same as JS_DECLARE_NEW_METHODS: it just declares methods + * that return mozilla::UniquePtr instances that will singly-manage ownership + * of the created object. This adds makes with up to 12 parameters. Add more + * versions below if you need more than 12 parameters. + * + * Note: Do not add a ; at the end of a use of JS_DECLARE_MAKE_METHODS, + * or the build will break. + */ +#define JS_DECLARE_MAKE_METHODS(MAKENAME, NEWNAME, QUALIFIERS)\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME() MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T, ())\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1)))\ + }\ +\ + template \ + QUALIFIERS \ +mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11, P12 &&p12) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11),\ + mozilla::Forward(p12)))\ + }\ + +JS_DECLARE_NEW_METHODS(js_new, js_malloc, static MOZ_ALWAYS_INLINE) template -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void js_delete(T *p) { if (p) { @@ -402,7 +521,7 @@ js_delete(T *p) } template -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void js_delete_poison(T *p) { if (p) { @@ -413,21 +532,21 @@ js_delete_poison(T *p) } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_malloc() { return (T *)js_malloc(sizeof(T)); } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_calloc() { return (T *)js_calloc(sizeof(T)); } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_malloc(size_t numElems) { if (numElems & mozilla::tl::MulOverflowMask::value) @@ -436,7 +555,7 @@ js_pod_malloc(size_t numElems) } template -static JS_ALWAYS_INLINE T * +static MOZ_ALWAYS_INLINE T * js_pod_calloc(size_t numElems) { if (numElems & mozilla::tl::MulOverflowMask::value) @@ -471,6 +590,25 @@ SCOPED_TEMPLATE(ScopedReleasePtr, ScopedReleasePtrTraits) } /* namespace js */ +namespace JS { + +template +struct DeletePolicy +{ + void operator()(T* ptr) { + js_delete(ptr); + } +}; + +struct FreePolicy +{ + void operator()(void* ptr) { + js_free(ptr); + } +}; + +} // namespace JS + namespace js { /* Integral types for all hash functions. */ @@ -535,7 +673,7 @@ namespace JS { inline void PoisonPtr(void *v) { -#if defined(JSGC_ROOT_ANALYSIS) && defined(DEBUG) +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) uint8_t *ptr = (uint8_t *) v + 3; *ptr = JS_FREE_PATTERN; #endif @@ -544,7 +682,7 @@ inline void PoisonPtr(void *v) template inline bool IsPoisonedPtr(T *v) { -#if defined(JSGC_ROOT_ANALYSIS) && defined(DEBUG) +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) uint32_t mask = uintptr_t(v) & 0xff000000; return mask == uint32_t(JS_FREE_PATTERN << 24); #else diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/Value.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/Value.h index ee4f3a64d3..0ec3934cc8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/Value.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/Value.h @@ -15,9 +15,11 @@ #include /* for std::numeric_limits */ +#include "js-config.h" #include "jstypes.h" #include "js/Anchor.h" +#include "js/GCAPI.h" #include "js/RootingAPI.h" #include "js/Utility.h" @@ -46,7 +48,7 @@ namespace JS { class Value; } # define JSVAL_ALIGNMENT #endif -#if JS_BITS_PER_WORD == 64 +#if defined(JS_PUNBOX64) # define JSVAL_TAG_SHIFT 47 #endif @@ -74,8 +76,9 @@ JS_ENUM_HEADER(JSValueType, uint8_t) JSVAL_TYPE_BOOLEAN = 0x03, JSVAL_TYPE_MAGIC = 0x04, JSVAL_TYPE_STRING = 0x05, - JSVAL_TYPE_NULL = 0x06, - JSVAL_TYPE_OBJECT = 0x07, + JSVAL_TYPE_SYMBOL = 0x06, + JSVAL_TYPE_NULL = 0x07, + JSVAL_TYPE_OBJECT = 0x08, /* These never appear in a jsval; they are only provided as an out-of-band value. */ JSVAL_TYPE_UNKNOWN = 0x20, @@ -84,7 +87,7 @@ JS_ENUM_HEADER(JSValueType, uint8_t) JS_STATIC_ASSERT(sizeof(JSValueType) == 1); -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) /* Remember to propagate changes to the C defines below. */ JS_ENUM_HEADER(JSValueTag, uint32_t) @@ -93,6 +96,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JSVAL_TAG_INT32 = JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32, JSVAL_TAG_UNDEFINED = JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED, JSVAL_TAG_STRING = JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL, JSVAL_TAG_BOOLEAN = JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN, JSVAL_TAG_MAGIC = JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC, JSVAL_TAG_NULL = JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL, @@ -101,7 +105,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JS_STATIC_ASSERT(sizeof(JSValueTag) == 4); -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) /* Remember to propagate changes to the C defines below. */ JS_ENUM_HEADER(JSValueTag, uint32_t) @@ -110,6 +114,7 @@ JS_ENUM_HEADER(JSValueTag, uint32_t) JSVAL_TAG_INT32 = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32, JSVAL_TAG_UNDEFINED = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED, JSVAL_TAG_STRING = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL, JSVAL_TAG_BOOLEAN = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN, JSVAL_TAG_MAGIC = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC, JSVAL_TAG_NULL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL, @@ -124,6 +129,7 @@ JS_ENUM_HEADER(JSValueShiftedTag, uint64_t) JSVAL_SHIFTED_TAG_INT32 = (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_UNDEFINED = (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_STRING = (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_SYMBOL = (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_BOOLEAN = (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_MAGIC = (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT), JSVAL_SHIFTED_TAG_NULL = (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT), @@ -143,29 +149,32 @@ typedef uint8_t JSValueType; #define JSVAL_TYPE_BOOLEAN ((uint8_t)0x03) #define JSVAL_TYPE_MAGIC ((uint8_t)0x04) #define JSVAL_TYPE_STRING ((uint8_t)0x05) -#define JSVAL_TYPE_NULL ((uint8_t)0x06) -#define JSVAL_TYPE_OBJECT ((uint8_t)0x07) +#define JSVAL_TYPE_SYMBOL ((uint8_t)0x06) +#define JSVAL_TYPE_NULL ((uint8_t)0x07) +#define JSVAL_TYPE_OBJECT ((uint8_t)0x08) #define JSVAL_TYPE_UNKNOWN ((uint8_t)0x20) -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) typedef uint32_t JSValueTag; #define JSVAL_TAG_CLEAR ((uint32_t)(0xFFFFFF80)) #define JSVAL_TAG_INT32 ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32)) #define JSVAL_TAG_UNDEFINED ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED)) #define JSVAL_TAG_STRING ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING)) +#define JSVAL_TAG_SYMBOL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL)) #define JSVAL_TAG_BOOLEAN ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN)) #define JSVAL_TAG_MAGIC ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC)) #define JSVAL_TAG_NULL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL)) #define JSVAL_TAG_OBJECT ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT)) -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) typedef uint32_t JSValueTag; #define JSVAL_TAG_MAX_DOUBLE ((uint32_t)(0x1FFF0)) #define JSVAL_TAG_INT32 (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32) #define JSVAL_TAG_UNDEFINED (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED) #define JSVAL_TAG_STRING (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING) +#define JSVAL_TAG_SYMBOL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL) #define JSVAL_TAG_BOOLEAN (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN) #define JSVAL_TAG_MAGIC (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC) #define JSVAL_TAG_NULL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL) @@ -176,20 +185,16 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_SHIFTED_TAG_INT32 (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_UNDEFINED (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_STRING (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_SYMBOL (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_BOOLEAN (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_MAGIC (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_NULL (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT) #define JSVAL_SHIFTED_TAG_OBJECT (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT) -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ #endif /* !defined(__SUNPRO_CC) && !defined(__xlC__) */ -#define JSVAL_LOWER_INCL_TYPE_OF_OBJ_OR_NULL_SET JSVAL_TYPE_NULL -#define JSVAL_UPPER_EXCL_TYPE_OF_PRIMITIVE_SET JSVAL_TYPE_OBJECT -#define JSVAL_UPPER_INCL_TYPE_OF_NUMBER_SET JSVAL_TYPE_INT32 -#define JSVAL_LOWER_INCL_TYPE_OF_PTR_PAYLOAD_SET JSVAL_TYPE_MAGIC - -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) #define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_CLEAR | (type))) @@ -198,7 +203,7 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32 #define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) #define JSVAL_PAYLOAD_MASK 0x00007FFFFFFFFFFFLL #define JSVAL_TAG_MASK 0xFFFF800000000000LL @@ -215,7 +220,7 @@ typedef uint64_t JSValueShiftedTag; #define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET JSVAL_SHIFTED_TAG_UNDEFINED #define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET JSVAL_SHIFTED_TAG_STRING -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ typedef enum JSWhyMagic { @@ -233,16 +238,16 @@ typedef enum JSWhyMagic JS_OPTIMIZED_ARGUMENTS, /* optimized-away 'arguments' value */ JS_IS_CONSTRUCTING, /* magic value passed to natives to indicate construction */ JS_OVERWRITTEN_CALLEE, /* arguments.callee has been overwritten */ - JS_FORWARD_TO_CALL_OBJECT, /* args object element stored in call object */ JS_BLOCK_NEEDS_CLONE, /* value of static block object slot */ JS_HASH_KEY_EMPTY, /* see class js::HashableValue */ JS_ION_ERROR, /* error while running Ion code */ - JS_ION_BAILOUT, /* status code to signal EnterIon will OSR into Interpret */ + JS_ION_BAILOUT, /* missing recover instruction result */ + JS_OPTIMIZED_OUT, /* optimized out slot */ JS_GENERIC_MAGIC /* for local use */ } JSWhyMagic; #if defined(IS_LITTLE_ENDIAN) -# if JS_BITS_PER_WORD == 32 +# if defined(JS_NUNBOX32) typedef union jsval_layout { uint64_t asBits; @@ -252,7 +257,9 @@ typedef union jsval_layout uint32_t u32; uint32_t boo; // Don't use |bool| -- it must be four bytes. JSString *str; + JS::Symbol *sym; JSObject *obj; + js::gc::Cell *cell; void *ptr; JSWhyMagic why; size_t word; @@ -263,7 +270,7 @@ typedef union jsval_layout double asDouble; void *asPtr; } JSVAL_ALIGNMENT jsval_layout; -# elif JS_BITS_PER_WORD == 64 +# elif defined(JS_PUNBOX64) typedef union jsval_layout { uint64_t asBits; @@ -286,9 +293,9 @@ typedef union jsval_layout size_t asWord; uintptr_t asUIntPtr; } JSVAL_ALIGNMENT jsval_layout; -# endif /* JS_BITS_PER_WORD */ +# endif /* JS_PUNBOX64 */ #else /* defined(IS_LITTLE_ENDIAN) */ -# if JS_BITS_PER_WORD == 32 +# if defined(JS_NUNBOX32) typedef union jsval_layout { uint64_t asBits; @@ -299,7 +306,9 @@ typedef union jsval_layout uint32_t u32; uint32_t boo; // Don't use |bool| -- it must be four bytes. JSString *str; + JS::Symbol *sym; JSObject *obj; + js::gc::Cell *cell; void *ptr; JSWhyMagic why; size_t word; @@ -309,7 +318,7 @@ typedef union jsval_layout double asDouble; void *asPtr; } JSVAL_ALIGNMENT jsval_layout; -# elif JS_BITS_PER_WORD == 64 +# elif defined(JS_PUNBOX64) typedef union jsval_layout { uint64_t asBits; @@ -330,7 +339,7 @@ typedef union jsval_layout size_t asWord; uintptr_t asUIntPtr; } JSVAL_ALIGNMENT jsval_layout; -# endif /* JS_BITS_PER_WORD */ +# endif /* JS_PUNBOX64 */ #endif /* defined(IS_LITTLE_ENDIAN) */ JS_STATIC_ASSERT(sizeof(jsval_layout) == 8); @@ -378,7 +387,7 @@ JS_STATIC_ASSERT(sizeof(jsval_layout) == 8); # define JS_VALUE_CONSTEXPR_VAR const #endif -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) /* * N.B. GCC, in some but not all cases, chooses to emit signed comparison of @@ -456,7 +465,7 @@ static inline jsval_layout STRING_TO_JSVAL_IMPL(JSString *str) { jsval_layout l; - MOZ_ASSERT(str); + MOZ_ASSERT(uintptr_t(str) > 0x1000); l.s.tag = JSVAL_TAG_STRING; l.s.payload.str = str; return l; @@ -468,6 +477,28 @@ JSVAL_TO_STRING_IMPL(jsval_layout l) return l.s.payload.str; } +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + l.s.tag = JSVAL_TAG_SYMBOL; + l.s.payload.sym = sym; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.payload.sym; +} + static inline bool JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) { @@ -524,7 +555,7 @@ static inline jsval_layout OBJECT_TO_JSVAL_IMPL(JSObject *obj) { jsval_layout l; - MOZ_ASSERT(obj); + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); l.s.tag = JSVAL_TAG_OBJECT; l.s.payload.obj = obj; return l; @@ -560,22 +591,22 @@ JSVAL_IS_GCTHING_IMPL(jsval_layout l) return (uint32_t)l.s.tag >= (uint32_t)JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET; } -static inline void * +static inline js::gc::Cell * JSVAL_TO_GCTHING_IMPL(jsval_layout l) { - return l.s.payload.ptr; -} - -static inline bool -JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) -{ - return l.s.tag == JSVAL_TAG_STRING || l.s.tag == JSVAL_TAG_OBJECT; + return l.s.payload.cell; } static inline uint32_t JSVAL_TRACE_KIND_IMPL(jsval_layout l) { - return (uint32_t)(bool)JSVAL_IS_STRING_IMPL(l); + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return l.s.tag & 0x03; } static inline bool @@ -585,7 +616,7 @@ JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) } static inline bool -JSVAL_IS_SPECIFIC_BOOLEAN(jsval_layout l, bool b) +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) { return (l.s.tag == JSVAL_TAG_BOOLEAN) && (l.s.payload.boo == uint32_t(b)); } @@ -599,6 +630,15 @@ MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) return l; } +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.s.tag = JSVAL_TAG_MAGIC; + l.s.payload.u32 = payload; + return l; +} + static inline bool JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) { @@ -614,7 +654,7 @@ JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) return (JSValueType)type; } -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) static inline JS_VALUE_CONSTEXPR jsval_layout BUILD_JSVAL(JSValueTag tag, uint64_t payload) @@ -678,7 +718,7 @@ STRING_TO_JSVAL_IMPL(JSString *str) { jsval_layout l; uint64_t strBits = (uint64_t)str; - MOZ_ASSERT(str); + MOZ_ASSERT(uintptr_t(str) > 0x1000); MOZ_ASSERT((strBits >> JSVAL_TAG_SHIFT) == 0); l.asBits = strBits | JSVAL_SHIFTED_TAG_STRING; return l; @@ -690,6 +730,29 @@ JSVAL_TO_STRING_IMPL(jsval_layout l) return (JSString *)(l.asBits & JSVAL_PAYLOAD_MASK); } +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + uint64_t symBits = (uint64_t)sym; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + MOZ_ASSERT((symBits >> JSVAL_TAG_SHIFT) == 0); + l.asBits = symBits | JSVAL_SHIFTED_TAG_SYMBOL; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return (JS::Symbol *)(l.asBits & JSVAL_PAYLOAD_MASK); +} + static inline bool JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) { @@ -725,7 +788,7 @@ JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l) static inline bool JSVAL_IS_OBJECT_IMPL(jsval_layout l) { - MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_SHIFTED_TAG_OBJECT); + MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_TAG_OBJECT); return l.asBits >= JSVAL_SHIFTED_TAG_OBJECT; } @@ -749,7 +812,7 @@ OBJECT_TO_JSVAL_IMPL(JSObject *obj) { jsval_layout l; uint64_t objBits = (uint64_t)obj; - MOZ_ASSERT(obj); + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); MOZ_ASSERT((objBits >> JSVAL_TAG_SHIFT) == 0); l.asBits = objBits | JSVAL_SHIFTED_TAG_OBJECT; return l; @@ -767,24 +830,24 @@ JSVAL_IS_GCTHING_IMPL(jsval_layout l) return l.asBits >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET; } -static inline void * +static inline js::gc::Cell * JSVAL_TO_GCTHING_IMPL(jsval_layout l) { uint64_t ptrBits = l.asBits & JSVAL_PAYLOAD_MASK; MOZ_ASSERT((ptrBits & 0x7) == 0); - return (void *)ptrBits; -} - -static inline bool -JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) -{ - return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l); + return reinterpret_cast(ptrBits); } static inline uint32_t JSVAL_TRACE_KIND_IMPL(jsval_layout l) { - return (uint32_t)(bool)!(JSVAL_IS_OBJECT_IMPL(l)); + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) & 0x03; } static inline jsval_layout @@ -812,7 +875,7 @@ JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) } static inline bool -JSVAL_IS_SPECIFIC_BOOLEAN(jsval_layout l, bool b) +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) { return l.asBits == (((uint64_t)(uint32_t)b) | JSVAL_SHIFTED_TAG_BOOLEAN); } @@ -825,6 +888,14 @@ MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) return l; } +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.asBits = ((uint64_t)payload) | JSVAL_SHIFTED_TAG_MAGIC; + return l; +} + static inline bool JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) { @@ -841,7 +912,13 @@ JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) return (JSValueType)type; } -#endif /* JS_BITS_PER_WORD */ +#endif /* JS_PUNBOX64 */ + +static inline bool +JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) +{ + return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l); +} static inline jsval_layout JSVAL_TO_IMPL(JS::Value v); static inline JS_VALUE_CONSTEXPR JS::Value IMPL_TO_JSVAL(jsval_layout l); @@ -859,7 +936,7 @@ static inline JS_VALUE_CONSTEXPR JS::Value UndefinedValue(); static MOZ_ALWAYS_INLINE double GenericNaN() { - return mozilla::SpecificNaN(0, 0x8000000000000ULL); + return mozilla::SpecificNaN(0, 0x8000000000000ULL); } /* MSVC with PGO miscompiles this function. */ @@ -883,27 +960,23 @@ CanonicalizeNaN(double d) * * - JS::Value has setX() and isX() members for X in * - * { Int32, Double, String, Boolean, Undefined, Null, Object, Magic } + * { Int32, Double, String, Symbol, Boolean, Undefined, Null, Object, Magic } * * JS::Value also contains toX() for each of the non-singleton types. * - * - Magic is a singleton type whose payload contains a JSWhyMagic "reason" for - * the magic value. By providing JSWhyMagic values when creating and checking - * for magic values, it is possible to assert, at runtime, that only magic - * values with the expected reason flow through a particular value. For - * example, if cx->exception has a magic value, the reason must be - * JS_GENERATOR_CLOSING. + * - Magic is a singleton type whose payload contains either a JSWhyMagic "reason" for + * the magic value or a uint32_t value. By providing JSWhyMagic values when + * creating and checking for magic values, it is possible to assert, at + * runtime, that only magic values with the expected reason flow through a + * particular value. For example, if cx->exception has a magic value, the + * reason must be JS_GENERATOR_CLOSING. * * - The JS::Value operations are preferred. The JSVAL_* operations remain for * compatibility; they may be removed at some point. These operations mostly * provide similar functionality. But there are a few key differences. One - * is that JS::Value gives null a separate type. Thus - * - * JSVAL_IS_OBJECT(v) === v.isObjectOrNull() - * !JSVAL_IS_PRIMITIVE(v) === v.isObject() - * + * is that JS::Value gives null a separate type. * Also, to help prevent mistakenly boxing a nullable JSObject* as an object, - * Value::setObject takes a JSObject&. (Conversely, Value::asObject returns a + * Value::setObject takes a JSObject&. (Conversely, Value::toObject returns a * JSObject&.) A convenience member Value::setObjectOrNull is provided. * * - JSVAL_VOID is the same as the singleton value of the Undefined type. @@ -961,6 +1034,11 @@ class Value data = STRING_TO_JSVAL_IMPL(str); } + void setSymbol(JS::Symbol *sym) { + MOZ_ASSERT(!IsPoisonedPtr(sym)); + data = SYMBOL_TO_JSVAL_IMPL(sym); + } + void setObject(JSObject &obj) { MOZ_ASSERT(!IsPoisonedPtr(&obj)); data = OBJECT_TO_JSVAL_IMPL(&obj); @@ -974,6 +1052,10 @@ class Value data = MAGIC_TO_JSVAL_IMPL(why); } + void setMagicUint32(uint32_t payload) { + data = MAGIC_UINT32_TO_JSVAL_IMPL(payload); + } + bool setNumber(uint32_t ui) { if (ui > JSVAL_INT_MAX) { setDouble((double)ui); @@ -986,7 +1068,7 @@ class Value bool setNumber(double d) { int32_t i; - if (mozilla::DoubleIsInt32(d, &i)) { + if (mozilla::NumberIsInt32(d, &i)) { setInt32(i); return true; } @@ -1042,6 +1124,10 @@ class Value return JSVAL_IS_STRING_IMPL(data); } + bool isSymbol() const { + return JSVAL_IS_SYMBOL_IMPL(data); + } + bool isObject() const { return JSVAL_IS_OBJECT_IMPL(data); } @@ -1063,11 +1149,11 @@ class Value } bool isTrue() const { - return JSVAL_IS_SPECIFIC_BOOLEAN(data, true); + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, true); } bool isFalse() const { - return JSVAL_IS_SPECIFIC_BOOLEAN(data, false); + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, false); } bool isMagic() const { @@ -1093,6 +1179,11 @@ class Value return data.s.payload.why; } + uint32_t magicUint32() const { + MOZ_ASSERT(isMagic()); + return data.s.payload.u32; + } + /*** Comparison ***/ bool operator==(const Value &rhs) const { @@ -1127,6 +1218,11 @@ class Value return JSVAL_TO_STRING_IMPL(data); } + JS::Symbol *toSymbol() const { + MOZ_ASSERT(isSymbol()); + return JSVAL_TO_SYMBOL_IMPL(data); + } + JSObject &toObject() const { MOZ_ASSERT(isObject()); return *JSVAL_TO_OBJECT_IMPL(data); @@ -1137,7 +1233,7 @@ class Value return JSVAL_TO_OBJECT_IMPL(data); } - void *toGCThing() const { + js::gc::Cell *toGCThing() const { MOZ_ASSERT(isGCThing()); return JSVAL_TO_GCTHING_IMPL(data); } @@ -1202,17 +1298,17 @@ class Value } const size_t *payloadWord() const { -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) return &data.s.payload.word; -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) return &data.asWord; #endif } const uintptr_t *payloadUIntPtr() const { -#if JS_BITS_PER_WORD == 32 +#if defined(JS_NUNBOX32) return &data.s.payload.uintptr; -#elif JS_BITS_PER_WORD == 64 +#elif defined(JS_PUNBOX64) return &data.asUIntPtr; #endif } @@ -1228,7 +1324,7 @@ class Value private: #if defined(JS_VALUE_IS_CONSTEXPR) - JS_VALUE_CONSTEXPR Value(jsval_layout layout) : data(layout) {} + MOZ_IMPLICIT JS_VALUE_CONSTEXPR Value(jsval_layout layout) : data(layout) {} #endif void staticAssertions() { @@ -1238,7 +1334,10 @@ class Value JS_STATIC_ASSERT(sizeof(Value) == 8); } - friend jsval_layout (::JSVAL_TO_IMPL)(Value); + //this may result in error of "JSVAL_TO_IMPL is not a function" on Visual Studio + //so we remove it , data is a public member on windows + //more detail: https://bugzilla.mozilla.org/show_bug.cgi?id=1082033 + //friend jsval_layout (::JSVAL_TO_IMPL)(Value); friend Value JS_VALUE_CONSTEXPR (::IMPL_TO_JSVAL)(jsval_layout l); friend Value JS_VALUE_CONSTEXPR (JS::UndefinedValue)(); }; @@ -1248,11 +1347,30 @@ IsPoisonedValue(const Value &v) { if (v.isString()) return IsPoisonedPtr(v.toString()); + if (v.isSymbol()) + return IsPoisonedPtr(v.toSymbol()); if (v.isObject()) return IsPoisonedPtr(&v.toObject()); return false; } +inline bool +IsOptimizedPlaceholderMagicValue(const Value &v) +{ + if (v.isMagic()) { + MOZ_ASSERT(v.whyMagic() == JS_OPTIMIZED_ARGUMENTS || v.whyMagic() == JS_OPTIMIZED_OUT); + return true; + } + return false; +} + +static MOZ_ALWAYS_INLINE void +ExposeValueToActiveJS(const Value &v) +{ + if (v.isMarkable()) + ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); +} + /************************************************************************/ static inline Value @@ -1315,6 +1433,14 @@ StringValue(JSString *str) return v; } +static inline Value +SymbolValue(JS::Symbol *sym) +{ + Value v; + v.setSymbol(sym); + return v; +} + static inline Value BooleanValue(bool boo) { @@ -1363,6 +1489,14 @@ MagicValue(JSWhyMagic why) return v; } +static inline Value +MagicValueUint32(uint32_t payload) +{ + Value v; + v.setMagicUint32(payload); + return v; +} + static inline Value NumberValue(float f) { @@ -1507,16 +1641,16 @@ namespace js { template <> struct GCMethods { static JS::Value initial() { return JS::UndefinedValue(); } - static ThingRootKind kind() { return THING_ROOT_VALUE; } static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } }; template <> struct GCMethods { static JS::Value initial() { return JS::UndefinedValue(); } - static ThingRootKind kind() { return THING_ROOT_VALUE; } static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } - static bool needsPostBarrier(const JS::Value &v) { return v.isMarkable(); } + static bool needsPostBarrier(const JS::Value &v) { + return v.isObject() && gc::IsInsideNursery(reinterpret_cast(&v.toObject())); + } #ifdef JSGC_GENERATIONAL static void postBarrier(JS::Value *v) { JS::HeapValuePostBarrier(v); } static void relocate(JS::Value *v) { JS::HeapValueRelocate(v); } @@ -1548,6 +1682,7 @@ class ValueOperations bool isInt32() const { return value()->isInt32(); } bool isDouble() const { return value()->isDouble(); } bool isString() const { return value()->isString(); } + bool isSymbol() const { return value()->isSymbol(); } bool isObject() const { return value()->isObject(); } bool isMagic() const { return value()->isMagic(); } bool isMagic(JSWhyMagic why) const { return value()->isMagic(why); } @@ -1563,14 +1698,17 @@ class ValueOperations int32_t toInt32() const { return value()->toInt32(); } double toDouble() const { return value()->toDouble(); } JSString *toString() const { return value()->toString(); } + JS::Symbol *toSymbol() const { return value()->toSymbol(); } JSObject &toObject() const { return value()->toObject(); } JSObject *toObjectOrNull() const { return value()->toObjectOrNull(); } void *toGCThing() const { return value()->toGCThing(); } + uint64_t asRawBits() const { return value()->asRawBits(); } JSValueType extractNonDoubleType() const { return value()->extractNonDoubleType(); } uint32_t toPrivateUint32() const { return value()->toPrivateUint32(); } JSWhyMagic whyMagic() const { return value()->whyMagic(); } + uint32_t magicUint32() const { return value()->magicUint32(); } }; /* @@ -1595,6 +1733,7 @@ class MutableValueOperations : public ValueOperations bool setNumber(uint32_t ui) { return value()->setNumber(ui); } bool setNumber(double d) { return value()->setNumber(d); } void setString(JSString *str) { this->value()->setString(str); } + void setSymbol(JS::Symbol *sym) { this->value()->setSymbol(sym); } void setObject(JSObject &obj) { this->value()->setObject(obj); } void setObjectOrNull(JSObject *arg) { this->value()->setObjectOrNull(arg); } }; @@ -1625,6 +1764,7 @@ class HeapBase : public ValueOperations > void setBoolean(bool b) { setBarriered(JS::BooleanValue(b)); } void setMagic(JSWhyMagic why) { setBarriered(JS::MagicValue(why)); } void setString(JSString *str) { setBarriered(JS::StringValue(str)); } + void setSymbol(JS::Symbol *sym) { setBarriered(JS::SymbolValue(sym)); } void setObject(JSObject &obj) { setBarriered(JS::ObjectValue(obj)); } bool setNumber(uint32_t ui) { @@ -1639,7 +1779,7 @@ class HeapBase : public ValueOperations > bool setNumber(double d) { int32_t i; - if (mozilla::DoubleIsInt32(d, &i)) { + if (mozilla::NumberIsInt32(d, &i)) { setInt32(i); return true; } @@ -1747,7 +1887,7 @@ inline Anchor::~Anchor() } #endif -#ifdef DEBUG +#ifdef JS_DEBUG namespace detail { struct ValueAlignmentTester { char c; JS::Value v; }; @@ -1759,7 +1899,7 @@ static_assert(sizeof(LayoutAlignmentTester) == 16, "jsval_layout must be 16-byte-aligned"); } // namespace detail -#endif /* DEBUG */ +#endif /* JS_DEBUG */ } // namespace JS @@ -1775,52 +1915,12 @@ static_assert(sizeof(jsval_layout) == sizeof(JS::Value), /************************************************************************/ -static inline bool -JSVAL_IS_NULL(jsval v) -{ - return JSVAL_IS_NULL_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_VOID(jsval v) -{ - return JSVAL_IS_UNDEFINED_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_INT(jsval v) -{ - return JSVAL_IS_INT32_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline int32_t -JSVAL_TO_INT(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_INT(v)); - return JSVAL_TO_INT32_IMPL(JSVAL_TO_IMPL(v)); -} - static inline JS_VALUE_CONSTEXPR jsval INT_TO_JSVAL(int32_t i) { return IMPL_TO_JSVAL(INT32_TO_JSVAL_IMPL(i)); } -static inline bool -JSVAL_IS_DOUBLE(jsval v) -{ - return JSVAL_IS_DOUBLE_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline double -JSVAL_TO_DOUBLE(jsval v) -{ - jsval_layout l; - MOZ_ASSERT(JSVAL_IS_DOUBLE(v)); - l = JSVAL_TO_IMPL(v); - return l.asDouble; -} - static inline JS_VALUE_CONSTEXPR jsval DOUBLE_TO_JSVAL(double d) { @@ -1852,38 +1952,12 @@ UINT_TO_JSVAL(uint32_t i) : DOUBLE_TO_JSVAL((double)i)); } -static inline bool -JSVAL_IS_NUMBER(jsval v) -{ - return JSVAL_IS_NUMBER_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_STRING(jsval v) -{ - return JSVAL_IS_STRING_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline JSString * -JSVAL_TO_STRING(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_STRING(v)); - return JSVAL_TO_STRING_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval STRING_TO_JSVAL(JSString *str) { return IMPL_TO_JSVAL(STRING_TO_JSVAL_IMPL(str)); } -static inline JSObject * -JSVAL_TO_OBJECT(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_OBJECT_OR_NULL_IMPL(JSVAL_TO_IMPL(v))); - return JSVAL_TO_OBJECT_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval OBJECT_TO_JSVAL(JSObject *obj) { @@ -1892,44 +1966,12 @@ OBJECT_TO_JSVAL(JSObject *obj) return IMPL_TO_JSVAL(BUILD_JSVAL(JSVAL_TAG_NULL, 0)); } -static inline bool -JSVAL_IS_BOOLEAN(jsval v) -{ - return JSVAL_IS_BOOLEAN_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_TO_BOOLEAN(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_BOOLEAN(v)); - return JSVAL_TO_BOOLEAN_IMPL(JSVAL_TO_IMPL(v)); -} - static inline jsval BOOLEAN_TO_JSVAL(bool b) { return IMPL_TO_JSVAL(BOOLEAN_TO_JSVAL_IMPL(b)); } -static inline bool -JSVAL_IS_PRIMITIVE(jsval v) -{ - return JSVAL_IS_PRIMITIVE_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline bool -JSVAL_IS_GCTHING(jsval v) -{ - return JSVAL_IS_GCTHING_IMPL(JSVAL_TO_IMPL(v)); -} - -static inline void * -JSVAL_TO_GCTHING(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_GCTHING(v)); - return JSVAL_TO_GCTHING_IMPL(JSVAL_TO_IMPL(v)); -} - /* To be GC-safe, privates are tagged as doubles. */ static inline jsval @@ -1938,13 +1980,6 @@ PRIVATE_TO_JSVAL(void *ptr) return IMPL_TO_JSVAL(PRIVATE_PTR_TO_JSVAL_IMPL(ptr)); } -static inline void * -JSVAL_TO_PRIVATE(jsval v) -{ - MOZ_ASSERT(JSVAL_IS_DOUBLE(v)); - return JSVAL_TO_PRIVATE_PTR_IMPL(JSVAL_TO_IMPL(v)); -} - // JS constants. For efficiency, prefer predicates (e.g. v.isNull()) and // constructing values from scratch (e.g. Int32Value(0)). These constants are // stored in memory and initialized at startup, so testing against them and @@ -1958,8 +1993,10 @@ extern JS_PUBLIC_DATA(const jsval) JSVAL_VOID; namespace JS { -extern JS_PUBLIC_DATA(const Handle) NullHandleValue; -extern JS_PUBLIC_DATA(const Handle) UndefinedHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) NullHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) TrueHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) FalseHandleValue; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/Vector.h index e8aef1713d..a2d24b10ed 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/js/Vector.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/Vector.h @@ -54,7 +54,7 @@ class Vector typedef typename mozilla::VectorBase Base; public: - Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} Vector(Vector &&vec) : Base(mozilla::Move(vec)) {} Vector &operator=(Vector &&vec) { return Base::operator=(mozilla::Move(vec)); diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/js/WeakMapPtr.h b/frameworks/js-bindings/external/spidermonkey/include/win32/js/WeakMapPtr.h new file mode 100644 index 0000000000..f5822bef4b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/js/WeakMapPtr.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_WeakMapPtr_h +#define js_WeakMapPtr_h + +#include "jspubtd.h" + +#include "js/TypeDecls.h" + +namespace JS { + +// A wrapper around the internal C++ representation of SpiderMonkey WeakMaps, +// usable outside the engine. +// +// The supported template specializations are enumerated in WeakMapPtr.cpp. If +// you want to use this class for a different key/value combination, add it to +// the list and the compiler will generate the relevant machinery. +template +class JS_PUBLIC_API(WeakMapPtr) +{ + public: + WeakMapPtr() : ptr(nullptr) {}; + bool init(JSContext *cx); + bool initialized() { return ptr != nullptr; }; + void destroy(); + virtual ~WeakMapPtr() { MOZ_ASSERT(!initialized()); } + void trace(JSTracer *tracer); + + V lookup(const K &key); + bool put(JSContext *cx, const K &key, const V &value); + + static void keyMarkCallback(JSTracer *trc, K key, void *data); + + private: + void *ptr; + + // WeakMapPtr is neither copyable nor assignable. + WeakMapPtr(const WeakMapPtr &wmp) MOZ_DELETE; + WeakMapPtr &operator=(const WeakMapPtr &wmp) MOZ_DELETE; +}; + +} /* namespace JS */ + +#endif /* js_WeakMapPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/jsalloc.h b/frameworks/js-bindings/external/spidermonkey/include/win32/jsalloc.h index 03b6b569e1..a1e547cec9 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/jsalloc.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/jsalloc.h @@ -4,7 +4,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/* JS allocation policies. */ +/* + * JS allocation policies. + * + * The allocators here are for system memory with lifetimes which are not + * managed by the GC. See the comment at the top of vm/MallocProvider.h. + */ #ifndef jsalloc_h #define jsalloc_h @@ -14,7 +19,7 @@ namespace js { -class ContextFriendFields; +struct ContextFriendFields; /* Policy for using system memory functions and doing no error reporting. */ class SystemAllocPolicy @@ -47,26 +52,26 @@ class TempAllocPolicy JS_FRIEND_API(void *) onOutOfMemory(void *p, size_t nbytes); public: - TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( - TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} + MOZ_IMPLICIT TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( + MOZ_IMPLICIT TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} void *malloc_(size_t bytes) { void *p = js_malloc(bytes); - if (JS_UNLIKELY(!p)) + if (MOZ_UNLIKELY(!p)) p = onOutOfMemory(nullptr, bytes); return p; } void *calloc_(size_t bytes) { void *p = js_calloc(bytes); - if (JS_UNLIKELY(!p)) + if (MOZ_UNLIKELY(!p)) p = onOutOfMemory(nullptr, bytes); return p; } void *realloc_(void *p, size_t oldBytes, size_t bytes) { void *p2 = js_realloc(p, bytes); - if (JS_UNLIKELY(!p2)) + if (MOZ_UNLIKELY(!p2)) p2 = onOutOfMemory(p2, bytes); return p2; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/jsapi.h b/frameworks/js-bindings/external/spidermonkey/include/win32/jsapi.h index 6d47488a33..4b5a4ce1ff 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/jsapi.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/jsapi.h @@ -9,10 +9,11 @@ #ifndef jsapi_h #define jsapi_h -#include "mozilla/Atomics.h" #include "mozilla/FloatingPoint.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/Range.h" #include "mozilla/RangedPtr.h" +#include "mozilla/TypedEnum.h" #include #include @@ -26,40 +27,28 @@ #include "js/Class.h" #include "js/HashTable.h" #include "js/Id.h" +#include "js/Principals.h" #include "js/RootingAPI.h" +#include "js/TracingAPI.h" #include "js/Utility.h" #include "js/Value.h" #include "js/Vector.h" /************************************************************************/ -struct JSTracer; - namespace JS { class Latin1CharsZ; class TwoByteChars; -typedef mozilla::RangedPtr CharPtr; - -class StableCharPtr : public CharPtr { - public: - StableCharPtr(const StableCharPtr &s) : CharPtr(s) {} - StableCharPtr(const mozilla::RangedPtr &s) : CharPtr(s) {} - StableCharPtr(const jschar *s, size_t len) : CharPtr(s, len) {} - StableCharPtr(const jschar *pos, const jschar *start, size_t len) - : CharPtr(pos, start, len) - {} -}; - -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG class JS_PUBLIC_API(AutoCheckRequestDepth) { JSContext *cx; public: - AutoCheckRequestDepth(JSContext *cx); - AutoCheckRequestDepth(js::ContextFriendFields *cx); + explicit AutoCheckRequestDepth(JSContext *cx); + explicit AutoCheckRequestDepth(js::ContextFriendFields *cx); ~AutoCheckRequestDepth(); }; @@ -71,155 +60,53 @@ class JS_PUBLIC_API(AutoCheckRequestDepth) # define CHECK_REQUEST(cx) \ ((void) 0) -#endif /* JS_THREADSAFE && DEBUG */ +#endif /* JS_THREADSAFE && JS_DEBUG */ -#ifdef DEBUG +#ifdef JS_DEBUG /* * Assert that we're not doing GC on cx, that we're in a request as * needed, and that the compartments for cx and v are correct. * Also check that GC would be safe at this point. */ JS_PUBLIC_API(void) -AssertArgumentsAreSane(JSContext *cx, JS::Handle v); +AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v); #else -inline void AssertArgumentsAreSane(JSContext *cx, JS::Handle v) { +inline void AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v) { /* Do nothing */ } -#endif /* DEBUG */ - -class JS_PUBLIC_API(AutoGCRooter) { - public: - AutoGCRooter(JSContext *cx, ptrdiff_t tag); - AutoGCRooter(js::ContextFriendFields *cx, ptrdiff_t tag); - - ~AutoGCRooter() { - JS_ASSERT(this == *stackTop); - *stackTop = down; - } - - /* Implemented in gc/RootMarking.cpp. */ - inline void trace(JSTracer *trc); - static void traceAll(JSTracer *trc); - static void traceAllWrappers(JSTracer *trc); - - protected: - AutoGCRooter * const down; - - /* - * Discriminates actual subclass of this being used. If non-negative, the - * subclass roots an array of values of the length stored in this field. - * If negative, meaning is indicated by the corresponding value in the enum - * below. Any other negative value indicates some deeper problem such as - * memory corruption. - */ - ptrdiff_t tag_; - - enum { - VALARRAY = -2, /* js::AutoValueArray */ - PARSER = -3, /* js::frontend::Parser */ - SHAPEVECTOR = -4, /* js::AutoShapeVector */ - IDARRAY = -6, /* js::AutoIdArray */ - DESCRIPTORS = -7, /* js::AutoPropDescArrayRooter */ - ID = -9, /* js::AutoIdRooter */ - VALVECTOR = -10, /* js::AutoValueVector */ - STRING = -12, /* js::AutoStringRooter */ - IDVECTOR = -13, /* js::AutoIdVector */ - OBJVECTOR = -14, /* js::AutoObjectVector */ - STRINGVECTOR =-15, /* js::AutoStringVector */ - SCRIPTVECTOR =-16, /* js::AutoScriptVector */ - NAMEVECTOR = -17, /* js::AutoNameVector */ - HASHABLEVALUE=-18, /* js::HashableValue */ - IONMASM = -19, /* js::jit::MacroAssembler */ - IONALLOC = -20, /* js::jit::AutoTempAllocatorRooter */ - WRAPVECTOR = -21, /* js::AutoWrapperVector */ - WRAPPER = -22, /* js::AutoWrapperRooter */ - OBJOBJHASHMAP=-23, /* js::AutoObjectObjectHashMap */ - OBJU32HASHMAP=-24, /* js::AutoObjectUnsigned32HashMap */ - OBJHASHSET = -25, /* js::AutoObjectHashSet */ - JSONPARSER = -26, /* js::JSONParser */ - CUSTOM = -27, /* js::CustomAutoRooter */ - FUNVECTOR = -28 /* js::AutoFunctionVector */ - }; - - private: - AutoGCRooter ** const stackTop; - - /* No copy or assignment semantics. */ - AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; - void operator=(AutoGCRooter &ida) MOZ_DELETE; -}; - -class AutoStringRooter : private AutoGCRooter { - public: - AutoStringRooter(JSContext *cx, JSString *str = nullptr - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, STRING), str_(str) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - void setString(JSString *str) { - str_ = str; - } - - JSString * string() const { - return str_; - } - - JSString ** addr() { - return &str_; - } - - JSString * const * addr() const { - return &str_; - } - - friend void AutoGCRooter::trace(JSTracer *trc); +#endif /* JS_DEBUG */ - private: - JSString *str_; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER -}; +/* AutoValueArray roots an internal fixed-size array of Values. */ +template +class AutoValueArray : public AutoGCRooter +{ + const size_t length_; + Value elements_[N]; -class AutoArrayRooter : private AutoGCRooter { public: - AutoArrayRooter(JSContext *cx, size_t len, Value *vec - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, len), array(vec), skip(cx, array, len) + explicit AutoValueArray(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, VALARRAY), length_(N) { + /* Always initialize in case we GC before assignment. */ + mozilla::PodArrayZero(elements_); MOZ_GUARD_OBJECT_NOTIFIER_INIT; - JS_ASSERT(tag_ >= 0); - } - - void changeLength(size_t newLength) { - tag_ = ptrdiff_t(newLength); - JS_ASSERT(tag_ >= 0); - } - - void changeArray(Value *newArray, size_t newLength) { - changeLength(newLength); - array = newArray; } - Value *array; + unsigned length() const { return length_; } + const Value *begin() const { return elements_; } + Value *begin() { return elements_; } - MutableHandle handleAt(size_t i) - { - JS_ASSERT(i < size_t(tag_)); - return MutableHandle::fromMarkedLocation(&array[i]); + HandleValue operator[](unsigned i) const { + JS_ASSERT(i < N); + return HandleValue::fromMarkedLocation(&elements_[i]); } - Handle handleAt(size_t i) const - { - JS_ASSERT(i < size_t(tag_)); - return Handle::fromMarkedLocation(&array[i]); + MutableHandleValue operator[](unsigned i) { + JS_ASSERT(i < N); + return MutableHandleValue::fromMarkedLocation(&elements_[i]); } - friend void AutoGCRooter::trace(JSTracer *trc); - - private: MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER - - js::SkipRoot skip; }; template @@ -228,20 +115,17 @@ class AutoVectorRooter : protected AutoGCRooter typedef js::Vector VectorImpl; VectorImpl vector; - /* Prevent overwriting of inline elements in vector. */ - js::SkipRoot vectorRoot; - public: explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, tag), vector(cx), vectorRoot(cx, &vector) + : AutoGCRooter(cx, tag), vector(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; } explicit AutoVectorRooter(js::ContextFriendFields *cx, ptrdiff_t tag MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, tag), vector(cx), vectorRoot(cx, &vector) + : AutoGCRooter(cx, tag), vector(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; } @@ -253,6 +137,7 @@ class AutoVectorRooter : protected AutoGCRooter bool empty() const { return vector.empty(); } bool append(const T &v) { return vector.append(v); } + bool append(const T *ptr, size_t len) { return vector.append(ptr, len); } bool appendAll(const AutoVectorRooter &other) { return vector.appendAll(other.vector); } @@ -291,13 +176,10 @@ class AutoVectorRooter : protected AutoGCRooter return vector.reserve(newLength); } - T &operator[](size_t i) { return vector[i]; } - const T &operator[](size_t i) const { return vector[i]; } - - JS::MutableHandle handleAt(size_t i) { + JS::MutableHandle operator[](size_t i) { return JS::MutableHandle::fromMarkedLocation(&vector[i]); } - JS::Handle handleAt(size_t i) const { + JS::Handle operator[](size_t i) const { return JS::Handle::fromMarkedLocation(&vector[i]); } @@ -408,7 +290,7 @@ class AutoHashMapRooter : protected AutoGCRooter return map.sizeOfIncludingThis(mallocSizeOf); } - unsigned generation() const { + uint32_t generation() const { return map.generation(); } @@ -523,7 +405,7 @@ class AutoHashSetRooter : protected AutoGCRooter return set.sizeOfIncludingThis(mallocSizeOf); } - unsigned generation() const { + uint32_t generation() const { return set.generation(); } @@ -629,7 +511,7 @@ class AutoScriptVector : public AutoVectorRooter }; /* - * Cutsom rooting behavior for internal and external clients. + * Custom rooting behavior for internal and external clients. */ class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter { @@ -651,6 +533,86 @@ class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER }; +/* + * RootedGeneric allows a class to instantiate its own Rooted type by + * including the method: + * + * void trace(JSTracer *trc); + * + * The trace() method must trace all of the class's fields. + */ +template +class RootedGeneric : private CustomAutoRooter +{ + public: + template + explicit RootedGeneric(CX *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + template + explicit RootedGeneric(CX *cx, const T& initial MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx), value(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + operator const T&() const { return value; } + T operator->() const { return value; } + + private: + virtual void trace(JSTracer *trc) { value->trace(trc); } + + T value; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* A handle to an array of rooted values. */ +class HandleValueArray +{ + const size_t length_; + const Value * const elements_; + + HandleValueArray(size_t len, const Value *elements) : length_(len), elements_(elements) {} + + public: + explicit HandleValueArray(const RootedValue& value) : length_(1), elements_(value.address()) {} + + MOZ_IMPLICIT HandleValueArray(const AutoValueVector& values) + : length_(values.length()), elements_(values.begin()) {} + + template + HandleValueArray(const AutoValueArray& values) : length_(N), elements_(values.begin()) {} + + /* CallArgs must already be rooted somewhere up the stack. */ + MOZ_IMPLICIT HandleValueArray(const JS::CallArgs& args) : length_(args.length()), elements_(args.array()) {} + + /* Use with care! Only call this if the data is guaranteed to be marked. */ + static HandleValueArray fromMarkedLocation(size_t len, const Value *elements) { + return HandleValueArray(len, elements); + } + + static HandleValueArray subarray(const HandleValueArray& values, size_t startIndex, size_t len) { + JS_ASSERT(startIndex + len <= values.length()); + return HandleValueArray(len, values.begin() + startIndex); + } + + static HandleValueArray empty() { + return HandleValueArray(0, nullptr); + } + + size_t length() const { return length_; } + const Value *begin() const { return elements_; } + + HandleValue operator[](size_t i) const { + JS_ASSERT(i < length_); + return HandleValue::fromMarkedLocation(&elements_[i]); + } +}; + } /* namespace JS */ /************************************************************************/ @@ -660,7 +622,7 @@ struct JSFreeOp { JSRuntime *runtime_; protected: - JSFreeOp(JSRuntime *rt) + explicit JSFreeOp(JSRuntime *rt) : runtime_(rt) { } public: @@ -725,10 +687,10 @@ typedef enum JSFinalizeStatus { } JSFinalizeStatus; typedef void -(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment); +(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment, void *data); typedef bool -(* JSOperationCallback)(JSContext *cx); +(* JSInterruptCallback)(JSContext *cx); typedef void (* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report); @@ -771,37 +733,20 @@ typedef struct JSErrorFormatString { } JSErrorFormatString; typedef const JSErrorFormatString * -(* JSErrorCallback)(void *userRef, const char *locale, - const unsigned errorNumber); +(* JSErrorCallback)(void *userRef, const unsigned errorNumber); typedef bool -(* JSLocaleToUpperCase)(JSContext *cx, JS::Handle src, - JS::MutableHandle rval); +(* JSLocaleToUpperCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); typedef bool -(* JSLocaleToLowerCase)(JSContext *cx, JS::Handle src, - JS::MutableHandle rval); +(* JSLocaleToLowerCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); typedef bool -(* JSLocaleCompare)(JSContext *cx, JS::Handle src1, JS::Handle src2, - JS::MutableHandle rval); - -typedef bool -(* JSLocaleToUnicode)(JSContext *cx, const char *src, JS::MutableHandle rval); - -/* - * Security protocol types. - */ - -typedef void -(* JSDestroyPrincipalsOp)(JSPrincipals *principals); +(* JSLocaleCompare)(JSContext *cx, JS::HandleString src1, JS::HandleString src2, + JS::MutableHandleValue rval); -/* - * Used to check if a CSP instance wants to disable eval() and friends. - * See js_CheckCSPPermitsJSAction() in jsobj. - */ typedef bool -(* JSCSPEvalChecker)(JSContext *cx); +(* JSLocaleToUnicode)(JSContext *cx, const char *src, JS::MutableHandleValue rval); /* * Callback used to ask the embedding for the cross compartment wrapper handler @@ -813,9 +758,8 @@ typedef bool * guaranteed not to wrap a function. */ typedef JSObject * -(* JSWrapObjectCallback)(JSContext *cx, JS::Handle existing, JS::Handle obj, - JS::Handle proto, JS::Handle parent, - unsigned flags); +(* JSWrapObjectCallback)(JSContext *cx, JS::HandleObject existing, JS::HandleObject obj, + JS::HandleObject parent, unsigned flags); /* * Callback used by the wrap hook to ask the embedding to prepare an object @@ -823,26 +767,12 @@ typedef JSObject * * or even finding a more suitable object for the new compartment. */ typedef JSObject * -(* JSPreWrapCallback)(JSContext *cx, JS::Handle scope, JS::Handle obj, +(* JSPreWrapCallback)(JSContext *cx, JS::HandleObject scope, JS::HandleObject obj, unsigned flags); -/* - * Callback used when wrapping determines that the underlying object is already - * in the compartment for which it is being wrapped. This allows consumers to - * maintain same-compartment wrapping invariants. - * - * |obj| is guaranteed to be same-compartment as |cx|, but it may (or may not) - * be a security or cross-compartment wrapper. This is an unfortunate contract, - * but is important for to avoid unnecessarily recomputing every cross- - * compartment wrapper that gets passed to wrap. - */ -typedef JSObject * -(* JSSameCompartmentWrapObjectCallback)(JSContext *cx, JS::Handle obj); - struct JSWrapObjectCallbacks { JSWrapObjectCallback wrap; - JSSameCompartmentWrapObjectCallback sameCompartmentWrap; JSPreWrapCallback preWrap; }; @@ -858,12 +788,12 @@ typedef void /************************************************************************/ -static JS_ALWAYS_INLINE jsval +static MOZ_ALWAYS_INLINE jsval JS_NumberValue(double d) { int32_t i; d = JS::CanonicalizeNaN(d); - if (mozilla::DoubleIsInt32(d, &i)) + if (mozilla::NumberIsInt32(d, &i)) return INT_TO_JSVAL(i); return DOUBLE_TO_JSVAL(d); } @@ -883,41 +813,91 @@ JS_StringHasBeenInterned(JSContext *cx, JSString *str); JS_PUBLIC_API(jsid) INTERNED_STRING_TO_JSID(JSContext *cx, JSString *str); -/* - * Returns true iff the given jsval is immune to GC and can be used across - * multiple JSRuntimes without requiring any conversion API. - */ -static JS_ALWAYS_INLINE bool -JSVAL_IS_UNIVERSAL(jsval v) -{ - return !JSVAL_IS_GCTHING(v); -} - namespace JS { -class AutoIdRooter : private AutoGCRooter +// Container class for passing in script source buffers to the JS engine. This +// not only groups the buffer and length values, it also provides a way to +// optionally pass ownership of the buffer to the JS engine without copying. +// Rules for use: +// +// 1) The data array must be allocated with js_malloc() or js_realloc() if +// ownership is being granted to the SourceBufferHolder. +// 2) If ownership is not given to the SourceBufferHolder, then the memory +// must be kept alive until the JS compilation is complete. +// 3) Any code calling SourceBufferHolder::take() must guarantee to keep the +// memory alive until JS compilation completes. Normally only the JS +// engine should be calling take(). +// +// Example use: +// +// size_t length = 512; +// jschar* chars = static_cast(js_malloc(sizeof(jschar) * length)); +// JS::SourceBufferHolder srcBuf(chars, length, JS::SourceBufferHolder::GiveOwnership); +// JS::Compile(cx, obj, options, srcBuf); +// +class MOZ_STACK_CLASS SourceBufferHolder MOZ_FINAL { public: - explicit AutoIdRooter(JSContext *cx, jsid aId = INT_TO_JSID(0) - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, ID), id_(aId) + enum Ownership { + NoOwnership, + GiveOwnership + }; + + SourceBufferHolder(const jschar *data, size_t dataLength, Ownership ownership) + : data_(data), + length_(dataLength), + ownsChars_(ownership == GiveOwnership) { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; + // Ensure that null buffers properly return an unowned, empty, + // null-terminated string. + static const jschar NullChar_ = 0; + if (!get()) { + data_ = &NullChar_; + length_ = 0; + ownsChars_ = false; + } } - jsid id() { - return id_; + ~SourceBufferHolder() { + if (ownsChars_) + js_free(const_cast(data_)); } - jsid * addr() { - return &id_; - } + // Access the underlying source buffer without affecting ownership. + const jschar *get() const { return data_; } - friend void AutoGCRooter::trace(JSTracer *trc); + // Length of the source buffer in jschars (not bytes) + size_t length() const { return length_; } + + // Returns true if the SourceBufferHolder owns the buffer and will free + // it upon destruction. If true, it is legal to call take(). + bool ownsChars() const { return ownsChars_; } + + // Retrieve and take ownership of the underlying data buffer. The caller + // is now responsible for calling js_free() on the returned value, *but only + // after JS script compilation has completed*. + // + // After the buffer has been taken the SourceBufferHolder functions as if + // it had been constructed on an unowned buffer; get() and length() still + // work. In order for this to be safe the taken buffer must be kept alive + // until after JS script compilation completes as noted above. + // + // Note, it's the caller's responsibility to check ownsChars() before taking + // the buffer. Taking and then free'ing an unowned buffer will have dire + // consequences. + jschar *take() { + JS_ASSERT(ownsChars_); + ownsChars_ = false; + return const_cast(data_); + } private: - jsid id_; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + SourceBufferHolder(SourceBufferHolder &) MOZ_DELETE; + SourceBufferHolder &operator=(SourceBufferHolder &) MOZ_DELETE; + + const jschar *data_; + size_t length_; + bool ownsChars_; }; } /* namespace JS */ @@ -941,8 +921,6 @@ class AutoIdRooter : private AutoGCRooter object that delegates to a prototype containing this property */ #define JSPROP_INDEX 0x80 /* name is actually (int) index */ -#define JSPROP_SHORTID 0x100 /* set in JS_DefineProperty attrs - if getters/setters use a shortid */ #define JSFUN_STUB_GSOPS 0x200 /* use JS_PropertyStub getter/setter instead of defaulting to class gsops @@ -1029,13 +1007,12 @@ JS_GetEmptyString(JSRuntime *rt); * unconverted arguments. */ extern JS_PUBLIC_API(bool) -JS_ConvertArguments(JSContext *cx, unsigned argc, jsval *argv, const char *format, - ...); +JS_ConvertArguments(JSContext *cx, const JS::CallArgs &args, const char *format, ...); #ifdef va_start extern JS_PUBLIC_API(bool) -JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv, - const char *format, va_list ap); +JS_ConvertArgumentsVA(JSContext *cx, const JS::CallArgs &args, const char *format, + va_list ap); #endif extern JS_PUBLIC_API(bool) @@ -1051,7 +1028,7 @@ extern JS_PUBLIC_API(JSFunction *) JS_ValueToConstructor(JSContext *cx, JS::HandleValue v); extern JS_PUBLIC_API(JSString *) -JS_ValueToSource(JSContext *cx, jsval v); +JS_ValueToSource(JSContext *cx, JS::Handle v); namespace js { /* @@ -1076,14 +1053,10 @@ ToStringSlow(JSContext *cx, JS::HandleValue v); namespace JS { /* ES5 9.3 ToNumber. */ -JS_ALWAYS_INLINE bool -ToNumber(JSContext *cx, Handle v, double *out) +MOZ_ALWAYS_INLINE bool +ToNumber(JSContext *cx, HandleValue v, double *out) { AssertArgumentsAreSane(cx, v); - { - js::SkipRoot root(cx, &v); - js::MaybeCheckStackRoots(cx); - } if (v.isNumber()) { *out = v.toNumber(); @@ -1092,7 +1065,7 @@ ToNumber(JSContext *cx, Handle v, double *out) return js::ToNumberSlow(cx, v, out); } -JS_ALWAYS_INLINE bool +MOZ_ALWAYS_INLINE bool ToBoolean(HandleValue v) { if (v.isBoolean()) @@ -1105,12 +1078,14 @@ ToBoolean(HandleValue v) double d = v.toDouble(); return !mozilla::IsNaN(d) && d != 0; } + if (v.isSymbol()) + return true; /* The slow path handles strings and objects. */ return js::ToBooleanSlow(v); } -JS_ALWAYS_INLINE JSString* +MOZ_ALWAYS_INLINE JSString* ToString(JSContext *cx, HandleValue v) { if (v.isString()) @@ -1133,32 +1108,31 @@ JS_DoubleToUint32(double d); namespace js { /* DO NOT CALL THIS. Use JS::ToUint16. */ extern JS_PUBLIC_API(bool) -ToUint16Slow(JSContext *cx, JS::Handle v, uint16_t *out); +ToUint16Slow(JSContext *cx, JS::HandleValue v, uint16_t *out); /* DO NOT CALL THIS. Use JS::ToInt32. */ extern JS_PUBLIC_API(bool) -ToInt32Slow(JSContext *cx, JS::Handle v, int32_t *out); +ToInt32Slow(JSContext *cx, JS::HandleValue v, int32_t *out); /* DO NOT CALL THIS. Use JS::ToUint32. */ extern JS_PUBLIC_API(bool) -ToUint32Slow(JSContext *cx, JS::Handle v, uint32_t *out); +ToUint32Slow(JSContext *cx, JS::HandleValue v, uint32_t *out); /* DO NOT CALL THIS. Use JS::ToInt64. */ extern JS_PUBLIC_API(bool) -ToInt64Slow(JSContext *cx, JS::Handle v, int64_t *out); +ToInt64Slow(JSContext *cx, JS::HandleValue v, int64_t *out); /* DO NOT CALL THIS. Use JS::ToUint64. */ extern JS_PUBLIC_API(bool) -ToUint64Slow(JSContext *cx, JS::Handle v, uint64_t *out); +ToUint64Slow(JSContext *cx, JS::HandleValue v, uint64_t *out); } /* namespace js */ namespace JS { -JS_ALWAYS_INLINE bool -ToUint16(JSContext *cx, JS::Handle v, uint16_t *out) +MOZ_ALWAYS_INLINE bool +ToUint16(JSContext *cx, JS::HandleValue v, uint16_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = uint16_t(v.toInt32()); @@ -1167,11 +1141,10 @@ ToUint16(JSContext *cx, JS::Handle v, uint16_t *out) return js::ToUint16Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToInt32(JSContext *cx, JS::Handle v, int32_t *out) +MOZ_ALWAYS_INLINE bool +ToInt32(JSContext *cx, JS::HandleValue v, int32_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = v.toInt32(); @@ -1180,11 +1153,10 @@ ToInt32(JSContext *cx, JS::Handle v, int32_t *out) return js::ToInt32Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToUint32(JSContext *cx, JS::Handle v, uint32_t *out) +MOZ_ALWAYS_INLINE bool +ToUint32(JSContext *cx, JS::HandleValue v, uint32_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = uint32_t(v.toInt32()); @@ -1193,32 +1165,28 @@ ToUint32(JSContext *cx, JS::Handle v, uint32_t *out) return js::ToUint32Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToInt64(JSContext *cx, JS::Handle v, int64_t *out) +MOZ_ALWAYS_INLINE bool +ToInt64(JSContext *cx, JS::HandleValue v, int64_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { *out = int64_t(v.toInt32()); return true; } - return js::ToInt64Slow(cx, v, out); } -JS_ALWAYS_INLINE bool -ToUint64(JSContext *cx, JS::Handle v, uint64_t *out) +MOZ_ALWAYS_INLINE bool +ToUint64(JSContext *cx, JS::HandleValue v, uint64_t *out) { AssertArgumentsAreSane(cx, v); - js::MaybeCheckStackRoots(cx); if (v.isInt32()) { /* Account for sign extension of negatives into the longer 64bit space. */ *out = uint64_t(int64_t(v.toInt32())); return true; } - return js::ToUint64Slow(cx, v, out); } @@ -1226,7 +1194,7 @@ ToUint64(JSContext *cx, JS::Handle v, uint64_t *out) } /* namespace JS */ extern JS_PUBLIC_API(JSType) -JS_TypeOfValue(JSContext *cx, jsval v); +JS_TypeOfValue(JSContext *cx, JS::Handle v); extern JS_PUBLIC_API(const char *) JS_GetTypeName(JSContext *cx, JSType type); @@ -1235,7 +1203,7 @@ extern JS_PUBLIC_API(bool) JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal); extern JS_PUBLIC_API(bool) -JS_LooselyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal); +JS_LooselyEqual(JSContext *cx, JS::Handle v1, JS::Handle v2, bool *equal); extern JS_PUBLIC_API(bool) JS_SameValue(JSContext *cx, jsval v1, jsval v2, bool *same); @@ -1258,12 +1226,6 @@ JS_IsBuiltinFunctionConstructor(JSFunction *fun); * See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference */ -typedef enum JSUseHelperThreads -{ - JS_NO_HELPER_THREADS, - JS_USE_HELPER_THREADS -} JSUseHelperThreads; - /** * Initialize SpiderMonkey, returning true only if initialization succeeded. * Once this method has succeeded, it is safe to call JS_NewRuntime and other @@ -1301,7 +1263,9 @@ extern JS_PUBLIC_API(void) JS_ShutDown(void); extern JS_PUBLIC_API(JSRuntime *) -JS_NewRuntime(uint32_t maxbytes, JSUseHelperThreads useHelperThreads); +JS_NewRuntime(uint32_t maxbytes, + uint32_t maxNurseryBytes = JS::DefaultNurseryBytes, + JSRuntime *parentRuntime = nullptr); extern JS_PUBLIC_API(void) JS_DestroyRuntime(JSRuntime *rt); @@ -1324,6 +1288,9 @@ JS_GetRuntimePrivate(JSRuntime *rt); extern JS_PUBLIC_API(JSRuntime *) JS_GetRuntime(JSContext *cx); +extern JS_PUBLIC_API(JSRuntime *) +JS_GetParentRuntime(JSContext *cx); + JS_PUBLIC_API(void) JS_SetRuntimePrivate(JSRuntime *rt, void *data); @@ -1349,8 +1316,8 @@ AssertHeapIsIdle(JSContext *cx); class JSAutoRequest { public: - JSAutoRequest(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit JSAutoRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : mContext(cx) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -1374,10 +1341,10 @@ class JSAutoRequest class JSAutoCheckRequest { public: - JSAutoCheckRequest(JSContext *cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + explicit JSAutoCheckRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) { -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG mContext = cx; JS_ASSERT(JS_IsInRequest(JS_GetRuntime(cx))); #endif @@ -1385,14 +1352,14 @@ class JSAutoCheckRequest } ~JSAutoCheckRequest() { -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG JS_ASSERT(JS_IsInRequest(JS_GetRuntime(mContext))); #endif } private: -#if defined JS_THREADSAFE && defined DEBUG +#if defined JS_THREADSAFE && defined JS_DEBUG JSContext *mContext; #endif MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER @@ -1448,54 +1415,122 @@ JS_StringToVersion(const char *string); namespace JS { -class JS_PUBLIC_API(ContextOptions) { +class JS_PUBLIC_API(RuntimeOptions) { public: - ContextOptions() - : extraWarnings_(false), + RuntimeOptions() + : baseline_(false), + ion_(false), + asmJS_(false), + nativeRegExp_(false), werror_(false), - varObjFix_(false), - privateIsNSISupports_(false), - dontReportUncaught_(false), - noDefaultCompartmentObject_(false), - noScriptRval_(false), strictMode_(false), - baseline_(false), - typeInference_(false), - ion_(false), - asmJS_(false) + varObjFix_(false) { } - bool extraWarnings() const { return extraWarnings_; } - ContextOptions &setExtraWarnings(bool flag) { - extraWarnings_ = flag; + bool baseline() const { return baseline_; } + RuntimeOptions &setBaseline(bool flag) { + baseline_ = flag; return *this; } - ContextOptions &toggleExtraWarnings() { - extraWarnings_ = !extraWarnings_; + RuntimeOptions &toggleBaseline() { + baseline_ = !baseline_; + return *this; + } + + bool ion() const { return ion_; } + RuntimeOptions &setIon(bool flag) { + ion_ = flag; + return *this; + } + RuntimeOptions &toggleIon() { + ion_ = !ion_; + return *this; + } + + bool asmJS() const { return asmJS_; } + RuntimeOptions &setAsmJS(bool flag) { + asmJS_ = flag; + return *this; + } + RuntimeOptions &toggleAsmJS() { + asmJS_ = !asmJS_; + return *this; + } + + bool nativeRegExp() const { return nativeRegExp_; } + RuntimeOptions &setNativeRegExp(bool flag) { + nativeRegExp_ = flag; return *this; } bool werror() const { return werror_; } - ContextOptions &setWerror(bool flag) { + RuntimeOptions &setWerror(bool flag) { werror_ = flag; return *this; } - ContextOptions &toggleWerror() { + RuntimeOptions &toggleWerror() { werror_ = !werror_; return *this; } + bool strictMode() const { return strictMode_; } + RuntimeOptions &setStrictMode(bool flag) { + strictMode_ = flag; + return *this; + } + RuntimeOptions &toggleStrictMode() { + strictMode_ = !strictMode_; + return *this; + } + bool varObjFix() const { return varObjFix_; } - ContextOptions &setVarObjFix(bool flag) { + RuntimeOptions &setVarObjFix(bool flag) { varObjFix_ = flag; return *this; } - ContextOptions &toggleVarObjFix() { + RuntimeOptions &toggleVarObjFix() { varObjFix_ = !varObjFix_; return *this; } + private: + bool baseline_ : 1; + bool ion_ : 1; + bool asmJS_ : 1; + bool nativeRegExp_ : 1; + bool werror_ : 1; + bool strictMode_ : 1; + bool varObjFix_ : 1; +}; + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSRuntime *rt); + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSContext *cx); + +class JS_PUBLIC_API(ContextOptions) { + public: + ContextOptions() + : extraWarnings_(false), + privateIsNSISupports_(false), + dontReportUncaught_(false), + noDefaultCompartmentObject_(false), + noScriptRval_(false) + { + } + + bool extraWarnings() const { return extraWarnings_; } + ContextOptions &setExtraWarnings(bool flag) { + extraWarnings_ = flag; + return *this; + } + ContextOptions &toggleExtraWarnings() { + extraWarnings_ = !extraWarnings_; + return *this; + } + bool privateIsNSISupports() const { return privateIsNSISupports_; } ContextOptions &setPrivateIsNSISupports(bool flag) { privateIsNSISupports_ = flag; @@ -1536,69 +1571,12 @@ class JS_PUBLIC_API(ContextOptions) { return *this; } - bool strictMode() const { return strictMode_; } - ContextOptions &setStrictMode(bool flag) { - strictMode_ = flag; - return *this; - } - ContextOptions &toggleStrictMode() { - strictMode_ = !strictMode_; - return *this; - } - - bool baseline() const { return baseline_; } - ContextOptions &setBaseline(bool flag) { - baseline_ = flag; - return *this; - } - ContextOptions &toggleBaseline() { - baseline_ = !baseline_; - return *this; - } - - bool typeInference() const { return typeInference_; } - ContextOptions &setTypeInference(bool flag) { - typeInference_ = flag; - return *this; - } - ContextOptions &toggleTypeInference() { - typeInference_ = !typeInference_; - return *this; - } - - bool ion() const { return ion_; } - ContextOptions &setIon(bool flag) { - ion_ = flag; - return *this; - } - ContextOptions &toggleIon() { - ion_ = !ion_; - return *this; - } - - bool asmJS() const { return asmJS_; } - ContextOptions &setAsmJS(bool flag) { - asmJS_ = flag; - return *this; - } - ContextOptions &toggleAsmJS() { - asmJS_ = !asmJS_; - return *this; - } - private: bool extraWarnings_ : 1; - bool werror_ : 1; - bool varObjFix_ : 1; bool privateIsNSISupports_ : 1; bool dontReportUncaught_ : 1; bool noDefaultCompartmentObject_ : 1; bool noScriptRval_ : 1; - bool strictMode_ : 1; - bool baseline_ : 1; - bool typeInference_ : 1; - bool ion_ : 1; - bool asmJS_ : 1; }; JS_PUBLIC_API(ContextOptions &) @@ -1606,7 +1584,7 @@ ContextOptionsRef(JSContext *cx); class JS_PUBLIC_API(AutoSaveContextOptions) { public: - AutoSaveContextOptions(JSContext *cx) + explicit AutoSaveContextOptions(JSContext *cx) : cx_(cx), oldOptions_(ContextOptionsRef(cx_)) { @@ -1624,9 +1602,6 @@ class JS_PUBLIC_API(AutoSaveContextOptions) { } /* namespace JS */ -extern JS_PUBLIC_API(void) -JS_SetJitHardening(JSRuntime *rt, bool enabled); - extern JS_PUBLIC_API(const char *) JS_GetImplementationVersion(void); @@ -1663,14 +1638,11 @@ JS_WrapObject(JSContext *cx, JS::MutableHandleObject objp); extern JS_PUBLIC_API(bool) JS_WrapValue(JSContext *cx, JS::MutableHandleValue vp); -extern JS_PUBLIC_API(bool) -JS_WrapId(JSContext *cx, jsid *idp); - extern JS_PUBLIC_API(JSObject *) -JS_TransplantObject(JSContext *cx, JS::Handle origobj, JS::Handle target); +JS_TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target); extern JS_PUBLIC_API(bool) -JS_RefreshCrossCompartmentWrappers(JSContext *cx, JSObject *ob); +JS_RefreshCrossCompartmentWrappers(JSContext *cx, JS::Handle obj); /* * At any time, a JSContext has a current (possibly-nullptr) compartment. @@ -1717,6 +1689,15 @@ class JS_PUBLIC_API(JSAutoCompartment) ~JSAutoCompartment(); }; +class JS_PUBLIC_API(JSAutoNullableCompartment) +{ + JSContext *cx_; + JSCompartment *oldCompartment_; + public: + explicit JSAutoNullableCompartment(JSContext *cx, JSObject *targetOrNull); + ~JSAutoNullableCompartment(); +}; + /* NB: This API is infallible; a nullptr return value does not indicate error. */ extern JS_PUBLIC_API(JSCompartment *) JS_EnterCompartment(JSContext *cx, JSObject *target); @@ -1743,7 +1724,7 @@ JS_IterateCompartments(JSRuntime *rt, void *data, * NB: This sets cx's global object to obj if it was null. */ extern JS_PUBLIC_API(bool) -JS_InitStandardClasses(JSContext *cx, JSObject *obj); +JS_InitStandardClasses(JSContext *cx, JS::Handle obj); /* * Resolve id, which must contain either a string or an int, to a standard @@ -1759,20 +1740,40 @@ JS_InitStandardClasses(JSContext *cx, JSObject *obj); * loops any classes not yet resolved lazily. */ extern JS_PUBLIC_API(bool) -JS_ResolveStandardClass(JSContext *cx, JS::Handle obj, JS::Handle id, - bool *resolved); +JS_ResolveStandardClass(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *resolved); extern JS_PUBLIC_API(bool) -JS_EnumerateStandardClasses(JSContext *cx, JS::Handle obj); +JS_EnumerateStandardClasses(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, JSObject **objp); +JS_GetClassObject(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); extern JS_PUBLIC_API(bool) -JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JSObject **objp); +JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); + +namespace JS { + +/* + * Determine if the given object is an instance/prototype/constructor for a standard + * class. If so, return the associated JSProtoKey. If not, return JSProto_Null. + */ + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstance(JSObject *obj); extern JS_PUBLIC_API(JSProtoKey) -JS_IdentifyClassPrototype(JSContext *cx, JSObject *obj); +IdentifyStandardPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstanceOrPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardConstructor(JSObject *obj); + +extern JS_PUBLIC_API(void) +ProtoKeyToId(JSContext *cx, JSProtoKey key, JS::MutableHandleId idp); + +} /* namespace JS */ extern JS_PUBLIC_API(JSProtoKey) JS_IdToProtoKey(JSContext *cx, JS::HandleId id); @@ -1782,21 +1783,28 @@ JS_IdToProtoKey(JSContext *cx, JS::HandleId id); * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetFunctionPrototype(JSContext *cx, JSObject *forObj); +JS_GetFunctionPrototype(JSContext *cx, JS::HandleObject forObj); /* * Returns the original value of |Object.prototype| from the global object in * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetObjectPrototype(JSContext *cx, JSObject *forObj); +JS_GetObjectPrototype(JSContext *cx, JS::HandleObject forObj); /* * Returns the original value of |Array.prototype| from the global object in * which |forObj| was created. */ extern JS_PUBLIC_API(JSObject *) -JS_GetArrayPrototype(JSContext *cx, JSObject *forObj); +JS_GetArrayPrototype(JSContext *cx, JS::HandleObject forObj); + +/* + * Returns the original value of |Error.prototype| from the global + * object of the current compartment of cx. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetErrorPrototype(JSContext *cx); extern JS_PUBLIC_API(JSObject *) JS_GetGlobalForObject(JSContext *cx, JSObject *obj); @@ -1818,23 +1826,11 @@ CurrentGlobalOrNull(JSContext *cx); } -/* - * This method returns the global corresponding to the most recent scripted - * frame, which may not match the cx's current compartment. This is extremely - * dangerous, because it can bypass compartment security invariants in subtle - * ways. To use it safely, the caller must perform a subsequent security - * check. There is currently only one consumer of this function in Gecko, and - * it should probably stay that way. If you'd like to use it, please consult - * the XPConnect module owner first. - */ -extern JS_PUBLIC_API(JSObject *) -JS_GetScriptedGlobal(JSContext *cx); - /* * Initialize the 'Reflect' object on a global object. */ extern JS_PUBLIC_API(JSObject *) -JS_InitReflect(JSContext *cx, JSObject *global); +JS_InitReflect(JSContext *cx, JS::HandleObject global); #ifdef JS_HAS_CTYPES /* @@ -1842,7 +1838,7 @@ JS_InitReflect(JSContext *cx, JSObject *global); * object will be sealed. */ extern JS_PUBLIC_API(bool) -JS_InitCTypesClass(JSContext *cx, JSObject *global); +JS_InitCTypesClass(JSContext *cx, JS::HandleObject global); /* * Convert a unicode string 'source' of length 'slen' to the platform native @@ -1917,6 +1913,7 @@ JS_strdup(JSContext *cx, const char *s); extern JS_PUBLIC_API(char *) JS_strdup(JSRuntime *rt, const char *s); +namespace JS { /* * A GC root is a pointer to a jsval, JSObject * or JSString * that itself @@ -1944,52 +1941,54 @@ JS_strdup(JSRuntime *rt, const char *s); * before freeing structPtr's memory. */ extern JS_PUBLIC_API(bool) -JS_AddValueRoot(JSContext *cx, jsval *vp); +AddValueRoot(JSContext *cx, JS::Heap *vp); extern JS_PUBLIC_API(bool) -JS_AddStringRoot(JSContext *cx, JSString **rp); +AddStringRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(bool) -JS_AddObjectRoot(JSContext *cx, JSObject **rp); +AddObjectRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(bool) -JS_AddNamedValueRoot(JSContext *cx, jsval *vp, const char *name); +AddNamedValueRoot(JSContext *cx, JS::Heap *vp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedValueRootRT(JSRuntime *rt, jsval *vp, const char *name); +AddNamedValueRootRT(JSRuntime *rt, JS::Heap *vp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedStringRoot(JSContext *cx, JSString **rp, const char *name); +AddNamedStringRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedObjectRoot(JSContext *cx, JSObject **rp, const char *name); +AddNamedObjectRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(bool) -JS_AddNamedScriptRoot(JSContext *cx, JSScript **rp, const char *name); +AddNamedScriptRoot(JSContext *cx, JS::Heap *rp, const char *name); extern JS_PUBLIC_API(void) -JS_RemoveValueRoot(JSContext *cx, jsval *vp); +RemoveValueRoot(JSContext *cx, JS::Heap *vp); extern JS_PUBLIC_API(void) -JS_RemoveStringRoot(JSContext *cx, JSString **rp); +RemoveStringRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveObjectRoot(JSContext *cx, JSObject **rp); +RemoveObjectRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveScriptRoot(JSContext *cx, JSScript **rp); +RemoveScriptRoot(JSContext *cx, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveValueRootRT(JSRuntime *rt, jsval *vp); +RemoveValueRootRT(JSRuntime *rt, JS::Heap *vp); extern JS_PUBLIC_API(void) -JS_RemoveStringRootRT(JSRuntime *rt, JSString **rp); +RemoveStringRootRT(JSRuntime *rt, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveObjectRootRT(JSRuntime *rt, JSObject **rp); +RemoveObjectRootRT(JSRuntime *rt, JS::Heap *rp); extern JS_PUBLIC_API(void) -JS_RemoveScriptRootRT(JSRuntime *rt, JSScript **rp); +RemoveScriptRootRT(JSRuntime *rt, JS::Heap *rp); + +} /* namespace JS */ /* * Register externally maintained GC roots. @@ -2005,42 +2004,10 @@ JS_AddExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); extern JS_PUBLIC_API(void) JS_RemoveExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); -/* - * JS_CallTracer API and related macros for implementors of JSTraceOp, to - * enumerate all references to traceable things reachable via a property or - * other strong ref identified for debugging purposes by name or index or - * a naming callback. - * - * See the JSTraceOp typedef. - */ +#ifdef JS_DEBUG /* - * Use the following macros to check if a particular jsval is a traceable - * thing and to extract the thing and its kind to pass to JS_CallTracer. - */ -static JS_ALWAYS_INLINE bool -JSVAL_IS_TRACEABLE(jsval v) -{ - return JSVAL_IS_TRACEABLE_IMPL(JSVAL_TO_IMPL(v)); -} - -static JS_ALWAYS_INLINE void * -JSVAL_TO_TRACEABLE(jsval v) -{ - return JSVAL_TO_GCTHING(v); -} - -static JS_ALWAYS_INLINE JSGCTraceKind -JSVAL_TRACE_KIND(jsval v) -{ - JS_ASSERT(JSVAL_IS_GCTHING(v)); - return (JSGCTraceKind) JSVAL_TRACE_KIND_IMPL(JSVAL_TO_IMPL(v)); -} - -#ifdef DEBUG - -/* - * DEBUG-only method to dump the object graph of heap-allocated things. + * Debug-only method to dump the object graph of heap-allocated things. * * fp: file for the dump output. * start: when non-null, dump only things reachable from start @@ -2072,14 +2039,17 @@ JS_MaybeGC(JSContext *cx); extern JS_PUBLIC_API(void) JS_SetGCCallback(JSRuntime *rt, JSGCCallback cb, void *data); +extern JS_PUBLIC_API(bool) +JS_AddFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb, void *data); + extern JS_PUBLIC_API(void) -JS_SetFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); +JS_RemoveFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); extern JS_PUBLIC_API(bool) JS_IsGCMarkingTracer(JSTracer *trc); /* For assertions only. */ -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_PUBLIC_API(bool) JS_IsMarkingGray(JSTracer *trc); #endif @@ -2175,22 +2145,17 @@ typedef enum JSGCParamKey { * available to be decommitted, then JS_MaybeGC will trigger a shrinking GC * to decommit it. */ - JSGC_DECOMMIT_THRESHOLD = 20 -} JSGCParamKey; - -typedef enum JSGCMode { - /* Perform only global GCs. */ - JSGC_MODE_GLOBAL = 0, - - /* Perform per-compartment GCs until too much garbage has accumulated. */ - JSGC_MODE_COMPARTMENT = 1, + JSGC_DECOMMIT_THRESHOLD = 20, /* - * Collect in short time slices rather than all at once. Implies - * JSGC_MODE_COMPARTMENT. + * We try to keep at least this many unused chunks in the free chunk pool at + * all times, even after a shrinking GC. */ - JSGC_MODE_INCREMENTAL = 2 -} JSGCMode; + JSGC_MIN_EMPTY_CHUNK_COUNT = 21, + + /* We never keep more than this many unused chunks in the free chunk pool. */ + JSGC_MAX_EMPTY_CHUNK_COUNT = 22 +} JSGCParamKey; extern JS_PUBLIC_API(void) JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32_t value); @@ -2204,6 +2169,9 @@ JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32_t value); extern JS_PUBLIC_API(uint32_t) JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key); +extern JS_PUBLIC_API(void) +JS_SetGCParametersBasedOnAvailableMemory(JSRuntime *rt, uint32_t availMem); + /* * Create a new JSString whose chars member refers to external memory, i.e., * memory requiring application-specific finalization. @@ -2252,7 +2220,7 @@ extern JS_PUBLIC_API(int) JS_IdArrayLength(JSContext *cx, JSIdArray *ida); extern JS_PUBLIC_API(jsid) -JS_IdArrayGet(JSContext *cx, JSIdArray *ida, int index); +JS_IdArrayGet(JSContext *cx, JSIdArray *ida, unsigned index); extern JS_PUBLIC_API(void) JS_DestroyIdArray(JSContext *cx, JSIdArray *ida); @@ -2272,13 +2240,12 @@ class AutoIdArray : private AutoGCRooter if (idArray) JS_DestroyIdArray(context, idArray); } - bool operator!() { + bool operator!() const { return !idArray; } jsid operator[](size_t i) const { JS_ASSERT(idArray); - JS_ASSERT(i < length()); - return JS_IdArrayGet(context, idArray, i); + return JS_IdArrayGet(context, idArray, unsigned(i)); } size_t length() const { return JS_IdArrayLength(context, idArray); @@ -2308,15 +2275,13 @@ class AutoIdArray : private AutoGCRooter } /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_ValueToId(JSContext *cx, jsval v, jsid *idp); +JS_ValueToId(JSContext *cx, JS::HandleValue v, JS::MutableHandleId idp); extern JS_PUBLIC_API(bool) -JS_IdToValue(JSContext *cx, jsid id, jsval *vp); +JS_StringToId(JSContext *cx, JS::HandleString s, JS::MutableHandleId idp); -/* - * JSNewResolveOp flag bits. - */ -#define JSRESOLVE_ASSIGNING 0x01 /* resolve on the left of assignment */ +extern JS_PUBLIC_API(bool) +JS_IdToValue(JSContext *cx, jsid id, JS::MutableHandle vp); /* * Invoke the [[DefaultValue]] hook (see ES5 8.6.2) with the provided hint on @@ -2325,29 +2290,30 @@ JS_IdToValue(JSContext *cx, jsid id, jsval *vp); * success the resulting value is stored in *vp. */ extern JS_PUBLIC_API(bool) -JS_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp); +JS_DefaultValue(JSContext *cx, JS::Handle obj, JSType hint, + JS::MutableHandle vp); extern JS_PUBLIC_API(bool) -JS_PropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, - JS::MutableHandle vp); +JS_PropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_StrictPropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, bool strict, - JS::MutableHandle vp); +JS_StrictPropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_DeletePropertyStub(JSContext *cx, JS::Handle obj, JS::Handle id, +JS_DeletePropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_EnumerateStub(JSContext *cx, JS::Handle obj); +JS_EnumerateStub(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_ResolveStub(JSContext *cx, JS::Handle obj, JS::Handle id); +JS_ResolveStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id); extern JS_PUBLIC_API(bool) -JS_ConvertStub(JSContext *cx, JS::Handle obj, JSType type, - JS::MutableHandle vp); +JS_ConvertStub(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); struct JSConstDoubleSpec { double dval; @@ -2385,7 +2351,7 @@ typedef struct JSNativeWrapper { * Macro static initializers which make it easy to pass no JSJitInfo as part of a * JSPropertySpec or JSFunctionSpec. */ -#define JSOP_WRAPPER(op) {op, nullptr} +#define JSOP_WRAPPER(op) { {op, nullptr} } #define JSOP_NULLWRAPPER JSOP_WRAPPER(nullptr) /* @@ -2394,13 +2360,29 @@ typedef struct JSNativeWrapper { * JSPROP_INDEX bit in flags. */ struct JSPropertySpec { + struct SelfHostedWrapper { + void *unused; + const char *funname; + }; + const char *name; - int8_t tinyid; uint8_t flags; - JSPropertyOpWrapper getter; - JSStrictPropertyOpWrapper setter; - const char *selfHostedGetter; - const char *selfHostedSetter; + union { + JSPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } getter; + union { + JSStrictPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } setter; + +private: + void StaticAsserts() { + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSPropertyOpWrapper)); + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSStrictPropertyOpWrapper)); + JS_STATIC_ASSERT(offsetof(SelfHostedWrapper, funname) == + offsetof(JSPropertyOpWrapper, info)); + } }; namespace JS { @@ -2409,6 +2391,11 @@ namespace detail { /* NEVER DEFINED, DON'T USE. For use by JS_CAST_NATIVE_TO only. */ inline int CheckIsNative(JSNative native); +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_STRING_TO only. */ +template +inline int +CheckIsCharacterLiteral(const char (&arr)[N]); + } // namespace detail } // namespace JS @@ -2416,6 +2403,10 @@ inline int CheckIsNative(JSNative native); (static_cast(sizeof(JS::detail::CheckIsNative(v))), \ reinterpret_cast(v)) +#define JS_CAST_STRING_TO(s, To) \ + (static_cast(sizeof(JS::detail::CheckIsCharacterLiteral(s))), \ + reinterpret_cast(s)) + #define JS_CHECK_ACCESSOR_FLAGS(flags) \ (static_cast::Type>(0), \ (flags)) @@ -2428,26 +2419,26 @@ inline int CheckIsNative(JSNative native); * JSNatives. */ #define JS_PSG(name, getter, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ - JSOP_NULLWRAPPER, nullptr, nullptr} + JSOP_NULLWRAPPER} #define JS_PSGS(name, getter, setter, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ - JSOP_WRAPPER(JS_CAST_NATIVE_TO(setter, JSStrictPropertyOp)), \ - nullptr, nullptr} + JSOP_WRAPPER(JS_CAST_NATIVE_TO(setter, JSStrictPropertyOp))} #define JS_SELF_HOSTED_GET(name, getterName, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER), \ - JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, getterName, nullptr} + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + JSOP_NULLWRAPPER } #define JS_SELF_HOSTED_GETSET(name, getterName, setterName, flags) \ - {name, 0, \ + {name, \ uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER | JSPROP_SETTER), \ - JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, getterName, setterName} -#define JS_PS_END {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER, \ - nullptr, nullptr} + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + { nullptr, JS_CAST_STRING_TO(setterName, const JSJitInfo *) } } +#define JS_PS_END { nullptr, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER } /* * To define a native function, set call to a JSNativeWrapper. To define a @@ -2487,7 +2478,7 @@ struct JSFunctionSpec { {name, {call, info}, nargs, flags, selfHostedName} extern JS_PUBLIC_API(JSObject *) -JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, +JS_InitClass(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent_proto, const JSClass *clasp, JSNative constructor, unsigned nargs, const JSPropertySpec *ps, const JSFunctionSpec *fs, const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs); @@ -2497,16 +2488,17 @@ JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, * right property flags. */ extern JS_PUBLIC_API(bool) -JS_LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor, JSObject *proto); +JS_LinkConstructorAndPrototype(JSContext *cx, JS::Handle ctor, + JS::Handle proto); extern JS_PUBLIC_API(const JSClass *) JS_GetClass(JSObject *obj); extern JS_PUBLIC_API(bool) -JS_InstanceOf(JSContext *cx, JSObject *obj, const JSClass *clasp, jsval *argv); +JS_InstanceOf(JSContext *cx, JS::Handle obj, const JSClass *clasp, JS::CallArgs *args); extern JS_PUBLIC_API(bool) -JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, bool *bp); +JS_HasInstance(JSContext *cx, JS::Handle obj, JS::Handle v, bool *bp); extern JS_PUBLIC_API(void *) JS_GetPrivate(JSObject *obj); @@ -2515,31 +2507,23 @@ extern JS_PUBLIC_API(void) JS_SetPrivate(JSObject *obj, void *data); extern JS_PUBLIC_API(void *) -JS_GetInstancePrivate(JSContext *cx, JSObject *obj, const JSClass *clasp, - jsval *argv); +JS_GetInstancePrivate(JSContext *cx, JS::Handle obj, const JSClass *clasp, + JS::CallArgs *args); extern JS_PUBLIC_API(bool) -JS_GetPrototype(JSContext *cx, JS::Handle obj, JS::MutableHandle protop); +JS_GetPrototype(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject protop); extern JS_PUBLIC_API(bool) -JS_SetPrototype(JSContext *cx, JS::Handle obj, JS::Handle proto); +JS_SetPrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); extern JS_PUBLIC_API(JSObject *) JS_GetParent(JSObject *obj); extern JS_PUBLIC_API(bool) -JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent); +JS_SetParent(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent); extern JS_PUBLIC_API(JSObject *) -JS_GetConstructor(JSContext *cx, JSObject *proto); - -/* - * Get a unique identifier for obj, good for the lifetime of obj (even if it - * is moved by a copying GC). Return false on failure (likely out of memory), - * and true with *idp containing the unique id on success. - */ -extern JS_PUBLIC_API(bool) -JS_GetObjectId(JSContext *cx, JSObject *obj, jsid *idp); +JS_GetConstructor(JSContext *cx, JS::Handle proto); namespace JS { @@ -2582,6 +2566,12 @@ class JS_PUBLIC_API(CompartmentOptions) explicit CompartmentOptions() : version_(JSVERSION_UNKNOWN) , invisibleToDebugger_(false) + , mergeable_(false) + , discardSource_(false) + , cloneSingletons_(false) + , traceGlobal_(nullptr) + , singletonsAsTemplates_(true) + , addonId_(nullptr) { zone_.spec = JS::FreshZone; } @@ -2597,23 +2587,36 @@ class JS_PUBLIC_API(CompartmentOptions) // of the embedding, and references to them should never leak out to script. // This flag causes the this compartment to skip firing onNewGlobalObject // and makes addDebuggee a no-op for this global. - bool invisibleToDebugger() { return invisibleToDebugger_; } + bool invisibleToDebugger() const { return invisibleToDebugger_; } CompartmentOptions &setInvisibleToDebugger(bool flag) { invisibleToDebugger_ = flag; return *this; } - bool baseline(JSContext *cx) const; - Override &baselineOverride() { return baselineOverride_; } + // Compartments used for off-thread compilation have their contents merged + // into a target compartment when the compilation is finished. This is only + // allowed if this flag is set. The invisibleToDebugger flag must also be + // set for such compartments. + bool mergeable() const { return mergeable_; } + CompartmentOptions &setMergeable(bool flag) { + mergeable_ = flag; + return *this; + } - bool typeInference(const js::ExclusiveContext *cx) const; - Override &typeInferenceOverride() { return typeInferenceOverride_; } + // For certain globals, we know enough about the code that will run in them + // that we can discard script source entirely. + bool discardSource() const { return discardSource_; } + CompartmentOptions &setDiscardSource(bool flag) { + discardSource_ = flag; + return *this; + } - bool ion(JSContext *cx) const; - Override &ionOverride() { return ionOverride_; } - bool asmJS(JSContext *cx) const; - Override &asmJSOverride() { return asmJSOverride_; } + bool cloneSingletons() const { return cloneSingletons_; } + CompartmentOptions &setCloneSingletons(bool flag) { + cloneSingletons_ = flag; + return *this; + } void *zonePointer() const { JS_ASSERT(uintptr_t(zone_.pointer) > uintptr_t(JS::SystemZone)); @@ -2623,22 +2626,55 @@ class JS_PUBLIC_API(CompartmentOptions) CompartmentOptions &setZone(ZoneSpecifier spec); CompartmentOptions &setSameZoneAs(JSObject *obj); + void setSingletonsAsValues() { + singletonsAsTemplates_ = false; + } + bool getSingletonsAsTemplates() const { + return singletonsAsTemplates_; + }; + + // A null add-on ID means that the compartment is not associated with an + // add-on. + JSAddonId *addonIdOrNull() const { return addonId_; } + CompartmentOptions &setAddonId(JSAddonId *id) { + addonId_ = id; + return *this; + } + + CompartmentOptions &setTrace(JSTraceOp op) { + traceGlobal_ = op; + return *this; + } + JSTraceOp getTrace() const { + return traceGlobal_; + } + private: JSVersion version_; bool invisibleToDebugger_; - Override baselineOverride_; - Override typeInferenceOverride_; - Override ionOverride_; - Override asmJSOverride_; + bool mergeable_; + bool discardSource_; + bool cloneSingletons_; union { ZoneSpecifier spec; void *pointer; // js::Zone* is not exposed in the API. } zone_; + JSTraceOp traceGlobal_; + + // To XDR singletons, we need to ensure that all singletons are all used as + // templates, by making JSOP_OBJECT return a clone of the JSScript + // singleton, instead of returning the value which is baked in the JSScript. + bool singletonsAsTemplates_; + + JSAddonId *addonId_; }; JS_PUBLIC_API(CompartmentOptions &) CompartmentOptionsRef(JSCompartment *compartment); +JS_PUBLIC_API(CompartmentOptions &) +CompartmentOptionsRef(JSObject *obj); + JS_PUBLIC_API(CompartmentOptions &) CompartmentOptionsRef(JSContext *cx); @@ -2673,16 +2709,28 @@ extern JS_PUBLIC_API(JSObject *) JS_NewGlobalObject(JSContext *cx, const JSClass *clasp, JSPrincipals *principals, JS::OnNewGlobalHookOption hookOption, const JS::CompartmentOptions &options = JS::CompartmentOptions()); +/* + * Spidermonkey does not have a good way of keeping track of what compartments should be marked on + * their own. We can mark the roots unconditionally, but marking GC things only relevant in live + * compartments is hard. To mitigate this, we create a static trace hook, installed on each global + * object, from which we can be sure the compartment is relevant, and mark it. + * + * It is still possible to specify custom trace hooks for global object classes. They can be + * provided via the CompartmentOptions passed to JS_NewGlobalObject. + */ +extern JS_PUBLIC_API(void) +JS_GlobalObjectTraceHook(JSTracer *trc, JSObject *global); extern JS_PUBLIC_API(void) JS_FireOnNewGlobalObject(JSContext *cx, JS::HandleObject global); extern JS_PUBLIC_API(JSObject *) -JS_NewObject(JSContext *cx, const JSClass *clasp, JSObject *proto, JSObject *parent); +JS_NewObject(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); /* Queries the [[Extensible]] property of the object. */ extern JS_PUBLIC_API(bool) -JS_IsExtensible(JSContext *cx, JS::Handle obj, bool *extensible); +JS_IsExtensible(JSContext *cx, JS::HandleObject obj, bool *extensible); extern JS_PUBLIC_API(bool) JS_IsNative(JSObject *obj); @@ -2695,8 +2743,8 @@ JS_GetObjectRuntime(JSObject *obj); * proto if proto's actual parameter value is null. */ extern JS_PUBLIC_API(JSObject *) -JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JSObject *proto, - JSObject *parent); +JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); /* * Freeze obj, and all objects it refers to, recursively. This will not recurse @@ -2704,88 +2752,126 @@ JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JSObject *proto, * deep-frozen. */ extern JS_PUBLIC_API(bool) -JS_DeepFreezeObject(JSContext *cx, JSObject *obj); +JS_DeepFreezeObject(JSContext *cx, JS::Handle obj); /* * Freezes an object; see ES5's Object.freeze(obj) method. */ extern JS_PUBLIC_API(bool) -JS_FreezeObject(JSContext *cx, JSObject *obj); +JS_FreezeObject(JSContext *cx, JS::Handle obj); extern JS_PUBLIC_API(bool) -JS_PreventExtensions(JSContext *cx, JS::Handle obj); +JS_PreventExtensions(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(JSObject *) -JS_New(JSContext *cx, JSObject *ctor, unsigned argc, jsval *argv); +JS_New(JSContext *cx, JS::HandleObject ctor, const JS::HandleValueArray& args); extern JS_PUBLIC_API(JSObject *) -JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, const JSClass *clasp, - JSObject *proto, unsigned attrs); +JS_DefineObject(JSContext *cx, JS::HandleObject obj, const char *name, + const JSClass *clasp = nullptr, JS::HandleObject proto = JS::NullPtr(), + unsigned attrs = 0); extern JS_PUBLIC_API(bool) -JS_DefineConstDoubles(JSContext *cx, JSObject *obj, const JSConstDoubleSpec *cds); +JS_DefineConstDoubles(JSContext *cx, JS::HandleObject obj, const JSConstDoubleSpec *cds); extern JS_PUBLIC_API(bool) -JS_DefineProperties(JSContext *cx, JSObject *obj, const JSPropertySpec *ps); +JS_DefineProperties(JSContext *cx, JS::HandleObject obj, const JSPropertySpec *ps); extern JS_PUBLIC_API(bool) -JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id, jsval descriptor, bool *bp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name, - int8_t tinyid, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name, - bool *foundp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnPropertyById(JSContext *cx, JSObject *obj, jsid id, - bool *foundp); +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, bool *foundp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, bool *foundp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name, - unsigned flags, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id, - unsigned flags, JSObject **objp, JS::MutableHandle vp); +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnProperty(JSContext *cx, JS::HandleObject obj, const char *name, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasProperty(JSContext *cx, JS::HandleObject obj, const char *name, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_LookupPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); struct JSPropertyDescriptor { JSObject *obj; unsigned attrs; - unsigned shortid; JSPropertyOp getter; JSStrictPropertyOp setter; JS::Value value; - JSPropertyDescriptor() : obj(nullptr), attrs(0), shortid(0), getter(nullptr), - setter(nullptr), value(JSVAL_VOID) + JSPropertyDescriptor() + : obj(nullptr), attrs(0), getter(nullptr), setter(nullptr), value(JSVAL_VOID) {} void trace(JSTracer *trc); + + static js::ThingRootKind rootKind() { return js::THING_ROOT_PROPERTY_DESCRIPTOR; } }; namespace JS { @@ -2803,30 +2889,29 @@ class PropertyDescriptorOperations bool hasGetterObject() const { return desc()->attrs & JSPROP_GETTER; } bool hasSetterObject() const { return desc()->attrs & JSPROP_SETTER; } bool hasGetterOrSetterObject() const { return desc()->attrs & (JSPROP_GETTER | JSPROP_SETTER); } + bool hasGetterOrSetter() const { return desc()->getter || desc()->setter; } bool isShared() const { return desc()->attrs & JSPROP_SHARED; } bool isIndex() const { return desc()->attrs & JSPROP_INDEX; } - bool hasShortId() const { return desc()->attrs & JSPROP_SHORTID; } bool hasAttributes(unsigned attrs) const { return desc()->attrs & attrs; } - JS::Handle object() const { - return JS::Handle::fromMarkedLocation(&desc()->obj); + JS::HandleObject object() const { + return JS::HandleObject::fromMarkedLocation(&desc()->obj); } unsigned attributes() const { return desc()->attrs; } - unsigned shortid() const { return desc()->shortid; } JSPropertyOp getter() const { return desc()->getter; } JSStrictPropertyOp setter() const { return desc()->setter; } - JS::Handle getterObject() const { + JS::HandleObject getterObject() const { MOZ_ASSERT(hasGetterObject()); - return JS::Handle::fromMarkedLocation( + return JS::HandleObject::fromMarkedLocation( reinterpret_cast(&desc()->getter)); } - JS::Handle setterObject() const { + JS::HandleObject setterObject() const { MOZ_ASSERT(hasSetterObject()); - return JS::Handle::fromMarkedLocation( + return JS::HandleObject::fromMarkedLocation( reinterpret_cast(&desc()->setter)); } - JS::Handle value() const { - return JS::Handle::fromMarkedLocation(&desc()->value); + JS::HandleValue value() const { + return JS::HandleValue::fromMarkedLocation(&desc()->value); } }; @@ -2840,30 +2925,47 @@ class MutablePropertyDescriptorOperations : public PropertyDescriptorOperations< void clear() { object().set(nullptr); setAttributes(0); - setShortId(0); setGetter(nullptr); setSetter(nullptr); value().setUndefined(); } - JS::MutableHandle object() { - return JS::MutableHandle::fromMarkedLocation(&desc()->obj); + void assign(JSPropertyDescriptor &other) { + object().set(other.obj); + setAttributes(other.attrs); + setGetter(other.getter); + setSetter(other.setter); + value().set(other.value); + } + + JS::MutableHandleObject object() { + return JS::MutableHandleObject::fromMarkedLocation(&desc()->obj); } unsigned &attributesRef() { return desc()->attrs; } JSPropertyOp &getter() { return desc()->getter; } JSStrictPropertyOp &setter() { return desc()->setter; } - JS::MutableHandle value() { - return JS::MutableHandle::fromMarkedLocation(&desc()->value); + JS::MutableHandleValue value() { + return JS::MutableHandleValue::fromMarkedLocation(&desc()->value); } void setEnumerable() { desc()->attrs |= JSPROP_ENUMERATE; } void setAttributes(unsigned attrs) { desc()->attrs = attrs; } - void setShortId(unsigned id) { desc()->shortid = id; } void setGetter(JSPropertyOp op) { desc()->getter = op; } void setSetter(JSStrictPropertyOp op) { desc()->setter = op; } void setGetterObject(JSObject *obj) { desc()->getter = reinterpret_cast(obj); } void setSetterObject(JSObject *obj) { desc()->setter = reinterpret_cast(obj); } + + JS::MutableHandleObject getterObject() { + MOZ_ASSERT(this->hasGetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->getter)); + } + JS::MutableHandleObject setterObject() { + MOZ_ASSERT(this->hasSetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->setter)); + } }; } /* namespace JS */ @@ -2873,7 +2975,6 @@ namespace js { template <> struct GCMethods { static JSPropertyDescriptor initial() { return JSPropertyDescriptor(); } - static ThingRootKind kind() { return THING_ROOT_PROPERTY_DESCRIPTOR; } static bool poisoned(const JSPropertyDescriptor &desc) { return (desc.obj && JS::IsPoisonedPtr(desc.obj)) || (desc.attrs & JSPROP_GETTER && desc.getter && JS::IsPoisonedPtr(desc.getter)) || @@ -2922,12 +3023,22 @@ class MutableHandleBase } /* namespace js */ +namespace JS { + +extern JS_PUBLIC_API(bool) +ParsePropertyDescriptorObject(JSContext *cx, + JS::HandleObject obj, + JS::HandleValue descriptor, + JS::MutableHandle desc); + +} // namespace JS + extern JS_PUBLIC_API(bool) -JS_GetOwnPropertyDescriptorById(JSContext *cx, JSObject *objArg, jsid id, unsigned flags, +JS_GetOwnPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, const char *name, unsigned flags, +JS_GetOwnPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandle desc); /* @@ -2936,138 +3047,193 @@ JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, const char *name, u * then this property was not found on the prototype chain. */ extern JS_PUBLIC_API(bool) -JS_GetPropertyDescriptorById(JSContext *cx, JSObject *obj, jsid id, unsigned flags, +JS_GetPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetPropertyDescriptor(JSContext *cx, JSObject *obj, const char *name, unsigned flags, +JS_GetPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandle desc); extern JS_PUBLIC_API(bool) -JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, JS::MutableHandle vp); +JS_GetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetPropertyTo(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject onBehalfOf, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); +JS_SetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_ForwardGetPropertyTo(JSContext *cx, JSObject *obj, jsid id, JSObject *onBehalfOf, - JS::MutableHandle vp); +JS_DeleteProperty(JSContext *cx, JS::HandleObject obj, const char *name); extern JS_PUBLIC_API(bool) -JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, JS::Handle v); +JS_DeleteProperty2(JSContext *cx, JS::HandleObject obj, const char *name, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_SetPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::Handle v); +JS_DeletePropertyById(JSContext *cx, JS::HandleObject obj, jsid id); extern JS_PUBLIC_API(bool) -JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name); +JS_DeletePropertyById2(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name, bool *succeeded); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleValue value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DeletePropertyById(JSContext *cx, JSObject *obj, jsid id); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleObject value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, bool *succeeded); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleString value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineUCProperty(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + int32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, - int8_t tinyid, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, - unsigned attrs); +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + uint32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnUCProperty(JSContext *cx, JSObject *obj, const jschar *name, +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + double value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *foundp); extern JS_PUBLIC_API(bool) -JS_HasUCProperty(JSContext *cx, JSObject *obj, +JS_HasUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *vp); extern JS_PUBLIC_API(bool) -JS_LookupUCProperty(JSContext *cx, JSObject *obj, +JS_LookupUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::MutableHandle vp); + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_GetUCProperty(JSContext *cx, JSObject *obj, +JS_GetUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::MutableHandle vp); + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_SetUCProperty(JSContext *cx, JSObject *obj, +JS_SetUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, - JS::Handle v); + JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_DeleteUCProperty2(JSContext *cx, JSObject *obj, const jschar *name, size_t namelen, +JS_DeleteUCProperty2(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, bool *succeeded); extern JS_PUBLIC_API(JSObject *) -JS_NewArrayObject(JSContext *cx, int length, jsval *vector); +JS_NewArrayObject(JSContext *cx, const JS::HandleValueArray& contents); + +extern JS_PUBLIC_API(JSObject *) +JS_NewArrayObject(JSContext *cx, size_t length); extern JS_PUBLIC_API(bool) -JS_IsArrayObject(JSContext *cx, JSObject *obj); +JS_IsArrayObject(JSContext *cx, JS::HandleValue value); extern JS_PUBLIC_API(bool) -JS_GetArrayLength(JSContext *cx, JSObject *obj, uint32_t *lengthp); +JS_IsArrayObject(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) -JS_SetArrayLength(JSContext *cx, JSObject *obj, uint32_t length); +JS_GetArrayLength(JSContext *cx, JS::Handle obj, uint32_t *lengthp); extern JS_PUBLIC_API(bool) -JS_DefineElement(JSContext *cx, JSObject *obj, uint32_t index, jsval value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +JS_SetArrayLength(JSContext *cx, JS::Handle obj, uint32_t length); extern JS_PUBLIC_API(bool) -JS_AlreadyHasOwnElement(JSContext *cx, JSObject *obj, uint32_t index, bool *foundp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_HasElement(JSContext *cx, JSObject *obj, uint32_t index, bool *foundp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_LookupElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_GetElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); extern JS_PUBLIC_API(bool) -JS_ForwardGetElementTo(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf, - JS::MutableHandle vp); +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetElementTo(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::HandleObject onBehalfOf, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t v); -/* - * Get the property with name given by |index|, if it has one. If - * not, |*present| will be set to false and the value of |vp| must not - * be relied on. - */ extern JS_PUBLIC_API(bool) -JS_GetElementIfPresent(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf, - JS::MutableHandle vp, bool* present); +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t v); extern JS_PUBLIC_API(bool) -JS_SetElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double v); extern JS_PUBLIC_API(bool) -JS_DeleteElement(JSContext *cx, JSObject *obj, uint32_t index); +JS_DeleteElement(JSContext *cx, JS::HandleObject obj, uint32_t index); extern JS_PUBLIC_API(bool) -JS_DeleteElement2(JSContext *cx, JSObject *obj, uint32_t index, bool *succeeded); +JS_DeleteElement2(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded); /* * Remove all configurable properties from the given (non-global) object and * assign undefined to all writable data properties. */ JS_PUBLIC_API(void) -JS_ClearNonGlobalObject(JSContext *cx, JSObject *objArg); +JS_ClearNonGlobalObject(JSContext *cx, JS::HandleObject obj); /* * Assign 'undefined' to all of the object's non-reserved slots. Note: this is @@ -3077,48 +3243,64 @@ JS_PUBLIC_API(void) JS_SetAllNonReservedSlotsToUndefined(JSContext *cx, JSObject *objArg); /* - * Create a new array buffer with the given contents, which must have been - * returned by JS_AllocateArrayBufferContents or JS_StealArrayBufferContents. - * The new array buffer takes ownership. After calling this function, do not - * free |contents| or use |contents| from another thread. + * Create a new array buffer with the given contents. On success, the ownership + * is transferred to the new array buffer. */ extern JS_PUBLIC_API(JSObject *) -JS_NewArrayBufferWithContents(JSContext *cx, void *contents); +JS_NewArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); /* * Steal the contents of the given array buffer. The array buffer has its * length set to 0 and its contents array cleared. The caller takes ownership - * of |*contents| and must free it or transfer ownership via + * of the return value and must free it or transfer ownership via * JS_NewArrayBufferWithContents when done using it. - * To free |*contents|, call free(). - * A pointer to the buffer's data is returned in |*data|. This pointer can - * be used until |*contents| is freed or has its ownership transferred. */ -extern JS_PUBLIC_API(bool) -JS_StealArrayBufferContents(JSContext *cx, JS::HandleObject obj, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_StealArrayBufferContents(JSContext *cx, JS::HandleObject obj); /* * Allocate memory that may be eventually passed to - * JS_NewArrayBufferWithContents. |nbytes| is the number of payload bytes - * required. The pointer to pass to JS_NewArrayBufferWithContents is returned - * in |contents|. The pointer to the |nbytes| of usable memory is returned in - * |data|. (*|contents| will contain a header before |data|.) The only legal - * operations on *|contents| is to free it, or pass it to - * JS_NewArrayBufferWithContents or JS_ReallocateArrayBufferContents. + * JS_NewArrayBufferWithContents. |maybecx| is optional; if a non-nullptr cx is + * given, it will be used for memory accounting and OOM reporting. |nbytes| is + * the number of payload bytes required. */ -extern JS_PUBLIC_API(bool) -JS_AllocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_AllocateArrayBufferContents(JSContext *maybecx, uint32_t nbytes); /* * Reallocate memory allocated by JS_AllocateArrayBufferContents, growing or - * shrinking it as appropriate. The new data pointer will be returned in data. - * If *contents is nullptr, behaves like JS_AllocateArrayBufferContents. + * shrinking it as appropriate. If oldContents is null then this behaves like + * JS_AllocateArrayBufferContents. */ -extern JS_PUBLIC_API(bool) -JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void **contents, uint8_t **data); +extern JS_PUBLIC_API(void *) +JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void *oldContents, uint32_t oldNbytes); + +/* + * Create a new mapped array buffer with the given memory mapped contents. On success, + * the ownership is transferred to the new mapped array buffer. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewMappedArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); + +/* + * Create memory mapped array buffer contents. + * Caller must take care of closing fd after calling this function. + */ +extern JS_PUBLIC_API(void *) +JS_CreateMappedArrayBufferContents(int fd, size_t offset, size_t length); + +/* + * Release the allocated resource of mapped array buffer contents before the + * object is created. + * If a new object has been created by JS_NewMappedArrayBufferWithContents() + * with this content, then JS_NeuterArrayBuffer() should be used instead to + * release the resource used by the object. + */ +extern JS_PUBLIC_API(void) +JS_ReleaseMappedArrayBufferContents(void *contents, size_t length); extern JS_PUBLIC_API(JSIdArray *) -JS_Enumerate(JSContext *cx, JSObject *obj); +JS_Enumerate(JSContext *cx, JS::HandleObject obj); /* * Create an object to iterate over enumerable properties of obj, in arbitrary @@ -3126,7 +3308,7 @@ JS_Enumerate(JSContext *cx, JSObject *obj); * order, which uses order of property definition in obj. */ extern JS_PUBLIC_API(JSObject *) -JS_NewPropertyIterator(JSContext *cx, JSObject *obj); +JS_NewPropertyIterator(JSContext *cx, JS::Handle obj); /* * Return true on success with *idp containing the id of the next enumerable @@ -3134,11 +3316,7 @@ JS_NewPropertyIterator(JSContext *cx, JSObject *obj); * left to visit. Return false on error. */ extern JS_PUBLIC_API(bool) -JS_NextProperty(JSContext *cx, JSObject *iterobj, jsid *idp); - -extern JS_PUBLIC_API(bool) -JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, - jsval *vp, unsigned *attrsp); +JS_NextProperty(JSContext *cx, JS::Handle iterobj, jsid *idp); extern JS_PUBLIC_API(jsval) JS_GetReservedSlot(JSObject *obj, uint32_t index); @@ -3148,84 +3326,12 @@ JS_SetReservedSlot(JSObject *obj, uint32_t index, jsval v); /************************************************************************/ -/* - * Security protocol. - */ -struct JSPrincipals { - /* Don't call "destroy"; use reference counting macros below. */ -#ifdef JS_THREADSAFE - mozilla::Atomic refcount; -#else - int32_t refcount; -#endif - -#ifdef DEBUG - /* A helper to facilitate principals debugging. */ - uint32_t debugToken; -#endif - - void setDebugToken(uint32_t token) { -# ifdef DEBUG - debugToken = token; -# endif - } - - /* - * This is not defined by the JS engine but should be provided by the - * embedding. - */ - JS_PUBLIC_API(void) dump(); -}; - -extern JS_PUBLIC_API(void) -JS_HoldPrincipals(JSPrincipals *principals); - -extern JS_PUBLIC_API(void) -JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals); - -struct JSSecurityCallbacks { - JSCheckAccessOp checkObjectAccess; - JSCSPEvalChecker contentSecurityPolicyAllows; - JSSubsumesOp subsumes; -}; - -extern JS_PUBLIC_API(void) -JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks); - -extern JS_PUBLIC_API(const JSSecurityCallbacks *) -JS_GetSecurityCallbacks(JSRuntime *rt); - -/* - * Code running with "trusted" principals will be given a deeper stack - * allocation than ordinary scripts. This allows trusted script to run after - * untrusted script has exhausted the stack. This function sets the - * runtime-wide trusted principal. - * - * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since - * there is no available JSContext. Instead, the caller must ensure that the - * given principals stays valid for as long as 'rt' may point to it. If the - * principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be - * called again, passing nullptr for 'prin'. - */ -extern JS_PUBLIC_API(void) -JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin); - -/* - * Initialize the callback that is called to destroy JSPrincipals instance - * when its reference counter drops to zero. The initialization can be done - * only once per JS runtime. - */ -extern JS_PUBLIC_API(void) -JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals); - -/************************************************************************/ - /* * Functions and scripts. */ extern JS_PUBLIC_API(JSFunction *) JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, - JSObject *parent, const char *name); + JS::Handle parent, const char *name); /* * Create the function with the name given by the id. JSID_IS_STRING(id) must @@ -3233,12 +3339,13 @@ JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, */ extern JS_PUBLIC_API(JSFunction *) JS_NewFunctionById(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, - JSObject *parent, jsid id); + JS::Handle parent, JS::Handle id); namespace JS { extern JS_PUBLIC_API(JSFunction *) -GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, jsid id, unsigned nargs); +GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, JS::Handle id, + unsigned nargs); } /* namespace JS */ @@ -3295,22 +3402,22 @@ JS_IsConstructor(JSFunction *fun); * If |callable| is not callable, will throw and return nullptr. */ extern JS_PUBLIC_API(JSObject*) -JS_BindCallable(JSContext *cx, JSObject *callable, JSObject *newThis); +JS_BindCallable(JSContext *cx, JS::Handle callable, JS::Handle newThis); extern JS_PUBLIC_API(bool) -JS_DefineFunctions(JSContext *cx, JSObject *obj, const JSFunctionSpec *fs); +JS_DefineFunctions(JSContext *cx, JS::Handle obj, const JSFunctionSpec *fs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call, +JS_DefineFunction(JSContext *cx, JS::Handle obj, const char *name, JSNative call, unsigned nargs, unsigned attrs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineUCFunction(JSContext *cx, JSObject *obj, +JS_DefineUCFunction(JSContext *cx, JS::Handle obj, const jschar *name, size_t namelen, JSNative call, unsigned nargs, unsigned attrs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call, +JS_DefineFunctionById(JSContext *cx, JS::Handle obj, JS::Handle id, JSNative call, unsigned nargs, unsigned attrs); /* @@ -3318,7 +3425,7 @@ JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call, * fail if funobj was lexically nested inside some other function. */ extern JS_PUBLIC_API(JSObject *) -JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent); +JS_CloneFunctionObject(JSContext *cx, JS::Handle funobj, JS::Handle parent); /* * Given a buffer, return false if the buffer might become a valid @@ -3328,32 +3435,49 @@ JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent); * the compiler. */ extern JS_PUBLIC_API(bool) -JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj, const char *utf8, size_t length); +JS_BufferIsCompilableUnit(JSContext *cx, JS::Handle obj, const char *utf8, + size_t length); -extern JS_PUBLIC_API(JSScript *) +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileScript(JSContext *cx, JS::HandleObject obj, const char *ascii, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileUCScript(JSContext *cx, JS::HandleObject obj, const jschar *chars, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleScript script); extern JS_PUBLIC_API(JSObject *) JS_GetGlobalFromScript(JSScript *script); -extern JS_PUBLIC_API(JSFunction *) +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileFunction(JSContext *cx, JS::HandleObject obj, const char *name, unsigned nargs, const char *const *argnames, const char *bytes, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); -extern JS_PUBLIC_API(JSFunction *) +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) JS_CompileUCFunction(JSContext *cx, JS::HandleObject obj, const char *name, unsigned nargs, const char *const *argnames, const jschar *chars, size_t length, - const JS::CompileOptions &options); + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); namespace JS { @@ -3401,12 +3525,14 @@ namespace JS { * is protected anyway); instead, create instances only of the derived classes: * CompileOptions and OwningCompileOptions. */ -class JS_PUBLIC_API(ReadOnlyCompileOptions) +class JS_FRIEND_API(ReadOnlyCompileOptions) { + friend class CompileOptions; + protected: - JSPrincipals *principals_; JSPrincipals *originPrincipals_; const char *filename_; + const char *introducerFilename_; const jschar *sourceMapURL_; // This constructor leaves 'version' set to JSVERSION_UNKNOWN. The structure @@ -3414,9 +3540,9 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) // classes' constructors take care of that, in ways appropriate to their // purpose. ReadOnlyCompileOptions() - : principals_(nullptr), - originPrincipals_(nullptr), + : originPrincipals_(nullptr), filename_(nullptr), + introducerFilename_(nullptr), sourceMapURL_(nullptr), version(JSVERSION_UNKNOWN), versionSet(false), @@ -3425,6 +3551,7 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) column(0), compileAndGo(false), forEval(false), + defineOnScope(true), noScriptRval(false), selfHostingMode(false), canLazilyParse(true), @@ -3433,7 +3560,12 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) werrorOption(false), asmJSOption(false), forceAsync(false), - sourcePolicy(SAVE_SOURCE) + installedFile(false), + sourceIsLazy(false), + introductionType(nullptr), + introductionLineno(0), + introductionOffset(0), + hasIntroductionInfo(false) { } // Set all POD options (those not requiring reference counts, copies, @@ -3443,12 +3575,13 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) public: // Read-only accessors for non-POD options. The proper way to set these // depends on the derived type. - JSPrincipals *principals() const { return principals_; } - JSPrincipals *originPrincipals() const; + JSPrincipals *originPrincipals(js::ExclusiveContext *cx) const; const char *filename() const { return filename_; } + const char *introducerFilename() const { return introducerFilename_; } const jschar *sourceMapURL() const { return sourceMapURL_; } virtual JSObject *element() const = 0; - virtual JSString *elementProperty() const = 0; + virtual JSString *elementAttributeName() const = 0; + virtual JSScript *introductionScript() const = 0; // POD options. JSVersion version; @@ -3458,6 +3591,7 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) unsigned column; bool compileAndGo; bool forEval; + bool defineOnScope; bool noScriptRval; bool selfHostingMode; bool canLazilyParse; @@ -3466,11 +3600,15 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) bool werrorOption; bool asmJSOption; bool forceAsync; - enum SourcePolicy { - NO_SOURCE, - LAZY_SOURCE, - SAVE_SOURCE - } sourcePolicy; + bool installedFile; // 'true' iff pre-compiling js file in packaged app + bool sourceIsLazy; + + // |introductionType| is a statically allocated C string: + // one of "eval", "Function", or "GeneratorFunction". + const char *introductionType; + unsigned introductionLineno; + uint32_t introductionOffset; + bool hasIntroductionInfo; private: static JSObject * const nullObjectPtr; @@ -3490,11 +3628,12 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) * comes to refer to the object that owns this, then the whole cycle, and * anything else it entrains, will never be freed. */ -class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions +class JS_FRIEND_API(OwningCompileOptions) : public ReadOnlyCompileOptions { JSRuntime *runtime; PersistentRootedObject elementRoot; - PersistentRootedString elementPropertyRoot; + PersistentRootedString elementAttributeNameRoot; + PersistentRootedScript introductionScriptRoot; public: // A minimal constructor, for use with OwningCompileOptions::copy. This @@ -3505,22 +3644,30 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions ~OwningCompileOptions(); JSObject *element() const MOZ_OVERRIDE { return elementRoot; } - JSString *elementProperty() const MOZ_OVERRIDE { return elementPropertyRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } // Set this to a copy of |rhs|. Return false on OOM. bool copy(JSContext *cx, const ReadOnlyCompileOptions &rhs); /* These setters make copies of their string arguments, and are fallible. */ + bool setFile(JSContext *cx, const char *f); bool setFileAndLine(JSContext *cx, const char *f, unsigned l); bool setSourceMapURL(JSContext *cx, const jschar *s); + bool setIntroducerFilename(JSContext *cx, const char *s); /* These setters are infallible, and can be chained. */ - OwningCompileOptions &setElement(JSObject *e) { elementRoot = e; return *this; } - OwningCompileOptions &setElementProperty(JSString *p) { elementPropertyRoot = p; return *this; } - OwningCompileOptions &setPrincipals(JSPrincipals *p) { - if (p) JS_HoldPrincipals(p); - if (principals_) JS_DropPrincipals(runtime, principals_); - principals_ = p; + OwningCompileOptions &setLine(unsigned l) { lineno = l; return *this; } + OwningCompileOptions &setElement(JSObject *e) { + elementRoot = e; + return *this; + } + OwningCompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + OwningCompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; return *this; } OwningCompileOptions &setOriginPrincipals(JSPrincipals *p) { @@ -3538,10 +3685,27 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions OwningCompileOptions &setColumn(unsigned c) { column = c; return *this; } OwningCompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } OwningCompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + OwningCompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } OwningCompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } OwningCompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } OwningCompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } - OwningCompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; } + OwningCompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + OwningCompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + bool setIntroductionInfo(JSContext *cx, const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + if (!setIntroducerFilename(cx, introducerFn)) + return false; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return true; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; }; /* @@ -3551,36 +3715,47 @@ class JS_PUBLIC_API(OwningCompileOptions) : public ReadOnlyCompileOptions * create an instance of this type, it's up to you to guarantee that * everything you store in it will outlive it. */ -class MOZ_STACK_CLASS JS_PUBLIC_API(CompileOptions) : public ReadOnlyCompileOptions +class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOptions { RootedObject elementRoot; - RootedString elementPropertyRoot; + RootedString elementAttributeNameRoot; + RootedScript introductionScriptRoot; public: explicit CompileOptions(JSContext *cx, JSVersion version = JSVERSION_UNKNOWN); CompileOptions(js::ContextFriendFields *cx, const ReadOnlyCompileOptions &rhs) - : ReadOnlyCompileOptions(), elementRoot(cx), elementPropertyRoot(cx) + : ReadOnlyCompileOptions(), elementRoot(cx), elementAttributeNameRoot(cx), + introductionScriptRoot(cx) { copyPODOptions(rhs); - principals_ = rhs.principals(); - originPrincipals_ = rhs.originPrincipals(); + originPrincipals_ = rhs.originPrincipals_; filename_ = rhs.filename(); sourceMapURL_ = rhs.sourceMapURL(); elementRoot = rhs.element(); - elementPropertyRoot = rhs.elementProperty(); + elementAttributeNameRoot = rhs.elementAttributeName(); + introductionScriptRoot = rhs.introductionScript(); } JSObject *element() const MOZ_OVERRIDE { return elementRoot; } - JSString *elementProperty() const MOZ_OVERRIDE { return elementPropertyRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } + CompileOptions &setFile(const char *f) { filename_ = f; return *this; } + CompileOptions &setLine(unsigned l) { lineno = l; return *this; } CompileOptions &setFileAndLine(const char *f, unsigned l) { filename_ = f; lineno = l; return *this; } CompileOptions &setSourceMapURL(const jschar *s) { sourceMapURL_ = s; return *this; } CompileOptions &setElement(JSObject *e) { elementRoot = e; return *this; } - CompileOptions &setElementProperty(JSString *p) { elementPropertyRoot = p; return *this; } - CompileOptions &setPrincipals(JSPrincipals *p) { principals_ = p; return *this; } + CompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + CompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; + return *this; + } CompileOptions &setOriginPrincipals(JSPrincipals *p) { originPrincipals_ = p; return *this; @@ -3594,25 +3769,50 @@ class MOZ_STACK_CLASS JS_PUBLIC_API(CompileOptions) : public ReadOnlyCompileOpti CompileOptions &setColumn(unsigned c) { column = c; return *this; } CompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } CompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + CompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } CompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } CompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } CompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } - CompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; } + CompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + CompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + CompileOptions &setIntroductionInfo(const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + introducerFilename_ = introducerFn; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return *this; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; }; -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *bytes, size_t length); +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const jschar *chars, size_t length); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, FILE *file); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleScript script); -extern JS_PUBLIC_API(JSScript *) -Compile(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, const char *filename); +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, FILE *file, + JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *filename, + JS::MutableHandleScript script); extern JS_PUBLIC_API(bool) CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t length); @@ -3625,8 +3825,8 @@ CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t * for the compilation. The callback will be invoked while off the main thread, * so must ensure that its operations are thread safe. Afterwards, * FinishOffThreadScript must be invoked on the main thread to get the result - * script or nullptr. If maybecx is specified, this method will also report - * any error or warnings generated during the parse. + * script or nullptr. If maybecx is not specified, the resources will be freed, + * but no script will be returned. * * The characters passed in to CompileOffThread must remain live until the * callback is invoked, and the resulting script will be rooted until the call @@ -3634,27 +3834,32 @@ CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t */ extern JS_PUBLIC_API(bool) -CompileOffThread(JSContext *cx, Handle obj, const ReadOnlyCompileOptions &options, +CompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, const jschar *chars, size_t length, OffThreadCompileCallback callback, void *callbackData); extern JS_PUBLIC_API(JSScript *) FinishOffThreadScript(JSContext *maybecx, JSRuntime *rt, void *token); -extern JS_PUBLIC_API(JSFunction *) -CompileFunction(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *name, unsigned nargs, const char *const *argnames, - const char *bytes, size_t length); + SourceBufferHolder &srcBuf, JS::MutableHandleFunction fun); -extern JS_PUBLIC_API(JSFunction *) -CompileFunction(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *name, unsigned nargs, const char *const *argnames, + const char *bytes, size_t length, JS::MutableHandleFunction fun); + +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *name, unsigned nargs, const char *const *argnames, - const jschar *chars, size_t length); + const jschar *chars, size_t length, JS::MutableHandleFunction fun); } /* namespace JS */ extern JS_PUBLIC_API(JSString *) -JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned indent); +JS_DecompileScript(JSContext *cx, JS::Handle script, const char *name, unsigned indent); /* * API extension: OR this into indent to avoid pretty-printing the decompiled @@ -3663,10 +3868,10 @@ JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned i #define JS_DONT_PRETTY_PRINT ((unsigned)0x8000) extern JS_PUBLIC_API(JSString *) -JS_DecompileFunction(JSContext *cx, JSFunction *fun, unsigned indent); +JS_DecompileFunction(JSContext *cx, JS::Handle fun, unsigned indent); extern JS_PUBLIC_API(JSString *) -JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, unsigned indent); +JS_DecompileFunctionBody(JSContext *cx, JS::Handle fun, unsigned indent); /* * NB: JS_ExecuteScript and the JS_Evaluate*Script* quadruplets use the obj @@ -3702,158 +3907,159 @@ JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, unsigned indent); * etc., entry points. */ extern JS_PUBLIC_API(bool) -JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval); +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval, - JSVersion version); +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script); + +namespace JS { /* - * Execute either the function-defining prolog of a script, or the script's - * main body, but not both. + * Like the above, but handles a cross-compartment script. If the script is + * cross-compartment, it is cloned into the current compartment before executing. */ -typedef enum JSExecPart { JSEXEC_PROLOG, JSEXEC_MAIN } JSExecPart; +extern JS_PUBLIC_API(bool) +CloneAndExecuteScript(JSContext *cx, JS::Handle obj, JS::Handle script); + +} /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_EvaluateScript(JSContext *cx, JSObject *obj, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleValue rval, JSVersion version); + +extern JS_PUBLIC_API(bool) +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JSVersion version); extern JS_PUBLIC_API(bool) -JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_EvaluateScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno); extern JS_PUBLIC_API(bool) -JS_EvaluateUCScript(JSContext *cx, JSObject *obj, +JS_EvaluateUCScript(JSContext *cx, JS::Handle obj, const jschar *chars, unsigned length, const char *filename, unsigned lineno, - jsval *rval); + JS::MutableHandle rval); + +namespace JS { extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleValue rval); -/* - * JSAPI clients may optionally specify the 'originPrincipals' of a script. - * A script's originPrincipals may be retrieved through the debug API (via - * JS_GetScriptOriginPrincipals) and the originPrincipals are transitively - * assigned to any nested scripts (including scripts dynamically created via - * eval and the Function constructor). If originPrincipals is null, then the - * value of principals is used as origin principals for the script. - */ extern JS_PUBLIC_API(bool) -JS_EvaluateUCScriptForPrincipalsVersionOrigin(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - JSPrincipals *originPrincipals, - const jschar *chars, unsigned length, - const char *filename, unsigned lineno, - jsval *rval, JSVersion version); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleValue rval); -namespace JS { +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const jschar *chars, size_t length, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *bytes, size_t length, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length); extern JS_PUBLIC_API(bool) -Evaluate(JSContext *cx, JS::Handle obj, const ReadOnlyCompileOptions &options, - const char *filename, jsval *rval); +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename); } /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunction(JSContext *cx, JS::HandleObject obj, JS::HandleFunction fun, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunctionName(JSContext *cx, JS::HandleObject obj, const char *name, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); extern JS_PUBLIC_API(bool) -JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunctionValue(JSContext *cx, JS::HandleObject obj, JS::HandleValue fval, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); namespace JS { static inline bool -Call(JSContext *cx, JSObject *thisObj, JSFunction *fun, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleFunction fun, + const JS::HandleValueArray &args, MutableHandleValue rval) { - return !!JS_CallFunction(cx, thisObj, fun, argc, argv, rval.address()); + return !!JS_CallFunction(cx, thisObj, fun, args, rval); } static inline bool -Call(JSContext *cx, JSObject *thisObj, const char *name, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, const char *name, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return !!JS_CallFunctionName(cx, thisObj, name, argc, argv, rval.address()); + return !!JS_CallFunctionName(cx, thisObj, name, args, rval); } static inline bool -Call(JSContext *cx, JSObject *thisObj, jsval fun, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return !!JS_CallFunctionValue(cx, thisObj, fun, argc, argv, rval.address()); + return !!JS_CallFunctionValue(cx, thisObj, fun, args, rval); } extern JS_PUBLIC_API(bool) -Call(JSContext *cx, jsval thisv, jsval fun, unsigned argc, jsval *argv, MutableHandle rval); +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval); static inline bool -Call(JSContext *cx, jsval thisv, JSObject *funObj, unsigned argc, jsval *argv, - MutableHandle rval) +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleObject funObj, const JS::HandleValueArray& args, + MutableHandleValue rval) { - return Call(cx, thisv, OBJECT_TO_JSVAL(funObj), argc, argv, rval); + JS_ASSERT(funObj); + JS::RootedValue fun(cx, JS::ObjectValue(*funObj)); + return Call(cx, thisv, fun, args, rval); } +extern JS_PUBLIC_API(bool) +Construct(JSContext *cx, JS::HandleValue fun, + const JS::HandleValueArray& args, + MutableHandleValue rval); + } /* namespace JS */ /* - * These functions allow setting an operation callback that will be called + * These functions allow setting an interrupt callback that will be called * from the JS thread some time after any thread triggered the callback using - * JS_TriggerOperationCallback(rt). + * JS_RequestInterruptCallback(rt). * * To schedule the GC and for other activities the engine internally triggers - * operation callbacks. The embedding should thus not rely on callbacks being + * interrupt callbacks. The embedding should thus not rely on callbacks being * triggered through the external API only. * * Important note: Additional callbacks can occur inside the callback handler * if it re-enters the JS engine. The embedding must ensure that the callback * is disconnected before attempting such re-entry. */ -extern JS_PUBLIC_API(JSOperationCallback) -JS_SetOperationCallback(JSRuntime *rt, JSOperationCallback callback); +extern JS_PUBLIC_API(JSInterruptCallback) +JS_SetInterruptCallback(JSRuntime *rt, JSInterruptCallback callback); -extern JS_PUBLIC_API(JSOperationCallback) -JS_GetOperationCallback(JSRuntime *rt); +extern JS_PUBLIC_API(JSInterruptCallback) +JS_GetInterruptCallback(JSRuntime *rt); extern JS_PUBLIC_API(void) -JS_TriggerOperationCallback(JSRuntime *rt); +JS_RequestInterruptCallback(JSRuntime *rt); extern JS_PUBLIC_API(bool) JS_IsRunning(JSContext *cx); @@ -3878,7 +4084,7 @@ JS_RestoreFrameChain(JSContext *cx); #ifdef MOZ_TRACE_JSCALLS /* * The callback is expected to be quick and noninvasive. It should not - * trigger interrupts, turn on debugging, or produce uncaught JS + * request interrupts, turn on debugging, or produce uncaught JS * exceptions. The state of the stack and registers in the context * cannot be relied upon, since this callback may be invoked directly * from either JIT. The 'entering' field means we are entering a @@ -3953,15 +4159,16 @@ JS_FileEscapedString(FILE *fp, JSString *str, char quote); * special cases where getting the chars is infallible: * * The first case is interned strings, i.e., strings from JS_InternString or - * JSID_TO_STRING(id), using JS_GetInternedStringChars*. + * JSID_TO_STRING(id), using JS_GetLatin1InternedStringChars or + * JS_GetTwoByteInternedStringChars. * * The second case is "flat" strings that have been explicitly prepared in a * fallible context by JS_FlattenString. To catch errors, a separate opaque * JSFlatString type is returned by JS_FlattenString and expected by * JS_GetFlatStringChars. Note, though, that this is purely a syntactic * distinction: the input and output of JS_FlattenString are the same actual - * GC-thing so only one needs to be rooted. If a JSString is known to be flat, - * JS_ASSERT_STRING_IS_FLAT can be used to make a debug-checked cast. Example: + * GC-thing. If a JSString is known to be flat, JS_ASSERT_STRING_IS_FLAT can be + * used to make a debug-checked cast. Example: * * // in a fallible context * JSFlatString *fstr = JS_FlattenString(cx, str); @@ -3970,55 +4177,80 @@ JS_FileEscapedString(FILE *fp, JSString *str, char quote); * JS_ASSERT(fstr == JS_ASSERT_STRING_IS_FLAT(str)); * * // in an infallible context, for the same 'str' - * const jschar *chars = JS_GetFlatStringChars(fstr) + * AutoCheckCannotGC nogc; + * const jschar *chars = JS_GetTwoByteFlatStringChars(nogc, fstr) * JS_ASSERT(chars); * - * The CharsZ APIs guarantee that the returned array has a null character at - * chars[length]. This can require additional copying so clients should prefer - * APIs without CharsZ if possible. The infallible functions also return - * null-terminated arrays. (There is no additional cost or non-Z alternative - * for the infallible functions, so 'Z' is left out of the identifier.) + * Flat strings and interned strings are always null-terminated, so + * JS_FlattenString can be used to get a null-terminated string. + * + * Additionally, string characters are stored as either Latin1Char (8-bit) + * or jschar (16-bit). Clients can use JS_StringHasLatin1Chars and can then + * call either the Latin1* or TwoByte* functions. Some functions like + * JS_CopyStringChars and JS_GetStringCharAt accept both Latin1 and TwoByte + * strings. */ extern JS_PUBLIC_API(size_t) JS_GetStringLength(JSString *str); -extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsAndLength(JSContext *cx, JSString *str, size_t *length); +extern JS_PUBLIC_API(bool) +JS_StringIsFlat(JSString *str); -extern JS_PUBLIC_API(const jschar *) -JS_GetInternedStringChars(JSString *str); +/* Returns true iff the string's characters are stored as Latin1. */ +extern JS_PUBLIC_API(bool) +JS_StringHasLatin1Chars(JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1StringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); extern JS_PUBLIC_API(const jschar *) -JS_GetInternedStringCharsAndLength(JSString *str, size_t *length); +JS_GetTwoByteStringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); + +extern JS_PUBLIC_API(bool) +JS_GetStringCharAt(JSContext *cx, JSString *str, size_t index, jschar *res); + +extern JS_PUBLIC_API(jschar) +JS_GetFlatStringCharAt(JSFlatString *str, size_t index); extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsZ(JSContext *cx, JSString *str); +JS_GetTwoByteExternalStringChars(JSString *str); + +extern JS_PUBLIC_API(bool) +JS_CopyStringChars(JSContext *cx, mozilla::Range dest, JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1InternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); extern JS_PUBLIC_API(const jschar *) -JS_GetStringCharsZAndLength(JSContext *cx, JSString *str, size_t *length); +JS_GetTwoByteInternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); extern JS_PUBLIC_API(JSFlatString *) JS_FlattenString(JSContext *cx, JSString *str); +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1FlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); + extern JS_PUBLIC_API(const jschar *) -JS_GetFlatStringChars(JSFlatString *str); +JS_GetTwoByteFlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); -static JS_ALWAYS_INLINE JSFlatString * +static MOZ_ALWAYS_INLINE JSFlatString * JSID_TO_FLAT_STRING(jsid id) { JS_ASSERT(JSID_IS_STRING(id)); return (JSFlatString *)(JSID_BITS(id)); } -static JS_ALWAYS_INLINE JSFlatString * +static MOZ_ALWAYS_INLINE JSFlatString * JS_ASSERT_STRING_IS_FLAT(JSString *str) { - JS_ASSERT(JS_GetFlatStringChars((JSFlatString *)str)); + JS_ASSERT(JS_StringIsFlat(str)); return (JSFlatString *)str; } -static JS_ALWAYS_INLINE JSString * +static MOZ_ALWAYS_INLINE JSString * JS_FORGET_STRING_FLATNESS(JSFlatString *fstr) { return (JSString *)fstr; @@ -4078,7 +4310,7 @@ JS_EncodeString(JSContext *cx, JSString *str); * Same behavior as JS_EncodeString(), but encode into UTF-8 string */ JS_PUBLIC_API(char *) -JS_EncodeStringToUTF8(JSContext *cx, JSString *str); +JS_EncodeStringToUTF8(JSContext *cx, JS::HandleString str); /* * Get number of bytes in the string encoding (without accounting for a @@ -4110,7 +4342,7 @@ class JSAutoByteString MOZ_GUARD_OBJECT_NOTIFIER_INIT; } - JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + explicit JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) : mBytes(nullptr) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; @@ -4135,7 +4367,7 @@ class JSAutoByteString char *encodeLatin1(js::ExclusiveContext *cx, JSString *str); - char *encodeUtf8(JSContext *cx, JSString *str) { + char *encodeUtf8(JSContext *cx, JS::HandleString str) { JS_ASSERT(!mBytes); JS_ASSERT(cx); mBytes = JS_EncodeStringToUTF8(cx, str); @@ -4170,6 +4402,84 @@ class JSAutoByteString JSAutoByteString &operator=(const JSAutoByteString &another); }; +namespace JS { + +extern JS_PUBLIC_API(JSAddonId *) +NewAddonId(JSContext *cx, JS::HandleString str); + +extern JS_PUBLIC_API(JSString *) +StringOfAddonId(JSAddonId *id); + +extern JS_PUBLIC_API(JSAddonId *) +AddonIdOfObject(JSObject *obj); + +} // namespace JS + +/************************************************************************/ +/* + * Symbols + */ + +namespace JS { + +/* + * Create a new Symbol with the given description. This function never returns + * a Symbol that is in the Runtime-wide symbol registry. + * + * If description is null, the new Symbol's [[Description]] attribute is + * undefined. + */ +JS_PUBLIC_API(Symbol *) +NewSymbol(JSContext *cx, HandleString description); + +/* + * Symbol.for as specified in ES6. + * + * Get a Symbol with the description 'key' from the Runtime-wide symbol registry. + * If there is not already a Symbol with that description in the registry, a new + * Symbol is created and registered. 'key' must not be null. + */ +JS_PUBLIC_API(Symbol *) +GetSymbolFor(JSContext *cx, HandleString key); + +/* + * Get the [[Description]] attribute of the given symbol. + * + * This function is infallible. If it returns null, that means the symbol's + * [[Description]] is undefined. + */ +JS_PUBLIC_API(JSString *) +GetSymbolDescription(HandleSymbol symbol); + +/* Well-known symbols. */ +MOZ_BEGIN_ENUM_CLASS(SymbolCode, uint32_t) + iterator, // well-known Symbol.iterator + InSymbolRegistry = 0xfffffffe, // created by Symbol.for() or JS::GetSymbolFor() + UniqueSymbol = 0xffffffff // created by Symbol() or JS::NewSymbol() +MOZ_END_ENUM_CLASS(SymbolCode) + +/* For use in loops that iterate over the well-known symbols. */ +const size_t WellKnownSymbolLimit = 1; + +/* + * Return the SymbolCode telling what sort of symbol `symbol` is. + * + * A symbol's SymbolCode never changes once it is created. + */ +JS_PUBLIC_API(SymbolCode) +GetSymbolCode(Handle symbol); + +/* + * Get one of the well-known symbols defined by ES6. A single set of well-known + * symbols is shared by all compartments in a JSRuntime. + * + * `which` must be in the range [0, WellKnownSymbolLimit). + */ +JS_PUBLIC_API(Symbol *) +GetWellKnownSymbol(JSContext *cx, SymbolCode which); + +} /* namespace JS */ + /************************************************************************/ /* * JSON functions @@ -4189,10 +4499,17 @@ JS_Stringify(JSContext *cx, JS::MutableHandleValue value, JS::HandleObject repla JS_PUBLIC_API(bool) JS_ParseJSON(JSContext *cx, const jschar *chars, uint32_t len, JS::MutableHandleValue vp); +JS_PUBLIC_API(bool) +JS_ParseJSON(JSContext *cx, JS::HandleString str, JS::MutableHandleValue vp); + JS_PUBLIC_API(bool) JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32_t len, JS::HandleValue reviver, JS::MutableHandleValue vp); +JS_PUBLIC_API(bool) +JS_ParseJSONWithReviver(JSContext *cx, JS::HandleString str, JS::HandleValue reviver, + JS::MutableHandleValue vp); + /************************************************************************/ /* @@ -4219,7 +4536,6 @@ struct JSLocaleCallbacks { JSLocaleToLowerCase localeToLowerCase; JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API JSLocaleToUnicode localeToUnicode; - JSErrorCallback localeGetErrorMessage; }; /* @@ -4357,8 +4673,35 @@ JS_GetErrorReporter(JSContext *cx); extern JS_PUBLIC_API(JSErrorReporter) JS_SetErrorReporter(JSContext *cx, JSErrorReporter er); +namespace JS { + +extern JS_PUBLIC_API(bool) +CreateError(JSContext *cx, JSExnType type, HandleString stack, + HandleString fileName, uint32_t lineNumber, uint32_t columnNumber, + JSErrorReport *report, HandleString message, MutableHandleValue rval); + /************************************************************************/ +/* + * Weak Maps. + */ + +extern JS_PUBLIC_API(JSObject *) +NewWeakMapObject(JSContext *cx); + +extern JS_PUBLIC_API(bool) +IsWeakMapObject(JSObject *obj); + +extern JS_PUBLIC_API(bool) +GetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::MutableHandleValue val); + +extern JS_PUBLIC_API(bool) +SetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::HandleValue val); + +} /* namespace JS */ + /* * Dates. */ @@ -4387,10 +4730,10 @@ JS_ClearDateCaches(JSContext *cx); /* * Regular Expressions. */ -#define JSREG_FOLD 0x01 /* fold uppercase to lowercase */ -#define JSREG_GLOB 0x02 /* global exec, creates array of matches */ -#define JSREG_MULTILINE 0x04 /* treat ^ and $ as begin and end of line */ -#define JSREG_STICKY 0x08 /* only match starting at lastIndex */ +#define JSREG_FOLD 0x01u /* fold uppercase to lowercase */ +#define JSREG_GLOB 0x02u /* global exec, creates array of matches */ +#define JSREG_MULTILINE 0x04u /* treat ^ and $ as begin and end of line */ +#define JSREG_STICKY 0x08u /* only match starting at lastIndex */ extern JS_PUBLIC_API(JSObject *) JS_NewRegExpObject(JSContext *cx, JS::HandleObject obj, char *bytes, size_t length, @@ -4400,11 +4743,11 @@ extern JS_PUBLIC_API(JSObject *) JS_NewUCRegExpObject(JSContext *cx, JS::HandleObject obj, jschar *chars, size_t length, unsigned flags); -extern JS_PUBLIC_API(void) +extern JS_PUBLIC_API(bool) JS_SetRegExpInput(JSContext *cx, JS::HandleObject obj, JS::HandleString input, bool multiline); -extern JS_PUBLIC_API(void) +extern JS_PUBLIC_API(bool) JS_ClearRegExpStatics(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(bool) @@ -4450,17 +4793,62 @@ JS_ClearPendingException(JSContext *cx); extern JS_PUBLIC_API(bool) JS_ReportPendingException(JSContext *cx); +namespace JS { + /* - * Save the current exception state. This takes a snapshot of cx's current - * exception state without making any change to that state. + * Save and later restore the current exception state of a given JSContext. + * This is useful for implementing behavior in C++ that's like try/catch + * or try/finally in JS. * - * The returned state pointer MUST be passed later to JS_RestoreExceptionState - * (to restore that saved state, overriding any more recent state) or else to - * JS_DropExceptionState (to free the state struct in case it is not correct - * or desirable to restore it). Both Restore and Drop free the state struct, - * so callers must stop using the pointer returned from Save after calling the - * Release or Drop API. + * Typical usage: + * + * bool ok = JS_EvaluateScript(cx, ...); + * AutoSaveExceptionState savedExc(cx); + * ... cleanup that might re-enter JS ... + * return ok; */ +class JS_PUBLIC_API(AutoSaveExceptionState) +{ + private: + JSContext *context; + bool wasPropagatingForcedReturn; + bool wasThrowing; + RootedValue exceptionValue; + + public: + /* + * Take a snapshot of cx's current exception state. Then clear any current + * pending exception in cx. + */ + explicit AutoSaveExceptionState(JSContext *cx); + + /* + * If neither drop() nor restore() was called, restore the exception + * state only if no exception is currently pending on cx. + */ + ~AutoSaveExceptionState(); + + /* + * Discard any stored exception state. + * If this is called, the destructor is a no-op. + */ + void drop() { + wasPropagatingForcedReturn = false; + wasThrowing = false; + exceptionValue.setUndefined(); + } + + /* + * Replace cx's exception state with the stored exception state. Then + * discard the stored exception state. If this is called, the + * destructor is a no-op. + */ + void restore(); +}; + +} /* namespace JS */ + +/* Deprecated API. Use AutoSaveExceptionState instead. */ extern JS_PUBLIC_API(JSExceptionState *) JS_SaveExceptionState(JSContext *cx); @@ -4471,22 +4859,14 @@ extern JS_PUBLIC_API(void) JS_DropExceptionState(JSContext *cx, JSExceptionState *state); /* - * If the given value is an exception object that originated from an error, - * the exception will contain an error report struct, and this API will return - * the address of that struct. Otherwise, it returns nullptr. The lifetime + * If the given object is an exception object, the exception will have (or be + * able to lazily create) an error report struct, and this function will return + * the address of that struct. Otherwise, it returns nullptr. The lifetime * of the error report struct that might be returned is the same as the * lifetime of the exception object. */ extern JS_PUBLIC_API(JSErrorReport *) -JS_ErrorFromException(JSContext *cx, JS::HandleValue v); - -/* - * Given a reported error's message and JSErrorReport struct pointer, throw - * the corresponding exception on cx. - */ -extern JS_PUBLIC_API(bool) -JS_ThrowReportedError(JSContext *cx, const char *message, - JSErrorReport *reportp); +JS_ErrorFromException(JSContext *cx, JS::HandleObject obj); /* * Throws a StopIteration exception on cx. @@ -4521,7 +4901,7 @@ JS_AbortIfWrongThread(JSRuntime *rt); * [[Prototype]]. */ extern JS_PUBLIC_API(JSObject *) -JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const jsval *vp); +JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const JS::CallArgs& args); /************************************************************************/ @@ -4536,16 +4916,18 @@ JS_ScheduleGC(JSContext *cx, uint32_t count); #endif extern JS_PUBLIC_API(void) -JS_SetParallelParsingEnabled(JSContext *cx, bool enabled); +JS_SetParallelParsingEnabled(JSRuntime *rt, bool enabled); extern JS_PUBLIC_API(void) -JS_SetParallelIonCompilationEnabled(JSContext *cx, bool enabled); +JS_SetOffthreadIonCompilationEnabled(JSRuntime *rt, bool enabled); -#define JIT_COMPILER_OPTIONS(Register) \ - Register(BASELINE_USECOUNT_TRIGGER, "baseline.usecount.trigger") \ - Register(ION_USECOUNT_TRIGGER, "ion.usecount.trigger") \ - Register(ION_ENABLE, "ion.enable") \ - Register(BASELINE_ENABLE, "baseline.enable") +#define JIT_COMPILER_OPTIONS(Register) \ + Register(BASELINE_USECOUNT_TRIGGER, "baseline.usecount.trigger") \ + Register(ION_USECOUNT_TRIGGER, "ion.usecount.trigger") \ + Register(ION_ENABLE, "ion.enable") \ + Register(BASELINE_ENABLE, "baseline.enable") \ + Register(OFFTHREAD_COMPILATION_ENABLE, "offthread-compilation.enable") \ + Register(SIGNALS_ENABLE, "signals.enable") typedef enum JSJitCompilerOption { #define JIT_COMPILER_DECLARE(key, str) \ @@ -4558,7 +4940,9 @@ typedef enum JSJitCompilerOption { } JSJitCompilerOption; extern JS_PUBLIC_API(void) -JS_SetGlobalJitCompilerOption(JSContext *cx, JSJitCompilerOption opt, uint32_t value); +JS_SetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt, uint32_t value); +extern JS_PUBLIC_API(int) +JS_GetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt); /* * Convert a uint32_t index into a jsid. @@ -4580,13 +4964,80 @@ JS_CharsToId(JSContext* cx, JS::TwoByteChars chars, JS::MutableHandleId); extern JS_PUBLIC_API(bool) JS_IsIdentifier(JSContext *cx, JS::HandleString str, bool *isIdentifier); +namespace JS { + +/* + * AutoFilename encapsulates a pointer to a C-string and keeps the C-string + * alive for as long as the associated AutoFilename object is alive. + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(AutoFilename) +{ + void *scriptSource_; + + AutoFilename(const AutoFilename &) MOZ_DELETE; + void operator=(const AutoFilename &) MOZ_DELETE; + + public: + AutoFilename() : scriptSource_(nullptr) {} + ~AutoFilename() { reset(nullptr); } + + const char *get() const; + + void reset(void *newScriptSource); +}; + /* - * Return the current script and line number of the most currently running + * Return the current filename and line number of the most currently running * frame. Returns true if a scripted frame was found, false otherwise. + * + * If a the embedding has hidden the scripted caller for the topmost activation + * record, this will also return false. */ extern JS_PUBLIC_API(bool) -JS_DescribeScriptedCaller(JSContext *cx, JS::MutableHandleScript script, unsigned *lineno); +DescribeScriptedCaller(JSContext *cx, AutoFilename *filename = nullptr, + unsigned *lineno = nullptr); +extern JS_PUBLIC_API(JSObject *) +GetScriptedCallerGlobal(JSContext *cx); + +/* + * Informs the JS engine that the scripted caller should be hidden. This can be + * used by the embedding to maintain an override of the scripted caller in its + * calculations, by hiding the scripted caller in the JS engine and pushing data + * onto a separate stack, which it inspects when DescribeScriptedCaller returns + * null. + * + * We maintain a counter on each activation record. Add() increments the counter + * of the topmost activation, and Remove() decrements it. The count may never + * drop below zero, and must always be exactly zero when the activation is + * popped from the stack. + */ +extern JS_PUBLIC_API(void) +HideScriptedCaller(JSContext *cx); + +extern JS_PUBLIC_API(void) +UnhideScriptedCaller(JSContext *cx); + +class AutoHideScriptedCaller +{ + public: + explicit AutoHideScriptedCaller(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mContext(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + HideScriptedCaller(mContext); + } + ~AutoHideScriptedCaller() { + UnhideScriptedCaller(mContext); + } + + protected: + JSContext *mContext; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +} /* namespace JS */ /* * Encode/Decode interpreted scripts and functions to/from memory. @@ -4599,12 +5050,11 @@ extern JS_PUBLIC_API(void *) JS_EncodeInterpretedFunction(JSContext *cx, JS::HandleObject funobj, uint32_t *lengthp); extern JS_PUBLIC_API(JSScript *) -JS_DecodeScript(JSContext *cx, const void *data, uint32_t length, - JSPrincipals *principals, JSPrincipals *originPrincipals); +JS_DecodeScript(JSContext *cx, const void *data, uint32_t length, JSPrincipals *originPrincipals); extern JS_PUBLIC_API(JSObject *) JS_DecodeInterpretedFunction(JSContext *cx, const void *data, uint32_t length, - JSPrincipals *principals, JSPrincipals *originPrincipals); + JSPrincipals *originPrincipals); namespace JS { @@ -4621,8 +5071,7 @@ typedef bool (* OpenAsmJSCacheEntryForReadOp)(HandleObject global, const jschar *begin, const jschar *limit, size_t *size, const uint8_t **memory, intptr_t *handle); typedef void -(* CloseAsmJSCacheEntryForReadOp)(HandleObject global, size_t size, const uint8_t *memory, - intptr_t handle); +(* CloseAsmJSCacheEntryForReadOp)(size_t size, const uint8_t *memory, intptr_t handle); /* * This callback represents a request by the JS engine to open for writing a @@ -4632,21 +5081,30 @@ typedef void * outparams. If the callback returns 'true', the JS engine guarantees a call * to CloseAsmJSCacheEntryForWriteOp passing the same base address, size and * handle. + * + * If 'installed' is true, then the cache entry is associated with a permanently + * installed JS file (e.g., in a packaged webapp). This information allows the + * embedding to store the cache entry in a installed location associated with + * the principal of 'global' where it will not be evicted until the associated + * installed JS file is removed. */ typedef bool -(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, const jschar *begin, const jschar *end, +(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, bool installed, + const jschar *begin, const jschar *end, size_t size, uint8_t **memory, intptr_t *handle); typedef void -(* CloseAsmJSCacheEntryForWriteOp)(HandleObject global, size_t size, uint8_t *memory, - intptr_t handle); +(* CloseAsmJSCacheEntryForWriteOp)(size_t size, uint8_t *memory, intptr_t handle); + +typedef js::Vector BuildIdCharVector; // Return the buildId (represented as a sequence of characters) associated with // the currently-executing build. If the JS engine is embedded such that a // single cache entry can be observed by different compiled versions of the JS // engine, it is critical that the buildId shall change for each new build of // the JS engine. + typedef bool -(* BuildIdOp)(js::Vector *buildId); +(* BuildIdOp)(BuildIdCharVector *buildId); struct AsmJSCacheOps { @@ -4660,6 +5118,132 @@ struct AsmJSCacheOps extern JS_PUBLIC_API(void) SetAsmJSCacheOps(JSRuntime *rt, const AsmJSCacheOps *callbacks); +/* + * Convenience class for imitating a JS level for-of loop. Typical usage: + * + * ForOfIterator it(cx); + * if (!it.init(iterable)) + * return false; + * RootedValue val(cx); + * while (true) { + * bool done; + * if (!it.next(&val, &done)) + * return false; + * if (done) + * break; + * if (!DoStuff(cx, val)) + * return false; + * } + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(ForOfIterator) { + protected: + JSContext *cx_; + /* + * Use the ForOfPIC on the global object (see vm/GlobalObject.h) to try + * to optimize iteration across arrays. + * + * Case 1: Regular Iteration + * iterator - pointer to the iterator object. + * index - fixed to NOT_ARRAY (== UINT32_MAX) + * + * Case 2: Optimized Array Iteration + * iterator - pointer to the array object. + * index - current position in array. + * + * The cases are distinguished by whether or not |index| is equal to NOT_ARRAY. + */ + JS::RootedObject iterator; + uint32_t index; + + static const uint32_t NOT_ARRAY = UINT32_MAX; + + ForOfIterator(const ForOfIterator &) MOZ_DELETE; + ForOfIterator &operator=(const ForOfIterator &) MOZ_DELETE; + + public: + explicit ForOfIterator(JSContext *cx) : cx_(cx), iterator(cx_), index(NOT_ARRAY) { } + + enum NonIterableBehavior { + ThrowOnNonIterable, + AllowNonIterable + }; + + /* + * Initialize the iterator. If AllowNonIterable is passed then if iterable + * does not have a callable @@iterator init() will just return true instead + * of throwing. Callers should then check valueIsIterable() before + * continuing with the iteration. + */ + bool init(JS::HandleValue iterable, + NonIterableBehavior nonIterableBehavior = ThrowOnNonIterable); + + /* + * This method assumes that |iterator| is already an iterator. It will not + * check for, and call @@iterator. Callers should make sure that the passed + * in value is in fact an iterator. + */ + bool initWithIterator(JS::HandleValue aIterator); + + /* + * Get the next value from the iterator. If false *done is true + * after this call, do not examine val. + */ + bool next(JS::MutableHandleValue val, bool *done); + + /* + * If initialized with throwOnNonCallable = false, check whether + * the value is iterable. + */ + bool valueIsIterable() const { + return iterator; + } + + private: + inline bool nextFromOptimizedArray(MutableHandleValue val, bool *done); + bool materializeArrayIterator(); +}; + + +/* + * If a large allocation fails, the JS engine may call the large-allocation- + * failure callback, if set, to allow the embedding to flush caches, possibly + * perform shrinking GCs, etc. to make some room so that the allocation will + * succeed if retried. After the callback returns, the JS engine will try to + * allocate again and may be succesful. + */ + +typedef void +(* LargeAllocationFailureCallback)(void *data); + +extern JS_PUBLIC_API(void) +SetLargeAllocationFailureCallback(JSRuntime *rt, LargeAllocationFailureCallback afc, void *data); + +/* + * Unlike the error reporter, which is only called if the exception for an OOM + * bubbles up and is not caught, the OutOfMemoryCallback is called immediately + * at the OOM site to allow the embedding to capture the current state of heap + * allocation before anything is freed. If the large-allocation-failure callback + * is called at all (not all allocation sites call the large-allocation-failure + * callback on failure), it is called before the out-of-memory callback; the + * out-of-memory callback is only called if the allocation still fails after the + * large-allocation-failure callback has returned. + */ + +typedef void +(* OutOfMemoryCallback)(JSContext *cx, void *data); + +extern JS_PUBLIC_API(void) +SetOutOfMemoryCallback(JSRuntime *rt, OutOfMemoryCallback cb, void *data); + + +/* + * Capture the current call stack as a chain of SavedFrame objects, and set + * |stackp| to the SavedFrame for the newest stack frame. If |maxFrameCount| is + * non-zero, capture at most the youngest |maxFrameCount| frames. + */ +extern JS_PUBLIC_API(bool) +CaptureCurrentStack(JSContext *cx, MutableHandleObject stackp, unsigned maxFrameCount = 0); + } /* namespace JS */ #endif /* jsapi_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/jscpucfg.h b/frameworks/js-bindings/external/spidermonkey/include/win32/jscpucfg.h index e545d8329d..a7a00613bb 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/jscpucfg.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/jscpucfg.h @@ -18,7 +18,7 @@ # error "CPU type is unknown" # endif /* !(defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)) */ -#elif defined(_WIN32) || defined(XP_OS2) +#elif defined(_WIN32) # ifdef __WATCOMC__ # define HAVE_VA_LIST_AS_ARRAY 1 @@ -27,7 +27,7 @@ # define IS_LITTLE_ENDIAN 1 # undef IS_BIG_ENDIAN -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) # if __LITTLE_ENDIAN__ # define IS_LITTLE_ENDIAN 1 # undef IS_BIG_ENDIAN @@ -89,8 +89,7 @@ # endif #elif defined(__sparc) || defined(__sparc__) || \ - defined(_POWER) || defined(__powerpc__) || \ - defined(__ppc__) || defined(__hppa) || \ + defined(_POWER) || defined(__hppa) || \ defined(_MIPSEB) || defined(_BIG_ENDIAN) /* IA64 running HP-UX will have _BIG_ENDIAN defined. * IA64 running Linux will have endian.h and be handled above. diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/jsfriendapi.h b/frameworks/js-bindings/external/spidermonkey/include/win32/jsfriendapi.h index eb05652a5b..674999eb62 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/jsfriendapi.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/jsfriendapi.h @@ -7,8 +7,12 @@ #ifndef jsfriendapi_h #define jsfriendapi_h +#include "mozilla/Casting.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/TypedEnum.h" +#include "mozilla/UniquePtr.h" +#include "jsapi.h" // For JSAutoByteString. See bug 1033916. #include "jsbytecode.h" #include "jspubtd.h" @@ -19,14 +23,20 @@ /* * This macro checks if the stack pointer has exceeded a given limit. If * |tolerance| is non-zero, it returns true only if the stack pointer has - * exceeded the limit by more than |tolerance| bytes. + * exceeded the limit by more than |tolerance| bytes. The WITH_INTOLERANCE + * versions use a negative tolerance (i.e., the limit is reduced by + * |intolerance| bytes). */ #if JS_STACK_GROWTH_DIRECTION > 0 # define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ ((uintptr_t)(sp) < (limit)+(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) < (limit)-(intolerance)) #else # define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ ((uintptr_t)(sp) > (limit)-(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) > (limit)+(intolerance)) #endif #define JS_CHECK_STACK_SIZE(limit, lval) JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, lval, 0) @@ -35,33 +45,35 @@ class JSAtom; struct JSErrorFormatString; class JSLinearString; struct JSJitInfo; -class JSErrorReport; +struct JSErrorReport; namespace JS { template class Heap; } /* namespace JS */ +namespace js { +class JS_FRIEND_API(BaseProxyHandler); +} /* namespace js */ + extern JS_FRIEND_API(void) JS_SetGrayGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); extern JS_FRIEND_API(JSString *) JS_GetAnonymousString(JSRuntime *rt); -extern JS_FRIEND_API(void) -JS_SetIsWorkerRuntime(JSRuntime *rt); - extern JS_FRIEND_API(JSObject *) -JS_FindCompilationScope(JSContext *cx, JSObject *obj); +JS_FindCompilationScope(JSContext *cx, JS::HandleObject obj); extern JS_FRIEND_API(JSFunction *) JS_GetObjectFunction(JSObject *obj); extern JS_FRIEND_API(bool) -JS_SplicePrototype(JSContext *cx, JSObject *obj, JSObject *proto); +JS_SplicePrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); extern JS_FRIEND_API(JSObject *) -JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JSObject *proto, JSObject *parent); +JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JS::HandleObject proto, + JS::HandleObject parent); extern JS_FRIEND_API(uint32_t) JS_ObjectCountDynamicSlots(JS::HandleObject obj); @@ -73,7 +85,7 @@ extern JS_FRIEND_API(size_t) JS_GetCustomIteratorCount(JSContext *cx); extern JS_FRIEND_API(bool) -JS_NondeterministicGetWeakMapKeys(JSContext *cx, JSObject *obj, JSObject **ret); +JS_NondeterministicGetWeakMapKeys(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject ret); /* * Determine whether the given object is backed by a DeadObjectProxy. @@ -122,16 +134,23 @@ JS_GetCompartmentPrincipals(JSCompartment *compartment); extern JS_FRIEND_API(void) JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals); +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptPrincipals(JSScript *script); + +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptOriginPrincipals(JSScript *script); + /* Safe to call with input obj == nullptr. Returns non-nullptr iff obj != nullptr. */ extern JS_FRIEND_API(JSObject *) -JS_ObjectToInnerObject(JSContext *cx, JSObject *obj); +JS_ObjectToInnerObject(JSContext *cx, JS::HandleObject obj); /* Requires obj != nullptr. */ extern JS_FRIEND_API(JSObject *) -JS_ObjectToOuterObject(JSContext *cx, JSObject *obj); +JS_ObjectToOuterObject(JSContext *cx, JS::HandleObject obj); extern JS_FRIEND_API(JSObject *) -JS_CloneObject(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent); +JS_CloneObject(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto, + JS::HandleObject parent); extern JS_FRIEND_API(JSString *) JS_BasicObjectToString(JSContext *cx, JS::HandleObject obj); @@ -149,13 +168,17 @@ js_ObjectClassIs(JSContext *cx, JS::HandleObject obj, js::ESClassValue classValu JS_FRIEND_API(const char *) js_ObjectClassName(JSContext *cx, JS::HandleObject obj); +namespace js { + JS_FRIEND_API(bool) -js_AddObjectRoot(JSRuntime *rt, JSObject **objp); +AddRawValueRoot(JSContext *cx, JS::Value *vp, const char *name); JS_FRIEND_API(void) -js_RemoveObjectRoot(JSRuntime *rt, JSObject **objp); +RemoveRawValueRoot(JSContext *cx, JS::Value *vp); -#ifdef DEBUG +} /* namespace js */ + +#ifdef JS_DEBUG /* * Routines to print out values during debugging. These are FRIEND_API to help @@ -184,7 +207,7 @@ js_DumpChars(const jschar *s, size_t n); * restrictions on the compartment of |cx|. */ extern JS_FRIEND_API(bool) -JS_CopyPropertiesFrom(JSContext *cx, JSObject *target, JSObject *obj); +JS_CopyPropertiesFrom(JSContext *cx, JS::HandleObject target, JS::HandleObject obj); /* * Single-property version of the above. This function asserts that an |own| @@ -221,20 +244,164 @@ struct JSFunctionSpecWithHelp { {nullptr, nullptr, 0, 0, nullptr, nullptr} extern JS_FRIEND_API(bool) -JS_DefineFunctionsWithHelp(JSContext *cx, JSObject *obj, const JSFunctionSpecWithHelp *fs); +JS_DefineFunctionsWithHelp(JSContext *cx, JS::HandleObject obj, const JSFunctionSpecWithHelp *fs); namespace js { +/* + * Helper Macros for creating JSClasses that function as proxies. + * + * NB: The macro invocation must be surrounded by braces, so as to + * allow for potention JSClass extensions. + */ +#define PROXY_MAKE_EXT(outerObject, innerObject, iteratorObject, \ + isWrappedNative) \ + { \ + outerObject, \ + innerObject, \ + iteratorObject, \ + isWrappedNative, \ + js::proxy_WeakmapKeyDelegate \ + } + +#define PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, ext) \ + { \ + name, \ + js::Class::NON_NATIVE | \ + JSCLASS_IS_PROXY | \ + JSCLASS_IMPLEMENTS_BARRIERS | \ + JSCLASS_HAS_RESERVED_SLOTS(js::PROXY_MINIMUM_SLOTS + (extraSlots)) | \ + flags, \ + JS_PropertyStub, /* addProperty */ \ + JS_DeletePropertyStub, /* delProperty */ \ + JS_PropertyStub, /* getProperty */ \ + JS_StrictPropertyStub, /* setProperty */ \ + JS_EnumerateStub, \ + JS_ResolveStub, \ + js::proxy_Convert, \ + js::proxy_Finalize, /* finalize */ \ + callOp, /* call */ \ + js::proxy_HasInstance, /* hasInstance */ \ + constructOp, /* construct */ \ + js::proxy_Trace, /* trace */ \ + JS_NULL_CLASS_SPEC, \ + ext, \ + { \ + js::proxy_LookupGeneric, \ + js::proxy_LookupProperty, \ + js::proxy_LookupElement, \ + js::proxy_DefineGeneric, \ + js::proxy_DefineProperty, \ + js::proxy_DefineElement, \ + js::proxy_GetGeneric, \ + js::proxy_GetProperty, \ + js::proxy_GetElement, \ + js::proxy_SetGeneric, \ + js::proxy_SetProperty, \ + js::proxy_SetElement, \ + js::proxy_GetGenericAttributes, \ + js::proxy_SetGenericAttributes, \ + js::proxy_DeleteGeneric, \ + js::proxy_Watch, js::proxy_Unwatch, \ + js::proxy_Slice, \ + nullptr, /* enumerate */ \ + nullptr, /* thisObject */ \ + } \ + } + +#define PROXY_CLASS_DEF(name, extraSlots, flags, callOp, constructOp) \ + PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, \ + PROXY_MAKE_EXT( \ + nullptr, /* outerObject */ \ + nullptr, /* innerObject */ \ + nullptr, /* iteratorObject */ \ + false /* isWrappedNative */ \ + )) + +/* + * Proxy stubs, similar to JS_*Stub, for embedder proxy class definitions. + * + * NB: Should not be called directly. + */ + +extern JS_FRIEND_API(bool) +proxy_LookupGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleObject objp, JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_DefineGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, + unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_GetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetProperty(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, + JS::Handle name, JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetElement(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_SetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp, + bool strict); +extern JS_FRIEND_API(bool) +proxy_GetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_SetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_DeleteGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); + +extern JS_FRIEND_API(void) +proxy_Trace(JSTracer *trc, JSObject *obj); +extern JS_FRIEND_API(JSObject *) +proxy_WeakmapKeyDelegate(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Convert(JSContext *cx, JS::HandleObject proxy, JSType hint, JS::MutableHandleValue vp); +extern JS_FRIEND_API(void) +proxy_Finalize(FreeOp *fop, JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_HasInstance(JSContext *cx, JS::HandleObject proxy, JS::MutableHandleValue v, bool *bp); +extern JS_FRIEND_API(bool) +proxy_Call(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(bool) +proxy_Construct(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(JSObject *) +proxy_innerObject(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Watch(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); +extern JS_FRIEND_API(bool) +proxy_Unwatch(JSContext *cx, JS::HandleObject obj, JS::HandleId id); +extern JS_FRIEND_API(bool) +proxy_Slice(JSContext *cx, JS::HandleObject proxy, uint32_t begin, uint32_t end, + JS::HandleObject result); + /* * A class of objects that return source code on demand. * - * When code is compiled with CompileOptions::LAZY_SOURCE, SpiderMonkey - * doesn't retain the source code (and doesn't do lazy bytecode - * generation). If we ever need the source code, say, in response to a call - * to Function.prototype.toSource or Debugger.Source.prototype.text, then - * we call the 'load' member function of the instance of this class that - * has hopefully been registered with the runtime, passing the code's URL, - * and hope that it will be able to find the source. + * When code is compiled with setSourceIsLazy(true), SpiderMonkey doesn't + * retain the source code (and doesn't do lazy bytecode generation). If we ever + * need the source code, say, in response to a call to Function.prototype. + * toSource or Debugger.Source.prototype.text, then we call the 'load' member + * function of the instance of this class that has hopefully been registered + * with the runtime, passing the code's URL, and hope that it will be able to + * find the source. */ class SourceHook { public: @@ -249,18 +416,25 @@ class SourceHook { }; /* - * Have |rt| use |hook| to retrieve LAZY_SOURCE source code. See the + * Have |rt| use |hook| to retrieve lazily-retrieved source code. See the * comments for SourceHook. The runtime takes ownership of the hook, and * will delete it when the runtime itself is deleted, or when a new hook is * set. */ extern JS_FRIEND_API(void) -SetSourceHook(JSRuntime *rt, SourceHook *hook); +SetSourceHook(JSRuntime *rt, mozilla::UniquePtr hook); /* Remove |rt|'s source hook, and return it. The caller now owns the hook. */ -extern JS_FRIEND_API(SourceHook *) +extern JS_FRIEND_API(mozilla::UniquePtr) ForgetSourceHook(JSRuntime *rt); +#ifdef NIGHTLY_BUILD +typedef void (*AssertOnScriptEntryHook)(JSContext *cx, JS::HandleScript script); + +extern JS_FRIEND_API(void) +SetAssertOnScriptEntryHook(JSRuntime *rt, AssertOnScriptEntryHook hook); +#endif + extern JS_FRIEND_API(JS::Zone *) GetCompartmentZone(JSCompartment *comp); @@ -293,16 +467,6 @@ IsSystemZone(JS::Zone *zone); extern JS_FRIEND_API(bool) IsAtomsCompartment(JSCompartment *comp); -/* - * Check whether it is OK to assign an undeclared variable with the name - * |propname| at the current location in script. It is not an error if there is - * no current script location, or if that location is not an assignment to an - * undeclared variable. Reports an error if one needs to be reported (and, - * particularly, always reports when it returns false). - */ -extern JS_FRIEND_API(bool) -ReportIfUndeclaredVarAssignment(JSContext *cx, JS::HandleString propname); - /* * Returns whether we're in a non-strict property set (in that we're in a * non-strict script and the bytecode we're on is a property set). The return @@ -339,6 +503,9 @@ TraceWeakMaps(WeakMapTracer *trc); extern JS_FRIEND_API(bool) AreGCGrayBitsValid(JSRuntime *rt); +extern JS_FRIEND_API(bool) +ZoneGlobalsAreAllGray(JS::Zone *zone); + typedef void (*GCThingCallback)(void *closure, void *gcthing); @@ -379,7 +546,7 @@ struct TypeObject { }; struct BaseShape { - const js::Class *clasp; + const js::Class *clasp_; JSObject *parent; JSObject *_1; JSCompartment *compartment; @@ -427,10 +594,20 @@ struct Function { void *_1; }; -struct Atom { - static const size_t LENGTH_SHIFT = 4; - size_t lengthAndFlags; - const jschar *chars; +struct String +{ + static const uint32_t INLINE_CHARS_BIT = JS_BIT(2); + static const uint32_t LATIN1_CHARS_BIT = JS_BIT(6); + static const uint32_t ROPE_FLAGS = 0; + static const uint32_t TYPE_FLAGS_MASK = JS_BIT(6) - 1; + uint32_t flags; + uint32_t length; + union { + const JS::Latin1Char *nonInlineCharsLatin1; + const jschar *nonInlineCharsTwoByte; + JS::Latin1Char inlineStorageLatin1[1]; + jschar inlineStorageTwoByte[1]; + }; }; } /* namespace shadow */ @@ -451,6 +628,46 @@ GetObjectJSClass(JSObject *obj) return js::Jsvalify(GetObjectClass(obj)); } +JS_FRIEND_API(const Class *) +ProtoKeyToClass(JSProtoKey key); + +// Returns true if the standard class identified by |key| inherits from +// another standard class with the same js::Class. This basically means +// that the various properties described by our js::Class are intended +// to live higher up on the proto chain. +// +// In practice, this only returns true for Error subtypes. +inline bool +StandardClassIsDependent(JSProtoKey key) +{ + JSProtoKey keyFromClass = JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + MOZ_ASSERT(keyFromClass); + return key != keyFromClass; +} + +// Returns the key for the class inherited by a given standard class (that +// is to say, the prototype of this standard class's prototype). +// +// You must be sure that this corresponds to a standard class with a cached +// JSProtoKey before calling this function. In general |key| will match the +// cached proto key, except in cases where multiple JSProtoKeys share a +// JSClass. +inline JSProtoKey +ParentKeyForStandardClass(JSProtoKey key) +{ + // [Object] has nothing to inherit from. + if (key == JSProto_Object) + return JSProto_Null; + + // If we're dependent (i.e. an Error subtype), return the key of the class + // we depend on. + if (StandardClassIsDependent(key)) + return JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + + // Otherwise, we inherit [Object]. + return JSProto_Object; +} + inline bool IsInnerObject(JSObject *obj) { return !!GetObjectClass(obj)->ext.outerObject; @@ -477,7 +694,7 @@ GetObjectParent(JSObject *obj) return reinterpret_cast(obj)->shape->base->parent; } -static JS_ALWAYS_INLINE JSCompartment * +static MOZ_ALWAYS_INLINE JSCompartment * GetObjectCompartment(JSObject *obj) { return reinterpret_cast(obj)->shape->base->compartment; @@ -489,10 +706,15 @@ GetObjectParentMaybeScope(JSObject *obj); JS_FRIEND_API(JSObject *) GetGlobalForObjectCrossCompartment(JSObject *obj); +// Sidestep the activeContext checking implicitly performed in +// JS_SetPendingException. +JS_FRIEND_API(void) +SetPendingExceptionCrossContext(JSContext *cx, JS::HandleValue v); + JS_FRIEND_API(void) AssertSameCompartment(JSContext *cx, JSObject *obj); -#ifdef DEBUG +#ifdef JS_DEBUG JS_FRIEND_API(void) AssertSameCompartment(JSObject *objA, JSObject *objB); #else @@ -509,9 +731,6 @@ SetDefaultObjectForContext(JSContext *cx, JSObject *obj); JS_FRIEND_API(void) NotifyAnimationActivity(JSObject *obj); -JS_FRIEND_API(bool) -IsOriginalScriptFunction(JSFunction *fun); - /* * Return the outermost enclosing function (script) of the scripted caller. * This function returns nullptr in several cases: @@ -521,7 +740,7 @@ IsOriginalScriptFunction(JSFunction *fun); * thus it will really return the outermost enclosing function *since the * innermost eval*. */ -JS_FRIEND_API(JSScript *) +JS_FRIEND_API(JSFunction *) GetOutermostEnclosingFunctionOfScriptedCaller(JSContext *cx); JS_FRIEND_API(JSFunction *) @@ -536,12 +755,6 @@ JS_FRIEND_API(JSFunction *) NewFunctionByIdWithReserved(JSContext *cx, JSNative native, unsigned nargs, unsigned flags, JSObject *parent, jsid id); -JS_FRIEND_API(JSObject *) -InitClassWithReserved(JSContext *cx, JSObject *obj, JSObject *parent_proto, - const JSClass *clasp, JSNative constructor, unsigned nargs, - const JSPropertySpec *ps, const JSFunctionSpec *fs, - const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs); - JS_FRIEND_API(const JS::Value &) GetFunctionNativeReserved(JSObject *fun, size_t which); @@ -549,7 +762,7 @@ JS_FRIEND_API(void) SetFunctionNativeReserved(JSObject *fun, size_t which, const JS::Value &val); JS_FRIEND_API(bool) -GetObjectProto(JSContext *cx, JS::Handle obj, JS::MutableHandle proto); +GetObjectProto(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject proto); JS_FRIEND_API(bool) GetOriginalEval(JSContext *cx, JS::HandleObject scope, @@ -604,25 +817,142 @@ GetObjectSlot(JSObject *obj, size_t slot) return reinterpret_cast(obj)->slotRef(slot); } -inline const jschar * -GetAtomChars(JSAtom *atom) +MOZ_ALWAYS_INLINE size_t +GetAtomLength(JSAtom *atom) { - return reinterpret_cast(atom)->chars; + return reinterpret_cast(atom)->length; } -inline size_t -GetAtomLength(JSAtom *atom) +static const uint32_t MaxStringLength = (1 << 28) - 1; + +MOZ_ALWAYS_INLINE size_t +GetStringLength(JSString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetFlatStringLength(JSFlatString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetLinearStringLength(JSLinearString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE bool +LinearStringHasLatin1Chars(JSLinearString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE bool +AtomHasLatin1Chars(JSAtom *atom) { - using shadow::Atom; - return reinterpret_cast(atom)->lengthAndFlags >> Atom::LENGTH_SHIFT; + return reinterpret_cast(atom)->flags & shadow::String::LATIN1_CHARS_BIT; } -inline JSLinearString * +MOZ_ALWAYS_INLINE bool +StringHasLatin1Chars(JSString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1LinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageLatin1; + return s->nonInlineCharsLatin1; +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteLinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(!LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageTwoByte; + return s->nonInlineCharsTwoByte; +} + +MOZ_ALWAYS_INLINE JSLinearString * AtomToLinearString(JSAtom *atom) { return reinterpret_cast(atom); } +MOZ_ALWAYS_INLINE JSLinearString * +FlatStringToLinearString(JSFlatString *s) +{ + return reinterpret_cast(s); +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1AtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetLatin1LinearStringChars(nogc, AtomToLinearString(atom)); +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteAtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetTwoByteLinearStringChars(nogc, AtomToLinearString(atom)); +} + +JS_FRIEND_API(JSLinearString *) +StringToLinearStringSlow(JSContext *cx, JSString *str); + +MOZ_ALWAYS_INLINE JSLinearString * +StringToLinearString(JSContext *cx, JSString *str) +{ + using shadow::String; + String *s = reinterpret_cast(str); + if (MOZ_UNLIKELY((s->flags & String::TYPE_FLAGS_MASK) == String::ROPE_FLAGS)) + return StringToLinearStringSlow(cx, str); + return reinterpret_cast(str); +} + +MOZ_ALWAYS_INLINE void +CopyLinearStringChars(jschar *dest, JSLinearString *s, size_t len) +{ + JS::AutoCheckCannotGC nogc; + if (LinearStringHasLatin1Chars(s)) { + const JS::Latin1Char *src = GetLatin1LinearStringChars(nogc, s); + for (size_t i = 0; i < len; i++) + dest[i] = src[i]; + } else { + const jschar *src = GetTwoByteLinearStringChars(nogc, s); + mozilla::PodCopy(dest, src, len); + } +} + +inline bool +CopyStringChars(JSContext *cx, jschar *dest, JSString *s, size_t len) +{ + JSLinearString *linear = StringToLinearString(cx, s); + if (!linear) + return false; + + CopyLinearStringChars(dest, linear, len); + return true; +} + +inline void +CopyFlatStringChars(jschar *dest, JSFlatString *s, size_t len) +{ + CopyLinearStringChars(dest, FlatStringToLinearString(s), len); +} + JS_FRIEND_API(bool) GetPropertyNames(JSContext *cx, JSObject *obj, unsigned flags, JS::AutoIdVector *props); @@ -641,24 +971,18 @@ SetPreserveWrapperCallback(JSRuntime *rt, PreserveWrapperCallback callback); JS_FRIEND_API(bool) IsObjectInContextCompartment(JSObject *obj, const JSContext *cx); -/* - * ErrorFromException takes a raw Value so that it's possible to call it during - * GC/CC/whatever, when it may not be possible to get a JSContext to create a - * Rooted. It promises to never ever GC. - */ -JS_FRIEND_API(JSErrorReport*) -ErrorFromException(JS::Value val); - /* * NB: these flag bits are encoded into the bytecode stream in the immediate * operand of JSOP_ITER, so don't change them without advancing vm/Xdr.h's * XDR_BYTECODE_VERSION. */ #define JSITER_ENUMERATE 0x1 /* for-in compatible hidden default iterator */ -#define JSITER_FOREACH 0x2 /* return [key, value] pair rather than key */ -#define JSITER_KEYVALUE 0x4 /* destructuring for-in wants [key, value] */ +#define JSITER_FOREACH 0x2 /* get obj[key] for each property */ +#define JSITER_KEYVALUE 0x4 /* obsolete destructuring for-in wants [key, value] */ #define JSITER_OWNONLY 0x8 /* iterate over obj's own properties only */ #define JSITER_HIDDEN 0x10 /* also enumerate non-enumerable properties */ +#define JSITER_SYMBOLS 0x20 /* also include symbol property keys */ +#define JSITER_SYMBOLSONLY 0x40 /* exclude string property keys */ JS_FRIEND_API(bool) RunningWithTrustedPrincipals(JSContext *cx); @@ -677,6 +1001,7 @@ GetNativeStackLimit(JSContext *cx) * These macros report a stack overflow and run |onerror| if we are close to * using up the C stack. The JS_CHECK_CHROME_RECURSION variant gives us a little * extra space so that we can ensure that crucial code is able to run. + * JS_CHECK_RECURSION_CONSERVATIVE gives us a little less space. */ #define JS_CHECK_RECURSION(cx, onerror) \ @@ -723,6 +1048,18 @@ GetNativeStackLimit(JSContext *cx) } \ JS_END_MACRO +#define JS_CHECK_RECURSION_CONSERVATIVE(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(js::GetNativeStackLimit(cx), \ + &stackDummy_, \ + 1024 * sizeof(size_t))) \ + { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + JS_FRIEND_API(void) StartPCCountProfiling(JSContext *cx); @@ -764,9 +1101,10 @@ extern JS_FRIEND_API(bool) IsContextRunningJS(JSContext *cx); typedef bool -(* DOMInstanceClassMatchesProto)(JSObject *protoObject, uint32_t protoID, uint32_t depth); +(* DOMInstanceClassHasProtoAtDepth)(const Class *instanceClass, + uint32_t protoID, uint32_t depth); struct JSDOMCallbacks { - DOMInstanceClassMatchesProto instanceClassMatchesProto; + DOMInstanceClassHasProtoAtDepth instanceClassMatchesProto; }; typedef struct JSDOMCallbacks DOMCallbacks; @@ -796,10 +1134,10 @@ CastToJSFreeOp(FreeOp *fop) * Get an error type name from a JSExnType constant. * Returns nullptr for invalid arguments and JSEXN_INTERNALERR */ -extern JS_FRIEND_API(const jschar*) -GetErrorTypeName(JSRuntime* rt, int16_t exnType); +extern JS_FRIEND_API(JSFlatString *) +GetErrorTypeName(JSRuntime *rt, int16_t exnType); -#ifdef DEBUG +#ifdef JS_DEBUG extern JS_FRIEND_API(unsigned) GetEnterCompartmentDepth(JSContext* cx); #endif @@ -836,13 +1174,13 @@ struct ChromeCompartmentsOnly : public CompartmentFilter { struct SingleCompartment : public CompartmentFilter { JSCompartment *ours; - SingleCompartment(JSCompartment *c) : ours(c) {} + explicit SingleCompartment(JSCompartment *c) : ours(c) {} virtual bool match(JSCompartment *c) const { return c == ours; } }; struct CompartmentsWithPrincipals : public CompartmentFilter { JSPrincipals *principals; - CompartmentsWithPrincipals(JSPrincipals *p) : principals(p) {} + explicit CompartmentsWithPrincipals(JSPrincipals *p) : principals(p) {} virtual bool match(JSCompartment *c) const { return JS_GetCompartmentPrincipals(c) == principals; } @@ -941,49 +1279,198 @@ typedef enum JSErrNum { } JSErrNum; extern JS_FRIEND_API(const JSErrorFormatString *) -js_GetErrorMessage(void *userRef, const char *locale, const unsigned errorNumber); +js_GetErrorMessage(void *userRef, const unsigned errorNumber); + +namespace js { + +// AutoStableStringChars is here so we can use it in ErrorReport. It +// should get moved out of here if we can manage it. See bug 1040316. + +/* + * This class provides safe access to a string's chars across a GC. Once + * we allocate strings and chars in the nursery (bug 903519), this class + * will have to make a copy of the string's chars if they are allocated + * in the nursery, so it's best to avoid using this class unless you really + * need it. It's usually more efficient to use the latin1Chars/twoByteChars + * JSString methods and often the code can be rewritten so that only indexes + * instead of char pointers are used in parts of the code that can GC. + */ +class MOZ_STACK_CLASS AutoStableStringChars +{ + /* Ensure the string is kept alive while we're using its chars. */ + JS::RootedString s_; + union { + const jschar *twoByteChars_; + const JS::Latin1Char *latin1Chars_; + }; + enum State { Uninitialized, Latin1, TwoByte }; + State state_; + bool ownsChars_; + + public: + AutoStableStringChars(JSContext *cx) + : s_(cx), state_(Uninitialized), ownsChars_(false) + {}; + ~AutoStableStringChars(); + + bool init(JSContext *cx, JSString *s); + + /* Like init(), but Latin1 chars are inflated to TwoByte. */ + bool initTwoByte(JSContext *cx, JSString *s); + + bool isLatin1() const { return state_ == Latin1; } + bool isTwoByte() const { return state_ == TwoByte; } + + const jschar *twoByteChars() const { + MOZ_ASSERT(state_ == TwoByte); + return twoByteChars_; + } + + mozilla::Range latin1Range() const { + MOZ_ASSERT(state_ == Latin1); + return mozilla::Range(latin1Chars_, + GetStringLength(s_)); + } + + mozilla::Range twoByteRange() const { + MOZ_ASSERT(state_ == TwoByte); + return mozilla::Range(twoByteChars_, + GetStringLength(s_)); + } + + /* If we own the chars, transfer ownership to the caller. */ + bool maybeGiveOwnershipToCaller() { + MOZ_ASSERT(state_ != Uninitialized); + if (!ownsChars_) + return false; + state_ = Uninitialized; + ownsChars_ = false; + return true; + } + + private: + AutoStableStringChars(const AutoStableStringChars &other) MOZ_DELETE; + void operator=(const AutoStableStringChars &other) MOZ_DELETE; +}; + +// Creates a string of the form |ErrorType: ErrorMessage| for a JSErrorReport, +// which generally matches the toString() behavior of an ErrorObject. +extern JS_FRIEND_API(JSString *) +ErrorReportToString(JSContext *cx, JSErrorReport *reportp); + +struct MOZ_STACK_CLASS JS_FRIEND_API(ErrorReport) +{ + ErrorReport(JSContext *cx); + ~ErrorReport(); + + bool init(JSContext *cx, JS::HandleValue exn); + + JSErrorReport *report() + { + return reportp; + } + + const char *message() + { + return message_; + } + + private: + // More or less an equivalent of JS_ReportErrorNumber/js_ReportErrorNumberVA + // but fills in an ErrorReport instead of reporting it. Uses varargs to + // make it simpler to call js_ExpandErrorArguments. + void populateUncaughtExceptionReport(JSContext *cx, ...); + void populateUncaughtExceptionReportVA(JSContext *cx, va_list ap); + + // We may have a provided JSErrorReport, so need a way to represent that. + JSErrorReport *reportp; + + // And we may have a message. + const char *message_; + + // Or we may need to synthesize a JSErrorReport one of our own. + JSErrorReport ownedReport; + + // Or a message of our own. If this is non-null, we need to clean up both + // it and ownedReport. + char *ownedMessage; + + // And we have a string to maybe keep alive that has pointers into + // it from ownedReport. + JS::RootedString str; + + // And keep its chars alive too. + AutoStableStringChars strChars; + + // And we need to root our exception value. + JS::RootedObject exnObject; + + // And possibly some byte storage for our message_. + JSAutoByteString bytesStorage; + + // And for our filename. + JSAutoByteString filename; + + // True if we need to free message_ and the stuff in ownedReport + bool ownsMessageAndReport; +}; + +} /* namespace js */ + /* Implemented in jsclone.cpp. */ extern JS_FRIEND_API(uint64_t) js_GetSCOffset(JSStructuredCloneWriter* writer); -/* Typed Array functions, implemented in jstypedarray.cpp */ - namespace js { -namespace ArrayBufferView { - -enum ViewType { - TYPE_INT8 = 0, - TYPE_UINT8, - TYPE_INT16, - TYPE_UINT16, - TYPE_INT32, - TYPE_UINT32, - TYPE_FLOAT32, - TYPE_FLOAT64, +namespace Scalar { + +/* Scalar types which can appear in typed arrays and typed objects. */ +enum Type { + Int8 = 0, + Uint8, + Int16, + Uint16, + Int32, + Uint32, + Float32, + Float64, /* * Special type that is a uint8_t, but assignments are clamped to [0, 256). * Treat the raw data type as a uint8_t. */ - TYPE_UINT8_CLAMPED, + Uint8Clamped, - /* - * Type returned for a DataView. Note that there is no single element type - * in this case. - */ - TYPE_DATAVIEW, - - TYPE_MAX + TypeMax }; -} /* namespace ArrayBufferView */ +static inline size_t +byteSize(Type atype) +{ + switch (atype) { + case Int8: + case Uint8: + case Uint8Clamped: + return 1; + case Int16: + case Uint16: + return 2; + case Int32: + case Uint32: + case Float32: + return 4; + case Float64: + return 8; + default: + MOZ_CRASH("invalid scalar type"); + } +} +} /* namespace Scalar */ } /* namespace js */ -typedef js::ArrayBufferView::ViewType JSArrayBufferViewType; - /* * Create a new typed array with nelements elements. * @@ -1019,23 +1506,23 @@ JS_NewFloat64Array(JSContext *cx, uint32_t nelements); */ extern JS_FRIEND_API(JSObject *) -JS_NewInt8ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt8ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint8ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ClampedArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint8ClampedArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewInt16ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt16ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint16ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint16ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewInt32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewInt32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewUint32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewUint32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewFloat32ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewFloat32ArrayFromArray(JSContext *cx, JS::HandleObject array); extern JS_FRIEND_API(JSObject *) -JS_NewFloat64ArrayFromArray(JSContext *cx, JSObject *array); +JS_NewFloat64ArrayFromArray(JSContext *cx, JS::HandleObject array); /* * Create a new typed array using the given ArrayBuffer for storage. The @@ -1044,31 +1531,31 @@ JS_NewFloat64ArrayFromArray(JSContext *cx, JSObject *array); */ extern JS_FRIEND_API(JSObject *) -JS_NewInt8ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewInt16ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint16ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewInt32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewInt32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewUint32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewUint32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewFloat32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewFloat32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); extern JS_FRIEND_API(JSObject *) -JS_NewFloat64ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer, +JS_NewFloat64ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, uint32_t byteOffset, int32_t length); /* @@ -1119,6 +1606,93 @@ JS_IsFloat32Array(JSObject *obj); extern JS_FRIEND_API(bool) JS_IsFloat64Array(JSObject *obj); +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +namespace js { + +extern JS_FRIEND_API(JSObject *) +UnwrapInt8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8ClampedArray(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat64Array(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBuffer(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBufferView(JSObject *obj); + +namespace detail { + +extern JS_FRIEND_DATA(const Class* const) Int8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ClampedArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float64ArrayClassPtr; + +const size_t TypedArrayLengthSlot = 1; + +} // namespace detail + +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +#define JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Type, type) \ +inline void \ +Get ## Type ## ArrayLengthAndData(JSObject *obj, uint32_t *length, type **data) \ +{ \ + JS_ASSERT(GetObjectClass(obj) == detail::Type ## ArrayClassPtr); \ + const JS::Value &slot = GetReservedSlot(obj, detail::TypedArrayLengthSlot); \ + *length = mozilla::SafeCast(slot.toInt32()); \ + *data = static_cast(GetObjectPrivate(obj)); \ +} + +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int8, int8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8Clamped, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int16, int16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint16, uint16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int32, int32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint32, uint32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float32, float) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float64, double) + +#undef JS_DEFINE_DATA_AND_LENGTH_ACCESSOR + +// This one isn't inlined because it's rather tricky (by dint of having to deal +// with a dozen-plus classes and varying slot layouts. +extern JS_FRIEND_API(void) +GetArrayBufferViewLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +// This one isn't inlined because there are a bunch of different ArrayBuffer +// classes that would have to be individually handled here. +extern JS_FRIEND_API(void) +GetArrayBufferLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +} // namespace js + /* * Unwrap Typed arrays all at once. Return nullptr without throwing if the * object cannot be viewed as the correct typed array, or the typed array @@ -1148,13 +1722,13 @@ extern JS_FRIEND_API(JSObject *) JS_GetObjectAsArrayBuffer(JSObject *obj, uint32_t *length, uint8_t **data); /* - * Get the type of elements in a typed array, or TYPE_DATAVIEW if a DataView. + * Get the type of elements in a typed array, or TypeMax if a DataView. * * |obj| must have passed a JS_IsArrayBufferView/JS_Is*Array test, or somehow * be known that it would pass such a test: it is an ArrayBufferView or a * wrapper of an ArrayBufferView, and the unwrapping will succeed. */ -extern JS_FRIEND_API(JSArrayBufferViewType) +extern JS_FRIEND_API(js::Scalar::Type) JS_GetArrayBufferViewType(JSObject *obj); /* @@ -1177,16 +1751,12 @@ extern JS_FRIEND_API(uint32_t) JS_GetArrayBufferByteLength(JSObject *obj); /* - * Return a pointer to an array buffer's data. The buffer is still owned by the - * array buffer object, and should not be modified on another thread. The - * returned pointer is stable across GCs. - * - * |obj| must have passed a JS_IsArrayBufferObject test, or somehow be known - * that it would pass such a test: it is an ArrayBuffer or a wrapper of an - * ArrayBuffer, and the unwrapping will succeed. + * Check whether the obj is ArrayBufferObject and memory mapped. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. */ -extern JS_FRIEND_API(uint8_t *) -JS_GetArrayBufferData(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsMappedArrayBufferObject(JSObject *obj); /* * Return the number of elements in a typed array. @@ -1236,13 +1806,17 @@ JS_GetArrayBufferViewByteLength(JSObject *obj); /* * Return a pointer to the start of the data referenced by a typed array. The * data is still owned by the typed array, and should not be modified on - * another thread. + * another thread. Furthermore, the pointer can become invalid on GC (if the + * data is small and fits inside the array's GC header), so callers must take + * care not to hold on across anything that could GC. * * |obj| must have passed a JS_Is*Array test, or somehow be known that it would * pass such a test: it is a typed array or a wrapper of a typed array, and the * unwrapping will succeed. */ +extern JS_FRIEND_API(uint8_t *) +JS_GetArrayBufferData(JSObject *obj); extern JS_FRIEND_API(int8_t *) JS_GetInt8ArrayData(JSObject *obj); extern JS_FRIEND_API(uint8_t *) @@ -1262,6 +1836,13 @@ JS_GetFloat32ArrayData(JSObject *obj); extern JS_FRIEND_API(double *) JS_GetFloat64ArrayData(JSObject *obj); +/* + * Stable versions of the above functions where the buffer remains valid as long + * as the object is live. + */ +extern JS_FRIEND_API(uint8_t *) +JS_GetStableArrayBufferData(JSContext *cx, JS::HandleObject obj); + /* * Same as above, but for any kind of ArrayBufferView. Prefer the type-specific * versions when possible. @@ -1275,13 +1856,33 @@ JS_GetArrayBufferViewData(JSObject *obj); * object that would return true for JS_IsArrayBufferViewObject(). */ extern JS_FRIEND_API(JSObject *) -JS_GetArrayBufferViewBuffer(JSObject *obj); +JS_GetArrayBufferViewBuffer(JSContext *cx, JS::HandleObject obj); + +typedef enum { + ChangeData, + KeepData +} NeuterDataDisposition; /* * Set an ArrayBuffer's length to 0 and neuter all of its views. + * + * The |changeData| argument is a hint to inform internal behavior with respect + * to the internal pointer to the ArrayBuffer's data after being neutered. + * There is no guarantee it will be respected. But if it is respected, the + * ArrayBuffer's internal data pointer will, or will not, have changed + * accordingly. + */ +extern JS_FRIEND_API(bool) +JS_NeuterArrayBuffer(JSContext *cx, JS::HandleObject obj, + NeuterDataDisposition changeData); + +/* + * Check whether the obj is ArrayBufferObject and neutered. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. */ extern JS_FRIEND_API(bool) -JS_NeuterArrayBuffer(JSContext *cx, JS::HandleObject obj); +JS_IsNeuteredArrayBufferObject(JSObject *obj); /* * Check whether obj supports JS_GetDataView* APIs. @@ -1360,7 +1961,7 @@ class JSJitGetterCallArgs : protected JS::MutableHandleValue : JS::MutableHandleValue(args.rval()) {} - explicit JSJitGetterCallArgs(JS::Rooted* rooted) + explicit JSJitGetterCallArgs(JS::RootedValue* rooted) : JS::MutableHandleValue(rooted) {} @@ -1422,6 +2023,12 @@ class JSJitMethodCallArgs : protected JS::detail::CallArgsBaseusedRval_, which we don't have. + return argv_[-2].toObject(); + } + // Add get() as needed }; @@ -1451,7 +2058,10 @@ struct JSJitInfo { Getter, Setter, Method, - OpType_None + ParallelNative, + StaticMethod, + // Must be last + OpTypeCount }; enum ArgType { @@ -1475,6 +2085,13 @@ struct JSJitInfo { ArgTypeListEnd = (1 << 31) }; + static_assert(Any & String, "Any must include String."); + static_assert(Any & Integer, "Any must include Integer."); + static_assert(Any & Double, "Any must include Double."); + static_assert(Any & Boolean, "Any must include Boolean."); + static_assert(Any & Object, "Any must include Object."); + static_assert(Any & Null, "Any must include Null."); + enum AliasSet { // An enum that describes what this getter/setter/method aliases. This // determines what things can be hoisted past this call, and if this @@ -1490,69 +2107,172 @@ struct JSJitInfo { // Alias the world. Calling this can change arbitrary values anywhere // in the system. Most things fall in this bucket. - AliasEverything + AliasEverything, + + // Must be last. + AliasSetCount }; - bool isDOMJitInfo() const + bool hasParallelNative() const + { + return type() == ParallelNative; + } + + bool needsOuterizedThisObject() const + { + return type() != Getter && type() != Setter; + } + + bool isTypedMethodJitInfo() const { - return type != OpType_None; + return isTypedMethod; + } + + OpType type() const + { + return OpType(type_); + } + + AliasSet aliasSet() const + { + return AliasSet(aliasSet_); + } + + JSValueType returnType() const + { + return JSValueType(returnType_); } union { JSJitGetterOp getter; JSJitSetterOp setter; JSJitMethodOp method; + /* An alternative native that's safe to call in parallel mode. */ + JSParallelNative parallelNative; + /* A DOM static method, used for Promise wrappers */ + JSNative staticMethod; }; - uint32_t protoID; - uint32_t depth; - // type not being OpType_None means this is a DOM method. If you - // change that, come up with a different way of implementing - // isDOMJitInfo(). - OpType type; - bool isInfallible; /* Is op fallible? False in setters. */ - bool isMovable; /* Is op movable? To be movable the op must not - AliasEverything, but even that might not be - enough (e.g. in cases when it can throw). */ - AliasSet aliasSet; /* The alias set for this op. This is a _minimal_ - alias set; in particular for a method it does not - include whatever argument conversions might do. - That's covered by argTypes and runtime analysis - of the actual argument types being passed in. */ - // XXXbz should we have a JSGetterJitInfo subclass or something? + uint16_t protoID; + uint16_t depth; + + // These fields are carefully packed to take up 4 bytes. If you need more + // bits for whatever reason, please see if you can steal bits from existing + // fields before adding more members to this structure. + +#define JITINFO_OP_TYPE_BITS 4 +#define JITINFO_ALIAS_SET_BITS 4 +#define JITINFO_RETURN_TYPE_BITS 8 + + // The OpType that says what sort of function we are. + uint32_t type_ : JITINFO_OP_TYPE_BITS; + + // The alias set for this op. This is a _minimal_ alias set; in + // particular for a method it does not include whatever argument + // conversions might do. That's covered by argTypes and runtime + // analysis of the actual argument types being passed in. + uint32_t aliasSet_ : JITINFO_ALIAS_SET_BITS; + + // The return type tag. Might be JSVAL_TYPE_UNKNOWN. + uint32_t returnType_ : JITINFO_RETURN_TYPE_BITS; + + static_assert(OpTypeCount <= (1 << JITINFO_OP_TYPE_BITS), + "Not enough space for OpType"); + static_assert(AliasSetCount <= (1 << JITINFO_ALIAS_SET_BITS), + "Not enough space for AliasSet"); + static_assert((sizeof(JSValueType) * 8) <= JITINFO_RETURN_TYPE_BITS, + "Not enough space for JSValueType"); + +#undef JITINFO_RETURN_TYPE_BITS +#undef JITINFO_ALIAS_SET_BITS +#undef JITINFO_OP_TYPE_BITS + + uint32_t isInfallible : 1; /* Is op fallible? False in setters. */ + uint32_t isMovable : 1; /* Is op movable? To be movable the op must + not AliasEverything, but even that might + not be enough (e.g. in cases when it can + throw). */ // XXXbz should we have a JSValueType for the type of the member? - bool isInSlot; /* True if this is a getter that can get a member - from a slot of the "this" object directly. */ - size_t slotIndex; /* If isMember is true, the index of the slot to get - the value from. Otherwise 0. */ - JSValueType returnType; /* The return type tag. Might be JSVAL_TYPE_UNKNOWN */ - - const ArgType* const argTypes; /* For a method, a list of sets of types that - the function expects. This can be used, - for example, to figure out when argument - coercions can have side-effects. nullptr - if we have no type information for - arguments. */ - - /* An alternative native that's safe to call in parallel mode. */ - JSParallelNative parallelNative; - -private: - static void staticAsserts() - { - JS_STATIC_ASSERT(Any & String); - JS_STATIC_ASSERT(Any & Integer); - JS_STATIC_ASSERT(Any & Double); - JS_STATIC_ASSERT(Any & Boolean); - JS_STATIC_ASSERT(Any & Object); - JS_STATIC_ASSERT(Any & Null); - } + uint32_t isAlwaysInSlot : 1; /* True if this is a getter that can always + get the value from a slot of the "this" + object. */ + uint32_t isLazilyCachedInSlot : 1; /* True if this is a getter that can + sometimes (if the slot doesn't contain + UndefinedValue()) get the value from a + slot of the "this" object. */ + uint32_t isTypedMethod : 1; /* True if this is an instance of + JSTypedMethodJitInfo. */ + uint32_t slotIndex : 11; /* If isAlwaysInSlot or isSometimesInSlot is + true, the index of the slot to get the value + from. Otherwise 0. */ }; -#define JS_JITINFO_NATIVE_PARALLEL(op) \ - {{nullptr},0,0,JSJitInfo::OpType_None,false,false,JSJitInfo::AliasEverything,false,0,JSVAL_TYPE_MISSING,nullptr,op} +static_assert(sizeof(JSJitInfo) == (sizeof(void*) + 2 * sizeof(uint32_t)), + "There are several thousand instances of JSJitInfo stored in " + "a binary. Please don't increase its space requirements without " + "verifying that there is no other way forward (better packing, " + "smaller datatypes for fields, subclassing, etc.)."); -static JS_ALWAYS_INLINE const JSJitInfo * +struct JSTypedMethodJitInfo +{ + // We use C-style inheritance here, rather than C++ style inheritance + // because not all compilers support brace-initialization for non-aggregate + // classes. Using C++ style inheritance and constructors instead of + // brace-initialization would also force the creation of static + // constructors (on some compilers) when JSJitInfo and JSTypedMethodJitInfo + // structures are declared. Since there can be several thousand of these + // structures present and we want to have roughly equivalent performance + // across a range of compilers, we do things manually. + JSJitInfo base; + + const JSJitInfo::ArgType* const argTypes; /* For a method, a list of sets of + types that the function + expects. This can be used, + for example, to figure out + when argument coercions can + have side-effects. */ +}; + +namespace JS { +namespace detail { + +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_PARALLEL_NATIVE_TO only. */ +inline int CheckIsParallelNative(JSParallelNative parallelNative); + +} // namespace detail +} // namespace JS + +#define JS_CAST_PARALLEL_NATIVE_TO(v, To) \ + (static_cast(sizeof(JS::detail::CheckIsParallelNative(v))), \ + reinterpret_cast(v)) + +/* + * You may ask yourself: why do we define a wrapper around a wrapper here? + * The answer is that some compilers don't understand initializing a union + * as we do below with a construct like: + * + * reinterpret_cast(JSParallelNativeThreadSafeWrapper) + * + * (We need the reinterpret_cast because we must initialize the union with + * a datum of the type of the union's first member.) + * + * Presumably this has something to do with template instantiation. + * Initializing with a normal function pointer seems to work fine. Hence + * the ugliness that you see before you. + */ +#define JS_JITINFO_NATIVE_PARALLEL(infoName, parallelOp) \ + const JSJitInfo infoName = \ + {{JS_CAST_PARALLEL_NATIVE_TO(parallelOp, JSJitGetterOp)},0,0,JSJitInfo::ParallelNative,JSJitInfo::AliasEverything,JSVAL_TYPE_MISSING,false,false,false,false,false,0} + +#define JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(infoName, wrapperName, serialOp) \ + bool wrapperName##_ParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, \ + JS::Value *vp) \ + { \ + return JSParallelNativeThreadSafeWrapper(cx, argc, vp); \ + } \ + JS_JITINFO_NATIVE_PARALLEL(infoName, wrapperName##_ParallelNativeThreadSafeWrapper) + +static MOZ_ALWAYS_INLINE const JSJitInfo * FUNCTION_VALUE_TO_JITINFO(const JS::Value& v) { JS_ASSERT(js::GetObjectClass(&v.toObject()) == js::FunctionClassPtr); @@ -1562,7 +2282,7 @@ FUNCTION_VALUE_TO_JITINFO(const JS::Value& v) /* Statically asserted in jsfun.h. */ static const unsigned JS_FUNCTION_INTERPRETED_BIT = 0x1; -static JS_ALWAYS_INLINE void +static MOZ_ALWAYS_INLINE void SET_JITINFO(JSFunction * func, const JSJitInfo *info) { js::shadow::Function *fun = reinterpret_cast(func); @@ -1575,7 +2295,7 @@ SET_JITINFO(JSFunction * func, const JSJitInfo *info) * eliminate Gecko's dependencies on it! */ -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid JSID_FROM_BITS(size_t bits) { jsid id; @@ -1610,7 +2330,7 @@ bool IdMatchesAtom(jsid id, JSAtom *atom); * Thus, it is only the rare third case which needs this function, which * handles any JSAtom* that is known not to be representable with an int jsid. */ -static JS_ALWAYS_INLINE jsid +static MOZ_ALWAYS_INLINE jsid NON_INTEGER_ATOM_TO_JSID(JSAtom *atom) { JS_ASSERT(((size_t)atom & 0x7) == 0); @@ -1620,19 +2340,19 @@ NON_INTEGER_ATOM_TO_JSID(JSAtom *atom) } /* All strings stored in jsids are atomized, but are not necessarily property names. */ -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ATOM(jsid id) { return JSID_IS_STRING(id); } -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool JSID_IS_ATOM(jsid id, JSAtom *atom) { return id == JSID_FROM_BITS((size_t)atom); } -static JS_ALWAYS_INLINE JSAtom * +static MOZ_ALWAYS_INLINE JSAtom * JSID_TO_ATOM(jsid id) { return (JSAtom *)JSID_TO_STRING(id); @@ -1642,31 +2362,19 @@ JS_STATIC_ASSERT(sizeof(jsid) == sizeof(void*)); namespace js { -static JS_ALWAYS_INLINE JS::Value +static MOZ_ALWAYS_INLINE JS::Value IdToValue(jsid id) { if (JSID_IS_STRING(id)) return JS::StringValue(JSID_TO_STRING(id)); - if (JS_LIKELY(JSID_IS_INT(id))) + if (JSID_IS_INT(id)) return JS::Int32Value(JSID_TO_INT(id)); - if (JS_LIKELY(JSID_IS_OBJECT(id))) - return JS::ObjectValue(*JSID_TO_OBJECT(id)); + if (JSID_IS_SYMBOL(id)) + return JS::SymbolValue(JSID_TO_SYMBOL(id)); JS_ASSERT(JSID_IS_VOID(id)); return JS::UndefinedValue(); } -static JS_ALWAYS_INLINE jsval -IdToJsval(jsid id) -{ - return IdToValue(id); -} - -extern JS_FRIEND_API(bool) -IsReadOnlyDateMethod(JS::IsAcceptableThis test, JS::NativeImpl method); - -extern JS_FRIEND_API(bool) -IsTypedArrayThisCheck(JS::IsAcceptableThis test); - /* * If the embedder has registered a default JSContext callback, returns the * result of the callback. Otherwise, asserts that |rt| has exactly one @@ -1681,6 +2389,21 @@ typedef JSContext* JS_FRIEND_API(void) SetDefaultJSContextCallback(JSRuntime *rt, DefaultJSContextCallback cb); +/* + * To help embedders enforce their invariants, we allow them to specify in + * advance which JSContext should be passed to JSAPI calls. If this is set + * to a non-null value, the assertSameCompartment machinery does double- + * duty (in debug builds) to verify that it matches the cx being used. + */ +#ifdef DEBUG +JS_FRIEND_API(void) +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx); +#else +inline void +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx) {}; +#endif + + enum CTypesActivityType { CTYPES_CALL_BEGIN, CTYPES_CALL_END, @@ -1720,13 +2443,6 @@ class JS_FRIEND_API(AutoCTypesActivityCallback) { } }; -#ifdef DEBUG -extern JS_FRIEND_API(void) -assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id); -#else -inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id) {}; -#endif - typedef bool (* ObjectMetadataCallback)(JSContext *cx, JSObject **pmetadata); @@ -1747,6 +2463,13 @@ SetObjectMetadata(JSContext *cx, JS::HandleObject obj, JS::HandleObject metadata JS_FRIEND_API(JSObject *) GetObjectMetadata(JSObject *obj); +JS_FRIEND_API(void) +UnsafeDefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value); + +JS_FRIEND_API(bool) +SliceSlowly(JSContext* cx, JS::HandleObject obj, JS::HandleObject receiver, + uint32_t begin, uint32_t end, JS::HandleObject result); + /* ES5 8.12.8. */ extern JS_FRIEND_API(bool) DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandleValue vp); @@ -1766,7 +2489,43 @@ DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandle */ extern JS_FRIEND_API(bool) CheckDefineProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, - JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +/* + * Helper function for HTMLDocument and HTMLFormElement. + * + * These are the only two interfaces that have [OverrideBuiltins], a named + * getter, and no named setter. They're implemented as proxies with a custom + * getOwnPropertyDescriptor() method. Unfortunately, overriding + * getOwnPropertyDescriptor() automatically affects the behavior of set(), + * which normally is just common sense but is *not* desired for these two + * interfaces. + * + * The fix is for these two interfaces to override set() to ignore the + * getOwnPropertyDescriptor() override. + * + * SetPropertyIgnoringNamedGetter is exposed to make it easier to override + * set() in this way. It carries out all the steps of BaseProxyHandler::set() + * except the initial getOwnPropertyDescriptor()/getPropertyDescriptor() calls. + * The caller must supply those results as the 'desc' and 'descIsOwn' + * parameters. + * + * Implemented in jsproxy.cpp. + */ +JS_FRIEND_API(bool) +SetPropertyIgnoringNamedGetter(JSContext *cx, const BaseProxyHandler *handler, + JS::HandleObject proxy, JS::HandleObject receiver, + JS::HandleId id, JS::MutableHandle desc, + bool descIsOwn, bool strict, JS::MutableHandleValue vp); + +JS_FRIEND_API(void) +ReportErrorWithId(JSContext *cx, const char *msg, JS::HandleId id); + +// This function is for one specific use case, please don't use this for anything else! +extern JS_FRIEND_API(bool) +ExecuteInGlobalAndReturnScope(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleObject scope); } /* namespace js */ @@ -1775,27 +2534,27 @@ js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg, JS::Handle descriptor, bool *bp); extern JS_FRIEND_API(bool) -js_ReportIsNotFunction(JSContext *cx, const JS::Value& v); +js_ReportIsNotFunction(JSContext *cx, JS::HandleValue v); #ifdef JSGC_GENERATIONAL extern JS_FRIEND_API(void) JS_StoreObjectPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSObject *key, void *data), JSObject *key, void *data); extern JS_FRIEND_API(void) JS_StoreStringPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSString *key, void *data), JSString *key, void *data); #else inline void JS_StoreObjectPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSObject *key, void *data), JSObject *key, void *data) {} inline void JS_StoreStringPostBarrierCallback(JSContext* cx, - void (*callback)(JSTracer *trc, void *key, void *data), + void (*callback)(JSTracer *trc, JSString *key, void *data), JSString *key, void *data) {} #endif /* JSGC_GENERATIONAL */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/jsperf.h b/frameworks/js-bindings/external/spidermonkey/include/win32/jsperf.h index e3cbc23143..60c572f559 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/jsperf.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/jsperf.h @@ -88,7 +88,7 @@ class JS_FRIEND_API(PerfMeasurement) * then the eventsMeasured bitmask will only include the subset of * |toMeasure| corresponding to the events that can be measured. */ - PerfMeasurement(EventMask toMeasure); + explicit PerfMeasurement(EventMask toMeasure); /* Done with this set of measurements, tear down OS-level state. */ ~PerfMeasurement(); @@ -118,7 +118,7 @@ class JS_FRIEND_API(PerfMeasurement) * global object). The JS-visible API is identical to the C++ API. */ extern JS_FRIEND_API(JSObject*) - RegisterPerfMeasurement(JSContext *cx, JSObject *global); + RegisterPerfMeasurement(JSContext *cx, JS::HandleObject global); /* * Given a Value which contains an instance of the aforementioned diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/jsprf.h b/frameworks/js-bindings/external/spidermonkey/include/win32/jsprf.h index b235f0b4fb..bfedf98ca8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/jsprf.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/jsprf.h @@ -57,23 +57,11 @@ extern JS_PUBLIC_API(void) JS_smprintf_free(char *mem); */ extern JS_PUBLIC_API(char*) JS_sprintf_append(char *last, const char *fmt, ...); -/* -** sprintf into a function. The function "f" is called with a string to -** place into the output. "arg" is an opaque pointer used by the stuff -** function to hold any state needed to do the storage of the output -** data. The return value is a count of the number of characters fed to -** the stuff function, or (uint32_t)-1 if an error occurs. -*/ -typedef int (*JSStuffFunc)(void *arg, const char *s, uint32_t slen); - -extern JS_PUBLIC_API(uint32_t) JS_sxprintf(JSStuffFunc f, void *arg, const char *fmt, ...); - /* ** va_list forms of the above. */ extern JS_PUBLIC_API(uint32_t) JS_vsnprintf(char *out, uint32_t outlen, const char *fmt, va_list ap); extern JS_PUBLIC_API(char*) JS_vsmprintf(const char *fmt, va_list ap); extern JS_PUBLIC_API(char*) JS_vsprintf_append(char *last, const char *fmt, va_list ap); -extern JS_PUBLIC_API(uint32_t) JS_vsxprintf(JSStuffFunc f, void *arg, const char *fmt, va_list ap); #endif /* jsprf_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/jsprototypes.h b/frameworks/js-bindings/external/spidermonkey/include/win32/jsprototypes.h index bc4a767033..1cb56bf8da 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/jsprototypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/jsprototypes.h @@ -34,7 +34,7 @@ #define CLASP(name) (&name##Class) #define OCLASP(name) (&name##Object::class_) -#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[ScalarTypeRepresentation::type]) +#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[Scalar::type]) #ifdef ENABLE_PARALLEL_JS #define IF_PJS(real,imaginary) real @@ -54,47 +54,61 @@ #define IF_BDATA(real,imaginary) imaginary #endif +#ifdef ENABLE_SHARED_ARRAY_BUFFER +#define IF_SAB(real,imaginary) real +#else +#define IF_SAB(real,imaginary) imaginary +#endif + +#ifdef JS_HAS_SYMBOLS +#define IF_SYMBOLS(real,imaginary) real +#else +#define IF_SYMBOLS(real,imaginary) imaginary +#endif + #define JS_FOR_PROTOTYPES(real,imaginary) \ imaginary(Null, 0, js_InitNullClass, dummy) \ - real(Object, 1, js_InitObjectClass, &JSObject::class_) \ - real(Function, 2, js_InitFunctionClass, &JSFunction::class_) \ - real(Array, 3, js_InitArrayClass, OCLASP(Array)) \ + real(Object, 1, js_InitViaClassSpec, &JSObject::class_) \ + real(Function, 2, js_InitViaClassSpec, &JSFunction::class_) \ + real(Array, 3, js_InitViaClassSpec, OCLASP(Array)) \ real(Boolean, 4, js_InitBooleanClass, OCLASP(Boolean)) \ real(JSON, 5, js_InitJSONClass, CLASP(JSON)) \ - real(Date, 6, js_InitDateClass, OCLASP(Date)) \ + real(Date, 6, js_InitViaClassSpec, OCLASP(Date)) \ real(Math, 7, js_InitMathClass, CLASP(Math)) \ real(Number, 8, js_InitNumberClass, OCLASP(Number)) \ real(String, 9, js_InitStringClass, OCLASP(String)) \ real(RegExp, 10, js_InitRegExpClass, OCLASP(RegExp)) \ - real(Error, 11, js_InitExceptionClasses, OCLASP(Error)) \ - real(InternalError, 12, js_InitExceptionClasses, OCLASP(Error)) \ - real(EvalError, 13, js_InitExceptionClasses, OCLASP(Error)) \ - real(RangeError, 14, js_InitExceptionClasses, OCLASP(Error)) \ - real(ReferenceError, 15, js_InitExceptionClasses, OCLASP(Error)) \ - real(SyntaxError, 16, js_InitExceptionClasses, OCLASP(Error)) \ - real(TypeError, 17, js_InitExceptionClasses, OCLASP(Error)) \ - real(URIError, 18, js_InitExceptionClasses, OCLASP(Error)) \ + real(Error, 11, js_InitViaClassSpec, OCLASP(Error)) \ + real(InternalError, 12, js_InitViaClassSpec, OCLASP(Error)) \ + real(EvalError, 13, js_InitViaClassSpec, OCLASP(Error)) \ + real(RangeError, 14, js_InitViaClassSpec, OCLASP(Error)) \ + real(ReferenceError, 15, js_InitViaClassSpec, OCLASP(Error)) \ + real(SyntaxError, 16, js_InitViaClassSpec, OCLASP(Error)) \ + real(TypeError, 17, js_InitViaClassSpec, OCLASP(Error)) \ + real(URIError, 18, js_InitViaClassSpec, OCLASP(Error)) \ real(Iterator, 19, js_InitIteratorClasses, OCLASP(PropertyIterator)) \ real(StopIteration, 20, js_InitIteratorClasses, OCLASP(StopIteration)) \ - real(ArrayBuffer, 21, js_InitTypedArrayClasses, &js::ArrayBufferObject::protoClass) \ - real(Int8Array, 22, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT8)) \ - real(Uint8Array, 23, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT8)) \ - real(Int16Array, 24, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT16)) \ - real(Uint16Array, 25, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT16)) \ - real(Int32Array, 26, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT32)) \ - real(Uint32Array, 27, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT32)) \ - real(Float32Array, 28, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_FLOAT32)) \ - real(Float64Array, 29, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_FLOAT64)) \ - real(Uint8ClampedArray, 30, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT8_CLAMPED)) \ + real(ArrayBuffer, 21, js_InitArrayBufferClass, &js::ArrayBufferObject::protoClass) \ + real(Int8Array, 22, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int8)) \ + real(Uint8Array, 23, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8)) \ + real(Int16Array, 24, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int16)) \ + real(Uint16Array, 25, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint16)) \ + real(Int32Array, 26, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int32)) \ + real(Uint32Array, 27, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint32)) \ + real(Float32Array, 28, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float32)) \ + real(Float64Array, 29, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float64)) \ + real(Uint8ClampedArray, 30, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8Clamped)) \ real(Proxy, 31, js_InitProxyClass, &ProxyObject::uncallableClass_) \ real(WeakMap, 32, js_InitWeakMapClass, OCLASP(WeakMap)) \ real(Map, 33, js_InitMapClass, OCLASP(Map)) \ real(Set, 34, js_InitSetClass, OCLASP(Set)) \ - real(DataView, 35, js_InitTypedArrayClasses, OCLASP(DataView)) \ -IF_PJS(real,imaginary) (ParallelArray, 36, js_InitParallelArrayClass, OCLASP(ParallelArray)) \ -IF_INTL(real,imaginary) (Intl, 37, js_InitIntlClass, CLASP(Intl)) \ -IF_BDATA(real,imaginary)(TypedObject, 38, js_InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \ - imaginary(GeneratorFunction, 39, js_InitIteratorClasses, dummy) \ + real(DataView, 35, js_InitDataViewClass, OCLASP(DataView)) \ +IF_SYMBOLS(real,imaginary)(Symbol, 36, js_InitSymbolClass, &js::SymbolObject::class_) \ +IF_SAB(real,imaginary)(SharedArrayBuffer, 37, js_InitSharedArrayBufferClass, &js::SharedArrayBufferObject::protoClass) \ +IF_INTL(real,imaginary) (Intl, 38, js_InitIntlClass, CLASP(Intl)) \ +IF_BDATA(real,imaginary)(TypedObject, 39, js_InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \ + imaginary(GeneratorFunction, 40, js_InitIteratorClasses, dummy) \ +IF_BDATA(real,imaginary)(SIMD, 41, js_InitSIMDClass, OCLASP(SIMD)) \ #define JS_FOR_EACH_PROTOTYPE(macro) JS_FOR_PROTOTYPES(macro,macro) diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/jsproxy.h b/frameworks/js-bindings/external/spidermonkey/include/win32/jsproxy.h index 3d2ea81cb3..b4588c4c2a 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/jsproxy.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/jsproxy.h @@ -47,6 +47,22 @@ class JS_FRIEND_API(Wrapper); * BaseProxyHandler provides implementations of the derived traps in terms of * the (pure virtual) fundamental traps. * + * In addition to the normal traps, there are two models for proxy prototype + * chains. First, proxies may opt to use the standard prototype mechanism used + * throughout the engine. To do so, simply pass a prototype to NewProxyObject() + * at creation time. All prototype accesses will then "just work" to treat the + * proxy as a "normal" object. Alternatively, if instead the proxy wishes to + * implement more complicated prototype semantics (if, for example, it wants to + * delegate the prototype lookup to a wrapped object), it may pass Proxy::LazyProto + * as the prototype at create time and opt in to the trapped prototype system, + * which guarantees that their trap will be called on any and every prototype + * chain access of the object. + * + * This system is implemented with two traps: {get,set}PrototypeOf. The default + * implementation of setPrototypeOf throws a TypeError. Since it is not possible + * to create an object without a sense of prototype chain, handler implementors + * must provide a getPrototypeOf trap if opting in to the dynamic prototype system. + * * To minimize code duplication, a set of abstract proxy handler classes is * provided, from which other handlers may inherit. These abstract classes * are organized in the following hierarchy: @@ -72,37 +88,55 @@ class JS_FRIEND_API(Wrapper); class JS_FRIEND_API(BaseProxyHandler) { const void *mFamily; + + /* + * Proxy handlers can use mHasPrototype to request the following special + * treatment from the JS engine: + * + * - When mHasPrototype is true, the engine never calls these methods: + * getPropertyDescriptor, has, set, enumerate, iterate. Instead, for + * these operations, it calls the "own" traps like + * getOwnPropertyDescriptor, hasOwn, defineProperty, keys, etc., and + * consults the prototype chain if needed. + * + * - When mHasPrototype is true, the engine calls handler->get() only if + * handler->hasOwn() says an own property exists on the proxy. If not, + * it consults the prototype chain. + * + * This is useful because it frees the ProxyHandler from having to implement + * any behavior having to do with the prototype chain. + */ bool mHasPrototype; - bool mHasPolicy; - protected: - // Subclasses may set this in their constructor. - void setHasPrototype(bool aHasPrototype) { mHasPrototype = aHasPrototype; } - void setHasPolicy(bool aHasPolicy) { mHasPolicy = aHasPolicy; } + + /* + * All proxies indicate whether they have any sort of interesting security + * policy that might prevent the caller from doing something it wants to + * the object. In the case of wrappers, this distinction is used to + * determine whether the caller may strip off the wrapper if it so desires. + */ + bool mHasSecurityPolicy; public: - explicit BaseProxyHandler(const void *family); + explicit BaseProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); virtual ~BaseProxyHandler(); - bool hasPrototype() { + bool hasPrototype() const { return mHasPrototype; } - bool hasPolicy() { - return mHasPolicy; + bool hasSecurityPolicy() const { + return mHasSecurityPolicy; } - inline const void *family() { + inline const void *family() const { return mFamily; } static size_t offsetOfFamily() { return offsetof(BaseProxyHandler, mFamily); } - virtual bool isOuterWindow() { - return false; - } - - virtual bool finalizeInBackground(Value priv) { + virtual bool finalizeInBackground(Value priv) const { /* * Called on creation of a proxy to determine whether its finalize * method can be finalized on the background thread. @@ -119,66 +153,75 @@ class JS_FRIEND_API(BaseProxyHandler) * The |act| parameter to enter() specifies the action being performed. * If |bp| is false, the trap suggests that the caller throw (though it * may still decide to squelch the error). + * + * We make these OR-able so that assertEnteredPolicy can pass a union of them. + * For example, get{,Own}PropertyDescriptor is invoked by both calls to ::get() + * and ::set() (since we need to look up the accessor), so its + * assertEnteredPolicy would pass GET | SET. */ - enum Action { - GET, - SET, - CALL + typedef uint32_t Action; + enum { + NONE = 0x00, + GET = 0x01, + SET = 0x02, + CALL = 0x04, + ENUMERATE = 0x08 }; + virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Action act, - bool *bp); + bool *bp) const; /* ES5 Harmony fundamental proxy traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) = 0; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const = 0; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, - unsigned flags) = 0; + MutableHandle desc) const = 0; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, - HandleId id, MutableHandle desc, - unsigned flags) = 0; + HandleId id, MutableHandle desc) const = 0; virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc) = 0; + MutableHandle desc) const = 0; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, - AutoIdVector &props) = 0; - virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) = 0; - virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) = 0; + AutoIdVector &props) const = 0; + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const = 0; + virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) const = 0; /* ES5 Harmony derived proxy traps. */ - virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); - virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); + virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; + virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, MutableHandleValue vp); + HandleId id, MutableHandleValue vp) const; virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp); - virtual bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props); + HandleId id, bool strict, MutableHandleValue vp) const; + virtual bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props) const; virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, - MutableHandleValue vp); + MutableHandleValue vp) const; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) = 0; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args); - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args); - virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args); - virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp); - virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx); - virtual const char *className(JSContext *cx, HandleObject proxy); - virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent); - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g); - virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); - virtual void finalize(JSFreeOp *fop, JSObject *proxy); - virtual bool getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver, - uint32_t index, MutableHandleValue vp, bool *present); - virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const = 0; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args) const; + virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp) const; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx) const; + virtual const char *className(JSContext *cx, HandleObject proxy) const; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const; + virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp) const; + virtual void finalize(JSFreeOp *fop, JSObject *proxy) const; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop) const; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp) const; // These two hooks must be overridden, or not overridden, in tandem -- no // overriding just one! virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable); - virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id); + JS::HandleObject callable) const; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const; + + virtual bool slice(JSContext *cx, HandleObject proxy, uint32_t begin, uint32_t end, + HandleObject result) const; /* See comment for weakmapKeyDelegateOp in js/Class.h. */ - virtual JSObject *weakmapKeyDelegate(JSObject *proxy); - virtual bool isScripted() { return false; } + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const; + virtual bool isScripted() const { return false; } }; /* @@ -194,54 +237,58 @@ class JS_FRIEND_API(BaseProxyHandler) class JS_PUBLIC_API(DirectProxyHandler) : public BaseProxyHandler { public: - explicit DirectProxyHandler(const void *family); + explicit DirectProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); /* ES5 Harmony fundamental proxy traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags) MOZ_OVERRIDE; - virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, - HandleId id, MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool enumerate(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; /* ES5 Harmony derived proxy traps. */ virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool keys(JSContext *cx, HandleObject proxy, - AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, - unsigned indent) MOZ_OVERRIDE; + unsigned indent) const MOZ_OVERRIDE; virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, - RegExpGuard *g) MOZ_OVERRIDE; - virtual JSObject *weakmapKeyDelegate(JSObject *proxy); + RegExpGuard *g) const MOZ_OVERRIDE; + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const MOZ_OVERRIDE; }; /* @@ -257,16 +304,15 @@ class Proxy /* ES5 Harmony fundamental proxy traps. */ static bool preventExtensions(JSContext *cx, HandleObject proxy); static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags); - static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, unsigned flags, HandleId id, + MutableHandle desc); + static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, MutableHandleValue vp); static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, - MutableHandle desc, unsigned flags); - static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, unsigned flags, HandleId id, + MutableHandle desc); + static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, MutableHandleValue vp); static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, MutableHandle desc); - static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, HandleValue v); static bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props); static bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); static bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props); @@ -276,8 +322,6 @@ class Proxy static bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); static bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, MutableHandleValue vp); - static bool getElementIfPresent(JSContext *cx, HandleObject proxy, HandleObject receiver, - uint32_t index, MutableHandleValue vp, bool *present); static bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, bool strict, MutableHandleValue vp); static bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props); @@ -295,44 +339,26 @@ class Proxy static bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g); static bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); static bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + static bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp); - static bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable); - static bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id); + static bool watch(JSContext *cx, HandleObject proxy, HandleId id, HandleObject callable); + static bool unwatch(JSContext *cx, HandleObject proxy, HandleId id); + + static bool slice(JSContext *cx, HandleObject obj, uint32_t begin, uint32_t end, + HandleObject result); /* IC entry path for handling __noSuchMethod__ on access. */ static bool callProp(JSContext *cx, HandleObject proxy, HandleObject reveiver, HandleId id, MutableHandleValue vp); - - static JSObject * const LazyProto; }; // Use these in places where you don't want to #include vm/ProxyObject.h. extern JS_FRIEND_DATA(const js::Class* const) CallableProxyClassPtr; extern JS_FRIEND_DATA(const js::Class* const) UncallableProxyClassPtr; -extern JS_FRIEND_DATA(const js::Class* const) OuterWindowProxyClassPtr; - -inline bool IsProxyClass(const Class *clasp) -{ - return clasp == CallableProxyClassPtr || - clasp == UncallableProxyClassPtr || - clasp == OuterWindowProxyClassPtr; -} inline bool IsProxy(JSObject *obj) { - return IsProxyClass(GetObjectClass(obj)); -} - -BaseProxyHandler * -GetProxyHandler(JSObject *obj); - -inline bool IsScriptedProxy(JSObject *obj) -{ - if (!IsProxy(obj)) - return false; - - return GetProxyHandler(obj)->isScripted(); + return GetObjectClass(obj)->isProxy(); } /* @@ -343,15 +369,16 @@ inline bool IsScriptedProxy(JSObject *obj) * needs to store one slot's worth of data doesn't need to branch on what sort * of object it has. */ -const uint32_t PROXY_PRIVATE_SLOT = 0; -const uint32_t PROXY_HANDLER_SLOT = 1; -const uint32_t PROXY_EXTRA_SLOT = 2; +const uint32_t PROXY_PRIVATE_SLOT = 0; +const uint32_t PROXY_HANDLER_SLOT = 1; +const uint32_t PROXY_EXTRA_SLOT = 2; +const uint32_t PROXY_MINIMUM_SLOTS = 4; -inline BaseProxyHandler * +inline const BaseProxyHandler * GetProxyHandler(JSObject *obj) { JS_ASSERT(IsProxy(obj)); - return (BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate(); + return (const BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate(); } inline const Value & @@ -390,17 +417,24 @@ SetProxyExtra(JSObject *obj, size_t n, const Value &extra) SetReservedSlot(obj, PROXY_EXTRA_SLOT + n, extra); } +inline bool +IsScriptedProxy(JSObject *obj) +{ + return IsProxy(obj) && GetProxyHandler(obj)->isScripted(); +} + class MOZ_STACK_CLASS ProxyOptions { - public: - ProxyOptions() : callable_(false), - singleton_(false) + protected: + /* protected constructor for subclass */ + ProxyOptions(bool singletonArg, const Class *claspArg) + : singleton_(singletonArg), + clasp_(claspArg) {} - bool callable() const { return callable_; } - ProxyOptions &setCallable(bool flag) { - callable_ = flag; - return *this; - } + public: + ProxyOptions() : singleton_(false), + clasp_(UncallableProxyClassPtr) + {} bool singleton() const { return singleton_; } ProxyOptions &setSingleton(bool flag) { @@ -408,13 +442,26 @@ class MOZ_STACK_CLASS ProxyOptions { return *this; } + const Class *clasp() const { + return clasp_; + } + ProxyOptions &setClass(const Class *claspArg) { + clasp_ = claspArg; + return *this; + } + ProxyOptions &selectDefaultClass(bool callable) { + const Class *classp = callable? CallableProxyClassPtr : + UncallableProxyClassPtr; + return setClass(classp); + } + private: - bool callable_; bool singleton_; + const Class *clasp_; }; JS_FRIEND_API(JSObject *) -NewProxyObject(JSContext *cx, BaseProxyHandler *handler, HandleValue priv, +NewProxyObject(JSContext *cx, const BaseProxyHandler *handler, HandleValue priv, JSObject *proto, JSObject *parent, const ProxyOptions &options = ProxyOptions()); JSObject * @@ -424,15 +471,15 @@ class JS_FRIEND_API(AutoEnterPolicy) { public: typedef BaseProxyHandler::Action Action; - AutoEnterPolicy(JSContext *cx, BaseProxyHandler *handler, + AutoEnterPolicy(JSContext *cx, const BaseProxyHandler *handler, HandleObject wrapper, HandleId id, Action act, bool mayThrow) -#ifdef DEBUG +#ifdef JS_DEBUG : context(nullptr) #endif { - allow = handler->hasPolicy() ? handler->enter(cx, wrapper, id, act, &rv) - : true; - recordEnter(cx, wrapper, id); + allow = handler->hasSecurityPolicy() ? handler->enter(cx, wrapper, id, act, &rv) + : true; + recordEnter(cx, wrapper, id, act); // We want to throw an exception if all of the following are true: // * The policy disallowed access. // * The policy set rv to false, indicating that we should throw. @@ -449,48 +496,65 @@ class JS_FRIEND_API(AutoEnterPolicy) protected: // no-op constructor for subclass AutoEnterPolicy() -#ifdef DEBUG +#ifdef JS_DEBUG : context(nullptr) + , enteredAction(BaseProxyHandler::NONE) #endif {}; void reportErrorIfExceptionIsNotPending(JSContext *cx, jsid id); bool allow; bool rv; -#ifdef DEBUG +#ifdef JS_DEBUG JSContext *context; mozilla::Maybe enteredProxy; mozilla::Maybe enteredId; + Action enteredAction; + // NB: We explicitly don't track the entered action here, because sometimes // SET traps do an implicit GET during their implementation, leading to // spurious assertions. AutoEnterPolicy *prev; - void recordEnter(JSContext *cx, HandleObject proxy, HandleId id); + void recordEnter(JSContext *cx, HandleObject proxy, HandleId id, Action act); void recordLeave(); - friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id); + friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id, Action act); #else - inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id) {} + inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id, Action act) {} inline void recordLeave() {} #endif }; -#ifdef DEBUG +#ifdef JS_DEBUG class JS_FRIEND_API(AutoWaivePolicy) : public AutoEnterPolicy { public: - AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id) + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) { allow = true; - recordEnter(cx, proxy, id); + recordEnter(cx, proxy, id, act); } }; #else class JS_FRIEND_API(AutoWaivePolicy) { - public: AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id) {}; + public: + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) + {} }; #endif +#ifdef JS_DEBUG +extern JS_FRIEND_API(void) +assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act); +#else +inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act) +{}; +#endif + } /* namespace js */ extern JS_FRIEND_API(JSObject *) diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/jspubtd.h b/frameworks/js-bindings/external/spidermonkey/include/win32/jspubtd.h index 9683c23ea4..ffd75e2e5c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/jspubtd.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/jspubtd.h @@ -11,6 +11,7 @@ * JS public API typedefs. */ +#include "mozilla/Assertions.h" #include "mozilla/LinkedList.h" #include "mozilla/NullPtr.h" #include "mozilla/PodOperations.h" @@ -20,7 +21,7 @@ #include "js/TypeDecls.h" -#if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING) || defined(DEBUG) +#if defined(JSGC_USE_EXACT_ROOTING) || defined(JS_DEBUG) # define JSGC_TRACK_EXACT_ROOTS #endif @@ -32,23 +33,25 @@ class CallArgs; template class Rooted; -class JS_PUBLIC_API(AutoGCRooter); - -class JS_PUBLIC_API(CompileOptions); -class JS_PUBLIC_API(ReadOnlyCompileOptions); -class JS_PUBLIC_API(OwningCompileOptions); +class JS_FRIEND_API(CompileOptions); +class JS_FRIEND_API(ReadOnlyCompileOptions); +class JS_FRIEND_API(OwningCompileOptions); class JS_PUBLIC_API(CompartmentOptions); struct Zone; } /* namespace JS */ +namespace js { +struct ContextFriendFields; +} // namespace js + /* * Run-time version enumeration. For compile-time version checking, please use * the JS_HAS_* macros in jsversion.h, or use MOZJS_MAJOR_VERSION, * MOZJS_MINOR_VERSION, MOZJS_PATCH_VERSION, and MOZJS_ALPHA definitions. */ -typedef enum JSVersion { +enum JSVersion { JSVERSION_ECMA_3 = 148, JSVERSION_1_6 = 160, JSVERSION_1_7 = 170, @@ -57,10 +60,10 @@ typedef enum JSVersion { JSVERSION_DEFAULT = 0, JSVERSION_UNKNOWN = -1, JSVERSION_LATEST = JSVERSION_ECMA_5 -} JSVersion; +}; /* Result of typeof operator enumeration. */ -typedef enum JSType { +enum JSType { JSTYPE_VOID, /* undefined */ JSTYPE_OBJECT, /* object */ JSTYPE_FUNCTION, /* function */ @@ -68,44 +71,23 @@ typedef enum JSType { JSTYPE_NUMBER, /* number */ JSTYPE_BOOLEAN, /* boolean */ JSTYPE_NULL, /* null */ + JSTYPE_SYMBOL, /* symbol */ JSTYPE_LIMIT -} JSType; +}; /* Dense index into cached prototypes and class atoms for standard objects. */ -typedef enum JSProtoKey { +enum JSProtoKey { #define PROTOKEY_AND_INITIALIZER(name,code,init,clasp) JSProto_##name = code, JS_FOR_EACH_PROTOTYPE(PROTOKEY_AND_INITIALIZER) #undef PROTOKEY_AND_INITIALIZER JSProto_LIMIT -} JSProtoKey; - -/* js_CheckAccess mode enumeration. */ -typedef enum JSAccessMode { - JSACC_PROTO = 0, /* XXXbe redundant w.r.t. id */ - - /* - * enum value #1 formerly called JSACC_PARENT, - * gap preserved for ABI compatibility. - */ - - /* - * enum value #2 formerly called JSACC_IMPORT, - * gap preserved for ABI compatibility. - */ - - JSACC_WATCH = 3, /* a watchpoint on object foo for id 'bar' */ - JSACC_READ = 4, /* a "get" of foo.bar */ - JSACC_WRITE = 8, /* a "set" of foo.bar = baz */ - JSACC_LIMIT -} JSAccessMode; - -#define JSACC_TYPEMASK (JSACC_WRITE - 1) +}; /* * This enum type is used to control the behavior of a JSObject property * iterator function that has type JSNewEnumerate. */ -typedef enum JSIterateOp { +enum JSIterateOp { /* Create new iterator state over enumerable properties. */ JSENUMERATE_INIT, @@ -117,12 +99,13 @@ typedef enum JSIterateOp { /* Destroy iterator state. */ JSENUMERATE_DESTROY -} JSIterateOp; +}; -/* See JSVAL_TRACE_KIND and JSTraceCallback in jsapi.h. */ -typedef enum { +/* See Value::gcKind() and JSTraceCallback in Tracer.h. */ +enum JSGCTraceKind { JSTRACE_OBJECT, JSTRACE_STRING, + JSTRACE_SYMBOL, JSTRACE_SCRIPT, /* @@ -130,37 +113,36 @@ typedef enum { * it implements JSTraceCallback. */ JSTRACE_LAZY_SCRIPT, - JSTRACE_IONCODE, + JSTRACE_JITCODE, JSTRACE_SHAPE, JSTRACE_BASE_SHAPE, JSTRACE_TYPE_OBJECT, JSTRACE_LAST = JSTRACE_TYPE_OBJECT -} JSGCTraceKind; - -/* Struct typedefs and class forward declarations. */ -typedef struct JSClass JSClass; -typedef struct JSCompartment JSCompartment; -typedef struct JSConstDoubleSpec JSConstDoubleSpec; -typedef struct JSCrossCompartmentCall JSCrossCompartmentCall; -typedef struct JSErrorReport JSErrorReport; -typedef struct JSExceptionState JSExceptionState; -typedef struct JSFunctionSpec JSFunctionSpec; -typedef struct JSIdArray JSIdArray; -typedef struct JSLocaleCallbacks JSLocaleCallbacks; -typedef struct JSObjectMap JSObjectMap; -typedef struct JSPrincipals JSPrincipals; -typedef struct JSPropertyDescriptor JSPropertyDescriptor; -typedef struct JSPropertyName JSPropertyName; -typedef struct JSPropertySpec JSPropertySpec; -typedef struct JSRuntime JSRuntime; -typedef struct JSSecurityCallbacks JSSecurityCallbacks; -typedef struct JSStructuredCloneCallbacks JSStructuredCloneCallbacks; -typedef struct JSStructuredCloneReader JSStructuredCloneReader; -typedef struct JSStructuredCloneWriter JSStructuredCloneWriter; -typedef struct JSTracer JSTracer; - -class JSFlatString; -class JSStableString; // long story +}; + +/* Struct forward declarations. */ +struct JSClass; +struct JSCompartment; +struct JSConstDoubleSpec; +struct JSCrossCompartmentCall; +struct JSErrorReport; +struct JSExceptionState; +struct JSFunctionSpec; +struct JSIdArray; +struct JSLocaleCallbacks; +struct JSObjectMap; +struct JSPrincipals; +struct JSPropertyDescriptor; +struct JSPropertyName; +struct JSPropertySpec; +struct JSRuntime; +struct JSSecurityCallbacks; +struct JSStructuredCloneCallbacks; +struct JSStructuredCloneReader; +struct JSStructuredCloneWriter; +class JS_PUBLIC_API(JSTracer); + +class JSFlatString; #ifdef JS_THREADSAFE typedef struct PRCallOnceType JSCallOnceType; @@ -182,6 +164,7 @@ namespace js { namespace gc { class StoreBuffer; void MarkPersistentRootedChains(JSTracer *); +void FinishPersistentRootedChains(JSRuntime *); } } @@ -197,24 +180,18 @@ struct Runtime bool needsBarrier_; #ifdef JSGC_GENERATIONAL - /* Allow inlining of Nursery::isInside. */ - uintptr_t gcNurseryStart_; - uintptr_t gcNurseryEnd_; - private: js::gc::StoreBuffer *gcStoreBufferPtr_; #endif public: - Runtime( + explicit Runtime( #ifdef JSGC_GENERATIONAL js::gc::StoreBuffer *storeBuffer #endif ) : needsBarrier_(false) #ifdef JSGC_GENERATIONAL - , gcNurseryStart_(0) - , gcNurseryEnd_(0) , gcStoreBufferPtr_(storeBuffer) #endif {} @@ -235,7 +212,7 @@ struct Runtime private: template friend class JS::PersistentRooted; friend void js::gc::MarkPersistentRootedChains(JSTracer *); - friend void ::js_FinishGC(JSRuntime *rt); + friend void js::gc::FinishPersistentRootedChains(JSRuntime *rt); mozilla::LinkedList functionPersistentRooteds; mozilla::LinkedList idPersistentRooteds; @@ -274,6 +251,75 @@ inline mozilla::LinkedList &Runtime::getPersistentRootedList() { return valuePersistentRooteds; } } /* namespace shadow */ + +class JS_PUBLIC_API(AutoGCRooter) +{ + public: + AutoGCRooter(JSContext *cx, ptrdiff_t tag); + AutoGCRooter(js::ContextFriendFields *cx, ptrdiff_t tag); + + ~AutoGCRooter() { + MOZ_ASSERT(this == *stackTop); + *stackTop = down; + } + + /* Implemented in gc/RootMarking.cpp. */ + inline void trace(JSTracer *trc); + static void traceAll(JSTracer *trc); + static void traceAllWrappers(JSTracer *trc); + + /* T must be a context type */ + template + static void traceAllInContext(T* cx, JSTracer *trc) { + for (AutoGCRooter *gcr = cx->autoGCRooters; gcr; gcr = gcr->down) + gcr->trace(trc); + } + + protected: + AutoGCRooter * const down; + + /* + * Discriminates actual subclass of this being used. If non-negative, the + * subclass roots an array of values of the length stored in this field. + * If negative, meaning is indicated by the corresponding value in the enum + * below. Any other negative value indicates some deeper problem such as + * memory corruption. + */ + ptrdiff_t tag_; + + enum { + VALARRAY = -2, /* js::AutoValueArray */ + PARSER = -3, /* js::frontend::Parser */ + SHAPEVECTOR = -4, /* js::AutoShapeVector */ + IDARRAY = -6, /* js::AutoIdArray */ + DESCVECTOR = -7, /* js::AutoPropDescVector */ + VALVECTOR = -10, /* js::AutoValueVector */ + IDVECTOR = -13, /* js::AutoIdVector */ + OBJVECTOR = -14, /* js::AutoObjectVector */ + STRINGVECTOR =-15, /* js::AutoStringVector */ + SCRIPTVECTOR =-16, /* js::AutoScriptVector */ + NAMEVECTOR = -17, /* js::AutoNameVector */ + HASHABLEVALUE=-18, /* js::HashableValue */ + IONMASM = -19, /* js::jit::MacroAssembler */ + IONALLOC = -20, /* js::jit::AutoTempAllocatorRooter */ + WRAPVECTOR = -21, /* js::AutoWrapperVector */ + WRAPPER = -22, /* js::AutoWrapperRooter */ + OBJOBJHASHMAP=-23, /* js::AutoObjectObjectHashMap */ + OBJU32HASHMAP=-24, /* js::AutoObjectUnsigned32HashMap */ + OBJHASHSET = -25, /* js::AutoObjectHashSet */ + JSONPARSER = -26, /* js::JSONParser */ + CUSTOM = -27, /* js::CustomAutoRooter */ + FUNVECTOR = -28 /* js::AutoFunctionVector */ + }; + + private: + AutoGCRooter ** const stackTop; + + /* No copy or assignment semantics. */ + AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; + void operator=(AutoGCRooter &ida) MOZ_DELETE; +}; + } /* namespace JS */ namespace js { @@ -287,13 +333,11 @@ namespace js { enum ParallelResult { TP_SUCCESS, TP_RETRY_SEQUENTIALLY, TP_RETRY_AFTER_GC, TP_FATAL }; struct ThreadSafeContext; -struct ForkJoinSlice; +class ForkJoinContext; class ExclusiveContext; class Allocator; -class SkipRoot; - enum ThingRootKind { THING_ROOT_OBJECT, @@ -301,14 +345,16 @@ enum ThingRootKind THING_ROOT_BASE_SHAPE, THING_ROOT_TYPE_OBJECT, THING_ROOT_STRING, - THING_ROOT_ION_CODE, + THING_ROOT_SYMBOL, + THING_ROOT_JIT_CODE, THING_ROOT_SCRIPT, + THING_ROOT_LAZY_SCRIPT, THING_ROOT_ID, - THING_ROOT_PROPERTY_ID, THING_ROOT_VALUE, THING_ROOT_TYPE, THING_ROOT_BINDINGS, THING_ROOT_PROPERTY_DESCRIPTOR, + THING_ROOT_PROP_DESC, THING_ROOT_LIMIT }; @@ -343,6 +389,7 @@ template <> struct RootKind : SpecificRootKind struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; template <> struct RootKind : SpecificRootKind {}; @@ -364,9 +411,6 @@ struct ContextFriendFields { #ifdef JSGC_TRACK_EXACT_ROOTS mozilla::PodArrayZero(thingGCRooters); -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - skipGCRooters = nullptr; #endif } @@ -379,31 +423,31 @@ struct ContextFriendFields } #ifdef JSGC_TRACK_EXACT_ROOTS + private: /* * Stack allocated GC roots for stack GC heap pointers, which may be * overwritten if moved during a GC. */ JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* - * Stack allocated list of stack locations which hold non-relocatable - * GC heap pointers (where the target is rooted somewhere else) or integer - * values which may be confused for GC heap pointers. These are used to - * suppress false positives which occur when a rooting analysis treats the - * location as holding a relocatable pointer, but have no other effect on - * GC behavior. - */ - SkipRoot *skipGCRooters; + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } + #endif + void checkNoGCRooters(); + /* Stack of thread-stack-allocated GC roots. */ JS::AutoGCRooter *autoGCRooters; friend JSRuntime *GetRuntime(const JSContext *cx); friend JSCompartment *GetContextCompartment(const JSContext *cx); friend JS::Zone *GetContextZone(const JSContext *cx); + template friend class JS::Rooted; }; /* @@ -447,7 +491,7 @@ struct PerThreadDataFriendFields struct PerThreadDummy { void *field1; uintptr_t field2; -#ifdef DEBUG +#ifdef JS_DEBUG uint64_t field3; #endif } mainThread; @@ -458,23 +502,19 @@ struct PerThreadDataFriendFields PerThreadDataFriendFields(); #ifdef JSGC_TRACK_EXACT_ROOTS + private: /* * Stack allocated GC roots for stack GC heap pointers, which may be * overwritten if moved during a GC. */ JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; -#endif -#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE) - /* - * Stack allocated list of stack locations which hold non-relocatable - * GC heap pointers (where the target is rooted somewhere else) or integer - * values which may be confused for GC heap pointers. These are used to - * suppress false positives which occur when a rooting analysis treats the - * location as holding a relocatable pointer, but have no other effect on - * GC behavior. - */ - SkipRoot *skipGCRooters; + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } #endif /* Limit pointer for checking native stack consumption. */ @@ -499,6 +539,8 @@ struct PerThreadDataFriendFields return reinterpret_cast( reinterpret_cast(rt) + RuntimeMainThreadOffset); } + + template friend class JS::Rooted; }; } /* namespace js */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/jstypes.h b/frameworks/js-bindings/external/spidermonkey/include/win32/jstypes.h index d5b15ccb1d..e9927bca0d 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/jstypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/jstypes.h @@ -77,8 +77,13 @@ # define JS_PUBLIC_DATA(t) MOZ_IMPORT_DATA t #endif -#define JS_FRIEND_API(t) JS_PUBLIC_API(t) -#define JS_FRIEND_DATA(t) JS_PUBLIC_DATA(t) +#if defined(STATIC_JS_API) || defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API) +# define JS_FRIEND_API(t) MOZ_EXPORT t +# define JS_FRIEND_DATA(t) MOZ_EXPORT t +#else +# define JS_FRIEND_API(t) MOZ_IMPORT_API t +# define JS_FRIEND_DATA(t) MOZ_IMPORT_DATA t +#endif #if defined(_MSC_VER) && defined(_M_IX86) #define JS_FASTCALL __fastcall @@ -89,22 +94,6 @@ #define JS_NO_FASTCALL #endif -#ifndef JS_ALWAYS_INLINE -#define JS_ALWAYS_INLINE MOZ_ALWAYS_INLINE -#endif - -#ifndef JS_NEVER_INLINE -#define JS_NEVER_INLINE MOZ_NEVER_INLINE -#endif - -#ifndef JS_WARN_UNUSED_RESULT -# if defined __GNUC__ -# define JS_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -# else -# define JS_WARN_UNUSED_RESULT -# endif -#endif - /*********************************************************************** ** MACROS: JS_BEGIN_MACRO ** JS_END_MACRO @@ -122,15 +111,6 @@ # define JS_END_MACRO } while (0) #endif -/*********************************************************************** -** MACROS: JS_BEGIN_EXTERN_C -** JS_END_EXTERN_C -** DESCRIPTION: -** Macro shorthands for conditional C++ extern block delimiters. -***********************************************************************/ -#define JS_BEGIN_EXTERN_C MOZ_BEGIN_EXTERN_C -#define JS_END_EXTERN_C MOZ_END_EXTERN_C - /*********************************************************************** ** MACROS: JS_BIT ** JS_BITMASK @@ -143,8 +123,6 @@ /*********************************************************************** ** MACROS: JS_HOWMANY ** JS_ROUNDUP -** JS_MIN -** JS_MAX ** DESCRIPTION: ** Commonly used macros for operations on compatible types. ***********************************************************************/ @@ -183,34 +161,6 @@ # error "Implement me" #endif -/*********************************************************************** -** MACROS: JS_LIKELY -** JS_UNLIKELY -** DESCRIPTION: -** These macros allow you to give a hint to the compiler about branch -** probability so that it can better optimize. Use them like this: -** -** if (JS_LIKELY(v == 1)) { -** ... expected code path ... -** } -** -** if (JS_UNLIKELY(v == 0)) { -** ... non-expected code path ... -** } -** -***********************************************************************/ -#ifdef __GNUC__ - -# define JS_LIKELY(x) (__builtin_expect((x), 1)) -# define JS_UNLIKELY(x) (__builtin_expect((x), 0)) - -#else - -# define JS_LIKELY(x) (x) -# define JS_UNLIKELY(x) (x) - -#endif - /*********************************************************************** ** MACROS: JS_ARRAY_LENGTH ** JS_ARRAY_END diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/jsversion.h b/frameworks/js-bindings/external/spidermonkey/include/win32/jsversion.h index 827a56981d..1f31e40b5e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/jsversion.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/jsversion.h @@ -25,6 +25,9 @@ #define JS_HAS_DESTRUCTURING 2 /* has [a,b] = ... or {p:a,q:b} = ... */ #define JS_HAS_GENERATOR_EXPRS 1 /* has (expr for (lhs in iterable)) */ #define JS_HAS_EXPR_CLOSURES 1 /* has function (formals) listexpr */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_TEMPLATE_STRINGS 1 /* has template string support */ +#endif /* Support for JS_NewGlobalObject. */ #define JS_HAS_NEW_GLOBAL_OBJECT 1 @@ -41,14 +44,9 @@ */ #define JS_OLD_GETTER_SETTER_METHODS 1 -/* A kill-switch for bug 586842. Embedders shouldn't touch this! */ -#define JS_USE_NEW_OBJECT_REPRESENTATION 0 - -#if JS_USE_NEW_OBJECT_REPRESENTATION -# define JS_NEW_OBJECT_REPRESENTATION_ONLY() ((void)0) -#else -# define JS_NEW_OBJECT_REPRESENTATION_ONLY() \ - MOZ_ASSUME_UNREACHABLE("don't call this! to be used in the new object representation") +/* Support for Symbols - Nightly-only for now. */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_SYMBOLS 1 #endif #endif /* jsversion_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/jswrapper.h b/frameworks/js-bindings/external/spidermonkey/include/win32/jswrapper.h index 1bf1e16664..a8a510c4f7 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/jswrapper.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/jswrapper.h @@ -15,6 +15,35 @@ namespace js { class DummyFrameGuard; +/* + * Helper for Wrapper::New default options. + * + * Callers of Wrapper::New() who wish to specify a prototype for the created + * Wrapper, *MUST* construct a WrapperOptions with a JSContext. + */ +class MOZ_STACK_CLASS WrapperOptions : public ProxyOptions { + public: + WrapperOptions() : ProxyOptions(false, nullptr), + proto_() + {} + + explicit WrapperOptions(JSContext *cx) : ProxyOptions(false, nullptr), + proto_() + { + proto_.construct(cx); + } + + inline JSObject *proto() const; + WrapperOptions &setProto(JSObject *protoArg) { + JS_ASSERT(!proto_.empty()); + proto_.ref() = protoArg; + return *this; + } + + private: + mozilla::Maybe proto_; +}; + /* * A wrapper is a proxy with a target object to which it generally forwards * operations, but may restrict access to certain operations or instrument @@ -27,7 +56,6 @@ class DummyFrameGuard; class JS_FRIEND_API(Wrapper) : public DirectProxyHandler { unsigned mFlags; - bool mSafeToUnwrap; public: using BaseProxyHandler::Action; @@ -38,23 +66,14 @@ class JS_FRIEND_API(Wrapper) : public DirectProxyHandler }; virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; - /* - * Wrappers can explicitly specify that they are unsafe to unwrap from a - * security perspective (as is the case for SecurityWrappers). If a wrapper - * is not safe to unwrap, operations requiring full access to the underlying - * object (via CheckedUnwrap) will throw. Otherwise, they will succeed. - */ - void setSafeToUnwrap(bool safe) { mSafeToUnwrap = safe; } - bool isSafeToUnwrap() { return mSafeToUnwrap; } + static JSObject *New(JSContext *cx, JSObject *obj, JSObject *parent, const Wrapper *handler, + const WrapperOptions *options = nullptr); - static JSObject *New(JSContext *cx, JSObject *obj, JSObject *proto, - JSObject *parent, Wrapper *handler); + static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, const Wrapper *handler); - static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, Wrapper *handler); - - static Wrapper *wrapperHandler(JSObject *wrapper); + static const Wrapper *wrapperHandler(JSObject *wrapper); static JSObject *wrappedObject(JSObject *wrapper); @@ -62,68 +81,78 @@ class JS_FRIEND_API(Wrapper) : public DirectProxyHandler return mFlags; } - explicit Wrapper(unsigned flags, bool hasPrototype = false); + explicit Wrapper(unsigned flags, bool hasPrototype = false, bool hasSecurityPolicy = false); virtual ~Wrapper(); - virtual bool finalizeInBackground(Value priv) MOZ_OVERRIDE; + virtual bool finalizeInBackground(Value priv) const MOZ_OVERRIDE; + + static const Wrapper singleton; + static const Wrapper singletonWithPrototype; - static Wrapper singleton; - static Wrapper singletonWithPrototype; + static JSObject *defaultProto; }; +inline JSObject * +WrapperOptions::proto() const +{ + return proto_.empty() ? Wrapper::defaultProto : proto_.ref(); +} + /* Base class for all cross compartment wrapper handlers. */ class JS_FRIEND_API(CrossCompartmentWrapper) : public Wrapper { public: - CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false); + explicit CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false, + bool hasSecurityPolicy = false); virtual ~CrossCompartmentWrapper(); /* ES5 Harmony fundamental wrapper traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, - AutoIdVector &props) MOZ_OVERRIDE; - virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; /* ES5 Harmony derived wrapper traps. */ - virtual bool has(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool hasOwn(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; + virtual bool has(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool hasOwn(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; virtual bool get(JSContext *cx, HandleObject wrapper, HandleObject receiver, - HandleId id, MutableHandleValue vp) MOZ_OVERRIDE; + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool set(JSContext *cx, HandleObject wrapper, HandleObject receiver, - HandleId id, bool strict, MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool keys(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool keys(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; virtual bool iterate(JSContext *cx, HandleObject wrapper, unsigned flags, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject wrapper, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject wrapper, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject wrapper, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual JSString *fun_toString(JSContext *cx, HandleObject wrapper, - unsigned indent) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; - static CrossCompartmentWrapper singleton; - static CrossCompartmentWrapper singletonWithPrototype; + static const CrossCompartmentWrapper singleton; + static const CrossCompartmentWrapper singletonWithPrototype; }; /* @@ -139,25 +168,28 @@ template class JS_FRIEND_API(SecurityWrapper) : public Base { public: - SecurityWrapper(unsigned flags); + explicit SecurityWrapper(unsigned flags, bool hasPrototype = false); - virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) MOZ_OVERRIDE; - virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Wrapper::Action act, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; + + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, - JS::HandleObject callable) MOZ_OVERRIDE; - virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) MOZ_OVERRIDE; + JS::HandleObject callable) const MOZ_OVERRIDE; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const MOZ_OVERRIDE; /* * Allow our subclasses to select the superclass behavior they want without @@ -179,48 +211,42 @@ class JS_FRIEND_API(DeadObjectProxy) : public BaseProxyHandler explicit DeadObjectProxy(); /* ES5 Harmony fundamental wrapper traps. */ - virtual bool preventExtensions(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc, - unsigned flags) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, - MutableHandle desc) MOZ_OVERRIDE; + MutableHandle desc) const MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, - AutoIdVector &props) MOZ_OVERRIDE; - virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; - virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; /* Spidermonkey extensions. */ - virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) MOZ_OVERRIDE; - virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; - virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) MOZ_OVERRIDE; + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) MOZ_OVERRIDE; + CallArgs args) const MOZ_OVERRIDE; virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, - bool *bp) MOZ_OVERRIDE; + bool *bp) const MOZ_OVERRIDE; virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, - JSContext *cx) MOZ_OVERRIDE; - virtual const char *className(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; - virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) MOZ_OVERRIDE; - virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE; + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, - MutableHandleValue vp) MOZ_OVERRIDE; - virtual bool getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver, - uint32_t index, MutableHandleValue vp, - bool *present) MOZ_OVERRIDE; + MutableHandleValue vp) const MOZ_OVERRIDE; virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, - MutableHandleObject protop) MOZ_OVERRIDE; + MutableHandleObject protop) const MOZ_OVERRIDE; - static DeadObjectProxy singleton; + static const DeadObjectProxy singleton; }; extern JSObject * TransparentObjectWrapper(JSContext *cx, HandleObject existing, HandleObject obj, - HandleObject wrappedProto, HandleObject parent, - unsigned flags); + HandleObject parent, unsigned flags); // Proxy family for wrappers. Public so that IsWrapper() can be fully inlined by // jsfriendapi users. @@ -295,8 +321,8 @@ RecomputeWrappers(JSContext *cx, const CompartmentFilter &sourceFilter, struct JS_FRIEND_API(AutoMaybeTouchDeadZones) { // The version that takes an object just uses it for its runtime. - AutoMaybeTouchDeadZones(JSContext *cx); - AutoMaybeTouchDeadZones(JSObject *obj); + explicit AutoMaybeTouchDeadZones(JSContext *cx); + explicit AutoMaybeTouchDeadZones(JSObject *obj); ~AutoMaybeTouchDeadZones(); private: diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Alignment.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Alignment.h index 29599d0ef1..0ac8a48779 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Alignment.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Alignment.h @@ -21,14 +21,14 @@ namespace mozilla { template class AlignmentFinder { - struct Aligner - { - char c; - T t; - }; - - public: - static const size_t alignment = sizeof(Aligner) - sizeof(T); + struct Aligner + { + char mChar; + T mT; + }; + +public: + static const size_t alignment = sizeof(Aligner) - sizeof(T); }; #define MOZ_ALIGNOF(T) mozilla::AlignmentFinder::alignment @@ -64,38 +64,38 @@ template struct AlignedElem; /* - * We have to specialize this template because GCC doesn't like __attribute__((aligned(foo))) where - * foo is a template parameter. + * We have to specialize this template because GCC doesn't like + * __attribute__((aligned(foo))) where foo is a template parameter. */ template<> struct AlignedElem<1> { - MOZ_ALIGNED_DECL(uint8_t elem, 1); + MOZ_ALIGNED_DECL(uint8_t elem, 1); }; template<> struct AlignedElem<2> { - MOZ_ALIGNED_DECL(uint8_t elem, 2); + MOZ_ALIGNED_DECL(uint8_t elem, 2); }; template<> struct AlignedElem<4> { - MOZ_ALIGNED_DECL(uint8_t elem, 4); + MOZ_ALIGNED_DECL(uint8_t elem, 4); }; template<> struct AlignedElem<8> { - MOZ_ALIGNED_DECL(uint8_t elem, 8); + MOZ_ALIGNED_DECL(uint8_t elem, 8); }; template<> struct AlignedElem<16> { - MOZ_ALIGNED_DECL(uint8_t elem, 16); + MOZ_ALIGNED_DECL(uint8_t elem, 16); }; /* @@ -111,25 +111,27 @@ struct AlignedElem<16> template struct AlignedStorage { - union U { - char bytes[Nbytes]; - uint64_t _; - } u; - - const void* addr() const { return u.bytes; } - void* addr() { return u.bytes; } + union U + { + char mBytes[Nbytes]; + uint64_t mDummy; + } u; + + const void* addr() const { return u.mBytes; } + void* addr() { return u.mBytes; } }; template struct AlignedStorage2 { - union U { - char bytes[sizeof(T)]; - uint64_t _; - } u; - - const T* addr() const { return reinterpret_cast(u.bytes); } - T* addr() { return static_cast(static_cast(u.bytes)); } + union U + { + char mBytes[sizeof(T)]; + uint64_t mDummy; + } u; + + const T* addr() const { return reinterpret_cast(u.mBytes); } + T* addr() { return static_cast(static_cast(u.mBytes)); } }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/AllocPolicy.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/AllocPolicy.h index 20087e93bb..357c632a02 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/AllocPolicy.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/AllocPolicy.h @@ -49,14 +49,31 @@ namespace mozilla { */ class MallocAllocPolicy { - public: - void* malloc_(size_t bytes) { return malloc(bytes); } - void* calloc_(size_t bytes) { return calloc(bytes, 1); } - void* realloc_(void* p, size_t oldBytes, size_t bytes) { return realloc(p, bytes); } - void free_(void* p) { free(p); } - void reportAllocOverflow() const {} -}; +public: + void* malloc_(size_t aBytes) + { + return malloc(aBytes); + } + + void* calloc_(size_t aBytes) + { + return calloc(aBytes, 1); + } + + void* realloc_(void* aPtr, size_t aOldBytes, size_t aBytes) + { + return realloc(aPtr, aBytes); + } + void free_(void* aPtr) + { + free(aPtr); + } + + void reportAllocOverflow() const + { + } +}; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Array.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Array.h index 5af9aaa133..b2ab578d4b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Array.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Array.h @@ -19,31 +19,35 @@ namespace mozilla { template class Array { - T arr[Length]; - - public: - T& operator[](size_t i) { - MOZ_ASSERT(i < Length); - return arr[i]; - } - - const T& operator[](size_t i) const { - MOZ_ASSERT(i < Length); - return arr[i]; - } + T mArr[Length]; + +public: + T& operator[](size_t aIndex) + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } + + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } }; template class Array { - public: - T& operator[](size_t i) { - MOZ_ASSUME_UNREACHABLE("indexing into zero-length array"); - } - - const T& operator[](size_t i) const { - MOZ_ASSUME_UNREACHABLE("indexing into zero-length array"); - } +public: + T& operator[](size_t aIndex) + { + MOZ_CRASH("indexing into zero-length array"); + } + + const T& operator[](size_t aIndex) const + { + MOZ_CRASH("indexing into zero-length array"); + } }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ArrayUtils.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ArrayUtils.h index e2226bf59d..44f5980c44 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ArrayUtils.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ArrayUtils.h @@ -18,22 +18,24 @@ #ifdef __cplusplus +#include "mozilla/Alignment.h" #include "mozilla/Array.h" +#include "mozilla/TypeTraits.h" namespace mozilla { /* - * Safely subtract two pointers when it is known that end >= begin. This avoids - * the common compiler bug that if (size_t(end) - size_t(begin)) has the MSB - * set, the unsigned subtraction followed by right shift will produce -1, or - * size_t(-1), instead of the real difference. + * Safely subtract two pointers when it is known that aEnd >= aBegin. This + * avoids the common compiler bug that if (size_t(aEnd) - size_t(aBegin)) has + * the MSB set, the unsigned subtraction followed by right shift will produce + * -1, or size_t(-1), instead of the real difference. */ template MOZ_ALWAYS_INLINE size_t -PointerRangeSize(T* begin, T* end) +PointerRangeSize(T* aBegin, T* aEnd) { - MOZ_ASSERT(end >= begin); - return (size_t(end) - size_t(begin)) / sizeof(T); + MOZ_ASSERT(aEnd >= aBegin); + return (size_t(aEnd) - size_t(aBegin)) / sizeof(T); } /* @@ -44,14 +46,14 @@ PointerRangeSize(T* begin, T* end) */ template MOZ_CONSTEXPR size_t -ArrayLength(T (&arr)[N]) +ArrayLength(T (&aArr)[N]) { return N; } template MOZ_CONSTEXPR size_t -ArrayLength(const Array& arr) +ArrayLength(const Array& aArr) { return N; } @@ -63,25 +65,100 @@ ArrayLength(const Array& arr) */ template MOZ_CONSTEXPR T* -ArrayEnd(T (&arr)[N]) +ArrayEnd(T (&aArr)[N]) { - return arr + ArrayLength(arr); + return aArr + ArrayLength(aArr); } template MOZ_CONSTEXPR T* -ArrayEnd(Array& arr) +ArrayEnd(Array& aArr) { - return &arr[0] + ArrayLength(arr); + return &aArr[0] + ArrayLength(aArr); } template MOZ_CONSTEXPR const T* -ArrayEnd(const Array& arr) +ArrayEnd(const Array& aArr) { - return &arr[0] + ArrayLength(arr); + return &aArr[0] + ArrayLength(aArr); } +namespace detail { + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % MOZ_ALIGNOF(AlignType)) == 0, + "performing a range-check with a misaligned pointer"); + } +}; + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + } +}; + +} // namespace detail + +/** + * Determines whether |aPtr| points at an object in the range [aBegin, aEnd). + * + * |aPtr| must have the same alignment as |aBegin| and |aEnd|. This usually + * should be achieved by ensuring |aPtr| points at a |U|, not just that it + * points at a |T|. + * + * It is a usage error for any argument to be misaligned. + * + * It's okay for T* to be void*, and if so U* may also be void*. In the latter + * case no argument is required to be aligned (obviously, as void* implies no + * particular alignment). + */ +template +inline typename EnableIf::value || + IsBaseOf::value || + IsVoid::value, + bool>::Type +IsInRange(T* aPtr, U* aBegin, U* aEnd) +{ + MOZ_ASSERT(aBegin <= aEnd); + detail::AlignedChecker::test(aPtr); + detail::AlignedChecker::test(aBegin); + detail::AlignedChecker::test(aEnd); + return aBegin <= static_cast(aPtr) && static_cast(aPtr) < aEnd; +} + +/** + * Convenience version of the above method when the valid range is specified as + * uintptr_t values. As above, |aPtr| must be aligned, and |aBegin| and |aEnd| + * must be aligned with respect to |T|. + */ +template +inline bool +IsInRange(T* aPtr, uintptr_t aBegin, uintptr_t aEnd) +{ + return IsInRange(aPtr, + reinterpret_cast(aBegin), reinterpret_cast(aEnd)); +} + +namespace detail { + +/* + * Helper for the MOZ_ARRAY_LENGTH() macro to make the length a typesafe + * compile-time constant even on compilers lacking constexpr support. + */ +template +char (&ArrayLengthHelper(T (&array)[N]))[N]; + +} /* namespace detail */ + } /* namespace mozilla */ #endif /* __cplusplus */ @@ -91,8 +168,8 @@ ArrayEnd(const Array& arr) * that can't use C++ template functions and for static_assert() calls that * can't call ArrayLength() when it is not a C++11 constexpr function. */ -#ifdef MOZ_HAVE_CXX11_CONSTEXPR -# define MOZ_ARRAY_LENGTH(array) mozilla::ArrayLength(array) +#ifdef __cplusplus +# define MOZ_ARRAY_LENGTH(array) sizeof(mozilla::detail::ArrayLengthHelper(array)) #else # define MOZ_ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0])) #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Assertions.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Assertions.h index 8a5fa205f9..a463b2768d 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Assertions.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Assertions.h @@ -9,9 +9,17 @@ #ifndef mozilla_Assertions_h #define mozilla_Assertions_h +#if defined(MOZILLA_INTERNAL_API) && defined(__cplusplus) +#define MOZ_DUMP_ASSERTION_STACK +#endif + #include "mozilla/Attributes.h" #include "mozilla/Compiler.h" #include "mozilla/Likely.h" +#include "mozilla/MacroArgs.h" +#ifdef MOZ_DUMP_ASSERTION_STACK +#include "nsTraceRefcnt.h" +#endif #include #include @@ -24,13 +32,13 @@ * number of undesired macros and symbols. */ # ifdef __cplusplus - extern "C" { +extern "C" { # endif - __declspec(dllimport) int __stdcall - TerminateProcess(void* hProcess, unsigned int uExitCode); - __declspec(dllimport) void* __stdcall GetCurrentProcess(void); +__declspec(dllimport) int __stdcall +TerminateProcess(void* hProcess, unsigned int uExitCode); +__declspec(dllimport) void* __stdcall GetCurrentProcess(void); # ifdef __cplusplus - } +} # endif #else # include @@ -116,33 +124,42 @@ extern "C" { #endif /* - * Prints |s| as an assertion failure (using file and ln as the location of the - * assertion) to the standard debug-output channel. + * Prints |aStr| as an assertion failure (using aFilename and aLine as the + * location of the assertion) to the standard debug-output channel. * * Usually you should use MOZ_ASSERT or MOZ_CRASH instead of this method. This * method is primarily for internal use in this header, and only secondarily * for use in implementing release-build assertions. */ static MOZ_ALWAYS_INLINE void -MOZ_ReportAssertionFailure(const char* s, const char* file, int ln) +MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS { #ifdef ANDROID __android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert", - "Assertion failure: %s, at %s:%d\n", s, file, ln); + "Assertion failure: %s, at %s:%d\n", + aStr, aFilename, aLine); #else - fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln); + fprintf(stderr, "Assertion failure: %s, at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif fflush(stderr); #endif } static MOZ_ALWAYS_INLINE void -MOZ_ReportCrash(const char* s, const char* file, int ln) +MOZ_ReportCrash(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS { #ifdef ANDROID - __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", - "Hit MOZ_CRASH(%s) at %s:%d\n", s, file, ln); + __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", + "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); #else - fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", s, file, ln); + fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif fflush(stderr); #endif } @@ -238,7 +255,7 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} do { \ MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \ MOZ_REALLY_CRASH(); \ - } while(0) + } while (0) #endif #ifdef __cplusplus @@ -279,52 +296,108 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} * MOZ_RELEASE_ASSERT, which applies to non-debug builds as well. */ +/* + * Implement MOZ_VALIDATE_ASSERT_CONDITION_TYPE, which is used to guard against + * accidentally passing something unintended in lieu of an assertion condition. + */ + +#ifdef __cplusplus +# if defined(__clang__) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# elif defined(__GNUC__) +// B2G GCC 4.4 has insufficient decltype support. +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# endif +# elif defined(_MSC_VER) +// Disabled for now because of insufficient decltype support. Bug 1004028. +# endif +#endif + +#ifdef MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# include "mozilla/TypeTraits.h" +namespace mozilla { +namespace detail { + +template +struct IsFunction +{ + static const bool value = false; +}; + +template +struct IsFunction +{ + static const bool value = true; +}; + +template +void ValidateAssertConditionType() +{ + typedef typename RemoveReference::Type ValueT; + static_assert(!IsArray::value, + "Expected boolean assertion condition, got an array or a " + "string!"); + static_assert(!IsFunction::value, + "Expected boolean assertion condition, got a function! Did " + "you intend to call that function?"); + static_assert(!IsFloatingPoint::value, + "It's often a bad idea to assert that a floating-point number " + "is nonzero, because such assertions tend to intermittently " + "fail. Shouldn't your code gracefully handle this case instead " + "of asserting? Anyway, if you really want to do that, write an " + "explicit boolean condition, like !!x or x!=0."); +} + +} // namespace detail +} // namespace mozilla +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) \ + mozilla::detail::ValidateAssertConditionType() +#else +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) +#endif + /* First the single-argument form. */ #define MOZ_ASSERT_HELPER1(expr) \ - do { \ - if (MOZ_UNLIKELY(!(expr))) { \ - MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } \ - } while (0) + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) /* Now the two-argument form. */ #define MOZ_ASSERT_HELPER2(expr, explain) \ - do { \ - if (MOZ_UNLIKELY(!(expr))) { \ - MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } \ - } while (0) -/* And now, helper macrology up the wazoo. */ -/* - * Count the number of arguments passed to MOZ_ASSERT, very carefully - * tiptoeing around an MSVC bug where it improperly expands __VA_ARGS__ as a - * single token in argument lists. See these URLs for details: - * - * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement - * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 - */ -#define MOZ_COUNT_ASSERT_ARGS_IMPL2(_1, _2, count, ...) \ - count -#define MOZ_COUNT_ASSERT_ARGS_IMPL(args) \ - MOZ_COUNT_ASSERT_ARGS_IMPL2 args -#define MOZ_COUNT_ASSERT_ARGS(...) \ - MOZ_COUNT_ASSERT_ARGS_IMPL((__VA_ARGS__, 2, 1, 0)) -/* Pick the right helper macro to invoke. */ -#define MOZ_ASSERT_CHOOSE_HELPER2(count) MOZ_ASSERT_HELPER##count -#define MOZ_ASSERT_CHOOSE_HELPER1(count) MOZ_ASSERT_CHOOSE_HELPER2(count) -#define MOZ_ASSERT_CHOOSE_HELPER(count) MOZ_ASSERT_CHOOSE_HELPER1(count) -/* The actual macros. */ -#define MOZ_ASSERT_GLUE(x, y) x y + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) + +#define MOZ_RELEASE_ASSERT_GLUE(a, b) a b #define MOZ_RELEASE_ASSERT(...) \ - MOZ_ASSERT_GLUE(MOZ_ASSERT_CHOOSE_HELPER(MOZ_COUNT_ASSERT_ARGS(__VA_ARGS__)), \ - (__VA_ARGS__)) + MOZ_RELEASE_ASSERT_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \ + (__VA_ARGS__)) + #ifdef DEBUG # define MOZ_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) #else -# define MOZ_ASSERT(...) do { } while(0) +# define MOZ_ASSERT(...) do { } while (0) #endif /* DEBUG */ +/* + * MOZ_NIGHTLY_ASSERT is defined for both debug and release builds on the + * Nightly channel, but only debug builds on Aurora, Beta, and Release. + */ +#if defined(NIGHTLY_BUILD) +# define MOZ_NIGHTLY_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) +#else +# define MOZ_NIGHTLY_ASSERT(...) MOZ_ASSERT(__VA_ARGS__) +#endif + /* * MOZ_ASSERT_IF(cond1, cond2) is equivalent to MOZ_ASSERT(cond2) if cond1 is * true. @@ -337,19 +410,20 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} #ifdef DEBUG # define MOZ_ASSERT_IF(cond, expr) \ do { \ - if (cond) \ + if (cond) { \ MOZ_ASSERT(expr); \ + } \ } while (0) #else # define MOZ_ASSERT_IF(cond, expr) do { } while (0) #endif /* - * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that it is - * undefined behavior for execution to reach this point. No guarantees are made - * about what will happen if this is reached at runtime. Most code should - * probably use the higher level MOZ_ASSUME_UNREACHABLE, which uses this when - * appropriate. + * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that + * it is undefined behavior for execution to reach this point. No guarantees + * are made about what will happen if this is reached at runtime. Most code + * should use MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE because it has extra + * asserts. */ #if defined(__clang__) # define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable() @@ -379,21 +453,22 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} #endif /* - * MOZ_ASSUME_UNREACHABLE([reason]) tells the compiler that it can assume that - * the macro call cannot be reached during execution. This lets the compiler - * generate better-optimized code under some circumstances, at the expense of - * the program's behavior being undefined if control reaches the - * MOZ_ASSUME_UNREACHABLE. + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE([reason]) tells the compiler that it + * can assume that the macro call cannot be reached during execution. This lets + * the compiler generate better-optimized code under some circumstances, at the + * expense of the program's behavior being undefined if control reaches the + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE. * * In Gecko, you probably should not use this macro outside of performance- or * size-critical code, because it's unsafe. If you don't care about code size * or performance, you should probably use MOZ_ASSERT or MOZ_CRASH. * * SpiderMonkey is a different beast, and there it's acceptable to use - * MOZ_ASSUME_UNREACHABLE more widely. + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE more widely. * - * Note that MOZ_ASSUME_UNREACHABLE is noreturn, so it's valid not to return a - * value following a MOZ_ASSUME_UNREACHABLE call. + * Note that MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE is noreturn, so it's valid + * not to return a value following a MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE + * call. * * Example usage: * @@ -413,19 +488,32 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} * case VALUE_FLOAT: * return (int) *(float*) value; * default: - * MOZ_ASSUME_UNREACHABLE("can only handle VALUE_INT and VALUE_FLOAT"); + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected ValueType"); * } * } */ -#if defined(DEBUG) -# define MOZ_ASSUME_UNREACHABLE(...) \ - do { \ - MOZ_ASSERT(false, "MOZ_ASSUME_UNREACHABLE(" __VA_ARGS__ ")"); \ - MOZ_ASSUME_UNREACHABLE_MARKER(); \ - } while (0) -#else -# define MOZ_ASSUME_UNREACHABLE(reason) MOZ_ASSUME_UNREACHABLE_MARKER() -#endif + +/* + * Assert in all debug builds plus the Nightly channel's release builds. Take + * this extra testing precaution because hitting MOZ_ASSUME_UNREACHABLE_MARKER + * could trigger exploitable undefined behavior. + */ +#define MOZ_ASSERT_UNREACHABLE(reason) \ + MOZ_NIGHTLY_ASSERT(false, "MOZ_ASSERT_UNREACHABLE: " reason) + +#define MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) \ + do { \ + MOZ_ASSERT_UNREACHABLE(reason); \ + MOZ_ASSUME_UNREACHABLE_MARKER(); \ + } while (0) + +/* + * TODO: Bug 990764: Audit all MOZ_ASSUME_UNREACHABLE calls and replace them + * with MOZ_ASSERT_UNREACHABLE, MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE, or + * MOZ_CRASH. For now, preserve the macro's same meaning of unreachable. + */ +#define MOZ_ASSUME_UNREACHABLE(reason) \ + MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) /* * MOZ_ALWAYS_TRUE(expr) and MOZ_ALWAYS_FALSE(expr) always evaluate the provided @@ -441,4 +529,6 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} # define MOZ_ALWAYS_FALSE(expr) ((void)(expr)) #endif +#undef MOZ_DUMP_ASSERTION_STACK + #endif /* mozilla_Assertions_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Atomics.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Atomics.h index 03ae7c34f3..71d95c61ba 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Atomics.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Atomics.h @@ -41,6 +41,13 @@ # define MOZ_HAVE_CXX11_ATOMICS # endif #elif defined(_MSC_VER) && _MSC_VER >= 1700 +# if defined(DEBUG) + /* + * Provide our own failure code since we're having trouble linking to + * std::_Debug_message (bug 982310). + */ +# define _INVALID_MEMORY_ORDER MOZ_CRASH("Invalid memory order") +# endif # define MOZ_HAVE_CXX11_ATOMICS #endif @@ -107,6 +114,7 @@ enum MemoryOrdering { * ordering if you can't easily test non-x86 architectures! */ Relaxed, + /* * When an atomic value is updated with ReleaseAcquire ordering, and * that new value is observed with ReleaseAcquire ordering, prior @@ -128,6 +136,7 @@ enum MemoryOrdering { * a good, hard look at actual lock or mutex primitives first. */ ReleaseAcquire, + /* * When an atomic value is updated with SequentiallyConsistent * ordering, all writes observable when the update is observed, just @@ -177,126 +186,154 @@ template struct AtomicOrderConstraints; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_relaxed; - static const std::memory_order LoadOrder = std::memory_order_relaxed; - static const std::memory_order StoreOrder = std::memory_order_relaxed; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_relaxed; + static const std::memory_order AtomicRMWOrder = std::memory_order_relaxed; + static const std::memory_order LoadOrder = std::memory_order_relaxed; + static const std::memory_order StoreOrder = std::memory_order_relaxed; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_relaxed; }; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_acq_rel; - static const std::memory_order LoadOrder = std::memory_order_acquire; - static const std::memory_order StoreOrder = std::memory_order_release; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_acquire; + static const std::memory_order AtomicRMWOrder = std::memory_order_acq_rel; + static const std::memory_order LoadOrder = std::memory_order_acquire; + static const std::memory_order StoreOrder = std::memory_order_release; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_acquire; }; template<> struct AtomicOrderConstraints { - static const std::memory_order AtomicRMWOrder = std::memory_order_seq_cst; - static const std::memory_order LoadOrder = std::memory_order_seq_cst; - static const std::memory_order StoreOrder = std::memory_order_seq_cst; - static const std::memory_order CompareExchangeFailureOrder = - std::memory_order_seq_cst; + static const std::memory_order AtomicRMWOrder = std::memory_order_seq_cst; + static const std::memory_order LoadOrder = std::memory_order_seq_cst; + static const std::memory_order StoreOrder = std::memory_order_seq_cst; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_seq_cst; }; template struct IntrinsicBase { - typedef std::atomic ValueType; - typedef AtomicOrderConstraints OrderedOp; + typedef std::atomic ValueType; + typedef AtomicOrderConstraints OrderedOp; }; template struct IntrinsicMemoryOps : public IntrinsicBase { - typedef IntrinsicBase Base; - static T load(const typename Base::ValueType& ptr) { - return ptr.load(Base::OrderedOp::LoadOrder); - } - static void store(typename Base::ValueType& ptr, T val) { - ptr.store(val, Base::OrderedOp::StoreOrder); - } - static T exchange(typename Base::ValueType& ptr, T val) { - return ptr.exchange(val, Base::OrderedOp::AtomicRMWOrder); - } - static bool compareExchange(typename Base::ValueType& ptr, T oldVal, T newVal) { - return ptr.compare_exchange_strong(oldVal, newVal, - Base::OrderedOp::AtomicRMWOrder, - Base::OrderedOp::CompareExchangeFailureOrder); - } + typedef IntrinsicBase Base; + + static T load(const typename Base::ValueType& aPtr) + { + return aPtr.load(Base::OrderedOp::LoadOrder); + } + + static void store(typename Base::ValueType& aPtr, T aVal) + { + aPtr.store(aVal, Base::OrderedOp::StoreOrder); + } + + static T exchange(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.exchange(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static bool compareExchange(typename Base::ValueType& aPtr, + T aOldVal, T aNewVal) + { + return aPtr.compare_exchange_strong(aOldVal, aNewVal, + Base::OrderedOp::AtomicRMWOrder, + Base::OrderedOp::CompareExchangeFailureOrder); + } }; template struct IntrinsicAddSub : public IntrinsicBase { - typedef IntrinsicBase Base; - static T add(typename Base::ValueType& ptr, T val) { - return ptr.fetch_add(val, Base::OrderedOp::AtomicRMWOrder); - } - static T sub(typename Base::ValueType& ptr, T val) { - return ptr.fetch_sub(val, Base::OrderedOp::AtomicRMWOrder); - } + typedef IntrinsicBase Base; + + static T add(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_add(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T sub(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_sub(aVal, Base::OrderedOp::AtomicRMWOrder); + } }; template struct IntrinsicAddSub : public IntrinsicBase { - typedef IntrinsicBase Base; - static T* add(typename Base::ValueType& ptr, ptrdiff_t val) { - return ptr.fetch_add(fixupAddend(val), Base::OrderedOp::AtomicRMWOrder); - } - static T* sub(typename Base::ValueType& ptr, ptrdiff_t val) { - return ptr.fetch_sub(fixupAddend(val), Base::OrderedOp::AtomicRMWOrder); - } - private: - /* - * GCC 4.6's header has a bug where adding X to an - * atomic is not the same as adding X to a T*. Hence the need - * for this function to provide the correct addend. - */ - static ptrdiff_t fixupAddend(ptrdiff_t val) { + typedef IntrinsicBase Base; + + static T* add(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_add(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } + + static T* sub(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_sub(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } +private: + /* + * GCC 4.6's header has a bug where adding X to an + * atomic is not the same as adding X to a T*. Hence the need + * for this function to provide the correct addend. + */ + static ptrdiff_t fixupAddend(ptrdiff_t aVal) + { #if defined(__clang__) || defined(_MSC_VER) - return val; + return aVal; #elif defined(__GNUC__) && MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) && \ - !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) - return val * sizeof(T); + !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) + return aVal * sizeof(T); #else - return val; + return aVal; #endif - } + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - typedef IntrinsicBase Base; - static T inc(typename Base::ValueType& ptr) { - return IntrinsicAddSub::add(ptr, 1); - } - static T dec(typename Base::ValueType& ptr) { - return IntrinsicAddSub::sub(ptr, 1); - } + typedef IntrinsicBase Base; + + static T inc(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::add(aPtr, 1); + } + + static T dec(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::sub(aPtr, 1); + } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef IntrinsicBase Base; - static T or_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_or(val, Base::OrderedOp::AtomicRMWOrder); - } - static T xor_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_xor(val, Base::OrderedOp::AtomicRMWOrder); - } - static T and_(typename Base::ValueType& ptr, T val) { - return ptr.fetch_and(val, Base::OrderedOp::AtomicRMWOrder); - } + typedef IntrinsicBase Base; + + static T or_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_or(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T xor_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_xor(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T and_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_and(aVal, Base::OrderedOp::AtomicRMWOrder); + } }; template @@ -345,111 +382,119 @@ template struct Barrier; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() {} - static void beforeStore() {} - static void afterStore() {} + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} + static void afterStore() {} }; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() { __sync_synchronize(); } - static void beforeStore() { __sync_synchronize(); } - static void afterStore() {} + static void beforeLoad() {} + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() {} }; template<> struct Barrier { - static void beforeLoad() { __sync_synchronize(); } - static void afterLoad() { __sync_synchronize(); } - static void beforeStore() { __sync_synchronize(); } - static void afterStore() { __sync_synchronize(); } + static void beforeLoad() { __sync_synchronize(); } + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() { __sync_synchronize(); } }; template struct IntrinsicMemoryOps { - static T load(const T& ptr) { - Barrier::beforeLoad(); - T val = ptr; - Barrier::afterLoad(); - return val; - } - static void store(T& ptr, T val) { - Barrier::beforeStore(); - ptr = val; - Barrier::afterStore(); - } - static T exchange(T& ptr, T val) { - // __sync_lock_test_and_set is only an acquire barrier; loads and stores - // can't be moved up from after to before it, but they can be moved down - // from before to after it. We may want a stricter ordering, so we need - // an explicit barrier. - - Barrier::beforeStore(); - return __sync_lock_test_and_set(&ptr, val); - } - static bool compareExchange(T& ptr, T oldVal, T newVal) { - return __sync_bool_compare_and_swap(&ptr, oldVal, newVal); - } + static T load(const T& aPtr) + { + Barrier::beforeLoad(); + T val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(T& aPtr, T aVal) + { + Barrier::beforeStore(); + aPtr = aVal; + Barrier::afterStore(); + } + + static T exchange(T& aPtr, T aVal) + { + // __sync_lock_test_and_set is only an acquire barrier; loads and stores + // can't be moved up from after to before it, but they can be moved down + // from before to after it. We may want a stricter ordering, so we need + // an explicit barrier. + Barrier::beforeStore(); + return __sync_lock_test_and_set(&aPtr, aVal); + } + + static bool compareExchange(T& aPtr, T aOldVal, T aNewVal) + { + return __sync_bool_compare_and_swap(&aPtr, aOldVal, aNewVal); + } }; template struct IntrinsicAddSub { - typedef T ValueType; - static T add(T& ptr, T val) { - return __sync_fetch_and_add(&ptr, val); - } - static T sub(T& ptr, T val) { - return __sync_fetch_and_sub(&ptr, val); - } + typedef T ValueType; + + static T add(T& aPtr, T aVal) + { + return __sync_fetch_and_add(&aPtr, aVal); + } + + static T sub(T& aPtr, T aVal) + { + return __sync_fetch_and_sub(&aPtr, aVal); + } }; template struct IntrinsicAddSub { - typedef T* ValueType; - /* - * The reinterpret_casts are needed so that - * __sync_fetch_and_{add,sub} will properly type-check. - * - * Also, these functions do not provide standard semantics for - * pointer types, so we need to adjust the addend. - */ - static ValueType add(ValueType& ptr, ptrdiff_t val) { - ValueType amount = reinterpret_cast(val * sizeof(T)); - return __sync_fetch_and_add(&ptr, amount); - } - static ValueType sub(ValueType& ptr, ptrdiff_t val) { - ValueType amount = reinterpret_cast(val * sizeof(T)); - return __sync_fetch_and_sub(&ptr, amount); - } + typedef T* ValueType; + + /* + * The reinterpret_casts are needed so that + * __sync_fetch_and_{add,sub} will properly type-check. + * + * Also, these functions do not provide standard semantics for + * pointer types, so we need to adjust the addend. + */ + static ValueType add(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_add(&aPtr, amount); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_sub(&aPtr, amount); + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - static T inc(T& ptr) { return IntrinsicAddSub::add(ptr, 1); } - static T dec(T& ptr) { return IntrinsicAddSub::sub(ptr, 1); } + static T inc(T& aPtr) { return IntrinsicAddSub::add(aPtr, 1); } + static T dec(T& aPtr) { return IntrinsicAddSub::sub(aPtr, 1); } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - static T or_(T& ptr, T val) { - return __sync_fetch_and_or(&ptr, val); - } - static T xor_(T& ptr, T val) { - return __sync_fetch_and_xor(&ptr, val); - } - static T and_(T& ptr, T val) { - return __sync_fetch_and_and(&ptr, val); - } + static T or_( T& aPtr, T aVal) { return __sync_fetch_and_or(&aPtr, aVal); } + static T xor_(T& aPtr, T aVal) { return __sync_fetch_and_xor(&aPtr, aVal); } + static T and_(T& aPtr, T aVal) { return __sync_fetch_and_and(&aPtr, aVal); } }; template @@ -470,19 +515,9 @@ struct AtomicIntrinsics : public IntrinsicMemoryOps, * version of Windows we support. Therefore, we only provide operations * on 32-bit datatypes for 32-bit Windows versions; for 64-bit Windows * versions, we support 64-bit datatypes as well. - * - * To avoid namespace pollution issues, we declare whatever functions we - * need ourselves. */ -extern "C" { -long __cdecl _InterlockedExchangeAdd(long volatile* dst, long value); -long __cdecl _InterlockedOr(long volatile* dst, long value); -long __cdecl _InterlockedXor(long volatile* dst, long value); -long __cdecl _InterlockedAnd(long volatile* dst, long value); -long __cdecl _InterlockedExchange(long volatile *dst, long value); -long __cdecl _InterlockedCompareExchange(long volatile *dst, long newVal, long oldVal); -} +# include # pragma intrinsic(_InterlockedExchangeAdd) # pragma intrinsic(_InterlockedOr) @@ -507,34 +542,34 @@ namespace detail { * The PrimitiveIntrinsics template should define |Type|, the datatype of size * DataSize upon which we operate, and the following eight functions. * - * static Type add(Type* ptr, Type val); - * static Type sub(Type* ptr, Type val); - * static Type or_(Type* ptr, Type val); - * static Type xor_(Type* ptr, Type val); - * static Type and_(Type* ptr, Type val); + * static Type add(Type* aPtr, Type aVal); + * static Type sub(Type* aPtr, Type aVal); + * static Type or_(Type* aPtr, Type aVal); + * static Type xor_(Type* aPtr, Type aVal); + * static Type and_(Type* aPtr, Type aVal); * * These functions perform the obvious operation on the value contained in - * |*ptr| combined with |val| and return the value previously stored in - * |*ptr|. + * |*aPtr| combined with |aVal| and return the value previously stored in + * |*aPtr|. * - * static void store(Type* ptr, Type val); + * static void store(Type* aPtr, Type aVal); * - * This function atomically stores |val| into |*ptr| and must provide a full + * This function atomically stores |aVal| into |*aPtr| and must provide a full * memory fence after the store to prevent compiler and hardware instruction * reordering. It should also act as a compiler barrier to prevent reads and * writes from moving to after the store. * - * static Type exchange(Type* ptr, Type val); + * static Type exchange(Type* aPtr, Type aVal); * - * This function atomically stores |val| into |*ptr| and returns the previous - * contents of *ptr; + * This function atomically stores |aVal| into |*aPtr| and returns the + * previous contents of |*aPtr|; * - * static bool compareExchange(Type* ptr, Type oldVal, Type newVal); + * static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal); * * This function atomically performs the following operation: * - * if (*ptr == oldVal) { - * *ptr = newVal; + * if (*aPtr == aOldVal) { + * *aPtr = aNewVal; * return true; * } else { * return false; @@ -546,56 +581,55 @@ template struct PrimitiveIntrinsics; template<> struct PrimitiveIntrinsics<4> { - typedef long Type; + typedef long Type; - static Type add(Type* ptr, Type val) { - return _InterlockedExchangeAdd(ptr, val); - } - static Type sub(Type* ptr, Type val) { - /* - * _InterlockedExchangeSubtract isn't available before Windows 7, - * and we must support Windows XP. - */ - return _InterlockedExchangeAdd(ptr, -val); - } - static Type or_(Type* ptr, Type val) { - return _InterlockedOr(ptr, val); - } - static Type xor_(Type* ptr, Type val) { - return _InterlockedXor(ptr, val); - } - static Type and_(Type* ptr, Type val) { - return _InterlockedAnd(ptr, val); - } - static void store(Type* ptr, Type val) { - _InterlockedExchange(ptr, val); - } - static Type exchange(Type* ptr, Type val) { - return _InterlockedExchange(ptr, val); - } - static bool compareExchange(Type* ptr, Type oldVal, Type newVal) { - return _InterlockedCompareExchange(ptr, newVal, oldVal) == oldVal; - } + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * _InterlockedExchangeSubtract isn't available before Windows 7, + * and we must support Windows XP. + */ + return _InterlockedExchangeAdd(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange(aPtr, aNewVal, aOldVal) == aOldVal; + } }; # if defined(_M_X64) -extern "C" { -long long __cdecl _InterlockedExchangeAdd64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedOr64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedXor64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedAnd64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedExchange64(long long volatile* dst, - long long value); -long long __cdecl _InterlockedCompareExchange64(long long volatile* dst, - long long newVal, - long long oldVal); -} - # pragma intrinsic(_InterlockedExchangeAdd64) # pragma intrinsic(_InterlockedOr64) # pragma intrinsic(_InterlockedXor64) @@ -606,41 +640,54 @@ long long __cdecl _InterlockedCompareExchange64(long long volatile* dst, template <> struct PrimitiveIntrinsics<8> { - typedef __int64 Type; + typedef __int64 Type; - static Type add(Type* ptr, Type val) { - return _InterlockedExchangeAdd64(ptr, val); - } - static Type sub(Type* ptr, Type val) { - /* - * There is no _InterlockedExchangeSubtract64. - */ - return _InterlockedExchangeAdd64(ptr, -val); - } - static Type or_(Type* ptr, Type val) { - return _InterlockedOr64(ptr, val); - } - static Type xor_(Type* ptr, Type val) { - return _InterlockedXor64(ptr, val); - } - static Type and_(Type* ptr, Type val) { - return _InterlockedAnd64(ptr, val); - } - static void store(Type* ptr, Type val) { - _InterlockedExchange64(ptr, val); - } - static Type exchange(Type* ptr, Type val) { - return _InterlockedExchange64(ptr, val); - } - static bool compareExchange(Type* ptr, Type oldVal, Type newVal) { - return _InterlockedCompareExchange64(ptr, newVal, oldVal) == oldVal; - } + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd64(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * There is no _InterlockedExchangeSubtract64. + */ + return _InterlockedExchangeAdd64(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr64(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor64(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd64(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange64(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange64(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange64(aPtr, aNewVal, aOldVal) == aOldVal; + } }; # endif -extern "C" { void _ReadWriteBarrier(); } - # pragma intrinsic(_ReadWriteBarrier) template struct Barrier; @@ -654,168 +701,198 @@ template struct Barrier; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() {} - static void beforeStore() {} + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} }; template<> struct Barrier { - static void beforeLoad() {} - static void afterLoad() { _ReadWriteBarrier(); } - static void beforeStore() { _ReadWriteBarrier(); } + static void beforeLoad() {} + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } }; template<> struct Barrier { - static void beforeLoad() { _ReadWriteBarrier(); } - static void afterLoad() { _ReadWriteBarrier(); } - static void beforeStore() { _ReadWriteBarrier(); } + static void beforeLoad() { _ReadWriteBarrier(); } + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } }; template struct CastHelper { - static PrimType toPrimType(T val) { return static_cast(val); } - static T fromPrimType(PrimType val) { return static_cast(val); } + static PrimType toPrimType(T aVal) { return static_cast(aVal); } + static T fromPrimType(PrimType aVal) { return static_cast(aVal); } }; template struct CastHelper { - static PrimType toPrimType(T* val) { return reinterpret_cast(val); } - static T* fromPrimType(PrimType val) { return reinterpret_cast(val); } + static PrimType toPrimType(T* aVal) { return reinterpret_cast(aVal); } + static T* fromPrimType(PrimType aVal) { return reinterpret_cast(aVal); } }; template struct IntrinsicBase { - typedef T ValueType; - typedef PrimitiveIntrinsics Primitives; - typedef typename Primitives::Type PrimType; - static_assert(sizeof(PrimType) == sizeof(T), - "Selection of PrimitiveIntrinsics was wrong"); - typedef CastHelper Cast; + typedef T ValueType; + typedef PrimitiveIntrinsics Primitives; + typedef typename Primitives::Type PrimType; + static_assert(sizeof(PrimType) == sizeof(T), + "Selection of PrimitiveIntrinsics was wrong"); + typedef CastHelper Cast; }; template struct IntrinsicMemoryOps : public IntrinsicBase { - typedef typename IntrinsicBase::ValueType ValueType; - typedef typename IntrinsicBase::Primitives Primitives; - typedef typename IntrinsicBase::PrimType PrimType; - typedef typename IntrinsicBase::Cast Cast; - static ValueType load(const ValueType& ptr) { - Barrier::beforeLoad(); - ValueType val = ptr; - Barrier::afterLoad(); - return val; - } - static void store(ValueType& ptr, ValueType val) { - // For SequentiallyConsistent, Primitives::store() will generate the - // proper memory fence. Everything else just needs a barrier before - // the store. - if (Order == SequentiallyConsistent) { - Primitives::store(reinterpret_cast(&ptr), - Cast::toPrimType(val)); - } else { - Barrier::beforeStore(); - ptr = val; - } - } - static ValueType exchange(ValueType& ptr, ValueType val) { - PrimType oldval = - Primitives::exchange(reinterpret_cast(&ptr), - Cast::toPrimType(val)); - return Cast::fromPrimType(oldval); - } - static bool compareExchange(ValueType& ptr, ValueType oldVal, ValueType newVal) { - return Primitives::compareExchange(reinterpret_cast(&ptr), - Cast::toPrimType(oldVal), - Cast::toPrimType(newVal)); + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + + static ValueType load(const ValueType& aPtr) + { + Barrier::beforeLoad(); + ValueType val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(ValueType& aPtr, ValueType aVal) + { + // For SequentiallyConsistent, Primitives::store() will generate the + // proper memory fence. Everything else just needs a barrier before + // the store. + if (Order == SequentiallyConsistent) { + Primitives::store(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + } else { + Barrier::beforeStore(); + aPtr = aVal; } + } + + static ValueType exchange(ValueType& aPtr, ValueType aVal) + { + PrimType oldval = + Primitives::exchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + return Cast::fromPrimType(oldval); + } + + static bool compareExchange(ValueType& aPtr, ValueType aOldVal, + ValueType aNewVal) + { + return Primitives::compareExchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aOldVal), + Cast::toPrimType(aNewVal)); + } }; template struct IntrinsicApplyHelper : public IntrinsicBase { - typedef typename IntrinsicBase::ValueType ValueType; - typedef typename IntrinsicBase::PrimType PrimType; - typedef typename IntrinsicBase::Cast Cast; - typedef PrimType (*BinaryOp)(PrimType*, PrimType); - typedef PrimType (*UnaryOp)(PrimType*); - - static ValueType applyBinaryFunction(BinaryOp op, ValueType& ptr, - ValueType val) { - PrimType* primTypePtr = reinterpret_cast(&ptr); - PrimType primTypeVal = Cast::toPrimType(val); - return Cast::fromPrimType(op(primTypePtr, primTypeVal)); - } - - static ValueType applyUnaryFunction(UnaryOp op, ValueType& ptr) { - PrimType* primTypePtr = reinterpret_cast(&ptr); - return Cast::fromPrimType(op(primTypePtr)); - } + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + typedef PrimType (*BinaryOp)(PrimType*, PrimType); + typedef PrimType (*UnaryOp)(PrimType*); + + static ValueType applyBinaryFunction(BinaryOp aOp, ValueType& aPtr, + ValueType aVal) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + PrimType primTypeVal = Cast::toPrimType(aVal); + return Cast::fromPrimType(aOp(primTypePtr, primTypeVal)); + } + + static ValueType applyUnaryFunction(UnaryOp aOp, ValueType& aPtr) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + return Cast::fromPrimType(aOp(primTypePtr)); + } }; template struct IntrinsicAddSub : public IntrinsicApplyHelper { - typedef typename IntrinsicApplyHelper::ValueType ValueType; - typedef typename IntrinsicBase::Primitives Primitives; - static ValueType add(ValueType& ptr, ValueType val) { - return applyBinaryFunction(&Primitives::add, ptr, val); - } - static ValueType sub(ValueType& ptr, ValueType val) { - return applyBinaryFunction(&Primitives::sub, ptr, val); - } + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::add, aPtr, aVal); + } + + static ValueType sub(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::sub, aPtr, aVal); + } }; template struct IntrinsicAddSub : public IntrinsicApplyHelper { - typedef typename IntrinsicApplyHelper::ValueType ValueType; - static ValueType add(ValueType& ptr, ptrdiff_t amount) { - return applyBinaryFunction(&Primitives::add, ptr, - (ValueType)(amount * sizeof(ValueType))); - } - static ValueType sub(ValueType& ptr, ptrdiff_t amount) { - return applyBinaryFunction(&Primitives::sub, ptr, - (ValueType)(amount * sizeof(ValueType))); - } + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::add, aPtr, + (ValueType)(aAmount * sizeof(T))); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::sub, aPtr, + (ValueType)(aAmount * sizeof(T))); + } }; template struct IntrinsicIncDec : public IntrinsicAddSub { - typedef typename IntrinsicAddSub::ValueType ValueType; - static ValueType inc(ValueType& ptr) { return add(ptr, 1); } - static ValueType dec(ValueType& ptr) { return sub(ptr, 1); } + typedef typename IntrinsicAddSub::ValueType ValueType; + static ValueType inc(ValueType& aPtr) { return add(aPtr, 1); } + static ValueType dec(ValueType& aPtr) { return sub(aPtr, 1); } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef typename IntrinsicIncDec::ValueType ValueType; - static ValueType or_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::or_, ptr, val); - } - static ValueType xor_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::xor_, ptr, val); - } - static ValueType and_(ValueType& ptr, T val) { - return applyBinaryFunction(&Primitives::and_, ptr, val); - } + typedef typename IntrinsicIncDec::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType or_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::or_, aPtr, aVal); + } + + static ValueType xor_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::xor_, aPtr, aVal); + } + + static ValueType and_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::and_, aPtr, aVal); + } }; template struct AtomicIntrinsics : public IntrinsicMemoryOps, public IntrinsicIncDec { - typedef typename IntrinsicMemoryOps::ValueType ValueType; + typedef typename IntrinsicMemoryOps::ValueType ValueType; + // This is required to make us be able to build with MSVC10, for unknown + // reasons. + typedef typename IntrinsicBase::Primitives Primitives; }; } // namespace detail @@ -832,73 +909,80 @@ namespace detail { template class AtomicBase { - // We only support 32-bit types on 32-bit Windows, which constrains our - // implementation elsewhere. But we support pointer-sized types everywhere. - static_assert(sizeof(T) == 4 || (sizeof(uintptr_t) == 8 && sizeof(T) == 8), - "mozilla/Atomics.h only supports 32-bit and pointer-sized types"); - - protected: - typedef typename detail::AtomicIntrinsics Intrinsics; - typename Intrinsics::ValueType mValue; - - public: - MOZ_CONSTEXPR AtomicBase() : mValue() {} - MOZ_CONSTEXPR AtomicBase(T aInit) : mValue(aInit) {} - - operator T() const { return Intrinsics::load(mValue); } - - T operator=(T aValue) { - Intrinsics::store(mValue, aValue); - return aValue; - } - - /** - * Performs an atomic swap operation. aValue is stored and the previous - * value of this variable is returned. - */ - T exchange(T aValue) { - return Intrinsics::exchange(mValue, aValue); - } - - /** - * Performs an atomic compare-and-swap operation and returns true if it - * succeeded. This is equivalent to atomically doing - * - * if (mValue == aOldValue) { - * mValue = aNewValue; - * return true; - * } else { - * return false; - * } - */ - bool compareExchange(T aOldValue, T aNewValue) { - return Intrinsics::compareExchange(mValue, aOldValue, aNewValue); - } - - private: - template - AtomicBase(const AtomicBase& aCopy) MOZ_DELETE; + // We only support 32-bit types on 32-bit Windows, which constrains our + // implementation elsewhere. But we support pointer-sized types everywhere. + static_assert(sizeof(T) == 4 || (sizeof(uintptr_t) == 8 && sizeof(T) == 8), + "mozilla/Atomics.h only supports 32-bit and pointer-sized types"); + +protected: + typedef typename detail::AtomicIntrinsics Intrinsics; + typename Intrinsics::ValueType mValue; + +public: + MOZ_CONSTEXPR AtomicBase() : mValue() {} + explicit MOZ_CONSTEXPR AtomicBase(T aInit) : mValue(aInit) {} + + // Note: we can't provide operator T() here because Atomic inherits + // from AtomcBase with T=uint32_t and not T=bool. If we implemented + // operator T() here, it would cause errors when comparing Atomic with + // a regular bool. + + T operator=(T aVal) + { + Intrinsics::store(mValue, aVal); + return aVal; + } + + /** + * Performs an atomic swap operation. aVal is stored and the previous + * value of this variable is returned. + */ + T exchange(T aVal) + { + return Intrinsics::exchange(mValue, aVal); + } + + /** + * Performs an atomic compare-and-swap operation and returns true if it + * succeeded. This is equivalent to atomically doing + * + * if (mValue == aOldValue) { + * mValue = aNewValue; + * return true; + * } else { + * return false; + * } + */ + bool compareExchange(T aOldValue, T aNewValue) + { + return Intrinsics::compareExchange(mValue, aOldValue, aNewValue); + } + +private: + template + AtomicBase(const AtomicBase& aCopy) MOZ_DELETE; }; template class AtomicBaseIncDec : public AtomicBase { - typedef typename detail::AtomicBase Base; + typedef typename detail::AtomicBase Base; - public: - MOZ_CONSTEXPR AtomicBaseIncDec() : Base() {} - MOZ_CONSTEXPR AtomicBaseIncDec(T aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR AtomicBaseIncDec() : Base() {} + explicit MOZ_CONSTEXPR AtomicBaseIncDec(T aInit) : Base(aInit) {} - using Base::operator=; + using Base::operator=; - T operator++(int) { return Base::Intrinsics::inc(Base::mValue); } - T operator--(int) { return Base::Intrinsics::dec(Base::mValue); } - T operator++() { return Base::Intrinsics::inc(Base::mValue) + 1; } - T operator--() { return Base::Intrinsics::dec(Base::mValue) - 1; } + operator T() const { return Base::Intrinsics::load(Base::mValue); } + T operator++(int) { return Base::Intrinsics::inc(Base::mValue); } + T operator--(int) { return Base::Intrinsics::dec(Base::mValue); } + T operator++() { return Base::Intrinsics::inc(Base::mValue) + 1; } + T operator--() { return Base::Intrinsics::dec(Base::mValue) - 1; } - private: - template - AtomicBaseIncDec(const AtomicBaseIncDec& aCopy) MOZ_DELETE; +private: + template + AtomicBaseIncDec(const AtomicBaseIncDec& aCopy) MOZ_DELETE; }; } // namespace detail @@ -934,25 +1018,45 @@ class Atomic; * swap method is provided. */ template -class Atomic::value>::Type> +class Atomic::value && + !IsSame::value>::Type> : public detail::AtomicBaseIncDec { - typedef typename detail::AtomicBaseIncDec Base; + typedef typename detail::AtomicBaseIncDec Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + + using Base::operator=; + + T operator+=(T aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + T operator-=(T aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } - using Base::operator=; + T operator|=(T aVal) + { + return Base::Intrinsics::or_(Base::mValue, aVal) | aVal; + } - T operator+=(T delta) { return Base::Intrinsics::add(Base::mValue, delta) + delta; } - T operator-=(T delta) { return Base::Intrinsics::sub(Base::mValue, delta) - delta; } - T operator|=(T val) { return Base::Intrinsics::or_(Base::mValue, val) | val; } - T operator^=(T val) { return Base::Intrinsics::xor_(Base::mValue, val) ^ val; } - T operator&=(T val) { return Base::Intrinsics::and_(Base::mValue, val) & val; } + T operator^=(T aVal) + { + return Base::Intrinsics::xor_(Base::mValue, aVal) ^ aVal; + } - private: - Atomic(Atomic& aOther) MOZ_DELETE; + T operator&=(T aVal) + { + return Base::Intrinsics::and_(Base::mValue, aVal) & aVal; + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; /** @@ -966,23 +1070,26 @@ class Atomic::value>::Type> template class Atomic : public detail::AtomicBaseIncDec { - typedef typename detail::AtomicBaseIncDec Base; + typedef typename detail::AtomicBaseIncDec Base; - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T* aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T* aInit) : Base(aInit) {} - using Base::operator=; + using Base::operator=; - T* operator+=(ptrdiff_t delta) { - return Base::Intrinsics::add(Base::mValue, delta) + delta; - } - T* operator-=(ptrdiff_t delta) { - return Base::Intrinsics::sub(Base::mValue, delta) - delta; - } + T* operator+=(ptrdiff_t aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } + + T* operator-=(ptrdiff_t aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } - private: - Atomic(Atomic& aOther) MOZ_DELETE; +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; /** @@ -994,16 +1101,69 @@ template class Atomic::value>::Type> : public detail::AtomicBase { - typedef typename detail::AtomicBase Base; + typedef typename detail::AtomicBase Base; - public: - MOZ_CONSTEXPR Atomic() : Base() {} - MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} - using Base::operator=; + operator T() const { return Base::Intrinsics::load(Base::mValue); } - private: - Atomic(Atomic& aOther) MOZ_DELETE; + using Base::operator=; + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +/** + * Atomic implementation for boolean types. + * + * The atomic store and load operations and the atomic swap method is provided. + * + * Note: + * + * - sizeof(Atomic) != sizeof(bool) for some implementations of + * bool and/or some implementations of std::atomic. This is allowed in + * [atomic.types.generic]p9. + * + * - It's not obvious whether the 8-bit atomic functions on Windows are always + * inlined or not. If they are not inlined, the corresponding functions in the + * runtime library are not available on Windows XP. This is why we implement + * Atomic with an underlying type of uint32_t. + */ +template +class Atomic + : protected detail::AtomicBase +{ + typedef typename detail::AtomicBase Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(bool aInit) : Base(aInit) {} + + // We provide boolean wrappers for the underlying AtomicBase methods. + operator bool() const + { + return Base::Intrinsics::load(Base::mValue); + } + + bool operator=(bool aVal) + { + return Base::operator=(aVal); + } + + bool exchange(bool aVal) + { + return Base::exchange(aVal); + } + + bool compareExchange(bool aOldValue, bool aNewValue) + { + return Base::compareExchange(aOldValue, aNewValue); + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Attributes.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Attributes.h index 671f30cded..cdce8c7717 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Attributes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Attributes.h @@ -37,6 +37,7 @@ # define MOZ_ALWAYS_INLINE inline #endif +#if defined(_MSC_VER) /* * g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality * without warnings (functionality used by the macros below). These modes are @@ -44,8 +45,27 @@ * standardly, by checking whether __cplusplus has a C++11 or greater value. * Current versions of g++ do not correctly set __cplusplus, so we check both * for forward compatibility. + * + * Even though some versions of MSVC support explicit conversion operators, we + * don't indicate support for them here, due to + * http://stackoverflow.com/questions/20498142/visual-studio-2013-explicit-keyword-bug */ -#if defined(__clang__) +# if _MSC_VER >= 1800 +# define MOZ_HAVE_CXX11_DELETE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_FINAL final +# else +# if defined(__clang__) +# error Please do not try to use clang-cl with MSVC10 or below emulation! +# endif + /* MSVC <= 10 used to spell "final" as "sealed". */ +# define MOZ_HAVE_CXX11_FINAL sealed +# endif +# define MOZ_HAVE_CXX11_OVERRIDE +# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) +# define MOZ_HAVE_NORETURN __declspec(noreturn) +#elif defined(__clang__) /* * Per Clang documentation, "Note that marketing version numbers should not * be used to check for language features, as different vendors use different @@ -57,6 +77,9 @@ # if __has_extension(cxx_constexpr) # define MOZ_HAVE_CXX11_CONSTEXPR # endif +# if __has_extension(cxx_explicit_conversions) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif # if __has_extension(cxx_deleted_functions) # define MOZ_HAVE_CXX11_DELETE # endif @@ -79,6 +102,9 @@ # if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) # define MOZ_HAVE_CXX11_CONSTEXPR # endif +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif # define MOZ_HAVE_CXX11_DELETE # else /* __final is a non-C++11 GCC synonym for 'final', per GCC r176655. */ @@ -88,19 +114,16 @@ # endif # define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) # define MOZ_HAVE_NORETURN __attribute__((noreturn)) -#elif defined(_MSC_VER) -# if _MSC_VER >= 1800 -# define MOZ_HAVE_CXX11_DELETE -# endif -# if _MSC_VER >= 1700 -# define MOZ_HAVE_CXX11_FINAL final -# else - /* MSVC <= 10 used to spell "final" as "sealed". */ -# define MOZ_HAVE_CXX11_FINAL sealed +#endif + +/* + * When built with clang analyzer (a.k.a scan-build), define MOZ_HAVE_NORETURN + * to mark some false positives + */ +#ifdef __clang_analyzer__ +# if __has_extension(attribute_analyzer_noreturn) +# define MOZ_HAVE_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) # endif -# define MOZ_HAVE_CXX11_OVERRIDE -# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) -# define MOZ_HAVE_NORETURN __declspec(noreturn) #endif /* @@ -121,6 +144,31 @@ # define MOZ_CONSTEXPR_VAR const #endif +/* + * MOZ_EXPLICIT_CONVERSION is a specifier on a type conversion + * overloaded operator that declares that a C++11 compiler should restrict + * this operator to allow only explicit type conversions, disallowing + * implicit conversions. + * + * Example: + * + * template + * class Ptr + * { + * T* mPtr; + * MOZ_EXPLICIT_CONVERSION operator bool() const + * { + * return mPtr != nullptr; + * } + * }; + * + */ +#ifdef MOZ_HAVE_EXPLICIT_CONVERSION +# define MOZ_EXPLICIT_CONVERSION explicit +#else +# define MOZ_EXPLICIT_CONVERSION /* no support */ +#endif + /* * MOZ_NEVER_INLINE is a macro which expands to tell the compiler that the * method decorated with it must never be inlined, even if the compiler would @@ -153,18 +201,47 @@ # define MOZ_NORETURN /* no support */ #endif +/* + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS, specified at the end of a function + * declaration, indicates that for the purposes of static analysis, this + * function does not return. (The function definition does not need to be + * annotated.) + * + * MOZ_ReportCrash(const char* s, const char* file, int ln) + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS + * + * Some static analyzers, like scan-build from clang, can use this information + * to eliminate false positives. From the upstream documentation of scan-build: + * "This attribute is useful for annotating assertion handlers that actually + * can return, but for the purpose of using the analyzer we want to pretend + * that such functions do not return." + * + */ +#if defined(MOZ_HAVE_ANALYZER_NORETURN) +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS MOZ_HAVE_ANALYZER_NORETURN +#else +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS /* no support */ +#endif + /* * MOZ_ASAN_BLACKLIST is a macro to tell AddressSanitizer (a compile-time - * instrumentation shipped with Clang) to not instrument the annotated function. - * Furthermore, it will prevent the compiler from inlining the function because - * inlining currently breaks the blacklisting mechanism of AddressSanitizer. + * instrumentation shipped with Clang and GCC) to not instrument the annotated + * function. Furthermore, it will prevent the compiler from inlining the + * function because inlining currently breaks the blacklisting mechanism of + * AddressSanitizer. */ #if defined(__has_feature) # if __has_feature(address_sanitizer) -# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) -# else -# define MOZ_ASAN_BLACKLIST /* nothing */ +# define MOZ_HAVE_ASAN_BLACKLIST # endif +#elif defined(__GNUC__) +# if defined(__SANITIZE_ADDRESS__) +# define MOZ_HAVE_ASAN_BLACKLIST +# endif +#endif + +#if defined(MOZ_HAVE_ASAN_BLACKLIST) +# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) #else # define MOZ_ASAN_BLACKLIST /* nothing */ #endif @@ -197,9 +274,9 @@ * * struct NonCopyable * { - * private: - * NonCopyable(const NonCopyable& other) MOZ_DELETE; - * void operator=(const NonCopyable& other) MOZ_DELETE; + * private: + * NonCopyable(const NonCopyable& aOther) MOZ_DELETE; + * void operator=(const NonCopyable& aOther) MOZ_DELETE; * }; * * If MOZ_DELETE can't be implemented for the current compiler, use of the @@ -225,23 +302,23 @@ * * class Base * { - * public: - * virtual void f() = 0; + * public: + * virtual void f() = 0; * }; * class Derived1 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE; + * public: + * virtual void f() MOZ_OVERRIDE; * }; * class Derived2 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE = 0; + * public: + * virtual void f() MOZ_OVERRIDE = 0; * }; * class Derived3 : public Base * { - * public: - * virtual void f() MOZ_OVERRIDE { } + * public: + * virtual void f() MOZ_OVERRIDE { } * }; * * In compilers supporting C++11 override controls, MOZ_OVERRIDE *requires* that @@ -269,16 +346,16 @@ * * class Base MOZ_FINAL * { - * public: - * Base(); - * ~Base(); - * virtual void f() { } + * public: + * Base(); + * ~Base(); + * virtual void f() { } * }; * // This will be an error in some compilers: * class Derived : public Base * { - * public: - * ~Derived() { } + * public: + * ~Derived() { } * }; * * One particularly common reason to specify MOZ_FINAL upon a class is to tell @@ -305,14 +382,14 @@ * * class Base * { - * public: - * virtual void f() MOZ_FINAL; + * public: + * virtual void f() MOZ_FINAL; * }; * class Derived * { - * public: - * // This will be an error in some compilers: - * virtual void f(); + * public: + * // This will be an error in some compilers: + * virtual void f(); * }; * * In compilers implementing final controls, it is an error for a derived class @@ -372,13 +449,13 @@ * * typedef int MOZ_TYPE_ATTRIBUTE MagicInt; * int MOZ_TYPE_ATTRIBUTE someVariable; - * int * MOZ_TYPE_ATTRIBUTE magicPtrInt; - * int MOZ_TYPE_ATTRIBUTE * ptrToMagicInt; + * int* MOZ_TYPE_ATTRIBUTE magicPtrInt; + * int MOZ_TYPE_ATTRIBUTE* ptrToMagicInt; * * Attributes that apply to statements precede the statement: * * MOZ_IF_ATTRIBUTE if (x == 0) - * MOZ_DO_ATTRIBUTE do { } while(0); + * MOZ_DO_ATTRIBUTE do { } while (0); * * Attributes that apply to labels precede the label: * @@ -412,11 +489,16 @@ * MOZ_HEAP_ALLOCATOR: Applies to any function. This indicates that the return * value is allocated on the heap, and will as a result check such allocations * during MOZ_STACK_CLASS and MOZ_NONHEAP_CLASS annotation checking. + * MOZ_IMPLICIT: Applies to constructors. Implicit conversion constructors + * are disallowed by default unless they are marked as MOZ_IMPLICIT. This + * attribute must be used for constructors which intend to provide implicit + * conversions. */ #ifdef MOZ_CLANG_PLUGIN # define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override"))) # define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class"))) # define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class"))) +# define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) /* * It turns out that clang doesn't like void func() __attribute__ {} without a * warning, so use pragmas to disable the warning. This code won't work on GCC @@ -431,6 +513,7 @@ # define MOZ_MUST_OVERRIDE /* nothing */ # define MOZ_STACK_CLASS /* nothing */ # define MOZ_NONHEAP_CLASS /* nothing */ +# define MOZ_IMPLICIT /* nothing */ # define MOZ_HEAP_ALLOCATOR /* nothing */ #endif /* MOZ_CLANG_PLUGIN */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/BinarySearch.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/BinarySearch.h new file mode 100644 index 0000000000..c8f593d6a9 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/BinarySearch.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_BinarySearch_h +#define mozilla_BinarySearch_h + +#include "mozilla/Assertions.h" + +#include + +namespace mozilla { + +/* + * The algorithm searches the given container |aContainer| over the sorted + * index range [aBegin, aEnd) for an index |i| where |aContainer[i] == aTarget|. + * If such an index |i| is found, BinarySearch returns |true| and the index is + * returned via the outparam |aMatchOrInsertionPoint|. If no index is found, + * BinarySearch returns |false| and the outparam returns the first index in + * [aBegin, aEnd] where |aTarget| can be inserted to maintain sorted order. + * + * Example: + * + * Vector sortedInts = ... + * + * size_t match; + * if (BinarySearch(sortedInts, 0, sortedInts.length(), 13, &match)) { + * printf("found 13 at %lu\n", match); + * } + */ + +template +bool +BinarySearch(const Container& aContainer, size_t aBegin, size_t aEnd, + T aTarget, size_t* aMatchOrInsertionPoint) +{ + MOZ_ASSERT(aBegin <= aEnd); + + size_t low = aBegin; + size_t high = aEnd; + while (low != high) { + size_t middle = low + (high - low) / 2; + + // Allow any intermediate type so long as it provides a suitable ordering + // relation. + const auto& middleValue = aContainer[middle]; + + MOZ_ASSERT(aContainer[low] <= aContainer[middle]); + MOZ_ASSERT(aContainer[middle] <= aContainer[high - 1]); + MOZ_ASSERT(aContainer[low] <= aContainer[high - 1]); + + if (aTarget == middleValue) { + *aMatchOrInsertionPoint = middle; + return true; + } + + if (aTarget < middleValue) { + high = middle; + } else { + low = middle + 1; + } + } + + *aMatchOrInsertionPoint = low; + return false; +} + +} // namespace mozilla + +#endif // mozilla_BinarySearch_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/BloomFilter.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/BloomFilter.h index 8129c489d4..6757e41181 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/BloomFilter.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/BloomFilter.h @@ -55,177 +55,199 @@ namespace mozilla { template class BloomFilter { - /* - * A counting Bloom filter with 8-bit counters. For now we assume - * that having two hash functions is enough, but we may revisit that - * decision later. - * - * The filter uses an array with 2**KeySize entries. - * - * Assuming a well-distributed hash function, a Bloom filter with - * array size M containing N elements and - * using k hash function has expected false positive rate exactly - * - * $ (1 - (1 - 1/M)^{kN})^k $ - * - * because each array slot has a - * - * $ (1 - 1/M)^{kN} $ - * - * chance of being 0, and the expected false positive rate is the - * probability that all of the k hash functions will hit a nonzero - * slot. - * - * For reasonable assumptions (M large, kN large, which should both - * hold if we're worried about false positives) about M and kN this - * becomes approximately - * - * $$ (1 - \exp(-kN/M))^k $$ - * - * For our special case of k == 2, that's $(1 - \exp(-2N/M))^2$, - * or in other words - * - * $$ N/M = -0.5 * \ln(1 - \sqrt(r)) $$ - * - * where r is the false positive rate. This can be used to compute - * the desired KeySize for a given load N and false positive rate r. - * - * If N/M is assumed small, then the false positive rate can - * further be approximated as 4*N^2/M^2. So increasing KeySize by - * 1, which doubles M, reduces the false positive rate by about a - * factor of 4, and a false positive rate of 1% corresponds to - * about M/N == 20. - * - * What this means in practice is that for a few hundred keys using a - * KeySize of 12 gives false positive rates on the order of 0.25-4%. - * - * Similarly, using a KeySize of 10 would lead to a 4% false - * positive rate for N == 100 and to quite bad false positive - * rates for larger N. - */ - public: - BloomFilter() { - static_assert(KeySize <= keyShift, "KeySize too big"); - - // Should we have a custom operator new using calloc instead and - // require that we're allocated via the operator? - clear(); - } - - /* - * Clear the filter. This should be done before reusing it, because - * just removing all items doesn't clear counters that hit the upper - * bound. - */ - void clear(); - - /* - * Add an item to the filter. - */ - void add(const T* t); - - /* - * Remove an item from the filter. - */ - void remove(const T* t); - - /* - * Check whether the filter might contain an item. This can - * sometimes return true even if the item is not in the filter, - * but will never return false for items that are actually in the - * filter. - */ - bool mightContain(const T* t) const; - - /* - * Methods for add/remove/contain when we already have a hash computed - */ - void add(uint32_t hash); - void remove(uint32_t hash); - bool mightContain(uint32_t hash) const; - - private: - static const size_t arraySize = (1 << KeySize); - static const uint32_t keyMask = (1 << KeySize) - 1; - static const uint32_t keyShift = 16; - - static uint32_t hash1(uint32_t hash) { return hash & keyMask; } - static uint32_t hash2(uint32_t hash) { return (hash >> keyShift) & keyMask; } - - uint8_t& firstSlot(uint32_t hash) { return counters[hash1(hash)]; } - uint8_t& secondSlot(uint32_t hash) { return counters[hash2(hash)]; } - const uint8_t& firstSlot(uint32_t hash) const { return counters[hash1(hash)]; } - const uint8_t& secondSlot(uint32_t hash) const { return counters[hash2(hash)]; } - - static bool full(const uint8_t& slot) { return slot == UINT8_MAX; } - - uint8_t counters[arraySize]; + /* + * A counting Bloom filter with 8-bit counters. For now we assume + * that having two hash functions is enough, but we may revisit that + * decision later. + * + * The filter uses an array with 2**KeySize entries. + * + * Assuming a well-distributed hash function, a Bloom filter with + * array size M containing N elements and + * using k hash function has expected false positive rate exactly + * + * $ (1 - (1 - 1/M)^{kN})^k $ + * + * because each array slot has a + * + * $ (1 - 1/M)^{kN} $ + * + * chance of being 0, and the expected false positive rate is the + * probability that all of the k hash functions will hit a nonzero + * slot. + * + * For reasonable assumptions (M large, kN large, which should both + * hold if we're worried about false positives) about M and kN this + * becomes approximately + * + * $$ (1 - \exp(-kN/M))^k $$ + * + * For our special case of k == 2, that's $(1 - \exp(-2N/M))^2$, + * or in other words + * + * $$ N/M = -0.5 * \ln(1 - \sqrt(r)) $$ + * + * where r is the false positive rate. This can be used to compute + * the desired KeySize for a given load N and false positive rate r. + * + * If N/M is assumed small, then the false positive rate can + * further be approximated as 4*N^2/M^2. So increasing KeySize by + * 1, which doubles M, reduces the false positive rate by about a + * factor of 4, and a false positive rate of 1% corresponds to + * about M/N == 20. + * + * What this means in practice is that for a few hundred keys using a + * KeySize of 12 gives false positive rates on the order of 0.25-4%. + * + * Similarly, using a KeySize of 10 would lead to a 4% false + * positive rate for N == 100 and to quite bad false positive + * rates for larger N. + */ +public: + BloomFilter() + { + static_assert(KeySize <= kKeyShift, "KeySize too big"); + + // Should we have a custom operator new using calloc instead and + // require that we're allocated via the operator? + clear(); + } + + /* + * Clear the filter. This should be done before reusing it, because + * just removing all items doesn't clear counters that hit the upper + * bound. + */ + void clear(); + + /* + * Add an item to the filter. + */ + void add(const T* aValue); + + /* + * Remove an item from the filter. + */ + void remove(const T* aValue); + + /* + * Check whether the filter might contain an item. This can + * sometimes return true even if the item is not in the filter, + * but will never return false for items that are actually in the + * filter. + */ + bool mightContain(const T* aValue) const; + + /* + * Methods for add/remove/contain when we already have a hash computed + */ + void add(uint32_t aHash); + void remove(uint32_t aHash); + bool mightContain(uint32_t aHash) const; + +private: + static const size_t kArraySize = (1 << KeySize); + static const uint32_t kKeyMask = (1 << KeySize) - 1; + static const uint32_t kKeyShift = 16; + + static uint32_t hash1(uint32_t aHash) + { + return aHash & kKeyMask; + } + static uint32_t hash2(uint32_t aHash) + { + return (aHash >> kKeyShift) & kKeyMask; + } + + uint8_t& firstSlot(uint32_t aHash) + { + return mCounters[hash1(aHash)]; + } + uint8_t& secondSlot(uint32_t aHash) + { + return mCounters[hash2(aHash)]; + } + + const uint8_t& firstSlot(uint32_t aHash) const + { + return mCounters[hash1(aHash)]; + } + const uint8_t& secondSlot(uint32_t aHash) const + { + return mCounters[hash2(aHash)]; + } + + static bool full(const uint8_t& aSlot) { return aSlot == UINT8_MAX; } + + uint8_t mCounters[kArraySize]; }; template inline void BloomFilter::clear() { - memset(counters, 0, arraySize); + memset(mCounters, 0, kArraySize); } template inline void -BloomFilter::add(uint32_t hash) +BloomFilter::add(uint32_t aHash) { - uint8_t& slot1 = firstSlot(hash); - if (MOZ_LIKELY(!full(slot1))) + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { ++slot1; - - uint8_t& slot2 = secondSlot(hash); - if (MOZ_LIKELY(!full(slot2))) + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { ++slot2; + } } template MOZ_ALWAYS_INLINE void -BloomFilter::add(const T* t) +BloomFilter::add(const T* aValue) { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); return add(hash); } template inline void -BloomFilter::remove(uint32_t hash) +BloomFilter::remove(uint32_t aHash) { // If the slots are full, we don't know whether we bumped them to be // there when we added or not, so just leave them full. - uint8_t& slot1 = firstSlot(hash); - if (MOZ_LIKELY(!full(slot1))) + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { --slot1; - - uint8_t& slot2 = secondSlot(hash); - if (MOZ_LIKELY(!full(slot2))) + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { --slot2; + } } template MOZ_ALWAYS_INLINE void -BloomFilter::remove(const T* t) +BloomFilter::remove(const T* aValue) { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); remove(hash); } template MOZ_ALWAYS_INLINE bool -BloomFilter::mightContain(uint32_t hash) const +BloomFilter::mightContain(uint32_t aHash) const { // Check that all the slots for this hash contain something - return firstSlot(hash) && secondSlot(hash); + return firstSlot(aHash) && secondSlot(aHash); } template MOZ_ALWAYS_INLINE bool -BloomFilter::mightContain(const T* t) const +BloomFilter::mightContain(const T* aValue) const { - uint32_t hash = t->hash(); + uint32_t hash = aValue->hash(); return mightContain(hash); } diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Casting.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Casting.h index 76df0ef27e..dc449af6b6 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Casting.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Casting.h @@ -17,7 +17,8 @@ namespace mozilla { /** - * Return a value of type |To|, containing the underlying bit pattern of |from|. + * Return a value of type |To|, containing the underlying bit pattern of + * |aFrom|. * * |To| and |From| must be types of the same size; be careful of cross-platform * size differences, or this might fail to compile on some but not all @@ -25,16 +26,17 @@ namespace mozilla { */ template inline To -BitwiseCast(const From from) +BitwiseCast(const From aFrom) { static_assert(sizeof(From) == sizeof(To), "To and From must have the same size"); - union { - From from; - To to; + union + { + From mFrom; + To mTo; } u; - u.from = from; - return u.to; + u.mFrom = aFrom; + return u.mTo; } namespace detail { @@ -58,34 +60,39 @@ enum UUComparison { FromIsBigger, FromIsNotBigger }; // Unsigned-to-unsigned range check template sizeof(To)) ? FromIsBigger : FromIsNotBigger> + UUComparison = (sizeof(From) > sizeof(To)) + ? FromIsBigger + : FromIsNotBigger> struct UnsignedUnsignedCheck; template struct UnsignedUnsignedCheck { - public: - static bool checkBounds(const From from) { - return from <= From(To(-1)); - } +public: + static bool checkBounds(const From aFrom) + { + return aFrom <= From(To(-1)); + } }; template struct UnsignedUnsignedCheck { - public: - static bool checkBounds(const From from) { - return true; - } +public: + static bool checkBounds(const From aFrom) + { + return true; + } }; template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - return UnsignedUnsignedCheck::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return UnsignedUnsignedCheck::checkBounds(aFrom); + } }; // Signed-to-unsigned range check @@ -93,14 +100,17 @@ struct BoundsCheckImpl template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - if (from < 0) - return false; - if (sizeof(To) >= sizeof(From)) - return true; - return from <= From(To(-1)); +public: + static bool checkBounds(const From aFrom) + { + if (aFrom < 0) { + return false; + } + if (sizeof(To) >= sizeof(From)) { + return true; } + return aFrom <= From(To(-1)); + } }; // Unsigned-to-signed range check @@ -108,35 +118,40 @@ struct BoundsCheckImpl enum USComparison { FromIsSmaller, FromIsNotSmaller }; template + USComparison = (sizeof(From) < sizeof(To)) + ? FromIsSmaller + : FromIsNotSmaller> struct UnsignedSignedCheck; template struct UnsignedSignedCheck { - public: - static bool checkBounds(const From from) { - return true; - } +public: + static bool checkBounds(const From aFrom) + { + return true; + } }; template struct UnsignedSignedCheck { - public: - static bool checkBounds(const From from) { - const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); - return from <= From(MaxValue); - } +public: + static bool checkBounds(const From aFrom) + { + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + return aFrom <= From(MaxValue); + } }; template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - return UnsignedSignedCheck::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return UnsignedSignedCheck::checkBounds(aFrom); + } }; // Signed-to-signed range check @@ -144,42 +159,46 @@ struct BoundsCheckImpl template struct BoundsCheckImpl { - public: - static bool checkBounds(const From from) { - if (sizeof(From) <= sizeof(To)) - return true; - const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); - const To MinValue = -MaxValue - To(1); - return From(MinValue) <= from && - From(from) <= From(MaxValue); +public: + static bool checkBounds(const From aFrom) + { + if (sizeof(From) <= sizeof(To)) { + return true; } + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + const To MinValue = -MaxValue - To(1); + return From(MinValue) <= aFrom && + From(aFrom) <= From(MaxValue); + } }; template::value && IsIntegral::value> + bool TypesAreIntegral = IsIntegral::value && + IsIntegral::value> class BoundsChecker; template class BoundsChecker { - public: - static bool checkBounds(const From from) { return true; } +public: + static bool checkBounds(const From aFrom) { return true; } }; template class BoundsChecker { - public: - static bool checkBounds(const From from) { - return BoundsCheckImpl::checkBounds(from); - } +public: + static bool checkBounds(const From aFrom) + { + return BoundsCheckImpl::checkBounds(aFrom); + } }; template inline bool -IsInBounds(const From from) +IsInBounds(const From aFrom) { - return BoundsChecker::checkBounds(from); + return BoundsChecker::checkBounds(aFrom); } } // namespace detail @@ -191,10 +210,10 @@ IsInBounds(const From from) */ template inline To -SafeCast(const From from) +SafeCast(const From aFrom) { - MOZ_ASSERT((detail::IsInBounds(from))); - return static_cast(from); + MOZ_ASSERT((detail::IsInBounds(aFrom))); + return static_cast(aFrom); } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ChaosMode.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ChaosMode.h new file mode 100644 index 0000000000..ff59f2c6ec --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ChaosMode.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_ChaosMode_h +#define mozilla_ChaosMode_h + +#include +#include + +namespace mozilla { + +/** + * When "chaos mode" is activated, code that makes implicitly nondeterministic + * choices is encouraged to make random and extreme choices, to test more + * code paths and uncover bugs. + */ +class ChaosMode +{ +public: + static bool isActive() + { + // Flip this to true to activate chaos mode + return false; + } + + /** + * Returns a somewhat (but not uniformly) random uint32_t < aBound. + * Not to be used for anything except ChaosMode, since it's not very random. + */ + static uint32_t randomUint32LessThan(uint32_t aBound) + { + return uint32_t(rand()) % aBound; + } +}; + +} /* namespace mozilla */ + +#endif /* mozilla_ChaosMode_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Char16.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Char16.h index 56b5265789..e54eb0d5c8 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Char16.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Char16.h @@ -9,11 +9,12 @@ #ifndef mozilla_Char16_h #define mozilla_Char16_h +#ifdef __cplusplus + /* - * C11 and C++11 introduce a char16_t type and support for UTF-16 string and - * character literals. C++11's char16_t is a distinct builtin type. C11's - * char16_t is a typedef for uint_least16_t. Technically, char16_t is a 16-bit - * code unit of a Unicode code point, not a "character". + * C++11 introduces a char16_t type and support for UTF-16 string and character + * literals. C++11's char16_t is a distinct builtin type. Technically, char16_t + * is a 16-bit code unit of a Unicode code point, not a "character". */ #ifdef _MSC_VER @@ -23,8 +24,7 @@ * to Windows's 16-bit wchar_t so we can declare UTF-16 literals as constant * expressions (and pass char16_t pointers to Windows APIs). We #define * _CHAR16T here in order to prevent yvals.h from overriding our char16_t - * typedefs, which we set to wchar_t for C++ code and to unsigned short for - * C code. + * typedefs, which we set to wchar_t for C++ code. * * In addition, #defining _CHAR16T will prevent yvals.h from defining a * char32_t type, so we have to undo that damage here and provide our own, @@ -32,15 +32,9 @@ */ # define MOZ_UTF16_HELPER(s) L##s # define _CHAR16T -# ifdef __cplusplus - //typedef wchar_t char16_t; - typedef unsigned short char16_t; -# else - typedef unsigned short char16_t; -# endif - typedef unsigned int char32_t; -#elif defined(__cplusplus) && \ - (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)) +typedef wchar_t char16_t; +typedef unsigned int char32_t; +#else /* C++11 has a builtin char16_t type. */ # define MOZ_UTF16_HELPER(s) u##s /** @@ -51,20 +45,6 @@ # ifdef WIN32 # define MOZ_USE_CHAR16_WRAPPER # endif -#elif !defined(__cplusplus) -# if defined(WIN32) -# include - typedef wchar_t char16_t; -# else - /** - * We can't use the stdint.h uint16_t type here because including - * stdint.h will break building some of our C libraries, such as - * sqlite. - */ - typedef unsigned short char16_t; -# endif -#else -# error "Char16.h requires C++11 (or something like it) for UTF-16 support." #endif #ifdef MOZ_USE_CHAR16_WRAPPER @@ -81,86 +61,109 @@ */ class char16ptr_t { - private: - const char16_t* ptr; - static_assert(sizeof(char16_t) == sizeof(wchar_t), "char16_t and wchar_t sizes differ"); - - public: - char16ptr_t(const char16_t* ptr) : ptr(ptr) {} - char16ptr_t(const wchar_t* ptr) : ptr(reinterpret_cast(ptr)) {} - - /* Without this, nullptr assignment would be ambiguous. */ - constexpr char16ptr_t(decltype(nullptr)) : ptr(nullptr) {} - - operator const char16_t*() const { - return ptr; - } - operator const wchar_t*() const { - return reinterpret_cast(ptr); - } - operator const void*() const { - return ptr; - } - operator bool() const { - return ptr != nullptr; - } - operator std::wstring() const { - return std::wstring(static_cast(*this)); - } - - /* Explicit cast operators to allow things like (char16_t*)str. */ - explicit operator char16_t*() const { - return const_cast(ptr); - } - explicit operator wchar_t*() const { - return const_cast(static_cast(*this)); - } - - /** - * Some Windows API calls accept BYTE* but require that data actually be WCHAR*. - * Supporting this requires explicit operators to support the requisite explicit - * casts. - */ - explicit operator const char*() const { - return reinterpret_cast(ptr); - } - explicit operator const unsigned char*() const { - return reinterpret_cast(ptr); - } - explicit operator unsigned char*() const { - return const_cast(reinterpret_cast(ptr)); - } - explicit operator void*() const { - return const_cast(ptr); - } - - /* Some operators used on pointers. */ - char16_t operator[](size_t i) const { - return ptr[i]; - } - bool operator==(const char16ptr_t &x) const { - return ptr == x.ptr; - } - bool operator==(decltype(nullptr)) const { - return ptr == nullptr; - } - bool operator!=(const char16ptr_t &x) const { - return ptr != x.ptr; - } - bool operator!=(decltype(nullptr)) const { - return ptr != nullptr; - } - char16ptr_t operator+(size_t add) const { - return char16ptr_t(ptr + add); - } - ptrdiff_t operator-(const char16ptr_t &other) const { - return ptr - other.ptr; - } +private: + const char16_t* mPtr; + static_assert(sizeof(char16_t) == sizeof(wchar_t), + "char16_t and wchar_t sizes differ"); + +public: + char16ptr_t(const char16_t* aPtr) : mPtr(aPtr) {} + char16ptr_t(const wchar_t* aPtr) : + mPtr(reinterpret_cast(aPtr)) + {} + + /* Without this, nullptr assignment would be ambiguous. */ + constexpr char16ptr_t(decltype(nullptr)) : mPtr(nullptr) {} + + operator const char16_t*() const + { + return mPtr; + } + operator const wchar_t*() const + { + return reinterpret_cast(mPtr); + } + operator const void*() const + { + return mPtr; + } + operator bool() const + { + return mPtr != nullptr; + } + operator std::wstring() const + { + return std::wstring(static_cast(*this)); + } + + /* Explicit cast operators to allow things like (char16_t*)str. */ + explicit operator char16_t*() const + { + return const_cast(mPtr); + } + explicit operator wchar_t*() const + { + return const_cast(static_cast(*this)); + } + + /** + * Some Windows API calls accept BYTE* but require that data actually be + * WCHAR*. Supporting this requires explicit operators to support the + * requisite explicit casts. + */ + explicit operator const char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator const unsigned char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator unsigned char*() const + { + return + const_cast(reinterpret_cast(mPtr)); + } + explicit operator void*() const + { + return const_cast(mPtr); + } + + /* Some operators used on pointers. */ + char16_t operator[](size_t aIndex) const + { + return mPtr[aIndex]; + } + bool operator==(const char16ptr_t& aOther) const + { + return mPtr == aOther.mPtr; + } + bool operator==(decltype(nullptr)) const + { + return mPtr == nullptr; + } + bool operator!=(const char16ptr_t& aOther) const + { + return mPtr != aOther.mPtr; + } + bool operator!=(decltype(nullptr)) const + { + return mPtr != nullptr; + } + char16ptr_t operator+(size_t aValue) const + { + return char16ptr_t(mPtr + aValue); + } + ptrdiff_t operator-(const char16ptr_t& aOther) const + { + return mPtr - aOther.mPtr; + } }; inline decltype((char*)0-(char*)0) -operator-(const char16_t* x, const char16ptr_t y) { - return x - static_cast(y); +operator-(const char16_t* aX, const char16ptr_t aY) +{ + return aX - static_cast(aY); } #else @@ -169,10 +172,6 @@ typedef const char16_t* char16ptr_t; #endif -/* This is a temporary hack until bug 927728 is fixed. */ -#define __PRUNICHAR__ -typedef char16_t PRUnichar; - /* * Macro arguments used in concatenation or stringification won't be expanded. * Therefore, in order for |MOZ_UTF16(FOO)| to work as expected (which is to @@ -183,12 +182,11 @@ typedef char16_t PRUnichar; */ #define MOZ_UTF16(s) MOZ_UTF16_HELPER(s) -#if defined(__cplusplus) && \ - (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)) static_assert(sizeof(char16_t) == 2, "Is char16_t type 16 bits?"); static_assert(char16_t(-1) > char16_t(0), "Is char16_t type unsigned?"); static_assert(sizeof(MOZ_UTF16('A')) == 2, "Is char literal 16 bits?"); static_assert(sizeof(MOZ_UTF16("")[0]) == 2, "Is string char 16 bits?"); + #endif #endif /* mozilla_Char16_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/CheckedInt.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/CheckedInt.h index 050cef8ed8..ad4c5fef41 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/CheckedInt.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/CheckedInt.h @@ -9,21 +9,9 @@ #ifndef mozilla_CheckedInt_h #define mozilla_CheckedInt_h -// Enable relying of Mozilla's MFBT for possibly-available C++11 features -#define MOZ_CHECKEDINT_USE_MFBT - #include - -#ifdef MOZ_CHECKEDINT_USE_MFBT -# include "mozilla/Assertions.h" -#else -# include -# define MOZ_ASSERT(cond, reason) assert((cond) && reason) -# define MOZ_DELETE -#endif - -#include -#include +#include "mozilla/Assertions.h" +#include "mozilla/IntegerTypeTraits.h" namespace mozilla { @@ -47,13 +35,13 @@ struct UnsupportedType {}; template struct IsSupportedPass2 { - static const bool value = false; + static const bool value = false; }; template struct IsSupported { - static const bool value = IsSupportedPass2::value; + static const bool value = IsSupportedPass2::value; }; template<> @@ -134,133 +122,45 @@ struct IsSupportedPass2 { static const bool value = true; }; /* - * Step 2: some integer-traits kind of stuff. + * Step 2: Implement the actual validity checks. + * + * Ideas taken from IntegerLib, code different. */ -template -struct StdintTypeForSizeAndSignedness -{}; - -template<> -struct StdintTypeForSizeAndSignedness<1, true> -{ typedef int8_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<1, false> -{ typedef uint8_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<2, true> -{ typedef int16_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<2, false> -{ typedef uint16_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<4, true> -{ typedef int32_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<4, false> -{ typedef uint32_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<8, true> -{ typedef int64_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<8, false> -{ typedef uint64_t Type; }; - -template -struct UnsignedType -{ - typedef typename StdintTypeForSizeAndSignedness::Type Type; -}; - -template -struct IsSigned -{ - static const bool value = IntegerType(-1) <= IntegerType(0); -}; - template struct TwiceBiggerType { - typedef typename StdintTypeForSizeAndSignedness< - sizeof(IntegerType) * 2, - IsSigned::value - >::Type Type; + typedef typename detail::StdintTypeForSizeAndSignedness< + sizeof(IntegerType) * 2, + IsSigned::value + >::Type Type; }; template struct TwiceBiggerType { - typedef UnsupportedType Type; + typedef UnsupportedType Type; }; -template -struct PositionOfSignBit -{ - static const size_t value = CHAR_BIT * sizeof(IntegerType) - 1; -}; - -template -struct MinValue -{ - private: - typedef typename UnsignedType::Type UnsignedIntegerType; - static const size_t PosOfSignBit = PositionOfSignBit::value; - - public: - // Bitwise ops may return a larger type, that's why we cast explicitly. - // In C++, left bit shifts on signed values is undefined by the standard - // unless the shifted value is representable. - // Notice that signed-to-unsigned conversions are always well-defined in - // the standard as the value congruent to 2**n, as expected. By contrast, - // unsigned-to-signed is only well-defined if the value is representable. - static const IntegerType value = - IsSigned::value - ? IntegerType(UnsignedIntegerType(1) << PosOfSignBit) - : IntegerType(0); -}; - -template -struct MaxValue -{ - // Tricksy, but covered by the unit test. - // Relies heavily on the type of MinValue::value - // being IntegerType. - static const IntegerType value = ~MinValue::value; -}; - -/* - * Step 3: Implement the actual validity checks. - * - * Ideas taken from IntegerLib, code different. - */ - template inline bool -HasSignBit(T x) +HasSignBit(T aX) { // In C++, right bit shifts on negative values is undefined by the standard. // Notice that signed-to-unsigned conversions are always well-defined in the // standard, as the value congruent modulo 2**n as expected. By contrast, // unsigned-to-signed is only well-defined if the value is representable. - return bool(typename UnsignedType::Type(x) - >> PositionOfSignBit::value); + return bool(typename MakeUnsigned::Type(aX) >> + PositionOfSignBit::value); } // Bitwise ops may return a larger type, so it's good to use this inline // helper guaranteeing that the result is really of type T. template inline T -BinaryComplement(T x) +BinaryComplement(T aX) { - return ~x; + return ~aX; } template struct DoesRangeContainRange { - static const bool value = sizeof(T) >= sizeof(U); + static const bool value = sizeof(T) >= sizeof(U); }; template struct DoesRangeContainRange { - static const bool value = sizeof(T) > sizeof(U); + static const bool value = sizeof(T) > sizeof(U); }; template struct DoesRangeContainRange { - static const bool value = false; + static const bool value = false; }; template struct IsInRangeImpl { - static bool run(U) - { - return true; - } + static bool run(U) + { + return true; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return x <= MaxValue::value && x >= MinValue::value; - } + static bool run(U aX) + { + return aX <= MaxValue::value && aX >= MinValue::value; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return x <= MaxValue::value; - } + static bool run(U aX) + { + return aX <= MaxValue::value; + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return sizeof(T) > sizeof(U) || x <= U(MaxValue::value); - } + static bool run(U aX) + { + return sizeof(T) > sizeof(U) || aX <= U(MaxValue::value); + } }; template struct IsInRangeImpl { - static bool run(U x) - { - return sizeof(T) >= sizeof(U) - ? x >= 0 - : x >= 0 && x <= U(MaxValue::value); - } + static bool run(U aX) + { + return sizeof(T) >= sizeof(U) + ? aX >= 0 + : aX >= 0 && aX <= U(MaxValue::value); + } }; template inline bool -IsInRange(U x) +IsInRange(U aX) { - return IsInRangeImpl::run(x); + return IsInRangeImpl::run(aX); } template inline bool -IsAddValid(T x, T y) +IsAddValid(T aX, T aY) { - // Addition is valid if the sign of x+y is equal to either that of x or that - // of y. Since the value of x+y is undefined if we have a signed type, we - // compute it using the unsigned type of the same size. - // Beware! These bitwise operations can return a larger integer type, - // if T was a small type like int8_t, so we explicitly cast to T. + // Addition is valid if the sign of aX+aY is equal to either that of aX or + // that of aY. Since the value of aX+aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. Beware! + // These bitwise operations can return a larger integer type, if T was a + // small type like int8_t, so we explicitly cast to T. - typename UnsignedType::Type ux = x; - typename UnsignedType::Type uy = y; - typename UnsignedType::Type result = ux + uy; + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux + uy; return IsSigned::value - ? HasSignBit(BinaryComplement(T((result ^ x) & (result ^ y)))) - : BinaryComplement(x) >= y; + ? HasSignBit(BinaryComplement(T((result ^ aX) & (result ^ aY)))) + : BinaryComplement(aX) >= aY; } template inline bool -IsSubValid(T x, T y) +IsSubValid(T aX, T aY) { - // Subtraction is valid if either x and y have same sign, or x-y and x have - // same sign. Since the value of x-y is undefined if we have a signed type, - // we compute it using the unsigned type of the same size. - typename UnsignedType::Type ux = x; - typename UnsignedType::Type uy = y; - typename UnsignedType::Type result = ux - uy; + // Subtraction is valid if either aX and aY have same sign, or aX-aY and aX + // have same sign. Since the value of aX-aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux - uy; return IsSigned::value - ? HasSignBit(BinaryComplement(T((result ^ x) & (x ^ y)))) - : x >= y; + ? HasSignBit(BinaryComplement(T((result ^ aX) & (aX ^ aY)))) + : aX >= aY; } template struct IsMulValidImpl { - static bool run(T x, T y) - { - typedef typename TwiceBiggerType::Type TwiceBiggerType; - TwiceBiggerType product = TwiceBiggerType(x) * TwiceBiggerType(y); - return IsInRange(product); - } + static bool run(T aX, T aY) + { + typedef typename TwiceBiggerType::Type TwiceBiggerType; + TwiceBiggerType product = TwiceBiggerType(aX) * TwiceBiggerType(aY); + return IsInRange(product); + } }; template struct IsMulValidImpl { - static bool run(T x, T y) - { - const T max = MaxValue::value; - const T min = MinValue::value; - - if (x == 0 || y == 0) - return true; - - if (x > 0) { - return y > 0 - ? x <= max / y - : y >= min / x; - } + static bool run(T aX, T aY) + { + const T max = MaxValue::value; + const T min = MinValue::value; - // If we reach this point, we know that x < 0. - return y > 0 - ? x >= min / y - : y >= max / x; + if (aX == 0 || aY == 0) { + return true; } + if (aX > 0) { + return aY > 0 + ? aX <= max / aY + : aY >= min / aX; + } + + // If we reach this point, we know that aX < 0. + return aY > 0 + ? aX >= min / aY + : aY >= max / aX; + } }; template struct IsMulValidImpl { - static bool run(T x, T y) - { - return y == 0 || x <= MaxValue::value / y; - } + static bool run(T aX, T aY) + { + return aY == 0 || aX <= MaxValue::value / aY; + } }; template inline bool -IsMulValid(T x, T y) +IsMulValid(T aX, T aY) { - return IsMulValidImpl::run(x, y); + return IsMulValidImpl::run(aX, aY); } template inline bool -IsDivValid(T x, T y) +IsDivValid(T aX, T aY) { - // Keep in mind that in the signed case, min/-1 is invalid because abs(min)>max. - return y != 0 && - !(IsSigned::value && x == MinValue::value && y == T(-1)); + // Keep in mind that in the signed case, min/-1 is invalid because + // abs(min)>max. + return aY != 0 && + !(IsSigned::value && aX == MinValue::value && aY == T(-1)); } template::value> @@ -455,36 +356,40 @@ struct IsModValidImpl; template inline bool -IsModValid(T x, T y) +IsModValid(T aX, T aY) { - return IsModValidImpl::run(x, y); + return IsModValidImpl::run(aX, aY); } /* * Mod is pretty simple. * For now, let's just use the ANSI C definition: - * If x or y are negative, the results are implementation defined. + * If aX or aY are negative, the results are implementation defined. * Consider these invalid. - * Undefined for y=0. - * The result will never exceed either x or y. + * Undefined for aY=0. + * The result will never exceed either aX or aY. * - * Checking that x>=0 is a warning when T is unsigned. + * Checking that aX>=0 is a warning when T is unsigned. */ template -struct IsModValidImpl { - static inline bool run(T x, T y) { - return y >= 1; +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + return aY >= 1; } }; template -struct IsModValidImpl { - static inline bool run(T x, T y) { - if (x < 0) +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + if (aX < 0) { return false; - - return y >= 1; + } + return aY >= 1; } }; @@ -494,32 +399,33 @@ struct NegateImpl; template struct NegateImpl { - static CheckedInt negate(const CheckedInt& val) - { - // Handle negation separately for signed/unsigned, for simpler code and to - // avoid an MSVC warning negating an unsigned value. - return CheckedInt(0, val.isValid() && val.mValue == 0); - } + static CheckedInt negate(const CheckedInt& aVal) + { + // Handle negation separately for signed/unsigned, for simpler code and to + // avoid an MSVC warning negating an unsigned value. + return CheckedInt(0, aVal.isValid() && aVal.mValue == 0); + } }; template struct NegateImpl { - static CheckedInt negate(const CheckedInt& val) - { - // Watch out for the min-value, which (with twos-complement) can't be - // negated as -min-value is then (max-value + 1). - if (!val.isValid() || val.mValue == MinValue::value) - return CheckedInt(val.mValue, false); - return CheckedInt(-val.mValue, true); + static CheckedInt negate(const CheckedInt& aVal) + { + // Watch out for the min-value, which (with twos-complement) can't be + // negated as -min-value is then (max-value + 1). + if (!aVal.isValid() || aVal.mValue == MinValue::value) { + return CheckedInt(aVal.mValue, false); } + return CheckedInt(-aVal.mValue, true); + } }; } // namespace detail /* - * Step 4: Now define the CheckedInt class. + * Step 3: Now define the CheckedInt class. */ /** @@ -538,18 +444,18 @@ struct NegateImpl * (e.g. in case of a division by zero). * * For example, suppose that you want to implement a function that computes - * (x+y)/z, that doesn't crash if z==0, and that reports on error (divide by + * (aX+aY)/aZ, that doesn't crash if aZ==0, and that reports on error (divide by * zero or integer overflow). You could code it as follows: @code - bool computeXPlusYOverZ(int x, int y, int z, int *result) + bool computeXPlusYOverZ(int aX, int aY, int aZ, int* aResult) { - CheckedInt checkedResult = (CheckedInt(x) + y) / z; - if (checkedResult.isValid()) { - *result = checkedResult.value(); - return true; - } else { - return false; - } + CheckedInt checkedResult = (CheckedInt(aX) + aY) / aZ; + if (checkedResult.isValid()) { + *aResult = checkedResult.value(); + return true; + } else { + return false; + } } @endcode * @@ -592,193 +498,188 @@ struct NegateImpl template class CheckedInt { - protected: - T mValue; - bool mIsValid; +protected: + T mValue; + bool mIsValid; - template - CheckedInt(U value, bool isValid) : mValue(value), mIsValid(isValid) - { - static_assert(detail::IsSupported::value && - detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + template + CheckedInt(U aValue, bool aIsValid) : mValue(aValue), mIsValid(aIsValid) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - friend struct detail::NegateImpl; - - public: - /** - * Constructs a checked integer with given @a value. The checked integer is - * initialized as valid or invalid depending on whether the @a value - * is in range. - * - * This constructor is not explicit. Instead, the type of its argument is a - * separate template parameter, ensuring that no conversion is performed - * before this constructor is actually called. As explained in the above - * documentation for class CheckedInt, this constructor checks that its - * argument is valid. - */ - template - CheckedInt(U value) - : mValue(T(value)), - mIsValid(detail::IsInRange(value)) - { - static_assert(detail::IsSupported::value && - detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + friend struct detail::NegateImpl; + +public: + /** + * Constructs a checked integer with given @a value. The checked integer is + * initialized as valid or invalid depending on whether the @a value + * is in range. + * + * This constructor is not explicit. Instead, the type of its argument is a + * separate template parameter, ensuring that no conversion is performed + * before this constructor is actually called. As explained in the above + * documentation for class CheckedInt, this constructor checks that its + * argument is valid. + */ + template + CheckedInt(U aValue) + : mValue(T(aValue)), + mIsValid(detail::IsInRange(aValue)) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - template - friend class CheckedInt; + template + friend class CheckedInt; - template - CheckedInt toChecked() const - { - CheckedInt ret(mValue); - ret.mIsValid = ret.mIsValid && mIsValid; - return ret; - } + template + CheckedInt toChecked() const + { + CheckedInt ret(mValue); + ret.mIsValid = ret.mIsValid && mIsValid; + return ret; + } - /** Constructs a valid checked integer with initial value 0 */ - CheckedInt() : mValue(0), mIsValid(true) - { - static_assert(detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } + /** Constructs a valid checked integer with initial value 0 */ + CheckedInt() : mValue(0), mIsValid(true) + { + static_assert(detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } - /** @returns the actual value */ - T value() const - { - MOZ_ASSERT(mIsValid, "Invalid checked integer (division by zero or integer overflow)"); - return mValue; - } + /** @returns the actual value */ + T value() const + { + MOZ_ASSERT(mIsValid, "Invalid checked integer (division by zero or integer overflow)"); + return mValue; + } - /** - * @returns true if the checked integer is valid, i.e. is not the result - * of an invalid operation or of an operation involving an invalid checked - * integer - */ - bool isValid() const - { - return mIsValid; - } + /** + * @returns true if the checked integer is valid, i.e. is not the result + * of an invalid operation or of an operation involving an invalid checked + * integer + */ + bool isValid() const + { + return mIsValid; + } - template - friend CheckedInt operator +(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator +=(U rhs); - - template - friend CheckedInt operator -(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator -=(U rhs); - - template - friend CheckedInt operator *(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator *=(U rhs); - - template - friend CheckedInt operator /(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator /=(U rhs); - - template - friend CheckedInt operator %(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator %=(U rhs); - - CheckedInt operator -() const - { - return detail::NegateImpl::negate(*this); - } + template + friend CheckedInt operator +(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator +=(U aRhs); + + template + friend CheckedInt operator -(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator -=(U aRhs); + + template + friend CheckedInt operator *(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator *=(U aRhs); + + template + friend CheckedInt operator /(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator /=(U aRhs); + + template + friend CheckedInt operator %(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator %=(U aRhs); + + CheckedInt operator -() const + { + return detail::NegateImpl::negate(*this); + } - /** - * @returns true if the left and right hand sides are valid - * and have the same value. - * - * Note that these semantics are the reason why we don't offer - * a operator!=. Indeed, we'd want to have a!=b be equivalent to !(a==b) - * but that would mean that whenever a or b is invalid, a!=b - * is always true, which would be very confusing. - * - * For similar reasons, operators <, >, <=, >= would be very tricky to - * specify, so we just avoid offering them. - * - * Notice that these == semantics are made more reasonable by these facts: - * 1. a==b implies equality at the raw data level - * (the converse is false, as a==b is never true among invalids) - * 2. This is similar to the behavior of IEEE floats, where a==b - * means that a and b have the same value *and* neither is NaN. - */ - bool operator ==(const CheckedInt& other) const - { - return mIsValid && other.mIsValid && mValue == other.mValue; - } + /** + * @returns true if the left and right hand sides are valid + * and have the same value. + * + * Note that these semantics are the reason why we don't offer + * a operator!=. Indeed, we'd want to have a!=b be equivalent to !(a==b) + * but that would mean that whenever a or b is invalid, a!=b + * is always true, which would be very confusing. + * + * For similar reasons, operators <, >, <=, >= would be very tricky to + * specify, so we just avoid offering them. + * + * Notice that these == semantics are made more reasonable by these facts: + * 1. a==b implies equality at the raw data level + * (the converse is false, as a==b is never true among invalids) + * 2. This is similar to the behavior of IEEE floats, where a==b + * means that a and b have the same value *and* neither is NaN. + */ + bool operator ==(const CheckedInt& aOther) const + { + return mIsValid && aOther.mIsValid && mValue == aOther.mValue; + } - /** prefix ++ */ - CheckedInt& operator++() - { - *this += 1; - return *this; - } + /** prefix ++ */ + CheckedInt& operator++() + { + *this += 1; + return *this; + } - /** postfix ++ */ - CheckedInt operator++(int) - { - CheckedInt tmp = *this; - *this += 1; - return tmp; - } + /** postfix ++ */ + CheckedInt operator++(int) + { + CheckedInt tmp = *this; + *this += 1; + return tmp; + } - /** prefix -- */ - CheckedInt& operator--() - { - *this -= 1; - return *this; - } + /** prefix -- */ + CheckedInt& operator--() + { + *this -= 1; + return *this; + } - /** postfix -- */ - CheckedInt operator--(int) - { - CheckedInt tmp = *this; - *this -= 1; - return tmp; - } + /** postfix -- */ + CheckedInt operator--(int) + { + CheckedInt tmp = *this; + *this -= 1; + return tmp; + } - private: - /** - * The !=, <, <=, >, >= operators are disabled: - * see the comment on operator==. - */ - template - bool operator !=(U other) const MOZ_DELETE; - template - bool operator <(U other) const MOZ_DELETE; - template - bool operator <=(U other) const MOZ_DELETE; - template - bool operator >(U other) const MOZ_DELETE; - template - bool operator >=(U other) const MOZ_DELETE; +private: + /** + * The !=, <, <=, >, >= operators are disabled: + * see the comment on operator==. + */ + template bool operator !=(U aOther) const MOZ_DELETE; + template bool operator < (U aOther) const MOZ_DELETE; + template bool operator <=(U aOther) const MOZ_DELETE; + template bool operator > (U aOther) const MOZ_DELETE; + template bool operator >=(U aOther) const MOZ_DELETE; }; -#define MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP) \ -template \ -inline CheckedInt operator OP(const CheckedInt &lhs, \ - const CheckedInt &rhs) \ -{ \ - if (!detail::Is##NAME##Valid(lhs.mValue, rhs.mValue)) \ - return CheckedInt(0, false); \ - \ - return CheckedInt(lhs.mValue OP rhs.mValue, \ - lhs.mIsValid && rhs.mIsValid); \ -} +#define MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP) \ + template \ + inline CheckedInt \ + operator OP(const CheckedInt &aLhs, const CheckedInt &aRhs) \ + { \ + if (!detail::Is##NAME##Valid(aLhs.mValue, aRhs.mValue)) { \ + return CheckedInt(0, false); \ + } \ + return CheckedInt(aLhs.mValue OP aRhs.mValue, \ + aLhs.mIsValid && aRhs.mIsValid); \ + } MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Add, +) MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Sub, -) @@ -799,47 +700,47 @@ namespace detail { template struct CastToCheckedIntImpl { - typedef CheckedInt ReturnType; - static CheckedInt run(U u) { return u; } + typedef CheckedInt ReturnType; + static CheckedInt run(U aU) { return aU; } }; template struct CastToCheckedIntImpl > { - typedef const CheckedInt& ReturnType; - static const CheckedInt& run(const CheckedInt& u) { return u; } + typedef const CheckedInt& ReturnType; + static const CheckedInt& run(const CheckedInt& aU) { return aU; } }; } // namespace detail template inline typename detail::CastToCheckedIntImpl::ReturnType -castToCheckedInt(U u) +castToCheckedInt(U aU) { static_assert(detail::IsSupported::value && detail::IsSupported::value, "This type is not supported by CheckedInt"); - return detail::CastToCheckedIntImpl::run(u); + return detail::CastToCheckedIntImpl::run(aU); } -#define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP) \ -template \ -template \ -CheckedInt& CheckedInt::operator COMPOUND_OP(U rhs) \ -{ \ - *this = *this OP castToCheckedInt(rhs); \ - return *this; \ -} \ -template \ -inline CheckedInt operator OP(const CheckedInt &lhs, U rhs) \ -{ \ - return lhs OP castToCheckedInt(rhs); \ -} \ -template \ -inline CheckedInt operator OP(U lhs, const CheckedInt &rhs) \ -{ \ - return castToCheckedInt(lhs) OP rhs; \ -} +#define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP) \ + template \ + template \ + CheckedInt& CheckedInt::operator COMPOUND_OP(U aRhs) \ + { \ + *this = *this OP castToCheckedInt(aRhs); \ + return *this; \ + } \ + template \ + inline CheckedInt operator OP(const CheckedInt &aLhs, U aRhs) \ + { \ + return aLhs OP castToCheckedInt(aRhs); \ + } \ + template \ + inline CheckedInt operator OP(U aLhs, const CheckedInt &aRhs) \ + { \ + return castToCheckedInt(aLhs) OP aRhs; \ + } MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(+, +=) MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(*, *=) @@ -851,16 +752,16 @@ MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(%, %=) template inline bool -operator ==(const CheckedInt &lhs, U rhs) +operator ==(const CheckedInt &aLhs, U aRhs) { - return lhs == castToCheckedInt(rhs); + return aLhs == castToCheckedInt(aRhs); } template inline bool -operator ==(U lhs, const CheckedInt &rhs) +operator ==(U aLhs, const CheckedInt &aRhs) { - return castToCheckedInt(lhs) == rhs; + return castToCheckedInt(aLhs) == aRhs; } // Convenience typedefs. diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Compiler.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Compiler.h index fd5c98c98d..50f127da86 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Compiler.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Compiler.h @@ -9,23 +9,41 @@ #ifndef mozilla_Compiler_h #define mozilla_Compiler_h +#define MOZ_IS_GCC 0 +#define MOS_IS_MSVC 0 + #if !defined(__clang__) && defined(__GNUC__) -#define MOZ_IS_GCC 1 +# undef MOZ_IS_GCC +# define MOZ_IS_GCC 1 /* * This macro should simplify gcc version checking. For example, to check - * for gcc 4.5.1 or later, check `#ifdef MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`. + * for gcc 4.5.1 or later, check `#if MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`. */ # define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel) \ ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \ >= ((major) * 10000 + (minor) * 100 + (patchlevel))) -#if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0) -# error "mfbt (and Gecko) require at least gcc 4.4 to build." -#endif +# if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0) +# error "mfbt (and Gecko) require at least gcc 4.4 to build." +# endif -#else +#elif defined(_MSC_VER) -#define MOZ_IS_GCC 0 +# undef MOZ_IS_MSVC +# define MOZ_IS_MSVC 1 + /* + * This macro should simplify MSVC version checking. For example, to check + * for VC10 or later, check `#ifdef MOZ_MSVC_VERSION_AT_LEAST(10)`. + */ +# define MOZ_MSVC_VERSION_AT_LEAST(version) \ + (version == 10 ? _MSC_VER >= 1600 : \ + (version == 11 ? _MSC_VER >= 1700 : \ + (version == 12 ? _MSC_VER >= 1800 : \ + (version == 13 ? _MSC_VER >= 1900 : \ + 0)))) +# if !MOZ_MSVC_VERSION_AT_LEAST(10) +# error "mfbt (and Gecko) require at least MSVC 2010 RTM to build." +# endif #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Compression.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Compression.h index 2b8a7a7d8e..a764a1b5d5 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Compression.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Compression.h @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -22,41 +23,41 @@ namespace Compression { * * Compared to zlib it compresses at about 10x the speed, decompresses at about * 4x the speed and produces output of about 1.5x the size. - * */ class LZ4 { - public: - /** - * Compresses 'inputSize' bytes from 'source' into 'dest'. - * Destination buffer must be already allocated, - * and must be sized to handle worst cases situations (input data not compressible) - * Worst case size evaluation is provided by function LZ4_compressBound() + * Compresses |aInputSize| bytes from |aSource| into |aDest|. Destination + * buffer must be already allocated, and must be sized to handle worst cases + * situations (input data not compressible). Worst case size evaluation is + * provided by function maxCompressedSize() * - * @param inputSize is the input size. Max supported value is ~1.9GB - * @param return the number of bytes written in buffer dest + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return the number of bytes written in buffer |aDest| */ - static MFBT_API size_t compress(const char* source, size_t inputSize, char* dest); + static MFBT_API size_t + compress(const char* aSource, size_t aInputSize, char* aDest); /** - * Compress 'inputSize' bytes from 'source' into an output buffer - * 'dest' of maximum size 'maxOutputSize'. If it cannot achieve it, + * Compress |aInputSize| bytes from |aSource| into an output buffer + * |aDest| of maximum size |aMaxOutputSize|. If it cannot achieve it, * compression will stop, and result of the function will be zero, - * 'dest' will still be written to, but since the number of input + * |aDest| will still be written to, but since the number of input * bytes consumed is not returned the result is not usable. * * This function never writes outside of provided output buffer. * - * @param inputSize is the input size. Max supported value is ~1.9GB - * @param maxOutputSize is the size of the destination buffer (which must be already allocated) - * @return the number of bytes written in buffer 'dest' - or 0 if the compression fails - */ - static MFBT_API size_t compressLimitedOutput(const char* source, size_t inputSize, char* dest, - size_t maxOutputSize); + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @param aMaxOutputSize is the size of the destination buffer (which must + * be already allocated) + * @return the number of bytes written in buffer |aDest| or 0 if the + * compression fails + */ + static MFBT_API size_t + compressLimitedOutput(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize); /** * If the source stream is malformed, the function will stop decoding @@ -66,48 +67,50 @@ class LZ4 * This function never writes outside of provided buffers, and never * modifies input buffer. * - * note : destination buffer must be already allocated. - * its size must be a minimum of 'outputSize' bytes. - * @param outputSize is the output size, therefore the original size + * Note: destination buffer must be already allocated, and its size must be a + * minimum of |aOutputSize| bytes. + * + * @param aOutputSize is the output size, therefore the original size * @return the number of bytes read in the source buffer - */ - static MFBT_API bool decompress(const char* source, char* dest, size_t outputSize); + */ + static MFBT_API bool + decompress(const char* aSource, char* aDest, size_t aOutputSize); /** * If the source stream is malformed, the function will stop decoding * and return false. * - * This function never writes beyond dest + maxOutputSize, and is + * This function never writes beyond aDest + aMaxOutputSize, and is * therefore protected against malicious data packets. * - * note : Destination buffer must be already allocated. - * This version is slightly slower than the decompress - * without the maxOutputSize + * Note: Destination buffer must be already allocated. This version is + * slightly slower than the decompress without the aMaxOutputSize. * - * @param inputSize is the length of the input compressed data - * @param maxOutputSize is the size of the destination buffer (which must be already allocated) - * @param outputSize the actual number of bytes decoded in the destination buffer (necessarily <= maxOutputSize) - - */ - static MFBT_API bool decompress(const char* source, size_t inputSize, char* dest, - size_t maxOutputSize, size_t *outputSize); + * @param aInputSize is the length of the input compressed data + * @param aMaxOutputSize is the size of the destination buffer (which must be + * already allocated) + * @param aOutputSize the actual number of bytes decoded in the destination + * buffer (necessarily <= aMaxOutputSize) + */ + static MFBT_API bool + decompress(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize, size_t* aOutputSize); /* - Provides the maximum size that LZ4 may output in a "worst case" - scenario (input data not compressible) primarily useful for memory - allocation of output buffer. - note : this function is limited by "int" range (2^31-1) - - @param inputSize is the input size. Max supported value is ~1.9GB - @return maximum output size in a "worst case" scenario - */ - static inline size_t maxCompressedSize(size_t inputSize) + * Provides the maximum size that LZ4 may output in a "worst case" + * scenario (input data not compressible) primarily useful for memory + * allocation of output buffer. + * note : this function is limited by "int" range (2^31-1) + * + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return maximum output size in a "worst case" scenario + */ + static inline size_t maxCompressedSize(size_t aInputSize) { - size_t max = ((inputSize) + ((inputSize)/255) + 16); - MOZ_ASSERT(max > inputSize); - return max; + size_t max = (aInputSize + (aInputSize / 255) + 16); + MOZ_ASSERT(max > aInputSize); + return max; } - }; } /* namespace Compression */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/DebugOnly.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/DebugOnly.h index e5f0d729b5..5d0197b194 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/DebugOnly.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/DebugOnly.h @@ -12,6 +12,8 @@ #ifndef mozilla_DebugOnly_h #define mozilla_DebugOnly_h +#include "mozilla/Attributes.h" + namespace mozilla { /** @@ -27,50 +29,51 @@ namespace mozilla { * * DebugOnly instances can only be coerced to T in debug builds. In release * builds they don't have a value, so type coercion is not well defined. + * + * Note that DebugOnly instances still take up one byte of space, plus padding, + * when used as members of structs. */ template class DebugOnly { - public: +public: #ifdef DEBUG - T value; + T value; + + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T& aOther) : value(aOther) { } + DebugOnly(const DebugOnly& aOther) : value(aOther.value) { } + DebugOnly& operator=(const T& aRhs) { + value = aRhs; + return *this; + } - DebugOnly() { } - DebugOnly(const T& other) : value(other) { } - DebugOnly(const DebugOnly& other) : value(other.value) { } - DebugOnly& operator=(const T& rhs) { - value = rhs; - return *this; - } - void operator++(int) { - value++; - } - void operator--(int) { - value--; - } + void operator++(int) { value++; } + void operator--(int) { value--; } - T* operator&() { return &value; } + T* operator&() { return &value; } - operator T&() { return value; } - operator const T&() const { return value; } + operator T&() { return value; } + operator const T&() const { return value; } - T& operator->() { return value; } + T& operator->() { return value; } + const T& operator->() const { return value; } #else - DebugOnly() { } - DebugOnly(const T&) { } - DebugOnly(const DebugOnly&) { } - DebugOnly& operator=(const T&) { return *this; } - void operator++(int) { } - void operator--(int) { } + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T&) { } + DebugOnly(const DebugOnly&) { } + DebugOnly& operator=(const T&) { return *this; } + void operator++(int) { } + void operator--(int) { } #endif - /* - * DebugOnly must always have a destructor or else it will - * generate "unused variable" warnings, exactly what it's intended - * to avoid! - */ - ~DebugOnly() {} + /* + * DebugOnly must always have a destructor or else it will + * generate "unused variable" warnings, exactly what it's intended + * to avoid! + */ + ~DebugOnly() {} }; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Decimal.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Decimal.h index 3c67d784c9..9f4926bd06 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Decimal.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Decimal.h @@ -112,7 +112,7 @@ class Decimal { Sign m_sign; }; - MFBT_API Decimal(int32_t = 0); + MFBT_API explicit Decimal(int32_t = 0); MFBT_API Decimal(Sign, int exponent, uint64_t coefficient); MFBT_API Decimal(const Decimal&); @@ -185,7 +185,7 @@ class Decimal { int exponent; }; - MFBT_API Decimal(double); + MFBT_API explicit Decimal(double); MFBT_API Decimal compareTo(const Decimal&) const; static MFBT_API AlignedOperands alignOperands(const Decimal& lhs, const Decimal& rhs); diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Endian.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Endian.h index cb6bd27c05..e4e1ff8549 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Endian.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Endian.h @@ -42,21 +42,22 @@ * * class ExampleHeader * { - * private: - * uint32_t magic; - * uint32_t length; - * uint32_t totalRecords; - * uint64_t checksum; + * private: + * uint32_t mMagic; + * uint32_t mLength; + * uint32_t mTotalRecords; + * uint64_t mChecksum; * - * public: - * ExampleHeader(const void* data) { - * const uint8_t* ptr = static_cast(data); - * magic = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * length = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * totalRecords = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); - * checksum = BigEndian::readUint64(ptr); - * } - * ... + * public: + * ExampleHeader(const void* data) + * { + * const uint8_t* ptr = static_cast(data); + * mMagic = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mLength = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mTotalRecords = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mChecksum = BigEndian::readUint64(ptr); + * } + * ... * }; */ @@ -91,7 +92,7 @@ # else # error "CPU type is unknown" # endif -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) # if __LITTLE_ENDIAN__ # define MOZ_LITTLE_ENDIAN 1 # elif __BIG_ENDIAN__ @@ -119,17 +120,16 @@ * cases. */ #elif defined(__sparc) || defined(__sparc__) || \ - defined(_POWER) || defined(__powerpc__) || \ - defined(__ppc__) || defined(__hppa) || \ + defined(_POWER) || defined(__hppa) || \ defined(_MIPSEB) || defined(__ARMEB__) || \ - defined(__s390__) || \ + defined(__s390__) || defined(__AARCH64EB__) || \ (defined(__sh__) && defined(__LITTLE_ENDIAN__)) || \ (defined(__ia64) && defined(__BIG_ENDIAN__)) # define MOZ_BIG_ENDIAN 1 #elif defined(__i386) || defined(__i386__) || \ defined(__x86_64) || defined(__x86_64__) || \ defined(_MIPSEL) || defined(__ARMEL__) || \ - defined(__alpha__) || \ + defined(__alpha__) || defined(__AARCH64EL__) || \ (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ (defined(__ia64) && !defined(__BIG_ENDIAN__)) # define MOZ_LITTLE_ENDIAN 1 @@ -170,12 +170,12 @@ struct Swapper; template struct Swapper { - static T swap(T value) + static T swap(T aValue) { #if defined(MOZ_HAVE_BUILTIN_BYTESWAP16) - return MOZ_HAVE_BUILTIN_BYTESWAP16(value); + return MOZ_HAVE_BUILTIN_BYTESWAP16(aValue); #else - return T(((value & 0x00ff) << 8) | ((value & 0xff00) >> 8)); + return T(((aValue & 0x00ff) << 8) | ((aValue & 0xff00) >> 8)); #endif } }; @@ -183,17 +183,17 @@ struct Swapper template struct Swapper { - static T swap(T value) + static T swap(T aValue) { #if defined(__clang__) || defined(__GNUC__) - return T(__builtin_bswap32(value)); + return T(__builtin_bswap32(aValue)); #elif defined(_MSC_VER) - return T(_byteswap_ulong(value)); + return T(_byteswap_ulong(aValue)); #else - return T(((value & 0x000000ffU) << 24) | - ((value & 0x0000ff00U) << 8) | - ((value & 0x00ff0000U) >> 8) | - ((value & 0xff000000U) >> 24)); + return T(((aValue & 0x000000ffU) << 24) | + ((aValue & 0x0000ff00U) << 8) | + ((aValue & 0x00ff0000U) >> 8) | + ((aValue & 0xff000000U) >> 24)); #endif } }; @@ -201,21 +201,21 @@ struct Swapper template struct Swapper { - static inline T swap(T value) + static inline T swap(T aValue) { #if defined(__clang__) || defined(__GNUC__) - return T(__builtin_bswap64(value)); + return T(__builtin_bswap64(aValue)); #elif defined(_MSC_VER) - return T(_byteswap_uint64(value)); + return T(_byteswap_uint64(aValue)); #else - return T(((value & 0x00000000000000ffULL) << 56) | - ((value & 0x000000000000ff00ULL) << 40) | - ((value & 0x0000000000ff0000ULL) << 24) | - ((value & 0x00000000ff000000ULL) << 8) | - ((value & 0x000000ff00000000ULL) >> 8) | - ((value & 0x0000ff0000000000ULL) >> 24) | - ((value & 0x00ff000000000000ULL) >> 40) | - ((value & 0xff00000000000000ULL) >> 56)); + return T(((aValue & 0x00000000000000ffULL) << 56) | + ((aValue & 0x000000000000ff00ULL) << 40) | + ((aValue & 0x0000000000ff0000ULL) << 24) | + ((aValue & 0x00000000ff000000ULL) << 8) | + ((aValue & 0x000000ff00000000ULL) >> 8) | + ((aValue & 0x0000ff0000000000ULL) >> 24) | + ((aValue & 0x00ff000000000000ULL) >> 40) | + ((aValue & 0xff00000000000000ULL) >> 56)); #endif } }; @@ -230,360 +230,415 @@ enum Endianness { Little, Big }; class EndianUtils { - /** - * Assert that the memory regions [dest, dest+count) and [src, src+count] - * do not overlap. count is given in bytes. - */ - static void assertNoOverlap(const void* dest, const void* src, size_t count) - { - DebugOnly byteDestPtr = static_cast(dest); - DebugOnly byteSrcPtr = static_cast(src); - MOZ_ASSERT((byteDestPtr <= byteSrcPtr && - byteDestPtr + count <= byteSrcPtr) || - (byteSrcPtr <= byteDestPtr && - byteSrcPtr + count <= byteDestPtr)); - } + /** + * Assert that the memory regions [aDest, aDest+aCount) and + * [aSrc, aSrc+aCount] do not overlap. aCount is given in bytes. + */ + static void assertNoOverlap(const void* aDest, const void* aSrc, + size_t aCount) + { + DebugOnly byteDestPtr = static_cast(aDest); + DebugOnly byteSrcPtr = static_cast(aSrc); + MOZ_ASSERT((byteDestPtr <= byteSrcPtr && + byteDestPtr + aCount <= byteSrcPtr) || + (byteSrcPtr <= byteDestPtr && + byteSrcPtr + aCount <= byteDestPtr)); + } - template - static void assertAligned(T* ptr) - { - MOZ_ASSERT((uintptr_t(ptr) % sizeof(T)) == 0, "Unaligned pointer!"); + template + static void assertAligned(T* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % sizeof(T)) == 0, "Unaligned pointer!"); + } + +protected: + /** + * Return |aValue| converted from SourceEndian encoding to DestEndian + * encoding. + */ + template + static inline T maybeSwap(T aValue) + { + if (SourceEndian == DestEndian) { + return aValue; } + return Swapper::swap(aValue); + } - protected: - /** - * Return |value| converted from SourceEndian encoding to DestEndian - * encoding. - */ - template - static inline T maybeSwap(T value) - { - if (SourceEndian == DestEndian) - return value; + /** + * Convert |aCount| elements at |aPtr| from SourceEndian encoding to + * DestEndian encoding. + */ + template + static inline void maybeSwapInPlace(T* aPtr, size_t aCount) + { + assertAligned(aPtr); - return Swapper::swap(value); + if (SourceEndian == DestEndian) { + return; } + for (size_t i = 0; i < aCount; i++) { + aPtr[i] = Swapper::swap(aPtr[i]); + } + } - /** - * Convert |count| elements at |ptr| from SourceEndian encoding to - * DestEndian encoding. - */ - template - static inline void maybeSwapInPlace(T* ptr, size_t count) - { - assertAligned(ptr); + /** + * Write |aCount| elements to the unaligned address |aDest| in DestEndian + * format, using elements found at |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapTo(void* aDest, const T* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aSrc); - if (SourceEndian == DestEndian) - return; + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; + } - for (size_t i = 0; i < count; i++) - ptr[i] = Swapper::swap(ptr[i]); + uint8_t* byteDestPtr = static_cast(aDest); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + u.mVal = maybeSwap(aSrc[i]); + memcpy(byteDestPtr, u.mBuffer, sizeof(T)); + byteDestPtr += sizeof(T); } + } - /** - * Write |count| elements to the unaligned address |dest| in DestEndian - * format, using elements found at |src| in SourceEndian format. - */ - template - static void copyAndSwapTo(void* dest, const T* src, size_t count) - { - assertNoOverlap(dest, src, count * sizeof(T)); - assertAligned(src); - - if (SourceEndian == DestEndian) { - memcpy(dest, src, count * sizeof(T)); - return; - } - - uint8_t* byteDestPtr = static_cast(dest); - for (size_t i = 0; i < count; ++i) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - u.val = maybeSwap(src[i]); - memcpy(byteDestPtr, u.buffer, sizeof(T)); - byteDestPtr += sizeof(T); - } + /** + * Write |aCount| elements to |aDest| in DestEndian format, using elements + * found at the unaligned address |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapFrom(T* aDest, const void* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aDest); + + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; } - /** - * Write |count| elements to |dest| in DestEndian format, using elements - * found at the unaligned address |src| in SourceEndian format. - */ - template - static void copyAndSwapFrom(T* dest, const void* src, size_t count) - { - assertNoOverlap(dest, src, count * sizeof(T)); - assertAligned(dest); - - if (SourceEndian == DestEndian) { - memcpy(dest, src, count * sizeof(T)); - return; - } - - const uint8_t* byteSrcPtr = static_cast(src); - for (size_t i = 0; i < count; ++i) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - memcpy(u.buffer, byteSrcPtr, sizeof(T)); - dest[i] = maybeSwap(u.val); - byteSrcPtr += sizeof(T); - } + const uint8_t* byteSrcPtr = static_cast(aSrc); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, byteSrcPtr, sizeof(T)); + aDest[i] = maybeSwap(u.mVal); + byteSrcPtr += sizeof(T); } + } }; template class Endian : private EndianUtils { - protected: - /** Read a uint16_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint16_t readUint16(const void* p) { - return read(p); - } +protected: + /** Read a uint16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint16_t readUint16(const void* aPtr) + { + return read(aPtr); + } - /** Read a uint32_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint32_t readUint32(const void* p) { - return read(p); - } + /** Read a uint32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint32_t readUint32(const void* aPtr) + { + return read(aPtr); + } - /** Read a uint64_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT uint64_t readUint64(const void* p) { - return read(p); - } + /** Read a uint64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint64_t readUint64(const void* aPtr) + { + return read(aPtr); + } - /** Read an int16_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int16_t readInt16(const void* p) { - return read(p); - } + /** Read an int16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int16_t readInt16(const void* aPtr) + { + return read(aPtr); + } - /** Read an int32_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int32_t readInt32(const void* p) { - return read(p); - } + /** Read an int32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int32_t readInt32(const void* aPtr) + { + return read(aPtr); + } - /** Read an int64_t in ThisEndian endianness from |p| and return it. */ - static MOZ_WARN_UNUSED_RESULT int64_t readInt64(const void* p) { - return read(p); - } + /** Read an int64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int64_t readInt64(const void* aPtr) + { + return read(aPtr); + } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint16(void* p, uint16_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint32(void* p, uint32_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeUint64(void* p, uint64_t val) { - write(p, val); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint16(void* aPtr, uint16_t aValue) + { + write(aPtr, aValue); + } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt16(void* p, int16_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt32(void* p, int32_t val) { - write(p, val); - } - /** Write |val| to |p| using ThisEndian endianness. */ - static void writeInt64(void* p, int64_t val) { - write(p, val); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint32(void* aPtr, uint32_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T to little-endian format. - * - * This function is intended for cases where you have data in your - * native-endian format and you need it to appear in little-endian - * format for transmission. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToLittleEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to little-endian format if ThisEndian is Big. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapToLittleEndian(void* dest, const T* src, - size_t count) { - copyAndSwapTo(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapToLittleEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint64(void* aPtr, uint64_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T to big-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToBigEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to big-endian format if ThisEndian is Little. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapToBigEndian(void* dest, const T* src, size_t count) { - copyAndSwapTo(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapToBigEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt16(void* aPtr, int16_t aValue) + { + write(aPtr, aValue); + } - /* - * Synonyms for the big-endian functions, for better readability - * in network code. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapToNetworkOrder(T value) { - return swapToBigEndian(value); - } - template - static void - copyAndSwapToNetworkOrder(void* dest, const T* src, size_t count) { - copyAndSwapToBigEndian(dest, src, count); - } - template - static void - swapToNetworkOrderInPlace(T* p, size_t count) { - swapToBigEndianInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt32(void* aPtr, int32_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T from little-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromLittleEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to little-endian format if ThisEndian is Big. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapFromLittleEndian(T* dest, const void* src, - size_t count) { - copyAndSwapFrom(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapFromLittleEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt64(void* aPtr, int64_t aValue) + { + write(aPtr, aValue); + } - /* - * Converts a value of type T from big-endian format. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromBigEndian(T value) { - return maybeSwap(value); - } - /* - * Copies count values of type T starting at src to dest, converting - * them to big-endian format if ThisEndian is Little. - * As with memcpy, dest and src must not overlap. - */ - template - static void copyAndSwapFromBigEndian(T* dest, const void* src, - size_t count) { - copyAndSwapFrom(dest, src, count); - } - /* - * Likewise, but converts values in place. - */ - template - static void swapFromBigEndianInPlace(T* p, size_t count) { - maybeSwapInPlace(p, count); - } + /* + * Converts a value of type T to little-endian format. + * + * This function is intended for cases where you have data in your + * native-endian format and you need it to appear in little-endian + * format for transmission. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToLittleEndian(T aValue) + { + return maybeSwap(aValue); + } - /* - * Synonyms for the big-endian functions, for better readability - * in network code. - */ - template - MOZ_WARN_UNUSED_RESULT static T swapFromNetworkOrder(T value) { - return swapFromBigEndian(value); - } - template - static void copyAndSwapFromNetworkOrder(T* dest, const void* src, - size_t count) { - copyAndSwapFromBigEndian(dest, src, count); - } - template - static void swapFromNetworkOrderInPlace(T* p, size_t count) { - swapFromBigEndianInPlace(p, count); - } + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToLittleEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } - private: - /** - * Read a value of type T, encoded in endianness ThisEndian from |p|. - * Return that value encoded in native endianness. - */ - template - static T read(const void* p) { - union { - T val; - uint8_t buffer[sizeof(T)]; - } u; - memcpy(u.buffer, p, sizeof(T)); - return maybeSwap(u.val); - } + /* + * Likewise, but converts values in place. + */ + template + static void swapToLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } - /** - * Write a value of type T, in native endianness, to |p|, in ThisEndian - * endianness. - */ - template - static void write(void* p, T value) { - T tmp = maybeSwap(value); - memcpy(p, &tmp, sizeof(T)); - } + /* + * Converts a value of type T to big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToBigEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapToBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + + template + MOZ_WARN_UNUSED_RESULT static T swapToNetworkOrder(T aValue) + { + return swapToBigEndian(aValue); + } + + template + static void + copyAndSwapToNetworkOrder(void* aDest, const T* aSrc, size_t aCount) + { + copyAndSwapToBigEndian(aDest, aSrc, aCount); + } + + template + static void + swapToNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapToBigEndianInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from little-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromLittleEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromLittleEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromBigEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromNetworkOrder(T aValue) + { + return swapFromBigEndian(aValue); + } + + template + static void copyAndSwapFromNetworkOrder(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFromBigEndian(aDest, aSrc, aCount); + } + + template + static void swapFromNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapFromBigEndianInPlace(aPtr, aCount); + } + +private: + /** + * Read a value of type T, encoded in endianness ThisEndian from |aPtr|. + * Return that value encoded in native endianness. + */ + template + static T read(const void* aPtr) + { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, aPtr, sizeof(T)); + return maybeSwap(u.mVal); + } + + /** + * Write a value of type T, in native endianness, to |aPtr|, in ThisEndian + * endianness. + */ + template + static void write(void* aPtr, T aValue) + { + T tmp = maybeSwap(aValue); + memcpy(aPtr, &tmp, sizeof(T)); + } - Endian() MOZ_DELETE; - Endian(const Endian& other) MOZ_DELETE; - void operator=(const Endian& other) MOZ_DELETE; + Endian() MOZ_DELETE; + Endian(const Endian& aTther) MOZ_DELETE; + void operator=(const Endian& aOther) MOZ_DELETE; }; template class EndianReadWrite : public Endian { - private: - typedef Endian super; - - public: - using super::readUint16; - using super::readUint32; - using super::readUint64; - using super::readInt16; - using super::readInt32; - using super::readInt64; - using super::writeUint16; - using super::writeUint32; - using super::writeUint64; - using super::writeInt16; - using super::writeInt32; - using super::writeInt64; +private: + typedef Endian super; + +public: + using super::readUint16; + using super::readUint32; + using super::readUint64; + using super::readInt16; + using super::readInt32; + using super::readInt64; + using super::writeUint16; + using super::writeUint32; + using super::writeUint64; + using super::writeInt16; + using super::writeInt32; + using super::writeInt64; }; } /* namespace detail */ @@ -598,39 +653,39 @@ typedef BigEndian NetworkEndian; class NativeEndian MOZ_FINAL : public detail::Endian { - private: - typedef detail::Endian super; - - public: - /* - * These functions are intended for cases where you have data in your - * native-endian format and you need the data to appear in the appropriate - * endianness for transmission, serialization, etc. - */ - using super::swapToLittleEndian; - using super::copyAndSwapToLittleEndian; - using super::swapToLittleEndianInPlace; - using super::swapToBigEndian; - using super::copyAndSwapToBigEndian; - using super::swapToBigEndianInPlace; - using super::swapToNetworkOrder; - using super::copyAndSwapToNetworkOrder; - using super::swapToNetworkOrderInPlace; - - /* - * These functions are intended for cases where you have data in the - * given endianness (e.g. reading from disk or a file-format) and you - * need the data to appear in native-endian format for processing. - */ - using super::swapFromLittleEndian; - using super::copyAndSwapFromLittleEndian; - using super::swapFromLittleEndianInPlace; - using super::swapFromBigEndian; - using super::copyAndSwapFromBigEndian; - using super::swapFromBigEndianInPlace; - using super::swapFromNetworkOrder; - using super::copyAndSwapFromNetworkOrder; - using super::swapFromNetworkOrderInPlace; +private: + typedef detail::Endian super; + +public: + /* + * These functions are intended for cases where you have data in your + * native-endian format and you need the data to appear in the appropriate + * endianness for transmission, serialization, etc. + */ + using super::swapToLittleEndian; + using super::copyAndSwapToLittleEndian; + using super::swapToLittleEndianInPlace; + using super::swapToBigEndian; + using super::copyAndSwapToBigEndian; + using super::swapToBigEndianInPlace; + using super::swapToNetworkOrder; + using super::copyAndSwapToNetworkOrder; + using super::swapToNetworkOrderInPlace; + + /* + * These functions are intended for cases where you have data in the + * given endianness (e.g. reading from disk or a file-format) and you + * need the data to appear in native-endian format for processing. + */ + using super::swapFromLittleEndian; + using super::copyAndSwapFromLittleEndian; + using super::swapFromLittleEndianInPlace; + using super::swapFromBigEndian; + using super::copyAndSwapFromBigEndian; + using super::swapFromBigEndianInPlace; + using super::swapFromNetworkOrder; + using super::copyAndSwapFromNetworkOrder; + using super::swapFromNetworkOrderInPlace; }; #undef MOZ_NATIVE_ENDIANNESS diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/EnumSet.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/EnumSet.h index 95c5608cf4..8c78b2b442 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/EnumSet.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/EnumSet.h @@ -10,6 +10,7 @@ #define mozilla_EnumSet_h #include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" #include @@ -23,153 +24,181 @@ namespace mozilla { template class EnumSet { - public: - EnumSet() - : mBitField(0) - { } - - EnumSet(T aEnum) - : mBitField(aEnum) - { } - - EnumSet(T aEnum1, T aEnum2) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2)) - { } - - EnumSet(T aEnum1, T aEnum2, T aEnum3) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2) | - bitFor(aEnum3)) - { } - - EnumSet(T aEnum1, T aEnum2, T aEnum3, T aEnum4) - : mBitField(bitFor(aEnum1) | - bitFor(aEnum2) | - bitFor(aEnum3) | - bitFor(aEnum4)) - { } - - EnumSet(const EnumSet& aEnumSet) - : mBitField(aEnumSet.mBitField) - { } - - /** - * Add an element - */ - void operator+=(T aEnum) { - mBitField |= bitFor(aEnum); - } - - /** - * Add an element - */ - EnumSet operator+(T aEnum) const { - EnumSet result(*this); - result += aEnum; - return result; - } - - /** - * Union - */ - void operator+=(const EnumSet aEnumSet) { - mBitField |= aEnumSet.mBitField; - } - - /** - * Union - */ - EnumSet operator+(const EnumSet aEnumSet) const { - EnumSet result(*this); - result += aEnumSet; - return result; - } - - /** - * Remove an element - */ - void operator-=(T aEnum) { - mBitField &= ~(bitFor(aEnum)); - } - - /** - * Remove an element - */ - EnumSet operator-(T aEnum) const { - EnumSet result(*this); - result -= aEnum; - return result; - } - - /** - * Remove a set of elements - */ - void operator-=(const EnumSet aEnumSet) { - mBitField &= ~(aEnumSet.mBitField); - } - - /** - * Remove a set of elements - */ - EnumSet operator-(const EnumSet aEnumSet) const { - EnumSet result(*this); - result -= aEnumSet; - return result; - } - - /** - * Intersection - */ - void operator&=(const EnumSet aEnumSet) { - mBitField &= aEnumSet.mBitField; - } - - /** - * Intersection - */ - EnumSet operator&(const EnumSet aEnumSet) const { - EnumSet result(*this); - result &= aEnumSet; - return result; - } - - /** - * Equality - */ - - bool operator==(const EnumSet aEnumSet) const { - return mBitField == aEnumSet.mBitField; - } - - /** - * Test is an element is contained in the set - */ - bool contains(T aEnum) const { - return mBitField & bitFor(aEnum); - } - - /** - * Return the number of elements in the set - */ - - uint8_t size() { - uint8_t count = 0; - for (uint32_t bitField = mBitField; bitField; bitField >>= 1) { - if (bitField & 1) - count++; +public: + EnumSet() + : mBitField(0) + { } + + MOZ_IMPLICIT EnumSet(T aEnum) + : mBitField(bitFor(aEnum)) + { } + + EnumSet(T aEnum1, T aEnum2) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3, T aEnum4) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3) | + bitFor(aEnum4)) + { } + + EnumSet(const EnumSet& aEnumSet) + : mBitField(aEnumSet.mBitField) + { } + + /** + * Add an element + */ + void operator+=(T aEnum) + { + mBitField |= bitFor(aEnum); + } + + /** + * Add an element + */ + EnumSet operator+(T aEnum) const + { + EnumSet result(*this); + result += aEnum; + return result; + } + + /** + * Union + */ + void operator+=(const EnumSet aEnumSet) + { + mBitField |= aEnumSet.mBitField; + } + + /** + * Union + */ + EnumSet operator+(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result += aEnumSet; + return result; + } + + /** + * Remove an element + */ + void operator-=(T aEnum) + { + mBitField &= ~(bitFor(aEnum)); + } + + /** + * Remove an element + */ + EnumSet operator-(T aEnum) const + { + EnumSet result(*this); + result -= aEnum; + return result; + } + + /** + * Remove a set of elements + */ + void operator-=(const EnumSet aEnumSet) + { + mBitField &= ~(aEnumSet.mBitField); + } + + /** + * Remove a set of elements + */ + EnumSet operator-(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result -= aEnumSet; + return result; + } + + /** + * Intersection + */ + void operator&=(const EnumSet aEnumSet) + { + mBitField &= aEnumSet.mBitField; + } + + /** + * Intersection + */ + EnumSet operator&(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result &= aEnumSet; + return result; + } + + /** + * Equality + */ + bool operator==(const EnumSet aEnumSet) const + { + return mBitField == aEnumSet.mBitField; + } + + /** + * Test is an element is contained in the set. + */ + bool contains(T aEnum) const + { + return mBitField & bitFor(aEnum); + } + + /** + * Return the number of elements in the set. + */ + uint8_t size() + { + uint8_t count = 0; + for (uint32_t bitField = mBitField; bitField; bitField >>= 1) { + if (bitField & 1) { + count++; } - return count; } - - private: - static uint32_t bitFor(T aEnum) { - uint32_t bitNumber(aEnum); - MOZ_ASSERT(bitNumber < 32); - return 1U << bitNumber; - } - - uint32_t mBitField; + return count; + } + + bool isEmpty() const + { + return mBitField == 0; + } + + uint32_t serialize() const + { + return mBitField; + } + + void deserialize(uint32_t aValue) + { + mBitField = aValue; + } + +private: + static uint32_t bitFor(T aEnum) + { + uint32_t bitNumber = (uint32_t)aEnum; + MOZ_ASSERT(bitNumber < 32); + return 1U << bitNumber; + } + + uint32_t mBitField; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/EnumeratedArray.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/EnumeratedArray.h new file mode 100644 index 0000000000..7e8e89275f --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/EnumeratedArray.h @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* EnumeratedArray is like Array, but indexed by a typed enum. */ + +#ifndef mozilla_EnumeratedArray_h +#define mozilla_EnumeratedArray_h + +#include "mozilla/Array.h" +#include "mozilla/TypedEnum.h" + +namespace mozilla { + +/** + * EnumeratedArray is a fixed-size array container for use when an + * array is indexed by a specific enum class, as currently implemented + * by MOZ_BEGIN_ENUM_CLASS. + * + * This provides type safety by guarding at compile time against accidentally + * indexing such arrays with unrelated values. This also removes the need + * for manual casting when using a typed enum value to index arrays. + * + * Aside from the typing of indices, EnumeratedArray is similar to Array. + * + * Example: + * + * MOZ_BEGIN_ENUM_CLASS(AnimalSpecies) + * Cow, + * Sheep, + * Count + * MOZ_END_ENUM_CLASS(AnimalSpecies) + * + * EnumeratedArray headCount; + * + * headCount[AnimalSpecies::Cow] = 17; + * headCount[AnimalSpecies::Sheep] = 30; + * + */ +template +class EnumeratedArray +{ +public: + static const size_t kSize = size_t(SizeAsEnumValue); + +private: + Array mArray; + +public: + EnumeratedArray() {} + + explicit EnumeratedArray(const EnumeratedArray& aOther) + { + for (size_t i = 0; i < kSize; i++) { + mArray[i] = aOther.mArray[i]; + } + } + + ValueType& operator[](IndexType aIndex) + { + return mArray[size_t(aIndex)]; + } + + const ValueType& operator[](IndexType aIndex) const + { + return mArray[size_t(aIndex)]; + } +}; + +} // namespace mozilla + +#endif // mozilla_EnumeratedArray_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/FloatingPoint.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/FloatingPoint.h index 7d6b28b413..0ed567832b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/FloatingPoint.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/FloatingPoint.h @@ -12,6 +12,7 @@ #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/Casting.h" +#include "mozilla/MathAlgorithms.h" #include "mozilla/Types.h" #include @@ -33,211 +34,274 @@ namespace mozilla { * compiler bustage, particularly PGO-specific bustage. */ -/* - * These implementations all assume |double| is a 64-bit double format number - * type, compatible with the IEEE-754 standard. C/C++ don't require this to be - * the case. But we required this in implementations of these algorithms that - * preceded this header, so we shouldn't break anything if we continue doing so. - */ -static_assert(sizeof(double) == sizeof(uint64_t), "double must be 64 bits"); +struct FloatTypeTraits +{ + typedef uint32_t Bits; -const unsigned DoubleExponentBias = 1023; -const unsigned DoubleExponentShift = 52; + static const unsigned kExponentBias = 127; + static const unsigned kExponentShift = 23; -const uint64_t DoubleSignBit = 0x8000000000000000ULL; -const uint64_t DoubleExponentBits = 0x7ff0000000000000ULL; -const uint64_t DoubleSignificandBits = 0x000fffffffffffffULL; + static const Bits kSignBit = 0x80000000UL; + static const Bits kExponentBits = 0x7F800000UL; + static const Bits kSignificandBits = 0x007FFFFFUL; +}; + +struct DoubleTypeTraits +{ + typedef uint64_t Bits; -static_assert((DoubleSignBit & DoubleExponentBits) == 0, - "sign bit doesn't overlap exponent bits"); -static_assert((DoubleSignBit & DoubleSignificandBits) == 0, - "sign bit doesn't overlap significand bits"); -static_assert((DoubleExponentBits & DoubleSignificandBits) == 0, - "exponent bits don't overlap significand bits"); + static const unsigned kExponentBias = 1023; + static const unsigned kExponentShift = 52; -static_assert((DoubleSignBit | DoubleExponentBits | DoubleSignificandBits) == - ~uint64_t(0), - "all bits accounted for"); + static const Bits kSignBit = 0x8000000000000000ULL; + static const Bits kExponentBits = 0x7ff0000000000000ULL; + static const Bits kSignificandBits = 0x000fffffffffffffULL; +}; + +template struct SelectTrait; +template<> struct SelectTrait : public FloatTypeTraits {}; +template<> struct SelectTrait : public DoubleTypeTraits {}; /* - * Ditto for |float| that must be a 32-bit double format number type, compatible - * with the IEEE-754 standard. + * This struct contains details regarding the encoding of floating-point + * numbers that can be useful for direct bit manipulation. As of now, the + * template parameter has to be float or double. + * + * The nested typedef |Bits| is the unsigned integral type with the same size + * as T: uint32_t for float and uint64_t for double (static assertions + * double-check these assumptions). + * + * kExponentBias is the offset that is subtracted from the exponent when + * computing the value, i.e. one plus the opposite of the mininum possible + * exponent. + * kExponentShift is the shift that one needs to apply to retrieve the + * exponent component of the value. + * + * kSignBit contains a bits mask. Bit-and-ing with this mask will result in + * obtaining the sign bit. + * kExponentBits contains the mask needed for obtaining the exponent bits and + * kSignificandBits contains the mask needed for obtaining the significand + * bits. + * + * Full details of how floating point number formats are encoded are beyond + * the scope of this comment. For more information, see + * http://en.wikipedia.org/wiki/IEEE_floating_point + * http://en.wikipedia.org/wiki/Floating_point#IEEE_754:_floating_point_in_modern_computers */ -static_assert(sizeof(float) == sizeof(uint32_t), "float must be 32bits"); - -const unsigned FloatExponentBias = 127; -const unsigned FloatExponentShift = 23; +template +struct FloatingPoint : public SelectTrait +{ + typedef SelectTrait Base; + typedef typename Base::Bits Bits; -const uint32_t FloatSignBit = 0x80000000UL; -const uint32_t FloatExponentBits = 0x7F800000UL; -const uint32_t FloatSignificandBits = 0x007FFFFFUL; + static_assert((Base::kSignBit & Base::kExponentBits) == 0, + "sign bit shouldn't overlap exponent bits"); + static_assert((Base::kSignBit & Base::kSignificandBits) == 0, + "sign bit shouldn't overlap significand bits"); + static_assert((Base::kExponentBits & Base::kSignificandBits) == 0, + "exponent bits shouldn't overlap significand bits"); -static_assert((FloatSignBit & FloatExponentBits) == 0, - "sign bit doesn't overlap exponent bits"); -static_assert((FloatSignBit & FloatSignificandBits) == 0, - "sign bit doesn't overlap significand bits"); -static_assert((FloatExponentBits & FloatSignificandBits) == 0, - "exponent bits don't overlap significand bits"); + static_assert((Base::kSignBit | Base::kExponentBits | Base::kSignificandBits) == + ~Bits(0), + "all bits accounted for"); -static_assert((FloatSignBit | FloatExponentBits | FloatSignificandBits) == - ~uint32_t(0), - "all bits accounted for"); + /* + * These implementations assume float/double are 32/64-bit single/double + * format number types compatible with the IEEE-754 standard. C++ don't + * require this to be the case. But we required this in implementations of + * these algorithms that preceded this header, so we shouldn't break anything + * if we keep doing so. + */ + static_assert(sizeof(T) == sizeof(Bits), "Bits must be same size as T"); +}; /** Determines whether a double is NaN. */ +template static MOZ_ALWAYS_INLINE bool -IsNaN(double d) +IsNaN(T aValue) { /* - * A double is NaN if all exponent bits are 1 and the significand contains at - * least one non-zero bit. + * A float/double is NaN if all exponent bits are 1 and the significand + * contains at least one non-zero bit. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleExponentBits) == DoubleExponentBits && - (bits & DoubleSignificandBits) != 0; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) == Traits::kExponentBits && + (bits & Traits::kSignificandBits) != 0; } -/** Determines whether a double is +Infinity or -Infinity. */ +/** Determines whether a float/double is +Infinity or -Infinity. */ +template static MOZ_ALWAYS_INLINE bool -IsInfinite(double d) +IsInfinite(T aValue) { /* Infinities have all exponent bits set to 1 and an all-0 significand. */ - uint64_t bits = BitwiseCast(d); - return (bits & ~DoubleSignBit) == DoubleExponentBits; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & ~Traits::kSignBit) == Traits::kExponentBits; } -/** Determines whether a double is not NaN or infinite. */ +/** Determines whether a float/double is not NaN or infinite. */ +template static MOZ_ALWAYS_INLINE bool -IsFinite(double d) +IsFinite(T aValue) { /* - * NaN and Infinities are the only non-finite doubles, and both have all - * exponent bits set to 1. + * NaN and Infinities are the only non-finite floats/doubles, and both have + * all exponent bits set to 1. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleExponentBits) != DoubleExponentBits; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) != Traits::kExponentBits; } /** - * Determines whether a double is negative. It is an error to call this method - * on a double which is NaN. + * Determines whether a float/double is negative. It is an error to call this + * method on a float/double which is NaN. */ +template static MOZ_ALWAYS_INLINE bool -IsNegative(double d) +IsNegative(T aValue) { - MOZ_ASSERT(!IsNaN(d), "NaN does not have a sign"); + MOZ_ASSERT(!IsNaN(aValue), "NaN does not have a sign"); /* The sign bit is set if the double is negative. */ - uint64_t bits = BitwiseCast(d); - return (bits & DoubleSignBit) != 0; + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kSignBit) != 0; } -/** Determines whether a double represents -0. */ +/** Determines whether a float/double represents -0. */ +template static MOZ_ALWAYS_INLINE bool -IsNegativeZero(double d) +IsNegativeZero(T aValue) { - /* Only the sign bit is set if the double is -0. */ - uint64_t bits = BitwiseCast(d); - return bits == DoubleSignBit; + /* Only the sign bit is set if the value is -0. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return bits == Traits::kSignBit; } /** - * Returns the exponent portion of the double. + * Returns the exponent portion of the float/double. * * Zero is not special-cased, so ExponentComponent(0.0) is - * -int_fast16_t(DoubleExponentBias). + * -int_fast16_t(Traits::kExponentBias). */ +template static MOZ_ALWAYS_INLINE int_fast16_t -ExponentComponent(double d) +ExponentComponent(T aValue) { /* - * The exponent component of a double is an unsigned number, biased from its - * actual value. Subtract the bias to retrieve the actual exponent. + * The exponent component of a float/double is an unsigned number, biased + * from its actual value. Subtract the bias to retrieve the actual exponent. */ - uint64_t bits = BitwiseCast(d); - return int_fast16_t((bits & DoubleExponentBits) >> DoubleExponentShift) - - int_fast16_t(DoubleExponentBias); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return int_fast16_t((bits & Traits::kExponentBits) >> Traits::kExponentShift) - + int_fast16_t(Traits::kExponentBias); } /** Returns +Infinity. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T PositiveInfinity() { /* * Positive infinity has all exponent bits set, sign bit set to 0, and no * significand. */ - return BitwiseCast(DoubleExponentBits); + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kExponentBits); } /** Returns -Infinity. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T NegativeInfinity() { /* * Negative infinity has all exponent bits set, sign bit set to 1, and no * significand. */ - return BitwiseCast(DoubleSignBit | DoubleExponentBits); + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kSignBit | Traits::kExponentBits); } + /** Constructs a NaN value with the specified sign bit and significand bits. */ -static MOZ_ALWAYS_INLINE double -SpecificNaN(int signbit, uint64_t significand) +template +static MOZ_ALWAYS_INLINE T +SpecificNaN(int signbit, typename FloatingPoint::Bits significand) { + typedef FloatingPoint Traits; MOZ_ASSERT(signbit == 0 || signbit == 1); - MOZ_ASSERT((significand & ~DoubleSignificandBits) == 0); - MOZ_ASSERT(significand & DoubleSignificandBits); - - double d = BitwiseCast((signbit ? DoubleSignBit : 0) | - DoubleExponentBits | - significand); - MOZ_ASSERT(IsNaN(d)); - return d; + MOZ_ASSERT((significand & ~Traits::kSignificandBits) == 0); + MOZ_ASSERT(significand & Traits::kSignificandBits); + + T t = BitwiseCast((signbit ? Traits::kSignBit : 0) | + Traits::kExponentBits | + significand); + MOZ_ASSERT(IsNaN(t)); + return t; } -/** Computes the smallest non-zero positive double value. */ -static MOZ_ALWAYS_INLINE double -MinDoubleValue() +/** Computes the smallest non-zero positive float/double value. */ +template +static MOZ_ALWAYS_INLINE T +MinNumberValue() { - return BitwiseCast(uint64_t(1)); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + return BitwiseCast(Bits(1)); } /** - * If d is equal to some int32_t value, set *i to that value and return true; - * otherwise return false. + * If aValue is equal to some int32_t value, set *aInt32 to that value and + * return true; otherwise return false. * * Note that negative zero is "equal" to zero here. To test whether a value can - * be losslessly converted to int32_t and back, use DoubleIsInt32 instead. + * be losslessly converted to int32_t and back, use NumberIsInt32 instead. */ +template static MOZ_ALWAYS_INLINE bool -DoubleEqualsInt32(double d, int32_t* i) +NumberEqualsInt32(T aValue, int32_t* aInt32) { /* - * XXX Casting a double that doesn't truncate to int32_t, to int32_t, induces - * undefined behavior. We should definitely fix this (bug 744965), but as - * apparently it "works" in practice, it's not a pressing concern now. + * XXX Casting a floating-point value that doesn't truncate to int32_t, to + * int32_t, induces undefined behavior. We should definitely fix this + * (bug 744965), but as apparently it "works" in practice, it's not a + * pressing concern now. */ - return d == (*i = int32_t(d)); + return aValue == (*aInt32 = int32_t(aValue)); } /** * If d can be converted to int32_t and back to an identical double value, - * set *i to that value and return true; otherwise return false. + * set *aInt32 to that value and return true; otherwise return false. * - * The difference between this and DoubleEqualsInt32 is that this method returns + * The difference between this and NumberEqualsInt32 is that this method returns * false for negative zero. */ +template static MOZ_ALWAYS_INLINE bool -DoubleIsInt32(double d, int32_t* i) +NumberIsInt32(T aValue, int32_t* aInt32) { - return !IsNegativeZero(d) && DoubleEqualsInt32(d, i); + return !IsNegativeZero(aValue) && NumberEqualsInt32(aValue, aInt32); } /** * Computes a NaN value. Do not use this method if you depend upon a particular * NaN value being returned. */ -static MOZ_ALWAYS_INLINE double +template +static MOZ_ALWAYS_INLINE T UnspecifiedNaN() { /* @@ -246,7 +310,8 @@ UnspecifiedNaN() * this value can be represented in a 32-bit signed immediate field, allowing * it to be stored to memory in a single instruction). */ - return SpecificNaN(1, 0xfffffffffffffULL); + typedef FloatingPoint Traits; + return SpecificNaN(1, Traits::kSignificandBits); } /** @@ -254,40 +319,81 @@ UnspecifiedNaN() * any NaN value to any other NaN value. (The normal equality operators equate * -0 with +0, and they equate NaN to no other value.) */ +template static inline bool -DoublesAreIdentical(double d1, double d2) +NumbersAreIdentical(T aValue1, T aValue2) { - if (IsNaN(d1)) - return IsNaN(d2); - return BitwiseCast(d1) == BitwiseCast(d2); + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + if (IsNaN(aValue1)) { + return IsNaN(aValue2); + } + return BitwiseCast(aValue1) == BitwiseCast(aValue2); } -/** Determines whether a float is NaN. */ +namespace detail { + +template +struct FuzzyEqualsEpsilon; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-5 that is exactly representable in a float. + static float value() { return 1.0f / (1 << 17); } +}; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-12 that is exactly representable in a double. + static double value() { return 1.0 / (1LL << 40); } +}; + +} // namespace detail + +/** + * Compare two floating point values for equality, modulo rounding error. That + * is, the two values are considered equal if they are both not NaN and if they + * are less than or equal to aEpsilon apart. The default value of aEpsilon is + * near 1e-5. + * + * For most scenarios you will want to use FuzzyEqualsMultiplicative instead, + * as it is more reasonable over the entire range of floating point numbers. + * This additive version should only be used if you know the range of the + * numbers you are dealing with is bounded and stays around the same order of + * magnitude. + */ +template static MOZ_ALWAYS_INLINE bool -IsFloatNaN(float f) +FuzzyEqualsAdditive(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) { - /* - * A float is NaN if all exponent bits are 1 and the significand contains at - * least one non-zero bit. - */ - uint32_t bits = BitwiseCast(f); - return (bits & FloatExponentBits) == FloatExponentBits && - (bits & FloatSignificandBits) != 0; + static_assert(IsFloatingPoint::value, "floating point type required"); + return Abs(aValue1 - aValue2) <= aEpsilon; } -/** Constructs a NaN value with the specified sign bit and significand bits. */ -static MOZ_ALWAYS_INLINE float -SpecificFloatNaN(int signbit, uint32_t significand) +/** + * Compare two floating point values for equality, allowing for rounding error + * relative to the magnitude of the values. That is, the two values are + * considered equal if they are both not NaN and they are less than or equal to + * some aEpsilon apart, where the aEpsilon is scaled by the smaller of the two + * argument values. + * + * In most cases you will want to use this rather than FuzzyEqualsAdditive, as + * this function effectively masks out differences in the bottom few bits of + * the floating point numbers being compared, regardless of what order of + * magnitude those numbers are at. + */ +template +static MOZ_ALWAYS_INLINE bool +FuzzyEqualsMultiplicative(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) { - MOZ_ASSERT(signbit == 0 || signbit == 1); - MOZ_ASSERT((significand & ~FloatSignificandBits) == 0); - MOZ_ASSERT(significand & FloatSignificandBits); - - float f = BitwiseCast((signbit ? FloatSignBit : 0) | - FloatExponentBits | - significand); - MOZ_ASSERT(IsFloatNaN(f)); - return f; + static_assert(IsFloatingPoint::value, "floating point type required"); + // can't use std::min because of bug 965340 + T smaller = Abs(aValue1) < Abs(aValue2) ? Abs(aValue1) : Abs(aValue2); + return Abs(aValue1 - aValue2) <= aEpsilon * smaller; } /** @@ -300,7 +406,7 @@ SpecificFloatNaN(int signbit, uint32_t significand) */ MOZ_WARN_UNUSED_RESULT extern MFBT_API bool -IsFloat32Representable(double x); +IsFloat32Representable(double aFloat32); } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/GuardObjects.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/GuardObjects.h index aeae7dcbc0..2cd950f314 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/GuardObjects.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/GuardObjects.h @@ -68,48 +68,49 @@ namespace detail { * For more details, and examples of using these macros, see * https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla */ -class MOZ_EXPORT GuardObjectNotifier +class GuardObjectNotifier { - private: - bool* statementDone; +private: + bool* mStatementDone; - public: - GuardObjectNotifier() : statementDone(nullptr) { } +public: + GuardObjectNotifier() : mStatementDone(nullptr) { } - ~GuardObjectNotifier() { - *statementDone = true; - } + ~GuardObjectNotifier() { *mStatementDone = true; } - void setStatementDone(bool* statementIsDone) { - statementDone = statementIsDone; - } + void setStatementDone(bool* aStatementIsDone) + { + mStatementDone = aStatementIsDone; + } }; -class MOZ_EXPORT GuardObjectNotificationReceiver +class GuardObjectNotificationReceiver { - private: - bool statementDone; - - public: - GuardObjectNotificationReceiver() : statementDone(false) { } - - ~GuardObjectNotificationReceiver() { - /* - * Assert that the guard object was not used as a temporary. (Note that - * this assert might also fire if init is not called because the guard - * object's implementation is not using the above macros correctly.) - */ - MOZ_ASSERT(statementDone); - } - - void init(const GuardObjectNotifier& constNotifier) { - /* - * constNotifier is passed as a const reference so that we can pass a - * temporary, but we really intend it as non-const. - */ - GuardObjectNotifier& notifier = const_cast(constNotifier); - notifier.setStatementDone(&statementDone); - } +private: + bool mStatementDone; + +public: + GuardObjectNotificationReceiver() : mStatementDone(false) { } + + ~GuardObjectNotificationReceiver() { + /* + * Assert that the guard object was not used as a temporary. (Note that + * this assert might also fire if init is not called because the guard + * object's implementation is not using the above macros correctly.) + */ + MOZ_ASSERT(mStatementDone); + } + + void init(const GuardObjectNotifier& aConstNotifier) + { + /* + * aConstNotifier is passed as a const reference so that we can pass a + * temporary, but we really intend it as non-const. + */ + GuardObjectNotifier& notifier = + const_cast(aConstNotifier); + notifier.setStatementDone(&mStatementDone); + } }; } /* namespace detail */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/HashFunctions.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/HashFunctions.h index b228955ce5..8b2c172bd1 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/HashFunctions.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/HashFunctions.h @@ -27,16 +27,17 @@ * * class ComplexObject * { - * char* str; - * uint32_t uint1, uint2; - * void (*callbackFn)(); + * char* mStr; + * uint32_t mUint1, mUint2; + * void (*mCallbackFn)(); * - * public: - * uint32_t hash() { - * uint32_t hash = HashString(str); - * hash = AddToHash(hash, uint1, uint2); - * return AddToHash(hash, callbackFn); - * } + * public: + * uint32_t hash() + * { + * uint32_t hash = HashString(mStr); + * hash = AddToHash(hash, mUint1, mUint2); + * return AddToHash(hash, mCallbackFn); + * } * }; * * If you want to hash an nsAString or nsACString, use the HashString functions @@ -59,19 +60,19 @@ namespace mozilla { /** * The golden ratio as a 32-bit fixed-point value. */ -static const uint32_t GoldenRatioU32 = 0x9E3779B9U; +static const uint32_t kGoldenRatioU32 = 0x9E3779B9U; inline uint32_t -RotateBitsLeft32(uint32_t value, uint8_t bits) +RotateBitsLeft32(uint32_t aValue, uint8_t aBits) { - MOZ_ASSERT(bits < 32); - return (value << bits) | (value >> (32 - bits)); + MOZ_ASSERT(aBits < 32); + return (aValue << aBits) | (aValue >> (32 - aBits)); } namespace detail { inline uint32_t -AddU32ToHash(uint32_t hash, uint32_t value) +AddU32ToHash(uint32_t aHash, uint32_t aValue) { /* * This is the meat of all our hash routines. This hash function is not @@ -91,12 +92,12 @@ AddU32ToHash(uint32_t hash, uint32_t value) * preferable so our hash explores the whole universe of possible rotations. * * Finally, we multiply by the golden ratio *after* xor'ing, not before. - * Otherwise, if |hash| is 0 (as it often is for the beginning of a message), - * the expression + * Otherwise, if |aHash| is 0 (as it often is for the beginning of a + * message), the expression * - * (GoldenRatioU32 * RotateBitsLeft(hash, 5)) |xor| value + * (kGoldenRatioU32 * RotateBitsLeft(aHash, 5)) |xor| aValue * - * evaluates to |value|. + * evaluates to |aValue|. * * (Number-theoretic aside: Because any odd number |m| is relatively prime to * our modulus (2^32), the list @@ -112,7 +113,7 @@ AddU32ToHash(uint32_t hash, uint32_t value) * multiplicative effect. Our golden ratio constant has order 2^29, which is * more than enough for our purposes.) */ - return GoldenRatioU32 * (RotateBitsLeft32(hash, 5) ^ value); + return kGoldenRatioU32 * (RotateBitsLeft32(aHash, 5) ^ aValue); } /** @@ -120,29 +121,29 @@ AddU32ToHash(uint32_t hash, uint32_t value) */ template inline uint32_t -AddUintptrToHash(uint32_t hash, uintptr_t value); +AddUintptrToHash(uint32_t aHash, uintptr_t aValue); template<> inline uint32_t -AddUintptrToHash<4>(uint32_t hash, uintptr_t value) +AddUintptrToHash<4>(uint32_t aHash, uintptr_t aValue) { - return AddU32ToHash(hash, static_cast(value)); + return AddU32ToHash(aHash, static_cast(aValue)); } template<> inline uint32_t -AddUintptrToHash<8>(uint32_t hash, uintptr_t value) +AddUintptrToHash<8>(uint32_t aHash, uintptr_t aValue) { /* * The static cast to uint64_t below is necessary because this function * sometimes gets compiled on 32-bit platforms (yes, even though it's a * template and we never call this particular override in a 32-bit build). If - * we do value >> 32 on a 32-bit machine, we're shifting a 32-bit uintptr_t + * we do aValue >> 32 on a 32-bit machine, we're shifting a 32-bit uintptr_t * right 32 bits, and the compiler throws an error. */ - uint32_t v1 = static_cast(value); - uint32_t v2 = static_cast(static_cast(value) >> 32); - return AddU32ToHash(AddU32ToHash(hash, v1), v2); + uint32_t v1 = static_cast(aValue); + uint32_t v2 = static_cast(static_cast(aValue) >> 32); + return AddU32ToHash(AddU32ToHash(aHash, v1), v2); } } /* namespace detail */ @@ -155,71 +156,63 @@ AddUintptrToHash<8>(uint32_t hash, uintptr_t value) * convert to uint32_t, data pointers, and function pointers. */ template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, A a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A aA) { /* * Try to convert |A| to uint32_t implicitly. If this works, great. If not, * we'll error out. */ - return detail::AddU32ToHash(hash, a); + return detail::AddU32ToHash(aHash, aA); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, A* a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A* aA) { /* * You might think this function should just take a void*. But then we'd only * catch data pointers and couldn't handle function pointers. */ - static_assert(sizeof(a) == sizeof(uintptr_t), - "Strange pointer!"); + static_assert(sizeof(aA) == sizeof(uintptr_t), "Strange pointer!"); - return detail::AddUintptrToHash(hash, uintptr_t(a)); + return detail::AddUintptrToHash(aHash, uintptr_t(aA)); } template<> -MOZ_WARN_UNUSED_RESULT -inline uint32_t -AddToHash(uint32_t hash, uintptr_t a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, uintptr_t aA) { - return detail::AddUintptrToHash(hash, a); + return detail::AddUintptrToHash(aHash, aA); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB) { - return AddToHash(AddToHash(hash, a), b); + return AddToHash(AddToHash(aHash, aA), aB); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC) { - return AddToHash(AddToHash(hash, a, b), c); + return AddToHash(AddToHash(aHash, aA, aB), aC); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c, D d) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD) { - return AddToHash(AddToHash(hash, a, b, c), d); + return AddToHash(AddToHash(aHash, aA, aB, aC), aD); } template -MOZ_WARN_UNUSED_RESULT -uint32_t -AddToHash(uint32_t hash, A a, B b, C c, D d, E e) +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD, E aE) { - return AddToHash(AddToHash(hash, a, b, c, d), e); + return AddToHash(AddToHash(aHash, aA, aB, aC, aD), aE); } /** @@ -230,64 +223,61 @@ AddToHash(uint32_t hash, A a, B b, C c, D d, E e) * that x has already been hashed. */ template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA) { - return AddToHash(0, a); + return AddToHash(0, aA); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB) { - return AddToHash(0, a, b); + return AddToHash(0, aA, aB); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC) { - return AddToHash(0, a, b, c); + return AddToHash(0, aA, aB, aC); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c, D d) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD) { - return AddToHash(0, a, b, c, d); + return AddToHash(0, aA, aB, aC, aD); } template -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashGeneric(A a, B b, C c, D d, E e) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD, E aE) { - return AddToHash(0, a, b, c, d, e); + return AddToHash(0, aA, aB, aC, aD, aE); } namespace detail { template uint32_t -HashUntilZero(const T* str) +HashUntilZero(const T* aStr) { uint32_t hash = 0; - for (T c; (c = *str); str++) + for (T c; (c = *aStr); aStr++) { hash = AddToHash(hash, c); + } return hash; } template uint32_t -HashKnownLength(const T* str, size_t length) +HashKnownLength(const T* aStr, size_t aLength) { uint32_t hash = 0; - for (size_t i = 0; i < length; i++) - hash = AddToHash(hash, str[i]); + for (size_t i = 0; i < aLength; i++) { + hash = AddToHash(hash, aStr[i]); + } return hash; } @@ -299,67 +289,66 @@ HashKnownLength(const T* str, size_t length) * If you have the string's length, you might as well call the overload which * includes the length. It may be marginally faster. */ -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } MOZ_WARN_UNUSED_RESULT inline uint32_t -HashString(const uint16_t* str) +HashString(const unsigned char* aStr, size_t aLength) { - return detail::HashUntilZero(str); + return detail::HashKnownLength(aStr, aLength); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const uint16_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr) { - return detail::HashKnownLength(str, length); + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); } #ifdef MOZ_CHAR16_IS_NOT_WCHAR -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char16_t* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const char16_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } #endif /* - * On Windows, wchar_t (PRUnichar) is not the same as uint16_t, even though it's + * On Windows, wchar_t (char16_t) is not the same as uint16_t, even though it's * the same width! */ #ifdef WIN32 -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const wchar_t* str) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr) { - return detail::HashUntilZero(str); + return detail::HashUntilZero(aStr); } -MOZ_WARN_UNUSED_RESULT -inline uint32_t -HashString(const wchar_t* str, size_t length) +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr, size_t aLength) { - return detail::HashKnownLength(str, length); + return detail::HashKnownLength(aStr, aLength); } #endif @@ -369,9 +358,8 @@ HashString(const wchar_t* str, size_t length) * This hash walks word-by-word, rather than byte-by-byte, so you won't get the * same result out of HashBytes as you would out of HashString. */ -MOZ_WARN_UNUSED_RESULT -extern MFBT_API uint32_t -HashBytes(const void* bytes, size_t length); +MOZ_WARN_UNUSED_RESULT extern MFBT_API uint32_t +HashBytes(const void* bytes, size_t aLength); } /* namespace mozilla */ #endif /* __cplusplus */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/IntegerPrintfMacros.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/IntegerPrintfMacros.h index 1ae60d618e..ff2415a86f 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/IntegerPrintfMacros.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/IntegerPrintfMacros.h @@ -1,7 +1,8 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* Implements the C99 interface, minus the SCN* format macros. */ @@ -37,4 +38,25 @@ # include #endif +/* + * Fix up Android's broken [u]intptr_t inttype macros. Android's PRI*PTR + * macros are defined as "ld", but sizeof(long) is 8 and sizeof(intptr_t) + * is 4 on 32-bit Android. TestTypeTraits.cpp asserts that these new macro + * definitions match the actual type sizes seen at compile time. + */ +#if defined(ANDROID) && !defined(__LP64__) +# undef PRIdPTR /* intptr_t */ +# define PRIdPTR "d" /* intptr_t */ +# undef PRIiPTR /* intptr_t */ +# define PRIiPTR "i" /* intptr_t */ +# undef PRIoPTR /* uintptr_t */ +# define PRIoPTR "o" /* uintptr_t */ +# undef PRIuPTR /* uintptr_t */ +# define PRIuPTR "u" /* uintptr_t */ +# undef PRIxPTR /* uintptr_t */ +# define PRIxPTR "x" /* uintptr_t */ +# undef PRIXPTR /* uintptr_t */ +# define PRIXPTR "X" /* uintptr_t */ +#endif + #endif /* mozilla_IntegerPrintfMacros_h_ */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/IntegerTypeTraits.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/IntegerTypeTraits.h new file mode 100644 index 0000000000..9414451f91 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/IntegerTypeTraits.h @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Helpers to manipulate integer types that don't fit in TypeTraits.h */ + +#ifndef mozilla_IntegerTypeTraits_h +#define mozilla_IntegerTypeTraits_h + +#include "mozilla/TypeTraits.h" +#include + +namespace mozilla { + +namespace detail { + +/** + * StdintTypeForSizeAndSignedness returns the stdint integer type + * of given size (can be 1, 2, 4 or 8) and given signedness + * (false means unsigned, true means signed). + */ +template +struct StdintTypeForSizeAndSignedness; + +template<> +struct StdintTypeForSizeAndSignedness<1, true> +{ + typedef int8_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<1, false> +{ + typedef uint8_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<2, true> +{ + typedef int16_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<2, false> +{ + typedef uint16_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<4, true> +{ + typedef int32_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<4, false> +{ + typedef uint32_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<8, true> +{ + typedef int64_t Type; +}; + +template<> +struct StdintTypeForSizeAndSignedness<8, false> +{ + typedef uint64_t Type; +}; + +} // namespace detail + +template +struct UnsignedStdintTypeForSize + : detail::StdintTypeForSizeAndSignedness +{}; + +template +struct PositionOfSignBit +{ + static_assert(IsIntegral::value, + "PositionOfSignBit is only for integral types"); + // 8 here should be CHAR_BIT from limits.h, but the world has moved on. + static const size_t value = 8 * sizeof(IntegerType) - 1; +}; + +/** + * MinValue returns the minimum value of the given integer type as a + * compile-time constant, which std::numeric_limits::min() + * cannot do in c++98. + */ +template +struct MinValue +{ +private: + static_assert(IsIntegral::value, + "MinValue is only for integral types"); + + typedef typename MakeUnsigned::Type UnsignedIntegerType; + static const size_t PosOfSignBit = PositionOfSignBit::value; + +public: + // Bitwise ops may return a larger type, that's why we cast explicitly. + // In C++, left bit shifts on signed values is undefined by the standard + // unless the shifted value is representable. + // Notice that signed-to-unsigned conversions are always well-defined in + // the standard as the value congruent to 2**n, as expected. By contrast, + // unsigned-to-signed is only well-defined if the value is representable. + static const IntegerType value = + IsSigned::value + ? IntegerType(UnsignedIntegerType(1) << PosOfSignBit) + : IntegerType(0); +}; + +/** + * MaxValue returns the maximum value of the given integer type as a + * compile-time constant, which std::numeric_limits::max() + * cannot do in c++98. + */ +template +struct MaxValue +{ + static_assert(IsIntegral::value, + "MaxValue is only for integral types"); + + // Tricksy, but covered by the CheckedInt unit test. + // Relies on the type of MinValue::value + // being IntegerType. + static const IntegerType value = ~MinValue::value; +}; + +} // namespace mozilla + +#endif // mozilla_IntegerTypeTraits_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/LinkedList.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/LinkedList.h index 3aee7cde45..693c019f92 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/LinkedList.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/LinkedList.h @@ -23,32 +23,36 @@ * * class Observer : public LinkedListElement * { - * public: - * void observe(char* topic) { ... } + * public: + * void observe(char* aTopic) { ... } * }; * * class ObserverContainer * { - * private: - * LinkedList list; + * private: + * LinkedList list; * - * public: - * void addObserver(Observer* observer) { - * // Will assert if |observer| is part of another list. - * list.insertBack(observer); - * } + * public: + * void addObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is part of another list. + * list.insertBack(aObserver); + * } * - * void removeObserver(Observer* observer) { - * // Will assert if |observer| is not part of some list. - * observer.remove(); - * // Or, will assert if |observer| is not part of |list| specifically. - * // observer.removeFrom(list); - * } + * void removeObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is not part of some list. + * aObserver.remove(); + * // Or, will assert if |aObserver| is not part of |list| specifically. + * // aObserver.removeFrom(list); + * } * - * void notifyObservers(char* topic) { - * for (Observer* o = list.getFirst(); o != nullptr; o = o->getNext()) - * o->observe(topic); + * void notifyObservers(char* aTopic) + * { + * for (Observer* o = list.getFirst(); o != nullptr; o = o->getNext()) { + * o->observe(aTopic); * } + * } * }; * */ @@ -72,411 +76,407 @@ class LinkedList; template class LinkedListElement { - /* - * It's convenient that we return nullptr when getNext() or getPrevious() - * hits the end of the list, but doing so costs an extra word of storage in - * each linked list node (to keep track of whether |this| is the sentinel - * node) and a branch on this value in getNext/getPrevious. - * - * We could get rid of the extra word of storage by shoving the "is - * sentinel" bit into one of the pointers, although this would, of course, - * have performance implications of its own. - * - * But the goal here isn't to win an award for the fastest or slimmest - * linked list; rather, we want a *convenient* linked list. So we won't - * waste time guessing which micro-optimization strategy is best. - * - * - * Speaking of unnecessary work, it's worth addressing here why we wrote - * mozilla::LinkedList in the first place, instead of using stl::list. - * - * The key difference between mozilla::LinkedList and stl::list is that - * mozilla::LinkedList stores the prev/next pointers in the object itself, - * while stl::list stores the prev/next pointers in a list element which - * itself points to the object being stored. - * - * mozilla::LinkedList's approach makes it harder to store an object in more - * than one list. But the upside is that you can call next() / prev() / - * remove() directly on the object. With stl::list, you'd need to store a - * pointer to its iterator in the object in order to accomplish this. Not - * only would this waste space, but you'd have to remember to update that - * pointer every time you added or removed the object from a list. - * - * In-place, constant-time removal is a killer feature of doubly-linked - * lists, and supporting this painlessly was a key design criterion. - */ - - private: - LinkedListElement* next; - LinkedListElement* prev; - const bool isSentinel; - - public: - LinkedListElement() - : next(MOZ_THIS_IN_INITIALIZER_LIST()), - prev(MOZ_THIS_IN_INITIALIZER_LIST()), - isSentinel(false) - { } - - LinkedListElement(LinkedListElement&& other) - : isSentinel(other.isSentinel) - { - if (!other.isInList()) { - next = this; - prev = this; - return; - } - - MOZ_ASSERT(other.next->prev == &other); - MOZ_ASSERT(other.prev->next == &other); - - /* - * Initialize |this| with |other|'s prev/next pointers, and adjust those - * element to point to this one. - */ - next = other.next; - prev = other.prev; - - next->prev = this; - prev->next = this; - - /* - * Adjust |other| so it doesn't think it's in a list. This makes it - * safely destructable. - */ - other.next = &other; - other.prev = &other; - } - - ~LinkedListElement() { - if (!isSentinel && isInList()) - remove(); - } - - /* - * Get the next element in the list, or nullptr if this is the last element - * in the list. - */ - T* getNext() { - return next->asT(); - } - const T* getNext() const { - return next->asT(); + /* + * It's convenient that we return nullptr when getNext() or getPrevious() + * hits the end of the list, but doing so costs an extra word of storage in + * each linked list node (to keep track of whether |this| is the sentinel + * node) and a branch on this value in getNext/getPrevious. + * + * We could get rid of the extra word of storage by shoving the "is + * sentinel" bit into one of the pointers, although this would, of course, + * have performance implications of its own. + * + * But the goal here isn't to win an award for the fastest or slimmest + * linked list; rather, we want a *convenient* linked list. So we won't + * waste time guessing which micro-optimization strategy is best. + * + * + * Speaking of unnecessary work, it's worth addressing here why we wrote + * mozilla::LinkedList in the first place, instead of using stl::list. + * + * The key difference between mozilla::LinkedList and stl::list is that + * mozilla::LinkedList stores the mPrev/mNext pointers in the object itself, + * while stl::list stores the mPrev/mNext pointers in a list element which + * itself points to the object being stored. + * + * mozilla::LinkedList's approach makes it harder to store an object in more + * than one list. But the upside is that you can call next() / prev() / + * remove() directly on the object. With stl::list, you'd need to store a + * pointer to its iterator in the object in order to accomplish this. Not + * only would this waste space, but you'd have to remember to update that + * pointer every time you added or removed the object from a list. + * + * In-place, constant-time removal is a killer feature of doubly-linked + * lists, and supporting this painlessly was a key design criterion. + */ + +private: + LinkedListElement* mNext; + LinkedListElement* mPrev; + const bool mIsSentinel; + +public: + LinkedListElement() + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(false) + { } + + LinkedListElement(LinkedListElement&& other) + : mIsSentinel(other.mIsSentinel) + { + if (!other.isInList()) { + mNext = this; + mPrev = this; + return; } - /* - * Get the previous element in the list, or nullptr if this is the first - * element in the list. - */ - T* getPrevious() { - return prev->asT(); - } - const T* getPrevious() const { - return prev->asT(); - } + MOZ_ASSERT(other.mNext->mPrev == &other); + MOZ_ASSERT(other.mPrev->mNext == &other); /* - * Insert elem after this element in the list. |this| must be part of a - * linked list when you call setNext(); otherwise, this method will assert. + * Initialize |this| with |other|'s mPrev/mNext pointers, and adjust those + * element to point to this one. */ - void setNext(T* elem) { - MOZ_ASSERT(isInList()); - setNextUnsafe(elem); - } + mNext = other.mNext; + mPrev = other.mPrev; - /* - * Insert elem before this element in the list. |this| must be part of a - * linked list when you call setPrevious(); otherwise, this method will - * assert. - */ - void setPrevious(T* elem) { - MOZ_ASSERT(isInList()); - setPreviousUnsafe(elem); - } + mNext->mPrev = this; + mPrev->mNext = this; /* - * Remove this element from the list which contains it. If this element is - * not currently part of a linked list, this method asserts. + * Adjust |other| so it doesn't think it's in a list. This makes it + * safely destructable. */ - void remove() { - MOZ_ASSERT(isInList()); - - prev->next = next; - next->prev = prev; - next = this; - prev = this; - } + other.mNext = &other; + other.mPrev = &other; + } - /* - * Identical to remove(), but also asserts in debug builds that this element - * is in list. - */ - void removeFrom(const LinkedList& list) { - list.assertContains(asT()); + ~LinkedListElement() + { + if (!mIsSentinel && isInList()) { remove(); } - - /* - * Return true if |this| part is of a linked list, and false otherwise. - */ - bool isInList() const { - MOZ_ASSERT((next == this) == (prev == this)); - return next != this; - } - - private: - friend class LinkedList; - - enum NodeKind { - NODE_KIND_NORMAL, - NODE_KIND_SENTINEL - }; - - LinkedListElement(NodeKind nodeKind) - : next(MOZ_THIS_IN_INITIALIZER_LIST()), - prev(MOZ_THIS_IN_INITIALIZER_LIST()), - isSentinel(nodeKind == NODE_KIND_SENTINEL) - { } - - /* - * Return |this| cast to T* if we're a normal node, or return nullptr if - * we're a sentinel node. - */ - T* asT() { - if (isSentinel) - return nullptr; - - return static_cast(this); - } - const T* asT() const { - if (isSentinel) - return nullptr; - - return static_cast(this); - } - - /* - * Insert elem after this element, but don't check that this element is in - * the list. This is called by LinkedList::insertFront(). - */ - void setNextUnsafe(T* elem) { - LinkedListElement *listElem = static_cast(elem); - MOZ_ASSERT(!listElem->isInList()); - - listElem->next = this->next; - listElem->prev = this; - this->next->prev = listElem; - this->next = listElem; - } - - /* - * Insert elem before this element, but don't check that this element is in - * the list. This is called by LinkedList::insertBack(). - */ - void setPreviousUnsafe(T* elem) { - LinkedListElement* listElem = static_cast*>(elem); - MOZ_ASSERT(!listElem->isInList()); - - listElem->next = this; - listElem->prev = this->prev; - this->prev->next = listElem; - this->prev = listElem; - } - - private: - LinkedListElement& operator=(const LinkedListElement& other) MOZ_DELETE; - LinkedListElement(const LinkedListElement& other) MOZ_DELETE; + } + + /* + * Get the next element in the list, or nullptr if this is the last element + * in the list. + */ + T* getNext() { return mNext->asT(); } + const T* getNext() const { return mNext->asT(); } + + /* + * Get the previous element in the list, or nullptr if this is the first + * element in the list. + */ + T* getPrevious() { return mPrev->asT(); } + const T* getPrevious() const { return mPrev->asT(); } + + /* + * Insert aElem after this element in the list. |this| must be part of a + * linked list when you call setNext(); otherwise, this method will assert. + */ + void setNext(T* aElem) + { + MOZ_ASSERT(isInList()); + setNextUnsafe(aElem); + } + + /* + * Insert aElem before this element in the list. |this| must be part of a + * linked list when you call setPrevious(); otherwise, this method will + * assert. + */ + void setPrevious(T* aElem) + { + MOZ_ASSERT(isInList()); + setPreviousUnsafe(aElem); + } + + /* + * Remove this element from the list which contains it. If this element is + * not currently part of a linked list, this method asserts. + */ + void remove() + { + MOZ_ASSERT(isInList()); + + mPrev->mNext = mNext; + mNext->mPrev = mPrev; + mNext = this; + mPrev = this; + } + + /* + * Identical to remove(), but also asserts in debug builds that this element + * is in aList. + */ + void removeFrom(const LinkedList& aList) + { + aList.assertContains(asT()); + remove(); + } + + /* + * Return true if |this| part is of a linked list, and false otherwise. + */ + bool isInList() const + { + MOZ_ASSERT((mNext == this) == (mPrev == this)); + return mNext != this; + } + +private: + friend class LinkedList; + + enum NodeKind { + NODE_KIND_NORMAL, + NODE_KIND_SENTINEL + }; + + explicit LinkedListElement(NodeKind nodeKind) + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(nodeKind == NODE_KIND_SENTINEL) + { } + + /* + * Return |this| cast to T* if we're a normal node, or return nullptr if + * we're a sentinel node. + */ + T* asT() + { + return mIsSentinel ? nullptr : static_cast(this); + } + const T* asT() const + { + return mIsSentinel ? nullptr : static_cast(this); + } + + /* + * Insert aElem after this element, but don't check that this element is in + * the list. This is called by LinkedList::insertFront(). + */ + void setNextUnsafe(T* aElem) + { + LinkedListElement *listElem = static_cast(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this->mNext; + listElem->mPrev = this; + this->mNext->mPrev = listElem; + this->mNext = listElem; + } + + /* + * Insert aElem before this element, but don't check that this element is in + * the list. This is called by LinkedList::insertBack(). + */ + void setPreviousUnsafe(T* aElem) + { + LinkedListElement* listElem = static_cast*>(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this; + listElem->mPrev = this->mPrev; + this->mPrev->mNext = listElem; + this->mPrev = listElem; + } + +private: + LinkedListElement& operator=(const LinkedListElement& aOther) MOZ_DELETE; + LinkedListElement(const LinkedListElement& aOther) MOZ_DELETE; }; template class LinkedList { - private: - LinkedListElement sentinel; - - public: - LinkedList() : sentinel(LinkedListElement::NODE_KIND_SENTINEL) { } - - LinkedList(LinkedList&& other) - : sentinel(mozilla::Move(other.sentinel)) - { } - - ~LinkedList() { - MOZ_ASSERT(isEmpty()); - } - - /* - * Add elem to the front of the list. - */ - void insertFront(T* elem) { - /* Bypass setNext()'s this->isInList() assertion. */ - sentinel.setNextUnsafe(elem); - } - - /* - * Add elem to the back of the list. - */ - void insertBack(T* elem) { - sentinel.setPreviousUnsafe(elem); - } - - /* - * Get the first element of the list, or nullptr if the list is empty. - */ - T* getFirst() { - return sentinel.getNext(); - } - const T* getFirst() const { - return sentinel.getNext(); +private: + LinkedListElement sentinel; + +public: + LinkedList() : sentinel(LinkedListElement::NODE_KIND_SENTINEL) { } + + LinkedList(LinkedList&& aOther) + : sentinel(mozilla::Move(aOther.sentinel)) + { } + + ~LinkedList() { MOZ_ASSERT(isEmpty()); } + + /* + * Add aElem to the front of the list. + */ + void insertFront(T* aElem) + { + /* Bypass setNext()'s this->isInList() assertion. */ + sentinel.setNextUnsafe(aElem); + } + + /* + * Add aElem to the back of the list. + */ + void insertBack(T* aElem) + { + sentinel.setPreviousUnsafe(aElem); + } + + /* + * Get the first element of the list, or nullptr if the list is empty. + */ + T* getFirst() { return sentinel.getNext(); } + const T* getFirst() const { return sentinel.getNext(); } + + /* + * Get the last element of the list, or nullptr if the list is empty. + */ + T* getLast() { return sentinel.getPrevious(); } + const T* getLast() const { return sentinel.getPrevious(); } + + /* + * Get and remove the first element of the list. If the list is empty, + * return nullptr. + */ + T* popFirst() + { + T* ret = sentinel.getNext(); + if (ret) { + static_cast*>(ret)->remove(); } - - /* - * Get the last element of the list, or nullptr if the list is empty. - */ - T* getLast() { - return sentinel.getPrevious(); - } - const T* getLast() const { - return sentinel.getPrevious(); - } - - /* - * Get and remove the first element of the list. If the list is empty, - * return nullptr. - */ - T* popFirst() { - T* ret = sentinel.getNext(); - if (ret) - static_cast*>(ret)->remove(); - return ret; + return ret; + } + + /* + * Get and remove the last element of the list. If the list is empty, + * return nullptr. + */ + T* popLast() + { + T* ret = sentinel.getPrevious(); + if (ret) { + static_cast*>(ret)->remove(); } - - /* - * Get and remove the last element of the list. If the list is empty, - * return nullptr. - */ - T* popLast() { - T* ret = sentinel.getPrevious(); - if (ret) - static_cast*>(ret)->remove(); - return ret; + return ret; + } + + /* + * Return true if the list is empty, or false otherwise. + */ + bool isEmpty() const + { + return !sentinel.isInList(); + } + + /* + * Remove all the elements from the list. + * + * This runs in time linear to the list's length, because we have to mark + * each element as not in the list. + */ + void clear() + { + while (popFirst()) { + continue; } - - /* - * Return true if the list is empty, or false otherwise. - */ - bool isEmpty() const { - return !sentinel.isInList(); + } + + /* + * Measures the memory consumption of the list excluding |this|. Note that + * it only measures the list elements themselves. If the list elements + * contain pointers to other memory blocks, those blocks must be measured + * separately during a subsequent iteration over the list. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const + { + size_t n = 0; + for (const T* t = getFirst(); t; t = t->getNext()) { + n += aMallocSizeOf(t); } + return n; + } + + /* + * Like sizeOfExcludingThis(), but measures |this| as well. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const + { + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); + } + + /* + * In a debug build, make sure that the list is sane (no cycles, consistent + * mNext/mPrev pointers, only one sentinel). Has no effect in release builds. + */ + void debugAssertIsSane() const + { +#ifdef DEBUG + const LinkedListElement* slow; + const LinkedListElement* fast1; + const LinkedListElement* fast2; /* - * Remove all the elements from the list. - * - * This runs in time linear to the list's length, because we have to mark - * each element as not in the list. + * Check for cycles in the forward singly-linked list using the + * tortoise/hare algorithm. */ - void clear() { - while (popFirst()) - continue; + for (slow = sentinel.mNext, + fast1 = sentinel.mNext->mNext, + fast2 = sentinel.mNext->mNext->mNext; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mNext, fast1 = fast2->mNext, fast2 = fast1->mNext) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); } - /* - * Measures the memory consumption of the list excluding |this|. Note that - * it only measures the list elements themselves. If the list elements - * contain pointers to other memory blocks, those blocks must be measured - * separately during a subsequent iteration over the list. - */ - size_t sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const { - size_t n = 0; - for (const T* t = getFirst(); t; t = t->getNext()) - n += mallocSizeOf(t); - return n; + /* Check for cycles in the backward singly-linked list. */ + for (slow = sentinel.mPrev, + fast1 = sentinel.mPrev->mPrev, + fast2 = sentinel.mPrev->mPrev->mPrev; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mPrev, fast1 = fast2->mPrev, fast2 = fast1->mPrev) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); } /* - * Like sizeOfExcludingThis(), but measures |this| as well. + * Check that |sentinel| is the only node in the list with + * mIsSentinel == true. */ - size_t sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const { - return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + for (const LinkedListElement* elem = sentinel.mNext; + elem != &sentinel; + elem = elem->mNext) { + MOZ_ASSERT(!elem->mIsSentinel); } - /* - * In a debug build, make sure that the list is sane (no cycles, consistent - * next/prev pointers, only one sentinel). Has no effect in release builds. - */ - void debugAssertIsSane() const { -#ifdef DEBUG - const LinkedListElement* slow; - const LinkedListElement* fast1; - const LinkedListElement* fast2; - - /* - * Check for cycles in the forward singly-linked list using the - * tortoise/hare algorithm. - */ - for (slow = sentinel.next, - fast1 = sentinel.next->next, - fast2 = sentinel.next->next->next; - slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; - slow = slow->next, fast1 = fast2->next, fast2 = fast1->next) - { - MOZ_ASSERT(slow != fast1); - MOZ_ASSERT(slow != fast2); - } - - /* Check for cycles in the backward singly-linked list. */ - for (slow = sentinel.prev, - fast1 = sentinel.prev->prev, - fast2 = sentinel.prev->prev->prev; - slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; - slow = slow->prev, fast1 = fast2->prev, fast2 = fast1->prev) - { - MOZ_ASSERT(slow != fast1); - MOZ_ASSERT(slow != fast2); - } - - /* - * Check that |sentinel| is the only node in the list with - * isSentinel == true. - */ - for (const LinkedListElement* elem = sentinel.next; - elem != &sentinel; - elem = elem->next) - { - MOZ_ASSERT(!elem->isSentinel); - } - - /* Check that the next/prev pointers match up. */ - const LinkedListElement* prev = &sentinel; - const LinkedListElement* cur = sentinel.next; - do { - MOZ_ASSERT(cur->prev == prev); - MOZ_ASSERT(prev->next == cur); + /* Check that the mNext/mPrev pointers match up. */ + const LinkedListElement* prev = &sentinel; + const LinkedListElement* cur = sentinel.mNext; + do { + MOZ_ASSERT(cur->mPrev == prev); + MOZ_ASSERT(prev->mNext == cur); - prev = cur; - cur = cur->next; - } while (cur != &sentinel); + prev = cur; + cur = cur->mNext; + } while (cur != &sentinel); #endif /* ifdef DEBUG */ - } + } - private: - friend class LinkedListElement; +private: + friend class LinkedListElement; - void assertContains(const T* t) const { + void assertContains(const T* aValue) const + { #ifdef DEBUG - for (const T* elem = getFirst(); - elem; - elem = elem->getNext()) - { - if (elem == t) - return; + for (const T* elem = getFirst(); elem; elem = elem->getNext()) { + if (elem == aValue) { + return; } - MOZ_CRASH("element wasn't found in this list!"); -#endif } + MOZ_CRASH("element wasn't found in this list!"); +#endif + } - LinkedList& operator=(const LinkedList& other) MOZ_DELETE; - LinkedList(const LinkedList& other) MOZ_DELETE; + LinkedList& operator=(const LinkedList& aOther) MOZ_DELETE; + LinkedList(const LinkedList& aOther) MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MSIntTypes.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MSIntTypes.h index 3dfba55f58..4ce922fbc5 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MSIntTypes.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MSIntTypes.h @@ -1,32 +1,32 @@ // ISO C9x compliant inttypes.h for Microsoft Visual Studio -// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 -// +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// // Copyright (c) 2006 Alexander Chemeris -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: -// +// // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. -// +// // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. -// +// // 3. The name of the author may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// +// /////////////////////////////////////////////////////////////////////////////// #ifndef _MSC_VER // [ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MacroArgs.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MacroArgs.h new file mode 100644 index 0000000000..c8b7338210 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MacroArgs.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements various macros meant to ease the use of variadic macros. + */ + +#ifndef mozilla_MacroArgs_h +#define mozilla_MacroArgs_h + +/* + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) counts the number of variadic + * arguments and prefixes it with |aPrefix|. For example: + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(, foo, 42) expands to 2 + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(A, foo, 42, bar) expands to A3 + * + * You must pass in between 1 and 50 (inclusive) variadic arguments, past + * |aPrefix|. It is not legal to do + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(prefix) + * + * (that is, pass in 0 variadic arguments). To ensure that a compile-time + * error occurs when these constraints are violated, use the + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT macro with the same variaidc arguments + * wherever this macro is used. + * + * Passing (__VA_ARGS__, ) rather than simply calling + * MOZ_MACROARGS_ARG_COUNT_HELPER2(__VA_ARGS__, ) very + * carefully tiptoes around a MSVC bug where it improperly expands __VA_ARGS__ + * as a single token in argument lists. For details, see: + * + * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement + * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 + */ +#define MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) \ + MOZ_MACROARGS_ARG_COUNT_HELPER((__VA_ARGS__, \ + aPrefix##50, aPrefix##49, aPrefix##48, aPrefix##47, aPrefix##46, \ + aPrefix##45, aPrefix##44, aPrefix##43, aPrefix##42, aPrefix##41, \ + aPrefix##40, aPrefix##39, aPrefix##38, aPrefix##37, aPrefix##36, \ + aPrefix##35, aPrefix##34, aPrefix##33, aPrefix##32, aPrefix##31, \ + aPrefix##30, aPrefix##29, aPrefix##28, aPrefix##27, aPrefix##26, \ + aPrefix##25, aPrefix##24, aPrefix##23, aPrefix##22, aPrefix##21, \ + aPrefix##20, aPrefix##19, aPrefix##18, aPrefix##17, aPrefix##16, \ + aPrefix##15, aPrefix##14, aPrefix##13, aPrefix##12, aPrefix##11, \ + aPrefix##10, aPrefix##9, aPrefix##8, aPrefix##7, aPrefix##6, \ + aPrefix##5, aPrefix##4, aPrefix##3, aPrefix##2, aPrefix##1, aPrefix##0)) + +#define MOZ_MACROARGS_ARG_COUNT_HELPER(aArgs) \ + MOZ_MACROARGS_ARG_COUNT_HELPER2 aArgs + +#define MOZ_MACROARGS_ARG_COUNT_HELPER2( \ + a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, \ + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \ + a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \ + a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \ + a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \ + a51, ...) a51 + +/* + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT ensures that a compile-time error occurs + * when the argument count constraints of MOZ_PASTE_PREFIX_AND_ARG_COUNT are + * violated. Use this macro wherever MOZ_PASTE_PREFIX_AND_ARG_COUNT is used + * and pass it the same variadic arguments. + * + * This macro employs a few dirty tricks to function. To detect the zero + * argument case, |(__VA_ARGS__)| is stringified, sizeof-ed, and compared to + * what it should be in the absence of arguments. + * + * Detecting too many arguments is a little trickier. With a valid argument + * count and a prefix of 1, MOZ_PASTE_PREFIX_AND_ARG_COUNT expands to e.g. 14. + * With a prefix of 0.0, it expands to e.g. 0.04. If there are too many + * arguments, it expands to the first argument over the limit. If this + * exceeding argument is a number, the assertion will fail as there is no + * number than can simultaneously be both > 10 and == 0. If the exceeding + * argument is not a number, a compile-time error should still occur due to + * the operations performed on it. + */ +#define MOZ_MACROARGS_STRINGIFY_HELPER(x) #x +#define MOZ_STATIC_ASSERT_VALID_ARG_COUNT(...) \ + static_assert( \ + sizeof(MOZ_MACROARGS_STRINGIFY_HELPER((__VA_ARGS__))) != sizeof("()") && \ + (MOZ_PASTE_PREFIX_AND_ARG_COUNT(1, __VA_ARGS__)) > 10 && \ + (int)(MOZ_PASTE_PREFIX_AND_ARG_COUNT(0.0, __VA_ARGS__)) == 0, \ + "MOZ_STATIC_ASSERT_VALID_ARG_COUNT requires 1 to 50 arguments") /* ; */ + +/* + * MOZ_ARGS_AFTER_N expands to its arguments excluding the first |N| + * arguments. For example: + * + * MOZ_ARGS_AFTER_2(a, b, c, d) expands to: c, d + */ +#define MOZ_ARGS_AFTER_1(a1, ...) __VA_ARGS__ +#define MOZ_ARGS_AFTER_2(a1, a2, ...) __VA_ARGS__ + +/* + * MOZ_ARG_N expands to its |N|th argument. + */ +#define MOZ_ARG_1(a1, ...) a1 +#define MOZ_ARG_2(a1, a2, ...) a2 + +#endif /* mozilla_MacroArgs_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MacroForEach.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MacroForEach.h new file mode 100644 index 0000000000..ae1f4d0e99 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MacroForEach.h @@ -0,0 +1,158 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements a higher-order macro for iteratively calling another macro with + * fixed leading arguments, plus a trailing element picked from a second list + * of arguments. + */ + +#ifndef mozilla_MacroForEach_h +#define mozilla_MacroForEach_h + +#include "mozilla/MacroArgs.h" + +/* + * MOZ_FOR_EACH(aMacro, aFixedArgs, aArgs) expands to N calls to the macro + * |aMacro| where N is equal the number of items in the list |aArgs|. The + * arguments for each |aMacro| call are composed of *all* arguments in the list + * |aFixedArgs| as well as a single argument in the list |aArgs|. For example: + * + * #define MACRO_A(x) x + + * int a = MOZ_FOR_EACH(MACRO_A, (), (1, 2, 3)) 0; + * // Expands to: MACRO_A(1) MACRO_A(2) MACRO_A(3) 0; + * // And further to: 1 + 2 + 3 + 0; + * + * #define MACRO_B(k, x) (k + x) + + * int b = MOZ_FOR_EACH(MACRO_B, (5,), (1, 2)) 0; + * // Expands to: MACRO_B(5, 1) MACRO_B(5, 2) 0; + * + * #define MACRO_C(k1, k2, x) (k1 + k2 + x) + + * int c = MOZ_FOR_EACH(MACRO_C, (5, 8,), (1, 2)) 0; + * // Expands to: MACRO_B(5, 8, 1) MACRO_B(5, 8, 2) 0; + * + * If the |aFixedArgs| list is not empty, a trailing comma must be included. + * + * The |aArgs| list must be not be empty and may be up to 50 items long. Use + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT to ensure that violating this constraint + * results in a compile-time error. + */ +#define MOZ_FOR_EACH_EXPAND_HELPER(...) __VA_ARGS__ +#define MOZ_FOR_EACH_GLUE(a, b) a b +#define MOZ_FOR_EACH(aMacro, aFixedArgs, aArgs) \ + MOZ_FOR_EACH_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_FOR_EACH_, \ + MOZ_FOR_EACH_EXPAND_HELPER aArgs), \ + (aMacro, aFixedArgs, aArgs)) + +#define MOZ_FOR_EACH_HELPER_GLUE(a, b) a b +#define MOZ_FOR_EACH_HELPER(aMacro, aFixedArgs, aArgs) \ + MOZ_FOR_EACH_HELPER_GLUE( \ + aMacro, \ + (MOZ_FOR_EACH_EXPAND_HELPER aFixedArgs MOZ_ARG_1 aArgs)) + +#define MOZ_FOR_EACH_1(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) +#define MOZ_FOR_EACH_2(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_1(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_3(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_2(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_4(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_3(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_5(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_4(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_6(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_5(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_7(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_6(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_8(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_7(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_9(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_8(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_10(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_9(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_11(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_10(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_12(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_11(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_13(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_12(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_14(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_13(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_15(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_14(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_16(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_15(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_17(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_16(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_18(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_17(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_19(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_18(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_20(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_19(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_21(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_20(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_22(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_21(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_23(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_22(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_24(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_23(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_25(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_24(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_26(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_25(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_27(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_26(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_28(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_27(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_29(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_28(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_30(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_29(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_31(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_30(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_32(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_31(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_33(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_32(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_34(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_33(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_35(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_34(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_36(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_35(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_37(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_36(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_38(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_37(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_39(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_38(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_40(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_39(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_41(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_40(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_42(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_41(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_43(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_42(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_44(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_43(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_45(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_44(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_46(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_45(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_47(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_46(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_48(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_47(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_49(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_48(m, fa, (MOZ_ARGS_AFTER_1 a)) +#define MOZ_FOR_EACH_50(m, fa, a) \ + MOZ_FOR_EACH_HELPER(m, fa, a) MOZ_FOR_EACH_49(m, fa, (MOZ_ARGS_AFTER_1 a)) + +#endif /* mozilla_MacroForEach_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MathAlgorithms.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MathAlgorithms.h index 7b98c7fc19..cd71d19770 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MathAlgorithms.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MathAlgorithms.h @@ -21,31 +21,31 @@ namespace mozilla { // Greatest Common Divisor template MOZ_ALWAYS_INLINE IntegerType -EuclidGCD(IntegerType a, IntegerType b) +EuclidGCD(IntegerType aA, IntegerType aB) { // Euclid's algorithm; O(N) in the worst case. (There are better // ways, but we don't need them for the current use of this algo.) - MOZ_ASSERT(a > 0); - MOZ_ASSERT(b > 0); + MOZ_ASSERT(aA > IntegerType(0)); + MOZ_ASSERT(aB > IntegerType(0)); - while (a != b) { - if (a > b) { - a = a - b; + while (aA != aB) { + if (aA > aB) { + aA = aA - aB; } else { - b = b - a; + aB = aB - aA; } } - return a; + return aA; } // Least Common Multiple template MOZ_ALWAYS_INLINE IntegerType -EuclidLCM(IntegerType a, IntegerType b) +EuclidLCM(IntegerType aA, IntegerType aB) { // Divide first to reduce overflow risk. - return (a / EuclidGCD(a, b)) * b; + return (aA / EuclidGCD(aA, aB)) * aB; } namespace detail { @@ -68,7 +68,7 @@ template<> struct AllowDeprecatedAbs : TrueType {}; // to Abs below, and it will be removed when all callers have been changed. template inline typename mozilla::EnableIf::value, T>::Type -DeprecatedAbs(const T t) +DeprecatedAbs(const T aValue) { // The absolute value of the smallest possible value of a signed-integer type // won't fit in that type (on twos-complement systems -- and we're blithely @@ -79,10 +79,10 @@ DeprecatedAbs(const T t) // value in the range [-maxvalue, 0]), then negating (giving a value in the // range [0, maxvalue]), doesn't produce maxvalue (because in twos-complement, // (minvalue + 1) == -maxvalue). - MOZ_ASSERT(t >= 0 || - -(t + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1), + MOZ_ASSERT(aValue >= 0 || + -(aValue + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1), "You can't negate the smallest possible negative integer!"); - return t >= 0 ? t : -t; + return aValue >= 0 ? aValue : -aValue; } namespace detail { @@ -102,7 +102,8 @@ template<> struct AbsReturnTypeFixed { typedef uint64_t Type; }; template struct AbsReturnType : AbsReturnTypeFixed {}; -template<> struct AbsReturnType : EnableIf {}; +template<> struct AbsReturnType : + EnableIf {}; template<> struct AbsReturnType { typedef unsigned char Type; }; template<> struct AbsReturnType { typedef unsigned short Type; }; template<> struct AbsReturnType { typedef unsigned int Type; }; @@ -116,50 +117,46 @@ template<> struct AbsReturnType { typedef long double Type; }; template inline typename detail::AbsReturnType::Type -Abs(const T t) +Abs(const T aValue) { typedef typename detail::AbsReturnType::Type ReturnType; - return t >= 0 ? ReturnType(t) : ~ReturnType(t) + 1; + return aValue >= 0 ? ReturnType(aValue) : ~ReturnType(aValue) + 1; } template<> inline float -Abs(const float f) +Abs(const float aFloat) { - return std::fabs(f); + return std::fabs(aFloat); } template<> inline double -Abs(const double d) +Abs(const double aDouble) { - return std::fabs(d); + return std::fabs(aDouble); } template<> inline long double -Abs(const long double d) +Abs(const long double aLongDouble) { - return std::fabs(d); + return std::fabs(aLongDouble); } } // namespace mozilla -#if defined(_WIN32) && (_MSC_VER >= 1300) && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) +#if defined(_WIN32) && (_MSC_VER >= 1300) && \ + (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) # define MOZ_BITSCAN_WINDOWS - extern "C" { - unsigned char _BitScanForward(unsigned long* Index, unsigned long mask); - unsigned char _BitScanReverse(unsigned long* Index, unsigned long mask); +# include # pragma intrinsic(_BitScanForward, _BitScanReverse) # if defined(_M_AMD64) || defined(_M_X64) # define MOZ_BITSCAN_WINDOWS64 - unsigned char _BitScanForward64(unsigned long* index, unsigned __int64 mask); - unsigned char _BitScanReverse64(unsigned long* index, unsigned __int64 mask); # pragma intrinsic(_BitScanForward64, _BitScanReverse64) # endif - } // extern "C" #endif @@ -169,62 +166,68 @@ namespace detail { #if defined(MOZ_BITSCAN_WINDOWS) - inline uint_fast8_t - CountLeadingZeroes32(uint32_t u) - { - unsigned long index; - _BitScanReverse(&index, static_cast(u)); - return uint_fast8_t(31 - index); - } +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanReverse(&index, static_cast(aValue)); + return uint_fast8_t(31 - index); +} - inline uint_fast8_t - CountTrailingZeroes32(uint32_t u) - { - unsigned long index; - _BitScanForward(&index, static_cast(u)); - return uint_fast8_t(index); - } +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanForward(&index, static_cast(aValue)); + return uint_fast8_t(index); +} - inline uint_fast8_t - CountPopulation32(uint32_t u) - { - uint32_t sum2 = (u & 0x55555555) + ((u & 0xaaaaaaaa) >> 1); - uint32_t sum4 = (sum2 & 0x33333333) + ((sum2 & 0xcccccccc) >> 2); - uint32_t sum8 = (sum4 & 0x0f0f0f0f) + ((sum4 & 0xf0f0f0f0) >> 4); - uint32_t sum16 = (sum8 & 0x00ff00ff) + ((sum8 & 0xff00ff00) >> 8); - return sum16; - } +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + uint32_t x = aValue - ((aValue >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + return (((x + (x >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; +} +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return uint_fast8_t(CountPopulation32(aValue & 0xffffffff) + + CountPopulation32(aValue >> 32)); +} - inline uint_fast8_t - CountLeadingZeroes64(uint64_t u) - { -# if defined(MOZ_BITSCAN_WINDOWS64) - unsigned long index; - _BitScanReverse64(&index, static_cast(u)); - return uint_fast8_t(63 - index); -# else - uint32_t hi = uint32_t(u >> 32); - if (hi != 0) - return CountLeadingZeroes32(hi); - return 32 + CountLeadingZeroes32(uint32_t(u)); -# endif +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanReverse64(&index, static_cast(aValue)); + return uint_fast8_t(63 - index); +#else + uint32_t hi = uint32_t(aValue >> 32); + if (hi != 0) { + return CountLeadingZeroes32(hi); } + return 32u + CountLeadingZeroes32(uint32_t(aValue)); +#endif +} - inline uint_fast8_t - CountTrailingZeroes64(uint64_t u) - { -# if defined(MOZ_BITSCAN_WINDOWS64) - unsigned long index; - _BitScanForward64(&index, static_cast(u)); - return uint_fast8_t(index); -# else - uint32_t lo = uint32_t(u); - if (lo != 0) - return CountTrailingZeroes32(lo); - return 32 + CountTrailingZeroes32(uint32_t(u >> 32)); -# endif +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanForward64(&index, static_cast(aValue)); + return uint_fast8_t(index); +#else + uint32_t lo = uint32_t(aValue); + if (lo != 0) { + return CountTrailingZeroes32(lo); } + return 32u + CountTrailingZeroes32(uint32_t(aValue >> 32)); +#endif +} # ifdef MOZ_HAVE_BITSCAN64 # undef MOZ_HAVE_BITSCAN64 @@ -240,52 +243,59 @@ namespace detail { // gcc has had __builtin_clz and friends since 3.4: no need to check. # endif - inline uint_fast8_t - CountLeadingZeroes32(uint32_t u) - { - return __builtin_clz(u); - } +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + return __builtin_clz(aValue); +} - inline uint_fast8_t - CountTrailingZeroes32(uint32_t u) - { - return __builtin_ctz(u); - } +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + return __builtin_ctz(aValue); +} - inline uint_fast8_t - CountPopulation32(uint32_t u) - { - return __builtin_popcount(u); - } +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + return __builtin_popcount(aValue); +} - inline uint_fast8_t - CountLeadingZeroes64(uint64_t u) - { - return __builtin_clzll(u); - } +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return __builtin_popcountll(aValue); +} - inline uint_fast8_t - CountTrailingZeroes64(uint64_t u) - { - return __builtin_ctzll(u); - } +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ + return __builtin_clzll(aValue); +} + +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ + return __builtin_ctzll(aValue); +} #else # error "Implement these!" - inline uint_fast8_t CountLeadingZeroes32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountTrailingZeroes32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountPopulation32(uint32_t u) MOZ_DELETE; - inline uint_fast8_t CountLeadingZeroes64(uint64_t u) MOZ_DELETE; - inline uint_fast8_t CountTrailingZeroes64(uint64_t u) MOZ_DELETE; +inline uint_fast8_t CountLeadingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountLeadingZeroes64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes64(uint64_t aValue) MOZ_DELETE; #endif } // namespace detail /** - * Compute the number of high-order zero bits in the NON-ZERO number |u|. That - * is, looking at the bitwise representation of the number, with the highest- - * valued bits at the start, return the number of zeroes before the first one - * is observed. + * Compute the number of high-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * highest- valued bits at the start, return the number of zeroes before the + * first one is observed. * * CountLeadingZeroes32(0xF0FF1000) is 0; * CountLeadingZeroes32(0x7F8F0001) is 1; @@ -293,17 +303,17 @@ namespace detail { * CountLeadingZeroes32(0x1FF50010) is 3; and so on. */ inline uint_fast8_t -CountLeadingZeroes32(uint32_t u) +CountLeadingZeroes32(uint32_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountLeadingZeroes32(u); + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes32(aValue); } /** - * Compute the number of low-order zero bits in the NON-ZERO number |u|. That - * is, looking at the bitwise representation of the number, with the lowest- - * valued bits at the start, return the number of zeroes before the first one - * is observed. + * Compute the number of low-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * lowest- valued bits at the start, return the number of zeroes before the + * first one is observed. * * CountTrailingZeroes32(0x0100FFFF) is 0; * CountTrailingZeroes32(0x7000FFFE) is 1; @@ -311,35 +321,42 @@ CountLeadingZeroes32(uint32_t u) * CountTrailingZeroes32(0x0080FFF8) is 3; and so on. */ inline uint_fast8_t -CountTrailingZeroes32(uint32_t u) +CountTrailingZeroes32(uint32_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountTrailingZeroes32(u); + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes32(aValue); } /** - * Compute the number of one bits in the number |u|, + * Compute the number of one bits in the number |aValue|, */ inline uint_fast8_t -CountPopulation32(uint32_t u) +CountPopulation32(uint32_t aValue) +{ + return detail::CountPopulation32(aValue); +} + +/** Analogous to CoutPopulation32, but for 64-bit numbers */ +inline uint_fast8_t +CountPopulation64(uint64_t aValue) { - return detail::CountPopulation32(u); + return detail::CountPopulation64(aValue); } /** Analogous to CountLeadingZeroes32, but for 64-bit numbers. */ inline uint_fast8_t -CountLeadingZeroes64(uint64_t u) +CountLeadingZeroes64(uint64_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountLeadingZeroes64(u); + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes64(aValue); } /** Analogous to CountTrailingZeroes32, but for 64-bit numbers. */ inline uint_fast8_t -CountTrailingZeroes64(uint64_t u) +CountTrailingZeroes64(uint64_t aValue) { - MOZ_ASSERT(u != 0); - return detail::CountTrailingZeroes64(u); + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes64(aValue); } namespace detail { @@ -350,27 +367,29 @@ class CeilingLog2; template class CeilingLog2 { - public: - static uint_fast8_t compute(const T t) { - // Check for <= 1 to avoid the == 0 undefined case. - return t <= 1 ? 0 : 32 - CountLeadingZeroes32(t - 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0u : 32u - CountLeadingZeroes32(aValue - 1); + } }; template class CeilingLog2 { - public: - static uint_fast8_t compute(const T t) { - // Check for <= 1 to avoid the == 0 undefined case. - return t <= 1 ? 0 : 64 - CountLeadingZeroes64(t - 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0 : 64 - CountLeadingZeroes64(aValue - 1); + } }; } // namespace detail /** - * Compute the log of the least power of 2 greater than or equal to |t|. + * Compute the log of the least power of 2 greater than or equal to |aValue|. * * CeilingLog2(0..1) is 0; * CeilingLog2(2) is 1; @@ -380,16 +399,16 @@ class CeilingLog2 */ template inline uint_fast8_t -CeilingLog2(const T t) +CeilingLog2(const T aValue) { - return detail::CeilingLog2::compute(t); + return detail::CeilingLog2::compute(aValue); } /** A CeilingLog2 variant that accepts only size_t. */ inline uint_fast8_t -CeilingLog2Size(size_t n) +CeilingLog2Size(size_t aValue) { - return CeilingLog2(n); + return CeilingLog2(aValue); } namespace detail { @@ -400,25 +419,27 @@ class FloorLog2; template class FloorLog2 { - public: - static uint_fast8_t compute(const T t) { - return 31 - CountLeadingZeroes32(t | 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + return 31u - CountLeadingZeroes32(aValue | 1); + } }; template class FloorLog2 { - public: - static uint_fast8_t compute(const T t) { - return 63 - CountLeadingZeroes64(t | 1); - } +public: + static uint_fast8_t compute(const T aValue) + { + return 63u - CountLeadingZeroes64(aValue | 1); + } }; } // namespace detail /** - * Compute the log of the greatest power of 2 less than or equal to |t|. + * Compute the log of the greatest power of 2 less than or equal to |aValue|. * * FloorLog2(0..1) is 0; * FloorLog2(2..3) is 1; @@ -427,16 +448,16 @@ class FloorLog2 */ template inline uint_fast8_t -FloorLog2(const T t) +FloorLog2(const T aValue) { - return detail::FloorLog2::compute(t); + return detail::FloorLog2::compute(aValue); } /** A FloorLog2 variant that accepts only size_t. */ inline uint_fast8_t -FloorLog2Size(size_t n) +FloorLog2Size(size_t aValue) { - return FloorLog2(n); + return FloorLog2(aValue); } /* @@ -444,11 +465,11 @@ FloorLog2Size(size_t n) * be so great that the computed value would overflow |size_t|. */ inline size_t -RoundUpPow2(size_t x) +RoundUpPow2(size_t aValue) { - MOZ_ASSERT(x <= (size_t(1) << (sizeof(size_t) * CHAR_BIT - 1)), + MOZ_ASSERT(aValue <= (size_t(1) << (sizeof(size_t) * CHAR_BIT - 1)), "can't round up -- will overflow!"); - return size_t(1) << CeilingLog2(x); + return size_t(1) << CeilingLog2(aValue); } /** @@ -456,11 +477,11 @@ RoundUpPow2(size_t x) */ template inline T -RotateLeft(const T t, uint_fast8_t shift) +RotateLeft(const T aValue, uint_fast8_t aShift) { - MOZ_ASSERT(shift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); static_assert(IsUnsigned::value, "Rotates require unsigned values"); - return (t << shift) | (t >> (sizeof(T) * CHAR_BIT - shift)); + return (aValue << aShift) | (aValue >> (sizeof(T) * CHAR_BIT - aShift)); } /** @@ -468,11 +489,11 @@ RotateLeft(const T t, uint_fast8_t shift) */ template inline T -RotateRight(const T t, uint_fast8_t shift) +RotateRight(const T aValue, uint_fast8_t aShift) { - MOZ_ASSERT(shift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); static_assert(IsUnsigned::value, "Rotates require unsigned values"); - return (t >> shift) | (t << (sizeof(T) * CHAR_BIT - shift)); + return (aValue >> aShift) | (aValue << (sizeof(T) * CHAR_BIT - aShift)); } } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Maybe.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Maybe.h index 25683a28ab..4ba88f6771 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Maybe.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Maybe.h @@ -31,131 +31,150 @@ namespace mozilla { template class Maybe { - AlignedStorage2 storage; - bool constructed; - - T& asT() { return *storage.addr(); } - - public: - Maybe() { constructed = false; } - ~Maybe() { if (constructed) asT().~T(); } - - bool empty() const { return !constructed; } - - void construct() { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(); - constructed = true; - } - - template - void construct(const T1& t1) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8, const T9& t9) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8, t9); - constructed = true; - } - - template - void construct(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, - const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); - constructed = true; - } - - T* addr() { - MOZ_ASSERT(constructed); - return &asT(); - } - - T& ref() { - MOZ_ASSERT(constructed); - return asT(); - } - - const T& ref() const { - MOZ_ASSERT(constructed); - return const_cast(this)->asT(); - } - - void destroy() { - ref().~T(); - constructed = false; - } - - void destroyIfConstructed() { - if (!empty()) - destroy(); - } - - private: - Maybe(const Maybe& other) MOZ_DELETE; - const Maybe& operator=(const Maybe& other) MOZ_DELETE; + AlignedStorage2 storage; + bool constructed; + + T& asT() { return *storage.addr(); } + +public: + Maybe() { constructed = false; } + ~Maybe() { if (constructed) { asT().~T(); } } + + bool empty() const { return !constructed; } + + void construct() + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(); + constructed = true; + } + + template + void construct(const T1& aT1) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9, const T10& aT10) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9, aT10); + constructed = true; + } + + T* addr() + { + MOZ_ASSERT(constructed); + return &asT(); + } + + T& ref() + { + MOZ_ASSERT(constructed); + return asT(); + } + + const T& ref() const + { + MOZ_ASSERT(constructed); + return const_cast(this)->asT(); + } + + void destroy() + { + ref().~T(); + constructed = false; + } + + void destroyIfConstructed() + { + if (!empty()) { + destroy(); + } + } + +private: + Maybe(const Maybe& aOther) MOZ_DELETE; + const Maybe& operator=(const Maybe& aOther) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MaybeOneOf.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MaybeOneOf.h new file mode 100644 index 0000000000..1c58f88253 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MaybeOneOf.h @@ -0,0 +1,144 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_MaybeOneOf_h +#define mozilla_MaybeOneOf_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" +#include "mozilla/Move.h" +#include "mozilla/TemplateLib.h" + +#include // For placement new + +namespace mozilla { + +/* + * MaybeOneOf is like Maybe, but it supports constructing either T1 + * or T2. When a MaybeOneOf is constructed, it is |empty()|, i.e., + * no value has been constructed and no destructor will be called when the + * MaybeOneOf is destroyed. Upon calling |construct()| or + * |construct()|, a T1 or T2 object will be constructed with the given + * arguments and that object will be destroyed when the owning MaybeOneOf is + * destroyed. + */ +template +class MaybeOneOf +{ + AlignedStorage::value> storage; + + enum State { None, SomeT1, SomeT2 } state; + template struct Type2State {}; + + template + T& as() + { + MOZ_ASSERT(state == Type2State::result); + return *(T*)storage.addr(); + } + + template + const T& as() const + { + MOZ_ASSERT(state == Type2State::result); + return *(T*)storage.addr(); + } + +public: + MaybeOneOf() : state(None) {} + ~MaybeOneOf() { destroyIfConstructed(); } + + bool empty() const { return state == None; } + + template + bool constructed() const { return state == Type2State::result; } + + template + void construct() + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(); + } + + template + void construct(U&& aU) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(Move(aU)); + } + + template + void construct(const U1& aU1) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(aU1); + } + + template + void construct(const U1& aU1, const U2& aU2) + { + MOZ_ASSERT(state == None); + state = Type2State::result; + ::new (storage.addr()) T(aU1, aU2); + } + + template + T& ref() + { + return as(); + } + + template + const T& ref() const + { + return as(); + } + + void destroy() + { + MOZ_ASSERT(state == SomeT1 || state == SomeT2); + if (state == SomeT1) { + as().~T1(); + } else if (state == SomeT2) { + as().~T2(); + } + state = None; + } + + void destroyIfConstructed() + { + if (!empty()) { + destroy(); + } + } + +private: + MaybeOneOf(const MaybeOneOf& aOther) MOZ_DELETE; + const MaybeOneOf& operator=(const MaybeOneOf& aOther) MOZ_DELETE; +}; + +template +template +struct MaybeOneOf::Type2State +{ + typedef MaybeOneOf Enclosing; + static const typename Enclosing::State result = Enclosing::SomeT1; +}; + +template +template +struct MaybeOneOf::Type2State +{ + typedef MaybeOneOf Enclosing; + static const typename Enclosing::State result = Enclosing::SomeT2; +}; + +} // namespace mozilla + +#endif /* mozilla_MaybeOneOf_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MemoryChecking.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MemoryChecking.h index 2130990c6b..0642d758c0 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MemoryChecking.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/MemoryChecking.h @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* - * Provides a common interface to the ASan (AddressSanitizer) and Valgrind + * Provides a common interface to the ASan (AddressSanitizer) and Valgrind * functions used to mark memory in certain ways. In detail, the following * three macros are provided: * @@ -34,14 +34,14 @@ #if defined(MOZ_ASAN) #include +#include "mozilla/Types.h" + extern "C" { - /* These definitions are usually provided through the - * sanitizer/asan_interface.h header installed by ASan. - */ - void __asan_poison_memory_region(void const volatile *addr, size_t size) - __attribute__((visibility("default"))); - void __asan_unpoison_memory_region(void const volatile *addr, size_t size) - __attribute__((visibility("default"))); +/* These definitions are usually provided through the + * sanitizer/asan_interface.h header installed by ASan. + */ +void MOZ_EXPORT __asan_poison_memory_region(void const volatile *addr, size_t size); +void MOZ_EXPORT __asan_unpoison_memory_region(void const volatile *addr, size_t size); #define MOZ_MAKE_MEM_NOACCESS(addr, size) \ __asan_poison_memory_region((addr), (size)) @@ -63,9 +63,9 @@ extern "C" { VALGRIND_MAKE_MEM_DEFINED((addr), (size)) #else -#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while(0) -#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while(0) -#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while(0) +#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while (0) #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Move.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Move.h index f7d39ffa9b..08ae86fa57 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Move.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Move.h @@ -105,7 +105,7 @@ namespace mozilla { * * c2 = Move(c1); * - * This destroys c1, moves c1's value to c2, and leaves c1 in an undefined but + * This destroys c2, moves c1's value to c2, and leaves c1 in an undefined but * destructible state. * * As we say, a move must leave the original in a "destructible" state. The @@ -132,7 +132,7 @@ namespace mozilla { * * To avoid this, C++11 has tweaks to make it possible to write what you mean. * The four constructor overloads above can be written as one constructor - * template like so: + * template like so[0]: * * template * C::C(XArg&& x, YArg&& y) : x(Forward(x)), y(Forward(y)) { } @@ -144,8 +144,8 @@ namespace mozilla { * - First, when a function template takes an argument that is an rvalue * reference to a template argument (like 'XArg&& x' and 'YArg&& y' above), * then when the argument is applied to an lvalue, the template argument - * resolves to 'T &'; and when it is applied to an rvalue, the template - * argument resolves to 'T &&'. Thus, in a call to C::C like: + * resolves to 'T&'; and when it is applied to an rvalue, the template + * argument resolves to 'T&&'. Thus, in a call to C::C like: * * X foo(int); * Y yy; @@ -180,6 +180,28 @@ namespace mozilla { * 'std::forward', which are just like our 'Move' and 'Forward'; but those * definitions aren't available in that header on all our platforms, so we * define them ourselves here.) + * + * 0. This pattern is known as "perfect forwarding". Interestingly, it is not + * actually perfect, and it can't forward all possible argument expressions! + * There are two issues: one that's a C++11 issue, and one that's a legacy + * compiler issue. + * + * The C++11 issue is that you can't form a reference to a bit-field. As a + * workaround, assign the bit-field to a local variable and use that: + * + * // C is as above + * struct S { int x : 1; } s; + * C(s.x, 0); // BAD: s.x is a reference to a bit-field, can't form those + * int tmp = s.x; + * C(tmp, 0); // OK: tmp not a bit-field + * + * The legacy issue is that when we don't have true nullptr and must emulate + * it (gcc 4.4/4.5), forwarding |nullptr| results in an |int| or |long| + * forwarded reference. But such a reference, even if its value is a null + * pointer constant expression, is not itself a null pointer constant + * expression. This causes -Werror=conversion-null errors and pointer-to- + * integer comparison errors. Until we always have true nullptr, users of + * forwarding methods must not pass |nullptr| to them. */ /** @@ -188,9 +210,9 @@ namespace mozilla { */ template inline typename RemoveReference::Type&& -Move(T&& a) +Move(T&& aX) { - return static_cast::Type&&>(a); + return static_cast::Type&&>(aX); } /** @@ -199,28 +221,28 @@ Move(T&& a) */ template inline T&& -Forward(typename RemoveReference::Type& a) +Forward(typename RemoveReference::Type& aX) { - return static_cast(a); + return static_cast(aX); } template inline T&& -Forward(typename RemoveReference::Type&& t) +Forward(typename RemoveReference::Type&& aX) { static_assert(!IsLvalueReference::value, "misuse of Forward detected! try the other overload"); - return static_cast(t); + return static_cast(aX); } -/** Swap |t| and |u| using move-construction if possible. */ +/** Swap |aX| and |aY| using move-construction if possible. */ template inline void -Swap(T& t, T& u) +Swap(T& aX, T& aY) { - T tmp(Move(t)); - t = Move(u); - u = Move(tmp); + T tmp(Move(aX)); + aX = Move(aY); + aY = Move(tmp); } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/NullPtr.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/NullPtr.h index 35faadc4c3..5963613c4b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/NullPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/NullPtr.h @@ -13,12 +13,10 @@ #define mozilla_NullPtr_h #if defined(__clang__) -# ifndef __has_extension -# define __has_extension __has_feature -# endif -# if __has_extension(cxx_nullptr) -# define MOZ_HAVE_CXX11_NULLPTR +# if !__has_extension(cxx_nullptr) +# error "clang version natively supporting nullptr is required." # endif +# define MOZ_HAVE_CXX11_NULLPTR #elif defined(__GNUC__) # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L # include "mozilla/Compiler.h" @@ -26,23 +24,89 @@ # define MOZ_HAVE_CXX11_NULLPTR # endif # endif -#elif _MSC_VER >= 1600 -# define MOZ_HAVE_CXX11_NULLPTR +#elif defined(_MSC_VER) + // The minimum supported MSVC (10, _MSC_VER 1600) supports nullptr. +# define MOZ_HAVE_CXX11_NULLPTR #endif +namespace mozilla { + /** - * Use C++11 nullptr if available; otherwise use __null for gcc, or a 0 literal - * with the correct size to match the size of a pointer on a given platform. + * IsNullPointer::value is true iff T is the type of C++11's nullptr. If + * nullptr is emulated, IsNullPointer::value is false for all T. + * + * IsNullPointer is useful to give an argument the true decltype(nullptr) type. + * decltype(nullptr) doesn't work when nullptr is emulated. The simplest + * workaround is to use template overloading and SFINAE to expose an overload + * only if an argument's type is decltype(nullptr). Some examples (that assume + * namespace mozilla has been opened, for simplicity): + * + * // foo(T*), foo(stuff that converts to T*), and foo(decltype(nullptr)) + * // (only invoked if nullptr is true nullptr, otherwise foo(T*) is invoked) + * // but nothing else + * void foo(T*) { } + * template + * void foo(N, + * typename EnableIf::value, int>::Type dummy = 0) + * { } + * + * // foo(T*) *exactly* and foo(decltype(nullptr)), nothing else + * void foo(T*) { } + * template + * void foo(U, + * typename EnableIf::value, int>::Type dummy = 0) + * MOZ_DELETE; + * + * The exact details of how set up the SFINAE bits vary on a case-by-case basis. + * If you need help with this (and unless you've internalized way more sadmaking + * nullptr-emulation knowledge than you should have, you do), feel free to poke + * the person with blame on this comment with questions. :-) + * + * Ideally this would be in TypeTraits.h, but C++11 omitted std::is_null_pointer + * (fixed in C++1y), so in the interests of easing a switch to , + * this trait lives elsewhere. */ +template +struct IsNullPointer { static const bool value = false; }; -#ifndef MOZ_HAVE_CXX11_NULLPTR -# if defined(__GNUC__) -# define nullptr __null -# elif defined(_WIN64) -# define nullptr 0LL -# else -# define nullptr 0L -# endif +} // namespace mozilla + +/** + * mozilla::NullptrT is a type that's sort of like decltype(nullptr). But it + * can't be identical, because emulated nullptr doesn't have a distinct type. + * Only with gcc 4.4/4.5, emulated nullptr is __null, and decltype(__null) is + * int or long. But passing __null to an int/long parameter triggers + * -Werror=conversion-null errors with gcc 4.5, or (depending on subsequent use + * inside the overloaded function) can trigger pointer-to-integer comparison + * compiler errors. So fairly often, actually, NullptrT is *not* what you want. + * + * Instead, often you should use template-based overloading in concert with + * SFINAE to add a nullptr overload -- see the comments by IsNullPointer. + * + * So when *should* you use NullptrT? Thus far, the only truly good use seems + * to be as an argument type for operator overloads (because C++ doesn't allow + * operator= to have more than one argument, operator== to have more than two, + * &c.). But even in such cases, it really only works if there are no other + * overloads of the operator that accept a pointer type. If you want both T* + * and nullptr_t overloads, you'll have to wait til we drop gcc 4.4/4.5 support. + * (Currently b2g is the only impediment to this.) + */ +#ifdef MOZ_HAVE_CXX11_NULLPTR +// decltype does the right thing for actual nullptr. +namespace mozilla { +typedef decltype(nullptr) NullptrT; +template<> +struct IsNullPointer { static const bool value = true; }; +} +# undef MOZ_HAVE_CXX11_NULLPTR +#elif MOZ_IS_GCC +# define nullptr __null +// void* sweeps up more than just nullptr, but compilers supporting true +// nullptr are the majority now, so they should detect mistakes. If you're +// feeling paranoid, check/assert that your NullptrT equals nullptr. +namespace mozilla { typedef void* NullptrT; } +#else +# error "No compiler support for nullptr or its emulation." #endif #endif /* mozilla_NullPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/NumericLimits.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/NumericLimits.h index d2ee29813e..730fcb410b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/NumericLimits.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/NumericLimits.h @@ -17,10 +17,10 @@ namespace mozilla { /** - * The NumericLimits class provides a compatibility layer with std::numeric_limits - * for char16_t, otherwise it is exactly the same as std::numeric_limits. - * Code which does not need std::numeric_limits should avoid using - * NumericLimits. + * The NumericLimits class provides a compatibility layer with + * std::numeric_limits for char16_t, otherwise it is exactly the same as + * std::numeric_limits. Code which does not need std::numeric_limits + * should avoid using NumericLimits. */ template class NumericLimits : public std::numeric_limits diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Pair.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Pair.h new file mode 100644 index 0000000000..e9e8a76938 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Pair.h @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A class holding a pair of objects that tries to conserve storage space. */ + +#ifndef mozilla_Pair_h +#define mozilla_Pair_h + +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +namespace detail { + +enum StorageType { AsBase, AsMember }; + +// Optimize storage using the Empty Base Optimization -- that empty base classes +// don't take up space -- to optimize size when one or the other class is +// stateless and can be used as a base class. +// +// The extra conditions on storage for B are necessary so that PairHelper won't +// ambiguously inherit from either A or B, such that one or the other base class +// would be inaccessible. +template::value ? detail::AsBase : detail::AsMember, + detail::StorageType = + IsEmpty::value && !IsBaseOf::value && !IsBaseOf::value + ? detail::AsBase + : detail::AsMember> +struct PairHelper; + +template +struct PairHelper +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : mFirstA(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(mSecondB, aOther.mSecondB); + } + +private: + A mFirstA; + B mSecondB; +}; + +template +struct PairHelper : private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : B(Forward(aB)), + mFirstA(Forward(aA)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return *this; } + const B& second() const { return *this; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(static_cast(*this), static_cast(aOther)); + } + +private: + A mFirstA; +}; + +template +struct PairHelper : private A +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return *this; } + const A& first() const { return *this; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(mSecondB, aOther.mSecondB); + } + +private: + B mSecondB; +}; + +template +struct PairHelper : private A, private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + B(Forward(aB)) + {} + + A& first() { return static_cast(*this); } + const A& first() const { return static_cast(*this); } + B& second() { return static_cast(*this); } + const B& second() const { return static_cast(*this); } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(static_cast(*this), static_cast(aOther)); + } +}; + +} // namespace detail + +/** + * Pair is the logical concatenation of an instance of A with an instance B. + * Space is conserved when possible. Neither A nor B may be a final class. + * + * It's typically clearer to have individual A and B member fields. Except if + * you want the space-conserving qualities of Pair, you're probably better off + * not using this! + * + * No guarantees are provided about the memory layout of A and B, the order of + * initialization or destruction of A and B, and so on. (This is approximately + * required to optimize space usage.) The first/second names are merely + * conceptual! + */ +template +struct Pair + : private detail::PairHelper +{ + typedef typename detail::PairHelper Base; + +public: + template + Pair(AArg&& aA, BArg&& aB) + : Base(Forward(aA), Forward(aB)) + {} + + /** The A instance. */ + using Base::first; + /** The B instance. */ + using Base::second; + + /** Swap this pair with another pair. */ + void swap(Pair& aOther) { Base::swap(aOther); } + +private: + Pair(const Pair&) MOZ_DELETE; +}; + +template +void +Swap(Pair& aX, Pair& aY) +{ + aX.swap(aY); +} + +} // namespace mozilla + +#endif /* mozilla_Pair_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/PodOperations.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/PodOperations.h index adbf2e699d..843e1311d3 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/PodOperations.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/PodOperations.h @@ -24,26 +24,27 @@ namespace mozilla { -/** Set the contents of |t| to 0. */ +/** Set the contents of |aT| to 0. */ template static MOZ_ALWAYS_INLINE void -PodZero(T* t) +PodZero(T* aT) { - memset(t, 0, sizeof(T)); + memset(aT, 0, sizeof(T)); } -/** Set the contents of |nelem| elements starting at |t| to 0. */ +/** Set the contents of |aNElem| elements starting at |aT| to 0. */ template static MOZ_ALWAYS_INLINE void -PodZero(T* t, size_t nelem) +PodZero(T* aT, size_t aNElem) { /* - * This function is often called with 'nelem' small; we use an inline loop + * This function is often called with 'aNElem' small; we use an inline loop * instead of calling 'memset' with a non-constant length. The compiler * should inline the memset call with constant size, though. */ - for (T* end = t + nelem; t < end; t++) - memset(t, 0, sizeof(T)); + for (T* end = aT + aNElem; aT < end; aT++) { + memset(aT, 0, sizeof(T)); + } } /* @@ -54,107 +55,116 @@ PodZero(T* t, size_t nelem) * compile error involving PodZero and array types, use PodArrayZero instead. */ template -static void PodZero(T (&t)[N]) MOZ_DELETE; +static void PodZero(T (&aT)[N]) MOZ_DELETE; template -static void PodZero(T (&t)[N], size_t nelem) MOZ_DELETE; +static void PodZero(T (&aT)[N], size_t aNElem) MOZ_DELETE; -/** Set the contents of the array |t| to zero. */ +/** Set the contents of the array |aT| to zero. */ template static MOZ_ALWAYS_INLINE void -PodArrayZero(T (&t)[N]) +PodArrayZero(T (&aT)[N]) { - memset(t, 0, N * sizeof(T)); + memset(aT, 0, N * sizeof(T)); } template static MOZ_ALWAYS_INLINE void -PodArrayZero(Array& arr) +PodArrayZero(Array& aArr) { - memset(&arr[0], 0, N * sizeof(T)); + memset(&aArr[0], 0, N * sizeof(T)); } /** - * Assign |*src| to |*dst|. The locations must not be the same and must not + * Assign |*aSrc| to |*aDst|. The locations must not be the same and must not * overlap. */ template static MOZ_ALWAYS_INLINE void -PodAssign(T* dst, const T* src) +PodAssign(T* aDst, const T* aSrc) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, PointerRangeSize(src, static_cast(dst)) >= 1); - MOZ_ASSERT_IF(dst < src, PointerRangeSize(static_cast(dst), src) >= 1); - memcpy(reinterpret_cast(dst), reinterpret_cast(src), sizeof(T)); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= 1); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= 1); + memcpy(reinterpret_cast(aDst), reinterpret_cast(aSrc), + sizeof(T)); } /** - * Copy |nelem| T elements from |src| to |dst|. The two memory ranges must not - * overlap! + * Copy |aNElem| T elements from |aSrc| to |aDst|. The two memory ranges must + * not overlap! */ template static MOZ_ALWAYS_INLINE void -PodCopy(T* dst, const T* src, size_t nelem) +PodCopy(T* aDst, const T* aSrc, size_t aNElem) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, PointerRangeSize(src, static_cast(dst)) >= nelem); - MOZ_ASSERT_IF(dst < src, PointerRangeSize(static_cast(dst), src) >= nelem); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); - if (nelem < 128) { + if (aNElem < 128) { /* * Avoid using operator= in this loop, as it may have been * intentionally deleted by the POD type. */ - for (const T* srcend = src + nelem; src < srcend; src++, dst++) - PodAssign(dst, src); + for (const T* srcend = aSrc + aNElem; aSrc < srcend; aSrc++, aDst++) { + PodAssign(aDst, aSrc); + } } else { - memcpy(dst, src, nelem * sizeof(T)); + memcpy(aDst, aSrc, aNElem * sizeof(T)); } } template static MOZ_ALWAYS_INLINE void -PodCopy(volatile T* dst, const volatile T* src, size_t nelem) +PodCopy(volatile T* aDst, const volatile T* aSrc, size_t aNElem) { - MOZ_ASSERT(dst != src); - MOZ_ASSERT_IF(src < dst, - PointerRangeSize(src, static_cast(dst)) >= nelem); - MOZ_ASSERT_IF(dst < src, - PointerRangeSize(static_cast(dst), src) >= nelem); + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); /* - * Volatile |dst| requires extra work, because it's undefined behavior to + * Volatile |aDst| requires extra work, because it's undefined behavior to * modify volatile objects using the mem* functions. Just write out the * loops manually, using operator= rather than memcpy for the same reason, * and let the compiler optimize to the extent it can. */ - for (const volatile T* srcend = src + nelem; src < srcend; src++, dst++) - *dst = *src; + for (const volatile T* srcend = aSrc + aNElem; + aSrc < srcend; + aSrc++, aDst++) { + *aDst = *aSrc; + } } /* - * Copy the contents of the array |src| into the array |dst|, both of size N. + * Copy the contents of the array |aSrc| into the array |aDst|, both of size N. * The arrays must not overlap! */ template static MOZ_ALWAYS_INLINE void -PodArrayCopy(T (&dst)[N], const T (&src)[N]) +PodArrayCopy(T (&aDst)[N], const T (&aSrc)[N]) { - PodCopy(dst, src, N); + PodCopy(aDst, aSrc, N); } /** - * Copy the memory for |nelem| T elements from |src| to |dst|. If the two - * memory ranges overlap, then the effect is as if the |nelem| elements are - * first copied from |src| to a temporary array, and then from the temporary - * array to |dst|. + * Copy the memory for |aNElem| T elements from |aSrc| to |aDst|. If the two + * memory ranges overlap, then the effect is as if the |aNElem| elements are + * first copied from |aSrc| to a temporary array, and then from the temporary + * array to |aDst|. */ template static MOZ_ALWAYS_INLINE void -PodMove(T* dst, const T* src, size_t nelem) +PodMove(T* aDst, const T* aSrc, size_t aNElem) { - MOZ_ASSERT(nelem <= SIZE_MAX / sizeof(T), + MOZ_ASSERT(aNElem <= SIZE_MAX / sizeof(T), "trying to move an impossible number of elements"); - memmove(dst, src, nelem * sizeof(T)); + memmove(aDst, aSrc, aNElem * sizeof(T)); } /** @@ -170,8 +180,9 @@ PodEqual(const T* one, const T* two, size_t len) const T* p1 = one; const T* p2 = two; for (; p1 < p1end; p1++, p2++) { - if (*p1 != *p2) + if (*p1 != *p2) { return false; + } } return true; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Range.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Range.h index 4e02d962b5..814a2821ad 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Range.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Range.h @@ -18,32 +18,26 @@ namespace mozilla { template class Range { - RangedPtr mStart; - RangedPtr mEnd; + const RangedPtr mStart; + const RangedPtr mEnd; - typedef void (Range::* ConvertibleToBool)(); - void nonNull() {} + typedef void (Range::* ConvertibleToBool)(); + void nonNull() {} - public: - Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} - Range(T* p, size_t len) - : mStart(p, p, p + len), - mEnd(p + len, p, p + len) - {} +public: + Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} + Range(T* aPtr, size_t aLength) + : mStart(aPtr, aPtr, aPtr + aLength), + mEnd(aPtr + aLength, aPtr, aPtr + aLength) + {} - RangedPtr start() const { return mStart; } - RangedPtr end() const { return mEnd; } - size_t length() const { return mEnd - mStart; } + RangedPtr start() const { return mStart; } + RangedPtr end() const { return mEnd; } + size_t length() const { return mEnd - mStart; } - T& operator[](size_t offset) { - return mStart[offset]; - } + T& operator[](size_t aOffset) const { return mStart[aOffset]; } - const T& operator[](size_t offset) const { - return mStart[offset]; - } - - operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } + operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RangedPtr.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RangedPtr.h index 561e564ded..4d94035b90 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RangedPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RangedPtr.h @@ -43,214 +43,240 @@ namespace mozilla { template class RangedPtr { - T* ptr; + T* mPtr; #ifdef DEBUG - T* const rangeStart; - T* const rangeEnd; + T* const mRangeStart; + T* const mRangeEnd; #endif - typedef void (RangedPtr::* ConvertibleToBool)(); - void nonNull() {} + typedef void (RangedPtr::* ConvertibleToBool)(); + void nonNull() {} - void checkSanity() { - MOZ_ASSERT(rangeStart <= ptr); - MOZ_ASSERT(ptr <= rangeEnd); - } + void checkSanity() + { + MOZ_ASSERT(mRangeStart <= mPtr); + MOZ_ASSERT(mPtr <= mRangeEnd); + } - /* Creates a new pointer for |p|, restricted to this pointer's range. */ - RangedPtr create(T *p) const { + /* Creates a new pointer for |aPtr|, restricted to this pointer's range. */ + RangedPtr create(T* aPtr) const + { #ifdef DEBUG - return RangedPtr(p, rangeStart, rangeEnd); + return RangedPtr(aPtr, mRangeStart, mRangeEnd); #else - return RangedPtr(p, nullptr, size_t(0)); + return RangedPtr(aPtr, nullptr, size_t(0)); #endif - } + } - uintptr_t asUintptr() const { return uintptr_t(ptr); } + uintptr_t asUintptr() const { return reinterpret_cast(mPtr); } - public: - RangedPtr(T* p, T* start, T* end) - : ptr(p) +public: + RangedPtr(T* aPtr, T* aStart, T* aEnd) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(start), rangeEnd(end) + , mRangeStart(aStart), mRangeEnd(aEnd) #endif - { - MOZ_ASSERT(rangeStart <= rangeEnd); - checkSanity(); - } - RangedPtr(T* p, T* start, size_t length) - : ptr(p) + { + MOZ_ASSERT(mRangeStart <= mRangeEnd); + checkSanity(); + } + RangedPtr(T* aPtr, T* aStart, size_t aLength) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(start), rangeEnd(start + length) + , mRangeStart(aStart), mRangeEnd(aStart + aLength) #endif - { - MOZ_ASSERT(length <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(uintptr_t(rangeStart) + length * sizeof(T) >= uintptr_t(rangeStart)); - checkSanity(); - } - - /* Equivalent to RangedPtr(p, p, length). */ - RangedPtr(T* p, size_t length) - : ptr(p) + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aPtr, aPtr, aLength). */ + RangedPtr(T* aPtr, size_t aLength) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(p), rangeEnd(p + length) + , mRangeStart(aPtr), mRangeEnd(aPtr + aLength) #endif - { - MOZ_ASSERT(length <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(uintptr_t(rangeStart) + length * sizeof(T) >= uintptr_t(rangeStart)); - checkSanity(); - } - - /* Equivalent to RangedPtr(arr, arr, N). */ - template - RangedPtr(T (&arr)[N]) - : ptr(arr) + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aArr, aArr, N). */ + template + RangedPtr(T (&aArr)[N]) + : mPtr(aArr) #ifdef DEBUG - , rangeStart(arr), rangeEnd(arr + N) + , mRangeStart(aArr), mRangeEnd(aArr + N) #endif - { - checkSanity(); - } - - T* get() const { - return ptr; - } - - operator ConvertibleToBool() const { return ptr ? &RangedPtr::nonNull : 0; } - - /* - * You can only assign one RangedPtr into another if the two pointers have - * the same valid range: - * - * char arr1[] = "hi"; - * char arr2[] = "bye"; - * RangedPtr p1(arr1, 2); - * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works - * p1 = RangedPtr(arr2, 3); // asserts - */ - RangedPtr& operator=(const RangedPtr& other) { - MOZ_ASSERT(rangeStart == other.rangeStart); - MOZ_ASSERT(rangeEnd == other.rangeEnd); - ptr = other.ptr; - checkSanity(); - return *this; - } - - RangedPtr operator+(size_t inc) { - MOZ_ASSERT(inc <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(asUintptr() + inc * sizeof(T) >= asUintptr()); - return create(ptr + inc); - } - - RangedPtr operator-(size_t dec) { - MOZ_ASSERT(dec <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(asUintptr() - dec * sizeof(T) <= asUintptr()); - return create(ptr - dec); - } - - /* - * You can assign a raw pointer into a RangedPtr if the raw pointer is - * within the range specified at creation. - */ - template - RangedPtr& operator=(U* p) { - *this = create(p); - return *this; - } - - template - RangedPtr& operator=(const RangedPtr& p) { - MOZ_ASSERT(rangeStart <= p.ptr); - MOZ_ASSERT(p.ptr <= rangeEnd); - ptr = p.ptr; - checkSanity(); - return *this; - } - - RangedPtr& operator++() { - return (*this += 1); - } - - RangedPtr operator++(int) { - RangedPtr rcp = *this; - ++*this; - return rcp; - } - - RangedPtr& operator--() { - return (*this -= 1); - } - - RangedPtr operator--(int) { - RangedPtr rcp = *this; - --*this; - return rcp; - } - - RangedPtr& operator+=(size_t inc) { - *this = *this + inc; - return *this; - } - - RangedPtr& operator-=(size_t dec) { - *this = *this - dec; - return *this; - } - - T& operator[](int index) const { - MOZ_ASSERT(size_t(index > 0 ? index : -index) <= size_t(-1) / sizeof(T)); - return *create(ptr + index); - } - - T& operator*() const { - return *ptr; - } - - template - bool operator==(const RangedPtr& other) const { - return ptr == other.ptr; - } - template - bool operator!=(const RangedPtr& other) const { - return !(*this == other); - } - - template - bool operator==(const U* u) const { - return ptr == u; - } - template - bool operator!=(const U* u) const { - return !(*this == u); - } - - template - bool operator<(const RangedPtr& other) const { - return ptr < other.ptr; - } - template - bool operator<=(const RangedPtr& other) const { - return ptr <= other.ptr; - } - - template - bool operator>(const RangedPtr& other) const { - return ptr > other.ptr; - } - template - bool operator>=(const RangedPtr& other) const { - return ptr >= other.ptr; - } - - size_t operator-(const RangedPtr& other) const { - MOZ_ASSERT(ptr >= other.ptr); - return PointerRangeSize(other.ptr, ptr); - } - - private: - RangedPtr() MOZ_DELETE; - T* operator&() MOZ_DELETE; + { + checkSanity(); + } + + T* get() const { return mPtr; } + + operator ConvertibleToBool() const { return mPtr ? &RangedPtr::nonNull : 0; } + + /* + * You can only assign one RangedPtr into another if the two pointers have + * the same valid range: + * + * char arr1[] = "hi"; + * char arr2[] = "bye"; + * RangedPtr p1(arr1, 2); + * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works + * p1 = RangedPtr(arr2, 3); // asserts + */ + RangedPtr& operator=(const RangedPtr& aOther) + { + MOZ_ASSERT(mRangeStart == aOther.mRangeStart); + MOZ_ASSERT(mRangeEnd == aOther.mRangeEnd); + mPtr = aOther.mPtr; + checkSanity(); + return *this; + } + + RangedPtr operator+(size_t aInc) + { + MOZ_ASSERT(aInc <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() + aInc * sizeof(T) >= asUintptr()); + return create(mPtr + aInc); + } + + RangedPtr operator-(size_t aDec) + { + MOZ_ASSERT(aDec <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() - aDec * sizeof(T) <= asUintptr()); + return create(mPtr - aDec); + } + + /* + * You can assign a raw pointer into a RangedPtr if the raw pointer is + * within the range specified at creation. + */ + template + RangedPtr& operator=(U* aPtr) + { + *this = create(aPtr); + return *this; + } + + template + RangedPtr& operator=(const RangedPtr& aPtr) + { + MOZ_ASSERT(mRangeStart <= aPtr.mPtr); + MOZ_ASSERT(aPtr.mPtr <= mRangeEnd); + mPtr = aPtr.mPtr; + checkSanity(); + return *this; + } + + RangedPtr& operator++() + { + return (*this += 1); + } + + RangedPtr operator++(int) + { + RangedPtr rcp = *this; + ++*this; + return rcp; + } + + RangedPtr& operator--() + { + return (*this -= 1); + } + + RangedPtr operator--(int) + { + RangedPtr rcp = *this; + --*this; + return rcp; + } + + RangedPtr& operator+=(size_t aInc) + { + *this = *this + aInc; + return *this; + } + + RangedPtr& operator-=(size_t aDec) + { + *this = *this - aDec; + return *this; + } + + T& operator[](int aIndex) const + { + MOZ_ASSERT(size_t(aIndex > 0 ? aIndex : -aIndex) <= size_t(-1) / sizeof(T)); + return *create(mPtr + aIndex); + } + + T& operator*() const + { + MOZ_ASSERT(mPtr >= mRangeStart); + MOZ_ASSERT(mPtr < mRangeEnd); + return *mPtr; + } + + template + bool operator==(const RangedPtr& aOther) const + { + return mPtr == aOther.mPtr; + } + template + bool operator!=(const RangedPtr& aOther) const + { + return !(*this == aOther); + } + + template + bool operator==(const U* u) const + { + return mPtr == u; + } + template + bool operator!=(const U* u) const + { + return !(*this == u); + } + + template + bool operator<(const RangedPtr& aOther) const + { + return mPtr < aOther.mPtr; + } + template + bool operator<=(const RangedPtr& aOther) const + { + return mPtr <= aOther.mPtr; + } + + template + bool operator>(const RangedPtr& aOther) const + { + return mPtr > aOther.mPtr; + } + template + bool operator>=(const RangedPtr& aOther) const + { + return mPtr >= aOther.mPtr; + } + + size_t operator-(const RangedPtr& aOther) const + { + MOZ_ASSERT(mPtr >= aOther.mPtr); + return PointerRangeSize(aOther.mPtr, mPtr); + } + +private: + RangedPtr() MOZ_DELETE; + T* operator&() MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ReentrancyGuard.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ReentrancyGuard.h index d589f368a2..557c61015e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ReentrancyGuard.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ReentrancyGuard.h @@ -18,38 +18,38 @@ namespace mozilla { /* Useful for implementing containers that assert non-reentrancy */ class ReentrancyGuard { - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER #ifdef DEBUG - bool& entered; + bool& mEntered; #endif - public: - template +public: + template #ifdef DEBUG - ReentrancyGuard(T& obj - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : entered(obj.entered) + ReentrancyGuard(T& aObj + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mEntered(aObj.mEntered) #else - ReentrancyGuard(T& - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + ReentrancyGuard(T& + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) #endif - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; #ifdef DEBUG - MOZ_ASSERT(!entered); - entered = true; + MOZ_ASSERT(!mEntered); + mEntered = true; #endif - } - ~ReentrancyGuard() - { + } + ~ReentrancyGuard() + { #ifdef DEBUG - entered = false; + mEntered = false; #endif - } + } - private: - ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; - void operator=(const ReentrancyGuard&) MOZ_DELETE; +private: + ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; + void operator=(const ReentrancyGuard&) MOZ_DELETE; }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RefCountType.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RefCountType.h new file mode 100644 index 0000000000..e95a22a0ca --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RefCountType.h @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_RefCountType_h +#define mozilla_RefCountType_h + +#include + +/** + * MozRefCountType is Mozilla's reference count type. + * + * We use the same type to represent the refcount of RefCounted objects + * as well, in order to be able to use the leak detection facilities + * that are implemented by XPCOM. + * + * Note that this type is not in the mozilla namespace so that it is + * usable for both C and C++ code. + */ +typedef uintptr_t MozRefCountType; + +/* + * This is the return type for AddRef() and Release() in nsISupports. + * IUnknown of COM returns an unsigned long from equivalent functions. + * + * The following ifdef exists to maintain binary compatibility with + * IUnknown, the base interface in Microsoft COM. + */ +#ifdef XP_WIN +typedef unsigned long MozExternalRefCountType; +#else +typedef uint32_t MozExternalRefCountType; +#endif + +#endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RefPtr.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RefPtr.h index 72c7904554..4901067b4c 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RefPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RefPtr.h @@ -12,7 +12,17 @@ #include "mozilla/Assertions.h" #include "mozilla/Atomics.h" #include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" +#include "mozilla/RefCountType.h" #include "mozilla/TypeTraits.h" +#if defined(MOZILLA_INTERNAL_API) +#include "nsXPCOM.h" +#endif + +#if defined(MOZILLA_INTERNAL_API) && \ + (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) +#define MOZ_REFCOUNTED_LEAK_CHECKING +#endif namespace mozilla { @@ -42,10 +52,37 @@ template OutParamRef byRef(RefPtr&); * state is represented in DEBUG builds by refcount==0xffffdead. This * state distinguishes use-before-ref (refcount==0) from * use-after-destroy (refcount==0xffffdead). + * + * Note that when deriving from RefCounted or AtomicRefCounted, you + * should add MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public + * section of your class, where ClassName is the name of your class. */ namespace detail { #ifdef DEBUG -static const int DEAD = 0xffffdead; +const MozRefCountType DEAD = 0xffffdead; +#endif + +// When building code that gets compiled into Gecko, try to use the +// trace-refcount leak logging facilities. +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +class RefCountLogger +{ +public: + static void logAddRef(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName, uint32_t aInstanceSize) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogAddRef(const_cast(aPointer), aRefCount, aTypeName, + aInstanceSize); + } + + static void logRelease(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogRelease(const_cast(aPointer), aRefCount, aTypeName); + } +}; #endif // This is used WeakPtr.h as well as this file. @@ -58,70 +95,122 @@ enum RefCountAtomicity template class RefCounted { - friend class RefPtr; + friend class RefPtr; - protected: - RefCounted() : refCnt(0) { } - ~RefCounted() { - MOZ_ASSERT(refCnt == detail::DEAD); - } +protected: + RefCounted() : mRefCnt(0) {} + ~RefCounted() { MOZ_ASSERT(mRefCnt == detail::DEAD); } - public: - // Compatibility with nsRefPtr. - void AddRef() const { - MOZ_ASSERT(refCnt >= 0); - ++refCnt; - } +public: + // Compatibility with nsRefPtr. + void AddRef() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) >= 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + ++mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + uint32_t size = static_cast(this)->typeSize(); + const void* ptr = static_cast(this); + MozRefCountType cnt = ++mRefCnt; + detail::RefCountLogger::logAddRef(ptr, cnt, type, size); +#endif + } - void Release() const { - MOZ_ASSERT(refCnt > 0); - if (0 == --refCnt) { + void Release() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) > 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + MozRefCountType cnt = --mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + const void* ptr = static_cast(this); + MozRefCountType cnt = --mRefCnt; + // Note: it's not safe to touch |this| after decrementing the refcount, + // except for below. + detail::RefCountLogger::logRelease(ptr, cnt, type); +#endif + if (0 == cnt) { + // Because we have atomically decremented the refcount above, only + // one thread can get a 0 count here, so as long as we can assume that + // everything else in the system is accessing this object through + // RefPtrs, it's safe to access |this| here. #ifdef DEBUG - refCnt = detail::DEAD; + mRefCnt = detail::DEAD; #endif - delete static_cast(this); - } + delete static_cast(this); } + } - // Compatibility with wtf::RefPtr. - void ref() { AddRef(); } - void deref() { Release(); } - int refCount() const { return refCnt; } - bool hasOneRef() const { - MOZ_ASSERT(refCnt > 0); - return refCnt == 1; - } + // Compatibility with wtf::RefPtr. + void ref() { AddRef(); } + void deref() { Release(); } + MozRefCountType refCount() const { return mRefCnt; } + bool hasOneRef() const + { + MOZ_ASSERT(mRefCnt > 0); + return mRefCnt == 1; + } - private: - mutable typename Conditional, int>::Type refCnt; +private: + mutable typename Conditional, + MozRefCountType>::Type mRefCnt; }; -} +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) \ + virtual const char* typeName() const { return #T; } \ + virtual size_t typeSize() const { return sizeof(*this); } +#else +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) +#endif + +// Note that this macro is expanded unconditionally because it declares only +// two small inline functions which will hopefully get eliminated by the linker +// in non-leak-checking builds. +#define MOZ_DECLARE_REFCOUNTED_TYPENAME(T) \ + const char* typeName() const { return #T; } \ + size_t typeSize() const { return sizeof(*this); } + +} // namespace detail template class RefCounted : public detail::RefCounted { - public: - ~RefCounted() { - static_assert(IsBaseOf::value, - "T must derive from RefCounted"); - } +public: + ~RefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from RefCounted"); + } }; +namespace external { + /** * AtomicRefCounted is like RefCounted, with an atomically updated * reference counter. + * + * NOTE: Please do not use this class, use NS_INLINE_DECL_THREADSAFE_REFCOUNTING + * instead. */ template -class AtomicRefCounted : public detail::RefCounted +class AtomicRefCounted : + public mozilla::detail::RefCounted { - public: - ~AtomicRefCounted() { - static_assert(IsBaseOf::value, - "T must derive from AtomicRefCounted"); - } +public: + ~AtomicRefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from AtomicRefCounted"); + } }; +} // namespace external + /** * RefPtr points to a refcounted thing that has AddRef and Release * methods to increase/decrease the refcount, respectively. After a @@ -135,73 +224,83 @@ class AtomicRefCounted : public detail::RefCounted template class RefPtr { - // To allow them to use unref() - friend class TemporaryRef; - friend class OutParamRef; + // To allow them to use unref() + friend class TemporaryRef; + friend class OutParamRef; - struct DontRef {}; + struct DontRef {}; - public: - RefPtr() : ptr(0) { } - RefPtr(const RefPtr& o) : ptr(ref(o.ptr)) {} - RefPtr(const TemporaryRef& o) : ptr(o.drop()) {} - RefPtr(T* t) : ptr(ref(t)) {} +public: + RefPtr() : mPtr(0) {} + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.mPtr)) {} + MOZ_IMPLICIT RefPtr(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + MOZ_IMPLICIT RefPtr(T* aVal) : mPtr(ref(aVal)) {} - template - RefPtr(const RefPtr& o) : ptr(ref(o.get())) {} + template + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.get())) {} - ~RefPtr() { unref(ptr); } + ~RefPtr() { unref(mPtr); } - RefPtr& operator=(const RefPtr& o) { - assign(ref(o.ptr)); - return *this; - } - RefPtr& operator=(const TemporaryRef& o) { - assign(o.drop()); - return *this; - } - RefPtr& operator=(T* t) { - assign(ref(t)); - return *this; - } + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.mPtr)); + return *this; + } + RefPtr& operator=(const TemporaryRef& aOther) + { + assign(aOther.drop()); + return *this; + } + RefPtr& operator=(T* aVal) + { + assign(ref(aVal)); + return *this; + } - template - RefPtr& operator=(const RefPtr& o) { - assign(ref(o.get())); - return *this; - } + template + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.get())); + return *this; + } - TemporaryRef forget() { - T* tmp = ptr; - ptr = 0; - return TemporaryRef(tmp, DontRef()); - } + TemporaryRef forget() + { + T* tmp = mPtr; + mPtr = nullptr; + return TemporaryRef(tmp, DontRef()); + } - T* get() const { return ptr; } - operator T*() const { return ptr; } - T* operator->() const { return ptr; } - T& operator*() const { return *ptr; } - template - operator TemporaryRef() { return TemporaryRef(ptr); } - - private: - void assign(T* t) { - unref(ptr); - ptr = t; - } + T* get() const { return mPtr; } + operator T*() const { return mPtr; } + T* operator->() const { return mPtr; } + T& operator*() const { return *mPtr; } + template + operator TemporaryRef() { return TemporaryRef(mPtr); } + +private: + void assign(T* aVal) + { + unref(mPtr); + mPtr = aVal; + } - T* ptr; + T* mPtr; - static MOZ_ALWAYS_INLINE T* ref(T* t) { - if (t) - t->AddRef(); - return t; + static MOZ_ALWAYS_INLINE T* ref(T* aVal) + { + if (aVal) { + aVal->AddRef(); } + return aVal; + } - static MOZ_ALWAYS_INLINE void unref(T* t) { - if (t) - t->Release(); + static MOZ_ALWAYS_INLINE void unref(T* aVal) + { + if (aVal) { + aVal->Release(); } + } }; /** @@ -213,33 +312,34 @@ class RefPtr template class TemporaryRef { - // To allow it to construct TemporaryRef from a bare T* - friend class RefPtr; + // To allow it to construct TemporaryRef from a bare T* + friend class RefPtr; - typedef typename RefPtr::DontRef DontRef; + typedef typename RefPtr::DontRef DontRef; - public: - TemporaryRef(T* t) : ptr(RefPtr::ref(t)) {} - TemporaryRef(const TemporaryRef& o) : ptr(o.drop()) {} +public: + MOZ_IMPLICIT TemporaryRef(T* aVal) : mPtr(RefPtr::ref(aVal)) {} + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} - template - TemporaryRef(const TemporaryRef& o) : ptr(o.drop()) {} + template + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} - ~TemporaryRef() { RefPtr::unref(ptr); } + ~TemporaryRef() { RefPtr::unref(mPtr); } - T* drop() const { - T* tmp = ptr; - ptr = 0; - return tmp; - } + T* drop() const + { + T* tmp = mPtr; + mPtr = nullptr; + return tmp; + } - private: - TemporaryRef(T* t, const DontRef&) : ptr(t) {} +private: + TemporaryRef(T* aVal, const DontRef&) : mPtr(aVal) {} - mutable T* ptr; + mutable T* mPtr; - TemporaryRef() MOZ_DELETE; - void operator=(const TemporaryRef&) MOZ_DELETE; + TemporaryRef() MOZ_DELETE; + void operator=(const TemporaryRef&) MOZ_DELETE; }; /** @@ -259,24 +359,25 @@ class TemporaryRef template class OutParamRef { - friend OutParamRef byRef(RefPtr&); + friend OutParamRef byRef(RefPtr&); - public: - ~OutParamRef() { - RefPtr::unref(refPtr.ptr); - refPtr.ptr = tmp; - } +public: + ~OutParamRef() + { + RefPtr::unref(mRefPtr.mPtr); + mRefPtr.mPtr = mTmp; + } - operator T**() { return &tmp; } + operator T**() { return &mTmp; } - private: - OutParamRef(RefPtr& p) : refPtr(p), tmp(p.get()) {} +private: + explicit OutParamRef(RefPtr& p) : mRefPtr(p), mTmp(p.get()) {} - RefPtr& refPtr; - T* tmp; + RefPtr& mRefPtr; + T* mTmp; - OutParamRef() MOZ_DELETE; - OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; + OutParamRef() MOZ_DELETE; + OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; }; /** @@ -284,9 +385,9 @@ class OutParamRef */ template OutParamRef -byRef(RefPtr& ptr) +byRef(RefPtr& aPtr) { - return OutParamRef(ptr); + return OutParamRef(aPtr); } } // namespace mozilla @@ -301,19 +402,21 @@ using namespace mozilla; struct Foo : public RefCounted { - Foo() : dead(false) { } - ~Foo() { - MOZ_ASSERT(!dead); - dead = true; - numDestroyed++; + MOZ_DECLARE_REFCOUNTED_TYPENAME(Foo) + Foo() : mDead(false) {} + ~Foo() + { + MOZ_ASSERT(!mDead); + mDead = true; + sNumDestroyed++; } - bool dead; - static int numDestroyed; + bool mDead; + static int sNumDestroyed; }; -int Foo::numDestroyed; +int Foo::sNumDestroyed; -struct Bar : public Foo { }; +struct Bar : public Foo {}; TemporaryRef NewFoo() @@ -364,25 +467,25 @@ main(int argc, char** argv) // This should blow up // Foo* f = new Foo(); delete f; - MOZ_ASSERT(0 == Foo::numDestroyed); + MOZ_ASSERT(0 == Foo::sNumDestroyed); { RefPtr f = new Foo(); MOZ_ASSERT(f->refCount() == 1); } - MOZ_ASSERT(1 == Foo::numDestroyed); + MOZ_ASSERT(1 == Foo::sNumDestroyed); { RefPtr f1 = NewFoo(); RefPtr f2(NewFoo()); - MOZ_ASSERT(1 == Foo::numDestroyed); + MOZ_ASSERT(1 == Foo::sNumDestroyed); } - MOZ_ASSERT(3 == Foo::numDestroyed); + MOZ_ASSERT(3 == Foo::sNumDestroyed); { RefPtr b = NewBar(); - MOZ_ASSERT(3 == Foo::numDestroyed); + MOZ_ASSERT(3 == Foo::sNumDestroyed); } - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); { RefPtr f1; @@ -390,56 +493,56 @@ main(int argc, char** argv) f1 = new Foo(); RefPtr f2(f1); RefPtr f3 = f2; - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); } - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); } - MOZ_ASSERT(5 == Foo::numDestroyed); + MOZ_ASSERT(5 == Foo::sNumDestroyed); { RefPtr f = new Foo(); f.forget(); - MOZ_ASSERT(6 == Foo::numDestroyed); + MOZ_ASSERT(6 == Foo::sNumDestroyed); } { RefPtr f = new Foo(); GetNewFoo(byRef(f)); - MOZ_ASSERT(7 == Foo::numDestroyed); + MOZ_ASSERT(7 == Foo::sNumDestroyed); } - MOZ_ASSERT(8 == Foo::numDestroyed); + MOZ_ASSERT(8 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetPassedFoo(byRef(f)); - MOZ_ASSERT(8 == Foo::numDestroyed); + MOZ_ASSERT(8 == Foo::sNumDestroyed); } - MOZ_ASSERT(9 == Foo::numDestroyed); + MOZ_ASSERT(9 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetNewFoo(&f); - MOZ_ASSERT(10 == Foo::numDestroyed); + MOZ_ASSERT(10 == Foo::sNumDestroyed); } - MOZ_ASSERT(11 == Foo::numDestroyed); + MOZ_ASSERT(11 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetPassedFoo(&f); - MOZ_ASSERT(11 == Foo::numDestroyed); + MOZ_ASSERT(11 == Foo::sNumDestroyed); } - MOZ_ASSERT(12 == Foo::numDestroyed); + MOZ_ASSERT(12 == Foo::sNumDestroyed); { RefPtr f1 = new Bar(); } - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); { RefPtr f = GetNullFoo(); - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); } - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); return 0; } diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RollingMean.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RollingMean.h index 5caee3bc83..5add14c879 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RollingMean.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/RollingMean.h @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-w idth: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -12,9 +13,7 @@ #include "mozilla/TypeTraits.h" #include "mozilla/Vector.h" -#include #include -#include namespace mozilla { @@ -30,78 +29,85 @@ namespace mozilla { template class RollingMean { - private: - size_t mInsertIndex; - size_t mMaxValues; - Vector mValues; - S mTotal; - - public: - static_assert(!IsFloatingPoint::value, - "floating-point types are unsupported due to rounding " - "errors"); - - RollingMean(size_t aMaxValues) - : mInsertIndex(0), - mMaxValues(aMaxValues), - mTotal(0) - { - MOZ_ASSERT(aMaxValues > 0); - } - - RollingMean& operator=(RollingMean&& aOther) { - MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); - this->~RollingMean(); - new(this) RollingMean(aOther.mMaxValues); - mInsertIndex = aOther.mInsertIndex; - mTotal = aOther.mTotal; - mValues.swap(aOther.mValues); - return *this; - } - - /** - * Insert a value into the rolling mean. - */ - bool insert(T aValue) { - MOZ_ASSERT(mValues.length() <= mMaxValues); - - if (mValues.length() == mMaxValues) { - mTotal = mTotal - mValues[mInsertIndex] + aValue; - mValues[mInsertIndex] = aValue; - } else { - if (!mValues.append(aValue)) - return false; - mTotal = mTotal + aValue; +private: + size_t mInsertIndex; + size_t mMaxValues; + Vector mValues; + S mTotal; + +public: + static_assert(!IsFloatingPoint::value, + "floating-point types are unsupported due to rounding " + "errors"); + + explicit RollingMean(size_t aMaxValues) + : mInsertIndex(0), + mMaxValues(aMaxValues), + mTotal(0) + { + MOZ_ASSERT(aMaxValues > 0); + } + + RollingMean& operator=(RollingMean&& aOther) + { + MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); + this->~RollingMean(); + new(this) RollingMean(aOther.mMaxValues); + mInsertIndex = aOther.mInsertIndex; + mTotal = aOther.mTotal; + mValues.swap(aOther.mValues); + return *this; + } + + /** + * Insert a value into the rolling mean. + */ + bool insert(T aValue) + { + MOZ_ASSERT(mValues.length() <= mMaxValues); + + if (mValues.length() == mMaxValues) { + mTotal = mTotal - mValues[mInsertIndex] + aValue; + mValues[mInsertIndex] = aValue; + } else { + if (!mValues.append(aValue)) { + return false; } - - mInsertIndex = (mInsertIndex + 1) % mMaxValues; - return true; - } - - /** - * Calculate the rolling mean. - */ - T mean() { - MOZ_ASSERT(!empty()); - return T(mTotal / mValues.length()); - } - - bool empty() { - return mValues.empty(); + mTotal = mTotal + aValue; } - /** - * Remove all values from the rolling mean. - */ - void clear() { - mValues.clear(); - mInsertIndex = 0; - mTotal = T(0); - } - - size_t maxValues() { - return mMaxValues; - } + mInsertIndex = (mInsertIndex + 1) % mMaxValues; + return true; + } + + /** + * Calculate the rolling mean. + */ + T mean() + { + MOZ_ASSERT(!empty()); + return T(mTotal / mValues.length()); + } + + bool empty() + { + return mValues.empty(); + } + + /** + * Remove all values from the rolling mean. + */ + void clear() + { + mValues.clear(); + mInsertIndex = 0; + mTotal = T(0); + } + + size_t maxValues() + { + return mMaxValues; + } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/SHA1.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/SHA1.h index b167648540..ddccaa67e7 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/SHA1.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/SHA1.h @@ -36,25 +36,26 @@ namespace mozilla { */ class SHA1Sum { - union { - uint32_t w[16]; /* input buffer */ - uint8_t b[64]; - } u; - uint64_t size; /* count of hashed bytes. */ - unsigned H[22]; /* 5 state variables, 16 tmp values, 1 extra */ - bool mDone; - - public: - MFBT_API SHA1Sum(); - - static const size_t HashSize = 20; - typedef uint8_t Hash[HashSize]; - - /* Add len bytes of dataIn to the data sequence being hashed. */ - MFBT_API void update(const void* dataIn, uint32_t len); - - /* Compute the final hash of all data into hashOut. */ - MFBT_API void finish(SHA1Sum::Hash& hashOut); + union + { + uint32_t mW[16]; /* input buffer */ + uint8_t mB[64]; + } mU; + uint64_t mSize; /* count of hashed bytes. */ + unsigned mH[22]; /* 5 state variables, 16 tmp values, 1 extra */ + bool mDone; + +public: + MFBT_API SHA1Sum(); + + static const size_t kHashSize = 20; + typedef uint8_t Hash[kHashSize]; + + /* Add len bytes of dataIn to the data sequence being hashed. */ + MFBT_API void update(const void* aData, uint32_t aLength); + + /* Compute the final hash of all data into hashOut. */ + MFBT_API void finish(SHA1Sum::Hash& aHashOut); }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Scoped.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Scoped.h index fc48584b3e..3f854d6375 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Scoped.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Scoped.h @@ -52,8 +52,10 @@ * the scope, graphics contexts, etc. */ +#include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/GuardObjects.h" +#include "mozilla/Move.h" #include "mozilla/NullPtr.h" namespace mozilla { @@ -62,7 +64,8 @@ namespace mozilla { * Scoped is a helper to create RAII wrappers * Type argument |Traits| is expected to have the following structure: * - * struct Traits { + * struct Traits + * { * // Define the type of the value stored in the wrapper * typedef value_type type; * // Returns the value corresponding to the uninitialized or freed state @@ -75,84 +78,102 @@ namespace mozilla { template class Scoped { - public: - typedef typename Traits::type Resource; +public: + typedef typename Traits::type Resource; - explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) - : value(Traits::empty()) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - explicit Scoped(const Resource& v - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : value(v) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - ~Scoped() { - Traits::release(value); - } + explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + : mValue(Traits::empty()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } - // Constant getter - operator const Resource&() const { return value; } - const Resource& operator->() const { return value; } - const Resource& get() const { return value; } - // Non-constant getter. - Resource& rwget() { return value; } + explicit Scoped(const Resource& aValue + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(aValue) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } - /* - * Forget the resource. - * - * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will - * have no effect at destruction (unless it is reset to another resource by - * |operator=|). - * - * @return The original resource. - */ - Resource forget() { - Resource tmp = value; - value = Traits::empty(); - return tmp; - } + /* Move constructor. */ + explicit Scoped(Scoped&& aOther + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(Move(aOther.mValue)) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + aOther.mValue = Traits::empty(); + } - /* - * Perform immediate clean-up of this |Scoped|. - * - * If this |Scoped| is currently empty, this method has no effect. - */ - void dispose() { - Traits::release(value); - value = Traits::empty(); - } + ~Scoped() { Traits::release(mValue); } - bool operator==(const Resource& other) const { - return value == other; - } + // Constant getter + operator const Resource&() const { return mValue; } + const Resource& operator->() const { return mValue; } + const Resource& get() const { return mValue; } + // Non-constant getter. + Resource& rwget() { return mValue; } - /* - * Replace the resource with another resource. - * - * Calling |operator=| has the side-effect of triggering clean-up. If you do - * not want to trigger clean-up, you should first invoke |forget|. - * - * @return this - */ - Scoped& operator=(const Resource& other) { - return reset(other); - } - Scoped& reset(const Resource& other) { - Traits::release(value); - value = other; - return *this; - } + /* + * Forget the resource. + * + * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will + * have no effect at destruction (unless it is reset to another resource by + * |operator=|). + * + * @return The original resource. + */ + Resource forget() + { + Resource tmp = mValue; + mValue = Traits::empty(); + return tmp; + } + + /* + * Perform immediate clean-up of this |Scoped|. + * + * If this |Scoped| is currently empty, this method has no effect. + */ + void dispose() + { + Traits::release(mValue); + mValue = Traits::empty(); + } + + bool operator==(const Resource& aOther) const { return mValue == aOther; } + + /* + * Replace the resource with another resource. + * + * Calling |operator=| has the side-effect of triggering clean-up. If you do + * not want to trigger clean-up, you should first invoke |forget|. + * + * @return this + */ + Scoped& operator=(const Resource& aOther) { return reset(aOther); } + + Scoped& reset(const Resource& aOther) + { + Traits::release(mValue); + mValue = aOther; + return *this; + } + + /* Move assignment operator. */ + Scoped& operator=(Scoped&& aRhs) + { + MOZ_ASSERT(&aRhs != this, "self-move-assignment not allowed"); + this->~Scoped(); + new(this) Scoped(Move(aRhs)); + return *this; + } - private: - explicit Scoped(const Scoped& value) MOZ_DELETE; - Scoped& operator=(const Scoped& value) MOZ_DELETE; +private: + explicit Scoped(const Scoped& aValue) MOZ_DELETE; + Scoped& operator=(const Scoped& aValue) MOZ_DELETE; - private: - Resource value; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +private: + Resource mValue; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER }; /* @@ -163,26 +184,38 @@ class Scoped * @param Traits A struct implementing clean-up. See the implementations * for more details. */ -#define SCOPED_TEMPLATE(name, Traits) \ -template \ -struct name : public mozilla::Scoped > \ -{ \ - typedef mozilla::Scoped > Super; \ - typedef typename Super::Resource Resource; \ - name& operator=(Resource ptr) { \ - Super::operator=(ptr); \ - return *this; \ - } \ - explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ - : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ - {} \ - explicit name(Resource ptr \ - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ - : Super(ptr MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ - {} \ - private: \ - explicit name(name& source) MOZ_DELETE; \ - name& operator=(name& source) MOZ_DELETE; \ +#define SCOPED_TEMPLATE(name, Traits) \ +template \ +struct name : public mozilla::Scoped > \ +{ \ + typedef mozilla::Scoped > Super; \ + typedef typename Super::Resource Resource; \ + name& operator=(Resource aRhs) \ + { \ + Super::operator=(aRhs); \ + return *this; \ + } \ + name& operator=(name&& aRhs) \ + { \ + Super::operator=(Move(aRhs)); \ + return *this; \ + } \ + explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ + : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ + {} \ + explicit name(Resource aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ + explicit name(name&& aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(Move(aRhs) \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ +private: \ + explicit name(name&) MOZ_DELETE; \ + name& operator=(name&) MOZ_DELETE; \ }; /* @@ -195,9 +228,9 @@ struct name : public mozilla::Scoped > \ template struct ScopedFreePtrTraits { - typedef T* type; - static T* empty() { return nullptr; } - static void release(T* ptr) { free(ptr); } + typedef T* type; + static T* empty() { return nullptr; } + static void release(T* aPtr) { free(aPtr); } }; SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) @@ -210,7 +243,7 @@ SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) template struct ScopedDeletePtrTraits : public ScopedFreePtrTraits { - static void release(T* ptr) { delete ptr; } + static void release(T* aPtr) { delete aPtr; } }; SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) @@ -223,7 +256,7 @@ SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) template struct ScopedDeleteArrayTraits : public ScopedFreePtrTraits { - static void release(T* ptr) { delete [] ptr; } + static void release(T* aPtr) { delete [] aPtr; } }; SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) @@ -250,21 +283,22 @@ SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) * } // file is closed with PR_Close here */ #define MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(name, Type, Deleter) \ -template <> inline void TypeSpecificDelete(Type * value) { Deleter(value); } \ +template <> inline void TypeSpecificDelete(Type* aValue) { Deleter(aValue); } \ typedef ::mozilla::TypeSpecificScopedPointer name; -template void TypeSpecificDelete(T * value); +template void TypeSpecificDelete(T* aValue); template struct TypeSpecificScopedPointerTraits { - typedef T* type; - const static type empty() { return nullptr; } - const static void release(type value) - { - if (value) - TypeSpecificDelete(value); + typedef T* type; + static type empty() { return nullptr; } + static void release(type aValue) + { + if (aValue) { + TypeSpecificDelete(aValue); } + } }; SCOPED_TEMPLATE(TypeSpecificScopedPointer, TypeSpecificScopedPointerTraits) diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/SplayTree.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/SplayTree.h index 58ba5432b6..a6d692266f 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/SplayTree.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/SplayTree.h @@ -23,18 +23,20 @@ class SplayTree; template class SplayTreeNode { - public: - template - friend class SplayTree; - - SplayTreeNode() - : left(nullptr), right(nullptr), parent(nullptr) - {} - - private: - T* left; - T* right; - T* parent; +public: + template + friend class SplayTree; + + SplayTreeNode() + : mLeft(nullptr) + , mRight(nullptr) + , mParent(nullptr) + {} + +private: + T* mLeft; + T* mRight; + T* mParent; }; @@ -51,232 +53,242 @@ class SplayTreeNode template class SplayTree { - T* root; - T* freeList; + T* mRoot; - public: - SplayTree() - : root(nullptr), freeList(nullptr) - {} - - bool empty() const { - return !root; - } +public: + SplayTree() + : mRoot(nullptr) + {} - T* find(const T& v) - { - if (empty()) - return nullptr; + bool empty() const + { + return !mRoot; + } - T* last = lookup(v); - splay(last); - checkCoherency(root, nullptr); - return Comparator::compare(v, *last) == 0 ? last : nullptr; + T* find(const T& aValue) + { + if (empty()) { + return nullptr; } - bool insert(T* v) - { - MOZ_ASSERT(!find(*v), "Duplicate elements are not allowed."); - - if (!root) { - root = v; - return true; - } - T* last = lookup(*v); - int cmp = Comparator::compare(*v, *last); + T* last = lookup(aValue); + splay(last); + checkCoherency(mRoot, nullptr); + return Comparator::compare(aValue, *last) == 0 ? last : nullptr; + } - T** parentPointer = (cmp < 0) ? &last->left : &last->right; - MOZ_ASSERT(!*parentPointer); - *parentPointer = v; - v->parent = last; + bool insert(T* aValue) + { + MOZ_ASSERT(!find(*aValue), "Duplicate elements are not allowed."); - splay(v); - checkCoherency(root, nullptr); + if (!mRoot) { + mRoot = aValue; return true; } - - T* remove(const T& v) - { - T* last = lookup(v); - MOZ_ASSERT(last, "This tree must contain the element being removed."); - MOZ_ASSERT(Comparator::compare(v, *last) == 0); - - // Splay the tree so that the item to remove is the root. - splay(last); - MOZ_ASSERT(last == root); - - // Find another node which can be swapped in for the root: either the - // rightmost child of the root's left, or the leftmost child of the - // root's right. - T* swap; - T* swapChild; - if (root->left) { - swap = root->left; - while (swap->right) - swap = swap->right; - swapChild = swap->left; - } else if (root->right) { - swap = root->right; - while (swap->left) - swap = swap->left; - swapChild = swap->right; - } else { - T* result = root; - root = nullptr; - return result; - } - - // The selected node has at most one child, in swapChild. Detach it - // from the subtree by replacing it with that child. - if (swap == swap->parent->left) - swap->parent->left = swapChild; - else - swap->parent->right = swapChild; - if (swapChild) - swapChild->parent = swap->parent; - - // Make the selected node the new root. - root = swap; - root->parent = nullptr; - root->left = last->left; - root->right = last->right; - if (root->left) { - root->left->parent = root; + T* last = lookup(*aValue); + int cmp = Comparator::compare(*aValue, *last); + + T** parentPointer = (cmp < 0) ? &last->mLeft : &last->mRight; + MOZ_ASSERT(!*parentPointer); + *parentPointer = aValue; + aValue->mParent = last; + + splay(aValue); + checkCoherency(mRoot, nullptr); + return true; + } + + T* remove(const T& aValue) + { + T* last = lookup(aValue); + MOZ_ASSERT(last, "This tree must contain the element being removed."); + MOZ_ASSERT(Comparator::compare(aValue, *last) == 0); + + // Splay the tree so that the item to remove is the root. + splay(last); + MOZ_ASSERT(last == mRoot); + + // Find another node which can be swapped in for the root: either the + // rightmost child of the root's left, or the leftmost child of the + // root's right. + T* swap; + T* swapChild; + if (mRoot->mLeft) { + swap = mRoot->mLeft; + while (swap->mRight) { + swap = swap->mRight; } - if (root->right) { - root->right->parent = root; + swapChild = swap->mLeft; + } else if (mRoot->mRight) { + swap = mRoot->mRight; + while (swap->mLeft) { + swap = swap->mLeft; } - - checkCoherency(root, nullptr); - return last; + swapChild = swap->mRight; + } else { + T* result = mRoot; + mRoot = nullptr; + return result; } - T* removeMin() - { - MOZ_ASSERT(root, "No min to remove!"); - - T* min = root; - while (min->left) - min = min->left; - return remove(*min); + // The selected node has at most one child, in swapChild. Detach it + // from the subtree by replacing it with that child. + if (swap == swap->mParent->mLeft) { + swap->mParent->mLeft = swapChild; + } else { + swap->mParent->mRight = swapChild; } - - private: - /** - * Returns the node in this comparing equal to |v|, or a node just greater or - * just less than |v| if there is no such node. - */ - T* lookup(const T& v) - { - MOZ_ASSERT(!empty()); - - T* node = root; - T* parent; - do { - parent = node; - int c = Comparator::compare(v, *node); - if (c == 0) - return node; - else if (c < 0) - node = node->left; - else - node = node->right; - } while (node); - return parent; + if (swapChild) { + swapChild->mParent = swap->mParent; } - /** - * Rotate the tree until |node| is at the root of the tree. Performing - * the rotations in this fashion preserves the amortized balancing of - * the tree. - */ - void splay(T* node) - { - MOZ_ASSERT(node); - - while (node != root) { - T* parent = node->parent; - if (parent == root) { - // Zig rotation. - rotate(node); - MOZ_ASSERT(node == root); - return; - } - T* grandparent = parent->parent; - if ((parent->left == node) == (grandparent->left == parent)) { - // Zig-zig rotation. - rotate(parent); - rotate(node); - } else { - // Zig-zag rotation. - rotate(node); - rotate(node); - } - } + // Make the selected node the new root. + mRoot = swap; + mRoot->mParent = nullptr; + mRoot->mLeft = last->mLeft; + mRoot->mRight = last->mRight; + if (mRoot->mLeft) { + mRoot->mLeft->mParent = mRoot; } + if (mRoot->mRight) { + mRoot->mRight->mParent = mRoot; + } + + checkCoherency(mRoot, nullptr); + return last; + } - void rotate(T* node) - { - // Rearrange nodes so that node becomes the parent of its current - // parent, while preserving the sortedness of the tree. - T* parent = node->parent; - if (parent->left == node) { - // x y - // y c ==> a x - // a b b c - parent->left = node->right; - if (node->right) - node->right->parent = parent; - node->right = parent; + T* removeMin() + { + MOZ_ASSERT(mRoot, "No min to remove!"); + + T* min = mRoot; + while (min->mLeft) { + min = min->mLeft; + } + return remove(*min); + } + +private: + /** + * Returns the node in this comparing equal to |aValue|, or a node just + * greater or just less than |aValue| if there is no such node. + */ + T* lookup(const T& aValue) + { + MOZ_ASSERT(!empty()); + + T* node = mRoot; + T* parent; + do { + parent = node; + int c = Comparator::compare(aValue, *node); + if (c == 0) { + return node; + } else if (c < 0) { + node = node->mLeft; } else { - MOZ_ASSERT(parent->right == node); - // x y - // a y ==> x c - // b c a b - parent->right = node->left; - if (node->left) - node->left->parent = parent; - node->left = parent; + node = node->mRight; } - node->parent = parent->parent; - parent->parent = node; - if (T* grandparent = node->parent) { - if (grandparent->left == parent) - grandparent->left = node; - else - grandparent->right = node; + } while (node); + return parent; + } + + /** + * Rotate the tree until |node| is at the root of the tree. Performing + * the rotations in this fashion preserves the amortized balancing of + * the tree. + */ + void splay(T* aNode) + { + MOZ_ASSERT(aNode); + + while (aNode != mRoot) { + T* parent = aNode->mParent; + if (parent == mRoot) { + // Zig rotation. + rotate(aNode); + MOZ_ASSERT(aNode == mRoot); + return; + } + T* grandparent = parent->mParent; + if ((parent->mLeft == aNode) == (grandparent->mLeft == parent)) { + // Zig-zig rotation. + rotate(parent); + rotate(aNode); } else { - root = node; + // Zig-zag rotation. + rotate(aNode); + rotate(aNode); } } - - T* checkCoherency(T* node, T* minimum) - { -#ifdef DEBUG - MOZ_ASSERT_IF(root, !root->parent); - if (!node) { - MOZ_ASSERT(!root); - return nullptr; + } + + void rotate(T* aNode) + { + // Rearrange nodes so that aNode becomes the parent of its current + // parent, while preserving the sortedness of the tree. + T* parent = aNode->mParent; + if (parent->mLeft == aNode) { + // x y + // y c ==> a x + // a b b c + parent->mLeft = aNode->mRight; + if (aNode->mRight) { + aNode->mRight->mParent = parent; } - MOZ_ASSERT_IF(!node->parent, node == root); - MOZ_ASSERT_IF(minimum, Comparator::compare(*minimum, *node) < 0); - if (node->left) { - MOZ_ASSERT(node->left->parent == node); - T* leftMaximum = checkCoherency(node->left, minimum); - MOZ_ASSERT(Comparator::compare(*leftMaximum, *node) < 0); + aNode->mRight = parent; + } else { + MOZ_ASSERT(parent->mRight == aNode); + // x y + // a y ==> x c + // b c a b + parent->mRight = aNode->mLeft; + if (aNode->mLeft) { + aNode->mLeft->mParent = parent; } - if (node->right) { - MOZ_ASSERT(node->right->parent == node); - return checkCoherency(node->right, node); + aNode->mLeft = parent; + } + aNode->mParent = parent->mParent; + parent->mParent = aNode; + if (T* grandparent = aNode->mParent) { + if (grandparent->mLeft == parent) { + grandparent->mLeft = aNode; + } else { + grandparent->mRight = aNode; } - return node; -#else + } else { + mRoot = aNode; + } + } + + T* checkCoherency(T* aNode, T* aMinimum) + { +#ifdef DEBUG + MOZ_ASSERT_IF(mRoot, !mRoot->mParent); + if (!aNode) { + MOZ_ASSERT(!mRoot); return nullptr; -#endif } + MOZ_ASSERT_IF(!aNode->mParent, aNode == mRoot); + MOZ_ASSERT_IF(aMinimum, Comparator::compare(*aMinimum, *aNode) < 0); + if (aNode->mLeft) { + MOZ_ASSERT(aNode->mLeft->mParent == aNode); + T* leftMaximum = checkCoherency(aNode->mLeft, aMinimum); + MOZ_ASSERT(Comparator::compare(*leftMaximum, *aNode) < 0); + } + if (aNode->mRight) { + MOZ_ASSERT(aNode->mRight->mParent == aNode); + return checkCoherency(aNode->mRight, aNode); + } + return aNode; +#else + return nullptr; +#endif + } - SplayTree(const SplayTree&) MOZ_DELETE; - void operator=(const SplayTree&) MOZ_DELETE; + SplayTree(const SplayTree&) MOZ_DELETE; + void operator=(const SplayTree&) MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TaggedAnonymousMemory.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TaggedAnonymousMemory.h new file mode 100644 index 0000000000..d26b06dfb4 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TaggedAnonymousMemory.h @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Some Linux kernels -- specifically, newer versions of Android and +// some B2G devices -- have a feature for assigning names to ranges of +// anonymous memory (i.e., memory that doesn't have a "name" in the +// form of an underlying mapped file). These names are reported in +// /proc//smaps alongside system-level memory usage information +// such as Proportional Set Size (memory usage adjusted for sharing +// between processes), which allows reporting this information at a +// finer granularity than would otherwise be possible (e.g., +// separating malloc() heap from JS heap). +// +// Existing memory can be tagged with MozTagAnonymousMemory(); it will +// tag the range of complete pages containing the given interval, so +// the results may be inexact if the range isn't page-aligned. +// MozTaggedAnonymousMmap() can be used like mmap() with an extra +// parameter, and will tag the returned memory if the mapping was +// successful (and if it was in fact anonymous). +// +// NOTE: The pointer given as the "tag" argument MUST remain valid as +// long as the mapping exists. The referenced string is read when +// /proc//smaps or /proc//maps is read, not when the tag is +// established, so freeing it or changing its contents will have +// unexpected results. Using a static string is probably best. +// +// Also note that this header can be used by both C and C++ code. + +#ifndef mozilla_TaggedAnonymousMemory_h +#define mozilla_TaggedAnonymousMemory_h + +#ifndef XP_WIN + +#include +#include + +#include "mozilla/Types.h" + +#ifdef ANDROID + +#ifdef __cplusplus +extern "C" { +#endif + +MFBT_API void +MozTagAnonymousMemory(const void* aPtr, size_t aLength, const char* aTag); + +MFBT_API void* +MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt, int aFlags, + int aFd, off_t aOffset, const char* aTag); + +MFBT_API int +MozTaggedMemoryIsSupported(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#else // ANDROID + +static inline void +MozTagAnonymousMemory(const void* aPtr, size_t aLength, const char* aTag) +{ +} + +static inline void* +MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt, int aFlags, + int aFd, off_t aOffset, const char* aTag) +{ + return mmap(aAddr, aLength, aProt, aFlags, aFd, aOffset); +} + +static inline int +MozTaggedMemoryIsSupported(void) +{ + return 0; +} + +#endif // ANDROID + +#endif // !XP_WIN + +#endif // mozilla_TaggedAnonymousMemory_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TemplateLib.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TemplateLib.h index 50275fdadb..ea12c18b2b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TemplateLib.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TemplateLib.h @@ -28,19 +28,19 @@ namespace tl { template struct Min { - static const size_t value = I < J ? I : J; + static const size_t value = I < J ? I : J; }; template struct Max { - static const size_t value = I > J ? I : J; + static const size_t value = I > J ? I : J; }; /** Compute floor(log2(i)). */ template struct FloorLog2 { - static const size_t value = 1 + FloorLog2::value; + static const size_t value = 1 + FloorLog2::value; }; template<> struct FloorLog2<0> { /* Error */ }; template<> struct FloorLog2<1> { static const size_t value = 0; }; @@ -49,26 +49,26 @@ template<> struct FloorLog2<1> { static const size_t value = 0; }; template struct CeilingLog2 { - static const size_t value = FloorLog2<2 * I - 1>::value; + static const size_t value = FloorLog2<2 * I - 1>::value; }; /** Round up to the nearest power of 2. */ template struct RoundUpPow2 { - static const size_t value = size_t(1) << CeilingLog2::value; + static const size_t value = size_t(1) << CeilingLog2::value; }; template<> struct RoundUpPow2<0> { - static const size_t value = 1; + static const size_t value = 1; }; /** Compute the number of bits in the given unsigned type. */ template struct BitSize { - static const size_t value = sizeof(T) * CHAR_BIT; + static const size_t value = sizeof(T) * CHAR_BIT; }; /** @@ -78,17 +78,18 @@ struct BitSize template struct NBitMask { - // Assert the precondition. On success this evaluates to 0. Otherwise it - // triggers divide-by-zero at compile time: a guaranteed compile error in - // C++11, and usually one in C++98. Add this value to |value| to assure - // its computation. - static const size_t checkPrecondition = 0 / size_t(N < BitSize::value); - static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; + // Assert the precondition. On success this evaluates to 0. Otherwise it + // triggers divide-by-zero at compile time: a guaranteed compile error in + // C++11, and usually one in C++98. Add this value to |value| to assure + // its computation. + static const size_t checkPrecondition = + 0 / size_t(N < BitSize::value); + static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; }; template<> struct NBitMask::value> { - static const size_t value = size_t(-1); + static const size_t value = size_t(-1); }; /** @@ -98,8 +99,8 @@ struct NBitMask::value> template struct MulOverflowMask { - static const size_t value = - ~NBitMask::value - CeilingLog2::value>::value; + static const size_t value = + ~NBitMask::value - CeilingLog2::value>::value; }; template<> struct MulOverflowMask<0> { /* Error */ }; template<> struct MulOverflowMask<1> { static const size_t value = 0; }; diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ThreadLocal.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ThreadLocal.h index 6df109821f..28015de22e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ThreadLocal.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ThreadLocal.h @@ -54,7 +54,10 @@ typedef sig_atomic_t sig_safe_t; * * API usage: * - * // Create a TLS item + * // Create a TLS item. + * // + * // Note that init() should be invoked exactly once, before any usage of set() + * // or get(). * mozilla::ThreadLocal tlsKey; * if (!tlsKey.init()) { * // deal with the error @@ -70,30 +73,29 @@ template class ThreadLocal { #if defined(XP_WIN) - typedef unsigned long key_t; + typedef unsigned long key_t; #else - typedef pthread_key_t key_t; + typedef pthread_key_t key_t; #endif - union Helper { - void* ptr; - T value; - }; + union Helper + { + void* mPtr; + T mValue; + }; - public: - MOZ_WARN_UNUSED_RESULT inline bool init(); +public: + MOZ_WARN_UNUSED_RESULT inline bool init(); - inline T get() const; + inline T get() const; - inline void set(const T value); + inline void set(const T aValue); - bool initialized() const { - return inited; - } + bool initialized() const { return mInited; } - private: - key_t key; - bool inited; +private: + key_t mKey; + bool mInited; }; template @@ -105,12 +107,12 @@ ThreadLocal::init() "a pointer"); MOZ_ASSERT(!initialized()); #ifdef XP_WIN - key = TlsAlloc(); - inited = key != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES + mKey = TlsAlloc(); + mInited = mKey != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES #else - inited = !pthread_key_create(&key, nullptr); + mInited = !pthread_key_create(&mKey, nullptr); #endif - return inited; + return mInited; } template @@ -120,28 +122,28 @@ ThreadLocal::get() const MOZ_ASSERT(initialized()); Helper h; #ifdef XP_WIN - h.ptr = TlsGetValue(key); + h.mPtr = TlsGetValue(mKey); #else - h.ptr = pthread_getspecific(key); + h.mPtr = pthread_getspecific(mKey); #endif - return h.value; + return h.mValue; } template inline void -ThreadLocal::set(const T value) +ThreadLocal::set(const T aValue) { MOZ_ASSERT(initialized()); Helper h; - h.value = value; - bool succeeded; + h.mValue = aValue; #ifdef XP_WIN - succeeded = TlsSetValue(key, h.ptr); + bool succeeded = TlsSetValue(mKey, h.mPtr); #else - succeeded = !pthread_setspecific(key, h.ptr); + bool succeeded = !pthread_setspecific(mKey, h.mPtr); #endif - if (!succeeded) + if (!succeeded) { MOZ_CRASH(); + } } } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ToString.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ToString.h new file mode 100644 index 0000000000..f11cad5cb6 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/ToString.h @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Utilities for converting an object to a string representation. */ + +#ifndef mozilla_ToString_h +#define mozilla_ToString_h + +#include +#include + +namespace mozilla { + +/** + * A convenience function for converting an object to a string representation. + * Supports any object which can be streamed to an std::ostream. + */ +template +std::string +ToString(const T& aValue) +{ + std::ostringstream stream; + stream << aValue; + return stream.str(); +} + +} // namespace mozilla + +#endif /* mozilla_ToString_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TypeTraits.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TypeTraits.h index 1ccd0c85d1..515c68d94e 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TypeTraits.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TypeTraits.h @@ -9,6 +9,8 @@ #ifndef mozilla_TypeTraits_h #define mozilla_TypeTraits_h +#include "mozilla/Types.h" + /* * These traits are approximate copies of the traits and semantics from C++11's * header. Don't add traits not in that header! When all @@ -32,9 +34,9 @@ template struct RemoveCV; template struct IntegralConstant { - static const T value = Value; - typedef T ValueType; - typedef IntegralConstant Type; + static const T value = Value; + typedef T ValueType; + typedef IntegralConstant Type; }; /** Convenient aliases. */ @@ -47,6 +49,27 @@ typedef IntegralConstant FalseType; namespace detail { +template +struct IsVoidHelper : FalseType {}; + +template<> +struct IsVoidHelper : TrueType {}; + +} // namespace detail + +/** + * IsVoid determines whether a type is void. + * + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true; + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true. + */ +template +struct IsVoid : detail::IsVoidHelper::Type> {}; + +namespace detail { + template struct IsIntegralHelper : FalseType {}; @@ -114,6 +137,31 @@ struct IsFloatingPoint : detail::IsFloatingPointHelper::Type> {}; +namespace detail { + +template +struct IsArrayHelper : FalseType {}; + +template +struct IsArrayHelper : TrueType {}; + +template +struct IsArrayHelper : TrueType {}; + +} // namespace detail + +/** + * IsArray determines whether a type is an array type, of known or unknown + * length. + * + * mozilla::IsArray::value is false; + * mozilla::IsArray::value is true; + * mozilla::IsArray::value is true. + */ +template +struct IsArray : detail::IsArrayHelper::Type> +{}; + /** * IsPointer determines whether a type is a pointer type (but not a pointer-to- * member type). @@ -130,6 +178,40 @@ struct IsPointer : FalseType {}; template struct IsPointer : TrueType {}; +/** + * IsLvalueReference determines whether a type is an lvalue reference. + * + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is true; + * mozilla::IsLvalueReference::value is false. + */ +template +struct IsLvalueReference : FalseType {}; + +template +struct IsLvalueReference : TrueType {}; + +/** + * IsRvalueReference determines whether a type is an rvalue reference. + * + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is true. + */ +template +struct IsRvalueReference : FalseType {}; + +template +struct IsRvalueReference : TrueType {}; + namespace detail { // __is_enum is a supported extension across all of our supported compilers. @@ -152,8 +234,55 @@ struct IsEnum : detail::IsEnumHelper::Type> {}; +namespace detail { + +// __is_class is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx +template +struct IsClassHelper + : IntegralConstant +{}; + +} // namespace detail + +/** + * IsClass determines whether a type is a class type (but not a union). + * + * struct S {}; + * union U {}; + * mozilla::IsClass::value is false; + * mozilla::IsClass::value is true; + * mozilla::IsClass::value is false; + */ +template +struct IsClass + : detail::IsClassHelper::Type> +{}; + /* 20.9.4.2 Composite type traits [meta.unary.comp] */ +/** + * IsReference determines whether a type is an lvalue or rvalue reference. + * + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true. + */ +template +struct IsReference + : IntegralConstant::value || IsRvalueReference::value> +{}; + /** * IsArithmetic determines whether a type is arithmetic. A type is arithmetic * iff it is an integral type or a floating point type. @@ -228,26 +357,90 @@ template struct IsPod : TrueType {}; namespace detail { -template::value> -struct IsSignedHelper; - +// __is_empty is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx template -struct IsSignedHelper : TrueType {}; +struct IsEmptyHelper + : IntegralConstant::value && __is_empty(T)> +{}; +} // namespace detail + +/** + * IsEmpty determines whether a type is a class (but not a union) that is empty. + * + * A class is empty iff it and all its base classes have no non-static data + * members (except bit-fields of length 0) and no virtual member functions, and + * no base class is empty or a virtual base class. + * + * Intuitively, empty classes don't have any data that has to be stored in + * instances of those classes. (The size of the class must still be non-zero, + * because distinct array elements of any type must have different addresses. + * However, if the Empty Base Optimization is implemented by the compiler [most + * compilers implement it, and in certain cases C++11 requires it], the size of + * a class inheriting from an empty |Base| class need not be inflated by + * |sizeof(Base)|.) And intuitively, non-empty classes have data members and/or + * vtable pointers that must be stored in each instance for proper behavior. + * + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * union U1 { int x; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct E1 {}; + * struct E2 { int : 0 }; + * struct E3 : E1 {}; + * struct E4 : E2 {}; + * static_assert(mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value, + * "all empty"); + * union U2 { E1 e1; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct NE1 { int x; }; + * struct NE2 : virtual E1 {}; + * struct NE3 : E2 { virtual ~NE3() {} }; + * struct NE4 { virtual void f() {} }; + * static_assert(!mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value, + * "all empty"); + */ template -struct IsSignedHelper - : IntegralConstant::value && T(-1) < T(1)> +struct IsEmpty : detail::IsEmptyHelper::Type> {}; + +namespace detail { + +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> +struct IsSignedHelper; + +// Floating point is signed. +template +struct IsSignedHelper : TrueType {}; + +// Integral is conditionally signed. +template +struct IsSignedHelper + : IntegralConstant +{}; + +// Non-floating point, non-integral is not signed. +template +struct IsSignedHelper : FalseType {}; + } // namespace detail /** * IsSigned determines whether a type is a signed arithmetic type. |char| is * considered a signed type if it has the same representation as |signed char|. * - * Don't use this if the type might be user-defined! You might or might not get - * a compile error, depending. - * * mozilla::IsSigned::value is true; * mozilla::IsSigned::value is false; * mozilla::IsSigned::value is false; @@ -258,28 +451,32 @@ struct IsSigned : detail::IsSignedHelper {}; namespace detail { -template::value> +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> struct IsUnsignedHelper; -template -struct IsUnsignedHelper : FalseType {}; +// Floating point is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; -template -struct IsUnsignedHelper +// Integral is conditionally unsigned. +template +struct IsUnsignedHelper : IntegralConstant::value && - (IsSame::Type, bool>::value || - T(1) < T(-1))> + (IsSame::value || bool(NoCV(1) < NoCV(-1)))> {}; +// Non-floating point, non-integral is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; + } // namespace detail /** * IsUnsigned determines whether a type is an unsigned arithmetic type. * - * Don't use this if the type might be user-defined! You might or might not get - * a compile error, depending. - * * mozilla::IsUnsigned::value is false; * mozilla::IsUnsigned::value is true; * mozilla::IsUnsigned::value is true; @@ -310,6 +507,13 @@ struct IsSame : TrueType {}; namespace detail { +#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) + +template +struct BaseOfTester : IntegralConstant {}; + +#else + // The trickery used to implement IsBaseOf here makes it possible to use it for // the cases of private and multiple inheritance. This code was inspired by the // sample code here: @@ -318,35 +522,35 @@ namespace detail { template struct BaseOfHelper { - public: - operator Base*() const; - operator Derived*(); +public: + operator Base*() const; + operator Derived*(); }; template struct BaseOfTester { - private: - template - static char test(Derived*, T); - static int test(Base*, int); - - public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); }; template struct BaseOfTester { - private: - template - static char test(Derived*, T); - static int test(Base*, int); - - public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); }; template @@ -358,6 +562,8 @@ struct BaseOfTester : TrueType {}; template struct BaseOfTester : TrueType {}; +#endif + } /* namespace detail */ /* @@ -382,18 +588,18 @@ namespace detail { template struct ConvertibleTester { - private: - static From create(); +private: + static From create(); - template - static char test(To to); + template + static char test(To to); - template - static int test(...); + template + static int test(...); - public: - static const bool value = - sizeof(test(create())) == sizeof(char); +public: + static const bool value = + sizeof(test(create())) == sizeof(char); }; } // namespace detail @@ -424,16 +630,6 @@ struct IsConvertible : IntegralConstant::value> {}; -/** - * Is IsLvalueReference is true if its template param is T& and is false if - * its type is T or T&&. - */ -template -struct IsLvalueReference : FalseType {}; - -template -struct IsLvalueReference : TrueType {}; - /* 20.9.7 Transformations between types [meta.trans] */ /* 20.9.7.1 Const-volatile modifications [meta.trans.cv] */ @@ -449,13 +645,13 @@ struct IsLvalueReference : TrueType {}; template struct RemoveConst { - typedef T Type; + typedef T Type; }; template struct RemoveConst { - typedef T Type; + typedef T Type; }; /** @@ -469,13 +665,13 @@ struct RemoveConst template struct RemoveVolatile { - typedef T Type; + typedef T Type; }; template struct RemoveVolatile { - typedef T Type; + typedef T Type; }; /** @@ -489,7 +685,7 @@ struct RemoveVolatile template struct RemoveCV { - typedef typename RemoveConst::Type>::Type Type; + typedef typename RemoveConst::Type>::Type Type; }; /* 20.9.7.2 Reference modifications [meta.trans.ref] */ @@ -505,29 +701,69 @@ struct RemoveCV template struct RemoveReference { - typedef T Type; + typedef T Type; }; template struct RemoveReference { - typedef T Type; + typedef T Type; }; template struct RemoveReference { - typedef T Type; + typedef T Type; }; +template +struct Conditional; + +namespace detail { + +enum Voidness { TIsVoid, TIsNotVoid }; + +template::value ? TIsVoid : TIsNotVoid> +struct AddLvalueReferenceHelper; + +template +struct AddLvalueReferenceHelper +{ + typedef void Type; +}; + +template +struct AddLvalueReferenceHelper +{ + typedef T& Type; +}; + +} // namespace detail + +/** + * AddLvalueReference adds an lvalue & reference to T if one isn't already + * present. (Note: adding an lvalue reference to an rvalue && reference in + * essence replaces the && with a &&, per C+11 reference collapsing rules. For + * example, int&& would become int&.) + * + * The final computed type will only *not* be an lvalue reference if T is void. + * + * mozilla::AddLvalueReference::Type is int&; + * mozilla::AddLvalueRference::Type is volatile int&; + * mozilla::AddLvalueReference::Type is void*&; + * mozilla::AddLvalueReference::Type is void; + * mozilla::AddLvalueReference::Type is struct S&. + */ +template +struct AddLvalueReference + : detail::AddLvalueReferenceHelper +{}; + /* 20.9.7.3 Sign modifications [meta.trans.sign] */ template struct EnableIf; -template -struct Conditional; - namespace detail { template @@ -568,7 +804,7 @@ struct MakeSigned; template struct MakeSigned { - typedef T Type; + typedef T Type; }; template @@ -603,7 +839,8 @@ struct MakeSigned */ template struct MakeSigned - : EnableIf::value && !IsSame::Type>::value, + : EnableIf::value && + !IsSame::Type>::value, typename detail::MakeSigned >::Type {}; @@ -636,7 +873,7 @@ struct MakeUnsigned; template struct MakeUnsigned { - typedef T Type; + typedef T Type; }; template @@ -671,13 +908,41 @@ struct MakeUnsigned */ template struct MakeUnsigned - : EnableIf::value && !IsSame::Type>::value, + : EnableIf::value && + !IsSame::Type>::value, typename detail::MakeUnsigned >::Type {}; /* 20.9.7.4 Array modifications [meta.trans.arr] */ +/** + * RemoveExtent produces either the type of the elements of the array T, or T + * itself. + * + * mozilla::RemoveExtent::Type is int; + * mozilla::RemoveExtent::Type is const int; + * mozilla::RemoveExtent::Type is volatile int; + * mozilla::RemoveExtent::Type is long[17]. + */ +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + /* 20.9.7.5 Pointer modifications [meta.trans.ptr] */ /* 20.9.7.6 Other transformations [meta.trans.other] */ @@ -707,7 +972,7 @@ struct EnableIf template struct EnableIf { - typedef T Type; + typedef T Type; }; /** @@ -719,13 +984,13 @@ struct EnableIf template struct Conditional { - typedef A Type; + typedef A Type; }; template struct Conditional { - typedef B Type; + typedef B Type; }; } /* namespace mozilla */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TypedEnum.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TypedEnum.h index e55365abb8..d84cd90257 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TypedEnum.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TypedEnum.h @@ -9,39 +9,11 @@ #ifndef mozilla_TypedEnum_h #define mozilla_TypedEnum_h -#include "mozilla/Attributes.h" +#include "mozilla/TypedEnumInternal.h" +#include "mozilla/MacroArgs.h" #if defined(__cplusplus) -#if defined(__clang__) - /* - * Per Clang documentation, "Note that marketing version numbers should not - * be used to check for language features, as different vendors use different - * numbering schemes. Instead, use the feature checking macros." - */ -# ifndef __has_extension -# define __has_extension __has_feature /* compatibility, for older versions of clang */ -# endif -# if __has_extension(cxx_strong_enums) -# define MOZ_HAVE_CXX11_ENUM_TYPE -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -#elif defined(__GNUC__) -# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L -# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3) -# define MOZ_HAVE_CXX11_ENUM_TYPE -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -# endif -#elif defined(_MSC_VER) -# if _MSC_VER >= 1400 -# define MOZ_HAVE_CXX11_ENUM_TYPE -# endif -# if _MSC_VER >= 1700 -# define MOZ_HAVE_CXX11_STRONG_ENUMS -# endif -#endif - /** * MOZ_ENUM_TYPE specifies the underlying numeric type for an enum. It's * specified by placing MOZ_ENUM_TYPE(type) immediately after the enum name in @@ -97,13 +69,12 @@ * in namespace scope to handle bits that can only be implemented with * namespace-scoped code. For example: * - * class FooBar { - * + * class FooBar + * { * MOZ_BEGIN_NESTED_ENUM_CLASS(Enum, int32_t) * A, * B = 6 * MOZ_END_NESTED_ENUM_CLASS(Enum) - * * }; * * MOZ_FINISH_NESTED_ENUM_CLASS(FooBar::Enum) @@ -131,6 +102,10 @@ * these are already integer types so there is nothing more to do. */ # define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name + /* + * See the comment below about MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) Name #else /** * We need Name to both name a type, and scope the provided enumerator @@ -172,24 +147,28 @@ # define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER1(Name) \ class Name \ { \ - public: \ - enum Enum \ - { + public: \ + enum Enum \ + { /* Two-argument form. */ # define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER2(Name, type) \ class Name \ { \ - public: \ - enum Enum MOZ_ENUM_TYPE(type) \ - { + public: \ + enum Enum MOZ_ENUM_TYPE(type) \ + { # define MOZ_END_NESTED_ENUM_CLASS(Name) \ - }; \ - Name() {} \ - Name(Enum aEnum) : mEnum(aEnum) {} \ - explicit Name(int num) : mEnum((Enum)num) {} \ - operator Enum() const { return mEnum; } \ - private: \ - Enum mEnum; \ + }; \ + Name() {} \ + MOZ_CONSTEXPR Name(Enum aEnum) : mEnum(aEnum) {} \ + template \ + explicit MOZ_CONSTEXPR Name(Other num) : mEnum((Enum)num) {} \ + MOZ_CONSTEXPR operator Enum() const { return mEnum; } \ + explicit MOZ_CONSTEXPR Name(const mozilla::CastableTypedEnumResult& aOther) \ + : mEnum(aOther.get()) \ + {} \ + private: \ + Enum mEnum; \ }; # define MOZ_FINISH_NESTED_ENUM_CLASS(Name) \ inline int operator+(const int&, const Name::Enum&) MOZ_DELETE; \ @@ -225,7 +204,6 @@ inline bool operator&&(const Name::Enum&, const bool&) MOZ_DELETE; \ inline bool operator||(const bool&, const Name::Enum&) MOZ_DELETE; \ inline bool operator||(const Name::Enum&, const bool&) MOZ_DELETE; \ - inline int operator~(const Name::Enum&) MOZ_DELETE; \ inline int operator&(const int&, const Name::Enum&) MOZ_DELETE; \ inline int operator&(const Name::Enum&, const int&) MOZ_DELETE; \ inline int operator|(const int&, const Name::Enum&) MOZ_DELETE; \ @@ -253,35 +231,45 @@ * In the present case, the integer type is the Enum nested type. */ # define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name::Enum + /* + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is a variant of MOZ_ENUM_CLASS_ENUM_TYPE + * to be used when the enum class at hand depends on template parameters. + * + * Indeed, if T depends on template parameters, in order to name a nested type + * in T, C++ does not allow to just write "T::NestedType". Instead, we have + * to write "typename T::NestedType". The role of this macro is to add + * this "typename" keywords where needed. + * + * Example: + * + * template + * struct S {}; + * + * MOZ_BEGIN_ENUM_CLASS(E) + * Foo, + * Bar + * MOZ_END_ENUM_CLASS(E) + * + * S s; + * + * In this example, the second template parameter to S is meant to be of type + * T, but on non-C++11 compilers, type T is a class type, not an integer + * type, so it is not accepted as the type of a constant template parameter. + * One would then want to use MOZ_ENUM_CLASS_ENUM_TYPE(T), but that doesn't + * work either as T depends on template parameters (more specifically here, T + * _is_ a template parameter) so as MOZ_ENUM_CLASS_ENUM_TYPE(T) expands to + * T::Enum, we are missing the required "typename" keyword. So here, + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is needed. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) typename Name::Enum #endif - /* - * Count the number of arguments passed to MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS, - * very carefully tiptoeing around an MSVC bug where it improperly expands - * __VA_ARGS__ as a single token in argument lists. See these URLs for - * details: - * - * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement - * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 - */ -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL2(_1, _2, count, ...) \ - count -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL(args) \ - MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL2 args -# define MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS(...) \ - MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS_IMPL((__VA_ARGS__, 2, 1, 0)) - /* Pick the right helper macro to invoke. */ -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER2(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER##count -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER1(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER2(count) -# define MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER(count) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER1(count) - /* The actual macro. */ -# define MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(x, y) x y +# define MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(a, b) a b # define MOZ_BEGIN_NESTED_ENUM_CLASS(...) \ - MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(MOZ_BEGIN_NESTED_ENUM_CLASS_CHOOSE_HELPER(MOZ_COUNT_BEGIN_ENUM_CLASS_ARGS(__VA_ARGS__)), \ - (__VA_ARGS__)) + MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER, \ + __VA_ARGS__), \ + (__VA_ARGS__)) # define MOZ_BEGIN_ENUM_CLASS(...) MOZ_BEGIN_NESTED_ENUM_CLASS(__VA_ARGS__) # define MOZ_END_ENUM_CLASS(Name) \ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TypedEnumBits.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TypedEnumBits.h new file mode 100644 index 0000000000..1f439f1239 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TypedEnumBits.h @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS allows using a typed enum as bit flags. + */ + +#ifndef mozilla_TypedEnumBits_h +#define mozilla_TypedEnumBits_h + +#include "mozilla/IntegerTypeTraits.h" +#include "mozilla/TypedEnumInternal.h" + +namespace mozilla { + +#define MOZ_CASTABLETYPEDENUMRESULT_BINOP(Op, OtherType, ReturnType) \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const OtherType& aE, const CastableTypedEnumResult& aR) \ +{ \ + return ReturnType(aE Op OtherType(aR)); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR, const OtherType& aE) \ +{ \ + return ReturnType(OtherType(aR) Op aE); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR1, \ + const CastableTypedEnumResult& aR2) \ +{ \ + return ReturnType(OtherType(aR1) Op OtherType(aR2)); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_BINOP(|, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(&, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(^, E, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(==, E, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(!=, E, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(||, bool, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP(&&, bool, bool) + +template +MOZ_CONSTEXPR CastableTypedEnumResult +operator ~(const CastableTypedEnumResult& aR) +{ + return CastableTypedEnumResult(~(E(aR))); +} + +#define MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(Op) \ +template \ +E& \ +operator Op(E& aR1, \ + const CastableTypedEnumResult& aR2) \ +{ \ + return aR1 Op E(aR2); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(&=) +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(|=) +MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(^=) + +#undef MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP + +#undef MOZ_CASTABLETYPEDENUMRESULT_BINOP + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS + +#define MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(Op, ReturnType) \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(typename E::Enum aE, const CastableTypedEnumResult& aR) \ +{ \ + return ReturnType(aE Op E(aR)); \ +} \ +template \ +MOZ_CONSTEXPR ReturnType \ +operator Op(const CastableTypedEnumResult& aR, typename E::Enum aE) \ +{ \ + return ReturnType(E(aR) Op aE); \ +} + +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(|, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(&, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(^, CastableTypedEnumResult) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(==, bool) +MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(!=, bool) + +#undef MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11 + +#endif // not MOZ_HAVE_CXX11_STRONG_ENUMS + +namespace detail { +template +struct UnsignedIntegerTypeForEnum + : UnsignedStdintTypeForSize +{}; +} + +} // namespace mozilla + +#define MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, Op) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name a, Name b) \ + { \ + typedef mozilla::CastableTypedEnumResult Result; \ + typedef mozilla::detail::UnsignedIntegerTypeForEnum::Type U; \ + return Result(Name(U(a) Op U(b))); \ + } \ + \ + inline Name& \ + operator Op##=(Name& a, Name b) \ + { \ + return a = a Op b; \ + } + +#define MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, |) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, &) \ + MOZ_MAKE_ENUM_CLASS_BINOP_IMPL(Name, ^) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator~(Name a) \ + { \ + typedef mozilla::CastableTypedEnumResult Result; \ + typedef mozilla::detail::UnsignedIntegerTypeForEnum::Type U; \ + return Result(Name(~(U(a)))); \ + } + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS +# define MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, Op) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name a, Name::Enum b) \ + { \ + return a Op Name(b); \ + } \ + \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name::Enum a, Name b) \ + { \ + return Name(a) Op b; \ + } \ + \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator Op(Name::Enum a, Name::Enum b) \ + { \ + return Name(a) Op Name(b); \ + } \ + \ + inline Name& \ + operator Op##=(Name& a, Name::Enum b) \ + { \ + return a = a Op Name(b); \ + } + +# define MOZ_MAKE_ENUM_CLASS_OPS_EXTRA_NON_CXX11(Name) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, |) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, &) \ + MOZ_MAKE_ENUM_CLASS_BITWISE_BINOP_EXTRA_NON_CXX11(Name, ^) \ + inline MOZ_CONSTEXPR mozilla::CastableTypedEnumResult \ + operator~(Name::Enum a) \ + { \ + return ~(Name(a)); \ + } +#endif + +/** + * MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS generates standard bitwise operators + * for the given enum type. Use this to enable using an enum type as bit-field. + */ +#ifdef MOZ_HAVE_CXX11_STRONG_ENUMS +# define MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) +#else +# define MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_IMPL(Name) \ + MOZ_MAKE_ENUM_CLASS_OPS_EXTRA_NON_CXX11(Name) +#endif + +#endif // mozilla_TypedEnumBits_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TypedEnumInternal.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TypedEnumInternal.h new file mode 100644 index 0000000000..8c88cb589b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/TypedEnumInternal.h @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Internal stuff needed by TypedEnum.h and TypedEnumBits.h. */ + +// NOTE: When we can assume C++11 enum class support and TypedEnum.h goes away, +// we should then consider folding TypedEnumInternal.h into TypedEnumBits.h. + +#ifndef mozilla_TypedEnumInternal_h +#define mozilla_TypedEnumInternal_h + +#include "mozilla/Attributes.h" + +#if defined(__cplusplus) + +#if defined(__clang__) + /* + * Per Clang documentation, "Note that marketing version numbers should not + * be used to check for language features, as different vendors use different + * numbering schemes. Instead, use the feature checking macros." + */ +# ifndef __has_extension +# define __has_extension __has_feature /* compatibility, for older versions of clang */ +# endif +# if __has_extension(cxx_strong_enums) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#elif defined(__GNUC__) +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +# endif +#elif defined(_MSC_VER) +# if _MSC_VER >= 1400 +# define MOZ_HAVE_CXX11_ENUM_TYPE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#endif + +namespace mozilla { + +/* + * The problem that CastableTypedEnumResult aims to solve is that + * typed enums are not convertible to bool, and there is no way to make them + * be, yet user code wants to be able to write + * + * if (myFlags & Flags::SOME_PARTICULAR_FLAG) (1) + * + * There are different approaches to solving this. Most of them require + * adapting user code. For example, we could implement operator! and have + * the user write + * + * if (!!(myFlags & Flags::SOME_PARTICULAR_FLAG)) (2) + * + * Or we could supply a IsNonZero() or Any() function returning whether + * an enum value is nonzero, and have the user write + * + * if (Any(Flags & Flags::SOME_PARTICULAR_FLAG)) (3) + * + * But instead, we choose to preserve the original user syntax (1) as it + * is inherently more readable, and to ease porting existing code to typed + * enums. We achieve this by having operator& and other binary bitwise + * operators have as return type a class, CastableTypedEnumResult, + * that wraps a typed enum but adds bool convertibility. + */ +template +class CastableTypedEnumResult +{ +private: + const E mValue; + +public: + explicit MOZ_CONSTEXPR CastableTypedEnumResult(E aValue) + : mValue(aValue) + {} + + MOZ_CONSTEXPR operator E() const { return mValue; } + + template + MOZ_EXPLICIT_CONVERSION MOZ_CONSTEXPR + operator DestinationType() const { return DestinationType(mValue); } + + MOZ_CONSTEXPR bool operator !() const { return !bool(mValue); } + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS + // This get() method is used to implement a constructor in the + // non-c++11 fallback path for MOZ_BEGIN_ENUM_CLASS, taking a + // CastableTypedEnumResult. If we try to implement it using the + // above conversion operator E(), then at least clang 3.3 + // (when forced to take the non-c++11 fallback path) compiles + // this constructor to an infinite recursion. So we introduce this + // get() method, that does exactly the same as the conversion operator, + // to work around this. + MOZ_CONSTEXPR E get() const { return mValue; } +#endif +}; + +} // namespace mozilla + +#endif // __cplusplus + +#endif // mozilla_TypedEnumInternal_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Types.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Types.h index 5340b2b600..e7e18abb27 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Types.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Types.h @@ -37,7 +37,7 @@ * These macros are designed for use by library interfaces -- not for normal * methods or data used cross-file. */ -#if defined(WIN32) || defined(XP_OS2) +#if defined(WIN32) # define MOZ_EXPORT __declspec(dllexport) #else /* Unix */ # ifdef HAVE_VISIBILITY_ATTRIBUTE @@ -63,16 +63,12 @@ # else # define MOZ_IMPORT_API __declspec(dllimport) # endif -#elif defined(XP_OS2) -# define MOZ_IMPORT_API __declspec(dllimport) #else # define MOZ_IMPORT_API MOZ_EXPORT #endif #if defined(_WIN32) && !defined(__MWERKS__) # define MOZ_IMPORT_DATA __declspec(dllimport) -#elif defined(XP_OS2) -# define MOZ_IMPORT_DATA __declspec(dllimport) #else # define MOZ_IMPORT_DATA MOZ_EXPORT #endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/UniquePtr.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/UniquePtr.h new file mode 100644 index 0000000000..9c873db90c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/UniquePtr.h @@ -0,0 +1,674 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Smart pointer managing sole ownership of a resource. */ + +#ifndef mozilla_UniquePtr_h +#define mozilla_UniquePtr_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/Pair.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +template class DefaultDelete; +template> class UniquePtr; + +} // namespace mozilla + +namespace mozilla { + +/** + * UniquePtr is a smart pointer that wholly owns a resource. Ownership may be + * transferred out of a UniquePtr through explicit action, but otherwise the + * resource is destroyed when the UniquePtr is destroyed. + * + * UniquePtr is similar to C++98's std::auto_ptr, but it improves upon auto_ptr + * in one crucial way: it's impossible to copy a UniquePtr. Copying an auto_ptr + * obviously *can't* copy ownership of its singly-owned resource. So what + * happens if you try to copy one? Bizarrely, ownership is implicitly + * *transferred*, preserving single ownership but breaking code that assumes a + * copy of an object is identical to the original. (This is why auto_ptr is + * prohibited in STL containers.) + * + * UniquePtr solves this problem by being *movable* rather than copyable. + * Instead of passing a |UniquePtr u| directly to the constructor or assignment + * operator, you pass |Move(u)|. In doing so you indicate that you're *moving* + * ownership out of |u|, into the target of the construction/assignment. After + * the transfer completes, |u| contains |nullptr| and may be safely destroyed. + * This preserves single ownership but also allows UniquePtr to be moved by + * algorithms that have been made move-safe. (Note: if |u| is instead a + * temporary expression, don't use |Move()|: just pass the expression, because + * it's already move-ready. For more information see Move.h.) + * + * UniquePtr is also better than std::auto_ptr in that the deletion operation is + * customizable. An optional second template parameter specifies a class that + * (through its operator()(T*)) implements the desired deletion policy. If no + * policy is specified, mozilla::DefaultDelete is used -- which will either + * |delete| or |delete[]| the resource, depending whether the resource is an + * array. Custom deletion policies ideally should be empty classes (no member + * fields, no member fields in base classes, no virtual methods/inheritance), + * because then UniquePtr can be just as efficient as a raw pointer. + * + * Use of UniquePtr proceeds like so: + * + * UniquePtr g1; // initializes to nullptr + * g1.reset(new int); // switch resources using reset() + * g1 = nullptr; // clears g1, deletes the int + * + * UniquePtr g2(new int); // owns that int + * int* p = g2.release(); // g2 leaks its int -- still requires deletion + * delete p; // now freed + * + * struct S { int x; S(int x) : x(x) {} }; + * UniquePtr g3, g4(new S(5)); + * g3 = Move(g4); // g3 owns the S, g4 cleared + * S* p = g3.get(); // g3 still owns |p| + * assert(g3->x == 5); // operator-> works (if .get() != nullptr) + * assert((*g3).x == 5); // also operator* (again, if not cleared) + * Swap(g3, g4); // g4 now owns the S, g3 cleared + * g3.swap(g4); // g3 now owns the S, g4 cleared + * UniquePtr g5(Move(g3)); // g5 owns the S, g3 cleared + * g5.reset(); // deletes the S, g5 cleared + * + * struct FreePolicy { void operator()(void* p) { free(p); } }; + * UniquePtr g6(static_cast(malloc(sizeof(int)))); + * int* ptr = g6.get(); + * g6 = nullptr; // calls free(ptr) + * + * Now, carefully note a few things you *can't* do: + * + * UniquePtr b1; + * b1 = new int; // BAD: can only assign another UniquePtr + * int* ptr = b1; // BAD: no auto-conversion to pointer, use get() + * + * UniquePtr b2(b1); // BAD: can't copy a UniquePtr + * UniquePtr b3 = b1; // BAD: can't copy-assign a UniquePtr + * + * A few miscellaneous notes: + * + * UniquePtr, when not instantiated for an array type, can be move-constructed + * and move-assigned, not only from itself but from "derived" UniquePtr + * instantiations where U converts to T and E converts to D. If you want to use + * this, you're going to have to specify a deletion policy for both UniquePtr + * instantations, and T pretty much has to have a virtual destructor. In other + * words, this doesn't work: + * + * struct Base { virtual ~Base() {} }; + * struct Derived : Base {}; + * + * UniquePtr b1; + * // BAD: DefaultDelete and DefaultDelete don't interconvert + * UniquePtr d1(Move(b)); + * + * UniquePtr b2; + * UniquePtr> d2(Move(b2)); // okay + * + * UniquePtr is specialized for array types. Specializing with an array type + * creates a smart-pointer version of that array -- not a pointer to such an + * array. + * + * UniquePtr arr(new int[5]); + * arr[0] = 4; + * + * What else is different? Deletion of course uses |delete[]|. An operator[] + * is provided. Functionality that doesn't make sense for arrays is removed. + * The constructors and mutating methods only accept array pointers (not T*, U* + * that converts to T*, or UniquePtr or UniquePtr) or |nullptr|. + * + * It's perfectly okay to return a UniquePtr from a method to assure the related + * resource is properly deleted. You'll need to use |Move()| when returning a + * local UniquePtr. Otherwise you can return |nullptr|, or you can return + * |UniquePtr(ptr)|. + * + * UniquePtr will commonly be a member of a class, with lifetime equivalent to + * that of that class. If you want to expose the related resource, you could + * expose a raw pointer via |get()|, but ownership of a raw pointer is + * inherently unclear. So it's better to expose a |const UniquePtr&| instead. + * This prohibits mutation but still allows use of |get()| when needed (but + * operator-> is preferred). Of course, you can only use this smart pointer as + * long as the enclosing class instance remains live -- no different than if you + * exposed the |get()| raw pointer. + * + * To pass a UniquePtr-managed resource as a pointer, use a |const UniquePtr&| + * argument. To specify an inout parameter (where the method may or may not + * take ownership of the resource, or reset it), or to specify an out parameter + * (where simply returning a |UniquePtr| isn't possible), use a |UniquePtr&| + * argument. To unconditionally transfer ownership of a UniquePtr + * into a method, use a |UniquePtr| argument. To conditionally transfer + * ownership of a resource into a method, should the method want it, use a + * |UniquePtr&&| argument. + */ +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + Pointer& ptr() { return tuple.first(); } + const Pointer& ptr() const { return tuple.first(); } + + DeleterType& del() { return tuple.second(); } + const DeleterType& del() const { return tuple.second(); } + + public: + /** + * Construct a UniquePtr containing |nullptr|. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! Ideally + // you should make deletion use the same function every time, using a + // deleter policy: + // + // // BAD, won't compile with MSVC10, deleter doesn't need to be a + // // variable at all + // typedef void (&FreeSignature)(void*); + // UniquePtr ptr((int*) malloc(sizeof(int)), free); + // + // // GOOD, compiles with MSVC10, deletion behavior statically known and + // // optimizable + // struct DeleteByFreeing + // { + // void operator()(void* ptr) { free(ptr); } + // }; + // + // If deletion really, truly, must be a variable: you might be able to work + // around this with a deleter class that contains the function reference. + // But this workaround is untried and untested, because variable deletion + // behavior really isn't something you should use. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + template + UniquePtr(UniquePtr&& other, + typename EnableIf::Pointer, + Pointer>::value && + !IsArray::value && + (IsReference::value + ? IsSame::value + : IsConvertible::value), + int>::Type dummy = 0) + : tuple(other.release(), Forward(other.getDeleter())) + { + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + template + UniquePtr& operator=(UniquePtr&& other) + { + static_assert(IsConvertible::Pointer, Pointer>::value, + "incompatible UniquePtr pointees"); + static_assert(!IsArray::value, + "can't assign from UniquePtr holding an array"); + + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT n) { + MOZ_ASSERT(n == nullptr); + reset(nullptr); + return *this; + } + + T& operator*() const { return *get(); } + Pointer operator->() const { + MOZ_ASSERT(get(), "dereferencing a UniquePtr containing nullptr"); + return get(); + } + + Pointer get() const { return ptr(); } + + DeleterType& getDeleter() { return del(); } + const DeleterType& getDeleter() const { return del(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = ptr(); + ptr() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = ptr(); + ptr() = p; + if (old != nullptr) + getDeleter()(old); + } + + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +// In case you didn't read the comment by the main definition (you should!): the +// UniquePtr specialization exists to manage array pointers. It deletes +// such pointers using delete[], it will reject construction and modification +// attempts using U* or U[]. Otherwise it works like the normal UniquePtr. +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + public: + /** + * Construct a UniquePtr containing nullptr. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + private: + // delete[] knows how to handle *only* an array of a single class type. For + // delete[] to work correctly, it must know the size of each element, the + // fields and base classes of each element requiring destruction, and so on. + // So forbid all overloads which would end up invoking delete[] on a pointer + // of the wrong type. + template + UniquePtr(U&& u, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! See the + // comment by this constructor in the non-T[] specialization above. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + private: + // Forbidden for the same reasons as stated above. + template + UniquePtr(U&& u, V&& v, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT) { + reset(); + return *this; + } + + T& operator[](decltype(sizeof(int)) i) const { return get()[i]; } + Pointer get() const { return tuple.first(); } + + DeleterType& getDeleter() { return tuple.second(); } + const DeleterType& getDeleter() const { return tuple.second(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = tuple.first(); + tuple.first() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = tuple.first(); + tuple.first() = p; + if (old != nullptr) + tuple.second()(old); + } + + private: + // Kill off all remaining overloads that aren't true nullptr (the overload + // above should handle that) or emulated nullptr (which acts like int/long + // on gcc 4.4/4.5). + template + void reset(U, + typename EnableIf::value && + !IsSame::Type>::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +/** A default deletion policy using plain old operator delete. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + template + DefaultDelete(const DefaultDelete& other, + typename EnableIf::value, + int>::Type dummy = 0) + {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete ptr; + } +}; + +/** A default deletion policy using operator delete[]. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete[] ptr; + } + + private: + template + void operator()(U* ptr) const MOZ_DELETE; +}; + +template +void +Swap(UniquePtr& x, UniquePtr& y) +{ + x.swap(y); +} + +template +bool +operator==(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() == y.get(); +} + +template +bool +operator!=(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() != y.get(); +} + +template +bool +operator==(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator==(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator!=(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +template +bool +operator!=(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +// No operator<, operator>, operator<=, operator>= for now because simplicity. + +namespace detail { + +template +struct UniqueSelector +{ + typedef UniquePtr SingleObject; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr UnknownBound; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr KnownBound; +}; + +} // namespace detail + +// We don't have variadic template support everywhere, so just hard-code arities +// 0-4 for now. If you need more arguments, feel free to add the extra +// overloads. +// +// Beware! Due to lack of true nullptr support in gcc 4.4 and 4.5, passing +// literal nullptr to MakeUnique will not work on some platforms. See Move.h +// for more details. + +template +typename detail::UniqueSelector::SingleObject +MakeUnique() +{ + return UniquePtr(new T()); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1) +{ + return UniquePtr(new T(Forward(a1))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2) +{ + return UniquePtr(new T(Forward(a1), Forward(a2))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4), Forward(a5))); +} + +template +typename detail::UniqueSelector::UnknownBound +MakeUnique(decltype(sizeof(int)) n) +{ + typedef typename RemoveExtent::Type ArrayType; + return UniquePtr(new ArrayType[n]()); +} + +template +typename detail::UniqueSelector::KnownBound +MakeUnique() MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) MOZ_DELETE; + +} // namespace mozilla + +#endif /* mozilla_UniquePtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Vector.h index c67467524f..8540caf476 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Vector.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/Vector.h @@ -39,14 +39,13 @@ namespace detail { /* * Check that the given capacity wastes the minimal amount of space if - * allocated on the heap. This means that cap*sizeof(T) is as close to a - * power-of-two as possible. growStorageBy() is responsible for ensuring - * this. + * allocated on the heap. This means that aCapacity*sizeof(T) is as close to a + * power-of-two as possible. growStorageBy() is responsible for ensuring this. */ template -static bool CapacityHasExcessSpace(size_t cap) +static bool CapacityHasExcessSpace(size_t aCapacity) { - size_t size = cap * sizeof(T); + size_t size = aCapacity * sizeof(T); return RoundUpPow2(size) - size >= sizeof(T); } @@ -57,72 +56,90 @@ static bool CapacityHasExcessSpace(size_t cap) template struct VectorImpl { - /* Destroys constructed objects in the range [begin, end). */ - static inline void destroy(T* begin, T* end) { - for (T* p = begin; p < end; ++p) - p->~T(); + /* Destroys constructed objects in the range [aBegin, aEnd). */ + static inline void destroy(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + p->~T(); } + } - /* Constructs objects in the uninitialized range [begin, end). */ - static inline void initialize(T* begin, T* end) { - for (T* p = begin; p < end; ++p) - new(p) T(); + /* Constructs objects in the uninitialized range [aBegin, aEnd). */ + static inline void initialize(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); } + } - /* - * Copy-constructs objects in the uninitialized range - * [dst, dst+(srcend-srcbeg)) from the range [srcbeg, srcend). - */ - template - static inline void copyConstruct(T* dst, const U* srcbeg, const U* srcend) { - for (const U* p = srcbeg; p < srcend; ++p, ++dst) - new(dst) T(*p); + /* + * Copy-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(*p); } + } - /* - * Move-constructs objects in the uninitialized range - * [dst, dst+(srcend-srcbeg)) from the range [srcbeg, srcend). - */ - template - static inline void moveConstruct(T* dst, U* srcbeg, U* srcend) { - for (U* p = srcbeg; p < srcend; ++p, ++dst) - new(dst) T(Move(*p)); + /* + * Move-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void moveConstruct(T* aDst, U* aSrcStart, U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(Move(*p)); } + } - /* - * Copy-constructs objects in the uninitialized range [dst, dst+n) from the - * same object u. - */ - template - static inline void copyConstructN(T* dst, size_t n, const U& u) { - for (T* end = dst + n; dst < end; ++dst) - new(dst) T(u); + /* + * Copy-constructs objects in the uninitialized range [aDst, aDst+aN) from + * the same object aU. + */ + template + static inline void copyConstructN(T* aDst, size_t aN, const U& aU) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + new(aDst) T(aU); } + } - /* - * Grows the given buffer to have capacity newCap, preserving the objects - * constructed in the range [begin, end) and updating v. Assumes that (1) - * newCap has not overflowed, and (2) multiplying newCap by sizeof(T) will - * not overflow. - */ - static inline bool - growTo(VectorBase& v, size_t newCap) { - MOZ_ASSERT(!v.usingInlineStorage()); - MOZ_ASSERT(!CapacityHasExcessSpace(newCap)); - T* newbuf = reinterpret_cast(v.malloc_(newCap * sizeof(T))); - if (!newbuf) - return false; - T* dst = newbuf; - T* src = v.beginNoCheck(); - for (; src < v.endNoCheck(); ++dst, ++src) - new(dst) T(Move(*src)); - VectorImpl::destroy(v.beginNoCheck(), v.endNoCheck()); - v.free_(v.mBegin); - v.mBegin = newbuf; - /* v.mLength is unchanged. */ - v.mCapacity = newCap; - return true; + /* + * Grows the given buffer to have capacity aNewCap, preserving the objects + * constructed in the range [begin, end) and updating aV. Assumes that (1) + * aNewCap has not overflowed, and (2) multiplying aNewCap by sizeof(T) will + * not overflow. + */ + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + T* newbuf = reinterpret_cast(aV.malloc_(aNewCap * sizeof(T))); + if (!newbuf) { + return false; + } + T* dst = newbuf; + T* src = aV.beginNoCheck(); + for (; src < aV.endNoCheck(); ++dst, ++src) { + new(dst) T(Move(*src)); } + VectorImpl::destroy(aV.beginNoCheck(), aV.endNoCheck()); + aV.free_(aV.mBegin); + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } }; /* @@ -133,58 +150,71 @@ struct VectorImpl template struct VectorImpl { - static inline void destroy(T*, T*) {} - - static inline void initialize(T* begin, T* end) { - /* - * You would think that memset would be a big win (or even break even) - * when we know T is a POD. But currently it's not. This is probably - * because |append| tends to be given small ranges and memset requires - * a function call that doesn't get inlined. - * - * memset(begin, 0, sizeof(T) * (end-begin)); - */ - for (T* p = begin; p < end; ++p) - new(p) T(); - } + static inline void destroy(T*, T*) {} - template - static inline void copyConstruct(T* dst, const U* srcbeg, const U* srcend) { - /* - * See above memset comment. Also, notice that copyConstruct is - * currently templated (T != U), so memcpy won't work without - * requiring T == U. - * - * memcpy(dst, srcbeg, sizeof(T) * (srcend - srcbeg)); - */ - for (const U* p = srcbeg; p < srcend; ++p, ++dst) - *dst = *p; + static inline void initialize(T* aBegin, T* aEnd) + { + /* + * You would think that memset would be a big win (or even break even) + * when we know T is a POD. But currently it's not. This is probably + * because |append| tends to be given small ranges and memset requires + * a function call that doesn't get inlined. + * + * memset(aBegin, 0, sizeof(T) * (aEnd - aBegin)); + */ + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); } + } - template - static inline void moveConstruct(T* dst, const U* srcbeg, const U* srcend) { - copyConstruct(dst, srcbeg, srcend); + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + /* + * See above memset comment. Also, notice that copyConstruct is + * currently templated (T != U), so memcpy won't work without + * requiring T == U. + * + * memcpy(aDst, aSrcStart, sizeof(T) * (aSrcEnd - aSrcStart)); + */ + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + *aDst = *p; } + } - static inline void copyConstructN(T* dst, size_t n, const T& t) { - for (T* end = dst + n; dst < end; ++dst) - *dst = t; + template + static inline void moveConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + copyConstruct(aDst, aSrcStart, aSrcEnd); + } + + static inline void copyConstructN(T* aDst, size_t aN, const T& aT) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + *aDst = aT; } + } - static inline bool - growTo(VectorBase& v, size_t newCap) { - MOZ_ASSERT(!v.usingInlineStorage()); - MOZ_ASSERT(!CapacityHasExcessSpace(newCap)); - size_t oldSize = sizeof(T) * v.mCapacity; - size_t newSize = sizeof(T) * newCap; - T* newbuf = reinterpret_cast(v.realloc_(v.mBegin, oldSize, newSize)); - if (!newbuf) - return false; - v.mBegin = newbuf; - /* v.mLength is unchanged. */ - v.mCapacity = newCap; - return true; + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + size_t oldSize = sizeof(T) * aV.mCapacity; + size_t newSize = sizeof(T) * aNewCap; + T* newbuf = reinterpret_cast(aV.realloc_(aV.mBegin, oldSize, newSize)); + if (!newbuf) { + return false; } + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } }; } // namespace detail @@ -199,368 +229,387 @@ struct VectorImpl template class VectorBase : private AllocPolicy { - /* utilities */ + /* utilities */ - static const bool sElemIsPod = IsPod::value; - typedef detail::VectorImpl Impl; - friend struct detail::VectorImpl; + static const bool kElemIsPod = IsPod::value; + typedef detail::VectorImpl Impl; + friend struct detail::VectorImpl; - bool growStorageBy(size_t incr); - bool convertToHeapStorage(size_t newCap); + bool growStorageBy(size_t aIncr); + bool convertToHeapStorage(size_t aNewCap); - /* magic constants */ + /* magic constants */ - static const int sMaxInlineBytes = 1024; + static const int kMaxInlineBytes = 1024; - /* compute constants */ + /* compute constants */ - /* - * Consider element size to be 1 for buffer sizing if there are 0 inline - * elements. This allows us to compile when the definition of the element - * type is not visible here. - * - * Explicit specialization is only allowed at namespace scope, so in order - * to keep everything here, we use a dummy template parameter with partial - * specialization. - */ - template - struct ElemSize - { - static const size_t value = sizeof(T); - }; - template - struct ElemSize<0, Dummy> - { - static const size_t value = 1; - }; - - static const size_t sInlineCapacity = - tl::Min::value>::value; - - /* Calculate inline buffer size; avoid 0-sized array. */ - static const size_t sInlineBytes = - tl::Max<1, sInlineCapacity * ElemSize::value>::value; - - /* member data */ + /* + * Consider element size to be 1 for buffer sizing if there are 0 inline + * elements. This allows us to compile when the definition of the element + * type is not visible here. + * + * Explicit specialization is only allowed at namespace scope, so in order + * to keep everything here, we use a dummy template parameter with partial + * specialization. + */ + template + struct ElemSize + { + static const size_t value = sizeof(T); + }; + template + struct ElemSize<0, Dummy> + { + static const size_t value = 1; + }; + + static const size_t kInlineCapacity = + tl::Min::value>::value; + + /* Calculate inline buffer size; avoid 0-sized array. */ + static const size_t kInlineBytes = + tl::Max<1, kInlineCapacity * ElemSize::value>::value; + + /* member data */ - /* - * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, - * mBegin + mLength) hold valid constructed T objects. The range [mBegin + - * mLength, mBegin + mCapacity) holds uninitialized memory. The range - * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory - * previously allocated by a call to reserve(). - */ - T* mBegin; + /* + * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, + * mBegin + mLength) hold valid constructed T objects. The range [mBegin + + * mLength, mBegin + mCapacity) holds uninitialized memory. The range + * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory + * previously allocated by a call to reserve(). + */ + T* mBegin; - /* Number of elements in the vector. */ - size_t mLength; + /* Number of elements in the vector. */ + size_t mLength; - /* Max number of elements storable in the vector without resizing. */ - size_t mCapacity; + /* Max number of elements storable in the vector without resizing. */ + size_t mCapacity; #ifdef DEBUG - /* Max elements of reserved or used space in this vector. */ - size_t mReserved; + /* Max elements of reserved or used space in this vector. */ + size_t mReserved; #endif - /* Memory used for inline storage. */ - AlignedStorage storage; + /* Memory used for inline storage. */ + AlignedStorage mStorage; #ifdef DEBUG - friend class ReentrancyGuard; - bool entered; + friend class ReentrancyGuard; + bool mEntered; #endif - /* private accessors */ + /* private accessors */ - bool usingInlineStorage() const { - return mBegin == const_cast(this)->inlineStorage(); - } + bool usingInlineStorage() const + { + return mBegin == const_cast(this)->inlineStorage(); + } - T* inlineStorage() { - return static_cast(storage.addr()); - } + T* inlineStorage() + { + return static_cast(mStorage.addr()); + } - T* beginNoCheck() const { - return mBegin; - } + T* beginNoCheck() const + { + return mBegin; + } - T* endNoCheck() { - return mBegin + mLength; - } + T* endNoCheck() + { + return mBegin + mLength; + } - const T* endNoCheck() const { - return mBegin + mLength; - } + const T* endNoCheck() const + { + return mBegin + mLength; + } #ifdef DEBUG - size_t reserved() const { - MOZ_ASSERT(mReserved <= mCapacity); - MOZ_ASSERT(mLength <= mReserved); - return mReserved; - } + size_t reserved() const + { + MOZ_ASSERT(mReserved <= mCapacity); + MOZ_ASSERT(mLength <= mReserved); + return mReserved; + } #endif - /* Append operations guaranteed to succeed due to pre-reserved space. */ - template void internalAppend(U&& u); - template - void internalAppendAll(const VectorBase& u); - void internalAppendN(const T& t, size_t n); - template void internalAppend(const U* begin, size_t length); + /* Append operations guaranteed to succeed due to pre-reserved space. */ + template void internalAppend(U&& aU); + template + void internalAppendAll(const VectorBase& aU); + void internalAppendN(const T& aT, size_t aN); + template void internalAppend(const U* aBegin, size_t aLength); - public: - static const size_t sMaxInlineStorage = N; +public: + static const size_t sMaxInlineStorage = N; - typedef T ElementType; + typedef T ElementType; - VectorBase(AllocPolicy = AllocPolicy()); - VectorBase(ThisVector&&); /* Move constructor. */ - ThisVector& operator=(ThisVector&&); /* Move assignment. */ - ~VectorBase(); + explicit VectorBase(AllocPolicy = AllocPolicy()); + explicit VectorBase(ThisVector&&); /* Move constructor. */ + ThisVector& operator=(ThisVector&&); /* Move assignment. */ + ~VectorBase(); - /* accessors */ + /* accessors */ - const AllocPolicy& allocPolicy() const { - return *this; - } + const AllocPolicy& allocPolicy() const { return *this; } - AllocPolicy& allocPolicy() { - return *this; - } + AllocPolicy& allocPolicy() { return *this; } - enum { InlineLength = N }; + enum { InlineLength = N }; - size_t length() const { - return mLength; - } + size_t length() const { return mLength; } - bool empty() const { - return mLength == 0; - } + bool empty() const { return mLength == 0; } - size_t capacity() const { - return mCapacity; - } + size_t capacity() const { return mCapacity; } - T* begin() { - MOZ_ASSERT(!entered); - return mBegin; - } + T* begin() + { + MOZ_ASSERT(!mEntered); + return mBegin; + } - const T* begin() const { - MOZ_ASSERT(!entered); - return mBegin; - } + const T* begin() const + { + MOZ_ASSERT(!mEntered); + return mBegin; + } - T* end() { - MOZ_ASSERT(!entered); - return mBegin + mLength; - } + T* end() + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } - const T* end() const { - MOZ_ASSERT(!entered); - return mBegin + mLength; - } + const T* end() const + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } - T& operator[](size_t i) { - MOZ_ASSERT(!entered); - MOZ_ASSERT(i < mLength); - return begin()[i]; - } + T& operator[](size_t aIndex) + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } - const T& operator[](size_t i) const { - MOZ_ASSERT(!entered); - MOZ_ASSERT(i < mLength); - return begin()[i]; - } + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } - T& back() { - MOZ_ASSERT(!entered); - MOZ_ASSERT(!empty()); - return *(end() - 1); - } + T& back() + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } - const T& back() const { - MOZ_ASSERT(!entered); - MOZ_ASSERT(!empty()); - return *(end() - 1); - } + const T& back() const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } - class Range + class Range + { + friend class VectorBase; + T* mCur; + T* mEnd; + Range(T* aCur, T* aEnd) + : mCur(aCur) + , mEnd(aEnd) { - friend class VectorBase; - T* cur_; - T* end_; - Range(T* cur, T* end) : cur_(cur), end_(end) {} - - public: - Range() {} - bool empty() const { return cur_ == end_; } - size_t remain() const { return end_ - cur_; } - T& front() const { return *cur_; } - void popFront() { MOZ_ASSERT(!empty()); ++cur_; } - T popCopyFront() { MOZ_ASSERT(!empty()); return *cur_++; } - }; - - Range all() { - return Range(begin(), end()); + MOZ_ASSERT(aCur <= aEnd); } - /* mutators */ + public: + Range() {} + bool empty() const { return mCur == mEnd; } + size_t remain() const { return PointerRangeSize(mCur, mEnd); } + T& front() const { MOZ_ASSERT(!empty()); return *mCur; } + void popFront() { MOZ_ASSERT(!empty()); ++mCur; } + T popCopyFront() { MOZ_ASSERT(!empty()); return *mCur++; } + }; - /** - * Given that the vector is empty and has no inline storage, grow to - * |capacity|. - */ - bool initCapacity(size_t request); + Range all() { return Range(begin(), end()); } - /** - * If reserve(length() + N) succeeds, the N next appends are guaranteed to - * succeed. - */ - bool reserve(size_t request); + /* mutators */ - /** - * Destroy elements in the range [end() - incr, end()). Does not deallocate - * or unreserve storage for those elements. - */ - void shrinkBy(size_t incr); + /** + * Given that the vector is empty and has no inline storage, grow to + * |capacity|. + */ + bool initCapacity(size_t aRequest); - /** Grow the vector by incr elements. */ - bool growBy(size_t incr); + /** + * If reserve(length() + N) succeeds, the N next appends are guaranteed to + * succeed. + */ + bool reserve(size_t aRequest); - /** Call shrinkBy or growBy based on whether newSize > length(). */ - bool resize(size_t newLength); + /** + * Destroy elements in the range [end() - aIncr, end()). Does not deallocate + * or unreserve storage for those elements. + */ + void shrinkBy(size_t aIncr); - /** - * Increase the length of the vector, but don't initialize the new elements - * -- leave them as uninitialized memory. - */ - bool growByUninitialized(size_t incr); - bool resizeUninitialized(size_t newLength); + /** Grow the vector by aIncr elements. */ + bool growBy(size_t aIncr); - /** Shorthand for shrinkBy(length()). */ - void clear(); + /** Call shrinkBy or growBy based on whether newSize > length(). */ + bool resize(size_t aNewLength); - /** Clears and releases any heap-allocated storage. */ - void clearAndFree(); + /** + * Increase the length of the vector, but don't initialize the new elements + * -- leave them as uninitialized memory. + */ + bool growByUninitialized(size_t aIncr); + bool resizeUninitialized(size_t aNewLength); - /** - * If true, appending |needed| elements won't reallocate elements storage. - * This *doesn't* mean that infallibleAppend may be used! You still must - * reserve the extra space, even if this method indicates that appends won't - * need to reallocate elements storage. - */ - bool canAppendWithoutRealloc(size_t needed) const; + /** Shorthand for shrinkBy(length()). */ + void clear(); - /** Potentially fallible append operations. */ + /** Clears and releases any heap-allocated storage. */ + void clearAndFree(); - /** - * This can take either a T& or a T&&. Given a T&&, it moves |u| into the - * vector, instead of copying it. If it fails, |u| is left unmoved. ("We are - * not amused.") - */ - template bool append(U&& u); + /** + * If true, appending |aNeeded| elements won't reallocate elements storage. + * This *doesn't* mean that infallibleAppend may be used! You still must + * reserve the extra space, even if this method indicates that appends won't + * need to reallocate elements storage. + */ + bool canAppendWithoutRealloc(size_t aNeeded) const; - template - bool appendAll(const VectorBase& u); - bool appendN(const T& t, size_t n); - template bool append(const U* begin, const U* end); - template bool append(const U* begin, size_t length); + /** Potentially fallible append operations. */ - /* - * Guaranteed-infallible append operations for use upon vectors whose - * memory has been pre-reserved. Don't use this if you haven't reserved the - * memory! - */ - template void infallibleAppend(U&& u) { - internalAppend(Forward(u)); - } - void infallibleAppendN(const T& t, size_t n) { - internalAppendN(t, n); - } - template void infallibleAppend(const U* aBegin, const U* aEnd) { - internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); - } - template void infallibleAppend(const U* aBegin, size_t aLength) { - internalAppend(aBegin, aLength); - } + /** + * This can take either a T& or a T&&. Given a T&&, it moves |aU| into the + * vector, instead of copying it. If it fails, |aU| is left unmoved. ("We are + * not amused.") + */ + template bool append(U&& aU); + + template + bool appendAll(const VectorBase& aU); + bool appendN(const T& aT, size_t aN); + template bool append(const U* aBegin, const U* aEnd); + template bool append(const U* aBegin, size_t aLength); - void popBack(); + /* + * Guaranteed-infallible append operations for use upon vectors whose + * memory has been pre-reserved. Don't use this if you haven't reserved the + * memory! + */ + template void infallibleAppend(U&& aU) + { + internalAppend(Forward(aU)); + } + void infallibleAppendN(const T& aT, size_t aN) + { + internalAppendN(aT, aN); + } + template void infallibleAppend(const U* aBegin, const U* aEnd) + { + internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); + } + template void infallibleAppend(const U* aBegin, size_t aLength) + { + internalAppend(aBegin, aLength); + } - T popCopy(); + void popBack(); - /** - * Transfers ownership of the internal buffer used by this vector to the - * caller. (It's the caller's responsibility to properly deallocate this - * buffer, in accordance with this vector's AllocPolicy.) After this call, - * the vector is empty. Since the returned buffer may need to be allocated - * (if the elements are currently stored in-place), the call can fail, - * returning nullptr. - * - * N.B. Although a T*, only the range [0, length()) is constructed. - */ - T* extractRawBuffer(); + T popCopy(); - /** - * Transfer ownership of an array of objects into the vector. The caller - * must have allocated the array in accordance with this vector's - * AllocPolicy. - * - * N.B. This call assumes that there are no uninitialized elements in the - * passed array. - */ - void replaceRawBuffer(T* p, size_t length); + /** + * Transfers ownership of the internal buffer used by this vector to the + * caller. (It's the caller's responsibility to properly deallocate this + * buffer, in accordance with this vector's AllocPolicy.) After this call, + * the vector is empty. Since the returned buffer may need to be allocated + * (if the elements are currently stored in-place), the call can fail, + * returning nullptr. + * + * N.B. Although a T*, only the range [0, length()) is constructed. + */ + T* extractRawBuffer(); + + /** + * Transfer ownership of an array of objects into the vector. The caller + * must have allocated the array in accordance with this vector's + * AllocPolicy. + * + * N.B. This call assumes that there are no uninitialized elements in the + * passed array. + */ + void replaceRawBuffer(T* aP, size_t aLength); + + /** + * Places |aVal| at position |aP|, shifting existing elements from |aP| onward + * one position higher. On success, |aP| should not be reused because it'll + * be a dangling pointer if reallocation of the vector storage occurred; the + * return value should be used instead. On failure, nullptr is returned. + * + * Example usage: + * + * if (!(p = vec.insert(p, val))) { + * + * } + * + * + * This is inherently a linear-time operation. Be careful! + */ + template + T* insert(T* aP, U&& aVal); - /** - * Places |val| at position |p|, shifting existing elements from |p| onward - * one position higher. On success, |p| should not be reused because it'll - * be a dangling pointer if reallocation of the vector storage occurred; the - * return value should be used instead. On failure, nullptr is returned. - * - * Example usage: - * - * if (!(p = vec.insert(p, val))) - * - * - * - * This is inherently a linear-time operation. Be careful! - */ - template - T* insert(T* p, U&& val); + /** + * Removes the element |aT|, which must fall in the bounds [begin, end), + * shifting existing elements from |aT + 1| onward one position lower. + */ + void erase(T* aT); - /** - * Removes the element |t|, which must fall in the bounds [begin, end), - * shifting existing elements from |t + 1| onward one position lower. - */ - void erase(T* t); + /** + * Removes the elements [|aBegin|, |aEnd|), which must fall in the bounds + * [begin, end), shifting existing elements from |aEnd + 1| onward to aBegin's + * old position. + */ + void erase(T* aBegin, T* aEnd); - /** - * Measure the size of the vector's heap-allocated storage. - */ - size_t sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const; + /** + * Measure the size of the vector's heap-allocated storage. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const; - /** - * Like sizeOfExcludingThis, but also measures the size of the vector - * object (which must be heap-allocated) itself. - */ - size_t sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const; + /** + * Like sizeOfExcludingThis, but also measures the size of the vector + * object (which must be heap-allocated) itself. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; - void swap(ThisVector& other); + void swap(ThisVector& aOther); - private: - VectorBase(const VectorBase&) MOZ_DELETE; - void operator=(const VectorBase&) MOZ_DELETE; +private: + VectorBase(const VectorBase&) MOZ_DELETE; + void operator=(const VectorBase&) MOZ_DELETE; - /* Move-construct/assign only from our derived class, ThisVector. */ - VectorBase(VectorBase&&) MOZ_DELETE; - void operator=(VectorBase&&) MOZ_DELETE; + /* Move-construct/assign only from our derived class, ThisVector. */ + VectorBase(VectorBase&&) MOZ_DELETE; + void operator=(VectorBase&&) MOZ_DELETE; }; /* This does the re-entrancy check plus several other sanity checks. */ #define MOZ_REENTRANCY_GUARD_ET_AL \ ReentrancyGuard g(*this); \ - MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == sInlineCapacity); \ + MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == kInlineCapacity); \ MOZ_ASSERT(reserved() <= mCapacity); \ MOZ_ASSERT(mLength <= reserved()); \ MOZ_ASSERT(mLength <= mCapacity) @@ -569,39 +618,39 @@ class VectorBase : private AllocPolicy template MOZ_ALWAYS_INLINE -VectorBase::VectorBase(AP ap) - : AP(ap), - mLength(0), - mCapacity(sInlineCapacity) +VectorBase::VectorBase(AP aAP) + : AP(aAP) + , mLength(0) + , mCapacity(kInlineCapacity) #ifdef DEBUG - , mReserved(sInlineCapacity), - entered(false) + , mReserved(kInlineCapacity) + , mEntered(false) #endif { - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); } /* Move constructor. */ template MOZ_ALWAYS_INLINE -VectorBase::VectorBase(TV&& rhs) - : AllocPolicy(Move(rhs)) +VectorBase::VectorBase(TV&& aRhs) + : AllocPolicy(Move(aRhs)) #ifdef DEBUG - , entered(false) + , mEntered(false) #endif { - mLength = rhs.mLength; - mCapacity = rhs.mCapacity; + mLength = aRhs.mLength; + mCapacity = aRhs.mCapacity; #ifdef DEBUG - mReserved = rhs.mReserved; + mReserved = aRhs.mReserved; #endif - if (rhs.usingInlineStorage()) { + if (aRhs.usingInlineStorage()) { /* We can't move the buffer over in this case, so copy elements. */ - mBegin = static_cast(storage.addr()); - Impl::moveConstruct(mBegin, rhs.beginNoCheck(), rhs.endNoCheck()); + mBegin = static_cast(mStorage.addr()); + Impl::moveConstruct(mBegin, aRhs.beginNoCheck(), aRhs.endNoCheck()); /* - * Leave rhs's mLength, mBegin, mCapacity, and mReserved as they are. + * Leave aRhs's mLength, mBegin, mCapacity, and mReserved as they are. * The elements in its in-line storage still need to be destroyed. */ } else { @@ -609,26 +658,25 @@ VectorBase::VectorBase(TV&& rhs) * Take src's buffer, and turn src into an empty vector using * in-line storage. */ - mBegin = rhs.mBegin; - rhs.mBegin = static_cast(rhs.storage.addr()); - rhs.mCapacity = sInlineCapacity; - rhs.mLength = 0; + mBegin = aRhs.mBegin; + aRhs.mBegin = static_cast(aRhs.mStorage.addr()); + aRhs.mCapacity = kInlineCapacity; + aRhs.mLength = 0; #ifdef DEBUG - rhs.mReserved = sInlineCapacity; + aRhs.mReserved = kInlineCapacity; #endif } } /* Move assignment. */ template -MOZ_ALWAYS_INLINE -TV& -VectorBase::operator=(TV&& rhs) +MOZ_ALWAYS_INLINE TV& +VectorBase::operator=(TV&& aRhs) { - MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + MOZ_ASSERT(this != &aRhs, "self-move assignment is prohibited"); TV* tv = static_cast(this); tv->~TV(); - new(tv) TV(Move(rhs)); + new(tv) TV(Move(aRhs)); return *tv; } @@ -638,26 +686,28 @@ VectorBase::~VectorBase() { MOZ_REENTRANCY_GUARD_ET_AL; Impl::destroy(beginNoCheck(), endNoCheck()); - if (!usingInlineStorage()) + if (!usingInlineStorage()) { this->free_(beginNoCheck()); + } } /* - * This function will create a new heap buffer with capacity newCap, + * This function will create a new heap buffer with capacity aNewCap, * move all elements in the inline buffer to this new buffer, * and fail on OOM. */ template inline bool -VectorBase::convertToHeapStorage(size_t newCap) +VectorBase::convertToHeapStorage(size_t aNewCap) { MOZ_ASSERT(usingInlineStorage()); /* Allocate buffer. */ - MOZ_ASSERT(!detail::CapacityHasExcessSpace(newCap)); - T* newBuf = reinterpret_cast(this->malloc_(newCap * sizeof(T))); - if (!newBuf) + MOZ_ASSERT(!detail::CapacityHasExcessSpace(aNewCap)); + T* newBuf = reinterpret_cast(this->malloc_(aNewCap * sizeof(T))); + if (!newBuf) { return false; + } /* Copy inline elements into heap buffer. */ Impl::moveConstruct(newBuf, beginNoCheck(), endNoCheck()); @@ -666,15 +716,15 @@ VectorBase::convertToHeapStorage(size_t newCap) /* Switch in heap buffer. */ mBegin = newBuf; /* mLength is unchanged. */ - mCapacity = newCap; + mCapacity = aNewCap; return true; } template MOZ_NEVER_INLINE bool -VectorBase::growStorageBy(size_t incr) +VectorBase::growStorageBy(size_t aIncr) { - MOZ_ASSERT(mLength + incr > mCapacity); + MOZ_ASSERT(mLength + aIncr > mCapacity); MOZ_ASSERT_IF(!usingInlineStorage(), !detail::CapacityHasExcessSpace(mCapacity)); @@ -688,11 +738,11 @@ VectorBase::growStorageBy(size_t incr) size_t newCap; - if (incr == 1) { + if (aIncr == 1) { if (usingInlineStorage()) { /* This case occurs in ~70--80% of the calls to this function. */ size_t newSize = - tl::RoundUpPow2<(sInlineCapacity + 1) * sizeof(T)>::value; + tl::RoundUpPow2<(kInlineCapacity + 1) * sizeof(T)>::value; newCap = newSize / sizeof(T); goto convert; } @@ -725,13 +775,14 @@ VectorBase::growStorageBy(size_t incr) * then there might be space for one more element. */ newCap = mLength * 2; - if (detail::CapacityHasExcessSpace(newCap)) + if (detail::CapacityHasExcessSpace(newCap)) { newCap += 1; + } } else { /* This case occurs in ~2% of the calls to this function. */ - size_t newMinCap = mLength + incr; + size_t newMinCap = mLength + aIncr; - /* Did mLength + incr overflow? Will newCap * sizeof(T) overflow? */ + /* Did mLength + aIncr overflow? Will newCap * sizeof(T) overflow? */ if (newMinCap < mLength || newMinCap & tl::MulOverflowMask<2 * sizeof(T)>::value) { @@ -745,7 +796,7 @@ VectorBase::growStorageBy(size_t incr) } if (usingInlineStorage()) { - convert: +convert: return convertToHeapStorage(newCap); } @@ -755,34 +806,37 @@ VectorBase::growStorageBy(size_t incr) template inline bool -VectorBase::initCapacity(size_t request) +VectorBase::initCapacity(size_t aRequest) { MOZ_ASSERT(empty()); MOZ_ASSERT(usingInlineStorage()); - if (request == 0) + if (aRequest == 0) { return true; - T* newbuf = reinterpret_cast(this->malloc_(request * sizeof(T))); - if (!newbuf) + } + T* newbuf = reinterpret_cast(this->malloc_(aRequest * sizeof(T))); + if (!newbuf) { return false; + } mBegin = newbuf; - mCapacity = request; + mCapacity = aRequest; #ifdef DEBUG - mReserved = request; + mReserved = aRequest; #endif return true; } template inline bool -VectorBase::reserve(size_t request) +VectorBase::reserve(size_t aRequest) { MOZ_REENTRANCY_GUARD_ET_AL; - if (request > mCapacity && !growStorageBy(request - mLength)) + if (aRequest > mCapacity && !growStorageBy(aRequest - mLength)) { return false; - + } #ifdef DEBUG - if (request > mReserved) - mReserved = request; + if (aRequest > mReserved) { + mReserved = aRequest; + } MOZ_ASSERT(mLength <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); #endif @@ -791,69 +845,73 @@ VectorBase::reserve(size_t request) template inline void -VectorBase::shrinkBy(size_t incr) +VectorBase::shrinkBy(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - MOZ_ASSERT(incr <= mLength); - Impl::destroy(endNoCheck() - incr, endNoCheck()); - mLength -= incr; + MOZ_ASSERT(aIncr <= mLength); + Impl::destroy(endNoCheck() - aIncr, endNoCheck()); + mLength -= aIncr; } template MOZ_ALWAYS_INLINE bool -VectorBase::growBy(size_t incr) +VectorBase::growBy(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - if (incr > mCapacity - mLength && !growStorageBy(incr)) + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { return false; - - MOZ_ASSERT(mLength + incr <= mCapacity); - T* newend = endNoCheck() + incr; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + T* newend = endNoCheck() + aIncr; Impl::initialize(endNoCheck(), newend); - mLength += incr; + mLength += aIncr; #ifdef DEBUG - if (mLength > mReserved) + if (mLength > mReserved) { mReserved = mLength; + } #endif return true; } template MOZ_ALWAYS_INLINE bool -VectorBase::growByUninitialized(size_t incr) +VectorBase::growByUninitialized(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - if (incr > mCapacity - mLength && !growStorageBy(incr)) + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { return false; - - MOZ_ASSERT(mLength + incr <= mCapacity); - mLength += incr; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + mLength += aIncr; #ifdef DEBUG - if (mLength > mReserved) + if (mLength > mReserved) { mReserved = mLength; + } #endif return true; } template inline bool -VectorBase::resize(size_t newLength) +VectorBase::resize(size_t aNewLength) { size_t curLength = mLength; - if (newLength > curLength) - return growBy(newLength - curLength); - shrinkBy(curLength - newLength); + if (aNewLength > curLength) { + return growBy(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); return true; } template MOZ_ALWAYS_INLINE bool -VectorBase::resizeUninitialized(size_t newLength) +VectorBase::resizeUninitialized(size_t aNewLength) { size_t curLength = mLength; - if (newLength > curLength) - return growByUninitialized(newLength - curLength); - shrinkBy(curLength - newLength); + if (aNewLength > curLength) { + return growByUninitialized(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); return true; } @@ -872,166 +930,186 @@ VectorBase::clearAndFree() { clear(); - if (usingInlineStorage()) + if (usingInlineStorage()) { return; - + } this->free_(beginNoCheck()); - mBegin = static_cast(storage.addr()); - mCapacity = sInlineCapacity; + mBegin = static_cast(mStorage.addr()); + mCapacity = kInlineCapacity; #ifdef DEBUG - mReserved = sInlineCapacity; + mReserved = kInlineCapacity; #endif } template inline bool -VectorBase::canAppendWithoutRealloc(size_t needed) const +VectorBase::canAppendWithoutRealloc(size_t aNeeded) const { - return mLength + needed <= mCapacity; + return mLength + aNeeded <= mCapacity; } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppendAll(const VectorBase& other) +VectorBase::internalAppendAll( + const VectorBase& aOther) { - internalAppend(other.begin(), other.length()); + internalAppend(aOther.begin(), aOther.length()); } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppend(U&& u) +VectorBase::internalAppend(U&& aU) { MOZ_ASSERT(mLength + 1 <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - new(endNoCheck()) T(Forward(u)); + new(endNoCheck()) T(Forward(aU)); ++mLength; } template MOZ_ALWAYS_INLINE bool -VectorBase::appendN(const T& t, size_t needed) +VectorBase::appendN(const T& aT, size_t aNeeded) { MOZ_REENTRANCY_GUARD_ET_AL; - if (mLength + needed > mCapacity && !growStorageBy(needed)) + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { return false; - + } #ifdef DEBUG - if (mLength + needed > mReserved) - mReserved = mLength + needed; + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } #endif - internalAppendN(t, needed); + internalAppendN(aT, aNeeded); return true; } template MOZ_ALWAYS_INLINE void -VectorBase::internalAppendN(const T& t, size_t needed) +VectorBase::internalAppendN(const T& aT, size_t aNeeded) { - MOZ_ASSERT(mLength + needed <= mReserved); + MOZ_ASSERT(mLength + aNeeded <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - Impl::copyConstructN(endNoCheck(), needed, t); - mLength += needed; + Impl::copyConstructN(endNoCheck(), aNeeded, aT); + mLength += aNeeded; } template template inline T* -VectorBase::insert(T* p, U&& val) +VectorBase::insert(T* aP, U&& aVal) { - MOZ_ASSERT(begin() <= p); - MOZ_ASSERT(p <= end()); - size_t pos = p - begin(); + MOZ_ASSERT(begin() <= aP); + MOZ_ASSERT(aP <= end()); + size_t pos = aP - begin(); MOZ_ASSERT(pos <= mLength); size_t oldLength = mLength; if (pos == oldLength) { - if (!append(Forward(val))) + if (!append(Forward(aVal))) { return nullptr; + } } else { T oldBack = Move(back()); - if (!append(Move(oldBack))) /* Dup the last element. */ + if (!append(Move(oldBack))) { /* Dup the last element. */ return nullptr; - for (size_t i = oldLength; i > pos; --i) + } + for (size_t i = oldLength; i > pos; --i) { (*this)[i] = Move((*this)[i - 1]); - (*this)[pos] = Forward(val); + } + (*this)[pos] = Forward(aVal); } return begin() + pos; } template inline void -VectorBase::erase(T* it) +VectorBase::erase(T* aIt) { - MOZ_ASSERT(begin() <= it); - MOZ_ASSERT(it < end()); - while (it + 1 < end()) { - *it = *(it + 1); - ++it; + MOZ_ASSERT(begin() <= aIt); + MOZ_ASSERT(aIt < end()); + while (aIt + 1 < end()) { + *aIt = Move(*(aIt + 1)); + ++aIt; } - popBack(); + popBack(); +} + +template +inline void +VectorBase::erase(T* aBegin, T* aEnd) +{ + MOZ_ASSERT(begin() <= aBegin); + MOZ_ASSERT(aBegin <= aEnd); + MOZ_ASSERT(aEnd <= end()); + while (aEnd < end()) { + *aBegin++ = Move(*aEnd++); + } + shrinkBy(aEnd - aBegin); } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(const U* insBegin, const U* insEnd) +VectorBase::append(const U* aInsBegin, const U* aInsEnd) { MOZ_REENTRANCY_GUARD_ET_AL; - size_t needed = PointerRangeSize(insBegin, insEnd); - if (mLength + needed > mCapacity && !growStorageBy(needed)) + size_t aNeeded = PointerRangeSize(aInsBegin, aInsEnd); + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { return false; - + } #ifdef DEBUG - if (mLength + needed > mReserved) - mReserved = mLength + needed; + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } #endif - internalAppend(insBegin, needed); + internalAppend(aInsBegin, aNeeded); return true; } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppend(const U* insBegin, size_t insLength) +VectorBase::internalAppend(const U* aInsBegin, size_t aInsLength) { - MOZ_ASSERT(mLength + insLength <= mReserved); + MOZ_ASSERT(mLength + aInsLength <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - Impl::copyConstruct(endNoCheck(), insBegin, insBegin + insLength); - mLength += insLength; + Impl::copyConstruct(endNoCheck(), aInsBegin, aInsBegin + aInsLength); + mLength += aInsLength; } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(U&& u) +VectorBase::append(U&& aU) { MOZ_REENTRANCY_GUARD_ET_AL; - if (mLength == mCapacity && !growStorageBy(1)) + if (mLength == mCapacity && !growStorageBy(1)) { return false; - + } #ifdef DEBUG - if (mLength + 1 > mReserved) + if (mLength + 1 > mReserved) { mReserved = mLength + 1; + } #endif - internalAppend(Forward(u)); + internalAppend(Forward(aU)); return true; } template template MOZ_ALWAYS_INLINE bool -VectorBase::appendAll(const VectorBase& other) +VectorBase::appendAll(const VectorBase& aOther) { - return append(other.begin(), other.length()); + return append(aOther.begin(), aOther.length()); } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(const U *insBegin, size_t insLength) +VectorBase::append(const U* aInsBegin, size_t aInsLength) { - return append(insBegin, insBegin + insLength); + return append(aInsBegin, aInsBegin + aInsLength); } template @@ -1060,19 +1138,20 @@ VectorBase::extractRawBuffer() T* ret; if (usingInlineStorage()) { ret = reinterpret_cast(this->malloc_(mLength * sizeof(T))); - if (!ret) + if (!ret) { return nullptr; + } Impl::copyConstruct(ret, beginNoCheck(), endNoCheck()); Impl::destroy(beginNoCheck(), endNoCheck()); /* mBegin, mCapacity are unchanged. */ mLength = 0; } else { ret = mBegin; - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); mLength = 0; - mCapacity = sInlineCapacity; + mCapacity = kInlineCapacity; #ifdef DEBUG - mReserved = sInlineCapacity; + mReserved = kInlineCapacity; #endif } return ret; @@ -1080,30 +1159,31 @@ VectorBase::extractRawBuffer() template inline void -VectorBase::replaceRawBuffer(T* p, size_t aLength) +VectorBase::replaceRawBuffer(T* aP, size_t aLength) { MOZ_REENTRANCY_GUARD_ET_AL; /* Destroy what we have. */ Impl::destroy(beginNoCheck(), endNoCheck()); - if (!usingInlineStorage()) + if (!usingInlineStorage()) { this->free_(beginNoCheck()); + } /* Take in the new buffer. */ - if (aLength <= sInlineCapacity) { + if (aLength <= kInlineCapacity) { /* - * We convert to inline storage if possible, even though p might + * We convert to inline storage if possible, even though aP might * otherwise be acceptable. Maybe this behaviour should be * specifiable with an argument to this function. */ - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); mLength = aLength; - mCapacity = sInlineCapacity; - Impl::moveConstruct(mBegin, p, p + aLength); - Impl::destroy(p, p + aLength); - this->free_(p); + mCapacity = kInlineCapacity; + Impl::moveConstruct(mBegin, aP, aP + aLength); + Impl::destroy(aP, aP + aLength); + this->free_(aP); } else { - mBegin = p; + mBegin = aP; mLength = aLength; mCapacity = aLength; } @@ -1114,42 +1194,42 @@ VectorBase::replaceRawBuffer(T* p, size_t aLength) template inline size_t -VectorBase::sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const +VectorBase::sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { - return usingInlineStorage() ? 0 : mallocSizeOf(beginNoCheck()); + return usingInlineStorage() ? 0 : aMallocSizeOf(beginNoCheck()); } template inline size_t -VectorBase::sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const +VectorBase::sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { - return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); } template inline void -VectorBase::swap(TV& other) +VectorBase::swap(TV& aOther) { static_assert(N == 0, "still need to implement this for N != 0"); // This only works when inline storage is always empty. - if (!usingInlineStorage() && other.usingInlineStorage()) { - other.mBegin = mBegin; + if (!usingInlineStorage() && aOther.usingInlineStorage()) { + aOther.mBegin = mBegin; mBegin = inlineStorage(); - } else if (usingInlineStorage() && !other.usingInlineStorage()) { - mBegin = other.mBegin; - other.mBegin = other.inlineStorage(); - } else if (!usingInlineStorage() && !other.usingInlineStorage()) { - Swap(mBegin, other.mBegin); + } else if (usingInlineStorage() && !aOther.usingInlineStorage()) { + mBegin = aOther.mBegin; + aOther.mBegin = aOther.inlineStorage(); + } else if (!usingInlineStorage() && !aOther.usingInlineStorage()) { + Swap(mBegin, aOther.mBegin); } else { // This case is a no-op, since we'd set both to use their inline storage. } - Swap(mLength, other.mLength); - Swap(mCapacity, other.mCapacity); + Swap(mLength, aOther.mLength); + Swap(mCapacity, aOther.mCapacity); #ifdef DEBUG - Swap(mReserved, other.mReserved); + Swap(mReserved, aOther.mReserved); #endif } @@ -1180,14 +1260,15 @@ class Vector AllocPolicy, Vector > { - typedef VectorBase Base; - - public: - Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} - Vector(Vector&& vec) : Base(Move(vec)) {} - Vector& operator=(Vector&& vec) { - return Base::operator=(Move(vec)); - } + typedef VectorBase Base; + +public: + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + Vector(Vector&& vec) : Base(Move(vec)) {} + Vector& operator=(Vector&& aOther) + { + return Base::operator=(Move(aOther)); + } }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/WeakPtr.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/WeakPtr.h index 0165e3a017..07f00bc295 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/WeakPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/WeakPtr.h @@ -14,21 +14,29 @@ * the WeakPtrs to it and allows the WeakReference to live beyond the lifetime * of 'Foo'. * + * PLEASE NOTE: This weak pointer implementation is not thread-safe. + * + * Note that when deriving from SupportsWeakPtr you should add + * MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public section of your + * class, where ClassName is the name of your class. + * * The overhead of WeakPtr is that accesses to 'Foo' becomes an additional * dereference, and an additional heap allocated pointer sized object shared * between all of the WeakPtrs. * * Example of usage: * - * // To have a class C support weak pointers, inherit from SupportsWeakPtr. + * // To have a class C support weak pointers, inherit from + * // SupportsWeakPtr. * class C : public SupportsWeakPtr * { - * public: - * int num; - * void act(); + * public: + * MOZ_DECLARE_REFCOUNTED_TYPENAME(C) + * int mNum; + * void act(); * }; * - * C* ptr = new C(); + * C* ptr = new C(); * * // Get weak pointers to ptr. The first time asWeakPtr is called * // a reference counted WeakReference object is created that @@ -39,7 +47,7 @@ * * // Test a weak pointer for validity before using it. * if (weak) { - * weak->num = 17; + * weak->mNum = 17; * weak->act(); * } * @@ -59,11 +67,14 @@ #ifndef mozilla_WeakPtr_h #define mozilla_WeakPtr_h +#include "mozilla/ArrayUtils.h" #include "mozilla/Assertions.h" #include "mozilla/NullPtr.h" #include "mozilla/RefPtr.h" #include "mozilla/TypeTraits.h" +#include + namespace mozilla { template class WeakPtrBase; @@ -71,23 +82,48 @@ template class SupportsWeakPtrBase; namespace detail { -// This can live beyond the lifetime of the class derived from SupportsWeakPtrBase. +// This can live beyond the lifetime of the class derived from +// SupportsWeakPtrBase. template class WeakReference : public ::mozilla::RefCounted > { - public: - explicit WeakReference(T* p) : ptr(p) {} - T* get() const { - return ptr; - } - - private: - friend class WeakPtrBase >; - friend class SupportsWeakPtrBase >; - void detach() { - ptr = nullptr; - } - T* ptr; +public: + explicit WeakReference(T* p) : mPtr(p) {} + + T* get() const { return mPtr; } + +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#ifdef XP_WIN +#define snprintf _snprintf +#endif + const char* typeName() const + { + static char nameBuffer[1024]; + const char* innerType = mPtr->typeName(); + // We could do fancier length checks at runtime, but innerType is + // controlled by us so we can ensure that this never causes a buffer + // overflow by this assertion. + MOZ_ASSERT(strlen(innerType) + sizeof("WeakReference<>") < + ArrayLength(nameBuffer), + "Exceedingly large type name"); + snprintf(nameBuffer, ArrayLength(nameBuffer), "WeakReference<%s>", + innerType); + // This is usually not OK, but here we are returning a pointer to a static + // buffer which will immediately be used by the caller. + return nameBuffer; + } + + size_t typeSize() const { return sizeof(*this); } +#undef snprintf +#endif + +private: + friend class WeakPtrBase >; + friend class SupportsWeakPtrBase >; + + void detach() { mPtr = nullptr; } + + T* mPtr; }; } // namespace detail @@ -95,25 +131,29 @@ class WeakReference : public ::mozilla::RefCounted > template class SupportsWeakPtrBase { - public: - WeakPtrBase asWeakPtr() { - if (!weakRef) - weakRef = new WeakReference(static_cast(this)); - return WeakPtrBase(weakRef); +public: + WeakPtrBase asWeakPtr() + { + if (!weakRef) { + weakRef = new WeakReference(static_cast(this)); } - - protected: - ~SupportsWeakPtrBase() { - static_assert(IsBaseOf, T>::value, - "T must derive from SupportsWeakPtrBase"); - if (weakRef) - weakRef->detach(); + return WeakPtrBase(weakRef); + } + +protected: + ~SupportsWeakPtrBase() + { + static_assert(IsBaseOf, T>::value, + "T must derive from SupportsWeakPtrBase"); + if (weakRef) { + weakRef->detach(); } + } - private: - friend class WeakPtrBase; +private: + friend class WeakPtrBase; - RefPtr weakRef; + RefPtr weakRef; }; template @@ -124,42 +164,37 @@ class SupportsWeakPtr : public SupportsWeakPtrBase > template class WeakPtrBase { - public: - WeakPtrBase(const WeakPtrBase& o) : ref(o.ref) {} - // Ensure that ref is dereferenceable in the uninitialized state - WeakPtrBase() : ref(new WeakReference(nullptr)) {} +public: + WeakPtrBase(const WeakPtrBase& aOther) + : mRef(aOther.mRef) + {} - operator T*() const { - return ref->get(); - } - T& operator*() const { - return *ref->get(); - } + // Ensure that mRef is dereferenceable in the uninitialized state. + WeakPtrBase() : mRef(new WeakReference(nullptr)) {} - T* operator->() const { - return ref->get(); - } + operator T*() const { return mRef->get(); } + T& operator*() const { return *mRef->get(); } - T* get() const { - return ref->get(); - } + T* operator->() const { return mRef->get(); } + + T* get() const { return mRef->get(); } - private: - friend class SupportsWeakPtrBase; +private: + friend class SupportsWeakPtrBase; - explicit WeakPtrBase(const RefPtr &o) : ref(o) {} + explicit WeakPtrBase(const RefPtr &aOther) : mRef(aOther) {} - RefPtr ref; + RefPtr mRef; }; template class WeakPtr : public WeakPtrBase > { - typedef WeakPtrBase > Base; - public: - WeakPtr(const WeakPtr& o) : Base(o) {} - WeakPtr(const Base& o) : Base(o) {} - WeakPtr() {} + typedef WeakPtrBase > Base; +public: + WeakPtr(const WeakPtr& aOther) : Base(aOther) {} + MOZ_IMPLICIT WeakPtr(const Base& aOther) : Base(aOther) {} + WeakPtr() {} }; } // namespace mozilla diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/WindowsVersion.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/WindowsVersion.h new file mode 100644 index 0000000000..fcf24acc2e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozilla/WindowsVersion.h @@ -0,0 +1,144 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_WindowsVersion_h +#define mozilla_WindowsVersion_h + +#include "mozilla/Attributes.h" +#include +#include + +namespace mozilla { + +inline bool +IsWindowsVersionOrLater(uint32_t aVersion) +{ + static uint32_t minVersion = 0; + static uint32_t maxVersion = UINT32_MAX; + + if (minVersion >= aVersion) { + return true; + } + + if (aVersion >= maxVersion) { + return false; + } + + OSVERSIONINFOEX info; + ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + info.dwMajorVersion = aVersion >> 24; + info.dwMinorVersion = (aVersion >> 16) & 0xFF; + info.wServicePackMajor = (aVersion >> 8) & 0xFF; + info.wServicePackMinor = aVersion & 0xFF; + + DWORDLONG conditionMask = 0; + VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); + VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); + VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); + VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL); + + if (VerifyVersionInfo(&info, + VER_MAJORVERSION | VER_MINORVERSION | + VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, + conditionMask)) { + minVersion = aVersion; + return true; + } + + maxVersion = aVersion; + return false; +} + +inline bool +IsWindowsBuildOrLater(uint32_t aBuild) +{ + static uint32_t minBuild = 0; + static uint32_t maxBuild = UINT32_MAX; + + if (minBuild >= aBuild) { + return true; + } + + if (aBuild >= maxBuild) { + return false; + } + + OSVERSIONINFOEX info; + ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + info.dwBuildNumber = aBuild; + + DWORDLONG conditionMask = 0; + VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL); + + if (VerifyVersionInfo(&info, VER_BUILDNUMBER, conditionMask)) { + minBuild = aBuild; + return true; + } + + maxBuild = aBuild; + return false; +} + +MOZ_ALWAYS_INLINE bool +IsXPSP3OrLater() +{ + return IsWindowsVersionOrLater(0x05010300ul); +} + +MOZ_ALWAYS_INLINE bool +IsWin2003OrLater() +{ + return IsWindowsVersionOrLater(0x05020000ul); +} + +MOZ_ALWAYS_INLINE bool +IsWin2003SP2OrLater() +{ + return IsWindowsVersionOrLater(0x05020200ul); +} + +MOZ_ALWAYS_INLINE bool +IsVistaOrLater() +{ + return IsWindowsVersionOrLater(0x06000000ul); +} + +MOZ_ALWAYS_INLINE bool +IsVistaSP1OrLater() +{ + return IsWindowsVersionOrLater(0x06000100ul); +} + +MOZ_ALWAYS_INLINE bool +IsWin7OrLater() +{ + return IsWindowsVersionOrLater(0x06010000ul); +} + +MOZ_ALWAYS_INLINE bool +IsWin7SP1OrLater() +{ + return IsWindowsVersionOrLater(0x06010100ul); +} + +MOZ_ALWAYS_INLINE bool +IsWin8OrLater() +{ + return IsWindowsVersionOrLater(0x06020000ul); +} + +MOZ_ALWAYS_INLINE bool +IsNotWin7PreRTM() +{ + return IsWin7SP1OrLater() || !IsWin7OrLater() || + IsWindowsBuildOrLater(7600); +} + +} // namespace mozilla + +#endif /* mozilla_WindowsVersion_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/mozzconf.h b/frameworks/js-bindings/external/spidermonkey/include/win32/mozzconf.h new file mode 100644 index 0000000000..f1da5ae28f --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/mozzconf.h @@ -0,0 +1,129 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef MOZZCONF_H +#define MOZZCONF_H + +#include "mozilla/Types.h" + +#if defined(ZLIB_IN_MOZGLUE) +#define ZEXTERN MFBT_API +#endif + +/* Exported Symbols */ +#define zlibVersion MOZ_Z_zlibVersion +#define deflate MOZ_Z_deflate +#define deflateEnd MOZ_Z_deflateEnd +#define inflate MOZ_Z_inflate +#define inflateEnd MOZ_Z_inflateEnd +#define deflateSetDictionary MOZ_Z_deflateSetDictionary +#define deflateCopy MOZ_Z_deflateCopy +#define deflateReset MOZ_Z_deflateReset +#define deflateParams MOZ_Z_deflateParams +#define deflateBound MOZ_Z_deflateBound +#define deflatePrime MOZ_Z_deflatePrime +#define inflateSetDictionary MOZ_Z_inflateSetDictionary +#define inflateSync MOZ_Z_inflateSync +#define inflateCopy MOZ_Z_inflateCopy +#define inflateReset MOZ_Z_inflateReset +#define inflateBack MOZ_Z_inflateBack +#define inflateBackEnd MOZ_Z_inflateBackEnd +#define zlibCompileFlags MOZ_Z_zlibCompileFlags +#define compress MOZ_Z_compress +#define compress2 MOZ_Z_compress2 +#define compressBound MOZ_Z_compressBound +#define uncompress MOZ_Z_uncompress +#define gzopen MOZ_Z_gzopen +#define gzdopen MOZ_Z_gzdopen +#define gzsetparams MOZ_Z_gzsetparams +#define gzread MOZ_Z_gzread +#define gzwrite MOZ_Z_gzwrite +#define gzprintf MOZ_Z_gzprintf +#define gzputs MOZ_Z_gzputs +#define gzgets MOZ_Z_gzgets +#define gzputc MOZ_Z_gzputc +#define gzgetc MOZ_Z_gzgetc +#define gzungetc MOZ_Z_gzungetc +#define gzflush MOZ_Z_gzflush +#define gzseek MOZ_Z_gzseek +#define gzrewind MOZ_Z_gzrewind +#define gztell MOZ_Z_gztell +#define gzeof MOZ_Z_gzeof +#define gzclose MOZ_Z_gzclose +#define gzerror MOZ_Z_gzerror +#define gzclearerr MOZ_Z_gzclearerr +#define adler32 MOZ_Z_adler32 +#define crc32 MOZ_Z_crc32 +#define deflateInit_ MOZ_Z_deflateInit_ +#define deflateInit2_ MOZ_Z_deflateInit2_ +#define inflateInit_ MOZ_Z_inflateInit_ +#define inflateInit2_ MOZ_Z_inflateInit2_ +#define inflateBackInit_ MOZ_Z_inflateBackInit_ +#define inflateSyncPoint MOZ_Z_inflateSyncPoint +#define get_crc_table MOZ_Z_get_crc_table +#define zError MOZ_Z_zError + +/* Extra global symbols */ +#define _dist_code MOZ_Z__dist_code +#define _length_code MOZ_Z__length_code +#define _tr_align MOZ_Z__tr_align +#define _tr_flush_block MOZ_Z__tr_flush_block +#define _tr_init MOZ_Z__tr_init +#define _tr_stored_block MOZ_Z__tr_stored_block +#define _tr_tally MOZ_Z__tr_tally +#define deflate_copyright MOZ_Z_deflate_copyright +#define inflate_copyright MOZ_Z_inflate_copyright +#define inflate_fast MOZ_Z_inflate_fast +#define inflate_table MOZ_Z_inflate_table +#define z_errmsg MOZ_Z_z_errmsg +#define zcalloc MOZ_Z_zcalloc +#define zcfree MOZ_Z_zcfree +#define alloc_func MOZ_Z_alloc_func +#define free_func MOZ_Z_free_func +#define in_func MOZ_Z_in_func +#define out_func MOZ_Z_out_func + +/* New as of zlib-1.2.3 */ +#define adler32_combine MOZ_Z_adler32_combine +#define crc32_combine MOZ_Z_crc32_combine +#define deflateSetHeader MOZ_Z_deflateSetHeader +#define deflateTune MOZ_Z_deflateTune +#define gzdirect MOZ_Z_gzdirect +#define inflatePrime MOZ_Z_inflatePrime +#define inflateGetHeader MOZ_Z_inflateGetHeader + +/* New as of zlib-1.2.4 */ +#define adler32_combine64 MOZ_Z_adler32_combine64 +#define crc32_combine64 MOZ_Z_crc32_combine64 +#define gz_error MOZ_Z_gz_error +#define gz_intmax MOZ_Z_gz_intmax +#define gz_strwinerror MOZ_Z_gz_strwinerror +#define gzbuffer MOZ_Z_gzbuffer +#define gzclose_r MOZ_Z_gzclose_r +#define gzclose_w MOZ_Z_gzclose_w +#define gzoffset MOZ_Z_gzoffset +#define gzoffset64 MOZ_Z_gzoffset64 +#define gzopen64 MOZ_Z_gzopen64 +#define gzseek64 MOZ_Z_gzseek64 +#define gztell64 MOZ_Z_gztell64 +#define inflateMark MOZ_Z_inflateMark +#define inflateReset2 MOZ_Z_inflateReset2 +#define inflateUndermine MOZ_Z_inflateUndermine + +/* New as of zlib-1.2.6 */ +#define deflatePending MOZ_Z_deflatePending +#define deflateResetKeep MOZ_Z_deflateResetKeep +#define inflateResetKeep MOZ_Z_inflateResetKeep +#define gzgetc_ MOZ_Z_gzgetc_ + +/* New as of zlib-1.2.7 */ +#define gzopen_w MOZ_Z_gzopen_w + +/* New as of zlib-1.2.8 */ +#define _tr_flush_bits MOZ_Z__tr_flush_bits +#define gzvprintf MOZ_Z_gzvprintf +#define inflateGetDictionary MOZ_Z_inflateGetDictionary + +#endif diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/zconf.h b/frameworks/js-bindings/external/spidermonkey/include/win32/zconf.h new file mode 100644 index 0000000000..fa0950b9de --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/zconf.h @@ -0,0 +1,514 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2013 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#ifndef ZCONF_H +#define ZCONF_H + +/* This header does prefixing as below, but with an updated set of names. */ +#include "mozzconf.h" + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + * Even better than compiling with -DZ_PREFIX would be to use configure to set + * this permanently in zconf.h using "./configure --zprefix". + */ +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ +# define Z_PREFIX_SET + +/* all linked symbols */ +# define _dist_code z__dist_code +# define _length_code z__length_code +# define _tr_align z__tr_align +# define _tr_flush_bits z__tr_flush_bits +# define _tr_flush_block z__tr_flush_block +# define _tr_init z__tr_init +# define _tr_stored_block z__tr_stored_block +# define _tr_tally z__tr_tally +# define adler32 z_adler32 +# define adler32_combine z_adler32_combine +# define adler32_combine64 z_adler32_combine64 +# ifndef Z_SOLO +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# endif +# define crc32 z_crc32 +# define crc32_combine z_crc32_combine +# define crc32_combine64 z_crc32_combine64 +# define deflate z_deflate +# define deflateBound z_deflateBound +# define deflateCopy z_deflateCopy +# define deflateEnd z_deflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateInit_ z_deflateInit_ +# define deflateParams z_deflateParams +# define deflatePending z_deflatePending +# define deflatePrime z_deflatePrime +# define deflateReset z_deflateReset +# define deflateResetKeep z_deflateResetKeep +# define deflateSetDictionary z_deflateSetDictionary +# define deflateSetHeader z_deflateSetHeader +# define deflateTune z_deflateTune +# define deflate_copyright z_deflate_copyright +# define get_crc_table z_get_crc_table +# ifndef Z_SOLO +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflush z_gzflush +# define gzgetc z_gzgetc +# define gzgetc_ z_gzgetc_ +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# ifdef _WIN32 +# define gzopen_w z_gzopen_w +# endif +# define gzprintf z_gzprintf +# define gzvprintf z_gzvprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzwrite z_gzwrite +# endif +# define inflate z_inflate +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define inflateBackInit_ z_inflateBackInit_ +# define inflateCopy z_inflateCopy +# define inflateEnd z_inflateEnd +# define inflateGetHeader z_inflateGetHeader +# define inflateInit2_ z_inflateInit2_ +# define inflateInit_ z_inflateInit_ +# define inflateMark z_inflateMark +# define inflatePrime z_inflatePrime +# define inflateReset z_inflateReset +# define inflateReset2 z_inflateReset2 +# define inflateSetDictionary z_inflateSetDictionary +# define inflateGetDictionary z_inflateGetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateUndermine z_inflateUndermine +# define inflateResetKeep z_inflateResetKeep +# define inflate_copyright z_inflate_copyright +# define inflate_fast z_inflate_fast +# define inflate_table z_inflate_table +# ifndef Z_SOLO +# define uncompress z_uncompress +# endif +# define zError z_zError +# ifndef Z_SOLO +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# endif +# define zlibCompileFlags z_zlibCompileFlags +# define zlibVersion z_zlibVersion + +/* all zlib typedefs in zlib.h and zconf.h */ +# define Byte z_Byte +# define Bytef z_Bytef +# define alloc_func z_alloc_func +# define charf z_charf +# define free_func z_free_func +# ifndef Z_SOLO +# define gzFile z_gzFile +# endif +# define gz_header z_gz_header +# define gz_headerp z_gz_headerp +# define in_func z_in_func +# define intf z_intf +# define out_func z_out_func +# define uInt z_uInt +# define uIntf z_uIntf +# define uLong z_uLong +# define uLongf z_uLongf +# define voidp z_voidp +# define voidpc z_voidpc +# define voidpf z_voidpf + +/* all zlib structs in zlib.h and zconf.h */ +# define gz_header_s z_gz_header_s +# define internal_state z_internal_state + +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +#if defined(ZLIB_CONST) && !defined(z_const) +# define z_const const +#else +# define z_const +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +#ifndef Z_ARG /* function prototypes for stdarg */ +# if defined(STDC) || defined(Z_HAVE_STDARG_H) +# define Z_ARG(args) args +# else +# define Z_ARG(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) || (defined(__OS2__) && defined(__declspec)) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte const *voidpc; + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) +# include +# if (UINT_MAX == 0xffffffffUL) +# define Z_U4 unsigned +# elif (ULONG_MAX == 0xffffffffUL) +# define Z_U4 unsigned long +# elif (USHRT_MAX == 0xffffffffUL) +# define Z_U4 unsigned short +# endif +#endif + +#ifdef Z_U4 + typedef Z_U4 z_crc_t; +#else + typedef unsigned long z_crc_t; +#endif + +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_UNISTD_H +#endif + +#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_STDARG_H +#endif + +#ifdef STDC +# ifndef Z_SOLO +# include /* for off_t */ +# endif +#endif + +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +# ifndef Z_SOLO +# include /* for va_list */ +# endif +#endif + +#ifdef _WIN32 +# ifndef Z_SOLO +# include /* for wchar_t */ +# endif +#endif + +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even + * though the former does not conform to the LFS document), but considering + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as + * equivalently requesting no 64-bit operations + */ +#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 +# undef _LARGEFILE64_SOURCE +#endif + +#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) +# define Z_HAVE_UNISTD_H +#endif +#ifndef Z_SOLO +# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) +# include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ +# ifdef VMS +# include /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif +# endif +#endif + +#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 +# define Z_LFS64 +#endif + +#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) +# define Z_LARGE64 +#endif + +#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) +# define Z_WANT64 +#endif + +#if !defined(SEEK_SET) && !defined(Z_SOLO) +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif + +#ifndef z_off_t +# define z_off_t long +#endif + +#if !defined(_WIN32) && defined(Z_LARGE64) +# define z_off64_t off64_t +#else +# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# define z_off64_t __int64 +# else +# define z_off64_t z_off_t +# endif +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) + #pragma map(deflateInit_,"DEIN") + #pragma map(deflateInit2_,"DEIN2") + #pragma map(deflateEnd,"DEEND") + #pragma map(deflateBound,"DEBND") + #pragma map(inflateInit_,"ININ") + #pragma map(inflateInit2_,"ININ2") + #pragma map(inflateEnd,"INEND") + #pragma map(inflateSync,"INSY") + #pragma map(inflateSetDictionary,"INSEDI") + #pragma map(compressBound,"CMBND") + #pragma map(inflate_table,"INTABL") + #pragma map(inflate_fast,"INFA") + #pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/win32/zlib.h b/frameworks/js-bindings/external/spidermonkey/include/win32/zlib.h new file mode 100644 index 0000000000..b6ce7f1b09 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/win32/zlib.h @@ -0,0 +1,1769 @@ +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.8, April 28th, 2013 + + Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 + (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). +*/ + +#ifndef ZLIB_H +#define ZLIB_H + +#include "zconf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZLIB_VERSION "1.2.8" +#define ZLIB_VERNUM 0x1280 +#define ZLIB_VER_MAJOR 1 +#define ZLIB_VER_MINOR 2 +#define ZLIB_VER_REVISION 8 +#define ZLIB_VER_SUBREVISION 0 + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed data. + This version of the library supports only one compression method (deflation) + but other algorithms will be added later and will have the same stream + interface. + + Compression can be done in a single step if the buffers are large enough, + or can be done by repeated calls of the compression function. In the latter + case, the application must provide more input and/or consume the output + (providing more output space) before each call. + + The compressed data format used by default by the in-memory functions is + the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped + around a deflate stream, which is itself documented in RFC 1951. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio using the functions that start + with "gz". The gzip format is different from the zlib format. gzip is a + gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. + + This library can optionally read and write gzip streams in memory as well. + + The zlib format was designed to be compact and fast for use in memory + and on communications channels. The gzip format was designed for single- + file compression on file systems, has a larger header than zlib to maintain + directory information, and uses a different, slower check method than zlib. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never crash + even in case of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); + +struct internal_state; + +typedef struct z_stream_s { + z_const Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total number of input bytes read so far */ + + Bytef *next_out; /* next output byte should be put there */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total number of bytes output so far */ + + z_const char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: binary or text */ + uLong adler; /* adler32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream FAR *z_streamp; + +/* + gzip header information passed to and from zlib routines. See RFC 1952 + for more details on the meanings of these fields. +*/ +typedef struct gz_header_s { + int text; /* true if compressed data believed to be text */ + uLong time; /* modification time */ + int xflags; /* extra flags (not used when writing a gzip file) */ + int os; /* operating system */ + Bytef *extra; /* pointer to extra field or Z_NULL if none */ + uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ + uInt extra_max; /* space at extra (only when reading header) */ + Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ + uInt name_max; /* space at name (only when reading header) */ + Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ + uInt comm_max; /* space at comment (only when reading header) */ + int hcrc; /* true if there was or will be a header crc */ + int done; /* true when done reading gzip header (not used + when writing a gzip file) */ +} gz_header; + +typedef gz_header FAR *gz_headerp; + +/* + The application must update next_in and avail_in when avail_in has dropped + to zero. It must update next_out and avail_out when avail_out has dropped + to zero. The application must initialize zalloc, zfree and opaque before + calling the init function. All other fields are set by the compression + library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this if + the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers + returned by zalloc for objects of exactly 65536 bytes *must* have their + offset normalized to zero. The default allocation function provided by this + library ensures this (see zutil.c). To reduce memory requirements and avoid + any allocation of 64K objects, at the expense of compression ratio, compile + the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or progress + reports. After compression, total_in holds the total size of the + uncompressed data and may be saved for use in the decompressor (particularly + if the decompressor wants to decompress everything in a single step). +*/ + + /* constants */ + +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +#define Z_BLOCK 5 +#define Z_TREES 6 +/* Allowed flush values; see deflate() and inflate() below for details */ + +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_RLE 3 +#define Z_FIXED 4 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_TEXT 1 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ +#define Z_UNKNOWN 2 +/* Possible values of the data_type field (though see inflate()) */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +#define zlib_version zlibVersion() +/* for compatibility with versions < 1.0.2 */ + + + /* basic functions */ + +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is not + compatible with the zlib.h header file used by the application. This check + is automatically made by deflateInit and inflateInit. + */ + +/* +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. If + zalloc and zfree are set to Z_NULL, deflateInit updates them to use default + allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at all + (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION + requests a default compromise between speed and compression (currently + equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if level is not a valid compression level, or + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). msg is set to null + if there is no error message. deflateInit does not perform any compression: + this will be done by deflate(). +*/ + + +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary (in interactive applications). Some + output may be provided even if flush is not set. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating avail_in or avail_out accordingly; avail_out should + never be zero before the call. The application can consume the compressed + output when it wants, for example when the output buffer is full (avail_out + == 0), or after each call of deflate(). If deflate returns Z_OK and with + zero avail_out, it must be called again after making room in the output + buffer because there might be more output pending. + + Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to + decide how much data to accumulate before producing output, in order to + maximize compression. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In + particular avail_in is zero after the call if enough output space has been + provided before the call.) Flushing may degrade compression for some + compression algorithms and so it should be used only when necessary. This + completes the current deflate block and follows it with an empty stored block + that is three bits plus filler bits to the next byte, followed by four bytes + (00 00 ff ff). + + If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the + output buffer, but the output is not aligned to a byte boundary. All of the + input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. + This completes the current deflate block and follows it with an empty fixed + codes block that is 10 bits long. This assures that enough bytes are output + in order for the decompressor to finish the block before the empty fixed code + block. + + If flush is set to Z_BLOCK, a deflate block is completed and emitted, as + for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to + seven bits of the current block are held to be written as the next byte after + the next deflate block is completed. In this case, the decompressor may not + be provided enough bits at this point in order to complete decompression of + the data provided so far to the compressor. It may need to wait for the next + block to be emitted. This is for advanced applications that need to control + the emission of deflate blocks. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that + avail_out is greater than six to avoid repeated flush markers due to + avail_out == 0 on return. + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there was + enough output space; if deflate returns with Z_OK, this function must be + called again with Z_FINISH and more output space (updated avail_out) but no + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the stream + are deflateReset or deflateEnd. + + Z_FINISH can be used immediately after deflateInit if all the compression + is to be done in a single step. In this case, avail_out must be at least the + value returned by deflateBound (see below). Then deflate is guaranteed to + return Z_STREAM_END. If not enough output space is provided, deflate will + not return Z_STREAM_END, and it must be called again as described above. + + deflate() sets strm->adler to the adler32 checksum of all input read + so far (that is, total_in bytes). + + deflate() may update strm->data_type if it can make a good guess about + the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered + binary. This field is only for information purposes and does not affect the + compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible + (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not + fatal, and deflate() can be called again with more input and more output + space to continue compressing. +*/ + + +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, msg + may be set but then points to a static string (which must not be + deallocated). +*/ + + +/* +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + + Initializes the internal stream state for decompression. The fields + next_in, avail_in, zalloc, zfree and opaque must be initialized before by + the caller. If next_in is not Z_NULL and avail_in is large enough (the + exact value depends on the compression method), inflateInit determines the + compression method from the zlib header and allocates all data structures + accordingly; otherwise the allocation will be deferred to the first call of + inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to + use default allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit() does not process any header information -- that is deferred + until inflate() is called. +*/ + + +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing will + resume at this point for the next call of inflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there is + no more input data or no more space in the output buffer (see below about + the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating the next_* and avail_* values accordingly. The + application can consume the uncompressed output when it wants, for example + when the output buffer is full (avail_out == 0), or after each call of + inflate(). If inflate returns Z_OK and with zero avail_out, it must be + called again after making room in the output buffer because there might be + more output pending. + + The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, + Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much + output as possible to the output buffer. Z_BLOCK requests that inflate() + stop if and when it gets to the next deflate block boundary. When decoding + the zlib or gzip format, this will cause inflate() to return immediately + after the header and before the first block. When doing a raw inflate, + inflate() will go ahead and process the first block, and will return when it + gets to the end of that block, or when it runs out of data. + + The Z_BLOCK option assists in appending to or combining deflate streams. + Also to assist in this, on return inflate() will set strm->data_type to the + number of unused bits in the last byte taken from strm->next_in, plus 64 if + inflate() is currently decoding the last block in the deflate stream, plus + 128 if inflate() returned immediately after decoding an end-of-block code or + decoding the complete header up to just before the first byte of the deflate + stream. The end-of-block will not be indicated until all of the uncompressed + data from that block has been written to strm->next_out. The number of + unused bits may in general be greater than seven, except when bit 7 of + data_type is set, in which case the number of unused bits will be less than + eight. data_type is set as noted here every time inflate() returns for all + flush options, and so can be used to determine the amount of currently + consumed input in bits. + + The Z_TREES option behaves as Z_BLOCK does, but it also returns when the + end of each deflate block header is reached, before any actual data in that + block is decoded. This allows the caller to determine the length of the + deflate block header for later use in random access within a deflate block. + 256 is added to the value of strm->data_type when inflate() returns + immediately after reaching the end of the deflate block header. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step (a + single call of inflate), the parameter flush should be set to Z_FINISH. In + this case all pending input is processed and all pending output is flushed; + avail_out must be large enough to hold all of the uncompressed data for the + operation to complete. (The size of the uncompressed data may have been + saved by the compressor for this purpose.) The use of Z_FINISH is not + required to perform an inflation in one step. However it may be used to + inform inflate that a faster approach can be used for the single inflate() + call. Z_FINISH also informs inflate to not maintain a sliding window if the + stream completes, which reduces inflate's memory footprint. If the stream + does not complete, either because not all of the stream is provided or not + enough output space is provided, then a sliding window will be allocated and + inflate() can be called again to continue the operation as if Z_NO_FLUSH had + been used. + + In this implementation, inflate() always flushes as much output as + possible to the output buffer, and always uses the faster approach on the + first call. So the effects of the flush parameter in this implementation are + on the return value of inflate() as noted below, when inflate() returns early + when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of + memory for a sliding window when Z_FINISH is used. + + If a preset dictionary is needed after this call (see inflateSetDictionary + below), inflate sets strm->adler to the Adler-32 checksum of the dictionary + chosen by the compressor and returns Z_NEED_DICT; otherwise it sets + strm->adler to the Adler-32 checksum of all output produced so far (that is, + total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described + below. At the end of the stream, inflate() checks that its computed adler32 + checksum is equal to that saved by the compressor and returns Z_STREAM_END + only if the checksum is correct. + + inflate() can decompress and check either zlib-wrapped or gzip-wrapped + deflate data. The header type is detected automatically, if requested when + initializing with inflateInit2(). Any information contained in the gzip + header is not retained, so applications that need that information should + instead use raw inflate, see inflateInit2() below, or inflateBack() and + perform their own processing of the gzip header and trailer. When processing + gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output + producted so far. The CRC-32 is checked against the gzip trailer. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect check + value), Z_STREAM_ERROR if the stream structure was inconsistent (for example + next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, + Z_BUF_ERROR if no progress is possible or if there was not enough room in the + output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and + inflate() can be called again with more input and more output space to + continue decompressing. If Z_DATA_ERROR is returned, the application may + then call inflateSync() to look for a good compression block if a partial + recovery of the data is desired. +*/ + + +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state + was inconsistent. In the error case, msg may be set but then points to a + static string (which must not be deallocated). +*/ + + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +/* +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by the + caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8..15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if + deflateInit is used instead. + + windowBits can also be -8..-15 for raw deflate. In this case, -windowBits + determines the window size. deflate() will then generate raw deflate data + with no zlib header or trailer, and will not compute an adler32 check value. + + windowBits can also be greater than 15 for optional gzip encoding. Add + 16 to windowBits to write a simple gzip header and trailer around the + compressed data instead of a zlib wrapper. The gzip header will have no + file name, no extra data, no comment, no modification time (set to zero), no + header crc, and the operating system will be set to 255 (unknown). If a + gzip stream is being written, strm->adler is a crc32 instead of an adler32. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but is + slow and reduces compression ratio; memLevel=9 uses maximum memory for + optimal speed. The default value is 8. See zconf.h for total memory usage + as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match), or Z_RLE to limit match distances to one (run-length + encoding). Filtered data consists mostly of small values with a somewhat + random distribution. In this case, the compression algorithm is tuned to + compress them better. The effect of Z_FILTERED is to force more Huffman + coding and less string matching; it is somewhat intermediate between + Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as + fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The + strategy parameter only affects the compression ratio but not the + correctness of the compressed output even if it is not set appropriately. + Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler + decoder for special applications. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid + method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is + incompatible with the version assumed by the caller (ZLIB_VERSION). msg is + set to null if there is no error message. deflateInit2 does not perform any + compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. When using the zlib format, this + function must be called immediately after deflateInit, deflateInit2 or + deflateReset, and before any call of deflate. When doing raw deflate, this + function must be called either before any call of deflate, or immediately + after the completion of a deflate block, i.e. after all input has been + consumed and all output has been delivered when using any of the flush + options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The + compressor and decompressor must use exactly the same dictionary (see + inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size + provided in deflateInit or deflateInit2. Thus the strings most likely to be + useful should be put at the end of the dictionary, not at the front. In + addition, the current implementation of deflate will use at most the window + size minus 262 bytes of the provided dictionary. + + Upon return of this function, strm->adler is set to the adler32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The adler32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) If a raw deflate was requested, then the + adler32 value is not computed and strm->adler is not set. + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if not at a block boundary for raw deflate). deflateSetDictionary does + not perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and can + consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, + but does not free and reallocate all the internal compression state. The + stream will keep the same compression level and any other attributes that + may have been set by deflateInit2. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, + int level, + int strategy)); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2. This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different strategy. + If the compression level is changed, the input available so far is + compressed with the old level (and may be flushed); the new level will take + effect only at the next call of deflate(). + + Before the call of deflateParams, the stream state must be set as for + a call of deflate(), since the currently available input may have to be + compressed and flushed. In particular, strm->avail_out must be non-zero. + + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if + strm->avail_out was zero. +*/ + +ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain)); +/* + Fine tune deflate's internal compression parameters. This should only be + used by someone who understands the algorithm used by zlib's deflate for + searching for the best matching string, and even then only by the most + fanatic optimizer trying to squeeze out the last compressed bit for their + specific input data. Read the deflate.c source code for the meaning of the + max_lazy, good_length, nice_length, and max_chain parameters. + + deflateTune() can be called after deflateInit() or deflateInit2(), and + returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. + */ + +ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, + uLong sourceLen)); +/* + deflateBound() returns an upper bound on the compressed size after + deflation of sourceLen bytes. It must be called after deflateInit() or + deflateInit2(), and after deflateSetHeader(), if used. This would be used + to allocate an output buffer for deflation in a single pass, and so would be + called before deflate(). If that first deflate() call is provided the + sourceLen input bytes, an output buffer allocated to the size returned by + deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed + to return Z_STREAM_END. Note that it is possible for the compressed size to + be larger than the value returned by deflateBound() if flush options other + than Z_FINISH or Z_NO_FLUSH are used. +*/ + +ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, + unsigned *pending, + int *bits)); +/* + deflatePending() returns the number of bytes and bits of output that have + been generated, but not yet provided in the available output. The bytes not + provided would be due to the available output space having being consumed. + The number of bits of output not provided are between 0 and 7, where they + await more bits to join them in order to fill out a full byte. If pending + or bits are Z_NULL, then those values are not set. + + deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. + */ + +ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + deflatePrime() inserts bits in the deflate output stream. The intent + is that this function is used to start off the deflate output with the bits + leftover from a previous deflate stream when appending to it. As such, this + function can only be used for raw deflate, and must be used before the first + deflate() call after a deflateInit2() or deflateReset(). bits must be less + than or equal to 16, and that many of the least significant bits of value + will be inserted in the output. + + deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough + room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, + gz_headerp head)); +/* + deflateSetHeader() provides gzip header information for when a gzip + stream is requested by deflateInit2(). deflateSetHeader() may be called + after deflateInit2() or deflateReset() and before the first call of + deflate(). The text, time, os, extra field, name, and comment information + in the provided gz_header structure are written to the gzip header (xflag is + ignored -- the extra flags are set according to the compression level). The + caller must assure that, if not Z_NULL, name and comment are terminated with + a zero byte, and that if extra is not Z_NULL, that extra_len bytes are + available there. If hcrc is true, a gzip header crc is included. Note that + the current versions of the command-line version of gzip (up through version + 1.3.x) do not support header crc's, and will report that it is a "multi-part + gzip file" and give up. + + If deflateSetHeader is not used, the default gzip header has text false, + the time set to zero, and os set to 255, with no extra, name, or comment + fields. The gzip header is returned to the default state by deflateReset(). + + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + + This is another version of inflateInit with an extra parameter. The + fields next_in, avail_in, zalloc, zfree and opaque must be initialized + before by the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8..15 for + this version of the library. The default value is 15 if inflateInit is used + instead. windowBits must be greater than or equal to the windowBits value + provided to deflateInit2() while compressing, or it must be equal to 15 if + deflateInit2() was not used. If a compressed stream with a larger window + size is given as input, inflate() will return with the error code + Z_DATA_ERROR instead of trying to allocate a larger window. + + windowBits can also be zero to request that inflate use the window size in + the zlib header of the compressed stream. + + windowBits can also be -8..-15 for raw inflate. In this case, -windowBits + determines the window size. inflate() will then process raw deflate data, + not looking for a zlib or gzip header, not generating a check value, and not + looking for any check values for comparison at the end of the stream. This + is for use with other formats that use the deflate compressed data format + such as zip. Those formats provide their own check values. If a custom + format is developed using the raw deflate format for compressed data, it is + recommended that a check value such as an adler32 or a crc32 be applied to + the uncompressed data as is done in the zlib, gzip, and zip formats. For + most applications, the zlib format should be used as is. Note that comments + above on the use in deflateInit2() applies to the magnitude of windowBits. + + windowBits can also be greater than 15 for optional gzip decoding. Add + 32 to windowBits to enable zlib and gzip decoding with automatic header + detection, or add 16 to decode only the gzip format (the zlib format will + return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a + crc32 instead of an adler32. + + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit2 does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit2() does not process any header information -- that is + deferred until inflate() is called. +*/ + +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate, + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the adler32 value returned by that call of inflate. + The compressor and decompressor must use exactly the same dictionary (see + deflateSetDictionary). For raw inflate, this function can be called at any + time to set the dictionary. If the provided dictionary is smaller than the + window and there is already data in the window, then the provided dictionary + will amend what's there. The application must insure that the dictionary + that was used for compression is provided. + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect adler32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, + Bytef *dictionary, + uInt *dictLength)); +/* + Returns the sliding dictionary being maintained by inflate. dictLength is + set to the number of bytes in the dictionary, and that many bytes are copied + to dictionary. dictionary must have enough space, where 32768 bytes is + always enough. If inflateGetDictionary() is called with dictionary equal to + Z_NULL, then only the dictionary length is returned, and nothing is copied. + Similary, if dictLength is Z_NULL, then it is not set. + + inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the + stream state is inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +/* + Skips invalid compressed data until a possible full flush point (see above + for the description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync searches for a 00 00 FF FF pattern in the compressed data. + All full flush points have this pattern, but not all occurrences of this + pattern are full flush points. + + inflateSync returns Z_OK if a possible full flush point has been found, + Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point + has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. + In the success case, the application may save the current current value of + total_in which indicates where valid compressed data was found. In the + error case, the application may repeatedly call inflateSync, providing more + input each time, until success or end of the input data. +*/ + +ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when randomly accessing a large stream. The + first pass through the stream can periodically record the inflate state, + allowing restarting inflate at those points when randomly accessing the + stream. + + inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate all the internal decompression state. The + stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, + int windowBits)); +/* + This function is the same as inflateReset, but it also permits changing + the wrap and window size requests. The windowBits parameter is interpreted + the same as it is for inflateInit2. + + inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL), or if + the windowBits parameter is invalid. +*/ + +ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + This function inserts bits in the inflate input stream. The intent is + that this function is used to start inflating at a bit position in the + middle of a byte. The provided bits will be used before any bytes are used + from next_in. This function should only be used with raw inflate, and + should be used before the first inflate() call after inflateInit2() or + inflateReset(). bits must be less than or equal to 16, and that many of the + least significant bits of value will be inserted in the input. + + If bits is negative, then the input stream bit buffer is emptied. Then + inflatePrime() can be called again to put bits in the buffer. This is used + to clear out bits leftover after feeding inflate a block description prior + to feeding inflate codes. + + inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +/* + This function returns two values, one in the lower 16 bits of the return + value, and the other in the remaining upper bits, obtained by shifting the + return value down 16 bits. If the upper value is -1 and the lower value is + zero, then inflate() is currently decoding information outside of a block. + If the upper value is -1 and the lower value is non-zero, then inflate is in + the middle of a stored block, with the lower value equaling the number of + bytes from the input remaining to copy. If the upper value is not -1, then + it is the number of bits back from the current bit position in the input of + the code (literal or length/distance pair) currently being processed. In + that case the lower value is the number of bytes already emitted for that + code. + + A code is being processed if inflate is waiting for more input to complete + decoding of the code, or if it has completed decoding but is waiting for + more output space to write the literal or match data. + + inflateMark() is used to mark locations in the input data for random + access, which may be at bit positions, and to note those cases where the + output of a code may span boundaries of random access blocks. The current + location in the input stream can be determined from avail_in and data_type + as noted in the description for the Z_BLOCK flush parameter for inflate. + + inflateMark returns the value noted above or -1 << 16 if the provided + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, + gz_headerp head)); +/* + inflateGetHeader() requests that gzip header information be stored in the + provided gz_header structure. inflateGetHeader() may be called after + inflateInit2() or inflateReset(), and before the first call of inflate(). + As inflate() processes the gzip stream, head->done is zero until the header + is completed, at which time head->done is set to one. If a zlib stream is + being decoded, then head->done is set to -1 to indicate that there will be + no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be + used to force inflate() to return immediately after header processing is + complete and before any actual data is decompressed. + + The text, time, xflags, and os fields are filled in with the gzip header + contents. hcrc is set to true if there is a header CRC. (The header CRC + was valid if done is set to one.) If extra is not Z_NULL, then extra_max + contains the maximum number of bytes to write to extra. Once done is true, + extra_len contains the actual extra field length, and extra contains the + extra field, or that field truncated if extra_max is less than extra_len. + If name is not Z_NULL, then up to name_max characters are written there, + terminated with a zero unless the length is greater than name_max. If + comment is not Z_NULL, then up to comm_max characters are written there, + terminated with a zero unless the length is greater than comm_max. When any + of extra, name, or comment are not Z_NULL and the respective field is not + present in the header, then that field is set to Z_NULL to signal its + absence. This allows the use of deflateSetHeader() with the returned + structure to duplicate the header. However if those fields are set to + allocated memory, then the application will need to save those pointers + elsewhere so that they can be eventually freed. + + If inflateGetHeader is not used, then the header information is simply + discarded. The header is always checked for validity, including the header + CRC if present. inflateReset() will reset the process to discard the header + information. The application would need to call inflateGetHeader() again to + retrieve the header from the next gzip stream. + + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, + unsigned char FAR *window)); + + Initialize the internal stream state for decompression using inflateBack() + calls. The fields zalloc, zfree and opaque in strm must be initialized + before the call. If zalloc and zfree are Z_NULL, then the default library- + derived memory allocation routines are used. windowBits is the base two + logarithm of the window size, in the range 8..15. window is a caller + supplied buffer of that size. Except for special applications where it is + assured that deflate was used with small window sizes, windowBits must be 15 + and a 32K byte window must be supplied to be able to decompress general + deflate streams. + + See inflateBack() for the usage of these routines. + + inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of + the parameters are invalid, Z_MEM_ERROR if the internal state could not be + allocated, or Z_VERSION_ERROR if the version of the library does not match + the version of the header file. +*/ + +typedef unsigned (*in_func) OF((void FAR *, + z_const unsigned char FAR * FAR *)); +typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); + +ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc)); +/* + inflateBack() does a raw inflate with a single call using a call-back + interface for input and output. This is potentially more efficient than + inflate() for file i/o applications, in that it avoids copying between the + output and the sliding window by simply making the window itself the output + buffer. inflate() can be faster on modern CPUs when used with large + buffers. inflateBack() trusts the application to not change the output + buffer passed by the output function, at least until inflateBack() returns. + + inflateBackInit() must be called first to allocate the internal state + and to initialize the state with the user-provided window buffer. + inflateBack() may then be used multiple times to inflate a complete, raw + deflate stream with each call. inflateBackEnd() is then called to free the + allocated state. + + A raw deflate stream is one with no zlib or gzip header or trailer. + This routine would normally be used in a utility that reads zip or gzip + files and writes out uncompressed files. The utility would decode the + header and process the trailer on its own, hence this routine expects only + the raw deflate stream to decompress. This is different from the normal + behavior of inflate(), which expects either a zlib or gzip header and + trailer around the deflate stream. + + inflateBack() uses two subroutines supplied by the caller that are then + called by inflateBack() for input and output. inflateBack() calls those + routines until it reads a complete deflate stream and writes out all of the + uncompressed data, or until it encounters an error. The function's + parameters and return types are defined above in the in_func and out_func + typedefs. inflateBack() will call in(in_desc, &buf) which should return the + number of bytes of provided input, and a pointer to that input in buf. If + there is no input available, in() must return zero--buf is ignored in that + case--and inflateBack() will return a buffer error. inflateBack() will call + out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() + should return zero on success, or non-zero on failure. If out() returns + non-zero, inflateBack() will return with an error. Neither in() nor out() + are permitted to change the contents of the window provided to + inflateBackInit(), which is also the buffer that out() uses to write from. + The length written by out() will be at most the window size. Any non-zero + amount of input may be provided by in(). + + For convenience, inflateBack() can be provided input on the first call by + setting strm->next_in and strm->avail_in. If that input is exhausted, then + in() will be called. Therefore strm->next_in must be initialized before + calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called + immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in + must also be initialized, and then if strm->avail_in is not zero, input will + initially be taken from strm->next_in[0 .. strm->avail_in - 1]. + + The in_desc and out_desc parameters of inflateBack() is passed as the + first parameter of in() and out() respectively when they are called. These + descriptors can be optionally used to pass any information that the caller- + supplied in() and out() functions need to do their job. + + On return, inflateBack() will set strm->next_in and strm->avail_in to + pass back any unused input that was provided by the last in() call. The + return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR + if in() or out() returned an error, Z_DATA_ERROR if there was a format error + in the deflate stream (in which case strm->msg is set to indicate the nature + of the error), or Z_STREAM_ERROR if the stream was not properly initialized. + In the case of Z_BUF_ERROR, an input or output error can be distinguished + using strm->next_in which will be Z_NULL only if in() returned an error. If + strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning + non-zero. (in() will always be called before out(), so strm->next_in is + assured to be defined if out() returns non-zero.) Note that inflateBack() + cannot return Z_OK. +*/ + +ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +/* + All memory allocated by inflateBackInit() is freed. + + inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream + state was inconsistent. +*/ + +ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +/* Return flags indicating compile-time options. + + Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: + 1.0: size of uInt + 3.2: size of uLong + 5.4: size of voidpf (pointer) + 7.6: size of z_off_t + + Compiler, assembler, and debug options: + 8: DEBUG + 9: ASMV or ASMINF -- use ASM code + 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention + 11: 0 (reserved) + + One-time table building (smaller code, but not thread-safe if true): + 12: BUILDFIXED -- build static block decoding tables when needed + 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed + 14,15: 0 (reserved) + + Library content (indicates missing functionality): + 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking + deflate code when not needed) + 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect + and decode gzip streams (to avoid linking crc code) + 18-19: 0 (reserved) + + Operation variations (changes in library functionality): + 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate + 21: FASTEST -- deflate algorithm with only one, lowest compression level + 22,23: 0 (reserved) + + The sprintf variant used by gzprintf (zero is best): + 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format + 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! + 26: 0 = returns value, 1 = void -- 1 means inferred string length returned + + Remainder: + 27-31: 0 (reserved) + */ + +#ifndef Z_SOLO + + /* utility functions */ + +/* + The following utility functions are implemented on top of the basic + stream-oriented functions. To simplify the interface, some default options + are assumed (compression level and memory usage, standard memory allocation + functions). The source code of these utility functions can be modified if + you need special options. +*/ + +ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Compresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer. +*/ + +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level)); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + +ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +/* + compressBound() returns an upper bound on the compressed size after + compress() or compress2() on sourceLen bytes. It would be used before a + compress() or compress2() call to allocate the destination buffer. +*/ + +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be large enough to hold the entire + uncompressed data. (The size of the uncompressed data must have been saved + previously by the compressor and transmitted to the decompressor by some + mechanism outside the scope of this compression library.) Upon exit, destLen + is the actual size of the uncompressed buffer. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In + the case where there is not enough room, uncompress() will fill the output + buffer with the uncompressed data up to that point. +*/ + + /* gzip file access functions */ + +/* + This library supports reading and writing files in gzip (.gz) format with + an interface similar to that of stdio, using the functions that start with + "gz". The gzip format is different from the zlib format. gzip is a gzip + wrapper, documented in RFC 1952, wrapped around a deflate stream. +*/ + +typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ + +/* +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); + + Opens a gzip (.gz) file for reading or writing. The mode parameter is as + in fopen ("rb" or "wb") but can also include a compression level ("wb9") or + a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only + compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' + for fixed code compression as in "wb9F". (See the description of + deflateInit2 for more information about the strategy parameter.) 'T' will + request transparent writing or appending with no compression and not using + the gzip format. + + "a" can be used instead of "w" to request that the gzip stream that will + be written be appended to the file. "+" will result in an error, since + reading and writing to the same gzip file is not supported. The addition of + "x" when writing will create the file exclusively, which fails if the file + already exists. On systems that support it, the addition of "e" when + reading or writing will set the flag to close the file on an execve() call. + + These functions, as well as gzip, will read and decode a sequence of gzip + streams in a file. The append function of gzopen() can be used to create + such a file. (Also see gzflush() for another way to do this.) When + appending, gzopen does not test whether the file begins with a gzip stream, + nor does it look for the end of the gzip streams to begin appending. gzopen + will simply append a gzip stream to the existing file. + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. When + reading, this will be detected automatically by looking for the magic two- + byte gzip header. + + gzopen returns NULL if the file could not be opened, if there was + insufficient memory to allocate the gzFile state, or if an invalid mode was + specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). + errno can be checked to determine if the reason gzopen failed was that the + file could not be opened. +*/ + +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +/* + gzdopen associates a gzFile with the file descriptor fd. File descriptors + are obtained from calls like open, dup, creat, pipe or fileno (if the file + has been previously opened with fopen). The mode parameter is as in gzopen. + + The next call of gzclose on the returned gzFile will also close the file + descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor + fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, + mode);. The duplicated descriptor should be saved to avoid a leak, since + gzdopen does not close fd if it fails. If you are using fileno() to get the + file descriptor from a FILE *, then you will have to use dup() to avoid + double-close()ing the file descriptor. Both gzclose() and fclose() will + close the associated file descriptor, so they need to have different file + descriptors. + + gzdopen returns NULL if there was insufficient memory to allocate the + gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not + provided, or '+' was provided), or if fd is -1. The file descriptor is not + used until the next gz* read, write, seek, or close operation, so gzdopen + will not detect if fd is invalid (unless fd is -1). +*/ + +ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +/* + Set the internal buffer size used by this library's functions. The + default buffer size is 8192 bytes. This function must be called after + gzopen() or gzdopen(), and before any other calls that read or write the + file. The buffer memory allocation is always deferred to the first read or + write. Two buffers are allocated, either both of the specified size when + writing, or one of the specified size and the other twice that size when + reading. A larger buffer size of, for example, 64K or 128K bytes will + noticeably increase the speed of decompression (reading). + + The new buffer size also affects the maximum length for gzprintf(). + + gzbuffer() returns 0 on success, or -1 on failure, such as being called + too late. +*/ + +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. + + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not + opened for writing. +*/ + +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +/* + Reads the given number of uncompressed bytes from the compressed file. If + the input file is not in gzip format, gzread copies the given number of + bytes into the buffer directly from the file. + + After reaching the end of a gzip stream in the input, gzread will continue + to read, looking for another gzip stream. Any number of gzip streams may be + concatenated in the input file, and will all be decompressed by gzread(). + If something other than a gzip stream is encountered after a gzip stream, + that remaining trailing garbage is ignored (and no error is returned). + + gzread can be used to read a gzip file that is being concurrently written. + Upon reaching the end of the input, gzread will return with the available + data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then + gzclearerr can be used to clear the end of file indicator in order to permit + gzread to be tried again. Z_OK indicates that a gzip stream was completed + on the last gzread. Z_BUF_ERROR indicates that the input file ended in the + middle of a gzip stream. Note that gzread does not return -1 in the event + of an incomplete gzip stream. This error is deferred until gzclose(), which + will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip + stream. Alternatively, gzerror can be used before gzclose to detect this + case. + + gzread returns the number of uncompressed bytes actually read, less than + len for end of file, or -1 for error. +*/ + +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, + voidpc buf, unsigned len)); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes written or 0 in case of + error. +*/ + +ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the arguments to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written, or 0 in case of error. The number of + uncompressed bytes written is limited to 8191, or one less than the buffer + size given to gzbuffer(). The caller should assure that this limit is not + exceeded. If it is exceeded, then gzprintf() will return an error (0) with + nothing written. In this case, there may also be a buffer overflow with + unpredictable consequences, which is possible only if zlib was compiled with + the insecure functions sprintf() or vsprintf() because the secure snprintf() + or vsnprintf() functions were not available. This can be determined using + zlibCompileFlags(). +*/ + +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + + gzputs returns the number of characters written, or -1 in case of error. +*/ + +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +/* + Reads bytes from the compressed file until len-1 characters are read, or a + newline character is read and transferred to buf, or an end-of-file + condition is encountered. If any characters are read or if len == 1, the + string is terminated with a null character. If no characters are read due + to an end-of-file or len < 1, then the buffer is left untouched. + + gzgets returns buf which is a null-terminated string, or it returns NULL + for end-of-file or in case of error. If there was an error, the contents at + buf are indeterminate. +*/ + +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +/* + Writes c, converted to an unsigned char, into the compressed file. gzputc + returns the value that was written, or -1 in case of error. +*/ + +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +/* + Reads one byte from the compressed file. gzgetc returns this byte or -1 + in case of end of file or error. This is implemented as a macro for speed. + As such, it does not do all of the checking the other functions do. I.e. + it does not check to see if file is NULL, nor whether the structure file + points to has been clobbered or not. +*/ + +ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +/* + Push one character back onto the stream to be read as the first character + on the next read. At least one character of push-back is allowed. + gzungetc() returns the character pushed, or -1 on failure. gzungetc() will + fail if c is -1, and may fail if a character has been pushed but not read + yet. If gzungetc is used immediately after gzopen or gzdopen, at least the + output buffer size of pushed characters is allowed. (See gzbuffer above.) + The pushed character will be discarded if the stream is repositioned with + gzseek() or gzrewind(). +*/ + +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +/* + Flushes all pending output into the compressed file. The parameter flush + is as in the deflate() function. The return value is the zlib error number + (see function gzerror below). gzflush is only permitted when writing. + + If the flush parameter is Z_FINISH, the remaining data is written and the + gzip stream is completed in the output. If gzwrite() is called again, a new + gzip stream will be started in the output. gzread() is able to read such + concatented gzip streams. + + gzflush should be called only when strictly necessary because it will + degrade compression if called too often. +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, + z_off_t offset, int whence)); + + Sets the starting position for the next gzread or gzwrite on the given + compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); + + Returns the starting position for the next gzread or gzwrite on the given + compressed file. This position represents a number of bytes in the + uncompressed data stream, and is zero when starting, even if appending or + reading a gzip stream from the middle of a file using gzdopen(). + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); + + Returns the current offset in the file being read or written. This offset + includes the count of bytes that precede the gzip stream, for example when + appending or when using gzdopen() for reading. When reading, the offset + does not include as yet unused buffered input. This information can be used + for a progress indicator. On error, gzoffset() returns -1. +*/ + +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +/* + Returns true (1) if the end-of-file indicator has been set while reading, + false (0) otherwise. Note that the end-of-file indicator is set only if the + read tried to go past the end of the input, but came up short. Therefore, + just like feof(), gzeof() may return false even if there is no more data to + read, in the event that the last read request was for the exact number of + bytes remaining in the input file. This will happen if the input file size + is an exact multiple of the buffer size. + + If gzeof() returns true, then the read functions will return no more data, + unless the end-of-file indicator is reset by gzclearerr() and the input file + has grown since the previous end of file was detected. +*/ + +ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +/* + Returns true (1) if file is being copied directly while reading, or false + (0) if file is a gzip stream being decompressed. + + If the input file is empty, gzdirect() will return true, since the input + does not contain a gzip stream. + + If gzdirect() is used immediately after gzopen() or gzdopen() it will + cause buffers to be allocated to allow reading the file to determine if it + is a gzip file. Therefore if gzbuffer() is used, it should be called before + gzdirect(). + + When writing, gzdirect() returns true (1) if transparent writing was + requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: + gzdirect() is not needed when writing. Transparent writing must be + explicitly requested, so the application already knows the answer. When + linking statically, using gzdirect() will include all of the zlib code for + gzip file reading and decompression, which may not be desired.) +*/ + +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +/* + Flushes all pending output if necessary, closes the compressed file and + deallocates the (de)compression state. Note that once file is closed, you + cannot call gzerror with file, since its structures have been deallocated. + gzclose must not be called more than once on the same file, just as free + must not be called more than once on the same allocation. + + gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a + file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the + last read ended in the middle of a gzip stream, or Z_OK on success. +*/ + +ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +/* + Same as gzclose(), but gzclose_r() is only for use when reading, and + gzclose_w() is only for use when writing or appending. The advantage to + using these instead of gzclose() is that they avoid linking in zlib + compression or decompression code that is not used when only reading or only + writing respectively. If gzclose() is used, then both compression and + decompression code will be included the application when linking to a static + zlib library. +*/ + +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +/* + Returns the error message for the last error which occurred on the given + compressed file. errnum is set to zlib error number. If an error occurred + in the file system and not in the compression library, errnum is set to + Z_ERRNO and the application may consult errno to get the exact error code. + + The application must not modify the returned string. Future calls to + this function may invalidate the previously returned string. If file is + closed, then the string previously returned by gzerror will no longer be + available. + + gzerror() should be used to distinguish errors from end-of-file for those + functions above that do not distinguish those cases in their return values. +*/ + +ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +/* + Clears the error and end-of-file flags for file. This is analogous to the + clearerr() function in stdio. This is useful for continuing to read a gzip + file that is being written concurrently. +*/ + +#endif /* !Z_SOLO */ + + /* checksum functions */ + +/* + These functions are not related to compression but are exported + anyway because they might be useful in applications using the compression + library. +*/ + +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +/* + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is Z_NULL, this function returns the + required initial value for the checksum. + + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. + + Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, + z_off_t len2)); + + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 + and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for + each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note + that the z_off_t type (like off_t) is a signed integer. If len2 is + negative, the result has no meaning or utility. +*/ + +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +/* + Update a running CRC-32 with the bytes buf[0..len-1] and return the + updated CRC-32. If buf is Z_NULL, this function returns the required + initial value for the crc. Pre- and post-conditioning (one's complement) is + performed within this function so it shouldn't be done by the application. + + Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); + + Combine two CRC-32 check values into one. For two sequences of bytes, + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and + len2. +*/ + + + /* various hacks, don't look :) */ + +/* deflateInit and inflateInit are macros to allow checking the zlib version + * and the compiler's view of z_stream: + */ +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size)); +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size)); +#define deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) +#define inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) +#define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ + (int)sizeof(z_stream)) +#define inflateBackInit(strm, windowBits, window) \ + inflateBackInit_((strm), (windowBits), (window), \ + ZLIB_VERSION, (int)sizeof(z_stream)) + +#ifndef Z_SOLO + +/* gzgetc() macro and its supporting function and exposed data structure. Note + * that the real internal state is much larger than the exposed structure. + * This abbreviated structure exposes just enough for the gzgetc() macro. The + * user should not mess with these exposed elements, since their names or + * behavior could change in the future, perhaps even capriciously. They can + * only be used by the gzgetc() macro. You have been warned. + */ +struct gzFile_s { + unsigned have; + unsigned char *next; + z_off64_t pos; +}; +ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ +#ifdef Z_PREFIX_SET +# undef z_gzgetc +# define z_gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) +#else +# undef gzgetc +# define gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) +#endif + +/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or + * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if + * both are true, the application gets the *64 functions, and the regular + * functions are changed to 64 bits) -- in case these are set on systems + * without large file support, _LFS64_LARGEFILE must also be true + */ +#ifdef Z_LARGE64 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); + ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); +#endif + +#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) +# ifdef Z_PREFIX_SET +# define z_gzopen z_gzopen64 +# define z_gzseek z_gzseek64 +# define z_gztell z_gztell64 +# define z_gzoffset z_gzoffset64 +# define z_adler32_combine z_adler32_combine64 +# define z_crc32_combine z_crc32_combine64 +# else +# define gzopen gzopen64 +# define gzseek gzseek64 +# define gztell gztell64 +# define gzoffset gzoffset64 +# define adler32_combine adler32_combine64 +# define crc32_combine crc32_combine64 +# endif +# ifndef Z_LARGE64 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); +# endif +#else + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); +#endif + +#else /* Z_SOLO */ + + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); + +#endif /* !Z_SOLO */ + +/* hack for buggy compilers */ +#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) + struct internal_state {int dummy;}; +#endif + +/* undocumented functions */ +ZEXTERN const char * ZEXPORT zError OF((int)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); +ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); +ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); +ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); +ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); +#if defined(_WIN32) && !defined(Z_SOLO) +ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, + const char *mode)); +#endif +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +# ifndef Z_SOLO +ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, + const char *format, + va_list va)); +# endif +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* ZLIB_H */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js-config.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js-config.h new file mode 100644 index 0000000000..774d938667 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js-config.h @@ -0,0 +1,53 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sw=4 et tw=78: + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_config_h +#define js_config_h + +/* Definitions set at build time that affect SpiderMonkey's public API. + This header file is generated by the SpiderMonkey configure script, + and installed along with jsapi.h. */ + +/* Define to 1 if SpiderMonkey is in debug mode. */ +/* #undef JS_DEBUG */ + +/* Define to 1 if SpiderMonkey should not use struct types in debug builds. */ +/* #undef JS_NO_JSVAL_JSID_STRUCT_TYPES */ + +/* Define to 1 if SpiderMonkey should support multi-threaded clients. */ +/* #undef JS_THREADSAFE */ + +/* Define to 1 if SpiderMonkey should include ctypes support. */ +#define JS_HAS_CTYPES 1 + +/* Define to 1 if SpiderMonkey should support the ability to perform + entirely too much GC. */ +#define JS_GC_ZEAL 1 + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +/* #undef JS_HAVE_ENDIAN_H */ + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +/* #undef JS_HAVE_MACHINE_ENDIAN_H */ + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +/* #undef JS_HAVE_SYS_ISA_DEFS_H */ + +/* Define to 1 if SpiderMonkey is in NUNBOX32 mode. */ +#define JS_NUNBOX32 1 + +/* Define to 1 if SpiderMonkey is in PUNBOX64 mode. */ +/* #undef JS_PUNBOX64 */ + +/* MOZILLA JSAPI version number components */ +#define MOZJS_MAJOR_VERSION 33 +#define MOZJS_MINOR_VERSION 1 + +#endif /* js_config_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js.msg b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js.msg new file mode 100644 index 0000000000..d342ad4506 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js.msg @@ -0,0 +1,443 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * This is the JavaScript error message file. + * + * The format for each JS error message is: + * + * MSG_DEF(, , , , + * ) + * + * where ; + * is a legal C identifer that will be used in the + * JS engine source. + * + * is an unique integral value identifying this error. + * + * is an integer literal specifying the total number of + * replaceable arguments in the following format string. + * + * is an exception index from the enum in jsexn.c; + * JSEXN_NONE for none. The given exception index will be raised by the + * engine when the corresponding error occurs. + * + * is a string literal, optionally containing sequences + * {X} where X is an integer representing the argument number that will + * be replaced with a string value when the error is reported. + * + * e.g. + * + * MSG_DEF(JSMSG_NOT_A_SUBSPECIES, 73, JSEXN_NONE, 2, + * "{0} is not a member of the {1} family") + * + * can be used: + * + * JS_ReportErrorNumber(JSMSG_NOT_A_SUBSPECIES, "Rhino", "Monkey"); + * + * to report: + * + * "Rhino is not a member of the Monkey family" + * + * When removing MSG_DEFs, convert them to JSMSG_UNUSED placeholders: + * + * MSG_DEF(JSMSG_UNUSED7, 7, 0, JSEXN_NONE, "") + * + * Before adding a new MSG_DEF at the end, look for existing JSMSG_UNUSED + * free index placeholders in the middle of the list. + */ + +MSG_DEF(JSMSG_NOT_AN_ERROR, 0, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_NOT_DEFINED, 1, 1, JSEXN_REFERENCEERR, "{0} is not defined") +MSG_DEF(JSMSG_INACTIVE, 2, 0, JSEXN_INTERNALERR, "nothing active on context") +MSG_DEF(JSMSG_MORE_ARGS_NEEDED, 3, 3, JSEXN_TYPEERR, "{0} requires more than {1} argument{2}") +MSG_DEF(JSMSG_BAD_CHAR, 4, 1, JSEXN_INTERNALERR, "invalid format character {0}") +MSG_DEF(JSMSG_BAD_TYPE, 5, 1, JSEXN_TYPEERR, "unknown type {0}") +MSG_DEF(JSMSG_ALLOC_OVERFLOW, 6, 0, JSEXN_INTERNALERR, "allocation size overflow") +MSG_DEF(JSMSG_MISSING_HEXDIGITS, 7, 0, JSEXN_SYNTAXERR, "missing hexadecimal digits after '0x'") +MSG_DEF(JSMSG_INCOMPATIBLE_PROTO, 8, 3, JSEXN_TYPEERR, "{0}.prototype.{1} called on incompatible {2}") +MSG_DEF(JSMSG_NO_CONSTRUCTOR, 9, 1, JSEXN_TYPEERR, "{0} has no constructor") +MSG_DEF(JSMSG_CANT_ALIAS, 10, 3, JSEXN_TYPEERR, "can't alias {0} to {1} in class {2}") +MSG_DEF(JSMSG_NOT_SCRIPTED_FUNCTION, 11, 1, JSEXN_TYPEERR, "{0} is not a scripted function") +MSG_DEF(JSMSG_BAD_SORT_ARG, 12, 0, JSEXN_TYPEERR, "invalid Array.prototype.sort argument") +MSG_DEF(JSMSG_BAD_ATOMIC_NUMBER, 13, 1, JSEXN_INTERNALERR, "internal error: no index for atom {0}") +MSG_DEF(JSMSG_TOO_MANY_LITERALS, 14, 0, JSEXN_INTERNALERR, "too many literals") +MSG_DEF(JSMSG_CANT_WATCH, 15, 1, JSEXN_TYPEERR, "can't watch non-native objects of class {0}") +MSG_DEF(JSMSG_STACK_UNDERFLOW, 16, 2, JSEXN_INTERNALERR, "internal error compiling {0}: stack underflow at pc {1}") +MSG_DEF(JSMSG_NEED_DIET, 17, 1, JSEXN_INTERNALERR, "{0} too large") +MSG_DEF(JSMSG_TOO_MANY_LOCAL_ROOTS, 18, 0, JSEXN_ERR, "out of local root space") +MSG_DEF(JSMSG_READ_ONLY, 19, 1, JSEXN_TYPEERR, "{0} is read-only") +MSG_DEF(JSMSG_BAD_FORMAL, 20, 0, JSEXN_SYNTAXERR, "malformed formal parameter") +MSG_DEF(JSMSG_CANT_DELETE, 21, 1, JSEXN_TYPEERR, "property {0} is non-configurable and can't be deleted") +MSG_DEF(JSMSG_NOT_FUNCTION, 22, 1, JSEXN_TYPEERR, "{0} is not a function") +MSG_DEF(JSMSG_NOT_CONSTRUCTOR, 23, 1, JSEXN_TYPEERR, "{0} is not a constructor") +MSG_DEF(JSMSG_INVALID_DATE, 24, 0, JSEXN_RANGEERR, "invalid date") +MSG_DEF(JSMSG_TOO_DEEP, 25, 1, JSEXN_INTERNALERR, "{0} nested too deeply") +MSG_DEF(JSMSG_OVER_RECURSED, 26, 0, JSEXN_INTERNALERR, "too much recursion") +MSG_DEF(JSMSG_IN_NOT_OBJECT, 27, 1, JSEXN_TYPEERR, "invalid 'in' operand {0}") +MSG_DEF(JSMSG_BAD_NEW_RESULT, 28, 1, JSEXN_TYPEERR, "invalid new expression result {0}") +MSG_DEF(JSMSG_OBJECT_ACCESS_DENIED, 29, 0, JSEXN_ERR, "Permission denied to access object") +MSG_DEF(JSMSG_PROPERTY_ACCESS_DENIED, 30, 1, JSEXN_ERR, "Permission denied to access property '{0}'") +MSG_DEF(JSMSG_BAD_INSTANCEOF_RHS, 31, 1, JSEXN_TYPEERR, "invalid 'instanceof' operand {0}") +MSG_DEF(JSMSG_BAD_BYTECODE, 32, 1, JSEXN_INTERNALERR, "unimplemented JavaScript bytecode {0}") +MSG_DEF(JSMSG_BAD_RADIX, 33, 0, JSEXN_RANGEERR, "radix must be an integer at least 2 and no greater than 36") +MSG_DEF(JSMSG_PAREN_BEFORE_LET, 34, 0, JSEXN_SYNTAXERR, "missing ( before let head") +MSG_DEF(JSMSG_CANT_CONVERT, 35, 1, JSEXN_ERR, "can't convert {0} to an integer") +MSG_DEF(JSMSG_CYCLIC_VALUE, 36, 1, JSEXN_TYPEERR, "cyclic {0} value") +MSG_DEF(JSMSG_COMPILE_EXECED_SCRIPT, 37, 0, JSEXN_TYPEERR, "can't compile over a script that is currently executing") +MSG_DEF(JSMSG_CANT_CONVERT_TO, 38, 2, JSEXN_TYPEERR, "can't convert {0} to {1}") +MSG_DEF(JSMSG_NO_PROPERTIES, 39, 1, JSEXN_TYPEERR, "{0} has no properties") +MSG_DEF(JSMSG_CANT_FIND_CLASS, 40, 1, JSEXN_TYPEERR, "can't find class id {0}") +MSG_DEF(JSMSG_DEAD_OBJECT, 41, 0, JSEXN_TYPEERR, "can't access dead object") +MSG_DEF(JSMSG_BYTECODE_TOO_BIG, 42, 2, JSEXN_INTERNALERR, "bytecode {0} too large (limit {1})") +MSG_DEF(JSMSG_UNKNOWN_FORMAT, 43, 1, JSEXN_INTERNALERR, "unknown bytecode format {0}") +MSG_DEF(JSMSG_TOO_MANY_CON_ARGS, 44, 0, JSEXN_SYNTAXERR, "too many constructor arguments") +MSG_DEF(JSMSG_TOO_MANY_FUN_ARGS, 45, 0, JSEXN_SYNTAXERR, "too many function arguments") +MSG_DEF(JSMSG_BAD_QUANTIFIER, 46, 0, JSEXN_SYNTAXERR, "invalid quantifier") +MSG_DEF(JSMSG_MIN_TOO_BIG, 47, 1, JSEXN_SYNTAXERR, "overlarge minimum {0}") +MSG_DEF(JSMSG_MAX_TOO_BIG, 48, 1, JSEXN_SYNTAXERR, "overlarge maximum {0}") +MSG_DEF(JSMSG_OUT_OF_ORDER, 49, 1, JSEXN_SYNTAXERR, "maximum {0} less than minimum") +MSG_DEF(JSMSG_BAD_DESTRUCT_DECL, 50, 0, JSEXN_SYNTAXERR, "missing = in destructuring declaration") +MSG_DEF(JSMSG_BAD_DESTRUCT_ASS, 51, 0, JSEXN_REFERENCEERR, "invalid destructuring assignment operator") +MSG_DEF(JSMSG_PAREN_AFTER_LET, 52, 0, JSEXN_SYNTAXERR, "missing ) after let head") +MSG_DEF(JSMSG_CURLY_AFTER_LET, 53, 0, JSEXN_SYNTAXERR, "missing } after let block") +MSG_DEF(JSMSG_MISSING_PAREN, 54, 0, JSEXN_SYNTAXERR, "unterminated parenthetical") +MSG_DEF(JSMSG_UNTERM_CLASS, 55, 0, JSEXN_SYNTAXERR, "unterminated character class") +MSG_DEF(JSMSG_TRAILING_SLASH, 56, 0, JSEXN_SYNTAXERR, "trailing \\ in regular expression") +MSG_DEF(JSMSG_BAD_CLASS_RANGE, 57, 0, JSEXN_SYNTAXERR, "invalid range in character class") +MSG_DEF(JSMSG_BAD_REGEXP_FLAG, 58, 1, JSEXN_SYNTAXERR, "invalid regular expression flag {0}") +MSG_DEF(JSMSG_NO_INPUT, 59, 5, JSEXN_SYNTAXERR, "no input for /{0}/{1}{2}{3}{4}") +MSG_DEF(JSMSG_CANT_OPEN, 60, 2, JSEXN_ERR, "can't open {0}: {1}") +MSG_DEF(JSMSG_TOO_MANY_FUN_APPLY_ARGS, 61, 0, JSEXN_RANGEERR, "arguments array passed to Function.prototype.apply is too large") +MSG_DEF(JSMSG_UNMATCHED_RIGHT_PAREN, 62, 0, JSEXN_SYNTAXERR, "unmatched ) in regular expression") +MSG_DEF(JSMSG_TOO_BIG_TO_ENCODE, 63, 0, JSEXN_INTERNALERR, "data are to big to encode") +MSG_DEF(JSMSG_ARG_INDEX_OUT_OF_RANGE, 64, 1, JSEXN_RANGEERR, "argument {0} accesses an index that is out of range") +MSG_DEF(JSMSG_SPREAD_TOO_LARGE, 65, 0, JSEXN_RANGEERR, "array too large due to spread operand(s)") +MSG_DEF(JSMSG_SOURCE_TOO_LONG, 66, 0, JSEXN_RANGEERR, "source is too long") +MSG_DEF(JSMSG_BAD_WEAKMAP_KEY, 67, 0, JSEXN_TYPEERR, "cannot use the given object as a weak map key") +MSG_DEF(JSMSG_BAD_SCRIPT_MAGIC, 68, 0, JSEXN_INTERNALERR, "bad script XDR magic number") +MSG_DEF(JSMSG_PAREN_BEFORE_FORMAL, 69, 0, JSEXN_SYNTAXERR, "missing ( before formal parameters") +MSG_DEF(JSMSG_MISSING_FORMAL, 70, 0, JSEXN_SYNTAXERR, "missing formal parameter") +MSG_DEF(JSMSG_PAREN_AFTER_FORMAL, 71, 0, JSEXN_SYNTAXERR, "missing ) after formal parameters") +MSG_DEF(JSMSG_CURLY_BEFORE_BODY, 72, 0, JSEXN_SYNTAXERR, "missing { before function body") +MSG_DEF(JSMSG_CURLY_AFTER_BODY, 73, 0, JSEXN_SYNTAXERR, "missing } after function body") +MSG_DEF(JSMSG_PAREN_BEFORE_COND, 74, 0, JSEXN_SYNTAXERR, "missing ( before condition") +MSG_DEF(JSMSG_PAREN_AFTER_COND, 75, 0, JSEXN_SYNTAXERR, "missing ) after condition") +MSG_DEF(JSMSG_BAD_DUP_ARGS, 76, 0, JSEXN_SYNTAXERR, "duplicate argument names not allowed in this context") +MSG_DEF(JSMSG_NAME_AFTER_DOT, 77, 0, JSEXN_SYNTAXERR, "missing name after . operator") +MSG_DEF(JSMSG_BRACKET_IN_INDEX, 78, 0, JSEXN_SYNTAXERR, "missing ] in index expression") +MSG_DEF(JSMSG_ACCESSOR_DEF_DENIED, 79, 1, JSEXN_ERR, "Permission denied to define accessor property '{0}'") +MSG_DEF(JSMSG_PAREN_BEFORE_SWITCH, 80, 0, JSEXN_SYNTAXERR, "missing ( before switch expression") +MSG_DEF(JSMSG_PAREN_AFTER_SWITCH, 81, 0, JSEXN_SYNTAXERR, "missing ) after switch expression") +MSG_DEF(JSMSG_CURLY_BEFORE_SWITCH, 82, 0, JSEXN_SYNTAXERR, "missing { before switch body") +MSG_DEF(JSMSG_COLON_AFTER_CASE, 83, 0, JSEXN_SYNTAXERR, "missing : after case label") +MSG_DEF(JSMSG_WHILE_AFTER_DO, 84, 0, JSEXN_SYNTAXERR, "missing while after do-loop body") +MSG_DEF(JSMSG_PAREN_AFTER_FOR, 85, 0, JSEXN_SYNTAXERR, "missing ( after for") +MSG_DEF(JSMSG_SEMI_AFTER_FOR_INIT, 86, 0, JSEXN_SYNTAXERR, "missing ; after for-loop initializer") +MSG_DEF(JSMSG_SEMI_AFTER_FOR_COND, 87, 0, JSEXN_SYNTAXERR, "missing ; after for-loop condition") +MSG_DEF(JSMSG_PAREN_AFTER_FOR_CTRL, 88, 0, JSEXN_SYNTAXERR, "missing ) after for-loop control") +MSG_DEF(JSMSG_CURLY_BEFORE_TRY, 89, 0, JSEXN_SYNTAXERR, "missing { before try block") +MSG_DEF(JSMSG_CURLY_AFTER_TRY, 90, 0, JSEXN_SYNTAXERR, "missing } after try block") +MSG_DEF(JSMSG_PAREN_BEFORE_CATCH, 91, 0, JSEXN_SYNTAXERR, "missing ( before catch") +MSG_DEF(JSMSG_CATCH_IDENTIFIER, 92, 0, JSEXN_SYNTAXERR, "missing identifier in catch") +MSG_DEF(JSMSG_PAREN_AFTER_CATCH, 93, 0, JSEXN_SYNTAXERR, "missing ) after catch") +MSG_DEF(JSMSG_CURLY_BEFORE_CATCH, 94, 0, JSEXN_SYNTAXERR, "missing { before catch block") +MSG_DEF(JSMSG_CURLY_AFTER_CATCH, 95, 0, JSEXN_SYNTAXERR, "missing } after catch block") +MSG_DEF(JSMSG_CURLY_BEFORE_FINALLY, 96, 0, JSEXN_SYNTAXERR, "missing { before finally block") +MSG_DEF(JSMSG_CURLY_AFTER_FINALLY, 97, 0, JSEXN_SYNTAXERR, "missing } after finally block") +MSG_DEF(JSMSG_CATCH_OR_FINALLY, 98, 0, JSEXN_SYNTAXERR, "missing catch or finally after try") +MSG_DEF(JSMSG_PAREN_BEFORE_WITH, 99, 0, JSEXN_SYNTAXERR, "missing ( before with-statement object") +MSG_DEF(JSMSG_PAREN_AFTER_WITH, 100, 0, JSEXN_SYNTAXERR, "missing ) after with-statement object") +MSG_DEF(JSMSG_CURLY_IN_COMPOUND, 101, 0, JSEXN_SYNTAXERR, "missing } in compound statement") +MSG_DEF(JSMSG_NO_VARIABLE_NAME, 102, 0, JSEXN_SYNTAXERR, "missing variable name") +MSG_DEF(JSMSG_COLON_IN_COND, 103, 0, JSEXN_SYNTAXERR, "missing : in conditional expression") +MSG_DEF(JSMSG_PAREN_AFTER_ARGS, 104, 0, JSEXN_SYNTAXERR, "missing ) after argument list") +MSG_DEF(JSMSG_BRACKET_AFTER_LIST, 105, 0, JSEXN_SYNTAXERR, "missing ] after element list") +MSG_DEF(JSMSG_COLON_AFTER_ID, 106, 0, JSEXN_SYNTAXERR, "missing : after property id") +MSG_DEF(JSMSG_CURLY_AFTER_LIST, 107, 0, JSEXN_SYNTAXERR, "missing } after property list") +MSG_DEF(JSMSG_PAREN_IN_PAREN, 108, 0, JSEXN_SYNTAXERR, "missing ) in parenthetical") +MSG_DEF(JSMSG_SEMI_BEFORE_STMNT, 109, 0, JSEXN_SYNTAXERR, "missing ; before statement") +MSG_DEF(JSMSG_NO_RETURN_VALUE, 110, 1, JSEXN_TYPEERR, "function {0} does not always return a value") +MSG_DEF(JSMSG_DUPLICATE_FORMAL, 111, 1, JSEXN_SYNTAXERR, "duplicate formal argument {0}") +MSG_DEF(JSMSG_EQUAL_AS_ASSIGN, 112, 0, JSEXN_SYNTAXERR, "test for equality (==) mistyped as assignment (=)?") +MSG_DEF(JSMSG_OPTIMIZED_CLOSURE_LEAK, 113, 0, JSEXN_INTERNALERR, "can't access optimized closure") +MSG_DEF(JSMSG_TOO_MANY_DEFAULTS, 114, 0, JSEXN_SYNTAXERR, "more than one switch default") +MSG_DEF(JSMSG_TOO_MANY_CASES, 115, 0, JSEXN_INTERNALERR, "too many switch cases") +MSG_DEF(JSMSG_BAD_SWITCH, 116, 0, JSEXN_SYNTAXERR, "invalid switch statement") +MSG_DEF(JSMSG_BAD_FOR_LEFTSIDE, 117, 0, JSEXN_SYNTAXERR, "invalid for/in left-hand side") +MSG_DEF(JSMSG_CATCH_AFTER_GENERAL, 118, 0, JSEXN_SYNTAXERR, "catch after unconditional catch") +MSG_DEF(JSMSG_CATCH_WITHOUT_TRY, 119, 0, JSEXN_SYNTAXERR, "catch without try") +MSG_DEF(JSMSG_FINALLY_WITHOUT_TRY, 120, 0, JSEXN_SYNTAXERR, "finally without try") +MSG_DEF(JSMSG_LABEL_NOT_FOUND, 121, 0, JSEXN_SYNTAXERR, "label not found") +MSG_DEF(JSMSG_TOUGH_BREAK, 122, 0, JSEXN_SYNTAXERR, "unlabeled break must be inside loop or switch") +MSG_DEF(JSMSG_BAD_CONTINUE, 123, 0, JSEXN_SYNTAXERR, "continue must be inside loop") +MSG_DEF(JSMSG_BAD_RETURN_OR_YIELD, 124, 1, JSEXN_SYNTAXERR, "{0} not in function") +MSG_DEF(JSMSG_BAD_LABEL, 125, 0, JSEXN_SYNTAXERR, "invalid label") +MSG_DEF(JSMSG_DUPLICATE_LABEL, 126, 0, JSEXN_SYNTAXERR, "duplicate label") +MSG_DEF(JSMSG_VAR_HIDES_ARG, 127, 1, JSEXN_TYPEERR, "variable {0} redeclares argument") +MSG_DEF(JSMSG_BAD_VAR_INIT, 128, 0, JSEXN_SYNTAXERR, "invalid variable initialization") +MSG_DEF(JSMSG_BAD_LEFTSIDE_OF_ASS, 129, 0, JSEXN_REFERENCEERR, "invalid assignment left-hand side") +MSG_DEF(JSMSG_BAD_OPERAND, 130, 1, JSEXN_SYNTAXERR, "invalid {0} operand") +MSG_DEF(JSMSG_BAD_PROP_ID, 131, 0, JSEXN_SYNTAXERR, "invalid property id") +MSG_DEF(JSMSG_RESERVED_ID, 132, 1, JSEXN_SYNTAXERR, "{0} is a reserved identifier") +MSG_DEF(JSMSG_SYNTAX_ERROR, 133, 0, JSEXN_SYNTAXERR, "syntax error") +MSG_DEF(JSMSG_MISSING_BINARY_DIGITS, 134, 0, JSEXN_SYNTAXERR, "missing binary digits after '0b'") +MSG_DEF(JSMSG_BAD_PROTOTYPE, 135, 1, JSEXN_TYPEERR, "'prototype' property of {0} is not an object") +MSG_DEF(JSMSG_MISSING_EXPONENT, 136, 0, JSEXN_SYNTAXERR, "missing exponent") +MSG_DEF(JSMSG_OUT_OF_MEMORY, 137, 0, JSEXN_ERR, "out of memory") +MSG_DEF(JSMSG_UNTERMINATED_STRING, 138, 0, JSEXN_SYNTAXERR, "unterminated string literal") +MSG_DEF(JSMSG_TOO_MANY_PARENS, 139, 0, JSEXN_INTERNALERR, "too many parentheses in regular expression") +MSG_DEF(JSMSG_UNTERMINATED_COMMENT, 140, 0, JSEXN_SYNTAXERR, "unterminated comment") +MSG_DEF(JSMSG_UNTERMINATED_REGEXP, 141, 0, JSEXN_SYNTAXERR, "unterminated regular expression literal") +MSG_DEF(JSMSG_BAD_CLONE_FUNOBJ_SCOPE, 142, 0, JSEXN_TYPEERR, "bad cloned function scope chain") +MSG_DEF(JSMSG_MISSING_OCTAL_DIGITS, 143, 0, JSEXN_SYNTAXERR, "missing octal digits after '0o'") +MSG_DEF(JSMSG_ILLEGAL_CHARACTER, 144, 0, JSEXN_SYNTAXERR, "illegal character") +MSG_DEF(JSMSG_BAD_OCTAL, 145, 1, JSEXN_SYNTAXERR, "{0} is not a legal ECMA-262 octal constant") +MSG_DEF(JSMSG_RESULTING_STRING_TOO_LARGE, 146, 0, JSEXN_RANGEERR, "repeat count must be less than infinity and not overflow maximum string size") +MSG_DEF(JSMSG_UNCAUGHT_EXCEPTION, 147, 1, JSEXN_INTERNALERR, "uncaught exception: {0}") +MSG_DEF(JSMSG_INVALID_BACKREF, 148, 0, JSEXN_SYNTAXERR, "non-octal digit in an escape sequence that doesn't match a back-reference") +MSG_DEF(JSMSG_BAD_BACKREF, 149, 0, JSEXN_SYNTAXERR, "back-reference exceeds number of capturing parentheses") +MSG_DEF(JSMSG_PRECISION_RANGE, 150, 1, JSEXN_RANGEERR, "precision {0} out of range") +MSG_DEF(JSMSG_BAD_GETTER_OR_SETTER, 151, 1, JSEXN_TYPEERR, "invalid {0} usage") +MSG_DEF(JSMSG_BAD_ARRAY_LENGTH, 152, 0, JSEXN_RANGEERR, "invalid array length") +MSG_DEF(JSMSG_CANT_DESCRIBE_PROPS, 153, 1, JSEXN_TYPEERR, "can't describe non-native properties of class {0}") +MSG_DEF(JSMSG_BAD_APPLY_ARGS, 154, 1, JSEXN_TYPEERR, "second argument to Function.prototype.{0} must be an array") +MSG_DEF(JSMSG_REDECLARED_VAR, 155, 2, JSEXN_TYPEERR, "redeclaration of {0} {1}") +MSG_DEF(JSMSG_UNDECLARED_VAR, 156, 1, JSEXN_REFERENCEERR, "assignment to undeclared variable {0}") +MSG_DEF(JSMSG_ANON_NO_RETURN_VALUE, 157, 0, JSEXN_TYPEERR, "anonymous function does not always return a value") +MSG_DEF(JSMSG_DEPRECATED_USAGE, 158, 1, JSEXN_REFERENCEERR, "deprecated {0} usage") +MSG_DEF(JSMSG_BAD_URI, 159, 0, JSEXN_URIERR, "malformed URI sequence") +MSG_DEF(JSMSG_GETTER_ONLY, 160, 0, JSEXN_TYPEERR, "setting a property that has only a getter") +MSG_DEF(JSMSG_IDSTART_AFTER_NUMBER, 161, 0, JSEXN_SYNTAXERR, "identifier starts immediately after numeric literal") +MSG_DEF(JSMSG_UNDEFINED_PROP, 162, 1, JSEXN_REFERENCEERR, "reference to undefined property {0}") +MSG_DEF(JSMSG_USELESS_EXPR, 163, 0, JSEXN_TYPEERR, "useless expression") +MSG_DEF(JSMSG_REDECLARED_PARAM, 164, 1, JSEXN_TYPEERR, "redeclaration of formal parameter {0}") +MSG_DEF(JSMSG_NEWREGEXP_FLAGGED, 165, 0, JSEXN_TYPEERR, "can't supply flags when constructing one RegExp from another") +MSG_DEF(JSMSG_RESERVED_SLOT_RANGE, 166, 0, JSEXN_RANGEERR, "reserved slot index out of range") +MSG_DEF(JSMSG_CANT_DECODE_PRINCIPALS, 167, 0, JSEXN_INTERNALERR, "can't decode JSPrincipals") +MSG_DEF(JSMSG_CANT_SEAL_OBJECT, 168, 1, JSEXN_ERR, "can't seal {0} objects") +MSG_DEF(JSMSG_TOO_MANY_CATCH_VARS, 169, 0, JSEXN_SYNTAXERR, "too many catch variables") +MSG_DEF(JSMSG_NEGATIVE_REPETITION_COUNT, 170, 0, JSEXN_RANGEERR, "repeat count must be non-negative") +MSG_DEF(JSMSG_INVALID_FOR_OF_INIT, 171, 0, JSEXN_SYNTAXERR, "for-of loop variable declaration may not have an initializer") +MSG_DEF(JSMSG_INVALID_MAP_ITERABLE, 172, 0, JSEXN_TYPEERR, "iterable for map should have array-like objects") +MSG_DEF(JSMSG_NOT_A_CODEPOINT, 173, 1, JSEXN_RANGEERR, "{0} is not a valid code point") +MSG_DEF(JSMSG_BRACKET_AFTER_ARRAY_COMPREHENSION, 174, 0, JSEXN_SYNTAXERR, "missing ] after array comprehension") +MSG_DEF(JSMSG_NESTING_GENERATOR, 175, 0, JSEXN_TYPEERR, "already executing generator") +MSG_DEF(JSMSG_PAREN_AFTER_FOR_OF_ITERABLE, 176, 0, JSEXN_SYNTAXERR, "missing ) after for-of iterable") +MSG_DEF(JSMSG_INVALID_NORMALIZE_FORM, 177, 0, JSEXN_RANGEERR, "form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD'") +MSG_DEF(JSMSG_NOTHING_TO_REPEAT, 178, 0, JSEXN_SYNTAXERR, "nothing to repeat") +MSG_DEF(JSMSG_INVALID_GROUP, 179, 0, JSEXN_SYNTAXERR, "invalid regexp group") +MSG_DEF(JSMSG_ESCAPE_AT_END_OF_REGEXP, 180, 0, JSEXN_SYNTAXERR, "\\ at end of pattern") +MSG_DEF(JSMSG_NUMBERS_OUT_OF_ORDER, 181, 0, JSEXN_SYNTAXERR, "numbers out of order in {} quantifier.") +MSG_DEF(JSMSG_BAD_GENERATOR_SEND, 182, 1, JSEXN_TYPEERR, "attempt to send {0} to newborn generator") +MSG_DEF(JSMSG_SC_NOT_TRANSFERABLE, 183, 0, JSEXN_TYPEERR, "invalid transferable array for structured clone") +MSG_DEF(JSMSG_SC_DUP_TRANSFERABLE, 184, 0, JSEXN_TYPEERR, "duplicate transferable for structured clone") +MSG_DEF(JSMSG_CANT_REPORT_AS_NON_EXTENSIBLE, 185, 0, JSEXN_TYPEERR, "proxy can't report an extensible object as non-extensible") +MSG_DEF(JSMSG_SYMBOL_TO_STRING, 186, 0, JSEXN_TYPEERR, "can't convert symbol to string") +MSG_DEF(JSMSG_UNUSED187, 187, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_INCOMPATIBLE_METHOD, 188, 3, JSEXN_TYPEERR, "{0} {1} called on incompatible {2}") +MSG_DEF(JSMSG_SYMBOL_TO_PRIMITIVE, 189, 0, JSEXN_TYPEERR, "can't convert symbol object to primitive") +MSG_DEF(JSMSG_UNUSED190, 190, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_BAD_INDEX, 191, 0, JSEXN_RANGEERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_SELFHOSTED_TOP_LEVEL_LET,192,0, JSEXN_SYNTAXERR, "self-hosted code cannot contain top-level 'let' declarations") +MSG_DEF(JSMSG_BAD_FOR_EACH_LOOP, 193, 0, JSEXN_SYNTAXERR, "invalid for each loop") +MSG_DEF(JSMSG_OBJECT_WATCH_DEPRECATED,194, 0, JSEXN_NONE, "Object.prototype.watch and unwatch are very slow, non-standard, and deprecated; use a getter/setter instead") +MSG_DEF(JSMSG_TYPE_ERR_BAD_ARGS, 195, 0, JSEXN_TYPEERR, "invalid arguments") +MSG_DEF(JSMSG_REDECLARED_CATCH_IDENTIFIER, 196, 1, JSEXN_TYPEERR, "redeclaration of identifier '{0}' in catch") +MSG_DEF(JSMSG_INTERNAL_INTL_ERROR, 197, 0, JSEXN_ERR, "internal error while computing Intl data") +MSG_DEF(JSMSG_DEFAULT_LOCALE_ERROR, 198, 0, JSEXN_ERR, "internal error getting the default locale") +MSG_DEF(JSMSG_TOO_MANY_LOCALS, 199, 0, JSEXN_SYNTAXERR, "too many local variables") +MSG_DEF(JSMSG_ARRAY_INIT_TOO_BIG, 200, 0, JSEXN_INTERNALERR, "array initialiser too large") +MSG_DEF(JSMSG_REGEXP_TOO_COMPLEX, 201, 0, JSEXN_INTERNALERR, "regular expression too complex") +MSG_DEF(JSMSG_BUFFER_TOO_SMALL, 202, 0, JSEXN_INTERNALERR, "buffer too small") +MSG_DEF(JSMSG_BAD_SURROGATE_CHAR, 203, 1, JSEXN_TYPEERR, "bad surrogate character {0}") +MSG_DEF(JSMSG_UTF8_CHAR_TOO_LARGE, 204, 1, JSEXN_TYPEERR, "UTF-8 character {0} too large") +MSG_DEF(JSMSG_MALFORMED_UTF8_CHAR, 205, 1, JSEXN_TYPEERR, "malformed UTF-8 character sequence at offset {0}") +MSG_DEF(JSMSG_USER_DEFINED_ERROR, 206, 0, JSEXN_ERR, "JS_ReportError was called") +MSG_DEF(JSMSG_WRONG_CONSTRUCTOR, 207, 1, JSEXN_TYPEERR, "wrong constructor called for {0}") +MSG_DEF(JSMSG_BAD_GENERATOR_RETURN, 208, 1, JSEXN_TYPEERR, "generator function {0} returns a value") +MSG_DEF(JSMSG_BAD_ANON_GENERATOR_RETURN, 209, 0, JSEXN_TYPEERR, "anonymous generator function returns a value") +MSG_DEF(JSMSG_PROTO_SETTING_SLOW, 210, 0, JSEXN_NONE, "mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create") +MSG_DEF(JSMSG_IN_AFTER_FOR_NAME, 211, 0, JSEXN_SYNTAXERR, "missing 'in' or 'of' after for") +MSG_DEF(JSMSG_BAD_TRAP_RETURN_VALUE, 212, 2, JSEXN_TYPEERR,"trap {1} for {0} returned a primitive value") +MSG_DEF(JSMSG_OF_AFTER_FOR_NAME, 213, 0, JSEXN_SYNTAXERR, "missing 'of' after for") +MSG_DEF(JSMSG_BAD_GENERATOR_YIELD, 214, 1, JSEXN_TYPEERR, "yield from closing generator {0}") +MSG_DEF(JSMSG_BAD_GENERATOR_SYNTAX, 215, 1, JSEXN_SYNTAXERR, "{0} expression must be parenthesized") +MSG_DEF(JSMSG_ARRAY_COMP_LEFTSIDE, 216, 0, JSEXN_SYNTAXERR, "invalid array comprehension left-hand side") +MSG_DEF(JSMSG_LET_COMP_BINDING, 217, 0, JSEXN_SYNTAXERR, "'let' is not a valid name for a comprehension variable") +MSG_DEF(JSMSG_EMPTY_ARRAY_REDUCE, 218, 0, JSEXN_TYPEERR, "reduce of empty array with no initial value") +MSG_DEF(JSMSG_BAD_SYMBOL, 219, 1, JSEXN_TYPEERR, "{0} is not a well-known @@-symbol") +MSG_DEF(JSMSG_BAD_DELETE_OPERAND, 220, 0, JSEXN_REFERENCEERR, "invalid delete operand") +MSG_DEF(JSMSG_BAD_INCOP_OPERAND, 221, 0, JSEXN_REFERENCEERR, "invalid increment/decrement operand") +MSG_DEF(JSMSG_UNEXPECTED_TYPE, 222, 2, JSEXN_TYPEERR, "{0} is {1}") +MSG_DEF(JSMSG_LET_DECL_NOT_IN_BLOCK, 223, 0, JSEXN_SYNTAXERR, "let declaration not directly within block") +MSG_DEF(JSMSG_UNUSED224, 224, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_CANT_SET_ARRAY_ATTRS, 225, 0, JSEXN_INTERNALERR, "can't set attributes on indexed array properties") +MSG_DEF(JSMSG_EVAL_ARITY, 226, 0, JSEXN_TYPEERR, "eval accepts only one parameter") +MSG_DEF(JSMSG_MISSING_FUN_ARG, 227, 2, JSEXN_TYPEERR, "missing argument {0} when calling function {1}") +MSG_DEF(JSMSG_JSON_BAD_PARSE, 228, 3, JSEXN_SYNTAXERR, "JSON.parse: {0} at line {1} column {2} of the JSON data") +MSG_DEF(JSMSG_JSON_BAD_STRINGIFY, 229, 0, JSEXN_ERR, "JSON.stringify") +MSG_DEF(JSMSG_NOT_CALLABLE_OR_UNDEFINED, 230, 0, JSEXN_TYPEERR, "value is not a function or undefined") +MSG_DEF(JSMSG_NOT_NONNULL_OBJECT, 231, 0, JSEXN_TYPEERR, "value is not a non-null object") +MSG_DEF(JSMSG_DEPRECATED_OCTAL, 232, 0, JSEXN_SYNTAXERR, "octal literals and octal escape sequences are deprecated") +MSG_DEF(JSMSG_STRICT_CODE_WITH, 233, 0, JSEXN_SYNTAXERR, "strict mode code may not contain 'with' statements") +MSG_DEF(JSMSG_DUPLICATE_PROPERTY, 234, 1, JSEXN_SYNTAXERR, "property name {0} appears more than once in object literal") +MSG_DEF(JSMSG_DEPRECATED_DELETE_OPERAND, 235, 0, JSEXN_SYNTAXERR, "applying the 'delete' operator to an unqualified name is deprecated") +MSG_DEF(JSMSG_BAD_STRICT_ASSIGN, 236, 1, JSEXN_SYNTAXERR, "can't assign to {0} in strict mode") +MSG_DEF(JSMSG_BAD_BINDING, 237, 1, JSEXN_SYNTAXERR, "redefining {0} is deprecated") +MSG_DEF(JSMSG_INVALID_DESCRIPTOR, 238, 0, JSEXN_TYPEERR, "property descriptors must not specify a value or be writable when a getter or setter has been specified") +MSG_DEF(JSMSG_OBJECT_NOT_EXTENSIBLE, 239, 1, JSEXN_TYPEERR, "{0} is not extensible") +MSG_DEF(JSMSG_CANT_REDEFINE_PROP, 240, 1, JSEXN_TYPEERR, "can't redefine non-configurable property '{0}'") +MSG_DEF(JSMSG_CANT_APPEND_TO_ARRAY, 241, 0, JSEXN_TYPEERR, "can't add elements past the end of an array if its length property is unwritable") +MSG_DEF(JSMSG_CANT_REDEFINE_ARRAY_LENGTH,242, 0, JSEXN_TYPEERR, "can't redefine array length") +MSG_DEF(JSMSG_CANT_DEFINE_PAST_ARRAY_LENGTH,243, 0, JSEXN_TYPEERR, "can't define array index property past the end of an array with non-writable length") +MSG_DEF(JSMSG_TYPED_ARRAY_BAD_INDEX, 244, 0, JSEXN_ERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_TYPED_ARRAY_NEGATIVE_ARG, 245, 1, JSEXN_ERR, "argument {0} must be >= 0") +MSG_DEF(JSMSG_TYPED_ARRAY_BAD_ARGS, 246, 0, JSEXN_ERR, "invalid arguments") +MSG_DEF(JSMSG_CSP_BLOCKED_FUNCTION, 247, 0, JSEXN_ERR, "call to Function() blocked by CSP") +MSG_DEF(JSMSG_BAD_GET_SET_FIELD, 248, 1, JSEXN_TYPEERR, "property descriptor's {0} field is neither undefined nor a function") +MSG_DEF(JSMSG_BAD_PROXY_FIX, 249, 0, JSEXN_TYPEERR, "proxy was fixed while executing the handler") +MSG_DEF(JSMSG_INVALID_EVAL_SCOPE_ARG, 250, 0, JSEXN_EVALERR, "invalid eval scope argument") +MSG_DEF(JSMSG_ACCESSOR_WRONG_ARGS, 251, 3, JSEXN_SYNTAXERR, "{0} functions must have {1} argument{2}") +MSG_DEF(JSMSG_THROW_TYPE_ERROR, 252, 0, JSEXN_TYPEERR, "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them") +MSG_DEF(JSMSG_BAD_TOISOSTRING_PROP, 253, 0, JSEXN_TYPEERR, "toISOString property is not callable") +MSG_DEF(JSMSG_BAD_PARSE_NODE, 254, 0, JSEXN_INTERNALERR, "bad parse node") +MSG_DEF(JSMSG_NOT_EXPECTED_TYPE, 255, 3, JSEXN_TYPEERR, "{0}: expected {1}, got {2}") +MSG_DEF(JSMSG_CALLER_IS_STRICT, 256, 0, JSEXN_TYPEERR, "access to strict mode caller function is censored") +MSG_DEF(JSMSG_NEED_DEBUG_MODE, 257, 0, JSEXN_ERR, "function can be called only in debug mode") +MSG_DEF(JSMSG_STRICT_CODE_LET_EXPR_STMT, 258, 0, JSEXN_ERR, "strict mode code may not contain unparenthesized let expression statements") +MSG_DEF(JSMSG_CANT_CHANGE_EXTENSIBILITY, 259, 0, JSEXN_TYPEERR, "can't change object's extensibility") +MSG_DEF(JSMSG_SC_BAD_SERIALIZED_DATA, 260, 1, JSEXN_INTERNALERR, "bad serialized structured data ({0})") +MSG_DEF(JSMSG_SC_UNSUPPORTED_TYPE, 261, 0, JSEXN_TYPEERR, "unsupported type for structured data") +MSG_DEF(JSMSG_SC_RECURSION, 262, 0, JSEXN_INTERNALERR, "recursive object") +MSG_DEF(JSMSG_DEBUG_CANT_DEBUG_GLOBAL, 263, 0, JSEXN_ERR, "passing non-debuggable global to addDebuggee") +MSG_DEF(JSMSG_BAD_CLONE_VERSION, 264, 0, JSEXN_ERR, "unsupported structured clone version") +MSG_DEF(JSMSG_CANT_CLONE_OBJECT, 265, 0, JSEXN_TYPEERR, "can't clone object") +MSG_DEF(JSMSG_DEBUG_RESUMPTION_VALUE_DISALLOWED, 266, 0, JSEXN_TYPEERR, "resumption values are disallowed in this hook") +MSG_DEF(JSMSG_STRICT_FUNCTION_STATEMENT, 267, 0, JSEXN_SYNTAXERR, "in strict mode code, functions may be declared only at top level or immediately within another function") +MSG_DEF(JSMSG_INVALID_FOR_IN_INIT, 268, 0, JSEXN_SYNTAXERR, "for-in loop let declaration may not have an initializer") +MSG_DEF(JSMSG_CLEARED_SCOPE, 269, 0, JSEXN_TYPEERR, "attempt to run compile-and-go script on a cleared scope") +MSG_DEF(JSMSG_MALFORMED_ESCAPE, 270, 1, JSEXN_SYNTAXERR, "malformed {0} character escape sequence") +MSG_DEF(JSMSG_BAD_GENEXP_BODY, 271, 1, JSEXN_SYNTAXERR, "illegal use of {0} in generator expression") +MSG_DEF(JSMSG_YIELD_WITHOUT_OPERAND, 272, 0, JSEXN_SYNTAXERR, "yield without a value is deprecated, and illegal in ES6 (use 'yield undefined' instead)") +MSG_DEF(JSMSG_UNNAMED_FUNCTION_STMT, 273, 0, JSEXN_SYNTAXERR, "function statement requires a name") +MSG_DEF(JSMSG_CCW_REQUIRED, 274, 1, JSEXN_TYPEERR, "{0}: argument must be an object from a different compartment") +MSG_DEF(JSMSG_DEBUG_BAD_RESUMPTION, 275, 0, JSEXN_TYPEERR, "debugger resumption value must be undefined, {throw: val}, {return: val}, or null") +MSG_DEF(JSMSG_ASSIGN_FUNCTION_OR_NULL, 276, 1, JSEXN_TYPEERR, "value assigned to {0} must be a function or null") +MSG_DEF(JSMSG_DEBUG_NOT_LIVE, 277, 1, JSEXN_ERR, "{0} is not live") +MSG_DEF(JSMSG_DEBUG_OBJECT_WRONG_OWNER, 278, 0, JSEXN_TYPEERR, "Debugger.Object belongs to a different Debugger") +MSG_DEF(JSMSG_DEBUG_OBJECT_PROTO, 279, 0, JSEXN_TYPEERR, "Debugger.Object.prototype is not a valid Debugger.Object") +MSG_DEF(JSMSG_DEBUG_LOOP, 280, 0, JSEXN_TYPEERR, "cannot debug an object in same compartment as debugger or a compartment that is already debugging the debugger") +MSG_DEF(JSMSG_DEBUG_NOT_IDLE, 281, 0, JSEXN_ERR, "can't start debugging: a debuggee script is on the stack") +MSG_DEF(JSMSG_DEBUG_BAD_OFFSET, 282, 0, JSEXN_TYPEERR, "invalid script offset") +MSG_DEF(JSMSG_DEBUG_BAD_LINE, 283, 0, JSEXN_TYPEERR, "invalid line number") +MSG_DEF(JSMSG_DEBUG_NOT_DEBUGGING, 284, 0, JSEXN_ERR, "can't set breakpoint: script global is not a debuggee") +MSG_DEF(JSMSG_DEBUG_COMPARTMENT_MISMATCH, 285, 2, JSEXN_TYPEERR, "{0}: descriptor .{1} property is an object in a different compartment than the target object") +MSG_DEF(JSMSG_DEBUG_NOT_SCRIPT_FRAME, 286, 0, JSEXN_ERR, "stack frame is not running JavaScript code") +MSG_DEF(JSMSG_CANT_WATCH_PROP, 287, 0, JSEXN_TYPEERR, "properties whose names are objects can't be watched") +MSG_DEF(JSMSG_CSP_BLOCKED_EVAL, 288, 0, JSEXN_ERR, "call to eval() blocked by CSP") +MSG_DEF(JSMSG_DEBUG_NO_SCOPE_OBJECT, 289, 0, JSEXN_TYPEERR, "declarative Environments don't have binding objects") +MSG_DEF(JSMSG_EMPTY_CONSEQUENT, 290, 0, JSEXN_SYNTAXERR, "mistyped ; after conditional?") +MSG_DEF(JSMSG_NOT_ITERABLE, 291, 1, JSEXN_TYPEERR, "{0} is not iterable") +MSG_DEF(JSMSG_QUERY_LINE_WITHOUT_URL, 292, 0, JSEXN_TYPEERR, "findScripts query object has 'line' property, but no 'url' property") +MSG_DEF(JSMSG_QUERY_INNERMOST_WITHOUT_LINE_URL, 293, 0, JSEXN_TYPEERR, "findScripts query object has 'innermost' property without both 'url' and 'line' properties") +MSG_DEF(JSMSG_DEBUG_VARIABLE_NOT_FOUND, 294, 0, JSEXN_TYPEERR, "variable not found in environment") +MSG_DEF(JSMSG_PARAMETER_AFTER_REST, 295, 0, JSEXN_SYNTAXERR, "parameter after rest parameter") +MSG_DEF(JSMSG_NO_REST_NAME, 296, 0, JSEXN_SYNTAXERR, "no parameter name after ...") +MSG_DEF(JSMSG_ARGUMENTS_AND_REST, 297, 0, JSEXN_SYNTAXERR, "'arguments' object may not be used in conjunction with a rest parameter") +MSG_DEF(JSMSG_FUNCTION_ARGUMENTS_AND_REST, 298, 0, JSEXN_ERR, "the 'arguments' property of a function with a rest parameter may not be used") +MSG_DEF(JSMSG_REST_WITH_DEFAULT, 299, 0, JSEXN_SYNTAXERR, "rest parameter may not have a default") +MSG_DEF(JSMSG_NONDEFAULT_FORMAL_AFTER_DEFAULT, 300, 0, JSEXN_SYNTAXERR, "parameter(s) with default followed by parameter without default") +MSG_DEF(JSMSG_YIELD_IN_DEFAULT, 301, 0, JSEXN_SYNTAXERR, "yield in default expression") +MSG_DEF(JSMSG_INTRINSIC_NOT_DEFINED, 302, 1, JSEXN_REFERENCEERR, "no intrinsic function {0}") +MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 303, 2, JSEXN_NONE, "{0} is being assigned a {1}, but already has one") +MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 304, 0, JSEXN_RANGEERR, "invalid parallel method argument") +MSG_DEF(JSMSG_REGEXP_RUNTIME_ERROR, 305, 0, JSEXN_INTERNALERR, "an error occurred while executing regular expression") +MSG_DEF(JSMSG_DEBUG_OPTIMIZED_OUT, 306, 0, JSEXN_ERR, "variable has been optimized out") +MSG_DEF(JSMSG_NEXT_RETURNED_PRIMITIVE,307, 0, JSEXN_TYPEERR, "iterator.next() returned a non-object value") +MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_CONFLICT, 308, 0, JSEXN_ERR, "no conflict resolution function provided") +MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BOUNDS, 309, 0, JSEXN_ERR, "index in scatter vector out of bounds") +MSG_DEF(JSMSG_CANT_REPORT_NC_AS_NE, 310, 0, JSEXN_TYPEERR, "proxy can't report a non-configurable own property as non-existent") +MSG_DEF(JSMSG_CANT_REPORT_E_AS_NE, 311, 0, JSEXN_TYPEERR, "proxy can't report an existing own property as non-existent on a non-extensible object") +MSG_DEF(JSMSG_CANT_REPORT_NEW, 312, 0, JSEXN_TYPEERR, "proxy can't report a new property on a non-extensible object") +MSG_DEF(JSMSG_CANT_REPORT_INVALID, 313, 0, JSEXN_TYPEERR, "proxy can't report an incompatible property descriptor") +MSG_DEF(JSMSG_CANT_REPORT_NE_AS_NC, 314, 0, JSEXN_TYPEERR, "proxy can't report a non-existent property as non-configurable") +MSG_DEF(JSMSG_CANT_DEFINE_NEW, 315, 0, JSEXN_TYPEERR, "proxy can't define a new property on a non-extensible object") +MSG_DEF(JSMSG_CANT_DEFINE_INVALID, 316, 0, JSEXN_TYPEERR, "proxy can't define an incompatible property descriptor") +MSG_DEF(JSMSG_CANT_DEFINE_NE_AS_NC, 317, 0, JSEXN_TYPEERR, "proxy can't define a non-existent property as non-configurable") +MSG_DEF(JSMSG_INVALID_TRAP_RESULT, 318, 2, JSEXN_TYPEERR, "trap {1} for {0} returned an invalid result") +MSG_DEF(JSMSG_CANT_SKIP_NC, 319, 0, JSEXN_TYPEERR, "proxy can't skip a non-configurable property") +MSG_DEF(JSMSG_MUST_REPORT_SAME_VALUE, 320, 0, JSEXN_TYPEERR, "proxy must report the same value for a non-writable, non-configurable property") +MSG_DEF(JSMSG_MUST_REPORT_UNDEFINED, 321, 0, JSEXN_TYPEERR, "proxy must report undefined for a non-configurable accessor property without a getter") +MSG_DEF(JSMSG_CANT_SET_NW_NC, 322, 0, JSEXN_TYPEERR, "proxy can't successfully set a non-writable, non-configurable property") +MSG_DEF(JSMSG_CANT_SET_WO_SETTER, 323, 0, JSEXN_TYPEERR, "proxy can't succesfully set an accessor property without a setter") +MSG_DEF(JSMSG_DEBUG_BAD_REFERENT, 324, 2, JSEXN_TYPEERR, "{0} does not refer to {1}") +MSG_DEF(JSMSG_DEBUG_WRAPPER_IN_WAY, 325, 3, JSEXN_TYPEERR, "{0} is {1}{2}a global object, but a direct reference is required") +MSG_DEF(JSMSG_UNWRAP_DENIED, 326, 0, JSEXN_ERR, "permission denied to unwrap object") +MSG_DEF(JSMSG_INTL_OBJECT_NOT_INITED, 327, 3, JSEXN_TYPEERR, "Intl.{0}.prototype.{1} called on value that's not an object initialized as a {2}") +MSG_DEF(JSMSG_INVALID_LOCALES_ELEMENT,328, 0, JSEXN_TYPEERR, "invalid element in locales argument") +MSG_DEF(JSMSG_INVALID_LANGUAGE_TAG, 329, 1, JSEXN_RANGEERR, "invalid language tag: {0}") +MSG_DEF(JSMSG_INVALID_LOCALE_MATCHER, 330, 1, JSEXN_RANGEERR, "invalid locale matcher in supportedLocalesOf(): {0}") +MSG_DEF(JSMSG_INVALID_OPTION_VALUE, 331, 2, JSEXN_RANGEERR, "invalid value {1} for option {0}") +MSG_DEF(JSMSG_INVALID_DIGITS_VALUE, 332, 1, JSEXN_RANGEERR, "invalid digits value: {0}") +MSG_DEF(JSMSG_INTL_OBJECT_REINITED, 333, 0, JSEXN_TYPEERR, "can't initialize object twice as an object of an Intl constructor") +MSG_DEF(JSMSG_INVALID_CURRENCY_CODE, 334, 1, JSEXN_RANGEERR, "invalid currency code in NumberFormat(): {0}") +MSG_DEF(JSMSG_UNDEFINED_CURRENCY, 335, 0, JSEXN_TYPEERR, "undefined currency in NumberFormat() with currency style") +MSG_DEF(JSMSG_INVALID_TIME_ZONE, 336, 1, JSEXN_RANGEERR, "invalid time zone in DateTimeFormat(): {0}") +MSG_DEF(JSMSG_DATE_NOT_FINITE, 337, 0, JSEXN_RANGEERR, "date value is not finite in DateTimeFormat.format()") +MSG_DEF(JSMSG_USE_ASM_DIRECTIVE_FAIL, 338, 0, JSEXN_SYNTAXERR, "\"use asm\" is only meaningful in the Directive Prologue of a function body") +MSG_DEF(JSMSG_USE_ASM_TYPE_FAIL, 339, 1, JSEXN_TYPEERR, "asm.js type error: {0}") +MSG_DEF(JSMSG_USE_ASM_LINK_FAIL, 340, 1, JSEXN_TYPEERR, "asm.js link error: {0}") +MSG_DEF(JSMSG_USE_ASM_TYPE_OK, 341, 1, JSEXN_NONE, "Successfully compiled asm.js code ({0})") +MSG_DEF(JSMSG_BAD_ARROW_ARGS, 342, 0, JSEXN_SYNTAXERR, "invalid arrow-function arguments (parentheses around the arrow-function may help)") +MSG_DEF(JSMSG_YIELD_IN_ARROW, 343, 0, JSEXN_SYNTAXERR, "arrow function may not contain yield") +MSG_DEF(JSMSG_WRONG_VALUE, 344, 2, JSEXN_ERR, "expected {0} but found {1}") +MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BAD_TARGET, 345, 1, JSEXN_ERR, "target for index {0} is not an integer") +MSG_DEF(JSMSG_SELFHOSTED_UNBOUND_NAME,346, 0, JSEXN_TYPEERR, "self-hosted code may not contain unbound name lookups") +MSG_DEF(JSMSG_DEPRECATED_PRAGMA, 347, 1, JSEXN_NONE, "Using //@ to indicate {0} pragmas is deprecated. Use //# instead") +MSG_DEF(JSMSG_BAD_DESTRUCT_ASSIGN, 348, 1, JSEXN_SYNTAXERR, "can't assign to {0} using destructuring assignment") +MSG_DEF(JSMSG_TYPEDOBJECT_ARRAYTYPE_BAD_ARGS, 349, 0, JSEXN_ERR, "Invalid arguments") +MSG_DEF(JSMSG_TYPEDOBJECT_BINARYARRAY_BAD_INDEX, 350, 0, JSEXN_RANGEERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_TYPEDOBJECT_STRUCTTYPE_BAD_ARGS, 351, 0, JSEXN_RANGEERR, "invalid field descriptor") +MSG_DEF(JSMSG_TYPEDOBJECT_NOT_BINARYSTRUCT, 352, 1, JSEXN_TYPEERR, "{0} is not a BinaryStruct") +MSG_DEF(JSMSG_TYPEDOBJECT_SUBARRAY_INTEGER_ARG, 353, 1, JSEXN_ERR, "argument {0} must be an integer") +MSG_DEF(JSMSG_TYPEDOBJECT_STRUCTTYPE_EMPTY_DESCRIPTOR, 354, 0, JSEXN_ERR, "field descriptor cannot be empty") +MSG_DEF(JSMSG_TYPEDOBJECT_STRUCTTYPE_BAD_FIELD, 355, 1, JSEXN_ERR, "field {0} is not a valid BinaryData Type descriptor") +MSG_DEF(JSMSG_GENERATOR_FINISHED, 356, 0, JSEXN_TYPEERR, "generator has already finished") +MSG_DEF(JSMSG_TYPEDOBJECT_TOO_BIG, 357, 0, JSEXN_ERR, "Type is too large to allocate") +MSG_DEF(JSMSG_TYPEDOBJECT_NOT_TYPE_OBJECT, 358, 0, JSEXN_ERR, "Expected a type object") +MSG_DEF(JSMSG_TOO_MANY_CON_SPREADARGS, 359, 0, JSEXN_RANGEERR, "too many constructor arguments") +MSG_DEF(JSMSG_TOO_MANY_FUN_SPREADARGS, 360, 0, JSEXN_RANGEERR, "too many function arguments") +MSG_DEF(JSMSG_DEBUG_NOT_DEBUGGEE, 361, 2, JSEXN_ERR, "{0} is not a debuggee {1}") +MSG_DEF(JSMSG_TYPEDOBJECT_NOT_TYPED_OBJECT, 362, 0, JSEXN_ERR, "Expected a typed object") +MSG_DEF(JSMSG_TYPEDOBJECT_NO_SUCH_PROP, 363, 1, JSEXN_TYPEERR, "No such property: {0}") +MSG_DEF(JSMSG_TYPEDOBJECT_BAD_ARGS, 364, 0, JSEXN_TYPEERR, "invalid arguments") +MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_UNATTACHED, 365, 0, JSEXN_TYPEERR, "handle unattached") +MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_BAD_TYPE, 366, 0, JSEXN_TYPEERR, "handle moved to destination of incorrect type") + +MSG_DEF(JSMSG_IMPORT_DECL_AT_TOP_LEVEL, 367, 0, JSEXN_SYNTAXERR, "import declarations may only appear at top level") +MSG_DEF(JSMSG_NO_IMPORT_NAME, 368, 0, JSEXN_SYNTAXERR, "missing import name") +MSG_DEF(JSMSG_AS_AFTER_RESERVED_WORD, 369, 1, JSEXN_SYNTAXERR, "missing keyword 'as' after reserved word '{0}'") +MSG_DEF(JSMSG_NO_BINDING_NAME, 370, 0, JSEXN_SYNTAXERR, "missing binding name") +MSG_DEF(JSMSG_RC_AFTER_IMPORT_SPEC_LIST, 371, 0, JSEXN_SYNTAXERR, "missing '}' after module specifier list") +MSG_DEF(JSMSG_FROM_AFTER_IMPORT_SPEC_SET, 372, 0, JSEXN_SYNTAXERR, "missing keyword 'from' after import specifier set") +MSG_DEF(JSMSG_DECLARATION_AFTER_IMPORT, 373, 0, JSEXN_SYNTAXERR, "missing declaration after 'import' keyword") +MSG_DEF(JSMSG_MODULE_SPEC_AFTER_FROM, 374, 0, JSEXN_SYNTAXERR, "missing module specifier after 'from' keyword") +MSG_DEF(JSMSG_MODULES_NOT_IMPLEMENTED, 375, 0, JSEXN_SYNTAXERR, "modules are not implemented yet") +MSG_DEF(JSMSG_EXPORT_DECL_AT_TOP_LEVEL, 376, 0, JSEXN_SYNTAXERR, "export declarations may only appear at top level") +MSG_DEF(JSMSG_RC_AFTER_EXPORT_SPEC_LIST, 377, 0, JSEXN_SYNTAXERR, "missing '}' after export specifier list") +MSG_DEF(JSMSG_NO_EXPORT_NAME, 378, 0, JSEXN_SYNTAXERR, "missing export name") +MSG_DEF(JSMSG_DECLARATION_AFTER_EXPORT, 379, 0, JSEXN_SYNTAXERR, "missing declaration after 'export' keyword") +MSG_DEF(JSMSG_INVALID_PROTOTYPE, 380, 0, JSEXN_TYPEERR, "prototype field is not an object") +MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_TO_UNSIZED, 381, 0, JSEXN_TYPEERR, "cannot create a handle to an unsized type") +MSG_DEF(JSMSG_SETPROTOTYPEOF_FAIL, 382, 1, JSEXN_TYPEERR, "[[SetPrototypeOf]] failed on {0}") +MSG_DEF(JSMSG_INVALID_ARG_TYPE, 383, 3, JSEXN_TYPEERR, "Invalid type: {0} can't be a{1} {2}") +MSG_DEF(JSMSG_TERMINATED, 384, 1, JSEXN_ERR, "Script terminated by timeout at:\n{0}") +MSG_DEF(JSMSG_NO_SUCH_SELF_HOSTED_PROP, 385, 1, JSEXN_ERR, "No such property on self-hosted object: {0}") +MSG_DEF(JSMSG_PROXY_EXTENSIBILITY, 386, 0, JSEXN_TYPEERR, "proxy must report same extensiblitity as target") +MSG_DEF(JSMSG_PROXY_CONSTRUCT_OBJECT, 387, 0, JSEXN_TYPEERR, "proxy [[Construct]] must return an object") +MSG_DEF(JSMSG_PROXY_GETOWN_OBJORUNDEF, 388, 0, JSEXN_TYPEERR, "proxy [[GetOwnProperty]] must return an object or undefined") +MSG_DEF(JSMSG_CANT_REPORT_C_AS_NC, 389, 0, JSEXN_TYPEERR, "proxy can't report existing configurable property as non-configurable") diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Anchor.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Anchor.h new file mode 100644 index 0000000000..d9ed3fd750 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Anchor.h @@ -0,0 +1,174 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JS::Anchor implementation. */ + +#ifndef js_Anchor_h +#define js_Anchor_h + +#include "mozilla/Attributes.h" + +#include "js/TypeDecls.h" + +namespace JS { + +/* + * Protecting non-Value, non-JSObject *, non-JSString * values from collection + * + * Most of the time, the garbage collector's conservative stack scanner works + * behind the scenes, finding all live values and protecting them from being + * collected. However, when JSAPI client code obtains a pointer to data the + * scanner does not know about, owned by an object the scanner does know about, + * Care Must Be Taken. + * + * The scanner recognizes only a select set of types: pointers to JSObjects and + * similar things (JSFunctions, and so on), pointers to JSStrings, and Values. + * So while the scanner finds all live |JSString| pointers, it does not notice + * |jschar| pointers. + * + * So suppose we have: + * + * void f(JSString *str) { + * const jschar *ch = JS_GetStringCharsZ(str); + * ... do stuff with ch, but no uses of str ...; + * } + * + * After the call to |JS_GetStringCharsZ|, there are no further uses of + * |str|, which means that the compiler is within its rights to not store + * it anywhere. But because the stack scanner will not notice |ch|, there + * is no longer any live value in this frame that would keep the string + * alive. If |str| is the last reference to that |JSString|, and the + * collector runs while we are using |ch|, the string's array of |jschar|s + * may be freed out from under us. + * + * Note that there is only an issue when 1) we extract a thing X the scanner + * doesn't recognize from 2) a thing Y the scanner does recognize, and 3) if Y + * gets garbage-collected, then X gets freed. If we have code like this: + * + * void g(JSObject *obj) { + * JS::Value x; + * JS_GetProperty(obj, "x", &x); + * ... do stuff with x ... + * } + * + * there's no problem, because the value we've extracted, x, is a Value, a + * type that the conservative scanner recognizes. + * + * Conservative GC frees us from the obligation to explicitly root the types it + * knows about, but when we work with derived values like |ch|, we must root + * their owners, as the derived value alone won't keep them alive. + * + * A JS::Anchor is a kind of GC root that allows us to keep the owners of + * derived values like |ch| alive throughout the Anchor's lifetime. We could + * fix the above code as follows: + * + * void f(JSString *str) { + * JS::Anchor a_str(str); + * const jschar *ch = JS_GetStringCharsZ(str); + * ... do stuff with ch, but no uses of str ...; + * } + * + * This simply ensures that |str| will be live until |a_str| goes out of scope. + * As long as we don't retain a pointer to the string's characters for longer + * than that, we have avoided all garbage collection hazards. + */ +template class AnchorPermitted; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; + +template +class Anchor : AnchorPermitted +{ + public: + Anchor() { } + explicit Anchor(T t) { hold = t; } + inline ~Anchor(); + + private: + T hold; + + /* + * Rooting analysis considers use of operator= to be a use of an anchor. + * For simplicity, Anchor is treated as if it contained a GC thing, from + * construction. Thus if we had + * + * void operator=(const T &t) { hold = t; } + * + * and this code + * + * JS::Anchor anchor; + * stuff that could GC, producing |str|; + * anchor = str; + * + * the last line would be seen as a hazard, because the final = would "use" + * |anchor| that is a GC thing -- which could have been moved around by the + * GC. The workaround is to structure your code so that JS::Anchor is + * always constructed, living for however long the corresponding value must + * live. + */ + void operator=(const T &t) MOZ_DELETE; + + Anchor(const Anchor &other) MOZ_DELETE; + void operator=(const Anchor &other) MOZ_DELETE; +}; + +template +inline Anchor::~Anchor() +{ +#ifdef __GNUC__ + /* + * No code is generated for this. But because this is marked 'volatile', G++ will + * assume it has important side-effects, and won't delete it. (G++ never looks at + * the actual text and notices it's empty.) And because we have passed |hold| to + * it, GCC will keep |hold| alive until this point. + * + * The "memory" clobber operand ensures that G++ will not move prior memory + * accesses after the asm --- it's a barrier. Unfortunately, it also means that + * G++ will assume that all memory has changed after the asm, as it would for a + * call to an unknown function. I don't know of a way to avoid that consequence. + */ + asm volatile("":: "g" (hold) : "memory"); +#else + /* + * An adequate portable substitute, for non-structure types. + * + * The compiler promises that, by the end of an expression statement, the + * last-stored value to a volatile object is the same as it would be in an + * unoptimized, direct implementation (the "abstract machine" whose behavior the + * language spec describes). However, the compiler is still free to reorder + * non-volatile accesses across this store --- which is what we must prevent. So + * assigning the held value to a volatile variable, as we do here, is not enough. + * + * In our case, however, garbage collection only occurs at function calls, so it + * is sufficient to ensure that the destructor's store isn't moved earlier across + * any function calls that could collect. It is hard to imagine the compiler + * analyzing the program so thoroughly that it could prove that such motion was + * safe. In practice, compilers treat calls to the collector as opaque operations + * --- in particular, as operations which could access volatile variables, across + * which this destructor must not be moved. + * + * ("Objection, your honor! *Alleged* killer whale!") + * + * The disadvantage of this approach is that it does generate code for the store. + * We do need to use Anchors in some cases where cycles are tight. + * + * Note that there is a Anchor::~Anchor() specialization in Value.h. + */ + volatile T sink; + sink = hold; +#endif /* defined(__GNUC__) */ +} + +} // namespace JS + +#endif /* js_Anchor_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/CallArgs.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/CallArgs.h new file mode 100644 index 0000000000..97a30553f0 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/CallArgs.h @@ -0,0 +1,420 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Helper classes encapsulating access to the callee, |this| value, arguments, + * and argument count for a function call. + * + * The intent of JS::CallArgs and JS::CallReceiver is that they be used to + * encapsulate access to the un-abstracted |unsigned argc, Value *vp| arguments + * to a function. It's possible (albeit deprecated) to manually index into + * |vp| to access the callee, |this|, and arguments of a function, and to set + * its return value. It's also possible to use the supported API of JS_CALLEE, + * JS_THIS, JS_ARGV, JS_RVAL and JS_SET_RVAL to the same ends. But neither API + * has the error-handling or moving-GC correctness of CallArgs or CallReceiver. + * New code should use CallArgs and CallReceiver instead whenever possible. + * + * The eventual plan is to change JSNative to take |const CallArgs&| directly, + * for automatic assertion of correct use and to make calling functions more + * efficient. Embedders should start internally switching away from using + * |argc| and |vp| directly, except to create a |CallArgs|. Then, when an + * eventual release making that change occurs, porting efforts will require + * changing methods' signatures but won't require invasive changes to the + * methods' implementations, potentially under time pressure. + */ + +#ifndef js_CallArgs_h +#define js_CallArgs_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/TypeTraits.h" + +#include "jstypes.h" + +#include "js/RootingAPI.h" +#include "js/Value.h" + +/* Typedef for native functions called by the JS VM. */ +typedef bool +(* JSNative)(JSContext *cx, unsigned argc, JS::Value *vp); + +/* Typedef for native functions that may be called in parallel. */ +typedef bool +(* JSParallelNative)(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); + +/* + * Typedef for native functions that may be called either in parallel or + * sequential execution. + */ +typedef bool +(* JSThreadSafeNative)(js::ThreadSafeContext *cx, unsigned argc, JS::Value *vp); + +/* + * Convenience wrappers for passing in ThreadSafeNative to places that expect + * a JSNative or a JSParallelNative. + */ +template +inline bool +JSNativeThreadSafeWrapper(JSContext *cx, unsigned argc, JS::Value *vp); + +template +inline bool +JSParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); + +/* + * Compute |this| for the |vp| inside a JSNative, either boxing primitives or + * replacing with the global object as necessary. + * + * This method will go away at some point: instead use |args.thisv()|. If the + * value is an object, no further work is required. If that value is |null| or + * |undefined|, use |JS_GetGlobalForObject| to compute the global object. If + * the value is some other primitive, use |JS_ValueToObject| to box it. + */ +extern JS_PUBLIC_API(JS::Value) +JS_ComputeThis(JSContext *cx, JS::Value *vp); + +namespace JS { + +extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; + +/* + * JS::CallReceiver encapsulates access to the callee, |this|, and eventual + * return value for a function call. The principal way to create a + * CallReceiver is using JS::CallReceiverFromVp: + * + * static bool + * FunctionReturningThis(JSContext *cx, unsigned argc, JS::Value *vp) + * { + * JS::CallReceiver rec = JS::CallReceiverFromVp(vp); + * + * // Access to the callee must occur before accessing/setting + * // the return value. + * JSObject &callee = rec.callee(); + * rec.rval().set(JS::ObjectValue(callee)); + * + * // callee() and calleev() will now assert. + * + * // It's always fine to access thisv(). + * HandleValue thisv = rec.thisv(); + * rec.rval().set(thisv); + * + * // As the return value was last set to |this|, returns |this|. + * return true; + * } + * + * A note on JS_ComputeThis and JS_THIS_OBJECT: these methods currently aren't + * part of the CallReceiver interface. We will likely add them at some point. + * Until then, you should probably continue using |vp| directly for these two + * cases. + * + * CallReceiver is exposed publicly and used internally. Not all parts of its + * public interface are meant to be used by embedders! See inline comments to + * for details. + */ + +namespace detail { + +#ifdef JS_DEBUG +extern JS_PUBLIC_API(void) +CheckIsValidConstructible(Value v); +#endif + +enum UsedRval { IncludeUsedRval, NoUsedRval }; + +template +class MOZ_STACK_CLASS UsedRvalBase; + +template<> +class MOZ_STACK_CLASS UsedRvalBase +{ + protected: + mutable bool usedRval_; + void setUsedRval() const { usedRval_ = true; } + void clearUsedRval() const { usedRval_ = false; } +}; + +template<> +class MOZ_STACK_CLASS UsedRvalBase +{ + protected: + void setUsedRval() const {} + void clearUsedRval() const {} +}; + +template +class MOZ_STACK_CLASS CallReceiverBase : public UsedRvalBase< +#ifdef JS_DEBUG + WantUsedRval +#else + NoUsedRval +#endif + > +{ + protected: + Value *argv_; + + public: + /* + * Returns the function being called, as an object. Must not be called + * after rval() has been used! + */ + JSObject &callee() const { + MOZ_ASSERT(!this->usedRval_); + return argv_[-2].toObject(); + } + + /* + * Returns the function being called, as a value. Must not be called after + * rval() has been used! + */ + HandleValue calleev() const { + MOZ_ASSERT(!this->usedRval_); + return HandleValue::fromMarkedLocation(&argv_[-2]); + } + + /* + * Returns the |this| value passed to the function. This method must not + * be called when the function is being called as a constructor via |new|. + * The value may or may not be an object: it is the individual function's + * responsibility to box the value if needed. + */ + HandleValue thisv() const { + // Some internal code uses thisv() in constructing cases, so don't do + // this yet. + // MOZ_ASSERT(!argv_[-1].isMagic(JS_IS_CONSTRUCTING)); + return HandleValue::fromMarkedLocation(&argv_[-1]); + } + + Value computeThis(JSContext *cx) const { + if (thisv().isObject()) + return thisv(); + + return JS_ComputeThis(cx, base()); + } + + bool isConstructing() const { +#ifdef JS_DEBUG + if (this->usedRval_) + CheckIsValidConstructible(calleev()); +#endif + return argv_[-1].isMagic(); + } + + /* + * Returns the currently-set return value. The initial contents of this + * value are unspecified. Once this method has been called, callee() and + * calleev() can no longer be used. (If you're compiling against a debug + * build of SpiderMonkey, these methods will assert to aid debugging.) + * + * If the method you're implementing succeeds by returning true, you *must* + * set this. (SpiderMonkey doesn't currently assert this, but it will do + * so eventually.) You don't need to use or change this if your method + * fails. + */ + MutableHandleValue rval() const { + this->setUsedRval(); + return MutableHandleValue::fromMarkedLocation(&argv_[-2]); + } + + public: + // These methods are only intended for internal use. Embedders shouldn't + // use them! + + Value *base() const { return argv_ - 2; } + + Value *spAfterCall() const { + this->setUsedRval(); + return argv_ - 1; + } + + public: + // These methods are publicly exposed, but they are *not* to be used when + // implementing a JSNative method and encapsulating access to |vp| within + // it. You probably don't want to use these! + + void setCallee(Value aCalleev) const { + this->clearUsedRval(); + argv_[-2] = aCalleev; + } + + void setThis(Value aThisv) const { + argv_[-1] = aThisv; + } + + MutableHandleValue mutableThisv() const { + return MutableHandleValue::fromMarkedLocation(&argv_[-1]); + } +}; + +} // namespace detail + +class MOZ_STACK_CLASS CallReceiver : public detail::CallReceiverBase +{ + private: + friend CallReceiver CallReceiverFromVp(Value *vp); + friend CallReceiver CallReceiverFromArgv(Value *argv); +}; + +MOZ_ALWAYS_INLINE CallReceiver +CallReceiverFromArgv(Value *argv) +{ + CallReceiver receiver; + receiver.clearUsedRval(); + receiver.argv_ = argv; + return receiver; +} + +MOZ_ALWAYS_INLINE CallReceiver +CallReceiverFromVp(Value *vp) +{ + return CallReceiverFromArgv(vp + 2); +} + +/* + * JS::CallArgs encapsulates everything JS::CallReceiver does, plus access to + * the function call's arguments. The principal way to create a CallArgs is + * like so, using JS::CallArgsFromVp: + * + * static bool + * FunctionReturningArgcTimesArg0(JSContext *cx, unsigned argc, JS::Value *vp) + * { + * JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + * + * // Guard against no arguments or a non-numeric arg0. + * if (args.length() == 0 || !args[0].isNumber()) { + * args.rval().setInt32(0); + * return true; + * } + * + * args.rval().set(JS::NumberValue(args.length() * args[0].toNumber())); + * return true; + * } + * + * CallArgs is exposed publicly and used internally. Not all parts of its + * public interface are meant to be used by embedders! See inline comments to + * for details. + */ +namespace detail { + +template +class MOZ_STACK_CLASS CallArgsBase : + public mozilla::Conditional >::Type +{ + protected: + unsigned argc_; + + public: + /* Returns the number of arguments. */ + unsigned length() const { return argc_; } + + /* Returns the i-th zero-indexed argument. */ + MutableHandleValue operator[](unsigned i) const { + MOZ_ASSERT(i < argc_); + return MutableHandleValue::fromMarkedLocation(&this->argv_[i]); + } + + /* + * Returns the i-th zero-indexed argument, or |undefined| if there's no + * such argument. + */ + HandleValue get(unsigned i) const { + return i < length() + ? HandleValue::fromMarkedLocation(&this->argv_[i]) + : UndefinedHandleValue; + } + + /* + * Returns true if the i-th zero-indexed argument is present and is not + * |undefined|. + */ + bool hasDefined(unsigned i) const { + return i < argc_ && !this->argv_[i].isUndefined(); + } + + public: + // These methods are publicly exposed, but we're less sure of the interface + // here than we'd like (because they're hackish and drop assertions). Try + // to avoid using these if you can. + + Value *array() const { return this->argv_; } + Value *end() const { return this->argv_ + argc_; } +}; + +} // namespace detail + +class MOZ_STACK_CLASS CallArgs : public detail::CallArgsBase +{ + private: + friend CallArgs CallArgsFromVp(unsigned argc, Value *vp); + friend CallArgs CallArgsFromSp(unsigned argc, Value *sp); + + static CallArgs create(unsigned argc, Value *argv) { + CallArgs args; + args.clearUsedRval(); + args.argv_ = argv; + args.argc_ = argc; + return args; + } + +}; + +MOZ_ALWAYS_INLINE CallArgs +CallArgsFromVp(unsigned argc, Value *vp) +{ + return CallArgs::create(argc, vp + 2); +} + +// This method is only intended for internal use in SpiderMonkey. We may +// eventually move it to an internal header. Embedders should use +// JS::CallArgsFromVp! +MOZ_ALWAYS_INLINE CallArgs +CallArgsFromSp(unsigned argc, Value *sp) +{ + return CallArgs::create(argc, sp - argc); +} + +} // namespace JS + +/* + * Macros to hide interpreter stack layout details from a JSNative using its + * JS::Value *vp parameter. DO NOT USE THESE! Instead use JS::CallArgs and + * friends, above. These macros will be removed when we change JSNative to + * take a const JS::CallArgs&. + */ + +#define JS_THIS_OBJECT(cx,vp) (JS_THIS(cx,vp).toObjectOrNull()) +#define JS_ARGV(cx,vp) ((vp) + 2) +#define JS_SET_RVAL(cx,vp,v) (*(vp) = (v)) + +/* + * Note: if this method returns null, an error has occurred and must be + * propagated or caught. + */ +MOZ_ALWAYS_INLINE JS::Value +JS_THIS(JSContext *cx, JS::Value *vp) +{ + return vp[1].isPrimitive() ? JS_ComputeThis(cx, vp) : vp[1]; +} + +/* + * |this| is passed to functions in ES5 without change. Functions themselves + * do any post-processing they desire to box |this|, compute the global object, + * &c. This macro retrieves a function's unboxed |this| value. + * + * This macro must not be used in conjunction with JS_THIS or JS_THIS_OBJECT, + * or vice versa. Either use the provided this value with this macro, or + * compute the boxed |this| value using those. JS_THIS_VALUE must not be used + * if the function is being called as a constructor. + * + * But: DO NOT USE THIS! Instead use JS::CallArgs::thisv(), above. + * + */ +#define JS_THIS_VALUE(cx,vp) ((vp)[1]) + +#endif /* js_CallArgs_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/CallNonGenericMethod.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/CallNonGenericMethod.h new file mode 100644 index 0000000000..ad9a7f708c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/CallNonGenericMethod.h @@ -0,0 +1,117 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_CallNonGenericMethod_h +#define js_CallNonGenericMethod_h + +#include "jstypes.h" + +#include "js/CallArgs.h" + +namespace JS { + +// Returns true if |v| is considered an acceptable this-value. +typedef bool (*IsAcceptableThis)(HandleValue v); + +// Implements the guts of a method; guaranteed to be provided an acceptable +// this-value, as determined by a corresponding IsAcceptableThis method. +typedef bool (*NativeImpl)(JSContext *cx, CallArgs args); + +namespace detail { + +// DON'T CALL THIS DIRECTLY. It's for use only by CallNonGenericMethod! +extern JS_PUBLIC_API(bool) +CallMethodIfWrapped(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args); + +} // namespace detail + +// Methods usually act upon |this| objects only from a single global object and +// compartment. Sometimes, however, a method must act upon |this| values from +// multiple global objects or compartments. In such cases the |this| value a +// method might see will be wrapped, such that various access to the object -- +// to its class, its private data, its reserved slots, and so on -- will not +// work properly without entering that object's compartment. This method +// implements a solution to this problem. +// +// To implement a method that accepts |this| values from multiple compartments, +// define two functions. The first function matches the IsAcceptableThis type +// and indicates whether the provided value is an acceptable |this| for the +// method; it must be a pure function only of its argument. +// +// static const JSClass AnswerClass = { ... }; +// +// static bool +// IsAnswerObject(const Value &v) +// { +// if (!v.isObject()) +// return false; +// return JS_GetClass(&v.toObject()) == &AnswerClass; +// } +// +// The second function implements the NativeImpl signature and defines the +// behavior of the method when it is provided an acceptable |this| value. +// Aside from some typing niceties -- see the CallArgs interface for details -- +// its interface is the same as that of JSNative. +// +// static bool +// answer_getAnswer_impl(JSContext *cx, JS::CallArgs args) +// { +// args.rval().setInt32(42); +// return true; +// } +// +// The implementation function is guaranteed to be called *only* with a |this| +// value which is considered acceptable. +// +// Now to implement the actual method, write a JSNative that calls the method +// declared below, passing the appropriate template and runtime arguments. +// +// static bool +// answer_getAnswer(JSContext *cx, unsigned argc, JS::Value *vp) +// { +// JS::CallArgs args = JS::CallArgsFromVp(argc, vp); +// return JS::CallNonGenericMethod(cx, args); +// } +// +// Note that, because they are used as template arguments, the predicate +// and implementation functions must have external linkage. (This is +// unfortunate, but GCC wasn't inlining things as one would hope when we +// passed them as function arguments.) +// +// JS::CallNonGenericMethod will test whether |args.thisv()| is acceptable. If +// it is, it will call the provided implementation function, which will return +// a value and indicate success. If it is not, it will attempt to unwrap +// |this| and call the implementation function on the unwrapped |this|. If +// that succeeds, all well and good. If it doesn't succeed, a TypeError will +// be thrown. +// +// Note: JS::CallNonGenericMethod will only work correctly if it's called in +// tail position in a JSNative. Do not call it from any other place. +// +template +MOZ_ALWAYS_INLINE bool +CallNonGenericMethod(JSContext *cx, CallArgs args) +{ + HandleValue thisv = args.thisv(); + if (Test(thisv)) + return Impl(cx, args); + + return detail::CallMethodIfWrapped(cx, Test, Impl, args); +} + +MOZ_ALWAYS_INLINE bool +CallNonGenericMethod(JSContext *cx, IsAcceptableThis Test, NativeImpl Impl, CallArgs args) +{ + HandleValue thisv = args.thisv(); + if (Test(thisv)) + return Impl(cx, args); + + return detail::CallMethodIfWrapped(cx, Test, Impl, args); +} + +} // namespace JS + +#endif /* js_CallNonGenericMethod_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/CharacterEncoding.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/CharacterEncoding.h new file mode 100644 index 0000000000..45c77761b3 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/CharacterEncoding.h @@ -0,0 +1,226 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_CharacterEncoding_h +#define js_CharacterEncoding_h + +#include "mozilla/NullPtr.h" +#include "mozilla/Range.h" + +#include "js/TypeDecls.h" +#include "js/Utility.h" + +namespace js { +struct ThreadSafeContext; +} + +class JSFlatString; + +namespace JS { + +/* + * By default, all C/C++ 1-byte-per-character strings passed into the JSAPI + * are treated as ISO/IEC 8859-1, also known as Latin-1. That is, each + * byte is treated as a 2-byte character, and there is no way to pass in a + * string containing characters beyond U+00FF. + */ +class Latin1Chars : public mozilla::Range +{ + typedef mozilla::Range Base; + + public: + Latin1Chars() : Base() {} + Latin1Chars(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) {} + Latin1Chars(const Latin1Char *aBytes, size_t aLength) + : Base(const_cast(aBytes), aLength) + {} + Latin1Chars(const char *aBytes, size_t aLength) + : Base(reinterpret_cast(const_cast(aBytes)), aLength) + {} +}; + +/* + * A Latin1Chars, but with \0 termination for C compatibility. + */ +class Latin1CharsZ : public mozilla::RangedPtr +{ + typedef mozilla::RangedPtr Base; + + public: + Latin1CharsZ() : Base(nullptr, 0) {} + + Latin1CharsZ(char *aBytes, size_t aLength) + : Base(reinterpret_cast(aBytes), aLength) + { + MOZ_ASSERT(aBytes[aLength] == '\0'); + } + + Latin1CharsZ(Latin1Char *aBytes, size_t aLength) + : Base(aBytes, aLength) + { + MOZ_ASSERT(aBytes[aLength] == '\0'); + } + + using Base::operator=; + + char *c_str() { return reinterpret_cast(get()); } +}; + +class UTF8Chars : public mozilla::Range +{ + typedef mozilla::Range Base; + + public: + UTF8Chars() : Base() {} + UTF8Chars(char *aBytes, size_t aLength) + : Base(reinterpret_cast(aBytes), aLength) + {} + UTF8Chars(const char *aBytes, size_t aLength) + : Base(reinterpret_cast(const_cast(aBytes)), aLength) + {} +}; + +/* + * SpiderMonkey also deals directly with UTF-8 encoded text in some places. + */ +class UTF8CharsZ : public mozilla::RangedPtr +{ + typedef mozilla::RangedPtr Base; + + public: + UTF8CharsZ() : Base(nullptr, 0) {} + + UTF8CharsZ(char *aBytes, size_t aLength) + : Base(reinterpret_cast(aBytes), aLength) + { + MOZ_ASSERT(aBytes[aLength] == '\0'); + } + + UTF8CharsZ(unsigned char *aBytes, size_t aLength) + : Base(aBytes, aLength) + { + MOZ_ASSERT(aBytes[aLength] == '\0'); + } + + using Base::operator=; + + char *c_str() { return reinterpret_cast(get()); } +}; + +/* + * SpiderMonkey uses a 2-byte character representation: it is a + * 2-byte-at-a-time view of a UTF-16 byte stream. This is similar to UCS-2, + * but unlike UCS-2, we do not strip UTF-16 extension bytes. This allows a + * sufficiently dedicated JavaScript program to be fully unicode-aware by + * manually interpreting UTF-16 extension characters embedded in the JS + * string. + */ +class TwoByteChars : public mozilla::Range +{ + typedef mozilla::Range Base; + + public: + TwoByteChars() : Base() {} + TwoByteChars(jschar *aChars, size_t aLength) : Base(aChars, aLength) {} + TwoByteChars(const jschar *aChars, size_t aLength) : Base(const_cast(aChars), aLength) {} +}; + +/* + * A TwoByteChars, but \0 terminated for compatibility with JSFlatString. + */ +class TwoByteCharsZ : public mozilla::RangedPtr +{ + typedef mozilla::RangedPtr Base; + + public: + TwoByteCharsZ() : Base(nullptr, 0) {} + + TwoByteCharsZ(jschar *chars, size_t length) + : Base(chars, length) + { + MOZ_ASSERT(chars[length] == '\0'); + } + + using Base::operator=; +}; + +typedef mozilla::RangedPtr ConstCharPtr; + +/* + * Like TwoByteChars, but the chars are const. + */ +class ConstTwoByteChars : public mozilla::RangedPtr +{ + public: + ConstTwoByteChars(const ConstTwoByteChars &s) : ConstCharPtr(s) {} + MOZ_IMPLICIT ConstTwoByteChars(const mozilla::RangedPtr &s) : ConstCharPtr(s) {} + ConstTwoByteChars(const jschar *s, size_t len) : ConstCharPtr(s, len) {} + ConstTwoByteChars(const jschar *pos, const jschar *start, size_t len) + : ConstCharPtr(pos, start, len) + {} + + using ConstCharPtr::operator=; +}; + + +/* + * Convert a 2-byte character sequence to "ISO-Latin-1". This works by + * truncating each 2-byte pair in the sequence to a 1-byte pair. If the source + * contains any UTF-16 extension characters, then this may give invalid Latin1 + * output. The returned string is zero terminated. The returned string or the + * returned string's |start()| must be freed with JS_free or js_free, + * respectively. If allocation fails, an OOM error will be set and the method + * will return a nullptr chars (which can be tested for with the ! operator). + * This method cannot trigger GC. + */ +extern Latin1CharsZ +LossyTwoByteCharsToNewLatin1CharsZ(js::ThreadSafeContext *cx, + const mozilla::Range tbchars); + +template +extern UTF8CharsZ +CharsToNewUTF8CharsZ(js::ThreadSafeContext *cx, const mozilla::Range chars); + +uint32_t +Utf8ToOneUcs4Char(const uint8_t *utf8Buffer, int utf8Length); + +/* + * Inflate bytes in UTF-8 encoding to jschars. + * - On error, returns an empty TwoByteCharsZ. + * - On success, returns a malloc'd TwoByteCharsZ, and updates |outlen| to hold + * its length; the length value excludes the trailing null. + */ +extern TwoByteCharsZ +UTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen); + +/* + * The same as UTF8CharsToNewTwoByteCharsZ(), except that any malformed UTF-8 characters + * will be replaced by \uFFFD. No exception will be thrown for malformed UTF-8 + * input. + */ +extern TwoByteCharsZ +LossyUTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen); + +/* + * Returns the length of the char buffer required to encode |s| as UTF8. + * Does not include the null-terminator. + */ +JS_PUBLIC_API(size_t) +GetDeflatedUTF8StringLength(JSFlatString *s); + +/* + * Encode |src| as UTF8. The caller must ensure |dst| has enough space. + * Does not write the null terminator. + */ +JS_PUBLIC_API(void) +DeflateStringToUTF8Buffer(JSFlatString *src, mozilla::RangedPtr dst); + +} // namespace JS + +inline void JS_free(JS::Latin1CharsZ &ptr) { js_free((void*)ptr.get()); } +inline void JS_free(JS::UTF8CharsZ &ptr) { js_free((void*)ptr.get()); } + +#endif /* js_CharacterEncoding_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Class.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Class.h new file mode 100644 index 0000000000..559cc65c85 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Class.h @@ -0,0 +1,544 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JSClass definition and its component types, plus related interfaces. */ + +#ifndef js_Class_h +#define js_Class_h + +#include "mozilla/NullPtr.h" + +#include "jstypes.h" + +#include "js/CallArgs.h" +#include "js/Id.h" +#include "js/TypeDecls.h" + +/* + * A JSClass acts as a vtable for JS objects that allows JSAPI clients to + * control various aspects of the behavior of an object like property lookup. + * js::Class is an engine-private extension that allows more control over + * object behavior and, e.g., allows custom slow layout. + */ + +struct JSFreeOp; +struct JSFunctionSpec; + +namespace js { + +struct Class; +class FreeOp; +class PropertyName; +class Shape; + +// This is equal to JSFunction::class_. Use it in places where you don't want +// to #include jsfun.h. +extern JS_FRIEND_DATA(const js::Class* const) FunctionClassPtr; + +} // namespace js + +// JSClass operation signatures. + +// Add or get a property named by id in obj. Note the jsid id type -- id may +// be a string (Unicode property identifier) or an int (element index). The +// *vp out parameter, on success, is the new property value after the action. +typedef bool +(* JSPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); + +// Set a property named by id in obj, treating the assignment as strict +// mode code if strict is true. Note the jsid id type -- id may be a string +// (Unicode property identifier) or an int (element index). The *vp out +// parameter, on success, is the new property value after the +// set. +typedef bool +(* JSStrictPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool strict, JS::MutableHandleValue vp); + +// Delete a property named by id in obj. +// +// If an error occurred, return false as per normal JSAPI error practice. +// +// If no error occurred, but the deletion attempt wasn't allowed (perhaps +// because the property was non-configurable), set *succeeded to false and +// return true. This will cause |delete obj[id]| to evaluate to false in +// non-strict mode code, and to throw a TypeError in strict mode code. +// +// If no error occurred and the deletion wasn't disallowed (this is *not* the +// same as saying that a deletion actually occurred -- deleting a non-existent +// property, or an inherited property, is allowed -- it's just pointless), +// set *succeeded to true and return true. +typedef bool +(* JSDeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *succeeded); + +// This function type is used for callbacks that enumerate the properties of +// a JSObject. The behavior depends on the value of enum_op: +// +// JSENUMERATE_INIT +// A new, opaque iterator state should be allocated and stored in *statep. +// (You can use PRIVATE_TO_JSVAL() to tag the pointer to be stored). +// +// The number of properties that will be enumerated should be returned as +// an integer jsval in *idp, if idp is non-null, and provided the number of +// enumerable properties is known. If idp is non-null and the number of +// enumerable properties can't be computed in advance, *idp should be set +// to JSVAL_ZERO. +// +// JSENUMERATE_INIT_ALL +// Used identically to JSENUMERATE_INIT, but exposes all properties of the +// object regardless of enumerability. +// +// JSENUMERATE_NEXT +// A previously allocated opaque iterator state is passed in via statep. +// Return the next jsid in the iteration using *idp. The opaque iterator +// state pointed at by statep is destroyed and *statep is set to JSVAL_NULL +// if there are no properties left to enumerate. +// +// JSENUMERATE_DESTROY +// Destroy the opaque iterator state previously allocated in *statep by a +// call to this function when enum_op was JSENUMERATE_INIT or +// JSENUMERATE_INIT_ALL. +// +// The return value is used to indicate success, with a value of false +// indicating failure. +typedef bool +(* JSNewEnumerateOp)(JSContext *cx, JS::HandleObject obj, JSIterateOp enum_op, + JS::MutableHandleValue statep, JS::MutableHandleId idp); + +// The old-style JSClass.enumerate op should define all lazy properties not +// yet reflected in obj. +typedef bool +(* JSEnumerateOp)(JSContext *cx, JS::HandleObject obj); + +// Resolve a lazy property named by id in obj by defining it directly in obj. +// Lazy properties are those reflected from some peer native property space +// (e.g., the DOM attributes for a given node reflected as obj) on demand. +// +// JS looks for a property in an object, and if not found, tries to resolve +// the given id. If resolve succeeds, the engine looks again in case resolve +// defined obj[id]. If no such property exists directly in obj, the process +// is repeated with obj's prototype, etc. +// +// NB: JSNewResolveOp provides a cheaper way to resolve lazy properties. +typedef bool +(* JSResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); + +// Like JSResolveOp, except the *objp out parameter, on success, should be null +// to indicate that id was not resolved; and non-null, referring to obj or one +// of its prototypes, if id was resolved. The hook may assume *objp is null on +// entry. +// +// This hook instead of JSResolveOp is called via the JSClass.resolve member +// if JSCLASS_NEW_RESOLVE is set in JSClass.flags. +typedef bool +(* JSNewResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleObject objp); + +// Convert obj to the given type, returning true with the resulting value in +// *vp on success, and returning false on error or exception. +typedef bool +(* JSConvertOp)(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); + +// Finalize obj, which the garbage collector has determined to be unreachable +// from other live objects or from GC roots. Obviously, finalizers must never +// store a reference to obj. +typedef void +(* JSFinalizeOp)(JSFreeOp *fop, JSObject *obj); + +// Finalizes external strings created by JS_NewExternalString. +struct JSStringFinalizer { + void (*finalize)(const JSStringFinalizer *fin, jschar *chars); +}; + +// Check whether v is an instance of obj. Return false on error or exception, +// true on success with true in *bp if v is an instance of obj, false in +// *bp otherwise. +typedef bool +(* JSHasInstanceOp)(JSContext *cx, JS::HandleObject obj, JS::MutableHandleValue vp, + bool *bp); + +// Function type for trace operation of the class called to enumerate all +// traceable things reachable from obj's private data structure. For each such +// thing, a trace implementation must call one of the JS_Call*Tracer variants +// on the thing. +// +// JSTraceOp implementation can assume that no other threads mutates object +// state. It must not change state of the object or corresponding native +// structures. The only exception for this rule is the case when the embedding +// needs a tight integration with GC. In that case the embedding can check if +// the traversal is a part of the marking phase through calling +// JS_IsGCMarkingTracer and apply a special code like emptying caches or +// marking its native structures. +typedef void +(* JSTraceOp)(JSTracer *trc, JSObject *obj); + +// Hook that creates an iterator object for a given object. Returns the +// iterator object or null if an error or exception was thrown on cx. +typedef JSObject * +(* JSIteratorOp)(JSContext *cx, JS::HandleObject obj, bool keysonly); + +typedef JSObject * +(* JSWeakmapKeyDelegateOp)(JSObject *obj); + +/* js::Class operation signatures. */ + +namespace js { + +typedef bool +(* LookupGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleObject objp, JS::MutableHandle propp); +typedef bool +(* LookupPropOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleObject objp, JS::MutableHandle propp); +typedef bool +(* LookupElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::MutableHandleObject objp, JS::MutableHandle propp); +typedef bool +(* DefineGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +typedef bool +(* DefinePropOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, + unsigned attrs); +typedef bool +(* DefineElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +typedef bool +(* GenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, + JS::MutableHandleValue vp); +typedef bool +(* PropertyIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, + JS::Handle name, JS::MutableHandleValue vp); +typedef bool +(* ElementIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, + JS::MutableHandleValue vp); +typedef bool +(* StrictGenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp, bool strict); +typedef bool +(* StrictPropertyIdOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleValue vp, bool strict); +typedef bool +(* StrictElementIdOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::MutableHandleValue vp, bool strict); +typedef bool +(* GenericAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +typedef bool +(* PropertyAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, + unsigned *attrsp); +typedef bool +(* DeleteGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); + +typedef bool +(* WatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); + +typedef bool +(* UnwatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); + +typedef bool +(* SliceOp)(JSContext *cx, JS::HandleObject obj, uint32_t begin, uint32_t end, + JS::HandleObject result); // result is actually preallocted. + +// A generic type for functions mapping an object to another object, or null +// if an error or exception was thrown on cx. +typedef JSObject * +(* ObjectOp)(JSContext *cx, JS::HandleObject obj); + +// Hook to map an object to its inner object. Infallible. +typedef JSObject * +(* InnerObjectOp)(JSObject *obj); + +typedef void +(* FinalizeOp)(FreeOp *fop, JSObject *obj); + +#define JS_CLASS_MEMBERS(FinalizeOpType) \ + const char *name; \ + uint32_t flags; \ + \ + /* Mandatory function pointer members. */ \ + JSPropertyOp addProperty; \ + JSDeletePropertyOp delProperty; \ + JSPropertyOp getProperty; \ + JSStrictPropertyOp setProperty; \ + JSEnumerateOp enumerate; \ + JSResolveOp resolve; \ + JSConvertOp convert; \ + \ + /* Optional members (may be null). */ \ + FinalizeOpType finalize; \ + JSNative call; \ + JSHasInstanceOp hasInstance; \ + JSNative construct; \ + JSTraceOp trace + +// Callback for the creation of constructor and prototype objects. +typedef JSObject *(*ClassObjectCreationOp)(JSContext *cx, JSProtoKey key); + +// Callback for custom post-processing after class initialization via ClassSpec. +typedef bool (*FinishClassInitOp)(JSContext *cx, JS::HandleObject ctor, + JS::HandleObject proto); + +struct ClassSpec +{ + ClassObjectCreationOp createConstructor; + ClassObjectCreationOp createPrototype; + const JSFunctionSpec *constructorFunctions; + const JSFunctionSpec *prototypeFunctions; + const JSPropertySpec *prototypeProperties; + FinishClassInitOp finishInit; + bool defined() const { return !!createConstructor; } +}; + +struct ClassExtension +{ + ObjectOp outerObject; + InnerObjectOp innerObject; + JSIteratorOp iteratorObject; + + /* + * isWrappedNative is true only if the class is an XPCWrappedNative. + * WeakMaps use this to override the wrapper disposal optimization. + */ + bool isWrappedNative; + + /* + * If an object is used as a key in a weakmap, it may be desirable for the + * garbage collector to keep that object around longer than it otherwise + * would. A common case is when the key is a wrapper around an object in + * another compartment, and we want to avoid collecting the wrapper (and + * removing the weakmap entry) as long as the wrapped object is alive. In + * that case, the wrapped object is returned by the wrapper's + * weakmapKeyDelegateOp hook. As long as the wrapper is used as a weakmap + * key, it will not be collected (and remain in the weakmap) until the + * wrapped object is collected. + */ + JSWeakmapKeyDelegateOp weakmapKeyDelegateOp; +}; + +#define JS_NULL_CLASS_SPEC {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr} +#define JS_NULL_CLASS_EXT {nullptr,nullptr,nullptr,false,nullptr} + +struct ObjectOps +{ + LookupGenericOp lookupGeneric; + LookupPropOp lookupProperty; + LookupElementOp lookupElement; + DefineGenericOp defineGeneric; + DefinePropOp defineProperty; + DefineElementOp defineElement; + GenericIdOp getGeneric; + PropertyIdOp getProperty; + ElementIdOp getElement; + StrictGenericIdOp setGeneric; + StrictPropertyIdOp setProperty; + StrictElementIdOp setElement; + GenericAttributesOp getGenericAttributes; + GenericAttributesOp setGenericAttributes; + DeleteGenericOp deleteGeneric; + WatchOp watch; + UnwatchOp unwatch; + SliceOp slice; // Optimized slice, can be null. + JSNewEnumerateOp enumerate; + ObjectOp thisObject; +}; + +#define JS_NULL_OBJECT_OPS \ + {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr} + +} // namespace js + +// Classes, objects, and properties. + +typedef void (*JSClassInternal)(); + +struct JSClass { + JS_CLASS_MEMBERS(JSFinalizeOp); + + void *reserved[31]; +}; + +#define JSCLASS_HAS_PRIVATE (1<<0) // objects have private slot +#define JSCLASS_NEW_ENUMERATE (1<<1) // has JSNewEnumerateOp hook +#define JSCLASS_NEW_RESOLVE (1<<2) // has JSNewResolveOp hook +#define JSCLASS_PRIVATE_IS_NSISUPPORTS (1<<3) // private is (nsISupports *) +#define JSCLASS_IS_DOMJSCLASS (1<<4) // objects are DOM +#define JSCLASS_IMPLEMENTS_BARRIERS (1<<5) // Correctly implements GC read + // and write barriers +#define JSCLASS_EMULATES_UNDEFINED (1<<6) // objects of this class act + // like the value undefined, + // in some contexts +#define JSCLASS_USERBIT1 (1<<7) // Reserved for embeddings. + +// To reserve slots fetched and stored via JS_Get/SetReservedSlot, bitwise-or +// JSCLASS_HAS_RESERVED_SLOTS(n) into the initializer for JSClass.flags, where +// n is a constant in [1, 255]. Reserved slots are indexed from 0 to n-1. +#define JSCLASS_RESERVED_SLOTS_SHIFT 8 // room for 8 flags below */ +#define JSCLASS_RESERVED_SLOTS_WIDTH 8 // and 16 above this field */ +#define JSCLASS_RESERVED_SLOTS_MASK JS_BITMASK(JSCLASS_RESERVED_SLOTS_WIDTH) +#define JSCLASS_HAS_RESERVED_SLOTS(n) (((n) & JSCLASS_RESERVED_SLOTS_MASK) \ + << JSCLASS_RESERVED_SLOTS_SHIFT) +#define JSCLASS_RESERVED_SLOTS(clasp) (((clasp)->flags \ + >> JSCLASS_RESERVED_SLOTS_SHIFT) \ + & JSCLASS_RESERVED_SLOTS_MASK) + +#define JSCLASS_HIGH_FLAGS_SHIFT (JSCLASS_RESERVED_SLOTS_SHIFT + \ + JSCLASS_RESERVED_SLOTS_WIDTH) + +#define JSCLASS_IS_ANONYMOUS (1<<(JSCLASS_HIGH_FLAGS_SHIFT+0)) +#define JSCLASS_IS_GLOBAL (1<<(JSCLASS_HIGH_FLAGS_SHIFT+1)) +#define JSCLASS_INTERNAL_FLAG2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2)) +#define JSCLASS_INTERNAL_FLAG3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3)) + +#define JSCLASS_IS_PROXY (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4)) + +// Bit 22 unused. + +// Reserved for embeddings. +#define JSCLASS_USERBIT2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+6)) +#define JSCLASS_USERBIT3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+7)) + +#define JSCLASS_BACKGROUND_FINALIZE (1<<(JSCLASS_HIGH_FLAGS_SHIFT+8)) + +// Bits 26 through 31 are reserved for the CACHED_PROTO_KEY mechanism, see +// below. + +// ECMA-262 requires that most constructors used internally create objects +// with "the original Foo.prototype value" as their [[Prototype]] (__proto__) +// member initial value. The "original ... value" verbiage is there because +// in ECMA-262, global properties naming class objects are read/write and +// deleteable, for the most part. +// +// Implementing this efficiently requires that global objects have classes +// with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS was +// previously allowed, but is now an ES5 violation and thus unsupported. +// +// JSCLASS_GLOBAL_APPLICATION_SLOTS is the number of slots reserved at +// the beginning of every global object's slots for use by the +// application. +#define JSCLASS_GLOBAL_APPLICATION_SLOTS 3 +#define JSCLASS_GLOBAL_SLOT_COUNT (JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 3 + 30) +#define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n) \ + (JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + (n))) +#define JSCLASS_GLOBAL_FLAGS \ + JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(0) +#define JSCLASS_HAS_GLOBAL_FLAG_AND_SLOTS(clasp) \ + (((clasp)->flags & JSCLASS_IS_GLOBAL) \ + && JSCLASS_RESERVED_SLOTS(clasp) >= JSCLASS_GLOBAL_SLOT_COUNT) + +// Fast access to the original value of each standard class's prototype. +#define JSCLASS_CACHED_PROTO_SHIFT (JSCLASS_HIGH_FLAGS_SHIFT + 10) +#define JSCLASS_CACHED_PROTO_WIDTH 6 +#define JSCLASS_CACHED_PROTO_MASK JS_BITMASK(JSCLASS_CACHED_PROTO_WIDTH) +#define JSCLASS_HAS_CACHED_PROTO(key) (uint32_t(key) << JSCLASS_CACHED_PROTO_SHIFT) +#define JSCLASS_CACHED_PROTO_KEY(clasp) ((JSProtoKey) \ + (((clasp)->flags \ + >> JSCLASS_CACHED_PROTO_SHIFT) \ + & JSCLASS_CACHED_PROTO_MASK)) + +// Initializer for unused members of statically initialized JSClass structs. +#define JSCLASS_NO_INTERNAL_MEMBERS {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} +#define JSCLASS_NO_OPTIONAL_MEMBERS 0,0,0,0,0,JSCLASS_NO_INTERNAL_MEMBERS + +namespace js { + +struct Class +{ + JS_CLASS_MEMBERS(FinalizeOp); + ClassSpec spec; + ClassExtension ext; + ObjectOps ops; + + /* Class is not native and its map is not a scope. */ + static const uint32_t NON_NATIVE = JSCLASS_INTERNAL_FLAG2; + + bool isNative() const { + return !(flags & NON_NATIVE); + } + + bool hasPrivate() const { + return !!(flags & JSCLASS_HAS_PRIVATE); + } + + bool emulatesUndefined() const { + return flags & JSCLASS_EMULATES_UNDEFINED; + } + + bool isJSFunction() const { + return this == js::FunctionClassPtr; + } + + bool isCallable() const { + return isJSFunction() || call; + } + + bool isProxy() const { + return flags & JSCLASS_IS_PROXY; + } + + bool isDOMClass() const { + return flags & JSCLASS_IS_DOMJSCLASS; + } + + static size_t offsetOfFlags() { return offsetof(Class, flags); } +}; + +JS_STATIC_ASSERT(offsetof(JSClass, name) == offsetof(Class, name)); +JS_STATIC_ASSERT(offsetof(JSClass, flags) == offsetof(Class, flags)); +JS_STATIC_ASSERT(offsetof(JSClass, addProperty) == offsetof(Class, addProperty)); +JS_STATIC_ASSERT(offsetof(JSClass, delProperty) == offsetof(Class, delProperty)); +JS_STATIC_ASSERT(offsetof(JSClass, getProperty) == offsetof(Class, getProperty)); +JS_STATIC_ASSERT(offsetof(JSClass, setProperty) == offsetof(Class, setProperty)); +JS_STATIC_ASSERT(offsetof(JSClass, enumerate) == offsetof(Class, enumerate)); +JS_STATIC_ASSERT(offsetof(JSClass, resolve) == offsetof(Class, resolve)); +JS_STATIC_ASSERT(offsetof(JSClass, convert) == offsetof(Class, convert)); +JS_STATIC_ASSERT(offsetof(JSClass, finalize) == offsetof(Class, finalize)); +JS_STATIC_ASSERT(offsetof(JSClass, call) == offsetof(Class, call)); +JS_STATIC_ASSERT(offsetof(JSClass, construct) == offsetof(Class, construct)); +JS_STATIC_ASSERT(offsetof(JSClass, hasInstance) == offsetof(Class, hasInstance)); +JS_STATIC_ASSERT(offsetof(JSClass, trace) == offsetof(Class, trace)); +JS_STATIC_ASSERT(sizeof(JSClass) == sizeof(Class)); + +static MOZ_ALWAYS_INLINE const JSClass * +Jsvalify(const Class *c) +{ + return (const JSClass *)c; +} + +static MOZ_ALWAYS_INLINE const Class * +Valueify(const JSClass *c) +{ + return (const Class *)c; +} + +/* + * Enumeration describing possible values of the [[Class]] internal property + * value of objects. + */ +enum ESClassValue { + ESClass_Array, ESClass_Number, ESClass_String, ESClass_Boolean, + ESClass_RegExp, ESClass_ArrayBuffer, ESClass_Date +}; + +/* + * Return whether the given object has the given [[Class]] internal property + * value. Beware, this query says nothing about the js::Class of the JSObject + * so the caller must not assume anything about obj's representation (e.g., obj + * may be a proxy). + */ +inline bool +ObjectClassIs(JSObject &obj, ESClassValue classValue, JSContext *cx); + +/* Just a helper that checks v.isObject before calling ObjectClassIs. */ +inline bool +IsObjectWithClass(const JS::Value &v, ESClassValue classValue, JSContext *cx); + +} /* namespace js */ + +#endif /* js_Class_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Date.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Date.h new file mode 100644 index 0000000000..6199f9eca5 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Date.h @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_Date_h +#define js_Date_h + +#include "jstypes.h" + +namespace JS { + +// Year is a year, month is 0-11, day is 1-based. The return value is +// a number of milliseconds since the epoch. Can return NaN. +JS_PUBLIC_API(double) +MakeDate(double year, unsigned month, unsigned day); + +// Takes an integer number of milliseconds since the epoch and returns the +// year. Can return NaN, and will do so if NaN is passed in. +JS_PUBLIC_API(double) +YearFromTime(double time); + +// Takes an integer number of milliseconds since the epoch and returns the +// month (0-11). Can return NaN, and will do so if NaN is passed in. +JS_PUBLIC_API(double) +MonthFromTime(double time); + +// Takes an integer number of milliseconds since the epoch and returns the +// day (1-based). Can return NaN, and will do so if NaN is passed in. +JS_PUBLIC_API(double) +DayFromTime(double time); + +} // namespace JS + +#endif /* js_Date_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/GCAPI.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/GCAPI.h new file mode 100644 index 0000000000..c58d62d029 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/GCAPI.h @@ -0,0 +1,514 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_GCAPI_h +#define js_GCAPI_h + +#include "mozilla/NullPtr.h" + +#include "js/HeapAPI.h" + +namespace js { +namespace gc { +class GCRuntime; +} +} + +typedef enum JSGCMode { + /* Perform only global GCs. */ + JSGC_MODE_GLOBAL = 0, + + /* Perform per-compartment GCs until too much garbage has accumulated. */ + JSGC_MODE_COMPARTMENT = 1, + + /* + * Collect in short time slices rather than all at once. Implies + * JSGC_MODE_COMPARTMENT. + */ + JSGC_MODE_INCREMENTAL = 2 +} JSGCMode; + +namespace JS { + +#define GCREASONS(D) \ + /* Reasons internal to the JS engine */ \ + D(API) \ + D(MAYBEGC) \ + D(DESTROY_RUNTIME) \ + D(DESTROY_CONTEXT) \ + D(LAST_DITCH) \ + D(TOO_MUCH_MALLOC) \ + D(ALLOC_TRIGGER) \ + D(DEBUG_GC) \ + D(TRANSPLANT) \ + D(RESET) \ + D(OUT_OF_NURSERY) \ + D(EVICT_NURSERY) \ + D(FULL_STORE_BUFFER) \ + \ + /* These are reserved for future use. */ \ + D(RESERVED0) \ + D(RESERVED1) \ + D(RESERVED2) \ + D(RESERVED3) \ + D(RESERVED4) \ + D(RESERVED5) \ + D(RESERVED6) \ + D(RESERVED7) \ + D(RESERVED8) \ + D(RESERVED9) \ + D(RESERVED10) \ + D(RESERVED11) \ + D(RESERVED12) \ + D(RESERVED13) \ + D(RESERVED14) \ + D(RESERVED15) \ + D(RESERVED16) \ + D(RESERVED17) \ + D(RESERVED18) \ + D(RESERVED19) \ + \ + /* Reasons from Firefox */ \ + D(DOM_WINDOW_UTILS) \ + D(COMPONENT_UTILS) \ + D(MEM_PRESSURE) \ + D(CC_WAITING) \ + D(CC_FORCED) \ + D(LOAD_END) \ + D(POST_COMPARTMENT) \ + D(PAGE_HIDE) \ + D(NSJSCONTEXT_DESTROY) \ + D(SET_NEW_DOCUMENT) \ + D(SET_DOC_SHELL) \ + D(DOM_UTILS) \ + D(DOM_IPC) \ + D(DOM_WORKER) \ + D(INTER_SLICE_GC) \ + D(REFRESH_FRAME) \ + D(FULL_GC_TIMER) \ + D(SHUTDOWN_CC) \ + D(FINISH_LARGE_EVALUTE) + +namespace gcreason { + +/* GCReasons will end up looking like JSGC_MAYBEGC */ +enum Reason { +#define MAKE_REASON(name) name, + GCREASONS(MAKE_REASON) +#undef MAKE_REASON + NO_REASON, + NUM_REASONS, + + /* + * For telemetry, we want to keep a fixed max bucket size over time so we + * don't have to switch histograms. 100 is conservative; as of this writing + * there are 26. But the cost of extra buckets seems to be low while the + * cost of switching histograms is high. + */ + NUM_TELEMETRY_REASONS = 100 +}; + +} /* namespace gcreason */ + +/* + * Zone GC: + * + * SpiderMonkey's GC is capable of performing a collection on an arbitrary + * subset of the zones in the system. This allows an embedding to minimize + * collection time by only collecting zones that have run code recently, + * ignoring the parts of the heap that are unlikely to have changed. + * + * When triggering a GC using one of the functions below, it is first necessary + * to select the zones to be collected. To do this, you can call + * PrepareZoneForGC on each zone, or you can call PrepareForFullGC to select + * all zones. Failing to select any zone is an error. + */ + +/* + * Schedule the given zone to be collected as part of the next GC. + */ +extern JS_FRIEND_API(void) +PrepareZoneForGC(Zone *zone); + +/* + * Schedule all zones to be collected in the next GC. + */ +extern JS_FRIEND_API(void) +PrepareForFullGC(JSRuntime *rt); + +/* + * When performing an incremental GC, the zones that were selected for the + * previous incremental slice must be selected in subsequent slices as well. + * This function selects those slices automatically. + */ +extern JS_FRIEND_API(void) +PrepareForIncrementalGC(JSRuntime *rt); + +/* + * Returns true if any zone in the system has been scheduled for GC with one of + * the functions above or by the JS engine. + */ +extern JS_FRIEND_API(bool) +IsGCScheduled(JSRuntime *rt); + +/* + * Undoes the effect of the Prepare methods above. The given zone will not be + * collected in the next GC. + */ +extern JS_FRIEND_API(void) +SkipZoneForGC(Zone *zone); + +/* + * Non-Incremental GC: + * + * The following functions perform a non-incremental GC. + */ + +/* + * Performs a non-incremental collection of all selected zones. Some objects + * that are unreachable from the program may still be alive afterwards because + * of internal references. + */ +extern JS_FRIEND_API(void) +GCForReason(JSRuntime *rt, gcreason::Reason reason); + +/* + * Perform a non-incremental collection after clearing caches and other + * temporary references to objects. This will remove all unreferenced objects + * in the system. + */ +extern JS_FRIEND_API(void) +ShrinkingGC(JSRuntime *rt, gcreason::Reason reason); + +/* + * Incremental GC: + * + * Incremental GC divides the full mark-and-sweep collection into multiple + * slices, allowing client JavaScript code to run between each slice. This + * allows interactive apps to avoid long collection pauses. Incremental GC does + * not make collection take less time, it merely spreads that time out so that + * the pauses are less noticable. + * + * For a collection to be carried out incrementally the following conditions + * must be met: + * - The collection must be run by calling JS::IncrementalGC() rather than + * JS_GC(). + * - The GC mode must have been set to JSGC_MODE_INCREMENTAL with + * JS_SetGCParameter(). + * - All native objects that have their own trace hook must indicate that they + * implement read and write barriers with the JSCLASS_IMPLEMENTS_BARRIERS + * flag. + * + * Note: Even if incremental GC is enabled and working correctly, + * non-incremental collections can still happen when low on memory. + */ + +/* + * Begin an incremental collection and perform one slice worth of work or + * perform a slice of an ongoing incremental collection. When this function + * returns, the collection is not complete. This function must be called + * repeatedly until !IsIncrementalGCInProgress(rt). + * + * Note: SpiderMonkey's GC is not realtime. Slices in practice may be longer or + * shorter than the requested interval. + */ +extern JS_FRIEND_API(void) +IncrementalGC(JSRuntime *rt, gcreason::Reason reason, int64_t millis = 0); + +/* + * If IsIncrementalGCInProgress(rt), this call finishes the ongoing collection + * by performing an arbitrarily long slice. If !IsIncrementalGCInProgress(rt), + * this is equivalent to GCForReason. When this function returns, + * IsIncrementalGCInProgress(rt) will always be false. + */ +extern JS_FRIEND_API(void) +FinishIncrementalGC(JSRuntime *rt, gcreason::Reason reason); + +enum GCProgress { + /* + * During non-incremental GC, the GC is bracketed by JSGC_CYCLE_BEGIN/END + * callbacks. During an incremental GC, the sequence of callbacks is as + * follows: + * JSGC_CYCLE_BEGIN, JSGC_SLICE_END (first slice) + * JSGC_SLICE_BEGIN, JSGC_SLICE_END (second slice) + * ... + * JSGC_SLICE_BEGIN, JSGC_CYCLE_END (last slice) + */ + + GC_CYCLE_BEGIN, + GC_SLICE_BEGIN, + GC_SLICE_END, + GC_CYCLE_END +}; + +struct JS_FRIEND_API(GCDescription) { + bool isCompartment_; + + explicit GCDescription(bool isCompartment) + : isCompartment_(isCompartment) {} + + jschar *formatMessage(JSRuntime *rt) const; + jschar *formatJSON(JSRuntime *rt, uint64_t timestamp) const; +}; + +typedef void +(* GCSliceCallback)(JSRuntime *rt, GCProgress progress, const GCDescription &desc); + +/* + * The GC slice callback is called at the beginning and end of each slice. This + * callback may be used for GC notifications as well as to perform additional + * marking. + */ +extern JS_FRIEND_API(GCSliceCallback) +SetGCSliceCallback(JSRuntime *rt, GCSliceCallback callback); + +/* + * Incremental GC defaults to enabled, but may be disabled for testing or in + * embeddings that have not yet implemented barriers on their native classes. + * There is not currently a way to re-enable incremental GC once it has been + * disabled on the runtime. + */ +extern JS_FRIEND_API(void) +DisableIncrementalGC(JSRuntime *rt); + +/* + * Returns true if incremental GC is enabled. Simply having incremental GC + * enabled is not sufficient to ensure incremental collections are happening. + * See the comment "Incremental GC" above for reasons why incremental GC may be + * suppressed. Inspection of the "nonincremental reason" field of the + * GCDescription returned by GCSliceCallback may help narrow down the cause if + * collections are not happening incrementally when expected. + */ +extern JS_FRIEND_API(bool) +IsIncrementalGCEnabled(JSRuntime *rt); + +/* + * Returns true while an incremental GC is ongoing, both when actively + * collecting and between slices. + */ +JS_FRIEND_API(bool) +IsIncrementalGCInProgress(JSRuntime *rt); + +/* + * Returns true when writes to GC things must call an incremental (pre) barrier. + * This is generally only true when running mutator code in-between GC slices. + * At other times, the barrier may be elided for performance. + */ +extern JS_FRIEND_API(bool) +IsIncrementalBarrierNeeded(JSRuntime *rt); + +extern JS_FRIEND_API(bool) +IsIncrementalBarrierNeeded(JSContext *cx); + +/* + * Notify the GC that a reference to a GC thing is about to be overwritten. + * These methods must be called if IsIncrementalBarrierNeeded. + */ +extern JS_FRIEND_API(void) +IncrementalReferenceBarrier(void *ptr, JSGCTraceKind kind); + +extern JS_FRIEND_API(void) +IncrementalValueBarrier(const Value &v); + +extern JS_FRIEND_API(void) +IncrementalObjectBarrier(JSObject *obj); + +/* + * Returns true if the most recent GC ran incrementally. + */ +extern JS_FRIEND_API(bool) +WasIncrementalGC(JSRuntime *rt); + +/* + * Generational GC: + * + * Note: Generational GC is not yet enabled by default. The following class + * is non-functional unless SpiderMonkey was configured with + * --enable-gcgenerational. + */ + +/* Ensure that generational GC is disabled within some scope. */ +class JS_FRIEND_API(AutoDisableGenerationalGC) +{ + js::gc::GCRuntime *gc; +#if defined(JSGC_GENERATIONAL) && defined(JS_GC_ZEAL) + bool restartVerifier; +#endif + + public: + explicit AutoDisableGenerationalGC(JSRuntime *rt); + ~AutoDisableGenerationalGC(); +}; + +/* + * Returns true if generational allocation and collection is currently enabled + * on the given runtime. + */ +extern JS_FRIEND_API(bool) +IsGenerationalGCEnabled(JSRuntime *rt); + +/* + * Returns the GC's "number". This does not correspond directly to the number + * of GCs that have been run, but is guaranteed to be monotonically increasing + * with GC activity. + */ +extern JS_FRIEND_API(size_t) +GetGCNumber(); + +/* + * The GC does not immediately return the unused memory freed by a collection + * back to the system incase it is needed soon afterwards. This call forces the + * GC to return this memory immediately. + */ +extern JS_FRIEND_API(void) +ShrinkGCBuffers(JSRuntime *rt); + +/* + * Assert if a GC occurs while this class is live. This class does not disable + * the static rooting hazard analysis. + */ +class JS_PUBLIC_API(AutoAssertOnGC) +{ +#ifdef DEBUG + js::gc::GCRuntime *gc; + size_t gcNumber; + + public: + AutoAssertOnGC(); + explicit AutoAssertOnGC(JSRuntime *rt); + ~AutoAssertOnGC(); + + static void VerifyIsSafeToGC(JSRuntime *rt); +#else + public: + AutoAssertOnGC() {} + explicit AutoAssertOnGC(JSRuntime *rt) {} + ~AutoAssertOnGC() {} + + static void VerifyIsSafeToGC(JSRuntime *rt) {} +#endif +}; + +/* + * Disable the static rooting hazard analysis in the live region, but assert if + * any GC occurs while this guard object is live. This is most useful to help + * the exact rooting hazard analysis in complex regions, since it cannot + * understand dataflow. + * + * Note: GC behavior is unpredictable even when deterministice and is generally + * non-deterministic in practice. The fact that this guard has not + * asserted is not a guarantee that a GC cannot happen in the guarded + * region. As a rule, anyone performing a GC unsafe action should + * understand the GC properties of all code in that region and ensure + * that the hazard analysis is correct for that code, rather than relying + * on this class. + */ +class JS_PUBLIC_API(AutoSuppressGCAnalysis) : public AutoAssertOnGC +{ + public: + AutoSuppressGCAnalysis() : AutoAssertOnGC() {} + explicit AutoSuppressGCAnalysis(JSRuntime *rt) : AutoAssertOnGC(rt) {} +}; + +/* + * Place AutoCheckCannotGC in scopes that you believe can never GC. These + * annotations will be verified both dynamically via AutoAssertOnGC, and + * statically with the rooting hazard analysis (implemented by making the + * analysis consider AutoCheckCannotGC to be a GC pointer, and therefore + * complain if it is live across a GC call.) It is useful when dealing with + * internal pointers to GC things where the GC thing itself may not be present + * for the static analysis: e.g. acquiring inline chars from a JSString* on the + * heap. + */ +class JS_PUBLIC_API(AutoCheckCannotGC) : public AutoAssertOnGC +{ + public: + AutoCheckCannotGC() : AutoAssertOnGC() {} + explicit AutoCheckCannotGC(JSRuntime *rt) : AutoAssertOnGC(rt) {} +}; + +/* + * Unsets the gray bit for anything reachable from |thing|. |kind| should not be + * JSTRACE_SHAPE. |thing| should be non-null. + */ +extern JS_FRIEND_API(bool) +UnmarkGrayGCThingRecursively(void *thing, JSGCTraceKind kind); + +/* + * This should be called when an object that is marked gray is exposed to the JS + * engine (by handing it to running JS code or writing it into live JS + * data). During incremental GC, since the gray bits haven't been computed yet, + * we conservatively mark the object black. + */ +static MOZ_ALWAYS_INLINE void +ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) +{ + MOZ_ASSERT(kind != JSTRACE_SHAPE); + + shadow::Runtime *rt = js::gc::GetGCThingRuntime(thing); +#ifdef JSGC_GENERATIONAL + /* + * GC things residing in the nursery cannot be gray: they have no mark bits. + * All live objects in the nursery are moved to tenured at the beginning of + * each GC slice, so the gray marker never sees nursery things. + */ + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) + return; +#endif + if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) + IncrementalReferenceBarrier(thing, kind); + else if (GCThingIsMarkedGray(thing)) + UnmarkGrayGCThingRecursively(thing, kind); +} + +static MOZ_ALWAYS_INLINE void +ExposeObjectToActiveJS(JSObject *obj) +{ + ExposeGCThingToActiveJS(obj, JSTRACE_OBJECT); +} + +/* + * If a GC is currently marking, mark the object black. + */ +static MOZ_ALWAYS_INLINE void +MarkGCThingAsLive(JSRuntime *rt_, void *thing, JSGCTraceKind kind) +{ + shadow::Runtime *rt = shadow::Runtime::asShadowRuntime(rt_); +#ifdef JSGC_GENERATIONAL + /* + * Any object in the nursery will not be freed during any GC running at that time. + */ + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) + return; +#endif + if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) + IncrementalReferenceBarrier(thing, kind); +} + +static MOZ_ALWAYS_INLINE void +MarkStringAsLive(Zone *zone, JSString *string) +{ + JSRuntime *rt = JS::shadow::Zone::asShadowZone(zone)->runtimeFromMainThread(); + MarkGCThingAsLive(rt, string, JSTRACE_STRING); +} + +/* + * Internal to Firefox. + * + * Note: this is not related to the PokeGC in nsJSEnvironment. + */ +extern JS_FRIEND_API(void) +PokeGC(JSRuntime *rt); + +/* + * Internal to Firefox. + */ +extern JS_FRIEND_API(void) +NotifyDidPaint(JSRuntime *rt); + +} /* namespace JS */ + +#endif /* js_GCAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/HashTable.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/HashTable.h new file mode 100644 index 0000000000..4c27308b5e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/HashTable.h @@ -0,0 +1,1672 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_HashTable_h +#define js_HashTable_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Casting.h" +#include "mozilla/DebugOnly.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/PodOperations.h" +#include "mozilla/ReentrancyGuard.h" +#include "mozilla/TemplateLib.h" +#include "mozilla/TypeTraits.h" + +#include "js/Utility.h" + +namespace js { + +class TempAllocPolicy; +template struct DefaultHasher; +template class HashMapEntry; +namespace detail { + template class HashTableEntry; + template class HashTable; +} + +/*****************************************************************************/ + +// A JS-friendly, STL-like container providing a hash-based map from keys to +// values. In particular, HashMap calls constructors and destructors of all +// objects added so non-PODs may be used safely. +// +// Key/Value requirements: +// - movable, destructible, assignable +// HashPolicy requirements: +// - see Hash Policy section below +// AllocPolicy: +// - see jsalloc.h +// +// Note: +// - HashMap is not reentrant: Key/Value/HashPolicy/AllocPolicy members +// called by HashMap must not call back into the same HashMap object. +// - Due to the lack of exception handling, the user must call |init()|. +template , + class AllocPolicy = TempAllocPolicy> +class HashMap +{ + typedef HashMapEntry TableEntry; + + struct MapHashPolicy : HashPolicy + { + typedef Key KeyType; + static const Key &getKey(TableEntry &e) { return e.key(); } + static void setKey(TableEntry &e, Key &k) { HashPolicy::rekey(e.mutableKey(), k); } + }; + + typedef detail::HashTable Impl; + Impl impl; + + public: + typedef typename HashPolicy::Lookup Lookup; + typedef TableEntry Entry; + + // HashMap construction is fallible (due to OOM); thus the user must call + // init after constructing a HashMap and check the return value. + explicit HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} + bool init(uint32_t len = 16) { return impl.init(len); } + bool initialized() const { return impl.initialized(); } + + // Return whether the given lookup value is present in the map. E.g.: + // + // typedef HashMap HM; + // HM h; + // if (HM::Ptr p = h.lookup(3)) { + // const HM::Entry &e = *p; // p acts like a pointer to Entry + // assert(p->key == 3); // Entry contains the key + // char val = p->value; // and value + // } + // + // Also see the definition of Ptr in HashTable above (with T = Entry). + typedef typename Impl::Ptr Ptr; + Ptr lookup(const Lookup &l) const { return impl.lookup(l); } + + // Like lookup, but does not assert if two threads call lookup at the same + // time. Only use this method when none of the threads will modify the map. + Ptr readonlyThreadsafeLookup(const Lookup &l) const { return impl.readonlyThreadsafeLookup(l); } + + // Assuming |p.found()|, remove |*p|. + void remove(Ptr p) { impl.remove(p); } + + // Like |lookup(l)|, but on miss, |p = lookupForAdd(l)| allows efficient + // insertion of Key |k| (where |HashPolicy::match(k,l) == true|) using + // |add(p,k,v)|. After |add(p,k,v)|, |p| points to the new Entry. E.g.: + // + // typedef HashMap HM; + // HM h; + // HM::AddPtr p = h.lookupForAdd(3); + // if (!p) { + // if (!h.add(p, 3, 'a')) + // return false; + // } + // const HM::Entry &e = *p; // p acts like a pointer to Entry + // assert(p->key == 3); // Entry contains the key + // char val = p->value; // and value + // + // Also see the definition of AddPtr in HashTable above (with T = Entry). + // + // N.B. The caller must ensure that no mutating hash table operations + // occur between a pair of |lookupForAdd| and |add| calls. To avoid + // looking up the key a second time, the caller may use the more efficient + // relookupOrAdd method. This method reuses part of the hashing computation + // to more efficiently insert the key if it has not been added. For + // example, a mutation-handling version of the previous example: + // + // HM::AddPtr p = h.lookupForAdd(3); + // if (!p) { + // call_that_may_mutate_h(); + // if (!h.relookupOrAdd(p, 3, 'a')) + // return false; + // } + // const HM::Entry &e = *p; + // assert(p->key == 3); + // char val = p->value; + typedef typename Impl::AddPtr AddPtr; + AddPtr lookupForAdd(const Lookup &l) const { + return impl.lookupForAdd(l); + } + + template + bool add(AddPtr &p, KeyInput &&k, ValueInput &&v) { + Entry e(mozilla::Forward(k), mozilla::Forward(v)); + return impl.add(p, mozilla::Move(e)); + } + + template + bool add(AddPtr &p, KeyInput &&k) { + Entry e(mozilla::Forward(k), Value()); + return impl.add(p, mozilla::Move(e)); + } + + template + bool relookupOrAdd(AddPtr &p, KeyInput &&k, ValueInput &&v) { + Entry e(mozilla::Forward(k), mozilla::Forward(v)); + return impl.relookupOrAdd(p, e.key(), mozilla::Move(e)); + } + + // |all()| returns a Range containing |count()| elements. E.g.: + // + // typedef HashMap HM; + // HM h; + // for (HM::Range r = h.all(); !r.empty(); r.popFront()) + // char c = r.front().value(); + // + // Also see the definition of Range in HashTable above (with T = Entry). + typedef typename Impl::Range Range; + Range all() const { return impl.all(); } + + // Typedef for the enumeration class. An Enum may be used to examine and + // remove table entries: + // + // typedef HashMap HM; + // HM s; + // for (HM::Enum e(s); !e.empty(); e.popFront()) + // if (e.front().value() == 'l') + // e.removeFront(); + // + // Table resize may occur in Enum's destructor. Also see the definition of + // Enum in HashTable above (with T = Entry). + typedef typename Impl::Enum Enum; + + // Remove all entries. This does not shrink the table. For that consider + // using the finish() method. + void clear() { impl.clear(); } + + // Remove all the entries and release all internal buffers. The map must + // be initialized again before any use. + void finish() { impl.finish(); } + + // Does the table contain any entries? + bool empty() const { return impl.empty(); } + + // Number of live elements in the map. + uint32_t count() const { return impl.count(); } + + // Total number of allocation in the dynamic table. Note: resize will + // happen well before count() == capacity(). + size_t capacity() const { return impl.capacity(); } + + // Don't just call |impl.sizeOfExcludingThis()| because there's no + // guarantee that |impl| is the first field in HashMap. + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return impl.sizeOfExcludingThis(mallocSizeOf); + } + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return mallocSizeOf(this) + impl.sizeOfExcludingThis(mallocSizeOf); + } + + // If |generation()| is the same before and after a HashMap operation, + // pointers into the table remain valid. + uint32_t generation() const { return impl.generation(); } + + /************************************************** Shorthand operations */ + + bool has(const Lookup &l) const { + return impl.lookup(l) != nullptr; + } + + // Overwrite existing value with v. Return false on oom. + template + bool put(KeyInput &&k, ValueInput &&v) { + AddPtr p = lookupForAdd(k); + if (p) { + p->value() = mozilla::Forward(v); + return true; + } + return add(p, mozilla::Forward(k), mozilla::Forward(v)); + } + + // Like put, but assert that the given key is not already present. + template + bool putNew(KeyInput &&k, ValueInput &&v) { + Entry e(mozilla::Forward(k), mozilla::Forward(v)); + return impl.putNew(e.key(), mozilla::Move(e)); + } + + // Add (k,defaultValue) if |k| is not found. Return a false-y Ptr on oom. + Ptr lookupWithDefault(const Key &k, const Value &defaultValue) { + AddPtr p = lookupForAdd(k); + if (p) + return p; + (void)add(p, k, defaultValue); // p is left false-y on oom. + return p; + } + + // Remove if present. + void remove(const Lookup &l) { + if (Ptr p = lookup(l)) + remove(p); + } + + // Infallibly rekey one entry, if necessary. + // Requires template parameters Key and HashPolicy::Lookup to be the same type. + void rekeyIfMoved(const Key &old_key, const Key &new_key) { + if (old_key != new_key) + rekeyAs(old_key, new_key, new_key); + } + + // Infallibly rekey one entry, if present. + void rekeyAs(const Lookup &old_lookup, const Lookup &new_lookup, const Key &new_key) { + if (Ptr p = lookup(old_lookup)) + impl.rekeyAndMaybeRehash(p, new_lookup, new_key); + } + + // HashMap is movable + HashMap(HashMap &&rhs) : impl(mozilla::Move(rhs.impl)) {} + void operator=(HashMap &&rhs) { + MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + impl = mozilla::Move(rhs.impl); + } + + private: + // HashMap is not copyable or assignable + HashMap(const HashMap &hm) MOZ_DELETE; + HashMap &operator=(const HashMap &hm) MOZ_DELETE; + + friend class Impl::Enum; +}; + +/*****************************************************************************/ + +// A JS-friendly, STL-like container providing a hash-based set of values. In +// particular, HashSet calls constructors and destructors of all objects added +// so non-PODs may be used safely. +// +// T requirements: +// - movable, destructible, assignable +// HashPolicy requirements: +// - see Hash Policy section below +// AllocPolicy: +// - see jsalloc.h +// +// Note: +// - HashSet is not reentrant: T/HashPolicy/AllocPolicy members called by +// HashSet must not call back into the same HashSet object. +// - Due to the lack of exception handling, the user must call |init()|. +template , + class AllocPolicy = TempAllocPolicy> +class HashSet +{ + struct SetOps : HashPolicy + { + typedef T KeyType; + static const KeyType &getKey(const T &t) { return t; } + static void setKey(T &t, KeyType &k) { HashPolicy::rekey(t, k); } + }; + + typedef detail::HashTable Impl; + Impl impl; + + public: + typedef typename HashPolicy::Lookup Lookup; + typedef T Entry; + + // HashSet construction is fallible (due to OOM); thus the user must call + // init after constructing a HashSet and check the return value. + explicit HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} + bool init(uint32_t len = 16) { return impl.init(len); } + bool initialized() const { return impl.initialized(); } + + // Return whether the given lookup value is present in the map. E.g.: + // + // typedef HashSet HS; + // HS h; + // if (HS::Ptr p = h.lookup(3)) { + // assert(*p == 3); // p acts like a pointer to int + // } + // + // Also see the definition of Ptr in HashTable above. + typedef typename Impl::Ptr Ptr; + Ptr lookup(const Lookup &l) const { return impl.lookup(l); } + + // Like lookup, but does not assert if two threads call lookup at the same + // time. Only use this method when none of the threads will modify the map. + Ptr readonlyThreadsafeLookup(const Lookup &l) const { return impl.readonlyThreadsafeLookup(l); } + + // Assuming |p.found()|, remove |*p|. + void remove(Ptr p) { impl.remove(p); } + + // Like |lookup(l)|, but on miss, |p = lookupForAdd(l)| allows efficient + // insertion of T value |t| (where |HashPolicy::match(t,l) == true|) using + // |add(p,t)|. After |add(p,t)|, |p| points to the new element. E.g.: + // + // typedef HashSet HS; + // HS h; + // HS::AddPtr p = h.lookupForAdd(3); + // if (!p) { + // if (!h.add(p, 3)) + // return false; + // } + // assert(*p == 3); // p acts like a pointer to int + // + // Also see the definition of AddPtr in HashTable above. + // + // N.B. The caller must ensure that no mutating hash table operations + // occur between a pair of |lookupForAdd| and |add| calls. To avoid + // looking up the key a second time, the caller may use the more efficient + // relookupOrAdd method. This method reuses part of the hashing computation + // to more efficiently insert the key if it has not been added. For + // example, a mutation-handling version of the previous example: + // + // HS::AddPtr p = h.lookupForAdd(3); + // if (!p) { + // call_that_may_mutate_h(); + // if (!h.relookupOrAdd(p, 3, 3)) + // return false; + // } + // assert(*p == 3); + // + // Note that relookupOrAdd(p,l,t) performs Lookup using |l| and adds the + // entry |t|, where the caller ensures match(l,t). + typedef typename Impl::AddPtr AddPtr; + AddPtr lookupForAdd(const Lookup &l) const { return impl.lookupForAdd(l); } + + template + bool add(AddPtr &p, U &&u) { + return impl.add(p, mozilla::Forward(u)); + } + + template + bool relookupOrAdd(AddPtr &p, const Lookup &l, U &&u) { + return impl.relookupOrAdd(p, l, mozilla::Forward(u)); + } + + // |all()| returns a Range containing |count()| elements: + // + // typedef HashSet HS; + // HS h; + // for (HS::Range r = h.all(); !r.empty(); r.popFront()) + // int i = r.front(); + // + // Also see the definition of Range in HashTable above. + typedef typename Impl::Range Range; + Range all() const { return impl.all(); } + + // Typedef for the enumeration class. An Enum may be used to examine and + // remove table entries: + // + // typedef HashSet HS; + // HS s; + // for (HS::Enum e(s); !e.empty(); e.popFront()) + // if (e.front() == 42) + // e.removeFront(); + // + // Table resize may occur in Enum's destructor. Also see the definition of + // Enum in HashTable above. + typedef typename Impl::Enum Enum; + + // Remove all entries. This does not shrink the table. For that consider + // using the finish() method. + void clear() { impl.clear(); } + + // Remove all the entries and release all internal buffers. The set must + // be initialized again before any use. + void finish() { impl.finish(); } + + // Does the table contain any entries? + bool empty() const { return impl.empty(); } + + // Number of live elements in the map. + uint32_t count() const { return impl.count(); } + + // Total number of allocation in the dynamic table. Note: resize will + // happen well before count() == capacity(). + size_t capacity() const { return impl.capacity(); } + + // Don't just call |impl.sizeOfExcludingThis()| because there's no + // guarantee that |impl| is the first field in HashSet. + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return impl.sizeOfExcludingThis(mallocSizeOf); + } + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return mallocSizeOf(this) + impl.sizeOfExcludingThis(mallocSizeOf); + } + + // If |generation()| is the same before and after a HashSet operation, + // pointers into the table remain valid. + uint32_t generation() const { return impl.generation(); } + + /************************************************** Shorthand operations */ + + bool has(const Lookup &l) const { + return impl.lookup(l) != nullptr; + } + + // Add |u| if it is not present already. Return false on oom. + template + bool put(U &&u) { + AddPtr p = lookupForAdd(u); + return p ? true : add(p, mozilla::Forward(u)); + } + + // Like put, but assert that the given key is not already present. + template + bool putNew(U &&u) { + return impl.putNew(u, mozilla::Forward(u)); + } + + template + bool putNew(const Lookup &l, U &&u) { + return impl.putNew(l, mozilla::Forward(u)); + } + + void remove(const Lookup &l) { + if (Ptr p = lookup(l)) + remove(p); + } + + // Infallibly rekey one entry, if present. + // Requires template parameters T and HashPolicy::Lookup to be the same type. + void rekeyIfMoved(const Lookup &old_value, const T &new_value) { + if (old_value != new_value) + rekeyAs(old_value, new_value, new_value); + } + + // Infallibly rekey one entry, if present. + void rekeyAs(const Lookup &old_lookup, const Lookup &new_lookup, const T &new_value) { + if (Ptr p = lookup(old_lookup)) + impl.rekeyAndMaybeRehash(p, new_lookup, new_value); + } + + // Infallibly rekey one entry with a new key that is equivalent. + void rekeyInPlace(Ptr p, const T &new_value) + { + MOZ_ASSERT(HashPolicy::match(*p, new_value)); + impl.rekeyInPlace(p, new_value); + } + + // HashSet is movable + HashSet(HashSet &&rhs) : impl(mozilla::Move(rhs.impl)) {} + void operator=(HashSet &&rhs) { + MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + impl = mozilla::Move(rhs.impl); + } + + private: + // HashSet is not copyable or assignable + HashSet(const HashSet &hs) MOZ_DELETE; + HashSet &operator=(const HashSet &hs) MOZ_DELETE; + + friend class Impl::Enum; +}; + +/*****************************************************************************/ + +// Hash Policy +// +// A hash policy P for a hash table with key-type Key must provide: +// - a type |P::Lookup| to use to lookup table entries; +// - a static member function |P::hash| with signature +// +// static js::HashNumber hash(Lookup) +// +// to use to hash the lookup type; and +// - a static member function |P::match| with signature +// +// static bool match(Key, Lookup) +// +// to use to test equality of key and lookup values. +// +// Normally, Lookup = Key. In general, though, different values and types of +// values can be used to lookup and store. If a Lookup value |l| is != to the +// added Key value |k|, the user must ensure that |P::match(k,l)|. E.g.: +// +// js::HashSet::AddPtr p = h.lookup(l); +// if (!p) { +// assert(P::match(k, l)); // must hold +// h.add(p, k); +// } + +// Pointer hashing policy that strips the lowest zeroBits when calculating the +// hash to improve key distribution. +template +struct PointerHasher +{ + typedef Key Lookup; + static HashNumber hash(const Lookup &l) { + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); + size_t word = reinterpret_cast(l) >> zeroBits; + JS_STATIC_ASSERT(sizeof(HashNumber) == 4); +#if JS_BITS_PER_WORD == 32 + return HashNumber(word); +#else + JS_STATIC_ASSERT(sizeof word == 8); + return HashNumber((word >> 32) ^ word); +#endif + } + static bool match(const Key &k, const Lookup &l) { + MOZ_ASSERT(!JS::IsPoisonedPtr(k)); + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); + return k == l; + } + static void rekey(Key &k, const Key& newKey) { + k = newKey; + } +}; + +// Default hash policy: just use the 'lookup' value. This of course only +// works if the lookup value is integral. HashTable applies ScrambleHashCode to +// the result of the 'hash' which means that it is 'ok' if the lookup value is +// not well distributed over the HashNumber domain. +template +struct DefaultHasher +{ + typedef Key Lookup; + static HashNumber hash(const Lookup &l) { + // Hash if can implicitly cast to hash number type. + return l; + } + static bool match(const Key &k, const Lookup &l) { + // Use builtin or overloaded operator==. + return k == l; + } + static void rekey(Key &k, const Key& newKey) { + k = newKey; + } +}; + +// Specialize hashing policy for pointer types. It assumes that the type is +// at least word-aligned. For types with smaller size use PointerHasher. +template +struct DefaultHasher : PointerHasher::value> +{}; + +// For doubles, we can xor the two uint32s. +template <> +struct DefaultHasher +{ + typedef double Lookup; + static HashNumber hash(double d) { + JS_STATIC_ASSERT(sizeof(HashNumber) == 4); + uint64_t u = mozilla::BitwiseCast(d); + return HashNumber(u ^ (u >> 32)); + } + static bool match(double lhs, double rhs) { + return mozilla::BitwiseCast(lhs) == mozilla::BitwiseCast(rhs); + } +}; + +template <> +struct DefaultHasher +{ + typedef float Lookup; + static HashNumber hash(float f) { + JS_STATIC_ASSERT(sizeof(HashNumber) == 4); + return HashNumber(mozilla::BitwiseCast(f)); + } + static bool match(float lhs, float rhs) { + return mozilla::BitwiseCast(lhs) == mozilla::BitwiseCast(rhs); + } +}; + +/*****************************************************************************/ + +// Both HashMap and HashSet are implemented by a single HashTable that is even +// more heavily parameterized than the other two. This leaves HashTable gnarly +// and extremely coupled to HashMap and HashSet; thus code should not use +// HashTable directly. + +template +class HashMapEntry +{ + Key key_; + Value value_; + + template friend class detail::HashTable; + template friend class detail::HashTableEntry; + template friend class HashMap; + + Key & mutableKey() { return key_; } + + public: + template + HashMapEntry(KeyInput &&k, ValueInput &&v) + : key_(mozilla::Forward(k)), + value_(mozilla::Forward(v)) + {} + + HashMapEntry(HashMapEntry &&rhs) + : key_(mozilla::Move(rhs.key_)), + value_(mozilla::Move(rhs.value_)) + {} + + typedef Key KeyType; + typedef Value ValueType; + + const Key & key() const { return key_; } + const Value & value() const { return value_; } + Value & value() { return value_; } + + private: + HashMapEntry(const HashMapEntry &) MOZ_DELETE; + void operator=(const HashMapEntry &) MOZ_DELETE; +}; + +} // namespace js + +namespace mozilla { + +template +struct IsPod > : IsPod {}; + +template +struct IsPod > + : IntegralConstant::value && IsPod::value> +{}; + +} // namespace mozilla + +namespace js { + +namespace detail { + +template +class HashTable; + +template +class HashTableEntry +{ + template friend class HashTable; + typedef typename mozilla::RemoveConst::Type NonConstT; + + HashNumber keyHash; + mozilla::AlignedStorage2 mem; + + static const HashNumber sFreeKey = 0; + static const HashNumber sRemovedKey = 1; + static const HashNumber sCollisionBit = 1; + + static bool isLiveHash(HashNumber hash) + { + return hash > sRemovedKey; + } + + HashTableEntry(const HashTableEntry &) MOZ_DELETE; + void operator=(const HashTableEntry &) MOZ_DELETE; + ~HashTableEntry() MOZ_DELETE; + + public: + // NB: HashTableEntry is treated as a POD: no constructor or destructor calls. + + void destroyIfLive() { + if (isLive()) + mem.addr()->~T(); + } + + void destroy() { + MOZ_ASSERT(isLive()); + mem.addr()->~T(); + } + + void swap(HashTableEntry *other) { + mozilla::Swap(keyHash, other->keyHash); + mozilla::Swap(mem, other->mem); + } + + T &get() { MOZ_ASSERT(isLive()); return *mem.addr(); } + + bool isFree() const { return keyHash == sFreeKey; } + void clearLive() { MOZ_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); } + void clear() { if (isLive()) mem.addr()->~T(); keyHash = sFreeKey; } + bool isRemoved() const { return keyHash == sRemovedKey; } + void removeLive() { MOZ_ASSERT(isLive()); keyHash = sRemovedKey; mem.addr()->~T(); } + bool isLive() const { return isLiveHash(keyHash); } + void setCollision() { MOZ_ASSERT(isLive()); keyHash |= sCollisionBit; } + void setCollision(HashNumber bit) { MOZ_ASSERT(isLive()); keyHash |= bit; } + void unsetCollision() { keyHash &= ~sCollisionBit; } + bool hasCollision() const { return keyHash & sCollisionBit; } + bool matchHash(HashNumber hn) { return (keyHash & ~sCollisionBit) == hn; } + HashNumber getKeyHash() const { return keyHash & ~sCollisionBit; } + + template + void setLive(HashNumber hn, U &&u) + { + MOZ_ASSERT(!isLive()); + keyHash = hn; + new(mem.addr()) T(mozilla::Forward(u)); + MOZ_ASSERT(isLive()); + } +}; + +template +class HashTable : private AllocPolicy +{ + friend class mozilla::ReentrancyGuard; + + typedef typename mozilla::RemoveConst::Type NonConstT; + typedef typename HashPolicy::KeyType Key; + typedef typename HashPolicy::Lookup Lookup; + + public: + typedef HashTableEntry Entry; + + // A nullable pointer to a hash table element. A Ptr |p| can be tested + // either explicitly |if (p.found()) p->...| or using boolean conversion + // |if (p) p->...|. Ptr objects must not be used after any mutating hash + // table operations unless |generation()| is tested. + class Ptr + { + friend class HashTable; + typedef void (Ptr::* ConvertibleToBool)(); + void nonNull() {} + + Entry *entry_; +#ifdef DEBUG + const HashTable *table_; + uint32_t generation; +#endif + + protected: + Ptr(Entry &entry, const HashTable &tableArg) + : entry_(&entry) +#ifdef DEBUG + , table_(&tableArg) + , generation(tableArg.generation()) +#endif + {} + + public: + // Leaves Ptr uninitialized. + Ptr() { +#ifdef JS_DEBUG + entry_ = (Entry *)0xbad; +#endif + } + + bool found() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->isLive(); + } + + operator ConvertibleToBool() const { + return found() ? &Ptr::nonNull : 0; + } + + bool operator==(const Ptr &rhs) const { + MOZ_ASSERT(found() && rhs.found()); + return entry_ == rhs.entry_; + } + + bool operator!=(const Ptr &rhs) const { + MOZ_ASSERT(generation == table_->generation()); + return !(*this == rhs); + } + + T &operator*() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->get(); + } + + T *operator->() const { + MOZ_ASSERT(generation == table_->generation()); + return &entry_->get(); + } + }; + + // A Ptr that can be used to add a key after a failed lookup. + class AddPtr : public Ptr + { + friend class HashTable; + HashNumber keyHash; +#ifdef DEBUG + uint64_t mutationCount; +#endif + + AddPtr(Entry &entry, const HashTable &tableArg, HashNumber hn) + : Ptr(entry, tableArg) + , keyHash(hn) +#ifdef DEBUG + , mutationCount(tableArg.mutationCount) +#endif + {} + + public: + // Leaves AddPtr uninitialized. + AddPtr() {} + }; + + // A collection of hash table entries. The collection is enumerated by + // calling |front()| followed by |popFront()| as long as |!empty()|. As + // with Ptr/AddPtr, Range objects must not be used after any mutating hash + // table operation unless the |generation()| is tested. + class Range + { + protected: + friend class HashTable; + + Range(const HashTable &tableArg, Entry *c, Entry *e) + : cur(c) + , end(e) +#ifdef DEBUG + , table_(&tableArg) + , mutationCount(tableArg.mutationCount) + , generation(tableArg.generation()) + , validEntry(true) +#endif + { + while (cur < end && !cur->isLive()) + ++cur; + } + + Entry *cur, *end; +#ifdef DEBUG + const HashTable *table_; + uint64_t mutationCount; + uint32_t generation; + bool validEntry; +#endif + + public: + Range() + : cur(nullptr) + , end(nullptr) +#ifdef DEBUG + , table_(nullptr) + , mutationCount(0) + , generation(0) + , validEntry(false) +#endif + {} + + bool empty() const { + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); + return cur == end; + } + + T &front() const { + MOZ_ASSERT(validEntry); + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); + return cur->get(); + } + + void popFront() { + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); + while (++cur < end && !cur->isLive()) + continue; +#ifdef DEBUG + validEntry = true; +#endif + } + }; + + // A Range whose lifetime delimits a mutating enumeration of a hash table. + // Since rehashing when elements were removed during enumeration would be + // bad, it is postponed until the Enum is destructed. Since the Enum's + // destructor touches the hash table, the user must ensure that the hash + // table is still alive when the destructor runs. + class Enum : public Range + { + friend class HashTable; + + HashTable &table_; + bool rekeyed; + bool removed; + + /* Not copyable. */ + Enum(const Enum &) MOZ_DELETE; + void operator=(const Enum &) MOZ_DELETE; + + public: + template explicit + Enum(Map &map) : Range(map.all()), table_(map.impl), rekeyed(false), removed(false) {} + + // Removes the |front()| element from the table, leaving |front()| + // invalid until the next call to |popFront()|. For example: + // + // HashSet s; + // for (HashSet::Enum e(s); !e.empty(); e.popFront()) + // if (e.front() == 42) + // e.removeFront(); + void removeFront() { + table_.remove(*this->cur); + removed = true; +#ifdef DEBUG + this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif + } + + // Removes the |front()| element and re-inserts it into the table with + // a new key at the new Lookup position. |front()| is invalid after + // this operation until the next call to |popFront()|. + void rekeyFront(const Lookup &l, const Key &k) { + Ptr p(*this->cur, table_); + table_.rekeyWithoutRehash(p, l, k); + rekeyed = true; +#ifdef DEBUG + this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif + } + + void rekeyFront(const Key &k) { + rekeyFront(k, k); + } + + // Potentially rehashes the table. + ~Enum() { + if (rekeyed) { + table_.gen++; + table_.checkOverRemoved(); + } + + if (removed) + table_.compactIfUnderloaded(); + } + }; + + // HashTable is movable + HashTable(HashTable &&rhs) + : AllocPolicy(rhs) + { + mozilla::PodAssign(this, &rhs); + rhs.table = nullptr; + } + void operator=(HashTable &&rhs) { + MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + if (table) + destroyTable(*this, table, capacity()); + mozilla::PodAssign(this, &rhs); + rhs.table = nullptr; + } + + private: + // HashTable is not copyable or assignable + HashTable(const HashTable &) MOZ_DELETE; + void operator=(const HashTable &) MOZ_DELETE; + + private: + static const size_t CAP_BITS = 24; + + public: + Entry *table; // entry storage + uint32_t gen; // entry storage generation number + uint32_t entryCount; // number of entries in table + uint32_t removedCount:CAP_BITS; // removed entry sentinels in table + uint32_t hashShift:8; // multiplicative hash shift + +#ifdef JS_DEBUG + mozilla::DebugOnly mutationCount; + mutable mozilla::DebugOnly mEntered; + mutable struct Stats + { + uint32_t searches; // total number of table searches + uint32_t steps; // hash chain links traversed + uint32_t hits; // searches that found key + uint32_t misses; // searches that didn't find key + uint32_t addOverRemoved; // adds that recycled a removed entry + uint32_t removes; // calls to remove + uint32_t removeFrees; // calls to remove that freed the entry + uint32_t grows; // table expansions + uint32_t shrinks; // table contractions + uint32_t compresses; // table compressions + uint32_t rehashes; // tombstone decontaminations + } stats; +# define METER(x) x +#else +# define METER(x) +#endif + + // The default initial capacity is 32 (enough to hold 16 elements), but it + // can be as low as 4. + static const unsigned sMinCapacityLog2 = 2; + static const unsigned sMinCapacity = 1 << sMinCapacityLog2; + static const unsigned sMaxInit = JS_BIT(CAP_BITS - 1); + static const unsigned sMaxCapacity = JS_BIT(CAP_BITS); + static const unsigned sHashBits = mozilla::tl::BitSize::value; + + // Hash-table alpha is conceptually a fraction, but to avoid floating-point + // math we implement it as a ratio of integers. + static const uint8_t sAlphaDenominator = 4; + static const uint8_t sMinAlphaNumerator = 1; // min alpha: 1/4 + static const uint8_t sMaxAlphaNumerator = 3; // max alpha: 3/4 + + static const HashNumber sFreeKey = Entry::sFreeKey; + static const HashNumber sRemovedKey = Entry::sRemovedKey; + static const HashNumber sCollisionBit = Entry::sCollisionBit; + + void setTableSizeLog2(unsigned sizeLog2) + { + hashShift = sHashBits - sizeLog2; + } + + static bool isLiveHash(HashNumber hash) + { + return Entry::isLiveHash(hash); + } + + static HashNumber prepareHash(const Lookup& l) + { + HashNumber keyHash = ScrambleHashCode(HashPolicy::hash(l)); + + // Avoid reserved hash codes. + if (!isLiveHash(keyHash)) + keyHash -= (sRemovedKey + 1); + return keyHash & ~sCollisionBit; + } + + static Entry *createTable(AllocPolicy &alloc, uint32_t capacity) + { + static_assert(sFreeKey == 0, + "newly-calloc'd tables have to be considered empty"); + static_assert(sMaxCapacity <= SIZE_MAX / sizeof(Entry), + "would overflow allocating max number of entries"); + return static_cast(alloc.calloc_(capacity * sizeof(Entry))); + } + + static void destroyTable(AllocPolicy &alloc, Entry *oldTable, uint32_t capacity) + { + for (Entry *e = oldTable, *end = e + capacity; e < end; ++e) + e->destroyIfLive(); + alloc.free_(oldTable); + } + + public: + explicit HashTable(AllocPolicy ap) + : AllocPolicy(ap) + , table(nullptr) + , gen(0) + , entryCount(0) + , removedCount(0) + , hashShift(sHashBits) +#ifdef DEBUG + , mutationCount(0) + , mEntered(false) +#endif + {} + + MOZ_WARN_UNUSED_RESULT bool init(uint32_t length) + { + MOZ_ASSERT(!initialized()); + + // Reject all lengths whose initial computed capacity would exceed + // sMaxCapacity. Round that maximum length down to the nearest power + // of two for speedier code. + if (length > sMaxInit) { + this->reportAllocOverflow(); + return false; + } + + static_assert((sMaxInit * sAlphaDenominator) / sAlphaDenominator == sMaxInit, + "multiplication in numerator below could overflow"); + static_assert(sMaxInit * sAlphaDenominator <= UINT32_MAX - sMaxAlphaNumerator, + "numerator calculation below could potentially overflow"); + + // Compute the smallest capacity allowing |length| elements to be + // inserted without rehashing: ceil(length / max-alpha). (Ceiling + // integral division: .) + uint32_t newCapacity = + (length * sAlphaDenominator + sMaxAlphaNumerator - 1) / sMaxAlphaNumerator; + if (newCapacity < sMinCapacity) + newCapacity = sMinCapacity; + + // FIXME: use JS_CEILING_LOG2 when PGO stops crashing (bug 543034). + uint32_t roundUp = sMinCapacity, roundUpLog2 = sMinCapacityLog2; + while (roundUp < newCapacity) { + roundUp <<= 1; + ++roundUpLog2; + } + + newCapacity = roundUp; + MOZ_ASSERT(newCapacity >= length); + MOZ_ASSERT(newCapacity <= sMaxCapacity); + + table = createTable(*this, newCapacity); + if (!table) + return false; + + setTableSizeLog2(roundUpLog2); + METER(memset(&stats, 0, sizeof(stats))); + return true; + } + + bool initialized() const + { + return !!table; + } + + ~HashTable() + { + if (table) + destroyTable(*this, table, capacity()); + } + + private: + HashNumber hash1(HashNumber hash0) const + { + return hash0 >> hashShift; + } + + struct DoubleHash + { + HashNumber h2; + HashNumber sizeMask; + }; + + DoubleHash hash2(HashNumber curKeyHash) const + { + unsigned sizeLog2 = sHashBits - hashShift; + DoubleHash dh = { + ((curKeyHash << sizeLog2) >> hashShift) | 1, + (HashNumber(1) << sizeLog2) - 1 + }; + return dh; + } + + static HashNumber applyDoubleHash(HashNumber h1, const DoubleHash &dh) + { + return (h1 - dh.h2) & dh.sizeMask; + } + + bool overloaded() + { + static_assert(sMaxCapacity <= UINT32_MAX / sMaxAlphaNumerator, + "multiplication below could overflow"); + return entryCount + removedCount >= + capacity() * sMaxAlphaNumerator / sAlphaDenominator; + } + + // Would the table be underloaded if it had the given capacity and entryCount? + static bool wouldBeUnderloaded(uint32_t capacity, uint32_t entryCount) + { + static_assert(sMaxCapacity <= UINT32_MAX / sMinAlphaNumerator, + "multiplication below could overflow"); + return capacity > sMinCapacity && + entryCount <= capacity * sMinAlphaNumerator / sAlphaDenominator; + } + + bool underloaded() + { + return wouldBeUnderloaded(capacity(), entryCount); + } + + static bool match(Entry &e, const Lookup &l) + { + return HashPolicy::match(HashPolicy::getKey(e.get()), l); + } + + Entry &lookup(const Lookup &l, HashNumber keyHash, unsigned collisionBit) const + { + MOZ_ASSERT(isLiveHash(keyHash)); + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(collisionBit == 0 || collisionBit == sCollisionBit); + MOZ_ASSERT(table); + METER(stats.searches++); + + // Compute the primary hash address. + HashNumber h1 = hash1(keyHash); + Entry *entry = &table[h1]; + + // Miss: return space for a new entry. + if (entry->isFree()) { + METER(stats.misses++); + return *entry; + } + + // Hit: return entry. + if (entry->matchHash(keyHash) && match(*entry, l)) { + METER(stats.hits++); + return *entry; + } + + // Collision: double hash. + DoubleHash dh = hash2(keyHash); + + // Save the first removed entry pointer so we can recycle later. + Entry *firstRemoved = nullptr; + + while(true) { + if (MOZ_UNLIKELY(entry->isRemoved())) { + if (!firstRemoved) + firstRemoved = entry; + } else { + entry->setCollision(collisionBit); + } + + METER(stats.steps++); + h1 = applyDoubleHash(h1, dh); + + entry = &table[h1]; + if (entry->isFree()) { + METER(stats.misses++); + return firstRemoved ? *firstRemoved : *entry; + } + + if (entry->matchHash(keyHash) && match(*entry, l)) { + METER(stats.hits++); + return *entry; + } + } + } + + // This is a copy of lookup hardcoded to the assumptions: + // 1. the lookup is a lookupForAdd + // 2. the key, whose |keyHash| has been passed is not in the table, + // 3. no entries have been removed from the table. + // This specialized search avoids the need for recovering lookup values + // from entries, which allows more flexible Lookup/Key types. + Entry &findFreeEntry(HashNumber keyHash) + { + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(table); + METER(stats.searches++); + + // We assume 'keyHash' has already been distributed. + + // Compute the primary hash address. + HashNumber h1 = hash1(keyHash); + Entry *entry = &table[h1]; + + // Miss: return space for a new entry. + if (!entry->isLive()) { + METER(stats.misses++); + return *entry; + } + + // Collision: double hash. + DoubleHash dh = hash2(keyHash); + + while(true) { + MOZ_ASSERT(!entry->isRemoved()); + entry->setCollision(); + + METER(stats.steps++); + h1 = applyDoubleHash(h1, dh); + + entry = &table[h1]; + if (!entry->isLive()) { + METER(stats.misses++); + return *entry; + } + } + } + + enum RebuildStatus { NotOverloaded, Rehashed, RehashFailed }; + + RebuildStatus changeTableSize(int deltaLog2) + { + // Look, but don't touch, until we succeed in getting new entry store. + Entry *oldTable = table; + uint32_t oldCap = capacity(); + uint32_t newLog2 = sHashBits - hashShift + deltaLog2; + uint32_t newCapacity = JS_BIT(newLog2); + if (newCapacity > sMaxCapacity) { + this->reportAllocOverflow(); + return RehashFailed; + } + + Entry *newTable = createTable(*this, newCapacity); + if (!newTable) + return RehashFailed; + + // We can't fail from here on, so update table parameters. + setTableSizeLog2(newLog2); + removedCount = 0; + gen++; + table = newTable; + + // Copy only live entries, leaving removed ones behind. + for (Entry *src = oldTable, *end = src + oldCap; src < end; ++src) { + if (src->isLive()) { + HashNumber hn = src->getKeyHash(); + findFreeEntry(hn).setLive(hn, mozilla::Move(src->get())); + src->destroy(); + } + } + + // All entries have been destroyed, no need to destroyTable. + this->free_(oldTable); + return Rehashed; + } + + RebuildStatus checkOverloaded() + { + if (!overloaded()) + return NotOverloaded; + + // Compress if a quarter or more of all entries are removed. + int deltaLog2; + if (removedCount >= (capacity() >> 2)) { + METER(stats.compresses++); + deltaLog2 = 0; + } else { + METER(stats.grows++); + deltaLog2 = 1; + } + + return changeTableSize(deltaLog2); + } + + // Infallibly rehash the table if we are overloaded with removals. + void checkOverRemoved() + { + if (overloaded()) { + if (checkOverloaded() == RehashFailed) + rehashTableInPlace(); + } + } + + void remove(Entry &e) + { + MOZ_ASSERT(table); + METER(stats.removes++); + + if (e.hasCollision()) { + e.removeLive(); + removedCount++; + } else { + METER(stats.removeFrees++); + e.clearLive(); + } + entryCount--; +#ifdef DEBUG + mutationCount++; +#endif + } + + void checkUnderloaded() + { + if (underloaded()) { + METER(stats.shrinks++); + (void) changeTableSize(-1); + } + } + + // Resize the table down to the largest capacity which doesn't underload the + // table. Since we call checkUnderloaded() on every remove, you only need + // to call this after a bulk removal of items done without calling remove(). + void compactIfUnderloaded() + { + int32_t resizeLog2 = 0; + uint32_t newCapacity = capacity(); + while (wouldBeUnderloaded(newCapacity, entryCount)) { + newCapacity = newCapacity >> 1; + resizeLog2--; + } + + if (resizeLog2 != 0) { + changeTableSize(resizeLog2); + } + } + + // This is identical to changeTableSize(currentSize), but without requiring + // a second table. We do this by recycling the collision bits to tell us if + // the element is already inserted or still waiting to be inserted. Since + // already-inserted elements win any conflicts, we get the same table as we + // would have gotten through random insertion order. + void rehashTableInPlace() + { + METER(stats.rehashes++); + removedCount = 0; + for (size_t i = 0; i < capacity(); ++i) + table[i].unsetCollision(); + + for (size_t i = 0; i < capacity();) { + Entry *src = &table[i]; + + if (!src->isLive() || src->hasCollision()) { + ++i; + continue; + } + + HashNumber keyHash = src->getKeyHash(); + HashNumber h1 = hash1(keyHash); + DoubleHash dh = hash2(keyHash); + Entry *tgt = &table[h1]; + while (true) { + if (!tgt->hasCollision()) { + src->swap(tgt); + tgt->setCollision(); + break; + } + + h1 = applyDoubleHash(h1, dh); + tgt = &table[h1]; + } + } + + // TODO: this algorithm leaves collision bits on *all* elements, even if + // they are on no collision path. We have the option of setting the + // collision bits correctly on a subsequent pass or skipping the rehash + // unless we are totally filled with tombstones: benchmark to find out + // which approach is best. + } + + public: + void clear() + { + if (mozilla::IsPod::value) { + memset(table, 0, sizeof(*table) * capacity()); + } else { + uint32_t tableCapacity = capacity(); + for (Entry *e = table, *end = table + tableCapacity; e < end; ++e) + e->clear(); + } + removedCount = 0; + entryCount = 0; +#ifdef DEBUG + mutationCount++; +#endif + } + + void finish() + { + MOZ_ASSERT(!mEntered); + + if (!table) + return; + + destroyTable(*this, table, capacity()); + table = nullptr; + gen++; + entryCount = 0; + removedCount = 0; +#ifdef DEBUG + mutationCount++; +#endif + } + + Range all() const + { + MOZ_ASSERT(table); + return Range(*this, table, table + capacity()); + } + + bool empty() const + { + MOZ_ASSERT(table); + return !entryCount; + } + + uint32_t count() const + { + MOZ_ASSERT(table); + return entryCount; + } + + uint32_t capacity() const + { + MOZ_ASSERT(table); + return JS_BIT(sHashBits - hashShift); + } + + uint32_t generation() const + { + MOZ_ASSERT(table); + return gen; + } + + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const + { + return mallocSizeOf(table); + } + + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const + { + return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + } + + Ptr lookup(const Lookup &l) const + { + mozilla::ReentrancyGuard g(*this); + HashNumber keyHash = prepareHash(l); + return Ptr(lookup(l, keyHash, 0), *this); + } + + Ptr readonlyThreadsafeLookup(const Lookup &l) const + { + HashNumber keyHash = prepareHash(l); + return Ptr(lookup(l, keyHash, 0), *this); + } + + AddPtr lookupForAdd(const Lookup &l) const + { + mozilla::ReentrancyGuard g(*this); + HashNumber keyHash = prepareHash(l); + Entry &entry = lookup(l, keyHash, sCollisionBit); + AddPtr p(entry, *this, keyHash); + return p; + } + + template + bool add(AddPtr &p, U &&u) + { + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(table); + MOZ_ASSERT(!p.found()); + MOZ_ASSERT(!(p.keyHash & sCollisionBit)); + + // Changing an entry from removed to live does not affect whether we + // are overloaded and can be handled separately. + if (p.entry_->isRemoved()) { + METER(stats.addOverRemoved++); + removedCount--; + p.keyHash |= sCollisionBit; + } else { + // Preserve the validity of |p.entry_|. + RebuildStatus status = checkOverloaded(); + if (status == RehashFailed) + return false; + if (status == Rehashed) + p.entry_ = &findFreeEntry(p.keyHash); + } + + p.entry_->setLive(p.keyHash, mozilla::Forward(u)); + entryCount++; +#ifdef DEBUG + mutationCount++; + p.generation = generation(); + p.mutationCount = mutationCount; +#endif + return true; + } + + // Note: |l| may be a reference to a piece of |u|, so this function + // must take care not to use |l| after moving |u|. + template + void putNewInfallible(const Lookup &l, U &&u) + { + MOZ_ASSERT(table); + + HashNumber keyHash = prepareHash(l); + Entry *entry = &findFreeEntry(keyHash); + + if (entry->isRemoved()) { + METER(stats.addOverRemoved++); + removedCount--; + keyHash |= sCollisionBit; + } + + entry->setLive(keyHash, mozilla::Forward(u)); + entryCount++; +#ifdef DEBUG + mutationCount++; +#endif + } + + // Note: |l| may be a reference to a piece of |u|, so this function + // must take care not to use |l| after moving |u|. + template + bool putNew(const Lookup &l, U &&u) + { + if (checkOverloaded() == RehashFailed) + return false; + + putNewInfallible(l, mozilla::Forward(u)); + return true; + } + + // Note: |l| may be a reference to a piece of |u|, so this function + // must take care not to use |l| after moving |u|. + template + bool relookupOrAdd(AddPtr& p, const Lookup &l, U &&u) + { +#ifdef DEBUG + p.generation = generation(); + p.mutationCount = mutationCount; +#endif + { + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(prepareHash(l) == p.keyHash); // l has not been destroyed + p.entry_ = &lookup(l, p.keyHash, sCollisionBit); + } + return p.found() || add(p, mozilla::Forward(u)); + } + + void remove(Ptr p) + { + MOZ_ASSERT(table); + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(p.found()); + remove(*p.entry_); + checkUnderloaded(); + } + + void rekeyWithoutRehash(Ptr p, const Lookup &l, const Key &k) + { + MOZ_ASSERT(table); + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(p.found()); + typename HashTableEntry::NonConstT t(mozilla::Move(*p)); + HashPolicy::setKey(t, const_cast(k)); + remove(*p.entry_); + putNewInfallible(l, mozilla::Move(t)); + } + + void rekeyAndMaybeRehash(Ptr p, const Lookup &l, const Key &k) + { + rekeyWithoutRehash(p, l, k); + checkOverRemoved(); + } + + void rekeyInPlace(Ptr p, const Key &k) + { + MOZ_ASSERT(table); + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(p.found()); + HashPolicy::rekey(const_cast(*p), const_cast(k)); + } + +#undef METER +}; + +} // namespace detail +} // namespace js + +#endif /* js_HashTable_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/HeapAPI.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/HeapAPI.h new file mode 100644 index 0000000000..bdd63c1937 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/HeapAPI.h @@ -0,0 +1,317 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_HeapAPI_h +#define js_HeapAPI_h + +#include + +#include "jspubtd.h" + +#include "js/Utility.h" + +/* These values are private to the JS engine. */ +namespace js { + +// Whether the current thread is permitted access to any part of the specified +// runtime or zone. +JS_FRIEND_API(bool) +CurrentThreadCanAccessRuntime(JSRuntime *rt); + +JS_FRIEND_API(bool) +CurrentThreadCanAccessZone(JS::Zone *zone); + +namespace gc { + +struct Cell; + +const size_t ArenaShift = 12; +const size_t ArenaSize = size_t(1) << ArenaShift; +const size_t ArenaMask = ArenaSize - 1; + +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkShift = 18; +#else +const size_t ChunkShift = 20; +#endif +const size_t ChunkSize = size_t(1) << ChunkShift; +const size_t ChunkMask = ChunkSize - 1; + +const size_t CellShift = 3; +const size_t CellSize = size_t(1) << CellShift; +const size_t CellMask = CellSize - 1; + +/* These are magic constants derived from actual offsets in gc/Heap.h. */ +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkMarkBitmapOffset = 258104; +const size_t ChunkMarkBitmapBits = 31744; +#else +const size_t ChunkMarkBitmapOffset = 1032352; +const size_t ChunkMarkBitmapBits = 129024; +#endif +const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*); +const size_t ChunkLocationOffset = ChunkSize - 2 * sizeof(void*) - sizeof(uint64_t); + +/* + * Live objects are marked black. How many other additional colors are available + * depends on the size of the GCThing. Objects marked gray are eligible for + * cycle collection. + */ +static const uint32_t BLACK = 0; +static const uint32_t GRAY = 1; + +/* + * The "location" field in the Chunk trailer is a bit vector indicting various + * roles of the chunk. + * + * The value 0 for the "location" field is invalid, at least one bit must be + * set. + * + * Some bits preclude others, for example, any "nursery" bit precludes any + * "tenured" or "middle generation" bit. + */ +const uintptr_t ChunkLocationBitNursery = 1; // Standard GGC nursery +const uintptr_t ChunkLocationBitTenuredHeap = 2; // Standard GGC tenured generation +const uintptr_t ChunkLocationBitPJSNewspace = 4; // The PJS generational GC's allocation space +const uintptr_t ChunkLocationBitPJSFromspace = 8; // The PJS generational GC's fromspace (during GC) + +const uintptr_t ChunkLocationAnyNursery = ChunkLocationBitNursery | + ChunkLocationBitPJSNewspace | + ChunkLocationBitPJSFromspace; + +#ifdef JS_DEBUG +/* When downcasting, ensure we are actually the right type. */ +extern JS_FRIEND_API(void) +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind); +#else +inline void +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind) {} +#endif + +} /* namespace gc */ +} /* namespace js */ + +namespace JS { +struct Zone; + +/* Default size for the generational nursery in bytes. */ +const uint32_t DefaultNurseryBytes = 16 * 1024 * 1024; + +/* Default maximum heap size in bytes to pass to JS_NewRuntime(). */ +const uint32_t DefaultHeapMaxBytes = 32 * 1024 * 1024; + +/* + * We cannot expose the class hierarchy: the implementation is hidden. Instead + * we provide cast functions with strong debug-mode assertions. + */ +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSObject *obj) +{ + js::gc::Cell *cell = reinterpret_cast(obj); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFunction *fun) +{ + js::gc::Cell *cell = reinterpret_cast(fun); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSString *str) +{ + js::gc::Cell *cell = reinterpret_cast(str); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFlatString *flat) +{ + js::gc::Cell *cell = reinterpret_cast(flat); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JS::Symbol *sym) +{ + js::gc::Cell *cell = reinterpret_cast(sym); + AssertGCThingHasType(cell, JSTRACE_SYMBOL); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSScript *script) +{ + js::gc::Cell *cell = reinterpret_cast(script); + AssertGCThingHasType(cell, JSTRACE_SCRIPT); + return cell; +} + +namespace shadow { + +struct ArenaHeader +{ + JS::Zone *zone; +}; + +struct Zone +{ + protected: + JSRuntime *const runtime_; + JSTracer *const barrierTracer_; // A pointer to the JSRuntime's |gcMarker|. + + public: + bool needsBarrier_; + + Zone(JSRuntime *runtime, JSTracer *barrierTracerArg) + : runtime_(runtime), + barrierTracer_(barrierTracerArg), + needsBarrier_(false) + {} + + bool needsBarrier() const { + return needsBarrier_; + } + + JSTracer *barrierTracer() { + MOZ_ASSERT(needsBarrier_); + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + return barrierTracer_; + } + + JSRuntime *runtimeFromMainThread() const { + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + return runtime_; + } + + // Note: Unrestricted access to the zone's runtime from an arbitrary + // thread can easily lead to races. Use this method very carefully. + JSRuntime *runtimeFromAnyThread() const { + return runtime_; + } + + static JS::shadow::Zone *asShadowZone(JS::Zone *zone) { + return reinterpret_cast(zone); + } +}; + +} /* namespace shadow */ +} /* namespace JS */ + +namespace js { +namespace gc { + +static MOZ_ALWAYS_INLINE uintptr_t * +GetGCThingMarkBitmap(const void *thing) +{ + MOZ_ASSERT(thing); + uintptr_t addr = uintptr_t(thing); + addr &= ~js::gc::ChunkMask; + addr |= js::gc::ChunkMarkBitmapOffset; + return reinterpret_cast(addr); +} + +static MOZ_ALWAYS_INLINE JS::shadow::Runtime * +GetGCThingRuntime(const void *thing) +{ + MOZ_ASSERT(thing); + uintptr_t addr = uintptr_t(thing); + addr &= ~js::gc::ChunkMask; + addr |= js::gc::ChunkRuntimeOffset; + return *reinterpret_cast(addr); +} + +static MOZ_ALWAYS_INLINE void +GetGCThingMarkWordAndMask(const void *thing, uint32_t color, + uintptr_t **wordp, uintptr_t *maskp) +{ + uintptr_t addr = uintptr_t(thing); + size_t bit = (addr & js::gc::ChunkMask) / js::gc::CellSize + color; + MOZ_ASSERT(bit < js::gc::ChunkMarkBitmapBits); + uintptr_t *bitmap = GetGCThingMarkBitmap(thing); + const uintptr_t nbits = sizeof(*bitmap) * CHAR_BIT; + *maskp = uintptr_t(1) << (bit % nbits); + *wordp = &bitmap[bit / nbits]; +} + +static MOZ_ALWAYS_INLINE JS::shadow::ArenaHeader * +GetGCThingArena(void *thing) +{ + uintptr_t addr = uintptr_t(thing); + addr &= ~js::gc::ArenaMask; + return reinterpret_cast(addr); +} + +MOZ_ALWAYS_INLINE bool +IsInsideNursery(const js::gc::Cell *cell) +{ +#ifdef JSGC_GENERATIONAL + if (!cell) + return false; + uintptr_t addr = uintptr_t(cell); + addr &= ~js::gc::ChunkMask; + addr |= js::gc::ChunkLocationOffset; + uint32_t location = *reinterpret_cast(addr); + JS_ASSERT(location != 0); + return location & ChunkLocationAnyNursery; +#else + return false; +#endif +} + +} /* namespace gc */ + +} /* namespace js */ + +namespace JS { + +static MOZ_ALWAYS_INLINE Zone * +GetGCThingZone(void *thing) +{ + MOZ_ASSERT(thing); + return js::gc::GetGCThingArena(thing)->zone; +} + +static MOZ_ALWAYS_INLINE Zone * +GetObjectZone(JSObject *obj) +{ + return GetGCThingZone(obj); +} + +static MOZ_ALWAYS_INLINE bool +GCThingIsMarkedGray(void *thing) +{ +#ifdef JSGC_GENERATIONAL + /* + * GC things residing in the nursery cannot be gray: they have no mark bits. + * All live objects in the nursery are moved to tenured at the beginning of + * each GC slice, so the gray marker never sees nursery things. + */ + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) + return false; +#endif + uintptr_t *word, mask; + js::gc::GetGCThingMarkWordAndMask(thing, js::gc::GRAY, &word, &mask); + return *word & mask; +} + +static MOZ_ALWAYS_INLINE bool +IsIncrementalBarrierNeededOnGCThing(shadow::Runtime *rt, void *thing, JSGCTraceKind kind) +{ + if (!rt->needsBarrier_) + return false; + JS::Zone *zone = GetGCThingZone(thing); + return reinterpret_cast(zone)->needsBarrier_; +} + +} /* namespace JS */ + +#endif /* js_HeapAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Id.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Id.h new file mode 100644 index 0000000000..11116f2efe --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Id.h @@ -0,0 +1,185 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_Id_h +#define js_Id_h + +// A jsid is an identifier for a property or method of an object which is +// either a 31-bit signed integer, interned string or object. +// +// Also, there is an additional jsid value, JSID_VOID, which does not occur in +// JS scripts but may be used to indicate the absence of a valid jsid. A void +// jsid is not a valid id and only arises as an exceptional API return value, +// such as in JS_NextProperty. Embeddings must not pass JSID_VOID into JSAPI +// entry points expecting a jsid and do not need to handle JSID_VOID in hooks +// receiving a jsid except when explicitly noted in the API contract. +// +// A jsid is not implicitly convertible to or from a jsval; JS_ValueToId or +// JS_IdToValue must be used instead. + +#include "mozilla/NullPtr.h" + +#include "jstypes.h" + +#include "js/HeapAPI.h" +#include "js/RootingAPI.h" +#include "js/TypeDecls.h" +#include "js/Utility.h" + +struct jsid +{ + size_t asBits; + bool operator==(jsid rhs) const { return asBits == rhs.asBits; } + bool operator!=(jsid rhs) const { return asBits != rhs.asBits; } +}; +#define JSID_BITS(id) (id.asBits) + +#define JSID_TYPE_STRING 0x0 +#define JSID_TYPE_INT 0x1 +#define JSID_TYPE_VOID 0x2 +#define JSID_TYPE_SYMBOL 0x4 +#define JSID_TYPE_MASK 0x7 + +// Avoid using canonical 'id' for jsid parameters since this is a magic word in +// Objective-C++ which, apparently, wants to be able to #include jsapi.h. +#define id iden + +static MOZ_ALWAYS_INLINE bool +JSID_IS_STRING(jsid id) +{ + return (JSID_BITS(id) & JSID_TYPE_MASK) == 0; +} + +static MOZ_ALWAYS_INLINE JSString * +JSID_TO_STRING(jsid id) +{ + MOZ_ASSERT(JSID_IS_STRING(id)); + return (JSString *)JSID_BITS(id); +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_ZERO(jsid id) +{ + return JSID_BITS(id) == 0; +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_INT(jsid id) +{ + return !!(JSID_BITS(id) & JSID_TYPE_INT); +} + +static MOZ_ALWAYS_INLINE int32_t +JSID_TO_INT(jsid id) +{ + MOZ_ASSERT(JSID_IS_INT(id)); + return ((uint32_t)JSID_BITS(id)) >> 1; +} + +#define JSID_INT_MIN 0 +#define JSID_INT_MAX INT32_MAX + +static MOZ_ALWAYS_INLINE bool +INT_FITS_IN_JSID(int32_t i) +{ + return i >= 0; +} + +static MOZ_ALWAYS_INLINE jsid +INT_TO_JSID(int32_t i) +{ + jsid id; + MOZ_ASSERT(INT_FITS_IN_JSID(i)); + JSID_BITS(id) = ((i << 1) | JSID_TYPE_INT); + return id; +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_SYMBOL(jsid id) +{ + return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_SYMBOL && + JSID_BITS(id) != JSID_TYPE_SYMBOL; +} + +static MOZ_ALWAYS_INLINE JS::Symbol * +JSID_TO_SYMBOL(jsid id) +{ + MOZ_ASSERT(JSID_IS_SYMBOL(id)); + return (JS::Symbol *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); +} + +static MOZ_ALWAYS_INLINE jsid +SYMBOL_TO_JSID(JS::Symbol *sym) +{ + jsid id; + MOZ_ASSERT(sym != nullptr); + MOZ_ASSERT((size_t(sym) & JSID_TYPE_MASK) == 0); + JS_ASSERT(!js::gc::IsInsideNursery(JS::AsCell(sym))); + JS_ASSERT(!JS::IsPoisonedPtr(sym)); + JSID_BITS(id) = (size_t(sym) | JSID_TYPE_SYMBOL); + return id; +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_GCTHING(jsid id) +{ + return JSID_IS_STRING(id) || JSID_IS_SYMBOL(id); +} + +static MOZ_ALWAYS_INLINE void * +JSID_TO_GCTHING(jsid id) +{ + return (void *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_VOID(const jsid id) +{ + MOZ_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID, + JSID_BITS(id) == JSID_TYPE_VOID); + return ((size_t)JSID_BITS(id) == JSID_TYPE_VOID); +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_EMPTY(const jsid id) +{ + return ((size_t)JSID_BITS(id) == JSID_TYPE_SYMBOL); +} + +extern JS_PUBLIC_DATA(const jsid) JSID_VOID; +extern JS_PUBLIC_DATA(const jsid) JSID_EMPTY; + +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_VOIDHANDLE; +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_EMPTYHANDLE; + +namespace js { + +inline bool +IsPoisonedId(jsid id) +{ + if (JSID_IS_STRING(id)) + return JS::IsPoisonedPtr(JSID_TO_STRING(id)); + if (JSID_IS_SYMBOL(id)) + return JS::IsPoisonedPtr(JSID_TO_SYMBOL(id)); + return false; +} + +template <> struct GCMethods +{ + static jsid initial() { return JSID_VOID; } + static bool poisoned(jsid id) { return IsPoisonedId(id); } + static bool needsPostBarrier(jsid id) { return false; } +#ifdef JSGC_GENERATIONAL + static void postBarrier(jsid *idp) {} + static void relocate(jsid *idp) {} +#endif +}; + +#undef id + +} + +#endif /* js_Id_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/LegacyIntTypes.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/LegacyIntTypes.h new file mode 100644 index 0000000000..2c8498c89e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/LegacyIntTypes.h @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * This section typedefs the old 'native' types to the new types. + * These redefinitions are provided solely to allow JSAPI users to more easily + * transition to types. They are not to be used in the JSAPI, and + * new JSAPI user code should not use them. This mapping file may eventually + * be removed from SpiderMonkey, so don't depend on it in the long run. + */ + +/* + * BEWARE: Comity with other implementers of these types is not guaranteed. + * Indeed, if you use this header and third-party code defining these + * types, *expect* to encounter either compile errors or link errors, + * depending how these types are used and on the order of inclusion. + * It is safest to use only the types. + */ +#ifndef js_LegacyIntTypes_h +#define js_LegacyIntTypes_h + +#include + +#include "js-config.h" + +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; +typedef uint64_t uint64; + +/* + * On AIX 4.3, sys/inttypes.h (which is included by sys/types.h, a very + * common header file) defines the types int8, int16, int32, and int64. + * So we don't define these four types here to avoid conflicts in case + * the code also includes sys/types.h. + */ +#if defined(AIX) && defined(HAVE_SYS_INTTYPES_H) +#include +#else +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; +typedef int64_t int64; +#endif /* AIX && HAVE_SYS_INTTYPES_H */ + +typedef uint8_t JSUint8; +typedef uint16_t JSUint16; +typedef uint32_t JSUint32; +typedef uint64_t JSUint64; + +typedef int8_t JSInt8; +typedef int16_t JSInt16; +typedef int32_t JSInt32; +typedef int64_t JSInt64; + +#endif /* js_LegacyIntTypes_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/MemoryMetrics.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/MemoryMetrics.h new file mode 100644 index 0000000000..31e456baba --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/MemoryMetrics.h @@ -0,0 +1,668 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_MemoryMetrics_h +#define js_MemoryMetrics_h + +// These declarations are highly likely to change in the future. Depend on them +// at your own risk. + +#include "mozilla/MemoryReporting.h" +#include "mozilla/NullPtr.h" +#include "mozilla/PodOperations.h" + +#include + +#include "jsalloc.h" +#include "jspubtd.h" + +#include "js/HashTable.h" +#include "js/Utility.h" +#include "js/Vector.h" + +class nsISupports; // Needed for ObjectPrivateVisitor. + +namespace JS { + +struct TabSizes +{ + enum Kind { + Objects, + Strings, + Private, + Other + }; + + TabSizes() { mozilla::PodZero(this); } + + void add(Kind kind, size_t n) { + switch (kind) { + case Objects: objects += n; break; + case Strings: strings += n; break; + case Private: private_ += n; break; + case Other: other += n; break; + default: MOZ_CRASH("bad TabSizes kind"); + } + } + + size_t objects; + size_t strings; + size_t private_; + size_t other; +}; + +} // namespace JS + +namespace js { + +// In memory reporting, we have concept of "sundries", line items which are too +// small to be worth reporting individually. Under some circumstances, a memory +// reporter gets tossed into the sundries bucket if it's smaller than +// MemoryReportingSundriesThreshold() bytes. +// +// We need to define this value here, rather than in the code which actually +// generates the memory reports, because NotableStringInfo uses this value. +JS_FRIEND_API(size_t) MemoryReportingSundriesThreshold(); + +// This hash policy avoids flattening ropes (which perturbs the site being +// measured and requires a JSContext) at the expense of doing a FULL ROPE COPY +// on every hash and match! Beware. +struct InefficientNonFlatteningStringHashPolicy +{ + typedef JSString *Lookup; + static HashNumber hash(const Lookup &l); + static bool match(const JSString *const &k, const Lookup &l); +}; + +struct CStringHashPolicy +{ + typedef const char *Lookup; + static HashNumber hash(const Lookup &l); + static bool match(const char *const &k, const Lookup &l); +}; + +// This file features many classes with numerous size_t fields, and each such +// class has one or more methods that need to operate on all of these fields. +// Writing these individually is error-prone -- it's easy to add a new field +// without updating all the required methods. So we define a single macro list +// in each class to name the fields (and notable characteristics of them), and +// then use the following macros to transform those lists into the required +// methods. +// +// In some classes, one or more of the macro arguments aren't used. We use '_' +// for those. +// +#define DECL_SIZE(kind, gc, mSize) size_t mSize; +#define ZERO_SIZE(kind, gc, mSize) mSize(0), +#define COPY_OTHER_SIZE(kind, gc, mSize) mSize(other.mSize), +#define ADD_OTHER_SIZE(kind, gc, mSize) mSize += other.mSize; +#define SUB_OTHER_SIZE(kind, gc, mSize) MOZ_ASSERT(mSize >= other.mSize); \ + mSize -= other.mSize; +#define ADD_SIZE_TO_N(kind, gc, mSize) n += mSize; +#define ADD_SIZE_TO_N_IF_LIVE_GC_THING(kind, gc, mSize) n += (js::gc) ? mSize : 0; +#define ADD_TO_TAB_SIZES(kind, gc, mSize) sizes->add(JS::TabSizes::kind, mSize); + +// Used to annotate which size_t fields measure live GC things and which don't. +enum { + NotLiveGCThing = false, + IsLiveGCThing = true +}; + +} // namespace js + +namespace JS { + +// Data for tracking memory usage of things hanging off objects. +struct ObjectsExtraSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(Objects, NotLiveGCThing, mallocHeapSlots) \ + macro(Objects, NotLiveGCThing, mallocHeapElementsNonAsmJS) \ + macro(Objects, NotLiveGCThing, mallocHeapElementsAsmJS) \ + macro(Objects, NotLiveGCThing, nonHeapElementsAsmJS) \ + macro(Objects, NotLiveGCThing, nonHeapElementsMapped) \ + macro(Objects, NotLiveGCThing, nonHeapCodeAsmJS) \ + macro(Objects, NotLiveGCThing, mallocHeapAsmJSModuleData) \ + macro(Objects, NotLiveGCThing, mallocHeapArgumentsData) \ + macro(Objects, NotLiveGCThing, mallocHeapRegExpStatics) \ + macro(Objects, NotLiveGCThing, mallocHeapPropertyIteratorData) \ + macro(Objects, NotLiveGCThing, mallocHeapCtypesData) + + ObjectsExtraSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + dummy() + {} + + void add(const ObjectsExtraSizes &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE) + } + + size_t sizeOfLiveGCThings() const { + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + return n; + } + + void addToTabSizes(TabSizes *sizes) const { + FOR_EACH_SIZE(ADD_TO_TAB_SIZES) + } + + FOR_EACH_SIZE(DECL_SIZE) + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) + +#undef FOR_EACH_SIZE +}; + +// Data for tracking JIT-code memory usage. +struct CodeSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, ion) \ + macro(_, _, baseline) \ + macro(_, _, regexp) \ + macro(_, _, other) \ + macro(_, _, unused) + + CodeSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + dummy() + {} + + FOR_EACH_SIZE(DECL_SIZE) + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) + +#undef FOR_EACH_SIZE +}; + +// Data for tracking GC memory usage. +struct GCSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, marker) \ + macro(_, _, nurseryCommitted) \ + macro(_, _, nurseryDecommitted) \ + macro(_, _, nurseryHugeSlots) \ + macro(_, _, storeBufferVals) \ + macro(_, _, storeBufferCells) \ + macro(_, _, storeBufferSlots) \ + macro(_, _, storeBufferWholeCells) \ + macro(_, _, storeBufferRelocVals) \ + macro(_, _, storeBufferRelocCells) \ + macro(_, _, storeBufferGenerics) + + GCSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + dummy() + {} + + FOR_EACH_SIZE(DECL_SIZE) + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) + +#undef FOR_EACH_SIZE +}; + +// This class holds information about the memory taken up by identical copies of +// a particular string. Multiple JSStrings may have their sizes aggregated +// together into one StringInfo object. Note that two strings with identical +// chars will not be aggregated together if one is a short string and the other +// is not. +struct StringInfo +{ +#define FOR_EACH_SIZE(macro) \ + macro(Strings, IsLiveGCThing, gcHeapLatin1) \ + macro(Strings, IsLiveGCThing, gcHeapTwoByte) \ + macro(Strings, NotLiveGCThing, mallocHeapLatin1) \ + macro(Strings, NotLiveGCThing, mallocHeapTwoByte) + + StringInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numCopies(0) + {} + + void add(const StringInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE); + numCopies++; + } + + void subtract(const StringInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE); + numCopies--; + } + + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + size_t sizeOfLiveGCThings() const { + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + return n; + } + + void addToTabSizes(TabSizes *sizes) const { + FOR_EACH_SIZE(ADD_TO_TAB_SIZES) + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numCopies; // How many copies of the string have we seen? + +#undef FOR_EACH_SIZE +}; + +// Holds data about a notable string (one which, counting all duplicates, uses +// more than a certain amount of memory) so we can report it individually. +// +// The only difference between this class and StringInfo is that +// NotableStringInfo holds a copy of some or all of the string's chars. +struct NotableStringInfo : public StringInfo +{ + static const size_t MAX_SAVED_CHARS = 1024; + + NotableStringInfo(); + NotableStringInfo(JSString *str, const StringInfo &info); + NotableStringInfo(NotableStringInfo &&info); + NotableStringInfo &operator=(NotableStringInfo &&info); + + ~NotableStringInfo() { + js_free(buffer); + } + + char *buffer; + size_t length; + + private: + NotableStringInfo(const NotableStringInfo& info) MOZ_DELETE; +}; + +// This class holds information about the memory taken up by script sources +// from a particular file. +struct ScriptSourceInfo +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, compressed) \ + macro(_, _, uncompressed) \ + macro(_, _, misc) + + ScriptSourceInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numScripts(0) + {} + + void add(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE) + numScripts++; + } + + void subtract(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE) + numScripts--; + } + + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numScripts; // How many ScriptSources come from this file? (It + // can be more than one in XML files that have + // multiple scripts in CDATA sections.) +#undef FOR_EACH_SIZE +}; + +// Holds data about a notable script source file (one whose combined +// script sources use more than a certain amount of memory) so we can report it +// individually. +// +// The only difference between this class and ScriptSourceInfo is that this +// class holds a copy of the filename. +struct NotableScriptSourceInfo : public ScriptSourceInfo +{ + NotableScriptSourceInfo(); + NotableScriptSourceInfo(const char *filename, const ScriptSourceInfo &info); + NotableScriptSourceInfo(NotableScriptSourceInfo &&info); + NotableScriptSourceInfo &operator=(NotableScriptSourceInfo &&info); + + ~NotableScriptSourceInfo() { + js_free(filename_); + } + + char *filename_; + + private: + NotableScriptSourceInfo(const NotableScriptSourceInfo& info) MOZ_DELETE; +}; + +// These measurements relate directly to the JSRuntime, and not to zones and +// compartments within it. +struct RuntimeSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, object) \ + macro(_, _, atomsTable) \ + macro(_, _, contexts) \ + macro(_, _, dtoa) \ + macro(_, _, temporary) \ + macro(_, _, interpreterStack) \ + macro(_, _, mathCache) \ + macro(_, _, uncompressedSourceCache) \ + macro(_, _, compressedSourceSet) \ + macro(_, _, scriptData) \ + + RuntimeSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + scriptSourceInfo(), + code(), + gc(), + notableScriptSources() + { + allScriptSources = js_new(); + if (!allScriptSources || !allScriptSources->init()) + MOZ_CRASH("oom"); + } + + ~RuntimeSizes() { + // |allScriptSources| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allScriptSources); + } + + // The script source measurements in |scriptSourceInfo| are initially for + // all script sources. At the end, if the measurement granularity is + // FineGrained, we subtract the measurements of the notable script sources + // and move them into |notableScriptSources|. + FOR_EACH_SIZE(DECL_SIZE) + ScriptSourceInfo scriptSourceInfo; + CodeSizes code; + GCSizes gc; + + typedef js::HashMap ScriptSourcesHashMap; + + // |allScriptSources| is only used transiently. During the reporting phase + // it is filled with info about every script source in the runtime. It's + // then used to fill in |notableScriptSources| (which actually gets + // reported), and immediately discarded afterwards. + ScriptSourcesHashMap *allScriptSources; + js::Vector notableScriptSources; + +#undef FOR_EACH_SIZE +}; + +struct ZoneStats +{ +#define FOR_EACH_SIZE(macro) \ + macro(Other, IsLiveGCThing, symbolsGCHeap) \ + macro(Other, NotLiveGCThing, gcHeapArenaAdmin) \ + macro(Other, NotLiveGCThing, unusedGCThings) \ + macro(Other, IsLiveGCThing, lazyScriptsGCHeap) \ + macro(Other, NotLiveGCThing, lazyScriptsMallocHeap) \ + macro(Other, IsLiveGCThing, jitCodesGCHeap) \ + macro(Other, IsLiveGCThing, typeObjectsGCHeap) \ + macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \ + macro(Other, NotLiveGCThing, typePool) \ + macro(Other, NotLiveGCThing, baselineStubsOptimized) \ + + ZoneStats() + : FOR_EACH_SIZE(ZERO_SIZE) + stringInfo(), + extra(), + allStrings(nullptr), + notableStrings(), + isTotals(true) + {} + + ZoneStats(ZoneStats &&other) + : FOR_EACH_SIZE(COPY_OTHER_SIZE) + stringInfo(mozilla::Move(other.stringInfo)), + extra(other.extra), + allStrings(other.allStrings), + notableStrings(mozilla::Move(other.notableStrings)), + isTotals(other.isTotals) + { + other.allStrings = nullptr; + MOZ_ASSERT(!other.isTotals); + } + + ~ZoneStats() { + // |allStrings| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allStrings); + } + + bool initStrings(JSRuntime *rt); + + void addSizes(const ZoneStats &other) { + MOZ_ASSERT(isTotals); + FOR_EACH_SIZE(ADD_OTHER_SIZE) + stringInfo.add(other.stringInfo); + } + + size_t sizeOfLiveGCThings() const { + MOZ_ASSERT(isTotals); + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + n += stringInfo.sizeOfLiveGCThings(); + return n; + } + + void addToTabSizes(JS::TabSizes *sizes) const { + MOZ_ASSERT(isTotals); + FOR_EACH_SIZE(ADD_TO_TAB_SIZES) + stringInfo.addToTabSizes(sizes); + } + + // These string measurements are initially for all strings. At the end, + // if the measurement granularity is FineGrained, we subtract the + // measurements of the notable script sources and move them into + // |notableStrings|. + FOR_EACH_SIZE(DECL_SIZE) + StringInfo stringInfo; + void *extra; // This field can be used by embedders. + + typedef js::HashMap StringsHashMap; + + // |allStrings| is only used transiently. During the zone traversal it is + // filled with info about every string in the zone. It's then used to fill + // in |notableStrings| (which actually gets reported), and immediately + // discarded afterwards. + StringsHashMap *allStrings; + js::Vector notableStrings; + bool isTotals; + +#undef FOR_EACH_SIZE +}; + +struct CompartmentStats +{ +#define FOR_EACH_SIZE(macro) \ + macro(Objects, IsLiveGCThing, objectsGCHeapOrdinary) \ + macro(Objects, IsLiveGCThing, objectsGCHeapFunction) \ + macro(Objects, IsLiveGCThing, objectsGCHeapDenseArray) \ + macro(Objects, IsLiveGCThing, objectsGCHeapSlowArray) \ + macro(Objects, IsLiveGCThing, objectsGCHeapCrossCompartmentWrapper) \ + macro(Private, NotLiveGCThing, objectsPrivate) \ + macro(Other, IsLiveGCThing, shapesGCHeapTreeGlobalParented) \ + macro(Other, IsLiveGCThing, shapesGCHeapTreeNonGlobalParented) \ + macro(Other, IsLiveGCThing, shapesGCHeapDict) \ + macro(Other, IsLiveGCThing, shapesGCHeapBase) \ + macro(Other, NotLiveGCThing, shapesMallocHeapTreeTables) \ + macro(Other, NotLiveGCThing, shapesMallocHeapDictTables) \ + macro(Other, NotLiveGCThing, shapesMallocHeapTreeShapeKids) \ + macro(Other, NotLiveGCThing, shapesMallocHeapCompartmentTables) \ + macro(Other, IsLiveGCThing, scriptsGCHeap) \ + macro(Other, NotLiveGCThing, scriptsMallocHeapData) \ + macro(Other, NotLiveGCThing, baselineData) \ + macro(Other, NotLiveGCThing, baselineStubsFallback) \ + macro(Other, NotLiveGCThing, ionData) \ + macro(Other, NotLiveGCThing, typeInferenceTypeScripts) \ + macro(Other, NotLiveGCThing, typeInferenceAllocationSiteTables) \ + macro(Other, NotLiveGCThing, typeInferenceArrayTypeTables) \ + macro(Other, NotLiveGCThing, typeInferenceObjectTypeTables) \ + macro(Other, NotLiveGCThing, compartmentObject) \ + macro(Other, NotLiveGCThing, crossCompartmentWrappersTable) \ + macro(Other, NotLiveGCThing, regexpCompartment) \ + macro(Other, NotLiveGCThing, debuggeesSet) \ + macro(Other, NotLiveGCThing, savedStacksSet) + + CompartmentStats() + : FOR_EACH_SIZE(ZERO_SIZE) + objectsExtra(), + extra() + {} + + CompartmentStats(const CompartmentStats &other) + : FOR_EACH_SIZE(COPY_OTHER_SIZE) + objectsExtra(other.objectsExtra), + extra(other.extra) + {} + + void add(const CompartmentStats &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE) + objectsExtra.add(other.objectsExtra); + // Do nothing with |extra|. + } + + size_t sizeOfLiveGCThings() const { + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + n += objectsExtra.sizeOfLiveGCThings(); + // Do nothing with |extra|. + return n; + } + + void addToTabSizes(TabSizes *sizes) const { + FOR_EACH_SIZE(ADD_TO_TAB_SIZES); + objectsExtra.addToTabSizes(sizes); + // Do nothing with |extra|. + } + + FOR_EACH_SIZE(DECL_SIZE) + ObjectsExtraSizes objectsExtra; + void *extra; // This field can be used by embedders. + +#undef FOR_EACH_SIZE +}; + +typedef js::Vector CompartmentStatsVector; +typedef js::Vector ZoneStatsVector; + +struct RuntimeStats +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, gcHeapChunkTotal) \ + macro(_, _, gcHeapDecommittedArenas) \ + macro(_, _, gcHeapUnusedChunks) \ + macro(_, _, gcHeapUnusedArenas) \ + macro(_, _, gcHeapChunkAdmin) \ + macro(_, _, gcHeapGCThings) \ + + explicit RuntimeStats(mozilla::MallocSizeOf mallocSizeOf) + : FOR_EACH_SIZE(ZERO_SIZE) + runtime(), + cTotals(), + zTotals(), + compartmentStatsVector(), + zoneStatsVector(), + currZoneStats(nullptr), + mallocSizeOf_(mallocSizeOf) + {} + + // Here's a useful breakdown of the GC heap. + // + // - rtStats.gcHeapChunkTotal + // - decommitted bytes + // - rtStats.gcHeapDecommittedArenas (decommitted arenas in non-empty chunks) + // - unused bytes + // - rtStats.gcHeapUnusedChunks (empty chunks) + // - rtStats.gcHeapUnusedArenas (empty arenas within non-empty chunks) + // - rtStats.zTotals.unusedGCThings (empty GC thing slots within non-empty arenas) + // - used bytes + // - rtStats.gcHeapChunkAdmin + // - rtStats.zTotals.gcHeapArenaAdmin + // - rtStats.gcHeapGCThings (in-use GC things) + // == rtStats.zTotals.sizeOfLiveGCThings() + rtStats.cTotals.sizeOfLiveGCThings() + // + // It's possible that some arenas in empty chunks may be decommitted, but + // we don't count those under rtStats.gcHeapDecommittedArenas because (a) + // it's rare, and (b) this means that rtStats.gcHeapUnusedChunks is a + // multiple of the chunk size, which is good. + + FOR_EACH_SIZE(DECL_SIZE) + + RuntimeSizes runtime; + + CompartmentStats cTotals; // The sum of this runtime's compartments' measurements. + ZoneStats zTotals; // The sum of this runtime's zones' measurements. + + CompartmentStatsVector compartmentStatsVector; + ZoneStatsVector zoneStatsVector; + + ZoneStats *currZoneStats; + + mozilla::MallocSizeOf mallocSizeOf_; + + virtual void initExtraCompartmentStats(JSCompartment *c, CompartmentStats *cstats) = 0; + virtual void initExtraZoneStats(JS::Zone *zone, ZoneStats *zstats) = 0; + +#undef FOR_EACH_SIZE +}; + +class ObjectPrivateVisitor +{ + public: + // Within CollectRuntimeStats, this method is called for each JS object + // that has an nsISupports pointer. + virtual size_t sizeOfIncludingThis(nsISupports *aSupports) = 0; + + // A callback that gets a JSObject's nsISupports pointer, if it has one. + // Note: this function does *not* addref |iface|. + typedef bool(*GetISupportsFun)(JSObject *obj, nsISupports **iface); + GetISupportsFun getISupports_; + + explicit ObjectPrivateVisitor(GetISupportsFun getISupports) + : getISupports_(getISupports) + {} +}; + +extern JS_PUBLIC_API(bool) +CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv, bool anonymize); + +extern JS_PUBLIC_API(size_t) +SystemCompartmentCount(JSRuntime *rt); + +extern JS_PUBLIC_API(size_t) +UserCompartmentCount(JSRuntime *rt); + +extern JS_PUBLIC_API(size_t) +PeakSizeOfTemporary(const JSRuntime *rt); + +extern JS_PUBLIC_API(bool) +AddSizeOfTab(JSRuntime *rt, JS::HandleObject obj, mozilla::MallocSizeOf mallocSizeOf, + ObjectPrivateVisitor *opv, TabSizes *sizes); + +} // namespace JS + +#undef DECL_SIZE +#undef ZERO_SIZE +#undef COPY_OTHER_SIZE +#undef ADD_OTHER_SIZE +#undef SUB_OTHER_SIZE +#undef ADD_SIZE_TO_N +#undef ADD_SIZE_TO_N_IF_LIVE_GC_THING +#undef ADD_TO_TAB_SIZES + +#endif /* js_MemoryMetrics_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/OldDebugAPI.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/OldDebugAPI.h new file mode 100644 index 0000000000..7117d754d9 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/OldDebugAPI.h @@ -0,0 +1,385 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_OldDebugAPI_h +#define js_OldDebugAPI_h + +/* + * JS debugger API. + */ + +#include "mozilla/NullPtr.h" + +#include "jsapi.h" +#include "jsbytecode.h" + +#include "js/CallArgs.h" +#include "js/TypeDecls.h" + +class JSAtom; +struct JSFreeOp; + +namespace js { +class InterpreterFrame; +class FrameIter; +class ScriptSource; +} + +// Raw JSScript* because this needs to be callable from a signal handler. +extern JS_PUBLIC_API(unsigned) +JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); + +extern JS_PUBLIC_API(const char *) +JS_GetScriptFilename(JSScript *script); + +namespace JS { + +extern JS_PUBLIC_API(char *) +FormatStackDump(JSContext *cx, char *buf, bool showArgs, bool showLocals, bool showThisProps); + +} // namespace JS + +# ifdef JS_DEBUG +JS_FRIEND_API(void) js_DumpValue(const JS::Value &val); +JS_FRIEND_API(void) js_DumpId(jsid id); +JS_FRIEND_API(void) js_DumpInterpreterFrame(JSContext *cx, js::InterpreterFrame *start = nullptr); +# endif + +JS_FRIEND_API(void) +js_DumpBacktrace(JSContext *cx); + +typedef enum JSTrapStatus { + JSTRAP_ERROR, + JSTRAP_CONTINUE, + JSTRAP_RETURN, + JSTRAP_THROW, + JSTRAP_LIMIT +} JSTrapStatus; + +typedef JSTrapStatus +(* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, + JS::Value closure); + +typedef JSTrapStatus +(* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, + void *closure); + +typedef bool +(* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, JS::Value old, + JS::Value *newp, void *closure); + + + +extern JS_PUBLIC_API(JSCompartment *) +JS_EnterCompartmentOfScript(JSContext *cx, JSScript *target); + +extern JS_PUBLIC_API(JSString *) +JS_DecompileScript(JSContext *cx, JS::HandleScript script, const char *name, unsigned indent); + +/* + * Currently, we only support runtime-wide debugging. In the future, we should + * be able to support compartment-wide debugging. + */ +extern JS_PUBLIC_API(void) +JS_SetRuntimeDebugMode(JSRuntime *rt, bool debug); + +/* + * Debug mode is a compartment-wide mode that enables a debugger to attach + * to and interact with running methodjit-ed frames. In particular, it causes + * every function to be compiled as if an eval was present (so eval-in-frame) + * can work, and it ensures that functions can be re-JITed for other debug + * features. In general, it is not safe to interact with frames that were live + * before debug mode was enabled. For this reason, it is also not safe to + * enable debug mode while frames are live. + */ + +/* Get current state of debugging mode. */ +extern JS_PUBLIC_API(bool) +JS_GetDebugMode(JSContext *cx); + +/* + * Turn on/off debugging mode for all compartments. This returns false if any code + * from any of the runtime's compartments is running or on the stack. + */ +JS_FRIEND_API(bool) +JS_SetDebugModeForAllCompartments(JSContext *cx, bool debug); + +/* + * Turn on/off debugging mode for a single compartment. This should only be + * used when no code from this compartment is running or on the stack in any + * thread. + */ +JS_FRIEND_API(bool) +JS_SetDebugModeForCompartment(JSContext *cx, JSCompartment *comp, bool debug); + +/* + * Turn on/off debugging mode for a context's compartment. + */ +JS_FRIEND_API(bool) +JS_SetDebugMode(JSContext *cx, bool debug); + +/* Turn on single step mode. */ +extern JS_PUBLIC_API(bool) +JS_SetSingleStepMode(JSContext *cx, JS::HandleScript script, bool singleStep); + +/* The closure argument will be marked. */ +extern JS_PUBLIC_API(bool) +JS_SetTrap(JSContext *cx, JS::HandleScript script, jsbytecode *pc, + JSTrapHandler handler, JS::HandleValue closure); + +extern JS_PUBLIC_API(void) +JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc, + JSTrapHandler *handlerp, JS::Value *closurep); + +extern JS_PUBLIC_API(void) +JS_ClearScriptTraps(JSRuntime *rt, JSScript *script); + +extern JS_PUBLIC_API(void) +JS_ClearAllTrapsForCompartment(JSContext *cx); + +/************************************************************************/ + +extern JS_PUBLIC_API(bool) +JS_SetWatchPoint(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JSWatchPointHandler handler, JS::HandleObject closure); + +extern JS_PUBLIC_API(bool) +JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id, + JSWatchPointHandler *handlerp, JSObject **closurep); + +extern JS_PUBLIC_API(bool) +JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj); + +/************************************************************************/ + +extern JS_PUBLIC_API(jsbytecode *) +JS_LineNumberToPC(JSContext *cx, JSScript *script, unsigned lineno); + +extern JS_PUBLIC_API(jsbytecode *) +JS_EndPC(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(bool) +JS_GetLinePCs(JSContext *cx, JSScript *script, + unsigned startLine, unsigned maxLines, + unsigned* count, unsigned** lines, jsbytecode*** pcs); + +extern JS_PUBLIC_API(unsigned) +JS_GetFunctionArgumentCount(JSContext *cx, JSFunction *fun); + +extern JS_PUBLIC_API(bool) +JS_FunctionHasLocalNames(JSContext *cx, JSFunction *fun); + +/* + * N.B. The mark is in the context temp pool and thus the caller must take care + * to call JS_ReleaseFunctionLocalNameArray in a LIFO manner (wrt to any other + * call that may use the temp pool. + */ +extern JS_PUBLIC_API(uintptr_t *) +JS_GetFunctionLocalNameArray(JSContext *cx, JSFunction *fun, void **markp); + +extern JS_PUBLIC_API(JSAtom *) +JS_LocalNameToAtom(uintptr_t w); + +extern JS_PUBLIC_API(JSString *) +JS_AtomKey(JSAtom *atom); + +extern JS_PUBLIC_API(void) +JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mark); + +extern JS_PUBLIC_API(JSScript *) +JS_GetFunctionScript(JSContext *cx, JS::HandleFunction fun); + +extern JS_PUBLIC_API(JSNative) +JS_GetFunctionNative(JSContext *cx, JSFunction *fun); + +JS_PUBLIC_API(JSFunction *) +JS_GetScriptFunction(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(JSObject *) +JS_GetParentOrScopeChain(JSContext *cx, JSObject *obj); + +/************************************************************************/ + +/* + * This is almost JS_GetClass(obj)->name except that certain debug-only + * proxies are made transparent. In particular, this function turns the class + * of any scope (returned via JS_GetFrameScopeChain or JS_GetFrameCalleeObject) + * from "Proxy" to "Call", "Block", "With" etc. + */ +extern JS_PUBLIC_API(const char *) +JS_GetDebugClassName(JSObject *obj); + +/************************************************************************/ + +extern JS_PUBLIC_API(const jschar *) +JS_GetScriptSourceMap(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(unsigned) +JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(unsigned) +JS_GetScriptLineExtent(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(JSVersion) +JS_GetScriptVersion(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(bool) +JS_GetScriptIsSelfHosted(JSScript *script); + +/************************************************************************/ + +typedef struct JSPropertyDesc { + JS::Value id; /* primary id, atomized string, or int */ + JS::Value value; /* property value */ + uint8_t flags; /* flags, see below */ + uint8_t spare; /* unused */ + JS::Value alias; /* alias id if JSPD_ALIAS flag */ +} JSPropertyDesc; + +#define JSPD_ENUMERATE 0x01 /* visible to for/in loop */ +#define JSPD_READONLY 0x02 /* assignment is error */ +#define JSPD_PERMANENT 0x04 /* property cannot be deleted */ +#define JSPD_ALIAS 0x08 /* property has an alias id */ +#define JSPD_EXCEPTION 0x40 /* exception occurred fetching the property, */ + /* value is exception */ +#define JSPD_ERROR 0x80 /* native getter returned false without */ + /* throwing an exception */ + +typedef struct JSPropertyDescArray { + uint32_t length; /* number of elements in array */ + JSPropertyDesc *array; /* alloc'd by Get, freed by Put */ +} JSPropertyDescArray; + +typedef struct JSScopeProperty JSScopeProperty; + +extern JS_PUBLIC_API(bool) +JS_GetPropertyDescArray(JSContext *cx, JS::HandleObject obj, JSPropertyDescArray *pda); + +extern JS_PUBLIC_API(void) +JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); + +/************************************************************************/ + +/* + * JSAbstractFramePtr is the public version of AbstractFramePtr, a pointer to a + * StackFrame or baseline JIT frame. + */ +class JS_PUBLIC_API(JSAbstractFramePtr) +{ + uintptr_t ptr_; + jsbytecode *pc_; + + protected: + JSAbstractFramePtr() + : ptr_(0), pc_(nullptr) + { } + + public: + JSAbstractFramePtr(void *raw, jsbytecode *pc); + + uintptr_t raw() const { return ptr_; } + jsbytecode *pc() const { return pc_; } + + operator bool() const { return !!ptr_; } + + JSObject *scopeChain(JSContext *cx); + JSObject *callObject(JSContext *cx); + + JSFunction *maybeFun(); + JSScript *script(); + + bool getThisValue(JSContext *cx, JS::MutableHandleValue thisv); + + bool isDebuggerFrame(); + + bool evaluateInStackFrame(JSContext *cx, + const char *bytes, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandleValue rval); + + bool evaluateUCInStackFrame(JSContext *cx, + const jschar *chars, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandleValue rval); +}; + +class JS_PUBLIC_API(JSNullFramePtr) : public JSAbstractFramePtr +{ + public: + JSNullFramePtr() + : JSAbstractFramePtr() + {} +}; + +/* + * This class does not work when IonMonkey is active. It's only used by jsd, + * which can only be used when IonMonkey is disabled. + * + * To find the calling script and line number, use JS_DescribeSciptedCaller. + * To summarize the call stack, use JS::DescribeStack. + */ +class JS_PUBLIC_API(JSBrokenFrameIterator) +{ + void *data_; + + public: + explicit JSBrokenFrameIterator(JSContext *cx); + ~JSBrokenFrameIterator(); + + bool done() const; + JSBrokenFrameIterator& operator++(); + + JSAbstractFramePtr abstractFramePtr() const; + jsbytecode *pc() const; + + bool isConstructing() const; +}; + +typedef bool +(* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report, + void *closure); + +typedef struct JSDebugHooks { + JSDebuggerHandler debuggerHandler; + void *debuggerHandlerData; +} JSDebugHooks; + +/************************************************************************/ + +extern JS_PUBLIC_API(bool) +JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler hook, void *closure); + +/************************************************************************/ + +extern JS_PUBLIC_API(const JSDebugHooks *) +JS_GetGlobalDebugHooks(JSRuntime *rt); + +/** + * Add various profiling-related functions as properties of the given object. + */ +extern JS_PUBLIC_API(bool) +JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj); + +/* Defined in vm/Debugger.cpp. */ +extern JS_PUBLIC_API(bool) +JS_DefineDebuggerObject(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(void) +JS_DumpPCCounts(JSContext *cx, JS::HandleScript script); + +extern JS_PUBLIC_API(void) +JS_DumpCompartmentPCCounts(JSContext *cx); + +namespace js { +extern JS_FRIEND_API(bool) +CanCallContextDebugHandler(JSContext *cx); +} + +/* Call the context debug handler on the topmost scripted frame. */ +extern JS_FRIEND_API(bool) +js_CallContextDebugHandler(JSContext *cx); + +#endif /* js_OldDebugAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Principals.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Principals.h new file mode 100644 index 0000000000..78d8c7e893 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Principals.h @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JSPrincipals and related interfaces. */ + +#ifndef js_Principals_h +#define js_Principals_h + +#include "mozilla/Atomics.h" + +#include + +#include "jspubtd.h" + +struct JSPrincipals { + /* Don't call "destroy"; use reference counting macros below. */ +#ifdef JS_THREADSAFE + mozilla::Atomic refcount; +#else + int32_t refcount; +#endif + +#ifdef JS_DEBUG + /* A helper to facilitate principals debugging. */ + uint32_t debugToken; +#endif + + void setDebugToken(uint32_t token) { +# ifdef JS_DEBUG + debugToken = token; +# endif + } + + /* + * This is not defined by the JS engine but should be provided by the + * embedding. + */ + JS_PUBLIC_API(void) dump(); +}; + +extern JS_PUBLIC_API(void) +JS_HoldPrincipals(JSPrincipals *principals); + +extern JS_PUBLIC_API(void) +JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals); + +// Return whether the first principal subsumes the second. The exact meaning of +// 'subsumes' is left up to the browser. Subsumption is checked inside the JS +// engine when determining, e.g., which stack frames to display in a backtrace. +typedef bool +(* JSSubsumesOp)(JSPrincipals *first, JSPrincipals *second); + +/* + * Used to check if a CSP instance wants to disable eval() and friends. + * See js_CheckCSPPermitsJSAction() in jsobj. + */ +typedef bool +(* JSCSPEvalChecker)(JSContext *cx); + +struct JSSecurityCallbacks { + JSCSPEvalChecker contentSecurityPolicyAllows; + JSSubsumesOp subsumes; +}; + +extern JS_PUBLIC_API(void) +JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks); + +extern JS_PUBLIC_API(const JSSecurityCallbacks *) +JS_GetSecurityCallbacks(JSRuntime *rt); + +/* + * Code running with "trusted" principals will be given a deeper stack + * allocation than ordinary scripts. This allows trusted script to run after + * untrusted script has exhausted the stack. This function sets the + * runtime-wide trusted principal. + * + * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since + * there is no available JSContext. Instead, the caller must ensure that the + * given principals stays valid for as long as 'rt' may point to it. If the + * principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be + * called again, passing nullptr for 'prin'. + */ +extern JS_PUBLIC_API(void) +JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin); + +typedef void +(* JSDestroyPrincipalsOp)(JSPrincipals *principals); + +/* + * Initialize the callback that is called to destroy JSPrincipals instance + * when its reference counter drops to zero. The initialization can be done + * only once per JS runtime. + */ +extern JS_PUBLIC_API(void) +JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals); + +#endif /* js_Principals_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/ProfilingStack.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/ProfilingStack.h new file mode 100644 index 0000000000..e82ce1c9d8 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/ProfilingStack.h @@ -0,0 +1,169 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_ProfilingStack_h +#define js_ProfilingStack_h + +#include "mozilla/NullPtr.h" +#include "mozilla/TypedEnum.h" + +#include "jsbytecode.h" +#include "jstypes.h" + +#include "js/Utility.h" + +struct JSRuntime; + +namespace js { + +// A call stack can be specified to the JS engine such that all JS entry/exits +// to functions push/pop an entry to/from the specified stack. +// +// For more detailed information, see vm/SPSProfiler.h. +// +class ProfileEntry +{ + // All fields are marked volatile to prevent the compiler from re-ordering + // instructions. Namely this sequence: + // + // entry[size] = ...; + // size++; + // + // If the size modification were somehow reordered before the stores, then + // if a sample were taken it would be examining bogus information. + // + // A ProfileEntry represents both a C++ profile entry and a JS one. + + // Descriptive string of this entry. + const char * volatile string; + + // Stack pointer for non-JS entries, the script pointer otherwise. + void * volatile spOrScript; + + // Line number for non-JS entries, the bytecode offset otherwise. + int32_t volatile lineOrPc; + + // General purpose storage describing this frame. + uint32_t volatile flags_; + + public: + // These traits are bit masks. Make sure they're powers of 2. + enum Flags { + // Indicate whether a profile entry represents a CPP frame. If not set, + // a JS frame is assumed by default. You're not allowed to publicly + // change the frame type. Instead, call `setJsFrame` or `setCppFrame`. + IS_CPP_ENTRY = 0x01, + + // Indicate that copying the frame label is not necessary when taking a + // sample of the pseudostack. + FRAME_LABEL_COPY = 0x02, + + // Mask for removing all flags except the category information. + CATEGORY_MASK = ~IS_CPP_ENTRY & ~FRAME_LABEL_COPY + }; + + MOZ_BEGIN_NESTED_ENUM_CLASS(Category, uint32_t) + OTHER = 0x04, + CSS = 0x08, + JS = 0x10, + GC = 0x20, + CC = 0x40, + NETWORK = 0x80, + GRAPHICS = 0x100, + STORAGE = 0x200, + EVENTS = 0x400, + + FIRST = OTHER, + LAST = EVENTS + MOZ_END_NESTED_ENUM_CLASS(Category) + + // All of these methods are marked with the 'volatile' keyword because SPS's + // representation of the stack is stored such that all ProfileEntry + // instances are volatile. These methods would not be available unless they + // were marked as volatile as well. + + bool isCpp() const volatile { return hasFlag(IS_CPP_ENTRY); } + bool isJs() const volatile { return !isCpp(); } + + bool isCopyLabel() const volatile { return hasFlag(FRAME_LABEL_COPY); }; + + void setLabel(const char *aString) volatile { string = aString; } + const char *label() const volatile { return string; } + + void setJsFrame(JSScript *aScript, jsbytecode *aPc) volatile { + flags_ = 0; + spOrScript = aScript; + setPC(aPc); + } + void setCppFrame(void *aSp, uint32_t aLine) volatile { + flags_ = IS_CPP_ENTRY; + spOrScript = aSp; + lineOrPc = static_cast(aLine); + } + + void setFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ |= flag; + } + void unsetFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ &= ~flag; + } + bool hasFlag(uint32_t flag) const volatile { + return bool(flags_ & flag); + } + + uint32_t flags() const volatile { + return flags_; + } + uint32_t category() const volatile { + return flags_ & CATEGORY_MASK; + } + + void *stackAddress() const volatile { + MOZ_ASSERT(!isJs()); + return spOrScript; + } + JSScript *script() const volatile { + MOZ_ASSERT(isJs()); + return (JSScript *)spOrScript; + } + uint32_t line() const volatile { + MOZ_ASSERT(!isJs()); + return static_cast(lineOrPc); + } + + // We can't know the layout of JSScript, so look in vm/SPSProfiler.cpp. + JS_FRIEND_API(jsbytecode *) pc() const volatile; + JS_FRIEND_API(void) setPC(jsbytecode *pc) volatile; + + // The offset of a pc into a script's code can actually be 0, so to + // signify a nullptr pc, use a -1 index. This is checked against in + // pc() and setPC() to set/get the right pc. + static const int32_t NullPCOffset = -1; + + static size_t offsetOfLabel() { return offsetof(ProfileEntry, string); } + static size_t offsetOfSpOrScript() { return offsetof(ProfileEntry, spOrScript); } + static size_t offsetOfLineOrPc() { return offsetof(ProfileEntry, lineOrPc); } + static size_t offsetOfFlags() { return offsetof(ProfileEntry, flags_); } +}; + +JS_FRIEND_API(void) +SetRuntimeProfilingStack(JSRuntime *rt, ProfileEntry *stack, uint32_t *size, + uint32_t max); + +JS_FRIEND_API(void) +EnableRuntimeProfilingStack(JSRuntime *rt, bool enabled); + +JS_FRIEND_API(void) +RegisterRuntimeProfilingEventMarker(JSRuntime *rt, void (*fn)(const char *)); + +JS_FRIEND_API(jsbytecode*) +ProfilingGetPC(JSRuntime *rt, JSScript *script, void *ip); + +} // namespace js + +#endif /* js_ProfilingStack_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/PropertyKey.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/PropertyKey.h new file mode 100644 index 0000000000..1f90653b40 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/PropertyKey.h @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JS::PropertyKey implementation. */ + +#ifndef js_PropertyKey_h +#define js_PropertyKey_h + +#include "js/TypeDecls.h" +#include "js/Value.h" + +namespace JS { + +class PropertyKey; + +namespace detail { + +extern JS_PUBLIC_API(bool) +ToPropertyKeySlow(JSContext *cx, HandleValue v, PropertyKey *key); + +} // namespace detail + +/* + * A PropertyKey is a key used to access some property on an object. It is a + * natural way to represent a property accessed using a JavaScript value. + * + * PropertyKey can represent indexes, named properties, and ES6 symbols. The + * latter aren't implemented in SpiderMonkey yet, but PropertyKey carves out + * space for them. + */ +class PropertyKey +{ + Value v; + friend JS_PUBLIC_API(bool) detail::ToPropertyKeySlow(JSContext *cx, HandleValue v, PropertyKey *key); + + public: + explicit PropertyKey(uint32_t index) : v(PrivateUint32Value(index)) {} + + /* + * An index is a string property name whose characters exactly spell out an + * unsigned 32-bit integer in decimal: "0", "1", "2", ...., "4294967294", + * "4294967295". + */ + bool isIndex(uint32_t *index) { + // The implementation here assumes that private uint32_t are stored + // using the int32_t representation. This is purely an implementation + // detail: embedders must not rely upon this! + if (!v.isInt32()) + return false; + *index = v.toPrivateUint32(); + return true; + } + + /* + * A name is a string property name which is *not* an index. Note that by + * the ECMAScript language grammar, any dotted property access |obj.prop| + * will access a named property. + */ + bool isName(JSString **str) { + uint32_t dummy; + if (isIndex(&dummy)) + return false; + *str = v.toString(); + return true; + } + + /* + * A symbol is a property name that's a Symbol, a particular kind of object + * in ES6. It is the only kind of property name that's not a string. + * + * SpiderMonkey doesn't yet implement symbols, but we're carving out API + * space for them in advance. + */ + bool isSymbol() { + return false; + } +}; + +inline bool +ToPropertyKey(JSContext *cx, HandleValue v, PropertyKey *key) +{ + if (v.isInt32() && v.toInt32() >= 0) { + *key = PropertyKey(uint32_t(v.toInt32())); + return true; + } + + return detail::ToPropertyKeySlow(cx, v, key); +} + +} // namespace JS + +#endif /* js_PropertyKey_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/RequiredDefines.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/RequiredDefines.h new file mode 100644 index 0000000000..308fd7d625 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/RequiredDefines.h @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Various #defines required to build SpiderMonkey. Embedders should add this + * file to the start of the command line via -include or a similar mechanism, + * or SpiderMonkey public headers may not work correctly. + */ + +#ifndef js_RequiredDefines_h +#define js_RequiredDefines_h + +/* + * The c99 defining the limit macros (UINT32_MAX for example), says: + * + * C++ implementations should define these macros only when + * __STDC_LIMIT_MACROS is defined before is included. + * + * The same also occurs with __STDC_CONSTANT_MACROS for the constant macros + * (INT8_C for example) used to specify a literal constant of the proper type, + * and with __STDC_FORMAT_MACROS for the format macros (PRId32 for example) used + * with the fprintf function family. + */ +#define __STDC_LIMIT_MACROS +#define __STDC_CONSTANT_MACROS +#define __STDC_FORMAT_MACROS + +/* Also define a char16_t type if not provided by the compiler. */ +#include "mozilla/Char16.h" + +#endif /* js_RequiredDefines_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/RootingAPI.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/RootingAPI.h new file mode 100644 index 0000000000..621a1e4394 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/RootingAPI.h @@ -0,0 +1,1253 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_RootingAPI_h +#define js_RootingAPI_h + +#include "mozilla/Attributes.h" +#include "mozilla/GuardObjects.h" +#include "mozilla/LinkedList.h" +#include "mozilla/NullPtr.h" +#include "mozilla/TypeTraits.h" + +#include "jspubtd.h" + +#include "js/GCAPI.h" +#include "js/HeapAPI.h" +#include "js/TypeDecls.h" +#include "js/Utility.h" + +/* + * Moving GC Stack Rooting + * + * A moving GC may change the physical location of GC allocated things, even + * when they are rooted, updating all pointers to the thing to refer to its new + * location. The GC must therefore know about all live pointers to a thing, + * not just one of them, in order to behave correctly. + * + * The |Rooted| and |Handle| classes below are used to root stack locations + * whose value may be held live across a call that can trigger GC. For a + * code fragment such as: + * + * JSObject *obj = NewObject(cx); + * DoSomething(cx); + * ... = obj->lastProperty(); + * + * If |DoSomething()| can trigger a GC, the stack location of |obj| must be + * rooted to ensure that the GC does not move the JSObject referred to by + * |obj| without updating |obj|'s location itself. This rooting must happen + * regardless of whether there are other roots which ensure that the object + * itself will not be collected. + * + * If |DoSomething()| cannot trigger a GC, and the same holds for all other + * calls made between |obj|'s definitions and its last uses, then no rooting + * is required. + * + * SpiderMonkey can trigger a GC at almost any time and in ways that are not + * always clear. For example, the following innocuous-looking actions can + * cause a GC: allocation of any new GC thing; JSObject::hasProperty; + * JS_ReportError and friends; and ToNumber, among many others. The following + * dangerous-looking actions cannot trigger a GC: js_malloc, cx->malloc_, + * rt->malloc_, and friends and JS_ReportOutOfMemory. + * + * The following family of three classes will exactly root a stack location. + * Incorrect usage of these classes will result in a compile error in almost + * all cases. Therefore, it is very hard to be incorrectly rooted if you use + * these classes exclusively. These classes are all templated on the type T of + * the value being rooted. + * + * - Rooted declares a variable of type T, whose value is always rooted. + * Rooted may be automatically coerced to a Handle, below. Rooted + * should be used whenever a local variable's value may be held live across a + * call which can trigger a GC. + * + * - Handle is a const reference to a Rooted. Functions which take GC + * things or values as arguments and need to root those arguments should + * generally use handles for those arguments and avoid any explicit rooting. + * This has two benefits. First, when several such functions call each other + * then redundant rooting of multiple copies of the GC thing can be avoided. + * Second, if the caller does not pass a rooted value a compile error will be + * generated, which is quicker and easier to fix than when relying on a + * separate rooting analysis. + * + * - MutableHandle is a non-const reference to Rooted. It is used in the + * same way as Handle and includes a |set(const T &v)| method to allow + * updating the value of the referenced Rooted. A MutableHandle can be + * created from a Rooted by using |Rooted::operator&()|. + * + * In some cases the small performance overhead of exact rooting (measured to + * be a few nanoseconds on desktop) is too much. In these cases, try the + * following: + * + * - Move all Rooted above inner loops: this allows you to re-use the root + * on each iteration of the loop. + * + * - Pass Handle through your hot call stack to avoid re-rooting costs at + * every invocation. + * + * The following diagram explains the list of supported, implicit type + * conversions between classes of this family: + * + * Rooted ----> Handle + * | ^ + * | | + * | | + * +---> MutableHandle + * (via &) + * + * All of these types have an implicit conversion to raw pointers. + */ + +namespace js { + +class ScriptSourceObject; + +template +struct GCMethods {}; + +template +class RootedBase {}; + +template +class HandleBase {}; + +template +class MutableHandleBase {}; + +template +class HeapBase {}; + +/* + * js::NullPtr acts like a nullptr pointer in contexts that require a Handle. + * + * Handle provides an implicit constructor for js::NullPtr so that, given: + * foo(Handle h); + * callers can simply write: + * foo(js::NullPtr()); + * which avoids creating a Rooted just to pass nullptr. + * + * This is the SpiderMonkey internal variant. js::NullPtr should be used in + * preference to JS::NullPtr to avoid the GOT access required for JS_PUBLIC_API + * symbols. + */ +struct NullPtr +{ + static void * const constNullValue; +}; + +namespace gc { +struct Cell; +template +struct PersistentRootedMarker; +} /* namespace gc */ + +} /* namespace js */ + +namespace JS { + +template class Rooted; +template class PersistentRooted; + +/* This is exposing internal state of the GC for inlining purposes. */ +JS_FRIEND_API(bool) isGCEnabled(); + +/* + * JS::NullPtr acts like a nullptr pointer in contexts that require a Handle. + * + * Handle provides an implicit constructor for JS::NullPtr so that, given: + * foo(Handle h); + * callers can simply write: + * foo(JS::NullPtr()); + * which avoids creating a Rooted just to pass nullptr. + */ +struct JS_PUBLIC_API(NullPtr) +{ + static void * const constNullValue; +}; + +/* + * The Heap class is a heap-stored reference to a JS GC thing. All members of + * heap classes that refer to GC things should use Heap (or possibly + * TenuredHeap, described below). + * + * Heap is an abstraction that hides some of the complexity required to + * maintain GC invariants for the contained reference. It uses operator + * overloading to provide a normal pointer interface, but notifies the GC every + * time the value it contains is updated. This is necessary for generational GC, + * which keeps track of all pointers into the nursery. + * + * Heap instances must be traced when their containing object is traced to + * keep the pointed-to GC thing alive. + * + * Heap objects should only be used on the heap. GC references stored on the + * C/C++ stack must use Rooted/Handle/MutableHandle instead. + * + * Type T must be one of: JS::Value, jsid, JSObject*, JSString*, JSScript* + */ +template +class Heap : public js::HeapBase +{ + public: + Heap() { + static_assert(sizeof(T) == sizeof(Heap), + "Heap must be binary compatible with T."); + init(js::GCMethods::initial()); + } + explicit Heap(T p) { init(p); } + + /* + * For Heap, move semantics are equivalent to copy semantics. In C++, a + * copy constructor taking const-ref is the way to get a single function + * that will be used for both lvalue and rvalue copies, so we can simply + * omit the rvalue variant. + */ + explicit Heap(const Heap &p) { init(p.ptr); } + + ~Heap() { + if (js::GCMethods::needsPostBarrier(ptr)) + relocate(); + } + + bool operator==(const Heap &other) { return ptr == other.ptr; } + bool operator!=(const Heap &other) { return ptr != other.ptr; } + + bool operator==(const T &other) const { return ptr == other; } + bool operator!=(const T &other) const { return ptr != other; } + + operator T() const { return ptr; } + T operator->() const { return ptr; } + const T *address() const { return &ptr; } + const T &get() const { return ptr; } + + T *unsafeGet() { return &ptr; } + + Heap &operator=(T p) { + set(p); + return *this; + } + + Heap &operator=(const Heap& other) { + set(other.get()); + return *this; + } + + void set(T newPtr) { + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); + if (js::GCMethods::needsPostBarrier(newPtr)) { + ptr = newPtr; + post(); + } else if (js::GCMethods::needsPostBarrier(ptr)) { + relocate(); /* Called before overwriting ptr. */ + ptr = newPtr; + } else { + ptr = newPtr; + } + } + + /* + * Set the pointer to a value which will cause a crash if it is + * dereferenced. + */ + void setToCrashOnTouch() { + ptr = reinterpret_cast(crashOnTouchPointer); + } + + bool isSetToCrashOnTouch() { + return ptr == crashOnTouchPointer; + } + + private: + void init(T newPtr) { + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); + ptr = newPtr; + if (js::GCMethods::needsPostBarrier(ptr)) + post(); + } + + void post() { +#ifdef JSGC_GENERATIONAL + MOZ_ASSERT(js::GCMethods::needsPostBarrier(ptr)); + js::GCMethods::postBarrier(&ptr); +#endif + } + + void relocate() { +#ifdef JSGC_GENERATIONAL + js::GCMethods::relocate(&ptr); +#endif + } + + enum { + crashOnTouchPointer = 1 + }; + + T ptr; +}; + +#ifdef JS_DEBUG +/* + * For generational GC, assert that an object is in the tenured generation as + * opposed to being in the nursery. + */ +extern JS_FRIEND_API(void) +AssertGCThingMustBeTenured(JSObject* obj); +#else +inline void +AssertGCThingMustBeTenured(JSObject *obj) {} +#endif + +/* + * The TenuredHeap class is similar to the Heap class above in that it + * encapsulates the GC concerns of an on-heap reference to a JS object. However, + * it has two important differences: + * + * 1) Pointers which are statically known to only reference "tenured" objects + * can avoid the extra overhead of SpiderMonkey's write barriers. + * + * 2) Objects in the "tenured" heap have stronger alignment restrictions than + * those in the "nursery", so it is possible to store flags in the lower + * bits of pointers known to be tenured. TenuredHeap wraps a normal tagged + * pointer with a nice API for accessing the flag bits and adds various + * assertions to ensure that it is not mis-used. + * + * GC things are said to be "tenured" when they are located in the long-lived + * heap: e.g. they have gained tenure as an object by surviving past at least + * one GC. For performance, SpiderMonkey allocates some things which are known + * to normally be long lived directly into the tenured generation; for example, + * global objects. Additionally, SpiderMonkey does not visit individual objects + * when deleting non-tenured objects, so object with finalizers are also always + * tenured; for instance, this includes most DOM objects. + * + * The considerations to keep in mind when using a TenuredHeap vs a normal + * Heap are: + * + * - It is invalid for a TenuredHeap to refer to a non-tenured thing. + * - It is however valid for a Heap to refer to a tenured thing. + * - It is not possible to store flag bits in a Heap. + */ +template +class TenuredHeap : public js::HeapBase +{ + public: + TenuredHeap() : bits(0) { + static_assert(sizeof(T) == sizeof(TenuredHeap), + "TenuredHeap must be binary compatible with T."); + } + explicit TenuredHeap(T p) : bits(0) { setPtr(p); } + explicit TenuredHeap(const TenuredHeap &p) : bits(0) { setPtr(p.getPtr()); } + + bool operator==(const TenuredHeap &other) { return bits == other.bits; } + bool operator!=(const TenuredHeap &other) { return bits != other.bits; } + + void setPtr(T newPtr) { + MOZ_ASSERT((reinterpret_cast(newPtr) & flagsMask) == 0); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); + if (newPtr) + AssertGCThingMustBeTenured(newPtr); + bits = (bits & flagsMask) | reinterpret_cast(newPtr); + } + + void setFlags(uintptr_t flagsToSet) { + MOZ_ASSERT((flagsToSet & ~flagsMask) == 0); + bits |= flagsToSet; + } + + void unsetFlags(uintptr_t flagsToUnset) { + MOZ_ASSERT((flagsToUnset & ~flagsMask) == 0); + bits &= ~flagsToUnset; + } + + bool hasFlag(uintptr_t flag) const { + MOZ_ASSERT((flag & ~flagsMask) == 0); + return (bits & flag) != 0; + } + + T getPtr() const { return reinterpret_cast(bits & ~flagsMask); } + uintptr_t getFlags() const { return bits & flagsMask; } + + operator T() const { return getPtr(); } + T operator->() const { return getPtr(); } + + TenuredHeap &operator=(T p) { + setPtr(p); + return *this; + } + + TenuredHeap &operator=(const TenuredHeap& other) { + bits = other.bits; + return *this; + } + + private: + enum { + maskBits = 3, + flagsMask = (1 << maskBits) - 1, + }; + + uintptr_t bits; +}; + +/* + * Reference to a T that has been rooted elsewhere. This is most useful + * as a parameter type, which guarantees that the T lvalue is properly + * rooted. See "Move GC Stack Rooting" above. + * + * If you want to add additional methods to Handle for a specific + * specialization, define a HandleBase specialization containing them. + */ +template +class MOZ_NONHEAP_CLASS Handle : public js::HandleBase +{ + friend class JS::MutableHandle; + + public: + /* Creates a handle from a handle of a type convertible to T. */ + template + Handle(Handle handle, + typename mozilla::EnableIf::value, int>::Type dummy = 0) + { + static_assert(sizeof(Handle) == sizeof(T *), + "Handle must be binary compatible with T*."); + ptr = reinterpret_cast(handle.address()); + } + + /* Create a handle for a nullptr pointer. */ + MOZ_IMPLICIT Handle(js::NullPtr) { + static_assert(mozilla::IsPointer::value, + "js::NullPtr overload not valid for non-pointer types"); + ptr = reinterpret_cast(&js::NullPtr::constNullValue); + } + + /* Create a handle for a nullptr pointer. */ + MOZ_IMPLICIT Handle(JS::NullPtr) { + static_assert(mozilla::IsPointer::value, + "JS::NullPtr overload not valid for non-pointer types"); + ptr = reinterpret_cast(&JS::NullPtr::constNullValue); + } + + MOZ_IMPLICIT Handle(MutableHandle handle) { + ptr = handle.address(); + } + + /* + * Take care when calling this method! + * + * This creates a Handle from the raw location of a T. + * + * It should be called only if the following conditions hold: + * + * 1) the location of the T is guaranteed to be marked (for some reason + * other than being a Rooted), e.g., if it is guaranteed to be reachable + * from an implicit root. + * + * 2) the contents of the location are immutable, or at least cannot change + * for the lifetime of the handle, as its users may not expect its value + * to change underneath them. + */ + static MOZ_CONSTEXPR Handle fromMarkedLocation(const T *p) { + return Handle(p, DeliberatelyChoosingThisOverload, + ImUsingThisOnlyInFromFromMarkedLocation); + } + + /* + * Construct a handle from an explicitly rooted location. This is the + * normal way to create a handle, and normally happens implicitly. + */ + template + inline + Handle(const Rooted &root, + typename mozilla::EnableIf::value, int>::Type dummy = 0); + + template + inline + Handle(const PersistentRooted &root, + typename mozilla::EnableIf::value, int>::Type dummy = 0); + + /* Construct a read only handle from a mutable handle. */ + template + inline + Handle(MutableHandle &root, + typename mozilla::EnableIf::value, int>::Type dummy = 0); + + const T *address() const { return ptr; } + const T& get() const { return *ptr; } + + /* + * Return a reference so passing a Handle to something that + * takes a |const T&| is not a GC hazard. + */ + operator const T&() const { return get(); } + T operator->() const { return get(); } + + bool operator!=(const T &other) const { return *ptr != other; } + bool operator==(const T &other) const { return *ptr == other; } + + private: + Handle() {} + + enum Disambiguator { DeliberatelyChoosingThisOverload = 42 }; + enum CallerIdentity { ImUsingThisOnlyInFromFromMarkedLocation = 17 }; + MOZ_CONSTEXPR Handle(const T *p, Disambiguator, CallerIdentity) : ptr(p) {} + + const T *ptr; + + template void operator=(S) MOZ_DELETE; + void operator=(Handle) MOZ_DELETE; +}; + +/* + * Similar to a handle, but the underlying storage can be changed. This is + * useful for outparams. + * + * If you want to add additional methods to MutableHandle for a specific + * specialization, define a MutableHandleBase specialization containing + * them. + */ +template +class MOZ_STACK_CLASS MutableHandle : public js::MutableHandleBase +{ + public: + inline MOZ_IMPLICIT MutableHandle(Rooted *root); + inline MOZ_IMPLICIT MutableHandle(PersistentRooted *root); + + private: + // Disallow true nullptr and emulated nullptr (gcc 4.4/4.5, __null, appears + // as int/long [32/64-bit]) for overloading purposes. + template + MutableHandle(N, + typename mozilla::EnableIf::value || + mozilla::IsSame::value || + mozilla::IsSame::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + void set(T v) { + MOZ_ASSERT(!js::GCMethods::poisoned(v)); + *ptr = v; + } + + /* + * This may be called only if the location of the T is guaranteed + * to be marked (for some reason other than being a Rooted), + * e.g., if it is guaranteed to be reachable from an implicit root. + * + * Create a MutableHandle from a raw location of a T. + */ + static MutableHandle fromMarkedLocation(T *p) { + MutableHandle h; + h.ptr = p; + return h; + } + + T *address() const { return ptr; } + const T& get() const { return *ptr; } + + /* + * Return a reference so passing a MutableHandle to something that takes + * a |const T&| is not a GC hazard. + */ + operator const T&() const { return get(); } + T operator->() const { return get(); } + + private: + MutableHandle() {} + + T *ptr; + + template void operator=(S v) MOZ_DELETE; + void operator=(MutableHandle other) MOZ_DELETE; +}; + +#ifdef JSGC_GENERATIONAL +JS_FRIEND_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); +JS_FRIEND_API(void) HeapCellRelocate(js::gc::Cell **cellp); +#endif + +} /* namespace JS */ + +namespace js { + +/* + * InternalHandle is a handle to an internal pointer into a gcthing. Use + * InternalHandle when you have a pointer to a direct field of a gcthing, or + * when you need a parameter type for something that *may* be a pointer to a + * direct field of a gcthing. + */ +template +class InternalHandle {}; + +template +class InternalHandle +{ + void * const *holder; + size_t offset; + + public: + /* + * Create an InternalHandle using a Handle to the gcthing containing the + * field in question, and a pointer to the field. + */ + template + InternalHandle(const JS::Handle &handle, T *field) + : holder((void**)handle.address()), offset(uintptr_t(field) - uintptr_t(handle.get())) + {} + + /* + * Create an InternalHandle to a field within a Rooted<>. + */ + template + InternalHandle(const JS::Rooted &root, T *field) + : holder((void**)root.address()), offset(uintptr_t(field) - uintptr_t(root.get())) + {} + + InternalHandle(const InternalHandle& other) + : holder(other.holder), offset(other.offset) {} + + T *get() const { return reinterpret_cast(uintptr_t(*holder) + offset); } + + const T &operator*() const { return *get(); } + T *operator->() const { return get(); } + + static InternalHandle fromMarkedLocation(T *fieldPtr) { + return InternalHandle(fieldPtr); + } + + private: + /* + * Create an InternalHandle to something that is not a pointer to a + * gcthing, and so does not need to be rooted in the first place. Use these + * InternalHandles to pass pointers into functions that also need to accept + * regular InternalHandles to gcthing fields. + * + * Make this private to prevent accidental misuse; this is only for + * fromMarkedLocation(). + */ + explicit InternalHandle(T *field) + : holder(reinterpret_cast(&js::NullPtr::constNullValue)), + offset(uintptr_t(field)) + {} + + void operator=(InternalHandle other) MOZ_DELETE; +}; + +/* + * By default, things should use the inheritance hierarchy to find their + * ThingRootKind. Some pointer types are explicitly set in jspubtd.h so that + * Rooted may be used without the class definition being available. + */ +template +struct RootKind +{ + static ThingRootKind rootKind() { return T::rootKind(); } +}; + +template +struct RootKind +{ + static ThingRootKind rootKind() { return T::rootKind(); } +}; + +template +struct GCMethods +{ + static T *initial() { return nullptr; } + static bool poisoned(T *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(T *v) { return false; } +#ifdef JSGC_GENERATIONAL + static void postBarrier(T **vp) {} + static void relocate(T **vp) {} +#endif +}; + +template <> +struct GCMethods +{ + static JSObject *initial() { return nullptr; } + static bool poisoned(JSObject *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSObject *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSObject **vp) { + JS::HeapCellPostBarrier(reinterpret_cast(vp)); + } + static void relocate(JSObject **vp) { + JS::HeapCellRelocate(reinterpret_cast(vp)); + } +#endif +}; + +template <> +struct GCMethods +{ + static JSFunction *initial() { return nullptr; } + static bool poisoned(JSFunction *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSFunction *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSFunction **vp) { + JS::HeapCellPostBarrier(reinterpret_cast(vp)); + } + static void relocate(JSFunction **vp) { + JS::HeapCellRelocate(reinterpret_cast(vp)); + } +#endif +}; + +#ifdef JS_DEBUG +/* This helper allows us to assert that Rooted is scoped within a request. */ +extern JS_PUBLIC_API(bool) +IsInRequest(JSContext *cx); +#endif + +} /* namespace js */ + +namespace JS { + +/* + * Local variable of type T whose value is always rooted. This is typically + * used for local variables, or for non-rooted values being passed to a + * function that requires a handle, e.g. Foo(Root(cx, x)). + * + * If you want to add additional methods to Rooted for a specific + * specialization, define a RootedBase specialization containing them. + */ +template +class MOZ_STACK_CLASS Rooted : public js::RootedBase +{ + /* Note: CX is a subclass of either ContextFriendFields or PerThreadDataFriendFields. */ + template + void init(CX *cx) { +#ifdef JSGC_TRACK_EXACT_ROOTS + js::ThingRootKind kind = js::RootKind::rootKind(); + this->stack = &cx->thingGCRooters[kind]; + this->prev = *stack; + *stack = reinterpret_cast*>(this); + + MOZ_ASSERT(!js::GCMethods::poisoned(ptr)); +#endif + } + + public: + explicit Rooted(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(js::GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG + MOZ_ASSERT(js::IsInRequest(cx)); +#endif + init(js::ContextFriendFields::get(cx)); + } + + Rooted(JSContext *cx, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG + MOZ_ASSERT(js::IsInRequest(cx)); +#endif + init(js::ContextFriendFields::get(cx)); + } + + explicit Rooted(js::ContextFriendFields *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(js::GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(cx); + } + + Rooted(js::ContextFriendFields *cx, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(cx); + } + + explicit Rooted(js::PerThreadDataFriendFields *pt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(js::GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(pt); + } + + Rooted(js::PerThreadDataFriendFields *pt, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(pt); + } + + explicit Rooted(JSRuntime *rt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(js::GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(js::PerThreadDataFriendFields::getMainThread(rt)); + } + + Rooted(JSRuntime *rt, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(js::PerThreadDataFriendFields::getMainThread(rt)); + } + + // Note that we need to let the compiler generate the default destructor in + // non-exact-rooting builds because of a bug in the instrumented PGO builds + // using MSVC, see bug 915735 for more details. +#ifdef JSGC_TRACK_EXACT_ROOTS + ~Rooted() { + MOZ_ASSERT(*stack == reinterpret_cast*>(this)); + *stack = prev; + } +#endif + +#ifdef JSGC_TRACK_EXACT_ROOTS + Rooted *previous() { return reinterpret_cast*>(prev); } +#endif + + /* + * Important: Return a reference here so passing a Rooted to + * something that takes a |const T&| is not a GC hazard. + */ + operator const T&() const { return ptr; } + T operator->() const { return ptr; } + T *address() { return &ptr; } + const T *address() const { return &ptr; } + T &get() { return ptr; } + const T &get() const { return ptr; } + + T &operator=(T value) { + MOZ_ASSERT(!js::GCMethods::poisoned(value)); + ptr = value; + return ptr; + } + + T &operator=(const Rooted &value) { + ptr = value; + return ptr; + } + + void set(T value) { + MOZ_ASSERT(!js::GCMethods::poisoned(value)); + ptr = value; + } + + bool operator!=(const T &other) const { return ptr != other; } + bool operator==(const T &other) const { return ptr == other; } + + private: +#ifdef JSGC_TRACK_EXACT_ROOTS + /* + * These need to be templated on void* to avoid aliasing issues between, for + * example, Rooted and Rooted, which use the same + * stack head pointer for different classes. + */ + Rooted **stack, *prev; +#endif + + /* + * |ptr| must be the last field in Rooted because the analysis treats all + * Rooted as Rooted during the analysis. See bug 829372. + */ + T ptr; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + Rooted(const Rooted &) MOZ_DELETE; +}; + +} /* namespace JS */ + +namespace js { + +/* + * Augment the generic Rooted interface when T = JSObject* with + * class-querying and downcasting operations. + * + * Given a Rooted obj, one can view + * Handle h = obj.as(); + * as an optimization of + * Rooted rooted(cx, &obj->as()); + * Handle h = rooted; + */ +template <> +class RootedBase +{ + public: + template + JS::Handle as() const; +}; + +/* Interface substitute for Rooted which does not root the variable's memory. */ +template +class FakeRooted : public RootedBase +{ + public: + template + FakeRooted(CX *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + template + FakeRooted(CX *cx, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + operator T() const { return ptr; } + T operator->() const { return ptr; } + T *address() { return &ptr; } + const T *address() const { return &ptr; } + T &get() { return ptr; } + const T &get() const { return ptr; } + + FakeRooted &operator=(T value) { + MOZ_ASSERT(!GCMethods::poisoned(value)); + ptr = value; + return *this; + } + + FakeRooted &operator=(const FakeRooted &other) { + MOZ_ASSERT(!GCMethods::poisoned(other.ptr)); + ptr = other.ptr; + return *this; + } + + bool operator!=(const T &other) const { return ptr != other; } + bool operator==(const T &other) const { return ptr == other; } + + private: + T ptr; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + FakeRooted(const FakeRooted &) MOZ_DELETE; +}; + +/* Interface substitute for MutableHandle which is not required to point to rooted memory. */ +template +class FakeMutableHandle : public js::MutableHandleBase +{ + public: + MOZ_IMPLICIT FakeMutableHandle(T *t) { + ptr = t; + } + + MOZ_IMPLICIT FakeMutableHandle(FakeRooted *root) { + ptr = root->address(); + } + + void set(T v) { + MOZ_ASSERT(!js::GCMethods::poisoned(v)); + *ptr = v; + } + + T *address() const { return ptr; } + T get() const { return *ptr; } + + operator T() const { return get(); } + T operator->() const { return get(); } + + private: + FakeMutableHandle() {} + + T *ptr; + + template + void operator=(S v) MOZ_DELETE; + + void operator=(const FakeMutableHandle& other) MOZ_DELETE; +}; + +/* + * Types for a variable that either should or shouldn't be rooted, depending on + * the template parameter allowGC. Used for implementing functions that can + * operate on either rooted or unrooted data. + * + * The toHandle() and toMutableHandle() functions are for calling functions + * which require handle types and are only called in the CanGC case. These + * allow the calling code to type check. + */ +enum AllowGC { + NoGC = 0, + CanGC = 1 +}; +template +class MaybeRooted +{ +}; + +template class MaybeRooted +{ + public: + typedef JS::Handle HandleType; + typedef JS::Rooted RootType; + typedef JS::MutableHandle MutableHandleType; + + static inline JS::Handle toHandle(HandleType v) { + return v; + } + + static inline JS::MutableHandle toMutableHandle(MutableHandleType v) { + return v; + } +}; + +template class MaybeRooted +{ + public: + typedef T HandleType; + typedef FakeRooted RootType; + typedef FakeMutableHandle MutableHandleType; + + static JS::Handle toHandle(HandleType v) { + MOZ_CRASH("Bad conversion"); + } + + static JS::MutableHandle toMutableHandle(MutableHandleType v) { + MOZ_CRASH("Bad conversion"); + } +}; + +} /* namespace js */ + +namespace JS { + +template template +inline +Handle::Handle(const Rooted &root, + typename mozilla::EnableIf::value, int>::Type dummy) +{ + ptr = reinterpret_cast(root.address()); +} + +template template +inline +Handle::Handle(const PersistentRooted &root, + typename mozilla::EnableIf::value, int>::Type dummy) +{ + ptr = reinterpret_cast(root.address()); +} + +template template +inline +Handle::Handle(MutableHandle &root, + typename mozilla::EnableIf::value, int>::Type dummy) +{ + ptr = reinterpret_cast(root.address()); +} + +template +inline +MutableHandle::MutableHandle(Rooted *root) +{ + static_assert(sizeof(MutableHandle) == sizeof(T *), + "MutableHandle must be binary compatible with T*."); + ptr = root->address(); +} + +template +inline +MutableHandle::MutableHandle(PersistentRooted *root) +{ + static_assert(sizeof(MutableHandle) == sizeof(T *), + "MutableHandle must be binary compatible with T*."); + ptr = root->address(); +} + +/* + * A copyable, assignable global GC root type with arbitrary lifetime, an + * infallible constructor, and automatic unrooting on destruction. + * + * These roots can be used in heap-allocated data structures, so they are not + * associated with any particular JSContext or stack. They are registered with + * the JSRuntime itself, without locking, so they require a full JSContext to be + * constructed, not one of its more restricted superclasses. + * + * Note that you must not use an PersistentRooted in an object owned by a JS + * object: + * + * Whenever one object whose lifetime is decided by the GC refers to another + * such object, that edge must be traced only if the owning JS object is traced. + * This applies not only to JS objects (which obviously are managed by the GC) + * but also to C++ objects owned by JS objects. + * + * If you put a PersistentRooted in such a C++ object, that is almost certainly + * a leak. When a GC begins, the referent of the PersistentRooted is treated as + * live, unconditionally (because a PersistentRooted is a *root*), even if the + * JS object that owns it is unreachable. If there is any path from that + * referent back to the JS object, then the C++ object containing the + * PersistentRooted will not be destructed, and the whole blob of objects will + * not be freed, even if there are no references to them from the outside. + * + * In the context of Firefox, this is a severe restriction: almost everything in + * Firefox is owned by some JS object or another, so using PersistentRooted in + * such objects would introduce leaks. For these kinds of edges, Heap or + * TenuredHeap would be better types. It's up to the implementor of the type + * containing Heap or TenuredHeap members to make sure their referents get + * marked when the object itself is marked. + */ +template +class PersistentRooted : private mozilla::LinkedListElement > { + friend class mozilla::LinkedList; + friend class mozilla::LinkedListElement; + + friend struct js::gc::PersistentRootedMarker; + + void registerWithRuntime(JSRuntime *rt) { + JS::shadow::Runtime *srt = JS::shadow::Runtime::asShadowRuntime(rt); + srt->getPersistentRootedList().insertBack(this); + } + + public: + explicit PersistentRooted(JSContext *cx) : ptr(js::GCMethods::initial()) + { + registerWithRuntime(js::GetRuntime(cx)); + } + + PersistentRooted(JSContext *cx, T initial) : ptr(initial) + { + registerWithRuntime(js::GetRuntime(cx)); + } + + explicit PersistentRooted(JSRuntime *rt) : ptr(js::GCMethods::initial()) + { + registerWithRuntime(rt); + } + + PersistentRooted(JSRuntime *rt, T initial) : ptr(initial) + { + registerWithRuntime(rt); + } + + PersistentRooted(const PersistentRooted &rhs) + : mozilla::LinkedListElement >(), + ptr(rhs.ptr) + { + /* + * Copy construction takes advantage of the fact that the original + * is already inserted, and simply adds itself to whatever list the + * original was on - no JSRuntime pointer needed. + * + * This requires mutating rhs's links, but those should be 'mutable' + * anyway. C++ doesn't let us declare mutable base classes. + */ + const_cast(rhs).setNext(this); + } + + /* + * Important: Return a reference here so passing a Rooted to + * something that takes a |const T&| is not a GC hazard. + */ + operator const T&() const { return ptr; } + T operator->() const { return ptr; } + T *address() { return &ptr; } + const T *address() const { return &ptr; } + T &get() { return ptr; } + const T &get() const { return ptr; } + + T &operator=(T value) { + MOZ_ASSERT(!js::GCMethods::poisoned(value)); + ptr = value; + return ptr; + } + + T &operator=(const PersistentRooted &value) { + ptr = value; + return ptr; + } + + void set(T value) { + MOZ_ASSERT(!js::GCMethods::poisoned(value)); + ptr = value; + } + + bool operator!=(const T &other) const { return ptr != other; } + bool operator==(const T &other) const { return ptr == other; } + + private: + T ptr; +}; + +class JS_PUBLIC_API(ObjectPtr) +{ + Heap value; + + public: + ObjectPtr() : value(nullptr) {} + + explicit ObjectPtr(JSObject *obj) : value(obj) {} + + /* Always call finalize before the destructor. */ + ~ObjectPtr() { MOZ_ASSERT(!value); } + + void finalize(JSRuntime *rt) { + if (IsIncrementalBarrierNeeded(rt)) + IncrementalObjectBarrier(value); + value = nullptr; + } + + void init(JSObject *obj) { value = obj; } + + JSObject *get() const { return value; } + + void writeBarrierPre(JSRuntime *rt) { + IncrementalObjectBarrier(value); + } + + bool isAboutToBeFinalized(); + + ObjectPtr &operator=(JSObject *obj) { + IncrementalObjectBarrier(value); + value = obj; + return *this; + } + + void trace(JSTracer *trc, const char *name); + + JSObject &operator*() const { return *value; } + JSObject *operator->() const { return value; } + operator JSObject *() const { return value; } +}; + +} /* namespace JS */ + +namespace js { + +/* Base class for automatic read-only object rooting during compilation. */ +class CompilerRootNode +{ + protected: + explicit CompilerRootNode(js::gc::Cell *ptr) : next(nullptr), ptr_(ptr) {} + + public: + void **address() { return (void **)&ptr_; } + + public: + CompilerRootNode *next; + + protected: + js::gc::Cell *ptr_; +}; + +} /* namespace js */ + +#endif /* js_RootingAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/SliceBudget.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/SliceBudget.h new file mode 100644 index 0000000000..7c602c5572 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/SliceBudget.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_SliceBudget_h +#define js_SliceBudget_h + +#include + +namespace js { + +/* + * This class records how much work has been done in a given collection slice, so that + * we can return before pausing for too long. Some slices are allowed to run for + * unlimited time, and others are bounded. To reduce the number of gettimeofday + * calls, we only check the time every 1000 operations. + */ +struct JS_PUBLIC_API(SliceBudget) +{ + int64_t deadline; /* in microseconds */ + intptr_t counter; + + static const intptr_t CounterReset = 1000; + + static const int64_t Unlimited = 0; + static int64_t TimeBudget(int64_t millis); + static int64_t WorkBudget(int64_t work); + + /* Equivalent to SliceBudget(UnlimitedBudget). */ + SliceBudget(); + + /* Instantiate as SliceBudget(Time/WorkBudget(n)). */ + explicit SliceBudget(int64_t budget); + + void reset() { + deadline = unlimitedDeadline; + counter = unlimitedStartCounter; + } + + void step(intptr_t amt = 1) { + counter -= amt; + } + + bool checkOverBudget(); + + bool isOverBudget() { + if (counter >= 0) + return false; + return checkOverBudget(); + } + + bool isUnlimited() { + return deadline == unlimitedDeadline; + } + +private: + static const int64_t unlimitedDeadline = INT64_MAX; + static const intptr_t unlimitedStartCounter = INTPTR_MAX; + +}; + +} // namespace js + +#endif /* js_SliceBudget_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/StructuredClone.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/StructuredClone.h new file mode 100644 index 0000000000..fa48ce045a --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/StructuredClone.h @@ -0,0 +1,245 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_StructuredClone_h +#define js_StructuredClone_h + +#include "mozilla/NullPtr.h" + +#include + +#include "jstypes.h" + +#include "js/RootingAPI.h" +#include "js/TypeDecls.h" +#include "js/Value.h" + +struct JSRuntime; +struct JSStructuredCloneReader; +struct JSStructuredCloneWriter; + +// API for the HTML5 internal structured cloning algorithm. + +namespace JS { +enum TransferableOwnership { + // Transferable data has not been filled in yet + SCTAG_TMO_UNFILLED = 0, + + // Structured clone buffer does not yet own the data + SCTAG_TMO_UNOWNED = 1, + + // All values at least this large are owned by the clone buffer + SCTAG_TMO_FIRST_OWNED = 2, + + // Data is a pointer that can be freed + SCTAG_TMO_ALLOC_DATA = 2, + + // Data is a SharedArrayBufferObject's buffer + SCTAG_TMO_SHARED_BUFFER = 3, + + // Data is a memory mapped pointer + SCTAG_TMO_MAPPED_DATA = 4, + + // Data is embedding-specific. The engine can free it by calling the + // freeTransfer op. The embedding can also use SCTAG_TMO_USER_MIN and + // greater, up to 32 bits, to distinguish specific ownership variants. + SCTAG_TMO_CUSTOM = 5, + + SCTAG_TMO_USER_MIN +}; +} /* namespace JS */ + +// Read structured data from the reader r. This hook is used to read a value +// previously serialized by a call to the WriteStructuredCloneOp hook. +// +// tag and data are the pair of uint32_t values from the header. The callback +// may use the JS_Read* APIs to read any other relevant parts of the object +// from the reader r. closure is any value passed to the JS_ReadStructuredClone +// function. Return the new object on success, nullptr on error/exception. +typedef JSObject *(*ReadStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r, + uint32_t tag, uint32_t data, void *closure); + +// Structured data serialization hook. The engine can write primitive values, +// Objects, Arrays, Dates, RegExps, TypedArrays, and ArrayBuffers. Any other +// type of object requires application support. This callback must first use +// the JS_WriteUint32Pair API to write an object header, passing a value +// greater than JS_SCTAG_USER to the tag parameter. Then it can use the +// JS_Write* APIs to write any other relevant parts of the value v to the +// writer w. closure is any value passed to the JS_WriteStructuredCLone function. +// +// Return true on success, false on error/exception. +typedef bool (*WriteStructuredCloneOp)(JSContext *cx, JSStructuredCloneWriter *w, + JS::HandleObject obj, void *closure); + +// This is called when JS_WriteStructuredClone is given an invalid transferable. +// To follow HTML5, the application must throw a DATA_CLONE_ERR DOMException +// with error set to one of the JS_SCERR_* values. +typedef void (*StructuredCloneErrorOp)(JSContext *cx, uint32_t errorid); + +// This is called when JS_ReadStructuredClone receives a transferable object +// not known to the engine. If this hook does not exist or returns false, the +// JS engine calls the reportError op if set, otherwise it throws a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback and must return a non-null object in returnObject on success. +typedef bool (*ReadTransferStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r, + uint32_t tag, void *content, uint64_t extraData, + void *closure, + JS::MutableHandleObject returnObject); + +// Called when JS_WriteStructuredClone receives a transferable object not +// handled by the engine. If this hook does not exist or returns false, the JS +// engine will call the reportError hook or fall back to throwing a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback. +// +// tag: indicates what type of transferable this is. Must be greater than +// 0xFFFF0201 (value of the internal SCTAG_TRANSFER_MAP_PENDING_ENTRY) +// +// ownership: see TransferableOwnership, above. Used to communicate any needed +// ownership info to the FreeTransferStructuredCloneOp. +// +// content, extraData: what the ReadTransferStructuredCloneOp will receive +// +typedef bool (*TransferStructuredCloneOp)(JSContext *cx, + JS::Handle obj, + void *closure, + // Output: + uint32_t *tag, + JS::TransferableOwnership *ownership, + void **content, + uint64_t *extraData); + +// Called when JS_ClearStructuredClone has to free an unknown transferable +// object. Note that it should never trigger a garbage collection (and will +// assert in a debug build if it does.) +typedef void (*FreeTransferStructuredCloneOp)(uint32_t tag, JS::TransferableOwnership ownership, + void *content, uint64_t extraData, void *closure); + +// The maximum supported structured-clone serialization format version. Note +// that this does not need to be bumped for Transferable-only changes, since +// they are never saved to persistent storage. +#define JS_STRUCTURED_CLONE_VERSION 4 + +struct JSStructuredCloneCallbacks { + ReadStructuredCloneOp read; + WriteStructuredCloneOp write; + StructuredCloneErrorOp reportError; + ReadTransferStructuredCloneOp readTransfer; + TransferStructuredCloneOp writeTransfer; + FreeTransferStructuredCloneOp freeTransfer; +}; + +// Note: if the *data contains transferable objects, it can be read only once. +JS_PUBLIC_API(bool) +JS_ReadStructuredClone(JSContext *cx, uint64_t *data, size_t nbytes, uint32_t version, + JS::MutableHandleValue vp, + const JSStructuredCloneCallbacks *optionalCallbacks, void *closure); + +// Note: On success, the caller is responsible for calling +// JS_ClearStructuredClone(*datap, nbytes, optionalCallbacks, closure). +JS_PUBLIC_API(bool) +JS_WriteStructuredClone(JSContext *cx, JS::HandleValue v, uint64_t **datap, size_t *nbytesp, + const JSStructuredCloneCallbacks *optionalCallbacks, + void *closure, JS::HandleValue transferable); + +JS_PUBLIC_API(bool) +JS_ClearStructuredClone(uint64_t *data, size_t nbytes, + const JSStructuredCloneCallbacks *optionalCallbacks, + void *closure); + +JS_PUBLIC_API(bool) +JS_StructuredCloneHasTransferables(const uint64_t *data, size_t nbytes, bool *hasTransferable); + +JS_PUBLIC_API(bool) +JS_StructuredClone(JSContext *cx, JS::HandleValue v, JS::MutableHandleValue vp, + const JSStructuredCloneCallbacks *optionalCallbacks, void *closure); + +// RAII sugar for JS_WriteStructuredClone. +class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) { + uint64_t *data_; + size_t nbytes_; + uint32_t version_; + const JSStructuredCloneCallbacks *callbacks_; + void *closure_; + + public: + JSAutoStructuredCloneBuffer() + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(nullptr), closure_(nullptr) + {} + + JSAutoStructuredCloneBuffer(const JSStructuredCloneCallbacks *callbacks, void *closure) + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(callbacks), closure_(closure) + {} + + JSAutoStructuredCloneBuffer(JSAutoStructuredCloneBuffer &&other); + JSAutoStructuredCloneBuffer &operator=(JSAutoStructuredCloneBuffer &&other); + + ~JSAutoStructuredCloneBuffer() { clear(); } + + uint64_t *data() const { return data_; } + size_t nbytes() const { return nbytes_; } + + void clear(); + + // Copy some memory. It will be automatically freed by the destructor. + bool copy(const uint64_t *data, size_t nbytes, uint32_t version=JS_STRUCTURED_CLONE_VERSION); + + // Adopt some memory. It will be automatically freed by the destructor. + // data must have been allocated by the JS engine (e.g., extracted via + // JSAutoStructuredCloneBuffer::steal). + void adopt(uint64_t *data, size_t nbytes, uint32_t version=JS_STRUCTURED_CLONE_VERSION); + + // Remove the buffer so that it will not be automatically freed. + // After this, the caller is responsible for feeding the memory back to + // JSAutoStructuredCloneBuffer::adopt. + void steal(uint64_t **datap, size_t *nbytesp, uint32_t *versionp=nullptr); + + bool read(JSContext *cx, JS::MutableHandleValue vp, + const JSStructuredCloneCallbacks *optionalCallbacks=nullptr, void *closure=nullptr); + + bool write(JSContext *cx, JS::HandleValue v, + const JSStructuredCloneCallbacks *optionalCallbacks=nullptr, void *closure=nullptr); + + bool write(JSContext *cx, JS::HandleValue v, JS::HandleValue transferable, + const JSStructuredCloneCallbacks *optionalCallbacks=nullptr, void *closure=nullptr); + + private: + // Copy and assignment are not supported. + JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; + JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; +}; + +// The range of tag values the application may use for its own custom object types. +#define JS_SCTAG_USER_MIN ((uint32_t) 0xFFFF8000) +#define JS_SCTAG_USER_MAX ((uint32_t) 0xFFFFFFFF) + +#define JS_SCERR_RECURSION 0 +#define JS_SCERR_TRANSFERABLE 1 + +JS_PUBLIC_API(void) +JS_SetStructuredCloneCallbacks(JSRuntime *rt, const JSStructuredCloneCallbacks *callbacks); + +JS_PUBLIC_API(bool) +JS_ReadUint32Pair(JSStructuredCloneReader *r, uint32_t *p1, uint32_t *p2); + +JS_PUBLIC_API(bool) +JS_ReadBytes(JSStructuredCloneReader *r, void *p, size_t len); + +JS_PUBLIC_API(bool) +JS_ReadTypedArray(JSStructuredCloneReader *r, JS::MutableHandleValue vp); + +JS_PUBLIC_API(bool) +JS_WriteUint32Pair(JSStructuredCloneWriter *w, uint32_t tag, uint32_t data); + +JS_PUBLIC_API(bool) +JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len); + +JS_PUBLIC_API(bool) +JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::HandleValue v); + +#endif /* js_StructuredClone_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/TracingAPI.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/TracingAPI.h new file mode 100644 index 0000000000..3c7fdbe1b1 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/TracingAPI.h @@ -0,0 +1,216 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_TracingAPI_h +#define js_TracingAPI_h + +#include "mozilla/NullPtr.h" + +#include "jspubtd.h" + +class JS_PUBLIC_API(JSTracer); + +namespace JS { +template class Heap; +template class TenuredHeap; +} + +// Tracer callback, called for each traceable thing directly referenced by a +// particular object or runtime structure. It is the callback responsibility +// to ensure the traversal of the full object graph via calling eventually +// JS_TraceChildren on the passed thing. In this case the callback must be +// prepared to deal with cycles in the traversal graph. +// +// kind argument is one of JSTRACE_OBJECT, JSTRACE_STRING or a tag denoting +// internal implementation-specific traversal kind. In the latter case the only +// operations on thing that the callback can do is to call JS_TraceChildren or +// JS_GetTraceThingInfo. +// +// If eagerlyTraceWeakMaps is true, when we trace a WeakMap visit all +// of its mappings. This should be used in cases where the tracer +// wants to use the existing liveness of entries. +typedef void +(* JSTraceCallback)(JSTracer *trc, void **thingp, JSGCTraceKind kind); + +// Callback that JSTraceOp implementation can provide to return a string +// describing the reference traced with JS_CallTracer. +typedef void +(* JSTraceNamePrinter)(JSTracer *trc, char *buf, size_t bufsize); + +enum WeakMapTraceKind { + DoNotTraceWeakMaps = 0, + TraceWeakMapValues = 1, + TraceWeakMapKeysValues = 2 +}; + +class JS_PUBLIC_API(JSTracer) +{ + public: + JSTracer(JSRuntime *rt, JSTraceCallback traceCallback, + WeakMapTraceKind weakTraceKind = TraceWeakMapValues); + + // Set debugging information about a reference to a traceable thing to prepare + // for the following call to JS_CallTracer. + // + // When printer is null, arg must be const char * or char * C string naming + // the reference and index must be either (size_t)-1 indicating that the name + // alone describes the reference or it must be an index into some array vector + // that stores the reference. + // + // When printer callback is not null, the arg and index arguments are + // available to the callback as debugPrintArg_ and debugPrintIndex_ fields + // of JSTracer. + // + // The storage for name or callback's arguments needs to live only until + // the following call to JS_CallTracer returns. + void setTracingDetails(JSTraceNamePrinter printer, const void *arg, size_t index) { + debugPrinter_ = printer; + debugPrintArg_ = arg; + debugPrintIndex_ = index; + } + + void setTracingIndex(const char *name, size_t index) { + setTracingDetails(nullptr, (void *)name, index); + } + + void setTracingName(const char *name) { + setTracingDetails(nullptr, (void *)name, size_t(-1)); + } + + // Remove the currently set tracing details. + void clearTracingDetails() { + debugPrinter_ = nullptr; + debugPrintArg_ = nullptr; + } + + // Return true if tracing details are currently set. + bool hasTracingDetails() const; + + // Get the string set with the most recent call to setTracingName or return + // fallback if a name printer function has been installed. + const char *tracingName(const char *fallback) const; + + // Build a description of this edge in the heap graph. This call may invoke + // the debug printer, which may inspect arbitrary areas of the heap. + const char *getTracingEdgeName(char *buffer, size_t bufferSize); + + // Access the currently active tracing details. + JSTraceNamePrinter debugPrinter() const; + const void *debugPrintArg() const; + size_t debugPrintIndex() const; + + // Return the runtime set on the tracer. + JSRuntime *runtime() const { return runtime_; } + + // Return the weak map tracing behavior set on this tracer. + WeakMapTraceKind eagerlyTraceWeakMaps() const { return eagerlyTraceWeakMaps_; } + + // Update the trace callback. + void setTraceCallback(JSTraceCallback traceCallback); + +#ifdef JS_GC_ZEAL + // Sets the "real" location for a marked reference, when passing the address + // directly is not feasable. This address is used for matching against the + // store buffer when verifying the correctness of the entrees there. + // + // This is currently complicated by our need to nest calls for Values + // stored as keys in hash tables. + void setTracingLocation(void *location); + void unsetTracingLocation(); + void **tracingLocation(void **thingp); +#else + void setTracingLocation(void *location) {} + void unsetTracingLocation() {} + void **tracingLocation(void **thingp) { return nullptr; } +#endif + + // We expose |callback| directly so that IS_GC_MARKING_TRACER can compare + // it to GCMarker::GrayCallback. + JSTraceCallback callback; + + private: + JSRuntime *runtime_; + JSTraceNamePrinter debugPrinter_; + const void *debugPrintArg_; + size_t debugPrintIndex_; + WeakMapTraceKind eagerlyTraceWeakMaps_; +#ifdef JS_GC_ZEAL + void *realLocation_; +#endif +}; + +// The JS_Call*Tracer family of functions traces the given GC thing reference. +// This performs the tracing action configured on the given JSTracer: +// typically calling the JSTracer::callback or marking the thing as live. +// +// The argument to JS_Call*Tracer is an in-out param: when the function +// returns, the garbage collector might have moved the GC thing. In this case, +// the reference passed to JS_Call*Tracer will be updated to the object's new +// location. Callers of this method are responsible for updating any state +// that is dependent on the object's address. For example, if the object's +// address is used as a key in a hashtable, then the object must be removed +// and re-inserted with the correct hash. +// +extern JS_PUBLIC_API(void) +JS_CallValueTracer(JSTracer *trc, JS::Value *valuep, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallIdTracer(JSTracer *trc, jsid *idp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallObjectTracer(JSTracer *trc, JSObject **objp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallStringTracer(JSTracer *trc, JSString **strp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallScriptTracer(JSTracer *trc, JSScript **scriptp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapValueTracer(JSTracer *trc, JS::Heap *valuep, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapIdTracer(JSTracer *trc, JS::Heap *idp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapObjectTracer(JSTracer *trc, JS::Heap *objp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapStringTracer(JSTracer *trc, JS::Heap *strp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapScriptTracer(JSTracer *trc, JS::Heap *scriptp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapFunctionTracer(JSTracer *trc, JS::Heap *funp, const char *name); + +template +inline void +JS_CallHashSetObjectTracer(JSTracer *trc, HashSetEnum &e, JSObject *const &key, const char *name) +{ + JSObject *updated = key; + trc->setTracingLocation(reinterpret_cast(&const_cast(key))); + JS_CallObjectTracer(trc, &updated, name); + if (updated != key) + e.rekeyFront(key, updated); +} + +// Trace an object that is known to always be tenured. No post barriers are +// required in this case. +extern JS_PUBLIC_API(void) +JS_CallTenuredObjectTracer(JSTracer *trc, JS::TenuredHeap *objp, const char *name); + +extern JS_PUBLIC_API(void) +JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind); + +extern JS_PUBLIC_API(void) +JS_TraceRuntime(JSTracer *trc); + +extern JS_PUBLIC_API(void) +JS_GetTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc, + void *thing, JSGCTraceKind kind, bool includeDetails); + +#endif /* js_TracingAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/TypeDecls.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/TypeDecls.h new file mode 100644 index 0000000000..2a8234218c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/TypeDecls.h @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This file contains public type declarations that are used *frequently*. If +// it doesn't occur at least 10 times in Gecko, it probably shouldn't be in +// here. +// +// It includes only: +// - forward declarations of structs and classes; +// - typedefs; +// - enums (maybe). +// It does *not* contain any struct or class definitions. + +#ifndef js_TypeDecls_h +#define js_TypeDecls_h + +#include +#include + +#include "js-config.h" +#include "mozilla/Char16.h" + +struct JSContext; +class JSFunction; +class JSObject; +class JSScript; +class JSString; +class JSAddonId; + +struct jsid; + +typedef char16_t jschar; + +namespace JS { + +typedef unsigned char Latin1Char; + +class Symbol; +class Value; +template class Handle; +template class MutableHandle; +template class Rooted; +template class PersistentRooted; + +typedef Handle HandleFunction; +typedef Handle HandleId; +typedef Handle HandleObject; +typedef Handle HandleScript; +typedef Handle HandleString; +typedef Handle HandleSymbol; +typedef Handle HandleValue; + +typedef MutableHandle MutableHandleFunction; +typedef MutableHandle MutableHandleId; +typedef MutableHandle MutableHandleObject; +typedef MutableHandle MutableHandleScript; +typedef MutableHandle MutableHandleString; +typedef MutableHandle MutableHandleSymbol; +typedef MutableHandle MutableHandleValue; + +typedef Rooted RootedObject; +typedef Rooted RootedFunction; +typedef Rooted RootedScript; +typedef Rooted RootedString; +typedef Rooted RootedSymbol; +typedef Rooted RootedId; +typedef Rooted RootedValue; + +typedef PersistentRooted PersistentRootedFunction; +typedef PersistentRooted PersistentRootedId; +typedef PersistentRooted PersistentRootedObject; +typedef PersistentRooted PersistentRootedScript; +typedef PersistentRooted PersistentRootedString; +typedef PersistentRooted PersistentRootedSymbol; +typedef PersistentRooted PersistentRootedValue; + +} // namespace JS + +#endif /* js_TypeDecls_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Utility.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Utility.h new file mode 100644 index 0000000000..89c495e411 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Utility.h @@ -0,0 +1,736 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_Utility_h +#define js_Utility_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/Scoped.h" +#include "mozilla/TemplateLib.h" + +#include +#include + +#ifdef JS_OOM_DO_BACKTRACES +#include +#include +#endif + +#include "jstypes.h" + +/* The public JS engine namespace. */ +namespace JS {} + +/* The mozilla-shared reusable template/utility namespace. */ +namespace mozilla {} + +/* The private JS engine namespace. */ +namespace js {} + +/* + * Patterns used by SpiderMonkey to overwrite unused memory. If you are + * accessing an object with one of these pattern, you probably have a dangling + * pointer. + */ +#define JS_FRESH_NURSERY_PATTERN 0x2F +#define JS_SWEPT_NURSERY_PATTERN 0x2B +#define JS_ALLOCATED_NURSERY_PATTERN 0x2D +#define JS_FRESH_TENURED_PATTERN 0x4F +#define JS_SWEPT_TENURED_PATTERN 0x4B +#define JS_ALLOCATED_TENURED_PATTERN 0x4D +#define JS_SWEPT_CODE_PATTERN 0x3b +#define JS_SWEPT_FRAME_PATTERN 0x5b +#define JS_POISONED_FORKJOIN_CHUNK 0xBD + +#define JS_ASSERT(expr) MOZ_ASSERT(expr) +#define JS_ASSERT_IF(cond, expr) MOZ_ASSERT_IF(cond, expr) + +#define JS_STATIC_ASSERT(cond) static_assert(cond, "JS_STATIC_ASSERT") +#define JS_STATIC_ASSERT_IF(cond, expr) MOZ_STATIC_ASSERT_IF(cond, expr, "JS_STATIC_ASSERT_IF") + +extern MOZ_NORETURN JS_PUBLIC_API(void) +JS_Assert(const char *s, const char *file, int ln); + +/* + * Custom allocator support for SpiderMonkey + */ +#if defined JS_USE_CUSTOM_ALLOCATOR +# include "jscustomallocator.h" +#else +# if defined(DEBUG) || defined(JS_OOM_BREAKPOINT) +/* + * In order to test OOM conditions, when the testing function + * oomAfterAllocations COUNT is passed, we fail continuously after the NUM'th + * allocation from now. + */ +extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtin/TestingFunctions.cpp */ +extern JS_PUBLIC_DATA(uint32_t) OOM_counter; /* data race, who cares. */ + +#ifdef JS_OOM_BREAKPOINT +static MOZ_NEVER_INLINE void js_failedAllocBreakpoint() { asm(""); } +#define JS_OOM_CALL_BP_FUNC() js_failedAllocBreakpoint() +#else +#define JS_OOM_CALL_BP_FUNC() do {} while(0) +#endif + +# define JS_OOM_POSSIBLY_FAIL() \ + do \ + { \ + if (++OOM_counter > OOM_maxAllocations) { \ + JS_OOM_CALL_BP_FUNC();\ + return nullptr; \ + } \ + } while (0) + +# else +# define JS_OOM_POSSIBLY_FAIL() do {} while(0) +# endif /* DEBUG || JS_OOM_BREAKPOINT */ + +static inline void* js_malloc(size_t bytes) +{ + JS_OOM_POSSIBLY_FAIL(); + return malloc(bytes); +} + +static inline void* js_calloc(size_t bytes) +{ + JS_OOM_POSSIBLY_FAIL(); + return calloc(bytes, 1); +} + +static inline void* js_calloc(size_t nmemb, size_t size) +{ + JS_OOM_POSSIBLY_FAIL(); + return calloc(nmemb, size); +} + +static inline void* js_realloc(void* p, size_t bytes) +{ + JS_OOM_POSSIBLY_FAIL(); + return realloc(p, bytes); +} + +static inline void js_free(void* p) +{ + free(p); +} +#endif/* JS_USE_CUSTOM_ALLOCATOR */ + +#include + +/* + * Low-level memory management in SpiderMonkey: + * + * ** Do not use the standard malloc/free/realloc: SpiderMonkey allows these + * to be redefined (via JS_USE_CUSTOM_ALLOCATOR) and Gecko even #define's + * these symbols. + * + * ** Do not use the builtin C++ operator new and delete: these throw on + * error and we cannot override them not to. + * + * Allocation: + * + * - If the lifetime of the allocation is tied to the lifetime of a GC-thing + * (that is, finalizing the GC-thing will free the allocation), call one of + * the following functions: + * + * JSContext::{malloc_,realloc_,calloc_,new_} + * JSRuntime::{malloc_,realloc_,calloc_,new_} + * + * These functions accumulate the number of bytes allocated which is used as + * part of the GC-triggering heuristic. + * + * The difference between the JSContext and JSRuntime versions is that the + * cx version reports an out-of-memory error on OOM. (This follows from the + * general SpiderMonkey idiom that a JSContext-taking function reports its + * own errors.) + * + * - Otherwise, use js_malloc/js_realloc/js_calloc/js_free/js_new + * + * Deallocation: + * + * - Ordinarily, use js_free/js_delete. + * + * - For deallocations during GC finalization, use one of the following + * operations on the FreeOp provided to the finalizer: + * + * FreeOp::{free_,delete_} + * + * The advantage of these operations is that the memory is batched and freed + * on another thread. + */ + +#define JS_NEW_BODY(allocator, t, parms) \ + void *memory = allocator(sizeof(t)); \ + return memory ? new(memory) t parms : nullptr; +#define JS_MAKE_BODY(newname, T, parms) \ + T *ptr = newname parms; \ + return mozilla::UniquePtr>(ptr); + +/* + * Given a class which should provide 'new' methods, add + * JS_DECLARE_NEW_METHODS (see JSContext for a usage example). This + * adds news with up to 12 parameters. Add more versions of new below if + * you need more than 12 parameters. + * + * Note: Do not add a ; at the end of a use of JS_DECLARE_NEW_METHODS, + * or the build will break. + */ +#define JS_DECLARE_NEW_METHODS(NEWNAME, ALLOCATOR, QUALIFIERS)\ + template \ + QUALIFIERS T *NEWNAME() MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T, ())\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11, P12 &&p12) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11),\ + mozilla::Forward(p12)))\ + }\ + +/* + * Given a class which should provide 'make' methods, add + * JS_DECLARE_MAKE_METHODS (see JSContext for a usage example). This method + * is functionally the same as JS_DECLARE_NEW_METHODS: it just declares methods + * that return mozilla::UniquePtr instances that will singly-manage ownership + * of the created object. This adds makes with up to 12 parameters. Add more + * versions below if you need more than 12 parameters. + * + * Note: Do not add a ; at the end of a use of JS_DECLARE_MAKE_METHODS, + * or the build will break. + */ +#define JS_DECLARE_MAKE_METHODS(MAKENAME, NEWNAME, QUALIFIERS)\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME() MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T, ())\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1)))\ + }\ +\ + template \ + QUALIFIERS \ +mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11, P12 &&p12) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11),\ + mozilla::Forward(p12)))\ + }\ + +JS_DECLARE_NEW_METHODS(js_new, js_malloc, static MOZ_ALWAYS_INLINE) + +template +static MOZ_ALWAYS_INLINE void +js_delete(T *p) +{ + if (p) { + p->~T(); + js_free(p); + } +} + +template +static MOZ_ALWAYS_INLINE void +js_delete_poison(T *p) +{ + if (p) { + p->~T(); + memset(p, 0x3B, sizeof(T)); + js_free(p); + } +} + +template +static MOZ_ALWAYS_INLINE T * +js_pod_malloc() +{ + return (T *)js_malloc(sizeof(T)); +} + +template +static MOZ_ALWAYS_INLINE T * +js_pod_calloc() +{ + return (T *)js_calloc(sizeof(T)); +} + +template +static MOZ_ALWAYS_INLINE T * +js_pod_malloc(size_t numElems) +{ + if (numElems & mozilla::tl::MulOverflowMask::value) + return nullptr; + return (T *)js_malloc(numElems * sizeof(T)); +} + +template +static MOZ_ALWAYS_INLINE T * +js_pod_calloc(size_t numElems) +{ + if (numElems & mozilla::tl::MulOverflowMask::value) + return nullptr; + return (T *)js_calloc(numElems * sizeof(T)); +} + +namespace js { + +template +struct ScopedFreePtrTraits +{ + typedef T* type; + static T* empty() { return nullptr; } + static void release(T* ptr) { js_free(ptr); } +}; +SCOPED_TEMPLATE(ScopedJSFreePtr, ScopedFreePtrTraits) + +template +struct ScopedDeletePtrTraits : public ScopedFreePtrTraits +{ + static void release(T *ptr) { js_delete(ptr); } +}; +SCOPED_TEMPLATE(ScopedJSDeletePtr, ScopedDeletePtrTraits) + +template +struct ScopedReleasePtrTraits : public ScopedFreePtrTraits +{ + static void release(T *ptr) { if (ptr) ptr->release(); } +}; +SCOPED_TEMPLATE(ScopedReleasePtr, ScopedReleasePtrTraits) + +} /* namespace js */ + +namespace JS { + +template +struct DeletePolicy +{ + void operator()(T* ptr) { + js_delete(ptr); + } +}; + +struct FreePolicy +{ + void operator()(void* ptr) { + js_free(ptr); + } +}; + +} // namespace JS + +namespace js { + +/* Integral types for all hash functions. */ +typedef uint32_t HashNumber; +const unsigned HashNumberSizeBits = 32; + +namespace detail { + +/* + * Given a raw hash code, h, return a number that can be used to select a hash + * bucket. + * + * This function aims to produce as uniform an output distribution as possible, + * especially in the most significant (leftmost) bits, even though the input + * distribution may be highly nonrandom, given the constraints that this must + * be deterministic and quick to compute. + * + * Since the leftmost bits of the result are best, the hash bucket index is + * computed by doing ScrambleHashCode(h) / (2^32/N) or the equivalent + * right-shift, not ScrambleHashCode(h) % N or the equivalent bit-mask. + * + * FIXME: OrderedHashTable uses a bit-mask; see bug 775896. + */ +inline HashNumber +ScrambleHashCode(HashNumber h) +{ + /* + * Simply returning h would not cause any hash tables to produce wrong + * answers. But it can produce pathologically bad performance: The caller + * right-shifts the result, keeping only the highest bits. The high bits of + * hash codes are very often completely entropy-free. (So are the lowest + * bits.) + * + * So we use Fibonacci hashing, as described in Knuth, The Art of Computer + * Programming, 6.4. This mixes all the bits of the input hash code h. + * + * The value of goldenRatio is taken from the hex + * expansion of the golden ratio, which starts 1.9E3779B9.... + * This value is especially good if values with consecutive hash codes + * are stored in a hash table; see Knuth for details. + */ + static const HashNumber goldenRatio = 0x9E3779B9U; + return h * goldenRatio; +} + +} /* namespace detail */ + +} /* namespace js */ + +namespace JS { + +/* + * Methods for poisoning GC heap pointer words and checking for poisoned words. + * These are in this file for use in Value methods and so forth. + * + * If the moving GC hazard analysis is in use and detects a non-rooted stack + * pointer to a GC thing, one byte of that pointer is poisoned to refer to an + * invalid location. For both 32 bit and 64 bit systems, the fourth byte of the + * pointer is overwritten, to reduce the likelihood of accidentally changing + * a live integer value. + */ + +inline void PoisonPtr(void *v) +{ +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) + uint8_t *ptr = (uint8_t *) v + 3; + *ptr = JS_FREE_PATTERN; +#endif +} + +template +inline bool IsPoisonedPtr(T *v) +{ +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) + uint32_t mask = uintptr_t(v) & 0xff000000; + return mask == uint32_t(JS_FREE_PATTERN << 24); +#else + return false; +#endif +} + +} + +/* sixgill annotation defines */ +#ifndef HAVE_STATIC_ANNOTATIONS +# define HAVE_STATIC_ANNOTATIONS +# ifdef XGILL_PLUGIN +# define STATIC_PRECONDITION(COND) __attribute__((precondition(#COND))) +# define STATIC_PRECONDITION_ASSUME(COND) __attribute__((precondition_assume(#COND))) +# define STATIC_POSTCONDITION(COND) __attribute__((postcondition(#COND))) +# define STATIC_POSTCONDITION_ASSUME(COND) __attribute__((postcondition_assume(#COND))) +# define STATIC_INVARIANT(COND) __attribute__((invariant(#COND))) +# define STATIC_INVARIANT_ASSUME(COND) __attribute__((invariant_assume(#COND))) +# define STATIC_PASTE2(X,Y) X ## Y +# define STATIC_PASTE1(X,Y) STATIC_PASTE2(X,Y) +# define STATIC_ASSERT(COND) \ + JS_BEGIN_MACRO \ + __attribute__((assert_static(#COND), unused)) \ + int STATIC_PASTE1(assert_static_, __COUNTER__); \ + JS_END_MACRO +# define STATIC_ASSUME(COND) \ + JS_BEGIN_MACRO \ + __attribute__((assume_static(#COND), unused)) \ + int STATIC_PASTE1(assume_static_, __COUNTER__); \ + JS_END_MACRO +# define STATIC_ASSERT_RUNTIME(COND) \ + JS_BEGIN_MACRO \ + __attribute__((assert_static_runtime(#COND), unused)) \ + int STATIC_PASTE1(assert_static_runtime_, __COUNTER__); \ + JS_END_MACRO +# else /* XGILL_PLUGIN */ +# define STATIC_PRECONDITION(COND) /* nothing */ +# define STATIC_PRECONDITION_ASSUME(COND) /* nothing */ +# define STATIC_POSTCONDITION(COND) /* nothing */ +# define STATIC_POSTCONDITION_ASSUME(COND) /* nothing */ +# define STATIC_INVARIANT(COND) /* nothing */ +# define STATIC_INVARIANT_ASSUME(COND) /* nothing */ +# define STATIC_ASSERT(COND) JS_BEGIN_MACRO /* nothing */ JS_END_MACRO +# define STATIC_ASSUME(COND) JS_BEGIN_MACRO /* nothing */ JS_END_MACRO +# define STATIC_ASSERT_RUNTIME(COND) JS_BEGIN_MACRO /* nothing */ JS_END_MACRO +# endif /* XGILL_PLUGIN */ +# define STATIC_SKIP_INFERENCE STATIC_INVARIANT(skip_inference()) +#endif /* HAVE_STATIC_ANNOTATIONS */ + +#endif /* js_Utility_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Value.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Value.h new file mode 100644 index 0000000000..e7b89e684d --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Value.h @@ -0,0 +1,2003 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JS::Value implementation. */ + +#ifndef js_Value_h +#define js_Value_h + +#include "mozilla/Attributes.h" +#include "mozilla/FloatingPoint.h" +#include "mozilla/Likely.h" + +#include /* for std::numeric_limits */ + +#include "js-config.h" +#include "jstypes.h" + +#include "js/Anchor.h" +#include "js/GCAPI.h" +#include "js/RootingAPI.h" +#include "js/Utility.h" + +namespace JS { class Value; } + +/* JS::Value can store a full int32_t. */ +#define JSVAL_INT_BITS 32 +#define JSVAL_INT_MIN ((int32_t)0x80000000) +#define JSVAL_INT_MAX ((int32_t)0x7fffffff) + +/* + * Try to get jsvals 64-bit aligned. We could almost assert that all values are + * aligned, but MSVC and GCC occasionally break alignment. + */ +#if defined(__GNUC__) || defined(__xlc__) || defined(__xlC__) +# define JSVAL_ALIGNMENT __attribute__((aligned (8))) +#elif defined(_MSC_VER) + /* + * Structs can be aligned with MSVC, but not if they are used as parameters, + * so we just don't try to align. + */ +# define JSVAL_ALIGNMENT +#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) +# define JSVAL_ALIGNMENT +#elif defined(__HP_cc) || defined(__HP_aCC) +# define JSVAL_ALIGNMENT +#endif + +#if defined(JS_PUNBOX64) +# define JSVAL_TAG_SHIFT 47 +#endif + +/* + * We try to use enums so that printing a jsval_layout in the debugger shows + * nice symbolic type tags, however we can only do this when we can force the + * underlying type of the enum to be the desired size. + */ +#if !defined(__SUNPRO_CC) && !defined(__xlC__) + +#if defined(_MSC_VER) +# define JS_ENUM_HEADER(id, type) enum id : type +# define JS_ENUM_FOOTER(id) +#else +# define JS_ENUM_HEADER(id, type) enum id +# define JS_ENUM_FOOTER(id) __attribute__((packed)) +#endif + +/* Remember to propagate changes to the C defines below. */ +JS_ENUM_HEADER(JSValueType, uint8_t) +{ + JSVAL_TYPE_DOUBLE = 0x00, + JSVAL_TYPE_INT32 = 0x01, + JSVAL_TYPE_UNDEFINED = 0x02, + JSVAL_TYPE_BOOLEAN = 0x03, + JSVAL_TYPE_MAGIC = 0x04, + JSVAL_TYPE_STRING = 0x05, + JSVAL_TYPE_SYMBOL = 0x06, + JSVAL_TYPE_NULL = 0x07, + JSVAL_TYPE_OBJECT = 0x08, + + /* These never appear in a jsval; they are only provided as an out-of-band value. */ + JSVAL_TYPE_UNKNOWN = 0x20, + JSVAL_TYPE_MISSING = 0x21 +} JS_ENUM_FOOTER(JSValueType); + +JS_STATIC_ASSERT(sizeof(JSValueType) == 1); + +#if defined(JS_NUNBOX32) + +/* Remember to propagate changes to the C defines below. */ +JS_ENUM_HEADER(JSValueTag, uint32_t) +{ + JSVAL_TAG_CLEAR = 0xFFFFFF80, + JSVAL_TAG_INT32 = JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32, + JSVAL_TAG_UNDEFINED = JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED, + JSVAL_TAG_STRING = JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL, + JSVAL_TAG_BOOLEAN = JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN, + JSVAL_TAG_MAGIC = JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC, + JSVAL_TAG_NULL = JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL, + JSVAL_TAG_OBJECT = JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT +} JS_ENUM_FOOTER(JSValueTag); + +JS_STATIC_ASSERT(sizeof(JSValueTag) == 4); + +#elif defined(JS_PUNBOX64) + +/* Remember to propagate changes to the C defines below. */ +JS_ENUM_HEADER(JSValueTag, uint32_t) +{ + JSVAL_TAG_MAX_DOUBLE = 0x1FFF0, + JSVAL_TAG_INT32 = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32, + JSVAL_TAG_UNDEFINED = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED, + JSVAL_TAG_STRING = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL, + JSVAL_TAG_BOOLEAN = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN, + JSVAL_TAG_MAGIC = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC, + JSVAL_TAG_NULL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL, + JSVAL_TAG_OBJECT = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_OBJECT +} JS_ENUM_FOOTER(JSValueTag); + +JS_STATIC_ASSERT(sizeof(JSValueTag) == sizeof(uint32_t)); + +JS_ENUM_HEADER(JSValueShiftedTag, uint64_t) +{ + JSVAL_SHIFTED_TAG_MAX_DOUBLE = ((((uint64_t)JSVAL_TAG_MAX_DOUBLE) << JSVAL_TAG_SHIFT) | 0xFFFFFFFF), + JSVAL_SHIFTED_TAG_INT32 = (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_UNDEFINED = (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_STRING = (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_SYMBOL = (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_BOOLEAN = (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_MAGIC = (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_NULL = (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_OBJECT = (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT) +} JS_ENUM_FOOTER(JSValueShiftedTag); + +JS_STATIC_ASSERT(sizeof(JSValueShiftedTag) == sizeof(uint64_t)); + +#endif + +#else /* !defined(__SUNPRO_CC) && !defined(__xlC__) */ + +typedef uint8_t JSValueType; +#define JSVAL_TYPE_DOUBLE ((uint8_t)0x00) +#define JSVAL_TYPE_INT32 ((uint8_t)0x01) +#define JSVAL_TYPE_UNDEFINED ((uint8_t)0x02) +#define JSVAL_TYPE_BOOLEAN ((uint8_t)0x03) +#define JSVAL_TYPE_MAGIC ((uint8_t)0x04) +#define JSVAL_TYPE_STRING ((uint8_t)0x05) +#define JSVAL_TYPE_SYMBOL ((uint8_t)0x06) +#define JSVAL_TYPE_NULL ((uint8_t)0x07) +#define JSVAL_TYPE_OBJECT ((uint8_t)0x08) +#define JSVAL_TYPE_UNKNOWN ((uint8_t)0x20) + +#if defined(JS_NUNBOX32) + +typedef uint32_t JSValueTag; +#define JSVAL_TAG_CLEAR ((uint32_t)(0xFFFFFF80)) +#define JSVAL_TAG_INT32 ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32)) +#define JSVAL_TAG_UNDEFINED ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED)) +#define JSVAL_TAG_STRING ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING)) +#define JSVAL_TAG_SYMBOL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL)) +#define JSVAL_TAG_BOOLEAN ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN)) +#define JSVAL_TAG_MAGIC ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC)) +#define JSVAL_TAG_NULL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL)) +#define JSVAL_TAG_OBJECT ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT)) + +#elif defined(JS_PUNBOX64) + +typedef uint32_t JSValueTag; +#define JSVAL_TAG_MAX_DOUBLE ((uint32_t)(0x1FFF0)) +#define JSVAL_TAG_INT32 (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32) +#define JSVAL_TAG_UNDEFINED (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED) +#define JSVAL_TAG_STRING (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING) +#define JSVAL_TAG_SYMBOL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL) +#define JSVAL_TAG_BOOLEAN (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN) +#define JSVAL_TAG_MAGIC (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC) +#define JSVAL_TAG_NULL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL) +#define JSVAL_TAG_OBJECT (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_OBJECT) + +typedef uint64_t JSValueShiftedTag; +#define JSVAL_SHIFTED_TAG_MAX_DOUBLE ((((uint64_t)JSVAL_TAG_MAX_DOUBLE) << JSVAL_TAG_SHIFT) | 0xFFFFFFFF) +#define JSVAL_SHIFTED_TAG_INT32 (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_UNDEFINED (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_STRING (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_SYMBOL (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_BOOLEAN (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_MAGIC (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_NULL (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_OBJECT (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT) + +#endif /* JS_PUNBOX64 */ +#endif /* !defined(__SUNPRO_CC) && !defined(__xlC__) */ + +#if defined(JS_NUNBOX32) + +#define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_CLEAR | (type))) + +#define JSVAL_LOWER_INCL_TAG_OF_OBJ_OR_NULL_SET JSVAL_TAG_NULL +#define JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET JSVAL_TAG_OBJECT +#define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32 +#define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING + +#elif defined(JS_PUNBOX64) + +#define JSVAL_PAYLOAD_MASK 0x00007FFFFFFFFFFFLL +#define JSVAL_TAG_MASK 0xFFFF800000000000LL +#define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_MAX_DOUBLE | (type))) +#define JSVAL_TYPE_TO_SHIFTED_TAG(type) (((uint64_t)JSVAL_TYPE_TO_TAG(type)) << JSVAL_TAG_SHIFT) + +#define JSVAL_LOWER_INCL_TAG_OF_OBJ_OR_NULL_SET JSVAL_TAG_NULL +#define JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET JSVAL_TAG_OBJECT +#define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32 +#define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING + +#define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_OBJ_OR_NULL_SET JSVAL_SHIFTED_TAG_NULL +#define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_PRIMITIVE_SET JSVAL_SHIFTED_TAG_OBJECT +#define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET JSVAL_SHIFTED_TAG_UNDEFINED +#define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET JSVAL_SHIFTED_TAG_STRING + +#endif /* JS_PUNBOX64 */ + +typedef enum JSWhyMagic +{ + JS_ELEMENTS_HOLE, /* a hole in a native object's elements */ + JS_NATIVE_ENUMERATE, /* indicates that a custom enumerate hook forwarded + * to JS_EnumerateState, which really means the object can be + * enumerated like a native object. */ + JS_NO_ITER_VALUE, /* there is not a pending iterator value */ + JS_GENERATOR_CLOSING, /* exception value thrown when closing a generator */ + JS_NO_CONSTANT, /* compiler sentinel value */ + JS_THIS_POISON, /* used in debug builds to catch tracing errors */ + JS_ARG_POISON, /* used in debug builds to catch tracing errors */ + JS_SERIALIZE_NO_NODE, /* an empty subnode in the AST serializer */ + JS_LAZY_ARGUMENTS, /* lazy arguments value on the stack */ + JS_OPTIMIZED_ARGUMENTS, /* optimized-away 'arguments' value */ + JS_IS_CONSTRUCTING, /* magic value passed to natives to indicate construction */ + JS_OVERWRITTEN_CALLEE, /* arguments.callee has been overwritten */ + JS_BLOCK_NEEDS_CLONE, /* value of static block object slot */ + JS_HASH_KEY_EMPTY, /* see class js::HashableValue */ + JS_ION_ERROR, /* error while running Ion code */ + JS_ION_BAILOUT, /* missing recover instruction result */ + JS_OPTIMIZED_OUT, /* optimized out slot */ + JS_GENERIC_MAGIC /* for local use */ +} JSWhyMagic; + +#if defined(IS_LITTLE_ENDIAN) +# if defined(JS_NUNBOX32) +typedef union jsval_layout +{ + uint64_t asBits; + struct { + union { + int32_t i32; + uint32_t u32; + uint32_t boo; // Don't use |bool| -- it must be four bytes. + JSString *str; + JS::Symbol *sym; + JSObject *obj; + js::gc::Cell *cell; + void *ptr; + JSWhyMagic why; + size_t word; + uintptr_t uintptr; + } payload; + JSValueTag tag; + } s; + double asDouble; + void *asPtr; +} JSVAL_ALIGNMENT jsval_layout; +# elif defined(JS_PUNBOX64) +typedef union jsval_layout +{ + uint64_t asBits; +#if !defined(_WIN64) + /* MSVC does not pack these correctly :-( */ + struct { + uint64_t payload47 : 47; + JSValueTag tag : 17; + } debugView; +#endif + struct { + union { + int32_t i32; + uint32_t u32; + JSWhyMagic why; + } payload; + } s; + double asDouble; + void *asPtr; + size_t asWord; + uintptr_t asUIntPtr; +} JSVAL_ALIGNMENT jsval_layout; +# endif /* JS_PUNBOX64 */ +#else /* defined(IS_LITTLE_ENDIAN) */ +# if defined(JS_NUNBOX32) +typedef union jsval_layout +{ + uint64_t asBits; + struct { + JSValueTag tag; + union { + int32_t i32; + uint32_t u32; + uint32_t boo; // Don't use |bool| -- it must be four bytes. + JSString *str; + JS::Symbol *sym; + JSObject *obj; + js::gc::Cell *cell; + void *ptr; + JSWhyMagic why; + size_t word; + uintptr_t uintptr; + } payload; + } s; + double asDouble; + void *asPtr; +} JSVAL_ALIGNMENT jsval_layout; +# elif defined(JS_PUNBOX64) +typedef union jsval_layout +{ + uint64_t asBits; + struct { + JSValueTag tag : 17; + uint64_t payload47 : 47; + } debugView; + struct { + uint32_t padding; + union { + int32_t i32; + uint32_t u32; + JSWhyMagic why; + } payload; + } s; + double asDouble; + void *asPtr; + size_t asWord; + uintptr_t asUIntPtr; +} JSVAL_ALIGNMENT jsval_layout; +# endif /* JS_PUNBOX64 */ +#endif /* defined(IS_LITTLE_ENDIAN) */ + +JS_STATIC_ASSERT(sizeof(jsval_layout) == 8); + +/* + * For codesize purposes on some platforms, it's important that the + * compiler know that JS::Values constructed from constant values can be + * folded to constant bit patterns at compile time, rather than + * constructed at runtime. Doing this requires a fair amount of C++11 + * features, which are not supported on all of our compilers. Set up + * some defines and helper macros in an attempt to confine the ugliness + * here, rather than scattering it all about the file. The important + * features are: + * + * - constexpr; + * - defaulted functions; + * - C99-style designated initializers. + */ +#if defined(__clang__) +# if __has_feature(cxx_constexpr) && __has_feature(cxx_defaulted_functions) +# define JS_VALUE_IS_CONSTEXPR +# endif +#elif defined(__GNUC__) +/* + * We need 4.5 for defaulted functions, 4.6 for constexpr, 4.7 because 4.6 + * doesn't understand |(X) { .field = ... }| syntax, and 4.7.3 because + * versions prior to that have bugs in the C++ front-end that cause crashes. + */ +# if MOZ_GCC_VERSION_AT_LEAST(4, 7, 3) +# define JS_VALUE_IS_CONSTEXPR +# endif +#endif + +#if defined(JS_VALUE_IS_CONSTEXPR) +# define JS_RETURN_LAYOUT_FROM_BITS(BITS) \ + return (jsval_layout) { .asBits = (BITS) } +# define JS_VALUE_CONSTEXPR MOZ_CONSTEXPR +# define JS_VALUE_CONSTEXPR_VAR MOZ_CONSTEXPR_VAR +#else +# define JS_RETURN_LAYOUT_FROM_BITS(BITS) \ + jsval_layout l; \ + l.asBits = (BITS); \ + return l; +# define JS_VALUE_CONSTEXPR +# define JS_VALUE_CONSTEXPR_VAR const +#endif + +#if defined(JS_NUNBOX32) + +/* + * N.B. GCC, in some but not all cases, chooses to emit signed comparison of + * JSValueTag even though its underlying type has been forced to be uint32_t. + * Thus, all comparisons should explicitly cast operands to uint32_t. + */ + +static inline JS_VALUE_CONSTEXPR jsval_layout +BUILD_JSVAL(JSValueTag tag, uint32_t payload) +{ + JS_RETURN_LAYOUT_FROM_BITS((((uint64_t)(uint32_t)tag) << 32) | payload); +} + +static inline bool +JSVAL_IS_DOUBLE_IMPL(jsval_layout l) +{ + return (uint32_t)l.s.tag <= (uint32_t)JSVAL_TAG_CLEAR; +} + +static inline jsval_layout +DOUBLE_TO_JSVAL_IMPL(double d) +{ + jsval_layout l; + l.asDouble = d; + MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(l)); + return l; +} + +static inline bool +JSVAL_IS_INT32_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_INT32; +} + +static inline int32_t +JSVAL_TO_INT32_IMPL(jsval_layout l) +{ + return l.s.payload.i32; +} + +static inline JS_VALUE_CONSTEXPR jsval_layout +INT32_TO_JSVAL_IMPL(int32_t i) +{ +#if defined(JS_VALUE_IS_CONSTEXPR) + return BUILD_JSVAL(JSVAL_TAG_INT32, i); +#else + jsval_layout l; + l.s.tag = JSVAL_TAG_INT32; + l.s.payload.i32 = i; + return l; +#endif +} + +static inline bool +JSVAL_IS_NUMBER_IMPL(jsval_layout l) +{ + JSValueTag tag = l.s.tag; + MOZ_ASSERT(tag != JSVAL_TAG_CLEAR); + return (uint32_t)tag <= (uint32_t)JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET; +} + +static inline bool +JSVAL_IS_UNDEFINED_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_UNDEFINED; +} + +static inline bool +JSVAL_IS_STRING_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_STRING; +} + +static inline jsval_layout +STRING_TO_JSVAL_IMPL(JSString *str) +{ + jsval_layout l; + MOZ_ASSERT(uintptr_t(str) > 0x1000); + l.s.tag = JSVAL_TAG_STRING; + l.s.payload.str = str; + return l; +} + +static inline JSString * +JSVAL_TO_STRING_IMPL(jsval_layout l) +{ + return l.s.payload.str; +} + +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + l.s.tag = JSVAL_TAG_SYMBOL; + l.s.payload.sym = sym; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.payload.sym; +} + +static inline bool +JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_BOOLEAN; +} + +static inline bool +JSVAL_TO_BOOLEAN_IMPL(jsval_layout l) +{ + return l.s.payload.boo; +} + +static inline jsval_layout +BOOLEAN_TO_JSVAL_IMPL(bool b) +{ + jsval_layout l; + l.s.tag = JSVAL_TAG_BOOLEAN; + l.s.payload.boo = b; + return l; +} + +static inline bool +JSVAL_IS_MAGIC_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_MAGIC; +} + +static inline bool +JSVAL_IS_OBJECT_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_OBJECT; +} + +static inline bool +JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l) +{ + return (uint32_t)l.s.tag < (uint32_t)JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET; +} + +static inline bool +JSVAL_IS_OBJECT_OR_NULL_IMPL(jsval_layout l) +{ + MOZ_ASSERT((uint32_t)l.s.tag <= (uint32_t)JSVAL_TAG_OBJECT); + return (uint32_t)l.s.tag >= (uint32_t)JSVAL_LOWER_INCL_TAG_OF_OBJ_OR_NULL_SET; +} + +static inline JSObject * +JSVAL_TO_OBJECT_IMPL(jsval_layout l) +{ + return l.s.payload.obj; +} + +static inline jsval_layout +OBJECT_TO_JSVAL_IMPL(JSObject *obj) +{ + jsval_layout l; + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); + l.s.tag = JSVAL_TAG_OBJECT; + l.s.payload.obj = obj; + return l; +} + +static inline bool +JSVAL_IS_NULL_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_NULL; +} + +static inline jsval_layout +PRIVATE_PTR_TO_JSVAL_IMPL(void *ptr) +{ + jsval_layout l; + MOZ_ASSERT(((uint32_t)ptr & 1) == 0); + l.s.tag = (JSValueTag)0; + l.s.payload.ptr = ptr; + MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(l)); + return l; +} + +static inline void * +JSVAL_TO_PRIVATE_PTR_IMPL(jsval_layout l) +{ + return l.s.payload.ptr; +} + +static inline bool +JSVAL_IS_GCTHING_IMPL(jsval_layout l) +{ + /* gcc sometimes generates signed < without explicit casts. */ + return (uint32_t)l.s.tag >= (uint32_t)JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET; +} + +static inline js::gc::Cell * +JSVAL_TO_GCTHING_IMPL(jsval_layout l) +{ + return l.s.payload.cell; +} + +static inline uint32_t +JSVAL_TRACE_KIND_IMPL(jsval_layout l) +{ + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return l.s.tag & 0x03; +} + +static inline bool +JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) +{ + return l.s.tag == JSVAL_TAG_INT32 && l.s.payload.i32 == i32; +} + +static inline bool +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) +{ + return (l.s.tag == JSVAL_TAG_BOOLEAN) && (l.s.payload.boo == uint32_t(b)); +} + +static inline jsval_layout +MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) +{ + jsval_layout l; + l.s.tag = JSVAL_TAG_MAGIC; + l.s.payload.why = why; + return l; +} + +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.s.tag = JSVAL_TAG_MAGIC; + l.s.payload.u32 = payload; + return l; +} + +static inline bool +JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) +{ + JSValueTag ltag = lhs.s.tag, rtag = rhs.s.tag; + return ltag == rtag || (ltag < JSVAL_TAG_CLEAR && rtag < JSVAL_TAG_CLEAR); +} + +static inline JSValueType +JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) +{ + uint32_t type = l.s.tag & 0xF; + MOZ_ASSERT(type > JSVAL_TYPE_DOUBLE); + return (JSValueType)type; +} + +#elif defined(JS_PUNBOX64) + +static inline JS_VALUE_CONSTEXPR jsval_layout +BUILD_JSVAL(JSValueTag tag, uint64_t payload) +{ + JS_RETURN_LAYOUT_FROM_BITS((((uint64_t)(uint32_t)tag) << JSVAL_TAG_SHIFT) | payload); +} + +static inline bool +JSVAL_IS_DOUBLE_IMPL(jsval_layout l) +{ + return l.asBits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE; +} + +static inline jsval_layout +DOUBLE_TO_JSVAL_IMPL(double d) +{ + jsval_layout l; + l.asDouble = d; + MOZ_ASSERT(l.asBits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE); + return l; +} + +static inline bool +JSVAL_IS_INT32_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_INT32; +} + +static inline int32_t +JSVAL_TO_INT32_IMPL(jsval_layout l) +{ + return (int32_t)l.asBits; +} + +static inline JS_VALUE_CONSTEXPR jsval_layout +INT32_TO_JSVAL_IMPL(int32_t i32) +{ + JS_RETURN_LAYOUT_FROM_BITS(((uint64_t)(uint32_t)i32) | JSVAL_SHIFTED_TAG_INT32); +} + +static inline bool +JSVAL_IS_NUMBER_IMPL(jsval_layout l) +{ + return l.asBits < JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET; +} + +static inline bool +JSVAL_IS_UNDEFINED_IMPL(jsval_layout l) +{ + return l.asBits == JSVAL_SHIFTED_TAG_UNDEFINED; +} + +static inline bool +JSVAL_IS_STRING_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_STRING; +} + +static inline jsval_layout +STRING_TO_JSVAL_IMPL(JSString *str) +{ + jsval_layout l; + uint64_t strBits = (uint64_t)str; + MOZ_ASSERT(uintptr_t(str) > 0x1000); + MOZ_ASSERT((strBits >> JSVAL_TAG_SHIFT) == 0); + l.asBits = strBits | JSVAL_SHIFTED_TAG_STRING; + return l; +} + +static inline JSString * +JSVAL_TO_STRING_IMPL(jsval_layout l) +{ + return (JSString *)(l.asBits & JSVAL_PAYLOAD_MASK); +} + +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + uint64_t symBits = (uint64_t)sym; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + MOZ_ASSERT((symBits >> JSVAL_TAG_SHIFT) == 0); + l.asBits = symBits | JSVAL_SHIFTED_TAG_SYMBOL; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return (JS::Symbol *)(l.asBits & JSVAL_PAYLOAD_MASK); +} + +static inline bool +JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_BOOLEAN; +} + +static inline bool +JSVAL_TO_BOOLEAN_IMPL(jsval_layout l) +{ + return (bool)(l.asBits & JSVAL_PAYLOAD_MASK); +} + +static inline jsval_layout +BOOLEAN_TO_JSVAL_IMPL(bool b) +{ + jsval_layout l; + l.asBits = ((uint64_t)(uint32_t)b) | JSVAL_SHIFTED_TAG_BOOLEAN; + return l; +} + +static inline bool +JSVAL_IS_MAGIC_IMPL(jsval_layout l) +{ + return (l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_MAGIC; +} + +static inline bool +JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l) +{ + return l.asBits < JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_PRIMITIVE_SET; +} + +static inline bool +JSVAL_IS_OBJECT_IMPL(jsval_layout l) +{ + MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_TAG_OBJECT); + return l.asBits >= JSVAL_SHIFTED_TAG_OBJECT; +} + +static inline bool +JSVAL_IS_OBJECT_OR_NULL_IMPL(jsval_layout l) +{ + MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_TAG_OBJECT); + return l.asBits >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_OBJ_OR_NULL_SET; +} + +static inline JSObject * +JSVAL_TO_OBJECT_IMPL(jsval_layout l) +{ + uint64_t ptrBits = l.asBits & JSVAL_PAYLOAD_MASK; + MOZ_ASSERT((ptrBits & 0x7) == 0); + return (JSObject *)ptrBits; +} + +static inline jsval_layout +OBJECT_TO_JSVAL_IMPL(JSObject *obj) +{ + jsval_layout l; + uint64_t objBits = (uint64_t)obj; + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); + MOZ_ASSERT((objBits >> JSVAL_TAG_SHIFT) == 0); + l.asBits = objBits | JSVAL_SHIFTED_TAG_OBJECT; + return l; +} + +static inline bool +JSVAL_IS_NULL_IMPL(jsval_layout l) +{ + return l.asBits == JSVAL_SHIFTED_TAG_NULL; +} + +static inline bool +JSVAL_IS_GCTHING_IMPL(jsval_layout l) +{ + return l.asBits >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET; +} + +static inline js::gc::Cell * +JSVAL_TO_GCTHING_IMPL(jsval_layout l) +{ + uint64_t ptrBits = l.asBits & JSVAL_PAYLOAD_MASK; + MOZ_ASSERT((ptrBits & 0x7) == 0); + return reinterpret_cast(ptrBits); +} + +static inline uint32_t +JSVAL_TRACE_KIND_IMPL(jsval_layout l) +{ + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) & 0x03; +} + +static inline jsval_layout +PRIVATE_PTR_TO_JSVAL_IMPL(void *ptr) +{ + jsval_layout l; + uint64_t ptrBits = (uint64_t)ptr; + MOZ_ASSERT((ptrBits & 1) == 0); + l.asBits = ptrBits >> 1; + MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(l)); + return l; +} + +static inline void * +JSVAL_TO_PRIVATE_PTR_IMPL(jsval_layout l) +{ + MOZ_ASSERT((l.asBits & 0x8000000000000000LL) == 0); + return (void *)(l.asBits << 1); +} + +static inline bool +JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) +{ + return l.asBits == (((uint64_t)(uint32_t)i32) | JSVAL_SHIFTED_TAG_INT32); +} + +static inline bool +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) +{ + return l.asBits == (((uint64_t)(uint32_t)b) | JSVAL_SHIFTED_TAG_BOOLEAN); +} + +static inline jsval_layout +MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) +{ + jsval_layout l; + l.asBits = ((uint64_t)(uint32_t)why) | JSVAL_SHIFTED_TAG_MAGIC; + return l; +} + +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.asBits = ((uint64_t)payload) | JSVAL_SHIFTED_TAG_MAGIC; + return l; +} + +static inline bool +JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) +{ + uint64_t lbits = lhs.asBits, rbits = rhs.asBits; + return (lbits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE && rbits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE) || + (((lbits ^ rbits) & 0xFFFF800000000000LL) == 0); +} + +static inline JSValueType +JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) +{ + uint64_t type = (l.asBits >> JSVAL_TAG_SHIFT) & 0xF; + MOZ_ASSERT(type > JSVAL_TYPE_DOUBLE); + return (JSValueType)type; +} + +#endif /* JS_PUNBOX64 */ + +static inline bool +JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) +{ + return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l); +} + +static inline jsval_layout JSVAL_TO_IMPL(JS::Value v); +static inline JS_VALUE_CONSTEXPR JS::Value IMPL_TO_JSVAL(jsval_layout l); + +namespace JS { + +static inline JS_VALUE_CONSTEXPR JS::Value UndefinedValue(); + +/** + * Returns a generic quiet NaN value, with all payload bits set to zero. + * + * Among other properties, this NaN's bit pattern conforms to JS::Value's + * bit pattern restrictions. + */ +static MOZ_ALWAYS_INLINE double +GenericNaN() +{ + return mozilla::SpecificNaN(0, 0x8000000000000ULL); +} + +/* MSVC with PGO miscompiles this function. */ +#if defined(_MSC_VER) +# pragma optimize("g", off) +#endif +static inline double +CanonicalizeNaN(double d) +{ + if (MOZ_UNLIKELY(mozilla::IsNaN(d))) + return GenericNaN(); + return d; +} +#if defined(_MSC_VER) +# pragma optimize("", on) +#endif + +/* + * JS::Value is the interface for a single JavaScript Engine value. A few + * general notes on JS::Value: + * + * - JS::Value has setX() and isX() members for X in + * + * { Int32, Double, String, Symbol, Boolean, Undefined, Null, Object, Magic } + * + * JS::Value also contains toX() for each of the non-singleton types. + * + * - Magic is a singleton type whose payload contains either a JSWhyMagic "reason" for + * the magic value or a uint32_t value. By providing JSWhyMagic values when + * creating and checking for magic values, it is possible to assert, at + * runtime, that only magic values with the expected reason flow through a + * particular value. For example, if cx->exception has a magic value, the + * reason must be JS_GENERATOR_CLOSING. + * + * - The JS::Value operations are preferred. The JSVAL_* operations remain for + * compatibility; they may be removed at some point. These operations mostly + * provide similar functionality. But there are a few key differences. One + * is that JS::Value gives null a separate type. + * Also, to help prevent mistakenly boxing a nullable JSObject* as an object, + * Value::setObject takes a JSObject&. (Conversely, Value::toObject returns a + * JSObject&.) A convenience member Value::setObjectOrNull is provided. + * + * - JSVAL_VOID is the same as the singleton value of the Undefined type. + * + * - Note that JS::Value is 8 bytes on 32 and 64-bit architectures. Thus, on + * 32-bit user code should avoid copying jsval/JS::Value as much as possible, + * preferring to pass by const Value &. + */ +class Value +{ + public: + /* + * N.B. the default constructor leaves Value unitialized. Adding a default + * constructor prevents Value from being stored in a union. + */ +#if defined(JS_VALUE_IS_CONSTEXPR) + Value() = default; + Value(const Value& v) = default; +#endif + + /*** Mutators ***/ + + void setNull() { + data.asBits = BUILD_JSVAL(JSVAL_TAG_NULL, 0).asBits; + } + + void setUndefined() { + data.asBits = BUILD_JSVAL(JSVAL_TAG_UNDEFINED, 0).asBits; + } + + void setInt32(int32_t i) { + data = INT32_TO_JSVAL_IMPL(i); + } + + int32_t &getInt32Ref() { + MOZ_ASSERT(isInt32()); + return data.s.payload.i32; + } + + void setDouble(double d) { + data = DOUBLE_TO_JSVAL_IMPL(d); + } + + void setNaN() { + setDouble(GenericNaN()); + } + + double &getDoubleRef() { + MOZ_ASSERT(isDouble()); + return data.asDouble; + } + + void setString(JSString *str) { + MOZ_ASSERT(!IsPoisonedPtr(str)); + data = STRING_TO_JSVAL_IMPL(str); + } + + void setSymbol(JS::Symbol *sym) { + MOZ_ASSERT(!IsPoisonedPtr(sym)); + data = SYMBOL_TO_JSVAL_IMPL(sym); + } + + void setObject(JSObject &obj) { + MOZ_ASSERT(!IsPoisonedPtr(&obj)); + data = OBJECT_TO_JSVAL_IMPL(&obj); + } + + void setBoolean(bool b) { + data = BOOLEAN_TO_JSVAL_IMPL(b); + } + + void setMagic(JSWhyMagic why) { + data = MAGIC_TO_JSVAL_IMPL(why); + } + + void setMagicUint32(uint32_t payload) { + data = MAGIC_UINT32_TO_JSVAL_IMPL(payload); + } + + bool setNumber(uint32_t ui) { + if (ui > JSVAL_INT_MAX) { + setDouble((double)ui); + return false; + } else { + setInt32((int32_t)ui); + return true; + } + } + + bool setNumber(double d) { + int32_t i; + if (mozilla::NumberIsInt32(d, &i)) { + setInt32(i); + return true; + } + + setDouble(d); + return false; + } + + void setObjectOrNull(JSObject *arg) { + if (arg) + setObject(*arg); + else + setNull(); + } + + void swap(Value &rhs) { + uint64_t tmp = rhs.data.asBits; + rhs.data.asBits = data.asBits; + data.asBits = tmp; + } + + /*** Value type queries ***/ + + bool isUndefined() const { + return JSVAL_IS_UNDEFINED_IMPL(data); + } + + bool isNull() const { + return JSVAL_IS_NULL_IMPL(data); + } + + bool isNullOrUndefined() const { + return isNull() || isUndefined(); + } + + bool isInt32() const { + return JSVAL_IS_INT32_IMPL(data); + } + + bool isInt32(int32_t i32) const { + return JSVAL_IS_SPECIFIC_INT32_IMPL(data, i32); + } + + bool isDouble() const { + return JSVAL_IS_DOUBLE_IMPL(data); + } + + bool isNumber() const { + return JSVAL_IS_NUMBER_IMPL(data); + } + + bool isString() const { + return JSVAL_IS_STRING_IMPL(data); + } + + bool isSymbol() const { + return JSVAL_IS_SYMBOL_IMPL(data); + } + + bool isObject() const { + return JSVAL_IS_OBJECT_IMPL(data); + } + + bool isPrimitive() const { + return JSVAL_IS_PRIMITIVE_IMPL(data); + } + + bool isObjectOrNull() const { + return JSVAL_IS_OBJECT_OR_NULL_IMPL(data); + } + + bool isGCThing() const { + return JSVAL_IS_GCTHING_IMPL(data); + } + + bool isBoolean() const { + return JSVAL_IS_BOOLEAN_IMPL(data); + } + + bool isTrue() const { + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, true); + } + + bool isFalse() const { + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, false); + } + + bool isMagic() const { + return JSVAL_IS_MAGIC_IMPL(data); + } + + bool isMagic(JSWhyMagic why) const { + MOZ_ASSERT_IF(isMagic(), data.s.payload.why == why); + return JSVAL_IS_MAGIC_IMPL(data); + } + + bool isMarkable() const { + return JSVAL_IS_TRACEABLE_IMPL(data); + } + + JSGCTraceKind gcKind() const { + MOZ_ASSERT(isMarkable()); + return JSGCTraceKind(JSVAL_TRACE_KIND_IMPL(data)); + } + + JSWhyMagic whyMagic() const { + MOZ_ASSERT(isMagic()); + return data.s.payload.why; + } + + uint32_t magicUint32() const { + MOZ_ASSERT(isMagic()); + return data.s.payload.u32; + } + + /*** Comparison ***/ + + bool operator==(const Value &rhs) const { + return data.asBits == rhs.data.asBits; + } + + bool operator!=(const Value &rhs) const { + return data.asBits != rhs.data.asBits; + } + + friend inline bool SameType(const Value &lhs, const Value &rhs); + + /*** Extract the value's typed payload ***/ + + int32_t toInt32() const { + MOZ_ASSERT(isInt32()); + return JSVAL_TO_INT32_IMPL(data); + } + + double toDouble() const { + MOZ_ASSERT(isDouble()); + return data.asDouble; + } + + double toNumber() const { + MOZ_ASSERT(isNumber()); + return isDouble() ? toDouble() : double(toInt32()); + } + + JSString *toString() const { + MOZ_ASSERT(isString()); + return JSVAL_TO_STRING_IMPL(data); + } + + JS::Symbol *toSymbol() const { + MOZ_ASSERT(isSymbol()); + return JSVAL_TO_SYMBOL_IMPL(data); + } + + JSObject &toObject() const { + MOZ_ASSERT(isObject()); + return *JSVAL_TO_OBJECT_IMPL(data); + } + + JSObject *toObjectOrNull() const { + MOZ_ASSERT(isObjectOrNull()); + return JSVAL_TO_OBJECT_IMPL(data); + } + + js::gc::Cell *toGCThing() const { + MOZ_ASSERT(isGCThing()); + return JSVAL_TO_GCTHING_IMPL(data); + } + + bool toBoolean() const { + MOZ_ASSERT(isBoolean()); + return JSVAL_TO_BOOLEAN_IMPL(data); + } + + uint32_t payloadAsRawUint32() const { + MOZ_ASSERT(!isDouble()); + return data.s.payload.u32; + } + + uint64_t asRawBits() const { + return data.asBits; + } + + JSValueType extractNonDoubleType() const { + return JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(data); + } + + /* + * Private API + * + * Private setters/getters allow the caller to read/write arbitrary types + * that fit in the 64-bit payload. It is the caller's responsibility, after + * storing to a value with setPrivateX to read only using getPrivateX. + * Privates values are given a type which ensures they are not marked. + */ + + void setPrivate(void *ptr) { + data = PRIVATE_PTR_TO_JSVAL_IMPL(ptr); + } + + void *toPrivate() const { + MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(data)); + return JSVAL_TO_PRIVATE_PTR_IMPL(data); + } + + void setPrivateUint32(uint32_t ui) { + MOZ_ASSERT(uint32_t(int32_t(ui)) == ui); + setInt32(int32_t(ui)); + } + + uint32_t toPrivateUint32() const { + return uint32_t(toInt32()); + } + + /* + * An unmarked value is just a void* cast as a Value. Thus, the Value is + * not safe for GC and must not be marked. This API avoids raw casts + * and the ensuing strict-aliasing warnings. + */ + + void setUnmarkedPtr(void *ptr) { + data.asPtr = ptr; + } + + void *toUnmarkedPtr() const { + return data.asPtr; + } + + const size_t *payloadWord() const { +#if defined(JS_NUNBOX32) + return &data.s.payload.word; +#elif defined(JS_PUNBOX64) + return &data.asWord; +#endif + } + + const uintptr_t *payloadUIntPtr() const { +#if defined(JS_NUNBOX32) + return &data.s.payload.uintptr; +#elif defined(JS_PUNBOX64) + return &data.asUIntPtr; +#endif + } + +#if !defined(_MSC_VER) && !defined(__sparc) + // Value must be POD so that MSVC will pass it by value and not in memory + // (bug 689101); the same is true for SPARC as well (bug 737344). More + // precisely, we don't want Value return values compiled as out params. + private: +#endif + + jsval_layout data; + + private: +#if defined(JS_VALUE_IS_CONSTEXPR) + MOZ_IMPLICIT JS_VALUE_CONSTEXPR Value(jsval_layout layout) : data(layout) {} +#endif + + void staticAssertions() { + JS_STATIC_ASSERT(sizeof(JSValueType) == 1); + JS_STATIC_ASSERT(sizeof(JSValueTag) == 4); + JS_STATIC_ASSERT(sizeof(JSWhyMagic) <= 4); + JS_STATIC_ASSERT(sizeof(Value) == 8); + } + + friend jsval_layout (::JSVAL_TO_IMPL)(Value); + friend Value JS_VALUE_CONSTEXPR (::IMPL_TO_JSVAL)(jsval_layout l); + friend Value JS_VALUE_CONSTEXPR (JS::UndefinedValue)(); +}; + +inline bool +IsPoisonedValue(const Value &v) +{ + if (v.isString()) + return IsPoisonedPtr(v.toString()); + if (v.isSymbol()) + return IsPoisonedPtr(v.toSymbol()); + if (v.isObject()) + return IsPoisonedPtr(&v.toObject()); + return false; +} + +inline bool +IsOptimizedPlaceholderMagicValue(const Value &v) +{ + if (v.isMagic()) { + MOZ_ASSERT(v.whyMagic() == JS_OPTIMIZED_ARGUMENTS || v.whyMagic() == JS_OPTIMIZED_OUT); + return true; + } + return false; +} + +static MOZ_ALWAYS_INLINE void +ExposeValueToActiveJS(const Value &v) +{ + if (v.isMarkable()) + ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); +} + +/************************************************************************/ + +static inline Value +NullValue() +{ + Value v; + v.setNull(); + return v; +} + +static inline JS_VALUE_CONSTEXPR Value +UndefinedValue() +{ +#if defined(JS_VALUE_IS_CONSTEXPR) + return Value(BUILD_JSVAL(JSVAL_TAG_UNDEFINED, 0)); +#else + JS::Value v; + v.setUndefined(); + return v; +#endif +} + +static inline Value +Int32Value(int32_t i32) +{ + Value v; + v.setInt32(i32); + return v; +} + +static inline Value +DoubleValue(double dbl) +{ + Value v; + v.setDouble(dbl); + return v; +} + +static inline Value +DoubleNaNValue() +{ + Value v; + v.setNaN(); + return v; +} + +static inline Value +Float32Value(float f) +{ + Value v; + v.setDouble(f); + return v; +} + +static inline Value +StringValue(JSString *str) +{ + Value v; + v.setString(str); + return v; +} + +static inline Value +SymbolValue(JS::Symbol *sym) +{ + Value v; + v.setSymbol(sym); + return v; +} + +static inline Value +BooleanValue(bool boo) +{ + Value v; + v.setBoolean(boo); + return v; +} + +static inline Value +TrueValue() +{ + Value v; + v.setBoolean(true); + return v; +} + +static inline Value +FalseValue() +{ + Value v; + v.setBoolean(false); + return v; +} + +static inline Value +ObjectValue(JSObject &obj) +{ + Value v; + v.setObject(obj); + return v; +} + +static inline Value +ObjectValueCrashOnTouch() +{ + Value v; + v.setObject(*reinterpret_cast(0x42)); + return v; +} + +static inline Value +MagicValue(JSWhyMagic why) +{ + Value v; + v.setMagic(why); + return v; +} + +static inline Value +MagicValueUint32(uint32_t payload) +{ + Value v; + v.setMagicUint32(payload); + return v; +} + +static inline Value +NumberValue(float f) +{ + Value v; + v.setNumber(f); + return v; +} + +static inline Value +NumberValue(double dbl) +{ + Value v; + v.setNumber(dbl); + return v; +} + +static inline Value +NumberValue(int8_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(uint8_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(int16_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(uint16_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(int32_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(uint32_t i) +{ + Value v; + v.setNumber(i); + return v; +} + +namespace detail { + +template +class MakeNumberValue +{ + public: + template + static inline Value create(const T t) + { + Value v; + if (JSVAL_INT_MIN <= t && t <= JSVAL_INT_MAX) + v.setInt32(int32_t(t)); + else + v.setDouble(double(t)); + return v; + } +}; + +template <> +class MakeNumberValue +{ + public: + template + static inline Value create(const T t) + { + Value v; + if (t <= JSVAL_INT_MAX) + v.setInt32(int32_t(t)); + else + v.setDouble(double(t)); + return v; + } +}; + +} // namespace detail + +template +static inline Value +NumberValue(const T t) +{ + MOZ_ASSERT(T(double(t)) == t, "value creation would be lossy"); + return detail::MakeNumberValue::is_signed>::create(t); +} + +static inline Value +ObjectOrNullValue(JSObject *obj) +{ + Value v; + v.setObjectOrNull(obj); + return v; +} + +static inline Value +PrivateValue(void *ptr) +{ + Value v; + v.setPrivate(ptr); + return v; +} + +static inline Value +PrivateUint32Value(uint32_t ui) +{ + Value v; + v.setPrivateUint32(ui); + return v; +} + +inline bool +SameType(const Value &lhs, const Value &rhs) +{ + return JSVAL_SAME_TYPE_IMPL(lhs.data, rhs.data); +} + +} // namespace JS + +/************************************************************************/ + +#ifdef JSGC_GENERATIONAL +namespace JS { +JS_PUBLIC_API(void) HeapValuePostBarrier(Value *valuep); +JS_PUBLIC_API(void) HeapValueRelocate(Value *valuep); +} +#endif + +namespace js { + +template <> struct GCMethods +{ + static JS::Value initial() { return JS::UndefinedValue(); } + static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } +}; + +template <> struct GCMethods +{ + static JS::Value initial() { return JS::UndefinedValue(); } + static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } + static bool needsPostBarrier(const JS::Value &v) { + return v.isObject() && gc::IsInsideNursery(reinterpret_cast(&v.toObject())); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JS::Value *v) { JS::HeapValuePostBarrier(v); } + static void relocate(JS::Value *v) { JS::HeapValueRelocate(v); } +#endif +}; + +template class MutableValueOperations; + +/* + * A class designed for CRTP use in implementing the non-mutating parts of the + * Value interface in Value-like classes. Outer must be a class inheriting + * ValueOperations with a visible extract() method returning the + * const Value* abstracted by Outer. + */ +template +class ValueOperations +{ + friend class MutableValueOperations; + + const JS::Value * value() const { return static_cast(this)->extract(); } + + public: + bool isUndefined() const { return value()->isUndefined(); } + bool isNull() const { return value()->isNull(); } + bool isBoolean() const { return value()->isBoolean(); } + bool isTrue() const { return value()->isTrue(); } + bool isFalse() const { return value()->isFalse(); } + bool isNumber() const { return value()->isNumber(); } + bool isInt32() const { return value()->isInt32(); } + bool isDouble() const { return value()->isDouble(); } + bool isString() const { return value()->isString(); } + bool isSymbol() const { return value()->isSymbol(); } + bool isObject() const { return value()->isObject(); } + bool isMagic() const { return value()->isMagic(); } + bool isMagic(JSWhyMagic why) const { return value()->isMagic(why); } + bool isMarkable() const { return value()->isMarkable(); } + bool isPrimitive() const { return value()->isPrimitive(); } + bool isGCThing() const { return value()->isGCThing(); } + + bool isNullOrUndefined() const { return value()->isNullOrUndefined(); } + bool isObjectOrNull() const { return value()->isObjectOrNull(); } + + bool toBoolean() const { return value()->toBoolean(); } + double toNumber() const { return value()->toNumber(); } + int32_t toInt32() const { return value()->toInt32(); } + double toDouble() const { return value()->toDouble(); } + JSString *toString() const { return value()->toString(); } + JS::Symbol *toSymbol() const { return value()->toSymbol(); } + JSObject &toObject() const { return value()->toObject(); } + JSObject *toObjectOrNull() const { return value()->toObjectOrNull(); } + void *toGCThing() const { return value()->toGCThing(); } + uint64_t asRawBits() const { return value()->asRawBits(); } + + JSValueType extractNonDoubleType() const { return value()->extractNonDoubleType(); } + uint32_t toPrivateUint32() const { return value()->toPrivateUint32(); } + + JSWhyMagic whyMagic() const { return value()->whyMagic(); } + uint32_t magicUint32() const { return value()->magicUint32(); } +}; + +/* + * A class designed for CRTP use in implementing all the mutating parts of the + * Value interface in Value-like classes. Outer must be a class inheriting + * MutableValueOperations with visible extractMutable() and extract() + * methods returning the const Value* and Value* abstracted by Outer. + */ +template +class MutableValueOperations : public ValueOperations +{ + JS::Value * value() { return static_cast(this)->extractMutable(); } + + public: + void setNull() { value()->setNull(); } + void setUndefined() { value()->setUndefined(); } + void setInt32(int32_t i) { value()->setInt32(i); } + void setDouble(double d) { value()->setDouble(d); } + void setNaN() { setDouble(JS::GenericNaN()); } + void setBoolean(bool b) { value()->setBoolean(b); } + void setMagic(JSWhyMagic why) { value()->setMagic(why); } + bool setNumber(uint32_t ui) { return value()->setNumber(ui); } + bool setNumber(double d) { return value()->setNumber(d); } + void setString(JSString *str) { this->value()->setString(str); } + void setSymbol(JS::Symbol *sym) { this->value()->setSymbol(sym); } + void setObject(JSObject &obj) { this->value()->setObject(obj); } + void setObjectOrNull(JSObject *arg) { this->value()->setObjectOrNull(arg); } +}; + +/* + * Augment the generic Heap interface when T = Value with + * type-querying, value-extracting, and mutating operations. + */ +template <> +class HeapBase : public ValueOperations > +{ + typedef JS::Heap Outer; + + friend class ValueOperations; + + const JS::Value * extract() const { return static_cast(this)->address(); } + + void setBarriered(const JS::Value &v) { + static_cast *>(this)->set(v); + } + + public: + void setNull() { setBarriered(JS::NullValue()); } + void setUndefined() { setBarriered(JS::UndefinedValue()); } + void setInt32(int32_t i) { setBarriered(JS::Int32Value(i)); } + void setDouble(double d) { setBarriered(JS::DoubleValue(d)); } + void setNaN() { setDouble(JS::GenericNaN()); } + void setBoolean(bool b) { setBarriered(JS::BooleanValue(b)); } + void setMagic(JSWhyMagic why) { setBarriered(JS::MagicValue(why)); } + void setString(JSString *str) { setBarriered(JS::StringValue(str)); } + void setSymbol(JS::Symbol *sym) { setBarriered(JS::SymbolValue(sym)); } + void setObject(JSObject &obj) { setBarriered(JS::ObjectValue(obj)); } + + bool setNumber(uint32_t ui) { + if (ui > JSVAL_INT_MAX) { + setDouble((double)ui); + return false; + } else { + setInt32((int32_t)ui); + return true; + } + } + + bool setNumber(double d) { + int32_t i; + if (mozilla::NumberIsInt32(d, &i)) { + setInt32(i); + return true; + } + + setDouble(d); + return false; + } + + void setObjectOrNull(JSObject *arg) { + if (arg) + setObject(*arg); + else + setNull(); + } +}; + +/* + * Augment the generic Handle interface when T = Value with type-querying + * and value-extracting operations. + */ +template <> +class HandleBase : public ValueOperations > +{ + friend class ValueOperations >; + const JS::Value * extract() const { + return static_cast*>(this)->address(); + } +}; + +/* + * Augment the generic MutableHandle interface when T = Value with + * type-querying, value-extracting, and mutating operations. + */ +template <> +class MutableHandleBase : public MutableValueOperations > +{ + friend class ValueOperations >; + const JS::Value * extract() const { + return static_cast*>(this)->address(); + } + + friend class MutableValueOperations >; + JS::Value * extractMutable() { + return static_cast*>(this)->address(); + } +}; + +/* + * Augment the generic Rooted interface when T = Value with type-querying, + * value-extracting, and mutating operations. + */ +template <> +class RootedBase : public MutableValueOperations > +{ + friend class ValueOperations >; + const JS::Value * extract() const { + return static_cast*>(this)->address(); + } + + friend class MutableValueOperations >; + JS::Value * extractMutable() { + return static_cast*>(this)->address(); + } +}; + +} // namespace js + +inline jsval_layout +JSVAL_TO_IMPL(JS::Value v) +{ + return v.data; +} + +inline JS_VALUE_CONSTEXPR JS::Value +IMPL_TO_JSVAL(jsval_layout l) +{ +#if defined(JS_VALUE_IS_CONSTEXPR) + return JS::Value(l); +#else + JS::Value v; + v.data = l; + return v; +#endif +} + +namespace JS { + +#ifndef __GNUC__ +/* + * The default assignment operator for |struct C| has the signature: + * + * C& C::operator=(const C&) + * + * And in particular requires implicit conversion of |this| to type |C| for the + * return value. But |volatile C| cannot thus be converted to |C|, so just + * doing |sink = hold| as in the non-specialized version would fail to compile. + * Do the assignment on asBits instead, since I don't think we want to give + * jsval_layout an assignment operator returning |volatile jsval_layout|. + */ +template<> +inline Anchor::~Anchor() +{ + volatile uint64_t bits; + bits = JSVAL_TO_IMPL(hold).asBits; +} +#endif + +#ifdef JS_DEBUG +namespace detail { + +struct ValueAlignmentTester { char c; JS::Value v; }; +static_assert(sizeof(ValueAlignmentTester) == 16, + "JS::Value must be 16-byte-aligned"); + +struct LayoutAlignmentTester { char c; jsval_layout l; }; +static_assert(sizeof(LayoutAlignmentTester) == 16, + "jsval_layout must be 16-byte-aligned"); + +} // namespace detail +#endif /* JS_DEBUG */ + +} // namespace JS + +/* + * JS::Value and jsval are the same type; jsval is the old name, kept around + * for backwards compatibility along with all the JSVAL_* operations below. + * jsval_layout is an implementation detail and should not be used externally. + */ +typedef JS::Value jsval; + +static_assert(sizeof(jsval_layout) == sizeof(JS::Value), + "jsval_layout and JS::Value must have identical layouts"); + +/************************************************************************/ + +static inline JS_VALUE_CONSTEXPR jsval +INT_TO_JSVAL(int32_t i) +{ + return IMPL_TO_JSVAL(INT32_TO_JSVAL_IMPL(i)); +} + +static inline JS_VALUE_CONSTEXPR jsval +DOUBLE_TO_JSVAL(double d) +{ + /* + * This is a manually inlined version of: + * d = JS_CANONICALIZE_NAN(d); + * return IMPL_TO_JSVAL(DOUBLE_TO_JSVAL_IMPL(d)); + * because GCC from XCode 3.1.4 miscompiles the above code. + */ +#if defined(JS_VALUE_IS_CONSTEXPR) + return IMPL_TO_JSVAL(MOZ_UNLIKELY(d != d) + ? (jsval_layout) { .asBits = 0x7FF8000000000000LL } + : (jsval_layout) { .asDouble = d }); +#else + jsval_layout l; + if (MOZ_UNLIKELY(d != d)) + l.asBits = 0x7FF8000000000000LL; + else + l.asDouble = d; + return IMPL_TO_JSVAL(l); +#endif +} + +static inline JS_VALUE_CONSTEXPR jsval +UINT_TO_JSVAL(uint32_t i) +{ + return (i <= JSVAL_INT_MAX + ? INT_TO_JSVAL((int32_t)i) + : DOUBLE_TO_JSVAL((double)i)); +} + +static inline jsval +STRING_TO_JSVAL(JSString *str) +{ + return IMPL_TO_JSVAL(STRING_TO_JSVAL_IMPL(str)); +} + +static inline jsval +OBJECT_TO_JSVAL(JSObject *obj) +{ + if (obj) + return IMPL_TO_JSVAL(OBJECT_TO_JSVAL_IMPL(obj)); + return IMPL_TO_JSVAL(BUILD_JSVAL(JSVAL_TAG_NULL, 0)); +} + +static inline jsval +BOOLEAN_TO_JSVAL(bool b) +{ + return IMPL_TO_JSVAL(BOOLEAN_TO_JSVAL_IMPL(b)); +} + +/* To be GC-safe, privates are tagged as doubles. */ + +static inline jsval +PRIVATE_TO_JSVAL(void *ptr) +{ + return IMPL_TO_JSVAL(PRIVATE_PTR_TO_JSVAL_IMPL(ptr)); +} + +// JS constants. For efficiency, prefer predicates (e.g. v.isNull()) and +// constructing values from scratch (e.g. Int32Value(0)). These constants are +// stored in memory and initialized at startup, so testing against them and +// using them requires memory loads and will be correspondingly slow. +extern JS_PUBLIC_DATA(const jsval) JSVAL_NULL; +extern JS_PUBLIC_DATA(const jsval) JSVAL_ZERO; +extern JS_PUBLIC_DATA(const jsval) JSVAL_ONE; +extern JS_PUBLIC_DATA(const jsval) JSVAL_FALSE; +extern JS_PUBLIC_DATA(const jsval) JSVAL_TRUE; +extern JS_PUBLIC_DATA(const jsval) JSVAL_VOID; + +namespace JS { + +extern JS_PUBLIC_DATA(const HandleValue) NullHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) TrueHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) FalseHandleValue; + +} + +#undef JS_VALUE_IS_CONSTEXPR +#undef JS_RETURN_LAYOUT_FROM_BITS + +#endif /* js_Value_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Vector.h new file mode 100644 index 0000000000..a2d24b10ed --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/js/Vector.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_Vector_h +#define js_Vector_h + +#include "mozilla/Vector.h" + +/* Silence dire "bugs in previous versions of MSVC have been fixed" warnings */ +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4345) +#endif + +namespace js { + +class TempAllocPolicy; + +// If we had C++11 template aliases, we could just use this: +// +// template +// using Vector = mozilla::Vector; +// +// ...and get rid of all the CRTP madness in mozilla::Vector(Base). But we +// can't because compiler support's not up to snuff. (Template aliases are in +// gcc 4.7 and clang 3.0 and are expected to be in MSVC 2013.) Instead, have a +// completely separate class inheriting from mozilla::Vector, and throw CRTP at +// the problem til things work. +// +// This workaround presents a couple issues. First, because js::Vector is a +// distinct type from mozilla::Vector, overload resolution, method calls, etc. +// are affected. *Hopefully* this won't be too bad in practice. (A bunch of +// places had to be fixed when mozilla::Vector was introduced, but it wasn't a +// crazy number.) Second, mozilla::Vector's interface has to be made subclass- +// ready via CRTP -- or rather, via mozilla::VectorBase, which basically no one +// should use. :-) Third, we have to redefine the constructors and the non- +// inherited operators. Blech. Happily there aren't too many of these, so it +// isn't the end of the world. + +template +class Vector + : public mozilla::VectorBase > +{ + typedef typename mozilla::VectorBase Base; + + public: + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + Vector(Vector &&vec) : Base(mozilla::Move(vec)) {} + Vector &operator=(Vector &&vec) { + return Base::operator=(mozilla::Move(vec)); + } +}; + +} // namespace js + +#endif /* js_Vector_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsalloc.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsalloc.h new file mode 100644 index 0000000000..a1e547cec9 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsalloc.h @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * JS allocation policies. + * + * The allocators here are for system memory with lifetimes which are not + * managed by the GC. See the comment at the top of vm/MallocProvider.h. + */ + +#ifndef jsalloc_h +#define jsalloc_h + +#include "js/TypeDecls.h" +#include "js/Utility.h" + +namespace js { + +struct ContextFriendFields; + +/* Policy for using system memory functions and doing no error reporting. */ +class SystemAllocPolicy +{ + public: + void *malloc_(size_t bytes) { return js_malloc(bytes); } + void *calloc_(size_t bytes) { return js_calloc(bytes); } + void *realloc_(void *p, size_t oldBytes, size_t bytes) { return js_realloc(p, bytes); } + void free_(void *p) { js_free(p); } + void reportAllocOverflow() const {} +}; + +/* + * Allocation policy that calls the system memory functions and reports errors + * to the context. Since the JSContext given on construction is stored for + * the lifetime of the container, this policy may only be used for containers + * whose lifetime is a shorter than the given JSContext. + * + * FIXME bug 647103 - rewrite this in terms of temporary allocation functions, + * not the system ones. + */ +class TempAllocPolicy +{ + ContextFriendFields *const cx_; + + /* + * Non-inline helper to call JSRuntime::onOutOfMemory with minimal + * code bloat. + */ + JS_FRIEND_API(void *) onOutOfMemory(void *p, size_t nbytes); + + public: + MOZ_IMPLICIT TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( + MOZ_IMPLICIT TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} + + void *malloc_(size_t bytes) { + void *p = js_malloc(bytes); + if (MOZ_UNLIKELY(!p)) + p = onOutOfMemory(nullptr, bytes); + return p; + } + + void *calloc_(size_t bytes) { + void *p = js_calloc(bytes); + if (MOZ_UNLIKELY(!p)) + p = onOutOfMemory(nullptr, bytes); + return p; + } + + void *realloc_(void *p, size_t oldBytes, size_t bytes) { + void *p2 = js_realloc(p, bytes); + if (MOZ_UNLIKELY(!p2)) + p2 = onOutOfMemory(p2, bytes); + return p2; + } + + void free_(void *p) { + js_free(p); + } + + JS_FRIEND_API(void) reportAllocOverflow() const; +}; + +} /* namespace js */ + +#endif /* jsalloc_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsapi.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsapi.h new file mode 100644 index 0000000000..4c4a24dfeb --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsapi.h @@ -0,0 +1,5250 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JavaScript API. */ + +#ifndef jsapi_h +#define jsapi_h + +#include "mozilla/Char16.h" +#include "mozilla/FloatingPoint.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/Range.h" +#include "mozilla/RangedPtr.h" +#include "mozilla/TypedEnum.h" + +#include +#include +#include +#include + +#include "jsalloc.h" +#include "jspubtd.h" + +#include "js/CallArgs.h" +#include "js/Class.h" +#include "js/HashTable.h" +#include "js/Id.h" +#include "js/Principals.h" +#include "js/RootingAPI.h" +#include "js/TracingAPI.h" +#include "js/Utility.h" +#include "js/Value.h" +#include "js/Vector.h" + +/************************************************************************/ + +namespace JS { + +class Latin1CharsZ; +class TwoByteChars; + +#if defined JS_THREADSAFE && defined JS_DEBUG + +class JS_PUBLIC_API(AutoCheckRequestDepth) +{ + JSContext *cx; + public: + explicit AutoCheckRequestDepth(JSContext *cx); + explicit AutoCheckRequestDepth(js::ContextFriendFields *cx); + ~AutoCheckRequestDepth(); +}; + +# define CHECK_REQUEST(cx) \ + JS::AutoCheckRequestDepth _autoCheckRequestDepth(cx) + +#else + +# define CHECK_REQUEST(cx) \ + ((void) 0) + +#endif /* JS_THREADSAFE && JS_DEBUG */ + +#ifdef JS_DEBUG +/* + * Assert that we're not doing GC on cx, that we're in a request as + * needed, and that the compartments for cx and v are correct. + * Also check that GC would be safe at this point. + */ +JS_PUBLIC_API(void) +AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v); +#else +inline void AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v) { + /* Do nothing */ +} +#endif /* JS_DEBUG */ + +/* AutoValueArray roots an internal fixed-size array of Values. */ +template +class AutoValueArray : public AutoGCRooter +{ + const size_t length_; + Value elements_[N]; + + public: + explicit AutoValueArray(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, VALARRAY), length_(N) + { + /* Always initialize in case we GC before assignment. */ + mozilla::PodArrayZero(elements_); + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + unsigned length() const { return length_; } + const Value *begin() const { return elements_; } + Value *begin() { return elements_; } + + HandleValue operator[](unsigned i) const { + JS_ASSERT(i < N); + return HandleValue::fromMarkedLocation(&elements_[i]); + } + MutableHandleValue operator[](unsigned i) { + JS_ASSERT(i < N); + return MutableHandleValue::fromMarkedLocation(&elements_[i]); + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +template +class AutoVectorRooter : protected AutoGCRooter +{ + typedef js::Vector VectorImpl; + VectorImpl vector; + + public: + explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, tag), vector(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + explicit AutoVectorRooter(js::ContextFriendFields *cx, ptrdiff_t tag + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, tag), vector(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + typedef T ElementType; + typedef typename VectorImpl::Range Range; + + size_t length() const { return vector.length(); } + bool empty() const { return vector.empty(); } + + bool append(const T &v) { return vector.append(v); } + bool append(const T *ptr, size_t len) { return vector.append(ptr, len); } + bool appendAll(const AutoVectorRooter &other) { + return vector.appendAll(other.vector); + } + + bool insert(T *p, const T &val) { return vector.insert(p, val); } + + /* For use when space has already been reserved. */ + void infallibleAppend(const T &v) { vector.infallibleAppend(v); } + + void popBack() { vector.popBack(); } + T popCopy() { return vector.popCopy(); } + + bool growBy(size_t inc) { + size_t oldLength = vector.length(); + if (!vector.growByUninitialized(inc)) + return false; + makeRangeGCSafe(oldLength); + return true; + } + + bool resize(size_t newLength) { + size_t oldLength = vector.length(); + if (newLength <= oldLength) { + vector.shrinkBy(oldLength - newLength); + return true; + } + if (!vector.growByUninitialized(newLength - oldLength)) + return false; + makeRangeGCSafe(oldLength); + return true; + } + + void clear() { vector.clear(); } + + bool reserve(size_t newLength) { + return vector.reserve(newLength); + } + + JS::MutableHandle operator[](size_t i) { + return JS::MutableHandle::fromMarkedLocation(&vector[i]); + } + JS::Handle operator[](size_t i) const { + return JS::Handle::fromMarkedLocation(&vector[i]); + } + + const T *begin() const { return vector.begin(); } + T *begin() { return vector.begin(); } + + const T *end() const { return vector.end(); } + T *end() { return vector.end(); } + + Range all() { return vector.all(); } + + const T &back() const { return vector.back(); } + + friend void AutoGCRooter::trace(JSTracer *trc); + + private: + void makeRangeGCSafe(size_t oldLength) { + T *t = vector.begin() + oldLength; + for (size_t i = oldLength; i < vector.length(); ++i, ++t) + memset(t, 0, sizeof(T)); + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +template +class AutoHashMapRooter : protected AutoGCRooter +{ + private: + typedef js::HashMap HashMapImpl; + + public: + explicit AutoHashMapRooter(JSContext *cx, ptrdiff_t tag + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, tag), map(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + typedef Key KeyType; + typedef Value ValueType; + typedef typename HashMapImpl::Entry Entry; + typedef typename HashMapImpl::Lookup Lookup; + typedef typename HashMapImpl::Ptr Ptr; + typedef typename HashMapImpl::AddPtr AddPtr; + + bool init(uint32_t len = 16) { + return map.init(len); + } + bool initialized() const { + return map.initialized(); + } + Ptr lookup(const Lookup &l) const { + return map.lookup(l); + } + void remove(Ptr p) { + map.remove(p); + } + AddPtr lookupForAdd(const Lookup &l) const { + return map.lookupForAdd(l); + } + + template + bool add(AddPtr &p, const KeyInput &k, const ValueInput &v) { + return map.add(p, k, v); + } + + bool add(AddPtr &p, const Key &k) { + return map.add(p, k); + } + + template + bool relookupOrAdd(AddPtr &p, const KeyInput &k, const ValueInput &v) { + return map.relookupOrAdd(p, k, v); + } + + typedef typename HashMapImpl::Range Range; + Range all() const { + return map.all(); + } + + typedef typename HashMapImpl::Enum Enum; + + void clear() { + map.clear(); + } + + void finish() { + map.finish(); + } + + bool empty() const { + return map.empty(); + } + + uint32_t count() const { + return map.count(); + } + + size_t capacity() const { + return map.capacity(); + } + + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return map.sizeOfExcludingThis(mallocSizeOf); + } + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return map.sizeOfIncludingThis(mallocSizeOf); + } + + uint32_t generation() const { + return map.generation(); + } + + /************************************************** Shorthand operations */ + + bool has(const Lookup &l) const { + return map.has(l); + } + + template + bool put(const KeyInput &k, const ValueInput &v) { + return map.put(k, v); + } + + template + bool putNew(const KeyInput &k, const ValueInput &v) { + return map.putNew(k, v); + } + + Ptr lookupWithDefault(const Key &k, const Value &defaultValue) { + return map.lookupWithDefault(k, defaultValue); + } + + void remove(const Lookup &l) { + map.remove(l); + } + + friend void AutoGCRooter::trace(JSTracer *trc); + + private: + AutoHashMapRooter(const AutoHashMapRooter &hmr) MOZ_DELETE; + AutoHashMapRooter &operator=(const AutoHashMapRooter &hmr) MOZ_DELETE; + + HashMapImpl map; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +template +class AutoHashSetRooter : protected AutoGCRooter +{ + private: + typedef js::HashSet HashSetImpl; + + public: + explicit AutoHashSetRooter(JSContext *cx, ptrdiff_t tag + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, tag), set(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + typedef typename HashSetImpl::Lookup Lookup; + typedef typename HashSetImpl::Ptr Ptr; + typedef typename HashSetImpl::AddPtr AddPtr; + + bool init(uint32_t len = 16) { + return set.init(len); + } + bool initialized() const { + return set.initialized(); + } + Ptr lookup(const Lookup &l) const { + return set.lookup(l); + } + void remove(Ptr p) { + set.remove(p); + } + AddPtr lookupForAdd(const Lookup &l) const { + return set.lookupForAdd(l); + } + + bool add(AddPtr &p, const T &t) { + return set.add(p, t); + } + + bool relookupOrAdd(AddPtr &p, const Lookup &l, const T &t) { + return set.relookupOrAdd(p, l, t); + } + + typedef typename HashSetImpl::Range Range; + Range all() const { + return set.all(); + } + + typedef typename HashSetImpl::Enum Enum; + + void clear() { + set.clear(); + } + + void finish() { + set.finish(); + } + + bool empty() const { + return set.empty(); + } + + uint32_t count() const { + return set.count(); + } + + size_t capacity() const { + return set.capacity(); + } + + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return set.sizeOfExcludingThis(mallocSizeOf); + } + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return set.sizeOfIncludingThis(mallocSizeOf); + } + + uint32_t generation() const { + return set.generation(); + } + + /************************************************** Shorthand operations */ + + bool has(const Lookup &l) const { + return set.has(l); + } + + bool put(const T &t) { + return set.put(t); + } + + bool putNew(const T &t) { + return set.putNew(t); + } + + void remove(const Lookup &l) { + set.remove(l); + } + + friend void AutoGCRooter::trace(JSTracer *trc); + + private: + AutoHashSetRooter(const AutoHashSetRooter &hmr) MOZ_DELETE; + AutoHashSetRooter &operator=(const AutoHashSetRooter &hmr) MOZ_DELETE; + + HashSetImpl set; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class MOZ_STACK_CLASS AutoValueVector : public AutoVectorRooter +{ + public: + explicit AutoValueVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, VALVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class AutoIdVector : public AutoVectorRooter +{ + public: + explicit AutoIdVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, IDVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class AutoObjectVector : public AutoVectorRooter +{ + public: + explicit AutoObjectVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, OBJVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class AutoFunctionVector : public AutoVectorRooter +{ + public: + explicit AutoFunctionVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, FUNVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + explicit AutoFunctionVector(js::ContextFriendFields *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, FUNVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class AutoScriptVector : public AutoVectorRooter +{ + public: + explicit AutoScriptVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, SCRIPTVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* + * Custom rooting behavior for internal and external clients. + */ +class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter +{ + public: + template + explicit CustomAutoRooter(CX *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, CUSTOM) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + friend void AutoGCRooter::trace(JSTracer *trc); + + protected: + /* Supplied by derived class to trace roots. */ + virtual void trace(JSTracer *trc) = 0; + + private: + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* + * RootedGeneric allows a class to instantiate its own Rooted type by + * including the method: + * + * void trace(JSTracer *trc); + * + * The trace() method must trace all of the class's fields. + */ +template +class RootedGeneric : private CustomAutoRooter +{ + public: + template + explicit RootedGeneric(CX *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + template + explicit RootedGeneric(CX *cx, const T& initial MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx), value(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + operator const T&() const { return value; } + T operator->() const { return value; } + + private: + virtual void trace(JSTracer *trc) { value->trace(trc); } + + T value; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* A handle to an array of rooted values. */ +class HandleValueArray +{ + const size_t length_; + const Value * const elements_; + + HandleValueArray(size_t len, const Value *elements) : length_(len), elements_(elements) {} + + public: + explicit HandleValueArray(const RootedValue& value) : length_(1), elements_(value.address()) {} + + MOZ_IMPLICIT HandleValueArray(const AutoValueVector& values) + : length_(values.length()), elements_(values.begin()) {} + + template + HandleValueArray(const AutoValueArray& values) : length_(N), elements_(values.begin()) {} + + /* CallArgs must already be rooted somewhere up the stack. */ + MOZ_IMPLICIT HandleValueArray(const JS::CallArgs& args) : length_(args.length()), elements_(args.array()) {} + + /* Use with care! Only call this if the data is guaranteed to be marked. */ + static HandleValueArray fromMarkedLocation(size_t len, const Value *elements) { + return HandleValueArray(len, elements); + } + + static HandleValueArray subarray(const HandleValueArray& values, size_t startIndex, size_t len) { + JS_ASSERT(startIndex + len <= values.length()); + return HandleValueArray(len, values.begin() + startIndex); + } + + static HandleValueArray empty() { + return HandleValueArray(0, nullptr); + } + + size_t length() const { return length_; } + const Value *begin() const { return elements_; } + + HandleValue operator[](size_t i) const { + JS_ASSERT(i < length_); + return HandleValue::fromMarkedLocation(&elements_[i]); + } +}; + +} /* namespace JS */ + +/************************************************************************/ + +struct JSFreeOp { + private: + JSRuntime *runtime_; + + protected: + explicit JSFreeOp(JSRuntime *rt) + : runtime_(rt) { } + + public: + JSRuntime *runtime() const { + return runtime_; + } +}; + +/* Callbacks and their arguments. */ + +/************************************************************************/ + +typedef enum JSContextOp { + JSCONTEXT_NEW, + JSCONTEXT_DESTROY +} JSContextOp; + +/* + * The possible values for contextOp when the runtime calls the callback are: + * JSCONTEXT_NEW JS_NewContext successfully created a new JSContext + * instance. The callback can initialize the instance as + * required. If the callback returns false, the instance + * will be destroyed and JS_NewContext returns null. In + * this case the callback is not called again. + * JSCONTEXT_DESTROY One of JS_DestroyContext* methods is called. The + * callback may perform its own cleanup and must always + * return true. + * Any other value For future compatibility the callback must do nothing + * and return true in this case. + */ +typedef bool +(* JSContextCallback)(JSContext *cx, unsigned contextOp, void *data); + +typedef enum JSGCStatus { + JSGC_BEGIN, + JSGC_END +} JSGCStatus; + +typedef void +(* JSGCCallback)(JSRuntime *rt, JSGCStatus status, void *data); + +typedef enum JSFinalizeStatus { + /* + * Called when preparing to sweep a group of compartments, before anything + * has been swept. The collector will not yield to the mutator before + * calling the callback with JSFINALIZE_GROUP_END status. + */ + JSFINALIZE_GROUP_START, + + /* + * Called when preparing to sweep a group of compartments. Weak references + * to unmarked things have been removed and things that are not swept + * incrementally have been finalized at this point. The collector may yield + * to the mutator after this point. + */ + JSFINALIZE_GROUP_END, + + /* + * Called at the end of collection when everything has been swept. + */ + JSFINALIZE_COLLECTION_END +} JSFinalizeStatus; + +typedef void +(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment, void *data); + +typedef bool +(* JSInterruptCallback)(JSContext *cx); + +typedef void +(* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report); + +#ifdef MOZ_TRACE_JSCALLS +typedef void +(* JSFunctionCallback)(const JSFunction *fun, + const JSScript *scr, + const JSContext *cx, + int entering); +#endif + +/* + * Possible exception types. These types are part of a JSErrorFormatString + * structure. They define which error to throw in case of a runtime error. + * JSEXN_NONE marks an unthrowable error. + */ +typedef enum JSExnType { + JSEXN_NONE = -1, + JSEXN_ERR, + JSEXN_INTERNALERR, + JSEXN_EVALERR, + JSEXN_RANGEERR, + JSEXN_REFERENCEERR, + JSEXN_SYNTAXERR, + JSEXN_TYPEERR, + JSEXN_URIERR, + JSEXN_LIMIT +} JSExnType; + +typedef struct JSErrorFormatString { + /* The error format string in ASCII. */ + const char *format; + + /* The number of arguments to expand in the formatted error message. */ + uint16_t argCount; + + /* One of the JSExnType constants above. */ + int16_t exnType; +} JSErrorFormatString; + +typedef const JSErrorFormatString * +(* JSErrorCallback)(void *userRef, const unsigned errorNumber); + +typedef bool +(* JSLocaleToUpperCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); + +typedef bool +(* JSLocaleToLowerCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); + +typedef bool +(* JSLocaleCompare)(JSContext *cx, JS::HandleString src1, JS::HandleString src2, + JS::MutableHandleValue rval); + +typedef bool +(* JSLocaleToUnicode)(JSContext *cx, const char *src, JS::MutableHandleValue rval); + +/* + * Callback used to ask the embedding for the cross compartment wrapper handler + * that implements the desired prolicy for this kind of object in the + * destination compartment. |obj| is the object to be wrapped. If |existing| is + * non-nullptr, it will point to an existing wrapper object that should be + * re-used if possible. |existing| is guaranteed to be a cross-compartment + * wrapper with a lazily-defined prototype and the correct global. It is + * guaranteed not to wrap a function. + */ +typedef JSObject * +(* JSWrapObjectCallback)(JSContext *cx, JS::HandleObject existing, JS::HandleObject obj, + JS::HandleObject parent, unsigned flags); + +/* + * Callback used by the wrap hook to ask the embedding to prepare an object + * for wrapping in a context. This might include unwrapping other wrappers + * or even finding a more suitable object for the new compartment. + */ +typedef JSObject * +(* JSPreWrapCallback)(JSContext *cx, JS::HandleObject scope, JS::HandleObject obj, + unsigned flags); + +struct JSWrapObjectCallbacks +{ + JSWrapObjectCallback wrap; + JSPreWrapCallback preWrap; +}; + +typedef void +(* JSDestroyCompartmentCallback)(JSFreeOp *fop, JSCompartment *compartment); + +typedef void +(* JSZoneCallback)(JS::Zone *zone); + +typedef void +(* JSCompartmentNameCallback)(JSRuntime *rt, JSCompartment *compartment, + char *buf, size_t bufsize); + +/************************************************************************/ + +static MOZ_ALWAYS_INLINE jsval +JS_NumberValue(double d) +{ + int32_t i; + d = JS::CanonicalizeNaN(d); + if (mozilla::NumberIsInt32(d, &i)) + return INT_TO_JSVAL(i); + return DOUBLE_TO_JSVAL(d); +} + +/************************************************************************/ + +JS_PUBLIC_API(bool) +JS_StringHasBeenInterned(JSContext *cx, JSString *str); + +/* + * Only JSStrings that have been interned via the JSAPI can be turned into + * jsids by API clients. + * + * N.B. if a jsid is backed by a string which has not been interned, that + * string must be appropriately rooted to avoid being collected by the GC. + */ +JS_PUBLIC_API(jsid) +INTERNED_STRING_TO_JSID(JSContext *cx, JSString *str); + +namespace JS { + +// Container class for passing in script source buffers to the JS engine. This +// not only groups the buffer and length values, it also provides a way to +// optionally pass ownership of the buffer to the JS engine without copying. +// Rules for use: +// +// 1) The data array must be allocated with js_malloc() or js_realloc() if +// ownership is being granted to the SourceBufferHolder. +// 2) If ownership is not given to the SourceBufferHolder, then the memory +// must be kept alive until the JS compilation is complete. +// 3) Any code calling SourceBufferHolder::take() must guarantee to keep the +// memory alive until JS compilation completes. Normally only the JS +// engine should be calling take(). +// +// Example use: +// +// size_t length = 512; +// jschar* chars = static_cast(js_malloc(sizeof(jschar) * length)); +// JS::SourceBufferHolder srcBuf(chars, length, JS::SourceBufferHolder::GiveOwnership); +// JS::Compile(cx, obj, options, srcBuf); +// +class MOZ_STACK_CLASS SourceBufferHolder MOZ_FINAL +{ + public: + enum Ownership { + NoOwnership, + GiveOwnership + }; + + SourceBufferHolder(const jschar *data, size_t dataLength, Ownership ownership) + : data_(data), + length_(dataLength), + ownsChars_(ownership == GiveOwnership) + { + // Ensure that null buffers properly return an unowned, empty, + // null-terminated string. + static const jschar NullChar_ = 0; + if (!get()) { + data_ = &NullChar_; + length_ = 0; + ownsChars_ = false; + } + } + + ~SourceBufferHolder() { + if (ownsChars_) + js_free(const_cast(data_)); + } + + // Access the underlying source buffer without affecting ownership. + const jschar *get() const { return data_; } + + // Length of the source buffer in jschars (not bytes) + size_t length() const { return length_; } + + // Returns true if the SourceBufferHolder owns the buffer and will free + // it upon destruction. If true, it is legal to call take(). + bool ownsChars() const { return ownsChars_; } + + // Retrieve and take ownership of the underlying data buffer. The caller + // is now responsible for calling js_free() on the returned value, *but only + // after JS script compilation has completed*. + // + // After the buffer has been taken the SourceBufferHolder functions as if + // it had been constructed on an unowned buffer; get() and length() still + // work. In order for this to be safe the taken buffer must be kept alive + // until after JS script compilation completes as noted above. + // + // Note, it's the caller's responsibility to check ownsChars() before taking + // the buffer. Taking and then free'ing an unowned buffer will have dire + // consequences. + jschar *take() { + JS_ASSERT(ownsChars_); + ownsChars_ = false; + return const_cast(data_); + } + + private: + SourceBufferHolder(SourceBufferHolder &) MOZ_DELETE; + SourceBufferHolder &operator=(SourceBufferHolder &) MOZ_DELETE; + + const jschar *data_; + size_t length_; + bool ownsChars_; +}; + +} /* namespace JS */ + +/************************************************************************/ + +/* Property attributes, set in JSPropertySpec and passed to API functions. */ +#define JSPROP_ENUMERATE 0x01 /* property is visible to for/in loop */ +#define JSPROP_READONLY 0x02 /* not settable: assignment is no-op. + This flag is only valid when neither + JSPROP_GETTER nor JSPROP_SETTER is + set. */ +#define JSPROP_PERMANENT 0x04 /* property cannot be deleted */ +#define JSPROP_NATIVE_ACCESSORS 0x08 /* set in JSPropertyDescriptor.flags + if getters/setters are JSNatives */ +#define JSPROP_GETTER 0x10 /* property holds getter function */ +#define JSPROP_SETTER 0x20 /* property holds setter function */ +#define JSPROP_SHARED 0x40 /* don't allocate a value slot for this + property; don't copy the property on + set of the same-named property in an + object that delegates to a prototype + containing this property */ +#define JSPROP_INDEX 0x80 /* name is actually (int) index */ + +#define JSFUN_STUB_GSOPS 0x200 /* use JS_PropertyStub getter/setter + instead of defaulting to class gsops + for property holding function */ + +#define JSFUN_CONSTRUCTOR 0x400 /* native that can be called as a ctor */ + + +/* + * Specify a generic native prototype methods, i.e., methods of a class + * prototype that are exposed as static methods taking an extra leading + * argument: the generic |this| parameter. + * + * If you set this flag in a JSFunctionSpec struct's flags initializer, then + * that struct must live at least as long as the native static method object + * created due to this flag by JS_DefineFunctions or JS_InitClass. Typically + * JSFunctionSpec structs are allocated in static arrays. + */ +#define JSFUN_GENERIC_NATIVE 0x800 + +#define JSFUN_FLAGS_MASK 0xe00 /* | of all the JSFUN_* flags */ + +/* + * The first call to JS_CallOnce by any thread in a process will call 'func'. + * Later calls to JS_CallOnce with the same JSCallOnceType object will be + * suppressed. + * + * Equivalently: each distinct JSCallOnceType object will allow one JS_CallOnce + * to invoke its JSInitCallback. + */ +extern JS_PUBLIC_API(bool) +JS_CallOnce(JSCallOnceType *once, JSInitCallback func); + +/* Microseconds since the epoch, midnight, January 1, 1970 UTC. */ +extern JS_PUBLIC_API(int64_t) +JS_Now(void); + +/* Don't want to export data, so provide accessors for non-inline jsvals. */ +extern JS_PUBLIC_API(jsval) +JS_GetNaNValue(JSContext *cx); + +extern JS_PUBLIC_API(jsval) +JS_GetNegativeInfinityValue(JSContext *cx); + +extern JS_PUBLIC_API(jsval) +JS_GetPositiveInfinityValue(JSContext *cx); + +extern JS_PUBLIC_API(jsval) +JS_GetEmptyStringValue(JSContext *cx); + +extern JS_PUBLIC_API(JSString *) +JS_GetEmptyString(JSRuntime *rt); + +/* + * Format is a string of the following characters (spaces are insignificant), + * specifying the tabulated type conversions: + * + * b bool Boolean + * c uint16_t/jschar ECMA uint16_t, Unicode char + * i int32_t ECMA int32_t + * j int32_t ECMA int32_t (used to be different) + * u uint32_t ECMA uint32_t + * d double IEEE double + * I double Integral IEEE double + * S JSString * Unicode string, accessed by a JSString pointer + * W jschar * Unicode character vector, 0-terminated (W for wide) + * o JSObject * Object reference + * f JSFunction * Function private + * v jsval Argument value (no conversion) + * * N/A Skip this argument (no vararg) + * / N/A End of required arguments + * + * The variable argument list after format must consist of &b, &c, &s, e.g., + * where those variables have the types given above. For the pointer types + * char *, JSString *, and JSObject *, the pointed-at memory returned belongs + * to the JS runtime, not to the calling native code. The runtime promises + * to keep this memory valid so long as argv refers to allocated stack space + * (so long as the native function is active). + * + * Fewer arguments than format specifies may be passed only if there is a / + * in format after the last required argument specifier and argc is at least + * the number of required arguments. More arguments than format specifies + * may be passed without error; it is up to the caller to deal with trailing + * unconverted arguments. + */ +extern JS_PUBLIC_API(bool) +JS_ConvertArguments(JSContext *cx, const JS::CallArgs &args, const char *format, ...); + +#ifdef va_start +extern JS_PUBLIC_API(bool) +JS_ConvertArgumentsVA(JSContext *cx, const JS::CallArgs &args, const char *format, + va_list ap); +#endif + +extern JS_PUBLIC_API(bool) +JS_ConvertValue(JSContext *cx, JS::HandleValue v, JSType type, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ValueToObject(JSContext *cx, JS::HandleValue v, JS::MutableHandleObject objp); + +extern JS_PUBLIC_API(JSFunction *) +JS_ValueToFunction(JSContext *cx, JS::HandleValue v); + +extern JS_PUBLIC_API(JSFunction *) +JS_ValueToConstructor(JSContext *cx, JS::HandleValue v); + +extern JS_PUBLIC_API(JSString *) +JS_ValueToSource(JSContext *cx, JS::Handle v); + +namespace js { +/* + * DO NOT CALL THIS. Use JS::ToNumber + */ +extern JS_PUBLIC_API(bool) +ToNumberSlow(JSContext *cx, JS::Value v, double *dp); + +/* + * DO NOT CALL THIS. Use JS::ToBoolean + */ +extern JS_PUBLIC_API(bool) +ToBooleanSlow(JS::HandleValue v); + +/* + * DO NOT CALL THIS. Use JS::ToString + */ +extern JS_PUBLIC_API(JSString*) +ToStringSlow(JSContext *cx, JS::HandleValue v); +} /* namespace js */ + +namespace JS { + +/* ES5 9.3 ToNumber. */ +MOZ_ALWAYS_INLINE bool +ToNumber(JSContext *cx, HandleValue v, double *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isNumber()) { + *out = v.toNumber(); + return true; + } + return js::ToNumberSlow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToBoolean(HandleValue v) +{ + if (v.isBoolean()) + return v.toBoolean(); + if (v.isInt32()) + return v.toInt32() != 0; + if (v.isNullOrUndefined()) + return false; + if (v.isDouble()) { + double d = v.toDouble(); + return !mozilla::IsNaN(d) && d != 0; + } + if (v.isSymbol()) + return true; + + /* The slow path handles strings and objects. */ + return js::ToBooleanSlow(v); +} + +MOZ_ALWAYS_INLINE JSString* +ToString(JSContext *cx, HandleValue v) +{ + if (v.isString()) + return v.toString(); + return js::ToStringSlow(cx, v); +} + +} /* namespace JS */ + +extern JS_PUBLIC_API(bool) +JS_DoubleIsInt32(double d, int32_t *ip); + +extern JS_PUBLIC_API(int32_t) +JS_DoubleToInt32(double d); + +extern JS_PUBLIC_API(uint32_t) +JS_DoubleToUint32(double d); + + +namespace js { +/* DO NOT CALL THIS. Use JS::ToUint16. */ +extern JS_PUBLIC_API(bool) +ToUint16Slow(JSContext *cx, JS::HandleValue v, uint16_t *out); + +/* DO NOT CALL THIS. Use JS::ToInt32. */ +extern JS_PUBLIC_API(bool) +ToInt32Slow(JSContext *cx, JS::HandleValue v, int32_t *out); + +/* DO NOT CALL THIS. Use JS::ToUint32. */ +extern JS_PUBLIC_API(bool) +ToUint32Slow(JSContext *cx, JS::HandleValue v, uint32_t *out); + +/* DO NOT CALL THIS. Use JS::ToInt64. */ +extern JS_PUBLIC_API(bool) +ToInt64Slow(JSContext *cx, JS::HandleValue v, int64_t *out); + +/* DO NOT CALL THIS. Use JS::ToUint64. */ +extern JS_PUBLIC_API(bool) +ToUint64Slow(JSContext *cx, JS::HandleValue v, uint64_t *out); +} /* namespace js */ + +namespace JS { + +MOZ_ALWAYS_INLINE bool +ToUint16(JSContext *cx, JS::HandleValue v, uint16_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + *out = uint16_t(v.toInt32()); + return true; + } + return js::ToUint16Slow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToInt32(JSContext *cx, JS::HandleValue v, int32_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + *out = v.toInt32(); + return true; + } + return js::ToInt32Slow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToUint32(JSContext *cx, JS::HandleValue v, uint32_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + *out = uint32_t(v.toInt32()); + return true; + } + return js::ToUint32Slow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToInt64(JSContext *cx, JS::HandleValue v, int64_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + *out = int64_t(v.toInt32()); + return true; + } + return js::ToInt64Slow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToUint64(JSContext *cx, JS::HandleValue v, uint64_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + /* Account for sign extension of negatives into the longer 64bit space. */ + *out = uint64_t(int64_t(v.toInt32())); + return true; + } + return js::ToUint64Slow(cx, v, out); +} + + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSType) +JS_TypeOfValue(JSContext *cx, JS::Handle v); + +extern JS_PUBLIC_API(const char *) +JS_GetTypeName(JSContext *cx, JSType type); + +extern JS_PUBLIC_API(bool) +JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal); + +extern JS_PUBLIC_API(bool) +JS_LooselyEqual(JSContext *cx, JS::Handle v1, JS::Handle v2, bool *equal); + +extern JS_PUBLIC_API(bool) +JS_SameValue(JSContext *cx, jsval v1, jsval v2, bool *same); + +/* True iff fun is the global eval function. */ +extern JS_PUBLIC_API(bool) +JS_IsBuiltinEvalFunction(JSFunction *fun); + +/* True iff fun is the Function constructor. */ +extern JS_PUBLIC_API(bool) +JS_IsBuiltinFunctionConstructor(JSFunction *fun); + +/************************************************************************/ + +/* + * Initialization, locking, contexts, and memory allocation. + * + * It is important that the first runtime and first context be created in a + * single-threaded fashion, otherwise the behavior of the library is undefined. + * See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference + */ + +/** + * Initialize SpiderMonkey, returning true only if initialization succeeded. + * Once this method has succeeded, it is safe to call JS_NewRuntime and other + * JSAPI methods. + * + * This method must be called before any other JSAPI method is used on any + * thread. Once it has been used, it is safe to call any JSAPI method, and it + * remains safe to do so until JS_ShutDown is correctly called. + * + * It is currently not possible to initialize SpiderMonkey multiple times (that + * is, calling JS_Init/JSAPI methods/JS_ShutDown in that order, then doing so + * again). This restriction may eventually be lifted. + */ +extern JS_PUBLIC_API(bool) +JS_Init(void); + +/** + * Destroy free-standing resources allocated by SpiderMonkey, not associated + * with any runtime, context, or other structure. + * + * This method should be called after all other JSAPI data has been properly + * cleaned up: every new runtime must have been destroyed, every new context + * must have been destroyed, and so on. Calling this method before all other + * resources have been destroyed has undefined behavior. + * + * Failure to call this method, at present, has no adverse effects other than + * leaking memory. This may not always be the case; it's recommended that all + * embedders call this method when all other JSAPI operations have completed. + * + * It is currently not possible to initialize SpiderMonkey multiple times (that + * is, calling JS_Init/JSAPI methods/JS_ShutDown in that order, then doing so + * again). This restriction may eventually be lifted. + */ +extern JS_PUBLIC_API(void) +JS_ShutDown(void); + +extern JS_PUBLIC_API(JSRuntime *) +JS_NewRuntime(uint32_t maxbytes, + uint32_t maxNurseryBytes = JS::DefaultNurseryBytes, + JSRuntime *parentRuntime = nullptr); + +extern JS_PUBLIC_API(void) +JS_DestroyRuntime(JSRuntime *rt); + +// These are equivalent to ICU's |UMemAllocFn|, |UMemReallocFn|, and +// |UMemFreeFn| types. The first argument (called |context| in the ICU docs) +// will always be nullptr, and should be ignored. +typedef void *(*JS_ICUAllocFn)(const void *, size_t size); +typedef void *(*JS_ICUReallocFn)(const void *, void *p, size_t size); +typedef void (*JS_ICUFreeFn)(const void *, void *p); + +// This function can be used to track memory used by ICU. +// Do not use it unless you know what you are doing! +extern JS_PUBLIC_API(bool) +JS_SetICUMemoryFunctions(JS_ICUAllocFn allocFn, JS_ICUReallocFn reallocFn, JS_ICUFreeFn freeFn); + +JS_PUBLIC_API(void *) +JS_GetRuntimePrivate(JSRuntime *rt); + +extern JS_PUBLIC_API(JSRuntime *) +JS_GetRuntime(JSContext *cx); + +extern JS_PUBLIC_API(JSRuntime *) +JS_GetParentRuntime(JSContext *cx); + +JS_PUBLIC_API(void) +JS_SetRuntimePrivate(JSRuntime *rt, void *data); + +extern JS_PUBLIC_API(void) +JS_BeginRequest(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_EndRequest(JSContext *cx); + +extern JS_PUBLIC_API(bool) +JS_IsInRequest(JSRuntime *rt); + +namespace js { + +void +AssertHeapIsIdle(JSRuntime *rt); + +void +AssertHeapIsIdle(JSContext *cx); + +} /* namespace js */ + +class JSAutoRequest +{ + public: + explicit JSAutoRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mContext(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + JS_BeginRequest(mContext); + } + ~JSAutoRequest() { + JS_EndRequest(mContext); + } + + protected: + JSContext *mContext; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + +#if 0 + private: + static void *operator new(size_t) CPP_THROW_NEW { return 0; }; + static void operator delete(void *, size_t) { }; +#endif +}; + +class JSAutoCheckRequest +{ + public: + explicit JSAutoCheckRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + { +#if defined JS_THREADSAFE && defined JS_DEBUG + mContext = cx; + JS_ASSERT(JS_IsInRequest(JS_GetRuntime(cx))); +#endif + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + ~JSAutoCheckRequest() { +#if defined JS_THREADSAFE && defined JS_DEBUG + JS_ASSERT(JS_IsInRequest(JS_GetRuntime(mContext))); +#endif + } + + + private: +#if defined JS_THREADSAFE && defined JS_DEBUG + JSContext *mContext; +#endif + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +extern JS_PUBLIC_API(void) +JS_SetContextCallback(JSRuntime *rt, JSContextCallback cxCallback, void *data); + +extern JS_PUBLIC_API(JSContext *) +JS_NewContext(JSRuntime *rt, size_t stackChunkSize); + +extern JS_PUBLIC_API(void) +JS_DestroyContext(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_DestroyContextNoGC(JSContext *cx); + +extern JS_PUBLIC_API(void *) +JS_GetContextPrivate(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_SetContextPrivate(JSContext *cx, void *data); + +extern JS_PUBLIC_API(void *) +JS_GetSecondContextPrivate(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_SetSecondContextPrivate(JSContext *cx, void *data); + +extern JS_PUBLIC_API(JSRuntime *) +JS_GetRuntime(JSContext *cx); + +extern JS_PUBLIC_API(JSContext *) +JS_ContextIterator(JSRuntime *rt, JSContext **iterp); + +extern JS_PUBLIC_API(JSVersion) +JS_GetVersion(JSContext *cx); + +// Mutate the version on the compartment. This is generally discouraged, but +// necessary to support the version mutation in the js and xpc shell command +// set. +// +// It would be nice to put this in jsfriendapi, but the linkage requirements +// of the shells make that impossible. +JS_PUBLIC_API(void) +JS_SetVersionForCompartment(JSCompartment *compartment, JSVersion version); + +extern JS_PUBLIC_API(const char *) +JS_VersionToString(JSVersion version); + +extern JS_PUBLIC_API(JSVersion) +JS_StringToVersion(const char *string); + +namespace JS { + +class JS_PUBLIC_API(RuntimeOptions) { + public: + RuntimeOptions() + : baseline_(false), + ion_(false), + asmJS_(false), + nativeRegExp_(false), + werror_(false), + strictMode_(false), + varObjFix_(false) + { + } + + bool baseline() const { return baseline_; } + RuntimeOptions &setBaseline(bool flag) { + baseline_ = flag; + return *this; + } + RuntimeOptions &toggleBaseline() { + baseline_ = !baseline_; + return *this; + } + + bool ion() const { return ion_; } + RuntimeOptions &setIon(bool flag) { + ion_ = flag; + return *this; + } + RuntimeOptions &toggleIon() { + ion_ = !ion_; + return *this; + } + + bool asmJS() const { return asmJS_; } + RuntimeOptions &setAsmJS(bool flag) { + asmJS_ = flag; + return *this; + } + RuntimeOptions &toggleAsmJS() { + asmJS_ = !asmJS_; + return *this; + } + + bool nativeRegExp() const { return nativeRegExp_; } + RuntimeOptions &setNativeRegExp(bool flag) { + nativeRegExp_ = flag; + return *this; + } + + bool werror() const { return werror_; } + RuntimeOptions &setWerror(bool flag) { + werror_ = flag; + return *this; + } + RuntimeOptions &toggleWerror() { + werror_ = !werror_; + return *this; + } + + bool strictMode() const { return strictMode_; } + RuntimeOptions &setStrictMode(bool flag) { + strictMode_ = flag; + return *this; + } + RuntimeOptions &toggleStrictMode() { + strictMode_ = !strictMode_; + return *this; + } + + bool varObjFix() const { return varObjFix_; } + RuntimeOptions &setVarObjFix(bool flag) { + varObjFix_ = flag; + return *this; + } + RuntimeOptions &toggleVarObjFix() { + varObjFix_ = !varObjFix_; + return *this; + } + + private: + bool baseline_ : 1; + bool ion_ : 1; + bool asmJS_ : 1; + bool nativeRegExp_ : 1; + bool werror_ : 1; + bool strictMode_ : 1; + bool varObjFix_ : 1; +}; + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSRuntime *rt); + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSContext *cx); + +class JS_PUBLIC_API(ContextOptions) { + public: + ContextOptions() + : extraWarnings_(false), + privateIsNSISupports_(false), + dontReportUncaught_(false), + noDefaultCompartmentObject_(false), + noScriptRval_(false) + { + } + + bool extraWarnings() const { return extraWarnings_; } + ContextOptions &setExtraWarnings(bool flag) { + extraWarnings_ = flag; + return *this; + } + ContextOptions &toggleExtraWarnings() { + extraWarnings_ = !extraWarnings_; + return *this; + } + + bool privateIsNSISupports() const { return privateIsNSISupports_; } + ContextOptions &setPrivateIsNSISupports(bool flag) { + privateIsNSISupports_ = flag; + return *this; + } + ContextOptions &togglePrivateIsNSISupports() { + privateIsNSISupports_ = !privateIsNSISupports_; + return *this; + } + + bool dontReportUncaught() const { return dontReportUncaught_; } + ContextOptions &setDontReportUncaught(bool flag) { + dontReportUncaught_ = flag; + return *this; + } + ContextOptions &toggleDontReportUncaught() { + dontReportUncaught_ = !dontReportUncaught_; + return *this; + } + + bool noDefaultCompartmentObject() const { return noDefaultCompartmentObject_; } + ContextOptions &setNoDefaultCompartmentObject(bool flag) { + noDefaultCompartmentObject_ = flag; + return *this; + } + ContextOptions &toggleNoDefaultCompartmentObject() { + noDefaultCompartmentObject_ = !noDefaultCompartmentObject_; + return *this; + } + + bool noScriptRval() const { return noScriptRval_; } + ContextOptions &setNoScriptRval(bool flag) { + noScriptRval_ = flag; + return *this; + } + ContextOptions &toggleNoScriptRval() { + noScriptRval_ = !noScriptRval_; + return *this; + } + + private: + bool extraWarnings_ : 1; + bool privateIsNSISupports_ : 1; + bool dontReportUncaught_ : 1; + bool noDefaultCompartmentObject_ : 1; + bool noScriptRval_ : 1; +}; + +JS_PUBLIC_API(ContextOptions &) +ContextOptionsRef(JSContext *cx); + +class JS_PUBLIC_API(AutoSaveContextOptions) { + public: + explicit AutoSaveContextOptions(JSContext *cx) + : cx_(cx), + oldOptions_(ContextOptionsRef(cx_)) + { + } + + ~AutoSaveContextOptions() + { + ContextOptionsRef(cx_) = oldOptions_; + } + + private: + JSContext *cx_; + JS::ContextOptions oldOptions_; +}; + +} /* namespace JS */ + +extern JS_PUBLIC_API(const char *) +JS_GetImplementationVersion(void); + +extern JS_PUBLIC_API(void) +JS_SetDestroyCompartmentCallback(JSRuntime *rt, JSDestroyCompartmentCallback callback); + +extern JS_PUBLIC_API(void) +JS_SetDestroyZoneCallback(JSRuntime *rt, JSZoneCallback callback); + +extern JS_PUBLIC_API(void) +JS_SetSweepZoneCallback(JSRuntime *rt, JSZoneCallback callback); + +extern JS_PUBLIC_API(void) +JS_SetCompartmentNameCallback(JSRuntime *rt, JSCompartmentNameCallback callback); + +extern JS_PUBLIC_API(void) +JS_SetWrapObjectCallbacks(JSRuntime *rt, const JSWrapObjectCallbacks *callbacks); + +extern JS_PUBLIC_API(void) +JS_SetCompartmentPrivate(JSCompartment *compartment, void *data); + +extern JS_PUBLIC_API(void *) +JS_GetCompartmentPrivate(JSCompartment *compartment); + +extern JS_PUBLIC_API(void) +JS_SetZoneUserData(JS::Zone *zone, void *data); + +extern JS_PUBLIC_API(void *) +JS_GetZoneUserData(JS::Zone *zone); + +extern JS_PUBLIC_API(bool) +JS_WrapObject(JSContext *cx, JS::MutableHandleObject objp); + +extern JS_PUBLIC_API(bool) +JS_WrapValue(JSContext *cx, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(JSObject *) +JS_TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target); + +extern JS_PUBLIC_API(bool) +JS_RefreshCrossCompartmentWrappers(JSContext *cx, JS::Handle obj); + +/* + * At any time, a JSContext has a current (possibly-nullptr) compartment. + * Compartments are described in: + * + * developer.mozilla.org/en-US/docs/SpiderMonkey/SpiderMonkey_compartments + * + * The current compartment of a context may be changed. The preferred way to do + * this is with JSAutoCompartment: + * + * void foo(JSContext *cx, JSObject *obj) { + * // in some compartment 'c' + * { + * JSAutoCompartment ac(cx, obj); // constructor enters + * // in the compartment of 'obj' + * } // destructor leaves + * // back in compartment 'c' + * } + * + * For more complicated uses that don't neatly fit in a C++ stack frame, the + * compartment can entered and left using separate function calls: + * + * void foo(JSContext *cx, JSObject *obj) { + * // in 'oldCompartment' + * JSCompartment *oldCompartment = JS_EnterCompartment(cx, obj); + * // in the compartment of 'obj' + * JS_LeaveCompartment(cx, oldCompartment); + * // back in 'oldCompartment' + * } + * + * Note: these calls must still execute in a LIFO manner w.r.t all other + * enter/leave calls on the context. Furthermore, only the return value of a + * JS_EnterCompartment call may be passed as the 'oldCompartment' argument of + * the corresponding JS_LeaveCompartment call. + */ + +class JS_PUBLIC_API(JSAutoCompartment) +{ + JSContext *cx_; + JSCompartment *oldCompartment_; + public: + JSAutoCompartment(JSContext *cx, JSObject *target); + JSAutoCompartment(JSContext *cx, JSScript *target); + ~JSAutoCompartment(); +}; + +class JS_PUBLIC_API(JSAutoNullableCompartment) +{ + JSContext *cx_; + JSCompartment *oldCompartment_; + public: + explicit JSAutoNullableCompartment(JSContext *cx, JSObject *targetOrNull); + ~JSAutoNullableCompartment(); +}; + +/* NB: This API is infallible; a nullptr return value does not indicate error. */ +extern JS_PUBLIC_API(JSCompartment *) +JS_EnterCompartment(JSContext *cx, JSObject *target); + +extern JS_PUBLIC_API(void) +JS_LeaveCompartment(JSContext *cx, JSCompartment *oldCompartment); + +typedef void (*JSIterateCompartmentCallback)(JSRuntime *rt, void *data, JSCompartment *compartment); + +/* + * This function calls |compartmentCallback| on every compartment. Beware that + * there is no guarantee that the compartment will survive after the callback + * returns. + */ +extern JS_PUBLIC_API(void) +JS_IterateCompartments(JSRuntime *rt, void *data, + JSIterateCompartmentCallback compartmentCallback); + +/* + * Initialize standard JS class constructors, prototypes, and any top-level + * functions and constants associated with the standard classes (e.g. isNaN + * for Number). + * + * NB: This sets cx's global object to obj if it was null. + */ +extern JS_PUBLIC_API(bool) +JS_InitStandardClasses(JSContext *cx, JS::Handle obj); + +/* + * Resolve id, which must contain either a string or an int, to a standard + * class name in obj if possible, defining the class's constructor and/or + * prototype and storing true in *resolved. If id does not name a standard + * class or a top-level property induced by initializing a standard class, + * store false in *resolved and just return true. Return false on error, + * as usual for bool result-typed API entry points. + * + * This API can be called directly from a global object class's resolve op, + * to define standard classes lazily. The class's enumerate op should call + * JS_EnumerateStandardClasses(cx, obj), to define eagerly during for..in + * loops any classes not yet resolved lazily. + */ +extern JS_PUBLIC_API(bool) +JS_ResolveStandardClass(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *resolved); + +extern JS_PUBLIC_API(bool) +JS_EnumerateStandardClasses(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(bool) +JS_GetClassObject(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); + +extern JS_PUBLIC_API(bool) +JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); + +namespace JS { + +/* + * Determine if the given object is an instance/prototype/constructor for a standard + * class. If so, return the associated JSProtoKey. If not, return JSProto_Null. + */ + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstance(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstanceOrPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardConstructor(JSObject *obj); + +extern JS_PUBLIC_API(void) +ProtoKeyToId(JSContext *cx, JSProtoKey key, JS::MutableHandleId idp); + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSProtoKey) +JS_IdToProtoKey(JSContext *cx, JS::HandleId id); + +/* + * Returns the original value of |Function.prototype| from the global object in + * which |forObj| was created. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetFunctionPrototype(JSContext *cx, JS::HandleObject forObj); + +/* + * Returns the original value of |Object.prototype| from the global object in + * which |forObj| was created. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetObjectPrototype(JSContext *cx, JS::HandleObject forObj); + +/* + * Returns the original value of |Array.prototype| from the global object in + * which |forObj| was created. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetArrayPrototype(JSContext *cx, JS::HandleObject forObj); + +/* + * Returns the original value of |Error.prototype| from the global + * object of the current compartment of cx. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetErrorPrototype(JSContext *cx); + +extern JS_PUBLIC_API(JSObject *) +JS_GetGlobalForObject(JSContext *cx, JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_IsGlobalObject(JSObject *obj); + +/* + * May return nullptr, if |c| never had a global (e.g. the atoms compartment), + * or if |c|'s global has been collected. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetGlobalForCompartmentOrNull(JSContext *cx, JSCompartment *c); + +namespace JS { + +extern JS_PUBLIC_API(JSObject *) +CurrentGlobalOrNull(JSContext *cx); + +} + +/* + * Initialize the 'Reflect' object on a global object. + */ +extern JS_PUBLIC_API(JSObject *) +JS_InitReflect(JSContext *cx, JS::HandleObject global); + +#ifdef JS_HAS_CTYPES +/* + * Initialize the 'ctypes' object on a global variable 'obj'. The 'ctypes' + * object will be sealed. + */ +extern JS_PUBLIC_API(bool) +JS_InitCTypesClass(JSContext *cx, JS::HandleObject global); + +/* + * Convert a unicode string 'source' of length 'slen' to the platform native + * charset, returning a null-terminated string allocated with JS_malloc. On + * failure, this function should report an error. + */ +typedef char * +(* JSCTypesUnicodeToNativeFun)(JSContext *cx, const jschar *source, size_t slen); + +/* + * Set of function pointers that ctypes can use for various internal functions. + * See JS_SetCTypesCallbacks below. Providing nullptr for a function is safe, + * and will result in the applicable ctypes functionality not being available. + */ +struct JSCTypesCallbacks { + JSCTypesUnicodeToNativeFun unicodeToNative; +}; + +typedef struct JSCTypesCallbacks JSCTypesCallbacks; + +/* + * Set the callbacks on the provided 'ctypesObj' object. 'callbacks' should be a + * pointer to static data that exists for the lifetime of 'ctypesObj', but it + * may safely be altered after calling this function and without having + * to call this function again. + */ +extern JS_PUBLIC_API(void) +JS_SetCTypesCallbacks(JSObject *ctypesObj, JSCTypesCallbacks *callbacks); +#endif + +typedef bool +(* JSEnumerateDiagnosticMemoryCallback)(void *ptr, size_t length); + +/* + * Enumerate memory regions that contain diagnostic information + * intended to be included in crash report minidumps. + */ +extern JS_PUBLIC_API(void) +JS_EnumerateDiagnosticMemoryRegions(JSEnumerateDiagnosticMemoryCallback callback); + +extern JS_PUBLIC_API(void *) +JS_malloc(JSContext *cx, size_t nbytes); + +extern JS_PUBLIC_API(void *) +JS_realloc(JSContext *cx, void *p, size_t nbytes); + +/* + * A wrapper for js_free(p) that may delay js_free(p) invocation as a + * performance optimization. + * cx may be nullptr. + */ +extern JS_PUBLIC_API(void) +JS_free(JSContext *cx, void *p); + +/* + * A wrapper for js_free(p) that may delay js_free(p) invocation as a + * performance optimization as specified by the given JSFreeOp instance. + */ +extern JS_PUBLIC_API(void) +JS_freeop(JSFreeOp *fop, void *p); + +extern JS_PUBLIC_API(JSFreeOp *) +JS_GetDefaultFreeOp(JSRuntime *rt); + +extern JS_PUBLIC_API(void) +JS_updateMallocCounter(JSContext *cx, size_t nbytes); + +extern JS_PUBLIC_API(char *) +JS_strdup(JSContext *cx, const char *s); + +/* Duplicate a string. Does not report an error on failure. */ +extern JS_PUBLIC_API(char *) +JS_strdup(JSRuntime *rt, const char *s); + +namespace JS { + +/* + * A GC root is a pointer to a jsval, JSObject * or JSString * that itself + * points into the GC heap. JS_AddValueRoot takes a pointer to a jsval and + * JS_AddGCThingRoot takes a pointer to a JSObject * or JString *. + * + * Note that, since JS_Add*Root stores the address of a variable (of type + * jsval, JSString *, or JSObject *), that variable must live until + * JS_Remove*Root is called to remove that variable. For example, after: + * + * void some_function() { + * jsval v; + * JS_AddNamedValueRoot(cx, &v, "name"); + * + * the caller must perform + * + * JS_RemoveValueRoot(cx, &v); + * + * before some_function() returns. + * + * Also, use JS_AddNamed*Root(cx, &structPtr->memberObj, "structPtr->memberObj") + * in preference to JS_Add*Root(cx, &structPtr->memberObj), in order to identify + * roots by their source callsites. This way, you can find the callsite while + * debugging if you should fail to do JS_Remove*Root(cx, &structPtr->memberObj) + * before freeing structPtr's memory. + */ +extern JS_PUBLIC_API(bool) +AddValueRoot(JSContext *cx, JS::Heap *vp); + +extern JS_PUBLIC_API(bool) +AddStringRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(bool) +AddObjectRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(bool) +AddNamedValueRoot(JSContext *cx, JS::Heap *vp, const char *name); + +extern JS_PUBLIC_API(bool) +AddNamedValueRootRT(JSRuntime *rt, JS::Heap *vp, const char *name); + +extern JS_PUBLIC_API(bool) +AddNamedStringRoot(JSContext *cx, JS::Heap *rp, const char *name); + +extern JS_PUBLIC_API(bool) +AddNamedObjectRoot(JSContext *cx, JS::Heap *rp, const char *name); + +extern JS_PUBLIC_API(bool) +AddNamedScriptRoot(JSContext *cx, JS::Heap *rp, const char *name); + +extern JS_PUBLIC_API(void) +RemoveValueRoot(JSContext *cx, JS::Heap *vp); + +extern JS_PUBLIC_API(void) +RemoveStringRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveObjectRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveScriptRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveValueRootRT(JSRuntime *rt, JS::Heap *vp); + +extern JS_PUBLIC_API(void) +RemoveStringRootRT(JSRuntime *rt, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveObjectRootRT(JSRuntime *rt, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveScriptRootRT(JSRuntime *rt, JS::Heap *rp); + +} /* namespace JS */ + +/* + * Register externally maintained GC roots. + * + * traceOp: the trace operation. For each root the implementation should call + * JS_CallTracer whenever the root contains a traceable thing. + * data: the data argument to pass to each invocation of traceOp. + */ +extern JS_PUBLIC_API(bool) +JS_AddExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); + +/* Undo a call to JS_AddExtraGCRootsTracer. */ +extern JS_PUBLIC_API(void) +JS_RemoveExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); + +#ifdef JS_DEBUG + +/* + * Debug-only method to dump the object graph of heap-allocated things. + * + * fp: file for the dump output. + * start: when non-null, dump only things reachable from start + * thing. Otherwise dump all things reachable from the + * runtime roots. + * startKind: trace kind of start if start is not null. Must be + * JSTRACE_OBJECT when start is null. + * thingToFind: dump only paths in the object graph leading to thingToFind + * when non-null. + * maxDepth: the upper bound on the number of edges to descend from the + * graph roots. + * thingToIgnore: thing to ignore during the graph traversal when non-null. + */ +extern JS_PUBLIC_API(bool) +JS_DumpHeap(JSRuntime *rt, FILE *fp, void* startThing, JSGCTraceKind kind, + void *thingToFind, size_t maxDepth, void *thingToIgnore); + +#endif + +/* + * Garbage collector API. + */ +extern JS_PUBLIC_API(void) +JS_GC(JSRuntime *rt); + +extern JS_PUBLIC_API(void) +JS_MaybeGC(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_SetGCCallback(JSRuntime *rt, JSGCCallback cb, void *data); + +extern JS_PUBLIC_API(bool) +JS_AddFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb, void *data); + +extern JS_PUBLIC_API(void) +JS_RemoveFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); + +extern JS_PUBLIC_API(bool) +JS_IsGCMarkingTracer(JSTracer *trc); + +/* For assertions only. */ +#ifdef JS_DEBUG +extern JS_PUBLIC_API(bool) +JS_IsMarkingGray(JSTracer *trc); +#endif + +/* + * JS_IsAboutToBeFinalized checks if the given object is going to be finalized + * at the end of the current GC. When called outside of the context of a GC, + * this function will return false. Typically this function is used on weak + * references, where the reference should be nulled out or destroyed if the + * given object is about to be finalized. + * + * The argument to JS_IsAboutToBeFinalized is an in-out param: when the + * function returns false, the object being referenced is still alive, but the + * garbage collector might have moved it. In this case, the reference passed + * to JS_IsAboutToBeFinalized will be updated to the object's new location. + * Callers of this method are responsible for updating any state that is + * dependent on the object's address. For example, if the object's address is + * used as a key in a hashtable, then the object must be removed and + * re-inserted with the correct hash. + */ +extern JS_PUBLIC_API(bool) +JS_IsAboutToBeFinalized(JS::Heap *objp); + +extern JS_PUBLIC_API(bool) +JS_IsAboutToBeFinalizedUnbarriered(JSObject **objp); + +typedef enum JSGCParamKey { + /* Maximum nominal heap before last ditch GC. */ + JSGC_MAX_BYTES = 0, + + /* Number of JS_malloc bytes before last ditch GC. */ + JSGC_MAX_MALLOC_BYTES = 1, + + /* Amount of bytes allocated by the GC. */ + JSGC_BYTES = 3, + + /* Number of times when GC was invoked. */ + JSGC_NUMBER = 4, + + /* Max size of the code cache in bytes. */ + JSGC_MAX_CODE_CACHE_BYTES = 5, + + /* Select GC mode. */ + JSGC_MODE = 6, + + /* Number of cached empty GC chunks. */ + JSGC_UNUSED_CHUNKS = 7, + + /* Total number of allocated GC chunks. */ + JSGC_TOTAL_CHUNKS = 8, + + /* Max milliseconds to spend in an incremental GC slice. */ + JSGC_SLICE_TIME_BUDGET = 9, + + /* Maximum size the GC mark stack can grow to. */ + JSGC_MARK_STACK_LIMIT = 10, + + /* + * GCs less than this far apart in time will be considered 'high-frequency GCs'. + * See setGCLastBytes in jsgc.cpp. + */ + JSGC_HIGH_FREQUENCY_TIME_LIMIT = 11, + + /* Start of dynamic heap growth. */ + JSGC_HIGH_FREQUENCY_LOW_LIMIT = 12, + + /* End of dynamic heap growth. */ + JSGC_HIGH_FREQUENCY_HIGH_LIMIT = 13, + + /* Upper bound of heap growth. */ + JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX = 14, + + /* Lower bound of heap growth. */ + JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN = 15, + + /* Heap growth for low frequency GCs. */ + JSGC_LOW_FREQUENCY_HEAP_GROWTH = 16, + + /* + * If false, the heap growth factor is fixed at 3. If true, it is determined + * based on whether GCs are high- or low- frequency. + */ + JSGC_DYNAMIC_HEAP_GROWTH = 17, + + /* If true, high-frequency GCs will use a longer mark slice. */ + JSGC_DYNAMIC_MARK_SLICE = 18, + + /* Lower limit after which we limit the heap growth. */ + JSGC_ALLOCATION_THRESHOLD = 19, + + /* + * We decommit memory lazily. If more than this number of megabytes is + * available to be decommitted, then JS_MaybeGC will trigger a shrinking GC + * to decommit it. + */ + JSGC_DECOMMIT_THRESHOLD = 20, + + /* + * We try to keep at least this many unused chunks in the free chunk pool at + * all times, even after a shrinking GC. + */ + JSGC_MIN_EMPTY_CHUNK_COUNT = 21, + + /* We never keep more than this many unused chunks in the free chunk pool. */ + JSGC_MAX_EMPTY_CHUNK_COUNT = 22 +} JSGCParamKey; + +extern JS_PUBLIC_API(void) +JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32_t value); + +extern JS_PUBLIC_API(uint32_t) +JS_GetGCParameter(JSRuntime *rt, JSGCParamKey key); + +extern JS_PUBLIC_API(void) +JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32_t value); + +extern JS_PUBLIC_API(uint32_t) +JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key); + +extern JS_PUBLIC_API(void) +JS_SetGCParametersBasedOnAvailableMemory(JSRuntime *rt, uint32_t availMem); + +/* + * Create a new JSString whose chars member refers to external memory, i.e., + * memory requiring application-specific finalization. + */ +extern JS_PUBLIC_API(JSString *) +JS_NewExternalString(JSContext *cx, const jschar *chars, size_t length, + const JSStringFinalizer *fin); + +/* + * Return whether 'str' was created with JS_NewExternalString or + * JS_NewExternalStringWithClosure. + */ +extern JS_PUBLIC_API(bool) +JS_IsExternalString(JSString *str); + +/* + * Return the 'closure' arg passed to JS_NewExternalStringWithClosure or + * nullptr if the external string was created via JS_NewExternalString. + */ +extern JS_PUBLIC_API(const JSStringFinalizer *) +JS_GetExternalStringFinalizer(JSString *str); + +/* + * Set the size of the native stack that should not be exceed. To disable + * stack size checking pass 0. + * + * SpiderMonkey allows for a distinction between system code (such as GCs, which + * may incidentally be triggered by script but are not strictly performed on + * behalf of such script), trusted script (as determined by JS_SetTrustedPrincipals), + * and untrusted script. Each kind of code may have a different stack quota, + * allowing embedders to keep higher-priority machinery running in the face of + * scripted stack exhaustion by something else. + * + * The stack quotas for each kind of code should be monotonically descending, + * and may be specified with this function. If 0 is passed for a given kind + * of code, it defaults to the value of the next-highest-priority kind. + */ +extern JS_PUBLIC_API(void) +JS_SetNativeStackQuota(JSRuntime *cx, size_t systemCodeStackSize, + size_t trustedScriptStackSize = 0, + size_t untrustedScriptStackSize = 0); + +/************************************************************************/ + +extern JS_PUBLIC_API(int) +JS_IdArrayLength(JSContext *cx, JSIdArray *ida); + +extern JS_PUBLIC_API(jsid) +JS_IdArrayGet(JSContext *cx, JSIdArray *ida, unsigned index); + +extern JS_PUBLIC_API(void) +JS_DestroyIdArray(JSContext *cx, JSIdArray *ida); + +namespace JS { + +class AutoIdArray : private AutoGCRooter +{ + public: + AutoIdArray(JSContext *cx, JSIdArray *ida + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, IDARRAY), context(cx), idArray(ida) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + ~AutoIdArray() { + if (idArray) + JS_DestroyIdArray(context, idArray); + } + bool operator!() const { + return !idArray; + } + jsid operator[](size_t i) const { + JS_ASSERT(idArray); + return JS_IdArrayGet(context, idArray, unsigned(i)); + } + size_t length() const { + return JS_IdArrayLength(context, idArray); + } + + friend void AutoGCRooter::trace(JSTracer *trc); + + JSIdArray *steal() { + JSIdArray *copy = idArray; + idArray = nullptr; + return copy; + } + + protected: + inline void trace(JSTracer *trc); + + private: + JSContext *context; + JSIdArray *idArray; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + /* No copy or assignment semantics. */ + AutoIdArray(AutoIdArray &ida) MOZ_DELETE; + void operator=(AutoIdArray &ida) MOZ_DELETE; +}; + +} /* namespace JS */ + +extern JS_PUBLIC_API(bool) +JS_ValueToId(JSContext *cx, JS::HandleValue v, JS::MutableHandleId idp); + +extern JS_PUBLIC_API(bool) +JS_StringToId(JSContext *cx, JS::HandleString s, JS::MutableHandleId idp); + +extern JS_PUBLIC_API(bool) +JS_IdToValue(JSContext *cx, jsid id, JS::MutableHandle vp); + +/* + * Invoke the [[DefaultValue]] hook (see ES5 8.6.2) with the provided hint on + * the specified object, computing a primitive default value for the object. + * The hint must be JSTYPE_STRING, JSTYPE_NUMBER, or JSTYPE_VOID (no hint). On + * success the resulting value is stored in *vp. + */ +extern JS_PUBLIC_API(bool) +JS_DefaultValue(JSContext *cx, JS::Handle obj, JSType hint, + JS::MutableHandle vp); + +extern JS_PUBLIC_API(bool) +JS_PropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_StrictPropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_DeletePropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *succeeded); + +extern JS_PUBLIC_API(bool) +JS_EnumerateStub(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(bool) +JS_ResolveStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id); + +extern JS_PUBLIC_API(bool) +JS_ConvertStub(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); + +struct JSConstDoubleSpec { + double dval; + const char *name; + uint8_t flags; + uint8_t spare[3]; +}; + +struct JSJitInfo; + +/* + * Wrappers to replace {Strict,}PropertyOp for JSPropertySpecs. This will allow + * us to pass one JSJitInfo per function with the property spec, without + * additional field overhead. + */ +typedef struct JSStrictPropertyOpWrapper { + JSStrictPropertyOp op; + const JSJitInfo *info; +} JSStrictPropertyOpWrapper; + +typedef struct JSPropertyOpWrapper { + JSPropertyOp op; + const JSJitInfo *info; +} JSPropertyOpWrapper; + +/* + * Wrapper to do as above, but for JSNatives for JSFunctionSpecs. + */ +typedef struct JSNativeWrapper { + JSNative op; + const JSJitInfo *info; +} JSNativeWrapper; + +/* + * Macro static initializers which make it easy to pass no JSJitInfo as part of a + * JSPropertySpec or JSFunctionSpec. + */ +#define JSOP_WRAPPER(op) { {op, nullptr} } +#define JSOP_NULLWRAPPER JSOP_WRAPPER(nullptr) + +/* + * To define an array element rather than a named property member, cast the + * element's index to (const char *) and initialize name with it, and set the + * JSPROP_INDEX bit in flags. + */ +struct JSPropertySpec { + struct SelfHostedWrapper { + void *unused; + const char *funname; + }; + + const char *name; + uint8_t flags; + union { + JSPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } getter; + union { + JSStrictPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } setter; + +private: + void StaticAsserts() { + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSPropertyOpWrapper)); + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSStrictPropertyOpWrapper)); + JS_STATIC_ASSERT(offsetof(SelfHostedWrapper, funname) == + offsetof(JSPropertyOpWrapper, info)); + } +}; + +namespace JS { +namespace detail { + +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_NATIVE_TO only. */ +inline int CheckIsNative(JSNative native); + +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_STRING_TO only. */ +template +inline int +CheckIsCharacterLiteral(const char (&arr)[N]); + +} // namespace detail +} // namespace JS + +#define JS_CAST_NATIVE_TO(v, To) \ + (static_cast(sizeof(JS::detail::CheckIsNative(v))), \ + reinterpret_cast(v)) + +#define JS_CAST_STRING_TO(s, To) \ + (static_cast(sizeof(JS::detail::CheckIsCharacterLiteral(s))), \ + reinterpret_cast(s)) + +#define JS_CHECK_ACCESSOR_FLAGS(flags) \ + (static_cast::Type>(0), \ + (flags)) + +/* + * JSPropertySpec uses JSAPI JSPropertyOp and JSStrictPropertyOp in function + * signatures. These macros encapsulate the definition of JSNative-backed + * JSPropertySpecs, performing type-safe casts on the getter/setter functions + * and adding the necessary property flags to trigger interpretation as + * JSNatives. + */ +#define JS_PSG(name, getter, flags) \ + {name, \ + uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ + JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ + JSOP_NULLWRAPPER} +#define JS_PSGS(name, getter, setter, flags) \ + {name, \ + uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ + JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ + JSOP_WRAPPER(JS_CAST_NATIVE_TO(setter, JSStrictPropertyOp))} +#define JS_SELF_HOSTED_GET(name, getterName, flags) \ + {name, \ + uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER), \ + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + JSOP_NULLWRAPPER } +#define JS_SELF_HOSTED_GETSET(name, getterName, setterName, flags) \ + {name, \ + uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER | JSPROP_SETTER), \ + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + { nullptr, JS_CAST_STRING_TO(setterName, const JSJitInfo *) } } +#define JS_PS_END { nullptr, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER } + +/* + * To define a native function, set call to a JSNativeWrapper. To define a + * self-hosted function, set selfHostedName to the name of a function + * compiled during JSRuntime::initSelfHosting. + */ +struct JSFunctionSpec { + const char *name; + JSNativeWrapper call; + uint16_t nargs; + uint16_t flags; + const char *selfHostedName; +}; + +/* + * Terminating sentinel initializer to put at the end of a JSFunctionSpec array + * that's passed to JS_DefineFunctions or JS_InitClass. + */ +#define JS_FS_END JS_FS(nullptr,nullptr,0,0) + +/* + * Initializer macros for a JSFunctionSpec array element. JS_FN (whose name pays + * homage to the old JSNative/JSFastNative split) simply adds the flag + * JSFUN_STUB_GSOPS. JS_FNINFO allows the simple adding of + * JSJitInfos. JS_SELF_HOSTED_FN declares a self-hosted function. Finally + * JS_FNSPEC has slots for all the fields. + */ +#define JS_FS(name,call,nargs,flags) \ + JS_FNSPEC(name, call, nullptr, nargs, flags, nullptr) +#define JS_FN(name,call,nargs,flags) \ + JS_FNSPEC(name, call, nullptr, nargs, (flags) | JSFUN_STUB_GSOPS, nullptr) +#define JS_FNINFO(name,call,info,nargs,flags) \ + JS_FNSPEC(name, call, info, nargs, flags, nullptr) +#define JS_SELF_HOSTED_FN(name,selfHostedName,nargs,flags) \ + JS_FNSPEC(name, nullptr, nullptr, nargs, flags, selfHostedName) +#define JS_FNSPEC(name,call,info,nargs,flags,selfHostedName) \ + {name, {call, info}, nargs, flags, selfHostedName} + +extern JS_PUBLIC_API(JSObject *) +JS_InitClass(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent_proto, + const JSClass *clasp, JSNative constructor, unsigned nargs, + const JSPropertySpec *ps, const JSFunctionSpec *fs, + const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs); + +/* + * Set up ctor.prototype = proto and proto.constructor = ctor with the + * right property flags. + */ +extern JS_PUBLIC_API(bool) +JS_LinkConstructorAndPrototype(JSContext *cx, JS::Handle ctor, + JS::Handle proto); + +extern JS_PUBLIC_API(const JSClass *) +JS_GetClass(JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_InstanceOf(JSContext *cx, JS::Handle obj, const JSClass *clasp, JS::CallArgs *args); + +extern JS_PUBLIC_API(bool) +JS_HasInstance(JSContext *cx, JS::Handle obj, JS::Handle v, bool *bp); + +extern JS_PUBLIC_API(void *) +JS_GetPrivate(JSObject *obj); + +extern JS_PUBLIC_API(void) +JS_SetPrivate(JSObject *obj, void *data); + +extern JS_PUBLIC_API(void *) +JS_GetInstancePrivate(JSContext *cx, JS::Handle obj, const JSClass *clasp, + JS::CallArgs *args); + +extern JS_PUBLIC_API(bool) +JS_GetPrototype(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject protop); + +extern JS_PUBLIC_API(bool) +JS_SetPrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); + +extern JS_PUBLIC_API(JSObject *) +JS_GetParent(JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_SetParent(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent); + +extern JS_PUBLIC_API(JSObject *) +JS_GetConstructor(JSContext *cx, JS::Handle proto); + +namespace JS { + +enum ZoneSpecifier { + FreshZone = 0, + SystemZone = 1 +}; + +class JS_PUBLIC_API(CompartmentOptions) +{ + public: + class Override { + public: + Override() : mode_(Default) {} + + bool get(bool defaultValue) const { + if (mode_ == Default) + return defaultValue; + return mode_ == ForceTrue; + }; + + void set(bool overrideValue) { + mode_ = overrideValue ? ForceTrue : ForceFalse; + }; + + void reset() { + mode_ = Default; + } + + private: + enum Mode { + Default, + ForceTrue, + ForceFalse + }; + + Mode mode_; + }; + + explicit CompartmentOptions() + : version_(JSVERSION_UNKNOWN) + , invisibleToDebugger_(false) + , mergeable_(false) + , discardSource_(false) + , cloneSingletons_(false) + , traceGlobal_(nullptr) + , singletonsAsTemplates_(true) + , addonId_(nullptr) + { + zone_.spec = JS::FreshZone; + } + + JSVersion version() const { return version_; } + CompartmentOptions &setVersion(JSVersion aVersion) { + MOZ_ASSERT(aVersion != JSVERSION_UNKNOWN); + version_ = aVersion; + return *this; + } + + // Certain scopes (i.e. XBL compilation scopes) are implementation details + // of the embedding, and references to them should never leak out to script. + // This flag causes the this compartment to skip firing onNewGlobalObject + // and makes addDebuggee a no-op for this global. + bool invisibleToDebugger() const { return invisibleToDebugger_; } + CompartmentOptions &setInvisibleToDebugger(bool flag) { + invisibleToDebugger_ = flag; + return *this; + } + + // Compartments used for off-thread compilation have their contents merged + // into a target compartment when the compilation is finished. This is only + // allowed if this flag is set. The invisibleToDebugger flag must also be + // set for such compartments. + bool mergeable() const { return mergeable_; } + CompartmentOptions &setMergeable(bool flag) { + mergeable_ = flag; + return *this; + } + + // For certain globals, we know enough about the code that will run in them + // that we can discard script source entirely. + bool discardSource() const { return discardSource_; } + CompartmentOptions &setDiscardSource(bool flag) { + discardSource_ = flag; + return *this; + } + + + bool cloneSingletons() const { return cloneSingletons_; } + CompartmentOptions &setCloneSingletons(bool flag) { + cloneSingletons_ = flag; + return *this; + } + + void *zonePointer() const { + JS_ASSERT(uintptr_t(zone_.pointer) > uintptr_t(JS::SystemZone)); + return zone_.pointer; + } + ZoneSpecifier zoneSpecifier() const { return zone_.spec; } + CompartmentOptions &setZone(ZoneSpecifier spec); + CompartmentOptions &setSameZoneAs(JSObject *obj); + + void setSingletonsAsValues() { + singletonsAsTemplates_ = false; + } + bool getSingletonsAsTemplates() const { + return singletonsAsTemplates_; + }; + + // A null add-on ID means that the compartment is not associated with an + // add-on. + JSAddonId *addonIdOrNull() const { return addonId_; } + CompartmentOptions &setAddonId(JSAddonId *id) { + addonId_ = id; + return *this; + } + + CompartmentOptions &setTrace(JSTraceOp op) { + traceGlobal_ = op; + return *this; + } + JSTraceOp getTrace() const { + return traceGlobal_; + } + + private: + JSVersion version_; + bool invisibleToDebugger_; + bool mergeable_; + bool discardSource_; + bool cloneSingletons_; + union { + ZoneSpecifier spec; + void *pointer; // js::Zone* is not exposed in the API. + } zone_; + JSTraceOp traceGlobal_; + + // To XDR singletons, we need to ensure that all singletons are all used as + // templates, by making JSOP_OBJECT return a clone of the JSScript + // singleton, instead of returning the value which is baked in the JSScript. + bool singletonsAsTemplates_; + + JSAddonId *addonId_; +}; + +JS_PUBLIC_API(CompartmentOptions &) +CompartmentOptionsRef(JSCompartment *compartment); + +JS_PUBLIC_API(CompartmentOptions &) +CompartmentOptionsRef(JSObject *obj); + +JS_PUBLIC_API(CompartmentOptions &) +CompartmentOptionsRef(JSContext *cx); + +// During global creation, we fire notifications to callbacks registered +// via the Debugger API. These callbacks are arbitrary script, and can touch +// the global in arbitrary ways. When that happens, the global should not be +// in a half-baked state. But this creates a problem for consumers that need +// to set slots on the global to put it in a consistent state. +// +// This API provides a way for consumers to set slots atomically (immediately +// after the global is created), before any debugger hooks are fired. It's +// unfortunately on the clunky side, but that's the way the cookie crumbles. +// +// If callers have no additional state on the global to set up, they may pass +// |FireOnNewGlobalHook| to JS_NewGlobalObject, which causes that function to +// fire the hook as its final act before returning. Otherwise, callers should +// pass |DontFireOnNewGlobalHook|, which means that they are responsible for +// invoking JS_FireOnNewGlobalObject upon successfully creating the global. If +// an error occurs and the operation aborts, callers should skip firing the +// hook. But otherwise, callers must take care to fire the hook exactly once +// before compiling any script in the global's scope (we have assertions in +// place to enforce this). This lets us be sure that debugger clients never miss +// breakpoints. +enum OnNewGlobalHookOption { + FireOnNewGlobalHook, + DontFireOnNewGlobalHook +}; + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSObject *) +JS_NewGlobalObject(JSContext *cx, const JSClass *clasp, JSPrincipals *principals, + JS::OnNewGlobalHookOption hookOption, + const JS::CompartmentOptions &options = JS::CompartmentOptions()); +/* + * Spidermonkey does not have a good way of keeping track of what compartments should be marked on + * their own. We can mark the roots unconditionally, but marking GC things only relevant in live + * compartments is hard. To mitigate this, we create a static trace hook, installed on each global + * object, from which we can be sure the compartment is relevant, and mark it. + * + * It is still possible to specify custom trace hooks for global object classes. They can be + * provided via the CompartmentOptions passed to JS_NewGlobalObject. + */ +extern JS_PUBLIC_API(void) +JS_GlobalObjectTraceHook(JSTracer *trc, JSObject *global); + +extern JS_PUBLIC_API(void) +JS_FireOnNewGlobalObject(JSContext *cx, JS::HandleObject global); + +extern JS_PUBLIC_API(JSObject *) +JS_NewObject(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); + +/* Queries the [[Extensible]] property of the object. */ +extern JS_PUBLIC_API(bool) +JS_IsExtensible(JSContext *cx, JS::HandleObject obj, bool *extensible); + +extern JS_PUBLIC_API(bool) +JS_IsNative(JSObject *obj); + +extern JS_PUBLIC_API(JSRuntime *) +JS_GetObjectRuntime(JSObject *obj); + +/* + * Unlike JS_NewObject, JS_NewObjectWithGivenProto does not compute a default + * proto if proto's actual parameter value is null. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); + +/* + * Freeze obj, and all objects it refers to, recursively. This will not recurse + * through non-extensible objects, on the assumption that those are already + * deep-frozen. + */ +extern JS_PUBLIC_API(bool) +JS_DeepFreezeObject(JSContext *cx, JS::Handle obj); + +/* + * Freezes an object; see ES5's Object.freeze(obj) method. + */ +extern JS_PUBLIC_API(bool) +JS_FreezeObject(JSContext *cx, JS::Handle obj); + +extern JS_PUBLIC_API(bool) +JS_PreventExtensions(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(JSObject *) +JS_New(JSContext *cx, JS::HandleObject ctor, const JS::HandleValueArray& args); + +extern JS_PUBLIC_API(JSObject *) +JS_DefineObject(JSContext *cx, JS::HandleObject obj, const char *name, + const JSClass *clasp = nullptr, JS::HandleObject proto = JS::NullPtr(), + unsigned attrs = 0); + +extern JS_PUBLIC_API(bool) +JS_DefineConstDoubles(JSContext *cx, JS::HandleObject obj, const JSConstDoubleSpec *cds); + +extern JS_PUBLIC_API(bool) +JS_DefineProperties(JSContext *cx, JS::HandleObject obj, const JSPropertySpec *ps); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnProperty(JSContext *cx, JS::HandleObject obj, const char *name, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasProperty(JSContext *cx, JS::HandleObject obj, const char *name, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_LookupPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); + +struct JSPropertyDescriptor { + JSObject *obj; + unsigned attrs; + JSPropertyOp getter; + JSStrictPropertyOp setter; + JS::Value value; + + JSPropertyDescriptor() + : obj(nullptr), attrs(0), getter(nullptr), setter(nullptr), value(JSVAL_VOID) + {} + + void trace(JSTracer *trc); + + static js::ThingRootKind rootKind() { return js::THING_ROOT_PROPERTY_DESCRIPTOR; } +}; + +namespace JS { + +template +class PropertyDescriptorOperations +{ + const JSPropertyDescriptor * desc() const { return static_cast(this)->extract(); } + + public: + bool isEnumerable() const { return desc()->attrs & JSPROP_ENUMERATE; } + bool isReadonly() const { return desc()->attrs & JSPROP_READONLY; } + bool isPermanent() const { return desc()->attrs & JSPROP_PERMANENT; } + bool hasNativeAccessors() const { return desc()->attrs & JSPROP_NATIVE_ACCESSORS; } + bool hasGetterObject() const { return desc()->attrs & JSPROP_GETTER; } + bool hasSetterObject() const { return desc()->attrs & JSPROP_SETTER; } + bool hasGetterOrSetterObject() const { return desc()->attrs & (JSPROP_GETTER | JSPROP_SETTER); } + bool hasGetterOrSetter() const { return desc()->getter || desc()->setter; } + bool isShared() const { return desc()->attrs & JSPROP_SHARED; } + bool isIndex() const { return desc()->attrs & JSPROP_INDEX; } + bool hasAttributes(unsigned attrs) const { return desc()->attrs & attrs; } + + JS::HandleObject object() const { + return JS::HandleObject::fromMarkedLocation(&desc()->obj); + } + unsigned attributes() const { return desc()->attrs; } + JSPropertyOp getter() const { return desc()->getter; } + JSStrictPropertyOp setter() const { return desc()->setter; } + JS::HandleObject getterObject() const { + MOZ_ASSERT(hasGetterObject()); + return JS::HandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->getter)); + } + JS::HandleObject setterObject() const { + MOZ_ASSERT(hasSetterObject()); + return JS::HandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->setter)); + } + JS::HandleValue value() const { + return JS::HandleValue::fromMarkedLocation(&desc()->value); + } +}; + +template +class MutablePropertyDescriptorOperations : public PropertyDescriptorOperations +{ + JSPropertyDescriptor * desc() { return static_cast(this)->extractMutable(); } + + public: + + void clear() { + object().set(nullptr); + setAttributes(0); + setGetter(nullptr); + setSetter(nullptr); + value().setUndefined(); + } + + void assign(JSPropertyDescriptor &other) { + object().set(other.obj); + setAttributes(other.attrs); + setGetter(other.getter); + setSetter(other.setter); + value().set(other.value); + } + + JS::MutableHandleObject object() { + return JS::MutableHandleObject::fromMarkedLocation(&desc()->obj); + } + unsigned &attributesRef() { return desc()->attrs; } + JSPropertyOp &getter() { return desc()->getter; } + JSStrictPropertyOp &setter() { return desc()->setter; } + JS::MutableHandleValue value() { + return JS::MutableHandleValue::fromMarkedLocation(&desc()->value); + } + + void setEnumerable() { desc()->attrs |= JSPROP_ENUMERATE; } + void setAttributes(unsigned attrs) { desc()->attrs = attrs; } + + void setGetter(JSPropertyOp op) { desc()->getter = op; } + void setSetter(JSStrictPropertyOp op) { desc()->setter = op; } + void setGetterObject(JSObject *obj) { desc()->getter = reinterpret_cast(obj); } + void setSetterObject(JSObject *obj) { desc()->setter = reinterpret_cast(obj); } + + JS::MutableHandleObject getterObject() { + MOZ_ASSERT(this->hasGetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->getter)); + } + JS::MutableHandleObject setterObject() { + MOZ_ASSERT(this->hasSetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->setter)); + } +}; + +} /* namespace JS */ + +namespace js { + +template <> +struct GCMethods { + static JSPropertyDescriptor initial() { return JSPropertyDescriptor(); } + static bool poisoned(const JSPropertyDescriptor &desc) { + return (desc.obj && JS::IsPoisonedPtr(desc.obj)) || + (desc.attrs & JSPROP_GETTER && desc.getter && JS::IsPoisonedPtr(desc.getter)) || + (desc.attrs & JSPROP_SETTER && desc.setter && JS::IsPoisonedPtr(desc.setter)) || + (desc.value.isGCThing() && JS::IsPoisonedPtr(desc.value.toGCThing())); + } +}; + +template <> +class RootedBase + : public JS::MutablePropertyDescriptorOperations > +{ + friend class JS::PropertyDescriptorOperations >; + friend class JS::MutablePropertyDescriptorOperations >; + const JSPropertyDescriptor *extract() const { + return static_cast*>(this)->address(); + } + JSPropertyDescriptor *extractMutable() { + return static_cast*>(this)->address(); + } +}; + +template <> +class HandleBase + : public JS::PropertyDescriptorOperations > +{ + friend class JS::PropertyDescriptorOperations >; + const JSPropertyDescriptor *extract() const { + return static_cast*>(this)->address(); + } +}; + +template <> +class MutableHandleBase + : public JS::MutablePropertyDescriptorOperations > +{ + friend class JS::PropertyDescriptorOperations >; + friend class JS::MutablePropertyDescriptorOperations >; + const JSPropertyDescriptor *extract() const { + return static_cast*>(this)->address(); + } + JSPropertyDescriptor *extractMutable() { + return static_cast*>(this)->address(); + } +}; + +} /* namespace js */ + +namespace JS { + +extern JS_PUBLIC_API(bool) +ParsePropertyDescriptorObject(JSContext *cx, + JS::HandleObject obj, + JS::HandleValue descriptor, + JS::MutableHandle desc); + +} // namespace JS + +extern JS_PUBLIC_API(bool) +JS_GetOwnPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandle desc); + +extern JS_PUBLIC_API(bool) +JS_GetOwnPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, + JS::MutableHandle desc); + +/* + * Like JS_GetOwnPropertyDescriptorById but will return a property on + * an object on the prototype chain (returned in desc->obj). If desc->obj is null, + * then this property was not found on the prototype chain. + */ +extern JS_PUBLIC_API(bool) +JS_GetPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandle desc); + +extern JS_PUBLIC_API(bool) +JS_GetPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, + JS::MutableHandle desc); + +extern JS_PUBLIC_API(bool) +JS_GetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetPropertyTo(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject onBehalfOf, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_SetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_DeleteProperty(JSContext *cx, JS::HandleObject obj, const char *name); + +extern JS_PUBLIC_API(bool) +JS_DeleteProperty2(JSContext *cx, JS::HandleObject obj, const char *name, bool *succeeded); + +extern JS_PUBLIC_API(bool) +JS_DeletePropertyById(JSContext *cx, JS::HandleObject obj, jsid id); + +extern JS_PUBLIC_API(bool) +JS_DeletePropertyById2(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleValue value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleObject value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleString value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + int32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + uint32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + double value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, + size_t namelen, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasUCProperty(JSContext *cx, JS::HandleObject obj, + const jschar *name, size_t namelen, + bool *vp); + +extern JS_PUBLIC_API(bool) +JS_LookupUCProperty(JSContext *cx, JS::HandleObject obj, + const jschar *name, size_t namelen, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetUCProperty(JSContext *cx, JS::HandleObject obj, + const jschar *name, size_t namelen, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetUCProperty(JSContext *cx, JS::HandleObject obj, + const jschar *name, size_t namelen, + JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_DeleteUCProperty2(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + bool *succeeded); + +extern JS_PUBLIC_API(JSObject *) +JS_NewArrayObject(JSContext *cx, const JS::HandleValueArray& contents); + +extern JS_PUBLIC_API(JSObject *) +JS_NewArrayObject(JSContext *cx, size_t length); + +extern JS_PUBLIC_API(bool) +JS_IsArrayObject(JSContext *cx, JS::HandleValue value); + +extern JS_PUBLIC_API(bool) +JS_IsArrayObject(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(bool) +JS_GetArrayLength(JSContext *cx, JS::Handle obj, uint32_t *lengthp); + +extern JS_PUBLIC_API(bool) +JS_SetArrayLength(JSContext *cx, JS::Handle obj, uint32_t length); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetElementTo(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::HandleObject onBehalfOf, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double v); + +extern JS_PUBLIC_API(bool) +JS_DeleteElement(JSContext *cx, JS::HandleObject obj, uint32_t index); + +extern JS_PUBLIC_API(bool) +JS_DeleteElement2(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded); + +/* + * Remove all configurable properties from the given (non-global) object and + * assign undefined to all writable data properties. + */ +JS_PUBLIC_API(void) +JS_ClearNonGlobalObject(JSContext *cx, JS::HandleObject obj); + +/* + * Assign 'undefined' to all of the object's non-reserved slots. Note: this is + * done for all slots, regardless of the associated property descriptor. + */ +JS_PUBLIC_API(void) +JS_SetAllNonReservedSlotsToUndefined(JSContext *cx, JSObject *objArg); + +/* + * Create a new array buffer with the given contents. On success, the ownership + * is transferred to the new array buffer. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); + +/* + * Steal the contents of the given array buffer. The array buffer has its + * length set to 0 and its contents array cleared. The caller takes ownership + * of the return value and must free it or transfer ownership via + * JS_NewArrayBufferWithContents when done using it. + */ +extern JS_PUBLIC_API(void *) +JS_StealArrayBufferContents(JSContext *cx, JS::HandleObject obj); + +/* + * Allocate memory that may be eventually passed to + * JS_NewArrayBufferWithContents. |maybecx| is optional; if a non-nullptr cx is + * given, it will be used for memory accounting and OOM reporting. |nbytes| is + * the number of payload bytes required. + */ +extern JS_PUBLIC_API(void *) +JS_AllocateArrayBufferContents(JSContext *maybecx, uint32_t nbytes); + +/* + * Reallocate memory allocated by JS_AllocateArrayBufferContents, growing or + * shrinking it as appropriate. If oldContents is null then this behaves like + * JS_AllocateArrayBufferContents. + */ +extern JS_PUBLIC_API(void *) +JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void *oldContents, uint32_t oldNbytes); + +/* + * Create a new mapped array buffer with the given memory mapped contents. On success, + * the ownership is transferred to the new mapped array buffer. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewMappedArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); + +/* + * Create memory mapped array buffer contents. + * Caller must take care of closing fd after calling this function. + */ +extern JS_PUBLIC_API(void *) +JS_CreateMappedArrayBufferContents(int fd, size_t offset, size_t length); + +/* + * Release the allocated resource of mapped array buffer contents before the + * object is created. + * If a new object has been created by JS_NewMappedArrayBufferWithContents() + * with this content, then JS_NeuterArrayBuffer() should be used instead to + * release the resource used by the object. + */ +extern JS_PUBLIC_API(void) +JS_ReleaseMappedArrayBufferContents(void *contents, size_t length); + +extern JS_PUBLIC_API(JSIdArray *) +JS_Enumerate(JSContext *cx, JS::HandleObject obj); + +/* + * Create an object to iterate over enumerable properties of obj, in arbitrary + * property definition order. NB: This differs from longstanding for..in loop + * order, which uses order of property definition in obj. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewPropertyIterator(JSContext *cx, JS::Handle obj); + +/* + * Return true on success with *idp containing the id of the next enumerable + * property to visit using iterobj, or JSID_IS_VOID if there is no such property + * left to visit. Return false on error. + */ +extern JS_PUBLIC_API(bool) +JS_NextProperty(JSContext *cx, JS::Handle iterobj, jsid *idp); + +extern JS_PUBLIC_API(jsval) +JS_GetReservedSlot(JSObject *obj, uint32_t index); + +extern JS_PUBLIC_API(void) +JS_SetReservedSlot(JSObject *obj, uint32_t index, jsval v); + +/************************************************************************/ + +/* + * Functions and scripts. + */ +extern JS_PUBLIC_API(JSFunction *) +JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, + JS::Handle parent, const char *name); + +/* + * Create the function with the name given by the id. JSID_IS_STRING(id) must + * be true. + */ +extern JS_PUBLIC_API(JSFunction *) +JS_NewFunctionById(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, + JS::Handle parent, JS::Handle id); + +namespace JS { + +extern JS_PUBLIC_API(JSFunction *) +GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, JS::Handle id, + unsigned nargs); + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSObject *) +JS_GetFunctionObject(JSFunction *fun); + +/* + * Return the function's identifier as a JSString, or null if fun is unnamed. + * The returned string lives as long as fun, so you don't need to root a saved + * reference to it if fun is well-connected or rooted, and provided you bound + * the use of the saved reference by fun's lifetime. + */ +extern JS_PUBLIC_API(JSString *) +JS_GetFunctionId(JSFunction *fun); + +/* + * Return a function's display name. This is the defined name if one was given + * where the function was defined, or it could be an inferred name by the JS + * engine in the case that the function was defined to be anonymous. This can + * still return nullptr if a useful display name could not be inferred. The + * same restrictions on rooting as those in JS_GetFunctionId apply. + */ +extern JS_PUBLIC_API(JSString *) +JS_GetFunctionDisplayId(JSFunction *fun); + +/* + * Return the arity (length) of fun. + */ +extern JS_PUBLIC_API(uint16_t) +JS_GetFunctionArity(JSFunction *fun); + +/* + * Infallible predicate to test whether obj is a function object (faster than + * comparing obj's class name to "Function", but equivalent unless someone has + * overwritten the "Function" identifier with a different constructor and then + * created instances using that constructor that might be passed in as obj). + */ +extern JS_PUBLIC_API(bool) +JS_ObjectIsFunction(JSContext *cx, JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_ObjectIsCallable(JSContext *cx, JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_IsNativeFunction(JSObject *funobj, JSNative call); + +/* Return whether the given function is a valid constructor. */ +extern JS_PUBLIC_API(bool) +JS_IsConstructor(JSFunction *fun); + +/* + * Bind the given callable to use the given object as "this". + * + * If |callable| is not callable, will throw and return nullptr. + */ +extern JS_PUBLIC_API(JSObject*) +JS_BindCallable(JSContext *cx, JS::Handle callable, JS::Handle newThis); + +extern JS_PUBLIC_API(bool) +JS_DefineFunctions(JSContext *cx, JS::Handle obj, const JSFunctionSpec *fs); + +extern JS_PUBLIC_API(JSFunction *) +JS_DefineFunction(JSContext *cx, JS::Handle obj, const char *name, JSNative call, + unsigned nargs, unsigned attrs); + +extern JS_PUBLIC_API(JSFunction *) +JS_DefineUCFunction(JSContext *cx, JS::Handle obj, + const jschar *name, size_t namelen, JSNative call, + unsigned nargs, unsigned attrs); + +extern JS_PUBLIC_API(JSFunction *) +JS_DefineFunctionById(JSContext *cx, JS::Handle obj, JS::Handle id, JSNative call, + unsigned nargs, unsigned attrs); + +/* + * Clone a top-level function into a new scope. This function will dynamically + * fail if funobj was lexically nested inside some other function. + */ +extern JS_PUBLIC_API(JSObject *) +JS_CloneFunctionObject(JSContext *cx, JS::Handle funobj, JS::Handle parent); + +/* + * Given a buffer, return false if the buffer might become a valid + * javascript statement with the addition of more lines. Otherwise return + * true. The intent is to support interactive compilation - accumulate + * lines in a buffer until JS_BufferIsCompilableUnit is true, then pass it to + * the compiler. + */ +extern JS_PUBLIC_API(bool) +JS_BufferIsCompilableUnit(JSContext *cx, JS::Handle obj, const char *utf8, + size_t length); + +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +JS_CompileScript(JSContext *cx, JS::HandleObject obj, + const char *ascii, size_t length, + const JS::CompileOptions &options, + JS::MutableHandleScript script); + +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +JS_CompileUCScript(JSContext *cx, JS::HandleObject obj, + const jschar *chars, size_t length, + const JS::CompileOptions &options, + JS::MutableHandleScript script); + +extern JS_PUBLIC_API(JSObject *) +JS_GetGlobalFromScript(JSScript *script); + +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +JS_CompileFunction(JSContext *cx, JS::HandleObject obj, const char *name, + unsigned nargs, const char *const *argnames, + const char *bytes, size_t length, + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); + +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +JS_CompileUCFunction(JSContext *cx, JS::HandleObject obj, const char *name, + unsigned nargs, const char *const *argnames, + const jschar *chars, size_t length, + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); + +namespace JS { + +/* Options for JavaScript compilation. */ + +/* + * In the most common use case, a CompileOptions instance is allocated on the + * stack, and holds non-owning references to non-POD option values: strings; + * principals; objects; and so on. The code declaring the instance guarantees + * that such option values will outlive the CompileOptions itself: objects are + * otherwise rooted; principals have had their reference counts bumped; strings + * will not be freed until the CompileOptions goes out of scope. In this + * situation, CompileOptions only refers to things others own, so it can be + * lightweight. + * + * In some cases, however, we need to hold compilation options with a + * non-stack-like lifetime. For example, JS::CompileOffThread needs to save + * compilation options where a worker thread can find them, and then return + * immediately. The worker thread will come along at some later point, and use + * the options. + * + * The compiler itself just needs to be able to access a collection of options; + * it doesn't care who owns them, or what's keeping them alive. It does its own + * addrefs/copies/tracing/etc. + * + * So, we have a class hierarchy that reflects these three use cases: + * + * - ReadOnlyCompileOptions is the common base class. It can be used by code + * that simply needs to access options set elsewhere, like the compiler. + * + * - The usual CompileOptions class must be stack-allocated, and holds + * non-owning references to the filename, element, and so on. It's derived + * from ReadOnlyCompileOptions, so the compiler can use it. + * + * - OwningCompileOptions roots / copies / reference counts of all its values, + * and unroots / frees / releases them when it is destructed. It too is + * derived from ReadOnlyCompileOptions, so the compiler accepts it. + */ + +/* + * The common base class for the CompileOptions hierarchy. + * + * Use this in code that only needs to access compilation options created + * elsewhere, like the compiler. Don't instantiate this class (the constructor + * is protected anyway); instead, create instances only of the derived classes: + * CompileOptions and OwningCompileOptions. + */ +class JS_FRIEND_API(ReadOnlyCompileOptions) +{ + friend class CompileOptions; + + protected: + JSPrincipals *originPrincipals_; + const char *filename_; + const char *introducerFilename_; + const jschar *sourceMapURL_; + + // This constructor leaves 'version' set to JSVERSION_UNKNOWN. The structure + // is unusable until that's set to something more specific; the derived + // classes' constructors take care of that, in ways appropriate to their + // purpose. + ReadOnlyCompileOptions() + : originPrincipals_(nullptr), + filename_(nullptr), + introducerFilename_(nullptr), + sourceMapURL_(nullptr), + version(JSVERSION_UNKNOWN), + versionSet(false), + utf8(false), + lineno(1), + column(0), + compileAndGo(false), + forEval(false), + defineOnScope(true), + noScriptRval(false), + selfHostingMode(false), + canLazilyParse(true), + strictOption(false), + extraWarningsOption(false), + werrorOption(false), + asmJSOption(false), + forceAsync(false), + installedFile(false), + sourceIsLazy(false), + introductionType(nullptr), + introductionLineno(0), + introductionOffset(0), + hasIntroductionInfo(false) + { } + + // Set all POD options (those not requiring reference counts, copies, + // rooting, or other hand-holding) to their values in |rhs|. + void copyPODOptions(const ReadOnlyCompileOptions &rhs); + + public: + // Read-only accessors for non-POD options. The proper way to set these + // depends on the derived type. + JSPrincipals *originPrincipals(js::ExclusiveContext *cx) const; + const char *filename() const { return filename_; } + const char *introducerFilename() const { return introducerFilename_; } + const jschar *sourceMapURL() const { return sourceMapURL_; } + virtual JSObject *element() const = 0; + virtual JSString *elementAttributeName() const = 0; + virtual JSScript *introductionScript() const = 0; + + // POD options. + JSVersion version; + bool versionSet; + bool utf8; + unsigned lineno; + unsigned column; + bool compileAndGo; + bool forEval; + bool defineOnScope; + bool noScriptRval; + bool selfHostingMode; + bool canLazilyParse; + bool strictOption; + bool extraWarningsOption; + bool werrorOption; + bool asmJSOption; + bool forceAsync; + bool installedFile; // 'true' iff pre-compiling js file in packaged app + bool sourceIsLazy; + + // |introductionType| is a statically allocated C string: + // one of "eval", "Function", or "GeneratorFunction". + const char *introductionType; + unsigned introductionLineno; + uint32_t introductionOffset; + bool hasIntroductionInfo; + + private: + static JSObject * const nullObjectPtr; + void operator=(const ReadOnlyCompileOptions &) MOZ_DELETE; +}; + +/* + * Compilation options, with dynamic lifetime. An instance of this type + * makes a copy of / holds / roots all dynamically allocated resources + * (principals; elements; strings) that it refers to. Its destructor frees + * / drops / unroots them. This is heavier than CompileOptions, below, but + * unlike CompileOptions, it can outlive any given stack frame. + * + * Note that this *roots* any JS values it refers to - they're live + * unconditionally. Thus, instances of this type can't be owned, directly + * or indirectly, by a JavaScript object: if any value that this roots ever + * comes to refer to the object that owns this, then the whole cycle, and + * anything else it entrains, will never be freed. + */ +class JS_FRIEND_API(OwningCompileOptions) : public ReadOnlyCompileOptions +{ + JSRuntime *runtime; + PersistentRootedObject elementRoot; + PersistentRootedString elementAttributeNameRoot; + PersistentRootedScript introductionScriptRoot; + + public: + // A minimal constructor, for use with OwningCompileOptions::copy. This + // leaves |this.version| set to JSVERSION_UNKNOWN; the instance + // shouldn't be used until we've set that to something real (as |copy| + // will). + explicit OwningCompileOptions(JSContext *cx); + ~OwningCompileOptions(); + + JSObject *element() const MOZ_OVERRIDE { return elementRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } + + // Set this to a copy of |rhs|. Return false on OOM. + bool copy(JSContext *cx, const ReadOnlyCompileOptions &rhs); + + /* These setters make copies of their string arguments, and are fallible. */ + bool setFile(JSContext *cx, const char *f); + bool setFileAndLine(JSContext *cx, const char *f, unsigned l); + bool setSourceMapURL(JSContext *cx, const jschar *s); + bool setIntroducerFilename(JSContext *cx, const char *s); + + /* These setters are infallible, and can be chained. */ + OwningCompileOptions &setLine(unsigned l) { lineno = l; return *this; } + OwningCompileOptions &setElement(JSObject *e) { + elementRoot = e; + return *this; + } + OwningCompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + OwningCompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; + return *this; + } + OwningCompileOptions &setOriginPrincipals(JSPrincipals *p) { + if (p) JS_HoldPrincipals(p); + if (originPrincipals_) JS_DropPrincipals(runtime, originPrincipals_); + originPrincipals_ = p; + return *this; + } + OwningCompileOptions &setVersion(JSVersion v) { + version = v; + versionSet = true; + return *this; + } + OwningCompileOptions &setUTF8(bool u) { utf8 = u; return *this; } + OwningCompileOptions &setColumn(unsigned c) { column = c; return *this; } + OwningCompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } + OwningCompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + OwningCompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } + OwningCompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } + OwningCompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } + OwningCompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } + OwningCompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + OwningCompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + bool setIntroductionInfo(JSContext *cx, const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + if (!setIntroducerFilename(cx, introducerFn)) + return false; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return true; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; +}; + +/* + * Compilation options stored on the stack. An instance of this type + * simply holds references to dynamically allocated resources (element; + * filename; source map URL) that are owned by something else. If you + * create an instance of this type, it's up to you to guarantee that + * everything you store in it will outlive it. + */ +class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOptions +{ + RootedObject elementRoot; + RootedString elementAttributeNameRoot; + RootedScript introductionScriptRoot; + + public: + explicit CompileOptions(JSContext *cx, JSVersion version = JSVERSION_UNKNOWN); + CompileOptions(js::ContextFriendFields *cx, const ReadOnlyCompileOptions &rhs) + : ReadOnlyCompileOptions(), elementRoot(cx), elementAttributeNameRoot(cx), + introductionScriptRoot(cx) + { + copyPODOptions(rhs); + + originPrincipals_ = rhs.originPrincipals_; + filename_ = rhs.filename(); + sourceMapURL_ = rhs.sourceMapURL(); + elementRoot = rhs.element(); + elementAttributeNameRoot = rhs.elementAttributeName(); + introductionScriptRoot = rhs.introductionScript(); + } + + JSObject *element() const MOZ_OVERRIDE { return elementRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } + + CompileOptions &setFile(const char *f) { filename_ = f; return *this; } + CompileOptions &setLine(unsigned l) { lineno = l; return *this; } + CompileOptions &setFileAndLine(const char *f, unsigned l) { + filename_ = f; lineno = l; return *this; + } + CompileOptions &setSourceMapURL(const jschar *s) { sourceMapURL_ = s; return *this; } + CompileOptions &setElement(JSObject *e) { elementRoot = e; return *this; } + CompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + CompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; + return *this; + } + CompileOptions &setOriginPrincipals(JSPrincipals *p) { + originPrincipals_ = p; + return *this; + } + CompileOptions &setVersion(JSVersion v) { + version = v; + versionSet = true; + return *this; + } + CompileOptions &setUTF8(bool u) { utf8 = u; return *this; } + CompileOptions &setColumn(unsigned c) { column = c; return *this; } + CompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } + CompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + CompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } + CompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } + CompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } + CompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } + CompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + CompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + CompileOptions &setIntroductionInfo(const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + introducerFilename_ = introducerFn; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return *this; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; +}; + +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, FILE *file, + JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *filename, + JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t length); + +/* + * Off thread compilation control flow. + * + * After successfully triggering an off thread compile of a script, the + * callback will eventually be invoked with the specified data and a token + * for the compilation. The callback will be invoked while off the main thread, + * so must ensure that its operations are thread safe. Afterwards, + * FinishOffThreadScript must be invoked on the main thread to get the result + * script or nullptr. If maybecx is not specified, the resources will be freed, + * but no script will be returned. + * + * The characters passed in to CompileOffThread must remain live until the + * callback is invoked, and the resulting script will be rooted until the call + * to FinishOffThreadScript. + */ + +extern JS_PUBLIC_API(bool) +CompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, + OffThreadCompileCallback callback, void *callbackData); + +extern JS_PUBLIC_API(JSScript *) +FinishOffThreadScript(JSContext *maybecx, JSRuntime *rt, void *token); + +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *name, unsigned nargs, const char *const *argnames, + SourceBufferHolder &srcBuf, JS::MutableHandleFunction fun); + +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *name, unsigned nargs, const char *const *argnames, + const char *bytes, size_t length, JS::MutableHandleFunction fun); + +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *name, unsigned nargs, const char *const *argnames, + const jschar *chars, size_t length, JS::MutableHandleFunction fun); + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSString *) +JS_DecompileScript(JSContext *cx, JS::Handle script, const char *name, unsigned indent); + +/* + * API extension: OR this into indent to avoid pretty-printing the decompiled + * source resulting from JS_DecompileFunction{,Body}. + */ +#define JS_DONT_PRETTY_PRINT ((unsigned)0x8000) + +extern JS_PUBLIC_API(JSString *) +JS_DecompileFunction(JSContext *cx, JS::Handle fun, unsigned indent); + +extern JS_PUBLIC_API(JSString *) +JS_DecompileFunctionBody(JSContext *cx, JS::Handle fun, unsigned indent); + +/* + * NB: JS_ExecuteScript and the JS_Evaluate*Script* quadruplets use the obj + * parameter as the initial scope chain header, the 'this' keyword value, and + * the variables object (ECMA parlance for where 'var' and 'function' bind + * names) of the execution context for script. + * + * Using obj as the variables object is problematic if obj's parent (which is + * the scope chain link; see JS_SetParent and JS_NewObject) is not null: in + * this case, variables created by 'var x = 0', e.g., go in obj, but variables + * created by assignment to an unbound id, 'x = 0', go in the last object on + * the scope chain linked by parent. + * + * ECMA calls that last scoping object the "global object", but note that many + * embeddings have several such objects. ECMA requires that "global code" be + * executed with the variables object equal to this global object. But these + * JS API entry points provide freedom to execute code against a "sub-global", + * i.e., a parented or scoped object, in which case the variables object will + * differ from the last object on the scope chain, resulting in confusing and + * non-ECMA explicit vs. implicit variable creation. + * + * Caveat embedders: unless you already depend on this buggy variables object + * binding behavior, you should call ContextOptionsRef(cx).setVarObjFix(true) + * for each context in the application, if you pass parented objects as the obj + * parameter, or may ever pass such objects in the future. + * + * Why a runtime option? The alternative is to add six or so new API entry + * points with signatures matching the following six, and that doesn't seem + * worth the code bloat cost. Such new entry points would probably have less + * obvious names, too, so would not tend to be used. The JS_SetOption call, + * OTOH, can be more easily hacked into existing code that does not depend on + * the bug; such code can continue to use the familiar JS_EvaluateScript, + * etc., entry points. + */ +extern JS_PUBLIC_API(bool) +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script); + +namespace JS { + +/* + * Like the above, but handles a cross-compartment script. If the script is + * cross-compartment, it is cloned into the current compartment before executing. + */ +extern JS_PUBLIC_API(bool) +CloneAndExecuteScript(JSContext *cx, JS::Handle obj, JS::Handle script); + +} /* namespace JS */ + +extern JS_PUBLIC_API(bool) +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleValue rval, JSVersion version); + +extern JS_PUBLIC_API(bool) +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JSVersion version); + +extern JS_PUBLIC_API(bool) +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno); + +extern JS_PUBLIC_API(bool) +JS_EvaluateUCScript(JSContext *cx, JS::Handle obj, + const jschar *chars, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandle rval); + +namespace JS { + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename); + +} /* namespace JS */ + +extern JS_PUBLIC_API(bool) +JS_CallFunction(JSContext *cx, JS::HandleObject obj, JS::HandleFunction fun, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_CallFunctionName(JSContext *cx, JS::HandleObject obj, const char *name, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_CallFunctionValue(JSContext *cx, JS::HandleObject obj, JS::HandleValue fval, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); + +namespace JS { + +static inline bool +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleFunction fun, + const JS::HandleValueArray &args, MutableHandleValue rval) +{ + return !!JS_CallFunction(cx, thisObj, fun, args, rval); +} + +static inline bool +Call(JSContext *cx, JS::HandleObject thisObj, const char *name, const JS::HandleValueArray& args, + MutableHandleValue rval) +{ + return !!JS_CallFunctionName(cx, thisObj, name, args, rval); +} + +static inline bool +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval) +{ + return !!JS_CallFunctionValue(cx, thisObj, fun, args, rval); +} + +extern JS_PUBLIC_API(bool) +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval); + +static inline bool +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleObject funObj, const JS::HandleValueArray& args, + MutableHandleValue rval) +{ + JS_ASSERT(funObj); + JS::RootedValue fun(cx, JS::ObjectValue(*funObj)); + return Call(cx, thisv, fun, args, rval); +} + +extern JS_PUBLIC_API(bool) +Construct(JSContext *cx, JS::HandleValue fun, + const JS::HandleValueArray& args, + MutableHandleValue rval); + +} /* namespace JS */ + +/* + * These functions allow setting an interrupt callback that will be called + * from the JS thread some time after any thread triggered the callback using + * JS_RequestInterruptCallback(rt). + * + * To schedule the GC and for other activities the engine internally triggers + * interrupt callbacks. The embedding should thus not rely on callbacks being + * triggered through the external API only. + * + * Important note: Additional callbacks can occur inside the callback handler + * if it re-enters the JS engine. The embedding must ensure that the callback + * is disconnected before attempting such re-entry. + */ +extern JS_PUBLIC_API(JSInterruptCallback) +JS_SetInterruptCallback(JSRuntime *rt, JSInterruptCallback callback); + +extern JS_PUBLIC_API(JSInterruptCallback) +JS_GetInterruptCallback(JSRuntime *rt); + +extern JS_PUBLIC_API(void) +JS_RequestInterruptCallback(JSRuntime *rt); + +extern JS_PUBLIC_API(bool) +JS_IsRunning(JSContext *cx); + +/* + * Saving and restoring frame chains. + * + * These two functions are used to set aside cx's call stack while that stack + * is inactive. After a call to JS_SaveFrameChain, it looks as if there is no + * code running on cx. Before calling JS_RestoreFrameChain, cx's call stack + * must be balanced and all nested calls to JS_SaveFrameChain must have had + * matching JS_RestoreFrameChain calls. + * + * JS_SaveFrameChain deals with cx not having any code running on it. + */ +extern JS_PUBLIC_API(bool) +JS_SaveFrameChain(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_RestoreFrameChain(JSContext *cx); + +#ifdef MOZ_TRACE_JSCALLS +/* + * The callback is expected to be quick and noninvasive. It should not + * request interrupts, turn on debugging, or produce uncaught JS + * exceptions. The state of the stack and registers in the context + * cannot be relied upon, since this callback may be invoked directly + * from either JIT. The 'entering' field means we are entering a + * function if it is positive, leaving a function if it is zero or + * negative. + */ +extern JS_PUBLIC_API(void) +JS_SetFunctionCallback(JSContext *cx, JSFunctionCallback fcb); + +extern JS_PUBLIC_API(JSFunctionCallback) +JS_GetFunctionCallback(JSContext *cx); +#endif /* MOZ_TRACE_JSCALLS */ + +/************************************************************************/ + +/* + * Strings. + * + * NB: JS_NewUCString takes ownership of bytes on success, avoiding a copy; + * but on error (signified by null return), it leaves chars owned by the + * caller. So the caller must free bytes in the error case, if it has no use + * for them. In contrast, all the JS_New*StringCopy* functions do not take + * ownership of the character memory passed to them -- they copy it. + */ +extern JS_PUBLIC_API(JSString *) +JS_NewStringCopyN(JSContext *cx, const char *s, size_t n); + +extern JS_PUBLIC_API(JSString *) +JS_NewStringCopyZ(JSContext *cx, const char *s); + +extern JS_PUBLIC_API(JSString *) +JS_InternJSString(JSContext *cx, JS::HandleString str); + +extern JS_PUBLIC_API(JSString *) +JS_InternStringN(JSContext *cx, const char *s, size_t length); + +extern JS_PUBLIC_API(JSString *) +JS_InternString(JSContext *cx, const char *s); + +extern JS_PUBLIC_API(JSString *) +JS_NewUCString(JSContext *cx, jschar *chars, size_t length); + +extern JS_PUBLIC_API(JSString *) +JS_NewUCStringCopyN(JSContext *cx, const jschar *s, size_t n); + +extern JS_PUBLIC_API(JSString *) +JS_NewUCStringCopyZ(JSContext *cx, const jschar *s); + +extern JS_PUBLIC_API(JSString *) +JS_InternUCStringN(JSContext *cx, const jschar *s, size_t length); + +extern JS_PUBLIC_API(JSString *) +JS_InternUCString(JSContext *cx, const jschar *s); + +extern JS_PUBLIC_API(bool) +JS_CompareStrings(JSContext *cx, JSString *str1, JSString *str2, int32_t *result); + +extern JS_PUBLIC_API(bool) +JS_StringEqualsAscii(JSContext *cx, JSString *str, const char *asciiBytes, bool *match); + +extern JS_PUBLIC_API(size_t) +JS_PutEscapedString(JSContext *cx, char *buffer, size_t size, JSString *str, char quote); + +extern JS_PUBLIC_API(bool) +JS_FileEscapedString(FILE *fp, JSString *str, char quote); + +/* + * Extracting string characters and length. + * + * While getting the length of a string is infallible, getting the chars can + * fail. As indicated by the lack of a JSContext parameter, there are two + * special cases where getting the chars is infallible: + * + * The first case is interned strings, i.e., strings from JS_InternString or + * JSID_TO_STRING(id), using JS_GetLatin1InternedStringChars or + * JS_GetTwoByteInternedStringChars. + * + * The second case is "flat" strings that have been explicitly prepared in a + * fallible context by JS_FlattenString. To catch errors, a separate opaque + * JSFlatString type is returned by JS_FlattenString and expected by + * JS_GetFlatStringChars. Note, though, that this is purely a syntactic + * distinction: the input and output of JS_FlattenString are the same actual + * GC-thing. If a JSString is known to be flat, JS_ASSERT_STRING_IS_FLAT can be + * used to make a debug-checked cast. Example: + * + * // in a fallible context + * JSFlatString *fstr = JS_FlattenString(cx, str); + * if (!fstr) + * return false; + * JS_ASSERT(fstr == JS_ASSERT_STRING_IS_FLAT(str)); + * + * // in an infallible context, for the same 'str' + * AutoCheckCannotGC nogc; + * const jschar *chars = JS_GetTwoByteFlatStringChars(nogc, fstr) + * JS_ASSERT(chars); + * + * Flat strings and interned strings are always null-terminated, so + * JS_FlattenString can be used to get a null-terminated string. + * + * Additionally, string characters are stored as either Latin1Char (8-bit) + * or jschar (16-bit). Clients can use JS_StringHasLatin1Chars and can then + * call either the Latin1* or TwoByte* functions. Some functions like + * JS_CopyStringChars and JS_GetStringCharAt accept both Latin1 and TwoByte + * strings. + */ + +extern JS_PUBLIC_API(size_t) +JS_GetStringLength(JSString *str); + +extern JS_PUBLIC_API(bool) +JS_StringIsFlat(JSString *str); + +/* Returns true iff the string's characters are stored as Latin1. */ +extern JS_PUBLIC_API(bool) +JS_StringHasLatin1Chars(JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1StringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); + +extern JS_PUBLIC_API(const jschar *) +JS_GetTwoByteStringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); + +extern JS_PUBLIC_API(bool) +JS_GetStringCharAt(JSContext *cx, JSString *str, size_t index, jschar *res); + +extern JS_PUBLIC_API(jschar) +JS_GetFlatStringCharAt(JSFlatString *str, size_t index); + +extern JS_PUBLIC_API(const jschar *) +JS_GetTwoByteExternalStringChars(JSString *str); + +extern JS_PUBLIC_API(bool) +JS_CopyStringChars(JSContext *cx, mozilla::Range dest, JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1InternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); + +extern JS_PUBLIC_API(const jschar *) +JS_GetTwoByteInternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); + +extern JS_PUBLIC_API(JSFlatString *) +JS_FlattenString(JSContext *cx, JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1FlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); + +extern JS_PUBLIC_API(const jschar *) +JS_GetTwoByteFlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); + +static MOZ_ALWAYS_INLINE JSFlatString * +JSID_TO_FLAT_STRING(jsid id) +{ + JS_ASSERT(JSID_IS_STRING(id)); + return (JSFlatString *)(JSID_BITS(id)); +} + +static MOZ_ALWAYS_INLINE JSFlatString * +JS_ASSERT_STRING_IS_FLAT(JSString *str) +{ + JS_ASSERT(JS_StringIsFlat(str)); + return (JSFlatString *)str; +} + +static MOZ_ALWAYS_INLINE JSString * +JS_FORGET_STRING_FLATNESS(JSFlatString *fstr) +{ + return (JSString *)fstr; +} + +/* + * Additional APIs that avoid fallibility when given a flat string. + */ + +extern JS_PUBLIC_API(bool) +JS_FlatStringEqualsAscii(JSFlatString *str, const char *asciiBytes); + +extern JS_PUBLIC_API(size_t) +JS_PutEscapedFlatString(char *buffer, size_t size, JSFlatString *str, char quote); + +/* + * Create a dependent string, i.e., a string that owns no character storage, + * but that refers to a slice of another string's chars. Dependent strings + * are mutable by definition, so the thread safety comments above apply. + */ +extern JS_PUBLIC_API(JSString *) +JS_NewDependentString(JSContext *cx, JS::HandleString str, size_t start, + size_t length); + +/* + * Concatenate two strings, possibly resulting in a rope. + * See above for thread safety comments. + */ +extern JS_PUBLIC_API(JSString *) +JS_ConcatStrings(JSContext *cx, JS::HandleString left, JS::HandleString right); + +/* + * For JS_DecodeBytes, set *dstlenp to the size of the destination buffer before + * the call; on return, *dstlenp contains the number of jschars actually stored. + * To determine the necessary destination buffer size, make a sizing call that + * passes nullptr for dst. + * + * On errors, the functions report the error. In that case, *dstlenp contains + * the number of characters or bytes transferred so far. If cx is nullptr, no + * error is reported on failure, and the functions simply return false. + * + * NB: This function does not store an additional zero byte or jschar after the + * transcoded string. + */ +JS_PUBLIC_API(bool) +JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst, + size_t *dstlenp); + +/* + * A variation on JS_EncodeCharacters where a null terminated string is + * returned that you are expected to call JS_free on when done. + */ +JS_PUBLIC_API(char *) +JS_EncodeString(JSContext *cx, JSString *str); + +/* + * Same behavior as JS_EncodeString(), but encode into UTF-8 string + */ +JS_PUBLIC_API(char *) +JS_EncodeStringToUTF8(JSContext *cx, JS::HandleString str); + +/* + * Get number of bytes in the string encoding (without accounting for a + * terminating zero bytes. The function returns (size_t) -1 if the string + * can not be encoded into bytes and reports an error using cx accordingly. + */ +JS_PUBLIC_API(size_t) +JS_GetStringEncodingLength(JSContext *cx, JSString *str); + +/* + * Encode string into a buffer. The function does not stores an additional + * zero byte. The function returns (size_t) -1 if the string can not be + * encoded into bytes with no error reported. Otherwise it returns the number + * of bytes that are necessary to encode the string. If that exceeds the + * length parameter, the string will be cut and only length bytes will be + * written into the buffer. + */ +JS_PUBLIC_API(size_t) +JS_EncodeStringToBuffer(JSContext *cx, JSString *str, char *buffer, size_t length); + +class JSAutoByteString +{ + public: + JSAutoByteString(JSContext *cx, JSString *str + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mBytes(JS_EncodeString(cx, str)) + { + JS_ASSERT(cx); + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + explicit JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + : mBytes(nullptr) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + ~JSAutoByteString() { + js_free(mBytes); + } + + /* Take ownership of the given byte array. */ + void initBytes(char *bytes) { + JS_ASSERT(!mBytes); + mBytes = bytes; + } + + char *encodeLatin1(JSContext *cx, JSString *str) { + JS_ASSERT(!mBytes); + JS_ASSERT(cx); + mBytes = JS_EncodeString(cx, str); + return mBytes; + } + + char *encodeLatin1(js::ExclusiveContext *cx, JSString *str); + + char *encodeUtf8(JSContext *cx, JS::HandleString str) { + JS_ASSERT(!mBytes); + JS_ASSERT(cx); + mBytes = JS_EncodeStringToUTF8(cx, str); + return mBytes; + } + + void clear() { + js_free(mBytes); + mBytes = nullptr; + } + + char *ptr() const { + return mBytes; + } + + bool operator!() const { + return !mBytes; + } + + size_t length() const { + if (!mBytes) + return 0; + return strlen(mBytes); + } + + private: + char *mBytes; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + /* Copy and assignment are not supported. */ + JSAutoByteString(const JSAutoByteString &another); + JSAutoByteString &operator=(const JSAutoByteString &another); +}; + +namespace JS { + +extern JS_PUBLIC_API(JSAddonId *) +NewAddonId(JSContext *cx, JS::HandleString str); + +extern JS_PUBLIC_API(JSString *) +StringOfAddonId(JSAddonId *id); + +extern JS_PUBLIC_API(JSAddonId *) +AddonIdOfObject(JSObject *obj); + +} // namespace JS + +/************************************************************************/ +/* + * Symbols + */ + +namespace JS { + +/* + * Create a new Symbol with the given description. This function never returns + * a Symbol that is in the Runtime-wide symbol registry. + * + * If description is null, the new Symbol's [[Description]] attribute is + * undefined. + */ +JS_PUBLIC_API(Symbol *) +NewSymbol(JSContext *cx, HandleString description); + +/* + * Symbol.for as specified in ES6. + * + * Get a Symbol with the description 'key' from the Runtime-wide symbol registry. + * If there is not already a Symbol with that description in the registry, a new + * Symbol is created and registered. 'key' must not be null. + */ +JS_PUBLIC_API(Symbol *) +GetSymbolFor(JSContext *cx, HandleString key); + +/* + * Get the [[Description]] attribute of the given symbol. + * + * This function is infallible. If it returns null, that means the symbol's + * [[Description]] is undefined. + */ +JS_PUBLIC_API(JSString *) +GetSymbolDescription(HandleSymbol symbol); + +/* Well-known symbols. */ +MOZ_BEGIN_ENUM_CLASS(SymbolCode, uint32_t) + iterator, // well-known Symbol.iterator + InSymbolRegistry = 0xfffffffe, // created by Symbol.for() or JS::GetSymbolFor() + UniqueSymbol = 0xffffffff // created by Symbol() or JS::NewSymbol() +MOZ_END_ENUM_CLASS(SymbolCode) + +/* For use in loops that iterate over the well-known symbols. */ +const size_t WellKnownSymbolLimit = 1; + +/* + * Return the SymbolCode telling what sort of symbol `symbol` is. + * + * A symbol's SymbolCode never changes once it is created. + */ +JS_PUBLIC_API(SymbolCode) +GetSymbolCode(Handle symbol); + +/* + * Get one of the well-known symbols defined by ES6. A single set of well-known + * symbols is shared by all compartments in a JSRuntime. + * + * `which` must be in the range [0, WellKnownSymbolLimit). + */ +JS_PUBLIC_API(Symbol *) +GetWellKnownSymbol(JSContext *cx, SymbolCode which); + +} /* namespace JS */ + +/************************************************************************/ +/* + * JSON functions + */ +typedef bool (* JSONWriteCallback)(const jschar *buf, uint32_t len, void *data); + +/* + * JSON.stringify as specified by ES5. + */ +JS_PUBLIC_API(bool) +JS_Stringify(JSContext *cx, JS::MutableHandleValue value, JS::HandleObject replacer, + JS::HandleValue space, JSONWriteCallback callback, void *data); + +/* + * JSON.parse as specified by ES5. + */ +JS_PUBLIC_API(bool) +JS_ParseJSON(JSContext *cx, const jschar *chars, uint32_t len, JS::MutableHandleValue vp); + +JS_PUBLIC_API(bool) +JS_ParseJSON(JSContext *cx, JS::HandleString str, JS::MutableHandleValue vp); + +JS_PUBLIC_API(bool) +JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32_t len, JS::HandleValue reviver, + JS::MutableHandleValue vp); + +JS_PUBLIC_API(bool) +JS_ParseJSONWithReviver(JSContext *cx, JS::HandleString str, JS::HandleValue reviver, + JS::MutableHandleValue vp); + +/************************************************************************/ + +/* + * The default locale for the ECMAScript Internationalization API + * (Intl.Collator, Intl.NumberFormat, Intl.DateTimeFormat). + * Note that the Internationalization API encourages clients to + * specify their own locales. + * The locale string remains owned by the caller. + */ +extern JS_PUBLIC_API(bool) +JS_SetDefaultLocale(JSRuntime *rt, const char *locale); + +/* + * Reset the default locale to OS defaults. + */ +extern JS_PUBLIC_API(void) +JS_ResetDefaultLocale(JSRuntime *rt); + +/* + * Locale specific string conversion and error message callbacks. + */ +struct JSLocaleCallbacks { + JSLocaleToUpperCase localeToUpperCase; + JSLocaleToLowerCase localeToLowerCase; + JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API + JSLocaleToUnicode localeToUnicode; +}; + +/* + * Establish locale callbacks. The pointer must persist as long as the + * JSRuntime. Passing nullptr restores the default behaviour. + */ +extern JS_PUBLIC_API(void) +JS_SetLocaleCallbacks(JSRuntime *rt, JSLocaleCallbacks *callbacks); + +/* + * Return the address of the current locale callbacks struct, which may + * be nullptr. + */ +extern JS_PUBLIC_API(JSLocaleCallbacks *) +JS_GetLocaleCallbacks(JSRuntime *rt); + +/************************************************************************/ + +/* + * Error reporting. + */ + +/* + * Report an exception represented by the sprintf-like conversion of format + * and its arguments. This exception message string is passed to a pre-set + * JSErrorReporter function (set by JS_SetErrorReporter). + */ +extern JS_PUBLIC_API(void) +JS_ReportError(JSContext *cx, const char *format, ...); + +/* + * Use an errorNumber to retrieve the format string, args are char * + */ +extern JS_PUBLIC_API(void) +JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback, + void *userRef, const unsigned errorNumber, ...); + +#ifdef va_start +extern JS_PUBLIC_API(void) +JS_ReportErrorNumberVA(JSContext *cx, JSErrorCallback errorCallback, + void *userRef, const unsigned errorNumber, va_list ap); +#endif + +/* + * Use an errorNumber to retrieve the format string, args are jschar * + */ +extern JS_PUBLIC_API(void) +JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback, + void *userRef, const unsigned errorNumber, ...); + +extern JS_PUBLIC_API(void) +JS_ReportErrorNumberUCArray(JSContext *cx, JSErrorCallback errorCallback, + void *userRef, const unsigned errorNumber, + const jschar **args); + +/* + * As above, but report a warning instead (JSREPORT_IS_WARNING(report.flags)). + * Return true if there was no error trying to issue the warning, and if the + * warning was not converted into an error due to the JSOPTION_WERROR option + * being set, false otherwise. + */ +extern JS_PUBLIC_API(bool) +JS_ReportWarning(JSContext *cx, const char *format, ...); + +extern JS_PUBLIC_API(bool) +JS_ReportErrorFlagsAndNumber(JSContext *cx, unsigned flags, + JSErrorCallback errorCallback, void *userRef, + const unsigned errorNumber, ...); + +extern JS_PUBLIC_API(bool) +JS_ReportErrorFlagsAndNumberUC(JSContext *cx, unsigned flags, + JSErrorCallback errorCallback, void *userRef, + const unsigned errorNumber, ...); + +/* + * Complain when out of memory. + */ +extern JS_PUBLIC_API(void) +JS_ReportOutOfMemory(JSContext *cx); + +/* + * Complain when an allocation size overflows the maximum supported limit. + */ +extern JS_PUBLIC_API(void) +JS_ReportAllocationOverflow(JSContext *cx); + +struct JSErrorReport { + const char *filename; /* source file name, URL, etc., or null */ + JSPrincipals *originPrincipals; /* see 'originPrincipals' comment above */ + unsigned lineno; /* source line number */ + const char *linebuf; /* offending source line without final \n */ + const char *tokenptr; /* pointer to error token in linebuf */ + const jschar *uclinebuf; /* unicode (original) line buffer */ + const jschar *uctokenptr; /* unicode (original) token pointer */ + unsigned flags; /* error/warning, etc. */ + unsigned errorNumber; /* the error number, e.g. see js.msg */ + const jschar *ucmessage; /* the (default) error message */ + const jschar **messageArgs; /* arguments for the error message */ + int16_t exnType; /* One of the JSExnType constants */ + unsigned column; /* zero-based column index in line */ +}; + +/* + * JSErrorReport flag values. These may be freely composed. + */ +#define JSREPORT_ERROR 0x0 /* pseudo-flag for default case */ +#define JSREPORT_WARNING 0x1 /* reported via JS_ReportWarning */ +#define JSREPORT_EXCEPTION 0x2 /* exception was thrown */ +#define JSREPORT_STRICT 0x4 /* error or warning due to strict option */ + +/* + * This condition is an error in strict mode code, a warning if + * JS_HAS_STRICT_OPTION(cx), and otherwise should not be reported at + * all. We check the strictness of the context's top frame's script; + * where that isn't appropriate, the caller should do the right checks + * itself instead of using this flag. + */ +#define JSREPORT_STRICT_MODE_ERROR 0x8 + +/* + * If JSREPORT_EXCEPTION is set, then a JavaScript-catchable exception + * has been thrown for this runtime error, and the host should ignore it. + * Exception-aware hosts should also check for JS_IsExceptionPending if + * JS_ExecuteScript returns failure, and signal or propagate the exception, as + * appropriate. + */ +#define JSREPORT_IS_WARNING(flags) (((flags) & JSREPORT_WARNING) != 0) +#define JSREPORT_IS_EXCEPTION(flags) (((flags) & JSREPORT_EXCEPTION) != 0) +#define JSREPORT_IS_STRICT(flags) (((flags) & JSREPORT_STRICT) != 0) +#define JSREPORT_IS_STRICT_MODE_ERROR(flags) (((flags) & \ + JSREPORT_STRICT_MODE_ERROR) != 0) +extern JS_PUBLIC_API(JSErrorReporter) +JS_GetErrorReporter(JSContext *cx); + +extern JS_PUBLIC_API(JSErrorReporter) +JS_SetErrorReporter(JSContext *cx, JSErrorReporter er); + +namespace JS { + +extern JS_PUBLIC_API(bool) +CreateError(JSContext *cx, JSExnType type, HandleString stack, + HandleString fileName, uint32_t lineNumber, uint32_t columnNumber, + JSErrorReport *report, HandleString message, MutableHandleValue rval); + +/************************************************************************/ + +/* + * Weak Maps. + */ + +extern JS_PUBLIC_API(JSObject *) +NewWeakMapObject(JSContext *cx); + +extern JS_PUBLIC_API(bool) +IsWeakMapObject(JSObject *obj); + +extern JS_PUBLIC_API(bool) +GetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::MutableHandleValue val); + +extern JS_PUBLIC_API(bool) +SetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::HandleValue val); + +} /* namespace JS */ + +/* + * Dates. + */ + +extern JS_PUBLIC_API(JSObject *) +JS_NewDateObject(JSContext *cx, int year, int mon, int mday, int hour, int min, int sec); + +extern JS_PUBLIC_API(JSObject *) +JS_NewDateObjectMsec(JSContext *cx, double msec); + +/* + * Infallible predicate to test whether obj is a date object. + */ +extern JS_PUBLIC_API(bool) +JS_ObjectIsDate(JSContext *cx, JS::HandleObject obj); + +/* + * Clears the cache of calculated local time from each Date object. + * Call to propagate a system timezone change. + */ +extern JS_PUBLIC_API(void) +JS_ClearDateCaches(JSContext *cx); + +/************************************************************************/ + +/* + * Regular Expressions. + */ +#define JSREG_FOLD 0x01u /* fold uppercase to lowercase */ +#define JSREG_GLOB 0x02u /* global exec, creates array of matches */ +#define JSREG_MULTILINE 0x04u /* treat ^ and $ as begin and end of line */ +#define JSREG_STICKY 0x08u /* only match starting at lastIndex */ + +extern JS_PUBLIC_API(JSObject *) +JS_NewRegExpObject(JSContext *cx, JS::HandleObject obj, char *bytes, size_t length, + unsigned flags); + +extern JS_PUBLIC_API(JSObject *) +JS_NewUCRegExpObject(JSContext *cx, JS::HandleObject obj, jschar *chars, size_t length, + unsigned flags); + +extern JS_PUBLIC_API(bool) +JS_SetRegExpInput(JSContext *cx, JS::HandleObject obj, JS::HandleString input, + bool multiline); + +extern JS_PUBLIC_API(bool) +JS_ClearRegExpStatics(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(bool) +JS_ExecuteRegExp(JSContext *cx, JS::HandleObject obj, JS::HandleObject reobj, + jschar *chars, size_t length, size_t *indexp, bool test, + JS::MutableHandleValue rval); + +/* RegExp interface for clients without a global object. */ + +extern JS_PUBLIC_API(JSObject *) +JS_NewRegExpObjectNoStatics(JSContext *cx, char *bytes, size_t length, unsigned flags); + +extern JS_PUBLIC_API(JSObject *) +JS_NewUCRegExpObjectNoStatics(JSContext *cx, jschar *chars, size_t length, unsigned flags); + +extern JS_PUBLIC_API(bool) +JS_ExecuteRegExpNoStatics(JSContext *cx, JS::HandleObject reobj, jschar *chars, size_t length, + size_t *indexp, bool test, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_ObjectIsRegExp(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(unsigned) +JS_GetRegExpFlags(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(JSString *) +JS_GetRegExpSource(JSContext *cx, JS::HandleObject obj); + +/************************************************************************/ + +extern JS_PUBLIC_API(bool) +JS_IsExceptionPending(JSContext *cx); + +extern JS_PUBLIC_API(bool) +JS_GetPendingException(JSContext *cx, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(void) +JS_SetPendingException(JSContext *cx, JS::HandleValue v); + +extern JS_PUBLIC_API(void) +JS_ClearPendingException(JSContext *cx); + +extern JS_PUBLIC_API(bool) +JS_ReportPendingException(JSContext *cx); + +namespace JS { + +/* + * Save and later restore the current exception state of a given JSContext. + * This is useful for implementing behavior in C++ that's like try/catch + * or try/finally in JS. + * + * Typical usage: + * + * bool ok = JS_EvaluateScript(cx, ...); + * AutoSaveExceptionState savedExc(cx); + * ... cleanup that might re-enter JS ... + * return ok; + */ +class JS_PUBLIC_API(AutoSaveExceptionState) +{ + private: + JSContext *context; + bool wasPropagatingForcedReturn; + bool wasThrowing; + RootedValue exceptionValue; + + public: + /* + * Take a snapshot of cx's current exception state. Then clear any current + * pending exception in cx. + */ + explicit AutoSaveExceptionState(JSContext *cx); + + /* + * If neither drop() nor restore() was called, restore the exception + * state only if no exception is currently pending on cx. + */ + ~AutoSaveExceptionState(); + + /* + * Discard any stored exception state. + * If this is called, the destructor is a no-op. + */ + void drop() { + wasPropagatingForcedReturn = false; + wasThrowing = false; + exceptionValue.setUndefined(); + } + + /* + * Replace cx's exception state with the stored exception state. Then + * discard the stored exception state. If this is called, the + * destructor is a no-op. + */ + void restore(); +}; + +} /* namespace JS */ + +/* Deprecated API. Use AutoSaveExceptionState instead. */ +extern JS_PUBLIC_API(JSExceptionState *) +JS_SaveExceptionState(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_RestoreExceptionState(JSContext *cx, JSExceptionState *state); + +extern JS_PUBLIC_API(void) +JS_DropExceptionState(JSContext *cx, JSExceptionState *state); + +/* + * If the given object is an exception object, the exception will have (or be + * able to lazily create) an error report struct, and this function will return + * the address of that struct. Otherwise, it returns nullptr. The lifetime + * of the error report struct that might be returned is the same as the + * lifetime of the exception object. + */ +extern JS_PUBLIC_API(JSErrorReport *) +JS_ErrorFromException(JSContext *cx, JS::HandleObject obj); + +/* + * Throws a StopIteration exception on cx. + */ +extern JS_PUBLIC_API(bool) +JS_ThrowStopIteration(JSContext *cx); + +extern JS_PUBLIC_API(bool) +JS_IsStopIteration(jsval v); + +extern JS_PUBLIC_API(intptr_t) +JS_GetCurrentThread(); + +/* + * A JS runtime always has an "owner thread". The owner thread is set when the + * runtime is created (to the current thread) and practically all entry points + * into the JS engine check that a runtime (or anything contained in the + * runtime: context, compartment, object, etc) is only touched by its owner + * thread. Embeddings may check this invariant outside the JS engine by calling + * JS_AbortIfWrongThread (which will abort if not on the owner thread, even for + * non-debug builds). + */ + +extern JS_PUBLIC_API(void) +JS_AbortIfWrongThread(JSRuntime *rt); + +/************************************************************************/ + +/* + * A constructor can request that the JS engine create a default new 'this' + * object of the given class, using the callee to determine parentage and + * [[Prototype]]. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const JS::CallArgs& args); + +/************************************************************************/ + +#ifdef JS_GC_ZEAL +#define JS_DEFAULT_ZEAL_FREQ 100 + +extern JS_PUBLIC_API(void) +JS_SetGCZeal(JSContext *cx, uint8_t zeal, uint32_t frequency); + +extern JS_PUBLIC_API(void) +JS_ScheduleGC(JSContext *cx, uint32_t count); +#endif + +extern JS_PUBLIC_API(void) +JS_SetParallelParsingEnabled(JSRuntime *rt, bool enabled); + +extern JS_PUBLIC_API(void) +JS_SetOffthreadIonCompilationEnabled(JSRuntime *rt, bool enabled); + +#define JIT_COMPILER_OPTIONS(Register) \ + Register(BASELINE_USECOUNT_TRIGGER, "baseline.usecount.trigger") \ + Register(ION_USECOUNT_TRIGGER, "ion.usecount.trigger") \ + Register(ION_ENABLE, "ion.enable") \ + Register(BASELINE_ENABLE, "baseline.enable") \ + Register(OFFTHREAD_COMPILATION_ENABLE, "offthread-compilation.enable") \ + Register(SIGNALS_ENABLE, "signals.enable") + +typedef enum JSJitCompilerOption { +#define JIT_COMPILER_DECLARE(key, str) \ + JSJITCOMPILER_ ## key, + + JIT_COMPILER_OPTIONS(JIT_COMPILER_DECLARE) +#undef JIT_COMPILER_DECLARE + + JSJITCOMPILER_NOT_AN_OPTION +} JSJitCompilerOption; + +extern JS_PUBLIC_API(void) +JS_SetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt, uint32_t value); +extern JS_PUBLIC_API(int) +JS_GetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt); + +/* + * Convert a uint32_t index into a jsid. + */ +extern JS_PUBLIC_API(bool) +JS_IndexToId(JSContext *cx, uint32_t index, JS::MutableHandleId); + +/* + * Convert chars into a jsid. + * + * |chars| may not be an index. + */ +extern JS_PUBLIC_API(bool) +JS_CharsToId(JSContext* cx, JS::TwoByteChars chars, JS::MutableHandleId); + +/* + * Test if the given string is a valid ECMAScript identifier + */ +extern JS_PUBLIC_API(bool) +JS_IsIdentifier(JSContext *cx, JS::HandleString str, bool *isIdentifier); + +namespace JS { + +/* + * AutoFilename encapsulates a pointer to a C-string and keeps the C-string + * alive for as long as the associated AutoFilename object is alive. + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(AutoFilename) +{ + void *scriptSource_; + + AutoFilename(const AutoFilename &) MOZ_DELETE; + void operator=(const AutoFilename &) MOZ_DELETE; + + public: + AutoFilename() : scriptSource_(nullptr) {} + ~AutoFilename() { reset(nullptr); } + + const char *get() const; + + void reset(void *newScriptSource); +}; + +/* + * Return the current filename and line number of the most currently running + * frame. Returns true if a scripted frame was found, false otherwise. + * + * If a the embedding has hidden the scripted caller for the topmost activation + * record, this will also return false. + */ +extern JS_PUBLIC_API(bool) +DescribeScriptedCaller(JSContext *cx, AutoFilename *filename = nullptr, + unsigned *lineno = nullptr); + +extern JS_PUBLIC_API(JSObject *) +GetScriptedCallerGlobal(JSContext *cx); + +/* + * Informs the JS engine that the scripted caller should be hidden. This can be + * used by the embedding to maintain an override of the scripted caller in its + * calculations, by hiding the scripted caller in the JS engine and pushing data + * onto a separate stack, which it inspects when DescribeScriptedCaller returns + * null. + * + * We maintain a counter on each activation record. Add() increments the counter + * of the topmost activation, and Remove() decrements it. The count may never + * drop below zero, and must always be exactly zero when the activation is + * popped from the stack. + */ +extern JS_PUBLIC_API(void) +HideScriptedCaller(JSContext *cx); + +extern JS_PUBLIC_API(void) +UnhideScriptedCaller(JSContext *cx); + +class AutoHideScriptedCaller +{ + public: + explicit AutoHideScriptedCaller(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mContext(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + HideScriptedCaller(mContext); + } + ~AutoHideScriptedCaller() { + UnhideScriptedCaller(mContext); + } + + protected: + JSContext *mContext; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +} /* namespace JS */ + +/* + * Encode/Decode interpreted scripts and functions to/from memory. + */ + +extern JS_PUBLIC_API(void *) +JS_EncodeScript(JSContext *cx, JS::HandleScript script, uint32_t *lengthp); + +extern JS_PUBLIC_API(void *) +JS_EncodeInterpretedFunction(JSContext *cx, JS::HandleObject funobj, uint32_t *lengthp); + +extern JS_PUBLIC_API(JSScript *) +JS_DecodeScript(JSContext *cx, const void *data, uint32_t length, JSPrincipals *originPrincipals); + +extern JS_PUBLIC_API(JSObject *) +JS_DecodeInterpretedFunction(JSContext *cx, const void *data, uint32_t length, + JSPrincipals *originPrincipals); + +namespace JS { + +/* + * This callback represents a request by the JS engine to open for reading the + * existing cache entry for the given global and char range that may contain a + * module. If a cache entry exists, the callback shall return 'true' and return + * the size, base address and an opaque file handle as outparams. If the + * callback returns 'true', the JS engine guarantees a call to + * CloseAsmJSCacheEntryForReadOp, passing the same base address, size and + * handle. + */ +typedef bool +(* OpenAsmJSCacheEntryForReadOp)(HandleObject global, const jschar *begin, const jschar *limit, + size_t *size, const uint8_t **memory, intptr_t *handle); +typedef void +(* CloseAsmJSCacheEntryForReadOp)(size_t size, const uint8_t *memory, intptr_t handle); + +/* + * This callback represents a request by the JS engine to open for writing a + * cache entry of the given size for the given global and char range containing + * the just-compiled module. If cache entry space is available, the callback + * shall return 'true' and return the base address and an opaque file handle as + * outparams. If the callback returns 'true', the JS engine guarantees a call + * to CloseAsmJSCacheEntryForWriteOp passing the same base address, size and + * handle. + * + * If 'installed' is true, then the cache entry is associated with a permanently + * installed JS file (e.g., in a packaged webapp). This information allows the + * embedding to store the cache entry in a installed location associated with + * the principal of 'global' where it will not be evicted until the associated + * installed JS file is removed. + */ +typedef bool +(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, bool installed, + const jschar *begin, const jschar *end, + size_t size, uint8_t **memory, intptr_t *handle); +typedef void +(* CloseAsmJSCacheEntryForWriteOp)(size_t size, uint8_t *memory, intptr_t handle); + +typedef js::Vector BuildIdCharVector; + +// Return the buildId (represented as a sequence of characters) associated with +// the currently-executing build. If the JS engine is embedded such that a +// single cache entry can be observed by different compiled versions of the JS +// engine, it is critical that the buildId shall change for each new build of +// the JS engine. + +typedef bool +(* BuildIdOp)(BuildIdCharVector *buildId); + +struct AsmJSCacheOps +{ + OpenAsmJSCacheEntryForReadOp openEntryForRead; + CloseAsmJSCacheEntryForReadOp closeEntryForRead; + OpenAsmJSCacheEntryForWriteOp openEntryForWrite; + CloseAsmJSCacheEntryForWriteOp closeEntryForWrite; + BuildIdOp buildId; +}; + +extern JS_PUBLIC_API(void) +SetAsmJSCacheOps(JSRuntime *rt, const AsmJSCacheOps *callbacks); + +/* + * Convenience class for imitating a JS level for-of loop. Typical usage: + * + * ForOfIterator it(cx); + * if (!it.init(iterable)) + * return false; + * RootedValue val(cx); + * while (true) { + * bool done; + * if (!it.next(&val, &done)) + * return false; + * if (done) + * break; + * if (!DoStuff(cx, val)) + * return false; + * } + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(ForOfIterator) { + protected: + JSContext *cx_; + /* + * Use the ForOfPIC on the global object (see vm/GlobalObject.h) to try + * to optimize iteration across arrays. + * + * Case 1: Regular Iteration + * iterator - pointer to the iterator object. + * index - fixed to NOT_ARRAY (== UINT32_MAX) + * + * Case 2: Optimized Array Iteration + * iterator - pointer to the array object. + * index - current position in array. + * + * The cases are distinguished by whether or not |index| is equal to NOT_ARRAY. + */ + JS::RootedObject iterator; + uint32_t index; + + static const uint32_t NOT_ARRAY = UINT32_MAX; + + ForOfIterator(const ForOfIterator &) MOZ_DELETE; + ForOfIterator &operator=(const ForOfIterator &) MOZ_DELETE; + + public: + explicit ForOfIterator(JSContext *cx) : cx_(cx), iterator(cx_), index(NOT_ARRAY) { } + + enum NonIterableBehavior { + ThrowOnNonIterable, + AllowNonIterable + }; + + /* + * Initialize the iterator. If AllowNonIterable is passed then if iterable + * does not have a callable @@iterator init() will just return true instead + * of throwing. Callers should then check valueIsIterable() before + * continuing with the iteration. + */ + bool init(JS::HandleValue iterable, + NonIterableBehavior nonIterableBehavior = ThrowOnNonIterable); + + /* + * This method assumes that |iterator| is already an iterator. It will not + * check for, and call @@iterator. Callers should make sure that the passed + * in value is in fact an iterator. + */ + bool initWithIterator(JS::HandleValue aIterator); + + /* + * Get the next value from the iterator. If false *done is true + * after this call, do not examine val. + */ + bool next(JS::MutableHandleValue val, bool *done); + + /* + * If initialized with throwOnNonCallable = false, check whether + * the value is iterable. + */ + bool valueIsIterable() const { + return iterator; + } + + private: + inline bool nextFromOptimizedArray(MutableHandleValue val, bool *done); + bool materializeArrayIterator(); +}; + + +/* + * If a large allocation fails, the JS engine may call the large-allocation- + * failure callback, if set, to allow the embedding to flush caches, possibly + * perform shrinking GCs, etc. to make some room so that the allocation will + * succeed if retried. After the callback returns, the JS engine will try to + * allocate again and may be succesful. + */ + +typedef void +(* LargeAllocationFailureCallback)(void *data); + +extern JS_PUBLIC_API(void) +SetLargeAllocationFailureCallback(JSRuntime *rt, LargeAllocationFailureCallback afc, void *data); + +/* + * Unlike the error reporter, which is only called if the exception for an OOM + * bubbles up and is not caught, the OutOfMemoryCallback is called immediately + * at the OOM site to allow the embedding to capture the current state of heap + * allocation before anything is freed. If the large-allocation-failure callback + * is called at all (not all allocation sites call the large-allocation-failure + * callback on failure), it is called before the out-of-memory callback; the + * out-of-memory callback is only called if the allocation still fails after the + * large-allocation-failure callback has returned. + */ + +typedef void +(* OutOfMemoryCallback)(JSContext *cx, void *data); + +extern JS_PUBLIC_API(void) +SetOutOfMemoryCallback(JSRuntime *rt, OutOfMemoryCallback cb, void *data); + + +/* + * Capture the current call stack as a chain of SavedFrame objects, and set + * |stackp| to the SavedFrame for the newest stack frame. If |maxFrameCount| is + * non-zero, capture at most the youngest |maxFrameCount| frames. + */ +extern JS_PUBLIC_API(bool) +CaptureCurrentStack(JSContext *cx, MutableHandleObject stackp, unsigned maxFrameCount = 0); + +} /* namespace JS */ + +#endif /* jsapi_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsbytecode.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsbytecode.h new file mode 100644 index 0000000000..8e4f4cf90b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsbytecode.h @@ -0,0 +1,14 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsbytecode_h +#define jsbytecode_h + +#include + +typedef uint8_t jsbytecode; + +#endif /* jsbytecode_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsclist.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsclist.h new file mode 100644 index 0000000000..23da9b8cd5 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsclist.h @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsclist_h +#define jsclist_h + +#include "jstypes.h" + +/* +** Circular linked list +*/ +typedef struct JSCListStr { + struct JSCListStr *next; + struct JSCListStr *prev; +} JSCList; + +/* +** Insert element "_e" into the list, before "_l". +*/ +#define JS_INSERT_BEFORE(_e,_l) \ + JS_BEGIN_MACRO \ + (_e)->next = (_l); \ + (_e)->prev = (_l)->prev; \ + (_l)->prev->next = (_e); \ + (_l)->prev = (_e); \ + JS_END_MACRO + +/* +** Insert element "_e" into the list, after "_l". +*/ +#define JS_INSERT_AFTER(_e,_l) \ + JS_BEGIN_MACRO \ + (_e)->next = (_l)->next; \ + (_e)->prev = (_l); \ + (_l)->next->prev = (_e); \ + (_l)->next = (_e); \ + JS_END_MACRO + +/* +** Return the element following element "_e" +*/ +#define JS_NEXT_LINK(_e) \ + ((_e)->next) +/* +** Return the element preceding element "_e" +*/ +#define JS_PREV_LINK(_e) \ + ((_e)->prev) + +/* +** Append an element "_e" to the end of the list "_l" +*/ +#define JS_APPEND_LINK(_e,_l) JS_INSERT_BEFORE(_e,_l) + +/* +** Insert an element "_e" at the head of the list "_l" +*/ +#define JS_INSERT_LINK(_e,_l) JS_INSERT_AFTER(_e,_l) + +/* Return the head/tail of the list */ +#define JS_LIST_HEAD(_l) (_l)->next +#define JS_LIST_TAIL(_l) (_l)->prev + +/* +** Remove the element "_e" from it's circular list. +*/ +#define JS_REMOVE_LINK(_e) \ + JS_BEGIN_MACRO \ + (_e)->prev->next = (_e)->next; \ + (_e)->next->prev = (_e)->prev; \ + JS_END_MACRO + +/* +** Remove the element "_e" from it's circular list. Also initializes the +** linkage. +*/ +#define JS_REMOVE_AND_INIT_LINK(_e) \ + JS_BEGIN_MACRO \ + (_e)->prev->next = (_e)->next; \ + (_e)->next->prev = (_e)->prev; \ + (_e)->next = (_e); \ + (_e)->prev = (_e); \ + JS_END_MACRO + +/* +** Return non-zero if the given circular list "_l" is empty, zero if the +** circular list is not empty +*/ +#define JS_CLIST_IS_EMPTY(_l) \ + ((_l)->next == (_l)) + +/* +** Initialize a circular list +*/ +#define JS_INIT_CLIST(_l) \ + JS_BEGIN_MACRO \ + (_l)->next = (_l); \ + (_l)->prev = (_l); \ + JS_END_MACRO + +#define JS_INIT_STATIC_CLIST(_l) \ + {(_l), (_l)} + +#endif /* jsclist_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jscpucfg.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jscpucfg.h new file mode 100644 index 0000000000..a7a00613bb --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jscpucfg.h @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jscpucfg_h +#define jscpucfg_h + +#define JS_HAVE_LONG_LONG + +#if defined(_WIN64) + +# if defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_) +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# else /* !(defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)) */ +# error "CPU type is unknown" +# endif /* !(defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)) */ + +#elif defined(_WIN32) + +# ifdef __WATCOMC__ +# define HAVE_VA_LIST_AS_ARRAY 1 +# endif + +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN + +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) +# if __LITTLE_ENDIAN__ +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# elif __BIG_ENDIAN__ +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 +# endif + +#elif defined(JS_HAVE_ENDIAN_H) +# include + +# if defined(__BYTE_ORDER) +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# elif __BYTE_ORDER == __BIG_ENDIAN +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 +# endif +# else /* !defined(__BYTE_ORDER) */ +# error "endian.h does not define __BYTE_ORDER. Cannot determine endianness." +# endif + +/* BSDs */ +#elif defined(JS_HAVE_MACHINE_ENDIAN_H) +# include +# include + +# if defined(_BYTE_ORDER) +# if _BYTE_ORDER == _LITTLE_ENDIAN +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# elif _BYTE_ORDER == _BIG_ENDIAN +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 +# endif +# else /* !defined(_BYTE_ORDER) */ +# error "machine/endian.h does not define _BYTE_ORDER. Cannot determine endianness." +# endif + +#elif defined(JS_HAVE_SYS_ISA_DEFS_H) +# include + +# if defined(_BIG_ENDIAN) +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 +# elif defined(_LITTLE_ENDIAN) +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# else /* !defined(_LITTLE_ENDIAN) */ +# error "sys/isa_defs.h does not define _BIG_ENDIAN or _LITTLE_ENDIAN. Cannot determine endianness." +# endif +# if !defined(JS_STACK_GROWTH_DIRECTION) +# if defined(_STACK_GROWS_UPWARD) +# define JS_STACK_GROWTH_DIRECTION (1) +# elif defined(_STACK_GROWS_DOWNWARD) +# define JS_STACK_GROWTH_DIRECTION (-1) +# endif +# endif + +#elif defined(__sparc) || defined(__sparc__) || \ + defined(_POWER) || defined(__hppa) || \ + defined(_MIPSEB) || defined(_BIG_ENDIAN) +/* IA64 running HP-UX will have _BIG_ENDIAN defined. + * IA64 running Linux will have endian.h and be handled above. + */ +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 + +#else /* !defined(__sparc) && !defined(__sparc__) && ... */ +# error "Cannot determine endianness of your platform. Please add support to jscpucfg.h." +#endif + +#ifndef JS_STACK_GROWTH_DIRECTION +# ifdef __hppa +# define JS_STACK_GROWTH_DIRECTION (1) +# else +# define JS_STACK_GROWTH_DIRECTION (-1) +# endif +#endif + +#endif /* jscpucfg_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsfriendapi.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsfriendapi.h new file mode 100644 index 0000000000..674999eb62 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsfriendapi.h @@ -0,0 +1,2561 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsfriendapi_h +#define jsfriendapi_h + +#include "mozilla/Casting.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/TypedEnum.h" +#include "mozilla/UniquePtr.h" + +#include "jsapi.h" // For JSAutoByteString. See bug 1033916. +#include "jsbytecode.h" +#include "jspubtd.h" + +#include "js/CallArgs.h" +#include "js/CallNonGenericMethod.h" +#include "js/Class.h" + +/* + * This macro checks if the stack pointer has exceeded a given limit. If + * |tolerance| is non-zero, it returns true only if the stack pointer has + * exceeded the limit by more than |tolerance| bytes. The WITH_INTOLERANCE + * versions use a negative tolerance (i.e., the limit is reduced by + * |intolerance| bytes). + */ +#if JS_STACK_GROWTH_DIRECTION > 0 +# define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ + ((uintptr_t)(sp) < (limit)+(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) < (limit)-(intolerance)) +#else +# define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ + ((uintptr_t)(sp) > (limit)-(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) > (limit)+(intolerance)) +#endif + +#define JS_CHECK_STACK_SIZE(limit, lval) JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, lval, 0) + +class JSAtom; +struct JSErrorFormatString; +class JSLinearString; +struct JSJitInfo; +struct JSErrorReport; + +namespace JS { +template +class Heap; +} /* namespace JS */ + +namespace js { +class JS_FRIEND_API(BaseProxyHandler); +} /* namespace js */ + +extern JS_FRIEND_API(void) +JS_SetGrayGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); + +extern JS_FRIEND_API(JSString *) +JS_GetAnonymousString(JSRuntime *rt); + +extern JS_FRIEND_API(JSObject *) +JS_FindCompilationScope(JSContext *cx, JS::HandleObject obj); + +extern JS_FRIEND_API(JSFunction *) +JS_GetObjectFunction(JSObject *obj); + +extern JS_FRIEND_API(bool) +JS_SplicePrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); + +extern JS_FRIEND_API(JSObject *) +JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JS::HandleObject proto, + JS::HandleObject parent); + +extern JS_FRIEND_API(uint32_t) +JS_ObjectCountDynamicSlots(JS::HandleObject obj); + +extern JS_FRIEND_API(size_t) +JS_SetProtoCalled(JSContext *cx); + +extern JS_FRIEND_API(size_t) +JS_GetCustomIteratorCount(JSContext *cx); + +extern JS_FRIEND_API(bool) +JS_NondeterministicGetWeakMapKeys(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject ret); + +/* + * Determine whether the given object is backed by a DeadObjectProxy. + * + * Such objects hold no other objects (they have no outgoing reference edges) + * and will throw if you touch them (e.g. by reading/writing a property). + */ +extern JS_FRIEND_API(bool) +JS_IsDeadWrapper(JSObject *obj); + +/* + * Used by the cycle collector to trace through the shape and all + * shapes it reaches, marking all non-shape children found in the + * process. Uses bounded stack space. + */ +extern JS_FRIEND_API(void) +JS_TraceShapeCycleCollectorChildren(JSTracer *trc, void *shape); + +enum { + JS_TELEMETRY_GC_REASON, + JS_TELEMETRY_GC_IS_COMPARTMENTAL, + JS_TELEMETRY_GC_MS, + JS_TELEMETRY_GC_MAX_PAUSE_MS, + JS_TELEMETRY_GC_MARK_MS, + JS_TELEMETRY_GC_SWEEP_MS, + JS_TELEMETRY_GC_MARK_ROOTS_MS, + JS_TELEMETRY_GC_MARK_GRAY_MS, + JS_TELEMETRY_GC_SLICE_MS, + JS_TELEMETRY_GC_MMU_50, + JS_TELEMETRY_GC_RESET, + JS_TELEMETRY_GC_INCREMENTAL_DISABLED, + JS_TELEMETRY_GC_NON_INCREMENTAL, + JS_TELEMETRY_GC_SCC_SWEEP_TOTAL_MS, + JS_TELEMETRY_GC_SCC_SWEEP_MAX_PAUSE_MS +}; + +typedef void +(* JSAccumulateTelemetryDataCallback)(int id, uint32_t sample); + +extern JS_FRIEND_API(void) +JS_SetAccumulateTelemetryCallback(JSRuntime *rt, JSAccumulateTelemetryDataCallback callback); + +extern JS_FRIEND_API(JSPrincipals *) +JS_GetCompartmentPrincipals(JSCompartment *compartment); + +extern JS_FRIEND_API(void) +JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals); + +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptPrincipals(JSScript *script); + +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptOriginPrincipals(JSScript *script); + +/* Safe to call with input obj == nullptr. Returns non-nullptr iff obj != nullptr. */ +extern JS_FRIEND_API(JSObject *) +JS_ObjectToInnerObject(JSContext *cx, JS::HandleObject obj); + +/* Requires obj != nullptr. */ +extern JS_FRIEND_API(JSObject *) +JS_ObjectToOuterObject(JSContext *cx, JS::HandleObject obj); + +extern JS_FRIEND_API(JSObject *) +JS_CloneObject(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto, + JS::HandleObject parent); + +extern JS_FRIEND_API(JSString *) +JS_BasicObjectToString(JSContext *cx, JS::HandleObject obj); + +extern JS_FRIEND_API(bool) +js_GetterOnlyPropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, + JS::MutableHandleValue vp); + +JS_FRIEND_API(void) +js_ReportOverRecursed(JSContext *maybecx); + +JS_FRIEND_API(bool) +js_ObjectClassIs(JSContext *cx, JS::HandleObject obj, js::ESClassValue classValue); + +JS_FRIEND_API(const char *) +js_ObjectClassName(JSContext *cx, JS::HandleObject obj); + +namespace js { + +JS_FRIEND_API(bool) +AddRawValueRoot(JSContext *cx, JS::Value *vp, const char *name); + +JS_FRIEND_API(void) +RemoveRawValueRoot(JSContext *cx, JS::Value *vp); + +} /* namespace js */ + +#ifdef JS_DEBUG + +/* + * Routines to print out values during debugging. These are FRIEND_API to help + * the debugger find them and to support temporarily hacking js_Dump* calls + * into other code. + */ + +extern JS_FRIEND_API(void) +js_DumpString(JSString *str); + +extern JS_FRIEND_API(void) +js_DumpAtom(JSAtom *atom); + +extern JS_FRIEND_API(void) +js_DumpObject(JSObject *obj); + +extern JS_FRIEND_API(void) +js_DumpChars(const jschar *s, size_t n); +#endif + +/* + * Copies all own properties from |obj| to |target|. |obj| must be a "native" + * object (that is to say, normal-ish - not an Array or a Proxy). + * + * This function immediately enters a compartment, and does not impose any + * restrictions on the compartment of |cx|. + */ +extern JS_FRIEND_API(bool) +JS_CopyPropertiesFrom(JSContext *cx, JS::HandleObject target, JS::HandleObject obj); + +/* + * Single-property version of the above. This function asserts that an |own| + * property of the given name exists on |obj|. + * + * On entry, |cx| must be same-compartment with |obj|. + */ +extern JS_FRIEND_API(bool) +JS_CopyPropertyFrom(JSContext *cx, JS::HandleId id, JS::HandleObject target, + JS::HandleObject obj); + +extern JS_FRIEND_API(bool) +JS_WrapPropertyDescriptor(JSContext *cx, JS::MutableHandle desc); + +extern JS_FRIEND_API(bool) +JS_WrapAutoIdVector(JSContext *cx, JS::AutoIdVector &props); + +extern JS_FRIEND_API(bool) +JS_EnumerateState(JSContext *cx, JS::HandleObject obj, JSIterateOp enum_op, + JS::MutableHandleValue statep, JS::MutableHandleId idp); + +struct JSFunctionSpecWithHelp { + const char *name; + JSNative call; + uint16_t nargs; + uint16_t flags; + const char *usage; + const char *help; +}; + +#define JS_FN_HELP(name,call,nargs,flags,usage,help) \ + {name, call, nargs, (flags) | JSPROP_ENUMERATE | JSFUN_STUB_GSOPS, usage, help} +#define JS_FS_HELP_END \ + {nullptr, nullptr, 0, 0, nullptr, nullptr} + +extern JS_FRIEND_API(bool) +JS_DefineFunctionsWithHelp(JSContext *cx, JS::HandleObject obj, const JSFunctionSpecWithHelp *fs); + +namespace js { + +/* + * Helper Macros for creating JSClasses that function as proxies. + * + * NB: The macro invocation must be surrounded by braces, so as to + * allow for potention JSClass extensions. + */ +#define PROXY_MAKE_EXT(outerObject, innerObject, iteratorObject, \ + isWrappedNative) \ + { \ + outerObject, \ + innerObject, \ + iteratorObject, \ + isWrappedNative, \ + js::proxy_WeakmapKeyDelegate \ + } + +#define PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, ext) \ + { \ + name, \ + js::Class::NON_NATIVE | \ + JSCLASS_IS_PROXY | \ + JSCLASS_IMPLEMENTS_BARRIERS | \ + JSCLASS_HAS_RESERVED_SLOTS(js::PROXY_MINIMUM_SLOTS + (extraSlots)) | \ + flags, \ + JS_PropertyStub, /* addProperty */ \ + JS_DeletePropertyStub, /* delProperty */ \ + JS_PropertyStub, /* getProperty */ \ + JS_StrictPropertyStub, /* setProperty */ \ + JS_EnumerateStub, \ + JS_ResolveStub, \ + js::proxy_Convert, \ + js::proxy_Finalize, /* finalize */ \ + callOp, /* call */ \ + js::proxy_HasInstance, /* hasInstance */ \ + constructOp, /* construct */ \ + js::proxy_Trace, /* trace */ \ + JS_NULL_CLASS_SPEC, \ + ext, \ + { \ + js::proxy_LookupGeneric, \ + js::proxy_LookupProperty, \ + js::proxy_LookupElement, \ + js::proxy_DefineGeneric, \ + js::proxy_DefineProperty, \ + js::proxy_DefineElement, \ + js::proxy_GetGeneric, \ + js::proxy_GetProperty, \ + js::proxy_GetElement, \ + js::proxy_SetGeneric, \ + js::proxy_SetProperty, \ + js::proxy_SetElement, \ + js::proxy_GetGenericAttributes, \ + js::proxy_SetGenericAttributes, \ + js::proxy_DeleteGeneric, \ + js::proxy_Watch, js::proxy_Unwatch, \ + js::proxy_Slice, \ + nullptr, /* enumerate */ \ + nullptr, /* thisObject */ \ + } \ + } + +#define PROXY_CLASS_DEF(name, extraSlots, flags, callOp, constructOp) \ + PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, \ + PROXY_MAKE_EXT( \ + nullptr, /* outerObject */ \ + nullptr, /* innerObject */ \ + nullptr, /* iteratorObject */ \ + false /* isWrappedNative */ \ + )) + +/* + * Proxy stubs, similar to JS_*Stub, for embedder proxy class definitions. + * + * NB: Should not be called directly. + */ + +extern JS_FRIEND_API(bool) +proxy_LookupGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleObject objp, JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_DefineGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, + unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_GetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetProperty(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, + JS::Handle name, JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetElement(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_SetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp, + bool strict); +extern JS_FRIEND_API(bool) +proxy_GetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_SetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_DeleteGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); + +extern JS_FRIEND_API(void) +proxy_Trace(JSTracer *trc, JSObject *obj); +extern JS_FRIEND_API(JSObject *) +proxy_WeakmapKeyDelegate(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Convert(JSContext *cx, JS::HandleObject proxy, JSType hint, JS::MutableHandleValue vp); +extern JS_FRIEND_API(void) +proxy_Finalize(FreeOp *fop, JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_HasInstance(JSContext *cx, JS::HandleObject proxy, JS::MutableHandleValue v, bool *bp); +extern JS_FRIEND_API(bool) +proxy_Call(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(bool) +proxy_Construct(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(JSObject *) +proxy_innerObject(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Watch(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); +extern JS_FRIEND_API(bool) +proxy_Unwatch(JSContext *cx, JS::HandleObject obj, JS::HandleId id); +extern JS_FRIEND_API(bool) +proxy_Slice(JSContext *cx, JS::HandleObject proxy, uint32_t begin, uint32_t end, + JS::HandleObject result); + +/* + * A class of objects that return source code on demand. + * + * When code is compiled with setSourceIsLazy(true), SpiderMonkey doesn't + * retain the source code (and doesn't do lazy bytecode generation). If we ever + * need the source code, say, in response to a call to Function.prototype. + * toSource or Debugger.Source.prototype.text, then we call the 'load' member + * function of the instance of this class that has hopefully been registered + * with the runtime, passing the code's URL, and hope that it will be able to + * find the source. + */ +class SourceHook { + public: + virtual ~SourceHook() { } + + /* + * Set |*src| and |*length| to refer to the source code for |filename|. + * On success, the caller owns the buffer to which |*src| points, and + * should use JS_free to free it. + */ + virtual bool load(JSContext *cx, const char *filename, jschar **src, size_t *length) = 0; +}; + +/* + * Have |rt| use |hook| to retrieve lazily-retrieved source code. See the + * comments for SourceHook. The runtime takes ownership of the hook, and + * will delete it when the runtime itself is deleted, or when a new hook is + * set. + */ +extern JS_FRIEND_API(void) +SetSourceHook(JSRuntime *rt, mozilla::UniquePtr hook); + +/* Remove |rt|'s source hook, and return it. The caller now owns the hook. */ +extern JS_FRIEND_API(mozilla::UniquePtr) +ForgetSourceHook(JSRuntime *rt); + +#ifdef NIGHTLY_BUILD +typedef void (*AssertOnScriptEntryHook)(JSContext *cx, JS::HandleScript script); + +extern JS_FRIEND_API(void) +SetAssertOnScriptEntryHook(JSRuntime *rt, AssertOnScriptEntryHook hook); +#endif + +extern JS_FRIEND_API(JS::Zone *) +GetCompartmentZone(JSCompartment *comp); + +typedef bool +(* PreserveWrapperCallback)(JSContext *cx, JSObject *obj); + +typedef enum { + CollectNurseryBeforeDump, + IgnoreNurseryObjects +} DumpHeapNurseryBehaviour; + + /* + * Dump the complete object graph of heap-allocated things. + * fp is the file for the dump output. + */ +extern JS_FRIEND_API(void) +DumpHeapComplete(JSRuntime *rt, FILE *fp, DumpHeapNurseryBehaviour nurseryBehaviour); + +#ifdef JS_OLD_GETTER_SETTER_METHODS +JS_FRIEND_API(bool) obj_defineGetter(JSContext *cx, unsigned argc, JS::Value *vp); +JS_FRIEND_API(bool) obj_defineSetter(JSContext *cx, unsigned argc, JS::Value *vp); +#endif + +extern JS_FRIEND_API(bool) +IsSystemCompartment(JSCompartment *comp); + +extern JS_FRIEND_API(bool) +IsSystemZone(JS::Zone *zone); + +extern JS_FRIEND_API(bool) +IsAtomsCompartment(JSCompartment *comp); + +/* + * Returns whether we're in a non-strict property set (in that we're in a + * non-strict script and the bytecode we're on is a property set). The return + * value does NOT indicate any sort of exception was thrown: it's just a + * boolean. + */ +extern JS_FRIEND_API(bool) +IsInNonStrictPropertySet(JSContext *cx); + +struct WeakMapTracer; + +/* + * Weak map tracer callback, called once for every binding of every + * weak map that was live at the time of the last garbage collection. + * + * m will be nullptr if the weak map is not contained in a JS Object. + */ +typedef void +(* WeakMapTraceCallback)(WeakMapTracer *trc, JSObject *m, + void *k, JSGCTraceKind kkind, + void *v, JSGCTraceKind vkind); + +struct WeakMapTracer { + JSRuntime *runtime; + WeakMapTraceCallback callback; + + WeakMapTracer(JSRuntime *rt, WeakMapTraceCallback cb) + : runtime(rt), callback(cb) {} +}; + +extern JS_FRIEND_API(void) +TraceWeakMaps(WeakMapTracer *trc); + +extern JS_FRIEND_API(bool) +AreGCGrayBitsValid(JSRuntime *rt); + +extern JS_FRIEND_API(bool) +ZoneGlobalsAreAllGray(JS::Zone *zone); + +typedef void +(*GCThingCallback)(void *closure, void *gcthing); + +extern JS_FRIEND_API(void) +VisitGrayWrapperTargets(JS::Zone *zone, GCThingCallback callback, void *closure); + +extern JS_FRIEND_API(JSObject *) +GetWeakmapKeyDelegate(JSObject *key); + +JS_FRIEND_API(JSGCTraceKind) +GCThingTraceKind(void *thing); + +/* + * Invoke cellCallback on every gray JS_OBJECT in the given zone. + */ +extern JS_FRIEND_API(void) +IterateGrayObjects(JS::Zone *zone, GCThingCallback cellCallback, void *data); + +#ifdef JS_HAS_CTYPES +extern JS_FRIEND_API(size_t) +SizeOfDataIfCDataObject(mozilla::MallocSizeOf mallocSizeOf, JSObject *obj); +#endif + +extern JS_FRIEND_API(JSCompartment *) +GetAnyCompartmentInZone(JS::Zone *zone); + +/* + * Shadow declarations of JS internal structures, for access by inline access + * functions below. Do not use these structures in any other way. When adding + * new fields for access by inline methods, make sure to add static asserts to + * the original header file to ensure that offsets are consistent. + */ +namespace shadow { + +struct TypeObject { + const Class *clasp; + JSObject *proto; +}; + +struct BaseShape { + const js::Class *clasp_; + JSObject *parent; + JSObject *_1; + JSCompartment *compartment; +}; + +class Shape { +public: + shadow::BaseShape *base; + jsid _1; + uint32_t slotInfo; + + static const uint32_t FIXED_SLOTS_SHIFT = 27; +}; + +struct Object { + shadow::Shape *shape; + shadow::TypeObject *type; + JS::Value *slots; + JS::Value *_1; + + size_t numFixedSlots() const { return shape->slotInfo >> Shape::FIXED_SLOTS_SHIFT; } + JS::Value *fixedSlots() const { + return (JS::Value *)(uintptr_t(this) + sizeof(shadow::Object)); + } + + JS::Value &slotRef(size_t slot) const { + size_t nfixed = numFixedSlots(); + if (slot < nfixed) + return fixedSlots()[slot]; + return slots[slot - nfixed]; + } + + // Reserved slots with index < MAX_FIXED_SLOTS are guaranteed to + // be fixed slots. + static const uint32_t MAX_FIXED_SLOTS = 16; +}; + +struct Function { + Object base; + uint16_t nargs; + uint16_t flags; + /* Used only for natives */ + JSNative native; + const JSJitInfo *jitinfo; + void *_1; +}; + +struct String +{ + static const uint32_t INLINE_CHARS_BIT = JS_BIT(2); + static const uint32_t LATIN1_CHARS_BIT = JS_BIT(6); + static const uint32_t ROPE_FLAGS = 0; + static const uint32_t TYPE_FLAGS_MASK = JS_BIT(6) - 1; + uint32_t flags; + uint32_t length; + union { + const JS::Latin1Char *nonInlineCharsLatin1; + const jschar *nonInlineCharsTwoByte; + JS::Latin1Char inlineStorageLatin1[1]; + jschar inlineStorageTwoByte[1]; + }; +}; + +} /* namespace shadow */ + +// This is equal to |&JSObject::class_|. Use it in places where you don't want +// to #include jsobj.h. +extern JS_FRIEND_DATA(const js::Class* const) ObjectClassPtr; + +inline const js::Class * +GetObjectClass(JSObject *obj) +{ + return reinterpret_cast(obj)->type->clasp; +} + +inline const JSClass * +GetObjectJSClass(JSObject *obj) +{ + return js::Jsvalify(GetObjectClass(obj)); +} + +JS_FRIEND_API(const Class *) +ProtoKeyToClass(JSProtoKey key); + +// Returns true if the standard class identified by |key| inherits from +// another standard class with the same js::Class. This basically means +// that the various properties described by our js::Class are intended +// to live higher up on the proto chain. +// +// In practice, this only returns true for Error subtypes. +inline bool +StandardClassIsDependent(JSProtoKey key) +{ + JSProtoKey keyFromClass = JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + MOZ_ASSERT(keyFromClass); + return key != keyFromClass; +} + +// Returns the key for the class inherited by a given standard class (that +// is to say, the prototype of this standard class's prototype). +// +// You must be sure that this corresponds to a standard class with a cached +// JSProtoKey before calling this function. In general |key| will match the +// cached proto key, except in cases where multiple JSProtoKeys share a +// JSClass. +inline JSProtoKey +ParentKeyForStandardClass(JSProtoKey key) +{ + // [Object] has nothing to inherit from. + if (key == JSProto_Object) + return JSProto_Null; + + // If we're dependent (i.e. an Error subtype), return the key of the class + // we depend on. + if (StandardClassIsDependent(key)) + return JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + + // Otherwise, we inherit [Object]. + return JSProto_Object; +} + +inline bool +IsInnerObject(JSObject *obj) { + return !!GetObjectClass(obj)->ext.outerObject; +} + +inline bool +IsOuterObject(JSObject *obj) { + return !!GetObjectClass(obj)->ext.innerObject; +} + +JS_FRIEND_API(bool) +IsFunctionObject(JSObject *obj); + +JS_FRIEND_API(bool) +IsScopeObject(JSObject *obj); + +JS_FRIEND_API(bool) +IsCallObject(JSObject *obj); + +inline JSObject * +GetObjectParent(JSObject *obj) +{ + JS_ASSERT(!IsScopeObject(obj)); + return reinterpret_cast(obj)->shape->base->parent; +} + +static MOZ_ALWAYS_INLINE JSCompartment * +GetObjectCompartment(JSObject *obj) +{ + return reinterpret_cast(obj)->shape->base->compartment; +} + +JS_FRIEND_API(JSObject *) +GetObjectParentMaybeScope(JSObject *obj); + +JS_FRIEND_API(JSObject *) +GetGlobalForObjectCrossCompartment(JSObject *obj); + +// Sidestep the activeContext checking implicitly performed in +// JS_SetPendingException. +JS_FRIEND_API(void) +SetPendingExceptionCrossContext(JSContext *cx, JS::HandleValue v); + +JS_FRIEND_API(void) +AssertSameCompartment(JSContext *cx, JSObject *obj); + +#ifdef JS_DEBUG +JS_FRIEND_API(void) +AssertSameCompartment(JSObject *objA, JSObject *objB); +#else +inline void AssertSameCompartment(JSObject *objA, JSObject *objB) {} +#endif + +// For legacy consumers only. This whole concept is going away soon. +JS_FRIEND_API(JSObject *) +DefaultObjectForContextOrNull(JSContext *cx); + +JS_FRIEND_API(void) +SetDefaultObjectForContext(JSContext *cx, JSObject *obj); + +JS_FRIEND_API(void) +NotifyAnimationActivity(JSObject *obj); + +/* + * Return the outermost enclosing function (script) of the scripted caller. + * This function returns nullptr in several cases: + * - no script is running on the context + * - the caller is in global or eval code + * In particular, this function will "stop" its outermost search at eval() and + * thus it will really return the outermost enclosing function *since the + * innermost eval*. + */ +JS_FRIEND_API(JSFunction *) +GetOutermostEnclosingFunctionOfScriptedCaller(JSContext *cx); + +JS_FRIEND_API(JSFunction *) +DefineFunctionWithReserved(JSContext *cx, JSObject *obj, const char *name, JSNative call, + unsigned nargs, unsigned attrs); + +JS_FRIEND_API(JSFunction *) +NewFunctionWithReserved(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, + JSObject *parent, const char *name); + +JS_FRIEND_API(JSFunction *) +NewFunctionByIdWithReserved(JSContext *cx, JSNative native, unsigned nargs, unsigned flags, + JSObject *parent, jsid id); + +JS_FRIEND_API(const JS::Value &) +GetFunctionNativeReserved(JSObject *fun, size_t which); + +JS_FRIEND_API(void) +SetFunctionNativeReserved(JSObject *fun, size_t which, const JS::Value &val); + +JS_FRIEND_API(bool) +GetObjectProto(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject proto); + +JS_FRIEND_API(bool) +GetOriginalEval(JSContext *cx, JS::HandleObject scope, + JS::MutableHandleObject eval); + +inline void * +GetObjectPrivate(JSObject *obj) +{ + const shadow::Object *nobj = reinterpret_cast(obj); + void **addr = reinterpret_cast(&nobj->fixedSlots()[nobj->numFixedSlots()]); + return *addr; +} + +/* + * Get a slot that is both reserved for object's clasp *and* is fixed (fits + * within the maximum capacity for the object's fixed slots). + */ +inline const JS::Value & +GetReservedSlot(JSObject *obj, size_t slot) +{ + JS_ASSERT(slot < JSCLASS_RESERVED_SLOTS(GetObjectClass(obj))); + return reinterpret_cast(obj)->slotRef(slot); +} + +JS_FRIEND_API(void) +SetReservedSlotWithBarrier(JSObject *obj, size_t slot, const JS::Value &value); + +inline void +SetReservedSlot(JSObject *obj, size_t slot, const JS::Value &value) +{ + JS_ASSERT(slot < JSCLASS_RESERVED_SLOTS(GetObjectClass(obj))); + shadow::Object *sobj = reinterpret_cast(obj); + if (sobj->slotRef(slot).isMarkable() +#ifdef JSGC_GENERATIONAL + || value.isMarkable() +#endif + ) + { + SetReservedSlotWithBarrier(obj, slot, value); + } else { + sobj->slotRef(slot) = value; + } +} + +JS_FRIEND_API(uint32_t) +GetObjectSlotSpan(JSObject *obj); + +inline const JS::Value & +GetObjectSlot(JSObject *obj, size_t slot) +{ + JS_ASSERT(slot < GetObjectSlotSpan(obj)); + return reinterpret_cast(obj)->slotRef(slot); +} + +MOZ_ALWAYS_INLINE size_t +GetAtomLength(JSAtom *atom) +{ + return reinterpret_cast(atom)->length; +} + +static const uint32_t MaxStringLength = (1 << 28) - 1; + +MOZ_ALWAYS_INLINE size_t +GetStringLength(JSString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetFlatStringLength(JSFlatString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetLinearStringLength(JSLinearString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE bool +LinearStringHasLatin1Chars(JSLinearString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE bool +AtomHasLatin1Chars(JSAtom *atom) +{ + return reinterpret_cast(atom)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE bool +StringHasLatin1Chars(JSString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1LinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageLatin1; + return s->nonInlineCharsLatin1; +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteLinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(!LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageTwoByte; + return s->nonInlineCharsTwoByte; +} + +MOZ_ALWAYS_INLINE JSLinearString * +AtomToLinearString(JSAtom *atom) +{ + return reinterpret_cast(atom); +} + +MOZ_ALWAYS_INLINE JSLinearString * +FlatStringToLinearString(JSFlatString *s) +{ + return reinterpret_cast(s); +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1AtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetLatin1LinearStringChars(nogc, AtomToLinearString(atom)); +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteAtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetTwoByteLinearStringChars(nogc, AtomToLinearString(atom)); +} + +JS_FRIEND_API(JSLinearString *) +StringToLinearStringSlow(JSContext *cx, JSString *str); + +MOZ_ALWAYS_INLINE JSLinearString * +StringToLinearString(JSContext *cx, JSString *str) +{ + using shadow::String; + String *s = reinterpret_cast(str); + if (MOZ_UNLIKELY((s->flags & String::TYPE_FLAGS_MASK) == String::ROPE_FLAGS)) + return StringToLinearStringSlow(cx, str); + return reinterpret_cast(str); +} + +MOZ_ALWAYS_INLINE void +CopyLinearStringChars(jschar *dest, JSLinearString *s, size_t len) +{ + JS::AutoCheckCannotGC nogc; + if (LinearStringHasLatin1Chars(s)) { + const JS::Latin1Char *src = GetLatin1LinearStringChars(nogc, s); + for (size_t i = 0; i < len; i++) + dest[i] = src[i]; + } else { + const jschar *src = GetTwoByteLinearStringChars(nogc, s); + mozilla::PodCopy(dest, src, len); + } +} + +inline bool +CopyStringChars(JSContext *cx, jschar *dest, JSString *s, size_t len) +{ + JSLinearString *linear = StringToLinearString(cx, s); + if (!linear) + return false; + + CopyLinearStringChars(dest, linear, len); + return true; +} + +inline void +CopyFlatStringChars(jschar *dest, JSFlatString *s, size_t len) +{ + CopyLinearStringChars(dest, FlatStringToLinearString(s), len); +} + +JS_FRIEND_API(bool) +GetPropertyNames(JSContext *cx, JSObject *obj, unsigned flags, JS::AutoIdVector *props); + +JS_FRIEND_API(bool) +AppendUnique(JSContext *cx, JS::AutoIdVector &base, JS::AutoIdVector &others); + +JS_FRIEND_API(bool) +GetGeneric(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id, JS::Value *vp); + +JS_FRIEND_API(bool) +StringIsArrayIndex(JSLinearString *str, uint32_t *indexp); + +JS_FRIEND_API(void) +SetPreserveWrapperCallback(JSRuntime *rt, PreserveWrapperCallback callback); + +JS_FRIEND_API(bool) +IsObjectInContextCompartment(JSObject *obj, const JSContext *cx); + +/* + * NB: these flag bits are encoded into the bytecode stream in the immediate + * operand of JSOP_ITER, so don't change them without advancing vm/Xdr.h's + * XDR_BYTECODE_VERSION. + */ +#define JSITER_ENUMERATE 0x1 /* for-in compatible hidden default iterator */ +#define JSITER_FOREACH 0x2 /* get obj[key] for each property */ +#define JSITER_KEYVALUE 0x4 /* obsolete destructuring for-in wants [key, value] */ +#define JSITER_OWNONLY 0x8 /* iterate over obj's own properties only */ +#define JSITER_HIDDEN 0x10 /* also enumerate non-enumerable properties */ +#define JSITER_SYMBOLS 0x20 /* also include symbol property keys */ +#define JSITER_SYMBOLSONLY 0x40 /* exclude string property keys */ + +JS_FRIEND_API(bool) +RunningWithTrustedPrincipals(JSContext *cx); + +inline uintptr_t +GetNativeStackLimit(JSContext *cx) +{ + StackKind kind = RunningWithTrustedPrincipals(cx) ? StackForTrustedScript + : StackForUntrustedScript; + PerThreadDataFriendFields *mainThread = + PerThreadDataFriendFields::getMainThread(GetRuntime(cx)); + return mainThread->nativeStackLimit[kind]; +} + +/* + * These macros report a stack overflow and run |onerror| if we are close to + * using up the C stack. The JS_CHECK_CHROME_RECURSION variant gives us a little + * extra space so that we can ensure that crucial code is able to run. + * JS_CHECK_RECURSION_CONSERVATIVE gives us a little less space. + */ + +#define JS_CHECK_RECURSION(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), &stackDummy_)) { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_RECURSION_DONT_REPORT(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), &stackDummy_)) { \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_RECURSION_WITH_SP_DONT_REPORT(cx, sp, onerror) \ + JS_BEGIN_MACRO \ + if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), sp)) { \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_RECURSION_WITH_SP(cx, sp, onerror) \ + JS_BEGIN_MACRO \ + if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), sp)) { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_CHROME_RECURSION(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE_WITH_TOLERANCE(js::GetNativeStackLimit(cx), \ + &stackDummy_, \ + 1024 * sizeof(size_t))) \ + { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_RECURSION_CONSERVATIVE(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(js::GetNativeStackLimit(cx), \ + &stackDummy_, \ + 1024 * sizeof(size_t))) \ + { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + +JS_FRIEND_API(void) +StartPCCountProfiling(JSContext *cx); + +JS_FRIEND_API(void) +StopPCCountProfiling(JSContext *cx); + +JS_FRIEND_API(void) +PurgePCCounts(JSContext *cx); + +JS_FRIEND_API(size_t) +GetPCCountScriptCount(JSContext *cx); + +JS_FRIEND_API(JSString *) +GetPCCountScriptSummary(JSContext *cx, size_t script); + +JS_FRIEND_API(JSString *) +GetPCCountScriptContents(JSContext *cx, size_t script); + +#ifdef JS_THREADSAFE +JS_FRIEND_API(bool) +ContextHasOutstandingRequests(const JSContext *cx); +#endif + +typedef void +(* ActivityCallback)(void *arg, bool active); + +/* + * Sets a callback that is run whenever the runtime goes idle - the + * last active request ceases - and begins activity - when it was + * idle and a request begins. + */ +JS_FRIEND_API(void) +SetActivityCallback(JSRuntime *rt, ActivityCallback cb, void *arg); + +extern JS_FRIEND_API(const JSStructuredCloneCallbacks *) +GetContextStructuredCloneCallbacks(JSContext *cx); + +extern JS_FRIEND_API(bool) +IsContextRunningJS(JSContext *cx); + +typedef bool +(* DOMInstanceClassHasProtoAtDepth)(const Class *instanceClass, + uint32_t protoID, uint32_t depth); +struct JSDOMCallbacks { + DOMInstanceClassHasProtoAtDepth instanceClassMatchesProto; +}; +typedef struct JSDOMCallbacks DOMCallbacks; + +extern JS_FRIEND_API(void) +SetDOMCallbacks(JSRuntime *rt, const DOMCallbacks *callbacks); + +extern JS_FRIEND_API(const DOMCallbacks *) +GetDOMCallbacks(JSRuntime *rt); + +extern JS_FRIEND_API(JSObject *) +GetTestingFunctions(JSContext *cx); + +/* + * Helper to convert FreeOp to JSFreeOp when the definition of FreeOp is not + * available and the compiler does not know that FreeOp inherits from + * JSFreeOp. + */ +inline JSFreeOp * +CastToJSFreeOp(FreeOp *fop) +{ + return reinterpret_cast(fop); +} + +/* Implemented in jsexn.cpp. */ + +/* + * Get an error type name from a JSExnType constant. + * Returns nullptr for invalid arguments and JSEXN_INTERNALERR + */ +extern JS_FRIEND_API(JSFlatString *) +GetErrorTypeName(JSRuntime *rt, int16_t exnType); + +#ifdef JS_DEBUG +extern JS_FRIEND_API(unsigned) +GetEnterCompartmentDepth(JSContext* cx); +#endif + +/* Implemented in jswrapper.cpp. */ +typedef enum NukeReferencesToWindow { + NukeWindowReferences, + DontNukeWindowReferences +} NukeReferencesToWindow; + +/* + * These filters are designed to be ephemeral stack classes, and thus don't + * do any rooting or holding of their members. + */ +struct CompartmentFilter { + virtual bool match(JSCompartment *c) const = 0; +}; + +struct AllCompartments : public CompartmentFilter { + virtual bool match(JSCompartment *c) const { return true; } +}; + +struct ContentCompartmentsOnly : public CompartmentFilter { + virtual bool match(JSCompartment *c) const { + return !IsSystemCompartment(c); + } +}; + +struct ChromeCompartmentsOnly : public CompartmentFilter { + virtual bool match(JSCompartment *c) const { + return IsSystemCompartment(c); + } +}; + +struct SingleCompartment : public CompartmentFilter { + JSCompartment *ours; + explicit SingleCompartment(JSCompartment *c) : ours(c) {} + virtual bool match(JSCompartment *c) const { return c == ours; } +}; + +struct CompartmentsWithPrincipals : public CompartmentFilter { + JSPrincipals *principals; + explicit CompartmentsWithPrincipals(JSPrincipals *p) : principals(p) {} + virtual bool match(JSCompartment *c) const { + return JS_GetCompartmentPrincipals(c) == principals; + } +}; + +extern JS_FRIEND_API(bool) +NukeCrossCompartmentWrappers(JSContext* cx, + const CompartmentFilter& sourceFilter, + const CompartmentFilter& targetFilter, + NukeReferencesToWindow nukeReferencesToWindow); + +/* Specify information about DOMProxy proxies in the DOM, for use by ICs. */ + +/* + * The DOMProxyShadowsCheck function will be called to check if the property for + * id should be gotten from the prototype, or if there is an own property that + * shadows it. + * If DoesntShadow is returned then the slot at listBaseExpandoSlot should + * either be undefined or point to an expando object that would contain the own + * property. + * If DoesntShadowUnique is returned then the slot at listBaseExpandoSlot should + * contain a private pointer to a ExpandoAndGeneration, which contains a + * JS::Value that should either be undefined or point to an expando object, and + * a uint32 value. If that value changes then the IC for getting a property will + * be invalidated. + */ + +struct ExpandoAndGeneration { + ExpandoAndGeneration() + : expando(JS::UndefinedValue()), + generation(0) + {} + + void Unlink() + { + ++generation; + expando.setUndefined(); + } + + static size_t offsetOfExpando() + { + return offsetof(ExpandoAndGeneration, expando); + } + + static size_t offsetOfGeneration() + { + return offsetof(ExpandoAndGeneration, generation); + } + + JS::Heap expando; + uint32_t generation; +}; + +typedef enum DOMProxyShadowsResult { + ShadowCheckFailed, + Shadows, + DoesntShadow, + DoesntShadowUnique +} DOMProxyShadowsResult; +typedef DOMProxyShadowsResult +(* DOMProxyShadowsCheck)(JSContext* cx, JS::HandleObject object, JS::HandleId id); +JS_FRIEND_API(void) +SetDOMProxyInformation(const void *domProxyHandlerFamily, uint32_t domProxyExpandoSlot, + DOMProxyShadowsCheck domProxyShadowsCheck); + +const void *GetDOMProxyHandlerFamily(); +uint32_t GetDOMProxyExpandoSlot(); +DOMProxyShadowsCheck GetDOMProxyShadowsCheck(); + +} /* namespace js */ + +/* Implemented in jsdate.cpp. */ + +/* + * Detect whether the internal date value is NaN. (Because failure is + * out-of-band for js_DateGet*) + */ +extern JS_FRIEND_API(bool) +js_DateIsValid(JSObject* obj); + +extern JS_FRIEND_API(double) +js_DateGetMsecSinceEpoch(JSObject *obj); + +/* Implemented in jscntxt.cpp. */ + +/* + * Report an exception, which is currently realized as a printf-style format + * string and its arguments. + */ +typedef enum JSErrNum { +#define MSG_DEF(name, number, count, exception, format) \ + name = number, +#include "js.msg" +#undef MSG_DEF + JSErr_Limit +} JSErrNum; + +extern JS_FRIEND_API(const JSErrorFormatString *) +js_GetErrorMessage(void *userRef, const unsigned errorNumber); + +namespace js { + +// AutoStableStringChars is here so we can use it in ErrorReport. It +// should get moved out of here if we can manage it. See bug 1040316. + +/* + * This class provides safe access to a string's chars across a GC. Once + * we allocate strings and chars in the nursery (bug 903519), this class + * will have to make a copy of the string's chars if they are allocated + * in the nursery, so it's best to avoid using this class unless you really + * need it. It's usually more efficient to use the latin1Chars/twoByteChars + * JSString methods and often the code can be rewritten so that only indexes + * instead of char pointers are used in parts of the code that can GC. + */ +class MOZ_STACK_CLASS AutoStableStringChars +{ + /* Ensure the string is kept alive while we're using its chars. */ + JS::RootedString s_; + union { + const jschar *twoByteChars_; + const JS::Latin1Char *latin1Chars_; + }; + enum State { Uninitialized, Latin1, TwoByte }; + State state_; + bool ownsChars_; + + public: + AutoStableStringChars(JSContext *cx) + : s_(cx), state_(Uninitialized), ownsChars_(false) + {}; + ~AutoStableStringChars(); + + bool init(JSContext *cx, JSString *s); + + /* Like init(), but Latin1 chars are inflated to TwoByte. */ + bool initTwoByte(JSContext *cx, JSString *s); + + bool isLatin1() const { return state_ == Latin1; } + bool isTwoByte() const { return state_ == TwoByte; } + + const jschar *twoByteChars() const { + MOZ_ASSERT(state_ == TwoByte); + return twoByteChars_; + } + + mozilla::Range latin1Range() const { + MOZ_ASSERT(state_ == Latin1); + return mozilla::Range(latin1Chars_, + GetStringLength(s_)); + } + + mozilla::Range twoByteRange() const { + MOZ_ASSERT(state_ == TwoByte); + return mozilla::Range(twoByteChars_, + GetStringLength(s_)); + } + + /* If we own the chars, transfer ownership to the caller. */ + bool maybeGiveOwnershipToCaller() { + MOZ_ASSERT(state_ != Uninitialized); + if (!ownsChars_) + return false; + state_ = Uninitialized; + ownsChars_ = false; + return true; + } + + private: + AutoStableStringChars(const AutoStableStringChars &other) MOZ_DELETE; + void operator=(const AutoStableStringChars &other) MOZ_DELETE; +}; + +// Creates a string of the form |ErrorType: ErrorMessage| for a JSErrorReport, +// which generally matches the toString() behavior of an ErrorObject. +extern JS_FRIEND_API(JSString *) +ErrorReportToString(JSContext *cx, JSErrorReport *reportp); + +struct MOZ_STACK_CLASS JS_FRIEND_API(ErrorReport) +{ + ErrorReport(JSContext *cx); + ~ErrorReport(); + + bool init(JSContext *cx, JS::HandleValue exn); + + JSErrorReport *report() + { + return reportp; + } + + const char *message() + { + return message_; + } + + private: + // More or less an equivalent of JS_ReportErrorNumber/js_ReportErrorNumberVA + // but fills in an ErrorReport instead of reporting it. Uses varargs to + // make it simpler to call js_ExpandErrorArguments. + void populateUncaughtExceptionReport(JSContext *cx, ...); + void populateUncaughtExceptionReportVA(JSContext *cx, va_list ap); + + // We may have a provided JSErrorReport, so need a way to represent that. + JSErrorReport *reportp; + + // And we may have a message. + const char *message_; + + // Or we may need to synthesize a JSErrorReport one of our own. + JSErrorReport ownedReport; + + // Or a message of our own. If this is non-null, we need to clean up both + // it and ownedReport. + char *ownedMessage; + + // And we have a string to maybe keep alive that has pointers into + // it from ownedReport. + JS::RootedString str; + + // And keep its chars alive too. + AutoStableStringChars strChars; + + // And we need to root our exception value. + JS::RootedObject exnObject; + + // And possibly some byte storage for our message_. + JSAutoByteString bytesStorage; + + // And for our filename. + JSAutoByteString filename; + + // True if we need to free message_ and the stuff in ownedReport + bool ownsMessageAndReport; +}; + +} /* namespace js */ + + +/* Implemented in jsclone.cpp. */ + +extern JS_FRIEND_API(uint64_t) +js_GetSCOffset(JSStructuredCloneWriter* writer); + +namespace js { +namespace Scalar { + +/* Scalar types which can appear in typed arrays and typed objects. */ +enum Type { + Int8 = 0, + Uint8, + Int16, + Uint16, + Int32, + Uint32, + Float32, + Float64, + + /* + * Special type that is a uint8_t, but assignments are clamped to [0, 256). + * Treat the raw data type as a uint8_t. + */ + Uint8Clamped, + + TypeMax +}; + +static inline size_t +byteSize(Type atype) +{ + switch (atype) { + case Int8: + case Uint8: + case Uint8Clamped: + return 1; + case Int16: + case Uint16: + return 2; + case Int32: + case Uint32: + case Float32: + return 4; + case Float64: + return 8; + default: + MOZ_CRASH("invalid scalar type"); + } +} + +} /* namespace Scalar */ +} /* namespace js */ + +/* + * Create a new typed array with nelements elements. + * + * These functions (except the WithBuffer variants) fill in the array with zeros. + */ + +extern JS_FRIEND_API(JSObject *) +JS_NewInt8Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ClampedArray(JSContext *cx, uint32_t nelements); + +extern JS_FRIEND_API(JSObject *) +JS_NewInt16Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewUint16Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewInt32Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewUint32Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat32Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat64Array(JSContext *cx, uint32_t nelements); + +/* + * Create a new typed array and copy in values from the given object. The + * object is used as if it were an array; that is, the new array (if + * successfully created) will have length given by array.length, and its + * elements will be those specified by array[0], array[1], and so on, after + * conversion to the typed array element type. + */ + +extern JS_FRIEND_API(JSObject *) +JS_NewInt8ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ClampedArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewInt16ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewUint16ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewInt32ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewUint32ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat32ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat64ArrayFromArray(JSContext *cx, JS::HandleObject array); + +/* + * Create a new typed array using the given ArrayBuffer for storage. The + * length value is optional; if -1 is passed, enough elements to use up the + * remainder of the byte array is used as the default value. + */ + +extern JS_FRIEND_API(JSObject *) +JS_NewInt8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewInt16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewUint16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewInt32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewUint32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat64ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); + +/* + * Create a new ArrayBuffer with the given byte length. + */ +extern JS_FRIEND_API(JSObject *) +JS_NewArrayBuffer(JSContext *cx, uint32_t nbytes); + +/* + * Check whether obj supports JS_GetTypedArray* APIs. Note that this may return + * false if a security wrapper is encountered that denies the unwrapping. If + * this test or one of the JS_Is*Array tests succeeds, then it is safe to call + * the various accessor JSAPI calls defined below. + */ +extern JS_FRIEND_API(bool) +JS_IsTypedArrayObject(JSObject *obj); + +/* + * Check whether obj supports JS_GetArrayBufferView* APIs. Note that this may + * return false if a security wrapper is encountered that denies the + * unwrapping. If this test or one of the more specific tests succeeds, then it + * is safe to call the various ArrayBufferView accessor JSAPI calls defined + * below. + */ +extern JS_FRIEND_API(bool) +JS_IsArrayBufferViewObject(JSObject *obj); + +/* + * Test for specific typed array types (ArrayBufferView subtypes) + */ + +extern JS_FRIEND_API(bool) +JS_IsInt8Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsUint8Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsUint8ClampedArray(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsInt16Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsUint16Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsInt32Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsUint32Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsFloat32Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsFloat64Array(JSObject *obj); + +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +namespace js { + +extern JS_FRIEND_API(JSObject *) +UnwrapInt8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8ClampedArray(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat64Array(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBuffer(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBufferView(JSObject *obj); + +namespace detail { + +extern JS_FRIEND_DATA(const Class* const) Int8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ClampedArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float64ArrayClassPtr; + +const size_t TypedArrayLengthSlot = 1; + +} // namespace detail + +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +#define JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Type, type) \ +inline void \ +Get ## Type ## ArrayLengthAndData(JSObject *obj, uint32_t *length, type **data) \ +{ \ + JS_ASSERT(GetObjectClass(obj) == detail::Type ## ArrayClassPtr); \ + const JS::Value &slot = GetReservedSlot(obj, detail::TypedArrayLengthSlot); \ + *length = mozilla::SafeCast(slot.toInt32()); \ + *data = static_cast(GetObjectPrivate(obj)); \ +} + +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int8, int8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8Clamped, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int16, int16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint16, uint16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int32, int32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint32, uint32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float32, float) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float64, double) + +#undef JS_DEFINE_DATA_AND_LENGTH_ACCESSOR + +// This one isn't inlined because it's rather tricky (by dint of having to deal +// with a dozen-plus classes and varying slot layouts. +extern JS_FRIEND_API(void) +GetArrayBufferViewLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +// This one isn't inlined because there are a bunch of different ArrayBuffer +// classes that would have to be individually handled here. +extern JS_FRIEND_API(void) +GetArrayBufferLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +} // namespace js + +/* + * Unwrap Typed arrays all at once. Return nullptr without throwing if the + * object cannot be viewed as the correct typed array, or the typed array + * object on success, filling both outparameters. + */ +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsInt8Array(JSObject *obj, uint32_t *length, int8_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsUint8Array(JSObject *obj, uint32_t *length, uint8_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsUint8ClampedArray(JSObject *obj, uint32_t *length, uint8_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsInt16Array(JSObject *obj, uint32_t *length, int16_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsUint16Array(JSObject *obj, uint32_t *length, uint16_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsInt32Array(JSObject *obj, uint32_t *length, int32_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsUint32Array(JSObject *obj, uint32_t *length, uint32_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsFloat32Array(JSObject *obj, uint32_t *length, float **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsFloat64Array(JSObject *obj, uint32_t *length, double **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsArrayBufferView(JSObject *obj, uint32_t *length, uint8_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsArrayBuffer(JSObject *obj, uint32_t *length, uint8_t **data); + +/* + * Get the type of elements in a typed array, or TypeMax if a DataView. + * + * |obj| must have passed a JS_IsArrayBufferView/JS_Is*Array test, or somehow + * be known that it would pass such a test: it is an ArrayBufferView or a + * wrapper of an ArrayBufferView, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(js::Scalar::Type) +JS_GetArrayBufferViewType(JSObject *obj); + +/* + * Check whether obj supports the JS_GetArrayBuffer* APIs. Note that this may + * return false if a security wrapper is encountered that denies the + * unwrapping. If this test succeeds, then it is safe to call the various + * accessor JSAPI calls defined below. + */ +extern JS_FRIEND_API(bool) +JS_IsArrayBufferObject(JSObject *obj); + +/* + * Return the available byte length of an array buffer. + * + * |obj| must have passed a JS_IsArrayBufferObject test, or somehow be known + * that it would pass such a test: it is an ArrayBuffer or a wrapper of an + * ArrayBuffer, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(uint32_t) +JS_GetArrayBufferByteLength(JSObject *obj); + +/* + * Check whether the obj is ArrayBufferObject and memory mapped. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. + */ +extern JS_FRIEND_API(bool) +JS_IsMappedArrayBufferObject(JSObject *obj); + +/* + * Return the number of elements in a typed array. + * + * |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow + * be known that it would pass such a test: it is a typed array or a wrapper of + * a typed array, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(uint32_t) +JS_GetTypedArrayLength(JSObject *obj); + +/* + * Return the byte offset from the start of an array buffer to the start of a + * typed array view. + * + * |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow + * be known that it would pass such a test: it is a typed array or a wrapper of + * a typed array, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(uint32_t) +JS_GetTypedArrayByteOffset(JSObject *obj); + +/* + * Return the byte length of a typed array. + * + * |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow + * be known that it would pass such a test: it is a typed array or a wrapper of + * a typed array, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(uint32_t) +JS_GetTypedArrayByteLength(JSObject *obj); + +/* + * Check whether obj supports JS_ArrayBufferView* APIs. Note that this may + * return false if a security wrapper is encountered that denies the + * unwrapping. + */ +extern JS_FRIEND_API(bool) +JS_IsArrayBufferViewObject(JSObject *obj); + +/* + * More generic name for JS_GetTypedArrayByteLength to cover DataViews as well + */ +extern JS_FRIEND_API(uint32_t) +JS_GetArrayBufferViewByteLength(JSObject *obj); + +/* + * Return a pointer to the start of the data referenced by a typed array. The + * data is still owned by the typed array, and should not be modified on + * another thread. Furthermore, the pointer can become invalid on GC (if the + * data is small and fits inside the array's GC header), so callers must take + * care not to hold on across anything that could GC. + * + * |obj| must have passed a JS_Is*Array test, or somehow be known that it would + * pass such a test: it is a typed array or a wrapper of a typed array, and the + * unwrapping will succeed. + */ + +extern JS_FRIEND_API(uint8_t *) +JS_GetArrayBufferData(JSObject *obj); +extern JS_FRIEND_API(int8_t *) +JS_GetInt8ArrayData(JSObject *obj); +extern JS_FRIEND_API(uint8_t *) +JS_GetUint8ArrayData(JSObject *obj); +extern JS_FRIEND_API(uint8_t *) +JS_GetUint8ClampedArrayData(JSObject *obj); +extern JS_FRIEND_API(int16_t *) +JS_GetInt16ArrayData(JSObject *obj); +extern JS_FRIEND_API(uint16_t *) +JS_GetUint16ArrayData(JSObject *obj); +extern JS_FRIEND_API(int32_t *) +JS_GetInt32ArrayData(JSObject *obj); +extern JS_FRIEND_API(uint32_t *) +JS_GetUint32ArrayData(JSObject *obj); +extern JS_FRIEND_API(float *) +JS_GetFloat32ArrayData(JSObject *obj); +extern JS_FRIEND_API(double *) +JS_GetFloat64ArrayData(JSObject *obj); + +/* + * Stable versions of the above functions where the buffer remains valid as long + * as the object is live. + */ +extern JS_FRIEND_API(uint8_t *) +JS_GetStableArrayBufferData(JSContext *cx, JS::HandleObject obj); + +/* + * Same as above, but for any kind of ArrayBufferView. Prefer the type-specific + * versions when possible. + */ +extern JS_FRIEND_API(void *) +JS_GetArrayBufferViewData(JSObject *obj); + +/* + * Return the ArrayBuffer underlying an ArrayBufferView. If the buffer has been + * neutered, this will still return the neutered buffer. |obj| must be an + * object that would return true for JS_IsArrayBufferViewObject(). + */ +extern JS_FRIEND_API(JSObject *) +JS_GetArrayBufferViewBuffer(JSContext *cx, JS::HandleObject obj); + +typedef enum { + ChangeData, + KeepData +} NeuterDataDisposition; + +/* + * Set an ArrayBuffer's length to 0 and neuter all of its views. + * + * The |changeData| argument is a hint to inform internal behavior with respect + * to the internal pointer to the ArrayBuffer's data after being neutered. + * There is no guarantee it will be respected. But if it is respected, the + * ArrayBuffer's internal data pointer will, or will not, have changed + * accordingly. + */ +extern JS_FRIEND_API(bool) +JS_NeuterArrayBuffer(JSContext *cx, JS::HandleObject obj, + NeuterDataDisposition changeData); + +/* + * Check whether the obj is ArrayBufferObject and neutered. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. + */ +extern JS_FRIEND_API(bool) +JS_IsNeuteredArrayBufferObject(JSObject *obj); + +/* + * Check whether obj supports JS_GetDataView* APIs. + */ +JS_FRIEND_API(bool) +JS_IsDataViewObject(JSObject *obj); + +/* + * Return the byte offset of a data view into its array buffer. |obj| must be a + * DataView. + * + * |obj| must have passed a JS_IsDataViewObject test, or somehow be known that + * it would pass such a test: it is a data view or a wrapper of a data view, + * and the unwrapping will succeed. + */ +JS_FRIEND_API(uint32_t) +JS_GetDataViewByteOffset(JSObject *obj); + +/* + * Return the byte length of a data view. + * + * |obj| must have passed a JS_IsDataViewObject test, or somehow be known that + * it would pass such a test: it is a data view or a wrapper of a data view, + * and the unwrapping will succeed. If cx is nullptr, then DEBUG builds may be + * unable to assert when unwrapping should be disallowed. + */ +JS_FRIEND_API(uint32_t) +JS_GetDataViewByteLength(JSObject *obj); + +/* + * Return a pointer to the beginning of the data referenced by a DataView. + * + * |obj| must have passed a JS_IsDataViewObject test, or somehow be known that + * it would pass such a test: it is a data view or a wrapper of a data view, + * and the unwrapping will succeed. If cx is nullptr, then DEBUG builds may be + * unable to assert when unwrapping should be disallowed. + */ +JS_FRIEND_API(void *) +JS_GetDataViewData(JSObject *obj); + +namespace js { + +/* + * Add a watchpoint -- in the Object.prototype.watch sense -- to |obj| for the + * property |id|, using the callable object |callable| as the function to be + * called for notifications. + * + * This is an internal function exposed -- temporarily -- only so that DOM + * proxies can be watchable. Don't use it! We'll soon kill off the + * Object.prototype.{,un}watch functions, at which point this will go too. + */ +extern JS_FRIEND_API(bool) +WatchGuts(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); + +/* + * Remove a watchpoint -- in the Object.prototype.watch sense -- from |obj| for + * the property |id|. + * + * This is an internal function exposed -- temporarily -- only so that DOM + * proxies can be watchable. Don't use it! We'll soon kill off the + * Object.prototype.{,un}watch functions, at which point this will go too. + */ +extern JS_FRIEND_API(bool) +UnwatchGuts(JSContext *cx, JS::HandleObject obj, JS::HandleId id); + +} // namespace js + +/* + * A class, expected to be passed by value, which represents the CallArgs for a + * JSJitGetterOp. + */ +class JSJitGetterCallArgs : protected JS::MutableHandleValue +{ + public: + explicit JSJitGetterCallArgs(const JS::CallArgs& args) + : JS::MutableHandleValue(args.rval()) + {} + + explicit JSJitGetterCallArgs(JS::RootedValue* rooted) + : JS::MutableHandleValue(rooted) + {} + + JS::MutableHandleValue rval() { + return *this; + } +}; + +/* + * A class, expected to be passed by value, which represents the CallArgs for a + * JSJitSetterOp. + */ +class JSJitSetterCallArgs : protected JS::MutableHandleValue +{ + public: + explicit JSJitSetterCallArgs(const JS::CallArgs& args) + : JS::MutableHandleValue(args[0]) + {} + + JS::MutableHandleValue operator[](unsigned i) { + MOZ_ASSERT(i == 0); + return *this; + } + + unsigned length() const { return 1; } + + // Add get() or maybe hasDefined() as needed +}; + +struct JSJitMethodCallArgsTraits; + +/* + * A class, expected to be passed by reference, which represents the CallArgs + * for a JSJitMethodOp. + */ +class JSJitMethodCallArgs : protected JS::detail::CallArgsBase +{ + private: + typedef JS::detail::CallArgsBase Base; + friend struct JSJitMethodCallArgsTraits; + + public: + explicit JSJitMethodCallArgs(const JS::CallArgs& args) { + argv_ = args.array(); + argc_ = args.length(); + } + + JS::MutableHandleValue rval() const { + return Base::rval(); + } + + unsigned length() const { return Base::length(); } + + JS::MutableHandleValue operator[](unsigned i) const { + return Base::operator[](i); + } + + bool hasDefined(unsigned i) const { + return Base::hasDefined(i); + } + + JSObject &callee() const { + // We can't use Base::callee() because that will try to poke at + // this->usedRval_, which we don't have. + return argv_[-2].toObject(); + } + + // Add get() as needed +}; + +struct JSJitMethodCallArgsTraits +{ + static const size_t offsetOfArgv = offsetof(JSJitMethodCallArgs, argv_); + static const size_t offsetOfArgc = offsetof(JSJitMethodCallArgs, argc_); +}; + +/* + * This struct contains metadata passed from the DOM to the JS Engine for JIT + * optimizations on DOM property accessors. Eventually, this should be made + * available to general JSAPI users, but we are not currently ready to do so. + */ +typedef bool +(* JSJitGetterOp)(JSContext *cx, JS::HandleObject thisObj, + void *specializedThis, JSJitGetterCallArgs args); +typedef bool +(* JSJitSetterOp)(JSContext *cx, JS::HandleObject thisObj, + void *specializedThis, JSJitSetterCallArgs args); +typedef bool +(* JSJitMethodOp)(JSContext *cx, JS::HandleObject thisObj, + void *specializedThis, const JSJitMethodCallArgs& args); + +struct JSJitInfo { + enum OpType { + Getter, + Setter, + Method, + ParallelNative, + StaticMethod, + // Must be last + OpTypeCount + }; + + enum ArgType { + // Basic types + String = (1 << 0), + Integer = (1 << 1), // Only 32-bit or less + Double = (1 << 2), // Maybe we want to add Float sometime too + Boolean = (1 << 3), + Object = (1 << 4), + Null = (1 << 5), + + // And derived types + Numeric = Integer | Double, + // Should "Primitive" use the WebIDL definition, which + // excludes string and null, or the typical JS one that includes them? + Primitive = Numeric | Boolean | Null | String, + ObjectOrNull = Object | Null, + Any = ObjectOrNull | Primitive, + + // Our sentinel value. + ArgTypeListEnd = (1 << 31) + }; + + static_assert(Any & String, "Any must include String."); + static_assert(Any & Integer, "Any must include Integer."); + static_assert(Any & Double, "Any must include Double."); + static_assert(Any & Boolean, "Any must include Boolean."); + static_assert(Any & Object, "Any must include Object."); + static_assert(Any & Null, "Any must include Null."); + + enum AliasSet { + // An enum that describes what this getter/setter/method aliases. This + // determines what things can be hoisted past this call, and if this + // call is movable what it can be hoisted past. + + // Alias nothing: a constant value, getting it can't affect any other + // values, nothing can affect it. + AliasNone, + + // Alias things that can modify the DOM but nothing else. Doing the + // call can't affect the behavior of any other function. + AliasDOMSets, + + // Alias the world. Calling this can change arbitrary values anywhere + // in the system. Most things fall in this bucket. + AliasEverything, + + // Must be last. + AliasSetCount + }; + + bool hasParallelNative() const + { + return type() == ParallelNative; + } + + bool needsOuterizedThisObject() const + { + return type() != Getter && type() != Setter; + } + + bool isTypedMethodJitInfo() const + { + return isTypedMethod; + } + + OpType type() const + { + return OpType(type_); + } + + AliasSet aliasSet() const + { + return AliasSet(aliasSet_); + } + + JSValueType returnType() const + { + return JSValueType(returnType_); + } + + union { + JSJitGetterOp getter; + JSJitSetterOp setter; + JSJitMethodOp method; + /* An alternative native that's safe to call in parallel mode. */ + JSParallelNative parallelNative; + /* A DOM static method, used for Promise wrappers */ + JSNative staticMethod; + }; + + uint16_t protoID; + uint16_t depth; + + // These fields are carefully packed to take up 4 bytes. If you need more + // bits for whatever reason, please see if you can steal bits from existing + // fields before adding more members to this structure. + +#define JITINFO_OP_TYPE_BITS 4 +#define JITINFO_ALIAS_SET_BITS 4 +#define JITINFO_RETURN_TYPE_BITS 8 + + // The OpType that says what sort of function we are. + uint32_t type_ : JITINFO_OP_TYPE_BITS; + + // The alias set for this op. This is a _minimal_ alias set; in + // particular for a method it does not include whatever argument + // conversions might do. That's covered by argTypes and runtime + // analysis of the actual argument types being passed in. + uint32_t aliasSet_ : JITINFO_ALIAS_SET_BITS; + + // The return type tag. Might be JSVAL_TYPE_UNKNOWN. + uint32_t returnType_ : JITINFO_RETURN_TYPE_BITS; + + static_assert(OpTypeCount <= (1 << JITINFO_OP_TYPE_BITS), + "Not enough space for OpType"); + static_assert(AliasSetCount <= (1 << JITINFO_ALIAS_SET_BITS), + "Not enough space for AliasSet"); + static_assert((sizeof(JSValueType) * 8) <= JITINFO_RETURN_TYPE_BITS, + "Not enough space for JSValueType"); + +#undef JITINFO_RETURN_TYPE_BITS +#undef JITINFO_ALIAS_SET_BITS +#undef JITINFO_OP_TYPE_BITS + + uint32_t isInfallible : 1; /* Is op fallible? False in setters. */ + uint32_t isMovable : 1; /* Is op movable? To be movable the op must + not AliasEverything, but even that might + not be enough (e.g. in cases when it can + throw). */ + // XXXbz should we have a JSValueType for the type of the member? + uint32_t isAlwaysInSlot : 1; /* True if this is a getter that can always + get the value from a slot of the "this" + object. */ + uint32_t isLazilyCachedInSlot : 1; /* True if this is a getter that can + sometimes (if the slot doesn't contain + UndefinedValue()) get the value from a + slot of the "this" object. */ + uint32_t isTypedMethod : 1; /* True if this is an instance of + JSTypedMethodJitInfo. */ + uint32_t slotIndex : 11; /* If isAlwaysInSlot or isSometimesInSlot is + true, the index of the slot to get the value + from. Otherwise 0. */ +}; + +static_assert(sizeof(JSJitInfo) == (sizeof(void*) + 2 * sizeof(uint32_t)), + "There are several thousand instances of JSJitInfo stored in " + "a binary. Please don't increase its space requirements without " + "verifying that there is no other way forward (better packing, " + "smaller datatypes for fields, subclassing, etc.)."); + +struct JSTypedMethodJitInfo +{ + // We use C-style inheritance here, rather than C++ style inheritance + // because not all compilers support brace-initialization for non-aggregate + // classes. Using C++ style inheritance and constructors instead of + // brace-initialization would also force the creation of static + // constructors (on some compilers) when JSJitInfo and JSTypedMethodJitInfo + // structures are declared. Since there can be several thousand of these + // structures present and we want to have roughly equivalent performance + // across a range of compilers, we do things manually. + JSJitInfo base; + + const JSJitInfo::ArgType* const argTypes; /* For a method, a list of sets of + types that the function + expects. This can be used, + for example, to figure out + when argument coercions can + have side-effects. */ +}; + +namespace JS { +namespace detail { + +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_PARALLEL_NATIVE_TO only. */ +inline int CheckIsParallelNative(JSParallelNative parallelNative); + +} // namespace detail +} // namespace JS + +#define JS_CAST_PARALLEL_NATIVE_TO(v, To) \ + (static_cast(sizeof(JS::detail::CheckIsParallelNative(v))), \ + reinterpret_cast(v)) + +/* + * You may ask yourself: why do we define a wrapper around a wrapper here? + * The answer is that some compilers don't understand initializing a union + * as we do below with a construct like: + * + * reinterpret_cast(JSParallelNativeThreadSafeWrapper) + * + * (We need the reinterpret_cast because we must initialize the union with + * a datum of the type of the union's first member.) + * + * Presumably this has something to do with template instantiation. + * Initializing with a normal function pointer seems to work fine. Hence + * the ugliness that you see before you. + */ +#define JS_JITINFO_NATIVE_PARALLEL(infoName, parallelOp) \ + const JSJitInfo infoName = \ + {{JS_CAST_PARALLEL_NATIVE_TO(parallelOp, JSJitGetterOp)},0,0,JSJitInfo::ParallelNative,JSJitInfo::AliasEverything,JSVAL_TYPE_MISSING,false,false,false,false,false,0} + +#define JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(infoName, wrapperName, serialOp) \ + bool wrapperName##_ParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, \ + JS::Value *vp) \ + { \ + return JSParallelNativeThreadSafeWrapper(cx, argc, vp); \ + } \ + JS_JITINFO_NATIVE_PARALLEL(infoName, wrapperName##_ParallelNativeThreadSafeWrapper) + +static MOZ_ALWAYS_INLINE const JSJitInfo * +FUNCTION_VALUE_TO_JITINFO(const JS::Value& v) +{ + JS_ASSERT(js::GetObjectClass(&v.toObject()) == js::FunctionClassPtr); + return reinterpret_cast(&v.toObject())->jitinfo; +} + +/* Statically asserted in jsfun.h. */ +static const unsigned JS_FUNCTION_INTERPRETED_BIT = 0x1; + +static MOZ_ALWAYS_INLINE void +SET_JITINFO(JSFunction * func, const JSJitInfo *info) +{ + js::shadow::Function *fun = reinterpret_cast(func); + JS_ASSERT(!(fun->flags & JS_FUNCTION_INTERPRETED_BIT)); + fun->jitinfo = info; +} + +/* + * Engine-internal extensions of jsid. This code is here only until we + * eliminate Gecko's dependencies on it! + */ + +static MOZ_ALWAYS_INLINE jsid +JSID_FROM_BITS(size_t bits) +{ + jsid id; + JSID_BITS(id) = bits; + return id; +} + +namespace js { +namespace detail { +bool IdMatchesAtom(jsid id, JSAtom *atom); +} +} + +/* + * Must not be used on atoms that are representable as integer jsids. + * Prefer NameToId or AtomToId over this function: + * + * A PropertyName is an atom that does not contain an integer in the range + * [0, UINT32_MAX]. However, jsid can only hold an integer in the range + * [0, JSID_INT_MAX] (where JSID_INT_MAX == 2^31-1). Thus, for the range of + * integers (JSID_INT_MAX, UINT32_MAX], to represent as a jsid 'id', it must be + * the case JSID_IS_ATOM(id) and !JSID_TO_ATOM(id)->isPropertyName(). In most + * cases when creating a jsid, code does not have to care about this corner + * case because: + * + * - When given an arbitrary JSAtom*, AtomToId must be used, which checks for + * integer atoms representable as integer jsids, and does this conversion. + * + * - When given a PropertyName*, NameToId can be used which which does not need + * to do any dynamic checks. + * + * Thus, it is only the rare third case which needs this function, which + * handles any JSAtom* that is known not to be representable with an int jsid. + */ +static MOZ_ALWAYS_INLINE jsid +NON_INTEGER_ATOM_TO_JSID(JSAtom *atom) +{ + JS_ASSERT(((size_t)atom & 0x7) == 0); + jsid id = JSID_FROM_BITS((size_t)atom); + JS_ASSERT(js::detail::IdMatchesAtom(id, atom)); + return id; +} + +/* All strings stored in jsids are atomized, but are not necessarily property names. */ +static MOZ_ALWAYS_INLINE bool +JSID_IS_ATOM(jsid id) +{ + return JSID_IS_STRING(id); +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_ATOM(jsid id, JSAtom *atom) +{ + return id == JSID_FROM_BITS((size_t)atom); +} + +static MOZ_ALWAYS_INLINE JSAtom * +JSID_TO_ATOM(jsid id) +{ + return (JSAtom *)JSID_TO_STRING(id); +} + +JS_STATIC_ASSERT(sizeof(jsid) == sizeof(void*)); + +namespace js { + +static MOZ_ALWAYS_INLINE JS::Value +IdToValue(jsid id) +{ + if (JSID_IS_STRING(id)) + return JS::StringValue(JSID_TO_STRING(id)); + if (JSID_IS_INT(id)) + return JS::Int32Value(JSID_TO_INT(id)); + if (JSID_IS_SYMBOL(id)) + return JS::SymbolValue(JSID_TO_SYMBOL(id)); + JS_ASSERT(JSID_IS_VOID(id)); + return JS::UndefinedValue(); +} + +/* + * If the embedder has registered a default JSContext callback, returns the + * result of the callback. Otherwise, asserts that |rt| has exactly one + * JSContext associated with it, and returns that context. + */ +extern JS_FRIEND_API(JSContext *) +DefaultJSContext(JSRuntime *rt); + +typedef JSContext* +(* DefaultJSContextCallback)(JSRuntime *rt); + +JS_FRIEND_API(void) +SetDefaultJSContextCallback(JSRuntime *rt, DefaultJSContextCallback cb); + +/* + * To help embedders enforce their invariants, we allow them to specify in + * advance which JSContext should be passed to JSAPI calls. If this is set + * to a non-null value, the assertSameCompartment machinery does double- + * duty (in debug builds) to verify that it matches the cx being used. + */ +#ifdef DEBUG +JS_FRIEND_API(void) +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx); +#else +inline void +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx) {}; +#endif + + +enum CTypesActivityType { + CTYPES_CALL_BEGIN, + CTYPES_CALL_END, + CTYPES_CALLBACK_BEGIN, + CTYPES_CALLBACK_END +}; + +typedef void +(* CTypesActivityCallback)(JSContext *cx, CTypesActivityType type); + +/* + * Sets a callback that is run whenever js-ctypes is about to be used when + * calling into C. + */ +JS_FRIEND_API(void) +SetCTypesActivityCallback(JSRuntime *rt, CTypesActivityCallback cb); + +class JS_FRIEND_API(AutoCTypesActivityCallback) { + private: + JSContext *cx; + CTypesActivityCallback callback; + CTypesActivityType endType; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + public: + AutoCTypesActivityCallback(JSContext *cx, CTypesActivityType beginType, + CTypesActivityType endType + MOZ_GUARD_OBJECT_NOTIFIER_PARAM); + ~AutoCTypesActivityCallback() { + DoEndCallback(); + } + void DoEndCallback() { + if (callback) { + callback(cx, endType); + callback = nullptr; + } + } +}; + +typedef bool +(* ObjectMetadataCallback)(JSContext *cx, JSObject **pmetadata); + +/* + * Specify a callback to invoke when creating each JS object in the current + * compartment, which may return a metadata object to associate with the + * object. Objects with different metadata have different shape hierarchies, + * so for efficiency, objects should generally try to share metadata objects. + */ +JS_FRIEND_API(void) +SetObjectMetadataCallback(JSContext *cx, ObjectMetadataCallback callback); + +/* Manipulate the metadata associated with an object. */ + +JS_FRIEND_API(bool) +SetObjectMetadata(JSContext *cx, JS::HandleObject obj, JS::HandleObject metadata); + +JS_FRIEND_API(JSObject *) +GetObjectMetadata(JSObject *obj); + +JS_FRIEND_API(void) +UnsafeDefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value); + +JS_FRIEND_API(bool) +SliceSlowly(JSContext* cx, JS::HandleObject obj, JS::HandleObject receiver, + uint32_t begin, uint32_t end, JS::HandleObject result); + +/* ES5 8.12.8. */ +extern JS_FRIEND_API(bool) +DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandleValue vp); + +/* + * Helper function. To approximate a call to the [[DefineOwnProperty]] internal + * method described in ES5, first call this, then call JS_DefinePropertyById. + * + * JS_DefinePropertyById by itself does not enforce the invariants on + * non-configurable properties when obj->isNative(). This function performs the + * relevant checks (specified in ES5 8.12.9 [[DefineOwnProperty]] steps 1-11), + * but only if obj is native. + * + * The reason for the messiness here is that ES5 uses [[DefineOwnProperty]] as + * a sort of extension point, but there is no hook in js::Class, + * js::ProxyHandler, or the JSAPI with precisely the right semantics for it. + */ +extern JS_FRIEND_API(bool) +CheckDefineProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +/* + * Helper function for HTMLDocument and HTMLFormElement. + * + * These are the only two interfaces that have [OverrideBuiltins], a named + * getter, and no named setter. They're implemented as proxies with a custom + * getOwnPropertyDescriptor() method. Unfortunately, overriding + * getOwnPropertyDescriptor() automatically affects the behavior of set(), + * which normally is just common sense but is *not* desired for these two + * interfaces. + * + * The fix is for these two interfaces to override set() to ignore the + * getOwnPropertyDescriptor() override. + * + * SetPropertyIgnoringNamedGetter is exposed to make it easier to override + * set() in this way. It carries out all the steps of BaseProxyHandler::set() + * except the initial getOwnPropertyDescriptor()/getPropertyDescriptor() calls. + * The caller must supply those results as the 'desc' and 'descIsOwn' + * parameters. + * + * Implemented in jsproxy.cpp. + */ +JS_FRIEND_API(bool) +SetPropertyIgnoringNamedGetter(JSContext *cx, const BaseProxyHandler *handler, + JS::HandleObject proxy, JS::HandleObject receiver, + JS::HandleId id, JS::MutableHandle desc, + bool descIsOwn, bool strict, JS::MutableHandleValue vp); + +JS_FRIEND_API(void) +ReportErrorWithId(JSContext *cx, const char *msg, JS::HandleId id); + +// This function is for one specific use case, please don't use this for anything else! +extern JS_FRIEND_API(bool) +ExecuteInGlobalAndReturnScope(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleObject scope); + +} /* namespace js */ + +extern JS_FRIEND_API(bool) +js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg, + JS::Handle descriptor, bool *bp); + +extern JS_FRIEND_API(bool) +js_ReportIsNotFunction(JSContext *cx, JS::HandleValue v); + +#ifdef JSGC_GENERATIONAL +extern JS_FRIEND_API(void) +JS_StoreObjectPostBarrierCallback(JSContext* cx, + void (*callback)(JSTracer *trc, JSObject *key, void *data), + JSObject *key, void *data); + +extern JS_FRIEND_API(void) +JS_StoreStringPostBarrierCallback(JSContext* cx, + void (*callback)(JSTracer *trc, JSString *key, void *data), + JSString *key, void *data); +#else +inline void +JS_StoreObjectPostBarrierCallback(JSContext* cx, + void (*callback)(JSTracer *trc, JSObject *key, void *data), + JSObject *key, void *data) {} + +inline void +JS_StoreStringPostBarrierCallback(JSContext* cx, + void (*callback)(JSTracer *trc, JSString *key, void *data), + JSString *key, void *data) {} +#endif /* JSGC_GENERATIONAL */ + +#endif /* jsfriendapi_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsprf.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsprf.h new file mode 100644 index 0000000000..bfedf98ca8 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsprf.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsprf_h +#define jsprf_h + +/* +** API for PR printf like routines. Supports the following formats +** %d - decimal +** %u - unsigned decimal +** %x - unsigned hex +** %X - unsigned uppercase hex +** %o - unsigned octal +** %hd, %hu, %hx, %hX, %ho - 16-bit versions of above +** %ld, %lu, %lx, %lX, %lo - 32-bit versions of above +** %lld, %llu, %llx, %llX, %llo - 64 bit versions of above +** %s - ascii string +** %hs - ucs2 string +** %c - character +** %p - pointer (deals with machine dependent pointer size) +** %f - float +** %g - float +*/ + +#include + +#include "jstypes.h" + +/* +** sprintf into a fixed size buffer. Guarantees that a NUL is at the end +** of the buffer. Returns the length of the written output, NOT including +** the NUL, or (uint32_t)-1 if an error occurs. +*/ +extern JS_PUBLIC_API(uint32_t) JS_snprintf(char *out, uint32_t outlen, const char *fmt, ...); + +/* +** sprintf into a malloc'd buffer. Return a pointer to the malloc'd +** buffer on success, nullptr on failure. Call "JS_smprintf_free" to release +** the memory returned. +*/ +extern JS_PUBLIC_API(char*) JS_smprintf(const char *fmt, ...); + +/* +** Free the memory allocated, for the caller, by JS_smprintf +*/ +extern JS_PUBLIC_API(void) JS_smprintf_free(char *mem); + +/* +** "append" sprintf into a malloc'd buffer. "last" is the last value of +** the malloc'd buffer. sprintf will append data to the end of last, +** growing it as necessary using realloc. If last is nullptr, JS_sprintf_append +** will allocate the initial string. The return value is the new value of +** last for subsequent calls, or nullptr if there is a malloc failure. +*/ +extern JS_PUBLIC_API(char*) JS_sprintf_append(char *last, const char *fmt, ...); + +/* +** va_list forms of the above. +*/ +extern JS_PUBLIC_API(uint32_t) JS_vsnprintf(char *out, uint32_t outlen, const char *fmt, va_list ap); +extern JS_PUBLIC_API(char*) JS_vsmprintf(const char *fmt, va_list ap); +extern JS_PUBLIC_API(char*) JS_vsprintf_append(char *last, const char *fmt, va_list ap); + +#endif /* jsprf_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsprototypes.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsprototypes.h new file mode 100644 index 0000000000..1cb56bf8da --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsprototypes.h @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsprototypes_h +#define jsprototypes_h + +/* A higher-order macro for enumerating all JSProtoKey values. */ +/* + * Consumers define macros as follows: + * macro(name, code, init, clasp) + * name: The canonical name of the class. + * code: The enumerator code. There are part of the XDR API, and must not change. + * init: Initialization function. These are |extern "C";|, and clients should use + * |extern "C" {}| as appropriate when using this macro. + * clasp: The JSClass for this object, or "dummy" if it doesn't exist. + * + * + * Consumers wishing to iterate over all the JSProtoKey values, can use + * JS_FOR_EACH_PROTOTYPE. However, there are certain values that don't correspond + * to real constructors, like Null or constructors that are disabled via + * preprocessor directives. We still need to include these in the JSProtoKey list + * in order to maintain binary XDR compatibility, but we need to provide a tool + * to handle them differently. JS_FOR_PROTOTYPES fills this niche. + * + * Consumers pass two macros to JS_FOR_PROTOTYPES - |real| and |imaginary|. The + * former is invoked for entries that have real client-exposed constructors, and + * the latter is called for the rest. Consumers that don't care about this + * distinction can simply pass the same macro to both, which is exactly what + * JS_FOR_EACH_PROTOTYPE does. + */ + +#define CLASP(name) (&name##Class) +#define OCLASP(name) (&name##Object::class_) +#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[Scalar::type]) + +#ifdef ENABLE_PARALLEL_JS +#define IF_PJS(real,imaginary) real +#else +#define IF_PJS(real,imaginary) imaginary +#endif + +#ifdef EXPOSE_INTL_API +#define IF_INTL(real,imaginary) real +#else +#define IF_INTL(real,imaginary) imaginary +#endif + +#ifdef ENABLE_BINARYDATA +#define IF_BDATA(real,imaginary) real +#else +#define IF_BDATA(real,imaginary) imaginary +#endif + +#ifdef ENABLE_SHARED_ARRAY_BUFFER +#define IF_SAB(real,imaginary) real +#else +#define IF_SAB(real,imaginary) imaginary +#endif + +#ifdef JS_HAS_SYMBOLS +#define IF_SYMBOLS(real,imaginary) real +#else +#define IF_SYMBOLS(real,imaginary) imaginary +#endif + +#define JS_FOR_PROTOTYPES(real,imaginary) \ + imaginary(Null, 0, js_InitNullClass, dummy) \ + real(Object, 1, js_InitViaClassSpec, &JSObject::class_) \ + real(Function, 2, js_InitViaClassSpec, &JSFunction::class_) \ + real(Array, 3, js_InitViaClassSpec, OCLASP(Array)) \ + real(Boolean, 4, js_InitBooleanClass, OCLASP(Boolean)) \ + real(JSON, 5, js_InitJSONClass, CLASP(JSON)) \ + real(Date, 6, js_InitViaClassSpec, OCLASP(Date)) \ + real(Math, 7, js_InitMathClass, CLASP(Math)) \ + real(Number, 8, js_InitNumberClass, OCLASP(Number)) \ + real(String, 9, js_InitStringClass, OCLASP(String)) \ + real(RegExp, 10, js_InitRegExpClass, OCLASP(RegExp)) \ + real(Error, 11, js_InitViaClassSpec, OCLASP(Error)) \ + real(InternalError, 12, js_InitViaClassSpec, OCLASP(Error)) \ + real(EvalError, 13, js_InitViaClassSpec, OCLASP(Error)) \ + real(RangeError, 14, js_InitViaClassSpec, OCLASP(Error)) \ + real(ReferenceError, 15, js_InitViaClassSpec, OCLASP(Error)) \ + real(SyntaxError, 16, js_InitViaClassSpec, OCLASP(Error)) \ + real(TypeError, 17, js_InitViaClassSpec, OCLASP(Error)) \ + real(URIError, 18, js_InitViaClassSpec, OCLASP(Error)) \ + real(Iterator, 19, js_InitIteratorClasses, OCLASP(PropertyIterator)) \ + real(StopIteration, 20, js_InitIteratorClasses, OCLASP(StopIteration)) \ + real(ArrayBuffer, 21, js_InitArrayBufferClass, &js::ArrayBufferObject::protoClass) \ + real(Int8Array, 22, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int8)) \ + real(Uint8Array, 23, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8)) \ + real(Int16Array, 24, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int16)) \ + real(Uint16Array, 25, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint16)) \ + real(Int32Array, 26, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int32)) \ + real(Uint32Array, 27, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint32)) \ + real(Float32Array, 28, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float32)) \ + real(Float64Array, 29, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float64)) \ + real(Uint8ClampedArray, 30, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8Clamped)) \ + real(Proxy, 31, js_InitProxyClass, &ProxyObject::uncallableClass_) \ + real(WeakMap, 32, js_InitWeakMapClass, OCLASP(WeakMap)) \ + real(Map, 33, js_InitMapClass, OCLASP(Map)) \ + real(Set, 34, js_InitSetClass, OCLASP(Set)) \ + real(DataView, 35, js_InitDataViewClass, OCLASP(DataView)) \ +IF_SYMBOLS(real,imaginary)(Symbol, 36, js_InitSymbolClass, &js::SymbolObject::class_) \ +IF_SAB(real,imaginary)(SharedArrayBuffer, 37, js_InitSharedArrayBufferClass, &js::SharedArrayBufferObject::protoClass) \ +IF_INTL(real,imaginary) (Intl, 38, js_InitIntlClass, CLASP(Intl)) \ +IF_BDATA(real,imaginary)(TypedObject, 39, js_InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \ + imaginary(GeneratorFunction, 40, js_InitIteratorClasses, dummy) \ +IF_BDATA(real,imaginary)(SIMD, 41, js_InitSIMDClass, OCLASP(SIMD)) \ + +#define JS_FOR_EACH_PROTOTYPE(macro) JS_FOR_PROTOTYPES(macro,macro) + +#endif /* jsprototypes_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsproxy.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsproxy.h new file mode 100644 index 0000000000..b4588c4c2a --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsproxy.h @@ -0,0 +1,563 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsproxy_h +#define jsproxy_h + +#include "mozilla/Maybe.h" + +#include "jsfriendapi.h" + +#include "js/CallNonGenericMethod.h" +#include "js/Class.h" + +namespace js { + +using JS::AutoIdVector; +using JS::CallArgs; +using JS::HandleId; +using JS::HandleObject; +using JS::HandleValue; +using JS::IsAcceptableThis; +using JS::MutableHandle; +using JS::MutableHandleObject; +using JS::MutableHandleValue; +using JS::NativeImpl; +using JS::PrivateValue; +using JS::Value; + +class RegExpGuard; +class JS_FRIEND_API(Wrapper); + +/* + * A proxy is a JSObject that implements generic behavior by providing custom + * implementations for each object trap. The implementation for each trap is + * provided by a C++ object stored on the proxy, known as its handler. + * + * A major use case for proxies is to forward each trap to another object, + * known as its target. The target can be an arbitrary C++ object. Not every + * proxy has the notion of a target, however. + * + * Proxy traps are grouped into fundamental and derived traps. Every proxy has + * to at least provide implementations for the fundamental traps, but the + * derived traps can be implemented in terms of the fundamental ones + * BaseProxyHandler provides implementations of the derived traps in terms of + * the (pure virtual) fundamental traps. + * + * In addition to the normal traps, there are two models for proxy prototype + * chains. First, proxies may opt to use the standard prototype mechanism used + * throughout the engine. To do so, simply pass a prototype to NewProxyObject() + * at creation time. All prototype accesses will then "just work" to treat the + * proxy as a "normal" object. Alternatively, if instead the proxy wishes to + * implement more complicated prototype semantics (if, for example, it wants to + * delegate the prototype lookup to a wrapped object), it may pass Proxy::LazyProto + * as the prototype at create time and opt in to the trapped prototype system, + * which guarantees that their trap will be called on any and every prototype + * chain access of the object. + * + * This system is implemented with two traps: {get,set}PrototypeOf. The default + * implementation of setPrototypeOf throws a TypeError. Since it is not possible + * to create an object without a sense of prototype chain, handler implementors + * must provide a getPrototypeOf trap if opting in to the dynamic prototype system. + * + * To minimize code duplication, a set of abstract proxy handler classes is + * provided, from which other handlers may inherit. These abstract classes + * are organized in the following hierarchy: + * + * BaseProxyHandler + * | + * DirectProxyHandler + * | + * Wrapper + */ + +/* + * BaseProxyHandler is the most generic kind of proxy handler. It does not make + * any assumptions about the target. Consequently, it does not provide any + * default implementation for the fundamental traps. It does, however, implement + * the derived traps in terms of the fundamental ones. This allows consumers of + * this class to define any custom behavior they want. + * + * Important: If you add a trap here, you should probably also add a Proxy::foo + * entry point with an AutoEnterPolicy. If you don't, you need an explicit + * override for the trap in SecurityWrapper. See bug 945826 comment 0. + */ +class JS_FRIEND_API(BaseProxyHandler) +{ + const void *mFamily; + + /* + * Proxy handlers can use mHasPrototype to request the following special + * treatment from the JS engine: + * + * - When mHasPrototype is true, the engine never calls these methods: + * getPropertyDescriptor, has, set, enumerate, iterate. Instead, for + * these operations, it calls the "own" traps like + * getOwnPropertyDescriptor, hasOwn, defineProperty, keys, etc., and + * consults the prototype chain if needed. + * + * - When mHasPrototype is true, the engine calls handler->get() only if + * handler->hasOwn() says an own property exists on the proxy. If not, + * it consults the prototype chain. + * + * This is useful because it frees the ProxyHandler from having to implement + * any behavior having to do with the prototype chain. + */ + bool mHasPrototype; + + /* + * All proxies indicate whether they have any sort of interesting security + * policy that might prevent the caller from doing something it wants to + * the object. In the case of wrappers, this distinction is used to + * determine whether the caller may strip off the wrapper if it so desires. + */ + bool mHasSecurityPolicy; + + public: + explicit BaseProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); + virtual ~BaseProxyHandler(); + + bool hasPrototype() const { + return mHasPrototype; + } + + bool hasSecurityPolicy() const { + return mHasSecurityPolicy; + } + + inline const void *family() const { + return mFamily; + } + static size_t offsetOfFamily() { + return offsetof(BaseProxyHandler, mFamily); + } + + virtual bool finalizeInBackground(Value priv) const { + /* + * Called on creation of a proxy to determine whether its finalize + * method can be finalized on the background thread. + */ + return true; + } + + /* Policy enforcement traps. + * + * enter() allows the policy to specify whether the caller may perform |act| + * on the proxy's |id| property. In the case when |act| is CALL, |id| is + * generally JSID_VOID. + * + * The |act| parameter to enter() specifies the action being performed. + * If |bp| is false, the trap suggests that the caller throw (though it + * may still decide to squelch the error). + * + * We make these OR-able so that assertEnteredPolicy can pass a union of them. + * For example, get{,Own}PropertyDescriptor is invoked by both calls to ::get() + * and ::set() (since we need to look up the accessor), so its + * assertEnteredPolicy would pass GET | SET. + */ + typedef uint32_t Action; + enum { + NONE = 0x00, + GET = 0x01, + SET = 0x02, + CALL = 0x04, + ENUMERATE = 0x08 + }; + + virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Action act, + bool *bp) const; + + /* ES5 Harmony fundamental proxy traps. */ + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const = 0; + virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const = 0; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, + HandleId id, MutableHandle desc) const = 0; + virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const = 0; + virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, + AutoIdVector &props) const = 0; + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const = 0; + virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) const = 0; + + /* ES5 Harmony derived proxy traps. */ + virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; + virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; + virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, + HandleId id, MutableHandleValue vp) const; + virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, + HandleId id, bool strict, MutableHandleValue vp) const; + virtual bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props) const; + virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, + MutableHandleValue vp) const; + + /* Spidermonkey extensions. */ + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const = 0; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args) const; + virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp) const; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx) const; + virtual const char *className(JSContext *cx, HandleObject proxy) const; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const; + virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp) const; + virtual void finalize(JSFreeOp *fop, JSObject *proxy) const; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop) const; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp) const; + + // These two hooks must be overridden, or not overridden, in tandem -- no + // overriding just one! + virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, + JS::HandleObject callable) const; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const; + + virtual bool slice(JSContext *cx, HandleObject proxy, uint32_t begin, uint32_t end, + HandleObject result) const; + + /* See comment for weakmapKeyDelegateOp in js/Class.h. */ + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const; + virtual bool isScripted() const { return false; } +}; + +/* + * DirectProxyHandler includes a notion of a target object. All traps are + * reimplemented such that they forward their behavior to the target. This + * allows consumers of this class to forward to another object as transparently + * and efficiently as possible. + * + * Important: If you add a trap implementation here, you probably also need to + * add an override in CrossCompartmentWrapper. If you don't, you risk + * compartment mismatches. See bug 945826 comment 0. + */ +class JS_PUBLIC_API(DirectProxyHandler) : public BaseProxyHandler +{ + public: + explicit DirectProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); + + /* ES5 Harmony fundamental proxy traps. */ + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, + bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject proxy, + AutoIdVector &props) const MOZ_OVERRIDE; + + /* ES5 Harmony derived proxy traps. */ + virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, + bool *bp) const MOZ_OVERRIDE; + virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, + bool *bp) const MOZ_OVERRIDE; + virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool keys(JSContext *cx, HandleObject proxy, + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, + MutableHandleValue vp) const MOZ_OVERRIDE; + + /* Spidermonkey extensions. */ + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, + CallArgs args) const MOZ_OVERRIDE; + virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, + bool *bp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, + unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, + RegExpGuard *g) const MOZ_OVERRIDE; + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const MOZ_OVERRIDE; +}; + +/* + * Dispatch point for handlers that executes the appropriate C++ or scripted traps. + * + * Important: All proxy traps need either (a) an AutoEnterPolicy in their + * Proxy::foo entry point below or (b) an override in SecurityWrapper. See bug + * 945826 comment 0. + */ +class Proxy +{ + public: + /* ES5 Harmony fundamental proxy traps. */ + static bool preventExtensions(JSContext *cx, HandleObject proxy); + static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc); + static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandleValue vp); + static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc); + static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandleValue vp); + static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc); + static bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props); + static bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); + static bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props); + + /* ES5 Harmony derived proxy traps. */ + static bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); + static bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); + static bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, + MutableHandleValue vp); + static bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, + bool strict, MutableHandleValue vp); + static bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props); + static bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, MutableHandleValue vp); + + /* Spidermonkey extensions. */ + static bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible); + static bool call(JSContext *cx, HandleObject proxy, const CallArgs &args); + static bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args); + static bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args); + static bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp); + static bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx); + static const char *className(JSContext *cx, HandleObject proxy); + static JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent); + static bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g); + static bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); + static bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + static bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp); + + static bool watch(JSContext *cx, HandleObject proxy, HandleId id, HandleObject callable); + static bool unwatch(JSContext *cx, HandleObject proxy, HandleId id); + + static bool slice(JSContext *cx, HandleObject obj, uint32_t begin, uint32_t end, + HandleObject result); + + /* IC entry path for handling __noSuchMethod__ on access. */ + static bool callProp(JSContext *cx, HandleObject proxy, HandleObject reveiver, HandleId id, + MutableHandleValue vp); +}; + +// Use these in places where you don't want to #include vm/ProxyObject.h. +extern JS_FRIEND_DATA(const js::Class* const) CallableProxyClassPtr; +extern JS_FRIEND_DATA(const js::Class* const) UncallableProxyClassPtr; + +inline bool IsProxy(JSObject *obj) +{ + return GetObjectClass(obj)->isProxy(); +} + +/* + * These are part of the API. + * + * NOTE: PROXY_PRIVATE_SLOT is 0 because that way slot 0 is usable by API + * clients for both proxy and non-proxy objects. So an API client that only + * needs to store one slot's worth of data doesn't need to branch on what sort + * of object it has. + */ +const uint32_t PROXY_PRIVATE_SLOT = 0; +const uint32_t PROXY_HANDLER_SLOT = 1; +const uint32_t PROXY_EXTRA_SLOT = 2; +const uint32_t PROXY_MINIMUM_SLOTS = 4; + +inline const BaseProxyHandler * +GetProxyHandler(JSObject *obj) +{ + JS_ASSERT(IsProxy(obj)); + return (const BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate(); +} + +inline const Value & +GetProxyPrivate(JSObject *obj) +{ + JS_ASSERT(IsProxy(obj)); + return GetReservedSlot(obj, PROXY_PRIVATE_SLOT); +} + +inline JSObject * +GetProxyTargetObject(JSObject *obj) +{ + JS_ASSERT(IsProxy(obj)); + return GetProxyPrivate(obj).toObjectOrNull(); +} + +inline const Value & +GetProxyExtra(JSObject *obj, size_t n) +{ + JS_ASSERT(IsProxy(obj)); + return GetReservedSlot(obj, PROXY_EXTRA_SLOT + n); +} + +inline void +SetProxyHandler(JSObject *obj, BaseProxyHandler *handler) +{ + JS_ASSERT(IsProxy(obj)); + SetReservedSlot(obj, PROXY_HANDLER_SLOT, PrivateValue(handler)); +} + +inline void +SetProxyExtra(JSObject *obj, size_t n, const Value &extra) +{ + JS_ASSERT(IsProxy(obj)); + JS_ASSERT(n <= 1); + SetReservedSlot(obj, PROXY_EXTRA_SLOT + n, extra); +} + +inline bool +IsScriptedProxy(JSObject *obj) +{ + return IsProxy(obj) && GetProxyHandler(obj)->isScripted(); +} + +class MOZ_STACK_CLASS ProxyOptions { + protected: + /* protected constructor for subclass */ + ProxyOptions(bool singletonArg, const Class *claspArg) + : singleton_(singletonArg), + clasp_(claspArg) + {} + + public: + ProxyOptions() : singleton_(false), + clasp_(UncallableProxyClassPtr) + {} + + bool singleton() const { return singleton_; } + ProxyOptions &setSingleton(bool flag) { + singleton_ = flag; + return *this; + } + + const Class *clasp() const { + return clasp_; + } + ProxyOptions &setClass(const Class *claspArg) { + clasp_ = claspArg; + return *this; + } + ProxyOptions &selectDefaultClass(bool callable) { + const Class *classp = callable? CallableProxyClassPtr : + UncallableProxyClassPtr; + return setClass(classp); + } + + private: + bool singleton_; + const Class *clasp_; +}; + +JS_FRIEND_API(JSObject *) +NewProxyObject(JSContext *cx, const BaseProxyHandler *handler, HandleValue priv, + JSObject *proto, JSObject *parent, const ProxyOptions &options = ProxyOptions()); + +JSObject * +RenewProxyObject(JSContext *cx, JSObject *obj, BaseProxyHandler *handler, Value priv); + +class JS_FRIEND_API(AutoEnterPolicy) +{ + public: + typedef BaseProxyHandler::Action Action; + AutoEnterPolicy(JSContext *cx, const BaseProxyHandler *handler, + HandleObject wrapper, HandleId id, Action act, bool mayThrow) +#ifdef JS_DEBUG + : context(nullptr) +#endif + { + allow = handler->hasSecurityPolicy() ? handler->enter(cx, wrapper, id, act, &rv) + : true; + recordEnter(cx, wrapper, id, act); + // We want to throw an exception if all of the following are true: + // * The policy disallowed access. + // * The policy set rv to false, indicating that we should throw. + // * The caller did not instruct us to ignore exceptions. + // * The policy did not throw itself. + if (!allow && !rv && mayThrow) + reportErrorIfExceptionIsNotPending(cx, id); + } + + virtual ~AutoEnterPolicy() { recordLeave(); } + inline bool allowed() { return allow; } + inline bool returnValue() { JS_ASSERT(!allowed()); return rv; } + + protected: + // no-op constructor for subclass + AutoEnterPolicy() +#ifdef JS_DEBUG + : context(nullptr) + , enteredAction(BaseProxyHandler::NONE) +#endif + {}; + void reportErrorIfExceptionIsNotPending(JSContext *cx, jsid id); + bool allow; + bool rv; + +#ifdef JS_DEBUG + JSContext *context; + mozilla::Maybe enteredProxy; + mozilla::Maybe enteredId; + Action enteredAction; + + // NB: We explicitly don't track the entered action here, because sometimes + // SET traps do an implicit GET during their implementation, leading to + // spurious assertions. + AutoEnterPolicy *prev; + void recordEnter(JSContext *cx, HandleObject proxy, HandleId id, Action act); + void recordLeave(); + + friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id, Action act); +#else + inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id, Action act) {} + inline void recordLeave() {} +#endif + +}; + +#ifdef JS_DEBUG +class JS_FRIEND_API(AutoWaivePolicy) : public AutoEnterPolicy { +public: + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) + { + allow = true; + recordEnter(cx, proxy, id, act); + } +}; +#else +class JS_FRIEND_API(AutoWaivePolicy) { + public: + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) + {} +}; +#endif + +#ifdef JS_DEBUG +extern JS_FRIEND_API(void) +assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act); +#else +inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act) +{}; +#endif + +} /* namespace js */ + +extern JS_FRIEND_API(JSObject *) +js_InitProxyClass(JSContext *cx, JS::HandleObject obj); + +#endif /* jsproxy_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jspubtd.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jspubtd.h new file mode 100644 index 0000000000..7a524c8aef --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jspubtd.h @@ -0,0 +1,548 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jspubtd_h +#define jspubtd_h + +/* + * JS public API typedefs. + */ + +#include "mozilla/Assertions.h" +#include "mozilla/LinkedList.h" +#include "mozilla/NullPtr.h" +#include "mozilla/PodOperations.h" + +#include "jsprototypes.h" +#include "jstypes.h" + +#include "js/TypeDecls.h" + +#if defined(JSGC_USE_EXACT_ROOTING) +# define JSGC_TRACK_EXACT_ROOTS +#endif + +namespace JS { + +class AutoIdVector; +class CallArgs; + +template +class Rooted; + +class JS_FRIEND_API(CompileOptions); +class JS_FRIEND_API(ReadOnlyCompileOptions); +class JS_FRIEND_API(OwningCompileOptions); +class JS_PUBLIC_API(CompartmentOptions); + +struct Zone; + +} /* namespace JS */ + +namespace js { +struct ContextFriendFields; +} // namespace js + +/* + * Run-time version enumeration. For compile-time version checking, please use + * the JS_HAS_* macros in jsversion.h, or use MOZJS_MAJOR_VERSION, + * MOZJS_MINOR_VERSION, MOZJS_PATCH_VERSION, and MOZJS_ALPHA definitions. + */ +enum JSVersion { + JSVERSION_ECMA_3 = 148, + JSVERSION_1_6 = 160, + JSVERSION_1_7 = 170, + JSVERSION_1_8 = 180, + JSVERSION_ECMA_5 = 185, + JSVERSION_DEFAULT = 0, + JSVERSION_UNKNOWN = -1, + JSVERSION_LATEST = JSVERSION_ECMA_5 +}; + +/* Result of typeof operator enumeration. */ +enum JSType { + JSTYPE_VOID, /* undefined */ + JSTYPE_OBJECT, /* object */ + JSTYPE_FUNCTION, /* function */ + JSTYPE_STRING, /* string */ + JSTYPE_NUMBER, /* number */ + JSTYPE_BOOLEAN, /* boolean */ + JSTYPE_NULL, /* null */ + JSTYPE_SYMBOL, /* symbol */ + JSTYPE_LIMIT +}; + +/* Dense index into cached prototypes and class atoms for standard objects. */ +enum JSProtoKey { +#define PROTOKEY_AND_INITIALIZER(name,code,init,clasp) JSProto_##name = code, + JS_FOR_EACH_PROTOTYPE(PROTOKEY_AND_INITIALIZER) +#undef PROTOKEY_AND_INITIALIZER + JSProto_LIMIT +}; + +/* + * This enum type is used to control the behavior of a JSObject property + * iterator function that has type JSNewEnumerate. + */ +enum JSIterateOp { + /* Create new iterator state over enumerable properties. */ + JSENUMERATE_INIT, + + /* Create new iterator state over all properties. */ + JSENUMERATE_INIT_ALL, + + /* Iterate once. */ + JSENUMERATE_NEXT, + + /* Destroy iterator state. */ + JSENUMERATE_DESTROY +}; + +/* See Value::gcKind() and JSTraceCallback in Tracer.h. */ +enum JSGCTraceKind { + JSTRACE_OBJECT, + JSTRACE_STRING, + JSTRACE_SYMBOL, + JSTRACE_SCRIPT, + + /* + * Trace kinds internal to the engine. The embedding can only see them if + * it implements JSTraceCallback. + */ + JSTRACE_LAZY_SCRIPT, + JSTRACE_JITCODE, + JSTRACE_SHAPE, + JSTRACE_BASE_SHAPE, + JSTRACE_TYPE_OBJECT, + JSTRACE_LAST = JSTRACE_TYPE_OBJECT +}; + +/* Struct forward declarations. */ +struct JSClass; +struct JSCompartment; +struct JSConstDoubleSpec; +struct JSCrossCompartmentCall; +struct JSErrorReport; +struct JSExceptionState; +struct JSFunctionSpec; +struct JSIdArray; +struct JSLocaleCallbacks; +struct JSObjectMap; +struct JSPrincipals; +struct JSPropertyDescriptor; +struct JSPropertyName; +struct JSPropertySpec; +struct JSRuntime; +struct JSSecurityCallbacks; +struct JSStructuredCloneCallbacks; +struct JSStructuredCloneReader; +struct JSStructuredCloneWriter; +class JS_PUBLIC_API(JSTracer); + +class JSFlatString; + +#ifdef JS_THREADSAFE +typedef struct PRCallOnceType JSCallOnceType; +#else +typedef bool JSCallOnceType; +#endif +typedef bool (*JSInitCallback)(void); + +/* + * Generic trace operation that calls JS_CallTracer on each traceable thing + * stored in data. + */ +typedef void +(* JSTraceDataOp)(JSTracer *trc, void *data); + +void js_FinishGC(JSRuntime *rt); + +namespace js { +namespace gc { +class StoreBuffer; +void MarkPersistentRootedChains(JSTracer *); +void FinishPersistentRootedChains(JSRuntime *); +} +} + +namespace JS { + +typedef void (*OffThreadCompileCallback)(void *token, void *callbackData); + +namespace shadow { + +struct Runtime +{ + /* Restrict zone access during Minor GC. */ + bool needsBarrier_; + +#ifdef JSGC_GENERATIONAL + private: + js::gc::StoreBuffer *gcStoreBufferPtr_; +#endif + + public: + explicit Runtime( +#ifdef JSGC_GENERATIONAL + js::gc::StoreBuffer *storeBuffer +#endif + ) + : needsBarrier_(false) +#ifdef JSGC_GENERATIONAL + , gcStoreBufferPtr_(storeBuffer) +#endif + {} + + bool needsBarrier() const { + return needsBarrier_; + } + +#ifdef JSGC_GENERATIONAL + js::gc::StoreBuffer *gcStoreBufferPtr() { return gcStoreBufferPtr_; } +#endif + + static JS::shadow::Runtime *asShadowRuntime(JSRuntime *rt) { + return reinterpret_cast(rt); + } + + /* Allow inlining of PersistentRooted constructors and destructors. */ + private: + template friend class JS::PersistentRooted; + friend void js::gc::MarkPersistentRootedChains(JSTracer *); + friend void js::gc::FinishPersistentRootedChains(JSRuntime *rt); + + mozilla::LinkedList functionPersistentRooteds; + mozilla::LinkedList idPersistentRooteds; + mozilla::LinkedList objectPersistentRooteds; + mozilla::LinkedList scriptPersistentRooteds; + mozilla::LinkedList stringPersistentRooteds; + mozilla::LinkedList valuePersistentRooteds; + + /* Specializations of this return references to the appropriate list. */ + template + inline mozilla::LinkedList > &getPersistentRootedList(); +}; + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return functionPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return idPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return objectPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return scriptPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return stringPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return valuePersistentRooteds; } + +} /* namespace shadow */ + +class JS_PUBLIC_API(AutoGCRooter) +{ + public: + AutoGCRooter(JSContext *cx, ptrdiff_t tag); + AutoGCRooter(js::ContextFriendFields *cx, ptrdiff_t tag); + + ~AutoGCRooter() { + MOZ_ASSERT(this == *stackTop); + *stackTop = down; + } + + /* Implemented in gc/RootMarking.cpp. */ + inline void trace(JSTracer *trc); + static void traceAll(JSTracer *trc); + static void traceAllWrappers(JSTracer *trc); + + /* T must be a context type */ + template + static void traceAllInContext(T* cx, JSTracer *trc) { + for (AutoGCRooter *gcr = cx->autoGCRooters; gcr; gcr = gcr->down) + gcr->trace(trc); + } + + protected: + AutoGCRooter * const down; + + /* + * Discriminates actual subclass of this being used. If non-negative, the + * subclass roots an array of values of the length stored in this field. + * If negative, meaning is indicated by the corresponding value in the enum + * below. Any other negative value indicates some deeper problem such as + * memory corruption. + */ + ptrdiff_t tag_; + + enum { + VALARRAY = -2, /* js::AutoValueArray */ + PARSER = -3, /* js::frontend::Parser */ + SHAPEVECTOR = -4, /* js::AutoShapeVector */ + IDARRAY = -6, /* js::AutoIdArray */ + DESCVECTOR = -7, /* js::AutoPropDescVector */ + VALVECTOR = -10, /* js::AutoValueVector */ + IDVECTOR = -13, /* js::AutoIdVector */ + OBJVECTOR = -14, /* js::AutoObjectVector */ + STRINGVECTOR =-15, /* js::AutoStringVector */ + SCRIPTVECTOR =-16, /* js::AutoScriptVector */ + NAMEVECTOR = -17, /* js::AutoNameVector */ + HASHABLEVALUE=-18, /* js::HashableValue */ + IONMASM = -19, /* js::jit::MacroAssembler */ + IONALLOC = -20, /* js::jit::AutoTempAllocatorRooter */ + WRAPVECTOR = -21, /* js::AutoWrapperVector */ + WRAPPER = -22, /* js::AutoWrapperRooter */ + OBJOBJHASHMAP=-23, /* js::AutoObjectObjectHashMap */ + OBJU32HASHMAP=-24, /* js::AutoObjectUnsigned32HashMap */ + OBJHASHSET = -25, /* js::AutoObjectHashSet */ + JSONPARSER = -26, /* js::JSONParser */ + CUSTOM = -27, /* js::CustomAutoRooter */ + FUNVECTOR = -28 /* js::AutoFunctionVector */ + }; + + private: + AutoGCRooter ** const stackTop; + + /* No copy or assignment semantics. */ + AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; + void operator=(AutoGCRooter &ida) MOZ_DELETE; +}; + +} /* namespace JS */ + +namespace js { + +/* + * Parallel operations in general can have one of three states. They may + * succeed, fail, or "bail", where bail indicates that the code encountered an + * unexpected condition and should be re-run sequentially. Different + * subcategories of the "bail" state are encoded as variants of TP_RETRY_*. + */ +enum ParallelResult { TP_SUCCESS, TP_RETRY_SEQUENTIALLY, TP_RETRY_AFTER_GC, TP_FATAL }; + +struct ThreadSafeContext; +class ForkJoinContext; +class ExclusiveContext; + +class Allocator; + +enum ThingRootKind +{ + THING_ROOT_OBJECT, + THING_ROOT_SHAPE, + THING_ROOT_BASE_SHAPE, + THING_ROOT_TYPE_OBJECT, + THING_ROOT_STRING, + THING_ROOT_SYMBOL, + THING_ROOT_JIT_CODE, + THING_ROOT_SCRIPT, + THING_ROOT_LAZY_SCRIPT, + THING_ROOT_ID, + THING_ROOT_VALUE, + THING_ROOT_TYPE, + THING_ROOT_BINDINGS, + THING_ROOT_PROPERTY_DESCRIPTOR, + THING_ROOT_PROP_DESC, + THING_ROOT_LIMIT +}; + +/* + * This list enumerates the different types of conceptual stacks we have in + * SpiderMonkey. In reality, they all share the C stack, but we allow different + * stack limits depending on the type of code running. + */ +enum StackKind +{ + StackForSystemCode, // C++, such as the GC, running on behalf of the VM. + StackForTrustedScript, // Script running with trusted principals. + StackForUntrustedScript, // Script running with untrusted principals. + StackKindCount +}; + +template +struct RootKind; + +/* + * Specifically mark the ThingRootKind of externally visible types, so that + * JSAPI users may use JSRooted... types without having the class definition + * available. + */ +template +struct SpecificRootKind +{ + static ThingRootKind rootKind() { return Kind; } +}; + +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; + +struct ContextFriendFields +{ + protected: + JSRuntime *const runtime_; + + /* The current compartment. */ + JSCompartment *compartment_; + + /* The current zone. */ + JS::Zone *zone_; + + public: + explicit ContextFriendFields(JSRuntime *rt) + : runtime_(rt), compartment_(nullptr), zone_(nullptr), autoGCRooters(nullptr) + { +#ifdef JSGC_TRACK_EXACT_ROOTS + mozilla::PodArrayZero(thingGCRooters); +#endif + } + + static const ContextFriendFields *get(const JSContext *cx) { + return reinterpret_cast(cx); + } + + static ContextFriendFields *get(JSContext *cx) { + return reinterpret_cast(cx); + } + +#ifdef JSGC_TRACK_EXACT_ROOTS + private: + /* + * Stack allocated GC roots for stack GC heap pointers, which may be + * overwritten if moved during a GC. + */ + JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; + + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } + +#endif + + void checkNoGCRooters(); + + /* Stack of thread-stack-allocated GC roots. */ + JS::AutoGCRooter *autoGCRooters; + + friend JSRuntime *GetRuntime(const JSContext *cx); + friend JSCompartment *GetContextCompartment(const JSContext *cx); + friend JS::Zone *GetContextZone(const JSContext *cx); + template friend class JS::Rooted; +}; + +/* + * Inlinable accessors for JSContext. + * + * - These must not be available on the more restricted superclasses of + * JSContext, so we can't simply define them on ContextFriendFields. + * + * - They're perfectly ordinary JSContext functionality, so ought to be + * usable without resorting to jsfriendapi.h, and when JSContext is an + * incomplete type. + */ +inline JSRuntime * +GetRuntime(const JSContext *cx) +{ + return ContextFriendFields::get(cx)->runtime_; +} + +inline JSCompartment * +GetContextCompartment(const JSContext *cx) +{ + return ContextFriendFields::get(cx)->compartment_; +} + +inline JS::Zone * +GetContextZone(const JSContext *cx) +{ + return ContextFriendFields::get(cx)->zone_; +} + +class PerThreadData; + +struct PerThreadDataFriendFields +{ + private: + // Note: this type only exists to permit us to derive the offset of + // the perThread data within the real JSRuntime* type in a portable + // way. + struct RuntimeDummy : JS::shadow::Runtime + { + struct PerThreadDummy { + void *field1; + uintptr_t field2; +#ifdef JS_DEBUG + uint64_t field3; +#endif + } mainThread; + }; + + public: + + PerThreadDataFriendFields(); + +#ifdef JSGC_TRACK_EXACT_ROOTS + private: + /* + * Stack allocated GC roots for stack GC heap pointers, which may be + * overwritten if moved during a GC. + */ + JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; + + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } +#endif + + /* Limit pointer for checking native stack consumption. */ + uintptr_t nativeStackLimit[StackKindCount]; + + static const size_t RuntimeMainThreadOffset = offsetof(RuntimeDummy, mainThread); + + static inline PerThreadDataFriendFields *get(js::PerThreadData *pt) { + return reinterpret_cast(pt); + } + + static inline PerThreadDataFriendFields *getMainThread(JSRuntime *rt) { + // mainThread must always appear directly after |JS::shadow::Runtime|. + // Tested by a JS_STATIC_ASSERT in |jsfriendapi.cpp| + return reinterpret_cast( + reinterpret_cast(rt) + RuntimeMainThreadOffset); + } + + static inline const PerThreadDataFriendFields *getMainThread(const JSRuntime *rt) { + // mainThread must always appear directly after |JS::shadow::Runtime|. + // Tested by a JS_STATIC_ASSERT in |jsfriendapi.cpp| + return reinterpret_cast( + reinterpret_cast(rt) + RuntimeMainThreadOffset); + } + + template friend class JS::Rooted; +}; + +} /* namespace js */ + +#endif /* jspubtd_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jstypes.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jstypes.h new file mode 100644 index 0000000000..e9927bca0d --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jstypes.h @@ -0,0 +1,226 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* +** File: jstypes.h +** Description: Definitions of NSPR's basic types +** +** Prototypes and macros used to make up for deficiencies in ANSI environments +** that we have found. +** +** Since we do not wrap and all the other standard headers, authors +** of portable code will not know in general that they need these definitions. +** Instead of requiring these authors to find the dependent uses in their code +** and take the following steps only in those C files, we take steps once here +** for all C files. +**/ + +#ifndef jstypes_h +#define jstypes_h + +#include "mozilla/Attributes.h" +#include "mozilla/Types.h" + +// jstypes.h is (or should be!) included by every file in SpiderMonkey. +// js-config.h and jsversion.h also should be included by every file. +// So include them here. +// XXX: including them in js/RequiredDefines.h should be a better option, since +// that is by definition the header file that should be included in all +// SpiderMonkey code. However, Gecko doesn't do this! See bug 909576. +#include "js-config.h" +#include "jsversion.h" + +/*********************************************************************** +** MACROS: JS_EXTERN_API +** JS_EXPORT_API +** DESCRIPTION: +** These are only for externally visible routines and globals. For +** internal routines, just use "extern" for type checking and that +** will not export internal cross-file or forward-declared symbols. +** Define a macro for declaring procedures return types. We use this to +** deal with windoze specific type hackery for DLL definitions. Use +** JS_EXTERN_API when the prototype for the method is declared. Use +** JS_EXPORT_API for the implementation of the method. +** +** Example: +** in dowhim.h +** JS_EXTERN_API( void ) DoWhatIMean( void ); +** in dowhim.c +** JS_EXPORT_API( void ) DoWhatIMean( void ) { return; } +** +** +***********************************************************************/ + +#define JS_EXTERN_API(type) extern MOZ_EXPORT type +#define JS_EXPORT_API(type) MOZ_EXPORT type +#define JS_EXPORT_DATA(type) MOZ_EXPORT type +#define JS_IMPORT_API(type) MOZ_IMPORT_API type +#define JS_IMPORT_DATA(type) MOZ_IMPORT_DATA type + +/* + * The linkage of JS API functions differs depending on whether the file is + * used within the JS library or not. Any source file within the JS + * interpreter should define EXPORT_JS_API whereas any client of the library + * should not. STATIC_JS_API is used to build JS as a static library. + */ +#if defined(STATIC_JS_API) +# define JS_PUBLIC_API(t) t +# define JS_PUBLIC_DATA(t) t +#elif defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API) +# define JS_PUBLIC_API(t) MOZ_EXPORT t +# define JS_PUBLIC_DATA(t) MOZ_EXPORT t +#else +# define JS_PUBLIC_API(t) MOZ_IMPORT_API t +# define JS_PUBLIC_DATA(t) MOZ_IMPORT_DATA t +#endif + +#if defined(STATIC_JS_API) || defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API) +# define JS_FRIEND_API(t) MOZ_EXPORT t +# define JS_FRIEND_DATA(t) MOZ_EXPORT t +#else +# define JS_FRIEND_API(t) MOZ_IMPORT_API t +# define JS_FRIEND_DATA(t) MOZ_IMPORT_DATA t +#endif + +#if defined(_MSC_VER) && defined(_M_IX86) +#define JS_FASTCALL __fastcall +#elif defined(__GNUC__) && defined(__i386__) +#define JS_FASTCALL __attribute__((fastcall)) +#else +#define JS_FASTCALL +#define JS_NO_FASTCALL +#endif + +/*********************************************************************** +** MACROS: JS_BEGIN_MACRO +** JS_END_MACRO +** DESCRIPTION: +** Macro body brackets so that macros with compound statement definitions +** behave syntactically more like functions when called. +***********************************************************************/ +#define JS_BEGIN_MACRO do { + +#if defined(_MSC_VER) && _MSC_VER >= 1400 +# define JS_END_MACRO \ + } __pragma(warning(push)) __pragma(warning(disable:4127)) \ + while (0) __pragma(warning(pop)) +#else +# define JS_END_MACRO } while (0) +#endif + +/*********************************************************************** +** MACROS: JS_BIT +** JS_BITMASK +** DESCRIPTION: +** Bit masking macros. XXX n must be <= 31 to be portable +***********************************************************************/ +#define JS_BIT(n) ((uint32_t)1 << (n)) +#define JS_BITMASK(n) (JS_BIT(n) - 1) + +/*********************************************************************** +** MACROS: JS_HOWMANY +** JS_ROUNDUP +** DESCRIPTION: +** Commonly used macros for operations on compatible types. +***********************************************************************/ +#define JS_HOWMANY(x,y) (((x)+(y)-1)/(y)) +#define JS_ROUNDUP(x,y) (JS_HOWMANY(x,y)*(y)) + +#include "jscpucfg.h" + +/* + * Define JS_64BIT iff we are building in an environment with 64-bit + * addresses. + */ +#ifdef _MSC_VER +# if defined(_M_X64) || defined(_M_AMD64) +# define JS_64BIT +# endif +#elif defined(__GNUC__) +/* Additional GCC defines are when running on Solaris, AIX, and HPUX */ +# if defined(__x86_64__) || defined(__sparcv9) || \ + defined(__64BIT__) || defined(__LP64__) +# define JS_64BIT +# endif +#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* Sun Studio C/C++ */ +# if defined(__x86_64) || defined(__sparcv9) +# define JS_64BIT +# endif +#elif defined(__xlc__) || defined(__xlC__) /* IBM XL C/C++ */ +# if defined(__64BIT__) +# define JS_64BIT +# endif +#elif defined(__HP_cc) || defined(__HP_aCC) /* HP-UX cc/aCC */ +# if defined(__LP64__) +# define JS_64BIT +# endif +#else +# error "Implement me" +#endif + +/*********************************************************************** +** MACROS: JS_ARRAY_LENGTH +** JS_ARRAY_END +** DESCRIPTION: +** Macros to get the number of elements and the pointer to one past the +** last element of a C array. Use them like this: +** +** jschar buf[10], *s; +** JSString *str; +** ... +** for (s = buf; s != JS_ARRAY_END(buf); ++s) *s = ...; +** ... +** str = JS_NewStringCopyN(cx, buf, JS_ARRAY_LENGTH(buf)); +** ... +** +***********************************************************************/ + +#define JS_ARRAY_LENGTH(array) (sizeof (array) / sizeof (array)[0]) +#define JS_ARRAY_END(array) ((array) + JS_ARRAY_LENGTH(array)) + +#define JS_BITS_PER_BYTE 8 +#define JS_BITS_PER_BYTE_LOG2 3 + +#if defined(JS_64BIT) +# define JS_BITS_PER_WORD 64 +#else +# define JS_BITS_PER_WORD 32 +#endif + +/*********************************************************************** +** MACROS: JS_FUNC_TO_DATA_PTR +** JS_DATA_TO_FUNC_PTR +** DESCRIPTION: +** Macros to convert between function and data pointers assuming that +** they have the same size. Use them like this: +** +** JSPropertyOp nativeGetter; +** JSObject *scriptedGetter; +** ... +** scriptedGetter = JS_FUNC_TO_DATA_PTR(JSObject *, nativeGetter); +** ... +** nativeGetter = JS_DATA_TO_FUNC_PTR(JSPropertyOp, scriptedGetter); +** +***********************************************************************/ + +#ifdef __GNUC__ +# define JS_FUNC_TO_DATA_PTR(type, fun) (__extension__ (type) (size_t) (fun)) +# define JS_DATA_TO_FUNC_PTR(type, ptr) (__extension__ (type) (size_t) (ptr)) +#else +/* Use an extra (void *) cast for MSVC. */ +# define JS_FUNC_TO_DATA_PTR(type, fun) ((type) (void *) (fun)) +# define JS_DATA_TO_FUNC_PTR(type, ptr) ((type) (void *) (ptr)) +#endif + +#ifdef __GNUC__ +# define JS_EXTENSION __extension__ +# define JS_EXTENSION_(s) __extension__ ({ s; }) +#else +# define JS_EXTENSION +# define JS_EXTENSION_(s) s +#endif + +#endif /* jstypes_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsversion.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsversion.h new file mode 100644 index 0000000000..1f31e40b5e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jsversion.h @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsversion_h +#define jsversion_h + +/* + * JS Capability Macros. + */ +#define JS_HAS_STR_HTML_HELPERS 1 /* has str.anchor, str.bold, etc. */ +#define JS_HAS_OBJ_PROTO_PROP 1 /* has o.__proto__ etc. */ +#define JS_HAS_OBJ_WATCHPOINT 1 /* has o.watch and o.unwatch */ +#define JS_HAS_TOSOURCE 1 /* has Object/Array toSource method */ +#define JS_HAS_CATCH_GUARD 1 /* has exception handling catch guard */ +#define JS_HAS_UNEVAL 1 /* has uneval() top-level function */ +#define JS_HAS_CONST 1 /* has JS2 const as alternative var */ +#define JS_HAS_FUN_EXPR_STMT 1 /* has function expression statement */ +#define JS_HAS_NO_SUCH_METHOD 1 /* has o.__noSuchMethod__ handler */ +#define JS_HAS_FOR_EACH_IN 1 /* has for each (lhs in iterable) */ +#define JS_HAS_GENERATORS 1 /* has yield in generator function */ +#define JS_HAS_BLOCK_SCOPE 1 /* has block scope via let/arraycomp */ +#define JS_HAS_DESTRUCTURING 2 /* has [a,b] = ... or {p:a,q:b} = ... */ +#define JS_HAS_GENERATOR_EXPRS 1 /* has (expr for (lhs in iterable)) */ +#define JS_HAS_EXPR_CLOSURES 1 /* has function (formals) listexpr */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_TEMPLATE_STRINGS 1 /* has template string support */ +#endif + +/* Support for JS_NewGlobalObject. */ +#define JS_HAS_NEW_GLOBAL_OBJECT 1 + +/* Support for JS_MakeSystemObject. */ +#define JS_HAS_MAKE_SYSTEM_OBJECT 1 + +/* Feature-test macro for evolving destructuring support. */ +#define JS_HAS_DESTRUCTURING_SHORTHAND (JS_HAS_DESTRUCTURING == 2) + +/* + * Feature for Object.prototype.__{define,lookup}{G,S}etter__ legacy support; + * support likely to be made opt-in at some future time. + */ +#define JS_OLD_GETTER_SETTER_METHODS 1 + +/* Support for Symbols - Nightly-only for now. */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_SYMBOLS 1 +#endif + +#endif /* jsversion_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jswrapper.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jswrapper.h new file mode 100644 index 0000000000..a8a510c4f7 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/jswrapper.h @@ -0,0 +1,337 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jswrapper_h +#define jswrapper_h + +#include "mozilla/Attributes.h" + +#include "jsproxy.h" + +namespace js { + +class DummyFrameGuard; + +/* + * Helper for Wrapper::New default options. + * + * Callers of Wrapper::New() who wish to specify a prototype for the created + * Wrapper, *MUST* construct a WrapperOptions with a JSContext. + */ +class MOZ_STACK_CLASS WrapperOptions : public ProxyOptions { + public: + WrapperOptions() : ProxyOptions(false, nullptr), + proto_() + {} + + explicit WrapperOptions(JSContext *cx) : ProxyOptions(false, nullptr), + proto_() + { + proto_.construct(cx); + } + + inline JSObject *proto() const; + WrapperOptions &setProto(JSObject *protoArg) { + JS_ASSERT(!proto_.empty()); + proto_.ref() = protoArg; + return *this; + } + + private: + mozilla::Maybe proto_; +}; + +/* + * A wrapper is a proxy with a target object to which it generally forwards + * operations, but may restrict access to certain operations or instrument + * the trap operations in various ways. A wrapper is distinct from a Direct Proxy + * Handler in the sense that it can be "unwrapped" in C++, exposing the underlying + * object (Direct Proxy Handlers have an underlying target object, but don't + * expect to expose this object via any kind of unwrapping operation). Callers + * should be careful to avoid unwrapping security wrappers in the wrong context. + */ +class JS_FRIEND_API(Wrapper) : public DirectProxyHandler +{ + unsigned mFlags; + + public: + using BaseProxyHandler::Action; + + enum Flags { + CROSS_COMPARTMENT = 1 << 0, + LAST_USED_FLAG = CROSS_COMPARTMENT + }; + + virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, + MutableHandleValue vp) const MOZ_OVERRIDE; + + static JSObject *New(JSContext *cx, JSObject *obj, JSObject *parent, const Wrapper *handler, + const WrapperOptions *options = nullptr); + + static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, const Wrapper *handler); + + static const Wrapper *wrapperHandler(JSObject *wrapper); + + static JSObject *wrappedObject(JSObject *wrapper); + + unsigned flags() const { + return mFlags; + } + + explicit Wrapper(unsigned flags, bool hasPrototype = false, bool hasSecurityPolicy = false); + + virtual ~Wrapper(); + + virtual bool finalizeInBackground(Value priv) const MOZ_OVERRIDE; + + static const Wrapper singleton; + static const Wrapper singletonWithPrototype; + + static JSObject *defaultProto; +}; + +inline JSObject * +WrapperOptions::proto() const +{ + return proto_.empty() ? Wrapper::defaultProto : proto_.ref(); +} + +/* Base class for all cross compartment wrapper handlers. */ +class JS_FRIEND_API(CrossCompartmentWrapper) : public Wrapper +{ + public: + explicit CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false, + bool hasSecurityPolicy = false); + + virtual ~CrossCompartmentWrapper(); + + /* ES5 Harmony fundamental wrapper traps. */ + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; + virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; + + /* ES5 Harmony derived wrapper traps. */ + virtual bool has(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool hasOwn(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool get(JSContext *cx, HandleObject wrapper, HandleObject receiver, + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool set(JSContext *cx, HandleObject wrapper, HandleObject receiver, + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool keys(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool iterate(JSContext *cx, HandleObject wrapper, unsigned flags, + MutableHandleValue vp) const MOZ_OVERRIDE; + + /* Spidermonkey extensions. */ + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, + CallArgs args) const MOZ_OVERRIDE; + virtual bool hasInstance(JSContext *cx, HandleObject wrapper, MutableHandleValue v, + bool *bp) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual JSString *fun_toString(JSContext *cx, HandleObject wrapper, + unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; + virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, + MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; + + static const CrossCompartmentWrapper singleton; + static const CrossCompartmentWrapper singletonWithPrototype; +}; + +/* + * Base class for security wrappers. A security wrapper is potentially hiding + * all or part of some wrapped object thus SecurityWrapper defaults to denying + * access to the wrappee. This is the opposite of Wrapper which tries to be + * completely transparent. + * + * NB: Currently, only a few ProxyHandler operations are overridden to deny + * access, relying on derived SecurityWrapper to block access when necessary. + */ +template +class JS_FRIEND_API(SecurityWrapper) : public Base +{ + public: + explicit SecurityWrapper(unsigned flags, bool hasPrototype = false); + + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; + virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Wrapper::Action act, + bool *bp) const MOZ_OVERRIDE; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, + CallArgs args) const MOZ_OVERRIDE; + virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, + MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, + JSContext *cx) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; + virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; + + virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, + JS::HandleObject callable) const MOZ_OVERRIDE; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const MOZ_OVERRIDE; + + /* + * Allow our subclasses to select the superclass behavior they want without + * needing to specify an exact superclass. + */ + typedef Base Permissive; + typedef SecurityWrapper Restrictive; +}; + +typedef SecurityWrapper SameCompartmentSecurityWrapper; +typedef SecurityWrapper CrossCompartmentSecurityWrapper; + +class JS_FRIEND_API(DeadObjectProxy) : public BaseProxyHandler +{ + public: + // This variable exists solely to provide a unique address for use as an identifier. + static const char sDeadObjectFamily; + + explicit DeadObjectProxy(); + + /* ES5 Harmony fundamental wrapper traps. */ + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; + + /* Spidermonkey extensions. */ + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, + CallArgs args) const MOZ_OVERRIDE; + virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, + bool *bp) const MOZ_OVERRIDE; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; + virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, + MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + + static const DeadObjectProxy singleton; +}; + +extern JSObject * +TransparentObjectWrapper(JSContext *cx, HandleObject existing, HandleObject obj, + HandleObject parent, unsigned flags); + +// Proxy family for wrappers. Public so that IsWrapper() can be fully inlined by +// jsfriendapi users. +// This variable exists solely to provide a unique address for use as an identifier. +extern JS_FRIEND_DATA(const char) sWrapperFamily; + +inline bool +IsWrapper(JSObject *obj) +{ + return IsProxy(obj) && GetProxyHandler(obj)->family() == &sWrapperFamily; +} + +// Given a JSObject, returns that object stripped of wrappers. If +// stopAtOuter is true, then this returns the outer window if it was +// previously wrapped. Otherwise, this returns the first object for +// which JSObject::isWrapper returns false. +JS_FRIEND_API(JSObject *) +UncheckedUnwrap(JSObject *obj, bool stopAtOuter = true, unsigned *flagsp = nullptr); + +// Given a JSObject, returns that object stripped of wrappers. At each stage, +// the security wrapper has the opportunity to veto the unwrap. Since checked +// code should never be unwrapping outer window wrappers, we always stop at +// outer windows. +JS_FRIEND_API(JSObject *) +CheckedUnwrap(JSObject *obj, bool stopAtOuter = true); + +// Unwrap only the outermost security wrapper, with the same semantics as +// above. This is the checked version of Wrapper::wrappedObject. +JS_FRIEND_API(JSObject *) +UnwrapOneChecked(JSObject *obj, bool stopAtOuter = true); + +JS_FRIEND_API(bool) +IsCrossCompartmentWrapper(JSObject *obj); + +bool +IsDeadProxyObject(JSObject *obj); + +JSObject * +NewDeadProxyObject(JSContext *cx, JSObject *parent, + const ProxyOptions &options = ProxyOptions()); + +void +NukeCrossCompartmentWrapper(JSContext *cx, JSObject *wrapper); + +bool +RemapWrapper(JSContext *cx, JSObject *wobj, JSObject *newTarget); + +JS_FRIEND_API(bool) +RemapAllWrappersForObject(JSContext *cx, JSObject *oldTarget, + JSObject *newTarget); + +// API to recompute all cross-compartment wrappers whose source and target +// match the given filters. +JS_FRIEND_API(bool) +RecomputeWrappers(JSContext *cx, const CompartmentFilter &sourceFilter, + const CompartmentFilter &targetFilter); + +/* + * This auto class should be used around any code, such as brain transplants, + * that may touch dead zones. Brain transplants can cause problems + * because they operate on all compartments, whether live or dead. A brain + * transplant can cause a formerly dead object to be "reanimated" by causing a + * read or write barrier to be invoked on it during the transplant. In this way, + * a zone becomes a zombie, kept alive by repeatedly consuming + * (transplanted) brains. + * + * To work around this issue, we observe when mark bits are set on objects in + * dead zones. If this happens during a brain transplant, we do a full, + * non-incremental GC at the end of the brain transplant. This will clean up any + * objects that were improperly marked. + */ +struct JS_FRIEND_API(AutoMaybeTouchDeadZones) +{ + // The version that takes an object just uses it for its runtime. + explicit AutoMaybeTouchDeadZones(JSContext *cx); + explicit AutoMaybeTouchDeadZones(JSObject *obj); + ~AutoMaybeTouchDeadZones(); + + private: + JSRuntime *runtime; + unsigned markCount; + bool inIncremental; + bool manipulatingDeadZones; +}; + +} /* namespace js */ + +#endif /* jswrapper_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Alignment.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Alignment.h new file mode 100644 index 0000000000..0ac8a48779 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Alignment.h @@ -0,0 +1,139 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Functionality related to memory alignment. */ + +#ifndef mozilla_Alignment_h +#define mozilla_Alignment_h + +#include +#include + +namespace mozilla { + +/* + * This class, and the corresponding macro MOZ_ALIGNOF, figures out how many + * bytes of alignment a given type needs. + */ +template +class AlignmentFinder +{ + struct Aligner + { + char mChar; + T mT; + }; + +public: + static const size_t alignment = sizeof(Aligner) - sizeof(T); +}; + +#define MOZ_ALIGNOF(T) mozilla::AlignmentFinder::alignment + +/* + * Declare the MOZ_ALIGNED_DECL macro for declaring aligned types. + * + * For instance, + * + * MOZ_ALIGNED_DECL(char arr[2], 8); + * + * will declare a two-character array |arr| aligned to 8 bytes. + */ + +#if defined(__GNUC__) +# define MOZ_ALIGNED_DECL(_type, _align) \ + _type __attribute__((aligned(_align))) +#elif defined(_MSC_VER) +# define MOZ_ALIGNED_DECL(_type, _align) \ + __declspec(align(_align)) _type +#else +# warning "We don't know how to align variables on this compiler." +# define MOZ_ALIGNED_DECL(_type, _align) _type +#endif + +/* + * AlignedElem is a structure whose alignment is guaranteed to be at least N + * bytes. + * + * We support 1, 2, 4, 8, and 16-bit alignment. + */ +template +struct AlignedElem; + +/* + * We have to specialize this template because GCC doesn't like + * __attribute__((aligned(foo))) where foo is a template parameter. + */ + +template<> +struct AlignedElem<1> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 1); +}; + +template<> +struct AlignedElem<2> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 2); +}; + +template<> +struct AlignedElem<4> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 4); +}; + +template<> +struct AlignedElem<8> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 8); +}; + +template<> +struct AlignedElem<16> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 16); +}; + +/* + * This utility pales in comparison to Boost's aligned_storage. The utility + * simply assumes that uint64_t is enough alignment for anyone. This may need + * to be extended one day... + * + * As an important side effect, pulling the storage into this template is + * enough obfuscation to confuse gcc's strict-aliasing analysis into not giving + * false negatives when we cast from the char buffer to whatever type we've + * constructed using the bytes. + */ +template +struct AlignedStorage +{ + union U + { + char mBytes[Nbytes]; + uint64_t mDummy; + } u; + + const void* addr() const { return u.mBytes; } + void* addr() { return u.mBytes; } +}; + +template +struct AlignedStorage2 +{ + union U + { + char mBytes[sizeof(T)]; + uint64_t mDummy; + } u; + + const T* addr() const { return reinterpret_cast(u.mBytes); } + T* addr() { return static_cast(static_cast(u.mBytes)); } +}; + +} /* namespace mozilla */ + +#endif /* mozilla_Alignment_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/AllocPolicy.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/AllocPolicy.h new file mode 100644 index 0000000000..357c632a02 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/AllocPolicy.h @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * An allocation policy concept, usable for structures and algorithms to + * control how memory is allocated and how failures are handled. + */ + +#ifndef mozilla_AllocPolicy_h +#define mozilla_AllocPolicy_h + +#include +#include + +namespace mozilla { + +/* + * Allocation policies are used to implement the standard allocation behaviors + * in a customizable way. Additionally, custom behaviors may be added to these + * behaviors, such as additionally reporting an error through an out-of-band + * mechanism when OOM occurs. The concept modeled here is as follows: + * + * - public copy constructor, assignment, destructor + * - void* malloc_(size_t) + * Responsible for OOM reporting when null is returned. + * - void* calloc_(size_t) + * Responsible for OOM reporting when null is returned. + * - void* realloc_(void*, size_t, size_t) + * Responsible for OOM reporting when null is returned. The *used* bytes + * of the previous buffer is passed in (rather than the old allocation + * size), in addition to the *new* allocation size requested. + * - void free_(void*) + * - void reportAllocOverflow() const + * Called on allocation overflow (that is, an allocation implicitly tried + * to allocate more than the available memory space -- think allocating an + * array of large-size objects, where N * size overflows) before null is + * returned. + * + * mfbt provides (and typically uses by default) only MallocAllocPolicy, which + * does nothing more than delegate to the malloc/alloc/free functions. + */ + +/* + * A policy that straightforwardly uses malloc/calloc/realloc/free and adds no + * extra behaviors. + */ +class MallocAllocPolicy +{ +public: + void* malloc_(size_t aBytes) + { + return malloc(aBytes); + } + + void* calloc_(size_t aBytes) + { + return calloc(aBytes, 1); + } + + void* realloc_(void* aPtr, size_t aOldBytes, size_t aBytes) + { + return realloc(aPtr, aBytes); + } + + void free_(void* aPtr) + { + free(aPtr); + } + + void reportAllocOverflow() const + { + } +}; + +} // namespace mozilla + +#endif /* mozilla_AllocPolicy_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Array.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Array.h new file mode 100644 index 0000000000..b2ab578d4b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Array.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A compile-time constant-length array with bounds-checking assertions. */ + +#ifndef mozilla_Array_h +#define mozilla_Array_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" + +#include + +namespace mozilla { + +template +class Array +{ + T mArr[Length]; + +public: + T& operator[](size_t aIndex) + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } + + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } +}; + +template +class Array +{ +public: + T& operator[](size_t aIndex) + { + MOZ_CRASH("indexing into zero-length array"); + } + + const T& operator[](size_t aIndex) const + { + MOZ_CRASH("indexing into zero-length array"); + } +}; + +} /* namespace mozilla */ + +#endif /* mozilla_Array_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/ArrayUtils.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/ArrayUtils.h new file mode 100644 index 0000000000..44f5980c44 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/ArrayUtils.h @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements various helper functions related to arrays. + */ + +#ifndef mozilla_ArrayUtils_h +#define mozilla_ArrayUtils_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" + +#include + +#ifdef __cplusplus + +#include "mozilla/Alignment.h" +#include "mozilla/Array.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +/* + * Safely subtract two pointers when it is known that aEnd >= aBegin. This + * avoids the common compiler bug that if (size_t(aEnd) - size_t(aBegin)) has + * the MSB set, the unsigned subtraction followed by right shift will produce + * -1, or size_t(-1), instead of the real difference. + */ +template +MOZ_ALWAYS_INLINE size_t +PointerRangeSize(T* aBegin, T* aEnd) +{ + MOZ_ASSERT(aEnd >= aBegin); + return (size_t(aEnd) - size_t(aBegin)) / sizeof(T); +} + +/* + * Compute the length of an array with constant length. (Use of this method + * with a non-array pointer will not compile.) + * + * Beware of the implicit trailing '\0' when using this with string constants. + */ +template +MOZ_CONSTEXPR size_t +ArrayLength(T (&aArr)[N]) +{ + return N; +} + +template +MOZ_CONSTEXPR size_t +ArrayLength(const Array& aArr) +{ + return N; +} + +/* + * Compute the address one past the last element of a constant-length array. + * + * Beware of the implicit trailing '\0' when using this with string constants. + */ +template +MOZ_CONSTEXPR T* +ArrayEnd(T (&aArr)[N]) +{ + return aArr + ArrayLength(aArr); +} + +template +MOZ_CONSTEXPR T* +ArrayEnd(Array& aArr) +{ + return &aArr[0] + ArrayLength(aArr); +} + +template +MOZ_CONSTEXPR const T* +ArrayEnd(const Array& aArr) +{ + return &aArr[0] + ArrayLength(aArr); +} + +namespace detail { + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % MOZ_ALIGNOF(AlignType)) == 0, + "performing a range-check with a misaligned pointer"); + } +}; + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + } +}; + +} // namespace detail + +/** + * Determines whether |aPtr| points at an object in the range [aBegin, aEnd). + * + * |aPtr| must have the same alignment as |aBegin| and |aEnd|. This usually + * should be achieved by ensuring |aPtr| points at a |U|, not just that it + * points at a |T|. + * + * It is a usage error for any argument to be misaligned. + * + * It's okay for T* to be void*, and if so U* may also be void*. In the latter + * case no argument is required to be aligned (obviously, as void* implies no + * particular alignment). + */ +template +inline typename EnableIf::value || + IsBaseOf::value || + IsVoid::value, + bool>::Type +IsInRange(T* aPtr, U* aBegin, U* aEnd) +{ + MOZ_ASSERT(aBegin <= aEnd); + detail::AlignedChecker::test(aPtr); + detail::AlignedChecker::test(aBegin); + detail::AlignedChecker::test(aEnd); + return aBegin <= static_cast(aPtr) && static_cast(aPtr) < aEnd; +} + +/** + * Convenience version of the above method when the valid range is specified as + * uintptr_t values. As above, |aPtr| must be aligned, and |aBegin| and |aEnd| + * must be aligned with respect to |T|. + */ +template +inline bool +IsInRange(T* aPtr, uintptr_t aBegin, uintptr_t aEnd) +{ + return IsInRange(aPtr, + reinterpret_cast(aBegin), reinterpret_cast(aEnd)); +} + +namespace detail { + +/* + * Helper for the MOZ_ARRAY_LENGTH() macro to make the length a typesafe + * compile-time constant even on compilers lacking constexpr support. + */ +template +char (&ArrayLengthHelper(T (&array)[N]))[N]; + +} /* namespace detail */ + +} /* namespace mozilla */ + +#endif /* __cplusplus */ + +/* + * MOZ_ARRAY_LENGTH() is an alternative to mozilla::ArrayLength() for C files + * that can't use C++ template functions and for static_assert() calls that + * can't call ArrayLength() when it is not a C++11 constexpr function. + */ +#ifdef __cplusplus +# define MOZ_ARRAY_LENGTH(array) sizeof(mozilla::detail::ArrayLengthHelper(array)) +#else +# define MOZ_ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0])) +#endif + +#endif /* mozilla_ArrayUtils_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Assertions.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Assertions.h new file mode 100644 index 0000000000..34b0d7d534 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Assertions.h @@ -0,0 +1,534 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implementations of runtime and static assertion macros for C and C++. */ + +#ifndef mozilla_Assertions_h +#define mozilla_Assertions_h +#include +#if defined(MOZILLA_INTERNAL_API) && defined(__cplusplus) +#define MOZ_DUMP_ASSERTION_STACK +#endif + +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/Likely.h" +#include "mozilla/MacroArgs.h" +#ifdef MOZ_DUMP_ASSERTION_STACK +#include "nsTraceRefcnt.h" +#endif + +#include +#include +#include +#ifdef WIN32 + /* + * TerminateProcess and GetCurrentProcess are defined in , which + * further depends on . We hardcode these few definitions manually + * because those headers clutter the global namespace with a significant + * number of undesired macros and symbols. + */ +# ifdef __cplusplus +extern "C" { +# endif +__declspec(dllimport) int __stdcall +TerminateProcess(void* hProcess, unsigned int uExitCode); +__declspec(dllimport) void* __stdcall GetCurrentProcess(void); +# ifdef __cplusplus +} +# endif +#else +# include +#endif +#ifdef ANDROID +# include +#endif + +/* + * MOZ_STATIC_ASSERT may be used to assert a condition *at compile time* in C. + * In C++11, static_assert is provided by the compiler to the same effect. + * This can be useful when you make certain assumptions about what must hold for + * optimal, or even correct, behavior. For example, you might assert that the + * size of a struct is a multiple of the target architecture's word size: + * + * struct S { ... }; + * // C + * MOZ_STATIC_ASSERT(sizeof(S) % sizeof(size_t) == 0, + * "S should be a multiple of word size for efficiency"); + * // C++11 + * static_assert(sizeof(S) % sizeof(size_t) == 0, + * "S should be a multiple of word size for efficiency"); + * + * This macro can be used in any location where both an extern declaration and a + * typedef could be used. + */ +#ifndef __cplusplus + /* + * Some of the definitions below create an otherwise-unused typedef. This + * triggers compiler warnings with some versions of gcc, so mark the typedefs + * as permissibly-unused to disable the warnings. + */ +# if defined(__GNUC__) +# define MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused)) +# else +# define MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE /* nothing */ +# endif +# define MOZ_STATIC_ASSERT_GLUE1(x, y) x##y +# define MOZ_STATIC_ASSERT_GLUE(x, y) MOZ_STATIC_ASSERT_GLUE1(x, y) +# if defined(__SUNPRO_CC) + /* + * The Sun Studio C++ compiler is buggy when declaring, inside a function, + * another extern'd function with an array argument whose length contains a + * sizeof, triggering the error message "sizeof expression not accepted as + * size of array parameter". This bug (6688515, not public yet) would hit + * defining moz_static_assert as a function, so we always define an extern + * array for Sun Studio. + * + * We include the line number in the symbol name in a best-effort attempt + * to avoid conflicts (see below). + */ +# define MOZ_STATIC_ASSERT(cond, reason) \ + extern char MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __LINE__)[(cond) ? 1 : -1] +# elif defined(__COUNTER__) + /* + * If there was no preferred alternative, use a compiler-agnostic version. + * + * Note that the non-__COUNTER__ version has a bug in C++: it can't be used + * in both |extern "C"| and normal C++ in the same translation unit. (Alas + * |extern "C"| isn't allowed in a function.) The only affected compiler + * we really care about is gcc 4.2. For that compiler and others like it, + * we include the line number in the function name to do the best we can to + * avoid conflicts. These should be rare: a conflict would require use of + * MOZ_STATIC_ASSERT on the same line in separate files in the same + * translation unit, *and* the uses would have to be in code with + * different linkage, *and* the first observed use must be in C++-linkage + * code. + */ +# define MOZ_STATIC_ASSERT(cond, reason) \ + typedef int MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __COUNTER__)[(cond) ? 1 : -1] MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE +# else +# define MOZ_STATIC_ASSERT(cond, reason) \ + extern void MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __LINE__)(int arg[(cond) ? 1 : -1]) MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE +# endif + +#define MOZ_STATIC_ASSERT_IF(cond, expr, reason) MOZ_STATIC_ASSERT(!(cond) || (expr), reason) +#else +#define MOZ_STATIC_ASSERT_IF(cond, expr, reason) static_assert(!(cond) || (expr), reason) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Prints |aStr| as an assertion failure (using aFilename and aLine as the + * location of the assertion) to the standard debug-output channel. + * + * Usually you should use MOZ_ASSERT or MOZ_CRASH instead of this method. This + * method is primarily for internal use in this header, and only secondarily + * for use in implementing release-build assertions. + */ +static MOZ_ALWAYS_INLINE void +MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS +{ +#ifdef ANDROID + __android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert", + "Assertion failure: %s, at %s:%d\n", + aStr, aFilename, aLine); +#else + fprintf(stderr, "Assertion failure: %s, at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif + fflush(stderr); +#endif +} + +static MOZ_ALWAYS_INLINE void +MOZ_ReportCrash(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS +{ +#ifdef ANDROID + __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", + "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); +#else + fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif + fflush(stderr); +#endif +} + +/** + * MOZ_REALLY_CRASH is used in the implementation of MOZ_CRASH(). You should + * call MOZ_CRASH instead. + */ +#if defined(_MSC_VER) + /* + * On MSVC use the __debugbreak compiler intrinsic, which produces an inline + * (not nested in a system function) breakpoint. This distinctively invokes + * Breakpad without requiring system library symbols on all stack-processing + * machines, as a nested breakpoint would require. + * + * We use TerminateProcess with the exit code aborting would generate + * because we don't want to invoke atexit handlers, destructors, library + * unload handlers, and so on when our process might be in a compromised + * state. + * + * We don't use abort() because it'd cause Windows to annoyingly pop up the + * process error dialog multiple times. See bug 345118 and bug 426163. + * + * We follow TerminateProcess() with a call to MOZ_NoReturn() so that the + * compiler doesn't hassle us to provide a return statement after a + * MOZ_REALLY_CRASH() call. + * + * (Technically these are Windows requirements, not MSVC requirements. But + * practically you need MSVC for debugging, and we only ship builds created + * by MSVC, so doing it this way reduces complexity.) + */ + +__declspec(noreturn) __inline void MOZ_NoReturn() {} + +# ifdef __cplusplus +# define MOZ_REALLY_CRASH() \ + do { \ + ::__debugbreak(); \ + *((volatile int*) NULL) = 123; \ + ::TerminateProcess(::GetCurrentProcess(), 3); \ + ::MOZ_NoReturn(); \ + } while (0) +# else +# define MOZ_REALLY_CRASH() \ + do { \ + __debugbreak(); \ + *((volatile int*) NULL) = 123; \ + TerminateProcess(GetCurrentProcess(), 3); \ + MOZ_NoReturn(); \ + } while (0) +# endif +#else +# ifdef __cplusplus +# define MOZ_REALLY_CRASH() \ + do { \ + *((volatile int*) NULL) = 123; \ + ::abort(); \ + } while (0) +# else +# define MOZ_REALLY_CRASH() \ + do { \ + *((volatile int*) NULL) = 123; \ + abort(); \ + } while (0) +# endif +#endif + +/* + * MOZ_CRASH([explanation-string]) crashes the program, plain and simple, in a + * Breakpad-compatible way, in both debug and release builds. + * + * MOZ_CRASH is a good solution for "handling" failure cases when you're + * unwilling or unable to handle them more cleanly -- for OOM, for likely memory + * corruption, and so on. It's also a good solution if you need safe behavior + * in release builds as well as debug builds. But if the failure is one that + * should be debugged and fixed, MOZ_ASSERT is generally preferable. + * + * The optional explanation-string, if provided, must be a string literal + * explaining why we're crashing. This argument is intended for use with + * MOZ_CRASH() calls whose rationale is non-obvious; don't use it if it's + * obvious why we're crashing. + * + * If we're a DEBUG build and we crash at a MOZ_CRASH which provides an + * explanation-string, we print the string to stderr. Otherwise, we don't + * print anything; this is because we want MOZ_CRASH to be 100% safe in release + * builds, and it's hard to print to stderr safely when memory might have been + * corrupted. + */ +#ifndef DEBUG +# define MOZ_CRASH(...) MOZ_REALLY_CRASH() +#else +# define MOZ_CRASH(...) \ + do { \ + MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } while (0) +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* + * MOZ_ASSERT(expr [, explanation-string]) asserts that |expr| must be truthy in + * debug builds. If it is, execution continues. Otherwise, an error message + * including the expression and the explanation-string (if provided) is printed, + * an attempt is made to invoke any existing debugger, and execution halts. + * MOZ_ASSERT is fatal: no recovery is possible. Do not assert a condition + * which can correctly be falsy. + * + * The optional explanation-string, if provided, must be a string literal + * explaining the assertion. It is intended for use with assertions whose + * correctness or rationale is non-obvious, and for assertions where the "real" + * condition being tested is best described prosaically. Don't provide an + * explanation if it's not actually helpful. + * + * // No explanation needed: pointer arguments often must not be NULL. + * MOZ_ASSERT(arg); + * + * // An explanation can be helpful to explain exactly how we know an + * // assertion is valid. + * MOZ_ASSERT(state == WAITING_FOR_RESPONSE, + * "given that and , we must have..."); + * + * // Or it might disambiguate multiple identical (save for their location) + * // assertions of the same expression. + * MOZ_ASSERT(getSlot(PRIMITIVE_THIS_SLOT).isUndefined(), + * "we already set [[PrimitiveThis]] for this Boolean object"); + * MOZ_ASSERT(getSlot(PRIMITIVE_THIS_SLOT).isUndefined(), + * "we already set [[PrimitiveThis]] for this String object"); + * + * MOZ_ASSERT has no effect in non-debug builds. It is designed to catch bugs + * *only* during debugging, not "in the field". If you want the latter, use + * MOZ_RELEASE_ASSERT, which applies to non-debug builds as well. + */ + +/* + * Implement MOZ_VALIDATE_ASSERT_CONDITION_TYPE, which is used to guard against + * accidentally passing something unintended in lieu of an assertion condition. + */ + +#ifdef __cplusplus +# if defined(__clang__) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# elif defined(__GNUC__) +// B2G GCC 4.4 has insufficient decltype support. +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# endif +# elif defined(_MSC_VER) +// Disabled for now because of insufficient decltype support. Bug 1004028. +# endif +#endif + +#ifdef MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# include "mozilla/TypeTraits.h" +namespace mozilla { +namespace detail { + +template +struct IsFunction +{ + static const bool value = false; +}; + +template +struct IsFunction +{ + static const bool value = true; +}; + +template +void ValidateAssertConditionType() +{ + typedef typename RemoveReference::Type ValueT; + static_assert(!IsArray::value, + "Expected boolean assertion condition, got an array or a " + "string!"); + static_assert(!IsFunction::value, + "Expected boolean assertion condition, got a function! Did " + "you intend to call that function?"); + static_assert(!IsFloatingPoint::value, + "It's often a bad idea to assert that a floating-point number " + "is nonzero, because such assertions tend to intermittently " + "fail. Shouldn't your code gracefully handle this case instead " + "of asserting? Anyway, if you really want to do that, write an " + "explicit boolean condition, like !!x or x!=0."); +} + +} // namespace detail +} // namespace mozilla +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) \ + mozilla::detail::ValidateAssertConditionType() +#else +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) +#endif + +/* First the single-argument form. */ +#define MOZ_ASSERT_HELPER1(expr) \ + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) +/* Now the two-argument form. */ +#define MOZ_ASSERT_HELPER2(expr, explain) \ + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) + +#define MOZ_RELEASE_ASSERT_GLUE(a, b) a b +#define MOZ_RELEASE_ASSERT(...) \ + MOZ_RELEASE_ASSERT_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \ + (__VA_ARGS__)) + +#ifdef DEBUG +# define MOZ_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) +#else +# define MOZ_ASSERT(...) do { } while (0) +#endif /* DEBUG */ + +/* + * MOZ_NIGHTLY_ASSERT is defined for both debug and release builds on the + * Nightly channel, but only debug builds on Aurora, Beta, and Release. + */ +#if defined(NIGHTLY_BUILD) +# define MOZ_NIGHTLY_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) +#else +# define MOZ_NIGHTLY_ASSERT(...) MOZ_ASSERT(__VA_ARGS__) +#endif + +/* + * MOZ_ASSERT_IF(cond1, cond2) is equivalent to MOZ_ASSERT(cond2) if cond1 is + * true. + * + * MOZ_ASSERT_IF(isPrime(num), num == 2 || isOdd(num)); + * + * As with MOZ_ASSERT, MOZ_ASSERT_IF has effect only in debug builds. It is + * designed to catch bugs during debugging, not "in the field". + */ +#ifdef DEBUG +# define MOZ_ASSERT_IF(cond, expr) \ + do { \ + if (cond) { \ + MOZ_ASSERT(expr); \ + } \ + } while (0) +#else +# define MOZ_ASSERT_IF(cond, expr) do { } while (0) +#endif + +/* + * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that + * it is undefined behavior for execution to reach this point. No guarantees + * are made about what will happen if this is reached at runtime. Most code + * should use MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE because it has extra + * asserts. + */ +#if defined(__clang__) +# define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable() +#elif defined(__GNUC__) + /* + * __builtin_unreachable() was implemented in gcc 4.5. If we don't have + * that, call a noreturn function; abort() will do nicely. Qualify the call + * in C++ in case there's another abort() visible in local scope. + */ +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable() +# else +# ifdef __cplusplus +# define MOZ_ASSUME_UNREACHABLE_MARKER() ::abort() +# else +# define MOZ_ASSUME_UNREACHABLE_MARKER() abort() +# endif +# endif +#elif defined(_MSC_VER) +# define MOZ_ASSUME_UNREACHABLE_MARKER() __assume(0) +#else +# ifdef __cplusplus +# define MOZ_ASSUME_UNREACHABLE_MARKER() ::abort() +# else +# define MOZ_ASSUME_UNREACHABLE_MARKER() abort() +# endif +#endif + +/* + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE([reason]) tells the compiler that it + * can assume that the macro call cannot be reached during execution. This lets + * the compiler generate better-optimized code under some circumstances, at the + * expense of the program's behavior being undefined if control reaches the + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE. + * + * In Gecko, you probably should not use this macro outside of performance- or + * size-critical code, because it's unsafe. If you don't care about code size + * or performance, you should probably use MOZ_ASSERT or MOZ_CRASH. + * + * SpiderMonkey is a different beast, and there it's acceptable to use + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE more widely. + * + * Note that MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE is noreturn, so it's valid + * not to return a value following a MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE + * call. + * + * Example usage: + * + * enum ValueType { + * VALUE_STRING, + * VALUE_INT, + * VALUE_FLOAT + * }; + * + * int ptrToInt(ValueType type, void* value) { + * { + * // We know for sure that type is either INT or FLOAT, and we want this + * // code to run as quickly as possible. + * switch (type) { + * case VALUE_INT: + * return *(int*) value; + * case VALUE_FLOAT: + * return (int) *(float*) value; + * default: + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected ValueType"); + * } + * } + */ + +/* + * Assert in all debug builds plus the Nightly channel's release builds. Take + * this extra testing precaution because hitting MOZ_ASSUME_UNREACHABLE_MARKER + * could trigger exploitable undefined behavior. + */ +#define MOZ_ASSERT_UNREACHABLE(reason) \ + MOZ_NIGHTLY_ASSERT(false, "MOZ_ASSERT_UNREACHABLE: " reason) + +#define MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) \ + do { \ + MOZ_ASSERT_UNREACHABLE(reason); \ + MOZ_ASSUME_UNREACHABLE_MARKER(); \ + } while (0) + +/* + * TODO: Bug 990764: Audit all MOZ_ASSUME_UNREACHABLE calls and replace them + * with MOZ_ASSERT_UNREACHABLE, MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE, or + * MOZ_CRASH. For now, preserve the macro's same meaning of unreachable. + */ +#define MOZ_ASSUME_UNREACHABLE(reason) \ + MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) + +/* + * MOZ_ALWAYS_TRUE(expr) and MOZ_ALWAYS_FALSE(expr) always evaluate the provided + * expression, in debug builds and in release builds both. Then, in debug + * builds only, the value of the expression is asserted either true or false + * using MOZ_ASSERT. + */ +#ifdef DEBUG +# define MOZ_ALWAYS_TRUE(expr) MOZ_ASSERT((expr)) +# define MOZ_ALWAYS_FALSE(expr) MOZ_ASSERT(!(expr)) +#else +# define MOZ_ALWAYS_TRUE(expr) ((void)(expr)) +# define MOZ_ALWAYS_FALSE(expr) ((void)(expr)) +#endif + +#undef MOZ_DUMP_ASSERTION_STACK + +#endif /* mozilla_Assertions_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Atomics.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Atomics.h new file mode 100644 index 0000000000..71d95c61ba --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Atomics.h @@ -0,0 +1,1171 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements (almost always) lock-free atomic operations. The operations here + * are a subset of that which can be found in C++11's header, with a + * different API to enforce consistent memory ordering constraints. + * + * Anyone caught using |volatile| for inter-thread memory safety needs to be + * sent a copy of this header and the C++11 standard. + */ + +#ifndef mozilla_Atomics_h +#define mozilla_Atomics_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/TypeTraits.h" + +#include + +/* + * Our minimum deployment target on clang/OS X is OS X 10.6, whose SDK + * does not have . So be sure to check for support + * along with C++0x support. + */ +#if defined(__clang__) || defined(__GNUC__) + /* + * Clang doesn't like from libstdc++ before 4.7 due to the + * loose typing of the atomic builtins. GCC 4.5 and 4.6 lacks inline + * definitions for unspecialized std::atomic and causes linking errors. + * Therefore, we require at least 4.7.0 for using libstdc++. + */ +# if MOZ_USING_LIBSTDCXX && MOZ_LIBSTDCXX_VERSION_AT_LEAST(4, 7, 0) +# define MOZ_HAVE_CXX11_ATOMICS +# elif MOZ_USING_LIBCXX +# define MOZ_HAVE_CXX11_ATOMICS +# endif +#elif defined(_MSC_VER) && _MSC_VER >= 1700 +# if defined(DEBUG) + /* + * Provide our own failure code since we're having trouble linking to + * std::_Debug_message (bug 982310). + */ +# define _INVALID_MEMORY_ORDER MOZ_CRASH("Invalid memory order") +# endif +# define MOZ_HAVE_CXX11_ATOMICS +#endif + +namespace mozilla { + +/** + * An enum of memory ordering possibilities for atomics. + * + * Memory ordering is the observable state of distinct values in memory. + * (It's a separate concept from atomicity, which concerns whether an + * operation can ever be observed in an intermediate state. Don't + * conflate the two!) Given a sequence of operations in source code on + * memory, it is *not* always the case that, at all times and on all + * cores, those operations will appear to have occurred in that exact + * sequence. First, the compiler might reorder that sequence, if it + * thinks another ordering will be more efficient. Second, the CPU may + * not expose so consistent a view of memory. CPUs will often perform + * their own instruction reordering, above and beyond that performed by + * the compiler. And each core has its own memory caches, and accesses + * (reads and writes both) to "memory" may only resolve to out-of-date + * cache entries -- not to the "most recently" performed operation in + * some global sense. Any access to a value that may be used by + * multiple threads, potentially across multiple cores, must therefore + * have a memory ordering imposed on it, for all code on all + * threads/cores to have a sufficiently coherent worldview. + * + * http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync and + * http://en.cppreference.com/w/cpp/atomic/memory_order go into more + * detail on all this, including examples of how each mode works. + * + * Note that for simplicity and practicality, not all of the modes in + * C++11 are supported. The missing C++11 modes are either subsumed by + * the modes we provide below, or not relevant for the CPUs we support + * in Gecko. These three modes are confusing enough as it is! + */ +enum MemoryOrdering { + /* + * Relaxed ordering is the simplest memory ordering: none at all. + * When the result of a write is observed, nothing may be inferred + * about other memory. Writes ostensibly performed "before" on the + * writing thread may not yet be visible. Writes performed "after" on + * the writing thread may already be visible, if the compiler or CPU + * reordered them. (The latter can happen if reads and/or writes get + * held up in per-processor caches.) Relaxed ordering means + * operations can always use cached values (as long as the actual + * updates to atomic values actually occur, correctly, eventually), so + * it's usually the fastest sort of atomic access. For this reason, + * *it's also the most dangerous kind of access*. + * + * Relaxed ordering is good for things like process-wide statistics + * counters that don't need to be consistent with anything else, so + * long as updates themselves are atomic. (And so long as any + * observations of that value can tolerate being out-of-date -- if you + * need some sort of up-to-date value, you need some sort of other + * synchronizing operation.) It's *not* good for locks, mutexes, + * reference counts, etc. that mediate access to other memory, or must + * be observably consistent with other memory. + * + * x86 architectures don't take advantage of the optimization + * opportunities that relaxed ordering permits. Thus it's possible + * that using relaxed ordering will "work" on x86 but fail elsewhere + * (ARM, say, which *does* implement non-sequentially-consistent + * relaxed ordering semantics). Be extra-careful using relaxed + * ordering if you can't easily test non-x86 architectures! + */ + Relaxed, + + /* + * When an atomic value is updated with ReleaseAcquire ordering, and + * that new value is observed with ReleaseAcquire ordering, prior + * writes (atomic or not) are also observable. What ReleaseAcquire + * *doesn't* give you is any observable ordering guarantees for + * ReleaseAcquire-ordered operations on different objects. For + * example, if there are two cores that each perform ReleaseAcquire + * operations on separate objects, each core may or may not observe + * the operations made by the other core. The only way the cores can + * be synchronized with ReleaseAcquire is if they both + * ReleaseAcquire-access the same object. This implies that you can't + * necessarily describe some global total ordering of ReleaseAcquire + * operations. + * + * ReleaseAcquire ordering is good for (as the name implies) atomic + * operations on values controlling ownership of things: reference + * counts, mutexes, and the like. However, if you are thinking about + * using these to implement your own locks or mutexes, you should take + * a good, hard look at actual lock or mutex primitives first. + */ + ReleaseAcquire, + + /* + * When an atomic value is updated with SequentiallyConsistent + * ordering, all writes observable when the update is observed, just + * as with ReleaseAcquire ordering. But, furthermore, a global total + * ordering of SequentiallyConsistent operations *can* be described. + * For example, if two cores perform SequentiallyConsistent operations + * on separate objects, one core will observably perform its update + * (and all previous operations will have completed), then the other + * core will observably perform its update (and all previous + * operations will have completed). (Although those previous + * operations aren't themselves ordered -- they could be intermixed, + * or ordered if they occur on atomic values with ordering + * requirements.) SequentiallyConsistent is the *simplest and safest* + * ordering of atomic operations -- it's always as if one operation + * happens, then another, then another, in some order -- and every + * core observes updates to happen in that single order. Because it + * has the most synchronization requirements, operations ordered this + * way also tend to be slowest. + * + * SequentiallyConsistent ordering can be desirable when multiple + * threads observe objects, and they all have to agree on the + * observable order of changes to them. People expect + * SequentiallyConsistent ordering, even if they shouldn't, when + * writing code, atomic or otherwise. SequentiallyConsistent is also + * the ordering of choice when designing lockless data structures. If + * you don't know what order to use, use this one. + */ + SequentiallyConsistent, +}; + +} // namespace mozilla + +// Build up the underlying intrinsics. +#ifdef MOZ_HAVE_CXX11_ATOMICS + +# include + +namespace mozilla { +namespace detail { + +/* + * We provide CompareExchangeFailureOrder to work around a bug in some + * versions of GCC's header. See bug 898491. + */ +template struct AtomicOrderConstraints; + +template<> +struct AtomicOrderConstraints +{ + static const std::memory_order AtomicRMWOrder = std::memory_order_relaxed; + static const std::memory_order LoadOrder = std::memory_order_relaxed; + static const std::memory_order StoreOrder = std::memory_order_relaxed; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_relaxed; +}; + +template<> +struct AtomicOrderConstraints +{ + static const std::memory_order AtomicRMWOrder = std::memory_order_acq_rel; + static const std::memory_order LoadOrder = std::memory_order_acquire; + static const std::memory_order StoreOrder = std::memory_order_release; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_acquire; +}; + +template<> +struct AtomicOrderConstraints +{ + static const std::memory_order AtomicRMWOrder = std::memory_order_seq_cst; + static const std::memory_order LoadOrder = std::memory_order_seq_cst; + static const std::memory_order StoreOrder = std::memory_order_seq_cst; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_seq_cst; +}; + +template +struct IntrinsicBase +{ + typedef std::atomic ValueType; + typedef AtomicOrderConstraints OrderedOp; +}; + +template +struct IntrinsicMemoryOps : public IntrinsicBase +{ + typedef IntrinsicBase Base; + + static T load(const typename Base::ValueType& aPtr) + { + return aPtr.load(Base::OrderedOp::LoadOrder); + } + + static void store(typename Base::ValueType& aPtr, T aVal) + { + aPtr.store(aVal, Base::OrderedOp::StoreOrder); + } + + static T exchange(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.exchange(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static bool compareExchange(typename Base::ValueType& aPtr, + T aOldVal, T aNewVal) + { + return aPtr.compare_exchange_strong(aOldVal, aNewVal, + Base::OrderedOp::AtomicRMWOrder, + Base::OrderedOp::CompareExchangeFailureOrder); + } +}; + +template +struct IntrinsicAddSub : public IntrinsicBase +{ + typedef IntrinsicBase Base; + + static T add(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_add(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T sub(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_sub(aVal, Base::OrderedOp::AtomicRMWOrder); + } +}; + +template +struct IntrinsicAddSub : public IntrinsicBase +{ + typedef IntrinsicBase Base; + + static T* add(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_add(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } + + static T* sub(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_sub(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } +private: + /* + * GCC 4.6's header has a bug where adding X to an + * atomic is not the same as adding X to a T*. Hence the need + * for this function to provide the correct addend. + */ + static ptrdiff_t fixupAddend(ptrdiff_t aVal) + { +#if defined(__clang__) || defined(_MSC_VER) + return aVal; +#elif defined(__GNUC__) && MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) && \ + !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) + return aVal * sizeof(T); +#else + return aVal; +#endif + } +}; + +template +struct IntrinsicIncDec : public IntrinsicAddSub +{ + typedef IntrinsicBase Base; + + static T inc(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::add(aPtr, 1); + } + + static T dec(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::sub(aPtr, 1); + } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ + typedef IntrinsicBase Base; + + static T or_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_or(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T xor_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_xor(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T and_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_and(aVal, Base::OrderedOp::AtomicRMWOrder); + } +}; + +template +struct AtomicIntrinsics + : public IntrinsicMemoryOps, public IntrinsicIncDec +{ +}; + +} // namespace detail +} // namespace mozilla + +#elif defined(__GNUC__) + +namespace mozilla { +namespace detail { + +/* + * The __sync_* family of intrinsics is documented here: + * + * http://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Atomic-Builtins.html + * + * While these intrinsics are deprecated in favor of the newer __atomic_* + * family of intrincs: + * + * http://gcc.gnu.org/onlinedocs/gcc-4.7.3/gcc/_005f_005fatomic-Builtins.html + * + * any GCC version that supports the __atomic_* intrinsics will also support + * the header and so will be handled above. We provide a version of + * atomics using the __sync_* intrinsics to support older versions of GCC. + * + * All __sync_* intrinsics that we use below act as full memory barriers, for + * both compiler and hardware reordering, except for __sync_lock_test_and_set, + * which is a only an acquire barrier. When we call __sync_lock_test_and_set, + * we add a barrier above it as appropriate. + */ + +template struct Barrier; + +/* + * Some processors (in particular, x86) don't require quite so many calls to + * __sync_sychronize as our specializations of Barrier produce. If + * performance turns out to be an issue, defining these specializations + * on a per-processor basis would be a good first tuning step. + */ + +template<> +struct Barrier +{ + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} + static void afterStore() {} +}; + +template<> +struct Barrier +{ + static void beforeLoad() {} + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() {} +}; + +template<> +struct Barrier +{ + static void beforeLoad() { __sync_synchronize(); } + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() { __sync_synchronize(); } +}; + +template +struct IntrinsicMemoryOps +{ + static T load(const T& aPtr) + { + Barrier::beforeLoad(); + T val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(T& aPtr, T aVal) + { + Barrier::beforeStore(); + aPtr = aVal; + Barrier::afterStore(); + } + + static T exchange(T& aPtr, T aVal) + { + // __sync_lock_test_and_set is only an acquire barrier; loads and stores + // can't be moved up from after to before it, but they can be moved down + // from before to after it. We may want a stricter ordering, so we need + // an explicit barrier. + Barrier::beforeStore(); + return __sync_lock_test_and_set(&aPtr, aVal); + } + + static bool compareExchange(T& aPtr, T aOldVal, T aNewVal) + { + return __sync_bool_compare_and_swap(&aPtr, aOldVal, aNewVal); + } +}; + +template +struct IntrinsicAddSub +{ + typedef T ValueType; + + static T add(T& aPtr, T aVal) + { + return __sync_fetch_and_add(&aPtr, aVal); + } + + static T sub(T& aPtr, T aVal) + { + return __sync_fetch_and_sub(&aPtr, aVal); + } +}; + +template +struct IntrinsicAddSub +{ + typedef T* ValueType; + + /* + * The reinterpret_casts are needed so that + * __sync_fetch_and_{add,sub} will properly type-check. + * + * Also, these functions do not provide standard semantics for + * pointer types, so we need to adjust the addend. + */ + static ValueType add(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_add(&aPtr, amount); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_sub(&aPtr, amount); + } +}; + +template +struct IntrinsicIncDec : public IntrinsicAddSub +{ + static T inc(T& aPtr) { return IntrinsicAddSub::add(aPtr, 1); } + static T dec(T& aPtr) { return IntrinsicAddSub::sub(aPtr, 1); } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ + static T or_( T& aPtr, T aVal) { return __sync_fetch_and_or(&aPtr, aVal); } + static T xor_(T& aPtr, T aVal) { return __sync_fetch_and_xor(&aPtr, aVal); } + static T and_(T& aPtr, T aVal) { return __sync_fetch_and_and(&aPtr, aVal); } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ +}; + +} // namespace detail +} // namespace mozilla + +#elif defined(_MSC_VER) + +/* + * Windows comes with a full complement of atomic operations. + * Unfortunately, most of those aren't available for Windows XP (even if + * the compiler supports intrinsics for them), which is the oldest + * version of Windows we support. Therefore, we only provide operations + * on 32-bit datatypes for 32-bit Windows versions; for 64-bit Windows + * versions, we support 64-bit datatypes as well. + */ + +# include + +# pragma intrinsic(_InterlockedExchangeAdd) +# pragma intrinsic(_InterlockedOr) +# pragma intrinsic(_InterlockedXor) +# pragma intrinsic(_InterlockedAnd) +# pragma intrinsic(_InterlockedExchange) +# pragma intrinsic(_InterlockedCompareExchange) + +namespace mozilla { +namespace detail { + +# if !defined(_M_IX86) && !defined(_M_X64) + /* + * The implementations below are optimized for x86ish systems. You + * will have to modify them if you are porting to Windows on a + * different architecture. + */ +# error "Unknown CPU type" +# endif + +/* + * The PrimitiveIntrinsics template should define |Type|, the datatype of size + * DataSize upon which we operate, and the following eight functions. + * + * static Type add(Type* aPtr, Type aVal); + * static Type sub(Type* aPtr, Type aVal); + * static Type or_(Type* aPtr, Type aVal); + * static Type xor_(Type* aPtr, Type aVal); + * static Type and_(Type* aPtr, Type aVal); + * + * These functions perform the obvious operation on the value contained in + * |*aPtr| combined with |aVal| and return the value previously stored in + * |*aPtr|. + * + * static void store(Type* aPtr, Type aVal); + * + * This function atomically stores |aVal| into |*aPtr| and must provide a full + * memory fence after the store to prevent compiler and hardware instruction + * reordering. It should also act as a compiler barrier to prevent reads and + * writes from moving to after the store. + * + * static Type exchange(Type* aPtr, Type aVal); + * + * This function atomically stores |aVal| into |*aPtr| and returns the + * previous contents of |*aPtr|; + * + * static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal); + * + * This function atomically performs the following operation: + * + * if (*aPtr == aOldVal) { + * *aPtr = aNewVal; + * return true; + * } else { + * return false; + * } + * + */ +template struct PrimitiveIntrinsics; + +template<> +struct PrimitiveIntrinsics<4> +{ + typedef long Type; + + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * _InterlockedExchangeSubtract isn't available before Windows 7, + * and we must support Windows XP. + */ + return _InterlockedExchangeAdd(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange(aPtr, aNewVal, aOldVal) == aOldVal; + } +}; + +# if defined(_M_X64) + +# pragma intrinsic(_InterlockedExchangeAdd64) +# pragma intrinsic(_InterlockedOr64) +# pragma intrinsic(_InterlockedXor64) +# pragma intrinsic(_InterlockedAnd64) +# pragma intrinsic(_InterlockedExchange64) +# pragma intrinsic(_InterlockedCompareExchange64) + +template <> +struct PrimitiveIntrinsics<8> +{ + typedef __int64 Type; + + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd64(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * There is no _InterlockedExchangeSubtract64. + */ + return _InterlockedExchangeAdd64(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr64(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor64(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd64(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange64(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange64(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange64(aPtr, aNewVal, aOldVal) == aOldVal; + } +}; + +# endif + +# pragma intrinsic(_ReadWriteBarrier) + +template struct Barrier; + +/* + * We do not provide an afterStore method in Barrier, as Relaxed and + * ReleaseAcquire orderings do not require one, and the required barrier + * for SequentiallyConsistent is handled by PrimitiveIntrinsics. + */ + +template<> +struct Barrier +{ + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} +}; + +template<> +struct Barrier +{ + static void beforeLoad() {} + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } +}; + +template<> +struct Barrier +{ + static void beforeLoad() { _ReadWriteBarrier(); } + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } +}; + +template +struct CastHelper +{ + static PrimType toPrimType(T aVal) { return static_cast(aVal); } + static T fromPrimType(PrimType aVal) { return static_cast(aVal); } +}; + +template +struct CastHelper +{ + static PrimType toPrimType(T* aVal) { return reinterpret_cast(aVal); } + static T* fromPrimType(PrimType aVal) { return reinterpret_cast(aVal); } +}; + +template +struct IntrinsicBase +{ + typedef T ValueType; + typedef PrimitiveIntrinsics Primitives; + typedef typename Primitives::Type PrimType; + static_assert(sizeof(PrimType) == sizeof(T), + "Selection of PrimitiveIntrinsics was wrong"); + typedef CastHelper Cast; +}; + +template +struct IntrinsicMemoryOps : public IntrinsicBase +{ + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + + static ValueType load(const ValueType& aPtr) + { + Barrier::beforeLoad(); + ValueType val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(ValueType& aPtr, ValueType aVal) + { + // For SequentiallyConsistent, Primitives::store() will generate the + // proper memory fence. Everything else just needs a barrier before + // the store. + if (Order == SequentiallyConsistent) { + Primitives::store(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + } else { + Barrier::beforeStore(); + aPtr = aVal; + } + } + + static ValueType exchange(ValueType& aPtr, ValueType aVal) + { + PrimType oldval = + Primitives::exchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + return Cast::fromPrimType(oldval); + } + + static bool compareExchange(ValueType& aPtr, ValueType aOldVal, + ValueType aNewVal) + { + return Primitives::compareExchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aOldVal), + Cast::toPrimType(aNewVal)); + } +}; + +template +struct IntrinsicApplyHelper : public IntrinsicBase +{ + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + typedef PrimType (*BinaryOp)(PrimType*, PrimType); + typedef PrimType (*UnaryOp)(PrimType*); + + static ValueType applyBinaryFunction(BinaryOp aOp, ValueType& aPtr, + ValueType aVal) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + PrimType primTypeVal = Cast::toPrimType(aVal); + return Cast::fromPrimType(aOp(primTypePtr, primTypeVal)); + } + + static ValueType applyUnaryFunction(UnaryOp aOp, ValueType& aPtr) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + return Cast::fromPrimType(aOp(primTypePtr)); + } +}; + +template +struct IntrinsicAddSub : public IntrinsicApplyHelper +{ + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::add, aPtr, aVal); + } + + static ValueType sub(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::sub, aPtr, aVal); + } +}; + +template +struct IntrinsicAddSub : public IntrinsicApplyHelper +{ + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::add, aPtr, + (ValueType)(aAmount * sizeof(T))); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::sub, aPtr, + (ValueType)(aAmount * sizeof(T))); + } +}; + +template +struct IntrinsicIncDec : public IntrinsicAddSub +{ + typedef typename IntrinsicAddSub::ValueType ValueType; + static ValueType inc(ValueType& aPtr) { return add(aPtr, 1); } + static ValueType dec(ValueType& aPtr) { return sub(aPtr, 1); } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ + typedef typename IntrinsicIncDec::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType or_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::or_, aPtr, aVal); + } + + static ValueType xor_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::xor_, aPtr, aVal); + } + + static ValueType and_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::and_, aPtr, aVal); + } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ + typedef typename IntrinsicMemoryOps::ValueType ValueType; + // This is required to make us be able to build with MSVC10, for unknown + // reasons. + typedef typename IntrinsicBase::Primitives Primitives; +}; + +} // namespace detail +} // namespace mozilla + +#else +# error "Atomic compiler intrinsics are not supported on your platform" +#endif + +namespace mozilla { + +namespace detail { + +template +class AtomicBase +{ + // We only support 32-bit types on 32-bit Windows, which constrains our + // implementation elsewhere. But we support pointer-sized types everywhere. + static_assert(sizeof(T) == 4 || (sizeof(uintptr_t) == 8 && sizeof(T) == 8), + "mozilla/Atomics.h only supports 32-bit and pointer-sized types"); + +protected: + typedef typename detail::AtomicIntrinsics Intrinsics; + typename Intrinsics::ValueType mValue; + +public: + MOZ_CONSTEXPR AtomicBase() : mValue() {} + explicit MOZ_CONSTEXPR AtomicBase(T aInit) : mValue(aInit) {} + + // Note: we can't provide operator T() here because Atomic inherits + // from AtomcBase with T=uint32_t and not T=bool. If we implemented + // operator T() here, it would cause errors when comparing Atomic with + // a regular bool. + + T operator=(T aVal) + { + Intrinsics::store(mValue, aVal); + return aVal; + } + + /** + * Performs an atomic swap operation. aVal is stored and the previous + * value of this variable is returned. + */ + T exchange(T aVal) + { + return Intrinsics::exchange(mValue, aVal); + } + + /** + * Performs an atomic compare-and-swap operation and returns true if it + * succeeded. This is equivalent to atomically doing + * + * if (mValue == aOldValue) { + * mValue = aNewValue; + * return true; + * } else { + * return false; + * } + */ + bool compareExchange(T aOldValue, T aNewValue) + { + return Intrinsics::compareExchange(mValue, aOldValue, aNewValue); + } + +private: + template + AtomicBase(const AtomicBase& aCopy) MOZ_DELETE; +}; + +template +class AtomicBaseIncDec : public AtomicBase +{ + typedef typename detail::AtomicBase Base; + +public: + MOZ_CONSTEXPR AtomicBaseIncDec() : Base() {} + explicit MOZ_CONSTEXPR AtomicBaseIncDec(T aInit) : Base(aInit) {} + + using Base::operator=; + + operator T() const { return Base::Intrinsics::load(Base::mValue); } + T operator++(int) { return Base::Intrinsics::inc(Base::mValue); } + T operator--(int) { return Base::Intrinsics::dec(Base::mValue); } + T operator++() { return Base::Intrinsics::inc(Base::mValue) + 1; } + T operator--() { return Base::Intrinsics::dec(Base::mValue) - 1; } + +private: + template + AtomicBaseIncDec(const AtomicBaseIncDec& aCopy) MOZ_DELETE; +}; + +} // namespace detail + +/** + * A wrapper for a type that enforces that all memory accesses are atomic. + * + * In general, where a variable |T foo| exists, |Atomic foo| can be used in + * its place. Implementations for integral and pointer types are provided + * below. + * + * Atomic accesses are sequentially consistent by default. You should + * use the default unless you are tall enough to ride the + * memory-ordering roller coaster (if you're not sure, you aren't) and + * you have a compelling reason to do otherwise. + * + * There is one exception to the case of atomic memory accesses: providing an + * initial value of the atomic value is not guaranteed to be atomic. This is a + * deliberate design choice that enables static atomic variables to be declared + * without introducing extra static constructors. + */ +template +class Atomic; + +/** + * Atomic implementation for integral types. + * + * In addition to atomic store and load operations, compound assignment and + * increment/decrement operators are implemented which perform the + * corresponding read-modify-write operation atomically. Finally, an atomic + * swap method is provided. + */ +template +class Atomic::value && + !IsSame::value>::Type> + : public detail::AtomicBaseIncDec +{ + typedef typename detail::AtomicBaseIncDec Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + + using Base::operator=; + + T operator+=(T aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } + + T operator-=(T aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } + + T operator|=(T aVal) + { + return Base::Intrinsics::or_(Base::mValue, aVal) | aVal; + } + + T operator^=(T aVal) + { + return Base::Intrinsics::xor_(Base::mValue, aVal) ^ aVal; + } + + T operator&=(T aVal) + { + return Base::Intrinsics::and_(Base::mValue, aVal) & aVal; + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +/** + * Atomic implementation for pointer types. + * + * An atomic compare-and-swap primitive for pointer variables is provided, as + * are atomic increment and decement operators. Also provided are the compound + * assignment operators for addition and subtraction. Atomic swap (via + * exchange()) is included as well. + */ +template +class Atomic : public detail::AtomicBaseIncDec +{ + typedef typename detail::AtomicBaseIncDec Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T* aInit) : Base(aInit) {} + + using Base::operator=; + + T* operator+=(ptrdiff_t aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } + + T* operator-=(ptrdiff_t aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +/** + * Atomic implementation for enum types. + * + * The atomic store and load operations and the atomic swap method is provided. + */ +template +class Atomic::value>::Type> + : public detail::AtomicBase +{ + typedef typename detail::AtomicBase Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + + operator T() const { return Base::Intrinsics::load(Base::mValue); } + + using Base::operator=; + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +/** + * Atomic implementation for boolean types. + * + * The atomic store and load operations and the atomic swap method is provided. + * + * Note: + * + * - sizeof(Atomic) != sizeof(bool) for some implementations of + * bool and/or some implementations of std::atomic. This is allowed in + * [atomic.types.generic]p9. + * + * - It's not obvious whether the 8-bit atomic functions on Windows are always + * inlined or not. If they are not inlined, the corresponding functions in the + * runtime library are not available on Windows XP. This is why we implement + * Atomic with an underlying type of uint32_t. + */ +template +class Atomic + : protected detail::AtomicBase +{ + typedef typename detail::AtomicBase Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(bool aInit) : Base(aInit) {} + + // We provide boolean wrappers for the underlying AtomicBase methods. + operator bool() const + { + return Base::Intrinsics::load(Base::mValue); + } + + bool operator=(bool aVal) + { + return Base::operator=(aVal); + } + + bool exchange(bool aVal) + { + return Base::exchange(aVal); + } + + bool compareExchange(bool aOldValue, bool aNewValue) + { + return Base::compareExchange(aOldValue, aNewValue); + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +} // namespace mozilla + +#endif /* mozilla_Atomics_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Attributes.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Attributes.h new file mode 100644 index 0000000000..cdce8c7717 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Attributes.h @@ -0,0 +1,536 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implementations of various class and method modifier attributes. */ + +#ifndef mozilla_Attributes_h +#define mozilla_Attributes_h + +#include "mozilla/Compiler.h" + +/* + * MOZ_ALWAYS_INLINE is a macro which expands to tell the compiler that the + * method decorated with it must be inlined, even if the compiler thinks + * otherwise. This is only a (much) stronger version of the inline hint: + * compilers are not guaranteed to respect it (although they're much more likely + * to do so). + * + * The MOZ_ALWAYS_INLINE_EVEN_DEBUG macro is yet stronger. It tells the + * compiler to inline even in DEBUG builds. It should be used very rarely. + */ +#if defined(_MSC_VER) +# define MOZ_ALWAYS_INLINE_EVEN_DEBUG __forceinline +#elif defined(__GNUC__) +# define MOZ_ALWAYS_INLINE_EVEN_DEBUG __attribute__((always_inline)) inline +#else +# define MOZ_ALWAYS_INLINE_EVEN_DEBUG inline +#endif + +#if !defined(DEBUG) +# define MOZ_ALWAYS_INLINE MOZ_ALWAYS_INLINE_EVEN_DEBUG +#elif defined(_MSC_VER) && !defined(__cplusplus) +# define MOZ_ALWAYS_INLINE __inline +#else +# define MOZ_ALWAYS_INLINE inline +#endif + +#if defined(_MSC_VER) +/* + * g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality + * without warnings (functionality used by the macros below). These modes are + * detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, more + * standardly, by checking whether __cplusplus has a C++11 or greater value. + * Current versions of g++ do not correctly set __cplusplus, so we check both + * for forward compatibility. + * + * Even though some versions of MSVC support explicit conversion operators, we + * don't indicate support for them here, due to + * http://stackoverflow.com/questions/20498142/visual-studio-2013-explicit-keyword-bug + */ +# if _MSC_VER >= 1800 +# define MOZ_HAVE_CXX11_DELETE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_FINAL final +# else +# if defined(__clang__) +# error Please do not try to use clang-cl with MSVC10 or below emulation! +# endif + /* MSVC <= 10 used to spell "final" as "sealed". */ +# define MOZ_HAVE_CXX11_FINAL sealed +# endif +# define MOZ_HAVE_CXX11_OVERRIDE +# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) +# define MOZ_HAVE_NORETURN __declspec(noreturn) +#elif defined(__clang__) + /* + * Per Clang documentation, "Note that marketing version numbers should not + * be used to check for language features, as different vendors use different + * numbering schemes. Instead, use the feature checking macros." + */ +# ifndef __has_extension +# define __has_extension __has_feature /* compatibility, for older versions of clang */ +# endif +# if __has_extension(cxx_constexpr) +# define MOZ_HAVE_CXX11_CONSTEXPR +# endif +# if __has_extension(cxx_explicit_conversions) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif +# if __has_extension(cxx_deleted_functions) +# define MOZ_HAVE_CXX11_DELETE +# endif +# if __has_extension(cxx_override_control) +# define MOZ_HAVE_CXX11_OVERRIDE +# define MOZ_HAVE_CXX11_FINAL final +# endif +# if __has_attribute(noinline) +# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) +# endif +# if __has_attribute(noreturn) +# define MOZ_HAVE_NORETURN __attribute__((noreturn)) +# endif +#elif defined(__GNUC__) +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# if MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) +# define MOZ_HAVE_CXX11_OVERRIDE +# define MOZ_HAVE_CXX11_FINAL final +# endif +# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) +# define MOZ_HAVE_CXX11_CONSTEXPR +# endif +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif +# define MOZ_HAVE_CXX11_DELETE +# else + /* __final is a non-C++11 GCC synonym for 'final', per GCC r176655. */ +# if MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) +# define MOZ_HAVE_CXX11_FINAL __final +# endif +# endif +# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) +# define MOZ_HAVE_NORETURN __attribute__((noreturn)) +#endif + +/* + * When built with clang analyzer (a.k.a scan-build), define MOZ_HAVE_NORETURN + * to mark some false positives + */ +#ifdef __clang_analyzer__ +# if __has_extension(attribute_analyzer_noreturn) +# define MOZ_HAVE_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) +# endif +#endif + +/* + * The MOZ_CONSTEXPR specifier declares that a C++11 compiler can evaluate a + * function at compile time. A constexpr function cannot examine any values + * except its arguments and can have no side effects except its return value. + * The MOZ_CONSTEXPR_VAR specifier tells a C++11 compiler that a variable's + * value may be computed at compile time. It should be prefered to just + * marking variables as MOZ_CONSTEXPR because if the compiler does not support + * constexpr it will fall back to making the variable const, and some compilers + * do not accept variables being marked both const and constexpr. + */ +#ifdef MOZ_HAVE_CXX11_CONSTEXPR +# define MOZ_CONSTEXPR constexpr +# define MOZ_CONSTEXPR_VAR constexpr +#else +# define MOZ_CONSTEXPR /* no support */ +# define MOZ_CONSTEXPR_VAR const +#endif + +/* + * MOZ_EXPLICIT_CONVERSION is a specifier on a type conversion + * overloaded operator that declares that a C++11 compiler should restrict + * this operator to allow only explicit type conversions, disallowing + * implicit conversions. + * + * Example: + * + * template + * class Ptr + * { + * T* mPtr; + * MOZ_EXPLICIT_CONVERSION operator bool() const + * { + * return mPtr != nullptr; + * } + * }; + * + */ +#ifdef MOZ_HAVE_EXPLICIT_CONVERSION +# define MOZ_EXPLICIT_CONVERSION explicit +#else +# define MOZ_EXPLICIT_CONVERSION /* no support */ +#endif + +/* + * MOZ_NEVER_INLINE is a macro which expands to tell the compiler that the + * method decorated with it must never be inlined, even if the compiler would + * otherwise choose to inline the method. Compilers aren't absolutely + * guaranteed to support this, but most do. + */ +#if defined(MOZ_HAVE_NEVER_INLINE) +# define MOZ_NEVER_INLINE MOZ_HAVE_NEVER_INLINE +#else +# define MOZ_NEVER_INLINE /* no support */ +#endif + +/* + * MOZ_NORETURN, specified at the start of a function declaration, indicates + * that the given function does not return. (The function definition does not + * need to be annotated.) + * + * MOZ_NORETURN void abort(const char* msg); + * + * This modifier permits the compiler to optimize code assuming a call to such a + * function will never return. It also enables the compiler to avoid spurious + * warnings about not initializing variables, or about any other seemingly-dodgy + * operations performed after the function returns. + * + * This modifier does not affect the corresponding function's linking behavior. + */ +#if defined(MOZ_HAVE_NORETURN) +# define MOZ_NORETURN MOZ_HAVE_NORETURN +#else +# define MOZ_NORETURN /* no support */ +#endif + +/* + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS, specified at the end of a function + * declaration, indicates that for the purposes of static analysis, this + * function does not return. (The function definition does not need to be + * annotated.) + * + * MOZ_ReportCrash(const char* s, const char* file, int ln) + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS + * + * Some static analyzers, like scan-build from clang, can use this information + * to eliminate false positives. From the upstream documentation of scan-build: + * "This attribute is useful for annotating assertion handlers that actually + * can return, but for the purpose of using the analyzer we want to pretend + * that such functions do not return." + * + */ +#if defined(MOZ_HAVE_ANALYZER_NORETURN) +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS MOZ_HAVE_ANALYZER_NORETURN +#else +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS /* no support */ +#endif + +/* + * MOZ_ASAN_BLACKLIST is a macro to tell AddressSanitizer (a compile-time + * instrumentation shipped with Clang and GCC) to not instrument the annotated + * function. Furthermore, it will prevent the compiler from inlining the + * function because inlining currently breaks the blacklisting mechanism of + * AddressSanitizer. + */ +#if defined(__has_feature) +# if __has_feature(address_sanitizer) +# define MOZ_HAVE_ASAN_BLACKLIST +# endif +#elif defined(__GNUC__) +# if defined(__SANITIZE_ADDRESS__) +# define MOZ_HAVE_ASAN_BLACKLIST +# endif +#endif + +#if defined(MOZ_HAVE_ASAN_BLACKLIST) +# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) +#else +# define MOZ_ASAN_BLACKLIST /* nothing */ +#endif + +/* + * MOZ_TSAN_BLACKLIST is a macro to tell ThreadSanitizer (a compile-time + * instrumentation shipped with Clang) to not instrument the annotated function. + * Furthermore, it will prevent the compiler from inlining the function because + * inlining currently breaks the blacklisting mechanism of ThreadSanitizer. + */ +#if defined(__has_feature) +# if __has_feature(thread_sanitizer) +# define MOZ_TSAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_thread)) +# else +# define MOZ_TSAN_BLACKLIST /* nothing */ +# endif +#else +# define MOZ_TSAN_BLACKLIST /* nothing */ +#endif + +#ifdef __cplusplus + +/* + * MOZ_DELETE, specified immediately prior to the ';' terminating an undefined- + * method declaration, attempts to delete that method from the corresponding + * class. An attempt to use the method will always produce an error *at compile + * time* (instead of sometimes as late as link time) when this macro can be + * implemented. For example, you can use MOZ_DELETE to produce classes with no + * implicit copy constructor or assignment operator: + * + * struct NonCopyable + * { + * private: + * NonCopyable(const NonCopyable& aOther) MOZ_DELETE; + * void operator=(const NonCopyable& aOther) MOZ_DELETE; + * }; + * + * If MOZ_DELETE can't be implemented for the current compiler, use of the + * annotated method will still cause an error, but the error might occur at link + * time in some cases rather than at compile time. + * + * MOZ_DELETE relies on C++11 functionality not universally implemented. As a + * backstop, method declarations using MOZ_DELETE should be private. + */ +#if defined(MOZ_HAVE_CXX11_DELETE) +# define MOZ_DELETE = delete +#else +# define MOZ_DELETE /* no support */ +#endif + +/* + * MOZ_OVERRIDE explicitly indicates that a virtual member function in a class + * overrides a member function of a base class, rather than potentially being a + * new member function. MOZ_OVERRIDE should be placed immediately before the + * ';' terminating the member function's declaration, or before '= 0;' if the + * member function is pure. If the member function is defined in the class + * definition, it should appear before the opening brace of the function body. + * + * class Base + * { + * public: + * virtual void f() = 0; + * }; + * class Derived1 : public Base + * { + * public: + * virtual void f() MOZ_OVERRIDE; + * }; + * class Derived2 : public Base + * { + * public: + * virtual void f() MOZ_OVERRIDE = 0; + * }; + * class Derived3 : public Base + * { + * public: + * virtual void f() MOZ_OVERRIDE { } + * }; + * + * In compilers supporting C++11 override controls, MOZ_OVERRIDE *requires* that + * the function marked with it override a member function of a base class: it + * is a compile error if it does not. Otherwise MOZ_OVERRIDE does not affect + * semantics and merely documents the override relationship to the reader (but + * of course must still be used correctly to not break C++11 compilers). + */ +#if defined(MOZ_HAVE_CXX11_OVERRIDE) +# define MOZ_OVERRIDE override +#else +# define MOZ_OVERRIDE /* no support */ +#endif + +/* + * MOZ_FINAL indicates that some functionality cannot be overridden through + * inheritance. It can be used to annotate either classes/structs or virtual + * member functions. + * + * To annotate a class/struct with MOZ_FINAL, place MOZ_FINAL immediately after + * the name of the class, before the list of classes from which it derives (if + * any) and before its opening brace. MOZ_FINAL must not be used to annotate + * unnamed classes or structs. (With some compilers, and with C++11 proper, the + * underlying expansion is ambiguous with specifying a class name.) + * + * class Base MOZ_FINAL + * { + * public: + * Base(); + * ~Base(); + * virtual void f() { } + * }; + * // This will be an error in some compilers: + * class Derived : public Base + * { + * public: + * ~Derived() { } + * }; + * + * One particularly common reason to specify MOZ_FINAL upon a class is to tell + * the compiler that it's not dangerous for it to have a non-virtual destructor + * yet have one or more virtual functions, silencing the warning it might emit + * in this case. Suppose Base above weren't annotated with MOZ_FINAL. Because + * ~Base() is non-virtual, an attempt to delete a Derived* through a Base* + * wouldn't call ~Derived(), so any cleanup ~Derived() might do wouldn't happen. + * (Formally C++ says behavior is undefined, but compilers will likely just call + * ~Base() and not ~Derived().) Specifying MOZ_FINAL tells the compiler that + * it's safe for the destructor to be non-virtual. + * + * In compilers implementing final controls, it is an error to inherit from a + * class annotated with MOZ_FINAL. In other compilers it serves only as + * documentation. + * + * To annotate a virtual member function with MOZ_FINAL, place MOZ_FINAL + * immediately before the ';' terminating the member function's declaration, or + * before '= 0;' if the member function is pure. If the member function is + * defined in the class definition, it should appear before the opening brace of + * the function body. (This placement is identical to that for MOZ_OVERRIDE. + * If both are used, they should appear in the order 'MOZ_FINAL MOZ_OVERRIDE' + * for consistency.) + * + * class Base + * { + * public: + * virtual void f() MOZ_FINAL; + * }; + * class Derived + * { + * public: + * // This will be an error in some compilers: + * virtual void f(); + * }; + * + * In compilers implementing final controls, it is an error for a derived class + * to override a method annotated with MOZ_FINAL. In other compilers it serves + * only as documentation. + */ +#if defined(MOZ_HAVE_CXX11_FINAL) +# define MOZ_FINAL MOZ_HAVE_CXX11_FINAL +#else +# define MOZ_FINAL /* no support */ +#endif + +/** + * MOZ_WARN_UNUSED_RESULT tells the compiler to emit a warning if a function's + * return value is not used by the caller. + * + * Place this attribute at the very beginning of a function definition. For + * example, write + * + * MOZ_WARN_UNUSED_RESULT int foo(); + * + * or + * + * MOZ_WARN_UNUSED_RESULT int foo() { return 42; } + */ +#if defined(__GNUC__) || defined(__clang__) +# define MOZ_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) +#else +# define MOZ_WARN_UNUSED_RESULT +#endif + +/* + * The following macros are attributes that support the static analysis plugin + * included with Mozilla, and will be implemented (when such support is enabled) + * as C++11 attributes. Since such attributes are legal pretty much everywhere + * and have subtly different semantics depending on their placement, the + * following is a guide on where to place the attributes. + * + * Attributes that apply to a struct or class precede the name of the class: + * (Note that this is different from the placement of MOZ_FINAL for classes!) + * + * class MOZ_CLASS_ATTRIBUTE SomeClass {}; + * + * Attributes that apply to functions follow the parentheses and const + * qualifiers but precede MOZ_FINAL, MOZ_OVERRIDE and the function body: + * + * void DeclaredFunction() MOZ_FUNCTION_ATTRIBUTE; + * void SomeFunction() MOZ_FUNCTION_ATTRIBUTE {} + * void PureFunction() const MOZ_FUNCTION_ATTRIBUTE = 0; + * void OverriddenFunction() MOZ_FUNCTION_ATTIRBUTE MOZ_OVERRIDE; + * + * Attributes that apply to variables or parameters follow the variable's name: + * + * int variable MOZ_VARIABLE_ATTRIBUTE; + * + * Attributes that apply to types follow the type name: + * + * typedef int MOZ_TYPE_ATTRIBUTE MagicInt; + * int MOZ_TYPE_ATTRIBUTE someVariable; + * int* MOZ_TYPE_ATTRIBUTE magicPtrInt; + * int MOZ_TYPE_ATTRIBUTE* ptrToMagicInt; + * + * Attributes that apply to statements precede the statement: + * + * MOZ_IF_ATTRIBUTE if (x == 0) + * MOZ_DO_ATTRIBUTE do { } while (0); + * + * Attributes that apply to labels precede the label: + * + * MOZ_LABEL_ATTRIBUTE target: + * goto target; + * MOZ_CASE_ATTRIBUTE case 5: + * MOZ_DEFAULT_ATTRIBUTE default: + * + * The static analyses that are performed by the plugin are as follows: + * + * MOZ_MUST_OVERRIDE: Applies to all C++ member functions. All immediate + * subclasses must provide an exact override of this method; if a subclass + * does not override this method, the compiler will emit an error. This + * attribute is not limited to virtual methods, so if it is applied to a + * nonvirtual method and the subclass does not provide an equivalent + * definition, the compiler will emit an error. + * MOZ_STACK_CLASS: Applies to all classes. Any class with this annotation is + * expected to live on the stack, so it is a compile-time error to use it, or + * an array of such objects, as a global or static variable, or as the type of + * a new expression (unless placement new is being used). If a member of + * another class uses this class, or if another class inherits from this + * class, then it is considered to be a stack class as well, although this + * attribute need not be provided in such cases. + * MOZ_NONHEAP_CLASS: Applies to all classes. Any class with this annotation is + * expected to live on the stack or in static storage, so it is a compile-time + * error to use it, or an array of such objects, as the type of a new + * expression (unless placement new is being used). If a member of another + * class uses this class, or if another class inherits from this class, then + * it is considered to be a non-heap class as well, although this attribute + * need not be provided in such cases. + * MOZ_HEAP_ALLOCATOR: Applies to any function. This indicates that the return + * value is allocated on the heap, and will as a result check such allocations + * during MOZ_STACK_CLASS and MOZ_NONHEAP_CLASS annotation checking. + * MOZ_IMPLICIT: Applies to constructors. Implicit conversion constructors + * are disallowed by default unless they are marked as MOZ_IMPLICIT. This + * attribute must be used for constructors which intend to provide implicit + * conversions. + */ +#ifdef MOZ_CLANG_PLUGIN +# define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override"))) +# define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class"))) +# define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class"))) +# define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) +/* + * It turns out that clang doesn't like void func() __attribute__ {} without a + * warning, so use pragmas to disable the warning. This code won't work on GCC + * anyways, so the warning is safe to ignore. + */ +# define MOZ_HEAP_ALLOCATOR \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((annotate("moz_heap_allocator"))) \ + _Pragma("clang diagnostic pop") +#else +# define MOZ_MUST_OVERRIDE /* nothing */ +# define MOZ_STACK_CLASS /* nothing */ +# define MOZ_NONHEAP_CLASS /* nothing */ +# define MOZ_IMPLICIT /* nothing */ +# define MOZ_HEAP_ALLOCATOR /* nothing */ +#endif /* MOZ_CLANG_PLUGIN */ + +/* + * MOZ_THIS_IN_INITIALIZER_LIST is used to avoid a warning when we know that + * it's safe to use 'this' in an initializer list. + */ +#ifdef _MSC_VER +# define MOZ_THIS_IN_INITIALIZER_LIST() \ + __pragma(warning(push)) \ + __pragma(warning(disable:4355)) \ + this \ + __pragma(warning(pop)) +#else +# define MOZ_THIS_IN_INITIALIZER_LIST() this +#endif + +#endif /* __cplusplus */ + +#endif /* mozilla_Attributes_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/BloomFilter.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/BloomFilter.h new file mode 100644 index 0000000000..6757e41181 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/BloomFilter.h @@ -0,0 +1,256 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * A counting Bloom filter implementation. This allows consumers to + * do fast probabilistic "is item X in set Y?" testing which will + * never answer "no" when the correct answer is "yes" (but might + * incorrectly answer "yes" when the correct answer is "no"). + */ + +#ifndef mozilla_BloomFilter_h +#define mozilla_BloomFilter_h + +#include "mozilla/Assertions.h" +#include "mozilla/Likely.h" + +#include +#include + +namespace mozilla { + +/* + * This class implements a counting Bloom filter as described at + * , with + * 8-bit counters. This allows quick probabilistic answers to the + * question "is object X in set Y?" where the contents of Y might not + * be time-invariant. The probabilistic nature of the test means that + * sometimes the answer will be "yes" when it should be "no". If the + * answer is "no", then X is guaranteed not to be in Y. + * + * The filter is parametrized on KeySize, which is the size of the key + * generated by each of hash functions used by the filter, in bits, + * and the type of object T being added and removed. T must implement + * a |uint32_t hash() const| method which returns a uint32_t hash key + * that will be used to generate the two separate hash functions for + * the Bloom filter. This hash key MUST be well-distributed for good + * results! KeySize is not allowed to be larger than 16. + * + * The filter uses exactly 2**KeySize bytes of memory. From now on we + * will refer to the memory used by the filter as M. + * + * The expected rate of incorrect "yes" answers depends on M and on + * the number N of objects in set Y. As long as N is small compared + * to M, the rate of such answers is expected to be approximately + * 4*(N/M)**2 for this filter. In practice, if Y has a few hundred + * elements then using a KeySize of 12 gives a reasonably low + * incorrect answer rate. A KeySize of 12 has the additional benefit + * of using exactly one page for the filter in typical hardware + * configurations. + */ + +template +class BloomFilter +{ + /* + * A counting Bloom filter with 8-bit counters. For now we assume + * that having two hash functions is enough, but we may revisit that + * decision later. + * + * The filter uses an array with 2**KeySize entries. + * + * Assuming a well-distributed hash function, a Bloom filter with + * array size M containing N elements and + * using k hash function has expected false positive rate exactly + * + * $ (1 - (1 - 1/M)^{kN})^k $ + * + * because each array slot has a + * + * $ (1 - 1/M)^{kN} $ + * + * chance of being 0, and the expected false positive rate is the + * probability that all of the k hash functions will hit a nonzero + * slot. + * + * For reasonable assumptions (M large, kN large, which should both + * hold if we're worried about false positives) about M and kN this + * becomes approximately + * + * $$ (1 - \exp(-kN/M))^k $$ + * + * For our special case of k == 2, that's $(1 - \exp(-2N/M))^2$, + * or in other words + * + * $$ N/M = -0.5 * \ln(1 - \sqrt(r)) $$ + * + * where r is the false positive rate. This can be used to compute + * the desired KeySize for a given load N and false positive rate r. + * + * If N/M is assumed small, then the false positive rate can + * further be approximated as 4*N^2/M^2. So increasing KeySize by + * 1, which doubles M, reduces the false positive rate by about a + * factor of 4, and a false positive rate of 1% corresponds to + * about M/N == 20. + * + * What this means in practice is that for a few hundred keys using a + * KeySize of 12 gives false positive rates on the order of 0.25-4%. + * + * Similarly, using a KeySize of 10 would lead to a 4% false + * positive rate for N == 100 and to quite bad false positive + * rates for larger N. + */ +public: + BloomFilter() + { + static_assert(KeySize <= kKeyShift, "KeySize too big"); + + // Should we have a custom operator new using calloc instead and + // require that we're allocated via the operator? + clear(); + } + + /* + * Clear the filter. This should be done before reusing it, because + * just removing all items doesn't clear counters that hit the upper + * bound. + */ + void clear(); + + /* + * Add an item to the filter. + */ + void add(const T* aValue); + + /* + * Remove an item from the filter. + */ + void remove(const T* aValue); + + /* + * Check whether the filter might contain an item. This can + * sometimes return true even if the item is not in the filter, + * but will never return false for items that are actually in the + * filter. + */ + bool mightContain(const T* aValue) const; + + /* + * Methods for add/remove/contain when we already have a hash computed + */ + void add(uint32_t aHash); + void remove(uint32_t aHash); + bool mightContain(uint32_t aHash) const; + +private: + static const size_t kArraySize = (1 << KeySize); + static const uint32_t kKeyMask = (1 << KeySize) - 1; + static const uint32_t kKeyShift = 16; + + static uint32_t hash1(uint32_t aHash) + { + return aHash & kKeyMask; + } + static uint32_t hash2(uint32_t aHash) + { + return (aHash >> kKeyShift) & kKeyMask; + } + + uint8_t& firstSlot(uint32_t aHash) + { + return mCounters[hash1(aHash)]; + } + uint8_t& secondSlot(uint32_t aHash) + { + return mCounters[hash2(aHash)]; + } + + const uint8_t& firstSlot(uint32_t aHash) const + { + return mCounters[hash1(aHash)]; + } + const uint8_t& secondSlot(uint32_t aHash) const + { + return mCounters[hash2(aHash)]; + } + + static bool full(const uint8_t& aSlot) { return aSlot == UINT8_MAX; } + + uint8_t mCounters[kArraySize]; +}; + +template +inline void +BloomFilter::clear() +{ + memset(mCounters, 0, kArraySize); +} + +template +inline void +BloomFilter::add(uint32_t aHash) +{ + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { + ++slot1; + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { + ++slot2; + } +} + +template +MOZ_ALWAYS_INLINE void +BloomFilter::add(const T* aValue) +{ + uint32_t hash = aValue->hash(); + return add(hash); +} + +template +inline void +BloomFilter::remove(uint32_t aHash) +{ + // If the slots are full, we don't know whether we bumped them to be + // there when we added or not, so just leave them full. + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { + --slot1; + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { + --slot2; + } +} + +template +MOZ_ALWAYS_INLINE void +BloomFilter::remove(const T* aValue) +{ + uint32_t hash = aValue->hash(); + remove(hash); +} + +template +MOZ_ALWAYS_INLINE bool +BloomFilter::mightContain(uint32_t aHash) const +{ + // Check that all the slots for this hash contain something + return firstSlot(aHash) && secondSlot(aHash); +} + +template +MOZ_ALWAYS_INLINE bool +BloomFilter::mightContain(const T* aValue) const +{ + uint32_t hash = aValue->hash(); + return mightContain(hash); +} + +} // namespace mozilla + +#endif /* mozilla_BloomFilter_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Casting.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Casting.h new file mode 100644 index 0000000000..dc449af6b6 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Casting.h @@ -0,0 +1,221 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Cast operations to supplement the built-in casting operations. */ + +#ifndef mozilla_Casting_h +#define mozilla_Casting_h + +#include "mozilla/Assertions.h" +#include "mozilla/TypeTraits.h" + +#include + +namespace mozilla { + +/** + * Return a value of type |To|, containing the underlying bit pattern of + * |aFrom|. + * + * |To| and |From| must be types of the same size; be careful of cross-platform + * size differences, or this might fail to compile on some but not all + * platforms. + */ +template +inline To +BitwiseCast(const From aFrom) +{ + static_assert(sizeof(From) == sizeof(To), + "To and From must have the same size"); + union + { + From mFrom; + To mTo; + } u; + u.mFrom = aFrom; + return u.mTo; +} + +namespace detail { + +enum ToSignedness { ToIsSigned, ToIsUnsigned }; +enum FromSignedness { FromIsSigned, FromIsUnsigned }; + +template::value ? FromIsSigned : FromIsUnsigned, + ToSignedness = IsSigned::value ? ToIsSigned : ToIsUnsigned> +struct BoundsCheckImpl; + +// Implicit conversions on operands to binary operations make this all a bit +// hard to verify. Attempt to ease the pain below by *only* comparing values +// that are obviously the same type (and will undergo no further conversions), +// even when it's not strictly necessary, for explicitness. + +enum UUComparison { FromIsBigger, FromIsNotBigger }; + +// Unsigned-to-unsigned range check + +template sizeof(To)) + ? FromIsBigger + : FromIsNotBigger> +struct UnsignedUnsignedCheck; + +template +struct UnsignedUnsignedCheck +{ +public: + static bool checkBounds(const From aFrom) + { + return aFrom <= From(To(-1)); + } +}; + +template +struct UnsignedUnsignedCheck +{ +public: + static bool checkBounds(const From aFrom) + { + return true; + } +}; + +template +struct BoundsCheckImpl +{ +public: + static bool checkBounds(const From aFrom) + { + return UnsignedUnsignedCheck::checkBounds(aFrom); + } +}; + +// Signed-to-unsigned range check + +template +struct BoundsCheckImpl +{ +public: + static bool checkBounds(const From aFrom) + { + if (aFrom < 0) { + return false; + } + if (sizeof(To) >= sizeof(From)) { + return true; + } + return aFrom <= From(To(-1)); + } +}; + +// Unsigned-to-signed range check + +enum USComparison { FromIsSmaller, FromIsNotSmaller }; + +template +struct UnsignedSignedCheck; + +template +struct UnsignedSignedCheck +{ +public: + static bool checkBounds(const From aFrom) + { + return true; + } +}; + +template +struct UnsignedSignedCheck +{ +public: + static bool checkBounds(const From aFrom) + { + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + return aFrom <= From(MaxValue); + } +}; + +template +struct BoundsCheckImpl +{ +public: + static bool checkBounds(const From aFrom) + { + return UnsignedSignedCheck::checkBounds(aFrom); + } +}; + +// Signed-to-signed range check + +template +struct BoundsCheckImpl +{ +public: + static bool checkBounds(const From aFrom) + { + if (sizeof(From) <= sizeof(To)) { + return true; + } + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + const To MinValue = -MaxValue - To(1); + return From(MinValue) <= aFrom && + From(aFrom) <= From(MaxValue); + } +}; + +template::value && + IsIntegral::value> +class BoundsChecker; + +template +class BoundsChecker +{ +public: + static bool checkBounds(const From aFrom) { return true; } +}; + +template +class BoundsChecker +{ +public: + static bool checkBounds(const From aFrom) + { + return BoundsCheckImpl::checkBounds(aFrom); + } +}; + +template +inline bool +IsInBounds(const From aFrom) +{ + return BoundsChecker::checkBounds(aFrom); +} + +} // namespace detail + +/** + * Cast a value of integral type |From| to a value of integral type |To|, + * asserting that the cast will be a safe cast per C++ (that is, that |to| is in + * the range of values permitted for the type |From|). + */ +template +inline To +SafeCast(const From aFrom) +{ + MOZ_ASSERT((detail::IsInBounds(aFrom))); + return static_cast(aFrom); +} + +} // namespace mozilla + +#endif /* mozilla_Casting_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Char16.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Char16.h new file mode 100644 index 0000000000..e54eb0d5c8 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Char16.h @@ -0,0 +1,192 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implements a UTF-16 character type. */ + +#ifndef mozilla_Char16_h +#define mozilla_Char16_h + +#ifdef __cplusplus + +/* + * C++11 introduces a char16_t type and support for UTF-16 string and character + * literals. C++11's char16_t is a distinct builtin type. Technically, char16_t + * is a 16-bit code unit of a Unicode code point, not a "character". + */ + +#ifdef _MSC_VER + /* + * C++11 says char16_t is a distinct builtin type, but Windows's yvals.h + * typedefs char16_t as an unsigned short. We would like to alias char16_t + * to Windows's 16-bit wchar_t so we can declare UTF-16 literals as constant + * expressions (and pass char16_t pointers to Windows APIs). We #define + * _CHAR16T here in order to prevent yvals.h from overriding our char16_t + * typedefs, which we set to wchar_t for C++ code. + * + * In addition, #defining _CHAR16T will prevent yvals.h from defining a + * char32_t type, so we have to undo that damage here and provide our own, + * which is identical to the yvals.h type. + */ +# define MOZ_UTF16_HELPER(s) L##s +# define _CHAR16T +typedef wchar_t char16_t; +typedef unsigned int char32_t; +#else + /* C++11 has a builtin char16_t type. */ +# define MOZ_UTF16_HELPER(s) u##s + /** + * This macro is used to distinguish when char16_t would be a distinct + * typedef from wchar_t. + */ +# define MOZ_CHAR16_IS_NOT_WCHAR +# ifdef WIN32 +# define MOZ_USE_CHAR16_WRAPPER +# endif +#endif + +#ifdef MOZ_USE_CHAR16_WRAPPER +# include + /** + * Win32 API extensively uses wchar_t, which is represented by a separated + * builtin type than char16_t per spec. It's not the case for MSVC, but GCC + * follows the spec. We want to mix wchar_t and char16_t on Windows builds. + * This class is supposed to make it easier. It stores char16_t const pointer, + * but provides implicit casts for wchar_t as well. On other platforms, we + * simply use |typedef const char16_t* char16ptr_t|. Here, we want to make + * the class as similar to this typedef, including providing some casts that + * are allowed by the typedef. + */ +class char16ptr_t +{ +private: + const char16_t* mPtr; + static_assert(sizeof(char16_t) == sizeof(wchar_t), + "char16_t and wchar_t sizes differ"); + +public: + char16ptr_t(const char16_t* aPtr) : mPtr(aPtr) {} + char16ptr_t(const wchar_t* aPtr) : + mPtr(reinterpret_cast(aPtr)) + {} + + /* Without this, nullptr assignment would be ambiguous. */ + constexpr char16ptr_t(decltype(nullptr)) : mPtr(nullptr) {} + + operator const char16_t*() const + { + return mPtr; + } + operator const wchar_t*() const + { + return reinterpret_cast(mPtr); + } + operator const void*() const + { + return mPtr; + } + operator bool() const + { + return mPtr != nullptr; + } + operator std::wstring() const + { + return std::wstring(static_cast(*this)); + } + + /* Explicit cast operators to allow things like (char16_t*)str. */ + explicit operator char16_t*() const + { + return const_cast(mPtr); + } + explicit operator wchar_t*() const + { + return const_cast(static_cast(*this)); + } + + /** + * Some Windows API calls accept BYTE* but require that data actually be + * WCHAR*. Supporting this requires explicit operators to support the + * requisite explicit casts. + */ + explicit operator const char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator const unsigned char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator unsigned char*() const + { + return + const_cast(reinterpret_cast(mPtr)); + } + explicit operator void*() const + { + return const_cast(mPtr); + } + + /* Some operators used on pointers. */ + char16_t operator[](size_t aIndex) const + { + return mPtr[aIndex]; + } + bool operator==(const char16ptr_t& aOther) const + { + return mPtr == aOther.mPtr; + } + bool operator==(decltype(nullptr)) const + { + return mPtr == nullptr; + } + bool operator!=(const char16ptr_t& aOther) const + { + return mPtr != aOther.mPtr; + } + bool operator!=(decltype(nullptr)) const + { + return mPtr != nullptr; + } + char16ptr_t operator+(size_t aValue) const + { + return char16ptr_t(mPtr + aValue); + } + ptrdiff_t operator-(const char16ptr_t& aOther) const + { + return mPtr - aOther.mPtr; + } +}; + +inline decltype((char*)0-(char*)0) +operator-(const char16_t* aX, const char16ptr_t aY) +{ + return aX - static_cast(aY); +} + +#else + +typedef const char16_t* char16ptr_t; + +#endif + +/* + * Macro arguments used in concatenation or stringification won't be expanded. + * Therefore, in order for |MOZ_UTF16(FOO)| to work as expected (which is to + * expand |FOO| before doing whatever |MOZ_UTF16| needs to do to it) a helper + * macro, |MOZ_UTF16_HELPER| needs to be inserted in between to allow the macro + * argument to expand. See "3.10.6 Separate Expansion of Macro Arguments" of the + * CPP manual for a more accurate and precise explanation. + */ +#define MOZ_UTF16(s) MOZ_UTF16_HELPER(s) + +static_assert(sizeof(char16_t) == 2, "Is char16_t type 16 bits?"); +static_assert(char16_t(-1) > char16_t(0), "Is char16_t type unsigned?"); +static_assert(sizeof(MOZ_UTF16('A')) == 2, "Is char literal 16 bits?"); +static_assert(sizeof(MOZ_UTF16("")[0]) == 2, "Is string char 16 bits?"); + +#endif + +#endif /* mozilla_Char16_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/CheckedInt.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/CheckedInt.h new file mode 100644 index 0000000000..ad4c5fef41 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/CheckedInt.h @@ -0,0 +1,779 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Provides checked integers, detecting integer overflow and divide-by-0. */ + +#ifndef mozilla_CheckedInt_h +#define mozilla_CheckedInt_h + +#include +#include "mozilla/Assertions.h" +#include "mozilla/IntegerTypeTraits.h" + +namespace mozilla { + +template class CheckedInt; + +namespace detail { + +/* + * Step 1: manually record supported types + * + * What's nontrivial here is that there are different families of integer + * types: basic integer types and stdint types. It is merrily undefined which + * types from one family may be just typedefs for a type from another family. + * + * For example, on GCC 4.6, aside from the basic integer types, the only other + * type that isn't just a typedef for some of them, is int8_t. + */ + +struct UnsupportedType {}; + +template +struct IsSupportedPass2 +{ + static const bool value = false; +}; + +template +struct IsSupported +{ + static const bool value = IsSupportedPass2::value; +}; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +/* + * Step 2: Implement the actual validity checks. + * + * Ideas taken from IntegerLib, code different. + */ + +template +struct TwiceBiggerType +{ + typedef typename detail::StdintTypeForSizeAndSignedness< + sizeof(IntegerType) * 2, + IsSigned::value + >::Type Type; +}; + +template +struct TwiceBiggerType +{ + typedef UnsupportedType Type; +}; + +template +inline bool +HasSignBit(T aX) +{ + // In C++, right bit shifts on negative values is undefined by the standard. + // Notice that signed-to-unsigned conversions are always well-defined in the + // standard, as the value congruent modulo 2**n as expected. By contrast, + // unsigned-to-signed is only well-defined if the value is representable. + return bool(typename MakeUnsigned::Type(aX) >> + PositionOfSignBit::value); +} + +// Bitwise ops may return a larger type, so it's good to use this inline +// helper guaranteeing that the result is really of type T. +template +inline T +BinaryComplement(T aX) +{ + return ~aX; +} + +template::value, + bool IsUSigned = IsSigned::value> +struct DoesRangeContainRange +{ +}; + +template +struct DoesRangeContainRange +{ + static const bool value = sizeof(T) >= sizeof(U); +}; + +template +struct DoesRangeContainRange +{ + static const bool value = sizeof(T) > sizeof(U); +}; + +template +struct DoesRangeContainRange +{ + static const bool value = false; +}; + +template::value, + bool IsUSigned = IsSigned::value, + bool DoesTRangeContainURange = DoesRangeContainRange::value> +struct IsInRangeImpl {}; + +template +struct IsInRangeImpl +{ + static bool run(U) + { + return true; + } +}; + +template +struct IsInRangeImpl +{ + static bool run(U aX) + { + return aX <= MaxValue::value && aX >= MinValue::value; + } +}; + +template +struct IsInRangeImpl +{ + static bool run(U aX) + { + return aX <= MaxValue::value; + } +}; + +template +struct IsInRangeImpl +{ + static bool run(U aX) + { + return sizeof(T) > sizeof(U) || aX <= U(MaxValue::value); + } +}; + +template +struct IsInRangeImpl +{ + static bool run(U aX) + { + return sizeof(T) >= sizeof(U) + ? aX >= 0 + : aX >= 0 && aX <= U(MaxValue::value); + } +}; + +template +inline bool +IsInRange(U aX) +{ + return IsInRangeImpl::run(aX); +} + +template +inline bool +IsAddValid(T aX, T aY) +{ + // Addition is valid if the sign of aX+aY is equal to either that of aX or + // that of aY. Since the value of aX+aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. Beware! + // These bitwise operations can return a larger integer type, if T was a + // small type like int8_t, so we explicitly cast to T. + + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux + uy; + return IsSigned::value + ? HasSignBit(BinaryComplement(T((result ^ aX) & (result ^ aY)))) + : BinaryComplement(aX) >= aY; +} + +template +inline bool +IsSubValid(T aX, T aY) +{ + // Subtraction is valid if either aX and aY have same sign, or aX-aY and aX + // have same sign. Since the value of aX-aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux - uy; + + return IsSigned::value + ? HasSignBit(BinaryComplement(T((result ^ aX) & (aX ^ aY)))) + : aX >= aY; +} + +template::value, + bool TwiceBiggerTypeIsSupported = + IsSupported::Type>::value> +struct IsMulValidImpl {}; + +template +struct IsMulValidImpl +{ + static bool run(T aX, T aY) + { + typedef typename TwiceBiggerType::Type TwiceBiggerType; + TwiceBiggerType product = TwiceBiggerType(aX) * TwiceBiggerType(aY); + return IsInRange(product); + } +}; + +template +struct IsMulValidImpl +{ + static bool run(T aX, T aY) + { + const T max = MaxValue::value; + const T min = MinValue::value; + + if (aX == 0 || aY == 0) { + return true; + } + if (aX > 0) { + return aY > 0 + ? aX <= max / aY + : aY >= min / aX; + } + + // If we reach this point, we know that aX < 0. + return aY > 0 + ? aX >= min / aY + : aY >= max / aX; + } +}; + +template +struct IsMulValidImpl +{ + static bool run(T aX, T aY) + { + return aY == 0 || aX <= MaxValue::value / aY; + } +}; + +template +inline bool +IsMulValid(T aX, T aY) +{ + return IsMulValidImpl::run(aX, aY); +} + +template +inline bool +IsDivValid(T aX, T aY) +{ + // Keep in mind that in the signed case, min/-1 is invalid because + // abs(min)>max. + return aY != 0 && + !(IsSigned::value && aX == MinValue::value && aY == T(-1)); +} + +template::value> +struct IsModValidImpl; + +template +inline bool +IsModValid(T aX, T aY) +{ + return IsModValidImpl::run(aX, aY); +} + +/* + * Mod is pretty simple. + * For now, let's just use the ANSI C definition: + * If aX or aY are negative, the results are implementation defined. + * Consider these invalid. + * Undefined for aY=0. + * The result will never exceed either aX or aY. + * + * Checking that aX>=0 is a warning when T is unsigned. + */ + +template +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + return aY >= 1; + } +}; + +template +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + if (aX < 0) { + return false; + } + return aY >= 1; + } +}; + +template::value> +struct NegateImpl; + +template +struct NegateImpl +{ + static CheckedInt negate(const CheckedInt& aVal) + { + // Handle negation separately for signed/unsigned, for simpler code and to + // avoid an MSVC warning negating an unsigned value. + return CheckedInt(0, aVal.isValid() && aVal.mValue == 0); + } +}; + +template +struct NegateImpl +{ + static CheckedInt negate(const CheckedInt& aVal) + { + // Watch out for the min-value, which (with twos-complement) can't be + // negated as -min-value is then (max-value + 1). + if (!aVal.isValid() || aVal.mValue == MinValue::value) { + return CheckedInt(aVal.mValue, false); + } + return CheckedInt(-aVal.mValue, true); + } +}; + +} // namespace detail + + +/* + * Step 3: Now define the CheckedInt class. + */ + +/** + * @class CheckedInt + * @brief Integer wrapper class checking for integer overflow and other errors + * @param T the integer type to wrap. Can be any type among the following: + * - any basic integer type such as |int| + * - any stdint type such as |int8_t| + * + * This class implements guarded integer arithmetic. Do a computation, check + * that isValid() returns true, you then have a guarantee that no problem, such + * as integer overflow, happened during this computation, and you can call + * value() to get the plain integer value. + * + * The arithmetic operators in this class are guaranteed not to raise a signal + * (e.g. in case of a division by zero). + * + * For example, suppose that you want to implement a function that computes + * (aX+aY)/aZ, that doesn't crash if aZ==0, and that reports on error (divide by + * zero or integer overflow). You could code it as follows: + @code + bool computeXPlusYOverZ(int aX, int aY, int aZ, int* aResult) + { + CheckedInt checkedResult = (CheckedInt(aX) + aY) / aZ; + if (checkedResult.isValid()) { + *aResult = checkedResult.value(); + return true; + } else { + return false; + } + } + @endcode + * + * Implicit conversion from plain integers to checked integers is allowed. The + * plain integer is checked to be in range before being casted to the + * destination type. This means that the following lines all compile, and the + * resulting CheckedInts are correctly detected as valid or invalid: + * @code + // 1 is of type int, is found to be in range for uint8_t, x is valid + CheckedInt x(1); + // -1 is of type int, is found not to be in range for uint8_t, x is invalid + CheckedInt x(-1); + // -1 is of type int, is found to be in range for int8_t, x is valid + CheckedInt x(-1); + // 1000 is of type int16_t, is found not to be in range for int8_t, + // x is invalid + CheckedInt x(int16_t(1000)); + // 3123456789 is of type uint32_t, is found not to be in range for int32_t, + // x is invalid + CheckedInt x(uint32_t(3123456789)); + * @endcode + * Implicit conversion from + * checked integers to plain integers is not allowed. As shown in the + * above example, to get the value of a checked integer as a normal integer, + * call value(). + * + * Arithmetic operations between checked and plain integers is allowed; the + * result type is the type of the checked integer. + * + * Checked integers of different types cannot be used in the same arithmetic + * expression. + * + * There are convenience typedefs for all stdint types, of the following form + * (these are just 2 examples): + @code + typedef CheckedInt CheckedInt32; + typedef CheckedInt CheckedUint16; + @endcode + */ +template +class CheckedInt +{ +protected: + T mValue; + bool mIsValid; + + template + CheckedInt(U aValue, bool aIsValid) : mValue(aValue), mIsValid(aIsValid) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } + + friend struct detail::NegateImpl; + +public: + /** + * Constructs a checked integer with given @a value. The checked integer is + * initialized as valid or invalid depending on whether the @a value + * is in range. + * + * This constructor is not explicit. Instead, the type of its argument is a + * separate template parameter, ensuring that no conversion is performed + * before this constructor is actually called. As explained in the above + * documentation for class CheckedInt, this constructor checks that its + * argument is valid. + */ + template + CheckedInt(U aValue) + : mValue(T(aValue)), + mIsValid(detail::IsInRange(aValue)) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } + + template + friend class CheckedInt; + + template + CheckedInt toChecked() const + { + CheckedInt ret(mValue); + ret.mIsValid = ret.mIsValid && mIsValid; + return ret; + } + + /** Constructs a valid checked integer with initial value 0 */ + CheckedInt() : mValue(0), mIsValid(true) + { + static_assert(detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } + + /** @returns the actual value */ + T value() const + { + MOZ_ASSERT(mIsValid, "Invalid checked integer (division by zero or integer overflow)"); + return mValue; + } + + /** + * @returns true if the checked integer is valid, i.e. is not the result + * of an invalid operation or of an operation involving an invalid checked + * integer + */ + bool isValid() const + { + return mIsValid; + } + + template + friend CheckedInt operator +(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator +=(U aRhs); + + template + friend CheckedInt operator -(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator -=(U aRhs); + + template + friend CheckedInt operator *(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator *=(U aRhs); + + template + friend CheckedInt operator /(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator /=(U aRhs); + + template + friend CheckedInt operator %(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator %=(U aRhs); + + CheckedInt operator -() const + { + return detail::NegateImpl::negate(*this); + } + + /** + * @returns true if the left and right hand sides are valid + * and have the same value. + * + * Note that these semantics are the reason why we don't offer + * a operator!=. Indeed, we'd want to have a!=b be equivalent to !(a==b) + * but that would mean that whenever a or b is invalid, a!=b + * is always true, which would be very confusing. + * + * For similar reasons, operators <, >, <=, >= would be very tricky to + * specify, so we just avoid offering them. + * + * Notice that these == semantics are made more reasonable by these facts: + * 1. a==b implies equality at the raw data level + * (the converse is false, as a==b is never true among invalids) + * 2. This is similar to the behavior of IEEE floats, where a==b + * means that a and b have the same value *and* neither is NaN. + */ + bool operator ==(const CheckedInt& aOther) const + { + return mIsValid && aOther.mIsValid && mValue == aOther.mValue; + } + + /** prefix ++ */ + CheckedInt& operator++() + { + *this += 1; + return *this; + } + + /** postfix ++ */ + CheckedInt operator++(int) + { + CheckedInt tmp = *this; + *this += 1; + return tmp; + } + + /** prefix -- */ + CheckedInt& operator--() + { + *this -= 1; + return *this; + } + + /** postfix -- */ + CheckedInt operator--(int) + { + CheckedInt tmp = *this; + *this -= 1; + return tmp; + } + +private: + /** + * The !=, <, <=, >, >= operators are disabled: + * see the comment on operator==. + */ + template bool operator !=(U aOther) const MOZ_DELETE; + template bool operator < (U aOther) const MOZ_DELETE; + template bool operator <=(U aOther) const MOZ_DELETE; + template bool operator > (U aOther) const MOZ_DELETE; + template bool operator >=(U aOther) const MOZ_DELETE; +}; + +#define MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP) \ + template \ + inline CheckedInt \ + operator OP(const CheckedInt &aLhs, const CheckedInt &aRhs) \ + { \ + if (!detail::Is##NAME##Valid(aLhs.mValue, aRhs.mValue)) { \ + return CheckedInt(0, false); \ + } \ + return CheckedInt(aLhs.mValue OP aRhs.mValue, \ + aLhs.mIsValid && aRhs.mIsValid); \ + } + +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Add, +) +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Sub, -) +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Mul, *) +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Div, /) +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Mod, %) + +#undef MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR + +// Implement castToCheckedInt(x), making sure that +// - it allows x to be either a CheckedInt or any integer type +// that can be casted to T +// - if x is already a CheckedInt, we just return a reference to it, +// instead of copying it (optimization) + +namespace detail { + +template +struct CastToCheckedIntImpl +{ + typedef CheckedInt ReturnType; + static CheckedInt run(U aU) { return aU; } +}; + +template +struct CastToCheckedIntImpl > +{ + typedef const CheckedInt& ReturnType; + static const CheckedInt& run(const CheckedInt& aU) { return aU; } +}; + +} // namespace detail + +template +inline typename detail::CastToCheckedIntImpl::ReturnType +castToCheckedInt(U aU) +{ + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + return detail::CastToCheckedIntImpl::run(aU); +} + +#define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP) \ + template \ + template \ + CheckedInt& CheckedInt::operator COMPOUND_OP(U aRhs) \ + { \ + *this = *this OP castToCheckedInt(aRhs); \ + return *this; \ + } \ + template \ + inline CheckedInt operator OP(const CheckedInt &aLhs, U aRhs) \ + { \ + return aLhs OP castToCheckedInt(aRhs); \ + } \ + template \ + inline CheckedInt operator OP(U aLhs, const CheckedInt &aRhs) \ + { \ + return castToCheckedInt(aLhs) OP aRhs; \ + } + +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(+, +=) +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(*, *=) +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(-, -=) +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(/, /=) +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(%, %=) + +#undef MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS + +template +inline bool +operator ==(const CheckedInt &aLhs, U aRhs) +{ + return aLhs == castToCheckedInt(aRhs); +} + +template +inline bool +operator ==(U aLhs, const CheckedInt &aRhs) +{ + return castToCheckedInt(aLhs) == aRhs; +} + +// Convenience typedefs. +typedef CheckedInt CheckedInt8; +typedef CheckedInt CheckedUint8; +typedef CheckedInt CheckedInt16; +typedef CheckedInt CheckedUint16; +typedef CheckedInt CheckedInt32; +typedef CheckedInt CheckedUint32; +typedef CheckedInt CheckedInt64; +typedef CheckedInt CheckedUint64; + +} // namespace mozilla + +#endif /* mozilla_CheckedInt_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Compiler.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Compiler.h new file mode 100644 index 0000000000..50f127da86 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Compiler.h @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Various compiler checks. */ + +#ifndef mozilla_Compiler_h +#define mozilla_Compiler_h + +#define MOZ_IS_GCC 0 +#define MOS_IS_MSVC 0 + +#if !defined(__clang__) && defined(__GNUC__) + +# undef MOZ_IS_GCC +# define MOZ_IS_GCC 1 + /* + * This macro should simplify gcc version checking. For example, to check + * for gcc 4.5.1 or later, check `#if MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`. + */ +# define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel) \ + ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \ + >= ((major) * 10000 + (minor) * 100 + (patchlevel))) +# if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0) +# error "mfbt (and Gecko) require at least gcc 4.4 to build." +# endif + +#elif defined(_MSC_VER) + +# undef MOZ_IS_MSVC +# define MOZ_IS_MSVC 1 + /* + * This macro should simplify MSVC version checking. For example, to check + * for VC10 or later, check `#ifdef MOZ_MSVC_VERSION_AT_LEAST(10)`. + */ +# define MOZ_MSVC_VERSION_AT_LEAST(version) \ + (version == 10 ? _MSC_VER >= 1600 : \ + (version == 11 ? _MSC_VER >= 1700 : \ + (version == 12 ? _MSC_VER >= 1800 : \ + (version == 13 ? _MSC_VER >= 1900 : \ + 0)))) +# if !MOZ_MSVC_VERSION_AT_LEAST(10) +# error "mfbt (and Gecko) require at least MSVC 2010 RTM to build." +# endif + +#endif + +/* + * The situation with standard libraries is a lot worse than with compilers, + * particularly as clang and gcc could end up using one of three or so standard + * libraries, and they may not be up-to-snuff with newer C++11 versions. To + * detect the library, we're going to include cstddef (which is a small header + * which will be transitively included by everybody else at some point) to grab + * the version macros and deduce macros from there. + */ +#ifdef __cplusplus +# include +# ifdef _STLPORT_MAJOR +# define MOZ_USING_STLPORT 1 +# define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) \ + (_STLPORT_VERSION >= ((major) << 8 | (minor) << 4 | (patch))) +# elif defined(_LIBCPP_VERSION) + /* + * libc++, unfortunately, doesn't appear to have useful versioning macros. + * Hopefully, the recommendations of N3694 with respect to standard libraries + * will get applied instead and we won't need to worry about version numbers + * here. + */ +# define MOZ_USING_LIBCXX 1 +# elif defined(__GLIBCXX__) +# define MOZ_USING_LIBSTDCXX 1 + /* + * libstdc++ is also annoying and doesn't give us useful versioning macros + * for the library. If we're using gcc, then assume that libstdc++ matches + * the compiler version. If we're using clang, we're going to have to fake + * major/minor combinations by looking for newly-defined config macros. + */ +# if MOZ_IS_GCC +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + MOZ_GCC_VERSION_AT_LEAST(major, minor, patch) +# elif defined(_GLIBCXX_THROW_OR_ABORT) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 8)) +# elif defined(_GLIBCXX_NOEXCEPT) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 7)) +# elif defined(_GLIBCXX_USE_DEPRECATED) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 6)) +# elif defined(_GLIBCXX_PSEUDO_VISIBILITY) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 5)) +# elif defined(_GLIBCXX_BEGIN_EXTERN_C) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 4)) +# elif defined(_GLIBCXX_VISIBILITY_ATTR) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 3)) +# elif defined(_GLIBCXX_VISIBILITY) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 2)) +# else +# error "Your version of libstdc++ is unknown to us and is likely too old." +# endif +# endif + + // Flesh out the defines for everyone else +# ifndef MOZ_USING_STLPORT +# define MOZ_USING_STLPORT 0 +# define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) 0 +# endif +# ifndef MOZ_USING_LIBCXX +# define MOZ_USING_LIBCXX 0 +# endif +# ifndef MOZ_USING_LIBSTDCXX +# define MOZ_USING_LIBSTDCXX 0 +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) 0 +# endif +#endif /* __cplusplus */ + +#endif /* mozilla_Compiler_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Compression.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Compression.h new file mode 100644 index 0000000000..a764a1b5d5 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Compression.h @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Various simple compression/decompression functions. */ + +#ifndef mozilla_Compression_h_ +#define mozilla_Compression_h_ + +#include "mozilla/Types.h" +#include "mozilla/Assertions.h" + +namespace mozilla { +namespace Compression { + +/** + * LZ4 is a very fast byte-wise compression algorithm. + * + * Compared to Google's Snappy it is faster to compress and decompress and + * generally produces output of about the same size. + * + * Compared to zlib it compresses at about 10x the speed, decompresses at about + * 4x the speed and produces output of about 1.5x the size. + */ + +class LZ4 +{ +public: + /** + * Compresses |aInputSize| bytes from |aSource| into |aDest|. Destination + * buffer must be already allocated, and must be sized to handle worst cases + * situations (input data not compressible). Worst case size evaluation is + * provided by function maxCompressedSize() + * + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return the number of bytes written in buffer |aDest| + */ + static MFBT_API size_t + compress(const char* aSource, size_t aInputSize, char* aDest); + + /** + * Compress |aInputSize| bytes from |aSource| into an output buffer + * |aDest| of maximum size |aMaxOutputSize|. If it cannot achieve it, + * compression will stop, and result of the function will be zero, + * |aDest| will still be written to, but since the number of input + * bytes consumed is not returned the result is not usable. + * + * This function never writes outside of provided output buffer. + * + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @param aMaxOutputSize is the size of the destination buffer (which must + * be already allocated) + * @return the number of bytes written in buffer |aDest| or 0 if the + * compression fails + */ + static MFBT_API size_t + compressLimitedOutput(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize); + + /** + * If the source stream is malformed, the function will stop decoding + * and return a negative result, indicating the byte position of the + * faulty instruction + * + * This function never writes outside of provided buffers, and never + * modifies input buffer. + * + * Note: destination buffer must be already allocated, and its size must be a + * minimum of |aOutputSize| bytes. + * + * @param aOutputSize is the output size, therefore the original size + * @return the number of bytes read in the source buffer + */ + static MFBT_API bool + decompress(const char* aSource, char* aDest, size_t aOutputSize); + + /** + * If the source stream is malformed, the function will stop decoding + * and return false. + * + * This function never writes beyond aDest + aMaxOutputSize, and is + * therefore protected against malicious data packets. + * + * Note: Destination buffer must be already allocated. This version is + * slightly slower than the decompress without the aMaxOutputSize. + * + * @param aInputSize is the length of the input compressed data + * @param aMaxOutputSize is the size of the destination buffer (which must be + * already allocated) + * @param aOutputSize the actual number of bytes decoded in the destination + * buffer (necessarily <= aMaxOutputSize) + */ + static MFBT_API bool + decompress(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize, size_t* aOutputSize); + + /* + * Provides the maximum size that LZ4 may output in a "worst case" + * scenario (input data not compressible) primarily useful for memory + * allocation of output buffer. + * note : this function is limited by "int" range (2^31-1) + * + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return maximum output size in a "worst case" scenario + */ + static inline size_t maxCompressedSize(size_t aInputSize) + { + size_t max = (aInputSize + (aInputSize / 255) + 16); + MOZ_ASSERT(max > aInputSize); + return max; + } +}; + +} /* namespace Compression */ +} /* namespace mozilla */ + +#endif /* mozilla_Compression_h_ */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Constants.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Constants.h new file mode 100644 index 0000000000..86bbb6b354 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Constants.h @@ -0,0 +1,16 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* mfbt math constants. */ + +#ifndef mozilla_Constants_h +#define mozilla_Constants_h + +#ifndef M_PI +# define M_PI 3.14159265358979323846 +#endif + +#endif /* mozilla_Constants_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/DebugOnly.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/DebugOnly.h new file mode 100644 index 0000000000..5d0197b194 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/DebugOnly.h @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Provides DebugOnly, a type for variables used only in debug builds (i.e. by + * assertions). + */ + +#ifndef mozilla_DebugOnly_h +#define mozilla_DebugOnly_h + +#include "mozilla/Attributes.h" + +namespace mozilla { + +/** + * DebugOnly contains a value of type T, but only in debug builds. In release + * builds, it does not contain a value. This helper is intended to be used with + * MOZ_ASSERT()-style macros, allowing one to write: + * + * DebugOnly check = func(); + * MOZ_ASSERT(check); + * + * more concisely than declaring |check| conditional on #ifdef DEBUG, but also + * without allocating storage space for |check| in release builds. + * + * DebugOnly instances can only be coerced to T in debug builds. In release + * builds they don't have a value, so type coercion is not well defined. + * + * Note that DebugOnly instances still take up one byte of space, plus padding, + * when used as members of structs. + */ +template +class DebugOnly +{ +public: +#ifdef DEBUG + T value; + + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T& aOther) : value(aOther) { } + DebugOnly(const DebugOnly& aOther) : value(aOther.value) { } + DebugOnly& operator=(const T& aRhs) { + value = aRhs; + return *this; + } + + void operator++(int) { value++; } + void operator--(int) { value--; } + + T* operator&() { return &value; } + + operator T&() { return value; } + operator const T&() const { return value; } + + T& operator->() { return value; } + const T& operator->() const { return value; } + +#else + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T&) { } + DebugOnly(const DebugOnly&) { } + DebugOnly& operator=(const T&) { return *this; } + void operator++(int) { } + void operator--(int) { } +#endif + + /* + * DebugOnly must always have a destructor or else it will + * generate "unused variable" warnings, exactly what it's intended + * to avoid! + */ + ~DebugOnly() {} +}; + +} + +#endif /* mozilla_DebugOnly_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Endian.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Endian.h new file mode 100644 index 0000000000..b36991ff88 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Endian.h @@ -0,0 +1,697 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Functions for reading and writing integers in various endiannesses. */ + +/* + * The classes LittleEndian and BigEndian expose static methods for + * reading and writing 16-, 32-, and 64-bit signed and unsigned integers + * in their respective endianness. The naming scheme is: + * + * {Little,Big}Endian::{read,write}{Uint,Int} + * + * For instance, LittleEndian::readInt32 will read a 32-bit signed + * integer from memory in little endian format. Similarly, + * BigEndian::writeUint16 will write a 16-bit unsigned integer to memory + * in big-endian format. + * + * The class NativeEndian exposes methods for conversion of existing + * data to and from the native endianness. These methods are intended + * for cases where data needs to be transferred, serialized, etc. + * swap{To,From}{Little,Big}Endian byteswap a single value if necessary. + * Bulk conversion functions are also provided which optimize the + * no-conversion-needed case: + * + * - copyAndSwap{To,From}{Little,Big}Endian; + * - swap{To,From}{Little,Big}EndianInPlace. + * + * The *From* variants are intended to be used for reading data and the + * *To* variants for writing data. + * + * Methods on NativeEndian work with integer data of any type. + * Floating-point data is not supported. + * + * For clarity in networking code, "Network" may be used as a synonym + * for "Big" in any of the above methods or class names. + * + * As an example, reading a file format header whose fields are stored + * in big-endian format might look like: + * + * class ExampleHeader + * { + * private: + * uint32_t mMagic; + * uint32_t mLength; + * uint32_t mTotalRecords; + * uint64_t mChecksum; + * + * public: + * ExampleHeader(const void* data) + * { + * const uint8_t* ptr = static_cast(data); + * mMagic = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mLength = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mTotalRecords = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mChecksum = BigEndian::readUint64(ptr); + * } + * ... + * }; + */ + +#ifndef mozilla_Endian_h +#define mozilla_Endian_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/DebugOnly.h" +#include "mozilla/TypeTraits.h" + +#include +#include + +#if defined(_MSC_VER) && _MSC_VER >= 1300 +# include +# pragma intrinsic(_byteswap_ushort) +# pragma intrinsic(_byteswap_ulong) +# pragma intrinsic(_byteswap_uint64) +#endif + +#if defined(_WIN64) +# if defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_) +# define MOZ_LITTLE_ENDIAN 1 +# else +# error "CPU type is unknown" +# endif +#elif defined(_WIN32) +# if defined(_M_IX86) +# define MOZ_LITTLE_ENDIAN 1 +# elif defined(_M_ARM) +# define MOZ_LITTLE_ENDIAN 1 +# else +# error "CPU type is unknown" +# endif +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) +# if __LITTLE_ENDIAN__ +# define MOZ_LITTLE_ENDIAN 1 +# elif __BIG_ENDIAN__ +# define MOZ_BIG_ENDIAN 1 +# endif +#elif defined(__GNUC__) && \ + defined(__BYTE_ORDER__) && \ + defined(__ORDER_LITTLE_ENDIAN__) && \ + defined(__ORDER_BIG_ENDIAN__) + /* + * Some versions of GCC provide architecture-independent macros for + * this. Yes, there are more than two values for __BYTE_ORDER__. + */ +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define MOZ_LITTLE_ENDIAN 1 +# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define MOZ_BIG_ENDIAN 1 +# else +# error "Can't handle mixed-endian architectures" +# endif +/* + * We can't include useful headers like or + * here because they're not present on all platforms. Instead we have + * this big conditional that ideally will catch all the interesting + * cases. + */ +#elif defined(__sparc) || defined(__sparc__) || \ + defined(_POWER) || defined(__hppa) || \ + defined(_MIPSEB) || defined(__ARMEB__) || \ + defined(__s390__) || defined(__AARCH64EB__) || \ + (defined(__sh__) && defined(__LITTLE_ENDIAN__)) || \ + (defined(__ia64) && defined(__BIG_ENDIAN__)) +# define MOZ_BIG_ENDIAN 1 +#elif defined(__i386) || defined(__i386__) || \ + defined(__x86_64) || defined(__x86_64__) || \ + defined(_MIPSEL) || defined(__ARMEL__) || \ + defined(__alpha__) || defined(__AARCH64EL__) || \ + (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ + (defined(__ia64) && !defined(__BIG_ENDIAN__)) +# define MOZ_LITTLE_ENDIAN 1 +#endif + +#if MOZ_BIG_ENDIAN +# define MOZ_LITTLE_ENDIAN 0 +#elif MOZ_LITTLE_ENDIAN +# define MOZ_BIG_ENDIAN 0 +#else +# error "Cannot determine endianness" +#endif + +#if defined(__clang__) +# if __has_builtin(__builtin_bswap16) +# define MOZ_HAVE_BUILTIN_BYTESWAP16 __builtin_bswap16 +# endif +#elif defined(__GNUC__) +# if MOZ_GCC_VERSION_AT_LEAST(4, 8, 0) +# define MOZ_HAVE_BUILTIN_BYTESWAP16 __builtin_bswap16 +# endif +#elif defined(_MSC_VER) +# define MOZ_HAVE_BUILTIN_BYTESWAP16 _byteswap_ushort +#endif + +namespace mozilla { + +namespace detail { + +/* + * We need wrappers here because free functions with default template + * arguments and/or partial specialization of function templates are not + * supported by all the compilers we use. + */ +template +struct Swapper; + +template +struct Swapper +{ + static T swap(T aValue) + { +#if defined(MOZ_HAVE_BUILTIN_BYTESWAP16) + return MOZ_HAVE_BUILTIN_BYTESWAP16(aValue); +#else + return T(((aValue & 0x00ff) << 8) | ((aValue & 0xff00) >> 8)); +#endif + } +}; + +template +struct Swapper +{ + static T swap(T aValue) + { +#if defined(__clang__) || defined(__GNUC__) + return T(__builtin_bswap32(aValue)); +#elif defined(_MSC_VER) + return T(_byteswap_ulong(aValue)); +#else + return T(((aValue & 0x000000ffU) << 24) | + ((aValue & 0x0000ff00U) << 8) | + ((aValue & 0x00ff0000U) >> 8) | + ((aValue & 0xff000000U) >> 24)); +#endif + } +}; + +template +struct Swapper +{ + static inline T swap(T aValue) + { +#if defined(__clang__) || defined(__GNUC__) + return T(__builtin_bswap64(aValue)); +#elif defined(_MSC_VER) + return T(_byteswap_uint64(aValue)); +#else + return T(((aValue & 0x00000000000000ffULL) << 56) | + ((aValue & 0x000000000000ff00ULL) << 40) | + ((aValue & 0x0000000000ff0000ULL) << 24) | + ((aValue & 0x00000000ff000000ULL) << 8) | + ((aValue & 0x000000ff00000000ULL) >> 8) | + ((aValue & 0x0000ff0000000000ULL) >> 24) | + ((aValue & 0x00ff000000000000ULL) >> 40) | + ((aValue & 0xff00000000000000ULL) >> 56)); +#endif + } +}; + +enum Endianness { Little, Big }; + +#if MOZ_BIG_ENDIAN +# define MOZ_NATIVE_ENDIANNESS detail::Big +#else +# define MOZ_NATIVE_ENDIANNESS detail::Little +#endif + +class EndianUtils +{ + /** + * Assert that the memory regions [aDest, aDest+aCount) and + * [aSrc, aSrc+aCount] do not overlap. aCount is given in bytes. + */ + static void assertNoOverlap(const void* aDest, const void* aSrc, + size_t aCount) + { + DebugOnly byteDestPtr = static_cast(aDest); + DebugOnly byteSrcPtr = static_cast(aSrc); + MOZ_ASSERT((byteDestPtr <= byteSrcPtr && + byteDestPtr + aCount <= byteSrcPtr) || + (byteSrcPtr <= byteDestPtr && + byteSrcPtr + aCount <= byteDestPtr)); + } + + template + static void assertAligned(T* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % sizeof(T)) == 0, "Unaligned pointer!"); + } + +protected: + /** + * Return |aValue| converted from SourceEndian encoding to DestEndian + * encoding. + */ + template + static inline T maybeSwap(T aValue) + { + if (SourceEndian == DestEndian) { + return aValue; + } + return Swapper::swap(aValue); + } + + /** + * Convert |aCount| elements at |aPtr| from SourceEndian encoding to + * DestEndian encoding. + */ + template + static inline void maybeSwapInPlace(T* aPtr, size_t aCount) + { + assertAligned(aPtr); + + if (SourceEndian == DestEndian) { + return; + } + for (size_t i = 0; i < aCount; i++) { + aPtr[i] = Swapper::swap(aPtr[i]); + } + } + + /** + * Write |aCount| elements to the unaligned address |aDest| in DestEndian + * format, using elements found at |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapTo(void* aDest, const T* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aSrc); + + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; + } + + uint8_t* byteDestPtr = static_cast(aDest); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + u.mVal = maybeSwap(aSrc[i]); + memcpy(byteDestPtr, u.mBuffer, sizeof(T)); + byteDestPtr += sizeof(T); + } + } + + /** + * Write |aCount| elements to |aDest| in DestEndian format, using elements + * found at the unaligned address |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapFrom(T* aDest, const void* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aDest); + + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; + } + + const uint8_t* byteSrcPtr = static_cast(aSrc); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, byteSrcPtr, sizeof(T)); + aDest[i] = maybeSwap(u.mVal); + byteSrcPtr += sizeof(T); + } + } +}; + +template +class Endian : private EndianUtils +{ +protected: + /** Read a uint16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint16_t readUint16(const void* aPtr) + { + return read(aPtr); + } + + /** Read a uint32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint32_t readUint32(const void* aPtr) + { + return read(aPtr); + } + + /** Read a uint64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint64_t readUint64(const void* aPtr) + { + return read(aPtr); + } + + /** Read an int16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int16_t readInt16(const void* aPtr) + { + return read(aPtr); + } + + /** Read an int32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int32_t readInt32(const void* aPtr) + { + return read(aPtr); + } + + /** Read an int64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int64_t readInt64(const void* aPtr) + { + return read(aPtr); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint16(void* aPtr, uint16_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint32(void* aPtr, uint32_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint64(void* aPtr, uint64_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt16(void* aPtr, int16_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt32(void* aPtr, int32_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt64(void* aPtr, int64_t aValue) + { + write(aPtr, aValue); + } + + /* + * Converts a value of type T to little-endian format. + * + * This function is intended for cases where you have data in your + * native-endian format and you need it to appear in little-endian + * format for transmission. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToLittleEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToLittleEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapToLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T to big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToBigEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapToBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + + template + MOZ_WARN_UNUSED_RESULT static T swapToNetworkOrder(T aValue) + { + return swapToBigEndian(aValue); + } + + template + static void + copyAndSwapToNetworkOrder(void* aDest, const T* aSrc, size_t aCount) + { + copyAndSwapToBigEndian(aDest, aSrc, aCount); + } + + template + static void + swapToNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapToBigEndianInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from little-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromLittleEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromLittleEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromBigEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromNetworkOrder(T aValue) + { + return swapFromBigEndian(aValue); + } + + template + static void copyAndSwapFromNetworkOrder(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFromBigEndian(aDest, aSrc, aCount); + } + + template + static void swapFromNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapFromBigEndianInPlace(aPtr, aCount); + } + +private: + /** + * Read a value of type T, encoded in endianness ThisEndian from |aPtr|. + * Return that value encoded in native endianness. + */ + template + static T read(const void* aPtr) + { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, aPtr, sizeof(T)); + return maybeSwap(u.mVal); + } + + /** + * Write a value of type T, in native endianness, to |aPtr|, in ThisEndian + * endianness. + */ + template + static void write(void* aPtr, T aValue) + { + T tmp = maybeSwap(aValue); + memcpy(aPtr, &tmp, sizeof(T)); + } + + Endian() MOZ_DELETE; + Endian(const Endian& aTther) MOZ_DELETE; + void operator=(const Endian& aOther) MOZ_DELETE; +}; + +template +class EndianReadWrite : public Endian +{ +private: + typedef Endian super; + +public: + using super::readUint16; + using super::readUint32; + using super::readUint64; + using super::readInt16; + using super::readInt32; + using super::readInt64; + using super::writeUint16; + using super::writeUint32; + using super::writeUint64; + using super::writeInt16; + using super::writeInt32; + using super::writeInt64; +}; + +} /* namespace detail */ + +class LittleEndian MOZ_FINAL : public detail::EndianReadWrite +{}; + +class BigEndian MOZ_FINAL : public detail::EndianReadWrite +{}; + +typedef BigEndian NetworkEndian; + +class NativeEndian MOZ_FINAL : public detail::Endian +{ +private: + typedef detail::Endian super; + +public: + /* + * These functions are intended for cases where you have data in your + * native-endian format and you need the data to appear in the appropriate + * endianness for transmission, serialization, etc. + */ + using super::swapToLittleEndian; + using super::copyAndSwapToLittleEndian; + using super::swapToLittleEndianInPlace; + using super::swapToBigEndian; + using super::copyAndSwapToBigEndian; + using super::swapToBigEndianInPlace; + using super::swapToNetworkOrder; + using super::copyAndSwapToNetworkOrder; + using super::swapToNetworkOrderInPlace; + + /* + * These functions are intended for cases where you have data in the + * given endianness (e.g. reading from disk or a file-format) and you + * need the data to appear in native-endian format for processing. + */ + using super::swapFromLittleEndian; + using super::copyAndSwapFromLittleEndian; + using super::swapFromLittleEndianInPlace; + using super::swapFromBigEndian; + using super::copyAndSwapFromBigEndian; + using super::swapFromBigEndianInPlace; + using super::swapFromNetworkOrder; + using super::copyAndSwapFromNetworkOrder; + using super::swapFromNetworkOrderInPlace; +}; + +#undef MOZ_NATIVE_ENDIANNESS + +} /* namespace mozilla */ + +#endif /* mozilla_Endian_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/EnumSet.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/EnumSet.h new file mode 100644 index 0000000000..8c78b2b442 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/EnumSet.h @@ -0,0 +1,206 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A set abstraction for enumeration values. */ + +#ifndef mozilla_EnumSet_h +#define mozilla_EnumSet_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" + +#include + +namespace mozilla { + +/** + * EnumSet is a set of values defined by an enumeration. It is implemented + * using a 32 bit mask for each value so it will only work for enums with an int + * representation less than 32. It works both for enum and enum class types. + */ +template +class EnumSet +{ +public: + EnumSet() + : mBitField(0) + { } + + MOZ_IMPLICIT EnumSet(T aEnum) + : mBitField(bitFor(aEnum)) + { } + + EnumSet(T aEnum1, T aEnum2) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3, T aEnum4) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3) | + bitFor(aEnum4)) + { } + + EnumSet(const EnumSet& aEnumSet) + : mBitField(aEnumSet.mBitField) + { } + + /** + * Add an element + */ + void operator+=(T aEnum) + { + mBitField |= bitFor(aEnum); + } + + /** + * Add an element + */ + EnumSet operator+(T aEnum) const + { + EnumSet result(*this); + result += aEnum; + return result; + } + + /** + * Union + */ + void operator+=(const EnumSet aEnumSet) + { + mBitField |= aEnumSet.mBitField; + } + + /** + * Union + */ + EnumSet operator+(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result += aEnumSet; + return result; + } + + /** + * Remove an element + */ + void operator-=(T aEnum) + { + mBitField &= ~(bitFor(aEnum)); + } + + /** + * Remove an element + */ + EnumSet operator-(T aEnum) const + { + EnumSet result(*this); + result -= aEnum; + return result; + } + + /** + * Remove a set of elements + */ + void operator-=(const EnumSet aEnumSet) + { + mBitField &= ~(aEnumSet.mBitField); + } + + /** + * Remove a set of elements + */ + EnumSet operator-(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result -= aEnumSet; + return result; + } + + /** + * Intersection + */ + void operator&=(const EnumSet aEnumSet) + { + mBitField &= aEnumSet.mBitField; + } + + /** + * Intersection + */ + EnumSet operator&(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result &= aEnumSet; + return result; + } + + /** + * Equality + */ + bool operator==(const EnumSet aEnumSet) const + { + return mBitField == aEnumSet.mBitField; + } + + /** + * Test is an element is contained in the set. + */ + bool contains(T aEnum) const + { + return mBitField & bitFor(aEnum); + } + + /** + * Return the number of elements in the set. + */ + uint8_t size() + { + uint8_t count = 0; + for (uint32_t bitField = mBitField; bitField; bitField >>= 1) { + if (bitField & 1) { + count++; + } + } + return count; + } + + bool isEmpty() const + { + return mBitField == 0; + } + + uint32_t serialize() const + { + return mBitField; + } + + void deserialize(uint32_t aValue) + { + mBitField = aValue; + } + +private: + static uint32_t bitFor(T aEnum) + { + uint32_t bitNumber = (uint32_t)aEnum; + MOZ_ASSERT(bitNumber < 32); + return 1U << bitNumber; + } + + uint32_t mBitField; +}; + +} // namespace mozilla + +#endif /* mozilla_EnumSet_h_*/ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/FloatingPoint.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/FloatingPoint.h new file mode 100644 index 0000000000..0ed567832b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/FloatingPoint.h @@ -0,0 +1,413 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Various predicates and operations on IEEE-754 floating point types. */ + +#ifndef mozilla_FloatingPoint_h +#define mozilla_FloatingPoint_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Casting.h" +#include "mozilla/MathAlgorithms.h" +#include "mozilla/Types.h" + +#include + +namespace mozilla { + +/* + * It's reasonable to ask why we have this header at all. Don't isnan, + * copysign, the built-in comparison operators, and the like solve these + * problems? Unfortunately, they don't. We've found that various compilers + * (MSVC, MSVC when compiling with PGO, and GCC on OS X, at least) miscompile + * the standard methods in various situations, so we can't use them. Some of + * these compilers even have problems compiling seemingly reasonable bitwise + * algorithms! But with some care we've found algorithms that seem to not + * trigger those compiler bugs. + * + * For the aforementioned reasons, be very wary of making changes to any of + * these algorithms. If you must make changes, keep a careful eye out for + * compiler bustage, particularly PGO-specific bustage. + */ + +struct FloatTypeTraits +{ + typedef uint32_t Bits; + + static const unsigned kExponentBias = 127; + static const unsigned kExponentShift = 23; + + static const Bits kSignBit = 0x80000000UL; + static const Bits kExponentBits = 0x7F800000UL; + static const Bits kSignificandBits = 0x007FFFFFUL; +}; + +struct DoubleTypeTraits +{ + typedef uint64_t Bits; + + static const unsigned kExponentBias = 1023; + static const unsigned kExponentShift = 52; + + static const Bits kSignBit = 0x8000000000000000ULL; + static const Bits kExponentBits = 0x7ff0000000000000ULL; + static const Bits kSignificandBits = 0x000fffffffffffffULL; +}; + +template struct SelectTrait; +template<> struct SelectTrait : public FloatTypeTraits {}; +template<> struct SelectTrait : public DoubleTypeTraits {}; + +/* + * This struct contains details regarding the encoding of floating-point + * numbers that can be useful for direct bit manipulation. As of now, the + * template parameter has to be float or double. + * + * The nested typedef |Bits| is the unsigned integral type with the same size + * as T: uint32_t for float and uint64_t for double (static assertions + * double-check these assumptions). + * + * kExponentBias is the offset that is subtracted from the exponent when + * computing the value, i.e. one plus the opposite of the mininum possible + * exponent. + * kExponentShift is the shift that one needs to apply to retrieve the + * exponent component of the value. + * + * kSignBit contains a bits mask. Bit-and-ing with this mask will result in + * obtaining the sign bit. + * kExponentBits contains the mask needed for obtaining the exponent bits and + * kSignificandBits contains the mask needed for obtaining the significand + * bits. + * + * Full details of how floating point number formats are encoded are beyond + * the scope of this comment. For more information, see + * http://en.wikipedia.org/wiki/IEEE_floating_point + * http://en.wikipedia.org/wiki/Floating_point#IEEE_754:_floating_point_in_modern_computers + */ +template +struct FloatingPoint : public SelectTrait +{ + typedef SelectTrait Base; + typedef typename Base::Bits Bits; + + static_assert((Base::kSignBit & Base::kExponentBits) == 0, + "sign bit shouldn't overlap exponent bits"); + static_assert((Base::kSignBit & Base::kSignificandBits) == 0, + "sign bit shouldn't overlap significand bits"); + static_assert((Base::kExponentBits & Base::kSignificandBits) == 0, + "exponent bits shouldn't overlap significand bits"); + + static_assert((Base::kSignBit | Base::kExponentBits | Base::kSignificandBits) == + ~Bits(0), + "all bits accounted for"); + + /* + * These implementations assume float/double are 32/64-bit single/double + * format number types compatible with the IEEE-754 standard. C++ don't + * require this to be the case. But we required this in implementations of + * these algorithms that preceded this header, so we shouldn't break anything + * if we keep doing so. + */ + static_assert(sizeof(T) == sizeof(Bits), "Bits must be same size as T"); +}; + +/** Determines whether a double is NaN. */ +template +static MOZ_ALWAYS_INLINE bool +IsNaN(T aValue) +{ + /* + * A float/double is NaN if all exponent bits are 1 and the significand + * contains at least one non-zero bit. + */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) == Traits::kExponentBits && + (bits & Traits::kSignificandBits) != 0; +} + +/** Determines whether a float/double is +Infinity or -Infinity. */ +template +static MOZ_ALWAYS_INLINE bool +IsInfinite(T aValue) +{ + /* Infinities have all exponent bits set to 1 and an all-0 significand. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & ~Traits::kSignBit) == Traits::kExponentBits; +} + +/** Determines whether a float/double is not NaN or infinite. */ +template +static MOZ_ALWAYS_INLINE bool +IsFinite(T aValue) +{ + /* + * NaN and Infinities are the only non-finite floats/doubles, and both have + * all exponent bits set to 1. + */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) != Traits::kExponentBits; +} + +/** + * Determines whether a float/double is negative. It is an error to call this + * method on a float/double which is NaN. + */ +template +static MOZ_ALWAYS_INLINE bool +IsNegative(T aValue) +{ + MOZ_ASSERT(!IsNaN(aValue), "NaN does not have a sign"); + + /* The sign bit is set if the double is negative. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kSignBit) != 0; +} + +/** Determines whether a float/double represents -0. */ +template +static MOZ_ALWAYS_INLINE bool +IsNegativeZero(T aValue) +{ + /* Only the sign bit is set if the value is -0. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return bits == Traits::kSignBit; +} + +/** + * Returns the exponent portion of the float/double. + * + * Zero is not special-cased, so ExponentComponent(0.0) is + * -int_fast16_t(Traits::kExponentBias). + */ +template +static MOZ_ALWAYS_INLINE int_fast16_t +ExponentComponent(T aValue) +{ + /* + * The exponent component of a float/double is an unsigned number, biased + * from its actual value. Subtract the bias to retrieve the actual exponent. + */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return int_fast16_t((bits & Traits::kExponentBits) >> Traits::kExponentShift) - + int_fast16_t(Traits::kExponentBias); +} + +/** Returns +Infinity. */ +template +static MOZ_ALWAYS_INLINE T +PositiveInfinity() +{ + /* + * Positive infinity has all exponent bits set, sign bit set to 0, and no + * significand. + */ + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kExponentBits); +} + +/** Returns -Infinity. */ +template +static MOZ_ALWAYS_INLINE T +NegativeInfinity() +{ + /* + * Negative infinity has all exponent bits set, sign bit set to 1, and no + * significand. + */ + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kSignBit | Traits::kExponentBits); +} + + +/** Constructs a NaN value with the specified sign bit and significand bits. */ +template +static MOZ_ALWAYS_INLINE T +SpecificNaN(int signbit, typename FloatingPoint::Bits significand) +{ + typedef FloatingPoint Traits; + MOZ_ASSERT(signbit == 0 || signbit == 1); + MOZ_ASSERT((significand & ~Traits::kSignificandBits) == 0); + MOZ_ASSERT(significand & Traits::kSignificandBits); + + T t = BitwiseCast((signbit ? Traits::kSignBit : 0) | + Traits::kExponentBits | + significand); + MOZ_ASSERT(IsNaN(t)); + return t; +} + +/** Computes the smallest non-zero positive float/double value. */ +template +static MOZ_ALWAYS_INLINE T +MinNumberValue() +{ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + return BitwiseCast(Bits(1)); +} + +/** + * If aValue is equal to some int32_t value, set *aInt32 to that value and + * return true; otherwise return false. + * + * Note that negative zero is "equal" to zero here. To test whether a value can + * be losslessly converted to int32_t and back, use NumberIsInt32 instead. + */ +template +static MOZ_ALWAYS_INLINE bool +NumberEqualsInt32(T aValue, int32_t* aInt32) +{ + /* + * XXX Casting a floating-point value that doesn't truncate to int32_t, to + * int32_t, induces undefined behavior. We should definitely fix this + * (bug 744965), but as apparently it "works" in practice, it's not a + * pressing concern now. + */ + return aValue == (*aInt32 = int32_t(aValue)); +} + +/** + * If d can be converted to int32_t and back to an identical double value, + * set *aInt32 to that value and return true; otherwise return false. + * + * The difference between this and NumberEqualsInt32 is that this method returns + * false for negative zero. + */ +template +static MOZ_ALWAYS_INLINE bool +NumberIsInt32(T aValue, int32_t* aInt32) +{ + return !IsNegativeZero(aValue) && NumberEqualsInt32(aValue, aInt32); +} + +/** + * Computes a NaN value. Do not use this method if you depend upon a particular + * NaN value being returned. + */ +template +static MOZ_ALWAYS_INLINE T +UnspecifiedNaN() +{ + /* + * If we can use any quiet NaN, we might as well use the all-ones NaN, + * since it's cheap to materialize on common platforms (such as x64, where + * this value can be represented in a 32-bit signed immediate field, allowing + * it to be stored to memory in a single instruction). + */ + typedef FloatingPoint Traits; + return SpecificNaN(1, Traits::kSignificandBits); +} + +/** + * Compare two doubles for equality, *without* equating -0 to +0, and equating + * any NaN value to any other NaN value. (The normal equality operators equate + * -0 with +0, and they equate NaN to no other value.) + */ +template +static inline bool +NumbersAreIdentical(T aValue1, T aValue2) +{ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + if (IsNaN(aValue1)) { + return IsNaN(aValue2); + } + return BitwiseCast(aValue1) == BitwiseCast(aValue2); +} + +namespace detail { + +template +struct FuzzyEqualsEpsilon; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-5 that is exactly representable in a float. + static float value() { return 1.0f / (1 << 17); } +}; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-12 that is exactly representable in a double. + static double value() { return 1.0 / (1LL << 40); } +}; + +} // namespace detail + +/** + * Compare two floating point values for equality, modulo rounding error. That + * is, the two values are considered equal if they are both not NaN and if they + * are less than or equal to aEpsilon apart. The default value of aEpsilon is + * near 1e-5. + * + * For most scenarios you will want to use FuzzyEqualsMultiplicative instead, + * as it is more reasonable over the entire range of floating point numbers. + * This additive version should only be used if you know the range of the + * numbers you are dealing with is bounded and stays around the same order of + * magnitude. + */ +template +static MOZ_ALWAYS_INLINE bool +FuzzyEqualsAdditive(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) +{ + static_assert(IsFloatingPoint::value, "floating point type required"); + return Abs(aValue1 - aValue2) <= aEpsilon; +} + +/** + * Compare two floating point values for equality, allowing for rounding error + * relative to the magnitude of the values. That is, the two values are + * considered equal if they are both not NaN and they are less than or equal to + * some aEpsilon apart, where the aEpsilon is scaled by the smaller of the two + * argument values. + * + * In most cases you will want to use this rather than FuzzyEqualsAdditive, as + * this function effectively masks out differences in the bottom few bits of + * the floating point numbers being compared, regardless of what order of + * magnitude those numbers are at. + */ +template +static MOZ_ALWAYS_INLINE bool +FuzzyEqualsMultiplicative(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) +{ + static_assert(IsFloatingPoint::value, "floating point type required"); + // can't use std::min because of bug 965340 + T smaller = Abs(aValue1) < Abs(aValue2) ? Abs(aValue1) : Abs(aValue2); + return Abs(aValue1 - aValue2) <= aEpsilon * smaller; +} + +/** + * Returns true if the given value can be losslessly represented as an IEEE-754 + * single format number, false otherwise. All NaN values are considered + * representable (notwithstanding that the exact bit pattern of a double format + * NaN value can't be exactly represented in single format). + * + * This function isn't inlined to avoid buggy optimizations by MSVC. + */ +MOZ_WARN_UNUSED_RESULT +extern MFBT_API bool +IsFloat32Representable(double aFloat32); + +} /* namespace mozilla */ + +#endif /* mozilla_FloatingPoint_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/GuardObjects.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/GuardObjects.h new file mode 100644 index 0000000000..2cd950f314 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/GuardObjects.h @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implementation of macros to ensure correct use of RAII Auto* objects. */ + +#ifndef mozilla_GuardObjects_h +#define mozilla_GuardObjects_h + +#include "mozilla/Assertions.h" +#include "mozilla/NullPtr.h" +#include "mozilla/Types.h" + +#ifdef __cplusplus + +#ifdef DEBUG + +namespace mozilla { +namespace detail { + +/* + * The following classes are designed to cause assertions to detect + * inadvertent use of guard objects as temporaries. In other words, + * when we have a guard object whose only purpose is its constructor and + * destructor (and is never otherwise referenced), the intended use + * might be: + * + * AutoRestore savePainting(mIsPainting); + * + * but is is easy to accidentally write: + * + * AutoRestore(mIsPainting); + * + * which compiles just fine, but runs the destructor well before the + * intended time. + * + * They work by adding (#ifdef DEBUG) an additional parameter to the + * guard object's constructor, with a default value, so that users of + * the guard object's API do not need to do anything. The default value + * of this parameter is a temporary object. C++ (ISO/IEC 14882:1998), + * section 12.2 [class.temporary], clauses 4 and 5 seem to assume a + * guarantee that temporaries are destroyed in the reverse of their + * construction order, but I actually can't find a statement that that + * is true in the general case (beyond the two specific cases mentioned + * there). However, it seems to be true. + * + * These classes are intended to be used only via the macros immediately + * below them: + * + * MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER declares (ifdef DEBUG) a member + * variable, and should be put where a declaration of a private + * member variable would be placed. + * MOZ_GUARD_OBJECT_NOTIFIER_PARAM should be placed at the end of the + * parameters to each constructor of the guard object; it declares + * (ifdef DEBUG) an additional parameter. (But use the *_ONLY_PARAM + * variant for constructors that take no other parameters.) + * MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL should likewise be used in + * the implementation of such constructors when they are not inline. + * MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT should be used in + * the implementation of such constructors to pass the parameter to + * a base class that also uses these macros + * MOZ_GUARD_OBJECT_NOTIFIER_INIT is a statement that belongs in each + * constructor. It uses the parameter declared by + * MOZ_GUARD_OBJECT_NOTIFIER_PARAM. + * + * For more details, and examples of using these macros, see + * https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla + */ +class GuardObjectNotifier +{ +private: + bool* mStatementDone; + +public: + GuardObjectNotifier() : mStatementDone(nullptr) { } + + ~GuardObjectNotifier() { *mStatementDone = true; } + + void setStatementDone(bool* aStatementIsDone) + { + mStatementDone = aStatementIsDone; + } +}; + +class GuardObjectNotificationReceiver +{ +private: + bool mStatementDone; + +public: + GuardObjectNotificationReceiver() : mStatementDone(false) { } + + ~GuardObjectNotificationReceiver() { + /* + * Assert that the guard object was not used as a temporary. (Note that + * this assert might also fire if init is not called because the guard + * object's implementation is not using the above macros correctly.) + */ + MOZ_ASSERT(mStatementDone); + } + + void init(const GuardObjectNotifier& aConstNotifier) + { + /* + * aConstNotifier is passed as a const reference so that we can pass a + * temporary, but we really intend it as non-const. + */ + GuardObjectNotifier& notifier = + const_cast(aConstNotifier); + notifier.setStatementDone(&mStatementDone); + } +}; + +} /* namespace detail */ +} /* namespace mozilla */ + +#endif /* DEBUG */ + +#ifdef DEBUG +# define MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER \ + mozilla::detail::GuardObjectNotificationReceiver _mCheckNotUsedAsTemporary; +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM \ + , const mozilla::detail::GuardObjectNotifier& _notifier = \ + mozilla::detail::GuardObjectNotifier() +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM \ + const mozilla::detail::GuardObjectNotifier& _notifier = \ + mozilla::detail::GuardObjectNotifier() +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL \ + , const mozilla::detail::GuardObjectNotifier& _notifier +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL \ + const mozilla::detail::GuardObjectNotifier& _notifier +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT \ + , _notifier +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT \ + _notifier +# define MOZ_GUARD_OBJECT_NOTIFIER_INIT \ + do { _mCheckNotUsedAsTemporary.init(_notifier); } while (0) +#else +# define MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT +# define MOZ_GUARD_OBJECT_NOTIFIER_INIT do { } while (0) +#endif + +#endif /* __cplusplus */ + +#endif /* mozilla_GuardObjects_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/HashFunctions.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/HashFunctions.h new file mode 100644 index 0000000000..8b2c172bd1 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/HashFunctions.h @@ -0,0 +1,367 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Utilities for hashing. */ + +/* + * This file exports functions for hashing data down to a 32-bit value, + * including: + * + * - HashString Hash a char* or uint16_t/wchar_t* of known or unknown + * length. + * + * - HashBytes Hash a byte array of known length. + * + * - HashGeneric Hash one or more values. Currently, we support uint32_t, + * types which can be implicitly cast to uint32_t, data + * pointers, and function pointers. + * + * - AddToHash Add one or more values to the given hash. This supports the + * same list of types as HashGeneric. + * + * + * You can chain these functions together to hash complex objects. For example: + * + * class ComplexObject + * { + * char* mStr; + * uint32_t mUint1, mUint2; + * void (*mCallbackFn)(); + * + * public: + * uint32_t hash() + * { + * uint32_t hash = HashString(mStr); + * hash = AddToHash(hash, mUint1, mUint2); + * return AddToHash(hash, mCallbackFn); + * } + * }; + * + * If you want to hash an nsAString or nsACString, use the HashString functions + * in nsHashKeys.h. + */ + +#ifndef mozilla_HashFunctions_h +#define mozilla_HashFunctions_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Char16.h" +#include "mozilla/Types.h" + +#include + +#ifdef __cplusplus +namespace mozilla { + +/** + * The golden ratio as a 32-bit fixed-point value. + */ +static const uint32_t kGoldenRatioU32 = 0x9E3779B9U; + +inline uint32_t +RotateBitsLeft32(uint32_t aValue, uint8_t aBits) +{ + MOZ_ASSERT(aBits < 32); + return (aValue << aBits) | (aValue >> (32 - aBits)); +} + +namespace detail { + +inline uint32_t +AddU32ToHash(uint32_t aHash, uint32_t aValue) +{ + /* + * This is the meat of all our hash routines. This hash function is not + * particularly sophisticated, but it seems to work well for our mostly + * plain-text inputs. Implementation notes follow. + * + * Our use of the golden ratio here is arbitrary; we could pick almost any + * number which: + * + * * is odd (because otherwise, all our hash values will be even) + * + * * has a reasonably-even mix of 1's and 0's (consider the extreme case + * where we multiply by 0x3 or 0xeffffff -- this will not produce good + * mixing across all bits of the hash). + * + * The rotation length of 5 is also arbitrary, although an odd number is again + * preferable so our hash explores the whole universe of possible rotations. + * + * Finally, we multiply by the golden ratio *after* xor'ing, not before. + * Otherwise, if |aHash| is 0 (as it often is for the beginning of a + * message), the expression + * + * (kGoldenRatioU32 * RotateBitsLeft(aHash, 5)) |xor| aValue + * + * evaluates to |aValue|. + * + * (Number-theoretic aside: Because any odd number |m| is relatively prime to + * our modulus (2^32), the list + * + * [x * m (mod 2^32) for 0 <= x < 2^32] + * + * has no duplicate elements. This means that multiplying by |m| does not + * cause us to skip any possible hash values. + * + * It's also nice if |m| has large-ish order mod 2^32 -- that is, if the + * smallest k such that m^k == 1 (mod 2^32) is large -- so we can safely + * multiply our hash value by |m| a few times without negating the + * multiplicative effect. Our golden ratio constant has order 2^29, which is + * more than enough for our purposes.) + */ + return kGoldenRatioU32 * (RotateBitsLeft32(aHash, 5) ^ aValue); +} + +/** + * AddUintptrToHash takes sizeof(uintptr_t) as a template parameter. + */ +template +inline uint32_t +AddUintptrToHash(uint32_t aHash, uintptr_t aValue); + +template<> +inline uint32_t +AddUintptrToHash<4>(uint32_t aHash, uintptr_t aValue) +{ + return AddU32ToHash(aHash, static_cast(aValue)); +} + +template<> +inline uint32_t +AddUintptrToHash<8>(uint32_t aHash, uintptr_t aValue) +{ + /* + * The static cast to uint64_t below is necessary because this function + * sometimes gets compiled on 32-bit platforms (yes, even though it's a + * template and we never call this particular override in a 32-bit build). If + * we do aValue >> 32 on a 32-bit machine, we're shifting a 32-bit uintptr_t + * right 32 bits, and the compiler throws an error. + */ + uint32_t v1 = static_cast(aValue); + uint32_t v2 = static_cast(static_cast(aValue) >> 32); + return AddU32ToHash(AddU32ToHash(aHash, v1), v2); +} + +} /* namespace detail */ + +/** + * AddToHash takes a hash and some values and returns a new hash based on the + * inputs. + * + * Currently, we support hashing uint32_t's, values which we can implicitly + * convert to uint32_t, data pointers, and function pointers. + */ +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A aA) +{ + /* + * Try to convert |A| to uint32_t implicitly. If this works, great. If not, + * we'll error out. + */ + return detail::AddU32ToHash(aHash, aA); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A* aA) +{ + /* + * You might think this function should just take a void*. But then we'd only + * catch data pointers and couldn't handle function pointers. + */ + + static_assert(sizeof(aA) == sizeof(uintptr_t), "Strange pointer!"); + + return detail::AddUintptrToHash(aHash, uintptr_t(aA)); +} + +template<> +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, uintptr_t aA) +{ + return detail::AddUintptrToHash(aHash, aA); +} + +template +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB) +{ + return AddToHash(AddToHash(aHash, aA), aB); +} + +template +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC) +{ + return AddToHash(AddToHash(aHash, aA, aB), aC); +} + +template +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD) +{ + return AddToHash(AddToHash(aHash, aA, aB, aC), aD); +} + +template +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD, E aE) +{ + return AddToHash(AddToHash(aHash, aA, aB, aC, aD), aE); +} + +/** + * The HashGeneric class of functions let you hash one or more values. + * + * If you want to hash together two values x and y, calling HashGeneric(x, y) is + * much better than calling AddToHash(x, y), because AddToHash(x, y) assumes + * that x has already been hashed. + */ +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA) +{ + return AddToHash(0, aA); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB) +{ + return AddToHash(0, aA, aB); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC) +{ + return AddToHash(0, aA, aB, aC); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD) +{ + return AddToHash(0, aA, aB, aC, aD); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD, E aE) +{ + return AddToHash(0, aA, aB, aC, aD, aE); +} + +namespace detail { + +template +uint32_t +HashUntilZero(const T* aStr) +{ + uint32_t hash = 0; + for (T c; (c = *aStr); aStr++) { + hash = AddToHash(hash, c); + } + return hash; +} + +template +uint32_t +HashKnownLength(const T* aStr, size_t aLength) +{ + uint32_t hash = 0; + for (size_t i = 0; i < aLength; i++) { + hash = AddToHash(hash, aStr[i]); + } + return hash; +} + +} /* namespace detail */ + +/** + * The HashString overloads below do just what you'd expect. + * + * If you have the string's length, you might as well call the overload which + * includes the length. It may be marginally faster. + */ +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr) +{ + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} + +MOZ_WARN_UNUSED_RESULT +inline uint32_t +HashString(const unsigned char* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr) +{ + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} + +#ifdef MOZ_CHAR16_IS_NOT_WCHAR +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr) +{ + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} +#endif + +/* + * On Windows, wchar_t (char16_t) is not the same as uint16_t, even though it's + * the same width! + */ +#ifdef WIN32 +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr) +{ + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} +#endif + +/** + * Hash some number of bytes. + * + * This hash walks word-by-word, rather than byte-by-byte, so you won't get the + * same result out of HashBytes as you would out of HashString. + */ +MOZ_WARN_UNUSED_RESULT extern MFBT_API uint32_t +HashBytes(const void* bytes, size_t aLength); + +} /* namespace mozilla */ +#endif /* __cplusplus */ + +#endif /* mozilla_HashFunctions_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/IntegerPrintfMacros.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/IntegerPrintfMacros.h new file mode 100644 index 0000000000..ff2415a86f --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/IntegerPrintfMacros.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implements the C99 interface, minus the SCN* format macros. */ + +#ifndef mozilla_IntegerPrintfMacros_h_ +#define mozilla_IntegerPrintfMacros_h_ + +/* + * MSVC++ doesn't include , even in versions shipping , so + * we have to reimplement it there. Note: #includes . + * + * Note that this header DOES NOT implement 's scanf macros. MSVC's + * scanf doesn't have sufficient format specifier support to implement them + * (specifically, to implement scanning into an 8-bit location). + * + * http://stackoverflow.com/questions/3036396/scanfd-char-char-as-int-format-string + * + * Moreover, scanf is a footgun: if the input number exceeds the bounds of the + * target type, behavior is undefined (in the compiler sense: that is, this code + * could overwrite your hard drive with zeroes): + * + * uint8_t u; + * sscanf("256", "%" SCNu8, &u); // BAD + * + * This header will sometimes provide SCN* macros, by dint of being implemented + * using . But for these reasons, *never* use them! + */ + +#if defined(MOZ_CUSTOM_INTTYPES_H) +# include MOZ_CUSTOM_INTTYPES_H +#elif defined(_MSC_VER) +# include "mozilla/MSIntTypes.h" +#else +# include +#endif + +/* + * Fix up Android's broken [u]intptr_t inttype macros. Android's PRI*PTR + * macros are defined as "ld", but sizeof(long) is 8 and sizeof(intptr_t) + * is 4 on 32-bit Android. TestTypeTraits.cpp asserts that these new macro + * definitions match the actual type sizes seen at compile time. + */ +#if defined(ANDROID) && !defined(__LP64__) +# undef PRIdPTR /* intptr_t */ +# define PRIdPTR "d" /* intptr_t */ +# undef PRIiPTR /* intptr_t */ +# define PRIiPTR "i" /* intptr_t */ +# undef PRIoPTR /* uintptr_t */ +# define PRIoPTR "o" /* uintptr_t */ +# undef PRIuPTR /* uintptr_t */ +# define PRIuPTR "u" /* uintptr_t */ +# undef PRIxPTR /* uintptr_t */ +# define PRIxPTR "x" /* uintptr_t */ +# undef PRIXPTR /* uintptr_t */ +# define PRIXPTR "X" /* uintptr_t */ +#endif + +#endif /* mozilla_IntegerPrintfMacros_h_ */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Likely.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Likely.h new file mode 100644 index 0000000000..4f21609295 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Likely.h @@ -0,0 +1,23 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * MOZ_LIKELY and MOZ_UNLIKELY macros to hint to the compiler how a + * boolean predicate should be branch-predicted. + */ + +#ifndef mozilla_Likely_h +#define mozilla_Likely_h + +#if defined(__clang__) || defined(__GNUC__) +# define MOZ_LIKELY(x) (__builtin_expect(!!(x), 1)) +# define MOZ_UNLIKELY(x) (__builtin_expect(!!(x), 0)) +#else +# define MOZ_LIKELY(x) (!!(x)) +# define MOZ_UNLIKELY(x) (!!(x)) +#endif + +#endif /* mozilla_Likely_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/LinkedList.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/LinkedList.h new file mode 100644 index 0000000000..693c019f92 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/LinkedList.h @@ -0,0 +1,486 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A type-safe doubly-linked list class. */ + +/* + * The classes LinkedList and LinkedListElement together form a + * convenient, type-safe doubly-linked list implementation. + * + * The class T which will be inserted into the linked list must inherit from + * LinkedListElement. A given object may be in only one linked list at a + * time. + * + * A LinkedListElement automatically removes itself from the list upon + * destruction, and a LinkedList will fatally assert in debug builds if it's + * non-empty when it's destructed. + * + * For example, you might use LinkedList in a simple observer list class as + * follows. + * + * class Observer : public LinkedListElement + * { + * public: + * void observe(char* aTopic) { ... } + * }; + * + * class ObserverContainer + * { + * private: + * LinkedList list; + * + * public: + * void addObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is part of another list. + * list.insertBack(aObserver); + * } + * + * void removeObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is not part of some list. + * aObserver.remove(); + * // Or, will assert if |aObserver| is not part of |list| specifically. + * // aObserver.removeFrom(list); + * } + * + * void notifyObservers(char* aTopic) + * { + * for (Observer* o = list.getFirst(); o != nullptr; o = o->getNext()) { + * o->observe(aTopic); + * } + * } + * }; + * + */ + +#ifndef mozilla_LinkedList_h +#define mozilla_LinkedList_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" + +#ifdef __cplusplus + +namespace mozilla { + +template +class LinkedList; + +template +class LinkedListElement +{ + /* + * It's convenient that we return nullptr when getNext() or getPrevious() + * hits the end of the list, but doing so costs an extra word of storage in + * each linked list node (to keep track of whether |this| is the sentinel + * node) and a branch on this value in getNext/getPrevious. + * + * We could get rid of the extra word of storage by shoving the "is + * sentinel" bit into one of the pointers, although this would, of course, + * have performance implications of its own. + * + * But the goal here isn't to win an award for the fastest or slimmest + * linked list; rather, we want a *convenient* linked list. So we won't + * waste time guessing which micro-optimization strategy is best. + * + * + * Speaking of unnecessary work, it's worth addressing here why we wrote + * mozilla::LinkedList in the first place, instead of using stl::list. + * + * The key difference between mozilla::LinkedList and stl::list is that + * mozilla::LinkedList stores the mPrev/mNext pointers in the object itself, + * while stl::list stores the mPrev/mNext pointers in a list element which + * itself points to the object being stored. + * + * mozilla::LinkedList's approach makes it harder to store an object in more + * than one list. But the upside is that you can call next() / prev() / + * remove() directly on the object. With stl::list, you'd need to store a + * pointer to its iterator in the object in order to accomplish this. Not + * only would this waste space, but you'd have to remember to update that + * pointer every time you added or removed the object from a list. + * + * In-place, constant-time removal is a killer feature of doubly-linked + * lists, and supporting this painlessly was a key design criterion. + */ + +private: + LinkedListElement* mNext; + LinkedListElement* mPrev; + const bool mIsSentinel; + +public: + LinkedListElement() + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(false) + { } + + LinkedListElement(LinkedListElement&& other) + : mIsSentinel(other.mIsSentinel) + { + if (!other.isInList()) { + mNext = this; + mPrev = this; + return; + } + + MOZ_ASSERT(other.mNext->mPrev == &other); + MOZ_ASSERT(other.mPrev->mNext == &other); + + /* + * Initialize |this| with |other|'s mPrev/mNext pointers, and adjust those + * element to point to this one. + */ + mNext = other.mNext; + mPrev = other.mPrev; + + mNext->mPrev = this; + mPrev->mNext = this; + + /* + * Adjust |other| so it doesn't think it's in a list. This makes it + * safely destructable. + */ + other.mNext = &other; + other.mPrev = &other; + } + + ~LinkedListElement() + { + if (!mIsSentinel && isInList()) { + remove(); + } + } + + /* + * Get the next element in the list, or nullptr if this is the last element + * in the list. + */ + T* getNext() { return mNext->asT(); } + const T* getNext() const { return mNext->asT(); } + + /* + * Get the previous element in the list, or nullptr if this is the first + * element in the list. + */ + T* getPrevious() { return mPrev->asT(); } + const T* getPrevious() const { return mPrev->asT(); } + + /* + * Insert aElem after this element in the list. |this| must be part of a + * linked list when you call setNext(); otherwise, this method will assert. + */ + void setNext(T* aElem) + { + MOZ_ASSERT(isInList()); + setNextUnsafe(aElem); + } + + /* + * Insert aElem before this element in the list. |this| must be part of a + * linked list when you call setPrevious(); otherwise, this method will + * assert. + */ + void setPrevious(T* aElem) + { + MOZ_ASSERT(isInList()); + setPreviousUnsafe(aElem); + } + + /* + * Remove this element from the list which contains it. If this element is + * not currently part of a linked list, this method asserts. + */ + void remove() + { + MOZ_ASSERT(isInList()); + + mPrev->mNext = mNext; + mNext->mPrev = mPrev; + mNext = this; + mPrev = this; + } + + /* + * Identical to remove(), but also asserts in debug builds that this element + * is in aList. + */ + void removeFrom(const LinkedList& aList) + { + aList.assertContains(asT()); + remove(); + } + + /* + * Return true if |this| part is of a linked list, and false otherwise. + */ + bool isInList() const + { + MOZ_ASSERT((mNext == this) == (mPrev == this)); + return mNext != this; + } + +private: + friend class LinkedList; + + enum NodeKind { + NODE_KIND_NORMAL, + NODE_KIND_SENTINEL + }; + + explicit LinkedListElement(NodeKind nodeKind) + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(nodeKind == NODE_KIND_SENTINEL) + { } + + /* + * Return |this| cast to T* if we're a normal node, or return nullptr if + * we're a sentinel node. + */ + T* asT() + { + return mIsSentinel ? nullptr : static_cast(this); + } + const T* asT() const + { + return mIsSentinel ? nullptr : static_cast(this); + } + + /* + * Insert aElem after this element, but don't check that this element is in + * the list. This is called by LinkedList::insertFront(). + */ + void setNextUnsafe(T* aElem) + { + LinkedListElement *listElem = static_cast(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this->mNext; + listElem->mPrev = this; + this->mNext->mPrev = listElem; + this->mNext = listElem; + } + + /* + * Insert aElem before this element, but don't check that this element is in + * the list. This is called by LinkedList::insertBack(). + */ + void setPreviousUnsafe(T* aElem) + { + LinkedListElement* listElem = static_cast*>(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this; + listElem->mPrev = this->mPrev; + this->mPrev->mNext = listElem; + this->mPrev = listElem; + } + +private: + LinkedListElement& operator=(const LinkedListElement& aOther) MOZ_DELETE; + LinkedListElement(const LinkedListElement& aOther) MOZ_DELETE; +}; + +template +class LinkedList +{ +private: + LinkedListElement sentinel; + +public: + LinkedList() : sentinel(LinkedListElement::NODE_KIND_SENTINEL) { } + + LinkedList(LinkedList&& aOther) + : sentinel(mozilla::Move(aOther.sentinel)) + { } + + ~LinkedList() { MOZ_ASSERT(isEmpty()); } + + /* + * Add aElem to the front of the list. + */ + void insertFront(T* aElem) + { + /* Bypass setNext()'s this->isInList() assertion. */ + sentinel.setNextUnsafe(aElem); + } + + /* + * Add aElem to the back of the list. + */ + void insertBack(T* aElem) + { + sentinel.setPreviousUnsafe(aElem); + } + + /* + * Get the first element of the list, or nullptr if the list is empty. + */ + T* getFirst() { return sentinel.getNext(); } + const T* getFirst() const { return sentinel.getNext(); } + + /* + * Get the last element of the list, or nullptr if the list is empty. + */ + T* getLast() { return sentinel.getPrevious(); } + const T* getLast() const { return sentinel.getPrevious(); } + + /* + * Get and remove the first element of the list. If the list is empty, + * return nullptr. + */ + T* popFirst() + { + T* ret = sentinel.getNext(); + if (ret) { + static_cast*>(ret)->remove(); + } + return ret; + } + + /* + * Get and remove the last element of the list. If the list is empty, + * return nullptr. + */ + T* popLast() + { + T* ret = sentinel.getPrevious(); + if (ret) { + static_cast*>(ret)->remove(); + } + return ret; + } + + /* + * Return true if the list is empty, or false otherwise. + */ + bool isEmpty() const + { + return !sentinel.isInList(); + } + + /* + * Remove all the elements from the list. + * + * This runs in time linear to the list's length, because we have to mark + * each element as not in the list. + */ + void clear() + { + while (popFirst()) { + continue; + } + } + + /* + * Measures the memory consumption of the list excluding |this|. Note that + * it only measures the list elements themselves. If the list elements + * contain pointers to other memory blocks, those blocks must be measured + * separately during a subsequent iteration over the list. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const + { + size_t n = 0; + for (const T* t = getFirst(); t; t = t->getNext()) { + n += aMallocSizeOf(t); + } + return n; + } + + /* + * Like sizeOfExcludingThis(), but measures |this| as well. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const + { + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); + } + + /* + * In a debug build, make sure that the list is sane (no cycles, consistent + * mNext/mPrev pointers, only one sentinel). Has no effect in release builds. + */ + void debugAssertIsSane() const + { +#ifdef DEBUG + const LinkedListElement* slow; + const LinkedListElement* fast1; + const LinkedListElement* fast2; + + /* + * Check for cycles in the forward singly-linked list using the + * tortoise/hare algorithm. + */ + for (slow = sentinel.mNext, + fast1 = sentinel.mNext->mNext, + fast2 = sentinel.mNext->mNext->mNext; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mNext, fast1 = fast2->mNext, fast2 = fast1->mNext) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); + } + + /* Check for cycles in the backward singly-linked list. */ + for (slow = sentinel.mPrev, + fast1 = sentinel.mPrev->mPrev, + fast2 = sentinel.mPrev->mPrev->mPrev; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mPrev, fast1 = fast2->mPrev, fast2 = fast1->mPrev) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); + } + + /* + * Check that |sentinel| is the only node in the list with + * mIsSentinel == true. + */ + for (const LinkedListElement* elem = sentinel.mNext; + elem != &sentinel; + elem = elem->mNext) { + MOZ_ASSERT(!elem->mIsSentinel); + } + + /* Check that the mNext/mPrev pointers match up. */ + const LinkedListElement* prev = &sentinel; + const LinkedListElement* cur = sentinel.mNext; + do { + MOZ_ASSERT(cur->mPrev == prev); + MOZ_ASSERT(prev->mNext == cur); + + prev = cur; + cur = cur->mNext; + } while (cur != &sentinel); +#endif /* ifdef DEBUG */ + } + +private: + friend class LinkedListElement; + + void assertContains(const T* aValue) const + { +#ifdef DEBUG + for (const T* elem = getFirst(); elem; elem = elem->getNext()) { + if (elem == aValue) { + return; + } + } + MOZ_CRASH("element wasn't found in this list!"); +#endif + } + + LinkedList& operator=(const LinkedList& aOther) MOZ_DELETE; + LinkedList(const LinkedList& aOther) MOZ_DELETE; +}; + +} /* namespace mozilla */ + +#endif /* __cplusplus */ + +#endif /* mozilla_LinkedList_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MSIntTypes.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MSIntTypes.h new file mode 100644 index 0000000000..4ce922fbc5 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MSIntTypes.h @@ -0,0 +1,198 @@ +// ISO C9x compliant inttypes.h for Microsoft Visual Studio +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// +// Copyright (c) 2006 Alexander Chemeris +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. The name of the author may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _MSC_VER // [ +#error "Use this header only with Microsoft Visual C++ compilers!" +#endif // _MSC_VER ] + +#ifndef _MSC_INTTYPES_H_ // [ +#define _MSC_INTTYPES_H_ + +#if _MSC_VER > 1000 +#pragma once +#endif + +#include + +// 7.8 Format conversion of integer types + +typedef struct { + intmax_t quot; + intmax_t rem; +} imaxdiv_t; + +// 7.8.1 Macros for format specifiers + +#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 + +// The fprintf macros for signed integers are: +#define PRId8 "d" +#define PRIi8 "i" +#define PRIdLEAST8 "d" +#define PRIiLEAST8 "i" +#define PRIdFAST8 "d" +#define PRIiFAST8 "i" + +#define PRId16 "hd" +#define PRIi16 "hi" +#define PRIdLEAST16 "hd" +#define PRIiLEAST16 "hi" +#define PRIdFAST16 "hd" +#define PRIiFAST16 "hi" + +#define PRId32 "I32d" +#define PRIi32 "I32i" +#define PRIdLEAST32 "I32d" +#define PRIiLEAST32 "I32i" +#define PRIdFAST32 "I32d" +#define PRIiFAST32 "I32i" + +#define PRId64 "I64d" +#define PRIi64 "I64i" +#define PRIdLEAST64 "I64d" +#define PRIiLEAST64 "I64i" +#define PRIdFAST64 "I64d" +#define PRIiFAST64 "I64i" + +#define PRIdMAX "I64d" +#define PRIiMAX "I64i" + +#define PRIdPTR "Id" +#define PRIiPTR "Ii" + +// The fprintf macros for unsigned integers are: +#define PRIo8 "o" +#define PRIu8 "u" +#define PRIx8 "x" +#define PRIX8 "X" +#define PRIoLEAST8 "o" +#define PRIuLEAST8 "u" +#define PRIxLEAST8 "x" +#define PRIXLEAST8 "X" +#define PRIoFAST8 "o" +#define PRIuFAST8 "u" +#define PRIxFAST8 "x" +#define PRIXFAST8 "X" + +#define PRIo16 "ho" +#define PRIu16 "hu" +#define PRIx16 "hx" +#define PRIX16 "hX" +#define PRIoLEAST16 "ho" +#define PRIuLEAST16 "hu" +#define PRIxLEAST16 "hx" +#define PRIXLEAST16 "hX" +#define PRIoFAST16 "ho" +#define PRIuFAST16 "hu" +#define PRIxFAST16 "hx" +#define PRIXFAST16 "hX" + +#define PRIo32 "I32o" +#define PRIu32 "I32u" +#define PRIx32 "I32x" +#define PRIX32 "I32X" +#define PRIoLEAST32 "I32o" +#define PRIuLEAST32 "I32u" +#define PRIxLEAST32 "I32x" +#define PRIXLEAST32 "I32X" +#define PRIoFAST32 "I32o" +#define PRIuFAST32 "I32u" +#define PRIxFAST32 "I32x" +#define PRIXFAST32 "I32X" + +#define PRIo64 "I64o" +#define PRIu64 "I64u" +#define PRIx64 "I64x" +#define PRIX64 "I64X" +#define PRIoLEAST64 "I64o" +#define PRIuLEAST64 "I64u" +#define PRIxLEAST64 "I64x" +#define PRIXLEAST64 "I64X" +#define PRIoFAST64 "I64o" +#define PRIuFAST64 "I64u" +#define PRIxFAST64 "I64x" +#define PRIXFAST64 "I64X" + +#define PRIoMAX "I64o" +#define PRIuMAX "I64u" +#define PRIxMAX "I64x" +#define PRIXMAX "I64X" + +#define PRIoPTR "Io" +#define PRIuPTR "Iu" +#define PRIxPTR "Ix" +#define PRIXPTR "IX" + +// DO NOT SUPPORT THE scanf MACROS! See the comment at the top of +// IntegerPrintfMacros.h. + +#endif // __STDC_FORMAT_MACROS ] + +// 7.8.2 Functions for greatest-width integer types + +// 7.8.2.1 The imaxabs function +#define imaxabs _abs64 + +// 7.8.2.2 The imaxdiv function + +// This is modified version of div() function from Microsoft's div.c found +// in %MSVC.NET%\crt\src\div.c +#ifdef STATIC_IMAXDIV // [ +static +#else // STATIC_IMAXDIV ][ +_inline +#endif // STATIC_IMAXDIV ] +imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) +{ + imaxdiv_t result; + + result.quot = numer / denom; + result.rem = numer % denom; + + if (numer < 0 && result.rem > 0) { + // did division wrong; must fix up + ++result.quot; + result.rem -= denom; + } + + return result; +} + +// 7.8.2.3 The strtoimax and strtoumax functions +#define strtoimax _strtoi64 +#define strtoumax _strtoui64 + +// 7.8.2.4 The wcstoimax and wcstoumax functions +#define wcstoimax _wcstoi64 +#define wcstoumax _wcstoui64 + + +#endif // _MSC_INTTYPES_H_ ] diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MacroArgs.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MacroArgs.h new file mode 100644 index 0000000000..c8b7338210 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MacroArgs.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements various macros meant to ease the use of variadic macros. + */ + +#ifndef mozilla_MacroArgs_h +#define mozilla_MacroArgs_h + +/* + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) counts the number of variadic + * arguments and prefixes it with |aPrefix|. For example: + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(, foo, 42) expands to 2 + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(A, foo, 42, bar) expands to A3 + * + * You must pass in between 1 and 50 (inclusive) variadic arguments, past + * |aPrefix|. It is not legal to do + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(prefix) + * + * (that is, pass in 0 variadic arguments). To ensure that a compile-time + * error occurs when these constraints are violated, use the + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT macro with the same variaidc arguments + * wherever this macro is used. + * + * Passing (__VA_ARGS__, ) rather than simply calling + * MOZ_MACROARGS_ARG_COUNT_HELPER2(__VA_ARGS__, ) very + * carefully tiptoes around a MSVC bug where it improperly expands __VA_ARGS__ + * as a single token in argument lists. For details, see: + * + * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement + * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 + */ +#define MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) \ + MOZ_MACROARGS_ARG_COUNT_HELPER((__VA_ARGS__, \ + aPrefix##50, aPrefix##49, aPrefix##48, aPrefix##47, aPrefix##46, \ + aPrefix##45, aPrefix##44, aPrefix##43, aPrefix##42, aPrefix##41, \ + aPrefix##40, aPrefix##39, aPrefix##38, aPrefix##37, aPrefix##36, \ + aPrefix##35, aPrefix##34, aPrefix##33, aPrefix##32, aPrefix##31, \ + aPrefix##30, aPrefix##29, aPrefix##28, aPrefix##27, aPrefix##26, \ + aPrefix##25, aPrefix##24, aPrefix##23, aPrefix##22, aPrefix##21, \ + aPrefix##20, aPrefix##19, aPrefix##18, aPrefix##17, aPrefix##16, \ + aPrefix##15, aPrefix##14, aPrefix##13, aPrefix##12, aPrefix##11, \ + aPrefix##10, aPrefix##9, aPrefix##8, aPrefix##7, aPrefix##6, \ + aPrefix##5, aPrefix##4, aPrefix##3, aPrefix##2, aPrefix##1, aPrefix##0)) + +#define MOZ_MACROARGS_ARG_COUNT_HELPER(aArgs) \ + MOZ_MACROARGS_ARG_COUNT_HELPER2 aArgs + +#define MOZ_MACROARGS_ARG_COUNT_HELPER2( \ + a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, \ + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \ + a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \ + a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \ + a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \ + a51, ...) a51 + +/* + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT ensures that a compile-time error occurs + * when the argument count constraints of MOZ_PASTE_PREFIX_AND_ARG_COUNT are + * violated. Use this macro wherever MOZ_PASTE_PREFIX_AND_ARG_COUNT is used + * and pass it the same variadic arguments. + * + * This macro employs a few dirty tricks to function. To detect the zero + * argument case, |(__VA_ARGS__)| is stringified, sizeof-ed, and compared to + * what it should be in the absence of arguments. + * + * Detecting too many arguments is a little trickier. With a valid argument + * count and a prefix of 1, MOZ_PASTE_PREFIX_AND_ARG_COUNT expands to e.g. 14. + * With a prefix of 0.0, it expands to e.g. 0.04. If there are too many + * arguments, it expands to the first argument over the limit. If this + * exceeding argument is a number, the assertion will fail as there is no + * number than can simultaneously be both > 10 and == 0. If the exceeding + * argument is not a number, a compile-time error should still occur due to + * the operations performed on it. + */ +#define MOZ_MACROARGS_STRINGIFY_HELPER(x) #x +#define MOZ_STATIC_ASSERT_VALID_ARG_COUNT(...) \ + static_assert( \ + sizeof(MOZ_MACROARGS_STRINGIFY_HELPER((__VA_ARGS__))) != sizeof("()") && \ + (MOZ_PASTE_PREFIX_AND_ARG_COUNT(1, __VA_ARGS__)) > 10 && \ + (int)(MOZ_PASTE_PREFIX_AND_ARG_COUNT(0.0, __VA_ARGS__)) == 0, \ + "MOZ_STATIC_ASSERT_VALID_ARG_COUNT requires 1 to 50 arguments") /* ; */ + +/* + * MOZ_ARGS_AFTER_N expands to its arguments excluding the first |N| + * arguments. For example: + * + * MOZ_ARGS_AFTER_2(a, b, c, d) expands to: c, d + */ +#define MOZ_ARGS_AFTER_1(a1, ...) __VA_ARGS__ +#define MOZ_ARGS_AFTER_2(a1, a2, ...) __VA_ARGS__ + +/* + * MOZ_ARG_N expands to its |N|th argument. + */ +#define MOZ_ARG_1(a1, ...) a1 +#define MOZ_ARG_2(a1, a2, ...) a2 + +#endif /* mozilla_MacroArgs_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MathAlgorithms.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MathAlgorithms.h new file mode 100644 index 0000000000..9a8aa2f413 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MathAlgorithms.h @@ -0,0 +1,501 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* mfbt maths algorithms. */ + +#ifndef mozilla_MathAlgorithms_h +#define mozilla_MathAlgorithms_h + +#include "mozilla/Assertions.h" +#include "mozilla/TypeTraits.h" + +#include +#include +#include + +namespace mozilla { + +// Greatest Common Divisor +template +MOZ_ALWAYS_INLINE IntegerType +EuclidGCD(IntegerType aA, IntegerType aB) +{ + // Euclid's algorithm; O(N) in the worst case. (There are better + // ways, but we don't need them for the current use of this algo.) + MOZ_ASSERT(aA > IntegerType(0)); + MOZ_ASSERT(aB > IntegerType(0)); + + while (aA != aB) { + if (aA > aB) { + aA = aA - aB; + } else { + aB = aB - aA; + } + } + + return aA; +} + +// Least Common Multiple +template +MOZ_ALWAYS_INLINE IntegerType +EuclidLCM(IntegerType aA, IntegerType aB) +{ + // Divide first to reduce overflow risk. + return (aA / EuclidGCD(aA, aB)) * aB; +} + +namespace detail { + +template +struct AllowDeprecatedAbsFixed : FalseType {}; + +template<> struct AllowDeprecatedAbsFixed : TrueType {}; +template<> struct AllowDeprecatedAbsFixed : TrueType {}; + +template +struct AllowDeprecatedAbs : AllowDeprecatedAbsFixed {}; + +template<> struct AllowDeprecatedAbs : TrueType {}; +template<> struct AllowDeprecatedAbs : TrueType {}; + +} // namespace detail + +// DO NOT USE DeprecatedAbs. It exists only until its callers can be converted +// to Abs below, and it will be removed when all callers have been changed. +template +inline typename mozilla::EnableIf::value, T>::Type +DeprecatedAbs(const T aValue) +{ + // The absolute value of the smallest possible value of a signed-integer type + // won't fit in that type (on twos-complement systems -- and we're blithely + // assuming we're on such systems, for the non- types listed above), + // so assert that the input isn't that value. + // + // This is the case if: the value is non-negative; or if adding one (giving a + // value in the range [-maxvalue, 0]), then negating (giving a value in the + // range [0, maxvalue]), doesn't produce maxvalue (because in twos-complement, + // (minvalue + 1) == -maxvalue). + MOZ_ASSERT(aValue >= 0 || + -(aValue + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1), + "You can't negate the smallest possible negative integer!"); + return aValue >= 0 ? aValue : -aValue; +} + +namespace detail { + +// For now mozilla::Abs only takes intN_T, the signed natural types, and +// float/double/long double. Feel free to add overloads for other standard, +// signed types if you need them. + +template +struct AbsReturnTypeFixed; + +template<> struct AbsReturnTypeFixed { typedef uint8_t Type; }; +template<> struct AbsReturnTypeFixed { typedef uint16_t Type; }; +template<> struct AbsReturnTypeFixed { typedef uint32_t Type; }; +template<> struct AbsReturnTypeFixed { typedef uint64_t Type; }; + +template +struct AbsReturnType : AbsReturnTypeFixed {}; + +template<> struct AbsReturnType : + EnableIf {}; +template<> struct AbsReturnType { typedef unsigned char Type; }; +template<> struct AbsReturnType { typedef unsigned short Type; }; +template<> struct AbsReturnType { typedef unsigned int Type; }; +template<> struct AbsReturnType { typedef unsigned long Type; }; +template<> struct AbsReturnType { typedef unsigned long long Type; }; +template<> struct AbsReturnType { typedef float Type; }; +template<> struct AbsReturnType { typedef double Type; }; +template<> struct AbsReturnType { typedef long double Type; }; + +} // namespace detail + +template +inline typename detail::AbsReturnType::Type +Abs(const T aValue) +{ + typedef typename detail::AbsReturnType::Type ReturnType; + return aValue >= 0 ? ReturnType(aValue) : ~ReturnType(aValue) + 1; +} + +template<> +inline float +Abs(const float aFloat) +{ + return std::fabs(aFloat); +} + +template<> +inline double +Abs(const double aDouble) +{ + return std::fabs(aDouble); +} + +template<> +inline long double +Abs(const long double aLongDouble) +{ + return std::fabs(aLongDouble); +} + +} // namespace mozilla + +#if defined(_WIN32) && (_MSC_VER >= 1300) && \ + (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) || defined(_M_ARM)) +# define MOZ_BITSCAN_WINDOWS + +# include +# pragma intrinsic(_BitScanForward, _BitScanReverse) + +# if defined(_M_AMD64) || defined(_M_X64) +# define MOZ_BITSCAN_WINDOWS64 +# pragma intrinsic(_BitScanForward64, _BitScanReverse64) +# endif + +#endif + +namespace mozilla { + +namespace detail { + +#if defined(MOZ_BITSCAN_WINDOWS) + +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanReverse(&index, static_cast(aValue)); + return uint_fast8_t(31 - index); +} + + +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanForward(&index, static_cast(aValue)); + return uint_fast8_t(index); +} + +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + uint32_t x = aValue - ((aValue >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + return (((x + (x >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; +} +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return uint_fast8_t(CountPopulation32(aValue & 0xffffffff) + + CountPopulation32(aValue >> 32)); +} + +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanReverse64(&index, static_cast(aValue)); + return uint_fast8_t(63 - index); +#else + uint32_t hi = uint32_t(aValue >> 32); + if (hi != 0) { + return CountLeadingZeroes32(hi); + } + return 32u + CountLeadingZeroes32(uint32_t(aValue)); +#endif +} + +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanForward64(&index, static_cast(aValue)); + return uint_fast8_t(index); +#else + uint32_t lo = uint32_t(aValue); + if (lo != 0) { + return CountTrailingZeroes32(lo); + } + return 32u + CountTrailingZeroes32(uint32_t(aValue >> 32)); +#endif +} + +# ifdef MOZ_HAVE_BITSCAN64 +# undef MOZ_HAVE_BITSCAN64 +# endif + +#elif defined(__clang__) || defined(__GNUC__) + +# if defined(__clang__) +# if !__has_builtin(__builtin_ctz) || !__has_builtin(__builtin_clz) +# error "A clang providing __builtin_c[lt]z is required to build" +# endif +# else + // gcc has had __builtin_clz and friends since 3.4: no need to check. +# endif + +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + return __builtin_clz(aValue); +} + +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + return __builtin_ctz(aValue); +} + +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + return __builtin_popcount(aValue); +} + +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return __builtin_popcountll(aValue); +} + +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ + return __builtin_clzll(aValue); +} + +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ + return __builtin_ctzll(aValue); +} + +#else +# error "Implement these!" +inline uint_fast8_t CountLeadingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountLeadingZeroes64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes64(uint64_t aValue) MOZ_DELETE; +#endif + +} // namespace detail + +/** + * Compute the number of high-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * highest- valued bits at the start, return the number of zeroes before the + * first one is observed. + * + * CountLeadingZeroes32(0xF0FF1000) is 0; + * CountLeadingZeroes32(0x7F8F0001) is 1; + * CountLeadingZeroes32(0x3FFF0100) is 2; + * CountLeadingZeroes32(0x1FF50010) is 3; and so on. + */ +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes32(aValue); +} + +/** + * Compute the number of low-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * lowest- valued bits at the start, return the number of zeroes before the + * first one is observed. + * + * CountTrailingZeroes32(0x0100FFFF) is 0; + * CountTrailingZeroes32(0x7000FFFE) is 1; + * CountTrailingZeroes32(0x0080FFFC) is 2; + * CountTrailingZeroes32(0x0080FFF8) is 3; and so on. + */ +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes32(aValue); +} + +/** + * Compute the number of one bits in the number |aValue|, + */ +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + return detail::CountPopulation32(aValue); +} + +/** Analogous to CoutPopulation32, but for 64-bit numbers */ +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return detail::CountPopulation64(aValue); +} + +/** Analogous to CountLeadingZeroes32, but for 64-bit numbers. */ +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes64(aValue); +} + +/** Analogous to CountTrailingZeroes32, but for 64-bit numbers. */ +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes64(aValue); +} + +namespace detail { + +template +class CeilingLog2; + +template +class CeilingLog2 +{ +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0u : 32u - CountLeadingZeroes32(aValue - 1); + } +}; + +template +class CeilingLog2 +{ +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0 : 64 - CountLeadingZeroes64(aValue - 1); + } +}; + +} // namespace detail + +/** + * Compute the log of the least power of 2 greater than or equal to |aValue|. + * + * CeilingLog2(0..1) is 0; + * CeilingLog2(2) is 1; + * CeilingLog2(3..4) is 2; + * CeilingLog2(5..8) is 3; + * CeilingLog2(9..16) is 4; and so on. + */ +template +inline uint_fast8_t +CeilingLog2(const T aValue) +{ + return detail::CeilingLog2::compute(aValue); +} + +/** A CeilingLog2 variant that accepts only size_t. */ +inline uint_fast8_t +CeilingLog2Size(size_t aValue) +{ + return CeilingLog2(aValue); +} + +namespace detail { + +template +class FloorLog2; + +template +class FloorLog2 +{ +public: + static uint_fast8_t compute(const T aValue) + { + return 31u - CountLeadingZeroes32(aValue | 1); + } +}; + +template +class FloorLog2 +{ +public: + static uint_fast8_t compute(const T aValue) + { + return 63u - CountLeadingZeroes64(aValue | 1); + } +}; + +} // namespace detail + +/** + * Compute the log of the greatest power of 2 less than or equal to |aValue|. + * + * FloorLog2(0..1) is 0; + * FloorLog2(2..3) is 1; + * FloorLog2(4..7) is 2; + * FloorLog2(8..15) is 3; and so on. + */ +template +inline uint_fast8_t +FloorLog2(const T aValue) +{ + return detail::FloorLog2::compute(aValue); +} + +/** A FloorLog2 variant that accepts only size_t. */ +inline uint_fast8_t +FloorLog2Size(size_t aValue) +{ + return FloorLog2(aValue); +} + +/* + * Compute the smallest power of 2 greater than or equal to |x|. |x| must not + * be so great that the computed value would overflow |size_t|. + */ +inline size_t +RoundUpPow2(size_t aValue) +{ + MOZ_ASSERT(aValue <= (size_t(1) << (sizeof(size_t) * CHAR_BIT - 1)), + "can't round up -- will overflow!"); + return size_t(1) << CeilingLog2(aValue); +} + +/** + * Rotates the bits of the given value left by the amount of the shift width. + */ +template +inline T +RotateLeft(const T aValue, uint_fast8_t aShift) +{ + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + static_assert(IsUnsigned::value, "Rotates require unsigned values"); + return (aValue << aShift) | (aValue >> (sizeof(T) * CHAR_BIT - aShift)); +} + +/** + * Rotates the bits of the given value right by the amount of the shift width. + */ +template +inline T +RotateRight(const T aValue, uint_fast8_t aShift) +{ + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + static_assert(IsUnsigned::value, "Rotates require unsigned values"); + return (aValue >> aShift) | (aValue << (sizeof(T) * CHAR_BIT - aShift)); +} + +} /* namespace mozilla */ + +#endif /* mozilla_MathAlgorithms_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Maybe.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Maybe.h new file mode 100644 index 0000000000..4ba88f6771 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Maybe.h @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A class for lazily constructing an object without sticking it on the heap. */ + +#ifndef mozilla_Maybe_h +#define mozilla_Maybe_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" + +// For placement new +#include + +namespace mozilla { + +/* + * Small utility for lazily constructing objects without using dynamic storage. + * When a Maybe is constructed, it is |empty()|, i.e., no value of T has + * been constructed and no T destructor will be called when the Maybe is + * destroyed. Upon calling |construct|, a T object will be constructed with the + * given arguments and that object will be destroyed when the owning Maybe + * is destroyed. + * + * N.B. GCC seems to miss some optimizations with Maybe and may generate extra + * branches/loads/stores. Use with caution on hot paths. + */ +template +class Maybe +{ + AlignedStorage2 storage; + bool constructed; + + T& asT() { return *storage.addr(); } + +public: + Maybe() { constructed = false; } + ~Maybe() { if (constructed) { asT().~T(); } } + + bool empty() const { return !constructed; } + + void construct() + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(); + constructed = true; + } + + template + void construct(const T1& aT1) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9, const T10& aT10) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9, aT10); + constructed = true; + } + + T* addr() + { + MOZ_ASSERT(constructed); + return &asT(); + } + + T& ref() + { + MOZ_ASSERT(constructed); + return asT(); + } + + const T& ref() const + { + MOZ_ASSERT(constructed); + return const_cast(this)->asT(); + } + + void destroy() + { + ref().~T(); + constructed = false; + } + + void destroyIfConstructed() + { + if (!empty()) { + destroy(); + } + } + +private: + Maybe(const Maybe& aOther) MOZ_DELETE; + const Maybe& operator=(const Maybe& aOther) MOZ_DELETE; +}; + +} // namespace mozilla + +#endif /* mozilla_Maybe_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MemoryChecking.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MemoryChecking.h new file mode 100644 index 0000000000..0642d758c0 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MemoryChecking.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Provides a common interface to the ASan (AddressSanitizer) and Valgrind + * functions used to mark memory in certain ways. In detail, the following + * three macros are provided: + * + * MOZ_MAKE_MEM_NOACCESS - Mark memory as unsafe to access (e.g. freed) + * MOZ_MAKE_MEM_UNDEFINED - Mark memory as accessible, with content undefined + * MOZ_MAKE_MEM_DEFINED - Mark memory as accessible, with content defined + * + * With Valgrind in use, these directly map to the three respective Valgrind + * macros. With ASan in use, the NOACCESS macro maps to poisoning the memory, + * while the UNDEFINED/DEFINED macros unpoison memory. + * + * With no memory checker available, all macros expand to the empty statement. + */ + +#ifndef mozilla_MemoryChecking_h +#define mozilla_MemoryChecking_h + +#if defined(MOZ_VALGRIND) +#include "valgrind/memcheck.h" +#endif + +#if defined(MOZ_ASAN) || defined(MOZ_VALGRIND) +#define MOZ_HAVE_MEM_CHECKS 1 +#endif + +#if defined(MOZ_ASAN) +#include + +#include "mozilla/Types.h" + +extern "C" { +/* These definitions are usually provided through the + * sanitizer/asan_interface.h header installed by ASan. + */ +void MOZ_EXPORT __asan_poison_memory_region(void const volatile *addr, size_t size); +void MOZ_EXPORT __asan_unpoison_memory_region(void const volatile *addr, size_t size); + +#define MOZ_MAKE_MEM_NOACCESS(addr, size) \ + __asan_poison_memory_region((addr), (size)) + +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) \ + __asan_unpoison_memory_region((addr), (size)) + +#define MOZ_MAKE_MEM_DEFINED(addr, size) \ + __asan_unpoison_memory_region((addr), (size)) +} +#elif defined(MOZ_VALGRIND) +#define MOZ_MAKE_MEM_NOACCESS(addr, size) \ + VALGRIND_MAKE_MEM_NOACCESS((addr), (size)) + +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) \ + VALGRIND_MAKE_MEM_UNDEFINED((addr), (size)) + +#define MOZ_MAKE_MEM_DEFINED(addr, size) \ + VALGRIND_MAKE_MEM_DEFINED((addr), (size)) +#else + +#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while (0) + +#endif + +#endif /* mozilla_MemoryChecking_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MemoryReporting.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MemoryReporting.h new file mode 100644 index 0000000000..d2340ecf09 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/MemoryReporting.h @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Memory reporting infrastructure. */ + +#ifndef mozilla_MemoryReporting_h +#define mozilla_MemoryReporting_h + +#include + +#ifdef __cplusplus + +namespace mozilla { + +/* + * This is for functions that are like malloc_usable_size. Such functions are + * used for measuring the size of data structures. + */ +typedef size_t (*MallocSizeOf)(const void* p); + +} /* namespace mozilla */ + +#endif /* __cplusplus */ + +typedef size_t (*MozMallocSizeOf)(const void* p); + +#endif /* mozilla_MemoryReporting_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Move.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Move.h new file mode 100644 index 0000000000..08ae86fa57 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Move.h @@ -0,0 +1,250 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* C++11-style, but C++98-usable, "move references" implementation. */ + +#ifndef mozilla_Move_h +#define mozilla_Move_h + +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +/* + * "Move" References + * + * Some types can be copied much more efficiently if we know the original's + * value need not be preserved --- that is, if we are doing a "move", not a + * "copy". For example, if we have: + * + * Vector u; + * Vector v(u); + * + * the constructor for v must apply a copy constructor to each element of u --- + * taking time linear in the length of u. However, if we know we will not need u + * any more once v has been initialized, then we could initialize v very + * efficiently simply by stealing u's dynamically allocated buffer and giving it + * to v --- a constant-time operation, regardless of the size of u. + * + * Moves often appear in container implementations. For example, when we append + * to a vector, we may need to resize its buffer. This entails moving each of + * its extant elements from the old, smaller buffer to the new, larger buffer. + * But once the elements have been migrated, we're just going to throw away the + * old buffer; we don't care if they still have their values. So if the vector's + * element type can implement "move" more efficiently than "copy", the vector + * resizing should by all means use a "move" operation. Hash tables should also + * use moves when resizing their internal array as entries are added and + * removed. + * + * The details of the optimization, and whether it's worth applying, vary + * from one type to the next: copying an 'int' is as cheap as moving it, so + * there's no benefit in distinguishing 'int' moves from copies. And while + * some constructor calls for complex types are moves, many really have to + * be copies, and can't be optimized this way. So we need: + * + * 1) a way for a type (like Vector) to announce that it can be moved more + * efficiently than it can be copied, and provide an implementation of that + * move operation; and + * + * 2) a way for a particular invocation of a copy constructor to say that it's + * really a move, not a copy, and that the value of the original isn't + * important afterwards (although it must still be safe to destroy). + * + * If a constructor has a single argument of type 'T&&' (an 'rvalue reference + * to T'), that indicates that it is a 'move constructor'. That's 1). It should + * move, not copy, its argument into the object being constructed. It may leave + * the original in any safely-destructible state. + * + * If a constructor's argument is an rvalue, as in 'C(f(x))' or 'C(x + y)', as + * opposed to an lvalue, as in 'C(x)', then overload resolution will prefer the + * move constructor, if there is one. The 'mozilla::Move' function, defined in + * this file, is an identity function you can use in a constructor invocation to + * make any argument into an rvalue, like this: C(Move(x)). That's 2). (You + * could use any function that works, but 'Move' indicates your intention + * clearly.) + * + * Where we might define a copy constructor for a class C like this: + * + * C(const C& rhs) { ... copy rhs to this ... } + * + * we would declare a move constructor like this: + * + * C(C&& rhs) { .. move rhs to this ... } + * + * And where we might perform a copy like this: + * + * C c2(c1); + * + * we would perform a move like this: + * + * C c2(Move(c1)); + * + * Note that 'T&&' implicitly converts to 'T&'. So you can pass a 'T&&' to an + * ordinary copy constructor for a type that doesn't support a special move + * constructor, and you'll just get a copy. This means that templates can use + * Move whenever they know they won't use the original value any more, even if + * they're not sure whether the type at hand has a specialized move constructor. + * If it doesn't, the 'T&&' will just convert to a 'T&', and the ordinary copy + * constructor will apply. + * + * A class with a move constructor can also provide a move assignment operator. + * A generic definition would run this's destructor, and then apply the move + * constructor to *this's memory. A typical definition: + * + * C& operator=(C&& rhs) { + * MOZ_ASSERT(&rhs != this, "self-moves are prohibited"); + * this->~C(); + * new(this) C(Move(rhs)); + * return *this; + * } + * + * With that in place, one can write move assignments like this: + * + * c2 = Move(c1); + * + * This destroys c2, moves c1's value to c2, and leaves c1 in an undefined but + * destructible state. + * + * As we say, a move must leave the original in a "destructible" state. The + * original's destructor will still be called, so if a move doesn't + * actually steal all its resources, that's fine. We require only that the + * move destination must take on the original's value; and that destructing + * the original must not break the move destination. + * + * (Opinions differ on whether move assignment operators should deal with move + * assignment of an object onto itself. It seems wise to either handle that + * case, or assert that it does not occur.) + * + * Forwarding: + * + * Sometimes we want copy construction or assignment if we're passed an ordinary + * value, but move construction if passed an rvalue reference. For example, if + * our constructor takes two arguments and either could usefully be a move, it + * seems silly to write out all four combinations: + * + * C::C(X& x, Y& y) : x(x), y(y) { } + * C::C(X& x, Y&& y) : x(x), y(Move(y)) { } + * C::C(X&& x, Y& y) : x(Move(x)), y(y) { } + * C::C(X&& x, Y&& y) : x(Move(x)), y(Move(y)) { } + * + * To avoid this, C++11 has tweaks to make it possible to write what you mean. + * The four constructor overloads above can be written as one constructor + * template like so[0]: + * + * template + * C::C(XArg&& x, YArg&& y) : x(Forward(x)), y(Forward(y)) { } + * + * ("'Don't Repeat Yourself'? What's that?") + * + * This takes advantage of two new rules in C++11: + * + * - First, when a function template takes an argument that is an rvalue + * reference to a template argument (like 'XArg&& x' and 'YArg&& y' above), + * then when the argument is applied to an lvalue, the template argument + * resolves to 'T&'; and when it is applied to an rvalue, the template + * argument resolves to 'T&&'. Thus, in a call to C::C like: + * + * X foo(int); + * Y yy; + * + * C(foo(5), yy) + * + * XArg would resolve to 'X&&', and YArg would resolve to 'Y&'. + * + * - Second, Whereas C++ used to forbid references to references, C++11 defines + * 'collapsing rules': 'T& &', 'T&& &', and 'T& &&' (that is, any combination + * involving an lvalue reference) now collapse to simply 'T&'; and 'T&& &&' + * collapses to 'T&&'. + * + * Thus, in the call above, 'XArg&&' is 'X&& &&', collapsing to 'X&&'; and + * 'YArg&&' is 'Y& &&', which collapses to 'Y &'. Because the arguments are + * declared as rvalue references to template arguments, the rvalue-ness + * "shines through" where present. + * + * Then, the 'Forward' function --- you must invoke 'Forward' with its type + * argument --- returns an lvalue reference or an rvalue reference to its + * argument, depending on what T is. In our unified constructor definition, that + * means that we'll invoke either the copy or move constructors for x and y, + * depending on what we gave C's constructor. In our call, we'll move 'foo()' + * into 'x', but copy 'yy' into 'y'. + * + * This header file defines Move and Forward in the mozilla namespace. It's up + * to individual containers to annotate moves as such, by calling Move; and it's + * up to individual types to define move constructors and assignment operators + * when valuable. + * + * (C++11 says that the header file should define 'std::move' and + * 'std::forward', which are just like our 'Move' and 'Forward'; but those + * definitions aren't available in that header on all our platforms, so we + * define them ourselves here.) + * + * 0. This pattern is known as "perfect forwarding". Interestingly, it is not + * actually perfect, and it can't forward all possible argument expressions! + * There are two issues: one that's a C++11 issue, and one that's a legacy + * compiler issue. + * + * The C++11 issue is that you can't form a reference to a bit-field. As a + * workaround, assign the bit-field to a local variable and use that: + * + * // C is as above + * struct S { int x : 1; } s; + * C(s.x, 0); // BAD: s.x is a reference to a bit-field, can't form those + * int tmp = s.x; + * C(tmp, 0); // OK: tmp not a bit-field + * + * The legacy issue is that when we don't have true nullptr and must emulate + * it (gcc 4.4/4.5), forwarding |nullptr| results in an |int| or |long| + * forwarded reference. But such a reference, even if its value is a null + * pointer constant expression, is not itself a null pointer constant + * expression. This causes -Werror=conversion-null errors and pointer-to- + * integer comparison errors. Until we always have true nullptr, users of + * forwarding methods must not pass |nullptr| to them. + */ + +/** + * Identical to std::Move(); this is necessary until our stlport supports + * std::move(). + */ +template +inline typename RemoveReference::Type&& +Move(T&& aX) +{ + return static_cast::Type&&>(aX); +} + +/** + * These two overloads are identical to std::forward(); they are necessary until + * our stlport supports std::forward(). + */ +template +inline T&& +Forward(typename RemoveReference::Type& aX) +{ + return static_cast(aX); +} + +template +inline T&& +Forward(typename RemoveReference::Type&& aX) +{ + static_assert(!IsLvalueReference::value, + "misuse of Forward detected! try the other overload"); + return static_cast(aX); +} + +/** Swap |aX| and |aY| using move-construction if possible. */ +template +inline void +Swap(T& aX, T& aY) +{ + T tmp(Move(aX)); + aX = Move(aY); + aY = Move(tmp); +} + +} // namespace mozilla + +#endif /* mozilla_Move_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/NullPtr.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/NullPtr.h new file mode 100644 index 0000000000..5963613c4b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/NullPtr.h @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements a workaround for compilers which do not support the C++11 nullptr + * constant. + */ + +#ifndef mozilla_NullPtr_h +#define mozilla_NullPtr_h + +#if defined(__clang__) +# if !__has_extension(cxx_nullptr) +# error "clang version natively supporting nullptr is required." +# endif +# define MOZ_HAVE_CXX11_NULLPTR +#elif defined(__GNUC__) +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# include "mozilla/Compiler.h" +# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) +# define MOZ_HAVE_CXX11_NULLPTR +# endif +# endif +#elif defined(_MSC_VER) + // The minimum supported MSVC (10, _MSC_VER 1600) supports nullptr. +# define MOZ_HAVE_CXX11_NULLPTR +#endif + +namespace mozilla { + +/** + * IsNullPointer::value is true iff T is the type of C++11's nullptr. If + * nullptr is emulated, IsNullPointer::value is false for all T. + * + * IsNullPointer is useful to give an argument the true decltype(nullptr) type. + * decltype(nullptr) doesn't work when nullptr is emulated. The simplest + * workaround is to use template overloading and SFINAE to expose an overload + * only if an argument's type is decltype(nullptr). Some examples (that assume + * namespace mozilla has been opened, for simplicity): + * + * // foo(T*), foo(stuff that converts to T*), and foo(decltype(nullptr)) + * // (only invoked if nullptr is true nullptr, otherwise foo(T*) is invoked) + * // but nothing else + * void foo(T*) { } + * template + * void foo(N, + * typename EnableIf::value, int>::Type dummy = 0) + * { } + * + * // foo(T*) *exactly* and foo(decltype(nullptr)), nothing else + * void foo(T*) { } + * template + * void foo(U, + * typename EnableIf::value, int>::Type dummy = 0) + * MOZ_DELETE; + * + * The exact details of how set up the SFINAE bits vary on a case-by-case basis. + * If you need help with this (and unless you've internalized way more sadmaking + * nullptr-emulation knowledge than you should have, you do), feel free to poke + * the person with blame on this comment with questions. :-) + * + * Ideally this would be in TypeTraits.h, but C++11 omitted std::is_null_pointer + * (fixed in C++1y), so in the interests of easing a switch to , + * this trait lives elsewhere. + */ +template +struct IsNullPointer { static const bool value = false; }; + +} // namespace mozilla + +/** + * mozilla::NullptrT is a type that's sort of like decltype(nullptr). But it + * can't be identical, because emulated nullptr doesn't have a distinct type. + * Only with gcc 4.4/4.5, emulated nullptr is __null, and decltype(__null) is + * int or long. But passing __null to an int/long parameter triggers + * -Werror=conversion-null errors with gcc 4.5, or (depending on subsequent use + * inside the overloaded function) can trigger pointer-to-integer comparison + * compiler errors. So fairly often, actually, NullptrT is *not* what you want. + * + * Instead, often you should use template-based overloading in concert with + * SFINAE to add a nullptr overload -- see the comments by IsNullPointer. + * + * So when *should* you use NullptrT? Thus far, the only truly good use seems + * to be as an argument type for operator overloads (because C++ doesn't allow + * operator= to have more than one argument, operator== to have more than two, + * &c.). But even in such cases, it really only works if there are no other + * overloads of the operator that accept a pointer type. If you want both T* + * and nullptr_t overloads, you'll have to wait til we drop gcc 4.4/4.5 support. + * (Currently b2g is the only impediment to this.) + */ +#ifdef MOZ_HAVE_CXX11_NULLPTR +// decltype does the right thing for actual nullptr. +namespace mozilla { +typedef decltype(nullptr) NullptrT; +template<> +struct IsNullPointer { static const bool value = true; }; +} +# undef MOZ_HAVE_CXX11_NULLPTR +#elif MOZ_IS_GCC +# define nullptr __null +// void* sweeps up more than just nullptr, but compilers supporting true +// nullptr are the majority now, so they should detect mistakes. If you're +// feeling paranoid, check/assert that your NullptrT equals nullptr. +namespace mozilla { typedef void* NullptrT; } +#else +# error "No compiler support for nullptr or its emulation." +#endif + +#endif /* mozilla_NullPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/NumericLimits.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/NumericLimits.h new file mode 100644 index 0000000000..730fcb410b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/NumericLimits.h @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Compatibility with std::numeric_limits. */ + +#ifndef mozilla_NumericLimits_h +#define mozilla_NumericLimits_h + +#include "mozilla/Char16.h" + +#include +#include + +namespace mozilla { + +/** + * The NumericLimits class provides a compatibility layer with + * std::numeric_limits for char16_t, otherwise it is exactly the same as + * std::numeric_limits. Code which does not need std::numeric_limits + * should avoid using NumericLimits. + */ +template +class NumericLimits : public std::numeric_limits +{ +}; + +#ifdef MOZ_CHAR16_IS_NOT_WCHAR +template<> +class NumericLimits : public std::numeric_limits +{ + // char16_t and uint16_t numeric limits should be exactly the same. +}; +#endif + +} // namespace mozilla + +#endif /* mozilla_NumericLimits_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Pair.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Pair.h new file mode 100644 index 0000000000..e9e8a76938 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Pair.h @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A class holding a pair of objects that tries to conserve storage space. */ + +#ifndef mozilla_Pair_h +#define mozilla_Pair_h + +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +namespace detail { + +enum StorageType { AsBase, AsMember }; + +// Optimize storage using the Empty Base Optimization -- that empty base classes +// don't take up space -- to optimize size when one or the other class is +// stateless and can be used as a base class. +// +// The extra conditions on storage for B are necessary so that PairHelper won't +// ambiguously inherit from either A or B, such that one or the other base class +// would be inaccessible. +template::value ? detail::AsBase : detail::AsMember, + detail::StorageType = + IsEmpty::value && !IsBaseOf::value && !IsBaseOf::value + ? detail::AsBase + : detail::AsMember> +struct PairHelper; + +template +struct PairHelper +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : mFirstA(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(mSecondB, aOther.mSecondB); + } + +private: + A mFirstA; + B mSecondB; +}; + +template +struct PairHelper : private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : B(Forward(aB)), + mFirstA(Forward(aA)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return *this; } + const B& second() const { return *this; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(static_cast(*this), static_cast(aOther)); + } + +private: + A mFirstA; +}; + +template +struct PairHelper : private A +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return *this; } + const A& first() const { return *this; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(mSecondB, aOther.mSecondB); + } + +private: + B mSecondB; +}; + +template +struct PairHelper : private A, private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + B(Forward(aB)) + {} + + A& first() { return static_cast(*this); } + const A& first() const { return static_cast(*this); } + B& second() { return static_cast(*this); } + const B& second() const { return static_cast(*this); } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(static_cast(*this), static_cast(aOther)); + } +}; + +} // namespace detail + +/** + * Pair is the logical concatenation of an instance of A with an instance B. + * Space is conserved when possible. Neither A nor B may be a final class. + * + * It's typically clearer to have individual A and B member fields. Except if + * you want the space-conserving qualities of Pair, you're probably better off + * not using this! + * + * No guarantees are provided about the memory layout of A and B, the order of + * initialization or destruction of A and B, and so on. (This is approximately + * required to optimize space usage.) The first/second names are merely + * conceptual! + */ +template +struct Pair + : private detail::PairHelper +{ + typedef typename detail::PairHelper Base; + +public: + template + Pair(AArg&& aA, BArg&& aB) + : Base(Forward(aA), Forward(aB)) + {} + + /** The A instance. */ + using Base::first; + /** The B instance. */ + using Base::second; + + /** Swap this pair with another pair. */ + void swap(Pair& aOther) { Base::swap(aOther); } + +private: + Pair(const Pair&) MOZ_DELETE; +}; + +template +void +Swap(Pair& aX, Pair& aY) +{ + aX.swap(aY); +} + +} // namespace mozilla + +#endif /* mozilla_Pair_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/PodOperations.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/PodOperations.h new file mode 100644 index 0000000000..843e1311d3 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/PodOperations.h @@ -0,0 +1,195 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Operations for zeroing POD types, arrays, and so on. + * + * These operations are preferable to memset, memcmp, and the like because they + * don't require remembering to multiply by sizeof(T), array lengths, and so on + * everywhere. + */ + +#ifndef mozilla_PodOperations_h +#define mozilla_PodOperations_h + +#include "mozilla/Array.h" +#include "mozilla/ArrayUtils.h" +#include "mozilla/Attributes.h" + +#include +#include + +namespace mozilla { + +/** Set the contents of |aT| to 0. */ +template +static MOZ_ALWAYS_INLINE void +PodZero(T* aT) +{ + memset(aT, 0, sizeof(T)); +} + +/** Set the contents of |aNElem| elements starting at |aT| to 0. */ +template +static MOZ_ALWAYS_INLINE void +PodZero(T* aT, size_t aNElem) +{ + /* + * This function is often called with 'aNElem' small; we use an inline loop + * instead of calling 'memset' with a non-constant length. The compiler + * should inline the memset call with constant size, though. + */ + for (T* end = aT + aNElem; aT < end; aT++) { + memset(aT, 0, sizeof(T)); + } +} + +/* + * Arrays implicitly convert to pointers to their first element, which is + * dangerous when combined with the above PodZero definitions. Adding an + * overload for arrays is ambiguous, so we need another identifier. The + * ambiguous overload is left to catch mistaken uses of PodZero; if you get a + * compile error involving PodZero and array types, use PodArrayZero instead. + */ +template +static void PodZero(T (&aT)[N]) MOZ_DELETE; +template +static void PodZero(T (&aT)[N], size_t aNElem) MOZ_DELETE; + +/** Set the contents of the array |aT| to zero. */ +template +static MOZ_ALWAYS_INLINE void +PodArrayZero(T (&aT)[N]) +{ + memset(aT, 0, N * sizeof(T)); +} + +template +static MOZ_ALWAYS_INLINE void +PodArrayZero(Array& aArr) +{ + memset(&aArr[0], 0, N * sizeof(T)); +} + +/** + * Assign |*aSrc| to |*aDst|. The locations must not be the same and must not + * overlap. + */ +template +static MOZ_ALWAYS_INLINE void +PodAssign(T* aDst, const T* aSrc) +{ + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= 1); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= 1); + memcpy(reinterpret_cast(aDst), reinterpret_cast(aSrc), + sizeof(T)); +} + +/** + * Copy |aNElem| T elements from |aSrc| to |aDst|. The two memory ranges must + * not overlap! + */ +template +static MOZ_ALWAYS_INLINE void +PodCopy(T* aDst, const T* aSrc, size_t aNElem) +{ + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); + + if (aNElem < 128) { + /* + * Avoid using operator= in this loop, as it may have been + * intentionally deleted by the POD type. + */ + for (const T* srcend = aSrc + aNElem; aSrc < srcend; aSrc++, aDst++) { + PodAssign(aDst, aSrc); + } + } else { + memcpy(aDst, aSrc, aNElem * sizeof(T)); + } +} + +template +static MOZ_ALWAYS_INLINE void +PodCopy(volatile T* aDst, const volatile T* aSrc, size_t aNElem) +{ + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); + + /* + * Volatile |aDst| requires extra work, because it's undefined behavior to + * modify volatile objects using the mem* functions. Just write out the + * loops manually, using operator= rather than memcpy for the same reason, + * and let the compiler optimize to the extent it can. + */ + for (const volatile T* srcend = aSrc + aNElem; + aSrc < srcend; + aSrc++, aDst++) { + *aDst = *aSrc; + } +} + +/* + * Copy the contents of the array |aSrc| into the array |aDst|, both of size N. + * The arrays must not overlap! + */ +template +static MOZ_ALWAYS_INLINE void +PodArrayCopy(T (&aDst)[N], const T (&aSrc)[N]) +{ + PodCopy(aDst, aSrc, N); +} + +/** + * Copy the memory for |aNElem| T elements from |aSrc| to |aDst|. If the two + * memory ranges overlap, then the effect is as if the |aNElem| elements are + * first copied from |aSrc| to a temporary array, and then from the temporary + * array to |aDst|. + */ +template +static MOZ_ALWAYS_INLINE void +PodMove(T* aDst, const T* aSrc, size_t aNElem) +{ + MOZ_ASSERT(aNElem <= SIZE_MAX / sizeof(T), + "trying to move an impossible number of elements"); + memmove(aDst, aSrc, aNElem * sizeof(T)); +} + +/** + * Determine whether the |len| elements at |one| are memory-identical to the + * |len| elements at |two|. + */ +template +static MOZ_ALWAYS_INLINE bool +PodEqual(const T* one, const T* two, size_t len) +{ + if (len < 128) { + const T* p1end = one + len; + const T* p1 = one; + const T* p2 = two; + for (; p1 < p1end; p1++, p2++) { + if (*p1 != *p2) { + return false; + } + } + return true; + } + + return !memcmp(one, two, len * sizeof(T)); +} + +} // namespace mozilla + +#endif /* mozilla_PodOperations_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Poison.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Poison.h new file mode 100644 index 0000000000..75e0f081cd --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Poison.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * A poison value that can be used to fill a memory space with + * an address that leads to a safe crash when dereferenced. + */ + +#ifndef mozilla_Poison_h +#define mozilla_Poison_h + +#include "mozilla/Assertions.h" +#include "mozilla/Types.h" + +#include + +MOZ_BEGIN_EXTERN_C + +extern MFBT_DATA uintptr_t gMozillaPoisonValue; + +/** + * @return the poison value. + */ +inline uintptr_t mozPoisonValue() +{ + return gMozillaPoisonValue; +} + +/** + * Overwrite the memory block of aSize bytes at aPtr with the poison value. + * aPtr MUST be aligned at a sizeof(uintptr_t) boundary. + * Only an even number of sizeof(uintptr_t) bytes are overwritten, the last + * few bytes (if any) is not overwritten. + */ +inline void mozWritePoison(void* aPtr, size_t aSize) +{ + const uintptr_t POISON = mozPoisonValue(); + char* p = (char*)aPtr; + char* limit = p + aSize; + MOZ_ASSERT((uintptr_t)aPtr % sizeof(uintptr_t) == 0, "bad alignment"); + MOZ_ASSERT(aSize >= sizeof(uintptr_t), "poisoning this object has no effect"); + for (; p < limit; p += sizeof(uintptr_t)) { + *((uintptr_t*)p) = POISON; + } +} + +/** + * Initialize the poison value. + * This should only be called once. + */ +extern MFBT_API void mozPoisonValueInit(); + +/* Values annotated by CrashReporter */ +extern MFBT_DATA uintptr_t gMozillaPoisonBase; +extern MFBT_DATA uintptr_t gMozillaPoisonSize; + +MOZ_END_EXTERN_C + +#endif /* mozilla_Poison_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Range.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Range.h new file mode 100644 index 0000000000..814a2821ad --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Range.h @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_Range_h +#define mozilla_Range_h + +#include "mozilla/NullPtr.h" +#include "mozilla/RangedPtr.h" + +#include + +namespace mozilla { + +// Range is a tuple containing a pointer and a length. +template +class Range +{ + const RangedPtr mStart; + const RangedPtr mEnd; + + typedef void (Range::* ConvertibleToBool)(); + void nonNull() {} + +public: + Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} + Range(T* aPtr, size_t aLength) + : mStart(aPtr, aPtr, aPtr + aLength), + mEnd(aPtr + aLength, aPtr, aPtr + aLength) + {} + + RangedPtr start() const { return mStart; } + RangedPtr end() const { return mEnd; } + size_t length() const { return mEnd - mStart; } + + T& operator[](size_t aOffset) const { return mStart[aOffset]; } + + operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } +}; + +} // namespace mozilla + +#endif /* mozilla_Range_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/RangedPtr.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/RangedPtr.h new file mode 100644 index 0000000000..4d94035b90 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/RangedPtr.h @@ -0,0 +1,284 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements a smart pointer asserted to remain within a range specified at + * construction. + */ + +#ifndef mozilla_RangedPtr_h +#define mozilla_RangedPtr_h + +#include "mozilla/ArrayUtils.h" +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" + +#include + +namespace mozilla { + +/* + * RangedPtr is a smart pointer restricted to an address range specified at + * creation. The pointer (and any smart pointers derived from it) must remain + * within the range [start, end] (inclusive of end to facilitate use as + * sentinels). Dereferencing or indexing into the pointer (or pointers derived + * from it) must remain within the range [start, end). All the standard pointer + * operators are defined on it; in debug builds these operations assert that the + * range specified at construction is respected. + * + * In theory passing a smart pointer instance as an argument can be slightly + * slower than passing a T* (due to ABI requirements for passing structs versus + * passing pointers), if the method being called isn't inlined. If you are in + * extremely performance-critical code, you may want to be careful using this + * smart pointer as an argument type. + * + * RangedPtr intentionally does not implicitly convert to T*. Use get() to + * explicitly convert to T*. Keep in mind that the raw pointer of course won't + * implement bounds checking in debug builds. + */ +template +class RangedPtr +{ + T* mPtr; + +#ifdef DEBUG + T* const mRangeStart; + T* const mRangeEnd; +#endif + + typedef void (RangedPtr::* ConvertibleToBool)(); + void nonNull() {} + + void checkSanity() + { + MOZ_ASSERT(mRangeStart <= mPtr); + MOZ_ASSERT(mPtr <= mRangeEnd); + } + + /* Creates a new pointer for |aPtr|, restricted to this pointer's range. */ + RangedPtr create(T* aPtr) const + { +#ifdef DEBUG + return RangedPtr(aPtr, mRangeStart, mRangeEnd); +#else + return RangedPtr(aPtr, nullptr, size_t(0)); +#endif + } + + uintptr_t asUintptr() const { return reinterpret_cast(mPtr); } + +public: + RangedPtr(T* aPtr, T* aStart, T* aEnd) + : mPtr(aPtr) +#ifdef DEBUG + , mRangeStart(aStart), mRangeEnd(aEnd) +#endif + { + MOZ_ASSERT(mRangeStart <= mRangeEnd); + checkSanity(); + } + RangedPtr(T* aPtr, T* aStart, size_t aLength) + : mPtr(aPtr) +#ifdef DEBUG + , mRangeStart(aStart), mRangeEnd(aStart + aLength) +#endif + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aPtr, aPtr, aLength). */ + RangedPtr(T* aPtr, size_t aLength) + : mPtr(aPtr) +#ifdef DEBUG + , mRangeStart(aPtr), mRangeEnd(aPtr + aLength) +#endif + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aArr, aArr, N). */ + template + RangedPtr(T (&aArr)[N]) + : mPtr(aArr) +#ifdef DEBUG + , mRangeStart(aArr), mRangeEnd(aArr + N) +#endif + { + checkSanity(); + } + + T* get() const { return mPtr; } + + operator ConvertibleToBool() const { return mPtr ? &RangedPtr::nonNull : 0; } + + /* + * You can only assign one RangedPtr into another if the two pointers have + * the same valid range: + * + * char arr1[] = "hi"; + * char arr2[] = "bye"; + * RangedPtr p1(arr1, 2); + * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works + * p1 = RangedPtr(arr2, 3); // asserts + */ + RangedPtr& operator=(const RangedPtr& aOther) + { + MOZ_ASSERT(mRangeStart == aOther.mRangeStart); + MOZ_ASSERT(mRangeEnd == aOther.mRangeEnd); + mPtr = aOther.mPtr; + checkSanity(); + return *this; + } + + RangedPtr operator+(size_t aInc) + { + MOZ_ASSERT(aInc <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() + aInc * sizeof(T) >= asUintptr()); + return create(mPtr + aInc); + } + + RangedPtr operator-(size_t aDec) + { + MOZ_ASSERT(aDec <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() - aDec * sizeof(T) <= asUintptr()); + return create(mPtr - aDec); + } + + /* + * You can assign a raw pointer into a RangedPtr if the raw pointer is + * within the range specified at creation. + */ + template + RangedPtr& operator=(U* aPtr) + { + *this = create(aPtr); + return *this; + } + + template + RangedPtr& operator=(const RangedPtr& aPtr) + { + MOZ_ASSERT(mRangeStart <= aPtr.mPtr); + MOZ_ASSERT(aPtr.mPtr <= mRangeEnd); + mPtr = aPtr.mPtr; + checkSanity(); + return *this; + } + + RangedPtr& operator++() + { + return (*this += 1); + } + + RangedPtr operator++(int) + { + RangedPtr rcp = *this; + ++*this; + return rcp; + } + + RangedPtr& operator--() + { + return (*this -= 1); + } + + RangedPtr operator--(int) + { + RangedPtr rcp = *this; + --*this; + return rcp; + } + + RangedPtr& operator+=(size_t aInc) + { + *this = *this + aInc; + return *this; + } + + RangedPtr& operator-=(size_t aDec) + { + *this = *this - aDec; + return *this; + } + + T& operator[](int aIndex) const + { + MOZ_ASSERT(size_t(aIndex > 0 ? aIndex : -aIndex) <= size_t(-1) / sizeof(T)); + return *create(mPtr + aIndex); + } + + T& operator*() const + { + MOZ_ASSERT(mPtr >= mRangeStart); + MOZ_ASSERT(mPtr < mRangeEnd); + return *mPtr; + } + + template + bool operator==(const RangedPtr& aOther) const + { + return mPtr == aOther.mPtr; + } + template + bool operator!=(const RangedPtr& aOther) const + { + return !(*this == aOther); + } + + template + bool operator==(const U* u) const + { + return mPtr == u; + } + template + bool operator!=(const U* u) const + { + return !(*this == u); + } + + template + bool operator<(const RangedPtr& aOther) const + { + return mPtr < aOther.mPtr; + } + template + bool operator<=(const RangedPtr& aOther) const + { + return mPtr <= aOther.mPtr; + } + + template + bool operator>(const RangedPtr& aOther) const + { + return mPtr > aOther.mPtr; + } + template + bool operator>=(const RangedPtr& aOther) const + { + return mPtr >= aOther.mPtr; + } + + size_t operator-(const RangedPtr& aOther) const + { + MOZ_ASSERT(mPtr >= aOther.mPtr); + return PointerRangeSize(aOther.mPtr, mPtr); + } + +private: + RangedPtr() MOZ_DELETE; + T* operator&() MOZ_DELETE; +}; + +} /* namespace mozilla */ + +#endif /* mozilla_RangedPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/ReentrancyGuard.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/ReentrancyGuard.h new file mode 100644 index 0000000000..557c61015e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/ReentrancyGuard.h @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Small helper class for asserting uses of a class are non-reentrant. */ + +#ifndef mozilla_ReentrancyGuard_h +#define mozilla_ReentrancyGuard_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/GuardObjects.h" + +namespace mozilla { + +/* Useful for implementing containers that assert non-reentrancy */ +class ReentrancyGuard +{ + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +#ifdef DEBUG + bool& mEntered; +#endif + +public: + template +#ifdef DEBUG + ReentrancyGuard(T& aObj + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mEntered(aObj.mEntered) +#else + ReentrancyGuard(T& + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) +#endif + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef DEBUG + MOZ_ASSERT(!mEntered); + mEntered = true; +#endif + } + ~ReentrancyGuard() + { +#ifdef DEBUG + mEntered = false; +#endif + } + +private: + ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; + void operator=(const ReentrancyGuard&) MOZ_DELETE; +}; + +} // namespace mozilla + +#endif /* mozilla_ReentrancyGuard_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/RefPtr.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/RefPtr.h new file mode 100644 index 0000000000..4901067b4c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/RefPtr.h @@ -0,0 +1,552 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Helpers for defining and using refcounted objects. */ + +#ifndef mozilla_RefPtr_h +#define mozilla_RefPtr_h + +#include "mozilla/Assertions.h" +#include "mozilla/Atomics.h" +#include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" +#include "mozilla/RefCountType.h" +#include "mozilla/TypeTraits.h" +#if defined(MOZILLA_INTERNAL_API) +#include "nsXPCOM.h" +#endif + +#if defined(MOZILLA_INTERNAL_API) && \ + (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) +#define MOZ_REFCOUNTED_LEAK_CHECKING +#endif + +namespace mozilla { + +template class RefCounted; +template class RefPtr; +template class TemporaryRef; +template class OutParamRef; +template OutParamRef byRef(RefPtr&); + +/** + * RefCounted is a sort of a "mixin" for a class T. RefCounted + * manages, well, refcounting for T, and because RefCounted is + * parameterized on T, RefCounted can call T's destructor directly. + * This means T doesn't need to have a virtual dtor and so doesn't + * need a vtable. + * + * RefCounted is created with refcount == 0. Newly-allocated + * RefCounted must immediately be assigned to a RefPtr to make the + * refcount > 0. It's an error to allocate and free a bare + * RefCounted, i.e. outside of the RefPtr machinery. Attempts to + * do so will abort DEBUG builds. + * + * Live RefCounted have refcount > 0. The lifetime (refcounts) of + * live RefCounted are controlled by RefPtr and + * RefPtr. Upon a transition from refcounted==1 + * to 0, the RefCounted "dies" and is destroyed. The "destroyed" + * state is represented in DEBUG builds by refcount==0xffffdead. This + * state distinguishes use-before-ref (refcount==0) from + * use-after-destroy (refcount==0xffffdead). + * + * Note that when deriving from RefCounted or AtomicRefCounted, you + * should add MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public + * section of your class, where ClassName is the name of your class. + */ +namespace detail { +#ifdef DEBUG +const MozRefCountType DEAD = 0xffffdead; +#endif + +// When building code that gets compiled into Gecko, try to use the +// trace-refcount leak logging facilities. +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +class RefCountLogger +{ +public: + static void logAddRef(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName, uint32_t aInstanceSize) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogAddRef(const_cast(aPointer), aRefCount, aTypeName, + aInstanceSize); + } + + static void logRelease(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogRelease(const_cast(aPointer), aRefCount, aTypeName); + } +}; +#endif + +// This is used WeakPtr.h as well as this file. +enum RefCountAtomicity +{ + AtomicRefCount, + NonAtomicRefCount +}; + +template +class RefCounted +{ + friend class RefPtr; + +protected: + RefCounted() : mRefCnt(0) {} + ~RefCounted() { MOZ_ASSERT(mRefCnt == detail::DEAD); } + +public: + // Compatibility with nsRefPtr. + void AddRef() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) >= 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + ++mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + uint32_t size = static_cast(this)->typeSize(); + const void* ptr = static_cast(this); + MozRefCountType cnt = ++mRefCnt; + detail::RefCountLogger::logAddRef(ptr, cnt, type, size); +#endif + } + + void Release() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) > 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + MozRefCountType cnt = --mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + const void* ptr = static_cast(this); + MozRefCountType cnt = --mRefCnt; + // Note: it's not safe to touch |this| after decrementing the refcount, + // except for below. + detail::RefCountLogger::logRelease(ptr, cnt, type); +#endif + if (0 == cnt) { + // Because we have atomically decremented the refcount above, only + // one thread can get a 0 count here, so as long as we can assume that + // everything else in the system is accessing this object through + // RefPtrs, it's safe to access |this| here. +#ifdef DEBUG + mRefCnt = detail::DEAD; +#endif + delete static_cast(this); + } + } + + // Compatibility with wtf::RefPtr. + void ref() { AddRef(); } + void deref() { Release(); } + MozRefCountType refCount() const { return mRefCnt; } + bool hasOneRef() const + { + MOZ_ASSERT(mRefCnt > 0); + return mRefCnt == 1; + } + +private: + mutable typename Conditional, + MozRefCountType>::Type mRefCnt; +}; + +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) \ + virtual const char* typeName() const { return #T; } \ + virtual size_t typeSize() const { return sizeof(*this); } +#else +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) +#endif + +// Note that this macro is expanded unconditionally because it declares only +// two small inline functions which will hopefully get eliminated by the linker +// in non-leak-checking builds. +#define MOZ_DECLARE_REFCOUNTED_TYPENAME(T) \ + const char* typeName() const { return #T; } \ + size_t typeSize() const { return sizeof(*this); } + +} // namespace detail + +template +class RefCounted : public detail::RefCounted +{ +public: + ~RefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from RefCounted"); + } +}; + +namespace external { + +/** + * AtomicRefCounted is like RefCounted, with an atomically updated + * reference counter. + * + * NOTE: Please do not use this class, use NS_INLINE_DECL_THREADSAFE_REFCOUNTING + * instead. + */ +template +class AtomicRefCounted : + public mozilla::detail::RefCounted +{ +public: + ~AtomicRefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from AtomicRefCounted"); + } +}; + +} // namespace external + +/** + * RefPtr points to a refcounted thing that has AddRef and Release + * methods to increase/decrease the refcount, respectively. After a + * RefPtr is assigned a T*, the T* can be used through the RefPtr + * as if it were a T*. + * + * A RefPtr can forget its underlying T*, which results in the T* + * being wrapped in a temporary object until the T* is either + * re-adopted from or released by the temporary. + */ +template +class RefPtr +{ + // To allow them to use unref() + friend class TemporaryRef; + friend class OutParamRef; + + struct DontRef {}; + +public: + RefPtr() : mPtr(0) {} + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.mPtr)) {} + MOZ_IMPLICIT RefPtr(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + MOZ_IMPLICIT RefPtr(T* aVal) : mPtr(ref(aVal)) {} + + template + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.get())) {} + + ~RefPtr() { unref(mPtr); } + + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.mPtr)); + return *this; + } + RefPtr& operator=(const TemporaryRef& aOther) + { + assign(aOther.drop()); + return *this; + } + RefPtr& operator=(T* aVal) + { + assign(ref(aVal)); + return *this; + } + + template + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.get())); + return *this; + } + + TemporaryRef forget() + { + T* tmp = mPtr; + mPtr = nullptr; + return TemporaryRef(tmp, DontRef()); + } + + T* get() const { return mPtr; } + operator T*() const { return mPtr; } + T* operator->() const { return mPtr; } + T& operator*() const { return *mPtr; } + template + operator TemporaryRef() { return TemporaryRef(mPtr); } + +private: + void assign(T* aVal) + { + unref(mPtr); + mPtr = aVal; + } + + T* mPtr; + + static MOZ_ALWAYS_INLINE T* ref(T* aVal) + { + if (aVal) { + aVal->AddRef(); + } + return aVal; + } + + static MOZ_ALWAYS_INLINE void unref(T* aVal) + { + if (aVal) { + aVal->Release(); + } + } +}; + +/** + * TemporaryRef represents an object that holds a temporary + * reference to a T. TemporaryRef objects can't be manually ref'd or + * unref'd (being temporaries, not lvalues), so can only relinquish + * references to other objects, or unref on destruction. + */ +template +class TemporaryRef +{ + // To allow it to construct TemporaryRef from a bare T* + friend class RefPtr; + + typedef typename RefPtr::DontRef DontRef; + +public: + MOZ_IMPLICIT TemporaryRef(T* aVal) : mPtr(RefPtr::ref(aVal)) {} + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + + template + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + + ~TemporaryRef() { RefPtr::unref(mPtr); } + + T* drop() const + { + T* tmp = mPtr; + mPtr = nullptr; + return tmp; + } + +private: + TemporaryRef(T* aVal, const DontRef&) : mPtr(aVal) {} + + mutable T* mPtr; + + TemporaryRef() MOZ_DELETE; + void operator=(const TemporaryRef&) MOZ_DELETE; +}; + +/** + * OutParamRef is a wrapper that tracks a refcounted pointer passed as + * an outparam argument to a function. OutParamRef implements COM T** + * outparam semantics: this requires the callee to AddRef() the T* + * returned through the T** outparam on behalf of the caller. This + * means the caller (through OutParamRef) must Release() the old + * object contained in the tracked RefPtr. It's OK if the callee + * returns the same T* passed to it through the T** outparam, as long + * as the callee obeys the COM discipline. + * + * Prefer returning TemporaryRef from functions over creating T** + * outparams and passing OutParamRef to T**. Prefer RefPtr* + * outparams over T** outparams. + */ +template +class OutParamRef +{ + friend OutParamRef byRef(RefPtr&); + +public: + ~OutParamRef() + { + RefPtr::unref(mRefPtr.mPtr); + mRefPtr.mPtr = mTmp; + } + + operator T**() { return &mTmp; } + +private: + explicit OutParamRef(RefPtr& p) : mRefPtr(p), mTmp(p.get()) {} + + RefPtr& mRefPtr; + T* mTmp; + + OutParamRef() MOZ_DELETE; + OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; +}; + +/** + * byRef cooperates with OutParamRef to implement COM outparam semantics. + */ +template +OutParamRef +byRef(RefPtr& aPtr) +{ + return OutParamRef(aPtr); +} + +} // namespace mozilla + +#if 0 + +// Command line that builds these tests +// +// cp RefPtr.h test.cc && g++ -g -Wall -pedantic -DDEBUG -o test test.cc && ./test + +using namespace mozilla; + +struct Foo : public RefCounted +{ + MOZ_DECLARE_REFCOUNTED_TYPENAME(Foo) + Foo() : mDead(false) {} + ~Foo() + { + MOZ_ASSERT(!mDead); + mDead = true; + sNumDestroyed++; + } + + bool mDead; + static int sNumDestroyed; +}; +int Foo::sNumDestroyed; + +struct Bar : public Foo {}; + +TemporaryRef +NewFoo() +{ + return RefPtr(new Foo()); +} + +TemporaryRef +NewBar() +{ + return new Bar(); +} + +void +GetNewFoo(Foo** f) +{ + *f = new Bar(); + // Kids, don't try this at home + (*f)->AddRef(); +} + +void +GetPassedFoo(Foo** f) +{ + // Kids, don't try this at home + (*f)->AddRef(); +} + +void +GetNewFoo(RefPtr* f) +{ + *f = new Bar(); +} + +void +GetPassedFoo(RefPtr* f) +{} + +TemporaryRef +GetNullFoo() +{ + return 0; +} + +int +main(int argc, char** argv) +{ + // This should blow up +// Foo* f = new Foo(); delete f; + + MOZ_ASSERT(0 == Foo::sNumDestroyed); + { + RefPtr f = new Foo(); + MOZ_ASSERT(f->refCount() == 1); + } + MOZ_ASSERT(1 == Foo::sNumDestroyed); + + { + RefPtr f1 = NewFoo(); + RefPtr f2(NewFoo()); + MOZ_ASSERT(1 == Foo::sNumDestroyed); + } + MOZ_ASSERT(3 == Foo::sNumDestroyed); + + { + RefPtr b = NewBar(); + MOZ_ASSERT(3 == Foo::sNumDestroyed); + } + MOZ_ASSERT(4 == Foo::sNumDestroyed); + + { + RefPtr f1; + { + f1 = new Foo(); + RefPtr f2(f1); + RefPtr f3 = f2; + MOZ_ASSERT(4 == Foo::sNumDestroyed); + } + MOZ_ASSERT(4 == Foo::sNumDestroyed); + } + MOZ_ASSERT(5 == Foo::sNumDestroyed); + + { + RefPtr f = new Foo(); + f.forget(); + MOZ_ASSERT(6 == Foo::sNumDestroyed); + } + + { + RefPtr f = new Foo(); + GetNewFoo(byRef(f)); + MOZ_ASSERT(7 == Foo::sNumDestroyed); + } + MOZ_ASSERT(8 == Foo::sNumDestroyed); + + { + RefPtr f = new Foo(); + GetPassedFoo(byRef(f)); + MOZ_ASSERT(8 == Foo::sNumDestroyed); + } + MOZ_ASSERT(9 == Foo::sNumDestroyed); + + { + RefPtr f = new Foo(); + GetNewFoo(&f); + MOZ_ASSERT(10 == Foo::sNumDestroyed); + } + MOZ_ASSERT(11 == Foo::sNumDestroyed); + + { + RefPtr f = new Foo(); + GetPassedFoo(&f); + MOZ_ASSERT(11 == Foo::sNumDestroyed); + } + MOZ_ASSERT(12 == Foo::sNumDestroyed); + + { + RefPtr f1 = new Bar(); + } + MOZ_ASSERT(13 == Foo::sNumDestroyed); + + { + RefPtr f = GetNullFoo(); + MOZ_ASSERT(13 == Foo::sNumDestroyed); + } + MOZ_ASSERT(13 == Foo::sNumDestroyed); + + return 0; +} + +#endif + +#endif /* mozilla_RefPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/RollingMean.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/RollingMean.h new file mode 100644 index 0000000000..5add14c879 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/RollingMean.h @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A set abstraction for enumeration values. */ + +#ifndef mozilla_RollingMean_h_ +#define mozilla_RollingMean_h_ + +#include "mozilla/Assertions.h" +#include "mozilla/TypeTraits.h" +#include "mozilla/Vector.h" + +#include + +namespace mozilla { + +/** + * RollingMean calculates a rolling mean of the values it is given. It + * accumulates the total as values are added and removed. The second type + * argument S specifies the type of the total. This may need to be a bigger + * type in order to maintain that the sum of all values in the average doesn't + * exceed the maximum input value. + * + * WARNING: Float types are not supported due to rounding errors. + */ +template +class RollingMean +{ +private: + size_t mInsertIndex; + size_t mMaxValues; + Vector mValues; + S mTotal; + +public: + static_assert(!IsFloatingPoint::value, + "floating-point types are unsupported due to rounding " + "errors"); + + explicit RollingMean(size_t aMaxValues) + : mInsertIndex(0), + mMaxValues(aMaxValues), + mTotal(0) + { + MOZ_ASSERT(aMaxValues > 0); + } + + RollingMean& operator=(RollingMean&& aOther) + { + MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); + this->~RollingMean(); + new(this) RollingMean(aOther.mMaxValues); + mInsertIndex = aOther.mInsertIndex; + mTotal = aOther.mTotal; + mValues.swap(aOther.mValues); + return *this; + } + + /** + * Insert a value into the rolling mean. + */ + bool insert(T aValue) + { + MOZ_ASSERT(mValues.length() <= mMaxValues); + + if (mValues.length() == mMaxValues) { + mTotal = mTotal - mValues[mInsertIndex] + aValue; + mValues[mInsertIndex] = aValue; + } else { + if (!mValues.append(aValue)) { + return false; + } + mTotal = mTotal + aValue; + } + + mInsertIndex = (mInsertIndex + 1) % mMaxValues; + return true; + } + + /** + * Calculate the rolling mean. + */ + T mean() + { + MOZ_ASSERT(!empty()); + return T(mTotal / mValues.length()); + } + + bool empty() + { + return mValues.empty(); + } + + /** + * Remove all values from the rolling mean. + */ + void clear() + { + mValues.clear(); + mInsertIndex = 0; + mTotal = T(0); + } + + size_t maxValues() + { + return mMaxValues; + } +}; + +} // namespace mozilla + +#endif // mozilla_RollingMean_h_ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/SHA1.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/SHA1.h new file mode 100644 index 0000000000..ddccaa67e7 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/SHA1.h @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Simple class for computing SHA1. */ + +#ifndef mozilla_SHA1_h +#define mozilla_SHA1_h + +#include "mozilla/Types.h" + +#include +#include + +namespace mozilla { + +/** + * This class computes the SHA1 hash of a byte sequence, or of the concatenation + * of multiple sequences. For example, computing the SHA1 of two sequences of + * bytes could be done as follows: + * + * void SHA1(const uint8_t* buf1, uint32_t size1, + * const uint8_t* buf2, uint32_t size2, + * SHA1Sum::Hash& hash) + * { + * SHA1Sum s; + * s.update(buf1, size1); + * s.update(buf2, size2); + * s.finish(hash); + * } + * + * The finish method may only be called once and cannot be followed by calls + * to update. + */ +class SHA1Sum +{ + union + { + uint32_t mW[16]; /* input buffer */ + uint8_t mB[64]; + } mU; + uint64_t mSize; /* count of hashed bytes. */ + unsigned mH[22]; /* 5 state variables, 16 tmp values, 1 extra */ + bool mDone; + +public: + MFBT_API SHA1Sum(); + + static const size_t kHashSize = 20; + typedef uint8_t Hash[kHashSize]; + + /* Add len bytes of dataIn to the data sequence being hashed. */ + MFBT_API void update(const void* aData, uint32_t aLength); + + /* Compute the final hash of all data into hashOut. */ + MFBT_API void finish(SHA1Sum::Hash& aHashOut); +}; + +} /* namespace mozilla */ + +#endif /* mozilla_SHA1_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Scoped.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Scoped.h new file mode 100644 index 0000000000..3f854d6375 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Scoped.h @@ -0,0 +1,308 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A number of structures to simplify scope-based RAII management. */ + +#ifndef mozilla_Scoped_h +#define mozilla_Scoped_h + +/* + * Resource Acquisition Is Initialization is a programming idiom used + * to write robust code that is able to deallocate resources properly, + * even in presence of execution errors or exceptions that need to be + * propagated. The Scoped* classes defined in this header perform the + * deallocation of the resource they hold once program execution + * reaches the end of the scope for which they have been defined. + * + * This header provides the following RAII classes: + * + * - |ScopedFreePtr| - a container for a pointer, that automatically calls + * |free()| at the end of the scope; + * - |ScopedDeletePtr| - a container for a pointer, that automatically calls + * |delete| at the end of the scope; + * - |ScopedDeleteArray| - a container for a pointer to an array, that + * automatically calls |delete[]| at the end of the scope. + * + * The general scenario for each of the RAII classes is the following: + * + * ScopedClass foo(create_value()); + * // ... In this scope, |foo| is defined. Use |foo.get()| or |foo.rwget()| + * to access the value. + * // ... In case of |return| or |throw|, |foo| is deallocated automatically. + * // ... If |foo| needs to be returned or stored, use |foo.forget()| + * + * Note that the RAII classes defined in this header do _not_ perform any form + * of reference-counting or garbage-collection. These classes have exactly two + * behaviors: + * + * - if |forget()| has not been called, the resource is always deallocated at + * the end of the scope; + * - if |forget()| has been called, any control on the resource is unbound + * and the resource is not deallocated by the class. + * + * Extension: + * + * In addition, this header provides class |Scoped| and macros |SCOPED_TEMPLATE| + * and |MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE| to simplify the definition + * of RAII classes for other scenarios. These macros have been used to + * automatically close file descriptors/file handles when reaching the end of + * the scope, graphics contexts, etc. + */ + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/GuardObjects.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" + +namespace mozilla { + +/* + * Scoped is a helper to create RAII wrappers + * Type argument |Traits| is expected to have the following structure: + * + * struct Traits + * { + * // Define the type of the value stored in the wrapper + * typedef value_type type; + * // Returns the value corresponding to the uninitialized or freed state + * const static type empty(); + * // Release resources corresponding to the wrapped value + * // This function is responsible for not releasing an |empty| value + * const static void release(type); + * } + */ +template +class Scoped +{ +public: + typedef typename Traits::type Resource; + + explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + : mValue(Traits::empty()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + explicit Scoped(const Resource& aValue + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(aValue) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + /* Move constructor. */ + explicit Scoped(Scoped&& aOther + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(Move(aOther.mValue)) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + aOther.mValue = Traits::empty(); + } + + ~Scoped() { Traits::release(mValue); } + + // Constant getter + operator const Resource&() const { return mValue; } + const Resource& operator->() const { return mValue; } + const Resource& get() const { return mValue; } + // Non-constant getter. + Resource& rwget() { return mValue; } + + /* + * Forget the resource. + * + * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will + * have no effect at destruction (unless it is reset to another resource by + * |operator=|). + * + * @return The original resource. + */ + Resource forget() + { + Resource tmp = mValue; + mValue = Traits::empty(); + return tmp; + } + + /* + * Perform immediate clean-up of this |Scoped|. + * + * If this |Scoped| is currently empty, this method has no effect. + */ + void dispose() + { + Traits::release(mValue); + mValue = Traits::empty(); + } + + bool operator==(const Resource& aOther) const { return mValue == aOther; } + + /* + * Replace the resource with another resource. + * + * Calling |operator=| has the side-effect of triggering clean-up. If you do + * not want to trigger clean-up, you should first invoke |forget|. + * + * @return this + */ + Scoped& operator=(const Resource& aOther) { return reset(aOther); } + + Scoped& reset(const Resource& aOther) + { + Traits::release(mValue); + mValue = aOther; + return *this; + } + + /* Move assignment operator. */ + Scoped& operator=(Scoped&& aRhs) + { + MOZ_ASSERT(&aRhs != this, "self-move-assignment not allowed"); + this->~Scoped(); + new(this) Scoped(Move(aRhs)); + return *this; + } + +private: + explicit Scoped(const Scoped& aValue) MOZ_DELETE; + Scoped& operator=(const Scoped& aValue) MOZ_DELETE; + +private: + Resource mValue; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* + * SCOPED_TEMPLATE defines a templated class derived from Scoped + * This allows to implement templates such as ScopedFreePtr. + * + * @param name The name of the class to define. + * @param Traits A struct implementing clean-up. See the implementations + * for more details. + */ +#define SCOPED_TEMPLATE(name, Traits) \ +template \ +struct name : public mozilla::Scoped > \ +{ \ + typedef mozilla::Scoped > Super; \ + typedef typename Super::Resource Resource; \ + name& operator=(Resource aRhs) \ + { \ + Super::operator=(aRhs); \ + return *this; \ + } \ + name& operator=(name&& aRhs) \ + { \ + Super::operator=(Move(aRhs)); \ + return *this; \ + } \ + explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ + : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ + {} \ + explicit name(Resource aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ + explicit name(name&& aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(Move(aRhs) \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ +private: \ + explicit name(name&) MOZ_DELETE; \ + name& operator=(name&) MOZ_DELETE; \ +}; + +/* + * ScopedFreePtr is a RAII wrapper for pointers that need to be free()d. + * + * struct S { ... }; + * ScopedFreePtr foo = malloc(sizeof(S)); + * ScopedFreePtr bar = strdup(str); + */ +template +struct ScopedFreePtrTraits +{ + typedef T* type; + static T* empty() { return nullptr; } + static void release(T* aPtr) { free(aPtr); } +}; +SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) + +/* + * ScopedDeletePtr is a RAII wrapper for pointers that need to be deleted. + * + * struct S { ... }; + * ScopedDeletePtr foo = new S(); + */ +template +struct ScopedDeletePtrTraits : public ScopedFreePtrTraits +{ + static void release(T* aPtr) { delete aPtr; } +}; +SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) + +/* + * ScopedDeleteArray is a RAII wrapper for pointers that need to be delete[]ed. + * + * struct S { ... }; + * ScopedDeleteArray foo = new S[42]; + */ +template +struct ScopedDeleteArrayTraits : public ScopedFreePtrTraits +{ + static void release(T* aPtr) { delete [] aPtr; } +}; +SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) + +/* + * MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE makes it easy to create scoped + * pointers for types with custom deleters; just overload + * TypeSpecificDelete(T*) in the same namespace as T to call the deleter for + * type T. + * + * @param name The name of the class to define. + * @param Type A struct implementing clean-up. See the implementations + * for more details. + * *param Deleter The function that is used to delete/destroy/free a + * non-null value of Type*. + * + * Example: + * + * MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(ScopedPRFileDesc, PRFileDesc, \ + * PR_Close) + * ... + * { + * ScopedPRFileDesc file(PR_OpenFile(...)); + * ... + * } // file is closed with PR_Close here + */ +#define MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(name, Type, Deleter) \ +template <> inline void TypeSpecificDelete(Type* aValue) { Deleter(aValue); } \ +typedef ::mozilla::TypeSpecificScopedPointer name; + +template void TypeSpecificDelete(T* aValue); + +template +struct TypeSpecificScopedPointerTraits +{ + typedef T* type; + static type empty() { return nullptr; } + static void release(type aValue) + { + if (aValue) { + TypeSpecificDelete(aValue); + } + } +}; + +SCOPED_TEMPLATE(TypeSpecificScopedPointer, TypeSpecificScopedPointerTraits) + +} /* namespace mozilla */ + +#endif /* mozilla_Scoped_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/SplayTree.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/SplayTree.h new file mode 100644 index 0000000000..a6d692266f --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/SplayTree.h @@ -0,0 +1,296 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * A sorted tree with optimal access times, where recently-accessed elements + * are faster to access again. + */ + +#ifndef mozilla_SplayTree_h +#define mozilla_SplayTree_h + +#include "mozilla/Assertions.h" +#include "mozilla/NullPtr.h" + +namespace mozilla { + +template +class SplayTree; + +template +class SplayTreeNode +{ +public: + template + friend class SplayTree; + + SplayTreeNode() + : mLeft(nullptr) + , mRight(nullptr) + , mParent(nullptr) + {} + +private: + T* mLeft; + T* mRight; + T* mParent; +}; + + +/** + * Class which represents a splay tree. + * Splay trees are balanced binary search trees for which search, insert and + * remove are all amortized O(log n), but where accessing a node makes it + * faster to access that node in the future. + * + * T indicates the type of tree elements, Comparator must have a static + * compare(const T&, const T&) method ordering the elements. The compare + * method must be free from side effects. + */ +template +class SplayTree +{ + T* mRoot; + +public: + SplayTree() + : mRoot(nullptr) + {} + + bool empty() const + { + return !mRoot; + } + + T* find(const T& aValue) + { + if (empty()) { + return nullptr; + } + + T* last = lookup(aValue); + splay(last); + checkCoherency(mRoot, nullptr); + return Comparator::compare(aValue, *last) == 0 ? last : nullptr; + } + + bool insert(T* aValue) + { + MOZ_ASSERT(!find(*aValue), "Duplicate elements are not allowed."); + + if (!mRoot) { + mRoot = aValue; + return true; + } + T* last = lookup(*aValue); + int cmp = Comparator::compare(*aValue, *last); + + T** parentPointer = (cmp < 0) ? &last->mLeft : &last->mRight; + MOZ_ASSERT(!*parentPointer); + *parentPointer = aValue; + aValue->mParent = last; + + splay(aValue); + checkCoherency(mRoot, nullptr); + return true; + } + + T* remove(const T& aValue) + { + T* last = lookup(aValue); + MOZ_ASSERT(last, "This tree must contain the element being removed."); + MOZ_ASSERT(Comparator::compare(aValue, *last) == 0); + + // Splay the tree so that the item to remove is the root. + splay(last); + MOZ_ASSERT(last == mRoot); + + // Find another node which can be swapped in for the root: either the + // rightmost child of the root's left, or the leftmost child of the + // root's right. + T* swap; + T* swapChild; + if (mRoot->mLeft) { + swap = mRoot->mLeft; + while (swap->mRight) { + swap = swap->mRight; + } + swapChild = swap->mLeft; + } else if (mRoot->mRight) { + swap = mRoot->mRight; + while (swap->mLeft) { + swap = swap->mLeft; + } + swapChild = swap->mRight; + } else { + T* result = mRoot; + mRoot = nullptr; + return result; + } + + // The selected node has at most one child, in swapChild. Detach it + // from the subtree by replacing it with that child. + if (swap == swap->mParent->mLeft) { + swap->mParent->mLeft = swapChild; + } else { + swap->mParent->mRight = swapChild; + } + if (swapChild) { + swapChild->mParent = swap->mParent; + } + + // Make the selected node the new root. + mRoot = swap; + mRoot->mParent = nullptr; + mRoot->mLeft = last->mLeft; + mRoot->mRight = last->mRight; + if (mRoot->mLeft) { + mRoot->mLeft->mParent = mRoot; + } + if (mRoot->mRight) { + mRoot->mRight->mParent = mRoot; + } + + checkCoherency(mRoot, nullptr); + return last; + } + + T* removeMin() + { + MOZ_ASSERT(mRoot, "No min to remove!"); + + T* min = mRoot; + while (min->mLeft) { + min = min->mLeft; + } + return remove(*min); + } + +private: + /** + * Returns the node in this comparing equal to |aValue|, or a node just + * greater or just less than |aValue| if there is no such node. + */ + T* lookup(const T& aValue) + { + MOZ_ASSERT(!empty()); + + T* node = mRoot; + T* parent; + do { + parent = node; + int c = Comparator::compare(aValue, *node); + if (c == 0) { + return node; + } else if (c < 0) { + node = node->mLeft; + } else { + node = node->mRight; + } + } while (node); + return parent; + } + + /** + * Rotate the tree until |node| is at the root of the tree. Performing + * the rotations in this fashion preserves the amortized balancing of + * the tree. + */ + void splay(T* aNode) + { + MOZ_ASSERT(aNode); + + while (aNode != mRoot) { + T* parent = aNode->mParent; + if (parent == mRoot) { + // Zig rotation. + rotate(aNode); + MOZ_ASSERT(aNode == mRoot); + return; + } + T* grandparent = parent->mParent; + if ((parent->mLeft == aNode) == (grandparent->mLeft == parent)) { + // Zig-zig rotation. + rotate(parent); + rotate(aNode); + } else { + // Zig-zag rotation. + rotate(aNode); + rotate(aNode); + } + } + } + + void rotate(T* aNode) + { + // Rearrange nodes so that aNode becomes the parent of its current + // parent, while preserving the sortedness of the tree. + T* parent = aNode->mParent; + if (parent->mLeft == aNode) { + // x y + // y c ==> a x + // a b b c + parent->mLeft = aNode->mRight; + if (aNode->mRight) { + aNode->mRight->mParent = parent; + } + aNode->mRight = parent; + } else { + MOZ_ASSERT(parent->mRight == aNode); + // x y + // a y ==> x c + // b c a b + parent->mRight = aNode->mLeft; + if (aNode->mLeft) { + aNode->mLeft->mParent = parent; + } + aNode->mLeft = parent; + } + aNode->mParent = parent->mParent; + parent->mParent = aNode; + if (T* grandparent = aNode->mParent) { + if (grandparent->mLeft == parent) { + grandparent->mLeft = aNode; + } else { + grandparent->mRight = aNode; + } + } else { + mRoot = aNode; + } + } + + T* checkCoherency(T* aNode, T* aMinimum) + { +#ifdef DEBUG + MOZ_ASSERT_IF(mRoot, !mRoot->mParent); + if (!aNode) { + MOZ_ASSERT(!mRoot); + return nullptr; + } + MOZ_ASSERT_IF(!aNode->mParent, aNode == mRoot); + MOZ_ASSERT_IF(aMinimum, Comparator::compare(*aMinimum, *aNode) < 0); + if (aNode->mLeft) { + MOZ_ASSERT(aNode->mLeft->mParent == aNode); + T* leftMaximum = checkCoherency(aNode->mLeft, aMinimum); + MOZ_ASSERT(Comparator::compare(*leftMaximum, *aNode) < 0); + } + if (aNode->mRight) { + MOZ_ASSERT(aNode->mRight->mParent == aNode); + return checkCoherency(aNode->mRight, aNode); + } + return aNode; +#else + return nullptr; +#endif + } + + SplayTree(const SplayTree&) MOZ_DELETE; + void operator=(const SplayTree&) MOZ_DELETE; +}; + +} /* namespace mozilla */ + +#endif /* mozilla_SplayTree_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/TemplateLib.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/TemplateLib.h new file mode 100644 index 0000000000..ea12c18b2b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/TemplateLib.h @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Reusable template meta-functions on types and compile-time values. Meta- + * functions are placed inside the 'tl' namespace to avoid conflict with non- + * meta functions of the same name (e.g., mozilla::tl::FloorLog2 vs. + * mozilla::FloorLog2). + * + * When constexpr support becomes universal, we should probably use that instead + * of some of these templates, for simplicity. + */ + +#ifndef mozilla_TemplateLib_h +#define mozilla_TemplateLib_h + +#include +#include + +namespace mozilla { + +namespace tl { + +/** Compute min/max. */ +template +struct Min +{ + static const size_t value = I < J ? I : J; +}; +template +struct Max +{ + static const size_t value = I > J ? I : J; +}; + +/** Compute floor(log2(i)). */ +template +struct FloorLog2 +{ + static const size_t value = 1 + FloorLog2::value; +}; +template<> struct FloorLog2<0> { /* Error */ }; +template<> struct FloorLog2<1> { static const size_t value = 0; }; + +/** Compute ceiling(log2(i)). */ +template +struct CeilingLog2 +{ + static const size_t value = FloorLog2<2 * I - 1>::value; +}; + +/** Round up to the nearest power of 2. */ +template +struct RoundUpPow2 +{ + static const size_t value = size_t(1) << CeilingLog2::value; +}; +template<> +struct RoundUpPow2<0> +{ + static const size_t value = 1; +}; + +/** Compute the number of bits in the given unsigned type. */ +template +struct BitSize +{ + static const size_t value = sizeof(T) * CHAR_BIT; +}; + +/** + * Produce an N-bit mask, where N <= BitSize::value. Handle the + * language-undefined edge case when N = BitSize::value. + */ +template +struct NBitMask +{ + // Assert the precondition. On success this evaluates to 0. Otherwise it + // triggers divide-by-zero at compile time: a guaranteed compile error in + // C++11, and usually one in C++98. Add this value to |value| to assure + // its computation. + static const size_t checkPrecondition = + 0 / size_t(N < BitSize::value); + static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; +}; +template<> +struct NBitMask::value> +{ + static const size_t value = size_t(-1); +}; + +/** + * For the unsigned integral type size_t, compute a mask M for N such that + * for all X, !(X & M) implies X * N will not overflow (w.r.t size_t) + */ +template +struct MulOverflowMask +{ + static const size_t value = + ~NBitMask::value - CeilingLog2::value>::value; +}; +template<> struct MulOverflowMask<0> { /* Error */ }; +template<> struct MulOverflowMask<1> { static const size_t value = 0; }; + +} // namespace tl + +} // namespace mozilla + +#endif /* mozilla_TemplateLib_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/ThreadLocal.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/ThreadLocal.h new file mode 100644 index 0000000000..28015de22e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/ThreadLocal.h @@ -0,0 +1,151 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Cross-platform lightweight thread local data wrappers. */ + +#ifndef mozilla_ThreadLocal_h +#define mozilla_ThreadLocal_h + +#if defined(XP_WIN) +// This file will get included in any file that wants to add a profiler mark. +// In order to not bring together we could include windef.h and +// winbase.h which are sufficient to get the prototypes for the Tls* functions. +// # include +// # include +// Unfortunately, even including these headers causes us to add a bunch of ugly +// stuff to our namespace e.g #define CreateEvent CreateEventW +extern "C" { +__declspec(dllimport) void* __stdcall TlsGetValue(unsigned long); +__declspec(dllimport) int __stdcall TlsSetValue(unsigned long, void*); +__declspec(dllimport) unsigned long __stdcall TlsAlloc(); +} +#else +# include +# include +#endif + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" + +namespace mozilla { + +// sig_safe_t denotes an atomic type which can be read or stored in a single +// instruction. This means that data of this type is safe to be manipulated +// from a signal handler, or other similar asynchronous execution contexts. +#if defined(XP_WIN) +typedef unsigned long sig_safe_t; +#else +typedef sig_atomic_t sig_safe_t; +#endif + +/* + * Thread Local Storage helpers. + * + * Usage: + * + * Only static-storage-duration (e.g. global variables, or static class members) + * objects of this class should be instantiated. This class relies on + * zero-initialization, which is implicit for static-storage-duration objects. + * It doesn't have a custom default constructor, to avoid static initializers. + * + * API usage: + * + * // Create a TLS item. + * // + * // Note that init() should be invoked exactly once, before any usage of set() + * // or get(). + * mozilla::ThreadLocal tlsKey; + * if (!tlsKey.init()) { + * // deal with the error + * } + * + * // Set the TLS value + * tlsKey.set(123); + * + * // Get the TLS value + * int value = tlsKey.get(); + */ +template +class ThreadLocal +{ +#if defined(XP_WIN) + typedef unsigned long key_t; +#else + typedef pthread_key_t key_t; +#endif + + union Helper + { + void* mPtr; + T mValue; + }; + +public: + MOZ_WARN_UNUSED_RESULT inline bool init(); + + inline T get() const; + + inline void set(const T aValue); + + bool initialized() const { return mInited; } + +private: + key_t mKey; + bool mInited; +}; + +template +inline bool +ThreadLocal::init() +{ + static_assert(sizeof(T) <= sizeof(void*), + "mozilla::ThreadLocal can't be used for types larger than " + "a pointer"); + MOZ_ASSERT(!initialized()); +#ifdef XP_WIN + mKey = TlsAlloc(); + mInited = mKey != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES +#else + mInited = !pthread_key_create(&mKey, nullptr); +#endif + return mInited; +} + +template +inline T +ThreadLocal::get() const +{ + MOZ_ASSERT(initialized()); + Helper h; +#ifdef XP_WIN + h.mPtr = TlsGetValue(mKey); +#else + h.mPtr = pthread_getspecific(mKey); +#endif + return h.mValue; +} + +template +inline void +ThreadLocal::set(const T aValue) +{ + MOZ_ASSERT(initialized()); + Helper h; + h.mValue = aValue; +#ifdef XP_WIN + bool succeeded = TlsSetValue(mKey, h.mPtr); +#else + bool succeeded = !pthread_setspecific(mKey, h.mPtr); +#endif + if (!succeeded) { + MOZ_CRASH(); + } +} + +} // namespace mozilla + +#endif /* mozilla_ThreadLocal_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/TypeTraits.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/TypeTraits.h new file mode 100644 index 0000000000..515c68d94e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/TypeTraits.h @@ -0,0 +1,998 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Template-based metaprogramming and type-testing facilities. */ + +#ifndef mozilla_TypeTraits_h +#define mozilla_TypeTraits_h + +#include "mozilla/Types.h" + +/* + * These traits are approximate copies of the traits and semantics from C++11's + * header. Don't add traits not in that header! When all + * platforms provide that header, we can convert all users and remove this one. + */ + +#include + +namespace mozilla { + +/* Forward declarations. */ + +template struct RemoveCV; + +/* 20.9.3 Helper classes [meta.help] */ + +/** + * Helper class used as a base for various type traits, exposed publicly + * because exposes it as well. + */ +template +struct IntegralConstant +{ + static const T value = Value; + typedef T ValueType; + typedef IntegralConstant Type; +}; + +/** Convenient aliases. */ +typedef IntegralConstant TrueType; +typedef IntegralConstant FalseType; + +/* 20.9.4 Unary type traits [meta.unary] */ + +/* 20.9.4.1 Primary type categories [meta.unary.cat] */ + +namespace detail { + +template +struct IsVoidHelper : FalseType {}; + +template<> +struct IsVoidHelper : TrueType {}; + +} // namespace detail + +/** + * IsVoid determines whether a type is void. + * + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true; + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true. + */ +template +struct IsVoid : detail::IsVoidHelper::Type> {}; + +namespace detail { + +template +struct IsIntegralHelper : FalseType {}; + +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +#ifdef MOZ_CHAR16_IS_NOT_WCHAR +template<> struct IsIntegralHelper : TrueType {}; +#endif + +} /* namespace detail */ + +/** + * IsIntegral determines whether a type is an integral type. + * + * mozilla::IsIntegral::value is true; + * mozilla::IsIntegral::value is true; + * mozilla::IsIntegral::value is true; + * mozilla::IsIntegral::value is false; + * mozilla::IsIntegral::value is false; + * + * Note that the behavior of IsIntegral on char16_t and char32_t is + * unspecified. + */ +template +struct IsIntegral : detail::IsIntegralHelper::Type> +{}; + +template +struct IsSame; + +namespace detail { + +template +struct IsFloatingPointHelper + : IntegralConstant::value || + IsSame::value || + IsSame::value> +{}; + +} // namespace detail + +/** + * IsFloatingPoint determines whether a type is a floating point type (float, + * double, long double). + * + * mozilla::IsFloatingPoint::value is false; + * mozilla::IsFloatingPoint::value is true; + * mozilla::IsFloatingPoint::value is true; + * mozilla::IsFloatingPoint::value is false. + */ +template +struct IsFloatingPoint + : detail::IsFloatingPointHelper::Type> +{}; + +namespace detail { + +template +struct IsArrayHelper : FalseType {}; + +template +struct IsArrayHelper : TrueType {}; + +template +struct IsArrayHelper : TrueType {}; + +} // namespace detail + +/** + * IsArray determines whether a type is an array type, of known or unknown + * length. + * + * mozilla::IsArray::value is false; + * mozilla::IsArray::value is true; + * mozilla::IsArray::value is true. + */ +template +struct IsArray : detail::IsArrayHelper::Type> +{}; + +/** + * IsPointer determines whether a type is a pointer type (but not a pointer-to- + * member type). + * + * mozilla::IsPointer::value is true; + * mozilla::IsPointer::value is true; + * mozilla::IsPointer::value is true; + * mozilla::IsPointer::value is false; + * mozilla::IsPointer::value is false. + */ +template +struct IsPointer : FalseType {}; + +template +struct IsPointer : TrueType {}; + +/** + * IsLvalueReference determines whether a type is an lvalue reference. + * + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is true; + * mozilla::IsLvalueReference::value is false. + */ +template +struct IsLvalueReference : FalseType {}; + +template +struct IsLvalueReference : TrueType {}; + +/** + * IsRvalueReference determines whether a type is an rvalue reference. + * + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is true. + */ +template +struct IsRvalueReference : FalseType {}; + +template +struct IsRvalueReference : TrueType {}; + +namespace detail { + +// __is_enum is a supported extension across all of our supported compilers. +template +struct IsEnumHelper + : IntegralConstant +{}; + +} // namespace detail + +/** + * IsEnum determines whether a type is an enum type. + * + * mozilla::IsEnum::value is true; + * mozilla::IsEnum::value is false; + * mozilla::IsEnum::value is false; + */ +template +struct IsEnum + : detail::IsEnumHelper::Type> +{}; + +namespace detail { + +// __is_class is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx +template +struct IsClassHelper + : IntegralConstant +{}; + +} // namespace detail + +/** + * IsClass determines whether a type is a class type (but not a union). + * + * struct S {}; + * union U {}; + * mozilla::IsClass::value is false; + * mozilla::IsClass::value is true; + * mozilla::IsClass::value is false; + */ +template +struct IsClass + : detail::IsClassHelper::Type> +{}; + +/* 20.9.4.2 Composite type traits [meta.unary.comp] */ + +/** + * IsReference determines whether a type is an lvalue or rvalue reference. + * + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true. + */ +template +struct IsReference + : IntegralConstant::value || IsRvalueReference::value> +{}; + +/** + * IsArithmetic determines whether a type is arithmetic. A type is arithmetic + * iff it is an integral type or a floating point type. + * + * mozilla::IsArithmetic::value is true; + * mozilla::IsArithmetic::value is true; + * mozilla::IsArithmetic::value is false. + */ +template +struct IsArithmetic + : IntegralConstant::value || IsFloatingPoint::value> +{}; + +/* 20.9.4.3 Type properties [meta.unary.prop] */ + +/** + * IsConst determines whether a type is const or not. + * + * mozilla::IsConst::value is false; + * mozilla::IsConst::value is true; + * mozilla::IsConst::value is false. + */ +template +struct IsConst : FalseType {}; + +template +struct IsConst : TrueType {}; + +/** + * IsVolatile determines whether a type is volatile or not. + * + * mozilla::IsVolatile::value is false; + * mozilla::IsVolatile::value is true; + * mozilla::IsVolatile::value is false. + */ +template +struct IsVolatile : FalseType {}; + +template +struct IsVolatile : TrueType {}; + +/** + * Traits class for identifying POD types. Until C++11 there's no automatic + * way to detect PODs, so for the moment this is done manually. Users may + * define specializations of this class that inherit from mozilla::TrueType and + * mozilla::FalseType (or equivalently mozilla::IntegralConstant, or conveniently from mozilla::IsPod for composite types) as needed to + * ensure correct IsPod behavior. + */ +template +struct IsPod : public FalseType {}; + +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +#ifdef MOZ_CHAR16_IS_NOT_WCHAR +template<> struct IsPod : TrueType {}; +#endif +template struct IsPod : TrueType {}; + +namespace detail { + +// __is_empty is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx +template +struct IsEmptyHelper + : IntegralConstant::value && __is_empty(T)> +{}; + +} // namespace detail + +/** + * IsEmpty determines whether a type is a class (but not a union) that is empty. + * + * A class is empty iff it and all its base classes have no non-static data + * members (except bit-fields of length 0) and no virtual member functions, and + * no base class is empty or a virtual base class. + * + * Intuitively, empty classes don't have any data that has to be stored in + * instances of those classes. (The size of the class must still be non-zero, + * because distinct array elements of any type must have different addresses. + * However, if the Empty Base Optimization is implemented by the compiler [most + * compilers implement it, and in certain cases C++11 requires it], the size of + * a class inheriting from an empty |Base| class need not be inflated by + * |sizeof(Base)|.) And intuitively, non-empty classes have data members and/or + * vtable pointers that must be stored in each instance for proper behavior. + * + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * union U1 { int x; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct E1 {}; + * struct E2 { int : 0 }; + * struct E3 : E1 {}; + * struct E4 : E2 {}; + * static_assert(mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value, + * "all empty"); + * union U2 { E1 e1; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct NE1 { int x; }; + * struct NE2 : virtual E1 {}; + * struct NE3 : E2 { virtual ~NE3() {} }; + * struct NE4 { virtual void f() {} }; + * static_assert(!mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value, + * "all empty"); + */ +template +struct IsEmpty : detail::IsEmptyHelper::Type> +{}; + + +namespace detail { + +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> +struct IsSignedHelper; + +// Floating point is signed. +template +struct IsSignedHelper : TrueType {}; + +// Integral is conditionally signed. +template +struct IsSignedHelper + : IntegralConstant +{}; + +// Non-floating point, non-integral is not signed. +template +struct IsSignedHelper : FalseType {}; + +} // namespace detail + +/** + * IsSigned determines whether a type is a signed arithmetic type. |char| is + * considered a signed type if it has the same representation as |signed char|. + * + * mozilla::IsSigned::value is true; + * mozilla::IsSigned::value is false; + * mozilla::IsSigned::value is false; + * mozilla::IsSigned::value is true. + */ +template +struct IsSigned : detail::IsSignedHelper {}; + +namespace detail { + +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> +struct IsUnsignedHelper; + +// Floating point is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; + +// Integral is conditionally unsigned. +template +struct IsUnsignedHelper + : IntegralConstant::value || bool(NoCV(1) < NoCV(-1)))> +{}; + +// Non-floating point, non-integral is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; + +} // namespace detail + +/** + * IsUnsigned determines whether a type is an unsigned arithmetic type. + * + * mozilla::IsUnsigned::value is false; + * mozilla::IsUnsigned::value is true; + * mozilla::IsUnsigned::value is true; + * mozilla::IsUnsigned::value is false. + */ +template +struct IsUnsigned : detail::IsUnsignedHelper {}; + +/* 20.9.5 Type property queries [meta.unary.prop.query] */ + +/* 20.9.6 Relationships between types [meta.rel] */ + +/** + * IsSame tests whether two types are the same type. + * + * mozilla::IsSame::value is true; + * mozilla::IsSame::value is true; + * mozilla::IsSame::value is false; + * mozilla::IsSame::value is true; + * mozilla::IsSame::value is false; + * mozilla::IsSame::value is true. + */ +template +struct IsSame : FalseType {}; + +template +struct IsSame : TrueType {}; + +namespace detail { + +#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) + +template +struct BaseOfTester : IntegralConstant {}; + +#else + +// The trickery used to implement IsBaseOf here makes it possible to use it for +// the cases of private and multiple inheritance. This code was inspired by the +// sample code here: +// +// http://stackoverflow.com/questions/2910979/how-is-base-of-works +template +struct BaseOfHelper +{ +public: + operator Base*() const; + operator Derived*(); +}; + +template +struct BaseOfTester +{ +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); +}; + +template +struct BaseOfTester +{ +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); +}; + +template +struct BaseOfTester : FalseType {}; + +template +struct BaseOfTester : TrueType {}; + +template +struct BaseOfTester : TrueType {}; + +#endif + +} /* namespace detail */ + +/* + * IsBaseOf allows to know whether a given class is derived from another. + * + * Consider the following class definitions: + * + * class A {}; + * class B : public A {}; + * class C {}; + * + * mozilla::IsBaseOf::value is true; + * mozilla::IsBaseOf::value is false; + */ +template +struct IsBaseOf + : IntegralConstant::value> +{}; + +namespace detail { + +template +struct ConvertibleTester +{ +private: + static From create(); + + template + static char test(To to); + + template + static int test(...); + +public: + static const bool value = + sizeof(test(create())) == sizeof(char); +}; + +} // namespace detail + +/** + * IsConvertible determines whether a value of type From will implicitly convert + * to a value of type To. For example: + * + * struct A {}; + * struct B : public A {}; + * struct C {}; + * + * mozilla::IsConvertible::value is true; + * mozilla::IsConvertible::value is true; + * mozilla::IsConvertible::value is true; + * mozilla::IsConvertible::value is true; + * mozilla::IsConvertible::value is false; + * mozilla::IsConvertible::value is false; + * mozilla::IsConvertible::value is false; + * mozilla::IsConvertible::value is false. + * + * For obscure reasons, you can't use IsConvertible when the types being tested + * are related through private inheritance, and you'll get a compile error if + * you try. Just don't do it! + */ +template +struct IsConvertible + : IntegralConstant::value> +{}; + +/* 20.9.7 Transformations between types [meta.trans] */ + +/* 20.9.7.1 Const-volatile modifications [meta.trans.cv] */ + +/** + * RemoveConst removes top-level const qualifications on a type. + * + * mozilla::RemoveConst::Type is int; + * mozilla::RemoveConst::Type is int; + * mozilla::RemoveConst::Type is const int*; + * mozilla::RemoveConst::Type is int*. + */ +template +struct RemoveConst +{ + typedef T Type; +}; + +template +struct RemoveConst +{ + typedef T Type; +}; + +/** + * RemoveVolatile removes top-level volatile qualifications on a type. + * + * mozilla::RemoveVolatile::Type is int; + * mozilla::RemoveVolatile::Type is int; + * mozilla::RemoveVolatile::Type is volatile int*; + * mozilla::RemoveVolatile::Type is int*. + */ +template +struct RemoveVolatile +{ + typedef T Type; +}; + +template +struct RemoveVolatile +{ + typedef T Type; +}; + +/** + * RemoveCV removes top-level const and volatile qualifications on a type. + * + * mozilla::RemoveCV::Type is int; + * mozilla::RemoveCV::Type is int; + * mozilla::RemoveCV::Type is int; + * mozilla::RemoveCV::Type is int*. + */ +template +struct RemoveCV +{ + typedef typename RemoveConst::Type>::Type Type; +}; + +/* 20.9.7.2 Reference modifications [meta.trans.ref] */ + +/** + * Converts reference types to the underlying types. + * + * mozilla::RemoveReference::Type is T; + * mozilla::RemoveReference::Type is T; + * mozilla::RemoveReference::Type is T; + */ + +template +struct RemoveReference +{ + typedef T Type; +}; + +template +struct RemoveReference +{ + typedef T Type; +}; + +template +struct RemoveReference +{ + typedef T Type; +}; + +template +struct Conditional; + +namespace detail { + +enum Voidness { TIsVoid, TIsNotVoid }; + +template::value ? TIsVoid : TIsNotVoid> +struct AddLvalueReferenceHelper; + +template +struct AddLvalueReferenceHelper +{ + typedef void Type; +}; + +template +struct AddLvalueReferenceHelper +{ + typedef T& Type; +}; + +} // namespace detail + +/** + * AddLvalueReference adds an lvalue & reference to T if one isn't already + * present. (Note: adding an lvalue reference to an rvalue && reference in + * essence replaces the && with a &&, per C+11 reference collapsing rules. For + * example, int&& would become int&.) + * + * The final computed type will only *not* be an lvalue reference if T is void. + * + * mozilla::AddLvalueReference::Type is int&; + * mozilla::AddLvalueRference::Type is volatile int&; + * mozilla::AddLvalueReference::Type is void*&; + * mozilla::AddLvalueReference::Type is void; + * mozilla::AddLvalueReference::Type is struct S&. + */ +template +struct AddLvalueReference + : detail::AddLvalueReferenceHelper +{}; + +/* 20.9.7.3 Sign modifications [meta.trans.sign] */ + +template +struct EnableIf; + +namespace detail { + +template +struct WithC : Conditional +{}; + +template +struct WithV : Conditional +{}; + + +template +struct WithCV : WithC::Type> +{}; + +template +struct CorrespondingSigned; + +template<> +struct CorrespondingSigned { typedef signed char Type; }; +template<> +struct CorrespondingSigned { typedef signed char Type; }; +template<> +struct CorrespondingSigned { typedef short Type; }; +template<> +struct CorrespondingSigned { typedef int Type; }; +template<> +struct CorrespondingSigned { typedef long Type; }; +template<> +struct CorrespondingSigned { typedef long long Type; }; + +template::Type, + bool IsSignedIntegerType = IsSigned::value && + !IsSame::value> +struct MakeSigned; + +template +struct MakeSigned +{ + typedef T Type; +}; + +template +struct MakeSigned + : WithCV::value, IsVolatile::value, + typename CorrespondingSigned::Type> +{}; + +} // namespace detail + +/** + * MakeSigned produces the corresponding signed integer type for a given + * integral type T, with the const/volatile qualifiers of T. T must be a + * possibly-const/volatile-qualified integral type that isn't bool. + * + * If T is already a signed integer type (not including char!), then T is + * produced. + * + * Otherwise, if T is an unsigned integer type, the signed variety of T, with + * T's const/volatile qualifiers, is produced. + * + * Otherwise, the integral type of the same size as T, with the lowest rank, + * with T's const/volatile qualifiers, is produced. (This basically only acts + * to produce signed char when T = char.) + * + * mozilla::MakeSigned::Type is signed long; + * mozilla::MakeSigned::Type is volatile int; + * mozilla::MakeSigned::Type is const signed short; + * mozilla::MakeSigned::Type is const signed char; + * mozilla::MakeSigned is an error; + * mozilla::MakeSigned is an error. + */ +template +struct MakeSigned + : EnableIf::value && + !IsSame::Type>::value, + typename detail::MakeSigned + >::Type +{}; + +namespace detail { + +template +struct CorrespondingUnsigned; + +template<> +struct CorrespondingUnsigned { typedef unsigned char Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned char Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned short Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned int Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned long Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned long long Type; }; + + +template::Type, + bool IsUnsignedIntegerType = IsUnsigned::value && + !IsSame::value> +struct MakeUnsigned; + +template +struct MakeUnsigned +{ + typedef T Type; +}; + +template +struct MakeUnsigned + : WithCV::value, IsVolatile::value, + typename CorrespondingUnsigned::Type> +{}; + +} // namespace detail + +/** + * MakeUnsigned produces the corresponding unsigned integer type for a given + * integral type T, with the const/volatile qualifiers of T. T must be a + * possibly-const/volatile-qualified integral type that isn't bool. + * + * If T is already an unsigned integer type (not including char!), then T is + * produced. + * + * Otherwise, if T is an signed integer type, the unsigned variety of T, with + * T's const/volatile qualifiers, is produced. + * + * Otherwise, the unsigned integral type of the same size as T, with the lowest + * rank, with T's const/volatile qualifiers, is produced. (This basically only + * acts to produce unsigned char when T = char.) + * + * mozilla::MakeUnsigned::Type is unsigned long; + * mozilla::MakeUnsigned::Type is volatile unsigned int; + * mozilla::MakeUnsigned::Type is const unsigned short; + * mozilla::MakeUnsigned::Type is const unsigned char; + * mozilla::MakeUnsigned is an error; + * mozilla::MakeUnsigned is an error. + */ +template +struct MakeUnsigned + : EnableIf::value && + !IsSame::Type>::value, + typename detail::MakeUnsigned + >::Type +{}; + +/* 20.9.7.4 Array modifications [meta.trans.arr] */ + +/** + * RemoveExtent produces either the type of the elements of the array T, or T + * itself. + * + * mozilla::RemoveExtent::Type is int; + * mozilla::RemoveExtent::Type is const int; + * mozilla::RemoveExtent::Type is volatile int; + * mozilla::RemoveExtent::Type is long[17]. + */ +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + +/* 20.9.7.5 Pointer modifications [meta.trans.ptr] */ + +/* 20.9.7.6 Other transformations [meta.trans.other] */ + +/** + * EnableIf is a struct containing a typedef of T if and only if B is true. + * + * mozilla::EnableIf::Type is int; + * mozilla::EnableIf::Type is a compile-time error. + * + * Use this template to implement SFINAE-style (Substitution Failure Is not An + * Error) requirements. For example, you might use it to impose a restriction + * on a template parameter: + * + * template + * class PodVector // vector optimized to store POD (memcpy-able) types + * { + * EnableIf::value, T>::Type* vector; + * size_t length; + * ... + * }; + */ +template +struct EnableIf +{}; + +template +struct EnableIf +{ + typedef T Type; +}; + +/** + * Conditional selects a class between two, depending on a given boolean value. + * + * mozilla::Conditional::Type is A; + * mozilla::Conditional::Type is B; + */ +template +struct Conditional +{ + typedef A Type; +}; + +template +struct Conditional +{ + typedef B Type; +}; + +} /* namespace mozilla */ + +#endif /* mozilla_TypeTraits_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/TypedEnum.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/TypedEnum.h new file mode 100644 index 0000000000..d84cd90257 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/TypedEnum.h @@ -0,0 +1,281 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Macros to emulate C++11 typed enums and enum classes. */ + +#ifndef mozilla_TypedEnum_h +#define mozilla_TypedEnum_h + +#include "mozilla/TypedEnumInternal.h" +#include "mozilla/MacroArgs.h" + +#if defined(__cplusplus) + +/** + * MOZ_ENUM_TYPE specifies the underlying numeric type for an enum. It's + * specified by placing MOZ_ENUM_TYPE(type) immediately after the enum name in + * its declaration, and before the opening curly brace, like + * + * enum MyEnum MOZ_ENUM_TYPE(uint16_t) + * { + * A, + * B = 7, + * C + * }; + * + * In supporting compilers, the macro will expand to ": uint16_t". The + * compiler will allocate exactly two bytes for MyEnum and will require all + * enumerators to have values between 0 and 65535. (Thus specifying "B = + * 100000" instead of "B = 7" would fail to compile.) In old compilers the + * macro expands to the empty string, and the underlying type is generally + * undefined. + */ +#ifdef MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_ENUM_TYPE(type) : type +#else +# define MOZ_ENUM_TYPE(type) /* no support */ +#endif + +/** + * MOZ_BEGIN_ENUM_CLASS and MOZ_END_ENUM_CLASS provide access to the + * strongly-typed enumeration feature of C++11 ("enum class"). If supported + * by the compiler, an enum defined using these macros will not be implicitly + * converted to any other type, and its enumerators will be scoped using the + * enumeration name. Place MOZ_BEGIN_ENUM_CLASS(EnumName [, type]) in place of + * "enum EnumName {", and MOZ_END_ENUM_CLASS(EnumName) in place of the closing + * "};". For example, + * + * MOZ_BEGIN_ENUM_CLASS(Enum, int32_t) + * A, + * B = 6 + * MOZ_END_ENUM_CLASS(Enum) + * + * This will make "Enum::A" and "Enum::B" appear in the global scope, but "A" + * and "B" will not. In compilers that support C++11 strongly-typed + * enumerations, implicit conversions of Enum values to numeric types will + * fail. In other compilers, Enum itself will actually be defined as a class, + * and some implicit conversions will fail while others will succeed. + * + * The optional type argument specifies the underlying type for the enum where + * supported, as with MOZ_ENUM_TYPE(). As with MOZ_ENUM_TYPE(), it will do + * nothing on compilers that do not support it. + * + * MOZ_{BEGIN,END}_ENUM_CLASS doesn't work for defining enum classes nested + * inside classes. To define an enum class nested inside another class, use + * MOZ_{BEGIN,END}_NESTED_ENUM_CLASS, and place a MOZ_FINISH_NESTED_ENUM_CLASS + * in namespace scope to handle bits that can only be implemented with + * namespace-scoped code. For example: + * + * class FooBar + * { + * MOZ_BEGIN_NESTED_ENUM_CLASS(Enum, int32_t) + * A, + * B = 6 + * MOZ_END_NESTED_ENUM_CLASS(Enum) + * }; + * + * MOZ_FINISH_NESTED_ENUM_CLASS(FooBar::Enum) + */ +#if defined(MOZ_HAVE_CXX11_STRONG_ENUMS) + /* + * All compilers that support strong enums also support an explicit + * underlying type, so no extra check is needed. + */ + + /* Single-argument form. */ +# define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER1(Name) \ + enum class Name { + /* Two-argument form. */ +# define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER2(Name, type) \ + enum class Name : type { +# define MOZ_END_NESTED_ENUM_CLASS(Name) \ + }; +# define MOZ_FINISH_NESTED_ENUM_CLASS(Name) /* nothing */ + + /* + * MOZ_ENUM_CLASS_ENUM_TYPE allows using enum classes + * as template parameter types. For that, we need integer types. + * In the present case where the compiler supports strong enums, + * these are already integer types so there is nothing more to do. + */ +# define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name + /* + * See the comment below about MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) Name +#else + /** + * We need Name to both name a type, and scope the provided enumerator + * names. Namespaces and classes both provide scoping, but namespaces + * aren't types, so we need to use a class that wraps the enum values. We + * have an implicit conversion from the inner enum type to the class, so + * statements like + * + * Enum x = Enum::A; + * + * will still work. We need to define an implicit conversion from the class + * to the inner enum as well, so that (for instance) switch statements will + * work. This means that the class can be implicitly converted to a numeric + * value as well via the enum type, since C++ allows an implicit + * user-defined conversion followed by a standard conversion to still be + * implicit. + * + * We have an explicit constructor from int defined, so that casts like + * (Enum)7 will still work. We also have a zero-argument constructor with + * no arguments, so declaration without initialization (like "Enum foo;") + * will work. + * + * Additionally, we'll delete as many operators as possible for the inner + * enum type, so statements like this will still fail: + * + * f(5 + Enum::B); // deleted operator+ + * + * But we can't prevent things like this, because C++ doesn't allow + * overriding conversions or assignment operators for enums: + * + * int x = Enum::A; + * int f() + * { + * return Enum::A; + * } + */ + + /* Single-argument form. */ +# define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER1(Name) \ + class Name \ + { \ + public: \ + enum Enum \ + { + /* Two-argument form. */ +# define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER2(Name, type) \ + class Name \ + { \ + public: \ + enum Enum MOZ_ENUM_TYPE(type) \ + { +# define MOZ_END_NESTED_ENUM_CLASS(Name) \ + }; \ + Name() {} \ + MOZ_CONSTEXPR Name(Enum aEnum) : mEnum(aEnum) {} \ + template \ + explicit MOZ_CONSTEXPR Name(Other num) : mEnum((Enum)num) {} \ + MOZ_CONSTEXPR operator Enum() const { return mEnum; } \ + explicit MOZ_CONSTEXPR Name(const mozilla::CastableTypedEnumResult& aOther) \ + : mEnum(aOther.get()) \ + {} \ + private: \ + Enum mEnum; \ + }; +# define MOZ_FINISH_NESTED_ENUM_CLASS(Name) \ + inline int operator+(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator+(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator-(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator-(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator*(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator*(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator/(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator/(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator%(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator%(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator+(const Name::Enum&) MOZ_DELETE; \ + inline int operator-(const Name::Enum&) MOZ_DELETE; \ + inline int& operator++(Name::Enum&) MOZ_DELETE; \ + inline int operator++(Name::Enum&, int) MOZ_DELETE; \ + inline int& operator--(Name::Enum&) MOZ_DELETE; \ + inline int operator--(Name::Enum&, int) MOZ_DELETE; \ + inline bool operator==(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator==(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator!=(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator!=(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator>(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator>(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator<(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator<(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator>=(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator>=(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator<=(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator<=(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator!(const Name::Enum&) MOZ_DELETE; \ + inline bool operator&&(const bool&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator&&(const Name::Enum&, const bool&) MOZ_DELETE; \ + inline bool operator||(const bool&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator||(const Name::Enum&, const bool&) MOZ_DELETE; \ + inline int operator&(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator&(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator|(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator|(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator^(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator^(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator<<(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator<<(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator>>(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator>>(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int& operator+=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator-=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator*=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator/=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator%=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator&=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator|=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator^=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator<<=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator>>=(int&, const Name::Enum&) MOZ_DELETE; + + /* + * MOZ_ENUM_CLASS_ENUM_TYPE allows using enum classes + * as template parameter types. For that, we need integer types. + * In the present case, the integer type is the Enum nested type. + */ +# define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name::Enum + /* + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is a variant of MOZ_ENUM_CLASS_ENUM_TYPE + * to be used when the enum class at hand depends on template parameters. + * + * Indeed, if T depends on template parameters, in order to name a nested type + * in T, C++ does not allow to just write "T::NestedType". Instead, we have + * to write "typename T::NestedType". The role of this macro is to add + * this "typename" keywords where needed. + * + * Example: + * + * template + * struct S {}; + * + * MOZ_BEGIN_ENUM_CLASS(E) + * Foo, + * Bar + * MOZ_END_ENUM_CLASS(E) + * + * S s; + * + * In this example, the second template parameter to S is meant to be of type + * T, but on non-C++11 compilers, type T is a class type, not an integer + * type, so it is not accepted as the type of a constant template parameter. + * One would then want to use MOZ_ENUM_CLASS_ENUM_TYPE(T), but that doesn't + * work either as T depends on template parameters (more specifically here, T + * _is_ a template parameter) so as MOZ_ENUM_CLASS_ENUM_TYPE(T) expands to + * T::Enum, we are missing the required "typename" keyword. So here, + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is needed. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) typename Name::Enum +#endif + +# define MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(a, b) a b +# define MOZ_BEGIN_NESTED_ENUM_CLASS(...) \ + MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER, \ + __VA_ARGS__), \ + (__VA_ARGS__)) + +# define MOZ_BEGIN_ENUM_CLASS(...) MOZ_BEGIN_NESTED_ENUM_CLASS(__VA_ARGS__) +# define MOZ_END_ENUM_CLASS(Name) \ + MOZ_END_NESTED_ENUM_CLASS(Name) \ + MOZ_FINISH_NESTED_ENUM_CLASS(Name) + +#endif /* __cplusplus */ + +#endif /* mozilla_TypedEnum_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/TypedEnumInternal.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/TypedEnumInternal.h new file mode 100644 index 0000000000..8c88cb589b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/TypedEnumInternal.h @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Internal stuff needed by TypedEnum.h and TypedEnumBits.h. */ + +// NOTE: When we can assume C++11 enum class support and TypedEnum.h goes away, +// we should then consider folding TypedEnumInternal.h into TypedEnumBits.h. + +#ifndef mozilla_TypedEnumInternal_h +#define mozilla_TypedEnumInternal_h + +#include "mozilla/Attributes.h" + +#if defined(__cplusplus) + +#if defined(__clang__) + /* + * Per Clang documentation, "Note that marketing version numbers should not + * be used to check for language features, as different vendors use different + * numbering schemes. Instead, use the feature checking macros." + */ +# ifndef __has_extension +# define __has_extension __has_feature /* compatibility, for older versions of clang */ +# endif +# if __has_extension(cxx_strong_enums) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#elif defined(__GNUC__) +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +# endif +#elif defined(_MSC_VER) +# if _MSC_VER >= 1400 +# define MOZ_HAVE_CXX11_ENUM_TYPE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#endif + +namespace mozilla { + +/* + * The problem that CastableTypedEnumResult aims to solve is that + * typed enums are not convertible to bool, and there is no way to make them + * be, yet user code wants to be able to write + * + * if (myFlags & Flags::SOME_PARTICULAR_FLAG) (1) + * + * There are different approaches to solving this. Most of them require + * adapting user code. For example, we could implement operator! and have + * the user write + * + * if (!!(myFlags & Flags::SOME_PARTICULAR_FLAG)) (2) + * + * Or we could supply a IsNonZero() or Any() function returning whether + * an enum value is nonzero, and have the user write + * + * if (Any(Flags & Flags::SOME_PARTICULAR_FLAG)) (3) + * + * But instead, we choose to preserve the original user syntax (1) as it + * is inherently more readable, and to ease porting existing code to typed + * enums. We achieve this by having operator& and other binary bitwise + * operators have as return type a class, CastableTypedEnumResult, + * that wraps a typed enum but adds bool convertibility. + */ +template +class CastableTypedEnumResult +{ +private: + const E mValue; + +public: + explicit MOZ_CONSTEXPR CastableTypedEnumResult(E aValue) + : mValue(aValue) + {} + + MOZ_CONSTEXPR operator E() const { return mValue; } + + template + MOZ_EXPLICIT_CONVERSION MOZ_CONSTEXPR + operator DestinationType() const { return DestinationType(mValue); } + + MOZ_CONSTEXPR bool operator !() const { return !bool(mValue); } + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS + // This get() method is used to implement a constructor in the + // non-c++11 fallback path for MOZ_BEGIN_ENUM_CLASS, taking a + // CastableTypedEnumResult. If we try to implement it using the + // above conversion operator E(), then at least clang 3.3 + // (when forced to take the non-c++11 fallback path) compiles + // this constructor to an infinite recursion. So we introduce this + // get() method, that does exactly the same as the conversion operator, + // to work around this. + MOZ_CONSTEXPR E get() const { return mValue; } +#endif +}; + +} // namespace mozilla + +#endif // __cplusplus + +#endif // mozilla_TypedEnumInternal_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Types.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Types.h new file mode 100644 index 0000000000..e7e18abb27 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Types.h @@ -0,0 +1,134 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* mfbt foundational types and macros. */ + +#ifndef mozilla_Types_h +#define mozilla_Types_h + +/* + * This header must be valid C and C++, includable by code embedding either + * SpiderMonkey or Gecko. + */ + +/* Expose all types and size_t. */ +#include +#include + +/* Implement compiler and linker macros needed for APIs. */ + +/* + * MOZ_EXPORT is used to declare and define a symbol or type which is externally + * visible to users of the current library. It encapsulates various decorations + * needed to properly export the method's symbol. + * + * api.h: + * extern MOZ_EXPORT int MeaningOfLife(void); + * extern MOZ_EXPORT int LuggageCombination; + * + * api.c: + * int MeaningOfLife(void) { return 42; } + * int LuggageCombination = 12345; + * + * If you are merely sharing a method across files, just use plain |extern|. + * These macros are designed for use by library interfaces -- not for normal + * methods or data used cross-file. + */ +#if defined(WIN32) +# define MOZ_EXPORT __declspec(dllexport) +#else /* Unix */ +# ifdef HAVE_VISIBILITY_ATTRIBUTE +# define MOZ_EXPORT __attribute__((visibility("default"))) +# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) +# define MOZ_EXPORT __global +# else +# define MOZ_EXPORT /* nothing */ +# endif +#endif + + +/* + * Whereas implementers use MOZ_EXPORT to declare and define library symbols, + * users use MOZ_IMPORT_API and MOZ_IMPORT_DATA to access them. Most often the + * implementer of the library will expose an API macro which expands to either + * the export or import version of the macro, depending upon the compilation + * mode. + */ +#ifdef _WIN32 +# if defined(__MWERKS__) +# define MOZ_IMPORT_API /* nothing */ +# else +# define MOZ_IMPORT_API __declspec(dllimport) +# endif +#else +# define MOZ_IMPORT_API MOZ_EXPORT +#endif + +#if defined(_WIN32) && !defined(__MWERKS__) +# define MOZ_IMPORT_DATA __declspec(dllimport) +#else +# define MOZ_IMPORT_DATA MOZ_EXPORT +#endif + +/* + * Consistent with the above comment, the MFBT_API and MFBT_DATA macros expose + * export mfbt declarations when building mfbt, and they expose import mfbt + * declarations when using mfbt. + */ +#if defined(IMPL_MFBT) +# define MFBT_API MOZ_EXPORT +# define MFBT_DATA MOZ_EXPORT +#else + /* + * On linux mozglue is linked in the program and we link libxul.so with + * -z,defs. Normally that causes the linker to reject undefined references in + * libxul.so, but as a loophole it allows undefined references to weak + * symbols. We add the weak attribute to the import version of the MFBT API + * macros to exploit this. + */ +# if defined(MOZ_GLUE_IN_PROGRAM) +# define MFBT_API __attribute__((weak)) MOZ_IMPORT_API +# define MFBT_DATA __attribute__((weak)) MOZ_IMPORT_DATA +# else +# define MFBT_API MOZ_IMPORT_API +# define MFBT_DATA MOZ_IMPORT_DATA +# endif +#endif + +/* + * C symbols in C++ code must be declared immediately within |extern "C"| + * blocks. However, in C code, they need not be declared specially. This + * difference is abstracted behind the MOZ_BEGIN_EXTERN_C and MOZ_END_EXTERN_C + * macros, so that the user need not know whether he is being used in C or C++ + * code. + * + * MOZ_BEGIN_EXTERN_C + * + * extern MOZ_EXPORT int MostRandomNumber(void); + * ...other declarations... + * + * MOZ_END_EXTERN_C + * + * This said, it is preferable to just use |extern "C"| in C++ header files for + * its greater clarity. + */ +#ifdef __cplusplus +# define MOZ_BEGIN_EXTERN_C extern "C" { +# define MOZ_END_EXTERN_C } +#else +# define MOZ_BEGIN_EXTERN_C +# define MOZ_END_EXTERN_C +#endif + +/* + * GCC's typeof is available when decltype is not. + */ +#if defined(__GNUC__) && defined(__cplusplus) && \ + !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L +# define decltype __typeof__ +#endif + +#endif /* mozilla_Types_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/UniquePtr.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/UniquePtr.h new file mode 100644 index 0000000000..9c873db90c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/UniquePtr.h @@ -0,0 +1,674 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Smart pointer managing sole ownership of a resource. */ + +#ifndef mozilla_UniquePtr_h +#define mozilla_UniquePtr_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/Pair.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +template class DefaultDelete; +template> class UniquePtr; + +} // namespace mozilla + +namespace mozilla { + +/** + * UniquePtr is a smart pointer that wholly owns a resource. Ownership may be + * transferred out of a UniquePtr through explicit action, but otherwise the + * resource is destroyed when the UniquePtr is destroyed. + * + * UniquePtr is similar to C++98's std::auto_ptr, but it improves upon auto_ptr + * in one crucial way: it's impossible to copy a UniquePtr. Copying an auto_ptr + * obviously *can't* copy ownership of its singly-owned resource. So what + * happens if you try to copy one? Bizarrely, ownership is implicitly + * *transferred*, preserving single ownership but breaking code that assumes a + * copy of an object is identical to the original. (This is why auto_ptr is + * prohibited in STL containers.) + * + * UniquePtr solves this problem by being *movable* rather than copyable. + * Instead of passing a |UniquePtr u| directly to the constructor or assignment + * operator, you pass |Move(u)|. In doing so you indicate that you're *moving* + * ownership out of |u|, into the target of the construction/assignment. After + * the transfer completes, |u| contains |nullptr| and may be safely destroyed. + * This preserves single ownership but also allows UniquePtr to be moved by + * algorithms that have been made move-safe. (Note: if |u| is instead a + * temporary expression, don't use |Move()|: just pass the expression, because + * it's already move-ready. For more information see Move.h.) + * + * UniquePtr is also better than std::auto_ptr in that the deletion operation is + * customizable. An optional second template parameter specifies a class that + * (through its operator()(T*)) implements the desired deletion policy. If no + * policy is specified, mozilla::DefaultDelete is used -- which will either + * |delete| or |delete[]| the resource, depending whether the resource is an + * array. Custom deletion policies ideally should be empty classes (no member + * fields, no member fields in base classes, no virtual methods/inheritance), + * because then UniquePtr can be just as efficient as a raw pointer. + * + * Use of UniquePtr proceeds like so: + * + * UniquePtr g1; // initializes to nullptr + * g1.reset(new int); // switch resources using reset() + * g1 = nullptr; // clears g1, deletes the int + * + * UniquePtr g2(new int); // owns that int + * int* p = g2.release(); // g2 leaks its int -- still requires deletion + * delete p; // now freed + * + * struct S { int x; S(int x) : x(x) {} }; + * UniquePtr g3, g4(new S(5)); + * g3 = Move(g4); // g3 owns the S, g4 cleared + * S* p = g3.get(); // g3 still owns |p| + * assert(g3->x == 5); // operator-> works (if .get() != nullptr) + * assert((*g3).x == 5); // also operator* (again, if not cleared) + * Swap(g3, g4); // g4 now owns the S, g3 cleared + * g3.swap(g4); // g3 now owns the S, g4 cleared + * UniquePtr g5(Move(g3)); // g5 owns the S, g3 cleared + * g5.reset(); // deletes the S, g5 cleared + * + * struct FreePolicy { void operator()(void* p) { free(p); } }; + * UniquePtr g6(static_cast(malloc(sizeof(int)))); + * int* ptr = g6.get(); + * g6 = nullptr; // calls free(ptr) + * + * Now, carefully note a few things you *can't* do: + * + * UniquePtr b1; + * b1 = new int; // BAD: can only assign another UniquePtr + * int* ptr = b1; // BAD: no auto-conversion to pointer, use get() + * + * UniquePtr b2(b1); // BAD: can't copy a UniquePtr + * UniquePtr b3 = b1; // BAD: can't copy-assign a UniquePtr + * + * A few miscellaneous notes: + * + * UniquePtr, when not instantiated for an array type, can be move-constructed + * and move-assigned, not only from itself but from "derived" UniquePtr + * instantiations where U converts to T and E converts to D. If you want to use + * this, you're going to have to specify a deletion policy for both UniquePtr + * instantations, and T pretty much has to have a virtual destructor. In other + * words, this doesn't work: + * + * struct Base { virtual ~Base() {} }; + * struct Derived : Base {}; + * + * UniquePtr b1; + * // BAD: DefaultDelete and DefaultDelete don't interconvert + * UniquePtr d1(Move(b)); + * + * UniquePtr b2; + * UniquePtr> d2(Move(b2)); // okay + * + * UniquePtr is specialized for array types. Specializing with an array type + * creates a smart-pointer version of that array -- not a pointer to such an + * array. + * + * UniquePtr arr(new int[5]); + * arr[0] = 4; + * + * What else is different? Deletion of course uses |delete[]|. An operator[] + * is provided. Functionality that doesn't make sense for arrays is removed. + * The constructors and mutating methods only accept array pointers (not T*, U* + * that converts to T*, or UniquePtr or UniquePtr) or |nullptr|. + * + * It's perfectly okay to return a UniquePtr from a method to assure the related + * resource is properly deleted. You'll need to use |Move()| when returning a + * local UniquePtr. Otherwise you can return |nullptr|, or you can return + * |UniquePtr(ptr)|. + * + * UniquePtr will commonly be a member of a class, with lifetime equivalent to + * that of that class. If you want to expose the related resource, you could + * expose a raw pointer via |get()|, but ownership of a raw pointer is + * inherently unclear. So it's better to expose a |const UniquePtr&| instead. + * This prohibits mutation but still allows use of |get()| when needed (but + * operator-> is preferred). Of course, you can only use this smart pointer as + * long as the enclosing class instance remains live -- no different than if you + * exposed the |get()| raw pointer. + * + * To pass a UniquePtr-managed resource as a pointer, use a |const UniquePtr&| + * argument. To specify an inout parameter (where the method may or may not + * take ownership of the resource, or reset it), or to specify an out parameter + * (where simply returning a |UniquePtr| isn't possible), use a |UniquePtr&| + * argument. To unconditionally transfer ownership of a UniquePtr + * into a method, use a |UniquePtr| argument. To conditionally transfer + * ownership of a resource into a method, should the method want it, use a + * |UniquePtr&&| argument. + */ +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + Pointer& ptr() { return tuple.first(); } + const Pointer& ptr() const { return tuple.first(); } + + DeleterType& del() { return tuple.second(); } + const DeleterType& del() const { return tuple.second(); } + + public: + /** + * Construct a UniquePtr containing |nullptr|. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! Ideally + // you should make deletion use the same function every time, using a + // deleter policy: + // + // // BAD, won't compile with MSVC10, deleter doesn't need to be a + // // variable at all + // typedef void (&FreeSignature)(void*); + // UniquePtr ptr((int*) malloc(sizeof(int)), free); + // + // // GOOD, compiles with MSVC10, deletion behavior statically known and + // // optimizable + // struct DeleteByFreeing + // { + // void operator()(void* ptr) { free(ptr); } + // }; + // + // If deletion really, truly, must be a variable: you might be able to work + // around this with a deleter class that contains the function reference. + // But this workaround is untried and untested, because variable deletion + // behavior really isn't something you should use. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + template + UniquePtr(UniquePtr&& other, + typename EnableIf::Pointer, + Pointer>::value && + !IsArray::value && + (IsReference::value + ? IsSame::value + : IsConvertible::value), + int>::Type dummy = 0) + : tuple(other.release(), Forward(other.getDeleter())) + { + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + template + UniquePtr& operator=(UniquePtr&& other) + { + static_assert(IsConvertible::Pointer, Pointer>::value, + "incompatible UniquePtr pointees"); + static_assert(!IsArray::value, + "can't assign from UniquePtr holding an array"); + + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT n) { + MOZ_ASSERT(n == nullptr); + reset(nullptr); + return *this; + } + + T& operator*() const { return *get(); } + Pointer operator->() const { + MOZ_ASSERT(get(), "dereferencing a UniquePtr containing nullptr"); + return get(); + } + + Pointer get() const { return ptr(); } + + DeleterType& getDeleter() { return del(); } + const DeleterType& getDeleter() const { return del(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = ptr(); + ptr() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = ptr(); + ptr() = p; + if (old != nullptr) + getDeleter()(old); + } + + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +// In case you didn't read the comment by the main definition (you should!): the +// UniquePtr specialization exists to manage array pointers. It deletes +// such pointers using delete[], it will reject construction and modification +// attempts using U* or U[]. Otherwise it works like the normal UniquePtr. +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + public: + /** + * Construct a UniquePtr containing nullptr. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + private: + // delete[] knows how to handle *only* an array of a single class type. For + // delete[] to work correctly, it must know the size of each element, the + // fields and base classes of each element requiring destruction, and so on. + // So forbid all overloads which would end up invoking delete[] on a pointer + // of the wrong type. + template + UniquePtr(U&& u, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! See the + // comment by this constructor in the non-T[] specialization above. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + private: + // Forbidden for the same reasons as stated above. + template + UniquePtr(U&& u, V&& v, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT) { + reset(); + return *this; + } + + T& operator[](decltype(sizeof(int)) i) const { return get()[i]; } + Pointer get() const { return tuple.first(); } + + DeleterType& getDeleter() { return tuple.second(); } + const DeleterType& getDeleter() const { return tuple.second(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = tuple.first(); + tuple.first() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = tuple.first(); + tuple.first() = p; + if (old != nullptr) + tuple.second()(old); + } + + private: + // Kill off all remaining overloads that aren't true nullptr (the overload + // above should handle that) or emulated nullptr (which acts like int/long + // on gcc 4.4/4.5). + template + void reset(U, + typename EnableIf::value && + !IsSame::Type>::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +/** A default deletion policy using plain old operator delete. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + template + DefaultDelete(const DefaultDelete& other, + typename EnableIf::value, + int>::Type dummy = 0) + {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete ptr; + } +}; + +/** A default deletion policy using operator delete[]. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete[] ptr; + } + + private: + template + void operator()(U* ptr) const MOZ_DELETE; +}; + +template +void +Swap(UniquePtr& x, UniquePtr& y) +{ + x.swap(y); +} + +template +bool +operator==(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() == y.get(); +} + +template +bool +operator!=(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() != y.get(); +} + +template +bool +operator==(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator==(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator!=(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +template +bool +operator!=(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +// No operator<, operator>, operator<=, operator>= for now because simplicity. + +namespace detail { + +template +struct UniqueSelector +{ + typedef UniquePtr SingleObject; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr UnknownBound; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr KnownBound; +}; + +} // namespace detail + +// We don't have variadic template support everywhere, so just hard-code arities +// 0-4 for now. If you need more arguments, feel free to add the extra +// overloads. +// +// Beware! Due to lack of true nullptr support in gcc 4.4 and 4.5, passing +// literal nullptr to MakeUnique will not work on some platforms. See Move.h +// for more details. + +template +typename detail::UniqueSelector::SingleObject +MakeUnique() +{ + return UniquePtr(new T()); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1) +{ + return UniquePtr(new T(Forward(a1))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2) +{ + return UniquePtr(new T(Forward(a1), Forward(a2))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4), Forward(a5))); +} + +template +typename detail::UniqueSelector::UnknownBound +MakeUnique(decltype(sizeof(int)) n) +{ + typedef typename RemoveExtent::Type ArrayType; + return UniquePtr(new ArrayType[n]()); +} + +template +typename detail::UniqueSelector::KnownBound +MakeUnique() MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) MOZ_DELETE; + +} // namespace mozilla + +#endif /* mozilla_UniquePtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Vector.h new file mode 100644 index 0000000000..8540caf476 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/Vector.h @@ -0,0 +1,1280 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A type/length-parametrized vector class. */ + +#ifndef mozilla_Vector_h +#define mozilla_Vector_h + +#include "mozilla/Alignment.h" +#include "mozilla/AllocPolicy.h" +#include "mozilla/ArrayUtils.h" // for PointerRangeSize +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/MathAlgorithms.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/ReentrancyGuard.h" +#include "mozilla/TemplateLib.h" +#include "mozilla/TypeTraits.h" + +#include // for placement new + +/* Silence dire "bugs in previous versions of MSVC have been fixed" warnings */ +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4345) +#endif + +namespace mozilla { + +template +class VectorBase; + +namespace detail { + +/* + * Check that the given capacity wastes the minimal amount of space if + * allocated on the heap. This means that aCapacity*sizeof(T) is as close to a + * power-of-two as possible. growStorageBy() is responsible for ensuring this. + */ +template +static bool CapacityHasExcessSpace(size_t aCapacity) +{ + size_t size = aCapacity * sizeof(T); + return RoundUpPow2(size) - size >= sizeof(T); +} + +/* + * This template class provides a default implementation for vector operations + * when the element type is not known to be a POD, as judged by IsPod. + */ +template +struct VectorImpl +{ + /* Destroys constructed objects in the range [aBegin, aEnd). */ + static inline void destroy(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + p->~T(); + } + } + + /* Constructs objects in the uninitialized range [aBegin, aEnd). */ + static inline void initialize(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); + } + } + + /* + * Copy-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(*p); + } + } + + /* + * Move-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void moveConstruct(T* aDst, U* aSrcStart, U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(Move(*p)); + } + } + + /* + * Copy-constructs objects in the uninitialized range [aDst, aDst+aN) from + * the same object aU. + */ + template + static inline void copyConstructN(T* aDst, size_t aN, const U& aU) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + new(aDst) T(aU); + } + } + + /* + * Grows the given buffer to have capacity aNewCap, preserving the objects + * constructed in the range [begin, end) and updating aV. Assumes that (1) + * aNewCap has not overflowed, and (2) multiplying aNewCap by sizeof(T) will + * not overflow. + */ + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + T* newbuf = reinterpret_cast(aV.malloc_(aNewCap * sizeof(T))); + if (!newbuf) { + return false; + } + T* dst = newbuf; + T* src = aV.beginNoCheck(); + for (; src < aV.endNoCheck(); ++dst, ++src) { + new(dst) T(Move(*src)); + } + VectorImpl::destroy(aV.beginNoCheck(), aV.endNoCheck()); + aV.free_(aV.mBegin); + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } +}; + +/* + * This partial template specialization provides a default implementation for + * vector operations when the element type is known to be a POD, as judged by + * IsPod. + */ +template +struct VectorImpl +{ + static inline void destroy(T*, T*) {} + + static inline void initialize(T* aBegin, T* aEnd) + { + /* + * You would think that memset would be a big win (or even break even) + * when we know T is a POD. But currently it's not. This is probably + * because |append| tends to be given small ranges and memset requires + * a function call that doesn't get inlined. + * + * memset(aBegin, 0, sizeof(T) * (aEnd - aBegin)); + */ + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); + } + } + + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + /* + * See above memset comment. Also, notice that copyConstruct is + * currently templated (T != U), so memcpy won't work without + * requiring T == U. + * + * memcpy(aDst, aSrcStart, sizeof(T) * (aSrcEnd - aSrcStart)); + */ + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + *aDst = *p; + } + } + + template + static inline void moveConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + copyConstruct(aDst, aSrcStart, aSrcEnd); + } + + static inline void copyConstructN(T* aDst, size_t aN, const T& aT) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + *aDst = aT; + } + } + + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + size_t oldSize = sizeof(T) * aV.mCapacity; + size_t newSize = sizeof(T) * aNewCap; + T* newbuf = reinterpret_cast(aV.realloc_(aV.mBegin, oldSize, newSize)); + if (!newbuf) { + return false; + } + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } +}; + +} // namespace detail + +/* + * A CRTP base class for vector-like classes. Unless you really really want + * your own vector class -- and you almost certainly don't -- you should use + * mozilla::Vector instead! + * + * See mozilla::Vector for interface requirements. + */ +template +class VectorBase : private AllocPolicy +{ + /* utilities */ + + static const bool kElemIsPod = IsPod::value; + typedef detail::VectorImpl Impl; + friend struct detail::VectorImpl; + + bool growStorageBy(size_t aIncr); + bool convertToHeapStorage(size_t aNewCap); + + /* magic constants */ + + static const int kMaxInlineBytes = 1024; + + /* compute constants */ + + /* + * Consider element size to be 1 for buffer sizing if there are 0 inline + * elements. This allows us to compile when the definition of the element + * type is not visible here. + * + * Explicit specialization is only allowed at namespace scope, so in order + * to keep everything here, we use a dummy template parameter with partial + * specialization. + */ + template + struct ElemSize + { + static const size_t value = sizeof(T); + }; + template + struct ElemSize<0, Dummy> + { + static const size_t value = 1; + }; + + static const size_t kInlineCapacity = + tl::Min::value>::value; + + /* Calculate inline buffer size; avoid 0-sized array. */ + static const size_t kInlineBytes = + tl::Max<1, kInlineCapacity * ElemSize::value>::value; + + /* member data */ + + /* + * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, + * mBegin + mLength) hold valid constructed T objects. The range [mBegin + + * mLength, mBegin + mCapacity) holds uninitialized memory. The range + * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory + * previously allocated by a call to reserve(). + */ + T* mBegin; + + /* Number of elements in the vector. */ + size_t mLength; + + /* Max number of elements storable in the vector without resizing. */ + size_t mCapacity; + +#ifdef DEBUG + /* Max elements of reserved or used space in this vector. */ + size_t mReserved; +#endif + + /* Memory used for inline storage. */ + AlignedStorage mStorage; + +#ifdef DEBUG + friend class ReentrancyGuard; + bool mEntered; +#endif + + /* private accessors */ + + bool usingInlineStorage() const + { + return mBegin == const_cast(this)->inlineStorage(); + } + + T* inlineStorage() + { + return static_cast(mStorage.addr()); + } + + T* beginNoCheck() const + { + return mBegin; + } + + T* endNoCheck() + { + return mBegin + mLength; + } + + const T* endNoCheck() const + { + return mBegin + mLength; + } + +#ifdef DEBUG + size_t reserved() const + { + MOZ_ASSERT(mReserved <= mCapacity); + MOZ_ASSERT(mLength <= mReserved); + return mReserved; + } +#endif + + /* Append operations guaranteed to succeed due to pre-reserved space. */ + template void internalAppend(U&& aU); + template + void internalAppendAll(const VectorBase& aU); + void internalAppendN(const T& aT, size_t aN); + template void internalAppend(const U* aBegin, size_t aLength); + +public: + static const size_t sMaxInlineStorage = N; + + typedef T ElementType; + + explicit VectorBase(AllocPolicy = AllocPolicy()); + explicit VectorBase(ThisVector&&); /* Move constructor. */ + ThisVector& operator=(ThisVector&&); /* Move assignment. */ + ~VectorBase(); + + /* accessors */ + + const AllocPolicy& allocPolicy() const { return *this; } + + AllocPolicy& allocPolicy() { return *this; } + + enum { InlineLength = N }; + + size_t length() const { return mLength; } + + bool empty() const { return mLength == 0; } + + size_t capacity() const { return mCapacity; } + + T* begin() + { + MOZ_ASSERT(!mEntered); + return mBegin; + } + + const T* begin() const + { + MOZ_ASSERT(!mEntered); + return mBegin; + } + + T* end() + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } + + const T* end() const + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } + + T& operator[](size_t aIndex) + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } + + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } + + T& back() + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } + + const T& back() const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } + + class Range + { + friend class VectorBase; + T* mCur; + T* mEnd; + Range(T* aCur, T* aEnd) + : mCur(aCur) + , mEnd(aEnd) + { + MOZ_ASSERT(aCur <= aEnd); + } + + public: + Range() {} + bool empty() const { return mCur == mEnd; } + size_t remain() const { return PointerRangeSize(mCur, mEnd); } + T& front() const { MOZ_ASSERT(!empty()); return *mCur; } + void popFront() { MOZ_ASSERT(!empty()); ++mCur; } + T popCopyFront() { MOZ_ASSERT(!empty()); return *mCur++; } + }; + + Range all() { return Range(begin(), end()); } + + /* mutators */ + + /** + * Given that the vector is empty and has no inline storage, grow to + * |capacity|. + */ + bool initCapacity(size_t aRequest); + + /** + * If reserve(length() + N) succeeds, the N next appends are guaranteed to + * succeed. + */ + bool reserve(size_t aRequest); + + /** + * Destroy elements in the range [end() - aIncr, end()). Does not deallocate + * or unreserve storage for those elements. + */ + void shrinkBy(size_t aIncr); + + /** Grow the vector by aIncr elements. */ + bool growBy(size_t aIncr); + + /** Call shrinkBy or growBy based on whether newSize > length(). */ + bool resize(size_t aNewLength); + + /** + * Increase the length of the vector, but don't initialize the new elements + * -- leave them as uninitialized memory. + */ + bool growByUninitialized(size_t aIncr); + bool resizeUninitialized(size_t aNewLength); + + /** Shorthand for shrinkBy(length()). */ + void clear(); + + /** Clears and releases any heap-allocated storage. */ + void clearAndFree(); + + /** + * If true, appending |aNeeded| elements won't reallocate elements storage. + * This *doesn't* mean that infallibleAppend may be used! You still must + * reserve the extra space, even if this method indicates that appends won't + * need to reallocate elements storage. + */ + bool canAppendWithoutRealloc(size_t aNeeded) const; + + /** Potentially fallible append operations. */ + + /** + * This can take either a T& or a T&&. Given a T&&, it moves |aU| into the + * vector, instead of copying it. If it fails, |aU| is left unmoved. ("We are + * not amused.") + */ + template bool append(U&& aU); + + template + bool appendAll(const VectorBase& aU); + bool appendN(const T& aT, size_t aN); + template bool append(const U* aBegin, const U* aEnd); + template bool append(const U* aBegin, size_t aLength); + + /* + * Guaranteed-infallible append operations for use upon vectors whose + * memory has been pre-reserved. Don't use this if you haven't reserved the + * memory! + */ + template void infallibleAppend(U&& aU) + { + internalAppend(Forward(aU)); + } + void infallibleAppendN(const T& aT, size_t aN) + { + internalAppendN(aT, aN); + } + template void infallibleAppend(const U* aBegin, const U* aEnd) + { + internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); + } + template void infallibleAppend(const U* aBegin, size_t aLength) + { + internalAppend(aBegin, aLength); + } + + void popBack(); + + T popCopy(); + + /** + * Transfers ownership of the internal buffer used by this vector to the + * caller. (It's the caller's responsibility to properly deallocate this + * buffer, in accordance with this vector's AllocPolicy.) After this call, + * the vector is empty. Since the returned buffer may need to be allocated + * (if the elements are currently stored in-place), the call can fail, + * returning nullptr. + * + * N.B. Although a T*, only the range [0, length()) is constructed. + */ + T* extractRawBuffer(); + + /** + * Transfer ownership of an array of objects into the vector. The caller + * must have allocated the array in accordance with this vector's + * AllocPolicy. + * + * N.B. This call assumes that there are no uninitialized elements in the + * passed array. + */ + void replaceRawBuffer(T* aP, size_t aLength); + + /** + * Places |aVal| at position |aP|, shifting existing elements from |aP| onward + * one position higher. On success, |aP| should not be reused because it'll + * be a dangling pointer if reallocation of the vector storage occurred; the + * return value should be used instead. On failure, nullptr is returned. + * + * Example usage: + * + * if (!(p = vec.insert(p, val))) { + * + * } + * + * + * This is inherently a linear-time operation. Be careful! + */ + template + T* insert(T* aP, U&& aVal); + + /** + * Removes the element |aT|, which must fall in the bounds [begin, end), + * shifting existing elements from |aT + 1| onward one position lower. + */ + void erase(T* aT); + + /** + * Removes the elements [|aBegin|, |aEnd|), which must fall in the bounds + * [begin, end), shifting existing elements from |aEnd + 1| onward to aBegin's + * old position. + */ + void erase(T* aBegin, T* aEnd); + + /** + * Measure the size of the vector's heap-allocated storage. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const; + + /** + * Like sizeOfExcludingThis, but also measures the size of the vector + * object (which must be heap-allocated) itself. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; + + void swap(ThisVector& aOther); + +private: + VectorBase(const VectorBase&) MOZ_DELETE; + void operator=(const VectorBase&) MOZ_DELETE; + + /* Move-construct/assign only from our derived class, ThisVector. */ + VectorBase(VectorBase&&) MOZ_DELETE; + void operator=(VectorBase&&) MOZ_DELETE; +}; + +/* This does the re-entrancy check plus several other sanity checks. */ +#define MOZ_REENTRANCY_GUARD_ET_AL \ + ReentrancyGuard g(*this); \ + MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == kInlineCapacity); \ + MOZ_ASSERT(reserved() <= mCapacity); \ + MOZ_ASSERT(mLength <= reserved()); \ + MOZ_ASSERT(mLength <= mCapacity) + +/* Vector Implementation */ + +template +MOZ_ALWAYS_INLINE +VectorBase::VectorBase(AP aAP) + : AP(aAP) + , mLength(0) + , mCapacity(kInlineCapacity) +#ifdef DEBUG + , mReserved(kInlineCapacity) + , mEntered(false) +#endif +{ + mBegin = static_cast(mStorage.addr()); +} + +/* Move constructor. */ +template +MOZ_ALWAYS_INLINE +VectorBase::VectorBase(TV&& aRhs) + : AllocPolicy(Move(aRhs)) +#ifdef DEBUG + , mEntered(false) +#endif +{ + mLength = aRhs.mLength; + mCapacity = aRhs.mCapacity; +#ifdef DEBUG + mReserved = aRhs.mReserved; +#endif + + if (aRhs.usingInlineStorage()) { + /* We can't move the buffer over in this case, so copy elements. */ + mBegin = static_cast(mStorage.addr()); + Impl::moveConstruct(mBegin, aRhs.beginNoCheck(), aRhs.endNoCheck()); + /* + * Leave aRhs's mLength, mBegin, mCapacity, and mReserved as they are. + * The elements in its in-line storage still need to be destroyed. + */ + } else { + /* + * Take src's buffer, and turn src into an empty vector using + * in-line storage. + */ + mBegin = aRhs.mBegin; + aRhs.mBegin = static_cast(aRhs.mStorage.addr()); + aRhs.mCapacity = kInlineCapacity; + aRhs.mLength = 0; +#ifdef DEBUG + aRhs.mReserved = kInlineCapacity; +#endif + } +} + +/* Move assignment. */ +template +MOZ_ALWAYS_INLINE TV& +VectorBase::operator=(TV&& aRhs) +{ + MOZ_ASSERT(this != &aRhs, "self-move assignment is prohibited"); + TV* tv = static_cast(this); + tv->~TV(); + new(tv) TV(Move(aRhs)); + return *tv; +} + +template +MOZ_ALWAYS_INLINE +VectorBase::~VectorBase() +{ + MOZ_REENTRANCY_GUARD_ET_AL; + Impl::destroy(beginNoCheck(), endNoCheck()); + if (!usingInlineStorage()) { + this->free_(beginNoCheck()); + } +} + +/* + * This function will create a new heap buffer with capacity aNewCap, + * move all elements in the inline buffer to this new buffer, + * and fail on OOM. + */ +template +inline bool +VectorBase::convertToHeapStorage(size_t aNewCap) +{ + MOZ_ASSERT(usingInlineStorage()); + + /* Allocate buffer. */ + MOZ_ASSERT(!detail::CapacityHasExcessSpace(aNewCap)); + T* newBuf = reinterpret_cast(this->malloc_(aNewCap * sizeof(T))); + if (!newBuf) { + return false; + } + + /* Copy inline elements into heap buffer. */ + Impl::moveConstruct(newBuf, beginNoCheck(), endNoCheck()); + Impl::destroy(beginNoCheck(), endNoCheck()); + + /* Switch in heap buffer. */ + mBegin = newBuf; + /* mLength is unchanged. */ + mCapacity = aNewCap; + return true; +} + +template +MOZ_NEVER_INLINE bool +VectorBase::growStorageBy(size_t aIncr) +{ + MOZ_ASSERT(mLength + aIncr > mCapacity); + MOZ_ASSERT_IF(!usingInlineStorage(), + !detail::CapacityHasExcessSpace(mCapacity)); + + /* + * When choosing a new capacity, its size should is as close to 2**N bytes + * as possible. 2**N-sized requests are best because they are unlikely to + * be rounded up by the allocator. Asking for a 2**N number of elements + * isn't as good, because if sizeof(T) is not a power-of-two that would + * result in a non-2**N request size. + */ + + size_t newCap; + + if (aIncr == 1) { + if (usingInlineStorage()) { + /* This case occurs in ~70--80% of the calls to this function. */ + size_t newSize = + tl::RoundUpPow2<(kInlineCapacity + 1) * sizeof(T)>::value; + newCap = newSize / sizeof(T); + goto convert; + } + + if (mLength == 0) { + /* This case occurs in ~0--10% of the calls to this function. */ + newCap = 1; + goto grow; + } + + /* This case occurs in ~15--20% of the calls to this function. */ + + /* + * Will mLength * 4 *sizeof(T) overflow? This condition limits a vector + * to 1GB of memory on a 32-bit system, which is a reasonable limit. It + * also ensures that + * + * static_cast(end()) - static_cast(begin()) + * + * doesn't overflow ptrdiff_t (see bug 510319). + */ + if (mLength & tl::MulOverflowMask<4 * sizeof(T)>::value) { + this->reportAllocOverflow(); + return false; + } + + /* + * If we reach here, the existing capacity will have a size that is already + * as close to 2^N as sizeof(T) will allow. Just double the capacity, and + * then there might be space for one more element. + */ + newCap = mLength * 2; + if (detail::CapacityHasExcessSpace(newCap)) { + newCap += 1; + } + } else { + /* This case occurs in ~2% of the calls to this function. */ + size_t newMinCap = mLength + aIncr; + + /* Did mLength + aIncr overflow? Will newCap * sizeof(T) overflow? */ + if (newMinCap < mLength || + newMinCap & tl::MulOverflowMask<2 * sizeof(T)>::value) + { + this->reportAllocOverflow(); + return false; + } + + size_t newMinSize = newMinCap * sizeof(T); + size_t newSize = RoundUpPow2(newMinSize); + newCap = newSize / sizeof(T); + } + + if (usingInlineStorage()) { +convert: + return convertToHeapStorage(newCap); + } + +grow: + return Impl::growTo(*this, newCap); +} + +template +inline bool +VectorBase::initCapacity(size_t aRequest) +{ + MOZ_ASSERT(empty()); + MOZ_ASSERT(usingInlineStorage()); + if (aRequest == 0) { + return true; + } + T* newbuf = reinterpret_cast(this->malloc_(aRequest * sizeof(T))); + if (!newbuf) { + return false; + } + mBegin = newbuf; + mCapacity = aRequest; +#ifdef DEBUG + mReserved = aRequest; +#endif + return true; +} + +template +inline bool +VectorBase::reserve(size_t aRequest) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (aRequest > mCapacity && !growStorageBy(aRequest - mLength)) { + return false; + } +#ifdef DEBUG + if (aRequest > mReserved) { + mReserved = aRequest; + } + MOZ_ASSERT(mLength <= mReserved); + MOZ_ASSERT(mReserved <= mCapacity); +#endif + return true; +} + +template +inline void +VectorBase::shrinkBy(size_t aIncr) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + MOZ_ASSERT(aIncr <= mLength); + Impl::destroy(endNoCheck() - aIncr, endNoCheck()); + mLength -= aIncr; +} + +template +MOZ_ALWAYS_INLINE bool +VectorBase::growBy(size_t aIncr) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { + return false; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + T* newend = endNoCheck() + aIncr; + Impl::initialize(endNoCheck(), newend); + mLength += aIncr; +#ifdef DEBUG + if (mLength > mReserved) { + mReserved = mLength; + } +#endif + return true; +} + +template +MOZ_ALWAYS_INLINE bool +VectorBase::growByUninitialized(size_t aIncr) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { + return false; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + mLength += aIncr; +#ifdef DEBUG + if (mLength > mReserved) { + mReserved = mLength; + } +#endif + return true; +} + +template +inline bool +VectorBase::resize(size_t aNewLength) +{ + size_t curLength = mLength; + if (aNewLength > curLength) { + return growBy(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); + return true; +} + +template +MOZ_ALWAYS_INLINE bool +VectorBase::resizeUninitialized(size_t aNewLength) +{ + size_t curLength = mLength; + if (aNewLength > curLength) { + return growByUninitialized(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); + return true; +} + +template +inline void +VectorBase::clear() +{ + MOZ_REENTRANCY_GUARD_ET_AL; + Impl::destroy(beginNoCheck(), endNoCheck()); + mLength = 0; +} + +template +inline void +VectorBase::clearAndFree() +{ + clear(); + + if (usingInlineStorage()) { + return; + } + this->free_(beginNoCheck()); + mBegin = static_cast(mStorage.addr()); + mCapacity = kInlineCapacity; +#ifdef DEBUG + mReserved = kInlineCapacity; +#endif +} + +template +inline bool +VectorBase::canAppendWithoutRealloc(size_t aNeeded) const +{ + return mLength + aNeeded <= mCapacity; +} + +template +template +MOZ_ALWAYS_INLINE void +VectorBase::internalAppendAll( + const VectorBase& aOther) +{ + internalAppend(aOther.begin(), aOther.length()); +} + +template +template +MOZ_ALWAYS_INLINE void +VectorBase::internalAppend(U&& aU) +{ + MOZ_ASSERT(mLength + 1 <= mReserved); + MOZ_ASSERT(mReserved <= mCapacity); + new(endNoCheck()) T(Forward(aU)); + ++mLength; +} + +template +MOZ_ALWAYS_INLINE bool +VectorBase::appendN(const T& aT, size_t aNeeded) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { + return false; + } +#ifdef DEBUG + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } +#endif + internalAppendN(aT, aNeeded); + return true; +} + +template +MOZ_ALWAYS_INLINE void +VectorBase::internalAppendN(const T& aT, size_t aNeeded) +{ + MOZ_ASSERT(mLength + aNeeded <= mReserved); + MOZ_ASSERT(mReserved <= mCapacity); + Impl::copyConstructN(endNoCheck(), aNeeded, aT); + mLength += aNeeded; +} + +template +template +inline T* +VectorBase::insert(T* aP, U&& aVal) +{ + MOZ_ASSERT(begin() <= aP); + MOZ_ASSERT(aP <= end()); + size_t pos = aP - begin(); + MOZ_ASSERT(pos <= mLength); + size_t oldLength = mLength; + if (pos == oldLength) { + if (!append(Forward(aVal))) { + return nullptr; + } + } else { + T oldBack = Move(back()); + if (!append(Move(oldBack))) { /* Dup the last element. */ + return nullptr; + } + for (size_t i = oldLength; i > pos; --i) { + (*this)[i] = Move((*this)[i - 1]); + } + (*this)[pos] = Forward(aVal); + } + return begin() + pos; +} + +template +inline void +VectorBase::erase(T* aIt) +{ + MOZ_ASSERT(begin() <= aIt); + MOZ_ASSERT(aIt < end()); + while (aIt + 1 < end()) { + *aIt = Move(*(aIt + 1)); + ++aIt; + } + popBack(); +} + +template +inline void +VectorBase::erase(T* aBegin, T* aEnd) +{ + MOZ_ASSERT(begin() <= aBegin); + MOZ_ASSERT(aBegin <= aEnd); + MOZ_ASSERT(aEnd <= end()); + while (aEnd < end()) { + *aBegin++ = Move(*aEnd++); + } + shrinkBy(aEnd - aBegin); +} + +template +template +MOZ_ALWAYS_INLINE bool +VectorBase::append(const U* aInsBegin, const U* aInsEnd) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + size_t aNeeded = PointerRangeSize(aInsBegin, aInsEnd); + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { + return false; + } +#ifdef DEBUG + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } +#endif + internalAppend(aInsBegin, aNeeded); + return true; +} + +template +template +MOZ_ALWAYS_INLINE void +VectorBase::internalAppend(const U* aInsBegin, size_t aInsLength) +{ + MOZ_ASSERT(mLength + aInsLength <= mReserved); + MOZ_ASSERT(mReserved <= mCapacity); + Impl::copyConstruct(endNoCheck(), aInsBegin, aInsBegin + aInsLength); + mLength += aInsLength; +} + +template +template +MOZ_ALWAYS_INLINE bool +VectorBase::append(U&& aU) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (mLength == mCapacity && !growStorageBy(1)) { + return false; + } +#ifdef DEBUG + if (mLength + 1 > mReserved) { + mReserved = mLength + 1; + } +#endif + internalAppend(Forward(aU)); + return true; +} + +template +template +MOZ_ALWAYS_INLINE bool +VectorBase::appendAll(const VectorBase& aOther) +{ + return append(aOther.begin(), aOther.length()); +} + +template +template +MOZ_ALWAYS_INLINE bool +VectorBase::append(const U* aInsBegin, size_t aInsLength) +{ + return append(aInsBegin, aInsBegin + aInsLength); +} + +template +MOZ_ALWAYS_INLINE void +VectorBase::popBack() +{ + MOZ_REENTRANCY_GUARD_ET_AL; + MOZ_ASSERT(!empty()); + --mLength; + endNoCheck()->~T(); +} + +template +MOZ_ALWAYS_INLINE T +VectorBase::popCopy() +{ + T ret = back(); + popBack(); + return ret; +} + +template +inline T* +VectorBase::extractRawBuffer() +{ + T* ret; + if (usingInlineStorage()) { + ret = reinterpret_cast(this->malloc_(mLength * sizeof(T))); + if (!ret) { + return nullptr; + } + Impl::copyConstruct(ret, beginNoCheck(), endNoCheck()); + Impl::destroy(beginNoCheck(), endNoCheck()); + /* mBegin, mCapacity are unchanged. */ + mLength = 0; + } else { + ret = mBegin; + mBegin = static_cast(mStorage.addr()); + mLength = 0; + mCapacity = kInlineCapacity; +#ifdef DEBUG + mReserved = kInlineCapacity; +#endif + } + return ret; +} + +template +inline void +VectorBase::replaceRawBuffer(T* aP, size_t aLength) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + + /* Destroy what we have. */ + Impl::destroy(beginNoCheck(), endNoCheck()); + if (!usingInlineStorage()) { + this->free_(beginNoCheck()); + } + + /* Take in the new buffer. */ + if (aLength <= kInlineCapacity) { + /* + * We convert to inline storage if possible, even though aP might + * otherwise be acceptable. Maybe this behaviour should be + * specifiable with an argument to this function. + */ + mBegin = static_cast(mStorage.addr()); + mLength = aLength; + mCapacity = kInlineCapacity; + Impl::moveConstruct(mBegin, aP, aP + aLength); + Impl::destroy(aP, aP + aLength); + this->free_(aP); + } else { + mBegin = aP; + mLength = aLength; + mCapacity = aLength; + } +#ifdef DEBUG + mReserved = aLength; +#endif +} + +template +inline size_t +VectorBase::sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const +{ + return usingInlineStorage() ? 0 : aMallocSizeOf(beginNoCheck()); +} + +template +inline size_t +VectorBase::sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const +{ + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); +} + +template +inline void +VectorBase::swap(TV& aOther) +{ + static_assert(N == 0, + "still need to implement this for N != 0"); + + // This only works when inline storage is always empty. + if (!usingInlineStorage() && aOther.usingInlineStorage()) { + aOther.mBegin = mBegin; + mBegin = inlineStorage(); + } else if (usingInlineStorage() && !aOther.usingInlineStorage()) { + mBegin = aOther.mBegin; + aOther.mBegin = aOther.inlineStorage(); + } else if (!usingInlineStorage() && !aOther.usingInlineStorage()) { + Swap(mBegin, aOther.mBegin); + } else { + // This case is a no-op, since we'd set both to use their inline storage. + } + + Swap(mLength, aOther.mLength); + Swap(mCapacity, aOther.mCapacity); +#ifdef DEBUG + Swap(mReserved, aOther.mReserved); +#endif +} + +/* + * STL-like container providing a short-lived, dynamic buffer. Vector calls the + * constructors/destructors of all elements stored in its internal buffer, so + * non-PODs may be safely used. Additionally, Vector will store the first N + * elements in-place before resorting to dynamic allocation. + * + * T requirements: + * - default and copy constructible, assignable, destructible + * - operations do not throw + * N requirements: + * - any value, however, N is clamped to min/max values + * AllocPolicy: + * - see "Allocation policies" in AllocPolicy.h (defaults to + * mozilla::MallocAllocPolicy) + * + * Vector is not reentrant: T member functions called during Vector member + * functions must not call back into the same object! + */ +template +class Vector + : public VectorBase > +{ + typedef VectorBase Base; + +public: + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + Vector(Vector&& vec) : Base(Move(vec)) {} + Vector& operator=(Vector&& aOther) + { + return Base::operator=(Move(aOther)); + } +}; + +} // namespace mozilla + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#endif /* mozilla_Vector_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/WeakPtr.h b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/WeakPtr.h new file mode 100644 index 0000000000..07f00bc295 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/winrt_8.1/mozilla/WeakPtr.h @@ -0,0 +1,202 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Weak pointer functionality, implemented as a mixin for use with any class. */ + +/** + * SupportsWeakPtr lets you have a pointer to an object 'Foo' without affecting + * its lifetime. It works by creating a single shared reference counted object + * (WeakReference) that each WeakPtr will access 'Foo' through. This lets 'Foo' + * clear the pointer in the WeakReference without having to know about all of + * the WeakPtrs to it and allows the WeakReference to live beyond the lifetime + * of 'Foo'. + * + * PLEASE NOTE: This weak pointer implementation is not thread-safe. + * + * Note that when deriving from SupportsWeakPtr you should add + * MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public section of your + * class, where ClassName is the name of your class. + * + * The overhead of WeakPtr is that accesses to 'Foo' becomes an additional + * dereference, and an additional heap allocated pointer sized object shared + * between all of the WeakPtrs. + * + * Example of usage: + * + * // To have a class C support weak pointers, inherit from + * // SupportsWeakPtr. + * class C : public SupportsWeakPtr + * { + * public: + * MOZ_DECLARE_REFCOUNTED_TYPENAME(C) + * int mNum; + * void act(); + * }; + * + * C* ptr = new C(); + * + * // Get weak pointers to ptr. The first time asWeakPtr is called + * // a reference counted WeakReference object is created that + * // can live beyond the lifetime of 'ptr'. The WeakReference + * // object will be notified of 'ptr's destruction. + * WeakPtr weak = ptr->asWeakPtr(); + * WeakPtr other = ptr->asWeakPtr(); + * + * // Test a weak pointer for validity before using it. + * if (weak) { + * weak->mNum = 17; + * weak->act(); + * } + * + * // Destroying the underlying object clears weak pointers to it. + * delete ptr; + * + * MOZ_ASSERT(!weak, "Deleting |ptr| clears weak pointers to it."); + * MOZ_ASSERT(!other, "Deleting |ptr| clears all weak pointers to it."); + * + * WeakPtr is typesafe and may be used with any class. It is not required that + * the class be reference-counted or allocated in any particular way. + * + * The API was loosely inspired by Chromium's weak_ptr.h: + * http://src.chromium.org/svn/trunk/src/base/memory/weak_ptr.h + */ + +#ifndef mozilla_WeakPtr_h +#define mozilla_WeakPtr_h + +#include "mozilla/ArrayUtils.h" +#include "mozilla/Assertions.h" +#include "mozilla/NullPtr.h" +#include "mozilla/RefPtr.h" +#include "mozilla/TypeTraits.h" + +#include + +namespace mozilla { + +template class WeakPtrBase; +template class SupportsWeakPtrBase; + +namespace detail { + +// This can live beyond the lifetime of the class derived from +// SupportsWeakPtrBase. +template +class WeakReference : public ::mozilla::RefCounted > +{ +public: + explicit WeakReference(T* p) : mPtr(p) {} + + T* get() const { return mPtr; } + +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#ifdef XP_WIN +#define snprintf _snprintf +#endif + const char* typeName() const + { + static char nameBuffer[1024]; + const char* innerType = mPtr->typeName(); + // We could do fancier length checks at runtime, but innerType is + // controlled by us so we can ensure that this never causes a buffer + // overflow by this assertion. + MOZ_ASSERT(strlen(innerType) + sizeof("WeakReference<>") < + ArrayLength(nameBuffer), + "Exceedingly large type name"); + snprintf(nameBuffer, ArrayLength(nameBuffer), "WeakReference<%s>", + innerType); + // This is usually not OK, but here we are returning a pointer to a static + // buffer which will immediately be used by the caller. + return nameBuffer; + } + + size_t typeSize() const { return sizeof(*this); } +#undef snprintf +#endif + +private: + friend class WeakPtrBase >; + friend class SupportsWeakPtrBase >; + + void detach() { mPtr = nullptr; } + + T* mPtr; +}; + +} // namespace detail + +template +class SupportsWeakPtrBase +{ +public: + WeakPtrBase asWeakPtr() + { + if (!weakRef) { + weakRef = new WeakReference(static_cast(this)); + } + return WeakPtrBase(weakRef); + } + +protected: + ~SupportsWeakPtrBase() + { + static_assert(IsBaseOf, T>::value, + "T must derive from SupportsWeakPtrBase"); + if (weakRef) { + weakRef->detach(); + } + } + +private: + friend class WeakPtrBase; + + RefPtr weakRef; +}; + +template +class SupportsWeakPtr : public SupportsWeakPtrBase > +{ +}; + +template +class WeakPtrBase +{ +public: + WeakPtrBase(const WeakPtrBase& aOther) + : mRef(aOther.mRef) + {} + + // Ensure that mRef is dereferenceable in the uninitialized state. + WeakPtrBase() : mRef(new WeakReference(nullptr)) {} + + operator T*() const { return mRef->get(); } + T& operator*() const { return *mRef->get(); } + + T* operator->() const { return mRef->get(); } + + T* get() const { return mRef->get(); } + +private: + friend class SupportsWeakPtrBase; + + explicit WeakPtrBase(const RefPtr &aOther) : mRef(aOther) {} + + RefPtr mRef; +}; + +template +class WeakPtr : public WeakPtrBase > +{ + typedef WeakPtrBase > Base; +public: + WeakPtr(const WeakPtr& aOther) : Base(aOther) {} + MOZ_IMPLICIT WeakPtr(const Base& aOther) : Base(aOther) {} + WeakPtr() {} +}; + +} // namespace mozilla + +#endif /* mozilla_WeakPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js-config.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js-config.h new file mode 100644 index 0000000000..774d938667 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js-config.h @@ -0,0 +1,53 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sw=4 et tw=78: + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_config_h +#define js_config_h + +/* Definitions set at build time that affect SpiderMonkey's public API. + This header file is generated by the SpiderMonkey configure script, + and installed along with jsapi.h. */ + +/* Define to 1 if SpiderMonkey is in debug mode. */ +/* #undef JS_DEBUG */ + +/* Define to 1 if SpiderMonkey should not use struct types in debug builds. */ +/* #undef JS_NO_JSVAL_JSID_STRUCT_TYPES */ + +/* Define to 1 if SpiderMonkey should support multi-threaded clients. */ +/* #undef JS_THREADSAFE */ + +/* Define to 1 if SpiderMonkey should include ctypes support. */ +#define JS_HAS_CTYPES 1 + +/* Define to 1 if SpiderMonkey should support the ability to perform + entirely too much GC. */ +#define JS_GC_ZEAL 1 + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +/* #undef JS_HAVE_ENDIAN_H */ + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +/* #undef JS_HAVE_MACHINE_ENDIAN_H */ + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +/* #undef JS_HAVE_SYS_ISA_DEFS_H */ + +/* Define to 1 if SpiderMonkey is in NUNBOX32 mode. */ +#define JS_NUNBOX32 1 + +/* Define to 1 if SpiderMonkey is in PUNBOX64 mode. */ +/* #undef JS_PUNBOX64 */ + +/* MOZILLA JSAPI version number components */ +#define MOZJS_MAJOR_VERSION 33 +#define MOZJS_MINOR_VERSION 1 + +#endif /* js_config_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js.msg b/frameworks/js-bindings/external/spidermonkey/include/wp8/js.msg new file mode 100644 index 0000000000..d342ad4506 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js.msg @@ -0,0 +1,443 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * This is the JavaScript error message file. + * + * The format for each JS error message is: + * + * MSG_DEF(, , , , + * ) + * + * where ; + * is a legal C identifer that will be used in the + * JS engine source. + * + * is an unique integral value identifying this error. + * + * is an integer literal specifying the total number of + * replaceable arguments in the following format string. + * + * is an exception index from the enum in jsexn.c; + * JSEXN_NONE for none. The given exception index will be raised by the + * engine when the corresponding error occurs. + * + * is a string literal, optionally containing sequences + * {X} where X is an integer representing the argument number that will + * be replaced with a string value when the error is reported. + * + * e.g. + * + * MSG_DEF(JSMSG_NOT_A_SUBSPECIES, 73, JSEXN_NONE, 2, + * "{0} is not a member of the {1} family") + * + * can be used: + * + * JS_ReportErrorNumber(JSMSG_NOT_A_SUBSPECIES, "Rhino", "Monkey"); + * + * to report: + * + * "Rhino is not a member of the Monkey family" + * + * When removing MSG_DEFs, convert them to JSMSG_UNUSED placeholders: + * + * MSG_DEF(JSMSG_UNUSED7, 7, 0, JSEXN_NONE, "") + * + * Before adding a new MSG_DEF at the end, look for existing JSMSG_UNUSED + * free index placeholders in the middle of the list. + */ + +MSG_DEF(JSMSG_NOT_AN_ERROR, 0, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_NOT_DEFINED, 1, 1, JSEXN_REFERENCEERR, "{0} is not defined") +MSG_DEF(JSMSG_INACTIVE, 2, 0, JSEXN_INTERNALERR, "nothing active on context") +MSG_DEF(JSMSG_MORE_ARGS_NEEDED, 3, 3, JSEXN_TYPEERR, "{0} requires more than {1} argument{2}") +MSG_DEF(JSMSG_BAD_CHAR, 4, 1, JSEXN_INTERNALERR, "invalid format character {0}") +MSG_DEF(JSMSG_BAD_TYPE, 5, 1, JSEXN_TYPEERR, "unknown type {0}") +MSG_DEF(JSMSG_ALLOC_OVERFLOW, 6, 0, JSEXN_INTERNALERR, "allocation size overflow") +MSG_DEF(JSMSG_MISSING_HEXDIGITS, 7, 0, JSEXN_SYNTAXERR, "missing hexadecimal digits after '0x'") +MSG_DEF(JSMSG_INCOMPATIBLE_PROTO, 8, 3, JSEXN_TYPEERR, "{0}.prototype.{1} called on incompatible {2}") +MSG_DEF(JSMSG_NO_CONSTRUCTOR, 9, 1, JSEXN_TYPEERR, "{0} has no constructor") +MSG_DEF(JSMSG_CANT_ALIAS, 10, 3, JSEXN_TYPEERR, "can't alias {0} to {1} in class {2}") +MSG_DEF(JSMSG_NOT_SCRIPTED_FUNCTION, 11, 1, JSEXN_TYPEERR, "{0} is not a scripted function") +MSG_DEF(JSMSG_BAD_SORT_ARG, 12, 0, JSEXN_TYPEERR, "invalid Array.prototype.sort argument") +MSG_DEF(JSMSG_BAD_ATOMIC_NUMBER, 13, 1, JSEXN_INTERNALERR, "internal error: no index for atom {0}") +MSG_DEF(JSMSG_TOO_MANY_LITERALS, 14, 0, JSEXN_INTERNALERR, "too many literals") +MSG_DEF(JSMSG_CANT_WATCH, 15, 1, JSEXN_TYPEERR, "can't watch non-native objects of class {0}") +MSG_DEF(JSMSG_STACK_UNDERFLOW, 16, 2, JSEXN_INTERNALERR, "internal error compiling {0}: stack underflow at pc {1}") +MSG_DEF(JSMSG_NEED_DIET, 17, 1, JSEXN_INTERNALERR, "{0} too large") +MSG_DEF(JSMSG_TOO_MANY_LOCAL_ROOTS, 18, 0, JSEXN_ERR, "out of local root space") +MSG_DEF(JSMSG_READ_ONLY, 19, 1, JSEXN_TYPEERR, "{0} is read-only") +MSG_DEF(JSMSG_BAD_FORMAL, 20, 0, JSEXN_SYNTAXERR, "malformed formal parameter") +MSG_DEF(JSMSG_CANT_DELETE, 21, 1, JSEXN_TYPEERR, "property {0} is non-configurable and can't be deleted") +MSG_DEF(JSMSG_NOT_FUNCTION, 22, 1, JSEXN_TYPEERR, "{0} is not a function") +MSG_DEF(JSMSG_NOT_CONSTRUCTOR, 23, 1, JSEXN_TYPEERR, "{0} is not a constructor") +MSG_DEF(JSMSG_INVALID_DATE, 24, 0, JSEXN_RANGEERR, "invalid date") +MSG_DEF(JSMSG_TOO_DEEP, 25, 1, JSEXN_INTERNALERR, "{0} nested too deeply") +MSG_DEF(JSMSG_OVER_RECURSED, 26, 0, JSEXN_INTERNALERR, "too much recursion") +MSG_DEF(JSMSG_IN_NOT_OBJECT, 27, 1, JSEXN_TYPEERR, "invalid 'in' operand {0}") +MSG_DEF(JSMSG_BAD_NEW_RESULT, 28, 1, JSEXN_TYPEERR, "invalid new expression result {0}") +MSG_DEF(JSMSG_OBJECT_ACCESS_DENIED, 29, 0, JSEXN_ERR, "Permission denied to access object") +MSG_DEF(JSMSG_PROPERTY_ACCESS_DENIED, 30, 1, JSEXN_ERR, "Permission denied to access property '{0}'") +MSG_DEF(JSMSG_BAD_INSTANCEOF_RHS, 31, 1, JSEXN_TYPEERR, "invalid 'instanceof' operand {0}") +MSG_DEF(JSMSG_BAD_BYTECODE, 32, 1, JSEXN_INTERNALERR, "unimplemented JavaScript bytecode {0}") +MSG_DEF(JSMSG_BAD_RADIX, 33, 0, JSEXN_RANGEERR, "radix must be an integer at least 2 and no greater than 36") +MSG_DEF(JSMSG_PAREN_BEFORE_LET, 34, 0, JSEXN_SYNTAXERR, "missing ( before let head") +MSG_DEF(JSMSG_CANT_CONVERT, 35, 1, JSEXN_ERR, "can't convert {0} to an integer") +MSG_DEF(JSMSG_CYCLIC_VALUE, 36, 1, JSEXN_TYPEERR, "cyclic {0} value") +MSG_DEF(JSMSG_COMPILE_EXECED_SCRIPT, 37, 0, JSEXN_TYPEERR, "can't compile over a script that is currently executing") +MSG_DEF(JSMSG_CANT_CONVERT_TO, 38, 2, JSEXN_TYPEERR, "can't convert {0} to {1}") +MSG_DEF(JSMSG_NO_PROPERTIES, 39, 1, JSEXN_TYPEERR, "{0} has no properties") +MSG_DEF(JSMSG_CANT_FIND_CLASS, 40, 1, JSEXN_TYPEERR, "can't find class id {0}") +MSG_DEF(JSMSG_DEAD_OBJECT, 41, 0, JSEXN_TYPEERR, "can't access dead object") +MSG_DEF(JSMSG_BYTECODE_TOO_BIG, 42, 2, JSEXN_INTERNALERR, "bytecode {0} too large (limit {1})") +MSG_DEF(JSMSG_UNKNOWN_FORMAT, 43, 1, JSEXN_INTERNALERR, "unknown bytecode format {0}") +MSG_DEF(JSMSG_TOO_MANY_CON_ARGS, 44, 0, JSEXN_SYNTAXERR, "too many constructor arguments") +MSG_DEF(JSMSG_TOO_MANY_FUN_ARGS, 45, 0, JSEXN_SYNTAXERR, "too many function arguments") +MSG_DEF(JSMSG_BAD_QUANTIFIER, 46, 0, JSEXN_SYNTAXERR, "invalid quantifier") +MSG_DEF(JSMSG_MIN_TOO_BIG, 47, 1, JSEXN_SYNTAXERR, "overlarge minimum {0}") +MSG_DEF(JSMSG_MAX_TOO_BIG, 48, 1, JSEXN_SYNTAXERR, "overlarge maximum {0}") +MSG_DEF(JSMSG_OUT_OF_ORDER, 49, 1, JSEXN_SYNTAXERR, "maximum {0} less than minimum") +MSG_DEF(JSMSG_BAD_DESTRUCT_DECL, 50, 0, JSEXN_SYNTAXERR, "missing = in destructuring declaration") +MSG_DEF(JSMSG_BAD_DESTRUCT_ASS, 51, 0, JSEXN_REFERENCEERR, "invalid destructuring assignment operator") +MSG_DEF(JSMSG_PAREN_AFTER_LET, 52, 0, JSEXN_SYNTAXERR, "missing ) after let head") +MSG_DEF(JSMSG_CURLY_AFTER_LET, 53, 0, JSEXN_SYNTAXERR, "missing } after let block") +MSG_DEF(JSMSG_MISSING_PAREN, 54, 0, JSEXN_SYNTAXERR, "unterminated parenthetical") +MSG_DEF(JSMSG_UNTERM_CLASS, 55, 0, JSEXN_SYNTAXERR, "unterminated character class") +MSG_DEF(JSMSG_TRAILING_SLASH, 56, 0, JSEXN_SYNTAXERR, "trailing \\ in regular expression") +MSG_DEF(JSMSG_BAD_CLASS_RANGE, 57, 0, JSEXN_SYNTAXERR, "invalid range in character class") +MSG_DEF(JSMSG_BAD_REGEXP_FLAG, 58, 1, JSEXN_SYNTAXERR, "invalid regular expression flag {0}") +MSG_DEF(JSMSG_NO_INPUT, 59, 5, JSEXN_SYNTAXERR, "no input for /{0}/{1}{2}{3}{4}") +MSG_DEF(JSMSG_CANT_OPEN, 60, 2, JSEXN_ERR, "can't open {0}: {1}") +MSG_DEF(JSMSG_TOO_MANY_FUN_APPLY_ARGS, 61, 0, JSEXN_RANGEERR, "arguments array passed to Function.prototype.apply is too large") +MSG_DEF(JSMSG_UNMATCHED_RIGHT_PAREN, 62, 0, JSEXN_SYNTAXERR, "unmatched ) in regular expression") +MSG_DEF(JSMSG_TOO_BIG_TO_ENCODE, 63, 0, JSEXN_INTERNALERR, "data are to big to encode") +MSG_DEF(JSMSG_ARG_INDEX_OUT_OF_RANGE, 64, 1, JSEXN_RANGEERR, "argument {0} accesses an index that is out of range") +MSG_DEF(JSMSG_SPREAD_TOO_LARGE, 65, 0, JSEXN_RANGEERR, "array too large due to spread operand(s)") +MSG_DEF(JSMSG_SOURCE_TOO_LONG, 66, 0, JSEXN_RANGEERR, "source is too long") +MSG_DEF(JSMSG_BAD_WEAKMAP_KEY, 67, 0, JSEXN_TYPEERR, "cannot use the given object as a weak map key") +MSG_DEF(JSMSG_BAD_SCRIPT_MAGIC, 68, 0, JSEXN_INTERNALERR, "bad script XDR magic number") +MSG_DEF(JSMSG_PAREN_BEFORE_FORMAL, 69, 0, JSEXN_SYNTAXERR, "missing ( before formal parameters") +MSG_DEF(JSMSG_MISSING_FORMAL, 70, 0, JSEXN_SYNTAXERR, "missing formal parameter") +MSG_DEF(JSMSG_PAREN_AFTER_FORMAL, 71, 0, JSEXN_SYNTAXERR, "missing ) after formal parameters") +MSG_DEF(JSMSG_CURLY_BEFORE_BODY, 72, 0, JSEXN_SYNTAXERR, "missing { before function body") +MSG_DEF(JSMSG_CURLY_AFTER_BODY, 73, 0, JSEXN_SYNTAXERR, "missing } after function body") +MSG_DEF(JSMSG_PAREN_BEFORE_COND, 74, 0, JSEXN_SYNTAXERR, "missing ( before condition") +MSG_DEF(JSMSG_PAREN_AFTER_COND, 75, 0, JSEXN_SYNTAXERR, "missing ) after condition") +MSG_DEF(JSMSG_BAD_DUP_ARGS, 76, 0, JSEXN_SYNTAXERR, "duplicate argument names not allowed in this context") +MSG_DEF(JSMSG_NAME_AFTER_DOT, 77, 0, JSEXN_SYNTAXERR, "missing name after . operator") +MSG_DEF(JSMSG_BRACKET_IN_INDEX, 78, 0, JSEXN_SYNTAXERR, "missing ] in index expression") +MSG_DEF(JSMSG_ACCESSOR_DEF_DENIED, 79, 1, JSEXN_ERR, "Permission denied to define accessor property '{0}'") +MSG_DEF(JSMSG_PAREN_BEFORE_SWITCH, 80, 0, JSEXN_SYNTAXERR, "missing ( before switch expression") +MSG_DEF(JSMSG_PAREN_AFTER_SWITCH, 81, 0, JSEXN_SYNTAXERR, "missing ) after switch expression") +MSG_DEF(JSMSG_CURLY_BEFORE_SWITCH, 82, 0, JSEXN_SYNTAXERR, "missing { before switch body") +MSG_DEF(JSMSG_COLON_AFTER_CASE, 83, 0, JSEXN_SYNTAXERR, "missing : after case label") +MSG_DEF(JSMSG_WHILE_AFTER_DO, 84, 0, JSEXN_SYNTAXERR, "missing while after do-loop body") +MSG_DEF(JSMSG_PAREN_AFTER_FOR, 85, 0, JSEXN_SYNTAXERR, "missing ( after for") +MSG_DEF(JSMSG_SEMI_AFTER_FOR_INIT, 86, 0, JSEXN_SYNTAXERR, "missing ; after for-loop initializer") +MSG_DEF(JSMSG_SEMI_AFTER_FOR_COND, 87, 0, JSEXN_SYNTAXERR, "missing ; after for-loop condition") +MSG_DEF(JSMSG_PAREN_AFTER_FOR_CTRL, 88, 0, JSEXN_SYNTAXERR, "missing ) after for-loop control") +MSG_DEF(JSMSG_CURLY_BEFORE_TRY, 89, 0, JSEXN_SYNTAXERR, "missing { before try block") +MSG_DEF(JSMSG_CURLY_AFTER_TRY, 90, 0, JSEXN_SYNTAXERR, "missing } after try block") +MSG_DEF(JSMSG_PAREN_BEFORE_CATCH, 91, 0, JSEXN_SYNTAXERR, "missing ( before catch") +MSG_DEF(JSMSG_CATCH_IDENTIFIER, 92, 0, JSEXN_SYNTAXERR, "missing identifier in catch") +MSG_DEF(JSMSG_PAREN_AFTER_CATCH, 93, 0, JSEXN_SYNTAXERR, "missing ) after catch") +MSG_DEF(JSMSG_CURLY_BEFORE_CATCH, 94, 0, JSEXN_SYNTAXERR, "missing { before catch block") +MSG_DEF(JSMSG_CURLY_AFTER_CATCH, 95, 0, JSEXN_SYNTAXERR, "missing } after catch block") +MSG_DEF(JSMSG_CURLY_BEFORE_FINALLY, 96, 0, JSEXN_SYNTAXERR, "missing { before finally block") +MSG_DEF(JSMSG_CURLY_AFTER_FINALLY, 97, 0, JSEXN_SYNTAXERR, "missing } after finally block") +MSG_DEF(JSMSG_CATCH_OR_FINALLY, 98, 0, JSEXN_SYNTAXERR, "missing catch or finally after try") +MSG_DEF(JSMSG_PAREN_BEFORE_WITH, 99, 0, JSEXN_SYNTAXERR, "missing ( before with-statement object") +MSG_DEF(JSMSG_PAREN_AFTER_WITH, 100, 0, JSEXN_SYNTAXERR, "missing ) after with-statement object") +MSG_DEF(JSMSG_CURLY_IN_COMPOUND, 101, 0, JSEXN_SYNTAXERR, "missing } in compound statement") +MSG_DEF(JSMSG_NO_VARIABLE_NAME, 102, 0, JSEXN_SYNTAXERR, "missing variable name") +MSG_DEF(JSMSG_COLON_IN_COND, 103, 0, JSEXN_SYNTAXERR, "missing : in conditional expression") +MSG_DEF(JSMSG_PAREN_AFTER_ARGS, 104, 0, JSEXN_SYNTAXERR, "missing ) after argument list") +MSG_DEF(JSMSG_BRACKET_AFTER_LIST, 105, 0, JSEXN_SYNTAXERR, "missing ] after element list") +MSG_DEF(JSMSG_COLON_AFTER_ID, 106, 0, JSEXN_SYNTAXERR, "missing : after property id") +MSG_DEF(JSMSG_CURLY_AFTER_LIST, 107, 0, JSEXN_SYNTAXERR, "missing } after property list") +MSG_DEF(JSMSG_PAREN_IN_PAREN, 108, 0, JSEXN_SYNTAXERR, "missing ) in parenthetical") +MSG_DEF(JSMSG_SEMI_BEFORE_STMNT, 109, 0, JSEXN_SYNTAXERR, "missing ; before statement") +MSG_DEF(JSMSG_NO_RETURN_VALUE, 110, 1, JSEXN_TYPEERR, "function {0} does not always return a value") +MSG_DEF(JSMSG_DUPLICATE_FORMAL, 111, 1, JSEXN_SYNTAXERR, "duplicate formal argument {0}") +MSG_DEF(JSMSG_EQUAL_AS_ASSIGN, 112, 0, JSEXN_SYNTAXERR, "test for equality (==) mistyped as assignment (=)?") +MSG_DEF(JSMSG_OPTIMIZED_CLOSURE_LEAK, 113, 0, JSEXN_INTERNALERR, "can't access optimized closure") +MSG_DEF(JSMSG_TOO_MANY_DEFAULTS, 114, 0, JSEXN_SYNTAXERR, "more than one switch default") +MSG_DEF(JSMSG_TOO_MANY_CASES, 115, 0, JSEXN_INTERNALERR, "too many switch cases") +MSG_DEF(JSMSG_BAD_SWITCH, 116, 0, JSEXN_SYNTAXERR, "invalid switch statement") +MSG_DEF(JSMSG_BAD_FOR_LEFTSIDE, 117, 0, JSEXN_SYNTAXERR, "invalid for/in left-hand side") +MSG_DEF(JSMSG_CATCH_AFTER_GENERAL, 118, 0, JSEXN_SYNTAXERR, "catch after unconditional catch") +MSG_DEF(JSMSG_CATCH_WITHOUT_TRY, 119, 0, JSEXN_SYNTAXERR, "catch without try") +MSG_DEF(JSMSG_FINALLY_WITHOUT_TRY, 120, 0, JSEXN_SYNTAXERR, "finally without try") +MSG_DEF(JSMSG_LABEL_NOT_FOUND, 121, 0, JSEXN_SYNTAXERR, "label not found") +MSG_DEF(JSMSG_TOUGH_BREAK, 122, 0, JSEXN_SYNTAXERR, "unlabeled break must be inside loop or switch") +MSG_DEF(JSMSG_BAD_CONTINUE, 123, 0, JSEXN_SYNTAXERR, "continue must be inside loop") +MSG_DEF(JSMSG_BAD_RETURN_OR_YIELD, 124, 1, JSEXN_SYNTAXERR, "{0} not in function") +MSG_DEF(JSMSG_BAD_LABEL, 125, 0, JSEXN_SYNTAXERR, "invalid label") +MSG_DEF(JSMSG_DUPLICATE_LABEL, 126, 0, JSEXN_SYNTAXERR, "duplicate label") +MSG_DEF(JSMSG_VAR_HIDES_ARG, 127, 1, JSEXN_TYPEERR, "variable {0} redeclares argument") +MSG_DEF(JSMSG_BAD_VAR_INIT, 128, 0, JSEXN_SYNTAXERR, "invalid variable initialization") +MSG_DEF(JSMSG_BAD_LEFTSIDE_OF_ASS, 129, 0, JSEXN_REFERENCEERR, "invalid assignment left-hand side") +MSG_DEF(JSMSG_BAD_OPERAND, 130, 1, JSEXN_SYNTAXERR, "invalid {0} operand") +MSG_DEF(JSMSG_BAD_PROP_ID, 131, 0, JSEXN_SYNTAXERR, "invalid property id") +MSG_DEF(JSMSG_RESERVED_ID, 132, 1, JSEXN_SYNTAXERR, "{0} is a reserved identifier") +MSG_DEF(JSMSG_SYNTAX_ERROR, 133, 0, JSEXN_SYNTAXERR, "syntax error") +MSG_DEF(JSMSG_MISSING_BINARY_DIGITS, 134, 0, JSEXN_SYNTAXERR, "missing binary digits after '0b'") +MSG_DEF(JSMSG_BAD_PROTOTYPE, 135, 1, JSEXN_TYPEERR, "'prototype' property of {0} is not an object") +MSG_DEF(JSMSG_MISSING_EXPONENT, 136, 0, JSEXN_SYNTAXERR, "missing exponent") +MSG_DEF(JSMSG_OUT_OF_MEMORY, 137, 0, JSEXN_ERR, "out of memory") +MSG_DEF(JSMSG_UNTERMINATED_STRING, 138, 0, JSEXN_SYNTAXERR, "unterminated string literal") +MSG_DEF(JSMSG_TOO_MANY_PARENS, 139, 0, JSEXN_INTERNALERR, "too many parentheses in regular expression") +MSG_DEF(JSMSG_UNTERMINATED_COMMENT, 140, 0, JSEXN_SYNTAXERR, "unterminated comment") +MSG_DEF(JSMSG_UNTERMINATED_REGEXP, 141, 0, JSEXN_SYNTAXERR, "unterminated regular expression literal") +MSG_DEF(JSMSG_BAD_CLONE_FUNOBJ_SCOPE, 142, 0, JSEXN_TYPEERR, "bad cloned function scope chain") +MSG_DEF(JSMSG_MISSING_OCTAL_DIGITS, 143, 0, JSEXN_SYNTAXERR, "missing octal digits after '0o'") +MSG_DEF(JSMSG_ILLEGAL_CHARACTER, 144, 0, JSEXN_SYNTAXERR, "illegal character") +MSG_DEF(JSMSG_BAD_OCTAL, 145, 1, JSEXN_SYNTAXERR, "{0} is not a legal ECMA-262 octal constant") +MSG_DEF(JSMSG_RESULTING_STRING_TOO_LARGE, 146, 0, JSEXN_RANGEERR, "repeat count must be less than infinity and not overflow maximum string size") +MSG_DEF(JSMSG_UNCAUGHT_EXCEPTION, 147, 1, JSEXN_INTERNALERR, "uncaught exception: {0}") +MSG_DEF(JSMSG_INVALID_BACKREF, 148, 0, JSEXN_SYNTAXERR, "non-octal digit in an escape sequence that doesn't match a back-reference") +MSG_DEF(JSMSG_BAD_BACKREF, 149, 0, JSEXN_SYNTAXERR, "back-reference exceeds number of capturing parentheses") +MSG_DEF(JSMSG_PRECISION_RANGE, 150, 1, JSEXN_RANGEERR, "precision {0} out of range") +MSG_DEF(JSMSG_BAD_GETTER_OR_SETTER, 151, 1, JSEXN_TYPEERR, "invalid {0} usage") +MSG_DEF(JSMSG_BAD_ARRAY_LENGTH, 152, 0, JSEXN_RANGEERR, "invalid array length") +MSG_DEF(JSMSG_CANT_DESCRIBE_PROPS, 153, 1, JSEXN_TYPEERR, "can't describe non-native properties of class {0}") +MSG_DEF(JSMSG_BAD_APPLY_ARGS, 154, 1, JSEXN_TYPEERR, "second argument to Function.prototype.{0} must be an array") +MSG_DEF(JSMSG_REDECLARED_VAR, 155, 2, JSEXN_TYPEERR, "redeclaration of {0} {1}") +MSG_DEF(JSMSG_UNDECLARED_VAR, 156, 1, JSEXN_REFERENCEERR, "assignment to undeclared variable {0}") +MSG_DEF(JSMSG_ANON_NO_RETURN_VALUE, 157, 0, JSEXN_TYPEERR, "anonymous function does not always return a value") +MSG_DEF(JSMSG_DEPRECATED_USAGE, 158, 1, JSEXN_REFERENCEERR, "deprecated {0} usage") +MSG_DEF(JSMSG_BAD_URI, 159, 0, JSEXN_URIERR, "malformed URI sequence") +MSG_DEF(JSMSG_GETTER_ONLY, 160, 0, JSEXN_TYPEERR, "setting a property that has only a getter") +MSG_DEF(JSMSG_IDSTART_AFTER_NUMBER, 161, 0, JSEXN_SYNTAXERR, "identifier starts immediately after numeric literal") +MSG_DEF(JSMSG_UNDEFINED_PROP, 162, 1, JSEXN_REFERENCEERR, "reference to undefined property {0}") +MSG_DEF(JSMSG_USELESS_EXPR, 163, 0, JSEXN_TYPEERR, "useless expression") +MSG_DEF(JSMSG_REDECLARED_PARAM, 164, 1, JSEXN_TYPEERR, "redeclaration of formal parameter {0}") +MSG_DEF(JSMSG_NEWREGEXP_FLAGGED, 165, 0, JSEXN_TYPEERR, "can't supply flags when constructing one RegExp from another") +MSG_DEF(JSMSG_RESERVED_SLOT_RANGE, 166, 0, JSEXN_RANGEERR, "reserved slot index out of range") +MSG_DEF(JSMSG_CANT_DECODE_PRINCIPALS, 167, 0, JSEXN_INTERNALERR, "can't decode JSPrincipals") +MSG_DEF(JSMSG_CANT_SEAL_OBJECT, 168, 1, JSEXN_ERR, "can't seal {0} objects") +MSG_DEF(JSMSG_TOO_MANY_CATCH_VARS, 169, 0, JSEXN_SYNTAXERR, "too many catch variables") +MSG_DEF(JSMSG_NEGATIVE_REPETITION_COUNT, 170, 0, JSEXN_RANGEERR, "repeat count must be non-negative") +MSG_DEF(JSMSG_INVALID_FOR_OF_INIT, 171, 0, JSEXN_SYNTAXERR, "for-of loop variable declaration may not have an initializer") +MSG_DEF(JSMSG_INVALID_MAP_ITERABLE, 172, 0, JSEXN_TYPEERR, "iterable for map should have array-like objects") +MSG_DEF(JSMSG_NOT_A_CODEPOINT, 173, 1, JSEXN_RANGEERR, "{0} is not a valid code point") +MSG_DEF(JSMSG_BRACKET_AFTER_ARRAY_COMPREHENSION, 174, 0, JSEXN_SYNTAXERR, "missing ] after array comprehension") +MSG_DEF(JSMSG_NESTING_GENERATOR, 175, 0, JSEXN_TYPEERR, "already executing generator") +MSG_DEF(JSMSG_PAREN_AFTER_FOR_OF_ITERABLE, 176, 0, JSEXN_SYNTAXERR, "missing ) after for-of iterable") +MSG_DEF(JSMSG_INVALID_NORMALIZE_FORM, 177, 0, JSEXN_RANGEERR, "form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD'") +MSG_DEF(JSMSG_NOTHING_TO_REPEAT, 178, 0, JSEXN_SYNTAXERR, "nothing to repeat") +MSG_DEF(JSMSG_INVALID_GROUP, 179, 0, JSEXN_SYNTAXERR, "invalid regexp group") +MSG_DEF(JSMSG_ESCAPE_AT_END_OF_REGEXP, 180, 0, JSEXN_SYNTAXERR, "\\ at end of pattern") +MSG_DEF(JSMSG_NUMBERS_OUT_OF_ORDER, 181, 0, JSEXN_SYNTAXERR, "numbers out of order in {} quantifier.") +MSG_DEF(JSMSG_BAD_GENERATOR_SEND, 182, 1, JSEXN_TYPEERR, "attempt to send {0} to newborn generator") +MSG_DEF(JSMSG_SC_NOT_TRANSFERABLE, 183, 0, JSEXN_TYPEERR, "invalid transferable array for structured clone") +MSG_DEF(JSMSG_SC_DUP_TRANSFERABLE, 184, 0, JSEXN_TYPEERR, "duplicate transferable for structured clone") +MSG_DEF(JSMSG_CANT_REPORT_AS_NON_EXTENSIBLE, 185, 0, JSEXN_TYPEERR, "proxy can't report an extensible object as non-extensible") +MSG_DEF(JSMSG_SYMBOL_TO_STRING, 186, 0, JSEXN_TYPEERR, "can't convert symbol to string") +MSG_DEF(JSMSG_UNUSED187, 187, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_INCOMPATIBLE_METHOD, 188, 3, JSEXN_TYPEERR, "{0} {1} called on incompatible {2}") +MSG_DEF(JSMSG_SYMBOL_TO_PRIMITIVE, 189, 0, JSEXN_TYPEERR, "can't convert symbol object to primitive") +MSG_DEF(JSMSG_UNUSED190, 190, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_BAD_INDEX, 191, 0, JSEXN_RANGEERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_SELFHOSTED_TOP_LEVEL_LET,192,0, JSEXN_SYNTAXERR, "self-hosted code cannot contain top-level 'let' declarations") +MSG_DEF(JSMSG_BAD_FOR_EACH_LOOP, 193, 0, JSEXN_SYNTAXERR, "invalid for each loop") +MSG_DEF(JSMSG_OBJECT_WATCH_DEPRECATED,194, 0, JSEXN_NONE, "Object.prototype.watch and unwatch are very slow, non-standard, and deprecated; use a getter/setter instead") +MSG_DEF(JSMSG_TYPE_ERR_BAD_ARGS, 195, 0, JSEXN_TYPEERR, "invalid arguments") +MSG_DEF(JSMSG_REDECLARED_CATCH_IDENTIFIER, 196, 1, JSEXN_TYPEERR, "redeclaration of identifier '{0}' in catch") +MSG_DEF(JSMSG_INTERNAL_INTL_ERROR, 197, 0, JSEXN_ERR, "internal error while computing Intl data") +MSG_DEF(JSMSG_DEFAULT_LOCALE_ERROR, 198, 0, JSEXN_ERR, "internal error getting the default locale") +MSG_DEF(JSMSG_TOO_MANY_LOCALS, 199, 0, JSEXN_SYNTAXERR, "too many local variables") +MSG_DEF(JSMSG_ARRAY_INIT_TOO_BIG, 200, 0, JSEXN_INTERNALERR, "array initialiser too large") +MSG_DEF(JSMSG_REGEXP_TOO_COMPLEX, 201, 0, JSEXN_INTERNALERR, "regular expression too complex") +MSG_DEF(JSMSG_BUFFER_TOO_SMALL, 202, 0, JSEXN_INTERNALERR, "buffer too small") +MSG_DEF(JSMSG_BAD_SURROGATE_CHAR, 203, 1, JSEXN_TYPEERR, "bad surrogate character {0}") +MSG_DEF(JSMSG_UTF8_CHAR_TOO_LARGE, 204, 1, JSEXN_TYPEERR, "UTF-8 character {0} too large") +MSG_DEF(JSMSG_MALFORMED_UTF8_CHAR, 205, 1, JSEXN_TYPEERR, "malformed UTF-8 character sequence at offset {0}") +MSG_DEF(JSMSG_USER_DEFINED_ERROR, 206, 0, JSEXN_ERR, "JS_ReportError was called") +MSG_DEF(JSMSG_WRONG_CONSTRUCTOR, 207, 1, JSEXN_TYPEERR, "wrong constructor called for {0}") +MSG_DEF(JSMSG_BAD_GENERATOR_RETURN, 208, 1, JSEXN_TYPEERR, "generator function {0} returns a value") +MSG_DEF(JSMSG_BAD_ANON_GENERATOR_RETURN, 209, 0, JSEXN_TYPEERR, "anonymous generator function returns a value") +MSG_DEF(JSMSG_PROTO_SETTING_SLOW, 210, 0, JSEXN_NONE, "mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create") +MSG_DEF(JSMSG_IN_AFTER_FOR_NAME, 211, 0, JSEXN_SYNTAXERR, "missing 'in' or 'of' after for") +MSG_DEF(JSMSG_BAD_TRAP_RETURN_VALUE, 212, 2, JSEXN_TYPEERR,"trap {1} for {0} returned a primitive value") +MSG_DEF(JSMSG_OF_AFTER_FOR_NAME, 213, 0, JSEXN_SYNTAXERR, "missing 'of' after for") +MSG_DEF(JSMSG_BAD_GENERATOR_YIELD, 214, 1, JSEXN_TYPEERR, "yield from closing generator {0}") +MSG_DEF(JSMSG_BAD_GENERATOR_SYNTAX, 215, 1, JSEXN_SYNTAXERR, "{0} expression must be parenthesized") +MSG_DEF(JSMSG_ARRAY_COMP_LEFTSIDE, 216, 0, JSEXN_SYNTAXERR, "invalid array comprehension left-hand side") +MSG_DEF(JSMSG_LET_COMP_BINDING, 217, 0, JSEXN_SYNTAXERR, "'let' is not a valid name for a comprehension variable") +MSG_DEF(JSMSG_EMPTY_ARRAY_REDUCE, 218, 0, JSEXN_TYPEERR, "reduce of empty array with no initial value") +MSG_DEF(JSMSG_BAD_SYMBOL, 219, 1, JSEXN_TYPEERR, "{0} is not a well-known @@-symbol") +MSG_DEF(JSMSG_BAD_DELETE_OPERAND, 220, 0, JSEXN_REFERENCEERR, "invalid delete operand") +MSG_DEF(JSMSG_BAD_INCOP_OPERAND, 221, 0, JSEXN_REFERENCEERR, "invalid increment/decrement operand") +MSG_DEF(JSMSG_UNEXPECTED_TYPE, 222, 2, JSEXN_TYPEERR, "{0} is {1}") +MSG_DEF(JSMSG_LET_DECL_NOT_IN_BLOCK, 223, 0, JSEXN_SYNTAXERR, "let declaration not directly within block") +MSG_DEF(JSMSG_UNUSED224, 224, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_CANT_SET_ARRAY_ATTRS, 225, 0, JSEXN_INTERNALERR, "can't set attributes on indexed array properties") +MSG_DEF(JSMSG_EVAL_ARITY, 226, 0, JSEXN_TYPEERR, "eval accepts only one parameter") +MSG_DEF(JSMSG_MISSING_FUN_ARG, 227, 2, JSEXN_TYPEERR, "missing argument {0} when calling function {1}") +MSG_DEF(JSMSG_JSON_BAD_PARSE, 228, 3, JSEXN_SYNTAXERR, "JSON.parse: {0} at line {1} column {2} of the JSON data") +MSG_DEF(JSMSG_JSON_BAD_STRINGIFY, 229, 0, JSEXN_ERR, "JSON.stringify") +MSG_DEF(JSMSG_NOT_CALLABLE_OR_UNDEFINED, 230, 0, JSEXN_TYPEERR, "value is not a function or undefined") +MSG_DEF(JSMSG_NOT_NONNULL_OBJECT, 231, 0, JSEXN_TYPEERR, "value is not a non-null object") +MSG_DEF(JSMSG_DEPRECATED_OCTAL, 232, 0, JSEXN_SYNTAXERR, "octal literals and octal escape sequences are deprecated") +MSG_DEF(JSMSG_STRICT_CODE_WITH, 233, 0, JSEXN_SYNTAXERR, "strict mode code may not contain 'with' statements") +MSG_DEF(JSMSG_DUPLICATE_PROPERTY, 234, 1, JSEXN_SYNTAXERR, "property name {0} appears more than once in object literal") +MSG_DEF(JSMSG_DEPRECATED_DELETE_OPERAND, 235, 0, JSEXN_SYNTAXERR, "applying the 'delete' operator to an unqualified name is deprecated") +MSG_DEF(JSMSG_BAD_STRICT_ASSIGN, 236, 1, JSEXN_SYNTAXERR, "can't assign to {0} in strict mode") +MSG_DEF(JSMSG_BAD_BINDING, 237, 1, JSEXN_SYNTAXERR, "redefining {0} is deprecated") +MSG_DEF(JSMSG_INVALID_DESCRIPTOR, 238, 0, JSEXN_TYPEERR, "property descriptors must not specify a value or be writable when a getter or setter has been specified") +MSG_DEF(JSMSG_OBJECT_NOT_EXTENSIBLE, 239, 1, JSEXN_TYPEERR, "{0} is not extensible") +MSG_DEF(JSMSG_CANT_REDEFINE_PROP, 240, 1, JSEXN_TYPEERR, "can't redefine non-configurable property '{0}'") +MSG_DEF(JSMSG_CANT_APPEND_TO_ARRAY, 241, 0, JSEXN_TYPEERR, "can't add elements past the end of an array if its length property is unwritable") +MSG_DEF(JSMSG_CANT_REDEFINE_ARRAY_LENGTH,242, 0, JSEXN_TYPEERR, "can't redefine array length") +MSG_DEF(JSMSG_CANT_DEFINE_PAST_ARRAY_LENGTH,243, 0, JSEXN_TYPEERR, "can't define array index property past the end of an array with non-writable length") +MSG_DEF(JSMSG_TYPED_ARRAY_BAD_INDEX, 244, 0, JSEXN_ERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_TYPED_ARRAY_NEGATIVE_ARG, 245, 1, JSEXN_ERR, "argument {0} must be >= 0") +MSG_DEF(JSMSG_TYPED_ARRAY_BAD_ARGS, 246, 0, JSEXN_ERR, "invalid arguments") +MSG_DEF(JSMSG_CSP_BLOCKED_FUNCTION, 247, 0, JSEXN_ERR, "call to Function() blocked by CSP") +MSG_DEF(JSMSG_BAD_GET_SET_FIELD, 248, 1, JSEXN_TYPEERR, "property descriptor's {0} field is neither undefined nor a function") +MSG_DEF(JSMSG_BAD_PROXY_FIX, 249, 0, JSEXN_TYPEERR, "proxy was fixed while executing the handler") +MSG_DEF(JSMSG_INVALID_EVAL_SCOPE_ARG, 250, 0, JSEXN_EVALERR, "invalid eval scope argument") +MSG_DEF(JSMSG_ACCESSOR_WRONG_ARGS, 251, 3, JSEXN_SYNTAXERR, "{0} functions must have {1} argument{2}") +MSG_DEF(JSMSG_THROW_TYPE_ERROR, 252, 0, JSEXN_TYPEERR, "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them") +MSG_DEF(JSMSG_BAD_TOISOSTRING_PROP, 253, 0, JSEXN_TYPEERR, "toISOString property is not callable") +MSG_DEF(JSMSG_BAD_PARSE_NODE, 254, 0, JSEXN_INTERNALERR, "bad parse node") +MSG_DEF(JSMSG_NOT_EXPECTED_TYPE, 255, 3, JSEXN_TYPEERR, "{0}: expected {1}, got {2}") +MSG_DEF(JSMSG_CALLER_IS_STRICT, 256, 0, JSEXN_TYPEERR, "access to strict mode caller function is censored") +MSG_DEF(JSMSG_NEED_DEBUG_MODE, 257, 0, JSEXN_ERR, "function can be called only in debug mode") +MSG_DEF(JSMSG_STRICT_CODE_LET_EXPR_STMT, 258, 0, JSEXN_ERR, "strict mode code may not contain unparenthesized let expression statements") +MSG_DEF(JSMSG_CANT_CHANGE_EXTENSIBILITY, 259, 0, JSEXN_TYPEERR, "can't change object's extensibility") +MSG_DEF(JSMSG_SC_BAD_SERIALIZED_DATA, 260, 1, JSEXN_INTERNALERR, "bad serialized structured data ({0})") +MSG_DEF(JSMSG_SC_UNSUPPORTED_TYPE, 261, 0, JSEXN_TYPEERR, "unsupported type for structured data") +MSG_DEF(JSMSG_SC_RECURSION, 262, 0, JSEXN_INTERNALERR, "recursive object") +MSG_DEF(JSMSG_DEBUG_CANT_DEBUG_GLOBAL, 263, 0, JSEXN_ERR, "passing non-debuggable global to addDebuggee") +MSG_DEF(JSMSG_BAD_CLONE_VERSION, 264, 0, JSEXN_ERR, "unsupported structured clone version") +MSG_DEF(JSMSG_CANT_CLONE_OBJECT, 265, 0, JSEXN_TYPEERR, "can't clone object") +MSG_DEF(JSMSG_DEBUG_RESUMPTION_VALUE_DISALLOWED, 266, 0, JSEXN_TYPEERR, "resumption values are disallowed in this hook") +MSG_DEF(JSMSG_STRICT_FUNCTION_STATEMENT, 267, 0, JSEXN_SYNTAXERR, "in strict mode code, functions may be declared only at top level or immediately within another function") +MSG_DEF(JSMSG_INVALID_FOR_IN_INIT, 268, 0, JSEXN_SYNTAXERR, "for-in loop let declaration may not have an initializer") +MSG_DEF(JSMSG_CLEARED_SCOPE, 269, 0, JSEXN_TYPEERR, "attempt to run compile-and-go script on a cleared scope") +MSG_DEF(JSMSG_MALFORMED_ESCAPE, 270, 1, JSEXN_SYNTAXERR, "malformed {0} character escape sequence") +MSG_DEF(JSMSG_BAD_GENEXP_BODY, 271, 1, JSEXN_SYNTAXERR, "illegal use of {0} in generator expression") +MSG_DEF(JSMSG_YIELD_WITHOUT_OPERAND, 272, 0, JSEXN_SYNTAXERR, "yield without a value is deprecated, and illegal in ES6 (use 'yield undefined' instead)") +MSG_DEF(JSMSG_UNNAMED_FUNCTION_STMT, 273, 0, JSEXN_SYNTAXERR, "function statement requires a name") +MSG_DEF(JSMSG_CCW_REQUIRED, 274, 1, JSEXN_TYPEERR, "{0}: argument must be an object from a different compartment") +MSG_DEF(JSMSG_DEBUG_BAD_RESUMPTION, 275, 0, JSEXN_TYPEERR, "debugger resumption value must be undefined, {throw: val}, {return: val}, or null") +MSG_DEF(JSMSG_ASSIGN_FUNCTION_OR_NULL, 276, 1, JSEXN_TYPEERR, "value assigned to {0} must be a function or null") +MSG_DEF(JSMSG_DEBUG_NOT_LIVE, 277, 1, JSEXN_ERR, "{0} is not live") +MSG_DEF(JSMSG_DEBUG_OBJECT_WRONG_OWNER, 278, 0, JSEXN_TYPEERR, "Debugger.Object belongs to a different Debugger") +MSG_DEF(JSMSG_DEBUG_OBJECT_PROTO, 279, 0, JSEXN_TYPEERR, "Debugger.Object.prototype is not a valid Debugger.Object") +MSG_DEF(JSMSG_DEBUG_LOOP, 280, 0, JSEXN_TYPEERR, "cannot debug an object in same compartment as debugger or a compartment that is already debugging the debugger") +MSG_DEF(JSMSG_DEBUG_NOT_IDLE, 281, 0, JSEXN_ERR, "can't start debugging: a debuggee script is on the stack") +MSG_DEF(JSMSG_DEBUG_BAD_OFFSET, 282, 0, JSEXN_TYPEERR, "invalid script offset") +MSG_DEF(JSMSG_DEBUG_BAD_LINE, 283, 0, JSEXN_TYPEERR, "invalid line number") +MSG_DEF(JSMSG_DEBUG_NOT_DEBUGGING, 284, 0, JSEXN_ERR, "can't set breakpoint: script global is not a debuggee") +MSG_DEF(JSMSG_DEBUG_COMPARTMENT_MISMATCH, 285, 2, JSEXN_TYPEERR, "{0}: descriptor .{1} property is an object in a different compartment than the target object") +MSG_DEF(JSMSG_DEBUG_NOT_SCRIPT_FRAME, 286, 0, JSEXN_ERR, "stack frame is not running JavaScript code") +MSG_DEF(JSMSG_CANT_WATCH_PROP, 287, 0, JSEXN_TYPEERR, "properties whose names are objects can't be watched") +MSG_DEF(JSMSG_CSP_BLOCKED_EVAL, 288, 0, JSEXN_ERR, "call to eval() blocked by CSP") +MSG_DEF(JSMSG_DEBUG_NO_SCOPE_OBJECT, 289, 0, JSEXN_TYPEERR, "declarative Environments don't have binding objects") +MSG_DEF(JSMSG_EMPTY_CONSEQUENT, 290, 0, JSEXN_SYNTAXERR, "mistyped ; after conditional?") +MSG_DEF(JSMSG_NOT_ITERABLE, 291, 1, JSEXN_TYPEERR, "{0} is not iterable") +MSG_DEF(JSMSG_QUERY_LINE_WITHOUT_URL, 292, 0, JSEXN_TYPEERR, "findScripts query object has 'line' property, but no 'url' property") +MSG_DEF(JSMSG_QUERY_INNERMOST_WITHOUT_LINE_URL, 293, 0, JSEXN_TYPEERR, "findScripts query object has 'innermost' property without both 'url' and 'line' properties") +MSG_DEF(JSMSG_DEBUG_VARIABLE_NOT_FOUND, 294, 0, JSEXN_TYPEERR, "variable not found in environment") +MSG_DEF(JSMSG_PARAMETER_AFTER_REST, 295, 0, JSEXN_SYNTAXERR, "parameter after rest parameter") +MSG_DEF(JSMSG_NO_REST_NAME, 296, 0, JSEXN_SYNTAXERR, "no parameter name after ...") +MSG_DEF(JSMSG_ARGUMENTS_AND_REST, 297, 0, JSEXN_SYNTAXERR, "'arguments' object may not be used in conjunction with a rest parameter") +MSG_DEF(JSMSG_FUNCTION_ARGUMENTS_AND_REST, 298, 0, JSEXN_ERR, "the 'arguments' property of a function with a rest parameter may not be used") +MSG_DEF(JSMSG_REST_WITH_DEFAULT, 299, 0, JSEXN_SYNTAXERR, "rest parameter may not have a default") +MSG_DEF(JSMSG_NONDEFAULT_FORMAL_AFTER_DEFAULT, 300, 0, JSEXN_SYNTAXERR, "parameter(s) with default followed by parameter without default") +MSG_DEF(JSMSG_YIELD_IN_DEFAULT, 301, 0, JSEXN_SYNTAXERR, "yield in default expression") +MSG_DEF(JSMSG_INTRINSIC_NOT_DEFINED, 302, 1, JSEXN_REFERENCEERR, "no intrinsic function {0}") +MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 303, 2, JSEXN_NONE, "{0} is being assigned a {1}, but already has one") +MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 304, 0, JSEXN_RANGEERR, "invalid parallel method argument") +MSG_DEF(JSMSG_REGEXP_RUNTIME_ERROR, 305, 0, JSEXN_INTERNALERR, "an error occurred while executing regular expression") +MSG_DEF(JSMSG_DEBUG_OPTIMIZED_OUT, 306, 0, JSEXN_ERR, "variable has been optimized out") +MSG_DEF(JSMSG_NEXT_RETURNED_PRIMITIVE,307, 0, JSEXN_TYPEERR, "iterator.next() returned a non-object value") +MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_CONFLICT, 308, 0, JSEXN_ERR, "no conflict resolution function provided") +MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BOUNDS, 309, 0, JSEXN_ERR, "index in scatter vector out of bounds") +MSG_DEF(JSMSG_CANT_REPORT_NC_AS_NE, 310, 0, JSEXN_TYPEERR, "proxy can't report a non-configurable own property as non-existent") +MSG_DEF(JSMSG_CANT_REPORT_E_AS_NE, 311, 0, JSEXN_TYPEERR, "proxy can't report an existing own property as non-existent on a non-extensible object") +MSG_DEF(JSMSG_CANT_REPORT_NEW, 312, 0, JSEXN_TYPEERR, "proxy can't report a new property on a non-extensible object") +MSG_DEF(JSMSG_CANT_REPORT_INVALID, 313, 0, JSEXN_TYPEERR, "proxy can't report an incompatible property descriptor") +MSG_DEF(JSMSG_CANT_REPORT_NE_AS_NC, 314, 0, JSEXN_TYPEERR, "proxy can't report a non-existent property as non-configurable") +MSG_DEF(JSMSG_CANT_DEFINE_NEW, 315, 0, JSEXN_TYPEERR, "proxy can't define a new property on a non-extensible object") +MSG_DEF(JSMSG_CANT_DEFINE_INVALID, 316, 0, JSEXN_TYPEERR, "proxy can't define an incompatible property descriptor") +MSG_DEF(JSMSG_CANT_DEFINE_NE_AS_NC, 317, 0, JSEXN_TYPEERR, "proxy can't define a non-existent property as non-configurable") +MSG_DEF(JSMSG_INVALID_TRAP_RESULT, 318, 2, JSEXN_TYPEERR, "trap {1} for {0} returned an invalid result") +MSG_DEF(JSMSG_CANT_SKIP_NC, 319, 0, JSEXN_TYPEERR, "proxy can't skip a non-configurable property") +MSG_DEF(JSMSG_MUST_REPORT_SAME_VALUE, 320, 0, JSEXN_TYPEERR, "proxy must report the same value for a non-writable, non-configurable property") +MSG_DEF(JSMSG_MUST_REPORT_UNDEFINED, 321, 0, JSEXN_TYPEERR, "proxy must report undefined for a non-configurable accessor property without a getter") +MSG_DEF(JSMSG_CANT_SET_NW_NC, 322, 0, JSEXN_TYPEERR, "proxy can't successfully set a non-writable, non-configurable property") +MSG_DEF(JSMSG_CANT_SET_WO_SETTER, 323, 0, JSEXN_TYPEERR, "proxy can't succesfully set an accessor property without a setter") +MSG_DEF(JSMSG_DEBUG_BAD_REFERENT, 324, 2, JSEXN_TYPEERR, "{0} does not refer to {1}") +MSG_DEF(JSMSG_DEBUG_WRAPPER_IN_WAY, 325, 3, JSEXN_TYPEERR, "{0} is {1}{2}a global object, but a direct reference is required") +MSG_DEF(JSMSG_UNWRAP_DENIED, 326, 0, JSEXN_ERR, "permission denied to unwrap object") +MSG_DEF(JSMSG_INTL_OBJECT_NOT_INITED, 327, 3, JSEXN_TYPEERR, "Intl.{0}.prototype.{1} called on value that's not an object initialized as a {2}") +MSG_DEF(JSMSG_INVALID_LOCALES_ELEMENT,328, 0, JSEXN_TYPEERR, "invalid element in locales argument") +MSG_DEF(JSMSG_INVALID_LANGUAGE_TAG, 329, 1, JSEXN_RANGEERR, "invalid language tag: {0}") +MSG_DEF(JSMSG_INVALID_LOCALE_MATCHER, 330, 1, JSEXN_RANGEERR, "invalid locale matcher in supportedLocalesOf(): {0}") +MSG_DEF(JSMSG_INVALID_OPTION_VALUE, 331, 2, JSEXN_RANGEERR, "invalid value {1} for option {0}") +MSG_DEF(JSMSG_INVALID_DIGITS_VALUE, 332, 1, JSEXN_RANGEERR, "invalid digits value: {0}") +MSG_DEF(JSMSG_INTL_OBJECT_REINITED, 333, 0, JSEXN_TYPEERR, "can't initialize object twice as an object of an Intl constructor") +MSG_DEF(JSMSG_INVALID_CURRENCY_CODE, 334, 1, JSEXN_RANGEERR, "invalid currency code in NumberFormat(): {0}") +MSG_DEF(JSMSG_UNDEFINED_CURRENCY, 335, 0, JSEXN_TYPEERR, "undefined currency in NumberFormat() with currency style") +MSG_DEF(JSMSG_INVALID_TIME_ZONE, 336, 1, JSEXN_RANGEERR, "invalid time zone in DateTimeFormat(): {0}") +MSG_DEF(JSMSG_DATE_NOT_FINITE, 337, 0, JSEXN_RANGEERR, "date value is not finite in DateTimeFormat.format()") +MSG_DEF(JSMSG_USE_ASM_DIRECTIVE_FAIL, 338, 0, JSEXN_SYNTAXERR, "\"use asm\" is only meaningful in the Directive Prologue of a function body") +MSG_DEF(JSMSG_USE_ASM_TYPE_FAIL, 339, 1, JSEXN_TYPEERR, "asm.js type error: {0}") +MSG_DEF(JSMSG_USE_ASM_LINK_FAIL, 340, 1, JSEXN_TYPEERR, "asm.js link error: {0}") +MSG_DEF(JSMSG_USE_ASM_TYPE_OK, 341, 1, JSEXN_NONE, "Successfully compiled asm.js code ({0})") +MSG_DEF(JSMSG_BAD_ARROW_ARGS, 342, 0, JSEXN_SYNTAXERR, "invalid arrow-function arguments (parentheses around the arrow-function may help)") +MSG_DEF(JSMSG_YIELD_IN_ARROW, 343, 0, JSEXN_SYNTAXERR, "arrow function may not contain yield") +MSG_DEF(JSMSG_WRONG_VALUE, 344, 2, JSEXN_ERR, "expected {0} but found {1}") +MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BAD_TARGET, 345, 1, JSEXN_ERR, "target for index {0} is not an integer") +MSG_DEF(JSMSG_SELFHOSTED_UNBOUND_NAME,346, 0, JSEXN_TYPEERR, "self-hosted code may not contain unbound name lookups") +MSG_DEF(JSMSG_DEPRECATED_PRAGMA, 347, 1, JSEXN_NONE, "Using //@ to indicate {0} pragmas is deprecated. Use //# instead") +MSG_DEF(JSMSG_BAD_DESTRUCT_ASSIGN, 348, 1, JSEXN_SYNTAXERR, "can't assign to {0} using destructuring assignment") +MSG_DEF(JSMSG_TYPEDOBJECT_ARRAYTYPE_BAD_ARGS, 349, 0, JSEXN_ERR, "Invalid arguments") +MSG_DEF(JSMSG_TYPEDOBJECT_BINARYARRAY_BAD_INDEX, 350, 0, JSEXN_RANGEERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_TYPEDOBJECT_STRUCTTYPE_BAD_ARGS, 351, 0, JSEXN_RANGEERR, "invalid field descriptor") +MSG_DEF(JSMSG_TYPEDOBJECT_NOT_BINARYSTRUCT, 352, 1, JSEXN_TYPEERR, "{0} is not a BinaryStruct") +MSG_DEF(JSMSG_TYPEDOBJECT_SUBARRAY_INTEGER_ARG, 353, 1, JSEXN_ERR, "argument {0} must be an integer") +MSG_DEF(JSMSG_TYPEDOBJECT_STRUCTTYPE_EMPTY_DESCRIPTOR, 354, 0, JSEXN_ERR, "field descriptor cannot be empty") +MSG_DEF(JSMSG_TYPEDOBJECT_STRUCTTYPE_BAD_FIELD, 355, 1, JSEXN_ERR, "field {0} is not a valid BinaryData Type descriptor") +MSG_DEF(JSMSG_GENERATOR_FINISHED, 356, 0, JSEXN_TYPEERR, "generator has already finished") +MSG_DEF(JSMSG_TYPEDOBJECT_TOO_BIG, 357, 0, JSEXN_ERR, "Type is too large to allocate") +MSG_DEF(JSMSG_TYPEDOBJECT_NOT_TYPE_OBJECT, 358, 0, JSEXN_ERR, "Expected a type object") +MSG_DEF(JSMSG_TOO_MANY_CON_SPREADARGS, 359, 0, JSEXN_RANGEERR, "too many constructor arguments") +MSG_DEF(JSMSG_TOO_MANY_FUN_SPREADARGS, 360, 0, JSEXN_RANGEERR, "too many function arguments") +MSG_DEF(JSMSG_DEBUG_NOT_DEBUGGEE, 361, 2, JSEXN_ERR, "{0} is not a debuggee {1}") +MSG_DEF(JSMSG_TYPEDOBJECT_NOT_TYPED_OBJECT, 362, 0, JSEXN_ERR, "Expected a typed object") +MSG_DEF(JSMSG_TYPEDOBJECT_NO_SUCH_PROP, 363, 1, JSEXN_TYPEERR, "No such property: {0}") +MSG_DEF(JSMSG_TYPEDOBJECT_BAD_ARGS, 364, 0, JSEXN_TYPEERR, "invalid arguments") +MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_UNATTACHED, 365, 0, JSEXN_TYPEERR, "handle unattached") +MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_BAD_TYPE, 366, 0, JSEXN_TYPEERR, "handle moved to destination of incorrect type") + +MSG_DEF(JSMSG_IMPORT_DECL_AT_TOP_LEVEL, 367, 0, JSEXN_SYNTAXERR, "import declarations may only appear at top level") +MSG_DEF(JSMSG_NO_IMPORT_NAME, 368, 0, JSEXN_SYNTAXERR, "missing import name") +MSG_DEF(JSMSG_AS_AFTER_RESERVED_WORD, 369, 1, JSEXN_SYNTAXERR, "missing keyword 'as' after reserved word '{0}'") +MSG_DEF(JSMSG_NO_BINDING_NAME, 370, 0, JSEXN_SYNTAXERR, "missing binding name") +MSG_DEF(JSMSG_RC_AFTER_IMPORT_SPEC_LIST, 371, 0, JSEXN_SYNTAXERR, "missing '}' after module specifier list") +MSG_DEF(JSMSG_FROM_AFTER_IMPORT_SPEC_SET, 372, 0, JSEXN_SYNTAXERR, "missing keyword 'from' after import specifier set") +MSG_DEF(JSMSG_DECLARATION_AFTER_IMPORT, 373, 0, JSEXN_SYNTAXERR, "missing declaration after 'import' keyword") +MSG_DEF(JSMSG_MODULE_SPEC_AFTER_FROM, 374, 0, JSEXN_SYNTAXERR, "missing module specifier after 'from' keyword") +MSG_DEF(JSMSG_MODULES_NOT_IMPLEMENTED, 375, 0, JSEXN_SYNTAXERR, "modules are not implemented yet") +MSG_DEF(JSMSG_EXPORT_DECL_AT_TOP_LEVEL, 376, 0, JSEXN_SYNTAXERR, "export declarations may only appear at top level") +MSG_DEF(JSMSG_RC_AFTER_EXPORT_SPEC_LIST, 377, 0, JSEXN_SYNTAXERR, "missing '}' after export specifier list") +MSG_DEF(JSMSG_NO_EXPORT_NAME, 378, 0, JSEXN_SYNTAXERR, "missing export name") +MSG_DEF(JSMSG_DECLARATION_AFTER_EXPORT, 379, 0, JSEXN_SYNTAXERR, "missing declaration after 'export' keyword") +MSG_DEF(JSMSG_INVALID_PROTOTYPE, 380, 0, JSEXN_TYPEERR, "prototype field is not an object") +MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_TO_UNSIZED, 381, 0, JSEXN_TYPEERR, "cannot create a handle to an unsized type") +MSG_DEF(JSMSG_SETPROTOTYPEOF_FAIL, 382, 1, JSEXN_TYPEERR, "[[SetPrototypeOf]] failed on {0}") +MSG_DEF(JSMSG_INVALID_ARG_TYPE, 383, 3, JSEXN_TYPEERR, "Invalid type: {0} can't be a{1} {2}") +MSG_DEF(JSMSG_TERMINATED, 384, 1, JSEXN_ERR, "Script terminated by timeout at:\n{0}") +MSG_DEF(JSMSG_NO_SUCH_SELF_HOSTED_PROP, 385, 1, JSEXN_ERR, "No such property on self-hosted object: {0}") +MSG_DEF(JSMSG_PROXY_EXTENSIBILITY, 386, 0, JSEXN_TYPEERR, "proxy must report same extensiblitity as target") +MSG_DEF(JSMSG_PROXY_CONSTRUCT_OBJECT, 387, 0, JSEXN_TYPEERR, "proxy [[Construct]] must return an object") +MSG_DEF(JSMSG_PROXY_GETOWN_OBJORUNDEF, 388, 0, JSEXN_TYPEERR, "proxy [[GetOwnProperty]] must return an object or undefined") +MSG_DEF(JSMSG_CANT_REPORT_C_AS_NC, 389, 0, JSEXN_TYPEERR, "proxy can't report existing configurable property as non-configurable") diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Anchor.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Anchor.h new file mode 100644 index 0000000000..d9ed3fd750 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Anchor.h @@ -0,0 +1,174 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JS::Anchor implementation. */ + +#ifndef js_Anchor_h +#define js_Anchor_h + +#include "mozilla/Attributes.h" + +#include "js/TypeDecls.h" + +namespace JS { + +/* + * Protecting non-Value, non-JSObject *, non-JSString * values from collection + * + * Most of the time, the garbage collector's conservative stack scanner works + * behind the scenes, finding all live values and protecting them from being + * collected. However, when JSAPI client code obtains a pointer to data the + * scanner does not know about, owned by an object the scanner does know about, + * Care Must Be Taken. + * + * The scanner recognizes only a select set of types: pointers to JSObjects and + * similar things (JSFunctions, and so on), pointers to JSStrings, and Values. + * So while the scanner finds all live |JSString| pointers, it does not notice + * |jschar| pointers. + * + * So suppose we have: + * + * void f(JSString *str) { + * const jschar *ch = JS_GetStringCharsZ(str); + * ... do stuff with ch, but no uses of str ...; + * } + * + * After the call to |JS_GetStringCharsZ|, there are no further uses of + * |str|, which means that the compiler is within its rights to not store + * it anywhere. But because the stack scanner will not notice |ch|, there + * is no longer any live value in this frame that would keep the string + * alive. If |str| is the last reference to that |JSString|, and the + * collector runs while we are using |ch|, the string's array of |jschar|s + * may be freed out from under us. + * + * Note that there is only an issue when 1) we extract a thing X the scanner + * doesn't recognize from 2) a thing Y the scanner does recognize, and 3) if Y + * gets garbage-collected, then X gets freed. If we have code like this: + * + * void g(JSObject *obj) { + * JS::Value x; + * JS_GetProperty(obj, "x", &x); + * ... do stuff with x ... + * } + * + * there's no problem, because the value we've extracted, x, is a Value, a + * type that the conservative scanner recognizes. + * + * Conservative GC frees us from the obligation to explicitly root the types it + * knows about, but when we work with derived values like |ch|, we must root + * their owners, as the derived value alone won't keep them alive. + * + * A JS::Anchor is a kind of GC root that allows us to keep the owners of + * derived values like |ch| alive throughout the Anchor's lifetime. We could + * fix the above code as follows: + * + * void f(JSString *str) { + * JS::Anchor a_str(str); + * const jschar *ch = JS_GetStringCharsZ(str); + * ... do stuff with ch, but no uses of str ...; + * } + * + * This simply ensures that |str| will be live until |a_str| goes out of scope. + * As long as we don't retain a pointer to the string's characters for longer + * than that, we have avoided all garbage collection hazards. + */ +template class AnchorPermitted; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; + +template +class Anchor : AnchorPermitted +{ + public: + Anchor() { } + explicit Anchor(T t) { hold = t; } + inline ~Anchor(); + + private: + T hold; + + /* + * Rooting analysis considers use of operator= to be a use of an anchor. + * For simplicity, Anchor is treated as if it contained a GC thing, from + * construction. Thus if we had + * + * void operator=(const T &t) { hold = t; } + * + * and this code + * + * JS::Anchor anchor; + * stuff that could GC, producing |str|; + * anchor = str; + * + * the last line would be seen as a hazard, because the final = would "use" + * |anchor| that is a GC thing -- which could have been moved around by the + * GC. The workaround is to structure your code so that JS::Anchor is + * always constructed, living for however long the corresponding value must + * live. + */ + void operator=(const T &t) MOZ_DELETE; + + Anchor(const Anchor &other) MOZ_DELETE; + void operator=(const Anchor &other) MOZ_DELETE; +}; + +template +inline Anchor::~Anchor() +{ +#ifdef __GNUC__ + /* + * No code is generated for this. But because this is marked 'volatile', G++ will + * assume it has important side-effects, and won't delete it. (G++ never looks at + * the actual text and notices it's empty.) And because we have passed |hold| to + * it, GCC will keep |hold| alive until this point. + * + * The "memory" clobber operand ensures that G++ will not move prior memory + * accesses after the asm --- it's a barrier. Unfortunately, it also means that + * G++ will assume that all memory has changed after the asm, as it would for a + * call to an unknown function. I don't know of a way to avoid that consequence. + */ + asm volatile("":: "g" (hold) : "memory"); +#else + /* + * An adequate portable substitute, for non-structure types. + * + * The compiler promises that, by the end of an expression statement, the + * last-stored value to a volatile object is the same as it would be in an + * unoptimized, direct implementation (the "abstract machine" whose behavior the + * language spec describes). However, the compiler is still free to reorder + * non-volatile accesses across this store --- which is what we must prevent. So + * assigning the held value to a volatile variable, as we do here, is not enough. + * + * In our case, however, garbage collection only occurs at function calls, so it + * is sufficient to ensure that the destructor's store isn't moved earlier across + * any function calls that could collect. It is hard to imagine the compiler + * analyzing the program so thoroughly that it could prove that such motion was + * safe. In practice, compilers treat calls to the collector as opaque operations + * --- in particular, as operations which could access volatile variables, across + * which this destructor must not be moved. + * + * ("Objection, your honor! *Alleged* killer whale!") + * + * The disadvantage of this approach is that it does generate code for the store. + * We do need to use Anchors in some cases where cycles are tight. + * + * Note that there is a Anchor::~Anchor() specialization in Value.h. + */ + volatile T sink; + sink = hold; +#endif /* defined(__GNUC__) */ +} + +} // namespace JS + +#endif /* js_Anchor_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/CallArgs.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/CallArgs.h new file mode 100644 index 0000000000..97a30553f0 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/CallArgs.h @@ -0,0 +1,420 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Helper classes encapsulating access to the callee, |this| value, arguments, + * and argument count for a function call. + * + * The intent of JS::CallArgs and JS::CallReceiver is that they be used to + * encapsulate access to the un-abstracted |unsigned argc, Value *vp| arguments + * to a function. It's possible (albeit deprecated) to manually index into + * |vp| to access the callee, |this|, and arguments of a function, and to set + * its return value. It's also possible to use the supported API of JS_CALLEE, + * JS_THIS, JS_ARGV, JS_RVAL and JS_SET_RVAL to the same ends. But neither API + * has the error-handling or moving-GC correctness of CallArgs or CallReceiver. + * New code should use CallArgs and CallReceiver instead whenever possible. + * + * The eventual plan is to change JSNative to take |const CallArgs&| directly, + * for automatic assertion of correct use and to make calling functions more + * efficient. Embedders should start internally switching away from using + * |argc| and |vp| directly, except to create a |CallArgs|. Then, when an + * eventual release making that change occurs, porting efforts will require + * changing methods' signatures but won't require invasive changes to the + * methods' implementations, potentially under time pressure. + */ + +#ifndef js_CallArgs_h +#define js_CallArgs_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/TypeTraits.h" + +#include "jstypes.h" + +#include "js/RootingAPI.h" +#include "js/Value.h" + +/* Typedef for native functions called by the JS VM. */ +typedef bool +(* JSNative)(JSContext *cx, unsigned argc, JS::Value *vp); + +/* Typedef for native functions that may be called in parallel. */ +typedef bool +(* JSParallelNative)(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); + +/* + * Typedef for native functions that may be called either in parallel or + * sequential execution. + */ +typedef bool +(* JSThreadSafeNative)(js::ThreadSafeContext *cx, unsigned argc, JS::Value *vp); + +/* + * Convenience wrappers for passing in ThreadSafeNative to places that expect + * a JSNative or a JSParallelNative. + */ +template +inline bool +JSNativeThreadSafeWrapper(JSContext *cx, unsigned argc, JS::Value *vp); + +template +inline bool +JSParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); + +/* + * Compute |this| for the |vp| inside a JSNative, either boxing primitives or + * replacing with the global object as necessary. + * + * This method will go away at some point: instead use |args.thisv()|. If the + * value is an object, no further work is required. If that value is |null| or + * |undefined|, use |JS_GetGlobalForObject| to compute the global object. If + * the value is some other primitive, use |JS_ValueToObject| to box it. + */ +extern JS_PUBLIC_API(JS::Value) +JS_ComputeThis(JSContext *cx, JS::Value *vp); + +namespace JS { + +extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; + +/* + * JS::CallReceiver encapsulates access to the callee, |this|, and eventual + * return value for a function call. The principal way to create a + * CallReceiver is using JS::CallReceiverFromVp: + * + * static bool + * FunctionReturningThis(JSContext *cx, unsigned argc, JS::Value *vp) + * { + * JS::CallReceiver rec = JS::CallReceiverFromVp(vp); + * + * // Access to the callee must occur before accessing/setting + * // the return value. + * JSObject &callee = rec.callee(); + * rec.rval().set(JS::ObjectValue(callee)); + * + * // callee() and calleev() will now assert. + * + * // It's always fine to access thisv(). + * HandleValue thisv = rec.thisv(); + * rec.rval().set(thisv); + * + * // As the return value was last set to |this|, returns |this|. + * return true; + * } + * + * A note on JS_ComputeThis and JS_THIS_OBJECT: these methods currently aren't + * part of the CallReceiver interface. We will likely add them at some point. + * Until then, you should probably continue using |vp| directly for these two + * cases. + * + * CallReceiver is exposed publicly and used internally. Not all parts of its + * public interface are meant to be used by embedders! See inline comments to + * for details. + */ + +namespace detail { + +#ifdef JS_DEBUG +extern JS_PUBLIC_API(void) +CheckIsValidConstructible(Value v); +#endif + +enum UsedRval { IncludeUsedRval, NoUsedRval }; + +template +class MOZ_STACK_CLASS UsedRvalBase; + +template<> +class MOZ_STACK_CLASS UsedRvalBase +{ + protected: + mutable bool usedRval_; + void setUsedRval() const { usedRval_ = true; } + void clearUsedRval() const { usedRval_ = false; } +}; + +template<> +class MOZ_STACK_CLASS UsedRvalBase +{ + protected: + void setUsedRval() const {} + void clearUsedRval() const {} +}; + +template +class MOZ_STACK_CLASS CallReceiverBase : public UsedRvalBase< +#ifdef JS_DEBUG + WantUsedRval +#else + NoUsedRval +#endif + > +{ + protected: + Value *argv_; + + public: + /* + * Returns the function being called, as an object. Must not be called + * after rval() has been used! + */ + JSObject &callee() const { + MOZ_ASSERT(!this->usedRval_); + return argv_[-2].toObject(); + } + + /* + * Returns the function being called, as a value. Must not be called after + * rval() has been used! + */ + HandleValue calleev() const { + MOZ_ASSERT(!this->usedRval_); + return HandleValue::fromMarkedLocation(&argv_[-2]); + } + + /* + * Returns the |this| value passed to the function. This method must not + * be called when the function is being called as a constructor via |new|. + * The value may or may not be an object: it is the individual function's + * responsibility to box the value if needed. + */ + HandleValue thisv() const { + // Some internal code uses thisv() in constructing cases, so don't do + // this yet. + // MOZ_ASSERT(!argv_[-1].isMagic(JS_IS_CONSTRUCTING)); + return HandleValue::fromMarkedLocation(&argv_[-1]); + } + + Value computeThis(JSContext *cx) const { + if (thisv().isObject()) + return thisv(); + + return JS_ComputeThis(cx, base()); + } + + bool isConstructing() const { +#ifdef JS_DEBUG + if (this->usedRval_) + CheckIsValidConstructible(calleev()); +#endif + return argv_[-1].isMagic(); + } + + /* + * Returns the currently-set return value. The initial contents of this + * value are unspecified. Once this method has been called, callee() and + * calleev() can no longer be used. (If you're compiling against a debug + * build of SpiderMonkey, these methods will assert to aid debugging.) + * + * If the method you're implementing succeeds by returning true, you *must* + * set this. (SpiderMonkey doesn't currently assert this, but it will do + * so eventually.) You don't need to use or change this if your method + * fails. + */ + MutableHandleValue rval() const { + this->setUsedRval(); + return MutableHandleValue::fromMarkedLocation(&argv_[-2]); + } + + public: + // These methods are only intended for internal use. Embedders shouldn't + // use them! + + Value *base() const { return argv_ - 2; } + + Value *spAfterCall() const { + this->setUsedRval(); + return argv_ - 1; + } + + public: + // These methods are publicly exposed, but they are *not* to be used when + // implementing a JSNative method and encapsulating access to |vp| within + // it. You probably don't want to use these! + + void setCallee(Value aCalleev) const { + this->clearUsedRval(); + argv_[-2] = aCalleev; + } + + void setThis(Value aThisv) const { + argv_[-1] = aThisv; + } + + MutableHandleValue mutableThisv() const { + return MutableHandleValue::fromMarkedLocation(&argv_[-1]); + } +}; + +} // namespace detail + +class MOZ_STACK_CLASS CallReceiver : public detail::CallReceiverBase +{ + private: + friend CallReceiver CallReceiverFromVp(Value *vp); + friend CallReceiver CallReceiverFromArgv(Value *argv); +}; + +MOZ_ALWAYS_INLINE CallReceiver +CallReceiverFromArgv(Value *argv) +{ + CallReceiver receiver; + receiver.clearUsedRval(); + receiver.argv_ = argv; + return receiver; +} + +MOZ_ALWAYS_INLINE CallReceiver +CallReceiverFromVp(Value *vp) +{ + return CallReceiverFromArgv(vp + 2); +} + +/* + * JS::CallArgs encapsulates everything JS::CallReceiver does, plus access to + * the function call's arguments. The principal way to create a CallArgs is + * like so, using JS::CallArgsFromVp: + * + * static bool + * FunctionReturningArgcTimesArg0(JSContext *cx, unsigned argc, JS::Value *vp) + * { + * JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + * + * // Guard against no arguments or a non-numeric arg0. + * if (args.length() == 0 || !args[0].isNumber()) { + * args.rval().setInt32(0); + * return true; + * } + * + * args.rval().set(JS::NumberValue(args.length() * args[0].toNumber())); + * return true; + * } + * + * CallArgs is exposed publicly and used internally. Not all parts of its + * public interface are meant to be used by embedders! See inline comments to + * for details. + */ +namespace detail { + +template +class MOZ_STACK_CLASS CallArgsBase : + public mozilla::Conditional >::Type +{ + protected: + unsigned argc_; + + public: + /* Returns the number of arguments. */ + unsigned length() const { return argc_; } + + /* Returns the i-th zero-indexed argument. */ + MutableHandleValue operator[](unsigned i) const { + MOZ_ASSERT(i < argc_); + return MutableHandleValue::fromMarkedLocation(&this->argv_[i]); + } + + /* + * Returns the i-th zero-indexed argument, or |undefined| if there's no + * such argument. + */ + HandleValue get(unsigned i) const { + return i < length() + ? HandleValue::fromMarkedLocation(&this->argv_[i]) + : UndefinedHandleValue; + } + + /* + * Returns true if the i-th zero-indexed argument is present and is not + * |undefined|. + */ + bool hasDefined(unsigned i) const { + return i < argc_ && !this->argv_[i].isUndefined(); + } + + public: + // These methods are publicly exposed, but we're less sure of the interface + // here than we'd like (because they're hackish and drop assertions). Try + // to avoid using these if you can. + + Value *array() const { return this->argv_; } + Value *end() const { return this->argv_ + argc_; } +}; + +} // namespace detail + +class MOZ_STACK_CLASS CallArgs : public detail::CallArgsBase +{ + private: + friend CallArgs CallArgsFromVp(unsigned argc, Value *vp); + friend CallArgs CallArgsFromSp(unsigned argc, Value *sp); + + static CallArgs create(unsigned argc, Value *argv) { + CallArgs args; + args.clearUsedRval(); + args.argv_ = argv; + args.argc_ = argc; + return args; + } + +}; + +MOZ_ALWAYS_INLINE CallArgs +CallArgsFromVp(unsigned argc, Value *vp) +{ + return CallArgs::create(argc, vp + 2); +} + +// This method is only intended for internal use in SpiderMonkey. We may +// eventually move it to an internal header. Embedders should use +// JS::CallArgsFromVp! +MOZ_ALWAYS_INLINE CallArgs +CallArgsFromSp(unsigned argc, Value *sp) +{ + return CallArgs::create(argc, sp - argc); +} + +} // namespace JS + +/* + * Macros to hide interpreter stack layout details from a JSNative using its + * JS::Value *vp parameter. DO NOT USE THESE! Instead use JS::CallArgs and + * friends, above. These macros will be removed when we change JSNative to + * take a const JS::CallArgs&. + */ + +#define JS_THIS_OBJECT(cx,vp) (JS_THIS(cx,vp).toObjectOrNull()) +#define JS_ARGV(cx,vp) ((vp) + 2) +#define JS_SET_RVAL(cx,vp,v) (*(vp) = (v)) + +/* + * Note: if this method returns null, an error has occurred and must be + * propagated or caught. + */ +MOZ_ALWAYS_INLINE JS::Value +JS_THIS(JSContext *cx, JS::Value *vp) +{ + return vp[1].isPrimitive() ? JS_ComputeThis(cx, vp) : vp[1]; +} + +/* + * |this| is passed to functions in ES5 without change. Functions themselves + * do any post-processing they desire to box |this|, compute the global object, + * &c. This macro retrieves a function's unboxed |this| value. + * + * This macro must not be used in conjunction with JS_THIS or JS_THIS_OBJECT, + * or vice versa. Either use the provided this value with this macro, or + * compute the boxed |this| value using those. JS_THIS_VALUE must not be used + * if the function is being called as a constructor. + * + * But: DO NOT USE THIS! Instead use JS::CallArgs::thisv(), above. + * + */ +#define JS_THIS_VALUE(cx,vp) ((vp)[1]) + +#endif /* js_CallArgs_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/CallNonGenericMethod.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/CallNonGenericMethod.h new file mode 100644 index 0000000000..ad9a7f708c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/CallNonGenericMethod.h @@ -0,0 +1,117 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_CallNonGenericMethod_h +#define js_CallNonGenericMethod_h + +#include "jstypes.h" + +#include "js/CallArgs.h" + +namespace JS { + +// Returns true if |v| is considered an acceptable this-value. +typedef bool (*IsAcceptableThis)(HandleValue v); + +// Implements the guts of a method; guaranteed to be provided an acceptable +// this-value, as determined by a corresponding IsAcceptableThis method. +typedef bool (*NativeImpl)(JSContext *cx, CallArgs args); + +namespace detail { + +// DON'T CALL THIS DIRECTLY. It's for use only by CallNonGenericMethod! +extern JS_PUBLIC_API(bool) +CallMethodIfWrapped(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args); + +} // namespace detail + +// Methods usually act upon |this| objects only from a single global object and +// compartment. Sometimes, however, a method must act upon |this| values from +// multiple global objects or compartments. In such cases the |this| value a +// method might see will be wrapped, such that various access to the object -- +// to its class, its private data, its reserved slots, and so on -- will not +// work properly without entering that object's compartment. This method +// implements a solution to this problem. +// +// To implement a method that accepts |this| values from multiple compartments, +// define two functions. The first function matches the IsAcceptableThis type +// and indicates whether the provided value is an acceptable |this| for the +// method; it must be a pure function only of its argument. +// +// static const JSClass AnswerClass = { ... }; +// +// static bool +// IsAnswerObject(const Value &v) +// { +// if (!v.isObject()) +// return false; +// return JS_GetClass(&v.toObject()) == &AnswerClass; +// } +// +// The second function implements the NativeImpl signature and defines the +// behavior of the method when it is provided an acceptable |this| value. +// Aside from some typing niceties -- see the CallArgs interface for details -- +// its interface is the same as that of JSNative. +// +// static bool +// answer_getAnswer_impl(JSContext *cx, JS::CallArgs args) +// { +// args.rval().setInt32(42); +// return true; +// } +// +// The implementation function is guaranteed to be called *only* with a |this| +// value which is considered acceptable. +// +// Now to implement the actual method, write a JSNative that calls the method +// declared below, passing the appropriate template and runtime arguments. +// +// static bool +// answer_getAnswer(JSContext *cx, unsigned argc, JS::Value *vp) +// { +// JS::CallArgs args = JS::CallArgsFromVp(argc, vp); +// return JS::CallNonGenericMethod(cx, args); +// } +// +// Note that, because they are used as template arguments, the predicate +// and implementation functions must have external linkage. (This is +// unfortunate, but GCC wasn't inlining things as one would hope when we +// passed them as function arguments.) +// +// JS::CallNonGenericMethod will test whether |args.thisv()| is acceptable. If +// it is, it will call the provided implementation function, which will return +// a value and indicate success. If it is not, it will attempt to unwrap +// |this| and call the implementation function on the unwrapped |this|. If +// that succeeds, all well and good. If it doesn't succeed, a TypeError will +// be thrown. +// +// Note: JS::CallNonGenericMethod will only work correctly if it's called in +// tail position in a JSNative. Do not call it from any other place. +// +template +MOZ_ALWAYS_INLINE bool +CallNonGenericMethod(JSContext *cx, CallArgs args) +{ + HandleValue thisv = args.thisv(); + if (Test(thisv)) + return Impl(cx, args); + + return detail::CallMethodIfWrapped(cx, Test, Impl, args); +} + +MOZ_ALWAYS_INLINE bool +CallNonGenericMethod(JSContext *cx, IsAcceptableThis Test, NativeImpl Impl, CallArgs args) +{ + HandleValue thisv = args.thisv(); + if (Test(thisv)) + return Impl(cx, args); + + return detail::CallMethodIfWrapped(cx, Test, Impl, args); +} + +} // namespace JS + +#endif /* js_CallNonGenericMethod_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/CharacterEncoding.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/CharacterEncoding.h new file mode 100644 index 0000000000..45c77761b3 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/CharacterEncoding.h @@ -0,0 +1,226 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_CharacterEncoding_h +#define js_CharacterEncoding_h + +#include "mozilla/NullPtr.h" +#include "mozilla/Range.h" + +#include "js/TypeDecls.h" +#include "js/Utility.h" + +namespace js { +struct ThreadSafeContext; +} + +class JSFlatString; + +namespace JS { + +/* + * By default, all C/C++ 1-byte-per-character strings passed into the JSAPI + * are treated as ISO/IEC 8859-1, also known as Latin-1. That is, each + * byte is treated as a 2-byte character, and there is no way to pass in a + * string containing characters beyond U+00FF. + */ +class Latin1Chars : public mozilla::Range +{ + typedef mozilla::Range Base; + + public: + Latin1Chars() : Base() {} + Latin1Chars(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) {} + Latin1Chars(const Latin1Char *aBytes, size_t aLength) + : Base(const_cast(aBytes), aLength) + {} + Latin1Chars(const char *aBytes, size_t aLength) + : Base(reinterpret_cast(const_cast(aBytes)), aLength) + {} +}; + +/* + * A Latin1Chars, but with \0 termination for C compatibility. + */ +class Latin1CharsZ : public mozilla::RangedPtr +{ + typedef mozilla::RangedPtr Base; + + public: + Latin1CharsZ() : Base(nullptr, 0) {} + + Latin1CharsZ(char *aBytes, size_t aLength) + : Base(reinterpret_cast(aBytes), aLength) + { + MOZ_ASSERT(aBytes[aLength] == '\0'); + } + + Latin1CharsZ(Latin1Char *aBytes, size_t aLength) + : Base(aBytes, aLength) + { + MOZ_ASSERT(aBytes[aLength] == '\0'); + } + + using Base::operator=; + + char *c_str() { return reinterpret_cast(get()); } +}; + +class UTF8Chars : public mozilla::Range +{ + typedef mozilla::Range Base; + + public: + UTF8Chars() : Base() {} + UTF8Chars(char *aBytes, size_t aLength) + : Base(reinterpret_cast(aBytes), aLength) + {} + UTF8Chars(const char *aBytes, size_t aLength) + : Base(reinterpret_cast(const_cast(aBytes)), aLength) + {} +}; + +/* + * SpiderMonkey also deals directly with UTF-8 encoded text in some places. + */ +class UTF8CharsZ : public mozilla::RangedPtr +{ + typedef mozilla::RangedPtr Base; + + public: + UTF8CharsZ() : Base(nullptr, 0) {} + + UTF8CharsZ(char *aBytes, size_t aLength) + : Base(reinterpret_cast(aBytes), aLength) + { + MOZ_ASSERT(aBytes[aLength] == '\0'); + } + + UTF8CharsZ(unsigned char *aBytes, size_t aLength) + : Base(aBytes, aLength) + { + MOZ_ASSERT(aBytes[aLength] == '\0'); + } + + using Base::operator=; + + char *c_str() { return reinterpret_cast(get()); } +}; + +/* + * SpiderMonkey uses a 2-byte character representation: it is a + * 2-byte-at-a-time view of a UTF-16 byte stream. This is similar to UCS-2, + * but unlike UCS-2, we do not strip UTF-16 extension bytes. This allows a + * sufficiently dedicated JavaScript program to be fully unicode-aware by + * manually interpreting UTF-16 extension characters embedded in the JS + * string. + */ +class TwoByteChars : public mozilla::Range +{ + typedef mozilla::Range Base; + + public: + TwoByteChars() : Base() {} + TwoByteChars(jschar *aChars, size_t aLength) : Base(aChars, aLength) {} + TwoByteChars(const jschar *aChars, size_t aLength) : Base(const_cast(aChars), aLength) {} +}; + +/* + * A TwoByteChars, but \0 terminated for compatibility with JSFlatString. + */ +class TwoByteCharsZ : public mozilla::RangedPtr +{ + typedef mozilla::RangedPtr Base; + + public: + TwoByteCharsZ() : Base(nullptr, 0) {} + + TwoByteCharsZ(jschar *chars, size_t length) + : Base(chars, length) + { + MOZ_ASSERT(chars[length] == '\0'); + } + + using Base::operator=; +}; + +typedef mozilla::RangedPtr ConstCharPtr; + +/* + * Like TwoByteChars, but the chars are const. + */ +class ConstTwoByteChars : public mozilla::RangedPtr +{ + public: + ConstTwoByteChars(const ConstTwoByteChars &s) : ConstCharPtr(s) {} + MOZ_IMPLICIT ConstTwoByteChars(const mozilla::RangedPtr &s) : ConstCharPtr(s) {} + ConstTwoByteChars(const jschar *s, size_t len) : ConstCharPtr(s, len) {} + ConstTwoByteChars(const jschar *pos, const jschar *start, size_t len) + : ConstCharPtr(pos, start, len) + {} + + using ConstCharPtr::operator=; +}; + + +/* + * Convert a 2-byte character sequence to "ISO-Latin-1". This works by + * truncating each 2-byte pair in the sequence to a 1-byte pair. If the source + * contains any UTF-16 extension characters, then this may give invalid Latin1 + * output. The returned string is zero terminated. The returned string or the + * returned string's |start()| must be freed with JS_free or js_free, + * respectively. If allocation fails, an OOM error will be set and the method + * will return a nullptr chars (which can be tested for with the ! operator). + * This method cannot trigger GC. + */ +extern Latin1CharsZ +LossyTwoByteCharsToNewLatin1CharsZ(js::ThreadSafeContext *cx, + const mozilla::Range tbchars); + +template +extern UTF8CharsZ +CharsToNewUTF8CharsZ(js::ThreadSafeContext *cx, const mozilla::Range chars); + +uint32_t +Utf8ToOneUcs4Char(const uint8_t *utf8Buffer, int utf8Length); + +/* + * Inflate bytes in UTF-8 encoding to jschars. + * - On error, returns an empty TwoByteCharsZ. + * - On success, returns a malloc'd TwoByteCharsZ, and updates |outlen| to hold + * its length; the length value excludes the trailing null. + */ +extern TwoByteCharsZ +UTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen); + +/* + * The same as UTF8CharsToNewTwoByteCharsZ(), except that any malformed UTF-8 characters + * will be replaced by \uFFFD. No exception will be thrown for malformed UTF-8 + * input. + */ +extern TwoByteCharsZ +LossyUTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen); + +/* + * Returns the length of the char buffer required to encode |s| as UTF8. + * Does not include the null-terminator. + */ +JS_PUBLIC_API(size_t) +GetDeflatedUTF8StringLength(JSFlatString *s); + +/* + * Encode |src| as UTF8. The caller must ensure |dst| has enough space. + * Does not write the null terminator. + */ +JS_PUBLIC_API(void) +DeflateStringToUTF8Buffer(JSFlatString *src, mozilla::RangedPtr dst); + +} // namespace JS + +inline void JS_free(JS::Latin1CharsZ &ptr) { js_free((void*)ptr.get()); } +inline void JS_free(JS::UTF8CharsZ &ptr) { js_free((void*)ptr.get()); } + +#endif /* js_CharacterEncoding_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Class.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Class.h new file mode 100644 index 0000000000..559cc65c85 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Class.h @@ -0,0 +1,544 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JSClass definition and its component types, plus related interfaces. */ + +#ifndef js_Class_h +#define js_Class_h + +#include "mozilla/NullPtr.h" + +#include "jstypes.h" + +#include "js/CallArgs.h" +#include "js/Id.h" +#include "js/TypeDecls.h" + +/* + * A JSClass acts as a vtable for JS objects that allows JSAPI clients to + * control various aspects of the behavior of an object like property lookup. + * js::Class is an engine-private extension that allows more control over + * object behavior and, e.g., allows custom slow layout. + */ + +struct JSFreeOp; +struct JSFunctionSpec; + +namespace js { + +struct Class; +class FreeOp; +class PropertyName; +class Shape; + +// This is equal to JSFunction::class_. Use it in places where you don't want +// to #include jsfun.h. +extern JS_FRIEND_DATA(const js::Class* const) FunctionClassPtr; + +} // namespace js + +// JSClass operation signatures. + +// Add or get a property named by id in obj. Note the jsid id type -- id may +// be a string (Unicode property identifier) or an int (element index). The +// *vp out parameter, on success, is the new property value after the action. +typedef bool +(* JSPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); + +// Set a property named by id in obj, treating the assignment as strict +// mode code if strict is true. Note the jsid id type -- id may be a string +// (Unicode property identifier) or an int (element index). The *vp out +// parameter, on success, is the new property value after the +// set. +typedef bool +(* JSStrictPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool strict, JS::MutableHandleValue vp); + +// Delete a property named by id in obj. +// +// If an error occurred, return false as per normal JSAPI error practice. +// +// If no error occurred, but the deletion attempt wasn't allowed (perhaps +// because the property was non-configurable), set *succeeded to false and +// return true. This will cause |delete obj[id]| to evaluate to false in +// non-strict mode code, and to throw a TypeError in strict mode code. +// +// If no error occurred and the deletion wasn't disallowed (this is *not* the +// same as saying that a deletion actually occurred -- deleting a non-existent +// property, or an inherited property, is allowed -- it's just pointless), +// set *succeeded to true and return true. +typedef bool +(* JSDeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *succeeded); + +// This function type is used for callbacks that enumerate the properties of +// a JSObject. The behavior depends on the value of enum_op: +// +// JSENUMERATE_INIT +// A new, opaque iterator state should be allocated and stored in *statep. +// (You can use PRIVATE_TO_JSVAL() to tag the pointer to be stored). +// +// The number of properties that will be enumerated should be returned as +// an integer jsval in *idp, if idp is non-null, and provided the number of +// enumerable properties is known. If idp is non-null and the number of +// enumerable properties can't be computed in advance, *idp should be set +// to JSVAL_ZERO. +// +// JSENUMERATE_INIT_ALL +// Used identically to JSENUMERATE_INIT, but exposes all properties of the +// object regardless of enumerability. +// +// JSENUMERATE_NEXT +// A previously allocated opaque iterator state is passed in via statep. +// Return the next jsid in the iteration using *idp. The opaque iterator +// state pointed at by statep is destroyed and *statep is set to JSVAL_NULL +// if there are no properties left to enumerate. +// +// JSENUMERATE_DESTROY +// Destroy the opaque iterator state previously allocated in *statep by a +// call to this function when enum_op was JSENUMERATE_INIT or +// JSENUMERATE_INIT_ALL. +// +// The return value is used to indicate success, with a value of false +// indicating failure. +typedef bool +(* JSNewEnumerateOp)(JSContext *cx, JS::HandleObject obj, JSIterateOp enum_op, + JS::MutableHandleValue statep, JS::MutableHandleId idp); + +// The old-style JSClass.enumerate op should define all lazy properties not +// yet reflected in obj. +typedef bool +(* JSEnumerateOp)(JSContext *cx, JS::HandleObject obj); + +// Resolve a lazy property named by id in obj by defining it directly in obj. +// Lazy properties are those reflected from some peer native property space +// (e.g., the DOM attributes for a given node reflected as obj) on demand. +// +// JS looks for a property in an object, and if not found, tries to resolve +// the given id. If resolve succeeds, the engine looks again in case resolve +// defined obj[id]. If no such property exists directly in obj, the process +// is repeated with obj's prototype, etc. +// +// NB: JSNewResolveOp provides a cheaper way to resolve lazy properties. +typedef bool +(* JSResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); + +// Like JSResolveOp, except the *objp out parameter, on success, should be null +// to indicate that id was not resolved; and non-null, referring to obj or one +// of its prototypes, if id was resolved. The hook may assume *objp is null on +// entry. +// +// This hook instead of JSResolveOp is called via the JSClass.resolve member +// if JSCLASS_NEW_RESOLVE is set in JSClass.flags. +typedef bool +(* JSNewResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleObject objp); + +// Convert obj to the given type, returning true with the resulting value in +// *vp on success, and returning false on error or exception. +typedef bool +(* JSConvertOp)(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); + +// Finalize obj, which the garbage collector has determined to be unreachable +// from other live objects or from GC roots. Obviously, finalizers must never +// store a reference to obj. +typedef void +(* JSFinalizeOp)(JSFreeOp *fop, JSObject *obj); + +// Finalizes external strings created by JS_NewExternalString. +struct JSStringFinalizer { + void (*finalize)(const JSStringFinalizer *fin, jschar *chars); +}; + +// Check whether v is an instance of obj. Return false on error or exception, +// true on success with true in *bp if v is an instance of obj, false in +// *bp otherwise. +typedef bool +(* JSHasInstanceOp)(JSContext *cx, JS::HandleObject obj, JS::MutableHandleValue vp, + bool *bp); + +// Function type for trace operation of the class called to enumerate all +// traceable things reachable from obj's private data structure. For each such +// thing, a trace implementation must call one of the JS_Call*Tracer variants +// on the thing. +// +// JSTraceOp implementation can assume that no other threads mutates object +// state. It must not change state of the object or corresponding native +// structures. The only exception for this rule is the case when the embedding +// needs a tight integration with GC. In that case the embedding can check if +// the traversal is a part of the marking phase through calling +// JS_IsGCMarkingTracer and apply a special code like emptying caches or +// marking its native structures. +typedef void +(* JSTraceOp)(JSTracer *trc, JSObject *obj); + +// Hook that creates an iterator object for a given object. Returns the +// iterator object or null if an error or exception was thrown on cx. +typedef JSObject * +(* JSIteratorOp)(JSContext *cx, JS::HandleObject obj, bool keysonly); + +typedef JSObject * +(* JSWeakmapKeyDelegateOp)(JSObject *obj); + +/* js::Class operation signatures. */ + +namespace js { + +typedef bool +(* LookupGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleObject objp, JS::MutableHandle propp); +typedef bool +(* LookupPropOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleObject objp, JS::MutableHandle propp); +typedef bool +(* LookupElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::MutableHandleObject objp, JS::MutableHandle propp); +typedef bool +(* DefineGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +typedef bool +(* DefinePropOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, + unsigned attrs); +typedef bool +(* DefineElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +typedef bool +(* GenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, + JS::MutableHandleValue vp); +typedef bool +(* PropertyIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, + JS::Handle name, JS::MutableHandleValue vp); +typedef bool +(* ElementIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, + JS::MutableHandleValue vp); +typedef bool +(* StrictGenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp, bool strict); +typedef bool +(* StrictPropertyIdOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleValue vp, bool strict); +typedef bool +(* StrictElementIdOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::MutableHandleValue vp, bool strict); +typedef bool +(* GenericAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +typedef bool +(* PropertyAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, + unsigned *attrsp); +typedef bool +(* DeleteGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); + +typedef bool +(* WatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); + +typedef bool +(* UnwatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); + +typedef bool +(* SliceOp)(JSContext *cx, JS::HandleObject obj, uint32_t begin, uint32_t end, + JS::HandleObject result); // result is actually preallocted. + +// A generic type for functions mapping an object to another object, or null +// if an error or exception was thrown on cx. +typedef JSObject * +(* ObjectOp)(JSContext *cx, JS::HandleObject obj); + +// Hook to map an object to its inner object. Infallible. +typedef JSObject * +(* InnerObjectOp)(JSObject *obj); + +typedef void +(* FinalizeOp)(FreeOp *fop, JSObject *obj); + +#define JS_CLASS_MEMBERS(FinalizeOpType) \ + const char *name; \ + uint32_t flags; \ + \ + /* Mandatory function pointer members. */ \ + JSPropertyOp addProperty; \ + JSDeletePropertyOp delProperty; \ + JSPropertyOp getProperty; \ + JSStrictPropertyOp setProperty; \ + JSEnumerateOp enumerate; \ + JSResolveOp resolve; \ + JSConvertOp convert; \ + \ + /* Optional members (may be null). */ \ + FinalizeOpType finalize; \ + JSNative call; \ + JSHasInstanceOp hasInstance; \ + JSNative construct; \ + JSTraceOp trace + +// Callback for the creation of constructor and prototype objects. +typedef JSObject *(*ClassObjectCreationOp)(JSContext *cx, JSProtoKey key); + +// Callback for custom post-processing after class initialization via ClassSpec. +typedef bool (*FinishClassInitOp)(JSContext *cx, JS::HandleObject ctor, + JS::HandleObject proto); + +struct ClassSpec +{ + ClassObjectCreationOp createConstructor; + ClassObjectCreationOp createPrototype; + const JSFunctionSpec *constructorFunctions; + const JSFunctionSpec *prototypeFunctions; + const JSPropertySpec *prototypeProperties; + FinishClassInitOp finishInit; + bool defined() const { return !!createConstructor; } +}; + +struct ClassExtension +{ + ObjectOp outerObject; + InnerObjectOp innerObject; + JSIteratorOp iteratorObject; + + /* + * isWrappedNative is true only if the class is an XPCWrappedNative. + * WeakMaps use this to override the wrapper disposal optimization. + */ + bool isWrappedNative; + + /* + * If an object is used as a key in a weakmap, it may be desirable for the + * garbage collector to keep that object around longer than it otherwise + * would. A common case is when the key is a wrapper around an object in + * another compartment, and we want to avoid collecting the wrapper (and + * removing the weakmap entry) as long as the wrapped object is alive. In + * that case, the wrapped object is returned by the wrapper's + * weakmapKeyDelegateOp hook. As long as the wrapper is used as a weakmap + * key, it will not be collected (and remain in the weakmap) until the + * wrapped object is collected. + */ + JSWeakmapKeyDelegateOp weakmapKeyDelegateOp; +}; + +#define JS_NULL_CLASS_SPEC {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr} +#define JS_NULL_CLASS_EXT {nullptr,nullptr,nullptr,false,nullptr} + +struct ObjectOps +{ + LookupGenericOp lookupGeneric; + LookupPropOp lookupProperty; + LookupElementOp lookupElement; + DefineGenericOp defineGeneric; + DefinePropOp defineProperty; + DefineElementOp defineElement; + GenericIdOp getGeneric; + PropertyIdOp getProperty; + ElementIdOp getElement; + StrictGenericIdOp setGeneric; + StrictPropertyIdOp setProperty; + StrictElementIdOp setElement; + GenericAttributesOp getGenericAttributes; + GenericAttributesOp setGenericAttributes; + DeleteGenericOp deleteGeneric; + WatchOp watch; + UnwatchOp unwatch; + SliceOp slice; // Optimized slice, can be null. + JSNewEnumerateOp enumerate; + ObjectOp thisObject; +}; + +#define JS_NULL_OBJECT_OPS \ + {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr} + +} // namespace js + +// Classes, objects, and properties. + +typedef void (*JSClassInternal)(); + +struct JSClass { + JS_CLASS_MEMBERS(JSFinalizeOp); + + void *reserved[31]; +}; + +#define JSCLASS_HAS_PRIVATE (1<<0) // objects have private slot +#define JSCLASS_NEW_ENUMERATE (1<<1) // has JSNewEnumerateOp hook +#define JSCLASS_NEW_RESOLVE (1<<2) // has JSNewResolveOp hook +#define JSCLASS_PRIVATE_IS_NSISUPPORTS (1<<3) // private is (nsISupports *) +#define JSCLASS_IS_DOMJSCLASS (1<<4) // objects are DOM +#define JSCLASS_IMPLEMENTS_BARRIERS (1<<5) // Correctly implements GC read + // and write barriers +#define JSCLASS_EMULATES_UNDEFINED (1<<6) // objects of this class act + // like the value undefined, + // in some contexts +#define JSCLASS_USERBIT1 (1<<7) // Reserved for embeddings. + +// To reserve slots fetched and stored via JS_Get/SetReservedSlot, bitwise-or +// JSCLASS_HAS_RESERVED_SLOTS(n) into the initializer for JSClass.flags, where +// n is a constant in [1, 255]. Reserved slots are indexed from 0 to n-1. +#define JSCLASS_RESERVED_SLOTS_SHIFT 8 // room for 8 flags below */ +#define JSCLASS_RESERVED_SLOTS_WIDTH 8 // and 16 above this field */ +#define JSCLASS_RESERVED_SLOTS_MASK JS_BITMASK(JSCLASS_RESERVED_SLOTS_WIDTH) +#define JSCLASS_HAS_RESERVED_SLOTS(n) (((n) & JSCLASS_RESERVED_SLOTS_MASK) \ + << JSCLASS_RESERVED_SLOTS_SHIFT) +#define JSCLASS_RESERVED_SLOTS(clasp) (((clasp)->flags \ + >> JSCLASS_RESERVED_SLOTS_SHIFT) \ + & JSCLASS_RESERVED_SLOTS_MASK) + +#define JSCLASS_HIGH_FLAGS_SHIFT (JSCLASS_RESERVED_SLOTS_SHIFT + \ + JSCLASS_RESERVED_SLOTS_WIDTH) + +#define JSCLASS_IS_ANONYMOUS (1<<(JSCLASS_HIGH_FLAGS_SHIFT+0)) +#define JSCLASS_IS_GLOBAL (1<<(JSCLASS_HIGH_FLAGS_SHIFT+1)) +#define JSCLASS_INTERNAL_FLAG2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2)) +#define JSCLASS_INTERNAL_FLAG3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3)) + +#define JSCLASS_IS_PROXY (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4)) + +// Bit 22 unused. + +// Reserved for embeddings. +#define JSCLASS_USERBIT2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+6)) +#define JSCLASS_USERBIT3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+7)) + +#define JSCLASS_BACKGROUND_FINALIZE (1<<(JSCLASS_HIGH_FLAGS_SHIFT+8)) + +// Bits 26 through 31 are reserved for the CACHED_PROTO_KEY mechanism, see +// below. + +// ECMA-262 requires that most constructors used internally create objects +// with "the original Foo.prototype value" as their [[Prototype]] (__proto__) +// member initial value. The "original ... value" verbiage is there because +// in ECMA-262, global properties naming class objects are read/write and +// deleteable, for the most part. +// +// Implementing this efficiently requires that global objects have classes +// with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS was +// previously allowed, but is now an ES5 violation and thus unsupported. +// +// JSCLASS_GLOBAL_APPLICATION_SLOTS is the number of slots reserved at +// the beginning of every global object's slots for use by the +// application. +#define JSCLASS_GLOBAL_APPLICATION_SLOTS 3 +#define JSCLASS_GLOBAL_SLOT_COUNT (JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 3 + 30) +#define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n) \ + (JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + (n))) +#define JSCLASS_GLOBAL_FLAGS \ + JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(0) +#define JSCLASS_HAS_GLOBAL_FLAG_AND_SLOTS(clasp) \ + (((clasp)->flags & JSCLASS_IS_GLOBAL) \ + && JSCLASS_RESERVED_SLOTS(clasp) >= JSCLASS_GLOBAL_SLOT_COUNT) + +// Fast access to the original value of each standard class's prototype. +#define JSCLASS_CACHED_PROTO_SHIFT (JSCLASS_HIGH_FLAGS_SHIFT + 10) +#define JSCLASS_CACHED_PROTO_WIDTH 6 +#define JSCLASS_CACHED_PROTO_MASK JS_BITMASK(JSCLASS_CACHED_PROTO_WIDTH) +#define JSCLASS_HAS_CACHED_PROTO(key) (uint32_t(key) << JSCLASS_CACHED_PROTO_SHIFT) +#define JSCLASS_CACHED_PROTO_KEY(clasp) ((JSProtoKey) \ + (((clasp)->flags \ + >> JSCLASS_CACHED_PROTO_SHIFT) \ + & JSCLASS_CACHED_PROTO_MASK)) + +// Initializer for unused members of statically initialized JSClass structs. +#define JSCLASS_NO_INTERNAL_MEMBERS {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} +#define JSCLASS_NO_OPTIONAL_MEMBERS 0,0,0,0,0,JSCLASS_NO_INTERNAL_MEMBERS + +namespace js { + +struct Class +{ + JS_CLASS_MEMBERS(FinalizeOp); + ClassSpec spec; + ClassExtension ext; + ObjectOps ops; + + /* Class is not native and its map is not a scope. */ + static const uint32_t NON_NATIVE = JSCLASS_INTERNAL_FLAG2; + + bool isNative() const { + return !(flags & NON_NATIVE); + } + + bool hasPrivate() const { + return !!(flags & JSCLASS_HAS_PRIVATE); + } + + bool emulatesUndefined() const { + return flags & JSCLASS_EMULATES_UNDEFINED; + } + + bool isJSFunction() const { + return this == js::FunctionClassPtr; + } + + bool isCallable() const { + return isJSFunction() || call; + } + + bool isProxy() const { + return flags & JSCLASS_IS_PROXY; + } + + bool isDOMClass() const { + return flags & JSCLASS_IS_DOMJSCLASS; + } + + static size_t offsetOfFlags() { return offsetof(Class, flags); } +}; + +JS_STATIC_ASSERT(offsetof(JSClass, name) == offsetof(Class, name)); +JS_STATIC_ASSERT(offsetof(JSClass, flags) == offsetof(Class, flags)); +JS_STATIC_ASSERT(offsetof(JSClass, addProperty) == offsetof(Class, addProperty)); +JS_STATIC_ASSERT(offsetof(JSClass, delProperty) == offsetof(Class, delProperty)); +JS_STATIC_ASSERT(offsetof(JSClass, getProperty) == offsetof(Class, getProperty)); +JS_STATIC_ASSERT(offsetof(JSClass, setProperty) == offsetof(Class, setProperty)); +JS_STATIC_ASSERT(offsetof(JSClass, enumerate) == offsetof(Class, enumerate)); +JS_STATIC_ASSERT(offsetof(JSClass, resolve) == offsetof(Class, resolve)); +JS_STATIC_ASSERT(offsetof(JSClass, convert) == offsetof(Class, convert)); +JS_STATIC_ASSERT(offsetof(JSClass, finalize) == offsetof(Class, finalize)); +JS_STATIC_ASSERT(offsetof(JSClass, call) == offsetof(Class, call)); +JS_STATIC_ASSERT(offsetof(JSClass, construct) == offsetof(Class, construct)); +JS_STATIC_ASSERT(offsetof(JSClass, hasInstance) == offsetof(Class, hasInstance)); +JS_STATIC_ASSERT(offsetof(JSClass, trace) == offsetof(Class, trace)); +JS_STATIC_ASSERT(sizeof(JSClass) == sizeof(Class)); + +static MOZ_ALWAYS_INLINE const JSClass * +Jsvalify(const Class *c) +{ + return (const JSClass *)c; +} + +static MOZ_ALWAYS_INLINE const Class * +Valueify(const JSClass *c) +{ + return (const Class *)c; +} + +/* + * Enumeration describing possible values of the [[Class]] internal property + * value of objects. + */ +enum ESClassValue { + ESClass_Array, ESClass_Number, ESClass_String, ESClass_Boolean, + ESClass_RegExp, ESClass_ArrayBuffer, ESClass_Date +}; + +/* + * Return whether the given object has the given [[Class]] internal property + * value. Beware, this query says nothing about the js::Class of the JSObject + * so the caller must not assume anything about obj's representation (e.g., obj + * may be a proxy). + */ +inline bool +ObjectClassIs(JSObject &obj, ESClassValue classValue, JSContext *cx); + +/* Just a helper that checks v.isObject before calling ObjectClassIs. */ +inline bool +IsObjectWithClass(const JS::Value &v, ESClassValue classValue, JSContext *cx); + +} /* namespace js */ + +#endif /* js_Class_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Date.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Date.h new file mode 100644 index 0000000000..6199f9eca5 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Date.h @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_Date_h +#define js_Date_h + +#include "jstypes.h" + +namespace JS { + +// Year is a year, month is 0-11, day is 1-based. The return value is +// a number of milliseconds since the epoch. Can return NaN. +JS_PUBLIC_API(double) +MakeDate(double year, unsigned month, unsigned day); + +// Takes an integer number of milliseconds since the epoch and returns the +// year. Can return NaN, and will do so if NaN is passed in. +JS_PUBLIC_API(double) +YearFromTime(double time); + +// Takes an integer number of milliseconds since the epoch and returns the +// month (0-11). Can return NaN, and will do so if NaN is passed in. +JS_PUBLIC_API(double) +MonthFromTime(double time); + +// Takes an integer number of milliseconds since the epoch and returns the +// day (1-based). Can return NaN, and will do so if NaN is passed in. +JS_PUBLIC_API(double) +DayFromTime(double time); + +} // namespace JS + +#endif /* js_Date_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/GCAPI.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/GCAPI.h new file mode 100644 index 0000000000..c58d62d029 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/GCAPI.h @@ -0,0 +1,514 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_GCAPI_h +#define js_GCAPI_h + +#include "mozilla/NullPtr.h" + +#include "js/HeapAPI.h" + +namespace js { +namespace gc { +class GCRuntime; +} +} + +typedef enum JSGCMode { + /* Perform only global GCs. */ + JSGC_MODE_GLOBAL = 0, + + /* Perform per-compartment GCs until too much garbage has accumulated. */ + JSGC_MODE_COMPARTMENT = 1, + + /* + * Collect in short time slices rather than all at once. Implies + * JSGC_MODE_COMPARTMENT. + */ + JSGC_MODE_INCREMENTAL = 2 +} JSGCMode; + +namespace JS { + +#define GCREASONS(D) \ + /* Reasons internal to the JS engine */ \ + D(API) \ + D(MAYBEGC) \ + D(DESTROY_RUNTIME) \ + D(DESTROY_CONTEXT) \ + D(LAST_DITCH) \ + D(TOO_MUCH_MALLOC) \ + D(ALLOC_TRIGGER) \ + D(DEBUG_GC) \ + D(TRANSPLANT) \ + D(RESET) \ + D(OUT_OF_NURSERY) \ + D(EVICT_NURSERY) \ + D(FULL_STORE_BUFFER) \ + \ + /* These are reserved for future use. */ \ + D(RESERVED0) \ + D(RESERVED1) \ + D(RESERVED2) \ + D(RESERVED3) \ + D(RESERVED4) \ + D(RESERVED5) \ + D(RESERVED6) \ + D(RESERVED7) \ + D(RESERVED8) \ + D(RESERVED9) \ + D(RESERVED10) \ + D(RESERVED11) \ + D(RESERVED12) \ + D(RESERVED13) \ + D(RESERVED14) \ + D(RESERVED15) \ + D(RESERVED16) \ + D(RESERVED17) \ + D(RESERVED18) \ + D(RESERVED19) \ + \ + /* Reasons from Firefox */ \ + D(DOM_WINDOW_UTILS) \ + D(COMPONENT_UTILS) \ + D(MEM_PRESSURE) \ + D(CC_WAITING) \ + D(CC_FORCED) \ + D(LOAD_END) \ + D(POST_COMPARTMENT) \ + D(PAGE_HIDE) \ + D(NSJSCONTEXT_DESTROY) \ + D(SET_NEW_DOCUMENT) \ + D(SET_DOC_SHELL) \ + D(DOM_UTILS) \ + D(DOM_IPC) \ + D(DOM_WORKER) \ + D(INTER_SLICE_GC) \ + D(REFRESH_FRAME) \ + D(FULL_GC_TIMER) \ + D(SHUTDOWN_CC) \ + D(FINISH_LARGE_EVALUTE) + +namespace gcreason { + +/* GCReasons will end up looking like JSGC_MAYBEGC */ +enum Reason { +#define MAKE_REASON(name) name, + GCREASONS(MAKE_REASON) +#undef MAKE_REASON + NO_REASON, + NUM_REASONS, + + /* + * For telemetry, we want to keep a fixed max bucket size over time so we + * don't have to switch histograms. 100 is conservative; as of this writing + * there are 26. But the cost of extra buckets seems to be low while the + * cost of switching histograms is high. + */ + NUM_TELEMETRY_REASONS = 100 +}; + +} /* namespace gcreason */ + +/* + * Zone GC: + * + * SpiderMonkey's GC is capable of performing a collection on an arbitrary + * subset of the zones in the system. This allows an embedding to minimize + * collection time by only collecting zones that have run code recently, + * ignoring the parts of the heap that are unlikely to have changed. + * + * When triggering a GC using one of the functions below, it is first necessary + * to select the zones to be collected. To do this, you can call + * PrepareZoneForGC on each zone, or you can call PrepareForFullGC to select + * all zones. Failing to select any zone is an error. + */ + +/* + * Schedule the given zone to be collected as part of the next GC. + */ +extern JS_FRIEND_API(void) +PrepareZoneForGC(Zone *zone); + +/* + * Schedule all zones to be collected in the next GC. + */ +extern JS_FRIEND_API(void) +PrepareForFullGC(JSRuntime *rt); + +/* + * When performing an incremental GC, the zones that were selected for the + * previous incremental slice must be selected in subsequent slices as well. + * This function selects those slices automatically. + */ +extern JS_FRIEND_API(void) +PrepareForIncrementalGC(JSRuntime *rt); + +/* + * Returns true if any zone in the system has been scheduled for GC with one of + * the functions above or by the JS engine. + */ +extern JS_FRIEND_API(bool) +IsGCScheduled(JSRuntime *rt); + +/* + * Undoes the effect of the Prepare methods above. The given zone will not be + * collected in the next GC. + */ +extern JS_FRIEND_API(void) +SkipZoneForGC(Zone *zone); + +/* + * Non-Incremental GC: + * + * The following functions perform a non-incremental GC. + */ + +/* + * Performs a non-incremental collection of all selected zones. Some objects + * that are unreachable from the program may still be alive afterwards because + * of internal references. + */ +extern JS_FRIEND_API(void) +GCForReason(JSRuntime *rt, gcreason::Reason reason); + +/* + * Perform a non-incremental collection after clearing caches and other + * temporary references to objects. This will remove all unreferenced objects + * in the system. + */ +extern JS_FRIEND_API(void) +ShrinkingGC(JSRuntime *rt, gcreason::Reason reason); + +/* + * Incremental GC: + * + * Incremental GC divides the full mark-and-sweep collection into multiple + * slices, allowing client JavaScript code to run between each slice. This + * allows interactive apps to avoid long collection pauses. Incremental GC does + * not make collection take less time, it merely spreads that time out so that + * the pauses are less noticable. + * + * For a collection to be carried out incrementally the following conditions + * must be met: + * - The collection must be run by calling JS::IncrementalGC() rather than + * JS_GC(). + * - The GC mode must have been set to JSGC_MODE_INCREMENTAL with + * JS_SetGCParameter(). + * - All native objects that have their own trace hook must indicate that they + * implement read and write barriers with the JSCLASS_IMPLEMENTS_BARRIERS + * flag. + * + * Note: Even if incremental GC is enabled and working correctly, + * non-incremental collections can still happen when low on memory. + */ + +/* + * Begin an incremental collection and perform one slice worth of work or + * perform a slice of an ongoing incremental collection. When this function + * returns, the collection is not complete. This function must be called + * repeatedly until !IsIncrementalGCInProgress(rt). + * + * Note: SpiderMonkey's GC is not realtime. Slices in practice may be longer or + * shorter than the requested interval. + */ +extern JS_FRIEND_API(void) +IncrementalGC(JSRuntime *rt, gcreason::Reason reason, int64_t millis = 0); + +/* + * If IsIncrementalGCInProgress(rt), this call finishes the ongoing collection + * by performing an arbitrarily long slice. If !IsIncrementalGCInProgress(rt), + * this is equivalent to GCForReason. When this function returns, + * IsIncrementalGCInProgress(rt) will always be false. + */ +extern JS_FRIEND_API(void) +FinishIncrementalGC(JSRuntime *rt, gcreason::Reason reason); + +enum GCProgress { + /* + * During non-incremental GC, the GC is bracketed by JSGC_CYCLE_BEGIN/END + * callbacks. During an incremental GC, the sequence of callbacks is as + * follows: + * JSGC_CYCLE_BEGIN, JSGC_SLICE_END (first slice) + * JSGC_SLICE_BEGIN, JSGC_SLICE_END (second slice) + * ... + * JSGC_SLICE_BEGIN, JSGC_CYCLE_END (last slice) + */ + + GC_CYCLE_BEGIN, + GC_SLICE_BEGIN, + GC_SLICE_END, + GC_CYCLE_END +}; + +struct JS_FRIEND_API(GCDescription) { + bool isCompartment_; + + explicit GCDescription(bool isCompartment) + : isCompartment_(isCompartment) {} + + jschar *formatMessage(JSRuntime *rt) const; + jschar *formatJSON(JSRuntime *rt, uint64_t timestamp) const; +}; + +typedef void +(* GCSliceCallback)(JSRuntime *rt, GCProgress progress, const GCDescription &desc); + +/* + * The GC slice callback is called at the beginning and end of each slice. This + * callback may be used for GC notifications as well as to perform additional + * marking. + */ +extern JS_FRIEND_API(GCSliceCallback) +SetGCSliceCallback(JSRuntime *rt, GCSliceCallback callback); + +/* + * Incremental GC defaults to enabled, but may be disabled for testing or in + * embeddings that have not yet implemented barriers on their native classes. + * There is not currently a way to re-enable incremental GC once it has been + * disabled on the runtime. + */ +extern JS_FRIEND_API(void) +DisableIncrementalGC(JSRuntime *rt); + +/* + * Returns true if incremental GC is enabled. Simply having incremental GC + * enabled is not sufficient to ensure incremental collections are happening. + * See the comment "Incremental GC" above for reasons why incremental GC may be + * suppressed. Inspection of the "nonincremental reason" field of the + * GCDescription returned by GCSliceCallback may help narrow down the cause if + * collections are not happening incrementally when expected. + */ +extern JS_FRIEND_API(bool) +IsIncrementalGCEnabled(JSRuntime *rt); + +/* + * Returns true while an incremental GC is ongoing, both when actively + * collecting and between slices. + */ +JS_FRIEND_API(bool) +IsIncrementalGCInProgress(JSRuntime *rt); + +/* + * Returns true when writes to GC things must call an incremental (pre) barrier. + * This is generally only true when running mutator code in-between GC slices. + * At other times, the barrier may be elided for performance. + */ +extern JS_FRIEND_API(bool) +IsIncrementalBarrierNeeded(JSRuntime *rt); + +extern JS_FRIEND_API(bool) +IsIncrementalBarrierNeeded(JSContext *cx); + +/* + * Notify the GC that a reference to a GC thing is about to be overwritten. + * These methods must be called if IsIncrementalBarrierNeeded. + */ +extern JS_FRIEND_API(void) +IncrementalReferenceBarrier(void *ptr, JSGCTraceKind kind); + +extern JS_FRIEND_API(void) +IncrementalValueBarrier(const Value &v); + +extern JS_FRIEND_API(void) +IncrementalObjectBarrier(JSObject *obj); + +/* + * Returns true if the most recent GC ran incrementally. + */ +extern JS_FRIEND_API(bool) +WasIncrementalGC(JSRuntime *rt); + +/* + * Generational GC: + * + * Note: Generational GC is not yet enabled by default. The following class + * is non-functional unless SpiderMonkey was configured with + * --enable-gcgenerational. + */ + +/* Ensure that generational GC is disabled within some scope. */ +class JS_FRIEND_API(AutoDisableGenerationalGC) +{ + js::gc::GCRuntime *gc; +#if defined(JSGC_GENERATIONAL) && defined(JS_GC_ZEAL) + bool restartVerifier; +#endif + + public: + explicit AutoDisableGenerationalGC(JSRuntime *rt); + ~AutoDisableGenerationalGC(); +}; + +/* + * Returns true if generational allocation and collection is currently enabled + * on the given runtime. + */ +extern JS_FRIEND_API(bool) +IsGenerationalGCEnabled(JSRuntime *rt); + +/* + * Returns the GC's "number". This does not correspond directly to the number + * of GCs that have been run, but is guaranteed to be monotonically increasing + * with GC activity. + */ +extern JS_FRIEND_API(size_t) +GetGCNumber(); + +/* + * The GC does not immediately return the unused memory freed by a collection + * back to the system incase it is needed soon afterwards. This call forces the + * GC to return this memory immediately. + */ +extern JS_FRIEND_API(void) +ShrinkGCBuffers(JSRuntime *rt); + +/* + * Assert if a GC occurs while this class is live. This class does not disable + * the static rooting hazard analysis. + */ +class JS_PUBLIC_API(AutoAssertOnGC) +{ +#ifdef DEBUG + js::gc::GCRuntime *gc; + size_t gcNumber; + + public: + AutoAssertOnGC(); + explicit AutoAssertOnGC(JSRuntime *rt); + ~AutoAssertOnGC(); + + static void VerifyIsSafeToGC(JSRuntime *rt); +#else + public: + AutoAssertOnGC() {} + explicit AutoAssertOnGC(JSRuntime *rt) {} + ~AutoAssertOnGC() {} + + static void VerifyIsSafeToGC(JSRuntime *rt) {} +#endif +}; + +/* + * Disable the static rooting hazard analysis in the live region, but assert if + * any GC occurs while this guard object is live. This is most useful to help + * the exact rooting hazard analysis in complex regions, since it cannot + * understand dataflow. + * + * Note: GC behavior is unpredictable even when deterministice and is generally + * non-deterministic in practice. The fact that this guard has not + * asserted is not a guarantee that a GC cannot happen in the guarded + * region. As a rule, anyone performing a GC unsafe action should + * understand the GC properties of all code in that region and ensure + * that the hazard analysis is correct for that code, rather than relying + * on this class. + */ +class JS_PUBLIC_API(AutoSuppressGCAnalysis) : public AutoAssertOnGC +{ + public: + AutoSuppressGCAnalysis() : AutoAssertOnGC() {} + explicit AutoSuppressGCAnalysis(JSRuntime *rt) : AutoAssertOnGC(rt) {} +}; + +/* + * Place AutoCheckCannotGC in scopes that you believe can never GC. These + * annotations will be verified both dynamically via AutoAssertOnGC, and + * statically with the rooting hazard analysis (implemented by making the + * analysis consider AutoCheckCannotGC to be a GC pointer, and therefore + * complain if it is live across a GC call.) It is useful when dealing with + * internal pointers to GC things where the GC thing itself may not be present + * for the static analysis: e.g. acquiring inline chars from a JSString* on the + * heap. + */ +class JS_PUBLIC_API(AutoCheckCannotGC) : public AutoAssertOnGC +{ + public: + AutoCheckCannotGC() : AutoAssertOnGC() {} + explicit AutoCheckCannotGC(JSRuntime *rt) : AutoAssertOnGC(rt) {} +}; + +/* + * Unsets the gray bit for anything reachable from |thing|. |kind| should not be + * JSTRACE_SHAPE. |thing| should be non-null. + */ +extern JS_FRIEND_API(bool) +UnmarkGrayGCThingRecursively(void *thing, JSGCTraceKind kind); + +/* + * This should be called when an object that is marked gray is exposed to the JS + * engine (by handing it to running JS code or writing it into live JS + * data). During incremental GC, since the gray bits haven't been computed yet, + * we conservatively mark the object black. + */ +static MOZ_ALWAYS_INLINE void +ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) +{ + MOZ_ASSERT(kind != JSTRACE_SHAPE); + + shadow::Runtime *rt = js::gc::GetGCThingRuntime(thing); +#ifdef JSGC_GENERATIONAL + /* + * GC things residing in the nursery cannot be gray: they have no mark bits. + * All live objects in the nursery are moved to tenured at the beginning of + * each GC slice, so the gray marker never sees nursery things. + */ + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) + return; +#endif + if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) + IncrementalReferenceBarrier(thing, kind); + else if (GCThingIsMarkedGray(thing)) + UnmarkGrayGCThingRecursively(thing, kind); +} + +static MOZ_ALWAYS_INLINE void +ExposeObjectToActiveJS(JSObject *obj) +{ + ExposeGCThingToActiveJS(obj, JSTRACE_OBJECT); +} + +/* + * If a GC is currently marking, mark the object black. + */ +static MOZ_ALWAYS_INLINE void +MarkGCThingAsLive(JSRuntime *rt_, void *thing, JSGCTraceKind kind) +{ + shadow::Runtime *rt = shadow::Runtime::asShadowRuntime(rt_); +#ifdef JSGC_GENERATIONAL + /* + * Any object in the nursery will not be freed during any GC running at that time. + */ + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) + return; +#endif + if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) + IncrementalReferenceBarrier(thing, kind); +} + +static MOZ_ALWAYS_INLINE void +MarkStringAsLive(Zone *zone, JSString *string) +{ + JSRuntime *rt = JS::shadow::Zone::asShadowZone(zone)->runtimeFromMainThread(); + MarkGCThingAsLive(rt, string, JSTRACE_STRING); +} + +/* + * Internal to Firefox. + * + * Note: this is not related to the PokeGC in nsJSEnvironment. + */ +extern JS_FRIEND_API(void) +PokeGC(JSRuntime *rt); + +/* + * Internal to Firefox. + */ +extern JS_FRIEND_API(void) +NotifyDidPaint(JSRuntime *rt); + +} /* namespace JS */ + +#endif /* js_GCAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/HashTable.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/HashTable.h new file mode 100644 index 0000000000..4c27308b5e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/HashTable.h @@ -0,0 +1,1672 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_HashTable_h +#define js_HashTable_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Casting.h" +#include "mozilla/DebugOnly.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/PodOperations.h" +#include "mozilla/ReentrancyGuard.h" +#include "mozilla/TemplateLib.h" +#include "mozilla/TypeTraits.h" + +#include "js/Utility.h" + +namespace js { + +class TempAllocPolicy; +template struct DefaultHasher; +template class HashMapEntry; +namespace detail { + template class HashTableEntry; + template class HashTable; +} + +/*****************************************************************************/ + +// A JS-friendly, STL-like container providing a hash-based map from keys to +// values. In particular, HashMap calls constructors and destructors of all +// objects added so non-PODs may be used safely. +// +// Key/Value requirements: +// - movable, destructible, assignable +// HashPolicy requirements: +// - see Hash Policy section below +// AllocPolicy: +// - see jsalloc.h +// +// Note: +// - HashMap is not reentrant: Key/Value/HashPolicy/AllocPolicy members +// called by HashMap must not call back into the same HashMap object. +// - Due to the lack of exception handling, the user must call |init()|. +template , + class AllocPolicy = TempAllocPolicy> +class HashMap +{ + typedef HashMapEntry TableEntry; + + struct MapHashPolicy : HashPolicy + { + typedef Key KeyType; + static const Key &getKey(TableEntry &e) { return e.key(); } + static void setKey(TableEntry &e, Key &k) { HashPolicy::rekey(e.mutableKey(), k); } + }; + + typedef detail::HashTable Impl; + Impl impl; + + public: + typedef typename HashPolicy::Lookup Lookup; + typedef TableEntry Entry; + + // HashMap construction is fallible (due to OOM); thus the user must call + // init after constructing a HashMap and check the return value. + explicit HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} + bool init(uint32_t len = 16) { return impl.init(len); } + bool initialized() const { return impl.initialized(); } + + // Return whether the given lookup value is present in the map. E.g.: + // + // typedef HashMap HM; + // HM h; + // if (HM::Ptr p = h.lookup(3)) { + // const HM::Entry &e = *p; // p acts like a pointer to Entry + // assert(p->key == 3); // Entry contains the key + // char val = p->value; // and value + // } + // + // Also see the definition of Ptr in HashTable above (with T = Entry). + typedef typename Impl::Ptr Ptr; + Ptr lookup(const Lookup &l) const { return impl.lookup(l); } + + // Like lookup, but does not assert if two threads call lookup at the same + // time. Only use this method when none of the threads will modify the map. + Ptr readonlyThreadsafeLookup(const Lookup &l) const { return impl.readonlyThreadsafeLookup(l); } + + // Assuming |p.found()|, remove |*p|. + void remove(Ptr p) { impl.remove(p); } + + // Like |lookup(l)|, but on miss, |p = lookupForAdd(l)| allows efficient + // insertion of Key |k| (where |HashPolicy::match(k,l) == true|) using + // |add(p,k,v)|. After |add(p,k,v)|, |p| points to the new Entry. E.g.: + // + // typedef HashMap HM; + // HM h; + // HM::AddPtr p = h.lookupForAdd(3); + // if (!p) { + // if (!h.add(p, 3, 'a')) + // return false; + // } + // const HM::Entry &e = *p; // p acts like a pointer to Entry + // assert(p->key == 3); // Entry contains the key + // char val = p->value; // and value + // + // Also see the definition of AddPtr in HashTable above (with T = Entry). + // + // N.B. The caller must ensure that no mutating hash table operations + // occur between a pair of |lookupForAdd| and |add| calls. To avoid + // looking up the key a second time, the caller may use the more efficient + // relookupOrAdd method. This method reuses part of the hashing computation + // to more efficiently insert the key if it has not been added. For + // example, a mutation-handling version of the previous example: + // + // HM::AddPtr p = h.lookupForAdd(3); + // if (!p) { + // call_that_may_mutate_h(); + // if (!h.relookupOrAdd(p, 3, 'a')) + // return false; + // } + // const HM::Entry &e = *p; + // assert(p->key == 3); + // char val = p->value; + typedef typename Impl::AddPtr AddPtr; + AddPtr lookupForAdd(const Lookup &l) const { + return impl.lookupForAdd(l); + } + + template + bool add(AddPtr &p, KeyInput &&k, ValueInput &&v) { + Entry e(mozilla::Forward(k), mozilla::Forward(v)); + return impl.add(p, mozilla::Move(e)); + } + + template + bool add(AddPtr &p, KeyInput &&k) { + Entry e(mozilla::Forward(k), Value()); + return impl.add(p, mozilla::Move(e)); + } + + template + bool relookupOrAdd(AddPtr &p, KeyInput &&k, ValueInput &&v) { + Entry e(mozilla::Forward(k), mozilla::Forward(v)); + return impl.relookupOrAdd(p, e.key(), mozilla::Move(e)); + } + + // |all()| returns a Range containing |count()| elements. E.g.: + // + // typedef HashMap HM; + // HM h; + // for (HM::Range r = h.all(); !r.empty(); r.popFront()) + // char c = r.front().value(); + // + // Also see the definition of Range in HashTable above (with T = Entry). + typedef typename Impl::Range Range; + Range all() const { return impl.all(); } + + // Typedef for the enumeration class. An Enum may be used to examine and + // remove table entries: + // + // typedef HashMap HM; + // HM s; + // for (HM::Enum e(s); !e.empty(); e.popFront()) + // if (e.front().value() == 'l') + // e.removeFront(); + // + // Table resize may occur in Enum's destructor. Also see the definition of + // Enum in HashTable above (with T = Entry). + typedef typename Impl::Enum Enum; + + // Remove all entries. This does not shrink the table. For that consider + // using the finish() method. + void clear() { impl.clear(); } + + // Remove all the entries and release all internal buffers. The map must + // be initialized again before any use. + void finish() { impl.finish(); } + + // Does the table contain any entries? + bool empty() const { return impl.empty(); } + + // Number of live elements in the map. + uint32_t count() const { return impl.count(); } + + // Total number of allocation in the dynamic table. Note: resize will + // happen well before count() == capacity(). + size_t capacity() const { return impl.capacity(); } + + // Don't just call |impl.sizeOfExcludingThis()| because there's no + // guarantee that |impl| is the first field in HashMap. + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return impl.sizeOfExcludingThis(mallocSizeOf); + } + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return mallocSizeOf(this) + impl.sizeOfExcludingThis(mallocSizeOf); + } + + // If |generation()| is the same before and after a HashMap operation, + // pointers into the table remain valid. + uint32_t generation() const { return impl.generation(); } + + /************************************************** Shorthand operations */ + + bool has(const Lookup &l) const { + return impl.lookup(l) != nullptr; + } + + // Overwrite existing value with v. Return false on oom. + template + bool put(KeyInput &&k, ValueInput &&v) { + AddPtr p = lookupForAdd(k); + if (p) { + p->value() = mozilla::Forward(v); + return true; + } + return add(p, mozilla::Forward(k), mozilla::Forward(v)); + } + + // Like put, but assert that the given key is not already present. + template + bool putNew(KeyInput &&k, ValueInput &&v) { + Entry e(mozilla::Forward(k), mozilla::Forward(v)); + return impl.putNew(e.key(), mozilla::Move(e)); + } + + // Add (k,defaultValue) if |k| is not found. Return a false-y Ptr on oom. + Ptr lookupWithDefault(const Key &k, const Value &defaultValue) { + AddPtr p = lookupForAdd(k); + if (p) + return p; + (void)add(p, k, defaultValue); // p is left false-y on oom. + return p; + } + + // Remove if present. + void remove(const Lookup &l) { + if (Ptr p = lookup(l)) + remove(p); + } + + // Infallibly rekey one entry, if necessary. + // Requires template parameters Key and HashPolicy::Lookup to be the same type. + void rekeyIfMoved(const Key &old_key, const Key &new_key) { + if (old_key != new_key) + rekeyAs(old_key, new_key, new_key); + } + + // Infallibly rekey one entry, if present. + void rekeyAs(const Lookup &old_lookup, const Lookup &new_lookup, const Key &new_key) { + if (Ptr p = lookup(old_lookup)) + impl.rekeyAndMaybeRehash(p, new_lookup, new_key); + } + + // HashMap is movable + HashMap(HashMap &&rhs) : impl(mozilla::Move(rhs.impl)) {} + void operator=(HashMap &&rhs) { + MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + impl = mozilla::Move(rhs.impl); + } + + private: + // HashMap is not copyable or assignable + HashMap(const HashMap &hm) MOZ_DELETE; + HashMap &operator=(const HashMap &hm) MOZ_DELETE; + + friend class Impl::Enum; +}; + +/*****************************************************************************/ + +// A JS-friendly, STL-like container providing a hash-based set of values. In +// particular, HashSet calls constructors and destructors of all objects added +// so non-PODs may be used safely. +// +// T requirements: +// - movable, destructible, assignable +// HashPolicy requirements: +// - see Hash Policy section below +// AllocPolicy: +// - see jsalloc.h +// +// Note: +// - HashSet is not reentrant: T/HashPolicy/AllocPolicy members called by +// HashSet must not call back into the same HashSet object. +// - Due to the lack of exception handling, the user must call |init()|. +template , + class AllocPolicy = TempAllocPolicy> +class HashSet +{ + struct SetOps : HashPolicy + { + typedef T KeyType; + static const KeyType &getKey(const T &t) { return t; } + static void setKey(T &t, KeyType &k) { HashPolicy::rekey(t, k); } + }; + + typedef detail::HashTable Impl; + Impl impl; + + public: + typedef typename HashPolicy::Lookup Lookup; + typedef T Entry; + + // HashSet construction is fallible (due to OOM); thus the user must call + // init after constructing a HashSet and check the return value. + explicit HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} + bool init(uint32_t len = 16) { return impl.init(len); } + bool initialized() const { return impl.initialized(); } + + // Return whether the given lookup value is present in the map. E.g.: + // + // typedef HashSet HS; + // HS h; + // if (HS::Ptr p = h.lookup(3)) { + // assert(*p == 3); // p acts like a pointer to int + // } + // + // Also see the definition of Ptr in HashTable above. + typedef typename Impl::Ptr Ptr; + Ptr lookup(const Lookup &l) const { return impl.lookup(l); } + + // Like lookup, but does not assert if two threads call lookup at the same + // time. Only use this method when none of the threads will modify the map. + Ptr readonlyThreadsafeLookup(const Lookup &l) const { return impl.readonlyThreadsafeLookup(l); } + + // Assuming |p.found()|, remove |*p|. + void remove(Ptr p) { impl.remove(p); } + + // Like |lookup(l)|, but on miss, |p = lookupForAdd(l)| allows efficient + // insertion of T value |t| (where |HashPolicy::match(t,l) == true|) using + // |add(p,t)|. After |add(p,t)|, |p| points to the new element. E.g.: + // + // typedef HashSet HS; + // HS h; + // HS::AddPtr p = h.lookupForAdd(3); + // if (!p) { + // if (!h.add(p, 3)) + // return false; + // } + // assert(*p == 3); // p acts like a pointer to int + // + // Also see the definition of AddPtr in HashTable above. + // + // N.B. The caller must ensure that no mutating hash table operations + // occur between a pair of |lookupForAdd| and |add| calls. To avoid + // looking up the key a second time, the caller may use the more efficient + // relookupOrAdd method. This method reuses part of the hashing computation + // to more efficiently insert the key if it has not been added. For + // example, a mutation-handling version of the previous example: + // + // HS::AddPtr p = h.lookupForAdd(3); + // if (!p) { + // call_that_may_mutate_h(); + // if (!h.relookupOrAdd(p, 3, 3)) + // return false; + // } + // assert(*p == 3); + // + // Note that relookupOrAdd(p,l,t) performs Lookup using |l| and adds the + // entry |t|, where the caller ensures match(l,t). + typedef typename Impl::AddPtr AddPtr; + AddPtr lookupForAdd(const Lookup &l) const { return impl.lookupForAdd(l); } + + template + bool add(AddPtr &p, U &&u) { + return impl.add(p, mozilla::Forward(u)); + } + + template + bool relookupOrAdd(AddPtr &p, const Lookup &l, U &&u) { + return impl.relookupOrAdd(p, l, mozilla::Forward(u)); + } + + // |all()| returns a Range containing |count()| elements: + // + // typedef HashSet HS; + // HS h; + // for (HS::Range r = h.all(); !r.empty(); r.popFront()) + // int i = r.front(); + // + // Also see the definition of Range in HashTable above. + typedef typename Impl::Range Range; + Range all() const { return impl.all(); } + + // Typedef for the enumeration class. An Enum may be used to examine and + // remove table entries: + // + // typedef HashSet HS; + // HS s; + // for (HS::Enum e(s); !e.empty(); e.popFront()) + // if (e.front() == 42) + // e.removeFront(); + // + // Table resize may occur in Enum's destructor. Also see the definition of + // Enum in HashTable above. + typedef typename Impl::Enum Enum; + + // Remove all entries. This does not shrink the table. For that consider + // using the finish() method. + void clear() { impl.clear(); } + + // Remove all the entries and release all internal buffers. The set must + // be initialized again before any use. + void finish() { impl.finish(); } + + // Does the table contain any entries? + bool empty() const { return impl.empty(); } + + // Number of live elements in the map. + uint32_t count() const { return impl.count(); } + + // Total number of allocation in the dynamic table. Note: resize will + // happen well before count() == capacity(). + size_t capacity() const { return impl.capacity(); } + + // Don't just call |impl.sizeOfExcludingThis()| because there's no + // guarantee that |impl| is the first field in HashSet. + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return impl.sizeOfExcludingThis(mallocSizeOf); + } + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return mallocSizeOf(this) + impl.sizeOfExcludingThis(mallocSizeOf); + } + + // If |generation()| is the same before and after a HashSet operation, + // pointers into the table remain valid. + uint32_t generation() const { return impl.generation(); } + + /************************************************** Shorthand operations */ + + bool has(const Lookup &l) const { + return impl.lookup(l) != nullptr; + } + + // Add |u| if it is not present already. Return false on oom. + template + bool put(U &&u) { + AddPtr p = lookupForAdd(u); + return p ? true : add(p, mozilla::Forward(u)); + } + + // Like put, but assert that the given key is not already present. + template + bool putNew(U &&u) { + return impl.putNew(u, mozilla::Forward(u)); + } + + template + bool putNew(const Lookup &l, U &&u) { + return impl.putNew(l, mozilla::Forward(u)); + } + + void remove(const Lookup &l) { + if (Ptr p = lookup(l)) + remove(p); + } + + // Infallibly rekey one entry, if present. + // Requires template parameters T and HashPolicy::Lookup to be the same type. + void rekeyIfMoved(const Lookup &old_value, const T &new_value) { + if (old_value != new_value) + rekeyAs(old_value, new_value, new_value); + } + + // Infallibly rekey one entry, if present. + void rekeyAs(const Lookup &old_lookup, const Lookup &new_lookup, const T &new_value) { + if (Ptr p = lookup(old_lookup)) + impl.rekeyAndMaybeRehash(p, new_lookup, new_value); + } + + // Infallibly rekey one entry with a new key that is equivalent. + void rekeyInPlace(Ptr p, const T &new_value) + { + MOZ_ASSERT(HashPolicy::match(*p, new_value)); + impl.rekeyInPlace(p, new_value); + } + + // HashSet is movable + HashSet(HashSet &&rhs) : impl(mozilla::Move(rhs.impl)) {} + void operator=(HashSet &&rhs) { + MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + impl = mozilla::Move(rhs.impl); + } + + private: + // HashSet is not copyable or assignable + HashSet(const HashSet &hs) MOZ_DELETE; + HashSet &operator=(const HashSet &hs) MOZ_DELETE; + + friend class Impl::Enum; +}; + +/*****************************************************************************/ + +// Hash Policy +// +// A hash policy P for a hash table with key-type Key must provide: +// - a type |P::Lookup| to use to lookup table entries; +// - a static member function |P::hash| with signature +// +// static js::HashNumber hash(Lookup) +// +// to use to hash the lookup type; and +// - a static member function |P::match| with signature +// +// static bool match(Key, Lookup) +// +// to use to test equality of key and lookup values. +// +// Normally, Lookup = Key. In general, though, different values and types of +// values can be used to lookup and store. If a Lookup value |l| is != to the +// added Key value |k|, the user must ensure that |P::match(k,l)|. E.g.: +// +// js::HashSet::AddPtr p = h.lookup(l); +// if (!p) { +// assert(P::match(k, l)); // must hold +// h.add(p, k); +// } + +// Pointer hashing policy that strips the lowest zeroBits when calculating the +// hash to improve key distribution. +template +struct PointerHasher +{ + typedef Key Lookup; + static HashNumber hash(const Lookup &l) { + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); + size_t word = reinterpret_cast(l) >> zeroBits; + JS_STATIC_ASSERT(sizeof(HashNumber) == 4); +#if JS_BITS_PER_WORD == 32 + return HashNumber(word); +#else + JS_STATIC_ASSERT(sizeof word == 8); + return HashNumber((word >> 32) ^ word); +#endif + } + static bool match(const Key &k, const Lookup &l) { + MOZ_ASSERT(!JS::IsPoisonedPtr(k)); + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); + return k == l; + } + static void rekey(Key &k, const Key& newKey) { + k = newKey; + } +}; + +// Default hash policy: just use the 'lookup' value. This of course only +// works if the lookup value is integral. HashTable applies ScrambleHashCode to +// the result of the 'hash' which means that it is 'ok' if the lookup value is +// not well distributed over the HashNumber domain. +template +struct DefaultHasher +{ + typedef Key Lookup; + static HashNumber hash(const Lookup &l) { + // Hash if can implicitly cast to hash number type. + return l; + } + static bool match(const Key &k, const Lookup &l) { + // Use builtin or overloaded operator==. + return k == l; + } + static void rekey(Key &k, const Key& newKey) { + k = newKey; + } +}; + +// Specialize hashing policy for pointer types. It assumes that the type is +// at least word-aligned. For types with smaller size use PointerHasher. +template +struct DefaultHasher : PointerHasher::value> +{}; + +// For doubles, we can xor the two uint32s. +template <> +struct DefaultHasher +{ + typedef double Lookup; + static HashNumber hash(double d) { + JS_STATIC_ASSERT(sizeof(HashNumber) == 4); + uint64_t u = mozilla::BitwiseCast(d); + return HashNumber(u ^ (u >> 32)); + } + static bool match(double lhs, double rhs) { + return mozilla::BitwiseCast(lhs) == mozilla::BitwiseCast(rhs); + } +}; + +template <> +struct DefaultHasher +{ + typedef float Lookup; + static HashNumber hash(float f) { + JS_STATIC_ASSERT(sizeof(HashNumber) == 4); + return HashNumber(mozilla::BitwiseCast(f)); + } + static bool match(float lhs, float rhs) { + return mozilla::BitwiseCast(lhs) == mozilla::BitwiseCast(rhs); + } +}; + +/*****************************************************************************/ + +// Both HashMap and HashSet are implemented by a single HashTable that is even +// more heavily parameterized than the other two. This leaves HashTable gnarly +// and extremely coupled to HashMap and HashSet; thus code should not use +// HashTable directly. + +template +class HashMapEntry +{ + Key key_; + Value value_; + + template friend class detail::HashTable; + template friend class detail::HashTableEntry; + template friend class HashMap; + + Key & mutableKey() { return key_; } + + public: + template + HashMapEntry(KeyInput &&k, ValueInput &&v) + : key_(mozilla::Forward(k)), + value_(mozilla::Forward(v)) + {} + + HashMapEntry(HashMapEntry &&rhs) + : key_(mozilla::Move(rhs.key_)), + value_(mozilla::Move(rhs.value_)) + {} + + typedef Key KeyType; + typedef Value ValueType; + + const Key & key() const { return key_; } + const Value & value() const { return value_; } + Value & value() { return value_; } + + private: + HashMapEntry(const HashMapEntry &) MOZ_DELETE; + void operator=(const HashMapEntry &) MOZ_DELETE; +}; + +} // namespace js + +namespace mozilla { + +template +struct IsPod > : IsPod {}; + +template +struct IsPod > + : IntegralConstant::value && IsPod::value> +{}; + +} // namespace mozilla + +namespace js { + +namespace detail { + +template +class HashTable; + +template +class HashTableEntry +{ + template friend class HashTable; + typedef typename mozilla::RemoveConst::Type NonConstT; + + HashNumber keyHash; + mozilla::AlignedStorage2 mem; + + static const HashNumber sFreeKey = 0; + static const HashNumber sRemovedKey = 1; + static const HashNumber sCollisionBit = 1; + + static bool isLiveHash(HashNumber hash) + { + return hash > sRemovedKey; + } + + HashTableEntry(const HashTableEntry &) MOZ_DELETE; + void operator=(const HashTableEntry &) MOZ_DELETE; + ~HashTableEntry() MOZ_DELETE; + + public: + // NB: HashTableEntry is treated as a POD: no constructor or destructor calls. + + void destroyIfLive() { + if (isLive()) + mem.addr()->~T(); + } + + void destroy() { + MOZ_ASSERT(isLive()); + mem.addr()->~T(); + } + + void swap(HashTableEntry *other) { + mozilla::Swap(keyHash, other->keyHash); + mozilla::Swap(mem, other->mem); + } + + T &get() { MOZ_ASSERT(isLive()); return *mem.addr(); } + + bool isFree() const { return keyHash == sFreeKey; } + void clearLive() { MOZ_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); } + void clear() { if (isLive()) mem.addr()->~T(); keyHash = sFreeKey; } + bool isRemoved() const { return keyHash == sRemovedKey; } + void removeLive() { MOZ_ASSERT(isLive()); keyHash = sRemovedKey; mem.addr()->~T(); } + bool isLive() const { return isLiveHash(keyHash); } + void setCollision() { MOZ_ASSERT(isLive()); keyHash |= sCollisionBit; } + void setCollision(HashNumber bit) { MOZ_ASSERT(isLive()); keyHash |= bit; } + void unsetCollision() { keyHash &= ~sCollisionBit; } + bool hasCollision() const { return keyHash & sCollisionBit; } + bool matchHash(HashNumber hn) { return (keyHash & ~sCollisionBit) == hn; } + HashNumber getKeyHash() const { return keyHash & ~sCollisionBit; } + + template + void setLive(HashNumber hn, U &&u) + { + MOZ_ASSERT(!isLive()); + keyHash = hn; + new(mem.addr()) T(mozilla::Forward(u)); + MOZ_ASSERT(isLive()); + } +}; + +template +class HashTable : private AllocPolicy +{ + friend class mozilla::ReentrancyGuard; + + typedef typename mozilla::RemoveConst::Type NonConstT; + typedef typename HashPolicy::KeyType Key; + typedef typename HashPolicy::Lookup Lookup; + + public: + typedef HashTableEntry Entry; + + // A nullable pointer to a hash table element. A Ptr |p| can be tested + // either explicitly |if (p.found()) p->...| or using boolean conversion + // |if (p) p->...|. Ptr objects must not be used after any mutating hash + // table operations unless |generation()| is tested. + class Ptr + { + friend class HashTable; + typedef void (Ptr::* ConvertibleToBool)(); + void nonNull() {} + + Entry *entry_; +#ifdef DEBUG + const HashTable *table_; + uint32_t generation; +#endif + + protected: + Ptr(Entry &entry, const HashTable &tableArg) + : entry_(&entry) +#ifdef DEBUG + , table_(&tableArg) + , generation(tableArg.generation()) +#endif + {} + + public: + // Leaves Ptr uninitialized. + Ptr() { +#ifdef JS_DEBUG + entry_ = (Entry *)0xbad; +#endif + } + + bool found() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->isLive(); + } + + operator ConvertibleToBool() const { + return found() ? &Ptr::nonNull : 0; + } + + bool operator==(const Ptr &rhs) const { + MOZ_ASSERT(found() && rhs.found()); + return entry_ == rhs.entry_; + } + + bool operator!=(const Ptr &rhs) const { + MOZ_ASSERT(generation == table_->generation()); + return !(*this == rhs); + } + + T &operator*() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->get(); + } + + T *operator->() const { + MOZ_ASSERT(generation == table_->generation()); + return &entry_->get(); + } + }; + + // A Ptr that can be used to add a key after a failed lookup. + class AddPtr : public Ptr + { + friend class HashTable; + HashNumber keyHash; +#ifdef DEBUG + uint64_t mutationCount; +#endif + + AddPtr(Entry &entry, const HashTable &tableArg, HashNumber hn) + : Ptr(entry, tableArg) + , keyHash(hn) +#ifdef DEBUG + , mutationCount(tableArg.mutationCount) +#endif + {} + + public: + // Leaves AddPtr uninitialized. + AddPtr() {} + }; + + // A collection of hash table entries. The collection is enumerated by + // calling |front()| followed by |popFront()| as long as |!empty()|. As + // with Ptr/AddPtr, Range objects must not be used after any mutating hash + // table operation unless the |generation()| is tested. + class Range + { + protected: + friend class HashTable; + + Range(const HashTable &tableArg, Entry *c, Entry *e) + : cur(c) + , end(e) +#ifdef DEBUG + , table_(&tableArg) + , mutationCount(tableArg.mutationCount) + , generation(tableArg.generation()) + , validEntry(true) +#endif + { + while (cur < end && !cur->isLive()) + ++cur; + } + + Entry *cur, *end; +#ifdef DEBUG + const HashTable *table_; + uint64_t mutationCount; + uint32_t generation; + bool validEntry; +#endif + + public: + Range() + : cur(nullptr) + , end(nullptr) +#ifdef DEBUG + , table_(nullptr) + , mutationCount(0) + , generation(0) + , validEntry(false) +#endif + {} + + bool empty() const { + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); + return cur == end; + } + + T &front() const { + MOZ_ASSERT(validEntry); + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); + return cur->get(); + } + + void popFront() { + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); + while (++cur < end && !cur->isLive()) + continue; +#ifdef DEBUG + validEntry = true; +#endif + } + }; + + // A Range whose lifetime delimits a mutating enumeration of a hash table. + // Since rehashing when elements were removed during enumeration would be + // bad, it is postponed until the Enum is destructed. Since the Enum's + // destructor touches the hash table, the user must ensure that the hash + // table is still alive when the destructor runs. + class Enum : public Range + { + friend class HashTable; + + HashTable &table_; + bool rekeyed; + bool removed; + + /* Not copyable. */ + Enum(const Enum &) MOZ_DELETE; + void operator=(const Enum &) MOZ_DELETE; + + public: + template explicit + Enum(Map &map) : Range(map.all()), table_(map.impl), rekeyed(false), removed(false) {} + + // Removes the |front()| element from the table, leaving |front()| + // invalid until the next call to |popFront()|. For example: + // + // HashSet s; + // for (HashSet::Enum e(s); !e.empty(); e.popFront()) + // if (e.front() == 42) + // e.removeFront(); + void removeFront() { + table_.remove(*this->cur); + removed = true; +#ifdef DEBUG + this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif + } + + // Removes the |front()| element and re-inserts it into the table with + // a new key at the new Lookup position. |front()| is invalid after + // this operation until the next call to |popFront()|. + void rekeyFront(const Lookup &l, const Key &k) { + Ptr p(*this->cur, table_); + table_.rekeyWithoutRehash(p, l, k); + rekeyed = true; +#ifdef DEBUG + this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif + } + + void rekeyFront(const Key &k) { + rekeyFront(k, k); + } + + // Potentially rehashes the table. + ~Enum() { + if (rekeyed) { + table_.gen++; + table_.checkOverRemoved(); + } + + if (removed) + table_.compactIfUnderloaded(); + } + }; + + // HashTable is movable + HashTable(HashTable &&rhs) + : AllocPolicy(rhs) + { + mozilla::PodAssign(this, &rhs); + rhs.table = nullptr; + } + void operator=(HashTable &&rhs) { + MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + if (table) + destroyTable(*this, table, capacity()); + mozilla::PodAssign(this, &rhs); + rhs.table = nullptr; + } + + private: + // HashTable is not copyable or assignable + HashTable(const HashTable &) MOZ_DELETE; + void operator=(const HashTable &) MOZ_DELETE; + + private: + static const size_t CAP_BITS = 24; + + public: + Entry *table; // entry storage + uint32_t gen; // entry storage generation number + uint32_t entryCount; // number of entries in table + uint32_t removedCount:CAP_BITS; // removed entry sentinels in table + uint32_t hashShift:8; // multiplicative hash shift + +#ifdef JS_DEBUG + mozilla::DebugOnly mutationCount; + mutable mozilla::DebugOnly mEntered; + mutable struct Stats + { + uint32_t searches; // total number of table searches + uint32_t steps; // hash chain links traversed + uint32_t hits; // searches that found key + uint32_t misses; // searches that didn't find key + uint32_t addOverRemoved; // adds that recycled a removed entry + uint32_t removes; // calls to remove + uint32_t removeFrees; // calls to remove that freed the entry + uint32_t grows; // table expansions + uint32_t shrinks; // table contractions + uint32_t compresses; // table compressions + uint32_t rehashes; // tombstone decontaminations + } stats; +# define METER(x) x +#else +# define METER(x) +#endif + + // The default initial capacity is 32 (enough to hold 16 elements), but it + // can be as low as 4. + static const unsigned sMinCapacityLog2 = 2; + static const unsigned sMinCapacity = 1 << sMinCapacityLog2; + static const unsigned sMaxInit = JS_BIT(CAP_BITS - 1); + static const unsigned sMaxCapacity = JS_BIT(CAP_BITS); + static const unsigned sHashBits = mozilla::tl::BitSize::value; + + // Hash-table alpha is conceptually a fraction, but to avoid floating-point + // math we implement it as a ratio of integers. + static const uint8_t sAlphaDenominator = 4; + static const uint8_t sMinAlphaNumerator = 1; // min alpha: 1/4 + static const uint8_t sMaxAlphaNumerator = 3; // max alpha: 3/4 + + static const HashNumber sFreeKey = Entry::sFreeKey; + static const HashNumber sRemovedKey = Entry::sRemovedKey; + static const HashNumber sCollisionBit = Entry::sCollisionBit; + + void setTableSizeLog2(unsigned sizeLog2) + { + hashShift = sHashBits - sizeLog2; + } + + static bool isLiveHash(HashNumber hash) + { + return Entry::isLiveHash(hash); + } + + static HashNumber prepareHash(const Lookup& l) + { + HashNumber keyHash = ScrambleHashCode(HashPolicy::hash(l)); + + // Avoid reserved hash codes. + if (!isLiveHash(keyHash)) + keyHash -= (sRemovedKey + 1); + return keyHash & ~sCollisionBit; + } + + static Entry *createTable(AllocPolicy &alloc, uint32_t capacity) + { + static_assert(sFreeKey == 0, + "newly-calloc'd tables have to be considered empty"); + static_assert(sMaxCapacity <= SIZE_MAX / sizeof(Entry), + "would overflow allocating max number of entries"); + return static_cast(alloc.calloc_(capacity * sizeof(Entry))); + } + + static void destroyTable(AllocPolicy &alloc, Entry *oldTable, uint32_t capacity) + { + for (Entry *e = oldTable, *end = e + capacity; e < end; ++e) + e->destroyIfLive(); + alloc.free_(oldTable); + } + + public: + explicit HashTable(AllocPolicy ap) + : AllocPolicy(ap) + , table(nullptr) + , gen(0) + , entryCount(0) + , removedCount(0) + , hashShift(sHashBits) +#ifdef DEBUG + , mutationCount(0) + , mEntered(false) +#endif + {} + + MOZ_WARN_UNUSED_RESULT bool init(uint32_t length) + { + MOZ_ASSERT(!initialized()); + + // Reject all lengths whose initial computed capacity would exceed + // sMaxCapacity. Round that maximum length down to the nearest power + // of two for speedier code. + if (length > sMaxInit) { + this->reportAllocOverflow(); + return false; + } + + static_assert((sMaxInit * sAlphaDenominator) / sAlphaDenominator == sMaxInit, + "multiplication in numerator below could overflow"); + static_assert(sMaxInit * sAlphaDenominator <= UINT32_MAX - sMaxAlphaNumerator, + "numerator calculation below could potentially overflow"); + + // Compute the smallest capacity allowing |length| elements to be + // inserted without rehashing: ceil(length / max-alpha). (Ceiling + // integral division: .) + uint32_t newCapacity = + (length * sAlphaDenominator + sMaxAlphaNumerator - 1) / sMaxAlphaNumerator; + if (newCapacity < sMinCapacity) + newCapacity = sMinCapacity; + + // FIXME: use JS_CEILING_LOG2 when PGO stops crashing (bug 543034). + uint32_t roundUp = sMinCapacity, roundUpLog2 = sMinCapacityLog2; + while (roundUp < newCapacity) { + roundUp <<= 1; + ++roundUpLog2; + } + + newCapacity = roundUp; + MOZ_ASSERT(newCapacity >= length); + MOZ_ASSERT(newCapacity <= sMaxCapacity); + + table = createTable(*this, newCapacity); + if (!table) + return false; + + setTableSizeLog2(roundUpLog2); + METER(memset(&stats, 0, sizeof(stats))); + return true; + } + + bool initialized() const + { + return !!table; + } + + ~HashTable() + { + if (table) + destroyTable(*this, table, capacity()); + } + + private: + HashNumber hash1(HashNumber hash0) const + { + return hash0 >> hashShift; + } + + struct DoubleHash + { + HashNumber h2; + HashNumber sizeMask; + }; + + DoubleHash hash2(HashNumber curKeyHash) const + { + unsigned sizeLog2 = sHashBits - hashShift; + DoubleHash dh = { + ((curKeyHash << sizeLog2) >> hashShift) | 1, + (HashNumber(1) << sizeLog2) - 1 + }; + return dh; + } + + static HashNumber applyDoubleHash(HashNumber h1, const DoubleHash &dh) + { + return (h1 - dh.h2) & dh.sizeMask; + } + + bool overloaded() + { + static_assert(sMaxCapacity <= UINT32_MAX / sMaxAlphaNumerator, + "multiplication below could overflow"); + return entryCount + removedCount >= + capacity() * sMaxAlphaNumerator / sAlphaDenominator; + } + + // Would the table be underloaded if it had the given capacity and entryCount? + static bool wouldBeUnderloaded(uint32_t capacity, uint32_t entryCount) + { + static_assert(sMaxCapacity <= UINT32_MAX / sMinAlphaNumerator, + "multiplication below could overflow"); + return capacity > sMinCapacity && + entryCount <= capacity * sMinAlphaNumerator / sAlphaDenominator; + } + + bool underloaded() + { + return wouldBeUnderloaded(capacity(), entryCount); + } + + static bool match(Entry &e, const Lookup &l) + { + return HashPolicy::match(HashPolicy::getKey(e.get()), l); + } + + Entry &lookup(const Lookup &l, HashNumber keyHash, unsigned collisionBit) const + { + MOZ_ASSERT(isLiveHash(keyHash)); + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(collisionBit == 0 || collisionBit == sCollisionBit); + MOZ_ASSERT(table); + METER(stats.searches++); + + // Compute the primary hash address. + HashNumber h1 = hash1(keyHash); + Entry *entry = &table[h1]; + + // Miss: return space for a new entry. + if (entry->isFree()) { + METER(stats.misses++); + return *entry; + } + + // Hit: return entry. + if (entry->matchHash(keyHash) && match(*entry, l)) { + METER(stats.hits++); + return *entry; + } + + // Collision: double hash. + DoubleHash dh = hash2(keyHash); + + // Save the first removed entry pointer so we can recycle later. + Entry *firstRemoved = nullptr; + + while(true) { + if (MOZ_UNLIKELY(entry->isRemoved())) { + if (!firstRemoved) + firstRemoved = entry; + } else { + entry->setCollision(collisionBit); + } + + METER(stats.steps++); + h1 = applyDoubleHash(h1, dh); + + entry = &table[h1]; + if (entry->isFree()) { + METER(stats.misses++); + return firstRemoved ? *firstRemoved : *entry; + } + + if (entry->matchHash(keyHash) && match(*entry, l)) { + METER(stats.hits++); + return *entry; + } + } + } + + // This is a copy of lookup hardcoded to the assumptions: + // 1. the lookup is a lookupForAdd + // 2. the key, whose |keyHash| has been passed is not in the table, + // 3. no entries have been removed from the table. + // This specialized search avoids the need for recovering lookup values + // from entries, which allows more flexible Lookup/Key types. + Entry &findFreeEntry(HashNumber keyHash) + { + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(table); + METER(stats.searches++); + + // We assume 'keyHash' has already been distributed. + + // Compute the primary hash address. + HashNumber h1 = hash1(keyHash); + Entry *entry = &table[h1]; + + // Miss: return space for a new entry. + if (!entry->isLive()) { + METER(stats.misses++); + return *entry; + } + + // Collision: double hash. + DoubleHash dh = hash2(keyHash); + + while(true) { + MOZ_ASSERT(!entry->isRemoved()); + entry->setCollision(); + + METER(stats.steps++); + h1 = applyDoubleHash(h1, dh); + + entry = &table[h1]; + if (!entry->isLive()) { + METER(stats.misses++); + return *entry; + } + } + } + + enum RebuildStatus { NotOverloaded, Rehashed, RehashFailed }; + + RebuildStatus changeTableSize(int deltaLog2) + { + // Look, but don't touch, until we succeed in getting new entry store. + Entry *oldTable = table; + uint32_t oldCap = capacity(); + uint32_t newLog2 = sHashBits - hashShift + deltaLog2; + uint32_t newCapacity = JS_BIT(newLog2); + if (newCapacity > sMaxCapacity) { + this->reportAllocOverflow(); + return RehashFailed; + } + + Entry *newTable = createTable(*this, newCapacity); + if (!newTable) + return RehashFailed; + + // We can't fail from here on, so update table parameters. + setTableSizeLog2(newLog2); + removedCount = 0; + gen++; + table = newTable; + + // Copy only live entries, leaving removed ones behind. + for (Entry *src = oldTable, *end = src + oldCap; src < end; ++src) { + if (src->isLive()) { + HashNumber hn = src->getKeyHash(); + findFreeEntry(hn).setLive(hn, mozilla::Move(src->get())); + src->destroy(); + } + } + + // All entries have been destroyed, no need to destroyTable. + this->free_(oldTable); + return Rehashed; + } + + RebuildStatus checkOverloaded() + { + if (!overloaded()) + return NotOverloaded; + + // Compress if a quarter or more of all entries are removed. + int deltaLog2; + if (removedCount >= (capacity() >> 2)) { + METER(stats.compresses++); + deltaLog2 = 0; + } else { + METER(stats.grows++); + deltaLog2 = 1; + } + + return changeTableSize(deltaLog2); + } + + // Infallibly rehash the table if we are overloaded with removals. + void checkOverRemoved() + { + if (overloaded()) { + if (checkOverloaded() == RehashFailed) + rehashTableInPlace(); + } + } + + void remove(Entry &e) + { + MOZ_ASSERT(table); + METER(stats.removes++); + + if (e.hasCollision()) { + e.removeLive(); + removedCount++; + } else { + METER(stats.removeFrees++); + e.clearLive(); + } + entryCount--; +#ifdef DEBUG + mutationCount++; +#endif + } + + void checkUnderloaded() + { + if (underloaded()) { + METER(stats.shrinks++); + (void) changeTableSize(-1); + } + } + + // Resize the table down to the largest capacity which doesn't underload the + // table. Since we call checkUnderloaded() on every remove, you only need + // to call this after a bulk removal of items done without calling remove(). + void compactIfUnderloaded() + { + int32_t resizeLog2 = 0; + uint32_t newCapacity = capacity(); + while (wouldBeUnderloaded(newCapacity, entryCount)) { + newCapacity = newCapacity >> 1; + resizeLog2--; + } + + if (resizeLog2 != 0) { + changeTableSize(resizeLog2); + } + } + + // This is identical to changeTableSize(currentSize), but without requiring + // a second table. We do this by recycling the collision bits to tell us if + // the element is already inserted or still waiting to be inserted. Since + // already-inserted elements win any conflicts, we get the same table as we + // would have gotten through random insertion order. + void rehashTableInPlace() + { + METER(stats.rehashes++); + removedCount = 0; + for (size_t i = 0; i < capacity(); ++i) + table[i].unsetCollision(); + + for (size_t i = 0; i < capacity();) { + Entry *src = &table[i]; + + if (!src->isLive() || src->hasCollision()) { + ++i; + continue; + } + + HashNumber keyHash = src->getKeyHash(); + HashNumber h1 = hash1(keyHash); + DoubleHash dh = hash2(keyHash); + Entry *tgt = &table[h1]; + while (true) { + if (!tgt->hasCollision()) { + src->swap(tgt); + tgt->setCollision(); + break; + } + + h1 = applyDoubleHash(h1, dh); + tgt = &table[h1]; + } + } + + // TODO: this algorithm leaves collision bits on *all* elements, even if + // they are on no collision path. We have the option of setting the + // collision bits correctly on a subsequent pass or skipping the rehash + // unless we are totally filled with tombstones: benchmark to find out + // which approach is best. + } + + public: + void clear() + { + if (mozilla::IsPod::value) { + memset(table, 0, sizeof(*table) * capacity()); + } else { + uint32_t tableCapacity = capacity(); + for (Entry *e = table, *end = table + tableCapacity; e < end; ++e) + e->clear(); + } + removedCount = 0; + entryCount = 0; +#ifdef DEBUG + mutationCount++; +#endif + } + + void finish() + { + MOZ_ASSERT(!mEntered); + + if (!table) + return; + + destroyTable(*this, table, capacity()); + table = nullptr; + gen++; + entryCount = 0; + removedCount = 0; +#ifdef DEBUG + mutationCount++; +#endif + } + + Range all() const + { + MOZ_ASSERT(table); + return Range(*this, table, table + capacity()); + } + + bool empty() const + { + MOZ_ASSERT(table); + return !entryCount; + } + + uint32_t count() const + { + MOZ_ASSERT(table); + return entryCount; + } + + uint32_t capacity() const + { + MOZ_ASSERT(table); + return JS_BIT(sHashBits - hashShift); + } + + uint32_t generation() const + { + MOZ_ASSERT(table); + return gen; + } + + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const + { + return mallocSizeOf(table); + } + + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const + { + return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + } + + Ptr lookup(const Lookup &l) const + { + mozilla::ReentrancyGuard g(*this); + HashNumber keyHash = prepareHash(l); + return Ptr(lookup(l, keyHash, 0), *this); + } + + Ptr readonlyThreadsafeLookup(const Lookup &l) const + { + HashNumber keyHash = prepareHash(l); + return Ptr(lookup(l, keyHash, 0), *this); + } + + AddPtr lookupForAdd(const Lookup &l) const + { + mozilla::ReentrancyGuard g(*this); + HashNumber keyHash = prepareHash(l); + Entry &entry = lookup(l, keyHash, sCollisionBit); + AddPtr p(entry, *this, keyHash); + return p; + } + + template + bool add(AddPtr &p, U &&u) + { + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(table); + MOZ_ASSERT(!p.found()); + MOZ_ASSERT(!(p.keyHash & sCollisionBit)); + + // Changing an entry from removed to live does not affect whether we + // are overloaded and can be handled separately. + if (p.entry_->isRemoved()) { + METER(stats.addOverRemoved++); + removedCount--; + p.keyHash |= sCollisionBit; + } else { + // Preserve the validity of |p.entry_|. + RebuildStatus status = checkOverloaded(); + if (status == RehashFailed) + return false; + if (status == Rehashed) + p.entry_ = &findFreeEntry(p.keyHash); + } + + p.entry_->setLive(p.keyHash, mozilla::Forward(u)); + entryCount++; +#ifdef DEBUG + mutationCount++; + p.generation = generation(); + p.mutationCount = mutationCount; +#endif + return true; + } + + // Note: |l| may be a reference to a piece of |u|, so this function + // must take care not to use |l| after moving |u|. + template + void putNewInfallible(const Lookup &l, U &&u) + { + MOZ_ASSERT(table); + + HashNumber keyHash = prepareHash(l); + Entry *entry = &findFreeEntry(keyHash); + + if (entry->isRemoved()) { + METER(stats.addOverRemoved++); + removedCount--; + keyHash |= sCollisionBit; + } + + entry->setLive(keyHash, mozilla::Forward(u)); + entryCount++; +#ifdef DEBUG + mutationCount++; +#endif + } + + // Note: |l| may be a reference to a piece of |u|, so this function + // must take care not to use |l| after moving |u|. + template + bool putNew(const Lookup &l, U &&u) + { + if (checkOverloaded() == RehashFailed) + return false; + + putNewInfallible(l, mozilla::Forward(u)); + return true; + } + + // Note: |l| may be a reference to a piece of |u|, so this function + // must take care not to use |l| after moving |u|. + template + bool relookupOrAdd(AddPtr& p, const Lookup &l, U &&u) + { +#ifdef DEBUG + p.generation = generation(); + p.mutationCount = mutationCount; +#endif + { + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(prepareHash(l) == p.keyHash); // l has not been destroyed + p.entry_ = &lookup(l, p.keyHash, sCollisionBit); + } + return p.found() || add(p, mozilla::Forward(u)); + } + + void remove(Ptr p) + { + MOZ_ASSERT(table); + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(p.found()); + remove(*p.entry_); + checkUnderloaded(); + } + + void rekeyWithoutRehash(Ptr p, const Lookup &l, const Key &k) + { + MOZ_ASSERT(table); + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(p.found()); + typename HashTableEntry::NonConstT t(mozilla::Move(*p)); + HashPolicy::setKey(t, const_cast(k)); + remove(*p.entry_); + putNewInfallible(l, mozilla::Move(t)); + } + + void rekeyAndMaybeRehash(Ptr p, const Lookup &l, const Key &k) + { + rekeyWithoutRehash(p, l, k); + checkOverRemoved(); + } + + void rekeyInPlace(Ptr p, const Key &k) + { + MOZ_ASSERT(table); + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(p.found()); + HashPolicy::rekey(const_cast(*p), const_cast(k)); + } + +#undef METER +}; + +} // namespace detail +} // namespace js + +#endif /* js_HashTable_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/HeapAPI.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/HeapAPI.h new file mode 100644 index 0000000000..bdd63c1937 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/HeapAPI.h @@ -0,0 +1,317 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_HeapAPI_h +#define js_HeapAPI_h + +#include + +#include "jspubtd.h" + +#include "js/Utility.h" + +/* These values are private to the JS engine. */ +namespace js { + +// Whether the current thread is permitted access to any part of the specified +// runtime or zone. +JS_FRIEND_API(bool) +CurrentThreadCanAccessRuntime(JSRuntime *rt); + +JS_FRIEND_API(bool) +CurrentThreadCanAccessZone(JS::Zone *zone); + +namespace gc { + +struct Cell; + +const size_t ArenaShift = 12; +const size_t ArenaSize = size_t(1) << ArenaShift; +const size_t ArenaMask = ArenaSize - 1; + +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkShift = 18; +#else +const size_t ChunkShift = 20; +#endif +const size_t ChunkSize = size_t(1) << ChunkShift; +const size_t ChunkMask = ChunkSize - 1; + +const size_t CellShift = 3; +const size_t CellSize = size_t(1) << CellShift; +const size_t CellMask = CellSize - 1; + +/* These are magic constants derived from actual offsets in gc/Heap.h. */ +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkMarkBitmapOffset = 258104; +const size_t ChunkMarkBitmapBits = 31744; +#else +const size_t ChunkMarkBitmapOffset = 1032352; +const size_t ChunkMarkBitmapBits = 129024; +#endif +const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*); +const size_t ChunkLocationOffset = ChunkSize - 2 * sizeof(void*) - sizeof(uint64_t); + +/* + * Live objects are marked black. How many other additional colors are available + * depends on the size of the GCThing. Objects marked gray are eligible for + * cycle collection. + */ +static const uint32_t BLACK = 0; +static const uint32_t GRAY = 1; + +/* + * The "location" field in the Chunk trailer is a bit vector indicting various + * roles of the chunk. + * + * The value 0 for the "location" field is invalid, at least one bit must be + * set. + * + * Some bits preclude others, for example, any "nursery" bit precludes any + * "tenured" or "middle generation" bit. + */ +const uintptr_t ChunkLocationBitNursery = 1; // Standard GGC nursery +const uintptr_t ChunkLocationBitTenuredHeap = 2; // Standard GGC tenured generation +const uintptr_t ChunkLocationBitPJSNewspace = 4; // The PJS generational GC's allocation space +const uintptr_t ChunkLocationBitPJSFromspace = 8; // The PJS generational GC's fromspace (during GC) + +const uintptr_t ChunkLocationAnyNursery = ChunkLocationBitNursery | + ChunkLocationBitPJSNewspace | + ChunkLocationBitPJSFromspace; + +#ifdef JS_DEBUG +/* When downcasting, ensure we are actually the right type. */ +extern JS_FRIEND_API(void) +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind); +#else +inline void +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind) {} +#endif + +} /* namespace gc */ +} /* namespace js */ + +namespace JS { +struct Zone; + +/* Default size for the generational nursery in bytes. */ +const uint32_t DefaultNurseryBytes = 16 * 1024 * 1024; + +/* Default maximum heap size in bytes to pass to JS_NewRuntime(). */ +const uint32_t DefaultHeapMaxBytes = 32 * 1024 * 1024; + +/* + * We cannot expose the class hierarchy: the implementation is hidden. Instead + * we provide cast functions with strong debug-mode assertions. + */ +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSObject *obj) +{ + js::gc::Cell *cell = reinterpret_cast(obj); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFunction *fun) +{ + js::gc::Cell *cell = reinterpret_cast(fun); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSString *str) +{ + js::gc::Cell *cell = reinterpret_cast(str); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFlatString *flat) +{ + js::gc::Cell *cell = reinterpret_cast(flat); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JS::Symbol *sym) +{ + js::gc::Cell *cell = reinterpret_cast(sym); + AssertGCThingHasType(cell, JSTRACE_SYMBOL); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSScript *script) +{ + js::gc::Cell *cell = reinterpret_cast(script); + AssertGCThingHasType(cell, JSTRACE_SCRIPT); + return cell; +} + +namespace shadow { + +struct ArenaHeader +{ + JS::Zone *zone; +}; + +struct Zone +{ + protected: + JSRuntime *const runtime_; + JSTracer *const barrierTracer_; // A pointer to the JSRuntime's |gcMarker|. + + public: + bool needsBarrier_; + + Zone(JSRuntime *runtime, JSTracer *barrierTracerArg) + : runtime_(runtime), + barrierTracer_(barrierTracerArg), + needsBarrier_(false) + {} + + bool needsBarrier() const { + return needsBarrier_; + } + + JSTracer *barrierTracer() { + MOZ_ASSERT(needsBarrier_); + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + return barrierTracer_; + } + + JSRuntime *runtimeFromMainThread() const { + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + return runtime_; + } + + // Note: Unrestricted access to the zone's runtime from an arbitrary + // thread can easily lead to races. Use this method very carefully. + JSRuntime *runtimeFromAnyThread() const { + return runtime_; + } + + static JS::shadow::Zone *asShadowZone(JS::Zone *zone) { + return reinterpret_cast(zone); + } +}; + +} /* namespace shadow */ +} /* namespace JS */ + +namespace js { +namespace gc { + +static MOZ_ALWAYS_INLINE uintptr_t * +GetGCThingMarkBitmap(const void *thing) +{ + MOZ_ASSERT(thing); + uintptr_t addr = uintptr_t(thing); + addr &= ~js::gc::ChunkMask; + addr |= js::gc::ChunkMarkBitmapOffset; + return reinterpret_cast(addr); +} + +static MOZ_ALWAYS_INLINE JS::shadow::Runtime * +GetGCThingRuntime(const void *thing) +{ + MOZ_ASSERT(thing); + uintptr_t addr = uintptr_t(thing); + addr &= ~js::gc::ChunkMask; + addr |= js::gc::ChunkRuntimeOffset; + return *reinterpret_cast(addr); +} + +static MOZ_ALWAYS_INLINE void +GetGCThingMarkWordAndMask(const void *thing, uint32_t color, + uintptr_t **wordp, uintptr_t *maskp) +{ + uintptr_t addr = uintptr_t(thing); + size_t bit = (addr & js::gc::ChunkMask) / js::gc::CellSize + color; + MOZ_ASSERT(bit < js::gc::ChunkMarkBitmapBits); + uintptr_t *bitmap = GetGCThingMarkBitmap(thing); + const uintptr_t nbits = sizeof(*bitmap) * CHAR_BIT; + *maskp = uintptr_t(1) << (bit % nbits); + *wordp = &bitmap[bit / nbits]; +} + +static MOZ_ALWAYS_INLINE JS::shadow::ArenaHeader * +GetGCThingArena(void *thing) +{ + uintptr_t addr = uintptr_t(thing); + addr &= ~js::gc::ArenaMask; + return reinterpret_cast(addr); +} + +MOZ_ALWAYS_INLINE bool +IsInsideNursery(const js::gc::Cell *cell) +{ +#ifdef JSGC_GENERATIONAL + if (!cell) + return false; + uintptr_t addr = uintptr_t(cell); + addr &= ~js::gc::ChunkMask; + addr |= js::gc::ChunkLocationOffset; + uint32_t location = *reinterpret_cast(addr); + JS_ASSERT(location != 0); + return location & ChunkLocationAnyNursery; +#else + return false; +#endif +} + +} /* namespace gc */ + +} /* namespace js */ + +namespace JS { + +static MOZ_ALWAYS_INLINE Zone * +GetGCThingZone(void *thing) +{ + MOZ_ASSERT(thing); + return js::gc::GetGCThingArena(thing)->zone; +} + +static MOZ_ALWAYS_INLINE Zone * +GetObjectZone(JSObject *obj) +{ + return GetGCThingZone(obj); +} + +static MOZ_ALWAYS_INLINE bool +GCThingIsMarkedGray(void *thing) +{ +#ifdef JSGC_GENERATIONAL + /* + * GC things residing in the nursery cannot be gray: they have no mark bits. + * All live objects in the nursery are moved to tenured at the beginning of + * each GC slice, so the gray marker never sees nursery things. + */ + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) + return false; +#endif + uintptr_t *word, mask; + js::gc::GetGCThingMarkWordAndMask(thing, js::gc::GRAY, &word, &mask); + return *word & mask; +} + +static MOZ_ALWAYS_INLINE bool +IsIncrementalBarrierNeededOnGCThing(shadow::Runtime *rt, void *thing, JSGCTraceKind kind) +{ + if (!rt->needsBarrier_) + return false; + JS::Zone *zone = GetGCThingZone(thing); + return reinterpret_cast(zone)->needsBarrier_; +} + +} /* namespace JS */ + +#endif /* js_HeapAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Id.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Id.h new file mode 100644 index 0000000000..11116f2efe --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Id.h @@ -0,0 +1,185 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_Id_h +#define js_Id_h + +// A jsid is an identifier for a property or method of an object which is +// either a 31-bit signed integer, interned string or object. +// +// Also, there is an additional jsid value, JSID_VOID, which does not occur in +// JS scripts but may be used to indicate the absence of a valid jsid. A void +// jsid is not a valid id and only arises as an exceptional API return value, +// such as in JS_NextProperty. Embeddings must not pass JSID_VOID into JSAPI +// entry points expecting a jsid and do not need to handle JSID_VOID in hooks +// receiving a jsid except when explicitly noted in the API contract. +// +// A jsid is not implicitly convertible to or from a jsval; JS_ValueToId or +// JS_IdToValue must be used instead. + +#include "mozilla/NullPtr.h" + +#include "jstypes.h" + +#include "js/HeapAPI.h" +#include "js/RootingAPI.h" +#include "js/TypeDecls.h" +#include "js/Utility.h" + +struct jsid +{ + size_t asBits; + bool operator==(jsid rhs) const { return asBits == rhs.asBits; } + bool operator!=(jsid rhs) const { return asBits != rhs.asBits; } +}; +#define JSID_BITS(id) (id.asBits) + +#define JSID_TYPE_STRING 0x0 +#define JSID_TYPE_INT 0x1 +#define JSID_TYPE_VOID 0x2 +#define JSID_TYPE_SYMBOL 0x4 +#define JSID_TYPE_MASK 0x7 + +// Avoid using canonical 'id' for jsid parameters since this is a magic word in +// Objective-C++ which, apparently, wants to be able to #include jsapi.h. +#define id iden + +static MOZ_ALWAYS_INLINE bool +JSID_IS_STRING(jsid id) +{ + return (JSID_BITS(id) & JSID_TYPE_MASK) == 0; +} + +static MOZ_ALWAYS_INLINE JSString * +JSID_TO_STRING(jsid id) +{ + MOZ_ASSERT(JSID_IS_STRING(id)); + return (JSString *)JSID_BITS(id); +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_ZERO(jsid id) +{ + return JSID_BITS(id) == 0; +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_INT(jsid id) +{ + return !!(JSID_BITS(id) & JSID_TYPE_INT); +} + +static MOZ_ALWAYS_INLINE int32_t +JSID_TO_INT(jsid id) +{ + MOZ_ASSERT(JSID_IS_INT(id)); + return ((uint32_t)JSID_BITS(id)) >> 1; +} + +#define JSID_INT_MIN 0 +#define JSID_INT_MAX INT32_MAX + +static MOZ_ALWAYS_INLINE bool +INT_FITS_IN_JSID(int32_t i) +{ + return i >= 0; +} + +static MOZ_ALWAYS_INLINE jsid +INT_TO_JSID(int32_t i) +{ + jsid id; + MOZ_ASSERT(INT_FITS_IN_JSID(i)); + JSID_BITS(id) = ((i << 1) | JSID_TYPE_INT); + return id; +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_SYMBOL(jsid id) +{ + return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_SYMBOL && + JSID_BITS(id) != JSID_TYPE_SYMBOL; +} + +static MOZ_ALWAYS_INLINE JS::Symbol * +JSID_TO_SYMBOL(jsid id) +{ + MOZ_ASSERT(JSID_IS_SYMBOL(id)); + return (JS::Symbol *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); +} + +static MOZ_ALWAYS_INLINE jsid +SYMBOL_TO_JSID(JS::Symbol *sym) +{ + jsid id; + MOZ_ASSERT(sym != nullptr); + MOZ_ASSERT((size_t(sym) & JSID_TYPE_MASK) == 0); + JS_ASSERT(!js::gc::IsInsideNursery(JS::AsCell(sym))); + JS_ASSERT(!JS::IsPoisonedPtr(sym)); + JSID_BITS(id) = (size_t(sym) | JSID_TYPE_SYMBOL); + return id; +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_GCTHING(jsid id) +{ + return JSID_IS_STRING(id) || JSID_IS_SYMBOL(id); +} + +static MOZ_ALWAYS_INLINE void * +JSID_TO_GCTHING(jsid id) +{ + return (void *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_VOID(const jsid id) +{ + MOZ_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID, + JSID_BITS(id) == JSID_TYPE_VOID); + return ((size_t)JSID_BITS(id) == JSID_TYPE_VOID); +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_EMPTY(const jsid id) +{ + return ((size_t)JSID_BITS(id) == JSID_TYPE_SYMBOL); +} + +extern JS_PUBLIC_DATA(const jsid) JSID_VOID; +extern JS_PUBLIC_DATA(const jsid) JSID_EMPTY; + +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_VOIDHANDLE; +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_EMPTYHANDLE; + +namespace js { + +inline bool +IsPoisonedId(jsid id) +{ + if (JSID_IS_STRING(id)) + return JS::IsPoisonedPtr(JSID_TO_STRING(id)); + if (JSID_IS_SYMBOL(id)) + return JS::IsPoisonedPtr(JSID_TO_SYMBOL(id)); + return false; +} + +template <> struct GCMethods +{ + static jsid initial() { return JSID_VOID; } + static bool poisoned(jsid id) { return IsPoisonedId(id); } + static bool needsPostBarrier(jsid id) { return false; } +#ifdef JSGC_GENERATIONAL + static void postBarrier(jsid *idp) {} + static void relocate(jsid *idp) {} +#endif +}; + +#undef id + +} + +#endif /* js_Id_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/LegacyIntTypes.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/LegacyIntTypes.h new file mode 100644 index 0000000000..2c8498c89e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/LegacyIntTypes.h @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * This section typedefs the old 'native' types to the new types. + * These redefinitions are provided solely to allow JSAPI users to more easily + * transition to types. They are not to be used in the JSAPI, and + * new JSAPI user code should not use them. This mapping file may eventually + * be removed from SpiderMonkey, so don't depend on it in the long run. + */ + +/* + * BEWARE: Comity with other implementers of these types is not guaranteed. + * Indeed, if you use this header and third-party code defining these + * types, *expect* to encounter either compile errors or link errors, + * depending how these types are used and on the order of inclusion. + * It is safest to use only the types. + */ +#ifndef js_LegacyIntTypes_h +#define js_LegacyIntTypes_h + +#include + +#include "js-config.h" + +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; +typedef uint64_t uint64; + +/* + * On AIX 4.3, sys/inttypes.h (which is included by sys/types.h, a very + * common header file) defines the types int8, int16, int32, and int64. + * So we don't define these four types here to avoid conflicts in case + * the code also includes sys/types.h. + */ +#if defined(AIX) && defined(HAVE_SYS_INTTYPES_H) +#include +#else +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; +typedef int64_t int64; +#endif /* AIX && HAVE_SYS_INTTYPES_H */ + +typedef uint8_t JSUint8; +typedef uint16_t JSUint16; +typedef uint32_t JSUint32; +typedef uint64_t JSUint64; + +typedef int8_t JSInt8; +typedef int16_t JSInt16; +typedef int32_t JSInt32; +typedef int64_t JSInt64; + +#endif /* js_LegacyIntTypes_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/MemoryMetrics.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/MemoryMetrics.h new file mode 100644 index 0000000000..31e456baba --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/MemoryMetrics.h @@ -0,0 +1,668 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_MemoryMetrics_h +#define js_MemoryMetrics_h + +// These declarations are highly likely to change in the future. Depend on them +// at your own risk. + +#include "mozilla/MemoryReporting.h" +#include "mozilla/NullPtr.h" +#include "mozilla/PodOperations.h" + +#include + +#include "jsalloc.h" +#include "jspubtd.h" + +#include "js/HashTable.h" +#include "js/Utility.h" +#include "js/Vector.h" + +class nsISupports; // Needed for ObjectPrivateVisitor. + +namespace JS { + +struct TabSizes +{ + enum Kind { + Objects, + Strings, + Private, + Other + }; + + TabSizes() { mozilla::PodZero(this); } + + void add(Kind kind, size_t n) { + switch (kind) { + case Objects: objects += n; break; + case Strings: strings += n; break; + case Private: private_ += n; break; + case Other: other += n; break; + default: MOZ_CRASH("bad TabSizes kind"); + } + } + + size_t objects; + size_t strings; + size_t private_; + size_t other; +}; + +} // namespace JS + +namespace js { + +// In memory reporting, we have concept of "sundries", line items which are too +// small to be worth reporting individually. Under some circumstances, a memory +// reporter gets tossed into the sundries bucket if it's smaller than +// MemoryReportingSundriesThreshold() bytes. +// +// We need to define this value here, rather than in the code which actually +// generates the memory reports, because NotableStringInfo uses this value. +JS_FRIEND_API(size_t) MemoryReportingSundriesThreshold(); + +// This hash policy avoids flattening ropes (which perturbs the site being +// measured and requires a JSContext) at the expense of doing a FULL ROPE COPY +// on every hash and match! Beware. +struct InefficientNonFlatteningStringHashPolicy +{ + typedef JSString *Lookup; + static HashNumber hash(const Lookup &l); + static bool match(const JSString *const &k, const Lookup &l); +}; + +struct CStringHashPolicy +{ + typedef const char *Lookup; + static HashNumber hash(const Lookup &l); + static bool match(const char *const &k, const Lookup &l); +}; + +// This file features many classes with numerous size_t fields, and each such +// class has one or more methods that need to operate on all of these fields. +// Writing these individually is error-prone -- it's easy to add a new field +// without updating all the required methods. So we define a single macro list +// in each class to name the fields (and notable characteristics of them), and +// then use the following macros to transform those lists into the required +// methods. +// +// In some classes, one or more of the macro arguments aren't used. We use '_' +// for those. +// +#define DECL_SIZE(kind, gc, mSize) size_t mSize; +#define ZERO_SIZE(kind, gc, mSize) mSize(0), +#define COPY_OTHER_SIZE(kind, gc, mSize) mSize(other.mSize), +#define ADD_OTHER_SIZE(kind, gc, mSize) mSize += other.mSize; +#define SUB_OTHER_SIZE(kind, gc, mSize) MOZ_ASSERT(mSize >= other.mSize); \ + mSize -= other.mSize; +#define ADD_SIZE_TO_N(kind, gc, mSize) n += mSize; +#define ADD_SIZE_TO_N_IF_LIVE_GC_THING(kind, gc, mSize) n += (js::gc) ? mSize : 0; +#define ADD_TO_TAB_SIZES(kind, gc, mSize) sizes->add(JS::TabSizes::kind, mSize); + +// Used to annotate which size_t fields measure live GC things and which don't. +enum { + NotLiveGCThing = false, + IsLiveGCThing = true +}; + +} // namespace js + +namespace JS { + +// Data for tracking memory usage of things hanging off objects. +struct ObjectsExtraSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(Objects, NotLiveGCThing, mallocHeapSlots) \ + macro(Objects, NotLiveGCThing, mallocHeapElementsNonAsmJS) \ + macro(Objects, NotLiveGCThing, mallocHeapElementsAsmJS) \ + macro(Objects, NotLiveGCThing, nonHeapElementsAsmJS) \ + macro(Objects, NotLiveGCThing, nonHeapElementsMapped) \ + macro(Objects, NotLiveGCThing, nonHeapCodeAsmJS) \ + macro(Objects, NotLiveGCThing, mallocHeapAsmJSModuleData) \ + macro(Objects, NotLiveGCThing, mallocHeapArgumentsData) \ + macro(Objects, NotLiveGCThing, mallocHeapRegExpStatics) \ + macro(Objects, NotLiveGCThing, mallocHeapPropertyIteratorData) \ + macro(Objects, NotLiveGCThing, mallocHeapCtypesData) + + ObjectsExtraSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + dummy() + {} + + void add(const ObjectsExtraSizes &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE) + } + + size_t sizeOfLiveGCThings() const { + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + return n; + } + + void addToTabSizes(TabSizes *sizes) const { + FOR_EACH_SIZE(ADD_TO_TAB_SIZES) + } + + FOR_EACH_SIZE(DECL_SIZE) + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) + +#undef FOR_EACH_SIZE +}; + +// Data for tracking JIT-code memory usage. +struct CodeSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, ion) \ + macro(_, _, baseline) \ + macro(_, _, regexp) \ + macro(_, _, other) \ + macro(_, _, unused) + + CodeSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + dummy() + {} + + FOR_EACH_SIZE(DECL_SIZE) + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) + +#undef FOR_EACH_SIZE +}; + +// Data for tracking GC memory usage. +struct GCSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, marker) \ + macro(_, _, nurseryCommitted) \ + macro(_, _, nurseryDecommitted) \ + macro(_, _, nurseryHugeSlots) \ + macro(_, _, storeBufferVals) \ + macro(_, _, storeBufferCells) \ + macro(_, _, storeBufferSlots) \ + macro(_, _, storeBufferWholeCells) \ + macro(_, _, storeBufferRelocVals) \ + macro(_, _, storeBufferRelocCells) \ + macro(_, _, storeBufferGenerics) + + GCSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + dummy() + {} + + FOR_EACH_SIZE(DECL_SIZE) + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) + +#undef FOR_EACH_SIZE +}; + +// This class holds information about the memory taken up by identical copies of +// a particular string. Multiple JSStrings may have their sizes aggregated +// together into one StringInfo object. Note that two strings with identical +// chars will not be aggregated together if one is a short string and the other +// is not. +struct StringInfo +{ +#define FOR_EACH_SIZE(macro) \ + macro(Strings, IsLiveGCThing, gcHeapLatin1) \ + macro(Strings, IsLiveGCThing, gcHeapTwoByte) \ + macro(Strings, NotLiveGCThing, mallocHeapLatin1) \ + macro(Strings, NotLiveGCThing, mallocHeapTwoByte) + + StringInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numCopies(0) + {} + + void add(const StringInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE); + numCopies++; + } + + void subtract(const StringInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE); + numCopies--; + } + + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + size_t sizeOfLiveGCThings() const { + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + return n; + } + + void addToTabSizes(TabSizes *sizes) const { + FOR_EACH_SIZE(ADD_TO_TAB_SIZES) + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numCopies; // How many copies of the string have we seen? + +#undef FOR_EACH_SIZE +}; + +// Holds data about a notable string (one which, counting all duplicates, uses +// more than a certain amount of memory) so we can report it individually. +// +// The only difference between this class and StringInfo is that +// NotableStringInfo holds a copy of some or all of the string's chars. +struct NotableStringInfo : public StringInfo +{ + static const size_t MAX_SAVED_CHARS = 1024; + + NotableStringInfo(); + NotableStringInfo(JSString *str, const StringInfo &info); + NotableStringInfo(NotableStringInfo &&info); + NotableStringInfo &operator=(NotableStringInfo &&info); + + ~NotableStringInfo() { + js_free(buffer); + } + + char *buffer; + size_t length; + + private: + NotableStringInfo(const NotableStringInfo& info) MOZ_DELETE; +}; + +// This class holds information about the memory taken up by script sources +// from a particular file. +struct ScriptSourceInfo +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, compressed) \ + macro(_, _, uncompressed) \ + macro(_, _, misc) + + ScriptSourceInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numScripts(0) + {} + + void add(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE) + numScripts++; + } + + void subtract(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE) + numScripts--; + } + + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numScripts; // How many ScriptSources come from this file? (It + // can be more than one in XML files that have + // multiple scripts in CDATA sections.) +#undef FOR_EACH_SIZE +}; + +// Holds data about a notable script source file (one whose combined +// script sources use more than a certain amount of memory) so we can report it +// individually. +// +// The only difference between this class and ScriptSourceInfo is that this +// class holds a copy of the filename. +struct NotableScriptSourceInfo : public ScriptSourceInfo +{ + NotableScriptSourceInfo(); + NotableScriptSourceInfo(const char *filename, const ScriptSourceInfo &info); + NotableScriptSourceInfo(NotableScriptSourceInfo &&info); + NotableScriptSourceInfo &operator=(NotableScriptSourceInfo &&info); + + ~NotableScriptSourceInfo() { + js_free(filename_); + } + + char *filename_; + + private: + NotableScriptSourceInfo(const NotableScriptSourceInfo& info) MOZ_DELETE; +}; + +// These measurements relate directly to the JSRuntime, and not to zones and +// compartments within it. +struct RuntimeSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, object) \ + macro(_, _, atomsTable) \ + macro(_, _, contexts) \ + macro(_, _, dtoa) \ + macro(_, _, temporary) \ + macro(_, _, interpreterStack) \ + macro(_, _, mathCache) \ + macro(_, _, uncompressedSourceCache) \ + macro(_, _, compressedSourceSet) \ + macro(_, _, scriptData) \ + + RuntimeSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + scriptSourceInfo(), + code(), + gc(), + notableScriptSources() + { + allScriptSources = js_new(); + if (!allScriptSources || !allScriptSources->init()) + MOZ_CRASH("oom"); + } + + ~RuntimeSizes() { + // |allScriptSources| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allScriptSources); + } + + // The script source measurements in |scriptSourceInfo| are initially for + // all script sources. At the end, if the measurement granularity is + // FineGrained, we subtract the measurements of the notable script sources + // and move them into |notableScriptSources|. + FOR_EACH_SIZE(DECL_SIZE) + ScriptSourceInfo scriptSourceInfo; + CodeSizes code; + GCSizes gc; + + typedef js::HashMap ScriptSourcesHashMap; + + // |allScriptSources| is only used transiently. During the reporting phase + // it is filled with info about every script source in the runtime. It's + // then used to fill in |notableScriptSources| (which actually gets + // reported), and immediately discarded afterwards. + ScriptSourcesHashMap *allScriptSources; + js::Vector notableScriptSources; + +#undef FOR_EACH_SIZE +}; + +struct ZoneStats +{ +#define FOR_EACH_SIZE(macro) \ + macro(Other, IsLiveGCThing, symbolsGCHeap) \ + macro(Other, NotLiveGCThing, gcHeapArenaAdmin) \ + macro(Other, NotLiveGCThing, unusedGCThings) \ + macro(Other, IsLiveGCThing, lazyScriptsGCHeap) \ + macro(Other, NotLiveGCThing, lazyScriptsMallocHeap) \ + macro(Other, IsLiveGCThing, jitCodesGCHeap) \ + macro(Other, IsLiveGCThing, typeObjectsGCHeap) \ + macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \ + macro(Other, NotLiveGCThing, typePool) \ + macro(Other, NotLiveGCThing, baselineStubsOptimized) \ + + ZoneStats() + : FOR_EACH_SIZE(ZERO_SIZE) + stringInfo(), + extra(), + allStrings(nullptr), + notableStrings(), + isTotals(true) + {} + + ZoneStats(ZoneStats &&other) + : FOR_EACH_SIZE(COPY_OTHER_SIZE) + stringInfo(mozilla::Move(other.stringInfo)), + extra(other.extra), + allStrings(other.allStrings), + notableStrings(mozilla::Move(other.notableStrings)), + isTotals(other.isTotals) + { + other.allStrings = nullptr; + MOZ_ASSERT(!other.isTotals); + } + + ~ZoneStats() { + // |allStrings| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allStrings); + } + + bool initStrings(JSRuntime *rt); + + void addSizes(const ZoneStats &other) { + MOZ_ASSERT(isTotals); + FOR_EACH_SIZE(ADD_OTHER_SIZE) + stringInfo.add(other.stringInfo); + } + + size_t sizeOfLiveGCThings() const { + MOZ_ASSERT(isTotals); + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + n += stringInfo.sizeOfLiveGCThings(); + return n; + } + + void addToTabSizes(JS::TabSizes *sizes) const { + MOZ_ASSERT(isTotals); + FOR_EACH_SIZE(ADD_TO_TAB_SIZES) + stringInfo.addToTabSizes(sizes); + } + + // These string measurements are initially for all strings. At the end, + // if the measurement granularity is FineGrained, we subtract the + // measurements of the notable script sources and move them into + // |notableStrings|. + FOR_EACH_SIZE(DECL_SIZE) + StringInfo stringInfo; + void *extra; // This field can be used by embedders. + + typedef js::HashMap StringsHashMap; + + // |allStrings| is only used transiently. During the zone traversal it is + // filled with info about every string in the zone. It's then used to fill + // in |notableStrings| (which actually gets reported), and immediately + // discarded afterwards. + StringsHashMap *allStrings; + js::Vector notableStrings; + bool isTotals; + +#undef FOR_EACH_SIZE +}; + +struct CompartmentStats +{ +#define FOR_EACH_SIZE(macro) \ + macro(Objects, IsLiveGCThing, objectsGCHeapOrdinary) \ + macro(Objects, IsLiveGCThing, objectsGCHeapFunction) \ + macro(Objects, IsLiveGCThing, objectsGCHeapDenseArray) \ + macro(Objects, IsLiveGCThing, objectsGCHeapSlowArray) \ + macro(Objects, IsLiveGCThing, objectsGCHeapCrossCompartmentWrapper) \ + macro(Private, NotLiveGCThing, objectsPrivate) \ + macro(Other, IsLiveGCThing, shapesGCHeapTreeGlobalParented) \ + macro(Other, IsLiveGCThing, shapesGCHeapTreeNonGlobalParented) \ + macro(Other, IsLiveGCThing, shapesGCHeapDict) \ + macro(Other, IsLiveGCThing, shapesGCHeapBase) \ + macro(Other, NotLiveGCThing, shapesMallocHeapTreeTables) \ + macro(Other, NotLiveGCThing, shapesMallocHeapDictTables) \ + macro(Other, NotLiveGCThing, shapesMallocHeapTreeShapeKids) \ + macro(Other, NotLiveGCThing, shapesMallocHeapCompartmentTables) \ + macro(Other, IsLiveGCThing, scriptsGCHeap) \ + macro(Other, NotLiveGCThing, scriptsMallocHeapData) \ + macro(Other, NotLiveGCThing, baselineData) \ + macro(Other, NotLiveGCThing, baselineStubsFallback) \ + macro(Other, NotLiveGCThing, ionData) \ + macro(Other, NotLiveGCThing, typeInferenceTypeScripts) \ + macro(Other, NotLiveGCThing, typeInferenceAllocationSiteTables) \ + macro(Other, NotLiveGCThing, typeInferenceArrayTypeTables) \ + macro(Other, NotLiveGCThing, typeInferenceObjectTypeTables) \ + macro(Other, NotLiveGCThing, compartmentObject) \ + macro(Other, NotLiveGCThing, crossCompartmentWrappersTable) \ + macro(Other, NotLiveGCThing, regexpCompartment) \ + macro(Other, NotLiveGCThing, debuggeesSet) \ + macro(Other, NotLiveGCThing, savedStacksSet) + + CompartmentStats() + : FOR_EACH_SIZE(ZERO_SIZE) + objectsExtra(), + extra() + {} + + CompartmentStats(const CompartmentStats &other) + : FOR_EACH_SIZE(COPY_OTHER_SIZE) + objectsExtra(other.objectsExtra), + extra(other.extra) + {} + + void add(const CompartmentStats &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE) + objectsExtra.add(other.objectsExtra); + // Do nothing with |extra|. + } + + size_t sizeOfLiveGCThings() const { + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + n += objectsExtra.sizeOfLiveGCThings(); + // Do nothing with |extra|. + return n; + } + + void addToTabSizes(TabSizes *sizes) const { + FOR_EACH_SIZE(ADD_TO_TAB_SIZES); + objectsExtra.addToTabSizes(sizes); + // Do nothing with |extra|. + } + + FOR_EACH_SIZE(DECL_SIZE) + ObjectsExtraSizes objectsExtra; + void *extra; // This field can be used by embedders. + +#undef FOR_EACH_SIZE +}; + +typedef js::Vector CompartmentStatsVector; +typedef js::Vector ZoneStatsVector; + +struct RuntimeStats +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, gcHeapChunkTotal) \ + macro(_, _, gcHeapDecommittedArenas) \ + macro(_, _, gcHeapUnusedChunks) \ + macro(_, _, gcHeapUnusedArenas) \ + macro(_, _, gcHeapChunkAdmin) \ + macro(_, _, gcHeapGCThings) \ + + explicit RuntimeStats(mozilla::MallocSizeOf mallocSizeOf) + : FOR_EACH_SIZE(ZERO_SIZE) + runtime(), + cTotals(), + zTotals(), + compartmentStatsVector(), + zoneStatsVector(), + currZoneStats(nullptr), + mallocSizeOf_(mallocSizeOf) + {} + + // Here's a useful breakdown of the GC heap. + // + // - rtStats.gcHeapChunkTotal + // - decommitted bytes + // - rtStats.gcHeapDecommittedArenas (decommitted arenas in non-empty chunks) + // - unused bytes + // - rtStats.gcHeapUnusedChunks (empty chunks) + // - rtStats.gcHeapUnusedArenas (empty arenas within non-empty chunks) + // - rtStats.zTotals.unusedGCThings (empty GC thing slots within non-empty arenas) + // - used bytes + // - rtStats.gcHeapChunkAdmin + // - rtStats.zTotals.gcHeapArenaAdmin + // - rtStats.gcHeapGCThings (in-use GC things) + // == rtStats.zTotals.sizeOfLiveGCThings() + rtStats.cTotals.sizeOfLiveGCThings() + // + // It's possible that some arenas in empty chunks may be decommitted, but + // we don't count those under rtStats.gcHeapDecommittedArenas because (a) + // it's rare, and (b) this means that rtStats.gcHeapUnusedChunks is a + // multiple of the chunk size, which is good. + + FOR_EACH_SIZE(DECL_SIZE) + + RuntimeSizes runtime; + + CompartmentStats cTotals; // The sum of this runtime's compartments' measurements. + ZoneStats zTotals; // The sum of this runtime's zones' measurements. + + CompartmentStatsVector compartmentStatsVector; + ZoneStatsVector zoneStatsVector; + + ZoneStats *currZoneStats; + + mozilla::MallocSizeOf mallocSizeOf_; + + virtual void initExtraCompartmentStats(JSCompartment *c, CompartmentStats *cstats) = 0; + virtual void initExtraZoneStats(JS::Zone *zone, ZoneStats *zstats) = 0; + +#undef FOR_EACH_SIZE +}; + +class ObjectPrivateVisitor +{ + public: + // Within CollectRuntimeStats, this method is called for each JS object + // that has an nsISupports pointer. + virtual size_t sizeOfIncludingThis(nsISupports *aSupports) = 0; + + // A callback that gets a JSObject's nsISupports pointer, if it has one. + // Note: this function does *not* addref |iface|. + typedef bool(*GetISupportsFun)(JSObject *obj, nsISupports **iface); + GetISupportsFun getISupports_; + + explicit ObjectPrivateVisitor(GetISupportsFun getISupports) + : getISupports_(getISupports) + {} +}; + +extern JS_PUBLIC_API(bool) +CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv, bool anonymize); + +extern JS_PUBLIC_API(size_t) +SystemCompartmentCount(JSRuntime *rt); + +extern JS_PUBLIC_API(size_t) +UserCompartmentCount(JSRuntime *rt); + +extern JS_PUBLIC_API(size_t) +PeakSizeOfTemporary(const JSRuntime *rt); + +extern JS_PUBLIC_API(bool) +AddSizeOfTab(JSRuntime *rt, JS::HandleObject obj, mozilla::MallocSizeOf mallocSizeOf, + ObjectPrivateVisitor *opv, TabSizes *sizes); + +} // namespace JS + +#undef DECL_SIZE +#undef ZERO_SIZE +#undef COPY_OTHER_SIZE +#undef ADD_OTHER_SIZE +#undef SUB_OTHER_SIZE +#undef ADD_SIZE_TO_N +#undef ADD_SIZE_TO_N_IF_LIVE_GC_THING +#undef ADD_TO_TAB_SIZES + +#endif /* js_MemoryMetrics_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/OldDebugAPI.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/OldDebugAPI.h new file mode 100644 index 0000000000..7117d754d9 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/OldDebugAPI.h @@ -0,0 +1,385 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_OldDebugAPI_h +#define js_OldDebugAPI_h + +/* + * JS debugger API. + */ + +#include "mozilla/NullPtr.h" + +#include "jsapi.h" +#include "jsbytecode.h" + +#include "js/CallArgs.h" +#include "js/TypeDecls.h" + +class JSAtom; +struct JSFreeOp; + +namespace js { +class InterpreterFrame; +class FrameIter; +class ScriptSource; +} + +// Raw JSScript* because this needs to be callable from a signal handler. +extern JS_PUBLIC_API(unsigned) +JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); + +extern JS_PUBLIC_API(const char *) +JS_GetScriptFilename(JSScript *script); + +namespace JS { + +extern JS_PUBLIC_API(char *) +FormatStackDump(JSContext *cx, char *buf, bool showArgs, bool showLocals, bool showThisProps); + +} // namespace JS + +# ifdef JS_DEBUG +JS_FRIEND_API(void) js_DumpValue(const JS::Value &val); +JS_FRIEND_API(void) js_DumpId(jsid id); +JS_FRIEND_API(void) js_DumpInterpreterFrame(JSContext *cx, js::InterpreterFrame *start = nullptr); +# endif + +JS_FRIEND_API(void) +js_DumpBacktrace(JSContext *cx); + +typedef enum JSTrapStatus { + JSTRAP_ERROR, + JSTRAP_CONTINUE, + JSTRAP_RETURN, + JSTRAP_THROW, + JSTRAP_LIMIT +} JSTrapStatus; + +typedef JSTrapStatus +(* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, + JS::Value closure); + +typedef JSTrapStatus +(* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, + void *closure); + +typedef bool +(* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, JS::Value old, + JS::Value *newp, void *closure); + + + +extern JS_PUBLIC_API(JSCompartment *) +JS_EnterCompartmentOfScript(JSContext *cx, JSScript *target); + +extern JS_PUBLIC_API(JSString *) +JS_DecompileScript(JSContext *cx, JS::HandleScript script, const char *name, unsigned indent); + +/* + * Currently, we only support runtime-wide debugging. In the future, we should + * be able to support compartment-wide debugging. + */ +extern JS_PUBLIC_API(void) +JS_SetRuntimeDebugMode(JSRuntime *rt, bool debug); + +/* + * Debug mode is a compartment-wide mode that enables a debugger to attach + * to and interact with running methodjit-ed frames. In particular, it causes + * every function to be compiled as if an eval was present (so eval-in-frame) + * can work, and it ensures that functions can be re-JITed for other debug + * features. In general, it is not safe to interact with frames that were live + * before debug mode was enabled. For this reason, it is also not safe to + * enable debug mode while frames are live. + */ + +/* Get current state of debugging mode. */ +extern JS_PUBLIC_API(bool) +JS_GetDebugMode(JSContext *cx); + +/* + * Turn on/off debugging mode for all compartments. This returns false if any code + * from any of the runtime's compartments is running or on the stack. + */ +JS_FRIEND_API(bool) +JS_SetDebugModeForAllCompartments(JSContext *cx, bool debug); + +/* + * Turn on/off debugging mode for a single compartment. This should only be + * used when no code from this compartment is running or on the stack in any + * thread. + */ +JS_FRIEND_API(bool) +JS_SetDebugModeForCompartment(JSContext *cx, JSCompartment *comp, bool debug); + +/* + * Turn on/off debugging mode for a context's compartment. + */ +JS_FRIEND_API(bool) +JS_SetDebugMode(JSContext *cx, bool debug); + +/* Turn on single step mode. */ +extern JS_PUBLIC_API(bool) +JS_SetSingleStepMode(JSContext *cx, JS::HandleScript script, bool singleStep); + +/* The closure argument will be marked. */ +extern JS_PUBLIC_API(bool) +JS_SetTrap(JSContext *cx, JS::HandleScript script, jsbytecode *pc, + JSTrapHandler handler, JS::HandleValue closure); + +extern JS_PUBLIC_API(void) +JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc, + JSTrapHandler *handlerp, JS::Value *closurep); + +extern JS_PUBLIC_API(void) +JS_ClearScriptTraps(JSRuntime *rt, JSScript *script); + +extern JS_PUBLIC_API(void) +JS_ClearAllTrapsForCompartment(JSContext *cx); + +/************************************************************************/ + +extern JS_PUBLIC_API(bool) +JS_SetWatchPoint(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JSWatchPointHandler handler, JS::HandleObject closure); + +extern JS_PUBLIC_API(bool) +JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id, + JSWatchPointHandler *handlerp, JSObject **closurep); + +extern JS_PUBLIC_API(bool) +JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj); + +/************************************************************************/ + +extern JS_PUBLIC_API(jsbytecode *) +JS_LineNumberToPC(JSContext *cx, JSScript *script, unsigned lineno); + +extern JS_PUBLIC_API(jsbytecode *) +JS_EndPC(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(bool) +JS_GetLinePCs(JSContext *cx, JSScript *script, + unsigned startLine, unsigned maxLines, + unsigned* count, unsigned** lines, jsbytecode*** pcs); + +extern JS_PUBLIC_API(unsigned) +JS_GetFunctionArgumentCount(JSContext *cx, JSFunction *fun); + +extern JS_PUBLIC_API(bool) +JS_FunctionHasLocalNames(JSContext *cx, JSFunction *fun); + +/* + * N.B. The mark is in the context temp pool and thus the caller must take care + * to call JS_ReleaseFunctionLocalNameArray in a LIFO manner (wrt to any other + * call that may use the temp pool. + */ +extern JS_PUBLIC_API(uintptr_t *) +JS_GetFunctionLocalNameArray(JSContext *cx, JSFunction *fun, void **markp); + +extern JS_PUBLIC_API(JSAtom *) +JS_LocalNameToAtom(uintptr_t w); + +extern JS_PUBLIC_API(JSString *) +JS_AtomKey(JSAtom *atom); + +extern JS_PUBLIC_API(void) +JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mark); + +extern JS_PUBLIC_API(JSScript *) +JS_GetFunctionScript(JSContext *cx, JS::HandleFunction fun); + +extern JS_PUBLIC_API(JSNative) +JS_GetFunctionNative(JSContext *cx, JSFunction *fun); + +JS_PUBLIC_API(JSFunction *) +JS_GetScriptFunction(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(JSObject *) +JS_GetParentOrScopeChain(JSContext *cx, JSObject *obj); + +/************************************************************************/ + +/* + * This is almost JS_GetClass(obj)->name except that certain debug-only + * proxies are made transparent. In particular, this function turns the class + * of any scope (returned via JS_GetFrameScopeChain or JS_GetFrameCalleeObject) + * from "Proxy" to "Call", "Block", "With" etc. + */ +extern JS_PUBLIC_API(const char *) +JS_GetDebugClassName(JSObject *obj); + +/************************************************************************/ + +extern JS_PUBLIC_API(const jschar *) +JS_GetScriptSourceMap(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(unsigned) +JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(unsigned) +JS_GetScriptLineExtent(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(JSVersion) +JS_GetScriptVersion(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(bool) +JS_GetScriptIsSelfHosted(JSScript *script); + +/************************************************************************/ + +typedef struct JSPropertyDesc { + JS::Value id; /* primary id, atomized string, or int */ + JS::Value value; /* property value */ + uint8_t flags; /* flags, see below */ + uint8_t spare; /* unused */ + JS::Value alias; /* alias id if JSPD_ALIAS flag */ +} JSPropertyDesc; + +#define JSPD_ENUMERATE 0x01 /* visible to for/in loop */ +#define JSPD_READONLY 0x02 /* assignment is error */ +#define JSPD_PERMANENT 0x04 /* property cannot be deleted */ +#define JSPD_ALIAS 0x08 /* property has an alias id */ +#define JSPD_EXCEPTION 0x40 /* exception occurred fetching the property, */ + /* value is exception */ +#define JSPD_ERROR 0x80 /* native getter returned false without */ + /* throwing an exception */ + +typedef struct JSPropertyDescArray { + uint32_t length; /* number of elements in array */ + JSPropertyDesc *array; /* alloc'd by Get, freed by Put */ +} JSPropertyDescArray; + +typedef struct JSScopeProperty JSScopeProperty; + +extern JS_PUBLIC_API(bool) +JS_GetPropertyDescArray(JSContext *cx, JS::HandleObject obj, JSPropertyDescArray *pda); + +extern JS_PUBLIC_API(void) +JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); + +/************************************************************************/ + +/* + * JSAbstractFramePtr is the public version of AbstractFramePtr, a pointer to a + * StackFrame or baseline JIT frame. + */ +class JS_PUBLIC_API(JSAbstractFramePtr) +{ + uintptr_t ptr_; + jsbytecode *pc_; + + protected: + JSAbstractFramePtr() + : ptr_(0), pc_(nullptr) + { } + + public: + JSAbstractFramePtr(void *raw, jsbytecode *pc); + + uintptr_t raw() const { return ptr_; } + jsbytecode *pc() const { return pc_; } + + operator bool() const { return !!ptr_; } + + JSObject *scopeChain(JSContext *cx); + JSObject *callObject(JSContext *cx); + + JSFunction *maybeFun(); + JSScript *script(); + + bool getThisValue(JSContext *cx, JS::MutableHandleValue thisv); + + bool isDebuggerFrame(); + + bool evaluateInStackFrame(JSContext *cx, + const char *bytes, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandleValue rval); + + bool evaluateUCInStackFrame(JSContext *cx, + const jschar *chars, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandleValue rval); +}; + +class JS_PUBLIC_API(JSNullFramePtr) : public JSAbstractFramePtr +{ + public: + JSNullFramePtr() + : JSAbstractFramePtr() + {} +}; + +/* + * This class does not work when IonMonkey is active. It's only used by jsd, + * which can only be used when IonMonkey is disabled. + * + * To find the calling script and line number, use JS_DescribeSciptedCaller. + * To summarize the call stack, use JS::DescribeStack. + */ +class JS_PUBLIC_API(JSBrokenFrameIterator) +{ + void *data_; + + public: + explicit JSBrokenFrameIterator(JSContext *cx); + ~JSBrokenFrameIterator(); + + bool done() const; + JSBrokenFrameIterator& operator++(); + + JSAbstractFramePtr abstractFramePtr() const; + jsbytecode *pc() const; + + bool isConstructing() const; +}; + +typedef bool +(* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report, + void *closure); + +typedef struct JSDebugHooks { + JSDebuggerHandler debuggerHandler; + void *debuggerHandlerData; +} JSDebugHooks; + +/************************************************************************/ + +extern JS_PUBLIC_API(bool) +JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler hook, void *closure); + +/************************************************************************/ + +extern JS_PUBLIC_API(const JSDebugHooks *) +JS_GetGlobalDebugHooks(JSRuntime *rt); + +/** + * Add various profiling-related functions as properties of the given object. + */ +extern JS_PUBLIC_API(bool) +JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj); + +/* Defined in vm/Debugger.cpp. */ +extern JS_PUBLIC_API(bool) +JS_DefineDebuggerObject(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(void) +JS_DumpPCCounts(JSContext *cx, JS::HandleScript script); + +extern JS_PUBLIC_API(void) +JS_DumpCompartmentPCCounts(JSContext *cx); + +namespace js { +extern JS_FRIEND_API(bool) +CanCallContextDebugHandler(JSContext *cx); +} + +/* Call the context debug handler on the topmost scripted frame. */ +extern JS_FRIEND_API(bool) +js_CallContextDebugHandler(JSContext *cx); + +#endif /* js_OldDebugAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Principals.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Principals.h new file mode 100644 index 0000000000..78d8c7e893 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Principals.h @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JSPrincipals and related interfaces. */ + +#ifndef js_Principals_h +#define js_Principals_h + +#include "mozilla/Atomics.h" + +#include + +#include "jspubtd.h" + +struct JSPrincipals { + /* Don't call "destroy"; use reference counting macros below. */ +#ifdef JS_THREADSAFE + mozilla::Atomic refcount; +#else + int32_t refcount; +#endif + +#ifdef JS_DEBUG + /* A helper to facilitate principals debugging. */ + uint32_t debugToken; +#endif + + void setDebugToken(uint32_t token) { +# ifdef JS_DEBUG + debugToken = token; +# endif + } + + /* + * This is not defined by the JS engine but should be provided by the + * embedding. + */ + JS_PUBLIC_API(void) dump(); +}; + +extern JS_PUBLIC_API(void) +JS_HoldPrincipals(JSPrincipals *principals); + +extern JS_PUBLIC_API(void) +JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals); + +// Return whether the first principal subsumes the second. The exact meaning of +// 'subsumes' is left up to the browser. Subsumption is checked inside the JS +// engine when determining, e.g., which stack frames to display in a backtrace. +typedef bool +(* JSSubsumesOp)(JSPrincipals *first, JSPrincipals *second); + +/* + * Used to check if a CSP instance wants to disable eval() and friends. + * See js_CheckCSPPermitsJSAction() in jsobj. + */ +typedef bool +(* JSCSPEvalChecker)(JSContext *cx); + +struct JSSecurityCallbacks { + JSCSPEvalChecker contentSecurityPolicyAllows; + JSSubsumesOp subsumes; +}; + +extern JS_PUBLIC_API(void) +JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks); + +extern JS_PUBLIC_API(const JSSecurityCallbacks *) +JS_GetSecurityCallbacks(JSRuntime *rt); + +/* + * Code running with "trusted" principals will be given a deeper stack + * allocation than ordinary scripts. This allows trusted script to run after + * untrusted script has exhausted the stack. This function sets the + * runtime-wide trusted principal. + * + * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since + * there is no available JSContext. Instead, the caller must ensure that the + * given principals stays valid for as long as 'rt' may point to it. If the + * principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be + * called again, passing nullptr for 'prin'. + */ +extern JS_PUBLIC_API(void) +JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin); + +typedef void +(* JSDestroyPrincipalsOp)(JSPrincipals *principals); + +/* + * Initialize the callback that is called to destroy JSPrincipals instance + * when its reference counter drops to zero. The initialization can be done + * only once per JS runtime. + */ +extern JS_PUBLIC_API(void) +JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals); + +#endif /* js_Principals_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/ProfilingStack.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/ProfilingStack.h new file mode 100644 index 0000000000..e82ce1c9d8 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/ProfilingStack.h @@ -0,0 +1,169 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_ProfilingStack_h +#define js_ProfilingStack_h + +#include "mozilla/NullPtr.h" +#include "mozilla/TypedEnum.h" + +#include "jsbytecode.h" +#include "jstypes.h" + +#include "js/Utility.h" + +struct JSRuntime; + +namespace js { + +// A call stack can be specified to the JS engine such that all JS entry/exits +// to functions push/pop an entry to/from the specified stack. +// +// For more detailed information, see vm/SPSProfiler.h. +// +class ProfileEntry +{ + // All fields are marked volatile to prevent the compiler from re-ordering + // instructions. Namely this sequence: + // + // entry[size] = ...; + // size++; + // + // If the size modification were somehow reordered before the stores, then + // if a sample were taken it would be examining bogus information. + // + // A ProfileEntry represents both a C++ profile entry and a JS one. + + // Descriptive string of this entry. + const char * volatile string; + + // Stack pointer for non-JS entries, the script pointer otherwise. + void * volatile spOrScript; + + // Line number for non-JS entries, the bytecode offset otherwise. + int32_t volatile lineOrPc; + + // General purpose storage describing this frame. + uint32_t volatile flags_; + + public: + // These traits are bit masks. Make sure they're powers of 2. + enum Flags { + // Indicate whether a profile entry represents a CPP frame. If not set, + // a JS frame is assumed by default. You're not allowed to publicly + // change the frame type. Instead, call `setJsFrame` or `setCppFrame`. + IS_CPP_ENTRY = 0x01, + + // Indicate that copying the frame label is not necessary when taking a + // sample of the pseudostack. + FRAME_LABEL_COPY = 0x02, + + // Mask for removing all flags except the category information. + CATEGORY_MASK = ~IS_CPP_ENTRY & ~FRAME_LABEL_COPY + }; + + MOZ_BEGIN_NESTED_ENUM_CLASS(Category, uint32_t) + OTHER = 0x04, + CSS = 0x08, + JS = 0x10, + GC = 0x20, + CC = 0x40, + NETWORK = 0x80, + GRAPHICS = 0x100, + STORAGE = 0x200, + EVENTS = 0x400, + + FIRST = OTHER, + LAST = EVENTS + MOZ_END_NESTED_ENUM_CLASS(Category) + + // All of these methods are marked with the 'volatile' keyword because SPS's + // representation of the stack is stored such that all ProfileEntry + // instances are volatile. These methods would not be available unless they + // were marked as volatile as well. + + bool isCpp() const volatile { return hasFlag(IS_CPP_ENTRY); } + bool isJs() const volatile { return !isCpp(); } + + bool isCopyLabel() const volatile { return hasFlag(FRAME_LABEL_COPY); }; + + void setLabel(const char *aString) volatile { string = aString; } + const char *label() const volatile { return string; } + + void setJsFrame(JSScript *aScript, jsbytecode *aPc) volatile { + flags_ = 0; + spOrScript = aScript; + setPC(aPc); + } + void setCppFrame(void *aSp, uint32_t aLine) volatile { + flags_ = IS_CPP_ENTRY; + spOrScript = aSp; + lineOrPc = static_cast(aLine); + } + + void setFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ |= flag; + } + void unsetFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ &= ~flag; + } + bool hasFlag(uint32_t flag) const volatile { + return bool(flags_ & flag); + } + + uint32_t flags() const volatile { + return flags_; + } + uint32_t category() const volatile { + return flags_ & CATEGORY_MASK; + } + + void *stackAddress() const volatile { + MOZ_ASSERT(!isJs()); + return spOrScript; + } + JSScript *script() const volatile { + MOZ_ASSERT(isJs()); + return (JSScript *)spOrScript; + } + uint32_t line() const volatile { + MOZ_ASSERT(!isJs()); + return static_cast(lineOrPc); + } + + // We can't know the layout of JSScript, so look in vm/SPSProfiler.cpp. + JS_FRIEND_API(jsbytecode *) pc() const volatile; + JS_FRIEND_API(void) setPC(jsbytecode *pc) volatile; + + // The offset of a pc into a script's code can actually be 0, so to + // signify a nullptr pc, use a -1 index. This is checked against in + // pc() and setPC() to set/get the right pc. + static const int32_t NullPCOffset = -1; + + static size_t offsetOfLabel() { return offsetof(ProfileEntry, string); } + static size_t offsetOfSpOrScript() { return offsetof(ProfileEntry, spOrScript); } + static size_t offsetOfLineOrPc() { return offsetof(ProfileEntry, lineOrPc); } + static size_t offsetOfFlags() { return offsetof(ProfileEntry, flags_); } +}; + +JS_FRIEND_API(void) +SetRuntimeProfilingStack(JSRuntime *rt, ProfileEntry *stack, uint32_t *size, + uint32_t max); + +JS_FRIEND_API(void) +EnableRuntimeProfilingStack(JSRuntime *rt, bool enabled); + +JS_FRIEND_API(void) +RegisterRuntimeProfilingEventMarker(JSRuntime *rt, void (*fn)(const char *)); + +JS_FRIEND_API(jsbytecode*) +ProfilingGetPC(JSRuntime *rt, JSScript *script, void *ip); + +} // namespace js + +#endif /* js_ProfilingStack_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/PropertyKey.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/PropertyKey.h new file mode 100644 index 0000000000..1f90653b40 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/PropertyKey.h @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JS::PropertyKey implementation. */ + +#ifndef js_PropertyKey_h +#define js_PropertyKey_h + +#include "js/TypeDecls.h" +#include "js/Value.h" + +namespace JS { + +class PropertyKey; + +namespace detail { + +extern JS_PUBLIC_API(bool) +ToPropertyKeySlow(JSContext *cx, HandleValue v, PropertyKey *key); + +} // namespace detail + +/* + * A PropertyKey is a key used to access some property on an object. It is a + * natural way to represent a property accessed using a JavaScript value. + * + * PropertyKey can represent indexes, named properties, and ES6 symbols. The + * latter aren't implemented in SpiderMonkey yet, but PropertyKey carves out + * space for them. + */ +class PropertyKey +{ + Value v; + friend JS_PUBLIC_API(bool) detail::ToPropertyKeySlow(JSContext *cx, HandleValue v, PropertyKey *key); + + public: + explicit PropertyKey(uint32_t index) : v(PrivateUint32Value(index)) {} + + /* + * An index is a string property name whose characters exactly spell out an + * unsigned 32-bit integer in decimal: "0", "1", "2", ...., "4294967294", + * "4294967295". + */ + bool isIndex(uint32_t *index) { + // The implementation here assumes that private uint32_t are stored + // using the int32_t representation. This is purely an implementation + // detail: embedders must not rely upon this! + if (!v.isInt32()) + return false; + *index = v.toPrivateUint32(); + return true; + } + + /* + * A name is a string property name which is *not* an index. Note that by + * the ECMAScript language grammar, any dotted property access |obj.prop| + * will access a named property. + */ + bool isName(JSString **str) { + uint32_t dummy; + if (isIndex(&dummy)) + return false; + *str = v.toString(); + return true; + } + + /* + * A symbol is a property name that's a Symbol, a particular kind of object + * in ES6. It is the only kind of property name that's not a string. + * + * SpiderMonkey doesn't yet implement symbols, but we're carving out API + * space for them in advance. + */ + bool isSymbol() { + return false; + } +}; + +inline bool +ToPropertyKey(JSContext *cx, HandleValue v, PropertyKey *key) +{ + if (v.isInt32() && v.toInt32() >= 0) { + *key = PropertyKey(uint32_t(v.toInt32())); + return true; + } + + return detail::ToPropertyKeySlow(cx, v, key); +} + +} // namespace JS + +#endif /* js_PropertyKey_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/RequiredDefines.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/RequiredDefines.h new file mode 100644 index 0000000000..308fd7d625 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/RequiredDefines.h @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Various #defines required to build SpiderMonkey. Embedders should add this + * file to the start of the command line via -include or a similar mechanism, + * or SpiderMonkey public headers may not work correctly. + */ + +#ifndef js_RequiredDefines_h +#define js_RequiredDefines_h + +/* + * The c99 defining the limit macros (UINT32_MAX for example), says: + * + * C++ implementations should define these macros only when + * __STDC_LIMIT_MACROS is defined before is included. + * + * The same also occurs with __STDC_CONSTANT_MACROS for the constant macros + * (INT8_C for example) used to specify a literal constant of the proper type, + * and with __STDC_FORMAT_MACROS for the format macros (PRId32 for example) used + * with the fprintf function family. + */ +#define __STDC_LIMIT_MACROS +#define __STDC_CONSTANT_MACROS +#define __STDC_FORMAT_MACROS + +/* Also define a char16_t type if not provided by the compiler. */ +#include "mozilla/Char16.h" + +#endif /* js_RequiredDefines_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/RootingAPI.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/RootingAPI.h new file mode 100644 index 0000000000..621a1e4394 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/RootingAPI.h @@ -0,0 +1,1253 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_RootingAPI_h +#define js_RootingAPI_h + +#include "mozilla/Attributes.h" +#include "mozilla/GuardObjects.h" +#include "mozilla/LinkedList.h" +#include "mozilla/NullPtr.h" +#include "mozilla/TypeTraits.h" + +#include "jspubtd.h" + +#include "js/GCAPI.h" +#include "js/HeapAPI.h" +#include "js/TypeDecls.h" +#include "js/Utility.h" + +/* + * Moving GC Stack Rooting + * + * A moving GC may change the physical location of GC allocated things, even + * when they are rooted, updating all pointers to the thing to refer to its new + * location. The GC must therefore know about all live pointers to a thing, + * not just one of them, in order to behave correctly. + * + * The |Rooted| and |Handle| classes below are used to root stack locations + * whose value may be held live across a call that can trigger GC. For a + * code fragment such as: + * + * JSObject *obj = NewObject(cx); + * DoSomething(cx); + * ... = obj->lastProperty(); + * + * If |DoSomething()| can trigger a GC, the stack location of |obj| must be + * rooted to ensure that the GC does not move the JSObject referred to by + * |obj| without updating |obj|'s location itself. This rooting must happen + * regardless of whether there are other roots which ensure that the object + * itself will not be collected. + * + * If |DoSomething()| cannot trigger a GC, and the same holds for all other + * calls made between |obj|'s definitions and its last uses, then no rooting + * is required. + * + * SpiderMonkey can trigger a GC at almost any time and in ways that are not + * always clear. For example, the following innocuous-looking actions can + * cause a GC: allocation of any new GC thing; JSObject::hasProperty; + * JS_ReportError and friends; and ToNumber, among many others. The following + * dangerous-looking actions cannot trigger a GC: js_malloc, cx->malloc_, + * rt->malloc_, and friends and JS_ReportOutOfMemory. + * + * The following family of three classes will exactly root a stack location. + * Incorrect usage of these classes will result in a compile error in almost + * all cases. Therefore, it is very hard to be incorrectly rooted if you use + * these classes exclusively. These classes are all templated on the type T of + * the value being rooted. + * + * - Rooted declares a variable of type T, whose value is always rooted. + * Rooted may be automatically coerced to a Handle, below. Rooted + * should be used whenever a local variable's value may be held live across a + * call which can trigger a GC. + * + * - Handle is a const reference to a Rooted. Functions which take GC + * things or values as arguments and need to root those arguments should + * generally use handles for those arguments and avoid any explicit rooting. + * This has two benefits. First, when several such functions call each other + * then redundant rooting of multiple copies of the GC thing can be avoided. + * Second, if the caller does not pass a rooted value a compile error will be + * generated, which is quicker and easier to fix than when relying on a + * separate rooting analysis. + * + * - MutableHandle is a non-const reference to Rooted. It is used in the + * same way as Handle and includes a |set(const T &v)| method to allow + * updating the value of the referenced Rooted. A MutableHandle can be + * created from a Rooted by using |Rooted::operator&()|. + * + * In some cases the small performance overhead of exact rooting (measured to + * be a few nanoseconds on desktop) is too much. In these cases, try the + * following: + * + * - Move all Rooted above inner loops: this allows you to re-use the root + * on each iteration of the loop. + * + * - Pass Handle through your hot call stack to avoid re-rooting costs at + * every invocation. + * + * The following diagram explains the list of supported, implicit type + * conversions between classes of this family: + * + * Rooted ----> Handle + * | ^ + * | | + * | | + * +---> MutableHandle + * (via &) + * + * All of these types have an implicit conversion to raw pointers. + */ + +namespace js { + +class ScriptSourceObject; + +template +struct GCMethods {}; + +template +class RootedBase {}; + +template +class HandleBase {}; + +template +class MutableHandleBase {}; + +template +class HeapBase {}; + +/* + * js::NullPtr acts like a nullptr pointer in contexts that require a Handle. + * + * Handle provides an implicit constructor for js::NullPtr so that, given: + * foo(Handle h); + * callers can simply write: + * foo(js::NullPtr()); + * which avoids creating a Rooted just to pass nullptr. + * + * This is the SpiderMonkey internal variant. js::NullPtr should be used in + * preference to JS::NullPtr to avoid the GOT access required for JS_PUBLIC_API + * symbols. + */ +struct NullPtr +{ + static void * const constNullValue; +}; + +namespace gc { +struct Cell; +template +struct PersistentRootedMarker; +} /* namespace gc */ + +} /* namespace js */ + +namespace JS { + +template class Rooted; +template class PersistentRooted; + +/* This is exposing internal state of the GC for inlining purposes. */ +JS_FRIEND_API(bool) isGCEnabled(); + +/* + * JS::NullPtr acts like a nullptr pointer in contexts that require a Handle. + * + * Handle provides an implicit constructor for JS::NullPtr so that, given: + * foo(Handle h); + * callers can simply write: + * foo(JS::NullPtr()); + * which avoids creating a Rooted just to pass nullptr. + */ +struct JS_PUBLIC_API(NullPtr) +{ + static void * const constNullValue; +}; + +/* + * The Heap class is a heap-stored reference to a JS GC thing. All members of + * heap classes that refer to GC things should use Heap (or possibly + * TenuredHeap, described below). + * + * Heap is an abstraction that hides some of the complexity required to + * maintain GC invariants for the contained reference. It uses operator + * overloading to provide a normal pointer interface, but notifies the GC every + * time the value it contains is updated. This is necessary for generational GC, + * which keeps track of all pointers into the nursery. + * + * Heap instances must be traced when their containing object is traced to + * keep the pointed-to GC thing alive. + * + * Heap objects should only be used on the heap. GC references stored on the + * C/C++ stack must use Rooted/Handle/MutableHandle instead. + * + * Type T must be one of: JS::Value, jsid, JSObject*, JSString*, JSScript* + */ +template +class Heap : public js::HeapBase +{ + public: + Heap() { + static_assert(sizeof(T) == sizeof(Heap), + "Heap must be binary compatible with T."); + init(js::GCMethods::initial()); + } + explicit Heap(T p) { init(p); } + + /* + * For Heap, move semantics are equivalent to copy semantics. In C++, a + * copy constructor taking const-ref is the way to get a single function + * that will be used for both lvalue and rvalue copies, so we can simply + * omit the rvalue variant. + */ + explicit Heap(const Heap &p) { init(p.ptr); } + + ~Heap() { + if (js::GCMethods::needsPostBarrier(ptr)) + relocate(); + } + + bool operator==(const Heap &other) { return ptr == other.ptr; } + bool operator!=(const Heap &other) { return ptr != other.ptr; } + + bool operator==(const T &other) const { return ptr == other; } + bool operator!=(const T &other) const { return ptr != other; } + + operator T() const { return ptr; } + T operator->() const { return ptr; } + const T *address() const { return &ptr; } + const T &get() const { return ptr; } + + T *unsafeGet() { return &ptr; } + + Heap &operator=(T p) { + set(p); + return *this; + } + + Heap &operator=(const Heap& other) { + set(other.get()); + return *this; + } + + void set(T newPtr) { + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); + if (js::GCMethods::needsPostBarrier(newPtr)) { + ptr = newPtr; + post(); + } else if (js::GCMethods::needsPostBarrier(ptr)) { + relocate(); /* Called before overwriting ptr. */ + ptr = newPtr; + } else { + ptr = newPtr; + } + } + + /* + * Set the pointer to a value which will cause a crash if it is + * dereferenced. + */ + void setToCrashOnTouch() { + ptr = reinterpret_cast(crashOnTouchPointer); + } + + bool isSetToCrashOnTouch() { + return ptr == crashOnTouchPointer; + } + + private: + void init(T newPtr) { + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); + ptr = newPtr; + if (js::GCMethods::needsPostBarrier(ptr)) + post(); + } + + void post() { +#ifdef JSGC_GENERATIONAL + MOZ_ASSERT(js::GCMethods::needsPostBarrier(ptr)); + js::GCMethods::postBarrier(&ptr); +#endif + } + + void relocate() { +#ifdef JSGC_GENERATIONAL + js::GCMethods::relocate(&ptr); +#endif + } + + enum { + crashOnTouchPointer = 1 + }; + + T ptr; +}; + +#ifdef JS_DEBUG +/* + * For generational GC, assert that an object is in the tenured generation as + * opposed to being in the nursery. + */ +extern JS_FRIEND_API(void) +AssertGCThingMustBeTenured(JSObject* obj); +#else +inline void +AssertGCThingMustBeTenured(JSObject *obj) {} +#endif + +/* + * The TenuredHeap class is similar to the Heap class above in that it + * encapsulates the GC concerns of an on-heap reference to a JS object. However, + * it has two important differences: + * + * 1) Pointers which are statically known to only reference "tenured" objects + * can avoid the extra overhead of SpiderMonkey's write barriers. + * + * 2) Objects in the "tenured" heap have stronger alignment restrictions than + * those in the "nursery", so it is possible to store flags in the lower + * bits of pointers known to be tenured. TenuredHeap wraps a normal tagged + * pointer with a nice API for accessing the flag bits and adds various + * assertions to ensure that it is not mis-used. + * + * GC things are said to be "tenured" when they are located in the long-lived + * heap: e.g. they have gained tenure as an object by surviving past at least + * one GC. For performance, SpiderMonkey allocates some things which are known + * to normally be long lived directly into the tenured generation; for example, + * global objects. Additionally, SpiderMonkey does not visit individual objects + * when deleting non-tenured objects, so object with finalizers are also always + * tenured; for instance, this includes most DOM objects. + * + * The considerations to keep in mind when using a TenuredHeap vs a normal + * Heap are: + * + * - It is invalid for a TenuredHeap to refer to a non-tenured thing. + * - It is however valid for a Heap to refer to a tenured thing. + * - It is not possible to store flag bits in a Heap. + */ +template +class TenuredHeap : public js::HeapBase +{ + public: + TenuredHeap() : bits(0) { + static_assert(sizeof(T) == sizeof(TenuredHeap), + "TenuredHeap must be binary compatible with T."); + } + explicit TenuredHeap(T p) : bits(0) { setPtr(p); } + explicit TenuredHeap(const TenuredHeap &p) : bits(0) { setPtr(p.getPtr()); } + + bool operator==(const TenuredHeap &other) { return bits == other.bits; } + bool operator!=(const TenuredHeap &other) { return bits != other.bits; } + + void setPtr(T newPtr) { + MOZ_ASSERT((reinterpret_cast(newPtr) & flagsMask) == 0); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); + if (newPtr) + AssertGCThingMustBeTenured(newPtr); + bits = (bits & flagsMask) | reinterpret_cast(newPtr); + } + + void setFlags(uintptr_t flagsToSet) { + MOZ_ASSERT((flagsToSet & ~flagsMask) == 0); + bits |= flagsToSet; + } + + void unsetFlags(uintptr_t flagsToUnset) { + MOZ_ASSERT((flagsToUnset & ~flagsMask) == 0); + bits &= ~flagsToUnset; + } + + bool hasFlag(uintptr_t flag) const { + MOZ_ASSERT((flag & ~flagsMask) == 0); + return (bits & flag) != 0; + } + + T getPtr() const { return reinterpret_cast(bits & ~flagsMask); } + uintptr_t getFlags() const { return bits & flagsMask; } + + operator T() const { return getPtr(); } + T operator->() const { return getPtr(); } + + TenuredHeap &operator=(T p) { + setPtr(p); + return *this; + } + + TenuredHeap &operator=(const TenuredHeap& other) { + bits = other.bits; + return *this; + } + + private: + enum { + maskBits = 3, + flagsMask = (1 << maskBits) - 1, + }; + + uintptr_t bits; +}; + +/* + * Reference to a T that has been rooted elsewhere. This is most useful + * as a parameter type, which guarantees that the T lvalue is properly + * rooted. See "Move GC Stack Rooting" above. + * + * If you want to add additional methods to Handle for a specific + * specialization, define a HandleBase specialization containing them. + */ +template +class MOZ_NONHEAP_CLASS Handle : public js::HandleBase +{ + friend class JS::MutableHandle; + + public: + /* Creates a handle from a handle of a type convertible to T. */ + template + Handle(Handle handle, + typename mozilla::EnableIf::value, int>::Type dummy = 0) + { + static_assert(sizeof(Handle) == sizeof(T *), + "Handle must be binary compatible with T*."); + ptr = reinterpret_cast(handle.address()); + } + + /* Create a handle for a nullptr pointer. */ + MOZ_IMPLICIT Handle(js::NullPtr) { + static_assert(mozilla::IsPointer::value, + "js::NullPtr overload not valid for non-pointer types"); + ptr = reinterpret_cast(&js::NullPtr::constNullValue); + } + + /* Create a handle for a nullptr pointer. */ + MOZ_IMPLICIT Handle(JS::NullPtr) { + static_assert(mozilla::IsPointer::value, + "JS::NullPtr overload not valid for non-pointer types"); + ptr = reinterpret_cast(&JS::NullPtr::constNullValue); + } + + MOZ_IMPLICIT Handle(MutableHandle handle) { + ptr = handle.address(); + } + + /* + * Take care when calling this method! + * + * This creates a Handle from the raw location of a T. + * + * It should be called only if the following conditions hold: + * + * 1) the location of the T is guaranteed to be marked (for some reason + * other than being a Rooted), e.g., if it is guaranteed to be reachable + * from an implicit root. + * + * 2) the contents of the location are immutable, or at least cannot change + * for the lifetime of the handle, as its users may not expect its value + * to change underneath them. + */ + static MOZ_CONSTEXPR Handle fromMarkedLocation(const T *p) { + return Handle(p, DeliberatelyChoosingThisOverload, + ImUsingThisOnlyInFromFromMarkedLocation); + } + + /* + * Construct a handle from an explicitly rooted location. This is the + * normal way to create a handle, and normally happens implicitly. + */ + template + inline + Handle(const Rooted &root, + typename mozilla::EnableIf::value, int>::Type dummy = 0); + + template + inline + Handle(const PersistentRooted &root, + typename mozilla::EnableIf::value, int>::Type dummy = 0); + + /* Construct a read only handle from a mutable handle. */ + template + inline + Handle(MutableHandle &root, + typename mozilla::EnableIf::value, int>::Type dummy = 0); + + const T *address() const { return ptr; } + const T& get() const { return *ptr; } + + /* + * Return a reference so passing a Handle to something that + * takes a |const T&| is not a GC hazard. + */ + operator const T&() const { return get(); } + T operator->() const { return get(); } + + bool operator!=(const T &other) const { return *ptr != other; } + bool operator==(const T &other) const { return *ptr == other; } + + private: + Handle() {} + + enum Disambiguator { DeliberatelyChoosingThisOverload = 42 }; + enum CallerIdentity { ImUsingThisOnlyInFromFromMarkedLocation = 17 }; + MOZ_CONSTEXPR Handle(const T *p, Disambiguator, CallerIdentity) : ptr(p) {} + + const T *ptr; + + template void operator=(S) MOZ_DELETE; + void operator=(Handle) MOZ_DELETE; +}; + +/* + * Similar to a handle, but the underlying storage can be changed. This is + * useful for outparams. + * + * If you want to add additional methods to MutableHandle for a specific + * specialization, define a MutableHandleBase specialization containing + * them. + */ +template +class MOZ_STACK_CLASS MutableHandle : public js::MutableHandleBase +{ + public: + inline MOZ_IMPLICIT MutableHandle(Rooted *root); + inline MOZ_IMPLICIT MutableHandle(PersistentRooted *root); + + private: + // Disallow true nullptr and emulated nullptr (gcc 4.4/4.5, __null, appears + // as int/long [32/64-bit]) for overloading purposes. + template + MutableHandle(N, + typename mozilla::EnableIf::value || + mozilla::IsSame::value || + mozilla::IsSame::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + void set(T v) { + MOZ_ASSERT(!js::GCMethods::poisoned(v)); + *ptr = v; + } + + /* + * This may be called only if the location of the T is guaranteed + * to be marked (for some reason other than being a Rooted), + * e.g., if it is guaranteed to be reachable from an implicit root. + * + * Create a MutableHandle from a raw location of a T. + */ + static MutableHandle fromMarkedLocation(T *p) { + MutableHandle h; + h.ptr = p; + return h; + } + + T *address() const { return ptr; } + const T& get() const { return *ptr; } + + /* + * Return a reference so passing a MutableHandle to something that takes + * a |const T&| is not a GC hazard. + */ + operator const T&() const { return get(); } + T operator->() const { return get(); } + + private: + MutableHandle() {} + + T *ptr; + + template void operator=(S v) MOZ_DELETE; + void operator=(MutableHandle other) MOZ_DELETE; +}; + +#ifdef JSGC_GENERATIONAL +JS_FRIEND_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); +JS_FRIEND_API(void) HeapCellRelocate(js::gc::Cell **cellp); +#endif + +} /* namespace JS */ + +namespace js { + +/* + * InternalHandle is a handle to an internal pointer into a gcthing. Use + * InternalHandle when you have a pointer to a direct field of a gcthing, or + * when you need a parameter type for something that *may* be a pointer to a + * direct field of a gcthing. + */ +template +class InternalHandle {}; + +template +class InternalHandle +{ + void * const *holder; + size_t offset; + + public: + /* + * Create an InternalHandle using a Handle to the gcthing containing the + * field in question, and a pointer to the field. + */ + template + InternalHandle(const JS::Handle &handle, T *field) + : holder((void**)handle.address()), offset(uintptr_t(field) - uintptr_t(handle.get())) + {} + + /* + * Create an InternalHandle to a field within a Rooted<>. + */ + template + InternalHandle(const JS::Rooted &root, T *field) + : holder((void**)root.address()), offset(uintptr_t(field) - uintptr_t(root.get())) + {} + + InternalHandle(const InternalHandle& other) + : holder(other.holder), offset(other.offset) {} + + T *get() const { return reinterpret_cast(uintptr_t(*holder) + offset); } + + const T &operator*() const { return *get(); } + T *operator->() const { return get(); } + + static InternalHandle fromMarkedLocation(T *fieldPtr) { + return InternalHandle(fieldPtr); + } + + private: + /* + * Create an InternalHandle to something that is not a pointer to a + * gcthing, and so does not need to be rooted in the first place. Use these + * InternalHandles to pass pointers into functions that also need to accept + * regular InternalHandles to gcthing fields. + * + * Make this private to prevent accidental misuse; this is only for + * fromMarkedLocation(). + */ + explicit InternalHandle(T *field) + : holder(reinterpret_cast(&js::NullPtr::constNullValue)), + offset(uintptr_t(field)) + {} + + void operator=(InternalHandle other) MOZ_DELETE; +}; + +/* + * By default, things should use the inheritance hierarchy to find their + * ThingRootKind. Some pointer types are explicitly set in jspubtd.h so that + * Rooted may be used without the class definition being available. + */ +template +struct RootKind +{ + static ThingRootKind rootKind() { return T::rootKind(); } +}; + +template +struct RootKind +{ + static ThingRootKind rootKind() { return T::rootKind(); } +}; + +template +struct GCMethods +{ + static T *initial() { return nullptr; } + static bool poisoned(T *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(T *v) { return false; } +#ifdef JSGC_GENERATIONAL + static void postBarrier(T **vp) {} + static void relocate(T **vp) {} +#endif +}; + +template <> +struct GCMethods +{ + static JSObject *initial() { return nullptr; } + static bool poisoned(JSObject *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSObject *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSObject **vp) { + JS::HeapCellPostBarrier(reinterpret_cast(vp)); + } + static void relocate(JSObject **vp) { + JS::HeapCellRelocate(reinterpret_cast(vp)); + } +#endif +}; + +template <> +struct GCMethods +{ + static JSFunction *initial() { return nullptr; } + static bool poisoned(JSFunction *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSFunction *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSFunction **vp) { + JS::HeapCellPostBarrier(reinterpret_cast(vp)); + } + static void relocate(JSFunction **vp) { + JS::HeapCellRelocate(reinterpret_cast(vp)); + } +#endif +}; + +#ifdef JS_DEBUG +/* This helper allows us to assert that Rooted is scoped within a request. */ +extern JS_PUBLIC_API(bool) +IsInRequest(JSContext *cx); +#endif + +} /* namespace js */ + +namespace JS { + +/* + * Local variable of type T whose value is always rooted. This is typically + * used for local variables, or for non-rooted values being passed to a + * function that requires a handle, e.g. Foo(Root(cx, x)). + * + * If you want to add additional methods to Rooted for a specific + * specialization, define a RootedBase specialization containing them. + */ +template +class MOZ_STACK_CLASS Rooted : public js::RootedBase +{ + /* Note: CX is a subclass of either ContextFriendFields or PerThreadDataFriendFields. */ + template + void init(CX *cx) { +#ifdef JSGC_TRACK_EXACT_ROOTS + js::ThingRootKind kind = js::RootKind::rootKind(); + this->stack = &cx->thingGCRooters[kind]; + this->prev = *stack; + *stack = reinterpret_cast*>(this); + + MOZ_ASSERT(!js::GCMethods::poisoned(ptr)); +#endif + } + + public: + explicit Rooted(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(js::GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG + MOZ_ASSERT(js::IsInRequest(cx)); +#endif + init(js::ContextFriendFields::get(cx)); + } + + Rooted(JSContext *cx, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG + MOZ_ASSERT(js::IsInRequest(cx)); +#endif + init(js::ContextFriendFields::get(cx)); + } + + explicit Rooted(js::ContextFriendFields *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(js::GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(cx); + } + + Rooted(js::ContextFriendFields *cx, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(cx); + } + + explicit Rooted(js::PerThreadDataFriendFields *pt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(js::GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(pt); + } + + Rooted(js::PerThreadDataFriendFields *pt, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(pt); + } + + explicit Rooted(JSRuntime *rt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(js::GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(js::PerThreadDataFriendFields::getMainThread(rt)); + } + + Rooted(JSRuntime *rt, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(js::PerThreadDataFriendFields::getMainThread(rt)); + } + + // Note that we need to let the compiler generate the default destructor in + // non-exact-rooting builds because of a bug in the instrumented PGO builds + // using MSVC, see bug 915735 for more details. +#ifdef JSGC_TRACK_EXACT_ROOTS + ~Rooted() { + MOZ_ASSERT(*stack == reinterpret_cast*>(this)); + *stack = prev; + } +#endif + +#ifdef JSGC_TRACK_EXACT_ROOTS + Rooted *previous() { return reinterpret_cast*>(prev); } +#endif + + /* + * Important: Return a reference here so passing a Rooted to + * something that takes a |const T&| is not a GC hazard. + */ + operator const T&() const { return ptr; } + T operator->() const { return ptr; } + T *address() { return &ptr; } + const T *address() const { return &ptr; } + T &get() { return ptr; } + const T &get() const { return ptr; } + + T &operator=(T value) { + MOZ_ASSERT(!js::GCMethods::poisoned(value)); + ptr = value; + return ptr; + } + + T &operator=(const Rooted &value) { + ptr = value; + return ptr; + } + + void set(T value) { + MOZ_ASSERT(!js::GCMethods::poisoned(value)); + ptr = value; + } + + bool operator!=(const T &other) const { return ptr != other; } + bool operator==(const T &other) const { return ptr == other; } + + private: +#ifdef JSGC_TRACK_EXACT_ROOTS + /* + * These need to be templated on void* to avoid aliasing issues between, for + * example, Rooted and Rooted, which use the same + * stack head pointer for different classes. + */ + Rooted **stack, *prev; +#endif + + /* + * |ptr| must be the last field in Rooted because the analysis treats all + * Rooted as Rooted during the analysis. See bug 829372. + */ + T ptr; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + Rooted(const Rooted &) MOZ_DELETE; +}; + +} /* namespace JS */ + +namespace js { + +/* + * Augment the generic Rooted interface when T = JSObject* with + * class-querying and downcasting operations. + * + * Given a Rooted obj, one can view + * Handle h = obj.as(); + * as an optimization of + * Rooted rooted(cx, &obj->as()); + * Handle h = rooted; + */ +template <> +class RootedBase +{ + public: + template + JS::Handle as() const; +}; + +/* Interface substitute for Rooted which does not root the variable's memory. */ +template +class FakeRooted : public RootedBase +{ + public: + template + FakeRooted(CX *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + template + FakeRooted(CX *cx, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + operator T() const { return ptr; } + T operator->() const { return ptr; } + T *address() { return &ptr; } + const T *address() const { return &ptr; } + T &get() { return ptr; } + const T &get() const { return ptr; } + + FakeRooted &operator=(T value) { + MOZ_ASSERT(!GCMethods::poisoned(value)); + ptr = value; + return *this; + } + + FakeRooted &operator=(const FakeRooted &other) { + MOZ_ASSERT(!GCMethods::poisoned(other.ptr)); + ptr = other.ptr; + return *this; + } + + bool operator!=(const T &other) const { return ptr != other; } + bool operator==(const T &other) const { return ptr == other; } + + private: + T ptr; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + FakeRooted(const FakeRooted &) MOZ_DELETE; +}; + +/* Interface substitute for MutableHandle which is not required to point to rooted memory. */ +template +class FakeMutableHandle : public js::MutableHandleBase +{ + public: + MOZ_IMPLICIT FakeMutableHandle(T *t) { + ptr = t; + } + + MOZ_IMPLICIT FakeMutableHandle(FakeRooted *root) { + ptr = root->address(); + } + + void set(T v) { + MOZ_ASSERT(!js::GCMethods::poisoned(v)); + *ptr = v; + } + + T *address() const { return ptr; } + T get() const { return *ptr; } + + operator T() const { return get(); } + T operator->() const { return get(); } + + private: + FakeMutableHandle() {} + + T *ptr; + + template + void operator=(S v) MOZ_DELETE; + + void operator=(const FakeMutableHandle& other) MOZ_DELETE; +}; + +/* + * Types for a variable that either should or shouldn't be rooted, depending on + * the template parameter allowGC. Used for implementing functions that can + * operate on either rooted or unrooted data. + * + * The toHandle() and toMutableHandle() functions are for calling functions + * which require handle types and are only called in the CanGC case. These + * allow the calling code to type check. + */ +enum AllowGC { + NoGC = 0, + CanGC = 1 +}; +template +class MaybeRooted +{ +}; + +template class MaybeRooted +{ + public: + typedef JS::Handle HandleType; + typedef JS::Rooted RootType; + typedef JS::MutableHandle MutableHandleType; + + static inline JS::Handle toHandle(HandleType v) { + return v; + } + + static inline JS::MutableHandle toMutableHandle(MutableHandleType v) { + return v; + } +}; + +template class MaybeRooted +{ + public: + typedef T HandleType; + typedef FakeRooted RootType; + typedef FakeMutableHandle MutableHandleType; + + static JS::Handle toHandle(HandleType v) { + MOZ_CRASH("Bad conversion"); + } + + static JS::MutableHandle toMutableHandle(MutableHandleType v) { + MOZ_CRASH("Bad conversion"); + } +}; + +} /* namespace js */ + +namespace JS { + +template template +inline +Handle::Handle(const Rooted &root, + typename mozilla::EnableIf::value, int>::Type dummy) +{ + ptr = reinterpret_cast(root.address()); +} + +template template +inline +Handle::Handle(const PersistentRooted &root, + typename mozilla::EnableIf::value, int>::Type dummy) +{ + ptr = reinterpret_cast(root.address()); +} + +template template +inline +Handle::Handle(MutableHandle &root, + typename mozilla::EnableIf::value, int>::Type dummy) +{ + ptr = reinterpret_cast(root.address()); +} + +template +inline +MutableHandle::MutableHandle(Rooted *root) +{ + static_assert(sizeof(MutableHandle) == sizeof(T *), + "MutableHandle must be binary compatible with T*."); + ptr = root->address(); +} + +template +inline +MutableHandle::MutableHandle(PersistentRooted *root) +{ + static_assert(sizeof(MutableHandle) == sizeof(T *), + "MutableHandle must be binary compatible with T*."); + ptr = root->address(); +} + +/* + * A copyable, assignable global GC root type with arbitrary lifetime, an + * infallible constructor, and automatic unrooting on destruction. + * + * These roots can be used in heap-allocated data structures, so they are not + * associated with any particular JSContext or stack. They are registered with + * the JSRuntime itself, without locking, so they require a full JSContext to be + * constructed, not one of its more restricted superclasses. + * + * Note that you must not use an PersistentRooted in an object owned by a JS + * object: + * + * Whenever one object whose lifetime is decided by the GC refers to another + * such object, that edge must be traced only if the owning JS object is traced. + * This applies not only to JS objects (which obviously are managed by the GC) + * but also to C++ objects owned by JS objects. + * + * If you put a PersistentRooted in such a C++ object, that is almost certainly + * a leak. When a GC begins, the referent of the PersistentRooted is treated as + * live, unconditionally (because a PersistentRooted is a *root*), even if the + * JS object that owns it is unreachable. If there is any path from that + * referent back to the JS object, then the C++ object containing the + * PersistentRooted will not be destructed, and the whole blob of objects will + * not be freed, even if there are no references to them from the outside. + * + * In the context of Firefox, this is a severe restriction: almost everything in + * Firefox is owned by some JS object or another, so using PersistentRooted in + * such objects would introduce leaks. For these kinds of edges, Heap or + * TenuredHeap would be better types. It's up to the implementor of the type + * containing Heap or TenuredHeap members to make sure their referents get + * marked when the object itself is marked. + */ +template +class PersistentRooted : private mozilla::LinkedListElement > { + friend class mozilla::LinkedList; + friend class mozilla::LinkedListElement; + + friend struct js::gc::PersistentRootedMarker; + + void registerWithRuntime(JSRuntime *rt) { + JS::shadow::Runtime *srt = JS::shadow::Runtime::asShadowRuntime(rt); + srt->getPersistentRootedList().insertBack(this); + } + + public: + explicit PersistentRooted(JSContext *cx) : ptr(js::GCMethods::initial()) + { + registerWithRuntime(js::GetRuntime(cx)); + } + + PersistentRooted(JSContext *cx, T initial) : ptr(initial) + { + registerWithRuntime(js::GetRuntime(cx)); + } + + explicit PersistentRooted(JSRuntime *rt) : ptr(js::GCMethods::initial()) + { + registerWithRuntime(rt); + } + + PersistentRooted(JSRuntime *rt, T initial) : ptr(initial) + { + registerWithRuntime(rt); + } + + PersistentRooted(const PersistentRooted &rhs) + : mozilla::LinkedListElement >(), + ptr(rhs.ptr) + { + /* + * Copy construction takes advantage of the fact that the original + * is already inserted, and simply adds itself to whatever list the + * original was on - no JSRuntime pointer needed. + * + * This requires mutating rhs's links, but those should be 'mutable' + * anyway. C++ doesn't let us declare mutable base classes. + */ + const_cast(rhs).setNext(this); + } + + /* + * Important: Return a reference here so passing a Rooted to + * something that takes a |const T&| is not a GC hazard. + */ + operator const T&() const { return ptr; } + T operator->() const { return ptr; } + T *address() { return &ptr; } + const T *address() const { return &ptr; } + T &get() { return ptr; } + const T &get() const { return ptr; } + + T &operator=(T value) { + MOZ_ASSERT(!js::GCMethods::poisoned(value)); + ptr = value; + return ptr; + } + + T &operator=(const PersistentRooted &value) { + ptr = value; + return ptr; + } + + void set(T value) { + MOZ_ASSERT(!js::GCMethods::poisoned(value)); + ptr = value; + } + + bool operator!=(const T &other) const { return ptr != other; } + bool operator==(const T &other) const { return ptr == other; } + + private: + T ptr; +}; + +class JS_PUBLIC_API(ObjectPtr) +{ + Heap value; + + public: + ObjectPtr() : value(nullptr) {} + + explicit ObjectPtr(JSObject *obj) : value(obj) {} + + /* Always call finalize before the destructor. */ + ~ObjectPtr() { MOZ_ASSERT(!value); } + + void finalize(JSRuntime *rt) { + if (IsIncrementalBarrierNeeded(rt)) + IncrementalObjectBarrier(value); + value = nullptr; + } + + void init(JSObject *obj) { value = obj; } + + JSObject *get() const { return value; } + + void writeBarrierPre(JSRuntime *rt) { + IncrementalObjectBarrier(value); + } + + bool isAboutToBeFinalized(); + + ObjectPtr &operator=(JSObject *obj) { + IncrementalObjectBarrier(value); + value = obj; + return *this; + } + + void trace(JSTracer *trc, const char *name); + + JSObject &operator*() const { return *value; } + JSObject *operator->() const { return value; } + operator JSObject *() const { return value; } +}; + +} /* namespace JS */ + +namespace js { + +/* Base class for automatic read-only object rooting during compilation. */ +class CompilerRootNode +{ + protected: + explicit CompilerRootNode(js::gc::Cell *ptr) : next(nullptr), ptr_(ptr) {} + + public: + void **address() { return (void **)&ptr_; } + + public: + CompilerRootNode *next; + + protected: + js::gc::Cell *ptr_; +}; + +} /* namespace js */ + +#endif /* js_RootingAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/SliceBudget.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/SliceBudget.h new file mode 100644 index 0000000000..7c602c5572 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/SliceBudget.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_SliceBudget_h +#define js_SliceBudget_h + +#include + +namespace js { + +/* + * This class records how much work has been done in a given collection slice, so that + * we can return before pausing for too long. Some slices are allowed to run for + * unlimited time, and others are bounded. To reduce the number of gettimeofday + * calls, we only check the time every 1000 operations. + */ +struct JS_PUBLIC_API(SliceBudget) +{ + int64_t deadline; /* in microseconds */ + intptr_t counter; + + static const intptr_t CounterReset = 1000; + + static const int64_t Unlimited = 0; + static int64_t TimeBudget(int64_t millis); + static int64_t WorkBudget(int64_t work); + + /* Equivalent to SliceBudget(UnlimitedBudget). */ + SliceBudget(); + + /* Instantiate as SliceBudget(Time/WorkBudget(n)). */ + explicit SliceBudget(int64_t budget); + + void reset() { + deadline = unlimitedDeadline; + counter = unlimitedStartCounter; + } + + void step(intptr_t amt = 1) { + counter -= amt; + } + + bool checkOverBudget(); + + bool isOverBudget() { + if (counter >= 0) + return false; + return checkOverBudget(); + } + + bool isUnlimited() { + return deadline == unlimitedDeadline; + } + +private: + static const int64_t unlimitedDeadline = INT64_MAX; + static const intptr_t unlimitedStartCounter = INTPTR_MAX; + +}; + +} // namespace js + +#endif /* js_SliceBudget_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/StructuredClone.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/StructuredClone.h new file mode 100644 index 0000000000..fa48ce045a --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/StructuredClone.h @@ -0,0 +1,245 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_StructuredClone_h +#define js_StructuredClone_h + +#include "mozilla/NullPtr.h" + +#include + +#include "jstypes.h" + +#include "js/RootingAPI.h" +#include "js/TypeDecls.h" +#include "js/Value.h" + +struct JSRuntime; +struct JSStructuredCloneReader; +struct JSStructuredCloneWriter; + +// API for the HTML5 internal structured cloning algorithm. + +namespace JS { +enum TransferableOwnership { + // Transferable data has not been filled in yet + SCTAG_TMO_UNFILLED = 0, + + // Structured clone buffer does not yet own the data + SCTAG_TMO_UNOWNED = 1, + + // All values at least this large are owned by the clone buffer + SCTAG_TMO_FIRST_OWNED = 2, + + // Data is a pointer that can be freed + SCTAG_TMO_ALLOC_DATA = 2, + + // Data is a SharedArrayBufferObject's buffer + SCTAG_TMO_SHARED_BUFFER = 3, + + // Data is a memory mapped pointer + SCTAG_TMO_MAPPED_DATA = 4, + + // Data is embedding-specific. The engine can free it by calling the + // freeTransfer op. The embedding can also use SCTAG_TMO_USER_MIN and + // greater, up to 32 bits, to distinguish specific ownership variants. + SCTAG_TMO_CUSTOM = 5, + + SCTAG_TMO_USER_MIN +}; +} /* namespace JS */ + +// Read structured data from the reader r. This hook is used to read a value +// previously serialized by a call to the WriteStructuredCloneOp hook. +// +// tag and data are the pair of uint32_t values from the header. The callback +// may use the JS_Read* APIs to read any other relevant parts of the object +// from the reader r. closure is any value passed to the JS_ReadStructuredClone +// function. Return the new object on success, nullptr on error/exception. +typedef JSObject *(*ReadStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r, + uint32_t tag, uint32_t data, void *closure); + +// Structured data serialization hook. The engine can write primitive values, +// Objects, Arrays, Dates, RegExps, TypedArrays, and ArrayBuffers. Any other +// type of object requires application support. This callback must first use +// the JS_WriteUint32Pair API to write an object header, passing a value +// greater than JS_SCTAG_USER to the tag parameter. Then it can use the +// JS_Write* APIs to write any other relevant parts of the value v to the +// writer w. closure is any value passed to the JS_WriteStructuredCLone function. +// +// Return true on success, false on error/exception. +typedef bool (*WriteStructuredCloneOp)(JSContext *cx, JSStructuredCloneWriter *w, + JS::HandleObject obj, void *closure); + +// This is called when JS_WriteStructuredClone is given an invalid transferable. +// To follow HTML5, the application must throw a DATA_CLONE_ERR DOMException +// with error set to one of the JS_SCERR_* values. +typedef void (*StructuredCloneErrorOp)(JSContext *cx, uint32_t errorid); + +// This is called when JS_ReadStructuredClone receives a transferable object +// not known to the engine. If this hook does not exist or returns false, the +// JS engine calls the reportError op if set, otherwise it throws a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback and must return a non-null object in returnObject on success. +typedef bool (*ReadTransferStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r, + uint32_t tag, void *content, uint64_t extraData, + void *closure, + JS::MutableHandleObject returnObject); + +// Called when JS_WriteStructuredClone receives a transferable object not +// handled by the engine. If this hook does not exist or returns false, the JS +// engine will call the reportError hook or fall back to throwing a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback. +// +// tag: indicates what type of transferable this is. Must be greater than +// 0xFFFF0201 (value of the internal SCTAG_TRANSFER_MAP_PENDING_ENTRY) +// +// ownership: see TransferableOwnership, above. Used to communicate any needed +// ownership info to the FreeTransferStructuredCloneOp. +// +// content, extraData: what the ReadTransferStructuredCloneOp will receive +// +typedef bool (*TransferStructuredCloneOp)(JSContext *cx, + JS::Handle obj, + void *closure, + // Output: + uint32_t *tag, + JS::TransferableOwnership *ownership, + void **content, + uint64_t *extraData); + +// Called when JS_ClearStructuredClone has to free an unknown transferable +// object. Note that it should never trigger a garbage collection (and will +// assert in a debug build if it does.) +typedef void (*FreeTransferStructuredCloneOp)(uint32_t tag, JS::TransferableOwnership ownership, + void *content, uint64_t extraData, void *closure); + +// The maximum supported structured-clone serialization format version. Note +// that this does not need to be bumped for Transferable-only changes, since +// they are never saved to persistent storage. +#define JS_STRUCTURED_CLONE_VERSION 4 + +struct JSStructuredCloneCallbacks { + ReadStructuredCloneOp read; + WriteStructuredCloneOp write; + StructuredCloneErrorOp reportError; + ReadTransferStructuredCloneOp readTransfer; + TransferStructuredCloneOp writeTransfer; + FreeTransferStructuredCloneOp freeTransfer; +}; + +// Note: if the *data contains transferable objects, it can be read only once. +JS_PUBLIC_API(bool) +JS_ReadStructuredClone(JSContext *cx, uint64_t *data, size_t nbytes, uint32_t version, + JS::MutableHandleValue vp, + const JSStructuredCloneCallbacks *optionalCallbacks, void *closure); + +// Note: On success, the caller is responsible for calling +// JS_ClearStructuredClone(*datap, nbytes, optionalCallbacks, closure). +JS_PUBLIC_API(bool) +JS_WriteStructuredClone(JSContext *cx, JS::HandleValue v, uint64_t **datap, size_t *nbytesp, + const JSStructuredCloneCallbacks *optionalCallbacks, + void *closure, JS::HandleValue transferable); + +JS_PUBLIC_API(bool) +JS_ClearStructuredClone(uint64_t *data, size_t nbytes, + const JSStructuredCloneCallbacks *optionalCallbacks, + void *closure); + +JS_PUBLIC_API(bool) +JS_StructuredCloneHasTransferables(const uint64_t *data, size_t nbytes, bool *hasTransferable); + +JS_PUBLIC_API(bool) +JS_StructuredClone(JSContext *cx, JS::HandleValue v, JS::MutableHandleValue vp, + const JSStructuredCloneCallbacks *optionalCallbacks, void *closure); + +// RAII sugar for JS_WriteStructuredClone. +class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) { + uint64_t *data_; + size_t nbytes_; + uint32_t version_; + const JSStructuredCloneCallbacks *callbacks_; + void *closure_; + + public: + JSAutoStructuredCloneBuffer() + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(nullptr), closure_(nullptr) + {} + + JSAutoStructuredCloneBuffer(const JSStructuredCloneCallbacks *callbacks, void *closure) + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(callbacks), closure_(closure) + {} + + JSAutoStructuredCloneBuffer(JSAutoStructuredCloneBuffer &&other); + JSAutoStructuredCloneBuffer &operator=(JSAutoStructuredCloneBuffer &&other); + + ~JSAutoStructuredCloneBuffer() { clear(); } + + uint64_t *data() const { return data_; } + size_t nbytes() const { return nbytes_; } + + void clear(); + + // Copy some memory. It will be automatically freed by the destructor. + bool copy(const uint64_t *data, size_t nbytes, uint32_t version=JS_STRUCTURED_CLONE_VERSION); + + // Adopt some memory. It will be automatically freed by the destructor. + // data must have been allocated by the JS engine (e.g., extracted via + // JSAutoStructuredCloneBuffer::steal). + void adopt(uint64_t *data, size_t nbytes, uint32_t version=JS_STRUCTURED_CLONE_VERSION); + + // Remove the buffer so that it will not be automatically freed. + // After this, the caller is responsible for feeding the memory back to + // JSAutoStructuredCloneBuffer::adopt. + void steal(uint64_t **datap, size_t *nbytesp, uint32_t *versionp=nullptr); + + bool read(JSContext *cx, JS::MutableHandleValue vp, + const JSStructuredCloneCallbacks *optionalCallbacks=nullptr, void *closure=nullptr); + + bool write(JSContext *cx, JS::HandleValue v, + const JSStructuredCloneCallbacks *optionalCallbacks=nullptr, void *closure=nullptr); + + bool write(JSContext *cx, JS::HandleValue v, JS::HandleValue transferable, + const JSStructuredCloneCallbacks *optionalCallbacks=nullptr, void *closure=nullptr); + + private: + // Copy and assignment are not supported. + JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; + JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; +}; + +// The range of tag values the application may use for its own custom object types. +#define JS_SCTAG_USER_MIN ((uint32_t) 0xFFFF8000) +#define JS_SCTAG_USER_MAX ((uint32_t) 0xFFFFFFFF) + +#define JS_SCERR_RECURSION 0 +#define JS_SCERR_TRANSFERABLE 1 + +JS_PUBLIC_API(void) +JS_SetStructuredCloneCallbacks(JSRuntime *rt, const JSStructuredCloneCallbacks *callbacks); + +JS_PUBLIC_API(bool) +JS_ReadUint32Pair(JSStructuredCloneReader *r, uint32_t *p1, uint32_t *p2); + +JS_PUBLIC_API(bool) +JS_ReadBytes(JSStructuredCloneReader *r, void *p, size_t len); + +JS_PUBLIC_API(bool) +JS_ReadTypedArray(JSStructuredCloneReader *r, JS::MutableHandleValue vp); + +JS_PUBLIC_API(bool) +JS_WriteUint32Pair(JSStructuredCloneWriter *w, uint32_t tag, uint32_t data); + +JS_PUBLIC_API(bool) +JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len); + +JS_PUBLIC_API(bool) +JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::HandleValue v); + +#endif /* js_StructuredClone_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/TracingAPI.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/TracingAPI.h new file mode 100644 index 0000000000..3c7fdbe1b1 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/TracingAPI.h @@ -0,0 +1,216 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_TracingAPI_h +#define js_TracingAPI_h + +#include "mozilla/NullPtr.h" + +#include "jspubtd.h" + +class JS_PUBLIC_API(JSTracer); + +namespace JS { +template class Heap; +template class TenuredHeap; +} + +// Tracer callback, called for each traceable thing directly referenced by a +// particular object or runtime structure. It is the callback responsibility +// to ensure the traversal of the full object graph via calling eventually +// JS_TraceChildren on the passed thing. In this case the callback must be +// prepared to deal with cycles in the traversal graph. +// +// kind argument is one of JSTRACE_OBJECT, JSTRACE_STRING or a tag denoting +// internal implementation-specific traversal kind. In the latter case the only +// operations on thing that the callback can do is to call JS_TraceChildren or +// JS_GetTraceThingInfo. +// +// If eagerlyTraceWeakMaps is true, when we trace a WeakMap visit all +// of its mappings. This should be used in cases where the tracer +// wants to use the existing liveness of entries. +typedef void +(* JSTraceCallback)(JSTracer *trc, void **thingp, JSGCTraceKind kind); + +// Callback that JSTraceOp implementation can provide to return a string +// describing the reference traced with JS_CallTracer. +typedef void +(* JSTraceNamePrinter)(JSTracer *trc, char *buf, size_t bufsize); + +enum WeakMapTraceKind { + DoNotTraceWeakMaps = 0, + TraceWeakMapValues = 1, + TraceWeakMapKeysValues = 2 +}; + +class JS_PUBLIC_API(JSTracer) +{ + public: + JSTracer(JSRuntime *rt, JSTraceCallback traceCallback, + WeakMapTraceKind weakTraceKind = TraceWeakMapValues); + + // Set debugging information about a reference to a traceable thing to prepare + // for the following call to JS_CallTracer. + // + // When printer is null, arg must be const char * or char * C string naming + // the reference and index must be either (size_t)-1 indicating that the name + // alone describes the reference or it must be an index into some array vector + // that stores the reference. + // + // When printer callback is not null, the arg and index arguments are + // available to the callback as debugPrintArg_ and debugPrintIndex_ fields + // of JSTracer. + // + // The storage for name or callback's arguments needs to live only until + // the following call to JS_CallTracer returns. + void setTracingDetails(JSTraceNamePrinter printer, const void *arg, size_t index) { + debugPrinter_ = printer; + debugPrintArg_ = arg; + debugPrintIndex_ = index; + } + + void setTracingIndex(const char *name, size_t index) { + setTracingDetails(nullptr, (void *)name, index); + } + + void setTracingName(const char *name) { + setTracingDetails(nullptr, (void *)name, size_t(-1)); + } + + // Remove the currently set tracing details. + void clearTracingDetails() { + debugPrinter_ = nullptr; + debugPrintArg_ = nullptr; + } + + // Return true if tracing details are currently set. + bool hasTracingDetails() const; + + // Get the string set with the most recent call to setTracingName or return + // fallback if a name printer function has been installed. + const char *tracingName(const char *fallback) const; + + // Build a description of this edge in the heap graph. This call may invoke + // the debug printer, which may inspect arbitrary areas of the heap. + const char *getTracingEdgeName(char *buffer, size_t bufferSize); + + // Access the currently active tracing details. + JSTraceNamePrinter debugPrinter() const; + const void *debugPrintArg() const; + size_t debugPrintIndex() const; + + // Return the runtime set on the tracer. + JSRuntime *runtime() const { return runtime_; } + + // Return the weak map tracing behavior set on this tracer. + WeakMapTraceKind eagerlyTraceWeakMaps() const { return eagerlyTraceWeakMaps_; } + + // Update the trace callback. + void setTraceCallback(JSTraceCallback traceCallback); + +#ifdef JS_GC_ZEAL + // Sets the "real" location for a marked reference, when passing the address + // directly is not feasable. This address is used for matching against the + // store buffer when verifying the correctness of the entrees there. + // + // This is currently complicated by our need to nest calls for Values + // stored as keys in hash tables. + void setTracingLocation(void *location); + void unsetTracingLocation(); + void **tracingLocation(void **thingp); +#else + void setTracingLocation(void *location) {} + void unsetTracingLocation() {} + void **tracingLocation(void **thingp) { return nullptr; } +#endif + + // We expose |callback| directly so that IS_GC_MARKING_TRACER can compare + // it to GCMarker::GrayCallback. + JSTraceCallback callback; + + private: + JSRuntime *runtime_; + JSTraceNamePrinter debugPrinter_; + const void *debugPrintArg_; + size_t debugPrintIndex_; + WeakMapTraceKind eagerlyTraceWeakMaps_; +#ifdef JS_GC_ZEAL + void *realLocation_; +#endif +}; + +// The JS_Call*Tracer family of functions traces the given GC thing reference. +// This performs the tracing action configured on the given JSTracer: +// typically calling the JSTracer::callback or marking the thing as live. +// +// The argument to JS_Call*Tracer is an in-out param: when the function +// returns, the garbage collector might have moved the GC thing. In this case, +// the reference passed to JS_Call*Tracer will be updated to the object's new +// location. Callers of this method are responsible for updating any state +// that is dependent on the object's address. For example, if the object's +// address is used as a key in a hashtable, then the object must be removed +// and re-inserted with the correct hash. +// +extern JS_PUBLIC_API(void) +JS_CallValueTracer(JSTracer *trc, JS::Value *valuep, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallIdTracer(JSTracer *trc, jsid *idp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallObjectTracer(JSTracer *trc, JSObject **objp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallStringTracer(JSTracer *trc, JSString **strp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallScriptTracer(JSTracer *trc, JSScript **scriptp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapValueTracer(JSTracer *trc, JS::Heap *valuep, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapIdTracer(JSTracer *trc, JS::Heap *idp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapObjectTracer(JSTracer *trc, JS::Heap *objp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapStringTracer(JSTracer *trc, JS::Heap *strp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapScriptTracer(JSTracer *trc, JS::Heap *scriptp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapFunctionTracer(JSTracer *trc, JS::Heap *funp, const char *name); + +template +inline void +JS_CallHashSetObjectTracer(JSTracer *trc, HashSetEnum &e, JSObject *const &key, const char *name) +{ + JSObject *updated = key; + trc->setTracingLocation(reinterpret_cast(&const_cast(key))); + JS_CallObjectTracer(trc, &updated, name); + if (updated != key) + e.rekeyFront(key, updated); +} + +// Trace an object that is known to always be tenured. No post barriers are +// required in this case. +extern JS_PUBLIC_API(void) +JS_CallTenuredObjectTracer(JSTracer *trc, JS::TenuredHeap *objp, const char *name); + +extern JS_PUBLIC_API(void) +JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind); + +extern JS_PUBLIC_API(void) +JS_TraceRuntime(JSTracer *trc); + +extern JS_PUBLIC_API(void) +JS_GetTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc, + void *thing, JSGCTraceKind kind, bool includeDetails); + +#endif /* js_TracingAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/TypeDecls.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/TypeDecls.h new file mode 100644 index 0000000000..2a8234218c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/TypeDecls.h @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This file contains public type declarations that are used *frequently*. If +// it doesn't occur at least 10 times in Gecko, it probably shouldn't be in +// here. +// +// It includes only: +// - forward declarations of structs and classes; +// - typedefs; +// - enums (maybe). +// It does *not* contain any struct or class definitions. + +#ifndef js_TypeDecls_h +#define js_TypeDecls_h + +#include +#include + +#include "js-config.h" +#include "mozilla/Char16.h" + +struct JSContext; +class JSFunction; +class JSObject; +class JSScript; +class JSString; +class JSAddonId; + +struct jsid; + +typedef char16_t jschar; + +namespace JS { + +typedef unsigned char Latin1Char; + +class Symbol; +class Value; +template class Handle; +template class MutableHandle; +template class Rooted; +template class PersistentRooted; + +typedef Handle HandleFunction; +typedef Handle HandleId; +typedef Handle HandleObject; +typedef Handle HandleScript; +typedef Handle HandleString; +typedef Handle HandleSymbol; +typedef Handle HandleValue; + +typedef MutableHandle MutableHandleFunction; +typedef MutableHandle MutableHandleId; +typedef MutableHandle MutableHandleObject; +typedef MutableHandle MutableHandleScript; +typedef MutableHandle MutableHandleString; +typedef MutableHandle MutableHandleSymbol; +typedef MutableHandle MutableHandleValue; + +typedef Rooted RootedObject; +typedef Rooted RootedFunction; +typedef Rooted RootedScript; +typedef Rooted RootedString; +typedef Rooted RootedSymbol; +typedef Rooted RootedId; +typedef Rooted RootedValue; + +typedef PersistentRooted PersistentRootedFunction; +typedef PersistentRooted PersistentRootedId; +typedef PersistentRooted PersistentRootedObject; +typedef PersistentRooted PersistentRootedScript; +typedef PersistentRooted PersistentRootedString; +typedef PersistentRooted PersistentRootedSymbol; +typedef PersistentRooted PersistentRootedValue; + +} // namespace JS + +#endif /* js_TypeDecls_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Utility.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Utility.h new file mode 100644 index 0000000000..89c495e411 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Utility.h @@ -0,0 +1,736 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_Utility_h +#define js_Utility_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/Scoped.h" +#include "mozilla/TemplateLib.h" + +#include +#include + +#ifdef JS_OOM_DO_BACKTRACES +#include +#include +#endif + +#include "jstypes.h" + +/* The public JS engine namespace. */ +namespace JS {} + +/* The mozilla-shared reusable template/utility namespace. */ +namespace mozilla {} + +/* The private JS engine namespace. */ +namespace js {} + +/* + * Patterns used by SpiderMonkey to overwrite unused memory. If you are + * accessing an object with one of these pattern, you probably have a dangling + * pointer. + */ +#define JS_FRESH_NURSERY_PATTERN 0x2F +#define JS_SWEPT_NURSERY_PATTERN 0x2B +#define JS_ALLOCATED_NURSERY_PATTERN 0x2D +#define JS_FRESH_TENURED_PATTERN 0x4F +#define JS_SWEPT_TENURED_PATTERN 0x4B +#define JS_ALLOCATED_TENURED_PATTERN 0x4D +#define JS_SWEPT_CODE_PATTERN 0x3b +#define JS_SWEPT_FRAME_PATTERN 0x5b +#define JS_POISONED_FORKJOIN_CHUNK 0xBD + +#define JS_ASSERT(expr) MOZ_ASSERT(expr) +#define JS_ASSERT_IF(cond, expr) MOZ_ASSERT_IF(cond, expr) + +#define JS_STATIC_ASSERT(cond) static_assert(cond, "JS_STATIC_ASSERT") +#define JS_STATIC_ASSERT_IF(cond, expr) MOZ_STATIC_ASSERT_IF(cond, expr, "JS_STATIC_ASSERT_IF") + +extern MOZ_NORETURN JS_PUBLIC_API(void) +JS_Assert(const char *s, const char *file, int ln); + +/* + * Custom allocator support for SpiderMonkey + */ +#if defined JS_USE_CUSTOM_ALLOCATOR +# include "jscustomallocator.h" +#else +# if defined(DEBUG) || defined(JS_OOM_BREAKPOINT) +/* + * In order to test OOM conditions, when the testing function + * oomAfterAllocations COUNT is passed, we fail continuously after the NUM'th + * allocation from now. + */ +extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtin/TestingFunctions.cpp */ +extern JS_PUBLIC_DATA(uint32_t) OOM_counter; /* data race, who cares. */ + +#ifdef JS_OOM_BREAKPOINT +static MOZ_NEVER_INLINE void js_failedAllocBreakpoint() { asm(""); } +#define JS_OOM_CALL_BP_FUNC() js_failedAllocBreakpoint() +#else +#define JS_OOM_CALL_BP_FUNC() do {} while(0) +#endif + +# define JS_OOM_POSSIBLY_FAIL() \ + do \ + { \ + if (++OOM_counter > OOM_maxAllocations) { \ + JS_OOM_CALL_BP_FUNC();\ + return nullptr; \ + } \ + } while (0) + +# else +# define JS_OOM_POSSIBLY_FAIL() do {} while(0) +# endif /* DEBUG || JS_OOM_BREAKPOINT */ + +static inline void* js_malloc(size_t bytes) +{ + JS_OOM_POSSIBLY_FAIL(); + return malloc(bytes); +} + +static inline void* js_calloc(size_t bytes) +{ + JS_OOM_POSSIBLY_FAIL(); + return calloc(bytes, 1); +} + +static inline void* js_calloc(size_t nmemb, size_t size) +{ + JS_OOM_POSSIBLY_FAIL(); + return calloc(nmemb, size); +} + +static inline void* js_realloc(void* p, size_t bytes) +{ + JS_OOM_POSSIBLY_FAIL(); + return realloc(p, bytes); +} + +static inline void js_free(void* p) +{ + free(p); +} +#endif/* JS_USE_CUSTOM_ALLOCATOR */ + +#include + +/* + * Low-level memory management in SpiderMonkey: + * + * ** Do not use the standard malloc/free/realloc: SpiderMonkey allows these + * to be redefined (via JS_USE_CUSTOM_ALLOCATOR) and Gecko even #define's + * these symbols. + * + * ** Do not use the builtin C++ operator new and delete: these throw on + * error and we cannot override them not to. + * + * Allocation: + * + * - If the lifetime of the allocation is tied to the lifetime of a GC-thing + * (that is, finalizing the GC-thing will free the allocation), call one of + * the following functions: + * + * JSContext::{malloc_,realloc_,calloc_,new_} + * JSRuntime::{malloc_,realloc_,calloc_,new_} + * + * These functions accumulate the number of bytes allocated which is used as + * part of the GC-triggering heuristic. + * + * The difference between the JSContext and JSRuntime versions is that the + * cx version reports an out-of-memory error on OOM. (This follows from the + * general SpiderMonkey idiom that a JSContext-taking function reports its + * own errors.) + * + * - Otherwise, use js_malloc/js_realloc/js_calloc/js_free/js_new + * + * Deallocation: + * + * - Ordinarily, use js_free/js_delete. + * + * - For deallocations during GC finalization, use one of the following + * operations on the FreeOp provided to the finalizer: + * + * FreeOp::{free_,delete_} + * + * The advantage of these operations is that the memory is batched and freed + * on another thread. + */ + +#define JS_NEW_BODY(allocator, t, parms) \ + void *memory = allocator(sizeof(t)); \ + return memory ? new(memory) t parms : nullptr; +#define JS_MAKE_BODY(newname, T, parms) \ + T *ptr = newname parms; \ + return mozilla::UniquePtr>(ptr); + +/* + * Given a class which should provide 'new' methods, add + * JS_DECLARE_NEW_METHODS (see JSContext for a usage example). This + * adds news with up to 12 parameters. Add more versions of new below if + * you need more than 12 parameters. + * + * Note: Do not add a ; at the end of a use of JS_DECLARE_NEW_METHODS, + * or the build will break. + */ +#define JS_DECLARE_NEW_METHODS(NEWNAME, ALLOCATOR, QUALIFIERS)\ + template \ + QUALIFIERS T *NEWNAME() MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T, ())\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11, P12 &&p12) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11),\ + mozilla::Forward(p12)))\ + }\ + +/* + * Given a class which should provide 'make' methods, add + * JS_DECLARE_MAKE_METHODS (see JSContext for a usage example). This method + * is functionally the same as JS_DECLARE_NEW_METHODS: it just declares methods + * that return mozilla::UniquePtr instances that will singly-manage ownership + * of the created object. This adds makes with up to 12 parameters. Add more + * versions below if you need more than 12 parameters. + * + * Note: Do not add a ; at the end of a use of JS_DECLARE_MAKE_METHODS, + * or the build will break. + */ +#define JS_DECLARE_MAKE_METHODS(MAKENAME, NEWNAME, QUALIFIERS)\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME() MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T, ())\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1)))\ + }\ +\ + template \ + QUALIFIERS \ +mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11, P12 &&p12) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11),\ + mozilla::Forward(p12)))\ + }\ + +JS_DECLARE_NEW_METHODS(js_new, js_malloc, static MOZ_ALWAYS_INLINE) + +template +static MOZ_ALWAYS_INLINE void +js_delete(T *p) +{ + if (p) { + p->~T(); + js_free(p); + } +} + +template +static MOZ_ALWAYS_INLINE void +js_delete_poison(T *p) +{ + if (p) { + p->~T(); + memset(p, 0x3B, sizeof(T)); + js_free(p); + } +} + +template +static MOZ_ALWAYS_INLINE T * +js_pod_malloc() +{ + return (T *)js_malloc(sizeof(T)); +} + +template +static MOZ_ALWAYS_INLINE T * +js_pod_calloc() +{ + return (T *)js_calloc(sizeof(T)); +} + +template +static MOZ_ALWAYS_INLINE T * +js_pod_malloc(size_t numElems) +{ + if (numElems & mozilla::tl::MulOverflowMask::value) + return nullptr; + return (T *)js_malloc(numElems * sizeof(T)); +} + +template +static MOZ_ALWAYS_INLINE T * +js_pod_calloc(size_t numElems) +{ + if (numElems & mozilla::tl::MulOverflowMask::value) + return nullptr; + return (T *)js_calloc(numElems * sizeof(T)); +} + +namespace js { + +template +struct ScopedFreePtrTraits +{ + typedef T* type; + static T* empty() { return nullptr; } + static void release(T* ptr) { js_free(ptr); } +}; +SCOPED_TEMPLATE(ScopedJSFreePtr, ScopedFreePtrTraits) + +template +struct ScopedDeletePtrTraits : public ScopedFreePtrTraits +{ + static void release(T *ptr) { js_delete(ptr); } +}; +SCOPED_TEMPLATE(ScopedJSDeletePtr, ScopedDeletePtrTraits) + +template +struct ScopedReleasePtrTraits : public ScopedFreePtrTraits +{ + static void release(T *ptr) { if (ptr) ptr->release(); } +}; +SCOPED_TEMPLATE(ScopedReleasePtr, ScopedReleasePtrTraits) + +} /* namespace js */ + +namespace JS { + +template +struct DeletePolicy +{ + void operator()(T* ptr) { + js_delete(ptr); + } +}; + +struct FreePolicy +{ + void operator()(void* ptr) { + js_free(ptr); + } +}; + +} // namespace JS + +namespace js { + +/* Integral types for all hash functions. */ +typedef uint32_t HashNumber; +const unsigned HashNumberSizeBits = 32; + +namespace detail { + +/* + * Given a raw hash code, h, return a number that can be used to select a hash + * bucket. + * + * This function aims to produce as uniform an output distribution as possible, + * especially in the most significant (leftmost) bits, even though the input + * distribution may be highly nonrandom, given the constraints that this must + * be deterministic and quick to compute. + * + * Since the leftmost bits of the result are best, the hash bucket index is + * computed by doing ScrambleHashCode(h) / (2^32/N) or the equivalent + * right-shift, not ScrambleHashCode(h) % N or the equivalent bit-mask. + * + * FIXME: OrderedHashTable uses a bit-mask; see bug 775896. + */ +inline HashNumber +ScrambleHashCode(HashNumber h) +{ + /* + * Simply returning h would not cause any hash tables to produce wrong + * answers. But it can produce pathologically bad performance: The caller + * right-shifts the result, keeping only the highest bits. The high bits of + * hash codes are very often completely entropy-free. (So are the lowest + * bits.) + * + * So we use Fibonacci hashing, as described in Knuth, The Art of Computer + * Programming, 6.4. This mixes all the bits of the input hash code h. + * + * The value of goldenRatio is taken from the hex + * expansion of the golden ratio, which starts 1.9E3779B9.... + * This value is especially good if values with consecutive hash codes + * are stored in a hash table; see Knuth for details. + */ + static const HashNumber goldenRatio = 0x9E3779B9U; + return h * goldenRatio; +} + +} /* namespace detail */ + +} /* namespace js */ + +namespace JS { + +/* + * Methods for poisoning GC heap pointer words and checking for poisoned words. + * These are in this file for use in Value methods and so forth. + * + * If the moving GC hazard analysis is in use and detects a non-rooted stack + * pointer to a GC thing, one byte of that pointer is poisoned to refer to an + * invalid location. For both 32 bit and 64 bit systems, the fourth byte of the + * pointer is overwritten, to reduce the likelihood of accidentally changing + * a live integer value. + */ + +inline void PoisonPtr(void *v) +{ +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) + uint8_t *ptr = (uint8_t *) v + 3; + *ptr = JS_FREE_PATTERN; +#endif +} + +template +inline bool IsPoisonedPtr(T *v) +{ +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) + uint32_t mask = uintptr_t(v) & 0xff000000; + return mask == uint32_t(JS_FREE_PATTERN << 24); +#else + return false; +#endif +} + +} + +/* sixgill annotation defines */ +#ifndef HAVE_STATIC_ANNOTATIONS +# define HAVE_STATIC_ANNOTATIONS +# ifdef XGILL_PLUGIN +# define STATIC_PRECONDITION(COND) __attribute__((precondition(#COND))) +# define STATIC_PRECONDITION_ASSUME(COND) __attribute__((precondition_assume(#COND))) +# define STATIC_POSTCONDITION(COND) __attribute__((postcondition(#COND))) +# define STATIC_POSTCONDITION_ASSUME(COND) __attribute__((postcondition_assume(#COND))) +# define STATIC_INVARIANT(COND) __attribute__((invariant(#COND))) +# define STATIC_INVARIANT_ASSUME(COND) __attribute__((invariant_assume(#COND))) +# define STATIC_PASTE2(X,Y) X ## Y +# define STATIC_PASTE1(X,Y) STATIC_PASTE2(X,Y) +# define STATIC_ASSERT(COND) \ + JS_BEGIN_MACRO \ + __attribute__((assert_static(#COND), unused)) \ + int STATIC_PASTE1(assert_static_, __COUNTER__); \ + JS_END_MACRO +# define STATIC_ASSUME(COND) \ + JS_BEGIN_MACRO \ + __attribute__((assume_static(#COND), unused)) \ + int STATIC_PASTE1(assume_static_, __COUNTER__); \ + JS_END_MACRO +# define STATIC_ASSERT_RUNTIME(COND) \ + JS_BEGIN_MACRO \ + __attribute__((assert_static_runtime(#COND), unused)) \ + int STATIC_PASTE1(assert_static_runtime_, __COUNTER__); \ + JS_END_MACRO +# else /* XGILL_PLUGIN */ +# define STATIC_PRECONDITION(COND) /* nothing */ +# define STATIC_PRECONDITION_ASSUME(COND) /* nothing */ +# define STATIC_POSTCONDITION(COND) /* nothing */ +# define STATIC_POSTCONDITION_ASSUME(COND) /* nothing */ +# define STATIC_INVARIANT(COND) /* nothing */ +# define STATIC_INVARIANT_ASSUME(COND) /* nothing */ +# define STATIC_ASSERT(COND) JS_BEGIN_MACRO /* nothing */ JS_END_MACRO +# define STATIC_ASSUME(COND) JS_BEGIN_MACRO /* nothing */ JS_END_MACRO +# define STATIC_ASSERT_RUNTIME(COND) JS_BEGIN_MACRO /* nothing */ JS_END_MACRO +# endif /* XGILL_PLUGIN */ +# define STATIC_SKIP_INFERENCE STATIC_INVARIANT(skip_inference()) +#endif /* HAVE_STATIC_ANNOTATIONS */ + +#endif /* js_Utility_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Value.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Value.h new file mode 100644 index 0000000000..e7b89e684d --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Value.h @@ -0,0 +1,2003 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JS::Value implementation. */ + +#ifndef js_Value_h +#define js_Value_h + +#include "mozilla/Attributes.h" +#include "mozilla/FloatingPoint.h" +#include "mozilla/Likely.h" + +#include /* for std::numeric_limits */ + +#include "js-config.h" +#include "jstypes.h" + +#include "js/Anchor.h" +#include "js/GCAPI.h" +#include "js/RootingAPI.h" +#include "js/Utility.h" + +namespace JS { class Value; } + +/* JS::Value can store a full int32_t. */ +#define JSVAL_INT_BITS 32 +#define JSVAL_INT_MIN ((int32_t)0x80000000) +#define JSVAL_INT_MAX ((int32_t)0x7fffffff) + +/* + * Try to get jsvals 64-bit aligned. We could almost assert that all values are + * aligned, but MSVC and GCC occasionally break alignment. + */ +#if defined(__GNUC__) || defined(__xlc__) || defined(__xlC__) +# define JSVAL_ALIGNMENT __attribute__((aligned (8))) +#elif defined(_MSC_VER) + /* + * Structs can be aligned with MSVC, but not if they are used as parameters, + * so we just don't try to align. + */ +# define JSVAL_ALIGNMENT +#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) +# define JSVAL_ALIGNMENT +#elif defined(__HP_cc) || defined(__HP_aCC) +# define JSVAL_ALIGNMENT +#endif + +#if defined(JS_PUNBOX64) +# define JSVAL_TAG_SHIFT 47 +#endif + +/* + * We try to use enums so that printing a jsval_layout in the debugger shows + * nice symbolic type tags, however we can only do this when we can force the + * underlying type of the enum to be the desired size. + */ +#if !defined(__SUNPRO_CC) && !defined(__xlC__) + +#if defined(_MSC_VER) +# define JS_ENUM_HEADER(id, type) enum id : type +# define JS_ENUM_FOOTER(id) +#else +# define JS_ENUM_HEADER(id, type) enum id +# define JS_ENUM_FOOTER(id) __attribute__((packed)) +#endif + +/* Remember to propagate changes to the C defines below. */ +JS_ENUM_HEADER(JSValueType, uint8_t) +{ + JSVAL_TYPE_DOUBLE = 0x00, + JSVAL_TYPE_INT32 = 0x01, + JSVAL_TYPE_UNDEFINED = 0x02, + JSVAL_TYPE_BOOLEAN = 0x03, + JSVAL_TYPE_MAGIC = 0x04, + JSVAL_TYPE_STRING = 0x05, + JSVAL_TYPE_SYMBOL = 0x06, + JSVAL_TYPE_NULL = 0x07, + JSVAL_TYPE_OBJECT = 0x08, + + /* These never appear in a jsval; they are only provided as an out-of-band value. */ + JSVAL_TYPE_UNKNOWN = 0x20, + JSVAL_TYPE_MISSING = 0x21 +} JS_ENUM_FOOTER(JSValueType); + +JS_STATIC_ASSERT(sizeof(JSValueType) == 1); + +#if defined(JS_NUNBOX32) + +/* Remember to propagate changes to the C defines below. */ +JS_ENUM_HEADER(JSValueTag, uint32_t) +{ + JSVAL_TAG_CLEAR = 0xFFFFFF80, + JSVAL_TAG_INT32 = JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32, + JSVAL_TAG_UNDEFINED = JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED, + JSVAL_TAG_STRING = JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL, + JSVAL_TAG_BOOLEAN = JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN, + JSVAL_TAG_MAGIC = JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC, + JSVAL_TAG_NULL = JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL, + JSVAL_TAG_OBJECT = JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT +} JS_ENUM_FOOTER(JSValueTag); + +JS_STATIC_ASSERT(sizeof(JSValueTag) == 4); + +#elif defined(JS_PUNBOX64) + +/* Remember to propagate changes to the C defines below. */ +JS_ENUM_HEADER(JSValueTag, uint32_t) +{ + JSVAL_TAG_MAX_DOUBLE = 0x1FFF0, + JSVAL_TAG_INT32 = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32, + JSVAL_TAG_UNDEFINED = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED, + JSVAL_TAG_STRING = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL, + JSVAL_TAG_BOOLEAN = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN, + JSVAL_TAG_MAGIC = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC, + JSVAL_TAG_NULL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL, + JSVAL_TAG_OBJECT = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_OBJECT +} JS_ENUM_FOOTER(JSValueTag); + +JS_STATIC_ASSERT(sizeof(JSValueTag) == sizeof(uint32_t)); + +JS_ENUM_HEADER(JSValueShiftedTag, uint64_t) +{ + JSVAL_SHIFTED_TAG_MAX_DOUBLE = ((((uint64_t)JSVAL_TAG_MAX_DOUBLE) << JSVAL_TAG_SHIFT) | 0xFFFFFFFF), + JSVAL_SHIFTED_TAG_INT32 = (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_UNDEFINED = (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_STRING = (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_SYMBOL = (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_BOOLEAN = (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_MAGIC = (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_NULL = (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_OBJECT = (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT) +} JS_ENUM_FOOTER(JSValueShiftedTag); + +JS_STATIC_ASSERT(sizeof(JSValueShiftedTag) == sizeof(uint64_t)); + +#endif + +#else /* !defined(__SUNPRO_CC) && !defined(__xlC__) */ + +typedef uint8_t JSValueType; +#define JSVAL_TYPE_DOUBLE ((uint8_t)0x00) +#define JSVAL_TYPE_INT32 ((uint8_t)0x01) +#define JSVAL_TYPE_UNDEFINED ((uint8_t)0x02) +#define JSVAL_TYPE_BOOLEAN ((uint8_t)0x03) +#define JSVAL_TYPE_MAGIC ((uint8_t)0x04) +#define JSVAL_TYPE_STRING ((uint8_t)0x05) +#define JSVAL_TYPE_SYMBOL ((uint8_t)0x06) +#define JSVAL_TYPE_NULL ((uint8_t)0x07) +#define JSVAL_TYPE_OBJECT ((uint8_t)0x08) +#define JSVAL_TYPE_UNKNOWN ((uint8_t)0x20) + +#if defined(JS_NUNBOX32) + +typedef uint32_t JSValueTag; +#define JSVAL_TAG_CLEAR ((uint32_t)(0xFFFFFF80)) +#define JSVAL_TAG_INT32 ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32)) +#define JSVAL_TAG_UNDEFINED ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED)) +#define JSVAL_TAG_STRING ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING)) +#define JSVAL_TAG_SYMBOL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL)) +#define JSVAL_TAG_BOOLEAN ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN)) +#define JSVAL_TAG_MAGIC ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC)) +#define JSVAL_TAG_NULL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL)) +#define JSVAL_TAG_OBJECT ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT)) + +#elif defined(JS_PUNBOX64) + +typedef uint32_t JSValueTag; +#define JSVAL_TAG_MAX_DOUBLE ((uint32_t)(0x1FFF0)) +#define JSVAL_TAG_INT32 (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32) +#define JSVAL_TAG_UNDEFINED (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED) +#define JSVAL_TAG_STRING (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING) +#define JSVAL_TAG_SYMBOL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL) +#define JSVAL_TAG_BOOLEAN (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN) +#define JSVAL_TAG_MAGIC (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC) +#define JSVAL_TAG_NULL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL) +#define JSVAL_TAG_OBJECT (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_OBJECT) + +typedef uint64_t JSValueShiftedTag; +#define JSVAL_SHIFTED_TAG_MAX_DOUBLE ((((uint64_t)JSVAL_TAG_MAX_DOUBLE) << JSVAL_TAG_SHIFT) | 0xFFFFFFFF) +#define JSVAL_SHIFTED_TAG_INT32 (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_UNDEFINED (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_STRING (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_SYMBOL (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_BOOLEAN (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_MAGIC (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_NULL (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_OBJECT (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT) + +#endif /* JS_PUNBOX64 */ +#endif /* !defined(__SUNPRO_CC) && !defined(__xlC__) */ + +#if defined(JS_NUNBOX32) + +#define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_CLEAR | (type))) + +#define JSVAL_LOWER_INCL_TAG_OF_OBJ_OR_NULL_SET JSVAL_TAG_NULL +#define JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET JSVAL_TAG_OBJECT +#define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32 +#define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING + +#elif defined(JS_PUNBOX64) + +#define JSVAL_PAYLOAD_MASK 0x00007FFFFFFFFFFFLL +#define JSVAL_TAG_MASK 0xFFFF800000000000LL +#define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_MAX_DOUBLE | (type))) +#define JSVAL_TYPE_TO_SHIFTED_TAG(type) (((uint64_t)JSVAL_TYPE_TO_TAG(type)) << JSVAL_TAG_SHIFT) + +#define JSVAL_LOWER_INCL_TAG_OF_OBJ_OR_NULL_SET JSVAL_TAG_NULL +#define JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET JSVAL_TAG_OBJECT +#define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32 +#define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING + +#define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_OBJ_OR_NULL_SET JSVAL_SHIFTED_TAG_NULL +#define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_PRIMITIVE_SET JSVAL_SHIFTED_TAG_OBJECT +#define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET JSVAL_SHIFTED_TAG_UNDEFINED +#define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET JSVAL_SHIFTED_TAG_STRING + +#endif /* JS_PUNBOX64 */ + +typedef enum JSWhyMagic +{ + JS_ELEMENTS_HOLE, /* a hole in a native object's elements */ + JS_NATIVE_ENUMERATE, /* indicates that a custom enumerate hook forwarded + * to JS_EnumerateState, which really means the object can be + * enumerated like a native object. */ + JS_NO_ITER_VALUE, /* there is not a pending iterator value */ + JS_GENERATOR_CLOSING, /* exception value thrown when closing a generator */ + JS_NO_CONSTANT, /* compiler sentinel value */ + JS_THIS_POISON, /* used in debug builds to catch tracing errors */ + JS_ARG_POISON, /* used in debug builds to catch tracing errors */ + JS_SERIALIZE_NO_NODE, /* an empty subnode in the AST serializer */ + JS_LAZY_ARGUMENTS, /* lazy arguments value on the stack */ + JS_OPTIMIZED_ARGUMENTS, /* optimized-away 'arguments' value */ + JS_IS_CONSTRUCTING, /* magic value passed to natives to indicate construction */ + JS_OVERWRITTEN_CALLEE, /* arguments.callee has been overwritten */ + JS_BLOCK_NEEDS_CLONE, /* value of static block object slot */ + JS_HASH_KEY_EMPTY, /* see class js::HashableValue */ + JS_ION_ERROR, /* error while running Ion code */ + JS_ION_BAILOUT, /* missing recover instruction result */ + JS_OPTIMIZED_OUT, /* optimized out slot */ + JS_GENERIC_MAGIC /* for local use */ +} JSWhyMagic; + +#if defined(IS_LITTLE_ENDIAN) +# if defined(JS_NUNBOX32) +typedef union jsval_layout +{ + uint64_t asBits; + struct { + union { + int32_t i32; + uint32_t u32; + uint32_t boo; // Don't use |bool| -- it must be four bytes. + JSString *str; + JS::Symbol *sym; + JSObject *obj; + js::gc::Cell *cell; + void *ptr; + JSWhyMagic why; + size_t word; + uintptr_t uintptr; + } payload; + JSValueTag tag; + } s; + double asDouble; + void *asPtr; +} JSVAL_ALIGNMENT jsval_layout; +# elif defined(JS_PUNBOX64) +typedef union jsval_layout +{ + uint64_t asBits; +#if !defined(_WIN64) + /* MSVC does not pack these correctly :-( */ + struct { + uint64_t payload47 : 47; + JSValueTag tag : 17; + } debugView; +#endif + struct { + union { + int32_t i32; + uint32_t u32; + JSWhyMagic why; + } payload; + } s; + double asDouble; + void *asPtr; + size_t asWord; + uintptr_t asUIntPtr; +} JSVAL_ALIGNMENT jsval_layout; +# endif /* JS_PUNBOX64 */ +#else /* defined(IS_LITTLE_ENDIAN) */ +# if defined(JS_NUNBOX32) +typedef union jsval_layout +{ + uint64_t asBits; + struct { + JSValueTag tag; + union { + int32_t i32; + uint32_t u32; + uint32_t boo; // Don't use |bool| -- it must be four bytes. + JSString *str; + JS::Symbol *sym; + JSObject *obj; + js::gc::Cell *cell; + void *ptr; + JSWhyMagic why; + size_t word; + uintptr_t uintptr; + } payload; + } s; + double asDouble; + void *asPtr; +} JSVAL_ALIGNMENT jsval_layout; +# elif defined(JS_PUNBOX64) +typedef union jsval_layout +{ + uint64_t asBits; + struct { + JSValueTag tag : 17; + uint64_t payload47 : 47; + } debugView; + struct { + uint32_t padding; + union { + int32_t i32; + uint32_t u32; + JSWhyMagic why; + } payload; + } s; + double asDouble; + void *asPtr; + size_t asWord; + uintptr_t asUIntPtr; +} JSVAL_ALIGNMENT jsval_layout; +# endif /* JS_PUNBOX64 */ +#endif /* defined(IS_LITTLE_ENDIAN) */ + +JS_STATIC_ASSERT(sizeof(jsval_layout) == 8); + +/* + * For codesize purposes on some platforms, it's important that the + * compiler know that JS::Values constructed from constant values can be + * folded to constant bit patterns at compile time, rather than + * constructed at runtime. Doing this requires a fair amount of C++11 + * features, which are not supported on all of our compilers. Set up + * some defines and helper macros in an attempt to confine the ugliness + * here, rather than scattering it all about the file. The important + * features are: + * + * - constexpr; + * - defaulted functions; + * - C99-style designated initializers. + */ +#if defined(__clang__) +# if __has_feature(cxx_constexpr) && __has_feature(cxx_defaulted_functions) +# define JS_VALUE_IS_CONSTEXPR +# endif +#elif defined(__GNUC__) +/* + * We need 4.5 for defaulted functions, 4.6 for constexpr, 4.7 because 4.6 + * doesn't understand |(X) { .field = ... }| syntax, and 4.7.3 because + * versions prior to that have bugs in the C++ front-end that cause crashes. + */ +# if MOZ_GCC_VERSION_AT_LEAST(4, 7, 3) +# define JS_VALUE_IS_CONSTEXPR +# endif +#endif + +#if defined(JS_VALUE_IS_CONSTEXPR) +# define JS_RETURN_LAYOUT_FROM_BITS(BITS) \ + return (jsval_layout) { .asBits = (BITS) } +# define JS_VALUE_CONSTEXPR MOZ_CONSTEXPR +# define JS_VALUE_CONSTEXPR_VAR MOZ_CONSTEXPR_VAR +#else +# define JS_RETURN_LAYOUT_FROM_BITS(BITS) \ + jsval_layout l; \ + l.asBits = (BITS); \ + return l; +# define JS_VALUE_CONSTEXPR +# define JS_VALUE_CONSTEXPR_VAR const +#endif + +#if defined(JS_NUNBOX32) + +/* + * N.B. GCC, in some but not all cases, chooses to emit signed comparison of + * JSValueTag even though its underlying type has been forced to be uint32_t. + * Thus, all comparisons should explicitly cast operands to uint32_t. + */ + +static inline JS_VALUE_CONSTEXPR jsval_layout +BUILD_JSVAL(JSValueTag tag, uint32_t payload) +{ + JS_RETURN_LAYOUT_FROM_BITS((((uint64_t)(uint32_t)tag) << 32) | payload); +} + +static inline bool +JSVAL_IS_DOUBLE_IMPL(jsval_layout l) +{ + return (uint32_t)l.s.tag <= (uint32_t)JSVAL_TAG_CLEAR; +} + +static inline jsval_layout +DOUBLE_TO_JSVAL_IMPL(double d) +{ + jsval_layout l; + l.asDouble = d; + MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(l)); + return l; +} + +static inline bool +JSVAL_IS_INT32_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_INT32; +} + +static inline int32_t +JSVAL_TO_INT32_IMPL(jsval_layout l) +{ + return l.s.payload.i32; +} + +static inline JS_VALUE_CONSTEXPR jsval_layout +INT32_TO_JSVAL_IMPL(int32_t i) +{ +#if defined(JS_VALUE_IS_CONSTEXPR) + return BUILD_JSVAL(JSVAL_TAG_INT32, i); +#else + jsval_layout l; + l.s.tag = JSVAL_TAG_INT32; + l.s.payload.i32 = i; + return l; +#endif +} + +static inline bool +JSVAL_IS_NUMBER_IMPL(jsval_layout l) +{ + JSValueTag tag = l.s.tag; + MOZ_ASSERT(tag != JSVAL_TAG_CLEAR); + return (uint32_t)tag <= (uint32_t)JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET; +} + +static inline bool +JSVAL_IS_UNDEFINED_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_UNDEFINED; +} + +static inline bool +JSVAL_IS_STRING_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_STRING; +} + +static inline jsval_layout +STRING_TO_JSVAL_IMPL(JSString *str) +{ + jsval_layout l; + MOZ_ASSERT(uintptr_t(str) > 0x1000); + l.s.tag = JSVAL_TAG_STRING; + l.s.payload.str = str; + return l; +} + +static inline JSString * +JSVAL_TO_STRING_IMPL(jsval_layout l) +{ + return l.s.payload.str; +} + +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + l.s.tag = JSVAL_TAG_SYMBOL; + l.s.payload.sym = sym; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.payload.sym; +} + +static inline bool +JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_BOOLEAN; +} + +static inline bool +JSVAL_TO_BOOLEAN_IMPL(jsval_layout l) +{ + return l.s.payload.boo; +} + +static inline jsval_layout +BOOLEAN_TO_JSVAL_IMPL(bool b) +{ + jsval_layout l; + l.s.tag = JSVAL_TAG_BOOLEAN; + l.s.payload.boo = b; + return l; +} + +static inline bool +JSVAL_IS_MAGIC_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_MAGIC; +} + +static inline bool +JSVAL_IS_OBJECT_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_OBJECT; +} + +static inline bool +JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l) +{ + return (uint32_t)l.s.tag < (uint32_t)JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET; +} + +static inline bool +JSVAL_IS_OBJECT_OR_NULL_IMPL(jsval_layout l) +{ + MOZ_ASSERT((uint32_t)l.s.tag <= (uint32_t)JSVAL_TAG_OBJECT); + return (uint32_t)l.s.tag >= (uint32_t)JSVAL_LOWER_INCL_TAG_OF_OBJ_OR_NULL_SET; +} + +static inline JSObject * +JSVAL_TO_OBJECT_IMPL(jsval_layout l) +{ + return l.s.payload.obj; +} + +static inline jsval_layout +OBJECT_TO_JSVAL_IMPL(JSObject *obj) +{ + jsval_layout l; + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); + l.s.tag = JSVAL_TAG_OBJECT; + l.s.payload.obj = obj; + return l; +} + +static inline bool +JSVAL_IS_NULL_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_NULL; +} + +static inline jsval_layout +PRIVATE_PTR_TO_JSVAL_IMPL(void *ptr) +{ + jsval_layout l; + MOZ_ASSERT(((uint32_t)ptr & 1) == 0); + l.s.tag = (JSValueTag)0; + l.s.payload.ptr = ptr; + MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(l)); + return l; +} + +static inline void * +JSVAL_TO_PRIVATE_PTR_IMPL(jsval_layout l) +{ + return l.s.payload.ptr; +} + +static inline bool +JSVAL_IS_GCTHING_IMPL(jsval_layout l) +{ + /* gcc sometimes generates signed < without explicit casts. */ + return (uint32_t)l.s.tag >= (uint32_t)JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET; +} + +static inline js::gc::Cell * +JSVAL_TO_GCTHING_IMPL(jsval_layout l) +{ + return l.s.payload.cell; +} + +static inline uint32_t +JSVAL_TRACE_KIND_IMPL(jsval_layout l) +{ + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return l.s.tag & 0x03; +} + +static inline bool +JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) +{ + return l.s.tag == JSVAL_TAG_INT32 && l.s.payload.i32 == i32; +} + +static inline bool +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) +{ + return (l.s.tag == JSVAL_TAG_BOOLEAN) && (l.s.payload.boo == uint32_t(b)); +} + +static inline jsval_layout +MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) +{ + jsval_layout l; + l.s.tag = JSVAL_TAG_MAGIC; + l.s.payload.why = why; + return l; +} + +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.s.tag = JSVAL_TAG_MAGIC; + l.s.payload.u32 = payload; + return l; +} + +static inline bool +JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) +{ + JSValueTag ltag = lhs.s.tag, rtag = rhs.s.tag; + return ltag == rtag || (ltag < JSVAL_TAG_CLEAR && rtag < JSVAL_TAG_CLEAR); +} + +static inline JSValueType +JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) +{ + uint32_t type = l.s.tag & 0xF; + MOZ_ASSERT(type > JSVAL_TYPE_DOUBLE); + return (JSValueType)type; +} + +#elif defined(JS_PUNBOX64) + +static inline JS_VALUE_CONSTEXPR jsval_layout +BUILD_JSVAL(JSValueTag tag, uint64_t payload) +{ + JS_RETURN_LAYOUT_FROM_BITS((((uint64_t)(uint32_t)tag) << JSVAL_TAG_SHIFT) | payload); +} + +static inline bool +JSVAL_IS_DOUBLE_IMPL(jsval_layout l) +{ + return l.asBits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE; +} + +static inline jsval_layout +DOUBLE_TO_JSVAL_IMPL(double d) +{ + jsval_layout l; + l.asDouble = d; + MOZ_ASSERT(l.asBits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE); + return l; +} + +static inline bool +JSVAL_IS_INT32_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_INT32; +} + +static inline int32_t +JSVAL_TO_INT32_IMPL(jsval_layout l) +{ + return (int32_t)l.asBits; +} + +static inline JS_VALUE_CONSTEXPR jsval_layout +INT32_TO_JSVAL_IMPL(int32_t i32) +{ + JS_RETURN_LAYOUT_FROM_BITS(((uint64_t)(uint32_t)i32) | JSVAL_SHIFTED_TAG_INT32); +} + +static inline bool +JSVAL_IS_NUMBER_IMPL(jsval_layout l) +{ + return l.asBits < JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET; +} + +static inline bool +JSVAL_IS_UNDEFINED_IMPL(jsval_layout l) +{ + return l.asBits == JSVAL_SHIFTED_TAG_UNDEFINED; +} + +static inline bool +JSVAL_IS_STRING_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_STRING; +} + +static inline jsval_layout +STRING_TO_JSVAL_IMPL(JSString *str) +{ + jsval_layout l; + uint64_t strBits = (uint64_t)str; + MOZ_ASSERT(uintptr_t(str) > 0x1000); + MOZ_ASSERT((strBits >> JSVAL_TAG_SHIFT) == 0); + l.asBits = strBits | JSVAL_SHIFTED_TAG_STRING; + return l; +} + +static inline JSString * +JSVAL_TO_STRING_IMPL(jsval_layout l) +{ + return (JSString *)(l.asBits & JSVAL_PAYLOAD_MASK); +} + +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + uint64_t symBits = (uint64_t)sym; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + MOZ_ASSERT((symBits >> JSVAL_TAG_SHIFT) == 0); + l.asBits = symBits | JSVAL_SHIFTED_TAG_SYMBOL; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return (JS::Symbol *)(l.asBits & JSVAL_PAYLOAD_MASK); +} + +static inline bool +JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_BOOLEAN; +} + +static inline bool +JSVAL_TO_BOOLEAN_IMPL(jsval_layout l) +{ + return (bool)(l.asBits & JSVAL_PAYLOAD_MASK); +} + +static inline jsval_layout +BOOLEAN_TO_JSVAL_IMPL(bool b) +{ + jsval_layout l; + l.asBits = ((uint64_t)(uint32_t)b) | JSVAL_SHIFTED_TAG_BOOLEAN; + return l; +} + +static inline bool +JSVAL_IS_MAGIC_IMPL(jsval_layout l) +{ + return (l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_MAGIC; +} + +static inline bool +JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l) +{ + return l.asBits < JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_PRIMITIVE_SET; +} + +static inline bool +JSVAL_IS_OBJECT_IMPL(jsval_layout l) +{ + MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_TAG_OBJECT); + return l.asBits >= JSVAL_SHIFTED_TAG_OBJECT; +} + +static inline bool +JSVAL_IS_OBJECT_OR_NULL_IMPL(jsval_layout l) +{ + MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_TAG_OBJECT); + return l.asBits >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_OBJ_OR_NULL_SET; +} + +static inline JSObject * +JSVAL_TO_OBJECT_IMPL(jsval_layout l) +{ + uint64_t ptrBits = l.asBits & JSVAL_PAYLOAD_MASK; + MOZ_ASSERT((ptrBits & 0x7) == 0); + return (JSObject *)ptrBits; +} + +static inline jsval_layout +OBJECT_TO_JSVAL_IMPL(JSObject *obj) +{ + jsval_layout l; + uint64_t objBits = (uint64_t)obj; + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); + MOZ_ASSERT((objBits >> JSVAL_TAG_SHIFT) == 0); + l.asBits = objBits | JSVAL_SHIFTED_TAG_OBJECT; + return l; +} + +static inline bool +JSVAL_IS_NULL_IMPL(jsval_layout l) +{ + return l.asBits == JSVAL_SHIFTED_TAG_NULL; +} + +static inline bool +JSVAL_IS_GCTHING_IMPL(jsval_layout l) +{ + return l.asBits >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET; +} + +static inline js::gc::Cell * +JSVAL_TO_GCTHING_IMPL(jsval_layout l) +{ + uint64_t ptrBits = l.asBits & JSVAL_PAYLOAD_MASK; + MOZ_ASSERT((ptrBits & 0x7) == 0); + return reinterpret_cast(ptrBits); +} + +static inline uint32_t +JSVAL_TRACE_KIND_IMPL(jsval_layout l) +{ + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) & 0x03; +} + +static inline jsval_layout +PRIVATE_PTR_TO_JSVAL_IMPL(void *ptr) +{ + jsval_layout l; + uint64_t ptrBits = (uint64_t)ptr; + MOZ_ASSERT((ptrBits & 1) == 0); + l.asBits = ptrBits >> 1; + MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(l)); + return l; +} + +static inline void * +JSVAL_TO_PRIVATE_PTR_IMPL(jsval_layout l) +{ + MOZ_ASSERT((l.asBits & 0x8000000000000000LL) == 0); + return (void *)(l.asBits << 1); +} + +static inline bool +JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) +{ + return l.asBits == (((uint64_t)(uint32_t)i32) | JSVAL_SHIFTED_TAG_INT32); +} + +static inline bool +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) +{ + return l.asBits == (((uint64_t)(uint32_t)b) | JSVAL_SHIFTED_TAG_BOOLEAN); +} + +static inline jsval_layout +MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) +{ + jsval_layout l; + l.asBits = ((uint64_t)(uint32_t)why) | JSVAL_SHIFTED_TAG_MAGIC; + return l; +} + +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.asBits = ((uint64_t)payload) | JSVAL_SHIFTED_TAG_MAGIC; + return l; +} + +static inline bool +JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) +{ + uint64_t lbits = lhs.asBits, rbits = rhs.asBits; + return (lbits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE && rbits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE) || + (((lbits ^ rbits) & 0xFFFF800000000000LL) == 0); +} + +static inline JSValueType +JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) +{ + uint64_t type = (l.asBits >> JSVAL_TAG_SHIFT) & 0xF; + MOZ_ASSERT(type > JSVAL_TYPE_DOUBLE); + return (JSValueType)type; +} + +#endif /* JS_PUNBOX64 */ + +static inline bool +JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) +{ + return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l); +} + +static inline jsval_layout JSVAL_TO_IMPL(JS::Value v); +static inline JS_VALUE_CONSTEXPR JS::Value IMPL_TO_JSVAL(jsval_layout l); + +namespace JS { + +static inline JS_VALUE_CONSTEXPR JS::Value UndefinedValue(); + +/** + * Returns a generic quiet NaN value, with all payload bits set to zero. + * + * Among other properties, this NaN's bit pattern conforms to JS::Value's + * bit pattern restrictions. + */ +static MOZ_ALWAYS_INLINE double +GenericNaN() +{ + return mozilla::SpecificNaN(0, 0x8000000000000ULL); +} + +/* MSVC with PGO miscompiles this function. */ +#if defined(_MSC_VER) +# pragma optimize("g", off) +#endif +static inline double +CanonicalizeNaN(double d) +{ + if (MOZ_UNLIKELY(mozilla::IsNaN(d))) + return GenericNaN(); + return d; +} +#if defined(_MSC_VER) +# pragma optimize("", on) +#endif + +/* + * JS::Value is the interface for a single JavaScript Engine value. A few + * general notes on JS::Value: + * + * - JS::Value has setX() and isX() members for X in + * + * { Int32, Double, String, Symbol, Boolean, Undefined, Null, Object, Magic } + * + * JS::Value also contains toX() for each of the non-singleton types. + * + * - Magic is a singleton type whose payload contains either a JSWhyMagic "reason" for + * the magic value or a uint32_t value. By providing JSWhyMagic values when + * creating and checking for magic values, it is possible to assert, at + * runtime, that only magic values with the expected reason flow through a + * particular value. For example, if cx->exception has a magic value, the + * reason must be JS_GENERATOR_CLOSING. + * + * - The JS::Value operations are preferred. The JSVAL_* operations remain for + * compatibility; they may be removed at some point. These operations mostly + * provide similar functionality. But there are a few key differences. One + * is that JS::Value gives null a separate type. + * Also, to help prevent mistakenly boxing a nullable JSObject* as an object, + * Value::setObject takes a JSObject&. (Conversely, Value::toObject returns a + * JSObject&.) A convenience member Value::setObjectOrNull is provided. + * + * - JSVAL_VOID is the same as the singleton value of the Undefined type. + * + * - Note that JS::Value is 8 bytes on 32 and 64-bit architectures. Thus, on + * 32-bit user code should avoid copying jsval/JS::Value as much as possible, + * preferring to pass by const Value &. + */ +class Value +{ + public: + /* + * N.B. the default constructor leaves Value unitialized. Adding a default + * constructor prevents Value from being stored in a union. + */ +#if defined(JS_VALUE_IS_CONSTEXPR) + Value() = default; + Value(const Value& v) = default; +#endif + + /*** Mutators ***/ + + void setNull() { + data.asBits = BUILD_JSVAL(JSVAL_TAG_NULL, 0).asBits; + } + + void setUndefined() { + data.asBits = BUILD_JSVAL(JSVAL_TAG_UNDEFINED, 0).asBits; + } + + void setInt32(int32_t i) { + data = INT32_TO_JSVAL_IMPL(i); + } + + int32_t &getInt32Ref() { + MOZ_ASSERT(isInt32()); + return data.s.payload.i32; + } + + void setDouble(double d) { + data = DOUBLE_TO_JSVAL_IMPL(d); + } + + void setNaN() { + setDouble(GenericNaN()); + } + + double &getDoubleRef() { + MOZ_ASSERT(isDouble()); + return data.asDouble; + } + + void setString(JSString *str) { + MOZ_ASSERT(!IsPoisonedPtr(str)); + data = STRING_TO_JSVAL_IMPL(str); + } + + void setSymbol(JS::Symbol *sym) { + MOZ_ASSERT(!IsPoisonedPtr(sym)); + data = SYMBOL_TO_JSVAL_IMPL(sym); + } + + void setObject(JSObject &obj) { + MOZ_ASSERT(!IsPoisonedPtr(&obj)); + data = OBJECT_TO_JSVAL_IMPL(&obj); + } + + void setBoolean(bool b) { + data = BOOLEAN_TO_JSVAL_IMPL(b); + } + + void setMagic(JSWhyMagic why) { + data = MAGIC_TO_JSVAL_IMPL(why); + } + + void setMagicUint32(uint32_t payload) { + data = MAGIC_UINT32_TO_JSVAL_IMPL(payload); + } + + bool setNumber(uint32_t ui) { + if (ui > JSVAL_INT_MAX) { + setDouble((double)ui); + return false; + } else { + setInt32((int32_t)ui); + return true; + } + } + + bool setNumber(double d) { + int32_t i; + if (mozilla::NumberIsInt32(d, &i)) { + setInt32(i); + return true; + } + + setDouble(d); + return false; + } + + void setObjectOrNull(JSObject *arg) { + if (arg) + setObject(*arg); + else + setNull(); + } + + void swap(Value &rhs) { + uint64_t tmp = rhs.data.asBits; + rhs.data.asBits = data.asBits; + data.asBits = tmp; + } + + /*** Value type queries ***/ + + bool isUndefined() const { + return JSVAL_IS_UNDEFINED_IMPL(data); + } + + bool isNull() const { + return JSVAL_IS_NULL_IMPL(data); + } + + bool isNullOrUndefined() const { + return isNull() || isUndefined(); + } + + bool isInt32() const { + return JSVAL_IS_INT32_IMPL(data); + } + + bool isInt32(int32_t i32) const { + return JSVAL_IS_SPECIFIC_INT32_IMPL(data, i32); + } + + bool isDouble() const { + return JSVAL_IS_DOUBLE_IMPL(data); + } + + bool isNumber() const { + return JSVAL_IS_NUMBER_IMPL(data); + } + + bool isString() const { + return JSVAL_IS_STRING_IMPL(data); + } + + bool isSymbol() const { + return JSVAL_IS_SYMBOL_IMPL(data); + } + + bool isObject() const { + return JSVAL_IS_OBJECT_IMPL(data); + } + + bool isPrimitive() const { + return JSVAL_IS_PRIMITIVE_IMPL(data); + } + + bool isObjectOrNull() const { + return JSVAL_IS_OBJECT_OR_NULL_IMPL(data); + } + + bool isGCThing() const { + return JSVAL_IS_GCTHING_IMPL(data); + } + + bool isBoolean() const { + return JSVAL_IS_BOOLEAN_IMPL(data); + } + + bool isTrue() const { + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, true); + } + + bool isFalse() const { + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, false); + } + + bool isMagic() const { + return JSVAL_IS_MAGIC_IMPL(data); + } + + bool isMagic(JSWhyMagic why) const { + MOZ_ASSERT_IF(isMagic(), data.s.payload.why == why); + return JSVAL_IS_MAGIC_IMPL(data); + } + + bool isMarkable() const { + return JSVAL_IS_TRACEABLE_IMPL(data); + } + + JSGCTraceKind gcKind() const { + MOZ_ASSERT(isMarkable()); + return JSGCTraceKind(JSVAL_TRACE_KIND_IMPL(data)); + } + + JSWhyMagic whyMagic() const { + MOZ_ASSERT(isMagic()); + return data.s.payload.why; + } + + uint32_t magicUint32() const { + MOZ_ASSERT(isMagic()); + return data.s.payload.u32; + } + + /*** Comparison ***/ + + bool operator==(const Value &rhs) const { + return data.asBits == rhs.data.asBits; + } + + bool operator!=(const Value &rhs) const { + return data.asBits != rhs.data.asBits; + } + + friend inline bool SameType(const Value &lhs, const Value &rhs); + + /*** Extract the value's typed payload ***/ + + int32_t toInt32() const { + MOZ_ASSERT(isInt32()); + return JSVAL_TO_INT32_IMPL(data); + } + + double toDouble() const { + MOZ_ASSERT(isDouble()); + return data.asDouble; + } + + double toNumber() const { + MOZ_ASSERT(isNumber()); + return isDouble() ? toDouble() : double(toInt32()); + } + + JSString *toString() const { + MOZ_ASSERT(isString()); + return JSVAL_TO_STRING_IMPL(data); + } + + JS::Symbol *toSymbol() const { + MOZ_ASSERT(isSymbol()); + return JSVAL_TO_SYMBOL_IMPL(data); + } + + JSObject &toObject() const { + MOZ_ASSERT(isObject()); + return *JSVAL_TO_OBJECT_IMPL(data); + } + + JSObject *toObjectOrNull() const { + MOZ_ASSERT(isObjectOrNull()); + return JSVAL_TO_OBJECT_IMPL(data); + } + + js::gc::Cell *toGCThing() const { + MOZ_ASSERT(isGCThing()); + return JSVAL_TO_GCTHING_IMPL(data); + } + + bool toBoolean() const { + MOZ_ASSERT(isBoolean()); + return JSVAL_TO_BOOLEAN_IMPL(data); + } + + uint32_t payloadAsRawUint32() const { + MOZ_ASSERT(!isDouble()); + return data.s.payload.u32; + } + + uint64_t asRawBits() const { + return data.asBits; + } + + JSValueType extractNonDoubleType() const { + return JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(data); + } + + /* + * Private API + * + * Private setters/getters allow the caller to read/write arbitrary types + * that fit in the 64-bit payload. It is the caller's responsibility, after + * storing to a value with setPrivateX to read only using getPrivateX. + * Privates values are given a type which ensures they are not marked. + */ + + void setPrivate(void *ptr) { + data = PRIVATE_PTR_TO_JSVAL_IMPL(ptr); + } + + void *toPrivate() const { + MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(data)); + return JSVAL_TO_PRIVATE_PTR_IMPL(data); + } + + void setPrivateUint32(uint32_t ui) { + MOZ_ASSERT(uint32_t(int32_t(ui)) == ui); + setInt32(int32_t(ui)); + } + + uint32_t toPrivateUint32() const { + return uint32_t(toInt32()); + } + + /* + * An unmarked value is just a void* cast as a Value. Thus, the Value is + * not safe for GC and must not be marked. This API avoids raw casts + * and the ensuing strict-aliasing warnings. + */ + + void setUnmarkedPtr(void *ptr) { + data.asPtr = ptr; + } + + void *toUnmarkedPtr() const { + return data.asPtr; + } + + const size_t *payloadWord() const { +#if defined(JS_NUNBOX32) + return &data.s.payload.word; +#elif defined(JS_PUNBOX64) + return &data.asWord; +#endif + } + + const uintptr_t *payloadUIntPtr() const { +#if defined(JS_NUNBOX32) + return &data.s.payload.uintptr; +#elif defined(JS_PUNBOX64) + return &data.asUIntPtr; +#endif + } + +#if !defined(_MSC_VER) && !defined(__sparc) + // Value must be POD so that MSVC will pass it by value and not in memory + // (bug 689101); the same is true for SPARC as well (bug 737344). More + // precisely, we don't want Value return values compiled as out params. + private: +#endif + + jsval_layout data; + + private: +#if defined(JS_VALUE_IS_CONSTEXPR) + MOZ_IMPLICIT JS_VALUE_CONSTEXPR Value(jsval_layout layout) : data(layout) {} +#endif + + void staticAssertions() { + JS_STATIC_ASSERT(sizeof(JSValueType) == 1); + JS_STATIC_ASSERT(sizeof(JSValueTag) == 4); + JS_STATIC_ASSERT(sizeof(JSWhyMagic) <= 4); + JS_STATIC_ASSERT(sizeof(Value) == 8); + } + + friend jsval_layout (::JSVAL_TO_IMPL)(Value); + friend Value JS_VALUE_CONSTEXPR (::IMPL_TO_JSVAL)(jsval_layout l); + friend Value JS_VALUE_CONSTEXPR (JS::UndefinedValue)(); +}; + +inline bool +IsPoisonedValue(const Value &v) +{ + if (v.isString()) + return IsPoisonedPtr(v.toString()); + if (v.isSymbol()) + return IsPoisonedPtr(v.toSymbol()); + if (v.isObject()) + return IsPoisonedPtr(&v.toObject()); + return false; +} + +inline bool +IsOptimizedPlaceholderMagicValue(const Value &v) +{ + if (v.isMagic()) { + MOZ_ASSERT(v.whyMagic() == JS_OPTIMIZED_ARGUMENTS || v.whyMagic() == JS_OPTIMIZED_OUT); + return true; + } + return false; +} + +static MOZ_ALWAYS_INLINE void +ExposeValueToActiveJS(const Value &v) +{ + if (v.isMarkable()) + ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); +} + +/************************************************************************/ + +static inline Value +NullValue() +{ + Value v; + v.setNull(); + return v; +} + +static inline JS_VALUE_CONSTEXPR Value +UndefinedValue() +{ +#if defined(JS_VALUE_IS_CONSTEXPR) + return Value(BUILD_JSVAL(JSVAL_TAG_UNDEFINED, 0)); +#else + JS::Value v; + v.setUndefined(); + return v; +#endif +} + +static inline Value +Int32Value(int32_t i32) +{ + Value v; + v.setInt32(i32); + return v; +} + +static inline Value +DoubleValue(double dbl) +{ + Value v; + v.setDouble(dbl); + return v; +} + +static inline Value +DoubleNaNValue() +{ + Value v; + v.setNaN(); + return v; +} + +static inline Value +Float32Value(float f) +{ + Value v; + v.setDouble(f); + return v; +} + +static inline Value +StringValue(JSString *str) +{ + Value v; + v.setString(str); + return v; +} + +static inline Value +SymbolValue(JS::Symbol *sym) +{ + Value v; + v.setSymbol(sym); + return v; +} + +static inline Value +BooleanValue(bool boo) +{ + Value v; + v.setBoolean(boo); + return v; +} + +static inline Value +TrueValue() +{ + Value v; + v.setBoolean(true); + return v; +} + +static inline Value +FalseValue() +{ + Value v; + v.setBoolean(false); + return v; +} + +static inline Value +ObjectValue(JSObject &obj) +{ + Value v; + v.setObject(obj); + return v; +} + +static inline Value +ObjectValueCrashOnTouch() +{ + Value v; + v.setObject(*reinterpret_cast(0x42)); + return v; +} + +static inline Value +MagicValue(JSWhyMagic why) +{ + Value v; + v.setMagic(why); + return v; +} + +static inline Value +MagicValueUint32(uint32_t payload) +{ + Value v; + v.setMagicUint32(payload); + return v; +} + +static inline Value +NumberValue(float f) +{ + Value v; + v.setNumber(f); + return v; +} + +static inline Value +NumberValue(double dbl) +{ + Value v; + v.setNumber(dbl); + return v; +} + +static inline Value +NumberValue(int8_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(uint8_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(int16_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(uint16_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(int32_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(uint32_t i) +{ + Value v; + v.setNumber(i); + return v; +} + +namespace detail { + +template +class MakeNumberValue +{ + public: + template + static inline Value create(const T t) + { + Value v; + if (JSVAL_INT_MIN <= t && t <= JSVAL_INT_MAX) + v.setInt32(int32_t(t)); + else + v.setDouble(double(t)); + return v; + } +}; + +template <> +class MakeNumberValue +{ + public: + template + static inline Value create(const T t) + { + Value v; + if (t <= JSVAL_INT_MAX) + v.setInt32(int32_t(t)); + else + v.setDouble(double(t)); + return v; + } +}; + +} // namespace detail + +template +static inline Value +NumberValue(const T t) +{ + MOZ_ASSERT(T(double(t)) == t, "value creation would be lossy"); + return detail::MakeNumberValue::is_signed>::create(t); +} + +static inline Value +ObjectOrNullValue(JSObject *obj) +{ + Value v; + v.setObjectOrNull(obj); + return v; +} + +static inline Value +PrivateValue(void *ptr) +{ + Value v; + v.setPrivate(ptr); + return v; +} + +static inline Value +PrivateUint32Value(uint32_t ui) +{ + Value v; + v.setPrivateUint32(ui); + return v; +} + +inline bool +SameType(const Value &lhs, const Value &rhs) +{ + return JSVAL_SAME_TYPE_IMPL(lhs.data, rhs.data); +} + +} // namespace JS + +/************************************************************************/ + +#ifdef JSGC_GENERATIONAL +namespace JS { +JS_PUBLIC_API(void) HeapValuePostBarrier(Value *valuep); +JS_PUBLIC_API(void) HeapValueRelocate(Value *valuep); +} +#endif + +namespace js { + +template <> struct GCMethods +{ + static JS::Value initial() { return JS::UndefinedValue(); } + static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } +}; + +template <> struct GCMethods +{ + static JS::Value initial() { return JS::UndefinedValue(); } + static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } + static bool needsPostBarrier(const JS::Value &v) { + return v.isObject() && gc::IsInsideNursery(reinterpret_cast(&v.toObject())); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JS::Value *v) { JS::HeapValuePostBarrier(v); } + static void relocate(JS::Value *v) { JS::HeapValueRelocate(v); } +#endif +}; + +template class MutableValueOperations; + +/* + * A class designed for CRTP use in implementing the non-mutating parts of the + * Value interface in Value-like classes. Outer must be a class inheriting + * ValueOperations with a visible extract() method returning the + * const Value* abstracted by Outer. + */ +template +class ValueOperations +{ + friend class MutableValueOperations; + + const JS::Value * value() const { return static_cast(this)->extract(); } + + public: + bool isUndefined() const { return value()->isUndefined(); } + bool isNull() const { return value()->isNull(); } + bool isBoolean() const { return value()->isBoolean(); } + bool isTrue() const { return value()->isTrue(); } + bool isFalse() const { return value()->isFalse(); } + bool isNumber() const { return value()->isNumber(); } + bool isInt32() const { return value()->isInt32(); } + bool isDouble() const { return value()->isDouble(); } + bool isString() const { return value()->isString(); } + bool isSymbol() const { return value()->isSymbol(); } + bool isObject() const { return value()->isObject(); } + bool isMagic() const { return value()->isMagic(); } + bool isMagic(JSWhyMagic why) const { return value()->isMagic(why); } + bool isMarkable() const { return value()->isMarkable(); } + bool isPrimitive() const { return value()->isPrimitive(); } + bool isGCThing() const { return value()->isGCThing(); } + + bool isNullOrUndefined() const { return value()->isNullOrUndefined(); } + bool isObjectOrNull() const { return value()->isObjectOrNull(); } + + bool toBoolean() const { return value()->toBoolean(); } + double toNumber() const { return value()->toNumber(); } + int32_t toInt32() const { return value()->toInt32(); } + double toDouble() const { return value()->toDouble(); } + JSString *toString() const { return value()->toString(); } + JS::Symbol *toSymbol() const { return value()->toSymbol(); } + JSObject &toObject() const { return value()->toObject(); } + JSObject *toObjectOrNull() const { return value()->toObjectOrNull(); } + void *toGCThing() const { return value()->toGCThing(); } + uint64_t asRawBits() const { return value()->asRawBits(); } + + JSValueType extractNonDoubleType() const { return value()->extractNonDoubleType(); } + uint32_t toPrivateUint32() const { return value()->toPrivateUint32(); } + + JSWhyMagic whyMagic() const { return value()->whyMagic(); } + uint32_t magicUint32() const { return value()->magicUint32(); } +}; + +/* + * A class designed for CRTP use in implementing all the mutating parts of the + * Value interface in Value-like classes. Outer must be a class inheriting + * MutableValueOperations with visible extractMutable() and extract() + * methods returning the const Value* and Value* abstracted by Outer. + */ +template +class MutableValueOperations : public ValueOperations +{ + JS::Value * value() { return static_cast(this)->extractMutable(); } + + public: + void setNull() { value()->setNull(); } + void setUndefined() { value()->setUndefined(); } + void setInt32(int32_t i) { value()->setInt32(i); } + void setDouble(double d) { value()->setDouble(d); } + void setNaN() { setDouble(JS::GenericNaN()); } + void setBoolean(bool b) { value()->setBoolean(b); } + void setMagic(JSWhyMagic why) { value()->setMagic(why); } + bool setNumber(uint32_t ui) { return value()->setNumber(ui); } + bool setNumber(double d) { return value()->setNumber(d); } + void setString(JSString *str) { this->value()->setString(str); } + void setSymbol(JS::Symbol *sym) { this->value()->setSymbol(sym); } + void setObject(JSObject &obj) { this->value()->setObject(obj); } + void setObjectOrNull(JSObject *arg) { this->value()->setObjectOrNull(arg); } +}; + +/* + * Augment the generic Heap interface when T = Value with + * type-querying, value-extracting, and mutating operations. + */ +template <> +class HeapBase : public ValueOperations > +{ + typedef JS::Heap Outer; + + friend class ValueOperations; + + const JS::Value * extract() const { return static_cast(this)->address(); } + + void setBarriered(const JS::Value &v) { + static_cast *>(this)->set(v); + } + + public: + void setNull() { setBarriered(JS::NullValue()); } + void setUndefined() { setBarriered(JS::UndefinedValue()); } + void setInt32(int32_t i) { setBarriered(JS::Int32Value(i)); } + void setDouble(double d) { setBarriered(JS::DoubleValue(d)); } + void setNaN() { setDouble(JS::GenericNaN()); } + void setBoolean(bool b) { setBarriered(JS::BooleanValue(b)); } + void setMagic(JSWhyMagic why) { setBarriered(JS::MagicValue(why)); } + void setString(JSString *str) { setBarriered(JS::StringValue(str)); } + void setSymbol(JS::Symbol *sym) { setBarriered(JS::SymbolValue(sym)); } + void setObject(JSObject &obj) { setBarriered(JS::ObjectValue(obj)); } + + bool setNumber(uint32_t ui) { + if (ui > JSVAL_INT_MAX) { + setDouble((double)ui); + return false; + } else { + setInt32((int32_t)ui); + return true; + } + } + + bool setNumber(double d) { + int32_t i; + if (mozilla::NumberIsInt32(d, &i)) { + setInt32(i); + return true; + } + + setDouble(d); + return false; + } + + void setObjectOrNull(JSObject *arg) { + if (arg) + setObject(*arg); + else + setNull(); + } +}; + +/* + * Augment the generic Handle interface when T = Value with type-querying + * and value-extracting operations. + */ +template <> +class HandleBase : public ValueOperations > +{ + friend class ValueOperations >; + const JS::Value * extract() const { + return static_cast*>(this)->address(); + } +}; + +/* + * Augment the generic MutableHandle interface when T = Value with + * type-querying, value-extracting, and mutating operations. + */ +template <> +class MutableHandleBase : public MutableValueOperations > +{ + friend class ValueOperations >; + const JS::Value * extract() const { + return static_cast*>(this)->address(); + } + + friend class MutableValueOperations >; + JS::Value * extractMutable() { + return static_cast*>(this)->address(); + } +}; + +/* + * Augment the generic Rooted interface when T = Value with type-querying, + * value-extracting, and mutating operations. + */ +template <> +class RootedBase : public MutableValueOperations > +{ + friend class ValueOperations >; + const JS::Value * extract() const { + return static_cast*>(this)->address(); + } + + friend class MutableValueOperations >; + JS::Value * extractMutable() { + return static_cast*>(this)->address(); + } +}; + +} // namespace js + +inline jsval_layout +JSVAL_TO_IMPL(JS::Value v) +{ + return v.data; +} + +inline JS_VALUE_CONSTEXPR JS::Value +IMPL_TO_JSVAL(jsval_layout l) +{ +#if defined(JS_VALUE_IS_CONSTEXPR) + return JS::Value(l); +#else + JS::Value v; + v.data = l; + return v; +#endif +} + +namespace JS { + +#ifndef __GNUC__ +/* + * The default assignment operator for |struct C| has the signature: + * + * C& C::operator=(const C&) + * + * And in particular requires implicit conversion of |this| to type |C| for the + * return value. But |volatile C| cannot thus be converted to |C|, so just + * doing |sink = hold| as in the non-specialized version would fail to compile. + * Do the assignment on asBits instead, since I don't think we want to give + * jsval_layout an assignment operator returning |volatile jsval_layout|. + */ +template<> +inline Anchor::~Anchor() +{ + volatile uint64_t bits; + bits = JSVAL_TO_IMPL(hold).asBits; +} +#endif + +#ifdef JS_DEBUG +namespace detail { + +struct ValueAlignmentTester { char c; JS::Value v; }; +static_assert(sizeof(ValueAlignmentTester) == 16, + "JS::Value must be 16-byte-aligned"); + +struct LayoutAlignmentTester { char c; jsval_layout l; }; +static_assert(sizeof(LayoutAlignmentTester) == 16, + "jsval_layout must be 16-byte-aligned"); + +} // namespace detail +#endif /* JS_DEBUG */ + +} // namespace JS + +/* + * JS::Value and jsval are the same type; jsval is the old name, kept around + * for backwards compatibility along with all the JSVAL_* operations below. + * jsval_layout is an implementation detail and should not be used externally. + */ +typedef JS::Value jsval; + +static_assert(sizeof(jsval_layout) == sizeof(JS::Value), + "jsval_layout and JS::Value must have identical layouts"); + +/************************************************************************/ + +static inline JS_VALUE_CONSTEXPR jsval +INT_TO_JSVAL(int32_t i) +{ + return IMPL_TO_JSVAL(INT32_TO_JSVAL_IMPL(i)); +} + +static inline JS_VALUE_CONSTEXPR jsval +DOUBLE_TO_JSVAL(double d) +{ + /* + * This is a manually inlined version of: + * d = JS_CANONICALIZE_NAN(d); + * return IMPL_TO_JSVAL(DOUBLE_TO_JSVAL_IMPL(d)); + * because GCC from XCode 3.1.4 miscompiles the above code. + */ +#if defined(JS_VALUE_IS_CONSTEXPR) + return IMPL_TO_JSVAL(MOZ_UNLIKELY(d != d) + ? (jsval_layout) { .asBits = 0x7FF8000000000000LL } + : (jsval_layout) { .asDouble = d }); +#else + jsval_layout l; + if (MOZ_UNLIKELY(d != d)) + l.asBits = 0x7FF8000000000000LL; + else + l.asDouble = d; + return IMPL_TO_JSVAL(l); +#endif +} + +static inline JS_VALUE_CONSTEXPR jsval +UINT_TO_JSVAL(uint32_t i) +{ + return (i <= JSVAL_INT_MAX + ? INT_TO_JSVAL((int32_t)i) + : DOUBLE_TO_JSVAL((double)i)); +} + +static inline jsval +STRING_TO_JSVAL(JSString *str) +{ + return IMPL_TO_JSVAL(STRING_TO_JSVAL_IMPL(str)); +} + +static inline jsval +OBJECT_TO_JSVAL(JSObject *obj) +{ + if (obj) + return IMPL_TO_JSVAL(OBJECT_TO_JSVAL_IMPL(obj)); + return IMPL_TO_JSVAL(BUILD_JSVAL(JSVAL_TAG_NULL, 0)); +} + +static inline jsval +BOOLEAN_TO_JSVAL(bool b) +{ + return IMPL_TO_JSVAL(BOOLEAN_TO_JSVAL_IMPL(b)); +} + +/* To be GC-safe, privates are tagged as doubles. */ + +static inline jsval +PRIVATE_TO_JSVAL(void *ptr) +{ + return IMPL_TO_JSVAL(PRIVATE_PTR_TO_JSVAL_IMPL(ptr)); +} + +// JS constants. For efficiency, prefer predicates (e.g. v.isNull()) and +// constructing values from scratch (e.g. Int32Value(0)). These constants are +// stored in memory and initialized at startup, so testing against them and +// using them requires memory loads and will be correspondingly slow. +extern JS_PUBLIC_DATA(const jsval) JSVAL_NULL; +extern JS_PUBLIC_DATA(const jsval) JSVAL_ZERO; +extern JS_PUBLIC_DATA(const jsval) JSVAL_ONE; +extern JS_PUBLIC_DATA(const jsval) JSVAL_FALSE; +extern JS_PUBLIC_DATA(const jsval) JSVAL_TRUE; +extern JS_PUBLIC_DATA(const jsval) JSVAL_VOID; + +namespace JS { + +extern JS_PUBLIC_DATA(const HandleValue) NullHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) TrueHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) FalseHandleValue; + +} + +#undef JS_VALUE_IS_CONSTEXPR +#undef JS_RETURN_LAYOUT_FROM_BITS + +#endif /* js_Value_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Vector.h new file mode 100644 index 0000000000..a2d24b10ed --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/js/Vector.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_Vector_h +#define js_Vector_h + +#include "mozilla/Vector.h" + +/* Silence dire "bugs in previous versions of MSVC have been fixed" warnings */ +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4345) +#endif + +namespace js { + +class TempAllocPolicy; + +// If we had C++11 template aliases, we could just use this: +// +// template +// using Vector = mozilla::Vector; +// +// ...and get rid of all the CRTP madness in mozilla::Vector(Base). But we +// can't because compiler support's not up to snuff. (Template aliases are in +// gcc 4.7 and clang 3.0 and are expected to be in MSVC 2013.) Instead, have a +// completely separate class inheriting from mozilla::Vector, and throw CRTP at +// the problem til things work. +// +// This workaround presents a couple issues. First, because js::Vector is a +// distinct type from mozilla::Vector, overload resolution, method calls, etc. +// are affected. *Hopefully* this won't be too bad in practice. (A bunch of +// places had to be fixed when mozilla::Vector was introduced, but it wasn't a +// crazy number.) Second, mozilla::Vector's interface has to be made subclass- +// ready via CRTP -- or rather, via mozilla::VectorBase, which basically no one +// should use. :-) Third, we have to redefine the constructors and the non- +// inherited operators. Blech. Happily there aren't too many of these, so it +// isn't the end of the world. + +template +class Vector + : public mozilla::VectorBase > +{ + typedef typename mozilla::VectorBase Base; + + public: + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + Vector(Vector &&vec) : Base(mozilla::Move(vec)) {} + Vector &operator=(Vector &&vec) { + return Base::operator=(mozilla::Move(vec)); + } +}; + +} // namespace js + +#endif /* js_Vector_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/jsalloc.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsalloc.h new file mode 100644 index 0000000000..a1e547cec9 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsalloc.h @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * JS allocation policies. + * + * The allocators here are for system memory with lifetimes which are not + * managed by the GC. See the comment at the top of vm/MallocProvider.h. + */ + +#ifndef jsalloc_h +#define jsalloc_h + +#include "js/TypeDecls.h" +#include "js/Utility.h" + +namespace js { + +struct ContextFriendFields; + +/* Policy for using system memory functions and doing no error reporting. */ +class SystemAllocPolicy +{ + public: + void *malloc_(size_t bytes) { return js_malloc(bytes); } + void *calloc_(size_t bytes) { return js_calloc(bytes); } + void *realloc_(void *p, size_t oldBytes, size_t bytes) { return js_realloc(p, bytes); } + void free_(void *p) { js_free(p); } + void reportAllocOverflow() const {} +}; + +/* + * Allocation policy that calls the system memory functions and reports errors + * to the context. Since the JSContext given on construction is stored for + * the lifetime of the container, this policy may only be used for containers + * whose lifetime is a shorter than the given JSContext. + * + * FIXME bug 647103 - rewrite this in terms of temporary allocation functions, + * not the system ones. + */ +class TempAllocPolicy +{ + ContextFriendFields *const cx_; + + /* + * Non-inline helper to call JSRuntime::onOutOfMemory with minimal + * code bloat. + */ + JS_FRIEND_API(void *) onOutOfMemory(void *p, size_t nbytes); + + public: + MOZ_IMPLICIT TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( + MOZ_IMPLICIT TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} + + void *malloc_(size_t bytes) { + void *p = js_malloc(bytes); + if (MOZ_UNLIKELY(!p)) + p = onOutOfMemory(nullptr, bytes); + return p; + } + + void *calloc_(size_t bytes) { + void *p = js_calloc(bytes); + if (MOZ_UNLIKELY(!p)) + p = onOutOfMemory(nullptr, bytes); + return p; + } + + void *realloc_(void *p, size_t oldBytes, size_t bytes) { + void *p2 = js_realloc(p, bytes); + if (MOZ_UNLIKELY(!p2)) + p2 = onOutOfMemory(p2, bytes); + return p2; + } + + void free_(void *p) { + js_free(p); + } + + JS_FRIEND_API(void) reportAllocOverflow() const; +}; + +} /* namespace js */ + +#endif /* jsalloc_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/jsapi.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsapi.h new file mode 100644 index 0000000000..4c4a24dfeb --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsapi.h @@ -0,0 +1,5250 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JavaScript API. */ + +#ifndef jsapi_h +#define jsapi_h + +#include "mozilla/Char16.h" +#include "mozilla/FloatingPoint.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/Range.h" +#include "mozilla/RangedPtr.h" +#include "mozilla/TypedEnum.h" + +#include +#include +#include +#include + +#include "jsalloc.h" +#include "jspubtd.h" + +#include "js/CallArgs.h" +#include "js/Class.h" +#include "js/HashTable.h" +#include "js/Id.h" +#include "js/Principals.h" +#include "js/RootingAPI.h" +#include "js/TracingAPI.h" +#include "js/Utility.h" +#include "js/Value.h" +#include "js/Vector.h" + +/************************************************************************/ + +namespace JS { + +class Latin1CharsZ; +class TwoByteChars; + +#if defined JS_THREADSAFE && defined JS_DEBUG + +class JS_PUBLIC_API(AutoCheckRequestDepth) +{ + JSContext *cx; + public: + explicit AutoCheckRequestDepth(JSContext *cx); + explicit AutoCheckRequestDepth(js::ContextFriendFields *cx); + ~AutoCheckRequestDepth(); +}; + +# define CHECK_REQUEST(cx) \ + JS::AutoCheckRequestDepth _autoCheckRequestDepth(cx) + +#else + +# define CHECK_REQUEST(cx) \ + ((void) 0) + +#endif /* JS_THREADSAFE && JS_DEBUG */ + +#ifdef JS_DEBUG +/* + * Assert that we're not doing GC on cx, that we're in a request as + * needed, and that the compartments for cx and v are correct. + * Also check that GC would be safe at this point. + */ +JS_PUBLIC_API(void) +AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v); +#else +inline void AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v) { + /* Do nothing */ +} +#endif /* JS_DEBUG */ + +/* AutoValueArray roots an internal fixed-size array of Values. */ +template +class AutoValueArray : public AutoGCRooter +{ + const size_t length_; + Value elements_[N]; + + public: + explicit AutoValueArray(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, VALARRAY), length_(N) + { + /* Always initialize in case we GC before assignment. */ + mozilla::PodArrayZero(elements_); + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + unsigned length() const { return length_; } + const Value *begin() const { return elements_; } + Value *begin() { return elements_; } + + HandleValue operator[](unsigned i) const { + JS_ASSERT(i < N); + return HandleValue::fromMarkedLocation(&elements_[i]); + } + MutableHandleValue operator[](unsigned i) { + JS_ASSERT(i < N); + return MutableHandleValue::fromMarkedLocation(&elements_[i]); + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +template +class AutoVectorRooter : protected AutoGCRooter +{ + typedef js::Vector VectorImpl; + VectorImpl vector; + + public: + explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, tag), vector(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + explicit AutoVectorRooter(js::ContextFriendFields *cx, ptrdiff_t tag + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, tag), vector(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + typedef T ElementType; + typedef typename VectorImpl::Range Range; + + size_t length() const { return vector.length(); } + bool empty() const { return vector.empty(); } + + bool append(const T &v) { return vector.append(v); } + bool append(const T *ptr, size_t len) { return vector.append(ptr, len); } + bool appendAll(const AutoVectorRooter &other) { + return vector.appendAll(other.vector); + } + + bool insert(T *p, const T &val) { return vector.insert(p, val); } + + /* For use when space has already been reserved. */ + void infallibleAppend(const T &v) { vector.infallibleAppend(v); } + + void popBack() { vector.popBack(); } + T popCopy() { return vector.popCopy(); } + + bool growBy(size_t inc) { + size_t oldLength = vector.length(); + if (!vector.growByUninitialized(inc)) + return false; + makeRangeGCSafe(oldLength); + return true; + } + + bool resize(size_t newLength) { + size_t oldLength = vector.length(); + if (newLength <= oldLength) { + vector.shrinkBy(oldLength - newLength); + return true; + } + if (!vector.growByUninitialized(newLength - oldLength)) + return false; + makeRangeGCSafe(oldLength); + return true; + } + + void clear() { vector.clear(); } + + bool reserve(size_t newLength) { + return vector.reserve(newLength); + } + + JS::MutableHandle operator[](size_t i) { + return JS::MutableHandle::fromMarkedLocation(&vector[i]); + } + JS::Handle operator[](size_t i) const { + return JS::Handle::fromMarkedLocation(&vector[i]); + } + + const T *begin() const { return vector.begin(); } + T *begin() { return vector.begin(); } + + const T *end() const { return vector.end(); } + T *end() { return vector.end(); } + + Range all() { return vector.all(); } + + const T &back() const { return vector.back(); } + + friend void AutoGCRooter::trace(JSTracer *trc); + + private: + void makeRangeGCSafe(size_t oldLength) { + T *t = vector.begin() + oldLength; + for (size_t i = oldLength; i < vector.length(); ++i, ++t) + memset(t, 0, sizeof(T)); + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +template +class AutoHashMapRooter : protected AutoGCRooter +{ + private: + typedef js::HashMap HashMapImpl; + + public: + explicit AutoHashMapRooter(JSContext *cx, ptrdiff_t tag + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, tag), map(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + typedef Key KeyType; + typedef Value ValueType; + typedef typename HashMapImpl::Entry Entry; + typedef typename HashMapImpl::Lookup Lookup; + typedef typename HashMapImpl::Ptr Ptr; + typedef typename HashMapImpl::AddPtr AddPtr; + + bool init(uint32_t len = 16) { + return map.init(len); + } + bool initialized() const { + return map.initialized(); + } + Ptr lookup(const Lookup &l) const { + return map.lookup(l); + } + void remove(Ptr p) { + map.remove(p); + } + AddPtr lookupForAdd(const Lookup &l) const { + return map.lookupForAdd(l); + } + + template + bool add(AddPtr &p, const KeyInput &k, const ValueInput &v) { + return map.add(p, k, v); + } + + bool add(AddPtr &p, const Key &k) { + return map.add(p, k); + } + + template + bool relookupOrAdd(AddPtr &p, const KeyInput &k, const ValueInput &v) { + return map.relookupOrAdd(p, k, v); + } + + typedef typename HashMapImpl::Range Range; + Range all() const { + return map.all(); + } + + typedef typename HashMapImpl::Enum Enum; + + void clear() { + map.clear(); + } + + void finish() { + map.finish(); + } + + bool empty() const { + return map.empty(); + } + + uint32_t count() const { + return map.count(); + } + + size_t capacity() const { + return map.capacity(); + } + + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return map.sizeOfExcludingThis(mallocSizeOf); + } + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return map.sizeOfIncludingThis(mallocSizeOf); + } + + uint32_t generation() const { + return map.generation(); + } + + /************************************************** Shorthand operations */ + + bool has(const Lookup &l) const { + return map.has(l); + } + + template + bool put(const KeyInput &k, const ValueInput &v) { + return map.put(k, v); + } + + template + bool putNew(const KeyInput &k, const ValueInput &v) { + return map.putNew(k, v); + } + + Ptr lookupWithDefault(const Key &k, const Value &defaultValue) { + return map.lookupWithDefault(k, defaultValue); + } + + void remove(const Lookup &l) { + map.remove(l); + } + + friend void AutoGCRooter::trace(JSTracer *trc); + + private: + AutoHashMapRooter(const AutoHashMapRooter &hmr) MOZ_DELETE; + AutoHashMapRooter &operator=(const AutoHashMapRooter &hmr) MOZ_DELETE; + + HashMapImpl map; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +template +class AutoHashSetRooter : protected AutoGCRooter +{ + private: + typedef js::HashSet HashSetImpl; + + public: + explicit AutoHashSetRooter(JSContext *cx, ptrdiff_t tag + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, tag), set(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + typedef typename HashSetImpl::Lookup Lookup; + typedef typename HashSetImpl::Ptr Ptr; + typedef typename HashSetImpl::AddPtr AddPtr; + + bool init(uint32_t len = 16) { + return set.init(len); + } + bool initialized() const { + return set.initialized(); + } + Ptr lookup(const Lookup &l) const { + return set.lookup(l); + } + void remove(Ptr p) { + set.remove(p); + } + AddPtr lookupForAdd(const Lookup &l) const { + return set.lookupForAdd(l); + } + + bool add(AddPtr &p, const T &t) { + return set.add(p, t); + } + + bool relookupOrAdd(AddPtr &p, const Lookup &l, const T &t) { + return set.relookupOrAdd(p, l, t); + } + + typedef typename HashSetImpl::Range Range; + Range all() const { + return set.all(); + } + + typedef typename HashSetImpl::Enum Enum; + + void clear() { + set.clear(); + } + + void finish() { + set.finish(); + } + + bool empty() const { + return set.empty(); + } + + uint32_t count() const { + return set.count(); + } + + size_t capacity() const { + return set.capacity(); + } + + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return set.sizeOfExcludingThis(mallocSizeOf); + } + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return set.sizeOfIncludingThis(mallocSizeOf); + } + + uint32_t generation() const { + return set.generation(); + } + + /************************************************** Shorthand operations */ + + bool has(const Lookup &l) const { + return set.has(l); + } + + bool put(const T &t) { + return set.put(t); + } + + bool putNew(const T &t) { + return set.putNew(t); + } + + void remove(const Lookup &l) { + set.remove(l); + } + + friend void AutoGCRooter::trace(JSTracer *trc); + + private: + AutoHashSetRooter(const AutoHashSetRooter &hmr) MOZ_DELETE; + AutoHashSetRooter &operator=(const AutoHashSetRooter &hmr) MOZ_DELETE; + + HashSetImpl set; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class MOZ_STACK_CLASS AutoValueVector : public AutoVectorRooter +{ + public: + explicit AutoValueVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, VALVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class AutoIdVector : public AutoVectorRooter +{ + public: + explicit AutoIdVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, IDVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class AutoObjectVector : public AutoVectorRooter +{ + public: + explicit AutoObjectVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, OBJVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class AutoFunctionVector : public AutoVectorRooter +{ + public: + explicit AutoFunctionVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, FUNVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + explicit AutoFunctionVector(js::ContextFriendFields *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, FUNVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class AutoScriptVector : public AutoVectorRooter +{ + public: + explicit AutoScriptVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, SCRIPTVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* + * Custom rooting behavior for internal and external clients. + */ +class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter +{ + public: + template + explicit CustomAutoRooter(CX *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, CUSTOM) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + friend void AutoGCRooter::trace(JSTracer *trc); + + protected: + /* Supplied by derived class to trace roots. */ + virtual void trace(JSTracer *trc) = 0; + + private: + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* + * RootedGeneric allows a class to instantiate its own Rooted type by + * including the method: + * + * void trace(JSTracer *trc); + * + * The trace() method must trace all of the class's fields. + */ +template +class RootedGeneric : private CustomAutoRooter +{ + public: + template + explicit RootedGeneric(CX *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + template + explicit RootedGeneric(CX *cx, const T& initial MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx), value(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + operator const T&() const { return value; } + T operator->() const { return value; } + + private: + virtual void trace(JSTracer *trc) { value->trace(trc); } + + T value; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* A handle to an array of rooted values. */ +class HandleValueArray +{ + const size_t length_; + const Value * const elements_; + + HandleValueArray(size_t len, const Value *elements) : length_(len), elements_(elements) {} + + public: + explicit HandleValueArray(const RootedValue& value) : length_(1), elements_(value.address()) {} + + MOZ_IMPLICIT HandleValueArray(const AutoValueVector& values) + : length_(values.length()), elements_(values.begin()) {} + + template + HandleValueArray(const AutoValueArray& values) : length_(N), elements_(values.begin()) {} + + /* CallArgs must already be rooted somewhere up the stack. */ + MOZ_IMPLICIT HandleValueArray(const JS::CallArgs& args) : length_(args.length()), elements_(args.array()) {} + + /* Use with care! Only call this if the data is guaranteed to be marked. */ + static HandleValueArray fromMarkedLocation(size_t len, const Value *elements) { + return HandleValueArray(len, elements); + } + + static HandleValueArray subarray(const HandleValueArray& values, size_t startIndex, size_t len) { + JS_ASSERT(startIndex + len <= values.length()); + return HandleValueArray(len, values.begin() + startIndex); + } + + static HandleValueArray empty() { + return HandleValueArray(0, nullptr); + } + + size_t length() const { return length_; } + const Value *begin() const { return elements_; } + + HandleValue operator[](size_t i) const { + JS_ASSERT(i < length_); + return HandleValue::fromMarkedLocation(&elements_[i]); + } +}; + +} /* namespace JS */ + +/************************************************************************/ + +struct JSFreeOp { + private: + JSRuntime *runtime_; + + protected: + explicit JSFreeOp(JSRuntime *rt) + : runtime_(rt) { } + + public: + JSRuntime *runtime() const { + return runtime_; + } +}; + +/* Callbacks and their arguments. */ + +/************************************************************************/ + +typedef enum JSContextOp { + JSCONTEXT_NEW, + JSCONTEXT_DESTROY +} JSContextOp; + +/* + * The possible values for contextOp when the runtime calls the callback are: + * JSCONTEXT_NEW JS_NewContext successfully created a new JSContext + * instance. The callback can initialize the instance as + * required. If the callback returns false, the instance + * will be destroyed and JS_NewContext returns null. In + * this case the callback is not called again. + * JSCONTEXT_DESTROY One of JS_DestroyContext* methods is called. The + * callback may perform its own cleanup and must always + * return true. + * Any other value For future compatibility the callback must do nothing + * and return true in this case. + */ +typedef bool +(* JSContextCallback)(JSContext *cx, unsigned contextOp, void *data); + +typedef enum JSGCStatus { + JSGC_BEGIN, + JSGC_END +} JSGCStatus; + +typedef void +(* JSGCCallback)(JSRuntime *rt, JSGCStatus status, void *data); + +typedef enum JSFinalizeStatus { + /* + * Called when preparing to sweep a group of compartments, before anything + * has been swept. The collector will not yield to the mutator before + * calling the callback with JSFINALIZE_GROUP_END status. + */ + JSFINALIZE_GROUP_START, + + /* + * Called when preparing to sweep a group of compartments. Weak references + * to unmarked things have been removed and things that are not swept + * incrementally have been finalized at this point. The collector may yield + * to the mutator after this point. + */ + JSFINALIZE_GROUP_END, + + /* + * Called at the end of collection when everything has been swept. + */ + JSFINALIZE_COLLECTION_END +} JSFinalizeStatus; + +typedef void +(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment, void *data); + +typedef bool +(* JSInterruptCallback)(JSContext *cx); + +typedef void +(* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report); + +#ifdef MOZ_TRACE_JSCALLS +typedef void +(* JSFunctionCallback)(const JSFunction *fun, + const JSScript *scr, + const JSContext *cx, + int entering); +#endif + +/* + * Possible exception types. These types are part of a JSErrorFormatString + * structure. They define which error to throw in case of a runtime error. + * JSEXN_NONE marks an unthrowable error. + */ +typedef enum JSExnType { + JSEXN_NONE = -1, + JSEXN_ERR, + JSEXN_INTERNALERR, + JSEXN_EVALERR, + JSEXN_RANGEERR, + JSEXN_REFERENCEERR, + JSEXN_SYNTAXERR, + JSEXN_TYPEERR, + JSEXN_URIERR, + JSEXN_LIMIT +} JSExnType; + +typedef struct JSErrorFormatString { + /* The error format string in ASCII. */ + const char *format; + + /* The number of arguments to expand in the formatted error message. */ + uint16_t argCount; + + /* One of the JSExnType constants above. */ + int16_t exnType; +} JSErrorFormatString; + +typedef const JSErrorFormatString * +(* JSErrorCallback)(void *userRef, const unsigned errorNumber); + +typedef bool +(* JSLocaleToUpperCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); + +typedef bool +(* JSLocaleToLowerCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); + +typedef bool +(* JSLocaleCompare)(JSContext *cx, JS::HandleString src1, JS::HandleString src2, + JS::MutableHandleValue rval); + +typedef bool +(* JSLocaleToUnicode)(JSContext *cx, const char *src, JS::MutableHandleValue rval); + +/* + * Callback used to ask the embedding for the cross compartment wrapper handler + * that implements the desired prolicy for this kind of object in the + * destination compartment. |obj| is the object to be wrapped. If |existing| is + * non-nullptr, it will point to an existing wrapper object that should be + * re-used if possible. |existing| is guaranteed to be a cross-compartment + * wrapper with a lazily-defined prototype and the correct global. It is + * guaranteed not to wrap a function. + */ +typedef JSObject * +(* JSWrapObjectCallback)(JSContext *cx, JS::HandleObject existing, JS::HandleObject obj, + JS::HandleObject parent, unsigned flags); + +/* + * Callback used by the wrap hook to ask the embedding to prepare an object + * for wrapping in a context. This might include unwrapping other wrappers + * or even finding a more suitable object for the new compartment. + */ +typedef JSObject * +(* JSPreWrapCallback)(JSContext *cx, JS::HandleObject scope, JS::HandleObject obj, + unsigned flags); + +struct JSWrapObjectCallbacks +{ + JSWrapObjectCallback wrap; + JSPreWrapCallback preWrap; +}; + +typedef void +(* JSDestroyCompartmentCallback)(JSFreeOp *fop, JSCompartment *compartment); + +typedef void +(* JSZoneCallback)(JS::Zone *zone); + +typedef void +(* JSCompartmentNameCallback)(JSRuntime *rt, JSCompartment *compartment, + char *buf, size_t bufsize); + +/************************************************************************/ + +static MOZ_ALWAYS_INLINE jsval +JS_NumberValue(double d) +{ + int32_t i; + d = JS::CanonicalizeNaN(d); + if (mozilla::NumberIsInt32(d, &i)) + return INT_TO_JSVAL(i); + return DOUBLE_TO_JSVAL(d); +} + +/************************************************************************/ + +JS_PUBLIC_API(bool) +JS_StringHasBeenInterned(JSContext *cx, JSString *str); + +/* + * Only JSStrings that have been interned via the JSAPI can be turned into + * jsids by API clients. + * + * N.B. if a jsid is backed by a string which has not been interned, that + * string must be appropriately rooted to avoid being collected by the GC. + */ +JS_PUBLIC_API(jsid) +INTERNED_STRING_TO_JSID(JSContext *cx, JSString *str); + +namespace JS { + +// Container class for passing in script source buffers to the JS engine. This +// not only groups the buffer and length values, it also provides a way to +// optionally pass ownership of the buffer to the JS engine without copying. +// Rules for use: +// +// 1) The data array must be allocated with js_malloc() or js_realloc() if +// ownership is being granted to the SourceBufferHolder. +// 2) If ownership is not given to the SourceBufferHolder, then the memory +// must be kept alive until the JS compilation is complete. +// 3) Any code calling SourceBufferHolder::take() must guarantee to keep the +// memory alive until JS compilation completes. Normally only the JS +// engine should be calling take(). +// +// Example use: +// +// size_t length = 512; +// jschar* chars = static_cast(js_malloc(sizeof(jschar) * length)); +// JS::SourceBufferHolder srcBuf(chars, length, JS::SourceBufferHolder::GiveOwnership); +// JS::Compile(cx, obj, options, srcBuf); +// +class MOZ_STACK_CLASS SourceBufferHolder MOZ_FINAL +{ + public: + enum Ownership { + NoOwnership, + GiveOwnership + }; + + SourceBufferHolder(const jschar *data, size_t dataLength, Ownership ownership) + : data_(data), + length_(dataLength), + ownsChars_(ownership == GiveOwnership) + { + // Ensure that null buffers properly return an unowned, empty, + // null-terminated string. + static const jschar NullChar_ = 0; + if (!get()) { + data_ = &NullChar_; + length_ = 0; + ownsChars_ = false; + } + } + + ~SourceBufferHolder() { + if (ownsChars_) + js_free(const_cast(data_)); + } + + // Access the underlying source buffer without affecting ownership. + const jschar *get() const { return data_; } + + // Length of the source buffer in jschars (not bytes) + size_t length() const { return length_; } + + // Returns true if the SourceBufferHolder owns the buffer and will free + // it upon destruction. If true, it is legal to call take(). + bool ownsChars() const { return ownsChars_; } + + // Retrieve and take ownership of the underlying data buffer. The caller + // is now responsible for calling js_free() on the returned value, *but only + // after JS script compilation has completed*. + // + // After the buffer has been taken the SourceBufferHolder functions as if + // it had been constructed on an unowned buffer; get() and length() still + // work. In order for this to be safe the taken buffer must be kept alive + // until after JS script compilation completes as noted above. + // + // Note, it's the caller's responsibility to check ownsChars() before taking + // the buffer. Taking and then free'ing an unowned buffer will have dire + // consequences. + jschar *take() { + JS_ASSERT(ownsChars_); + ownsChars_ = false; + return const_cast(data_); + } + + private: + SourceBufferHolder(SourceBufferHolder &) MOZ_DELETE; + SourceBufferHolder &operator=(SourceBufferHolder &) MOZ_DELETE; + + const jschar *data_; + size_t length_; + bool ownsChars_; +}; + +} /* namespace JS */ + +/************************************************************************/ + +/* Property attributes, set in JSPropertySpec and passed to API functions. */ +#define JSPROP_ENUMERATE 0x01 /* property is visible to for/in loop */ +#define JSPROP_READONLY 0x02 /* not settable: assignment is no-op. + This flag is only valid when neither + JSPROP_GETTER nor JSPROP_SETTER is + set. */ +#define JSPROP_PERMANENT 0x04 /* property cannot be deleted */ +#define JSPROP_NATIVE_ACCESSORS 0x08 /* set in JSPropertyDescriptor.flags + if getters/setters are JSNatives */ +#define JSPROP_GETTER 0x10 /* property holds getter function */ +#define JSPROP_SETTER 0x20 /* property holds setter function */ +#define JSPROP_SHARED 0x40 /* don't allocate a value slot for this + property; don't copy the property on + set of the same-named property in an + object that delegates to a prototype + containing this property */ +#define JSPROP_INDEX 0x80 /* name is actually (int) index */ + +#define JSFUN_STUB_GSOPS 0x200 /* use JS_PropertyStub getter/setter + instead of defaulting to class gsops + for property holding function */ + +#define JSFUN_CONSTRUCTOR 0x400 /* native that can be called as a ctor */ + + +/* + * Specify a generic native prototype methods, i.e., methods of a class + * prototype that are exposed as static methods taking an extra leading + * argument: the generic |this| parameter. + * + * If you set this flag in a JSFunctionSpec struct's flags initializer, then + * that struct must live at least as long as the native static method object + * created due to this flag by JS_DefineFunctions or JS_InitClass. Typically + * JSFunctionSpec structs are allocated in static arrays. + */ +#define JSFUN_GENERIC_NATIVE 0x800 + +#define JSFUN_FLAGS_MASK 0xe00 /* | of all the JSFUN_* flags */ + +/* + * The first call to JS_CallOnce by any thread in a process will call 'func'. + * Later calls to JS_CallOnce with the same JSCallOnceType object will be + * suppressed. + * + * Equivalently: each distinct JSCallOnceType object will allow one JS_CallOnce + * to invoke its JSInitCallback. + */ +extern JS_PUBLIC_API(bool) +JS_CallOnce(JSCallOnceType *once, JSInitCallback func); + +/* Microseconds since the epoch, midnight, January 1, 1970 UTC. */ +extern JS_PUBLIC_API(int64_t) +JS_Now(void); + +/* Don't want to export data, so provide accessors for non-inline jsvals. */ +extern JS_PUBLIC_API(jsval) +JS_GetNaNValue(JSContext *cx); + +extern JS_PUBLIC_API(jsval) +JS_GetNegativeInfinityValue(JSContext *cx); + +extern JS_PUBLIC_API(jsval) +JS_GetPositiveInfinityValue(JSContext *cx); + +extern JS_PUBLIC_API(jsval) +JS_GetEmptyStringValue(JSContext *cx); + +extern JS_PUBLIC_API(JSString *) +JS_GetEmptyString(JSRuntime *rt); + +/* + * Format is a string of the following characters (spaces are insignificant), + * specifying the tabulated type conversions: + * + * b bool Boolean + * c uint16_t/jschar ECMA uint16_t, Unicode char + * i int32_t ECMA int32_t + * j int32_t ECMA int32_t (used to be different) + * u uint32_t ECMA uint32_t + * d double IEEE double + * I double Integral IEEE double + * S JSString * Unicode string, accessed by a JSString pointer + * W jschar * Unicode character vector, 0-terminated (W for wide) + * o JSObject * Object reference + * f JSFunction * Function private + * v jsval Argument value (no conversion) + * * N/A Skip this argument (no vararg) + * / N/A End of required arguments + * + * The variable argument list after format must consist of &b, &c, &s, e.g., + * where those variables have the types given above. For the pointer types + * char *, JSString *, and JSObject *, the pointed-at memory returned belongs + * to the JS runtime, not to the calling native code. The runtime promises + * to keep this memory valid so long as argv refers to allocated stack space + * (so long as the native function is active). + * + * Fewer arguments than format specifies may be passed only if there is a / + * in format after the last required argument specifier and argc is at least + * the number of required arguments. More arguments than format specifies + * may be passed without error; it is up to the caller to deal with trailing + * unconverted arguments. + */ +extern JS_PUBLIC_API(bool) +JS_ConvertArguments(JSContext *cx, const JS::CallArgs &args, const char *format, ...); + +#ifdef va_start +extern JS_PUBLIC_API(bool) +JS_ConvertArgumentsVA(JSContext *cx, const JS::CallArgs &args, const char *format, + va_list ap); +#endif + +extern JS_PUBLIC_API(bool) +JS_ConvertValue(JSContext *cx, JS::HandleValue v, JSType type, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ValueToObject(JSContext *cx, JS::HandleValue v, JS::MutableHandleObject objp); + +extern JS_PUBLIC_API(JSFunction *) +JS_ValueToFunction(JSContext *cx, JS::HandleValue v); + +extern JS_PUBLIC_API(JSFunction *) +JS_ValueToConstructor(JSContext *cx, JS::HandleValue v); + +extern JS_PUBLIC_API(JSString *) +JS_ValueToSource(JSContext *cx, JS::Handle v); + +namespace js { +/* + * DO NOT CALL THIS. Use JS::ToNumber + */ +extern JS_PUBLIC_API(bool) +ToNumberSlow(JSContext *cx, JS::Value v, double *dp); + +/* + * DO NOT CALL THIS. Use JS::ToBoolean + */ +extern JS_PUBLIC_API(bool) +ToBooleanSlow(JS::HandleValue v); + +/* + * DO NOT CALL THIS. Use JS::ToString + */ +extern JS_PUBLIC_API(JSString*) +ToStringSlow(JSContext *cx, JS::HandleValue v); +} /* namespace js */ + +namespace JS { + +/* ES5 9.3 ToNumber. */ +MOZ_ALWAYS_INLINE bool +ToNumber(JSContext *cx, HandleValue v, double *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isNumber()) { + *out = v.toNumber(); + return true; + } + return js::ToNumberSlow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToBoolean(HandleValue v) +{ + if (v.isBoolean()) + return v.toBoolean(); + if (v.isInt32()) + return v.toInt32() != 0; + if (v.isNullOrUndefined()) + return false; + if (v.isDouble()) { + double d = v.toDouble(); + return !mozilla::IsNaN(d) && d != 0; + } + if (v.isSymbol()) + return true; + + /* The slow path handles strings and objects. */ + return js::ToBooleanSlow(v); +} + +MOZ_ALWAYS_INLINE JSString* +ToString(JSContext *cx, HandleValue v) +{ + if (v.isString()) + return v.toString(); + return js::ToStringSlow(cx, v); +} + +} /* namespace JS */ + +extern JS_PUBLIC_API(bool) +JS_DoubleIsInt32(double d, int32_t *ip); + +extern JS_PUBLIC_API(int32_t) +JS_DoubleToInt32(double d); + +extern JS_PUBLIC_API(uint32_t) +JS_DoubleToUint32(double d); + + +namespace js { +/* DO NOT CALL THIS. Use JS::ToUint16. */ +extern JS_PUBLIC_API(bool) +ToUint16Slow(JSContext *cx, JS::HandleValue v, uint16_t *out); + +/* DO NOT CALL THIS. Use JS::ToInt32. */ +extern JS_PUBLIC_API(bool) +ToInt32Slow(JSContext *cx, JS::HandleValue v, int32_t *out); + +/* DO NOT CALL THIS. Use JS::ToUint32. */ +extern JS_PUBLIC_API(bool) +ToUint32Slow(JSContext *cx, JS::HandleValue v, uint32_t *out); + +/* DO NOT CALL THIS. Use JS::ToInt64. */ +extern JS_PUBLIC_API(bool) +ToInt64Slow(JSContext *cx, JS::HandleValue v, int64_t *out); + +/* DO NOT CALL THIS. Use JS::ToUint64. */ +extern JS_PUBLIC_API(bool) +ToUint64Slow(JSContext *cx, JS::HandleValue v, uint64_t *out); +} /* namespace js */ + +namespace JS { + +MOZ_ALWAYS_INLINE bool +ToUint16(JSContext *cx, JS::HandleValue v, uint16_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + *out = uint16_t(v.toInt32()); + return true; + } + return js::ToUint16Slow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToInt32(JSContext *cx, JS::HandleValue v, int32_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + *out = v.toInt32(); + return true; + } + return js::ToInt32Slow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToUint32(JSContext *cx, JS::HandleValue v, uint32_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + *out = uint32_t(v.toInt32()); + return true; + } + return js::ToUint32Slow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToInt64(JSContext *cx, JS::HandleValue v, int64_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + *out = int64_t(v.toInt32()); + return true; + } + return js::ToInt64Slow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToUint64(JSContext *cx, JS::HandleValue v, uint64_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + /* Account for sign extension of negatives into the longer 64bit space. */ + *out = uint64_t(int64_t(v.toInt32())); + return true; + } + return js::ToUint64Slow(cx, v, out); +} + + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSType) +JS_TypeOfValue(JSContext *cx, JS::Handle v); + +extern JS_PUBLIC_API(const char *) +JS_GetTypeName(JSContext *cx, JSType type); + +extern JS_PUBLIC_API(bool) +JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal); + +extern JS_PUBLIC_API(bool) +JS_LooselyEqual(JSContext *cx, JS::Handle v1, JS::Handle v2, bool *equal); + +extern JS_PUBLIC_API(bool) +JS_SameValue(JSContext *cx, jsval v1, jsval v2, bool *same); + +/* True iff fun is the global eval function. */ +extern JS_PUBLIC_API(bool) +JS_IsBuiltinEvalFunction(JSFunction *fun); + +/* True iff fun is the Function constructor. */ +extern JS_PUBLIC_API(bool) +JS_IsBuiltinFunctionConstructor(JSFunction *fun); + +/************************************************************************/ + +/* + * Initialization, locking, contexts, and memory allocation. + * + * It is important that the first runtime and first context be created in a + * single-threaded fashion, otherwise the behavior of the library is undefined. + * See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference + */ + +/** + * Initialize SpiderMonkey, returning true only if initialization succeeded. + * Once this method has succeeded, it is safe to call JS_NewRuntime and other + * JSAPI methods. + * + * This method must be called before any other JSAPI method is used on any + * thread. Once it has been used, it is safe to call any JSAPI method, and it + * remains safe to do so until JS_ShutDown is correctly called. + * + * It is currently not possible to initialize SpiderMonkey multiple times (that + * is, calling JS_Init/JSAPI methods/JS_ShutDown in that order, then doing so + * again). This restriction may eventually be lifted. + */ +extern JS_PUBLIC_API(bool) +JS_Init(void); + +/** + * Destroy free-standing resources allocated by SpiderMonkey, not associated + * with any runtime, context, or other structure. + * + * This method should be called after all other JSAPI data has been properly + * cleaned up: every new runtime must have been destroyed, every new context + * must have been destroyed, and so on. Calling this method before all other + * resources have been destroyed has undefined behavior. + * + * Failure to call this method, at present, has no adverse effects other than + * leaking memory. This may not always be the case; it's recommended that all + * embedders call this method when all other JSAPI operations have completed. + * + * It is currently not possible to initialize SpiderMonkey multiple times (that + * is, calling JS_Init/JSAPI methods/JS_ShutDown in that order, then doing so + * again). This restriction may eventually be lifted. + */ +extern JS_PUBLIC_API(void) +JS_ShutDown(void); + +extern JS_PUBLIC_API(JSRuntime *) +JS_NewRuntime(uint32_t maxbytes, + uint32_t maxNurseryBytes = JS::DefaultNurseryBytes, + JSRuntime *parentRuntime = nullptr); + +extern JS_PUBLIC_API(void) +JS_DestroyRuntime(JSRuntime *rt); + +// These are equivalent to ICU's |UMemAllocFn|, |UMemReallocFn|, and +// |UMemFreeFn| types. The first argument (called |context| in the ICU docs) +// will always be nullptr, and should be ignored. +typedef void *(*JS_ICUAllocFn)(const void *, size_t size); +typedef void *(*JS_ICUReallocFn)(const void *, void *p, size_t size); +typedef void (*JS_ICUFreeFn)(const void *, void *p); + +// This function can be used to track memory used by ICU. +// Do not use it unless you know what you are doing! +extern JS_PUBLIC_API(bool) +JS_SetICUMemoryFunctions(JS_ICUAllocFn allocFn, JS_ICUReallocFn reallocFn, JS_ICUFreeFn freeFn); + +JS_PUBLIC_API(void *) +JS_GetRuntimePrivate(JSRuntime *rt); + +extern JS_PUBLIC_API(JSRuntime *) +JS_GetRuntime(JSContext *cx); + +extern JS_PUBLIC_API(JSRuntime *) +JS_GetParentRuntime(JSContext *cx); + +JS_PUBLIC_API(void) +JS_SetRuntimePrivate(JSRuntime *rt, void *data); + +extern JS_PUBLIC_API(void) +JS_BeginRequest(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_EndRequest(JSContext *cx); + +extern JS_PUBLIC_API(bool) +JS_IsInRequest(JSRuntime *rt); + +namespace js { + +void +AssertHeapIsIdle(JSRuntime *rt); + +void +AssertHeapIsIdle(JSContext *cx); + +} /* namespace js */ + +class JSAutoRequest +{ + public: + explicit JSAutoRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mContext(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + JS_BeginRequest(mContext); + } + ~JSAutoRequest() { + JS_EndRequest(mContext); + } + + protected: + JSContext *mContext; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + +#if 0 + private: + static void *operator new(size_t) CPP_THROW_NEW { return 0; }; + static void operator delete(void *, size_t) { }; +#endif +}; + +class JSAutoCheckRequest +{ + public: + explicit JSAutoCheckRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + { +#if defined JS_THREADSAFE && defined JS_DEBUG + mContext = cx; + JS_ASSERT(JS_IsInRequest(JS_GetRuntime(cx))); +#endif + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + ~JSAutoCheckRequest() { +#if defined JS_THREADSAFE && defined JS_DEBUG + JS_ASSERT(JS_IsInRequest(JS_GetRuntime(mContext))); +#endif + } + + + private: +#if defined JS_THREADSAFE && defined JS_DEBUG + JSContext *mContext; +#endif + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +extern JS_PUBLIC_API(void) +JS_SetContextCallback(JSRuntime *rt, JSContextCallback cxCallback, void *data); + +extern JS_PUBLIC_API(JSContext *) +JS_NewContext(JSRuntime *rt, size_t stackChunkSize); + +extern JS_PUBLIC_API(void) +JS_DestroyContext(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_DestroyContextNoGC(JSContext *cx); + +extern JS_PUBLIC_API(void *) +JS_GetContextPrivate(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_SetContextPrivate(JSContext *cx, void *data); + +extern JS_PUBLIC_API(void *) +JS_GetSecondContextPrivate(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_SetSecondContextPrivate(JSContext *cx, void *data); + +extern JS_PUBLIC_API(JSRuntime *) +JS_GetRuntime(JSContext *cx); + +extern JS_PUBLIC_API(JSContext *) +JS_ContextIterator(JSRuntime *rt, JSContext **iterp); + +extern JS_PUBLIC_API(JSVersion) +JS_GetVersion(JSContext *cx); + +// Mutate the version on the compartment. This is generally discouraged, but +// necessary to support the version mutation in the js and xpc shell command +// set. +// +// It would be nice to put this in jsfriendapi, but the linkage requirements +// of the shells make that impossible. +JS_PUBLIC_API(void) +JS_SetVersionForCompartment(JSCompartment *compartment, JSVersion version); + +extern JS_PUBLIC_API(const char *) +JS_VersionToString(JSVersion version); + +extern JS_PUBLIC_API(JSVersion) +JS_StringToVersion(const char *string); + +namespace JS { + +class JS_PUBLIC_API(RuntimeOptions) { + public: + RuntimeOptions() + : baseline_(false), + ion_(false), + asmJS_(false), + nativeRegExp_(false), + werror_(false), + strictMode_(false), + varObjFix_(false) + { + } + + bool baseline() const { return baseline_; } + RuntimeOptions &setBaseline(bool flag) { + baseline_ = flag; + return *this; + } + RuntimeOptions &toggleBaseline() { + baseline_ = !baseline_; + return *this; + } + + bool ion() const { return ion_; } + RuntimeOptions &setIon(bool flag) { + ion_ = flag; + return *this; + } + RuntimeOptions &toggleIon() { + ion_ = !ion_; + return *this; + } + + bool asmJS() const { return asmJS_; } + RuntimeOptions &setAsmJS(bool flag) { + asmJS_ = flag; + return *this; + } + RuntimeOptions &toggleAsmJS() { + asmJS_ = !asmJS_; + return *this; + } + + bool nativeRegExp() const { return nativeRegExp_; } + RuntimeOptions &setNativeRegExp(bool flag) { + nativeRegExp_ = flag; + return *this; + } + + bool werror() const { return werror_; } + RuntimeOptions &setWerror(bool flag) { + werror_ = flag; + return *this; + } + RuntimeOptions &toggleWerror() { + werror_ = !werror_; + return *this; + } + + bool strictMode() const { return strictMode_; } + RuntimeOptions &setStrictMode(bool flag) { + strictMode_ = flag; + return *this; + } + RuntimeOptions &toggleStrictMode() { + strictMode_ = !strictMode_; + return *this; + } + + bool varObjFix() const { return varObjFix_; } + RuntimeOptions &setVarObjFix(bool flag) { + varObjFix_ = flag; + return *this; + } + RuntimeOptions &toggleVarObjFix() { + varObjFix_ = !varObjFix_; + return *this; + } + + private: + bool baseline_ : 1; + bool ion_ : 1; + bool asmJS_ : 1; + bool nativeRegExp_ : 1; + bool werror_ : 1; + bool strictMode_ : 1; + bool varObjFix_ : 1; +}; + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSRuntime *rt); + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSContext *cx); + +class JS_PUBLIC_API(ContextOptions) { + public: + ContextOptions() + : extraWarnings_(false), + privateIsNSISupports_(false), + dontReportUncaught_(false), + noDefaultCompartmentObject_(false), + noScriptRval_(false) + { + } + + bool extraWarnings() const { return extraWarnings_; } + ContextOptions &setExtraWarnings(bool flag) { + extraWarnings_ = flag; + return *this; + } + ContextOptions &toggleExtraWarnings() { + extraWarnings_ = !extraWarnings_; + return *this; + } + + bool privateIsNSISupports() const { return privateIsNSISupports_; } + ContextOptions &setPrivateIsNSISupports(bool flag) { + privateIsNSISupports_ = flag; + return *this; + } + ContextOptions &togglePrivateIsNSISupports() { + privateIsNSISupports_ = !privateIsNSISupports_; + return *this; + } + + bool dontReportUncaught() const { return dontReportUncaught_; } + ContextOptions &setDontReportUncaught(bool flag) { + dontReportUncaught_ = flag; + return *this; + } + ContextOptions &toggleDontReportUncaught() { + dontReportUncaught_ = !dontReportUncaught_; + return *this; + } + + bool noDefaultCompartmentObject() const { return noDefaultCompartmentObject_; } + ContextOptions &setNoDefaultCompartmentObject(bool flag) { + noDefaultCompartmentObject_ = flag; + return *this; + } + ContextOptions &toggleNoDefaultCompartmentObject() { + noDefaultCompartmentObject_ = !noDefaultCompartmentObject_; + return *this; + } + + bool noScriptRval() const { return noScriptRval_; } + ContextOptions &setNoScriptRval(bool flag) { + noScriptRval_ = flag; + return *this; + } + ContextOptions &toggleNoScriptRval() { + noScriptRval_ = !noScriptRval_; + return *this; + } + + private: + bool extraWarnings_ : 1; + bool privateIsNSISupports_ : 1; + bool dontReportUncaught_ : 1; + bool noDefaultCompartmentObject_ : 1; + bool noScriptRval_ : 1; +}; + +JS_PUBLIC_API(ContextOptions &) +ContextOptionsRef(JSContext *cx); + +class JS_PUBLIC_API(AutoSaveContextOptions) { + public: + explicit AutoSaveContextOptions(JSContext *cx) + : cx_(cx), + oldOptions_(ContextOptionsRef(cx_)) + { + } + + ~AutoSaveContextOptions() + { + ContextOptionsRef(cx_) = oldOptions_; + } + + private: + JSContext *cx_; + JS::ContextOptions oldOptions_; +}; + +} /* namespace JS */ + +extern JS_PUBLIC_API(const char *) +JS_GetImplementationVersion(void); + +extern JS_PUBLIC_API(void) +JS_SetDestroyCompartmentCallback(JSRuntime *rt, JSDestroyCompartmentCallback callback); + +extern JS_PUBLIC_API(void) +JS_SetDestroyZoneCallback(JSRuntime *rt, JSZoneCallback callback); + +extern JS_PUBLIC_API(void) +JS_SetSweepZoneCallback(JSRuntime *rt, JSZoneCallback callback); + +extern JS_PUBLIC_API(void) +JS_SetCompartmentNameCallback(JSRuntime *rt, JSCompartmentNameCallback callback); + +extern JS_PUBLIC_API(void) +JS_SetWrapObjectCallbacks(JSRuntime *rt, const JSWrapObjectCallbacks *callbacks); + +extern JS_PUBLIC_API(void) +JS_SetCompartmentPrivate(JSCompartment *compartment, void *data); + +extern JS_PUBLIC_API(void *) +JS_GetCompartmentPrivate(JSCompartment *compartment); + +extern JS_PUBLIC_API(void) +JS_SetZoneUserData(JS::Zone *zone, void *data); + +extern JS_PUBLIC_API(void *) +JS_GetZoneUserData(JS::Zone *zone); + +extern JS_PUBLIC_API(bool) +JS_WrapObject(JSContext *cx, JS::MutableHandleObject objp); + +extern JS_PUBLIC_API(bool) +JS_WrapValue(JSContext *cx, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(JSObject *) +JS_TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target); + +extern JS_PUBLIC_API(bool) +JS_RefreshCrossCompartmentWrappers(JSContext *cx, JS::Handle obj); + +/* + * At any time, a JSContext has a current (possibly-nullptr) compartment. + * Compartments are described in: + * + * developer.mozilla.org/en-US/docs/SpiderMonkey/SpiderMonkey_compartments + * + * The current compartment of a context may be changed. The preferred way to do + * this is with JSAutoCompartment: + * + * void foo(JSContext *cx, JSObject *obj) { + * // in some compartment 'c' + * { + * JSAutoCompartment ac(cx, obj); // constructor enters + * // in the compartment of 'obj' + * } // destructor leaves + * // back in compartment 'c' + * } + * + * For more complicated uses that don't neatly fit in a C++ stack frame, the + * compartment can entered and left using separate function calls: + * + * void foo(JSContext *cx, JSObject *obj) { + * // in 'oldCompartment' + * JSCompartment *oldCompartment = JS_EnterCompartment(cx, obj); + * // in the compartment of 'obj' + * JS_LeaveCompartment(cx, oldCompartment); + * // back in 'oldCompartment' + * } + * + * Note: these calls must still execute in a LIFO manner w.r.t all other + * enter/leave calls on the context. Furthermore, only the return value of a + * JS_EnterCompartment call may be passed as the 'oldCompartment' argument of + * the corresponding JS_LeaveCompartment call. + */ + +class JS_PUBLIC_API(JSAutoCompartment) +{ + JSContext *cx_; + JSCompartment *oldCompartment_; + public: + JSAutoCompartment(JSContext *cx, JSObject *target); + JSAutoCompartment(JSContext *cx, JSScript *target); + ~JSAutoCompartment(); +}; + +class JS_PUBLIC_API(JSAutoNullableCompartment) +{ + JSContext *cx_; + JSCompartment *oldCompartment_; + public: + explicit JSAutoNullableCompartment(JSContext *cx, JSObject *targetOrNull); + ~JSAutoNullableCompartment(); +}; + +/* NB: This API is infallible; a nullptr return value does not indicate error. */ +extern JS_PUBLIC_API(JSCompartment *) +JS_EnterCompartment(JSContext *cx, JSObject *target); + +extern JS_PUBLIC_API(void) +JS_LeaveCompartment(JSContext *cx, JSCompartment *oldCompartment); + +typedef void (*JSIterateCompartmentCallback)(JSRuntime *rt, void *data, JSCompartment *compartment); + +/* + * This function calls |compartmentCallback| on every compartment. Beware that + * there is no guarantee that the compartment will survive after the callback + * returns. + */ +extern JS_PUBLIC_API(void) +JS_IterateCompartments(JSRuntime *rt, void *data, + JSIterateCompartmentCallback compartmentCallback); + +/* + * Initialize standard JS class constructors, prototypes, and any top-level + * functions and constants associated with the standard classes (e.g. isNaN + * for Number). + * + * NB: This sets cx's global object to obj if it was null. + */ +extern JS_PUBLIC_API(bool) +JS_InitStandardClasses(JSContext *cx, JS::Handle obj); + +/* + * Resolve id, which must contain either a string or an int, to a standard + * class name in obj if possible, defining the class's constructor and/or + * prototype and storing true in *resolved. If id does not name a standard + * class or a top-level property induced by initializing a standard class, + * store false in *resolved and just return true. Return false on error, + * as usual for bool result-typed API entry points. + * + * This API can be called directly from a global object class's resolve op, + * to define standard classes lazily. The class's enumerate op should call + * JS_EnumerateStandardClasses(cx, obj), to define eagerly during for..in + * loops any classes not yet resolved lazily. + */ +extern JS_PUBLIC_API(bool) +JS_ResolveStandardClass(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *resolved); + +extern JS_PUBLIC_API(bool) +JS_EnumerateStandardClasses(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(bool) +JS_GetClassObject(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); + +extern JS_PUBLIC_API(bool) +JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); + +namespace JS { + +/* + * Determine if the given object is an instance/prototype/constructor for a standard + * class. If so, return the associated JSProtoKey. If not, return JSProto_Null. + */ + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstance(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstanceOrPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardConstructor(JSObject *obj); + +extern JS_PUBLIC_API(void) +ProtoKeyToId(JSContext *cx, JSProtoKey key, JS::MutableHandleId idp); + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSProtoKey) +JS_IdToProtoKey(JSContext *cx, JS::HandleId id); + +/* + * Returns the original value of |Function.prototype| from the global object in + * which |forObj| was created. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetFunctionPrototype(JSContext *cx, JS::HandleObject forObj); + +/* + * Returns the original value of |Object.prototype| from the global object in + * which |forObj| was created. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetObjectPrototype(JSContext *cx, JS::HandleObject forObj); + +/* + * Returns the original value of |Array.prototype| from the global object in + * which |forObj| was created. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetArrayPrototype(JSContext *cx, JS::HandleObject forObj); + +/* + * Returns the original value of |Error.prototype| from the global + * object of the current compartment of cx. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetErrorPrototype(JSContext *cx); + +extern JS_PUBLIC_API(JSObject *) +JS_GetGlobalForObject(JSContext *cx, JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_IsGlobalObject(JSObject *obj); + +/* + * May return nullptr, if |c| never had a global (e.g. the atoms compartment), + * or if |c|'s global has been collected. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetGlobalForCompartmentOrNull(JSContext *cx, JSCompartment *c); + +namespace JS { + +extern JS_PUBLIC_API(JSObject *) +CurrentGlobalOrNull(JSContext *cx); + +} + +/* + * Initialize the 'Reflect' object on a global object. + */ +extern JS_PUBLIC_API(JSObject *) +JS_InitReflect(JSContext *cx, JS::HandleObject global); + +#ifdef JS_HAS_CTYPES +/* + * Initialize the 'ctypes' object on a global variable 'obj'. The 'ctypes' + * object will be sealed. + */ +extern JS_PUBLIC_API(bool) +JS_InitCTypesClass(JSContext *cx, JS::HandleObject global); + +/* + * Convert a unicode string 'source' of length 'slen' to the platform native + * charset, returning a null-terminated string allocated with JS_malloc. On + * failure, this function should report an error. + */ +typedef char * +(* JSCTypesUnicodeToNativeFun)(JSContext *cx, const jschar *source, size_t slen); + +/* + * Set of function pointers that ctypes can use for various internal functions. + * See JS_SetCTypesCallbacks below. Providing nullptr for a function is safe, + * and will result in the applicable ctypes functionality not being available. + */ +struct JSCTypesCallbacks { + JSCTypesUnicodeToNativeFun unicodeToNative; +}; + +typedef struct JSCTypesCallbacks JSCTypesCallbacks; + +/* + * Set the callbacks on the provided 'ctypesObj' object. 'callbacks' should be a + * pointer to static data that exists for the lifetime of 'ctypesObj', but it + * may safely be altered after calling this function and without having + * to call this function again. + */ +extern JS_PUBLIC_API(void) +JS_SetCTypesCallbacks(JSObject *ctypesObj, JSCTypesCallbacks *callbacks); +#endif + +typedef bool +(* JSEnumerateDiagnosticMemoryCallback)(void *ptr, size_t length); + +/* + * Enumerate memory regions that contain diagnostic information + * intended to be included in crash report minidumps. + */ +extern JS_PUBLIC_API(void) +JS_EnumerateDiagnosticMemoryRegions(JSEnumerateDiagnosticMemoryCallback callback); + +extern JS_PUBLIC_API(void *) +JS_malloc(JSContext *cx, size_t nbytes); + +extern JS_PUBLIC_API(void *) +JS_realloc(JSContext *cx, void *p, size_t nbytes); + +/* + * A wrapper for js_free(p) that may delay js_free(p) invocation as a + * performance optimization. + * cx may be nullptr. + */ +extern JS_PUBLIC_API(void) +JS_free(JSContext *cx, void *p); + +/* + * A wrapper for js_free(p) that may delay js_free(p) invocation as a + * performance optimization as specified by the given JSFreeOp instance. + */ +extern JS_PUBLIC_API(void) +JS_freeop(JSFreeOp *fop, void *p); + +extern JS_PUBLIC_API(JSFreeOp *) +JS_GetDefaultFreeOp(JSRuntime *rt); + +extern JS_PUBLIC_API(void) +JS_updateMallocCounter(JSContext *cx, size_t nbytes); + +extern JS_PUBLIC_API(char *) +JS_strdup(JSContext *cx, const char *s); + +/* Duplicate a string. Does not report an error on failure. */ +extern JS_PUBLIC_API(char *) +JS_strdup(JSRuntime *rt, const char *s); + +namespace JS { + +/* + * A GC root is a pointer to a jsval, JSObject * or JSString * that itself + * points into the GC heap. JS_AddValueRoot takes a pointer to a jsval and + * JS_AddGCThingRoot takes a pointer to a JSObject * or JString *. + * + * Note that, since JS_Add*Root stores the address of a variable (of type + * jsval, JSString *, or JSObject *), that variable must live until + * JS_Remove*Root is called to remove that variable. For example, after: + * + * void some_function() { + * jsval v; + * JS_AddNamedValueRoot(cx, &v, "name"); + * + * the caller must perform + * + * JS_RemoveValueRoot(cx, &v); + * + * before some_function() returns. + * + * Also, use JS_AddNamed*Root(cx, &structPtr->memberObj, "structPtr->memberObj") + * in preference to JS_Add*Root(cx, &structPtr->memberObj), in order to identify + * roots by their source callsites. This way, you can find the callsite while + * debugging if you should fail to do JS_Remove*Root(cx, &structPtr->memberObj) + * before freeing structPtr's memory. + */ +extern JS_PUBLIC_API(bool) +AddValueRoot(JSContext *cx, JS::Heap *vp); + +extern JS_PUBLIC_API(bool) +AddStringRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(bool) +AddObjectRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(bool) +AddNamedValueRoot(JSContext *cx, JS::Heap *vp, const char *name); + +extern JS_PUBLIC_API(bool) +AddNamedValueRootRT(JSRuntime *rt, JS::Heap *vp, const char *name); + +extern JS_PUBLIC_API(bool) +AddNamedStringRoot(JSContext *cx, JS::Heap *rp, const char *name); + +extern JS_PUBLIC_API(bool) +AddNamedObjectRoot(JSContext *cx, JS::Heap *rp, const char *name); + +extern JS_PUBLIC_API(bool) +AddNamedScriptRoot(JSContext *cx, JS::Heap *rp, const char *name); + +extern JS_PUBLIC_API(void) +RemoveValueRoot(JSContext *cx, JS::Heap *vp); + +extern JS_PUBLIC_API(void) +RemoveStringRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveObjectRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveScriptRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveValueRootRT(JSRuntime *rt, JS::Heap *vp); + +extern JS_PUBLIC_API(void) +RemoveStringRootRT(JSRuntime *rt, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveObjectRootRT(JSRuntime *rt, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveScriptRootRT(JSRuntime *rt, JS::Heap *rp); + +} /* namespace JS */ + +/* + * Register externally maintained GC roots. + * + * traceOp: the trace operation. For each root the implementation should call + * JS_CallTracer whenever the root contains a traceable thing. + * data: the data argument to pass to each invocation of traceOp. + */ +extern JS_PUBLIC_API(bool) +JS_AddExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); + +/* Undo a call to JS_AddExtraGCRootsTracer. */ +extern JS_PUBLIC_API(void) +JS_RemoveExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); + +#ifdef JS_DEBUG + +/* + * Debug-only method to dump the object graph of heap-allocated things. + * + * fp: file for the dump output. + * start: when non-null, dump only things reachable from start + * thing. Otherwise dump all things reachable from the + * runtime roots. + * startKind: trace kind of start if start is not null. Must be + * JSTRACE_OBJECT when start is null. + * thingToFind: dump only paths in the object graph leading to thingToFind + * when non-null. + * maxDepth: the upper bound on the number of edges to descend from the + * graph roots. + * thingToIgnore: thing to ignore during the graph traversal when non-null. + */ +extern JS_PUBLIC_API(bool) +JS_DumpHeap(JSRuntime *rt, FILE *fp, void* startThing, JSGCTraceKind kind, + void *thingToFind, size_t maxDepth, void *thingToIgnore); + +#endif + +/* + * Garbage collector API. + */ +extern JS_PUBLIC_API(void) +JS_GC(JSRuntime *rt); + +extern JS_PUBLIC_API(void) +JS_MaybeGC(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_SetGCCallback(JSRuntime *rt, JSGCCallback cb, void *data); + +extern JS_PUBLIC_API(bool) +JS_AddFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb, void *data); + +extern JS_PUBLIC_API(void) +JS_RemoveFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); + +extern JS_PUBLIC_API(bool) +JS_IsGCMarkingTracer(JSTracer *trc); + +/* For assertions only. */ +#ifdef JS_DEBUG +extern JS_PUBLIC_API(bool) +JS_IsMarkingGray(JSTracer *trc); +#endif + +/* + * JS_IsAboutToBeFinalized checks if the given object is going to be finalized + * at the end of the current GC. When called outside of the context of a GC, + * this function will return false. Typically this function is used on weak + * references, where the reference should be nulled out or destroyed if the + * given object is about to be finalized. + * + * The argument to JS_IsAboutToBeFinalized is an in-out param: when the + * function returns false, the object being referenced is still alive, but the + * garbage collector might have moved it. In this case, the reference passed + * to JS_IsAboutToBeFinalized will be updated to the object's new location. + * Callers of this method are responsible for updating any state that is + * dependent on the object's address. For example, if the object's address is + * used as a key in a hashtable, then the object must be removed and + * re-inserted with the correct hash. + */ +extern JS_PUBLIC_API(bool) +JS_IsAboutToBeFinalized(JS::Heap *objp); + +extern JS_PUBLIC_API(bool) +JS_IsAboutToBeFinalizedUnbarriered(JSObject **objp); + +typedef enum JSGCParamKey { + /* Maximum nominal heap before last ditch GC. */ + JSGC_MAX_BYTES = 0, + + /* Number of JS_malloc bytes before last ditch GC. */ + JSGC_MAX_MALLOC_BYTES = 1, + + /* Amount of bytes allocated by the GC. */ + JSGC_BYTES = 3, + + /* Number of times when GC was invoked. */ + JSGC_NUMBER = 4, + + /* Max size of the code cache in bytes. */ + JSGC_MAX_CODE_CACHE_BYTES = 5, + + /* Select GC mode. */ + JSGC_MODE = 6, + + /* Number of cached empty GC chunks. */ + JSGC_UNUSED_CHUNKS = 7, + + /* Total number of allocated GC chunks. */ + JSGC_TOTAL_CHUNKS = 8, + + /* Max milliseconds to spend in an incremental GC slice. */ + JSGC_SLICE_TIME_BUDGET = 9, + + /* Maximum size the GC mark stack can grow to. */ + JSGC_MARK_STACK_LIMIT = 10, + + /* + * GCs less than this far apart in time will be considered 'high-frequency GCs'. + * See setGCLastBytes in jsgc.cpp. + */ + JSGC_HIGH_FREQUENCY_TIME_LIMIT = 11, + + /* Start of dynamic heap growth. */ + JSGC_HIGH_FREQUENCY_LOW_LIMIT = 12, + + /* End of dynamic heap growth. */ + JSGC_HIGH_FREQUENCY_HIGH_LIMIT = 13, + + /* Upper bound of heap growth. */ + JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX = 14, + + /* Lower bound of heap growth. */ + JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN = 15, + + /* Heap growth for low frequency GCs. */ + JSGC_LOW_FREQUENCY_HEAP_GROWTH = 16, + + /* + * If false, the heap growth factor is fixed at 3. If true, it is determined + * based on whether GCs are high- or low- frequency. + */ + JSGC_DYNAMIC_HEAP_GROWTH = 17, + + /* If true, high-frequency GCs will use a longer mark slice. */ + JSGC_DYNAMIC_MARK_SLICE = 18, + + /* Lower limit after which we limit the heap growth. */ + JSGC_ALLOCATION_THRESHOLD = 19, + + /* + * We decommit memory lazily. If more than this number of megabytes is + * available to be decommitted, then JS_MaybeGC will trigger a shrinking GC + * to decommit it. + */ + JSGC_DECOMMIT_THRESHOLD = 20, + + /* + * We try to keep at least this many unused chunks in the free chunk pool at + * all times, even after a shrinking GC. + */ + JSGC_MIN_EMPTY_CHUNK_COUNT = 21, + + /* We never keep more than this many unused chunks in the free chunk pool. */ + JSGC_MAX_EMPTY_CHUNK_COUNT = 22 +} JSGCParamKey; + +extern JS_PUBLIC_API(void) +JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32_t value); + +extern JS_PUBLIC_API(uint32_t) +JS_GetGCParameter(JSRuntime *rt, JSGCParamKey key); + +extern JS_PUBLIC_API(void) +JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32_t value); + +extern JS_PUBLIC_API(uint32_t) +JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key); + +extern JS_PUBLIC_API(void) +JS_SetGCParametersBasedOnAvailableMemory(JSRuntime *rt, uint32_t availMem); + +/* + * Create a new JSString whose chars member refers to external memory, i.e., + * memory requiring application-specific finalization. + */ +extern JS_PUBLIC_API(JSString *) +JS_NewExternalString(JSContext *cx, const jschar *chars, size_t length, + const JSStringFinalizer *fin); + +/* + * Return whether 'str' was created with JS_NewExternalString or + * JS_NewExternalStringWithClosure. + */ +extern JS_PUBLIC_API(bool) +JS_IsExternalString(JSString *str); + +/* + * Return the 'closure' arg passed to JS_NewExternalStringWithClosure or + * nullptr if the external string was created via JS_NewExternalString. + */ +extern JS_PUBLIC_API(const JSStringFinalizer *) +JS_GetExternalStringFinalizer(JSString *str); + +/* + * Set the size of the native stack that should not be exceed. To disable + * stack size checking pass 0. + * + * SpiderMonkey allows for a distinction between system code (such as GCs, which + * may incidentally be triggered by script but are not strictly performed on + * behalf of such script), trusted script (as determined by JS_SetTrustedPrincipals), + * and untrusted script. Each kind of code may have a different stack quota, + * allowing embedders to keep higher-priority machinery running in the face of + * scripted stack exhaustion by something else. + * + * The stack quotas for each kind of code should be monotonically descending, + * and may be specified with this function. If 0 is passed for a given kind + * of code, it defaults to the value of the next-highest-priority kind. + */ +extern JS_PUBLIC_API(void) +JS_SetNativeStackQuota(JSRuntime *cx, size_t systemCodeStackSize, + size_t trustedScriptStackSize = 0, + size_t untrustedScriptStackSize = 0); + +/************************************************************************/ + +extern JS_PUBLIC_API(int) +JS_IdArrayLength(JSContext *cx, JSIdArray *ida); + +extern JS_PUBLIC_API(jsid) +JS_IdArrayGet(JSContext *cx, JSIdArray *ida, unsigned index); + +extern JS_PUBLIC_API(void) +JS_DestroyIdArray(JSContext *cx, JSIdArray *ida); + +namespace JS { + +class AutoIdArray : private AutoGCRooter +{ + public: + AutoIdArray(JSContext *cx, JSIdArray *ida + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, IDARRAY), context(cx), idArray(ida) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + ~AutoIdArray() { + if (idArray) + JS_DestroyIdArray(context, idArray); + } + bool operator!() const { + return !idArray; + } + jsid operator[](size_t i) const { + JS_ASSERT(idArray); + return JS_IdArrayGet(context, idArray, unsigned(i)); + } + size_t length() const { + return JS_IdArrayLength(context, idArray); + } + + friend void AutoGCRooter::trace(JSTracer *trc); + + JSIdArray *steal() { + JSIdArray *copy = idArray; + idArray = nullptr; + return copy; + } + + protected: + inline void trace(JSTracer *trc); + + private: + JSContext *context; + JSIdArray *idArray; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + /* No copy or assignment semantics. */ + AutoIdArray(AutoIdArray &ida) MOZ_DELETE; + void operator=(AutoIdArray &ida) MOZ_DELETE; +}; + +} /* namespace JS */ + +extern JS_PUBLIC_API(bool) +JS_ValueToId(JSContext *cx, JS::HandleValue v, JS::MutableHandleId idp); + +extern JS_PUBLIC_API(bool) +JS_StringToId(JSContext *cx, JS::HandleString s, JS::MutableHandleId idp); + +extern JS_PUBLIC_API(bool) +JS_IdToValue(JSContext *cx, jsid id, JS::MutableHandle vp); + +/* + * Invoke the [[DefaultValue]] hook (see ES5 8.6.2) with the provided hint on + * the specified object, computing a primitive default value for the object. + * The hint must be JSTYPE_STRING, JSTYPE_NUMBER, or JSTYPE_VOID (no hint). On + * success the resulting value is stored in *vp. + */ +extern JS_PUBLIC_API(bool) +JS_DefaultValue(JSContext *cx, JS::Handle obj, JSType hint, + JS::MutableHandle vp); + +extern JS_PUBLIC_API(bool) +JS_PropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_StrictPropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_DeletePropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *succeeded); + +extern JS_PUBLIC_API(bool) +JS_EnumerateStub(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(bool) +JS_ResolveStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id); + +extern JS_PUBLIC_API(bool) +JS_ConvertStub(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); + +struct JSConstDoubleSpec { + double dval; + const char *name; + uint8_t flags; + uint8_t spare[3]; +}; + +struct JSJitInfo; + +/* + * Wrappers to replace {Strict,}PropertyOp for JSPropertySpecs. This will allow + * us to pass one JSJitInfo per function with the property spec, without + * additional field overhead. + */ +typedef struct JSStrictPropertyOpWrapper { + JSStrictPropertyOp op; + const JSJitInfo *info; +} JSStrictPropertyOpWrapper; + +typedef struct JSPropertyOpWrapper { + JSPropertyOp op; + const JSJitInfo *info; +} JSPropertyOpWrapper; + +/* + * Wrapper to do as above, but for JSNatives for JSFunctionSpecs. + */ +typedef struct JSNativeWrapper { + JSNative op; + const JSJitInfo *info; +} JSNativeWrapper; + +/* + * Macro static initializers which make it easy to pass no JSJitInfo as part of a + * JSPropertySpec or JSFunctionSpec. + */ +#define JSOP_WRAPPER(op) { {op, nullptr} } +#define JSOP_NULLWRAPPER JSOP_WRAPPER(nullptr) + +/* + * To define an array element rather than a named property member, cast the + * element's index to (const char *) and initialize name with it, and set the + * JSPROP_INDEX bit in flags. + */ +struct JSPropertySpec { + struct SelfHostedWrapper { + void *unused; + const char *funname; + }; + + const char *name; + uint8_t flags; + union { + JSPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } getter; + union { + JSStrictPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } setter; + +private: + void StaticAsserts() { + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSPropertyOpWrapper)); + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSStrictPropertyOpWrapper)); + JS_STATIC_ASSERT(offsetof(SelfHostedWrapper, funname) == + offsetof(JSPropertyOpWrapper, info)); + } +}; + +namespace JS { +namespace detail { + +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_NATIVE_TO only. */ +inline int CheckIsNative(JSNative native); + +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_STRING_TO only. */ +template +inline int +CheckIsCharacterLiteral(const char (&arr)[N]); + +} // namespace detail +} // namespace JS + +#define JS_CAST_NATIVE_TO(v, To) \ + (static_cast(sizeof(JS::detail::CheckIsNative(v))), \ + reinterpret_cast(v)) + +#define JS_CAST_STRING_TO(s, To) \ + (static_cast(sizeof(JS::detail::CheckIsCharacterLiteral(s))), \ + reinterpret_cast(s)) + +#define JS_CHECK_ACCESSOR_FLAGS(flags) \ + (static_cast::Type>(0), \ + (flags)) + +/* + * JSPropertySpec uses JSAPI JSPropertyOp and JSStrictPropertyOp in function + * signatures. These macros encapsulate the definition of JSNative-backed + * JSPropertySpecs, performing type-safe casts on the getter/setter functions + * and adding the necessary property flags to trigger interpretation as + * JSNatives. + */ +#define JS_PSG(name, getter, flags) \ + {name, \ + uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ + JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ + JSOP_NULLWRAPPER} +#define JS_PSGS(name, getter, setter, flags) \ + {name, \ + uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ + JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ + JSOP_WRAPPER(JS_CAST_NATIVE_TO(setter, JSStrictPropertyOp))} +#define JS_SELF_HOSTED_GET(name, getterName, flags) \ + {name, \ + uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER), \ + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + JSOP_NULLWRAPPER } +#define JS_SELF_HOSTED_GETSET(name, getterName, setterName, flags) \ + {name, \ + uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER | JSPROP_SETTER), \ + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + { nullptr, JS_CAST_STRING_TO(setterName, const JSJitInfo *) } } +#define JS_PS_END { nullptr, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER } + +/* + * To define a native function, set call to a JSNativeWrapper. To define a + * self-hosted function, set selfHostedName to the name of a function + * compiled during JSRuntime::initSelfHosting. + */ +struct JSFunctionSpec { + const char *name; + JSNativeWrapper call; + uint16_t nargs; + uint16_t flags; + const char *selfHostedName; +}; + +/* + * Terminating sentinel initializer to put at the end of a JSFunctionSpec array + * that's passed to JS_DefineFunctions or JS_InitClass. + */ +#define JS_FS_END JS_FS(nullptr,nullptr,0,0) + +/* + * Initializer macros for a JSFunctionSpec array element. JS_FN (whose name pays + * homage to the old JSNative/JSFastNative split) simply adds the flag + * JSFUN_STUB_GSOPS. JS_FNINFO allows the simple adding of + * JSJitInfos. JS_SELF_HOSTED_FN declares a self-hosted function. Finally + * JS_FNSPEC has slots for all the fields. + */ +#define JS_FS(name,call,nargs,flags) \ + JS_FNSPEC(name, call, nullptr, nargs, flags, nullptr) +#define JS_FN(name,call,nargs,flags) \ + JS_FNSPEC(name, call, nullptr, nargs, (flags) | JSFUN_STUB_GSOPS, nullptr) +#define JS_FNINFO(name,call,info,nargs,flags) \ + JS_FNSPEC(name, call, info, nargs, flags, nullptr) +#define JS_SELF_HOSTED_FN(name,selfHostedName,nargs,flags) \ + JS_FNSPEC(name, nullptr, nullptr, nargs, flags, selfHostedName) +#define JS_FNSPEC(name,call,info,nargs,flags,selfHostedName) \ + {name, {call, info}, nargs, flags, selfHostedName} + +extern JS_PUBLIC_API(JSObject *) +JS_InitClass(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent_proto, + const JSClass *clasp, JSNative constructor, unsigned nargs, + const JSPropertySpec *ps, const JSFunctionSpec *fs, + const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs); + +/* + * Set up ctor.prototype = proto and proto.constructor = ctor with the + * right property flags. + */ +extern JS_PUBLIC_API(bool) +JS_LinkConstructorAndPrototype(JSContext *cx, JS::Handle ctor, + JS::Handle proto); + +extern JS_PUBLIC_API(const JSClass *) +JS_GetClass(JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_InstanceOf(JSContext *cx, JS::Handle obj, const JSClass *clasp, JS::CallArgs *args); + +extern JS_PUBLIC_API(bool) +JS_HasInstance(JSContext *cx, JS::Handle obj, JS::Handle v, bool *bp); + +extern JS_PUBLIC_API(void *) +JS_GetPrivate(JSObject *obj); + +extern JS_PUBLIC_API(void) +JS_SetPrivate(JSObject *obj, void *data); + +extern JS_PUBLIC_API(void *) +JS_GetInstancePrivate(JSContext *cx, JS::Handle obj, const JSClass *clasp, + JS::CallArgs *args); + +extern JS_PUBLIC_API(bool) +JS_GetPrototype(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject protop); + +extern JS_PUBLIC_API(bool) +JS_SetPrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); + +extern JS_PUBLIC_API(JSObject *) +JS_GetParent(JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_SetParent(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent); + +extern JS_PUBLIC_API(JSObject *) +JS_GetConstructor(JSContext *cx, JS::Handle proto); + +namespace JS { + +enum ZoneSpecifier { + FreshZone = 0, + SystemZone = 1 +}; + +class JS_PUBLIC_API(CompartmentOptions) +{ + public: + class Override { + public: + Override() : mode_(Default) {} + + bool get(bool defaultValue) const { + if (mode_ == Default) + return defaultValue; + return mode_ == ForceTrue; + }; + + void set(bool overrideValue) { + mode_ = overrideValue ? ForceTrue : ForceFalse; + }; + + void reset() { + mode_ = Default; + } + + private: + enum Mode { + Default, + ForceTrue, + ForceFalse + }; + + Mode mode_; + }; + + explicit CompartmentOptions() + : version_(JSVERSION_UNKNOWN) + , invisibleToDebugger_(false) + , mergeable_(false) + , discardSource_(false) + , cloneSingletons_(false) + , traceGlobal_(nullptr) + , singletonsAsTemplates_(true) + , addonId_(nullptr) + { + zone_.spec = JS::FreshZone; + } + + JSVersion version() const { return version_; } + CompartmentOptions &setVersion(JSVersion aVersion) { + MOZ_ASSERT(aVersion != JSVERSION_UNKNOWN); + version_ = aVersion; + return *this; + } + + // Certain scopes (i.e. XBL compilation scopes) are implementation details + // of the embedding, and references to them should never leak out to script. + // This flag causes the this compartment to skip firing onNewGlobalObject + // and makes addDebuggee a no-op for this global. + bool invisibleToDebugger() const { return invisibleToDebugger_; } + CompartmentOptions &setInvisibleToDebugger(bool flag) { + invisibleToDebugger_ = flag; + return *this; + } + + // Compartments used for off-thread compilation have their contents merged + // into a target compartment when the compilation is finished. This is only + // allowed if this flag is set. The invisibleToDebugger flag must also be + // set for such compartments. + bool mergeable() const { return mergeable_; } + CompartmentOptions &setMergeable(bool flag) { + mergeable_ = flag; + return *this; + } + + // For certain globals, we know enough about the code that will run in them + // that we can discard script source entirely. + bool discardSource() const { return discardSource_; } + CompartmentOptions &setDiscardSource(bool flag) { + discardSource_ = flag; + return *this; + } + + + bool cloneSingletons() const { return cloneSingletons_; } + CompartmentOptions &setCloneSingletons(bool flag) { + cloneSingletons_ = flag; + return *this; + } + + void *zonePointer() const { + JS_ASSERT(uintptr_t(zone_.pointer) > uintptr_t(JS::SystemZone)); + return zone_.pointer; + } + ZoneSpecifier zoneSpecifier() const { return zone_.spec; } + CompartmentOptions &setZone(ZoneSpecifier spec); + CompartmentOptions &setSameZoneAs(JSObject *obj); + + void setSingletonsAsValues() { + singletonsAsTemplates_ = false; + } + bool getSingletonsAsTemplates() const { + return singletonsAsTemplates_; + }; + + // A null add-on ID means that the compartment is not associated with an + // add-on. + JSAddonId *addonIdOrNull() const { return addonId_; } + CompartmentOptions &setAddonId(JSAddonId *id) { + addonId_ = id; + return *this; + } + + CompartmentOptions &setTrace(JSTraceOp op) { + traceGlobal_ = op; + return *this; + } + JSTraceOp getTrace() const { + return traceGlobal_; + } + + private: + JSVersion version_; + bool invisibleToDebugger_; + bool mergeable_; + bool discardSource_; + bool cloneSingletons_; + union { + ZoneSpecifier spec; + void *pointer; // js::Zone* is not exposed in the API. + } zone_; + JSTraceOp traceGlobal_; + + // To XDR singletons, we need to ensure that all singletons are all used as + // templates, by making JSOP_OBJECT return a clone of the JSScript + // singleton, instead of returning the value which is baked in the JSScript. + bool singletonsAsTemplates_; + + JSAddonId *addonId_; +}; + +JS_PUBLIC_API(CompartmentOptions &) +CompartmentOptionsRef(JSCompartment *compartment); + +JS_PUBLIC_API(CompartmentOptions &) +CompartmentOptionsRef(JSObject *obj); + +JS_PUBLIC_API(CompartmentOptions &) +CompartmentOptionsRef(JSContext *cx); + +// During global creation, we fire notifications to callbacks registered +// via the Debugger API. These callbacks are arbitrary script, and can touch +// the global in arbitrary ways. When that happens, the global should not be +// in a half-baked state. But this creates a problem for consumers that need +// to set slots on the global to put it in a consistent state. +// +// This API provides a way for consumers to set slots atomically (immediately +// after the global is created), before any debugger hooks are fired. It's +// unfortunately on the clunky side, but that's the way the cookie crumbles. +// +// If callers have no additional state on the global to set up, they may pass +// |FireOnNewGlobalHook| to JS_NewGlobalObject, which causes that function to +// fire the hook as its final act before returning. Otherwise, callers should +// pass |DontFireOnNewGlobalHook|, which means that they are responsible for +// invoking JS_FireOnNewGlobalObject upon successfully creating the global. If +// an error occurs and the operation aborts, callers should skip firing the +// hook. But otherwise, callers must take care to fire the hook exactly once +// before compiling any script in the global's scope (we have assertions in +// place to enforce this). This lets us be sure that debugger clients never miss +// breakpoints. +enum OnNewGlobalHookOption { + FireOnNewGlobalHook, + DontFireOnNewGlobalHook +}; + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSObject *) +JS_NewGlobalObject(JSContext *cx, const JSClass *clasp, JSPrincipals *principals, + JS::OnNewGlobalHookOption hookOption, + const JS::CompartmentOptions &options = JS::CompartmentOptions()); +/* + * Spidermonkey does not have a good way of keeping track of what compartments should be marked on + * their own. We can mark the roots unconditionally, but marking GC things only relevant in live + * compartments is hard. To mitigate this, we create a static trace hook, installed on each global + * object, from which we can be sure the compartment is relevant, and mark it. + * + * It is still possible to specify custom trace hooks for global object classes. They can be + * provided via the CompartmentOptions passed to JS_NewGlobalObject. + */ +extern JS_PUBLIC_API(void) +JS_GlobalObjectTraceHook(JSTracer *trc, JSObject *global); + +extern JS_PUBLIC_API(void) +JS_FireOnNewGlobalObject(JSContext *cx, JS::HandleObject global); + +extern JS_PUBLIC_API(JSObject *) +JS_NewObject(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); + +/* Queries the [[Extensible]] property of the object. */ +extern JS_PUBLIC_API(bool) +JS_IsExtensible(JSContext *cx, JS::HandleObject obj, bool *extensible); + +extern JS_PUBLIC_API(bool) +JS_IsNative(JSObject *obj); + +extern JS_PUBLIC_API(JSRuntime *) +JS_GetObjectRuntime(JSObject *obj); + +/* + * Unlike JS_NewObject, JS_NewObjectWithGivenProto does not compute a default + * proto if proto's actual parameter value is null. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); + +/* + * Freeze obj, and all objects it refers to, recursively. This will not recurse + * through non-extensible objects, on the assumption that those are already + * deep-frozen. + */ +extern JS_PUBLIC_API(bool) +JS_DeepFreezeObject(JSContext *cx, JS::Handle obj); + +/* + * Freezes an object; see ES5's Object.freeze(obj) method. + */ +extern JS_PUBLIC_API(bool) +JS_FreezeObject(JSContext *cx, JS::Handle obj); + +extern JS_PUBLIC_API(bool) +JS_PreventExtensions(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(JSObject *) +JS_New(JSContext *cx, JS::HandleObject ctor, const JS::HandleValueArray& args); + +extern JS_PUBLIC_API(JSObject *) +JS_DefineObject(JSContext *cx, JS::HandleObject obj, const char *name, + const JSClass *clasp = nullptr, JS::HandleObject proto = JS::NullPtr(), + unsigned attrs = 0); + +extern JS_PUBLIC_API(bool) +JS_DefineConstDoubles(JSContext *cx, JS::HandleObject obj, const JSConstDoubleSpec *cds); + +extern JS_PUBLIC_API(bool) +JS_DefineProperties(JSContext *cx, JS::HandleObject obj, const JSPropertySpec *ps); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnProperty(JSContext *cx, JS::HandleObject obj, const char *name, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasProperty(JSContext *cx, JS::HandleObject obj, const char *name, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_LookupPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); + +struct JSPropertyDescriptor { + JSObject *obj; + unsigned attrs; + JSPropertyOp getter; + JSStrictPropertyOp setter; + JS::Value value; + + JSPropertyDescriptor() + : obj(nullptr), attrs(0), getter(nullptr), setter(nullptr), value(JSVAL_VOID) + {} + + void trace(JSTracer *trc); + + static js::ThingRootKind rootKind() { return js::THING_ROOT_PROPERTY_DESCRIPTOR; } +}; + +namespace JS { + +template +class PropertyDescriptorOperations +{ + const JSPropertyDescriptor * desc() const { return static_cast(this)->extract(); } + + public: + bool isEnumerable() const { return desc()->attrs & JSPROP_ENUMERATE; } + bool isReadonly() const { return desc()->attrs & JSPROP_READONLY; } + bool isPermanent() const { return desc()->attrs & JSPROP_PERMANENT; } + bool hasNativeAccessors() const { return desc()->attrs & JSPROP_NATIVE_ACCESSORS; } + bool hasGetterObject() const { return desc()->attrs & JSPROP_GETTER; } + bool hasSetterObject() const { return desc()->attrs & JSPROP_SETTER; } + bool hasGetterOrSetterObject() const { return desc()->attrs & (JSPROP_GETTER | JSPROP_SETTER); } + bool hasGetterOrSetter() const { return desc()->getter || desc()->setter; } + bool isShared() const { return desc()->attrs & JSPROP_SHARED; } + bool isIndex() const { return desc()->attrs & JSPROP_INDEX; } + bool hasAttributes(unsigned attrs) const { return desc()->attrs & attrs; } + + JS::HandleObject object() const { + return JS::HandleObject::fromMarkedLocation(&desc()->obj); + } + unsigned attributes() const { return desc()->attrs; } + JSPropertyOp getter() const { return desc()->getter; } + JSStrictPropertyOp setter() const { return desc()->setter; } + JS::HandleObject getterObject() const { + MOZ_ASSERT(hasGetterObject()); + return JS::HandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->getter)); + } + JS::HandleObject setterObject() const { + MOZ_ASSERT(hasSetterObject()); + return JS::HandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->setter)); + } + JS::HandleValue value() const { + return JS::HandleValue::fromMarkedLocation(&desc()->value); + } +}; + +template +class MutablePropertyDescriptorOperations : public PropertyDescriptorOperations +{ + JSPropertyDescriptor * desc() { return static_cast(this)->extractMutable(); } + + public: + + void clear() { + object().set(nullptr); + setAttributes(0); + setGetter(nullptr); + setSetter(nullptr); + value().setUndefined(); + } + + void assign(JSPropertyDescriptor &other) { + object().set(other.obj); + setAttributes(other.attrs); + setGetter(other.getter); + setSetter(other.setter); + value().set(other.value); + } + + JS::MutableHandleObject object() { + return JS::MutableHandleObject::fromMarkedLocation(&desc()->obj); + } + unsigned &attributesRef() { return desc()->attrs; } + JSPropertyOp &getter() { return desc()->getter; } + JSStrictPropertyOp &setter() { return desc()->setter; } + JS::MutableHandleValue value() { + return JS::MutableHandleValue::fromMarkedLocation(&desc()->value); + } + + void setEnumerable() { desc()->attrs |= JSPROP_ENUMERATE; } + void setAttributes(unsigned attrs) { desc()->attrs = attrs; } + + void setGetter(JSPropertyOp op) { desc()->getter = op; } + void setSetter(JSStrictPropertyOp op) { desc()->setter = op; } + void setGetterObject(JSObject *obj) { desc()->getter = reinterpret_cast(obj); } + void setSetterObject(JSObject *obj) { desc()->setter = reinterpret_cast(obj); } + + JS::MutableHandleObject getterObject() { + MOZ_ASSERT(this->hasGetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->getter)); + } + JS::MutableHandleObject setterObject() { + MOZ_ASSERT(this->hasSetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->setter)); + } +}; + +} /* namespace JS */ + +namespace js { + +template <> +struct GCMethods { + static JSPropertyDescriptor initial() { return JSPropertyDescriptor(); } + static bool poisoned(const JSPropertyDescriptor &desc) { + return (desc.obj && JS::IsPoisonedPtr(desc.obj)) || + (desc.attrs & JSPROP_GETTER && desc.getter && JS::IsPoisonedPtr(desc.getter)) || + (desc.attrs & JSPROP_SETTER && desc.setter && JS::IsPoisonedPtr(desc.setter)) || + (desc.value.isGCThing() && JS::IsPoisonedPtr(desc.value.toGCThing())); + } +}; + +template <> +class RootedBase + : public JS::MutablePropertyDescriptorOperations > +{ + friend class JS::PropertyDescriptorOperations >; + friend class JS::MutablePropertyDescriptorOperations >; + const JSPropertyDescriptor *extract() const { + return static_cast*>(this)->address(); + } + JSPropertyDescriptor *extractMutable() { + return static_cast*>(this)->address(); + } +}; + +template <> +class HandleBase + : public JS::PropertyDescriptorOperations > +{ + friend class JS::PropertyDescriptorOperations >; + const JSPropertyDescriptor *extract() const { + return static_cast*>(this)->address(); + } +}; + +template <> +class MutableHandleBase + : public JS::MutablePropertyDescriptorOperations > +{ + friend class JS::PropertyDescriptorOperations >; + friend class JS::MutablePropertyDescriptorOperations >; + const JSPropertyDescriptor *extract() const { + return static_cast*>(this)->address(); + } + JSPropertyDescriptor *extractMutable() { + return static_cast*>(this)->address(); + } +}; + +} /* namespace js */ + +namespace JS { + +extern JS_PUBLIC_API(bool) +ParsePropertyDescriptorObject(JSContext *cx, + JS::HandleObject obj, + JS::HandleValue descriptor, + JS::MutableHandle desc); + +} // namespace JS + +extern JS_PUBLIC_API(bool) +JS_GetOwnPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandle desc); + +extern JS_PUBLIC_API(bool) +JS_GetOwnPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, + JS::MutableHandle desc); + +/* + * Like JS_GetOwnPropertyDescriptorById but will return a property on + * an object on the prototype chain (returned in desc->obj). If desc->obj is null, + * then this property was not found on the prototype chain. + */ +extern JS_PUBLIC_API(bool) +JS_GetPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandle desc); + +extern JS_PUBLIC_API(bool) +JS_GetPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, + JS::MutableHandle desc); + +extern JS_PUBLIC_API(bool) +JS_GetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetPropertyTo(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject onBehalfOf, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_SetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_DeleteProperty(JSContext *cx, JS::HandleObject obj, const char *name); + +extern JS_PUBLIC_API(bool) +JS_DeleteProperty2(JSContext *cx, JS::HandleObject obj, const char *name, bool *succeeded); + +extern JS_PUBLIC_API(bool) +JS_DeletePropertyById(JSContext *cx, JS::HandleObject obj, jsid id); + +extern JS_PUBLIC_API(bool) +JS_DeletePropertyById2(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleValue value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleObject value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleString value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + int32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + uint32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + double value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, + size_t namelen, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasUCProperty(JSContext *cx, JS::HandleObject obj, + const jschar *name, size_t namelen, + bool *vp); + +extern JS_PUBLIC_API(bool) +JS_LookupUCProperty(JSContext *cx, JS::HandleObject obj, + const jschar *name, size_t namelen, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetUCProperty(JSContext *cx, JS::HandleObject obj, + const jschar *name, size_t namelen, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetUCProperty(JSContext *cx, JS::HandleObject obj, + const jschar *name, size_t namelen, + JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_DeleteUCProperty2(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + bool *succeeded); + +extern JS_PUBLIC_API(JSObject *) +JS_NewArrayObject(JSContext *cx, const JS::HandleValueArray& contents); + +extern JS_PUBLIC_API(JSObject *) +JS_NewArrayObject(JSContext *cx, size_t length); + +extern JS_PUBLIC_API(bool) +JS_IsArrayObject(JSContext *cx, JS::HandleValue value); + +extern JS_PUBLIC_API(bool) +JS_IsArrayObject(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(bool) +JS_GetArrayLength(JSContext *cx, JS::Handle obj, uint32_t *lengthp); + +extern JS_PUBLIC_API(bool) +JS_SetArrayLength(JSContext *cx, JS::Handle obj, uint32_t length); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetElementTo(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::HandleObject onBehalfOf, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double v); + +extern JS_PUBLIC_API(bool) +JS_DeleteElement(JSContext *cx, JS::HandleObject obj, uint32_t index); + +extern JS_PUBLIC_API(bool) +JS_DeleteElement2(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded); + +/* + * Remove all configurable properties from the given (non-global) object and + * assign undefined to all writable data properties. + */ +JS_PUBLIC_API(void) +JS_ClearNonGlobalObject(JSContext *cx, JS::HandleObject obj); + +/* + * Assign 'undefined' to all of the object's non-reserved slots. Note: this is + * done for all slots, regardless of the associated property descriptor. + */ +JS_PUBLIC_API(void) +JS_SetAllNonReservedSlotsToUndefined(JSContext *cx, JSObject *objArg); + +/* + * Create a new array buffer with the given contents. On success, the ownership + * is transferred to the new array buffer. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); + +/* + * Steal the contents of the given array buffer. The array buffer has its + * length set to 0 and its contents array cleared. The caller takes ownership + * of the return value and must free it or transfer ownership via + * JS_NewArrayBufferWithContents when done using it. + */ +extern JS_PUBLIC_API(void *) +JS_StealArrayBufferContents(JSContext *cx, JS::HandleObject obj); + +/* + * Allocate memory that may be eventually passed to + * JS_NewArrayBufferWithContents. |maybecx| is optional; if a non-nullptr cx is + * given, it will be used for memory accounting and OOM reporting. |nbytes| is + * the number of payload bytes required. + */ +extern JS_PUBLIC_API(void *) +JS_AllocateArrayBufferContents(JSContext *maybecx, uint32_t nbytes); + +/* + * Reallocate memory allocated by JS_AllocateArrayBufferContents, growing or + * shrinking it as appropriate. If oldContents is null then this behaves like + * JS_AllocateArrayBufferContents. + */ +extern JS_PUBLIC_API(void *) +JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void *oldContents, uint32_t oldNbytes); + +/* + * Create a new mapped array buffer with the given memory mapped contents. On success, + * the ownership is transferred to the new mapped array buffer. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewMappedArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); + +/* + * Create memory mapped array buffer contents. + * Caller must take care of closing fd after calling this function. + */ +extern JS_PUBLIC_API(void *) +JS_CreateMappedArrayBufferContents(int fd, size_t offset, size_t length); + +/* + * Release the allocated resource of mapped array buffer contents before the + * object is created. + * If a new object has been created by JS_NewMappedArrayBufferWithContents() + * with this content, then JS_NeuterArrayBuffer() should be used instead to + * release the resource used by the object. + */ +extern JS_PUBLIC_API(void) +JS_ReleaseMappedArrayBufferContents(void *contents, size_t length); + +extern JS_PUBLIC_API(JSIdArray *) +JS_Enumerate(JSContext *cx, JS::HandleObject obj); + +/* + * Create an object to iterate over enumerable properties of obj, in arbitrary + * property definition order. NB: This differs from longstanding for..in loop + * order, which uses order of property definition in obj. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewPropertyIterator(JSContext *cx, JS::Handle obj); + +/* + * Return true on success with *idp containing the id of the next enumerable + * property to visit using iterobj, or JSID_IS_VOID if there is no such property + * left to visit. Return false on error. + */ +extern JS_PUBLIC_API(bool) +JS_NextProperty(JSContext *cx, JS::Handle iterobj, jsid *idp); + +extern JS_PUBLIC_API(jsval) +JS_GetReservedSlot(JSObject *obj, uint32_t index); + +extern JS_PUBLIC_API(void) +JS_SetReservedSlot(JSObject *obj, uint32_t index, jsval v); + +/************************************************************************/ + +/* + * Functions and scripts. + */ +extern JS_PUBLIC_API(JSFunction *) +JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, + JS::Handle parent, const char *name); + +/* + * Create the function with the name given by the id. JSID_IS_STRING(id) must + * be true. + */ +extern JS_PUBLIC_API(JSFunction *) +JS_NewFunctionById(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, + JS::Handle parent, JS::Handle id); + +namespace JS { + +extern JS_PUBLIC_API(JSFunction *) +GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, JS::Handle id, + unsigned nargs); + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSObject *) +JS_GetFunctionObject(JSFunction *fun); + +/* + * Return the function's identifier as a JSString, or null if fun is unnamed. + * The returned string lives as long as fun, so you don't need to root a saved + * reference to it if fun is well-connected or rooted, and provided you bound + * the use of the saved reference by fun's lifetime. + */ +extern JS_PUBLIC_API(JSString *) +JS_GetFunctionId(JSFunction *fun); + +/* + * Return a function's display name. This is the defined name if one was given + * where the function was defined, or it could be an inferred name by the JS + * engine in the case that the function was defined to be anonymous. This can + * still return nullptr if a useful display name could not be inferred. The + * same restrictions on rooting as those in JS_GetFunctionId apply. + */ +extern JS_PUBLIC_API(JSString *) +JS_GetFunctionDisplayId(JSFunction *fun); + +/* + * Return the arity (length) of fun. + */ +extern JS_PUBLIC_API(uint16_t) +JS_GetFunctionArity(JSFunction *fun); + +/* + * Infallible predicate to test whether obj is a function object (faster than + * comparing obj's class name to "Function", but equivalent unless someone has + * overwritten the "Function" identifier with a different constructor and then + * created instances using that constructor that might be passed in as obj). + */ +extern JS_PUBLIC_API(bool) +JS_ObjectIsFunction(JSContext *cx, JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_ObjectIsCallable(JSContext *cx, JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_IsNativeFunction(JSObject *funobj, JSNative call); + +/* Return whether the given function is a valid constructor. */ +extern JS_PUBLIC_API(bool) +JS_IsConstructor(JSFunction *fun); + +/* + * Bind the given callable to use the given object as "this". + * + * If |callable| is not callable, will throw and return nullptr. + */ +extern JS_PUBLIC_API(JSObject*) +JS_BindCallable(JSContext *cx, JS::Handle callable, JS::Handle newThis); + +extern JS_PUBLIC_API(bool) +JS_DefineFunctions(JSContext *cx, JS::Handle obj, const JSFunctionSpec *fs); + +extern JS_PUBLIC_API(JSFunction *) +JS_DefineFunction(JSContext *cx, JS::Handle obj, const char *name, JSNative call, + unsigned nargs, unsigned attrs); + +extern JS_PUBLIC_API(JSFunction *) +JS_DefineUCFunction(JSContext *cx, JS::Handle obj, + const jschar *name, size_t namelen, JSNative call, + unsigned nargs, unsigned attrs); + +extern JS_PUBLIC_API(JSFunction *) +JS_DefineFunctionById(JSContext *cx, JS::Handle obj, JS::Handle id, JSNative call, + unsigned nargs, unsigned attrs); + +/* + * Clone a top-level function into a new scope. This function will dynamically + * fail if funobj was lexically nested inside some other function. + */ +extern JS_PUBLIC_API(JSObject *) +JS_CloneFunctionObject(JSContext *cx, JS::Handle funobj, JS::Handle parent); + +/* + * Given a buffer, return false if the buffer might become a valid + * javascript statement with the addition of more lines. Otherwise return + * true. The intent is to support interactive compilation - accumulate + * lines in a buffer until JS_BufferIsCompilableUnit is true, then pass it to + * the compiler. + */ +extern JS_PUBLIC_API(bool) +JS_BufferIsCompilableUnit(JSContext *cx, JS::Handle obj, const char *utf8, + size_t length); + +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +JS_CompileScript(JSContext *cx, JS::HandleObject obj, + const char *ascii, size_t length, + const JS::CompileOptions &options, + JS::MutableHandleScript script); + +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +JS_CompileUCScript(JSContext *cx, JS::HandleObject obj, + const jschar *chars, size_t length, + const JS::CompileOptions &options, + JS::MutableHandleScript script); + +extern JS_PUBLIC_API(JSObject *) +JS_GetGlobalFromScript(JSScript *script); + +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +JS_CompileFunction(JSContext *cx, JS::HandleObject obj, const char *name, + unsigned nargs, const char *const *argnames, + const char *bytes, size_t length, + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); + +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +JS_CompileUCFunction(JSContext *cx, JS::HandleObject obj, const char *name, + unsigned nargs, const char *const *argnames, + const jschar *chars, size_t length, + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); + +namespace JS { + +/* Options for JavaScript compilation. */ + +/* + * In the most common use case, a CompileOptions instance is allocated on the + * stack, and holds non-owning references to non-POD option values: strings; + * principals; objects; and so on. The code declaring the instance guarantees + * that such option values will outlive the CompileOptions itself: objects are + * otherwise rooted; principals have had their reference counts bumped; strings + * will not be freed until the CompileOptions goes out of scope. In this + * situation, CompileOptions only refers to things others own, so it can be + * lightweight. + * + * In some cases, however, we need to hold compilation options with a + * non-stack-like lifetime. For example, JS::CompileOffThread needs to save + * compilation options where a worker thread can find them, and then return + * immediately. The worker thread will come along at some later point, and use + * the options. + * + * The compiler itself just needs to be able to access a collection of options; + * it doesn't care who owns them, or what's keeping them alive. It does its own + * addrefs/copies/tracing/etc. + * + * So, we have a class hierarchy that reflects these three use cases: + * + * - ReadOnlyCompileOptions is the common base class. It can be used by code + * that simply needs to access options set elsewhere, like the compiler. + * + * - The usual CompileOptions class must be stack-allocated, and holds + * non-owning references to the filename, element, and so on. It's derived + * from ReadOnlyCompileOptions, so the compiler can use it. + * + * - OwningCompileOptions roots / copies / reference counts of all its values, + * and unroots / frees / releases them when it is destructed. It too is + * derived from ReadOnlyCompileOptions, so the compiler accepts it. + */ + +/* + * The common base class for the CompileOptions hierarchy. + * + * Use this in code that only needs to access compilation options created + * elsewhere, like the compiler. Don't instantiate this class (the constructor + * is protected anyway); instead, create instances only of the derived classes: + * CompileOptions and OwningCompileOptions. + */ +class JS_FRIEND_API(ReadOnlyCompileOptions) +{ + friend class CompileOptions; + + protected: + JSPrincipals *originPrincipals_; + const char *filename_; + const char *introducerFilename_; + const jschar *sourceMapURL_; + + // This constructor leaves 'version' set to JSVERSION_UNKNOWN. The structure + // is unusable until that's set to something more specific; the derived + // classes' constructors take care of that, in ways appropriate to their + // purpose. + ReadOnlyCompileOptions() + : originPrincipals_(nullptr), + filename_(nullptr), + introducerFilename_(nullptr), + sourceMapURL_(nullptr), + version(JSVERSION_UNKNOWN), + versionSet(false), + utf8(false), + lineno(1), + column(0), + compileAndGo(false), + forEval(false), + defineOnScope(true), + noScriptRval(false), + selfHostingMode(false), + canLazilyParse(true), + strictOption(false), + extraWarningsOption(false), + werrorOption(false), + asmJSOption(false), + forceAsync(false), + installedFile(false), + sourceIsLazy(false), + introductionType(nullptr), + introductionLineno(0), + introductionOffset(0), + hasIntroductionInfo(false) + { } + + // Set all POD options (those not requiring reference counts, copies, + // rooting, or other hand-holding) to their values in |rhs|. + void copyPODOptions(const ReadOnlyCompileOptions &rhs); + + public: + // Read-only accessors for non-POD options. The proper way to set these + // depends on the derived type. + JSPrincipals *originPrincipals(js::ExclusiveContext *cx) const; + const char *filename() const { return filename_; } + const char *introducerFilename() const { return introducerFilename_; } + const jschar *sourceMapURL() const { return sourceMapURL_; } + virtual JSObject *element() const = 0; + virtual JSString *elementAttributeName() const = 0; + virtual JSScript *introductionScript() const = 0; + + // POD options. + JSVersion version; + bool versionSet; + bool utf8; + unsigned lineno; + unsigned column; + bool compileAndGo; + bool forEval; + bool defineOnScope; + bool noScriptRval; + bool selfHostingMode; + bool canLazilyParse; + bool strictOption; + bool extraWarningsOption; + bool werrorOption; + bool asmJSOption; + bool forceAsync; + bool installedFile; // 'true' iff pre-compiling js file in packaged app + bool sourceIsLazy; + + // |introductionType| is a statically allocated C string: + // one of "eval", "Function", or "GeneratorFunction". + const char *introductionType; + unsigned introductionLineno; + uint32_t introductionOffset; + bool hasIntroductionInfo; + + private: + static JSObject * const nullObjectPtr; + void operator=(const ReadOnlyCompileOptions &) MOZ_DELETE; +}; + +/* + * Compilation options, with dynamic lifetime. An instance of this type + * makes a copy of / holds / roots all dynamically allocated resources + * (principals; elements; strings) that it refers to. Its destructor frees + * / drops / unroots them. This is heavier than CompileOptions, below, but + * unlike CompileOptions, it can outlive any given stack frame. + * + * Note that this *roots* any JS values it refers to - they're live + * unconditionally. Thus, instances of this type can't be owned, directly + * or indirectly, by a JavaScript object: if any value that this roots ever + * comes to refer to the object that owns this, then the whole cycle, and + * anything else it entrains, will never be freed. + */ +class JS_FRIEND_API(OwningCompileOptions) : public ReadOnlyCompileOptions +{ + JSRuntime *runtime; + PersistentRootedObject elementRoot; + PersistentRootedString elementAttributeNameRoot; + PersistentRootedScript introductionScriptRoot; + + public: + // A minimal constructor, for use with OwningCompileOptions::copy. This + // leaves |this.version| set to JSVERSION_UNKNOWN; the instance + // shouldn't be used until we've set that to something real (as |copy| + // will). + explicit OwningCompileOptions(JSContext *cx); + ~OwningCompileOptions(); + + JSObject *element() const MOZ_OVERRIDE { return elementRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } + + // Set this to a copy of |rhs|. Return false on OOM. + bool copy(JSContext *cx, const ReadOnlyCompileOptions &rhs); + + /* These setters make copies of their string arguments, and are fallible. */ + bool setFile(JSContext *cx, const char *f); + bool setFileAndLine(JSContext *cx, const char *f, unsigned l); + bool setSourceMapURL(JSContext *cx, const jschar *s); + bool setIntroducerFilename(JSContext *cx, const char *s); + + /* These setters are infallible, and can be chained. */ + OwningCompileOptions &setLine(unsigned l) { lineno = l; return *this; } + OwningCompileOptions &setElement(JSObject *e) { + elementRoot = e; + return *this; + } + OwningCompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + OwningCompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; + return *this; + } + OwningCompileOptions &setOriginPrincipals(JSPrincipals *p) { + if (p) JS_HoldPrincipals(p); + if (originPrincipals_) JS_DropPrincipals(runtime, originPrincipals_); + originPrincipals_ = p; + return *this; + } + OwningCompileOptions &setVersion(JSVersion v) { + version = v; + versionSet = true; + return *this; + } + OwningCompileOptions &setUTF8(bool u) { utf8 = u; return *this; } + OwningCompileOptions &setColumn(unsigned c) { column = c; return *this; } + OwningCompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } + OwningCompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + OwningCompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } + OwningCompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } + OwningCompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } + OwningCompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } + OwningCompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + OwningCompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + bool setIntroductionInfo(JSContext *cx, const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + if (!setIntroducerFilename(cx, introducerFn)) + return false; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return true; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; +}; + +/* + * Compilation options stored on the stack. An instance of this type + * simply holds references to dynamically allocated resources (element; + * filename; source map URL) that are owned by something else. If you + * create an instance of this type, it's up to you to guarantee that + * everything you store in it will outlive it. + */ +class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOptions +{ + RootedObject elementRoot; + RootedString elementAttributeNameRoot; + RootedScript introductionScriptRoot; + + public: + explicit CompileOptions(JSContext *cx, JSVersion version = JSVERSION_UNKNOWN); + CompileOptions(js::ContextFriendFields *cx, const ReadOnlyCompileOptions &rhs) + : ReadOnlyCompileOptions(), elementRoot(cx), elementAttributeNameRoot(cx), + introductionScriptRoot(cx) + { + copyPODOptions(rhs); + + originPrincipals_ = rhs.originPrincipals_; + filename_ = rhs.filename(); + sourceMapURL_ = rhs.sourceMapURL(); + elementRoot = rhs.element(); + elementAttributeNameRoot = rhs.elementAttributeName(); + introductionScriptRoot = rhs.introductionScript(); + } + + JSObject *element() const MOZ_OVERRIDE { return elementRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } + + CompileOptions &setFile(const char *f) { filename_ = f; return *this; } + CompileOptions &setLine(unsigned l) { lineno = l; return *this; } + CompileOptions &setFileAndLine(const char *f, unsigned l) { + filename_ = f; lineno = l; return *this; + } + CompileOptions &setSourceMapURL(const jschar *s) { sourceMapURL_ = s; return *this; } + CompileOptions &setElement(JSObject *e) { elementRoot = e; return *this; } + CompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + CompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; + return *this; + } + CompileOptions &setOriginPrincipals(JSPrincipals *p) { + originPrincipals_ = p; + return *this; + } + CompileOptions &setVersion(JSVersion v) { + version = v; + versionSet = true; + return *this; + } + CompileOptions &setUTF8(bool u) { utf8 = u; return *this; } + CompileOptions &setColumn(unsigned c) { column = c; return *this; } + CompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } + CompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + CompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } + CompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } + CompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } + CompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } + CompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + CompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + CompileOptions &setIntroductionInfo(const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + introducerFilename_ = introducerFn; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return *this; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; +}; + +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, FILE *file, + JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *filename, + JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t length); + +/* + * Off thread compilation control flow. + * + * After successfully triggering an off thread compile of a script, the + * callback will eventually be invoked with the specified data and a token + * for the compilation. The callback will be invoked while off the main thread, + * so must ensure that its operations are thread safe. Afterwards, + * FinishOffThreadScript must be invoked on the main thread to get the result + * script or nullptr. If maybecx is not specified, the resources will be freed, + * but no script will be returned. + * + * The characters passed in to CompileOffThread must remain live until the + * callback is invoked, and the resulting script will be rooted until the call + * to FinishOffThreadScript. + */ + +extern JS_PUBLIC_API(bool) +CompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, + OffThreadCompileCallback callback, void *callbackData); + +extern JS_PUBLIC_API(JSScript *) +FinishOffThreadScript(JSContext *maybecx, JSRuntime *rt, void *token); + +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *name, unsigned nargs, const char *const *argnames, + SourceBufferHolder &srcBuf, JS::MutableHandleFunction fun); + +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *name, unsigned nargs, const char *const *argnames, + const char *bytes, size_t length, JS::MutableHandleFunction fun); + +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *name, unsigned nargs, const char *const *argnames, + const jschar *chars, size_t length, JS::MutableHandleFunction fun); + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSString *) +JS_DecompileScript(JSContext *cx, JS::Handle script, const char *name, unsigned indent); + +/* + * API extension: OR this into indent to avoid pretty-printing the decompiled + * source resulting from JS_DecompileFunction{,Body}. + */ +#define JS_DONT_PRETTY_PRINT ((unsigned)0x8000) + +extern JS_PUBLIC_API(JSString *) +JS_DecompileFunction(JSContext *cx, JS::Handle fun, unsigned indent); + +extern JS_PUBLIC_API(JSString *) +JS_DecompileFunctionBody(JSContext *cx, JS::Handle fun, unsigned indent); + +/* + * NB: JS_ExecuteScript and the JS_Evaluate*Script* quadruplets use the obj + * parameter as the initial scope chain header, the 'this' keyword value, and + * the variables object (ECMA parlance for where 'var' and 'function' bind + * names) of the execution context for script. + * + * Using obj as the variables object is problematic if obj's parent (which is + * the scope chain link; see JS_SetParent and JS_NewObject) is not null: in + * this case, variables created by 'var x = 0', e.g., go in obj, but variables + * created by assignment to an unbound id, 'x = 0', go in the last object on + * the scope chain linked by parent. + * + * ECMA calls that last scoping object the "global object", but note that many + * embeddings have several such objects. ECMA requires that "global code" be + * executed with the variables object equal to this global object. But these + * JS API entry points provide freedom to execute code against a "sub-global", + * i.e., a parented or scoped object, in which case the variables object will + * differ from the last object on the scope chain, resulting in confusing and + * non-ECMA explicit vs. implicit variable creation. + * + * Caveat embedders: unless you already depend on this buggy variables object + * binding behavior, you should call ContextOptionsRef(cx).setVarObjFix(true) + * for each context in the application, if you pass parented objects as the obj + * parameter, or may ever pass such objects in the future. + * + * Why a runtime option? The alternative is to add six or so new API entry + * points with signatures matching the following six, and that doesn't seem + * worth the code bloat cost. Such new entry points would probably have less + * obvious names, too, so would not tend to be used. The JS_SetOption call, + * OTOH, can be more easily hacked into existing code that does not depend on + * the bug; such code can continue to use the familiar JS_EvaluateScript, + * etc., entry points. + */ +extern JS_PUBLIC_API(bool) +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script); + +namespace JS { + +/* + * Like the above, but handles a cross-compartment script. If the script is + * cross-compartment, it is cloned into the current compartment before executing. + */ +extern JS_PUBLIC_API(bool) +CloneAndExecuteScript(JSContext *cx, JS::Handle obj, JS::Handle script); + +} /* namespace JS */ + +extern JS_PUBLIC_API(bool) +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleValue rval, JSVersion version); + +extern JS_PUBLIC_API(bool) +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JSVersion version); + +extern JS_PUBLIC_API(bool) +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno); + +extern JS_PUBLIC_API(bool) +JS_EvaluateUCScript(JSContext *cx, JS::Handle obj, + const jschar *chars, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandle rval); + +namespace JS { + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename); + +} /* namespace JS */ + +extern JS_PUBLIC_API(bool) +JS_CallFunction(JSContext *cx, JS::HandleObject obj, JS::HandleFunction fun, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_CallFunctionName(JSContext *cx, JS::HandleObject obj, const char *name, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_CallFunctionValue(JSContext *cx, JS::HandleObject obj, JS::HandleValue fval, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); + +namespace JS { + +static inline bool +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleFunction fun, + const JS::HandleValueArray &args, MutableHandleValue rval) +{ + return !!JS_CallFunction(cx, thisObj, fun, args, rval); +} + +static inline bool +Call(JSContext *cx, JS::HandleObject thisObj, const char *name, const JS::HandleValueArray& args, + MutableHandleValue rval) +{ + return !!JS_CallFunctionName(cx, thisObj, name, args, rval); +} + +static inline bool +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval) +{ + return !!JS_CallFunctionValue(cx, thisObj, fun, args, rval); +} + +extern JS_PUBLIC_API(bool) +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval); + +static inline bool +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleObject funObj, const JS::HandleValueArray& args, + MutableHandleValue rval) +{ + JS_ASSERT(funObj); + JS::RootedValue fun(cx, JS::ObjectValue(*funObj)); + return Call(cx, thisv, fun, args, rval); +} + +extern JS_PUBLIC_API(bool) +Construct(JSContext *cx, JS::HandleValue fun, + const JS::HandleValueArray& args, + MutableHandleValue rval); + +} /* namespace JS */ + +/* + * These functions allow setting an interrupt callback that will be called + * from the JS thread some time after any thread triggered the callback using + * JS_RequestInterruptCallback(rt). + * + * To schedule the GC and for other activities the engine internally triggers + * interrupt callbacks. The embedding should thus not rely on callbacks being + * triggered through the external API only. + * + * Important note: Additional callbacks can occur inside the callback handler + * if it re-enters the JS engine. The embedding must ensure that the callback + * is disconnected before attempting such re-entry. + */ +extern JS_PUBLIC_API(JSInterruptCallback) +JS_SetInterruptCallback(JSRuntime *rt, JSInterruptCallback callback); + +extern JS_PUBLIC_API(JSInterruptCallback) +JS_GetInterruptCallback(JSRuntime *rt); + +extern JS_PUBLIC_API(void) +JS_RequestInterruptCallback(JSRuntime *rt); + +extern JS_PUBLIC_API(bool) +JS_IsRunning(JSContext *cx); + +/* + * Saving and restoring frame chains. + * + * These two functions are used to set aside cx's call stack while that stack + * is inactive. After a call to JS_SaveFrameChain, it looks as if there is no + * code running on cx. Before calling JS_RestoreFrameChain, cx's call stack + * must be balanced and all nested calls to JS_SaveFrameChain must have had + * matching JS_RestoreFrameChain calls. + * + * JS_SaveFrameChain deals with cx not having any code running on it. + */ +extern JS_PUBLIC_API(bool) +JS_SaveFrameChain(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_RestoreFrameChain(JSContext *cx); + +#ifdef MOZ_TRACE_JSCALLS +/* + * The callback is expected to be quick and noninvasive. It should not + * request interrupts, turn on debugging, or produce uncaught JS + * exceptions. The state of the stack and registers in the context + * cannot be relied upon, since this callback may be invoked directly + * from either JIT. The 'entering' field means we are entering a + * function if it is positive, leaving a function if it is zero or + * negative. + */ +extern JS_PUBLIC_API(void) +JS_SetFunctionCallback(JSContext *cx, JSFunctionCallback fcb); + +extern JS_PUBLIC_API(JSFunctionCallback) +JS_GetFunctionCallback(JSContext *cx); +#endif /* MOZ_TRACE_JSCALLS */ + +/************************************************************************/ + +/* + * Strings. + * + * NB: JS_NewUCString takes ownership of bytes on success, avoiding a copy; + * but on error (signified by null return), it leaves chars owned by the + * caller. So the caller must free bytes in the error case, if it has no use + * for them. In contrast, all the JS_New*StringCopy* functions do not take + * ownership of the character memory passed to them -- they copy it. + */ +extern JS_PUBLIC_API(JSString *) +JS_NewStringCopyN(JSContext *cx, const char *s, size_t n); + +extern JS_PUBLIC_API(JSString *) +JS_NewStringCopyZ(JSContext *cx, const char *s); + +extern JS_PUBLIC_API(JSString *) +JS_InternJSString(JSContext *cx, JS::HandleString str); + +extern JS_PUBLIC_API(JSString *) +JS_InternStringN(JSContext *cx, const char *s, size_t length); + +extern JS_PUBLIC_API(JSString *) +JS_InternString(JSContext *cx, const char *s); + +extern JS_PUBLIC_API(JSString *) +JS_NewUCString(JSContext *cx, jschar *chars, size_t length); + +extern JS_PUBLIC_API(JSString *) +JS_NewUCStringCopyN(JSContext *cx, const jschar *s, size_t n); + +extern JS_PUBLIC_API(JSString *) +JS_NewUCStringCopyZ(JSContext *cx, const jschar *s); + +extern JS_PUBLIC_API(JSString *) +JS_InternUCStringN(JSContext *cx, const jschar *s, size_t length); + +extern JS_PUBLIC_API(JSString *) +JS_InternUCString(JSContext *cx, const jschar *s); + +extern JS_PUBLIC_API(bool) +JS_CompareStrings(JSContext *cx, JSString *str1, JSString *str2, int32_t *result); + +extern JS_PUBLIC_API(bool) +JS_StringEqualsAscii(JSContext *cx, JSString *str, const char *asciiBytes, bool *match); + +extern JS_PUBLIC_API(size_t) +JS_PutEscapedString(JSContext *cx, char *buffer, size_t size, JSString *str, char quote); + +extern JS_PUBLIC_API(bool) +JS_FileEscapedString(FILE *fp, JSString *str, char quote); + +/* + * Extracting string characters and length. + * + * While getting the length of a string is infallible, getting the chars can + * fail. As indicated by the lack of a JSContext parameter, there are two + * special cases where getting the chars is infallible: + * + * The first case is interned strings, i.e., strings from JS_InternString or + * JSID_TO_STRING(id), using JS_GetLatin1InternedStringChars or + * JS_GetTwoByteInternedStringChars. + * + * The second case is "flat" strings that have been explicitly prepared in a + * fallible context by JS_FlattenString. To catch errors, a separate opaque + * JSFlatString type is returned by JS_FlattenString and expected by + * JS_GetFlatStringChars. Note, though, that this is purely a syntactic + * distinction: the input and output of JS_FlattenString are the same actual + * GC-thing. If a JSString is known to be flat, JS_ASSERT_STRING_IS_FLAT can be + * used to make a debug-checked cast. Example: + * + * // in a fallible context + * JSFlatString *fstr = JS_FlattenString(cx, str); + * if (!fstr) + * return false; + * JS_ASSERT(fstr == JS_ASSERT_STRING_IS_FLAT(str)); + * + * // in an infallible context, for the same 'str' + * AutoCheckCannotGC nogc; + * const jschar *chars = JS_GetTwoByteFlatStringChars(nogc, fstr) + * JS_ASSERT(chars); + * + * Flat strings and interned strings are always null-terminated, so + * JS_FlattenString can be used to get a null-terminated string. + * + * Additionally, string characters are stored as either Latin1Char (8-bit) + * or jschar (16-bit). Clients can use JS_StringHasLatin1Chars and can then + * call either the Latin1* or TwoByte* functions. Some functions like + * JS_CopyStringChars and JS_GetStringCharAt accept both Latin1 and TwoByte + * strings. + */ + +extern JS_PUBLIC_API(size_t) +JS_GetStringLength(JSString *str); + +extern JS_PUBLIC_API(bool) +JS_StringIsFlat(JSString *str); + +/* Returns true iff the string's characters are stored as Latin1. */ +extern JS_PUBLIC_API(bool) +JS_StringHasLatin1Chars(JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1StringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); + +extern JS_PUBLIC_API(const jschar *) +JS_GetTwoByteStringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); + +extern JS_PUBLIC_API(bool) +JS_GetStringCharAt(JSContext *cx, JSString *str, size_t index, jschar *res); + +extern JS_PUBLIC_API(jschar) +JS_GetFlatStringCharAt(JSFlatString *str, size_t index); + +extern JS_PUBLIC_API(const jschar *) +JS_GetTwoByteExternalStringChars(JSString *str); + +extern JS_PUBLIC_API(bool) +JS_CopyStringChars(JSContext *cx, mozilla::Range dest, JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1InternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); + +extern JS_PUBLIC_API(const jschar *) +JS_GetTwoByteInternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); + +extern JS_PUBLIC_API(JSFlatString *) +JS_FlattenString(JSContext *cx, JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1FlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); + +extern JS_PUBLIC_API(const jschar *) +JS_GetTwoByteFlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); + +static MOZ_ALWAYS_INLINE JSFlatString * +JSID_TO_FLAT_STRING(jsid id) +{ + JS_ASSERT(JSID_IS_STRING(id)); + return (JSFlatString *)(JSID_BITS(id)); +} + +static MOZ_ALWAYS_INLINE JSFlatString * +JS_ASSERT_STRING_IS_FLAT(JSString *str) +{ + JS_ASSERT(JS_StringIsFlat(str)); + return (JSFlatString *)str; +} + +static MOZ_ALWAYS_INLINE JSString * +JS_FORGET_STRING_FLATNESS(JSFlatString *fstr) +{ + return (JSString *)fstr; +} + +/* + * Additional APIs that avoid fallibility when given a flat string. + */ + +extern JS_PUBLIC_API(bool) +JS_FlatStringEqualsAscii(JSFlatString *str, const char *asciiBytes); + +extern JS_PUBLIC_API(size_t) +JS_PutEscapedFlatString(char *buffer, size_t size, JSFlatString *str, char quote); + +/* + * Create a dependent string, i.e., a string that owns no character storage, + * but that refers to a slice of another string's chars. Dependent strings + * are mutable by definition, so the thread safety comments above apply. + */ +extern JS_PUBLIC_API(JSString *) +JS_NewDependentString(JSContext *cx, JS::HandleString str, size_t start, + size_t length); + +/* + * Concatenate two strings, possibly resulting in a rope. + * See above for thread safety comments. + */ +extern JS_PUBLIC_API(JSString *) +JS_ConcatStrings(JSContext *cx, JS::HandleString left, JS::HandleString right); + +/* + * For JS_DecodeBytes, set *dstlenp to the size of the destination buffer before + * the call; on return, *dstlenp contains the number of jschars actually stored. + * To determine the necessary destination buffer size, make a sizing call that + * passes nullptr for dst. + * + * On errors, the functions report the error. In that case, *dstlenp contains + * the number of characters or bytes transferred so far. If cx is nullptr, no + * error is reported on failure, and the functions simply return false. + * + * NB: This function does not store an additional zero byte or jschar after the + * transcoded string. + */ +JS_PUBLIC_API(bool) +JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst, + size_t *dstlenp); + +/* + * A variation on JS_EncodeCharacters where a null terminated string is + * returned that you are expected to call JS_free on when done. + */ +JS_PUBLIC_API(char *) +JS_EncodeString(JSContext *cx, JSString *str); + +/* + * Same behavior as JS_EncodeString(), but encode into UTF-8 string + */ +JS_PUBLIC_API(char *) +JS_EncodeStringToUTF8(JSContext *cx, JS::HandleString str); + +/* + * Get number of bytes in the string encoding (without accounting for a + * terminating zero bytes. The function returns (size_t) -1 if the string + * can not be encoded into bytes and reports an error using cx accordingly. + */ +JS_PUBLIC_API(size_t) +JS_GetStringEncodingLength(JSContext *cx, JSString *str); + +/* + * Encode string into a buffer. The function does not stores an additional + * zero byte. The function returns (size_t) -1 if the string can not be + * encoded into bytes with no error reported. Otherwise it returns the number + * of bytes that are necessary to encode the string. If that exceeds the + * length parameter, the string will be cut and only length bytes will be + * written into the buffer. + */ +JS_PUBLIC_API(size_t) +JS_EncodeStringToBuffer(JSContext *cx, JSString *str, char *buffer, size_t length); + +class JSAutoByteString +{ + public: + JSAutoByteString(JSContext *cx, JSString *str + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mBytes(JS_EncodeString(cx, str)) + { + JS_ASSERT(cx); + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + explicit JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + : mBytes(nullptr) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + ~JSAutoByteString() { + js_free(mBytes); + } + + /* Take ownership of the given byte array. */ + void initBytes(char *bytes) { + JS_ASSERT(!mBytes); + mBytes = bytes; + } + + char *encodeLatin1(JSContext *cx, JSString *str) { + JS_ASSERT(!mBytes); + JS_ASSERT(cx); + mBytes = JS_EncodeString(cx, str); + return mBytes; + } + + char *encodeLatin1(js::ExclusiveContext *cx, JSString *str); + + char *encodeUtf8(JSContext *cx, JS::HandleString str) { + JS_ASSERT(!mBytes); + JS_ASSERT(cx); + mBytes = JS_EncodeStringToUTF8(cx, str); + return mBytes; + } + + void clear() { + js_free(mBytes); + mBytes = nullptr; + } + + char *ptr() const { + return mBytes; + } + + bool operator!() const { + return !mBytes; + } + + size_t length() const { + if (!mBytes) + return 0; + return strlen(mBytes); + } + + private: + char *mBytes; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + /* Copy and assignment are not supported. */ + JSAutoByteString(const JSAutoByteString &another); + JSAutoByteString &operator=(const JSAutoByteString &another); +}; + +namespace JS { + +extern JS_PUBLIC_API(JSAddonId *) +NewAddonId(JSContext *cx, JS::HandleString str); + +extern JS_PUBLIC_API(JSString *) +StringOfAddonId(JSAddonId *id); + +extern JS_PUBLIC_API(JSAddonId *) +AddonIdOfObject(JSObject *obj); + +} // namespace JS + +/************************************************************************/ +/* + * Symbols + */ + +namespace JS { + +/* + * Create a new Symbol with the given description. This function never returns + * a Symbol that is in the Runtime-wide symbol registry. + * + * If description is null, the new Symbol's [[Description]] attribute is + * undefined. + */ +JS_PUBLIC_API(Symbol *) +NewSymbol(JSContext *cx, HandleString description); + +/* + * Symbol.for as specified in ES6. + * + * Get a Symbol with the description 'key' from the Runtime-wide symbol registry. + * If there is not already a Symbol with that description in the registry, a new + * Symbol is created and registered. 'key' must not be null. + */ +JS_PUBLIC_API(Symbol *) +GetSymbolFor(JSContext *cx, HandleString key); + +/* + * Get the [[Description]] attribute of the given symbol. + * + * This function is infallible. If it returns null, that means the symbol's + * [[Description]] is undefined. + */ +JS_PUBLIC_API(JSString *) +GetSymbolDescription(HandleSymbol symbol); + +/* Well-known symbols. */ +MOZ_BEGIN_ENUM_CLASS(SymbolCode, uint32_t) + iterator, // well-known Symbol.iterator + InSymbolRegistry = 0xfffffffe, // created by Symbol.for() or JS::GetSymbolFor() + UniqueSymbol = 0xffffffff // created by Symbol() or JS::NewSymbol() +MOZ_END_ENUM_CLASS(SymbolCode) + +/* For use in loops that iterate over the well-known symbols. */ +const size_t WellKnownSymbolLimit = 1; + +/* + * Return the SymbolCode telling what sort of symbol `symbol` is. + * + * A symbol's SymbolCode never changes once it is created. + */ +JS_PUBLIC_API(SymbolCode) +GetSymbolCode(Handle symbol); + +/* + * Get one of the well-known symbols defined by ES6. A single set of well-known + * symbols is shared by all compartments in a JSRuntime. + * + * `which` must be in the range [0, WellKnownSymbolLimit). + */ +JS_PUBLIC_API(Symbol *) +GetWellKnownSymbol(JSContext *cx, SymbolCode which); + +} /* namespace JS */ + +/************************************************************************/ +/* + * JSON functions + */ +typedef bool (* JSONWriteCallback)(const jschar *buf, uint32_t len, void *data); + +/* + * JSON.stringify as specified by ES5. + */ +JS_PUBLIC_API(bool) +JS_Stringify(JSContext *cx, JS::MutableHandleValue value, JS::HandleObject replacer, + JS::HandleValue space, JSONWriteCallback callback, void *data); + +/* + * JSON.parse as specified by ES5. + */ +JS_PUBLIC_API(bool) +JS_ParseJSON(JSContext *cx, const jschar *chars, uint32_t len, JS::MutableHandleValue vp); + +JS_PUBLIC_API(bool) +JS_ParseJSON(JSContext *cx, JS::HandleString str, JS::MutableHandleValue vp); + +JS_PUBLIC_API(bool) +JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32_t len, JS::HandleValue reviver, + JS::MutableHandleValue vp); + +JS_PUBLIC_API(bool) +JS_ParseJSONWithReviver(JSContext *cx, JS::HandleString str, JS::HandleValue reviver, + JS::MutableHandleValue vp); + +/************************************************************************/ + +/* + * The default locale for the ECMAScript Internationalization API + * (Intl.Collator, Intl.NumberFormat, Intl.DateTimeFormat). + * Note that the Internationalization API encourages clients to + * specify their own locales. + * The locale string remains owned by the caller. + */ +extern JS_PUBLIC_API(bool) +JS_SetDefaultLocale(JSRuntime *rt, const char *locale); + +/* + * Reset the default locale to OS defaults. + */ +extern JS_PUBLIC_API(void) +JS_ResetDefaultLocale(JSRuntime *rt); + +/* + * Locale specific string conversion and error message callbacks. + */ +struct JSLocaleCallbacks { + JSLocaleToUpperCase localeToUpperCase; + JSLocaleToLowerCase localeToLowerCase; + JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API + JSLocaleToUnicode localeToUnicode; +}; + +/* + * Establish locale callbacks. The pointer must persist as long as the + * JSRuntime. Passing nullptr restores the default behaviour. + */ +extern JS_PUBLIC_API(void) +JS_SetLocaleCallbacks(JSRuntime *rt, JSLocaleCallbacks *callbacks); + +/* + * Return the address of the current locale callbacks struct, which may + * be nullptr. + */ +extern JS_PUBLIC_API(JSLocaleCallbacks *) +JS_GetLocaleCallbacks(JSRuntime *rt); + +/************************************************************************/ + +/* + * Error reporting. + */ + +/* + * Report an exception represented by the sprintf-like conversion of format + * and its arguments. This exception message string is passed to a pre-set + * JSErrorReporter function (set by JS_SetErrorReporter). + */ +extern JS_PUBLIC_API(void) +JS_ReportError(JSContext *cx, const char *format, ...); + +/* + * Use an errorNumber to retrieve the format string, args are char * + */ +extern JS_PUBLIC_API(void) +JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback, + void *userRef, const unsigned errorNumber, ...); + +#ifdef va_start +extern JS_PUBLIC_API(void) +JS_ReportErrorNumberVA(JSContext *cx, JSErrorCallback errorCallback, + void *userRef, const unsigned errorNumber, va_list ap); +#endif + +/* + * Use an errorNumber to retrieve the format string, args are jschar * + */ +extern JS_PUBLIC_API(void) +JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback, + void *userRef, const unsigned errorNumber, ...); + +extern JS_PUBLIC_API(void) +JS_ReportErrorNumberUCArray(JSContext *cx, JSErrorCallback errorCallback, + void *userRef, const unsigned errorNumber, + const jschar **args); + +/* + * As above, but report a warning instead (JSREPORT_IS_WARNING(report.flags)). + * Return true if there was no error trying to issue the warning, and if the + * warning was not converted into an error due to the JSOPTION_WERROR option + * being set, false otherwise. + */ +extern JS_PUBLIC_API(bool) +JS_ReportWarning(JSContext *cx, const char *format, ...); + +extern JS_PUBLIC_API(bool) +JS_ReportErrorFlagsAndNumber(JSContext *cx, unsigned flags, + JSErrorCallback errorCallback, void *userRef, + const unsigned errorNumber, ...); + +extern JS_PUBLIC_API(bool) +JS_ReportErrorFlagsAndNumberUC(JSContext *cx, unsigned flags, + JSErrorCallback errorCallback, void *userRef, + const unsigned errorNumber, ...); + +/* + * Complain when out of memory. + */ +extern JS_PUBLIC_API(void) +JS_ReportOutOfMemory(JSContext *cx); + +/* + * Complain when an allocation size overflows the maximum supported limit. + */ +extern JS_PUBLIC_API(void) +JS_ReportAllocationOverflow(JSContext *cx); + +struct JSErrorReport { + const char *filename; /* source file name, URL, etc., or null */ + JSPrincipals *originPrincipals; /* see 'originPrincipals' comment above */ + unsigned lineno; /* source line number */ + const char *linebuf; /* offending source line without final \n */ + const char *tokenptr; /* pointer to error token in linebuf */ + const jschar *uclinebuf; /* unicode (original) line buffer */ + const jschar *uctokenptr; /* unicode (original) token pointer */ + unsigned flags; /* error/warning, etc. */ + unsigned errorNumber; /* the error number, e.g. see js.msg */ + const jschar *ucmessage; /* the (default) error message */ + const jschar **messageArgs; /* arguments for the error message */ + int16_t exnType; /* One of the JSExnType constants */ + unsigned column; /* zero-based column index in line */ +}; + +/* + * JSErrorReport flag values. These may be freely composed. + */ +#define JSREPORT_ERROR 0x0 /* pseudo-flag for default case */ +#define JSREPORT_WARNING 0x1 /* reported via JS_ReportWarning */ +#define JSREPORT_EXCEPTION 0x2 /* exception was thrown */ +#define JSREPORT_STRICT 0x4 /* error or warning due to strict option */ + +/* + * This condition is an error in strict mode code, a warning if + * JS_HAS_STRICT_OPTION(cx), and otherwise should not be reported at + * all. We check the strictness of the context's top frame's script; + * where that isn't appropriate, the caller should do the right checks + * itself instead of using this flag. + */ +#define JSREPORT_STRICT_MODE_ERROR 0x8 + +/* + * If JSREPORT_EXCEPTION is set, then a JavaScript-catchable exception + * has been thrown for this runtime error, and the host should ignore it. + * Exception-aware hosts should also check for JS_IsExceptionPending if + * JS_ExecuteScript returns failure, and signal or propagate the exception, as + * appropriate. + */ +#define JSREPORT_IS_WARNING(flags) (((flags) & JSREPORT_WARNING) != 0) +#define JSREPORT_IS_EXCEPTION(flags) (((flags) & JSREPORT_EXCEPTION) != 0) +#define JSREPORT_IS_STRICT(flags) (((flags) & JSREPORT_STRICT) != 0) +#define JSREPORT_IS_STRICT_MODE_ERROR(flags) (((flags) & \ + JSREPORT_STRICT_MODE_ERROR) != 0) +extern JS_PUBLIC_API(JSErrorReporter) +JS_GetErrorReporter(JSContext *cx); + +extern JS_PUBLIC_API(JSErrorReporter) +JS_SetErrorReporter(JSContext *cx, JSErrorReporter er); + +namespace JS { + +extern JS_PUBLIC_API(bool) +CreateError(JSContext *cx, JSExnType type, HandleString stack, + HandleString fileName, uint32_t lineNumber, uint32_t columnNumber, + JSErrorReport *report, HandleString message, MutableHandleValue rval); + +/************************************************************************/ + +/* + * Weak Maps. + */ + +extern JS_PUBLIC_API(JSObject *) +NewWeakMapObject(JSContext *cx); + +extern JS_PUBLIC_API(bool) +IsWeakMapObject(JSObject *obj); + +extern JS_PUBLIC_API(bool) +GetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::MutableHandleValue val); + +extern JS_PUBLIC_API(bool) +SetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::HandleValue val); + +} /* namespace JS */ + +/* + * Dates. + */ + +extern JS_PUBLIC_API(JSObject *) +JS_NewDateObject(JSContext *cx, int year, int mon, int mday, int hour, int min, int sec); + +extern JS_PUBLIC_API(JSObject *) +JS_NewDateObjectMsec(JSContext *cx, double msec); + +/* + * Infallible predicate to test whether obj is a date object. + */ +extern JS_PUBLIC_API(bool) +JS_ObjectIsDate(JSContext *cx, JS::HandleObject obj); + +/* + * Clears the cache of calculated local time from each Date object. + * Call to propagate a system timezone change. + */ +extern JS_PUBLIC_API(void) +JS_ClearDateCaches(JSContext *cx); + +/************************************************************************/ + +/* + * Regular Expressions. + */ +#define JSREG_FOLD 0x01u /* fold uppercase to lowercase */ +#define JSREG_GLOB 0x02u /* global exec, creates array of matches */ +#define JSREG_MULTILINE 0x04u /* treat ^ and $ as begin and end of line */ +#define JSREG_STICKY 0x08u /* only match starting at lastIndex */ + +extern JS_PUBLIC_API(JSObject *) +JS_NewRegExpObject(JSContext *cx, JS::HandleObject obj, char *bytes, size_t length, + unsigned flags); + +extern JS_PUBLIC_API(JSObject *) +JS_NewUCRegExpObject(JSContext *cx, JS::HandleObject obj, jschar *chars, size_t length, + unsigned flags); + +extern JS_PUBLIC_API(bool) +JS_SetRegExpInput(JSContext *cx, JS::HandleObject obj, JS::HandleString input, + bool multiline); + +extern JS_PUBLIC_API(bool) +JS_ClearRegExpStatics(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(bool) +JS_ExecuteRegExp(JSContext *cx, JS::HandleObject obj, JS::HandleObject reobj, + jschar *chars, size_t length, size_t *indexp, bool test, + JS::MutableHandleValue rval); + +/* RegExp interface for clients without a global object. */ + +extern JS_PUBLIC_API(JSObject *) +JS_NewRegExpObjectNoStatics(JSContext *cx, char *bytes, size_t length, unsigned flags); + +extern JS_PUBLIC_API(JSObject *) +JS_NewUCRegExpObjectNoStatics(JSContext *cx, jschar *chars, size_t length, unsigned flags); + +extern JS_PUBLIC_API(bool) +JS_ExecuteRegExpNoStatics(JSContext *cx, JS::HandleObject reobj, jschar *chars, size_t length, + size_t *indexp, bool test, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_ObjectIsRegExp(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(unsigned) +JS_GetRegExpFlags(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(JSString *) +JS_GetRegExpSource(JSContext *cx, JS::HandleObject obj); + +/************************************************************************/ + +extern JS_PUBLIC_API(bool) +JS_IsExceptionPending(JSContext *cx); + +extern JS_PUBLIC_API(bool) +JS_GetPendingException(JSContext *cx, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(void) +JS_SetPendingException(JSContext *cx, JS::HandleValue v); + +extern JS_PUBLIC_API(void) +JS_ClearPendingException(JSContext *cx); + +extern JS_PUBLIC_API(bool) +JS_ReportPendingException(JSContext *cx); + +namespace JS { + +/* + * Save and later restore the current exception state of a given JSContext. + * This is useful for implementing behavior in C++ that's like try/catch + * or try/finally in JS. + * + * Typical usage: + * + * bool ok = JS_EvaluateScript(cx, ...); + * AutoSaveExceptionState savedExc(cx); + * ... cleanup that might re-enter JS ... + * return ok; + */ +class JS_PUBLIC_API(AutoSaveExceptionState) +{ + private: + JSContext *context; + bool wasPropagatingForcedReturn; + bool wasThrowing; + RootedValue exceptionValue; + + public: + /* + * Take a snapshot of cx's current exception state. Then clear any current + * pending exception in cx. + */ + explicit AutoSaveExceptionState(JSContext *cx); + + /* + * If neither drop() nor restore() was called, restore the exception + * state only if no exception is currently pending on cx. + */ + ~AutoSaveExceptionState(); + + /* + * Discard any stored exception state. + * If this is called, the destructor is a no-op. + */ + void drop() { + wasPropagatingForcedReturn = false; + wasThrowing = false; + exceptionValue.setUndefined(); + } + + /* + * Replace cx's exception state with the stored exception state. Then + * discard the stored exception state. If this is called, the + * destructor is a no-op. + */ + void restore(); +}; + +} /* namespace JS */ + +/* Deprecated API. Use AutoSaveExceptionState instead. */ +extern JS_PUBLIC_API(JSExceptionState *) +JS_SaveExceptionState(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_RestoreExceptionState(JSContext *cx, JSExceptionState *state); + +extern JS_PUBLIC_API(void) +JS_DropExceptionState(JSContext *cx, JSExceptionState *state); + +/* + * If the given object is an exception object, the exception will have (or be + * able to lazily create) an error report struct, and this function will return + * the address of that struct. Otherwise, it returns nullptr. The lifetime + * of the error report struct that might be returned is the same as the + * lifetime of the exception object. + */ +extern JS_PUBLIC_API(JSErrorReport *) +JS_ErrorFromException(JSContext *cx, JS::HandleObject obj); + +/* + * Throws a StopIteration exception on cx. + */ +extern JS_PUBLIC_API(bool) +JS_ThrowStopIteration(JSContext *cx); + +extern JS_PUBLIC_API(bool) +JS_IsStopIteration(jsval v); + +extern JS_PUBLIC_API(intptr_t) +JS_GetCurrentThread(); + +/* + * A JS runtime always has an "owner thread". The owner thread is set when the + * runtime is created (to the current thread) and practically all entry points + * into the JS engine check that a runtime (or anything contained in the + * runtime: context, compartment, object, etc) is only touched by its owner + * thread. Embeddings may check this invariant outside the JS engine by calling + * JS_AbortIfWrongThread (which will abort if not on the owner thread, even for + * non-debug builds). + */ + +extern JS_PUBLIC_API(void) +JS_AbortIfWrongThread(JSRuntime *rt); + +/************************************************************************/ + +/* + * A constructor can request that the JS engine create a default new 'this' + * object of the given class, using the callee to determine parentage and + * [[Prototype]]. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const JS::CallArgs& args); + +/************************************************************************/ + +#ifdef JS_GC_ZEAL +#define JS_DEFAULT_ZEAL_FREQ 100 + +extern JS_PUBLIC_API(void) +JS_SetGCZeal(JSContext *cx, uint8_t zeal, uint32_t frequency); + +extern JS_PUBLIC_API(void) +JS_ScheduleGC(JSContext *cx, uint32_t count); +#endif + +extern JS_PUBLIC_API(void) +JS_SetParallelParsingEnabled(JSRuntime *rt, bool enabled); + +extern JS_PUBLIC_API(void) +JS_SetOffthreadIonCompilationEnabled(JSRuntime *rt, bool enabled); + +#define JIT_COMPILER_OPTIONS(Register) \ + Register(BASELINE_USECOUNT_TRIGGER, "baseline.usecount.trigger") \ + Register(ION_USECOUNT_TRIGGER, "ion.usecount.trigger") \ + Register(ION_ENABLE, "ion.enable") \ + Register(BASELINE_ENABLE, "baseline.enable") \ + Register(OFFTHREAD_COMPILATION_ENABLE, "offthread-compilation.enable") \ + Register(SIGNALS_ENABLE, "signals.enable") + +typedef enum JSJitCompilerOption { +#define JIT_COMPILER_DECLARE(key, str) \ + JSJITCOMPILER_ ## key, + + JIT_COMPILER_OPTIONS(JIT_COMPILER_DECLARE) +#undef JIT_COMPILER_DECLARE + + JSJITCOMPILER_NOT_AN_OPTION +} JSJitCompilerOption; + +extern JS_PUBLIC_API(void) +JS_SetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt, uint32_t value); +extern JS_PUBLIC_API(int) +JS_GetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt); + +/* + * Convert a uint32_t index into a jsid. + */ +extern JS_PUBLIC_API(bool) +JS_IndexToId(JSContext *cx, uint32_t index, JS::MutableHandleId); + +/* + * Convert chars into a jsid. + * + * |chars| may not be an index. + */ +extern JS_PUBLIC_API(bool) +JS_CharsToId(JSContext* cx, JS::TwoByteChars chars, JS::MutableHandleId); + +/* + * Test if the given string is a valid ECMAScript identifier + */ +extern JS_PUBLIC_API(bool) +JS_IsIdentifier(JSContext *cx, JS::HandleString str, bool *isIdentifier); + +namespace JS { + +/* + * AutoFilename encapsulates a pointer to a C-string and keeps the C-string + * alive for as long as the associated AutoFilename object is alive. + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(AutoFilename) +{ + void *scriptSource_; + + AutoFilename(const AutoFilename &) MOZ_DELETE; + void operator=(const AutoFilename &) MOZ_DELETE; + + public: + AutoFilename() : scriptSource_(nullptr) {} + ~AutoFilename() { reset(nullptr); } + + const char *get() const; + + void reset(void *newScriptSource); +}; + +/* + * Return the current filename and line number of the most currently running + * frame. Returns true if a scripted frame was found, false otherwise. + * + * If a the embedding has hidden the scripted caller for the topmost activation + * record, this will also return false. + */ +extern JS_PUBLIC_API(bool) +DescribeScriptedCaller(JSContext *cx, AutoFilename *filename = nullptr, + unsigned *lineno = nullptr); + +extern JS_PUBLIC_API(JSObject *) +GetScriptedCallerGlobal(JSContext *cx); + +/* + * Informs the JS engine that the scripted caller should be hidden. This can be + * used by the embedding to maintain an override of the scripted caller in its + * calculations, by hiding the scripted caller in the JS engine and pushing data + * onto a separate stack, which it inspects when DescribeScriptedCaller returns + * null. + * + * We maintain a counter on each activation record. Add() increments the counter + * of the topmost activation, and Remove() decrements it. The count may never + * drop below zero, and must always be exactly zero when the activation is + * popped from the stack. + */ +extern JS_PUBLIC_API(void) +HideScriptedCaller(JSContext *cx); + +extern JS_PUBLIC_API(void) +UnhideScriptedCaller(JSContext *cx); + +class AutoHideScriptedCaller +{ + public: + explicit AutoHideScriptedCaller(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mContext(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + HideScriptedCaller(mContext); + } + ~AutoHideScriptedCaller() { + UnhideScriptedCaller(mContext); + } + + protected: + JSContext *mContext; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +} /* namespace JS */ + +/* + * Encode/Decode interpreted scripts and functions to/from memory. + */ + +extern JS_PUBLIC_API(void *) +JS_EncodeScript(JSContext *cx, JS::HandleScript script, uint32_t *lengthp); + +extern JS_PUBLIC_API(void *) +JS_EncodeInterpretedFunction(JSContext *cx, JS::HandleObject funobj, uint32_t *lengthp); + +extern JS_PUBLIC_API(JSScript *) +JS_DecodeScript(JSContext *cx, const void *data, uint32_t length, JSPrincipals *originPrincipals); + +extern JS_PUBLIC_API(JSObject *) +JS_DecodeInterpretedFunction(JSContext *cx, const void *data, uint32_t length, + JSPrincipals *originPrincipals); + +namespace JS { + +/* + * This callback represents a request by the JS engine to open for reading the + * existing cache entry for the given global and char range that may contain a + * module. If a cache entry exists, the callback shall return 'true' and return + * the size, base address and an opaque file handle as outparams. If the + * callback returns 'true', the JS engine guarantees a call to + * CloseAsmJSCacheEntryForReadOp, passing the same base address, size and + * handle. + */ +typedef bool +(* OpenAsmJSCacheEntryForReadOp)(HandleObject global, const jschar *begin, const jschar *limit, + size_t *size, const uint8_t **memory, intptr_t *handle); +typedef void +(* CloseAsmJSCacheEntryForReadOp)(size_t size, const uint8_t *memory, intptr_t handle); + +/* + * This callback represents a request by the JS engine to open for writing a + * cache entry of the given size for the given global and char range containing + * the just-compiled module. If cache entry space is available, the callback + * shall return 'true' and return the base address and an opaque file handle as + * outparams. If the callback returns 'true', the JS engine guarantees a call + * to CloseAsmJSCacheEntryForWriteOp passing the same base address, size and + * handle. + * + * If 'installed' is true, then the cache entry is associated with a permanently + * installed JS file (e.g., in a packaged webapp). This information allows the + * embedding to store the cache entry in a installed location associated with + * the principal of 'global' where it will not be evicted until the associated + * installed JS file is removed. + */ +typedef bool +(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, bool installed, + const jschar *begin, const jschar *end, + size_t size, uint8_t **memory, intptr_t *handle); +typedef void +(* CloseAsmJSCacheEntryForWriteOp)(size_t size, uint8_t *memory, intptr_t handle); + +typedef js::Vector BuildIdCharVector; + +// Return the buildId (represented as a sequence of characters) associated with +// the currently-executing build. If the JS engine is embedded such that a +// single cache entry can be observed by different compiled versions of the JS +// engine, it is critical that the buildId shall change for each new build of +// the JS engine. + +typedef bool +(* BuildIdOp)(BuildIdCharVector *buildId); + +struct AsmJSCacheOps +{ + OpenAsmJSCacheEntryForReadOp openEntryForRead; + CloseAsmJSCacheEntryForReadOp closeEntryForRead; + OpenAsmJSCacheEntryForWriteOp openEntryForWrite; + CloseAsmJSCacheEntryForWriteOp closeEntryForWrite; + BuildIdOp buildId; +}; + +extern JS_PUBLIC_API(void) +SetAsmJSCacheOps(JSRuntime *rt, const AsmJSCacheOps *callbacks); + +/* + * Convenience class for imitating a JS level for-of loop. Typical usage: + * + * ForOfIterator it(cx); + * if (!it.init(iterable)) + * return false; + * RootedValue val(cx); + * while (true) { + * bool done; + * if (!it.next(&val, &done)) + * return false; + * if (done) + * break; + * if (!DoStuff(cx, val)) + * return false; + * } + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(ForOfIterator) { + protected: + JSContext *cx_; + /* + * Use the ForOfPIC on the global object (see vm/GlobalObject.h) to try + * to optimize iteration across arrays. + * + * Case 1: Regular Iteration + * iterator - pointer to the iterator object. + * index - fixed to NOT_ARRAY (== UINT32_MAX) + * + * Case 2: Optimized Array Iteration + * iterator - pointer to the array object. + * index - current position in array. + * + * The cases are distinguished by whether or not |index| is equal to NOT_ARRAY. + */ + JS::RootedObject iterator; + uint32_t index; + + static const uint32_t NOT_ARRAY = UINT32_MAX; + + ForOfIterator(const ForOfIterator &) MOZ_DELETE; + ForOfIterator &operator=(const ForOfIterator &) MOZ_DELETE; + + public: + explicit ForOfIterator(JSContext *cx) : cx_(cx), iterator(cx_), index(NOT_ARRAY) { } + + enum NonIterableBehavior { + ThrowOnNonIterable, + AllowNonIterable + }; + + /* + * Initialize the iterator. If AllowNonIterable is passed then if iterable + * does not have a callable @@iterator init() will just return true instead + * of throwing. Callers should then check valueIsIterable() before + * continuing with the iteration. + */ + bool init(JS::HandleValue iterable, + NonIterableBehavior nonIterableBehavior = ThrowOnNonIterable); + + /* + * This method assumes that |iterator| is already an iterator. It will not + * check for, and call @@iterator. Callers should make sure that the passed + * in value is in fact an iterator. + */ + bool initWithIterator(JS::HandleValue aIterator); + + /* + * Get the next value from the iterator. If false *done is true + * after this call, do not examine val. + */ + bool next(JS::MutableHandleValue val, bool *done); + + /* + * If initialized with throwOnNonCallable = false, check whether + * the value is iterable. + */ + bool valueIsIterable() const { + return iterator; + } + + private: + inline bool nextFromOptimizedArray(MutableHandleValue val, bool *done); + bool materializeArrayIterator(); +}; + + +/* + * If a large allocation fails, the JS engine may call the large-allocation- + * failure callback, if set, to allow the embedding to flush caches, possibly + * perform shrinking GCs, etc. to make some room so that the allocation will + * succeed if retried. After the callback returns, the JS engine will try to + * allocate again and may be succesful. + */ + +typedef void +(* LargeAllocationFailureCallback)(void *data); + +extern JS_PUBLIC_API(void) +SetLargeAllocationFailureCallback(JSRuntime *rt, LargeAllocationFailureCallback afc, void *data); + +/* + * Unlike the error reporter, which is only called if the exception for an OOM + * bubbles up and is not caught, the OutOfMemoryCallback is called immediately + * at the OOM site to allow the embedding to capture the current state of heap + * allocation before anything is freed. If the large-allocation-failure callback + * is called at all (not all allocation sites call the large-allocation-failure + * callback on failure), it is called before the out-of-memory callback; the + * out-of-memory callback is only called if the allocation still fails after the + * large-allocation-failure callback has returned. + */ + +typedef void +(* OutOfMemoryCallback)(JSContext *cx, void *data); + +extern JS_PUBLIC_API(void) +SetOutOfMemoryCallback(JSRuntime *rt, OutOfMemoryCallback cb, void *data); + + +/* + * Capture the current call stack as a chain of SavedFrame objects, and set + * |stackp| to the SavedFrame for the newest stack frame. If |maxFrameCount| is + * non-zero, capture at most the youngest |maxFrameCount| frames. + */ +extern JS_PUBLIC_API(bool) +CaptureCurrentStack(JSContext *cx, MutableHandleObject stackp, unsigned maxFrameCount = 0); + +} /* namespace JS */ + +#endif /* jsapi_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/jsbytecode.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsbytecode.h new file mode 100644 index 0000000000..8e4f4cf90b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsbytecode.h @@ -0,0 +1,14 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsbytecode_h +#define jsbytecode_h + +#include + +typedef uint8_t jsbytecode; + +#endif /* jsbytecode_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/jsclist.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsclist.h new file mode 100644 index 0000000000..23da9b8cd5 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsclist.h @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsclist_h +#define jsclist_h + +#include "jstypes.h" + +/* +** Circular linked list +*/ +typedef struct JSCListStr { + struct JSCListStr *next; + struct JSCListStr *prev; +} JSCList; + +/* +** Insert element "_e" into the list, before "_l". +*/ +#define JS_INSERT_BEFORE(_e,_l) \ + JS_BEGIN_MACRO \ + (_e)->next = (_l); \ + (_e)->prev = (_l)->prev; \ + (_l)->prev->next = (_e); \ + (_l)->prev = (_e); \ + JS_END_MACRO + +/* +** Insert element "_e" into the list, after "_l". +*/ +#define JS_INSERT_AFTER(_e,_l) \ + JS_BEGIN_MACRO \ + (_e)->next = (_l)->next; \ + (_e)->prev = (_l); \ + (_l)->next->prev = (_e); \ + (_l)->next = (_e); \ + JS_END_MACRO + +/* +** Return the element following element "_e" +*/ +#define JS_NEXT_LINK(_e) \ + ((_e)->next) +/* +** Return the element preceding element "_e" +*/ +#define JS_PREV_LINK(_e) \ + ((_e)->prev) + +/* +** Append an element "_e" to the end of the list "_l" +*/ +#define JS_APPEND_LINK(_e,_l) JS_INSERT_BEFORE(_e,_l) + +/* +** Insert an element "_e" at the head of the list "_l" +*/ +#define JS_INSERT_LINK(_e,_l) JS_INSERT_AFTER(_e,_l) + +/* Return the head/tail of the list */ +#define JS_LIST_HEAD(_l) (_l)->next +#define JS_LIST_TAIL(_l) (_l)->prev + +/* +** Remove the element "_e" from it's circular list. +*/ +#define JS_REMOVE_LINK(_e) \ + JS_BEGIN_MACRO \ + (_e)->prev->next = (_e)->next; \ + (_e)->next->prev = (_e)->prev; \ + JS_END_MACRO + +/* +** Remove the element "_e" from it's circular list. Also initializes the +** linkage. +*/ +#define JS_REMOVE_AND_INIT_LINK(_e) \ + JS_BEGIN_MACRO \ + (_e)->prev->next = (_e)->next; \ + (_e)->next->prev = (_e)->prev; \ + (_e)->next = (_e); \ + (_e)->prev = (_e); \ + JS_END_MACRO + +/* +** Return non-zero if the given circular list "_l" is empty, zero if the +** circular list is not empty +*/ +#define JS_CLIST_IS_EMPTY(_l) \ + ((_l)->next == (_l)) + +/* +** Initialize a circular list +*/ +#define JS_INIT_CLIST(_l) \ + JS_BEGIN_MACRO \ + (_l)->next = (_l); \ + (_l)->prev = (_l); \ + JS_END_MACRO + +#define JS_INIT_STATIC_CLIST(_l) \ + {(_l), (_l)} + +#endif /* jsclist_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/jscpucfg.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/jscpucfg.h new file mode 100644 index 0000000000..a7a00613bb --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/jscpucfg.h @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jscpucfg_h +#define jscpucfg_h + +#define JS_HAVE_LONG_LONG + +#if defined(_WIN64) + +# if defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_) +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# else /* !(defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)) */ +# error "CPU type is unknown" +# endif /* !(defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)) */ + +#elif defined(_WIN32) + +# ifdef __WATCOMC__ +# define HAVE_VA_LIST_AS_ARRAY 1 +# endif + +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN + +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) +# if __LITTLE_ENDIAN__ +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# elif __BIG_ENDIAN__ +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 +# endif + +#elif defined(JS_HAVE_ENDIAN_H) +# include + +# if defined(__BYTE_ORDER) +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# elif __BYTE_ORDER == __BIG_ENDIAN +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 +# endif +# else /* !defined(__BYTE_ORDER) */ +# error "endian.h does not define __BYTE_ORDER. Cannot determine endianness." +# endif + +/* BSDs */ +#elif defined(JS_HAVE_MACHINE_ENDIAN_H) +# include +# include + +# if defined(_BYTE_ORDER) +# if _BYTE_ORDER == _LITTLE_ENDIAN +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# elif _BYTE_ORDER == _BIG_ENDIAN +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 +# endif +# else /* !defined(_BYTE_ORDER) */ +# error "machine/endian.h does not define _BYTE_ORDER. Cannot determine endianness." +# endif + +#elif defined(JS_HAVE_SYS_ISA_DEFS_H) +# include + +# if defined(_BIG_ENDIAN) +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 +# elif defined(_LITTLE_ENDIAN) +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# else /* !defined(_LITTLE_ENDIAN) */ +# error "sys/isa_defs.h does not define _BIG_ENDIAN or _LITTLE_ENDIAN. Cannot determine endianness." +# endif +# if !defined(JS_STACK_GROWTH_DIRECTION) +# if defined(_STACK_GROWS_UPWARD) +# define JS_STACK_GROWTH_DIRECTION (1) +# elif defined(_STACK_GROWS_DOWNWARD) +# define JS_STACK_GROWTH_DIRECTION (-1) +# endif +# endif + +#elif defined(__sparc) || defined(__sparc__) || \ + defined(_POWER) || defined(__hppa) || \ + defined(_MIPSEB) || defined(_BIG_ENDIAN) +/* IA64 running HP-UX will have _BIG_ENDIAN defined. + * IA64 running Linux will have endian.h and be handled above. + */ +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 + +#else /* !defined(__sparc) && !defined(__sparc__) && ... */ +# error "Cannot determine endianness of your platform. Please add support to jscpucfg.h." +#endif + +#ifndef JS_STACK_GROWTH_DIRECTION +# ifdef __hppa +# define JS_STACK_GROWTH_DIRECTION (1) +# else +# define JS_STACK_GROWTH_DIRECTION (-1) +# endif +#endif + +#endif /* jscpucfg_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/jsfriendapi.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsfriendapi.h new file mode 100644 index 0000000000..674999eb62 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsfriendapi.h @@ -0,0 +1,2561 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsfriendapi_h +#define jsfriendapi_h + +#include "mozilla/Casting.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/TypedEnum.h" +#include "mozilla/UniquePtr.h" + +#include "jsapi.h" // For JSAutoByteString. See bug 1033916. +#include "jsbytecode.h" +#include "jspubtd.h" + +#include "js/CallArgs.h" +#include "js/CallNonGenericMethod.h" +#include "js/Class.h" + +/* + * This macro checks if the stack pointer has exceeded a given limit. If + * |tolerance| is non-zero, it returns true only if the stack pointer has + * exceeded the limit by more than |tolerance| bytes. The WITH_INTOLERANCE + * versions use a negative tolerance (i.e., the limit is reduced by + * |intolerance| bytes). + */ +#if JS_STACK_GROWTH_DIRECTION > 0 +# define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ + ((uintptr_t)(sp) < (limit)+(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) < (limit)-(intolerance)) +#else +# define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ + ((uintptr_t)(sp) > (limit)-(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) > (limit)+(intolerance)) +#endif + +#define JS_CHECK_STACK_SIZE(limit, lval) JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, lval, 0) + +class JSAtom; +struct JSErrorFormatString; +class JSLinearString; +struct JSJitInfo; +struct JSErrorReport; + +namespace JS { +template +class Heap; +} /* namespace JS */ + +namespace js { +class JS_FRIEND_API(BaseProxyHandler); +} /* namespace js */ + +extern JS_FRIEND_API(void) +JS_SetGrayGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); + +extern JS_FRIEND_API(JSString *) +JS_GetAnonymousString(JSRuntime *rt); + +extern JS_FRIEND_API(JSObject *) +JS_FindCompilationScope(JSContext *cx, JS::HandleObject obj); + +extern JS_FRIEND_API(JSFunction *) +JS_GetObjectFunction(JSObject *obj); + +extern JS_FRIEND_API(bool) +JS_SplicePrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); + +extern JS_FRIEND_API(JSObject *) +JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JS::HandleObject proto, + JS::HandleObject parent); + +extern JS_FRIEND_API(uint32_t) +JS_ObjectCountDynamicSlots(JS::HandleObject obj); + +extern JS_FRIEND_API(size_t) +JS_SetProtoCalled(JSContext *cx); + +extern JS_FRIEND_API(size_t) +JS_GetCustomIteratorCount(JSContext *cx); + +extern JS_FRIEND_API(bool) +JS_NondeterministicGetWeakMapKeys(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject ret); + +/* + * Determine whether the given object is backed by a DeadObjectProxy. + * + * Such objects hold no other objects (they have no outgoing reference edges) + * and will throw if you touch them (e.g. by reading/writing a property). + */ +extern JS_FRIEND_API(bool) +JS_IsDeadWrapper(JSObject *obj); + +/* + * Used by the cycle collector to trace through the shape and all + * shapes it reaches, marking all non-shape children found in the + * process. Uses bounded stack space. + */ +extern JS_FRIEND_API(void) +JS_TraceShapeCycleCollectorChildren(JSTracer *trc, void *shape); + +enum { + JS_TELEMETRY_GC_REASON, + JS_TELEMETRY_GC_IS_COMPARTMENTAL, + JS_TELEMETRY_GC_MS, + JS_TELEMETRY_GC_MAX_PAUSE_MS, + JS_TELEMETRY_GC_MARK_MS, + JS_TELEMETRY_GC_SWEEP_MS, + JS_TELEMETRY_GC_MARK_ROOTS_MS, + JS_TELEMETRY_GC_MARK_GRAY_MS, + JS_TELEMETRY_GC_SLICE_MS, + JS_TELEMETRY_GC_MMU_50, + JS_TELEMETRY_GC_RESET, + JS_TELEMETRY_GC_INCREMENTAL_DISABLED, + JS_TELEMETRY_GC_NON_INCREMENTAL, + JS_TELEMETRY_GC_SCC_SWEEP_TOTAL_MS, + JS_TELEMETRY_GC_SCC_SWEEP_MAX_PAUSE_MS +}; + +typedef void +(* JSAccumulateTelemetryDataCallback)(int id, uint32_t sample); + +extern JS_FRIEND_API(void) +JS_SetAccumulateTelemetryCallback(JSRuntime *rt, JSAccumulateTelemetryDataCallback callback); + +extern JS_FRIEND_API(JSPrincipals *) +JS_GetCompartmentPrincipals(JSCompartment *compartment); + +extern JS_FRIEND_API(void) +JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals); + +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptPrincipals(JSScript *script); + +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptOriginPrincipals(JSScript *script); + +/* Safe to call with input obj == nullptr. Returns non-nullptr iff obj != nullptr. */ +extern JS_FRIEND_API(JSObject *) +JS_ObjectToInnerObject(JSContext *cx, JS::HandleObject obj); + +/* Requires obj != nullptr. */ +extern JS_FRIEND_API(JSObject *) +JS_ObjectToOuterObject(JSContext *cx, JS::HandleObject obj); + +extern JS_FRIEND_API(JSObject *) +JS_CloneObject(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto, + JS::HandleObject parent); + +extern JS_FRIEND_API(JSString *) +JS_BasicObjectToString(JSContext *cx, JS::HandleObject obj); + +extern JS_FRIEND_API(bool) +js_GetterOnlyPropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, + JS::MutableHandleValue vp); + +JS_FRIEND_API(void) +js_ReportOverRecursed(JSContext *maybecx); + +JS_FRIEND_API(bool) +js_ObjectClassIs(JSContext *cx, JS::HandleObject obj, js::ESClassValue classValue); + +JS_FRIEND_API(const char *) +js_ObjectClassName(JSContext *cx, JS::HandleObject obj); + +namespace js { + +JS_FRIEND_API(bool) +AddRawValueRoot(JSContext *cx, JS::Value *vp, const char *name); + +JS_FRIEND_API(void) +RemoveRawValueRoot(JSContext *cx, JS::Value *vp); + +} /* namespace js */ + +#ifdef JS_DEBUG + +/* + * Routines to print out values during debugging. These are FRIEND_API to help + * the debugger find them and to support temporarily hacking js_Dump* calls + * into other code. + */ + +extern JS_FRIEND_API(void) +js_DumpString(JSString *str); + +extern JS_FRIEND_API(void) +js_DumpAtom(JSAtom *atom); + +extern JS_FRIEND_API(void) +js_DumpObject(JSObject *obj); + +extern JS_FRIEND_API(void) +js_DumpChars(const jschar *s, size_t n); +#endif + +/* + * Copies all own properties from |obj| to |target|. |obj| must be a "native" + * object (that is to say, normal-ish - not an Array or a Proxy). + * + * This function immediately enters a compartment, and does not impose any + * restrictions on the compartment of |cx|. + */ +extern JS_FRIEND_API(bool) +JS_CopyPropertiesFrom(JSContext *cx, JS::HandleObject target, JS::HandleObject obj); + +/* + * Single-property version of the above. This function asserts that an |own| + * property of the given name exists on |obj|. + * + * On entry, |cx| must be same-compartment with |obj|. + */ +extern JS_FRIEND_API(bool) +JS_CopyPropertyFrom(JSContext *cx, JS::HandleId id, JS::HandleObject target, + JS::HandleObject obj); + +extern JS_FRIEND_API(bool) +JS_WrapPropertyDescriptor(JSContext *cx, JS::MutableHandle desc); + +extern JS_FRIEND_API(bool) +JS_WrapAutoIdVector(JSContext *cx, JS::AutoIdVector &props); + +extern JS_FRIEND_API(bool) +JS_EnumerateState(JSContext *cx, JS::HandleObject obj, JSIterateOp enum_op, + JS::MutableHandleValue statep, JS::MutableHandleId idp); + +struct JSFunctionSpecWithHelp { + const char *name; + JSNative call; + uint16_t nargs; + uint16_t flags; + const char *usage; + const char *help; +}; + +#define JS_FN_HELP(name,call,nargs,flags,usage,help) \ + {name, call, nargs, (flags) | JSPROP_ENUMERATE | JSFUN_STUB_GSOPS, usage, help} +#define JS_FS_HELP_END \ + {nullptr, nullptr, 0, 0, nullptr, nullptr} + +extern JS_FRIEND_API(bool) +JS_DefineFunctionsWithHelp(JSContext *cx, JS::HandleObject obj, const JSFunctionSpecWithHelp *fs); + +namespace js { + +/* + * Helper Macros for creating JSClasses that function as proxies. + * + * NB: The macro invocation must be surrounded by braces, so as to + * allow for potention JSClass extensions. + */ +#define PROXY_MAKE_EXT(outerObject, innerObject, iteratorObject, \ + isWrappedNative) \ + { \ + outerObject, \ + innerObject, \ + iteratorObject, \ + isWrappedNative, \ + js::proxy_WeakmapKeyDelegate \ + } + +#define PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, ext) \ + { \ + name, \ + js::Class::NON_NATIVE | \ + JSCLASS_IS_PROXY | \ + JSCLASS_IMPLEMENTS_BARRIERS | \ + JSCLASS_HAS_RESERVED_SLOTS(js::PROXY_MINIMUM_SLOTS + (extraSlots)) | \ + flags, \ + JS_PropertyStub, /* addProperty */ \ + JS_DeletePropertyStub, /* delProperty */ \ + JS_PropertyStub, /* getProperty */ \ + JS_StrictPropertyStub, /* setProperty */ \ + JS_EnumerateStub, \ + JS_ResolveStub, \ + js::proxy_Convert, \ + js::proxy_Finalize, /* finalize */ \ + callOp, /* call */ \ + js::proxy_HasInstance, /* hasInstance */ \ + constructOp, /* construct */ \ + js::proxy_Trace, /* trace */ \ + JS_NULL_CLASS_SPEC, \ + ext, \ + { \ + js::proxy_LookupGeneric, \ + js::proxy_LookupProperty, \ + js::proxy_LookupElement, \ + js::proxy_DefineGeneric, \ + js::proxy_DefineProperty, \ + js::proxy_DefineElement, \ + js::proxy_GetGeneric, \ + js::proxy_GetProperty, \ + js::proxy_GetElement, \ + js::proxy_SetGeneric, \ + js::proxy_SetProperty, \ + js::proxy_SetElement, \ + js::proxy_GetGenericAttributes, \ + js::proxy_SetGenericAttributes, \ + js::proxy_DeleteGeneric, \ + js::proxy_Watch, js::proxy_Unwatch, \ + js::proxy_Slice, \ + nullptr, /* enumerate */ \ + nullptr, /* thisObject */ \ + } \ + } + +#define PROXY_CLASS_DEF(name, extraSlots, flags, callOp, constructOp) \ + PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, \ + PROXY_MAKE_EXT( \ + nullptr, /* outerObject */ \ + nullptr, /* innerObject */ \ + nullptr, /* iteratorObject */ \ + false /* isWrappedNative */ \ + )) + +/* + * Proxy stubs, similar to JS_*Stub, for embedder proxy class definitions. + * + * NB: Should not be called directly. + */ + +extern JS_FRIEND_API(bool) +proxy_LookupGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleObject objp, JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_DefineGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, + unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_GetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetProperty(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, + JS::Handle name, JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetElement(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_SetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp, + bool strict); +extern JS_FRIEND_API(bool) +proxy_GetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_SetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_DeleteGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); + +extern JS_FRIEND_API(void) +proxy_Trace(JSTracer *trc, JSObject *obj); +extern JS_FRIEND_API(JSObject *) +proxy_WeakmapKeyDelegate(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Convert(JSContext *cx, JS::HandleObject proxy, JSType hint, JS::MutableHandleValue vp); +extern JS_FRIEND_API(void) +proxy_Finalize(FreeOp *fop, JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_HasInstance(JSContext *cx, JS::HandleObject proxy, JS::MutableHandleValue v, bool *bp); +extern JS_FRIEND_API(bool) +proxy_Call(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(bool) +proxy_Construct(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(JSObject *) +proxy_innerObject(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Watch(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); +extern JS_FRIEND_API(bool) +proxy_Unwatch(JSContext *cx, JS::HandleObject obj, JS::HandleId id); +extern JS_FRIEND_API(bool) +proxy_Slice(JSContext *cx, JS::HandleObject proxy, uint32_t begin, uint32_t end, + JS::HandleObject result); + +/* + * A class of objects that return source code on demand. + * + * When code is compiled with setSourceIsLazy(true), SpiderMonkey doesn't + * retain the source code (and doesn't do lazy bytecode generation). If we ever + * need the source code, say, in response to a call to Function.prototype. + * toSource or Debugger.Source.prototype.text, then we call the 'load' member + * function of the instance of this class that has hopefully been registered + * with the runtime, passing the code's URL, and hope that it will be able to + * find the source. + */ +class SourceHook { + public: + virtual ~SourceHook() { } + + /* + * Set |*src| and |*length| to refer to the source code for |filename|. + * On success, the caller owns the buffer to which |*src| points, and + * should use JS_free to free it. + */ + virtual bool load(JSContext *cx, const char *filename, jschar **src, size_t *length) = 0; +}; + +/* + * Have |rt| use |hook| to retrieve lazily-retrieved source code. See the + * comments for SourceHook. The runtime takes ownership of the hook, and + * will delete it when the runtime itself is deleted, or when a new hook is + * set. + */ +extern JS_FRIEND_API(void) +SetSourceHook(JSRuntime *rt, mozilla::UniquePtr hook); + +/* Remove |rt|'s source hook, and return it. The caller now owns the hook. */ +extern JS_FRIEND_API(mozilla::UniquePtr) +ForgetSourceHook(JSRuntime *rt); + +#ifdef NIGHTLY_BUILD +typedef void (*AssertOnScriptEntryHook)(JSContext *cx, JS::HandleScript script); + +extern JS_FRIEND_API(void) +SetAssertOnScriptEntryHook(JSRuntime *rt, AssertOnScriptEntryHook hook); +#endif + +extern JS_FRIEND_API(JS::Zone *) +GetCompartmentZone(JSCompartment *comp); + +typedef bool +(* PreserveWrapperCallback)(JSContext *cx, JSObject *obj); + +typedef enum { + CollectNurseryBeforeDump, + IgnoreNurseryObjects +} DumpHeapNurseryBehaviour; + + /* + * Dump the complete object graph of heap-allocated things. + * fp is the file for the dump output. + */ +extern JS_FRIEND_API(void) +DumpHeapComplete(JSRuntime *rt, FILE *fp, DumpHeapNurseryBehaviour nurseryBehaviour); + +#ifdef JS_OLD_GETTER_SETTER_METHODS +JS_FRIEND_API(bool) obj_defineGetter(JSContext *cx, unsigned argc, JS::Value *vp); +JS_FRIEND_API(bool) obj_defineSetter(JSContext *cx, unsigned argc, JS::Value *vp); +#endif + +extern JS_FRIEND_API(bool) +IsSystemCompartment(JSCompartment *comp); + +extern JS_FRIEND_API(bool) +IsSystemZone(JS::Zone *zone); + +extern JS_FRIEND_API(bool) +IsAtomsCompartment(JSCompartment *comp); + +/* + * Returns whether we're in a non-strict property set (in that we're in a + * non-strict script and the bytecode we're on is a property set). The return + * value does NOT indicate any sort of exception was thrown: it's just a + * boolean. + */ +extern JS_FRIEND_API(bool) +IsInNonStrictPropertySet(JSContext *cx); + +struct WeakMapTracer; + +/* + * Weak map tracer callback, called once for every binding of every + * weak map that was live at the time of the last garbage collection. + * + * m will be nullptr if the weak map is not contained in a JS Object. + */ +typedef void +(* WeakMapTraceCallback)(WeakMapTracer *trc, JSObject *m, + void *k, JSGCTraceKind kkind, + void *v, JSGCTraceKind vkind); + +struct WeakMapTracer { + JSRuntime *runtime; + WeakMapTraceCallback callback; + + WeakMapTracer(JSRuntime *rt, WeakMapTraceCallback cb) + : runtime(rt), callback(cb) {} +}; + +extern JS_FRIEND_API(void) +TraceWeakMaps(WeakMapTracer *trc); + +extern JS_FRIEND_API(bool) +AreGCGrayBitsValid(JSRuntime *rt); + +extern JS_FRIEND_API(bool) +ZoneGlobalsAreAllGray(JS::Zone *zone); + +typedef void +(*GCThingCallback)(void *closure, void *gcthing); + +extern JS_FRIEND_API(void) +VisitGrayWrapperTargets(JS::Zone *zone, GCThingCallback callback, void *closure); + +extern JS_FRIEND_API(JSObject *) +GetWeakmapKeyDelegate(JSObject *key); + +JS_FRIEND_API(JSGCTraceKind) +GCThingTraceKind(void *thing); + +/* + * Invoke cellCallback on every gray JS_OBJECT in the given zone. + */ +extern JS_FRIEND_API(void) +IterateGrayObjects(JS::Zone *zone, GCThingCallback cellCallback, void *data); + +#ifdef JS_HAS_CTYPES +extern JS_FRIEND_API(size_t) +SizeOfDataIfCDataObject(mozilla::MallocSizeOf mallocSizeOf, JSObject *obj); +#endif + +extern JS_FRIEND_API(JSCompartment *) +GetAnyCompartmentInZone(JS::Zone *zone); + +/* + * Shadow declarations of JS internal structures, for access by inline access + * functions below. Do not use these structures in any other way. When adding + * new fields for access by inline methods, make sure to add static asserts to + * the original header file to ensure that offsets are consistent. + */ +namespace shadow { + +struct TypeObject { + const Class *clasp; + JSObject *proto; +}; + +struct BaseShape { + const js::Class *clasp_; + JSObject *parent; + JSObject *_1; + JSCompartment *compartment; +}; + +class Shape { +public: + shadow::BaseShape *base; + jsid _1; + uint32_t slotInfo; + + static const uint32_t FIXED_SLOTS_SHIFT = 27; +}; + +struct Object { + shadow::Shape *shape; + shadow::TypeObject *type; + JS::Value *slots; + JS::Value *_1; + + size_t numFixedSlots() const { return shape->slotInfo >> Shape::FIXED_SLOTS_SHIFT; } + JS::Value *fixedSlots() const { + return (JS::Value *)(uintptr_t(this) + sizeof(shadow::Object)); + } + + JS::Value &slotRef(size_t slot) const { + size_t nfixed = numFixedSlots(); + if (slot < nfixed) + return fixedSlots()[slot]; + return slots[slot - nfixed]; + } + + // Reserved slots with index < MAX_FIXED_SLOTS are guaranteed to + // be fixed slots. + static const uint32_t MAX_FIXED_SLOTS = 16; +}; + +struct Function { + Object base; + uint16_t nargs; + uint16_t flags; + /* Used only for natives */ + JSNative native; + const JSJitInfo *jitinfo; + void *_1; +}; + +struct String +{ + static const uint32_t INLINE_CHARS_BIT = JS_BIT(2); + static const uint32_t LATIN1_CHARS_BIT = JS_BIT(6); + static const uint32_t ROPE_FLAGS = 0; + static const uint32_t TYPE_FLAGS_MASK = JS_BIT(6) - 1; + uint32_t flags; + uint32_t length; + union { + const JS::Latin1Char *nonInlineCharsLatin1; + const jschar *nonInlineCharsTwoByte; + JS::Latin1Char inlineStorageLatin1[1]; + jschar inlineStorageTwoByte[1]; + }; +}; + +} /* namespace shadow */ + +// This is equal to |&JSObject::class_|. Use it in places where you don't want +// to #include jsobj.h. +extern JS_FRIEND_DATA(const js::Class* const) ObjectClassPtr; + +inline const js::Class * +GetObjectClass(JSObject *obj) +{ + return reinterpret_cast(obj)->type->clasp; +} + +inline const JSClass * +GetObjectJSClass(JSObject *obj) +{ + return js::Jsvalify(GetObjectClass(obj)); +} + +JS_FRIEND_API(const Class *) +ProtoKeyToClass(JSProtoKey key); + +// Returns true if the standard class identified by |key| inherits from +// another standard class with the same js::Class. This basically means +// that the various properties described by our js::Class are intended +// to live higher up on the proto chain. +// +// In practice, this only returns true for Error subtypes. +inline bool +StandardClassIsDependent(JSProtoKey key) +{ + JSProtoKey keyFromClass = JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + MOZ_ASSERT(keyFromClass); + return key != keyFromClass; +} + +// Returns the key for the class inherited by a given standard class (that +// is to say, the prototype of this standard class's prototype). +// +// You must be sure that this corresponds to a standard class with a cached +// JSProtoKey before calling this function. In general |key| will match the +// cached proto key, except in cases where multiple JSProtoKeys share a +// JSClass. +inline JSProtoKey +ParentKeyForStandardClass(JSProtoKey key) +{ + // [Object] has nothing to inherit from. + if (key == JSProto_Object) + return JSProto_Null; + + // If we're dependent (i.e. an Error subtype), return the key of the class + // we depend on. + if (StandardClassIsDependent(key)) + return JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + + // Otherwise, we inherit [Object]. + return JSProto_Object; +} + +inline bool +IsInnerObject(JSObject *obj) { + return !!GetObjectClass(obj)->ext.outerObject; +} + +inline bool +IsOuterObject(JSObject *obj) { + return !!GetObjectClass(obj)->ext.innerObject; +} + +JS_FRIEND_API(bool) +IsFunctionObject(JSObject *obj); + +JS_FRIEND_API(bool) +IsScopeObject(JSObject *obj); + +JS_FRIEND_API(bool) +IsCallObject(JSObject *obj); + +inline JSObject * +GetObjectParent(JSObject *obj) +{ + JS_ASSERT(!IsScopeObject(obj)); + return reinterpret_cast(obj)->shape->base->parent; +} + +static MOZ_ALWAYS_INLINE JSCompartment * +GetObjectCompartment(JSObject *obj) +{ + return reinterpret_cast(obj)->shape->base->compartment; +} + +JS_FRIEND_API(JSObject *) +GetObjectParentMaybeScope(JSObject *obj); + +JS_FRIEND_API(JSObject *) +GetGlobalForObjectCrossCompartment(JSObject *obj); + +// Sidestep the activeContext checking implicitly performed in +// JS_SetPendingException. +JS_FRIEND_API(void) +SetPendingExceptionCrossContext(JSContext *cx, JS::HandleValue v); + +JS_FRIEND_API(void) +AssertSameCompartment(JSContext *cx, JSObject *obj); + +#ifdef JS_DEBUG +JS_FRIEND_API(void) +AssertSameCompartment(JSObject *objA, JSObject *objB); +#else +inline void AssertSameCompartment(JSObject *objA, JSObject *objB) {} +#endif + +// For legacy consumers only. This whole concept is going away soon. +JS_FRIEND_API(JSObject *) +DefaultObjectForContextOrNull(JSContext *cx); + +JS_FRIEND_API(void) +SetDefaultObjectForContext(JSContext *cx, JSObject *obj); + +JS_FRIEND_API(void) +NotifyAnimationActivity(JSObject *obj); + +/* + * Return the outermost enclosing function (script) of the scripted caller. + * This function returns nullptr in several cases: + * - no script is running on the context + * - the caller is in global or eval code + * In particular, this function will "stop" its outermost search at eval() and + * thus it will really return the outermost enclosing function *since the + * innermost eval*. + */ +JS_FRIEND_API(JSFunction *) +GetOutermostEnclosingFunctionOfScriptedCaller(JSContext *cx); + +JS_FRIEND_API(JSFunction *) +DefineFunctionWithReserved(JSContext *cx, JSObject *obj, const char *name, JSNative call, + unsigned nargs, unsigned attrs); + +JS_FRIEND_API(JSFunction *) +NewFunctionWithReserved(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, + JSObject *parent, const char *name); + +JS_FRIEND_API(JSFunction *) +NewFunctionByIdWithReserved(JSContext *cx, JSNative native, unsigned nargs, unsigned flags, + JSObject *parent, jsid id); + +JS_FRIEND_API(const JS::Value &) +GetFunctionNativeReserved(JSObject *fun, size_t which); + +JS_FRIEND_API(void) +SetFunctionNativeReserved(JSObject *fun, size_t which, const JS::Value &val); + +JS_FRIEND_API(bool) +GetObjectProto(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject proto); + +JS_FRIEND_API(bool) +GetOriginalEval(JSContext *cx, JS::HandleObject scope, + JS::MutableHandleObject eval); + +inline void * +GetObjectPrivate(JSObject *obj) +{ + const shadow::Object *nobj = reinterpret_cast(obj); + void **addr = reinterpret_cast(&nobj->fixedSlots()[nobj->numFixedSlots()]); + return *addr; +} + +/* + * Get a slot that is both reserved for object's clasp *and* is fixed (fits + * within the maximum capacity for the object's fixed slots). + */ +inline const JS::Value & +GetReservedSlot(JSObject *obj, size_t slot) +{ + JS_ASSERT(slot < JSCLASS_RESERVED_SLOTS(GetObjectClass(obj))); + return reinterpret_cast(obj)->slotRef(slot); +} + +JS_FRIEND_API(void) +SetReservedSlotWithBarrier(JSObject *obj, size_t slot, const JS::Value &value); + +inline void +SetReservedSlot(JSObject *obj, size_t slot, const JS::Value &value) +{ + JS_ASSERT(slot < JSCLASS_RESERVED_SLOTS(GetObjectClass(obj))); + shadow::Object *sobj = reinterpret_cast(obj); + if (sobj->slotRef(slot).isMarkable() +#ifdef JSGC_GENERATIONAL + || value.isMarkable() +#endif + ) + { + SetReservedSlotWithBarrier(obj, slot, value); + } else { + sobj->slotRef(slot) = value; + } +} + +JS_FRIEND_API(uint32_t) +GetObjectSlotSpan(JSObject *obj); + +inline const JS::Value & +GetObjectSlot(JSObject *obj, size_t slot) +{ + JS_ASSERT(slot < GetObjectSlotSpan(obj)); + return reinterpret_cast(obj)->slotRef(slot); +} + +MOZ_ALWAYS_INLINE size_t +GetAtomLength(JSAtom *atom) +{ + return reinterpret_cast(atom)->length; +} + +static const uint32_t MaxStringLength = (1 << 28) - 1; + +MOZ_ALWAYS_INLINE size_t +GetStringLength(JSString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetFlatStringLength(JSFlatString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetLinearStringLength(JSLinearString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE bool +LinearStringHasLatin1Chars(JSLinearString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE bool +AtomHasLatin1Chars(JSAtom *atom) +{ + return reinterpret_cast(atom)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE bool +StringHasLatin1Chars(JSString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1LinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageLatin1; + return s->nonInlineCharsLatin1; +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteLinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(!LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageTwoByte; + return s->nonInlineCharsTwoByte; +} + +MOZ_ALWAYS_INLINE JSLinearString * +AtomToLinearString(JSAtom *atom) +{ + return reinterpret_cast(atom); +} + +MOZ_ALWAYS_INLINE JSLinearString * +FlatStringToLinearString(JSFlatString *s) +{ + return reinterpret_cast(s); +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1AtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetLatin1LinearStringChars(nogc, AtomToLinearString(atom)); +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteAtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetTwoByteLinearStringChars(nogc, AtomToLinearString(atom)); +} + +JS_FRIEND_API(JSLinearString *) +StringToLinearStringSlow(JSContext *cx, JSString *str); + +MOZ_ALWAYS_INLINE JSLinearString * +StringToLinearString(JSContext *cx, JSString *str) +{ + using shadow::String; + String *s = reinterpret_cast(str); + if (MOZ_UNLIKELY((s->flags & String::TYPE_FLAGS_MASK) == String::ROPE_FLAGS)) + return StringToLinearStringSlow(cx, str); + return reinterpret_cast(str); +} + +MOZ_ALWAYS_INLINE void +CopyLinearStringChars(jschar *dest, JSLinearString *s, size_t len) +{ + JS::AutoCheckCannotGC nogc; + if (LinearStringHasLatin1Chars(s)) { + const JS::Latin1Char *src = GetLatin1LinearStringChars(nogc, s); + for (size_t i = 0; i < len; i++) + dest[i] = src[i]; + } else { + const jschar *src = GetTwoByteLinearStringChars(nogc, s); + mozilla::PodCopy(dest, src, len); + } +} + +inline bool +CopyStringChars(JSContext *cx, jschar *dest, JSString *s, size_t len) +{ + JSLinearString *linear = StringToLinearString(cx, s); + if (!linear) + return false; + + CopyLinearStringChars(dest, linear, len); + return true; +} + +inline void +CopyFlatStringChars(jschar *dest, JSFlatString *s, size_t len) +{ + CopyLinearStringChars(dest, FlatStringToLinearString(s), len); +} + +JS_FRIEND_API(bool) +GetPropertyNames(JSContext *cx, JSObject *obj, unsigned flags, JS::AutoIdVector *props); + +JS_FRIEND_API(bool) +AppendUnique(JSContext *cx, JS::AutoIdVector &base, JS::AutoIdVector &others); + +JS_FRIEND_API(bool) +GetGeneric(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id, JS::Value *vp); + +JS_FRIEND_API(bool) +StringIsArrayIndex(JSLinearString *str, uint32_t *indexp); + +JS_FRIEND_API(void) +SetPreserveWrapperCallback(JSRuntime *rt, PreserveWrapperCallback callback); + +JS_FRIEND_API(bool) +IsObjectInContextCompartment(JSObject *obj, const JSContext *cx); + +/* + * NB: these flag bits are encoded into the bytecode stream in the immediate + * operand of JSOP_ITER, so don't change them without advancing vm/Xdr.h's + * XDR_BYTECODE_VERSION. + */ +#define JSITER_ENUMERATE 0x1 /* for-in compatible hidden default iterator */ +#define JSITER_FOREACH 0x2 /* get obj[key] for each property */ +#define JSITER_KEYVALUE 0x4 /* obsolete destructuring for-in wants [key, value] */ +#define JSITER_OWNONLY 0x8 /* iterate over obj's own properties only */ +#define JSITER_HIDDEN 0x10 /* also enumerate non-enumerable properties */ +#define JSITER_SYMBOLS 0x20 /* also include symbol property keys */ +#define JSITER_SYMBOLSONLY 0x40 /* exclude string property keys */ + +JS_FRIEND_API(bool) +RunningWithTrustedPrincipals(JSContext *cx); + +inline uintptr_t +GetNativeStackLimit(JSContext *cx) +{ + StackKind kind = RunningWithTrustedPrincipals(cx) ? StackForTrustedScript + : StackForUntrustedScript; + PerThreadDataFriendFields *mainThread = + PerThreadDataFriendFields::getMainThread(GetRuntime(cx)); + return mainThread->nativeStackLimit[kind]; +} + +/* + * These macros report a stack overflow and run |onerror| if we are close to + * using up the C stack. The JS_CHECK_CHROME_RECURSION variant gives us a little + * extra space so that we can ensure that crucial code is able to run. + * JS_CHECK_RECURSION_CONSERVATIVE gives us a little less space. + */ + +#define JS_CHECK_RECURSION(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), &stackDummy_)) { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_RECURSION_DONT_REPORT(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), &stackDummy_)) { \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_RECURSION_WITH_SP_DONT_REPORT(cx, sp, onerror) \ + JS_BEGIN_MACRO \ + if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), sp)) { \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_RECURSION_WITH_SP(cx, sp, onerror) \ + JS_BEGIN_MACRO \ + if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), sp)) { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_CHROME_RECURSION(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE_WITH_TOLERANCE(js::GetNativeStackLimit(cx), \ + &stackDummy_, \ + 1024 * sizeof(size_t))) \ + { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_RECURSION_CONSERVATIVE(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(js::GetNativeStackLimit(cx), \ + &stackDummy_, \ + 1024 * sizeof(size_t))) \ + { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + +JS_FRIEND_API(void) +StartPCCountProfiling(JSContext *cx); + +JS_FRIEND_API(void) +StopPCCountProfiling(JSContext *cx); + +JS_FRIEND_API(void) +PurgePCCounts(JSContext *cx); + +JS_FRIEND_API(size_t) +GetPCCountScriptCount(JSContext *cx); + +JS_FRIEND_API(JSString *) +GetPCCountScriptSummary(JSContext *cx, size_t script); + +JS_FRIEND_API(JSString *) +GetPCCountScriptContents(JSContext *cx, size_t script); + +#ifdef JS_THREADSAFE +JS_FRIEND_API(bool) +ContextHasOutstandingRequests(const JSContext *cx); +#endif + +typedef void +(* ActivityCallback)(void *arg, bool active); + +/* + * Sets a callback that is run whenever the runtime goes idle - the + * last active request ceases - and begins activity - when it was + * idle and a request begins. + */ +JS_FRIEND_API(void) +SetActivityCallback(JSRuntime *rt, ActivityCallback cb, void *arg); + +extern JS_FRIEND_API(const JSStructuredCloneCallbacks *) +GetContextStructuredCloneCallbacks(JSContext *cx); + +extern JS_FRIEND_API(bool) +IsContextRunningJS(JSContext *cx); + +typedef bool +(* DOMInstanceClassHasProtoAtDepth)(const Class *instanceClass, + uint32_t protoID, uint32_t depth); +struct JSDOMCallbacks { + DOMInstanceClassHasProtoAtDepth instanceClassMatchesProto; +}; +typedef struct JSDOMCallbacks DOMCallbacks; + +extern JS_FRIEND_API(void) +SetDOMCallbacks(JSRuntime *rt, const DOMCallbacks *callbacks); + +extern JS_FRIEND_API(const DOMCallbacks *) +GetDOMCallbacks(JSRuntime *rt); + +extern JS_FRIEND_API(JSObject *) +GetTestingFunctions(JSContext *cx); + +/* + * Helper to convert FreeOp to JSFreeOp when the definition of FreeOp is not + * available and the compiler does not know that FreeOp inherits from + * JSFreeOp. + */ +inline JSFreeOp * +CastToJSFreeOp(FreeOp *fop) +{ + return reinterpret_cast(fop); +} + +/* Implemented in jsexn.cpp. */ + +/* + * Get an error type name from a JSExnType constant. + * Returns nullptr for invalid arguments and JSEXN_INTERNALERR + */ +extern JS_FRIEND_API(JSFlatString *) +GetErrorTypeName(JSRuntime *rt, int16_t exnType); + +#ifdef JS_DEBUG +extern JS_FRIEND_API(unsigned) +GetEnterCompartmentDepth(JSContext* cx); +#endif + +/* Implemented in jswrapper.cpp. */ +typedef enum NukeReferencesToWindow { + NukeWindowReferences, + DontNukeWindowReferences +} NukeReferencesToWindow; + +/* + * These filters are designed to be ephemeral stack classes, and thus don't + * do any rooting or holding of their members. + */ +struct CompartmentFilter { + virtual bool match(JSCompartment *c) const = 0; +}; + +struct AllCompartments : public CompartmentFilter { + virtual bool match(JSCompartment *c) const { return true; } +}; + +struct ContentCompartmentsOnly : public CompartmentFilter { + virtual bool match(JSCompartment *c) const { + return !IsSystemCompartment(c); + } +}; + +struct ChromeCompartmentsOnly : public CompartmentFilter { + virtual bool match(JSCompartment *c) const { + return IsSystemCompartment(c); + } +}; + +struct SingleCompartment : public CompartmentFilter { + JSCompartment *ours; + explicit SingleCompartment(JSCompartment *c) : ours(c) {} + virtual bool match(JSCompartment *c) const { return c == ours; } +}; + +struct CompartmentsWithPrincipals : public CompartmentFilter { + JSPrincipals *principals; + explicit CompartmentsWithPrincipals(JSPrincipals *p) : principals(p) {} + virtual bool match(JSCompartment *c) const { + return JS_GetCompartmentPrincipals(c) == principals; + } +}; + +extern JS_FRIEND_API(bool) +NukeCrossCompartmentWrappers(JSContext* cx, + const CompartmentFilter& sourceFilter, + const CompartmentFilter& targetFilter, + NukeReferencesToWindow nukeReferencesToWindow); + +/* Specify information about DOMProxy proxies in the DOM, for use by ICs. */ + +/* + * The DOMProxyShadowsCheck function will be called to check if the property for + * id should be gotten from the prototype, or if there is an own property that + * shadows it. + * If DoesntShadow is returned then the slot at listBaseExpandoSlot should + * either be undefined or point to an expando object that would contain the own + * property. + * If DoesntShadowUnique is returned then the slot at listBaseExpandoSlot should + * contain a private pointer to a ExpandoAndGeneration, which contains a + * JS::Value that should either be undefined or point to an expando object, and + * a uint32 value. If that value changes then the IC for getting a property will + * be invalidated. + */ + +struct ExpandoAndGeneration { + ExpandoAndGeneration() + : expando(JS::UndefinedValue()), + generation(0) + {} + + void Unlink() + { + ++generation; + expando.setUndefined(); + } + + static size_t offsetOfExpando() + { + return offsetof(ExpandoAndGeneration, expando); + } + + static size_t offsetOfGeneration() + { + return offsetof(ExpandoAndGeneration, generation); + } + + JS::Heap expando; + uint32_t generation; +}; + +typedef enum DOMProxyShadowsResult { + ShadowCheckFailed, + Shadows, + DoesntShadow, + DoesntShadowUnique +} DOMProxyShadowsResult; +typedef DOMProxyShadowsResult +(* DOMProxyShadowsCheck)(JSContext* cx, JS::HandleObject object, JS::HandleId id); +JS_FRIEND_API(void) +SetDOMProxyInformation(const void *domProxyHandlerFamily, uint32_t domProxyExpandoSlot, + DOMProxyShadowsCheck domProxyShadowsCheck); + +const void *GetDOMProxyHandlerFamily(); +uint32_t GetDOMProxyExpandoSlot(); +DOMProxyShadowsCheck GetDOMProxyShadowsCheck(); + +} /* namespace js */ + +/* Implemented in jsdate.cpp. */ + +/* + * Detect whether the internal date value is NaN. (Because failure is + * out-of-band for js_DateGet*) + */ +extern JS_FRIEND_API(bool) +js_DateIsValid(JSObject* obj); + +extern JS_FRIEND_API(double) +js_DateGetMsecSinceEpoch(JSObject *obj); + +/* Implemented in jscntxt.cpp. */ + +/* + * Report an exception, which is currently realized as a printf-style format + * string and its arguments. + */ +typedef enum JSErrNum { +#define MSG_DEF(name, number, count, exception, format) \ + name = number, +#include "js.msg" +#undef MSG_DEF + JSErr_Limit +} JSErrNum; + +extern JS_FRIEND_API(const JSErrorFormatString *) +js_GetErrorMessage(void *userRef, const unsigned errorNumber); + +namespace js { + +// AutoStableStringChars is here so we can use it in ErrorReport. It +// should get moved out of here if we can manage it. See bug 1040316. + +/* + * This class provides safe access to a string's chars across a GC. Once + * we allocate strings and chars in the nursery (bug 903519), this class + * will have to make a copy of the string's chars if they are allocated + * in the nursery, so it's best to avoid using this class unless you really + * need it. It's usually more efficient to use the latin1Chars/twoByteChars + * JSString methods and often the code can be rewritten so that only indexes + * instead of char pointers are used in parts of the code that can GC. + */ +class MOZ_STACK_CLASS AutoStableStringChars +{ + /* Ensure the string is kept alive while we're using its chars. */ + JS::RootedString s_; + union { + const jschar *twoByteChars_; + const JS::Latin1Char *latin1Chars_; + }; + enum State { Uninitialized, Latin1, TwoByte }; + State state_; + bool ownsChars_; + + public: + AutoStableStringChars(JSContext *cx) + : s_(cx), state_(Uninitialized), ownsChars_(false) + {}; + ~AutoStableStringChars(); + + bool init(JSContext *cx, JSString *s); + + /* Like init(), but Latin1 chars are inflated to TwoByte. */ + bool initTwoByte(JSContext *cx, JSString *s); + + bool isLatin1() const { return state_ == Latin1; } + bool isTwoByte() const { return state_ == TwoByte; } + + const jschar *twoByteChars() const { + MOZ_ASSERT(state_ == TwoByte); + return twoByteChars_; + } + + mozilla::Range latin1Range() const { + MOZ_ASSERT(state_ == Latin1); + return mozilla::Range(latin1Chars_, + GetStringLength(s_)); + } + + mozilla::Range twoByteRange() const { + MOZ_ASSERT(state_ == TwoByte); + return mozilla::Range(twoByteChars_, + GetStringLength(s_)); + } + + /* If we own the chars, transfer ownership to the caller. */ + bool maybeGiveOwnershipToCaller() { + MOZ_ASSERT(state_ != Uninitialized); + if (!ownsChars_) + return false; + state_ = Uninitialized; + ownsChars_ = false; + return true; + } + + private: + AutoStableStringChars(const AutoStableStringChars &other) MOZ_DELETE; + void operator=(const AutoStableStringChars &other) MOZ_DELETE; +}; + +// Creates a string of the form |ErrorType: ErrorMessage| for a JSErrorReport, +// which generally matches the toString() behavior of an ErrorObject. +extern JS_FRIEND_API(JSString *) +ErrorReportToString(JSContext *cx, JSErrorReport *reportp); + +struct MOZ_STACK_CLASS JS_FRIEND_API(ErrorReport) +{ + ErrorReport(JSContext *cx); + ~ErrorReport(); + + bool init(JSContext *cx, JS::HandleValue exn); + + JSErrorReport *report() + { + return reportp; + } + + const char *message() + { + return message_; + } + + private: + // More or less an equivalent of JS_ReportErrorNumber/js_ReportErrorNumberVA + // but fills in an ErrorReport instead of reporting it. Uses varargs to + // make it simpler to call js_ExpandErrorArguments. + void populateUncaughtExceptionReport(JSContext *cx, ...); + void populateUncaughtExceptionReportVA(JSContext *cx, va_list ap); + + // We may have a provided JSErrorReport, so need a way to represent that. + JSErrorReport *reportp; + + // And we may have a message. + const char *message_; + + // Or we may need to synthesize a JSErrorReport one of our own. + JSErrorReport ownedReport; + + // Or a message of our own. If this is non-null, we need to clean up both + // it and ownedReport. + char *ownedMessage; + + // And we have a string to maybe keep alive that has pointers into + // it from ownedReport. + JS::RootedString str; + + // And keep its chars alive too. + AutoStableStringChars strChars; + + // And we need to root our exception value. + JS::RootedObject exnObject; + + // And possibly some byte storage for our message_. + JSAutoByteString bytesStorage; + + // And for our filename. + JSAutoByteString filename; + + // True if we need to free message_ and the stuff in ownedReport + bool ownsMessageAndReport; +}; + +} /* namespace js */ + + +/* Implemented in jsclone.cpp. */ + +extern JS_FRIEND_API(uint64_t) +js_GetSCOffset(JSStructuredCloneWriter* writer); + +namespace js { +namespace Scalar { + +/* Scalar types which can appear in typed arrays and typed objects. */ +enum Type { + Int8 = 0, + Uint8, + Int16, + Uint16, + Int32, + Uint32, + Float32, + Float64, + + /* + * Special type that is a uint8_t, but assignments are clamped to [0, 256). + * Treat the raw data type as a uint8_t. + */ + Uint8Clamped, + + TypeMax +}; + +static inline size_t +byteSize(Type atype) +{ + switch (atype) { + case Int8: + case Uint8: + case Uint8Clamped: + return 1; + case Int16: + case Uint16: + return 2; + case Int32: + case Uint32: + case Float32: + return 4; + case Float64: + return 8; + default: + MOZ_CRASH("invalid scalar type"); + } +} + +} /* namespace Scalar */ +} /* namespace js */ + +/* + * Create a new typed array with nelements elements. + * + * These functions (except the WithBuffer variants) fill in the array with zeros. + */ + +extern JS_FRIEND_API(JSObject *) +JS_NewInt8Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ClampedArray(JSContext *cx, uint32_t nelements); + +extern JS_FRIEND_API(JSObject *) +JS_NewInt16Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewUint16Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewInt32Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewUint32Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat32Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat64Array(JSContext *cx, uint32_t nelements); + +/* + * Create a new typed array and copy in values from the given object. The + * object is used as if it were an array; that is, the new array (if + * successfully created) will have length given by array.length, and its + * elements will be those specified by array[0], array[1], and so on, after + * conversion to the typed array element type. + */ + +extern JS_FRIEND_API(JSObject *) +JS_NewInt8ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ClampedArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewInt16ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewUint16ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewInt32ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewUint32ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat32ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat64ArrayFromArray(JSContext *cx, JS::HandleObject array); + +/* + * Create a new typed array using the given ArrayBuffer for storage. The + * length value is optional; if -1 is passed, enough elements to use up the + * remainder of the byte array is used as the default value. + */ + +extern JS_FRIEND_API(JSObject *) +JS_NewInt8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewInt16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewUint16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewInt32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewUint32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat64ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); + +/* + * Create a new ArrayBuffer with the given byte length. + */ +extern JS_FRIEND_API(JSObject *) +JS_NewArrayBuffer(JSContext *cx, uint32_t nbytes); + +/* + * Check whether obj supports JS_GetTypedArray* APIs. Note that this may return + * false if a security wrapper is encountered that denies the unwrapping. If + * this test or one of the JS_Is*Array tests succeeds, then it is safe to call + * the various accessor JSAPI calls defined below. + */ +extern JS_FRIEND_API(bool) +JS_IsTypedArrayObject(JSObject *obj); + +/* + * Check whether obj supports JS_GetArrayBufferView* APIs. Note that this may + * return false if a security wrapper is encountered that denies the + * unwrapping. If this test or one of the more specific tests succeeds, then it + * is safe to call the various ArrayBufferView accessor JSAPI calls defined + * below. + */ +extern JS_FRIEND_API(bool) +JS_IsArrayBufferViewObject(JSObject *obj); + +/* + * Test for specific typed array types (ArrayBufferView subtypes) + */ + +extern JS_FRIEND_API(bool) +JS_IsInt8Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsUint8Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsUint8ClampedArray(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsInt16Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsUint16Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsInt32Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsUint32Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsFloat32Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsFloat64Array(JSObject *obj); + +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +namespace js { + +extern JS_FRIEND_API(JSObject *) +UnwrapInt8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8ClampedArray(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat64Array(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBuffer(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBufferView(JSObject *obj); + +namespace detail { + +extern JS_FRIEND_DATA(const Class* const) Int8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ClampedArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float64ArrayClassPtr; + +const size_t TypedArrayLengthSlot = 1; + +} // namespace detail + +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +#define JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Type, type) \ +inline void \ +Get ## Type ## ArrayLengthAndData(JSObject *obj, uint32_t *length, type **data) \ +{ \ + JS_ASSERT(GetObjectClass(obj) == detail::Type ## ArrayClassPtr); \ + const JS::Value &slot = GetReservedSlot(obj, detail::TypedArrayLengthSlot); \ + *length = mozilla::SafeCast(slot.toInt32()); \ + *data = static_cast(GetObjectPrivate(obj)); \ +} + +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int8, int8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8Clamped, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int16, int16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint16, uint16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int32, int32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint32, uint32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float32, float) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float64, double) + +#undef JS_DEFINE_DATA_AND_LENGTH_ACCESSOR + +// This one isn't inlined because it's rather tricky (by dint of having to deal +// with a dozen-plus classes and varying slot layouts. +extern JS_FRIEND_API(void) +GetArrayBufferViewLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +// This one isn't inlined because there are a bunch of different ArrayBuffer +// classes that would have to be individually handled here. +extern JS_FRIEND_API(void) +GetArrayBufferLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +} // namespace js + +/* + * Unwrap Typed arrays all at once. Return nullptr without throwing if the + * object cannot be viewed as the correct typed array, or the typed array + * object on success, filling both outparameters. + */ +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsInt8Array(JSObject *obj, uint32_t *length, int8_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsUint8Array(JSObject *obj, uint32_t *length, uint8_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsUint8ClampedArray(JSObject *obj, uint32_t *length, uint8_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsInt16Array(JSObject *obj, uint32_t *length, int16_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsUint16Array(JSObject *obj, uint32_t *length, uint16_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsInt32Array(JSObject *obj, uint32_t *length, int32_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsUint32Array(JSObject *obj, uint32_t *length, uint32_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsFloat32Array(JSObject *obj, uint32_t *length, float **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsFloat64Array(JSObject *obj, uint32_t *length, double **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsArrayBufferView(JSObject *obj, uint32_t *length, uint8_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsArrayBuffer(JSObject *obj, uint32_t *length, uint8_t **data); + +/* + * Get the type of elements in a typed array, or TypeMax if a DataView. + * + * |obj| must have passed a JS_IsArrayBufferView/JS_Is*Array test, or somehow + * be known that it would pass such a test: it is an ArrayBufferView or a + * wrapper of an ArrayBufferView, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(js::Scalar::Type) +JS_GetArrayBufferViewType(JSObject *obj); + +/* + * Check whether obj supports the JS_GetArrayBuffer* APIs. Note that this may + * return false if a security wrapper is encountered that denies the + * unwrapping. If this test succeeds, then it is safe to call the various + * accessor JSAPI calls defined below. + */ +extern JS_FRIEND_API(bool) +JS_IsArrayBufferObject(JSObject *obj); + +/* + * Return the available byte length of an array buffer. + * + * |obj| must have passed a JS_IsArrayBufferObject test, or somehow be known + * that it would pass such a test: it is an ArrayBuffer or a wrapper of an + * ArrayBuffer, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(uint32_t) +JS_GetArrayBufferByteLength(JSObject *obj); + +/* + * Check whether the obj is ArrayBufferObject and memory mapped. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. + */ +extern JS_FRIEND_API(bool) +JS_IsMappedArrayBufferObject(JSObject *obj); + +/* + * Return the number of elements in a typed array. + * + * |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow + * be known that it would pass such a test: it is a typed array or a wrapper of + * a typed array, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(uint32_t) +JS_GetTypedArrayLength(JSObject *obj); + +/* + * Return the byte offset from the start of an array buffer to the start of a + * typed array view. + * + * |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow + * be known that it would pass such a test: it is a typed array or a wrapper of + * a typed array, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(uint32_t) +JS_GetTypedArrayByteOffset(JSObject *obj); + +/* + * Return the byte length of a typed array. + * + * |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow + * be known that it would pass such a test: it is a typed array or a wrapper of + * a typed array, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(uint32_t) +JS_GetTypedArrayByteLength(JSObject *obj); + +/* + * Check whether obj supports JS_ArrayBufferView* APIs. Note that this may + * return false if a security wrapper is encountered that denies the + * unwrapping. + */ +extern JS_FRIEND_API(bool) +JS_IsArrayBufferViewObject(JSObject *obj); + +/* + * More generic name for JS_GetTypedArrayByteLength to cover DataViews as well + */ +extern JS_FRIEND_API(uint32_t) +JS_GetArrayBufferViewByteLength(JSObject *obj); + +/* + * Return a pointer to the start of the data referenced by a typed array. The + * data is still owned by the typed array, and should not be modified on + * another thread. Furthermore, the pointer can become invalid on GC (if the + * data is small and fits inside the array's GC header), so callers must take + * care not to hold on across anything that could GC. + * + * |obj| must have passed a JS_Is*Array test, or somehow be known that it would + * pass such a test: it is a typed array or a wrapper of a typed array, and the + * unwrapping will succeed. + */ + +extern JS_FRIEND_API(uint8_t *) +JS_GetArrayBufferData(JSObject *obj); +extern JS_FRIEND_API(int8_t *) +JS_GetInt8ArrayData(JSObject *obj); +extern JS_FRIEND_API(uint8_t *) +JS_GetUint8ArrayData(JSObject *obj); +extern JS_FRIEND_API(uint8_t *) +JS_GetUint8ClampedArrayData(JSObject *obj); +extern JS_FRIEND_API(int16_t *) +JS_GetInt16ArrayData(JSObject *obj); +extern JS_FRIEND_API(uint16_t *) +JS_GetUint16ArrayData(JSObject *obj); +extern JS_FRIEND_API(int32_t *) +JS_GetInt32ArrayData(JSObject *obj); +extern JS_FRIEND_API(uint32_t *) +JS_GetUint32ArrayData(JSObject *obj); +extern JS_FRIEND_API(float *) +JS_GetFloat32ArrayData(JSObject *obj); +extern JS_FRIEND_API(double *) +JS_GetFloat64ArrayData(JSObject *obj); + +/* + * Stable versions of the above functions where the buffer remains valid as long + * as the object is live. + */ +extern JS_FRIEND_API(uint8_t *) +JS_GetStableArrayBufferData(JSContext *cx, JS::HandleObject obj); + +/* + * Same as above, but for any kind of ArrayBufferView. Prefer the type-specific + * versions when possible. + */ +extern JS_FRIEND_API(void *) +JS_GetArrayBufferViewData(JSObject *obj); + +/* + * Return the ArrayBuffer underlying an ArrayBufferView. If the buffer has been + * neutered, this will still return the neutered buffer. |obj| must be an + * object that would return true for JS_IsArrayBufferViewObject(). + */ +extern JS_FRIEND_API(JSObject *) +JS_GetArrayBufferViewBuffer(JSContext *cx, JS::HandleObject obj); + +typedef enum { + ChangeData, + KeepData +} NeuterDataDisposition; + +/* + * Set an ArrayBuffer's length to 0 and neuter all of its views. + * + * The |changeData| argument is a hint to inform internal behavior with respect + * to the internal pointer to the ArrayBuffer's data after being neutered. + * There is no guarantee it will be respected. But if it is respected, the + * ArrayBuffer's internal data pointer will, or will not, have changed + * accordingly. + */ +extern JS_FRIEND_API(bool) +JS_NeuterArrayBuffer(JSContext *cx, JS::HandleObject obj, + NeuterDataDisposition changeData); + +/* + * Check whether the obj is ArrayBufferObject and neutered. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. + */ +extern JS_FRIEND_API(bool) +JS_IsNeuteredArrayBufferObject(JSObject *obj); + +/* + * Check whether obj supports JS_GetDataView* APIs. + */ +JS_FRIEND_API(bool) +JS_IsDataViewObject(JSObject *obj); + +/* + * Return the byte offset of a data view into its array buffer. |obj| must be a + * DataView. + * + * |obj| must have passed a JS_IsDataViewObject test, or somehow be known that + * it would pass such a test: it is a data view or a wrapper of a data view, + * and the unwrapping will succeed. + */ +JS_FRIEND_API(uint32_t) +JS_GetDataViewByteOffset(JSObject *obj); + +/* + * Return the byte length of a data view. + * + * |obj| must have passed a JS_IsDataViewObject test, or somehow be known that + * it would pass such a test: it is a data view or a wrapper of a data view, + * and the unwrapping will succeed. If cx is nullptr, then DEBUG builds may be + * unable to assert when unwrapping should be disallowed. + */ +JS_FRIEND_API(uint32_t) +JS_GetDataViewByteLength(JSObject *obj); + +/* + * Return a pointer to the beginning of the data referenced by a DataView. + * + * |obj| must have passed a JS_IsDataViewObject test, or somehow be known that + * it would pass such a test: it is a data view or a wrapper of a data view, + * and the unwrapping will succeed. If cx is nullptr, then DEBUG builds may be + * unable to assert when unwrapping should be disallowed. + */ +JS_FRIEND_API(void *) +JS_GetDataViewData(JSObject *obj); + +namespace js { + +/* + * Add a watchpoint -- in the Object.prototype.watch sense -- to |obj| for the + * property |id|, using the callable object |callable| as the function to be + * called for notifications. + * + * This is an internal function exposed -- temporarily -- only so that DOM + * proxies can be watchable. Don't use it! We'll soon kill off the + * Object.prototype.{,un}watch functions, at which point this will go too. + */ +extern JS_FRIEND_API(bool) +WatchGuts(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); + +/* + * Remove a watchpoint -- in the Object.prototype.watch sense -- from |obj| for + * the property |id|. + * + * This is an internal function exposed -- temporarily -- only so that DOM + * proxies can be watchable. Don't use it! We'll soon kill off the + * Object.prototype.{,un}watch functions, at which point this will go too. + */ +extern JS_FRIEND_API(bool) +UnwatchGuts(JSContext *cx, JS::HandleObject obj, JS::HandleId id); + +} // namespace js + +/* + * A class, expected to be passed by value, which represents the CallArgs for a + * JSJitGetterOp. + */ +class JSJitGetterCallArgs : protected JS::MutableHandleValue +{ + public: + explicit JSJitGetterCallArgs(const JS::CallArgs& args) + : JS::MutableHandleValue(args.rval()) + {} + + explicit JSJitGetterCallArgs(JS::RootedValue* rooted) + : JS::MutableHandleValue(rooted) + {} + + JS::MutableHandleValue rval() { + return *this; + } +}; + +/* + * A class, expected to be passed by value, which represents the CallArgs for a + * JSJitSetterOp. + */ +class JSJitSetterCallArgs : protected JS::MutableHandleValue +{ + public: + explicit JSJitSetterCallArgs(const JS::CallArgs& args) + : JS::MutableHandleValue(args[0]) + {} + + JS::MutableHandleValue operator[](unsigned i) { + MOZ_ASSERT(i == 0); + return *this; + } + + unsigned length() const { return 1; } + + // Add get() or maybe hasDefined() as needed +}; + +struct JSJitMethodCallArgsTraits; + +/* + * A class, expected to be passed by reference, which represents the CallArgs + * for a JSJitMethodOp. + */ +class JSJitMethodCallArgs : protected JS::detail::CallArgsBase +{ + private: + typedef JS::detail::CallArgsBase Base; + friend struct JSJitMethodCallArgsTraits; + + public: + explicit JSJitMethodCallArgs(const JS::CallArgs& args) { + argv_ = args.array(); + argc_ = args.length(); + } + + JS::MutableHandleValue rval() const { + return Base::rval(); + } + + unsigned length() const { return Base::length(); } + + JS::MutableHandleValue operator[](unsigned i) const { + return Base::operator[](i); + } + + bool hasDefined(unsigned i) const { + return Base::hasDefined(i); + } + + JSObject &callee() const { + // We can't use Base::callee() because that will try to poke at + // this->usedRval_, which we don't have. + return argv_[-2].toObject(); + } + + // Add get() as needed +}; + +struct JSJitMethodCallArgsTraits +{ + static const size_t offsetOfArgv = offsetof(JSJitMethodCallArgs, argv_); + static const size_t offsetOfArgc = offsetof(JSJitMethodCallArgs, argc_); +}; + +/* + * This struct contains metadata passed from the DOM to the JS Engine for JIT + * optimizations on DOM property accessors. Eventually, this should be made + * available to general JSAPI users, but we are not currently ready to do so. + */ +typedef bool +(* JSJitGetterOp)(JSContext *cx, JS::HandleObject thisObj, + void *specializedThis, JSJitGetterCallArgs args); +typedef bool +(* JSJitSetterOp)(JSContext *cx, JS::HandleObject thisObj, + void *specializedThis, JSJitSetterCallArgs args); +typedef bool +(* JSJitMethodOp)(JSContext *cx, JS::HandleObject thisObj, + void *specializedThis, const JSJitMethodCallArgs& args); + +struct JSJitInfo { + enum OpType { + Getter, + Setter, + Method, + ParallelNative, + StaticMethod, + // Must be last + OpTypeCount + }; + + enum ArgType { + // Basic types + String = (1 << 0), + Integer = (1 << 1), // Only 32-bit or less + Double = (1 << 2), // Maybe we want to add Float sometime too + Boolean = (1 << 3), + Object = (1 << 4), + Null = (1 << 5), + + // And derived types + Numeric = Integer | Double, + // Should "Primitive" use the WebIDL definition, which + // excludes string and null, or the typical JS one that includes them? + Primitive = Numeric | Boolean | Null | String, + ObjectOrNull = Object | Null, + Any = ObjectOrNull | Primitive, + + // Our sentinel value. + ArgTypeListEnd = (1 << 31) + }; + + static_assert(Any & String, "Any must include String."); + static_assert(Any & Integer, "Any must include Integer."); + static_assert(Any & Double, "Any must include Double."); + static_assert(Any & Boolean, "Any must include Boolean."); + static_assert(Any & Object, "Any must include Object."); + static_assert(Any & Null, "Any must include Null."); + + enum AliasSet { + // An enum that describes what this getter/setter/method aliases. This + // determines what things can be hoisted past this call, and if this + // call is movable what it can be hoisted past. + + // Alias nothing: a constant value, getting it can't affect any other + // values, nothing can affect it. + AliasNone, + + // Alias things that can modify the DOM but nothing else. Doing the + // call can't affect the behavior of any other function. + AliasDOMSets, + + // Alias the world. Calling this can change arbitrary values anywhere + // in the system. Most things fall in this bucket. + AliasEverything, + + // Must be last. + AliasSetCount + }; + + bool hasParallelNative() const + { + return type() == ParallelNative; + } + + bool needsOuterizedThisObject() const + { + return type() != Getter && type() != Setter; + } + + bool isTypedMethodJitInfo() const + { + return isTypedMethod; + } + + OpType type() const + { + return OpType(type_); + } + + AliasSet aliasSet() const + { + return AliasSet(aliasSet_); + } + + JSValueType returnType() const + { + return JSValueType(returnType_); + } + + union { + JSJitGetterOp getter; + JSJitSetterOp setter; + JSJitMethodOp method; + /* An alternative native that's safe to call in parallel mode. */ + JSParallelNative parallelNative; + /* A DOM static method, used for Promise wrappers */ + JSNative staticMethod; + }; + + uint16_t protoID; + uint16_t depth; + + // These fields are carefully packed to take up 4 bytes. If you need more + // bits for whatever reason, please see if you can steal bits from existing + // fields before adding more members to this structure. + +#define JITINFO_OP_TYPE_BITS 4 +#define JITINFO_ALIAS_SET_BITS 4 +#define JITINFO_RETURN_TYPE_BITS 8 + + // The OpType that says what sort of function we are. + uint32_t type_ : JITINFO_OP_TYPE_BITS; + + // The alias set for this op. This is a _minimal_ alias set; in + // particular for a method it does not include whatever argument + // conversions might do. That's covered by argTypes and runtime + // analysis of the actual argument types being passed in. + uint32_t aliasSet_ : JITINFO_ALIAS_SET_BITS; + + // The return type tag. Might be JSVAL_TYPE_UNKNOWN. + uint32_t returnType_ : JITINFO_RETURN_TYPE_BITS; + + static_assert(OpTypeCount <= (1 << JITINFO_OP_TYPE_BITS), + "Not enough space for OpType"); + static_assert(AliasSetCount <= (1 << JITINFO_ALIAS_SET_BITS), + "Not enough space for AliasSet"); + static_assert((sizeof(JSValueType) * 8) <= JITINFO_RETURN_TYPE_BITS, + "Not enough space for JSValueType"); + +#undef JITINFO_RETURN_TYPE_BITS +#undef JITINFO_ALIAS_SET_BITS +#undef JITINFO_OP_TYPE_BITS + + uint32_t isInfallible : 1; /* Is op fallible? False in setters. */ + uint32_t isMovable : 1; /* Is op movable? To be movable the op must + not AliasEverything, but even that might + not be enough (e.g. in cases when it can + throw). */ + // XXXbz should we have a JSValueType for the type of the member? + uint32_t isAlwaysInSlot : 1; /* True if this is a getter that can always + get the value from a slot of the "this" + object. */ + uint32_t isLazilyCachedInSlot : 1; /* True if this is a getter that can + sometimes (if the slot doesn't contain + UndefinedValue()) get the value from a + slot of the "this" object. */ + uint32_t isTypedMethod : 1; /* True if this is an instance of + JSTypedMethodJitInfo. */ + uint32_t slotIndex : 11; /* If isAlwaysInSlot or isSometimesInSlot is + true, the index of the slot to get the value + from. Otherwise 0. */ +}; + +static_assert(sizeof(JSJitInfo) == (sizeof(void*) + 2 * sizeof(uint32_t)), + "There are several thousand instances of JSJitInfo stored in " + "a binary. Please don't increase its space requirements without " + "verifying that there is no other way forward (better packing, " + "smaller datatypes for fields, subclassing, etc.)."); + +struct JSTypedMethodJitInfo +{ + // We use C-style inheritance here, rather than C++ style inheritance + // because not all compilers support brace-initialization for non-aggregate + // classes. Using C++ style inheritance and constructors instead of + // brace-initialization would also force the creation of static + // constructors (on some compilers) when JSJitInfo and JSTypedMethodJitInfo + // structures are declared. Since there can be several thousand of these + // structures present and we want to have roughly equivalent performance + // across a range of compilers, we do things manually. + JSJitInfo base; + + const JSJitInfo::ArgType* const argTypes; /* For a method, a list of sets of + types that the function + expects. This can be used, + for example, to figure out + when argument coercions can + have side-effects. */ +}; + +namespace JS { +namespace detail { + +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_PARALLEL_NATIVE_TO only. */ +inline int CheckIsParallelNative(JSParallelNative parallelNative); + +} // namespace detail +} // namespace JS + +#define JS_CAST_PARALLEL_NATIVE_TO(v, To) \ + (static_cast(sizeof(JS::detail::CheckIsParallelNative(v))), \ + reinterpret_cast(v)) + +/* + * You may ask yourself: why do we define a wrapper around a wrapper here? + * The answer is that some compilers don't understand initializing a union + * as we do below with a construct like: + * + * reinterpret_cast(JSParallelNativeThreadSafeWrapper) + * + * (We need the reinterpret_cast because we must initialize the union with + * a datum of the type of the union's first member.) + * + * Presumably this has something to do with template instantiation. + * Initializing with a normal function pointer seems to work fine. Hence + * the ugliness that you see before you. + */ +#define JS_JITINFO_NATIVE_PARALLEL(infoName, parallelOp) \ + const JSJitInfo infoName = \ + {{JS_CAST_PARALLEL_NATIVE_TO(parallelOp, JSJitGetterOp)},0,0,JSJitInfo::ParallelNative,JSJitInfo::AliasEverything,JSVAL_TYPE_MISSING,false,false,false,false,false,0} + +#define JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(infoName, wrapperName, serialOp) \ + bool wrapperName##_ParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, \ + JS::Value *vp) \ + { \ + return JSParallelNativeThreadSafeWrapper(cx, argc, vp); \ + } \ + JS_JITINFO_NATIVE_PARALLEL(infoName, wrapperName##_ParallelNativeThreadSafeWrapper) + +static MOZ_ALWAYS_INLINE const JSJitInfo * +FUNCTION_VALUE_TO_JITINFO(const JS::Value& v) +{ + JS_ASSERT(js::GetObjectClass(&v.toObject()) == js::FunctionClassPtr); + return reinterpret_cast(&v.toObject())->jitinfo; +} + +/* Statically asserted in jsfun.h. */ +static const unsigned JS_FUNCTION_INTERPRETED_BIT = 0x1; + +static MOZ_ALWAYS_INLINE void +SET_JITINFO(JSFunction * func, const JSJitInfo *info) +{ + js::shadow::Function *fun = reinterpret_cast(func); + JS_ASSERT(!(fun->flags & JS_FUNCTION_INTERPRETED_BIT)); + fun->jitinfo = info; +} + +/* + * Engine-internal extensions of jsid. This code is here only until we + * eliminate Gecko's dependencies on it! + */ + +static MOZ_ALWAYS_INLINE jsid +JSID_FROM_BITS(size_t bits) +{ + jsid id; + JSID_BITS(id) = bits; + return id; +} + +namespace js { +namespace detail { +bool IdMatchesAtom(jsid id, JSAtom *atom); +} +} + +/* + * Must not be used on atoms that are representable as integer jsids. + * Prefer NameToId or AtomToId over this function: + * + * A PropertyName is an atom that does not contain an integer in the range + * [0, UINT32_MAX]. However, jsid can only hold an integer in the range + * [0, JSID_INT_MAX] (where JSID_INT_MAX == 2^31-1). Thus, for the range of + * integers (JSID_INT_MAX, UINT32_MAX], to represent as a jsid 'id', it must be + * the case JSID_IS_ATOM(id) and !JSID_TO_ATOM(id)->isPropertyName(). In most + * cases when creating a jsid, code does not have to care about this corner + * case because: + * + * - When given an arbitrary JSAtom*, AtomToId must be used, which checks for + * integer atoms representable as integer jsids, and does this conversion. + * + * - When given a PropertyName*, NameToId can be used which which does not need + * to do any dynamic checks. + * + * Thus, it is only the rare third case which needs this function, which + * handles any JSAtom* that is known not to be representable with an int jsid. + */ +static MOZ_ALWAYS_INLINE jsid +NON_INTEGER_ATOM_TO_JSID(JSAtom *atom) +{ + JS_ASSERT(((size_t)atom & 0x7) == 0); + jsid id = JSID_FROM_BITS((size_t)atom); + JS_ASSERT(js::detail::IdMatchesAtom(id, atom)); + return id; +} + +/* All strings stored in jsids are atomized, but are not necessarily property names. */ +static MOZ_ALWAYS_INLINE bool +JSID_IS_ATOM(jsid id) +{ + return JSID_IS_STRING(id); +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_ATOM(jsid id, JSAtom *atom) +{ + return id == JSID_FROM_BITS((size_t)atom); +} + +static MOZ_ALWAYS_INLINE JSAtom * +JSID_TO_ATOM(jsid id) +{ + return (JSAtom *)JSID_TO_STRING(id); +} + +JS_STATIC_ASSERT(sizeof(jsid) == sizeof(void*)); + +namespace js { + +static MOZ_ALWAYS_INLINE JS::Value +IdToValue(jsid id) +{ + if (JSID_IS_STRING(id)) + return JS::StringValue(JSID_TO_STRING(id)); + if (JSID_IS_INT(id)) + return JS::Int32Value(JSID_TO_INT(id)); + if (JSID_IS_SYMBOL(id)) + return JS::SymbolValue(JSID_TO_SYMBOL(id)); + JS_ASSERT(JSID_IS_VOID(id)); + return JS::UndefinedValue(); +} + +/* + * If the embedder has registered a default JSContext callback, returns the + * result of the callback. Otherwise, asserts that |rt| has exactly one + * JSContext associated with it, and returns that context. + */ +extern JS_FRIEND_API(JSContext *) +DefaultJSContext(JSRuntime *rt); + +typedef JSContext* +(* DefaultJSContextCallback)(JSRuntime *rt); + +JS_FRIEND_API(void) +SetDefaultJSContextCallback(JSRuntime *rt, DefaultJSContextCallback cb); + +/* + * To help embedders enforce their invariants, we allow them to specify in + * advance which JSContext should be passed to JSAPI calls. If this is set + * to a non-null value, the assertSameCompartment machinery does double- + * duty (in debug builds) to verify that it matches the cx being used. + */ +#ifdef DEBUG +JS_FRIEND_API(void) +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx); +#else +inline void +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx) {}; +#endif + + +enum CTypesActivityType { + CTYPES_CALL_BEGIN, + CTYPES_CALL_END, + CTYPES_CALLBACK_BEGIN, + CTYPES_CALLBACK_END +}; + +typedef void +(* CTypesActivityCallback)(JSContext *cx, CTypesActivityType type); + +/* + * Sets a callback that is run whenever js-ctypes is about to be used when + * calling into C. + */ +JS_FRIEND_API(void) +SetCTypesActivityCallback(JSRuntime *rt, CTypesActivityCallback cb); + +class JS_FRIEND_API(AutoCTypesActivityCallback) { + private: + JSContext *cx; + CTypesActivityCallback callback; + CTypesActivityType endType; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + public: + AutoCTypesActivityCallback(JSContext *cx, CTypesActivityType beginType, + CTypesActivityType endType + MOZ_GUARD_OBJECT_NOTIFIER_PARAM); + ~AutoCTypesActivityCallback() { + DoEndCallback(); + } + void DoEndCallback() { + if (callback) { + callback(cx, endType); + callback = nullptr; + } + } +}; + +typedef bool +(* ObjectMetadataCallback)(JSContext *cx, JSObject **pmetadata); + +/* + * Specify a callback to invoke when creating each JS object in the current + * compartment, which may return a metadata object to associate with the + * object. Objects with different metadata have different shape hierarchies, + * so for efficiency, objects should generally try to share metadata objects. + */ +JS_FRIEND_API(void) +SetObjectMetadataCallback(JSContext *cx, ObjectMetadataCallback callback); + +/* Manipulate the metadata associated with an object. */ + +JS_FRIEND_API(bool) +SetObjectMetadata(JSContext *cx, JS::HandleObject obj, JS::HandleObject metadata); + +JS_FRIEND_API(JSObject *) +GetObjectMetadata(JSObject *obj); + +JS_FRIEND_API(void) +UnsafeDefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value); + +JS_FRIEND_API(bool) +SliceSlowly(JSContext* cx, JS::HandleObject obj, JS::HandleObject receiver, + uint32_t begin, uint32_t end, JS::HandleObject result); + +/* ES5 8.12.8. */ +extern JS_FRIEND_API(bool) +DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandleValue vp); + +/* + * Helper function. To approximate a call to the [[DefineOwnProperty]] internal + * method described in ES5, first call this, then call JS_DefinePropertyById. + * + * JS_DefinePropertyById by itself does not enforce the invariants on + * non-configurable properties when obj->isNative(). This function performs the + * relevant checks (specified in ES5 8.12.9 [[DefineOwnProperty]] steps 1-11), + * but only if obj is native. + * + * The reason for the messiness here is that ES5 uses [[DefineOwnProperty]] as + * a sort of extension point, but there is no hook in js::Class, + * js::ProxyHandler, or the JSAPI with precisely the right semantics for it. + */ +extern JS_FRIEND_API(bool) +CheckDefineProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +/* + * Helper function for HTMLDocument and HTMLFormElement. + * + * These are the only two interfaces that have [OverrideBuiltins], a named + * getter, and no named setter. They're implemented as proxies with a custom + * getOwnPropertyDescriptor() method. Unfortunately, overriding + * getOwnPropertyDescriptor() automatically affects the behavior of set(), + * which normally is just common sense but is *not* desired for these two + * interfaces. + * + * The fix is for these two interfaces to override set() to ignore the + * getOwnPropertyDescriptor() override. + * + * SetPropertyIgnoringNamedGetter is exposed to make it easier to override + * set() in this way. It carries out all the steps of BaseProxyHandler::set() + * except the initial getOwnPropertyDescriptor()/getPropertyDescriptor() calls. + * The caller must supply those results as the 'desc' and 'descIsOwn' + * parameters. + * + * Implemented in jsproxy.cpp. + */ +JS_FRIEND_API(bool) +SetPropertyIgnoringNamedGetter(JSContext *cx, const BaseProxyHandler *handler, + JS::HandleObject proxy, JS::HandleObject receiver, + JS::HandleId id, JS::MutableHandle desc, + bool descIsOwn, bool strict, JS::MutableHandleValue vp); + +JS_FRIEND_API(void) +ReportErrorWithId(JSContext *cx, const char *msg, JS::HandleId id); + +// This function is for one specific use case, please don't use this for anything else! +extern JS_FRIEND_API(bool) +ExecuteInGlobalAndReturnScope(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleObject scope); + +} /* namespace js */ + +extern JS_FRIEND_API(bool) +js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg, + JS::Handle descriptor, bool *bp); + +extern JS_FRIEND_API(bool) +js_ReportIsNotFunction(JSContext *cx, JS::HandleValue v); + +#ifdef JSGC_GENERATIONAL +extern JS_FRIEND_API(void) +JS_StoreObjectPostBarrierCallback(JSContext* cx, + void (*callback)(JSTracer *trc, JSObject *key, void *data), + JSObject *key, void *data); + +extern JS_FRIEND_API(void) +JS_StoreStringPostBarrierCallback(JSContext* cx, + void (*callback)(JSTracer *trc, JSString *key, void *data), + JSString *key, void *data); +#else +inline void +JS_StoreObjectPostBarrierCallback(JSContext* cx, + void (*callback)(JSTracer *trc, JSObject *key, void *data), + JSObject *key, void *data) {} + +inline void +JS_StoreStringPostBarrierCallback(JSContext* cx, + void (*callback)(JSTracer *trc, JSString *key, void *data), + JSString *key, void *data) {} +#endif /* JSGC_GENERATIONAL */ + +#endif /* jsfriendapi_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/jsprf.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsprf.h new file mode 100644 index 0000000000..bfedf98ca8 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsprf.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsprf_h +#define jsprf_h + +/* +** API for PR printf like routines. Supports the following formats +** %d - decimal +** %u - unsigned decimal +** %x - unsigned hex +** %X - unsigned uppercase hex +** %o - unsigned octal +** %hd, %hu, %hx, %hX, %ho - 16-bit versions of above +** %ld, %lu, %lx, %lX, %lo - 32-bit versions of above +** %lld, %llu, %llx, %llX, %llo - 64 bit versions of above +** %s - ascii string +** %hs - ucs2 string +** %c - character +** %p - pointer (deals with machine dependent pointer size) +** %f - float +** %g - float +*/ + +#include + +#include "jstypes.h" + +/* +** sprintf into a fixed size buffer. Guarantees that a NUL is at the end +** of the buffer. Returns the length of the written output, NOT including +** the NUL, or (uint32_t)-1 if an error occurs. +*/ +extern JS_PUBLIC_API(uint32_t) JS_snprintf(char *out, uint32_t outlen, const char *fmt, ...); + +/* +** sprintf into a malloc'd buffer. Return a pointer to the malloc'd +** buffer on success, nullptr on failure. Call "JS_smprintf_free" to release +** the memory returned. +*/ +extern JS_PUBLIC_API(char*) JS_smprintf(const char *fmt, ...); + +/* +** Free the memory allocated, for the caller, by JS_smprintf +*/ +extern JS_PUBLIC_API(void) JS_smprintf_free(char *mem); + +/* +** "append" sprintf into a malloc'd buffer. "last" is the last value of +** the malloc'd buffer. sprintf will append data to the end of last, +** growing it as necessary using realloc. If last is nullptr, JS_sprintf_append +** will allocate the initial string. The return value is the new value of +** last for subsequent calls, or nullptr if there is a malloc failure. +*/ +extern JS_PUBLIC_API(char*) JS_sprintf_append(char *last, const char *fmt, ...); + +/* +** va_list forms of the above. +*/ +extern JS_PUBLIC_API(uint32_t) JS_vsnprintf(char *out, uint32_t outlen, const char *fmt, va_list ap); +extern JS_PUBLIC_API(char*) JS_vsmprintf(const char *fmt, va_list ap); +extern JS_PUBLIC_API(char*) JS_vsprintf_append(char *last, const char *fmt, va_list ap); + +#endif /* jsprf_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/jsprototypes.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsprototypes.h new file mode 100644 index 0000000000..1cb56bf8da --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsprototypes.h @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsprototypes_h +#define jsprototypes_h + +/* A higher-order macro for enumerating all JSProtoKey values. */ +/* + * Consumers define macros as follows: + * macro(name, code, init, clasp) + * name: The canonical name of the class. + * code: The enumerator code. There are part of the XDR API, and must not change. + * init: Initialization function. These are |extern "C";|, and clients should use + * |extern "C" {}| as appropriate when using this macro. + * clasp: The JSClass for this object, or "dummy" if it doesn't exist. + * + * + * Consumers wishing to iterate over all the JSProtoKey values, can use + * JS_FOR_EACH_PROTOTYPE. However, there are certain values that don't correspond + * to real constructors, like Null or constructors that are disabled via + * preprocessor directives. We still need to include these in the JSProtoKey list + * in order to maintain binary XDR compatibility, but we need to provide a tool + * to handle them differently. JS_FOR_PROTOTYPES fills this niche. + * + * Consumers pass two macros to JS_FOR_PROTOTYPES - |real| and |imaginary|. The + * former is invoked for entries that have real client-exposed constructors, and + * the latter is called for the rest. Consumers that don't care about this + * distinction can simply pass the same macro to both, which is exactly what + * JS_FOR_EACH_PROTOTYPE does. + */ + +#define CLASP(name) (&name##Class) +#define OCLASP(name) (&name##Object::class_) +#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[Scalar::type]) + +#ifdef ENABLE_PARALLEL_JS +#define IF_PJS(real,imaginary) real +#else +#define IF_PJS(real,imaginary) imaginary +#endif + +#ifdef EXPOSE_INTL_API +#define IF_INTL(real,imaginary) real +#else +#define IF_INTL(real,imaginary) imaginary +#endif + +#ifdef ENABLE_BINARYDATA +#define IF_BDATA(real,imaginary) real +#else +#define IF_BDATA(real,imaginary) imaginary +#endif + +#ifdef ENABLE_SHARED_ARRAY_BUFFER +#define IF_SAB(real,imaginary) real +#else +#define IF_SAB(real,imaginary) imaginary +#endif + +#ifdef JS_HAS_SYMBOLS +#define IF_SYMBOLS(real,imaginary) real +#else +#define IF_SYMBOLS(real,imaginary) imaginary +#endif + +#define JS_FOR_PROTOTYPES(real,imaginary) \ + imaginary(Null, 0, js_InitNullClass, dummy) \ + real(Object, 1, js_InitViaClassSpec, &JSObject::class_) \ + real(Function, 2, js_InitViaClassSpec, &JSFunction::class_) \ + real(Array, 3, js_InitViaClassSpec, OCLASP(Array)) \ + real(Boolean, 4, js_InitBooleanClass, OCLASP(Boolean)) \ + real(JSON, 5, js_InitJSONClass, CLASP(JSON)) \ + real(Date, 6, js_InitViaClassSpec, OCLASP(Date)) \ + real(Math, 7, js_InitMathClass, CLASP(Math)) \ + real(Number, 8, js_InitNumberClass, OCLASP(Number)) \ + real(String, 9, js_InitStringClass, OCLASP(String)) \ + real(RegExp, 10, js_InitRegExpClass, OCLASP(RegExp)) \ + real(Error, 11, js_InitViaClassSpec, OCLASP(Error)) \ + real(InternalError, 12, js_InitViaClassSpec, OCLASP(Error)) \ + real(EvalError, 13, js_InitViaClassSpec, OCLASP(Error)) \ + real(RangeError, 14, js_InitViaClassSpec, OCLASP(Error)) \ + real(ReferenceError, 15, js_InitViaClassSpec, OCLASP(Error)) \ + real(SyntaxError, 16, js_InitViaClassSpec, OCLASP(Error)) \ + real(TypeError, 17, js_InitViaClassSpec, OCLASP(Error)) \ + real(URIError, 18, js_InitViaClassSpec, OCLASP(Error)) \ + real(Iterator, 19, js_InitIteratorClasses, OCLASP(PropertyIterator)) \ + real(StopIteration, 20, js_InitIteratorClasses, OCLASP(StopIteration)) \ + real(ArrayBuffer, 21, js_InitArrayBufferClass, &js::ArrayBufferObject::protoClass) \ + real(Int8Array, 22, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int8)) \ + real(Uint8Array, 23, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8)) \ + real(Int16Array, 24, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int16)) \ + real(Uint16Array, 25, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint16)) \ + real(Int32Array, 26, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int32)) \ + real(Uint32Array, 27, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint32)) \ + real(Float32Array, 28, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float32)) \ + real(Float64Array, 29, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float64)) \ + real(Uint8ClampedArray, 30, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8Clamped)) \ + real(Proxy, 31, js_InitProxyClass, &ProxyObject::uncallableClass_) \ + real(WeakMap, 32, js_InitWeakMapClass, OCLASP(WeakMap)) \ + real(Map, 33, js_InitMapClass, OCLASP(Map)) \ + real(Set, 34, js_InitSetClass, OCLASP(Set)) \ + real(DataView, 35, js_InitDataViewClass, OCLASP(DataView)) \ +IF_SYMBOLS(real,imaginary)(Symbol, 36, js_InitSymbolClass, &js::SymbolObject::class_) \ +IF_SAB(real,imaginary)(SharedArrayBuffer, 37, js_InitSharedArrayBufferClass, &js::SharedArrayBufferObject::protoClass) \ +IF_INTL(real,imaginary) (Intl, 38, js_InitIntlClass, CLASP(Intl)) \ +IF_BDATA(real,imaginary)(TypedObject, 39, js_InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \ + imaginary(GeneratorFunction, 40, js_InitIteratorClasses, dummy) \ +IF_BDATA(real,imaginary)(SIMD, 41, js_InitSIMDClass, OCLASP(SIMD)) \ + +#define JS_FOR_EACH_PROTOTYPE(macro) JS_FOR_PROTOTYPES(macro,macro) + +#endif /* jsprototypes_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/jsproxy.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsproxy.h new file mode 100644 index 0000000000..b4588c4c2a --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsproxy.h @@ -0,0 +1,563 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsproxy_h +#define jsproxy_h + +#include "mozilla/Maybe.h" + +#include "jsfriendapi.h" + +#include "js/CallNonGenericMethod.h" +#include "js/Class.h" + +namespace js { + +using JS::AutoIdVector; +using JS::CallArgs; +using JS::HandleId; +using JS::HandleObject; +using JS::HandleValue; +using JS::IsAcceptableThis; +using JS::MutableHandle; +using JS::MutableHandleObject; +using JS::MutableHandleValue; +using JS::NativeImpl; +using JS::PrivateValue; +using JS::Value; + +class RegExpGuard; +class JS_FRIEND_API(Wrapper); + +/* + * A proxy is a JSObject that implements generic behavior by providing custom + * implementations for each object trap. The implementation for each trap is + * provided by a C++ object stored on the proxy, known as its handler. + * + * A major use case for proxies is to forward each trap to another object, + * known as its target. The target can be an arbitrary C++ object. Not every + * proxy has the notion of a target, however. + * + * Proxy traps are grouped into fundamental and derived traps. Every proxy has + * to at least provide implementations for the fundamental traps, but the + * derived traps can be implemented in terms of the fundamental ones + * BaseProxyHandler provides implementations of the derived traps in terms of + * the (pure virtual) fundamental traps. + * + * In addition to the normal traps, there are two models for proxy prototype + * chains. First, proxies may opt to use the standard prototype mechanism used + * throughout the engine. To do so, simply pass a prototype to NewProxyObject() + * at creation time. All prototype accesses will then "just work" to treat the + * proxy as a "normal" object. Alternatively, if instead the proxy wishes to + * implement more complicated prototype semantics (if, for example, it wants to + * delegate the prototype lookup to a wrapped object), it may pass Proxy::LazyProto + * as the prototype at create time and opt in to the trapped prototype system, + * which guarantees that their trap will be called on any and every prototype + * chain access of the object. + * + * This system is implemented with two traps: {get,set}PrototypeOf. The default + * implementation of setPrototypeOf throws a TypeError. Since it is not possible + * to create an object without a sense of prototype chain, handler implementors + * must provide a getPrototypeOf trap if opting in to the dynamic prototype system. + * + * To minimize code duplication, a set of abstract proxy handler classes is + * provided, from which other handlers may inherit. These abstract classes + * are organized in the following hierarchy: + * + * BaseProxyHandler + * | + * DirectProxyHandler + * | + * Wrapper + */ + +/* + * BaseProxyHandler is the most generic kind of proxy handler. It does not make + * any assumptions about the target. Consequently, it does not provide any + * default implementation for the fundamental traps. It does, however, implement + * the derived traps in terms of the fundamental ones. This allows consumers of + * this class to define any custom behavior they want. + * + * Important: If you add a trap here, you should probably also add a Proxy::foo + * entry point with an AutoEnterPolicy. If you don't, you need an explicit + * override for the trap in SecurityWrapper. See bug 945826 comment 0. + */ +class JS_FRIEND_API(BaseProxyHandler) +{ + const void *mFamily; + + /* + * Proxy handlers can use mHasPrototype to request the following special + * treatment from the JS engine: + * + * - When mHasPrototype is true, the engine never calls these methods: + * getPropertyDescriptor, has, set, enumerate, iterate. Instead, for + * these operations, it calls the "own" traps like + * getOwnPropertyDescriptor, hasOwn, defineProperty, keys, etc., and + * consults the prototype chain if needed. + * + * - When mHasPrototype is true, the engine calls handler->get() only if + * handler->hasOwn() says an own property exists on the proxy. If not, + * it consults the prototype chain. + * + * This is useful because it frees the ProxyHandler from having to implement + * any behavior having to do with the prototype chain. + */ + bool mHasPrototype; + + /* + * All proxies indicate whether they have any sort of interesting security + * policy that might prevent the caller from doing something it wants to + * the object. In the case of wrappers, this distinction is used to + * determine whether the caller may strip off the wrapper if it so desires. + */ + bool mHasSecurityPolicy; + + public: + explicit BaseProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); + virtual ~BaseProxyHandler(); + + bool hasPrototype() const { + return mHasPrototype; + } + + bool hasSecurityPolicy() const { + return mHasSecurityPolicy; + } + + inline const void *family() const { + return mFamily; + } + static size_t offsetOfFamily() { + return offsetof(BaseProxyHandler, mFamily); + } + + virtual bool finalizeInBackground(Value priv) const { + /* + * Called on creation of a proxy to determine whether its finalize + * method can be finalized on the background thread. + */ + return true; + } + + /* Policy enforcement traps. + * + * enter() allows the policy to specify whether the caller may perform |act| + * on the proxy's |id| property. In the case when |act| is CALL, |id| is + * generally JSID_VOID. + * + * The |act| parameter to enter() specifies the action being performed. + * If |bp| is false, the trap suggests that the caller throw (though it + * may still decide to squelch the error). + * + * We make these OR-able so that assertEnteredPolicy can pass a union of them. + * For example, get{,Own}PropertyDescriptor is invoked by both calls to ::get() + * and ::set() (since we need to look up the accessor), so its + * assertEnteredPolicy would pass GET | SET. + */ + typedef uint32_t Action; + enum { + NONE = 0x00, + GET = 0x01, + SET = 0x02, + CALL = 0x04, + ENUMERATE = 0x08 + }; + + virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Action act, + bool *bp) const; + + /* ES5 Harmony fundamental proxy traps. */ + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const = 0; + virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const = 0; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, + HandleId id, MutableHandle desc) const = 0; + virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const = 0; + virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, + AutoIdVector &props) const = 0; + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const = 0; + virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) const = 0; + + /* ES5 Harmony derived proxy traps. */ + virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; + virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; + virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, + HandleId id, MutableHandleValue vp) const; + virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, + HandleId id, bool strict, MutableHandleValue vp) const; + virtual bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props) const; + virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, + MutableHandleValue vp) const; + + /* Spidermonkey extensions. */ + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const = 0; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args) const; + virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp) const; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx) const; + virtual const char *className(JSContext *cx, HandleObject proxy) const; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const; + virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp) const; + virtual void finalize(JSFreeOp *fop, JSObject *proxy) const; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop) const; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp) const; + + // These two hooks must be overridden, or not overridden, in tandem -- no + // overriding just one! + virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, + JS::HandleObject callable) const; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const; + + virtual bool slice(JSContext *cx, HandleObject proxy, uint32_t begin, uint32_t end, + HandleObject result) const; + + /* See comment for weakmapKeyDelegateOp in js/Class.h. */ + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const; + virtual bool isScripted() const { return false; } +}; + +/* + * DirectProxyHandler includes a notion of a target object. All traps are + * reimplemented such that they forward their behavior to the target. This + * allows consumers of this class to forward to another object as transparently + * and efficiently as possible. + * + * Important: If you add a trap implementation here, you probably also need to + * add an override in CrossCompartmentWrapper. If you don't, you risk + * compartment mismatches. See bug 945826 comment 0. + */ +class JS_PUBLIC_API(DirectProxyHandler) : public BaseProxyHandler +{ + public: + explicit DirectProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); + + /* ES5 Harmony fundamental proxy traps. */ + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, + bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject proxy, + AutoIdVector &props) const MOZ_OVERRIDE; + + /* ES5 Harmony derived proxy traps. */ + virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, + bool *bp) const MOZ_OVERRIDE; + virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, + bool *bp) const MOZ_OVERRIDE; + virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool keys(JSContext *cx, HandleObject proxy, + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, + MutableHandleValue vp) const MOZ_OVERRIDE; + + /* Spidermonkey extensions. */ + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, + CallArgs args) const MOZ_OVERRIDE; + virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, + bool *bp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, + unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, + RegExpGuard *g) const MOZ_OVERRIDE; + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const MOZ_OVERRIDE; +}; + +/* + * Dispatch point for handlers that executes the appropriate C++ or scripted traps. + * + * Important: All proxy traps need either (a) an AutoEnterPolicy in their + * Proxy::foo entry point below or (b) an override in SecurityWrapper. See bug + * 945826 comment 0. + */ +class Proxy +{ + public: + /* ES5 Harmony fundamental proxy traps. */ + static bool preventExtensions(JSContext *cx, HandleObject proxy); + static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc); + static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandleValue vp); + static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc); + static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandleValue vp); + static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc); + static bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props); + static bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); + static bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props); + + /* ES5 Harmony derived proxy traps. */ + static bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); + static bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); + static bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, + MutableHandleValue vp); + static bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, + bool strict, MutableHandleValue vp); + static bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props); + static bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, MutableHandleValue vp); + + /* Spidermonkey extensions. */ + static bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible); + static bool call(JSContext *cx, HandleObject proxy, const CallArgs &args); + static bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args); + static bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args); + static bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp); + static bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx); + static const char *className(JSContext *cx, HandleObject proxy); + static JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent); + static bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g); + static bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); + static bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + static bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp); + + static bool watch(JSContext *cx, HandleObject proxy, HandleId id, HandleObject callable); + static bool unwatch(JSContext *cx, HandleObject proxy, HandleId id); + + static bool slice(JSContext *cx, HandleObject obj, uint32_t begin, uint32_t end, + HandleObject result); + + /* IC entry path for handling __noSuchMethod__ on access. */ + static bool callProp(JSContext *cx, HandleObject proxy, HandleObject reveiver, HandleId id, + MutableHandleValue vp); +}; + +// Use these in places where you don't want to #include vm/ProxyObject.h. +extern JS_FRIEND_DATA(const js::Class* const) CallableProxyClassPtr; +extern JS_FRIEND_DATA(const js::Class* const) UncallableProxyClassPtr; + +inline bool IsProxy(JSObject *obj) +{ + return GetObjectClass(obj)->isProxy(); +} + +/* + * These are part of the API. + * + * NOTE: PROXY_PRIVATE_SLOT is 0 because that way slot 0 is usable by API + * clients for both proxy and non-proxy objects. So an API client that only + * needs to store one slot's worth of data doesn't need to branch on what sort + * of object it has. + */ +const uint32_t PROXY_PRIVATE_SLOT = 0; +const uint32_t PROXY_HANDLER_SLOT = 1; +const uint32_t PROXY_EXTRA_SLOT = 2; +const uint32_t PROXY_MINIMUM_SLOTS = 4; + +inline const BaseProxyHandler * +GetProxyHandler(JSObject *obj) +{ + JS_ASSERT(IsProxy(obj)); + return (const BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate(); +} + +inline const Value & +GetProxyPrivate(JSObject *obj) +{ + JS_ASSERT(IsProxy(obj)); + return GetReservedSlot(obj, PROXY_PRIVATE_SLOT); +} + +inline JSObject * +GetProxyTargetObject(JSObject *obj) +{ + JS_ASSERT(IsProxy(obj)); + return GetProxyPrivate(obj).toObjectOrNull(); +} + +inline const Value & +GetProxyExtra(JSObject *obj, size_t n) +{ + JS_ASSERT(IsProxy(obj)); + return GetReservedSlot(obj, PROXY_EXTRA_SLOT + n); +} + +inline void +SetProxyHandler(JSObject *obj, BaseProxyHandler *handler) +{ + JS_ASSERT(IsProxy(obj)); + SetReservedSlot(obj, PROXY_HANDLER_SLOT, PrivateValue(handler)); +} + +inline void +SetProxyExtra(JSObject *obj, size_t n, const Value &extra) +{ + JS_ASSERT(IsProxy(obj)); + JS_ASSERT(n <= 1); + SetReservedSlot(obj, PROXY_EXTRA_SLOT + n, extra); +} + +inline bool +IsScriptedProxy(JSObject *obj) +{ + return IsProxy(obj) && GetProxyHandler(obj)->isScripted(); +} + +class MOZ_STACK_CLASS ProxyOptions { + protected: + /* protected constructor for subclass */ + ProxyOptions(bool singletonArg, const Class *claspArg) + : singleton_(singletonArg), + clasp_(claspArg) + {} + + public: + ProxyOptions() : singleton_(false), + clasp_(UncallableProxyClassPtr) + {} + + bool singleton() const { return singleton_; } + ProxyOptions &setSingleton(bool flag) { + singleton_ = flag; + return *this; + } + + const Class *clasp() const { + return clasp_; + } + ProxyOptions &setClass(const Class *claspArg) { + clasp_ = claspArg; + return *this; + } + ProxyOptions &selectDefaultClass(bool callable) { + const Class *classp = callable? CallableProxyClassPtr : + UncallableProxyClassPtr; + return setClass(classp); + } + + private: + bool singleton_; + const Class *clasp_; +}; + +JS_FRIEND_API(JSObject *) +NewProxyObject(JSContext *cx, const BaseProxyHandler *handler, HandleValue priv, + JSObject *proto, JSObject *parent, const ProxyOptions &options = ProxyOptions()); + +JSObject * +RenewProxyObject(JSContext *cx, JSObject *obj, BaseProxyHandler *handler, Value priv); + +class JS_FRIEND_API(AutoEnterPolicy) +{ + public: + typedef BaseProxyHandler::Action Action; + AutoEnterPolicy(JSContext *cx, const BaseProxyHandler *handler, + HandleObject wrapper, HandleId id, Action act, bool mayThrow) +#ifdef JS_DEBUG + : context(nullptr) +#endif + { + allow = handler->hasSecurityPolicy() ? handler->enter(cx, wrapper, id, act, &rv) + : true; + recordEnter(cx, wrapper, id, act); + // We want to throw an exception if all of the following are true: + // * The policy disallowed access. + // * The policy set rv to false, indicating that we should throw. + // * The caller did not instruct us to ignore exceptions. + // * The policy did not throw itself. + if (!allow && !rv && mayThrow) + reportErrorIfExceptionIsNotPending(cx, id); + } + + virtual ~AutoEnterPolicy() { recordLeave(); } + inline bool allowed() { return allow; } + inline bool returnValue() { JS_ASSERT(!allowed()); return rv; } + + protected: + // no-op constructor for subclass + AutoEnterPolicy() +#ifdef JS_DEBUG + : context(nullptr) + , enteredAction(BaseProxyHandler::NONE) +#endif + {}; + void reportErrorIfExceptionIsNotPending(JSContext *cx, jsid id); + bool allow; + bool rv; + +#ifdef JS_DEBUG + JSContext *context; + mozilla::Maybe enteredProxy; + mozilla::Maybe enteredId; + Action enteredAction; + + // NB: We explicitly don't track the entered action here, because sometimes + // SET traps do an implicit GET during their implementation, leading to + // spurious assertions. + AutoEnterPolicy *prev; + void recordEnter(JSContext *cx, HandleObject proxy, HandleId id, Action act); + void recordLeave(); + + friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id, Action act); +#else + inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id, Action act) {} + inline void recordLeave() {} +#endif + +}; + +#ifdef JS_DEBUG +class JS_FRIEND_API(AutoWaivePolicy) : public AutoEnterPolicy { +public: + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) + { + allow = true; + recordEnter(cx, proxy, id, act); + } +}; +#else +class JS_FRIEND_API(AutoWaivePolicy) { + public: + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) + {} +}; +#endif + +#ifdef JS_DEBUG +extern JS_FRIEND_API(void) +assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act); +#else +inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act) +{}; +#endif + +} /* namespace js */ + +extern JS_FRIEND_API(JSObject *) +js_InitProxyClass(JSContext *cx, JS::HandleObject obj); + +#endif /* jsproxy_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/jspubtd.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/jspubtd.h new file mode 100644 index 0000000000..7a524c8aef --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/jspubtd.h @@ -0,0 +1,548 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jspubtd_h +#define jspubtd_h + +/* + * JS public API typedefs. + */ + +#include "mozilla/Assertions.h" +#include "mozilla/LinkedList.h" +#include "mozilla/NullPtr.h" +#include "mozilla/PodOperations.h" + +#include "jsprototypes.h" +#include "jstypes.h" + +#include "js/TypeDecls.h" + +#if defined(JSGC_USE_EXACT_ROOTING) +# define JSGC_TRACK_EXACT_ROOTS +#endif + +namespace JS { + +class AutoIdVector; +class CallArgs; + +template +class Rooted; + +class JS_FRIEND_API(CompileOptions); +class JS_FRIEND_API(ReadOnlyCompileOptions); +class JS_FRIEND_API(OwningCompileOptions); +class JS_PUBLIC_API(CompartmentOptions); + +struct Zone; + +} /* namespace JS */ + +namespace js { +struct ContextFriendFields; +} // namespace js + +/* + * Run-time version enumeration. For compile-time version checking, please use + * the JS_HAS_* macros in jsversion.h, or use MOZJS_MAJOR_VERSION, + * MOZJS_MINOR_VERSION, MOZJS_PATCH_VERSION, and MOZJS_ALPHA definitions. + */ +enum JSVersion { + JSVERSION_ECMA_3 = 148, + JSVERSION_1_6 = 160, + JSVERSION_1_7 = 170, + JSVERSION_1_8 = 180, + JSVERSION_ECMA_5 = 185, + JSVERSION_DEFAULT = 0, + JSVERSION_UNKNOWN = -1, + JSVERSION_LATEST = JSVERSION_ECMA_5 +}; + +/* Result of typeof operator enumeration. */ +enum JSType { + JSTYPE_VOID, /* undefined */ + JSTYPE_OBJECT, /* object */ + JSTYPE_FUNCTION, /* function */ + JSTYPE_STRING, /* string */ + JSTYPE_NUMBER, /* number */ + JSTYPE_BOOLEAN, /* boolean */ + JSTYPE_NULL, /* null */ + JSTYPE_SYMBOL, /* symbol */ + JSTYPE_LIMIT +}; + +/* Dense index into cached prototypes and class atoms for standard objects. */ +enum JSProtoKey { +#define PROTOKEY_AND_INITIALIZER(name,code,init,clasp) JSProto_##name = code, + JS_FOR_EACH_PROTOTYPE(PROTOKEY_AND_INITIALIZER) +#undef PROTOKEY_AND_INITIALIZER + JSProto_LIMIT +}; + +/* + * This enum type is used to control the behavior of a JSObject property + * iterator function that has type JSNewEnumerate. + */ +enum JSIterateOp { + /* Create new iterator state over enumerable properties. */ + JSENUMERATE_INIT, + + /* Create new iterator state over all properties. */ + JSENUMERATE_INIT_ALL, + + /* Iterate once. */ + JSENUMERATE_NEXT, + + /* Destroy iterator state. */ + JSENUMERATE_DESTROY +}; + +/* See Value::gcKind() and JSTraceCallback in Tracer.h. */ +enum JSGCTraceKind { + JSTRACE_OBJECT, + JSTRACE_STRING, + JSTRACE_SYMBOL, + JSTRACE_SCRIPT, + + /* + * Trace kinds internal to the engine. The embedding can only see them if + * it implements JSTraceCallback. + */ + JSTRACE_LAZY_SCRIPT, + JSTRACE_JITCODE, + JSTRACE_SHAPE, + JSTRACE_BASE_SHAPE, + JSTRACE_TYPE_OBJECT, + JSTRACE_LAST = JSTRACE_TYPE_OBJECT +}; + +/* Struct forward declarations. */ +struct JSClass; +struct JSCompartment; +struct JSConstDoubleSpec; +struct JSCrossCompartmentCall; +struct JSErrorReport; +struct JSExceptionState; +struct JSFunctionSpec; +struct JSIdArray; +struct JSLocaleCallbacks; +struct JSObjectMap; +struct JSPrincipals; +struct JSPropertyDescriptor; +struct JSPropertyName; +struct JSPropertySpec; +struct JSRuntime; +struct JSSecurityCallbacks; +struct JSStructuredCloneCallbacks; +struct JSStructuredCloneReader; +struct JSStructuredCloneWriter; +class JS_PUBLIC_API(JSTracer); + +class JSFlatString; + +#ifdef JS_THREADSAFE +typedef struct PRCallOnceType JSCallOnceType; +#else +typedef bool JSCallOnceType; +#endif +typedef bool (*JSInitCallback)(void); + +/* + * Generic trace operation that calls JS_CallTracer on each traceable thing + * stored in data. + */ +typedef void +(* JSTraceDataOp)(JSTracer *trc, void *data); + +void js_FinishGC(JSRuntime *rt); + +namespace js { +namespace gc { +class StoreBuffer; +void MarkPersistentRootedChains(JSTracer *); +void FinishPersistentRootedChains(JSRuntime *); +} +} + +namespace JS { + +typedef void (*OffThreadCompileCallback)(void *token, void *callbackData); + +namespace shadow { + +struct Runtime +{ + /* Restrict zone access during Minor GC. */ + bool needsBarrier_; + +#ifdef JSGC_GENERATIONAL + private: + js::gc::StoreBuffer *gcStoreBufferPtr_; +#endif + + public: + explicit Runtime( +#ifdef JSGC_GENERATIONAL + js::gc::StoreBuffer *storeBuffer +#endif + ) + : needsBarrier_(false) +#ifdef JSGC_GENERATIONAL + , gcStoreBufferPtr_(storeBuffer) +#endif + {} + + bool needsBarrier() const { + return needsBarrier_; + } + +#ifdef JSGC_GENERATIONAL + js::gc::StoreBuffer *gcStoreBufferPtr() { return gcStoreBufferPtr_; } +#endif + + static JS::shadow::Runtime *asShadowRuntime(JSRuntime *rt) { + return reinterpret_cast(rt); + } + + /* Allow inlining of PersistentRooted constructors and destructors. */ + private: + template friend class JS::PersistentRooted; + friend void js::gc::MarkPersistentRootedChains(JSTracer *); + friend void js::gc::FinishPersistentRootedChains(JSRuntime *rt); + + mozilla::LinkedList functionPersistentRooteds; + mozilla::LinkedList idPersistentRooteds; + mozilla::LinkedList objectPersistentRooteds; + mozilla::LinkedList scriptPersistentRooteds; + mozilla::LinkedList stringPersistentRooteds; + mozilla::LinkedList valuePersistentRooteds; + + /* Specializations of this return references to the appropriate list. */ + template + inline mozilla::LinkedList > &getPersistentRootedList(); +}; + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return functionPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return idPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return objectPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return scriptPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return stringPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return valuePersistentRooteds; } + +} /* namespace shadow */ + +class JS_PUBLIC_API(AutoGCRooter) +{ + public: + AutoGCRooter(JSContext *cx, ptrdiff_t tag); + AutoGCRooter(js::ContextFriendFields *cx, ptrdiff_t tag); + + ~AutoGCRooter() { + MOZ_ASSERT(this == *stackTop); + *stackTop = down; + } + + /* Implemented in gc/RootMarking.cpp. */ + inline void trace(JSTracer *trc); + static void traceAll(JSTracer *trc); + static void traceAllWrappers(JSTracer *trc); + + /* T must be a context type */ + template + static void traceAllInContext(T* cx, JSTracer *trc) { + for (AutoGCRooter *gcr = cx->autoGCRooters; gcr; gcr = gcr->down) + gcr->trace(trc); + } + + protected: + AutoGCRooter * const down; + + /* + * Discriminates actual subclass of this being used. If non-negative, the + * subclass roots an array of values of the length stored in this field. + * If negative, meaning is indicated by the corresponding value in the enum + * below. Any other negative value indicates some deeper problem such as + * memory corruption. + */ + ptrdiff_t tag_; + + enum { + VALARRAY = -2, /* js::AutoValueArray */ + PARSER = -3, /* js::frontend::Parser */ + SHAPEVECTOR = -4, /* js::AutoShapeVector */ + IDARRAY = -6, /* js::AutoIdArray */ + DESCVECTOR = -7, /* js::AutoPropDescVector */ + VALVECTOR = -10, /* js::AutoValueVector */ + IDVECTOR = -13, /* js::AutoIdVector */ + OBJVECTOR = -14, /* js::AutoObjectVector */ + STRINGVECTOR =-15, /* js::AutoStringVector */ + SCRIPTVECTOR =-16, /* js::AutoScriptVector */ + NAMEVECTOR = -17, /* js::AutoNameVector */ + HASHABLEVALUE=-18, /* js::HashableValue */ + IONMASM = -19, /* js::jit::MacroAssembler */ + IONALLOC = -20, /* js::jit::AutoTempAllocatorRooter */ + WRAPVECTOR = -21, /* js::AutoWrapperVector */ + WRAPPER = -22, /* js::AutoWrapperRooter */ + OBJOBJHASHMAP=-23, /* js::AutoObjectObjectHashMap */ + OBJU32HASHMAP=-24, /* js::AutoObjectUnsigned32HashMap */ + OBJHASHSET = -25, /* js::AutoObjectHashSet */ + JSONPARSER = -26, /* js::JSONParser */ + CUSTOM = -27, /* js::CustomAutoRooter */ + FUNVECTOR = -28 /* js::AutoFunctionVector */ + }; + + private: + AutoGCRooter ** const stackTop; + + /* No copy or assignment semantics. */ + AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; + void operator=(AutoGCRooter &ida) MOZ_DELETE; +}; + +} /* namespace JS */ + +namespace js { + +/* + * Parallel operations in general can have one of three states. They may + * succeed, fail, or "bail", where bail indicates that the code encountered an + * unexpected condition and should be re-run sequentially. Different + * subcategories of the "bail" state are encoded as variants of TP_RETRY_*. + */ +enum ParallelResult { TP_SUCCESS, TP_RETRY_SEQUENTIALLY, TP_RETRY_AFTER_GC, TP_FATAL }; + +struct ThreadSafeContext; +class ForkJoinContext; +class ExclusiveContext; + +class Allocator; + +enum ThingRootKind +{ + THING_ROOT_OBJECT, + THING_ROOT_SHAPE, + THING_ROOT_BASE_SHAPE, + THING_ROOT_TYPE_OBJECT, + THING_ROOT_STRING, + THING_ROOT_SYMBOL, + THING_ROOT_JIT_CODE, + THING_ROOT_SCRIPT, + THING_ROOT_LAZY_SCRIPT, + THING_ROOT_ID, + THING_ROOT_VALUE, + THING_ROOT_TYPE, + THING_ROOT_BINDINGS, + THING_ROOT_PROPERTY_DESCRIPTOR, + THING_ROOT_PROP_DESC, + THING_ROOT_LIMIT +}; + +/* + * This list enumerates the different types of conceptual stacks we have in + * SpiderMonkey. In reality, they all share the C stack, but we allow different + * stack limits depending on the type of code running. + */ +enum StackKind +{ + StackForSystemCode, // C++, such as the GC, running on behalf of the VM. + StackForTrustedScript, // Script running with trusted principals. + StackForUntrustedScript, // Script running with untrusted principals. + StackKindCount +}; + +template +struct RootKind; + +/* + * Specifically mark the ThingRootKind of externally visible types, so that + * JSAPI users may use JSRooted... types without having the class definition + * available. + */ +template +struct SpecificRootKind +{ + static ThingRootKind rootKind() { return Kind; } +}; + +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; + +struct ContextFriendFields +{ + protected: + JSRuntime *const runtime_; + + /* The current compartment. */ + JSCompartment *compartment_; + + /* The current zone. */ + JS::Zone *zone_; + + public: + explicit ContextFriendFields(JSRuntime *rt) + : runtime_(rt), compartment_(nullptr), zone_(nullptr), autoGCRooters(nullptr) + { +#ifdef JSGC_TRACK_EXACT_ROOTS + mozilla::PodArrayZero(thingGCRooters); +#endif + } + + static const ContextFriendFields *get(const JSContext *cx) { + return reinterpret_cast(cx); + } + + static ContextFriendFields *get(JSContext *cx) { + return reinterpret_cast(cx); + } + +#ifdef JSGC_TRACK_EXACT_ROOTS + private: + /* + * Stack allocated GC roots for stack GC heap pointers, which may be + * overwritten if moved during a GC. + */ + JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; + + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } + +#endif + + void checkNoGCRooters(); + + /* Stack of thread-stack-allocated GC roots. */ + JS::AutoGCRooter *autoGCRooters; + + friend JSRuntime *GetRuntime(const JSContext *cx); + friend JSCompartment *GetContextCompartment(const JSContext *cx); + friend JS::Zone *GetContextZone(const JSContext *cx); + template friend class JS::Rooted; +}; + +/* + * Inlinable accessors for JSContext. + * + * - These must not be available on the more restricted superclasses of + * JSContext, so we can't simply define them on ContextFriendFields. + * + * - They're perfectly ordinary JSContext functionality, so ought to be + * usable without resorting to jsfriendapi.h, and when JSContext is an + * incomplete type. + */ +inline JSRuntime * +GetRuntime(const JSContext *cx) +{ + return ContextFriendFields::get(cx)->runtime_; +} + +inline JSCompartment * +GetContextCompartment(const JSContext *cx) +{ + return ContextFriendFields::get(cx)->compartment_; +} + +inline JS::Zone * +GetContextZone(const JSContext *cx) +{ + return ContextFriendFields::get(cx)->zone_; +} + +class PerThreadData; + +struct PerThreadDataFriendFields +{ + private: + // Note: this type only exists to permit us to derive the offset of + // the perThread data within the real JSRuntime* type in a portable + // way. + struct RuntimeDummy : JS::shadow::Runtime + { + struct PerThreadDummy { + void *field1; + uintptr_t field2; +#ifdef JS_DEBUG + uint64_t field3; +#endif + } mainThread; + }; + + public: + + PerThreadDataFriendFields(); + +#ifdef JSGC_TRACK_EXACT_ROOTS + private: + /* + * Stack allocated GC roots for stack GC heap pointers, which may be + * overwritten if moved during a GC. + */ + JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; + + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } +#endif + + /* Limit pointer for checking native stack consumption. */ + uintptr_t nativeStackLimit[StackKindCount]; + + static const size_t RuntimeMainThreadOffset = offsetof(RuntimeDummy, mainThread); + + static inline PerThreadDataFriendFields *get(js::PerThreadData *pt) { + return reinterpret_cast(pt); + } + + static inline PerThreadDataFriendFields *getMainThread(JSRuntime *rt) { + // mainThread must always appear directly after |JS::shadow::Runtime|. + // Tested by a JS_STATIC_ASSERT in |jsfriendapi.cpp| + return reinterpret_cast( + reinterpret_cast(rt) + RuntimeMainThreadOffset); + } + + static inline const PerThreadDataFriendFields *getMainThread(const JSRuntime *rt) { + // mainThread must always appear directly after |JS::shadow::Runtime|. + // Tested by a JS_STATIC_ASSERT in |jsfriendapi.cpp| + return reinterpret_cast( + reinterpret_cast(rt) + RuntimeMainThreadOffset); + } + + template friend class JS::Rooted; +}; + +} /* namespace js */ + +#endif /* jspubtd_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/jstypes.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/jstypes.h new file mode 100644 index 0000000000..e9927bca0d --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/jstypes.h @@ -0,0 +1,226 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* +** File: jstypes.h +** Description: Definitions of NSPR's basic types +** +** Prototypes and macros used to make up for deficiencies in ANSI environments +** that we have found. +** +** Since we do not wrap and all the other standard headers, authors +** of portable code will not know in general that they need these definitions. +** Instead of requiring these authors to find the dependent uses in their code +** and take the following steps only in those C files, we take steps once here +** for all C files. +**/ + +#ifndef jstypes_h +#define jstypes_h + +#include "mozilla/Attributes.h" +#include "mozilla/Types.h" + +// jstypes.h is (or should be!) included by every file in SpiderMonkey. +// js-config.h and jsversion.h also should be included by every file. +// So include them here. +// XXX: including them in js/RequiredDefines.h should be a better option, since +// that is by definition the header file that should be included in all +// SpiderMonkey code. However, Gecko doesn't do this! See bug 909576. +#include "js-config.h" +#include "jsversion.h" + +/*********************************************************************** +** MACROS: JS_EXTERN_API +** JS_EXPORT_API +** DESCRIPTION: +** These are only for externally visible routines and globals. For +** internal routines, just use "extern" for type checking and that +** will not export internal cross-file or forward-declared symbols. +** Define a macro for declaring procedures return types. We use this to +** deal with windoze specific type hackery for DLL definitions. Use +** JS_EXTERN_API when the prototype for the method is declared. Use +** JS_EXPORT_API for the implementation of the method. +** +** Example: +** in dowhim.h +** JS_EXTERN_API( void ) DoWhatIMean( void ); +** in dowhim.c +** JS_EXPORT_API( void ) DoWhatIMean( void ) { return; } +** +** +***********************************************************************/ + +#define JS_EXTERN_API(type) extern MOZ_EXPORT type +#define JS_EXPORT_API(type) MOZ_EXPORT type +#define JS_EXPORT_DATA(type) MOZ_EXPORT type +#define JS_IMPORT_API(type) MOZ_IMPORT_API type +#define JS_IMPORT_DATA(type) MOZ_IMPORT_DATA type + +/* + * The linkage of JS API functions differs depending on whether the file is + * used within the JS library or not. Any source file within the JS + * interpreter should define EXPORT_JS_API whereas any client of the library + * should not. STATIC_JS_API is used to build JS as a static library. + */ +#if defined(STATIC_JS_API) +# define JS_PUBLIC_API(t) t +# define JS_PUBLIC_DATA(t) t +#elif defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API) +# define JS_PUBLIC_API(t) MOZ_EXPORT t +# define JS_PUBLIC_DATA(t) MOZ_EXPORT t +#else +# define JS_PUBLIC_API(t) MOZ_IMPORT_API t +# define JS_PUBLIC_DATA(t) MOZ_IMPORT_DATA t +#endif + +#if defined(STATIC_JS_API) || defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API) +# define JS_FRIEND_API(t) MOZ_EXPORT t +# define JS_FRIEND_DATA(t) MOZ_EXPORT t +#else +# define JS_FRIEND_API(t) MOZ_IMPORT_API t +# define JS_FRIEND_DATA(t) MOZ_IMPORT_DATA t +#endif + +#if defined(_MSC_VER) && defined(_M_IX86) +#define JS_FASTCALL __fastcall +#elif defined(__GNUC__) && defined(__i386__) +#define JS_FASTCALL __attribute__((fastcall)) +#else +#define JS_FASTCALL +#define JS_NO_FASTCALL +#endif + +/*********************************************************************** +** MACROS: JS_BEGIN_MACRO +** JS_END_MACRO +** DESCRIPTION: +** Macro body brackets so that macros with compound statement definitions +** behave syntactically more like functions when called. +***********************************************************************/ +#define JS_BEGIN_MACRO do { + +#if defined(_MSC_VER) && _MSC_VER >= 1400 +# define JS_END_MACRO \ + } __pragma(warning(push)) __pragma(warning(disable:4127)) \ + while (0) __pragma(warning(pop)) +#else +# define JS_END_MACRO } while (0) +#endif + +/*********************************************************************** +** MACROS: JS_BIT +** JS_BITMASK +** DESCRIPTION: +** Bit masking macros. XXX n must be <= 31 to be portable +***********************************************************************/ +#define JS_BIT(n) ((uint32_t)1 << (n)) +#define JS_BITMASK(n) (JS_BIT(n) - 1) + +/*********************************************************************** +** MACROS: JS_HOWMANY +** JS_ROUNDUP +** DESCRIPTION: +** Commonly used macros for operations on compatible types. +***********************************************************************/ +#define JS_HOWMANY(x,y) (((x)+(y)-1)/(y)) +#define JS_ROUNDUP(x,y) (JS_HOWMANY(x,y)*(y)) + +#include "jscpucfg.h" + +/* + * Define JS_64BIT iff we are building in an environment with 64-bit + * addresses. + */ +#ifdef _MSC_VER +# if defined(_M_X64) || defined(_M_AMD64) +# define JS_64BIT +# endif +#elif defined(__GNUC__) +/* Additional GCC defines are when running on Solaris, AIX, and HPUX */ +# if defined(__x86_64__) || defined(__sparcv9) || \ + defined(__64BIT__) || defined(__LP64__) +# define JS_64BIT +# endif +#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* Sun Studio C/C++ */ +# if defined(__x86_64) || defined(__sparcv9) +# define JS_64BIT +# endif +#elif defined(__xlc__) || defined(__xlC__) /* IBM XL C/C++ */ +# if defined(__64BIT__) +# define JS_64BIT +# endif +#elif defined(__HP_cc) || defined(__HP_aCC) /* HP-UX cc/aCC */ +# if defined(__LP64__) +# define JS_64BIT +# endif +#else +# error "Implement me" +#endif + +/*********************************************************************** +** MACROS: JS_ARRAY_LENGTH +** JS_ARRAY_END +** DESCRIPTION: +** Macros to get the number of elements and the pointer to one past the +** last element of a C array. Use them like this: +** +** jschar buf[10], *s; +** JSString *str; +** ... +** for (s = buf; s != JS_ARRAY_END(buf); ++s) *s = ...; +** ... +** str = JS_NewStringCopyN(cx, buf, JS_ARRAY_LENGTH(buf)); +** ... +** +***********************************************************************/ + +#define JS_ARRAY_LENGTH(array) (sizeof (array) / sizeof (array)[0]) +#define JS_ARRAY_END(array) ((array) + JS_ARRAY_LENGTH(array)) + +#define JS_BITS_PER_BYTE 8 +#define JS_BITS_PER_BYTE_LOG2 3 + +#if defined(JS_64BIT) +# define JS_BITS_PER_WORD 64 +#else +# define JS_BITS_PER_WORD 32 +#endif + +/*********************************************************************** +** MACROS: JS_FUNC_TO_DATA_PTR +** JS_DATA_TO_FUNC_PTR +** DESCRIPTION: +** Macros to convert between function and data pointers assuming that +** they have the same size. Use them like this: +** +** JSPropertyOp nativeGetter; +** JSObject *scriptedGetter; +** ... +** scriptedGetter = JS_FUNC_TO_DATA_PTR(JSObject *, nativeGetter); +** ... +** nativeGetter = JS_DATA_TO_FUNC_PTR(JSPropertyOp, scriptedGetter); +** +***********************************************************************/ + +#ifdef __GNUC__ +# define JS_FUNC_TO_DATA_PTR(type, fun) (__extension__ (type) (size_t) (fun)) +# define JS_DATA_TO_FUNC_PTR(type, ptr) (__extension__ (type) (size_t) (ptr)) +#else +/* Use an extra (void *) cast for MSVC. */ +# define JS_FUNC_TO_DATA_PTR(type, fun) ((type) (void *) (fun)) +# define JS_DATA_TO_FUNC_PTR(type, ptr) ((type) (void *) (ptr)) +#endif + +#ifdef __GNUC__ +# define JS_EXTENSION __extension__ +# define JS_EXTENSION_(s) __extension__ ({ s; }) +#else +# define JS_EXTENSION +# define JS_EXTENSION_(s) s +#endif + +#endif /* jstypes_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/jsversion.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsversion.h new file mode 100644 index 0000000000..1f31e40b5e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/jsversion.h @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsversion_h +#define jsversion_h + +/* + * JS Capability Macros. + */ +#define JS_HAS_STR_HTML_HELPERS 1 /* has str.anchor, str.bold, etc. */ +#define JS_HAS_OBJ_PROTO_PROP 1 /* has o.__proto__ etc. */ +#define JS_HAS_OBJ_WATCHPOINT 1 /* has o.watch and o.unwatch */ +#define JS_HAS_TOSOURCE 1 /* has Object/Array toSource method */ +#define JS_HAS_CATCH_GUARD 1 /* has exception handling catch guard */ +#define JS_HAS_UNEVAL 1 /* has uneval() top-level function */ +#define JS_HAS_CONST 1 /* has JS2 const as alternative var */ +#define JS_HAS_FUN_EXPR_STMT 1 /* has function expression statement */ +#define JS_HAS_NO_SUCH_METHOD 1 /* has o.__noSuchMethod__ handler */ +#define JS_HAS_FOR_EACH_IN 1 /* has for each (lhs in iterable) */ +#define JS_HAS_GENERATORS 1 /* has yield in generator function */ +#define JS_HAS_BLOCK_SCOPE 1 /* has block scope via let/arraycomp */ +#define JS_HAS_DESTRUCTURING 2 /* has [a,b] = ... or {p:a,q:b} = ... */ +#define JS_HAS_GENERATOR_EXPRS 1 /* has (expr for (lhs in iterable)) */ +#define JS_HAS_EXPR_CLOSURES 1 /* has function (formals) listexpr */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_TEMPLATE_STRINGS 1 /* has template string support */ +#endif + +/* Support for JS_NewGlobalObject. */ +#define JS_HAS_NEW_GLOBAL_OBJECT 1 + +/* Support for JS_MakeSystemObject. */ +#define JS_HAS_MAKE_SYSTEM_OBJECT 1 + +/* Feature-test macro for evolving destructuring support. */ +#define JS_HAS_DESTRUCTURING_SHORTHAND (JS_HAS_DESTRUCTURING == 2) + +/* + * Feature for Object.prototype.__{define,lookup}{G,S}etter__ legacy support; + * support likely to be made opt-in at some future time. + */ +#define JS_OLD_GETTER_SETTER_METHODS 1 + +/* Support for Symbols - Nightly-only for now. */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_SYMBOLS 1 +#endif + +#endif /* jsversion_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/jswrapper.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/jswrapper.h new file mode 100644 index 0000000000..a8a510c4f7 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/jswrapper.h @@ -0,0 +1,337 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jswrapper_h +#define jswrapper_h + +#include "mozilla/Attributes.h" + +#include "jsproxy.h" + +namespace js { + +class DummyFrameGuard; + +/* + * Helper for Wrapper::New default options. + * + * Callers of Wrapper::New() who wish to specify a prototype for the created + * Wrapper, *MUST* construct a WrapperOptions with a JSContext. + */ +class MOZ_STACK_CLASS WrapperOptions : public ProxyOptions { + public: + WrapperOptions() : ProxyOptions(false, nullptr), + proto_() + {} + + explicit WrapperOptions(JSContext *cx) : ProxyOptions(false, nullptr), + proto_() + { + proto_.construct(cx); + } + + inline JSObject *proto() const; + WrapperOptions &setProto(JSObject *protoArg) { + JS_ASSERT(!proto_.empty()); + proto_.ref() = protoArg; + return *this; + } + + private: + mozilla::Maybe proto_; +}; + +/* + * A wrapper is a proxy with a target object to which it generally forwards + * operations, but may restrict access to certain operations or instrument + * the trap operations in various ways. A wrapper is distinct from a Direct Proxy + * Handler in the sense that it can be "unwrapped" in C++, exposing the underlying + * object (Direct Proxy Handlers have an underlying target object, but don't + * expect to expose this object via any kind of unwrapping operation). Callers + * should be careful to avoid unwrapping security wrappers in the wrong context. + */ +class JS_FRIEND_API(Wrapper) : public DirectProxyHandler +{ + unsigned mFlags; + + public: + using BaseProxyHandler::Action; + + enum Flags { + CROSS_COMPARTMENT = 1 << 0, + LAST_USED_FLAG = CROSS_COMPARTMENT + }; + + virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, + MutableHandleValue vp) const MOZ_OVERRIDE; + + static JSObject *New(JSContext *cx, JSObject *obj, JSObject *parent, const Wrapper *handler, + const WrapperOptions *options = nullptr); + + static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, const Wrapper *handler); + + static const Wrapper *wrapperHandler(JSObject *wrapper); + + static JSObject *wrappedObject(JSObject *wrapper); + + unsigned flags() const { + return mFlags; + } + + explicit Wrapper(unsigned flags, bool hasPrototype = false, bool hasSecurityPolicy = false); + + virtual ~Wrapper(); + + virtual bool finalizeInBackground(Value priv) const MOZ_OVERRIDE; + + static const Wrapper singleton; + static const Wrapper singletonWithPrototype; + + static JSObject *defaultProto; +}; + +inline JSObject * +WrapperOptions::proto() const +{ + return proto_.empty() ? Wrapper::defaultProto : proto_.ref(); +} + +/* Base class for all cross compartment wrapper handlers. */ +class JS_FRIEND_API(CrossCompartmentWrapper) : public Wrapper +{ + public: + explicit CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false, + bool hasSecurityPolicy = false); + + virtual ~CrossCompartmentWrapper(); + + /* ES5 Harmony fundamental wrapper traps. */ + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; + virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; + + /* ES5 Harmony derived wrapper traps. */ + virtual bool has(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool hasOwn(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool get(JSContext *cx, HandleObject wrapper, HandleObject receiver, + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool set(JSContext *cx, HandleObject wrapper, HandleObject receiver, + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool keys(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool iterate(JSContext *cx, HandleObject wrapper, unsigned flags, + MutableHandleValue vp) const MOZ_OVERRIDE; + + /* Spidermonkey extensions. */ + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, + CallArgs args) const MOZ_OVERRIDE; + virtual bool hasInstance(JSContext *cx, HandleObject wrapper, MutableHandleValue v, + bool *bp) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual JSString *fun_toString(JSContext *cx, HandleObject wrapper, + unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; + virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, + MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; + + static const CrossCompartmentWrapper singleton; + static const CrossCompartmentWrapper singletonWithPrototype; +}; + +/* + * Base class for security wrappers. A security wrapper is potentially hiding + * all or part of some wrapped object thus SecurityWrapper defaults to denying + * access to the wrappee. This is the opposite of Wrapper which tries to be + * completely transparent. + * + * NB: Currently, only a few ProxyHandler operations are overridden to deny + * access, relying on derived SecurityWrapper to block access when necessary. + */ +template +class JS_FRIEND_API(SecurityWrapper) : public Base +{ + public: + explicit SecurityWrapper(unsigned flags, bool hasPrototype = false); + + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; + virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Wrapper::Action act, + bool *bp) const MOZ_OVERRIDE; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, + CallArgs args) const MOZ_OVERRIDE; + virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, + MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, + JSContext *cx) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; + virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; + + virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, + JS::HandleObject callable) const MOZ_OVERRIDE; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const MOZ_OVERRIDE; + + /* + * Allow our subclasses to select the superclass behavior they want without + * needing to specify an exact superclass. + */ + typedef Base Permissive; + typedef SecurityWrapper Restrictive; +}; + +typedef SecurityWrapper SameCompartmentSecurityWrapper; +typedef SecurityWrapper CrossCompartmentSecurityWrapper; + +class JS_FRIEND_API(DeadObjectProxy) : public BaseProxyHandler +{ + public: + // This variable exists solely to provide a unique address for use as an identifier. + static const char sDeadObjectFamily; + + explicit DeadObjectProxy(); + + /* ES5 Harmony fundamental wrapper traps. */ + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; + + /* Spidermonkey extensions. */ + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, + CallArgs args) const MOZ_OVERRIDE; + virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, + bool *bp) const MOZ_OVERRIDE; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; + virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, + MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + + static const DeadObjectProxy singleton; +}; + +extern JSObject * +TransparentObjectWrapper(JSContext *cx, HandleObject existing, HandleObject obj, + HandleObject parent, unsigned flags); + +// Proxy family for wrappers. Public so that IsWrapper() can be fully inlined by +// jsfriendapi users. +// This variable exists solely to provide a unique address for use as an identifier. +extern JS_FRIEND_DATA(const char) sWrapperFamily; + +inline bool +IsWrapper(JSObject *obj) +{ + return IsProxy(obj) && GetProxyHandler(obj)->family() == &sWrapperFamily; +} + +// Given a JSObject, returns that object stripped of wrappers. If +// stopAtOuter is true, then this returns the outer window if it was +// previously wrapped. Otherwise, this returns the first object for +// which JSObject::isWrapper returns false. +JS_FRIEND_API(JSObject *) +UncheckedUnwrap(JSObject *obj, bool stopAtOuter = true, unsigned *flagsp = nullptr); + +// Given a JSObject, returns that object stripped of wrappers. At each stage, +// the security wrapper has the opportunity to veto the unwrap. Since checked +// code should never be unwrapping outer window wrappers, we always stop at +// outer windows. +JS_FRIEND_API(JSObject *) +CheckedUnwrap(JSObject *obj, bool stopAtOuter = true); + +// Unwrap only the outermost security wrapper, with the same semantics as +// above. This is the checked version of Wrapper::wrappedObject. +JS_FRIEND_API(JSObject *) +UnwrapOneChecked(JSObject *obj, bool stopAtOuter = true); + +JS_FRIEND_API(bool) +IsCrossCompartmentWrapper(JSObject *obj); + +bool +IsDeadProxyObject(JSObject *obj); + +JSObject * +NewDeadProxyObject(JSContext *cx, JSObject *parent, + const ProxyOptions &options = ProxyOptions()); + +void +NukeCrossCompartmentWrapper(JSContext *cx, JSObject *wrapper); + +bool +RemapWrapper(JSContext *cx, JSObject *wobj, JSObject *newTarget); + +JS_FRIEND_API(bool) +RemapAllWrappersForObject(JSContext *cx, JSObject *oldTarget, + JSObject *newTarget); + +// API to recompute all cross-compartment wrappers whose source and target +// match the given filters. +JS_FRIEND_API(bool) +RecomputeWrappers(JSContext *cx, const CompartmentFilter &sourceFilter, + const CompartmentFilter &targetFilter); + +/* + * This auto class should be used around any code, such as brain transplants, + * that may touch dead zones. Brain transplants can cause problems + * because they operate on all compartments, whether live or dead. A brain + * transplant can cause a formerly dead object to be "reanimated" by causing a + * read or write barrier to be invoked on it during the transplant. In this way, + * a zone becomes a zombie, kept alive by repeatedly consuming + * (transplanted) brains. + * + * To work around this issue, we observe when mark bits are set on objects in + * dead zones. If this happens during a brain transplant, we do a full, + * non-incremental GC at the end of the brain transplant. This will clean up any + * objects that were improperly marked. + */ +struct JS_FRIEND_API(AutoMaybeTouchDeadZones) +{ + // The version that takes an object just uses it for its runtime. + explicit AutoMaybeTouchDeadZones(JSContext *cx); + explicit AutoMaybeTouchDeadZones(JSObject *obj); + ~AutoMaybeTouchDeadZones(); + + private: + JSRuntime *runtime; + unsigned markCount; + bool inIncremental; + bool manipulatingDeadZones; +}; + +} /* namespace js */ + +#endif /* jswrapper_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Alignment.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Alignment.h new file mode 100644 index 0000000000..0ac8a48779 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Alignment.h @@ -0,0 +1,139 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Functionality related to memory alignment. */ + +#ifndef mozilla_Alignment_h +#define mozilla_Alignment_h + +#include +#include + +namespace mozilla { + +/* + * This class, and the corresponding macro MOZ_ALIGNOF, figures out how many + * bytes of alignment a given type needs. + */ +template +class AlignmentFinder +{ + struct Aligner + { + char mChar; + T mT; + }; + +public: + static const size_t alignment = sizeof(Aligner) - sizeof(T); +}; + +#define MOZ_ALIGNOF(T) mozilla::AlignmentFinder::alignment + +/* + * Declare the MOZ_ALIGNED_DECL macro for declaring aligned types. + * + * For instance, + * + * MOZ_ALIGNED_DECL(char arr[2], 8); + * + * will declare a two-character array |arr| aligned to 8 bytes. + */ + +#if defined(__GNUC__) +# define MOZ_ALIGNED_DECL(_type, _align) \ + _type __attribute__((aligned(_align))) +#elif defined(_MSC_VER) +# define MOZ_ALIGNED_DECL(_type, _align) \ + __declspec(align(_align)) _type +#else +# warning "We don't know how to align variables on this compiler." +# define MOZ_ALIGNED_DECL(_type, _align) _type +#endif + +/* + * AlignedElem is a structure whose alignment is guaranteed to be at least N + * bytes. + * + * We support 1, 2, 4, 8, and 16-bit alignment. + */ +template +struct AlignedElem; + +/* + * We have to specialize this template because GCC doesn't like + * __attribute__((aligned(foo))) where foo is a template parameter. + */ + +template<> +struct AlignedElem<1> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 1); +}; + +template<> +struct AlignedElem<2> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 2); +}; + +template<> +struct AlignedElem<4> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 4); +}; + +template<> +struct AlignedElem<8> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 8); +}; + +template<> +struct AlignedElem<16> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 16); +}; + +/* + * This utility pales in comparison to Boost's aligned_storage. The utility + * simply assumes that uint64_t is enough alignment for anyone. This may need + * to be extended one day... + * + * As an important side effect, pulling the storage into this template is + * enough obfuscation to confuse gcc's strict-aliasing analysis into not giving + * false negatives when we cast from the char buffer to whatever type we've + * constructed using the bytes. + */ +template +struct AlignedStorage +{ + union U + { + char mBytes[Nbytes]; + uint64_t mDummy; + } u; + + const void* addr() const { return u.mBytes; } + void* addr() { return u.mBytes; } +}; + +template +struct AlignedStorage2 +{ + union U + { + char mBytes[sizeof(T)]; + uint64_t mDummy; + } u; + + const T* addr() const { return reinterpret_cast(u.mBytes); } + T* addr() { return static_cast(static_cast(u.mBytes)); } +}; + +} /* namespace mozilla */ + +#endif /* mozilla_Alignment_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/AllocPolicy.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/AllocPolicy.h new file mode 100644 index 0000000000..357c632a02 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/AllocPolicy.h @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * An allocation policy concept, usable for structures and algorithms to + * control how memory is allocated and how failures are handled. + */ + +#ifndef mozilla_AllocPolicy_h +#define mozilla_AllocPolicy_h + +#include +#include + +namespace mozilla { + +/* + * Allocation policies are used to implement the standard allocation behaviors + * in a customizable way. Additionally, custom behaviors may be added to these + * behaviors, such as additionally reporting an error through an out-of-band + * mechanism when OOM occurs. The concept modeled here is as follows: + * + * - public copy constructor, assignment, destructor + * - void* malloc_(size_t) + * Responsible for OOM reporting when null is returned. + * - void* calloc_(size_t) + * Responsible for OOM reporting when null is returned. + * - void* realloc_(void*, size_t, size_t) + * Responsible for OOM reporting when null is returned. The *used* bytes + * of the previous buffer is passed in (rather than the old allocation + * size), in addition to the *new* allocation size requested. + * - void free_(void*) + * - void reportAllocOverflow() const + * Called on allocation overflow (that is, an allocation implicitly tried + * to allocate more than the available memory space -- think allocating an + * array of large-size objects, where N * size overflows) before null is + * returned. + * + * mfbt provides (and typically uses by default) only MallocAllocPolicy, which + * does nothing more than delegate to the malloc/alloc/free functions. + */ + +/* + * A policy that straightforwardly uses malloc/calloc/realloc/free and adds no + * extra behaviors. + */ +class MallocAllocPolicy +{ +public: + void* malloc_(size_t aBytes) + { + return malloc(aBytes); + } + + void* calloc_(size_t aBytes) + { + return calloc(aBytes, 1); + } + + void* realloc_(void* aPtr, size_t aOldBytes, size_t aBytes) + { + return realloc(aPtr, aBytes); + } + + void free_(void* aPtr) + { + free(aPtr); + } + + void reportAllocOverflow() const + { + } +}; + +} // namespace mozilla + +#endif /* mozilla_AllocPolicy_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Array.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Array.h new file mode 100644 index 0000000000..b2ab578d4b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Array.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A compile-time constant-length array with bounds-checking assertions. */ + +#ifndef mozilla_Array_h +#define mozilla_Array_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" + +#include + +namespace mozilla { + +template +class Array +{ + T mArr[Length]; + +public: + T& operator[](size_t aIndex) + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } + + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } +}; + +template +class Array +{ +public: + T& operator[](size_t aIndex) + { + MOZ_CRASH("indexing into zero-length array"); + } + + const T& operator[](size_t aIndex) const + { + MOZ_CRASH("indexing into zero-length array"); + } +}; + +} /* namespace mozilla */ + +#endif /* mozilla_Array_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/ArrayUtils.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/ArrayUtils.h new file mode 100644 index 0000000000..44f5980c44 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/ArrayUtils.h @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements various helper functions related to arrays. + */ + +#ifndef mozilla_ArrayUtils_h +#define mozilla_ArrayUtils_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" + +#include + +#ifdef __cplusplus + +#include "mozilla/Alignment.h" +#include "mozilla/Array.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +/* + * Safely subtract two pointers when it is known that aEnd >= aBegin. This + * avoids the common compiler bug that if (size_t(aEnd) - size_t(aBegin)) has + * the MSB set, the unsigned subtraction followed by right shift will produce + * -1, or size_t(-1), instead of the real difference. + */ +template +MOZ_ALWAYS_INLINE size_t +PointerRangeSize(T* aBegin, T* aEnd) +{ + MOZ_ASSERT(aEnd >= aBegin); + return (size_t(aEnd) - size_t(aBegin)) / sizeof(T); +} + +/* + * Compute the length of an array with constant length. (Use of this method + * with a non-array pointer will not compile.) + * + * Beware of the implicit trailing '\0' when using this with string constants. + */ +template +MOZ_CONSTEXPR size_t +ArrayLength(T (&aArr)[N]) +{ + return N; +} + +template +MOZ_CONSTEXPR size_t +ArrayLength(const Array& aArr) +{ + return N; +} + +/* + * Compute the address one past the last element of a constant-length array. + * + * Beware of the implicit trailing '\0' when using this with string constants. + */ +template +MOZ_CONSTEXPR T* +ArrayEnd(T (&aArr)[N]) +{ + return aArr + ArrayLength(aArr); +} + +template +MOZ_CONSTEXPR T* +ArrayEnd(Array& aArr) +{ + return &aArr[0] + ArrayLength(aArr); +} + +template +MOZ_CONSTEXPR const T* +ArrayEnd(const Array& aArr) +{ + return &aArr[0] + ArrayLength(aArr); +} + +namespace detail { + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % MOZ_ALIGNOF(AlignType)) == 0, + "performing a range-check with a misaligned pointer"); + } +}; + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + } +}; + +} // namespace detail + +/** + * Determines whether |aPtr| points at an object in the range [aBegin, aEnd). + * + * |aPtr| must have the same alignment as |aBegin| and |aEnd|. This usually + * should be achieved by ensuring |aPtr| points at a |U|, not just that it + * points at a |T|. + * + * It is a usage error for any argument to be misaligned. + * + * It's okay for T* to be void*, and if so U* may also be void*. In the latter + * case no argument is required to be aligned (obviously, as void* implies no + * particular alignment). + */ +template +inline typename EnableIf::value || + IsBaseOf::value || + IsVoid::value, + bool>::Type +IsInRange(T* aPtr, U* aBegin, U* aEnd) +{ + MOZ_ASSERT(aBegin <= aEnd); + detail::AlignedChecker::test(aPtr); + detail::AlignedChecker::test(aBegin); + detail::AlignedChecker::test(aEnd); + return aBegin <= static_cast(aPtr) && static_cast(aPtr) < aEnd; +} + +/** + * Convenience version of the above method when the valid range is specified as + * uintptr_t values. As above, |aPtr| must be aligned, and |aBegin| and |aEnd| + * must be aligned with respect to |T|. + */ +template +inline bool +IsInRange(T* aPtr, uintptr_t aBegin, uintptr_t aEnd) +{ + return IsInRange(aPtr, + reinterpret_cast(aBegin), reinterpret_cast(aEnd)); +} + +namespace detail { + +/* + * Helper for the MOZ_ARRAY_LENGTH() macro to make the length a typesafe + * compile-time constant even on compilers lacking constexpr support. + */ +template +char (&ArrayLengthHelper(T (&array)[N]))[N]; + +} /* namespace detail */ + +} /* namespace mozilla */ + +#endif /* __cplusplus */ + +/* + * MOZ_ARRAY_LENGTH() is an alternative to mozilla::ArrayLength() for C files + * that can't use C++ template functions and for static_assert() calls that + * can't call ArrayLength() when it is not a C++11 constexpr function. + */ +#ifdef __cplusplus +# define MOZ_ARRAY_LENGTH(array) sizeof(mozilla::detail::ArrayLengthHelper(array)) +#else +# define MOZ_ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0])) +#endif + +#endif /* mozilla_ArrayUtils_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Assertions.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Assertions.h new file mode 100644 index 0000000000..34b0d7d534 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Assertions.h @@ -0,0 +1,534 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implementations of runtime and static assertion macros for C and C++. */ + +#ifndef mozilla_Assertions_h +#define mozilla_Assertions_h +#include +#if defined(MOZILLA_INTERNAL_API) && defined(__cplusplus) +#define MOZ_DUMP_ASSERTION_STACK +#endif + +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/Likely.h" +#include "mozilla/MacroArgs.h" +#ifdef MOZ_DUMP_ASSERTION_STACK +#include "nsTraceRefcnt.h" +#endif + +#include +#include +#include +#ifdef WIN32 + /* + * TerminateProcess and GetCurrentProcess are defined in , which + * further depends on . We hardcode these few definitions manually + * because those headers clutter the global namespace with a significant + * number of undesired macros and symbols. + */ +# ifdef __cplusplus +extern "C" { +# endif +__declspec(dllimport) int __stdcall +TerminateProcess(void* hProcess, unsigned int uExitCode); +__declspec(dllimport) void* __stdcall GetCurrentProcess(void); +# ifdef __cplusplus +} +# endif +#else +# include +#endif +#ifdef ANDROID +# include +#endif + +/* + * MOZ_STATIC_ASSERT may be used to assert a condition *at compile time* in C. + * In C++11, static_assert is provided by the compiler to the same effect. + * This can be useful when you make certain assumptions about what must hold for + * optimal, or even correct, behavior. For example, you might assert that the + * size of a struct is a multiple of the target architecture's word size: + * + * struct S { ... }; + * // C + * MOZ_STATIC_ASSERT(sizeof(S) % sizeof(size_t) == 0, + * "S should be a multiple of word size for efficiency"); + * // C++11 + * static_assert(sizeof(S) % sizeof(size_t) == 0, + * "S should be a multiple of word size for efficiency"); + * + * This macro can be used in any location where both an extern declaration and a + * typedef could be used. + */ +#ifndef __cplusplus + /* + * Some of the definitions below create an otherwise-unused typedef. This + * triggers compiler warnings with some versions of gcc, so mark the typedefs + * as permissibly-unused to disable the warnings. + */ +# if defined(__GNUC__) +# define MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused)) +# else +# define MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE /* nothing */ +# endif +# define MOZ_STATIC_ASSERT_GLUE1(x, y) x##y +# define MOZ_STATIC_ASSERT_GLUE(x, y) MOZ_STATIC_ASSERT_GLUE1(x, y) +# if defined(__SUNPRO_CC) + /* + * The Sun Studio C++ compiler is buggy when declaring, inside a function, + * another extern'd function with an array argument whose length contains a + * sizeof, triggering the error message "sizeof expression not accepted as + * size of array parameter". This bug (6688515, not public yet) would hit + * defining moz_static_assert as a function, so we always define an extern + * array for Sun Studio. + * + * We include the line number in the symbol name in a best-effort attempt + * to avoid conflicts (see below). + */ +# define MOZ_STATIC_ASSERT(cond, reason) \ + extern char MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __LINE__)[(cond) ? 1 : -1] +# elif defined(__COUNTER__) + /* + * If there was no preferred alternative, use a compiler-agnostic version. + * + * Note that the non-__COUNTER__ version has a bug in C++: it can't be used + * in both |extern "C"| and normal C++ in the same translation unit. (Alas + * |extern "C"| isn't allowed in a function.) The only affected compiler + * we really care about is gcc 4.2. For that compiler and others like it, + * we include the line number in the function name to do the best we can to + * avoid conflicts. These should be rare: a conflict would require use of + * MOZ_STATIC_ASSERT on the same line in separate files in the same + * translation unit, *and* the uses would have to be in code with + * different linkage, *and* the first observed use must be in C++-linkage + * code. + */ +# define MOZ_STATIC_ASSERT(cond, reason) \ + typedef int MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __COUNTER__)[(cond) ? 1 : -1] MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE +# else +# define MOZ_STATIC_ASSERT(cond, reason) \ + extern void MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __LINE__)(int arg[(cond) ? 1 : -1]) MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE +# endif + +#define MOZ_STATIC_ASSERT_IF(cond, expr, reason) MOZ_STATIC_ASSERT(!(cond) || (expr), reason) +#else +#define MOZ_STATIC_ASSERT_IF(cond, expr, reason) static_assert(!(cond) || (expr), reason) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Prints |aStr| as an assertion failure (using aFilename and aLine as the + * location of the assertion) to the standard debug-output channel. + * + * Usually you should use MOZ_ASSERT or MOZ_CRASH instead of this method. This + * method is primarily for internal use in this header, and only secondarily + * for use in implementing release-build assertions. + */ +static MOZ_ALWAYS_INLINE void +MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS +{ +#ifdef ANDROID + __android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert", + "Assertion failure: %s, at %s:%d\n", + aStr, aFilename, aLine); +#else + fprintf(stderr, "Assertion failure: %s, at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif + fflush(stderr); +#endif +} + +static MOZ_ALWAYS_INLINE void +MOZ_ReportCrash(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS +{ +#ifdef ANDROID + __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", + "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); +#else + fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif + fflush(stderr); +#endif +} + +/** + * MOZ_REALLY_CRASH is used in the implementation of MOZ_CRASH(). You should + * call MOZ_CRASH instead. + */ +#if defined(_MSC_VER) + /* + * On MSVC use the __debugbreak compiler intrinsic, which produces an inline + * (not nested in a system function) breakpoint. This distinctively invokes + * Breakpad without requiring system library symbols on all stack-processing + * machines, as a nested breakpoint would require. + * + * We use TerminateProcess with the exit code aborting would generate + * because we don't want to invoke atexit handlers, destructors, library + * unload handlers, and so on when our process might be in a compromised + * state. + * + * We don't use abort() because it'd cause Windows to annoyingly pop up the + * process error dialog multiple times. See bug 345118 and bug 426163. + * + * We follow TerminateProcess() with a call to MOZ_NoReturn() so that the + * compiler doesn't hassle us to provide a return statement after a + * MOZ_REALLY_CRASH() call. + * + * (Technically these are Windows requirements, not MSVC requirements. But + * practically you need MSVC for debugging, and we only ship builds created + * by MSVC, so doing it this way reduces complexity.) + */ + +__declspec(noreturn) __inline void MOZ_NoReturn() {} + +# ifdef __cplusplus +# define MOZ_REALLY_CRASH() \ + do { \ + ::__debugbreak(); \ + *((volatile int*) NULL) = 123; \ + ::TerminateProcess(::GetCurrentProcess(), 3); \ + ::MOZ_NoReturn(); \ + } while (0) +# else +# define MOZ_REALLY_CRASH() \ + do { \ + __debugbreak(); \ + *((volatile int*) NULL) = 123; \ + TerminateProcess(GetCurrentProcess(), 3); \ + MOZ_NoReturn(); \ + } while (0) +# endif +#else +# ifdef __cplusplus +# define MOZ_REALLY_CRASH() \ + do { \ + *((volatile int*) NULL) = 123; \ + ::abort(); \ + } while (0) +# else +# define MOZ_REALLY_CRASH() \ + do { \ + *((volatile int*) NULL) = 123; \ + abort(); \ + } while (0) +# endif +#endif + +/* + * MOZ_CRASH([explanation-string]) crashes the program, plain and simple, in a + * Breakpad-compatible way, in both debug and release builds. + * + * MOZ_CRASH is a good solution for "handling" failure cases when you're + * unwilling or unable to handle them more cleanly -- for OOM, for likely memory + * corruption, and so on. It's also a good solution if you need safe behavior + * in release builds as well as debug builds. But if the failure is one that + * should be debugged and fixed, MOZ_ASSERT is generally preferable. + * + * The optional explanation-string, if provided, must be a string literal + * explaining why we're crashing. This argument is intended for use with + * MOZ_CRASH() calls whose rationale is non-obvious; don't use it if it's + * obvious why we're crashing. + * + * If we're a DEBUG build and we crash at a MOZ_CRASH which provides an + * explanation-string, we print the string to stderr. Otherwise, we don't + * print anything; this is because we want MOZ_CRASH to be 100% safe in release + * builds, and it's hard to print to stderr safely when memory might have been + * corrupted. + */ +#ifndef DEBUG +# define MOZ_CRASH(...) MOZ_REALLY_CRASH() +#else +# define MOZ_CRASH(...) \ + do { \ + MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } while (0) +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* + * MOZ_ASSERT(expr [, explanation-string]) asserts that |expr| must be truthy in + * debug builds. If it is, execution continues. Otherwise, an error message + * including the expression and the explanation-string (if provided) is printed, + * an attempt is made to invoke any existing debugger, and execution halts. + * MOZ_ASSERT is fatal: no recovery is possible. Do not assert a condition + * which can correctly be falsy. + * + * The optional explanation-string, if provided, must be a string literal + * explaining the assertion. It is intended for use with assertions whose + * correctness or rationale is non-obvious, and for assertions where the "real" + * condition being tested is best described prosaically. Don't provide an + * explanation if it's not actually helpful. + * + * // No explanation needed: pointer arguments often must not be NULL. + * MOZ_ASSERT(arg); + * + * // An explanation can be helpful to explain exactly how we know an + * // assertion is valid. + * MOZ_ASSERT(state == WAITING_FOR_RESPONSE, + * "given that and , we must have..."); + * + * // Or it might disambiguate multiple identical (save for their location) + * // assertions of the same expression. + * MOZ_ASSERT(getSlot(PRIMITIVE_THIS_SLOT).isUndefined(), + * "we already set [[PrimitiveThis]] for this Boolean object"); + * MOZ_ASSERT(getSlot(PRIMITIVE_THIS_SLOT).isUndefined(), + * "we already set [[PrimitiveThis]] for this String object"); + * + * MOZ_ASSERT has no effect in non-debug builds. It is designed to catch bugs + * *only* during debugging, not "in the field". If you want the latter, use + * MOZ_RELEASE_ASSERT, which applies to non-debug builds as well. + */ + +/* + * Implement MOZ_VALIDATE_ASSERT_CONDITION_TYPE, which is used to guard against + * accidentally passing something unintended in lieu of an assertion condition. + */ + +#ifdef __cplusplus +# if defined(__clang__) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# elif defined(__GNUC__) +// B2G GCC 4.4 has insufficient decltype support. +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# endif +# elif defined(_MSC_VER) +// Disabled for now because of insufficient decltype support. Bug 1004028. +# endif +#endif + +#ifdef MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# include "mozilla/TypeTraits.h" +namespace mozilla { +namespace detail { + +template +struct IsFunction +{ + static const bool value = false; +}; + +template +struct IsFunction +{ + static const bool value = true; +}; + +template +void ValidateAssertConditionType() +{ + typedef typename RemoveReference::Type ValueT; + static_assert(!IsArray::value, + "Expected boolean assertion condition, got an array or a " + "string!"); + static_assert(!IsFunction::value, + "Expected boolean assertion condition, got a function! Did " + "you intend to call that function?"); + static_assert(!IsFloatingPoint::value, + "It's often a bad idea to assert that a floating-point number " + "is nonzero, because such assertions tend to intermittently " + "fail. Shouldn't your code gracefully handle this case instead " + "of asserting? Anyway, if you really want to do that, write an " + "explicit boolean condition, like !!x or x!=0."); +} + +} // namespace detail +} // namespace mozilla +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) \ + mozilla::detail::ValidateAssertConditionType() +#else +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) +#endif + +/* First the single-argument form. */ +#define MOZ_ASSERT_HELPER1(expr) \ + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) +/* Now the two-argument form. */ +#define MOZ_ASSERT_HELPER2(expr, explain) \ + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) + +#define MOZ_RELEASE_ASSERT_GLUE(a, b) a b +#define MOZ_RELEASE_ASSERT(...) \ + MOZ_RELEASE_ASSERT_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \ + (__VA_ARGS__)) + +#ifdef DEBUG +# define MOZ_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) +#else +# define MOZ_ASSERT(...) do { } while (0) +#endif /* DEBUG */ + +/* + * MOZ_NIGHTLY_ASSERT is defined for both debug and release builds on the + * Nightly channel, but only debug builds on Aurora, Beta, and Release. + */ +#if defined(NIGHTLY_BUILD) +# define MOZ_NIGHTLY_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) +#else +# define MOZ_NIGHTLY_ASSERT(...) MOZ_ASSERT(__VA_ARGS__) +#endif + +/* + * MOZ_ASSERT_IF(cond1, cond2) is equivalent to MOZ_ASSERT(cond2) if cond1 is + * true. + * + * MOZ_ASSERT_IF(isPrime(num), num == 2 || isOdd(num)); + * + * As with MOZ_ASSERT, MOZ_ASSERT_IF has effect only in debug builds. It is + * designed to catch bugs during debugging, not "in the field". + */ +#ifdef DEBUG +# define MOZ_ASSERT_IF(cond, expr) \ + do { \ + if (cond) { \ + MOZ_ASSERT(expr); \ + } \ + } while (0) +#else +# define MOZ_ASSERT_IF(cond, expr) do { } while (0) +#endif + +/* + * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that + * it is undefined behavior for execution to reach this point. No guarantees + * are made about what will happen if this is reached at runtime. Most code + * should use MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE because it has extra + * asserts. + */ +#if defined(__clang__) +# define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable() +#elif defined(__GNUC__) + /* + * __builtin_unreachable() was implemented in gcc 4.5. If we don't have + * that, call a noreturn function; abort() will do nicely. Qualify the call + * in C++ in case there's another abort() visible in local scope. + */ +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable() +# else +# ifdef __cplusplus +# define MOZ_ASSUME_UNREACHABLE_MARKER() ::abort() +# else +# define MOZ_ASSUME_UNREACHABLE_MARKER() abort() +# endif +# endif +#elif defined(_MSC_VER) +# define MOZ_ASSUME_UNREACHABLE_MARKER() __assume(0) +#else +# ifdef __cplusplus +# define MOZ_ASSUME_UNREACHABLE_MARKER() ::abort() +# else +# define MOZ_ASSUME_UNREACHABLE_MARKER() abort() +# endif +#endif + +/* + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE([reason]) tells the compiler that it + * can assume that the macro call cannot be reached during execution. This lets + * the compiler generate better-optimized code under some circumstances, at the + * expense of the program's behavior being undefined if control reaches the + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE. + * + * In Gecko, you probably should not use this macro outside of performance- or + * size-critical code, because it's unsafe. If you don't care about code size + * or performance, you should probably use MOZ_ASSERT or MOZ_CRASH. + * + * SpiderMonkey is a different beast, and there it's acceptable to use + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE more widely. + * + * Note that MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE is noreturn, so it's valid + * not to return a value following a MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE + * call. + * + * Example usage: + * + * enum ValueType { + * VALUE_STRING, + * VALUE_INT, + * VALUE_FLOAT + * }; + * + * int ptrToInt(ValueType type, void* value) { + * { + * // We know for sure that type is either INT or FLOAT, and we want this + * // code to run as quickly as possible. + * switch (type) { + * case VALUE_INT: + * return *(int*) value; + * case VALUE_FLOAT: + * return (int) *(float*) value; + * default: + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected ValueType"); + * } + * } + */ + +/* + * Assert in all debug builds plus the Nightly channel's release builds. Take + * this extra testing precaution because hitting MOZ_ASSUME_UNREACHABLE_MARKER + * could trigger exploitable undefined behavior. + */ +#define MOZ_ASSERT_UNREACHABLE(reason) \ + MOZ_NIGHTLY_ASSERT(false, "MOZ_ASSERT_UNREACHABLE: " reason) + +#define MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) \ + do { \ + MOZ_ASSERT_UNREACHABLE(reason); \ + MOZ_ASSUME_UNREACHABLE_MARKER(); \ + } while (0) + +/* + * TODO: Bug 990764: Audit all MOZ_ASSUME_UNREACHABLE calls and replace them + * with MOZ_ASSERT_UNREACHABLE, MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE, or + * MOZ_CRASH. For now, preserve the macro's same meaning of unreachable. + */ +#define MOZ_ASSUME_UNREACHABLE(reason) \ + MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) + +/* + * MOZ_ALWAYS_TRUE(expr) and MOZ_ALWAYS_FALSE(expr) always evaluate the provided + * expression, in debug builds and in release builds both. Then, in debug + * builds only, the value of the expression is asserted either true or false + * using MOZ_ASSERT. + */ +#ifdef DEBUG +# define MOZ_ALWAYS_TRUE(expr) MOZ_ASSERT((expr)) +# define MOZ_ALWAYS_FALSE(expr) MOZ_ASSERT(!(expr)) +#else +# define MOZ_ALWAYS_TRUE(expr) ((void)(expr)) +# define MOZ_ALWAYS_FALSE(expr) ((void)(expr)) +#endif + +#undef MOZ_DUMP_ASSERTION_STACK + +#endif /* mozilla_Assertions_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Atomics.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Atomics.h new file mode 100644 index 0000000000..71d95c61ba --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Atomics.h @@ -0,0 +1,1171 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements (almost always) lock-free atomic operations. The operations here + * are a subset of that which can be found in C++11's header, with a + * different API to enforce consistent memory ordering constraints. + * + * Anyone caught using |volatile| for inter-thread memory safety needs to be + * sent a copy of this header and the C++11 standard. + */ + +#ifndef mozilla_Atomics_h +#define mozilla_Atomics_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/TypeTraits.h" + +#include + +/* + * Our minimum deployment target on clang/OS X is OS X 10.6, whose SDK + * does not have . So be sure to check for support + * along with C++0x support. + */ +#if defined(__clang__) || defined(__GNUC__) + /* + * Clang doesn't like from libstdc++ before 4.7 due to the + * loose typing of the atomic builtins. GCC 4.5 and 4.6 lacks inline + * definitions for unspecialized std::atomic and causes linking errors. + * Therefore, we require at least 4.7.0 for using libstdc++. + */ +# if MOZ_USING_LIBSTDCXX && MOZ_LIBSTDCXX_VERSION_AT_LEAST(4, 7, 0) +# define MOZ_HAVE_CXX11_ATOMICS +# elif MOZ_USING_LIBCXX +# define MOZ_HAVE_CXX11_ATOMICS +# endif +#elif defined(_MSC_VER) && _MSC_VER >= 1700 +# if defined(DEBUG) + /* + * Provide our own failure code since we're having trouble linking to + * std::_Debug_message (bug 982310). + */ +# define _INVALID_MEMORY_ORDER MOZ_CRASH("Invalid memory order") +# endif +# define MOZ_HAVE_CXX11_ATOMICS +#endif + +namespace mozilla { + +/** + * An enum of memory ordering possibilities for atomics. + * + * Memory ordering is the observable state of distinct values in memory. + * (It's a separate concept from atomicity, which concerns whether an + * operation can ever be observed in an intermediate state. Don't + * conflate the two!) Given a sequence of operations in source code on + * memory, it is *not* always the case that, at all times and on all + * cores, those operations will appear to have occurred in that exact + * sequence. First, the compiler might reorder that sequence, if it + * thinks another ordering will be more efficient. Second, the CPU may + * not expose so consistent a view of memory. CPUs will often perform + * their own instruction reordering, above and beyond that performed by + * the compiler. And each core has its own memory caches, and accesses + * (reads and writes both) to "memory" may only resolve to out-of-date + * cache entries -- not to the "most recently" performed operation in + * some global sense. Any access to a value that may be used by + * multiple threads, potentially across multiple cores, must therefore + * have a memory ordering imposed on it, for all code on all + * threads/cores to have a sufficiently coherent worldview. + * + * http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync and + * http://en.cppreference.com/w/cpp/atomic/memory_order go into more + * detail on all this, including examples of how each mode works. + * + * Note that for simplicity and practicality, not all of the modes in + * C++11 are supported. The missing C++11 modes are either subsumed by + * the modes we provide below, or not relevant for the CPUs we support + * in Gecko. These three modes are confusing enough as it is! + */ +enum MemoryOrdering { + /* + * Relaxed ordering is the simplest memory ordering: none at all. + * When the result of a write is observed, nothing may be inferred + * about other memory. Writes ostensibly performed "before" on the + * writing thread may not yet be visible. Writes performed "after" on + * the writing thread may already be visible, if the compiler or CPU + * reordered them. (The latter can happen if reads and/or writes get + * held up in per-processor caches.) Relaxed ordering means + * operations can always use cached values (as long as the actual + * updates to atomic values actually occur, correctly, eventually), so + * it's usually the fastest sort of atomic access. For this reason, + * *it's also the most dangerous kind of access*. + * + * Relaxed ordering is good for things like process-wide statistics + * counters that don't need to be consistent with anything else, so + * long as updates themselves are atomic. (And so long as any + * observations of that value can tolerate being out-of-date -- if you + * need some sort of up-to-date value, you need some sort of other + * synchronizing operation.) It's *not* good for locks, mutexes, + * reference counts, etc. that mediate access to other memory, or must + * be observably consistent with other memory. + * + * x86 architectures don't take advantage of the optimization + * opportunities that relaxed ordering permits. Thus it's possible + * that using relaxed ordering will "work" on x86 but fail elsewhere + * (ARM, say, which *does* implement non-sequentially-consistent + * relaxed ordering semantics). Be extra-careful using relaxed + * ordering if you can't easily test non-x86 architectures! + */ + Relaxed, + + /* + * When an atomic value is updated with ReleaseAcquire ordering, and + * that new value is observed with ReleaseAcquire ordering, prior + * writes (atomic or not) are also observable. What ReleaseAcquire + * *doesn't* give you is any observable ordering guarantees for + * ReleaseAcquire-ordered operations on different objects. For + * example, if there are two cores that each perform ReleaseAcquire + * operations on separate objects, each core may or may not observe + * the operations made by the other core. The only way the cores can + * be synchronized with ReleaseAcquire is if they both + * ReleaseAcquire-access the same object. This implies that you can't + * necessarily describe some global total ordering of ReleaseAcquire + * operations. + * + * ReleaseAcquire ordering is good for (as the name implies) atomic + * operations on values controlling ownership of things: reference + * counts, mutexes, and the like. However, if you are thinking about + * using these to implement your own locks or mutexes, you should take + * a good, hard look at actual lock or mutex primitives first. + */ + ReleaseAcquire, + + /* + * When an atomic value is updated with SequentiallyConsistent + * ordering, all writes observable when the update is observed, just + * as with ReleaseAcquire ordering. But, furthermore, a global total + * ordering of SequentiallyConsistent operations *can* be described. + * For example, if two cores perform SequentiallyConsistent operations + * on separate objects, one core will observably perform its update + * (and all previous operations will have completed), then the other + * core will observably perform its update (and all previous + * operations will have completed). (Although those previous + * operations aren't themselves ordered -- they could be intermixed, + * or ordered if they occur on atomic values with ordering + * requirements.) SequentiallyConsistent is the *simplest and safest* + * ordering of atomic operations -- it's always as if one operation + * happens, then another, then another, in some order -- and every + * core observes updates to happen in that single order. Because it + * has the most synchronization requirements, operations ordered this + * way also tend to be slowest. + * + * SequentiallyConsistent ordering can be desirable when multiple + * threads observe objects, and they all have to agree on the + * observable order of changes to them. People expect + * SequentiallyConsistent ordering, even if they shouldn't, when + * writing code, atomic or otherwise. SequentiallyConsistent is also + * the ordering of choice when designing lockless data structures. If + * you don't know what order to use, use this one. + */ + SequentiallyConsistent, +}; + +} // namespace mozilla + +// Build up the underlying intrinsics. +#ifdef MOZ_HAVE_CXX11_ATOMICS + +# include + +namespace mozilla { +namespace detail { + +/* + * We provide CompareExchangeFailureOrder to work around a bug in some + * versions of GCC's header. See bug 898491. + */ +template struct AtomicOrderConstraints; + +template<> +struct AtomicOrderConstraints +{ + static const std::memory_order AtomicRMWOrder = std::memory_order_relaxed; + static const std::memory_order LoadOrder = std::memory_order_relaxed; + static const std::memory_order StoreOrder = std::memory_order_relaxed; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_relaxed; +}; + +template<> +struct AtomicOrderConstraints +{ + static const std::memory_order AtomicRMWOrder = std::memory_order_acq_rel; + static const std::memory_order LoadOrder = std::memory_order_acquire; + static const std::memory_order StoreOrder = std::memory_order_release; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_acquire; +}; + +template<> +struct AtomicOrderConstraints +{ + static const std::memory_order AtomicRMWOrder = std::memory_order_seq_cst; + static const std::memory_order LoadOrder = std::memory_order_seq_cst; + static const std::memory_order StoreOrder = std::memory_order_seq_cst; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_seq_cst; +}; + +template +struct IntrinsicBase +{ + typedef std::atomic ValueType; + typedef AtomicOrderConstraints OrderedOp; +}; + +template +struct IntrinsicMemoryOps : public IntrinsicBase +{ + typedef IntrinsicBase Base; + + static T load(const typename Base::ValueType& aPtr) + { + return aPtr.load(Base::OrderedOp::LoadOrder); + } + + static void store(typename Base::ValueType& aPtr, T aVal) + { + aPtr.store(aVal, Base::OrderedOp::StoreOrder); + } + + static T exchange(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.exchange(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static bool compareExchange(typename Base::ValueType& aPtr, + T aOldVal, T aNewVal) + { + return aPtr.compare_exchange_strong(aOldVal, aNewVal, + Base::OrderedOp::AtomicRMWOrder, + Base::OrderedOp::CompareExchangeFailureOrder); + } +}; + +template +struct IntrinsicAddSub : public IntrinsicBase +{ + typedef IntrinsicBase Base; + + static T add(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_add(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T sub(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_sub(aVal, Base::OrderedOp::AtomicRMWOrder); + } +}; + +template +struct IntrinsicAddSub : public IntrinsicBase +{ + typedef IntrinsicBase Base; + + static T* add(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_add(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } + + static T* sub(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_sub(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } +private: + /* + * GCC 4.6's header has a bug where adding X to an + * atomic is not the same as adding X to a T*. Hence the need + * for this function to provide the correct addend. + */ + static ptrdiff_t fixupAddend(ptrdiff_t aVal) + { +#if defined(__clang__) || defined(_MSC_VER) + return aVal; +#elif defined(__GNUC__) && MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) && \ + !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) + return aVal * sizeof(T); +#else + return aVal; +#endif + } +}; + +template +struct IntrinsicIncDec : public IntrinsicAddSub +{ + typedef IntrinsicBase Base; + + static T inc(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::add(aPtr, 1); + } + + static T dec(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::sub(aPtr, 1); + } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ + typedef IntrinsicBase Base; + + static T or_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_or(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T xor_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_xor(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T and_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_and(aVal, Base::OrderedOp::AtomicRMWOrder); + } +}; + +template +struct AtomicIntrinsics + : public IntrinsicMemoryOps, public IntrinsicIncDec +{ +}; + +} // namespace detail +} // namespace mozilla + +#elif defined(__GNUC__) + +namespace mozilla { +namespace detail { + +/* + * The __sync_* family of intrinsics is documented here: + * + * http://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Atomic-Builtins.html + * + * While these intrinsics are deprecated in favor of the newer __atomic_* + * family of intrincs: + * + * http://gcc.gnu.org/onlinedocs/gcc-4.7.3/gcc/_005f_005fatomic-Builtins.html + * + * any GCC version that supports the __atomic_* intrinsics will also support + * the header and so will be handled above. We provide a version of + * atomics using the __sync_* intrinsics to support older versions of GCC. + * + * All __sync_* intrinsics that we use below act as full memory barriers, for + * both compiler and hardware reordering, except for __sync_lock_test_and_set, + * which is a only an acquire barrier. When we call __sync_lock_test_and_set, + * we add a barrier above it as appropriate. + */ + +template struct Barrier; + +/* + * Some processors (in particular, x86) don't require quite so many calls to + * __sync_sychronize as our specializations of Barrier produce. If + * performance turns out to be an issue, defining these specializations + * on a per-processor basis would be a good first tuning step. + */ + +template<> +struct Barrier +{ + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} + static void afterStore() {} +}; + +template<> +struct Barrier +{ + static void beforeLoad() {} + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() {} +}; + +template<> +struct Barrier +{ + static void beforeLoad() { __sync_synchronize(); } + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() { __sync_synchronize(); } +}; + +template +struct IntrinsicMemoryOps +{ + static T load(const T& aPtr) + { + Barrier::beforeLoad(); + T val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(T& aPtr, T aVal) + { + Barrier::beforeStore(); + aPtr = aVal; + Barrier::afterStore(); + } + + static T exchange(T& aPtr, T aVal) + { + // __sync_lock_test_and_set is only an acquire barrier; loads and stores + // can't be moved up from after to before it, but they can be moved down + // from before to after it. We may want a stricter ordering, so we need + // an explicit barrier. + Barrier::beforeStore(); + return __sync_lock_test_and_set(&aPtr, aVal); + } + + static bool compareExchange(T& aPtr, T aOldVal, T aNewVal) + { + return __sync_bool_compare_and_swap(&aPtr, aOldVal, aNewVal); + } +}; + +template +struct IntrinsicAddSub +{ + typedef T ValueType; + + static T add(T& aPtr, T aVal) + { + return __sync_fetch_and_add(&aPtr, aVal); + } + + static T sub(T& aPtr, T aVal) + { + return __sync_fetch_and_sub(&aPtr, aVal); + } +}; + +template +struct IntrinsicAddSub +{ + typedef T* ValueType; + + /* + * The reinterpret_casts are needed so that + * __sync_fetch_and_{add,sub} will properly type-check. + * + * Also, these functions do not provide standard semantics for + * pointer types, so we need to adjust the addend. + */ + static ValueType add(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_add(&aPtr, amount); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_sub(&aPtr, amount); + } +}; + +template +struct IntrinsicIncDec : public IntrinsicAddSub +{ + static T inc(T& aPtr) { return IntrinsicAddSub::add(aPtr, 1); } + static T dec(T& aPtr) { return IntrinsicAddSub::sub(aPtr, 1); } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ + static T or_( T& aPtr, T aVal) { return __sync_fetch_and_or(&aPtr, aVal); } + static T xor_(T& aPtr, T aVal) { return __sync_fetch_and_xor(&aPtr, aVal); } + static T and_(T& aPtr, T aVal) { return __sync_fetch_and_and(&aPtr, aVal); } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ +}; + +} // namespace detail +} // namespace mozilla + +#elif defined(_MSC_VER) + +/* + * Windows comes with a full complement of atomic operations. + * Unfortunately, most of those aren't available for Windows XP (even if + * the compiler supports intrinsics for them), which is the oldest + * version of Windows we support. Therefore, we only provide operations + * on 32-bit datatypes for 32-bit Windows versions; for 64-bit Windows + * versions, we support 64-bit datatypes as well. + */ + +# include + +# pragma intrinsic(_InterlockedExchangeAdd) +# pragma intrinsic(_InterlockedOr) +# pragma intrinsic(_InterlockedXor) +# pragma intrinsic(_InterlockedAnd) +# pragma intrinsic(_InterlockedExchange) +# pragma intrinsic(_InterlockedCompareExchange) + +namespace mozilla { +namespace detail { + +# if !defined(_M_IX86) && !defined(_M_X64) + /* + * The implementations below are optimized for x86ish systems. You + * will have to modify them if you are porting to Windows on a + * different architecture. + */ +# error "Unknown CPU type" +# endif + +/* + * The PrimitiveIntrinsics template should define |Type|, the datatype of size + * DataSize upon which we operate, and the following eight functions. + * + * static Type add(Type* aPtr, Type aVal); + * static Type sub(Type* aPtr, Type aVal); + * static Type or_(Type* aPtr, Type aVal); + * static Type xor_(Type* aPtr, Type aVal); + * static Type and_(Type* aPtr, Type aVal); + * + * These functions perform the obvious operation on the value contained in + * |*aPtr| combined with |aVal| and return the value previously stored in + * |*aPtr|. + * + * static void store(Type* aPtr, Type aVal); + * + * This function atomically stores |aVal| into |*aPtr| and must provide a full + * memory fence after the store to prevent compiler and hardware instruction + * reordering. It should also act as a compiler barrier to prevent reads and + * writes from moving to after the store. + * + * static Type exchange(Type* aPtr, Type aVal); + * + * This function atomically stores |aVal| into |*aPtr| and returns the + * previous contents of |*aPtr|; + * + * static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal); + * + * This function atomically performs the following operation: + * + * if (*aPtr == aOldVal) { + * *aPtr = aNewVal; + * return true; + * } else { + * return false; + * } + * + */ +template struct PrimitiveIntrinsics; + +template<> +struct PrimitiveIntrinsics<4> +{ + typedef long Type; + + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * _InterlockedExchangeSubtract isn't available before Windows 7, + * and we must support Windows XP. + */ + return _InterlockedExchangeAdd(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange(aPtr, aNewVal, aOldVal) == aOldVal; + } +}; + +# if defined(_M_X64) + +# pragma intrinsic(_InterlockedExchangeAdd64) +# pragma intrinsic(_InterlockedOr64) +# pragma intrinsic(_InterlockedXor64) +# pragma intrinsic(_InterlockedAnd64) +# pragma intrinsic(_InterlockedExchange64) +# pragma intrinsic(_InterlockedCompareExchange64) + +template <> +struct PrimitiveIntrinsics<8> +{ + typedef __int64 Type; + + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd64(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * There is no _InterlockedExchangeSubtract64. + */ + return _InterlockedExchangeAdd64(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr64(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor64(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd64(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange64(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange64(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange64(aPtr, aNewVal, aOldVal) == aOldVal; + } +}; + +# endif + +# pragma intrinsic(_ReadWriteBarrier) + +template struct Barrier; + +/* + * We do not provide an afterStore method in Barrier, as Relaxed and + * ReleaseAcquire orderings do not require one, and the required barrier + * for SequentiallyConsistent is handled by PrimitiveIntrinsics. + */ + +template<> +struct Barrier +{ + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} +}; + +template<> +struct Barrier +{ + static void beforeLoad() {} + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } +}; + +template<> +struct Barrier +{ + static void beforeLoad() { _ReadWriteBarrier(); } + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } +}; + +template +struct CastHelper +{ + static PrimType toPrimType(T aVal) { return static_cast(aVal); } + static T fromPrimType(PrimType aVal) { return static_cast(aVal); } +}; + +template +struct CastHelper +{ + static PrimType toPrimType(T* aVal) { return reinterpret_cast(aVal); } + static T* fromPrimType(PrimType aVal) { return reinterpret_cast(aVal); } +}; + +template +struct IntrinsicBase +{ + typedef T ValueType; + typedef PrimitiveIntrinsics Primitives; + typedef typename Primitives::Type PrimType; + static_assert(sizeof(PrimType) == sizeof(T), + "Selection of PrimitiveIntrinsics was wrong"); + typedef CastHelper Cast; +}; + +template +struct IntrinsicMemoryOps : public IntrinsicBase +{ + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + + static ValueType load(const ValueType& aPtr) + { + Barrier::beforeLoad(); + ValueType val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(ValueType& aPtr, ValueType aVal) + { + // For SequentiallyConsistent, Primitives::store() will generate the + // proper memory fence. Everything else just needs a barrier before + // the store. + if (Order == SequentiallyConsistent) { + Primitives::store(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + } else { + Barrier::beforeStore(); + aPtr = aVal; + } + } + + static ValueType exchange(ValueType& aPtr, ValueType aVal) + { + PrimType oldval = + Primitives::exchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + return Cast::fromPrimType(oldval); + } + + static bool compareExchange(ValueType& aPtr, ValueType aOldVal, + ValueType aNewVal) + { + return Primitives::compareExchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aOldVal), + Cast::toPrimType(aNewVal)); + } +}; + +template +struct IntrinsicApplyHelper : public IntrinsicBase +{ + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + typedef PrimType (*BinaryOp)(PrimType*, PrimType); + typedef PrimType (*UnaryOp)(PrimType*); + + static ValueType applyBinaryFunction(BinaryOp aOp, ValueType& aPtr, + ValueType aVal) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + PrimType primTypeVal = Cast::toPrimType(aVal); + return Cast::fromPrimType(aOp(primTypePtr, primTypeVal)); + } + + static ValueType applyUnaryFunction(UnaryOp aOp, ValueType& aPtr) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + return Cast::fromPrimType(aOp(primTypePtr)); + } +}; + +template +struct IntrinsicAddSub : public IntrinsicApplyHelper +{ + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::add, aPtr, aVal); + } + + static ValueType sub(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::sub, aPtr, aVal); + } +}; + +template +struct IntrinsicAddSub : public IntrinsicApplyHelper +{ + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::add, aPtr, + (ValueType)(aAmount * sizeof(T))); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::sub, aPtr, + (ValueType)(aAmount * sizeof(T))); + } +}; + +template +struct IntrinsicIncDec : public IntrinsicAddSub +{ + typedef typename IntrinsicAddSub::ValueType ValueType; + static ValueType inc(ValueType& aPtr) { return add(aPtr, 1); } + static ValueType dec(ValueType& aPtr) { return sub(aPtr, 1); } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ + typedef typename IntrinsicIncDec::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType or_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::or_, aPtr, aVal); + } + + static ValueType xor_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::xor_, aPtr, aVal); + } + + static ValueType and_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::and_, aPtr, aVal); + } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ + typedef typename IntrinsicMemoryOps::ValueType ValueType; + // This is required to make us be able to build with MSVC10, for unknown + // reasons. + typedef typename IntrinsicBase::Primitives Primitives; +}; + +} // namespace detail +} // namespace mozilla + +#else +# error "Atomic compiler intrinsics are not supported on your platform" +#endif + +namespace mozilla { + +namespace detail { + +template +class AtomicBase +{ + // We only support 32-bit types on 32-bit Windows, which constrains our + // implementation elsewhere. But we support pointer-sized types everywhere. + static_assert(sizeof(T) == 4 || (sizeof(uintptr_t) == 8 && sizeof(T) == 8), + "mozilla/Atomics.h only supports 32-bit and pointer-sized types"); + +protected: + typedef typename detail::AtomicIntrinsics Intrinsics; + typename Intrinsics::ValueType mValue; + +public: + MOZ_CONSTEXPR AtomicBase() : mValue() {} + explicit MOZ_CONSTEXPR AtomicBase(T aInit) : mValue(aInit) {} + + // Note: we can't provide operator T() here because Atomic inherits + // from AtomcBase with T=uint32_t and not T=bool. If we implemented + // operator T() here, it would cause errors when comparing Atomic with + // a regular bool. + + T operator=(T aVal) + { + Intrinsics::store(mValue, aVal); + return aVal; + } + + /** + * Performs an atomic swap operation. aVal is stored and the previous + * value of this variable is returned. + */ + T exchange(T aVal) + { + return Intrinsics::exchange(mValue, aVal); + } + + /** + * Performs an atomic compare-and-swap operation and returns true if it + * succeeded. This is equivalent to atomically doing + * + * if (mValue == aOldValue) { + * mValue = aNewValue; + * return true; + * } else { + * return false; + * } + */ + bool compareExchange(T aOldValue, T aNewValue) + { + return Intrinsics::compareExchange(mValue, aOldValue, aNewValue); + } + +private: + template + AtomicBase(const AtomicBase& aCopy) MOZ_DELETE; +}; + +template +class AtomicBaseIncDec : public AtomicBase +{ + typedef typename detail::AtomicBase Base; + +public: + MOZ_CONSTEXPR AtomicBaseIncDec() : Base() {} + explicit MOZ_CONSTEXPR AtomicBaseIncDec(T aInit) : Base(aInit) {} + + using Base::operator=; + + operator T() const { return Base::Intrinsics::load(Base::mValue); } + T operator++(int) { return Base::Intrinsics::inc(Base::mValue); } + T operator--(int) { return Base::Intrinsics::dec(Base::mValue); } + T operator++() { return Base::Intrinsics::inc(Base::mValue) + 1; } + T operator--() { return Base::Intrinsics::dec(Base::mValue) - 1; } + +private: + template + AtomicBaseIncDec(const AtomicBaseIncDec& aCopy) MOZ_DELETE; +}; + +} // namespace detail + +/** + * A wrapper for a type that enforces that all memory accesses are atomic. + * + * In general, where a variable |T foo| exists, |Atomic foo| can be used in + * its place. Implementations for integral and pointer types are provided + * below. + * + * Atomic accesses are sequentially consistent by default. You should + * use the default unless you are tall enough to ride the + * memory-ordering roller coaster (if you're not sure, you aren't) and + * you have a compelling reason to do otherwise. + * + * There is one exception to the case of atomic memory accesses: providing an + * initial value of the atomic value is not guaranteed to be atomic. This is a + * deliberate design choice that enables static atomic variables to be declared + * without introducing extra static constructors. + */ +template +class Atomic; + +/** + * Atomic implementation for integral types. + * + * In addition to atomic store and load operations, compound assignment and + * increment/decrement operators are implemented which perform the + * corresponding read-modify-write operation atomically. Finally, an atomic + * swap method is provided. + */ +template +class Atomic::value && + !IsSame::value>::Type> + : public detail::AtomicBaseIncDec +{ + typedef typename detail::AtomicBaseIncDec Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + + using Base::operator=; + + T operator+=(T aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } + + T operator-=(T aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } + + T operator|=(T aVal) + { + return Base::Intrinsics::or_(Base::mValue, aVal) | aVal; + } + + T operator^=(T aVal) + { + return Base::Intrinsics::xor_(Base::mValue, aVal) ^ aVal; + } + + T operator&=(T aVal) + { + return Base::Intrinsics::and_(Base::mValue, aVal) & aVal; + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +/** + * Atomic implementation for pointer types. + * + * An atomic compare-and-swap primitive for pointer variables is provided, as + * are atomic increment and decement operators. Also provided are the compound + * assignment operators for addition and subtraction. Atomic swap (via + * exchange()) is included as well. + */ +template +class Atomic : public detail::AtomicBaseIncDec +{ + typedef typename detail::AtomicBaseIncDec Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T* aInit) : Base(aInit) {} + + using Base::operator=; + + T* operator+=(ptrdiff_t aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } + + T* operator-=(ptrdiff_t aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +/** + * Atomic implementation for enum types. + * + * The atomic store and load operations and the atomic swap method is provided. + */ +template +class Atomic::value>::Type> + : public detail::AtomicBase +{ + typedef typename detail::AtomicBase Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + + operator T() const { return Base::Intrinsics::load(Base::mValue); } + + using Base::operator=; + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +/** + * Atomic implementation for boolean types. + * + * The atomic store and load operations and the atomic swap method is provided. + * + * Note: + * + * - sizeof(Atomic) != sizeof(bool) for some implementations of + * bool and/or some implementations of std::atomic. This is allowed in + * [atomic.types.generic]p9. + * + * - It's not obvious whether the 8-bit atomic functions on Windows are always + * inlined or not. If they are not inlined, the corresponding functions in the + * runtime library are not available on Windows XP. This is why we implement + * Atomic with an underlying type of uint32_t. + */ +template +class Atomic + : protected detail::AtomicBase +{ + typedef typename detail::AtomicBase Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(bool aInit) : Base(aInit) {} + + // We provide boolean wrappers for the underlying AtomicBase methods. + operator bool() const + { + return Base::Intrinsics::load(Base::mValue); + } + + bool operator=(bool aVal) + { + return Base::operator=(aVal); + } + + bool exchange(bool aVal) + { + return Base::exchange(aVal); + } + + bool compareExchange(bool aOldValue, bool aNewValue) + { + return Base::compareExchange(aOldValue, aNewValue); + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +} // namespace mozilla + +#endif /* mozilla_Atomics_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Attributes.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Attributes.h new file mode 100644 index 0000000000..cdce8c7717 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Attributes.h @@ -0,0 +1,536 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implementations of various class and method modifier attributes. */ + +#ifndef mozilla_Attributes_h +#define mozilla_Attributes_h + +#include "mozilla/Compiler.h" + +/* + * MOZ_ALWAYS_INLINE is a macro which expands to tell the compiler that the + * method decorated with it must be inlined, even if the compiler thinks + * otherwise. This is only a (much) stronger version of the inline hint: + * compilers are not guaranteed to respect it (although they're much more likely + * to do so). + * + * The MOZ_ALWAYS_INLINE_EVEN_DEBUG macro is yet stronger. It tells the + * compiler to inline even in DEBUG builds. It should be used very rarely. + */ +#if defined(_MSC_VER) +# define MOZ_ALWAYS_INLINE_EVEN_DEBUG __forceinline +#elif defined(__GNUC__) +# define MOZ_ALWAYS_INLINE_EVEN_DEBUG __attribute__((always_inline)) inline +#else +# define MOZ_ALWAYS_INLINE_EVEN_DEBUG inline +#endif + +#if !defined(DEBUG) +# define MOZ_ALWAYS_INLINE MOZ_ALWAYS_INLINE_EVEN_DEBUG +#elif defined(_MSC_VER) && !defined(__cplusplus) +# define MOZ_ALWAYS_INLINE __inline +#else +# define MOZ_ALWAYS_INLINE inline +#endif + +#if defined(_MSC_VER) +/* + * g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality + * without warnings (functionality used by the macros below). These modes are + * detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, more + * standardly, by checking whether __cplusplus has a C++11 or greater value. + * Current versions of g++ do not correctly set __cplusplus, so we check both + * for forward compatibility. + * + * Even though some versions of MSVC support explicit conversion operators, we + * don't indicate support for them here, due to + * http://stackoverflow.com/questions/20498142/visual-studio-2013-explicit-keyword-bug + */ +# if _MSC_VER >= 1800 +# define MOZ_HAVE_CXX11_DELETE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_FINAL final +# else +# if defined(__clang__) +# error Please do not try to use clang-cl with MSVC10 or below emulation! +# endif + /* MSVC <= 10 used to spell "final" as "sealed". */ +# define MOZ_HAVE_CXX11_FINAL sealed +# endif +# define MOZ_HAVE_CXX11_OVERRIDE +# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) +# define MOZ_HAVE_NORETURN __declspec(noreturn) +#elif defined(__clang__) + /* + * Per Clang documentation, "Note that marketing version numbers should not + * be used to check for language features, as different vendors use different + * numbering schemes. Instead, use the feature checking macros." + */ +# ifndef __has_extension +# define __has_extension __has_feature /* compatibility, for older versions of clang */ +# endif +# if __has_extension(cxx_constexpr) +# define MOZ_HAVE_CXX11_CONSTEXPR +# endif +# if __has_extension(cxx_explicit_conversions) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif +# if __has_extension(cxx_deleted_functions) +# define MOZ_HAVE_CXX11_DELETE +# endif +# if __has_extension(cxx_override_control) +# define MOZ_HAVE_CXX11_OVERRIDE +# define MOZ_HAVE_CXX11_FINAL final +# endif +# if __has_attribute(noinline) +# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) +# endif +# if __has_attribute(noreturn) +# define MOZ_HAVE_NORETURN __attribute__((noreturn)) +# endif +#elif defined(__GNUC__) +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# if MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) +# define MOZ_HAVE_CXX11_OVERRIDE +# define MOZ_HAVE_CXX11_FINAL final +# endif +# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) +# define MOZ_HAVE_CXX11_CONSTEXPR +# endif +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif +# define MOZ_HAVE_CXX11_DELETE +# else + /* __final is a non-C++11 GCC synonym for 'final', per GCC r176655. */ +# if MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) +# define MOZ_HAVE_CXX11_FINAL __final +# endif +# endif +# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) +# define MOZ_HAVE_NORETURN __attribute__((noreturn)) +#endif + +/* + * When built with clang analyzer (a.k.a scan-build), define MOZ_HAVE_NORETURN + * to mark some false positives + */ +#ifdef __clang_analyzer__ +# if __has_extension(attribute_analyzer_noreturn) +# define MOZ_HAVE_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) +# endif +#endif + +/* + * The MOZ_CONSTEXPR specifier declares that a C++11 compiler can evaluate a + * function at compile time. A constexpr function cannot examine any values + * except its arguments and can have no side effects except its return value. + * The MOZ_CONSTEXPR_VAR specifier tells a C++11 compiler that a variable's + * value may be computed at compile time. It should be prefered to just + * marking variables as MOZ_CONSTEXPR because if the compiler does not support + * constexpr it will fall back to making the variable const, and some compilers + * do not accept variables being marked both const and constexpr. + */ +#ifdef MOZ_HAVE_CXX11_CONSTEXPR +# define MOZ_CONSTEXPR constexpr +# define MOZ_CONSTEXPR_VAR constexpr +#else +# define MOZ_CONSTEXPR /* no support */ +# define MOZ_CONSTEXPR_VAR const +#endif + +/* + * MOZ_EXPLICIT_CONVERSION is a specifier on a type conversion + * overloaded operator that declares that a C++11 compiler should restrict + * this operator to allow only explicit type conversions, disallowing + * implicit conversions. + * + * Example: + * + * template + * class Ptr + * { + * T* mPtr; + * MOZ_EXPLICIT_CONVERSION operator bool() const + * { + * return mPtr != nullptr; + * } + * }; + * + */ +#ifdef MOZ_HAVE_EXPLICIT_CONVERSION +# define MOZ_EXPLICIT_CONVERSION explicit +#else +# define MOZ_EXPLICIT_CONVERSION /* no support */ +#endif + +/* + * MOZ_NEVER_INLINE is a macro which expands to tell the compiler that the + * method decorated with it must never be inlined, even if the compiler would + * otherwise choose to inline the method. Compilers aren't absolutely + * guaranteed to support this, but most do. + */ +#if defined(MOZ_HAVE_NEVER_INLINE) +# define MOZ_NEVER_INLINE MOZ_HAVE_NEVER_INLINE +#else +# define MOZ_NEVER_INLINE /* no support */ +#endif + +/* + * MOZ_NORETURN, specified at the start of a function declaration, indicates + * that the given function does not return. (The function definition does not + * need to be annotated.) + * + * MOZ_NORETURN void abort(const char* msg); + * + * This modifier permits the compiler to optimize code assuming a call to such a + * function will never return. It also enables the compiler to avoid spurious + * warnings about not initializing variables, or about any other seemingly-dodgy + * operations performed after the function returns. + * + * This modifier does not affect the corresponding function's linking behavior. + */ +#if defined(MOZ_HAVE_NORETURN) +# define MOZ_NORETURN MOZ_HAVE_NORETURN +#else +# define MOZ_NORETURN /* no support */ +#endif + +/* + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS, specified at the end of a function + * declaration, indicates that for the purposes of static analysis, this + * function does not return. (The function definition does not need to be + * annotated.) + * + * MOZ_ReportCrash(const char* s, const char* file, int ln) + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS + * + * Some static analyzers, like scan-build from clang, can use this information + * to eliminate false positives. From the upstream documentation of scan-build: + * "This attribute is useful for annotating assertion handlers that actually + * can return, but for the purpose of using the analyzer we want to pretend + * that such functions do not return." + * + */ +#if defined(MOZ_HAVE_ANALYZER_NORETURN) +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS MOZ_HAVE_ANALYZER_NORETURN +#else +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS /* no support */ +#endif + +/* + * MOZ_ASAN_BLACKLIST is a macro to tell AddressSanitizer (a compile-time + * instrumentation shipped with Clang and GCC) to not instrument the annotated + * function. Furthermore, it will prevent the compiler from inlining the + * function because inlining currently breaks the blacklisting mechanism of + * AddressSanitizer. + */ +#if defined(__has_feature) +# if __has_feature(address_sanitizer) +# define MOZ_HAVE_ASAN_BLACKLIST +# endif +#elif defined(__GNUC__) +# if defined(__SANITIZE_ADDRESS__) +# define MOZ_HAVE_ASAN_BLACKLIST +# endif +#endif + +#if defined(MOZ_HAVE_ASAN_BLACKLIST) +# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) +#else +# define MOZ_ASAN_BLACKLIST /* nothing */ +#endif + +/* + * MOZ_TSAN_BLACKLIST is a macro to tell ThreadSanitizer (a compile-time + * instrumentation shipped with Clang) to not instrument the annotated function. + * Furthermore, it will prevent the compiler from inlining the function because + * inlining currently breaks the blacklisting mechanism of ThreadSanitizer. + */ +#if defined(__has_feature) +# if __has_feature(thread_sanitizer) +# define MOZ_TSAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_thread)) +# else +# define MOZ_TSAN_BLACKLIST /* nothing */ +# endif +#else +# define MOZ_TSAN_BLACKLIST /* nothing */ +#endif + +#ifdef __cplusplus + +/* + * MOZ_DELETE, specified immediately prior to the ';' terminating an undefined- + * method declaration, attempts to delete that method from the corresponding + * class. An attempt to use the method will always produce an error *at compile + * time* (instead of sometimes as late as link time) when this macro can be + * implemented. For example, you can use MOZ_DELETE to produce classes with no + * implicit copy constructor or assignment operator: + * + * struct NonCopyable + * { + * private: + * NonCopyable(const NonCopyable& aOther) MOZ_DELETE; + * void operator=(const NonCopyable& aOther) MOZ_DELETE; + * }; + * + * If MOZ_DELETE can't be implemented for the current compiler, use of the + * annotated method will still cause an error, but the error might occur at link + * time in some cases rather than at compile time. + * + * MOZ_DELETE relies on C++11 functionality not universally implemented. As a + * backstop, method declarations using MOZ_DELETE should be private. + */ +#if defined(MOZ_HAVE_CXX11_DELETE) +# define MOZ_DELETE = delete +#else +# define MOZ_DELETE /* no support */ +#endif + +/* + * MOZ_OVERRIDE explicitly indicates that a virtual member function in a class + * overrides a member function of a base class, rather than potentially being a + * new member function. MOZ_OVERRIDE should be placed immediately before the + * ';' terminating the member function's declaration, or before '= 0;' if the + * member function is pure. If the member function is defined in the class + * definition, it should appear before the opening brace of the function body. + * + * class Base + * { + * public: + * virtual void f() = 0; + * }; + * class Derived1 : public Base + * { + * public: + * virtual void f() MOZ_OVERRIDE; + * }; + * class Derived2 : public Base + * { + * public: + * virtual void f() MOZ_OVERRIDE = 0; + * }; + * class Derived3 : public Base + * { + * public: + * virtual void f() MOZ_OVERRIDE { } + * }; + * + * In compilers supporting C++11 override controls, MOZ_OVERRIDE *requires* that + * the function marked with it override a member function of a base class: it + * is a compile error if it does not. Otherwise MOZ_OVERRIDE does not affect + * semantics and merely documents the override relationship to the reader (but + * of course must still be used correctly to not break C++11 compilers). + */ +#if defined(MOZ_HAVE_CXX11_OVERRIDE) +# define MOZ_OVERRIDE override +#else +# define MOZ_OVERRIDE /* no support */ +#endif + +/* + * MOZ_FINAL indicates that some functionality cannot be overridden through + * inheritance. It can be used to annotate either classes/structs or virtual + * member functions. + * + * To annotate a class/struct with MOZ_FINAL, place MOZ_FINAL immediately after + * the name of the class, before the list of classes from which it derives (if + * any) and before its opening brace. MOZ_FINAL must not be used to annotate + * unnamed classes or structs. (With some compilers, and with C++11 proper, the + * underlying expansion is ambiguous with specifying a class name.) + * + * class Base MOZ_FINAL + * { + * public: + * Base(); + * ~Base(); + * virtual void f() { } + * }; + * // This will be an error in some compilers: + * class Derived : public Base + * { + * public: + * ~Derived() { } + * }; + * + * One particularly common reason to specify MOZ_FINAL upon a class is to tell + * the compiler that it's not dangerous for it to have a non-virtual destructor + * yet have one or more virtual functions, silencing the warning it might emit + * in this case. Suppose Base above weren't annotated with MOZ_FINAL. Because + * ~Base() is non-virtual, an attempt to delete a Derived* through a Base* + * wouldn't call ~Derived(), so any cleanup ~Derived() might do wouldn't happen. + * (Formally C++ says behavior is undefined, but compilers will likely just call + * ~Base() and not ~Derived().) Specifying MOZ_FINAL tells the compiler that + * it's safe for the destructor to be non-virtual. + * + * In compilers implementing final controls, it is an error to inherit from a + * class annotated with MOZ_FINAL. In other compilers it serves only as + * documentation. + * + * To annotate a virtual member function with MOZ_FINAL, place MOZ_FINAL + * immediately before the ';' terminating the member function's declaration, or + * before '= 0;' if the member function is pure. If the member function is + * defined in the class definition, it should appear before the opening brace of + * the function body. (This placement is identical to that for MOZ_OVERRIDE. + * If both are used, they should appear in the order 'MOZ_FINAL MOZ_OVERRIDE' + * for consistency.) + * + * class Base + * { + * public: + * virtual void f() MOZ_FINAL; + * }; + * class Derived + * { + * public: + * // This will be an error in some compilers: + * virtual void f(); + * }; + * + * In compilers implementing final controls, it is an error for a derived class + * to override a method annotated with MOZ_FINAL. In other compilers it serves + * only as documentation. + */ +#if defined(MOZ_HAVE_CXX11_FINAL) +# define MOZ_FINAL MOZ_HAVE_CXX11_FINAL +#else +# define MOZ_FINAL /* no support */ +#endif + +/** + * MOZ_WARN_UNUSED_RESULT tells the compiler to emit a warning if a function's + * return value is not used by the caller. + * + * Place this attribute at the very beginning of a function definition. For + * example, write + * + * MOZ_WARN_UNUSED_RESULT int foo(); + * + * or + * + * MOZ_WARN_UNUSED_RESULT int foo() { return 42; } + */ +#if defined(__GNUC__) || defined(__clang__) +# define MOZ_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) +#else +# define MOZ_WARN_UNUSED_RESULT +#endif + +/* + * The following macros are attributes that support the static analysis plugin + * included with Mozilla, and will be implemented (when such support is enabled) + * as C++11 attributes. Since such attributes are legal pretty much everywhere + * and have subtly different semantics depending on their placement, the + * following is a guide on where to place the attributes. + * + * Attributes that apply to a struct or class precede the name of the class: + * (Note that this is different from the placement of MOZ_FINAL for classes!) + * + * class MOZ_CLASS_ATTRIBUTE SomeClass {}; + * + * Attributes that apply to functions follow the parentheses and const + * qualifiers but precede MOZ_FINAL, MOZ_OVERRIDE and the function body: + * + * void DeclaredFunction() MOZ_FUNCTION_ATTRIBUTE; + * void SomeFunction() MOZ_FUNCTION_ATTRIBUTE {} + * void PureFunction() const MOZ_FUNCTION_ATTRIBUTE = 0; + * void OverriddenFunction() MOZ_FUNCTION_ATTIRBUTE MOZ_OVERRIDE; + * + * Attributes that apply to variables or parameters follow the variable's name: + * + * int variable MOZ_VARIABLE_ATTRIBUTE; + * + * Attributes that apply to types follow the type name: + * + * typedef int MOZ_TYPE_ATTRIBUTE MagicInt; + * int MOZ_TYPE_ATTRIBUTE someVariable; + * int* MOZ_TYPE_ATTRIBUTE magicPtrInt; + * int MOZ_TYPE_ATTRIBUTE* ptrToMagicInt; + * + * Attributes that apply to statements precede the statement: + * + * MOZ_IF_ATTRIBUTE if (x == 0) + * MOZ_DO_ATTRIBUTE do { } while (0); + * + * Attributes that apply to labels precede the label: + * + * MOZ_LABEL_ATTRIBUTE target: + * goto target; + * MOZ_CASE_ATTRIBUTE case 5: + * MOZ_DEFAULT_ATTRIBUTE default: + * + * The static analyses that are performed by the plugin are as follows: + * + * MOZ_MUST_OVERRIDE: Applies to all C++ member functions. All immediate + * subclasses must provide an exact override of this method; if a subclass + * does not override this method, the compiler will emit an error. This + * attribute is not limited to virtual methods, so if it is applied to a + * nonvirtual method and the subclass does not provide an equivalent + * definition, the compiler will emit an error. + * MOZ_STACK_CLASS: Applies to all classes. Any class with this annotation is + * expected to live on the stack, so it is a compile-time error to use it, or + * an array of such objects, as a global or static variable, or as the type of + * a new expression (unless placement new is being used). If a member of + * another class uses this class, or if another class inherits from this + * class, then it is considered to be a stack class as well, although this + * attribute need not be provided in such cases. + * MOZ_NONHEAP_CLASS: Applies to all classes. Any class with this annotation is + * expected to live on the stack or in static storage, so it is a compile-time + * error to use it, or an array of such objects, as the type of a new + * expression (unless placement new is being used). If a member of another + * class uses this class, or if another class inherits from this class, then + * it is considered to be a non-heap class as well, although this attribute + * need not be provided in such cases. + * MOZ_HEAP_ALLOCATOR: Applies to any function. This indicates that the return + * value is allocated on the heap, and will as a result check such allocations + * during MOZ_STACK_CLASS and MOZ_NONHEAP_CLASS annotation checking. + * MOZ_IMPLICIT: Applies to constructors. Implicit conversion constructors + * are disallowed by default unless they are marked as MOZ_IMPLICIT. This + * attribute must be used for constructors which intend to provide implicit + * conversions. + */ +#ifdef MOZ_CLANG_PLUGIN +# define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override"))) +# define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class"))) +# define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class"))) +# define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) +/* + * It turns out that clang doesn't like void func() __attribute__ {} without a + * warning, so use pragmas to disable the warning. This code won't work on GCC + * anyways, so the warning is safe to ignore. + */ +# define MOZ_HEAP_ALLOCATOR \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((annotate("moz_heap_allocator"))) \ + _Pragma("clang diagnostic pop") +#else +# define MOZ_MUST_OVERRIDE /* nothing */ +# define MOZ_STACK_CLASS /* nothing */ +# define MOZ_NONHEAP_CLASS /* nothing */ +# define MOZ_IMPLICIT /* nothing */ +# define MOZ_HEAP_ALLOCATOR /* nothing */ +#endif /* MOZ_CLANG_PLUGIN */ + +/* + * MOZ_THIS_IN_INITIALIZER_LIST is used to avoid a warning when we know that + * it's safe to use 'this' in an initializer list. + */ +#ifdef _MSC_VER +# define MOZ_THIS_IN_INITIALIZER_LIST() \ + __pragma(warning(push)) \ + __pragma(warning(disable:4355)) \ + this \ + __pragma(warning(pop)) +#else +# define MOZ_THIS_IN_INITIALIZER_LIST() this +#endif + +#endif /* __cplusplus */ + +#endif /* mozilla_Attributes_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/BloomFilter.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/BloomFilter.h new file mode 100644 index 0000000000..6757e41181 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/BloomFilter.h @@ -0,0 +1,256 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * A counting Bloom filter implementation. This allows consumers to + * do fast probabilistic "is item X in set Y?" testing which will + * never answer "no" when the correct answer is "yes" (but might + * incorrectly answer "yes" when the correct answer is "no"). + */ + +#ifndef mozilla_BloomFilter_h +#define mozilla_BloomFilter_h + +#include "mozilla/Assertions.h" +#include "mozilla/Likely.h" + +#include +#include + +namespace mozilla { + +/* + * This class implements a counting Bloom filter as described at + * , with + * 8-bit counters. This allows quick probabilistic answers to the + * question "is object X in set Y?" where the contents of Y might not + * be time-invariant. The probabilistic nature of the test means that + * sometimes the answer will be "yes" when it should be "no". If the + * answer is "no", then X is guaranteed not to be in Y. + * + * The filter is parametrized on KeySize, which is the size of the key + * generated by each of hash functions used by the filter, in bits, + * and the type of object T being added and removed. T must implement + * a |uint32_t hash() const| method which returns a uint32_t hash key + * that will be used to generate the two separate hash functions for + * the Bloom filter. This hash key MUST be well-distributed for good + * results! KeySize is not allowed to be larger than 16. + * + * The filter uses exactly 2**KeySize bytes of memory. From now on we + * will refer to the memory used by the filter as M. + * + * The expected rate of incorrect "yes" answers depends on M and on + * the number N of objects in set Y. As long as N is small compared + * to M, the rate of such answers is expected to be approximately + * 4*(N/M)**2 for this filter. In practice, if Y has a few hundred + * elements then using a KeySize of 12 gives a reasonably low + * incorrect answer rate. A KeySize of 12 has the additional benefit + * of using exactly one page for the filter in typical hardware + * configurations. + */ + +template +class BloomFilter +{ + /* + * A counting Bloom filter with 8-bit counters. For now we assume + * that having two hash functions is enough, but we may revisit that + * decision later. + * + * The filter uses an array with 2**KeySize entries. + * + * Assuming a well-distributed hash function, a Bloom filter with + * array size M containing N elements and + * using k hash function has expected false positive rate exactly + * + * $ (1 - (1 - 1/M)^{kN})^k $ + * + * because each array slot has a + * + * $ (1 - 1/M)^{kN} $ + * + * chance of being 0, and the expected false positive rate is the + * probability that all of the k hash functions will hit a nonzero + * slot. + * + * For reasonable assumptions (M large, kN large, which should both + * hold if we're worried about false positives) about M and kN this + * becomes approximately + * + * $$ (1 - \exp(-kN/M))^k $$ + * + * For our special case of k == 2, that's $(1 - \exp(-2N/M))^2$, + * or in other words + * + * $$ N/M = -0.5 * \ln(1 - \sqrt(r)) $$ + * + * where r is the false positive rate. This can be used to compute + * the desired KeySize for a given load N and false positive rate r. + * + * If N/M is assumed small, then the false positive rate can + * further be approximated as 4*N^2/M^2. So increasing KeySize by + * 1, which doubles M, reduces the false positive rate by about a + * factor of 4, and a false positive rate of 1% corresponds to + * about M/N == 20. + * + * What this means in practice is that for a few hundred keys using a + * KeySize of 12 gives false positive rates on the order of 0.25-4%. + * + * Similarly, using a KeySize of 10 would lead to a 4% false + * positive rate for N == 100 and to quite bad false positive + * rates for larger N. + */ +public: + BloomFilter() + { + static_assert(KeySize <= kKeyShift, "KeySize too big"); + + // Should we have a custom operator new using calloc instead and + // require that we're allocated via the operator? + clear(); + } + + /* + * Clear the filter. This should be done before reusing it, because + * just removing all items doesn't clear counters that hit the upper + * bound. + */ + void clear(); + + /* + * Add an item to the filter. + */ + void add(const T* aValue); + + /* + * Remove an item from the filter. + */ + void remove(const T* aValue); + + /* + * Check whether the filter might contain an item. This can + * sometimes return true even if the item is not in the filter, + * but will never return false for items that are actually in the + * filter. + */ + bool mightContain(const T* aValue) const; + + /* + * Methods for add/remove/contain when we already have a hash computed + */ + void add(uint32_t aHash); + void remove(uint32_t aHash); + bool mightContain(uint32_t aHash) const; + +private: + static const size_t kArraySize = (1 << KeySize); + static const uint32_t kKeyMask = (1 << KeySize) - 1; + static const uint32_t kKeyShift = 16; + + static uint32_t hash1(uint32_t aHash) + { + return aHash & kKeyMask; + } + static uint32_t hash2(uint32_t aHash) + { + return (aHash >> kKeyShift) & kKeyMask; + } + + uint8_t& firstSlot(uint32_t aHash) + { + return mCounters[hash1(aHash)]; + } + uint8_t& secondSlot(uint32_t aHash) + { + return mCounters[hash2(aHash)]; + } + + const uint8_t& firstSlot(uint32_t aHash) const + { + return mCounters[hash1(aHash)]; + } + const uint8_t& secondSlot(uint32_t aHash) const + { + return mCounters[hash2(aHash)]; + } + + static bool full(const uint8_t& aSlot) { return aSlot == UINT8_MAX; } + + uint8_t mCounters[kArraySize]; +}; + +template +inline void +BloomFilter::clear() +{ + memset(mCounters, 0, kArraySize); +} + +template +inline void +BloomFilter::add(uint32_t aHash) +{ + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { + ++slot1; + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { + ++slot2; + } +} + +template +MOZ_ALWAYS_INLINE void +BloomFilter::add(const T* aValue) +{ + uint32_t hash = aValue->hash(); + return add(hash); +} + +template +inline void +BloomFilter::remove(uint32_t aHash) +{ + // If the slots are full, we don't know whether we bumped them to be + // there when we added or not, so just leave them full. + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { + --slot1; + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { + --slot2; + } +} + +template +MOZ_ALWAYS_INLINE void +BloomFilter::remove(const T* aValue) +{ + uint32_t hash = aValue->hash(); + remove(hash); +} + +template +MOZ_ALWAYS_INLINE bool +BloomFilter::mightContain(uint32_t aHash) const +{ + // Check that all the slots for this hash contain something + return firstSlot(aHash) && secondSlot(aHash); +} + +template +MOZ_ALWAYS_INLINE bool +BloomFilter::mightContain(const T* aValue) const +{ + uint32_t hash = aValue->hash(); + return mightContain(hash); +} + +} // namespace mozilla + +#endif /* mozilla_BloomFilter_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Casting.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Casting.h new file mode 100644 index 0000000000..dc449af6b6 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Casting.h @@ -0,0 +1,221 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Cast operations to supplement the built-in casting operations. */ + +#ifndef mozilla_Casting_h +#define mozilla_Casting_h + +#include "mozilla/Assertions.h" +#include "mozilla/TypeTraits.h" + +#include + +namespace mozilla { + +/** + * Return a value of type |To|, containing the underlying bit pattern of + * |aFrom|. + * + * |To| and |From| must be types of the same size; be careful of cross-platform + * size differences, or this might fail to compile on some but not all + * platforms. + */ +template +inline To +BitwiseCast(const From aFrom) +{ + static_assert(sizeof(From) == sizeof(To), + "To and From must have the same size"); + union + { + From mFrom; + To mTo; + } u; + u.mFrom = aFrom; + return u.mTo; +} + +namespace detail { + +enum ToSignedness { ToIsSigned, ToIsUnsigned }; +enum FromSignedness { FromIsSigned, FromIsUnsigned }; + +template::value ? FromIsSigned : FromIsUnsigned, + ToSignedness = IsSigned::value ? ToIsSigned : ToIsUnsigned> +struct BoundsCheckImpl; + +// Implicit conversions on operands to binary operations make this all a bit +// hard to verify. Attempt to ease the pain below by *only* comparing values +// that are obviously the same type (and will undergo no further conversions), +// even when it's not strictly necessary, for explicitness. + +enum UUComparison { FromIsBigger, FromIsNotBigger }; + +// Unsigned-to-unsigned range check + +template sizeof(To)) + ? FromIsBigger + : FromIsNotBigger> +struct UnsignedUnsignedCheck; + +template +struct UnsignedUnsignedCheck +{ +public: + static bool checkBounds(const From aFrom) + { + return aFrom <= From(To(-1)); + } +}; + +template +struct UnsignedUnsignedCheck +{ +public: + static bool checkBounds(const From aFrom) + { + return true; + } +}; + +template +struct BoundsCheckImpl +{ +public: + static bool checkBounds(const From aFrom) + { + return UnsignedUnsignedCheck::checkBounds(aFrom); + } +}; + +// Signed-to-unsigned range check + +template +struct BoundsCheckImpl +{ +public: + static bool checkBounds(const From aFrom) + { + if (aFrom < 0) { + return false; + } + if (sizeof(To) >= sizeof(From)) { + return true; + } + return aFrom <= From(To(-1)); + } +}; + +// Unsigned-to-signed range check + +enum USComparison { FromIsSmaller, FromIsNotSmaller }; + +template +struct UnsignedSignedCheck; + +template +struct UnsignedSignedCheck +{ +public: + static bool checkBounds(const From aFrom) + { + return true; + } +}; + +template +struct UnsignedSignedCheck +{ +public: + static bool checkBounds(const From aFrom) + { + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + return aFrom <= From(MaxValue); + } +}; + +template +struct BoundsCheckImpl +{ +public: + static bool checkBounds(const From aFrom) + { + return UnsignedSignedCheck::checkBounds(aFrom); + } +}; + +// Signed-to-signed range check + +template +struct BoundsCheckImpl +{ +public: + static bool checkBounds(const From aFrom) + { + if (sizeof(From) <= sizeof(To)) { + return true; + } + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + const To MinValue = -MaxValue - To(1); + return From(MinValue) <= aFrom && + From(aFrom) <= From(MaxValue); + } +}; + +template::value && + IsIntegral::value> +class BoundsChecker; + +template +class BoundsChecker +{ +public: + static bool checkBounds(const From aFrom) { return true; } +}; + +template +class BoundsChecker +{ +public: + static bool checkBounds(const From aFrom) + { + return BoundsCheckImpl::checkBounds(aFrom); + } +}; + +template +inline bool +IsInBounds(const From aFrom) +{ + return BoundsChecker::checkBounds(aFrom); +} + +} // namespace detail + +/** + * Cast a value of integral type |From| to a value of integral type |To|, + * asserting that the cast will be a safe cast per C++ (that is, that |to| is in + * the range of values permitted for the type |From|). + */ +template +inline To +SafeCast(const From aFrom) +{ + MOZ_ASSERT((detail::IsInBounds(aFrom))); + return static_cast(aFrom); +} + +} // namespace mozilla + +#endif /* mozilla_Casting_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Char16.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Char16.h new file mode 100644 index 0000000000..e54eb0d5c8 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Char16.h @@ -0,0 +1,192 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implements a UTF-16 character type. */ + +#ifndef mozilla_Char16_h +#define mozilla_Char16_h + +#ifdef __cplusplus + +/* + * C++11 introduces a char16_t type and support for UTF-16 string and character + * literals. C++11's char16_t is a distinct builtin type. Technically, char16_t + * is a 16-bit code unit of a Unicode code point, not a "character". + */ + +#ifdef _MSC_VER + /* + * C++11 says char16_t is a distinct builtin type, but Windows's yvals.h + * typedefs char16_t as an unsigned short. We would like to alias char16_t + * to Windows's 16-bit wchar_t so we can declare UTF-16 literals as constant + * expressions (and pass char16_t pointers to Windows APIs). We #define + * _CHAR16T here in order to prevent yvals.h from overriding our char16_t + * typedefs, which we set to wchar_t for C++ code. + * + * In addition, #defining _CHAR16T will prevent yvals.h from defining a + * char32_t type, so we have to undo that damage here and provide our own, + * which is identical to the yvals.h type. + */ +# define MOZ_UTF16_HELPER(s) L##s +# define _CHAR16T +typedef wchar_t char16_t; +typedef unsigned int char32_t; +#else + /* C++11 has a builtin char16_t type. */ +# define MOZ_UTF16_HELPER(s) u##s + /** + * This macro is used to distinguish when char16_t would be a distinct + * typedef from wchar_t. + */ +# define MOZ_CHAR16_IS_NOT_WCHAR +# ifdef WIN32 +# define MOZ_USE_CHAR16_WRAPPER +# endif +#endif + +#ifdef MOZ_USE_CHAR16_WRAPPER +# include + /** + * Win32 API extensively uses wchar_t, which is represented by a separated + * builtin type than char16_t per spec. It's not the case for MSVC, but GCC + * follows the spec. We want to mix wchar_t and char16_t on Windows builds. + * This class is supposed to make it easier. It stores char16_t const pointer, + * but provides implicit casts for wchar_t as well. On other platforms, we + * simply use |typedef const char16_t* char16ptr_t|. Here, we want to make + * the class as similar to this typedef, including providing some casts that + * are allowed by the typedef. + */ +class char16ptr_t +{ +private: + const char16_t* mPtr; + static_assert(sizeof(char16_t) == sizeof(wchar_t), + "char16_t and wchar_t sizes differ"); + +public: + char16ptr_t(const char16_t* aPtr) : mPtr(aPtr) {} + char16ptr_t(const wchar_t* aPtr) : + mPtr(reinterpret_cast(aPtr)) + {} + + /* Without this, nullptr assignment would be ambiguous. */ + constexpr char16ptr_t(decltype(nullptr)) : mPtr(nullptr) {} + + operator const char16_t*() const + { + return mPtr; + } + operator const wchar_t*() const + { + return reinterpret_cast(mPtr); + } + operator const void*() const + { + return mPtr; + } + operator bool() const + { + return mPtr != nullptr; + } + operator std::wstring() const + { + return std::wstring(static_cast(*this)); + } + + /* Explicit cast operators to allow things like (char16_t*)str. */ + explicit operator char16_t*() const + { + return const_cast(mPtr); + } + explicit operator wchar_t*() const + { + return const_cast(static_cast(*this)); + } + + /** + * Some Windows API calls accept BYTE* but require that data actually be + * WCHAR*. Supporting this requires explicit operators to support the + * requisite explicit casts. + */ + explicit operator const char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator const unsigned char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator unsigned char*() const + { + return + const_cast(reinterpret_cast(mPtr)); + } + explicit operator void*() const + { + return const_cast(mPtr); + } + + /* Some operators used on pointers. */ + char16_t operator[](size_t aIndex) const + { + return mPtr[aIndex]; + } + bool operator==(const char16ptr_t& aOther) const + { + return mPtr == aOther.mPtr; + } + bool operator==(decltype(nullptr)) const + { + return mPtr == nullptr; + } + bool operator!=(const char16ptr_t& aOther) const + { + return mPtr != aOther.mPtr; + } + bool operator!=(decltype(nullptr)) const + { + return mPtr != nullptr; + } + char16ptr_t operator+(size_t aValue) const + { + return char16ptr_t(mPtr + aValue); + } + ptrdiff_t operator-(const char16ptr_t& aOther) const + { + return mPtr - aOther.mPtr; + } +}; + +inline decltype((char*)0-(char*)0) +operator-(const char16_t* aX, const char16ptr_t aY) +{ + return aX - static_cast(aY); +} + +#else + +typedef const char16_t* char16ptr_t; + +#endif + +/* + * Macro arguments used in concatenation or stringification won't be expanded. + * Therefore, in order for |MOZ_UTF16(FOO)| to work as expected (which is to + * expand |FOO| before doing whatever |MOZ_UTF16| needs to do to it) a helper + * macro, |MOZ_UTF16_HELPER| needs to be inserted in between to allow the macro + * argument to expand. See "3.10.6 Separate Expansion of Macro Arguments" of the + * CPP manual for a more accurate and precise explanation. + */ +#define MOZ_UTF16(s) MOZ_UTF16_HELPER(s) + +static_assert(sizeof(char16_t) == 2, "Is char16_t type 16 bits?"); +static_assert(char16_t(-1) > char16_t(0), "Is char16_t type unsigned?"); +static_assert(sizeof(MOZ_UTF16('A')) == 2, "Is char literal 16 bits?"); +static_assert(sizeof(MOZ_UTF16("")[0]) == 2, "Is string char 16 bits?"); + +#endif + +#endif /* mozilla_Char16_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/CheckedInt.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/CheckedInt.h new file mode 100644 index 0000000000..ad4c5fef41 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/CheckedInt.h @@ -0,0 +1,779 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Provides checked integers, detecting integer overflow and divide-by-0. */ + +#ifndef mozilla_CheckedInt_h +#define mozilla_CheckedInt_h + +#include +#include "mozilla/Assertions.h" +#include "mozilla/IntegerTypeTraits.h" + +namespace mozilla { + +template class CheckedInt; + +namespace detail { + +/* + * Step 1: manually record supported types + * + * What's nontrivial here is that there are different families of integer + * types: basic integer types and stdint types. It is merrily undefined which + * types from one family may be just typedefs for a type from another family. + * + * For example, on GCC 4.6, aside from the basic integer types, the only other + * type that isn't just a typedef for some of them, is int8_t. + */ + +struct UnsupportedType {}; + +template +struct IsSupportedPass2 +{ + static const bool value = false; +}; + +template +struct IsSupported +{ + static const bool value = IsSupportedPass2::value; +}; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +/* + * Step 2: Implement the actual validity checks. + * + * Ideas taken from IntegerLib, code different. + */ + +template +struct TwiceBiggerType +{ + typedef typename detail::StdintTypeForSizeAndSignedness< + sizeof(IntegerType) * 2, + IsSigned::value + >::Type Type; +}; + +template +struct TwiceBiggerType +{ + typedef UnsupportedType Type; +}; + +template +inline bool +HasSignBit(T aX) +{ + // In C++, right bit shifts on negative values is undefined by the standard. + // Notice that signed-to-unsigned conversions are always well-defined in the + // standard, as the value congruent modulo 2**n as expected. By contrast, + // unsigned-to-signed is only well-defined if the value is representable. + return bool(typename MakeUnsigned::Type(aX) >> + PositionOfSignBit::value); +} + +// Bitwise ops may return a larger type, so it's good to use this inline +// helper guaranteeing that the result is really of type T. +template +inline T +BinaryComplement(T aX) +{ + return ~aX; +} + +template::value, + bool IsUSigned = IsSigned::value> +struct DoesRangeContainRange +{ +}; + +template +struct DoesRangeContainRange +{ + static const bool value = sizeof(T) >= sizeof(U); +}; + +template +struct DoesRangeContainRange +{ + static const bool value = sizeof(T) > sizeof(U); +}; + +template +struct DoesRangeContainRange +{ + static const bool value = false; +}; + +template::value, + bool IsUSigned = IsSigned::value, + bool DoesTRangeContainURange = DoesRangeContainRange::value> +struct IsInRangeImpl {}; + +template +struct IsInRangeImpl +{ + static bool run(U) + { + return true; + } +}; + +template +struct IsInRangeImpl +{ + static bool run(U aX) + { + return aX <= MaxValue::value && aX >= MinValue::value; + } +}; + +template +struct IsInRangeImpl +{ + static bool run(U aX) + { + return aX <= MaxValue::value; + } +}; + +template +struct IsInRangeImpl +{ + static bool run(U aX) + { + return sizeof(T) > sizeof(U) || aX <= U(MaxValue::value); + } +}; + +template +struct IsInRangeImpl +{ + static bool run(U aX) + { + return sizeof(T) >= sizeof(U) + ? aX >= 0 + : aX >= 0 && aX <= U(MaxValue::value); + } +}; + +template +inline bool +IsInRange(U aX) +{ + return IsInRangeImpl::run(aX); +} + +template +inline bool +IsAddValid(T aX, T aY) +{ + // Addition is valid if the sign of aX+aY is equal to either that of aX or + // that of aY. Since the value of aX+aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. Beware! + // These bitwise operations can return a larger integer type, if T was a + // small type like int8_t, so we explicitly cast to T. + + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux + uy; + return IsSigned::value + ? HasSignBit(BinaryComplement(T((result ^ aX) & (result ^ aY)))) + : BinaryComplement(aX) >= aY; +} + +template +inline bool +IsSubValid(T aX, T aY) +{ + // Subtraction is valid if either aX and aY have same sign, or aX-aY and aX + // have same sign. Since the value of aX-aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux - uy; + + return IsSigned::value + ? HasSignBit(BinaryComplement(T((result ^ aX) & (aX ^ aY)))) + : aX >= aY; +} + +template::value, + bool TwiceBiggerTypeIsSupported = + IsSupported::Type>::value> +struct IsMulValidImpl {}; + +template +struct IsMulValidImpl +{ + static bool run(T aX, T aY) + { + typedef typename TwiceBiggerType::Type TwiceBiggerType; + TwiceBiggerType product = TwiceBiggerType(aX) * TwiceBiggerType(aY); + return IsInRange(product); + } +}; + +template +struct IsMulValidImpl +{ + static bool run(T aX, T aY) + { + const T max = MaxValue::value; + const T min = MinValue::value; + + if (aX == 0 || aY == 0) { + return true; + } + if (aX > 0) { + return aY > 0 + ? aX <= max / aY + : aY >= min / aX; + } + + // If we reach this point, we know that aX < 0. + return aY > 0 + ? aX >= min / aY + : aY >= max / aX; + } +}; + +template +struct IsMulValidImpl +{ + static bool run(T aX, T aY) + { + return aY == 0 || aX <= MaxValue::value / aY; + } +}; + +template +inline bool +IsMulValid(T aX, T aY) +{ + return IsMulValidImpl::run(aX, aY); +} + +template +inline bool +IsDivValid(T aX, T aY) +{ + // Keep in mind that in the signed case, min/-1 is invalid because + // abs(min)>max. + return aY != 0 && + !(IsSigned::value && aX == MinValue::value && aY == T(-1)); +} + +template::value> +struct IsModValidImpl; + +template +inline bool +IsModValid(T aX, T aY) +{ + return IsModValidImpl::run(aX, aY); +} + +/* + * Mod is pretty simple. + * For now, let's just use the ANSI C definition: + * If aX or aY are negative, the results are implementation defined. + * Consider these invalid. + * Undefined for aY=0. + * The result will never exceed either aX or aY. + * + * Checking that aX>=0 is a warning when T is unsigned. + */ + +template +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + return aY >= 1; + } +}; + +template +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + if (aX < 0) { + return false; + } + return aY >= 1; + } +}; + +template::value> +struct NegateImpl; + +template +struct NegateImpl +{ + static CheckedInt negate(const CheckedInt& aVal) + { + // Handle negation separately for signed/unsigned, for simpler code and to + // avoid an MSVC warning negating an unsigned value. + return CheckedInt(0, aVal.isValid() && aVal.mValue == 0); + } +}; + +template +struct NegateImpl +{ + static CheckedInt negate(const CheckedInt& aVal) + { + // Watch out for the min-value, which (with twos-complement) can't be + // negated as -min-value is then (max-value + 1). + if (!aVal.isValid() || aVal.mValue == MinValue::value) { + return CheckedInt(aVal.mValue, false); + } + return CheckedInt(-aVal.mValue, true); + } +}; + +} // namespace detail + + +/* + * Step 3: Now define the CheckedInt class. + */ + +/** + * @class CheckedInt + * @brief Integer wrapper class checking for integer overflow and other errors + * @param T the integer type to wrap. Can be any type among the following: + * - any basic integer type such as |int| + * - any stdint type such as |int8_t| + * + * This class implements guarded integer arithmetic. Do a computation, check + * that isValid() returns true, you then have a guarantee that no problem, such + * as integer overflow, happened during this computation, and you can call + * value() to get the plain integer value. + * + * The arithmetic operators in this class are guaranteed not to raise a signal + * (e.g. in case of a division by zero). + * + * For example, suppose that you want to implement a function that computes + * (aX+aY)/aZ, that doesn't crash if aZ==0, and that reports on error (divide by + * zero or integer overflow). You could code it as follows: + @code + bool computeXPlusYOverZ(int aX, int aY, int aZ, int* aResult) + { + CheckedInt checkedResult = (CheckedInt(aX) + aY) / aZ; + if (checkedResult.isValid()) { + *aResult = checkedResult.value(); + return true; + } else { + return false; + } + } + @endcode + * + * Implicit conversion from plain integers to checked integers is allowed. The + * plain integer is checked to be in range before being casted to the + * destination type. This means that the following lines all compile, and the + * resulting CheckedInts are correctly detected as valid or invalid: + * @code + // 1 is of type int, is found to be in range for uint8_t, x is valid + CheckedInt x(1); + // -1 is of type int, is found not to be in range for uint8_t, x is invalid + CheckedInt x(-1); + // -1 is of type int, is found to be in range for int8_t, x is valid + CheckedInt x(-1); + // 1000 is of type int16_t, is found not to be in range for int8_t, + // x is invalid + CheckedInt x(int16_t(1000)); + // 3123456789 is of type uint32_t, is found not to be in range for int32_t, + // x is invalid + CheckedInt x(uint32_t(3123456789)); + * @endcode + * Implicit conversion from + * checked integers to plain integers is not allowed. As shown in the + * above example, to get the value of a checked integer as a normal integer, + * call value(). + * + * Arithmetic operations between checked and plain integers is allowed; the + * result type is the type of the checked integer. + * + * Checked integers of different types cannot be used in the same arithmetic + * expression. + * + * There are convenience typedefs for all stdint types, of the following form + * (these are just 2 examples): + @code + typedef CheckedInt CheckedInt32; + typedef CheckedInt CheckedUint16; + @endcode + */ +template +class CheckedInt +{ +protected: + T mValue; + bool mIsValid; + + template + CheckedInt(U aValue, bool aIsValid) : mValue(aValue), mIsValid(aIsValid) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } + + friend struct detail::NegateImpl; + +public: + /** + * Constructs a checked integer with given @a value. The checked integer is + * initialized as valid or invalid depending on whether the @a value + * is in range. + * + * This constructor is not explicit. Instead, the type of its argument is a + * separate template parameter, ensuring that no conversion is performed + * before this constructor is actually called. As explained in the above + * documentation for class CheckedInt, this constructor checks that its + * argument is valid. + */ + template + CheckedInt(U aValue) + : mValue(T(aValue)), + mIsValid(detail::IsInRange(aValue)) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } + + template + friend class CheckedInt; + + template + CheckedInt toChecked() const + { + CheckedInt ret(mValue); + ret.mIsValid = ret.mIsValid && mIsValid; + return ret; + } + + /** Constructs a valid checked integer with initial value 0 */ + CheckedInt() : mValue(0), mIsValid(true) + { + static_assert(detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } + + /** @returns the actual value */ + T value() const + { + MOZ_ASSERT(mIsValid, "Invalid checked integer (division by zero or integer overflow)"); + return mValue; + } + + /** + * @returns true if the checked integer is valid, i.e. is not the result + * of an invalid operation or of an operation involving an invalid checked + * integer + */ + bool isValid() const + { + return mIsValid; + } + + template + friend CheckedInt operator +(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator +=(U aRhs); + + template + friend CheckedInt operator -(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator -=(U aRhs); + + template + friend CheckedInt operator *(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator *=(U aRhs); + + template + friend CheckedInt operator /(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator /=(U aRhs); + + template + friend CheckedInt operator %(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator %=(U aRhs); + + CheckedInt operator -() const + { + return detail::NegateImpl::negate(*this); + } + + /** + * @returns true if the left and right hand sides are valid + * and have the same value. + * + * Note that these semantics are the reason why we don't offer + * a operator!=. Indeed, we'd want to have a!=b be equivalent to !(a==b) + * but that would mean that whenever a or b is invalid, a!=b + * is always true, which would be very confusing. + * + * For similar reasons, operators <, >, <=, >= would be very tricky to + * specify, so we just avoid offering them. + * + * Notice that these == semantics are made more reasonable by these facts: + * 1. a==b implies equality at the raw data level + * (the converse is false, as a==b is never true among invalids) + * 2. This is similar to the behavior of IEEE floats, where a==b + * means that a and b have the same value *and* neither is NaN. + */ + bool operator ==(const CheckedInt& aOther) const + { + return mIsValid && aOther.mIsValid && mValue == aOther.mValue; + } + + /** prefix ++ */ + CheckedInt& operator++() + { + *this += 1; + return *this; + } + + /** postfix ++ */ + CheckedInt operator++(int) + { + CheckedInt tmp = *this; + *this += 1; + return tmp; + } + + /** prefix -- */ + CheckedInt& operator--() + { + *this -= 1; + return *this; + } + + /** postfix -- */ + CheckedInt operator--(int) + { + CheckedInt tmp = *this; + *this -= 1; + return tmp; + } + +private: + /** + * The !=, <, <=, >, >= operators are disabled: + * see the comment on operator==. + */ + template bool operator !=(U aOther) const MOZ_DELETE; + template bool operator < (U aOther) const MOZ_DELETE; + template bool operator <=(U aOther) const MOZ_DELETE; + template bool operator > (U aOther) const MOZ_DELETE; + template bool operator >=(U aOther) const MOZ_DELETE; +}; + +#define MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP) \ + template \ + inline CheckedInt \ + operator OP(const CheckedInt &aLhs, const CheckedInt &aRhs) \ + { \ + if (!detail::Is##NAME##Valid(aLhs.mValue, aRhs.mValue)) { \ + return CheckedInt(0, false); \ + } \ + return CheckedInt(aLhs.mValue OP aRhs.mValue, \ + aLhs.mIsValid && aRhs.mIsValid); \ + } + +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Add, +) +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Sub, -) +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Mul, *) +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Div, /) +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Mod, %) + +#undef MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR + +// Implement castToCheckedInt(x), making sure that +// - it allows x to be either a CheckedInt or any integer type +// that can be casted to T +// - if x is already a CheckedInt, we just return a reference to it, +// instead of copying it (optimization) + +namespace detail { + +template +struct CastToCheckedIntImpl +{ + typedef CheckedInt ReturnType; + static CheckedInt run(U aU) { return aU; } +}; + +template +struct CastToCheckedIntImpl > +{ + typedef const CheckedInt& ReturnType; + static const CheckedInt& run(const CheckedInt& aU) { return aU; } +}; + +} // namespace detail + +template +inline typename detail::CastToCheckedIntImpl::ReturnType +castToCheckedInt(U aU) +{ + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + return detail::CastToCheckedIntImpl::run(aU); +} + +#define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP) \ + template \ + template \ + CheckedInt& CheckedInt::operator COMPOUND_OP(U aRhs) \ + { \ + *this = *this OP castToCheckedInt(aRhs); \ + return *this; \ + } \ + template \ + inline CheckedInt operator OP(const CheckedInt &aLhs, U aRhs) \ + { \ + return aLhs OP castToCheckedInt(aRhs); \ + } \ + template \ + inline CheckedInt operator OP(U aLhs, const CheckedInt &aRhs) \ + { \ + return castToCheckedInt(aLhs) OP aRhs; \ + } + +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(+, +=) +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(*, *=) +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(-, -=) +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(/, /=) +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(%, %=) + +#undef MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS + +template +inline bool +operator ==(const CheckedInt &aLhs, U aRhs) +{ + return aLhs == castToCheckedInt(aRhs); +} + +template +inline bool +operator ==(U aLhs, const CheckedInt &aRhs) +{ + return castToCheckedInt(aLhs) == aRhs; +} + +// Convenience typedefs. +typedef CheckedInt CheckedInt8; +typedef CheckedInt CheckedUint8; +typedef CheckedInt CheckedInt16; +typedef CheckedInt CheckedUint16; +typedef CheckedInt CheckedInt32; +typedef CheckedInt CheckedUint32; +typedef CheckedInt CheckedInt64; +typedef CheckedInt CheckedUint64; + +} // namespace mozilla + +#endif /* mozilla_CheckedInt_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Compiler.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Compiler.h new file mode 100644 index 0000000000..50f127da86 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Compiler.h @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Various compiler checks. */ + +#ifndef mozilla_Compiler_h +#define mozilla_Compiler_h + +#define MOZ_IS_GCC 0 +#define MOS_IS_MSVC 0 + +#if !defined(__clang__) && defined(__GNUC__) + +# undef MOZ_IS_GCC +# define MOZ_IS_GCC 1 + /* + * This macro should simplify gcc version checking. For example, to check + * for gcc 4.5.1 or later, check `#if MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`. + */ +# define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel) \ + ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \ + >= ((major) * 10000 + (minor) * 100 + (patchlevel))) +# if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0) +# error "mfbt (and Gecko) require at least gcc 4.4 to build." +# endif + +#elif defined(_MSC_VER) + +# undef MOZ_IS_MSVC +# define MOZ_IS_MSVC 1 + /* + * This macro should simplify MSVC version checking. For example, to check + * for VC10 or later, check `#ifdef MOZ_MSVC_VERSION_AT_LEAST(10)`. + */ +# define MOZ_MSVC_VERSION_AT_LEAST(version) \ + (version == 10 ? _MSC_VER >= 1600 : \ + (version == 11 ? _MSC_VER >= 1700 : \ + (version == 12 ? _MSC_VER >= 1800 : \ + (version == 13 ? _MSC_VER >= 1900 : \ + 0)))) +# if !MOZ_MSVC_VERSION_AT_LEAST(10) +# error "mfbt (and Gecko) require at least MSVC 2010 RTM to build." +# endif + +#endif + +/* + * The situation with standard libraries is a lot worse than with compilers, + * particularly as clang and gcc could end up using one of three or so standard + * libraries, and they may not be up-to-snuff with newer C++11 versions. To + * detect the library, we're going to include cstddef (which is a small header + * which will be transitively included by everybody else at some point) to grab + * the version macros and deduce macros from there. + */ +#ifdef __cplusplus +# include +# ifdef _STLPORT_MAJOR +# define MOZ_USING_STLPORT 1 +# define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) \ + (_STLPORT_VERSION >= ((major) << 8 | (minor) << 4 | (patch))) +# elif defined(_LIBCPP_VERSION) + /* + * libc++, unfortunately, doesn't appear to have useful versioning macros. + * Hopefully, the recommendations of N3694 with respect to standard libraries + * will get applied instead and we won't need to worry about version numbers + * here. + */ +# define MOZ_USING_LIBCXX 1 +# elif defined(__GLIBCXX__) +# define MOZ_USING_LIBSTDCXX 1 + /* + * libstdc++ is also annoying and doesn't give us useful versioning macros + * for the library. If we're using gcc, then assume that libstdc++ matches + * the compiler version. If we're using clang, we're going to have to fake + * major/minor combinations by looking for newly-defined config macros. + */ +# if MOZ_IS_GCC +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + MOZ_GCC_VERSION_AT_LEAST(major, minor, patch) +# elif defined(_GLIBCXX_THROW_OR_ABORT) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 8)) +# elif defined(_GLIBCXX_NOEXCEPT) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 7)) +# elif defined(_GLIBCXX_USE_DEPRECATED) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 6)) +# elif defined(_GLIBCXX_PSEUDO_VISIBILITY) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 5)) +# elif defined(_GLIBCXX_BEGIN_EXTERN_C) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 4)) +# elif defined(_GLIBCXX_VISIBILITY_ATTR) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 3)) +# elif defined(_GLIBCXX_VISIBILITY) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 2)) +# else +# error "Your version of libstdc++ is unknown to us and is likely too old." +# endif +# endif + + // Flesh out the defines for everyone else +# ifndef MOZ_USING_STLPORT +# define MOZ_USING_STLPORT 0 +# define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) 0 +# endif +# ifndef MOZ_USING_LIBCXX +# define MOZ_USING_LIBCXX 0 +# endif +# ifndef MOZ_USING_LIBSTDCXX +# define MOZ_USING_LIBSTDCXX 0 +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) 0 +# endif +#endif /* __cplusplus */ + +#endif /* mozilla_Compiler_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Compression.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Compression.h new file mode 100644 index 0000000000..a764a1b5d5 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Compression.h @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Various simple compression/decompression functions. */ + +#ifndef mozilla_Compression_h_ +#define mozilla_Compression_h_ + +#include "mozilla/Types.h" +#include "mozilla/Assertions.h" + +namespace mozilla { +namespace Compression { + +/** + * LZ4 is a very fast byte-wise compression algorithm. + * + * Compared to Google's Snappy it is faster to compress and decompress and + * generally produces output of about the same size. + * + * Compared to zlib it compresses at about 10x the speed, decompresses at about + * 4x the speed and produces output of about 1.5x the size. + */ + +class LZ4 +{ +public: + /** + * Compresses |aInputSize| bytes from |aSource| into |aDest|. Destination + * buffer must be already allocated, and must be sized to handle worst cases + * situations (input data not compressible). Worst case size evaluation is + * provided by function maxCompressedSize() + * + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return the number of bytes written in buffer |aDest| + */ + static MFBT_API size_t + compress(const char* aSource, size_t aInputSize, char* aDest); + + /** + * Compress |aInputSize| bytes from |aSource| into an output buffer + * |aDest| of maximum size |aMaxOutputSize|. If it cannot achieve it, + * compression will stop, and result of the function will be zero, + * |aDest| will still be written to, but since the number of input + * bytes consumed is not returned the result is not usable. + * + * This function never writes outside of provided output buffer. + * + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @param aMaxOutputSize is the size of the destination buffer (which must + * be already allocated) + * @return the number of bytes written in buffer |aDest| or 0 if the + * compression fails + */ + static MFBT_API size_t + compressLimitedOutput(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize); + + /** + * If the source stream is malformed, the function will stop decoding + * and return a negative result, indicating the byte position of the + * faulty instruction + * + * This function never writes outside of provided buffers, and never + * modifies input buffer. + * + * Note: destination buffer must be already allocated, and its size must be a + * minimum of |aOutputSize| bytes. + * + * @param aOutputSize is the output size, therefore the original size + * @return the number of bytes read in the source buffer + */ + static MFBT_API bool + decompress(const char* aSource, char* aDest, size_t aOutputSize); + + /** + * If the source stream is malformed, the function will stop decoding + * and return false. + * + * This function never writes beyond aDest + aMaxOutputSize, and is + * therefore protected against malicious data packets. + * + * Note: Destination buffer must be already allocated. This version is + * slightly slower than the decompress without the aMaxOutputSize. + * + * @param aInputSize is the length of the input compressed data + * @param aMaxOutputSize is the size of the destination buffer (which must be + * already allocated) + * @param aOutputSize the actual number of bytes decoded in the destination + * buffer (necessarily <= aMaxOutputSize) + */ + static MFBT_API bool + decompress(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize, size_t* aOutputSize); + + /* + * Provides the maximum size that LZ4 may output in a "worst case" + * scenario (input data not compressible) primarily useful for memory + * allocation of output buffer. + * note : this function is limited by "int" range (2^31-1) + * + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return maximum output size in a "worst case" scenario + */ + static inline size_t maxCompressedSize(size_t aInputSize) + { + size_t max = (aInputSize + (aInputSize / 255) + 16); + MOZ_ASSERT(max > aInputSize); + return max; + } +}; + +} /* namespace Compression */ +} /* namespace mozilla */ + +#endif /* mozilla_Compression_h_ */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Constants.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Constants.h new file mode 100644 index 0000000000..86bbb6b354 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Constants.h @@ -0,0 +1,16 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* mfbt math constants. */ + +#ifndef mozilla_Constants_h +#define mozilla_Constants_h + +#ifndef M_PI +# define M_PI 3.14159265358979323846 +#endif + +#endif /* mozilla_Constants_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/DebugOnly.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/DebugOnly.h new file mode 100644 index 0000000000..5d0197b194 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/DebugOnly.h @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Provides DebugOnly, a type for variables used only in debug builds (i.e. by + * assertions). + */ + +#ifndef mozilla_DebugOnly_h +#define mozilla_DebugOnly_h + +#include "mozilla/Attributes.h" + +namespace mozilla { + +/** + * DebugOnly contains a value of type T, but only in debug builds. In release + * builds, it does not contain a value. This helper is intended to be used with + * MOZ_ASSERT()-style macros, allowing one to write: + * + * DebugOnly check = func(); + * MOZ_ASSERT(check); + * + * more concisely than declaring |check| conditional on #ifdef DEBUG, but also + * without allocating storage space for |check| in release builds. + * + * DebugOnly instances can only be coerced to T in debug builds. In release + * builds they don't have a value, so type coercion is not well defined. + * + * Note that DebugOnly instances still take up one byte of space, plus padding, + * when used as members of structs. + */ +template +class DebugOnly +{ +public: +#ifdef DEBUG + T value; + + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T& aOther) : value(aOther) { } + DebugOnly(const DebugOnly& aOther) : value(aOther.value) { } + DebugOnly& operator=(const T& aRhs) { + value = aRhs; + return *this; + } + + void operator++(int) { value++; } + void operator--(int) { value--; } + + T* operator&() { return &value; } + + operator T&() { return value; } + operator const T&() const { return value; } + + T& operator->() { return value; } + const T& operator->() const { return value; } + +#else + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T&) { } + DebugOnly(const DebugOnly&) { } + DebugOnly& operator=(const T&) { return *this; } + void operator++(int) { } + void operator--(int) { } +#endif + + /* + * DebugOnly must always have a destructor or else it will + * generate "unused variable" warnings, exactly what it's intended + * to avoid! + */ + ~DebugOnly() {} +}; + +} + +#endif /* mozilla_DebugOnly_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Endian.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Endian.h new file mode 100644 index 0000000000..b36991ff88 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Endian.h @@ -0,0 +1,697 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Functions for reading and writing integers in various endiannesses. */ + +/* + * The classes LittleEndian and BigEndian expose static methods for + * reading and writing 16-, 32-, and 64-bit signed and unsigned integers + * in their respective endianness. The naming scheme is: + * + * {Little,Big}Endian::{read,write}{Uint,Int} + * + * For instance, LittleEndian::readInt32 will read a 32-bit signed + * integer from memory in little endian format. Similarly, + * BigEndian::writeUint16 will write a 16-bit unsigned integer to memory + * in big-endian format. + * + * The class NativeEndian exposes methods for conversion of existing + * data to and from the native endianness. These methods are intended + * for cases where data needs to be transferred, serialized, etc. + * swap{To,From}{Little,Big}Endian byteswap a single value if necessary. + * Bulk conversion functions are also provided which optimize the + * no-conversion-needed case: + * + * - copyAndSwap{To,From}{Little,Big}Endian; + * - swap{To,From}{Little,Big}EndianInPlace. + * + * The *From* variants are intended to be used for reading data and the + * *To* variants for writing data. + * + * Methods on NativeEndian work with integer data of any type. + * Floating-point data is not supported. + * + * For clarity in networking code, "Network" may be used as a synonym + * for "Big" in any of the above methods or class names. + * + * As an example, reading a file format header whose fields are stored + * in big-endian format might look like: + * + * class ExampleHeader + * { + * private: + * uint32_t mMagic; + * uint32_t mLength; + * uint32_t mTotalRecords; + * uint64_t mChecksum; + * + * public: + * ExampleHeader(const void* data) + * { + * const uint8_t* ptr = static_cast(data); + * mMagic = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mLength = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mTotalRecords = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mChecksum = BigEndian::readUint64(ptr); + * } + * ... + * }; + */ + +#ifndef mozilla_Endian_h +#define mozilla_Endian_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/DebugOnly.h" +#include "mozilla/TypeTraits.h" + +#include +#include + +#if defined(_MSC_VER) && _MSC_VER >= 1300 +# include +# pragma intrinsic(_byteswap_ushort) +# pragma intrinsic(_byteswap_ulong) +# pragma intrinsic(_byteswap_uint64) +#endif + +#if defined(_WIN64) +# if defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_) +# define MOZ_LITTLE_ENDIAN 1 +# else +# error "CPU type is unknown" +# endif +#elif defined(_WIN32) +# if defined(_M_IX86) +# define MOZ_LITTLE_ENDIAN 1 +# elif defined(_M_ARM) +# define MOZ_LITTLE_ENDIAN 1 +# else +# error "CPU type is unknown" +# endif +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) +# if __LITTLE_ENDIAN__ +# define MOZ_LITTLE_ENDIAN 1 +# elif __BIG_ENDIAN__ +# define MOZ_BIG_ENDIAN 1 +# endif +#elif defined(__GNUC__) && \ + defined(__BYTE_ORDER__) && \ + defined(__ORDER_LITTLE_ENDIAN__) && \ + defined(__ORDER_BIG_ENDIAN__) + /* + * Some versions of GCC provide architecture-independent macros for + * this. Yes, there are more than two values for __BYTE_ORDER__. + */ +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define MOZ_LITTLE_ENDIAN 1 +# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define MOZ_BIG_ENDIAN 1 +# else +# error "Can't handle mixed-endian architectures" +# endif +/* + * We can't include useful headers like or + * here because they're not present on all platforms. Instead we have + * this big conditional that ideally will catch all the interesting + * cases. + */ +#elif defined(__sparc) || defined(__sparc__) || \ + defined(_POWER) || defined(__hppa) || \ + defined(_MIPSEB) || defined(__ARMEB__) || \ + defined(__s390__) || defined(__AARCH64EB__) || \ + (defined(__sh__) && defined(__LITTLE_ENDIAN__)) || \ + (defined(__ia64) && defined(__BIG_ENDIAN__)) +# define MOZ_BIG_ENDIAN 1 +#elif defined(__i386) || defined(__i386__) || \ + defined(__x86_64) || defined(__x86_64__) || \ + defined(_MIPSEL) || defined(__ARMEL__) || \ + defined(__alpha__) || defined(__AARCH64EL__) || \ + (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ + (defined(__ia64) && !defined(__BIG_ENDIAN__)) +# define MOZ_LITTLE_ENDIAN 1 +#endif + +#if MOZ_BIG_ENDIAN +# define MOZ_LITTLE_ENDIAN 0 +#elif MOZ_LITTLE_ENDIAN +# define MOZ_BIG_ENDIAN 0 +#else +# error "Cannot determine endianness" +#endif + +#if defined(__clang__) +# if __has_builtin(__builtin_bswap16) +# define MOZ_HAVE_BUILTIN_BYTESWAP16 __builtin_bswap16 +# endif +#elif defined(__GNUC__) +# if MOZ_GCC_VERSION_AT_LEAST(4, 8, 0) +# define MOZ_HAVE_BUILTIN_BYTESWAP16 __builtin_bswap16 +# endif +#elif defined(_MSC_VER) +# define MOZ_HAVE_BUILTIN_BYTESWAP16 _byteswap_ushort +#endif + +namespace mozilla { + +namespace detail { + +/* + * We need wrappers here because free functions with default template + * arguments and/or partial specialization of function templates are not + * supported by all the compilers we use. + */ +template +struct Swapper; + +template +struct Swapper +{ + static T swap(T aValue) + { +#if defined(MOZ_HAVE_BUILTIN_BYTESWAP16) + return MOZ_HAVE_BUILTIN_BYTESWAP16(aValue); +#else + return T(((aValue & 0x00ff) << 8) | ((aValue & 0xff00) >> 8)); +#endif + } +}; + +template +struct Swapper +{ + static T swap(T aValue) + { +#if defined(__clang__) || defined(__GNUC__) + return T(__builtin_bswap32(aValue)); +#elif defined(_MSC_VER) + return T(_byteswap_ulong(aValue)); +#else + return T(((aValue & 0x000000ffU) << 24) | + ((aValue & 0x0000ff00U) << 8) | + ((aValue & 0x00ff0000U) >> 8) | + ((aValue & 0xff000000U) >> 24)); +#endif + } +}; + +template +struct Swapper +{ + static inline T swap(T aValue) + { +#if defined(__clang__) || defined(__GNUC__) + return T(__builtin_bswap64(aValue)); +#elif defined(_MSC_VER) + return T(_byteswap_uint64(aValue)); +#else + return T(((aValue & 0x00000000000000ffULL) << 56) | + ((aValue & 0x000000000000ff00ULL) << 40) | + ((aValue & 0x0000000000ff0000ULL) << 24) | + ((aValue & 0x00000000ff000000ULL) << 8) | + ((aValue & 0x000000ff00000000ULL) >> 8) | + ((aValue & 0x0000ff0000000000ULL) >> 24) | + ((aValue & 0x00ff000000000000ULL) >> 40) | + ((aValue & 0xff00000000000000ULL) >> 56)); +#endif + } +}; + +enum Endianness { Little, Big }; + +#if MOZ_BIG_ENDIAN +# define MOZ_NATIVE_ENDIANNESS detail::Big +#else +# define MOZ_NATIVE_ENDIANNESS detail::Little +#endif + +class EndianUtils +{ + /** + * Assert that the memory regions [aDest, aDest+aCount) and + * [aSrc, aSrc+aCount] do not overlap. aCount is given in bytes. + */ + static void assertNoOverlap(const void* aDest, const void* aSrc, + size_t aCount) + { + DebugOnly byteDestPtr = static_cast(aDest); + DebugOnly byteSrcPtr = static_cast(aSrc); + MOZ_ASSERT((byteDestPtr <= byteSrcPtr && + byteDestPtr + aCount <= byteSrcPtr) || + (byteSrcPtr <= byteDestPtr && + byteSrcPtr + aCount <= byteDestPtr)); + } + + template + static void assertAligned(T* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % sizeof(T)) == 0, "Unaligned pointer!"); + } + +protected: + /** + * Return |aValue| converted from SourceEndian encoding to DestEndian + * encoding. + */ + template + static inline T maybeSwap(T aValue) + { + if (SourceEndian == DestEndian) { + return aValue; + } + return Swapper::swap(aValue); + } + + /** + * Convert |aCount| elements at |aPtr| from SourceEndian encoding to + * DestEndian encoding. + */ + template + static inline void maybeSwapInPlace(T* aPtr, size_t aCount) + { + assertAligned(aPtr); + + if (SourceEndian == DestEndian) { + return; + } + for (size_t i = 0; i < aCount; i++) { + aPtr[i] = Swapper::swap(aPtr[i]); + } + } + + /** + * Write |aCount| elements to the unaligned address |aDest| in DestEndian + * format, using elements found at |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapTo(void* aDest, const T* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aSrc); + + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; + } + + uint8_t* byteDestPtr = static_cast(aDest); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + u.mVal = maybeSwap(aSrc[i]); + memcpy(byteDestPtr, u.mBuffer, sizeof(T)); + byteDestPtr += sizeof(T); + } + } + + /** + * Write |aCount| elements to |aDest| in DestEndian format, using elements + * found at the unaligned address |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapFrom(T* aDest, const void* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aDest); + + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; + } + + const uint8_t* byteSrcPtr = static_cast(aSrc); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, byteSrcPtr, sizeof(T)); + aDest[i] = maybeSwap(u.mVal); + byteSrcPtr += sizeof(T); + } + } +}; + +template +class Endian : private EndianUtils +{ +protected: + /** Read a uint16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint16_t readUint16(const void* aPtr) + { + return read(aPtr); + } + + /** Read a uint32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint32_t readUint32(const void* aPtr) + { + return read(aPtr); + } + + /** Read a uint64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint64_t readUint64(const void* aPtr) + { + return read(aPtr); + } + + /** Read an int16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int16_t readInt16(const void* aPtr) + { + return read(aPtr); + } + + /** Read an int32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int32_t readInt32(const void* aPtr) + { + return read(aPtr); + } + + /** Read an int64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int64_t readInt64(const void* aPtr) + { + return read(aPtr); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint16(void* aPtr, uint16_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint32(void* aPtr, uint32_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint64(void* aPtr, uint64_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt16(void* aPtr, int16_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt32(void* aPtr, int32_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt64(void* aPtr, int64_t aValue) + { + write(aPtr, aValue); + } + + /* + * Converts a value of type T to little-endian format. + * + * This function is intended for cases where you have data in your + * native-endian format and you need it to appear in little-endian + * format for transmission. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToLittleEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToLittleEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapToLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T to big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToBigEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapToBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + + template + MOZ_WARN_UNUSED_RESULT static T swapToNetworkOrder(T aValue) + { + return swapToBigEndian(aValue); + } + + template + static void + copyAndSwapToNetworkOrder(void* aDest, const T* aSrc, size_t aCount) + { + copyAndSwapToBigEndian(aDest, aSrc, aCount); + } + + template + static void + swapToNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapToBigEndianInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from little-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromLittleEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromLittleEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromBigEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromNetworkOrder(T aValue) + { + return swapFromBigEndian(aValue); + } + + template + static void copyAndSwapFromNetworkOrder(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFromBigEndian(aDest, aSrc, aCount); + } + + template + static void swapFromNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapFromBigEndianInPlace(aPtr, aCount); + } + +private: + /** + * Read a value of type T, encoded in endianness ThisEndian from |aPtr|. + * Return that value encoded in native endianness. + */ + template + static T read(const void* aPtr) + { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, aPtr, sizeof(T)); + return maybeSwap(u.mVal); + } + + /** + * Write a value of type T, in native endianness, to |aPtr|, in ThisEndian + * endianness. + */ + template + static void write(void* aPtr, T aValue) + { + T tmp = maybeSwap(aValue); + memcpy(aPtr, &tmp, sizeof(T)); + } + + Endian() MOZ_DELETE; + Endian(const Endian& aTther) MOZ_DELETE; + void operator=(const Endian& aOther) MOZ_DELETE; +}; + +template +class EndianReadWrite : public Endian +{ +private: + typedef Endian super; + +public: + using super::readUint16; + using super::readUint32; + using super::readUint64; + using super::readInt16; + using super::readInt32; + using super::readInt64; + using super::writeUint16; + using super::writeUint32; + using super::writeUint64; + using super::writeInt16; + using super::writeInt32; + using super::writeInt64; +}; + +} /* namespace detail */ + +class LittleEndian MOZ_FINAL : public detail::EndianReadWrite +{}; + +class BigEndian MOZ_FINAL : public detail::EndianReadWrite +{}; + +typedef BigEndian NetworkEndian; + +class NativeEndian MOZ_FINAL : public detail::Endian +{ +private: + typedef detail::Endian super; + +public: + /* + * These functions are intended for cases where you have data in your + * native-endian format and you need the data to appear in the appropriate + * endianness for transmission, serialization, etc. + */ + using super::swapToLittleEndian; + using super::copyAndSwapToLittleEndian; + using super::swapToLittleEndianInPlace; + using super::swapToBigEndian; + using super::copyAndSwapToBigEndian; + using super::swapToBigEndianInPlace; + using super::swapToNetworkOrder; + using super::copyAndSwapToNetworkOrder; + using super::swapToNetworkOrderInPlace; + + /* + * These functions are intended for cases where you have data in the + * given endianness (e.g. reading from disk or a file-format) and you + * need the data to appear in native-endian format for processing. + */ + using super::swapFromLittleEndian; + using super::copyAndSwapFromLittleEndian; + using super::swapFromLittleEndianInPlace; + using super::swapFromBigEndian; + using super::copyAndSwapFromBigEndian; + using super::swapFromBigEndianInPlace; + using super::swapFromNetworkOrder; + using super::copyAndSwapFromNetworkOrder; + using super::swapFromNetworkOrderInPlace; +}; + +#undef MOZ_NATIVE_ENDIANNESS + +} /* namespace mozilla */ + +#endif /* mozilla_Endian_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/EnumSet.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/EnumSet.h new file mode 100644 index 0000000000..8c78b2b442 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/EnumSet.h @@ -0,0 +1,206 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A set abstraction for enumeration values. */ + +#ifndef mozilla_EnumSet_h +#define mozilla_EnumSet_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" + +#include + +namespace mozilla { + +/** + * EnumSet is a set of values defined by an enumeration. It is implemented + * using a 32 bit mask for each value so it will only work for enums with an int + * representation less than 32. It works both for enum and enum class types. + */ +template +class EnumSet +{ +public: + EnumSet() + : mBitField(0) + { } + + MOZ_IMPLICIT EnumSet(T aEnum) + : mBitField(bitFor(aEnum)) + { } + + EnumSet(T aEnum1, T aEnum2) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3, T aEnum4) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3) | + bitFor(aEnum4)) + { } + + EnumSet(const EnumSet& aEnumSet) + : mBitField(aEnumSet.mBitField) + { } + + /** + * Add an element + */ + void operator+=(T aEnum) + { + mBitField |= bitFor(aEnum); + } + + /** + * Add an element + */ + EnumSet operator+(T aEnum) const + { + EnumSet result(*this); + result += aEnum; + return result; + } + + /** + * Union + */ + void operator+=(const EnumSet aEnumSet) + { + mBitField |= aEnumSet.mBitField; + } + + /** + * Union + */ + EnumSet operator+(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result += aEnumSet; + return result; + } + + /** + * Remove an element + */ + void operator-=(T aEnum) + { + mBitField &= ~(bitFor(aEnum)); + } + + /** + * Remove an element + */ + EnumSet operator-(T aEnum) const + { + EnumSet result(*this); + result -= aEnum; + return result; + } + + /** + * Remove a set of elements + */ + void operator-=(const EnumSet aEnumSet) + { + mBitField &= ~(aEnumSet.mBitField); + } + + /** + * Remove a set of elements + */ + EnumSet operator-(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result -= aEnumSet; + return result; + } + + /** + * Intersection + */ + void operator&=(const EnumSet aEnumSet) + { + mBitField &= aEnumSet.mBitField; + } + + /** + * Intersection + */ + EnumSet operator&(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result &= aEnumSet; + return result; + } + + /** + * Equality + */ + bool operator==(const EnumSet aEnumSet) const + { + return mBitField == aEnumSet.mBitField; + } + + /** + * Test is an element is contained in the set. + */ + bool contains(T aEnum) const + { + return mBitField & bitFor(aEnum); + } + + /** + * Return the number of elements in the set. + */ + uint8_t size() + { + uint8_t count = 0; + for (uint32_t bitField = mBitField; bitField; bitField >>= 1) { + if (bitField & 1) { + count++; + } + } + return count; + } + + bool isEmpty() const + { + return mBitField == 0; + } + + uint32_t serialize() const + { + return mBitField; + } + + void deserialize(uint32_t aValue) + { + mBitField = aValue; + } + +private: + static uint32_t bitFor(T aEnum) + { + uint32_t bitNumber = (uint32_t)aEnum; + MOZ_ASSERT(bitNumber < 32); + return 1U << bitNumber; + } + + uint32_t mBitField; +}; + +} // namespace mozilla + +#endif /* mozilla_EnumSet_h_*/ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/FloatingPoint.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/FloatingPoint.h new file mode 100644 index 0000000000..0ed567832b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/FloatingPoint.h @@ -0,0 +1,413 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Various predicates and operations on IEEE-754 floating point types. */ + +#ifndef mozilla_FloatingPoint_h +#define mozilla_FloatingPoint_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Casting.h" +#include "mozilla/MathAlgorithms.h" +#include "mozilla/Types.h" + +#include + +namespace mozilla { + +/* + * It's reasonable to ask why we have this header at all. Don't isnan, + * copysign, the built-in comparison operators, and the like solve these + * problems? Unfortunately, they don't. We've found that various compilers + * (MSVC, MSVC when compiling with PGO, and GCC on OS X, at least) miscompile + * the standard methods in various situations, so we can't use them. Some of + * these compilers even have problems compiling seemingly reasonable bitwise + * algorithms! But with some care we've found algorithms that seem to not + * trigger those compiler bugs. + * + * For the aforementioned reasons, be very wary of making changes to any of + * these algorithms. If you must make changes, keep a careful eye out for + * compiler bustage, particularly PGO-specific bustage. + */ + +struct FloatTypeTraits +{ + typedef uint32_t Bits; + + static const unsigned kExponentBias = 127; + static const unsigned kExponentShift = 23; + + static const Bits kSignBit = 0x80000000UL; + static const Bits kExponentBits = 0x7F800000UL; + static const Bits kSignificandBits = 0x007FFFFFUL; +}; + +struct DoubleTypeTraits +{ + typedef uint64_t Bits; + + static const unsigned kExponentBias = 1023; + static const unsigned kExponentShift = 52; + + static const Bits kSignBit = 0x8000000000000000ULL; + static const Bits kExponentBits = 0x7ff0000000000000ULL; + static const Bits kSignificandBits = 0x000fffffffffffffULL; +}; + +template struct SelectTrait; +template<> struct SelectTrait : public FloatTypeTraits {}; +template<> struct SelectTrait : public DoubleTypeTraits {}; + +/* + * This struct contains details regarding the encoding of floating-point + * numbers that can be useful for direct bit manipulation. As of now, the + * template parameter has to be float or double. + * + * The nested typedef |Bits| is the unsigned integral type with the same size + * as T: uint32_t for float and uint64_t for double (static assertions + * double-check these assumptions). + * + * kExponentBias is the offset that is subtracted from the exponent when + * computing the value, i.e. one plus the opposite of the mininum possible + * exponent. + * kExponentShift is the shift that one needs to apply to retrieve the + * exponent component of the value. + * + * kSignBit contains a bits mask. Bit-and-ing with this mask will result in + * obtaining the sign bit. + * kExponentBits contains the mask needed for obtaining the exponent bits and + * kSignificandBits contains the mask needed for obtaining the significand + * bits. + * + * Full details of how floating point number formats are encoded are beyond + * the scope of this comment. For more information, see + * http://en.wikipedia.org/wiki/IEEE_floating_point + * http://en.wikipedia.org/wiki/Floating_point#IEEE_754:_floating_point_in_modern_computers + */ +template +struct FloatingPoint : public SelectTrait +{ + typedef SelectTrait Base; + typedef typename Base::Bits Bits; + + static_assert((Base::kSignBit & Base::kExponentBits) == 0, + "sign bit shouldn't overlap exponent bits"); + static_assert((Base::kSignBit & Base::kSignificandBits) == 0, + "sign bit shouldn't overlap significand bits"); + static_assert((Base::kExponentBits & Base::kSignificandBits) == 0, + "exponent bits shouldn't overlap significand bits"); + + static_assert((Base::kSignBit | Base::kExponentBits | Base::kSignificandBits) == + ~Bits(0), + "all bits accounted for"); + + /* + * These implementations assume float/double are 32/64-bit single/double + * format number types compatible with the IEEE-754 standard. C++ don't + * require this to be the case. But we required this in implementations of + * these algorithms that preceded this header, so we shouldn't break anything + * if we keep doing so. + */ + static_assert(sizeof(T) == sizeof(Bits), "Bits must be same size as T"); +}; + +/** Determines whether a double is NaN. */ +template +static MOZ_ALWAYS_INLINE bool +IsNaN(T aValue) +{ + /* + * A float/double is NaN if all exponent bits are 1 and the significand + * contains at least one non-zero bit. + */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) == Traits::kExponentBits && + (bits & Traits::kSignificandBits) != 0; +} + +/** Determines whether a float/double is +Infinity or -Infinity. */ +template +static MOZ_ALWAYS_INLINE bool +IsInfinite(T aValue) +{ + /* Infinities have all exponent bits set to 1 and an all-0 significand. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & ~Traits::kSignBit) == Traits::kExponentBits; +} + +/** Determines whether a float/double is not NaN or infinite. */ +template +static MOZ_ALWAYS_INLINE bool +IsFinite(T aValue) +{ + /* + * NaN and Infinities are the only non-finite floats/doubles, and both have + * all exponent bits set to 1. + */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) != Traits::kExponentBits; +} + +/** + * Determines whether a float/double is negative. It is an error to call this + * method on a float/double which is NaN. + */ +template +static MOZ_ALWAYS_INLINE bool +IsNegative(T aValue) +{ + MOZ_ASSERT(!IsNaN(aValue), "NaN does not have a sign"); + + /* The sign bit is set if the double is negative. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kSignBit) != 0; +} + +/** Determines whether a float/double represents -0. */ +template +static MOZ_ALWAYS_INLINE bool +IsNegativeZero(T aValue) +{ + /* Only the sign bit is set if the value is -0. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return bits == Traits::kSignBit; +} + +/** + * Returns the exponent portion of the float/double. + * + * Zero is not special-cased, so ExponentComponent(0.0) is + * -int_fast16_t(Traits::kExponentBias). + */ +template +static MOZ_ALWAYS_INLINE int_fast16_t +ExponentComponent(T aValue) +{ + /* + * The exponent component of a float/double is an unsigned number, biased + * from its actual value. Subtract the bias to retrieve the actual exponent. + */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return int_fast16_t((bits & Traits::kExponentBits) >> Traits::kExponentShift) - + int_fast16_t(Traits::kExponentBias); +} + +/** Returns +Infinity. */ +template +static MOZ_ALWAYS_INLINE T +PositiveInfinity() +{ + /* + * Positive infinity has all exponent bits set, sign bit set to 0, and no + * significand. + */ + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kExponentBits); +} + +/** Returns -Infinity. */ +template +static MOZ_ALWAYS_INLINE T +NegativeInfinity() +{ + /* + * Negative infinity has all exponent bits set, sign bit set to 1, and no + * significand. + */ + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kSignBit | Traits::kExponentBits); +} + + +/** Constructs a NaN value with the specified sign bit and significand bits. */ +template +static MOZ_ALWAYS_INLINE T +SpecificNaN(int signbit, typename FloatingPoint::Bits significand) +{ + typedef FloatingPoint Traits; + MOZ_ASSERT(signbit == 0 || signbit == 1); + MOZ_ASSERT((significand & ~Traits::kSignificandBits) == 0); + MOZ_ASSERT(significand & Traits::kSignificandBits); + + T t = BitwiseCast((signbit ? Traits::kSignBit : 0) | + Traits::kExponentBits | + significand); + MOZ_ASSERT(IsNaN(t)); + return t; +} + +/** Computes the smallest non-zero positive float/double value. */ +template +static MOZ_ALWAYS_INLINE T +MinNumberValue() +{ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + return BitwiseCast(Bits(1)); +} + +/** + * If aValue is equal to some int32_t value, set *aInt32 to that value and + * return true; otherwise return false. + * + * Note that negative zero is "equal" to zero here. To test whether a value can + * be losslessly converted to int32_t and back, use NumberIsInt32 instead. + */ +template +static MOZ_ALWAYS_INLINE bool +NumberEqualsInt32(T aValue, int32_t* aInt32) +{ + /* + * XXX Casting a floating-point value that doesn't truncate to int32_t, to + * int32_t, induces undefined behavior. We should definitely fix this + * (bug 744965), but as apparently it "works" in practice, it's not a + * pressing concern now. + */ + return aValue == (*aInt32 = int32_t(aValue)); +} + +/** + * If d can be converted to int32_t and back to an identical double value, + * set *aInt32 to that value and return true; otherwise return false. + * + * The difference between this and NumberEqualsInt32 is that this method returns + * false for negative zero. + */ +template +static MOZ_ALWAYS_INLINE bool +NumberIsInt32(T aValue, int32_t* aInt32) +{ + return !IsNegativeZero(aValue) && NumberEqualsInt32(aValue, aInt32); +} + +/** + * Computes a NaN value. Do not use this method if you depend upon a particular + * NaN value being returned. + */ +template +static MOZ_ALWAYS_INLINE T +UnspecifiedNaN() +{ + /* + * If we can use any quiet NaN, we might as well use the all-ones NaN, + * since it's cheap to materialize on common platforms (such as x64, where + * this value can be represented in a 32-bit signed immediate field, allowing + * it to be stored to memory in a single instruction). + */ + typedef FloatingPoint Traits; + return SpecificNaN(1, Traits::kSignificandBits); +} + +/** + * Compare two doubles for equality, *without* equating -0 to +0, and equating + * any NaN value to any other NaN value. (The normal equality operators equate + * -0 with +0, and they equate NaN to no other value.) + */ +template +static inline bool +NumbersAreIdentical(T aValue1, T aValue2) +{ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + if (IsNaN(aValue1)) { + return IsNaN(aValue2); + } + return BitwiseCast(aValue1) == BitwiseCast(aValue2); +} + +namespace detail { + +template +struct FuzzyEqualsEpsilon; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-5 that is exactly representable in a float. + static float value() { return 1.0f / (1 << 17); } +}; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-12 that is exactly representable in a double. + static double value() { return 1.0 / (1LL << 40); } +}; + +} // namespace detail + +/** + * Compare two floating point values for equality, modulo rounding error. That + * is, the two values are considered equal if they are both not NaN and if they + * are less than or equal to aEpsilon apart. The default value of aEpsilon is + * near 1e-5. + * + * For most scenarios you will want to use FuzzyEqualsMultiplicative instead, + * as it is more reasonable over the entire range of floating point numbers. + * This additive version should only be used if you know the range of the + * numbers you are dealing with is bounded and stays around the same order of + * magnitude. + */ +template +static MOZ_ALWAYS_INLINE bool +FuzzyEqualsAdditive(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) +{ + static_assert(IsFloatingPoint::value, "floating point type required"); + return Abs(aValue1 - aValue2) <= aEpsilon; +} + +/** + * Compare two floating point values for equality, allowing for rounding error + * relative to the magnitude of the values. That is, the two values are + * considered equal if they are both not NaN and they are less than or equal to + * some aEpsilon apart, where the aEpsilon is scaled by the smaller of the two + * argument values. + * + * In most cases you will want to use this rather than FuzzyEqualsAdditive, as + * this function effectively masks out differences in the bottom few bits of + * the floating point numbers being compared, regardless of what order of + * magnitude those numbers are at. + */ +template +static MOZ_ALWAYS_INLINE bool +FuzzyEqualsMultiplicative(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) +{ + static_assert(IsFloatingPoint::value, "floating point type required"); + // can't use std::min because of bug 965340 + T smaller = Abs(aValue1) < Abs(aValue2) ? Abs(aValue1) : Abs(aValue2); + return Abs(aValue1 - aValue2) <= aEpsilon * smaller; +} + +/** + * Returns true if the given value can be losslessly represented as an IEEE-754 + * single format number, false otherwise. All NaN values are considered + * representable (notwithstanding that the exact bit pattern of a double format + * NaN value can't be exactly represented in single format). + * + * This function isn't inlined to avoid buggy optimizations by MSVC. + */ +MOZ_WARN_UNUSED_RESULT +extern MFBT_API bool +IsFloat32Representable(double aFloat32); + +} /* namespace mozilla */ + +#endif /* mozilla_FloatingPoint_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/GuardObjects.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/GuardObjects.h new file mode 100644 index 0000000000..2cd950f314 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/GuardObjects.h @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implementation of macros to ensure correct use of RAII Auto* objects. */ + +#ifndef mozilla_GuardObjects_h +#define mozilla_GuardObjects_h + +#include "mozilla/Assertions.h" +#include "mozilla/NullPtr.h" +#include "mozilla/Types.h" + +#ifdef __cplusplus + +#ifdef DEBUG + +namespace mozilla { +namespace detail { + +/* + * The following classes are designed to cause assertions to detect + * inadvertent use of guard objects as temporaries. In other words, + * when we have a guard object whose only purpose is its constructor and + * destructor (and is never otherwise referenced), the intended use + * might be: + * + * AutoRestore savePainting(mIsPainting); + * + * but is is easy to accidentally write: + * + * AutoRestore(mIsPainting); + * + * which compiles just fine, but runs the destructor well before the + * intended time. + * + * They work by adding (#ifdef DEBUG) an additional parameter to the + * guard object's constructor, with a default value, so that users of + * the guard object's API do not need to do anything. The default value + * of this parameter is a temporary object. C++ (ISO/IEC 14882:1998), + * section 12.2 [class.temporary], clauses 4 and 5 seem to assume a + * guarantee that temporaries are destroyed in the reverse of their + * construction order, but I actually can't find a statement that that + * is true in the general case (beyond the two specific cases mentioned + * there). However, it seems to be true. + * + * These classes are intended to be used only via the macros immediately + * below them: + * + * MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER declares (ifdef DEBUG) a member + * variable, and should be put where a declaration of a private + * member variable would be placed. + * MOZ_GUARD_OBJECT_NOTIFIER_PARAM should be placed at the end of the + * parameters to each constructor of the guard object; it declares + * (ifdef DEBUG) an additional parameter. (But use the *_ONLY_PARAM + * variant for constructors that take no other parameters.) + * MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL should likewise be used in + * the implementation of such constructors when they are not inline. + * MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT should be used in + * the implementation of such constructors to pass the parameter to + * a base class that also uses these macros + * MOZ_GUARD_OBJECT_NOTIFIER_INIT is a statement that belongs in each + * constructor. It uses the parameter declared by + * MOZ_GUARD_OBJECT_NOTIFIER_PARAM. + * + * For more details, and examples of using these macros, see + * https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla + */ +class GuardObjectNotifier +{ +private: + bool* mStatementDone; + +public: + GuardObjectNotifier() : mStatementDone(nullptr) { } + + ~GuardObjectNotifier() { *mStatementDone = true; } + + void setStatementDone(bool* aStatementIsDone) + { + mStatementDone = aStatementIsDone; + } +}; + +class GuardObjectNotificationReceiver +{ +private: + bool mStatementDone; + +public: + GuardObjectNotificationReceiver() : mStatementDone(false) { } + + ~GuardObjectNotificationReceiver() { + /* + * Assert that the guard object was not used as a temporary. (Note that + * this assert might also fire if init is not called because the guard + * object's implementation is not using the above macros correctly.) + */ + MOZ_ASSERT(mStatementDone); + } + + void init(const GuardObjectNotifier& aConstNotifier) + { + /* + * aConstNotifier is passed as a const reference so that we can pass a + * temporary, but we really intend it as non-const. + */ + GuardObjectNotifier& notifier = + const_cast(aConstNotifier); + notifier.setStatementDone(&mStatementDone); + } +}; + +} /* namespace detail */ +} /* namespace mozilla */ + +#endif /* DEBUG */ + +#ifdef DEBUG +# define MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER \ + mozilla::detail::GuardObjectNotificationReceiver _mCheckNotUsedAsTemporary; +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM \ + , const mozilla::detail::GuardObjectNotifier& _notifier = \ + mozilla::detail::GuardObjectNotifier() +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM \ + const mozilla::detail::GuardObjectNotifier& _notifier = \ + mozilla::detail::GuardObjectNotifier() +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL \ + , const mozilla::detail::GuardObjectNotifier& _notifier +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL \ + const mozilla::detail::GuardObjectNotifier& _notifier +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT \ + , _notifier +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT \ + _notifier +# define MOZ_GUARD_OBJECT_NOTIFIER_INIT \ + do { _mCheckNotUsedAsTemporary.init(_notifier); } while (0) +#else +# define MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT +# define MOZ_GUARD_OBJECT_NOTIFIER_INIT do { } while (0) +#endif + +#endif /* __cplusplus */ + +#endif /* mozilla_GuardObjects_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/HashFunctions.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/HashFunctions.h new file mode 100644 index 0000000000..8b2c172bd1 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/HashFunctions.h @@ -0,0 +1,367 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Utilities for hashing. */ + +/* + * This file exports functions for hashing data down to a 32-bit value, + * including: + * + * - HashString Hash a char* or uint16_t/wchar_t* of known or unknown + * length. + * + * - HashBytes Hash a byte array of known length. + * + * - HashGeneric Hash one or more values. Currently, we support uint32_t, + * types which can be implicitly cast to uint32_t, data + * pointers, and function pointers. + * + * - AddToHash Add one or more values to the given hash. This supports the + * same list of types as HashGeneric. + * + * + * You can chain these functions together to hash complex objects. For example: + * + * class ComplexObject + * { + * char* mStr; + * uint32_t mUint1, mUint2; + * void (*mCallbackFn)(); + * + * public: + * uint32_t hash() + * { + * uint32_t hash = HashString(mStr); + * hash = AddToHash(hash, mUint1, mUint2); + * return AddToHash(hash, mCallbackFn); + * } + * }; + * + * If you want to hash an nsAString or nsACString, use the HashString functions + * in nsHashKeys.h. + */ + +#ifndef mozilla_HashFunctions_h +#define mozilla_HashFunctions_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Char16.h" +#include "mozilla/Types.h" + +#include + +#ifdef __cplusplus +namespace mozilla { + +/** + * The golden ratio as a 32-bit fixed-point value. + */ +static const uint32_t kGoldenRatioU32 = 0x9E3779B9U; + +inline uint32_t +RotateBitsLeft32(uint32_t aValue, uint8_t aBits) +{ + MOZ_ASSERT(aBits < 32); + return (aValue << aBits) | (aValue >> (32 - aBits)); +} + +namespace detail { + +inline uint32_t +AddU32ToHash(uint32_t aHash, uint32_t aValue) +{ + /* + * This is the meat of all our hash routines. This hash function is not + * particularly sophisticated, but it seems to work well for our mostly + * plain-text inputs. Implementation notes follow. + * + * Our use of the golden ratio here is arbitrary; we could pick almost any + * number which: + * + * * is odd (because otherwise, all our hash values will be even) + * + * * has a reasonably-even mix of 1's and 0's (consider the extreme case + * where we multiply by 0x3 or 0xeffffff -- this will not produce good + * mixing across all bits of the hash). + * + * The rotation length of 5 is also arbitrary, although an odd number is again + * preferable so our hash explores the whole universe of possible rotations. + * + * Finally, we multiply by the golden ratio *after* xor'ing, not before. + * Otherwise, if |aHash| is 0 (as it often is for the beginning of a + * message), the expression + * + * (kGoldenRatioU32 * RotateBitsLeft(aHash, 5)) |xor| aValue + * + * evaluates to |aValue|. + * + * (Number-theoretic aside: Because any odd number |m| is relatively prime to + * our modulus (2^32), the list + * + * [x * m (mod 2^32) for 0 <= x < 2^32] + * + * has no duplicate elements. This means that multiplying by |m| does not + * cause us to skip any possible hash values. + * + * It's also nice if |m| has large-ish order mod 2^32 -- that is, if the + * smallest k such that m^k == 1 (mod 2^32) is large -- so we can safely + * multiply our hash value by |m| a few times without negating the + * multiplicative effect. Our golden ratio constant has order 2^29, which is + * more than enough for our purposes.) + */ + return kGoldenRatioU32 * (RotateBitsLeft32(aHash, 5) ^ aValue); +} + +/** + * AddUintptrToHash takes sizeof(uintptr_t) as a template parameter. + */ +template +inline uint32_t +AddUintptrToHash(uint32_t aHash, uintptr_t aValue); + +template<> +inline uint32_t +AddUintptrToHash<4>(uint32_t aHash, uintptr_t aValue) +{ + return AddU32ToHash(aHash, static_cast(aValue)); +} + +template<> +inline uint32_t +AddUintptrToHash<8>(uint32_t aHash, uintptr_t aValue) +{ + /* + * The static cast to uint64_t below is necessary because this function + * sometimes gets compiled on 32-bit platforms (yes, even though it's a + * template and we never call this particular override in a 32-bit build). If + * we do aValue >> 32 on a 32-bit machine, we're shifting a 32-bit uintptr_t + * right 32 bits, and the compiler throws an error. + */ + uint32_t v1 = static_cast(aValue); + uint32_t v2 = static_cast(static_cast(aValue) >> 32); + return AddU32ToHash(AddU32ToHash(aHash, v1), v2); +} + +} /* namespace detail */ + +/** + * AddToHash takes a hash and some values and returns a new hash based on the + * inputs. + * + * Currently, we support hashing uint32_t's, values which we can implicitly + * convert to uint32_t, data pointers, and function pointers. + */ +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A aA) +{ + /* + * Try to convert |A| to uint32_t implicitly. If this works, great. If not, + * we'll error out. + */ + return detail::AddU32ToHash(aHash, aA); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A* aA) +{ + /* + * You might think this function should just take a void*. But then we'd only + * catch data pointers and couldn't handle function pointers. + */ + + static_assert(sizeof(aA) == sizeof(uintptr_t), "Strange pointer!"); + + return detail::AddUintptrToHash(aHash, uintptr_t(aA)); +} + +template<> +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, uintptr_t aA) +{ + return detail::AddUintptrToHash(aHash, aA); +} + +template +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB) +{ + return AddToHash(AddToHash(aHash, aA), aB); +} + +template +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC) +{ + return AddToHash(AddToHash(aHash, aA, aB), aC); +} + +template +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD) +{ + return AddToHash(AddToHash(aHash, aA, aB, aC), aD); +} + +template +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD, E aE) +{ + return AddToHash(AddToHash(aHash, aA, aB, aC, aD), aE); +} + +/** + * The HashGeneric class of functions let you hash one or more values. + * + * If you want to hash together two values x and y, calling HashGeneric(x, y) is + * much better than calling AddToHash(x, y), because AddToHash(x, y) assumes + * that x has already been hashed. + */ +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA) +{ + return AddToHash(0, aA); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB) +{ + return AddToHash(0, aA, aB); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC) +{ + return AddToHash(0, aA, aB, aC); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD) +{ + return AddToHash(0, aA, aB, aC, aD); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD, E aE) +{ + return AddToHash(0, aA, aB, aC, aD, aE); +} + +namespace detail { + +template +uint32_t +HashUntilZero(const T* aStr) +{ + uint32_t hash = 0; + for (T c; (c = *aStr); aStr++) { + hash = AddToHash(hash, c); + } + return hash; +} + +template +uint32_t +HashKnownLength(const T* aStr, size_t aLength) +{ + uint32_t hash = 0; + for (size_t i = 0; i < aLength; i++) { + hash = AddToHash(hash, aStr[i]); + } + return hash; +} + +} /* namespace detail */ + +/** + * The HashString overloads below do just what you'd expect. + * + * If you have the string's length, you might as well call the overload which + * includes the length. It may be marginally faster. + */ +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr) +{ + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} + +MOZ_WARN_UNUSED_RESULT +inline uint32_t +HashString(const unsigned char* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr) +{ + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} + +#ifdef MOZ_CHAR16_IS_NOT_WCHAR +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr) +{ + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} +#endif + +/* + * On Windows, wchar_t (char16_t) is not the same as uint16_t, even though it's + * the same width! + */ +#ifdef WIN32 +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr) +{ + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} +#endif + +/** + * Hash some number of bytes. + * + * This hash walks word-by-word, rather than byte-by-byte, so you won't get the + * same result out of HashBytes as you would out of HashString. + */ +MOZ_WARN_UNUSED_RESULT extern MFBT_API uint32_t +HashBytes(const void* bytes, size_t aLength); + +} /* namespace mozilla */ +#endif /* __cplusplus */ + +#endif /* mozilla_HashFunctions_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/IntegerPrintfMacros.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/IntegerPrintfMacros.h new file mode 100644 index 0000000000..ff2415a86f --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/IntegerPrintfMacros.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implements the C99 interface, minus the SCN* format macros. */ + +#ifndef mozilla_IntegerPrintfMacros_h_ +#define mozilla_IntegerPrintfMacros_h_ + +/* + * MSVC++ doesn't include , even in versions shipping , so + * we have to reimplement it there. Note: #includes . + * + * Note that this header DOES NOT implement 's scanf macros. MSVC's + * scanf doesn't have sufficient format specifier support to implement them + * (specifically, to implement scanning into an 8-bit location). + * + * http://stackoverflow.com/questions/3036396/scanfd-char-char-as-int-format-string + * + * Moreover, scanf is a footgun: if the input number exceeds the bounds of the + * target type, behavior is undefined (in the compiler sense: that is, this code + * could overwrite your hard drive with zeroes): + * + * uint8_t u; + * sscanf("256", "%" SCNu8, &u); // BAD + * + * This header will sometimes provide SCN* macros, by dint of being implemented + * using . But for these reasons, *never* use them! + */ + +#if defined(MOZ_CUSTOM_INTTYPES_H) +# include MOZ_CUSTOM_INTTYPES_H +#elif defined(_MSC_VER) +# include "mozilla/MSIntTypes.h" +#else +# include +#endif + +/* + * Fix up Android's broken [u]intptr_t inttype macros. Android's PRI*PTR + * macros are defined as "ld", but sizeof(long) is 8 and sizeof(intptr_t) + * is 4 on 32-bit Android. TestTypeTraits.cpp asserts that these new macro + * definitions match the actual type sizes seen at compile time. + */ +#if defined(ANDROID) && !defined(__LP64__) +# undef PRIdPTR /* intptr_t */ +# define PRIdPTR "d" /* intptr_t */ +# undef PRIiPTR /* intptr_t */ +# define PRIiPTR "i" /* intptr_t */ +# undef PRIoPTR /* uintptr_t */ +# define PRIoPTR "o" /* uintptr_t */ +# undef PRIuPTR /* uintptr_t */ +# define PRIuPTR "u" /* uintptr_t */ +# undef PRIxPTR /* uintptr_t */ +# define PRIxPTR "x" /* uintptr_t */ +# undef PRIXPTR /* uintptr_t */ +# define PRIXPTR "X" /* uintptr_t */ +#endif + +#endif /* mozilla_IntegerPrintfMacros_h_ */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Likely.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Likely.h new file mode 100644 index 0000000000..4f21609295 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Likely.h @@ -0,0 +1,23 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * MOZ_LIKELY and MOZ_UNLIKELY macros to hint to the compiler how a + * boolean predicate should be branch-predicted. + */ + +#ifndef mozilla_Likely_h +#define mozilla_Likely_h + +#if defined(__clang__) || defined(__GNUC__) +# define MOZ_LIKELY(x) (__builtin_expect(!!(x), 1)) +# define MOZ_UNLIKELY(x) (__builtin_expect(!!(x), 0)) +#else +# define MOZ_LIKELY(x) (!!(x)) +# define MOZ_UNLIKELY(x) (!!(x)) +#endif + +#endif /* mozilla_Likely_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/LinkedList.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/LinkedList.h new file mode 100644 index 0000000000..693c019f92 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/LinkedList.h @@ -0,0 +1,486 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A type-safe doubly-linked list class. */ + +/* + * The classes LinkedList and LinkedListElement together form a + * convenient, type-safe doubly-linked list implementation. + * + * The class T which will be inserted into the linked list must inherit from + * LinkedListElement. A given object may be in only one linked list at a + * time. + * + * A LinkedListElement automatically removes itself from the list upon + * destruction, and a LinkedList will fatally assert in debug builds if it's + * non-empty when it's destructed. + * + * For example, you might use LinkedList in a simple observer list class as + * follows. + * + * class Observer : public LinkedListElement + * { + * public: + * void observe(char* aTopic) { ... } + * }; + * + * class ObserverContainer + * { + * private: + * LinkedList list; + * + * public: + * void addObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is part of another list. + * list.insertBack(aObserver); + * } + * + * void removeObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is not part of some list. + * aObserver.remove(); + * // Or, will assert if |aObserver| is not part of |list| specifically. + * // aObserver.removeFrom(list); + * } + * + * void notifyObservers(char* aTopic) + * { + * for (Observer* o = list.getFirst(); o != nullptr; o = o->getNext()) { + * o->observe(aTopic); + * } + * } + * }; + * + */ + +#ifndef mozilla_LinkedList_h +#define mozilla_LinkedList_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" + +#ifdef __cplusplus + +namespace mozilla { + +template +class LinkedList; + +template +class LinkedListElement +{ + /* + * It's convenient that we return nullptr when getNext() or getPrevious() + * hits the end of the list, but doing so costs an extra word of storage in + * each linked list node (to keep track of whether |this| is the sentinel + * node) and a branch on this value in getNext/getPrevious. + * + * We could get rid of the extra word of storage by shoving the "is + * sentinel" bit into one of the pointers, although this would, of course, + * have performance implications of its own. + * + * But the goal here isn't to win an award for the fastest or slimmest + * linked list; rather, we want a *convenient* linked list. So we won't + * waste time guessing which micro-optimization strategy is best. + * + * + * Speaking of unnecessary work, it's worth addressing here why we wrote + * mozilla::LinkedList in the first place, instead of using stl::list. + * + * The key difference between mozilla::LinkedList and stl::list is that + * mozilla::LinkedList stores the mPrev/mNext pointers in the object itself, + * while stl::list stores the mPrev/mNext pointers in a list element which + * itself points to the object being stored. + * + * mozilla::LinkedList's approach makes it harder to store an object in more + * than one list. But the upside is that you can call next() / prev() / + * remove() directly on the object. With stl::list, you'd need to store a + * pointer to its iterator in the object in order to accomplish this. Not + * only would this waste space, but you'd have to remember to update that + * pointer every time you added or removed the object from a list. + * + * In-place, constant-time removal is a killer feature of doubly-linked + * lists, and supporting this painlessly was a key design criterion. + */ + +private: + LinkedListElement* mNext; + LinkedListElement* mPrev; + const bool mIsSentinel; + +public: + LinkedListElement() + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(false) + { } + + LinkedListElement(LinkedListElement&& other) + : mIsSentinel(other.mIsSentinel) + { + if (!other.isInList()) { + mNext = this; + mPrev = this; + return; + } + + MOZ_ASSERT(other.mNext->mPrev == &other); + MOZ_ASSERT(other.mPrev->mNext == &other); + + /* + * Initialize |this| with |other|'s mPrev/mNext pointers, and adjust those + * element to point to this one. + */ + mNext = other.mNext; + mPrev = other.mPrev; + + mNext->mPrev = this; + mPrev->mNext = this; + + /* + * Adjust |other| so it doesn't think it's in a list. This makes it + * safely destructable. + */ + other.mNext = &other; + other.mPrev = &other; + } + + ~LinkedListElement() + { + if (!mIsSentinel && isInList()) { + remove(); + } + } + + /* + * Get the next element in the list, or nullptr if this is the last element + * in the list. + */ + T* getNext() { return mNext->asT(); } + const T* getNext() const { return mNext->asT(); } + + /* + * Get the previous element in the list, or nullptr if this is the first + * element in the list. + */ + T* getPrevious() { return mPrev->asT(); } + const T* getPrevious() const { return mPrev->asT(); } + + /* + * Insert aElem after this element in the list. |this| must be part of a + * linked list when you call setNext(); otherwise, this method will assert. + */ + void setNext(T* aElem) + { + MOZ_ASSERT(isInList()); + setNextUnsafe(aElem); + } + + /* + * Insert aElem before this element in the list. |this| must be part of a + * linked list when you call setPrevious(); otherwise, this method will + * assert. + */ + void setPrevious(T* aElem) + { + MOZ_ASSERT(isInList()); + setPreviousUnsafe(aElem); + } + + /* + * Remove this element from the list which contains it. If this element is + * not currently part of a linked list, this method asserts. + */ + void remove() + { + MOZ_ASSERT(isInList()); + + mPrev->mNext = mNext; + mNext->mPrev = mPrev; + mNext = this; + mPrev = this; + } + + /* + * Identical to remove(), but also asserts in debug builds that this element + * is in aList. + */ + void removeFrom(const LinkedList& aList) + { + aList.assertContains(asT()); + remove(); + } + + /* + * Return true if |this| part is of a linked list, and false otherwise. + */ + bool isInList() const + { + MOZ_ASSERT((mNext == this) == (mPrev == this)); + return mNext != this; + } + +private: + friend class LinkedList; + + enum NodeKind { + NODE_KIND_NORMAL, + NODE_KIND_SENTINEL + }; + + explicit LinkedListElement(NodeKind nodeKind) + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(nodeKind == NODE_KIND_SENTINEL) + { } + + /* + * Return |this| cast to T* if we're a normal node, or return nullptr if + * we're a sentinel node. + */ + T* asT() + { + return mIsSentinel ? nullptr : static_cast(this); + } + const T* asT() const + { + return mIsSentinel ? nullptr : static_cast(this); + } + + /* + * Insert aElem after this element, but don't check that this element is in + * the list. This is called by LinkedList::insertFront(). + */ + void setNextUnsafe(T* aElem) + { + LinkedListElement *listElem = static_cast(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this->mNext; + listElem->mPrev = this; + this->mNext->mPrev = listElem; + this->mNext = listElem; + } + + /* + * Insert aElem before this element, but don't check that this element is in + * the list. This is called by LinkedList::insertBack(). + */ + void setPreviousUnsafe(T* aElem) + { + LinkedListElement* listElem = static_cast*>(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this; + listElem->mPrev = this->mPrev; + this->mPrev->mNext = listElem; + this->mPrev = listElem; + } + +private: + LinkedListElement& operator=(const LinkedListElement& aOther) MOZ_DELETE; + LinkedListElement(const LinkedListElement& aOther) MOZ_DELETE; +}; + +template +class LinkedList +{ +private: + LinkedListElement sentinel; + +public: + LinkedList() : sentinel(LinkedListElement::NODE_KIND_SENTINEL) { } + + LinkedList(LinkedList&& aOther) + : sentinel(mozilla::Move(aOther.sentinel)) + { } + + ~LinkedList() { MOZ_ASSERT(isEmpty()); } + + /* + * Add aElem to the front of the list. + */ + void insertFront(T* aElem) + { + /* Bypass setNext()'s this->isInList() assertion. */ + sentinel.setNextUnsafe(aElem); + } + + /* + * Add aElem to the back of the list. + */ + void insertBack(T* aElem) + { + sentinel.setPreviousUnsafe(aElem); + } + + /* + * Get the first element of the list, or nullptr if the list is empty. + */ + T* getFirst() { return sentinel.getNext(); } + const T* getFirst() const { return sentinel.getNext(); } + + /* + * Get the last element of the list, or nullptr if the list is empty. + */ + T* getLast() { return sentinel.getPrevious(); } + const T* getLast() const { return sentinel.getPrevious(); } + + /* + * Get and remove the first element of the list. If the list is empty, + * return nullptr. + */ + T* popFirst() + { + T* ret = sentinel.getNext(); + if (ret) { + static_cast*>(ret)->remove(); + } + return ret; + } + + /* + * Get and remove the last element of the list. If the list is empty, + * return nullptr. + */ + T* popLast() + { + T* ret = sentinel.getPrevious(); + if (ret) { + static_cast*>(ret)->remove(); + } + return ret; + } + + /* + * Return true if the list is empty, or false otherwise. + */ + bool isEmpty() const + { + return !sentinel.isInList(); + } + + /* + * Remove all the elements from the list. + * + * This runs in time linear to the list's length, because we have to mark + * each element as not in the list. + */ + void clear() + { + while (popFirst()) { + continue; + } + } + + /* + * Measures the memory consumption of the list excluding |this|. Note that + * it only measures the list elements themselves. If the list elements + * contain pointers to other memory blocks, those blocks must be measured + * separately during a subsequent iteration over the list. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const + { + size_t n = 0; + for (const T* t = getFirst(); t; t = t->getNext()) { + n += aMallocSizeOf(t); + } + return n; + } + + /* + * Like sizeOfExcludingThis(), but measures |this| as well. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const + { + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); + } + + /* + * In a debug build, make sure that the list is sane (no cycles, consistent + * mNext/mPrev pointers, only one sentinel). Has no effect in release builds. + */ + void debugAssertIsSane() const + { +#ifdef DEBUG + const LinkedListElement* slow; + const LinkedListElement* fast1; + const LinkedListElement* fast2; + + /* + * Check for cycles in the forward singly-linked list using the + * tortoise/hare algorithm. + */ + for (slow = sentinel.mNext, + fast1 = sentinel.mNext->mNext, + fast2 = sentinel.mNext->mNext->mNext; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mNext, fast1 = fast2->mNext, fast2 = fast1->mNext) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); + } + + /* Check for cycles in the backward singly-linked list. */ + for (slow = sentinel.mPrev, + fast1 = sentinel.mPrev->mPrev, + fast2 = sentinel.mPrev->mPrev->mPrev; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mPrev, fast1 = fast2->mPrev, fast2 = fast1->mPrev) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); + } + + /* + * Check that |sentinel| is the only node in the list with + * mIsSentinel == true. + */ + for (const LinkedListElement* elem = sentinel.mNext; + elem != &sentinel; + elem = elem->mNext) { + MOZ_ASSERT(!elem->mIsSentinel); + } + + /* Check that the mNext/mPrev pointers match up. */ + const LinkedListElement* prev = &sentinel; + const LinkedListElement* cur = sentinel.mNext; + do { + MOZ_ASSERT(cur->mPrev == prev); + MOZ_ASSERT(prev->mNext == cur); + + prev = cur; + cur = cur->mNext; + } while (cur != &sentinel); +#endif /* ifdef DEBUG */ + } + +private: + friend class LinkedListElement; + + void assertContains(const T* aValue) const + { +#ifdef DEBUG + for (const T* elem = getFirst(); elem; elem = elem->getNext()) { + if (elem == aValue) { + return; + } + } + MOZ_CRASH("element wasn't found in this list!"); +#endif + } + + LinkedList& operator=(const LinkedList& aOther) MOZ_DELETE; + LinkedList(const LinkedList& aOther) MOZ_DELETE; +}; + +} /* namespace mozilla */ + +#endif /* __cplusplus */ + +#endif /* mozilla_LinkedList_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MSIntTypes.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MSIntTypes.h new file mode 100644 index 0000000000..4ce922fbc5 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MSIntTypes.h @@ -0,0 +1,198 @@ +// ISO C9x compliant inttypes.h for Microsoft Visual Studio +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// +// Copyright (c) 2006 Alexander Chemeris +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. The name of the author may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _MSC_VER // [ +#error "Use this header only with Microsoft Visual C++ compilers!" +#endif // _MSC_VER ] + +#ifndef _MSC_INTTYPES_H_ // [ +#define _MSC_INTTYPES_H_ + +#if _MSC_VER > 1000 +#pragma once +#endif + +#include + +// 7.8 Format conversion of integer types + +typedef struct { + intmax_t quot; + intmax_t rem; +} imaxdiv_t; + +// 7.8.1 Macros for format specifiers + +#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 + +// The fprintf macros for signed integers are: +#define PRId8 "d" +#define PRIi8 "i" +#define PRIdLEAST8 "d" +#define PRIiLEAST8 "i" +#define PRIdFAST8 "d" +#define PRIiFAST8 "i" + +#define PRId16 "hd" +#define PRIi16 "hi" +#define PRIdLEAST16 "hd" +#define PRIiLEAST16 "hi" +#define PRIdFAST16 "hd" +#define PRIiFAST16 "hi" + +#define PRId32 "I32d" +#define PRIi32 "I32i" +#define PRIdLEAST32 "I32d" +#define PRIiLEAST32 "I32i" +#define PRIdFAST32 "I32d" +#define PRIiFAST32 "I32i" + +#define PRId64 "I64d" +#define PRIi64 "I64i" +#define PRIdLEAST64 "I64d" +#define PRIiLEAST64 "I64i" +#define PRIdFAST64 "I64d" +#define PRIiFAST64 "I64i" + +#define PRIdMAX "I64d" +#define PRIiMAX "I64i" + +#define PRIdPTR "Id" +#define PRIiPTR "Ii" + +// The fprintf macros for unsigned integers are: +#define PRIo8 "o" +#define PRIu8 "u" +#define PRIx8 "x" +#define PRIX8 "X" +#define PRIoLEAST8 "o" +#define PRIuLEAST8 "u" +#define PRIxLEAST8 "x" +#define PRIXLEAST8 "X" +#define PRIoFAST8 "o" +#define PRIuFAST8 "u" +#define PRIxFAST8 "x" +#define PRIXFAST8 "X" + +#define PRIo16 "ho" +#define PRIu16 "hu" +#define PRIx16 "hx" +#define PRIX16 "hX" +#define PRIoLEAST16 "ho" +#define PRIuLEAST16 "hu" +#define PRIxLEAST16 "hx" +#define PRIXLEAST16 "hX" +#define PRIoFAST16 "ho" +#define PRIuFAST16 "hu" +#define PRIxFAST16 "hx" +#define PRIXFAST16 "hX" + +#define PRIo32 "I32o" +#define PRIu32 "I32u" +#define PRIx32 "I32x" +#define PRIX32 "I32X" +#define PRIoLEAST32 "I32o" +#define PRIuLEAST32 "I32u" +#define PRIxLEAST32 "I32x" +#define PRIXLEAST32 "I32X" +#define PRIoFAST32 "I32o" +#define PRIuFAST32 "I32u" +#define PRIxFAST32 "I32x" +#define PRIXFAST32 "I32X" + +#define PRIo64 "I64o" +#define PRIu64 "I64u" +#define PRIx64 "I64x" +#define PRIX64 "I64X" +#define PRIoLEAST64 "I64o" +#define PRIuLEAST64 "I64u" +#define PRIxLEAST64 "I64x" +#define PRIXLEAST64 "I64X" +#define PRIoFAST64 "I64o" +#define PRIuFAST64 "I64u" +#define PRIxFAST64 "I64x" +#define PRIXFAST64 "I64X" + +#define PRIoMAX "I64o" +#define PRIuMAX "I64u" +#define PRIxMAX "I64x" +#define PRIXMAX "I64X" + +#define PRIoPTR "Io" +#define PRIuPTR "Iu" +#define PRIxPTR "Ix" +#define PRIXPTR "IX" + +// DO NOT SUPPORT THE scanf MACROS! See the comment at the top of +// IntegerPrintfMacros.h. + +#endif // __STDC_FORMAT_MACROS ] + +// 7.8.2 Functions for greatest-width integer types + +// 7.8.2.1 The imaxabs function +#define imaxabs _abs64 + +// 7.8.2.2 The imaxdiv function + +// This is modified version of div() function from Microsoft's div.c found +// in %MSVC.NET%\crt\src\div.c +#ifdef STATIC_IMAXDIV // [ +static +#else // STATIC_IMAXDIV ][ +_inline +#endif // STATIC_IMAXDIV ] +imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) +{ + imaxdiv_t result; + + result.quot = numer / denom; + result.rem = numer % denom; + + if (numer < 0 && result.rem > 0) { + // did division wrong; must fix up + ++result.quot; + result.rem -= denom; + } + + return result; +} + +// 7.8.2.3 The strtoimax and strtoumax functions +#define strtoimax _strtoi64 +#define strtoumax _strtoui64 + +// 7.8.2.4 The wcstoimax and wcstoumax functions +#define wcstoimax _wcstoi64 +#define wcstoumax _wcstoui64 + + +#endif // _MSC_INTTYPES_H_ ] diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MacroArgs.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MacroArgs.h new file mode 100644 index 0000000000..c8b7338210 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MacroArgs.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements various macros meant to ease the use of variadic macros. + */ + +#ifndef mozilla_MacroArgs_h +#define mozilla_MacroArgs_h + +/* + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) counts the number of variadic + * arguments and prefixes it with |aPrefix|. For example: + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(, foo, 42) expands to 2 + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(A, foo, 42, bar) expands to A3 + * + * You must pass in between 1 and 50 (inclusive) variadic arguments, past + * |aPrefix|. It is not legal to do + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(prefix) + * + * (that is, pass in 0 variadic arguments). To ensure that a compile-time + * error occurs when these constraints are violated, use the + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT macro with the same variaidc arguments + * wherever this macro is used. + * + * Passing (__VA_ARGS__, ) rather than simply calling + * MOZ_MACROARGS_ARG_COUNT_HELPER2(__VA_ARGS__, ) very + * carefully tiptoes around a MSVC bug where it improperly expands __VA_ARGS__ + * as a single token in argument lists. For details, see: + * + * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement + * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 + */ +#define MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) \ + MOZ_MACROARGS_ARG_COUNT_HELPER((__VA_ARGS__, \ + aPrefix##50, aPrefix##49, aPrefix##48, aPrefix##47, aPrefix##46, \ + aPrefix##45, aPrefix##44, aPrefix##43, aPrefix##42, aPrefix##41, \ + aPrefix##40, aPrefix##39, aPrefix##38, aPrefix##37, aPrefix##36, \ + aPrefix##35, aPrefix##34, aPrefix##33, aPrefix##32, aPrefix##31, \ + aPrefix##30, aPrefix##29, aPrefix##28, aPrefix##27, aPrefix##26, \ + aPrefix##25, aPrefix##24, aPrefix##23, aPrefix##22, aPrefix##21, \ + aPrefix##20, aPrefix##19, aPrefix##18, aPrefix##17, aPrefix##16, \ + aPrefix##15, aPrefix##14, aPrefix##13, aPrefix##12, aPrefix##11, \ + aPrefix##10, aPrefix##9, aPrefix##8, aPrefix##7, aPrefix##6, \ + aPrefix##5, aPrefix##4, aPrefix##3, aPrefix##2, aPrefix##1, aPrefix##0)) + +#define MOZ_MACROARGS_ARG_COUNT_HELPER(aArgs) \ + MOZ_MACROARGS_ARG_COUNT_HELPER2 aArgs + +#define MOZ_MACROARGS_ARG_COUNT_HELPER2( \ + a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, \ + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \ + a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \ + a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \ + a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \ + a51, ...) a51 + +/* + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT ensures that a compile-time error occurs + * when the argument count constraints of MOZ_PASTE_PREFIX_AND_ARG_COUNT are + * violated. Use this macro wherever MOZ_PASTE_PREFIX_AND_ARG_COUNT is used + * and pass it the same variadic arguments. + * + * This macro employs a few dirty tricks to function. To detect the zero + * argument case, |(__VA_ARGS__)| is stringified, sizeof-ed, and compared to + * what it should be in the absence of arguments. + * + * Detecting too many arguments is a little trickier. With a valid argument + * count and a prefix of 1, MOZ_PASTE_PREFIX_AND_ARG_COUNT expands to e.g. 14. + * With a prefix of 0.0, it expands to e.g. 0.04. If there are too many + * arguments, it expands to the first argument over the limit. If this + * exceeding argument is a number, the assertion will fail as there is no + * number than can simultaneously be both > 10 and == 0. If the exceeding + * argument is not a number, a compile-time error should still occur due to + * the operations performed on it. + */ +#define MOZ_MACROARGS_STRINGIFY_HELPER(x) #x +#define MOZ_STATIC_ASSERT_VALID_ARG_COUNT(...) \ + static_assert( \ + sizeof(MOZ_MACROARGS_STRINGIFY_HELPER((__VA_ARGS__))) != sizeof("()") && \ + (MOZ_PASTE_PREFIX_AND_ARG_COUNT(1, __VA_ARGS__)) > 10 && \ + (int)(MOZ_PASTE_PREFIX_AND_ARG_COUNT(0.0, __VA_ARGS__)) == 0, \ + "MOZ_STATIC_ASSERT_VALID_ARG_COUNT requires 1 to 50 arguments") /* ; */ + +/* + * MOZ_ARGS_AFTER_N expands to its arguments excluding the first |N| + * arguments. For example: + * + * MOZ_ARGS_AFTER_2(a, b, c, d) expands to: c, d + */ +#define MOZ_ARGS_AFTER_1(a1, ...) __VA_ARGS__ +#define MOZ_ARGS_AFTER_2(a1, a2, ...) __VA_ARGS__ + +/* + * MOZ_ARG_N expands to its |N|th argument. + */ +#define MOZ_ARG_1(a1, ...) a1 +#define MOZ_ARG_2(a1, a2, ...) a2 + +#endif /* mozilla_MacroArgs_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MathAlgorithms.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MathAlgorithms.h new file mode 100644 index 0000000000..9a8aa2f413 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MathAlgorithms.h @@ -0,0 +1,501 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* mfbt maths algorithms. */ + +#ifndef mozilla_MathAlgorithms_h +#define mozilla_MathAlgorithms_h + +#include "mozilla/Assertions.h" +#include "mozilla/TypeTraits.h" + +#include +#include +#include + +namespace mozilla { + +// Greatest Common Divisor +template +MOZ_ALWAYS_INLINE IntegerType +EuclidGCD(IntegerType aA, IntegerType aB) +{ + // Euclid's algorithm; O(N) in the worst case. (There are better + // ways, but we don't need them for the current use of this algo.) + MOZ_ASSERT(aA > IntegerType(0)); + MOZ_ASSERT(aB > IntegerType(0)); + + while (aA != aB) { + if (aA > aB) { + aA = aA - aB; + } else { + aB = aB - aA; + } + } + + return aA; +} + +// Least Common Multiple +template +MOZ_ALWAYS_INLINE IntegerType +EuclidLCM(IntegerType aA, IntegerType aB) +{ + // Divide first to reduce overflow risk. + return (aA / EuclidGCD(aA, aB)) * aB; +} + +namespace detail { + +template +struct AllowDeprecatedAbsFixed : FalseType {}; + +template<> struct AllowDeprecatedAbsFixed : TrueType {}; +template<> struct AllowDeprecatedAbsFixed : TrueType {}; + +template +struct AllowDeprecatedAbs : AllowDeprecatedAbsFixed {}; + +template<> struct AllowDeprecatedAbs : TrueType {}; +template<> struct AllowDeprecatedAbs : TrueType {}; + +} // namespace detail + +// DO NOT USE DeprecatedAbs. It exists only until its callers can be converted +// to Abs below, and it will be removed when all callers have been changed. +template +inline typename mozilla::EnableIf::value, T>::Type +DeprecatedAbs(const T aValue) +{ + // The absolute value of the smallest possible value of a signed-integer type + // won't fit in that type (on twos-complement systems -- and we're blithely + // assuming we're on such systems, for the non- types listed above), + // so assert that the input isn't that value. + // + // This is the case if: the value is non-negative; or if adding one (giving a + // value in the range [-maxvalue, 0]), then negating (giving a value in the + // range [0, maxvalue]), doesn't produce maxvalue (because in twos-complement, + // (minvalue + 1) == -maxvalue). + MOZ_ASSERT(aValue >= 0 || + -(aValue + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1), + "You can't negate the smallest possible negative integer!"); + return aValue >= 0 ? aValue : -aValue; +} + +namespace detail { + +// For now mozilla::Abs only takes intN_T, the signed natural types, and +// float/double/long double. Feel free to add overloads for other standard, +// signed types if you need them. + +template +struct AbsReturnTypeFixed; + +template<> struct AbsReturnTypeFixed { typedef uint8_t Type; }; +template<> struct AbsReturnTypeFixed { typedef uint16_t Type; }; +template<> struct AbsReturnTypeFixed { typedef uint32_t Type; }; +template<> struct AbsReturnTypeFixed { typedef uint64_t Type; }; + +template +struct AbsReturnType : AbsReturnTypeFixed {}; + +template<> struct AbsReturnType : + EnableIf {}; +template<> struct AbsReturnType { typedef unsigned char Type; }; +template<> struct AbsReturnType { typedef unsigned short Type; }; +template<> struct AbsReturnType { typedef unsigned int Type; }; +template<> struct AbsReturnType { typedef unsigned long Type; }; +template<> struct AbsReturnType { typedef unsigned long long Type; }; +template<> struct AbsReturnType { typedef float Type; }; +template<> struct AbsReturnType { typedef double Type; }; +template<> struct AbsReturnType { typedef long double Type; }; + +} // namespace detail + +template +inline typename detail::AbsReturnType::Type +Abs(const T aValue) +{ + typedef typename detail::AbsReturnType::Type ReturnType; + return aValue >= 0 ? ReturnType(aValue) : ~ReturnType(aValue) + 1; +} + +template<> +inline float +Abs(const float aFloat) +{ + return std::fabs(aFloat); +} + +template<> +inline double +Abs(const double aDouble) +{ + return std::fabs(aDouble); +} + +template<> +inline long double +Abs(const long double aLongDouble) +{ + return std::fabs(aLongDouble); +} + +} // namespace mozilla + +#if defined(_WIN32) && (_MSC_VER >= 1300) && \ + (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) || defined(_M_ARM)) +# define MOZ_BITSCAN_WINDOWS + +# include +# pragma intrinsic(_BitScanForward, _BitScanReverse) + +# if defined(_M_AMD64) || defined(_M_X64) +# define MOZ_BITSCAN_WINDOWS64 +# pragma intrinsic(_BitScanForward64, _BitScanReverse64) +# endif + +#endif + +namespace mozilla { + +namespace detail { + +#if defined(MOZ_BITSCAN_WINDOWS) + +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanReverse(&index, static_cast(aValue)); + return uint_fast8_t(31 - index); +} + + +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanForward(&index, static_cast(aValue)); + return uint_fast8_t(index); +} + +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + uint32_t x = aValue - ((aValue >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + return (((x + (x >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; +} +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return uint_fast8_t(CountPopulation32(aValue & 0xffffffff) + + CountPopulation32(aValue >> 32)); +} + +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanReverse64(&index, static_cast(aValue)); + return uint_fast8_t(63 - index); +#else + uint32_t hi = uint32_t(aValue >> 32); + if (hi != 0) { + return CountLeadingZeroes32(hi); + } + return 32u + CountLeadingZeroes32(uint32_t(aValue)); +#endif +} + +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanForward64(&index, static_cast(aValue)); + return uint_fast8_t(index); +#else + uint32_t lo = uint32_t(aValue); + if (lo != 0) { + return CountTrailingZeroes32(lo); + } + return 32u + CountTrailingZeroes32(uint32_t(aValue >> 32)); +#endif +} + +# ifdef MOZ_HAVE_BITSCAN64 +# undef MOZ_HAVE_BITSCAN64 +# endif + +#elif defined(__clang__) || defined(__GNUC__) + +# if defined(__clang__) +# if !__has_builtin(__builtin_ctz) || !__has_builtin(__builtin_clz) +# error "A clang providing __builtin_c[lt]z is required to build" +# endif +# else + // gcc has had __builtin_clz and friends since 3.4: no need to check. +# endif + +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + return __builtin_clz(aValue); +} + +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + return __builtin_ctz(aValue); +} + +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + return __builtin_popcount(aValue); +} + +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return __builtin_popcountll(aValue); +} + +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ + return __builtin_clzll(aValue); +} + +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ + return __builtin_ctzll(aValue); +} + +#else +# error "Implement these!" +inline uint_fast8_t CountLeadingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountLeadingZeroes64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes64(uint64_t aValue) MOZ_DELETE; +#endif + +} // namespace detail + +/** + * Compute the number of high-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * highest- valued bits at the start, return the number of zeroes before the + * first one is observed. + * + * CountLeadingZeroes32(0xF0FF1000) is 0; + * CountLeadingZeroes32(0x7F8F0001) is 1; + * CountLeadingZeroes32(0x3FFF0100) is 2; + * CountLeadingZeroes32(0x1FF50010) is 3; and so on. + */ +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes32(aValue); +} + +/** + * Compute the number of low-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * lowest- valued bits at the start, return the number of zeroes before the + * first one is observed. + * + * CountTrailingZeroes32(0x0100FFFF) is 0; + * CountTrailingZeroes32(0x7000FFFE) is 1; + * CountTrailingZeroes32(0x0080FFFC) is 2; + * CountTrailingZeroes32(0x0080FFF8) is 3; and so on. + */ +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes32(aValue); +} + +/** + * Compute the number of one bits in the number |aValue|, + */ +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + return detail::CountPopulation32(aValue); +} + +/** Analogous to CoutPopulation32, but for 64-bit numbers */ +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return detail::CountPopulation64(aValue); +} + +/** Analogous to CountLeadingZeroes32, but for 64-bit numbers. */ +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes64(aValue); +} + +/** Analogous to CountTrailingZeroes32, but for 64-bit numbers. */ +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes64(aValue); +} + +namespace detail { + +template +class CeilingLog2; + +template +class CeilingLog2 +{ +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0u : 32u - CountLeadingZeroes32(aValue - 1); + } +}; + +template +class CeilingLog2 +{ +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0 : 64 - CountLeadingZeroes64(aValue - 1); + } +}; + +} // namespace detail + +/** + * Compute the log of the least power of 2 greater than or equal to |aValue|. + * + * CeilingLog2(0..1) is 0; + * CeilingLog2(2) is 1; + * CeilingLog2(3..4) is 2; + * CeilingLog2(5..8) is 3; + * CeilingLog2(9..16) is 4; and so on. + */ +template +inline uint_fast8_t +CeilingLog2(const T aValue) +{ + return detail::CeilingLog2::compute(aValue); +} + +/** A CeilingLog2 variant that accepts only size_t. */ +inline uint_fast8_t +CeilingLog2Size(size_t aValue) +{ + return CeilingLog2(aValue); +} + +namespace detail { + +template +class FloorLog2; + +template +class FloorLog2 +{ +public: + static uint_fast8_t compute(const T aValue) + { + return 31u - CountLeadingZeroes32(aValue | 1); + } +}; + +template +class FloorLog2 +{ +public: + static uint_fast8_t compute(const T aValue) + { + return 63u - CountLeadingZeroes64(aValue | 1); + } +}; + +} // namespace detail + +/** + * Compute the log of the greatest power of 2 less than or equal to |aValue|. + * + * FloorLog2(0..1) is 0; + * FloorLog2(2..3) is 1; + * FloorLog2(4..7) is 2; + * FloorLog2(8..15) is 3; and so on. + */ +template +inline uint_fast8_t +FloorLog2(const T aValue) +{ + return detail::FloorLog2::compute(aValue); +} + +/** A FloorLog2 variant that accepts only size_t. */ +inline uint_fast8_t +FloorLog2Size(size_t aValue) +{ + return FloorLog2(aValue); +} + +/* + * Compute the smallest power of 2 greater than or equal to |x|. |x| must not + * be so great that the computed value would overflow |size_t|. + */ +inline size_t +RoundUpPow2(size_t aValue) +{ + MOZ_ASSERT(aValue <= (size_t(1) << (sizeof(size_t) * CHAR_BIT - 1)), + "can't round up -- will overflow!"); + return size_t(1) << CeilingLog2(aValue); +} + +/** + * Rotates the bits of the given value left by the amount of the shift width. + */ +template +inline T +RotateLeft(const T aValue, uint_fast8_t aShift) +{ + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + static_assert(IsUnsigned::value, "Rotates require unsigned values"); + return (aValue << aShift) | (aValue >> (sizeof(T) * CHAR_BIT - aShift)); +} + +/** + * Rotates the bits of the given value right by the amount of the shift width. + */ +template +inline T +RotateRight(const T aValue, uint_fast8_t aShift) +{ + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + static_assert(IsUnsigned::value, "Rotates require unsigned values"); + return (aValue >> aShift) | (aValue << (sizeof(T) * CHAR_BIT - aShift)); +} + +} /* namespace mozilla */ + +#endif /* mozilla_MathAlgorithms_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Maybe.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Maybe.h new file mode 100644 index 0000000000..4ba88f6771 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Maybe.h @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A class for lazily constructing an object without sticking it on the heap. */ + +#ifndef mozilla_Maybe_h +#define mozilla_Maybe_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" + +// For placement new +#include + +namespace mozilla { + +/* + * Small utility for lazily constructing objects without using dynamic storage. + * When a Maybe is constructed, it is |empty()|, i.e., no value of T has + * been constructed and no T destructor will be called when the Maybe is + * destroyed. Upon calling |construct|, a T object will be constructed with the + * given arguments and that object will be destroyed when the owning Maybe + * is destroyed. + * + * N.B. GCC seems to miss some optimizations with Maybe and may generate extra + * branches/loads/stores. Use with caution on hot paths. + */ +template +class Maybe +{ + AlignedStorage2 storage; + bool constructed; + + T& asT() { return *storage.addr(); } + +public: + Maybe() { constructed = false; } + ~Maybe() { if (constructed) { asT().~T(); } } + + bool empty() const { return !constructed; } + + void construct() + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(); + constructed = true; + } + + template + void construct(const T1& aT1) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9, const T10& aT10) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9, aT10); + constructed = true; + } + + T* addr() + { + MOZ_ASSERT(constructed); + return &asT(); + } + + T& ref() + { + MOZ_ASSERT(constructed); + return asT(); + } + + const T& ref() const + { + MOZ_ASSERT(constructed); + return const_cast(this)->asT(); + } + + void destroy() + { + ref().~T(); + constructed = false; + } + + void destroyIfConstructed() + { + if (!empty()) { + destroy(); + } + } + +private: + Maybe(const Maybe& aOther) MOZ_DELETE; + const Maybe& operator=(const Maybe& aOther) MOZ_DELETE; +}; + +} // namespace mozilla + +#endif /* mozilla_Maybe_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MemoryChecking.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MemoryChecking.h new file mode 100644 index 0000000000..0642d758c0 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MemoryChecking.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Provides a common interface to the ASan (AddressSanitizer) and Valgrind + * functions used to mark memory in certain ways. In detail, the following + * three macros are provided: + * + * MOZ_MAKE_MEM_NOACCESS - Mark memory as unsafe to access (e.g. freed) + * MOZ_MAKE_MEM_UNDEFINED - Mark memory as accessible, with content undefined + * MOZ_MAKE_MEM_DEFINED - Mark memory as accessible, with content defined + * + * With Valgrind in use, these directly map to the three respective Valgrind + * macros. With ASan in use, the NOACCESS macro maps to poisoning the memory, + * while the UNDEFINED/DEFINED macros unpoison memory. + * + * With no memory checker available, all macros expand to the empty statement. + */ + +#ifndef mozilla_MemoryChecking_h +#define mozilla_MemoryChecking_h + +#if defined(MOZ_VALGRIND) +#include "valgrind/memcheck.h" +#endif + +#if defined(MOZ_ASAN) || defined(MOZ_VALGRIND) +#define MOZ_HAVE_MEM_CHECKS 1 +#endif + +#if defined(MOZ_ASAN) +#include + +#include "mozilla/Types.h" + +extern "C" { +/* These definitions are usually provided through the + * sanitizer/asan_interface.h header installed by ASan. + */ +void MOZ_EXPORT __asan_poison_memory_region(void const volatile *addr, size_t size); +void MOZ_EXPORT __asan_unpoison_memory_region(void const volatile *addr, size_t size); + +#define MOZ_MAKE_MEM_NOACCESS(addr, size) \ + __asan_poison_memory_region((addr), (size)) + +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) \ + __asan_unpoison_memory_region((addr), (size)) + +#define MOZ_MAKE_MEM_DEFINED(addr, size) \ + __asan_unpoison_memory_region((addr), (size)) +} +#elif defined(MOZ_VALGRIND) +#define MOZ_MAKE_MEM_NOACCESS(addr, size) \ + VALGRIND_MAKE_MEM_NOACCESS((addr), (size)) + +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) \ + VALGRIND_MAKE_MEM_UNDEFINED((addr), (size)) + +#define MOZ_MAKE_MEM_DEFINED(addr, size) \ + VALGRIND_MAKE_MEM_DEFINED((addr), (size)) +#else + +#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while (0) + +#endif + +#endif /* mozilla_MemoryChecking_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MemoryReporting.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MemoryReporting.h new file mode 100644 index 0000000000..d2340ecf09 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/MemoryReporting.h @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Memory reporting infrastructure. */ + +#ifndef mozilla_MemoryReporting_h +#define mozilla_MemoryReporting_h + +#include + +#ifdef __cplusplus + +namespace mozilla { + +/* + * This is for functions that are like malloc_usable_size. Such functions are + * used for measuring the size of data structures. + */ +typedef size_t (*MallocSizeOf)(const void* p); + +} /* namespace mozilla */ + +#endif /* __cplusplus */ + +typedef size_t (*MozMallocSizeOf)(const void* p); + +#endif /* mozilla_MemoryReporting_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Move.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Move.h new file mode 100644 index 0000000000..08ae86fa57 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Move.h @@ -0,0 +1,250 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* C++11-style, but C++98-usable, "move references" implementation. */ + +#ifndef mozilla_Move_h +#define mozilla_Move_h + +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +/* + * "Move" References + * + * Some types can be copied much more efficiently if we know the original's + * value need not be preserved --- that is, if we are doing a "move", not a + * "copy". For example, if we have: + * + * Vector u; + * Vector v(u); + * + * the constructor for v must apply a copy constructor to each element of u --- + * taking time linear in the length of u. However, if we know we will not need u + * any more once v has been initialized, then we could initialize v very + * efficiently simply by stealing u's dynamically allocated buffer and giving it + * to v --- a constant-time operation, regardless of the size of u. + * + * Moves often appear in container implementations. For example, when we append + * to a vector, we may need to resize its buffer. This entails moving each of + * its extant elements from the old, smaller buffer to the new, larger buffer. + * But once the elements have been migrated, we're just going to throw away the + * old buffer; we don't care if they still have their values. So if the vector's + * element type can implement "move" more efficiently than "copy", the vector + * resizing should by all means use a "move" operation. Hash tables should also + * use moves when resizing their internal array as entries are added and + * removed. + * + * The details of the optimization, and whether it's worth applying, vary + * from one type to the next: copying an 'int' is as cheap as moving it, so + * there's no benefit in distinguishing 'int' moves from copies. And while + * some constructor calls for complex types are moves, many really have to + * be copies, and can't be optimized this way. So we need: + * + * 1) a way for a type (like Vector) to announce that it can be moved more + * efficiently than it can be copied, and provide an implementation of that + * move operation; and + * + * 2) a way for a particular invocation of a copy constructor to say that it's + * really a move, not a copy, and that the value of the original isn't + * important afterwards (although it must still be safe to destroy). + * + * If a constructor has a single argument of type 'T&&' (an 'rvalue reference + * to T'), that indicates that it is a 'move constructor'. That's 1). It should + * move, not copy, its argument into the object being constructed. It may leave + * the original in any safely-destructible state. + * + * If a constructor's argument is an rvalue, as in 'C(f(x))' or 'C(x + y)', as + * opposed to an lvalue, as in 'C(x)', then overload resolution will prefer the + * move constructor, if there is one. The 'mozilla::Move' function, defined in + * this file, is an identity function you can use in a constructor invocation to + * make any argument into an rvalue, like this: C(Move(x)). That's 2). (You + * could use any function that works, but 'Move' indicates your intention + * clearly.) + * + * Where we might define a copy constructor for a class C like this: + * + * C(const C& rhs) { ... copy rhs to this ... } + * + * we would declare a move constructor like this: + * + * C(C&& rhs) { .. move rhs to this ... } + * + * And where we might perform a copy like this: + * + * C c2(c1); + * + * we would perform a move like this: + * + * C c2(Move(c1)); + * + * Note that 'T&&' implicitly converts to 'T&'. So you can pass a 'T&&' to an + * ordinary copy constructor for a type that doesn't support a special move + * constructor, and you'll just get a copy. This means that templates can use + * Move whenever they know they won't use the original value any more, even if + * they're not sure whether the type at hand has a specialized move constructor. + * If it doesn't, the 'T&&' will just convert to a 'T&', and the ordinary copy + * constructor will apply. + * + * A class with a move constructor can also provide a move assignment operator. + * A generic definition would run this's destructor, and then apply the move + * constructor to *this's memory. A typical definition: + * + * C& operator=(C&& rhs) { + * MOZ_ASSERT(&rhs != this, "self-moves are prohibited"); + * this->~C(); + * new(this) C(Move(rhs)); + * return *this; + * } + * + * With that in place, one can write move assignments like this: + * + * c2 = Move(c1); + * + * This destroys c2, moves c1's value to c2, and leaves c1 in an undefined but + * destructible state. + * + * As we say, a move must leave the original in a "destructible" state. The + * original's destructor will still be called, so if a move doesn't + * actually steal all its resources, that's fine. We require only that the + * move destination must take on the original's value; and that destructing + * the original must not break the move destination. + * + * (Opinions differ on whether move assignment operators should deal with move + * assignment of an object onto itself. It seems wise to either handle that + * case, or assert that it does not occur.) + * + * Forwarding: + * + * Sometimes we want copy construction or assignment if we're passed an ordinary + * value, but move construction if passed an rvalue reference. For example, if + * our constructor takes two arguments and either could usefully be a move, it + * seems silly to write out all four combinations: + * + * C::C(X& x, Y& y) : x(x), y(y) { } + * C::C(X& x, Y&& y) : x(x), y(Move(y)) { } + * C::C(X&& x, Y& y) : x(Move(x)), y(y) { } + * C::C(X&& x, Y&& y) : x(Move(x)), y(Move(y)) { } + * + * To avoid this, C++11 has tweaks to make it possible to write what you mean. + * The four constructor overloads above can be written as one constructor + * template like so[0]: + * + * template + * C::C(XArg&& x, YArg&& y) : x(Forward(x)), y(Forward(y)) { } + * + * ("'Don't Repeat Yourself'? What's that?") + * + * This takes advantage of two new rules in C++11: + * + * - First, when a function template takes an argument that is an rvalue + * reference to a template argument (like 'XArg&& x' and 'YArg&& y' above), + * then when the argument is applied to an lvalue, the template argument + * resolves to 'T&'; and when it is applied to an rvalue, the template + * argument resolves to 'T&&'. Thus, in a call to C::C like: + * + * X foo(int); + * Y yy; + * + * C(foo(5), yy) + * + * XArg would resolve to 'X&&', and YArg would resolve to 'Y&'. + * + * - Second, Whereas C++ used to forbid references to references, C++11 defines + * 'collapsing rules': 'T& &', 'T&& &', and 'T& &&' (that is, any combination + * involving an lvalue reference) now collapse to simply 'T&'; and 'T&& &&' + * collapses to 'T&&'. + * + * Thus, in the call above, 'XArg&&' is 'X&& &&', collapsing to 'X&&'; and + * 'YArg&&' is 'Y& &&', which collapses to 'Y &'. Because the arguments are + * declared as rvalue references to template arguments, the rvalue-ness + * "shines through" where present. + * + * Then, the 'Forward' function --- you must invoke 'Forward' with its type + * argument --- returns an lvalue reference or an rvalue reference to its + * argument, depending on what T is. In our unified constructor definition, that + * means that we'll invoke either the copy or move constructors for x and y, + * depending on what we gave C's constructor. In our call, we'll move 'foo()' + * into 'x', but copy 'yy' into 'y'. + * + * This header file defines Move and Forward in the mozilla namespace. It's up + * to individual containers to annotate moves as such, by calling Move; and it's + * up to individual types to define move constructors and assignment operators + * when valuable. + * + * (C++11 says that the header file should define 'std::move' and + * 'std::forward', which are just like our 'Move' and 'Forward'; but those + * definitions aren't available in that header on all our platforms, so we + * define them ourselves here.) + * + * 0. This pattern is known as "perfect forwarding". Interestingly, it is not + * actually perfect, and it can't forward all possible argument expressions! + * There are two issues: one that's a C++11 issue, and one that's a legacy + * compiler issue. + * + * The C++11 issue is that you can't form a reference to a bit-field. As a + * workaround, assign the bit-field to a local variable and use that: + * + * // C is as above + * struct S { int x : 1; } s; + * C(s.x, 0); // BAD: s.x is a reference to a bit-field, can't form those + * int tmp = s.x; + * C(tmp, 0); // OK: tmp not a bit-field + * + * The legacy issue is that when we don't have true nullptr and must emulate + * it (gcc 4.4/4.5), forwarding |nullptr| results in an |int| or |long| + * forwarded reference. But such a reference, even if its value is a null + * pointer constant expression, is not itself a null pointer constant + * expression. This causes -Werror=conversion-null errors and pointer-to- + * integer comparison errors. Until we always have true nullptr, users of + * forwarding methods must not pass |nullptr| to them. + */ + +/** + * Identical to std::Move(); this is necessary until our stlport supports + * std::move(). + */ +template +inline typename RemoveReference::Type&& +Move(T&& aX) +{ + return static_cast::Type&&>(aX); +} + +/** + * These two overloads are identical to std::forward(); they are necessary until + * our stlport supports std::forward(). + */ +template +inline T&& +Forward(typename RemoveReference::Type& aX) +{ + return static_cast(aX); +} + +template +inline T&& +Forward(typename RemoveReference::Type&& aX) +{ + static_assert(!IsLvalueReference::value, + "misuse of Forward detected! try the other overload"); + return static_cast(aX); +} + +/** Swap |aX| and |aY| using move-construction if possible. */ +template +inline void +Swap(T& aX, T& aY) +{ + T tmp(Move(aX)); + aX = Move(aY); + aY = Move(tmp); +} + +} // namespace mozilla + +#endif /* mozilla_Move_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/NullPtr.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/NullPtr.h new file mode 100644 index 0000000000..5963613c4b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/NullPtr.h @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements a workaround for compilers which do not support the C++11 nullptr + * constant. + */ + +#ifndef mozilla_NullPtr_h +#define mozilla_NullPtr_h + +#if defined(__clang__) +# if !__has_extension(cxx_nullptr) +# error "clang version natively supporting nullptr is required." +# endif +# define MOZ_HAVE_CXX11_NULLPTR +#elif defined(__GNUC__) +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# include "mozilla/Compiler.h" +# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) +# define MOZ_HAVE_CXX11_NULLPTR +# endif +# endif +#elif defined(_MSC_VER) + // The minimum supported MSVC (10, _MSC_VER 1600) supports nullptr. +# define MOZ_HAVE_CXX11_NULLPTR +#endif + +namespace mozilla { + +/** + * IsNullPointer::value is true iff T is the type of C++11's nullptr. If + * nullptr is emulated, IsNullPointer::value is false for all T. + * + * IsNullPointer is useful to give an argument the true decltype(nullptr) type. + * decltype(nullptr) doesn't work when nullptr is emulated. The simplest + * workaround is to use template overloading and SFINAE to expose an overload + * only if an argument's type is decltype(nullptr). Some examples (that assume + * namespace mozilla has been opened, for simplicity): + * + * // foo(T*), foo(stuff that converts to T*), and foo(decltype(nullptr)) + * // (only invoked if nullptr is true nullptr, otherwise foo(T*) is invoked) + * // but nothing else + * void foo(T*) { } + * template + * void foo(N, + * typename EnableIf::value, int>::Type dummy = 0) + * { } + * + * // foo(T*) *exactly* and foo(decltype(nullptr)), nothing else + * void foo(T*) { } + * template + * void foo(U, + * typename EnableIf::value, int>::Type dummy = 0) + * MOZ_DELETE; + * + * The exact details of how set up the SFINAE bits vary on a case-by-case basis. + * If you need help with this (and unless you've internalized way more sadmaking + * nullptr-emulation knowledge than you should have, you do), feel free to poke + * the person with blame on this comment with questions. :-) + * + * Ideally this would be in TypeTraits.h, but C++11 omitted std::is_null_pointer + * (fixed in C++1y), so in the interests of easing a switch to , + * this trait lives elsewhere. + */ +template +struct IsNullPointer { static const bool value = false; }; + +} // namespace mozilla + +/** + * mozilla::NullptrT is a type that's sort of like decltype(nullptr). But it + * can't be identical, because emulated nullptr doesn't have a distinct type. + * Only with gcc 4.4/4.5, emulated nullptr is __null, and decltype(__null) is + * int or long. But passing __null to an int/long parameter triggers + * -Werror=conversion-null errors with gcc 4.5, or (depending on subsequent use + * inside the overloaded function) can trigger pointer-to-integer comparison + * compiler errors. So fairly often, actually, NullptrT is *not* what you want. + * + * Instead, often you should use template-based overloading in concert with + * SFINAE to add a nullptr overload -- see the comments by IsNullPointer. + * + * So when *should* you use NullptrT? Thus far, the only truly good use seems + * to be as an argument type for operator overloads (because C++ doesn't allow + * operator= to have more than one argument, operator== to have more than two, + * &c.). But even in such cases, it really only works if there are no other + * overloads of the operator that accept a pointer type. If you want both T* + * and nullptr_t overloads, you'll have to wait til we drop gcc 4.4/4.5 support. + * (Currently b2g is the only impediment to this.) + */ +#ifdef MOZ_HAVE_CXX11_NULLPTR +// decltype does the right thing for actual nullptr. +namespace mozilla { +typedef decltype(nullptr) NullptrT; +template<> +struct IsNullPointer { static const bool value = true; }; +} +# undef MOZ_HAVE_CXX11_NULLPTR +#elif MOZ_IS_GCC +# define nullptr __null +// void* sweeps up more than just nullptr, but compilers supporting true +// nullptr are the majority now, so they should detect mistakes. If you're +// feeling paranoid, check/assert that your NullptrT equals nullptr. +namespace mozilla { typedef void* NullptrT; } +#else +# error "No compiler support for nullptr or its emulation." +#endif + +#endif /* mozilla_NullPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/NumericLimits.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/NumericLimits.h new file mode 100644 index 0000000000..730fcb410b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/NumericLimits.h @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Compatibility with std::numeric_limits. */ + +#ifndef mozilla_NumericLimits_h +#define mozilla_NumericLimits_h + +#include "mozilla/Char16.h" + +#include +#include + +namespace mozilla { + +/** + * The NumericLimits class provides a compatibility layer with + * std::numeric_limits for char16_t, otherwise it is exactly the same as + * std::numeric_limits. Code which does not need std::numeric_limits + * should avoid using NumericLimits. + */ +template +class NumericLimits : public std::numeric_limits +{ +}; + +#ifdef MOZ_CHAR16_IS_NOT_WCHAR +template<> +class NumericLimits : public std::numeric_limits +{ + // char16_t and uint16_t numeric limits should be exactly the same. +}; +#endif + +} // namespace mozilla + +#endif /* mozilla_NumericLimits_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Pair.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Pair.h new file mode 100644 index 0000000000..e9e8a76938 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Pair.h @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A class holding a pair of objects that tries to conserve storage space. */ + +#ifndef mozilla_Pair_h +#define mozilla_Pair_h + +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +namespace detail { + +enum StorageType { AsBase, AsMember }; + +// Optimize storage using the Empty Base Optimization -- that empty base classes +// don't take up space -- to optimize size when one or the other class is +// stateless and can be used as a base class. +// +// The extra conditions on storage for B are necessary so that PairHelper won't +// ambiguously inherit from either A or B, such that one or the other base class +// would be inaccessible. +template::value ? detail::AsBase : detail::AsMember, + detail::StorageType = + IsEmpty::value && !IsBaseOf::value && !IsBaseOf::value + ? detail::AsBase + : detail::AsMember> +struct PairHelper; + +template +struct PairHelper +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : mFirstA(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(mSecondB, aOther.mSecondB); + } + +private: + A mFirstA; + B mSecondB; +}; + +template +struct PairHelper : private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : B(Forward(aB)), + mFirstA(Forward(aA)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return *this; } + const B& second() const { return *this; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(static_cast(*this), static_cast(aOther)); + } + +private: + A mFirstA; +}; + +template +struct PairHelper : private A +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return *this; } + const A& first() const { return *this; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(mSecondB, aOther.mSecondB); + } + +private: + B mSecondB; +}; + +template +struct PairHelper : private A, private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + B(Forward(aB)) + {} + + A& first() { return static_cast(*this); } + const A& first() const { return static_cast(*this); } + B& second() { return static_cast(*this); } + const B& second() const { return static_cast(*this); } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(static_cast(*this), static_cast(aOther)); + } +}; + +} // namespace detail + +/** + * Pair is the logical concatenation of an instance of A with an instance B. + * Space is conserved when possible. Neither A nor B may be a final class. + * + * It's typically clearer to have individual A and B member fields. Except if + * you want the space-conserving qualities of Pair, you're probably better off + * not using this! + * + * No guarantees are provided about the memory layout of A and B, the order of + * initialization or destruction of A and B, and so on. (This is approximately + * required to optimize space usage.) The first/second names are merely + * conceptual! + */ +template +struct Pair + : private detail::PairHelper +{ + typedef typename detail::PairHelper Base; + +public: + template + Pair(AArg&& aA, BArg&& aB) + : Base(Forward(aA), Forward(aB)) + {} + + /** The A instance. */ + using Base::first; + /** The B instance. */ + using Base::second; + + /** Swap this pair with another pair. */ + void swap(Pair& aOther) { Base::swap(aOther); } + +private: + Pair(const Pair&) MOZ_DELETE; +}; + +template +void +Swap(Pair& aX, Pair& aY) +{ + aX.swap(aY); +} + +} // namespace mozilla + +#endif /* mozilla_Pair_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/PodOperations.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/PodOperations.h new file mode 100644 index 0000000000..843e1311d3 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/PodOperations.h @@ -0,0 +1,195 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Operations for zeroing POD types, arrays, and so on. + * + * These operations are preferable to memset, memcmp, and the like because they + * don't require remembering to multiply by sizeof(T), array lengths, and so on + * everywhere. + */ + +#ifndef mozilla_PodOperations_h +#define mozilla_PodOperations_h + +#include "mozilla/Array.h" +#include "mozilla/ArrayUtils.h" +#include "mozilla/Attributes.h" + +#include +#include + +namespace mozilla { + +/** Set the contents of |aT| to 0. */ +template +static MOZ_ALWAYS_INLINE void +PodZero(T* aT) +{ + memset(aT, 0, sizeof(T)); +} + +/** Set the contents of |aNElem| elements starting at |aT| to 0. */ +template +static MOZ_ALWAYS_INLINE void +PodZero(T* aT, size_t aNElem) +{ + /* + * This function is often called with 'aNElem' small; we use an inline loop + * instead of calling 'memset' with a non-constant length. The compiler + * should inline the memset call with constant size, though. + */ + for (T* end = aT + aNElem; aT < end; aT++) { + memset(aT, 0, sizeof(T)); + } +} + +/* + * Arrays implicitly convert to pointers to their first element, which is + * dangerous when combined with the above PodZero definitions. Adding an + * overload for arrays is ambiguous, so we need another identifier. The + * ambiguous overload is left to catch mistaken uses of PodZero; if you get a + * compile error involving PodZero and array types, use PodArrayZero instead. + */ +template +static void PodZero(T (&aT)[N]) MOZ_DELETE; +template +static void PodZero(T (&aT)[N], size_t aNElem) MOZ_DELETE; + +/** Set the contents of the array |aT| to zero. */ +template +static MOZ_ALWAYS_INLINE void +PodArrayZero(T (&aT)[N]) +{ + memset(aT, 0, N * sizeof(T)); +} + +template +static MOZ_ALWAYS_INLINE void +PodArrayZero(Array& aArr) +{ + memset(&aArr[0], 0, N * sizeof(T)); +} + +/** + * Assign |*aSrc| to |*aDst|. The locations must not be the same and must not + * overlap. + */ +template +static MOZ_ALWAYS_INLINE void +PodAssign(T* aDst, const T* aSrc) +{ + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= 1); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= 1); + memcpy(reinterpret_cast(aDst), reinterpret_cast(aSrc), + sizeof(T)); +} + +/** + * Copy |aNElem| T elements from |aSrc| to |aDst|. The two memory ranges must + * not overlap! + */ +template +static MOZ_ALWAYS_INLINE void +PodCopy(T* aDst, const T* aSrc, size_t aNElem) +{ + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); + + if (aNElem < 128) { + /* + * Avoid using operator= in this loop, as it may have been + * intentionally deleted by the POD type. + */ + for (const T* srcend = aSrc + aNElem; aSrc < srcend; aSrc++, aDst++) { + PodAssign(aDst, aSrc); + } + } else { + memcpy(aDst, aSrc, aNElem * sizeof(T)); + } +} + +template +static MOZ_ALWAYS_INLINE void +PodCopy(volatile T* aDst, const volatile T* aSrc, size_t aNElem) +{ + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); + + /* + * Volatile |aDst| requires extra work, because it's undefined behavior to + * modify volatile objects using the mem* functions. Just write out the + * loops manually, using operator= rather than memcpy for the same reason, + * and let the compiler optimize to the extent it can. + */ + for (const volatile T* srcend = aSrc + aNElem; + aSrc < srcend; + aSrc++, aDst++) { + *aDst = *aSrc; + } +} + +/* + * Copy the contents of the array |aSrc| into the array |aDst|, both of size N. + * The arrays must not overlap! + */ +template +static MOZ_ALWAYS_INLINE void +PodArrayCopy(T (&aDst)[N], const T (&aSrc)[N]) +{ + PodCopy(aDst, aSrc, N); +} + +/** + * Copy the memory for |aNElem| T elements from |aSrc| to |aDst|. If the two + * memory ranges overlap, then the effect is as if the |aNElem| elements are + * first copied from |aSrc| to a temporary array, and then from the temporary + * array to |aDst|. + */ +template +static MOZ_ALWAYS_INLINE void +PodMove(T* aDst, const T* aSrc, size_t aNElem) +{ + MOZ_ASSERT(aNElem <= SIZE_MAX / sizeof(T), + "trying to move an impossible number of elements"); + memmove(aDst, aSrc, aNElem * sizeof(T)); +} + +/** + * Determine whether the |len| elements at |one| are memory-identical to the + * |len| elements at |two|. + */ +template +static MOZ_ALWAYS_INLINE bool +PodEqual(const T* one, const T* two, size_t len) +{ + if (len < 128) { + const T* p1end = one + len; + const T* p1 = one; + const T* p2 = two; + for (; p1 < p1end; p1++, p2++) { + if (*p1 != *p2) { + return false; + } + } + return true; + } + + return !memcmp(one, two, len * sizeof(T)); +} + +} // namespace mozilla + +#endif /* mozilla_PodOperations_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Poison.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Poison.h new file mode 100644 index 0000000000..75e0f081cd --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Poison.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * A poison value that can be used to fill a memory space with + * an address that leads to a safe crash when dereferenced. + */ + +#ifndef mozilla_Poison_h +#define mozilla_Poison_h + +#include "mozilla/Assertions.h" +#include "mozilla/Types.h" + +#include + +MOZ_BEGIN_EXTERN_C + +extern MFBT_DATA uintptr_t gMozillaPoisonValue; + +/** + * @return the poison value. + */ +inline uintptr_t mozPoisonValue() +{ + return gMozillaPoisonValue; +} + +/** + * Overwrite the memory block of aSize bytes at aPtr with the poison value. + * aPtr MUST be aligned at a sizeof(uintptr_t) boundary. + * Only an even number of sizeof(uintptr_t) bytes are overwritten, the last + * few bytes (if any) is not overwritten. + */ +inline void mozWritePoison(void* aPtr, size_t aSize) +{ + const uintptr_t POISON = mozPoisonValue(); + char* p = (char*)aPtr; + char* limit = p + aSize; + MOZ_ASSERT((uintptr_t)aPtr % sizeof(uintptr_t) == 0, "bad alignment"); + MOZ_ASSERT(aSize >= sizeof(uintptr_t), "poisoning this object has no effect"); + for (; p < limit; p += sizeof(uintptr_t)) { + *((uintptr_t*)p) = POISON; + } +} + +/** + * Initialize the poison value. + * This should only be called once. + */ +extern MFBT_API void mozPoisonValueInit(); + +/* Values annotated by CrashReporter */ +extern MFBT_DATA uintptr_t gMozillaPoisonBase; +extern MFBT_DATA uintptr_t gMozillaPoisonSize; + +MOZ_END_EXTERN_C + +#endif /* mozilla_Poison_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Range.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Range.h new file mode 100644 index 0000000000..814a2821ad --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Range.h @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_Range_h +#define mozilla_Range_h + +#include "mozilla/NullPtr.h" +#include "mozilla/RangedPtr.h" + +#include + +namespace mozilla { + +// Range is a tuple containing a pointer and a length. +template +class Range +{ + const RangedPtr mStart; + const RangedPtr mEnd; + + typedef void (Range::* ConvertibleToBool)(); + void nonNull() {} + +public: + Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} + Range(T* aPtr, size_t aLength) + : mStart(aPtr, aPtr, aPtr + aLength), + mEnd(aPtr + aLength, aPtr, aPtr + aLength) + {} + + RangedPtr start() const { return mStart; } + RangedPtr end() const { return mEnd; } + size_t length() const { return mEnd - mStart; } + + T& operator[](size_t aOffset) const { return mStart[aOffset]; } + + operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } +}; + +} // namespace mozilla + +#endif /* mozilla_Range_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/RangedPtr.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/RangedPtr.h new file mode 100644 index 0000000000..4d94035b90 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/RangedPtr.h @@ -0,0 +1,284 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements a smart pointer asserted to remain within a range specified at + * construction. + */ + +#ifndef mozilla_RangedPtr_h +#define mozilla_RangedPtr_h + +#include "mozilla/ArrayUtils.h" +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" + +#include + +namespace mozilla { + +/* + * RangedPtr is a smart pointer restricted to an address range specified at + * creation. The pointer (and any smart pointers derived from it) must remain + * within the range [start, end] (inclusive of end to facilitate use as + * sentinels). Dereferencing or indexing into the pointer (or pointers derived + * from it) must remain within the range [start, end). All the standard pointer + * operators are defined on it; in debug builds these operations assert that the + * range specified at construction is respected. + * + * In theory passing a smart pointer instance as an argument can be slightly + * slower than passing a T* (due to ABI requirements for passing structs versus + * passing pointers), if the method being called isn't inlined. If you are in + * extremely performance-critical code, you may want to be careful using this + * smart pointer as an argument type. + * + * RangedPtr intentionally does not implicitly convert to T*. Use get() to + * explicitly convert to T*. Keep in mind that the raw pointer of course won't + * implement bounds checking in debug builds. + */ +template +class RangedPtr +{ + T* mPtr; + +#ifdef DEBUG + T* const mRangeStart; + T* const mRangeEnd; +#endif + + typedef void (RangedPtr::* ConvertibleToBool)(); + void nonNull() {} + + void checkSanity() + { + MOZ_ASSERT(mRangeStart <= mPtr); + MOZ_ASSERT(mPtr <= mRangeEnd); + } + + /* Creates a new pointer for |aPtr|, restricted to this pointer's range. */ + RangedPtr create(T* aPtr) const + { +#ifdef DEBUG + return RangedPtr(aPtr, mRangeStart, mRangeEnd); +#else + return RangedPtr(aPtr, nullptr, size_t(0)); +#endif + } + + uintptr_t asUintptr() const { return reinterpret_cast(mPtr); } + +public: + RangedPtr(T* aPtr, T* aStart, T* aEnd) + : mPtr(aPtr) +#ifdef DEBUG + , mRangeStart(aStart), mRangeEnd(aEnd) +#endif + { + MOZ_ASSERT(mRangeStart <= mRangeEnd); + checkSanity(); + } + RangedPtr(T* aPtr, T* aStart, size_t aLength) + : mPtr(aPtr) +#ifdef DEBUG + , mRangeStart(aStart), mRangeEnd(aStart + aLength) +#endif + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aPtr, aPtr, aLength). */ + RangedPtr(T* aPtr, size_t aLength) + : mPtr(aPtr) +#ifdef DEBUG + , mRangeStart(aPtr), mRangeEnd(aPtr + aLength) +#endif + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aArr, aArr, N). */ + template + RangedPtr(T (&aArr)[N]) + : mPtr(aArr) +#ifdef DEBUG + , mRangeStart(aArr), mRangeEnd(aArr + N) +#endif + { + checkSanity(); + } + + T* get() const { return mPtr; } + + operator ConvertibleToBool() const { return mPtr ? &RangedPtr::nonNull : 0; } + + /* + * You can only assign one RangedPtr into another if the two pointers have + * the same valid range: + * + * char arr1[] = "hi"; + * char arr2[] = "bye"; + * RangedPtr p1(arr1, 2); + * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works + * p1 = RangedPtr(arr2, 3); // asserts + */ + RangedPtr& operator=(const RangedPtr& aOther) + { + MOZ_ASSERT(mRangeStart == aOther.mRangeStart); + MOZ_ASSERT(mRangeEnd == aOther.mRangeEnd); + mPtr = aOther.mPtr; + checkSanity(); + return *this; + } + + RangedPtr operator+(size_t aInc) + { + MOZ_ASSERT(aInc <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() + aInc * sizeof(T) >= asUintptr()); + return create(mPtr + aInc); + } + + RangedPtr operator-(size_t aDec) + { + MOZ_ASSERT(aDec <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() - aDec * sizeof(T) <= asUintptr()); + return create(mPtr - aDec); + } + + /* + * You can assign a raw pointer into a RangedPtr if the raw pointer is + * within the range specified at creation. + */ + template + RangedPtr& operator=(U* aPtr) + { + *this = create(aPtr); + return *this; + } + + template + RangedPtr& operator=(const RangedPtr& aPtr) + { + MOZ_ASSERT(mRangeStart <= aPtr.mPtr); + MOZ_ASSERT(aPtr.mPtr <= mRangeEnd); + mPtr = aPtr.mPtr; + checkSanity(); + return *this; + } + + RangedPtr& operator++() + { + return (*this += 1); + } + + RangedPtr operator++(int) + { + RangedPtr rcp = *this; + ++*this; + return rcp; + } + + RangedPtr& operator--() + { + return (*this -= 1); + } + + RangedPtr operator--(int) + { + RangedPtr rcp = *this; + --*this; + return rcp; + } + + RangedPtr& operator+=(size_t aInc) + { + *this = *this + aInc; + return *this; + } + + RangedPtr& operator-=(size_t aDec) + { + *this = *this - aDec; + return *this; + } + + T& operator[](int aIndex) const + { + MOZ_ASSERT(size_t(aIndex > 0 ? aIndex : -aIndex) <= size_t(-1) / sizeof(T)); + return *create(mPtr + aIndex); + } + + T& operator*() const + { + MOZ_ASSERT(mPtr >= mRangeStart); + MOZ_ASSERT(mPtr < mRangeEnd); + return *mPtr; + } + + template + bool operator==(const RangedPtr& aOther) const + { + return mPtr == aOther.mPtr; + } + template + bool operator!=(const RangedPtr& aOther) const + { + return !(*this == aOther); + } + + template + bool operator==(const U* u) const + { + return mPtr == u; + } + template + bool operator!=(const U* u) const + { + return !(*this == u); + } + + template + bool operator<(const RangedPtr& aOther) const + { + return mPtr < aOther.mPtr; + } + template + bool operator<=(const RangedPtr& aOther) const + { + return mPtr <= aOther.mPtr; + } + + template + bool operator>(const RangedPtr& aOther) const + { + return mPtr > aOther.mPtr; + } + template + bool operator>=(const RangedPtr& aOther) const + { + return mPtr >= aOther.mPtr; + } + + size_t operator-(const RangedPtr& aOther) const + { + MOZ_ASSERT(mPtr >= aOther.mPtr); + return PointerRangeSize(aOther.mPtr, mPtr); + } + +private: + RangedPtr() MOZ_DELETE; + T* operator&() MOZ_DELETE; +}; + +} /* namespace mozilla */ + +#endif /* mozilla_RangedPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/ReentrancyGuard.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/ReentrancyGuard.h new file mode 100644 index 0000000000..557c61015e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/ReentrancyGuard.h @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Small helper class for asserting uses of a class are non-reentrant. */ + +#ifndef mozilla_ReentrancyGuard_h +#define mozilla_ReentrancyGuard_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/GuardObjects.h" + +namespace mozilla { + +/* Useful for implementing containers that assert non-reentrancy */ +class ReentrancyGuard +{ + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +#ifdef DEBUG + bool& mEntered; +#endif + +public: + template +#ifdef DEBUG + ReentrancyGuard(T& aObj + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mEntered(aObj.mEntered) +#else + ReentrancyGuard(T& + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) +#endif + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef DEBUG + MOZ_ASSERT(!mEntered); + mEntered = true; +#endif + } + ~ReentrancyGuard() + { +#ifdef DEBUG + mEntered = false; +#endif + } + +private: + ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; + void operator=(const ReentrancyGuard&) MOZ_DELETE; +}; + +} // namespace mozilla + +#endif /* mozilla_ReentrancyGuard_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/RefPtr.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/RefPtr.h new file mode 100644 index 0000000000..4901067b4c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/RefPtr.h @@ -0,0 +1,552 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Helpers for defining and using refcounted objects. */ + +#ifndef mozilla_RefPtr_h +#define mozilla_RefPtr_h + +#include "mozilla/Assertions.h" +#include "mozilla/Atomics.h" +#include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" +#include "mozilla/RefCountType.h" +#include "mozilla/TypeTraits.h" +#if defined(MOZILLA_INTERNAL_API) +#include "nsXPCOM.h" +#endif + +#if defined(MOZILLA_INTERNAL_API) && \ + (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) +#define MOZ_REFCOUNTED_LEAK_CHECKING +#endif + +namespace mozilla { + +template class RefCounted; +template class RefPtr; +template class TemporaryRef; +template class OutParamRef; +template OutParamRef byRef(RefPtr&); + +/** + * RefCounted is a sort of a "mixin" for a class T. RefCounted + * manages, well, refcounting for T, and because RefCounted is + * parameterized on T, RefCounted can call T's destructor directly. + * This means T doesn't need to have a virtual dtor and so doesn't + * need a vtable. + * + * RefCounted is created with refcount == 0. Newly-allocated + * RefCounted must immediately be assigned to a RefPtr to make the + * refcount > 0. It's an error to allocate and free a bare + * RefCounted, i.e. outside of the RefPtr machinery. Attempts to + * do so will abort DEBUG builds. + * + * Live RefCounted have refcount > 0. The lifetime (refcounts) of + * live RefCounted are controlled by RefPtr and + * RefPtr. Upon a transition from refcounted==1 + * to 0, the RefCounted "dies" and is destroyed. The "destroyed" + * state is represented in DEBUG builds by refcount==0xffffdead. This + * state distinguishes use-before-ref (refcount==0) from + * use-after-destroy (refcount==0xffffdead). + * + * Note that when deriving from RefCounted or AtomicRefCounted, you + * should add MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public + * section of your class, where ClassName is the name of your class. + */ +namespace detail { +#ifdef DEBUG +const MozRefCountType DEAD = 0xffffdead; +#endif + +// When building code that gets compiled into Gecko, try to use the +// trace-refcount leak logging facilities. +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +class RefCountLogger +{ +public: + static void logAddRef(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName, uint32_t aInstanceSize) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogAddRef(const_cast(aPointer), aRefCount, aTypeName, + aInstanceSize); + } + + static void logRelease(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogRelease(const_cast(aPointer), aRefCount, aTypeName); + } +}; +#endif + +// This is used WeakPtr.h as well as this file. +enum RefCountAtomicity +{ + AtomicRefCount, + NonAtomicRefCount +}; + +template +class RefCounted +{ + friend class RefPtr; + +protected: + RefCounted() : mRefCnt(0) {} + ~RefCounted() { MOZ_ASSERT(mRefCnt == detail::DEAD); } + +public: + // Compatibility with nsRefPtr. + void AddRef() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) >= 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + ++mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + uint32_t size = static_cast(this)->typeSize(); + const void* ptr = static_cast(this); + MozRefCountType cnt = ++mRefCnt; + detail::RefCountLogger::logAddRef(ptr, cnt, type, size); +#endif + } + + void Release() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) > 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + MozRefCountType cnt = --mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + const void* ptr = static_cast(this); + MozRefCountType cnt = --mRefCnt; + // Note: it's not safe to touch |this| after decrementing the refcount, + // except for below. + detail::RefCountLogger::logRelease(ptr, cnt, type); +#endif + if (0 == cnt) { + // Because we have atomically decremented the refcount above, only + // one thread can get a 0 count here, so as long as we can assume that + // everything else in the system is accessing this object through + // RefPtrs, it's safe to access |this| here. +#ifdef DEBUG + mRefCnt = detail::DEAD; +#endif + delete static_cast(this); + } + } + + // Compatibility with wtf::RefPtr. + void ref() { AddRef(); } + void deref() { Release(); } + MozRefCountType refCount() const { return mRefCnt; } + bool hasOneRef() const + { + MOZ_ASSERT(mRefCnt > 0); + return mRefCnt == 1; + } + +private: + mutable typename Conditional, + MozRefCountType>::Type mRefCnt; +}; + +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) \ + virtual const char* typeName() const { return #T; } \ + virtual size_t typeSize() const { return sizeof(*this); } +#else +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) +#endif + +// Note that this macro is expanded unconditionally because it declares only +// two small inline functions which will hopefully get eliminated by the linker +// in non-leak-checking builds. +#define MOZ_DECLARE_REFCOUNTED_TYPENAME(T) \ + const char* typeName() const { return #T; } \ + size_t typeSize() const { return sizeof(*this); } + +} // namespace detail + +template +class RefCounted : public detail::RefCounted +{ +public: + ~RefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from RefCounted"); + } +}; + +namespace external { + +/** + * AtomicRefCounted is like RefCounted, with an atomically updated + * reference counter. + * + * NOTE: Please do not use this class, use NS_INLINE_DECL_THREADSAFE_REFCOUNTING + * instead. + */ +template +class AtomicRefCounted : + public mozilla::detail::RefCounted +{ +public: + ~AtomicRefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from AtomicRefCounted"); + } +}; + +} // namespace external + +/** + * RefPtr points to a refcounted thing that has AddRef and Release + * methods to increase/decrease the refcount, respectively. After a + * RefPtr is assigned a T*, the T* can be used through the RefPtr + * as if it were a T*. + * + * A RefPtr can forget its underlying T*, which results in the T* + * being wrapped in a temporary object until the T* is either + * re-adopted from or released by the temporary. + */ +template +class RefPtr +{ + // To allow them to use unref() + friend class TemporaryRef; + friend class OutParamRef; + + struct DontRef {}; + +public: + RefPtr() : mPtr(0) {} + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.mPtr)) {} + MOZ_IMPLICIT RefPtr(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + MOZ_IMPLICIT RefPtr(T* aVal) : mPtr(ref(aVal)) {} + + template + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.get())) {} + + ~RefPtr() { unref(mPtr); } + + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.mPtr)); + return *this; + } + RefPtr& operator=(const TemporaryRef& aOther) + { + assign(aOther.drop()); + return *this; + } + RefPtr& operator=(T* aVal) + { + assign(ref(aVal)); + return *this; + } + + template + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.get())); + return *this; + } + + TemporaryRef forget() + { + T* tmp = mPtr; + mPtr = nullptr; + return TemporaryRef(tmp, DontRef()); + } + + T* get() const { return mPtr; } + operator T*() const { return mPtr; } + T* operator->() const { return mPtr; } + T& operator*() const { return *mPtr; } + template + operator TemporaryRef() { return TemporaryRef(mPtr); } + +private: + void assign(T* aVal) + { + unref(mPtr); + mPtr = aVal; + } + + T* mPtr; + + static MOZ_ALWAYS_INLINE T* ref(T* aVal) + { + if (aVal) { + aVal->AddRef(); + } + return aVal; + } + + static MOZ_ALWAYS_INLINE void unref(T* aVal) + { + if (aVal) { + aVal->Release(); + } + } +}; + +/** + * TemporaryRef represents an object that holds a temporary + * reference to a T. TemporaryRef objects can't be manually ref'd or + * unref'd (being temporaries, not lvalues), so can only relinquish + * references to other objects, or unref on destruction. + */ +template +class TemporaryRef +{ + // To allow it to construct TemporaryRef from a bare T* + friend class RefPtr; + + typedef typename RefPtr::DontRef DontRef; + +public: + MOZ_IMPLICIT TemporaryRef(T* aVal) : mPtr(RefPtr::ref(aVal)) {} + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + + template + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + + ~TemporaryRef() { RefPtr::unref(mPtr); } + + T* drop() const + { + T* tmp = mPtr; + mPtr = nullptr; + return tmp; + } + +private: + TemporaryRef(T* aVal, const DontRef&) : mPtr(aVal) {} + + mutable T* mPtr; + + TemporaryRef() MOZ_DELETE; + void operator=(const TemporaryRef&) MOZ_DELETE; +}; + +/** + * OutParamRef is a wrapper that tracks a refcounted pointer passed as + * an outparam argument to a function. OutParamRef implements COM T** + * outparam semantics: this requires the callee to AddRef() the T* + * returned through the T** outparam on behalf of the caller. This + * means the caller (through OutParamRef) must Release() the old + * object contained in the tracked RefPtr. It's OK if the callee + * returns the same T* passed to it through the T** outparam, as long + * as the callee obeys the COM discipline. + * + * Prefer returning TemporaryRef from functions over creating T** + * outparams and passing OutParamRef to T**. Prefer RefPtr* + * outparams over T** outparams. + */ +template +class OutParamRef +{ + friend OutParamRef byRef(RefPtr&); + +public: + ~OutParamRef() + { + RefPtr::unref(mRefPtr.mPtr); + mRefPtr.mPtr = mTmp; + } + + operator T**() { return &mTmp; } + +private: + explicit OutParamRef(RefPtr& p) : mRefPtr(p), mTmp(p.get()) {} + + RefPtr& mRefPtr; + T* mTmp; + + OutParamRef() MOZ_DELETE; + OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; +}; + +/** + * byRef cooperates with OutParamRef to implement COM outparam semantics. + */ +template +OutParamRef +byRef(RefPtr& aPtr) +{ + return OutParamRef(aPtr); +} + +} // namespace mozilla + +#if 0 + +// Command line that builds these tests +// +// cp RefPtr.h test.cc && g++ -g -Wall -pedantic -DDEBUG -o test test.cc && ./test + +using namespace mozilla; + +struct Foo : public RefCounted +{ + MOZ_DECLARE_REFCOUNTED_TYPENAME(Foo) + Foo() : mDead(false) {} + ~Foo() + { + MOZ_ASSERT(!mDead); + mDead = true; + sNumDestroyed++; + } + + bool mDead; + static int sNumDestroyed; +}; +int Foo::sNumDestroyed; + +struct Bar : public Foo {}; + +TemporaryRef +NewFoo() +{ + return RefPtr(new Foo()); +} + +TemporaryRef +NewBar() +{ + return new Bar(); +} + +void +GetNewFoo(Foo** f) +{ + *f = new Bar(); + // Kids, don't try this at home + (*f)->AddRef(); +} + +void +GetPassedFoo(Foo** f) +{ + // Kids, don't try this at home + (*f)->AddRef(); +} + +void +GetNewFoo(RefPtr* f) +{ + *f = new Bar(); +} + +void +GetPassedFoo(RefPtr* f) +{} + +TemporaryRef +GetNullFoo() +{ + return 0; +} + +int +main(int argc, char** argv) +{ + // This should blow up +// Foo* f = new Foo(); delete f; + + MOZ_ASSERT(0 == Foo::sNumDestroyed); + { + RefPtr f = new Foo(); + MOZ_ASSERT(f->refCount() == 1); + } + MOZ_ASSERT(1 == Foo::sNumDestroyed); + + { + RefPtr f1 = NewFoo(); + RefPtr f2(NewFoo()); + MOZ_ASSERT(1 == Foo::sNumDestroyed); + } + MOZ_ASSERT(3 == Foo::sNumDestroyed); + + { + RefPtr b = NewBar(); + MOZ_ASSERT(3 == Foo::sNumDestroyed); + } + MOZ_ASSERT(4 == Foo::sNumDestroyed); + + { + RefPtr f1; + { + f1 = new Foo(); + RefPtr f2(f1); + RefPtr f3 = f2; + MOZ_ASSERT(4 == Foo::sNumDestroyed); + } + MOZ_ASSERT(4 == Foo::sNumDestroyed); + } + MOZ_ASSERT(5 == Foo::sNumDestroyed); + + { + RefPtr f = new Foo(); + f.forget(); + MOZ_ASSERT(6 == Foo::sNumDestroyed); + } + + { + RefPtr f = new Foo(); + GetNewFoo(byRef(f)); + MOZ_ASSERT(7 == Foo::sNumDestroyed); + } + MOZ_ASSERT(8 == Foo::sNumDestroyed); + + { + RefPtr f = new Foo(); + GetPassedFoo(byRef(f)); + MOZ_ASSERT(8 == Foo::sNumDestroyed); + } + MOZ_ASSERT(9 == Foo::sNumDestroyed); + + { + RefPtr f = new Foo(); + GetNewFoo(&f); + MOZ_ASSERT(10 == Foo::sNumDestroyed); + } + MOZ_ASSERT(11 == Foo::sNumDestroyed); + + { + RefPtr f = new Foo(); + GetPassedFoo(&f); + MOZ_ASSERT(11 == Foo::sNumDestroyed); + } + MOZ_ASSERT(12 == Foo::sNumDestroyed); + + { + RefPtr f1 = new Bar(); + } + MOZ_ASSERT(13 == Foo::sNumDestroyed); + + { + RefPtr f = GetNullFoo(); + MOZ_ASSERT(13 == Foo::sNumDestroyed); + } + MOZ_ASSERT(13 == Foo::sNumDestroyed); + + return 0; +} + +#endif + +#endif /* mozilla_RefPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/RollingMean.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/RollingMean.h new file mode 100644 index 0000000000..5add14c879 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/RollingMean.h @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A set abstraction for enumeration values. */ + +#ifndef mozilla_RollingMean_h_ +#define mozilla_RollingMean_h_ + +#include "mozilla/Assertions.h" +#include "mozilla/TypeTraits.h" +#include "mozilla/Vector.h" + +#include + +namespace mozilla { + +/** + * RollingMean calculates a rolling mean of the values it is given. It + * accumulates the total as values are added and removed. The second type + * argument S specifies the type of the total. This may need to be a bigger + * type in order to maintain that the sum of all values in the average doesn't + * exceed the maximum input value. + * + * WARNING: Float types are not supported due to rounding errors. + */ +template +class RollingMean +{ +private: + size_t mInsertIndex; + size_t mMaxValues; + Vector mValues; + S mTotal; + +public: + static_assert(!IsFloatingPoint::value, + "floating-point types are unsupported due to rounding " + "errors"); + + explicit RollingMean(size_t aMaxValues) + : mInsertIndex(0), + mMaxValues(aMaxValues), + mTotal(0) + { + MOZ_ASSERT(aMaxValues > 0); + } + + RollingMean& operator=(RollingMean&& aOther) + { + MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); + this->~RollingMean(); + new(this) RollingMean(aOther.mMaxValues); + mInsertIndex = aOther.mInsertIndex; + mTotal = aOther.mTotal; + mValues.swap(aOther.mValues); + return *this; + } + + /** + * Insert a value into the rolling mean. + */ + bool insert(T aValue) + { + MOZ_ASSERT(mValues.length() <= mMaxValues); + + if (mValues.length() == mMaxValues) { + mTotal = mTotal - mValues[mInsertIndex] + aValue; + mValues[mInsertIndex] = aValue; + } else { + if (!mValues.append(aValue)) { + return false; + } + mTotal = mTotal + aValue; + } + + mInsertIndex = (mInsertIndex + 1) % mMaxValues; + return true; + } + + /** + * Calculate the rolling mean. + */ + T mean() + { + MOZ_ASSERT(!empty()); + return T(mTotal / mValues.length()); + } + + bool empty() + { + return mValues.empty(); + } + + /** + * Remove all values from the rolling mean. + */ + void clear() + { + mValues.clear(); + mInsertIndex = 0; + mTotal = T(0); + } + + size_t maxValues() + { + return mMaxValues; + } +}; + +} // namespace mozilla + +#endif // mozilla_RollingMean_h_ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/SHA1.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/SHA1.h new file mode 100644 index 0000000000..ddccaa67e7 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/SHA1.h @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Simple class for computing SHA1. */ + +#ifndef mozilla_SHA1_h +#define mozilla_SHA1_h + +#include "mozilla/Types.h" + +#include +#include + +namespace mozilla { + +/** + * This class computes the SHA1 hash of a byte sequence, or of the concatenation + * of multiple sequences. For example, computing the SHA1 of two sequences of + * bytes could be done as follows: + * + * void SHA1(const uint8_t* buf1, uint32_t size1, + * const uint8_t* buf2, uint32_t size2, + * SHA1Sum::Hash& hash) + * { + * SHA1Sum s; + * s.update(buf1, size1); + * s.update(buf2, size2); + * s.finish(hash); + * } + * + * The finish method may only be called once and cannot be followed by calls + * to update. + */ +class SHA1Sum +{ + union + { + uint32_t mW[16]; /* input buffer */ + uint8_t mB[64]; + } mU; + uint64_t mSize; /* count of hashed bytes. */ + unsigned mH[22]; /* 5 state variables, 16 tmp values, 1 extra */ + bool mDone; + +public: + MFBT_API SHA1Sum(); + + static const size_t kHashSize = 20; + typedef uint8_t Hash[kHashSize]; + + /* Add len bytes of dataIn to the data sequence being hashed. */ + MFBT_API void update(const void* aData, uint32_t aLength); + + /* Compute the final hash of all data into hashOut. */ + MFBT_API void finish(SHA1Sum::Hash& aHashOut); +}; + +} /* namespace mozilla */ + +#endif /* mozilla_SHA1_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Scoped.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Scoped.h new file mode 100644 index 0000000000..3f854d6375 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Scoped.h @@ -0,0 +1,308 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A number of structures to simplify scope-based RAII management. */ + +#ifndef mozilla_Scoped_h +#define mozilla_Scoped_h + +/* + * Resource Acquisition Is Initialization is a programming idiom used + * to write robust code that is able to deallocate resources properly, + * even in presence of execution errors or exceptions that need to be + * propagated. The Scoped* classes defined in this header perform the + * deallocation of the resource they hold once program execution + * reaches the end of the scope for which they have been defined. + * + * This header provides the following RAII classes: + * + * - |ScopedFreePtr| - a container for a pointer, that automatically calls + * |free()| at the end of the scope; + * - |ScopedDeletePtr| - a container for a pointer, that automatically calls + * |delete| at the end of the scope; + * - |ScopedDeleteArray| - a container for a pointer to an array, that + * automatically calls |delete[]| at the end of the scope. + * + * The general scenario for each of the RAII classes is the following: + * + * ScopedClass foo(create_value()); + * // ... In this scope, |foo| is defined. Use |foo.get()| or |foo.rwget()| + * to access the value. + * // ... In case of |return| or |throw|, |foo| is deallocated automatically. + * // ... If |foo| needs to be returned or stored, use |foo.forget()| + * + * Note that the RAII classes defined in this header do _not_ perform any form + * of reference-counting or garbage-collection. These classes have exactly two + * behaviors: + * + * - if |forget()| has not been called, the resource is always deallocated at + * the end of the scope; + * - if |forget()| has been called, any control on the resource is unbound + * and the resource is not deallocated by the class. + * + * Extension: + * + * In addition, this header provides class |Scoped| and macros |SCOPED_TEMPLATE| + * and |MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE| to simplify the definition + * of RAII classes for other scenarios. These macros have been used to + * automatically close file descriptors/file handles when reaching the end of + * the scope, graphics contexts, etc. + */ + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/GuardObjects.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" + +namespace mozilla { + +/* + * Scoped is a helper to create RAII wrappers + * Type argument |Traits| is expected to have the following structure: + * + * struct Traits + * { + * // Define the type of the value stored in the wrapper + * typedef value_type type; + * // Returns the value corresponding to the uninitialized or freed state + * const static type empty(); + * // Release resources corresponding to the wrapped value + * // This function is responsible for not releasing an |empty| value + * const static void release(type); + * } + */ +template +class Scoped +{ +public: + typedef typename Traits::type Resource; + + explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + : mValue(Traits::empty()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + explicit Scoped(const Resource& aValue + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(aValue) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + /* Move constructor. */ + explicit Scoped(Scoped&& aOther + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(Move(aOther.mValue)) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + aOther.mValue = Traits::empty(); + } + + ~Scoped() { Traits::release(mValue); } + + // Constant getter + operator const Resource&() const { return mValue; } + const Resource& operator->() const { return mValue; } + const Resource& get() const { return mValue; } + // Non-constant getter. + Resource& rwget() { return mValue; } + + /* + * Forget the resource. + * + * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will + * have no effect at destruction (unless it is reset to another resource by + * |operator=|). + * + * @return The original resource. + */ + Resource forget() + { + Resource tmp = mValue; + mValue = Traits::empty(); + return tmp; + } + + /* + * Perform immediate clean-up of this |Scoped|. + * + * If this |Scoped| is currently empty, this method has no effect. + */ + void dispose() + { + Traits::release(mValue); + mValue = Traits::empty(); + } + + bool operator==(const Resource& aOther) const { return mValue == aOther; } + + /* + * Replace the resource with another resource. + * + * Calling |operator=| has the side-effect of triggering clean-up. If you do + * not want to trigger clean-up, you should first invoke |forget|. + * + * @return this + */ + Scoped& operator=(const Resource& aOther) { return reset(aOther); } + + Scoped& reset(const Resource& aOther) + { + Traits::release(mValue); + mValue = aOther; + return *this; + } + + /* Move assignment operator. */ + Scoped& operator=(Scoped&& aRhs) + { + MOZ_ASSERT(&aRhs != this, "self-move-assignment not allowed"); + this->~Scoped(); + new(this) Scoped(Move(aRhs)); + return *this; + } + +private: + explicit Scoped(const Scoped& aValue) MOZ_DELETE; + Scoped& operator=(const Scoped& aValue) MOZ_DELETE; + +private: + Resource mValue; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* + * SCOPED_TEMPLATE defines a templated class derived from Scoped + * This allows to implement templates such as ScopedFreePtr. + * + * @param name The name of the class to define. + * @param Traits A struct implementing clean-up. See the implementations + * for more details. + */ +#define SCOPED_TEMPLATE(name, Traits) \ +template \ +struct name : public mozilla::Scoped > \ +{ \ + typedef mozilla::Scoped > Super; \ + typedef typename Super::Resource Resource; \ + name& operator=(Resource aRhs) \ + { \ + Super::operator=(aRhs); \ + return *this; \ + } \ + name& operator=(name&& aRhs) \ + { \ + Super::operator=(Move(aRhs)); \ + return *this; \ + } \ + explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ + : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ + {} \ + explicit name(Resource aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ + explicit name(name&& aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(Move(aRhs) \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ +private: \ + explicit name(name&) MOZ_DELETE; \ + name& operator=(name&) MOZ_DELETE; \ +}; + +/* + * ScopedFreePtr is a RAII wrapper for pointers that need to be free()d. + * + * struct S { ... }; + * ScopedFreePtr foo = malloc(sizeof(S)); + * ScopedFreePtr bar = strdup(str); + */ +template +struct ScopedFreePtrTraits +{ + typedef T* type; + static T* empty() { return nullptr; } + static void release(T* aPtr) { free(aPtr); } +}; +SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) + +/* + * ScopedDeletePtr is a RAII wrapper for pointers that need to be deleted. + * + * struct S { ... }; + * ScopedDeletePtr foo = new S(); + */ +template +struct ScopedDeletePtrTraits : public ScopedFreePtrTraits +{ + static void release(T* aPtr) { delete aPtr; } +}; +SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) + +/* + * ScopedDeleteArray is a RAII wrapper for pointers that need to be delete[]ed. + * + * struct S { ... }; + * ScopedDeleteArray foo = new S[42]; + */ +template +struct ScopedDeleteArrayTraits : public ScopedFreePtrTraits +{ + static void release(T* aPtr) { delete [] aPtr; } +}; +SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) + +/* + * MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE makes it easy to create scoped + * pointers for types with custom deleters; just overload + * TypeSpecificDelete(T*) in the same namespace as T to call the deleter for + * type T. + * + * @param name The name of the class to define. + * @param Type A struct implementing clean-up. See the implementations + * for more details. + * *param Deleter The function that is used to delete/destroy/free a + * non-null value of Type*. + * + * Example: + * + * MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(ScopedPRFileDesc, PRFileDesc, \ + * PR_Close) + * ... + * { + * ScopedPRFileDesc file(PR_OpenFile(...)); + * ... + * } // file is closed with PR_Close here + */ +#define MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(name, Type, Deleter) \ +template <> inline void TypeSpecificDelete(Type* aValue) { Deleter(aValue); } \ +typedef ::mozilla::TypeSpecificScopedPointer name; + +template void TypeSpecificDelete(T* aValue); + +template +struct TypeSpecificScopedPointerTraits +{ + typedef T* type; + static type empty() { return nullptr; } + static void release(type aValue) + { + if (aValue) { + TypeSpecificDelete(aValue); + } + } +}; + +SCOPED_TEMPLATE(TypeSpecificScopedPointer, TypeSpecificScopedPointerTraits) + +} /* namespace mozilla */ + +#endif /* mozilla_Scoped_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/SplayTree.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/SplayTree.h new file mode 100644 index 0000000000..a6d692266f --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/SplayTree.h @@ -0,0 +1,296 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * A sorted tree with optimal access times, where recently-accessed elements + * are faster to access again. + */ + +#ifndef mozilla_SplayTree_h +#define mozilla_SplayTree_h + +#include "mozilla/Assertions.h" +#include "mozilla/NullPtr.h" + +namespace mozilla { + +template +class SplayTree; + +template +class SplayTreeNode +{ +public: + template + friend class SplayTree; + + SplayTreeNode() + : mLeft(nullptr) + , mRight(nullptr) + , mParent(nullptr) + {} + +private: + T* mLeft; + T* mRight; + T* mParent; +}; + + +/** + * Class which represents a splay tree. + * Splay trees are balanced binary search trees for which search, insert and + * remove are all amortized O(log n), but where accessing a node makes it + * faster to access that node in the future. + * + * T indicates the type of tree elements, Comparator must have a static + * compare(const T&, const T&) method ordering the elements. The compare + * method must be free from side effects. + */ +template +class SplayTree +{ + T* mRoot; + +public: + SplayTree() + : mRoot(nullptr) + {} + + bool empty() const + { + return !mRoot; + } + + T* find(const T& aValue) + { + if (empty()) { + return nullptr; + } + + T* last = lookup(aValue); + splay(last); + checkCoherency(mRoot, nullptr); + return Comparator::compare(aValue, *last) == 0 ? last : nullptr; + } + + bool insert(T* aValue) + { + MOZ_ASSERT(!find(*aValue), "Duplicate elements are not allowed."); + + if (!mRoot) { + mRoot = aValue; + return true; + } + T* last = lookup(*aValue); + int cmp = Comparator::compare(*aValue, *last); + + T** parentPointer = (cmp < 0) ? &last->mLeft : &last->mRight; + MOZ_ASSERT(!*parentPointer); + *parentPointer = aValue; + aValue->mParent = last; + + splay(aValue); + checkCoherency(mRoot, nullptr); + return true; + } + + T* remove(const T& aValue) + { + T* last = lookup(aValue); + MOZ_ASSERT(last, "This tree must contain the element being removed."); + MOZ_ASSERT(Comparator::compare(aValue, *last) == 0); + + // Splay the tree so that the item to remove is the root. + splay(last); + MOZ_ASSERT(last == mRoot); + + // Find another node which can be swapped in for the root: either the + // rightmost child of the root's left, or the leftmost child of the + // root's right. + T* swap; + T* swapChild; + if (mRoot->mLeft) { + swap = mRoot->mLeft; + while (swap->mRight) { + swap = swap->mRight; + } + swapChild = swap->mLeft; + } else if (mRoot->mRight) { + swap = mRoot->mRight; + while (swap->mLeft) { + swap = swap->mLeft; + } + swapChild = swap->mRight; + } else { + T* result = mRoot; + mRoot = nullptr; + return result; + } + + // The selected node has at most one child, in swapChild. Detach it + // from the subtree by replacing it with that child. + if (swap == swap->mParent->mLeft) { + swap->mParent->mLeft = swapChild; + } else { + swap->mParent->mRight = swapChild; + } + if (swapChild) { + swapChild->mParent = swap->mParent; + } + + // Make the selected node the new root. + mRoot = swap; + mRoot->mParent = nullptr; + mRoot->mLeft = last->mLeft; + mRoot->mRight = last->mRight; + if (mRoot->mLeft) { + mRoot->mLeft->mParent = mRoot; + } + if (mRoot->mRight) { + mRoot->mRight->mParent = mRoot; + } + + checkCoherency(mRoot, nullptr); + return last; + } + + T* removeMin() + { + MOZ_ASSERT(mRoot, "No min to remove!"); + + T* min = mRoot; + while (min->mLeft) { + min = min->mLeft; + } + return remove(*min); + } + +private: + /** + * Returns the node in this comparing equal to |aValue|, or a node just + * greater or just less than |aValue| if there is no such node. + */ + T* lookup(const T& aValue) + { + MOZ_ASSERT(!empty()); + + T* node = mRoot; + T* parent; + do { + parent = node; + int c = Comparator::compare(aValue, *node); + if (c == 0) { + return node; + } else if (c < 0) { + node = node->mLeft; + } else { + node = node->mRight; + } + } while (node); + return parent; + } + + /** + * Rotate the tree until |node| is at the root of the tree. Performing + * the rotations in this fashion preserves the amortized balancing of + * the tree. + */ + void splay(T* aNode) + { + MOZ_ASSERT(aNode); + + while (aNode != mRoot) { + T* parent = aNode->mParent; + if (parent == mRoot) { + // Zig rotation. + rotate(aNode); + MOZ_ASSERT(aNode == mRoot); + return; + } + T* grandparent = parent->mParent; + if ((parent->mLeft == aNode) == (grandparent->mLeft == parent)) { + // Zig-zig rotation. + rotate(parent); + rotate(aNode); + } else { + // Zig-zag rotation. + rotate(aNode); + rotate(aNode); + } + } + } + + void rotate(T* aNode) + { + // Rearrange nodes so that aNode becomes the parent of its current + // parent, while preserving the sortedness of the tree. + T* parent = aNode->mParent; + if (parent->mLeft == aNode) { + // x y + // y c ==> a x + // a b b c + parent->mLeft = aNode->mRight; + if (aNode->mRight) { + aNode->mRight->mParent = parent; + } + aNode->mRight = parent; + } else { + MOZ_ASSERT(parent->mRight == aNode); + // x y + // a y ==> x c + // b c a b + parent->mRight = aNode->mLeft; + if (aNode->mLeft) { + aNode->mLeft->mParent = parent; + } + aNode->mLeft = parent; + } + aNode->mParent = parent->mParent; + parent->mParent = aNode; + if (T* grandparent = aNode->mParent) { + if (grandparent->mLeft == parent) { + grandparent->mLeft = aNode; + } else { + grandparent->mRight = aNode; + } + } else { + mRoot = aNode; + } + } + + T* checkCoherency(T* aNode, T* aMinimum) + { +#ifdef DEBUG + MOZ_ASSERT_IF(mRoot, !mRoot->mParent); + if (!aNode) { + MOZ_ASSERT(!mRoot); + return nullptr; + } + MOZ_ASSERT_IF(!aNode->mParent, aNode == mRoot); + MOZ_ASSERT_IF(aMinimum, Comparator::compare(*aMinimum, *aNode) < 0); + if (aNode->mLeft) { + MOZ_ASSERT(aNode->mLeft->mParent == aNode); + T* leftMaximum = checkCoherency(aNode->mLeft, aMinimum); + MOZ_ASSERT(Comparator::compare(*leftMaximum, *aNode) < 0); + } + if (aNode->mRight) { + MOZ_ASSERT(aNode->mRight->mParent == aNode); + return checkCoherency(aNode->mRight, aNode); + } + return aNode; +#else + return nullptr; +#endif + } + + SplayTree(const SplayTree&) MOZ_DELETE; + void operator=(const SplayTree&) MOZ_DELETE; +}; + +} /* namespace mozilla */ + +#endif /* mozilla_SplayTree_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/TemplateLib.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/TemplateLib.h new file mode 100644 index 0000000000..ea12c18b2b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/TemplateLib.h @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Reusable template meta-functions on types and compile-time values. Meta- + * functions are placed inside the 'tl' namespace to avoid conflict with non- + * meta functions of the same name (e.g., mozilla::tl::FloorLog2 vs. + * mozilla::FloorLog2). + * + * When constexpr support becomes universal, we should probably use that instead + * of some of these templates, for simplicity. + */ + +#ifndef mozilla_TemplateLib_h +#define mozilla_TemplateLib_h + +#include +#include + +namespace mozilla { + +namespace tl { + +/** Compute min/max. */ +template +struct Min +{ + static const size_t value = I < J ? I : J; +}; +template +struct Max +{ + static const size_t value = I > J ? I : J; +}; + +/** Compute floor(log2(i)). */ +template +struct FloorLog2 +{ + static const size_t value = 1 + FloorLog2::value; +}; +template<> struct FloorLog2<0> { /* Error */ }; +template<> struct FloorLog2<1> { static const size_t value = 0; }; + +/** Compute ceiling(log2(i)). */ +template +struct CeilingLog2 +{ + static const size_t value = FloorLog2<2 * I - 1>::value; +}; + +/** Round up to the nearest power of 2. */ +template +struct RoundUpPow2 +{ + static const size_t value = size_t(1) << CeilingLog2::value; +}; +template<> +struct RoundUpPow2<0> +{ + static const size_t value = 1; +}; + +/** Compute the number of bits in the given unsigned type. */ +template +struct BitSize +{ + static const size_t value = sizeof(T) * CHAR_BIT; +}; + +/** + * Produce an N-bit mask, where N <= BitSize::value. Handle the + * language-undefined edge case when N = BitSize::value. + */ +template +struct NBitMask +{ + // Assert the precondition. On success this evaluates to 0. Otherwise it + // triggers divide-by-zero at compile time: a guaranteed compile error in + // C++11, and usually one in C++98. Add this value to |value| to assure + // its computation. + static const size_t checkPrecondition = + 0 / size_t(N < BitSize::value); + static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; +}; +template<> +struct NBitMask::value> +{ + static const size_t value = size_t(-1); +}; + +/** + * For the unsigned integral type size_t, compute a mask M for N such that + * for all X, !(X & M) implies X * N will not overflow (w.r.t size_t) + */ +template +struct MulOverflowMask +{ + static const size_t value = + ~NBitMask::value - CeilingLog2::value>::value; +}; +template<> struct MulOverflowMask<0> { /* Error */ }; +template<> struct MulOverflowMask<1> { static const size_t value = 0; }; + +} // namespace tl + +} // namespace mozilla + +#endif /* mozilla_TemplateLib_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/ThreadLocal.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/ThreadLocal.h new file mode 100644 index 0000000000..28015de22e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/ThreadLocal.h @@ -0,0 +1,151 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Cross-platform lightweight thread local data wrappers. */ + +#ifndef mozilla_ThreadLocal_h +#define mozilla_ThreadLocal_h + +#if defined(XP_WIN) +// This file will get included in any file that wants to add a profiler mark. +// In order to not bring together we could include windef.h and +// winbase.h which are sufficient to get the prototypes for the Tls* functions. +// # include +// # include +// Unfortunately, even including these headers causes us to add a bunch of ugly +// stuff to our namespace e.g #define CreateEvent CreateEventW +extern "C" { +__declspec(dllimport) void* __stdcall TlsGetValue(unsigned long); +__declspec(dllimport) int __stdcall TlsSetValue(unsigned long, void*); +__declspec(dllimport) unsigned long __stdcall TlsAlloc(); +} +#else +# include +# include +#endif + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" + +namespace mozilla { + +// sig_safe_t denotes an atomic type which can be read or stored in a single +// instruction. This means that data of this type is safe to be manipulated +// from a signal handler, or other similar asynchronous execution contexts. +#if defined(XP_WIN) +typedef unsigned long sig_safe_t; +#else +typedef sig_atomic_t sig_safe_t; +#endif + +/* + * Thread Local Storage helpers. + * + * Usage: + * + * Only static-storage-duration (e.g. global variables, or static class members) + * objects of this class should be instantiated. This class relies on + * zero-initialization, which is implicit for static-storage-duration objects. + * It doesn't have a custom default constructor, to avoid static initializers. + * + * API usage: + * + * // Create a TLS item. + * // + * // Note that init() should be invoked exactly once, before any usage of set() + * // or get(). + * mozilla::ThreadLocal tlsKey; + * if (!tlsKey.init()) { + * // deal with the error + * } + * + * // Set the TLS value + * tlsKey.set(123); + * + * // Get the TLS value + * int value = tlsKey.get(); + */ +template +class ThreadLocal +{ +#if defined(XP_WIN) + typedef unsigned long key_t; +#else + typedef pthread_key_t key_t; +#endif + + union Helper + { + void* mPtr; + T mValue; + }; + +public: + MOZ_WARN_UNUSED_RESULT inline bool init(); + + inline T get() const; + + inline void set(const T aValue); + + bool initialized() const { return mInited; } + +private: + key_t mKey; + bool mInited; +}; + +template +inline bool +ThreadLocal::init() +{ + static_assert(sizeof(T) <= sizeof(void*), + "mozilla::ThreadLocal can't be used for types larger than " + "a pointer"); + MOZ_ASSERT(!initialized()); +#ifdef XP_WIN + mKey = TlsAlloc(); + mInited = mKey != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES +#else + mInited = !pthread_key_create(&mKey, nullptr); +#endif + return mInited; +} + +template +inline T +ThreadLocal::get() const +{ + MOZ_ASSERT(initialized()); + Helper h; +#ifdef XP_WIN + h.mPtr = TlsGetValue(mKey); +#else + h.mPtr = pthread_getspecific(mKey); +#endif + return h.mValue; +} + +template +inline void +ThreadLocal::set(const T aValue) +{ + MOZ_ASSERT(initialized()); + Helper h; + h.mValue = aValue; +#ifdef XP_WIN + bool succeeded = TlsSetValue(mKey, h.mPtr); +#else + bool succeeded = !pthread_setspecific(mKey, h.mPtr); +#endif + if (!succeeded) { + MOZ_CRASH(); + } +} + +} // namespace mozilla + +#endif /* mozilla_ThreadLocal_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/TypeTraits.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/TypeTraits.h new file mode 100644 index 0000000000..515c68d94e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/TypeTraits.h @@ -0,0 +1,998 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Template-based metaprogramming and type-testing facilities. */ + +#ifndef mozilla_TypeTraits_h +#define mozilla_TypeTraits_h + +#include "mozilla/Types.h" + +/* + * These traits are approximate copies of the traits and semantics from C++11's + * header. Don't add traits not in that header! When all + * platforms provide that header, we can convert all users and remove this one. + */ + +#include + +namespace mozilla { + +/* Forward declarations. */ + +template struct RemoveCV; + +/* 20.9.3 Helper classes [meta.help] */ + +/** + * Helper class used as a base for various type traits, exposed publicly + * because exposes it as well. + */ +template +struct IntegralConstant +{ + static const T value = Value; + typedef T ValueType; + typedef IntegralConstant Type; +}; + +/** Convenient aliases. */ +typedef IntegralConstant TrueType; +typedef IntegralConstant FalseType; + +/* 20.9.4 Unary type traits [meta.unary] */ + +/* 20.9.4.1 Primary type categories [meta.unary.cat] */ + +namespace detail { + +template +struct IsVoidHelper : FalseType {}; + +template<> +struct IsVoidHelper : TrueType {}; + +} // namespace detail + +/** + * IsVoid determines whether a type is void. + * + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true; + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true. + */ +template +struct IsVoid : detail::IsVoidHelper::Type> {}; + +namespace detail { + +template +struct IsIntegralHelper : FalseType {}; + +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +#ifdef MOZ_CHAR16_IS_NOT_WCHAR +template<> struct IsIntegralHelper : TrueType {}; +#endif + +} /* namespace detail */ + +/** + * IsIntegral determines whether a type is an integral type. + * + * mozilla::IsIntegral::value is true; + * mozilla::IsIntegral::value is true; + * mozilla::IsIntegral::value is true; + * mozilla::IsIntegral::value is false; + * mozilla::IsIntegral::value is false; + * + * Note that the behavior of IsIntegral on char16_t and char32_t is + * unspecified. + */ +template +struct IsIntegral : detail::IsIntegralHelper::Type> +{}; + +template +struct IsSame; + +namespace detail { + +template +struct IsFloatingPointHelper + : IntegralConstant::value || + IsSame::value || + IsSame::value> +{}; + +} // namespace detail + +/** + * IsFloatingPoint determines whether a type is a floating point type (float, + * double, long double). + * + * mozilla::IsFloatingPoint::value is false; + * mozilla::IsFloatingPoint::value is true; + * mozilla::IsFloatingPoint::value is true; + * mozilla::IsFloatingPoint::value is false. + */ +template +struct IsFloatingPoint + : detail::IsFloatingPointHelper::Type> +{}; + +namespace detail { + +template +struct IsArrayHelper : FalseType {}; + +template +struct IsArrayHelper : TrueType {}; + +template +struct IsArrayHelper : TrueType {}; + +} // namespace detail + +/** + * IsArray determines whether a type is an array type, of known or unknown + * length. + * + * mozilla::IsArray::value is false; + * mozilla::IsArray::value is true; + * mozilla::IsArray::value is true. + */ +template +struct IsArray : detail::IsArrayHelper::Type> +{}; + +/** + * IsPointer determines whether a type is a pointer type (but not a pointer-to- + * member type). + * + * mozilla::IsPointer::value is true; + * mozilla::IsPointer::value is true; + * mozilla::IsPointer::value is true; + * mozilla::IsPointer::value is false; + * mozilla::IsPointer::value is false. + */ +template +struct IsPointer : FalseType {}; + +template +struct IsPointer : TrueType {}; + +/** + * IsLvalueReference determines whether a type is an lvalue reference. + * + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is true; + * mozilla::IsLvalueReference::value is false. + */ +template +struct IsLvalueReference : FalseType {}; + +template +struct IsLvalueReference : TrueType {}; + +/** + * IsRvalueReference determines whether a type is an rvalue reference. + * + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is true. + */ +template +struct IsRvalueReference : FalseType {}; + +template +struct IsRvalueReference : TrueType {}; + +namespace detail { + +// __is_enum is a supported extension across all of our supported compilers. +template +struct IsEnumHelper + : IntegralConstant +{}; + +} // namespace detail + +/** + * IsEnum determines whether a type is an enum type. + * + * mozilla::IsEnum::value is true; + * mozilla::IsEnum::value is false; + * mozilla::IsEnum::value is false; + */ +template +struct IsEnum + : detail::IsEnumHelper::Type> +{}; + +namespace detail { + +// __is_class is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx +template +struct IsClassHelper + : IntegralConstant +{}; + +} // namespace detail + +/** + * IsClass determines whether a type is a class type (but not a union). + * + * struct S {}; + * union U {}; + * mozilla::IsClass::value is false; + * mozilla::IsClass::value is true; + * mozilla::IsClass::value is false; + */ +template +struct IsClass + : detail::IsClassHelper::Type> +{}; + +/* 20.9.4.2 Composite type traits [meta.unary.comp] */ + +/** + * IsReference determines whether a type is an lvalue or rvalue reference. + * + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true. + */ +template +struct IsReference + : IntegralConstant::value || IsRvalueReference::value> +{}; + +/** + * IsArithmetic determines whether a type is arithmetic. A type is arithmetic + * iff it is an integral type or a floating point type. + * + * mozilla::IsArithmetic::value is true; + * mozilla::IsArithmetic::value is true; + * mozilla::IsArithmetic::value is false. + */ +template +struct IsArithmetic + : IntegralConstant::value || IsFloatingPoint::value> +{}; + +/* 20.9.4.3 Type properties [meta.unary.prop] */ + +/** + * IsConst determines whether a type is const or not. + * + * mozilla::IsConst::value is false; + * mozilla::IsConst::value is true; + * mozilla::IsConst::value is false. + */ +template +struct IsConst : FalseType {}; + +template +struct IsConst : TrueType {}; + +/** + * IsVolatile determines whether a type is volatile or not. + * + * mozilla::IsVolatile::value is false; + * mozilla::IsVolatile::value is true; + * mozilla::IsVolatile::value is false. + */ +template +struct IsVolatile : FalseType {}; + +template +struct IsVolatile : TrueType {}; + +/** + * Traits class for identifying POD types. Until C++11 there's no automatic + * way to detect PODs, so for the moment this is done manually. Users may + * define specializations of this class that inherit from mozilla::TrueType and + * mozilla::FalseType (or equivalently mozilla::IntegralConstant, or conveniently from mozilla::IsPod for composite types) as needed to + * ensure correct IsPod behavior. + */ +template +struct IsPod : public FalseType {}; + +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +#ifdef MOZ_CHAR16_IS_NOT_WCHAR +template<> struct IsPod : TrueType {}; +#endif +template struct IsPod : TrueType {}; + +namespace detail { + +// __is_empty is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx +template +struct IsEmptyHelper + : IntegralConstant::value && __is_empty(T)> +{}; + +} // namespace detail + +/** + * IsEmpty determines whether a type is a class (but not a union) that is empty. + * + * A class is empty iff it and all its base classes have no non-static data + * members (except bit-fields of length 0) and no virtual member functions, and + * no base class is empty or a virtual base class. + * + * Intuitively, empty classes don't have any data that has to be stored in + * instances of those classes. (The size of the class must still be non-zero, + * because distinct array elements of any type must have different addresses. + * However, if the Empty Base Optimization is implemented by the compiler [most + * compilers implement it, and in certain cases C++11 requires it], the size of + * a class inheriting from an empty |Base| class need not be inflated by + * |sizeof(Base)|.) And intuitively, non-empty classes have data members and/or + * vtable pointers that must be stored in each instance for proper behavior. + * + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * union U1 { int x; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct E1 {}; + * struct E2 { int : 0 }; + * struct E3 : E1 {}; + * struct E4 : E2 {}; + * static_assert(mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value, + * "all empty"); + * union U2 { E1 e1; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct NE1 { int x; }; + * struct NE2 : virtual E1 {}; + * struct NE3 : E2 { virtual ~NE3() {} }; + * struct NE4 { virtual void f() {} }; + * static_assert(!mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value, + * "all empty"); + */ +template +struct IsEmpty : detail::IsEmptyHelper::Type> +{}; + + +namespace detail { + +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> +struct IsSignedHelper; + +// Floating point is signed. +template +struct IsSignedHelper : TrueType {}; + +// Integral is conditionally signed. +template +struct IsSignedHelper + : IntegralConstant +{}; + +// Non-floating point, non-integral is not signed. +template +struct IsSignedHelper : FalseType {}; + +} // namespace detail + +/** + * IsSigned determines whether a type is a signed arithmetic type. |char| is + * considered a signed type if it has the same representation as |signed char|. + * + * mozilla::IsSigned::value is true; + * mozilla::IsSigned::value is false; + * mozilla::IsSigned::value is false; + * mozilla::IsSigned::value is true. + */ +template +struct IsSigned : detail::IsSignedHelper {}; + +namespace detail { + +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> +struct IsUnsignedHelper; + +// Floating point is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; + +// Integral is conditionally unsigned. +template +struct IsUnsignedHelper + : IntegralConstant::value || bool(NoCV(1) < NoCV(-1)))> +{}; + +// Non-floating point, non-integral is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; + +} // namespace detail + +/** + * IsUnsigned determines whether a type is an unsigned arithmetic type. + * + * mozilla::IsUnsigned::value is false; + * mozilla::IsUnsigned::value is true; + * mozilla::IsUnsigned::value is true; + * mozilla::IsUnsigned::value is false. + */ +template +struct IsUnsigned : detail::IsUnsignedHelper {}; + +/* 20.9.5 Type property queries [meta.unary.prop.query] */ + +/* 20.9.6 Relationships between types [meta.rel] */ + +/** + * IsSame tests whether two types are the same type. + * + * mozilla::IsSame::value is true; + * mozilla::IsSame::value is true; + * mozilla::IsSame::value is false; + * mozilla::IsSame::value is true; + * mozilla::IsSame::value is false; + * mozilla::IsSame::value is true. + */ +template +struct IsSame : FalseType {}; + +template +struct IsSame : TrueType {}; + +namespace detail { + +#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) + +template +struct BaseOfTester : IntegralConstant {}; + +#else + +// The trickery used to implement IsBaseOf here makes it possible to use it for +// the cases of private and multiple inheritance. This code was inspired by the +// sample code here: +// +// http://stackoverflow.com/questions/2910979/how-is-base-of-works +template +struct BaseOfHelper +{ +public: + operator Base*() const; + operator Derived*(); +}; + +template +struct BaseOfTester +{ +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); +}; + +template +struct BaseOfTester +{ +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); +}; + +template +struct BaseOfTester : FalseType {}; + +template +struct BaseOfTester : TrueType {}; + +template +struct BaseOfTester : TrueType {}; + +#endif + +} /* namespace detail */ + +/* + * IsBaseOf allows to know whether a given class is derived from another. + * + * Consider the following class definitions: + * + * class A {}; + * class B : public A {}; + * class C {}; + * + * mozilla::IsBaseOf::value is true; + * mozilla::IsBaseOf::value is false; + */ +template +struct IsBaseOf + : IntegralConstant::value> +{}; + +namespace detail { + +template +struct ConvertibleTester +{ +private: + static From create(); + + template + static char test(To to); + + template + static int test(...); + +public: + static const bool value = + sizeof(test(create())) == sizeof(char); +}; + +} // namespace detail + +/** + * IsConvertible determines whether a value of type From will implicitly convert + * to a value of type To. For example: + * + * struct A {}; + * struct B : public A {}; + * struct C {}; + * + * mozilla::IsConvertible::value is true; + * mozilla::IsConvertible::value is true; + * mozilla::IsConvertible::value is true; + * mozilla::IsConvertible::value is true; + * mozilla::IsConvertible::value is false; + * mozilla::IsConvertible::value is false; + * mozilla::IsConvertible::value is false; + * mozilla::IsConvertible::value is false. + * + * For obscure reasons, you can't use IsConvertible when the types being tested + * are related through private inheritance, and you'll get a compile error if + * you try. Just don't do it! + */ +template +struct IsConvertible + : IntegralConstant::value> +{}; + +/* 20.9.7 Transformations between types [meta.trans] */ + +/* 20.9.7.1 Const-volatile modifications [meta.trans.cv] */ + +/** + * RemoveConst removes top-level const qualifications on a type. + * + * mozilla::RemoveConst::Type is int; + * mozilla::RemoveConst::Type is int; + * mozilla::RemoveConst::Type is const int*; + * mozilla::RemoveConst::Type is int*. + */ +template +struct RemoveConst +{ + typedef T Type; +}; + +template +struct RemoveConst +{ + typedef T Type; +}; + +/** + * RemoveVolatile removes top-level volatile qualifications on a type. + * + * mozilla::RemoveVolatile::Type is int; + * mozilla::RemoveVolatile::Type is int; + * mozilla::RemoveVolatile::Type is volatile int*; + * mozilla::RemoveVolatile::Type is int*. + */ +template +struct RemoveVolatile +{ + typedef T Type; +}; + +template +struct RemoveVolatile +{ + typedef T Type; +}; + +/** + * RemoveCV removes top-level const and volatile qualifications on a type. + * + * mozilla::RemoveCV::Type is int; + * mozilla::RemoveCV::Type is int; + * mozilla::RemoveCV::Type is int; + * mozilla::RemoveCV::Type is int*. + */ +template +struct RemoveCV +{ + typedef typename RemoveConst::Type>::Type Type; +}; + +/* 20.9.7.2 Reference modifications [meta.trans.ref] */ + +/** + * Converts reference types to the underlying types. + * + * mozilla::RemoveReference::Type is T; + * mozilla::RemoveReference::Type is T; + * mozilla::RemoveReference::Type is T; + */ + +template +struct RemoveReference +{ + typedef T Type; +}; + +template +struct RemoveReference +{ + typedef T Type; +}; + +template +struct RemoveReference +{ + typedef T Type; +}; + +template +struct Conditional; + +namespace detail { + +enum Voidness { TIsVoid, TIsNotVoid }; + +template::value ? TIsVoid : TIsNotVoid> +struct AddLvalueReferenceHelper; + +template +struct AddLvalueReferenceHelper +{ + typedef void Type; +}; + +template +struct AddLvalueReferenceHelper +{ + typedef T& Type; +}; + +} // namespace detail + +/** + * AddLvalueReference adds an lvalue & reference to T if one isn't already + * present. (Note: adding an lvalue reference to an rvalue && reference in + * essence replaces the && with a &&, per C+11 reference collapsing rules. For + * example, int&& would become int&.) + * + * The final computed type will only *not* be an lvalue reference if T is void. + * + * mozilla::AddLvalueReference::Type is int&; + * mozilla::AddLvalueRference::Type is volatile int&; + * mozilla::AddLvalueReference::Type is void*&; + * mozilla::AddLvalueReference::Type is void; + * mozilla::AddLvalueReference::Type is struct S&. + */ +template +struct AddLvalueReference + : detail::AddLvalueReferenceHelper +{}; + +/* 20.9.7.3 Sign modifications [meta.trans.sign] */ + +template +struct EnableIf; + +namespace detail { + +template +struct WithC : Conditional +{}; + +template +struct WithV : Conditional +{}; + + +template +struct WithCV : WithC::Type> +{}; + +template +struct CorrespondingSigned; + +template<> +struct CorrespondingSigned { typedef signed char Type; }; +template<> +struct CorrespondingSigned { typedef signed char Type; }; +template<> +struct CorrespondingSigned { typedef short Type; }; +template<> +struct CorrespondingSigned { typedef int Type; }; +template<> +struct CorrespondingSigned { typedef long Type; }; +template<> +struct CorrespondingSigned { typedef long long Type; }; + +template::Type, + bool IsSignedIntegerType = IsSigned::value && + !IsSame::value> +struct MakeSigned; + +template +struct MakeSigned +{ + typedef T Type; +}; + +template +struct MakeSigned + : WithCV::value, IsVolatile::value, + typename CorrespondingSigned::Type> +{}; + +} // namespace detail + +/** + * MakeSigned produces the corresponding signed integer type for a given + * integral type T, with the const/volatile qualifiers of T. T must be a + * possibly-const/volatile-qualified integral type that isn't bool. + * + * If T is already a signed integer type (not including char!), then T is + * produced. + * + * Otherwise, if T is an unsigned integer type, the signed variety of T, with + * T's const/volatile qualifiers, is produced. + * + * Otherwise, the integral type of the same size as T, with the lowest rank, + * with T's const/volatile qualifiers, is produced. (This basically only acts + * to produce signed char when T = char.) + * + * mozilla::MakeSigned::Type is signed long; + * mozilla::MakeSigned::Type is volatile int; + * mozilla::MakeSigned::Type is const signed short; + * mozilla::MakeSigned::Type is const signed char; + * mozilla::MakeSigned is an error; + * mozilla::MakeSigned is an error. + */ +template +struct MakeSigned + : EnableIf::value && + !IsSame::Type>::value, + typename detail::MakeSigned + >::Type +{}; + +namespace detail { + +template +struct CorrespondingUnsigned; + +template<> +struct CorrespondingUnsigned { typedef unsigned char Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned char Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned short Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned int Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned long Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned long long Type; }; + + +template::Type, + bool IsUnsignedIntegerType = IsUnsigned::value && + !IsSame::value> +struct MakeUnsigned; + +template +struct MakeUnsigned +{ + typedef T Type; +}; + +template +struct MakeUnsigned + : WithCV::value, IsVolatile::value, + typename CorrespondingUnsigned::Type> +{}; + +} // namespace detail + +/** + * MakeUnsigned produces the corresponding unsigned integer type for a given + * integral type T, with the const/volatile qualifiers of T. T must be a + * possibly-const/volatile-qualified integral type that isn't bool. + * + * If T is already an unsigned integer type (not including char!), then T is + * produced. + * + * Otherwise, if T is an signed integer type, the unsigned variety of T, with + * T's const/volatile qualifiers, is produced. + * + * Otherwise, the unsigned integral type of the same size as T, with the lowest + * rank, with T's const/volatile qualifiers, is produced. (This basically only + * acts to produce unsigned char when T = char.) + * + * mozilla::MakeUnsigned::Type is unsigned long; + * mozilla::MakeUnsigned::Type is volatile unsigned int; + * mozilla::MakeUnsigned::Type is const unsigned short; + * mozilla::MakeUnsigned::Type is const unsigned char; + * mozilla::MakeUnsigned is an error; + * mozilla::MakeUnsigned is an error. + */ +template +struct MakeUnsigned + : EnableIf::value && + !IsSame::Type>::value, + typename detail::MakeUnsigned + >::Type +{}; + +/* 20.9.7.4 Array modifications [meta.trans.arr] */ + +/** + * RemoveExtent produces either the type of the elements of the array T, or T + * itself. + * + * mozilla::RemoveExtent::Type is int; + * mozilla::RemoveExtent::Type is const int; + * mozilla::RemoveExtent::Type is volatile int; + * mozilla::RemoveExtent::Type is long[17]. + */ +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + +/* 20.9.7.5 Pointer modifications [meta.trans.ptr] */ + +/* 20.9.7.6 Other transformations [meta.trans.other] */ + +/** + * EnableIf is a struct containing a typedef of T if and only if B is true. + * + * mozilla::EnableIf::Type is int; + * mozilla::EnableIf::Type is a compile-time error. + * + * Use this template to implement SFINAE-style (Substitution Failure Is not An + * Error) requirements. For example, you might use it to impose a restriction + * on a template parameter: + * + * template + * class PodVector // vector optimized to store POD (memcpy-able) types + * { + * EnableIf::value, T>::Type* vector; + * size_t length; + * ... + * }; + */ +template +struct EnableIf +{}; + +template +struct EnableIf +{ + typedef T Type; +}; + +/** + * Conditional selects a class between two, depending on a given boolean value. + * + * mozilla::Conditional::Type is A; + * mozilla::Conditional::Type is B; + */ +template +struct Conditional +{ + typedef A Type; +}; + +template +struct Conditional +{ + typedef B Type; +}; + +} /* namespace mozilla */ + +#endif /* mozilla_TypeTraits_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/TypedEnum.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/TypedEnum.h new file mode 100644 index 0000000000..d84cd90257 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/TypedEnum.h @@ -0,0 +1,281 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Macros to emulate C++11 typed enums and enum classes. */ + +#ifndef mozilla_TypedEnum_h +#define mozilla_TypedEnum_h + +#include "mozilla/TypedEnumInternal.h" +#include "mozilla/MacroArgs.h" + +#if defined(__cplusplus) + +/** + * MOZ_ENUM_TYPE specifies the underlying numeric type for an enum. It's + * specified by placing MOZ_ENUM_TYPE(type) immediately after the enum name in + * its declaration, and before the opening curly brace, like + * + * enum MyEnum MOZ_ENUM_TYPE(uint16_t) + * { + * A, + * B = 7, + * C + * }; + * + * In supporting compilers, the macro will expand to ": uint16_t". The + * compiler will allocate exactly two bytes for MyEnum and will require all + * enumerators to have values between 0 and 65535. (Thus specifying "B = + * 100000" instead of "B = 7" would fail to compile.) In old compilers the + * macro expands to the empty string, and the underlying type is generally + * undefined. + */ +#ifdef MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_ENUM_TYPE(type) : type +#else +# define MOZ_ENUM_TYPE(type) /* no support */ +#endif + +/** + * MOZ_BEGIN_ENUM_CLASS and MOZ_END_ENUM_CLASS provide access to the + * strongly-typed enumeration feature of C++11 ("enum class"). If supported + * by the compiler, an enum defined using these macros will not be implicitly + * converted to any other type, and its enumerators will be scoped using the + * enumeration name. Place MOZ_BEGIN_ENUM_CLASS(EnumName [, type]) in place of + * "enum EnumName {", and MOZ_END_ENUM_CLASS(EnumName) in place of the closing + * "};". For example, + * + * MOZ_BEGIN_ENUM_CLASS(Enum, int32_t) + * A, + * B = 6 + * MOZ_END_ENUM_CLASS(Enum) + * + * This will make "Enum::A" and "Enum::B" appear in the global scope, but "A" + * and "B" will not. In compilers that support C++11 strongly-typed + * enumerations, implicit conversions of Enum values to numeric types will + * fail. In other compilers, Enum itself will actually be defined as a class, + * and some implicit conversions will fail while others will succeed. + * + * The optional type argument specifies the underlying type for the enum where + * supported, as with MOZ_ENUM_TYPE(). As with MOZ_ENUM_TYPE(), it will do + * nothing on compilers that do not support it. + * + * MOZ_{BEGIN,END}_ENUM_CLASS doesn't work for defining enum classes nested + * inside classes. To define an enum class nested inside another class, use + * MOZ_{BEGIN,END}_NESTED_ENUM_CLASS, and place a MOZ_FINISH_NESTED_ENUM_CLASS + * in namespace scope to handle bits that can only be implemented with + * namespace-scoped code. For example: + * + * class FooBar + * { + * MOZ_BEGIN_NESTED_ENUM_CLASS(Enum, int32_t) + * A, + * B = 6 + * MOZ_END_NESTED_ENUM_CLASS(Enum) + * }; + * + * MOZ_FINISH_NESTED_ENUM_CLASS(FooBar::Enum) + */ +#if defined(MOZ_HAVE_CXX11_STRONG_ENUMS) + /* + * All compilers that support strong enums also support an explicit + * underlying type, so no extra check is needed. + */ + + /* Single-argument form. */ +# define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER1(Name) \ + enum class Name { + /* Two-argument form. */ +# define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER2(Name, type) \ + enum class Name : type { +# define MOZ_END_NESTED_ENUM_CLASS(Name) \ + }; +# define MOZ_FINISH_NESTED_ENUM_CLASS(Name) /* nothing */ + + /* + * MOZ_ENUM_CLASS_ENUM_TYPE allows using enum classes + * as template parameter types. For that, we need integer types. + * In the present case where the compiler supports strong enums, + * these are already integer types so there is nothing more to do. + */ +# define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name + /* + * See the comment below about MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) Name +#else + /** + * We need Name to both name a type, and scope the provided enumerator + * names. Namespaces and classes both provide scoping, but namespaces + * aren't types, so we need to use a class that wraps the enum values. We + * have an implicit conversion from the inner enum type to the class, so + * statements like + * + * Enum x = Enum::A; + * + * will still work. We need to define an implicit conversion from the class + * to the inner enum as well, so that (for instance) switch statements will + * work. This means that the class can be implicitly converted to a numeric + * value as well via the enum type, since C++ allows an implicit + * user-defined conversion followed by a standard conversion to still be + * implicit. + * + * We have an explicit constructor from int defined, so that casts like + * (Enum)7 will still work. We also have a zero-argument constructor with + * no arguments, so declaration without initialization (like "Enum foo;") + * will work. + * + * Additionally, we'll delete as many operators as possible for the inner + * enum type, so statements like this will still fail: + * + * f(5 + Enum::B); // deleted operator+ + * + * But we can't prevent things like this, because C++ doesn't allow + * overriding conversions or assignment operators for enums: + * + * int x = Enum::A; + * int f() + * { + * return Enum::A; + * } + */ + + /* Single-argument form. */ +# define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER1(Name) \ + class Name \ + { \ + public: \ + enum Enum \ + { + /* Two-argument form. */ +# define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER2(Name, type) \ + class Name \ + { \ + public: \ + enum Enum MOZ_ENUM_TYPE(type) \ + { +# define MOZ_END_NESTED_ENUM_CLASS(Name) \ + }; \ + Name() {} \ + MOZ_CONSTEXPR Name(Enum aEnum) : mEnum(aEnum) {} \ + template \ + explicit MOZ_CONSTEXPR Name(Other num) : mEnum((Enum)num) {} \ + MOZ_CONSTEXPR operator Enum() const { return mEnum; } \ + explicit MOZ_CONSTEXPR Name(const mozilla::CastableTypedEnumResult& aOther) \ + : mEnum(aOther.get()) \ + {} \ + private: \ + Enum mEnum; \ + }; +# define MOZ_FINISH_NESTED_ENUM_CLASS(Name) \ + inline int operator+(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator+(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator-(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator-(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator*(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator*(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator/(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator/(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator%(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator%(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator+(const Name::Enum&) MOZ_DELETE; \ + inline int operator-(const Name::Enum&) MOZ_DELETE; \ + inline int& operator++(Name::Enum&) MOZ_DELETE; \ + inline int operator++(Name::Enum&, int) MOZ_DELETE; \ + inline int& operator--(Name::Enum&) MOZ_DELETE; \ + inline int operator--(Name::Enum&, int) MOZ_DELETE; \ + inline bool operator==(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator==(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator!=(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator!=(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator>(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator>(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator<(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator<(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator>=(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator>=(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator<=(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator<=(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator!(const Name::Enum&) MOZ_DELETE; \ + inline bool operator&&(const bool&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator&&(const Name::Enum&, const bool&) MOZ_DELETE; \ + inline bool operator||(const bool&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator||(const Name::Enum&, const bool&) MOZ_DELETE; \ + inline int operator&(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator&(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator|(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator|(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator^(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator^(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator<<(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator<<(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator>>(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator>>(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int& operator+=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator-=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator*=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator/=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator%=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator&=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator|=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator^=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator<<=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator>>=(int&, const Name::Enum&) MOZ_DELETE; + + /* + * MOZ_ENUM_CLASS_ENUM_TYPE allows using enum classes + * as template parameter types. For that, we need integer types. + * In the present case, the integer type is the Enum nested type. + */ +# define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name::Enum + /* + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is a variant of MOZ_ENUM_CLASS_ENUM_TYPE + * to be used when the enum class at hand depends on template parameters. + * + * Indeed, if T depends on template parameters, in order to name a nested type + * in T, C++ does not allow to just write "T::NestedType". Instead, we have + * to write "typename T::NestedType". The role of this macro is to add + * this "typename" keywords where needed. + * + * Example: + * + * template + * struct S {}; + * + * MOZ_BEGIN_ENUM_CLASS(E) + * Foo, + * Bar + * MOZ_END_ENUM_CLASS(E) + * + * S s; + * + * In this example, the second template parameter to S is meant to be of type + * T, but on non-C++11 compilers, type T is a class type, not an integer + * type, so it is not accepted as the type of a constant template parameter. + * One would then want to use MOZ_ENUM_CLASS_ENUM_TYPE(T), but that doesn't + * work either as T depends on template parameters (more specifically here, T + * _is_ a template parameter) so as MOZ_ENUM_CLASS_ENUM_TYPE(T) expands to + * T::Enum, we are missing the required "typename" keyword. So here, + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is needed. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) typename Name::Enum +#endif + +# define MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(a, b) a b +# define MOZ_BEGIN_NESTED_ENUM_CLASS(...) \ + MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER, \ + __VA_ARGS__), \ + (__VA_ARGS__)) + +# define MOZ_BEGIN_ENUM_CLASS(...) MOZ_BEGIN_NESTED_ENUM_CLASS(__VA_ARGS__) +# define MOZ_END_ENUM_CLASS(Name) \ + MOZ_END_NESTED_ENUM_CLASS(Name) \ + MOZ_FINISH_NESTED_ENUM_CLASS(Name) + +#endif /* __cplusplus */ + +#endif /* mozilla_TypedEnum_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/TypedEnumInternal.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/TypedEnumInternal.h new file mode 100644 index 0000000000..8c88cb589b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/TypedEnumInternal.h @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Internal stuff needed by TypedEnum.h and TypedEnumBits.h. */ + +// NOTE: When we can assume C++11 enum class support and TypedEnum.h goes away, +// we should then consider folding TypedEnumInternal.h into TypedEnumBits.h. + +#ifndef mozilla_TypedEnumInternal_h +#define mozilla_TypedEnumInternal_h + +#include "mozilla/Attributes.h" + +#if defined(__cplusplus) + +#if defined(__clang__) + /* + * Per Clang documentation, "Note that marketing version numbers should not + * be used to check for language features, as different vendors use different + * numbering schemes. Instead, use the feature checking macros." + */ +# ifndef __has_extension +# define __has_extension __has_feature /* compatibility, for older versions of clang */ +# endif +# if __has_extension(cxx_strong_enums) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#elif defined(__GNUC__) +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +# endif +#elif defined(_MSC_VER) +# if _MSC_VER >= 1400 +# define MOZ_HAVE_CXX11_ENUM_TYPE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#endif + +namespace mozilla { + +/* + * The problem that CastableTypedEnumResult aims to solve is that + * typed enums are not convertible to bool, and there is no way to make them + * be, yet user code wants to be able to write + * + * if (myFlags & Flags::SOME_PARTICULAR_FLAG) (1) + * + * There are different approaches to solving this. Most of them require + * adapting user code. For example, we could implement operator! and have + * the user write + * + * if (!!(myFlags & Flags::SOME_PARTICULAR_FLAG)) (2) + * + * Or we could supply a IsNonZero() or Any() function returning whether + * an enum value is nonzero, and have the user write + * + * if (Any(Flags & Flags::SOME_PARTICULAR_FLAG)) (3) + * + * But instead, we choose to preserve the original user syntax (1) as it + * is inherently more readable, and to ease porting existing code to typed + * enums. We achieve this by having operator& and other binary bitwise + * operators have as return type a class, CastableTypedEnumResult, + * that wraps a typed enum but adds bool convertibility. + */ +template +class CastableTypedEnumResult +{ +private: + const E mValue; + +public: + explicit MOZ_CONSTEXPR CastableTypedEnumResult(E aValue) + : mValue(aValue) + {} + + MOZ_CONSTEXPR operator E() const { return mValue; } + + template + MOZ_EXPLICIT_CONVERSION MOZ_CONSTEXPR + operator DestinationType() const { return DestinationType(mValue); } + + MOZ_CONSTEXPR bool operator !() const { return !bool(mValue); } + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS + // This get() method is used to implement a constructor in the + // non-c++11 fallback path for MOZ_BEGIN_ENUM_CLASS, taking a + // CastableTypedEnumResult. If we try to implement it using the + // above conversion operator E(), then at least clang 3.3 + // (when forced to take the non-c++11 fallback path) compiles + // this constructor to an infinite recursion. So we introduce this + // get() method, that does exactly the same as the conversion operator, + // to work around this. + MOZ_CONSTEXPR E get() const { return mValue; } +#endif +}; + +} // namespace mozilla + +#endif // __cplusplus + +#endif // mozilla_TypedEnumInternal_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Types.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Types.h new file mode 100644 index 0000000000..e7e18abb27 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Types.h @@ -0,0 +1,134 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* mfbt foundational types and macros. */ + +#ifndef mozilla_Types_h +#define mozilla_Types_h + +/* + * This header must be valid C and C++, includable by code embedding either + * SpiderMonkey or Gecko. + */ + +/* Expose all types and size_t. */ +#include +#include + +/* Implement compiler and linker macros needed for APIs. */ + +/* + * MOZ_EXPORT is used to declare and define a symbol or type which is externally + * visible to users of the current library. It encapsulates various decorations + * needed to properly export the method's symbol. + * + * api.h: + * extern MOZ_EXPORT int MeaningOfLife(void); + * extern MOZ_EXPORT int LuggageCombination; + * + * api.c: + * int MeaningOfLife(void) { return 42; } + * int LuggageCombination = 12345; + * + * If you are merely sharing a method across files, just use plain |extern|. + * These macros are designed for use by library interfaces -- not for normal + * methods or data used cross-file. + */ +#if defined(WIN32) +# define MOZ_EXPORT __declspec(dllexport) +#else /* Unix */ +# ifdef HAVE_VISIBILITY_ATTRIBUTE +# define MOZ_EXPORT __attribute__((visibility("default"))) +# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) +# define MOZ_EXPORT __global +# else +# define MOZ_EXPORT /* nothing */ +# endif +#endif + + +/* + * Whereas implementers use MOZ_EXPORT to declare and define library symbols, + * users use MOZ_IMPORT_API and MOZ_IMPORT_DATA to access them. Most often the + * implementer of the library will expose an API macro which expands to either + * the export or import version of the macro, depending upon the compilation + * mode. + */ +#ifdef _WIN32 +# if defined(__MWERKS__) +# define MOZ_IMPORT_API /* nothing */ +# else +# define MOZ_IMPORT_API __declspec(dllimport) +# endif +#else +# define MOZ_IMPORT_API MOZ_EXPORT +#endif + +#if defined(_WIN32) && !defined(__MWERKS__) +# define MOZ_IMPORT_DATA __declspec(dllimport) +#else +# define MOZ_IMPORT_DATA MOZ_EXPORT +#endif + +/* + * Consistent with the above comment, the MFBT_API and MFBT_DATA macros expose + * export mfbt declarations when building mfbt, and they expose import mfbt + * declarations when using mfbt. + */ +#if defined(IMPL_MFBT) +# define MFBT_API MOZ_EXPORT +# define MFBT_DATA MOZ_EXPORT +#else + /* + * On linux mozglue is linked in the program and we link libxul.so with + * -z,defs. Normally that causes the linker to reject undefined references in + * libxul.so, but as a loophole it allows undefined references to weak + * symbols. We add the weak attribute to the import version of the MFBT API + * macros to exploit this. + */ +# if defined(MOZ_GLUE_IN_PROGRAM) +# define MFBT_API __attribute__((weak)) MOZ_IMPORT_API +# define MFBT_DATA __attribute__((weak)) MOZ_IMPORT_DATA +# else +# define MFBT_API MOZ_IMPORT_API +# define MFBT_DATA MOZ_IMPORT_DATA +# endif +#endif + +/* + * C symbols in C++ code must be declared immediately within |extern "C"| + * blocks. However, in C code, they need not be declared specially. This + * difference is abstracted behind the MOZ_BEGIN_EXTERN_C and MOZ_END_EXTERN_C + * macros, so that the user need not know whether he is being used in C or C++ + * code. + * + * MOZ_BEGIN_EXTERN_C + * + * extern MOZ_EXPORT int MostRandomNumber(void); + * ...other declarations... + * + * MOZ_END_EXTERN_C + * + * This said, it is preferable to just use |extern "C"| in C++ header files for + * its greater clarity. + */ +#ifdef __cplusplus +# define MOZ_BEGIN_EXTERN_C extern "C" { +# define MOZ_END_EXTERN_C } +#else +# define MOZ_BEGIN_EXTERN_C +# define MOZ_END_EXTERN_C +#endif + +/* + * GCC's typeof is available when decltype is not. + */ +#if defined(__GNUC__) && defined(__cplusplus) && \ + !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L +# define decltype __typeof__ +#endif + +#endif /* mozilla_Types_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/UniquePtr.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/UniquePtr.h new file mode 100644 index 0000000000..9c873db90c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/UniquePtr.h @@ -0,0 +1,674 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Smart pointer managing sole ownership of a resource. */ + +#ifndef mozilla_UniquePtr_h +#define mozilla_UniquePtr_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/Pair.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +template class DefaultDelete; +template> class UniquePtr; + +} // namespace mozilla + +namespace mozilla { + +/** + * UniquePtr is a smart pointer that wholly owns a resource. Ownership may be + * transferred out of a UniquePtr through explicit action, but otherwise the + * resource is destroyed when the UniquePtr is destroyed. + * + * UniquePtr is similar to C++98's std::auto_ptr, but it improves upon auto_ptr + * in one crucial way: it's impossible to copy a UniquePtr. Copying an auto_ptr + * obviously *can't* copy ownership of its singly-owned resource. So what + * happens if you try to copy one? Bizarrely, ownership is implicitly + * *transferred*, preserving single ownership but breaking code that assumes a + * copy of an object is identical to the original. (This is why auto_ptr is + * prohibited in STL containers.) + * + * UniquePtr solves this problem by being *movable* rather than copyable. + * Instead of passing a |UniquePtr u| directly to the constructor or assignment + * operator, you pass |Move(u)|. In doing so you indicate that you're *moving* + * ownership out of |u|, into the target of the construction/assignment. After + * the transfer completes, |u| contains |nullptr| and may be safely destroyed. + * This preserves single ownership but also allows UniquePtr to be moved by + * algorithms that have been made move-safe. (Note: if |u| is instead a + * temporary expression, don't use |Move()|: just pass the expression, because + * it's already move-ready. For more information see Move.h.) + * + * UniquePtr is also better than std::auto_ptr in that the deletion operation is + * customizable. An optional second template parameter specifies a class that + * (through its operator()(T*)) implements the desired deletion policy. If no + * policy is specified, mozilla::DefaultDelete is used -- which will either + * |delete| or |delete[]| the resource, depending whether the resource is an + * array. Custom deletion policies ideally should be empty classes (no member + * fields, no member fields in base classes, no virtual methods/inheritance), + * because then UniquePtr can be just as efficient as a raw pointer. + * + * Use of UniquePtr proceeds like so: + * + * UniquePtr g1; // initializes to nullptr + * g1.reset(new int); // switch resources using reset() + * g1 = nullptr; // clears g1, deletes the int + * + * UniquePtr g2(new int); // owns that int + * int* p = g2.release(); // g2 leaks its int -- still requires deletion + * delete p; // now freed + * + * struct S { int x; S(int x) : x(x) {} }; + * UniquePtr g3, g4(new S(5)); + * g3 = Move(g4); // g3 owns the S, g4 cleared + * S* p = g3.get(); // g3 still owns |p| + * assert(g3->x == 5); // operator-> works (if .get() != nullptr) + * assert((*g3).x == 5); // also operator* (again, if not cleared) + * Swap(g3, g4); // g4 now owns the S, g3 cleared + * g3.swap(g4); // g3 now owns the S, g4 cleared + * UniquePtr g5(Move(g3)); // g5 owns the S, g3 cleared + * g5.reset(); // deletes the S, g5 cleared + * + * struct FreePolicy { void operator()(void* p) { free(p); } }; + * UniquePtr g6(static_cast(malloc(sizeof(int)))); + * int* ptr = g6.get(); + * g6 = nullptr; // calls free(ptr) + * + * Now, carefully note a few things you *can't* do: + * + * UniquePtr b1; + * b1 = new int; // BAD: can only assign another UniquePtr + * int* ptr = b1; // BAD: no auto-conversion to pointer, use get() + * + * UniquePtr b2(b1); // BAD: can't copy a UniquePtr + * UniquePtr b3 = b1; // BAD: can't copy-assign a UniquePtr + * + * A few miscellaneous notes: + * + * UniquePtr, when not instantiated for an array type, can be move-constructed + * and move-assigned, not only from itself but from "derived" UniquePtr + * instantiations where U converts to T and E converts to D. If you want to use + * this, you're going to have to specify a deletion policy for both UniquePtr + * instantations, and T pretty much has to have a virtual destructor. In other + * words, this doesn't work: + * + * struct Base { virtual ~Base() {} }; + * struct Derived : Base {}; + * + * UniquePtr b1; + * // BAD: DefaultDelete and DefaultDelete don't interconvert + * UniquePtr d1(Move(b)); + * + * UniquePtr b2; + * UniquePtr> d2(Move(b2)); // okay + * + * UniquePtr is specialized for array types. Specializing with an array type + * creates a smart-pointer version of that array -- not a pointer to such an + * array. + * + * UniquePtr arr(new int[5]); + * arr[0] = 4; + * + * What else is different? Deletion of course uses |delete[]|. An operator[] + * is provided. Functionality that doesn't make sense for arrays is removed. + * The constructors and mutating methods only accept array pointers (not T*, U* + * that converts to T*, or UniquePtr or UniquePtr) or |nullptr|. + * + * It's perfectly okay to return a UniquePtr from a method to assure the related + * resource is properly deleted. You'll need to use |Move()| when returning a + * local UniquePtr. Otherwise you can return |nullptr|, or you can return + * |UniquePtr(ptr)|. + * + * UniquePtr will commonly be a member of a class, with lifetime equivalent to + * that of that class. If you want to expose the related resource, you could + * expose a raw pointer via |get()|, but ownership of a raw pointer is + * inherently unclear. So it's better to expose a |const UniquePtr&| instead. + * This prohibits mutation but still allows use of |get()| when needed (but + * operator-> is preferred). Of course, you can only use this smart pointer as + * long as the enclosing class instance remains live -- no different than if you + * exposed the |get()| raw pointer. + * + * To pass a UniquePtr-managed resource as a pointer, use a |const UniquePtr&| + * argument. To specify an inout parameter (where the method may or may not + * take ownership of the resource, or reset it), or to specify an out parameter + * (where simply returning a |UniquePtr| isn't possible), use a |UniquePtr&| + * argument. To unconditionally transfer ownership of a UniquePtr + * into a method, use a |UniquePtr| argument. To conditionally transfer + * ownership of a resource into a method, should the method want it, use a + * |UniquePtr&&| argument. + */ +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + Pointer& ptr() { return tuple.first(); } + const Pointer& ptr() const { return tuple.first(); } + + DeleterType& del() { return tuple.second(); } + const DeleterType& del() const { return tuple.second(); } + + public: + /** + * Construct a UniquePtr containing |nullptr|. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! Ideally + // you should make deletion use the same function every time, using a + // deleter policy: + // + // // BAD, won't compile with MSVC10, deleter doesn't need to be a + // // variable at all + // typedef void (&FreeSignature)(void*); + // UniquePtr ptr((int*) malloc(sizeof(int)), free); + // + // // GOOD, compiles with MSVC10, deletion behavior statically known and + // // optimizable + // struct DeleteByFreeing + // { + // void operator()(void* ptr) { free(ptr); } + // }; + // + // If deletion really, truly, must be a variable: you might be able to work + // around this with a deleter class that contains the function reference. + // But this workaround is untried and untested, because variable deletion + // behavior really isn't something you should use. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + template + UniquePtr(UniquePtr&& other, + typename EnableIf::Pointer, + Pointer>::value && + !IsArray::value && + (IsReference::value + ? IsSame::value + : IsConvertible::value), + int>::Type dummy = 0) + : tuple(other.release(), Forward(other.getDeleter())) + { + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + template + UniquePtr& operator=(UniquePtr&& other) + { + static_assert(IsConvertible::Pointer, Pointer>::value, + "incompatible UniquePtr pointees"); + static_assert(!IsArray::value, + "can't assign from UniquePtr holding an array"); + + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT n) { + MOZ_ASSERT(n == nullptr); + reset(nullptr); + return *this; + } + + T& operator*() const { return *get(); } + Pointer operator->() const { + MOZ_ASSERT(get(), "dereferencing a UniquePtr containing nullptr"); + return get(); + } + + Pointer get() const { return ptr(); } + + DeleterType& getDeleter() { return del(); } + const DeleterType& getDeleter() const { return del(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = ptr(); + ptr() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = ptr(); + ptr() = p; + if (old != nullptr) + getDeleter()(old); + } + + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +// In case you didn't read the comment by the main definition (you should!): the +// UniquePtr specialization exists to manage array pointers. It deletes +// such pointers using delete[], it will reject construction and modification +// attempts using U* or U[]. Otherwise it works like the normal UniquePtr. +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + public: + /** + * Construct a UniquePtr containing nullptr. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + private: + // delete[] knows how to handle *only* an array of a single class type. For + // delete[] to work correctly, it must know the size of each element, the + // fields and base classes of each element requiring destruction, and so on. + // So forbid all overloads which would end up invoking delete[] on a pointer + // of the wrong type. + template + UniquePtr(U&& u, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! See the + // comment by this constructor in the non-T[] specialization above. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + private: + // Forbidden for the same reasons as stated above. + template + UniquePtr(U&& u, V&& v, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT) { + reset(); + return *this; + } + + T& operator[](decltype(sizeof(int)) i) const { return get()[i]; } + Pointer get() const { return tuple.first(); } + + DeleterType& getDeleter() { return tuple.second(); } + const DeleterType& getDeleter() const { return tuple.second(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = tuple.first(); + tuple.first() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = tuple.first(); + tuple.first() = p; + if (old != nullptr) + tuple.second()(old); + } + + private: + // Kill off all remaining overloads that aren't true nullptr (the overload + // above should handle that) or emulated nullptr (which acts like int/long + // on gcc 4.4/4.5). + template + void reset(U, + typename EnableIf::value && + !IsSame::Type>::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +/** A default deletion policy using plain old operator delete. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + template + DefaultDelete(const DefaultDelete& other, + typename EnableIf::value, + int>::Type dummy = 0) + {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete ptr; + } +}; + +/** A default deletion policy using operator delete[]. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete[] ptr; + } + + private: + template + void operator()(U* ptr) const MOZ_DELETE; +}; + +template +void +Swap(UniquePtr& x, UniquePtr& y) +{ + x.swap(y); +} + +template +bool +operator==(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() == y.get(); +} + +template +bool +operator!=(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() != y.get(); +} + +template +bool +operator==(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator==(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator!=(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +template +bool +operator!=(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +// No operator<, operator>, operator<=, operator>= for now because simplicity. + +namespace detail { + +template +struct UniqueSelector +{ + typedef UniquePtr SingleObject; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr UnknownBound; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr KnownBound; +}; + +} // namespace detail + +// We don't have variadic template support everywhere, so just hard-code arities +// 0-4 for now. If you need more arguments, feel free to add the extra +// overloads. +// +// Beware! Due to lack of true nullptr support in gcc 4.4 and 4.5, passing +// literal nullptr to MakeUnique will not work on some platforms. See Move.h +// for more details. + +template +typename detail::UniqueSelector::SingleObject +MakeUnique() +{ + return UniquePtr(new T()); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1) +{ + return UniquePtr(new T(Forward(a1))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2) +{ + return UniquePtr(new T(Forward(a1), Forward(a2))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4), Forward(a5))); +} + +template +typename detail::UniqueSelector::UnknownBound +MakeUnique(decltype(sizeof(int)) n) +{ + typedef typename RemoveExtent::Type ArrayType; + return UniquePtr(new ArrayType[n]()); +} + +template +typename detail::UniqueSelector::KnownBound +MakeUnique() MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) MOZ_DELETE; + +} // namespace mozilla + +#endif /* mozilla_UniquePtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Vector.h new file mode 100644 index 0000000000..8540caf476 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/Vector.h @@ -0,0 +1,1280 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A type/length-parametrized vector class. */ + +#ifndef mozilla_Vector_h +#define mozilla_Vector_h + +#include "mozilla/Alignment.h" +#include "mozilla/AllocPolicy.h" +#include "mozilla/ArrayUtils.h" // for PointerRangeSize +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/MathAlgorithms.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/ReentrancyGuard.h" +#include "mozilla/TemplateLib.h" +#include "mozilla/TypeTraits.h" + +#include // for placement new + +/* Silence dire "bugs in previous versions of MSVC have been fixed" warnings */ +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4345) +#endif + +namespace mozilla { + +template +class VectorBase; + +namespace detail { + +/* + * Check that the given capacity wastes the minimal amount of space if + * allocated on the heap. This means that aCapacity*sizeof(T) is as close to a + * power-of-two as possible. growStorageBy() is responsible for ensuring this. + */ +template +static bool CapacityHasExcessSpace(size_t aCapacity) +{ + size_t size = aCapacity * sizeof(T); + return RoundUpPow2(size) - size >= sizeof(T); +} + +/* + * This template class provides a default implementation for vector operations + * when the element type is not known to be a POD, as judged by IsPod. + */ +template +struct VectorImpl +{ + /* Destroys constructed objects in the range [aBegin, aEnd). */ + static inline void destroy(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + p->~T(); + } + } + + /* Constructs objects in the uninitialized range [aBegin, aEnd). */ + static inline void initialize(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); + } + } + + /* + * Copy-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(*p); + } + } + + /* + * Move-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void moveConstruct(T* aDst, U* aSrcStart, U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(Move(*p)); + } + } + + /* + * Copy-constructs objects in the uninitialized range [aDst, aDst+aN) from + * the same object aU. + */ + template + static inline void copyConstructN(T* aDst, size_t aN, const U& aU) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + new(aDst) T(aU); + } + } + + /* + * Grows the given buffer to have capacity aNewCap, preserving the objects + * constructed in the range [begin, end) and updating aV. Assumes that (1) + * aNewCap has not overflowed, and (2) multiplying aNewCap by sizeof(T) will + * not overflow. + */ + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + T* newbuf = reinterpret_cast(aV.malloc_(aNewCap * sizeof(T))); + if (!newbuf) { + return false; + } + T* dst = newbuf; + T* src = aV.beginNoCheck(); + for (; src < aV.endNoCheck(); ++dst, ++src) { + new(dst) T(Move(*src)); + } + VectorImpl::destroy(aV.beginNoCheck(), aV.endNoCheck()); + aV.free_(aV.mBegin); + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } +}; + +/* + * This partial template specialization provides a default implementation for + * vector operations when the element type is known to be a POD, as judged by + * IsPod. + */ +template +struct VectorImpl +{ + static inline void destroy(T*, T*) {} + + static inline void initialize(T* aBegin, T* aEnd) + { + /* + * You would think that memset would be a big win (or even break even) + * when we know T is a POD. But currently it's not. This is probably + * because |append| tends to be given small ranges and memset requires + * a function call that doesn't get inlined. + * + * memset(aBegin, 0, sizeof(T) * (aEnd - aBegin)); + */ + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); + } + } + + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + /* + * See above memset comment. Also, notice that copyConstruct is + * currently templated (T != U), so memcpy won't work without + * requiring T == U. + * + * memcpy(aDst, aSrcStart, sizeof(T) * (aSrcEnd - aSrcStart)); + */ + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + *aDst = *p; + } + } + + template + static inline void moveConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + copyConstruct(aDst, aSrcStart, aSrcEnd); + } + + static inline void copyConstructN(T* aDst, size_t aN, const T& aT) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + *aDst = aT; + } + } + + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + size_t oldSize = sizeof(T) * aV.mCapacity; + size_t newSize = sizeof(T) * aNewCap; + T* newbuf = reinterpret_cast(aV.realloc_(aV.mBegin, oldSize, newSize)); + if (!newbuf) { + return false; + } + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } +}; + +} // namespace detail + +/* + * A CRTP base class for vector-like classes. Unless you really really want + * your own vector class -- and you almost certainly don't -- you should use + * mozilla::Vector instead! + * + * See mozilla::Vector for interface requirements. + */ +template +class VectorBase : private AllocPolicy +{ + /* utilities */ + + static const bool kElemIsPod = IsPod::value; + typedef detail::VectorImpl Impl; + friend struct detail::VectorImpl; + + bool growStorageBy(size_t aIncr); + bool convertToHeapStorage(size_t aNewCap); + + /* magic constants */ + + static const int kMaxInlineBytes = 1024; + + /* compute constants */ + + /* + * Consider element size to be 1 for buffer sizing if there are 0 inline + * elements. This allows us to compile when the definition of the element + * type is not visible here. + * + * Explicit specialization is only allowed at namespace scope, so in order + * to keep everything here, we use a dummy template parameter with partial + * specialization. + */ + template + struct ElemSize + { + static const size_t value = sizeof(T); + }; + template + struct ElemSize<0, Dummy> + { + static const size_t value = 1; + }; + + static const size_t kInlineCapacity = + tl::Min::value>::value; + + /* Calculate inline buffer size; avoid 0-sized array. */ + static const size_t kInlineBytes = + tl::Max<1, kInlineCapacity * ElemSize::value>::value; + + /* member data */ + + /* + * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, + * mBegin + mLength) hold valid constructed T objects. The range [mBegin + + * mLength, mBegin + mCapacity) holds uninitialized memory. The range + * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory + * previously allocated by a call to reserve(). + */ + T* mBegin; + + /* Number of elements in the vector. */ + size_t mLength; + + /* Max number of elements storable in the vector without resizing. */ + size_t mCapacity; + +#ifdef DEBUG + /* Max elements of reserved or used space in this vector. */ + size_t mReserved; +#endif + + /* Memory used for inline storage. */ + AlignedStorage mStorage; + +#ifdef DEBUG + friend class ReentrancyGuard; + bool mEntered; +#endif + + /* private accessors */ + + bool usingInlineStorage() const + { + return mBegin == const_cast(this)->inlineStorage(); + } + + T* inlineStorage() + { + return static_cast(mStorage.addr()); + } + + T* beginNoCheck() const + { + return mBegin; + } + + T* endNoCheck() + { + return mBegin + mLength; + } + + const T* endNoCheck() const + { + return mBegin + mLength; + } + +#ifdef DEBUG + size_t reserved() const + { + MOZ_ASSERT(mReserved <= mCapacity); + MOZ_ASSERT(mLength <= mReserved); + return mReserved; + } +#endif + + /* Append operations guaranteed to succeed due to pre-reserved space. */ + template void internalAppend(U&& aU); + template + void internalAppendAll(const VectorBase& aU); + void internalAppendN(const T& aT, size_t aN); + template void internalAppend(const U* aBegin, size_t aLength); + +public: + static const size_t sMaxInlineStorage = N; + + typedef T ElementType; + + explicit VectorBase(AllocPolicy = AllocPolicy()); + explicit VectorBase(ThisVector&&); /* Move constructor. */ + ThisVector& operator=(ThisVector&&); /* Move assignment. */ + ~VectorBase(); + + /* accessors */ + + const AllocPolicy& allocPolicy() const { return *this; } + + AllocPolicy& allocPolicy() { return *this; } + + enum { InlineLength = N }; + + size_t length() const { return mLength; } + + bool empty() const { return mLength == 0; } + + size_t capacity() const { return mCapacity; } + + T* begin() + { + MOZ_ASSERT(!mEntered); + return mBegin; + } + + const T* begin() const + { + MOZ_ASSERT(!mEntered); + return mBegin; + } + + T* end() + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } + + const T* end() const + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } + + T& operator[](size_t aIndex) + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } + + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } + + T& back() + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } + + const T& back() const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } + + class Range + { + friend class VectorBase; + T* mCur; + T* mEnd; + Range(T* aCur, T* aEnd) + : mCur(aCur) + , mEnd(aEnd) + { + MOZ_ASSERT(aCur <= aEnd); + } + + public: + Range() {} + bool empty() const { return mCur == mEnd; } + size_t remain() const { return PointerRangeSize(mCur, mEnd); } + T& front() const { MOZ_ASSERT(!empty()); return *mCur; } + void popFront() { MOZ_ASSERT(!empty()); ++mCur; } + T popCopyFront() { MOZ_ASSERT(!empty()); return *mCur++; } + }; + + Range all() { return Range(begin(), end()); } + + /* mutators */ + + /** + * Given that the vector is empty and has no inline storage, grow to + * |capacity|. + */ + bool initCapacity(size_t aRequest); + + /** + * If reserve(length() + N) succeeds, the N next appends are guaranteed to + * succeed. + */ + bool reserve(size_t aRequest); + + /** + * Destroy elements in the range [end() - aIncr, end()). Does not deallocate + * or unreserve storage for those elements. + */ + void shrinkBy(size_t aIncr); + + /** Grow the vector by aIncr elements. */ + bool growBy(size_t aIncr); + + /** Call shrinkBy or growBy based on whether newSize > length(). */ + bool resize(size_t aNewLength); + + /** + * Increase the length of the vector, but don't initialize the new elements + * -- leave them as uninitialized memory. + */ + bool growByUninitialized(size_t aIncr); + bool resizeUninitialized(size_t aNewLength); + + /** Shorthand for shrinkBy(length()). */ + void clear(); + + /** Clears and releases any heap-allocated storage. */ + void clearAndFree(); + + /** + * If true, appending |aNeeded| elements won't reallocate elements storage. + * This *doesn't* mean that infallibleAppend may be used! You still must + * reserve the extra space, even if this method indicates that appends won't + * need to reallocate elements storage. + */ + bool canAppendWithoutRealloc(size_t aNeeded) const; + + /** Potentially fallible append operations. */ + + /** + * This can take either a T& or a T&&. Given a T&&, it moves |aU| into the + * vector, instead of copying it. If it fails, |aU| is left unmoved. ("We are + * not amused.") + */ + template bool append(U&& aU); + + template + bool appendAll(const VectorBase& aU); + bool appendN(const T& aT, size_t aN); + template bool append(const U* aBegin, const U* aEnd); + template bool append(const U* aBegin, size_t aLength); + + /* + * Guaranteed-infallible append operations for use upon vectors whose + * memory has been pre-reserved. Don't use this if you haven't reserved the + * memory! + */ + template void infallibleAppend(U&& aU) + { + internalAppend(Forward(aU)); + } + void infallibleAppendN(const T& aT, size_t aN) + { + internalAppendN(aT, aN); + } + template void infallibleAppend(const U* aBegin, const U* aEnd) + { + internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); + } + template void infallibleAppend(const U* aBegin, size_t aLength) + { + internalAppend(aBegin, aLength); + } + + void popBack(); + + T popCopy(); + + /** + * Transfers ownership of the internal buffer used by this vector to the + * caller. (It's the caller's responsibility to properly deallocate this + * buffer, in accordance with this vector's AllocPolicy.) After this call, + * the vector is empty. Since the returned buffer may need to be allocated + * (if the elements are currently stored in-place), the call can fail, + * returning nullptr. + * + * N.B. Although a T*, only the range [0, length()) is constructed. + */ + T* extractRawBuffer(); + + /** + * Transfer ownership of an array of objects into the vector. The caller + * must have allocated the array in accordance with this vector's + * AllocPolicy. + * + * N.B. This call assumes that there are no uninitialized elements in the + * passed array. + */ + void replaceRawBuffer(T* aP, size_t aLength); + + /** + * Places |aVal| at position |aP|, shifting existing elements from |aP| onward + * one position higher. On success, |aP| should not be reused because it'll + * be a dangling pointer if reallocation of the vector storage occurred; the + * return value should be used instead. On failure, nullptr is returned. + * + * Example usage: + * + * if (!(p = vec.insert(p, val))) { + * + * } + * + * + * This is inherently a linear-time operation. Be careful! + */ + template + T* insert(T* aP, U&& aVal); + + /** + * Removes the element |aT|, which must fall in the bounds [begin, end), + * shifting existing elements from |aT + 1| onward one position lower. + */ + void erase(T* aT); + + /** + * Removes the elements [|aBegin|, |aEnd|), which must fall in the bounds + * [begin, end), shifting existing elements from |aEnd + 1| onward to aBegin's + * old position. + */ + void erase(T* aBegin, T* aEnd); + + /** + * Measure the size of the vector's heap-allocated storage. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const; + + /** + * Like sizeOfExcludingThis, but also measures the size of the vector + * object (which must be heap-allocated) itself. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; + + void swap(ThisVector& aOther); + +private: + VectorBase(const VectorBase&) MOZ_DELETE; + void operator=(const VectorBase&) MOZ_DELETE; + + /* Move-construct/assign only from our derived class, ThisVector. */ + VectorBase(VectorBase&&) MOZ_DELETE; + void operator=(VectorBase&&) MOZ_DELETE; +}; + +/* This does the re-entrancy check plus several other sanity checks. */ +#define MOZ_REENTRANCY_GUARD_ET_AL \ + ReentrancyGuard g(*this); \ + MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == kInlineCapacity); \ + MOZ_ASSERT(reserved() <= mCapacity); \ + MOZ_ASSERT(mLength <= reserved()); \ + MOZ_ASSERT(mLength <= mCapacity) + +/* Vector Implementation */ + +template +MOZ_ALWAYS_INLINE +VectorBase::VectorBase(AP aAP) + : AP(aAP) + , mLength(0) + , mCapacity(kInlineCapacity) +#ifdef DEBUG + , mReserved(kInlineCapacity) + , mEntered(false) +#endif +{ + mBegin = static_cast(mStorage.addr()); +} + +/* Move constructor. */ +template +MOZ_ALWAYS_INLINE +VectorBase::VectorBase(TV&& aRhs) + : AllocPolicy(Move(aRhs)) +#ifdef DEBUG + , mEntered(false) +#endif +{ + mLength = aRhs.mLength; + mCapacity = aRhs.mCapacity; +#ifdef DEBUG + mReserved = aRhs.mReserved; +#endif + + if (aRhs.usingInlineStorage()) { + /* We can't move the buffer over in this case, so copy elements. */ + mBegin = static_cast(mStorage.addr()); + Impl::moveConstruct(mBegin, aRhs.beginNoCheck(), aRhs.endNoCheck()); + /* + * Leave aRhs's mLength, mBegin, mCapacity, and mReserved as they are. + * The elements in its in-line storage still need to be destroyed. + */ + } else { + /* + * Take src's buffer, and turn src into an empty vector using + * in-line storage. + */ + mBegin = aRhs.mBegin; + aRhs.mBegin = static_cast(aRhs.mStorage.addr()); + aRhs.mCapacity = kInlineCapacity; + aRhs.mLength = 0; +#ifdef DEBUG + aRhs.mReserved = kInlineCapacity; +#endif + } +} + +/* Move assignment. */ +template +MOZ_ALWAYS_INLINE TV& +VectorBase::operator=(TV&& aRhs) +{ + MOZ_ASSERT(this != &aRhs, "self-move assignment is prohibited"); + TV* tv = static_cast(this); + tv->~TV(); + new(tv) TV(Move(aRhs)); + return *tv; +} + +template +MOZ_ALWAYS_INLINE +VectorBase::~VectorBase() +{ + MOZ_REENTRANCY_GUARD_ET_AL; + Impl::destroy(beginNoCheck(), endNoCheck()); + if (!usingInlineStorage()) { + this->free_(beginNoCheck()); + } +} + +/* + * This function will create a new heap buffer with capacity aNewCap, + * move all elements in the inline buffer to this new buffer, + * and fail on OOM. + */ +template +inline bool +VectorBase::convertToHeapStorage(size_t aNewCap) +{ + MOZ_ASSERT(usingInlineStorage()); + + /* Allocate buffer. */ + MOZ_ASSERT(!detail::CapacityHasExcessSpace(aNewCap)); + T* newBuf = reinterpret_cast(this->malloc_(aNewCap * sizeof(T))); + if (!newBuf) { + return false; + } + + /* Copy inline elements into heap buffer. */ + Impl::moveConstruct(newBuf, beginNoCheck(), endNoCheck()); + Impl::destroy(beginNoCheck(), endNoCheck()); + + /* Switch in heap buffer. */ + mBegin = newBuf; + /* mLength is unchanged. */ + mCapacity = aNewCap; + return true; +} + +template +MOZ_NEVER_INLINE bool +VectorBase::growStorageBy(size_t aIncr) +{ + MOZ_ASSERT(mLength + aIncr > mCapacity); + MOZ_ASSERT_IF(!usingInlineStorage(), + !detail::CapacityHasExcessSpace(mCapacity)); + + /* + * When choosing a new capacity, its size should is as close to 2**N bytes + * as possible. 2**N-sized requests are best because they are unlikely to + * be rounded up by the allocator. Asking for a 2**N number of elements + * isn't as good, because if sizeof(T) is not a power-of-two that would + * result in a non-2**N request size. + */ + + size_t newCap; + + if (aIncr == 1) { + if (usingInlineStorage()) { + /* This case occurs in ~70--80% of the calls to this function. */ + size_t newSize = + tl::RoundUpPow2<(kInlineCapacity + 1) * sizeof(T)>::value; + newCap = newSize / sizeof(T); + goto convert; + } + + if (mLength == 0) { + /* This case occurs in ~0--10% of the calls to this function. */ + newCap = 1; + goto grow; + } + + /* This case occurs in ~15--20% of the calls to this function. */ + + /* + * Will mLength * 4 *sizeof(T) overflow? This condition limits a vector + * to 1GB of memory on a 32-bit system, which is a reasonable limit. It + * also ensures that + * + * static_cast(end()) - static_cast(begin()) + * + * doesn't overflow ptrdiff_t (see bug 510319). + */ + if (mLength & tl::MulOverflowMask<4 * sizeof(T)>::value) { + this->reportAllocOverflow(); + return false; + } + + /* + * If we reach here, the existing capacity will have a size that is already + * as close to 2^N as sizeof(T) will allow. Just double the capacity, and + * then there might be space for one more element. + */ + newCap = mLength * 2; + if (detail::CapacityHasExcessSpace(newCap)) { + newCap += 1; + } + } else { + /* This case occurs in ~2% of the calls to this function. */ + size_t newMinCap = mLength + aIncr; + + /* Did mLength + aIncr overflow? Will newCap * sizeof(T) overflow? */ + if (newMinCap < mLength || + newMinCap & tl::MulOverflowMask<2 * sizeof(T)>::value) + { + this->reportAllocOverflow(); + return false; + } + + size_t newMinSize = newMinCap * sizeof(T); + size_t newSize = RoundUpPow2(newMinSize); + newCap = newSize / sizeof(T); + } + + if (usingInlineStorage()) { +convert: + return convertToHeapStorage(newCap); + } + +grow: + return Impl::growTo(*this, newCap); +} + +template +inline bool +VectorBase::initCapacity(size_t aRequest) +{ + MOZ_ASSERT(empty()); + MOZ_ASSERT(usingInlineStorage()); + if (aRequest == 0) { + return true; + } + T* newbuf = reinterpret_cast(this->malloc_(aRequest * sizeof(T))); + if (!newbuf) { + return false; + } + mBegin = newbuf; + mCapacity = aRequest; +#ifdef DEBUG + mReserved = aRequest; +#endif + return true; +} + +template +inline bool +VectorBase::reserve(size_t aRequest) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (aRequest > mCapacity && !growStorageBy(aRequest - mLength)) { + return false; + } +#ifdef DEBUG + if (aRequest > mReserved) { + mReserved = aRequest; + } + MOZ_ASSERT(mLength <= mReserved); + MOZ_ASSERT(mReserved <= mCapacity); +#endif + return true; +} + +template +inline void +VectorBase::shrinkBy(size_t aIncr) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + MOZ_ASSERT(aIncr <= mLength); + Impl::destroy(endNoCheck() - aIncr, endNoCheck()); + mLength -= aIncr; +} + +template +MOZ_ALWAYS_INLINE bool +VectorBase::growBy(size_t aIncr) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { + return false; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + T* newend = endNoCheck() + aIncr; + Impl::initialize(endNoCheck(), newend); + mLength += aIncr; +#ifdef DEBUG + if (mLength > mReserved) { + mReserved = mLength; + } +#endif + return true; +} + +template +MOZ_ALWAYS_INLINE bool +VectorBase::growByUninitialized(size_t aIncr) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { + return false; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + mLength += aIncr; +#ifdef DEBUG + if (mLength > mReserved) { + mReserved = mLength; + } +#endif + return true; +} + +template +inline bool +VectorBase::resize(size_t aNewLength) +{ + size_t curLength = mLength; + if (aNewLength > curLength) { + return growBy(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); + return true; +} + +template +MOZ_ALWAYS_INLINE bool +VectorBase::resizeUninitialized(size_t aNewLength) +{ + size_t curLength = mLength; + if (aNewLength > curLength) { + return growByUninitialized(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); + return true; +} + +template +inline void +VectorBase::clear() +{ + MOZ_REENTRANCY_GUARD_ET_AL; + Impl::destroy(beginNoCheck(), endNoCheck()); + mLength = 0; +} + +template +inline void +VectorBase::clearAndFree() +{ + clear(); + + if (usingInlineStorage()) { + return; + } + this->free_(beginNoCheck()); + mBegin = static_cast(mStorage.addr()); + mCapacity = kInlineCapacity; +#ifdef DEBUG + mReserved = kInlineCapacity; +#endif +} + +template +inline bool +VectorBase::canAppendWithoutRealloc(size_t aNeeded) const +{ + return mLength + aNeeded <= mCapacity; +} + +template +template +MOZ_ALWAYS_INLINE void +VectorBase::internalAppendAll( + const VectorBase& aOther) +{ + internalAppend(aOther.begin(), aOther.length()); +} + +template +template +MOZ_ALWAYS_INLINE void +VectorBase::internalAppend(U&& aU) +{ + MOZ_ASSERT(mLength + 1 <= mReserved); + MOZ_ASSERT(mReserved <= mCapacity); + new(endNoCheck()) T(Forward(aU)); + ++mLength; +} + +template +MOZ_ALWAYS_INLINE bool +VectorBase::appendN(const T& aT, size_t aNeeded) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { + return false; + } +#ifdef DEBUG + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } +#endif + internalAppendN(aT, aNeeded); + return true; +} + +template +MOZ_ALWAYS_INLINE void +VectorBase::internalAppendN(const T& aT, size_t aNeeded) +{ + MOZ_ASSERT(mLength + aNeeded <= mReserved); + MOZ_ASSERT(mReserved <= mCapacity); + Impl::copyConstructN(endNoCheck(), aNeeded, aT); + mLength += aNeeded; +} + +template +template +inline T* +VectorBase::insert(T* aP, U&& aVal) +{ + MOZ_ASSERT(begin() <= aP); + MOZ_ASSERT(aP <= end()); + size_t pos = aP - begin(); + MOZ_ASSERT(pos <= mLength); + size_t oldLength = mLength; + if (pos == oldLength) { + if (!append(Forward(aVal))) { + return nullptr; + } + } else { + T oldBack = Move(back()); + if (!append(Move(oldBack))) { /* Dup the last element. */ + return nullptr; + } + for (size_t i = oldLength; i > pos; --i) { + (*this)[i] = Move((*this)[i - 1]); + } + (*this)[pos] = Forward(aVal); + } + return begin() + pos; +} + +template +inline void +VectorBase::erase(T* aIt) +{ + MOZ_ASSERT(begin() <= aIt); + MOZ_ASSERT(aIt < end()); + while (aIt + 1 < end()) { + *aIt = Move(*(aIt + 1)); + ++aIt; + } + popBack(); +} + +template +inline void +VectorBase::erase(T* aBegin, T* aEnd) +{ + MOZ_ASSERT(begin() <= aBegin); + MOZ_ASSERT(aBegin <= aEnd); + MOZ_ASSERT(aEnd <= end()); + while (aEnd < end()) { + *aBegin++ = Move(*aEnd++); + } + shrinkBy(aEnd - aBegin); +} + +template +template +MOZ_ALWAYS_INLINE bool +VectorBase::append(const U* aInsBegin, const U* aInsEnd) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + size_t aNeeded = PointerRangeSize(aInsBegin, aInsEnd); + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { + return false; + } +#ifdef DEBUG + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } +#endif + internalAppend(aInsBegin, aNeeded); + return true; +} + +template +template +MOZ_ALWAYS_INLINE void +VectorBase::internalAppend(const U* aInsBegin, size_t aInsLength) +{ + MOZ_ASSERT(mLength + aInsLength <= mReserved); + MOZ_ASSERT(mReserved <= mCapacity); + Impl::copyConstruct(endNoCheck(), aInsBegin, aInsBegin + aInsLength); + mLength += aInsLength; +} + +template +template +MOZ_ALWAYS_INLINE bool +VectorBase::append(U&& aU) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (mLength == mCapacity && !growStorageBy(1)) { + return false; + } +#ifdef DEBUG + if (mLength + 1 > mReserved) { + mReserved = mLength + 1; + } +#endif + internalAppend(Forward(aU)); + return true; +} + +template +template +MOZ_ALWAYS_INLINE bool +VectorBase::appendAll(const VectorBase& aOther) +{ + return append(aOther.begin(), aOther.length()); +} + +template +template +MOZ_ALWAYS_INLINE bool +VectorBase::append(const U* aInsBegin, size_t aInsLength) +{ + return append(aInsBegin, aInsBegin + aInsLength); +} + +template +MOZ_ALWAYS_INLINE void +VectorBase::popBack() +{ + MOZ_REENTRANCY_GUARD_ET_AL; + MOZ_ASSERT(!empty()); + --mLength; + endNoCheck()->~T(); +} + +template +MOZ_ALWAYS_INLINE T +VectorBase::popCopy() +{ + T ret = back(); + popBack(); + return ret; +} + +template +inline T* +VectorBase::extractRawBuffer() +{ + T* ret; + if (usingInlineStorage()) { + ret = reinterpret_cast(this->malloc_(mLength * sizeof(T))); + if (!ret) { + return nullptr; + } + Impl::copyConstruct(ret, beginNoCheck(), endNoCheck()); + Impl::destroy(beginNoCheck(), endNoCheck()); + /* mBegin, mCapacity are unchanged. */ + mLength = 0; + } else { + ret = mBegin; + mBegin = static_cast(mStorage.addr()); + mLength = 0; + mCapacity = kInlineCapacity; +#ifdef DEBUG + mReserved = kInlineCapacity; +#endif + } + return ret; +} + +template +inline void +VectorBase::replaceRawBuffer(T* aP, size_t aLength) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + + /* Destroy what we have. */ + Impl::destroy(beginNoCheck(), endNoCheck()); + if (!usingInlineStorage()) { + this->free_(beginNoCheck()); + } + + /* Take in the new buffer. */ + if (aLength <= kInlineCapacity) { + /* + * We convert to inline storage if possible, even though aP might + * otherwise be acceptable. Maybe this behaviour should be + * specifiable with an argument to this function. + */ + mBegin = static_cast(mStorage.addr()); + mLength = aLength; + mCapacity = kInlineCapacity; + Impl::moveConstruct(mBegin, aP, aP + aLength); + Impl::destroy(aP, aP + aLength); + this->free_(aP); + } else { + mBegin = aP; + mLength = aLength; + mCapacity = aLength; + } +#ifdef DEBUG + mReserved = aLength; +#endif +} + +template +inline size_t +VectorBase::sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const +{ + return usingInlineStorage() ? 0 : aMallocSizeOf(beginNoCheck()); +} + +template +inline size_t +VectorBase::sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const +{ + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); +} + +template +inline void +VectorBase::swap(TV& aOther) +{ + static_assert(N == 0, + "still need to implement this for N != 0"); + + // This only works when inline storage is always empty. + if (!usingInlineStorage() && aOther.usingInlineStorage()) { + aOther.mBegin = mBegin; + mBegin = inlineStorage(); + } else if (usingInlineStorage() && !aOther.usingInlineStorage()) { + mBegin = aOther.mBegin; + aOther.mBegin = aOther.inlineStorage(); + } else if (!usingInlineStorage() && !aOther.usingInlineStorage()) { + Swap(mBegin, aOther.mBegin); + } else { + // This case is a no-op, since we'd set both to use their inline storage. + } + + Swap(mLength, aOther.mLength); + Swap(mCapacity, aOther.mCapacity); +#ifdef DEBUG + Swap(mReserved, aOther.mReserved); +#endif +} + +/* + * STL-like container providing a short-lived, dynamic buffer. Vector calls the + * constructors/destructors of all elements stored in its internal buffer, so + * non-PODs may be safely used. Additionally, Vector will store the first N + * elements in-place before resorting to dynamic allocation. + * + * T requirements: + * - default and copy constructible, assignable, destructible + * - operations do not throw + * N requirements: + * - any value, however, N is clamped to min/max values + * AllocPolicy: + * - see "Allocation policies" in AllocPolicy.h (defaults to + * mozilla::MallocAllocPolicy) + * + * Vector is not reentrant: T member functions called during Vector member + * functions must not call back into the same object! + */ +template +class Vector + : public VectorBase > +{ + typedef VectorBase Base; + +public: + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + Vector(Vector&& vec) : Base(Move(vec)) {} + Vector& operator=(Vector&& aOther) + { + return Base::operator=(Move(aOther)); + } +}; + +} // namespace mozilla + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#endif /* mozilla_Vector_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/WeakPtr.h b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/WeakPtr.h new file mode 100644 index 0000000000..07f00bc295 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp8/mozilla/WeakPtr.h @@ -0,0 +1,202 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Weak pointer functionality, implemented as a mixin for use with any class. */ + +/** + * SupportsWeakPtr lets you have a pointer to an object 'Foo' without affecting + * its lifetime. It works by creating a single shared reference counted object + * (WeakReference) that each WeakPtr will access 'Foo' through. This lets 'Foo' + * clear the pointer in the WeakReference without having to know about all of + * the WeakPtrs to it and allows the WeakReference to live beyond the lifetime + * of 'Foo'. + * + * PLEASE NOTE: This weak pointer implementation is not thread-safe. + * + * Note that when deriving from SupportsWeakPtr you should add + * MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public section of your + * class, where ClassName is the name of your class. + * + * The overhead of WeakPtr is that accesses to 'Foo' becomes an additional + * dereference, and an additional heap allocated pointer sized object shared + * between all of the WeakPtrs. + * + * Example of usage: + * + * // To have a class C support weak pointers, inherit from + * // SupportsWeakPtr. + * class C : public SupportsWeakPtr + * { + * public: + * MOZ_DECLARE_REFCOUNTED_TYPENAME(C) + * int mNum; + * void act(); + * }; + * + * C* ptr = new C(); + * + * // Get weak pointers to ptr. The first time asWeakPtr is called + * // a reference counted WeakReference object is created that + * // can live beyond the lifetime of 'ptr'. The WeakReference + * // object will be notified of 'ptr's destruction. + * WeakPtr weak = ptr->asWeakPtr(); + * WeakPtr other = ptr->asWeakPtr(); + * + * // Test a weak pointer for validity before using it. + * if (weak) { + * weak->mNum = 17; + * weak->act(); + * } + * + * // Destroying the underlying object clears weak pointers to it. + * delete ptr; + * + * MOZ_ASSERT(!weak, "Deleting |ptr| clears weak pointers to it."); + * MOZ_ASSERT(!other, "Deleting |ptr| clears all weak pointers to it."); + * + * WeakPtr is typesafe and may be used with any class. It is not required that + * the class be reference-counted or allocated in any particular way. + * + * The API was loosely inspired by Chromium's weak_ptr.h: + * http://src.chromium.org/svn/trunk/src/base/memory/weak_ptr.h + */ + +#ifndef mozilla_WeakPtr_h +#define mozilla_WeakPtr_h + +#include "mozilla/ArrayUtils.h" +#include "mozilla/Assertions.h" +#include "mozilla/NullPtr.h" +#include "mozilla/RefPtr.h" +#include "mozilla/TypeTraits.h" + +#include + +namespace mozilla { + +template class WeakPtrBase; +template class SupportsWeakPtrBase; + +namespace detail { + +// This can live beyond the lifetime of the class derived from +// SupportsWeakPtrBase. +template +class WeakReference : public ::mozilla::RefCounted > +{ +public: + explicit WeakReference(T* p) : mPtr(p) {} + + T* get() const { return mPtr; } + +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#ifdef XP_WIN +#define snprintf _snprintf +#endif + const char* typeName() const + { + static char nameBuffer[1024]; + const char* innerType = mPtr->typeName(); + // We could do fancier length checks at runtime, but innerType is + // controlled by us so we can ensure that this never causes a buffer + // overflow by this assertion. + MOZ_ASSERT(strlen(innerType) + sizeof("WeakReference<>") < + ArrayLength(nameBuffer), + "Exceedingly large type name"); + snprintf(nameBuffer, ArrayLength(nameBuffer), "WeakReference<%s>", + innerType); + // This is usually not OK, but here we are returning a pointer to a static + // buffer which will immediately be used by the caller. + return nameBuffer; + } + + size_t typeSize() const { return sizeof(*this); } +#undef snprintf +#endif + +private: + friend class WeakPtrBase >; + friend class SupportsWeakPtrBase >; + + void detach() { mPtr = nullptr; } + + T* mPtr; +}; + +} // namespace detail + +template +class SupportsWeakPtrBase +{ +public: + WeakPtrBase asWeakPtr() + { + if (!weakRef) { + weakRef = new WeakReference(static_cast(this)); + } + return WeakPtrBase(weakRef); + } + +protected: + ~SupportsWeakPtrBase() + { + static_assert(IsBaseOf, T>::value, + "T must derive from SupportsWeakPtrBase"); + if (weakRef) { + weakRef->detach(); + } + } + +private: + friend class WeakPtrBase; + + RefPtr weakRef; +}; + +template +class SupportsWeakPtr : public SupportsWeakPtrBase > +{ +}; + +template +class WeakPtrBase +{ +public: + WeakPtrBase(const WeakPtrBase& aOther) + : mRef(aOther.mRef) + {} + + // Ensure that mRef is dereferenceable in the uninitialized state. + WeakPtrBase() : mRef(new WeakReference(nullptr)) {} + + operator T*() const { return mRef->get(); } + T& operator*() const { return *mRef->get(); } + + T* operator->() const { return mRef->get(); } + + T* get() const { return mRef->get(); } + +private: + friend class SupportsWeakPtrBase; + + explicit WeakPtrBase(const RefPtr &aOther) : mRef(aOther) {} + + RefPtr mRef; +}; + +template +class WeakPtr : public WeakPtrBase > +{ + typedef WeakPtrBase > Base; +public: + WeakPtr(const WeakPtr& aOther) : Base(aOther) {} + MOZ_IMPLICIT WeakPtr(const Base& aOther) : Base(aOther) {} + WeakPtr() {} +}; + +} // namespace mozilla + +#endif /* mozilla_WeakPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js-config.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js-config.h new file mode 100644 index 0000000000..774d938667 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js-config.h @@ -0,0 +1,53 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sw=4 et tw=78: + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_config_h +#define js_config_h + +/* Definitions set at build time that affect SpiderMonkey's public API. + This header file is generated by the SpiderMonkey configure script, + and installed along with jsapi.h. */ + +/* Define to 1 if SpiderMonkey is in debug mode. */ +/* #undef JS_DEBUG */ + +/* Define to 1 if SpiderMonkey should not use struct types in debug builds. */ +/* #undef JS_NO_JSVAL_JSID_STRUCT_TYPES */ + +/* Define to 1 if SpiderMonkey should support multi-threaded clients. */ +/* #undef JS_THREADSAFE */ + +/* Define to 1 if SpiderMonkey should include ctypes support. */ +#define JS_HAS_CTYPES 1 + +/* Define to 1 if SpiderMonkey should support the ability to perform + entirely too much GC. */ +#define JS_GC_ZEAL 1 + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +/* #undef JS_HAVE_ENDIAN_H */ + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +/* #undef JS_HAVE_MACHINE_ENDIAN_H */ + +/* Define to 1 if the header is present and + useable. See jscpucfg.h. */ +/* #undef JS_HAVE_SYS_ISA_DEFS_H */ + +/* Define to 1 if SpiderMonkey is in NUNBOX32 mode. */ +#define JS_NUNBOX32 1 + +/* Define to 1 if SpiderMonkey is in PUNBOX64 mode. */ +/* #undef JS_PUNBOX64 */ + +/* MOZILLA JSAPI version number components */ +#define MOZJS_MAJOR_VERSION 33 +#define MOZJS_MINOR_VERSION 1 + +#endif /* js_config_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js.msg b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js.msg new file mode 100644 index 0000000000..d342ad4506 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js.msg @@ -0,0 +1,443 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * This is the JavaScript error message file. + * + * The format for each JS error message is: + * + * MSG_DEF(, , , , + * ) + * + * where ; + * is a legal C identifer that will be used in the + * JS engine source. + * + * is an unique integral value identifying this error. + * + * is an integer literal specifying the total number of + * replaceable arguments in the following format string. + * + * is an exception index from the enum in jsexn.c; + * JSEXN_NONE for none. The given exception index will be raised by the + * engine when the corresponding error occurs. + * + * is a string literal, optionally containing sequences + * {X} where X is an integer representing the argument number that will + * be replaced with a string value when the error is reported. + * + * e.g. + * + * MSG_DEF(JSMSG_NOT_A_SUBSPECIES, 73, JSEXN_NONE, 2, + * "{0} is not a member of the {1} family") + * + * can be used: + * + * JS_ReportErrorNumber(JSMSG_NOT_A_SUBSPECIES, "Rhino", "Monkey"); + * + * to report: + * + * "Rhino is not a member of the Monkey family" + * + * When removing MSG_DEFs, convert them to JSMSG_UNUSED placeholders: + * + * MSG_DEF(JSMSG_UNUSED7, 7, 0, JSEXN_NONE, "") + * + * Before adding a new MSG_DEF at the end, look for existing JSMSG_UNUSED + * free index placeholders in the middle of the list. + */ + +MSG_DEF(JSMSG_NOT_AN_ERROR, 0, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_NOT_DEFINED, 1, 1, JSEXN_REFERENCEERR, "{0} is not defined") +MSG_DEF(JSMSG_INACTIVE, 2, 0, JSEXN_INTERNALERR, "nothing active on context") +MSG_DEF(JSMSG_MORE_ARGS_NEEDED, 3, 3, JSEXN_TYPEERR, "{0} requires more than {1} argument{2}") +MSG_DEF(JSMSG_BAD_CHAR, 4, 1, JSEXN_INTERNALERR, "invalid format character {0}") +MSG_DEF(JSMSG_BAD_TYPE, 5, 1, JSEXN_TYPEERR, "unknown type {0}") +MSG_DEF(JSMSG_ALLOC_OVERFLOW, 6, 0, JSEXN_INTERNALERR, "allocation size overflow") +MSG_DEF(JSMSG_MISSING_HEXDIGITS, 7, 0, JSEXN_SYNTAXERR, "missing hexadecimal digits after '0x'") +MSG_DEF(JSMSG_INCOMPATIBLE_PROTO, 8, 3, JSEXN_TYPEERR, "{0}.prototype.{1} called on incompatible {2}") +MSG_DEF(JSMSG_NO_CONSTRUCTOR, 9, 1, JSEXN_TYPEERR, "{0} has no constructor") +MSG_DEF(JSMSG_CANT_ALIAS, 10, 3, JSEXN_TYPEERR, "can't alias {0} to {1} in class {2}") +MSG_DEF(JSMSG_NOT_SCRIPTED_FUNCTION, 11, 1, JSEXN_TYPEERR, "{0} is not a scripted function") +MSG_DEF(JSMSG_BAD_SORT_ARG, 12, 0, JSEXN_TYPEERR, "invalid Array.prototype.sort argument") +MSG_DEF(JSMSG_BAD_ATOMIC_NUMBER, 13, 1, JSEXN_INTERNALERR, "internal error: no index for atom {0}") +MSG_DEF(JSMSG_TOO_MANY_LITERALS, 14, 0, JSEXN_INTERNALERR, "too many literals") +MSG_DEF(JSMSG_CANT_WATCH, 15, 1, JSEXN_TYPEERR, "can't watch non-native objects of class {0}") +MSG_DEF(JSMSG_STACK_UNDERFLOW, 16, 2, JSEXN_INTERNALERR, "internal error compiling {0}: stack underflow at pc {1}") +MSG_DEF(JSMSG_NEED_DIET, 17, 1, JSEXN_INTERNALERR, "{0} too large") +MSG_DEF(JSMSG_TOO_MANY_LOCAL_ROOTS, 18, 0, JSEXN_ERR, "out of local root space") +MSG_DEF(JSMSG_READ_ONLY, 19, 1, JSEXN_TYPEERR, "{0} is read-only") +MSG_DEF(JSMSG_BAD_FORMAL, 20, 0, JSEXN_SYNTAXERR, "malformed formal parameter") +MSG_DEF(JSMSG_CANT_DELETE, 21, 1, JSEXN_TYPEERR, "property {0} is non-configurable and can't be deleted") +MSG_DEF(JSMSG_NOT_FUNCTION, 22, 1, JSEXN_TYPEERR, "{0} is not a function") +MSG_DEF(JSMSG_NOT_CONSTRUCTOR, 23, 1, JSEXN_TYPEERR, "{0} is not a constructor") +MSG_DEF(JSMSG_INVALID_DATE, 24, 0, JSEXN_RANGEERR, "invalid date") +MSG_DEF(JSMSG_TOO_DEEP, 25, 1, JSEXN_INTERNALERR, "{0} nested too deeply") +MSG_DEF(JSMSG_OVER_RECURSED, 26, 0, JSEXN_INTERNALERR, "too much recursion") +MSG_DEF(JSMSG_IN_NOT_OBJECT, 27, 1, JSEXN_TYPEERR, "invalid 'in' operand {0}") +MSG_DEF(JSMSG_BAD_NEW_RESULT, 28, 1, JSEXN_TYPEERR, "invalid new expression result {0}") +MSG_DEF(JSMSG_OBJECT_ACCESS_DENIED, 29, 0, JSEXN_ERR, "Permission denied to access object") +MSG_DEF(JSMSG_PROPERTY_ACCESS_DENIED, 30, 1, JSEXN_ERR, "Permission denied to access property '{0}'") +MSG_DEF(JSMSG_BAD_INSTANCEOF_RHS, 31, 1, JSEXN_TYPEERR, "invalid 'instanceof' operand {0}") +MSG_DEF(JSMSG_BAD_BYTECODE, 32, 1, JSEXN_INTERNALERR, "unimplemented JavaScript bytecode {0}") +MSG_DEF(JSMSG_BAD_RADIX, 33, 0, JSEXN_RANGEERR, "radix must be an integer at least 2 and no greater than 36") +MSG_DEF(JSMSG_PAREN_BEFORE_LET, 34, 0, JSEXN_SYNTAXERR, "missing ( before let head") +MSG_DEF(JSMSG_CANT_CONVERT, 35, 1, JSEXN_ERR, "can't convert {0} to an integer") +MSG_DEF(JSMSG_CYCLIC_VALUE, 36, 1, JSEXN_TYPEERR, "cyclic {0} value") +MSG_DEF(JSMSG_COMPILE_EXECED_SCRIPT, 37, 0, JSEXN_TYPEERR, "can't compile over a script that is currently executing") +MSG_DEF(JSMSG_CANT_CONVERT_TO, 38, 2, JSEXN_TYPEERR, "can't convert {0} to {1}") +MSG_DEF(JSMSG_NO_PROPERTIES, 39, 1, JSEXN_TYPEERR, "{0} has no properties") +MSG_DEF(JSMSG_CANT_FIND_CLASS, 40, 1, JSEXN_TYPEERR, "can't find class id {0}") +MSG_DEF(JSMSG_DEAD_OBJECT, 41, 0, JSEXN_TYPEERR, "can't access dead object") +MSG_DEF(JSMSG_BYTECODE_TOO_BIG, 42, 2, JSEXN_INTERNALERR, "bytecode {0} too large (limit {1})") +MSG_DEF(JSMSG_UNKNOWN_FORMAT, 43, 1, JSEXN_INTERNALERR, "unknown bytecode format {0}") +MSG_DEF(JSMSG_TOO_MANY_CON_ARGS, 44, 0, JSEXN_SYNTAXERR, "too many constructor arguments") +MSG_DEF(JSMSG_TOO_MANY_FUN_ARGS, 45, 0, JSEXN_SYNTAXERR, "too many function arguments") +MSG_DEF(JSMSG_BAD_QUANTIFIER, 46, 0, JSEXN_SYNTAXERR, "invalid quantifier") +MSG_DEF(JSMSG_MIN_TOO_BIG, 47, 1, JSEXN_SYNTAXERR, "overlarge minimum {0}") +MSG_DEF(JSMSG_MAX_TOO_BIG, 48, 1, JSEXN_SYNTAXERR, "overlarge maximum {0}") +MSG_DEF(JSMSG_OUT_OF_ORDER, 49, 1, JSEXN_SYNTAXERR, "maximum {0} less than minimum") +MSG_DEF(JSMSG_BAD_DESTRUCT_DECL, 50, 0, JSEXN_SYNTAXERR, "missing = in destructuring declaration") +MSG_DEF(JSMSG_BAD_DESTRUCT_ASS, 51, 0, JSEXN_REFERENCEERR, "invalid destructuring assignment operator") +MSG_DEF(JSMSG_PAREN_AFTER_LET, 52, 0, JSEXN_SYNTAXERR, "missing ) after let head") +MSG_DEF(JSMSG_CURLY_AFTER_LET, 53, 0, JSEXN_SYNTAXERR, "missing } after let block") +MSG_DEF(JSMSG_MISSING_PAREN, 54, 0, JSEXN_SYNTAXERR, "unterminated parenthetical") +MSG_DEF(JSMSG_UNTERM_CLASS, 55, 0, JSEXN_SYNTAXERR, "unterminated character class") +MSG_DEF(JSMSG_TRAILING_SLASH, 56, 0, JSEXN_SYNTAXERR, "trailing \\ in regular expression") +MSG_DEF(JSMSG_BAD_CLASS_RANGE, 57, 0, JSEXN_SYNTAXERR, "invalid range in character class") +MSG_DEF(JSMSG_BAD_REGEXP_FLAG, 58, 1, JSEXN_SYNTAXERR, "invalid regular expression flag {0}") +MSG_DEF(JSMSG_NO_INPUT, 59, 5, JSEXN_SYNTAXERR, "no input for /{0}/{1}{2}{3}{4}") +MSG_DEF(JSMSG_CANT_OPEN, 60, 2, JSEXN_ERR, "can't open {0}: {1}") +MSG_DEF(JSMSG_TOO_MANY_FUN_APPLY_ARGS, 61, 0, JSEXN_RANGEERR, "arguments array passed to Function.prototype.apply is too large") +MSG_DEF(JSMSG_UNMATCHED_RIGHT_PAREN, 62, 0, JSEXN_SYNTAXERR, "unmatched ) in regular expression") +MSG_DEF(JSMSG_TOO_BIG_TO_ENCODE, 63, 0, JSEXN_INTERNALERR, "data are to big to encode") +MSG_DEF(JSMSG_ARG_INDEX_OUT_OF_RANGE, 64, 1, JSEXN_RANGEERR, "argument {0} accesses an index that is out of range") +MSG_DEF(JSMSG_SPREAD_TOO_LARGE, 65, 0, JSEXN_RANGEERR, "array too large due to spread operand(s)") +MSG_DEF(JSMSG_SOURCE_TOO_LONG, 66, 0, JSEXN_RANGEERR, "source is too long") +MSG_DEF(JSMSG_BAD_WEAKMAP_KEY, 67, 0, JSEXN_TYPEERR, "cannot use the given object as a weak map key") +MSG_DEF(JSMSG_BAD_SCRIPT_MAGIC, 68, 0, JSEXN_INTERNALERR, "bad script XDR magic number") +MSG_DEF(JSMSG_PAREN_BEFORE_FORMAL, 69, 0, JSEXN_SYNTAXERR, "missing ( before formal parameters") +MSG_DEF(JSMSG_MISSING_FORMAL, 70, 0, JSEXN_SYNTAXERR, "missing formal parameter") +MSG_DEF(JSMSG_PAREN_AFTER_FORMAL, 71, 0, JSEXN_SYNTAXERR, "missing ) after formal parameters") +MSG_DEF(JSMSG_CURLY_BEFORE_BODY, 72, 0, JSEXN_SYNTAXERR, "missing { before function body") +MSG_DEF(JSMSG_CURLY_AFTER_BODY, 73, 0, JSEXN_SYNTAXERR, "missing } after function body") +MSG_DEF(JSMSG_PAREN_BEFORE_COND, 74, 0, JSEXN_SYNTAXERR, "missing ( before condition") +MSG_DEF(JSMSG_PAREN_AFTER_COND, 75, 0, JSEXN_SYNTAXERR, "missing ) after condition") +MSG_DEF(JSMSG_BAD_DUP_ARGS, 76, 0, JSEXN_SYNTAXERR, "duplicate argument names not allowed in this context") +MSG_DEF(JSMSG_NAME_AFTER_DOT, 77, 0, JSEXN_SYNTAXERR, "missing name after . operator") +MSG_DEF(JSMSG_BRACKET_IN_INDEX, 78, 0, JSEXN_SYNTAXERR, "missing ] in index expression") +MSG_DEF(JSMSG_ACCESSOR_DEF_DENIED, 79, 1, JSEXN_ERR, "Permission denied to define accessor property '{0}'") +MSG_DEF(JSMSG_PAREN_BEFORE_SWITCH, 80, 0, JSEXN_SYNTAXERR, "missing ( before switch expression") +MSG_DEF(JSMSG_PAREN_AFTER_SWITCH, 81, 0, JSEXN_SYNTAXERR, "missing ) after switch expression") +MSG_DEF(JSMSG_CURLY_BEFORE_SWITCH, 82, 0, JSEXN_SYNTAXERR, "missing { before switch body") +MSG_DEF(JSMSG_COLON_AFTER_CASE, 83, 0, JSEXN_SYNTAXERR, "missing : after case label") +MSG_DEF(JSMSG_WHILE_AFTER_DO, 84, 0, JSEXN_SYNTAXERR, "missing while after do-loop body") +MSG_DEF(JSMSG_PAREN_AFTER_FOR, 85, 0, JSEXN_SYNTAXERR, "missing ( after for") +MSG_DEF(JSMSG_SEMI_AFTER_FOR_INIT, 86, 0, JSEXN_SYNTAXERR, "missing ; after for-loop initializer") +MSG_DEF(JSMSG_SEMI_AFTER_FOR_COND, 87, 0, JSEXN_SYNTAXERR, "missing ; after for-loop condition") +MSG_DEF(JSMSG_PAREN_AFTER_FOR_CTRL, 88, 0, JSEXN_SYNTAXERR, "missing ) after for-loop control") +MSG_DEF(JSMSG_CURLY_BEFORE_TRY, 89, 0, JSEXN_SYNTAXERR, "missing { before try block") +MSG_DEF(JSMSG_CURLY_AFTER_TRY, 90, 0, JSEXN_SYNTAXERR, "missing } after try block") +MSG_DEF(JSMSG_PAREN_BEFORE_CATCH, 91, 0, JSEXN_SYNTAXERR, "missing ( before catch") +MSG_DEF(JSMSG_CATCH_IDENTIFIER, 92, 0, JSEXN_SYNTAXERR, "missing identifier in catch") +MSG_DEF(JSMSG_PAREN_AFTER_CATCH, 93, 0, JSEXN_SYNTAXERR, "missing ) after catch") +MSG_DEF(JSMSG_CURLY_BEFORE_CATCH, 94, 0, JSEXN_SYNTAXERR, "missing { before catch block") +MSG_DEF(JSMSG_CURLY_AFTER_CATCH, 95, 0, JSEXN_SYNTAXERR, "missing } after catch block") +MSG_DEF(JSMSG_CURLY_BEFORE_FINALLY, 96, 0, JSEXN_SYNTAXERR, "missing { before finally block") +MSG_DEF(JSMSG_CURLY_AFTER_FINALLY, 97, 0, JSEXN_SYNTAXERR, "missing } after finally block") +MSG_DEF(JSMSG_CATCH_OR_FINALLY, 98, 0, JSEXN_SYNTAXERR, "missing catch or finally after try") +MSG_DEF(JSMSG_PAREN_BEFORE_WITH, 99, 0, JSEXN_SYNTAXERR, "missing ( before with-statement object") +MSG_DEF(JSMSG_PAREN_AFTER_WITH, 100, 0, JSEXN_SYNTAXERR, "missing ) after with-statement object") +MSG_DEF(JSMSG_CURLY_IN_COMPOUND, 101, 0, JSEXN_SYNTAXERR, "missing } in compound statement") +MSG_DEF(JSMSG_NO_VARIABLE_NAME, 102, 0, JSEXN_SYNTAXERR, "missing variable name") +MSG_DEF(JSMSG_COLON_IN_COND, 103, 0, JSEXN_SYNTAXERR, "missing : in conditional expression") +MSG_DEF(JSMSG_PAREN_AFTER_ARGS, 104, 0, JSEXN_SYNTAXERR, "missing ) after argument list") +MSG_DEF(JSMSG_BRACKET_AFTER_LIST, 105, 0, JSEXN_SYNTAXERR, "missing ] after element list") +MSG_DEF(JSMSG_COLON_AFTER_ID, 106, 0, JSEXN_SYNTAXERR, "missing : after property id") +MSG_DEF(JSMSG_CURLY_AFTER_LIST, 107, 0, JSEXN_SYNTAXERR, "missing } after property list") +MSG_DEF(JSMSG_PAREN_IN_PAREN, 108, 0, JSEXN_SYNTAXERR, "missing ) in parenthetical") +MSG_DEF(JSMSG_SEMI_BEFORE_STMNT, 109, 0, JSEXN_SYNTAXERR, "missing ; before statement") +MSG_DEF(JSMSG_NO_RETURN_VALUE, 110, 1, JSEXN_TYPEERR, "function {0} does not always return a value") +MSG_DEF(JSMSG_DUPLICATE_FORMAL, 111, 1, JSEXN_SYNTAXERR, "duplicate formal argument {0}") +MSG_DEF(JSMSG_EQUAL_AS_ASSIGN, 112, 0, JSEXN_SYNTAXERR, "test for equality (==) mistyped as assignment (=)?") +MSG_DEF(JSMSG_OPTIMIZED_CLOSURE_LEAK, 113, 0, JSEXN_INTERNALERR, "can't access optimized closure") +MSG_DEF(JSMSG_TOO_MANY_DEFAULTS, 114, 0, JSEXN_SYNTAXERR, "more than one switch default") +MSG_DEF(JSMSG_TOO_MANY_CASES, 115, 0, JSEXN_INTERNALERR, "too many switch cases") +MSG_DEF(JSMSG_BAD_SWITCH, 116, 0, JSEXN_SYNTAXERR, "invalid switch statement") +MSG_DEF(JSMSG_BAD_FOR_LEFTSIDE, 117, 0, JSEXN_SYNTAXERR, "invalid for/in left-hand side") +MSG_DEF(JSMSG_CATCH_AFTER_GENERAL, 118, 0, JSEXN_SYNTAXERR, "catch after unconditional catch") +MSG_DEF(JSMSG_CATCH_WITHOUT_TRY, 119, 0, JSEXN_SYNTAXERR, "catch without try") +MSG_DEF(JSMSG_FINALLY_WITHOUT_TRY, 120, 0, JSEXN_SYNTAXERR, "finally without try") +MSG_DEF(JSMSG_LABEL_NOT_FOUND, 121, 0, JSEXN_SYNTAXERR, "label not found") +MSG_DEF(JSMSG_TOUGH_BREAK, 122, 0, JSEXN_SYNTAXERR, "unlabeled break must be inside loop or switch") +MSG_DEF(JSMSG_BAD_CONTINUE, 123, 0, JSEXN_SYNTAXERR, "continue must be inside loop") +MSG_DEF(JSMSG_BAD_RETURN_OR_YIELD, 124, 1, JSEXN_SYNTAXERR, "{0} not in function") +MSG_DEF(JSMSG_BAD_LABEL, 125, 0, JSEXN_SYNTAXERR, "invalid label") +MSG_DEF(JSMSG_DUPLICATE_LABEL, 126, 0, JSEXN_SYNTAXERR, "duplicate label") +MSG_DEF(JSMSG_VAR_HIDES_ARG, 127, 1, JSEXN_TYPEERR, "variable {0} redeclares argument") +MSG_DEF(JSMSG_BAD_VAR_INIT, 128, 0, JSEXN_SYNTAXERR, "invalid variable initialization") +MSG_DEF(JSMSG_BAD_LEFTSIDE_OF_ASS, 129, 0, JSEXN_REFERENCEERR, "invalid assignment left-hand side") +MSG_DEF(JSMSG_BAD_OPERAND, 130, 1, JSEXN_SYNTAXERR, "invalid {0} operand") +MSG_DEF(JSMSG_BAD_PROP_ID, 131, 0, JSEXN_SYNTAXERR, "invalid property id") +MSG_DEF(JSMSG_RESERVED_ID, 132, 1, JSEXN_SYNTAXERR, "{0} is a reserved identifier") +MSG_DEF(JSMSG_SYNTAX_ERROR, 133, 0, JSEXN_SYNTAXERR, "syntax error") +MSG_DEF(JSMSG_MISSING_BINARY_DIGITS, 134, 0, JSEXN_SYNTAXERR, "missing binary digits after '0b'") +MSG_DEF(JSMSG_BAD_PROTOTYPE, 135, 1, JSEXN_TYPEERR, "'prototype' property of {0} is not an object") +MSG_DEF(JSMSG_MISSING_EXPONENT, 136, 0, JSEXN_SYNTAXERR, "missing exponent") +MSG_DEF(JSMSG_OUT_OF_MEMORY, 137, 0, JSEXN_ERR, "out of memory") +MSG_DEF(JSMSG_UNTERMINATED_STRING, 138, 0, JSEXN_SYNTAXERR, "unterminated string literal") +MSG_DEF(JSMSG_TOO_MANY_PARENS, 139, 0, JSEXN_INTERNALERR, "too many parentheses in regular expression") +MSG_DEF(JSMSG_UNTERMINATED_COMMENT, 140, 0, JSEXN_SYNTAXERR, "unterminated comment") +MSG_DEF(JSMSG_UNTERMINATED_REGEXP, 141, 0, JSEXN_SYNTAXERR, "unterminated regular expression literal") +MSG_DEF(JSMSG_BAD_CLONE_FUNOBJ_SCOPE, 142, 0, JSEXN_TYPEERR, "bad cloned function scope chain") +MSG_DEF(JSMSG_MISSING_OCTAL_DIGITS, 143, 0, JSEXN_SYNTAXERR, "missing octal digits after '0o'") +MSG_DEF(JSMSG_ILLEGAL_CHARACTER, 144, 0, JSEXN_SYNTAXERR, "illegal character") +MSG_DEF(JSMSG_BAD_OCTAL, 145, 1, JSEXN_SYNTAXERR, "{0} is not a legal ECMA-262 octal constant") +MSG_DEF(JSMSG_RESULTING_STRING_TOO_LARGE, 146, 0, JSEXN_RANGEERR, "repeat count must be less than infinity and not overflow maximum string size") +MSG_DEF(JSMSG_UNCAUGHT_EXCEPTION, 147, 1, JSEXN_INTERNALERR, "uncaught exception: {0}") +MSG_DEF(JSMSG_INVALID_BACKREF, 148, 0, JSEXN_SYNTAXERR, "non-octal digit in an escape sequence that doesn't match a back-reference") +MSG_DEF(JSMSG_BAD_BACKREF, 149, 0, JSEXN_SYNTAXERR, "back-reference exceeds number of capturing parentheses") +MSG_DEF(JSMSG_PRECISION_RANGE, 150, 1, JSEXN_RANGEERR, "precision {0} out of range") +MSG_DEF(JSMSG_BAD_GETTER_OR_SETTER, 151, 1, JSEXN_TYPEERR, "invalid {0} usage") +MSG_DEF(JSMSG_BAD_ARRAY_LENGTH, 152, 0, JSEXN_RANGEERR, "invalid array length") +MSG_DEF(JSMSG_CANT_DESCRIBE_PROPS, 153, 1, JSEXN_TYPEERR, "can't describe non-native properties of class {0}") +MSG_DEF(JSMSG_BAD_APPLY_ARGS, 154, 1, JSEXN_TYPEERR, "second argument to Function.prototype.{0} must be an array") +MSG_DEF(JSMSG_REDECLARED_VAR, 155, 2, JSEXN_TYPEERR, "redeclaration of {0} {1}") +MSG_DEF(JSMSG_UNDECLARED_VAR, 156, 1, JSEXN_REFERENCEERR, "assignment to undeclared variable {0}") +MSG_DEF(JSMSG_ANON_NO_RETURN_VALUE, 157, 0, JSEXN_TYPEERR, "anonymous function does not always return a value") +MSG_DEF(JSMSG_DEPRECATED_USAGE, 158, 1, JSEXN_REFERENCEERR, "deprecated {0} usage") +MSG_DEF(JSMSG_BAD_URI, 159, 0, JSEXN_URIERR, "malformed URI sequence") +MSG_DEF(JSMSG_GETTER_ONLY, 160, 0, JSEXN_TYPEERR, "setting a property that has only a getter") +MSG_DEF(JSMSG_IDSTART_AFTER_NUMBER, 161, 0, JSEXN_SYNTAXERR, "identifier starts immediately after numeric literal") +MSG_DEF(JSMSG_UNDEFINED_PROP, 162, 1, JSEXN_REFERENCEERR, "reference to undefined property {0}") +MSG_DEF(JSMSG_USELESS_EXPR, 163, 0, JSEXN_TYPEERR, "useless expression") +MSG_DEF(JSMSG_REDECLARED_PARAM, 164, 1, JSEXN_TYPEERR, "redeclaration of formal parameter {0}") +MSG_DEF(JSMSG_NEWREGEXP_FLAGGED, 165, 0, JSEXN_TYPEERR, "can't supply flags when constructing one RegExp from another") +MSG_DEF(JSMSG_RESERVED_SLOT_RANGE, 166, 0, JSEXN_RANGEERR, "reserved slot index out of range") +MSG_DEF(JSMSG_CANT_DECODE_PRINCIPALS, 167, 0, JSEXN_INTERNALERR, "can't decode JSPrincipals") +MSG_DEF(JSMSG_CANT_SEAL_OBJECT, 168, 1, JSEXN_ERR, "can't seal {0} objects") +MSG_DEF(JSMSG_TOO_MANY_CATCH_VARS, 169, 0, JSEXN_SYNTAXERR, "too many catch variables") +MSG_DEF(JSMSG_NEGATIVE_REPETITION_COUNT, 170, 0, JSEXN_RANGEERR, "repeat count must be non-negative") +MSG_DEF(JSMSG_INVALID_FOR_OF_INIT, 171, 0, JSEXN_SYNTAXERR, "for-of loop variable declaration may not have an initializer") +MSG_DEF(JSMSG_INVALID_MAP_ITERABLE, 172, 0, JSEXN_TYPEERR, "iterable for map should have array-like objects") +MSG_DEF(JSMSG_NOT_A_CODEPOINT, 173, 1, JSEXN_RANGEERR, "{0} is not a valid code point") +MSG_DEF(JSMSG_BRACKET_AFTER_ARRAY_COMPREHENSION, 174, 0, JSEXN_SYNTAXERR, "missing ] after array comprehension") +MSG_DEF(JSMSG_NESTING_GENERATOR, 175, 0, JSEXN_TYPEERR, "already executing generator") +MSG_DEF(JSMSG_PAREN_AFTER_FOR_OF_ITERABLE, 176, 0, JSEXN_SYNTAXERR, "missing ) after for-of iterable") +MSG_DEF(JSMSG_INVALID_NORMALIZE_FORM, 177, 0, JSEXN_RANGEERR, "form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD'") +MSG_DEF(JSMSG_NOTHING_TO_REPEAT, 178, 0, JSEXN_SYNTAXERR, "nothing to repeat") +MSG_DEF(JSMSG_INVALID_GROUP, 179, 0, JSEXN_SYNTAXERR, "invalid regexp group") +MSG_DEF(JSMSG_ESCAPE_AT_END_OF_REGEXP, 180, 0, JSEXN_SYNTAXERR, "\\ at end of pattern") +MSG_DEF(JSMSG_NUMBERS_OUT_OF_ORDER, 181, 0, JSEXN_SYNTAXERR, "numbers out of order in {} quantifier.") +MSG_DEF(JSMSG_BAD_GENERATOR_SEND, 182, 1, JSEXN_TYPEERR, "attempt to send {0} to newborn generator") +MSG_DEF(JSMSG_SC_NOT_TRANSFERABLE, 183, 0, JSEXN_TYPEERR, "invalid transferable array for structured clone") +MSG_DEF(JSMSG_SC_DUP_TRANSFERABLE, 184, 0, JSEXN_TYPEERR, "duplicate transferable for structured clone") +MSG_DEF(JSMSG_CANT_REPORT_AS_NON_EXTENSIBLE, 185, 0, JSEXN_TYPEERR, "proxy can't report an extensible object as non-extensible") +MSG_DEF(JSMSG_SYMBOL_TO_STRING, 186, 0, JSEXN_TYPEERR, "can't convert symbol to string") +MSG_DEF(JSMSG_UNUSED187, 187, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_INCOMPATIBLE_METHOD, 188, 3, JSEXN_TYPEERR, "{0} {1} called on incompatible {2}") +MSG_DEF(JSMSG_SYMBOL_TO_PRIMITIVE, 189, 0, JSEXN_TYPEERR, "can't convert symbol object to primitive") +MSG_DEF(JSMSG_UNUSED190, 190, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_BAD_INDEX, 191, 0, JSEXN_RANGEERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_SELFHOSTED_TOP_LEVEL_LET,192,0, JSEXN_SYNTAXERR, "self-hosted code cannot contain top-level 'let' declarations") +MSG_DEF(JSMSG_BAD_FOR_EACH_LOOP, 193, 0, JSEXN_SYNTAXERR, "invalid for each loop") +MSG_DEF(JSMSG_OBJECT_WATCH_DEPRECATED,194, 0, JSEXN_NONE, "Object.prototype.watch and unwatch are very slow, non-standard, and deprecated; use a getter/setter instead") +MSG_DEF(JSMSG_TYPE_ERR_BAD_ARGS, 195, 0, JSEXN_TYPEERR, "invalid arguments") +MSG_DEF(JSMSG_REDECLARED_CATCH_IDENTIFIER, 196, 1, JSEXN_TYPEERR, "redeclaration of identifier '{0}' in catch") +MSG_DEF(JSMSG_INTERNAL_INTL_ERROR, 197, 0, JSEXN_ERR, "internal error while computing Intl data") +MSG_DEF(JSMSG_DEFAULT_LOCALE_ERROR, 198, 0, JSEXN_ERR, "internal error getting the default locale") +MSG_DEF(JSMSG_TOO_MANY_LOCALS, 199, 0, JSEXN_SYNTAXERR, "too many local variables") +MSG_DEF(JSMSG_ARRAY_INIT_TOO_BIG, 200, 0, JSEXN_INTERNALERR, "array initialiser too large") +MSG_DEF(JSMSG_REGEXP_TOO_COMPLEX, 201, 0, JSEXN_INTERNALERR, "regular expression too complex") +MSG_DEF(JSMSG_BUFFER_TOO_SMALL, 202, 0, JSEXN_INTERNALERR, "buffer too small") +MSG_DEF(JSMSG_BAD_SURROGATE_CHAR, 203, 1, JSEXN_TYPEERR, "bad surrogate character {0}") +MSG_DEF(JSMSG_UTF8_CHAR_TOO_LARGE, 204, 1, JSEXN_TYPEERR, "UTF-8 character {0} too large") +MSG_DEF(JSMSG_MALFORMED_UTF8_CHAR, 205, 1, JSEXN_TYPEERR, "malformed UTF-8 character sequence at offset {0}") +MSG_DEF(JSMSG_USER_DEFINED_ERROR, 206, 0, JSEXN_ERR, "JS_ReportError was called") +MSG_DEF(JSMSG_WRONG_CONSTRUCTOR, 207, 1, JSEXN_TYPEERR, "wrong constructor called for {0}") +MSG_DEF(JSMSG_BAD_GENERATOR_RETURN, 208, 1, JSEXN_TYPEERR, "generator function {0} returns a value") +MSG_DEF(JSMSG_BAD_ANON_GENERATOR_RETURN, 209, 0, JSEXN_TYPEERR, "anonymous generator function returns a value") +MSG_DEF(JSMSG_PROTO_SETTING_SLOW, 210, 0, JSEXN_NONE, "mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create") +MSG_DEF(JSMSG_IN_AFTER_FOR_NAME, 211, 0, JSEXN_SYNTAXERR, "missing 'in' or 'of' after for") +MSG_DEF(JSMSG_BAD_TRAP_RETURN_VALUE, 212, 2, JSEXN_TYPEERR,"trap {1} for {0} returned a primitive value") +MSG_DEF(JSMSG_OF_AFTER_FOR_NAME, 213, 0, JSEXN_SYNTAXERR, "missing 'of' after for") +MSG_DEF(JSMSG_BAD_GENERATOR_YIELD, 214, 1, JSEXN_TYPEERR, "yield from closing generator {0}") +MSG_DEF(JSMSG_BAD_GENERATOR_SYNTAX, 215, 1, JSEXN_SYNTAXERR, "{0} expression must be parenthesized") +MSG_DEF(JSMSG_ARRAY_COMP_LEFTSIDE, 216, 0, JSEXN_SYNTAXERR, "invalid array comprehension left-hand side") +MSG_DEF(JSMSG_LET_COMP_BINDING, 217, 0, JSEXN_SYNTAXERR, "'let' is not a valid name for a comprehension variable") +MSG_DEF(JSMSG_EMPTY_ARRAY_REDUCE, 218, 0, JSEXN_TYPEERR, "reduce of empty array with no initial value") +MSG_DEF(JSMSG_BAD_SYMBOL, 219, 1, JSEXN_TYPEERR, "{0} is not a well-known @@-symbol") +MSG_DEF(JSMSG_BAD_DELETE_OPERAND, 220, 0, JSEXN_REFERENCEERR, "invalid delete operand") +MSG_DEF(JSMSG_BAD_INCOP_OPERAND, 221, 0, JSEXN_REFERENCEERR, "invalid increment/decrement operand") +MSG_DEF(JSMSG_UNEXPECTED_TYPE, 222, 2, JSEXN_TYPEERR, "{0} is {1}") +MSG_DEF(JSMSG_LET_DECL_NOT_IN_BLOCK, 223, 0, JSEXN_SYNTAXERR, "let declaration not directly within block") +MSG_DEF(JSMSG_UNUSED224, 224, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_CANT_SET_ARRAY_ATTRS, 225, 0, JSEXN_INTERNALERR, "can't set attributes on indexed array properties") +MSG_DEF(JSMSG_EVAL_ARITY, 226, 0, JSEXN_TYPEERR, "eval accepts only one parameter") +MSG_DEF(JSMSG_MISSING_FUN_ARG, 227, 2, JSEXN_TYPEERR, "missing argument {0} when calling function {1}") +MSG_DEF(JSMSG_JSON_BAD_PARSE, 228, 3, JSEXN_SYNTAXERR, "JSON.parse: {0} at line {1} column {2} of the JSON data") +MSG_DEF(JSMSG_JSON_BAD_STRINGIFY, 229, 0, JSEXN_ERR, "JSON.stringify") +MSG_DEF(JSMSG_NOT_CALLABLE_OR_UNDEFINED, 230, 0, JSEXN_TYPEERR, "value is not a function or undefined") +MSG_DEF(JSMSG_NOT_NONNULL_OBJECT, 231, 0, JSEXN_TYPEERR, "value is not a non-null object") +MSG_DEF(JSMSG_DEPRECATED_OCTAL, 232, 0, JSEXN_SYNTAXERR, "octal literals and octal escape sequences are deprecated") +MSG_DEF(JSMSG_STRICT_CODE_WITH, 233, 0, JSEXN_SYNTAXERR, "strict mode code may not contain 'with' statements") +MSG_DEF(JSMSG_DUPLICATE_PROPERTY, 234, 1, JSEXN_SYNTAXERR, "property name {0} appears more than once in object literal") +MSG_DEF(JSMSG_DEPRECATED_DELETE_OPERAND, 235, 0, JSEXN_SYNTAXERR, "applying the 'delete' operator to an unqualified name is deprecated") +MSG_DEF(JSMSG_BAD_STRICT_ASSIGN, 236, 1, JSEXN_SYNTAXERR, "can't assign to {0} in strict mode") +MSG_DEF(JSMSG_BAD_BINDING, 237, 1, JSEXN_SYNTAXERR, "redefining {0} is deprecated") +MSG_DEF(JSMSG_INVALID_DESCRIPTOR, 238, 0, JSEXN_TYPEERR, "property descriptors must not specify a value or be writable when a getter or setter has been specified") +MSG_DEF(JSMSG_OBJECT_NOT_EXTENSIBLE, 239, 1, JSEXN_TYPEERR, "{0} is not extensible") +MSG_DEF(JSMSG_CANT_REDEFINE_PROP, 240, 1, JSEXN_TYPEERR, "can't redefine non-configurable property '{0}'") +MSG_DEF(JSMSG_CANT_APPEND_TO_ARRAY, 241, 0, JSEXN_TYPEERR, "can't add elements past the end of an array if its length property is unwritable") +MSG_DEF(JSMSG_CANT_REDEFINE_ARRAY_LENGTH,242, 0, JSEXN_TYPEERR, "can't redefine array length") +MSG_DEF(JSMSG_CANT_DEFINE_PAST_ARRAY_LENGTH,243, 0, JSEXN_TYPEERR, "can't define array index property past the end of an array with non-writable length") +MSG_DEF(JSMSG_TYPED_ARRAY_BAD_INDEX, 244, 0, JSEXN_ERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_TYPED_ARRAY_NEGATIVE_ARG, 245, 1, JSEXN_ERR, "argument {0} must be >= 0") +MSG_DEF(JSMSG_TYPED_ARRAY_BAD_ARGS, 246, 0, JSEXN_ERR, "invalid arguments") +MSG_DEF(JSMSG_CSP_BLOCKED_FUNCTION, 247, 0, JSEXN_ERR, "call to Function() blocked by CSP") +MSG_DEF(JSMSG_BAD_GET_SET_FIELD, 248, 1, JSEXN_TYPEERR, "property descriptor's {0} field is neither undefined nor a function") +MSG_DEF(JSMSG_BAD_PROXY_FIX, 249, 0, JSEXN_TYPEERR, "proxy was fixed while executing the handler") +MSG_DEF(JSMSG_INVALID_EVAL_SCOPE_ARG, 250, 0, JSEXN_EVALERR, "invalid eval scope argument") +MSG_DEF(JSMSG_ACCESSOR_WRONG_ARGS, 251, 3, JSEXN_SYNTAXERR, "{0} functions must have {1} argument{2}") +MSG_DEF(JSMSG_THROW_TYPE_ERROR, 252, 0, JSEXN_TYPEERR, "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them") +MSG_DEF(JSMSG_BAD_TOISOSTRING_PROP, 253, 0, JSEXN_TYPEERR, "toISOString property is not callable") +MSG_DEF(JSMSG_BAD_PARSE_NODE, 254, 0, JSEXN_INTERNALERR, "bad parse node") +MSG_DEF(JSMSG_NOT_EXPECTED_TYPE, 255, 3, JSEXN_TYPEERR, "{0}: expected {1}, got {2}") +MSG_DEF(JSMSG_CALLER_IS_STRICT, 256, 0, JSEXN_TYPEERR, "access to strict mode caller function is censored") +MSG_DEF(JSMSG_NEED_DEBUG_MODE, 257, 0, JSEXN_ERR, "function can be called only in debug mode") +MSG_DEF(JSMSG_STRICT_CODE_LET_EXPR_STMT, 258, 0, JSEXN_ERR, "strict mode code may not contain unparenthesized let expression statements") +MSG_DEF(JSMSG_CANT_CHANGE_EXTENSIBILITY, 259, 0, JSEXN_TYPEERR, "can't change object's extensibility") +MSG_DEF(JSMSG_SC_BAD_SERIALIZED_DATA, 260, 1, JSEXN_INTERNALERR, "bad serialized structured data ({0})") +MSG_DEF(JSMSG_SC_UNSUPPORTED_TYPE, 261, 0, JSEXN_TYPEERR, "unsupported type for structured data") +MSG_DEF(JSMSG_SC_RECURSION, 262, 0, JSEXN_INTERNALERR, "recursive object") +MSG_DEF(JSMSG_DEBUG_CANT_DEBUG_GLOBAL, 263, 0, JSEXN_ERR, "passing non-debuggable global to addDebuggee") +MSG_DEF(JSMSG_BAD_CLONE_VERSION, 264, 0, JSEXN_ERR, "unsupported structured clone version") +MSG_DEF(JSMSG_CANT_CLONE_OBJECT, 265, 0, JSEXN_TYPEERR, "can't clone object") +MSG_DEF(JSMSG_DEBUG_RESUMPTION_VALUE_DISALLOWED, 266, 0, JSEXN_TYPEERR, "resumption values are disallowed in this hook") +MSG_DEF(JSMSG_STRICT_FUNCTION_STATEMENT, 267, 0, JSEXN_SYNTAXERR, "in strict mode code, functions may be declared only at top level or immediately within another function") +MSG_DEF(JSMSG_INVALID_FOR_IN_INIT, 268, 0, JSEXN_SYNTAXERR, "for-in loop let declaration may not have an initializer") +MSG_DEF(JSMSG_CLEARED_SCOPE, 269, 0, JSEXN_TYPEERR, "attempt to run compile-and-go script on a cleared scope") +MSG_DEF(JSMSG_MALFORMED_ESCAPE, 270, 1, JSEXN_SYNTAXERR, "malformed {0} character escape sequence") +MSG_DEF(JSMSG_BAD_GENEXP_BODY, 271, 1, JSEXN_SYNTAXERR, "illegal use of {0} in generator expression") +MSG_DEF(JSMSG_YIELD_WITHOUT_OPERAND, 272, 0, JSEXN_SYNTAXERR, "yield without a value is deprecated, and illegal in ES6 (use 'yield undefined' instead)") +MSG_DEF(JSMSG_UNNAMED_FUNCTION_STMT, 273, 0, JSEXN_SYNTAXERR, "function statement requires a name") +MSG_DEF(JSMSG_CCW_REQUIRED, 274, 1, JSEXN_TYPEERR, "{0}: argument must be an object from a different compartment") +MSG_DEF(JSMSG_DEBUG_BAD_RESUMPTION, 275, 0, JSEXN_TYPEERR, "debugger resumption value must be undefined, {throw: val}, {return: val}, or null") +MSG_DEF(JSMSG_ASSIGN_FUNCTION_OR_NULL, 276, 1, JSEXN_TYPEERR, "value assigned to {0} must be a function or null") +MSG_DEF(JSMSG_DEBUG_NOT_LIVE, 277, 1, JSEXN_ERR, "{0} is not live") +MSG_DEF(JSMSG_DEBUG_OBJECT_WRONG_OWNER, 278, 0, JSEXN_TYPEERR, "Debugger.Object belongs to a different Debugger") +MSG_DEF(JSMSG_DEBUG_OBJECT_PROTO, 279, 0, JSEXN_TYPEERR, "Debugger.Object.prototype is not a valid Debugger.Object") +MSG_DEF(JSMSG_DEBUG_LOOP, 280, 0, JSEXN_TYPEERR, "cannot debug an object in same compartment as debugger or a compartment that is already debugging the debugger") +MSG_DEF(JSMSG_DEBUG_NOT_IDLE, 281, 0, JSEXN_ERR, "can't start debugging: a debuggee script is on the stack") +MSG_DEF(JSMSG_DEBUG_BAD_OFFSET, 282, 0, JSEXN_TYPEERR, "invalid script offset") +MSG_DEF(JSMSG_DEBUG_BAD_LINE, 283, 0, JSEXN_TYPEERR, "invalid line number") +MSG_DEF(JSMSG_DEBUG_NOT_DEBUGGING, 284, 0, JSEXN_ERR, "can't set breakpoint: script global is not a debuggee") +MSG_DEF(JSMSG_DEBUG_COMPARTMENT_MISMATCH, 285, 2, JSEXN_TYPEERR, "{0}: descriptor .{1} property is an object in a different compartment than the target object") +MSG_DEF(JSMSG_DEBUG_NOT_SCRIPT_FRAME, 286, 0, JSEXN_ERR, "stack frame is not running JavaScript code") +MSG_DEF(JSMSG_CANT_WATCH_PROP, 287, 0, JSEXN_TYPEERR, "properties whose names are objects can't be watched") +MSG_DEF(JSMSG_CSP_BLOCKED_EVAL, 288, 0, JSEXN_ERR, "call to eval() blocked by CSP") +MSG_DEF(JSMSG_DEBUG_NO_SCOPE_OBJECT, 289, 0, JSEXN_TYPEERR, "declarative Environments don't have binding objects") +MSG_DEF(JSMSG_EMPTY_CONSEQUENT, 290, 0, JSEXN_SYNTAXERR, "mistyped ; after conditional?") +MSG_DEF(JSMSG_NOT_ITERABLE, 291, 1, JSEXN_TYPEERR, "{0} is not iterable") +MSG_DEF(JSMSG_QUERY_LINE_WITHOUT_URL, 292, 0, JSEXN_TYPEERR, "findScripts query object has 'line' property, but no 'url' property") +MSG_DEF(JSMSG_QUERY_INNERMOST_WITHOUT_LINE_URL, 293, 0, JSEXN_TYPEERR, "findScripts query object has 'innermost' property without both 'url' and 'line' properties") +MSG_DEF(JSMSG_DEBUG_VARIABLE_NOT_FOUND, 294, 0, JSEXN_TYPEERR, "variable not found in environment") +MSG_DEF(JSMSG_PARAMETER_AFTER_REST, 295, 0, JSEXN_SYNTAXERR, "parameter after rest parameter") +MSG_DEF(JSMSG_NO_REST_NAME, 296, 0, JSEXN_SYNTAXERR, "no parameter name after ...") +MSG_DEF(JSMSG_ARGUMENTS_AND_REST, 297, 0, JSEXN_SYNTAXERR, "'arguments' object may not be used in conjunction with a rest parameter") +MSG_DEF(JSMSG_FUNCTION_ARGUMENTS_AND_REST, 298, 0, JSEXN_ERR, "the 'arguments' property of a function with a rest parameter may not be used") +MSG_DEF(JSMSG_REST_WITH_DEFAULT, 299, 0, JSEXN_SYNTAXERR, "rest parameter may not have a default") +MSG_DEF(JSMSG_NONDEFAULT_FORMAL_AFTER_DEFAULT, 300, 0, JSEXN_SYNTAXERR, "parameter(s) with default followed by parameter without default") +MSG_DEF(JSMSG_YIELD_IN_DEFAULT, 301, 0, JSEXN_SYNTAXERR, "yield in default expression") +MSG_DEF(JSMSG_INTRINSIC_NOT_DEFINED, 302, 1, JSEXN_REFERENCEERR, "no intrinsic function {0}") +MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 303, 2, JSEXN_NONE, "{0} is being assigned a {1}, but already has one") +MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 304, 0, JSEXN_RANGEERR, "invalid parallel method argument") +MSG_DEF(JSMSG_REGEXP_RUNTIME_ERROR, 305, 0, JSEXN_INTERNALERR, "an error occurred while executing regular expression") +MSG_DEF(JSMSG_DEBUG_OPTIMIZED_OUT, 306, 0, JSEXN_ERR, "variable has been optimized out") +MSG_DEF(JSMSG_NEXT_RETURNED_PRIMITIVE,307, 0, JSEXN_TYPEERR, "iterator.next() returned a non-object value") +MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_CONFLICT, 308, 0, JSEXN_ERR, "no conflict resolution function provided") +MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BOUNDS, 309, 0, JSEXN_ERR, "index in scatter vector out of bounds") +MSG_DEF(JSMSG_CANT_REPORT_NC_AS_NE, 310, 0, JSEXN_TYPEERR, "proxy can't report a non-configurable own property as non-existent") +MSG_DEF(JSMSG_CANT_REPORT_E_AS_NE, 311, 0, JSEXN_TYPEERR, "proxy can't report an existing own property as non-existent on a non-extensible object") +MSG_DEF(JSMSG_CANT_REPORT_NEW, 312, 0, JSEXN_TYPEERR, "proxy can't report a new property on a non-extensible object") +MSG_DEF(JSMSG_CANT_REPORT_INVALID, 313, 0, JSEXN_TYPEERR, "proxy can't report an incompatible property descriptor") +MSG_DEF(JSMSG_CANT_REPORT_NE_AS_NC, 314, 0, JSEXN_TYPEERR, "proxy can't report a non-existent property as non-configurable") +MSG_DEF(JSMSG_CANT_DEFINE_NEW, 315, 0, JSEXN_TYPEERR, "proxy can't define a new property on a non-extensible object") +MSG_DEF(JSMSG_CANT_DEFINE_INVALID, 316, 0, JSEXN_TYPEERR, "proxy can't define an incompatible property descriptor") +MSG_DEF(JSMSG_CANT_DEFINE_NE_AS_NC, 317, 0, JSEXN_TYPEERR, "proxy can't define a non-existent property as non-configurable") +MSG_DEF(JSMSG_INVALID_TRAP_RESULT, 318, 2, JSEXN_TYPEERR, "trap {1} for {0} returned an invalid result") +MSG_DEF(JSMSG_CANT_SKIP_NC, 319, 0, JSEXN_TYPEERR, "proxy can't skip a non-configurable property") +MSG_DEF(JSMSG_MUST_REPORT_SAME_VALUE, 320, 0, JSEXN_TYPEERR, "proxy must report the same value for a non-writable, non-configurable property") +MSG_DEF(JSMSG_MUST_REPORT_UNDEFINED, 321, 0, JSEXN_TYPEERR, "proxy must report undefined for a non-configurable accessor property without a getter") +MSG_DEF(JSMSG_CANT_SET_NW_NC, 322, 0, JSEXN_TYPEERR, "proxy can't successfully set a non-writable, non-configurable property") +MSG_DEF(JSMSG_CANT_SET_WO_SETTER, 323, 0, JSEXN_TYPEERR, "proxy can't succesfully set an accessor property without a setter") +MSG_DEF(JSMSG_DEBUG_BAD_REFERENT, 324, 2, JSEXN_TYPEERR, "{0} does not refer to {1}") +MSG_DEF(JSMSG_DEBUG_WRAPPER_IN_WAY, 325, 3, JSEXN_TYPEERR, "{0} is {1}{2}a global object, but a direct reference is required") +MSG_DEF(JSMSG_UNWRAP_DENIED, 326, 0, JSEXN_ERR, "permission denied to unwrap object") +MSG_DEF(JSMSG_INTL_OBJECT_NOT_INITED, 327, 3, JSEXN_TYPEERR, "Intl.{0}.prototype.{1} called on value that's not an object initialized as a {2}") +MSG_DEF(JSMSG_INVALID_LOCALES_ELEMENT,328, 0, JSEXN_TYPEERR, "invalid element in locales argument") +MSG_DEF(JSMSG_INVALID_LANGUAGE_TAG, 329, 1, JSEXN_RANGEERR, "invalid language tag: {0}") +MSG_DEF(JSMSG_INVALID_LOCALE_MATCHER, 330, 1, JSEXN_RANGEERR, "invalid locale matcher in supportedLocalesOf(): {0}") +MSG_DEF(JSMSG_INVALID_OPTION_VALUE, 331, 2, JSEXN_RANGEERR, "invalid value {1} for option {0}") +MSG_DEF(JSMSG_INVALID_DIGITS_VALUE, 332, 1, JSEXN_RANGEERR, "invalid digits value: {0}") +MSG_DEF(JSMSG_INTL_OBJECT_REINITED, 333, 0, JSEXN_TYPEERR, "can't initialize object twice as an object of an Intl constructor") +MSG_DEF(JSMSG_INVALID_CURRENCY_CODE, 334, 1, JSEXN_RANGEERR, "invalid currency code in NumberFormat(): {0}") +MSG_DEF(JSMSG_UNDEFINED_CURRENCY, 335, 0, JSEXN_TYPEERR, "undefined currency in NumberFormat() with currency style") +MSG_DEF(JSMSG_INVALID_TIME_ZONE, 336, 1, JSEXN_RANGEERR, "invalid time zone in DateTimeFormat(): {0}") +MSG_DEF(JSMSG_DATE_NOT_FINITE, 337, 0, JSEXN_RANGEERR, "date value is not finite in DateTimeFormat.format()") +MSG_DEF(JSMSG_USE_ASM_DIRECTIVE_FAIL, 338, 0, JSEXN_SYNTAXERR, "\"use asm\" is only meaningful in the Directive Prologue of a function body") +MSG_DEF(JSMSG_USE_ASM_TYPE_FAIL, 339, 1, JSEXN_TYPEERR, "asm.js type error: {0}") +MSG_DEF(JSMSG_USE_ASM_LINK_FAIL, 340, 1, JSEXN_TYPEERR, "asm.js link error: {0}") +MSG_DEF(JSMSG_USE_ASM_TYPE_OK, 341, 1, JSEXN_NONE, "Successfully compiled asm.js code ({0})") +MSG_DEF(JSMSG_BAD_ARROW_ARGS, 342, 0, JSEXN_SYNTAXERR, "invalid arrow-function arguments (parentheses around the arrow-function may help)") +MSG_DEF(JSMSG_YIELD_IN_ARROW, 343, 0, JSEXN_SYNTAXERR, "arrow function may not contain yield") +MSG_DEF(JSMSG_WRONG_VALUE, 344, 2, JSEXN_ERR, "expected {0} but found {1}") +MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BAD_TARGET, 345, 1, JSEXN_ERR, "target for index {0} is not an integer") +MSG_DEF(JSMSG_SELFHOSTED_UNBOUND_NAME,346, 0, JSEXN_TYPEERR, "self-hosted code may not contain unbound name lookups") +MSG_DEF(JSMSG_DEPRECATED_PRAGMA, 347, 1, JSEXN_NONE, "Using //@ to indicate {0} pragmas is deprecated. Use //# instead") +MSG_DEF(JSMSG_BAD_DESTRUCT_ASSIGN, 348, 1, JSEXN_SYNTAXERR, "can't assign to {0} using destructuring assignment") +MSG_DEF(JSMSG_TYPEDOBJECT_ARRAYTYPE_BAD_ARGS, 349, 0, JSEXN_ERR, "Invalid arguments") +MSG_DEF(JSMSG_TYPEDOBJECT_BINARYARRAY_BAD_INDEX, 350, 0, JSEXN_RANGEERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_TYPEDOBJECT_STRUCTTYPE_BAD_ARGS, 351, 0, JSEXN_RANGEERR, "invalid field descriptor") +MSG_DEF(JSMSG_TYPEDOBJECT_NOT_BINARYSTRUCT, 352, 1, JSEXN_TYPEERR, "{0} is not a BinaryStruct") +MSG_DEF(JSMSG_TYPEDOBJECT_SUBARRAY_INTEGER_ARG, 353, 1, JSEXN_ERR, "argument {0} must be an integer") +MSG_DEF(JSMSG_TYPEDOBJECT_STRUCTTYPE_EMPTY_DESCRIPTOR, 354, 0, JSEXN_ERR, "field descriptor cannot be empty") +MSG_DEF(JSMSG_TYPEDOBJECT_STRUCTTYPE_BAD_FIELD, 355, 1, JSEXN_ERR, "field {0} is not a valid BinaryData Type descriptor") +MSG_DEF(JSMSG_GENERATOR_FINISHED, 356, 0, JSEXN_TYPEERR, "generator has already finished") +MSG_DEF(JSMSG_TYPEDOBJECT_TOO_BIG, 357, 0, JSEXN_ERR, "Type is too large to allocate") +MSG_DEF(JSMSG_TYPEDOBJECT_NOT_TYPE_OBJECT, 358, 0, JSEXN_ERR, "Expected a type object") +MSG_DEF(JSMSG_TOO_MANY_CON_SPREADARGS, 359, 0, JSEXN_RANGEERR, "too many constructor arguments") +MSG_DEF(JSMSG_TOO_MANY_FUN_SPREADARGS, 360, 0, JSEXN_RANGEERR, "too many function arguments") +MSG_DEF(JSMSG_DEBUG_NOT_DEBUGGEE, 361, 2, JSEXN_ERR, "{0} is not a debuggee {1}") +MSG_DEF(JSMSG_TYPEDOBJECT_NOT_TYPED_OBJECT, 362, 0, JSEXN_ERR, "Expected a typed object") +MSG_DEF(JSMSG_TYPEDOBJECT_NO_SUCH_PROP, 363, 1, JSEXN_TYPEERR, "No such property: {0}") +MSG_DEF(JSMSG_TYPEDOBJECT_BAD_ARGS, 364, 0, JSEXN_TYPEERR, "invalid arguments") +MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_UNATTACHED, 365, 0, JSEXN_TYPEERR, "handle unattached") +MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_BAD_TYPE, 366, 0, JSEXN_TYPEERR, "handle moved to destination of incorrect type") + +MSG_DEF(JSMSG_IMPORT_DECL_AT_TOP_LEVEL, 367, 0, JSEXN_SYNTAXERR, "import declarations may only appear at top level") +MSG_DEF(JSMSG_NO_IMPORT_NAME, 368, 0, JSEXN_SYNTAXERR, "missing import name") +MSG_DEF(JSMSG_AS_AFTER_RESERVED_WORD, 369, 1, JSEXN_SYNTAXERR, "missing keyword 'as' after reserved word '{0}'") +MSG_DEF(JSMSG_NO_BINDING_NAME, 370, 0, JSEXN_SYNTAXERR, "missing binding name") +MSG_DEF(JSMSG_RC_AFTER_IMPORT_SPEC_LIST, 371, 0, JSEXN_SYNTAXERR, "missing '}' after module specifier list") +MSG_DEF(JSMSG_FROM_AFTER_IMPORT_SPEC_SET, 372, 0, JSEXN_SYNTAXERR, "missing keyword 'from' after import specifier set") +MSG_DEF(JSMSG_DECLARATION_AFTER_IMPORT, 373, 0, JSEXN_SYNTAXERR, "missing declaration after 'import' keyword") +MSG_DEF(JSMSG_MODULE_SPEC_AFTER_FROM, 374, 0, JSEXN_SYNTAXERR, "missing module specifier after 'from' keyword") +MSG_DEF(JSMSG_MODULES_NOT_IMPLEMENTED, 375, 0, JSEXN_SYNTAXERR, "modules are not implemented yet") +MSG_DEF(JSMSG_EXPORT_DECL_AT_TOP_LEVEL, 376, 0, JSEXN_SYNTAXERR, "export declarations may only appear at top level") +MSG_DEF(JSMSG_RC_AFTER_EXPORT_SPEC_LIST, 377, 0, JSEXN_SYNTAXERR, "missing '}' after export specifier list") +MSG_DEF(JSMSG_NO_EXPORT_NAME, 378, 0, JSEXN_SYNTAXERR, "missing export name") +MSG_DEF(JSMSG_DECLARATION_AFTER_EXPORT, 379, 0, JSEXN_SYNTAXERR, "missing declaration after 'export' keyword") +MSG_DEF(JSMSG_INVALID_PROTOTYPE, 380, 0, JSEXN_TYPEERR, "prototype field is not an object") +MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_TO_UNSIZED, 381, 0, JSEXN_TYPEERR, "cannot create a handle to an unsized type") +MSG_DEF(JSMSG_SETPROTOTYPEOF_FAIL, 382, 1, JSEXN_TYPEERR, "[[SetPrototypeOf]] failed on {0}") +MSG_DEF(JSMSG_INVALID_ARG_TYPE, 383, 3, JSEXN_TYPEERR, "Invalid type: {0} can't be a{1} {2}") +MSG_DEF(JSMSG_TERMINATED, 384, 1, JSEXN_ERR, "Script terminated by timeout at:\n{0}") +MSG_DEF(JSMSG_NO_SUCH_SELF_HOSTED_PROP, 385, 1, JSEXN_ERR, "No such property on self-hosted object: {0}") +MSG_DEF(JSMSG_PROXY_EXTENSIBILITY, 386, 0, JSEXN_TYPEERR, "proxy must report same extensiblitity as target") +MSG_DEF(JSMSG_PROXY_CONSTRUCT_OBJECT, 387, 0, JSEXN_TYPEERR, "proxy [[Construct]] must return an object") +MSG_DEF(JSMSG_PROXY_GETOWN_OBJORUNDEF, 388, 0, JSEXN_TYPEERR, "proxy [[GetOwnProperty]] must return an object or undefined") +MSG_DEF(JSMSG_CANT_REPORT_C_AS_NC, 389, 0, JSEXN_TYPEERR, "proxy can't report existing configurable property as non-configurable") diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Anchor.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Anchor.h new file mode 100644 index 0000000000..d9ed3fd750 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Anchor.h @@ -0,0 +1,174 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JS::Anchor implementation. */ + +#ifndef js_Anchor_h +#define js_Anchor_h + +#include "mozilla/Attributes.h" + +#include "js/TypeDecls.h" + +namespace JS { + +/* + * Protecting non-Value, non-JSObject *, non-JSString * values from collection + * + * Most of the time, the garbage collector's conservative stack scanner works + * behind the scenes, finding all live values and protecting them from being + * collected. However, when JSAPI client code obtains a pointer to data the + * scanner does not know about, owned by an object the scanner does know about, + * Care Must Be Taken. + * + * The scanner recognizes only a select set of types: pointers to JSObjects and + * similar things (JSFunctions, and so on), pointers to JSStrings, and Values. + * So while the scanner finds all live |JSString| pointers, it does not notice + * |jschar| pointers. + * + * So suppose we have: + * + * void f(JSString *str) { + * const jschar *ch = JS_GetStringCharsZ(str); + * ... do stuff with ch, but no uses of str ...; + * } + * + * After the call to |JS_GetStringCharsZ|, there are no further uses of + * |str|, which means that the compiler is within its rights to not store + * it anywhere. But because the stack scanner will not notice |ch|, there + * is no longer any live value in this frame that would keep the string + * alive. If |str| is the last reference to that |JSString|, and the + * collector runs while we are using |ch|, the string's array of |jschar|s + * may be freed out from under us. + * + * Note that there is only an issue when 1) we extract a thing X the scanner + * doesn't recognize from 2) a thing Y the scanner does recognize, and 3) if Y + * gets garbage-collected, then X gets freed. If we have code like this: + * + * void g(JSObject *obj) { + * JS::Value x; + * JS_GetProperty(obj, "x", &x); + * ... do stuff with x ... + * } + * + * there's no problem, because the value we've extracted, x, is a Value, a + * type that the conservative scanner recognizes. + * + * Conservative GC frees us from the obligation to explicitly root the types it + * knows about, but when we work with derived values like |ch|, we must root + * their owners, as the derived value alone won't keep them alive. + * + * A JS::Anchor is a kind of GC root that allows us to keep the owners of + * derived values like |ch| alive throughout the Anchor's lifetime. We could + * fix the above code as follows: + * + * void f(JSString *str) { + * JS::Anchor a_str(str); + * const jschar *ch = JS_GetStringCharsZ(str); + * ... do stuff with ch, but no uses of str ...; + * } + * + * This simply ensures that |str| will be live until |a_str| goes out of scope. + * As long as we don't retain a pointer to the string's characters for longer + * than that, we have avoided all garbage collection hazards. + */ +template class AnchorPermitted; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; + +template +class Anchor : AnchorPermitted +{ + public: + Anchor() { } + explicit Anchor(T t) { hold = t; } + inline ~Anchor(); + + private: + T hold; + + /* + * Rooting analysis considers use of operator= to be a use of an anchor. + * For simplicity, Anchor is treated as if it contained a GC thing, from + * construction. Thus if we had + * + * void operator=(const T &t) { hold = t; } + * + * and this code + * + * JS::Anchor anchor; + * stuff that could GC, producing |str|; + * anchor = str; + * + * the last line would be seen as a hazard, because the final = would "use" + * |anchor| that is a GC thing -- which could have been moved around by the + * GC. The workaround is to structure your code so that JS::Anchor is + * always constructed, living for however long the corresponding value must + * live. + */ + void operator=(const T &t) MOZ_DELETE; + + Anchor(const Anchor &other) MOZ_DELETE; + void operator=(const Anchor &other) MOZ_DELETE; +}; + +template +inline Anchor::~Anchor() +{ +#ifdef __GNUC__ + /* + * No code is generated for this. But because this is marked 'volatile', G++ will + * assume it has important side-effects, and won't delete it. (G++ never looks at + * the actual text and notices it's empty.) And because we have passed |hold| to + * it, GCC will keep |hold| alive until this point. + * + * The "memory" clobber operand ensures that G++ will not move prior memory + * accesses after the asm --- it's a barrier. Unfortunately, it also means that + * G++ will assume that all memory has changed after the asm, as it would for a + * call to an unknown function. I don't know of a way to avoid that consequence. + */ + asm volatile("":: "g" (hold) : "memory"); +#else + /* + * An adequate portable substitute, for non-structure types. + * + * The compiler promises that, by the end of an expression statement, the + * last-stored value to a volatile object is the same as it would be in an + * unoptimized, direct implementation (the "abstract machine" whose behavior the + * language spec describes). However, the compiler is still free to reorder + * non-volatile accesses across this store --- which is what we must prevent. So + * assigning the held value to a volatile variable, as we do here, is not enough. + * + * In our case, however, garbage collection only occurs at function calls, so it + * is sufficient to ensure that the destructor's store isn't moved earlier across + * any function calls that could collect. It is hard to imagine the compiler + * analyzing the program so thoroughly that it could prove that such motion was + * safe. In practice, compilers treat calls to the collector as opaque operations + * --- in particular, as operations which could access volatile variables, across + * which this destructor must not be moved. + * + * ("Objection, your honor! *Alleged* killer whale!") + * + * The disadvantage of this approach is that it does generate code for the store. + * We do need to use Anchors in some cases where cycles are tight. + * + * Note that there is a Anchor::~Anchor() specialization in Value.h. + */ + volatile T sink; + sink = hold; +#endif /* defined(__GNUC__) */ +} + +} // namespace JS + +#endif /* js_Anchor_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/CallArgs.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/CallArgs.h new file mode 100644 index 0000000000..97a30553f0 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/CallArgs.h @@ -0,0 +1,420 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Helper classes encapsulating access to the callee, |this| value, arguments, + * and argument count for a function call. + * + * The intent of JS::CallArgs and JS::CallReceiver is that they be used to + * encapsulate access to the un-abstracted |unsigned argc, Value *vp| arguments + * to a function. It's possible (albeit deprecated) to manually index into + * |vp| to access the callee, |this|, and arguments of a function, and to set + * its return value. It's also possible to use the supported API of JS_CALLEE, + * JS_THIS, JS_ARGV, JS_RVAL and JS_SET_RVAL to the same ends. But neither API + * has the error-handling or moving-GC correctness of CallArgs or CallReceiver. + * New code should use CallArgs and CallReceiver instead whenever possible. + * + * The eventual plan is to change JSNative to take |const CallArgs&| directly, + * for automatic assertion of correct use and to make calling functions more + * efficient. Embedders should start internally switching away from using + * |argc| and |vp| directly, except to create a |CallArgs|. Then, when an + * eventual release making that change occurs, porting efforts will require + * changing methods' signatures but won't require invasive changes to the + * methods' implementations, potentially under time pressure. + */ + +#ifndef js_CallArgs_h +#define js_CallArgs_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/TypeTraits.h" + +#include "jstypes.h" + +#include "js/RootingAPI.h" +#include "js/Value.h" + +/* Typedef for native functions called by the JS VM. */ +typedef bool +(* JSNative)(JSContext *cx, unsigned argc, JS::Value *vp); + +/* Typedef for native functions that may be called in parallel. */ +typedef bool +(* JSParallelNative)(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); + +/* + * Typedef for native functions that may be called either in parallel or + * sequential execution. + */ +typedef bool +(* JSThreadSafeNative)(js::ThreadSafeContext *cx, unsigned argc, JS::Value *vp); + +/* + * Convenience wrappers for passing in ThreadSafeNative to places that expect + * a JSNative or a JSParallelNative. + */ +template +inline bool +JSNativeThreadSafeWrapper(JSContext *cx, unsigned argc, JS::Value *vp); + +template +inline bool +JSParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, JS::Value *vp); + +/* + * Compute |this| for the |vp| inside a JSNative, either boxing primitives or + * replacing with the global object as necessary. + * + * This method will go away at some point: instead use |args.thisv()|. If the + * value is an object, no further work is required. If that value is |null| or + * |undefined|, use |JS_GetGlobalForObject| to compute the global object. If + * the value is some other primitive, use |JS_ValueToObject| to box it. + */ +extern JS_PUBLIC_API(JS::Value) +JS_ComputeThis(JSContext *cx, JS::Value *vp); + +namespace JS { + +extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; + +/* + * JS::CallReceiver encapsulates access to the callee, |this|, and eventual + * return value for a function call. The principal way to create a + * CallReceiver is using JS::CallReceiverFromVp: + * + * static bool + * FunctionReturningThis(JSContext *cx, unsigned argc, JS::Value *vp) + * { + * JS::CallReceiver rec = JS::CallReceiverFromVp(vp); + * + * // Access to the callee must occur before accessing/setting + * // the return value. + * JSObject &callee = rec.callee(); + * rec.rval().set(JS::ObjectValue(callee)); + * + * // callee() and calleev() will now assert. + * + * // It's always fine to access thisv(). + * HandleValue thisv = rec.thisv(); + * rec.rval().set(thisv); + * + * // As the return value was last set to |this|, returns |this|. + * return true; + * } + * + * A note on JS_ComputeThis and JS_THIS_OBJECT: these methods currently aren't + * part of the CallReceiver interface. We will likely add them at some point. + * Until then, you should probably continue using |vp| directly for these two + * cases. + * + * CallReceiver is exposed publicly and used internally. Not all parts of its + * public interface are meant to be used by embedders! See inline comments to + * for details. + */ + +namespace detail { + +#ifdef JS_DEBUG +extern JS_PUBLIC_API(void) +CheckIsValidConstructible(Value v); +#endif + +enum UsedRval { IncludeUsedRval, NoUsedRval }; + +template +class MOZ_STACK_CLASS UsedRvalBase; + +template<> +class MOZ_STACK_CLASS UsedRvalBase +{ + protected: + mutable bool usedRval_; + void setUsedRval() const { usedRval_ = true; } + void clearUsedRval() const { usedRval_ = false; } +}; + +template<> +class MOZ_STACK_CLASS UsedRvalBase +{ + protected: + void setUsedRval() const {} + void clearUsedRval() const {} +}; + +template +class MOZ_STACK_CLASS CallReceiverBase : public UsedRvalBase< +#ifdef JS_DEBUG + WantUsedRval +#else + NoUsedRval +#endif + > +{ + protected: + Value *argv_; + + public: + /* + * Returns the function being called, as an object. Must not be called + * after rval() has been used! + */ + JSObject &callee() const { + MOZ_ASSERT(!this->usedRval_); + return argv_[-2].toObject(); + } + + /* + * Returns the function being called, as a value. Must not be called after + * rval() has been used! + */ + HandleValue calleev() const { + MOZ_ASSERT(!this->usedRval_); + return HandleValue::fromMarkedLocation(&argv_[-2]); + } + + /* + * Returns the |this| value passed to the function. This method must not + * be called when the function is being called as a constructor via |new|. + * The value may or may not be an object: it is the individual function's + * responsibility to box the value if needed. + */ + HandleValue thisv() const { + // Some internal code uses thisv() in constructing cases, so don't do + // this yet. + // MOZ_ASSERT(!argv_[-1].isMagic(JS_IS_CONSTRUCTING)); + return HandleValue::fromMarkedLocation(&argv_[-1]); + } + + Value computeThis(JSContext *cx) const { + if (thisv().isObject()) + return thisv(); + + return JS_ComputeThis(cx, base()); + } + + bool isConstructing() const { +#ifdef JS_DEBUG + if (this->usedRval_) + CheckIsValidConstructible(calleev()); +#endif + return argv_[-1].isMagic(); + } + + /* + * Returns the currently-set return value. The initial contents of this + * value are unspecified. Once this method has been called, callee() and + * calleev() can no longer be used. (If you're compiling against a debug + * build of SpiderMonkey, these methods will assert to aid debugging.) + * + * If the method you're implementing succeeds by returning true, you *must* + * set this. (SpiderMonkey doesn't currently assert this, but it will do + * so eventually.) You don't need to use or change this if your method + * fails. + */ + MutableHandleValue rval() const { + this->setUsedRval(); + return MutableHandleValue::fromMarkedLocation(&argv_[-2]); + } + + public: + // These methods are only intended for internal use. Embedders shouldn't + // use them! + + Value *base() const { return argv_ - 2; } + + Value *spAfterCall() const { + this->setUsedRval(); + return argv_ - 1; + } + + public: + // These methods are publicly exposed, but they are *not* to be used when + // implementing a JSNative method and encapsulating access to |vp| within + // it. You probably don't want to use these! + + void setCallee(Value aCalleev) const { + this->clearUsedRval(); + argv_[-2] = aCalleev; + } + + void setThis(Value aThisv) const { + argv_[-1] = aThisv; + } + + MutableHandleValue mutableThisv() const { + return MutableHandleValue::fromMarkedLocation(&argv_[-1]); + } +}; + +} // namespace detail + +class MOZ_STACK_CLASS CallReceiver : public detail::CallReceiverBase +{ + private: + friend CallReceiver CallReceiverFromVp(Value *vp); + friend CallReceiver CallReceiverFromArgv(Value *argv); +}; + +MOZ_ALWAYS_INLINE CallReceiver +CallReceiverFromArgv(Value *argv) +{ + CallReceiver receiver; + receiver.clearUsedRval(); + receiver.argv_ = argv; + return receiver; +} + +MOZ_ALWAYS_INLINE CallReceiver +CallReceiverFromVp(Value *vp) +{ + return CallReceiverFromArgv(vp + 2); +} + +/* + * JS::CallArgs encapsulates everything JS::CallReceiver does, plus access to + * the function call's arguments. The principal way to create a CallArgs is + * like so, using JS::CallArgsFromVp: + * + * static bool + * FunctionReturningArgcTimesArg0(JSContext *cx, unsigned argc, JS::Value *vp) + * { + * JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + * + * // Guard against no arguments or a non-numeric arg0. + * if (args.length() == 0 || !args[0].isNumber()) { + * args.rval().setInt32(0); + * return true; + * } + * + * args.rval().set(JS::NumberValue(args.length() * args[0].toNumber())); + * return true; + * } + * + * CallArgs is exposed publicly and used internally. Not all parts of its + * public interface are meant to be used by embedders! See inline comments to + * for details. + */ +namespace detail { + +template +class MOZ_STACK_CLASS CallArgsBase : + public mozilla::Conditional >::Type +{ + protected: + unsigned argc_; + + public: + /* Returns the number of arguments. */ + unsigned length() const { return argc_; } + + /* Returns the i-th zero-indexed argument. */ + MutableHandleValue operator[](unsigned i) const { + MOZ_ASSERT(i < argc_); + return MutableHandleValue::fromMarkedLocation(&this->argv_[i]); + } + + /* + * Returns the i-th zero-indexed argument, or |undefined| if there's no + * such argument. + */ + HandleValue get(unsigned i) const { + return i < length() + ? HandleValue::fromMarkedLocation(&this->argv_[i]) + : UndefinedHandleValue; + } + + /* + * Returns true if the i-th zero-indexed argument is present and is not + * |undefined|. + */ + bool hasDefined(unsigned i) const { + return i < argc_ && !this->argv_[i].isUndefined(); + } + + public: + // These methods are publicly exposed, but we're less sure of the interface + // here than we'd like (because they're hackish and drop assertions). Try + // to avoid using these if you can. + + Value *array() const { return this->argv_; } + Value *end() const { return this->argv_ + argc_; } +}; + +} // namespace detail + +class MOZ_STACK_CLASS CallArgs : public detail::CallArgsBase +{ + private: + friend CallArgs CallArgsFromVp(unsigned argc, Value *vp); + friend CallArgs CallArgsFromSp(unsigned argc, Value *sp); + + static CallArgs create(unsigned argc, Value *argv) { + CallArgs args; + args.clearUsedRval(); + args.argv_ = argv; + args.argc_ = argc; + return args; + } + +}; + +MOZ_ALWAYS_INLINE CallArgs +CallArgsFromVp(unsigned argc, Value *vp) +{ + return CallArgs::create(argc, vp + 2); +} + +// This method is only intended for internal use in SpiderMonkey. We may +// eventually move it to an internal header. Embedders should use +// JS::CallArgsFromVp! +MOZ_ALWAYS_INLINE CallArgs +CallArgsFromSp(unsigned argc, Value *sp) +{ + return CallArgs::create(argc, sp - argc); +} + +} // namespace JS + +/* + * Macros to hide interpreter stack layout details from a JSNative using its + * JS::Value *vp parameter. DO NOT USE THESE! Instead use JS::CallArgs and + * friends, above. These macros will be removed when we change JSNative to + * take a const JS::CallArgs&. + */ + +#define JS_THIS_OBJECT(cx,vp) (JS_THIS(cx,vp).toObjectOrNull()) +#define JS_ARGV(cx,vp) ((vp) + 2) +#define JS_SET_RVAL(cx,vp,v) (*(vp) = (v)) + +/* + * Note: if this method returns null, an error has occurred and must be + * propagated or caught. + */ +MOZ_ALWAYS_INLINE JS::Value +JS_THIS(JSContext *cx, JS::Value *vp) +{ + return vp[1].isPrimitive() ? JS_ComputeThis(cx, vp) : vp[1]; +} + +/* + * |this| is passed to functions in ES5 without change. Functions themselves + * do any post-processing they desire to box |this|, compute the global object, + * &c. This macro retrieves a function's unboxed |this| value. + * + * This macro must not be used in conjunction with JS_THIS or JS_THIS_OBJECT, + * or vice versa. Either use the provided this value with this macro, or + * compute the boxed |this| value using those. JS_THIS_VALUE must not be used + * if the function is being called as a constructor. + * + * But: DO NOT USE THIS! Instead use JS::CallArgs::thisv(), above. + * + */ +#define JS_THIS_VALUE(cx,vp) ((vp)[1]) + +#endif /* js_CallArgs_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/CallNonGenericMethod.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/CallNonGenericMethod.h new file mode 100644 index 0000000000..ad9a7f708c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/CallNonGenericMethod.h @@ -0,0 +1,117 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_CallNonGenericMethod_h +#define js_CallNonGenericMethod_h + +#include "jstypes.h" + +#include "js/CallArgs.h" + +namespace JS { + +// Returns true if |v| is considered an acceptable this-value. +typedef bool (*IsAcceptableThis)(HandleValue v); + +// Implements the guts of a method; guaranteed to be provided an acceptable +// this-value, as determined by a corresponding IsAcceptableThis method. +typedef bool (*NativeImpl)(JSContext *cx, CallArgs args); + +namespace detail { + +// DON'T CALL THIS DIRECTLY. It's for use only by CallNonGenericMethod! +extern JS_PUBLIC_API(bool) +CallMethodIfWrapped(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args); + +} // namespace detail + +// Methods usually act upon |this| objects only from a single global object and +// compartment. Sometimes, however, a method must act upon |this| values from +// multiple global objects or compartments. In such cases the |this| value a +// method might see will be wrapped, such that various access to the object -- +// to its class, its private data, its reserved slots, and so on -- will not +// work properly without entering that object's compartment. This method +// implements a solution to this problem. +// +// To implement a method that accepts |this| values from multiple compartments, +// define two functions. The first function matches the IsAcceptableThis type +// and indicates whether the provided value is an acceptable |this| for the +// method; it must be a pure function only of its argument. +// +// static const JSClass AnswerClass = { ... }; +// +// static bool +// IsAnswerObject(const Value &v) +// { +// if (!v.isObject()) +// return false; +// return JS_GetClass(&v.toObject()) == &AnswerClass; +// } +// +// The second function implements the NativeImpl signature and defines the +// behavior of the method when it is provided an acceptable |this| value. +// Aside from some typing niceties -- see the CallArgs interface for details -- +// its interface is the same as that of JSNative. +// +// static bool +// answer_getAnswer_impl(JSContext *cx, JS::CallArgs args) +// { +// args.rval().setInt32(42); +// return true; +// } +// +// The implementation function is guaranteed to be called *only* with a |this| +// value which is considered acceptable. +// +// Now to implement the actual method, write a JSNative that calls the method +// declared below, passing the appropriate template and runtime arguments. +// +// static bool +// answer_getAnswer(JSContext *cx, unsigned argc, JS::Value *vp) +// { +// JS::CallArgs args = JS::CallArgsFromVp(argc, vp); +// return JS::CallNonGenericMethod(cx, args); +// } +// +// Note that, because they are used as template arguments, the predicate +// and implementation functions must have external linkage. (This is +// unfortunate, but GCC wasn't inlining things as one would hope when we +// passed them as function arguments.) +// +// JS::CallNonGenericMethod will test whether |args.thisv()| is acceptable. If +// it is, it will call the provided implementation function, which will return +// a value and indicate success. If it is not, it will attempt to unwrap +// |this| and call the implementation function on the unwrapped |this|. If +// that succeeds, all well and good. If it doesn't succeed, a TypeError will +// be thrown. +// +// Note: JS::CallNonGenericMethod will only work correctly if it's called in +// tail position in a JSNative. Do not call it from any other place. +// +template +MOZ_ALWAYS_INLINE bool +CallNonGenericMethod(JSContext *cx, CallArgs args) +{ + HandleValue thisv = args.thisv(); + if (Test(thisv)) + return Impl(cx, args); + + return detail::CallMethodIfWrapped(cx, Test, Impl, args); +} + +MOZ_ALWAYS_INLINE bool +CallNonGenericMethod(JSContext *cx, IsAcceptableThis Test, NativeImpl Impl, CallArgs args) +{ + HandleValue thisv = args.thisv(); + if (Test(thisv)) + return Impl(cx, args); + + return detail::CallMethodIfWrapped(cx, Test, Impl, args); +} + +} // namespace JS + +#endif /* js_CallNonGenericMethod_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/CharacterEncoding.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/CharacterEncoding.h new file mode 100644 index 0000000000..45c77761b3 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/CharacterEncoding.h @@ -0,0 +1,226 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_CharacterEncoding_h +#define js_CharacterEncoding_h + +#include "mozilla/NullPtr.h" +#include "mozilla/Range.h" + +#include "js/TypeDecls.h" +#include "js/Utility.h" + +namespace js { +struct ThreadSafeContext; +} + +class JSFlatString; + +namespace JS { + +/* + * By default, all C/C++ 1-byte-per-character strings passed into the JSAPI + * are treated as ISO/IEC 8859-1, also known as Latin-1. That is, each + * byte is treated as a 2-byte character, and there is no way to pass in a + * string containing characters beyond U+00FF. + */ +class Latin1Chars : public mozilla::Range +{ + typedef mozilla::Range Base; + + public: + Latin1Chars() : Base() {} + Latin1Chars(char *aBytes, size_t aLength) : Base(reinterpret_cast(aBytes), aLength) {} + Latin1Chars(const Latin1Char *aBytes, size_t aLength) + : Base(const_cast(aBytes), aLength) + {} + Latin1Chars(const char *aBytes, size_t aLength) + : Base(reinterpret_cast(const_cast(aBytes)), aLength) + {} +}; + +/* + * A Latin1Chars, but with \0 termination for C compatibility. + */ +class Latin1CharsZ : public mozilla::RangedPtr +{ + typedef mozilla::RangedPtr Base; + + public: + Latin1CharsZ() : Base(nullptr, 0) {} + + Latin1CharsZ(char *aBytes, size_t aLength) + : Base(reinterpret_cast(aBytes), aLength) + { + MOZ_ASSERT(aBytes[aLength] == '\0'); + } + + Latin1CharsZ(Latin1Char *aBytes, size_t aLength) + : Base(aBytes, aLength) + { + MOZ_ASSERT(aBytes[aLength] == '\0'); + } + + using Base::operator=; + + char *c_str() { return reinterpret_cast(get()); } +}; + +class UTF8Chars : public mozilla::Range +{ + typedef mozilla::Range Base; + + public: + UTF8Chars() : Base() {} + UTF8Chars(char *aBytes, size_t aLength) + : Base(reinterpret_cast(aBytes), aLength) + {} + UTF8Chars(const char *aBytes, size_t aLength) + : Base(reinterpret_cast(const_cast(aBytes)), aLength) + {} +}; + +/* + * SpiderMonkey also deals directly with UTF-8 encoded text in some places. + */ +class UTF8CharsZ : public mozilla::RangedPtr +{ + typedef mozilla::RangedPtr Base; + + public: + UTF8CharsZ() : Base(nullptr, 0) {} + + UTF8CharsZ(char *aBytes, size_t aLength) + : Base(reinterpret_cast(aBytes), aLength) + { + MOZ_ASSERT(aBytes[aLength] == '\0'); + } + + UTF8CharsZ(unsigned char *aBytes, size_t aLength) + : Base(aBytes, aLength) + { + MOZ_ASSERT(aBytes[aLength] == '\0'); + } + + using Base::operator=; + + char *c_str() { return reinterpret_cast(get()); } +}; + +/* + * SpiderMonkey uses a 2-byte character representation: it is a + * 2-byte-at-a-time view of a UTF-16 byte stream. This is similar to UCS-2, + * but unlike UCS-2, we do not strip UTF-16 extension bytes. This allows a + * sufficiently dedicated JavaScript program to be fully unicode-aware by + * manually interpreting UTF-16 extension characters embedded in the JS + * string. + */ +class TwoByteChars : public mozilla::Range +{ + typedef mozilla::Range Base; + + public: + TwoByteChars() : Base() {} + TwoByteChars(jschar *aChars, size_t aLength) : Base(aChars, aLength) {} + TwoByteChars(const jschar *aChars, size_t aLength) : Base(const_cast(aChars), aLength) {} +}; + +/* + * A TwoByteChars, but \0 terminated for compatibility with JSFlatString. + */ +class TwoByteCharsZ : public mozilla::RangedPtr +{ + typedef mozilla::RangedPtr Base; + + public: + TwoByteCharsZ() : Base(nullptr, 0) {} + + TwoByteCharsZ(jschar *chars, size_t length) + : Base(chars, length) + { + MOZ_ASSERT(chars[length] == '\0'); + } + + using Base::operator=; +}; + +typedef mozilla::RangedPtr ConstCharPtr; + +/* + * Like TwoByteChars, but the chars are const. + */ +class ConstTwoByteChars : public mozilla::RangedPtr +{ + public: + ConstTwoByteChars(const ConstTwoByteChars &s) : ConstCharPtr(s) {} + MOZ_IMPLICIT ConstTwoByteChars(const mozilla::RangedPtr &s) : ConstCharPtr(s) {} + ConstTwoByteChars(const jschar *s, size_t len) : ConstCharPtr(s, len) {} + ConstTwoByteChars(const jschar *pos, const jschar *start, size_t len) + : ConstCharPtr(pos, start, len) + {} + + using ConstCharPtr::operator=; +}; + + +/* + * Convert a 2-byte character sequence to "ISO-Latin-1". This works by + * truncating each 2-byte pair in the sequence to a 1-byte pair. If the source + * contains any UTF-16 extension characters, then this may give invalid Latin1 + * output. The returned string is zero terminated. The returned string or the + * returned string's |start()| must be freed with JS_free or js_free, + * respectively. If allocation fails, an OOM error will be set and the method + * will return a nullptr chars (which can be tested for with the ! operator). + * This method cannot trigger GC. + */ +extern Latin1CharsZ +LossyTwoByteCharsToNewLatin1CharsZ(js::ThreadSafeContext *cx, + const mozilla::Range tbchars); + +template +extern UTF8CharsZ +CharsToNewUTF8CharsZ(js::ThreadSafeContext *cx, const mozilla::Range chars); + +uint32_t +Utf8ToOneUcs4Char(const uint8_t *utf8Buffer, int utf8Length); + +/* + * Inflate bytes in UTF-8 encoding to jschars. + * - On error, returns an empty TwoByteCharsZ. + * - On success, returns a malloc'd TwoByteCharsZ, and updates |outlen| to hold + * its length; the length value excludes the trailing null. + */ +extern TwoByteCharsZ +UTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen); + +/* + * The same as UTF8CharsToNewTwoByteCharsZ(), except that any malformed UTF-8 characters + * will be replaced by \uFFFD. No exception will be thrown for malformed UTF-8 + * input. + */ +extern TwoByteCharsZ +LossyUTF8CharsToNewTwoByteCharsZ(JSContext *cx, const UTF8Chars utf8, size_t *outlen); + +/* + * Returns the length of the char buffer required to encode |s| as UTF8. + * Does not include the null-terminator. + */ +JS_PUBLIC_API(size_t) +GetDeflatedUTF8StringLength(JSFlatString *s); + +/* + * Encode |src| as UTF8. The caller must ensure |dst| has enough space. + * Does not write the null terminator. + */ +JS_PUBLIC_API(void) +DeflateStringToUTF8Buffer(JSFlatString *src, mozilla::RangedPtr dst); + +} // namespace JS + +inline void JS_free(JS::Latin1CharsZ &ptr) { js_free((void*)ptr.get()); } +inline void JS_free(JS::UTF8CharsZ &ptr) { js_free((void*)ptr.get()); } + +#endif /* js_CharacterEncoding_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Class.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Class.h new file mode 100644 index 0000000000..559cc65c85 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Class.h @@ -0,0 +1,544 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JSClass definition and its component types, plus related interfaces. */ + +#ifndef js_Class_h +#define js_Class_h + +#include "mozilla/NullPtr.h" + +#include "jstypes.h" + +#include "js/CallArgs.h" +#include "js/Id.h" +#include "js/TypeDecls.h" + +/* + * A JSClass acts as a vtable for JS objects that allows JSAPI clients to + * control various aspects of the behavior of an object like property lookup. + * js::Class is an engine-private extension that allows more control over + * object behavior and, e.g., allows custom slow layout. + */ + +struct JSFreeOp; +struct JSFunctionSpec; + +namespace js { + +struct Class; +class FreeOp; +class PropertyName; +class Shape; + +// This is equal to JSFunction::class_. Use it in places where you don't want +// to #include jsfun.h. +extern JS_FRIEND_DATA(const js::Class* const) FunctionClassPtr; + +} // namespace js + +// JSClass operation signatures. + +// Add or get a property named by id in obj. Note the jsid id type -- id may +// be a string (Unicode property identifier) or an int (element index). The +// *vp out parameter, on success, is the new property value after the action. +typedef bool +(* JSPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); + +// Set a property named by id in obj, treating the assignment as strict +// mode code if strict is true. Note the jsid id type -- id may be a string +// (Unicode property identifier) or an int (element index). The *vp out +// parameter, on success, is the new property value after the +// set. +typedef bool +(* JSStrictPropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool strict, JS::MutableHandleValue vp); + +// Delete a property named by id in obj. +// +// If an error occurred, return false as per normal JSAPI error practice. +// +// If no error occurred, but the deletion attempt wasn't allowed (perhaps +// because the property was non-configurable), set *succeeded to false and +// return true. This will cause |delete obj[id]| to evaluate to false in +// non-strict mode code, and to throw a TypeError in strict mode code. +// +// If no error occurred and the deletion wasn't disallowed (this is *not* the +// same as saying that a deletion actually occurred -- deleting a non-existent +// property, or an inherited property, is allowed -- it's just pointless), +// set *succeeded to true and return true. +typedef bool +(* JSDeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *succeeded); + +// This function type is used for callbacks that enumerate the properties of +// a JSObject. The behavior depends on the value of enum_op: +// +// JSENUMERATE_INIT +// A new, opaque iterator state should be allocated and stored in *statep. +// (You can use PRIVATE_TO_JSVAL() to tag the pointer to be stored). +// +// The number of properties that will be enumerated should be returned as +// an integer jsval in *idp, if idp is non-null, and provided the number of +// enumerable properties is known. If idp is non-null and the number of +// enumerable properties can't be computed in advance, *idp should be set +// to JSVAL_ZERO. +// +// JSENUMERATE_INIT_ALL +// Used identically to JSENUMERATE_INIT, but exposes all properties of the +// object regardless of enumerability. +// +// JSENUMERATE_NEXT +// A previously allocated opaque iterator state is passed in via statep. +// Return the next jsid in the iteration using *idp. The opaque iterator +// state pointed at by statep is destroyed and *statep is set to JSVAL_NULL +// if there are no properties left to enumerate. +// +// JSENUMERATE_DESTROY +// Destroy the opaque iterator state previously allocated in *statep by a +// call to this function when enum_op was JSENUMERATE_INIT or +// JSENUMERATE_INIT_ALL. +// +// The return value is used to indicate success, with a value of false +// indicating failure. +typedef bool +(* JSNewEnumerateOp)(JSContext *cx, JS::HandleObject obj, JSIterateOp enum_op, + JS::MutableHandleValue statep, JS::MutableHandleId idp); + +// The old-style JSClass.enumerate op should define all lazy properties not +// yet reflected in obj. +typedef bool +(* JSEnumerateOp)(JSContext *cx, JS::HandleObject obj); + +// Resolve a lazy property named by id in obj by defining it directly in obj. +// Lazy properties are those reflected from some peer native property space +// (e.g., the DOM attributes for a given node reflected as obj) on demand. +// +// JS looks for a property in an object, and if not found, tries to resolve +// the given id. If resolve succeeds, the engine looks again in case resolve +// defined obj[id]. If no such property exists directly in obj, the process +// is repeated with obj's prototype, etc. +// +// NB: JSNewResolveOp provides a cheaper way to resolve lazy properties. +typedef bool +(* JSResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); + +// Like JSResolveOp, except the *objp out parameter, on success, should be null +// to indicate that id was not resolved; and non-null, referring to obj or one +// of its prototypes, if id was resolved. The hook may assume *objp is null on +// entry. +// +// This hook instead of JSResolveOp is called via the JSClass.resolve member +// if JSCLASS_NEW_RESOLVE is set in JSClass.flags. +typedef bool +(* JSNewResolveOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleObject objp); + +// Convert obj to the given type, returning true with the resulting value in +// *vp on success, and returning false on error or exception. +typedef bool +(* JSConvertOp)(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); + +// Finalize obj, which the garbage collector has determined to be unreachable +// from other live objects or from GC roots. Obviously, finalizers must never +// store a reference to obj. +typedef void +(* JSFinalizeOp)(JSFreeOp *fop, JSObject *obj); + +// Finalizes external strings created by JS_NewExternalString. +struct JSStringFinalizer { + void (*finalize)(const JSStringFinalizer *fin, jschar *chars); +}; + +// Check whether v is an instance of obj. Return false on error or exception, +// true on success with true in *bp if v is an instance of obj, false in +// *bp otherwise. +typedef bool +(* JSHasInstanceOp)(JSContext *cx, JS::HandleObject obj, JS::MutableHandleValue vp, + bool *bp); + +// Function type for trace operation of the class called to enumerate all +// traceable things reachable from obj's private data structure. For each such +// thing, a trace implementation must call one of the JS_Call*Tracer variants +// on the thing. +// +// JSTraceOp implementation can assume that no other threads mutates object +// state. It must not change state of the object or corresponding native +// structures. The only exception for this rule is the case when the embedding +// needs a tight integration with GC. In that case the embedding can check if +// the traversal is a part of the marking phase through calling +// JS_IsGCMarkingTracer and apply a special code like emptying caches or +// marking its native structures. +typedef void +(* JSTraceOp)(JSTracer *trc, JSObject *obj); + +// Hook that creates an iterator object for a given object. Returns the +// iterator object or null if an error or exception was thrown on cx. +typedef JSObject * +(* JSIteratorOp)(JSContext *cx, JS::HandleObject obj, bool keysonly); + +typedef JSObject * +(* JSWeakmapKeyDelegateOp)(JSObject *obj); + +/* js::Class operation signatures. */ + +namespace js { + +typedef bool +(* LookupGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleObject objp, JS::MutableHandle propp); +typedef bool +(* LookupPropOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleObject objp, JS::MutableHandle propp); +typedef bool +(* LookupElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::MutableHandleObject objp, JS::MutableHandle propp); +typedef bool +(* DefineGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +typedef bool +(* DefinePropOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, + unsigned attrs); +typedef bool +(* DefineElementOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +typedef bool +(* GenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, + JS::MutableHandleValue vp); +typedef bool +(* PropertyIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, + JS::Handle name, JS::MutableHandleValue vp); +typedef bool +(* ElementIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, + JS::MutableHandleValue vp); +typedef bool +(* StrictGenericIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp, bool strict); +typedef bool +(* StrictPropertyIdOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleValue vp, bool strict); +typedef bool +(* StrictElementIdOp)(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::MutableHandleValue vp, bool strict); +typedef bool +(* GenericAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +typedef bool +(* PropertyAttributesOp)(JSContext *cx, JS::HandleObject obj, JS::Handle name, + unsigned *attrsp); +typedef bool +(* DeleteGenericOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); + +typedef bool +(* WatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); + +typedef bool +(* UnwatchOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id); + +typedef bool +(* SliceOp)(JSContext *cx, JS::HandleObject obj, uint32_t begin, uint32_t end, + JS::HandleObject result); // result is actually preallocted. + +// A generic type for functions mapping an object to another object, or null +// if an error or exception was thrown on cx. +typedef JSObject * +(* ObjectOp)(JSContext *cx, JS::HandleObject obj); + +// Hook to map an object to its inner object. Infallible. +typedef JSObject * +(* InnerObjectOp)(JSObject *obj); + +typedef void +(* FinalizeOp)(FreeOp *fop, JSObject *obj); + +#define JS_CLASS_MEMBERS(FinalizeOpType) \ + const char *name; \ + uint32_t flags; \ + \ + /* Mandatory function pointer members. */ \ + JSPropertyOp addProperty; \ + JSDeletePropertyOp delProperty; \ + JSPropertyOp getProperty; \ + JSStrictPropertyOp setProperty; \ + JSEnumerateOp enumerate; \ + JSResolveOp resolve; \ + JSConvertOp convert; \ + \ + /* Optional members (may be null). */ \ + FinalizeOpType finalize; \ + JSNative call; \ + JSHasInstanceOp hasInstance; \ + JSNative construct; \ + JSTraceOp trace + +// Callback for the creation of constructor and prototype objects. +typedef JSObject *(*ClassObjectCreationOp)(JSContext *cx, JSProtoKey key); + +// Callback for custom post-processing after class initialization via ClassSpec. +typedef bool (*FinishClassInitOp)(JSContext *cx, JS::HandleObject ctor, + JS::HandleObject proto); + +struct ClassSpec +{ + ClassObjectCreationOp createConstructor; + ClassObjectCreationOp createPrototype; + const JSFunctionSpec *constructorFunctions; + const JSFunctionSpec *prototypeFunctions; + const JSPropertySpec *prototypeProperties; + FinishClassInitOp finishInit; + bool defined() const { return !!createConstructor; } +}; + +struct ClassExtension +{ + ObjectOp outerObject; + InnerObjectOp innerObject; + JSIteratorOp iteratorObject; + + /* + * isWrappedNative is true only if the class is an XPCWrappedNative. + * WeakMaps use this to override the wrapper disposal optimization. + */ + bool isWrappedNative; + + /* + * If an object is used as a key in a weakmap, it may be desirable for the + * garbage collector to keep that object around longer than it otherwise + * would. A common case is when the key is a wrapper around an object in + * another compartment, and we want to avoid collecting the wrapper (and + * removing the weakmap entry) as long as the wrapped object is alive. In + * that case, the wrapped object is returned by the wrapper's + * weakmapKeyDelegateOp hook. As long as the wrapper is used as a weakmap + * key, it will not be collected (and remain in the weakmap) until the + * wrapped object is collected. + */ + JSWeakmapKeyDelegateOp weakmapKeyDelegateOp; +}; + +#define JS_NULL_CLASS_SPEC {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr} +#define JS_NULL_CLASS_EXT {nullptr,nullptr,nullptr,false,nullptr} + +struct ObjectOps +{ + LookupGenericOp lookupGeneric; + LookupPropOp lookupProperty; + LookupElementOp lookupElement; + DefineGenericOp defineGeneric; + DefinePropOp defineProperty; + DefineElementOp defineElement; + GenericIdOp getGeneric; + PropertyIdOp getProperty; + ElementIdOp getElement; + StrictGenericIdOp setGeneric; + StrictPropertyIdOp setProperty; + StrictElementIdOp setElement; + GenericAttributesOp getGenericAttributes; + GenericAttributesOp setGenericAttributes; + DeleteGenericOp deleteGeneric; + WatchOp watch; + UnwatchOp unwatch; + SliceOp slice; // Optimized slice, can be null. + JSNewEnumerateOp enumerate; + ObjectOp thisObject; +}; + +#define JS_NULL_OBJECT_OPS \ + {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \ + nullptr, nullptr, nullptr} + +} // namespace js + +// Classes, objects, and properties. + +typedef void (*JSClassInternal)(); + +struct JSClass { + JS_CLASS_MEMBERS(JSFinalizeOp); + + void *reserved[31]; +}; + +#define JSCLASS_HAS_PRIVATE (1<<0) // objects have private slot +#define JSCLASS_NEW_ENUMERATE (1<<1) // has JSNewEnumerateOp hook +#define JSCLASS_NEW_RESOLVE (1<<2) // has JSNewResolveOp hook +#define JSCLASS_PRIVATE_IS_NSISUPPORTS (1<<3) // private is (nsISupports *) +#define JSCLASS_IS_DOMJSCLASS (1<<4) // objects are DOM +#define JSCLASS_IMPLEMENTS_BARRIERS (1<<5) // Correctly implements GC read + // and write barriers +#define JSCLASS_EMULATES_UNDEFINED (1<<6) // objects of this class act + // like the value undefined, + // in some contexts +#define JSCLASS_USERBIT1 (1<<7) // Reserved for embeddings. + +// To reserve slots fetched and stored via JS_Get/SetReservedSlot, bitwise-or +// JSCLASS_HAS_RESERVED_SLOTS(n) into the initializer for JSClass.flags, where +// n is a constant in [1, 255]. Reserved slots are indexed from 0 to n-1. +#define JSCLASS_RESERVED_SLOTS_SHIFT 8 // room for 8 flags below */ +#define JSCLASS_RESERVED_SLOTS_WIDTH 8 // and 16 above this field */ +#define JSCLASS_RESERVED_SLOTS_MASK JS_BITMASK(JSCLASS_RESERVED_SLOTS_WIDTH) +#define JSCLASS_HAS_RESERVED_SLOTS(n) (((n) & JSCLASS_RESERVED_SLOTS_MASK) \ + << JSCLASS_RESERVED_SLOTS_SHIFT) +#define JSCLASS_RESERVED_SLOTS(clasp) (((clasp)->flags \ + >> JSCLASS_RESERVED_SLOTS_SHIFT) \ + & JSCLASS_RESERVED_SLOTS_MASK) + +#define JSCLASS_HIGH_FLAGS_SHIFT (JSCLASS_RESERVED_SLOTS_SHIFT + \ + JSCLASS_RESERVED_SLOTS_WIDTH) + +#define JSCLASS_IS_ANONYMOUS (1<<(JSCLASS_HIGH_FLAGS_SHIFT+0)) +#define JSCLASS_IS_GLOBAL (1<<(JSCLASS_HIGH_FLAGS_SHIFT+1)) +#define JSCLASS_INTERNAL_FLAG2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2)) +#define JSCLASS_INTERNAL_FLAG3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3)) + +#define JSCLASS_IS_PROXY (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4)) + +// Bit 22 unused. + +// Reserved for embeddings. +#define JSCLASS_USERBIT2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+6)) +#define JSCLASS_USERBIT3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+7)) + +#define JSCLASS_BACKGROUND_FINALIZE (1<<(JSCLASS_HIGH_FLAGS_SHIFT+8)) + +// Bits 26 through 31 are reserved for the CACHED_PROTO_KEY mechanism, see +// below. + +// ECMA-262 requires that most constructors used internally create objects +// with "the original Foo.prototype value" as their [[Prototype]] (__proto__) +// member initial value. The "original ... value" verbiage is there because +// in ECMA-262, global properties naming class objects are read/write and +// deleteable, for the most part. +// +// Implementing this efficiently requires that global objects have classes +// with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS was +// previously allowed, but is now an ES5 violation and thus unsupported. +// +// JSCLASS_GLOBAL_APPLICATION_SLOTS is the number of slots reserved at +// the beginning of every global object's slots for use by the +// application. +#define JSCLASS_GLOBAL_APPLICATION_SLOTS 3 +#define JSCLASS_GLOBAL_SLOT_COUNT (JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 3 + 30) +#define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n) \ + (JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + (n))) +#define JSCLASS_GLOBAL_FLAGS \ + JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(0) +#define JSCLASS_HAS_GLOBAL_FLAG_AND_SLOTS(clasp) \ + (((clasp)->flags & JSCLASS_IS_GLOBAL) \ + && JSCLASS_RESERVED_SLOTS(clasp) >= JSCLASS_GLOBAL_SLOT_COUNT) + +// Fast access to the original value of each standard class's prototype. +#define JSCLASS_CACHED_PROTO_SHIFT (JSCLASS_HIGH_FLAGS_SHIFT + 10) +#define JSCLASS_CACHED_PROTO_WIDTH 6 +#define JSCLASS_CACHED_PROTO_MASK JS_BITMASK(JSCLASS_CACHED_PROTO_WIDTH) +#define JSCLASS_HAS_CACHED_PROTO(key) (uint32_t(key) << JSCLASS_CACHED_PROTO_SHIFT) +#define JSCLASS_CACHED_PROTO_KEY(clasp) ((JSProtoKey) \ + (((clasp)->flags \ + >> JSCLASS_CACHED_PROTO_SHIFT) \ + & JSCLASS_CACHED_PROTO_MASK)) + +// Initializer for unused members of statically initialized JSClass structs. +#define JSCLASS_NO_INTERNAL_MEMBERS {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} +#define JSCLASS_NO_OPTIONAL_MEMBERS 0,0,0,0,0,JSCLASS_NO_INTERNAL_MEMBERS + +namespace js { + +struct Class +{ + JS_CLASS_MEMBERS(FinalizeOp); + ClassSpec spec; + ClassExtension ext; + ObjectOps ops; + + /* Class is not native and its map is not a scope. */ + static const uint32_t NON_NATIVE = JSCLASS_INTERNAL_FLAG2; + + bool isNative() const { + return !(flags & NON_NATIVE); + } + + bool hasPrivate() const { + return !!(flags & JSCLASS_HAS_PRIVATE); + } + + bool emulatesUndefined() const { + return flags & JSCLASS_EMULATES_UNDEFINED; + } + + bool isJSFunction() const { + return this == js::FunctionClassPtr; + } + + bool isCallable() const { + return isJSFunction() || call; + } + + bool isProxy() const { + return flags & JSCLASS_IS_PROXY; + } + + bool isDOMClass() const { + return flags & JSCLASS_IS_DOMJSCLASS; + } + + static size_t offsetOfFlags() { return offsetof(Class, flags); } +}; + +JS_STATIC_ASSERT(offsetof(JSClass, name) == offsetof(Class, name)); +JS_STATIC_ASSERT(offsetof(JSClass, flags) == offsetof(Class, flags)); +JS_STATIC_ASSERT(offsetof(JSClass, addProperty) == offsetof(Class, addProperty)); +JS_STATIC_ASSERT(offsetof(JSClass, delProperty) == offsetof(Class, delProperty)); +JS_STATIC_ASSERT(offsetof(JSClass, getProperty) == offsetof(Class, getProperty)); +JS_STATIC_ASSERT(offsetof(JSClass, setProperty) == offsetof(Class, setProperty)); +JS_STATIC_ASSERT(offsetof(JSClass, enumerate) == offsetof(Class, enumerate)); +JS_STATIC_ASSERT(offsetof(JSClass, resolve) == offsetof(Class, resolve)); +JS_STATIC_ASSERT(offsetof(JSClass, convert) == offsetof(Class, convert)); +JS_STATIC_ASSERT(offsetof(JSClass, finalize) == offsetof(Class, finalize)); +JS_STATIC_ASSERT(offsetof(JSClass, call) == offsetof(Class, call)); +JS_STATIC_ASSERT(offsetof(JSClass, construct) == offsetof(Class, construct)); +JS_STATIC_ASSERT(offsetof(JSClass, hasInstance) == offsetof(Class, hasInstance)); +JS_STATIC_ASSERT(offsetof(JSClass, trace) == offsetof(Class, trace)); +JS_STATIC_ASSERT(sizeof(JSClass) == sizeof(Class)); + +static MOZ_ALWAYS_INLINE const JSClass * +Jsvalify(const Class *c) +{ + return (const JSClass *)c; +} + +static MOZ_ALWAYS_INLINE const Class * +Valueify(const JSClass *c) +{ + return (const Class *)c; +} + +/* + * Enumeration describing possible values of the [[Class]] internal property + * value of objects. + */ +enum ESClassValue { + ESClass_Array, ESClass_Number, ESClass_String, ESClass_Boolean, + ESClass_RegExp, ESClass_ArrayBuffer, ESClass_Date +}; + +/* + * Return whether the given object has the given [[Class]] internal property + * value. Beware, this query says nothing about the js::Class of the JSObject + * so the caller must not assume anything about obj's representation (e.g., obj + * may be a proxy). + */ +inline bool +ObjectClassIs(JSObject &obj, ESClassValue classValue, JSContext *cx); + +/* Just a helper that checks v.isObject before calling ObjectClassIs. */ +inline bool +IsObjectWithClass(const JS::Value &v, ESClassValue classValue, JSContext *cx); + +} /* namespace js */ + +#endif /* js_Class_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Date.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Date.h new file mode 100644 index 0000000000..6199f9eca5 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Date.h @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_Date_h +#define js_Date_h + +#include "jstypes.h" + +namespace JS { + +// Year is a year, month is 0-11, day is 1-based. The return value is +// a number of milliseconds since the epoch. Can return NaN. +JS_PUBLIC_API(double) +MakeDate(double year, unsigned month, unsigned day); + +// Takes an integer number of milliseconds since the epoch and returns the +// year. Can return NaN, and will do so if NaN is passed in. +JS_PUBLIC_API(double) +YearFromTime(double time); + +// Takes an integer number of milliseconds since the epoch and returns the +// month (0-11). Can return NaN, and will do so if NaN is passed in. +JS_PUBLIC_API(double) +MonthFromTime(double time); + +// Takes an integer number of milliseconds since the epoch and returns the +// day (1-based). Can return NaN, and will do so if NaN is passed in. +JS_PUBLIC_API(double) +DayFromTime(double time); + +} // namespace JS + +#endif /* js_Date_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/GCAPI.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/GCAPI.h new file mode 100644 index 0000000000..c58d62d029 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/GCAPI.h @@ -0,0 +1,514 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_GCAPI_h +#define js_GCAPI_h + +#include "mozilla/NullPtr.h" + +#include "js/HeapAPI.h" + +namespace js { +namespace gc { +class GCRuntime; +} +} + +typedef enum JSGCMode { + /* Perform only global GCs. */ + JSGC_MODE_GLOBAL = 0, + + /* Perform per-compartment GCs until too much garbage has accumulated. */ + JSGC_MODE_COMPARTMENT = 1, + + /* + * Collect in short time slices rather than all at once. Implies + * JSGC_MODE_COMPARTMENT. + */ + JSGC_MODE_INCREMENTAL = 2 +} JSGCMode; + +namespace JS { + +#define GCREASONS(D) \ + /* Reasons internal to the JS engine */ \ + D(API) \ + D(MAYBEGC) \ + D(DESTROY_RUNTIME) \ + D(DESTROY_CONTEXT) \ + D(LAST_DITCH) \ + D(TOO_MUCH_MALLOC) \ + D(ALLOC_TRIGGER) \ + D(DEBUG_GC) \ + D(TRANSPLANT) \ + D(RESET) \ + D(OUT_OF_NURSERY) \ + D(EVICT_NURSERY) \ + D(FULL_STORE_BUFFER) \ + \ + /* These are reserved for future use. */ \ + D(RESERVED0) \ + D(RESERVED1) \ + D(RESERVED2) \ + D(RESERVED3) \ + D(RESERVED4) \ + D(RESERVED5) \ + D(RESERVED6) \ + D(RESERVED7) \ + D(RESERVED8) \ + D(RESERVED9) \ + D(RESERVED10) \ + D(RESERVED11) \ + D(RESERVED12) \ + D(RESERVED13) \ + D(RESERVED14) \ + D(RESERVED15) \ + D(RESERVED16) \ + D(RESERVED17) \ + D(RESERVED18) \ + D(RESERVED19) \ + \ + /* Reasons from Firefox */ \ + D(DOM_WINDOW_UTILS) \ + D(COMPONENT_UTILS) \ + D(MEM_PRESSURE) \ + D(CC_WAITING) \ + D(CC_FORCED) \ + D(LOAD_END) \ + D(POST_COMPARTMENT) \ + D(PAGE_HIDE) \ + D(NSJSCONTEXT_DESTROY) \ + D(SET_NEW_DOCUMENT) \ + D(SET_DOC_SHELL) \ + D(DOM_UTILS) \ + D(DOM_IPC) \ + D(DOM_WORKER) \ + D(INTER_SLICE_GC) \ + D(REFRESH_FRAME) \ + D(FULL_GC_TIMER) \ + D(SHUTDOWN_CC) \ + D(FINISH_LARGE_EVALUTE) + +namespace gcreason { + +/* GCReasons will end up looking like JSGC_MAYBEGC */ +enum Reason { +#define MAKE_REASON(name) name, + GCREASONS(MAKE_REASON) +#undef MAKE_REASON + NO_REASON, + NUM_REASONS, + + /* + * For telemetry, we want to keep a fixed max bucket size over time so we + * don't have to switch histograms. 100 is conservative; as of this writing + * there are 26. But the cost of extra buckets seems to be low while the + * cost of switching histograms is high. + */ + NUM_TELEMETRY_REASONS = 100 +}; + +} /* namespace gcreason */ + +/* + * Zone GC: + * + * SpiderMonkey's GC is capable of performing a collection on an arbitrary + * subset of the zones in the system. This allows an embedding to minimize + * collection time by only collecting zones that have run code recently, + * ignoring the parts of the heap that are unlikely to have changed. + * + * When triggering a GC using one of the functions below, it is first necessary + * to select the zones to be collected. To do this, you can call + * PrepareZoneForGC on each zone, or you can call PrepareForFullGC to select + * all zones. Failing to select any zone is an error. + */ + +/* + * Schedule the given zone to be collected as part of the next GC. + */ +extern JS_FRIEND_API(void) +PrepareZoneForGC(Zone *zone); + +/* + * Schedule all zones to be collected in the next GC. + */ +extern JS_FRIEND_API(void) +PrepareForFullGC(JSRuntime *rt); + +/* + * When performing an incremental GC, the zones that were selected for the + * previous incremental slice must be selected in subsequent slices as well. + * This function selects those slices automatically. + */ +extern JS_FRIEND_API(void) +PrepareForIncrementalGC(JSRuntime *rt); + +/* + * Returns true if any zone in the system has been scheduled for GC with one of + * the functions above or by the JS engine. + */ +extern JS_FRIEND_API(bool) +IsGCScheduled(JSRuntime *rt); + +/* + * Undoes the effect of the Prepare methods above. The given zone will not be + * collected in the next GC. + */ +extern JS_FRIEND_API(void) +SkipZoneForGC(Zone *zone); + +/* + * Non-Incremental GC: + * + * The following functions perform a non-incremental GC. + */ + +/* + * Performs a non-incremental collection of all selected zones. Some objects + * that are unreachable from the program may still be alive afterwards because + * of internal references. + */ +extern JS_FRIEND_API(void) +GCForReason(JSRuntime *rt, gcreason::Reason reason); + +/* + * Perform a non-incremental collection after clearing caches and other + * temporary references to objects. This will remove all unreferenced objects + * in the system. + */ +extern JS_FRIEND_API(void) +ShrinkingGC(JSRuntime *rt, gcreason::Reason reason); + +/* + * Incremental GC: + * + * Incremental GC divides the full mark-and-sweep collection into multiple + * slices, allowing client JavaScript code to run between each slice. This + * allows interactive apps to avoid long collection pauses. Incremental GC does + * not make collection take less time, it merely spreads that time out so that + * the pauses are less noticable. + * + * For a collection to be carried out incrementally the following conditions + * must be met: + * - The collection must be run by calling JS::IncrementalGC() rather than + * JS_GC(). + * - The GC mode must have been set to JSGC_MODE_INCREMENTAL with + * JS_SetGCParameter(). + * - All native objects that have their own trace hook must indicate that they + * implement read and write barriers with the JSCLASS_IMPLEMENTS_BARRIERS + * flag. + * + * Note: Even if incremental GC is enabled and working correctly, + * non-incremental collections can still happen when low on memory. + */ + +/* + * Begin an incremental collection and perform one slice worth of work or + * perform a slice of an ongoing incremental collection. When this function + * returns, the collection is not complete. This function must be called + * repeatedly until !IsIncrementalGCInProgress(rt). + * + * Note: SpiderMonkey's GC is not realtime. Slices in practice may be longer or + * shorter than the requested interval. + */ +extern JS_FRIEND_API(void) +IncrementalGC(JSRuntime *rt, gcreason::Reason reason, int64_t millis = 0); + +/* + * If IsIncrementalGCInProgress(rt), this call finishes the ongoing collection + * by performing an arbitrarily long slice. If !IsIncrementalGCInProgress(rt), + * this is equivalent to GCForReason. When this function returns, + * IsIncrementalGCInProgress(rt) will always be false. + */ +extern JS_FRIEND_API(void) +FinishIncrementalGC(JSRuntime *rt, gcreason::Reason reason); + +enum GCProgress { + /* + * During non-incremental GC, the GC is bracketed by JSGC_CYCLE_BEGIN/END + * callbacks. During an incremental GC, the sequence of callbacks is as + * follows: + * JSGC_CYCLE_BEGIN, JSGC_SLICE_END (first slice) + * JSGC_SLICE_BEGIN, JSGC_SLICE_END (second slice) + * ... + * JSGC_SLICE_BEGIN, JSGC_CYCLE_END (last slice) + */ + + GC_CYCLE_BEGIN, + GC_SLICE_BEGIN, + GC_SLICE_END, + GC_CYCLE_END +}; + +struct JS_FRIEND_API(GCDescription) { + bool isCompartment_; + + explicit GCDescription(bool isCompartment) + : isCompartment_(isCompartment) {} + + jschar *formatMessage(JSRuntime *rt) const; + jschar *formatJSON(JSRuntime *rt, uint64_t timestamp) const; +}; + +typedef void +(* GCSliceCallback)(JSRuntime *rt, GCProgress progress, const GCDescription &desc); + +/* + * The GC slice callback is called at the beginning and end of each slice. This + * callback may be used for GC notifications as well as to perform additional + * marking. + */ +extern JS_FRIEND_API(GCSliceCallback) +SetGCSliceCallback(JSRuntime *rt, GCSliceCallback callback); + +/* + * Incremental GC defaults to enabled, but may be disabled for testing or in + * embeddings that have not yet implemented barriers on their native classes. + * There is not currently a way to re-enable incremental GC once it has been + * disabled on the runtime. + */ +extern JS_FRIEND_API(void) +DisableIncrementalGC(JSRuntime *rt); + +/* + * Returns true if incremental GC is enabled. Simply having incremental GC + * enabled is not sufficient to ensure incremental collections are happening. + * See the comment "Incremental GC" above for reasons why incremental GC may be + * suppressed. Inspection of the "nonincremental reason" field of the + * GCDescription returned by GCSliceCallback may help narrow down the cause if + * collections are not happening incrementally when expected. + */ +extern JS_FRIEND_API(bool) +IsIncrementalGCEnabled(JSRuntime *rt); + +/* + * Returns true while an incremental GC is ongoing, both when actively + * collecting and between slices. + */ +JS_FRIEND_API(bool) +IsIncrementalGCInProgress(JSRuntime *rt); + +/* + * Returns true when writes to GC things must call an incremental (pre) barrier. + * This is generally only true when running mutator code in-between GC slices. + * At other times, the barrier may be elided for performance. + */ +extern JS_FRIEND_API(bool) +IsIncrementalBarrierNeeded(JSRuntime *rt); + +extern JS_FRIEND_API(bool) +IsIncrementalBarrierNeeded(JSContext *cx); + +/* + * Notify the GC that a reference to a GC thing is about to be overwritten. + * These methods must be called if IsIncrementalBarrierNeeded. + */ +extern JS_FRIEND_API(void) +IncrementalReferenceBarrier(void *ptr, JSGCTraceKind kind); + +extern JS_FRIEND_API(void) +IncrementalValueBarrier(const Value &v); + +extern JS_FRIEND_API(void) +IncrementalObjectBarrier(JSObject *obj); + +/* + * Returns true if the most recent GC ran incrementally. + */ +extern JS_FRIEND_API(bool) +WasIncrementalGC(JSRuntime *rt); + +/* + * Generational GC: + * + * Note: Generational GC is not yet enabled by default. The following class + * is non-functional unless SpiderMonkey was configured with + * --enable-gcgenerational. + */ + +/* Ensure that generational GC is disabled within some scope. */ +class JS_FRIEND_API(AutoDisableGenerationalGC) +{ + js::gc::GCRuntime *gc; +#if defined(JSGC_GENERATIONAL) && defined(JS_GC_ZEAL) + bool restartVerifier; +#endif + + public: + explicit AutoDisableGenerationalGC(JSRuntime *rt); + ~AutoDisableGenerationalGC(); +}; + +/* + * Returns true if generational allocation and collection is currently enabled + * on the given runtime. + */ +extern JS_FRIEND_API(bool) +IsGenerationalGCEnabled(JSRuntime *rt); + +/* + * Returns the GC's "number". This does not correspond directly to the number + * of GCs that have been run, but is guaranteed to be monotonically increasing + * with GC activity. + */ +extern JS_FRIEND_API(size_t) +GetGCNumber(); + +/* + * The GC does not immediately return the unused memory freed by a collection + * back to the system incase it is needed soon afterwards. This call forces the + * GC to return this memory immediately. + */ +extern JS_FRIEND_API(void) +ShrinkGCBuffers(JSRuntime *rt); + +/* + * Assert if a GC occurs while this class is live. This class does not disable + * the static rooting hazard analysis. + */ +class JS_PUBLIC_API(AutoAssertOnGC) +{ +#ifdef DEBUG + js::gc::GCRuntime *gc; + size_t gcNumber; + + public: + AutoAssertOnGC(); + explicit AutoAssertOnGC(JSRuntime *rt); + ~AutoAssertOnGC(); + + static void VerifyIsSafeToGC(JSRuntime *rt); +#else + public: + AutoAssertOnGC() {} + explicit AutoAssertOnGC(JSRuntime *rt) {} + ~AutoAssertOnGC() {} + + static void VerifyIsSafeToGC(JSRuntime *rt) {} +#endif +}; + +/* + * Disable the static rooting hazard analysis in the live region, but assert if + * any GC occurs while this guard object is live. This is most useful to help + * the exact rooting hazard analysis in complex regions, since it cannot + * understand dataflow. + * + * Note: GC behavior is unpredictable even when deterministice and is generally + * non-deterministic in practice. The fact that this guard has not + * asserted is not a guarantee that a GC cannot happen in the guarded + * region. As a rule, anyone performing a GC unsafe action should + * understand the GC properties of all code in that region and ensure + * that the hazard analysis is correct for that code, rather than relying + * on this class. + */ +class JS_PUBLIC_API(AutoSuppressGCAnalysis) : public AutoAssertOnGC +{ + public: + AutoSuppressGCAnalysis() : AutoAssertOnGC() {} + explicit AutoSuppressGCAnalysis(JSRuntime *rt) : AutoAssertOnGC(rt) {} +}; + +/* + * Place AutoCheckCannotGC in scopes that you believe can never GC. These + * annotations will be verified both dynamically via AutoAssertOnGC, and + * statically with the rooting hazard analysis (implemented by making the + * analysis consider AutoCheckCannotGC to be a GC pointer, and therefore + * complain if it is live across a GC call.) It is useful when dealing with + * internal pointers to GC things where the GC thing itself may not be present + * for the static analysis: e.g. acquiring inline chars from a JSString* on the + * heap. + */ +class JS_PUBLIC_API(AutoCheckCannotGC) : public AutoAssertOnGC +{ + public: + AutoCheckCannotGC() : AutoAssertOnGC() {} + explicit AutoCheckCannotGC(JSRuntime *rt) : AutoAssertOnGC(rt) {} +}; + +/* + * Unsets the gray bit for anything reachable from |thing|. |kind| should not be + * JSTRACE_SHAPE. |thing| should be non-null. + */ +extern JS_FRIEND_API(bool) +UnmarkGrayGCThingRecursively(void *thing, JSGCTraceKind kind); + +/* + * This should be called when an object that is marked gray is exposed to the JS + * engine (by handing it to running JS code or writing it into live JS + * data). During incremental GC, since the gray bits haven't been computed yet, + * we conservatively mark the object black. + */ +static MOZ_ALWAYS_INLINE void +ExposeGCThingToActiveJS(void *thing, JSGCTraceKind kind) +{ + MOZ_ASSERT(kind != JSTRACE_SHAPE); + + shadow::Runtime *rt = js::gc::GetGCThingRuntime(thing); +#ifdef JSGC_GENERATIONAL + /* + * GC things residing in the nursery cannot be gray: they have no mark bits. + * All live objects in the nursery are moved to tenured at the beginning of + * each GC slice, so the gray marker never sees nursery things. + */ + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) + return; +#endif + if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) + IncrementalReferenceBarrier(thing, kind); + else if (GCThingIsMarkedGray(thing)) + UnmarkGrayGCThingRecursively(thing, kind); +} + +static MOZ_ALWAYS_INLINE void +ExposeObjectToActiveJS(JSObject *obj) +{ + ExposeGCThingToActiveJS(obj, JSTRACE_OBJECT); +} + +/* + * If a GC is currently marking, mark the object black. + */ +static MOZ_ALWAYS_INLINE void +MarkGCThingAsLive(JSRuntime *rt_, void *thing, JSGCTraceKind kind) +{ + shadow::Runtime *rt = shadow::Runtime::asShadowRuntime(rt_); +#ifdef JSGC_GENERATIONAL + /* + * Any object in the nursery will not be freed during any GC running at that time. + */ + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) + return; +#endif + if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) + IncrementalReferenceBarrier(thing, kind); +} + +static MOZ_ALWAYS_INLINE void +MarkStringAsLive(Zone *zone, JSString *string) +{ + JSRuntime *rt = JS::shadow::Zone::asShadowZone(zone)->runtimeFromMainThread(); + MarkGCThingAsLive(rt, string, JSTRACE_STRING); +} + +/* + * Internal to Firefox. + * + * Note: this is not related to the PokeGC in nsJSEnvironment. + */ +extern JS_FRIEND_API(void) +PokeGC(JSRuntime *rt); + +/* + * Internal to Firefox. + */ +extern JS_FRIEND_API(void) +NotifyDidPaint(JSRuntime *rt); + +} /* namespace JS */ + +#endif /* js_GCAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/HashTable.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/HashTable.h new file mode 100644 index 0000000000..4c27308b5e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/HashTable.h @@ -0,0 +1,1672 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_HashTable_h +#define js_HashTable_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Casting.h" +#include "mozilla/DebugOnly.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/PodOperations.h" +#include "mozilla/ReentrancyGuard.h" +#include "mozilla/TemplateLib.h" +#include "mozilla/TypeTraits.h" + +#include "js/Utility.h" + +namespace js { + +class TempAllocPolicy; +template struct DefaultHasher; +template class HashMapEntry; +namespace detail { + template class HashTableEntry; + template class HashTable; +} + +/*****************************************************************************/ + +// A JS-friendly, STL-like container providing a hash-based map from keys to +// values. In particular, HashMap calls constructors and destructors of all +// objects added so non-PODs may be used safely. +// +// Key/Value requirements: +// - movable, destructible, assignable +// HashPolicy requirements: +// - see Hash Policy section below +// AllocPolicy: +// - see jsalloc.h +// +// Note: +// - HashMap is not reentrant: Key/Value/HashPolicy/AllocPolicy members +// called by HashMap must not call back into the same HashMap object. +// - Due to the lack of exception handling, the user must call |init()|. +template , + class AllocPolicy = TempAllocPolicy> +class HashMap +{ + typedef HashMapEntry TableEntry; + + struct MapHashPolicy : HashPolicy + { + typedef Key KeyType; + static const Key &getKey(TableEntry &e) { return e.key(); } + static void setKey(TableEntry &e, Key &k) { HashPolicy::rekey(e.mutableKey(), k); } + }; + + typedef detail::HashTable Impl; + Impl impl; + + public: + typedef typename HashPolicy::Lookup Lookup; + typedef TableEntry Entry; + + // HashMap construction is fallible (due to OOM); thus the user must call + // init after constructing a HashMap and check the return value. + explicit HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} + bool init(uint32_t len = 16) { return impl.init(len); } + bool initialized() const { return impl.initialized(); } + + // Return whether the given lookup value is present in the map. E.g.: + // + // typedef HashMap HM; + // HM h; + // if (HM::Ptr p = h.lookup(3)) { + // const HM::Entry &e = *p; // p acts like a pointer to Entry + // assert(p->key == 3); // Entry contains the key + // char val = p->value; // and value + // } + // + // Also see the definition of Ptr in HashTable above (with T = Entry). + typedef typename Impl::Ptr Ptr; + Ptr lookup(const Lookup &l) const { return impl.lookup(l); } + + // Like lookup, but does not assert if two threads call lookup at the same + // time. Only use this method when none of the threads will modify the map. + Ptr readonlyThreadsafeLookup(const Lookup &l) const { return impl.readonlyThreadsafeLookup(l); } + + // Assuming |p.found()|, remove |*p|. + void remove(Ptr p) { impl.remove(p); } + + // Like |lookup(l)|, but on miss, |p = lookupForAdd(l)| allows efficient + // insertion of Key |k| (where |HashPolicy::match(k,l) == true|) using + // |add(p,k,v)|. After |add(p,k,v)|, |p| points to the new Entry. E.g.: + // + // typedef HashMap HM; + // HM h; + // HM::AddPtr p = h.lookupForAdd(3); + // if (!p) { + // if (!h.add(p, 3, 'a')) + // return false; + // } + // const HM::Entry &e = *p; // p acts like a pointer to Entry + // assert(p->key == 3); // Entry contains the key + // char val = p->value; // and value + // + // Also see the definition of AddPtr in HashTable above (with T = Entry). + // + // N.B. The caller must ensure that no mutating hash table operations + // occur between a pair of |lookupForAdd| and |add| calls. To avoid + // looking up the key a second time, the caller may use the more efficient + // relookupOrAdd method. This method reuses part of the hashing computation + // to more efficiently insert the key if it has not been added. For + // example, a mutation-handling version of the previous example: + // + // HM::AddPtr p = h.lookupForAdd(3); + // if (!p) { + // call_that_may_mutate_h(); + // if (!h.relookupOrAdd(p, 3, 'a')) + // return false; + // } + // const HM::Entry &e = *p; + // assert(p->key == 3); + // char val = p->value; + typedef typename Impl::AddPtr AddPtr; + AddPtr lookupForAdd(const Lookup &l) const { + return impl.lookupForAdd(l); + } + + template + bool add(AddPtr &p, KeyInput &&k, ValueInput &&v) { + Entry e(mozilla::Forward(k), mozilla::Forward(v)); + return impl.add(p, mozilla::Move(e)); + } + + template + bool add(AddPtr &p, KeyInput &&k) { + Entry e(mozilla::Forward(k), Value()); + return impl.add(p, mozilla::Move(e)); + } + + template + bool relookupOrAdd(AddPtr &p, KeyInput &&k, ValueInput &&v) { + Entry e(mozilla::Forward(k), mozilla::Forward(v)); + return impl.relookupOrAdd(p, e.key(), mozilla::Move(e)); + } + + // |all()| returns a Range containing |count()| elements. E.g.: + // + // typedef HashMap HM; + // HM h; + // for (HM::Range r = h.all(); !r.empty(); r.popFront()) + // char c = r.front().value(); + // + // Also see the definition of Range in HashTable above (with T = Entry). + typedef typename Impl::Range Range; + Range all() const { return impl.all(); } + + // Typedef for the enumeration class. An Enum may be used to examine and + // remove table entries: + // + // typedef HashMap HM; + // HM s; + // for (HM::Enum e(s); !e.empty(); e.popFront()) + // if (e.front().value() == 'l') + // e.removeFront(); + // + // Table resize may occur in Enum's destructor. Also see the definition of + // Enum in HashTable above (with T = Entry). + typedef typename Impl::Enum Enum; + + // Remove all entries. This does not shrink the table. For that consider + // using the finish() method. + void clear() { impl.clear(); } + + // Remove all the entries and release all internal buffers. The map must + // be initialized again before any use. + void finish() { impl.finish(); } + + // Does the table contain any entries? + bool empty() const { return impl.empty(); } + + // Number of live elements in the map. + uint32_t count() const { return impl.count(); } + + // Total number of allocation in the dynamic table. Note: resize will + // happen well before count() == capacity(). + size_t capacity() const { return impl.capacity(); } + + // Don't just call |impl.sizeOfExcludingThis()| because there's no + // guarantee that |impl| is the first field in HashMap. + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return impl.sizeOfExcludingThis(mallocSizeOf); + } + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return mallocSizeOf(this) + impl.sizeOfExcludingThis(mallocSizeOf); + } + + // If |generation()| is the same before and after a HashMap operation, + // pointers into the table remain valid. + uint32_t generation() const { return impl.generation(); } + + /************************************************** Shorthand operations */ + + bool has(const Lookup &l) const { + return impl.lookup(l) != nullptr; + } + + // Overwrite existing value with v. Return false on oom. + template + bool put(KeyInput &&k, ValueInput &&v) { + AddPtr p = lookupForAdd(k); + if (p) { + p->value() = mozilla::Forward(v); + return true; + } + return add(p, mozilla::Forward(k), mozilla::Forward(v)); + } + + // Like put, but assert that the given key is not already present. + template + bool putNew(KeyInput &&k, ValueInput &&v) { + Entry e(mozilla::Forward(k), mozilla::Forward(v)); + return impl.putNew(e.key(), mozilla::Move(e)); + } + + // Add (k,defaultValue) if |k| is not found. Return a false-y Ptr on oom. + Ptr lookupWithDefault(const Key &k, const Value &defaultValue) { + AddPtr p = lookupForAdd(k); + if (p) + return p; + (void)add(p, k, defaultValue); // p is left false-y on oom. + return p; + } + + // Remove if present. + void remove(const Lookup &l) { + if (Ptr p = lookup(l)) + remove(p); + } + + // Infallibly rekey one entry, if necessary. + // Requires template parameters Key and HashPolicy::Lookup to be the same type. + void rekeyIfMoved(const Key &old_key, const Key &new_key) { + if (old_key != new_key) + rekeyAs(old_key, new_key, new_key); + } + + // Infallibly rekey one entry, if present. + void rekeyAs(const Lookup &old_lookup, const Lookup &new_lookup, const Key &new_key) { + if (Ptr p = lookup(old_lookup)) + impl.rekeyAndMaybeRehash(p, new_lookup, new_key); + } + + // HashMap is movable + HashMap(HashMap &&rhs) : impl(mozilla::Move(rhs.impl)) {} + void operator=(HashMap &&rhs) { + MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + impl = mozilla::Move(rhs.impl); + } + + private: + // HashMap is not copyable or assignable + HashMap(const HashMap &hm) MOZ_DELETE; + HashMap &operator=(const HashMap &hm) MOZ_DELETE; + + friend class Impl::Enum; +}; + +/*****************************************************************************/ + +// A JS-friendly, STL-like container providing a hash-based set of values. In +// particular, HashSet calls constructors and destructors of all objects added +// so non-PODs may be used safely. +// +// T requirements: +// - movable, destructible, assignable +// HashPolicy requirements: +// - see Hash Policy section below +// AllocPolicy: +// - see jsalloc.h +// +// Note: +// - HashSet is not reentrant: T/HashPolicy/AllocPolicy members called by +// HashSet must not call back into the same HashSet object. +// - Due to the lack of exception handling, the user must call |init()|. +template , + class AllocPolicy = TempAllocPolicy> +class HashSet +{ + struct SetOps : HashPolicy + { + typedef T KeyType; + static const KeyType &getKey(const T &t) { return t; } + static void setKey(T &t, KeyType &k) { HashPolicy::rekey(t, k); } + }; + + typedef detail::HashTable Impl; + Impl impl; + + public: + typedef typename HashPolicy::Lookup Lookup; + typedef T Entry; + + // HashSet construction is fallible (due to OOM); thus the user must call + // init after constructing a HashSet and check the return value. + explicit HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} + bool init(uint32_t len = 16) { return impl.init(len); } + bool initialized() const { return impl.initialized(); } + + // Return whether the given lookup value is present in the map. E.g.: + // + // typedef HashSet HS; + // HS h; + // if (HS::Ptr p = h.lookup(3)) { + // assert(*p == 3); // p acts like a pointer to int + // } + // + // Also see the definition of Ptr in HashTable above. + typedef typename Impl::Ptr Ptr; + Ptr lookup(const Lookup &l) const { return impl.lookup(l); } + + // Like lookup, but does not assert if two threads call lookup at the same + // time. Only use this method when none of the threads will modify the map. + Ptr readonlyThreadsafeLookup(const Lookup &l) const { return impl.readonlyThreadsafeLookup(l); } + + // Assuming |p.found()|, remove |*p|. + void remove(Ptr p) { impl.remove(p); } + + // Like |lookup(l)|, but on miss, |p = lookupForAdd(l)| allows efficient + // insertion of T value |t| (where |HashPolicy::match(t,l) == true|) using + // |add(p,t)|. After |add(p,t)|, |p| points to the new element. E.g.: + // + // typedef HashSet HS; + // HS h; + // HS::AddPtr p = h.lookupForAdd(3); + // if (!p) { + // if (!h.add(p, 3)) + // return false; + // } + // assert(*p == 3); // p acts like a pointer to int + // + // Also see the definition of AddPtr in HashTable above. + // + // N.B. The caller must ensure that no mutating hash table operations + // occur between a pair of |lookupForAdd| and |add| calls. To avoid + // looking up the key a second time, the caller may use the more efficient + // relookupOrAdd method. This method reuses part of the hashing computation + // to more efficiently insert the key if it has not been added. For + // example, a mutation-handling version of the previous example: + // + // HS::AddPtr p = h.lookupForAdd(3); + // if (!p) { + // call_that_may_mutate_h(); + // if (!h.relookupOrAdd(p, 3, 3)) + // return false; + // } + // assert(*p == 3); + // + // Note that relookupOrAdd(p,l,t) performs Lookup using |l| and adds the + // entry |t|, where the caller ensures match(l,t). + typedef typename Impl::AddPtr AddPtr; + AddPtr lookupForAdd(const Lookup &l) const { return impl.lookupForAdd(l); } + + template + bool add(AddPtr &p, U &&u) { + return impl.add(p, mozilla::Forward(u)); + } + + template + bool relookupOrAdd(AddPtr &p, const Lookup &l, U &&u) { + return impl.relookupOrAdd(p, l, mozilla::Forward(u)); + } + + // |all()| returns a Range containing |count()| elements: + // + // typedef HashSet HS; + // HS h; + // for (HS::Range r = h.all(); !r.empty(); r.popFront()) + // int i = r.front(); + // + // Also see the definition of Range in HashTable above. + typedef typename Impl::Range Range; + Range all() const { return impl.all(); } + + // Typedef for the enumeration class. An Enum may be used to examine and + // remove table entries: + // + // typedef HashSet HS; + // HS s; + // for (HS::Enum e(s); !e.empty(); e.popFront()) + // if (e.front() == 42) + // e.removeFront(); + // + // Table resize may occur in Enum's destructor. Also see the definition of + // Enum in HashTable above. + typedef typename Impl::Enum Enum; + + // Remove all entries. This does not shrink the table. For that consider + // using the finish() method. + void clear() { impl.clear(); } + + // Remove all the entries and release all internal buffers. The set must + // be initialized again before any use. + void finish() { impl.finish(); } + + // Does the table contain any entries? + bool empty() const { return impl.empty(); } + + // Number of live elements in the map. + uint32_t count() const { return impl.count(); } + + // Total number of allocation in the dynamic table. Note: resize will + // happen well before count() == capacity(). + size_t capacity() const { return impl.capacity(); } + + // Don't just call |impl.sizeOfExcludingThis()| because there's no + // guarantee that |impl| is the first field in HashSet. + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return impl.sizeOfExcludingThis(mallocSizeOf); + } + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return mallocSizeOf(this) + impl.sizeOfExcludingThis(mallocSizeOf); + } + + // If |generation()| is the same before and after a HashSet operation, + // pointers into the table remain valid. + uint32_t generation() const { return impl.generation(); } + + /************************************************** Shorthand operations */ + + bool has(const Lookup &l) const { + return impl.lookup(l) != nullptr; + } + + // Add |u| if it is not present already. Return false on oom. + template + bool put(U &&u) { + AddPtr p = lookupForAdd(u); + return p ? true : add(p, mozilla::Forward(u)); + } + + // Like put, but assert that the given key is not already present. + template + bool putNew(U &&u) { + return impl.putNew(u, mozilla::Forward(u)); + } + + template + bool putNew(const Lookup &l, U &&u) { + return impl.putNew(l, mozilla::Forward(u)); + } + + void remove(const Lookup &l) { + if (Ptr p = lookup(l)) + remove(p); + } + + // Infallibly rekey one entry, if present. + // Requires template parameters T and HashPolicy::Lookup to be the same type. + void rekeyIfMoved(const Lookup &old_value, const T &new_value) { + if (old_value != new_value) + rekeyAs(old_value, new_value, new_value); + } + + // Infallibly rekey one entry, if present. + void rekeyAs(const Lookup &old_lookup, const Lookup &new_lookup, const T &new_value) { + if (Ptr p = lookup(old_lookup)) + impl.rekeyAndMaybeRehash(p, new_lookup, new_value); + } + + // Infallibly rekey one entry with a new key that is equivalent. + void rekeyInPlace(Ptr p, const T &new_value) + { + MOZ_ASSERT(HashPolicy::match(*p, new_value)); + impl.rekeyInPlace(p, new_value); + } + + // HashSet is movable + HashSet(HashSet &&rhs) : impl(mozilla::Move(rhs.impl)) {} + void operator=(HashSet &&rhs) { + MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + impl = mozilla::Move(rhs.impl); + } + + private: + // HashSet is not copyable or assignable + HashSet(const HashSet &hs) MOZ_DELETE; + HashSet &operator=(const HashSet &hs) MOZ_DELETE; + + friend class Impl::Enum; +}; + +/*****************************************************************************/ + +// Hash Policy +// +// A hash policy P for a hash table with key-type Key must provide: +// - a type |P::Lookup| to use to lookup table entries; +// - a static member function |P::hash| with signature +// +// static js::HashNumber hash(Lookup) +// +// to use to hash the lookup type; and +// - a static member function |P::match| with signature +// +// static bool match(Key, Lookup) +// +// to use to test equality of key and lookup values. +// +// Normally, Lookup = Key. In general, though, different values and types of +// values can be used to lookup and store. If a Lookup value |l| is != to the +// added Key value |k|, the user must ensure that |P::match(k,l)|. E.g.: +// +// js::HashSet::AddPtr p = h.lookup(l); +// if (!p) { +// assert(P::match(k, l)); // must hold +// h.add(p, k); +// } + +// Pointer hashing policy that strips the lowest zeroBits when calculating the +// hash to improve key distribution. +template +struct PointerHasher +{ + typedef Key Lookup; + static HashNumber hash(const Lookup &l) { + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); + size_t word = reinterpret_cast(l) >> zeroBits; + JS_STATIC_ASSERT(sizeof(HashNumber) == 4); +#if JS_BITS_PER_WORD == 32 + return HashNumber(word); +#else + JS_STATIC_ASSERT(sizeof word == 8); + return HashNumber((word >> 32) ^ word); +#endif + } + static bool match(const Key &k, const Lookup &l) { + MOZ_ASSERT(!JS::IsPoisonedPtr(k)); + MOZ_ASSERT(!JS::IsPoisonedPtr(l)); + return k == l; + } + static void rekey(Key &k, const Key& newKey) { + k = newKey; + } +}; + +// Default hash policy: just use the 'lookup' value. This of course only +// works if the lookup value is integral. HashTable applies ScrambleHashCode to +// the result of the 'hash' which means that it is 'ok' if the lookup value is +// not well distributed over the HashNumber domain. +template +struct DefaultHasher +{ + typedef Key Lookup; + static HashNumber hash(const Lookup &l) { + // Hash if can implicitly cast to hash number type. + return l; + } + static bool match(const Key &k, const Lookup &l) { + // Use builtin or overloaded operator==. + return k == l; + } + static void rekey(Key &k, const Key& newKey) { + k = newKey; + } +}; + +// Specialize hashing policy for pointer types. It assumes that the type is +// at least word-aligned. For types with smaller size use PointerHasher. +template +struct DefaultHasher : PointerHasher::value> +{}; + +// For doubles, we can xor the two uint32s. +template <> +struct DefaultHasher +{ + typedef double Lookup; + static HashNumber hash(double d) { + JS_STATIC_ASSERT(sizeof(HashNumber) == 4); + uint64_t u = mozilla::BitwiseCast(d); + return HashNumber(u ^ (u >> 32)); + } + static bool match(double lhs, double rhs) { + return mozilla::BitwiseCast(lhs) == mozilla::BitwiseCast(rhs); + } +}; + +template <> +struct DefaultHasher +{ + typedef float Lookup; + static HashNumber hash(float f) { + JS_STATIC_ASSERT(sizeof(HashNumber) == 4); + return HashNumber(mozilla::BitwiseCast(f)); + } + static bool match(float lhs, float rhs) { + return mozilla::BitwiseCast(lhs) == mozilla::BitwiseCast(rhs); + } +}; + +/*****************************************************************************/ + +// Both HashMap and HashSet are implemented by a single HashTable that is even +// more heavily parameterized than the other two. This leaves HashTable gnarly +// and extremely coupled to HashMap and HashSet; thus code should not use +// HashTable directly. + +template +class HashMapEntry +{ + Key key_; + Value value_; + + template friend class detail::HashTable; + template friend class detail::HashTableEntry; + template friend class HashMap; + + Key & mutableKey() { return key_; } + + public: + template + HashMapEntry(KeyInput &&k, ValueInput &&v) + : key_(mozilla::Forward(k)), + value_(mozilla::Forward(v)) + {} + + HashMapEntry(HashMapEntry &&rhs) + : key_(mozilla::Move(rhs.key_)), + value_(mozilla::Move(rhs.value_)) + {} + + typedef Key KeyType; + typedef Value ValueType; + + const Key & key() const { return key_; } + const Value & value() const { return value_; } + Value & value() { return value_; } + + private: + HashMapEntry(const HashMapEntry &) MOZ_DELETE; + void operator=(const HashMapEntry &) MOZ_DELETE; +}; + +} // namespace js + +namespace mozilla { + +template +struct IsPod > : IsPod {}; + +template +struct IsPod > + : IntegralConstant::value && IsPod::value> +{}; + +} // namespace mozilla + +namespace js { + +namespace detail { + +template +class HashTable; + +template +class HashTableEntry +{ + template friend class HashTable; + typedef typename mozilla::RemoveConst::Type NonConstT; + + HashNumber keyHash; + mozilla::AlignedStorage2 mem; + + static const HashNumber sFreeKey = 0; + static const HashNumber sRemovedKey = 1; + static const HashNumber sCollisionBit = 1; + + static bool isLiveHash(HashNumber hash) + { + return hash > sRemovedKey; + } + + HashTableEntry(const HashTableEntry &) MOZ_DELETE; + void operator=(const HashTableEntry &) MOZ_DELETE; + ~HashTableEntry() MOZ_DELETE; + + public: + // NB: HashTableEntry is treated as a POD: no constructor or destructor calls. + + void destroyIfLive() { + if (isLive()) + mem.addr()->~T(); + } + + void destroy() { + MOZ_ASSERT(isLive()); + mem.addr()->~T(); + } + + void swap(HashTableEntry *other) { + mozilla::Swap(keyHash, other->keyHash); + mozilla::Swap(mem, other->mem); + } + + T &get() { MOZ_ASSERT(isLive()); return *mem.addr(); } + + bool isFree() const { return keyHash == sFreeKey; } + void clearLive() { MOZ_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); } + void clear() { if (isLive()) mem.addr()->~T(); keyHash = sFreeKey; } + bool isRemoved() const { return keyHash == sRemovedKey; } + void removeLive() { MOZ_ASSERT(isLive()); keyHash = sRemovedKey; mem.addr()->~T(); } + bool isLive() const { return isLiveHash(keyHash); } + void setCollision() { MOZ_ASSERT(isLive()); keyHash |= sCollisionBit; } + void setCollision(HashNumber bit) { MOZ_ASSERT(isLive()); keyHash |= bit; } + void unsetCollision() { keyHash &= ~sCollisionBit; } + bool hasCollision() const { return keyHash & sCollisionBit; } + bool matchHash(HashNumber hn) { return (keyHash & ~sCollisionBit) == hn; } + HashNumber getKeyHash() const { return keyHash & ~sCollisionBit; } + + template + void setLive(HashNumber hn, U &&u) + { + MOZ_ASSERT(!isLive()); + keyHash = hn; + new(mem.addr()) T(mozilla::Forward(u)); + MOZ_ASSERT(isLive()); + } +}; + +template +class HashTable : private AllocPolicy +{ + friend class mozilla::ReentrancyGuard; + + typedef typename mozilla::RemoveConst::Type NonConstT; + typedef typename HashPolicy::KeyType Key; + typedef typename HashPolicy::Lookup Lookup; + + public: + typedef HashTableEntry Entry; + + // A nullable pointer to a hash table element. A Ptr |p| can be tested + // either explicitly |if (p.found()) p->...| or using boolean conversion + // |if (p) p->...|. Ptr objects must not be used after any mutating hash + // table operations unless |generation()| is tested. + class Ptr + { + friend class HashTable; + typedef void (Ptr::* ConvertibleToBool)(); + void nonNull() {} + + Entry *entry_; +#ifdef DEBUG + const HashTable *table_; + uint32_t generation; +#endif + + protected: + Ptr(Entry &entry, const HashTable &tableArg) + : entry_(&entry) +#ifdef DEBUG + , table_(&tableArg) + , generation(tableArg.generation()) +#endif + {} + + public: + // Leaves Ptr uninitialized. + Ptr() { +#ifdef JS_DEBUG + entry_ = (Entry *)0xbad; +#endif + } + + bool found() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->isLive(); + } + + operator ConvertibleToBool() const { + return found() ? &Ptr::nonNull : 0; + } + + bool operator==(const Ptr &rhs) const { + MOZ_ASSERT(found() && rhs.found()); + return entry_ == rhs.entry_; + } + + bool operator!=(const Ptr &rhs) const { + MOZ_ASSERT(generation == table_->generation()); + return !(*this == rhs); + } + + T &operator*() const { + MOZ_ASSERT(generation == table_->generation()); + return entry_->get(); + } + + T *operator->() const { + MOZ_ASSERT(generation == table_->generation()); + return &entry_->get(); + } + }; + + // A Ptr that can be used to add a key after a failed lookup. + class AddPtr : public Ptr + { + friend class HashTable; + HashNumber keyHash; +#ifdef DEBUG + uint64_t mutationCount; +#endif + + AddPtr(Entry &entry, const HashTable &tableArg, HashNumber hn) + : Ptr(entry, tableArg) + , keyHash(hn) +#ifdef DEBUG + , mutationCount(tableArg.mutationCount) +#endif + {} + + public: + // Leaves AddPtr uninitialized. + AddPtr() {} + }; + + // A collection of hash table entries. The collection is enumerated by + // calling |front()| followed by |popFront()| as long as |!empty()|. As + // with Ptr/AddPtr, Range objects must not be used after any mutating hash + // table operation unless the |generation()| is tested. + class Range + { + protected: + friend class HashTable; + + Range(const HashTable &tableArg, Entry *c, Entry *e) + : cur(c) + , end(e) +#ifdef DEBUG + , table_(&tableArg) + , mutationCount(tableArg.mutationCount) + , generation(tableArg.generation()) + , validEntry(true) +#endif + { + while (cur < end && !cur->isLive()) + ++cur; + } + + Entry *cur, *end; +#ifdef DEBUG + const HashTable *table_; + uint64_t mutationCount; + uint32_t generation; + bool validEntry; +#endif + + public: + Range() + : cur(nullptr) + , end(nullptr) +#ifdef DEBUG + , table_(nullptr) + , mutationCount(0) + , generation(0) + , validEntry(false) +#endif + {} + + bool empty() const { + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); + return cur == end; + } + + T &front() const { + MOZ_ASSERT(validEntry); + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); + return cur->get(); + } + + void popFront() { + MOZ_ASSERT(!empty()); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); + while (++cur < end && !cur->isLive()) + continue; +#ifdef DEBUG + validEntry = true; +#endif + } + }; + + // A Range whose lifetime delimits a mutating enumeration of a hash table. + // Since rehashing when elements were removed during enumeration would be + // bad, it is postponed until the Enum is destructed. Since the Enum's + // destructor touches the hash table, the user must ensure that the hash + // table is still alive when the destructor runs. + class Enum : public Range + { + friend class HashTable; + + HashTable &table_; + bool rekeyed; + bool removed; + + /* Not copyable. */ + Enum(const Enum &) MOZ_DELETE; + void operator=(const Enum &) MOZ_DELETE; + + public: + template explicit + Enum(Map &map) : Range(map.all()), table_(map.impl), rekeyed(false), removed(false) {} + + // Removes the |front()| element from the table, leaving |front()| + // invalid until the next call to |popFront()|. For example: + // + // HashSet s; + // for (HashSet::Enum e(s); !e.empty(); e.popFront()) + // if (e.front() == 42) + // e.removeFront(); + void removeFront() { + table_.remove(*this->cur); + removed = true; +#ifdef DEBUG + this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif + } + + // Removes the |front()| element and re-inserts it into the table with + // a new key at the new Lookup position. |front()| is invalid after + // this operation until the next call to |popFront()|. + void rekeyFront(const Lookup &l, const Key &k) { + Ptr p(*this->cur, table_); + table_.rekeyWithoutRehash(p, l, k); + rekeyed = true; +#ifdef DEBUG + this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif + } + + void rekeyFront(const Key &k) { + rekeyFront(k, k); + } + + // Potentially rehashes the table. + ~Enum() { + if (rekeyed) { + table_.gen++; + table_.checkOverRemoved(); + } + + if (removed) + table_.compactIfUnderloaded(); + } + }; + + // HashTable is movable + HashTable(HashTable &&rhs) + : AllocPolicy(rhs) + { + mozilla::PodAssign(this, &rhs); + rhs.table = nullptr; + } + void operator=(HashTable &&rhs) { + MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + if (table) + destroyTable(*this, table, capacity()); + mozilla::PodAssign(this, &rhs); + rhs.table = nullptr; + } + + private: + // HashTable is not copyable or assignable + HashTable(const HashTable &) MOZ_DELETE; + void operator=(const HashTable &) MOZ_DELETE; + + private: + static const size_t CAP_BITS = 24; + + public: + Entry *table; // entry storage + uint32_t gen; // entry storage generation number + uint32_t entryCount; // number of entries in table + uint32_t removedCount:CAP_BITS; // removed entry sentinels in table + uint32_t hashShift:8; // multiplicative hash shift + +#ifdef JS_DEBUG + mozilla::DebugOnly mutationCount; + mutable mozilla::DebugOnly mEntered; + mutable struct Stats + { + uint32_t searches; // total number of table searches + uint32_t steps; // hash chain links traversed + uint32_t hits; // searches that found key + uint32_t misses; // searches that didn't find key + uint32_t addOverRemoved; // adds that recycled a removed entry + uint32_t removes; // calls to remove + uint32_t removeFrees; // calls to remove that freed the entry + uint32_t grows; // table expansions + uint32_t shrinks; // table contractions + uint32_t compresses; // table compressions + uint32_t rehashes; // tombstone decontaminations + } stats; +# define METER(x) x +#else +# define METER(x) +#endif + + // The default initial capacity is 32 (enough to hold 16 elements), but it + // can be as low as 4. + static const unsigned sMinCapacityLog2 = 2; + static const unsigned sMinCapacity = 1 << sMinCapacityLog2; + static const unsigned sMaxInit = JS_BIT(CAP_BITS - 1); + static const unsigned sMaxCapacity = JS_BIT(CAP_BITS); + static const unsigned sHashBits = mozilla::tl::BitSize::value; + + // Hash-table alpha is conceptually a fraction, but to avoid floating-point + // math we implement it as a ratio of integers. + static const uint8_t sAlphaDenominator = 4; + static const uint8_t sMinAlphaNumerator = 1; // min alpha: 1/4 + static const uint8_t sMaxAlphaNumerator = 3; // max alpha: 3/4 + + static const HashNumber sFreeKey = Entry::sFreeKey; + static const HashNumber sRemovedKey = Entry::sRemovedKey; + static const HashNumber sCollisionBit = Entry::sCollisionBit; + + void setTableSizeLog2(unsigned sizeLog2) + { + hashShift = sHashBits - sizeLog2; + } + + static bool isLiveHash(HashNumber hash) + { + return Entry::isLiveHash(hash); + } + + static HashNumber prepareHash(const Lookup& l) + { + HashNumber keyHash = ScrambleHashCode(HashPolicy::hash(l)); + + // Avoid reserved hash codes. + if (!isLiveHash(keyHash)) + keyHash -= (sRemovedKey + 1); + return keyHash & ~sCollisionBit; + } + + static Entry *createTable(AllocPolicy &alloc, uint32_t capacity) + { + static_assert(sFreeKey == 0, + "newly-calloc'd tables have to be considered empty"); + static_assert(sMaxCapacity <= SIZE_MAX / sizeof(Entry), + "would overflow allocating max number of entries"); + return static_cast(alloc.calloc_(capacity * sizeof(Entry))); + } + + static void destroyTable(AllocPolicy &alloc, Entry *oldTable, uint32_t capacity) + { + for (Entry *e = oldTable, *end = e + capacity; e < end; ++e) + e->destroyIfLive(); + alloc.free_(oldTable); + } + + public: + explicit HashTable(AllocPolicy ap) + : AllocPolicy(ap) + , table(nullptr) + , gen(0) + , entryCount(0) + , removedCount(0) + , hashShift(sHashBits) +#ifdef DEBUG + , mutationCount(0) + , mEntered(false) +#endif + {} + + MOZ_WARN_UNUSED_RESULT bool init(uint32_t length) + { + MOZ_ASSERT(!initialized()); + + // Reject all lengths whose initial computed capacity would exceed + // sMaxCapacity. Round that maximum length down to the nearest power + // of two for speedier code. + if (length > sMaxInit) { + this->reportAllocOverflow(); + return false; + } + + static_assert((sMaxInit * sAlphaDenominator) / sAlphaDenominator == sMaxInit, + "multiplication in numerator below could overflow"); + static_assert(sMaxInit * sAlphaDenominator <= UINT32_MAX - sMaxAlphaNumerator, + "numerator calculation below could potentially overflow"); + + // Compute the smallest capacity allowing |length| elements to be + // inserted without rehashing: ceil(length / max-alpha). (Ceiling + // integral division: .) + uint32_t newCapacity = + (length * sAlphaDenominator + sMaxAlphaNumerator - 1) / sMaxAlphaNumerator; + if (newCapacity < sMinCapacity) + newCapacity = sMinCapacity; + + // FIXME: use JS_CEILING_LOG2 when PGO stops crashing (bug 543034). + uint32_t roundUp = sMinCapacity, roundUpLog2 = sMinCapacityLog2; + while (roundUp < newCapacity) { + roundUp <<= 1; + ++roundUpLog2; + } + + newCapacity = roundUp; + MOZ_ASSERT(newCapacity >= length); + MOZ_ASSERT(newCapacity <= sMaxCapacity); + + table = createTable(*this, newCapacity); + if (!table) + return false; + + setTableSizeLog2(roundUpLog2); + METER(memset(&stats, 0, sizeof(stats))); + return true; + } + + bool initialized() const + { + return !!table; + } + + ~HashTable() + { + if (table) + destroyTable(*this, table, capacity()); + } + + private: + HashNumber hash1(HashNumber hash0) const + { + return hash0 >> hashShift; + } + + struct DoubleHash + { + HashNumber h2; + HashNumber sizeMask; + }; + + DoubleHash hash2(HashNumber curKeyHash) const + { + unsigned sizeLog2 = sHashBits - hashShift; + DoubleHash dh = { + ((curKeyHash << sizeLog2) >> hashShift) | 1, + (HashNumber(1) << sizeLog2) - 1 + }; + return dh; + } + + static HashNumber applyDoubleHash(HashNumber h1, const DoubleHash &dh) + { + return (h1 - dh.h2) & dh.sizeMask; + } + + bool overloaded() + { + static_assert(sMaxCapacity <= UINT32_MAX / sMaxAlphaNumerator, + "multiplication below could overflow"); + return entryCount + removedCount >= + capacity() * sMaxAlphaNumerator / sAlphaDenominator; + } + + // Would the table be underloaded if it had the given capacity and entryCount? + static bool wouldBeUnderloaded(uint32_t capacity, uint32_t entryCount) + { + static_assert(sMaxCapacity <= UINT32_MAX / sMinAlphaNumerator, + "multiplication below could overflow"); + return capacity > sMinCapacity && + entryCount <= capacity * sMinAlphaNumerator / sAlphaDenominator; + } + + bool underloaded() + { + return wouldBeUnderloaded(capacity(), entryCount); + } + + static bool match(Entry &e, const Lookup &l) + { + return HashPolicy::match(HashPolicy::getKey(e.get()), l); + } + + Entry &lookup(const Lookup &l, HashNumber keyHash, unsigned collisionBit) const + { + MOZ_ASSERT(isLiveHash(keyHash)); + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(collisionBit == 0 || collisionBit == sCollisionBit); + MOZ_ASSERT(table); + METER(stats.searches++); + + // Compute the primary hash address. + HashNumber h1 = hash1(keyHash); + Entry *entry = &table[h1]; + + // Miss: return space for a new entry. + if (entry->isFree()) { + METER(stats.misses++); + return *entry; + } + + // Hit: return entry. + if (entry->matchHash(keyHash) && match(*entry, l)) { + METER(stats.hits++); + return *entry; + } + + // Collision: double hash. + DoubleHash dh = hash2(keyHash); + + // Save the first removed entry pointer so we can recycle later. + Entry *firstRemoved = nullptr; + + while(true) { + if (MOZ_UNLIKELY(entry->isRemoved())) { + if (!firstRemoved) + firstRemoved = entry; + } else { + entry->setCollision(collisionBit); + } + + METER(stats.steps++); + h1 = applyDoubleHash(h1, dh); + + entry = &table[h1]; + if (entry->isFree()) { + METER(stats.misses++); + return firstRemoved ? *firstRemoved : *entry; + } + + if (entry->matchHash(keyHash) && match(*entry, l)) { + METER(stats.hits++); + return *entry; + } + } + } + + // This is a copy of lookup hardcoded to the assumptions: + // 1. the lookup is a lookupForAdd + // 2. the key, whose |keyHash| has been passed is not in the table, + // 3. no entries have been removed from the table. + // This specialized search avoids the need for recovering lookup values + // from entries, which allows more flexible Lookup/Key types. + Entry &findFreeEntry(HashNumber keyHash) + { + MOZ_ASSERT(!(keyHash & sCollisionBit)); + MOZ_ASSERT(table); + METER(stats.searches++); + + // We assume 'keyHash' has already been distributed. + + // Compute the primary hash address. + HashNumber h1 = hash1(keyHash); + Entry *entry = &table[h1]; + + // Miss: return space for a new entry. + if (!entry->isLive()) { + METER(stats.misses++); + return *entry; + } + + // Collision: double hash. + DoubleHash dh = hash2(keyHash); + + while(true) { + MOZ_ASSERT(!entry->isRemoved()); + entry->setCollision(); + + METER(stats.steps++); + h1 = applyDoubleHash(h1, dh); + + entry = &table[h1]; + if (!entry->isLive()) { + METER(stats.misses++); + return *entry; + } + } + } + + enum RebuildStatus { NotOverloaded, Rehashed, RehashFailed }; + + RebuildStatus changeTableSize(int deltaLog2) + { + // Look, but don't touch, until we succeed in getting new entry store. + Entry *oldTable = table; + uint32_t oldCap = capacity(); + uint32_t newLog2 = sHashBits - hashShift + deltaLog2; + uint32_t newCapacity = JS_BIT(newLog2); + if (newCapacity > sMaxCapacity) { + this->reportAllocOverflow(); + return RehashFailed; + } + + Entry *newTable = createTable(*this, newCapacity); + if (!newTable) + return RehashFailed; + + // We can't fail from here on, so update table parameters. + setTableSizeLog2(newLog2); + removedCount = 0; + gen++; + table = newTable; + + // Copy only live entries, leaving removed ones behind. + for (Entry *src = oldTable, *end = src + oldCap; src < end; ++src) { + if (src->isLive()) { + HashNumber hn = src->getKeyHash(); + findFreeEntry(hn).setLive(hn, mozilla::Move(src->get())); + src->destroy(); + } + } + + // All entries have been destroyed, no need to destroyTable. + this->free_(oldTable); + return Rehashed; + } + + RebuildStatus checkOverloaded() + { + if (!overloaded()) + return NotOverloaded; + + // Compress if a quarter or more of all entries are removed. + int deltaLog2; + if (removedCount >= (capacity() >> 2)) { + METER(stats.compresses++); + deltaLog2 = 0; + } else { + METER(stats.grows++); + deltaLog2 = 1; + } + + return changeTableSize(deltaLog2); + } + + // Infallibly rehash the table if we are overloaded with removals. + void checkOverRemoved() + { + if (overloaded()) { + if (checkOverloaded() == RehashFailed) + rehashTableInPlace(); + } + } + + void remove(Entry &e) + { + MOZ_ASSERT(table); + METER(stats.removes++); + + if (e.hasCollision()) { + e.removeLive(); + removedCount++; + } else { + METER(stats.removeFrees++); + e.clearLive(); + } + entryCount--; +#ifdef DEBUG + mutationCount++; +#endif + } + + void checkUnderloaded() + { + if (underloaded()) { + METER(stats.shrinks++); + (void) changeTableSize(-1); + } + } + + // Resize the table down to the largest capacity which doesn't underload the + // table. Since we call checkUnderloaded() on every remove, you only need + // to call this after a bulk removal of items done without calling remove(). + void compactIfUnderloaded() + { + int32_t resizeLog2 = 0; + uint32_t newCapacity = capacity(); + while (wouldBeUnderloaded(newCapacity, entryCount)) { + newCapacity = newCapacity >> 1; + resizeLog2--; + } + + if (resizeLog2 != 0) { + changeTableSize(resizeLog2); + } + } + + // This is identical to changeTableSize(currentSize), but without requiring + // a second table. We do this by recycling the collision bits to tell us if + // the element is already inserted or still waiting to be inserted. Since + // already-inserted elements win any conflicts, we get the same table as we + // would have gotten through random insertion order. + void rehashTableInPlace() + { + METER(stats.rehashes++); + removedCount = 0; + for (size_t i = 0; i < capacity(); ++i) + table[i].unsetCollision(); + + for (size_t i = 0; i < capacity();) { + Entry *src = &table[i]; + + if (!src->isLive() || src->hasCollision()) { + ++i; + continue; + } + + HashNumber keyHash = src->getKeyHash(); + HashNumber h1 = hash1(keyHash); + DoubleHash dh = hash2(keyHash); + Entry *tgt = &table[h1]; + while (true) { + if (!tgt->hasCollision()) { + src->swap(tgt); + tgt->setCollision(); + break; + } + + h1 = applyDoubleHash(h1, dh); + tgt = &table[h1]; + } + } + + // TODO: this algorithm leaves collision bits on *all* elements, even if + // they are on no collision path. We have the option of setting the + // collision bits correctly on a subsequent pass or skipping the rehash + // unless we are totally filled with tombstones: benchmark to find out + // which approach is best. + } + + public: + void clear() + { + if (mozilla::IsPod::value) { + memset(table, 0, sizeof(*table) * capacity()); + } else { + uint32_t tableCapacity = capacity(); + for (Entry *e = table, *end = table + tableCapacity; e < end; ++e) + e->clear(); + } + removedCount = 0; + entryCount = 0; +#ifdef DEBUG + mutationCount++; +#endif + } + + void finish() + { + MOZ_ASSERT(!mEntered); + + if (!table) + return; + + destroyTable(*this, table, capacity()); + table = nullptr; + gen++; + entryCount = 0; + removedCount = 0; +#ifdef DEBUG + mutationCount++; +#endif + } + + Range all() const + { + MOZ_ASSERT(table); + return Range(*this, table, table + capacity()); + } + + bool empty() const + { + MOZ_ASSERT(table); + return !entryCount; + } + + uint32_t count() const + { + MOZ_ASSERT(table); + return entryCount; + } + + uint32_t capacity() const + { + MOZ_ASSERT(table); + return JS_BIT(sHashBits - hashShift); + } + + uint32_t generation() const + { + MOZ_ASSERT(table); + return gen; + } + + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const + { + return mallocSizeOf(table); + } + + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const + { + return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + } + + Ptr lookup(const Lookup &l) const + { + mozilla::ReentrancyGuard g(*this); + HashNumber keyHash = prepareHash(l); + return Ptr(lookup(l, keyHash, 0), *this); + } + + Ptr readonlyThreadsafeLookup(const Lookup &l) const + { + HashNumber keyHash = prepareHash(l); + return Ptr(lookup(l, keyHash, 0), *this); + } + + AddPtr lookupForAdd(const Lookup &l) const + { + mozilla::ReentrancyGuard g(*this); + HashNumber keyHash = prepareHash(l); + Entry &entry = lookup(l, keyHash, sCollisionBit); + AddPtr p(entry, *this, keyHash); + return p; + } + + template + bool add(AddPtr &p, U &&u) + { + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(table); + MOZ_ASSERT(!p.found()); + MOZ_ASSERT(!(p.keyHash & sCollisionBit)); + + // Changing an entry from removed to live does not affect whether we + // are overloaded and can be handled separately. + if (p.entry_->isRemoved()) { + METER(stats.addOverRemoved++); + removedCount--; + p.keyHash |= sCollisionBit; + } else { + // Preserve the validity of |p.entry_|. + RebuildStatus status = checkOverloaded(); + if (status == RehashFailed) + return false; + if (status == Rehashed) + p.entry_ = &findFreeEntry(p.keyHash); + } + + p.entry_->setLive(p.keyHash, mozilla::Forward(u)); + entryCount++; +#ifdef DEBUG + mutationCount++; + p.generation = generation(); + p.mutationCount = mutationCount; +#endif + return true; + } + + // Note: |l| may be a reference to a piece of |u|, so this function + // must take care not to use |l| after moving |u|. + template + void putNewInfallible(const Lookup &l, U &&u) + { + MOZ_ASSERT(table); + + HashNumber keyHash = prepareHash(l); + Entry *entry = &findFreeEntry(keyHash); + + if (entry->isRemoved()) { + METER(stats.addOverRemoved++); + removedCount--; + keyHash |= sCollisionBit; + } + + entry->setLive(keyHash, mozilla::Forward(u)); + entryCount++; +#ifdef DEBUG + mutationCount++; +#endif + } + + // Note: |l| may be a reference to a piece of |u|, so this function + // must take care not to use |l| after moving |u|. + template + bool putNew(const Lookup &l, U &&u) + { + if (checkOverloaded() == RehashFailed) + return false; + + putNewInfallible(l, mozilla::Forward(u)); + return true; + } + + // Note: |l| may be a reference to a piece of |u|, so this function + // must take care not to use |l| after moving |u|. + template + bool relookupOrAdd(AddPtr& p, const Lookup &l, U &&u) + { +#ifdef DEBUG + p.generation = generation(); + p.mutationCount = mutationCount; +#endif + { + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(prepareHash(l) == p.keyHash); // l has not been destroyed + p.entry_ = &lookup(l, p.keyHash, sCollisionBit); + } + return p.found() || add(p, mozilla::Forward(u)); + } + + void remove(Ptr p) + { + MOZ_ASSERT(table); + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(p.found()); + remove(*p.entry_); + checkUnderloaded(); + } + + void rekeyWithoutRehash(Ptr p, const Lookup &l, const Key &k) + { + MOZ_ASSERT(table); + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(p.found()); + typename HashTableEntry::NonConstT t(mozilla::Move(*p)); + HashPolicy::setKey(t, const_cast(k)); + remove(*p.entry_); + putNewInfallible(l, mozilla::Move(t)); + } + + void rekeyAndMaybeRehash(Ptr p, const Lookup &l, const Key &k) + { + rekeyWithoutRehash(p, l, k); + checkOverRemoved(); + } + + void rekeyInPlace(Ptr p, const Key &k) + { + MOZ_ASSERT(table); + mozilla::ReentrancyGuard g(*this); + MOZ_ASSERT(p.found()); + HashPolicy::rekey(const_cast(*p), const_cast(k)); + } + +#undef METER +}; + +} // namespace detail +} // namespace js + +#endif /* js_HashTable_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/HeapAPI.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/HeapAPI.h new file mode 100644 index 0000000000..bdd63c1937 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/HeapAPI.h @@ -0,0 +1,317 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_HeapAPI_h +#define js_HeapAPI_h + +#include + +#include "jspubtd.h" + +#include "js/Utility.h" + +/* These values are private to the JS engine. */ +namespace js { + +// Whether the current thread is permitted access to any part of the specified +// runtime or zone. +JS_FRIEND_API(bool) +CurrentThreadCanAccessRuntime(JSRuntime *rt); + +JS_FRIEND_API(bool) +CurrentThreadCanAccessZone(JS::Zone *zone); + +namespace gc { + +struct Cell; + +const size_t ArenaShift = 12; +const size_t ArenaSize = size_t(1) << ArenaShift; +const size_t ArenaMask = ArenaSize - 1; + +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkShift = 18; +#else +const size_t ChunkShift = 20; +#endif +const size_t ChunkSize = size_t(1) << ChunkShift; +const size_t ChunkMask = ChunkSize - 1; + +const size_t CellShift = 3; +const size_t CellSize = size_t(1) << CellShift; +const size_t CellMask = CellSize - 1; + +/* These are magic constants derived from actual offsets in gc/Heap.h. */ +#ifdef JS_GC_SMALL_CHUNK_SIZE +const size_t ChunkMarkBitmapOffset = 258104; +const size_t ChunkMarkBitmapBits = 31744; +#else +const size_t ChunkMarkBitmapOffset = 1032352; +const size_t ChunkMarkBitmapBits = 129024; +#endif +const size_t ChunkRuntimeOffset = ChunkSize - sizeof(void*); +const size_t ChunkLocationOffset = ChunkSize - 2 * sizeof(void*) - sizeof(uint64_t); + +/* + * Live objects are marked black. How many other additional colors are available + * depends on the size of the GCThing. Objects marked gray are eligible for + * cycle collection. + */ +static const uint32_t BLACK = 0; +static const uint32_t GRAY = 1; + +/* + * The "location" field in the Chunk trailer is a bit vector indicting various + * roles of the chunk. + * + * The value 0 for the "location" field is invalid, at least one bit must be + * set. + * + * Some bits preclude others, for example, any "nursery" bit precludes any + * "tenured" or "middle generation" bit. + */ +const uintptr_t ChunkLocationBitNursery = 1; // Standard GGC nursery +const uintptr_t ChunkLocationBitTenuredHeap = 2; // Standard GGC tenured generation +const uintptr_t ChunkLocationBitPJSNewspace = 4; // The PJS generational GC's allocation space +const uintptr_t ChunkLocationBitPJSFromspace = 8; // The PJS generational GC's fromspace (during GC) + +const uintptr_t ChunkLocationAnyNursery = ChunkLocationBitNursery | + ChunkLocationBitPJSNewspace | + ChunkLocationBitPJSFromspace; + +#ifdef JS_DEBUG +/* When downcasting, ensure we are actually the right type. */ +extern JS_FRIEND_API(void) +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind); +#else +inline void +AssertGCThingHasType(js::gc::Cell *cell, JSGCTraceKind kind) {} +#endif + +} /* namespace gc */ +} /* namespace js */ + +namespace JS { +struct Zone; + +/* Default size for the generational nursery in bytes. */ +const uint32_t DefaultNurseryBytes = 16 * 1024 * 1024; + +/* Default maximum heap size in bytes to pass to JS_NewRuntime(). */ +const uint32_t DefaultHeapMaxBytes = 32 * 1024 * 1024; + +/* + * We cannot expose the class hierarchy: the implementation is hidden. Instead + * we provide cast functions with strong debug-mode assertions. + */ +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSObject *obj) +{ + js::gc::Cell *cell = reinterpret_cast(obj); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFunction *fun) +{ + js::gc::Cell *cell = reinterpret_cast(fun); + AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSString *str) +{ + js::gc::Cell *cell = reinterpret_cast(str); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFlatString *flat) +{ + js::gc::Cell *cell = reinterpret_cast(flat); + AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JS::Symbol *sym) +{ + js::gc::Cell *cell = reinterpret_cast(sym); + AssertGCThingHasType(cell, JSTRACE_SYMBOL); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSScript *script) +{ + js::gc::Cell *cell = reinterpret_cast(script); + AssertGCThingHasType(cell, JSTRACE_SCRIPT); + return cell; +} + +namespace shadow { + +struct ArenaHeader +{ + JS::Zone *zone; +}; + +struct Zone +{ + protected: + JSRuntime *const runtime_; + JSTracer *const barrierTracer_; // A pointer to the JSRuntime's |gcMarker|. + + public: + bool needsBarrier_; + + Zone(JSRuntime *runtime, JSTracer *barrierTracerArg) + : runtime_(runtime), + barrierTracer_(barrierTracerArg), + needsBarrier_(false) + {} + + bool needsBarrier() const { + return needsBarrier_; + } + + JSTracer *barrierTracer() { + MOZ_ASSERT(needsBarrier_); + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + return barrierTracer_; + } + + JSRuntime *runtimeFromMainThread() const { + MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + return runtime_; + } + + // Note: Unrestricted access to the zone's runtime from an arbitrary + // thread can easily lead to races. Use this method very carefully. + JSRuntime *runtimeFromAnyThread() const { + return runtime_; + } + + static JS::shadow::Zone *asShadowZone(JS::Zone *zone) { + return reinterpret_cast(zone); + } +}; + +} /* namespace shadow */ +} /* namespace JS */ + +namespace js { +namespace gc { + +static MOZ_ALWAYS_INLINE uintptr_t * +GetGCThingMarkBitmap(const void *thing) +{ + MOZ_ASSERT(thing); + uintptr_t addr = uintptr_t(thing); + addr &= ~js::gc::ChunkMask; + addr |= js::gc::ChunkMarkBitmapOffset; + return reinterpret_cast(addr); +} + +static MOZ_ALWAYS_INLINE JS::shadow::Runtime * +GetGCThingRuntime(const void *thing) +{ + MOZ_ASSERT(thing); + uintptr_t addr = uintptr_t(thing); + addr &= ~js::gc::ChunkMask; + addr |= js::gc::ChunkRuntimeOffset; + return *reinterpret_cast(addr); +} + +static MOZ_ALWAYS_INLINE void +GetGCThingMarkWordAndMask(const void *thing, uint32_t color, + uintptr_t **wordp, uintptr_t *maskp) +{ + uintptr_t addr = uintptr_t(thing); + size_t bit = (addr & js::gc::ChunkMask) / js::gc::CellSize + color; + MOZ_ASSERT(bit < js::gc::ChunkMarkBitmapBits); + uintptr_t *bitmap = GetGCThingMarkBitmap(thing); + const uintptr_t nbits = sizeof(*bitmap) * CHAR_BIT; + *maskp = uintptr_t(1) << (bit % nbits); + *wordp = &bitmap[bit / nbits]; +} + +static MOZ_ALWAYS_INLINE JS::shadow::ArenaHeader * +GetGCThingArena(void *thing) +{ + uintptr_t addr = uintptr_t(thing); + addr &= ~js::gc::ArenaMask; + return reinterpret_cast(addr); +} + +MOZ_ALWAYS_INLINE bool +IsInsideNursery(const js::gc::Cell *cell) +{ +#ifdef JSGC_GENERATIONAL + if (!cell) + return false; + uintptr_t addr = uintptr_t(cell); + addr &= ~js::gc::ChunkMask; + addr |= js::gc::ChunkLocationOffset; + uint32_t location = *reinterpret_cast(addr); + JS_ASSERT(location != 0); + return location & ChunkLocationAnyNursery; +#else + return false; +#endif +} + +} /* namespace gc */ + +} /* namespace js */ + +namespace JS { + +static MOZ_ALWAYS_INLINE Zone * +GetGCThingZone(void *thing) +{ + MOZ_ASSERT(thing); + return js::gc::GetGCThingArena(thing)->zone; +} + +static MOZ_ALWAYS_INLINE Zone * +GetObjectZone(JSObject *obj) +{ + return GetGCThingZone(obj); +} + +static MOZ_ALWAYS_INLINE bool +GCThingIsMarkedGray(void *thing) +{ +#ifdef JSGC_GENERATIONAL + /* + * GC things residing in the nursery cannot be gray: they have no mark bits. + * All live objects in the nursery are moved to tenured at the beginning of + * each GC slice, so the gray marker never sees nursery things. + */ + if (js::gc::IsInsideNursery((js::gc::Cell *)thing)) + return false; +#endif + uintptr_t *word, mask; + js::gc::GetGCThingMarkWordAndMask(thing, js::gc::GRAY, &word, &mask); + return *word & mask; +} + +static MOZ_ALWAYS_INLINE bool +IsIncrementalBarrierNeededOnGCThing(shadow::Runtime *rt, void *thing, JSGCTraceKind kind) +{ + if (!rt->needsBarrier_) + return false; + JS::Zone *zone = GetGCThingZone(thing); + return reinterpret_cast(zone)->needsBarrier_; +} + +} /* namespace JS */ + +#endif /* js_HeapAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Id.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Id.h new file mode 100644 index 0000000000..11116f2efe --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Id.h @@ -0,0 +1,185 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_Id_h +#define js_Id_h + +// A jsid is an identifier for a property or method of an object which is +// either a 31-bit signed integer, interned string or object. +// +// Also, there is an additional jsid value, JSID_VOID, which does not occur in +// JS scripts but may be used to indicate the absence of a valid jsid. A void +// jsid is not a valid id and only arises as an exceptional API return value, +// such as in JS_NextProperty. Embeddings must not pass JSID_VOID into JSAPI +// entry points expecting a jsid and do not need to handle JSID_VOID in hooks +// receiving a jsid except when explicitly noted in the API contract. +// +// A jsid is not implicitly convertible to or from a jsval; JS_ValueToId or +// JS_IdToValue must be used instead. + +#include "mozilla/NullPtr.h" + +#include "jstypes.h" + +#include "js/HeapAPI.h" +#include "js/RootingAPI.h" +#include "js/TypeDecls.h" +#include "js/Utility.h" + +struct jsid +{ + size_t asBits; + bool operator==(jsid rhs) const { return asBits == rhs.asBits; } + bool operator!=(jsid rhs) const { return asBits != rhs.asBits; } +}; +#define JSID_BITS(id) (id.asBits) + +#define JSID_TYPE_STRING 0x0 +#define JSID_TYPE_INT 0x1 +#define JSID_TYPE_VOID 0x2 +#define JSID_TYPE_SYMBOL 0x4 +#define JSID_TYPE_MASK 0x7 + +// Avoid using canonical 'id' for jsid parameters since this is a magic word in +// Objective-C++ which, apparently, wants to be able to #include jsapi.h. +#define id iden + +static MOZ_ALWAYS_INLINE bool +JSID_IS_STRING(jsid id) +{ + return (JSID_BITS(id) & JSID_TYPE_MASK) == 0; +} + +static MOZ_ALWAYS_INLINE JSString * +JSID_TO_STRING(jsid id) +{ + MOZ_ASSERT(JSID_IS_STRING(id)); + return (JSString *)JSID_BITS(id); +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_ZERO(jsid id) +{ + return JSID_BITS(id) == 0; +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_INT(jsid id) +{ + return !!(JSID_BITS(id) & JSID_TYPE_INT); +} + +static MOZ_ALWAYS_INLINE int32_t +JSID_TO_INT(jsid id) +{ + MOZ_ASSERT(JSID_IS_INT(id)); + return ((uint32_t)JSID_BITS(id)) >> 1; +} + +#define JSID_INT_MIN 0 +#define JSID_INT_MAX INT32_MAX + +static MOZ_ALWAYS_INLINE bool +INT_FITS_IN_JSID(int32_t i) +{ + return i >= 0; +} + +static MOZ_ALWAYS_INLINE jsid +INT_TO_JSID(int32_t i) +{ + jsid id; + MOZ_ASSERT(INT_FITS_IN_JSID(i)); + JSID_BITS(id) = ((i << 1) | JSID_TYPE_INT); + return id; +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_SYMBOL(jsid id) +{ + return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_SYMBOL && + JSID_BITS(id) != JSID_TYPE_SYMBOL; +} + +static MOZ_ALWAYS_INLINE JS::Symbol * +JSID_TO_SYMBOL(jsid id) +{ + MOZ_ASSERT(JSID_IS_SYMBOL(id)); + return (JS::Symbol *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); +} + +static MOZ_ALWAYS_INLINE jsid +SYMBOL_TO_JSID(JS::Symbol *sym) +{ + jsid id; + MOZ_ASSERT(sym != nullptr); + MOZ_ASSERT((size_t(sym) & JSID_TYPE_MASK) == 0); + JS_ASSERT(!js::gc::IsInsideNursery(JS::AsCell(sym))); + JS_ASSERT(!JS::IsPoisonedPtr(sym)); + JSID_BITS(id) = (size_t(sym) | JSID_TYPE_SYMBOL); + return id; +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_GCTHING(jsid id) +{ + return JSID_IS_STRING(id) || JSID_IS_SYMBOL(id); +} + +static MOZ_ALWAYS_INLINE void * +JSID_TO_GCTHING(jsid id) +{ + return (void *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK); +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_VOID(const jsid id) +{ + MOZ_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID, + JSID_BITS(id) == JSID_TYPE_VOID); + return ((size_t)JSID_BITS(id) == JSID_TYPE_VOID); +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_EMPTY(const jsid id) +{ + return ((size_t)JSID_BITS(id) == JSID_TYPE_SYMBOL); +} + +extern JS_PUBLIC_DATA(const jsid) JSID_VOID; +extern JS_PUBLIC_DATA(const jsid) JSID_EMPTY; + +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_VOIDHANDLE; +extern JS_PUBLIC_DATA(const JS::HandleId) JSID_EMPTYHANDLE; + +namespace js { + +inline bool +IsPoisonedId(jsid id) +{ + if (JSID_IS_STRING(id)) + return JS::IsPoisonedPtr(JSID_TO_STRING(id)); + if (JSID_IS_SYMBOL(id)) + return JS::IsPoisonedPtr(JSID_TO_SYMBOL(id)); + return false; +} + +template <> struct GCMethods +{ + static jsid initial() { return JSID_VOID; } + static bool poisoned(jsid id) { return IsPoisonedId(id); } + static bool needsPostBarrier(jsid id) { return false; } +#ifdef JSGC_GENERATIONAL + static void postBarrier(jsid *idp) {} + static void relocate(jsid *idp) {} +#endif +}; + +#undef id + +} + +#endif /* js_Id_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/LegacyIntTypes.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/LegacyIntTypes.h new file mode 100644 index 0000000000..2c8498c89e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/LegacyIntTypes.h @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * This section typedefs the old 'native' types to the new types. + * These redefinitions are provided solely to allow JSAPI users to more easily + * transition to types. They are not to be used in the JSAPI, and + * new JSAPI user code should not use them. This mapping file may eventually + * be removed from SpiderMonkey, so don't depend on it in the long run. + */ + +/* + * BEWARE: Comity with other implementers of these types is not guaranteed. + * Indeed, if you use this header and third-party code defining these + * types, *expect* to encounter either compile errors or link errors, + * depending how these types are used and on the order of inclusion. + * It is safest to use only the types. + */ +#ifndef js_LegacyIntTypes_h +#define js_LegacyIntTypes_h + +#include + +#include "js-config.h" + +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; +typedef uint64_t uint64; + +/* + * On AIX 4.3, sys/inttypes.h (which is included by sys/types.h, a very + * common header file) defines the types int8, int16, int32, and int64. + * So we don't define these four types here to avoid conflicts in case + * the code also includes sys/types.h. + */ +#if defined(AIX) && defined(HAVE_SYS_INTTYPES_H) +#include +#else +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; +typedef int64_t int64; +#endif /* AIX && HAVE_SYS_INTTYPES_H */ + +typedef uint8_t JSUint8; +typedef uint16_t JSUint16; +typedef uint32_t JSUint32; +typedef uint64_t JSUint64; + +typedef int8_t JSInt8; +typedef int16_t JSInt16; +typedef int32_t JSInt32; +typedef int64_t JSInt64; + +#endif /* js_LegacyIntTypes_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/MemoryMetrics.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/MemoryMetrics.h new file mode 100644 index 0000000000..31e456baba --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/MemoryMetrics.h @@ -0,0 +1,668 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_MemoryMetrics_h +#define js_MemoryMetrics_h + +// These declarations are highly likely to change in the future. Depend on them +// at your own risk. + +#include "mozilla/MemoryReporting.h" +#include "mozilla/NullPtr.h" +#include "mozilla/PodOperations.h" + +#include + +#include "jsalloc.h" +#include "jspubtd.h" + +#include "js/HashTable.h" +#include "js/Utility.h" +#include "js/Vector.h" + +class nsISupports; // Needed for ObjectPrivateVisitor. + +namespace JS { + +struct TabSizes +{ + enum Kind { + Objects, + Strings, + Private, + Other + }; + + TabSizes() { mozilla::PodZero(this); } + + void add(Kind kind, size_t n) { + switch (kind) { + case Objects: objects += n; break; + case Strings: strings += n; break; + case Private: private_ += n; break; + case Other: other += n; break; + default: MOZ_CRASH("bad TabSizes kind"); + } + } + + size_t objects; + size_t strings; + size_t private_; + size_t other; +}; + +} // namespace JS + +namespace js { + +// In memory reporting, we have concept of "sundries", line items which are too +// small to be worth reporting individually. Under some circumstances, a memory +// reporter gets tossed into the sundries bucket if it's smaller than +// MemoryReportingSundriesThreshold() bytes. +// +// We need to define this value here, rather than in the code which actually +// generates the memory reports, because NotableStringInfo uses this value. +JS_FRIEND_API(size_t) MemoryReportingSundriesThreshold(); + +// This hash policy avoids flattening ropes (which perturbs the site being +// measured and requires a JSContext) at the expense of doing a FULL ROPE COPY +// on every hash and match! Beware. +struct InefficientNonFlatteningStringHashPolicy +{ + typedef JSString *Lookup; + static HashNumber hash(const Lookup &l); + static bool match(const JSString *const &k, const Lookup &l); +}; + +struct CStringHashPolicy +{ + typedef const char *Lookup; + static HashNumber hash(const Lookup &l); + static bool match(const char *const &k, const Lookup &l); +}; + +// This file features many classes with numerous size_t fields, and each such +// class has one or more methods that need to operate on all of these fields. +// Writing these individually is error-prone -- it's easy to add a new field +// without updating all the required methods. So we define a single macro list +// in each class to name the fields (and notable characteristics of them), and +// then use the following macros to transform those lists into the required +// methods. +// +// In some classes, one or more of the macro arguments aren't used. We use '_' +// for those. +// +#define DECL_SIZE(kind, gc, mSize) size_t mSize; +#define ZERO_SIZE(kind, gc, mSize) mSize(0), +#define COPY_OTHER_SIZE(kind, gc, mSize) mSize(other.mSize), +#define ADD_OTHER_SIZE(kind, gc, mSize) mSize += other.mSize; +#define SUB_OTHER_SIZE(kind, gc, mSize) MOZ_ASSERT(mSize >= other.mSize); \ + mSize -= other.mSize; +#define ADD_SIZE_TO_N(kind, gc, mSize) n += mSize; +#define ADD_SIZE_TO_N_IF_LIVE_GC_THING(kind, gc, mSize) n += (js::gc) ? mSize : 0; +#define ADD_TO_TAB_SIZES(kind, gc, mSize) sizes->add(JS::TabSizes::kind, mSize); + +// Used to annotate which size_t fields measure live GC things and which don't. +enum { + NotLiveGCThing = false, + IsLiveGCThing = true +}; + +} // namespace js + +namespace JS { + +// Data for tracking memory usage of things hanging off objects. +struct ObjectsExtraSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(Objects, NotLiveGCThing, mallocHeapSlots) \ + macro(Objects, NotLiveGCThing, mallocHeapElementsNonAsmJS) \ + macro(Objects, NotLiveGCThing, mallocHeapElementsAsmJS) \ + macro(Objects, NotLiveGCThing, nonHeapElementsAsmJS) \ + macro(Objects, NotLiveGCThing, nonHeapElementsMapped) \ + macro(Objects, NotLiveGCThing, nonHeapCodeAsmJS) \ + macro(Objects, NotLiveGCThing, mallocHeapAsmJSModuleData) \ + macro(Objects, NotLiveGCThing, mallocHeapArgumentsData) \ + macro(Objects, NotLiveGCThing, mallocHeapRegExpStatics) \ + macro(Objects, NotLiveGCThing, mallocHeapPropertyIteratorData) \ + macro(Objects, NotLiveGCThing, mallocHeapCtypesData) + + ObjectsExtraSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + dummy() + {} + + void add(const ObjectsExtraSizes &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE) + } + + size_t sizeOfLiveGCThings() const { + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + return n; + } + + void addToTabSizes(TabSizes *sizes) const { + FOR_EACH_SIZE(ADD_TO_TAB_SIZES) + } + + FOR_EACH_SIZE(DECL_SIZE) + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) + +#undef FOR_EACH_SIZE +}; + +// Data for tracking JIT-code memory usage. +struct CodeSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, ion) \ + macro(_, _, baseline) \ + macro(_, _, regexp) \ + macro(_, _, other) \ + macro(_, _, unused) + + CodeSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + dummy() + {} + + FOR_EACH_SIZE(DECL_SIZE) + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) + +#undef FOR_EACH_SIZE +}; + +// Data for tracking GC memory usage. +struct GCSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, marker) \ + macro(_, _, nurseryCommitted) \ + macro(_, _, nurseryDecommitted) \ + macro(_, _, nurseryHugeSlots) \ + macro(_, _, storeBufferVals) \ + macro(_, _, storeBufferCells) \ + macro(_, _, storeBufferSlots) \ + macro(_, _, storeBufferWholeCells) \ + macro(_, _, storeBufferRelocVals) \ + macro(_, _, storeBufferRelocCells) \ + macro(_, _, storeBufferGenerics) + + GCSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + dummy() + {} + + FOR_EACH_SIZE(DECL_SIZE) + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) + +#undef FOR_EACH_SIZE +}; + +// This class holds information about the memory taken up by identical copies of +// a particular string. Multiple JSStrings may have their sizes aggregated +// together into one StringInfo object. Note that two strings with identical +// chars will not be aggregated together if one is a short string and the other +// is not. +struct StringInfo +{ +#define FOR_EACH_SIZE(macro) \ + macro(Strings, IsLiveGCThing, gcHeapLatin1) \ + macro(Strings, IsLiveGCThing, gcHeapTwoByte) \ + macro(Strings, NotLiveGCThing, mallocHeapLatin1) \ + macro(Strings, NotLiveGCThing, mallocHeapTwoByte) + + StringInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numCopies(0) + {} + + void add(const StringInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE); + numCopies++; + } + + void subtract(const StringInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE); + numCopies--; + } + + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + size_t sizeOfLiveGCThings() const { + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + return n; + } + + void addToTabSizes(TabSizes *sizes) const { + FOR_EACH_SIZE(ADD_TO_TAB_SIZES) + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numCopies; // How many copies of the string have we seen? + +#undef FOR_EACH_SIZE +}; + +// Holds data about a notable string (one which, counting all duplicates, uses +// more than a certain amount of memory) so we can report it individually. +// +// The only difference between this class and StringInfo is that +// NotableStringInfo holds a copy of some or all of the string's chars. +struct NotableStringInfo : public StringInfo +{ + static const size_t MAX_SAVED_CHARS = 1024; + + NotableStringInfo(); + NotableStringInfo(JSString *str, const StringInfo &info); + NotableStringInfo(NotableStringInfo &&info); + NotableStringInfo &operator=(NotableStringInfo &&info); + + ~NotableStringInfo() { + js_free(buffer); + } + + char *buffer; + size_t length; + + private: + NotableStringInfo(const NotableStringInfo& info) MOZ_DELETE; +}; + +// This class holds information about the memory taken up by script sources +// from a particular file. +struct ScriptSourceInfo +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, compressed) \ + macro(_, _, uncompressed) \ + macro(_, _, misc) + + ScriptSourceInfo() + : FOR_EACH_SIZE(ZERO_SIZE) + numScripts(0) + {} + + void add(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE) + numScripts++; + } + + void subtract(const ScriptSourceInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE) + numScripts--; + } + + bool isNotable() const { + static const size_t NotabilityThreshold = 16 * 1024; + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N) + return n >= NotabilityThreshold; + } + + FOR_EACH_SIZE(DECL_SIZE) + uint32_t numScripts; // How many ScriptSources come from this file? (It + // can be more than one in XML files that have + // multiple scripts in CDATA sections.) +#undef FOR_EACH_SIZE +}; + +// Holds data about a notable script source file (one whose combined +// script sources use more than a certain amount of memory) so we can report it +// individually. +// +// The only difference between this class and ScriptSourceInfo is that this +// class holds a copy of the filename. +struct NotableScriptSourceInfo : public ScriptSourceInfo +{ + NotableScriptSourceInfo(); + NotableScriptSourceInfo(const char *filename, const ScriptSourceInfo &info); + NotableScriptSourceInfo(NotableScriptSourceInfo &&info); + NotableScriptSourceInfo &operator=(NotableScriptSourceInfo &&info); + + ~NotableScriptSourceInfo() { + js_free(filename_); + } + + char *filename_; + + private: + NotableScriptSourceInfo(const NotableScriptSourceInfo& info) MOZ_DELETE; +}; + +// These measurements relate directly to the JSRuntime, and not to zones and +// compartments within it. +struct RuntimeSizes +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, object) \ + macro(_, _, atomsTable) \ + macro(_, _, contexts) \ + macro(_, _, dtoa) \ + macro(_, _, temporary) \ + macro(_, _, interpreterStack) \ + macro(_, _, mathCache) \ + macro(_, _, uncompressedSourceCache) \ + macro(_, _, compressedSourceSet) \ + macro(_, _, scriptData) \ + + RuntimeSizes() + : FOR_EACH_SIZE(ZERO_SIZE) + scriptSourceInfo(), + code(), + gc(), + notableScriptSources() + { + allScriptSources = js_new(); + if (!allScriptSources || !allScriptSources->init()) + MOZ_CRASH("oom"); + } + + ~RuntimeSizes() { + // |allScriptSources| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allScriptSources); + } + + // The script source measurements in |scriptSourceInfo| are initially for + // all script sources. At the end, if the measurement granularity is + // FineGrained, we subtract the measurements of the notable script sources + // and move them into |notableScriptSources|. + FOR_EACH_SIZE(DECL_SIZE) + ScriptSourceInfo scriptSourceInfo; + CodeSizes code; + GCSizes gc; + + typedef js::HashMap ScriptSourcesHashMap; + + // |allScriptSources| is only used transiently. During the reporting phase + // it is filled with info about every script source in the runtime. It's + // then used to fill in |notableScriptSources| (which actually gets + // reported), and immediately discarded afterwards. + ScriptSourcesHashMap *allScriptSources; + js::Vector notableScriptSources; + +#undef FOR_EACH_SIZE +}; + +struct ZoneStats +{ +#define FOR_EACH_SIZE(macro) \ + macro(Other, IsLiveGCThing, symbolsGCHeap) \ + macro(Other, NotLiveGCThing, gcHeapArenaAdmin) \ + macro(Other, NotLiveGCThing, unusedGCThings) \ + macro(Other, IsLiveGCThing, lazyScriptsGCHeap) \ + macro(Other, NotLiveGCThing, lazyScriptsMallocHeap) \ + macro(Other, IsLiveGCThing, jitCodesGCHeap) \ + macro(Other, IsLiveGCThing, typeObjectsGCHeap) \ + macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \ + macro(Other, NotLiveGCThing, typePool) \ + macro(Other, NotLiveGCThing, baselineStubsOptimized) \ + + ZoneStats() + : FOR_EACH_SIZE(ZERO_SIZE) + stringInfo(), + extra(), + allStrings(nullptr), + notableStrings(), + isTotals(true) + {} + + ZoneStats(ZoneStats &&other) + : FOR_EACH_SIZE(COPY_OTHER_SIZE) + stringInfo(mozilla::Move(other.stringInfo)), + extra(other.extra), + allStrings(other.allStrings), + notableStrings(mozilla::Move(other.notableStrings)), + isTotals(other.isTotals) + { + other.allStrings = nullptr; + MOZ_ASSERT(!other.isTotals); + } + + ~ZoneStats() { + // |allStrings| is usually deleted and set to nullptr before this + // destructor runs. But there are failure cases due to OOMs that may + // prevent that, so it doesn't hurt to try again here. + js_delete(allStrings); + } + + bool initStrings(JSRuntime *rt); + + void addSizes(const ZoneStats &other) { + MOZ_ASSERT(isTotals); + FOR_EACH_SIZE(ADD_OTHER_SIZE) + stringInfo.add(other.stringInfo); + } + + size_t sizeOfLiveGCThings() const { + MOZ_ASSERT(isTotals); + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + n += stringInfo.sizeOfLiveGCThings(); + return n; + } + + void addToTabSizes(JS::TabSizes *sizes) const { + MOZ_ASSERT(isTotals); + FOR_EACH_SIZE(ADD_TO_TAB_SIZES) + stringInfo.addToTabSizes(sizes); + } + + // These string measurements are initially for all strings. At the end, + // if the measurement granularity is FineGrained, we subtract the + // measurements of the notable script sources and move them into + // |notableStrings|. + FOR_EACH_SIZE(DECL_SIZE) + StringInfo stringInfo; + void *extra; // This field can be used by embedders. + + typedef js::HashMap StringsHashMap; + + // |allStrings| is only used transiently. During the zone traversal it is + // filled with info about every string in the zone. It's then used to fill + // in |notableStrings| (which actually gets reported), and immediately + // discarded afterwards. + StringsHashMap *allStrings; + js::Vector notableStrings; + bool isTotals; + +#undef FOR_EACH_SIZE +}; + +struct CompartmentStats +{ +#define FOR_EACH_SIZE(macro) \ + macro(Objects, IsLiveGCThing, objectsGCHeapOrdinary) \ + macro(Objects, IsLiveGCThing, objectsGCHeapFunction) \ + macro(Objects, IsLiveGCThing, objectsGCHeapDenseArray) \ + macro(Objects, IsLiveGCThing, objectsGCHeapSlowArray) \ + macro(Objects, IsLiveGCThing, objectsGCHeapCrossCompartmentWrapper) \ + macro(Private, NotLiveGCThing, objectsPrivate) \ + macro(Other, IsLiveGCThing, shapesGCHeapTreeGlobalParented) \ + macro(Other, IsLiveGCThing, shapesGCHeapTreeNonGlobalParented) \ + macro(Other, IsLiveGCThing, shapesGCHeapDict) \ + macro(Other, IsLiveGCThing, shapesGCHeapBase) \ + macro(Other, NotLiveGCThing, shapesMallocHeapTreeTables) \ + macro(Other, NotLiveGCThing, shapesMallocHeapDictTables) \ + macro(Other, NotLiveGCThing, shapesMallocHeapTreeShapeKids) \ + macro(Other, NotLiveGCThing, shapesMallocHeapCompartmentTables) \ + macro(Other, IsLiveGCThing, scriptsGCHeap) \ + macro(Other, NotLiveGCThing, scriptsMallocHeapData) \ + macro(Other, NotLiveGCThing, baselineData) \ + macro(Other, NotLiveGCThing, baselineStubsFallback) \ + macro(Other, NotLiveGCThing, ionData) \ + macro(Other, NotLiveGCThing, typeInferenceTypeScripts) \ + macro(Other, NotLiveGCThing, typeInferenceAllocationSiteTables) \ + macro(Other, NotLiveGCThing, typeInferenceArrayTypeTables) \ + macro(Other, NotLiveGCThing, typeInferenceObjectTypeTables) \ + macro(Other, NotLiveGCThing, compartmentObject) \ + macro(Other, NotLiveGCThing, crossCompartmentWrappersTable) \ + macro(Other, NotLiveGCThing, regexpCompartment) \ + macro(Other, NotLiveGCThing, debuggeesSet) \ + macro(Other, NotLiveGCThing, savedStacksSet) + + CompartmentStats() + : FOR_EACH_SIZE(ZERO_SIZE) + objectsExtra(), + extra() + {} + + CompartmentStats(const CompartmentStats &other) + : FOR_EACH_SIZE(COPY_OTHER_SIZE) + objectsExtra(other.objectsExtra), + extra(other.extra) + {} + + void add(const CompartmentStats &other) { + FOR_EACH_SIZE(ADD_OTHER_SIZE) + objectsExtra.add(other.objectsExtra); + // Do nothing with |extra|. + } + + size_t sizeOfLiveGCThings() const { + size_t n = 0; + FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) + n += objectsExtra.sizeOfLiveGCThings(); + // Do nothing with |extra|. + return n; + } + + void addToTabSizes(TabSizes *sizes) const { + FOR_EACH_SIZE(ADD_TO_TAB_SIZES); + objectsExtra.addToTabSizes(sizes); + // Do nothing with |extra|. + } + + FOR_EACH_SIZE(DECL_SIZE) + ObjectsExtraSizes objectsExtra; + void *extra; // This field can be used by embedders. + +#undef FOR_EACH_SIZE +}; + +typedef js::Vector CompartmentStatsVector; +typedef js::Vector ZoneStatsVector; + +struct RuntimeStats +{ +#define FOR_EACH_SIZE(macro) \ + macro(_, _, gcHeapChunkTotal) \ + macro(_, _, gcHeapDecommittedArenas) \ + macro(_, _, gcHeapUnusedChunks) \ + macro(_, _, gcHeapUnusedArenas) \ + macro(_, _, gcHeapChunkAdmin) \ + macro(_, _, gcHeapGCThings) \ + + explicit RuntimeStats(mozilla::MallocSizeOf mallocSizeOf) + : FOR_EACH_SIZE(ZERO_SIZE) + runtime(), + cTotals(), + zTotals(), + compartmentStatsVector(), + zoneStatsVector(), + currZoneStats(nullptr), + mallocSizeOf_(mallocSizeOf) + {} + + // Here's a useful breakdown of the GC heap. + // + // - rtStats.gcHeapChunkTotal + // - decommitted bytes + // - rtStats.gcHeapDecommittedArenas (decommitted arenas in non-empty chunks) + // - unused bytes + // - rtStats.gcHeapUnusedChunks (empty chunks) + // - rtStats.gcHeapUnusedArenas (empty arenas within non-empty chunks) + // - rtStats.zTotals.unusedGCThings (empty GC thing slots within non-empty arenas) + // - used bytes + // - rtStats.gcHeapChunkAdmin + // - rtStats.zTotals.gcHeapArenaAdmin + // - rtStats.gcHeapGCThings (in-use GC things) + // == rtStats.zTotals.sizeOfLiveGCThings() + rtStats.cTotals.sizeOfLiveGCThings() + // + // It's possible that some arenas in empty chunks may be decommitted, but + // we don't count those under rtStats.gcHeapDecommittedArenas because (a) + // it's rare, and (b) this means that rtStats.gcHeapUnusedChunks is a + // multiple of the chunk size, which is good. + + FOR_EACH_SIZE(DECL_SIZE) + + RuntimeSizes runtime; + + CompartmentStats cTotals; // The sum of this runtime's compartments' measurements. + ZoneStats zTotals; // The sum of this runtime's zones' measurements. + + CompartmentStatsVector compartmentStatsVector; + ZoneStatsVector zoneStatsVector; + + ZoneStats *currZoneStats; + + mozilla::MallocSizeOf mallocSizeOf_; + + virtual void initExtraCompartmentStats(JSCompartment *c, CompartmentStats *cstats) = 0; + virtual void initExtraZoneStats(JS::Zone *zone, ZoneStats *zstats) = 0; + +#undef FOR_EACH_SIZE +}; + +class ObjectPrivateVisitor +{ + public: + // Within CollectRuntimeStats, this method is called for each JS object + // that has an nsISupports pointer. + virtual size_t sizeOfIncludingThis(nsISupports *aSupports) = 0; + + // A callback that gets a JSObject's nsISupports pointer, if it has one. + // Note: this function does *not* addref |iface|. + typedef bool(*GetISupportsFun)(JSObject *obj, nsISupports **iface); + GetISupportsFun getISupports_; + + explicit ObjectPrivateVisitor(GetISupportsFun getISupports) + : getISupports_(getISupports) + {} +}; + +extern JS_PUBLIC_API(bool) +CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv, bool anonymize); + +extern JS_PUBLIC_API(size_t) +SystemCompartmentCount(JSRuntime *rt); + +extern JS_PUBLIC_API(size_t) +UserCompartmentCount(JSRuntime *rt); + +extern JS_PUBLIC_API(size_t) +PeakSizeOfTemporary(const JSRuntime *rt); + +extern JS_PUBLIC_API(bool) +AddSizeOfTab(JSRuntime *rt, JS::HandleObject obj, mozilla::MallocSizeOf mallocSizeOf, + ObjectPrivateVisitor *opv, TabSizes *sizes); + +} // namespace JS + +#undef DECL_SIZE +#undef ZERO_SIZE +#undef COPY_OTHER_SIZE +#undef ADD_OTHER_SIZE +#undef SUB_OTHER_SIZE +#undef ADD_SIZE_TO_N +#undef ADD_SIZE_TO_N_IF_LIVE_GC_THING +#undef ADD_TO_TAB_SIZES + +#endif /* js_MemoryMetrics_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/OldDebugAPI.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/OldDebugAPI.h new file mode 100644 index 0000000000..7117d754d9 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/OldDebugAPI.h @@ -0,0 +1,385 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_OldDebugAPI_h +#define js_OldDebugAPI_h + +/* + * JS debugger API. + */ + +#include "mozilla/NullPtr.h" + +#include "jsapi.h" +#include "jsbytecode.h" + +#include "js/CallArgs.h" +#include "js/TypeDecls.h" + +class JSAtom; +struct JSFreeOp; + +namespace js { +class InterpreterFrame; +class FrameIter; +class ScriptSource; +} + +// Raw JSScript* because this needs to be callable from a signal handler. +extern JS_PUBLIC_API(unsigned) +JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); + +extern JS_PUBLIC_API(const char *) +JS_GetScriptFilename(JSScript *script); + +namespace JS { + +extern JS_PUBLIC_API(char *) +FormatStackDump(JSContext *cx, char *buf, bool showArgs, bool showLocals, bool showThisProps); + +} // namespace JS + +# ifdef JS_DEBUG +JS_FRIEND_API(void) js_DumpValue(const JS::Value &val); +JS_FRIEND_API(void) js_DumpId(jsid id); +JS_FRIEND_API(void) js_DumpInterpreterFrame(JSContext *cx, js::InterpreterFrame *start = nullptr); +# endif + +JS_FRIEND_API(void) +js_DumpBacktrace(JSContext *cx); + +typedef enum JSTrapStatus { + JSTRAP_ERROR, + JSTRAP_CONTINUE, + JSTRAP_RETURN, + JSTRAP_THROW, + JSTRAP_LIMIT +} JSTrapStatus; + +typedef JSTrapStatus +(* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, + JS::Value closure); + +typedef JSTrapStatus +(* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, JS::Value *rval, + void *closure); + +typedef bool +(* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, JS::Value old, + JS::Value *newp, void *closure); + + + +extern JS_PUBLIC_API(JSCompartment *) +JS_EnterCompartmentOfScript(JSContext *cx, JSScript *target); + +extern JS_PUBLIC_API(JSString *) +JS_DecompileScript(JSContext *cx, JS::HandleScript script, const char *name, unsigned indent); + +/* + * Currently, we only support runtime-wide debugging. In the future, we should + * be able to support compartment-wide debugging. + */ +extern JS_PUBLIC_API(void) +JS_SetRuntimeDebugMode(JSRuntime *rt, bool debug); + +/* + * Debug mode is a compartment-wide mode that enables a debugger to attach + * to and interact with running methodjit-ed frames. In particular, it causes + * every function to be compiled as if an eval was present (so eval-in-frame) + * can work, and it ensures that functions can be re-JITed for other debug + * features. In general, it is not safe to interact with frames that were live + * before debug mode was enabled. For this reason, it is also not safe to + * enable debug mode while frames are live. + */ + +/* Get current state of debugging mode. */ +extern JS_PUBLIC_API(bool) +JS_GetDebugMode(JSContext *cx); + +/* + * Turn on/off debugging mode for all compartments. This returns false if any code + * from any of the runtime's compartments is running or on the stack. + */ +JS_FRIEND_API(bool) +JS_SetDebugModeForAllCompartments(JSContext *cx, bool debug); + +/* + * Turn on/off debugging mode for a single compartment. This should only be + * used when no code from this compartment is running or on the stack in any + * thread. + */ +JS_FRIEND_API(bool) +JS_SetDebugModeForCompartment(JSContext *cx, JSCompartment *comp, bool debug); + +/* + * Turn on/off debugging mode for a context's compartment. + */ +JS_FRIEND_API(bool) +JS_SetDebugMode(JSContext *cx, bool debug); + +/* Turn on single step mode. */ +extern JS_PUBLIC_API(bool) +JS_SetSingleStepMode(JSContext *cx, JS::HandleScript script, bool singleStep); + +/* The closure argument will be marked. */ +extern JS_PUBLIC_API(bool) +JS_SetTrap(JSContext *cx, JS::HandleScript script, jsbytecode *pc, + JSTrapHandler handler, JS::HandleValue closure); + +extern JS_PUBLIC_API(void) +JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc, + JSTrapHandler *handlerp, JS::Value *closurep); + +extern JS_PUBLIC_API(void) +JS_ClearScriptTraps(JSRuntime *rt, JSScript *script); + +extern JS_PUBLIC_API(void) +JS_ClearAllTrapsForCompartment(JSContext *cx); + +/************************************************************************/ + +extern JS_PUBLIC_API(bool) +JS_SetWatchPoint(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JSWatchPointHandler handler, JS::HandleObject closure); + +extern JS_PUBLIC_API(bool) +JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id, + JSWatchPointHandler *handlerp, JSObject **closurep); + +extern JS_PUBLIC_API(bool) +JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj); + +/************************************************************************/ + +extern JS_PUBLIC_API(jsbytecode *) +JS_LineNumberToPC(JSContext *cx, JSScript *script, unsigned lineno); + +extern JS_PUBLIC_API(jsbytecode *) +JS_EndPC(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(bool) +JS_GetLinePCs(JSContext *cx, JSScript *script, + unsigned startLine, unsigned maxLines, + unsigned* count, unsigned** lines, jsbytecode*** pcs); + +extern JS_PUBLIC_API(unsigned) +JS_GetFunctionArgumentCount(JSContext *cx, JSFunction *fun); + +extern JS_PUBLIC_API(bool) +JS_FunctionHasLocalNames(JSContext *cx, JSFunction *fun); + +/* + * N.B. The mark is in the context temp pool and thus the caller must take care + * to call JS_ReleaseFunctionLocalNameArray in a LIFO manner (wrt to any other + * call that may use the temp pool. + */ +extern JS_PUBLIC_API(uintptr_t *) +JS_GetFunctionLocalNameArray(JSContext *cx, JSFunction *fun, void **markp); + +extern JS_PUBLIC_API(JSAtom *) +JS_LocalNameToAtom(uintptr_t w); + +extern JS_PUBLIC_API(JSString *) +JS_AtomKey(JSAtom *atom); + +extern JS_PUBLIC_API(void) +JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mark); + +extern JS_PUBLIC_API(JSScript *) +JS_GetFunctionScript(JSContext *cx, JS::HandleFunction fun); + +extern JS_PUBLIC_API(JSNative) +JS_GetFunctionNative(JSContext *cx, JSFunction *fun); + +JS_PUBLIC_API(JSFunction *) +JS_GetScriptFunction(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(JSObject *) +JS_GetParentOrScopeChain(JSContext *cx, JSObject *obj); + +/************************************************************************/ + +/* + * This is almost JS_GetClass(obj)->name except that certain debug-only + * proxies are made transparent. In particular, this function turns the class + * of any scope (returned via JS_GetFrameScopeChain or JS_GetFrameCalleeObject) + * from "Proxy" to "Call", "Block", "With" etc. + */ +extern JS_PUBLIC_API(const char *) +JS_GetDebugClassName(JSObject *obj); + +/************************************************************************/ + +extern JS_PUBLIC_API(const jschar *) +JS_GetScriptSourceMap(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(unsigned) +JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(unsigned) +JS_GetScriptLineExtent(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(JSVersion) +JS_GetScriptVersion(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(bool) +JS_GetScriptIsSelfHosted(JSScript *script); + +/************************************************************************/ + +typedef struct JSPropertyDesc { + JS::Value id; /* primary id, atomized string, or int */ + JS::Value value; /* property value */ + uint8_t flags; /* flags, see below */ + uint8_t spare; /* unused */ + JS::Value alias; /* alias id if JSPD_ALIAS flag */ +} JSPropertyDesc; + +#define JSPD_ENUMERATE 0x01 /* visible to for/in loop */ +#define JSPD_READONLY 0x02 /* assignment is error */ +#define JSPD_PERMANENT 0x04 /* property cannot be deleted */ +#define JSPD_ALIAS 0x08 /* property has an alias id */ +#define JSPD_EXCEPTION 0x40 /* exception occurred fetching the property, */ + /* value is exception */ +#define JSPD_ERROR 0x80 /* native getter returned false without */ + /* throwing an exception */ + +typedef struct JSPropertyDescArray { + uint32_t length; /* number of elements in array */ + JSPropertyDesc *array; /* alloc'd by Get, freed by Put */ +} JSPropertyDescArray; + +typedef struct JSScopeProperty JSScopeProperty; + +extern JS_PUBLIC_API(bool) +JS_GetPropertyDescArray(JSContext *cx, JS::HandleObject obj, JSPropertyDescArray *pda); + +extern JS_PUBLIC_API(void) +JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); + +/************************************************************************/ + +/* + * JSAbstractFramePtr is the public version of AbstractFramePtr, a pointer to a + * StackFrame or baseline JIT frame. + */ +class JS_PUBLIC_API(JSAbstractFramePtr) +{ + uintptr_t ptr_; + jsbytecode *pc_; + + protected: + JSAbstractFramePtr() + : ptr_(0), pc_(nullptr) + { } + + public: + JSAbstractFramePtr(void *raw, jsbytecode *pc); + + uintptr_t raw() const { return ptr_; } + jsbytecode *pc() const { return pc_; } + + operator bool() const { return !!ptr_; } + + JSObject *scopeChain(JSContext *cx); + JSObject *callObject(JSContext *cx); + + JSFunction *maybeFun(); + JSScript *script(); + + bool getThisValue(JSContext *cx, JS::MutableHandleValue thisv); + + bool isDebuggerFrame(); + + bool evaluateInStackFrame(JSContext *cx, + const char *bytes, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandleValue rval); + + bool evaluateUCInStackFrame(JSContext *cx, + const jschar *chars, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandleValue rval); +}; + +class JS_PUBLIC_API(JSNullFramePtr) : public JSAbstractFramePtr +{ + public: + JSNullFramePtr() + : JSAbstractFramePtr() + {} +}; + +/* + * This class does not work when IonMonkey is active. It's only used by jsd, + * which can only be used when IonMonkey is disabled. + * + * To find the calling script and line number, use JS_DescribeSciptedCaller. + * To summarize the call stack, use JS::DescribeStack. + */ +class JS_PUBLIC_API(JSBrokenFrameIterator) +{ + void *data_; + + public: + explicit JSBrokenFrameIterator(JSContext *cx); + ~JSBrokenFrameIterator(); + + bool done() const; + JSBrokenFrameIterator& operator++(); + + JSAbstractFramePtr abstractFramePtr() const; + jsbytecode *pc() const; + + bool isConstructing() const; +}; + +typedef bool +(* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report, + void *closure); + +typedef struct JSDebugHooks { + JSDebuggerHandler debuggerHandler; + void *debuggerHandlerData; +} JSDebugHooks; + +/************************************************************************/ + +extern JS_PUBLIC_API(bool) +JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler hook, void *closure); + +/************************************************************************/ + +extern JS_PUBLIC_API(const JSDebugHooks *) +JS_GetGlobalDebugHooks(JSRuntime *rt); + +/** + * Add various profiling-related functions as properties of the given object. + */ +extern JS_PUBLIC_API(bool) +JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj); + +/* Defined in vm/Debugger.cpp. */ +extern JS_PUBLIC_API(bool) +JS_DefineDebuggerObject(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(void) +JS_DumpPCCounts(JSContext *cx, JS::HandleScript script); + +extern JS_PUBLIC_API(void) +JS_DumpCompartmentPCCounts(JSContext *cx); + +namespace js { +extern JS_FRIEND_API(bool) +CanCallContextDebugHandler(JSContext *cx); +} + +/* Call the context debug handler on the topmost scripted frame. */ +extern JS_FRIEND_API(bool) +js_CallContextDebugHandler(JSContext *cx); + +#endif /* js_OldDebugAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Principals.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Principals.h new file mode 100644 index 0000000000..78d8c7e893 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Principals.h @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JSPrincipals and related interfaces. */ + +#ifndef js_Principals_h +#define js_Principals_h + +#include "mozilla/Atomics.h" + +#include + +#include "jspubtd.h" + +struct JSPrincipals { + /* Don't call "destroy"; use reference counting macros below. */ +#ifdef JS_THREADSAFE + mozilla::Atomic refcount; +#else + int32_t refcount; +#endif + +#ifdef JS_DEBUG + /* A helper to facilitate principals debugging. */ + uint32_t debugToken; +#endif + + void setDebugToken(uint32_t token) { +# ifdef JS_DEBUG + debugToken = token; +# endif + } + + /* + * This is not defined by the JS engine but should be provided by the + * embedding. + */ + JS_PUBLIC_API(void) dump(); +}; + +extern JS_PUBLIC_API(void) +JS_HoldPrincipals(JSPrincipals *principals); + +extern JS_PUBLIC_API(void) +JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals); + +// Return whether the first principal subsumes the second. The exact meaning of +// 'subsumes' is left up to the browser. Subsumption is checked inside the JS +// engine when determining, e.g., which stack frames to display in a backtrace. +typedef bool +(* JSSubsumesOp)(JSPrincipals *first, JSPrincipals *second); + +/* + * Used to check if a CSP instance wants to disable eval() and friends. + * See js_CheckCSPPermitsJSAction() in jsobj. + */ +typedef bool +(* JSCSPEvalChecker)(JSContext *cx); + +struct JSSecurityCallbacks { + JSCSPEvalChecker contentSecurityPolicyAllows; + JSSubsumesOp subsumes; +}; + +extern JS_PUBLIC_API(void) +JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks); + +extern JS_PUBLIC_API(const JSSecurityCallbacks *) +JS_GetSecurityCallbacks(JSRuntime *rt); + +/* + * Code running with "trusted" principals will be given a deeper stack + * allocation than ordinary scripts. This allows trusted script to run after + * untrusted script has exhausted the stack. This function sets the + * runtime-wide trusted principal. + * + * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since + * there is no available JSContext. Instead, the caller must ensure that the + * given principals stays valid for as long as 'rt' may point to it. If the + * principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be + * called again, passing nullptr for 'prin'. + */ +extern JS_PUBLIC_API(void) +JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin); + +typedef void +(* JSDestroyPrincipalsOp)(JSPrincipals *principals); + +/* + * Initialize the callback that is called to destroy JSPrincipals instance + * when its reference counter drops to zero. The initialization can be done + * only once per JS runtime. + */ +extern JS_PUBLIC_API(void) +JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals); + +#endif /* js_Principals_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/ProfilingStack.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/ProfilingStack.h new file mode 100644 index 0000000000..e82ce1c9d8 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/ProfilingStack.h @@ -0,0 +1,169 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_ProfilingStack_h +#define js_ProfilingStack_h + +#include "mozilla/NullPtr.h" +#include "mozilla/TypedEnum.h" + +#include "jsbytecode.h" +#include "jstypes.h" + +#include "js/Utility.h" + +struct JSRuntime; + +namespace js { + +// A call stack can be specified to the JS engine such that all JS entry/exits +// to functions push/pop an entry to/from the specified stack. +// +// For more detailed information, see vm/SPSProfiler.h. +// +class ProfileEntry +{ + // All fields are marked volatile to prevent the compiler from re-ordering + // instructions. Namely this sequence: + // + // entry[size] = ...; + // size++; + // + // If the size modification were somehow reordered before the stores, then + // if a sample were taken it would be examining bogus information. + // + // A ProfileEntry represents both a C++ profile entry and a JS one. + + // Descriptive string of this entry. + const char * volatile string; + + // Stack pointer for non-JS entries, the script pointer otherwise. + void * volatile spOrScript; + + // Line number for non-JS entries, the bytecode offset otherwise. + int32_t volatile lineOrPc; + + // General purpose storage describing this frame. + uint32_t volatile flags_; + + public: + // These traits are bit masks. Make sure they're powers of 2. + enum Flags { + // Indicate whether a profile entry represents a CPP frame. If not set, + // a JS frame is assumed by default. You're not allowed to publicly + // change the frame type. Instead, call `setJsFrame` or `setCppFrame`. + IS_CPP_ENTRY = 0x01, + + // Indicate that copying the frame label is not necessary when taking a + // sample of the pseudostack. + FRAME_LABEL_COPY = 0x02, + + // Mask for removing all flags except the category information. + CATEGORY_MASK = ~IS_CPP_ENTRY & ~FRAME_LABEL_COPY + }; + + MOZ_BEGIN_NESTED_ENUM_CLASS(Category, uint32_t) + OTHER = 0x04, + CSS = 0x08, + JS = 0x10, + GC = 0x20, + CC = 0x40, + NETWORK = 0x80, + GRAPHICS = 0x100, + STORAGE = 0x200, + EVENTS = 0x400, + + FIRST = OTHER, + LAST = EVENTS + MOZ_END_NESTED_ENUM_CLASS(Category) + + // All of these methods are marked with the 'volatile' keyword because SPS's + // representation of the stack is stored such that all ProfileEntry + // instances are volatile. These methods would not be available unless they + // were marked as volatile as well. + + bool isCpp() const volatile { return hasFlag(IS_CPP_ENTRY); } + bool isJs() const volatile { return !isCpp(); } + + bool isCopyLabel() const volatile { return hasFlag(FRAME_LABEL_COPY); }; + + void setLabel(const char *aString) volatile { string = aString; } + const char *label() const volatile { return string; } + + void setJsFrame(JSScript *aScript, jsbytecode *aPc) volatile { + flags_ = 0; + spOrScript = aScript; + setPC(aPc); + } + void setCppFrame(void *aSp, uint32_t aLine) volatile { + flags_ = IS_CPP_ENTRY; + spOrScript = aSp; + lineOrPc = static_cast(aLine); + } + + void setFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ |= flag; + } + void unsetFlag(uint32_t flag) volatile { + MOZ_ASSERT(flag != IS_CPP_ENTRY); + flags_ &= ~flag; + } + bool hasFlag(uint32_t flag) const volatile { + return bool(flags_ & flag); + } + + uint32_t flags() const volatile { + return flags_; + } + uint32_t category() const volatile { + return flags_ & CATEGORY_MASK; + } + + void *stackAddress() const volatile { + MOZ_ASSERT(!isJs()); + return spOrScript; + } + JSScript *script() const volatile { + MOZ_ASSERT(isJs()); + return (JSScript *)spOrScript; + } + uint32_t line() const volatile { + MOZ_ASSERT(!isJs()); + return static_cast(lineOrPc); + } + + // We can't know the layout of JSScript, so look in vm/SPSProfiler.cpp. + JS_FRIEND_API(jsbytecode *) pc() const volatile; + JS_FRIEND_API(void) setPC(jsbytecode *pc) volatile; + + // The offset of a pc into a script's code can actually be 0, so to + // signify a nullptr pc, use a -1 index. This is checked against in + // pc() and setPC() to set/get the right pc. + static const int32_t NullPCOffset = -1; + + static size_t offsetOfLabel() { return offsetof(ProfileEntry, string); } + static size_t offsetOfSpOrScript() { return offsetof(ProfileEntry, spOrScript); } + static size_t offsetOfLineOrPc() { return offsetof(ProfileEntry, lineOrPc); } + static size_t offsetOfFlags() { return offsetof(ProfileEntry, flags_); } +}; + +JS_FRIEND_API(void) +SetRuntimeProfilingStack(JSRuntime *rt, ProfileEntry *stack, uint32_t *size, + uint32_t max); + +JS_FRIEND_API(void) +EnableRuntimeProfilingStack(JSRuntime *rt, bool enabled); + +JS_FRIEND_API(void) +RegisterRuntimeProfilingEventMarker(JSRuntime *rt, void (*fn)(const char *)); + +JS_FRIEND_API(jsbytecode*) +ProfilingGetPC(JSRuntime *rt, JSScript *script, void *ip); + +} // namespace js + +#endif /* js_ProfilingStack_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/PropertyKey.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/PropertyKey.h new file mode 100644 index 0000000000..1f90653b40 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/PropertyKey.h @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JS::PropertyKey implementation. */ + +#ifndef js_PropertyKey_h +#define js_PropertyKey_h + +#include "js/TypeDecls.h" +#include "js/Value.h" + +namespace JS { + +class PropertyKey; + +namespace detail { + +extern JS_PUBLIC_API(bool) +ToPropertyKeySlow(JSContext *cx, HandleValue v, PropertyKey *key); + +} // namespace detail + +/* + * A PropertyKey is a key used to access some property on an object. It is a + * natural way to represent a property accessed using a JavaScript value. + * + * PropertyKey can represent indexes, named properties, and ES6 symbols. The + * latter aren't implemented in SpiderMonkey yet, but PropertyKey carves out + * space for them. + */ +class PropertyKey +{ + Value v; + friend JS_PUBLIC_API(bool) detail::ToPropertyKeySlow(JSContext *cx, HandleValue v, PropertyKey *key); + + public: + explicit PropertyKey(uint32_t index) : v(PrivateUint32Value(index)) {} + + /* + * An index is a string property name whose characters exactly spell out an + * unsigned 32-bit integer in decimal: "0", "1", "2", ...., "4294967294", + * "4294967295". + */ + bool isIndex(uint32_t *index) { + // The implementation here assumes that private uint32_t are stored + // using the int32_t representation. This is purely an implementation + // detail: embedders must not rely upon this! + if (!v.isInt32()) + return false; + *index = v.toPrivateUint32(); + return true; + } + + /* + * A name is a string property name which is *not* an index. Note that by + * the ECMAScript language grammar, any dotted property access |obj.prop| + * will access a named property. + */ + bool isName(JSString **str) { + uint32_t dummy; + if (isIndex(&dummy)) + return false; + *str = v.toString(); + return true; + } + + /* + * A symbol is a property name that's a Symbol, a particular kind of object + * in ES6. It is the only kind of property name that's not a string. + * + * SpiderMonkey doesn't yet implement symbols, but we're carving out API + * space for them in advance. + */ + bool isSymbol() { + return false; + } +}; + +inline bool +ToPropertyKey(JSContext *cx, HandleValue v, PropertyKey *key) +{ + if (v.isInt32() && v.toInt32() >= 0) { + *key = PropertyKey(uint32_t(v.toInt32())); + return true; + } + + return detail::ToPropertyKeySlow(cx, v, key); +} + +} // namespace JS + +#endif /* js_PropertyKey_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/RequiredDefines.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/RequiredDefines.h new file mode 100644 index 0000000000..308fd7d625 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/RequiredDefines.h @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Various #defines required to build SpiderMonkey. Embedders should add this + * file to the start of the command line via -include or a similar mechanism, + * or SpiderMonkey public headers may not work correctly. + */ + +#ifndef js_RequiredDefines_h +#define js_RequiredDefines_h + +/* + * The c99 defining the limit macros (UINT32_MAX for example), says: + * + * C++ implementations should define these macros only when + * __STDC_LIMIT_MACROS is defined before is included. + * + * The same also occurs with __STDC_CONSTANT_MACROS for the constant macros + * (INT8_C for example) used to specify a literal constant of the proper type, + * and with __STDC_FORMAT_MACROS for the format macros (PRId32 for example) used + * with the fprintf function family. + */ +#define __STDC_LIMIT_MACROS +#define __STDC_CONSTANT_MACROS +#define __STDC_FORMAT_MACROS + +/* Also define a char16_t type if not provided by the compiler. */ +#include "mozilla/Char16.h" + +#endif /* js_RequiredDefines_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/RootingAPI.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/RootingAPI.h new file mode 100644 index 0000000000..621a1e4394 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/RootingAPI.h @@ -0,0 +1,1253 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_RootingAPI_h +#define js_RootingAPI_h + +#include "mozilla/Attributes.h" +#include "mozilla/GuardObjects.h" +#include "mozilla/LinkedList.h" +#include "mozilla/NullPtr.h" +#include "mozilla/TypeTraits.h" + +#include "jspubtd.h" + +#include "js/GCAPI.h" +#include "js/HeapAPI.h" +#include "js/TypeDecls.h" +#include "js/Utility.h" + +/* + * Moving GC Stack Rooting + * + * A moving GC may change the physical location of GC allocated things, even + * when they are rooted, updating all pointers to the thing to refer to its new + * location. The GC must therefore know about all live pointers to a thing, + * not just one of them, in order to behave correctly. + * + * The |Rooted| and |Handle| classes below are used to root stack locations + * whose value may be held live across a call that can trigger GC. For a + * code fragment such as: + * + * JSObject *obj = NewObject(cx); + * DoSomething(cx); + * ... = obj->lastProperty(); + * + * If |DoSomething()| can trigger a GC, the stack location of |obj| must be + * rooted to ensure that the GC does not move the JSObject referred to by + * |obj| without updating |obj|'s location itself. This rooting must happen + * regardless of whether there are other roots which ensure that the object + * itself will not be collected. + * + * If |DoSomething()| cannot trigger a GC, and the same holds for all other + * calls made between |obj|'s definitions and its last uses, then no rooting + * is required. + * + * SpiderMonkey can trigger a GC at almost any time and in ways that are not + * always clear. For example, the following innocuous-looking actions can + * cause a GC: allocation of any new GC thing; JSObject::hasProperty; + * JS_ReportError and friends; and ToNumber, among many others. The following + * dangerous-looking actions cannot trigger a GC: js_malloc, cx->malloc_, + * rt->malloc_, and friends and JS_ReportOutOfMemory. + * + * The following family of three classes will exactly root a stack location. + * Incorrect usage of these classes will result in a compile error in almost + * all cases. Therefore, it is very hard to be incorrectly rooted if you use + * these classes exclusively. These classes are all templated on the type T of + * the value being rooted. + * + * - Rooted declares a variable of type T, whose value is always rooted. + * Rooted may be automatically coerced to a Handle, below. Rooted + * should be used whenever a local variable's value may be held live across a + * call which can trigger a GC. + * + * - Handle is a const reference to a Rooted. Functions which take GC + * things or values as arguments and need to root those arguments should + * generally use handles for those arguments and avoid any explicit rooting. + * This has two benefits. First, when several such functions call each other + * then redundant rooting of multiple copies of the GC thing can be avoided. + * Second, if the caller does not pass a rooted value a compile error will be + * generated, which is quicker and easier to fix than when relying on a + * separate rooting analysis. + * + * - MutableHandle is a non-const reference to Rooted. It is used in the + * same way as Handle and includes a |set(const T &v)| method to allow + * updating the value of the referenced Rooted. A MutableHandle can be + * created from a Rooted by using |Rooted::operator&()|. + * + * In some cases the small performance overhead of exact rooting (measured to + * be a few nanoseconds on desktop) is too much. In these cases, try the + * following: + * + * - Move all Rooted above inner loops: this allows you to re-use the root + * on each iteration of the loop. + * + * - Pass Handle through your hot call stack to avoid re-rooting costs at + * every invocation. + * + * The following diagram explains the list of supported, implicit type + * conversions between classes of this family: + * + * Rooted ----> Handle + * | ^ + * | | + * | | + * +---> MutableHandle + * (via &) + * + * All of these types have an implicit conversion to raw pointers. + */ + +namespace js { + +class ScriptSourceObject; + +template +struct GCMethods {}; + +template +class RootedBase {}; + +template +class HandleBase {}; + +template +class MutableHandleBase {}; + +template +class HeapBase {}; + +/* + * js::NullPtr acts like a nullptr pointer in contexts that require a Handle. + * + * Handle provides an implicit constructor for js::NullPtr so that, given: + * foo(Handle h); + * callers can simply write: + * foo(js::NullPtr()); + * which avoids creating a Rooted just to pass nullptr. + * + * This is the SpiderMonkey internal variant. js::NullPtr should be used in + * preference to JS::NullPtr to avoid the GOT access required for JS_PUBLIC_API + * symbols. + */ +struct NullPtr +{ + static void * const constNullValue; +}; + +namespace gc { +struct Cell; +template +struct PersistentRootedMarker; +} /* namespace gc */ + +} /* namespace js */ + +namespace JS { + +template class Rooted; +template class PersistentRooted; + +/* This is exposing internal state of the GC for inlining purposes. */ +JS_FRIEND_API(bool) isGCEnabled(); + +/* + * JS::NullPtr acts like a nullptr pointer in contexts that require a Handle. + * + * Handle provides an implicit constructor for JS::NullPtr so that, given: + * foo(Handle h); + * callers can simply write: + * foo(JS::NullPtr()); + * which avoids creating a Rooted just to pass nullptr. + */ +struct JS_PUBLIC_API(NullPtr) +{ + static void * const constNullValue; +}; + +/* + * The Heap class is a heap-stored reference to a JS GC thing. All members of + * heap classes that refer to GC things should use Heap (or possibly + * TenuredHeap, described below). + * + * Heap is an abstraction that hides some of the complexity required to + * maintain GC invariants for the contained reference. It uses operator + * overloading to provide a normal pointer interface, but notifies the GC every + * time the value it contains is updated. This is necessary for generational GC, + * which keeps track of all pointers into the nursery. + * + * Heap instances must be traced when their containing object is traced to + * keep the pointed-to GC thing alive. + * + * Heap objects should only be used on the heap. GC references stored on the + * C/C++ stack must use Rooted/Handle/MutableHandle instead. + * + * Type T must be one of: JS::Value, jsid, JSObject*, JSString*, JSScript* + */ +template +class Heap : public js::HeapBase +{ + public: + Heap() { + static_assert(sizeof(T) == sizeof(Heap), + "Heap must be binary compatible with T."); + init(js::GCMethods::initial()); + } + explicit Heap(T p) { init(p); } + + /* + * For Heap, move semantics are equivalent to copy semantics. In C++, a + * copy constructor taking const-ref is the way to get a single function + * that will be used for both lvalue and rvalue copies, so we can simply + * omit the rvalue variant. + */ + explicit Heap(const Heap &p) { init(p.ptr); } + + ~Heap() { + if (js::GCMethods::needsPostBarrier(ptr)) + relocate(); + } + + bool operator==(const Heap &other) { return ptr == other.ptr; } + bool operator!=(const Heap &other) { return ptr != other.ptr; } + + bool operator==(const T &other) const { return ptr == other; } + bool operator!=(const T &other) const { return ptr != other; } + + operator T() const { return ptr; } + T operator->() const { return ptr; } + const T *address() const { return &ptr; } + const T &get() const { return ptr; } + + T *unsafeGet() { return &ptr; } + + Heap &operator=(T p) { + set(p); + return *this; + } + + Heap &operator=(const Heap& other) { + set(other.get()); + return *this; + } + + void set(T newPtr) { + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); + if (js::GCMethods::needsPostBarrier(newPtr)) { + ptr = newPtr; + post(); + } else if (js::GCMethods::needsPostBarrier(ptr)) { + relocate(); /* Called before overwriting ptr. */ + ptr = newPtr; + } else { + ptr = newPtr; + } + } + + /* + * Set the pointer to a value which will cause a crash if it is + * dereferenced. + */ + void setToCrashOnTouch() { + ptr = reinterpret_cast(crashOnTouchPointer); + } + + bool isSetToCrashOnTouch() { + return ptr == crashOnTouchPointer; + } + + private: + void init(T newPtr) { + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); + ptr = newPtr; + if (js::GCMethods::needsPostBarrier(ptr)) + post(); + } + + void post() { +#ifdef JSGC_GENERATIONAL + MOZ_ASSERT(js::GCMethods::needsPostBarrier(ptr)); + js::GCMethods::postBarrier(&ptr); +#endif + } + + void relocate() { +#ifdef JSGC_GENERATIONAL + js::GCMethods::relocate(&ptr); +#endif + } + + enum { + crashOnTouchPointer = 1 + }; + + T ptr; +}; + +#ifdef JS_DEBUG +/* + * For generational GC, assert that an object is in the tenured generation as + * opposed to being in the nursery. + */ +extern JS_FRIEND_API(void) +AssertGCThingMustBeTenured(JSObject* obj); +#else +inline void +AssertGCThingMustBeTenured(JSObject *obj) {} +#endif + +/* + * The TenuredHeap class is similar to the Heap class above in that it + * encapsulates the GC concerns of an on-heap reference to a JS object. However, + * it has two important differences: + * + * 1) Pointers which are statically known to only reference "tenured" objects + * can avoid the extra overhead of SpiderMonkey's write barriers. + * + * 2) Objects in the "tenured" heap have stronger alignment restrictions than + * those in the "nursery", so it is possible to store flags in the lower + * bits of pointers known to be tenured. TenuredHeap wraps a normal tagged + * pointer with a nice API for accessing the flag bits and adds various + * assertions to ensure that it is not mis-used. + * + * GC things are said to be "tenured" when they are located in the long-lived + * heap: e.g. they have gained tenure as an object by surviving past at least + * one GC. For performance, SpiderMonkey allocates some things which are known + * to normally be long lived directly into the tenured generation; for example, + * global objects. Additionally, SpiderMonkey does not visit individual objects + * when deleting non-tenured objects, so object with finalizers are also always + * tenured; for instance, this includes most DOM objects. + * + * The considerations to keep in mind when using a TenuredHeap vs a normal + * Heap are: + * + * - It is invalid for a TenuredHeap to refer to a non-tenured thing. + * - It is however valid for a Heap to refer to a tenured thing. + * - It is not possible to store flag bits in a Heap. + */ +template +class TenuredHeap : public js::HeapBase +{ + public: + TenuredHeap() : bits(0) { + static_assert(sizeof(T) == sizeof(TenuredHeap), + "TenuredHeap must be binary compatible with T."); + } + explicit TenuredHeap(T p) : bits(0) { setPtr(p); } + explicit TenuredHeap(const TenuredHeap &p) : bits(0) { setPtr(p.getPtr()); } + + bool operator==(const TenuredHeap &other) { return bits == other.bits; } + bool operator!=(const TenuredHeap &other) { return bits != other.bits; } + + void setPtr(T newPtr) { + MOZ_ASSERT((reinterpret_cast(newPtr) & flagsMask) == 0); + MOZ_ASSERT(!js::GCMethods::poisoned(newPtr)); + if (newPtr) + AssertGCThingMustBeTenured(newPtr); + bits = (bits & flagsMask) | reinterpret_cast(newPtr); + } + + void setFlags(uintptr_t flagsToSet) { + MOZ_ASSERT((flagsToSet & ~flagsMask) == 0); + bits |= flagsToSet; + } + + void unsetFlags(uintptr_t flagsToUnset) { + MOZ_ASSERT((flagsToUnset & ~flagsMask) == 0); + bits &= ~flagsToUnset; + } + + bool hasFlag(uintptr_t flag) const { + MOZ_ASSERT((flag & ~flagsMask) == 0); + return (bits & flag) != 0; + } + + T getPtr() const { return reinterpret_cast(bits & ~flagsMask); } + uintptr_t getFlags() const { return bits & flagsMask; } + + operator T() const { return getPtr(); } + T operator->() const { return getPtr(); } + + TenuredHeap &operator=(T p) { + setPtr(p); + return *this; + } + + TenuredHeap &operator=(const TenuredHeap& other) { + bits = other.bits; + return *this; + } + + private: + enum { + maskBits = 3, + flagsMask = (1 << maskBits) - 1, + }; + + uintptr_t bits; +}; + +/* + * Reference to a T that has been rooted elsewhere. This is most useful + * as a parameter type, which guarantees that the T lvalue is properly + * rooted. See "Move GC Stack Rooting" above. + * + * If you want to add additional methods to Handle for a specific + * specialization, define a HandleBase specialization containing them. + */ +template +class MOZ_NONHEAP_CLASS Handle : public js::HandleBase +{ + friend class JS::MutableHandle; + + public: + /* Creates a handle from a handle of a type convertible to T. */ + template + Handle(Handle handle, + typename mozilla::EnableIf::value, int>::Type dummy = 0) + { + static_assert(sizeof(Handle) == sizeof(T *), + "Handle must be binary compatible with T*."); + ptr = reinterpret_cast(handle.address()); + } + + /* Create a handle for a nullptr pointer. */ + MOZ_IMPLICIT Handle(js::NullPtr) { + static_assert(mozilla::IsPointer::value, + "js::NullPtr overload not valid for non-pointer types"); + ptr = reinterpret_cast(&js::NullPtr::constNullValue); + } + + /* Create a handle for a nullptr pointer. */ + MOZ_IMPLICIT Handle(JS::NullPtr) { + static_assert(mozilla::IsPointer::value, + "JS::NullPtr overload not valid for non-pointer types"); + ptr = reinterpret_cast(&JS::NullPtr::constNullValue); + } + + MOZ_IMPLICIT Handle(MutableHandle handle) { + ptr = handle.address(); + } + + /* + * Take care when calling this method! + * + * This creates a Handle from the raw location of a T. + * + * It should be called only if the following conditions hold: + * + * 1) the location of the T is guaranteed to be marked (for some reason + * other than being a Rooted), e.g., if it is guaranteed to be reachable + * from an implicit root. + * + * 2) the contents of the location are immutable, or at least cannot change + * for the lifetime of the handle, as its users may not expect its value + * to change underneath them. + */ + static MOZ_CONSTEXPR Handle fromMarkedLocation(const T *p) { + return Handle(p, DeliberatelyChoosingThisOverload, + ImUsingThisOnlyInFromFromMarkedLocation); + } + + /* + * Construct a handle from an explicitly rooted location. This is the + * normal way to create a handle, and normally happens implicitly. + */ + template + inline + Handle(const Rooted &root, + typename mozilla::EnableIf::value, int>::Type dummy = 0); + + template + inline + Handle(const PersistentRooted &root, + typename mozilla::EnableIf::value, int>::Type dummy = 0); + + /* Construct a read only handle from a mutable handle. */ + template + inline + Handle(MutableHandle &root, + typename mozilla::EnableIf::value, int>::Type dummy = 0); + + const T *address() const { return ptr; } + const T& get() const { return *ptr; } + + /* + * Return a reference so passing a Handle to something that + * takes a |const T&| is not a GC hazard. + */ + operator const T&() const { return get(); } + T operator->() const { return get(); } + + bool operator!=(const T &other) const { return *ptr != other; } + bool operator==(const T &other) const { return *ptr == other; } + + private: + Handle() {} + + enum Disambiguator { DeliberatelyChoosingThisOverload = 42 }; + enum CallerIdentity { ImUsingThisOnlyInFromFromMarkedLocation = 17 }; + MOZ_CONSTEXPR Handle(const T *p, Disambiguator, CallerIdentity) : ptr(p) {} + + const T *ptr; + + template void operator=(S) MOZ_DELETE; + void operator=(Handle) MOZ_DELETE; +}; + +/* + * Similar to a handle, but the underlying storage can be changed. This is + * useful for outparams. + * + * If you want to add additional methods to MutableHandle for a specific + * specialization, define a MutableHandleBase specialization containing + * them. + */ +template +class MOZ_STACK_CLASS MutableHandle : public js::MutableHandleBase +{ + public: + inline MOZ_IMPLICIT MutableHandle(Rooted *root); + inline MOZ_IMPLICIT MutableHandle(PersistentRooted *root); + + private: + // Disallow true nullptr and emulated nullptr (gcc 4.4/4.5, __null, appears + // as int/long [32/64-bit]) for overloading purposes. + template + MutableHandle(N, + typename mozilla::EnableIf::value || + mozilla::IsSame::value || + mozilla::IsSame::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + void set(T v) { + MOZ_ASSERT(!js::GCMethods::poisoned(v)); + *ptr = v; + } + + /* + * This may be called only if the location of the T is guaranteed + * to be marked (for some reason other than being a Rooted), + * e.g., if it is guaranteed to be reachable from an implicit root. + * + * Create a MutableHandle from a raw location of a T. + */ + static MutableHandle fromMarkedLocation(T *p) { + MutableHandle h; + h.ptr = p; + return h; + } + + T *address() const { return ptr; } + const T& get() const { return *ptr; } + + /* + * Return a reference so passing a MutableHandle to something that takes + * a |const T&| is not a GC hazard. + */ + operator const T&() const { return get(); } + T operator->() const { return get(); } + + private: + MutableHandle() {} + + T *ptr; + + template void operator=(S v) MOZ_DELETE; + void operator=(MutableHandle other) MOZ_DELETE; +}; + +#ifdef JSGC_GENERATIONAL +JS_FRIEND_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); +JS_FRIEND_API(void) HeapCellRelocate(js::gc::Cell **cellp); +#endif + +} /* namespace JS */ + +namespace js { + +/* + * InternalHandle is a handle to an internal pointer into a gcthing. Use + * InternalHandle when you have a pointer to a direct field of a gcthing, or + * when you need a parameter type for something that *may* be a pointer to a + * direct field of a gcthing. + */ +template +class InternalHandle {}; + +template +class InternalHandle +{ + void * const *holder; + size_t offset; + + public: + /* + * Create an InternalHandle using a Handle to the gcthing containing the + * field in question, and a pointer to the field. + */ + template + InternalHandle(const JS::Handle &handle, T *field) + : holder((void**)handle.address()), offset(uintptr_t(field) - uintptr_t(handle.get())) + {} + + /* + * Create an InternalHandle to a field within a Rooted<>. + */ + template + InternalHandle(const JS::Rooted &root, T *field) + : holder((void**)root.address()), offset(uintptr_t(field) - uintptr_t(root.get())) + {} + + InternalHandle(const InternalHandle& other) + : holder(other.holder), offset(other.offset) {} + + T *get() const { return reinterpret_cast(uintptr_t(*holder) + offset); } + + const T &operator*() const { return *get(); } + T *operator->() const { return get(); } + + static InternalHandle fromMarkedLocation(T *fieldPtr) { + return InternalHandle(fieldPtr); + } + + private: + /* + * Create an InternalHandle to something that is not a pointer to a + * gcthing, and so does not need to be rooted in the first place. Use these + * InternalHandles to pass pointers into functions that also need to accept + * regular InternalHandles to gcthing fields. + * + * Make this private to prevent accidental misuse; this is only for + * fromMarkedLocation(). + */ + explicit InternalHandle(T *field) + : holder(reinterpret_cast(&js::NullPtr::constNullValue)), + offset(uintptr_t(field)) + {} + + void operator=(InternalHandle other) MOZ_DELETE; +}; + +/* + * By default, things should use the inheritance hierarchy to find their + * ThingRootKind. Some pointer types are explicitly set in jspubtd.h so that + * Rooted may be used without the class definition being available. + */ +template +struct RootKind +{ + static ThingRootKind rootKind() { return T::rootKind(); } +}; + +template +struct RootKind +{ + static ThingRootKind rootKind() { return T::rootKind(); } +}; + +template +struct GCMethods +{ + static T *initial() { return nullptr; } + static bool poisoned(T *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(T *v) { return false; } +#ifdef JSGC_GENERATIONAL + static void postBarrier(T **vp) {} + static void relocate(T **vp) {} +#endif +}; + +template <> +struct GCMethods +{ + static JSObject *initial() { return nullptr; } + static bool poisoned(JSObject *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSObject *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSObject **vp) { + JS::HeapCellPostBarrier(reinterpret_cast(vp)); + } + static void relocate(JSObject **vp) { + JS::HeapCellRelocate(reinterpret_cast(vp)); + } +#endif +}; + +template <> +struct GCMethods +{ + static JSFunction *initial() { return nullptr; } + static bool poisoned(JSFunction *v) { return JS::IsPoisonedPtr(v); } + static bool needsPostBarrier(JSFunction *v) { + return v != nullptr && gc::IsInsideNursery(reinterpret_cast(v)); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JSFunction **vp) { + JS::HeapCellPostBarrier(reinterpret_cast(vp)); + } + static void relocate(JSFunction **vp) { + JS::HeapCellRelocate(reinterpret_cast(vp)); + } +#endif +}; + +#ifdef JS_DEBUG +/* This helper allows us to assert that Rooted is scoped within a request. */ +extern JS_PUBLIC_API(bool) +IsInRequest(JSContext *cx); +#endif + +} /* namespace js */ + +namespace JS { + +/* + * Local variable of type T whose value is always rooted. This is typically + * used for local variables, or for non-rooted values being passed to a + * function that requires a handle, e.g. Foo(Root(cx, x)). + * + * If you want to add additional methods to Rooted for a specific + * specialization, define a RootedBase specialization containing them. + */ +template +class MOZ_STACK_CLASS Rooted : public js::RootedBase +{ + /* Note: CX is a subclass of either ContextFriendFields or PerThreadDataFriendFields. */ + template + void init(CX *cx) { +#ifdef JSGC_TRACK_EXACT_ROOTS + js::ThingRootKind kind = js::RootKind::rootKind(); + this->stack = &cx->thingGCRooters[kind]; + this->prev = *stack; + *stack = reinterpret_cast*>(this); + + MOZ_ASSERT(!js::GCMethods::poisoned(ptr)); +#endif + } + + public: + explicit Rooted(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(js::GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG + MOZ_ASSERT(js::IsInRequest(cx)); +#endif + init(js::ContextFriendFields::get(cx)); + } + + Rooted(JSContext *cx, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef JS_DEBUG + MOZ_ASSERT(js::IsInRequest(cx)); +#endif + init(js::ContextFriendFields::get(cx)); + } + + explicit Rooted(js::ContextFriendFields *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(js::GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(cx); + } + + Rooted(js::ContextFriendFields *cx, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(cx); + } + + explicit Rooted(js::PerThreadDataFriendFields *pt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(js::GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(pt); + } + + Rooted(js::PerThreadDataFriendFields *pt, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(pt); + } + + explicit Rooted(JSRuntime *rt + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(js::GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(js::PerThreadDataFriendFields::getMainThread(rt)); + } + + Rooted(JSRuntime *rt, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + init(js::PerThreadDataFriendFields::getMainThread(rt)); + } + + // Note that we need to let the compiler generate the default destructor in + // non-exact-rooting builds because of a bug in the instrumented PGO builds + // using MSVC, see bug 915735 for more details. +#ifdef JSGC_TRACK_EXACT_ROOTS + ~Rooted() { + MOZ_ASSERT(*stack == reinterpret_cast*>(this)); + *stack = prev; + } +#endif + +#ifdef JSGC_TRACK_EXACT_ROOTS + Rooted *previous() { return reinterpret_cast*>(prev); } +#endif + + /* + * Important: Return a reference here so passing a Rooted to + * something that takes a |const T&| is not a GC hazard. + */ + operator const T&() const { return ptr; } + T operator->() const { return ptr; } + T *address() { return &ptr; } + const T *address() const { return &ptr; } + T &get() { return ptr; } + const T &get() const { return ptr; } + + T &operator=(T value) { + MOZ_ASSERT(!js::GCMethods::poisoned(value)); + ptr = value; + return ptr; + } + + T &operator=(const Rooted &value) { + ptr = value; + return ptr; + } + + void set(T value) { + MOZ_ASSERT(!js::GCMethods::poisoned(value)); + ptr = value; + } + + bool operator!=(const T &other) const { return ptr != other; } + bool operator==(const T &other) const { return ptr == other; } + + private: +#ifdef JSGC_TRACK_EXACT_ROOTS + /* + * These need to be templated on void* to avoid aliasing issues between, for + * example, Rooted and Rooted, which use the same + * stack head pointer for different classes. + */ + Rooted **stack, *prev; +#endif + + /* + * |ptr| must be the last field in Rooted because the analysis treats all + * Rooted as Rooted during the analysis. See bug 829372. + */ + T ptr; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + Rooted(const Rooted &) MOZ_DELETE; +}; + +} /* namespace JS */ + +namespace js { + +/* + * Augment the generic Rooted interface when T = JSObject* with + * class-querying and downcasting operations. + * + * Given a Rooted obj, one can view + * Handle h = obj.as(); + * as an optimization of + * Rooted rooted(cx, &obj->as()); + * Handle h = rooted; + */ +template <> +class RootedBase +{ + public: + template + JS::Handle as() const; +}; + +/* Interface substitute for Rooted which does not root the variable's memory. */ +template +class FakeRooted : public RootedBase +{ + public: + template + FakeRooted(CX *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(GCMethods::initial()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + template + FakeRooted(CX *cx, T initial + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : ptr(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + operator T() const { return ptr; } + T operator->() const { return ptr; } + T *address() { return &ptr; } + const T *address() const { return &ptr; } + T &get() { return ptr; } + const T &get() const { return ptr; } + + FakeRooted &operator=(T value) { + MOZ_ASSERT(!GCMethods::poisoned(value)); + ptr = value; + return *this; + } + + FakeRooted &operator=(const FakeRooted &other) { + MOZ_ASSERT(!GCMethods::poisoned(other.ptr)); + ptr = other.ptr; + return *this; + } + + bool operator!=(const T &other) const { return ptr != other; } + bool operator==(const T &other) const { return ptr == other; } + + private: + T ptr; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + FakeRooted(const FakeRooted &) MOZ_DELETE; +}; + +/* Interface substitute for MutableHandle which is not required to point to rooted memory. */ +template +class FakeMutableHandle : public js::MutableHandleBase +{ + public: + MOZ_IMPLICIT FakeMutableHandle(T *t) { + ptr = t; + } + + MOZ_IMPLICIT FakeMutableHandle(FakeRooted *root) { + ptr = root->address(); + } + + void set(T v) { + MOZ_ASSERT(!js::GCMethods::poisoned(v)); + *ptr = v; + } + + T *address() const { return ptr; } + T get() const { return *ptr; } + + operator T() const { return get(); } + T operator->() const { return get(); } + + private: + FakeMutableHandle() {} + + T *ptr; + + template + void operator=(S v) MOZ_DELETE; + + void operator=(const FakeMutableHandle& other) MOZ_DELETE; +}; + +/* + * Types for a variable that either should or shouldn't be rooted, depending on + * the template parameter allowGC. Used for implementing functions that can + * operate on either rooted or unrooted data. + * + * The toHandle() and toMutableHandle() functions are for calling functions + * which require handle types and are only called in the CanGC case. These + * allow the calling code to type check. + */ +enum AllowGC { + NoGC = 0, + CanGC = 1 +}; +template +class MaybeRooted +{ +}; + +template class MaybeRooted +{ + public: + typedef JS::Handle HandleType; + typedef JS::Rooted RootType; + typedef JS::MutableHandle MutableHandleType; + + static inline JS::Handle toHandle(HandleType v) { + return v; + } + + static inline JS::MutableHandle toMutableHandle(MutableHandleType v) { + return v; + } +}; + +template class MaybeRooted +{ + public: + typedef T HandleType; + typedef FakeRooted RootType; + typedef FakeMutableHandle MutableHandleType; + + static JS::Handle toHandle(HandleType v) { + MOZ_CRASH("Bad conversion"); + } + + static JS::MutableHandle toMutableHandle(MutableHandleType v) { + MOZ_CRASH("Bad conversion"); + } +}; + +} /* namespace js */ + +namespace JS { + +template template +inline +Handle::Handle(const Rooted &root, + typename mozilla::EnableIf::value, int>::Type dummy) +{ + ptr = reinterpret_cast(root.address()); +} + +template template +inline +Handle::Handle(const PersistentRooted &root, + typename mozilla::EnableIf::value, int>::Type dummy) +{ + ptr = reinterpret_cast(root.address()); +} + +template template +inline +Handle::Handle(MutableHandle &root, + typename mozilla::EnableIf::value, int>::Type dummy) +{ + ptr = reinterpret_cast(root.address()); +} + +template +inline +MutableHandle::MutableHandle(Rooted *root) +{ + static_assert(sizeof(MutableHandle) == sizeof(T *), + "MutableHandle must be binary compatible with T*."); + ptr = root->address(); +} + +template +inline +MutableHandle::MutableHandle(PersistentRooted *root) +{ + static_assert(sizeof(MutableHandle) == sizeof(T *), + "MutableHandle must be binary compatible with T*."); + ptr = root->address(); +} + +/* + * A copyable, assignable global GC root type with arbitrary lifetime, an + * infallible constructor, and automatic unrooting on destruction. + * + * These roots can be used in heap-allocated data structures, so they are not + * associated with any particular JSContext or stack. They are registered with + * the JSRuntime itself, without locking, so they require a full JSContext to be + * constructed, not one of its more restricted superclasses. + * + * Note that you must not use an PersistentRooted in an object owned by a JS + * object: + * + * Whenever one object whose lifetime is decided by the GC refers to another + * such object, that edge must be traced only if the owning JS object is traced. + * This applies not only to JS objects (which obviously are managed by the GC) + * but also to C++ objects owned by JS objects. + * + * If you put a PersistentRooted in such a C++ object, that is almost certainly + * a leak. When a GC begins, the referent of the PersistentRooted is treated as + * live, unconditionally (because a PersistentRooted is a *root*), even if the + * JS object that owns it is unreachable. If there is any path from that + * referent back to the JS object, then the C++ object containing the + * PersistentRooted will not be destructed, and the whole blob of objects will + * not be freed, even if there are no references to them from the outside. + * + * In the context of Firefox, this is a severe restriction: almost everything in + * Firefox is owned by some JS object or another, so using PersistentRooted in + * such objects would introduce leaks. For these kinds of edges, Heap or + * TenuredHeap would be better types. It's up to the implementor of the type + * containing Heap or TenuredHeap members to make sure their referents get + * marked when the object itself is marked. + */ +template +class PersistentRooted : private mozilla::LinkedListElement > { + friend class mozilla::LinkedList; + friend class mozilla::LinkedListElement; + + friend struct js::gc::PersistentRootedMarker; + + void registerWithRuntime(JSRuntime *rt) { + JS::shadow::Runtime *srt = JS::shadow::Runtime::asShadowRuntime(rt); + srt->getPersistentRootedList().insertBack(this); + } + + public: + explicit PersistentRooted(JSContext *cx) : ptr(js::GCMethods::initial()) + { + registerWithRuntime(js::GetRuntime(cx)); + } + + PersistentRooted(JSContext *cx, T initial) : ptr(initial) + { + registerWithRuntime(js::GetRuntime(cx)); + } + + explicit PersistentRooted(JSRuntime *rt) : ptr(js::GCMethods::initial()) + { + registerWithRuntime(rt); + } + + PersistentRooted(JSRuntime *rt, T initial) : ptr(initial) + { + registerWithRuntime(rt); + } + + PersistentRooted(const PersistentRooted &rhs) + : mozilla::LinkedListElement >(), + ptr(rhs.ptr) + { + /* + * Copy construction takes advantage of the fact that the original + * is already inserted, and simply adds itself to whatever list the + * original was on - no JSRuntime pointer needed. + * + * This requires mutating rhs's links, but those should be 'mutable' + * anyway. C++ doesn't let us declare mutable base classes. + */ + const_cast(rhs).setNext(this); + } + + /* + * Important: Return a reference here so passing a Rooted to + * something that takes a |const T&| is not a GC hazard. + */ + operator const T&() const { return ptr; } + T operator->() const { return ptr; } + T *address() { return &ptr; } + const T *address() const { return &ptr; } + T &get() { return ptr; } + const T &get() const { return ptr; } + + T &operator=(T value) { + MOZ_ASSERT(!js::GCMethods::poisoned(value)); + ptr = value; + return ptr; + } + + T &operator=(const PersistentRooted &value) { + ptr = value; + return ptr; + } + + void set(T value) { + MOZ_ASSERT(!js::GCMethods::poisoned(value)); + ptr = value; + } + + bool operator!=(const T &other) const { return ptr != other; } + bool operator==(const T &other) const { return ptr == other; } + + private: + T ptr; +}; + +class JS_PUBLIC_API(ObjectPtr) +{ + Heap value; + + public: + ObjectPtr() : value(nullptr) {} + + explicit ObjectPtr(JSObject *obj) : value(obj) {} + + /* Always call finalize before the destructor. */ + ~ObjectPtr() { MOZ_ASSERT(!value); } + + void finalize(JSRuntime *rt) { + if (IsIncrementalBarrierNeeded(rt)) + IncrementalObjectBarrier(value); + value = nullptr; + } + + void init(JSObject *obj) { value = obj; } + + JSObject *get() const { return value; } + + void writeBarrierPre(JSRuntime *rt) { + IncrementalObjectBarrier(value); + } + + bool isAboutToBeFinalized(); + + ObjectPtr &operator=(JSObject *obj) { + IncrementalObjectBarrier(value); + value = obj; + return *this; + } + + void trace(JSTracer *trc, const char *name); + + JSObject &operator*() const { return *value; } + JSObject *operator->() const { return value; } + operator JSObject *() const { return value; } +}; + +} /* namespace JS */ + +namespace js { + +/* Base class for automatic read-only object rooting during compilation. */ +class CompilerRootNode +{ + protected: + explicit CompilerRootNode(js::gc::Cell *ptr) : next(nullptr), ptr_(ptr) {} + + public: + void **address() { return (void **)&ptr_; } + + public: + CompilerRootNode *next; + + protected: + js::gc::Cell *ptr_; +}; + +} /* namespace js */ + +#endif /* js_RootingAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/SliceBudget.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/SliceBudget.h new file mode 100644 index 0000000000..7c602c5572 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/SliceBudget.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_SliceBudget_h +#define js_SliceBudget_h + +#include + +namespace js { + +/* + * This class records how much work has been done in a given collection slice, so that + * we can return before pausing for too long. Some slices are allowed to run for + * unlimited time, and others are bounded. To reduce the number of gettimeofday + * calls, we only check the time every 1000 operations. + */ +struct JS_PUBLIC_API(SliceBudget) +{ + int64_t deadline; /* in microseconds */ + intptr_t counter; + + static const intptr_t CounterReset = 1000; + + static const int64_t Unlimited = 0; + static int64_t TimeBudget(int64_t millis); + static int64_t WorkBudget(int64_t work); + + /* Equivalent to SliceBudget(UnlimitedBudget). */ + SliceBudget(); + + /* Instantiate as SliceBudget(Time/WorkBudget(n)). */ + explicit SliceBudget(int64_t budget); + + void reset() { + deadline = unlimitedDeadline; + counter = unlimitedStartCounter; + } + + void step(intptr_t amt = 1) { + counter -= amt; + } + + bool checkOverBudget(); + + bool isOverBudget() { + if (counter >= 0) + return false; + return checkOverBudget(); + } + + bool isUnlimited() { + return deadline == unlimitedDeadline; + } + +private: + static const int64_t unlimitedDeadline = INT64_MAX; + static const intptr_t unlimitedStartCounter = INTPTR_MAX; + +}; + +} // namespace js + +#endif /* js_SliceBudget_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/StructuredClone.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/StructuredClone.h new file mode 100644 index 0000000000..fa48ce045a --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/StructuredClone.h @@ -0,0 +1,245 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_StructuredClone_h +#define js_StructuredClone_h + +#include "mozilla/NullPtr.h" + +#include + +#include "jstypes.h" + +#include "js/RootingAPI.h" +#include "js/TypeDecls.h" +#include "js/Value.h" + +struct JSRuntime; +struct JSStructuredCloneReader; +struct JSStructuredCloneWriter; + +// API for the HTML5 internal structured cloning algorithm. + +namespace JS { +enum TransferableOwnership { + // Transferable data has not been filled in yet + SCTAG_TMO_UNFILLED = 0, + + // Structured clone buffer does not yet own the data + SCTAG_TMO_UNOWNED = 1, + + // All values at least this large are owned by the clone buffer + SCTAG_TMO_FIRST_OWNED = 2, + + // Data is a pointer that can be freed + SCTAG_TMO_ALLOC_DATA = 2, + + // Data is a SharedArrayBufferObject's buffer + SCTAG_TMO_SHARED_BUFFER = 3, + + // Data is a memory mapped pointer + SCTAG_TMO_MAPPED_DATA = 4, + + // Data is embedding-specific. The engine can free it by calling the + // freeTransfer op. The embedding can also use SCTAG_TMO_USER_MIN and + // greater, up to 32 bits, to distinguish specific ownership variants. + SCTAG_TMO_CUSTOM = 5, + + SCTAG_TMO_USER_MIN +}; +} /* namespace JS */ + +// Read structured data from the reader r. This hook is used to read a value +// previously serialized by a call to the WriteStructuredCloneOp hook. +// +// tag and data are the pair of uint32_t values from the header. The callback +// may use the JS_Read* APIs to read any other relevant parts of the object +// from the reader r. closure is any value passed to the JS_ReadStructuredClone +// function. Return the new object on success, nullptr on error/exception. +typedef JSObject *(*ReadStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r, + uint32_t tag, uint32_t data, void *closure); + +// Structured data serialization hook. The engine can write primitive values, +// Objects, Arrays, Dates, RegExps, TypedArrays, and ArrayBuffers. Any other +// type of object requires application support. This callback must first use +// the JS_WriteUint32Pair API to write an object header, passing a value +// greater than JS_SCTAG_USER to the tag parameter. Then it can use the +// JS_Write* APIs to write any other relevant parts of the value v to the +// writer w. closure is any value passed to the JS_WriteStructuredCLone function. +// +// Return true on success, false on error/exception. +typedef bool (*WriteStructuredCloneOp)(JSContext *cx, JSStructuredCloneWriter *w, + JS::HandleObject obj, void *closure); + +// This is called when JS_WriteStructuredClone is given an invalid transferable. +// To follow HTML5, the application must throw a DATA_CLONE_ERR DOMException +// with error set to one of the JS_SCERR_* values. +typedef void (*StructuredCloneErrorOp)(JSContext *cx, uint32_t errorid); + +// This is called when JS_ReadStructuredClone receives a transferable object +// not known to the engine. If this hook does not exist or returns false, the +// JS engine calls the reportError op if set, otherwise it throws a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback and must return a non-null object in returnObject on success. +typedef bool (*ReadTransferStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r, + uint32_t tag, void *content, uint64_t extraData, + void *closure, + JS::MutableHandleObject returnObject); + +// Called when JS_WriteStructuredClone receives a transferable object not +// handled by the engine. If this hook does not exist or returns false, the JS +// engine will call the reportError hook or fall back to throwing a +// DATA_CLONE_ERR DOM Exception. This method is called before any other +// callback. +// +// tag: indicates what type of transferable this is. Must be greater than +// 0xFFFF0201 (value of the internal SCTAG_TRANSFER_MAP_PENDING_ENTRY) +// +// ownership: see TransferableOwnership, above. Used to communicate any needed +// ownership info to the FreeTransferStructuredCloneOp. +// +// content, extraData: what the ReadTransferStructuredCloneOp will receive +// +typedef bool (*TransferStructuredCloneOp)(JSContext *cx, + JS::Handle obj, + void *closure, + // Output: + uint32_t *tag, + JS::TransferableOwnership *ownership, + void **content, + uint64_t *extraData); + +// Called when JS_ClearStructuredClone has to free an unknown transferable +// object. Note that it should never trigger a garbage collection (and will +// assert in a debug build if it does.) +typedef void (*FreeTransferStructuredCloneOp)(uint32_t tag, JS::TransferableOwnership ownership, + void *content, uint64_t extraData, void *closure); + +// The maximum supported structured-clone serialization format version. Note +// that this does not need to be bumped for Transferable-only changes, since +// they are never saved to persistent storage. +#define JS_STRUCTURED_CLONE_VERSION 4 + +struct JSStructuredCloneCallbacks { + ReadStructuredCloneOp read; + WriteStructuredCloneOp write; + StructuredCloneErrorOp reportError; + ReadTransferStructuredCloneOp readTransfer; + TransferStructuredCloneOp writeTransfer; + FreeTransferStructuredCloneOp freeTransfer; +}; + +// Note: if the *data contains transferable objects, it can be read only once. +JS_PUBLIC_API(bool) +JS_ReadStructuredClone(JSContext *cx, uint64_t *data, size_t nbytes, uint32_t version, + JS::MutableHandleValue vp, + const JSStructuredCloneCallbacks *optionalCallbacks, void *closure); + +// Note: On success, the caller is responsible for calling +// JS_ClearStructuredClone(*datap, nbytes, optionalCallbacks, closure). +JS_PUBLIC_API(bool) +JS_WriteStructuredClone(JSContext *cx, JS::HandleValue v, uint64_t **datap, size_t *nbytesp, + const JSStructuredCloneCallbacks *optionalCallbacks, + void *closure, JS::HandleValue transferable); + +JS_PUBLIC_API(bool) +JS_ClearStructuredClone(uint64_t *data, size_t nbytes, + const JSStructuredCloneCallbacks *optionalCallbacks, + void *closure); + +JS_PUBLIC_API(bool) +JS_StructuredCloneHasTransferables(const uint64_t *data, size_t nbytes, bool *hasTransferable); + +JS_PUBLIC_API(bool) +JS_StructuredClone(JSContext *cx, JS::HandleValue v, JS::MutableHandleValue vp, + const JSStructuredCloneCallbacks *optionalCallbacks, void *closure); + +// RAII sugar for JS_WriteStructuredClone. +class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) { + uint64_t *data_; + size_t nbytes_; + uint32_t version_; + const JSStructuredCloneCallbacks *callbacks_; + void *closure_; + + public: + JSAutoStructuredCloneBuffer() + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(nullptr), closure_(nullptr) + {} + + JSAutoStructuredCloneBuffer(const JSStructuredCloneCallbacks *callbacks, void *closure) + : data_(nullptr), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION), + callbacks_(callbacks), closure_(closure) + {} + + JSAutoStructuredCloneBuffer(JSAutoStructuredCloneBuffer &&other); + JSAutoStructuredCloneBuffer &operator=(JSAutoStructuredCloneBuffer &&other); + + ~JSAutoStructuredCloneBuffer() { clear(); } + + uint64_t *data() const { return data_; } + size_t nbytes() const { return nbytes_; } + + void clear(); + + // Copy some memory. It will be automatically freed by the destructor. + bool copy(const uint64_t *data, size_t nbytes, uint32_t version=JS_STRUCTURED_CLONE_VERSION); + + // Adopt some memory. It will be automatically freed by the destructor. + // data must have been allocated by the JS engine (e.g., extracted via + // JSAutoStructuredCloneBuffer::steal). + void adopt(uint64_t *data, size_t nbytes, uint32_t version=JS_STRUCTURED_CLONE_VERSION); + + // Remove the buffer so that it will not be automatically freed. + // After this, the caller is responsible for feeding the memory back to + // JSAutoStructuredCloneBuffer::adopt. + void steal(uint64_t **datap, size_t *nbytesp, uint32_t *versionp=nullptr); + + bool read(JSContext *cx, JS::MutableHandleValue vp, + const JSStructuredCloneCallbacks *optionalCallbacks=nullptr, void *closure=nullptr); + + bool write(JSContext *cx, JS::HandleValue v, + const JSStructuredCloneCallbacks *optionalCallbacks=nullptr, void *closure=nullptr); + + bool write(JSContext *cx, JS::HandleValue v, JS::HandleValue transferable, + const JSStructuredCloneCallbacks *optionalCallbacks=nullptr, void *closure=nullptr); + + private: + // Copy and assignment are not supported. + JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; + JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other) MOZ_DELETE; +}; + +// The range of tag values the application may use for its own custom object types. +#define JS_SCTAG_USER_MIN ((uint32_t) 0xFFFF8000) +#define JS_SCTAG_USER_MAX ((uint32_t) 0xFFFFFFFF) + +#define JS_SCERR_RECURSION 0 +#define JS_SCERR_TRANSFERABLE 1 + +JS_PUBLIC_API(void) +JS_SetStructuredCloneCallbacks(JSRuntime *rt, const JSStructuredCloneCallbacks *callbacks); + +JS_PUBLIC_API(bool) +JS_ReadUint32Pair(JSStructuredCloneReader *r, uint32_t *p1, uint32_t *p2); + +JS_PUBLIC_API(bool) +JS_ReadBytes(JSStructuredCloneReader *r, void *p, size_t len); + +JS_PUBLIC_API(bool) +JS_ReadTypedArray(JSStructuredCloneReader *r, JS::MutableHandleValue vp); + +JS_PUBLIC_API(bool) +JS_WriteUint32Pair(JSStructuredCloneWriter *w, uint32_t tag, uint32_t data); + +JS_PUBLIC_API(bool) +JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len); + +JS_PUBLIC_API(bool) +JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::HandleValue v); + +#endif /* js_StructuredClone_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/TracingAPI.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/TracingAPI.h new file mode 100644 index 0000000000..3c7fdbe1b1 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/TracingAPI.h @@ -0,0 +1,216 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_TracingAPI_h +#define js_TracingAPI_h + +#include "mozilla/NullPtr.h" + +#include "jspubtd.h" + +class JS_PUBLIC_API(JSTracer); + +namespace JS { +template class Heap; +template class TenuredHeap; +} + +// Tracer callback, called for each traceable thing directly referenced by a +// particular object or runtime structure. It is the callback responsibility +// to ensure the traversal of the full object graph via calling eventually +// JS_TraceChildren on the passed thing. In this case the callback must be +// prepared to deal with cycles in the traversal graph. +// +// kind argument is one of JSTRACE_OBJECT, JSTRACE_STRING or a tag denoting +// internal implementation-specific traversal kind. In the latter case the only +// operations on thing that the callback can do is to call JS_TraceChildren or +// JS_GetTraceThingInfo. +// +// If eagerlyTraceWeakMaps is true, when we trace a WeakMap visit all +// of its mappings. This should be used in cases where the tracer +// wants to use the existing liveness of entries. +typedef void +(* JSTraceCallback)(JSTracer *trc, void **thingp, JSGCTraceKind kind); + +// Callback that JSTraceOp implementation can provide to return a string +// describing the reference traced with JS_CallTracer. +typedef void +(* JSTraceNamePrinter)(JSTracer *trc, char *buf, size_t bufsize); + +enum WeakMapTraceKind { + DoNotTraceWeakMaps = 0, + TraceWeakMapValues = 1, + TraceWeakMapKeysValues = 2 +}; + +class JS_PUBLIC_API(JSTracer) +{ + public: + JSTracer(JSRuntime *rt, JSTraceCallback traceCallback, + WeakMapTraceKind weakTraceKind = TraceWeakMapValues); + + // Set debugging information about a reference to a traceable thing to prepare + // for the following call to JS_CallTracer. + // + // When printer is null, arg must be const char * or char * C string naming + // the reference and index must be either (size_t)-1 indicating that the name + // alone describes the reference or it must be an index into some array vector + // that stores the reference. + // + // When printer callback is not null, the arg and index arguments are + // available to the callback as debugPrintArg_ and debugPrintIndex_ fields + // of JSTracer. + // + // The storage for name or callback's arguments needs to live only until + // the following call to JS_CallTracer returns. + void setTracingDetails(JSTraceNamePrinter printer, const void *arg, size_t index) { + debugPrinter_ = printer; + debugPrintArg_ = arg; + debugPrintIndex_ = index; + } + + void setTracingIndex(const char *name, size_t index) { + setTracingDetails(nullptr, (void *)name, index); + } + + void setTracingName(const char *name) { + setTracingDetails(nullptr, (void *)name, size_t(-1)); + } + + // Remove the currently set tracing details. + void clearTracingDetails() { + debugPrinter_ = nullptr; + debugPrintArg_ = nullptr; + } + + // Return true if tracing details are currently set. + bool hasTracingDetails() const; + + // Get the string set with the most recent call to setTracingName or return + // fallback if a name printer function has been installed. + const char *tracingName(const char *fallback) const; + + // Build a description of this edge in the heap graph. This call may invoke + // the debug printer, which may inspect arbitrary areas of the heap. + const char *getTracingEdgeName(char *buffer, size_t bufferSize); + + // Access the currently active tracing details. + JSTraceNamePrinter debugPrinter() const; + const void *debugPrintArg() const; + size_t debugPrintIndex() const; + + // Return the runtime set on the tracer. + JSRuntime *runtime() const { return runtime_; } + + // Return the weak map tracing behavior set on this tracer. + WeakMapTraceKind eagerlyTraceWeakMaps() const { return eagerlyTraceWeakMaps_; } + + // Update the trace callback. + void setTraceCallback(JSTraceCallback traceCallback); + +#ifdef JS_GC_ZEAL + // Sets the "real" location for a marked reference, when passing the address + // directly is not feasable. This address is used for matching against the + // store buffer when verifying the correctness of the entrees there. + // + // This is currently complicated by our need to nest calls for Values + // stored as keys in hash tables. + void setTracingLocation(void *location); + void unsetTracingLocation(); + void **tracingLocation(void **thingp); +#else + void setTracingLocation(void *location) {} + void unsetTracingLocation() {} + void **tracingLocation(void **thingp) { return nullptr; } +#endif + + // We expose |callback| directly so that IS_GC_MARKING_TRACER can compare + // it to GCMarker::GrayCallback. + JSTraceCallback callback; + + private: + JSRuntime *runtime_; + JSTraceNamePrinter debugPrinter_; + const void *debugPrintArg_; + size_t debugPrintIndex_; + WeakMapTraceKind eagerlyTraceWeakMaps_; +#ifdef JS_GC_ZEAL + void *realLocation_; +#endif +}; + +// The JS_Call*Tracer family of functions traces the given GC thing reference. +// This performs the tracing action configured on the given JSTracer: +// typically calling the JSTracer::callback or marking the thing as live. +// +// The argument to JS_Call*Tracer is an in-out param: when the function +// returns, the garbage collector might have moved the GC thing. In this case, +// the reference passed to JS_Call*Tracer will be updated to the object's new +// location. Callers of this method are responsible for updating any state +// that is dependent on the object's address. For example, if the object's +// address is used as a key in a hashtable, then the object must be removed +// and re-inserted with the correct hash. +// +extern JS_PUBLIC_API(void) +JS_CallValueTracer(JSTracer *trc, JS::Value *valuep, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallIdTracer(JSTracer *trc, jsid *idp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallObjectTracer(JSTracer *trc, JSObject **objp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallStringTracer(JSTracer *trc, JSString **strp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallScriptTracer(JSTracer *trc, JSScript **scriptp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapValueTracer(JSTracer *trc, JS::Heap *valuep, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapIdTracer(JSTracer *trc, JS::Heap *idp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapObjectTracer(JSTracer *trc, JS::Heap *objp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapStringTracer(JSTracer *trc, JS::Heap *strp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapScriptTracer(JSTracer *trc, JS::Heap *scriptp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallHeapFunctionTracer(JSTracer *trc, JS::Heap *funp, const char *name); + +template +inline void +JS_CallHashSetObjectTracer(JSTracer *trc, HashSetEnum &e, JSObject *const &key, const char *name) +{ + JSObject *updated = key; + trc->setTracingLocation(reinterpret_cast(&const_cast(key))); + JS_CallObjectTracer(trc, &updated, name); + if (updated != key) + e.rekeyFront(key, updated); +} + +// Trace an object that is known to always be tenured. No post barriers are +// required in this case. +extern JS_PUBLIC_API(void) +JS_CallTenuredObjectTracer(JSTracer *trc, JS::TenuredHeap *objp, const char *name); + +extern JS_PUBLIC_API(void) +JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind); + +extern JS_PUBLIC_API(void) +JS_TraceRuntime(JSTracer *trc); + +extern JS_PUBLIC_API(void) +JS_GetTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc, + void *thing, JSGCTraceKind kind, bool includeDetails); + +#endif /* js_TracingAPI_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/TypeDecls.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/TypeDecls.h new file mode 100644 index 0000000000..2a8234218c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/TypeDecls.h @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This file contains public type declarations that are used *frequently*. If +// it doesn't occur at least 10 times in Gecko, it probably shouldn't be in +// here. +// +// It includes only: +// - forward declarations of structs and classes; +// - typedefs; +// - enums (maybe). +// It does *not* contain any struct or class definitions. + +#ifndef js_TypeDecls_h +#define js_TypeDecls_h + +#include +#include + +#include "js-config.h" +#include "mozilla/Char16.h" + +struct JSContext; +class JSFunction; +class JSObject; +class JSScript; +class JSString; +class JSAddonId; + +struct jsid; + +typedef char16_t jschar; + +namespace JS { + +typedef unsigned char Latin1Char; + +class Symbol; +class Value; +template class Handle; +template class MutableHandle; +template class Rooted; +template class PersistentRooted; + +typedef Handle HandleFunction; +typedef Handle HandleId; +typedef Handle HandleObject; +typedef Handle HandleScript; +typedef Handle HandleString; +typedef Handle HandleSymbol; +typedef Handle HandleValue; + +typedef MutableHandle MutableHandleFunction; +typedef MutableHandle MutableHandleId; +typedef MutableHandle MutableHandleObject; +typedef MutableHandle MutableHandleScript; +typedef MutableHandle MutableHandleString; +typedef MutableHandle MutableHandleSymbol; +typedef MutableHandle MutableHandleValue; + +typedef Rooted RootedObject; +typedef Rooted RootedFunction; +typedef Rooted RootedScript; +typedef Rooted RootedString; +typedef Rooted RootedSymbol; +typedef Rooted RootedId; +typedef Rooted RootedValue; + +typedef PersistentRooted PersistentRootedFunction; +typedef PersistentRooted PersistentRootedId; +typedef PersistentRooted PersistentRootedObject; +typedef PersistentRooted PersistentRootedScript; +typedef PersistentRooted PersistentRootedString; +typedef PersistentRooted PersistentRootedSymbol; +typedef PersistentRooted PersistentRootedValue; + +} // namespace JS + +#endif /* js_TypeDecls_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Utility.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Utility.h new file mode 100644 index 0000000000..89c495e411 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Utility.h @@ -0,0 +1,736 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_Utility_h +#define js_Utility_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/Scoped.h" +#include "mozilla/TemplateLib.h" + +#include +#include + +#ifdef JS_OOM_DO_BACKTRACES +#include +#include +#endif + +#include "jstypes.h" + +/* The public JS engine namespace. */ +namespace JS {} + +/* The mozilla-shared reusable template/utility namespace. */ +namespace mozilla {} + +/* The private JS engine namespace. */ +namespace js {} + +/* + * Patterns used by SpiderMonkey to overwrite unused memory. If you are + * accessing an object with one of these pattern, you probably have a dangling + * pointer. + */ +#define JS_FRESH_NURSERY_PATTERN 0x2F +#define JS_SWEPT_NURSERY_PATTERN 0x2B +#define JS_ALLOCATED_NURSERY_PATTERN 0x2D +#define JS_FRESH_TENURED_PATTERN 0x4F +#define JS_SWEPT_TENURED_PATTERN 0x4B +#define JS_ALLOCATED_TENURED_PATTERN 0x4D +#define JS_SWEPT_CODE_PATTERN 0x3b +#define JS_SWEPT_FRAME_PATTERN 0x5b +#define JS_POISONED_FORKJOIN_CHUNK 0xBD + +#define JS_ASSERT(expr) MOZ_ASSERT(expr) +#define JS_ASSERT_IF(cond, expr) MOZ_ASSERT_IF(cond, expr) + +#define JS_STATIC_ASSERT(cond) static_assert(cond, "JS_STATIC_ASSERT") +#define JS_STATIC_ASSERT_IF(cond, expr) MOZ_STATIC_ASSERT_IF(cond, expr, "JS_STATIC_ASSERT_IF") + +extern MOZ_NORETURN JS_PUBLIC_API(void) +JS_Assert(const char *s, const char *file, int ln); + +/* + * Custom allocator support for SpiderMonkey + */ +#if defined JS_USE_CUSTOM_ALLOCATOR +# include "jscustomallocator.h" +#else +# if defined(DEBUG) || defined(JS_OOM_BREAKPOINT) +/* + * In order to test OOM conditions, when the testing function + * oomAfterAllocations COUNT is passed, we fail continuously after the NUM'th + * allocation from now. + */ +extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtin/TestingFunctions.cpp */ +extern JS_PUBLIC_DATA(uint32_t) OOM_counter; /* data race, who cares. */ + +#ifdef JS_OOM_BREAKPOINT +static MOZ_NEVER_INLINE void js_failedAllocBreakpoint() { asm(""); } +#define JS_OOM_CALL_BP_FUNC() js_failedAllocBreakpoint() +#else +#define JS_OOM_CALL_BP_FUNC() do {} while(0) +#endif + +# define JS_OOM_POSSIBLY_FAIL() \ + do \ + { \ + if (++OOM_counter > OOM_maxAllocations) { \ + JS_OOM_CALL_BP_FUNC();\ + return nullptr; \ + } \ + } while (0) + +# else +# define JS_OOM_POSSIBLY_FAIL() do {} while(0) +# endif /* DEBUG || JS_OOM_BREAKPOINT */ + +static inline void* js_malloc(size_t bytes) +{ + JS_OOM_POSSIBLY_FAIL(); + return malloc(bytes); +} + +static inline void* js_calloc(size_t bytes) +{ + JS_OOM_POSSIBLY_FAIL(); + return calloc(bytes, 1); +} + +static inline void* js_calloc(size_t nmemb, size_t size) +{ + JS_OOM_POSSIBLY_FAIL(); + return calloc(nmemb, size); +} + +static inline void* js_realloc(void* p, size_t bytes) +{ + JS_OOM_POSSIBLY_FAIL(); + return realloc(p, bytes); +} + +static inline void js_free(void* p) +{ + free(p); +} +#endif/* JS_USE_CUSTOM_ALLOCATOR */ + +#include + +/* + * Low-level memory management in SpiderMonkey: + * + * ** Do not use the standard malloc/free/realloc: SpiderMonkey allows these + * to be redefined (via JS_USE_CUSTOM_ALLOCATOR) and Gecko even #define's + * these symbols. + * + * ** Do not use the builtin C++ operator new and delete: these throw on + * error and we cannot override them not to. + * + * Allocation: + * + * - If the lifetime of the allocation is tied to the lifetime of a GC-thing + * (that is, finalizing the GC-thing will free the allocation), call one of + * the following functions: + * + * JSContext::{malloc_,realloc_,calloc_,new_} + * JSRuntime::{malloc_,realloc_,calloc_,new_} + * + * These functions accumulate the number of bytes allocated which is used as + * part of the GC-triggering heuristic. + * + * The difference between the JSContext and JSRuntime versions is that the + * cx version reports an out-of-memory error on OOM. (This follows from the + * general SpiderMonkey idiom that a JSContext-taking function reports its + * own errors.) + * + * - Otherwise, use js_malloc/js_realloc/js_calloc/js_free/js_new + * + * Deallocation: + * + * - Ordinarily, use js_free/js_delete. + * + * - For deallocations during GC finalization, use one of the following + * operations on the FreeOp provided to the finalizer: + * + * FreeOp::{free_,delete_} + * + * The advantage of these operations is that the memory is batched and freed + * on another thread. + */ + +#define JS_NEW_BODY(allocator, t, parms) \ + void *memory = allocator(sizeof(t)); \ + return memory ? new(memory) t parms : nullptr; +#define JS_MAKE_BODY(newname, T, parms) \ + T *ptr = newname parms; \ + return mozilla::UniquePtr>(ptr); + +/* + * Given a class which should provide 'new' methods, add + * JS_DECLARE_NEW_METHODS (see JSContext for a usage example). This + * adds news with up to 12 parameters. Add more versions of new below if + * you need more than 12 parameters. + * + * Note: Do not add a ; at the end of a use of JS_DECLARE_NEW_METHODS, + * or the build will break. + */ +#define JS_DECLARE_NEW_METHODS(NEWNAME, ALLOCATOR, QUALIFIERS)\ + template \ + QUALIFIERS T *NEWNAME() MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T, ())\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11)))\ + }\ +\ + template \ + QUALIFIERS T *NEWNAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11, P12 &&p12) MOZ_HEAP_ALLOCATOR {\ + JS_NEW_BODY(ALLOCATOR, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11),\ + mozilla::Forward(p12)))\ + }\ + +/* + * Given a class which should provide 'make' methods, add + * JS_DECLARE_MAKE_METHODS (see JSContext for a usage example). This method + * is functionally the same as JS_DECLARE_NEW_METHODS: it just declares methods + * that return mozilla::UniquePtr instances that will singly-manage ownership + * of the created object. This adds makes with up to 12 parameters. Add more + * versions below if you need more than 12 parameters. + * + * Note: Do not add a ; at the end of a use of JS_DECLARE_MAKE_METHODS, + * or the build will break. + */ +#define JS_DECLARE_MAKE_METHODS(MAKENAME, NEWNAME, QUALIFIERS)\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME() MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T, ())\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1)))\ + }\ +\ + template \ + QUALIFIERS \ +mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11)))\ + }\ +\ + template \ + QUALIFIERS \ + mozilla::UniquePtr> \ + MAKENAME(P1 &&p1, P2 &&p2, P3 &&p3, P4 &&p4, P5 &&p5, P6 &&p6, P7 &&p7, P8 &&p8, P9 &&p9, P10 &&p10, P11 &&p11, P12 &&p12) MOZ_HEAP_ALLOCATOR {\ + JS_MAKE_BODY(NEWNAME, T,\ + (mozilla::Forward(p1),\ + mozilla::Forward(p2),\ + mozilla::Forward(p3),\ + mozilla::Forward(p4),\ + mozilla::Forward(p5),\ + mozilla::Forward(p6),\ + mozilla::Forward(p7),\ + mozilla::Forward(p8),\ + mozilla::Forward(p9),\ + mozilla::Forward(p10),\ + mozilla::Forward(p11),\ + mozilla::Forward(p12)))\ + }\ + +JS_DECLARE_NEW_METHODS(js_new, js_malloc, static MOZ_ALWAYS_INLINE) + +template +static MOZ_ALWAYS_INLINE void +js_delete(T *p) +{ + if (p) { + p->~T(); + js_free(p); + } +} + +template +static MOZ_ALWAYS_INLINE void +js_delete_poison(T *p) +{ + if (p) { + p->~T(); + memset(p, 0x3B, sizeof(T)); + js_free(p); + } +} + +template +static MOZ_ALWAYS_INLINE T * +js_pod_malloc() +{ + return (T *)js_malloc(sizeof(T)); +} + +template +static MOZ_ALWAYS_INLINE T * +js_pod_calloc() +{ + return (T *)js_calloc(sizeof(T)); +} + +template +static MOZ_ALWAYS_INLINE T * +js_pod_malloc(size_t numElems) +{ + if (numElems & mozilla::tl::MulOverflowMask::value) + return nullptr; + return (T *)js_malloc(numElems * sizeof(T)); +} + +template +static MOZ_ALWAYS_INLINE T * +js_pod_calloc(size_t numElems) +{ + if (numElems & mozilla::tl::MulOverflowMask::value) + return nullptr; + return (T *)js_calloc(numElems * sizeof(T)); +} + +namespace js { + +template +struct ScopedFreePtrTraits +{ + typedef T* type; + static T* empty() { return nullptr; } + static void release(T* ptr) { js_free(ptr); } +}; +SCOPED_TEMPLATE(ScopedJSFreePtr, ScopedFreePtrTraits) + +template +struct ScopedDeletePtrTraits : public ScopedFreePtrTraits +{ + static void release(T *ptr) { js_delete(ptr); } +}; +SCOPED_TEMPLATE(ScopedJSDeletePtr, ScopedDeletePtrTraits) + +template +struct ScopedReleasePtrTraits : public ScopedFreePtrTraits +{ + static void release(T *ptr) { if (ptr) ptr->release(); } +}; +SCOPED_TEMPLATE(ScopedReleasePtr, ScopedReleasePtrTraits) + +} /* namespace js */ + +namespace JS { + +template +struct DeletePolicy +{ + void operator()(T* ptr) { + js_delete(ptr); + } +}; + +struct FreePolicy +{ + void operator()(void* ptr) { + js_free(ptr); + } +}; + +} // namespace JS + +namespace js { + +/* Integral types for all hash functions. */ +typedef uint32_t HashNumber; +const unsigned HashNumberSizeBits = 32; + +namespace detail { + +/* + * Given a raw hash code, h, return a number that can be used to select a hash + * bucket. + * + * This function aims to produce as uniform an output distribution as possible, + * especially in the most significant (leftmost) bits, even though the input + * distribution may be highly nonrandom, given the constraints that this must + * be deterministic and quick to compute. + * + * Since the leftmost bits of the result are best, the hash bucket index is + * computed by doing ScrambleHashCode(h) / (2^32/N) or the equivalent + * right-shift, not ScrambleHashCode(h) % N or the equivalent bit-mask. + * + * FIXME: OrderedHashTable uses a bit-mask; see bug 775896. + */ +inline HashNumber +ScrambleHashCode(HashNumber h) +{ + /* + * Simply returning h would not cause any hash tables to produce wrong + * answers. But it can produce pathologically bad performance: The caller + * right-shifts the result, keeping only the highest bits. The high bits of + * hash codes are very often completely entropy-free. (So are the lowest + * bits.) + * + * So we use Fibonacci hashing, as described in Knuth, The Art of Computer + * Programming, 6.4. This mixes all the bits of the input hash code h. + * + * The value of goldenRatio is taken from the hex + * expansion of the golden ratio, which starts 1.9E3779B9.... + * This value is especially good if values with consecutive hash codes + * are stored in a hash table; see Knuth for details. + */ + static const HashNumber goldenRatio = 0x9E3779B9U; + return h * goldenRatio; +} + +} /* namespace detail */ + +} /* namespace js */ + +namespace JS { + +/* + * Methods for poisoning GC heap pointer words and checking for poisoned words. + * These are in this file for use in Value methods and so forth. + * + * If the moving GC hazard analysis is in use and detects a non-rooted stack + * pointer to a GC thing, one byte of that pointer is poisoned to refer to an + * invalid location. For both 32 bit and 64 bit systems, the fourth byte of the + * pointer is overwritten, to reduce the likelihood of accidentally changing + * a live integer value. + */ + +inline void PoisonPtr(void *v) +{ +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) + uint8_t *ptr = (uint8_t *) v + 3; + *ptr = JS_FREE_PATTERN; +#endif +} + +template +inline bool IsPoisonedPtr(T *v) +{ +#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG) + uint32_t mask = uintptr_t(v) & 0xff000000; + return mask == uint32_t(JS_FREE_PATTERN << 24); +#else + return false; +#endif +} + +} + +/* sixgill annotation defines */ +#ifndef HAVE_STATIC_ANNOTATIONS +# define HAVE_STATIC_ANNOTATIONS +# ifdef XGILL_PLUGIN +# define STATIC_PRECONDITION(COND) __attribute__((precondition(#COND))) +# define STATIC_PRECONDITION_ASSUME(COND) __attribute__((precondition_assume(#COND))) +# define STATIC_POSTCONDITION(COND) __attribute__((postcondition(#COND))) +# define STATIC_POSTCONDITION_ASSUME(COND) __attribute__((postcondition_assume(#COND))) +# define STATIC_INVARIANT(COND) __attribute__((invariant(#COND))) +# define STATIC_INVARIANT_ASSUME(COND) __attribute__((invariant_assume(#COND))) +# define STATIC_PASTE2(X,Y) X ## Y +# define STATIC_PASTE1(X,Y) STATIC_PASTE2(X,Y) +# define STATIC_ASSERT(COND) \ + JS_BEGIN_MACRO \ + __attribute__((assert_static(#COND), unused)) \ + int STATIC_PASTE1(assert_static_, __COUNTER__); \ + JS_END_MACRO +# define STATIC_ASSUME(COND) \ + JS_BEGIN_MACRO \ + __attribute__((assume_static(#COND), unused)) \ + int STATIC_PASTE1(assume_static_, __COUNTER__); \ + JS_END_MACRO +# define STATIC_ASSERT_RUNTIME(COND) \ + JS_BEGIN_MACRO \ + __attribute__((assert_static_runtime(#COND), unused)) \ + int STATIC_PASTE1(assert_static_runtime_, __COUNTER__); \ + JS_END_MACRO +# else /* XGILL_PLUGIN */ +# define STATIC_PRECONDITION(COND) /* nothing */ +# define STATIC_PRECONDITION_ASSUME(COND) /* nothing */ +# define STATIC_POSTCONDITION(COND) /* nothing */ +# define STATIC_POSTCONDITION_ASSUME(COND) /* nothing */ +# define STATIC_INVARIANT(COND) /* nothing */ +# define STATIC_INVARIANT_ASSUME(COND) /* nothing */ +# define STATIC_ASSERT(COND) JS_BEGIN_MACRO /* nothing */ JS_END_MACRO +# define STATIC_ASSUME(COND) JS_BEGIN_MACRO /* nothing */ JS_END_MACRO +# define STATIC_ASSERT_RUNTIME(COND) JS_BEGIN_MACRO /* nothing */ JS_END_MACRO +# endif /* XGILL_PLUGIN */ +# define STATIC_SKIP_INFERENCE STATIC_INVARIANT(skip_inference()) +#endif /* HAVE_STATIC_ANNOTATIONS */ + +#endif /* js_Utility_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Value.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Value.h new file mode 100644 index 0000000000..e7b89e684d --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Value.h @@ -0,0 +1,2003 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JS::Value implementation. */ + +#ifndef js_Value_h +#define js_Value_h + +#include "mozilla/Attributes.h" +#include "mozilla/FloatingPoint.h" +#include "mozilla/Likely.h" + +#include /* for std::numeric_limits */ + +#include "js-config.h" +#include "jstypes.h" + +#include "js/Anchor.h" +#include "js/GCAPI.h" +#include "js/RootingAPI.h" +#include "js/Utility.h" + +namespace JS { class Value; } + +/* JS::Value can store a full int32_t. */ +#define JSVAL_INT_BITS 32 +#define JSVAL_INT_MIN ((int32_t)0x80000000) +#define JSVAL_INT_MAX ((int32_t)0x7fffffff) + +/* + * Try to get jsvals 64-bit aligned. We could almost assert that all values are + * aligned, but MSVC and GCC occasionally break alignment. + */ +#if defined(__GNUC__) || defined(__xlc__) || defined(__xlC__) +# define JSVAL_ALIGNMENT __attribute__((aligned (8))) +#elif defined(_MSC_VER) + /* + * Structs can be aligned with MSVC, but not if they are used as parameters, + * so we just don't try to align. + */ +# define JSVAL_ALIGNMENT +#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) +# define JSVAL_ALIGNMENT +#elif defined(__HP_cc) || defined(__HP_aCC) +# define JSVAL_ALIGNMENT +#endif + +#if defined(JS_PUNBOX64) +# define JSVAL_TAG_SHIFT 47 +#endif + +/* + * We try to use enums so that printing a jsval_layout in the debugger shows + * nice symbolic type tags, however we can only do this when we can force the + * underlying type of the enum to be the desired size. + */ +#if !defined(__SUNPRO_CC) && !defined(__xlC__) + +#if defined(_MSC_VER) +# define JS_ENUM_HEADER(id, type) enum id : type +# define JS_ENUM_FOOTER(id) +#else +# define JS_ENUM_HEADER(id, type) enum id +# define JS_ENUM_FOOTER(id) __attribute__((packed)) +#endif + +/* Remember to propagate changes to the C defines below. */ +JS_ENUM_HEADER(JSValueType, uint8_t) +{ + JSVAL_TYPE_DOUBLE = 0x00, + JSVAL_TYPE_INT32 = 0x01, + JSVAL_TYPE_UNDEFINED = 0x02, + JSVAL_TYPE_BOOLEAN = 0x03, + JSVAL_TYPE_MAGIC = 0x04, + JSVAL_TYPE_STRING = 0x05, + JSVAL_TYPE_SYMBOL = 0x06, + JSVAL_TYPE_NULL = 0x07, + JSVAL_TYPE_OBJECT = 0x08, + + /* These never appear in a jsval; they are only provided as an out-of-band value. */ + JSVAL_TYPE_UNKNOWN = 0x20, + JSVAL_TYPE_MISSING = 0x21 +} JS_ENUM_FOOTER(JSValueType); + +JS_STATIC_ASSERT(sizeof(JSValueType) == 1); + +#if defined(JS_NUNBOX32) + +/* Remember to propagate changes to the C defines below. */ +JS_ENUM_HEADER(JSValueTag, uint32_t) +{ + JSVAL_TAG_CLEAR = 0xFFFFFF80, + JSVAL_TAG_INT32 = JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32, + JSVAL_TAG_UNDEFINED = JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED, + JSVAL_TAG_STRING = JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL, + JSVAL_TAG_BOOLEAN = JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN, + JSVAL_TAG_MAGIC = JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC, + JSVAL_TAG_NULL = JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL, + JSVAL_TAG_OBJECT = JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT +} JS_ENUM_FOOTER(JSValueTag); + +JS_STATIC_ASSERT(sizeof(JSValueTag) == 4); + +#elif defined(JS_PUNBOX64) + +/* Remember to propagate changes to the C defines below. */ +JS_ENUM_HEADER(JSValueTag, uint32_t) +{ + JSVAL_TAG_MAX_DOUBLE = 0x1FFF0, + JSVAL_TAG_INT32 = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32, + JSVAL_TAG_UNDEFINED = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED, + JSVAL_TAG_STRING = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING, + JSVAL_TAG_SYMBOL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL, + JSVAL_TAG_BOOLEAN = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN, + JSVAL_TAG_MAGIC = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC, + JSVAL_TAG_NULL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL, + JSVAL_TAG_OBJECT = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_OBJECT +} JS_ENUM_FOOTER(JSValueTag); + +JS_STATIC_ASSERT(sizeof(JSValueTag) == sizeof(uint32_t)); + +JS_ENUM_HEADER(JSValueShiftedTag, uint64_t) +{ + JSVAL_SHIFTED_TAG_MAX_DOUBLE = ((((uint64_t)JSVAL_TAG_MAX_DOUBLE) << JSVAL_TAG_SHIFT) | 0xFFFFFFFF), + JSVAL_SHIFTED_TAG_INT32 = (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_UNDEFINED = (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_STRING = (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_SYMBOL = (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_BOOLEAN = (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_MAGIC = (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_NULL = (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT), + JSVAL_SHIFTED_TAG_OBJECT = (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT) +} JS_ENUM_FOOTER(JSValueShiftedTag); + +JS_STATIC_ASSERT(sizeof(JSValueShiftedTag) == sizeof(uint64_t)); + +#endif + +#else /* !defined(__SUNPRO_CC) && !defined(__xlC__) */ + +typedef uint8_t JSValueType; +#define JSVAL_TYPE_DOUBLE ((uint8_t)0x00) +#define JSVAL_TYPE_INT32 ((uint8_t)0x01) +#define JSVAL_TYPE_UNDEFINED ((uint8_t)0x02) +#define JSVAL_TYPE_BOOLEAN ((uint8_t)0x03) +#define JSVAL_TYPE_MAGIC ((uint8_t)0x04) +#define JSVAL_TYPE_STRING ((uint8_t)0x05) +#define JSVAL_TYPE_SYMBOL ((uint8_t)0x06) +#define JSVAL_TYPE_NULL ((uint8_t)0x07) +#define JSVAL_TYPE_OBJECT ((uint8_t)0x08) +#define JSVAL_TYPE_UNKNOWN ((uint8_t)0x20) + +#if defined(JS_NUNBOX32) + +typedef uint32_t JSValueTag; +#define JSVAL_TAG_CLEAR ((uint32_t)(0xFFFFFF80)) +#define JSVAL_TAG_INT32 ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32)) +#define JSVAL_TAG_UNDEFINED ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED)) +#define JSVAL_TAG_STRING ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING)) +#define JSVAL_TAG_SYMBOL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL)) +#define JSVAL_TAG_BOOLEAN ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN)) +#define JSVAL_TAG_MAGIC ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC)) +#define JSVAL_TAG_NULL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL)) +#define JSVAL_TAG_OBJECT ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT)) + +#elif defined(JS_PUNBOX64) + +typedef uint32_t JSValueTag; +#define JSVAL_TAG_MAX_DOUBLE ((uint32_t)(0x1FFF0)) +#define JSVAL_TAG_INT32 (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32) +#define JSVAL_TAG_UNDEFINED (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED) +#define JSVAL_TAG_STRING (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING) +#define JSVAL_TAG_SYMBOL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL) +#define JSVAL_TAG_BOOLEAN (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN) +#define JSVAL_TAG_MAGIC (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC) +#define JSVAL_TAG_NULL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL) +#define JSVAL_TAG_OBJECT (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_OBJECT) + +typedef uint64_t JSValueShiftedTag; +#define JSVAL_SHIFTED_TAG_MAX_DOUBLE ((((uint64_t)JSVAL_TAG_MAX_DOUBLE) << JSVAL_TAG_SHIFT) | 0xFFFFFFFF) +#define JSVAL_SHIFTED_TAG_INT32 (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_UNDEFINED (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_STRING (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_SYMBOL (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_BOOLEAN (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_MAGIC (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_NULL (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT) +#define JSVAL_SHIFTED_TAG_OBJECT (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT) + +#endif /* JS_PUNBOX64 */ +#endif /* !defined(__SUNPRO_CC) && !defined(__xlC__) */ + +#if defined(JS_NUNBOX32) + +#define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_CLEAR | (type))) + +#define JSVAL_LOWER_INCL_TAG_OF_OBJ_OR_NULL_SET JSVAL_TAG_NULL +#define JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET JSVAL_TAG_OBJECT +#define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32 +#define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING + +#elif defined(JS_PUNBOX64) + +#define JSVAL_PAYLOAD_MASK 0x00007FFFFFFFFFFFLL +#define JSVAL_TAG_MASK 0xFFFF800000000000LL +#define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_MAX_DOUBLE | (type))) +#define JSVAL_TYPE_TO_SHIFTED_TAG(type) (((uint64_t)JSVAL_TYPE_TO_TAG(type)) << JSVAL_TAG_SHIFT) + +#define JSVAL_LOWER_INCL_TAG_OF_OBJ_OR_NULL_SET JSVAL_TAG_NULL +#define JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET JSVAL_TAG_OBJECT +#define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32 +#define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING + +#define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_OBJ_OR_NULL_SET JSVAL_SHIFTED_TAG_NULL +#define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_PRIMITIVE_SET JSVAL_SHIFTED_TAG_OBJECT +#define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET JSVAL_SHIFTED_TAG_UNDEFINED +#define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET JSVAL_SHIFTED_TAG_STRING + +#endif /* JS_PUNBOX64 */ + +typedef enum JSWhyMagic +{ + JS_ELEMENTS_HOLE, /* a hole in a native object's elements */ + JS_NATIVE_ENUMERATE, /* indicates that a custom enumerate hook forwarded + * to JS_EnumerateState, which really means the object can be + * enumerated like a native object. */ + JS_NO_ITER_VALUE, /* there is not a pending iterator value */ + JS_GENERATOR_CLOSING, /* exception value thrown when closing a generator */ + JS_NO_CONSTANT, /* compiler sentinel value */ + JS_THIS_POISON, /* used in debug builds to catch tracing errors */ + JS_ARG_POISON, /* used in debug builds to catch tracing errors */ + JS_SERIALIZE_NO_NODE, /* an empty subnode in the AST serializer */ + JS_LAZY_ARGUMENTS, /* lazy arguments value on the stack */ + JS_OPTIMIZED_ARGUMENTS, /* optimized-away 'arguments' value */ + JS_IS_CONSTRUCTING, /* magic value passed to natives to indicate construction */ + JS_OVERWRITTEN_CALLEE, /* arguments.callee has been overwritten */ + JS_BLOCK_NEEDS_CLONE, /* value of static block object slot */ + JS_HASH_KEY_EMPTY, /* see class js::HashableValue */ + JS_ION_ERROR, /* error while running Ion code */ + JS_ION_BAILOUT, /* missing recover instruction result */ + JS_OPTIMIZED_OUT, /* optimized out slot */ + JS_GENERIC_MAGIC /* for local use */ +} JSWhyMagic; + +#if defined(IS_LITTLE_ENDIAN) +# if defined(JS_NUNBOX32) +typedef union jsval_layout +{ + uint64_t asBits; + struct { + union { + int32_t i32; + uint32_t u32; + uint32_t boo; // Don't use |bool| -- it must be four bytes. + JSString *str; + JS::Symbol *sym; + JSObject *obj; + js::gc::Cell *cell; + void *ptr; + JSWhyMagic why; + size_t word; + uintptr_t uintptr; + } payload; + JSValueTag tag; + } s; + double asDouble; + void *asPtr; +} JSVAL_ALIGNMENT jsval_layout; +# elif defined(JS_PUNBOX64) +typedef union jsval_layout +{ + uint64_t asBits; +#if !defined(_WIN64) + /* MSVC does not pack these correctly :-( */ + struct { + uint64_t payload47 : 47; + JSValueTag tag : 17; + } debugView; +#endif + struct { + union { + int32_t i32; + uint32_t u32; + JSWhyMagic why; + } payload; + } s; + double asDouble; + void *asPtr; + size_t asWord; + uintptr_t asUIntPtr; +} JSVAL_ALIGNMENT jsval_layout; +# endif /* JS_PUNBOX64 */ +#else /* defined(IS_LITTLE_ENDIAN) */ +# if defined(JS_NUNBOX32) +typedef union jsval_layout +{ + uint64_t asBits; + struct { + JSValueTag tag; + union { + int32_t i32; + uint32_t u32; + uint32_t boo; // Don't use |bool| -- it must be four bytes. + JSString *str; + JS::Symbol *sym; + JSObject *obj; + js::gc::Cell *cell; + void *ptr; + JSWhyMagic why; + size_t word; + uintptr_t uintptr; + } payload; + } s; + double asDouble; + void *asPtr; +} JSVAL_ALIGNMENT jsval_layout; +# elif defined(JS_PUNBOX64) +typedef union jsval_layout +{ + uint64_t asBits; + struct { + JSValueTag tag : 17; + uint64_t payload47 : 47; + } debugView; + struct { + uint32_t padding; + union { + int32_t i32; + uint32_t u32; + JSWhyMagic why; + } payload; + } s; + double asDouble; + void *asPtr; + size_t asWord; + uintptr_t asUIntPtr; +} JSVAL_ALIGNMENT jsval_layout; +# endif /* JS_PUNBOX64 */ +#endif /* defined(IS_LITTLE_ENDIAN) */ + +JS_STATIC_ASSERT(sizeof(jsval_layout) == 8); + +/* + * For codesize purposes on some platforms, it's important that the + * compiler know that JS::Values constructed from constant values can be + * folded to constant bit patterns at compile time, rather than + * constructed at runtime. Doing this requires a fair amount of C++11 + * features, which are not supported on all of our compilers. Set up + * some defines and helper macros in an attempt to confine the ugliness + * here, rather than scattering it all about the file. The important + * features are: + * + * - constexpr; + * - defaulted functions; + * - C99-style designated initializers. + */ +#if defined(__clang__) +# if __has_feature(cxx_constexpr) && __has_feature(cxx_defaulted_functions) +# define JS_VALUE_IS_CONSTEXPR +# endif +#elif defined(__GNUC__) +/* + * We need 4.5 for defaulted functions, 4.6 for constexpr, 4.7 because 4.6 + * doesn't understand |(X) { .field = ... }| syntax, and 4.7.3 because + * versions prior to that have bugs in the C++ front-end that cause crashes. + */ +# if MOZ_GCC_VERSION_AT_LEAST(4, 7, 3) +# define JS_VALUE_IS_CONSTEXPR +# endif +#endif + +#if defined(JS_VALUE_IS_CONSTEXPR) +# define JS_RETURN_LAYOUT_FROM_BITS(BITS) \ + return (jsval_layout) { .asBits = (BITS) } +# define JS_VALUE_CONSTEXPR MOZ_CONSTEXPR +# define JS_VALUE_CONSTEXPR_VAR MOZ_CONSTEXPR_VAR +#else +# define JS_RETURN_LAYOUT_FROM_BITS(BITS) \ + jsval_layout l; \ + l.asBits = (BITS); \ + return l; +# define JS_VALUE_CONSTEXPR +# define JS_VALUE_CONSTEXPR_VAR const +#endif + +#if defined(JS_NUNBOX32) + +/* + * N.B. GCC, in some but not all cases, chooses to emit signed comparison of + * JSValueTag even though its underlying type has been forced to be uint32_t. + * Thus, all comparisons should explicitly cast operands to uint32_t. + */ + +static inline JS_VALUE_CONSTEXPR jsval_layout +BUILD_JSVAL(JSValueTag tag, uint32_t payload) +{ + JS_RETURN_LAYOUT_FROM_BITS((((uint64_t)(uint32_t)tag) << 32) | payload); +} + +static inline bool +JSVAL_IS_DOUBLE_IMPL(jsval_layout l) +{ + return (uint32_t)l.s.tag <= (uint32_t)JSVAL_TAG_CLEAR; +} + +static inline jsval_layout +DOUBLE_TO_JSVAL_IMPL(double d) +{ + jsval_layout l; + l.asDouble = d; + MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(l)); + return l; +} + +static inline bool +JSVAL_IS_INT32_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_INT32; +} + +static inline int32_t +JSVAL_TO_INT32_IMPL(jsval_layout l) +{ + return l.s.payload.i32; +} + +static inline JS_VALUE_CONSTEXPR jsval_layout +INT32_TO_JSVAL_IMPL(int32_t i) +{ +#if defined(JS_VALUE_IS_CONSTEXPR) + return BUILD_JSVAL(JSVAL_TAG_INT32, i); +#else + jsval_layout l; + l.s.tag = JSVAL_TAG_INT32; + l.s.payload.i32 = i; + return l; +#endif +} + +static inline bool +JSVAL_IS_NUMBER_IMPL(jsval_layout l) +{ + JSValueTag tag = l.s.tag; + MOZ_ASSERT(tag != JSVAL_TAG_CLEAR); + return (uint32_t)tag <= (uint32_t)JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET; +} + +static inline bool +JSVAL_IS_UNDEFINED_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_UNDEFINED; +} + +static inline bool +JSVAL_IS_STRING_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_STRING; +} + +static inline jsval_layout +STRING_TO_JSVAL_IMPL(JSString *str) +{ + jsval_layout l; + MOZ_ASSERT(uintptr_t(str) > 0x1000); + l.s.tag = JSVAL_TAG_STRING; + l.s.payload.str = str; + return l; +} + +static inline JSString * +JSVAL_TO_STRING_IMPL(jsval_layout l) +{ + return l.s.payload.str; +} + +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + l.s.tag = JSVAL_TAG_SYMBOL; + l.s.payload.sym = sym; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return l.s.payload.sym; +} + +static inline bool +JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_BOOLEAN; +} + +static inline bool +JSVAL_TO_BOOLEAN_IMPL(jsval_layout l) +{ + return l.s.payload.boo; +} + +static inline jsval_layout +BOOLEAN_TO_JSVAL_IMPL(bool b) +{ + jsval_layout l; + l.s.tag = JSVAL_TAG_BOOLEAN; + l.s.payload.boo = b; + return l; +} + +static inline bool +JSVAL_IS_MAGIC_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_MAGIC; +} + +static inline bool +JSVAL_IS_OBJECT_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_OBJECT; +} + +static inline bool +JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l) +{ + return (uint32_t)l.s.tag < (uint32_t)JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET; +} + +static inline bool +JSVAL_IS_OBJECT_OR_NULL_IMPL(jsval_layout l) +{ + MOZ_ASSERT((uint32_t)l.s.tag <= (uint32_t)JSVAL_TAG_OBJECT); + return (uint32_t)l.s.tag >= (uint32_t)JSVAL_LOWER_INCL_TAG_OF_OBJ_OR_NULL_SET; +} + +static inline JSObject * +JSVAL_TO_OBJECT_IMPL(jsval_layout l) +{ + return l.s.payload.obj; +} + +static inline jsval_layout +OBJECT_TO_JSVAL_IMPL(JSObject *obj) +{ + jsval_layout l; + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); + l.s.tag = JSVAL_TAG_OBJECT; + l.s.payload.obj = obj; + return l; +} + +static inline bool +JSVAL_IS_NULL_IMPL(jsval_layout l) +{ + return l.s.tag == JSVAL_TAG_NULL; +} + +static inline jsval_layout +PRIVATE_PTR_TO_JSVAL_IMPL(void *ptr) +{ + jsval_layout l; + MOZ_ASSERT(((uint32_t)ptr & 1) == 0); + l.s.tag = (JSValueTag)0; + l.s.payload.ptr = ptr; + MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(l)); + return l; +} + +static inline void * +JSVAL_TO_PRIVATE_PTR_IMPL(jsval_layout l) +{ + return l.s.payload.ptr; +} + +static inline bool +JSVAL_IS_GCTHING_IMPL(jsval_layout l) +{ + /* gcc sometimes generates signed < without explicit casts. */ + return (uint32_t)l.s.tag >= (uint32_t)JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET; +} + +static inline js::gc::Cell * +JSVAL_TO_GCTHING_IMPL(jsval_layout l) +{ + return l.s.payload.cell; +} + +static inline uint32_t +JSVAL_TRACE_KIND_IMPL(jsval_layout l) +{ + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return l.s.tag & 0x03; +} + +static inline bool +JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) +{ + return l.s.tag == JSVAL_TAG_INT32 && l.s.payload.i32 == i32; +} + +static inline bool +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) +{ + return (l.s.tag == JSVAL_TAG_BOOLEAN) && (l.s.payload.boo == uint32_t(b)); +} + +static inline jsval_layout +MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) +{ + jsval_layout l; + l.s.tag = JSVAL_TAG_MAGIC; + l.s.payload.why = why; + return l; +} + +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.s.tag = JSVAL_TAG_MAGIC; + l.s.payload.u32 = payload; + return l; +} + +static inline bool +JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) +{ + JSValueTag ltag = lhs.s.tag, rtag = rhs.s.tag; + return ltag == rtag || (ltag < JSVAL_TAG_CLEAR && rtag < JSVAL_TAG_CLEAR); +} + +static inline JSValueType +JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) +{ + uint32_t type = l.s.tag & 0xF; + MOZ_ASSERT(type > JSVAL_TYPE_DOUBLE); + return (JSValueType)type; +} + +#elif defined(JS_PUNBOX64) + +static inline JS_VALUE_CONSTEXPR jsval_layout +BUILD_JSVAL(JSValueTag tag, uint64_t payload) +{ + JS_RETURN_LAYOUT_FROM_BITS((((uint64_t)(uint32_t)tag) << JSVAL_TAG_SHIFT) | payload); +} + +static inline bool +JSVAL_IS_DOUBLE_IMPL(jsval_layout l) +{ + return l.asBits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE; +} + +static inline jsval_layout +DOUBLE_TO_JSVAL_IMPL(double d) +{ + jsval_layout l; + l.asDouble = d; + MOZ_ASSERT(l.asBits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE); + return l; +} + +static inline bool +JSVAL_IS_INT32_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_INT32; +} + +static inline int32_t +JSVAL_TO_INT32_IMPL(jsval_layout l) +{ + return (int32_t)l.asBits; +} + +static inline JS_VALUE_CONSTEXPR jsval_layout +INT32_TO_JSVAL_IMPL(int32_t i32) +{ + JS_RETURN_LAYOUT_FROM_BITS(((uint64_t)(uint32_t)i32) | JSVAL_SHIFTED_TAG_INT32); +} + +static inline bool +JSVAL_IS_NUMBER_IMPL(jsval_layout l) +{ + return l.asBits < JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET; +} + +static inline bool +JSVAL_IS_UNDEFINED_IMPL(jsval_layout l) +{ + return l.asBits == JSVAL_SHIFTED_TAG_UNDEFINED; +} + +static inline bool +JSVAL_IS_STRING_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_STRING; +} + +static inline jsval_layout +STRING_TO_JSVAL_IMPL(JSString *str) +{ + jsval_layout l; + uint64_t strBits = (uint64_t)str; + MOZ_ASSERT(uintptr_t(str) > 0x1000); + MOZ_ASSERT((strBits >> JSVAL_TAG_SHIFT) == 0); + l.asBits = strBits | JSVAL_SHIFTED_TAG_STRING; + return l; +} + +static inline JSString * +JSVAL_TO_STRING_IMPL(jsval_layout l) +{ + return (JSString *)(l.asBits & JSVAL_PAYLOAD_MASK); +} + +static inline bool +JSVAL_IS_SYMBOL_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_SYMBOL; +} + +static inline jsval_layout +SYMBOL_TO_JSVAL_IMPL(JS::Symbol *sym) +{ + jsval_layout l; + uint64_t symBits = (uint64_t)sym; + MOZ_ASSERT(uintptr_t(sym) > 0x1000); + MOZ_ASSERT((symBits >> JSVAL_TAG_SHIFT) == 0); + l.asBits = symBits | JSVAL_SHIFTED_TAG_SYMBOL; + return l; +} + +static inline JS::Symbol * +JSVAL_TO_SYMBOL_IMPL(jsval_layout l) +{ + return (JS::Symbol *)(l.asBits & JSVAL_PAYLOAD_MASK); +} + +static inline bool +JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) +{ + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_BOOLEAN; +} + +static inline bool +JSVAL_TO_BOOLEAN_IMPL(jsval_layout l) +{ + return (bool)(l.asBits & JSVAL_PAYLOAD_MASK); +} + +static inline jsval_layout +BOOLEAN_TO_JSVAL_IMPL(bool b) +{ + jsval_layout l; + l.asBits = ((uint64_t)(uint32_t)b) | JSVAL_SHIFTED_TAG_BOOLEAN; + return l; +} + +static inline bool +JSVAL_IS_MAGIC_IMPL(jsval_layout l) +{ + return (l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_MAGIC; +} + +static inline bool +JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l) +{ + return l.asBits < JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_PRIMITIVE_SET; +} + +static inline bool +JSVAL_IS_OBJECT_IMPL(jsval_layout l) +{ + MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_TAG_OBJECT); + return l.asBits >= JSVAL_SHIFTED_TAG_OBJECT; +} + +static inline bool +JSVAL_IS_OBJECT_OR_NULL_IMPL(jsval_layout l) +{ + MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_TAG_OBJECT); + return l.asBits >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_OBJ_OR_NULL_SET; +} + +static inline JSObject * +JSVAL_TO_OBJECT_IMPL(jsval_layout l) +{ + uint64_t ptrBits = l.asBits & JSVAL_PAYLOAD_MASK; + MOZ_ASSERT((ptrBits & 0x7) == 0); + return (JSObject *)ptrBits; +} + +static inline jsval_layout +OBJECT_TO_JSVAL_IMPL(JSObject *obj) +{ + jsval_layout l; + uint64_t objBits = (uint64_t)obj; + MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42); + MOZ_ASSERT((objBits >> JSVAL_TAG_SHIFT) == 0); + l.asBits = objBits | JSVAL_SHIFTED_TAG_OBJECT; + return l; +} + +static inline bool +JSVAL_IS_NULL_IMPL(jsval_layout l) +{ + return l.asBits == JSVAL_SHIFTED_TAG_NULL; +} + +static inline bool +JSVAL_IS_GCTHING_IMPL(jsval_layout l) +{ + return l.asBits >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET; +} + +static inline js::gc::Cell * +JSVAL_TO_GCTHING_IMPL(jsval_layout l) +{ + uint64_t ptrBits = l.asBits & JSVAL_PAYLOAD_MASK; + MOZ_ASSERT((ptrBits & 0x7) == 0); + return reinterpret_cast(ptrBits); +} + +static inline uint32_t +JSVAL_TRACE_KIND_IMPL(jsval_layout l) +{ + static_assert((JSVAL_TAG_STRING & 0x03) == JSTRACE_STRING, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_SYMBOL & 0x03) == JSTRACE_SYMBOL, + "Value type tags must correspond with JSGCTraceKinds."); + static_assert((JSVAL_TAG_OBJECT & 0x03) == JSTRACE_OBJECT, + "Value type tags must correspond with JSGCTraceKinds."); + return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) & 0x03; +} + +static inline jsval_layout +PRIVATE_PTR_TO_JSVAL_IMPL(void *ptr) +{ + jsval_layout l; + uint64_t ptrBits = (uint64_t)ptr; + MOZ_ASSERT((ptrBits & 1) == 0); + l.asBits = ptrBits >> 1; + MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(l)); + return l; +} + +static inline void * +JSVAL_TO_PRIVATE_PTR_IMPL(jsval_layout l) +{ + MOZ_ASSERT((l.asBits & 0x8000000000000000LL) == 0); + return (void *)(l.asBits << 1); +} + +static inline bool +JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32) +{ + return l.asBits == (((uint64_t)(uint32_t)i32) | JSVAL_SHIFTED_TAG_INT32); +} + +static inline bool +JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b) +{ + return l.asBits == (((uint64_t)(uint32_t)b) | JSVAL_SHIFTED_TAG_BOOLEAN); +} + +static inline jsval_layout +MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) +{ + jsval_layout l; + l.asBits = ((uint64_t)(uint32_t)why) | JSVAL_SHIFTED_TAG_MAGIC; + return l; +} + +static inline jsval_layout +MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload) +{ + jsval_layout l; + l.asBits = ((uint64_t)payload) | JSVAL_SHIFTED_TAG_MAGIC; + return l; +} + +static inline bool +JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) +{ + uint64_t lbits = lhs.asBits, rbits = rhs.asBits; + return (lbits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE && rbits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE) || + (((lbits ^ rbits) & 0xFFFF800000000000LL) == 0); +} + +static inline JSValueType +JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) +{ + uint64_t type = (l.asBits >> JSVAL_TAG_SHIFT) & 0xF; + MOZ_ASSERT(type > JSVAL_TYPE_DOUBLE); + return (JSValueType)type; +} + +#endif /* JS_PUNBOX64 */ + +static inline bool +JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) +{ + return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l); +} + +static inline jsval_layout JSVAL_TO_IMPL(JS::Value v); +static inline JS_VALUE_CONSTEXPR JS::Value IMPL_TO_JSVAL(jsval_layout l); + +namespace JS { + +static inline JS_VALUE_CONSTEXPR JS::Value UndefinedValue(); + +/** + * Returns a generic quiet NaN value, with all payload bits set to zero. + * + * Among other properties, this NaN's bit pattern conforms to JS::Value's + * bit pattern restrictions. + */ +static MOZ_ALWAYS_INLINE double +GenericNaN() +{ + return mozilla::SpecificNaN(0, 0x8000000000000ULL); +} + +/* MSVC with PGO miscompiles this function. */ +#if defined(_MSC_VER) +# pragma optimize("g", off) +#endif +static inline double +CanonicalizeNaN(double d) +{ + if (MOZ_UNLIKELY(mozilla::IsNaN(d))) + return GenericNaN(); + return d; +} +#if defined(_MSC_VER) +# pragma optimize("", on) +#endif + +/* + * JS::Value is the interface for a single JavaScript Engine value. A few + * general notes on JS::Value: + * + * - JS::Value has setX() and isX() members for X in + * + * { Int32, Double, String, Symbol, Boolean, Undefined, Null, Object, Magic } + * + * JS::Value also contains toX() for each of the non-singleton types. + * + * - Magic is a singleton type whose payload contains either a JSWhyMagic "reason" for + * the magic value or a uint32_t value. By providing JSWhyMagic values when + * creating and checking for magic values, it is possible to assert, at + * runtime, that only magic values with the expected reason flow through a + * particular value. For example, if cx->exception has a magic value, the + * reason must be JS_GENERATOR_CLOSING. + * + * - The JS::Value operations are preferred. The JSVAL_* operations remain for + * compatibility; they may be removed at some point. These operations mostly + * provide similar functionality. But there are a few key differences. One + * is that JS::Value gives null a separate type. + * Also, to help prevent mistakenly boxing a nullable JSObject* as an object, + * Value::setObject takes a JSObject&. (Conversely, Value::toObject returns a + * JSObject&.) A convenience member Value::setObjectOrNull is provided. + * + * - JSVAL_VOID is the same as the singleton value of the Undefined type. + * + * - Note that JS::Value is 8 bytes on 32 and 64-bit architectures. Thus, on + * 32-bit user code should avoid copying jsval/JS::Value as much as possible, + * preferring to pass by const Value &. + */ +class Value +{ + public: + /* + * N.B. the default constructor leaves Value unitialized. Adding a default + * constructor prevents Value from being stored in a union. + */ +#if defined(JS_VALUE_IS_CONSTEXPR) + Value() = default; + Value(const Value& v) = default; +#endif + + /*** Mutators ***/ + + void setNull() { + data.asBits = BUILD_JSVAL(JSVAL_TAG_NULL, 0).asBits; + } + + void setUndefined() { + data.asBits = BUILD_JSVAL(JSVAL_TAG_UNDEFINED, 0).asBits; + } + + void setInt32(int32_t i) { + data = INT32_TO_JSVAL_IMPL(i); + } + + int32_t &getInt32Ref() { + MOZ_ASSERT(isInt32()); + return data.s.payload.i32; + } + + void setDouble(double d) { + data = DOUBLE_TO_JSVAL_IMPL(d); + } + + void setNaN() { + setDouble(GenericNaN()); + } + + double &getDoubleRef() { + MOZ_ASSERT(isDouble()); + return data.asDouble; + } + + void setString(JSString *str) { + MOZ_ASSERT(!IsPoisonedPtr(str)); + data = STRING_TO_JSVAL_IMPL(str); + } + + void setSymbol(JS::Symbol *sym) { + MOZ_ASSERT(!IsPoisonedPtr(sym)); + data = SYMBOL_TO_JSVAL_IMPL(sym); + } + + void setObject(JSObject &obj) { + MOZ_ASSERT(!IsPoisonedPtr(&obj)); + data = OBJECT_TO_JSVAL_IMPL(&obj); + } + + void setBoolean(bool b) { + data = BOOLEAN_TO_JSVAL_IMPL(b); + } + + void setMagic(JSWhyMagic why) { + data = MAGIC_TO_JSVAL_IMPL(why); + } + + void setMagicUint32(uint32_t payload) { + data = MAGIC_UINT32_TO_JSVAL_IMPL(payload); + } + + bool setNumber(uint32_t ui) { + if (ui > JSVAL_INT_MAX) { + setDouble((double)ui); + return false; + } else { + setInt32((int32_t)ui); + return true; + } + } + + bool setNumber(double d) { + int32_t i; + if (mozilla::NumberIsInt32(d, &i)) { + setInt32(i); + return true; + } + + setDouble(d); + return false; + } + + void setObjectOrNull(JSObject *arg) { + if (arg) + setObject(*arg); + else + setNull(); + } + + void swap(Value &rhs) { + uint64_t tmp = rhs.data.asBits; + rhs.data.asBits = data.asBits; + data.asBits = tmp; + } + + /*** Value type queries ***/ + + bool isUndefined() const { + return JSVAL_IS_UNDEFINED_IMPL(data); + } + + bool isNull() const { + return JSVAL_IS_NULL_IMPL(data); + } + + bool isNullOrUndefined() const { + return isNull() || isUndefined(); + } + + bool isInt32() const { + return JSVAL_IS_INT32_IMPL(data); + } + + bool isInt32(int32_t i32) const { + return JSVAL_IS_SPECIFIC_INT32_IMPL(data, i32); + } + + bool isDouble() const { + return JSVAL_IS_DOUBLE_IMPL(data); + } + + bool isNumber() const { + return JSVAL_IS_NUMBER_IMPL(data); + } + + bool isString() const { + return JSVAL_IS_STRING_IMPL(data); + } + + bool isSymbol() const { + return JSVAL_IS_SYMBOL_IMPL(data); + } + + bool isObject() const { + return JSVAL_IS_OBJECT_IMPL(data); + } + + bool isPrimitive() const { + return JSVAL_IS_PRIMITIVE_IMPL(data); + } + + bool isObjectOrNull() const { + return JSVAL_IS_OBJECT_OR_NULL_IMPL(data); + } + + bool isGCThing() const { + return JSVAL_IS_GCTHING_IMPL(data); + } + + bool isBoolean() const { + return JSVAL_IS_BOOLEAN_IMPL(data); + } + + bool isTrue() const { + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, true); + } + + bool isFalse() const { + return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, false); + } + + bool isMagic() const { + return JSVAL_IS_MAGIC_IMPL(data); + } + + bool isMagic(JSWhyMagic why) const { + MOZ_ASSERT_IF(isMagic(), data.s.payload.why == why); + return JSVAL_IS_MAGIC_IMPL(data); + } + + bool isMarkable() const { + return JSVAL_IS_TRACEABLE_IMPL(data); + } + + JSGCTraceKind gcKind() const { + MOZ_ASSERT(isMarkable()); + return JSGCTraceKind(JSVAL_TRACE_KIND_IMPL(data)); + } + + JSWhyMagic whyMagic() const { + MOZ_ASSERT(isMagic()); + return data.s.payload.why; + } + + uint32_t magicUint32() const { + MOZ_ASSERT(isMagic()); + return data.s.payload.u32; + } + + /*** Comparison ***/ + + bool operator==(const Value &rhs) const { + return data.asBits == rhs.data.asBits; + } + + bool operator!=(const Value &rhs) const { + return data.asBits != rhs.data.asBits; + } + + friend inline bool SameType(const Value &lhs, const Value &rhs); + + /*** Extract the value's typed payload ***/ + + int32_t toInt32() const { + MOZ_ASSERT(isInt32()); + return JSVAL_TO_INT32_IMPL(data); + } + + double toDouble() const { + MOZ_ASSERT(isDouble()); + return data.asDouble; + } + + double toNumber() const { + MOZ_ASSERT(isNumber()); + return isDouble() ? toDouble() : double(toInt32()); + } + + JSString *toString() const { + MOZ_ASSERT(isString()); + return JSVAL_TO_STRING_IMPL(data); + } + + JS::Symbol *toSymbol() const { + MOZ_ASSERT(isSymbol()); + return JSVAL_TO_SYMBOL_IMPL(data); + } + + JSObject &toObject() const { + MOZ_ASSERT(isObject()); + return *JSVAL_TO_OBJECT_IMPL(data); + } + + JSObject *toObjectOrNull() const { + MOZ_ASSERT(isObjectOrNull()); + return JSVAL_TO_OBJECT_IMPL(data); + } + + js::gc::Cell *toGCThing() const { + MOZ_ASSERT(isGCThing()); + return JSVAL_TO_GCTHING_IMPL(data); + } + + bool toBoolean() const { + MOZ_ASSERT(isBoolean()); + return JSVAL_TO_BOOLEAN_IMPL(data); + } + + uint32_t payloadAsRawUint32() const { + MOZ_ASSERT(!isDouble()); + return data.s.payload.u32; + } + + uint64_t asRawBits() const { + return data.asBits; + } + + JSValueType extractNonDoubleType() const { + return JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(data); + } + + /* + * Private API + * + * Private setters/getters allow the caller to read/write arbitrary types + * that fit in the 64-bit payload. It is the caller's responsibility, after + * storing to a value with setPrivateX to read only using getPrivateX. + * Privates values are given a type which ensures they are not marked. + */ + + void setPrivate(void *ptr) { + data = PRIVATE_PTR_TO_JSVAL_IMPL(ptr); + } + + void *toPrivate() const { + MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(data)); + return JSVAL_TO_PRIVATE_PTR_IMPL(data); + } + + void setPrivateUint32(uint32_t ui) { + MOZ_ASSERT(uint32_t(int32_t(ui)) == ui); + setInt32(int32_t(ui)); + } + + uint32_t toPrivateUint32() const { + return uint32_t(toInt32()); + } + + /* + * An unmarked value is just a void* cast as a Value. Thus, the Value is + * not safe for GC and must not be marked. This API avoids raw casts + * and the ensuing strict-aliasing warnings. + */ + + void setUnmarkedPtr(void *ptr) { + data.asPtr = ptr; + } + + void *toUnmarkedPtr() const { + return data.asPtr; + } + + const size_t *payloadWord() const { +#if defined(JS_NUNBOX32) + return &data.s.payload.word; +#elif defined(JS_PUNBOX64) + return &data.asWord; +#endif + } + + const uintptr_t *payloadUIntPtr() const { +#if defined(JS_NUNBOX32) + return &data.s.payload.uintptr; +#elif defined(JS_PUNBOX64) + return &data.asUIntPtr; +#endif + } + +#if !defined(_MSC_VER) && !defined(__sparc) + // Value must be POD so that MSVC will pass it by value and not in memory + // (bug 689101); the same is true for SPARC as well (bug 737344). More + // precisely, we don't want Value return values compiled as out params. + private: +#endif + + jsval_layout data; + + private: +#if defined(JS_VALUE_IS_CONSTEXPR) + MOZ_IMPLICIT JS_VALUE_CONSTEXPR Value(jsval_layout layout) : data(layout) {} +#endif + + void staticAssertions() { + JS_STATIC_ASSERT(sizeof(JSValueType) == 1); + JS_STATIC_ASSERT(sizeof(JSValueTag) == 4); + JS_STATIC_ASSERT(sizeof(JSWhyMagic) <= 4); + JS_STATIC_ASSERT(sizeof(Value) == 8); + } + + friend jsval_layout (::JSVAL_TO_IMPL)(Value); + friend Value JS_VALUE_CONSTEXPR (::IMPL_TO_JSVAL)(jsval_layout l); + friend Value JS_VALUE_CONSTEXPR (JS::UndefinedValue)(); +}; + +inline bool +IsPoisonedValue(const Value &v) +{ + if (v.isString()) + return IsPoisonedPtr(v.toString()); + if (v.isSymbol()) + return IsPoisonedPtr(v.toSymbol()); + if (v.isObject()) + return IsPoisonedPtr(&v.toObject()); + return false; +} + +inline bool +IsOptimizedPlaceholderMagicValue(const Value &v) +{ + if (v.isMagic()) { + MOZ_ASSERT(v.whyMagic() == JS_OPTIMIZED_ARGUMENTS || v.whyMagic() == JS_OPTIMIZED_OUT); + return true; + } + return false; +} + +static MOZ_ALWAYS_INLINE void +ExposeValueToActiveJS(const Value &v) +{ + if (v.isMarkable()) + ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); +} + +/************************************************************************/ + +static inline Value +NullValue() +{ + Value v; + v.setNull(); + return v; +} + +static inline JS_VALUE_CONSTEXPR Value +UndefinedValue() +{ +#if defined(JS_VALUE_IS_CONSTEXPR) + return Value(BUILD_JSVAL(JSVAL_TAG_UNDEFINED, 0)); +#else + JS::Value v; + v.setUndefined(); + return v; +#endif +} + +static inline Value +Int32Value(int32_t i32) +{ + Value v; + v.setInt32(i32); + return v; +} + +static inline Value +DoubleValue(double dbl) +{ + Value v; + v.setDouble(dbl); + return v; +} + +static inline Value +DoubleNaNValue() +{ + Value v; + v.setNaN(); + return v; +} + +static inline Value +Float32Value(float f) +{ + Value v; + v.setDouble(f); + return v; +} + +static inline Value +StringValue(JSString *str) +{ + Value v; + v.setString(str); + return v; +} + +static inline Value +SymbolValue(JS::Symbol *sym) +{ + Value v; + v.setSymbol(sym); + return v; +} + +static inline Value +BooleanValue(bool boo) +{ + Value v; + v.setBoolean(boo); + return v; +} + +static inline Value +TrueValue() +{ + Value v; + v.setBoolean(true); + return v; +} + +static inline Value +FalseValue() +{ + Value v; + v.setBoolean(false); + return v; +} + +static inline Value +ObjectValue(JSObject &obj) +{ + Value v; + v.setObject(obj); + return v; +} + +static inline Value +ObjectValueCrashOnTouch() +{ + Value v; + v.setObject(*reinterpret_cast(0x42)); + return v; +} + +static inline Value +MagicValue(JSWhyMagic why) +{ + Value v; + v.setMagic(why); + return v; +} + +static inline Value +MagicValueUint32(uint32_t payload) +{ + Value v; + v.setMagicUint32(payload); + return v; +} + +static inline Value +NumberValue(float f) +{ + Value v; + v.setNumber(f); + return v; +} + +static inline Value +NumberValue(double dbl) +{ + Value v; + v.setNumber(dbl); + return v; +} + +static inline Value +NumberValue(int8_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(uint8_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(int16_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(uint16_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(int32_t i) +{ + return Int32Value(i); +} + +static inline Value +NumberValue(uint32_t i) +{ + Value v; + v.setNumber(i); + return v; +} + +namespace detail { + +template +class MakeNumberValue +{ + public: + template + static inline Value create(const T t) + { + Value v; + if (JSVAL_INT_MIN <= t && t <= JSVAL_INT_MAX) + v.setInt32(int32_t(t)); + else + v.setDouble(double(t)); + return v; + } +}; + +template <> +class MakeNumberValue +{ + public: + template + static inline Value create(const T t) + { + Value v; + if (t <= JSVAL_INT_MAX) + v.setInt32(int32_t(t)); + else + v.setDouble(double(t)); + return v; + } +}; + +} // namespace detail + +template +static inline Value +NumberValue(const T t) +{ + MOZ_ASSERT(T(double(t)) == t, "value creation would be lossy"); + return detail::MakeNumberValue::is_signed>::create(t); +} + +static inline Value +ObjectOrNullValue(JSObject *obj) +{ + Value v; + v.setObjectOrNull(obj); + return v; +} + +static inline Value +PrivateValue(void *ptr) +{ + Value v; + v.setPrivate(ptr); + return v; +} + +static inline Value +PrivateUint32Value(uint32_t ui) +{ + Value v; + v.setPrivateUint32(ui); + return v; +} + +inline bool +SameType(const Value &lhs, const Value &rhs) +{ + return JSVAL_SAME_TYPE_IMPL(lhs.data, rhs.data); +} + +} // namespace JS + +/************************************************************************/ + +#ifdef JSGC_GENERATIONAL +namespace JS { +JS_PUBLIC_API(void) HeapValuePostBarrier(Value *valuep); +JS_PUBLIC_API(void) HeapValueRelocate(Value *valuep); +} +#endif + +namespace js { + +template <> struct GCMethods +{ + static JS::Value initial() { return JS::UndefinedValue(); } + static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } +}; + +template <> struct GCMethods +{ + static JS::Value initial() { return JS::UndefinedValue(); } + static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); } + static bool needsPostBarrier(const JS::Value &v) { + return v.isObject() && gc::IsInsideNursery(reinterpret_cast(&v.toObject())); + } +#ifdef JSGC_GENERATIONAL + static void postBarrier(JS::Value *v) { JS::HeapValuePostBarrier(v); } + static void relocate(JS::Value *v) { JS::HeapValueRelocate(v); } +#endif +}; + +template class MutableValueOperations; + +/* + * A class designed for CRTP use in implementing the non-mutating parts of the + * Value interface in Value-like classes. Outer must be a class inheriting + * ValueOperations with a visible extract() method returning the + * const Value* abstracted by Outer. + */ +template +class ValueOperations +{ + friend class MutableValueOperations; + + const JS::Value * value() const { return static_cast(this)->extract(); } + + public: + bool isUndefined() const { return value()->isUndefined(); } + bool isNull() const { return value()->isNull(); } + bool isBoolean() const { return value()->isBoolean(); } + bool isTrue() const { return value()->isTrue(); } + bool isFalse() const { return value()->isFalse(); } + bool isNumber() const { return value()->isNumber(); } + bool isInt32() const { return value()->isInt32(); } + bool isDouble() const { return value()->isDouble(); } + bool isString() const { return value()->isString(); } + bool isSymbol() const { return value()->isSymbol(); } + bool isObject() const { return value()->isObject(); } + bool isMagic() const { return value()->isMagic(); } + bool isMagic(JSWhyMagic why) const { return value()->isMagic(why); } + bool isMarkable() const { return value()->isMarkable(); } + bool isPrimitive() const { return value()->isPrimitive(); } + bool isGCThing() const { return value()->isGCThing(); } + + bool isNullOrUndefined() const { return value()->isNullOrUndefined(); } + bool isObjectOrNull() const { return value()->isObjectOrNull(); } + + bool toBoolean() const { return value()->toBoolean(); } + double toNumber() const { return value()->toNumber(); } + int32_t toInt32() const { return value()->toInt32(); } + double toDouble() const { return value()->toDouble(); } + JSString *toString() const { return value()->toString(); } + JS::Symbol *toSymbol() const { return value()->toSymbol(); } + JSObject &toObject() const { return value()->toObject(); } + JSObject *toObjectOrNull() const { return value()->toObjectOrNull(); } + void *toGCThing() const { return value()->toGCThing(); } + uint64_t asRawBits() const { return value()->asRawBits(); } + + JSValueType extractNonDoubleType() const { return value()->extractNonDoubleType(); } + uint32_t toPrivateUint32() const { return value()->toPrivateUint32(); } + + JSWhyMagic whyMagic() const { return value()->whyMagic(); } + uint32_t magicUint32() const { return value()->magicUint32(); } +}; + +/* + * A class designed for CRTP use in implementing all the mutating parts of the + * Value interface in Value-like classes. Outer must be a class inheriting + * MutableValueOperations with visible extractMutable() and extract() + * methods returning the const Value* and Value* abstracted by Outer. + */ +template +class MutableValueOperations : public ValueOperations +{ + JS::Value * value() { return static_cast(this)->extractMutable(); } + + public: + void setNull() { value()->setNull(); } + void setUndefined() { value()->setUndefined(); } + void setInt32(int32_t i) { value()->setInt32(i); } + void setDouble(double d) { value()->setDouble(d); } + void setNaN() { setDouble(JS::GenericNaN()); } + void setBoolean(bool b) { value()->setBoolean(b); } + void setMagic(JSWhyMagic why) { value()->setMagic(why); } + bool setNumber(uint32_t ui) { return value()->setNumber(ui); } + bool setNumber(double d) { return value()->setNumber(d); } + void setString(JSString *str) { this->value()->setString(str); } + void setSymbol(JS::Symbol *sym) { this->value()->setSymbol(sym); } + void setObject(JSObject &obj) { this->value()->setObject(obj); } + void setObjectOrNull(JSObject *arg) { this->value()->setObjectOrNull(arg); } +}; + +/* + * Augment the generic Heap interface when T = Value with + * type-querying, value-extracting, and mutating operations. + */ +template <> +class HeapBase : public ValueOperations > +{ + typedef JS::Heap Outer; + + friend class ValueOperations; + + const JS::Value * extract() const { return static_cast(this)->address(); } + + void setBarriered(const JS::Value &v) { + static_cast *>(this)->set(v); + } + + public: + void setNull() { setBarriered(JS::NullValue()); } + void setUndefined() { setBarriered(JS::UndefinedValue()); } + void setInt32(int32_t i) { setBarriered(JS::Int32Value(i)); } + void setDouble(double d) { setBarriered(JS::DoubleValue(d)); } + void setNaN() { setDouble(JS::GenericNaN()); } + void setBoolean(bool b) { setBarriered(JS::BooleanValue(b)); } + void setMagic(JSWhyMagic why) { setBarriered(JS::MagicValue(why)); } + void setString(JSString *str) { setBarriered(JS::StringValue(str)); } + void setSymbol(JS::Symbol *sym) { setBarriered(JS::SymbolValue(sym)); } + void setObject(JSObject &obj) { setBarriered(JS::ObjectValue(obj)); } + + bool setNumber(uint32_t ui) { + if (ui > JSVAL_INT_MAX) { + setDouble((double)ui); + return false; + } else { + setInt32((int32_t)ui); + return true; + } + } + + bool setNumber(double d) { + int32_t i; + if (mozilla::NumberIsInt32(d, &i)) { + setInt32(i); + return true; + } + + setDouble(d); + return false; + } + + void setObjectOrNull(JSObject *arg) { + if (arg) + setObject(*arg); + else + setNull(); + } +}; + +/* + * Augment the generic Handle interface when T = Value with type-querying + * and value-extracting operations. + */ +template <> +class HandleBase : public ValueOperations > +{ + friend class ValueOperations >; + const JS::Value * extract() const { + return static_cast*>(this)->address(); + } +}; + +/* + * Augment the generic MutableHandle interface when T = Value with + * type-querying, value-extracting, and mutating operations. + */ +template <> +class MutableHandleBase : public MutableValueOperations > +{ + friend class ValueOperations >; + const JS::Value * extract() const { + return static_cast*>(this)->address(); + } + + friend class MutableValueOperations >; + JS::Value * extractMutable() { + return static_cast*>(this)->address(); + } +}; + +/* + * Augment the generic Rooted interface when T = Value with type-querying, + * value-extracting, and mutating operations. + */ +template <> +class RootedBase : public MutableValueOperations > +{ + friend class ValueOperations >; + const JS::Value * extract() const { + return static_cast*>(this)->address(); + } + + friend class MutableValueOperations >; + JS::Value * extractMutable() { + return static_cast*>(this)->address(); + } +}; + +} // namespace js + +inline jsval_layout +JSVAL_TO_IMPL(JS::Value v) +{ + return v.data; +} + +inline JS_VALUE_CONSTEXPR JS::Value +IMPL_TO_JSVAL(jsval_layout l) +{ +#if defined(JS_VALUE_IS_CONSTEXPR) + return JS::Value(l); +#else + JS::Value v; + v.data = l; + return v; +#endif +} + +namespace JS { + +#ifndef __GNUC__ +/* + * The default assignment operator for |struct C| has the signature: + * + * C& C::operator=(const C&) + * + * And in particular requires implicit conversion of |this| to type |C| for the + * return value. But |volatile C| cannot thus be converted to |C|, so just + * doing |sink = hold| as in the non-specialized version would fail to compile. + * Do the assignment on asBits instead, since I don't think we want to give + * jsval_layout an assignment operator returning |volatile jsval_layout|. + */ +template<> +inline Anchor::~Anchor() +{ + volatile uint64_t bits; + bits = JSVAL_TO_IMPL(hold).asBits; +} +#endif + +#ifdef JS_DEBUG +namespace detail { + +struct ValueAlignmentTester { char c; JS::Value v; }; +static_assert(sizeof(ValueAlignmentTester) == 16, + "JS::Value must be 16-byte-aligned"); + +struct LayoutAlignmentTester { char c; jsval_layout l; }; +static_assert(sizeof(LayoutAlignmentTester) == 16, + "jsval_layout must be 16-byte-aligned"); + +} // namespace detail +#endif /* JS_DEBUG */ + +} // namespace JS + +/* + * JS::Value and jsval are the same type; jsval is the old name, kept around + * for backwards compatibility along with all the JSVAL_* operations below. + * jsval_layout is an implementation detail and should not be used externally. + */ +typedef JS::Value jsval; + +static_assert(sizeof(jsval_layout) == sizeof(JS::Value), + "jsval_layout and JS::Value must have identical layouts"); + +/************************************************************************/ + +static inline JS_VALUE_CONSTEXPR jsval +INT_TO_JSVAL(int32_t i) +{ + return IMPL_TO_JSVAL(INT32_TO_JSVAL_IMPL(i)); +} + +static inline JS_VALUE_CONSTEXPR jsval +DOUBLE_TO_JSVAL(double d) +{ + /* + * This is a manually inlined version of: + * d = JS_CANONICALIZE_NAN(d); + * return IMPL_TO_JSVAL(DOUBLE_TO_JSVAL_IMPL(d)); + * because GCC from XCode 3.1.4 miscompiles the above code. + */ +#if defined(JS_VALUE_IS_CONSTEXPR) + return IMPL_TO_JSVAL(MOZ_UNLIKELY(d != d) + ? (jsval_layout) { .asBits = 0x7FF8000000000000LL } + : (jsval_layout) { .asDouble = d }); +#else + jsval_layout l; + if (MOZ_UNLIKELY(d != d)) + l.asBits = 0x7FF8000000000000LL; + else + l.asDouble = d; + return IMPL_TO_JSVAL(l); +#endif +} + +static inline JS_VALUE_CONSTEXPR jsval +UINT_TO_JSVAL(uint32_t i) +{ + return (i <= JSVAL_INT_MAX + ? INT_TO_JSVAL((int32_t)i) + : DOUBLE_TO_JSVAL((double)i)); +} + +static inline jsval +STRING_TO_JSVAL(JSString *str) +{ + return IMPL_TO_JSVAL(STRING_TO_JSVAL_IMPL(str)); +} + +static inline jsval +OBJECT_TO_JSVAL(JSObject *obj) +{ + if (obj) + return IMPL_TO_JSVAL(OBJECT_TO_JSVAL_IMPL(obj)); + return IMPL_TO_JSVAL(BUILD_JSVAL(JSVAL_TAG_NULL, 0)); +} + +static inline jsval +BOOLEAN_TO_JSVAL(bool b) +{ + return IMPL_TO_JSVAL(BOOLEAN_TO_JSVAL_IMPL(b)); +} + +/* To be GC-safe, privates are tagged as doubles. */ + +static inline jsval +PRIVATE_TO_JSVAL(void *ptr) +{ + return IMPL_TO_JSVAL(PRIVATE_PTR_TO_JSVAL_IMPL(ptr)); +} + +// JS constants. For efficiency, prefer predicates (e.g. v.isNull()) and +// constructing values from scratch (e.g. Int32Value(0)). These constants are +// stored in memory and initialized at startup, so testing against them and +// using them requires memory loads and will be correspondingly slow. +extern JS_PUBLIC_DATA(const jsval) JSVAL_NULL; +extern JS_PUBLIC_DATA(const jsval) JSVAL_ZERO; +extern JS_PUBLIC_DATA(const jsval) JSVAL_ONE; +extern JS_PUBLIC_DATA(const jsval) JSVAL_FALSE; +extern JS_PUBLIC_DATA(const jsval) JSVAL_TRUE; +extern JS_PUBLIC_DATA(const jsval) JSVAL_VOID; + +namespace JS { + +extern JS_PUBLIC_DATA(const HandleValue) NullHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) TrueHandleValue; +extern JS_PUBLIC_DATA(const HandleValue) FalseHandleValue; + +} + +#undef JS_VALUE_IS_CONSTEXPR +#undef JS_RETURN_LAYOUT_FROM_BITS + +#endif /* js_Value_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Vector.h new file mode 100644 index 0000000000..a2d24b10ed --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/js/Vector.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef js_Vector_h +#define js_Vector_h + +#include "mozilla/Vector.h" + +/* Silence dire "bugs in previous versions of MSVC have been fixed" warnings */ +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4345) +#endif + +namespace js { + +class TempAllocPolicy; + +// If we had C++11 template aliases, we could just use this: +// +// template +// using Vector = mozilla::Vector; +// +// ...and get rid of all the CRTP madness in mozilla::Vector(Base). But we +// can't because compiler support's not up to snuff. (Template aliases are in +// gcc 4.7 and clang 3.0 and are expected to be in MSVC 2013.) Instead, have a +// completely separate class inheriting from mozilla::Vector, and throw CRTP at +// the problem til things work. +// +// This workaround presents a couple issues. First, because js::Vector is a +// distinct type from mozilla::Vector, overload resolution, method calls, etc. +// are affected. *Hopefully* this won't be too bad in practice. (A bunch of +// places had to be fixed when mozilla::Vector was introduced, but it wasn't a +// crazy number.) Second, mozilla::Vector's interface has to be made subclass- +// ready via CRTP -- or rather, via mozilla::VectorBase, which basically no one +// should use. :-) Third, we have to redefine the constructors and the non- +// inherited operators. Blech. Happily there aren't too many of these, so it +// isn't the end of the world. + +template +class Vector + : public mozilla::VectorBase > +{ + typedef typename mozilla::VectorBase Base; + + public: + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + Vector(Vector &&vec) : Base(mozilla::Move(vec)) {} + Vector &operator=(Vector &&vec) { + return Base::operator=(mozilla::Move(vec)); + } +}; + +} // namespace js + +#endif /* js_Vector_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsalloc.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsalloc.h new file mode 100644 index 0000000000..a1e547cec9 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsalloc.h @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * JS allocation policies. + * + * The allocators here are for system memory with lifetimes which are not + * managed by the GC. See the comment at the top of vm/MallocProvider.h. + */ + +#ifndef jsalloc_h +#define jsalloc_h + +#include "js/TypeDecls.h" +#include "js/Utility.h" + +namespace js { + +struct ContextFriendFields; + +/* Policy for using system memory functions and doing no error reporting. */ +class SystemAllocPolicy +{ + public: + void *malloc_(size_t bytes) { return js_malloc(bytes); } + void *calloc_(size_t bytes) { return js_calloc(bytes); } + void *realloc_(void *p, size_t oldBytes, size_t bytes) { return js_realloc(p, bytes); } + void free_(void *p) { js_free(p); } + void reportAllocOverflow() const {} +}; + +/* + * Allocation policy that calls the system memory functions and reports errors + * to the context. Since the JSContext given on construction is stored for + * the lifetime of the container, this policy may only be used for containers + * whose lifetime is a shorter than the given JSContext. + * + * FIXME bug 647103 - rewrite this in terms of temporary allocation functions, + * not the system ones. + */ +class TempAllocPolicy +{ + ContextFriendFields *const cx_; + + /* + * Non-inline helper to call JSRuntime::onOutOfMemory with minimal + * code bloat. + */ + JS_FRIEND_API(void *) onOutOfMemory(void *p, size_t nbytes); + + public: + MOZ_IMPLICIT TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( + MOZ_IMPLICIT TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} + + void *malloc_(size_t bytes) { + void *p = js_malloc(bytes); + if (MOZ_UNLIKELY(!p)) + p = onOutOfMemory(nullptr, bytes); + return p; + } + + void *calloc_(size_t bytes) { + void *p = js_calloc(bytes); + if (MOZ_UNLIKELY(!p)) + p = onOutOfMemory(nullptr, bytes); + return p; + } + + void *realloc_(void *p, size_t oldBytes, size_t bytes) { + void *p2 = js_realloc(p, bytes); + if (MOZ_UNLIKELY(!p2)) + p2 = onOutOfMemory(p2, bytes); + return p2; + } + + void free_(void *p) { + js_free(p); + } + + JS_FRIEND_API(void) reportAllocOverflow() const; +}; + +} /* namespace js */ + +#endif /* jsalloc_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsapi.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsapi.h new file mode 100644 index 0000000000..4c4a24dfeb --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsapi.h @@ -0,0 +1,5250 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* JavaScript API. */ + +#ifndef jsapi_h +#define jsapi_h + +#include "mozilla/Char16.h" +#include "mozilla/FloatingPoint.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/Range.h" +#include "mozilla/RangedPtr.h" +#include "mozilla/TypedEnum.h" + +#include +#include +#include +#include + +#include "jsalloc.h" +#include "jspubtd.h" + +#include "js/CallArgs.h" +#include "js/Class.h" +#include "js/HashTable.h" +#include "js/Id.h" +#include "js/Principals.h" +#include "js/RootingAPI.h" +#include "js/TracingAPI.h" +#include "js/Utility.h" +#include "js/Value.h" +#include "js/Vector.h" + +/************************************************************************/ + +namespace JS { + +class Latin1CharsZ; +class TwoByteChars; + +#if defined JS_THREADSAFE && defined JS_DEBUG + +class JS_PUBLIC_API(AutoCheckRequestDepth) +{ + JSContext *cx; + public: + explicit AutoCheckRequestDepth(JSContext *cx); + explicit AutoCheckRequestDepth(js::ContextFriendFields *cx); + ~AutoCheckRequestDepth(); +}; + +# define CHECK_REQUEST(cx) \ + JS::AutoCheckRequestDepth _autoCheckRequestDepth(cx) + +#else + +# define CHECK_REQUEST(cx) \ + ((void) 0) + +#endif /* JS_THREADSAFE && JS_DEBUG */ + +#ifdef JS_DEBUG +/* + * Assert that we're not doing GC on cx, that we're in a request as + * needed, and that the compartments for cx and v are correct. + * Also check that GC would be safe at this point. + */ +JS_PUBLIC_API(void) +AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v); +#else +inline void AssertArgumentsAreSane(JSContext *cx, JS::HandleValue v) { + /* Do nothing */ +} +#endif /* JS_DEBUG */ + +/* AutoValueArray roots an internal fixed-size array of Values. */ +template +class AutoValueArray : public AutoGCRooter +{ + const size_t length_; + Value elements_[N]; + + public: + explicit AutoValueArray(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, VALARRAY), length_(N) + { + /* Always initialize in case we GC before assignment. */ + mozilla::PodArrayZero(elements_); + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + unsigned length() const { return length_; } + const Value *begin() const { return elements_; } + Value *begin() { return elements_; } + + HandleValue operator[](unsigned i) const { + JS_ASSERT(i < N); + return HandleValue::fromMarkedLocation(&elements_[i]); + } + MutableHandleValue operator[](unsigned i) { + JS_ASSERT(i < N); + return MutableHandleValue::fromMarkedLocation(&elements_[i]); + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +template +class AutoVectorRooter : protected AutoGCRooter +{ + typedef js::Vector VectorImpl; + VectorImpl vector; + + public: + explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, tag), vector(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + explicit AutoVectorRooter(js::ContextFriendFields *cx, ptrdiff_t tag + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, tag), vector(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + typedef T ElementType; + typedef typename VectorImpl::Range Range; + + size_t length() const { return vector.length(); } + bool empty() const { return vector.empty(); } + + bool append(const T &v) { return vector.append(v); } + bool append(const T *ptr, size_t len) { return vector.append(ptr, len); } + bool appendAll(const AutoVectorRooter &other) { + return vector.appendAll(other.vector); + } + + bool insert(T *p, const T &val) { return vector.insert(p, val); } + + /* For use when space has already been reserved. */ + void infallibleAppend(const T &v) { vector.infallibleAppend(v); } + + void popBack() { vector.popBack(); } + T popCopy() { return vector.popCopy(); } + + bool growBy(size_t inc) { + size_t oldLength = vector.length(); + if (!vector.growByUninitialized(inc)) + return false; + makeRangeGCSafe(oldLength); + return true; + } + + bool resize(size_t newLength) { + size_t oldLength = vector.length(); + if (newLength <= oldLength) { + vector.shrinkBy(oldLength - newLength); + return true; + } + if (!vector.growByUninitialized(newLength - oldLength)) + return false; + makeRangeGCSafe(oldLength); + return true; + } + + void clear() { vector.clear(); } + + bool reserve(size_t newLength) { + return vector.reserve(newLength); + } + + JS::MutableHandle operator[](size_t i) { + return JS::MutableHandle::fromMarkedLocation(&vector[i]); + } + JS::Handle operator[](size_t i) const { + return JS::Handle::fromMarkedLocation(&vector[i]); + } + + const T *begin() const { return vector.begin(); } + T *begin() { return vector.begin(); } + + const T *end() const { return vector.end(); } + T *end() { return vector.end(); } + + Range all() { return vector.all(); } + + const T &back() const { return vector.back(); } + + friend void AutoGCRooter::trace(JSTracer *trc); + + private: + void makeRangeGCSafe(size_t oldLength) { + T *t = vector.begin() + oldLength; + for (size_t i = oldLength; i < vector.length(); ++i, ++t) + memset(t, 0, sizeof(T)); + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +template +class AutoHashMapRooter : protected AutoGCRooter +{ + private: + typedef js::HashMap HashMapImpl; + + public: + explicit AutoHashMapRooter(JSContext *cx, ptrdiff_t tag + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, tag), map(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + typedef Key KeyType; + typedef Value ValueType; + typedef typename HashMapImpl::Entry Entry; + typedef typename HashMapImpl::Lookup Lookup; + typedef typename HashMapImpl::Ptr Ptr; + typedef typename HashMapImpl::AddPtr AddPtr; + + bool init(uint32_t len = 16) { + return map.init(len); + } + bool initialized() const { + return map.initialized(); + } + Ptr lookup(const Lookup &l) const { + return map.lookup(l); + } + void remove(Ptr p) { + map.remove(p); + } + AddPtr lookupForAdd(const Lookup &l) const { + return map.lookupForAdd(l); + } + + template + bool add(AddPtr &p, const KeyInput &k, const ValueInput &v) { + return map.add(p, k, v); + } + + bool add(AddPtr &p, const Key &k) { + return map.add(p, k); + } + + template + bool relookupOrAdd(AddPtr &p, const KeyInput &k, const ValueInput &v) { + return map.relookupOrAdd(p, k, v); + } + + typedef typename HashMapImpl::Range Range; + Range all() const { + return map.all(); + } + + typedef typename HashMapImpl::Enum Enum; + + void clear() { + map.clear(); + } + + void finish() { + map.finish(); + } + + bool empty() const { + return map.empty(); + } + + uint32_t count() const { + return map.count(); + } + + size_t capacity() const { + return map.capacity(); + } + + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return map.sizeOfExcludingThis(mallocSizeOf); + } + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return map.sizeOfIncludingThis(mallocSizeOf); + } + + uint32_t generation() const { + return map.generation(); + } + + /************************************************** Shorthand operations */ + + bool has(const Lookup &l) const { + return map.has(l); + } + + template + bool put(const KeyInput &k, const ValueInput &v) { + return map.put(k, v); + } + + template + bool putNew(const KeyInput &k, const ValueInput &v) { + return map.putNew(k, v); + } + + Ptr lookupWithDefault(const Key &k, const Value &defaultValue) { + return map.lookupWithDefault(k, defaultValue); + } + + void remove(const Lookup &l) { + map.remove(l); + } + + friend void AutoGCRooter::trace(JSTracer *trc); + + private: + AutoHashMapRooter(const AutoHashMapRooter &hmr) MOZ_DELETE; + AutoHashMapRooter &operator=(const AutoHashMapRooter &hmr) MOZ_DELETE; + + HashMapImpl map; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +template +class AutoHashSetRooter : protected AutoGCRooter +{ + private: + typedef js::HashSet HashSetImpl; + + public: + explicit AutoHashSetRooter(JSContext *cx, ptrdiff_t tag + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, tag), set(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + typedef typename HashSetImpl::Lookup Lookup; + typedef typename HashSetImpl::Ptr Ptr; + typedef typename HashSetImpl::AddPtr AddPtr; + + bool init(uint32_t len = 16) { + return set.init(len); + } + bool initialized() const { + return set.initialized(); + } + Ptr lookup(const Lookup &l) const { + return set.lookup(l); + } + void remove(Ptr p) { + set.remove(p); + } + AddPtr lookupForAdd(const Lookup &l) const { + return set.lookupForAdd(l); + } + + bool add(AddPtr &p, const T &t) { + return set.add(p, t); + } + + bool relookupOrAdd(AddPtr &p, const Lookup &l, const T &t) { + return set.relookupOrAdd(p, l, t); + } + + typedef typename HashSetImpl::Range Range; + Range all() const { + return set.all(); + } + + typedef typename HashSetImpl::Enum Enum; + + void clear() { + set.clear(); + } + + void finish() { + set.finish(); + } + + bool empty() const { + return set.empty(); + } + + uint32_t count() const { + return set.count(); + } + + size_t capacity() const { + return set.capacity(); + } + + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return set.sizeOfExcludingThis(mallocSizeOf); + } + size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const { + return set.sizeOfIncludingThis(mallocSizeOf); + } + + uint32_t generation() const { + return set.generation(); + } + + /************************************************** Shorthand operations */ + + bool has(const Lookup &l) const { + return set.has(l); + } + + bool put(const T &t) { + return set.put(t); + } + + bool putNew(const T &t) { + return set.putNew(t); + } + + void remove(const Lookup &l) { + set.remove(l); + } + + friend void AutoGCRooter::trace(JSTracer *trc); + + private: + AutoHashSetRooter(const AutoHashSetRooter &hmr) MOZ_DELETE; + AutoHashSetRooter &operator=(const AutoHashSetRooter &hmr) MOZ_DELETE; + + HashSetImpl set; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class MOZ_STACK_CLASS AutoValueVector : public AutoVectorRooter +{ + public: + explicit AutoValueVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, VALVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class AutoIdVector : public AutoVectorRooter +{ + public: + explicit AutoIdVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, IDVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class AutoObjectVector : public AutoVectorRooter +{ + public: + explicit AutoObjectVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, OBJVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class AutoFunctionVector : public AutoVectorRooter +{ + public: + explicit AutoFunctionVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, FUNVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + explicit AutoFunctionVector(js::ContextFriendFields *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, FUNVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +class AutoScriptVector : public AutoVectorRooter +{ + public: + explicit AutoScriptVector(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoVectorRooter(cx, SCRIPTVECTOR) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* + * Custom rooting behavior for internal and external clients. + */ +class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter +{ + public: + template + explicit CustomAutoRooter(CX *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, CUSTOM) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + friend void AutoGCRooter::trace(JSTracer *trc); + + protected: + /* Supplied by derived class to trace roots. */ + virtual void trace(JSTracer *trc) = 0; + + private: + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* + * RootedGeneric allows a class to instantiate its own Rooted type by + * including the method: + * + * void trace(JSTracer *trc); + * + * The trace() method must trace all of the class's fields. + */ +template +class RootedGeneric : private CustomAutoRooter +{ + public: + template + explicit RootedGeneric(CX *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + template + explicit RootedGeneric(CX *cx, const T& initial MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : CustomAutoRooter(cx), value(initial) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + operator const T&() const { return value; } + T operator->() const { return value; } + + private: + virtual void trace(JSTracer *trc) { value->trace(trc); } + + T value; + + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* A handle to an array of rooted values. */ +class HandleValueArray +{ + const size_t length_; + const Value * const elements_; + + HandleValueArray(size_t len, const Value *elements) : length_(len), elements_(elements) {} + + public: + explicit HandleValueArray(const RootedValue& value) : length_(1), elements_(value.address()) {} + + MOZ_IMPLICIT HandleValueArray(const AutoValueVector& values) + : length_(values.length()), elements_(values.begin()) {} + + template + HandleValueArray(const AutoValueArray& values) : length_(N), elements_(values.begin()) {} + + /* CallArgs must already be rooted somewhere up the stack. */ + MOZ_IMPLICIT HandleValueArray(const JS::CallArgs& args) : length_(args.length()), elements_(args.array()) {} + + /* Use with care! Only call this if the data is guaranteed to be marked. */ + static HandleValueArray fromMarkedLocation(size_t len, const Value *elements) { + return HandleValueArray(len, elements); + } + + static HandleValueArray subarray(const HandleValueArray& values, size_t startIndex, size_t len) { + JS_ASSERT(startIndex + len <= values.length()); + return HandleValueArray(len, values.begin() + startIndex); + } + + static HandleValueArray empty() { + return HandleValueArray(0, nullptr); + } + + size_t length() const { return length_; } + const Value *begin() const { return elements_; } + + HandleValue operator[](size_t i) const { + JS_ASSERT(i < length_); + return HandleValue::fromMarkedLocation(&elements_[i]); + } +}; + +} /* namespace JS */ + +/************************************************************************/ + +struct JSFreeOp { + private: + JSRuntime *runtime_; + + protected: + explicit JSFreeOp(JSRuntime *rt) + : runtime_(rt) { } + + public: + JSRuntime *runtime() const { + return runtime_; + } +}; + +/* Callbacks and their arguments. */ + +/************************************************************************/ + +typedef enum JSContextOp { + JSCONTEXT_NEW, + JSCONTEXT_DESTROY +} JSContextOp; + +/* + * The possible values for contextOp when the runtime calls the callback are: + * JSCONTEXT_NEW JS_NewContext successfully created a new JSContext + * instance. The callback can initialize the instance as + * required. If the callback returns false, the instance + * will be destroyed and JS_NewContext returns null. In + * this case the callback is not called again. + * JSCONTEXT_DESTROY One of JS_DestroyContext* methods is called. The + * callback may perform its own cleanup and must always + * return true. + * Any other value For future compatibility the callback must do nothing + * and return true in this case. + */ +typedef bool +(* JSContextCallback)(JSContext *cx, unsigned contextOp, void *data); + +typedef enum JSGCStatus { + JSGC_BEGIN, + JSGC_END +} JSGCStatus; + +typedef void +(* JSGCCallback)(JSRuntime *rt, JSGCStatus status, void *data); + +typedef enum JSFinalizeStatus { + /* + * Called when preparing to sweep a group of compartments, before anything + * has been swept. The collector will not yield to the mutator before + * calling the callback with JSFINALIZE_GROUP_END status. + */ + JSFINALIZE_GROUP_START, + + /* + * Called when preparing to sweep a group of compartments. Weak references + * to unmarked things have been removed and things that are not swept + * incrementally have been finalized at this point. The collector may yield + * to the mutator after this point. + */ + JSFINALIZE_GROUP_END, + + /* + * Called at the end of collection when everything has been swept. + */ + JSFINALIZE_COLLECTION_END +} JSFinalizeStatus; + +typedef void +(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment, void *data); + +typedef bool +(* JSInterruptCallback)(JSContext *cx); + +typedef void +(* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report); + +#ifdef MOZ_TRACE_JSCALLS +typedef void +(* JSFunctionCallback)(const JSFunction *fun, + const JSScript *scr, + const JSContext *cx, + int entering); +#endif + +/* + * Possible exception types. These types are part of a JSErrorFormatString + * structure. They define which error to throw in case of a runtime error. + * JSEXN_NONE marks an unthrowable error. + */ +typedef enum JSExnType { + JSEXN_NONE = -1, + JSEXN_ERR, + JSEXN_INTERNALERR, + JSEXN_EVALERR, + JSEXN_RANGEERR, + JSEXN_REFERENCEERR, + JSEXN_SYNTAXERR, + JSEXN_TYPEERR, + JSEXN_URIERR, + JSEXN_LIMIT +} JSExnType; + +typedef struct JSErrorFormatString { + /* The error format string in ASCII. */ + const char *format; + + /* The number of arguments to expand in the formatted error message. */ + uint16_t argCount; + + /* One of the JSExnType constants above. */ + int16_t exnType; +} JSErrorFormatString; + +typedef const JSErrorFormatString * +(* JSErrorCallback)(void *userRef, const unsigned errorNumber); + +typedef bool +(* JSLocaleToUpperCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); + +typedef bool +(* JSLocaleToLowerCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); + +typedef bool +(* JSLocaleCompare)(JSContext *cx, JS::HandleString src1, JS::HandleString src2, + JS::MutableHandleValue rval); + +typedef bool +(* JSLocaleToUnicode)(JSContext *cx, const char *src, JS::MutableHandleValue rval); + +/* + * Callback used to ask the embedding for the cross compartment wrapper handler + * that implements the desired prolicy for this kind of object in the + * destination compartment. |obj| is the object to be wrapped. If |existing| is + * non-nullptr, it will point to an existing wrapper object that should be + * re-used if possible. |existing| is guaranteed to be a cross-compartment + * wrapper with a lazily-defined prototype and the correct global. It is + * guaranteed not to wrap a function. + */ +typedef JSObject * +(* JSWrapObjectCallback)(JSContext *cx, JS::HandleObject existing, JS::HandleObject obj, + JS::HandleObject parent, unsigned flags); + +/* + * Callback used by the wrap hook to ask the embedding to prepare an object + * for wrapping in a context. This might include unwrapping other wrappers + * or even finding a more suitable object for the new compartment. + */ +typedef JSObject * +(* JSPreWrapCallback)(JSContext *cx, JS::HandleObject scope, JS::HandleObject obj, + unsigned flags); + +struct JSWrapObjectCallbacks +{ + JSWrapObjectCallback wrap; + JSPreWrapCallback preWrap; +}; + +typedef void +(* JSDestroyCompartmentCallback)(JSFreeOp *fop, JSCompartment *compartment); + +typedef void +(* JSZoneCallback)(JS::Zone *zone); + +typedef void +(* JSCompartmentNameCallback)(JSRuntime *rt, JSCompartment *compartment, + char *buf, size_t bufsize); + +/************************************************************************/ + +static MOZ_ALWAYS_INLINE jsval +JS_NumberValue(double d) +{ + int32_t i; + d = JS::CanonicalizeNaN(d); + if (mozilla::NumberIsInt32(d, &i)) + return INT_TO_JSVAL(i); + return DOUBLE_TO_JSVAL(d); +} + +/************************************************************************/ + +JS_PUBLIC_API(bool) +JS_StringHasBeenInterned(JSContext *cx, JSString *str); + +/* + * Only JSStrings that have been interned via the JSAPI can be turned into + * jsids by API clients. + * + * N.B. if a jsid is backed by a string which has not been interned, that + * string must be appropriately rooted to avoid being collected by the GC. + */ +JS_PUBLIC_API(jsid) +INTERNED_STRING_TO_JSID(JSContext *cx, JSString *str); + +namespace JS { + +// Container class for passing in script source buffers to the JS engine. This +// not only groups the buffer and length values, it also provides a way to +// optionally pass ownership of the buffer to the JS engine without copying. +// Rules for use: +// +// 1) The data array must be allocated with js_malloc() or js_realloc() if +// ownership is being granted to the SourceBufferHolder. +// 2) If ownership is not given to the SourceBufferHolder, then the memory +// must be kept alive until the JS compilation is complete. +// 3) Any code calling SourceBufferHolder::take() must guarantee to keep the +// memory alive until JS compilation completes. Normally only the JS +// engine should be calling take(). +// +// Example use: +// +// size_t length = 512; +// jschar* chars = static_cast(js_malloc(sizeof(jschar) * length)); +// JS::SourceBufferHolder srcBuf(chars, length, JS::SourceBufferHolder::GiveOwnership); +// JS::Compile(cx, obj, options, srcBuf); +// +class MOZ_STACK_CLASS SourceBufferHolder MOZ_FINAL +{ + public: + enum Ownership { + NoOwnership, + GiveOwnership + }; + + SourceBufferHolder(const jschar *data, size_t dataLength, Ownership ownership) + : data_(data), + length_(dataLength), + ownsChars_(ownership == GiveOwnership) + { + // Ensure that null buffers properly return an unowned, empty, + // null-terminated string. + static const jschar NullChar_ = 0; + if (!get()) { + data_ = &NullChar_; + length_ = 0; + ownsChars_ = false; + } + } + + ~SourceBufferHolder() { + if (ownsChars_) + js_free(const_cast(data_)); + } + + // Access the underlying source buffer without affecting ownership. + const jschar *get() const { return data_; } + + // Length of the source buffer in jschars (not bytes) + size_t length() const { return length_; } + + // Returns true if the SourceBufferHolder owns the buffer and will free + // it upon destruction. If true, it is legal to call take(). + bool ownsChars() const { return ownsChars_; } + + // Retrieve and take ownership of the underlying data buffer. The caller + // is now responsible for calling js_free() on the returned value, *but only + // after JS script compilation has completed*. + // + // After the buffer has been taken the SourceBufferHolder functions as if + // it had been constructed on an unowned buffer; get() and length() still + // work. In order for this to be safe the taken buffer must be kept alive + // until after JS script compilation completes as noted above. + // + // Note, it's the caller's responsibility to check ownsChars() before taking + // the buffer. Taking and then free'ing an unowned buffer will have dire + // consequences. + jschar *take() { + JS_ASSERT(ownsChars_); + ownsChars_ = false; + return const_cast(data_); + } + + private: + SourceBufferHolder(SourceBufferHolder &) MOZ_DELETE; + SourceBufferHolder &operator=(SourceBufferHolder &) MOZ_DELETE; + + const jschar *data_; + size_t length_; + bool ownsChars_; +}; + +} /* namespace JS */ + +/************************************************************************/ + +/* Property attributes, set in JSPropertySpec and passed to API functions. */ +#define JSPROP_ENUMERATE 0x01 /* property is visible to for/in loop */ +#define JSPROP_READONLY 0x02 /* not settable: assignment is no-op. + This flag is only valid when neither + JSPROP_GETTER nor JSPROP_SETTER is + set. */ +#define JSPROP_PERMANENT 0x04 /* property cannot be deleted */ +#define JSPROP_NATIVE_ACCESSORS 0x08 /* set in JSPropertyDescriptor.flags + if getters/setters are JSNatives */ +#define JSPROP_GETTER 0x10 /* property holds getter function */ +#define JSPROP_SETTER 0x20 /* property holds setter function */ +#define JSPROP_SHARED 0x40 /* don't allocate a value slot for this + property; don't copy the property on + set of the same-named property in an + object that delegates to a prototype + containing this property */ +#define JSPROP_INDEX 0x80 /* name is actually (int) index */ + +#define JSFUN_STUB_GSOPS 0x200 /* use JS_PropertyStub getter/setter + instead of defaulting to class gsops + for property holding function */ + +#define JSFUN_CONSTRUCTOR 0x400 /* native that can be called as a ctor */ + + +/* + * Specify a generic native prototype methods, i.e., methods of a class + * prototype that are exposed as static methods taking an extra leading + * argument: the generic |this| parameter. + * + * If you set this flag in a JSFunctionSpec struct's flags initializer, then + * that struct must live at least as long as the native static method object + * created due to this flag by JS_DefineFunctions or JS_InitClass. Typically + * JSFunctionSpec structs are allocated in static arrays. + */ +#define JSFUN_GENERIC_NATIVE 0x800 + +#define JSFUN_FLAGS_MASK 0xe00 /* | of all the JSFUN_* flags */ + +/* + * The first call to JS_CallOnce by any thread in a process will call 'func'. + * Later calls to JS_CallOnce with the same JSCallOnceType object will be + * suppressed. + * + * Equivalently: each distinct JSCallOnceType object will allow one JS_CallOnce + * to invoke its JSInitCallback. + */ +extern JS_PUBLIC_API(bool) +JS_CallOnce(JSCallOnceType *once, JSInitCallback func); + +/* Microseconds since the epoch, midnight, January 1, 1970 UTC. */ +extern JS_PUBLIC_API(int64_t) +JS_Now(void); + +/* Don't want to export data, so provide accessors for non-inline jsvals. */ +extern JS_PUBLIC_API(jsval) +JS_GetNaNValue(JSContext *cx); + +extern JS_PUBLIC_API(jsval) +JS_GetNegativeInfinityValue(JSContext *cx); + +extern JS_PUBLIC_API(jsval) +JS_GetPositiveInfinityValue(JSContext *cx); + +extern JS_PUBLIC_API(jsval) +JS_GetEmptyStringValue(JSContext *cx); + +extern JS_PUBLIC_API(JSString *) +JS_GetEmptyString(JSRuntime *rt); + +/* + * Format is a string of the following characters (spaces are insignificant), + * specifying the tabulated type conversions: + * + * b bool Boolean + * c uint16_t/jschar ECMA uint16_t, Unicode char + * i int32_t ECMA int32_t + * j int32_t ECMA int32_t (used to be different) + * u uint32_t ECMA uint32_t + * d double IEEE double + * I double Integral IEEE double + * S JSString * Unicode string, accessed by a JSString pointer + * W jschar * Unicode character vector, 0-terminated (W for wide) + * o JSObject * Object reference + * f JSFunction * Function private + * v jsval Argument value (no conversion) + * * N/A Skip this argument (no vararg) + * / N/A End of required arguments + * + * The variable argument list after format must consist of &b, &c, &s, e.g., + * where those variables have the types given above. For the pointer types + * char *, JSString *, and JSObject *, the pointed-at memory returned belongs + * to the JS runtime, not to the calling native code. The runtime promises + * to keep this memory valid so long as argv refers to allocated stack space + * (so long as the native function is active). + * + * Fewer arguments than format specifies may be passed only if there is a / + * in format after the last required argument specifier and argc is at least + * the number of required arguments. More arguments than format specifies + * may be passed without error; it is up to the caller to deal with trailing + * unconverted arguments. + */ +extern JS_PUBLIC_API(bool) +JS_ConvertArguments(JSContext *cx, const JS::CallArgs &args, const char *format, ...); + +#ifdef va_start +extern JS_PUBLIC_API(bool) +JS_ConvertArgumentsVA(JSContext *cx, const JS::CallArgs &args, const char *format, + va_list ap); +#endif + +extern JS_PUBLIC_API(bool) +JS_ConvertValue(JSContext *cx, JS::HandleValue v, JSType type, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ValueToObject(JSContext *cx, JS::HandleValue v, JS::MutableHandleObject objp); + +extern JS_PUBLIC_API(JSFunction *) +JS_ValueToFunction(JSContext *cx, JS::HandleValue v); + +extern JS_PUBLIC_API(JSFunction *) +JS_ValueToConstructor(JSContext *cx, JS::HandleValue v); + +extern JS_PUBLIC_API(JSString *) +JS_ValueToSource(JSContext *cx, JS::Handle v); + +namespace js { +/* + * DO NOT CALL THIS. Use JS::ToNumber + */ +extern JS_PUBLIC_API(bool) +ToNumberSlow(JSContext *cx, JS::Value v, double *dp); + +/* + * DO NOT CALL THIS. Use JS::ToBoolean + */ +extern JS_PUBLIC_API(bool) +ToBooleanSlow(JS::HandleValue v); + +/* + * DO NOT CALL THIS. Use JS::ToString + */ +extern JS_PUBLIC_API(JSString*) +ToStringSlow(JSContext *cx, JS::HandleValue v); +} /* namespace js */ + +namespace JS { + +/* ES5 9.3 ToNumber. */ +MOZ_ALWAYS_INLINE bool +ToNumber(JSContext *cx, HandleValue v, double *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isNumber()) { + *out = v.toNumber(); + return true; + } + return js::ToNumberSlow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToBoolean(HandleValue v) +{ + if (v.isBoolean()) + return v.toBoolean(); + if (v.isInt32()) + return v.toInt32() != 0; + if (v.isNullOrUndefined()) + return false; + if (v.isDouble()) { + double d = v.toDouble(); + return !mozilla::IsNaN(d) && d != 0; + } + if (v.isSymbol()) + return true; + + /* The slow path handles strings and objects. */ + return js::ToBooleanSlow(v); +} + +MOZ_ALWAYS_INLINE JSString* +ToString(JSContext *cx, HandleValue v) +{ + if (v.isString()) + return v.toString(); + return js::ToStringSlow(cx, v); +} + +} /* namespace JS */ + +extern JS_PUBLIC_API(bool) +JS_DoubleIsInt32(double d, int32_t *ip); + +extern JS_PUBLIC_API(int32_t) +JS_DoubleToInt32(double d); + +extern JS_PUBLIC_API(uint32_t) +JS_DoubleToUint32(double d); + + +namespace js { +/* DO NOT CALL THIS. Use JS::ToUint16. */ +extern JS_PUBLIC_API(bool) +ToUint16Slow(JSContext *cx, JS::HandleValue v, uint16_t *out); + +/* DO NOT CALL THIS. Use JS::ToInt32. */ +extern JS_PUBLIC_API(bool) +ToInt32Slow(JSContext *cx, JS::HandleValue v, int32_t *out); + +/* DO NOT CALL THIS. Use JS::ToUint32. */ +extern JS_PUBLIC_API(bool) +ToUint32Slow(JSContext *cx, JS::HandleValue v, uint32_t *out); + +/* DO NOT CALL THIS. Use JS::ToInt64. */ +extern JS_PUBLIC_API(bool) +ToInt64Slow(JSContext *cx, JS::HandleValue v, int64_t *out); + +/* DO NOT CALL THIS. Use JS::ToUint64. */ +extern JS_PUBLIC_API(bool) +ToUint64Slow(JSContext *cx, JS::HandleValue v, uint64_t *out); +} /* namespace js */ + +namespace JS { + +MOZ_ALWAYS_INLINE bool +ToUint16(JSContext *cx, JS::HandleValue v, uint16_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + *out = uint16_t(v.toInt32()); + return true; + } + return js::ToUint16Slow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToInt32(JSContext *cx, JS::HandleValue v, int32_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + *out = v.toInt32(); + return true; + } + return js::ToInt32Slow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToUint32(JSContext *cx, JS::HandleValue v, uint32_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + *out = uint32_t(v.toInt32()); + return true; + } + return js::ToUint32Slow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToInt64(JSContext *cx, JS::HandleValue v, int64_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + *out = int64_t(v.toInt32()); + return true; + } + return js::ToInt64Slow(cx, v, out); +} + +MOZ_ALWAYS_INLINE bool +ToUint64(JSContext *cx, JS::HandleValue v, uint64_t *out) +{ + AssertArgumentsAreSane(cx, v); + + if (v.isInt32()) { + /* Account for sign extension of negatives into the longer 64bit space. */ + *out = uint64_t(int64_t(v.toInt32())); + return true; + } + return js::ToUint64Slow(cx, v, out); +} + + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSType) +JS_TypeOfValue(JSContext *cx, JS::Handle v); + +extern JS_PUBLIC_API(const char *) +JS_GetTypeName(JSContext *cx, JSType type); + +extern JS_PUBLIC_API(bool) +JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal); + +extern JS_PUBLIC_API(bool) +JS_LooselyEqual(JSContext *cx, JS::Handle v1, JS::Handle v2, bool *equal); + +extern JS_PUBLIC_API(bool) +JS_SameValue(JSContext *cx, jsval v1, jsval v2, bool *same); + +/* True iff fun is the global eval function. */ +extern JS_PUBLIC_API(bool) +JS_IsBuiltinEvalFunction(JSFunction *fun); + +/* True iff fun is the Function constructor. */ +extern JS_PUBLIC_API(bool) +JS_IsBuiltinFunctionConstructor(JSFunction *fun); + +/************************************************************************/ + +/* + * Initialization, locking, contexts, and memory allocation. + * + * It is important that the first runtime and first context be created in a + * single-threaded fashion, otherwise the behavior of the library is undefined. + * See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference + */ + +/** + * Initialize SpiderMonkey, returning true only if initialization succeeded. + * Once this method has succeeded, it is safe to call JS_NewRuntime and other + * JSAPI methods. + * + * This method must be called before any other JSAPI method is used on any + * thread. Once it has been used, it is safe to call any JSAPI method, and it + * remains safe to do so until JS_ShutDown is correctly called. + * + * It is currently not possible to initialize SpiderMonkey multiple times (that + * is, calling JS_Init/JSAPI methods/JS_ShutDown in that order, then doing so + * again). This restriction may eventually be lifted. + */ +extern JS_PUBLIC_API(bool) +JS_Init(void); + +/** + * Destroy free-standing resources allocated by SpiderMonkey, not associated + * with any runtime, context, or other structure. + * + * This method should be called after all other JSAPI data has been properly + * cleaned up: every new runtime must have been destroyed, every new context + * must have been destroyed, and so on. Calling this method before all other + * resources have been destroyed has undefined behavior. + * + * Failure to call this method, at present, has no adverse effects other than + * leaking memory. This may not always be the case; it's recommended that all + * embedders call this method when all other JSAPI operations have completed. + * + * It is currently not possible to initialize SpiderMonkey multiple times (that + * is, calling JS_Init/JSAPI methods/JS_ShutDown in that order, then doing so + * again). This restriction may eventually be lifted. + */ +extern JS_PUBLIC_API(void) +JS_ShutDown(void); + +extern JS_PUBLIC_API(JSRuntime *) +JS_NewRuntime(uint32_t maxbytes, + uint32_t maxNurseryBytes = JS::DefaultNurseryBytes, + JSRuntime *parentRuntime = nullptr); + +extern JS_PUBLIC_API(void) +JS_DestroyRuntime(JSRuntime *rt); + +// These are equivalent to ICU's |UMemAllocFn|, |UMemReallocFn|, and +// |UMemFreeFn| types. The first argument (called |context| in the ICU docs) +// will always be nullptr, and should be ignored. +typedef void *(*JS_ICUAllocFn)(const void *, size_t size); +typedef void *(*JS_ICUReallocFn)(const void *, void *p, size_t size); +typedef void (*JS_ICUFreeFn)(const void *, void *p); + +// This function can be used to track memory used by ICU. +// Do not use it unless you know what you are doing! +extern JS_PUBLIC_API(bool) +JS_SetICUMemoryFunctions(JS_ICUAllocFn allocFn, JS_ICUReallocFn reallocFn, JS_ICUFreeFn freeFn); + +JS_PUBLIC_API(void *) +JS_GetRuntimePrivate(JSRuntime *rt); + +extern JS_PUBLIC_API(JSRuntime *) +JS_GetRuntime(JSContext *cx); + +extern JS_PUBLIC_API(JSRuntime *) +JS_GetParentRuntime(JSContext *cx); + +JS_PUBLIC_API(void) +JS_SetRuntimePrivate(JSRuntime *rt, void *data); + +extern JS_PUBLIC_API(void) +JS_BeginRequest(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_EndRequest(JSContext *cx); + +extern JS_PUBLIC_API(bool) +JS_IsInRequest(JSRuntime *rt); + +namespace js { + +void +AssertHeapIsIdle(JSRuntime *rt); + +void +AssertHeapIsIdle(JSContext *cx); + +} /* namespace js */ + +class JSAutoRequest +{ + public: + explicit JSAutoRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mContext(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + JS_BeginRequest(mContext); + } + ~JSAutoRequest() { + JS_EndRequest(mContext); + } + + protected: + JSContext *mContext; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + +#if 0 + private: + static void *operator new(size_t) CPP_THROW_NEW { return 0; }; + static void operator delete(void *, size_t) { }; +#endif +}; + +class JSAutoCheckRequest +{ + public: + explicit JSAutoCheckRequest(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + { +#if defined JS_THREADSAFE && defined JS_DEBUG + mContext = cx; + JS_ASSERT(JS_IsInRequest(JS_GetRuntime(cx))); +#endif + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + ~JSAutoCheckRequest() { +#if defined JS_THREADSAFE && defined JS_DEBUG + JS_ASSERT(JS_IsInRequest(JS_GetRuntime(mContext))); +#endif + } + + + private: +#if defined JS_THREADSAFE && defined JS_DEBUG + JSContext *mContext; +#endif + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +extern JS_PUBLIC_API(void) +JS_SetContextCallback(JSRuntime *rt, JSContextCallback cxCallback, void *data); + +extern JS_PUBLIC_API(JSContext *) +JS_NewContext(JSRuntime *rt, size_t stackChunkSize); + +extern JS_PUBLIC_API(void) +JS_DestroyContext(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_DestroyContextNoGC(JSContext *cx); + +extern JS_PUBLIC_API(void *) +JS_GetContextPrivate(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_SetContextPrivate(JSContext *cx, void *data); + +extern JS_PUBLIC_API(void *) +JS_GetSecondContextPrivate(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_SetSecondContextPrivate(JSContext *cx, void *data); + +extern JS_PUBLIC_API(JSRuntime *) +JS_GetRuntime(JSContext *cx); + +extern JS_PUBLIC_API(JSContext *) +JS_ContextIterator(JSRuntime *rt, JSContext **iterp); + +extern JS_PUBLIC_API(JSVersion) +JS_GetVersion(JSContext *cx); + +// Mutate the version on the compartment. This is generally discouraged, but +// necessary to support the version mutation in the js and xpc shell command +// set. +// +// It would be nice to put this in jsfriendapi, but the linkage requirements +// of the shells make that impossible. +JS_PUBLIC_API(void) +JS_SetVersionForCompartment(JSCompartment *compartment, JSVersion version); + +extern JS_PUBLIC_API(const char *) +JS_VersionToString(JSVersion version); + +extern JS_PUBLIC_API(JSVersion) +JS_StringToVersion(const char *string); + +namespace JS { + +class JS_PUBLIC_API(RuntimeOptions) { + public: + RuntimeOptions() + : baseline_(false), + ion_(false), + asmJS_(false), + nativeRegExp_(false), + werror_(false), + strictMode_(false), + varObjFix_(false) + { + } + + bool baseline() const { return baseline_; } + RuntimeOptions &setBaseline(bool flag) { + baseline_ = flag; + return *this; + } + RuntimeOptions &toggleBaseline() { + baseline_ = !baseline_; + return *this; + } + + bool ion() const { return ion_; } + RuntimeOptions &setIon(bool flag) { + ion_ = flag; + return *this; + } + RuntimeOptions &toggleIon() { + ion_ = !ion_; + return *this; + } + + bool asmJS() const { return asmJS_; } + RuntimeOptions &setAsmJS(bool flag) { + asmJS_ = flag; + return *this; + } + RuntimeOptions &toggleAsmJS() { + asmJS_ = !asmJS_; + return *this; + } + + bool nativeRegExp() const { return nativeRegExp_; } + RuntimeOptions &setNativeRegExp(bool flag) { + nativeRegExp_ = flag; + return *this; + } + + bool werror() const { return werror_; } + RuntimeOptions &setWerror(bool flag) { + werror_ = flag; + return *this; + } + RuntimeOptions &toggleWerror() { + werror_ = !werror_; + return *this; + } + + bool strictMode() const { return strictMode_; } + RuntimeOptions &setStrictMode(bool flag) { + strictMode_ = flag; + return *this; + } + RuntimeOptions &toggleStrictMode() { + strictMode_ = !strictMode_; + return *this; + } + + bool varObjFix() const { return varObjFix_; } + RuntimeOptions &setVarObjFix(bool flag) { + varObjFix_ = flag; + return *this; + } + RuntimeOptions &toggleVarObjFix() { + varObjFix_ = !varObjFix_; + return *this; + } + + private: + bool baseline_ : 1; + bool ion_ : 1; + bool asmJS_ : 1; + bool nativeRegExp_ : 1; + bool werror_ : 1; + bool strictMode_ : 1; + bool varObjFix_ : 1; +}; + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSRuntime *rt); + +JS_PUBLIC_API(RuntimeOptions &) +RuntimeOptionsRef(JSContext *cx); + +class JS_PUBLIC_API(ContextOptions) { + public: + ContextOptions() + : extraWarnings_(false), + privateIsNSISupports_(false), + dontReportUncaught_(false), + noDefaultCompartmentObject_(false), + noScriptRval_(false) + { + } + + bool extraWarnings() const { return extraWarnings_; } + ContextOptions &setExtraWarnings(bool flag) { + extraWarnings_ = flag; + return *this; + } + ContextOptions &toggleExtraWarnings() { + extraWarnings_ = !extraWarnings_; + return *this; + } + + bool privateIsNSISupports() const { return privateIsNSISupports_; } + ContextOptions &setPrivateIsNSISupports(bool flag) { + privateIsNSISupports_ = flag; + return *this; + } + ContextOptions &togglePrivateIsNSISupports() { + privateIsNSISupports_ = !privateIsNSISupports_; + return *this; + } + + bool dontReportUncaught() const { return dontReportUncaught_; } + ContextOptions &setDontReportUncaught(bool flag) { + dontReportUncaught_ = flag; + return *this; + } + ContextOptions &toggleDontReportUncaught() { + dontReportUncaught_ = !dontReportUncaught_; + return *this; + } + + bool noDefaultCompartmentObject() const { return noDefaultCompartmentObject_; } + ContextOptions &setNoDefaultCompartmentObject(bool flag) { + noDefaultCompartmentObject_ = flag; + return *this; + } + ContextOptions &toggleNoDefaultCompartmentObject() { + noDefaultCompartmentObject_ = !noDefaultCompartmentObject_; + return *this; + } + + bool noScriptRval() const { return noScriptRval_; } + ContextOptions &setNoScriptRval(bool flag) { + noScriptRval_ = flag; + return *this; + } + ContextOptions &toggleNoScriptRval() { + noScriptRval_ = !noScriptRval_; + return *this; + } + + private: + bool extraWarnings_ : 1; + bool privateIsNSISupports_ : 1; + bool dontReportUncaught_ : 1; + bool noDefaultCompartmentObject_ : 1; + bool noScriptRval_ : 1; +}; + +JS_PUBLIC_API(ContextOptions &) +ContextOptionsRef(JSContext *cx); + +class JS_PUBLIC_API(AutoSaveContextOptions) { + public: + explicit AutoSaveContextOptions(JSContext *cx) + : cx_(cx), + oldOptions_(ContextOptionsRef(cx_)) + { + } + + ~AutoSaveContextOptions() + { + ContextOptionsRef(cx_) = oldOptions_; + } + + private: + JSContext *cx_; + JS::ContextOptions oldOptions_; +}; + +} /* namespace JS */ + +extern JS_PUBLIC_API(const char *) +JS_GetImplementationVersion(void); + +extern JS_PUBLIC_API(void) +JS_SetDestroyCompartmentCallback(JSRuntime *rt, JSDestroyCompartmentCallback callback); + +extern JS_PUBLIC_API(void) +JS_SetDestroyZoneCallback(JSRuntime *rt, JSZoneCallback callback); + +extern JS_PUBLIC_API(void) +JS_SetSweepZoneCallback(JSRuntime *rt, JSZoneCallback callback); + +extern JS_PUBLIC_API(void) +JS_SetCompartmentNameCallback(JSRuntime *rt, JSCompartmentNameCallback callback); + +extern JS_PUBLIC_API(void) +JS_SetWrapObjectCallbacks(JSRuntime *rt, const JSWrapObjectCallbacks *callbacks); + +extern JS_PUBLIC_API(void) +JS_SetCompartmentPrivate(JSCompartment *compartment, void *data); + +extern JS_PUBLIC_API(void *) +JS_GetCompartmentPrivate(JSCompartment *compartment); + +extern JS_PUBLIC_API(void) +JS_SetZoneUserData(JS::Zone *zone, void *data); + +extern JS_PUBLIC_API(void *) +JS_GetZoneUserData(JS::Zone *zone); + +extern JS_PUBLIC_API(bool) +JS_WrapObject(JSContext *cx, JS::MutableHandleObject objp); + +extern JS_PUBLIC_API(bool) +JS_WrapValue(JSContext *cx, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(JSObject *) +JS_TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target); + +extern JS_PUBLIC_API(bool) +JS_RefreshCrossCompartmentWrappers(JSContext *cx, JS::Handle obj); + +/* + * At any time, a JSContext has a current (possibly-nullptr) compartment. + * Compartments are described in: + * + * developer.mozilla.org/en-US/docs/SpiderMonkey/SpiderMonkey_compartments + * + * The current compartment of a context may be changed. The preferred way to do + * this is with JSAutoCompartment: + * + * void foo(JSContext *cx, JSObject *obj) { + * // in some compartment 'c' + * { + * JSAutoCompartment ac(cx, obj); // constructor enters + * // in the compartment of 'obj' + * } // destructor leaves + * // back in compartment 'c' + * } + * + * For more complicated uses that don't neatly fit in a C++ stack frame, the + * compartment can entered and left using separate function calls: + * + * void foo(JSContext *cx, JSObject *obj) { + * // in 'oldCompartment' + * JSCompartment *oldCompartment = JS_EnterCompartment(cx, obj); + * // in the compartment of 'obj' + * JS_LeaveCompartment(cx, oldCompartment); + * // back in 'oldCompartment' + * } + * + * Note: these calls must still execute in a LIFO manner w.r.t all other + * enter/leave calls on the context. Furthermore, only the return value of a + * JS_EnterCompartment call may be passed as the 'oldCompartment' argument of + * the corresponding JS_LeaveCompartment call. + */ + +class JS_PUBLIC_API(JSAutoCompartment) +{ + JSContext *cx_; + JSCompartment *oldCompartment_; + public: + JSAutoCompartment(JSContext *cx, JSObject *target); + JSAutoCompartment(JSContext *cx, JSScript *target); + ~JSAutoCompartment(); +}; + +class JS_PUBLIC_API(JSAutoNullableCompartment) +{ + JSContext *cx_; + JSCompartment *oldCompartment_; + public: + explicit JSAutoNullableCompartment(JSContext *cx, JSObject *targetOrNull); + ~JSAutoNullableCompartment(); +}; + +/* NB: This API is infallible; a nullptr return value does not indicate error. */ +extern JS_PUBLIC_API(JSCompartment *) +JS_EnterCompartment(JSContext *cx, JSObject *target); + +extern JS_PUBLIC_API(void) +JS_LeaveCompartment(JSContext *cx, JSCompartment *oldCompartment); + +typedef void (*JSIterateCompartmentCallback)(JSRuntime *rt, void *data, JSCompartment *compartment); + +/* + * This function calls |compartmentCallback| on every compartment. Beware that + * there is no guarantee that the compartment will survive after the callback + * returns. + */ +extern JS_PUBLIC_API(void) +JS_IterateCompartments(JSRuntime *rt, void *data, + JSIterateCompartmentCallback compartmentCallback); + +/* + * Initialize standard JS class constructors, prototypes, and any top-level + * functions and constants associated with the standard classes (e.g. isNaN + * for Number). + * + * NB: This sets cx's global object to obj if it was null. + */ +extern JS_PUBLIC_API(bool) +JS_InitStandardClasses(JSContext *cx, JS::Handle obj); + +/* + * Resolve id, which must contain either a string or an int, to a standard + * class name in obj if possible, defining the class's constructor and/or + * prototype and storing true in *resolved. If id does not name a standard + * class or a top-level property induced by initializing a standard class, + * store false in *resolved and just return true. Return false on error, + * as usual for bool result-typed API entry points. + * + * This API can be called directly from a global object class's resolve op, + * to define standard classes lazily. The class's enumerate op should call + * JS_EnumerateStandardClasses(cx, obj), to define eagerly during for..in + * loops any classes not yet resolved lazily. + */ +extern JS_PUBLIC_API(bool) +JS_ResolveStandardClass(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *resolved); + +extern JS_PUBLIC_API(bool) +JS_EnumerateStandardClasses(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(bool) +JS_GetClassObject(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); + +extern JS_PUBLIC_API(bool) +JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JS::MutableHandle objp); + +namespace JS { + +/* + * Determine if the given object is an instance/prototype/constructor for a standard + * class. If so, return the associated JSProtoKey. If not, return JSProto_Null. + */ + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstance(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardInstanceOrPrototype(JSObject *obj); + +extern JS_PUBLIC_API(JSProtoKey) +IdentifyStandardConstructor(JSObject *obj); + +extern JS_PUBLIC_API(void) +ProtoKeyToId(JSContext *cx, JSProtoKey key, JS::MutableHandleId idp); + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSProtoKey) +JS_IdToProtoKey(JSContext *cx, JS::HandleId id); + +/* + * Returns the original value of |Function.prototype| from the global object in + * which |forObj| was created. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetFunctionPrototype(JSContext *cx, JS::HandleObject forObj); + +/* + * Returns the original value of |Object.prototype| from the global object in + * which |forObj| was created. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetObjectPrototype(JSContext *cx, JS::HandleObject forObj); + +/* + * Returns the original value of |Array.prototype| from the global object in + * which |forObj| was created. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetArrayPrototype(JSContext *cx, JS::HandleObject forObj); + +/* + * Returns the original value of |Error.prototype| from the global + * object of the current compartment of cx. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetErrorPrototype(JSContext *cx); + +extern JS_PUBLIC_API(JSObject *) +JS_GetGlobalForObject(JSContext *cx, JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_IsGlobalObject(JSObject *obj); + +/* + * May return nullptr, if |c| never had a global (e.g. the atoms compartment), + * or if |c|'s global has been collected. + */ +extern JS_PUBLIC_API(JSObject *) +JS_GetGlobalForCompartmentOrNull(JSContext *cx, JSCompartment *c); + +namespace JS { + +extern JS_PUBLIC_API(JSObject *) +CurrentGlobalOrNull(JSContext *cx); + +} + +/* + * Initialize the 'Reflect' object on a global object. + */ +extern JS_PUBLIC_API(JSObject *) +JS_InitReflect(JSContext *cx, JS::HandleObject global); + +#ifdef JS_HAS_CTYPES +/* + * Initialize the 'ctypes' object on a global variable 'obj'. The 'ctypes' + * object will be sealed. + */ +extern JS_PUBLIC_API(bool) +JS_InitCTypesClass(JSContext *cx, JS::HandleObject global); + +/* + * Convert a unicode string 'source' of length 'slen' to the platform native + * charset, returning a null-terminated string allocated with JS_malloc. On + * failure, this function should report an error. + */ +typedef char * +(* JSCTypesUnicodeToNativeFun)(JSContext *cx, const jschar *source, size_t slen); + +/* + * Set of function pointers that ctypes can use for various internal functions. + * See JS_SetCTypesCallbacks below. Providing nullptr for a function is safe, + * and will result in the applicable ctypes functionality not being available. + */ +struct JSCTypesCallbacks { + JSCTypesUnicodeToNativeFun unicodeToNative; +}; + +typedef struct JSCTypesCallbacks JSCTypesCallbacks; + +/* + * Set the callbacks on the provided 'ctypesObj' object. 'callbacks' should be a + * pointer to static data that exists for the lifetime of 'ctypesObj', but it + * may safely be altered after calling this function and without having + * to call this function again. + */ +extern JS_PUBLIC_API(void) +JS_SetCTypesCallbacks(JSObject *ctypesObj, JSCTypesCallbacks *callbacks); +#endif + +typedef bool +(* JSEnumerateDiagnosticMemoryCallback)(void *ptr, size_t length); + +/* + * Enumerate memory regions that contain diagnostic information + * intended to be included in crash report minidumps. + */ +extern JS_PUBLIC_API(void) +JS_EnumerateDiagnosticMemoryRegions(JSEnumerateDiagnosticMemoryCallback callback); + +extern JS_PUBLIC_API(void *) +JS_malloc(JSContext *cx, size_t nbytes); + +extern JS_PUBLIC_API(void *) +JS_realloc(JSContext *cx, void *p, size_t nbytes); + +/* + * A wrapper for js_free(p) that may delay js_free(p) invocation as a + * performance optimization. + * cx may be nullptr. + */ +extern JS_PUBLIC_API(void) +JS_free(JSContext *cx, void *p); + +/* + * A wrapper for js_free(p) that may delay js_free(p) invocation as a + * performance optimization as specified by the given JSFreeOp instance. + */ +extern JS_PUBLIC_API(void) +JS_freeop(JSFreeOp *fop, void *p); + +extern JS_PUBLIC_API(JSFreeOp *) +JS_GetDefaultFreeOp(JSRuntime *rt); + +extern JS_PUBLIC_API(void) +JS_updateMallocCounter(JSContext *cx, size_t nbytes); + +extern JS_PUBLIC_API(char *) +JS_strdup(JSContext *cx, const char *s); + +/* Duplicate a string. Does not report an error on failure. */ +extern JS_PUBLIC_API(char *) +JS_strdup(JSRuntime *rt, const char *s); + +namespace JS { + +/* + * A GC root is a pointer to a jsval, JSObject * or JSString * that itself + * points into the GC heap. JS_AddValueRoot takes a pointer to a jsval and + * JS_AddGCThingRoot takes a pointer to a JSObject * or JString *. + * + * Note that, since JS_Add*Root stores the address of a variable (of type + * jsval, JSString *, or JSObject *), that variable must live until + * JS_Remove*Root is called to remove that variable. For example, after: + * + * void some_function() { + * jsval v; + * JS_AddNamedValueRoot(cx, &v, "name"); + * + * the caller must perform + * + * JS_RemoveValueRoot(cx, &v); + * + * before some_function() returns. + * + * Also, use JS_AddNamed*Root(cx, &structPtr->memberObj, "structPtr->memberObj") + * in preference to JS_Add*Root(cx, &structPtr->memberObj), in order to identify + * roots by their source callsites. This way, you can find the callsite while + * debugging if you should fail to do JS_Remove*Root(cx, &structPtr->memberObj) + * before freeing structPtr's memory. + */ +extern JS_PUBLIC_API(bool) +AddValueRoot(JSContext *cx, JS::Heap *vp); + +extern JS_PUBLIC_API(bool) +AddStringRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(bool) +AddObjectRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(bool) +AddNamedValueRoot(JSContext *cx, JS::Heap *vp, const char *name); + +extern JS_PUBLIC_API(bool) +AddNamedValueRootRT(JSRuntime *rt, JS::Heap *vp, const char *name); + +extern JS_PUBLIC_API(bool) +AddNamedStringRoot(JSContext *cx, JS::Heap *rp, const char *name); + +extern JS_PUBLIC_API(bool) +AddNamedObjectRoot(JSContext *cx, JS::Heap *rp, const char *name); + +extern JS_PUBLIC_API(bool) +AddNamedScriptRoot(JSContext *cx, JS::Heap *rp, const char *name); + +extern JS_PUBLIC_API(void) +RemoveValueRoot(JSContext *cx, JS::Heap *vp); + +extern JS_PUBLIC_API(void) +RemoveStringRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveObjectRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveScriptRoot(JSContext *cx, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveValueRootRT(JSRuntime *rt, JS::Heap *vp); + +extern JS_PUBLIC_API(void) +RemoveStringRootRT(JSRuntime *rt, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveObjectRootRT(JSRuntime *rt, JS::Heap *rp); + +extern JS_PUBLIC_API(void) +RemoveScriptRootRT(JSRuntime *rt, JS::Heap *rp); + +} /* namespace JS */ + +/* + * Register externally maintained GC roots. + * + * traceOp: the trace operation. For each root the implementation should call + * JS_CallTracer whenever the root contains a traceable thing. + * data: the data argument to pass to each invocation of traceOp. + */ +extern JS_PUBLIC_API(bool) +JS_AddExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); + +/* Undo a call to JS_AddExtraGCRootsTracer. */ +extern JS_PUBLIC_API(void) +JS_RemoveExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); + +#ifdef JS_DEBUG + +/* + * Debug-only method to dump the object graph of heap-allocated things. + * + * fp: file for the dump output. + * start: when non-null, dump only things reachable from start + * thing. Otherwise dump all things reachable from the + * runtime roots. + * startKind: trace kind of start if start is not null. Must be + * JSTRACE_OBJECT when start is null. + * thingToFind: dump only paths in the object graph leading to thingToFind + * when non-null. + * maxDepth: the upper bound on the number of edges to descend from the + * graph roots. + * thingToIgnore: thing to ignore during the graph traversal when non-null. + */ +extern JS_PUBLIC_API(bool) +JS_DumpHeap(JSRuntime *rt, FILE *fp, void* startThing, JSGCTraceKind kind, + void *thingToFind, size_t maxDepth, void *thingToIgnore); + +#endif + +/* + * Garbage collector API. + */ +extern JS_PUBLIC_API(void) +JS_GC(JSRuntime *rt); + +extern JS_PUBLIC_API(void) +JS_MaybeGC(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_SetGCCallback(JSRuntime *rt, JSGCCallback cb, void *data); + +extern JS_PUBLIC_API(bool) +JS_AddFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb, void *data); + +extern JS_PUBLIC_API(void) +JS_RemoveFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); + +extern JS_PUBLIC_API(bool) +JS_IsGCMarkingTracer(JSTracer *trc); + +/* For assertions only. */ +#ifdef JS_DEBUG +extern JS_PUBLIC_API(bool) +JS_IsMarkingGray(JSTracer *trc); +#endif + +/* + * JS_IsAboutToBeFinalized checks if the given object is going to be finalized + * at the end of the current GC. When called outside of the context of a GC, + * this function will return false. Typically this function is used on weak + * references, where the reference should be nulled out or destroyed if the + * given object is about to be finalized. + * + * The argument to JS_IsAboutToBeFinalized is an in-out param: when the + * function returns false, the object being referenced is still alive, but the + * garbage collector might have moved it. In this case, the reference passed + * to JS_IsAboutToBeFinalized will be updated to the object's new location. + * Callers of this method are responsible for updating any state that is + * dependent on the object's address. For example, if the object's address is + * used as a key in a hashtable, then the object must be removed and + * re-inserted with the correct hash. + */ +extern JS_PUBLIC_API(bool) +JS_IsAboutToBeFinalized(JS::Heap *objp); + +extern JS_PUBLIC_API(bool) +JS_IsAboutToBeFinalizedUnbarriered(JSObject **objp); + +typedef enum JSGCParamKey { + /* Maximum nominal heap before last ditch GC. */ + JSGC_MAX_BYTES = 0, + + /* Number of JS_malloc bytes before last ditch GC. */ + JSGC_MAX_MALLOC_BYTES = 1, + + /* Amount of bytes allocated by the GC. */ + JSGC_BYTES = 3, + + /* Number of times when GC was invoked. */ + JSGC_NUMBER = 4, + + /* Max size of the code cache in bytes. */ + JSGC_MAX_CODE_CACHE_BYTES = 5, + + /* Select GC mode. */ + JSGC_MODE = 6, + + /* Number of cached empty GC chunks. */ + JSGC_UNUSED_CHUNKS = 7, + + /* Total number of allocated GC chunks. */ + JSGC_TOTAL_CHUNKS = 8, + + /* Max milliseconds to spend in an incremental GC slice. */ + JSGC_SLICE_TIME_BUDGET = 9, + + /* Maximum size the GC mark stack can grow to. */ + JSGC_MARK_STACK_LIMIT = 10, + + /* + * GCs less than this far apart in time will be considered 'high-frequency GCs'. + * See setGCLastBytes in jsgc.cpp. + */ + JSGC_HIGH_FREQUENCY_TIME_LIMIT = 11, + + /* Start of dynamic heap growth. */ + JSGC_HIGH_FREQUENCY_LOW_LIMIT = 12, + + /* End of dynamic heap growth. */ + JSGC_HIGH_FREQUENCY_HIGH_LIMIT = 13, + + /* Upper bound of heap growth. */ + JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX = 14, + + /* Lower bound of heap growth. */ + JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN = 15, + + /* Heap growth for low frequency GCs. */ + JSGC_LOW_FREQUENCY_HEAP_GROWTH = 16, + + /* + * If false, the heap growth factor is fixed at 3. If true, it is determined + * based on whether GCs are high- or low- frequency. + */ + JSGC_DYNAMIC_HEAP_GROWTH = 17, + + /* If true, high-frequency GCs will use a longer mark slice. */ + JSGC_DYNAMIC_MARK_SLICE = 18, + + /* Lower limit after which we limit the heap growth. */ + JSGC_ALLOCATION_THRESHOLD = 19, + + /* + * We decommit memory lazily. If more than this number of megabytes is + * available to be decommitted, then JS_MaybeGC will trigger a shrinking GC + * to decommit it. + */ + JSGC_DECOMMIT_THRESHOLD = 20, + + /* + * We try to keep at least this many unused chunks in the free chunk pool at + * all times, even after a shrinking GC. + */ + JSGC_MIN_EMPTY_CHUNK_COUNT = 21, + + /* We never keep more than this many unused chunks in the free chunk pool. */ + JSGC_MAX_EMPTY_CHUNK_COUNT = 22 +} JSGCParamKey; + +extern JS_PUBLIC_API(void) +JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32_t value); + +extern JS_PUBLIC_API(uint32_t) +JS_GetGCParameter(JSRuntime *rt, JSGCParamKey key); + +extern JS_PUBLIC_API(void) +JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32_t value); + +extern JS_PUBLIC_API(uint32_t) +JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key); + +extern JS_PUBLIC_API(void) +JS_SetGCParametersBasedOnAvailableMemory(JSRuntime *rt, uint32_t availMem); + +/* + * Create a new JSString whose chars member refers to external memory, i.e., + * memory requiring application-specific finalization. + */ +extern JS_PUBLIC_API(JSString *) +JS_NewExternalString(JSContext *cx, const jschar *chars, size_t length, + const JSStringFinalizer *fin); + +/* + * Return whether 'str' was created with JS_NewExternalString or + * JS_NewExternalStringWithClosure. + */ +extern JS_PUBLIC_API(bool) +JS_IsExternalString(JSString *str); + +/* + * Return the 'closure' arg passed to JS_NewExternalStringWithClosure or + * nullptr if the external string was created via JS_NewExternalString. + */ +extern JS_PUBLIC_API(const JSStringFinalizer *) +JS_GetExternalStringFinalizer(JSString *str); + +/* + * Set the size of the native stack that should not be exceed. To disable + * stack size checking pass 0. + * + * SpiderMonkey allows for a distinction between system code (such as GCs, which + * may incidentally be triggered by script but are not strictly performed on + * behalf of such script), trusted script (as determined by JS_SetTrustedPrincipals), + * and untrusted script. Each kind of code may have a different stack quota, + * allowing embedders to keep higher-priority machinery running in the face of + * scripted stack exhaustion by something else. + * + * The stack quotas for each kind of code should be monotonically descending, + * and may be specified with this function. If 0 is passed for a given kind + * of code, it defaults to the value of the next-highest-priority kind. + */ +extern JS_PUBLIC_API(void) +JS_SetNativeStackQuota(JSRuntime *cx, size_t systemCodeStackSize, + size_t trustedScriptStackSize = 0, + size_t untrustedScriptStackSize = 0); + +/************************************************************************/ + +extern JS_PUBLIC_API(int) +JS_IdArrayLength(JSContext *cx, JSIdArray *ida); + +extern JS_PUBLIC_API(jsid) +JS_IdArrayGet(JSContext *cx, JSIdArray *ida, unsigned index); + +extern JS_PUBLIC_API(void) +JS_DestroyIdArray(JSContext *cx, JSIdArray *ida); + +namespace JS { + +class AutoIdArray : private AutoGCRooter +{ + public: + AutoIdArray(JSContext *cx, JSIdArray *ida + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : AutoGCRooter(cx, IDARRAY), context(cx), idArray(ida) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + ~AutoIdArray() { + if (idArray) + JS_DestroyIdArray(context, idArray); + } + bool operator!() const { + return !idArray; + } + jsid operator[](size_t i) const { + JS_ASSERT(idArray); + return JS_IdArrayGet(context, idArray, unsigned(i)); + } + size_t length() const { + return JS_IdArrayLength(context, idArray); + } + + friend void AutoGCRooter::trace(JSTracer *trc); + + JSIdArray *steal() { + JSIdArray *copy = idArray; + idArray = nullptr; + return copy; + } + + protected: + inline void trace(JSTracer *trc); + + private: + JSContext *context; + JSIdArray *idArray; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + /* No copy or assignment semantics. */ + AutoIdArray(AutoIdArray &ida) MOZ_DELETE; + void operator=(AutoIdArray &ida) MOZ_DELETE; +}; + +} /* namespace JS */ + +extern JS_PUBLIC_API(bool) +JS_ValueToId(JSContext *cx, JS::HandleValue v, JS::MutableHandleId idp); + +extern JS_PUBLIC_API(bool) +JS_StringToId(JSContext *cx, JS::HandleString s, JS::MutableHandleId idp); + +extern JS_PUBLIC_API(bool) +JS_IdToValue(JSContext *cx, jsid id, JS::MutableHandle vp); + +/* + * Invoke the [[DefaultValue]] hook (see ES5 8.6.2) with the provided hint on + * the specified object, computing a primitive default value for the object. + * The hint must be JSTYPE_STRING, JSTYPE_NUMBER, or JSTYPE_VOID (no hint). On + * success the resulting value is stored in *vp. + */ +extern JS_PUBLIC_API(bool) +JS_DefaultValue(JSContext *cx, JS::Handle obj, JSType hint, + JS::MutableHandle vp); + +extern JS_PUBLIC_API(bool) +JS_PropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_StrictPropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_DeletePropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *succeeded); + +extern JS_PUBLIC_API(bool) +JS_EnumerateStub(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(bool) +JS_ResolveStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id); + +extern JS_PUBLIC_API(bool) +JS_ConvertStub(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); + +struct JSConstDoubleSpec { + double dval; + const char *name; + uint8_t flags; + uint8_t spare[3]; +}; + +struct JSJitInfo; + +/* + * Wrappers to replace {Strict,}PropertyOp for JSPropertySpecs. This will allow + * us to pass one JSJitInfo per function with the property spec, without + * additional field overhead. + */ +typedef struct JSStrictPropertyOpWrapper { + JSStrictPropertyOp op; + const JSJitInfo *info; +} JSStrictPropertyOpWrapper; + +typedef struct JSPropertyOpWrapper { + JSPropertyOp op; + const JSJitInfo *info; +} JSPropertyOpWrapper; + +/* + * Wrapper to do as above, but for JSNatives for JSFunctionSpecs. + */ +typedef struct JSNativeWrapper { + JSNative op; + const JSJitInfo *info; +} JSNativeWrapper; + +/* + * Macro static initializers which make it easy to pass no JSJitInfo as part of a + * JSPropertySpec or JSFunctionSpec. + */ +#define JSOP_WRAPPER(op) { {op, nullptr} } +#define JSOP_NULLWRAPPER JSOP_WRAPPER(nullptr) + +/* + * To define an array element rather than a named property member, cast the + * element's index to (const char *) and initialize name with it, and set the + * JSPROP_INDEX bit in flags. + */ +struct JSPropertySpec { + struct SelfHostedWrapper { + void *unused; + const char *funname; + }; + + const char *name; + uint8_t flags; + union { + JSPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } getter; + union { + JSStrictPropertyOpWrapper propertyOp; + SelfHostedWrapper selfHosted; + } setter; + +private: + void StaticAsserts() { + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSPropertyOpWrapper)); + JS_STATIC_ASSERT(sizeof(SelfHostedWrapper) == sizeof(JSStrictPropertyOpWrapper)); + JS_STATIC_ASSERT(offsetof(SelfHostedWrapper, funname) == + offsetof(JSPropertyOpWrapper, info)); + } +}; + +namespace JS { +namespace detail { + +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_NATIVE_TO only. */ +inline int CheckIsNative(JSNative native); + +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_STRING_TO only. */ +template +inline int +CheckIsCharacterLiteral(const char (&arr)[N]); + +} // namespace detail +} // namespace JS + +#define JS_CAST_NATIVE_TO(v, To) \ + (static_cast(sizeof(JS::detail::CheckIsNative(v))), \ + reinterpret_cast(v)) + +#define JS_CAST_STRING_TO(s, To) \ + (static_cast(sizeof(JS::detail::CheckIsCharacterLiteral(s))), \ + reinterpret_cast(s)) + +#define JS_CHECK_ACCESSOR_FLAGS(flags) \ + (static_cast::Type>(0), \ + (flags)) + +/* + * JSPropertySpec uses JSAPI JSPropertyOp and JSStrictPropertyOp in function + * signatures. These macros encapsulate the definition of JSNative-backed + * JSPropertySpecs, performing type-safe casts on the getter/setter functions + * and adding the necessary property flags to trigger interpretation as + * JSNatives. + */ +#define JS_PSG(name, getter, flags) \ + {name, \ + uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ + JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ + JSOP_NULLWRAPPER} +#define JS_PSGS(name, getter, setter, flags) \ + {name, \ + uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS), \ + JSOP_WRAPPER(JS_CAST_NATIVE_TO(getter, JSPropertyOp)), \ + JSOP_WRAPPER(JS_CAST_NATIVE_TO(setter, JSStrictPropertyOp))} +#define JS_SELF_HOSTED_GET(name, getterName, flags) \ + {name, \ + uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER), \ + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + JSOP_NULLWRAPPER } +#define JS_SELF_HOSTED_GETSET(name, getterName, setterName, flags) \ + {name, \ + uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER | JSPROP_SETTER), \ + { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \ + { nullptr, JS_CAST_STRING_TO(setterName, const JSJitInfo *) } } +#define JS_PS_END { nullptr, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER } + +/* + * To define a native function, set call to a JSNativeWrapper. To define a + * self-hosted function, set selfHostedName to the name of a function + * compiled during JSRuntime::initSelfHosting. + */ +struct JSFunctionSpec { + const char *name; + JSNativeWrapper call; + uint16_t nargs; + uint16_t flags; + const char *selfHostedName; +}; + +/* + * Terminating sentinel initializer to put at the end of a JSFunctionSpec array + * that's passed to JS_DefineFunctions or JS_InitClass. + */ +#define JS_FS_END JS_FS(nullptr,nullptr,0,0) + +/* + * Initializer macros for a JSFunctionSpec array element. JS_FN (whose name pays + * homage to the old JSNative/JSFastNative split) simply adds the flag + * JSFUN_STUB_GSOPS. JS_FNINFO allows the simple adding of + * JSJitInfos. JS_SELF_HOSTED_FN declares a self-hosted function. Finally + * JS_FNSPEC has slots for all the fields. + */ +#define JS_FS(name,call,nargs,flags) \ + JS_FNSPEC(name, call, nullptr, nargs, flags, nullptr) +#define JS_FN(name,call,nargs,flags) \ + JS_FNSPEC(name, call, nullptr, nargs, (flags) | JSFUN_STUB_GSOPS, nullptr) +#define JS_FNINFO(name,call,info,nargs,flags) \ + JS_FNSPEC(name, call, info, nargs, flags, nullptr) +#define JS_SELF_HOSTED_FN(name,selfHostedName,nargs,flags) \ + JS_FNSPEC(name, nullptr, nullptr, nargs, flags, selfHostedName) +#define JS_FNSPEC(name,call,info,nargs,flags,selfHostedName) \ + {name, {call, info}, nargs, flags, selfHostedName} + +extern JS_PUBLIC_API(JSObject *) +JS_InitClass(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent_proto, + const JSClass *clasp, JSNative constructor, unsigned nargs, + const JSPropertySpec *ps, const JSFunctionSpec *fs, + const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs); + +/* + * Set up ctor.prototype = proto and proto.constructor = ctor with the + * right property flags. + */ +extern JS_PUBLIC_API(bool) +JS_LinkConstructorAndPrototype(JSContext *cx, JS::Handle ctor, + JS::Handle proto); + +extern JS_PUBLIC_API(const JSClass *) +JS_GetClass(JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_InstanceOf(JSContext *cx, JS::Handle obj, const JSClass *clasp, JS::CallArgs *args); + +extern JS_PUBLIC_API(bool) +JS_HasInstance(JSContext *cx, JS::Handle obj, JS::Handle v, bool *bp); + +extern JS_PUBLIC_API(void *) +JS_GetPrivate(JSObject *obj); + +extern JS_PUBLIC_API(void) +JS_SetPrivate(JSObject *obj, void *data); + +extern JS_PUBLIC_API(void *) +JS_GetInstancePrivate(JSContext *cx, JS::Handle obj, const JSClass *clasp, + JS::CallArgs *args); + +extern JS_PUBLIC_API(bool) +JS_GetPrototype(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject protop); + +extern JS_PUBLIC_API(bool) +JS_SetPrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); + +extern JS_PUBLIC_API(JSObject *) +JS_GetParent(JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_SetParent(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent); + +extern JS_PUBLIC_API(JSObject *) +JS_GetConstructor(JSContext *cx, JS::Handle proto); + +namespace JS { + +enum ZoneSpecifier { + FreshZone = 0, + SystemZone = 1 +}; + +class JS_PUBLIC_API(CompartmentOptions) +{ + public: + class Override { + public: + Override() : mode_(Default) {} + + bool get(bool defaultValue) const { + if (mode_ == Default) + return defaultValue; + return mode_ == ForceTrue; + }; + + void set(bool overrideValue) { + mode_ = overrideValue ? ForceTrue : ForceFalse; + }; + + void reset() { + mode_ = Default; + } + + private: + enum Mode { + Default, + ForceTrue, + ForceFalse + }; + + Mode mode_; + }; + + explicit CompartmentOptions() + : version_(JSVERSION_UNKNOWN) + , invisibleToDebugger_(false) + , mergeable_(false) + , discardSource_(false) + , cloneSingletons_(false) + , traceGlobal_(nullptr) + , singletonsAsTemplates_(true) + , addonId_(nullptr) + { + zone_.spec = JS::FreshZone; + } + + JSVersion version() const { return version_; } + CompartmentOptions &setVersion(JSVersion aVersion) { + MOZ_ASSERT(aVersion != JSVERSION_UNKNOWN); + version_ = aVersion; + return *this; + } + + // Certain scopes (i.e. XBL compilation scopes) are implementation details + // of the embedding, and references to them should never leak out to script. + // This flag causes the this compartment to skip firing onNewGlobalObject + // and makes addDebuggee a no-op for this global. + bool invisibleToDebugger() const { return invisibleToDebugger_; } + CompartmentOptions &setInvisibleToDebugger(bool flag) { + invisibleToDebugger_ = flag; + return *this; + } + + // Compartments used for off-thread compilation have their contents merged + // into a target compartment when the compilation is finished. This is only + // allowed if this flag is set. The invisibleToDebugger flag must also be + // set for such compartments. + bool mergeable() const { return mergeable_; } + CompartmentOptions &setMergeable(bool flag) { + mergeable_ = flag; + return *this; + } + + // For certain globals, we know enough about the code that will run in them + // that we can discard script source entirely. + bool discardSource() const { return discardSource_; } + CompartmentOptions &setDiscardSource(bool flag) { + discardSource_ = flag; + return *this; + } + + + bool cloneSingletons() const { return cloneSingletons_; } + CompartmentOptions &setCloneSingletons(bool flag) { + cloneSingletons_ = flag; + return *this; + } + + void *zonePointer() const { + JS_ASSERT(uintptr_t(zone_.pointer) > uintptr_t(JS::SystemZone)); + return zone_.pointer; + } + ZoneSpecifier zoneSpecifier() const { return zone_.spec; } + CompartmentOptions &setZone(ZoneSpecifier spec); + CompartmentOptions &setSameZoneAs(JSObject *obj); + + void setSingletonsAsValues() { + singletonsAsTemplates_ = false; + } + bool getSingletonsAsTemplates() const { + return singletonsAsTemplates_; + }; + + // A null add-on ID means that the compartment is not associated with an + // add-on. + JSAddonId *addonIdOrNull() const { return addonId_; } + CompartmentOptions &setAddonId(JSAddonId *id) { + addonId_ = id; + return *this; + } + + CompartmentOptions &setTrace(JSTraceOp op) { + traceGlobal_ = op; + return *this; + } + JSTraceOp getTrace() const { + return traceGlobal_; + } + + private: + JSVersion version_; + bool invisibleToDebugger_; + bool mergeable_; + bool discardSource_; + bool cloneSingletons_; + union { + ZoneSpecifier spec; + void *pointer; // js::Zone* is not exposed in the API. + } zone_; + JSTraceOp traceGlobal_; + + // To XDR singletons, we need to ensure that all singletons are all used as + // templates, by making JSOP_OBJECT return a clone of the JSScript + // singleton, instead of returning the value which is baked in the JSScript. + bool singletonsAsTemplates_; + + JSAddonId *addonId_; +}; + +JS_PUBLIC_API(CompartmentOptions &) +CompartmentOptionsRef(JSCompartment *compartment); + +JS_PUBLIC_API(CompartmentOptions &) +CompartmentOptionsRef(JSObject *obj); + +JS_PUBLIC_API(CompartmentOptions &) +CompartmentOptionsRef(JSContext *cx); + +// During global creation, we fire notifications to callbacks registered +// via the Debugger API. These callbacks are arbitrary script, and can touch +// the global in arbitrary ways. When that happens, the global should not be +// in a half-baked state. But this creates a problem for consumers that need +// to set slots on the global to put it in a consistent state. +// +// This API provides a way for consumers to set slots atomically (immediately +// after the global is created), before any debugger hooks are fired. It's +// unfortunately on the clunky side, but that's the way the cookie crumbles. +// +// If callers have no additional state on the global to set up, they may pass +// |FireOnNewGlobalHook| to JS_NewGlobalObject, which causes that function to +// fire the hook as its final act before returning. Otherwise, callers should +// pass |DontFireOnNewGlobalHook|, which means that they are responsible for +// invoking JS_FireOnNewGlobalObject upon successfully creating the global. If +// an error occurs and the operation aborts, callers should skip firing the +// hook. But otherwise, callers must take care to fire the hook exactly once +// before compiling any script in the global's scope (we have assertions in +// place to enforce this). This lets us be sure that debugger clients never miss +// breakpoints. +enum OnNewGlobalHookOption { + FireOnNewGlobalHook, + DontFireOnNewGlobalHook +}; + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSObject *) +JS_NewGlobalObject(JSContext *cx, const JSClass *clasp, JSPrincipals *principals, + JS::OnNewGlobalHookOption hookOption, + const JS::CompartmentOptions &options = JS::CompartmentOptions()); +/* + * Spidermonkey does not have a good way of keeping track of what compartments should be marked on + * their own. We can mark the roots unconditionally, but marking GC things only relevant in live + * compartments is hard. To mitigate this, we create a static trace hook, installed on each global + * object, from which we can be sure the compartment is relevant, and mark it. + * + * It is still possible to specify custom trace hooks for global object classes. They can be + * provided via the CompartmentOptions passed to JS_NewGlobalObject. + */ +extern JS_PUBLIC_API(void) +JS_GlobalObjectTraceHook(JSTracer *trc, JSObject *global); + +extern JS_PUBLIC_API(void) +JS_FireOnNewGlobalObject(JSContext *cx, JS::HandleObject global); + +extern JS_PUBLIC_API(JSObject *) +JS_NewObject(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); + +/* Queries the [[Extensible]] property of the object. */ +extern JS_PUBLIC_API(bool) +JS_IsExtensible(JSContext *cx, JS::HandleObject obj, bool *extensible); + +extern JS_PUBLIC_API(bool) +JS_IsNative(JSObject *obj); + +extern JS_PUBLIC_API(JSRuntime *) +JS_GetObjectRuntime(JSObject *obj); + +/* + * Unlike JS_NewObject, JS_NewObjectWithGivenProto does not compute a default + * proto if proto's actual parameter value is null. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JS::Handle proto, + JS::Handle parent); + +/* + * Freeze obj, and all objects it refers to, recursively. This will not recurse + * through non-extensible objects, on the assumption that those are already + * deep-frozen. + */ +extern JS_PUBLIC_API(bool) +JS_DeepFreezeObject(JSContext *cx, JS::Handle obj); + +/* + * Freezes an object; see ES5's Object.freeze(obj) method. + */ +extern JS_PUBLIC_API(bool) +JS_FreezeObject(JSContext *cx, JS::Handle obj); + +extern JS_PUBLIC_API(bool) +JS_PreventExtensions(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(JSObject *) +JS_New(JSContext *cx, JS::HandleObject ctor, const JS::HandleValueArray& args); + +extern JS_PUBLIC_API(JSObject *) +JS_DefineObject(JSContext *cx, JS::HandleObject obj, const char *name, + const JSClass *clasp = nullptr, JS::HandleObject proto = JS::NullPtr(), + unsigned attrs = 0); + +extern JS_PUBLIC_API(bool) +JS_DefineConstDoubles(JSContext *cx, JS::HandleObject obj, const JSConstDoubleSpec *cds); + +extern JS_PUBLIC_API(bool) +JS_DefineProperties(JSContext *cx, JS::HandleObject obj, const JSPropertySpec *ps); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnProperty(JSContext *cx, JS::HandleObject obj, const char *name, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasProperty(JSContext *cx, JS::HandleObject obj, const char *name, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_LookupPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue vp); + +struct JSPropertyDescriptor { + JSObject *obj; + unsigned attrs; + JSPropertyOp getter; + JSStrictPropertyOp setter; + JS::Value value; + + JSPropertyDescriptor() + : obj(nullptr), attrs(0), getter(nullptr), setter(nullptr), value(JSVAL_VOID) + {} + + void trace(JSTracer *trc); + + static js::ThingRootKind rootKind() { return js::THING_ROOT_PROPERTY_DESCRIPTOR; } +}; + +namespace JS { + +template +class PropertyDescriptorOperations +{ + const JSPropertyDescriptor * desc() const { return static_cast(this)->extract(); } + + public: + bool isEnumerable() const { return desc()->attrs & JSPROP_ENUMERATE; } + bool isReadonly() const { return desc()->attrs & JSPROP_READONLY; } + bool isPermanent() const { return desc()->attrs & JSPROP_PERMANENT; } + bool hasNativeAccessors() const { return desc()->attrs & JSPROP_NATIVE_ACCESSORS; } + bool hasGetterObject() const { return desc()->attrs & JSPROP_GETTER; } + bool hasSetterObject() const { return desc()->attrs & JSPROP_SETTER; } + bool hasGetterOrSetterObject() const { return desc()->attrs & (JSPROP_GETTER | JSPROP_SETTER); } + bool hasGetterOrSetter() const { return desc()->getter || desc()->setter; } + bool isShared() const { return desc()->attrs & JSPROP_SHARED; } + bool isIndex() const { return desc()->attrs & JSPROP_INDEX; } + bool hasAttributes(unsigned attrs) const { return desc()->attrs & attrs; } + + JS::HandleObject object() const { + return JS::HandleObject::fromMarkedLocation(&desc()->obj); + } + unsigned attributes() const { return desc()->attrs; } + JSPropertyOp getter() const { return desc()->getter; } + JSStrictPropertyOp setter() const { return desc()->setter; } + JS::HandleObject getterObject() const { + MOZ_ASSERT(hasGetterObject()); + return JS::HandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->getter)); + } + JS::HandleObject setterObject() const { + MOZ_ASSERT(hasSetterObject()); + return JS::HandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->setter)); + } + JS::HandleValue value() const { + return JS::HandleValue::fromMarkedLocation(&desc()->value); + } +}; + +template +class MutablePropertyDescriptorOperations : public PropertyDescriptorOperations +{ + JSPropertyDescriptor * desc() { return static_cast(this)->extractMutable(); } + + public: + + void clear() { + object().set(nullptr); + setAttributes(0); + setGetter(nullptr); + setSetter(nullptr); + value().setUndefined(); + } + + void assign(JSPropertyDescriptor &other) { + object().set(other.obj); + setAttributes(other.attrs); + setGetter(other.getter); + setSetter(other.setter); + value().set(other.value); + } + + JS::MutableHandleObject object() { + return JS::MutableHandleObject::fromMarkedLocation(&desc()->obj); + } + unsigned &attributesRef() { return desc()->attrs; } + JSPropertyOp &getter() { return desc()->getter; } + JSStrictPropertyOp &setter() { return desc()->setter; } + JS::MutableHandleValue value() { + return JS::MutableHandleValue::fromMarkedLocation(&desc()->value); + } + + void setEnumerable() { desc()->attrs |= JSPROP_ENUMERATE; } + void setAttributes(unsigned attrs) { desc()->attrs = attrs; } + + void setGetter(JSPropertyOp op) { desc()->getter = op; } + void setSetter(JSStrictPropertyOp op) { desc()->setter = op; } + void setGetterObject(JSObject *obj) { desc()->getter = reinterpret_cast(obj); } + void setSetterObject(JSObject *obj) { desc()->setter = reinterpret_cast(obj); } + + JS::MutableHandleObject getterObject() { + MOZ_ASSERT(this->hasGetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->getter)); + } + JS::MutableHandleObject setterObject() { + MOZ_ASSERT(this->hasSetterObject()); + return JS::MutableHandleObject::fromMarkedLocation( + reinterpret_cast(&desc()->setter)); + } +}; + +} /* namespace JS */ + +namespace js { + +template <> +struct GCMethods { + static JSPropertyDescriptor initial() { return JSPropertyDescriptor(); } + static bool poisoned(const JSPropertyDescriptor &desc) { + return (desc.obj && JS::IsPoisonedPtr(desc.obj)) || + (desc.attrs & JSPROP_GETTER && desc.getter && JS::IsPoisonedPtr(desc.getter)) || + (desc.attrs & JSPROP_SETTER && desc.setter && JS::IsPoisonedPtr(desc.setter)) || + (desc.value.isGCThing() && JS::IsPoisonedPtr(desc.value.toGCThing())); + } +}; + +template <> +class RootedBase + : public JS::MutablePropertyDescriptorOperations > +{ + friend class JS::PropertyDescriptorOperations >; + friend class JS::MutablePropertyDescriptorOperations >; + const JSPropertyDescriptor *extract() const { + return static_cast*>(this)->address(); + } + JSPropertyDescriptor *extractMutable() { + return static_cast*>(this)->address(); + } +}; + +template <> +class HandleBase + : public JS::PropertyDescriptorOperations > +{ + friend class JS::PropertyDescriptorOperations >; + const JSPropertyDescriptor *extract() const { + return static_cast*>(this)->address(); + } +}; + +template <> +class MutableHandleBase + : public JS::MutablePropertyDescriptorOperations > +{ + friend class JS::PropertyDescriptorOperations >; + friend class JS::MutablePropertyDescriptorOperations >; + const JSPropertyDescriptor *extract() const { + return static_cast*>(this)->address(); + } + JSPropertyDescriptor *extractMutable() { + return static_cast*>(this)->address(); + } +}; + +} /* namespace js */ + +namespace JS { + +extern JS_PUBLIC_API(bool) +ParsePropertyDescriptorObject(JSContext *cx, + JS::HandleObject obj, + JS::HandleValue descriptor, + JS::MutableHandle desc); + +} // namespace JS + +extern JS_PUBLIC_API(bool) +JS_GetOwnPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandle desc); + +extern JS_PUBLIC_API(bool) +JS_GetOwnPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, + JS::MutableHandle desc); + +/* + * Like JS_GetOwnPropertyDescriptorById but will return a property on + * an object on the prototype chain (returned in desc->obj). If desc->obj is null, + * then this property was not found on the prototype chain. + */ +extern JS_PUBLIC_API(bool) +JS_GetPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandle desc); + +extern JS_PUBLIC_API(bool) +JS_GetPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, + JS::MutableHandle desc); + +extern JS_PUBLIC_API(bool) +JS_GetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetPropertyTo(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject onBehalfOf, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_SetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_DeleteProperty(JSContext *cx, JS::HandleObject obj, const char *name); + +extern JS_PUBLIC_API(bool) +JS_DeleteProperty2(JSContext *cx, JS::HandleObject obj, const char *name, bool *succeeded); + +extern JS_PUBLIC_API(bool) +JS_DeletePropertyById(JSContext *cx, JS::HandleObject obj, jsid id); + +extern JS_PUBLIC_API(bool) +JS_DeletePropertyById2(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleValue value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleObject value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + JS::HandleString value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + int32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + uint32_t value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + double value, unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, + size_t namelen, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasUCProperty(JSContext *cx, JS::HandleObject obj, + const jschar *name, size_t namelen, + bool *vp); + +extern JS_PUBLIC_API(bool) +JS_LookupUCProperty(JSContext *cx, JS::HandleObject obj, + const jschar *name, size_t namelen, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetUCProperty(JSContext *cx, JS::HandleObject obj, + const jschar *name, size_t namelen, + JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetUCProperty(JSContext *cx, JS::HandleObject obj, + const jschar *name, size_t namelen, + JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_DeleteUCProperty2(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen, + bool *succeeded); + +extern JS_PUBLIC_API(JSObject *) +JS_NewArrayObject(JSContext *cx, const JS::HandleValueArray& contents); + +extern JS_PUBLIC_API(JSObject *) +JS_NewArrayObject(JSContext *cx, size_t length); + +extern JS_PUBLIC_API(bool) +JS_IsArrayObject(JSContext *cx, JS::HandleValue value); + +extern JS_PUBLIC_API(bool) +JS_IsArrayObject(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(bool) +JS_GetArrayLength(JSContext *cx, JS::Handle obj, uint32_t *lengthp); + +extern JS_PUBLIC_API(bool) +JS_SetArrayLength(JSContext *cx, JS::Handle obj, uint32_t length); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +extern JS_PUBLIC_API(bool) +JS_AlreadyHasOwnElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_HasElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); + +extern JS_PUBLIC_API(bool) +JS_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_GetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_ForwardGetElementTo(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::HandleObject onBehalfOf, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t v); + +extern JS_PUBLIC_API(bool) +JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double v); + +extern JS_PUBLIC_API(bool) +JS_DeleteElement(JSContext *cx, JS::HandleObject obj, uint32_t index); + +extern JS_PUBLIC_API(bool) +JS_DeleteElement2(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded); + +/* + * Remove all configurable properties from the given (non-global) object and + * assign undefined to all writable data properties. + */ +JS_PUBLIC_API(void) +JS_ClearNonGlobalObject(JSContext *cx, JS::HandleObject obj); + +/* + * Assign 'undefined' to all of the object's non-reserved slots. Note: this is + * done for all slots, regardless of the associated property descriptor. + */ +JS_PUBLIC_API(void) +JS_SetAllNonReservedSlotsToUndefined(JSContext *cx, JSObject *objArg); + +/* + * Create a new array buffer with the given contents. On success, the ownership + * is transferred to the new array buffer. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); + +/* + * Steal the contents of the given array buffer. The array buffer has its + * length set to 0 and its contents array cleared. The caller takes ownership + * of the return value and must free it or transfer ownership via + * JS_NewArrayBufferWithContents when done using it. + */ +extern JS_PUBLIC_API(void *) +JS_StealArrayBufferContents(JSContext *cx, JS::HandleObject obj); + +/* + * Allocate memory that may be eventually passed to + * JS_NewArrayBufferWithContents. |maybecx| is optional; if a non-nullptr cx is + * given, it will be used for memory accounting and OOM reporting. |nbytes| is + * the number of payload bytes required. + */ +extern JS_PUBLIC_API(void *) +JS_AllocateArrayBufferContents(JSContext *maybecx, uint32_t nbytes); + +/* + * Reallocate memory allocated by JS_AllocateArrayBufferContents, growing or + * shrinking it as appropriate. If oldContents is null then this behaves like + * JS_AllocateArrayBufferContents. + */ +extern JS_PUBLIC_API(void *) +JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void *oldContents, uint32_t oldNbytes); + +/* + * Create a new mapped array buffer with the given memory mapped contents. On success, + * the ownership is transferred to the new mapped array buffer. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewMappedArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); + +/* + * Create memory mapped array buffer contents. + * Caller must take care of closing fd after calling this function. + */ +extern JS_PUBLIC_API(void *) +JS_CreateMappedArrayBufferContents(int fd, size_t offset, size_t length); + +/* + * Release the allocated resource of mapped array buffer contents before the + * object is created. + * If a new object has been created by JS_NewMappedArrayBufferWithContents() + * with this content, then JS_NeuterArrayBuffer() should be used instead to + * release the resource used by the object. + */ +extern JS_PUBLIC_API(void) +JS_ReleaseMappedArrayBufferContents(void *contents, size_t length); + +extern JS_PUBLIC_API(JSIdArray *) +JS_Enumerate(JSContext *cx, JS::HandleObject obj); + +/* + * Create an object to iterate over enumerable properties of obj, in arbitrary + * property definition order. NB: This differs from longstanding for..in loop + * order, which uses order of property definition in obj. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewPropertyIterator(JSContext *cx, JS::Handle obj); + +/* + * Return true on success with *idp containing the id of the next enumerable + * property to visit using iterobj, or JSID_IS_VOID if there is no such property + * left to visit. Return false on error. + */ +extern JS_PUBLIC_API(bool) +JS_NextProperty(JSContext *cx, JS::Handle iterobj, jsid *idp); + +extern JS_PUBLIC_API(jsval) +JS_GetReservedSlot(JSObject *obj, uint32_t index); + +extern JS_PUBLIC_API(void) +JS_SetReservedSlot(JSObject *obj, uint32_t index, jsval v); + +/************************************************************************/ + +/* + * Functions and scripts. + */ +extern JS_PUBLIC_API(JSFunction *) +JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, + JS::Handle parent, const char *name); + +/* + * Create the function with the name given by the id. JSID_IS_STRING(id) must + * be true. + */ +extern JS_PUBLIC_API(JSFunction *) +JS_NewFunctionById(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, + JS::Handle parent, JS::Handle id); + +namespace JS { + +extern JS_PUBLIC_API(JSFunction *) +GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, JS::Handle id, + unsigned nargs); + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSObject *) +JS_GetFunctionObject(JSFunction *fun); + +/* + * Return the function's identifier as a JSString, or null if fun is unnamed. + * The returned string lives as long as fun, so you don't need to root a saved + * reference to it if fun is well-connected or rooted, and provided you bound + * the use of the saved reference by fun's lifetime. + */ +extern JS_PUBLIC_API(JSString *) +JS_GetFunctionId(JSFunction *fun); + +/* + * Return a function's display name. This is the defined name if one was given + * where the function was defined, or it could be an inferred name by the JS + * engine in the case that the function was defined to be anonymous. This can + * still return nullptr if a useful display name could not be inferred. The + * same restrictions on rooting as those in JS_GetFunctionId apply. + */ +extern JS_PUBLIC_API(JSString *) +JS_GetFunctionDisplayId(JSFunction *fun); + +/* + * Return the arity (length) of fun. + */ +extern JS_PUBLIC_API(uint16_t) +JS_GetFunctionArity(JSFunction *fun); + +/* + * Infallible predicate to test whether obj is a function object (faster than + * comparing obj's class name to "Function", but equivalent unless someone has + * overwritten the "Function" identifier with a different constructor and then + * created instances using that constructor that might be passed in as obj). + */ +extern JS_PUBLIC_API(bool) +JS_ObjectIsFunction(JSContext *cx, JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_ObjectIsCallable(JSContext *cx, JSObject *obj); + +extern JS_PUBLIC_API(bool) +JS_IsNativeFunction(JSObject *funobj, JSNative call); + +/* Return whether the given function is a valid constructor. */ +extern JS_PUBLIC_API(bool) +JS_IsConstructor(JSFunction *fun); + +/* + * Bind the given callable to use the given object as "this". + * + * If |callable| is not callable, will throw and return nullptr. + */ +extern JS_PUBLIC_API(JSObject*) +JS_BindCallable(JSContext *cx, JS::Handle callable, JS::Handle newThis); + +extern JS_PUBLIC_API(bool) +JS_DefineFunctions(JSContext *cx, JS::Handle obj, const JSFunctionSpec *fs); + +extern JS_PUBLIC_API(JSFunction *) +JS_DefineFunction(JSContext *cx, JS::Handle obj, const char *name, JSNative call, + unsigned nargs, unsigned attrs); + +extern JS_PUBLIC_API(JSFunction *) +JS_DefineUCFunction(JSContext *cx, JS::Handle obj, + const jschar *name, size_t namelen, JSNative call, + unsigned nargs, unsigned attrs); + +extern JS_PUBLIC_API(JSFunction *) +JS_DefineFunctionById(JSContext *cx, JS::Handle obj, JS::Handle id, JSNative call, + unsigned nargs, unsigned attrs); + +/* + * Clone a top-level function into a new scope. This function will dynamically + * fail if funobj was lexically nested inside some other function. + */ +extern JS_PUBLIC_API(JSObject *) +JS_CloneFunctionObject(JSContext *cx, JS::Handle funobj, JS::Handle parent); + +/* + * Given a buffer, return false if the buffer might become a valid + * javascript statement with the addition of more lines. Otherwise return + * true. The intent is to support interactive compilation - accumulate + * lines in a buffer until JS_BufferIsCompilableUnit is true, then pass it to + * the compiler. + */ +extern JS_PUBLIC_API(bool) +JS_BufferIsCompilableUnit(JSContext *cx, JS::Handle obj, const char *utf8, + size_t length); + +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +JS_CompileScript(JSContext *cx, JS::HandleObject obj, + const char *ascii, size_t length, + const JS::CompileOptions &options, + JS::MutableHandleScript script); + +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +JS_CompileUCScript(JSContext *cx, JS::HandleObject obj, + const jschar *chars, size_t length, + const JS::CompileOptions &options, + JS::MutableHandleScript script); + +extern JS_PUBLIC_API(JSObject *) +JS_GetGlobalFromScript(JSScript *script); + +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +JS_CompileFunction(JSContext *cx, JS::HandleObject obj, const char *name, + unsigned nargs, const char *const *argnames, + const char *bytes, size_t length, + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); + +/* + * |fun| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +JS_CompileUCFunction(JSContext *cx, JS::HandleObject obj, const char *name, + unsigned nargs, const char *const *argnames, + const jschar *chars, size_t length, + const JS::CompileOptions &options, + JS::MutableHandleFunction fun); + +namespace JS { + +/* Options for JavaScript compilation. */ + +/* + * In the most common use case, a CompileOptions instance is allocated on the + * stack, and holds non-owning references to non-POD option values: strings; + * principals; objects; and so on. The code declaring the instance guarantees + * that such option values will outlive the CompileOptions itself: objects are + * otherwise rooted; principals have had their reference counts bumped; strings + * will not be freed until the CompileOptions goes out of scope. In this + * situation, CompileOptions only refers to things others own, so it can be + * lightweight. + * + * In some cases, however, we need to hold compilation options with a + * non-stack-like lifetime. For example, JS::CompileOffThread needs to save + * compilation options where a worker thread can find them, and then return + * immediately. The worker thread will come along at some later point, and use + * the options. + * + * The compiler itself just needs to be able to access a collection of options; + * it doesn't care who owns them, or what's keeping them alive. It does its own + * addrefs/copies/tracing/etc. + * + * So, we have a class hierarchy that reflects these three use cases: + * + * - ReadOnlyCompileOptions is the common base class. It can be used by code + * that simply needs to access options set elsewhere, like the compiler. + * + * - The usual CompileOptions class must be stack-allocated, and holds + * non-owning references to the filename, element, and so on. It's derived + * from ReadOnlyCompileOptions, so the compiler can use it. + * + * - OwningCompileOptions roots / copies / reference counts of all its values, + * and unroots / frees / releases them when it is destructed. It too is + * derived from ReadOnlyCompileOptions, so the compiler accepts it. + */ + +/* + * The common base class for the CompileOptions hierarchy. + * + * Use this in code that only needs to access compilation options created + * elsewhere, like the compiler. Don't instantiate this class (the constructor + * is protected anyway); instead, create instances only of the derived classes: + * CompileOptions and OwningCompileOptions. + */ +class JS_FRIEND_API(ReadOnlyCompileOptions) +{ + friend class CompileOptions; + + protected: + JSPrincipals *originPrincipals_; + const char *filename_; + const char *introducerFilename_; + const jschar *sourceMapURL_; + + // This constructor leaves 'version' set to JSVERSION_UNKNOWN. The structure + // is unusable until that's set to something more specific; the derived + // classes' constructors take care of that, in ways appropriate to their + // purpose. + ReadOnlyCompileOptions() + : originPrincipals_(nullptr), + filename_(nullptr), + introducerFilename_(nullptr), + sourceMapURL_(nullptr), + version(JSVERSION_UNKNOWN), + versionSet(false), + utf8(false), + lineno(1), + column(0), + compileAndGo(false), + forEval(false), + defineOnScope(true), + noScriptRval(false), + selfHostingMode(false), + canLazilyParse(true), + strictOption(false), + extraWarningsOption(false), + werrorOption(false), + asmJSOption(false), + forceAsync(false), + installedFile(false), + sourceIsLazy(false), + introductionType(nullptr), + introductionLineno(0), + introductionOffset(0), + hasIntroductionInfo(false) + { } + + // Set all POD options (those not requiring reference counts, copies, + // rooting, or other hand-holding) to their values in |rhs|. + void copyPODOptions(const ReadOnlyCompileOptions &rhs); + + public: + // Read-only accessors for non-POD options. The proper way to set these + // depends on the derived type. + JSPrincipals *originPrincipals(js::ExclusiveContext *cx) const; + const char *filename() const { return filename_; } + const char *introducerFilename() const { return introducerFilename_; } + const jschar *sourceMapURL() const { return sourceMapURL_; } + virtual JSObject *element() const = 0; + virtual JSString *elementAttributeName() const = 0; + virtual JSScript *introductionScript() const = 0; + + // POD options. + JSVersion version; + bool versionSet; + bool utf8; + unsigned lineno; + unsigned column; + bool compileAndGo; + bool forEval; + bool defineOnScope; + bool noScriptRval; + bool selfHostingMode; + bool canLazilyParse; + bool strictOption; + bool extraWarningsOption; + bool werrorOption; + bool asmJSOption; + bool forceAsync; + bool installedFile; // 'true' iff pre-compiling js file in packaged app + bool sourceIsLazy; + + // |introductionType| is a statically allocated C string: + // one of "eval", "Function", or "GeneratorFunction". + const char *introductionType; + unsigned introductionLineno; + uint32_t introductionOffset; + bool hasIntroductionInfo; + + private: + static JSObject * const nullObjectPtr; + void operator=(const ReadOnlyCompileOptions &) MOZ_DELETE; +}; + +/* + * Compilation options, with dynamic lifetime. An instance of this type + * makes a copy of / holds / roots all dynamically allocated resources + * (principals; elements; strings) that it refers to. Its destructor frees + * / drops / unroots them. This is heavier than CompileOptions, below, but + * unlike CompileOptions, it can outlive any given stack frame. + * + * Note that this *roots* any JS values it refers to - they're live + * unconditionally. Thus, instances of this type can't be owned, directly + * or indirectly, by a JavaScript object: if any value that this roots ever + * comes to refer to the object that owns this, then the whole cycle, and + * anything else it entrains, will never be freed. + */ +class JS_FRIEND_API(OwningCompileOptions) : public ReadOnlyCompileOptions +{ + JSRuntime *runtime; + PersistentRootedObject elementRoot; + PersistentRootedString elementAttributeNameRoot; + PersistentRootedScript introductionScriptRoot; + + public: + // A minimal constructor, for use with OwningCompileOptions::copy. This + // leaves |this.version| set to JSVERSION_UNKNOWN; the instance + // shouldn't be used until we've set that to something real (as |copy| + // will). + explicit OwningCompileOptions(JSContext *cx); + ~OwningCompileOptions(); + + JSObject *element() const MOZ_OVERRIDE { return elementRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } + + // Set this to a copy of |rhs|. Return false on OOM. + bool copy(JSContext *cx, const ReadOnlyCompileOptions &rhs); + + /* These setters make copies of their string arguments, and are fallible. */ + bool setFile(JSContext *cx, const char *f); + bool setFileAndLine(JSContext *cx, const char *f, unsigned l); + bool setSourceMapURL(JSContext *cx, const jschar *s); + bool setIntroducerFilename(JSContext *cx, const char *s); + + /* These setters are infallible, and can be chained. */ + OwningCompileOptions &setLine(unsigned l) { lineno = l; return *this; } + OwningCompileOptions &setElement(JSObject *e) { + elementRoot = e; + return *this; + } + OwningCompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + OwningCompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; + return *this; + } + OwningCompileOptions &setOriginPrincipals(JSPrincipals *p) { + if (p) JS_HoldPrincipals(p); + if (originPrincipals_) JS_DropPrincipals(runtime, originPrincipals_); + originPrincipals_ = p; + return *this; + } + OwningCompileOptions &setVersion(JSVersion v) { + version = v; + versionSet = true; + return *this; + } + OwningCompileOptions &setUTF8(bool u) { utf8 = u; return *this; } + OwningCompileOptions &setColumn(unsigned c) { column = c; return *this; } + OwningCompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } + OwningCompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + OwningCompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } + OwningCompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } + OwningCompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } + OwningCompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } + OwningCompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + OwningCompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + bool setIntroductionInfo(JSContext *cx, const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + if (!setIntroducerFilename(cx, introducerFn)) + return false; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return true; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; +}; + +/* + * Compilation options stored on the stack. An instance of this type + * simply holds references to dynamically allocated resources (element; + * filename; source map URL) that are owned by something else. If you + * create an instance of this type, it's up to you to guarantee that + * everything you store in it will outlive it. + */ +class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOptions +{ + RootedObject elementRoot; + RootedString elementAttributeNameRoot; + RootedScript introductionScriptRoot; + + public: + explicit CompileOptions(JSContext *cx, JSVersion version = JSVERSION_UNKNOWN); + CompileOptions(js::ContextFriendFields *cx, const ReadOnlyCompileOptions &rhs) + : ReadOnlyCompileOptions(), elementRoot(cx), elementAttributeNameRoot(cx), + introductionScriptRoot(cx) + { + copyPODOptions(rhs); + + originPrincipals_ = rhs.originPrincipals_; + filename_ = rhs.filename(); + sourceMapURL_ = rhs.sourceMapURL(); + elementRoot = rhs.element(); + elementAttributeNameRoot = rhs.elementAttributeName(); + introductionScriptRoot = rhs.introductionScript(); + } + + JSObject *element() const MOZ_OVERRIDE { return elementRoot; } + JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; } + JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; } + + CompileOptions &setFile(const char *f) { filename_ = f; return *this; } + CompileOptions &setLine(unsigned l) { lineno = l; return *this; } + CompileOptions &setFileAndLine(const char *f, unsigned l) { + filename_ = f; lineno = l; return *this; + } + CompileOptions &setSourceMapURL(const jschar *s) { sourceMapURL_ = s; return *this; } + CompileOptions &setElement(JSObject *e) { elementRoot = e; return *this; } + CompileOptions &setElementAttributeName(JSString *p) { + elementAttributeNameRoot = p; + return *this; + } + CompileOptions &setIntroductionScript(JSScript *s) { + introductionScriptRoot = s; + return *this; + } + CompileOptions &setOriginPrincipals(JSPrincipals *p) { + originPrincipals_ = p; + return *this; + } + CompileOptions &setVersion(JSVersion v) { + version = v; + versionSet = true; + return *this; + } + CompileOptions &setUTF8(bool u) { utf8 = u; return *this; } + CompileOptions &setColumn(unsigned c) { column = c; return *this; } + CompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } + CompileOptions &setForEval(bool eval) { forEval = eval; return *this; } + CompileOptions &setDefineOnScope(bool define) { defineOnScope = define; return *this; } + CompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } + CompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } + CompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; } + CompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; } + CompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; } + CompileOptions &setIntroductionInfo(const char *introducerFn, const char *intro, + unsigned line, JSScript *script, uint32_t offset) + { + introducerFilename_ = introducerFn; + introductionType = intro; + introductionLineno = line; + introductionScriptRoot = script; + introductionOffset = offset; + hasIntroductionInfo = true; + return *this; + } + + private: + void operator=(const CompileOptions &rhs) MOZ_DELETE; +}; + +/* + * |script| will always be set. On failure, it will be set to nullptr. + */ +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, FILE *file, + JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *filename, + JS::MutableHandleScript script); + +extern JS_PUBLIC_API(bool) +CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t length); + +/* + * Off thread compilation control flow. + * + * After successfully triggering an off thread compile of a script, the + * callback will eventually be invoked with the specified data and a token + * for the compilation. The callback will be invoked while off the main thread, + * so must ensure that its operations are thread safe. Afterwards, + * FinishOffThreadScript must be invoked on the main thread to get the result + * script or nullptr. If maybecx is not specified, the resources will be freed, + * but no script will be returned. + * + * The characters passed in to CompileOffThread must remain live until the + * callback is invoked, and the resulting script will be rooted until the call + * to FinishOffThreadScript. + */ + +extern JS_PUBLIC_API(bool) +CompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, + OffThreadCompileCallback callback, void *callbackData); + +extern JS_PUBLIC_API(JSScript *) +FinishOffThreadScript(JSContext *maybecx, JSRuntime *rt, void *token); + +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *name, unsigned nargs, const char *const *argnames, + SourceBufferHolder &srcBuf, JS::MutableHandleFunction fun); + +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *name, unsigned nargs, const char *const *argnames, + const char *bytes, size_t length, JS::MutableHandleFunction fun); + +extern JS_PUBLIC_API(bool) +CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *name, unsigned nargs, const char *const *argnames, + const jschar *chars, size_t length, JS::MutableHandleFunction fun); + +} /* namespace JS */ + +extern JS_PUBLIC_API(JSString *) +JS_DecompileScript(JSContext *cx, JS::Handle script, const char *name, unsigned indent); + +/* + * API extension: OR this into indent to avoid pretty-printing the decompiled + * source resulting from JS_DecompileFunction{,Body}. + */ +#define JS_DONT_PRETTY_PRINT ((unsigned)0x8000) + +extern JS_PUBLIC_API(JSString *) +JS_DecompileFunction(JSContext *cx, JS::Handle fun, unsigned indent); + +extern JS_PUBLIC_API(JSString *) +JS_DecompileFunctionBody(JSContext *cx, JS::Handle fun, unsigned indent); + +/* + * NB: JS_ExecuteScript and the JS_Evaluate*Script* quadruplets use the obj + * parameter as the initial scope chain header, the 'this' keyword value, and + * the variables object (ECMA parlance for where 'var' and 'function' bind + * names) of the execution context for script. + * + * Using obj as the variables object is problematic if obj's parent (which is + * the scope chain link; see JS_SetParent and JS_NewObject) is not null: in + * this case, variables created by 'var x = 0', e.g., go in obj, but variables + * created by assignment to an unbound id, 'x = 0', go in the last object on + * the scope chain linked by parent. + * + * ECMA calls that last scoping object the "global object", but note that many + * embeddings have several such objects. ECMA requires that "global code" be + * executed with the variables object equal to this global object. But these + * JS API entry points provide freedom to execute code against a "sub-global", + * i.e., a parented or scoped object, in which case the variables object will + * differ from the last object on the scope chain, resulting in confusing and + * non-ECMA explicit vs. implicit variable creation. + * + * Caveat embedders: unless you already depend on this buggy variables object + * binding behavior, you should call ContextOptionsRef(cx).setVarObjFix(true) + * for each context in the application, if you pass parented objects as the obj + * parameter, or may ever pass such objects in the future. + * + * Why a runtime option? The alternative is to add six or so new API entry + * points with signatures matching the following six, and that doesn't seem + * worth the code bloat cost. Such new entry points would probably have less + * obvious names, too, so would not tend to be used. The JS_SetOption call, + * OTOH, can be more easily hacked into existing code that does not depend on + * the bug; such code can continue to use the familiar JS_EvaluateScript, + * etc., entry points. + */ +extern JS_PUBLIC_API(bool) +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script); + +namespace JS { + +/* + * Like the above, but handles a cross-compartment script. If the script is + * cross-compartment, it is cloned into the current compartment before executing. + */ +extern JS_PUBLIC_API(bool) +CloneAndExecuteScript(JSContext *cx, JS::Handle obj, JS::Handle script); + +} /* namespace JS */ + +extern JS_PUBLIC_API(bool) +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleValue rval, JSVersion version); + +extern JS_PUBLIC_API(bool) +JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JSVersion version); + +extern JS_PUBLIC_API(bool) +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_EvaluateScript(JSContext *cx, JS::HandleObject obj, + const char *bytes, unsigned length, + const char *filename, unsigned lineno); + +extern JS_PUBLIC_API(bool) +JS_EvaluateUCScript(JSContext *cx, JS::Handle obj, + const jschar *chars, unsigned length, + const char *filename, unsigned lineno, + JS::MutableHandle rval); + +namespace JS { + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + SourceBufferHolder &srcBuf); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const jschar *chars, size_t length); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *bytes, size_t length); + +extern JS_PUBLIC_API(bool) +Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, + const char *filename); + +} /* namespace JS */ + +extern JS_PUBLIC_API(bool) +JS_CallFunction(JSContext *cx, JS::HandleObject obj, JS::HandleFunction fun, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_CallFunctionName(JSContext *cx, JS::HandleObject obj, const char *name, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_CallFunctionValue(JSContext *cx, JS::HandleObject obj, JS::HandleValue fval, + const JS::HandleValueArray& args, JS::MutableHandleValue rval); + +namespace JS { + +static inline bool +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleFunction fun, + const JS::HandleValueArray &args, MutableHandleValue rval) +{ + return !!JS_CallFunction(cx, thisObj, fun, args, rval); +} + +static inline bool +Call(JSContext *cx, JS::HandleObject thisObj, const char *name, const JS::HandleValueArray& args, + MutableHandleValue rval) +{ + return !!JS_CallFunctionName(cx, thisObj, name, args, rval); +} + +static inline bool +Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval) +{ + return !!JS_CallFunctionValue(cx, thisObj, fun, args, rval); +} + +extern JS_PUBLIC_API(bool) +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleValue fun, const JS::HandleValueArray& args, + MutableHandleValue rval); + +static inline bool +Call(JSContext *cx, JS::HandleValue thisv, JS::HandleObject funObj, const JS::HandleValueArray& args, + MutableHandleValue rval) +{ + JS_ASSERT(funObj); + JS::RootedValue fun(cx, JS::ObjectValue(*funObj)); + return Call(cx, thisv, fun, args, rval); +} + +extern JS_PUBLIC_API(bool) +Construct(JSContext *cx, JS::HandleValue fun, + const JS::HandleValueArray& args, + MutableHandleValue rval); + +} /* namespace JS */ + +/* + * These functions allow setting an interrupt callback that will be called + * from the JS thread some time after any thread triggered the callback using + * JS_RequestInterruptCallback(rt). + * + * To schedule the GC and for other activities the engine internally triggers + * interrupt callbacks. The embedding should thus not rely on callbacks being + * triggered through the external API only. + * + * Important note: Additional callbacks can occur inside the callback handler + * if it re-enters the JS engine. The embedding must ensure that the callback + * is disconnected before attempting such re-entry. + */ +extern JS_PUBLIC_API(JSInterruptCallback) +JS_SetInterruptCallback(JSRuntime *rt, JSInterruptCallback callback); + +extern JS_PUBLIC_API(JSInterruptCallback) +JS_GetInterruptCallback(JSRuntime *rt); + +extern JS_PUBLIC_API(void) +JS_RequestInterruptCallback(JSRuntime *rt); + +extern JS_PUBLIC_API(bool) +JS_IsRunning(JSContext *cx); + +/* + * Saving and restoring frame chains. + * + * These two functions are used to set aside cx's call stack while that stack + * is inactive. After a call to JS_SaveFrameChain, it looks as if there is no + * code running on cx. Before calling JS_RestoreFrameChain, cx's call stack + * must be balanced and all nested calls to JS_SaveFrameChain must have had + * matching JS_RestoreFrameChain calls. + * + * JS_SaveFrameChain deals with cx not having any code running on it. + */ +extern JS_PUBLIC_API(bool) +JS_SaveFrameChain(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_RestoreFrameChain(JSContext *cx); + +#ifdef MOZ_TRACE_JSCALLS +/* + * The callback is expected to be quick and noninvasive. It should not + * request interrupts, turn on debugging, or produce uncaught JS + * exceptions. The state of the stack and registers in the context + * cannot be relied upon, since this callback may be invoked directly + * from either JIT. The 'entering' field means we are entering a + * function if it is positive, leaving a function if it is zero or + * negative. + */ +extern JS_PUBLIC_API(void) +JS_SetFunctionCallback(JSContext *cx, JSFunctionCallback fcb); + +extern JS_PUBLIC_API(JSFunctionCallback) +JS_GetFunctionCallback(JSContext *cx); +#endif /* MOZ_TRACE_JSCALLS */ + +/************************************************************************/ + +/* + * Strings. + * + * NB: JS_NewUCString takes ownership of bytes on success, avoiding a copy; + * but on error (signified by null return), it leaves chars owned by the + * caller. So the caller must free bytes in the error case, if it has no use + * for them. In contrast, all the JS_New*StringCopy* functions do not take + * ownership of the character memory passed to them -- they copy it. + */ +extern JS_PUBLIC_API(JSString *) +JS_NewStringCopyN(JSContext *cx, const char *s, size_t n); + +extern JS_PUBLIC_API(JSString *) +JS_NewStringCopyZ(JSContext *cx, const char *s); + +extern JS_PUBLIC_API(JSString *) +JS_InternJSString(JSContext *cx, JS::HandleString str); + +extern JS_PUBLIC_API(JSString *) +JS_InternStringN(JSContext *cx, const char *s, size_t length); + +extern JS_PUBLIC_API(JSString *) +JS_InternString(JSContext *cx, const char *s); + +extern JS_PUBLIC_API(JSString *) +JS_NewUCString(JSContext *cx, jschar *chars, size_t length); + +extern JS_PUBLIC_API(JSString *) +JS_NewUCStringCopyN(JSContext *cx, const jschar *s, size_t n); + +extern JS_PUBLIC_API(JSString *) +JS_NewUCStringCopyZ(JSContext *cx, const jschar *s); + +extern JS_PUBLIC_API(JSString *) +JS_InternUCStringN(JSContext *cx, const jschar *s, size_t length); + +extern JS_PUBLIC_API(JSString *) +JS_InternUCString(JSContext *cx, const jschar *s); + +extern JS_PUBLIC_API(bool) +JS_CompareStrings(JSContext *cx, JSString *str1, JSString *str2, int32_t *result); + +extern JS_PUBLIC_API(bool) +JS_StringEqualsAscii(JSContext *cx, JSString *str, const char *asciiBytes, bool *match); + +extern JS_PUBLIC_API(size_t) +JS_PutEscapedString(JSContext *cx, char *buffer, size_t size, JSString *str, char quote); + +extern JS_PUBLIC_API(bool) +JS_FileEscapedString(FILE *fp, JSString *str, char quote); + +/* + * Extracting string characters and length. + * + * While getting the length of a string is infallible, getting the chars can + * fail. As indicated by the lack of a JSContext parameter, there are two + * special cases where getting the chars is infallible: + * + * The first case is interned strings, i.e., strings from JS_InternString or + * JSID_TO_STRING(id), using JS_GetLatin1InternedStringChars or + * JS_GetTwoByteInternedStringChars. + * + * The second case is "flat" strings that have been explicitly prepared in a + * fallible context by JS_FlattenString. To catch errors, a separate opaque + * JSFlatString type is returned by JS_FlattenString and expected by + * JS_GetFlatStringChars. Note, though, that this is purely a syntactic + * distinction: the input and output of JS_FlattenString are the same actual + * GC-thing. If a JSString is known to be flat, JS_ASSERT_STRING_IS_FLAT can be + * used to make a debug-checked cast. Example: + * + * // in a fallible context + * JSFlatString *fstr = JS_FlattenString(cx, str); + * if (!fstr) + * return false; + * JS_ASSERT(fstr == JS_ASSERT_STRING_IS_FLAT(str)); + * + * // in an infallible context, for the same 'str' + * AutoCheckCannotGC nogc; + * const jschar *chars = JS_GetTwoByteFlatStringChars(nogc, fstr) + * JS_ASSERT(chars); + * + * Flat strings and interned strings are always null-terminated, so + * JS_FlattenString can be used to get a null-terminated string. + * + * Additionally, string characters are stored as either Latin1Char (8-bit) + * or jschar (16-bit). Clients can use JS_StringHasLatin1Chars and can then + * call either the Latin1* or TwoByte* functions. Some functions like + * JS_CopyStringChars and JS_GetStringCharAt accept both Latin1 and TwoByte + * strings. + */ + +extern JS_PUBLIC_API(size_t) +JS_GetStringLength(JSString *str); + +extern JS_PUBLIC_API(bool) +JS_StringIsFlat(JSString *str); + +/* Returns true iff the string's characters are stored as Latin1. */ +extern JS_PUBLIC_API(bool) +JS_StringHasLatin1Chars(JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1StringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); + +extern JS_PUBLIC_API(const jschar *) +JS_GetTwoByteStringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, + size_t *length); + +extern JS_PUBLIC_API(bool) +JS_GetStringCharAt(JSContext *cx, JSString *str, size_t index, jschar *res); + +extern JS_PUBLIC_API(jschar) +JS_GetFlatStringCharAt(JSFlatString *str, size_t index); + +extern JS_PUBLIC_API(const jschar *) +JS_GetTwoByteExternalStringChars(JSString *str); + +extern JS_PUBLIC_API(bool) +JS_CopyStringChars(JSContext *cx, mozilla::Range dest, JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1InternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); + +extern JS_PUBLIC_API(const jschar *) +JS_GetTwoByteInternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); + +extern JS_PUBLIC_API(JSFlatString *) +JS_FlattenString(JSContext *cx, JSString *str); + +extern JS_PUBLIC_API(const JS::Latin1Char *) +JS_GetLatin1FlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); + +extern JS_PUBLIC_API(const jschar *) +JS_GetTwoByteFlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); + +static MOZ_ALWAYS_INLINE JSFlatString * +JSID_TO_FLAT_STRING(jsid id) +{ + JS_ASSERT(JSID_IS_STRING(id)); + return (JSFlatString *)(JSID_BITS(id)); +} + +static MOZ_ALWAYS_INLINE JSFlatString * +JS_ASSERT_STRING_IS_FLAT(JSString *str) +{ + JS_ASSERT(JS_StringIsFlat(str)); + return (JSFlatString *)str; +} + +static MOZ_ALWAYS_INLINE JSString * +JS_FORGET_STRING_FLATNESS(JSFlatString *fstr) +{ + return (JSString *)fstr; +} + +/* + * Additional APIs that avoid fallibility when given a flat string. + */ + +extern JS_PUBLIC_API(bool) +JS_FlatStringEqualsAscii(JSFlatString *str, const char *asciiBytes); + +extern JS_PUBLIC_API(size_t) +JS_PutEscapedFlatString(char *buffer, size_t size, JSFlatString *str, char quote); + +/* + * Create a dependent string, i.e., a string that owns no character storage, + * but that refers to a slice of another string's chars. Dependent strings + * are mutable by definition, so the thread safety comments above apply. + */ +extern JS_PUBLIC_API(JSString *) +JS_NewDependentString(JSContext *cx, JS::HandleString str, size_t start, + size_t length); + +/* + * Concatenate two strings, possibly resulting in a rope. + * See above for thread safety comments. + */ +extern JS_PUBLIC_API(JSString *) +JS_ConcatStrings(JSContext *cx, JS::HandleString left, JS::HandleString right); + +/* + * For JS_DecodeBytes, set *dstlenp to the size of the destination buffer before + * the call; on return, *dstlenp contains the number of jschars actually stored. + * To determine the necessary destination buffer size, make a sizing call that + * passes nullptr for dst. + * + * On errors, the functions report the error. In that case, *dstlenp contains + * the number of characters or bytes transferred so far. If cx is nullptr, no + * error is reported on failure, and the functions simply return false. + * + * NB: This function does not store an additional zero byte or jschar after the + * transcoded string. + */ +JS_PUBLIC_API(bool) +JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst, + size_t *dstlenp); + +/* + * A variation on JS_EncodeCharacters where a null terminated string is + * returned that you are expected to call JS_free on when done. + */ +JS_PUBLIC_API(char *) +JS_EncodeString(JSContext *cx, JSString *str); + +/* + * Same behavior as JS_EncodeString(), but encode into UTF-8 string + */ +JS_PUBLIC_API(char *) +JS_EncodeStringToUTF8(JSContext *cx, JS::HandleString str); + +/* + * Get number of bytes in the string encoding (without accounting for a + * terminating zero bytes. The function returns (size_t) -1 if the string + * can not be encoded into bytes and reports an error using cx accordingly. + */ +JS_PUBLIC_API(size_t) +JS_GetStringEncodingLength(JSContext *cx, JSString *str); + +/* + * Encode string into a buffer. The function does not stores an additional + * zero byte. The function returns (size_t) -1 if the string can not be + * encoded into bytes with no error reported. Otherwise it returns the number + * of bytes that are necessary to encode the string. If that exceeds the + * length parameter, the string will be cut and only length bytes will be + * written into the buffer. + */ +JS_PUBLIC_API(size_t) +JS_EncodeStringToBuffer(JSContext *cx, JSString *str, char *buffer, size_t length); + +class JSAutoByteString +{ + public: + JSAutoByteString(JSContext *cx, JSString *str + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mBytes(JS_EncodeString(cx, str)) + { + JS_ASSERT(cx); + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + explicit JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + : mBytes(nullptr) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + ~JSAutoByteString() { + js_free(mBytes); + } + + /* Take ownership of the given byte array. */ + void initBytes(char *bytes) { + JS_ASSERT(!mBytes); + mBytes = bytes; + } + + char *encodeLatin1(JSContext *cx, JSString *str) { + JS_ASSERT(!mBytes); + JS_ASSERT(cx); + mBytes = JS_EncodeString(cx, str); + return mBytes; + } + + char *encodeLatin1(js::ExclusiveContext *cx, JSString *str); + + char *encodeUtf8(JSContext *cx, JS::HandleString str) { + JS_ASSERT(!mBytes); + JS_ASSERT(cx); + mBytes = JS_EncodeStringToUTF8(cx, str); + return mBytes; + } + + void clear() { + js_free(mBytes); + mBytes = nullptr; + } + + char *ptr() const { + return mBytes; + } + + bool operator!() const { + return !mBytes; + } + + size_t length() const { + if (!mBytes) + return 0; + return strlen(mBytes); + } + + private: + char *mBytes; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + /* Copy and assignment are not supported. */ + JSAutoByteString(const JSAutoByteString &another); + JSAutoByteString &operator=(const JSAutoByteString &another); +}; + +namespace JS { + +extern JS_PUBLIC_API(JSAddonId *) +NewAddonId(JSContext *cx, JS::HandleString str); + +extern JS_PUBLIC_API(JSString *) +StringOfAddonId(JSAddonId *id); + +extern JS_PUBLIC_API(JSAddonId *) +AddonIdOfObject(JSObject *obj); + +} // namespace JS + +/************************************************************************/ +/* + * Symbols + */ + +namespace JS { + +/* + * Create a new Symbol with the given description. This function never returns + * a Symbol that is in the Runtime-wide symbol registry. + * + * If description is null, the new Symbol's [[Description]] attribute is + * undefined. + */ +JS_PUBLIC_API(Symbol *) +NewSymbol(JSContext *cx, HandleString description); + +/* + * Symbol.for as specified in ES6. + * + * Get a Symbol with the description 'key' from the Runtime-wide symbol registry. + * If there is not already a Symbol with that description in the registry, a new + * Symbol is created and registered. 'key' must not be null. + */ +JS_PUBLIC_API(Symbol *) +GetSymbolFor(JSContext *cx, HandleString key); + +/* + * Get the [[Description]] attribute of the given symbol. + * + * This function is infallible. If it returns null, that means the symbol's + * [[Description]] is undefined. + */ +JS_PUBLIC_API(JSString *) +GetSymbolDescription(HandleSymbol symbol); + +/* Well-known symbols. */ +MOZ_BEGIN_ENUM_CLASS(SymbolCode, uint32_t) + iterator, // well-known Symbol.iterator + InSymbolRegistry = 0xfffffffe, // created by Symbol.for() or JS::GetSymbolFor() + UniqueSymbol = 0xffffffff // created by Symbol() or JS::NewSymbol() +MOZ_END_ENUM_CLASS(SymbolCode) + +/* For use in loops that iterate over the well-known symbols. */ +const size_t WellKnownSymbolLimit = 1; + +/* + * Return the SymbolCode telling what sort of symbol `symbol` is. + * + * A symbol's SymbolCode never changes once it is created. + */ +JS_PUBLIC_API(SymbolCode) +GetSymbolCode(Handle symbol); + +/* + * Get one of the well-known symbols defined by ES6. A single set of well-known + * symbols is shared by all compartments in a JSRuntime. + * + * `which` must be in the range [0, WellKnownSymbolLimit). + */ +JS_PUBLIC_API(Symbol *) +GetWellKnownSymbol(JSContext *cx, SymbolCode which); + +} /* namespace JS */ + +/************************************************************************/ +/* + * JSON functions + */ +typedef bool (* JSONWriteCallback)(const jschar *buf, uint32_t len, void *data); + +/* + * JSON.stringify as specified by ES5. + */ +JS_PUBLIC_API(bool) +JS_Stringify(JSContext *cx, JS::MutableHandleValue value, JS::HandleObject replacer, + JS::HandleValue space, JSONWriteCallback callback, void *data); + +/* + * JSON.parse as specified by ES5. + */ +JS_PUBLIC_API(bool) +JS_ParseJSON(JSContext *cx, const jschar *chars, uint32_t len, JS::MutableHandleValue vp); + +JS_PUBLIC_API(bool) +JS_ParseJSON(JSContext *cx, JS::HandleString str, JS::MutableHandleValue vp); + +JS_PUBLIC_API(bool) +JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32_t len, JS::HandleValue reviver, + JS::MutableHandleValue vp); + +JS_PUBLIC_API(bool) +JS_ParseJSONWithReviver(JSContext *cx, JS::HandleString str, JS::HandleValue reviver, + JS::MutableHandleValue vp); + +/************************************************************************/ + +/* + * The default locale for the ECMAScript Internationalization API + * (Intl.Collator, Intl.NumberFormat, Intl.DateTimeFormat). + * Note that the Internationalization API encourages clients to + * specify their own locales. + * The locale string remains owned by the caller. + */ +extern JS_PUBLIC_API(bool) +JS_SetDefaultLocale(JSRuntime *rt, const char *locale); + +/* + * Reset the default locale to OS defaults. + */ +extern JS_PUBLIC_API(void) +JS_ResetDefaultLocale(JSRuntime *rt); + +/* + * Locale specific string conversion and error message callbacks. + */ +struct JSLocaleCallbacks { + JSLocaleToUpperCase localeToUpperCase; + JSLocaleToLowerCase localeToLowerCase; + JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API + JSLocaleToUnicode localeToUnicode; +}; + +/* + * Establish locale callbacks. The pointer must persist as long as the + * JSRuntime. Passing nullptr restores the default behaviour. + */ +extern JS_PUBLIC_API(void) +JS_SetLocaleCallbacks(JSRuntime *rt, JSLocaleCallbacks *callbacks); + +/* + * Return the address of the current locale callbacks struct, which may + * be nullptr. + */ +extern JS_PUBLIC_API(JSLocaleCallbacks *) +JS_GetLocaleCallbacks(JSRuntime *rt); + +/************************************************************************/ + +/* + * Error reporting. + */ + +/* + * Report an exception represented by the sprintf-like conversion of format + * and its arguments. This exception message string is passed to a pre-set + * JSErrorReporter function (set by JS_SetErrorReporter). + */ +extern JS_PUBLIC_API(void) +JS_ReportError(JSContext *cx, const char *format, ...); + +/* + * Use an errorNumber to retrieve the format string, args are char * + */ +extern JS_PUBLIC_API(void) +JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback, + void *userRef, const unsigned errorNumber, ...); + +#ifdef va_start +extern JS_PUBLIC_API(void) +JS_ReportErrorNumberVA(JSContext *cx, JSErrorCallback errorCallback, + void *userRef, const unsigned errorNumber, va_list ap); +#endif + +/* + * Use an errorNumber to retrieve the format string, args are jschar * + */ +extern JS_PUBLIC_API(void) +JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback, + void *userRef, const unsigned errorNumber, ...); + +extern JS_PUBLIC_API(void) +JS_ReportErrorNumberUCArray(JSContext *cx, JSErrorCallback errorCallback, + void *userRef, const unsigned errorNumber, + const jschar **args); + +/* + * As above, but report a warning instead (JSREPORT_IS_WARNING(report.flags)). + * Return true if there was no error trying to issue the warning, and if the + * warning was not converted into an error due to the JSOPTION_WERROR option + * being set, false otherwise. + */ +extern JS_PUBLIC_API(bool) +JS_ReportWarning(JSContext *cx, const char *format, ...); + +extern JS_PUBLIC_API(bool) +JS_ReportErrorFlagsAndNumber(JSContext *cx, unsigned flags, + JSErrorCallback errorCallback, void *userRef, + const unsigned errorNumber, ...); + +extern JS_PUBLIC_API(bool) +JS_ReportErrorFlagsAndNumberUC(JSContext *cx, unsigned flags, + JSErrorCallback errorCallback, void *userRef, + const unsigned errorNumber, ...); + +/* + * Complain when out of memory. + */ +extern JS_PUBLIC_API(void) +JS_ReportOutOfMemory(JSContext *cx); + +/* + * Complain when an allocation size overflows the maximum supported limit. + */ +extern JS_PUBLIC_API(void) +JS_ReportAllocationOverflow(JSContext *cx); + +struct JSErrorReport { + const char *filename; /* source file name, URL, etc., or null */ + JSPrincipals *originPrincipals; /* see 'originPrincipals' comment above */ + unsigned lineno; /* source line number */ + const char *linebuf; /* offending source line without final \n */ + const char *tokenptr; /* pointer to error token in linebuf */ + const jschar *uclinebuf; /* unicode (original) line buffer */ + const jschar *uctokenptr; /* unicode (original) token pointer */ + unsigned flags; /* error/warning, etc. */ + unsigned errorNumber; /* the error number, e.g. see js.msg */ + const jschar *ucmessage; /* the (default) error message */ + const jschar **messageArgs; /* arguments for the error message */ + int16_t exnType; /* One of the JSExnType constants */ + unsigned column; /* zero-based column index in line */ +}; + +/* + * JSErrorReport flag values. These may be freely composed. + */ +#define JSREPORT_ERROR 0x0 /* pseudo-flag for default case */ +#define JSREPORT_WARNING 0x1 /* reported via JS_ReportWarning */ +#define JSREPORT_EXCEPTION 0x2 /* exception was thrown */ +#define JSREPORT_STRICT 0x4 /* error or warning due to strict option */ + +/* + * This condition is an error in strict mode code, a warning if + * JS_HAS_STRICT_OPTION(cx), and otherwise should not be reported at + * all. We check the strictness of the context's top frame's script; + * where that isn't appropriate, the caller should do the right checks + * itself instead of using this flag. + */ +#define JSREPORT_STRICT_MODE_ERROR 0x8 + +/* + * If JSREPORT_EXCEPTION is set, then a JavaScript-catchable exception + * has been thrown for this runtime error, and the host should ignore it. + * Exception-aware hosts should also check for JS_IsExceptionPending if + * JS_ExecuteScript returns failure, and signal or propagate the exception, as + * appropriate. + */ +#define JSREPORT_IS_WARNING(flags) (((flags) & JSREPORT_WARNING) != 0) +#define JSREPORT_IS_EXCEPTION(flags) (((flags) & JSREPORT_EXCEPTION) != 0) +#define JSREPORT_IS_STRICT(flags) (((flags) & JSREPORT_STRICT) != 0) +#define JSREPORT_IS_STRICT_MODE_ERROR(flags) (((flags) & \ + JSREPORT_STRICT_MODE_ERROR) != 0) +extern JS_PUBLIC_API(JSErrorReporter) +JS_GetErrorReporter(JSContext *cx); + +extern JS_PUBLIC_API(JSErrorReporter) +JS_SetErrorReporter(JSContext *cx, JSErrorReporter er); + +namespace JS { + +extern JS_PUBLIC_API(bool) +CreateError(JSContext *cx, JSExnType type, HandleString stack, + HandleString fileName, uint32_t lineNumber, uint32_t columnNumber, + JSErrorReport *report, HandleString message, MutableHandleValue rval); + +/************************************************************************/ + +/* + * Weak Maps. + */ + +extern JS_PUBLIC_API(JSObject *) +NewWeakMapObject(JSContext *cx); + +extern JS_PUBLIC_API(bool) +IsWeakMapObject(JSObject *obj); + +extern JS_PUBLIC_API(bool) +GetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::MutableHandleValue val); + +extern JS_PUBLIC_API(bool) +SetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key, + JS::HandleValue val); + +} /* namespace JS */ + +/* + * Dates. + */ + +extern JS_PUBLIC_API(JSObject *) +JS_NewDateObject(JSContext *cx, int year, int mon, int mday, int hour, int min, int sec); + +extern JS_PUBLIC_API(JSObject *) +JS_NewDateObjectMsec(JSContext *cx, double msec); + +/* + * Infallible predicate to test whether obj is a date object. + */ +extern JS_PUBLIC_API(bool) +JS_ObjectIsDate(JSContext *cx, JS::HandleObject obj); + +/* + * Clears the cache of calculated local time from each Date object. + * Call to propagate a system timezone change. + */ +extern JS_PUBLIC_API(void) +JS_ClearDateCaches(JSContext *cx); + +/************************************************************************/ + +/* + * Regular Expressions. + */ +#define JSREG_FOLD 0x01u /* fold uppercase to lowercase */ +#define JSREG_GLOB 0x02u /* global exec, creates array of matches */ +#define JSREG_MULTILINE 0x04u /* treat ^ and $ as begin and end of line */ +#define JSREG_STICKY 0x08u /* only match starting at lastIndex */ + +extern JS_PUBLIC_API(JSObject *) +JS_NewRegExpObject(JSContext *cx, JS::HandleObject obj, char *bytes, size_t length, + unsigned flags); + +extern JS_PUBLIC_API(JSObject *) +JS_NewUCRegExpObject(JSContext *cx, JS::HandleObject obj, jschar *chars, size_t length, + unsigned flags); + +extern JS_PUBLIC_API(bool) +JS_SetRegExpInput(JSContext *cx, JS::HandleObject obj, JS::HandleString input, + bool multiline); + +extern JS_PUBLIC_API(bool) +JS_ClearRegExpStatics(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(bool) +JS_ExecuteRegExp(JSContext *cx, JS::HandleObject obj, JS::HandleObject reobj, + jschar *chars, size_t length, size_t *indexp, bool test, + JS::MutableHandleValue rval); + +/* RegExp interface for clients without a global object. */ + +extern JS_PUBLIC_API(JSObject *) +JS_NewRegExpObjectNoStatics(JSContext *cx, char *bytes, size_t length, unsigned flags); + +extern JS_PUBLIC_API(JSObject *) +JS_NewUCRegExpObjectNoStatics(JSContext *cx, jschar *chars, size_t length, unsigned flags); + +extern JS_PUBLIC_API(bool) +JS_ExecuteRegExpNoStatics(JSContext *cx, JS::HandleObject reobj, jschar *chars, size_t length, + size_t *indexp, bool test, JS::MutableHandleValue rval); + +extern JS_PUBLIC_API(bool) +JS_ObjectIsRegExp(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(unsigned) +JS_GetRegExpFlags(JSContext *cx, JS::HandleObject obj); + +extern JS_PUBLIC_API(JSString *) +JS_GetRegExpSource(JSContext *cx, JS::HandleObject obj); + +/************************************************************************/ + +extern JS_PUBLIC_API(bool) +JS_IsExceptionPending(JSContext *cx); + +extern JS_PUBLIC_API(bool) +JS_GetPendingException(JSContext *cx, JS::MutableHandleValue vp); + +extern JS_PUBLIC_API(void) +JS_SetPendingException(JSContext *cx, JS::HandleValue v); + +extern JS_PUBLIC_API(void) +JS_ClearPendingException(JSContext *cx); + +extern JS_PUBLIC_API(bool) +JS_ReportPendingException(JSContext *cx); + +namespace JS { + +/* + * Save and later restore the current exception state of a given JSContext. + * This is useful for implementing behavior in C++ that's like try/catch + * or try/finally in JS. + * + * Typical usage: + * + * bool ok = JS_EvaluateScript(cx, ...); + * AutoSaveExceptionState savedExc(cx); + * ... cleanup that might re-enter JS ... + * return ok; + */ +class JS_PUBLIC_API(AutoSaveExceptionState) +{ + private: + JSContext *context; + bool wasPropagatingForcedReturn; + bool wasThrowing; + RootedValue exceptionValue; + + public: + /* + * Take a snapshot of cx's current exception state. Then clear any current + * pending exception in cx. + */ + explicit AutoSaveExceptionState(JSContext *cx); + + /* + * If neither drop() nor restore() was called, restore the exception + * state only if no exception is currently pending on cx. + */ + ~AutoSaveExceptionState(); + + /* + * Discard any stored exception state. + * If this is called, the destructor is a no-op. + */ + void drop() { + wasPropagatingForcedReturn = false; + wasThrowing = false; + exceptionValue.setUndefined(); + } + + /* + * Replace cx's exception state with the stored exception state. Then + * discard the stored exception state. If this is called, the + * destructor is a no-op. + */ + void restore(); +}; + +} /* namespace JS */ + +/* Deprecated API. Use AutoSaveExceptionState instead. */ +extern JS_PUBLIC_API(JSExceptionState *) +JS_SaveExceptionState(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_RestoreExceptionState(JSContext *cx, JSExceptionState *state); + +extern JS_PUBLIC_API(void) +JS_DropExceptionState(JSContext *cx, JSExceptionState *state); + +/* + * If the given object is an exception object, the exception will have (or be + * able to lazily create) an error report struct, and this function will return + * the address of that struct. Otherwise, it returns nullptr. The lifetime + * of the error report struct that might be returned is the same as the + * lifetime of the exception object. + */ +extern JS_PUBLIC_API(JSErrorReport *) +JS_ErrorFromException(JSContext *cx, JS::HandleObject obj); + +/* + * Throws a StopIteration exception on cx. + */ +extern JS_PUBLIC_API(bool) +JS_ThrowStopIteration(JSContext *cx); + +extern JS_PUBLIC_API(bool) +JS_IsStopIteration(jsval v); + +extern JS_PUBLIC_API(intptr_t) +JS_GetCurrentThread(); + +/* + * A JS runtime always has an "owner thread". The owner thread is set when the + * runtime is created (to the current thread) and practically all entry points + * into the JS engine check that a runtime (or anything contained in the + * runtime: context, compartment, object, etc) is only touched by its owner + * thread. Embeddings may check this invariant outside the JS engine by calling + * JS_AbortIfWrongThread (which will abort if not on the owner thread, even for + * non-debug builds). + */ + +extern JS_PUBLIC_API(void) +JS_AbortIfWrongThread(JSRuntime *rt); + +/************************************************************************/ + +/* + * A constructor can request that the JS engine create a default new 'this' + * object of the given class, using the callee to determine parentage and + * [[Prototype]]. + */ +extern JS_PUBLIC_API(JSObject *) +JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const JS::CallArgs& args); + +/************************************************************************/ + +#ifdef JS_GC_ZEAL +#define JS_DEFAULT_ZEAL_FREQ 100 + +extern JS_PUBLIC_API(void) +JS_SetGCZeal(JSContext *cx, uint8_t zeal, uint32_t frequency); + +extern JS_PUBLIC_API(void) +JS_ScheduleGC(JSContext *cx, uint32_t count); +#endif + +extern JS_PUBLIC_API(void) +JS_SetParallelParsingEnabled(JSRuntime *rt, bool enabled); + +extern JS_PUBLIC_API(void) +JS_SetOffthreadIonCompilationEnabled(JSRuntime *rt, bool enabled); + +#define JIT_COMPILER_OPTIONS(Register) \ + Register(BASELINE_USECOUNT_TRIGGER, "baseline.usecount.trigger") \ + Register(ION_USECOUNT_TRIGGER, "ion.usecount.trigger") \ + Register(ION_ENABLE, "ion.enable") \ + Register(BASELINE_ENABLE, "baseline.enable") \ + Register(OFFTHREAD_COMPILATION_ENABLE, "offthread-compilation.enable") \ + Register(SIGNALS_ENABLE, "signals.enable") + +typedef enum JSJitCompilerOption { +#define JIT_COMPILER_DECLARE(key, str) \ + JSJITCOMPILER_ ## key, + + JIT_COMPILER_OPTIONS(JIT_COMPILER_DECLARE) +#undef JIT_COMPILER_DECLARE + + JSJITCOMPILER_NOT_AN_OPTION +} JSJitCompilerOption; + +extern JS_PUBLIC_API(void) +JS_SetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt, uint32_t value); +extern JS_PUBLIC_API(int) +JS_GetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt); + +/* + * Convert a uint32_t index into a jsid. + */ +extern JS_PUBLIC_API(bool) +JS_IndexToId(JSContext *cx, uint32_t index, JS::MutableHandleId); + +/* + * Convert chars into a jsid. + * + * |chars| may not be an index. + */ +extern JS_PUBLIC_API(bool) +JS_CharsToId(JSContext* cx, JS::TwoByteChars chars, JS::MutableHandleId); + +/* + * Test if the given string is a valid ECMAScript identifier + */ +extern JS_PUBLIC_API(bool) +JS_IsIdentifier(JSContext *cx, JS::HandleString str, bool *isIdentifier); + +namespace JS { + +/* + * AutoFilename encapsulates a pointer to a C-string and keeps the C-string + * alive for as long as the associated AutoFilename object is alive. + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(AutoFilename) +{ + void *scriptSource_; + + AutoFilename(const AutoFilename &) MOZ_DELETE; + void operator=(const AutoFilename &) MOZ_DELETE; + + public: + AutoFilename() : scriptSource_(nullptr) {} + ~AutoFilename() { reset(nullptr); } + + const char *get() const; + + void reset(void *newScriptSource); +}; + +/* + * Return the current filename and line number of the most currently running + * frame. Returns true if a scripted frame was found, false otherwise. + * + * If a the embedding has hidden the scripted caller for the topmost activation + * record, this will also return false. + */ +extern JS_PUBLIC_API(bool) +DescribeScriptedCaller(JSContext *cx, AutoFilename *filename = nullptr, + unsigned *lineno = nullptr); + +extern JS_PUBLIC_API(JSObject *) +GetScriptedCallerGlobal(JSContext *cx); + +/* + * Informs the JS engine that the scripted caller should be hidden. This can be + * used by the embedding to maintain an override of the scripted caller in its + * calculations, by hiding the scripted caller in the JS engine and pushing data + * onto a separate stack, which it inspects when DescribeScriptedCaller returns + * null. + * + * We maintain a counter on each activation record. Add() increments the counter + * of the topmost activation, and Remove() decrements it. The count may never + * drop below zero, and must always be exactly zero when the activation is + * popped from the stack. + */ +extern JS_PUBLIC_API(void) +HideScriptedCaller(JSContext *cx); + +extern JS_PUBLIC_API(void) +UnhideScriptedCaller(JSContext *cx); + +class AutoHideScriptedCaller +{ + public: + explicit AutoHideScriptedCaller(JSContext *cx + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mContext(cx) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + HideScriptedCaller(mContext); + } + ~AutoHideScriptedCaller() { + UnhideScriptedCaller(mContext); + } + + protected: + JSContext *mContext; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +} /* namespace JS */ + +/* + * Encode/Decode interpreted scripts and functions to/from memory. + */ + +extern JS_PUBLIC_API(void *) +JS_EncodeScript(JSContext *cx, JS::HandleScript script, uint32_t *lengthp); + +extern JS_PUBLIC_API(void *) +JS_EncodeInterpretedFunction(JSContext *cx, JS::HandleObject funobj, uint32_t *lengthp); + +extern JS_PUBLIC_API(JSScript *) +JS_DecodeScript(JSContext *cx, const void *data, uint32_t length, JSPrincipals *originPrincipals); + +extern JS_PUBLIC_API(JSObject *) +JS_DecodeInterpretedFunction(JSContext *cx, const void *data, uint32_t length, + JSPrincipals *originPrincipals); + +namespace JS { + +/* + * This callback represents a request by the JS engine to open for reading the + * existing cache entry for the given global and char range that may contain a + * module. If a cache entry exists, the callback shall return 'true' and return + * the size, base address and an opaque file handle as outparams. If the + * callback returns 'true', the JS engine guarantees a call to + * CloseAsmJSCacheEntryForReadOp, passing the same base address, size and + * handle. + */ +typedef bool +(* OpenAsmJSCacheEntryForReadOp)(HandleObject global, const jschar *begin, const jschar *limit, + size_t *size, const uint8_t **memory, intptr_t *handle); +typedef void +(* CloseAsmJSCacheEntryForReadOp)(size_t size, const uint8_t *memory, intptr_t handle); + +/* + * This callback represents a request by the JS engine to open for writing a + * cache entry of the given size for the given global and char range containing + * the just-compiled module. If cache entry space is available, the callback + * shall return 'true' and return the base address and an opaque file handle as + * outparams. If the callback returns 'true', the JS engine guarantees a call + * to CloseAsmJSCacheEntryForWriteOp passing the same base address, size and + * handle. + * + * If 'installed' is true, then the cache entry is associated with a permanently + * installed JS file (e.g., in a packaged webapp). This information allows the + * embedding to store the cache entry in a installed location associated with + * the principal of 'global' where it will not be evicted until the associated + * installed JS file is removed. + */ +typedef bool +(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, bool installed, + const jschar *begin, const jschar *end, + size_t size, uint8_t **memory, intptr_t *handle); +typedef void +(* CloseAsmJSCacheEntryForWriteOp)(size_t size, uint8_t *memory, intptr_t handle); + +typedef js::Vector BuildIdCharVector; + +// Return the buildId (represented as a sequence of characters) associated with +// the currently-executing build. If the JS engine is embedded such that a +// single cache entry can be observed by different compiled versions of the JS +// engine, it is critical that the buildId shall change for each new build of +// the JS engine. + +typedef bool +(* BuildIdOp)(BuildIdCharVector *buildId); + +struct AsmJSCacheOps +{ + OpenAsmJSCacheEntryForReadOp openEntryForRead; + CloseAsmJSCacheEntryForReadOp closeEntryForRead; + OpenAsmJSCacheEntryForWriteOp openEntryForWrite; + CloseAsmJSCacheEntryForWriteOp closeEntryForWrite; + BuildIdOp buildId; +}; + +extern JS_PUBLIC_API(void) +SetAsmJSCacheOps(JSRuntime *rt, const AsmJSCacheOps *callbacks); + +/* + * Convenience class for imitating a JS level for-of loop. Typical usage: + * + * ForOfIterator it(cx); + * if (!it.init(iterable)) + * return false; + * RootedValue val(cx); + * while (true) { + * bool done; + * if (!it.next(&val, &done)) + * return false; + * if (done) + * break; + * if (!DoStuff(cx, val)) + * return false; + * } + */ +class MOZ_STACK_CLASS JS_PUBLIC_API(ForOfIterator) { + protected: + JSContext *cx_; + /* + * Use the ForOfPIC on the global object (see vm/GlobalObject.h) to try + * to optimize iteration across arrays. + * + * Case 1: Regular Iteration + * iterator - pointer to the iterator object. + * index - fixed to NOT_ARRAY (== UINT32_MAX) + * + * Case 2: Optimized Array Iteration + * iterator - pointer to the array object. + * index - current position in array. + * + * The cases are distinguished by whether or not |index| is equal to NOT_ARRAY. + */ + JS::RootedObject iterator; + uint32_t index; + + static const uint32_t NOT_ARRAY = UINT32_MAX; + + ForOfIterator(const ForOfIterator &) MOZ_DELETE; + ForOfIterator &operator=(const ForOfIterator &) MOZ_DELETE; + + public: + explicit ForOfIterator(JSContext *cx) : cx_(cx), iterator(cx_), index(NOT_ARRAY) { } + + enum NonIterableBehavior { + ThrowOnNonIterable, + AllowNonIterable + }; + + /* + * Initialize the iterator. If AllowNonIterable is passed then if iterable + * does not have a callable @@iterator init() will just return true instead + * of throwing. Callers should then check valueIsIterable() before + * continuing with the iteration. + */ + bool init(JS::HandleValue iterable, + NonIterableBehavior nonIterableBehavior = ThrowOnNonIterable); + + /* + * This method assumes that |iterator| is already an iterator. It will not + * check for, and call @@iterator. Callers should make sure that the passed + * in value is in fact an iterator. + */ + bool initWithIterator(JS::HandleValue aIterator); + + /* + * Get the next value from the iterator. If false *done is true + * after this call, do not examine val. + */ + bool next(JS::MutableHandleValue val, bool *done); + + /* + * If initialized with throwOnNonCallable = false, check whether + * the value is iterable. + */ + bool valueIsIterable() const { + return iterator; + } + + private: + inline bool nextFromOptimizedArray(MutableHandleValue val, bool *done); + bool materializeArrayIterator(); +}; + + +/* + * If a large allocation fails, the JS engine may call the large-allocation- + * failure callback, if set, to allow the embedding to flush caches, possibly + * perform shrinking GCs, etc. to make some room so that the allocation will + * succeed if retried. After the callback returns, the JS engine will try to + * allocate again and may be succesful. + */ + +typedef void +(* LargeAllocationFailureCallback)(void *data); + +extern JS_PUBLIC_API(void) +SetLargeAllocationFailureCallback(JSRuntime *rt, LargeAllocationFailureCallback afc, void *data); + +/* + * Unlike the error reporter, which is only called if the exception for an OOM + * bubbles up and is not caught, the OutOfMemoryCallback is called immediately + * at the OOM site to allow the embedding to capture the current state of heap + * allocation before anything is freed. If the large-allocation-failure callback + * is called at all (not all allocation sites call the large-allocation-failure + * callback on failure), it is called before the out-of-memory callback; the + * out-of-memory callback is only called if the allocation still fails after the + * large-allocation-failure callback has returned. + */ + +typedef void +(* OutOfMemoryCallback)(JSContext *cx, void *data); + +extern JS_PUBLIC_API(void) +SetOutOfMemoryCallback(JSRuntime *rt, OutOfMemoryCallback cb, void *data); + + +/* + * Capture the current call stack as a chain of SavedFrame objects, and set + * |stackp| to the SavedFrame for the newest stack frame. If |maxFrameCount| is + * non-zero, capture at most the youngest |maxFrameCount| frames. + */ +extern JS_PUBLIC_API(bool) +CaptureCurrentStack(JSContext *cx, MutableHandleObject stackp, unsigned maxFrameCount = 0); + +} /* namespace JS */ + +#endif /* jsapi_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsbytecode.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsbytecode.h new file mode 100644 index 0000000000..8e4f4cf90b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsbytecode.h @@ -0,0 +1,14 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsbytecode_h +#define jsbytecode_h + +#include + +typedef uint8_t jsbytecode; + +#endif /* jsbytecode_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsclist.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsclist.h new file mode 100644 index 0000000000..23da9b8cd5 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsclist.h @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsclist_h +#define jsclist_h + +#include "jstypes.h" + +/* +** Circular linked list +*/ +typedef struct JSCListStr { + struct JSCListStr *next; + struct JSCListStr *prev; +} JSCList; + +/* +** Insert element "_e" into the list, before "_l". +*/ +#define JS_INSERT_BEFORE(_e,_l) \ + JS_BEGIN_MACRO \ + (_e)->next = (_l); \ + (_e)->prev = (_l)->prev; \ + (_l)->prev->next = (_e); \ + (_l)->prev = (_e); \ + JS_END_MACRO + +/* +** Insert element "_e" into the list, after "_l". +*/ +#define JS_INSERT_AFTER(_e,_l) \ + JS_BEGIN_MACRO \ + (_e)->next = (_l)->next; \ + (_e)->prev = (_l); \ + (_l)->next->prev = (_e); \ + (_l)->next = (_e); \ + JS_END_MACRO + +/* +** Return the element following element "_e" +*/ +#define JS_NEXT_LINK(_e) \ + ((_e)->next) +/* +** Return the element preceding element "_e" +*/ +#define JS_PREV_LINK(_e) \ + ((_e)->prev) + +/* +** Append an element "_e" to the end of the list "_l" +*/ +#define JS_APPEND_LINK(_e,_l) JS_INSERT_BEFORE(_e,_l) + +/* +** Insert an element "_e" at the head of the list "_l" +*/ +#define JS_INSERT_LINK(_e,_l) JS_INSERT_AFTER(_e,_l) + +/* Return the head/tail of the list */ +#define JS_LIST_HEAD(_l) (_l)->next +#define JS_LIST_TAIL(_l) (_l)->prev + +/* +** Remove the element "_e" from it's circular list. +*/ +#define JS_REMOVE_LINK(_e) \ + JS_BEGIN_MACRO \ + (_e)->prev->next = (_e)->next; \ + (_e)->next->prev = (_e)->prev; \ + JS_END_MACRO + +/* +** Remove the element "_e" from it's circular list. Also initializes the +** linkage. +*/ +#define JS_REMOVE_AND_INIT_LINK(_e) \ + JS_BEGIN_MACRO \ + (_e)->prev->next = (_e)->next; \ + (_e)->next->prev = (_e)->prev; \ + (_e)->next = (_e); \ + (_e)->prev = (_e); \ + JS_END_MACRO + +/* +** Return non-zero if the given circular list "_l" is empty, zero if the +** circular list is not empty +*/ +#define JS_CLIST_IS_EMPTY(_l) \ + ((_l)->next == (_l)) + +/* +** Initialize a circular list +*/ +#define JS_INIT_CLIST(_l) \ + JS_BEGIN_MACRO \ + (_l)->next = (_l); \ + (_l)->prev = (_l); \ + JS_END_MACRO + +#define JS_INIT_STATIC_CLIST(_l) \ + {(_l), (_l)} + +#endif /* jsclist_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jscpucfg.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jscpucfg.h new file mode 100644 index 0000000000..a7a00613bb --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jscpucfg.h @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jscpucfg_h +#define jscpucfg_h + +#define JS_HAVE_LONG_LONG + +#if defined(_WIN64) + +# if defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_) +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# else /* !(defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)) */ +# error "CPU type is unknown" +# endif /* !(defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)) */ + +#elif defined(_WIN32) + +# ifdef __WATCOMC__ +# define HAVE_VA_LIST_AS_ARRAY 1 +# endif + +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN + +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) +# if __LITTLE_ENDIAN__ +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# elif __BIG_ENDIAN__ +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 +# endif + +#elif defined(JS_HAVE_ENDIAN_H) +# include + +# if defined(__BYTE_ORDER) +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# elif __BYTE_ORDER == __BIG_ENDIAN +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 +# endif +# else /* !defined(__BYTE_ORDER) */ +# error "endian.h does not define __BYTE_ORDER. Cannot determine endianness." +# endif + +/* BSDs */ +#elif defined(JS_HAVE_MACHINE_ENDIAN_H) +# include +# include + +# if defined(_BYTE_ORDER) +# if _BYTE_ORDER == _LITTLE_ENDIAN +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# elif _BYTE_ORDER == _BIG_ENDIAN +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 +# endif +# else /* !defined(_BYTE_ORDER) */ +# error "machine/endian.h does not define _BYTE_ORDER. Cannot determine endianness." +# endif + +#elif defined(JS_HAVE_SYS_ISA_DEFS_H) +# include + +# if defined(_BIG_ENDIAN) +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 +# elif defined(_LITTLE_ENDIAN) +# define IS_LITTLE_ENDIAN 1 +# undef IS_BIG_ENDIAN +# else /* !defined(_LITTLE_ENDIAN) */ +# error "sys/isa_defs.h does not define _BIG_ENDIAN or _LITTLE_ENDIAN. Cannot determine endianness." +# endif +# if !defined(JS_STACK_GROWTH_DIRECTION) +# if defined(_STACK_GROWS_UPWARD) +# define JS_STACK_GROWTH_DIRECTION (1) +# elif defined(_STACK_GROWS_DOWNWARD) +# define JS_STACK_GROWTH_DIRECTION (-1) +# endif +# endif + +#elif defined(__sparc) || defined(__sparc__) || \ + defined(_POWER) || defined(__hppa) || \ + defined(_MIPSEB) || defined(_BIG_ENDIAN) +/* IA64 running HP-UX will have _BIG_ENDIAN defined. + * IA64 running Linux will have endian.h and be handled above. + */ +# undef IS_LITTLE_ENDIAN +# define IS_BIG_ENDIAN 1 + +#else /* !defined(__sparc) && !defined(__sparc__) && ... */ +# error "Cannot determine endianness of your platform. Please add support to jscpucfg.h." +#endif + +#ifndef JS_STACK_GROWTH_DIRECTION +# ifdef __hppa +# define JS_STACK_GROWTH_DIRECTION (1) +# else +# define JS_STACK_GROWTH_DIRECTION (-1) +# endif +#endif + +#endif /* jscpucfg_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsfriendapi.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsfriendapi.h new file mode 100644 index 0000000000..674999eb62 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsfriendapi.h @@ -0,0 +1,2561 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsfriendapi_h +#define jsfriendapi_h + +#include "mozilla/Casting.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/TypedEnum.h" +#include "mozilla/UniquePtr.h" + +#include "jsapi.h" // For JSAutoByteString. See bug 1033916. +#include "jsbytecode.h" +#include "jspubtd.h" + +#include "js/CallArgs.h" +#include "js/CallNonGenericMethod.h" +#include "js/Class.h" + +/* + * This macro checks if the stack pointer has exceeded a given limit. If + * |tolerance| is non-zero, it returns true only if the stack pointer has + * exceeded the limit by more than |tolerance| bytes. The WITH_INTOLERANCE + * versions use a negative tolerance (i.e., the limit is reduced by + * |intolerance| bytes). + */ +#if JS_STACK_GROWTH_DIRECTION > 0 +# define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ + ((uintptr_t)(sp) < (limit)+(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) < (limit)-(intolerance)) +#else +# define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ + ((uintptr_t)(sp) > (limit)-(tolerance)) +# define JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(limit, sp, intolerance) \ + ((uintptr_t)(sp) > (limit)+(intolerance)) +#endif + +#define JS_CHECK_STACK_SIZE(limit, lval) JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, lval, 0) + +class JSAtom; +struct JSErrorFormatString; +class JSLinearString; +struct JSJitInfo; +struct JSErrorReport; + +namespace JS { +template +class Heap; +} /* namespace JS */ + +namespace js { +class JS_FRIEND_API(BaseProxyHandler); +} /* namespace js */ + +extern JS_FRIEND_API(void) +JS_SetGrayGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data); + +extern JS_FRIEND_API(JSString *) +JS_GetAnonymousString(JSRuntime *rt); + +extern JS_FRIEND_API(JSObject *) +JS_FindCompilationScope(JSContext *cx, JS::HandleObject obj); + +extern JS_FRIEND_API(JSFunction *) +JS_GetObjectFunction(JSObject *obj); + +extern JS_FRIEND_API(bool) +JS_SplicePrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); + +extern JS_FRIEND_API(JSObject *) +JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JS::HandleObject proto, + JS::HandleObject parent); + +extern JS_FRIEND_API(uint32_t) +JS_ObjectCountDynamicSlots(JS::HandleObject obj); + +extern JS_FRIEND_API(size_t) +JS_SetProtoCalled(JSContext *cx); + +extern JS_FRIEND_API(size_t) +JS_GetCustomIteratorCount(JSContext *cx); + +extern JS_FRIEND_API(bool) +JS_NondeterministicGetWeakMapKeys(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject ret); + +/* + * Determine whether the given object is backed by a DeadObjectProxy. + * + * Such objects hold no other objects (they have no outgoing reference edges) + * and will throw if you touch them (e.g. by reading/writing a property). + */ +extern JS_FRIEND_API(bool) +JS_IsDeadWrapper(JSObject *obj); + +/* + * Used by the cycle collector to trace through the shape and all + * shapes it reaches, marking all non-shape children found in the + * process. Uses bounded stack space. + */ +extern JS_FRIEND_API(void) +JS_TraceShapeCycleCollectorChildren(JSTracer *trc, void *shape); + +enum { + JS_TELEMETRY_GC_REASON, + JS_TELEMETRY_GC_IS_COMPARTMENTAL, + JS_TELEMETRY_GC_MS, + JS_TELEMETRY_GC_MAX_PAUSE_MS, + JS_TELEMETRY_GC_MARK_MS, + JS_TELEMETRY_GC_SWEEP_MS, + JS_TELEMETRY_GC_MARK_ROOTS_MS, + JS_TELEMETRY_GC_MARK_GRAY_MS, + JS_TELEMETRY_GC_SLICE_MS, + JS_TELEMETRY_GC_MMU_50, + JS_TELEMETRY_GC_RESET, + JS_TELEMETRY_GC_INCREMENTAL_DISABLED, + JS_TELEMETRY_GC_NON_INCREMENTAL, + JS_TELEMETRY_GC_SCC_SWEEP_TOTAL_MS, + JS_TELEMETRY_GC_SCC_SWEEP_MAX_PAUSE_MS +}; + +typedef void +(* JSAccumulateTelemetryDataCallback)(int id, uint32_t sample); + +extern JS_FRIEND_API(void) +JS_SetAccumulateTelemetryCallback(JSRuntime *rt, JSAccumulateTelemetryDataCallback callback); + +extern JS_FRIEND_API(JSPrincipals *) +JS_GetCompartmentPrincipals(JSCompartment *compartment); + +extern JS_FRIEND_API(void) +JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals); + +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptPrincipals(JSScript *script); + +extern JS_FRIEND_API(JSPrincipals *) +JS_GetScriptOriginPrincipals(JSScript *script); + +/* Safe to call with input obj == nullptr. Returns non-nullptr iff obj != nullptr. */ +extern JS_FRIEND_API(JSObject *) +JS_ObjectToInnerObject(JSContext *cx, JS::HandleObject obj); + +/* Requires obj != nullptr. */ +extern JS_FRIEND_API(JSObject *) +JS_ObjectToOuterObject(JSContext *cx, JS::HandleObject obj); + +extern JS_FRIEND_API(JSObject *) +JS_CloneObject(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto, + JS::HandleObject parent); + +extern JS_FRIEND_API(JSString *) +JS_BasicObjectToString(JSContext *cx, JS::HandleObject obj); + +extern JS_FRIEND_API(bool) +js_GetterOnlyPropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, + JS::MutableHandleValue vp); + +JS_FRIEND_API(void) +js_ReportOverRecursed(JSContext *maybecx); + +JS_FRIEND_API(bool) +js_ObjectClassIs(JSContext *cx, JS::HandleObject obj, js::ESClassValue classValue); + +JS_FRIEND_API(const char *) +js_ObjectClassName(JSContext *cx, JS::HandleObject obj); + +namespace js { + +JS_FRIEND_API(bool) +AddRawValueRoot(JSContext *cx, JS::Value *vp, const char *name); + +JS_FRIEND_API(void) +RemoveRawValueRoot(JSContext *cx, JS::Value *vp); + +} /* namespace js */ + +#ifdef JS_DEBUG + +/* + * Routines to print out values during debugging. These are FRIEND_API to help + * the debugger find them and to support temporarily hacking js_Dump* calls + * into other code. + */ + +extern JS_FRIEND_API(void) +js_DumpString(JSString *str); + +extern JS_FRIEND_API(void) +js_DumpAtom(JSAtom *atom); + +extern JS_FRIEND_API(void) +js_DumpObject(JSObject *obj); + +extern JS_FRIEND_API(void) +js_DumpChars(const jschar *s, size_t n); +#endif + +/* + * Copies all own properties from |obj| to |target|. |obj| must be a "native" + * object (that is to say, normal-ish - not an Array or a Proxy). + * + * This function immediately enters a compartment, and does not impose any + * restrictions on the compartment of |cx|. + */ +extern JS_FRIEND_API(bool) +JS_CopyPropertiesFrom(JSContext *cx, JS::HandleObject target, JS::HandleObject obj); + +/* + * Single-property version of the above. This function asserts that an |own| + * property of the given name exists on |obj|. + * + * On entry, |cx| must be same-compartment with |obj|. + */ +extern JS_FRIEND_API(bool) +JS_CopyPropertyFrom(JSContext *cx, JS::HandleId id, JS::HandleObject target, + JS::HandleObject obj); + +extern JS_FRIEND_API(bool) +JS_WrapPropertyDescriptor(JSContext *cx, JS::MutableHandle desc); + +extern JS_FRIEND_API(bool) +JS_WrapAutoIdVector(JSContext *cx, JS::AutoIdVector &props); + +extern JS_FRIEND_API(bool) +JS_EnumerateState(JSContext *cx, JS::HandleObject obj, JSIterateOp enum_op, + JS::MutableHandleValue statep, JS::MutableHandleId idp); + +struct JSFunctionSpecWithHelp { + const char *name; + JSNative call; + uint16_t nargs; + uint16_t flags; + const char *usage; + const char *help; +}; + +#define JS_FN_HELP(name,call,nargs,flags,usage,help) \ + {name, call, nargs, (flags) | JSPROP_ENUMERATE | JSFUN_STUB_GSOPS, usage, help} +#define JS_FS_HELP_END \ + {nullptr, nullptr, 0, 0, nullptr, nullptr} + +extern JS_FRIEND_API(bool) +JS_DefineFunctionsWithHelp(JSContext *cx, JS::HandleObject obj, const JSFunctionSpecWithHelp *fs); + +namespace js { + +/* + * Helper Macros for creating JSClasses that function as proxies. + * + * NB: The macro invocation must be surrounded by braces, so as to + * allow for potention JSClass extensions. + */ +#define PROXY_MAKE_EXT(outerObject, innerObject, iteratorObject, \ + isWrappedNative) \ + { \ + outerObject, \ + innerObject, \ + iteratorObject, \ + isWrappedNative, \ + js::proxy_WeakmapKeyDelegate \ + } + +#define PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, ext) \ + { \ + name, \ + js::Class::NON_NATIVE | \ + JSCLASS_IS_PROXY | \ + JSCLASS_IMPLEMENTS_BARRIERS | \ + JSCLASS_HAS_RESERVED_SLOTS(js::PROXY_MINIMUM_SLOTS + (extraSlots)) | \ + flags, \ + JS_PropertyStub, /* addProperty */ \ + JS_DeletePropertyStub, /* delProperty */ \ + JS_PropertyStub, /* getProperty */ \ + JS_StrictPropertyStub, /* setProperty */ \ + JS_EnumerateStub, \ + JS_ResolveStub, \ + js::proxy_Convert, \ + js::proxy_Finalize, /* finalize */ \ + callOp, /* call */ \ + js::proxy_HasInstance, /* hasInstance */ \ + constructOp, /* construct */ \ + js::proxy_Trace, /* trace */ \ + JS_NULL_CLASS_SPEC, \ + ext, \ + { \ + js::proxy_LookupGeneric, \ + js::proxy_LookupProperty, \ + js::proxy_LookupElement, \ + js::proxy_DefineGeneric, \ + js::proxy_DefineProperty, \ + js::proxy_DefineElement, \ + js::proxy_GetGeneric, \ + js::proxy_GetProperty, \ + js::proxy_GetElement, \ + js::proxy_SetGeneric, \ + js::proxy_SetProperty, \ + js::proxy_SetElement, \ + js::proxy_GetGenericAttributes, \ + js::proxy_SetGenericAttributes, \ + js::proxy_DeleteGeneric, \ + js::proxy_Watch, js::proxy_Unwatch, \ + js::proxy_Slice, \ + nullptr, /* enumerate */ \ + nullptr, /* thisObject */ \ + } \ + } + +#define PROXY_CLASS_DEF(name, extraSlots, flags, callOp, constructOp) \ + PROXY_CLASS_WITH_EXT(name, extraSlots, flags, callOp, constructOp, \ + PROXY_MAKE_EXT( \ + nullptr, /* outerObject */ \ + nullptr, /* innerObject */ \ + nullptr, /* iteratorObject */ \ + false /* isWrappedNative */ \ + )) + +/* + * Proxy stubs, similar to JS_*Stub, for embedder proxy class definitions. + * + * NB: Should not be called directly. + */ + +extern JS_FRIEND_API(bool) +proxy_LookupGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleObject objp, JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleObject objp, + JS::MutableHandle propp); +extern JS_FRIEND_API(bool) +proxy_DefineGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::HandleValue value, JSPropertyOp getter, JSStrictPropertyOp setter, + unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +extern JS_FRIEND_API(bool) +proxy_GetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetProperty(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, + JS::Handle name, JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_GetElement(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index, + JS::MutableHandleValue vp); +extern JS_FRIEND_API(bool) +proxy_SetGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetProperty(JSContext *cx, JS::HandleObject obj, JS::Handle name, + JS::MutableHandleValue bp, bool strict); +extern JS_FRIEND_API(bool) +proxy_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp, + bool strict); +extern JS_FRIEND_API(bool) +proxy_GetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_SetGenericAttributes(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned *attrsp); +extern JS_FRIEND_API(bool) +proxy_DeleteGeneric(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); + +extern JS_FRIEND_API(void) +proxy_Trace(JSTracer *trc, JSObject *obj); +extern JS_FRIEND_API(JSObject *) +proxy_WeakmapKeyDelegate(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Convert(JSContext *cx, JS::HandleObject proxy, JSType hint, JS::MutableHandleValue vp); +extern JS_FRIEND_API(void) +proxy_Finalize(FreeOp *fop, JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_HasInstance(JSContext *cx, JS::HandleObject proxy, JS::MutableHandleValue v, bool *bp); +extern JS_FRIEND_API(bool) +proxy_Call(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(bool) +proxy_Construct(JSContext *cx, unsigned argc, JS::Value *vp); +extern JS_FRIEND_API(JSObject *) +proxy_innerObject(JSObject *obj); +extern JS_FRIEND_API(bool) +proxy_Watch(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); +extern JS_FRIEND_API(bool) +proxy_Unwatch(JSContext *cx, JS::HandleObject obj, JS::HandleId id); +extern JS_FRIEND_API(bool) +proxy_Slice(JSContext *cx, JS::HandleObject proxy, uint32_t begin, uint32_t end, + JS::HandleObject result); + +/* + * A class of objects that return source code on demand. + * + * When code is compiled with setSourceIsLazy(true), SpiderMonkey doesn't + * retain the source code (and doesn't do lazy bytecode generation). If we ever + * need the source code, say, in response to a call to Function.prototype. + * toSource or Debugger.Source.prototype.text, then we call the 'load' member + * function of the instance of this class that has hopefully been registered + * with the runtime, passing the code's URL, and hope that it will be able to + * find the source. + */ +class SourceHook { + public: + virtual ~SourceHook() { } + + /* + * Set |*src| and |*length| to refer to the source code for |filename|. + * On success, the caller owns the buffer to which |*src| points, and + * should use JS_free to free it. + */ + virtual bool load(JSContext *cx, const char *filename, jschar **src, size_t *length) = 0; +}; + +/* + * Have |rt| use |hook| to retrieve lazily-retrieved source code. See the + * comments for SourceHook. The runtime takes ownership of the hook, and + * will delete it when the runtime itself is deleted, or when a new hook is + * set. + */ +extern JS_FRIEND_API(void) +SetSourceHook(JSRuntime *rt, mozilla::UniquePtr hook); + +/* Remove |rt|'s source hook, and return it. The caller now owns the hook. */ +extern JS_FRIEND_API(mozilla::UniquePtr) +ForgetSourceHook(JSRuntime *rt); + +#ifdef NIGHTLY_BUILD +typedef void (*AssertOnScriptEntryHook)(JSContext *cx, JS::HandleScript script); + +extern JS_FRIEND_API(void) +SetAssertOnScriptEntryHook(JSRuntime *rt, AssertOnScriptEntryHook hook); +#endif + +extern JS_FRIEND_API(JS::Zone *) +GetCompartmentZone(JSCompartment *comp); + +typedef bool +(* PreserveWrapperCallback)(JSContext *cx, JSObject *obj); + +typedef enum { + CollectNurseryBeforeDump, + IgnoreNurseryObjects +} DumpHeapNurseryBehaviour; + + /* + * Dump the complete object graph of heap-allocated things. + * fp is the file for the dump output. + */ +extern JS_FRIEND_API(void) +DumpHeapComplete(JSRuntime *rt, FILE *fp, DumpHeapNurseryBehaviour nurseryBehaviour); + +#ifdef JS_OLD_GETTER_SETTER_METHODS +JS_FRIEND_API(bool) obj_defineGetter(JSContext *cx, unsigned argc, JS::Value *vp); +JS_FRIEND_API(bool) obj_defineSetter(JSContext *cx, unsigned argc, JS::Value *vp); +#endif + +extern JS_FRIEND_API(bool) +IsSystemCompartment(JSCompartment *comp); + +extern JS_FRIEND_API(bool) +IsSystemZone(JS::Zone *zone); + +extern JS_FRIEND_API(bool) +IsAtomsCompartment(JSCompartment *comp); + +/* + * Returns whether we're in a non-strict property set (in that we're in a + * non-strict script and the bytecode we're on is a property set). The return + * value does NOT indicate any sort of exception was thrown: it's just a + * boolean. + */ +extern JS_FRIEND_API(bool) +IsInNonStrictPropertySet(JSContext *cx); + +struct WeakMapTracer; + +/* + * Weak map tracer callback, called once for every binding of every + * weak map that was live at the time of the last garbage collection. + * + * m will be nullptr if the weak map is not contained in a JS Object. + */ +typedef void +(* WeakMapTraceCallback)(WeakMapTracer *trc, JSObject *m, + void *k, JSGCTraceKind kkind, + void *v, JSGCTraceKind vkind); + +struct WeakMapTracer { + JSRuntime *runtime; + WeakMapTraceCallback callback; + + WeakMapTracer(JSRuntime *rt, WeakMapTraceCallback cb) + : runtime(rt), callback(cb) {} +}; + +extern JS_FRIEND_API(void) +TraceWeakMaps(WeakMapTracer *trc); + +extern JS_FRIEND_API(bool) +AreGCGrayBitsValid(JSRuntime *rt); + +extern JS_FRIEND_API(bool) +ZoneGlobalsAreAllGray(JS::Zone *zone); + +typedef void +(*GCThingCallback)(void *closure, void *gcthing); + +extern JS_FRIEND_API(void) +VisitGrayWrapperTargets(JS::Zone *zone, GCThingCallback callback, void *closure); + +extern JS_FRIEND_API(JSObject *) +GetWeakmapKeyDelegate(JSObject *key); + +JS_FRIEND_API(JSGCTraceKind) +GCThingTraceKind(void *thing); + +/* + * Invoke cellCallback on every gray JS_OBJECT in the given zone. + */ +extern JS_FRIEND_API(void) +IterateGrayObjects(JS::Zone *zone, GCThingCallback cellCallback, void *data); + +#ifdef JS_HAS_CTYPES +extern JS_FRIEND_API(size_t) +SizeOfDataIfCDataObject(mozilla::MallocSizeOf mallocSizeOf, JSObject *obj); +#endif + +extern JS_FRIEND_API(JSCompartment *) +GetAnyCompartmentInZone(JS::Zone *zone); + +/* + * Shadow declarations of JS internal structures, for access by inline access + * functions below. Do not use these structures in any other way. When adding + * new fields for access by inline methods, make sure to add static asserts to + * the original header file to ensure that offsets are consistent. + */ +namespace shadow { + +struct TypeObject { + const Class *clasp; + JSObject *proto; +}; + +struct BaseShape { + const js::Class *clasp_; + JSObject *parent; + JSObject *_1; + JSCompartment *compartment; +}; + +class Shape { +public: + shadow::BaseShape *base; + jsid _1; + uint32_t slotInfo; + + static const uint32_t FIXED_SLOTS_SHIFT = 27; +}; + +struct Object { + shadow::Shape *shape; + shadow::TypeObject *type; + JS::Value *slots; + JS::Value *_1; + + size_t numFixedSlots() const { return shape->slotInfo >> Shape::FIXED_SLOTS_SHIFT; } + JS::Value *fixedSlots() const { + return (JS::Value *)(uintptr_t(this) + sizeof(shadow::Object)); + } + + JS::Value &slotRef(size_t slot) const { + size_t nfixed = numFixedSlots(); + if (slot < nfixed) + return fixedSlots()[slot]; + return slots[slot - nfixed]; + } + + // Reserved slots with index < MAX_FIXED_SLOTS are guaranteed to + // be fixed slots. + static const uint32_t MAX_FIXED_SLOTS = 16; +}; + +struct Function { + Object base; + uint16_t nargs; + uint16_t flags; + /* Used only for natives */ + JSNative native; + const JSJitInfo *jitinfo; + void *_1; +}; + +struct String +{ + static const uint32_t INLINE_CHARS_BIT = JS_BIT(2); + static const uint32_t LATIN1_CHARS_BIT = JS_BIT(6); + static const uint32_t ROPE_FLAGS = 0; + static const uint32_t TYPE_FLAGS_MASK = JS_BIT(6) - 1; + uint32_t flags; + uint32_t length; + union { + const JS::Latin1Char *nonInlineCharsLatin1; + const jschar *nonInlineCharsTwoByte; + JS::Latin1Char inlineStorageLatin1[1]; + jschar inlineStorageTwoByte[1]; + }; +}; + +} /* namespace shadow */ + +// This is equal to |&JSObject::class_|. Use it in places where you don't want +// to #include jsobj.h. +extern JS_FRIEND_DATA(const js::Class* const) ObjectClassPtr; + +inline const js::Class * +GetObjectClass(JSObject *obj) +{ + return reinterpret_cast(obj)->type->clasp; +} + +inline const JSClass * +GetObjectJSClass(JSObject *obj) +{ + return js::Jsvalify(GetObjectClass(obj)); +} + +JS_FRIEND_API(const Class *) +ProtoKeyToClass(JSProtoKey key); + +// Returns true if the standard class identified by |key| inherits from +// another standard class with the same js::Class. This basically means +// that the various properties described by our js::Class are intended +// to live higher up on the proto chain. +// +// In practice, this only returns true for Error subtypes. +inline bool +StandardClassIsDependent(JSProtoKey key) +{ + JSProtoKey keyFromClass = JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + MOZ_ASSERT(keyFromClass); + return key != keyFromClass; +} + +// Returns the key for the class inherited by a given standard class (that +// is to say, the prototype of this standard class's prototype). +// +// You must be sure that this corresponds to a standard class with a cached +// JSProtoKey before calling this function. In general |key| will match the +// cached proto key, except in cases where multiple JSProtoKeys share a +// JSClass. +inline JSProtoKey +ParentKeyForStandardClass(JSProtoKey key) +{ + // [Object] has nothing to inherit from. + if (key == JSProto_Object) + return JSProto_Null; + + // If we're dependent (i.e. an Error subtype), return the key of the class + // we depend on. + if (StandardClassIsDependent(key)) + return JSCLASS_CACHED_PROTO_KEY(ProtoKeyToClass(key)); + + // Otherwise, we inherit [Object]. + return JSProto_Object; +} + +inline bool +IsInnerObject(JSObject *obj) { + return !!GetObjectClass(obj)->ext.outerObject; +} + +inline bool +IsOuterObject(JSObject *obj) { + return !!GetObjectClass(obj)->ext.innerObject; +} + +JS_FRIEND_API(bool) +IsFunctionObject(JSObject *obj); + +JS_FRIEND_API(bool) +IsScopeObject(JSObject *obj); + +JS_FRIEND_API(bool) +IsCallObject(JSObject *obj); + +inline JSObject * +GetObjectParent(JSObject *obj) +{ + JS_ASSERT(!IsScopeObject(obj)); + return reinterpret_cast(obj)->shape->base->parent; +} + +static MOZ_ALWAYS_INLINE JSCompartment * +GetObjectCompartment(JSObject *obj) +{ + return reinterpret_cast(obj)->shape->base->compartment; +} + +JS_FRIEND_API(JSObject *) +GetObjectParentMaybeScope(JSObject *obj); + +JS_FRIEND_API(JSObject *) +GetGlobalForObjectCrossCompartment(JSObject *obj); + +// Sidestep the activeContext checking implicitly performed in +// JS_SetPendingException. +JS_FRIEND_API(void) +SetPendingExceptionCrossContext(JSContext *cx, JS::HandleValue v); + +JS_FRIEND_API(void) +AssertSameCompartment(JSContext *cx, JSObject *obj); + +#ifdef JS_DEBUG +JS_FRIEND_API(void) +AssertSameCompartment(JSObject *objA, JSObject *objB); +#else +inline void AssertSameCompartment(JSObject *objA, JSObject *objB) {} +#endif + +// For legacy consumers only. This whole concept is going away soon. +JS_FRIEND_API(JSObject *) +DefaultObjectForContextOrNull(JSContext *cx); + +JS_FRIEND_API(void) +SetDefaultObjectForContext(JSContext *cx, JSObject *obj); + +JS_FRIEND_API(void) +NotifyAnimationActivity(JSObject *obj); + +/* + * Return the outermost enclosing function (script) of the scripted caller. + * This function returns nullptr in several cases: + * - no script is running on the context + * - the caller is in global or eval code + * In particular, this function will "stop" its outermost search at eval() and + * thus it will really return the outermost enclosing function *since the + * innermost eval*. + */ +JS_FRIEND_API(JSFunction *) +GetOutermostEnclosingFunctionOfScriptedCaller(JSContext *cx); + +JS_FRIEND_API(JSFunction *) +DefineFunctionWithReserved(JSContext *cx, JSObject *obj, const char *name, JSNative call, + unsigned nargs, unsigned attrs); + +JS_FRIEND_API(JSFunction *) +NewFunctionWithReserved(JSContext *cx, JSNative call, unsigned nargs, unsigned flags, + JSObject *parent, const char *name); + +JS_FRIEND_API(JSFunction *) +NewFunctionByIdWithReserved(JSContext *cx, JSNative native, unsigned nargs, unsigned flags, + JSObject *parent, jsid id); + +JS_FRIEND_API(const JS::Value &) +GetFunctionNativeReserved(JSObject *fun, size_t which); + +JS_FRIEND_API(void) +SetFunctionNativeReserved(JSObject *fun, size_t which, const JS::Value &val); + +JS_FRIEND_API(bool) +GetObjectProto(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject proto); + +JS_FRIEND_API(bool) +GetOriginalEval(JSContext *cx, JS::HandleObject scope, + JS::MutableHandleObject eval); + +inline void * +GetObjectPrivate(JSObject *obj) +{ + const shadow::Object *nobj = reinterpret_cast(obj); + void **addr = reinterpret_cast(&nobj->fixedSlots()[nobj->numFixedSlots()]); + return *addr; +} + +/* + * Get a slot that is both reserved for object's clasp *and* is fixed (fits + * within the maximum capacity for the object's fixed slots). + */ +inline const JS::Value & +GetReservedSlot(JSObject *obj, size_t slot) +{ + JS_ASSERT(slot < JSCLASS_RESERVED_SLOTS(GetObjectClass(obj))); + return reinterpret_cast(obj)->slotRef(slot); +} + +JS_FRIEND_API(void) +SetReservedSlotWithBarrier(JSObject *obj, size_t slot, const JS::Value &value); + +inline void +SetReservedSlot(JSObject *obj, size_t slot, const JS::Value &value) +{ + JS_ASSERT(slot < JSCLASS_RESERVED_SLOTS(GetObjectClass(obj))); + shadow::Object *sobj = reinterpret_cast(obj); + if (sobj->slotRef(slot).isMarkable() +#ifdef JSGC_GENERATIONAL + || value.isMarkable() +#endif + ) + { + SetReservedSlotWithBarrier(obj, slot, value); + } else { + sobj->slotRef(slot) = value; + } +} + +JS_FRIEND_API(uint32_t) +GetObjectSlotSpan(JSObject *obj); + +inline const JS::Value & +GetObjectSlot(JSObject *obj, size_t slot) +{ + JS_ASSERT(slot < GetObjectSlotSpan(obj)); + return reinterpret_cast(obj)->slotRef(slot); +} + +MOZ_ALWAYS_INLINE size_t +GetAtomLength(JSAtom *atom) +{ + return reinterpret_cast(atom)->length; +} + +static const uint32_t MaxStringLength = (1 << 28) - 1; + +MOZ_ALWAYS_INLINE size_t +GetStringLength(JSString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetFlatStringLength(JSFlatString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE size_t +GetLinearStringLength(JSLinearString *s) +{ + return reinterpret_cast(s)->length; +} + +MOZ_ALWAYS_INLINE bool +LinearStringHasLatin1Chars(JSLinearString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE bool +AtomHasLatin1Chars(JSAtom *atom) +{ + return reinterpret_cast(atom)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE bool +StringHasLatin1Chars(JSString *s) +{ + return reinterpret_cast(s)->flags & shadow::String::LATIN1_CHARS_BIT; +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1LinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageLatin1; + return s->nonInlineCharsLatin1; +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteLinearStringChars(const JS::AutoCheckCannotGC &nogc, JSLinearString *linear) +{ + MOZ_ASSERT(!LinearStringHasLatin1Chars(linear)); + + using shadow::String; + String *s = reinterpret_cast(linear); + if (s->flags & String::INLINE_CHARS_BIT) + return s->inlineStorageTwoByte; + return s->nonInlineCharsTwoByte; +} + +MOZ_ALWAYS_INLINE JSLinearString * +AtomToLinearString(JSAtom *atom) +{ + return reinterpret_cast(atom); +} + +MOZ_ALWAYS_INLINE JSLinearString * +FlatStringToLinearString(JSFlatString *s) +{ + return reinterpret_cast(s); +} + +MOZ_ALWAYS_INLINE const JS::Latin1Char * +GetLatin1AtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetLatin1LinearStringChars(nogc, AtomToLinearString(atom)); +} + +MOZ_ALWAYS_INLINE const jschar * +GetTwoByteAtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom) +{ + return GetTwoByteLinearStringChars(nogc, AtomToLinearString(atom)); +} + +JS_FRIEND_API(JSLinearString *) +StringToLinearStringSlow(JSContext *cx, JSString *str); + +MOZ_ALWAYS_INLINE JSLinearString * +StringToLinearString(JSContext *cx, JSString *str) +{ + using shadow::String; + String *s = reinterpret_cast(str); + if (MOZ_UNLIKELY((s->flags & String::TYPE_FLAGS_MASK) == String::ROPE_FLAGS)) + return StringToLinearStringSlow(cx, str); + return reinterpret_cast(str); +} + +MOZ_ALWAYS_INLINE void +CopyLinearStringChars(jschar *dest, JSLinearString *s, size_t len) +{ + JS::AutoCheckCannotGC nogc; + if (LinearStringHasLatin1Chars(s)) { + const JS::Latin1Char *src = GetLatin1LinearStringChars(nogc, s); + for (size_t i = 0; i < len; i++) + dest[i] = src[i]; + } else { + const jschar *src = GetTwoByteLinearStringChars(nogc, s); + mozilla::PodCopy(dest, src, len); + } +} + +inline bool +CopyStringChars(JSContext *cx, jschar *dest, JSString *s, size_t len) +{ + JSLinearString *linear = StringToLinearString(cx, s); + if (!linear) + return false; + + CopyLinearStringChars(dest, linear, len); + return true; +} + +inline void +CopyFlatStringChars(jschar *dest, JSFlatString *s, size_t len) +{ + CopyLinearStringChars(dest, FlatStringToLinearString(s), len); +} + +JS_FRIEND_API(bool) +GetPropertyNames(JSContext *cx, JSObject *obj, unsigned flags, JS::AutoIdVector *props); + +JS_FRIEND_API(bool) +AppendUnique(JSContext *cx, JS::AutoIdVector &base, JS::AutoIdVector &others); + +JS_FRIEND_API(bool) +GetGeneric(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id, JS::Value *vp); + +JS_FRIEND_API(bool) +StringIsArrayIndex(JSLinearString *str, uint32_t *indexp); + +JS_FRIEND_API(void) +SetPreserveWrapperCallback(JSRuntime *rt, PreserveWrapperCallback callback); + +JS_FRIEND_API(bool) +IsObjectInContextCompartment(JSObject *obj, const JSContext *cx); + +/* + * NB: these flag bits are encoded into the bytecode stream in the immediate + * operand of JSOP_ITER, so don't change them without advancing vm/Xdr.h's + * XDR_BYTECODE_VERSION. + */ +#define JSITER_ENUMERATE 0x1 /* for-in compatible hidden default iterator */ +#define JSITER_FOREACH 0x2 /* get obj[key] for each property */ +#define JSITER_KEYVALUE 0x4 /* obsolete destructuring for-in wants [key, value] */ +#define JSITER_OWNONLY 0x8 /* iterate over obj's own properties only */ +#define JSITER_HIDDEN 0x10 /* also enumerate non-enumerable properties */ +#define JSITER_SYMBOLS 0x20 /* also include symbol property keys */ +#define JSITER_SYMBOLSONLY 0x40 /* exclude string property keys */ + +JS_FRIEND_API(bool) +RunningWithTrustedPrincipals(JSContext *cx); + +inline uintptr_t +GetNativeStackLimit(JSContext *cx) +{ + StackKind kind = RunningWithTrustedPrincipals(cx) ? StackForTrustedScript + : StackForUntrustedScript; + PerThreadDataFriendFields *mainThread = + PerThreadDataFriendFields::getMainThread(GetRuntime(cx)); + return mainThread->nativeStackLimit[kind]; +} + +/* + * These macros report a stack overflow and run |onerror| if we are close to + * using up the C stack. The JS_CHECK_CHROME_RECURSION variant gives us a little + * extra space so that we can ensure that crucial code is able to run. + * JS_CHECK_RECURSION_CONSERVATIVE gives us a little less space. + */ + +#define JS_CHECK_RECURSION(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), &stackDummy_)) { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_RECURSION_DONT_REPORT(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), &stackDummy_)) { \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_RECURSION_WITH_SP_DONT_REPORT(cx, sp, onerror) \ + JS_BEGIN_MACRO \ + if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), sp)) { \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_RECURSION_WITH_SP(cx, sp, onerror) \ + JS_BEGIN_MACRO \ + if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), sp)) { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_CHROME_RECURSION(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE_WITH_TOLERANCE(js::GetNativeStackLimit(cx), \ + &stackDummy_, \ + 1024 * sizeof(size_t))) \ + { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + +#define JS_CHECK_RECURSION_CONSERVATIVE(cx, onerror) \ + JS_BEGIN_MACRO \ + int stackDummy_; \ + if (!JS_CHECK_STACK_SIZE_WITH_INTOLERANCE(js::GetNativeStackLimit(cx), \ + &stackDummy_, \ + 1024 * sizeof(size_t))) \ + { \ + js_ReportOverRecursed(cx); \ + onerror; \ + } \ + JS_END_MACRO + +JS_FRIEND_API(void) +StartPCCountProfiling(JSContext *cx); + +JS_FRIEND_API(void) +StopPCCountProfiling(JSContext *cx); + +JS_FRIEND_API(void) +PurgePCCounts(JSContext *cx); + +JS_FRIEND_API(size_t) +GetPCCountScriptCount(JSContext *cx); + +JS_FRIEND_API(JSString *) +GetPCCountScriptSummary(JSContext *cx, size_t script); + +JS_FRIEND_API(JSString *) +GetPCCountScriptContents(JSContext *cx, size_t script); + +#ifdef JS_THREADSAFE +JS_FRIEND_API(bool) +ContextHasOutstandingRequests(const JSContext *cx); +#endif + +typedef void +(* ActivityCallback)(void *arg, bool active); + +/* + * Sets a callback that is run whenever the runtime goes idle - the + * last active request ceases - and begins activity - when it was + * idle and a request begins. + */ +JS_FRIEND_API(void) +SetActivityCallback(JSRuntime *rt, ActivityCallback cb, void *arg); + +extern JS_FRIEND_API(const JSStructuredCloneCallbacks *) +GetContextStructuredCloneCallbacks(JSContext *cx); + +extern JS_FRIEND_API(bool) +IsContextRunningJS(JSContext *cx); + +typedef bool +(* DOMInstanceClassHasProtoAtDepth)(const Class *instanceClass, + uint32_t protoID, uint32_t depth); +struct JSDOMCallbacks { + DOMInstanceClassHasProtoAtDepth instanceClassMatchesProto; +}; +typedef struct JSDOMCallbacks DOMCallbacks; + +extern JS_FRIEND_API(void) +SetDOMCallbacks(JSRuntime *rt, const DOMCallbacks *callbacks); + +extern JS_FRIEND_API(const DOMCallbacks *) +GetDOMCallbacks(JSRuntime *rt); + +extern JS_FRIEND_API(JSObject *) +GetTestingFunctions(JSContext *cx); + +/* + * Helper to convert FreeOp to JSFreeOp when the definition of FreeOp is not + * available and the compiler does not know that FreeOp inherits from + * JSFreeOp. + */ +inline JSFreeOp * +CastToJSFreeOp(FreeOp *fop) +{ + return reinterpret_cast(fop); +} + +/* Implemented in jsexn.cpp. */ + +/* + * Get an error type name from a JSExnType constant. + * Returns nullptr for invalid arguments and JSEXN_INTERNALERR + */ +extern JS_FRIEND_API(JSFlatString *) +GetErrorTypeName(JSRuntime *rt, int16_t exnType); + +#ifdef JS_DEBUG +extern JS_FRIEND_API(unsigned) +GetEnterCompartmentDepth(JSContext* cx); +#endif + +/* Implemented in jswrapper.cpp. */ +typedef enum NukeReferencesToWindow { + NukeWindowReferences, + DontNukeWindowReferences +} NukeReferencesToWindow; + +/* + * These filters are designed to be ephemeral stack classes, and thus don't + * do any rooting or holding of their members. + */ +struct CompartmentFilter { + virtual bool match(JSCompartment *c) const = 0; +}; + +struct AllCompartments : public CompartmentFilter { + virtual bool match(JSCompartment *c) const { return true; } +}; + +struct ContentCompartmentsOnly : public CompartmentFilter { + virtual bool match(JSCompartment *c) const { + return !IsSystemCompartment(c); + } +}; + +struct ChromeCompartmentsOnly : public CompartmentFilter { + virtual bool match(JSCompartment *c) const { + return IsSystemCompartment(c); + } +}; + +struct SingleCompartment : public CompartmentFilter { + JSCompartment *ours; + explicit SingleCompartment(JSCompartment *c) : ours(c) {} + virtual bool match(JSCompartment *c) const { return c == ours; } +}; + +struct CompartmentsWithPrincipals : public CompartmentFilter { + JSPrincipals *principals; + explicit CompartmentsWithPrincipals(JSPrincipals *p) : principals(p) {} + virtual bool match(JSCompartment *c) const { + return JS_GetCompartmentPrincipals(c) == principals; + } +}; + +extern JS_FRIEND_API(bool) +NukeCrossCompartmentWrappers(JSContext* cx, + const CompartmentFilter& sourceFilter, + const CompartmentFilter& targetFilter, + NukeReferencesToWindow nukeReferencesToWindow); + +/* Specify information about DOMProxy proxies in the DOM, for use by ICs. */ + +/* + * The DOMProxyShadowsCheck function will be called to check if the property for + * id should be gotten from the prototype, or if there is an own property that + * shadows it. + * If DoesntShadow is returned then the slot at listBaseExpandoSlot should + * either be undefined or point to an expando object that would contain the own + * property. + * If DoesntShadowUnique is returned then the slot at listBaseExpandoSlot should + * contain a private pointer to a ExpandoAndGeneration, which contains a + * JS::Value that should either be undefined or point to an expando object, and + * a uint32 value. If that value changes then the IC for getting a property will + * be invalidated. + */ + +struct ExpandoAndGeneration { + ExpandoAndGeneration() + : expando(JS::UndefinedValue()), + generation(0) + {} + + void Unlink() + { + ++generation; + expando.setUndefined(); + } + + static size_t offsetOfExpando() + { + return offsetof(ExpandoAndGeneration, expando); + } + + static size_t offsetOfGeneration() + { + return offsetof(ExpandoAndGeneration, generation); + } + + JS::Heap expando; + uint32_t generation; +}; + +typedef enum DOMProxyShadowsResult { + ShadowCheckFailed, + Shadows, + DoesntShadow, + DoesntShadowUnique +} DOMProxyShadowsResult; +typedef DOMProxyShadowsResult +(* DOMProxyShadowsCheck)(JSContext* cx, JS::HandleObject object, JS::HandleId id); +JS_FRIEND_API(void) +SetDOMProxyInformation(const void *domProxyHandlerFamily, uint32_t domProxyExpandoSlot, + DOMProxyShadowsCheck domProxyShadowsCheck); + +const void *GetDOMProxyHandlerFamily(); +uint32_t GetDOMProxyExpandoSlot(); +DOMProxyShadowsCheck GetDOMProxyShadowsCheck(); + +} /* namespace js */ + +/* Implemented in jsdate.cpp. */ + +/* + * Detect whether the internal date value is NaN. (Because failure is + * out-of-band for js_DateGet*) + */ +extern JS_FRIEND_API(bool) +js_DateIsValid(JSObject* obj); + +extern JS_FRIEND_API(double) +js_DateGetMsecSinceEpoch(JSObject *obj); + +/* Implemented in jscntxt.cpp. */ + +/* + * Report an exception, which is currently realized as a printf-style format + * string and its arguments. + */ +typedef enum JSErrNum { +#define MSG_DEF(name, number, count, exception, format) \ + name = number, +#include "js.msg" +#undef MSG_DEF + JSErr_Limit +} JSErrNum; + +extern JS_FRIEND_API(const JSErrorFormatString *) +js_GetErrorMessage(void *userRef, const unsigned errorNumber); + +namespace js { + +// AutoStableStringChars is here so we can use it in ErrorReport. It +// should get moved out of here if we can manage it. See bug 1040316. + +/* + * This class provides safe access to a string's chars across a GC. Once + * we allocate strings and chars in the nursery (bug 903519), this class + * will have to make a copy of the string's chars if they are allocated + * in the nursery, so it's best to avoid using this class unless you really + * need it. It's usually more efficient to use the latin1Chars/twoByteChars + * JSString methods and often the code can be rewritten so that only indexes + * instead of char pointers are used in parts of the code that can GC. + */ +class MOZ_STACK_CLASS AutoStableStringChars +{ + /* Ensure the string is kept alive while we're using its chars. */ + JS::RootedString s_; + union { + const jschar *twoByteChars_; + const JS::Latin1Char *latin1Chars_; + }; + enum State { Uninitialized, Latin1, TwoByte }; + State state_; + bool ownsChars_; + + public: + AutoStableStringChars(JSContext *cx) + : s_(cx), state_(Uninitialized), ownsChars_(false) + {}; + ~AutoStableStringChars(); + + bool init(JSContext *cx, JSString *s); + + /* Like init(), but Latin1 chars are inflated to TwoByte. */ + bool initTwoByte(JSContext *cx, JSString *s); + + bool isLatin1() const { return state_ == Latin1; } + bool isTwoByte() const { return state_ == TwoByte; } + + const jschar *twoByteChars() const { + MOZ_ASSERT(state_ == TwoByte); + return twoByteChars_; + } + + mozilla::Range latin1Range() const { + MOZ_ASSERT(state_ == Latin1); + return mozilla::Range(latin1Chars_, + GetStringLength(s_)); + } + + mozilla::Range twoByteRange() const { + MOZ_ASSERT(state_ == TwoByte); + return mozilla::Range(twoByteChars_, + GetStringLength(s_)); + } + + /* If we own the chars, transfer ownership to the caller. */ + bool maybeGiveOwnershipToCaller() { + MOZ_ASSERT(state_ != Uninitialized); + if (!ownsChars_) + return false; + state_ = Uninitialized; + ownsChars_ = false; + return true; + } + + private: + AutoStableStringChars(const AutoStableStringChars &other) MOZ_DELETE; + void operator=(const AutoStableStringChars &other) MOZ_DELETE; +}; + +// Creates a string of the form |ErrorType: ErrorMessage| for a JSErrorReport, +// which generally matches the toString() behavior of an ErrorObject. +extern JS_FRIEND_API(JSString *) +ErrorReportToString(JSContext *cx, JSErrorReport *reportp); + +struct MOZ_STACK_CLASS JS_FRIEND_API(ErrorReport) +{ + ErrorReport(JSContext *cx); + ~ErrorReport(); + + bool init(JSContext *cx, JS::HandleValue exn); + + JSErrorReport *report() + { + return reportp; + } + + const char *message() + { + return message_; + } + + private: + // More or less an equivalent of JS_ReportErrorNumber/js_ReportErrorNumberVA + // but fills in an ErrorReport instead of reporting it. Uses varargs to + // make it simpler to call js_ExpandErrorArguments. + void populateUncaughtExceptionReport(JSContext *cx, ...); + void populateUncaughtExceptionReportVA(JSContext *cx, va_list ap); + + // We may have a provided JSErrorReport, so need a way to represent that. + JSErrorReport *reportp; + + // And we may have a message. + const char *message_; + + // Or we may need to synthesize a JSErrorReport one of our own. + JSErrorReport ownedReport; + + // Or a message of our own. If this is non-null, we need to clean up both + // it and ownedReport. + char *ownedMessage; + + // And we have a string to maybe keep alive that has pointers into + // it from ownedReport. + JS::RootedString str; + + // And keep its chars alive too. + AutoStableStringChars strChars; + + // And we need to root our exception value. + JS::RootedObject exnObject; + + // And possibly some byte storage for our message_. + JSAutoByteString bytesStorage; + + // And for our filename. + JSAutoByteString filename; + + // True if we need to free message_ and the stuff in ownedReport + bool ownsMessageAndReport; +}; + +} /* namespace js */ + + +/* Implemented in jsclone.cpp. */ + +extern JS_FRIEND_API(uint64_t) +js_GetSCOffset(JSStructuredCloneWriter* writer); + +namespace js { +namespace Scalar { + +/* Scalar types which can appear in typed arrays and typed objects. */ +enum Type { + Int8 = 0, + Uint8, + Int16, + Uint16, + Int32, + Uint32, + Float32, + Float64, + + /* + * Special type that is a uint8_t, but assignments are clamped to [0, 256). + * Treat the raw data type as a uint8_t. + */ + Uint8Clamped, + + TypeMax +}; + +static inline size_t +byteSize(Type atype) +{ + switch (atype) { + case Int8: + case Uint8: + case Uint8Clamped: + return 1; + case Int16: + case Uint16: + return 2; + case Int32: + case Uint32: + case Float32: + return 4; + case Float64: + return 8; + default: + MOZ_CRASH("invalid scalar type"); + } +} + +} /* namespace Scalar */ +} /* namespace js */ + +/* + * Create a new typed array with nelements elements. + * + * These functions (except the WithBuffer variants) fill in the array with zeros. + */ + +extern JS_FRIEND_API(JSObject *) +JS_NewInt8Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ClampedArray(JSContext *cx, uint32_t nelements); + +extern JS_FRIEND_API(JSObject *) +JS_NewInt16Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewUint16Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewInt32Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewUint32Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat32Array(JSContext *cx, uint32_t nelements); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat64Array(JSContext *cx, uint32_t nelements); + +/* + * Create a new typed array and copy in values from the given object. The + * object is used as if it were an array; that is, the new array (if + * successfully created) will have length given by array.length, and its + * elements will be those specified by array[0], array[1], and so on, after + * conversion to the typed array element type. + */ + +extern JS_FRIEND_API(JSObject *) +JS_NewInt8ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ClampedArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewInt16ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewUint16ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewInt32ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewUint32ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat32ArrayFromArray(JSContext *cx, JS::HandleObject array); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat64ArrayFromArray(JSContext *cx, JS::HandleObject array); + +/* + * Create a new typed array using the given ArrayBuffer for storage. The + * length value is optional; if -1 is passed, enough elements to use up the + * remainder of the byte array is used as the default value. + */ + +extern JS_FRIEND_API(JSObject *) +JS_NewInt8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewInt16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewUint16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewInt32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewUint32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); +extern JS_FRIEND_API(JSObject *) +JS_NewFloat64ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer, + uint32_t byteOffset, int32_t length); + +/* + * Create a new ArrayBuffer with the given byte length. + */ +extern JS_FRIEND_API(JSObject *) +JS_NewArrayBuffer(JSContext *cx, uint32_t nbytes); + +/* + * Check whether obj supports JS_GetTypedArray* APIs. Note that this may return + * false if a security wrapper is encountered that denies the unwrapping. If + * this test or one of the JS_Is*Array tests succeeds, then it is safe to call + * the various accessor JSAPI calls defined below. + */ +extern JS_FRIEND_API(bool) +JS_IsTypedArrayObject(JSObject *obj); + +/* + * Check whether obj supports JS_GetArrayBufferView* APIs. Note that this may + * return false if a security wrapper is encountered that denies the + * unwrapping. If this test or one of the more specific tests succeeds, then it + * is safe to call the various ArrayBufferView accessor JSAPI calls defined + * below. + */ +extern JS_FRIEND_API(bool) +JS_IsArrayBufferViewObject(JSObject *obj); + +/* + * Test for specific typed array types (ArrayBufferView subtypes) + */ + +extern JS_FRIEND_API(bool) +JS_IsInt8Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsUint8Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsUint8ClampedArray(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsInt16Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsUint16Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsInt32Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsUint32Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsFloat32Array(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_IsFloat64Array(JSObject *obj); + +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +namespace js { + +extern JS_FRIEND_API(JSObject *) +UnwrapInt8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint8ClampedArray(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint16Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapInt32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapUint32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat32Array(JSObject *obj); +extern JS_FRIEND_API(JSObject *) +UnwrapFloat64Array(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBuffer(JSObject *obj); + +extern JS_FRIEND_API(JSObject *) +UnwrapArrayBufferView(JSObject *obj); + +namespace detail { + +extern JS_FRIEND_DATA(const Class* const) Int8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint8ClampedArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint16ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Int32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Uint32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float32ArrayClassPtr; +extern JS_FRIEND_DATA(const Class* const) Float64ArrayClassPtr; + +const size_t TypedArrayLengthSlot = 1; + +} // namespace detail + +/* + * Test for specific typed array types (ArrayBufferView subtypes) and return + * the unwrapped object if so, else nullptr. Never throws. + */ + +#define JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Type, type) \ +inline void \ +Get ## Type ## ArrayLengthAndData(JSObject *obj, uint32_t *length, type **data) \ +{ \ + JS_ASSERT(GetObjectClass(obj) == detail::Type ## ArrayClassPtr); \ + const JS::Value &slot = GetReservedSlot(obj, detail::TypedArrayLengthSlot); \ + *length = mozilla::SafeCast(slot.toInt32()); \ + *data = static_cast(GetObjectPrivate(obj)); \ +} + +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int8, int8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint8Clamped, uint8_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int16, int16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint16, uint16_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int32, int32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint32, uint32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float32, float) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float64, double) + +#undef JS_DEFINE_DATA_AND_LENGTH_ACCESSOR + +// This one isn't inlined because it's rather tricky (by dint of having to deal +// with a dozen-plus classes and varying slot layouts. +extern JS_FRIEND_API(void) +GetArrayBufferViewLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +// This one isn't inlined because there are a bunch of different ArrayBuffer +// classes that would have to be individually handled here. +extern JS_FRIEND_API(void) +GetArrayBufferLengthAndData(JSObject *obj, uint32_t *length, uint8_t **data); + +} // namespace js + +/* + * Unwrap Typed arrays all at once. Return nullptr without throwing if the + * object cannot be viewed as the correct typed array, or the typed array + * object on success, filling both outparameters. + */ +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsInt8Array(JSObject *obj, uint32_t *length, int8_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsUint8Array(JSObject *obj, uint32_t *length, uint8_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsUint8ClampedArray(JSObject *obj, uint32_t *length, uint8_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsInt16Array(JSObject *obj, uint32_t *length, int16_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsUint16Array(JSObject *obj, uint32_t *length, uint16_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsInt32Array(JSObject *obj, uint32_t *length, int32_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsUint32Array(JSObject *obj, uint32_t *length, uint32_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsFloat32Array(JSObject *obj, uint32_t *length, float **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsFloat64Array(JSObject *obj, uint32_t *length, double **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsArrayBufferView(JSObject *obj, uint32_t *length, uint8_t **data); +extern JS_FRIEND_API(JSObject *) +JS_GetObjectAsArrayBuffer(JSObject *obj, uint32_t *length, uint8_t **data); + +/* + * Get the type of elements in a typed array, or TypeMax if a DataView. + * + * |obj| must have passed a JS_IsArrayBufferView/JS_Is*Array test, or somehow + * be known that it would pass such a test: it is an ArrayBufferView or a + * wrapper of an ArrayBufferView, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(js::Scalar::Type) +JS_GetArrayBufferViewType(JSObject *obj); + +/* + * Check whether obj supports the JS_GetArrayBuffer* APIs. Note that this may + * return false if a security wrapper is encountered that denies the + * unwrapping. If this test succeeds, then it is safe to call the various + * accessor JSAPI calls defined below. + */ +extern JS_FRIEND_API(bool) +JS_IsArrayBufferObject(JSObject *obj); + +/* + * Return the available byte length of an array buffer. + * + * |obj| must have passed a JS_IsArrayBufferObject test, or somehow be known + * that it would pass such a test: it is an ArrayBuffer or a wrapper of an + * ArrayBuffer, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(uint32_t) +JS_GetArrayBufferByteLength(JSObject *obj); + +/* + * Check whether the obj is ArrayBufferObject and memory mapped. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. + */ +extern JS_FRIEND_API(bool) +JS_IsMappedArrayBufferObject(JSObject *obj); + +/* + * Return the number of elements in a typed array. + * + * |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow + * be known that it would pass such a test: it is a typed array or a wrapper of + * a typed array, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(uint32_t) +JS_GetTypedArrayLength(JSObject *obj); + +/* + * Return the byte offset from the start of an array buffer to the start of a + * typed array view. + * + * |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow + * be known that it would pass such a test: it is a typed array or a wrapper of + * a typed array, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(uint32_t) +JS_GetTypedArrayByteOffset(JSObject *obj); + +/* + * Return the byte length of a typed array. + * + * |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow + * be known that it would pass such a test: it is a typed array or a wrapper of + * a typed array, and the unwrapping will succeed. + */ +extern JS_FRIEND_API(uint32_t) +JS_GetTypedArrayByteLength(JSObject *obj); + +/* + * Check whether obj supports JS_ArrayBufferView* APIs. Note that this may + * return false if a security wrapper is encountered that denies the + * unwrapping. + */ +extern JS_FRIEND_API(bool) +JS_IsArrayBufferViewObject(JSObject *obj); + +/* + * More generic name for JS_GetTypedArrayByteLength to cover DataViews as well + */ +extern JS_FRIEND_API(uint32_t) +JS_GetArrayBufferViewByteLength(JSObject *obj); + +/* + * Return a pointer to the start of the data referenced by a typed array. The + * data is still owned by the typed array, and should not be modified on + * another thread. Furthermore, the pointer can become invalid on GC (if the + * data is small and fits inside the array's GC header), so callers must take + * care not to hold on across anything that could GC. + * + * |obj| must have passed a JS_Is*Array test, or somehow be known that it would + * pass such a test: it is a typed array or a wrapper of a typed array, and the + * unwrapping will succeed. + */ + +extern JS_FRIEND_API(uint8_t *) +JS_GetArrayBufferData(JSObject *obj); +extern JS_FRIEND_API(int8_t *) +JS_GetInt8ArrayData(JSObject *obj); +extern JS_FRIEND_API(uint8_t *) +JS_GetUint8ArrayData(JSObject *obj); +extern JS_FRIEND_API(uint8_t *) +JS_GetUint8ClampedArrayData(JSObject *obj); +extern JS_FRIEND_API(int16_t *) +JS_GetInt16ArrayData(JSObject *obj); +extern JS_FRIEND_API(uint16_t *) +JS_GetUint16ArrayData(JSObject *obj); +extern JS_FRIEND_API(int32_t *) +JS_GetInt32ArrayData(JSObject *obj); +extern JS_FRIEND_API(uint32_t *) +JS_GetUint32ArrayData(JSObject *obj); +extern JS_FRIEND_API(float *) +JS_GetFloat32ArrayData(JSObject *obj); +extern JS_FRIEND_API(double *) +JS_GetFloat64ArrayData(JSObject *obj); + +/* + * Stable versions of the above functions where the buffer remains valid as long + * as the object is live. + */ +extern JS_FRIEND_API(uint8_t *) +JS_GetStableArrayBufferData(JSContext *cx, JS::HandleObject obj); + +/* + * Same as above, but for any kind of ArrayBufferView. Prefer the type-specific + * versions when possible. + */ +extern JS_FRIEND_API(void *) +JS_GetArrayBufferViewData(JSObject *obj); + +/* + * Return the ArrayBuffer underlying an ArrayBufferView. If the buffer has been + * neutered, this will still return the neutered buffer. |obj| must be an + * object that would return true for JS_IsArrayBufferViewObject(). + */ +extern JS_FRIEND_API(JSObject *) +JS_GetArrayBufferViewBuffer(JSContext *cx, JS::HandleObject obj); + +typedef enum { + ChangeData, + KeepData +} NeuterDataDisposition; + +/* + * Set an ArrayBuffer's length to 0 and neuter all of its views. + * + * The |changeData| argument is a hint to inform internal behavior with respect + * to the internal pointer to the ArrayBuffer's data after being neutered. + * There is no guarantee it will be respected. But if it is respected, the + * ArrayBuffer's internal data pointer will, or will not, have changed + * accordingly. + */ +extern JS_FRIEND_API(bool) +JS_NeuterArrayBuffer(JSContext *cx, JS::HandleObject obj, + NeuterDataDisposition changeData); + +/* + * Check whether the obj is ArrayBufferObject and neutered. Note that this + * may return false if a security wrapper is encountered that denies the + * unwrapping. + */ +extern JS_FRIEND_API(bool) +JS_IsNeuteredArrayBufferObject(JSObject *obj); + +/* + * Check whether obj supports JS_GetDataView* APIs. + */ +JS_FRIEND_API(bool) +JS_IsDataViewObject(JSObject *obj); + +/* + * Return the byte offset of a data view into its array buffer. |obj| must be a + * DataView. + * + * |obj| must have passed a JS_IsDataViewObject test, or somehow be known that + * it would pass such a test: it is a data view or a wrapper of a data view, + * and the unwrapping will succeed. + */ +JS_FRIEND_API(uint32_t) +JS_GetDataViewByteOffset(JSObject *obj); + +/* + * Return the byte length of a data view. + * + * |obj| must have passed a JS_IsDataViewObject test, or somehow be known that + * it would pass such a test: it is a data view or a wrapper of a data view, + * and the unwrapping will succeed. If cx is nullptr, then DEBUG builds may be + * unable to assert when unwrapping should be disallowed. + */ +JS_FRIEND_API(uint32_t) +JS_GetDataViewByteLength(JSObject *obj); + +/* + * Return a pointer to the beginning of the data referenced by a DataView. + * + * |obj| must have passed a JS_IsDataViewObject test, or somehow be known that + * it would pass such a test: it is a data view or a wrapper of a data view, + * and the unwrapping will succeed. If cx is nullptr, then DEBUG builds may be + * unable to assert when unwrapping should be disallowed. + */ +JS_FRIEND_API(void *) +JS_GetDataViewData(JSObject *obj); + +namespace js { + +/* + * Add a watchpoint -- in the Object.prototype.watch sense -- to |obj| for the + * property |id|, using the callable object |callable| as the function to be + * called for notifications. + * + * This is an internal function exposed -- temporarily -- only so that DOM + * proxies can be watchable. Don't use it! We'll soon kill off the + * Object.prototype.{,un}watch functions, at which point this will go too. + */ +extern JS_FRIEND_API(bool) +WatchGuts(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); + +/* + * Remove a watchpoint -- in the Object.prototype.watch sense -- from |obj| for + * the property |id|. + * + * This is an internal function exposed -- temporarily -- only so that DOM + * proxies can be watchable. Don't use it! We'll soon kill off the + * Object.prototype.{,un}watch functions, at which point this will go too. + */ +extern JS_FRIEND_API(bool) +UnwatchGuts(JSContext *cx, JS::HandleObject obj, JS::HandleId id); + +} // namespace js + +/* + * A class, expected to be passed by value, which represents the CallArgs for a + * JSJitGetterOp. + */ +class JSJitGetterCallArgs : protected JS::MutableHandleValue +{ + public: + explicit JSJitGetterCallArgs(const JS::CallArgs& args) + : JS::MutableHandleValue(args.rval()) + {} + + explicit JSJitGetterCallArgs(JS::RootedValue* rooted) + : JS::MutableHandleValue(rooted) + {} + + JS::MutableHandleValue rval() { + return *this; + } +}; + +/* + * A class, expected to be passed by value, which represents the CallArgs for a + * JSJitSetterOp. + */ +class JSJitSetterCallArgs : protected JS::MutableHandleValue +{ + public: + explicit JSJitSetterCallArgs(const JS::CallArgs& args) + : JS::MutableHandleValue(args[0]) + {} + + JS::MutableHandleValue operator[](unsigned i) { + MOZ_ASSERT(i == 0); + return *this; + } + + unsigned length() const { return 1; } + + // Add get() or maybe hasDefined() as needed +}; + +struct JSJitMethodCallArgsTraits; + +/* + * A class, expected to be passed by reference, which represents the CallArgs + * for a JSJitMethodOp. + */ +class JSJitMethodCallArgs : protected JS::detail::CallArgsBase +{ + private: + typedef JS::detail::CallArgsBase Base; + friend struct JSJitMethodCallArgsTraits; + + public: + explicit JSJitMethodCallArgs(const JS::CallArgs& args) { + argv_ = args.array(); + argc_ = args.length(); + } + + JS::MutableHandleValue rval() const { + return Base::rval(); + } + + unsigned length() const { return Base::length(); } + + JS::MutableHandleValue operator[](unsigned i) const { + return Base::operator[](i); + } + + bool hasDefined(unsigned i) const { + return Base::hasDefined(i); + } + + JSObject &callee() const { + // We can't use Base::callee() because that will try to poke at + // this->usedRval_, which we don't have. + return argv_[-2].toObject(); + } + + // Add get() as needed +}; + +struct JSJitMethodCallArgsTraits +{ + static const size_t offsetOfArgv = offsetof(JSJitMethodCallArgs, argv_); + static const size_t offsetOfArgc = offsetof(JSJitMethodCallArgs, argc_); +}; + +/* + * This struct contains metadata passed from the DOM to the JS Engine for JIT + * optimizations on DOM property accessors. Eventually, this should be made + * available to general JSAPI users, but we are not currently ready to do so. + */ +typedef bool +(* JSJitGetterOp)(JSContext *cx, JS::HandleObject thisObj, + void *specializedThis, JSJitGetterCallArgs args); +typedef bool +(* JSJitSetterOp)(JSContext *cx, JS::HandleObject thisObj, + void *specializedThis, JSJitSetterCallArgs args); +typedef bool +(* JSJitMethodOp)(JSContext *cx, JS::HandleObject thisObj, + void *specializedThis, const JSJitMethodCallArgs& args); + +struct JSJitInfo { + enum OpType { + Getter, + Setter, + Method, + ParallelNative, + StaticMethod, + // Must be last + OpTypeCount + }; + + enum ArgType { + // Basic types + String = (1 << 0), + Integer = (1 << 1), // Only 32-bit or less + Double = (1 << 2), // Maybe we want to add Float sometime too + Boolean = (1 << 3), + Object = (1 << 4), + Null = (1 << 5), + + // And derived types + Numeric = Integer | Double, + // Should "Primitive" use the WebIDL definition, which + // excludes string and null, or the typical JS one that includes them? + Primitive = Numeric | Boolean | Null | String, + ObjectOrNull = Object | Null, + Any = ObjectOrNull | Primitive, + + // Our sentinel value. + ArgTypeListEnd = (1 << 31) + }; + + static_assert(Any & String, "Any must include String."); + static_assert(Any & Integer, "Any must include Integer."); + static_assert(Any & Double, "Any must include Double."); + static_assert(Any & Boolean, "Any must include Boolean."); + static_assert(Any & Object, "Any must include Object."); + static_assert(Any & Null, "Any must include Null."); + + enum AliasSet { + // An enum that describes what this getter/setter/method aliases. This + // determines what things can be hoisted past this call, and if this + // call is movable what it can be hoisted past. + + // Alias nothing: a constant value, getting it can't affect any other + // values, nothing can affect it. + AliasNone, + + // Alias things that can modify the DOM but nothing else. Doing the + // call can't affect the behavior of any other function. + AliasDOMSets, + + // Alias the world. Calling this can change arbitrary values anywhere + // in the system. Most things fall in this bucket. + AliasEverything, + + // Must be last. + AliasSetCount + }; + + bool hasParallelNative() const + { + return type() == ParallelNative; + } + + bool needsOuterizedThisObject() const + { + return type() != Getter && type() != Setter; + } + + bool isTypedMethodJitInfo() const + { + return isTypedMethod; + } + + OpType type() const + { + return OpType(type_); + } + + AliasSet aliasSet() const + { + return AliasSet(aliasSet_); + } + + JSValueType returnType() const + { + return JSValueType(returnType_); + } + + union { + JSJitGetterOp getter; + JSJitSetterOp setter; + JSJitMethodOp method; + /* An alternative native that's safe to call in parallel mode. */ + JSParallelNative parallelNative; + /* A DOM static method, used for Promise wrappers */ + JSNative staticMethod; + }; + + uint16_t protoID; + uint16_t depth; + + // These fields are carefully packed to take up 4 bytes. If you need more + // bits for whatever reason, please see if you can steal bits from existing + // fields before adding more members to this structure. + +#define JITINFO_OP_TYPE_BITS 4 +#define JITINFO_ALIAS_SET_BITS 4 +#define JITINFO_RETURN_TYPE_BITS 8 + + // The OpType that says what sort of function we are. + uint32_t type_ : JITINFO_OP_TYPE_BITS; + + // The alias set for this op. This is a _minimal_ alias set; in + // particular for a method it does not include whatever argument + // conversions might do. That's covered by argTypes and runtime + // analysis of the actual argument types being passed in. + uint32_t aliasSet_ : JITINFO_ALIAS_SET_BITS; + + // The return type tag. Might be JSVAL_TYPE_UNKNOWN. + uint32_t returnType_ : JITINFO_RETURN_TYPE_BITS; + + static_assert(OpTypeCount <= (1 << JITINFO_OP_TYPE_BITS), + "Not enough space for OpType"); + static_assert(AliasSetCount <= (1 << JITINFO_ALIAS_SET_BITS), + "Not enough space for AliasSet"); + static_assert((sizeof(JSValueType) * 8) <= JITINFO_RETURN_TYPE_BITS, + "Not enough space for JSValueType"); + +#undef JITINFO_RETURN_TYPE_BITS +#undef JITINFO_ALIAS_SET_BITS +#undef JITINFO_OP_TYPE_BITS + + uint32_t isInfallible : 1; /* Is op fallible? False in setters. */ + uint32_t isMovable : 1; /* Is op movable? To be movable the op must + not AliasEverything, but even that might + not be enough (e.g. in cases when it can + throw). */ + // XXXbz should we have a JSValueType for the type of the member? + uint32_t isAlwaysInSlot : 1; /* True if this is a getter that can always + get the value from a slot of the "this" + object. */ + uint32_t isLazilyCachedInSlot : 1; /* True if this is a getter that can + sometimes (if the slot doesn't contain + UndefinedValue()) get the value from a + slot of the "this" object. */ + uint32_t isTypedMethod : 1; /* True if this is an instance of + JSTypedMethodJitInfo. */ + uint32_t slotIndex : 11; /* If isAlwaysInSlot or isSometimesInSlot is + true, the index of the slot to get the value + from. Otherwise 0. */ +}; + +static_assert(sizeof(JSJitInfo) == (sizeof(void*) + 2 * sizeof(uint32_t)), + "There are several thousand instances of JSJitInfo stored in " + "a binary. Please don't increase its space requirements without " + "verifying that there is no other way forward (better packing, " + "smaller datatypes for fields, subclassing, etc.)."); + +struct JSTypedMethodJitInfo +{ + // We use C-style inheritance here, rather than C++ style inheritance + // because not all compilers support brace-initialization for non-aggregate + // classes. Using C++ style inheritance and constructors instead of + // brace-initialization would also force the creation of static + // constructors (on some compilers) when JSJitInfo and JSTypedMethodJitInfo + // structures are declared. Since there can be several thousand of these + // structures present and we want to have roughly equivalent performance + // across a range of compilers, we do things manually. + JSJitInfo base; + + const JSJitInfo::ArgType* const argTypes; /* For a method, a list of sets of + types that the function + expects. This can be used, + for example, to figure out + when argument coercions can + have side-effects. */ +}; + +namespace JS { +namespace detail { + +/* NEVER DEFINED, DON'T USE. For use by JS_CAST_PARALLEL_NATIVE_TO only. */ +inline int CheckIsParallelNative(JSParallelNative parallelNative); + +} // namespace detail +} // namespace JS + +#define JS_CAST_PARALLEL_NATIVE_TO(v, To) \ + (static_cast(sizeof(JS::detail::CheckIsParallelNative(v))), \ + reinterpret_cast(v)) + +/* + * You may ask yourself: why do we define a wrapper around a wrapper here? + * The answer is that some compilers don't understand initializing a union + * as we do below with a construct like: + * + * reinterpret_cast(JSParallelNativeThreadSafeWrapper) + * + * (We need the reinterpret_cast because we must initialize the union with + * a datum of the type of the union's first member.) + * + * Presumably this has something to do with template instantiation. + * Initializing with a normal function pointer seems to work fine. Hence + * the ugliness that you see before you. + */ +#define JS_JITINFO_NATIVE_PARALLEL(infoName, parallelOp) \ + const JSJitInfo infoName = \ + {{JS_CAST_PARALLEL_NATIVE_TO(parallelOp, JSJitGetterOp)},0,0,JSJitInfo::ParallelNative,JSJitInfo::AliasEverything,JSVAL_TYPE_MISSING,false,false,false,false,false,0} + +#define JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(infoName, wrapperName, serialOp) \ + bool wrapperName##_ParallelNativeThreadSafeWrapper(js::ForkJoinContext *cx, unsigned argc, \ + JS::Value *vp) \ + { \ + return JSParallelNativeThreadSafeWrapper(cx, argc, vp); \ + } \ + JS_JITINFO_NATIVE_PARALLEL(infoName, wrapperName##_ParallelNativeThreadSafeWrapper) + +static MOZ_ALWAYS_INLINE const JSJitInfo * +FUNCTION_VALUE_TO_JITINFO(const JS::Value& v) +{ + JS_ASSERT(js::GetObjectClass(&v.toObject()) == js::FunctionClassPtr); + return reinterpret_cast(&v.toObject())->jitinfo; +} + +/* Statically asserted in jsfun.h. */ +static const unsigned JS_FUNCTION_INTERPRETED_BIT = 0x1; + +static MOZ_ALWAYS_INLINE void +SET_JITINFO(JSFunction * func, const JSJitInfo *info) +{ + js::shadow::Function *fun = reinterpret_cast(func); + JS_ASSERT(!(fun->flags & JS_FUNCTION_INTERPRETED_BIT)); + fun->jitinfo = info; +} + +/* + * Engine-internal extensions of jsid. This code is here only until we + * eliminate Gecko's dependencies on it! + */ + +static MOZ_ALWAYS_INLINE jsid +JSID_FROM_BITS(size_t bits) +{ + jsid id; + JSID_BITS(id) = bits; + return id; +} + +namespace js { +namespace detail { +bool IdMatchesAtom(jsid id, JSAtom *atom); +} +} + +/* + * Must not be used on atoms that are representable as integer jsids. + * Prefer NameToId or AtomToId over this function: + * + * A PropertyName is an atom that does not contain an integer in the range + * [0, UINT32_MAX]. However, jsid can only hold an integer in the range + * [0, JSID_INT_MAX] (where JSID_INT_MAX == 2^31-1). Thus, for the range of + * integers (JSID_INT_MAX, UINT32_MAX], to represent as a jsid 'id', it must be + * the case JSID_IS_ATOM(id) and !JSID_TO_ATOM(id)->isPropertyName(). In most + * cases when creating a jsid, code does not have to care about this corner + * case because: + * + * - When given an arbitrary JSAtom*, AtomToId must be used, which checks for + * integer atoms representable as integer jsids, and does this conversion. + * + * - When given a PropertyName*, NameToId can be used which which does not need + * to do any dynamic checks. + * + * Thus, it is only the rare third case which needs this function, which + * handles any JSAtom* that is known not to be representable with an int jsid. + */ +static MOZ_ALWAYS_INLINE jsid +NON_INTEGER_ATOM_TO_JSID(JSAtom *atom) +{ + JS_ASSERT(((size_t)atom & 0x7) == 0); + jsid id = JSID_FROM_BITS((size_t)atom); + JS_ASSERT(js::detail::IdMatchesAtom(id, atom)); + return id; +} + +/* All strings stored in jsids are atomized, but are not necessarily property names. */ +static MOZ_ALWAYS_INLINE bool +JSID_IS_ATOM(jsid id) +{ + return JSID_IS_STRING(id); +} + +static MOZ_ALWAYS_INLINE bool +JSID_IS_ATOM(jsid id, JSAtom *atom) +{ + return id == JSID_FROM_BITS((size_t)atom); +} + +static MOZ_ALWAYS_INLINE JSAtom * +JSID_TO_ATOM(jsid id) +{ + return (JSAtom *)JSID_TO_STRING(id); +} + +JS_STATIC_ASSERT(sizeof(jsid) == sizeof(void*)); + +namespace js { + +static MOZ_ALWAYS_INLINE JS::Value +IdToValue(jsid id) +{ + if (JSID_IS_STRING(id)) + return JS::StringValue(JSID_TO_STRING(id)); + if (JSID_IS_INT(id)) + return JS::Int32Value(JSID_TO_INT(id)); + if (JSID_IS_SYMBOL(id)) + return JS::SymbolValue(JSID_TO_SYMBOL(id)); + JS_ASSERT(JSID_IS_VOID(id)); + return JS::UndefinedValue(); +} + +/* + * If the embedder has registered a default JSContext callback, returns the + * result of the callback. Otherwise, asserts that |rt| has exactly one + * JSContext associated with it, and returns that context. + */ +extern JS_FRIEND_API(JSContext *) +DefaultJSContext(JSRuntime *rt); + +typedef JSContext* +(* DefaultJSContextCallback)(JSRuntime *rt); + +JS_FRIEND_API(void) +SetDefaultJSContextCallback(JSRuntime *rt, DefaultJSContextCallback cb); + +/* + * To help embedders enforce their invariants, we allow them to specify in + * advance which JSContext should be passed to JSAPI calls. If this is set + * to a non-null value, the assertSameCompartment machinery does double- + * duty (in debug builds) to verify that it matches the cx being used. + */ +#ifdef DEBUG +JS_FRIEND_API(void) +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx); +#else +inline void +Debug_SetActiveJSContext(JSRuntime *rt, JSContext *cx) {}; +#endif + + +enum CTypesActivityType { + CTYPES_CALL_BEGIN, + CTYPES_CALL_END, + CTYPES_CALLBACK_BEGIN, + CTYPES_CALLBACK_END +}; + +typedef void +(* CTypesActivityCallback)(JSContext *cx, CTypesActivityType type); + +/* + * Sets a callback that is run whenever js-ctypes is about to be used when + * calling into C. + */ +JS_FRIEND_API(void) +SetCTypesActivityCallback(JSRuntime *rt, CTypesActivityCallback cb); + +class JS_FRIEND_API(AutoCTypesActivityCallback) { + private: + JSContext *cx; + CTypesActivityCallback callback; + CTypesActivityType endType; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + + public: + AutoCTypesActivityCallback(JSContext *cx, CTypesActivityType beginType, + CTypesActivityType endType + MOZ_GUARD_OBJECT_NOTIFIER_PARAM); + ~AutoCTypesActivityCallback() { + DoEndCallback(); + } + void DoEndCallback() { + if (callback) { + callback(cx, endType); + callback = nullptr; + } + } +}; + +typedef bool +(* ObjectMetadataCallback)(JSContext *cx, JSObject **pmetadata); + +/* + * Specify a callback to invoke when creating each JS object in the current + * compartment, which may return a metadata object to associate with the + * object. Objects with different metadata have different shape hierarchies, + * so for efficiency, objects should generally try to share metadata objects. + */ +JS_FRIEND_API(void) +SetObjectMetadataCallback(JSContext *cx, ObjectMetadataCallback callback); + +/* Manipulate the metadata associated with an object. */ + +JS_FRIEND_API(bool) +SetObjectMetadata(JSContext *cx, JS::HandleObject obj, JS::HandleObject metadata); + +JS_FRIEND_API(JSObject *) +GetObjectMetadata(JSObject *obj); + +JS_FRIEND_API(void) +UnsafeDefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value); + +JS_FRIEND_API(bool) +SliceSlowly(JSContext* cx, JS::HandleObject obj, JS::HandleObject receiver, + uint32_t begin, uint32_t end, JS::HandleObject result); + +/* ES5 8.12.8. */ +extern JS_FRIEND_API(bool) +DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandleValue vp); + +/* + * Helper function. To approximate a call to the [[DefineOwnProperty]] internal + * method described in ES5, first call this, then call JS_DefinePropertyById. + * + * JS_DefinePropertyById by itself does not enforce the invariants on + * non-configurable properties when obj->isNative(). This function performs the + * relevant checks (specified in ES5 8.12.9 [[DefineOwnProperty]] steps 1-11), + * but only if obj is native. + * + * The reason for the messiness here is that ES5 uses [[DefineOwnProperty]] as + * a sort of extension point, but there is no hook in js::Class, + * js::ProxyHandler, or the JSAPI with precisely the right semantics for it. + */ +extern JS_FRIEND_API(bool) +CheckDefineProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value, + unsigned attrs, + JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr); + +/* + * Helper function for HTMLDocument and HTMLFormElement. + * + * These are the only two interfaces that have [OverrideBuiltins], a named + * getter, and no named setter. They're implemented as proxies with a custom + * getOwnPropertyDescriptor() method. Unfortunately, overriding + * getOwnPropertyDescriptor() automatically affects the behavior of set(), + * which normally is just common sense but is *not* desired for these two + * interfaces. + * + * The fix is for these two interfaces to override set() to ignore the + * getOwnPropertyDescriptor() override. + * + * SetPropertyIgnoringNamedGetter is exposed to make it easier to override + * set() in this way. It carries out all the steps of BaseProxyHandler::set() + * except the initial getOwnPropertyDescriptor()/getPropertyDescriptor() calls. + * The caller must supply those results as the 'desc' and 'descIsOwn' + * parameters. + * + * Implemented in jsproxy.cpp. + */ +JS_FRIEND_API(bool) +SetPropertyIgnoringNamedGetter(JSContext *cx, const BaseProxyHandler *handler, + JS::HandleObject proxy, JS::HandleObject receiver, + JS::HandleId id, JS::MutableHandle desc, + bool descIsOwn, bool strict, JS::MutableHandleValue vp); + +JS_FRIEND_API(void) +ReportErrorWithId(JSContext *cx, const char *msg, JS::HandleId id); + +// This function is for one specific use case, please don't use this for anything else! +extern JS_FRIEND_API(bool) +ExecuteInGlobalAndReturnScope(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, + JS::MutableHandleObject scope); + +} /* namespace js */ + +extern JS_FRIEND_API(bool) +js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg, + JS::Handle descriptor, bool *bp); + +extern JS_FRIEND_API(bool) +js_ReportIsNotFunction(JSContext *cx, JS::HandleValue v); + +#ifdef JSGC_GENERATIONAL +extern JS_FRIEND_API(void) +JS_StoreObjectPostBarrierCallback(JSContext* cx, + void (*callback)(JSTracer *trc, JSObject *key, void *data), + JSObject *key, void *data); + +extern JS_FRIEND_API(void) +JS_StoreStringPostBarrierCallback(JSContext* cx, + void (*callback)(JSTracer *trc, JSString *key, void *data), + JSString *key, void *data); +#else +inline void +JS_StoreObjectPostBarrierCallback(JSContext* cx, + void (*callback)(JSTracer *trc, JSObject *key, void *data), + JSObject *key, void *data) {} + +inline void +JS_StoreStringPostBarrierCallback(JSContext* cx, + void (*callback)(JSTracer *trc, JSString *key, void *data), + JSString *key, void *data) {} +#endif /* JSGC_GENERATIONAL */ + +#endif /* jsfriendapi_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsprf.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsprf.h new file mode 100644 index 0000000000..bfedf98ca8 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsprf.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsprf_h +#define jsprf_h + +/* +** API for PR printf like routines. Supports the following formats +** %d - decimal +** %u - unsigned decimal +** %x - unsigned hex +** %X - unsigned uppercase hex +** %o - unsigned octal +** %hd, %hu, %hx, %hX, %ho - 16-bit versions of above +** %ld, %lu, %lx, %lX, %lo - 32-bit versions of above +** %lld, %llu, %llx, %llX, %llo - 64 bit versions of above +** %s - ascii string +** %hs - ucs2 string +** %c - character +** %p - pointer (deals with machine dependent pointer size) +** %f - float +** %g - float +*/ + +#include + +#include "jstypes.h" + +/* +** sprintf into a fixed size buffer. Guarantees that a NUL is at the end +** of the buffer. Returns the length of the written output, NOT including +** the NUL, or (uint32_t)-1 if an error occurs. +*/ +extern JS_PUBLIC_API(uint32_t) JS_snprintf(char *out, uint32_t outlen, const char *fmt, ...); + +/* +** sprintf into a malloc'd buffer. Return a pointer to the malloc'd +** buffer on success, nullptr on failure. Call "JS_smprintf_free" to release +** the memory returned. +*/ +extern JS_PUBLIC_API(char*) JS_smprintf(const char *fmt, ...); + +/* +** Free the memory allocated, for the caller, by JS_smprintf +*/ +extern JS_PUBLIC_API(void) JS_smprintf_free(char *mem); + +/* +** "append" sprintf into a malloc'd buffer. "last" is the last value of +** the malloc'd buffer. sprintf will append data to the end of last, +** growing it as necessary using realloc. If last is nullptr, JS_sprintf_append +** will allocate the initial string. The return value is the new value of +** last for subsequent calls, or nullptr if there is a malloc failure. +*/ +extern JS_PUBLIC_API(char*) JS_sprintf_append(char *last, const char *fmt, ...); + +/* +** va_list forms of the above. +*/ +extern JS_PUBLIC_API(uint32_t) JS_vsnprintf(char *out, uint32_t outlen, const char *fmt, va_list ap); +extern JS_PUBLIC_API(char*) JS_vsmprintf(const char *fmt, va_list ap); +extern JS_PUBLIC_API(char*) JS_vsprintf_append(char *last, const char *fmt, va_list ap); + +#endif /* jsprf_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsprototypes.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsprototypes.h new file mode 100644 index 0000000000..1cb56bf8da --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsprototypes.h @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsprototypes_h +#define jsprototypes_h + +/* A higher-order macro for enumerating all JSProtoKey values. */ +/* + * Consumers define macros as follows: + * macro(name, code, init, clasp) + * name: The canonical name of the class. + * code: The enumerator code. There are part of the XDR API, and must not change. + * init: Initialization function. These are |extern "C";|, and clients should use + * |extern "C" {}| as appropriate when using this macro. + * clasp: The JSClass for this object, or "dummy" if it doesn't exist. + * + * + * Consumers wishing to iterate over all the JSProtoKey values, can use + * JS_FOR_EACH_PROTOTYPE. However, there are certain values that don't correspond + * to real constructors, like Null or constructors that are disabled via + * preprocessor directives. We still need to include these in the JSProtoKey list + * in order to maintain binary XDR compatibility, but we need to provide a tool + * to handle them differently. JS_FOR_PROTOTYPES fills this niche. + * + * Consumers pass two macros to JS_FOR_PROTOTYPES - |real| and |imaginary|. The + * former is invoked for entries that have real client-exposed constructors, and + * the latter is called for the rest. Consumers that don't care about this + * distinction can simply pass the same macro to both, which is exactly what + * JS_FOR_EACH_PROTOTYPE does. + */ + +#define CLASP(name) (&name##Class) +#define OCLASP(name) (&name##Object::class_) +#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[Scalar::type]) + +#ifdef ENABLE_PARALLEL_JS +#define IF_PJS(real,imaginary) real +#else +#define IF_PJS(real,imaginary) imaginary +#endif + +#ifdef EXPOSE_INTL_API +#define IF_INTL(real,imaginary) real +#else +#define IF_INTL(real,imaginary) imaginary +#endif + +#ifdef ENABLE_BINARYDATA +#define IF_BDATA(real,imaginary) real +#else +#define IF_BDATA(real,imaginary) imaginary +#endif + +#ifdef ENABLE_SHARED_ARRAY_BUFFER +#define IF_SAB(real,imaginary) real +#else +#define IF_SAB(real,imaginary) imaginary +#endif + +#ifdef JS_HAS_SYMBOLS +#define IF_SYMBOLS(real,imaginary) real +#else +#define IF_SYMBOLS(real,imaginary) imaginary +#endif + +#define JS_FOR_PROTOTYPES(real,imaginary) \ + imaginary(Null, 0, js_InitNullClass, dummy) \ + real(Object, 1, js_InitViaClassSpec, &JSObject::class_) \ + real(Function, 2, js_InitViaClassSpec, &JSFunction::class_) \ + real(Array, 3, js_InitViaClassSpec, OCLASP(Array)) \ + real(Boolean, 4, js_InitBooleanClass, OCLASP(Boolean)) \ + real(JSON, 5, js_InitJSONClass, CLASP(JSON)) \ + real(Date, 6, js_InitViaClassSpec, OCLASP(Date)) \ + real(Math, 7, js_InitMathClass, CLASP(Math)) \ + real(Number, 8, js_InitNumberClass, OCLASP(Number)) \ + real(String, 9, js_InitStringClass, OCLASP(String)) \ + real(RegExp, 10, js_InitRegExpClass, OCLASP(RegExp)) \ + real(Error, 11, js_InitViaClassSpec, OCLASP(Error)) \ + real(InternalError, 12, js_InitViaClassSpec, OCLASP(Error)) \ + real(EvalError, 13, js_InitViaClassSpec, OCLASP(Error)) \ + real(RangeError, 14, js_InitViaClassSpec, OCLASP(Error)) \ + real(ReferenceError, 15, js_InitViaClassSpec, OCLASP(Error)) \ + real(SyntaxError, 16, js_InitViaClassSpec, OCLASP(Error)) \ + real(TypeError, 17, js_InitViaClassSpec, OCLASP(Error)) \ + real(URIError, 18, js_InitViaClassSpec, OCLASP(Error)) \ + real(Iterator, 19, js_InitIteratorClasses, OCLASP(PropertyIterator)) \ + real(StopIteration, 20, js_InitIteratorClasses, OCLASP(StopIteration)) \ + real(ArrayBuffer, 21, js_InitArrayBufferClass, &js::ArrayBufferObject::protoClass) \ + real(Int8Array, 22, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int8)) \ + real(Uint8Array, 23, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8)) \ + real(Int16Array, 24, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int16)) \ + real(Uint16Array, 25, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint16)) \ + real(Int32Array, 26, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Int32)) \ + real(Uint32Array, 27, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint32)) \ + real(Float32Array, 28, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float32)) \ + real(Float64Array, 29, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Float64)) \ + real(Uint8ClampedArray, 30, js_InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8Clamped)) \ + real(Proxy, 31, js_InitProxyClass, &ProxyObject::uncallableClass_) \ + real(WeakMap, 32, js_InitWeakMapClass, OCLASP(WeakMap)) \ + real(Map, 33, js_InitMapClass, OCLASP(Map)) \ + real(Set, 34, js_InitSetClass, OCLASP(Set)) \ + real(DataView, 35, js_InitDataViewClass, OCLASP(DataView)) \ +IF_SYMBOLS(real,imaginary)(Symbol, 36, js_InitSymbolClass, &js::SymbolObject::class_) \ +IF_SAB(real,imaginary)(SharedArrayBuffer, 37, js_InitSharedArrayBufferClass, &js::SharedArrayBufferObject::protoClass) \ +IF_INTL(real,imaginary) (Intl, 38, js_InitIntlClass, CLASP(Intl)) \ +IF_BDATA(real,imaginary)(TypedObject, 39, js_InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \ + imaginary(GeneratorFunction, 40, js_InitIteratorClasses, dummy) \ +IF_BDATA(real,imaginary)(SIMD, 41, js_InitSIMDClass, OCLASP(SIMD)) \ + +#define JS_FOR_EACH_PROTOTYPE(macro) JS_FOR_PROTOTYPES(macro,macro) + +#endif /* jsprototypes_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsproxy.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsproxy.h new file mode 100644 index 0000000000..b4588c4c2a --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsproxy.h @@ -0,0 +1,563 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsproxy_h +#define jsproxy_h + +#include "mozilla/Maybe.h" + +#include "jsfriendapi.h" + +#include "js/CallNonGenericMethod.h" +#include "js/Class.h" + +namespace js { + +using JS::AutoIdVector; +using JS::CallArgs; +using JS::HandleId; +using JS::HandleObject; +using JS::HandleValue; +using JS::IsAcceptableThis; +using JS::MutableHandle; +using JS::MutableHandleObject; +using JS::MutableHandleValue; +using JS::NativeImpl; +using JS::PrivateValue; +using JS::Value; + +class RegExpGuard; +class JS_FRIEND_API(Wrapper); + +/* + * A proxy is a JSObject that implements generic behavior by providing custom + * implementations for each object trap. The implementation for each trap is + * provided by a C++ object stored on the proxy, known as its handler. + * + * A major use case for proxies is to forward each trap to another object, + * known as its target. The target can be an arbitrary C++ object. Not every + * proxy has the notion of a target, however. + * + * Proxy traps are grouped into fundamental and derived traps. Every proxy has + * to at least provide implementations for the fundamental traps, but the + * derived traps can be implemented in terms of the fundamental ones + * BaseProxyHandler provides implementations of the derived traps in terms of + * the (pure virtual) fundamental traps. + * + * In addition to the normal traps, there are two models for proxy prototype + * chains. First, proxies may opt to use the standard prototype mechanism used + * throughout the engine. To do so, simply pass a prototype to NewProxyObject() + * at creation time. All prototype accesses will then "just work" to treat the + * proxy as a "normal" object. Alternatively, if instead the proxy wishes to + * implement more complicated prototype semantics (if, for example, it wants to + * delegate the prototype lookup to a wrapped object), it may pass Proxy::LazyProto + * as the prototype at create time and opt in to the trapped prototype system, + * which guarantees that their trap will be called on any and every prototype + * chain access of the object. + * + * This system is implemented with two traps: {get,set}PrototypeOf. The default + * implementation of setPrototypeOf throws a TypeError. Since it is not possible + * to create an object without a sense of prototype chain, handler implementors + * must provide a getPrototypeOf trap if opting in to the dynamic prototype system. + * + * To minimize code duplication, a set of abstract proxy handler classes is + * provided, from which other handlers may inherit. These abstract classes + * are organized in the following hierarchy: + * + * BaseProxyHandler + * | + * DirectProxyHandler + * | + * Wrapper + */ + +/* + * BaseProxyHandler is the most generic kind of proxy handler. It does not make + * any assumptions about the target. Consequently, it does not provide any + * default implementation for the fundamental traps. It does, however, implement + * the derived traps in terms of the fundamental ones. This allows consumers of + * this class to define any custom behavior they want. + * + * Important: If you add a trap here, you should probably also add a Proxy::foo + * entry point with an AutoEnterPolicy. If you don't, you need an explicit + * override for the trap in SecurityWrapper. See bug 945826 comment 0. + */ +class JS_FRIEND_API(BaseProxyHandler) +{ + const void *mFamily; + + /* + * Proxy handlers can use mHasPrototype to request the following special + * treatment from the JS engine: + * + * - When mHasPrototype is true, the engine never calls these methods: + * getPropertyDescriptor, has, set, enumerate, iterate. Instead, for + * these operations, it calls the "own" traps like + * getOwnPropertyDescriptor, hasOwn, defineProperty, keys, etc., and + * consults the prototype chain if needed. + * + * - When mHasPrototype is true, the engine calls handler->get() only if + * handler->hasOwn() says an own property exists on the proxy. If not, + * it consults the prototype chain. + * + * This is useful because it frees the ProxyHandler from having to implement + * any behavior having to do with the prototype chain. + */ + bool mHasPrototype; + + /* + * All proxies indicate whether they have any sort of interesting security + * policy that might prevent the caller from doing something it wants to + * the object. In the case of wrappers, this distinction is used to + * determine whether the caller may strip off the wrapper if it so desires. + */ + bool mHasSecurityPolicy; + + public: + explicit BaseProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); + virtual ~BaseProxyHandler(); + + bool hasPrototype() const { + return mHasPrototype; + } + + bool hasSecurityPolicy() const { + return mHasSecurityPolicy; + } + + inline const void *family() const { + return mFamily; + } + static size_t offsetOfFamily() { + return offsetof(BaseProxyHandler, mFamily); + } + + virtual bool finalizeInBackground(Value priv) const { + /* + * Called on creation of a proxy to determine whether its finalize + * method can be finalized on the background thread. + */ + return true; + } + + /* Policy enforcement traps. + * + * enter() allows the policy to specify whether the caller may perform |act| + * on the proxy's |id| property. In the case when |act| is CALL, |id| is + * generally JSID_VOID. + * + * The |act| parameter to enter() specifies the action being performed. + * If |bp| is false, the trap suggests that the caller throw (though it + * may still decide to squelch the error). + * + * We make these OR-able so that assertEnteredPolicy can pass a union of them. + * For example, get{,Own}PropertyDescriptor is invoked by both calls to ::get() + * and ::set() (since we need to look up the accessor), so its + * assertEnteredPolicy would pass GET | SET. + */ + typedef uint32_t Action; + enum { + NONE = 0x00, + GET = 0x01, + SET = 0x02, + CALL = 0x04, + ENUMERATE = 0x08 + }; + + virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Action act, + bool *bp) const; + + /* ES5 Harmony fundamental proxy traps. */ + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const = 0; + virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const = 0; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, + HandleId id, MutableHandle desc) const = 0; + virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const = 0; + virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, + AutoIdVector &props) const = 0; + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const = 0; + virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) const = 0; + + /* ES5 Harmony derived proxy traps. */ + virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; + virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) const; + virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, + HandleId id, MutableHandleValue vp) const; + virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, + HandleId id, bool strict, MutableHandleValue vp) const; + virtual bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props) const; + virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, + MutableHandleValue vp) const; + + /* Spidermonkey extensions. */ + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const = 0; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args) const; + virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp) const; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx) const; + virtual const char *className(JSContext *cx, HandleObject proxy) const; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const; + virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp) const; + virtual void finalize(JSFreeOp *fop, JSObject *proxy) const; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop) const; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp) const; + + // These two hooks must be overridden, or not overridden, in tandem -- no + // overriding just one! + virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, + JS::HandleObject callable) const; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const; + + virtual bool slice(JSContext *cx, HandleObject proxy, uint32_t begin, uint32_t end, + HandleObject result) const; + + /* See comment for weakmapKeyDelegateOp in js/Class.h. */ + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const; + virtual bool isScripted() const { return false; } +}; + +/* + * DirectProxyHandler includes a notion of a target object. All traps are + * reimplemented such that they forward their behavior to the target. This + * allows consumers of this class to forward to another object as transparently + * and efficiently as possible. + * + * Important: If you add a trap implementation here, you probably also need to + * add an override in CrossCompartmentWrapper. If you don't, you risk + * compartment mismatches. See bug 945826 comment 0. + */ +class JS_PUBLIC_API(DirectProxyHandler) : public BaseProxyHandler +{ + public: + explicit DirectProxyHandler(const void *family, bool hasPrototype = false, + bool hasSecurityPolicy = false); + + /* ES5 Harmony fundamental proxy traps. */ + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, + bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject proxy, + AutoIdVector &props) const MOZ_OVERRIDE; + + /* ES5 Harmony derived proxy traps. */ + virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, + bool *bp) const MOZ_OVERRIDE; + virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, + bool *bp) const MOZ_OVERRIDE; + virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool keys(JSContext *cx, HandleObject proxy, + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, + MutableHandleValue vp) const MOZ_OVERRIDE; + + /* Spidermonkey extensions. */ + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, + CallArgs args) const MOZ_OVERRIDE; + virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, + bool *bp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, + unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, + RegExpGuard *g) const MOZ_OVERRIDE; + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const MOZ_OVERRIDE; +}; + +/* + * Dispatch point for handlers that executes the appropriate C++ or scripted traps. + * + * Important: All proxy traps need either (a) an AutoEnterPolicy in their + * Proxy::foo entry point below or (b) an override in SecurityWrapper. See bug + * 945826 comment 0. + */ +class Proxy +{ + public: + /* ES5 Harmony fundamental proxy traps. */ + static bool preventExtensions(JSContext *cx, HandleObject proxy); + static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc); + static bool getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandleValue vp); + static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc); + static bool getOwnPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandleValue vp); + static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, + MutableHandle desc); + static bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props); + static bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); + static bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props); + + /* ES5 Harmony derived proxy traps. */ + static bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); + static bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); + static bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, + MutableHandleValue vp); + static bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, + bool strict, MutableHandleValue vp); + static bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props); + static bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, MutableHandleValue vp); + + /* Spidermonkey extensions. */ + static bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible); + static bool call(JSContext *cx, HandleObject proxy, const CallArgs &args); + static bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args); + static bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args); + static bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp); + static bool objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx); + static const char *className(JSContext *cx, HandleObject proxy); + static JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent); + static bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g); + static bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); + static bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop); + static bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, bool *bp); + + static bool watch(JSContext *cx, HandleObject proxy, HandleId id, HandleObject callable); + static bool unwatch(JSContext *cx, HandleObject proxy, HandleId id); + + static bool slice(JSContext *cx, HandleObject obj, uint32_t begin, uint32_t end, + HandleObject result); + + /* IC entry path for handling __noSuchMethod__ on access. */ + static bool callProp(JSContext *cx, HandleObject proxy, HandleObject reveiver, HandleId id, + MutableHandleValue vp); +}; + +// Use these in places where you don't want to #include vm/ProxyObject.h. +extern JS_FRIEND_DATA(const js::Class* const) CallableProxyClassPtr; +extern JS_FRIEND_DATA(const js::Class* const) UncallableProxyClassPtr; + +inline bool IsProxy(JSObject *obj) +{ + return GetObjectClass(obj)->isProxy(); +} + +/* + * These are part of the API. + * + * NOTE: PROXY_PRIVATE_SLOT is 0 because that way slot 0 is usable by API + * clients for both proxy and non-proxy objects. So an API client that only + * needs to store one slot's worth of data doesn't need to branch on what sort + * of object it has. + */ +const uint32_t PROXY_PRIVATE_SLOT = 0; +const uint32_t PROXY_HANDLER_SLOT = 1; +const uint32_t PROXY_EXTRA_SLOT = 2; +const uint32_t PROXY_MINIMUM_SLOTS = 4; + +inline const BaseProxyHandler * +GetProxyHandler(JSObject *obj) +{ + JS_ASSERT(IsProxy(obj)); + return (const BaseProxyHandler *) GetReservedSlot(obj, PROXY_HANDLER_SLOT).toPrivate(); +} + +inline const Value & +GetProxyPrivate(JSObject *obj) +{ + JS_ASSERT(IsProxy(obj)); + return GetReservedSlot(obj, PROXY_PRIVATE_SLOT); +} + +inline JSObject * +GetProxyTargetObject(JSObject *obj) +{ + JS_ASSERT(IsProxy(obj)); + return GetProxyPrivate(obj).toObjectOrNull(); +} + +inline const Value & +GetProxyExtra(JSObject *obj, size_t n) +{ + JS_ASSERT(IsProxy(obj)); + return GetReservedSlot(obj, PROXY_EXTRA_SLOT + n); +} + +inline void +SetProxyHandler(JSObject *obj, BaseProxyHandler *handler) +{ + JS_ASSERT(IsProxy(obj)); + SetReservedSlot(obj, PROXY_HANDLER_SLOT, PrivateValue(handler)); +} + +inline void +SetProxyExtra(JSObject *obj, size_t n, const Value &extra) +{ + JS_ASSERT(IsProxy(obj)); + JS_ASSERT(n <= 1); + SetReservedSlot(obj, PROXY_EXTRA_SLOT + n, extra); +} + +inline bool +IsScriptedProxy(JSObject *obj) +{ + return IsProxy(obj) && GetProxyHandler(obj)->isScripted(); +} + +class MOZ_STACK_CLASS ProxyOptions { + protected: + /* protected constructor for subclass */ + ProxyOptions(bool singletonArg, const Class *claspArg) + : singleton_(singletonArg), + clasp_(claspArg) + {} + + public: + ProxyOptions() : singleton_(false), + clasp_(UncallableProxyClassPtr) + {} + + bool singleton() const { return singleton_; } + ProxyOptions &setSingleton(bool flag) { + singleton_ = flag; + return *this; + } + + const Class *clasp() const { + return clasp_; + } + ProxyOptions &setClass(const Class *claspArg) { + clasp_ = claspArg; + return *this; + } + ProxyOptions &selectDefaultClass(bool callable) { + const Class *classp = callable? CallableProxyClassPtr : + UncallableProxyClassPtr; + return setClass(classp); + } + + private: + bool singleton_; + const Class *clasp_; +}; + +JS_FRIEND_API(JSObject *) +NewProxyObject(JSContext *cx, const BaseProxyHandler *handler, HandleValue priv, + JSObject *proto, JSObject *parent, const ProxyOptions &options = ProxyOptions()); + +JSObject * +RenewProxyObject(JSContext *cx, JSObject *obj, BaseProxyHandler *handler, Value priv); + +class JS_FRIEND_API(AutoEnterPolicy) +{ + public: + typedef BaseProxyHandler::Action Action; + AutoEnterPolicy(JSContext *cx, const BaseProxyHandler *handler, + HandleObject wrapper, HandleId id, Action act, bool mayThrow) +#ifdef JS_DEBUG + : context(nullptr) +#endif + { + allow = handler->hasSecurityPolicy() ? handler->enter(cx, wrapper, id, act, &rv) + : true; + recordEnter(cx, wrapper, id, act); + // We want to throw an exception if all of the following are true: + // * The policy disallowed access. + // * The policy set rv to false, indicating that we should throw. + // * The caller did not instruct us to ignore exceptions. + // * The policy did not throw itself. + if (!allow && !rv && mayThrow) + reportErrorIfExceptionIsNotPending(cx, id); + } + + virtual ~AutoEnterPolicy() { recordLeave(); } + inline bool allowed() { return allow; } + inline bool returnValue() { JS_ASSERT(!allowed()); return rv; } + + protected: + // no-op constructor for subclass + AutoEnterPolicy() +#ifdef JS_DEBUG + : context(nullptr) + , enteredAction(BaseProxyHandler::NONE) +#endif + {}; + void reportErrorIfExceptionIsNotPending(JSContext *cx, jsid id); + bool allow; + bool rv; + +#ifdef JS_DEBUG + JSContext *context; + mozilla::Maybe enteredProxy; + mozilla::Maybe enteredId; + Action enteredAction; + + // NB: We explicitly don't track the entered action here, because sometimes + // SET traps do an implicit GET during their implementation, leading to + // spurious assertions. + AutoEnterPolicy *prev; + void recordEnter(JSContext *cx, HandleObject proxy, HandleId id, Action act); + void recordLeave(); + + friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id, Action act); +#else + inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id, Action act) {} + inline void recordLeave() {} +#endif + +}; + +#ifdef JS_DEBUG +class JS_FRIEND_API(AutoWaivePolicy) : public AutoEnterPolicy { +public: + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) + { + allow = true; + recordEnter(cx, proxy, id, act); + } +}; +#else +class JS_FRIEND_API(AutoWaivePolicy) { + public: + AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id, + BaseProxyHandler::Action act) + {} +}; +#endif + +#ifdef JS_DEBUG +extern JS_FRIEND_API(void) +assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act); +#else +inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id, + BaseProxyHandler::Action act) +{}; +#endif + +} /* namespace js */ + +extern JS_FRIEND_API(JSObject *) +js_InitProxyClass(JSContext *cx, JS::HandleObject obj); + +#endif /* jsproxy_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jspubtd.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jspubtd.h new file mode 100644 index 0000000000..7a524c8aef --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jspubtd.h @@ -0,0 +1,548 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jspubtd_h +#define jspubtd_h + +/* + * JS public API typedefs. + */ + +#include "mozilla/Assertions.h" +#include "mozilla/LinkedList.h" +#include "mozilla/NullPtr.h" +#include "mozilla/PodOperations.h" + +#include "jsprototypes.h" +#include "jstypes.h" + +#include "js/TypeDecls.h" + +#if defined(JSGC_USE_EXACT_ROOTING) +# define JSGC_TRACK_EXACT_ROOTS +#endif + +namespace JS { + +class AutoIdVector; +class CallArgs; + +template +class Rooted; + +class JS_FRIEND_API(CompileOptions); +class JS_FRIEND_API(ReadOnlyCompileOptions); +class JS_FRIEND_API(OwningCompileOptions); +class JS_PUBLIC_API(CompartmentOptions); + +struct Zone; + +} /* namespace JS */ + +namespace js { +struct ContextFriendFields; +} // namespace js + +/* + * Run-time version enumeration. For compile-time version checking, please use + * the JS_HAS_* macros in jsversion.h, or use MOZJS_MAJOR_VERSION, + * MOZJS_MINOR_VERSION, MOZJS_PATCH_VERSION, and MOZJS_ALPHA definitions. + */ +enum JSVersion { + JSVERSION_ECMA_3 = 148, + JSVERSION_1_6 = 160, + JSVERSION_1_7 = 170, + JSVERSION_1_8 = 180, + JSVERSION_ECMA_5 = 185, + JSVERSION_DEFAULT = 0, + JSVERSION_UNKNOWN = -1, + JSVERSION_LATEST = JSVERSION_ECMA_5 +}; + +/* Result of typeof operator enumeration. */ +enum JSType { + JSTYPE_VOID, /* undefined */ + JSTYPE_OBJECT, /* object */ + JSTYPE_FUNCTION, /* function */ + JSTYPE_STRING, /* string */ + JSTYPE_NUMBER, /* number */ + JSTYPE_BOOLEAN, /* boolean */ + JSTYPE_NULL, /* null */ + JSTYPE_SYMBOL, /* symbol */ + JSTYPE_LIMIT +}; + +/* Dense index into cached prototypes and class atoms for standard objects. */ +enum JSProtoKey { +#define PROTOKEY_AND_INITIALIZER(name,code,init,clasp) JSProto_##name = code, + JS_FOR_EACH_PROTOTYPE(PROTOKEY_AND_INITIALIZER) +#undef PROTOKEY_AND_INITIALIZER + JSProto_LIMIT +}; + +/* + * This enum type is used to control the behavior of a JSObject property + * iterator function that has type JSNewEnumerate. + */ +enum JSIterateOp { + /* Create new iterator state over enumerable properties. */ + JSENUMERATE_INIT, + + /* Create new iterator state over all properties. */ + JSENUMERATE_INIT_ALL, + + /* Iterate once. */ + JSENUMERATE_NEXT, + + /* Destroy iterator state. */ + JSENUMERATE_DESTROY +}; + +/* See Value::gcKind() and JSTraceCallback in Tracer.h. */ +enum JSGCTraceKind { + JSTRACE_OBJECT, + JSTRACE_STRING, + JSTRACE_SYMBOL, + JSTRACE_SCRIPT, + + /* + * Trace kinds internal to the engine. The embedding can only see them if + * it implements JSTraceCallback. + */ + JSTRACE_LAZY_SCRIPT, + JSTRACE_JITCODE, + JSTRACE_SHAPE, + JSTRACE_BASE_SHAPE, + JSTRACE_TYPE_OBJECT, + JSTRACE_LAST = JSTRACE_TYPE_OBJECT +}; + +/* Struct forward declarations. */ +struct JSClass; +struct JSCompartment; +struct JSConstDoubleSpec; +struct JSCrossCompartmentCall; +struct JSErrorReport; +struct JSExceptionState; +struct JSFunctionSpec; +struct JSIdArray; +struct JSLocaleCallbacks; +struct JSObjectMap; +struct JSPrincipals; +struct JSPropertyDescriptor; +struct JSPropertyName; +struct JSPropertySpec; +struct JSRuntime; +struct JSSecurityCallbacks; +struct JSStructuredCloneCallbacks; +struct JSStructuredCloneReader; +struct JSStructuredCloneWriter; +class JS_PUBLIC_API(JSTracer); + +class JSFlatString; + +#ifdef JS_THREADSAFE +typedef struct PRCallOnceType JSCallOnceType; +#else +typedef bool JSCallOnceType; +#endif +typedef bool (*JSInitCallback)(void); + +/* + * Generic trace operation that calls JS_CallTracer on each traceable thing + * stored in data. + */ +typedef void +(* JSTraceDataOp)(JSTracer *trc, void *data); + +void js_FinishGC(JSRuntime *rt); + +namespace js { +namespace gc { +class StoreBuffer; +void MarkPersistentRootedChains(JSTracer *); +void FinishPersistentRootedChains(JSRuntime *); +} +} + +namespace JS { + +typedef void (*OffThreadCompileCallback)(void *token, void *callbackData); + +namespace shadow { + +struct Runtime +{ + /* Restrict zone access during Minor GC. */ + bool needsBarrier_; + +#ifdef JSGC_GENERATIONAL + private: + js::gc::StoreBuffer *gcStoreBufferPtr_; +#endif + + public: + explicit Runtime( +#ifdef JSGC_GENERATIONAL + js::gc::StoreBuffer *storeBuffer +#endif + ) + : needsBarrier_(false) +#ifdef JSGC_GENERATIONAL + , gcStoreBufferPtr_(storeBuffer) +#endif + {} + + bool needsBarrier() const { + return needsBarrier_; + } + +#ifdef JSGC_GENERATIONAL + js::gc::StoreBuffer *gcStoreBufferPtr() { return gcStoreBufferPtr_; } +#endif + + static JS::shadow::Runtime *asShadowRuntime(JSRuntime *rt) { + return reinterpret_cast(rt); + } + + /* Allow inlining of PersistentRooted constructors and destructors. */ + private: + template friend class JS::PersistentRooted; + friend void js::gc::MarkPersistentRootedChains(JSTracer *); + friend void js::gc::FinishPersistentRootedChains(JSRuntime *rt); + + mozilla::LinkedList functionPersistentRooteds; + mozilla::LinkedList idPersistentRooteds; + mozilla::LinkedList objectPersistentRooteds; + mozilla::LinkedList scriptPersistentRooteds; + mozilla::LinkedList stringPersistentRooteds; + mozilla::LinkedList valuePersistentRooteds; + + /* Specializations of this return references to the appropriate list. */ + template + inline mozilla::LinkedList > &getPersistentRootedList(); +}; + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return functionPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return idPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return objectPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return scriptPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return stringPersistentRooteds; } + +template<> +inline mozilla::LinkedList +&Runtime::getPersistentRootedList() { return valuePersistentRooteds; } + +} /* namespace shadow */ + +class JS_PUBLIC_API(AutoGCRooter) +{ + public: + AutoGCRooter(JSContext *cx, ptrdiff_t tag); + AutoGCRooter(js::ContextFriendFields *cx, ptrdiff_t tag); + + ~AutoGCRooter() { + MOZ_ASSERT(this == *stackTop); + *stackTop = down; + } + + /* Implemented in gc/RootMarking.cpp. */ + inline void trace(JSTracer *trc); + static void traceAll(JSTracer *trc); + static void traceAllWrappers(JSTracer *trc); + + /* T must be a context type */ + template + static void traceAllInContext(T* cx, JSTracer *trc) { + for (AutoGCRooter *gcr = cx->autoGCRooters; gcr; gcr = gcr->down) + gcr->trace(trc); + } + + protected: + AutoGCRooter * const down; + + /* + * Discriminates actual subclass of this being used. If non-negative, the + * subclass roots an array of values of the length stored in this field. + * If negative, meaning is indicated by the corresponding value in the enum + * below. Any other negative value indicates some deeper problem such as + * memory corruption. + */ + ptrdiff_t tag_; + + enum { + VALARRAY = -2, /* js::AutoValueArray */ + PARSER = -3, /* js::frontend::Parser */ + SHAPEVECTOR = -4, /* js::AutoShapeVector */ + IDARRAY = -6, /* js::AutoIdArray */ + DESCVECTOR = -7, /* js::AutoPropDescVector */ + VALVECTOR = -10, /* js::AutoValueVector */ + IDVECTOR = -13, /* js::AutoIdVector */ + OBJVECTOR = -14, /* js::AutoObjectVector */ + STRINGVECTOR =-15, /* js::AutoStringVector */ + SCRIPTVECTOR =-16, /* js::AutoScriptVector */ + NAMEVECTOR = -17, /* js::AutoNameVector */ + HASHABLEVALUE=-18, /* js::HashableValue */ + IONMASM = -19, /* js::jit::MacroAssembler */ + IONALLOC = -20, /* js::jit::AutoTempAllocatorRooter */ + WRAPVECTOR = -21, /* js::AutoWrapperVector */ + WRAPPER = -22, /* js::AutoWrapperRooter */ + OBJOBJHASHMAP=-23, /* js::AutoObjectObjectHashMap */ + OBJU32HASHMAP=-24, /* js::AutoObjectUnsigned32HashMap */ + OBJHASHSET = -25, /* js::AutoObjectHashSet */ + JSONPARSER = -26, /* js::JSONParser */ + CUSTOM = -27, /* js::CustomAutoRooter */ + FUNVECTOR = -28 /* js::AutoFunctionVector */ + }; + + private: + AutoGCRooter ** const stackTop; + + /* No copy or assignment semantics. */ + AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; + void operator=(AutoGCRooter &ida) MOZ_DELETE; +}; + +} /* namespace JS */ + +namespace js { + +/* + * Parallel operations in general can have one of three states. They may + * succeed, fail, or "bail", where bail indicates that the code encountered an + * unexpected condition and should be re-run sequentially. Different + * subcategories of the "bail" state are encoded as variants of TP_RETRY_*. + */ +enum ParallelResult { TP_SUCCESS, TP_RETRY_SEQUENTIALLY, TP_RETRY_AFTER_GC, TP_FATAL }; + +struct ThreadSafeContext; +class ForkJoinContext; +class ExclusiveContext; + +class Allocator; + +enum ThingRootKind +{ + THING_ROOT_OBJECT, + THING_ROOT_SHAPE, + THING_ROOT_BASE_SHAPE, + THING_ROOT_TYPE_OBJECT, + THING_ROOT_STRING, + THING_ROOT_SYMBOL, + THING_ROOT_JIT_CODE, + THING_ROOT_SCRIPT, + THING_ROOT_LAZY_SCRIPT, + THING_ROOT_ID, + THING_ROOT_VALUE, + THING_ROOT_TYPE, + THING_ROOT_BINDINGS, + THING_ROOT_PROPERTY_DESCRIPTOR, + THING_ROOT_PROP_DESC, + THING_ROOT_LIMIT +}; + +/* + * This list enumerates the different types of conceptual stacks we have in + * SpiderMonkey. In reality, they all share the C stack, but we allow different + * stack limits depending on the type of code running. + */ +enum StackKind +{ + StackForSystemCode, // C++, such as the GC, running on behalf of the VM. + StackForTrustedScript, // Script running with trusted principals. + StackForUntrustedScript, // Script running with untrusted principals. + StackKindCount +}; + +template +struct RootKind; + +/* + * Specifically mark the ThingRootKind of externally visible types, so that + * JSAPI users may use JSRooted... types without having the class definition + * available. + */ +template +struct SpecificRootKind +{ + static ThingRootKind rootKind() { return Kind; } +}; + +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; +template <> struct RootKind : SpecificRootKind {}; + +struct ContextFriendFields +{ + protected: + JSRuntime *const runtime_; + + /* The current compartment. */ + JSCompartment *compartment_; + + /* The current zone. */ + JS::Zone *zone_; + + public: + explicit ContextFriendFields(JSRuntime *rt) + : runtime_(rt), compartment_(nullptr), zone_(nullptr), autoGCRooters(nullptr) + { +#ifdef JSGC_TRACK_EXACT_ROOTS + mozilla::PodArrayZero(thingGCRooters); +#endif + } + + static const ContextFriendFields *get(const JSContext *cx) { + return reinterpret_cast(cx); + } + + static ContextFriendFields *get(JSContext *cx) { + return reinterpret_cast(cx); + } + +#ifdef JSGC_TRACK_EXACT_ROOTS + private: + /* + * Stack allocated GC roots for stack GC heap pointers, which may be + * overwritten if moved during a GC. + */ + JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; + + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } + +#endif + + void checkNoGCRooters(); + + /* Stack of thread-stack-allocated GC roots. */ + JS::AutoGCRooter *autoGCRooters; + + friend JSRuntime *GetRuntime(const JSContext *cx); + friend JSCompartment *GetContextCompartment(const JSContext *cx); + friend JS::Zone *GetContextZone(const JSContext *cx); + template friend class JS::Rooted; +}; + +/* + * Inlinable accessors for JSContext. + * + * - These must not be available on the more restricted superclasses of + * JSContext, so we can't simply define them on ContextFriendFields. + * + * - They're perfectly ordinary JSContext functionality, so ought to be + * usable without resorting to jsfriendapi.h, and when JSContext is an + * incomplete type. + */ +inline JSRuntime * +GetRuntime(const JSContext *cx) +{ + return ContextFriendFields::get(cx)->runtime_; +} + +inline JSCompartment * +GetContextCompartment(const JSContext *cx) +{ + return ContextFriendFields::get(cx)->compartment_; +} + +inline JS::Zone * +GetContextZone(const JSContext *cx) +{ + return ContextFriendFields::get(cx)->zone_; +} + +class PerThreadData; + +struct PerThreadDataFriendFields +{ + private: + // Note: this type only exists to permit us to derive the offset of + // the perThread data within the real JSRuntime* type in a portable + // way. + struct RuntimeDummy : JS::shadow::Runtime + { + struct PerThreadDummy { + void *field1; + uintptr_t field2; +#ifdef JS_DEBUG + uint64_t field3; +#endif + } mainThread; + }; + + public: + + PerThreadDataFriendFields(); + +#ifdef JSGC_TRACK_EXACT_ROOTS + private: + /* + * Stack allocated GC roots for stack GC heap pointers, which may be + * overwritten if moved during a GC. + */ + JS::Rooted *thingGCRooters[THING_ROOT_LIMIT]; + + public: + template + inline JS::Rooted *gcRooters() { + js::ThingRootKind kind = RootKind::rootKind(); + return reinterpret_cast *>(thingGCRooters[kind]); + } +#endif + + /* Limit pointer for checking native stack consumption. */ + uintptr_t nativeStackLimit[StackKindCount]; + + static const size_t RuntimeMainThreadOffset = offsetof(RuntimeDummy, mainThread); + + static inline PerThreadDataFriendFields *get(js::PerThreadData *pt) { + return reinterpret_cast(pt); + } + + static inline PerThreadDataFriendFields *getMainThread(JSRuntime *rt) { + // mainThread must always appear directly after |JS::shadow::Runtime|. + // Tested by a JS_STATIC_ASSERT in |jsfriendapi.cpp| + return reinterpret_cast( + reinterpret_cast(rt) + RuntimeMainThreadOffset); + } + + static inline const PerThreadDataFriendFields *getMainThread(const JSRuntime *rt) { + // mainThread must always appear directly after |JS::shadow::Runtime|. + // Tested by a JS_STATIC_ASSERT in |jsfriendapi.cpp| + return reinterpret_cast( + reinterpret_cast(rt) + RuntimeMainThreadOffset); + } + + template friend class JS::Rooted; +}; + +} /* namespace js */ + +#endif /* jspubtd_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jstypes.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jstypes.h new file mode 100644 index 0000000000..e9927bca0d --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jstypes.h @@ -0,0 +1,226 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* +** File: jstypes.h +** Description: Definitions of NSPR's basic types +** +** Prototypes and macros used to make up for deficiencies in ANSI environments +** that we have found. +** +** Since we do not wrap and all the other standard headers, authors +** of portable code will not know in general that they need these definitions. +** Instead of requiring these authors to find the dependent uses in their code +** and take the following steps only in those C files, we take steps once here +** for all C files. +**/ + +#ifndef jstypes_h +#define jstypes_h + +#include "mozilla/Attributes.h" +#include "mozilla/Types.h" + +// jstypes.h is (or should be!) included by every file in SpiderMonkey. +// js-config.h and jsversion.h also should be included by every file. +// So include them here. +// XXX: including them in js/RequiredDefines.h should be a better option, since +// that is by definition the header file that should be included in all +// SpiderMonkey code. However, Gecko doesn't do this! See bug 909576. +#include "js-config.h" +#include "jsversion.h" + +/*********************************************************************** +** MACROS: JS_EXTERN_API +** JS_EXPORT_API +** DESCRIPTION: +** These are only for externally visible routines and globals. For +** internal routines, just use "extern" for type checking and that +** will not export internal cross-file or forward-declared symbols. +** Define a macro for declaring procedures return types. We use this to +** deal with windoze specific type hackery for DLL definitions. Use +** JS_EXTERN_API when the prototype for the method is declared. Use +** JS_EXPORT_API for the implementation of the method. +** +** Example: +** in dowhim.h +** JS_EXTERN_API( void ) DoWhatIMean( void ); +** in dowhim.c +** JS_EXPORT_API( void ) DoWhatIMean( void ) { return; } +** +** +***********************************************************************/ + +#define JS_EXTERN_API(type) extern MOZ_EXPORT type +#define JS_EXPORT_API(type) MOZ_EXPORT type +#define JS_EXPORT_DATA(type) MOZ_EXPORT type +#define JS_IMPORT_API(type) MOZ_IMPORT_API type +#define JS_IMPORT_DATA(type) MOZ_IMPORT_DATA type + +/* + * The linkage of JS API functions differs depending on whether the file is + * used within the JS library or not. Any source file within the JS + * interpreter should define EXPORT_JS_API whereas any client of the library + * should not. STATIC_JS_API is used to build JS as a static library. + */ +#if defined(STATIC_JS_API) +# define JS_PUBLIC_API(t) t +# define JS_PUBLIC_DATA(t) t +#elif defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API) +# define JS_PUBLIC_API(t) MOZ_EXPORT t +# define JS_PUBLIC_DATA(t) MOZ_EXPORT t +#else +# define JS_PUBLIC_API(t) MOZ_IMPORT_API t +# define JS_PUBLIC_DATA(t) MOZ_IMPORT_DATA t +#endif + +#if defined(STATIC_JS_API) || defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API) +# define JS_FRIEND_API(t) MOZ_EXPORT t +# define JS_FRIEND_DATA(t) MOZ_EXPORT t +#else +# define JS_FRIEND_API(t) MOZ_IMPORT_API t +# define JS_FRIEND_DATA(t) MOZ_IMPORT_DATA t +#endif + +#if defined(_MSC_VER) && defined(_M_IX86) +#define JS_FASTCALL __fastcall +#elif defined(__GNUC__) && defined(__i386__) +#define JS_FASTCALL __attribute__((fastcall)) +#else +#define JS_FASTCALL +#define JS_NO_FASTCALL +#endif + +/*********************************************************************** +** MACROS: JS_BEGIN_MACRO +** JS_END_MACRO +** DESCRIPTION: +** Macro body brackets so that macros with compound statement definitions +** behave syntactically more like functions when called. +***********************************************************************/ +#define JS_BEGIN_MACRO do { + +#if defined(_MSC_VER) && _MSC_VER >= 1400 +# define JS_END_MACRO \ + } __pragma(warning(push)) __pragma(warning(disable:4127)) \ + while (0) __pragma(warning(pop)) +#else +# define JS_END_MACRO } while (0) +#endif + +/*********************************************************************** +** MACROS: JS_BIT +** JS_BITMASK +** DESCRIPTION: +** Bit masking macros. XXX n must be <= 31 to be portable +***********************************************************************/ +#define JS_BIT(n) ((uint32_t)1 << (n)) +#define JS_BITMASK(n) (JS_BIT(n) - 1) + +/*********************************************************************** +** MACROS: JS_HOWMANY +** JS_ROUNDUP +** DESCRIPTION: +** Commonly used macros for operations on compatible types. +***********************************************************************/ +#define JS_HOWMANY(x,y) (((x)+(y)-1)/(y)) +#define JS_ROUNDUP(x,y) (JS_HOWMANY(x,y)*(y)) + +#include "jscpucfg.h" + +/* + * Define JS_64BIT iff we are building in an environment with 64-bit + * addresses. + */ +#ifdef _MSC_VER +# if defined(_M_X64) || defined(_M_AMD64) +# define JS_64BIT +# endif +#elif defined(__GNUC__) +/* Additional GCC defines are when running on Solaris, AIX, and HPUX */ +# if defined(__x86_64__) || defined(__sparcv9) || \ + defined(__64BIT__) || defined(__LP64__) +# define JS_64BIT +# endif +#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* Sun Studio C/C++ */ +# if defined(__x86_64) || defined(__sparcv9) +# define JS_64BIT +# endif +#elif defined(__xlc__) || defined(__xlC__) /* IBM XL C/C++ */ +# if defined(__64BIT__) +# define JS_64BIT +# endif +#elif defined(__HP_cc) || defined(__HP_aCC) /* HP-UX cc/aCC */ +# if defined(__LP64__) +# define JS_64BIT +# endif +#else +# error "Implement me" +#endif + +/*********************************************************************** +** MACROS: JS_ARRAY_LENGTH +** JS_ARRAY_END +** DESCRIPTION: +** Macros to get the number of elements and the pointer to one past the +** last element of a C array. Use them like this: +** +** jschar buf[10], *s; +** JSString *str; +** ... +** for (s = buf; s != JS_ARRAY_END(buf); ++s) *s = ...; +** ... +** str = JS_NewStringCopyN(cx, buf, JS_ARRAY_LENGTH(buf)); +** ... +** +***********************************************************************/ + +#define JS_ARRAY_LENGTH(array) (sizeof (array) / sizeof (array)[0]) +#define JS_ARRAY_END(array) ((array) + JS_ARRAY_LENGTH(array)) + +#define JS_BITS_PER_BYTE 8 +#define JS_BITS_PER_BYTE_LOG2 3 + +#if defined(JS_64BIT) +# define JS_BITS_PER_WORD 64 +#else +# define JS_BITS_PER_WORD 32 +#endif + +/*********************************************************************** +** MACROS: JS_FUNC_TO_DATA_PTR +** JS_DATA_TO_FUNC_PTR +** DESCRIPTION: +** Macros to convert between function and data pointers assuming that +** they have the same size. Use them like this: +** +** JSPropertyOp nativeGetter; +** JSObject *scriptedGetter; +** ... +** scriptedGetter = JS_FUNC_TO_DATA_PTR(JSObject *, nativeGetter); +** ... +** nativeGetter = JS_DATA_TO_FUNC_PTR(JSPropertyOp, scriptedGetter); +** +***********************************************************************/ + +#ifdef __GNUC__ +# define JS_FUNC_TO_DATA_PTR(type, fun) (__extension__ (type) (size_t) (fun)) +# define JS_DATA_TO_FUNC_PTR(type, ptr) (__extension__ (type) (size_t) (ptr)) +#else +/* Use an extra (void *) cast for MSVC. */ +# define JS_FUNC_TO_DATA_PTR(type, fun) ((type) (void *) (fun)) +# define JS_DATA_TO_FUNC_PTR(type, ptr) ((type) (void *) (ptr)) +#endif + +#ifdef __GNUC__ +# define JS_EXTENSION __extension__ +# define JS_EXTENSION_(s) __extension__ ({ s; }) +#else +# define JS_EXTENSION +# define JS_EXTENSION_(s) s +#endif + +#endif /* jstypes_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsversion.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsversion.h new file mode 100644 index 0000000000..1f31e40b5e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jsversion.h @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jsversion_h +#define jsversion_h + +/* + * JS Capability Macros. + */ +#define JS_HAS_STR_HTML_HELPERS 1 /* has str.anchor, str.bold, etc. */ +#define JS_HAS_OBJ_PROTO_PROP 1 /* has o.__proto__ etc. */ +#define JS_HAS_OBJ_WATCHPOINT 1 /* has o.watch and o.unwatch */ +#define JS_HAS_TOSOURCE 1 /* has Object/Array toSource method */ +#define JS_HAS_CATCH_GUARD 1 /* has exception handling catch guard */ +#define JS_HAS_UNEVAL 1 /* has uneval() top-level function */ +#define JS_HAS_CONST 1 /* has JS2 const as alternative var */ +#define JS_HAS_FUN_EXPR_STMT 1 /* has function expression statement */ +#define JS_HAS_NO_SUCH_METHOD 1 /* has o.__noSuchMethod__ handler */ +#define JS_HAS_FOR_EACH_IN 1 /* has for each (lhs in iterable) */ +#define JS_HAS_GENERATORS 1 /* has yield in generator function */ +#define JS_HAS_BLOCK_SCOPE 1 /* has block scope via let/arraycomp */ +#define JS_HAS_DESTRUCTURING 2 /* has [a,b] = ... or {p:a,q:b} = ... */ +#define JS_HAS_GENERATOR_EXPRS 1 /* has (expr for (lhs in iterable)) */ +#define JS_HAS_EXPR_CLOSURES 1 /* has function (formals) listexpr */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_TEMPLATE_STRINGS 1 /* has template string support */ +#endif + +/* Support for JS_NewGlobalObject. */ +#define JS_HAS_NEW_GLOBAL_OBJECT 1 + +/* Support for JS_MakeSystemObject. */ +#define JS_HAS_MAKE_SYSTEM_OBJECT 1 + +/* Feature-test macro for evolving destructuring support. */ +#define JS_HAS_DESTRUCTURING_SHORTHAND (JS_HAS_DESTRUCTURING == 2) + +/* + * Feature for Object.prototype.__{define,lookup}{G,S}etter__ legacy support; + * support likely to be made opt-in at some future time. + */ +#define JS_OLD_GETTER_SETTER_METHODS 1 + +/* Support for Symbols - Nightly-only for now. */ +#ifdef NIGHTLY_BUILD +#define JS_HAS_SYMBOLS 1 +#endif + +#endif /* jsversion_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jswrapper.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jswrapper.h new file mode 100644 index 0000000000..a8a510c4f7 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/jswrapper.h @@ -0,0 +1,337 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef jswrapper_h +#define jswrapper_h + +#include "mozilla/Attributes.h" + +#include "jsproxy.h" + +namespace js { + +class DummyFrameGuard; + +/* + * Helper for Wrapper::New default options. + * + * Callers of Wrapper::New() who wish to specify a prototype for the created + * Wrapper, *MUST* construct a WrapperOptions with a JSContext. + */ +class MOZ_STACK_CLASS WrapperOptions : public ProxyOptions { + public: + WrapperOptions() : ProxyOptions(false, nullptr), + proto_() + {} + + explicit WrapperOptions(JSContext *cx) : ProxyOptions(false, nullptr), + proto_() + { + proto_.construct(cx); + } + + inline JSObject *proto() const; + WrapperOptions &setProto(JSObject *protoArg) { + JS_ASSERT(!proto_.empty()); + proto_.ref() = protoArg; + return *this; + } + + private: + mozilla::Maybe proto_; +}; + +/* + * A wrapper is a proxy with a target object to which it generally forwards + * operations, but may restrict access to certain operations or instrument + * the trap operations in various ways. A wrapper is distinct from a Direct Proxy + * Handler in the sense that it can be "unwrapped" in C++, exposing the underlying + * object (Direct Proxy Handlers have an underlying target object, but don't + * expect to expose this object via any kind of unwrapping operation). Callers + * should be careful to avoid unwrapping security wrappers in the wrong context. + */ +class JS_FRIEND_API(Wrapper) : public DirectProxyHandler +{ + unsigned mFlags; + + public: + using BaseProxyHandler::Action; + + enum Flags { + CROSS_COMPARTMENT = 1 << 0, + LAST_USED_FLAG = CROSS_COMPARTMENT + }; + + virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, + MutableHandleValue vp) const MOZ_OVERRIDE; + + static JSObject *New(JSContext *cx, JSObject *obj, JSObject *parent, const Wrapper *handler, + const WrapperOptions *options = nullptr); + + static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, const Wrapper *handler); + + static const Wrapper *wrapperHandler(JSObject *wrapper); + + static JSObject *wrappedObject(JSObject *wrapper); + + unsigned flags() const { + return mFlags; + } + + explicit Wrapper(unsigned flags, bool hasPrototype = false, bool hasSecurityPolicy = false); + + virtual ~Wrapper(); + + virtual bool finalizeInBackground(Value priv) const MOZ_OVERRIDE; + + static const Wrapper singleton; + static const Wrapper singletonWithPrototype; + + static JSObject *defaultProto; +}; + +inline JSObject * +WrapperOptions::proto() const +{ + return proto_.empty() ? Wrapper::defaultProto : proto_.ref(); +} + +/* Base class for all cross compartment wrapper handlers. */ +class JS_FRIEND_API(CrossCompartmentWrapper) : public Wrapper +{ + public: + explicit CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false, + bool hasSecurityPolicy = false); + + virtual ~CrossCompartmentWrapper(); + + /* ES5 Harmony fundamental wrapper traps. */ + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; + virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; + + /* ES5 Harmony derived wrapper traps. */ + virtual bool has(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool hasOwn(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool get(JSContext *cx, HandleObject wrapper, HandleObject receiver, + HandleId id, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool set(JSContext *cx, HandleObject wrapper, HandleObject receiver, + HandleId id, bool strict, MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool keys(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool iterate(JSContext *cx, HandleObject wrapper, unsigned flags, + MutableHandleValue vp) const MOZ_OVERRIDE; + + /* Spidermonkey extensions. */ + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject wrapper, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, + CallArgs args) const MOZ_OVERRIDE; + virtual bool hasInstance(JSContext *cx, HandleObject wrapper, MutableHandleValue v, + bool *bp) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual JSString *fun_toString(JSContext *cx, HandleObject wrapper, + unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; + virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, + MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; + + static const CrossCompartmentWrapper singleton; + static const CrossCompartmentWrapper singletonWithPrototype; +}; + +/* + * Base class for security wrappers. A security wrapper is potentially hiding + * all or part of some wrapped object thus SecurityWrapper defaults to denying + * access to the wrappee. This is the opposite of Wrapper which tries to be + * completely transparent. + * + * NB: Currently, only a few ProxyHandler operations are overridden to deny + * access, relying on derived SecurityWrapper to block access when necessary. + */ +template +class JS_FRIEND_API(SecurityWrapper) : public Base +{ + public: + explicit SecurityWrapper(unsigned flags, bool hasPrototype = false); + + virtual bool isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const MOZ_OVERRIDE; + virtual bool preventExtensions(JSContext *cx, HandleObject wrapper) const MOZ_OVERRIDE; + virtual bool enter(JSContext *cx, HandleObject wrapper, HandleId id, Wrapper::Action act, + bool *bp) const MOZ_OVERRIDE; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, + CallArgs args) const MOZ_OVERRIDE; + virtual bool defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, + MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, + JSContext *cx) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; + virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + + virtual bool setPrototypeOf(JSContext *cx, HandleObject proxy, HandleObject proto, + bool *bp) const MOZ_OVERRIDE; + + virtual bool watch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, + JS::HandleObject callable) const MOZ_OVERRIDE; + virtual bool unwatch(JSContext *cx, JS::HandleObject proxy, JS::HandleId id) const MOZ_OVERRIDE; + + /* + * Allow our subclasses to select the superclass behavior they want without + * needing to specify an exact superclass. + */ + typedef Base Permissive; + typedef SecurityWrapper Restrictive; +}; + +typedef SecurityWrapper SameCompartmentSecurityWrapper; +typedef SecurityWrapper CrossCompartmentSecurityWrapper; + +class JS_FRIEND_API(DeadObjectProxy) : public BaseProxyHandler +{ + public: + // This variable exists solely to provide a unique address for use as an identifier. + static const char sDeadObjectFamily; + + explicit DeadObjectProxy(); + + /* ES5 Harmony fundamental wrapper traps. */ + virtual bool preventExtensions(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual bool getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id, + MutableHandle desc) const MOZ_OVERRIDE; + virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, + AutoIdVector &props) const MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) const MOZ_OVERRIDE; + virtual bool enumerate(JSContext *cx, HandleObject wrapper, AutoIdVector &props) const MOZ_OVERRIDE; + + /* Spidermonkey extensions. */ + virtual bool isExtensible(JSContext *cx, HandleObject proxy, bool *extensible) const MOZ_OVERRIDE; + virtual bool call(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool construct(JSContext *cx, HandleObject proxy, const CallArgs &args) const MOZ_OVERRIDE; + virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, + CallArgs args) const MOZ_OVERRIDE; + virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, + bool *bp) const MOZ_OVERRIDE; + virtual bool objectClassIs(HandleObject obj, ESClassValue classValue, + JSContext *cx) const MOZ_OVERRIDE; + virtual const char *className(JSContext *cx, HandleObject proxy) const MOZ_OVERRIDE; + virtual JSString *fun_toString(JSContext *cx, HandleObject proxy, unsigned indent) const MOZ_OVERRIDE; + virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) const MOZ_OVERRIDE; + virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, + MutableHandleValue vp) const MOZ_OVERRIDE; + virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, + MutableHandleObject protop) const MOZ_OVERRIDE; + + static const DeadObjectProxy singleton; +}; + +extern JSObject * +TransparentObjectWrapper(JSContext *cx, HandleObject existing, HandleObject obj, + HandleObject parent, unsigned flags); + +// Proxy family for wrappers. Public so that IsWrapper() can be fully inlined by +// jsfriendapi users. +// This variable exists solely to provide a unique address for use as an identifier. +extern JS_FRIEND_DATA(const char) sWrapperFamily; + +inline bool +IsWrapper(JSObject *obj) +{ + return IsProxy(obj) && GetProxyHandler(obj)->family() == &sWrapperFamily; +} + +// Given a JSObject, returns that object stripped of wrappers. If +// stopAtOuter is true, then this returns the outer window if it was +// previously wrapped. Otherwise, this returns the first object for +// which JSObject::isWrapper returns false. +JS_FRIEND_API(JSObject *) +UncheckedUnwrap(JSObject *obj, bool stopAtOuter = true, unsigned *flagsp = nullptr); + +// Given a JSObject, returns that object stripped of wrappers. At each stage, +// the security wrapper has the opportunity to veto the unwrap. Since checked +// code should never be unwrapping outer window wrappers, we always stop at +// outer windows. +JS_FRIEND_API(JSObject *) +CheckedUnwrap(JSObject *obj, bool stopAtOuter = true); + +// Unwrap only the outermost security wrapper, with the same semantics as +// above. This is the checked version of Wrapper::wrappedObject. +JS_FRIEND_API(JSObject *) +UnwrapOneChecked(JSObject *obj, bool stopAtOuter = true); + +JS_FRIEND_API(bool) +IsCrossCompartmentWrapper(JSObject *obj); + +bool +IsDeadProxyObject(JSObject *obj); + +JSObject * +NewDeadProxyObject(JSContext *cx, JSObject *parent, + const ProxyOptions &options = ProxyOptions()); + +void +NukeCrossCompartmentWrapper(JSContext *cx, JSObject *wrapper); + +bool +RemapWrapper(JSContext *cx, JSObject *wobj, JSObject *newTarget); + +JS_FRIEND_API(bool) +RemapAllWrappersForObject(JSContext *cx, JSObject *oldTarget, + JSObject *newTarget); + +// API to recompute all cross-compartment wrappers whose source and target +// match the given filters. +JS_FRIEND_API(bool) +RecomputeWrappers(JSContext *cx, const CompartmentFilter &sourceFilter, + const CompartmentFilter &targetFilter); + +/* + * This auto class should be used around any code, such as brain transplants, + * that may touch dead zones. Brain transplants can cause problems + * because they operate on all compartments, whether live or dead. A brain + * transplant can cause a formerly dead object to be "reanimated" by causing a + * read or write barrier to be invoked on it during the transplant. In this way, + * a zone becomes a zombie, kept alive by repeatedly consuming + * (transplanted) brains. + * + * To work around this issue, we observe when mark bits are set on objects in + * dead zones. If this happens during a brain transplant, we do a full, + * non-incremental GC at the end of the brain transplant. This will clean up any + * objects that were improperly marked. + */ +struct JS_FRIEND_API(AutoMaybeTouchDeadZones) +{ + // The version that takes an object just uses it for its runtime. + explicit AutoMaybeTouchDeadZones(JSContext *cx); + explicit AutoMaybeTouchDeadZones(JSObject *obj); + ~AutoMaybeTouchDeadZones(); + + private: + JSRuntime *runtime; + unsigned markCount; + bool inIncremental; + bool manipulatingDeadZones; +}; + +} /* namespace js */ + +#endif /* jswrapper_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Alignment.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Alignment.h new file mode 100644 index 0000000000..0ac8a48779 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Alignment.h @@ -0,0 +1,139 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Functionality related to memory alignment. */ + +#ifndef mozilla_Alignment_h +#define mozilla_Alignment_h + +#include +#include + +namespace mozilla { + +/* + * This class, and the corresponding macro MOZ_ALIGNOF, figures out how many + * bytes of alignment a given type needs. + */ +template +class AlignmentFinder +{ + struct Aligner + { + char mChar; + T mT; + }; + +public: + static const size_t alignment = sizeof(Aligner) - sizeof(T); +}; + +#define MOZ_ALIGNOF(T) mozilla::AlignmentFinder::alignment + +/* + * Declare the MOZ_ALIGNED_DECL macro for declaring aligned types. + * + * For instance, + * + * MOZ_ALIGNED_DECL(char arr[2], 8); + * + * will declare a two-character array |arr| aligned to 8 bytes. + */ + +#if defined(__GNUC__) +# define MOZ_ALIGNED_DECL(_type, _align) \ + _type __attribute__((aligned(_align))) +#elif defined(_MSC_VER) +# define MOZ_ALIGNED_DECL(_type, _align) \ + __declspec(align(_align)) _type +#else +# warning "We don't know how to align variables on this compiler." +# define MOZ_ALIGNED_DECL(_type, _align) _type +#endif + +/* + * AlignedElem is a structure whose alignment is guaranteed to be at least N + * bytes. + * + * We support 1, 2, 4, 8, and 16-bit alignment. + */ +template +struct AlignedElem; + +/* + * We have to specialize this template because GCC doesn't like + * __attribute__((aligned(foo))) where foo is a template parameter. + */ + +template<> +struct AlignedElem<1> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 1); +}; + +template<> +struct AlignedElem<2> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 2); +}; + +template<> +struct AlignedElem<4> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 4); +}; + +template<> +struct AlignedElem<8> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 8); +}; + +template<> +struct AlignedElem<16> +{ + MOZ_ALIGNED_DECL(uint8_t elem, 16); +}; + +/* + * This utility pales in comparison to Boost's aligned_storage. The utility + * simply assumes that uint64_t is enough alignment for anyone. This may need + * to be extended one day... + * + * As an important side effect, pulling the storage into this template is + * enough obfuscation to confuse gcc's strict-aliasing analysis into not giving + * false negatives when we cast from the char buffer to whatever type we've + * constructed using the bytes. + */ +template +struct AlignedStorage +{ + union U + { + char mBytes[Nbytes]; + uint64_t mDummy; + } u; + + const void* addr() const { return u.mBytes; } + void* addr() { return u.mBytes; } +}; + +template +struct AlignedStorage2 +{ + union U + { + char mBytes[sizeof(T)]; + uint64_t mDummy; + } u; + + const T* addr() const { return reinterpret_cast(u.mBytes); } + T* addr() { return static_cast(static_cast(u.mBytes)); } +}; + +} /* namespace mozilla */ + +#endif /* mozilla_Alignment_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/AllocPolicy.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/AllocPolicy.h new file mode 100644 index 0000000000..357c632a02 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/AllocPolicy.h @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * An allocation policy concept, usable for structures and algorithms to + * control how memory is allocated and how failures are handled. + */ + +#ifndef mozilla_AllocPolicy_h +#define mozilla_AllocPolicy_h + +#include +#include + +namespace mozilla { + +/* + * Allocation policies are used to implement the standard allocation behaviors + * in a customizable way. Additionally, custom behaviors may be added to these + * behaviors, such as additionally reporting an error through an out-of-band + * mechanism when OOM occurs. The concept modeled here is as follows: + * + * - public copy constructor, assignment, destructor + * - void* malloc_(size_t) + * Responsible for OOM reporting when null is returned. + * - void* calloc_(size_t) + * Responsible for OOM reporting when null is returned. + * - void* realloc_(void*, size_t, size_t) + * Responsible for OOM reporting when null is returned. The *used* bytes + * of the previous buffer is passed in (rather than the old allocation + * size), in addition to the *new* allocation size requested. + * - void free_(void*) + * - void reportAllocOverflow() const + * Called on allocation overflow (that is, an allocation implicitly tried + * to allocate more than the available memory space -- think allocating an + * array of large-size objects, where N * size overflows) before null is + * returned. + * + * mfbt provides (and typically uses by default) only MallocAllocPolicy, which + * does nothing more than delegate to the malloc/alloc/free functions. + */ + +/* + * A policy that straightforwardly uses malloc/calloc/realloc/free and adds no + * extra behaviors. + */ +class MallocAllocPolicy +{ +public: + void* malloc_(size_t aBytes) + { + return malloc(aBytes); + } + + void* calloc_(size_t aBytes) + { + return calloc(aBytes, 1); + } + + void* realloc_(void* aPtr, size_t aOldBytes, size_t aBytes) + { + return realloc(aPtr, aBytes); + } + + void free_(void* aPtr) + { + free(aPtr); + } + + void reportAllocOverflow() const + { + } +}; + +} // namespace mozilla + +#endif /* mozilla_AllocPolicy_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Array.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Array.h new file mode 100644 index 0000000000..b2ab578d4b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Array.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A compile-time constant-length array with bounds-checking assertions. */ + +#ifndef mozilla_Array_h +#define mozilla_Array_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" + +#include + +namespace mozilla { + +template +class Array +{ + T mArr[Length]; + +public: + T& operator[](size_t aIndex) + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } + + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(aIndex < Length); + return mArr[aIndex]; + } +}; + +template +class Array +{ +public: + T& operator[](size_t aIndex) + { + MOZ_CRASH("indexing into zero-length array"); + } + + const T& operator[](size_t aIndex) const + { + MOZ_CRASH("indexing into zero-length array"); + } +}; + +} /* namespace mozilla */ + +#endif /* mozilla_Array_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/ArrayUtils.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/ArrayUtils.h new file mode 100644 index 0000000000..44f5980c44 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/ArrayUtils.h @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements various helper functions related to arrays. + */ + +#ifndef mozilla_ArrayUtils_h +#define mozilla_ArrayUtils_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" + +#include + +#ifdef __cplusplus + +#include "mozilla/Alignment.h" +#include "mozilla/Array.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +/* + * Safely subtract two pointers when it is known that aEnd >= aBegin. This + * avoids the common compiler bug that if (size_t(aEnd) - size_t(aBegin)) has + * the MSB set, the unsigned subtraction followed by right shift will produce + * -1, or size_t(-1), instead of the real difference. + */ +template +MOZ_ALWAYS_INLINE size_t +PointerRangeSize(T* aBegin, T* aEnd) +{ + MOZ_ASSERT(aEnd >= aBegin); + return (size_t(aEnd) - size_t(aBegin)) / sizeof(T); +} + +/* + * Compute the length of an array with constant length. (Use of this method + * with a non-array pointer will not compile.) + * + * Beware of the implicit trailing '\0' when using this with string constants. + */ +template +MOZ_CONSTEXPR size_t +ArrayLength(T (&aArr)[N]) +{ + return N; +} + +template +MOZ_CONSTEXPR size_t +ArrayLength(const Array& aArr) +{ + return N; +} + +/* + * Compute the address one past the last element of a constant-length array. + * + * Beware of the implicit trailing '\0' when using this with string constants. + */ +template +MOZ_CONSTEXPR T* +ArrayEnd(T (&aArr)[N]) +{ + return aArr + ArrayLength(aArr); +} + +template +MOZ_CONSTEXPR T* +ArrayEnd(Array& aArr) +{ + return &aArr[0] + ArrayLength(aArr); +} + +template +MOZ_CONSTEXPR const T* +ArrayEnd(const Array& aArr) +{ + return &aArr[0] + ArrayLength(aArr); +} + +namespace detail { + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % MOZ_ALIGNOF(AlignType)) == 0, + "performing a range-check with a misaligned pointer"); + } +}; + +template +struct AlignedChecker +{ + static void + test(Pointee* aPtr) + { + } +}; + +} // namespace detail + +/** + * Determines whether |aPtr| points at an object in the range [aBegin, aEnd). + * + * |aPtr| must have the same alignment as |aBegin| and |aEnd|. This usually + * should be achieved by ensuring |aPtr| points at a |U|, not just that it + * points at a |T|. + * + * It is a usage error for any argument to be misaligned. + * + * It's okay for T* to be void*, and if so U* may also be void*. In the latter + * case no argument is required to be aligned (obviously, as void* implies no + * particular alignment). + */ +template +inline typename EnableIf::value || + IsBaseOf::value || + IsVoid::value, + bool>::Type +IsInRange(T* aPtr, U* aBegin, U* aEnd) +{ + MOZ_ASSERT(aBegin <= aEnd); + detail::AlignedChecker::test(aPtr); + detail::AlignedChecker::test(aBegin); + detail::AlignedChecker::test(aEnd); + return aBegin <= static_cast(aPtr) && static_cast(aPtr) < aEnd; +} + +/** + * Convenience version of the above method when the valid range is specified as + * uintptr_t values. As above, |aPtr| must be aligned, and |aBegin| and |aEnd| + * must be aligned with respect to |T|. + */ +template +inline bool +IsInRange(T* aPtr, uintptr_t aBegin, uintptr_t aEnd) +{ + return IsInRange(aPtr, + reinterpret_cast(aBegin), reinterpret_cast(aEnd)); +} + +namespace detail { + +/* + * Helper for the MOZ_ARRAY_LENGTH() macro to make the length a typesafe + * compile-time constant even on compilers lacking constexpr support. + */ +template +char (&ArrayLengthHelper(T (&array)[N]))[N]; + +} /* namespace detail */ + +} /* namespace mozilla */ + +#endif /* __cplusplus */ + +/* + * MOZ_ARRAY_LENGTH() is an alternative to mozilla::ArrayLength() for C files + * that can't use C++ template functions and for static_assert() calls that + * can't call ArrayLength() when it is not a C++11 constexpr function. + */ +#ifdef __cplusplus +# define MOZ_ARRAY_LENGTH(array) sizeof(mozilla::detail::ArrayLengthHelper(array)) +#else +# define MOZ_ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0])) +#endif + +#endif /* mozilla_ArrayUtils_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Assertions.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Assertions.h new file mode 100644 index 0000000000..34b0d7d534 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Assertions.h @@ -0,0 +1,534 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implementations of runtime and static assertion macros for C and C++. */ + +#ifndef mozilla_Assertions_h +#define mozilla_Assertions_h +#include +#if defined(MOZILLA_INTERNAL_API) && defined(__cplusplus) +#define MOZ_DUMP_ASSERTION_STACK +#endif + +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/Likely.h" +#include "mozilla/MacroArgs.h" +#ifdef MOZ_DUMP_ASSERTION_STACK +#include "nsTraceRefcnt.h" +#endif + +#include +#include +#include +#ifdef WIN32 + /* + * TerminateProcess and GetCurrentProcess are defined in , which + * further depends on . We hardcode these few definitions manually + * because those headers clutter the global namespace with a significant + * number of undesired macros and symbols. + */ +# ifdef __cplusplus +extern "C" { +# endif +__declspec(dllimport) int __stdcall +TerminateProcess(void* hProcess, unsigned int uExitCode); +__declspec(dllimport) void* __stdcall GetCurrentProcess(void); +# ifdef __cplusplus +} +# endif +#else +# include +#endif +#ifdef ANDROID +# include +#endif + +/* + * MOZ_STATIC_ASSERT may be used to assert a condition *at compile time* in C. + * In C++11, static_assert is provided by the compiler to the same effect. + * This can be useful when you make certain assumptions about what must hold for + * optimal, or even correct, behavior. For example, you might assert that the + * size of a struct is a multiple of the target architecture's word size: + * + * struct S { ... }; + * // C + * MOZ_STATIC_ASSERT(sizeof(S) % sizeof(size_t) == 0, + * "S should be a multiple of word size for efficiency"); + * // C++11 + * static_assert(sizeof(S) % sizeof(size_t) == 0, + * "S should be a multiple of word size for efficiency"); + * + * This macro can be used in any location where both an extern declaration and a + * typedef could be used. + */ +#ifndef __cplusplus + /* + * Some of the definitions below create an otherwise-unused typedef. This + * triggers compiler warnings with some versions of gcc, so mark the typedefs + * as permissibly-unused to disable the warnings. + */ +# if defined(__GNUC__) +# define MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused)) +# else +# define MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE /* nothing */ +# endif +# define MOZ_STATIC_ASSERT_GLUE1(x, y) x##y +# define MOZ_STATIC_ASSERT_GLUE(x, y) MOZ_STATIC_ASSERT_GLUE1(x, y) +# if defined(__SUNPRO_CC) + /* + * The Sun Studio C++ compiler is buggy when declaring, inside a function, + * another extern'd function with an array argument whose length contains a + * sizeof, triggering the error message "sizeof expression not accepted as + * size of array parameter". This bug (6688515, not public yet) would hit + * defining moz_static_assert as a function, so we always define an extern + * array for Sun Studio. + * + * We include the line number in the symbol name in a best-effort attempt + * to avoid conflicts (see below). + */ +# define MOZ_STATIC_ASSERT(cond, reason) \ + extern char MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __LINE__)[(cond) ? 1 : -1] +# elif defined(__COUNTER__) + /* + * If there was no preferred alternative, use a compiler-agnostic version. + * + * Note that the non-__COUNTER__ version has a bug in C++: it can't be used + * in both |extern "C"| and normal C++ in the same translation unit. (Alas + * |extern "C"| isn't allowed in a function.) The only affected compiler + * we really care about is gcc 4.2. For that compiler and others like it, + * we include the line number in the function name to do the best we can to + * avoid conflicts. These should be rare: a conflict would require use of + * MOZ_STATIC_ASSERT on the same line in separate files in the same + * translation unit, *and* the uses would have to be in code with + * different linkage, *and* the first observed use must be in C++-linkage + * code. + */ +# define MOZ_STATIC_ASSERT(cond, reason) \ + typedef int MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __COUNTER__)[(cond) ? 1 : -1] MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE +# else +# define MOZ_STATIC_ASSERT(cond, reason) \ + extern void MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __LINE__)(int arg[(cond) ? 1 : -1]) MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE +# endif + +#define MOZ_STATIC_ASSERT_IF(cond, expr, reason) MOZ_STATIC_ASSERT(!(cond) || (expr), reason) +#else +#define MOZ_STATIC_ASSERT_IF(cond, expr, reason) static_assert(!(cond) || (expr), reason) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Prints |aStr| as an assertion failure (using aFilename and aLine as the + * location of the assertion) to the standard debug-output channel. + * + * Usually you should use MOZ_ASSERT or MOZ_CRASH instead of this method. This + * method is primarily for internal use in this header, and only secondarily + * for use in implementing release-build assertions. + */ +static MOZ_ALWAYS_INLINE void +MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS +{ +#ifdef ANDROID + __android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert", + "Assertion failure: %s, at %s:%d\n", + aStr, aFilename, aLine); +#else + fprintf(stderr, "Assertion failure: %s, at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif + fflush(stderr); +#endif +} + +static MOZ_ALWAYS_INLINE void +MOZ_ReportCrash(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS +{ +#ifdef ANDROID + __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", + "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); +#else + fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); +#ifdef MOZ_DUMP_ASSERTION_STACK + nsTraceRefcnt::WalkTheStack(stderr); +#endif + fflush(stderr); +#endif +} + +/** + * MOZ_REALLY_CRASH is used in the implementation of MOZ_CRASH(). You should + * call MOZ_CRASH instead. + */ +#if defined(_MSC_VER) + /* + * On MSVC use the __debugbreak compiler intrinsic, which produces an inline + * (not nested in a system function) breakpoint. This distinctively invokes + * Breakpad without requiring system library symbols on all stack-processing + * machines, as a nested breakpoint would require. + * + * We use TerminateProcess with the exit code aborting would generate + * because we don't want to invoke atexit handlers, destructors, library + * unload handlers, and so on when our process might be in a compromised + * state. + * + * We don't use abort() because it'd cause Windows to annoyingly pop up the + * process error dialog multiple times. See bug 345118 and bug 426163. + * + * We follow TerminateProcess() with a call to MOZ_NoReturn() so that the + * compiler doesn't hassle us to provide a return statement after a + * MOZ_REALLY_CRASH() call. + * + * (Technically these are Windows requirements, not MSVC requirements. But + * practically you need MSVC for debugging, and we only ship builds created + * by MSVC, so doing it this way reduces complexity.) + */ + +__declspec(noreturn) __inline void MOZ_NoReturn() {} + +# ifdef __cplusplus +# define MOZ_REALLY_CRASH() \ + do { \ + ::__debugbreak(); \ + *((volatile int*) NULL) = 123; \ + ::TerminateProcess(::GetCurrentProcess(), 3); \ + ::MOZ_NoReturn(); \ + } while (0) +# else +# define MOZ_REALLY_CRASH() \ + do { \ + __debugbreak(); \ + *((volatile int*) NULL) = 123; \ + TerminateProcess(GetCurrentProcess(), 3); \ + MOZ_NoReturn(); \ + } while (0) +# endif +#else +# ifdef __cplusplus +# define MOZ_REALLY_CRASH() \ + do { \ + *((volatile int*) NULL) = 123; \ + ::abort(); \ + } while (0) +# else +# define MOZ_REALLY_CRASH() \ + do { \ + *((volatile int*) NULL) = 123; \ + abort(); \ + } while (0) +# endif +#endif + +/* + * MOZ_CRASH([explanation-string]) crashes the program, plain and simple, in a + * Breakpad-compatible way, in both debug and release builds. + * + * MOZ_CRASH is a good solution for "handling" failure cases when you're + * unwilling or unable to handle them more cleanly -- for OOM, for likely memory + * corruption, and so on. It's also a good solution if you need safe behavior + * in release builds as well as debug builds. But if the failure is one that + * should be debugged and fixed, MOZ_ASSERT is generally preferable. + * + * The optional explanation-string, if provided, must be a string literal + * explaining why we're crashing. This argument is intended for use with + * MOZ_CRASH() calls whose rationale is non-obvious; don't use it if it's + * obvious why we're crashing. + * + * If we're a DEBUG build and we crash at a MOZ_CRASH which provides an + * explanation-string, we print the string to stderr. Otherwise, we don't + * print anything; this is because we want MOZ_CRASH to be 100% safe in release + * builds, and it's hard to print to stderr safely when memory might have been + * corrupted. + */ +#ifndef DEBUG +# define MOZ_CRASH(...) MOZ_REALLY_CRASH() +#else +# define MOZ_CRASH(...) \ + do { \ + MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } while (0) +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* + * MOZ_ASSERT(expr [, explanation-string]) asserts that |expr| must be truthy in + * debug builds. If it is, execution continues. Otherwise, an error message + * including the expression and the explanation-string (if provided) is printed, + * an attempt is made to invoke any existing debugger, and execution halts. + * MOZ_ASSERT is fatal: no recovery is possible. Do not assert a condition + * which can correctly be falsy. + * + * The optional explanation-string, if provided, must be a string literal + * explaining the assertion. It is intended for use with assertions whose + * correctness or rationale is non-obvious, and for assertions where the "real" + * condition being tested is best described prosaically. Don't provide an + * explanation if it's not actually helpful. + * + * // No explanation needed: pointer arguments often must not be NULL. + * MOZ_ASSERT(arg); + * + * // An explanation can be helpful to explain exactly how we know an + * // assertion is valid. + * MOZ_ASSERT(state == WAITING_FOR_RESPONSE, + * "given that and , we must have..."); + * + * // Or it might disambiguate multiple identical (save for their location) + * // assertions of the same expression. + * MOZ_ASSERT(getSlot(PRIMITIVE_THIS_SLOT).isUndefined(), + * "we already set [[PrimitiveThis]] for this Boolean object"); + * MOZ_ASSERT(getSlot(PRIMITIVE_THIS_SLOT).isUndefined(), + * "we already set [[PrimitiveThis]] for this String object"); + * + * MOZ_ASSERT has no effect in non-debug builds. It is designed to catch bugs + * *only* during debugging, not "in the field". If you want the latter, use + * MOZ_RELEASE_ASSERT, which applies to non-debug builds as well. + */ + +/* + * Implement MOZ_VALIDATE_ASSERT_CONDITION_TYPE, which is used to guard against + * accidentally passing something unintended in lieu of an assertion condition. + */ + +#ifdef __cplusplus +# if defined(__clang__) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# elif defined(__GNUC__) +// B2G GCC 4.4 has insufficient decltype support. +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# endif +# elif defined(_MSC_VER) +// Disabled for now because of insufficient decltype support. Bug 1004028. +# endif +#endif + +#ifdef MOZ_SUPPORT_ASSERT_CONDITION_TYPE_VALIDATION +# include "mozilla/TypeTraits.h" +namespace mozilla { +namespace detail { + +template +struct IsFunction +{ + static const bool value = false; +}; + +template +struct IsFunction +{ + static const bool value = true; +}; + +template +void ValidateAssertConditionType() +{ + typedef typename RemoveReference::Type ValueT; + static_assert(!IsArray::value, + "Expected boolean assertion condition, got an array or a " + "string!"); + static_assert(!IsFunction::value, + "Expected boolean assertion condition, got a function! Did " + "you intend to call that function?"); + static_assert(!IsFloatingPoint::value, + "It's often a bad idea to assert that a floating-point number " + "is nonzero, because such assertions tend to intermittently " + "fail. Shouldn't your code gracefully handle this case instead " + "of asserting? Anyway, if you really want to do that, write an " + "explicit boolean condition, like !!x or x!=0."); +} + +} // namespace detail +} // namespace mozilla +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) \ + mozilla::detail::ValidateAssertConditionType() +#else +# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) +#endif + +/* First the single-argument form. */ +#define MOZ_ASSERT_HELPER1(expr) \ + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) +/* Now the two-argument form. */ +#define MOZ_ASSERT_HELPER2(expr, explain) \ + do { \ + MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ + if (MOZ_UNLIKELY(!(expr))) { \ + MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ + MOZ_REALLY_CRASH(); \ + } \ + } while (0) + +#define MOZ_RELEASE_ASSERT_GLUE(a, b) a b +#define MOZ_RELEASE_ASSERT(...) \ + MOZ_RELEASE_ASSERT_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \ + (__VA_ARGS__)) + +#ifdef DEBUG +# define MOZ_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) +#else +# define MOZ_ASSERT(...) do { } while (0) +#endif /* DEBUG */ + +/* + * MOZ_NIGHTLY_ASSERT is defined for both debug and release builds on the + * Nightly channel, but only debug builds on Aurora, Beta, and Release. + */ +#if defined(NIGHTLY_BUILD) +# define MOZ_NIGHTLY_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) +#else +# define MOZ_NIGHTLY_ASSERT(...) MOZ_ASSERT(__VA_ARGS__) +#endif + +/* + * MOZ_ASSERT_IF(cond1, cond2) is equivalent to MOZ_ASSERT(cond2) if cond1 is + * true. + * + * MOZ_ASSERT_IF(isPrime(num), num == 2 || isOdd(num)); + * + * As with MOZ_ASSERT, MOZ_ASSERT_IF has effect only in debug builds. It is + * designed to catch bugs during debugging, not "in the field". + */ +#ifdef DEBUG +# define MOZ_ASSERT_IF(cond, expr) \ + do { \ + if (cond) { \ + MOZ_ASSERT(expr); \ + } \ + } while (0) +#else +# define MOZ_ASSERT_IF(cond, expr) do { } while (0) +#endif + +/* + * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that + * it is undefined behavior for execution to reach this point. No guarantees + * are made about what will happen if this is reached at runtime. Most code + * should use MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE because it has extra + * asserts. + */ +#if defined(__clang__) +# define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable() +#elif defined(__GNUC__) + /* + * __builtin_unreachable() was implemented in gcc 4.5. If we don't have + * that, call a noreturn function; abort() will do nicely. Qualify the call + * in C++ in case there's another abort() visible in local scope. + */ +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable() +# else +# ifdef __cplusplus +# define MOZ_ASSUME_UNREACHABLE_MARKER() ::abort() +# else +# define MOZ_ASSUME_UNREACHABLE_MARKER() abort() +# endif +# endif +#elif defined(_MSC_VER) +# define MOZ_ASSUME_UNREACHABLE_MARKER() __assume(0) +#else +# ifdef __cplusplus +# define MOZ_ASSUME_UNREACHABLE_MARKER() ::abort() +# else +# define MOZ_ASSUME_UNREACHABLE_MARKER() abort() +# endif +#endif + +/* + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE([reason]) tells the compiler that it + * can assume that the macro call cannot be reached during execution. This lets + * the compiler generate better-optimized code under some circumstances, at the + * expense of the program's behavior being undefined if control reaches the + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE. + * + * In Gecko, you probably should not use this macro outside of performance- or + * size-critical code, because it's unsafe. If you don't care about code size + * or performance, you should probably use MOZ_ASSERT or MOZ_CRASH. + * + * SpiderMonkey is a different beast, and there it's acceptable to use + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE more widely. + * + * Note that MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE is noreturn, so it's valid + * not to return a value following a MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE + * call. + * + * Example usage: + * + * enum ValueType { + * VALUE_STRING, + * VALUE_INT, + * VALUE_FLOAT + * }; + * + * int ptrToInt(ValueType type, void* value) { + * { + * // We know for sure that type is either INT or FLOAT, and we want this + * // code to run as quickly as possible. + * switch (type) { + * case VALUE_INT: + * return *(int*) value; + * case VALUE_FLOAT: + * return (int) *(float*) value; + * default: + * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected ValueType"); + * } + * } + */ + +/* + * Assert in all debug builds plus the Nightly channel's release builds. Take + * this extra testing precaution because hitting MOZ_ASSUME_UNREACHABLE_MARKER + * could trigger exploitable undefined behavior. + */ +#define MOZ_ASSERT_UNREACHABLE(reason) \ + MOZ_NIGHTLY_ASSERT(false, "MOZ_ASSERT_UNREACHABLE: " reason) + +#define MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) \ + do { \ + MOZ_ASSERT_UNREACHABLE(reason); \ + MOZ_ASSUME_UNREACHABLE_MARKER(); \ + } while (0) + +/* + * TODO: Bug 990764: Audit all MOZ_ASSUME_UNREACHABLE calls and replace them + * with MOZ_ASSERT_UNREACHABLE, MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE, or + * MOZ_CRASH. For now, preserve the macro's same meaning of unreachable. + */ +#define MOZ_ASSUME_UNREACHABLE(reason) \ + MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) + +/* + * MOZ_ALWAYS_TRUE(expr) and MOZ_ALWAYS_FALSE(expr) always evaluate the provided + * expression, in debug builds and in release builds both. Then, in debug + * builds only, the value of the expression is asserted either true or false + * using MOZ_ASSERT. + */ +#ifdef DEBUG +# define MOZ_ALWAYS_TRUE(expr) MOZ_ASSERT((expr)) +# define MOZ_ALWAYS_FALSE(expr) MOZ_ASSERT(!(expr)) +#else +# define MOZ_ALWAYS_TRUE(expr) ((void)(expr)) +# define MOZ_ALWAYS_FALSE(expr) ((void)(expr)) +#endif + +#undef MOZ_DUMP_ASSERTION_STACK + +#endif /* mozilla_Assertions_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Atomics.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Atomics.h new file mode 100644 index 0000000000..71d95c61ba --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Atomics.h @@ -0,0 +1,1171 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements (almost always) lock-free atomic operations. The operations here + * are a subset of that which can be found in C++11's header, with a + * different API to enforce consistent memory ordering constraints. + * + * Anyone caught using |volatile| for inter-thread memory safety needs to be + * sent a copy of this header and the C++11 standard. + */ + +#ifndef mozilla_Atomics_h +#define mozilla_Atomics_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/TypeTraits.h" + +#include + +/* + * Our minimum deployment target on clang/OS X is OS X 10.6, whose SDK + * does not have . So be sure to check for support + * along with C++0x support. + */ +#if defined(__clang__) || defined(__GNUC__) + /* + * Clang doesn't like from libstdc++ before 4.7 due to the + * loose typing of the atomic builtins. GCC 4.5 and 4.6 lacks inline + * definitions for unspecialized std::atomic and causes linking errors. + * Therefore, we require at least 4.7.0 for using libstdc++. + */ +# if MOZ_USING_LIBSTDCXX && MOZ_LIBSTDCXX_VERSION_AT_LEAST(4, 7, 0) +# define MOZ_HAVE_CXX11_ATOMICS +# elif MOZ_USING_LIBCXX +# define MOZ_HAVE_CXX11_ATOMICS +# endif +#elif defined(_MSC_VER) && _MSC_VER >= 1700 +# if defined(DEBUG) + /* + * Provide our own failure code since we're having trouble linking to + * std::_Debug_message (bug 982310). + */ +# define _INVALID_MEMORY_ORDER MOZ_CRASH("Invalid memory order") +# endif +# define MOZ_HAVE_CXX11_ATOMICS +#endif + +namespace mozilla { + +/** + * An enum of memory ordering possibilities for atomics. + * + * Memory ordering is the observable state of distinct values in memory. + * (It's a separate concept from atomicity, which concerns whether an + * operation can ever be observed in an intermediate state. Don't + * conflate the two!) Given a sequence of operations in source code on + * memory, it is *not* always the case that, at all times and on all + * cores, those operations will appear to have occurred in that exact + * sequence. First, the compiler might reorder that sequence, if it + * thinks another ordering will be more efficient. Second, the CPU may + * not expose so consistent a view of memory. CPUs will often perform + * their own instruction reordering, above and beyond that performed by + * the compiler. And each core has its own memory caches, and accesses + * (reads and writes both) to "memory" may only resolve to out-of-date + * cache entries -- not to the "most recently" performed operation in + * some global sense. Any access to a value that may be used by + * multiple threads, potentially across multiple cores, must therefore + * have a memory ordering imposed on it, for all code on all + * threads/cores to have a sufficiently coherent worldview. + * + * http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync and + * http://en.cppreference.com/w/cpp/atomic/memory_order go into more + * detail on all this, including examples of how each mode works. + * + * Note that for simplicity and practicality, not all of the modes in + * C++11 are supported. The missing C++11 modes are either subsumed by + * the modes we provide below, or not relevant for the CPUs we support + * in Gecko. These three modes are confusing enough as it is! + */ +enum MemoryOrdering { + /* + * Relaxed ordering is the simplest memory ordering: none at all. + * When the result of a write is observed, nothing may be inferred + * about other memory. Writes ostensibly performed "before" on the + * writing thread may not yet be visible. Writes performed "after" on + * the writing thread may already be visible, if the compiler or CPU + * reordered them. (The latter can happen if reads and/or writes get + * held up in per-processor caches.) Relaxed ordering means + * operations can always use cached values (as long as the actual + * updates to atomic values actually occur, correctly, eventually), so + * it's usually the fastest sort of atomic access. For this reason, + * *it's also the most dangerous kind of access*. + * + * Relaxed ordering is good for things like process-wide statistics + * counters that don't need to be consistent with anything else, so + * long as updates themselves are atomic. (And so long as any + * observations of that value can tolerate being out-of-date -- if you + * need some sort of up-to-date value, you need some sort of other + * synchronizing operation.) It's *not* good for locks, mutexes, + * reference counts, etc. that mediate access to other memory, or must + * be observably consistent with other memory. + * + * x86 architectures don't take advantage of the optimization + * opportunities that relaxed ordering permits. Thus it's possible + * that using relaxed ordering will "work" on x86 but fail elsewhere + * (ARM, say, which *does* implement non-sequentially-consistent + * relaxed ordering semantics). Be extra-careful using relaxed + * ordering if you can't easily test non-x86 architectures! + */ + Relaxed, + + /* + * When an atomic value is updated with ReleaseAcquire ordering, and + * that new value is observed with ReleaseAcquire ordering, prior + * writes (atomic or not) are also observable. What ReleaseAcquire + * *doesn't* give you is any observable ordering guarantees for + * ReleaseAcquire-ordered operations on different objects. For + * example, if there are two cores that each perform ReleaseAcquire + * operations on separate objects, each core may or may not observe + * the operations made by the other core. The only way the cores can + * be synchronized with ReleaseAcquire is if they both + * ReleaseAcquire-access the same object. This implies that you can't + * necessarily describe some global total ordering of ReleaseAcquire + * operations. + * + * ReleaseAcquire ordering is good for (as the name implies) atomic + * operations on values controlling ownership of things: reference + * counts, mutexes, and the like. However, if you are thinking about + * using these to implement your own locks or mutexes, you should take + * a good, hard look at actual lock or mutex primitives first. + */ + ReleaseAcquire, + + /* + * When an atomic value is updated with SequentiallyConsistent + * ordering, all writes observable when the update is observed, just + * as with ReleaseAcquire ordering. But, furthermore, a global total + * ordering of SequentiallyConsistent operations *can* be described. + * For example, if two cores perform SequentiallyConsistent operations + * on separate objects, one core will observably perform its update + * (and all previous operations will have completed), then the other + * core will observably perform its update (and all previous + * operations will have completed). (Although those previous + * operations aren't themselves ordered -- they could be intermixed, + * or ordered if they occur on atomic values with ordering + * requirements.) SequentiallyConsistent is the *simplest and safest* + * ordering of atomic operations -- it's always as if one operation + * happens, then another, then another, in some order -- and every + * core observes updates to happen in that single order. Because it + * has the most synchronization requirements, operations ordered this + * way also tend to be slowest. + * + * SequentiallyConsistent ordering can be desirable when multiple + * threads observe objects, and they all have to agree on the + * observable order of changes to them. People expect + * SequentiallyConsistent ordering, even if they shouldn't, when + * writing code, atomic or otherwise. SequentiallyConsistent is also + * the ordering of choice when designing lockless data structures. If + * you don't know what order to use, use this one. + */ + SequentiallyConsistent, +}; + +} // namespace mozilla + +// Build up the underlying intrinsics. +#ifdef MOZ_HAVE_CXX11_ATOMICS + +# include + +namespace mozilla { +namespace detail { + +/* + * We provide CompareExchangeFailureOrder to work around a bug in some + * versions of GCC's header. See bug 898491. + */ +template struct AtomicOrderConstraints; + +template<> +struct AtomicOrderConstraints +{ + static const std::memory_order AtomicRMWOrder = std::memory_order_relaxed; + static const std::memory_order LoadOrder = std::memory_order_relaxed; + static const std::memory_order StoreOrder = std::memory_order_relaxed; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_relaxed; +}; + +template<> +struct AtomicOrderConstraints +{ + static const std::memory_order AtomicRMWOrder = std::memory_order_acq_rel; + static const std::memory_order LoadOrder = std::memory_order_acquire; + static const std::memory_order StoreOrder = std::memory_order_release; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_acquire; +}; + +template<> +struct AtomicOrderConstraints +{ + static const std::memory_order AtomicRMWOrder = std::memory_order_seq_cst; + static const std::memory_order LoadOrder = std::memory_order_seq_cst; + static const std::memory_order StoreOrder = std::memory_order_seq_cst; + static const std::memory_order CompareExchangeFailureOrder = + std::memory_order_seq_cst; +}; + +template +struct IntrinsicBase +{ + typedef std::atomic ValueType; + typedef AtomicOrderConstraints OrderedOp; +}; + +template +struct IntrinsicMemoryOps : public IntrinsicBase +{ + typedef IntrinsicBase Base; + + static T load(const typename Base::ValueType& aPtr) + { + return aPtr.load(Base::OrderedOp::LoadOrder); + } + + static void store(typename Base::ValueType& aPtr, T aVal) + { + aPtr.store(aVal, Base::OrderedOp::StoreOrder); + } + + static T exchange(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.exchange(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static bool compareExchange(typename Base::ValueType& aPtr, + T aOldVal, T aNewVal) + { + return aPtr.compare_exchange_strong(aOldVal, aNewVal, + Base::OrderedOp::AtomicRMWOrder, + Base::OrderedOp::CompareExchangeFailureOrder); + } +}; + +template +struct IntrinsicAddSub : public IntrinsicBase +{ + typedef IntrinsicBase Base; + + static T add(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_add(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T sub(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_sub(aVal, Base::OrderedOp::AtomicRMWOrder); + } +}; + +template +struct IntrinsicAddSub : public IntrinsicBase +{ + typedef IntrinsicBase Base; + + static T* add(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_add(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } + + static T* sub(typename Base::ValueType& aPtr, ptrdiff_t aVal) + { + return aPtr.fetch_sub(fixupAddend(aVal), Base::OrderedOp::AtomicRMWOrder); + } +private: + /* + * GCC 4.6's header has a bug where adding X to an + * atomic is not the same as adding X to a T*. Hence the need + * for this function to provide the correct addend. + */ + static ptrdiff_t fixupAddend(ptrdiff_t aVal) + { +#if defined(__clang__) || defined(_MSC_VER) + return aVal; +#elif defined(__GNUC__) && MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) && \ + !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) + return aVal * sizeof(T); +#else + return aVal; +#endif + } +}; + +template +struct IntrinsicIncDec : public IntrinsicAddSub +{ + typedef IntrinsicBase Base; + + static T inc(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::add(aPtr, 1); + } + + static T dec(typename Base::ValueType& aPtr) + { + return IntrinsicAddSub::sub(aPtr, 1); + } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ + typedef IntrinsicBase Base; + + static T or_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_or(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T xor_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_xor(aVal, Base::OrderedOp::AtomicRMWOrder); + } + + static T and_(typename Base::ValueType& aPtr, T aVal) + { + return aPtr.fetch_and(aVal, Base::OrderedOp::AtomicRMWOrder); + } +}; + +template +struct AtomicIntrinsics + : public IntrinsicMemoryOps, public IntrinsicIncDec +{ +}; + +} // namespace detail +} // namespace mozilla + +#elif defined(__GNUC__) + +namespace mozilla { +namespace detail { + +/* + * The __sync_* family of intrinsics is documented here: + * + * http://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Atomic-Builtins.html + * + * While these intrinsics are deprecated in favor of the newer __atomic_* + * family of intrincs: + * + * http://gcc.gnu.org/onlinedocs/gcc-4.7.3/gcc/_005f_005fatomic-Builtins.html + * + * any GCC version that supports the __atomic_* intrinsics will also support + * the header and so will be handled above. We provide a version of + * atomics using the __sync_* intrinsics to support older versions of GCC. + * + * All __sync_* intrinsics that we use below act as full memory barriers, for + * both compiler and hardware reordering, except for __sync_lock_test_and_set, + * which is a only an acquire barrier. When we call __sync_lock_test_and_set, + * we add a barrier above it as appropriate. + */ + +template struct Barrier; + +/* + * Some processors (in particular, x86) don't require quite so many calls to + * __sync_sychronize as our specializations of Barrier produce. If + * performance turns out to be an issue, defining these specializations + * on a per-processor basis would be a good first tuning step. + */ + +template<> +struct Barrier +{ + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} + static void afterStore() {} +}; + +template<> +struct Barrier +{ + static void beforeLoad() {} + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() {} +}; + +template<> +struct Barrier +{ + static void beforeLoad() { __sync_synchronize(); } + static void afterLoad() { __sync_synchronize(); } + static void beforeStore() { __sync_synchronize(); } + static void afterStore() { __sync_synchronize(); } +}; + +template +struct IntrinsicMemoryOps +{ + static T load(const T& aPtr) + { + Barrier::beforeLoad(); + T val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(T& aPtr, T aVal) + { + Barrier::beforeStore(); + aPtr = aVal; + Barrier::afterStore(); + } + + static T exchange(T& aPtr, T aVal) + { + // __sync_lock_test_and_set is only an acquire barrier; loads and stores + // can't be moved up from after to before it, but they can be moved down + // from before to after it. We may want a stricter ordering, so we need + // an explicit barrier. + Barrier::beforeStore(); + return __sync_lock_test_and_set(&aPtr, aVal); + } + + static bool compareExchange(T& aPtr, T aOldVal, T aNewVal) + { + return __sync_bool_compare_and_swap(&aPtr, aOldVal, aNewVal); + } +}; + +template +struct IntrinsicAddSub +{ + typedef T ValueType; + + static T add(T& aPtr, T aVal) + { + return __sync_fetch_and_add(&aPtr, aVal); + } + + static T sub(T& aPtr, T aVal) + { + return __sync_fetch_and_sub(&aPtr, aVal); + } +}; + +template +struct IntrinsicAddSub +{ + typedef T* ValueType; + + /* + * The reinterpret_casts are needed so that + * __sync_fetch_and_{add,sub} will properly type-check. + * + * Also, these functions do not provide standard semantics for + * pointer types, so we need to adjust the addend. + */ + static ValueType add(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_add(&aPtr, amount); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aVal) + { + ValueType amount = reinterpret_cast(aVal * sizeof(T)); + return __sync_fetch_and_sub(&aPtr, amount); + } +}; + +template +struct IntrinsicIncDec : public IntrinsicAddSub +{ + static T inc(T& aPtr) { return IntrinsicAddSub::add(aPtr, 1); } + static T dec(T& aPtr) { return IntrinsicAddSub::sub(aPtr, 1); } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ + static T or_( T& aPtr, T aVal) { return __sync_fetch_and_or(&aPtr, aVal); } + static T xor_(T& aPtr, T aVal) { return __sync_fetch_and_xor(&aPtr, aVal); } + static T and_(T& aPtr, T aVal) { return __sync_fetch_and_and(&aPtr, aVal); } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ +}; + +} // namespace detail +} // namespace mozilla + +#elif defined(_MSC_VER) + +/* + * Windows comes with a full complement of atomic operations. + * Unfortunately, most of those aren't available for Windows XP (even if + * the compiler supports intrinsics for them), which is the oldest + * version of Windows we support. Therefore, we only provide operations + * on 32-bit datatypes for 32-bit Windows versions; for 64-bit Windows + * versions, we support 64-bit datatypes as well. + */ + +# include + +# pragma intrinsic(_InterlockedExchangeAdd) +# pragma intrinsic(_InterlockedOr) +# pragma intrinsic(_InterlockedXor) +# pragma intrinsic(_InterlockedAnd) +# pragma intrinsic(_InterlockedExchange) +# pragma intrinsic(_InterlockedCompareExchange) + +namespace mozilla { +namespace detail { + +# if !defined(_M_IX86) && !defined(_M_X64) + /* + * The implementations below are optimized for x86ish systems. You + * will have to modify them if you are porting to Windows on a + * different architecture. + */ +# error "Unknown CPU type" +# endif + +/* + * The PrimitiveIntrinsics template should define |Type|, the datatype of size + * DataSize upon which we operate, and the following eight functions. + * + * static Type add(Type* aPtr, Type aVal); + * static Type sub(Type* aPtr, Type aVal); + * static Type or_(Type* aPtr, Type aVal); + * static Type xor_(Type* aPtr, Type aVal); + * static Type and_(Type* aPtr, Type aVal); + * + * These functions perform the obvious operation on the value contained in + * |*aPtr| combined with |aVal| and return the value previously stored in + * |*aPtr|. + * + * static void store(Type* aPtr, Type aVal); + * + * This function atomically stores |aVal| into |*aPtr| and must provide a full + * memory fence after the store to prevent compiler and hardware instruction + * reordering. It should also act as a compiler barrier to prevent reads and + * writes from moving to after the store. + * + * static Type exchange(Type* aPtr, Type aVal); + * + * This function atomically stores |aVal| into |*aPtr| and returns the + * previous contents of |*aPtr|; + * + * static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal); + * + * This function atomically performs the following operation: + * + * if (*aPtr == aOldVal) { + * *aPtr = aNewVal; + * return true; + * } else { + * return false; + * } + * + */ +template struct PrimitiveIntrinsics; + +template<> +struct PrimitiveIntrinsics<4> +{ + typedef long Type; + + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * _InterlockedExchangeSubtract isn't available before Windows 7, + * and we must support Windows XP. + */ + return _InterlockedExchangeAdd(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange(aPtr, aNewVal, aOldVal) == aOldVal; + } +}; + +# if defined(_M_X64) + +# pragma intrinsic(_InterlockedExchangeAdd64) +# pragma intrinsic(_InterlockedOr64) +# pragma intrinsic(_InterlockedXor64) +# pragma intrinsic(_InterlockedAnd64) +# pragma intrinsic(_InterlockedExchange64) +# pragma intrinsic(_InterlockedCompareExchange64) + +template <> +struct PrimitiveIntrinsics<8> +{ + typedef __int64 Type; + + static Type add(Type* aPtr, Type aVal) + { + return _InterlockedExchangeAdd64(aPtr, aVal); + } + + static Type sub(Type* aPtr, Type aVal) + { + /* + * There is no _InterlockedExchangeSubtract64. + */ + return _InterlockedExchangeAdd64(aPtr, -aVal); + } + + static Type or_(Type* aPtr, Type aVal) + { + return _InterlockedOr64(aPtr, aVal); + } + + static Type xor_(Type* aPtr, Type aVal) + { + return _InterlockedXor64(aPtr, aVal); + } + + static Type and_(Type* aPtr, Type aVal) + { + return _InterlockedAnd64(aPtr, aVal); + } + + static void store(Type* aPtr, Type aVal) + { + _InterlockedExchange64(aPtr, aVal); + } + + static Type exchange(Type* aPtr, Type aVal) + { + return _InterlockedExchange64(aPtr, aVal); + } + + static bool compareExchange(Type* aPtr, Type aOldVal, Type aNewVal) + { + return _InterlockedCompareExchange64(aPtr, aNewVal, aOldVal) == aOldVal; + } +}; + +# endif + +# pragma intrinsic(_ReadWriteBarrier) + +template struct Barrier; + +/* + * We do not provide an afterStore method in Barrier, as Relaxed and + * ReleaseAcquire orderings do not require one, and the required barrier + * for SequentiallyConsistent is handled by PrimitiveIntrinsics. + */ + +template<> +struct Barrier +{ + static void beforeLoad() {} + static void afterLoad() {} + static void beforeStore() {} +}; + +template<> +struct Barrier +{ + static void beforeLoad() {} + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } +}; + +template<> +struct Barrier +{ + static void beforeLoad() { _ReadWriteBarrier(); } + static void afterLoad() { _ReadWriteBarrier(); } + static void beforeStore() { _ReadWriteBarrier(); } +}; + +template +struct CastHelper +{ + static PrimType toPrimType(T aVal) { return static_cast(aVal); } + static T fromPrimType(PrimType aVal) { return static_cast(aVal); } +}; + +template +struct CastHelper +{ + static PrimType toPrimType(T* aVal) { return reinterpret_cast(aVal); } + static T* fromPrimType(PrimType aVal) { return reinterpret_cast(aVal); } +}; + +template +struct IntrinsicBase +{ + typedef T ValueType; + typedef PrimitiveIntrinsics Primitives; + typedef typename Primitives::Type PrimType; + static_assert(sizeof(PrimType) == sizeof(T), + "Selection of PrimitiveIntrinsics was wrong"); + typedef CastHelper Cast; +}; + +template +struct IntrinsicMemoryOps : public IntrinsicBase +{ + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + + static ValueType load(const ValueType& aPtr) + { + Barrier::beforeLoad(); + ValueType val = aPtr; + Barrier::afterLoad(); + return val; + } + + static void store(ValueType& aPtr, ValueType aVal) + { + // For SequentiallyConsistent, Primitives::store() will generate the + // proper memory fence. Everything else just needs a barrier before + // the store. + if (Order == SequentiallyConsistent) { + Primitives::store(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + } else { + Barrier::beforeStore(); + aPtr = aVal; + } + } + + static ValueType exchange(ValueType& aPtr, ValueType aVal) + { + PrimType oldval = + Primitives::exchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aVal)); + return Cast::fromPrimType(oldval); + } + + static bool compareExchange(ValueType& aPtr, ValueType aOldVal, + ValueType aNewVal) + { + return Primitives::compareExchange(reinterpret_cast(&aPtr), + Cast::toPrimType(aOldVal), + Cast::toPrimType(aNewVal)); + } +}; + +template +struct IntrinsicApplyHelper : public IntrinsicBase +{ + typedef typename IntrinsicBase::ValueType ValueType; + typedef typename IntrinsicBase::PrimType PrimType; + typedef typename IntrinsicBase::Cast Cast; + typedef PrimType (*BinaryOp)(PrimType*, PrimType); + typedef PrimType (*UnaryOp)(PrimType*); + + static ValueType applyBinaryFunction(BinaryOp aOp, ValueType& aPtr, + ValueType aVal) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + PrimType primTypeVal = Cast::toPrimType(aVal); + return Cast::fromPrimType(aOp(primTypePtr, primTypeVal)); + } + + static ValueType applyUnaryFunction(UnaryOp aOp, ValueType& aPtr) + { + PrimType* primTypePtr = reinterpret_cast(&aPtr); + return Cast::fromPrimType(aOp(primTypePtr)); + } +}; + +template +struct IntrinsicAddSub : public IntrinsicApplyHelper +{ + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::add, aPtr, aVal); + } + + static ValueType sub(ValueType& aPtr, ValueType aVal) + { + return applyBinaryFunction(&Primitives::sub, aPtr, aVal); + } +}; + +template +struct IntrinsicAddSub : public IntrinsicApplyHelper +{ + typedef typename IntrinsicApplyHelper::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType add(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::add, aPtr, + (ValueType)(aAmount * sizeof(T))); + } + + static ValueType sub(ValueType& aPtr, ptrdiff_t aAmount) + { + return applyBinaryFunction(&Primitives::sub, aPtr, + (ValueType)(aAmount * sizeof(T))); + } +}; + +template +struct IntrinsicIncDec : public IntrinsicAddSub +{ + typedef typename IntrinsicAddSub::ValueType ValueType; + static ValueType inc(ValueType& aPtr) { return add(aPtr, 1); } + static ValueType dec(ValueType& aPtr) { return sub(aPtr, 1); } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ + typedef typename IntrinsicIncDec::ValueType ValueType; + typedef typename IntrinsicBase::Primitives Primitives; + + static ValueType or_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::or_, aPtr, aVal); + } + + static ValueType xor_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::xor_, aPtr, aVal); + } + + static ValueType and_(ValueType& aPtr, T aVal) + { + return applyBinaryFunction(&Primitives::and_, aPtr, aVal); + } +}; + +template +struct AtomicIntrinsics : public IntrinsicMemoryOps, + public IntrinsicIncDec +{ + typedef typename IntrinsicMemoryOps::ValueType ValueType; + // This is required to make us be able to build with MSVC10, for unknown + // reasons. + typedef typename IntrinsicBase::Primitives Primitives; +}; + +} // namespace detail +} // namespace mozilla + +#else +# error "Atomic compiler intrinsics are not supported on your platform" +#endif + +namespace mozilla { + +namespace detail { + +template +class AtomicBase +{ + // We only support 32-bit types on 32-bit Windows, which constrains our + // implementation elsewhere. But we support pointer-sized types everywhere. + static_assert(sizeof(T) == 4 || (sizeof(uintptr_t) == 8 && sizeof(T) == 8), + "mozilla/Atomics.h only supports 32-bit and pointer-sized types"); + +protected: + typedef typename detail::AtomicIntrinsics Intrinsics; + typename Intrinsics::ValueType mValue; + +public: + MOZ_CONSTEXPR AtomicBase() : mValue() {} + explicit MOZ_CONSTEXPR AtomicBase(T aInit) : mValue(aInit) {} + + // Note: we can't provide operator T() here because Atomic inherits + // from AtomcBase with T=uint32_t and not T=bool. If we implemented + // operator T() here, it would cause errors when comparing Atomic with + // a regular bool. + + T operator=(T aVal) + { + Intrinsics::store(mValue, aVal); + return aVal; + } + + /** + * Performs an atomic swap operation. aVal is stored and the previous + * value of this variable is returned. + */ + T exchange(T aVal) + { + return Intrinsics::exchange(mValue, aVal); + } + + /** + * Performs an atomic compare-and-swap operation and returns true if it + * succeeded. This is equivalent to atomically doing + * + * if (mValue == aOldValue) { + * mValue = aNewValue; + * return true; + * } else { + * return false; + * } + */ + bool compareExchange(T aOldValue, T aNewValue) + { + return Intrinsics::compareExchange(mValue, aOldValue, aNewValue); + } + +private: + template + AtomicBase(const AtomicBase& aCopy) MOZ_DELETE; +}; + +template +class AtomicBaseIncDec : public AtomicBase +{ + typedef typename detail::AtomicBase Base; + +public: + MOZ_CONSTEXPR AtomicBaseIncDec() : Base() {} + explicit MOZ_CONSTEXPR AtomicBaseIncDec(T aInit) : Base(aInit) {} + + using Base::operator=; + + operator T() const { return Base::Intrinsics::load(Base::mValue); } + T operator++(int) { return Base::Intrinsics::inc(Base::mValue); } + T operator--(int) { return Base::Intrinsics::dec(Base::mValue); } + T operator++() { return Base::Intrinsics::inc(Base::mValue) + 1; } + T operator--() { return Base::Intrinsics::dec(Base::mValue) - 1; } + +private: + template + AtomicBaseIncDec(const AtomicBaseIncDec& aCopy) MOZ_DELETE; +}; + +} // namespace detail + +/** + * A wrapper for a type that enforces that all memory accesses are atomic. + * + * In general, where a variable |T foo| exists, |Atomic foo| can be used in + * its place. Implementations for integral and pointer types are provided + * below. + * + * Atomic accesses are sequentially consistent by default. You should + * use the default unless you are tall enough to ride the + * memory-ordering roller coaster (if you're not sure, you aren't) and + * you have a compelling reason to do otherwise. + * + * There is one exception to the case of atomic memory accesses: providing an + * initial value of the atomic value is not guaranteed to be atomic. This is a + * deliberate design choice that enables static atomic variables to be declared + * without introducing extra static constructors. + */ +template +class Atomic; + +/** + * Atomic implementation for integral types. + * + * In addition to atomic store and load operations, compound assignment and + * increment/decrement operators are implemented which perform the + * corresponding read-modify-write operation atomically. Finally, an atomic + * swap method is provided. + */ +template +class Atomic::value && + !IsSame::value>::Type> + : public detail::AtomicBaseIncDec +{ + typedef typename detail::AtomicBaseIncDec Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + + using Base::operator=; + + T operator+=(T aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } + + T operator-=(T aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } + + T operator|=(T aVal) + { + return Base::Intrinsics::or_(Base::mValue, aVal) | aVal; + } + + T operator^=(T aVal) + { + return Base::Intrinsics::xor_(Base::mValue, aVal) ^ aVal; + } + + T operator&=(T aVal) + { + return Base::Intrinsics::and_(Base::mValue, aVal) & aVal; + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +/** + * Atomic implementation for pointer types. + * + * An atomic compare-and-swap primitive for pointer variables is provided, as + * are atomic increment and decement operators. Also provided are the compound + * assignment operators for addition and subtraction. Atomic swap (via + * exchange()) is included as well. + */ +template +class Atomic : public detail::AtomicBaseIncDec +{ + typedef typename detail::AtomicBaseIncDec Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T* aInit) : Base(aInit) {} + + using Base::operator=; + + T* operator+=(ptrdiff_t aDelta) + { + return Base::Intrinsics::add(Base::mValue, aDelta) + aDelta; + } + + T* operator-=(ptrdiff_t aDelta) + { + return Base::Intrinsics::sub(Base::mValue, aDelta) - aDelta; + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +/** + * Atomic implementation for enum types. + * + * The atomic store and load operations and the atomic swap method is provided. + */ +template +class Atomic::value>::Type> + : public detail::AtomicBase +{ + typedef typename detail::AtomicBase Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(T aInit) : Base(aInit) {} + + operator T() const { return Base::Intrinsics::load(Base::mValue); } + + using Base::operator=; + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +/** + * Atomic implementation for boolean types. + * + * The atomic store and load operations and the atomic swap method is provided. + * + * Note: + * + * - sizeof(Atomic) != sizeof(bool) for some implementations of + * bool and/or some implementations of std::atomic. This is allowed in + * [atomic.types.generic]p9. + * + * - It's not obvious whether the 8-bit atomic functions on Windows are always + * inlined or not. If they are not inlined, the corresponding functions in the + * runtime library are not available on Windows XP. This is why we implement + * Atomic with an underlying type of uint32_t. + */ +template +class Atomic + : protected detail::AtomicBase +{ + typedef typename detail::AtomicBase Base; + +public: + MOZ_CONSTEXPR Atomic() : Base() {} + explicit MOZ_CONSTEXPR Atomic(bool aInit) : Base(aInit) {} + + // We provide boolean wrappers for the underlying AtomicBase methods. + operator bool() const + { + return Base::Intrinsics::load(Base::mValue); + } + + bool operator=(bool aVal) + { + return Base::operator=(aVal); + } + + bool exchange(bool aVal) + { + return Base::exchange(aVal); + } + + bool compareExchange(bool aOldValue, bool aNewValue) + { + return Base::compareExchange(aOldValue, aNewValue); + } + +private: + Atomic(Atomic& aOther) MOZ_DELETE; +}; + +} // namespace mozilla + +#endif /* mozilla_Atomics_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Attributes.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Attributes.h new file mode 100644 index 0000000000..cdce8c7717 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Attributes.h @@ -0,0 +1,536 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implementations of various class and method modifier attributes. */ + +#ifndef mozilla_Attributes_h +#define mozilla_Attributes_h + +#include "mozilla/Compiler.h" + +/* + * MOZ_ALWAYS_INLINE is a macro which expands to tell the compiler that the + * method decorated with it must be inlined, even if the compiler thinks + * otherwise. This is only a (much) stronger version of the inline hint: + * compilers are not guaranteed to respect it (although they're much more likely + * to do so). + * + * The MOZ_ALWAYS_INLINE_EVEN_DEBUG macro is yet stronger. It tells the + * compiler to inline even in DEBUG builds. It should be used very rarely. + */ +#if defined(_MSC_VER) +# define MOZ_ALWAYS_INLINE_EVEN_DEBUG __forceinline +#elif defined(__GNUC__) +# define MOZ_ALWAYS_INLINE_EVEN_DEBUG __attribute__((always_inline)) inline +#else +# define MOZ_ALWAYS_INLINE_EVEN_DEBUG inline +#endif + +#if !defined(DEBUG) +# define MOZ_ALWAYS_INLINE MOZ_ALWAYS_INLINE_EVEN_DEBUG +#elif defined(_MSC_VER) && !defined(__cplusplus) +# define MOZ_ALWAYS_INLINE __inline +#else +# define MOZ_ALWAYS_INLINE inline +#endif + +#if defined(_MSC_VER) +/* + * g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality + * without warnings (functionality used by the macros below). These modes are + * detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, more + * standardly, by checking whether __cplusplus has a C++11 or greater value. + * Current versions of g++ do not correctly set __cplusplus, so we check both + * for forward compatibility. + * + * Even though some versions of MSVC support explicit conversion operators, we + * don't indicate support for them here, due to + * http://stackoverflow.com/questions/20498142/visual-studio-2013-explicit-keyword-bug + */ +# if _MSC_VER >= 1800 +# define MOZ_HAVE_CXX11_DELETE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_FINAL final +# else +# if defined(__clang__) +# error Please do not try to use clang-cl with MSVC10 or below emulation! +# endif + /* MSVC <= 10 used to spell "final" as "sealed". */ +# define MOZ_HAVE_CXX11_FINAL sealed +# endif +# define MOZ_HAVE_CXX11_OVERRIDE +# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) +# define MOZ_HAVE_NORETURN __declspec(noreturn) +#elif defined(__clang__) + /* + * Per Clang documentation, "Note that marketing version numbers should not + * be used to check for language features, as different vendors use different + * numbering schemes. Instead, use the feature checking macros." + */ +# ifndef __has_extension +# define __has_extension __has_feature /* compatibility, for older versions of clang */ +# endif +# if __has_extension(cxx_constexpr) +# define MOZ_HAVE_CXX11_CONSTEXPR +# endif +# if __has_extension(cxx_explicit_conversions) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif +# if __has_extension(cxx_deleted_functions) +# define MOZ_HAVE_CXX11_DELETE +# endif +# if __has_extension(cxx_override_control) +# define MOZ_HAVE_CXX11_OVERRIDE +# define MOZ_HAVE_CXX11_FINAL final +# endif +# if __has_attribute(noinline) +# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) +# endif +# if __has_attribute(noreturn) +# define MOZ_HAVE_NORETURN __attribute__((noreturn)) +# endif +#elif defined(__GNUC__) +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# if MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) +# define MOZ_HAVE_CXX11_OVERRIDE +# define MOZ_HAVE_CXX11_FINAL final +# endif +# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) +# define MOZ_HAVE_CXX11_CONSTEXPR +# endif +# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) +# define MOZ_HAVE_EXPLICIT_CONVERSION +# endif +# define MOZ_HAVE_CXX11_DELETE +# else + /* __final is a non-C++11 GCC synonym for 'final', per GCC r176655. */ +# if MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) +# define MOZ_HAVE_CXX11_FINAL __final +# endif +# endif +# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) +# define MOZ_HAVE_NORETURN __attribute__((noreturn)) +#endif + +/* + * When built with clang analyzer (a.k.a scan-build), define MOZ_HAVE_NORETURN + * to mark some false positives + */ +#ifdef __clang_analyzer__ +# if __has_extension(attribute_analyzer_noreturn) +# define MOZ_HAVE_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) +# endif +#endif + +/* + * The MOZ_CONSTEXPR specifier declares that a C++11 compiler can evaluate a + * function at compile time. A constexpr function cannot examine any values + * except its arguments and can have no side effects except its return value. + * The MOZ_CONSTEXPR_VAR specifier tells a C++11 compiler that a variable's + * value may be computed at compile time. It should be prefered to just + * marking variables as MOZ_CONSTEXPR because if the compiler does not support + * constexpr it will fall back to making the variable const, and some compilers + * do not accept variables being marked both const and constexpr. + */ +#ifdef MOZ_HAVE_CXX11_CONSTEXPR +# define MOZ_CONSTEXPR constexpr +# define MOZ_CONSTEXPR_VAR constexpr +#else +# define MOZ_CONSTEXPR /* no support */ +# define MOZ_CONSTEXPR_VAR const +#endif + +/* + * MOZ_EXPLICIT_CONVERSION is a specifier on a type conversion + * overloaded operator that declares that a C++11 compiler should restrict + * this operator to allow only explicit type conversions, disallowing + * implicit conversions. + * + * Example: + * + * template + * class Ptr + * { + * T* mPtr; + * MOZ_EXPLICIT_CONVERSION operator bool() const + * { + * return mPtr != nullptr; + * } + * }; + * + */ +#ifdef MOZ_HAVE_EXPLICIT_CONVERSION +# define MOZ_EXPLICIT_CONVERSION explicit +#else +# define MOZ_EXPLICIT_CONVERSION /* no support */ +#endif + +/* + * MOZ_NEVER_INLINE is a macro which expands to tell the compiler that the + * method decorated with it must never be inlined, even if the compiler would + * otherwise choose to inline the method. Compilers aren't absolutely + * guaranteed to support this, but most do. + */ +#if defined(MOZ_HAVE_NEVER_INLINE) +# define MOZ_NEVER_INLINE MOZ_HAVE_NEVER_INLINE +#else +# define MOZ_NEVER_INLINE /* no support */ +#endif + +/* + * MOZ_NORETURN, specified at the start of a function declaration, indicates + * that the given function does not return. (The function definition does not + * need to be annotated.) + * + * MOZ_NORETURN void abort(const char* msg); + * + * This modifier permits the compiler to optimize code assuming a call to such a + * function will never return. It also enables the compiler to avoid spurious + * warnings about not initializing variables, or about any other seemingly-dodgy + * operations performed after the function returns. + * + * This modifier does not affect the corresponding function's linking behavior. + */ +#if defined(MOZ_HAVE_NORETURN) +# define MOZ_NORETURN MOZ_HAVE_NORETURN +#else +# define MOZ_NORETURN /* no support */ +#endif + +/* + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS, specified at the end of a function + * declaration, indicates that for the purposes of static analysis, this + * function does not return. (The function definition does not need to be + * annotated.) + * + * MOZ_ReportCrash(const char* s, const char* file, int ln) + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS + * + * Some static analyzers, like scan-build from clang, can use this information + * to eliminate false positives. From the upstream documentation of scan-build: + * "This attribute is useful for annotating assertion handlers that actually + * can return, but for the purpose of using the analyzer we want to pretend + * that such functions do not return." + * + */ +#if defined(MOZ_HAVE_ANALYZER_NORETURN) +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS MOZ_HAVE_ANALYZER_NORETURN +#else +# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS /* no support */ +#endif + +/* + * MOZ_ASAN_BLACKLIST is a macro to tell AddressSanitizer (a compile-time + * instrumentation shipped with Clang and GCC) to not instrument the annotated + * function. Furthermore, it will prevent the compiler from inlining the + * function because inlining currently breaks the blacklisting mechanism of + * AddressSanitizer. + */ +#if defined(__has_feature) +# if __has_feature(address_sanitizer) +# define MOZ_HAVE_ASAN_BLACKLIST +# endif +#elif defined(__GNUC__) +# if defined(__SANITIZE_ADDRESS__) +# define MOZ_HAVE_ASAN_BLACKLIST +# endif +#endif + +#if defined(MOZ_HAVE_ASAN_BLACKLIST) +# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) +#else +# define MOZ_ASAN_BLACKLIST /* nothing */ +#endif + +/* + * MOZ_TSAN_BLACKLIST is a macro to tell ThreadSanitizer (a compile-time + * instrumentation shipped with Clang) to not instrument the annotated function. + * Furthermore, it will prevent the compiler from inlining the function because + * inlining currently breaks the blacklisting mechanism of ThreadSanitizer. + */ +#if defined(__has_feature) +# if __has_feature(thread_sanitizer) +# define MOZ_TSAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_thread)) +# else +# define MOZ_TSAN_BLACKLIST /* nothing */ +# endif +#else +# define MOZ_TSAN_BLACKLIST /* nothing */ +#endif + +#ifdef __cplusplus + +/* + * MOZ_DELETE, specified immediately prior to the ';' terminating an undefined- + * method declaration, attempts to delete that method from the corresponding + * class. An attempt to use the method will always produce an error *at compile + * time* (instead of sometimes as late as link time) when this macro can be + * implemented. For example, you can use MOZ_DELETE to produce classes with no + * implicit copy constructor or assignment operator: + * + * struct NonCopyable + * { + * private: + * NonCopyable(const NonCopyable& aOther) MOZ_DELETE; + * void operator=(const NonCopyable& aOther) MOZ_DELETE; + * }; + * + * If MOZ_DELETE can't be implemented for the current compiler, use of the + * annotated method will still cause an error, but the error might occur at link + * time in some cases rather than at compile time. + * + * MOZ_DELETE relies on C++11 functionality not universally implemented. As a + * backstop, method declarations using MOZ_DELETE should be private. + */ +#if defined(MOZ_HAVE_CXX11_DELETE) +# define MOZ_DELETE = delete +#else +# define MOZ_DELETE /* no support */ +#endif + +/* + * MOZ_OVERRIDE explicitly indicates that a virtual member function in a class + * overrides a member function of a base class, rather than potentially being a + * new member function. MOZ_OVERRIDE should be placed immediately before the + * ';' terminating the member function's declaration, or before '= 0;' if the + * member function is pure. If the member function is defined in the class + * definition, it should appear before the opening brace of the function body. + * + * class Base + * { + * public: + * virtual void f() = 0; + * }; + * class Derived1 : public Base + * { + * public: + * virtual void f() MOZ_OVERRIDE; + * }; + * class Derived2 : public Base + * { + * public: + * virtual void f() MOZ_OVERRIDE = 0; + * }; + * class Derived3 : public Base + * { + * public: + * virtual void f() MOZ_OVERRIDE { } + * }; + * + * In compilers supporting C++11 override controls, MOZ_OVERRIDE *requires* that + * the function marked with it override a member function of a base class: it + * is a compile error if it does not. Otherwise MOZ_OVERRIDE does not affect + * semantics and merely documents the override relationship to the reader (but + * of course must still be used correctly to not break C++11 compilers). + */ +#if defined(MOZ_HAVE_CXX11_OVERRIDE) +# define MOZ_OVERRIDE override +#else +# define MOZ_OVERRIDE /* no support */ +#endif + +/* + * MOZ_FINAL indicates that some functionality cannot be overridden through + * inheritance. It can be used to annotate either classes/structs or virtual + * member functions. + * + * To annotate a class/struct with MOZ_FINAL, place MOZ_FINAL immediately after + * the name of the class, before the list of classes from which it derives (if + * any) and before its opening brace. MOZ_FINAL must not be used to annotate + * unnamed classes or structs. (With some compilers, and with C++11 proper, the + * underlying expansion is ambiguous with specifying a class name.) + * + * class Base MOZ_FINAL + * { + * public: + * Base(); + * ~Base(); + * virtual void f() { } + * }; + * // This will be an error in some compilers: + * class Derived : public Base + * { + * public: + * ~Derived() { } + * }; + * + * One particularly common reason to specify MOZ_FINAL upon a class is to tell + * the compiler that it's not dangerous for it to have a non-virtual destructor + * yet have one or more virtual functions, silencing the warning it might emit + * in this case. Suppose Base above weren't annotated with MOZ_FINAL. Because + * ~Base() is non-virtual, an attempt to delete a Derived* through a Base* + * wouldn't call ~Derived(), so any cleanup ~Derived() might do wouldn't happen. + * (Formally C++ says behavior is undefined, but compilers will likely just call + * ~Base() and not ~Derived().) Specifying MOZ_FINAL tells the compiler that + * it's safe for the destructor to be non-virtual. + * + * In compilers implementing final controls, it is an error to inherit from a + * class annotated with MOZ_FINAL. In other compilers it serves only as + * documentation. + * + * To annotate a virtual member function with MOZ_FINAL, place MOZ_FINAL + * immediately before the ';' terminating the member function's declaration, or + * before '= 0;' if the member function is pure. If the member function is + * defined in the class definition, it should appear before the opening brace of + * the function body. (This placement is identical to that for MOZ_OVERRIDE. + * If both are used, they should appear in the order 'MOZ_FINAL MOZ_OVERRIDE' + * for consistency.) + * + * class Base + * { + * public: + * virtual void f() MOZ_FINAL; + * }; + * class Derived + * { + * public: + * // This will be an error in some compilers: + * virtual void f(); + * }; + * + * In compilers implementing final controls, it is an error for a derived class + * to override a method annotated with MOZ_FINAL. In other compilers it serves + * only as documentation. + */ +#if defined(MOZ_HAVE_CXX11_FINAL) +# define MOZ_FINAL MOZ_HAVE_CXX11_FINAL +#else +# define MOZ_FINAL /* no support */ +#endif + +/** + * MOZ_WARN_UNUSED_RESULT tells the compiler to emit a warning if a function's + * return value is not used by the caller. + * + * Place this attribute at the very beginning of a function definition. For + * example, write + * + * MOZ_WARN_UNUSED_RESULT int foo(); + * + * or + * + * MOZ_WARN_UNUSED_RESULT int foo() { return 42; } + */ +#if defined(__GNUC__) || defined(__clang__) +# define MOZ_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) +#else +# define MOZ_WARN_UNUSED_RESULT +#endif + +/* + * The following macros are attributes that support the static analysis plugin + * included with Mozilla, and will be implemented (when such support is enabled) + * as C++11 attributes. Since such attributes are legal pretty much everywhere + * and have subtly different semantics depending on their placement, the + * following is a guide on where to place the attributes. + * + * Attributes that apply to a struct or class precede the name of the class: + * (Note that this is different from the placement of MOZ_FINAL for classes!) + * + * class MOZ_CLASS_ATTRIBUTE SomeClass {}; + * + * Attributes that apply to functions follow the parentheses and const + * qualifiers but precede MOZ_FINAL, MOZ_OVERRIDE and the function body: + * + * void DeclaredFunction() MOZ_FUNCTION_ATTRIBUTE; + * void SomeFunction() MOZ_FUNCTION_ATTRIBUTE {} + * void PureFunction() const MOZ_FUNCTION_ATTRIBUTE = 0; + * void OverriddenFunction() MOZ_FUNCTION_ATTIRBUTE MOZ_OVERRIDE; + * + * Attributes that apply to variables or parameters follow the variable's name: + * + * int variable MOZ_VARIABLE_ATTRIBUTE; + * + * Attributes that apply to types follow the type name: + * + * typedef int MOZ_TYPE_ATTRIBUTE MagicInt; + * int MOZ_TYPE_ATTRIBUTE someVariable; + * int* MOZ_TYPE_ATTRIBUTE magicPtrInt; + * int MOZ_TYPE_ATTRIBUTE* ptrToMagicInt; + * + * Attributes that apply to statements precede the statement: + * + * MOZ_IF_ATTRIBUTE if (x == 0) + * MOZ_DO_ATTRIBUTE do { } while (0); + * + * Attributes that apply to labels precede the label: + * + * MOZ_LABEL_ATTRIBUTE target: + * goto target; + * MOZ_CASE_ATTRIBUTE case 5: + * MOZ_DEFAULT_ATTRIBUTE default: + * + * The static analyses that are performed by the plugin are as follows: + * + * MOZ_MUST_OVERRIDE: Applies to all C++ member functions. All immediate + * subclasses must provide an exact override of this method; if a subclass + * does not override this method, the compiler will emit an error. This + * attribute is not limited to virtual methods, so if it is applied to a + * nonvirtual method and the subclass does not provide an equivalent + * definition, the compiler will emit an error. + * MOZ_STACK_CLASS: Applies to all classes. Any class with this annotation is + * expected to live on the stack, so it is a compile-time error to use it, or + * an array of such objects, as a global or static variable, or as the type of + * a new expression (unless placement new is being used). If a member of + * another class uses this class, or if another class inherits from this + * class, then it is considered to be a stack class as well, although this + * attribute need not be provided in such cases. + * MOZ_NONHEAP_CLASS: Applies to all classes. Any class with this annotation is + * expected to live on the stack or in static storage, so it is a compile-time + * error to use it, or an array of such objects, as the type of a new + * expression (unless placement new is being used). If a member of another + * class uses this class, or if another class inherits from this class, then + * it is considered to be a non-heap class as well, although this attribute + * need not be provided in such cases. + * MOZ_HEAP_ALLOCATOR: Applies to any function. This indicates that the return + * value is allocated on the heap, and will as a result check such allocations + * during MOZ_STACK_CLASS and MOZ_NONHEAP_CLASS annotation checking. + * MOZ_IMPLICIT: Applies to constructors. Implicit conversion constructors + * are disallowed by default unless they are marked as MOZ_IMPLICIT. This + * attribute must be used for constructors which intend to provide implicit + * conversions. + */ +#ifdef MOZ_CLANG_PLUGIN +# define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override"))) +# define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class"))) +# define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class"))) +# define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) +/* + * It turns out that clang doesn't like void func() __attribute__ {} without a + * warning, so use pragmas to disable the warning. This code won't work on GCC + * anyways, so the warning is safe to ignore. + */ +# define MOZ_HEAP_ALLOCATOR \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((annotate("moz_heap_allocator"))) \ + _Pragma("clang diagnostic pop") +#else +# define MOZ_MUST_OVERRIDE /* nothing */ +# define MOZ_STACK_CLASS /* nothing */ +# define MOZ_NONHEAP_CLASS /* nothing */ +# define MOZ_IMPLICIT /* nothing */ +# define MOZ_HEAP_ALLOCATOR /* nothing */ +#endif /* MOZ_CLANG_PLUGIN */ + +/* + * MOZ_THIS_IN_INITIALIZER_LIST is used to avoid a warning when we know that + * it's safe to use 'this' in an initializer list. + */ +#ifdef _MSC_VER +# define MOZ_THIS_IN_INITIALIZER_LIST() \ + __pragma(warning(push)) \ + __pragma(warning(disable:4355)) \ + this \ + __pragma(warning(pop)) +#else +# define MOZ_THIS_IN_INITIALIZER_LIST() this +#endif + +#endif /* __cplusplus */ + +#endif /* mozilla_Attributes_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/BloomFilter.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/BloomFilter.h new file mode 100644 index 0000000000..6757e41181 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/BloomFilter.h @@ -0,0 +1,256 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * A counting Bloom filter implementation. This allows consumers to + * do fast probabilistic "is item X in set Y?" testing which will + * never answer "no" when the correct answer is "yes" (but might + * incorrectly answer "yes" when the correct answer is "no"). + */ + +#ifndef mozilla_BloomFilter_h +#define mozilla_BloomFilter_h + +#include "mozilla/Assertions.h" +#include "mozilla/Likely.h" + +#include +#include + +namespace mozilla { + +/* + * This class implements a counting Bloom filter as described at + * , with + * 8-bit counters. This allows quick probabilistic answers to the + * question "is object X in set Y?" where the contents of Y might not + * be time-invariant. The probabilistic nature of the test means that + * sometimes the answer will be "yes" when it should be "no". If the + * answer is "no", then X is guaranteed not to be in Y. + * + * The filter is parametrized on KeySize, which is the size of the key + * generated by each of hash functions used by the filter, in bits, + * and the type of object T being added and removed. T must implement + * a |uint32_t hash() const| method which returns a uint32_t hash key + * that will be used to generate the two separate hash functions for + * the Bloom filter. This hash key MUST be well-distributed for good + * results! KeySize is not allowed to be larger than 16. + * + * The filter uses exactly 2**KeySize bytes of memory. From now on we + * will refer to the memory used by the filter as M. + * + * The expected rate of incorrect "yes" answers depends on M and on + * the number N of objects in set Y. As long as N is small compared + * to M, the rate of such answers is expected to be approximately + * 4*(N/M)**2 for this filter. In practice, if Y has a few hundred + * elements then using a KeySize of 12 gives a reasonably low + * incorrect answer rate. A KeySize of 12 has the additional benefit + * of using exactly one page for the filter in typical hardware + * configurations. + */ + +template +class BloomFilter +{ + /* + * A counting Bloom filter with 8-bit counters. For now we assume + * that having two hash functions is enough, but we may revisit that + * decision later. + * + * The filter uses an array with 2**KeySize entries. + * + * Assuming a well-distributed hash function, a Bloom filter with + * array size M containing N elements and + * using k hash function has expected false positive rate exactly + * + * $ (1 - (1 - 1/M)^{kN})^k $ + * + * because each array slot has a + * + * $ (1 - 1/M)^{kN} $ + * + * chance of being 0, and the expected false positive rate is the + * probability that all of the k hash functions will hit a nonzero + * slot. + * + * For reasonable assumptions (M large, kN large, which should both + * hold if we're worried about false positives) about M and kN this + * becomes approximately + * + * $$ (1 - \exp(-kN/M))^k $$ + * + * For our special case of k == 2, that's $(1 - \exp(-2N/M))^2$, + * or in other words + * + * $$ N/M = -0.5 * \ln(1 - \sqrt(r)) $$ + * + * where r is the false positive rate. This can be used to compute + * the desired KeySize for a given load N and false positive rate r. + * + * If N/M is assumed small, then the false positive rate can + * further be approximated as 4*N^2/M^2. So increasing KeySize by + * 1, which doubles M, reduces the false positive rate by about a + * factor of 4, and a false positive rate of 1% corresponds to + * about M/N == 20. + * + * What this means in practice is that for a few hundred keys using a + * KeySize of 12 gives false positive rates on the order of 0.25-4%. + * + * Similarly, using a KeySize of 10 would lead to a 4% false + * positive rate for N == 100 and to quite bad false positive + * rates for larger N. + */ +public: + BloomFilter() + { + static_assert(KeySize <= kKeyShift, "KeySize too big"); + + // Should we have a custom operator new using calloc instead and + // require that we're allocated via the operator? + clear(); + } + + /* + * Clear the filter. This should be done before reusing it, because + * just removing all items doesn't clear counters that hit the upper + * bound. + */ + void clear(); + + /* + * Add an item to the filter. + */ + void add(const T* aValue); + + /* + * Remove an item from the filter. + */ + void remove(const T* aValue); + + /* + * Check whether the filter might contain an item. This can + * sometimes return true even if the item is not in the filter, + * but will never return false for items that are actually in the + * filter. + */ + bool mightContain(const T* aValue) const; + + /* + * Methods for add/remove/contain when we already have a hash computed + */ + void add(uint32_t aHash); + void remove(uint32_t aHash); + bool mightContain(uint32_t aHash) const; + +private: + static const size_t kArraySize = (1 << KeySize); + static const uint32_t kKeyMask = (1 << KeySize) - 1; + static const uint32_t kKeyShift = 16; + + static uint32_t hash1(uint32_t aHash) + { + return aHash & kKeyMask; + } + static uint32_t hash2(uint32_t aHash) + { + return (aHash >> kKeyShift) & kKeyMask; + } + + uint8_t& firstSlot(uint32_t aHash) + { + return mCounters[hash1(aHash)]; + } + uint8_t& secondSlot(uint32_t aHash) + { + return mCounters[hash2(aHash)]; + } + + const uint8_t& firstSlot(uint32_t aHash) const + { + return mCounters[hash1(aHash)]; + } + const uint8_t& secondSlot(uint32_t aHash) const + { + return mCounters[hash2(aHash)]; + } + + static bool full(const uint8_t& aSlot) { return aSlot == UINT8_MAX; } + + uint8_t mCounters[kArraySize]; +}; + +template +inline void +BloomFilter::clear() +{ + memset(mCounters, 0, kArraySize); +} + +template +inline void +BloomFilter::add(uint32_t aHash) +{ + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { + ++slot1; + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { + ++slot2; + } +} + +template +MOZ_ALWAYS_INLINE void +BloomFilter::add(const T* aValue) +{ + uint32_t hash = aValue->hash(); + return add(hash); +} + +template +inline void +BloomFilter::remove(uint32_t aHash) +{ + // If the slots are full, we don't know whether we bumped them to be + // there when we added or not, so just leave them full. + uint8_t& slot1 = firstSlot(aHash); + if (MOZ_LIKELY(!full(slot1))) { + --slot1; + } + uint8_t& slot2 = secondSlot(aHash); + if (MOZ_LIKELY(!full(slot2))) { + --slot2; + } +} + +template +MOZ_ALWAYS_INLINE void +BloomFilter::remove(const T* aValue) +{ + uint32_t hash = aValue->hash(); + remove(hash); +} + +template +MOZ_ALWAYS_INLINE bool +BloomFilter::mightContain(uint32_t aHash) const +{ + // Check that all the slots for this hash contain something + return firstSlot(aHash) && secondSlot(aHash); +} + +template +MOZ_ALWAYS_INLINE bool +BloomFilter::mightContain(const T* aValue) const +{ + uint32_t hash = aValue->hash(); + return mightContain(hash); +} + +} // namespace mozilla + +#endif /* mozilla_BloomFilter_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Casting.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Casting.h new file mode 100644 index 0000000000..dc449af6b6 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Casting.h @@ -0,0 +1,221 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Cast operations to supplement the built-in casting operations. */ + +#ifndef mozilla_Casting_h +#define mozilla_Casting_h + +#include "mozilla/Assertions.h" +#include "mozilla/TypeTraits.h" + +#include + +namespace mozilla { + +/** + * Return a value of type |To|, containing the underlying bit pattern of + * |aFrom|. + * + * |To| and |From| must be types of the same size; be careful of cross-platform + * size differences, or this might fail to compile on some but not all + * platforms. + */ +template +inline To +BitwiseCast(const From aFrom) +{ + static_assert(sizeof(From) == sizeof(To), + "To and From must have the same size"); + union + { + From mFrom; + To mTo; + } u; + u.mFrom = aFrom; + return u.mTo; +} + +namespace detail { + +enum ToSignedness { ToIsSigned, ToIsUnsigned }; +enum FromSignedness { FromIsSigned, FromIsUnsigned }; + +template::value ? FromIsSigned : FromIsUnsigned, + ToSignedness = IsSigned::value ? ToIsSigned : ToIsUnsigned> +struct BoundsCheckImpl; + +// Implicit conversions on operands to binary operations make this all a bit +// hard to verify. Attempt to ease the pain below by *only* comparing values +// that are obviously the same type (and will undergo no further conversions), +// even when it's not strictly necessary, for explicitness. + +enum UUComparison { FromIsBigger, FromIsNotBigger }; + +// Unsigned-to-unsigned range check + +template sizeof(To)) + ? FromIsBigger + : FromIsNotBigger> +struct UnsignedUnsignedCheck; + +template +struct UnsignedUnsignedCheck +{ +public: + static bool checkBounds(const From aFrom) + { + return aFrom <= From(To(-1)); + } +}; + +template +struct UnsignedUnsignedCheck +{ +public: + static bool checkBounds(const From aFrom) + { + return true; + } +}; + +template +struct BoundsCheckImpl +{ +public: + static bool checkBounds(const From aFrom) + { + return UnsignedUnsignedCheck::checkBounds(aFrom); + } +}; + +// Signed-to-unsigned range check + +template +struct BoundsCheckImpl +{ +public: + static bool checkBounds(const From aFrom) + { + if (aFrom < 0) { + return false; + } + if (sizeof(To) >= sizeof(From)) { + return true; + } + return aFrom <= From(To(-1)); + } +}; + +// Unsigned-to-signed range check + +enum USComparison { FromIsSmaller, FromIsNotSmaller }; + +template +struct UnsignedSignedCheck; + +template +struct UnsignedSignedCheck +{ +public: + static bool checkBounds(const From aFrom) + { + return true; + } +}; + +template +struct UnsignedSignedCheck +{ +public: + static bool checkBounds(const From aFrom) + { + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + return aFrom <= From(MaxValue); + } +}; + +template +struct BoundsCheckImpl +{ +public: + static bool checkBounds(const From aFrom) + { + return UnsignedSignedCheck::checkBounds(aFrom); + } +}; + +// Signed-to-signed range check + +template +struct BoundsCheckImpl +{ +public: + static bool checkBounds(const From aFrom) + { + if (sizeof(From) <= sizeof(To)) { + return true; + } + const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1); + const To MinValue = -MaxValue - To(1); + return From(MinValue) <= aFrom && + From(aFrom) <= From(MaxValue); + } +}; + +template::value && + IsIntegral::value> +class BoundsChecker; + +template +class BoundsChecker +{ +public: + static bool checkBounds(const From aFrom) { return true; } +}; + +template +class BoundsChecker +{ +public: + static bool checkBounds(const From aFrom) + { + return BoundsCheckImpl::checkBounds(aFrom); + } +}; + +template +inline bool +IsInBounds(const From aFrom) +{ + return BoundsChecker::checkBounds(aFrom); +} + +} // namespace detail + +/** + * Cast a value of integral type |From| to a value of integral type |To|, + * asserting that the cast will be a safe cast per C++ (that is, that |to| is in + * the range of values permitted for the type |From|). + */ +template +inline To +SafeCast(const From aFrom) +{ + MOZ_ASSERT((detail::IsInBounds(aFrom))); + return static_cast(aFrom); +} + +} // namespace mozilla + +#endif /* mozilla_Casting_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Char16.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Char16.h new file mode 100644 index 0000000000..e54eb0d5c8 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Char16.h @@ -0,0 +1,192 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implements a UTF-16 character type. */ + +#ifndef mozilla_Char16_h +#define mozilla_Char16_h + +#ifdef __cplusplus + +/* + * C++11 introduces a char16_t type and support for UTF-16 string and character + * literals. C++11's char16_t is a distinct builtin type. Technically, char16_t + * is a 16-bit code unit of a Unicode code point, not a "character". + */ + +#ifdef _MSC_VER + /* + * C++11 says char16_t is a distinct builtin type, but Windows's yvals.h + * typedefs char16_t as an unsigned short. We would like to alias char16_t + * to Windows's 16-bit wchar_t so we can declare UTF-16 literals as constant + * expressions (and pass char16_t pointers to Windows APIs). We #define + * _CHAR16T here in order to prevent yvals.h from overriding our char16_t + * typedefs, which we set to wchar_t for C++ code. + * + * In addition, #defining _CHAR16T will prevent yvals.h from defining a + * char32_t type, so we have to undo that damage here and provide our own, + * which is identical to the yvals.h type. + */ +# define MOZ_UTF16_HELPER(s) L##s +# define _CHAR16T +typedef wchar_t char16_t; +typedef unsigned int char32_t; +#else + /* C++11 has a builtin char16_t type. */ +# define MOZ_UTF16_HELPER(s) u##s + /** + * This macro is used to distinguish when char16_t would be a distinct + * typedef from wchar_t. + */ +# define MOZ_CHAR16_IS_NOT_WCHAR +# ifdef WIN32 +# define MOZ_USE_CHAR16_WRAPPER +# endif +#endif + +#ifdef MOZ_USE_CHAR16_WRAPPER +# include + /** + * Win32 API extensively uses wchar_t, which is represented by a separated + * builtin type than char16_t per spec. It's not the case for MSVC, but GCC + * follows the spec. We want to mix wchar_t and char16_t on Windows builds. + * This class is supposed to make it easier. It stores char16_t const pointer, + * but provides implicit casts for wchar_t as well. On other platforms, we + * simply use |typedef const char16_t* char16ptr_t|. Here, we want to make + * the class as similar to this typedef, including providing some casts that + * are allowed by the typedef. + */ +class char16ptr_t +{ +private: + const char16_t* mPtr; + static_assert(sizeof(char16_t) == sizeof(wchar_t), + "char16_t and wchar_t sizes differ"); + +public: + char16ptr_t(const char16_t* aPtr) : mPtr(aPtr) {} + char16ptr_t(const wchar_t* aPtr) : + mPtr(reinterpret_cast(aPtr)) + {} + + /* Without this, nullptr assignment would be ambiguous. */ + constexpr char16ptr_t(decltype(nullptr)) : mPtr(nullptr) {} + + operator const char16_t*() const + { + return mPtr; + } + operator const wchar_t*() const + { + return reinterpret_cast(mPtr); + } + operator const void*() const + { + return mPtr; + } + operator bool() const + { + return mPtr != nullptr; + } + operator std::wstring() const + { + return std::wstring(static_cast(*this)); + } + + /* Explicit cast operators to allow things like (char16_t*)str. */ + explicit operator char16_t*() const + { + return const_cast(mPtr); + } + explicit operator wchar_t*() const + { + return const_cast(static_cast(*this)); + } + + /** + * Some Windows API calls accept BYTE* but require that data actually be + * WCHAR*. Supporting this requires explicit operators to support the + * requisite explicit casts. + */ + explicit operator const char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator const unsigned char*() const + { + return reinterpret_cast(mPtr); + } + explicit operator unsigned char*() const + { + return + const_cast(reinterpret_cast(mPtr)); + } + explicit operator void*() const + { + return const_cast(mPtr); + } + + /* Some operators used on pointers. */ + char16_t operator[](size_t aIndex) const + { + return mPtr[aIndex]; + } + bool operator==(const char16ptr_t& aOther) const + { + return mPtr == aOther.mPtr; + } + bool operator==(decltype(nullptr)) const + { + return mPtr == nullptr; + } + bool operator!=(const char16ptr_t& aOther) const + { + return mPtr != aOther.mPtr; + } + bool operator!=(decltype(nullptr)) const + { + return mPtr != nullptr; + } + char16ptr_t operator+(size_t aValue) const + { + return char16ptr_t(mPtr + aValue); + } + ptrdiff_t operator-(const char16ptr_t& aOther) const + { + return mPtr - aOther.mPtr; + } +}; + +inline decltype((char*)0-(char*)0) +operator-(const char16_t* aX, const char16ptr_t aY) +{ + return aX - static_cast(aY); +} + +#else + +typedef const char16_t* char16ptr_t; + +#endif + +/* + * Macro arguments used in concatenation or stringification won't be expanded. + * Therefore, in order for |MOZ_UTF16(FOO)| to work as expected (which is to + * expand |FOO| before doing whatever |MOZ_UTF16| needs to do to it) a helper + * macro, |MOZ_UTF16_HELPER| needs to be inserted in between to allow the macro + * argument to expand. See "3.10.6 Separate Expansion of Macro Arguments" of the + * CPP manual for a more accurate and precise explanation. + */ +#define MOZ_UTF16(s) MOZ_UTF16_HELPER(s) + +static_assert(sizeof(char16_t) == 2, "Is char16_t type 16 bits?"); +static_assert(char16_t(-1) > char16_t(0), "Is char16_t type unsigned?"); +static_assert(sizeof(MOZ_UTF16('A')) == 2, "Is char literal 16 bits?"); +static_assert(sizeof(MOZ_UTF16("")[0]) == 2, "Is string char 16 bits?"); + +#endif + +#endif /* mozilla_Char16_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/CheckedInt.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/CheckedInt.h new file mode 100644 index 0000000000..ad4c5fef41 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/CheckedInt.h @@ -0,0 +1,779 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Provides checked integers, detecting integer overflow and divide-by-0. */ + +#ifndef mozilla_CheckedInt_h +#define mozilla_CheckedInt_h + +#include +#include "mozilla/Assertions.h" +#include "mozilla/IntegerTypeTraits.h" + +namespace mozilla { + +template class CheckedInt; + +namespace detail { + +/* + * Step 1: manually record supported types + * + * What's nontrivial here is that there are different families of integer + * types: basic integer types and stdint types. It is merrily undefined which + * types from one family may be just typedefs for a type from another family. + * + * For example, on GCC 4.6, aside from the basic integer types, the only other + * type that isn't just a typedef for some of them, is int8_t. + */ + +struct UnsupportedType {}; + +template +struct IsSupportedPass2 +{ + static const bool value = false; +}; + +template +struct IsSupported +{ + static const bool value = IsSupportedPass2::value; +}; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + +template<> +struct IsSupported +{ static const bool value = true; }; + + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +template<> +struct IsSupportedPass2 +{ static const bool value = true; }; + +/* + * Step 2: Implement the actual validity checks. + * + * Ideas taken from IntegerLib, code different. + */ + +template +struct TwiceBiggerType +{ + typedef typename detail::StdintTypeForSizeAndSignedness< + sizeof(IntegerType) * 2, + IsSigned::value + >::Type Type; +}; + +template +struct TwiceBiggerType +{ + typedef UnsupportedType Type; +}; + +template +inline bool +HasSignBit(T aX) +{ + // In C++, right bit shifts on negative values is undefined by the standard. + // Notice that signed-to-unsigned conversions are always well-defined in the + // standard, as the value congruent modulo 2**n as expected. By contrast, + // unsigned-to-signed is only well-defined if the value is representable. + return bool(typename MakeUnsigned::Type(aX) >> + PositionOfSignBit::value); +} + +// Bitwise ops may return a larger type, so it's good to use this inline +// helper guaranteeing that the result is really of type T. +template +inline T +BinaryComplement(T aX) +{ + return ~aX; +} + +template::value, + bool IsUSigned = IsSigned::value> +struct DoesRangeContainRange +{ +}; + +template +struct DoesRangeContainRange +{ + static const bool value = sizeof(T) >= sizeof(U); +}; + +template +struct DoesRangeContainRange +{ + static const bool value = sizeof(T) > sizeof(U); +}; + +template +struct DoesRangeContainRange +{ + static const bool value = false; +}; + +template::value, + bool IsUSigned = IsSigned::value, + bool DoesTRangeContainURange = DoesRangeContainRange::value> +struct IsInRangeImpl {}; + +template +struct IsInRangeImpl +{ + static bool run(U) + { + return true; + } +}; + +template +struct IsInRangeImpl +{ + static bool run(U aX) + { + return aX <= MaxValue::value && aX >= MinValue::value; + } +}; + +template +struct IsInRangeImpl +{ + static bool run(U aX) + { + return aX <= MaxValue::value; + } +}; + +template +struct IsInRangeImpl +{ + static bool run(U aX) + { + return sizeof(T) > sizeof(U) || aX <= U(MaxValue::value); + } +}; + +template +struct IsInRangeImpl +{ + static bool run(U aX) + { + return sizeof(T) >= sizeof(U) + ? aX >= 0 + : aX >= 0 && aX <= U(MaxValue::value); + } +}; + +template +inline bool +IsInRange(U aX) +{ + return IsInRangeImpl::run(aX); +} + +template +inline bool +IsAddValid(T aX, T aY) +{ + // Addition is valid if the sign of aX+aY is equal to either that of aX or + // that of aY. Since the value of aX+aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. Beware! + // These bitwise operations can return a larger integer type, if T was a + // small type like int8_t, so we explicitly cast to T. + + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux + uy; + return IsSigned::value + ? HasSignBit(BinaryComplement(T((result ^ aX) & (result ^ aY)))) + : BinaryComplement(aX) >= aY; +} + +template +inline bool +IsSubValid(T aX, T aY) +{ + // Subtraction is valid if either aX and aY have same sign, or aX-aY and aX + // have same sign. Since the value of aX-aY is undefined if we have a signed + // type, we compute it using the unsigned type of the same size. + typename MakeUnsigned::Type ux = aX; + typename MakeUnsigned::Type uy = aY; + typename MakeUnsigned::Type result = ux - uy; + + return IsSigned::value + ? HasSignBit(BinaryComplement(T((result ^ aX) & (aX ^ aY)))) + : aX >= aY; +} + +template::value, + bool TwiceBiggerTypeIsSupported = + IsSupported::Type>::value> +struct IsMulValidImpl {}; + +template +struct IsMulValidImpl +{ + static bool run(T aX, T aY) + { + typedef typename TwiceBiggerType::Type TwiceBiggerType; + TwiceBiggerType product = TwiceBiggerType(aX) * TwiceBiggerType(aY); + return IsInRange(product); + } +}; + +template +struct IsMulValidImpl +{ + static bool run(T aX, T aY) + { + const T max = MaxValue::value; + const T min = MinValue::value; + + if (aX == 0 || aY == 0) { + return true; + } + if (aX > 0) { + return aY > 0 + ? aX <= max / aY + : aY >= min / aX; + } + + // If we reach this point, we know that aX < 0. + return aY > 0 + ? aX >= min / aY + : aY >= max / aX; + } +}; + +template +struct IsMulValidImpl +{ + static bool run(T aX, T aY) + { + return aY == 0 || aX <= MaxValue::value / aY; + } +}; + +template +inline bool +IsMulValid(T aX, T aY) +{ + return IsMulValidImpl::run(aX, aY); +} + +template +inline bool +IsDivValid(T aX, T aY) +{ + // Keep in mind that in the signed case, min/-1 is invalid because + // abs(min)>max. + return aY != 0 && + !(IsSigned::value && aX == MinValue::value && aY == T(-1)); +} + +template::value> +struct IsModValidImpl; + +template +inline bool +IsModValid(T aX, T aY) +{ + return IsModValidImpl::run(aX, aY); +} + +/* + * Mod is pretty simple. + * For now, let's just use the ANSI C definition: + * If aX or aY are negative, the results are implementation defined. + * Consider these invalid. + * Undefined for aY=0. + * The result will never exceed either aX or aY. + * + * Checking that aX>=0 is a warning when T is unsigned. + */ + +template +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + return aY >= 1; + } +}; + +template +struct IsModValidImpl +{ + static inline bool run(T aX, T aY) + { + if (aX < 0) { + return false; + } + return aY >= 1; + } +}; + +template::value> +struct NegateImpl; + +template +struct NegateImpl +{ + static CheckedInt negate(const CheckedInt& aVal) + { + // Handle negation separately for signed/unsigned, for simpler code and to + // avoid an MSVC warning negating an unsigned value. + return CheckedInt(0, aVal.isValid() && aVal.mValue == 0); + } +}; + +template +struct NegateImpl +{ + static CheckedInt negate(const CheckedInt& aVal) + { + // Watch out for the min-value, which (with twos-complement) can't be + // negated as -min-value is then (max-value + 1). + if (!aVal.isValid() || aVal.mValue == MinValue::value) { + return CheckedInt(aVal.mValue, false); + } + return CheckedInt(-aVal.mValue, true); + } +}; + +} // namespace detail + + +/* + * Step 3: Now define the CheckedInt class. + */ + +/** + * @class CheckedInt + * @brief Integer wrapper class checking for integer overflow and other errors + * @param T the integer type to wrap. Can be any type among the following: + * - any basic integer type such as |int| + * - any stdint type such as |int8_t| + * + * This class implements guarded integer arithmetic. Do a computation, check + * that isValid() returns true, you then have a guarantee that no problem, such + * as integer overflow, happened during this computation, and you can call + * value() to get the plain integer value. + * + * The arithmetic operators in this class are guaranteed not to raise a signal + * (e.g. in case of a division by zero). + * + * For example, suppose that you want to implement a function that computes + * (aX+aY)/aZ, that doesn't crash if aZ==0, and that reports on error (divide by + * zero or integer overflow). You could code it as follows: + @code + bool computeXPlusYOverZ(int aX, int aY, int aZ, int* aResult) + { + CheckedInt checkedResult = (CheckedInt(aX) + aY) / aZ; + if (checkedResult.isValid()) { + *aResult = checkedResult.value(); + return true; + } else { + return false; + } + } + @endcode + * + * Implicit conversion from plain integers to checked integers is allowed. The + * plain integer is checked to be in range before being casted to the + * destination type. This means that the following lines all compile, and the + * resulting CheckedInts are correctly detected as valid or invalid: + * @code + // 1 is of type int, is found to be in range for uint8_t, x is valid + CheckedInt x(1); + // -1 is of type int, is found not to be in range for uint8_t, x is invalid + CheckedInt x(-1); + // -1 is of type int, is found to be in range for int8_t, x is valid + CheckedInt x(-1); + // 1000 is of type int16_t, is found not to be in range for int8_t, + // x is invalid + CheckedInt x(int16_t(1000)); + // 3123456789 is of type uint32_t, is found not to be in range for int32_t, + // x is invalid + CheckedInt x(uint32_t(3123456789)); + * @endcode + * Implicit conversion from + * checked integers to plain integers is not allowed. As shown in the + * above example, to get the value of a checked integer as a normal integer, + * call value(). + * + * Arithmetic operations between checked and plain integers is allowed; the + * result type is the type of the checked integer. + * + * Checked integers of different types cannot be used in the same arithmetic + * expression. + * + * There are convenience typedefs for all stdint types, of the following form + * (these are just 2 examples): + @code + typedef CheckedInt CheckedInt32; + typedef CheckedInt CheckedUint16; + @endcode + */ +template +class CheckedInt +{ +protected: + T mValue; + bool mIsValid; + + template + CheckedInt(U aValue, bool aIsValid) : mValue(aValue), mIsValid(aIsValid) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } + + friend struct detail::NegateImpl; + +public: + /** + * Constructs a checked integer with given @a value. The checked integer is + * initialized as valid or invalid depending on whether the @a value + * is in range. + * + * This constructor is not explicit. Instead, the type of its argument is a + * separate template parameter, ensuring that no conversion is performed + * before this constructor is actually called. As explained in the above + * documentation for class CheckedInt, this constructor checks that its + * argument is valid. + */ + template + CheckedInt(U aValue) + : mValue(T(aValue)), + mIsValid(detail::IsInRange(aValue)) + { + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } + + template + friend class CheckedInt; + + template + CheckedInt toChecked() const + { + CheckedInt ret(mValue); + ret.mIsValid = ret.mIsValid && mIsValid; + return ret; + } + + /** Constructs a valid checked integer with initial value 0 */ + CheckedInt() : mValue(0), mIsValid(true) + { + static_assert(detail::IsSupported::value, + "This type is not supported by CheckedInt"); + } + + /** @returns the actual value */ + T value() const + { + MOZ_ASSERT(mIsValid, "Invalid checked integer (division by zero or integer overflow)"); + return mValue; + } + + /** + * @returns true if the checked integer is valid, i.e. is not the result + * of an invalid operation or of an operation involving an invalid checked + * integer + */ + bool isValid() const + { + return mIsValid; + } + + template + friend CheckedInt operator +(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator +=(U aRhs); + + template + friend CheckedInt operator -(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator -=(U aRhs); + + template + friend CheckedInt operator *(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator *=(U aRhs); + + template + friend CheckedInt operator /(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator /=(U aRhs); + + template + friend CheckedInt operator %(const CheckedInt& aLhs, + const CheckedInt& aRhs); + template + CheckedInt& operator %=(U aRhs); + + CheckedInt operator -() const + { + return detail::NegateImpl::negate(*this); + } + + /** + * @returns true if the left and right hand sides are valid + * and have the same value. + * + * Note that these semantics are the reason why we don't offer + * a operator!=. Indeed, we'd want to have a!=b be equivalent to !(a==b) + * but that would mean that whenever a or b is invalid, a!=b + * is always true, which would be very confusing. + * + * For similar reasons, operators <, >, <=, >= would be very tricky to + * specify, so we just avoid offering them. + * + * Notice that these == semantics are made more reasonable by these facts: + * 1. a==b implies equality at the raw data level + * (the converse is false, as a==b is never true among invalids) + * 2. This is similar to the behavior of IEEE floats, where a==b + * means that a and b have the same value *and* neither is NaN. + */ + bool operator ==(const CheckedInt& aOther) const + { + return mIsValid && aOther.mIsValid && mValue == aOther.mValue; + } + + /** prefix ++ */ + CheckedInt& operator++() + { + *this += 1; + return *this; + } + + /** postfix ++ */ + CheckedInt operator++(int) + { + CheckedInt tmp = *this; + *this += 1; + return tmp; + } + + /** prefix -- */ + CheckedInt& operator--() + { + *this -= 1; + return *this; + } + + /** postfix -- */ + CheckedInt operator--(int) + { + CheckedInt tmp = *this; + *this -= 1; + return tmp; + } + +private: + /** + * The !=, <, <=, >, >= operators are disabled: + * see the comment on operator==. + */ + template bool operator !=(U aOther) const MOZ_DELETE; + template bool operator < (U aOther) const MOZ_DELETE; + template bool operator <=(U aOther) const MOZ_DELETE; + template bool operator > (U aOther) const MOZ_DELETE; + template bool operator >=(U aOther) const MOZ_DELETE; +}; + +#define MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP) \ + template \ + inline CheckedInt \ + operator OP(const CheckedInt &aLhs, const CheckedInt &aRhs) \ + { \ + if (!detail::Is##NAME##Valid(aLhs.mValue, aRhs.mValue)) { \ + return CheckedInt(0, false); \ + } \ + return CheckedInt(aLhs.mValue OP aRhs.mValue, \ + aLhs.mIsValid && aRhs.mIsValid); \ + } + +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Add, +) +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Sub, -) +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Mul, *) +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Div, /) +MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Mod, %) + +#undef MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR + +// Implement castToCheckedInt(x), making sure that +// - it allows x to be either a CheckedInt or any integer type +// that can be casted to T +// - if x is already a CheckedInt, we just return a reference to it, +// instead of copying it (optimization) + +namespace detail { + +template +struct CastToCheckedIntImpl +{ + typedef CheckedInt ReturnType; + static CheckedInt run(U aU) { return aU; } +}; + +template +struct CastToCheckedIntImpl > +{ + typedef const CheckedInt& ReturnType; + static const CheckedInt& run(const CheckedInt& aU) { return aU; } +}; + +} // namespace detail + +template +inline typename detail::CastToCheckedIntImpl::ReturnType +castToCheckedInt(U aU) +{ + static_assert(detail::IsSupported::value && + detail::IsSupported::value, + "This type is not supported by CheckedInt"); + return detail::CastToCheckedIntImpl::run(aU); +} + +#define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP) \ + template \ + template \ + CheckedInt& CheckedInt::operator COMPOUND_OP(U aRhs) \ + { \ + *this = *this OP castToCheckedInt(aRhs); \ + return *this; \ + } \ + template \ + inline CheckedInt operator OP(const CheckedInt &aLhs, U aRhs) \ + { \ + return aLhs OP castToCheckedInt(aRhs); \ + } \ + template \ + inline CheckedInt operator OP(U aLhs, const CheckedInt &aRhs) \ + { \ + return castToCheckedInt(aLhs) OP aRhs; \ + } + +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(+, +=) +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(*, *=) +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(-, -=) +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(/, /=) +MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(%, %=) + +#undef MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS + +template +inline bool +operator ==(const CheckedInt &aLhs, U aRhs) +{ + return aLhs == castToCheckedInt(aRhs); +} + +template +inline bool +operator ==(U aLhs, const CheckedInt &aRhs) +{ + return castToCheckedInt(aLhs) == aRhs; +} + +// Convenience typedefs. +typedef CheckedInt CheckedInt8; +typedef CheckedInt CheckedUint8; +typedef CheckedInt CheckedInt16; +typedef CheckedInt CheckedUint16; +typedef CheckedInt CheckedInt32; +typedef CheckedInt CheckedUint32; +typedef CheckedInt CheckedInt64; +typedef CheckedInt CheckedUint64; + +} // namespace mozilla + +#endif /* mozilla_CheckedInt_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Compiler.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Compiler.h new file mode 100644 index 0000000000..50f127da86 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Compiler.h @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Various compiler checks. */ + +#ifndef mozilla_Compiler_h +#define mozilla_Compiler_h + +#define MOZ_IS_GCC 0 +#define MOS_IS_MSVC 0 + +#if !defined(__clang__) && defined(__GNUC__) + +# undef MOZ_IS_GCC +# define MOZ_IS_GCC 1 + /* + * This macro should simplify gcc version checking. For example, to check + * for gcc 4.5.1 or later, check `#if MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`. + */ +# define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel) \ + ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \ + >= ((major) * 10000 + (minor) * 100 + (patchlevel))) +# if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0) +# error "mfbt (and Gecko) require at least gcc 4.4 to build." +# endif + +#elif defined(_MSC_VER) + +# undef MOZ_IS_MSVC +# define MOZ_IS_MSVC 1 + /* + * This macro should simplify MSVC version checking. For example, to check + * for VC10 or later, check `#ifdef MOZ_MSVC_VERSION_AT_LEAST(10)`. + */ +# define MOZ_MSVC_VERSION_AT_LEAST(version) \ + (version == 10 ? _MSC_VER >= 1600 : \ + (version == 11 ? _MSC_VER >= 1700 : \ + (version == 12 ? _MSC_VER >= 1800 : \ + (version == 13 ? _MSC_VER >= 1900 : \ + 0)))) +# if !MOZ_MSVC_VERSION_AT_LEAST(10) +# error "mfbt (and Gecko) require at least MSVC 2010 RTM to build." +# endif + +#endif + +/* + * The situation with standard libraries is a lot worse than with compilers, + * particularly as clang and gcc could end up using one of three or so standard + * libraries, and they may not be up-to-snuff with newer C++11 versions. To + * detect the library, we're going to include cstddef (which is a small header + * which will be transitively included by everybody else at some point) to grab + * the version macros and deduce macros from there. + */ +#ifdef __cplusplus +# include +# ifdef _STLPORT_MAJOR +# define MOZ_USING_STLPORT 1 +# define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) \ + (_STLPORT_VERSION >= ((major) << 8 | (minor) << 4 | (patch))) +# elif defined(_LIBCPP_VERSION) + /* + * libc++, unfortunately, doesn't appear to have useful versioning macros. + * Hopefully, the recommendations of N3694 with respect to standard libraries + * will get applied instead and we won't need to worry about version numbers + * here. + */ +# define MOZ_USING_LIBCXX 1 +# elif defined(__GLIBCXX__) +# define MOZ_USING_LIBSTDCXX 1 + /* + * libstdc++ is also annoying and doesn't give us useful versioning macros + * for the library. If we're using gcc, then assume that libstdc++ matches + * the compiler version. If we're using clang, we're going to have to fake + * major/minor combinations by looking for newly-defined config macros. + */ +# if MOZ_IS_GCC +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + MOZ_GCC_VERSION_AT_LEAST(major, minor, patch) +# elif defined(_GLIBCXX_THROW_OR_ABORT) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 8)) +# elif defined(_GLIBCXX_NOEXCEPT) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 7)) +# elif defined(_GLIBCXX_USE_DEPRECATED) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 6)) +# elif defined(_GLIBCXX_PSEUDO_VISIBILITY) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 5)) +# elif defined(_GLIBCXX_BEGIN_EXTERN_C) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 4)) +# elif defined(_GLIBCXX_VISIBILITY_ATTR) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 3)) +# elif defined(_GLIBCXX_VISIBILITY) +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ + ((major) < 4 || ((major) == 4 && (minor) <= 2)) +# else +# error "Your version of libstdc++ is unknown to us and is likely too old." +# endif +# endif + + // Flesh out the defines for everyone else +# ifndef MOZ_USING_STLPORT +# define MOZ_USING_STLPORT 0 +# define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) 0 +# endif +# ifndef MOZ_USING_LIBCXX +# define MOZ_USING_LIBCXX 0 +# endif +# ifndef MOZ_USING_LIBSTDCXX +# define MOZ_USING_LIBSTDCXX 0 +# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) 0 +# endif +#endif /* __cplusplus */ + +#endif /* mozilla_Compiler_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Compression.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Compression.h new file mode 100644 index 0000000000..a764a1b5d5 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Compression.h @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Various simple compression/decompression functions. */ + +#ifndef mozilla_Compression_h_ +#define mozilla_Compression_h_ + +#include "mozilla/Types.h" +#include "mozilla/Assertions.h" + +namespace mozilla { +namespace Compression { + +/** + * LZ4 is a very fast byte-wise compression algorithm. + * + * Compared to Google's Snappy it is faster to compress and decompress and + * generally produces output of about the same size. + * + * Compared to zlib it compresses at about 10x the speed, decompresses at about + * 4x the speed and produces output of about 1.5x the size. + */ + +class LZ4 +{ +public: + /** + * Compresses |aInputSize| bytes from |aSource| into |aDest|. Destination + * buffer must be already allocated, and must be sized to handle worst cases + * situations (input data not compressible). Worst case size evaluation is + * provided by function maxCompressedSize() + * + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return the number of bytes written in buffer |aDest| + */ + static MFBT_API size_t + compress(const char* aSource, size_t aInputSize, char* aDest); + + /** + * Compress |aInputSize| bytes from |aSource| into an output buffer + * |aDest| of maximum size |aMaxOutputSize|. If it cannot achieve it, + * compression will stop, and result of the function will be zero, + * |aDest| will still be written to, but since the number of input + * bytes consumed is not returned the result is not usable. + * + * This function never writes outside of provided output buffer. + * + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @param aMaxOutputSize is the size of the destination buffer (which must + * be already allocated) + * @return the number of bytes written in buffer |aDest| or 0 if the + * compression fails + */ + static MFBT_API size_t + compressLimitedOutput(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize); + + /** + * If the source stream is malformed, the function will stop decoding + * and return a negative result, indicating the byte position of the + * faulty instruction + * + * This function never writes outside of provided buffers, and never + * modifies input buffer. + * + * Note: destination buffer must be already allocated, and its size must be a + * minimum of |aOutputSize| bytes. + * + * @param aOutputSize is the output size, therefore the original size + * @return the number of bytes read in the source buffer + */ + static MFBT_API bool + decompress(const char* aSource, char* aDest, size_t aOutputSize); + + /** + * If the source stream is malformed, the function will stop decoding + * and return false. + * + * This function never writes beyond aDest + aMaxOutputSize, and is + * therefore protected against malicious data packets. + * + * Note: Destination buffer must be already allocated. This version is + * slightly slower than the decompress without the aMaxOutputSize. + * + * @param aInputSize is the length of the input compressed data + * @param aMaxOutputSize is the size of the destination buffer (which must be + * already allocated) + * @param aOutputSize the actual number of bytes decoded in the destination + * buffer (necessarily <= aMaxOutputSize) + */ + static MFBT_API bool + decompress(const char* aSource, size_t aInputSize, char* aDest, + size_t aMaxOutputSize, size_t* aOutputSize); + + /* + * Provides the maximum size that LZ4 may output in a "worst case" + * scenario (input data not compressible) primarily useful for memory + * allocation of output buffer. + * note : this function is limited by "int" range (2^31-1) + * + * @param aInputSize is the input size. Max supported value is ~1.9GB + * @return maximum output size in a "worst case" scenario + */ + static inline size_t maxCompressedSize(size_t aInputSize) + { + size_t max = (aInputSize + (aInputSize / 255) + 16); + MOZ_ASSERT(max > aInputSize); + return max; + } +}; + +} /* namespace Compression */ +} /* namespace mozilla */ + +#endif /* mozilla_Compression_h_ */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Constants.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Constants.h new file mode 100644 index 0000000000..86bbb6b354 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Constants.h @@ -0,0 +1,16 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* mfbt math constants. */ + +#ifndef mozilla_Constants_h +#define mozilla_Constants_h + +#ifndef M_PI +# define M_PI 3.14159265358979323846 +#endif + +#endif /* mozilla_Constants_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/DebugOnly.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/DebugOnly.h new file mode 100644 index 0000000000..5d0197b194 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/DebugOnly.h @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Provides DebugOnly, a type for variables used only in debug builds (i.e. by + * assertions). + */ + +#ifndef mozilla_DebugOnly_h +#define mozilla_DebugOnly_h + +#include "mozilla/Attributes.h" + +namespace mozilla { + +/** + * DebugOnly contains a value of type T, but only in debug builds. In release + * builds, it does not contain a value. This helper is intended to be used with + * MOZ_ASSERT()-style macros, allowing one to write: + * + * DebugOnly check = func(); + * MOZ_ASSERT(check); + * + * more concisely than declaring |check| conditional on #ifdef DEBUG, but also + * without allocating storage space for |check| in release builds. + * + * DebugOnly instances can only be coerced to T in debug builds. In release + * builds they don't have a value, so type coercion is not well defined. + * + * Note that DebugOnly instances still take up one byte of space, plus padding, + * when used as members of structs. + */ +template +class DebugOnly +{ +public: +#ifdef DEBUG + T value; + + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T& aOther) : value(aOther) { } + DebugOnly(const DebugOnly& aOther) : value(aOther.value) { } + DebugOnly& operator=(const T& aRhs) { + value = aRhs; + return *this; + } + + void operator++(int) { value++; } + void operator--(int) { value--; } + + T* operator&() { return &value; } + + operator T&() { return value; } + operator const T&() const { return value; } + + T& operator->() { return value; } + const T& operator->() const { return value; } + +#else + DebugOnly() { } + MOZ_IMPLICIT DebugOnly(const T&) { } + DebugOnly(const DebugOnly&) { } + DebugOnly& operator=(const T&) { return *this; } + void operator++(int) { } + void operator--(int) { } +#endif + + /* + * DebugOnly must always have a destructor or else it will + * generate "unused variable" warnings, exactly what it's intended + * to avoid! + */ + ~DebugOnly() {} +}; + +} + +#endif /* mozilla_DebugOnly_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Endian.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Endian.h new file mode 100644 index 0000000000..b36991ff88 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Endian.h @@ -0,0 +1,697 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Functions for reading and writing integers in various endiannesses. */ + +/* + * The classes LittleEndian and BigEndian expose static methods for + * reading and writing 16-, 32-, and 64-bit signed and unsigned integers + * in their respective endianness. The naming scheme is: + * + * {Little,Big}Endian::{read,write}{Uint,Int} + * + * For instance, LittleEndian::readInt32 will read a 32-bit signed + * integer from memory in little endian format. Similarly, + * BigEndian::writeUint16 will write a 16-bit unsigned integer to memory + * in big-endian format. + * + * The class NativeEndian exposes methods for conversion of existing + * data to and from the native endianness. These methods are intended + * for cases where data needs to be transferred, serialized, etc. + * swap{To,From}{Little,Big}Endian byteswap a single value if necessary. + * Bulk conversion functions are also provided which optimize the + * no-conversion-needed case: + * + * - copyAndSwap{To,From}{Little,Big}Endian; + * - swap{To,From}{Little,Big}EndianInPlace. + * + * The *From* variants are intended to be used for reading data and the + * *To* variants for writing data. + * + * Methods on NativeEndian work with integer data of any type. + * Floating-point data is not supported. + * + * For clarity in networking code, "Network" may be used as a synonym + * for "Big" in any of the above methods or class names. + * + * As an example, reading a file format header whose fields are stored + * in big-endian format might look like: + * + * class ExampleHeader + * { + * private: + * uint32_t mMagic; + * uint32_t mLength; + * uint32_t mTotalRecords; + * uint64_t mChecksum; + * + * public: + * ExampleHeader(const void* data) + * { + * const uint8_t* ptr = static_cast(data); + * mMagic = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mLength = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mTotalRecords = BigEndian::readUint32(ptr); ptr += sizeof(uint32_t); + * mChecksum = BigEndian::readUint64(ptr); + * } + * ... + * }; + */ + +#ifndef mozilla_Endian_h +#define mozilla_Endian_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/DebugOnly.h" +#include "mozilla/TypeTraits.h" + +#include +#include + +#if defined(_MSC_VER) && _MSC_VER >= 1300 +# include +# pragma intrinsic(_byteswap_ushort) +# pragma intrinsic(_byteswap_ulong) +# pragma intrinsic(_byteswap_uint64) +#endif + +#if defined(_WIN64) +# if defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_) +# define MOZ_LITTLE_ENDIAN 1 +# else +# error "CPU type is unknown" +# endif +#elif defined(_WIN32) +# if defined(_M_IX86) +# define MOZ_LITTLE_ENDIAN 1 +# elif defined(_M_ARM) +# define MOZ_LITTLE_ENDIAN 1 +# else +# error "CPU type is unknown" +# endif +#elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) +# if __LITTLE_ENDIAN__ +# define MOZ_LITTLE_ENDIAN 1 +# elif __BIG_ENDIAN__ +# define MOZ_BIG_ENDIAN 1 +# endif +#elif defined(__GNUC__) && \ + defined(__BYTE_ORDER__) && \ + defined(__ORDER_LITTLE_ENDIAN__) && \ + defined(__ORDER_BIG_ENDIAN__) + /* + * Some versions of GCC provide architecture-independent macros for + * this. Yes, there are more than two values for __BYTE_ORDER__. + */ +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define MOZ_LITTLE_ENDIAN 1 +# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define MOZ_BIG_ENDIAN 1 +# else +# error "Can't handle mixed-endian architectures" +# endif +/* + * We can't include useful headers like or + * here because they're not present on all platforms. Instead we have + * this big conditional that ideally will catch all the interesting + * cases. + */ +#elif defined(__sparc) || defined(__sparc__) || \ + defined(_POWER) || defined(__hppa) || \ + defined(_MIPSEB) || defined(__ARMEB__) || \ + defined(__s390__) || defined(__AARCH64EB__) || \ + (defined(__sh__) && defined(__LITTLE_ENDIAN__)) || \ + (defined(__ia64) && defined(__BIG_ENDIAN__)) +# define MOZ_BIG_ENDIAN 1 +#elif defined(__i386) || defined(__i386__) || \ + defined(__x86_64) || defined(__x86_64__) || \ + defined(_MIPSEL) || defined(__ARMEL__) || \ + defined(__alpha__) || defined(__AARCH64EL__) || \ + (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ + (defined(__ia64) && !defined(__BIG_ENDIAN__)) +# define MOZ_LITTLE_ENDIAN 1 +#endif + +#if MOZ_BIG_ENDIAN +# define MOZ_LITTLE_ENDIAN 0 +#elif MOZ_LITTLE_ENDIAN +# define MOZ_BIG_ENDIAN 0 +#else +# error "Cannot determine endianness" +#endif + +#if defined(__clang__) +# if __has_builtin(__builtin_bswap16) +# define MOZ_HAVE_BUILTIN_BYTESWAP16 __builtin_bswap16 +# endif +#elif defined(__GNUC__) +# if MOZ_GCC_VERSION_AT_LEAST(4, 8, 0) +# define MOZ_HAVE_BUILTIN_BYTESWAP16 __builtin_bswap16 +# endif +#elif defined(_MSC_VER) +# define MOZ_HAVE_BUILTIN_BYTESWAP16 _byteswap_ushort +#endif + +namespace mozilla { + +namespace detail { + +/* + * We need wrappers here because free functions with default template + * arguments and/or partial specialization of function templates are not + * supported by all the compilers we use. + */ +template +struct Swapper; + +template +struct Swapper +{ + static T swap(T aValue) + { +#if defined(MOZ_HAVE_BUILTIN_BYTESWAP16) + return MOZ_HAVE_BUILTIN_BYTESWAP16(aValue); +#else + return T(((aValue & 0x00ff) << 8) | ((aValue & 0xff00) >> 8)); +#endif + } +}; + +template +struct Swapper +{ + static T swap(T aValue) + { +#if defined(__clang__) || defined(__GNUC__) + return T(__builtin_bswap32(aValue)); +#elif defined(_MSC_VER) + return T(_byteswap_ulong(aValue)); +#else + return T(((aValue & 0x000000ffU) << 24) | + ((aValue & 0x0000ff00U) << 8) | + ((aValue & 0x00ff0000U) >> 8) | + ((aValue & 0xff000000U) >> 24)); +#endif + } +}; + +template +struct Swapper +{ + static inline T swap(T aValue) + { +#if defined(__clang__) || defined(__GNUC__) + return T(__builtin_bswap64(aValue)); +#elif defined(_MSC_VER) + return T(_byteswap_uint64(aValue)); +#else + return T(((aValue & 0x00000000000000ffULL) << 56) | + ((aValue & 0x000000000000ff00ULL) << 40) | + ((aValue & 0x0000000000ff0000ULL) << 24) | + ((aValue & 0x00000000ff000000ULL) << 8) | + ((aValue & 0x000000ff00000000ULL) >> 8) | + ((aValue & 0x0000ff0000000000ULL) >> 24) | + ((aValue & 0x00ff000000000000ULL) >> 40) | + ((aValue & 0xff00000000000000ULL) >> 56)); +#endif + } +}; + +enum Endianness { Little, Big }; + +#if MOZ_BIG_ENDIAN +# define MOZ_NATIVE_ENDIANNESS detail::Big +#else +# define MOZ_NATIVE_ENDIANNESS detail::Little +#endif + +class EndianUtils +{ + /** + * Assert that the memory regions [aDest, aDest+aCount) and + * [aSrc, aSrc+aCount] do not overlap. aCount is given in bytes. + */ + static void assertNoOverlap(const void* aDest, const void* aSrc, + size_t aCount) + { + DebugOnly byteDestPtr = static_cast(aDest); + DebugOnly byteSrcPtr = static_cast(aSrc); + MOZ_ASSERT((byteDestPtr <= byteSrcPtr && + byteDestPtr + aCount <= byteSrcPtr) || + (byteSrcPtr <= byteDestPtr && + byteSrcPtr + aCount <= byteDestPtr)); + } + + template + static void assertAligned(T* aPtr) + { + MOZ_ASSERT((uintptr_t(aPtr) % sizeof(T)) == 0, "Unaligned pointer!"); + } + +protected: + /** + * Return |aValue| converted from SourceEndian encoding to DestEndian + * encoding. + */ + template + static inline T maybeSwap(T aValue) + { + if (SourceEndian == DestEndian) { + return aValue; + } + return Swapper::swap(aValue); + } + + /** + * Convert |aCount| elements at |aPtr| from SourceEndian encoding to + * DestEndian encoding. + */ + template + static inline void maybeSwapInPlace(T* aPtr, size_t aCount) + { + assertAligned(aPtr); + + if (SourceEndian == DestEndian) { + return; + } + for (size_t i = 0; i < aCount; i++) { + aPtr[i] = Swapper::swap(aPtr[i]); + } + } + + /** + * Write |aCount| elements to the unaligned address |aDest| in DestEndian + * format, using elements found at |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapTo(void* aDest, const T* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aSrc); + + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; + } + + uint8_t* byteDestPtr = static_cast(aDest); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + u.mVal = maybeSwap(aSrc[i]); + memcpy(byteDestPtr, u.mBuffer, sizeof(T)); + byteDestPtr += sizeof(T); + } + } + + /** + * Write |aCount| elements to |aDest| in DestEndian format, using elements + * found at the unaligned address |aSrc| in SourceEndian format. + */ + template + static void copyAndSwapFrom(T* aDest, const void* aSrc, size_t aCount) + { + assertNoOverlap(aDest, aSrc, aCount * sizeof(T)); + assertAligned(aDest); + + if (SourceEndian == DestEndian) { + memcpy(aDest, aSrc, aCount * sizeof(T)); + return; + } + + const uint8_t* byteSrcPtr = static_cast(aSrc); + for (size_t i = 0; i < aCount; ++i) { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, byteSrcPtr, sizeof(T)); + aDest[i] = maybeSwap(u.mVal); + byteSrcPtr += sizeof(T); + } + } +}; + +template +class Endian : private EndianUtils +{ +protected: + /** Read a uint16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint16_t readUint16(const void* aPtr) + { + return read(aPtr); + } + + /** Read a uint32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint32_t readUint32(const void* aPtr) + { + return read(aPtr); + } + + /** Read a uint64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT uint64_t readUint64(const void* aPtr) + { + return read(aPtr); + } + + /** Read an int16_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int16_t readInt16(const void* aPtr) + { + return read(aPtr); + } + + /** Read an int32_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int32_t readInt32(const void* aPtr) + { + return read(aPtr); + } + + /** Read an int64_t in ThisEndian endianness from |aPtr| and return it. */ + static MOZ_WARN_UNUSED_RESULT int64_t readInt64(const void* aPtr) + { + return read(aPtr); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint16(void* aPtr, uint16_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint32(void* aPtr, uint32_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeUint64(void* aPtr, uint64_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt16(void* aPtr, int16_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt32(void* aPtr, int32_t aValue) + { + write(aPtr, aValue); + } + + /** Write |aValue| to |aPtr| using ThisEndian endianness. */ + static void writeInt64(void* aPtr, int64_t aValue) + { + write(aPtr, aValue); + } + + /* + * Converts a value of type T to little-endian format. + * + * This function is intended for cases where you have data in your + * native-endian format and you need it to appear in little-endian + * format for transmission. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToLittleEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToLittleEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapToLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T to big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapToBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapToBigEndian(void* aDest, const T* aSrc, + size_t aCount) + { + copyAndSwapTo(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapToBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + + template + MOZ_WARN_UNUSED_RESULT static T swapToNetworkOrder(T aValue) + { + return swapToBigEndian(aValue); + } + + template + static void + copyAndSwapToNetworkOrder(void* aDest, const T* aSrc, size_t aCount) + { + copyAndSwapToBigEndian(aDest, aSrc, aCount); + } + + template + static void + swapToNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapToBigEndianInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from little-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromLittleEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to little-endian format if ThisEndian is Big. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromLittleEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromLittleEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Converts a value of type T from big-endian format. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromBigEndian(T aValue) + { + return maybeSwap(aValue); + } + + /* + * Copies |aCount| values of type T starting at |aSrc| to |aDest|, converting + * them to big-endian format if ThisEndian is Little. + * As with memcpy, |aDest| and |aSrc| must not overlap. + */ + template + static void copyAndSwapFromBigEndian(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFrom(aDest, aSrc, aCount); + } + + /* + * Likewise, but converts values in place. + */ + template + static void swapFromBigEndianInPlace(T* aPtr, size_t aCount) + { + maybeSwapInPlace(aPtr, aCount); + } + + /* + * Synonyms for the big-endian functions, for better readability + * in network code. + */ + template + MOZ_WARN_UNUSED_RESULT static T swapFromNetworkOrder(T aValue) + { + return swapFromBigEndian(aValue); + } + + template + static void copyAndSwapFromNetworkOrder(T* aDest, const void* aSrc, + size_t aCount) + { + copyAndSwapFromBigEndian(aDest, aSrc, aCount); + } + + template + static void swapFromNetworkOrderInPlace(T* aPtr, size_t aCount) + { + swapFromBigEndianInPlace(aPtr, aCount); + } + +private: + /** + * Read a value of type T, encoded in endianness ThisEndian from |aPtr|. + * Return that value encoded in native endianness. + */ + template + static T read(const void* aPtr) + { + union + { + T mVal; + uint8_t mBuffer[sizeof(T)]; + } u; + memcpy(u.mBuffer, aPtr, sizeof(T)); + return maybeSwap(u.mVal); + } + + /** + * Write a value of type T, in native endianness, to |aPtr|, in ThisEndian + * endianness. + */ + template + static void write(void* aPtr, T aValue) + { + T tmp = maybeSwap(aValue); + memcpy(aPtr, &tmp, sizeof(T)); + } + + Endian() MOZ_DELETE; + Endian(const Endian& aTther) MOZ_DELETE; + void operator=(const Endian& aOther) MOZ_DELETE; +}; + +template +class EndianReadWrite : public Endian +{ +private: + typedef Endian super; + +public: + using super::readUint16; + using super::readUint32; + using super::readUint64; + using super::readInt16; + using super::readInt32; + using super::readInt64; + using super::writeUint16; + using super::writeUint32; + using super::writeUint64; + using super::writeInt16; + using super::writeInt32; + using super::writeInt64; +}; + +} /* namespace detail */ + +class LittleEndian MOZ_FINAL : public detail::EndianReadWrite +{}; + +class BigEndian MOZ_FINAL : public detail::EndianReadWrite +{}; + +typedef BigEndian NetworkEndian; + +class NativeEndian MOZ_FINAL : public detail::Endian +{ +private: + typedef detail::Endian super; + +public: + /* + * These functions are intended for cases where you have data in your + * native-endian format and you need the data to appear in the appropriate + * endianness for transmission, serialization, etc. + */ + using super::swapToLittleEndian; + using super::copyAndSwapToLittleEndian; + using super::swapToLittleEndianInPlace; + using super::swapToBigEndian; + using super::copyAndSwapToBigEndian; + using super::swapToBigEndianInPlace; + using super::swapToNetworkOrder; + using super::copyAndSwapToNetworkOrder; + using super::swapToNetworkOrderInPlace; + + /* + * These functions are intended for cases where you have data in the + * given endianness (e.g. reading from disk or a file-format) and you + * need the data to appear in native-endian format for processing. + */ + using super::swapFromLittleEndian; + using super::copyAndSwapFromLittleEndian; + using super::swapFromLittleEndianInPlace; + using super::swapFromBigEndian; + using super::copyAndSwapFromBigEndian; + using super::swapFromBigEndianInPlace; + using super::swapFromNetworkOrder; + using super::copyAndSwapFromNetworkOrder; + using super::swapFromNetworkOrderInPlace; +}; + +#undef MOZ_NATIVE_ENDIANNESS + +} /* namespace mozilla */ + +#endif /* mozilla_Endian_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/EnumSet.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/EnumSet.h new file mode 100644 index 0000000000..8c78b2b442 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/EnumSet.h @@ -0,0 +1,206 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A set abstraction for enumeration values. */ + +#ifndef mozilla_EnumSet_h +#define mozilla_EnumSet_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" + +#include + +namespace mozilla { + +/** + * EnumSet is a set of values defined by an enumeration. It is implemented + * using a 32 bit mask for each value so it will only work for enums with an int + * representation less than 32. It works both for enum and enum class types. + */ +template +class EnumSet +{ +public: + EnumSet() + : mBitField(0) + { } + + MOZ_IMPLICIT EnumSet(T aEnum) + : mBitField(bitFor(aEnum)) + { } + + EnumSet(T aEnum1, T aEnum2) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3)) + { } + + EnumSet(T aEnum1, T aEnum2, T aEnum3, T aEnum4) + : mBitField(bitFor(aEnum1) | + bitFor(aEnum2) | + bitFor(aEnum3) | + bitFor(aEnum4)) + { } + + EnumSet(const EnumSet& aEnumSet) + : mBitField(aEnumSet.mBitField) + { } + + /** + * Add an element + */ + void operator+=(T aEnum) + { + mBitField |= bitFor(aEnum); + } + + /** + * Add an element + */ + EnumSet operator+(T aEnum) const + { + EnumSet result(*this); + result += aEnum; + return result; + } + + /** + * Union + */ + void operator+=(const EnumSet aEnumSet) + { + mBitField |= aEnumSet.mBitField; + } + + /** + * Union + */ + EnumSet operator+(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result += aEnumSet; + return result; + } + + /** + * Remove an element + */ + void operator-=(T aEnum) + { + mBitField &= ~(bitFor(aEnum)); + } + + /** + * Remove an element + */ + EnumSet operator-(T aEnum) const + { + EnumSet result(*this); + result -= aEnum; + return result; + } + + /** + * Remove a set of elements + */ + void operator-=(const EnumSet aEnumSet) + { + mBitField &= ~(aEnumSet.mBitField); + } + + /** + * Remove a set of elements + */ + EnumSet operator-(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result -= aEnumSet; + return result; + } + + /** + * Intersection + */ + void operator&=(const EnumSet aEnumSet) + { + mBitField &= aEnumSet.mBitField; + } + + /** + * Intersection + */ + EnumSet operator&(const EnumSet aEnumSet) const + { + EnumSet result(*this); + result &= aEnumSet; + return result; + } + + /** + * Equality + */ + bool operator==(const EnumSet aEnumSet) const + { + return mBitField == aEnumSet.mBitField; + } + + /** + * Test is an element is contained in the set. + */ + bool contains(T aEnum) const + { + return mBitField & bitFor(aEnum); + } + + /** + * Return the number of elements in the set. + */ + uint8_t size() + { + uint8_t count = 0; + for (uint32_t bitField = mBitField; bitField; bitField >>= 1) { + if (bitField & 1) { + count++; + } + } + return count; + } + + bool isEmpty() const + { + return mBitField == 0; + } + + uint32_t serialize() const + { + return mBitField; + } + + void deserialize(uint32_t aValue) + { + mBitField = aValue; + } + +private: + static uint32_t bitFor(T aEnum) + { + uint32_t bitNumber = (uint32_t)aEnum; + MOZ_ASSERT(bitNumber < 32); + return 1U << bitNumber; + } + + uint32_t mBitField; +}; + +} // namespace mozilla + +#endif /* mozilla_EnumSet_h_*/ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/FloatingPoint.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/FloatingPoint.h new file mode 100644 index 0000000000..0ed567832b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/FloatingPoint.h @@ -0,0 +1,413 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Various predicates and operations on IEEE-754 floating point types. */ + +#ifndef mozilla_FloatingPoint_h +#define mozilla_FloatingPoint_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Casting.h" +#include "mozilla/MathAlgorithms.h" +#include "mozilla/Types.h" + +#include + +namespace mozilla { + +/* + * It's reasonable to ask why we have this header at all. Don't isnan, + * copysign, the built-in comparison operators, and the like solve these + * problems? Unfortunately, they don't. We've found that various compilers + * (MSVC, MSVC when compiling with PGO, and GCC on OS X, at least) miscompile + * the standard methods in various situations, so we can't use them. Some of + * these compilers even have problems compiling seemingly reasonable bitwise + * algorithms! But with some care we've found algorithms that seem to not + * trigger those compiler bugs. + * + * For the aforementioned reasons, be very wary of making changes to any of + * these algorithms. If you must make changes, keep a careful eye out for + * compiler bustage, particularly PGO-specific bustage. + */ + +struct FloatTypeTraits +{ + typedef uint32_t Bits; + + static const unsigned kExponentBias = 127; + static const unsigned kExponentShift = 23; + + static const Bits kSignBit = 0x80000000UL; + static const Bits kExponentBits = 0x7F800000UL; + static const Bits kSignificandBits = 0x007FFFFFUL; +}; + +struct DoubleTypeTraits +{ + typedef uint64_t Bits; + + static const unsigned kExponentBias = 1023; + static const unsigned kExponentShift = 52; + + static const Bits kSignBit = 0x8000000000000000ULL; + static const Bits kExponentBits = 0x7ff0000000000000ULL; + static const Bits kSignificandBits = 0x000fffffffffffffULL; +}; + +template struct SelectTrait; +template<> struct SelectTrait : public FloatTypeTraits {}; +template<> struct SelectTrait : public DoubleTypeTraits {}; + +/* + * This struct contains details regarding the encoding of floating-point + * numbers that can be useful for direct bit manipulation. As of now, the + * template parameter has to be float or double. + * + * The nested typedef |Bits| is the unsigned integral type with the same size + * as T: uint32_t for float and uint64_t for double (static assertions + * double-check these assumptions). + * + * kExponentBias is the offset that is subtracted from the exponent when + * computing the value, i.e. one plus the opposite of the mininum possible + * exponent. + * kExponentShift is the shift that one needs to apply to retrieve the + * exponent component of the value. + * + * kSignBit contains a bits mask. Bit-and-ing with this mask will result in + * obtaining the sign bit. + * kExponentBits contains the mask needed for obtaining the exponent bits and + * kSignificandBits contains the mask needed for obtaining the significand + * bits. + * + * Full details of how floating point number formats are encoded are beyond + * the scope of this comment. For more information, see + * http://en.wikipedia.org/wiki/IEEE_floating_point + * http://en.wikipedia.org/wiki/Floating_point#IEEE_754:_floating_point_in_modern_computers + */ +template +struct FloatingPoint : public SelectTrait +{ + typedef SelectTrait Base; + typedef typename Base::Bits Bits; + + static_assert((Base::kSignBit & Base::kExponentBits) == 0, + "sign bit shouldn't overlap exponent bits"); + static_assert((Base::kSignBit & Base::kSignificandBits) == 0, + "sign bit shouldn't overlap significand bits"); + static_assert((Base::kExponentBits & Base::kSignificandBits) == 0, + "exponent bits shouldn't overlap significand bits"); + + static_assert((Base::kSignBit | Base::kExponentBits | Base::kSignificandBits) == + ~Bits(0), + "all bits accounted for"); + + /* + * These implementations assume float/double are 32/64-bit single/double + * format number types compatible with the IEEE-754 standard. C++ don't + * require this to be the case. But we required this in implementations of + * these algorithms that preceded this header, so we shouldn't break anything + * if we keep doing so. + */ + static_assert(sizeof(T) == sizeof(Bits), "Bits must be same size as T"); +}; + +/** Determines whether a double is NaN. */ +template +static MOZ_ALWAYS_INLINE bool +IsNaN(T aValue) +{ + /* + * A float/double is NaN if all exponent bits are 1 and the significand + * contains at least one non-zero bit. + */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) == Traits::kExponentBits && + (bits & Traits::kSignificandBits) != 0; +} + +/** Determines whether a float/double is +Infinity or -Infinity. */ +template +static MOZ_ALWAYS_INLINE bool +IsInfinite(T aValue) +{ + /* Infinities have all exponent bits set to 1 and an all-0 significand. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & ~Traits::kSignBit) == Traits::kExponentBits; +} + +/** Determines whether a float/double is not NaN or infinite. */ +template +static MOZ_ALWAYS_INLINE bool +IsFinite(T aValue) +{ + /* + * NaN and Infinities are the only non-finite floats/doubles, and both have + * all exponent bits set to 1. + */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kExponentBits) != Traits::kExponentBits; +} + +/** + * Determines whether a float/double is negative. It is an error to call this + * method on a float/double which is NaN. + */ +template +static MOZ_ALWAYS_INLINE bool +IsNegative(T aValue) +{ + MOZ_ASSERT(!IsNaN(aValue), "NaN does not have a sign"); + + /* The sign bit is set if the double is negative. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return (bits & Traits::kSignBit) != 0; +} + +/** Determines whether a float/double represents -0. */ +template +static MOZ_ALWAYS_INLINE bool +IsNegativeZero(T aValue) +{ + /* Only the sign bit is set if the value is -0. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return bits == Traits::kSignBit; +} + +/** + * Returns the exponent portion of the float/double. + * + * Zero is not special-cased, so ExponentComponent(0.0) is + * -int_fast16_t(Traits::kExponentBias). + */ +template +static MOZ_ALWAYS_INLINE int_fast16_t +ExponentComponent(T aValue) +{ + /* + * The exponent component of a float/double is an unsigned number, biased + * from its actual value. Subtract the bias to retrieve the actual exponent. + */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return int_fast16_t((bits & Traits::kExponentBits) >> Traits::kExponentShift) - + int_fast16_t(Traits::kExponentBias); +} + +/** Returns +Infinity. */ +template +static MOZ_ALWAYS_INLINE T +PositiveInfinity() +{ + /* + * Positive infinity has all exponent bits set, sign bit set to 0, and no + * significand. + */ + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kExponentBits); +} + +/** Returns -Infinity. */ +template +static MOZ_ALWAYS_INLINE T +NegativeInfinity() +{ + /* + * Negative infinity has all exponent bits set, sign bit set to 1, and no + * significand. + */ + typedef FloatingPoint Traits; + return BitwiseCast(Traits::kSignBit | Traits::kExponentBits); +} + + +/** Constructs a NaN value with the specified sign bit and significand bits. */ +template +static MOZ_ALWAYS_INLINE T +SpecificNaN(int signbit, typename FloatingPoint::Bits significand) +{ + typedef FloatingPoint Traits; + MOZ_ASSERT(signbit == 0 || signbit == 1); + MOZ_ASSERT((significand & ~Traits::kSignificandBits) == 0); + MOZ_ASSERT(significand & Traits::kSignificandBits); + + T t = BitwiseCast((signbit ? Traits::kSignBit : 0) | + Traits::kExponentBits | + significand); + MOZ_ASSERT(IsNaN(t)); + return t; +} + +/** Computes the smallest non-zero positive float/double value. */ +template +static MOZ_ALWAYS_INLINE T +MinNumberValue() +{ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + return BitwiseCast(Bits(1)); +} + +/** + * If aValue is equal to some int32_t value, set *aInt32 to that value and + * return true; otherwise return false. + * + * Note that negative zero is "equal" to zero here. To test whether a value can + * be losslessly converted to int32_t and back, use NumberIsInt32 instead. + */ +template +static MOZ_ALWAYS_INLINE bool +NumberEqualsInt32(T aValue, int32_t* aInt32) +{ + /* + * XXX Casting a floating-point value that doesn't truncate to int32_t, to + * int32_t, induces undefined behavior. We should definitely fix this + * (bug 744965), but as apparently it "works" in practice, it's not a + * pressing concern now. + */ + return aValue == (*aInt32 = int32_t(aValue)); +} + +/** + * If d can be converted to int32_t and back to an identical double value, + * set *aInt32 to that value and return true; otherwise return false. + * + * The difference between this and NumberEqualsInt32 is that this method returns + * false for negative zero. + */ +template +static MOZ_ALWAYS_INLINE bool +NumberIsInt32(T aValue, int32_t* aInt32) +{ + return !IsNegativeZero(aValue) && NumberEqualsInt32(aValue, aInt32); +} + +/** + * Computes a NaN value. Do not use this method if you depend upon a particular + * NaN value being returned. + */ +template +static MOZ_ALWAYS_INLINE T +UnspecifiedNaN() +{ + /* + * If we can use any quiet NaN, we might as well use the all-ones NaN, + * since it's cheap to materialize on common platforms (such as x64, where + * this value can be represented in a 32-bit signed immediate field, allowing + * it to be stored to memory in a single instruction). + */ + typedef FloatingPoint Traits; + return SpecificNaN(1, Traits::kSignificandBits); +} + +/** + * Compare two doubles for equality, *without* equating -0 to +0, and equating + * any NaN value to any other NaN value. (The normal equality operators equate + * -0 with +0, and they equate NaN to no other value.) + */ +template +static inline bool +NumbersAreIdentical(T aValue1, T aValue2) +{ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + if (IsNaN(aValue1)) { + return IsNaN(aValue2); + } + return BitwiseCast(aValue1) == BitwiseCast(aValue2); +} + +namespace detail { + +template +struct FuzzyEqualsEpsilon; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-5 that is exactly representable in a float. + static float value() { return 1.0f / (1 << 17); } +}; + +template<> +struct FuzzyEqualsEpsilon +{ + // A number near 1e-12 that is exactly representable in a double. + static double value() { return 1.0 / (1LL << 40); } +}; + +} // namespace detail + +/** + * Compare two floating point values for equality, modulo rounding error. That + * is, the two values are considered equal if they are both not NaN and if they + * are less than or equal to aEpsilon apart. The default value of aEpsilon is + * near 1e-5. + * + * For most scenarios you will want to use FuzzyEqualsMultiplicative instead, + * as it is more reasonable over the entire range of floating point numbers. + * This additive version should only be used if you know the range of the + * numbers you are dealing with is bounded and stays around the same order of + * magnitude. + */ +template +static MOZ_ALWAYS_INLINE bool +FuzzyEqualsAdditive(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) +{ + static_assert(IsFloatingPoint::value, "floating point type required"); + return Abs(aValue1 - aValue2) <= aEpsilon; +} + +/** + * Compare two floating point values for equality, allowing for rounding error + * relative to the magnitude of the values. That is, the two values are + * considered equal if they are both not NaN and they are less than or equal to + * some aEpsilon apart, where the aEpsilon is scaled by the smaller of the two + * argument values. + * + * In most cases you will want to use this rather than FuzzyEqualsAdditive, as + * this function effectively masks out differences in the bottom few bits of + * the floating point numbers being compared, regardless of what order of + * magnitude those numbers are at. + */ +template +static MOZ_ALWAYS_INLINE bool +FuzzyEqualsMultiplicative(T aValue1, T aValue2, + T aEpsilon = detail::FuzzyEqualsEpsilon::value()) +{ + static_assert(IsFloatingPoint::value, "floating point type required"); + // can't use std::min because of bug 965340 + T smaller = Abs(aValue1) < Abs(aValue2) ? Abs(aValue1) : Abs(aValue2); + return Abs(aValue1 - aValue2) <= aEpsilon * smaller; +} + +/** + * Returns true if the given value can be losslessly represented as an IEEE-754 + * single format number, false otherwise. All NaN values are considered + * representable (notwithstanding that the exact bit pattern of a double format + * NaN value can't be exactly represented in single format). + * + * This function isn't inlined to avoid buggy optimizations by MSVC. + */ +MOZ_WARN_UNUSED_RESULT +extern MFBT_API bool +IsFloat32Representable(double aFloat32); + +} /* namespace mozilla */ + +#endif /* mozilla_FloatingPoint_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/GuardObjects.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/GuardObjects.h new file mode 100644 index 0000000000..2cd950f314 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/GuardObjects.h @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implementation of macros to ensure correct use of RAII Auto* objects. */ + +#ifndef mozilla_GuardObjects_h +#define mozilla_GuardObjects_h + +#include "mozilla/Assertions.h" +#include "mozilla/NullPtr.h" +#include "mozilla/Types.h" + +#ifdef __cplusplus + +#ifdef DEBUG + +namespace mozilla { +namespace detail { + +/* + * The following classes are designed to cause assertions to detect + * inadvertent use of guard objects as temporaries. In other words, + * when we have a guard object whose only purpose is its constructor and + * destructor (and is never otherwise referenced), the intended use + * might be: + * + * AutoRestore savePainting(mIsPainting); + * + * but is is easy to accidentally write: + * + * AutoRestore(mIsPainting); + * + * which compiles just fine, but runs the destructor well before the + * intended time. + * + * They work by adding (#ifdef DEBUG) an additional parameter to the + * guard object's constructor, with a default value, so that users of + * the guard object's API do not need to do anything. The default value + * of this parameter is a temporary object. C++ (ISO/IEC 14882:1998), + * section 12.2 [class.temporary], clauses 4 and 5 seem to assume a + * guarantee that temporaries are destroyed in the reverse of their + * construction order, but I actually can't find a statement that that + * is true in the general case (beyond the two specific cases mentioned + * there). However, it seems to be true. + * + * These classes are intended to be used only via the macros immediately + * below them: + * + * MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER declares (ifdef DEBUG) a member + * variable, and should be put where a declaration of a private + * member variable would be placed. + * MOZ_GUARD_OBJECT_NOTIFIER_PARAM should be placed at the end of the + * parameters to each constructor of the guard object; it declares + * (ifdef DEBUG) an additional parameter. (But use the *_ONLY_PARAM + * variant for constructors that take no other parameters.) + * MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL should likewise be used in + * the implementation of such constructors when they are not inline. + * MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT should be used in + * the implementation of such constructors to pass the parameter to + * a base class that also uses these macros + * MOZ_GUARD_OBJECT_NOTIFIER_INIT is a statement that belongs in each + * constructor. It uses the parameter declared by + * MOZ_GUARD_OBJECT_NOTIFIER_PARAM. + * + * For more details, and examples of using these macros, see + * https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla + */ +class GuardObjectNotifier +{ +private: + bool* mStatementDone; + +public: + GuardObjectNotifier() : mStatementDone(nullptr) { } + + ~GuardObjectNotifier() { *mStatementDone = true; } + + void setStatementDone(bool* aStatementIsDone) + { + mStatementDone = aStatementIsDone; + } +}; + +class GuardObjectNotificationReceiver +{ +private: + bool mStatementDone; + +public: + GuardObjectNotificationReceiver() : mStatementDone(false) { } + + ~GuardObjectNotificationReceiver() { + /* + * Assert that the guard object was not used as a temporary. (Note that + * this assert might also fire if init is not called because the guard + * object's implementation is not using the above macros correctly.) + */ + MOZ_ASSERT(mStatementDone); + } + + void init(const GuardObjectNotifier& aConstNotifier) + { + /* + * aConstNotifier is passed as a const reference so that we can pass a + * temporary, but we really intend it as non-const. + */ + GuardObjectNotifier& notifier = + const_cast(aConstNotifier); + notifier.setStatementDone(&mStatementDone); + } +}; + +} /* namespace detail */ +} /* namespace mozilla */ + +#endif /* DEBUG */ + +#ifdef DEBUG +# define MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER \ + mozilla::detail::GuardObjectNotificationReceiver _mCheckNotUsedAsTemporary; +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM \ + , const mozilla::detail::GuardObjectNotifier& _notifier = \ + mozilla::detail::GuardObjectNotifier() +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM \ + const mozilla::detail::GuardObjectNotifier& _notifier = \ + mozilla::detail::GuardObjectNotifier() +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL \ + , const mozilla::detail::GuardObjectNotifier& _notifier +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL \ + const mozilla::detail::GuardObjectNotifier& _notifier +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT \ + , _notifier +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT \ + _notifier +# define MOZ_GUARD_OBJECT_NOTIFIER_INIT \ + do { _mCheckNotUsedAsTemporary.init(_notifier); } while (0) +#else +# define MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL +# define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT +# define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT +# define MOZ_GUARD_OBJECT_NOTIFIER_INIT do { } while (0) +#endif + +#endif /* __cplusplus */ + +#endif /* mozilla_GuardObjects_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/HashFunctions.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/HashFunctions.h new file mode 100644 index 0000000000..8b2c172bd1 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/HashFunctions.h @@ -0,0 +1,367 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Utilities for hashing. */ + +/* + * This file exports functions for hashing data down to a 32-bit value, + * including: + * + * - HashString Hash a char* or uint16_t/wchar_t* of known or unknown + * length. + * + * - HashBytes Hash a byte array of known length. + * + * - HashGeneric Hash one or more values. Currently, we support uint32_t, + * types which can be implicitly cast to uint32_t, data + * pointers, and function pointers. + * + * - AddToHash Add one or more values to the given hash. This supports the + * same list of types as HashGeneric. + * + * + * You can chain these functions together to hash complex objects. For example: + * + * class ComplexObject + * { + * char* mStr; + * uint32_t mUint1, mUint2; + * void (*mCallbackFn)(); + * + * public: + * uint32_t hash() + * { + * uint32_t hash = HashString(mStr); + * hash = AddToHash(hash, mUint1, mUint2); + * return AddToHash(hash, mCallbackFn); + * } + * }; + * + * If you want to hash an nsAString or nsACString, use the HashString functions + * in nsHashKeys.h. + */ + +#ifndef mozilla_HashFunctions_h +#define mozilla_HashFunctions_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Char16.h" +#include "mozilla/Types.h" + +#include + +#ifdef __cplusplus +namespace mozilla { + +/** + * The golden ratio as a 32-bit fixed-point value. + */ +static const uint32_t kGoldenRatioU32 = 0x9E3779B9U; + +inline uint32_t +RotateBitsLeft32(uint32_t aValue, uint8_t aBits) +{ + MOZ_ASSERT(aBits < 32); + return (aValue << aBits) | (aValue >> (32 - aBits)); +} + +namespace detail { + +inline uint32_t +AddU32ToHash(uint32_t aHash, uint32_t aValue) +{ + /* + * This is the meat of all our hash routines. This hash function is not + * particularly sophisticated, but it seems to work well for our mostly + * plain-text inputs. Implementation notes follow. + * + * Our use of the golden ratio here is arbitrary; we could pick almost any + * number which: + * + * * is odd (because otherwise, all our hash values will be even) + * + * * has a reasonably-even mix of 1's and 0's (consider the extreme case + * where we multiply by 0x3 or 0xeffffff -- this will not produce good + * mixing across all bits of the hash). + * + * The rotation length of 5 is also arbitrary, although an odd number is again + * preferable so our hash explores the whole universe of possible rotations. + * + * Finally, we multiply by the golden ratio *after* xor'ing, not before. + * Otherwise, if |aHash| is 0 (as it often is for the beginning of a + * message), the expression + * + * (kGoldenRatioU32 * RotateBitsLeft(aHash, 5)) |xor| aValue + * + * evaluates to |aValue|. + * + * (Number-theoretic aside: Because any odd number |m| is relatively prime to + * our modulus (2^32), the list + * + * [x * m (mod 2^32) for 0 <= x < 2^32] + * + * has no duplicate elements. This means that multiplying by |m| does not + * cause us to skip any possible hash values. + * + * It's also nice if |m| has large-ish order mod 2^32 -- that is, if the + * smallest k such that m^k == 1 (mod 2^32) is large -- so we can safely + * multiply our hash value by |m| a few times without negating the + * multiplicative effect. Our golden ratio constant has order 2^29, which is + * more than enough for our purposes.) + */ + return kGoldenRatioU32 * (RotateBitsLeft32(aHash, 5) ^ aValue); +} + +/** + * AddUintptrToHash takes sizeof(uintptr_t) as a template parameter. + */ +template +inline uint32_t +AddUintptrToHash(uint32_t aHash, uintptr_t aValue); + +template<> +inline uint32_t +AddUintptrToHash<4>(uint32_t aHash, uintptr_t aValue) +{ + return AddU32ToHash(aHash, static_cast(aValue)); +} + +template<> +inline uint32_t +AddUintptrToHash<8>(uint32_t aHash, uintptr_t aValue) +{ + /* + * The static cast to uint64_t below is necessary because this function + * sometimes gets compiled on 32-bit platforms (yes, even though it's a + * template and we never call this particular override in a 32-bit build). If + * we do aValue >> 32 on a 32-bit machine, we're shifting a 32-bit uintptr_t + * right 32 bits, and the compiler throws an error. + */ + uint32_t v1 = static_cast(aValue); + uint32_t v2 = static_cast(static_cast(aValue) >> 32); + return AddU32ToHash(AddU32ToHash(aHash, v1), v2); +} + +} /* namespace detail */ + +/** + * AddToHash takes a hash and some values and returns a new hash based on the + * inputs. + * + * Currently, we support hashing uint32_t's, values which we can implicitly + * convert to uint32_t, data pointers, and function pointers. + */ +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A aA) +{ + /* + * Try to convert |A| to uint32_t implicitly. If this works, great. If not, + * we'll error out. + */ + return detail::AddU32ToHash(aHash, aA); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, A* aA) +{ + /* + * You might think this function should just take a void*. But then we'd only + * catch data pointers and couldn't handle function pointers. + */ + + static_assert(sizeof(aA) == sizeof(uintptr_t), "Strange pointer!"); + + return detail::AddUintptrToHash(aHash, uintptr_t(aA)); +} + +template<> +MOZ_WARN_UNUSED_RESULT inline uint32_t +AddToHash(uint32_t aHash, uintptr_t aA) +{ + return detail::AddUintptrToHash(aHash, aA); +} + +template +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB) +{ + return AddToHash(AddToHash(aHash, aA), aB); +} + +template +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC) +{ + return AddToHash(AddToHash(aHash, aA, aB), aC); +} + +template +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD) +{ + return AddToHash(AddToHash(aHash, aA, aB, aC), aD); +} + +template +MOZ_WARN_UNUSED_RESULT uint32_t +AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD, E aE) +{ + return AddToHash(AddToHash(aHash, aA, aB, aC, aD), aE); +} + +/** + * The HashGeneric class of functions let you hash one or more values. + * + * If you want to hash together two values x and y, calling HashGeneric(x, y) is + * much better than calling AddToHash(x, y), because AddToHash(x, y) assumes + * that x has already been hashed. + */ +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA) +{ + return AddToHash(0, aA); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB) +{ + return AddToHash(0, aA, aB); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC) +{ + return AddToHash(0, aA, aB, aC); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD) +{ + return AddToHash(0, aA, aB, aC, aD); +} + +template +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashGeneric(A aA, B aB, C aC, D aD, E aE) +{ + return AddToHash(0, aA, aB, aC, aD, aE); +} + +namespace detail { + +template +uint32_t +HashUntilZero(const T* aStr) +{ + uint32_t hash = 0; + for (T c; (c = *aStr); aStr++) { + hash = AddToHash(hash, c); + } + return hash; +} + +template +uint32_t +HashKnownLength(const T* aStr, size_t aLength) +{ + uint32_t hash = 0; + for (size_t i = 0; i < aLength; i++) { + hash = AddToHash(hash, aStr[i]); + } + return hash; +} + +} /* namespace detail */ + +/** + * The HashString overloads below do just what you'd expect. + * + * If you have the string's length, you might as well call the overload which + * includes the length. It may be marginally faster. + */ +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr) +{ + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} + +MOZ_WARN_UNUSED_RESULT +inline uint32_t +HashString(const unsigned char* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr) +{ + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const uint16_t* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} + +#ifdef MOZ_CHAR16_IS_NOT_WCHAR +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr) +{ + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const char16_t* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} +#endif + +/* + * On Windows, wchar_t (char16_t) is not the same as uint16_t, even though it's + * the same width! + */ +#ifdef WIN32 +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr) +{ + return detail::HashUntilZero(aStr); +} + +MOZ_WARN_UNUSED_RESULT inline uint32_t +HashString(const wchar_t* aStr, size_t aLength) +{ + return detail::HashKnownLength(aStr, aLength); +} +#endif + +/** + * Hash some number of bytes. + * + * This hash walks word-by-word, rather than byte-by-byte, so you won't get the + * same result out of HashBytes as you would out of HashString. + */ +MOZ_WARN_UNUSED_RESULT extern MFBT_API uint32_t +HashBytes(const void* bytes, size_t aLength); + +} /* namespace mozilla */ +#endif /* __cplusplus */ + +#endif /* mozilla_HashFunctions_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/IntegerPrintfMacros.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/IntegerPrintfMacros.h new file mode 100644 index 0000000000..ff2415a86f --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/IntegerPrintfMacros.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Implements the C99 interface, minus the SCN* format macros. */ + +#ifndef mozilla_IntegerPrintfMacros_h_ +#define mozilla_IntegerPrintfMacros_h_ + +/* + * MSVC++ doesn't include , even in versions shipping , so + * we have to reimplement it there. Note: #includes . + * + * Note that this header DOES NOT implement 's scanf macros. MSVC's + * scanf doesn't have sufficient format specifier support to implement them + * (specifically, to implement scanning into an 8-bit location). + * + * http://stackoverflow.com/questions/3036396/scanfd-char-char-as-int-format-string + * + * Moreover, scanf is a footgun: if the input number exceeds the bounds of the + * target type, behavior is undefined (in the compiler sense: that is, this code + * could overwrite your hard drive with zeroes): + * + * uint8_t u; + * sscanf("256", "%" SCNu8, &u); // BAD + * + * This header will sometimes provide SCN* macros, by dint of being implemented + * using . But for these reasons, *never* use them! + */ + +#if defined(MOZ_CUSTOM_INTTYPES_H) +# include MOZ_CUSTOM_INTTYPES_H +#elif defined(_MSC_VER) +# include "mozilla/MSIntTypes.h" +#else +# include +#endif + +/* + * Fix up Android's broken [u]intptr_t inttype macros. Android's PRI*PTR + * macros are defined as "ld", but sizeof(long) is 8 and sizeof(intptr_t) + * is 4 on 32-bit Android. TestTypeTraits.cpp asserts that these new macro + * definitions match the actual type sizes seen at compile time. + */ +#if defined(ANDROID) && !defined(__LP64__) +# undef PRIdPTR /* intptr_t */ +# define PRIdPTR "d" /* intptr_t */ +# undef PRIiPTR /* intptr_t */ +# define PRIiPTR "i" /* intptr_t */ +# undef PRIoPTR /* uintptr_t */ +# define PRIoPTR "o" /* uintptr_t */ +# undef PRIuPTR /* uintptr_t */ +# define PRIuPTR "u" /* uintptr_t */ +# undef PRIxPTR /* uintptr_t */ +# define PRIxPTR "x" /* uintptr_t */ +# undef PRIXPTR /* uintptr_t */ +# define PRIXPTR "X" /* uintptr_t */ +#endif + +#endif /* mozilla_IntegerPrintfMacros_h_ */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Likely.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Likely.h new file mode 100644 index 0000000000..4f21609295 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Likely.h @@ -0,0 +1,23 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * MOZ_LIKELY and MOZ_UNLIKELY macros to hint to the compiler how a + * boolean predicate should be branch-predicted. + */ + +#ifndef mozilla_Likely_h +#define mozilla_Likely_h + +#if defined(__clang__) || defined(__GNUC__) +# define MOZ_LIKELY(x) (__builtin_expect(!!(x), 1)) +# define MOZ_UNLIKELY(x) (__builtin_expect(!!(x), 0)) +#else +# define MOZ_LIKELY(x) (!!(x)) +# define MOZ_UNLIKELY(x) (!!(x)) +#endif + +#endif /* mozilla_Likely_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/LinkedList.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/LinkedList.h new file mode 100644 index 0000000000..693c019f92 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/LinkedList.h @@ -0,0 +1,486 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A type-safe doubly-linked list class. */ + +/* + * The classes LinkedList and LinkedListElement together form a + * convenient, type-safe doubly-linked list implementation. + * + * The class T which will be inserted into the linked list must inherit from + * LinkedListElement. A given object may be in only one linked list at a + * time. + * + * A LinkedListElement automatically removes itself from the list upon + * destruction, and a LinkedList will fatally assert in debug builds if it's + * non-empty when it's destructed. + * + * For example, you might use LinkedList in a simple observer list class as + * follows. + * + * class Observer : public LinkedListElement + * { + * public: + * void observe(char* aTopic) { ... } + * }; + * + * class ObserverContainer + * { + * private: + * LinkedList list; + * + * public: + * void addObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is part of another list. + * list.insertBack(aObserver); + * } + * + * void removeObserver(Observer* aObserver) + * { + * // Will assert if |aObserver| is not part of some list. + * aObserver.remove(); + * // Or, will assert if |aObserver| is not part of |list| specifically. + * // aObserver.removeFrom(list); + * } + * + * void notifyObservers(char* aTopic) + * { + * for (Observer* o = list.getFirst(); o != nullptr; o = o->getNext()) { + * o->observe(aTopic); + * } + * } + * }; + * + */ + +#ifndef mozilla_LinkedList_h +#define mozilla_LinkedList_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" + +#ifdef __cplusplus + +namespace mozilla { + +template +class LinkedList; + +template +class LinkedListElement +{ + /* + * It's convenient that we return nullptr when getNext() or getPrevious() + * hits the end of the list, but doing so costs an extra word of storage in + * each linked list node (to keep track of whether |this| is the sentinel + * node) and a branch on this value in getNext/getPrevious. + * + * We could get rid of the extra word of storage by shoving the "is + * sentinel" bit into one of the pointers, although this would, of course, + * have performance implications of its own. + * + * But the goal here isn't to win an award for the fastest or slimmest + * linked list; rather, we want a *convenient* linked list. So we won't + * waste time guessing which micro-optimization strategy is best. + * + * + * Speaking of unnecessary work, it's worth addressing here why we wrote + * mozilla::LinkedList in the first place, instead of using stl::list. + * + * The key difference between mozilla::LinkedList and stl::list is that + * mozilla::LinkedList stores the mPrev/mNext pointers in the object itself, + * while stl::list stores the mPrev/mNext pointers in a list element which + * itself points to the object being stored. + * + * mozilla::LinkedList's approach makes it harder to store an object in more + * than one list. But the upside is that you can call next() / prev() / + * remove() directly on the object. With stl::list, you'd need to store a + * pointer to its iterator in the object in order to accomplish this. Not + * only would this waste space, but you'd have to remember to update that + * pointer every time you added or removed the object from a list. + * + * In-place, constant-time removal is a killer feature of doubly-linked + * lists, and supporting this painlessly was a key design criterion. + */ + +private: + LinkedListElement* mNext; + LinkedListElement* mPrev; + const bool mIsSentinel; + +public: + LinkedListElement() + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(false) + { } + + LinkedListElement(LinkedListElement&& other) + : mIsSentinel(other.mIsSentinel) + { + if (!other.isInList()) { + mNext = this; + mPrev = this; + return; + } + + MOZ_ASSERT(other.mNext->mPrev == &other); + MOZ_ASSERT(other.mPrev->mNext == &other); + + /* + * Initialize |this| with |other|'s mPrev/mNext pointers, and adjust those + * element to point to this one. + */ + mNext = other.mNext; + mPrev = other.mPrev; + + mNext->mPrev = this; + mPrev->mNext = this; + + /* + * Adjust |other| so it doesn't think it's in a list. This makes it + * safely destructable. + */ + other.mNext = &other; + other.mPrev = &other; + } + + ~LinkedListElement() + { + if (!mIsSentinel && isInList()) { + remove(); + } + } + + /* + * Get the next element in the list, or nullptr if this is the last element + * in the list. + */ + T* getNext() { return mNext->asT(); } + const T* getNext() const { return mNext->asT(); } + + /* + * Get the previous element in the list, or nullptr if this is the first + * element in the list. + */ + T* getPrevious() { return mPrev->asT(); } + const T* getPrevious() const { return mPrev->asT(); } + + /* + * Insert aElem after this element in the list. |this| must be part of a + * linked list when you call setNext(); otherwise, this method will assert. + */ + void setNext(T* aElem) + { + MOZ_ASSERT(isInList()); + setNextUnsafe(aElem); + } + + /* + * Insert aElem before this element in the list. |this| must be part of a + * linked list when you call setPrevious(); otherwise, this method will + * assert. + */ + void setPrevious(T* aElem) + { + MOZ_ASSERT(isInList()); + setPreviousUnsafe(aElem); + } + + /* + * Remove this element from the list which contains it. If this element is + * not currently part of a linked list, this method asserts. + */ + void remove() + { + MOZ_ASSERT(isInList()); + + mPrev->mNext = mNext; + mNext->mPrev = mPrev; + mNext = this; + mPrev = this; + } + + /* + * Identical to remove(), but also asserts in debug builds that this element + * is in aList. + */ + void removeFrom(const LinkedList& aList) + { + aList.assertContains(asT()); + remove(); + } + + /* + * Return true if |this| part is of a linked list, and false otherwise. + */ + bool isInList() const + { + MOZ_ASSERT((mNext == this) == (mPrev == this)); + return mNext != this; + } + +private: + friend class LinkedList; + + enum NodeKind { + NODE_KIND_NORMAL, + NODE_KIND_SENTINEL + }; + + explicit LinkedListElement(NodeKind nodeKind) + : mNext(MOZ_THIS_IN_INITIALIZER_LIST()), + mPrev(MOZ_THIS_IN_INITIALIZER_LIST()), + mIsSentinel(nodeKind == NODE_KIND_SENTINEL) + { } + + /* + * Return |this| cast to T* if we're a normal node, or return nullptr if + * we're a sentinel node. + */ + T* asT() + { + return mIsSentinel ? nullptr : static_cast(this); + } + const T* asT() const + { + return mIsSentinel ? nullptr : static_cast(this); + } + + /* + * Insert aElem after this element, but don't check that this element is in + * the list. This is called by LinkedList::insertFront(). + */ + void setNextUnsafe(T* aElem) + { + LinkedListElement *listElem = static_cast(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this->mNext; + listElem->mPrev = this; + this->mNext->mPrev = listElem; + this->mNext = listElem; + } + + /* + * Insert aElem before this element, but don't check that this element is in + * the list. This is called by LinkedList::insertBack(). + */ + void setPreviousUnsafe(T* aElem) + { + LinkedListElement* listElem = static_cast*>(aElem); + MOZ_ASSERT(!listElem->isInList()); + + listElem->mNext = this; + listElem->mPrev = this->mPrev; + this->mPrev->mNext = listElem; + this->mPrev = listElem; + } + +private: + LinkedListElement& operator=(const LinkedListElement& aOther) MOZ_DELETE; + LinkedListElement(const LinkedListElement& aOther) MOZ_DELETE; +}; + +template +class LinkedList +{ +private: + LinkedListElement sentinel; + +public: + LinkedList() : sentinel(LinkedListElement::NODE_KIND_SENTINEL) { } + + LinkedList(LinkedList&& aOther) + : sentinel(mozilla::Move(aOther.sentinel)) + { } + + ~LinkedList() { MOZ_ASSERT(isEmpty()); } + + /* + * Add aElem to the front of the list. + */ + void insertFront(T* aElem) + { + /* Bypass setNext()'s this->isInList() assertion. */ + sentinel.setNextUnsafe(aElem); + } + + /* + * Add aElem to the back of the list. + */ + void insertBack(T* aElem) + { + sentinel.setPreviousUnsafe(aElem); + } + + /* + * Get the first element of the list, or nullptr if the list is empty. + */ + T* getFirst() { return sentinel.getNext(); } + const T* getFirst() const { return sentinel.getNext(); } + + /* + * Get the last element of the list, or nullptr if the list is empty. + */ + T* getLast() { return sentinel.getPrevious(); } + const T* getLast() const { return sentinel.getPrevious(); } + + /* + * Get and remove the first element of the list. If the list is empty, + * return nullptr. + */ + T* popFirst() + { + T* ret = sentinel.getNext(); + if (ret) { + static_cast*>(ret)->remove(); + } + return ret; + } + + /* + * Get and remove the last element of the list. If the list is empty, + * return nullptr. + */ + T* popLast() + { + T* ret = sentinel.getPrevious(); + if (ret) { + static_cast*>(ret)->remove(); + } + return ret; + } + + /* + * Return true if the list is empty, or false otherwise. + */ + bool isEmpty() const + { + return !sentinel.isInList(); + } + + /* + * Remove all the elements from the list. + * + * This runs in time linear to the list's length, because we have to mark + * each element as not in the list. + */ + void clear() + { + while (popFirst()) { + continue; + } + } + + /* + * Measures the memory consumption of the list excluding |this|. Note that + * it only measures the list elements themselves. If the list elements + * contain pointers to other memory blocks, those blocks must be measured + * separately during a subsequent iteration over the list. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const + { + size_t n = 0; + for (const T* t = getFirst(); t; t = t->getNext()) { + n += aMallocSizeOf(t); + } + return n; + } + + /* + * Like sizeOfExcludingThis(), but measures |this| as well. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const + { + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); + } + + /* + * In a debug build, make sure that the list is sane (no cycles, consistent + * mNext/mPrev pointers, only one sentinel). Has no effect in release builds. + */ + void debugAssertIsSane() const + { +#ifdef DEBUG + const LinkedListElement* slow; + const LinkedListElement* fast1; + const LinkedListElement* fast2; + + /* + * Check for cycles in the forward singly-linked list using the + * tortoise/hare algorithm. + */ + for (slow = sentinel.mNext, + fast1 = sentinel.mNext->mNext, + fast2 = sentinel.mNext->mNext->mNext; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mNext, fast1 = fast2->mNext, fast2 = fast1->mNext) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); + } + + /* Check for cycles in the backward singly-linked list. */ + for (slow = sentinel.mPrev, + fast1 = sentinel.mPrev->mPrev, + fast2 = sentinel.mPrev->mPrev->mPrev; + slow != &sentinel && fast1 != &sentinel && fast2 != &sentinel; + slow = slow->mPrev, fast1 = fast2->mPrev, fast2 = fast1->mPrev) { + MOZ_ASSERT(slow != fast1); + MOZ_ASSERT(slow != fast2); + } + + /* + * Check that |sentinel| is the only node in the list with + * mIsSentinel == true. + */ + for (const LinkedListElement* elem = sentinel.mNext; + elem != &sentinel; + elem = elem->mNext) { + MOZ_ASSERT(!elem->mIsSentinel); + } + + /* Check that the mNext/mPrev pointers match up. */ + const LinkedListElement* prev = &sentinel; + const LinkedListElement* cur = sentinel.mNext; + do { + MOZ_ASSERT(cur->mPrev == prev); + MOZ_ASSERT(prev->mNext == cur); + + prev = cur; + cur = cur->mNext; + } while (cur != &sentinel); +#endif /* ifdef DEBUG */ + } + +private: + friend class LinkedListElement; + + void assertContains(const T* aValue) const + { +#ifdef DEBUG + for (const T* elem = getFirst(); elem; elem = elem->getNext()) { + if (elem == aValue) { + return; + } + } + MOZ_CRASH("element wasn't found in this list!"); +#endif + } + + LinkedList& operator=(const LinkedList& aOther) MOZ_DELETE; + LinkedList(const LinkedList& aOther) MOZ_DELETE; +}; + +} /* namespace mozilla */ + +#endif /* __cplusplus */ + +#endif /* mozilla_LinkedList_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MSIntTypes.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MSIntTypes.h new file mode 100644 index 0000000000..4ce922fbc5 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MSIntTypes.h @@ -0,0 +1,198 @@ +// ISO C9x compliant inttypes.h for Microsoft Visual Studio +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// +// Copyright (c) 2006 Alexander Chemeris +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. The name of the author may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _MSC_VER // [ +#error "Use this header only with Microsoft Visual C++ compilers!" +#endif // _MSC_VER ] + +#ifndef _MSC_INTTYPES_H_ // [ +#define _MSC_INTTYPES_H_ + +#if _MSC_VER > 1000 +#pragma once +#endif + +#include + +// 7.8 Format conversion of integer types + +typedef struct { + intmax_t quot; + intmax_t rem; +} imaxdiv_t; + +// 7.8.1 Macros for format specifiers + +#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 + +// The fprintf macros for signed integers are: +#define PRId8 "d" +#define PRIi8 "i" +#define PRIdLEAST8 "d" +#define PRIiLEAST8 "i" +#define PRIdFAST8 "d" +#define PRIiFAST8 "i" + +#define PRId16 "hd" +#define PRIi16 "hi" +#define PRIdLEAST16 "hd" +#define PRIiLEAST16 "hi" +#define PRIdFAST16 "hd" +#define PRIiFAST16 "hi" + +#define PRId32 "I32d" +#define PRIi32 "I32i" +#define PRIdLEAST32 "I32d" +#define PRIiLEAST32 "I32i" +#define PRIdFAST32 "I32d" +#define PRIiFAST32 "I32i" + +#define PRId64 "I64d" +#define PRIi64 "I64i" +#define PRIdLEAST64 "I64d" +#define PRIiLEAST64 "I64i" +#define PRIdFAST64 "I64d" +#define PRIiFAST64 "I64i" + +#define PRIdMAX "I64d" +#define PRIiMAX "I64i" + +#define PRIdPTR "Id" +#define PRIiPTR "Ii" + +// The fprintf macros for unsigned integers are: +#define PRIo8 "o" +#define PRIu8 "u" +#define PRIx8 "x" +#define PRIX8 "X" +#define PRIoLEAST8 "o" +#define PRIuLEAST8 "u" +#define PRIxLEAST8 "x" +#define PRIXLEAST8 "X" +#define PRIoFAST8 "o" +#define PRIuFAST8 "u" +#define PRIxFAST8 "x" +#define PRIXFAST8 "X" + +#define PRIo16 "ho" +#define PRIu16 "hu" +#define PRIx16 "hx" +#define PRIX16 "hX" +#define PRIoLEAST16 "ho" +#define PRIuLEAST16 "hu" +#define PRIxLEAST16 "hx" +#define PRIXLEAST16 "hX" +#define PRIoFAST16 "ho" +#define PRIuFAST16 "hu" +#define PRIxFAST16 "hx" +#define PRIXFAST16 "hX" + +#define PRIo32 "I32o" +#define PRIu32 "I32u" +#define PRIx32 "I32x" +#define PRIX32 "I32X" +#define PRIoLEAST32 "I32o" +#define PRIuLEAST32 "I32u" +#define PRIxLEAST32 "I32x" +#define PRIXLEAST32 "I32X" +#define PRIoFAST32 "I32o" +#define PRIuFAST32 "I32u" +#define PRIxFAST32 "I32x" +#define PRIXFAST32 "I32X" + +#define PRIo64 "I64o" +#define PRIu64 "I64u" +#define PRIx64 "I64x" +#define PRIX64 "I64X" +#define PRIoLEAST64 "I64o" +#define PRIuLEAST64 "I64u" +#define PRIxLEAST64 "I64x" +#define PRIXLEAST64 "I64X" +#define PRIoFAST64 "I64o" +#define PRIuFAST64 "I64u" +#define PRIxFAST64 "I64x" +#define PRIXFAST64 "I64X" + +#define PRIoMAX "I64o" +#define PRIuMAX "I64u" +#define PRIxMAX "I64x" +#define PRIXMAX "I64X" + +#define PRIoPTR "Io" +#define PRIuPTR "Iu" +#define PRIxPTR "Ix" +#define PRIXPTR "IX" + +// DO NOT SUPPORT THE scanf MACROS! See the comment at the top of +// IntegerPrintfMacros.h. + +#endif // __STDC_FORMAT_MACROS ] + +// 7.8.2 Functions for greatest-width integer types + +// 7.8.2.1 The imaxabs function +#define imaxabs _abs64 + +// 7.8.2.2 The imaxdiv function + +// This is modified version of div() function from Microsoft's div.c found +// in %MSVC.NET%\crt\src\div.c +#ifdef STATIC_IMAXDIV // [ +static +#else // STATIC_IMAXDIV ][ +_inline +#endif // STATIC_IMAXDIV ] +imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) +{ + imaxdiv_t result; + + result.quot = numer / denom; + result.rem = numer % denom; + + if (numer < 0 && result.rem > 0) { + // did division wrong; must fix up + ++result.quot; + result.rem -= denom; + } + + return result; +} + +// 7.8.2.3 The strtoimax and strtoumax functions +#define strtoimax _strtoi64 +#define strtoumax _strtoui64 + +// 7.8.2.4 The wcstoimax and wcstoumax functions +#define wcstoimax _wcstoi64 +#define wcstoumax _wcstoui64 + + +#endif // _MSC_INTTYPES_H_ ] diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MacroArgs.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MacroArgs.h new file mode 100644 index 0000000000..c8b7338210 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MacroArgs.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements various macros meant to ease the use of variadic macros. + */ + +#ifndef mozilla_MacroArgs_h +#define mozilla_MacroArgs_h + +/* + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) counts the number of variadic + * arguments and prefixes it with |aPrefix|. For example: + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(, foo, 42) expands to 2 + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(A, foo, 42, bar) expands to A3 + * + * You must pass in between 1 and 50 (inclusive) variadic arguments, past + * |aPrefix|. It is not legal to do + * + * MOZ_PASTE_PREFIX_AND_ARG_COUNT(prefix) + * + * (that is, pass in 0 variadic arguments). To ensure that a compile-time + * error occurs when these constraints are violated, use the + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT macro with the same variaidc arguments + * wherever this macro is used. + * + * Passing (__VA_ARGS__, ) rather than simply calling + * MOZ_MACROARGS_ARG_COUNT_HELPER2(__VA_ARGS__, ) very + * carefully tiptoes around a MSVC bug where it improperly expands __VA_ARGS__ + * as a single token in argument lists. For details, see: + * + * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement + * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 + */ +#define MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) \ + MOZ_MACROARGS_ARG_COUNT_HELPER((__VA_ARGS__, \ + aPrefix##50, aPrefix##49, aPrefix##48, aPrefix##47, aPrefix##46, \ + aPrefix##45, aPrefix##44, aPrefix##43, aPrefix##42, aPrefix##41, \ + aPrefix##40, aPrefix##39, aPrefix##38, aPrefix##37, aPrefix##36, \ + aPrefix##35, aPrefix##34, aPrefix##33, aPrefix##32, aPrefix##31, \ + aPrefix##30, aPrefix##29, aPrefix##28, aPrefix##27, aPrefix##26, \ + aPrefix##25, aPrefix##24, aPrefix##23, aPrefix##22, aPrefix##21, \ + aPrefix##20, aPrefix##19, aPrefix##18, aPrefix##17, aPrefix##16, \ + aPrefix##15, aPrefix##14, aPrefix##13, aPrefix##12, aPrefix##11, \ + aPrefix##10, aPrefix##9, aPrefix##8, aPrefix##7, aPrefix##6, \ + aPrefix##5, aPrefix##4, aPrefix##3, aPrefix##2, aPrefix##1, aPrefix##0)) + +#define MOZ_MACROARGS_ARG_COUNT_HELPER(aArgs) \ + MOZ_MACROARGS_ARG_COUNT_HELPER2 aArgs + +#define MOZ_MACROARGS_ARG_COUNT_HELPER2( \ + a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, \ + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \ + a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \ + a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \ + a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \ + a51, ...) a51 + +/* + * MOZ_STATIC_ASSERT_VALID_ARG_COUNT ensures that a compile-time error occurs + * when the argument count constraints of MOZ_PASTE_PREFIX_AND_ARG_COUNT are + * violated. Use this macro wherever MOZ_PASTE_PREFIX_AND_ARG_COUNT is used + * and pass it the same variadic arguments. + * + * This macro employs a few dirty tricks to function. To detect the zero + * argument case, |(__VA_ARGS__)| is stringified, sizeof-ed, and compared to + * what it should be in the absence of arguments. + * + * Detecting too many arguments is a little trickier. With a valid argument + * count and a prefix of 1, MOZ_PASTE_PREFIX_AND_ARG_COUNT expands to e.g. 14. + * With a prefix of 0.0, it expands to e.g. 0.04. If there are too many + * arguments, it expands to the first argument over the limit. If this + * exceeding argument is a number, the assertion will fail as there is no + * number than can simultaneously be both > 10 and == 0. If the exceeding + * argument is not a number, a compile-time error should still occur due to + * the operations performed on it. + */ +#define MOZ_MACROARGS_STRINGIFY_HELPER(x) #x +#define MOZ_STATIC_ASSERT_VALID_ARG_COUNT(...) \ + static_assert( \ + sizeof(MOZ_MACROARGS_STRINGIFY_HELPER((__VA_ARGS__))) != sizeof("()") && \ + (MOZ_PASTE_PREFIX_AND_ARG_COUNT(1, __VA_ARGS__)) > 10 && \ + (int)(MOZ_PASTE_PREFIX_AND_ARG_COUNT(0.0, __VA_ARGS__)) == 0, \ + "MOZ_STATIC_ASSERT_VALID_ARG_COUNT requires 1 to 50 arguments") /* ; */ + +/* + * MOZ_ARGS_AFTER_N expands to its arguments excluding the first |N| + * arguments. For example: + * + * MOZ_ARGS_AFTER_2(a, b, c, d) expands to: c, d + */ +#define MOZ_ARGS_AFTER_1(a1, ...) __VA_ARGS__ +#define MOZ_ARGS_AFTER_2(a1, a2, ...) __VA_ARGS__ + +/* + * MOZ_ARG_N expands to its |N|th argument. + */ +#define MOZ_ARG_1(a1, ...) a1 +#define MOZ_ARG_2(a1, a2, ...) a2 + +#endif /* mozilla_MacroArgs_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MathAlgorithms.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MathAlgorithms.h new file mode 100644 index 0000000000..9a8aa2f413 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MathAlgorithms.h @@ -0,0 +1,501 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* mfbt maths algorithms. */ + +#ifndef mozilla_MathAlgorithms_h +#define mozilla_MathAlgorithms_h + +#include "mozilla/Assertions.h" +#include "mozilla/TypeTraits.h" + +#include +#include +#include + +namespace mozilla { + +// Greatest Common Divisor +template +MOZ_ALWAYS_INLINE IntegerType +EuclidGCD(IntegerType aA, IntegerType aB) +{ + // Euclid's algorithm; O(N) in the worst case. (There are better + // ways, but we don't need them for the current use of this algo.) + MOZ_ASSERT(aA > IntegerType(0)); + MOZ_ASSERT(aB > IntegerType(0)); + + while (aA != aB) { + if (aA > aB) { + aA = aA - aB; + } else { + aB = aB - aA; + } + } + + return aA; +} + +// Least Common Multiple +template +MOZ_ALWAYS_INLINE IntegerType +EuclidLCM(IntegerType aA, IntegerType aB) +{ + // Divide first to reduce overflow risk. + return (aA / EuclidGCD(aA, aB)) * aB; +} + +namespace detail { + +template +struct AllowDeprecatedAbsFixed : FalseType {}; + +template<> struct AllowDeprecatedAbsFixed : TrueType {}; +template<> struct AllowDeprecatedAbsFixed : TrueType {}; + +template +struct AllowDeprecatedAbs : AllowDeprecatedAbsFixed {}; + +template<> struct AllowDeprecatedAbs : TrueType {}; +template<> struct AllowDeprecatedAbs : TrueType {}; + +} // namespace detail + +// DO NOT USE DeprecatedAbs. It exists only until its callers can be converted +// to Abs below, and it will be removed when all callers have been changed. +template +inline typename mozilla::EnableIf::value, T>::Type +DeprecatedAbs(const T aValue) +{ + // The absolute value of the smallest possible value of a signed-integer type + // won't fit in that type (on twos-complement systems -- and we're blithely + // assuming we're on such systems, for the non- types listed above), + // so assert that the input isn't that value. + // + // This is the case if: the value is non-negative; or if adding one (giving a + // value in the range [-maxvalue, 0]), then negating (giving a value in the + // range [0, maxvalue]), doesn't produce maxvalue (because in twos-complement, + // (minvalue + 1) == -maxvalue). + MOZ_ASSERT(aValue >= 0 || + -(aValue + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1), + "You can't negate the smallest possible negative integer!"); + return aValue >= 0 ? aValue : -aValue; +} + +namespace detail { + +// For now mozilla::Abs only takes intN_T, the signed natural types, and +// float/double/long double. Feel free to add overloads for other standard, +// signed types if you need them. + +template +struct AbsReturnTypeFixed; + +template<> struct AbsReturnTypeFixed { typedef uint8_t Type; }; +template<> struct AbsReturnTypeFixed { typedef uint16_t Type; }; +template<> struct AbsReturnTypeFixed { typedef uint32_t Type; }; +template<> struct AbsReturnTypeFixed { typedef uint64_t Type; }; + +template +struct AbsReturnType : AbsReturnTypeFixed {}; + +template<> struct AbsReturnType : + EnableIf {}; +template<> struct AbsReturnType { typedef unsigned char Type; }; +template<> struct AbsReturnType { typedef unsigned short Type; }; +template<> struct AbsReturnType { typedef unsigned int Type; }; +template<> struct AbsReturnType { typedef unsigned long Type; }; +template<> struct AbsReturnType { typedef unsigned long long Type; }; +template<> struct AbsReturnType { typedef float Type; }; +template<> struct AbsReturnType { typedef double Type; }; +template<> struct AbsReturnType { typedef long double Type; }; + +} // namespace detail + +template +inline typename detail::AbsReturnType::Type +Abs(const T aValue) +{ + typedef typename detail::AbsReturnType::Type ReturnType; + return aValue >= 0 ? ReturnType(aValue) : ~ReturnType(aValue) + 1; +} + +template<> +inline float +Abs(const float aFloat) +{ + return std::fabs(aFloat); +} + +template<> +inline double +Abs(const double aDouble) +{ + return std::fabs(aDouble); +} + +template<> +inline long double +Abs(const long double aLongDouble) +{ + return std::fabs(aLongDouble); +} + +} // namespace mozilla + +#if defined(_WIN32) && (_MSC_VER >= 1300) && \ + (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) || defined(_M_ARM)) +# define MOZ_BITSCAN_WINDOWS + +# include +# pragma intrinsic(_BitScanForward, _BitScanReverse) + +# if defined(_M_AMD64) || defined(_M_X64) +# define MOZ_BITSCAN_WINDOWS64 +# pragma intrinsic(_BitScanForward64, _BitScanReverse64) +# endif + +#endif + +namespace mozilla { + +namespace detail { + +#if defined(MOZ_BITSCAN_WINDOWS) + +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanReverse(&index, static_cast(aValue)); + return uint_fast8_t(31 - index); +} + + +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + unsigned long index; + _BitScanForward(&index, static_cast(aValue)); + return uint_fast8_t(index); +} + +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + uint32_t x = aValue - ((aValue >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + return (((x + (x >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; +} +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return uint_fast8_t(CountPopulation32(aValue & 0xffffffff) + + CountPopulation32(aValue >> 32)); +} + +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanReverse64(&index, static_cast(aValue)); + return uint_fast8_t(63 - index); +#else + uint32_t hi = uint32_t(aValue >> 32); + if (hi != 0) { + return CountLeadingZeroes32(hi); + } + return 32u + CountLeadingZeroes32(uint32_t(aValue)); +#endif +} + +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ +#if defined(MOZ_BITSCAN_WINDOWS64) + unsigned long index; + _BitScanForward64(&index, static_cast(aValue)); + return uint_fast8_t(index); +#else + uint32_t lo = uint32_t(aValue); + if (lo != 0) { + return CountTrailingZeroes32(lo); + } + return 32u + CountTrailingZeroes32(uint32_t(aValue >> 32)); +#endif +} + +# ifdef MOZ_HAVE_BITSCAN64 +# undef MOZ_HAVE_BITSCAN64 +# endif + +#elif defined(__clang__) || defined(__GNUC__) + +# if defined(__clang__) +# if !__has_builtin(__builtin_ctz) || !__has_builtin(__builtin_clz) +# error "A clang providing __builtin_c[lt]z is required to build" +# endif +# else + // gcc has had __builtin_clz and friends since 3.4: no need to check. +# endif + +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + return __builtin_clz(aValue); +} + +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + return __builtin_ctz(aValue); +} + +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + return __builtin_popcount(aValue); +} + +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return __builtin_popcountll(aValue); +} + +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ + return __builtin_clzll(aValue); +} + +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ + return __builtin_ctzll(aValue); +} + +#else +# error "Implement these!" +inline uint_fast8_t CountLeadingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation32(uint32_t aValue) MOZ_DELETE; +inline uint_fast8_t CountPopulation64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountLeadingZeroes64(uint64_t aValue) MOZ_DELETE; +inline uint_fast8_t CountTrailingZeroes64(uint64_t aValue) MOZ_DELETE; +#endif + +} // namespace detail + +/** + * Compute the number of high-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * highest- valued bits at the start, return the number of zeroes before the + * first one is observed. + * + * CountLeadingZeroes32(0xF0FF1000) is 0; + * CountLeadingZeroes32(0x7F8F0001) is 1; + * CountLeadingZeroes32(0x3FFF0100) is 2; + * CountLeadingZeroes32(0x1FF50010) is 3; and so on. + */ +inline uint_fast8_t +CountLeadingZeroes32(uint32_t aValue) +{ + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes32(aValue); +} + +/** + * Compute the number of low-order zero bits in the NON-ZERO number |aValue|. + * That is, looking at the bitwise representation of the number, with the + * lowest- valued bits at the start, return the number of zeroes before the + * first one is observed. + * + * CountTrailingZeroes32(0x0100FFFF) is 0; + * CountTrailingZeroes32(0x7000FFFE) is 1; + * CountTrailingZeroes32(0x0080FFFC) is 2; + * CountTrailingZeroes32(0x0080FFF8) is 3; and so on. + */ +inline uint_fast8_t +CountTrailingZeroes32(uint32_t aValue) +{ + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes32(aValue); +} + +/** + * Compute the number of one bits in the number |aValue|, + */ +inline uint_fast8_t +CountPopulation32(uint32_t aValue) +{ + return detail::CountPopulation32(aValue); +} + +/** Analogous to CoutPopulation32, but for 64-bit numbers */ +inline uint_fast8_t +CountPopulation64(uint64_t aValue) +{ + return detail::CountPopulation64(aValue); +} + +/** Analogous to CountLeadingZeroes32, but for 64-bit numbers. */ +inline uint_fast8_t +CountLeadingZeroes64(uint64_t aValue) +{ + MOZ_ASSERT(aValue != 0); + return detail::CountLeadingZeroes64(aValue); +} + +/** Analogous to CountTrailingZeroes32, but for 64-bit numbers. */ +inline uint_fast8_t +CountTrailingZeroes64(uint64_t aValue) +{ + MOZ_ASSERT(aValue != 0); + return detail::CountTrailingZeroes64(aValue); +} + +namespace detail { + +template +class CeilingLog2; + +template +class CeilingLog2 +{ +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0u : 32u - CountLeadingZeroes32(aValue - 1); + } +}; + +template +class CeilingLog2 +{ +public: + static uint_fast8_t compute(const T aValue) + { + // Check for <= 1 to avoid the == 0 undefined case. + return aValue <= 1 ? 0 : 64 - CountLeadingZeroes64(aValue - 1); + } +}; + +} // namespace detail + +/** + * Compute the log of the least power of 2 greater than or equal to |aValue|. + * + * CeilingLog2(0..1) is 0; + * CeilingLog2(2) is 1; + * CeilingLog2(3..4) is 2; + * CeilingLog2(5..8) is 3; + * CeilingLog2(9..16) is 4; and so on. + */ +template +inline uint_fast8_t +CeilingLog2(const T aValue) +{ + return detail::CeilingLog2::compute(aValue); +} + +/** A CeilingLog2 variant that accepts only size_t. */ +inline uint_fast8_t +CeilingLog2Size(size_t aValue) +{ + return CeilingLog2(aValue); +} + +namespace detail { + +template +class FloorLog2; + +template +class FloorLog2 +{ +public: + static uint_fast8_t compute(const T aValue) + { + return 31u - CountLeadingZeroes32(aValue | 1); + } +}; + +template +class FloorLog2 +{ +public: + static uint_fast8_t compute(const T aValue) + { + return 63u - CountLeadingZeroes64(aValue | 1); + } +}; + +} // namespace detail + +/** + * Compute the log of the greatest power of 2 less than or equal to |aValue|. + * + * FloorLog2(0..1) is 0; + * FloorLog2(2..3) is 1; + * FloorLog2(4..7) is 2; + * FloorLog2(8..15) is 3; and so on. + */ +template +inline uint_fast8_t +FloorLog2(const T aValue) +{ + return detail::FloorLog2::compute(aValue); +} + +/** A FloorLog2 variant that accepts only size_t. */ +inline uint_fast8_t +FloorLog2Size(size_t aValue) +{ + return FloorLog2(aValue); +} + +/* + * Compute the smallest power of 2 greater than or equal to |x|. |x| must not + * be so great that the computed value would overflow |size_t|. + */ +inline size_t +RoundUpPow2(size_t aValue) +{ + MOZ_ASSERT(aValue <= (size_t(1) << (sizeof(size_t) * CHAR_BIT - 1)), + "can't round up -- will overflow!"); + return size_t(1) << CeilingLog2(aValue); +} + +/** + * Rotates the bits of the given value left by the amount of the shift width. + */ +template +inline T +RotateLeft(const T aValue, uint_fast8_t aShift) +{ + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + static_assert(IsUnsigned::value, "Rotates require unsigned values"); + return (aValue << aShift) | (aValue >> (sizeof(T) * CHAR_BIT - aShift)); +} + +/** + * Rotates the bits of the given value right by the amount of the shift width. + */ +template +inline T +RotateRight(const T aValue, uint_fast8_t aShift) +{ + MOZ_ASSERT(aShift < sizeof(T) * CHAR_BIT, "Shift value is too large!"); + static_assert(IsUnsigned::value, "Rotates require unsigned values"); + return (aValue >> aShift) | (aValue << (sizeof(T) * CHAR_BIT - aShift)); +} + +} /* namespace mozilla */ + +#endif /* mozilla_MathAlgorithms_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Maybe.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Maybe.h new file mode 100644 index 0000000000..4ba88f6771 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Maybe.h @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A class for lazily constructing an object without sticking it on the heap. */ + +#ifndef mozilla_Maybe_h +#define mozilla_Maybe_h + +#include "mozilla/Alignment.h" +#include "mozilla/Assertions.h" + +// For placement new +#include + +namespace mozilla { + +/* + * Small utility for lazily constructing objects without using dynamic storage. + * When a Maybe is constructed, it is |empty()|, i.e., no value of T has + * been constructed and no T destructor will be called when the Maybe is + * destroyed. Upon calling |construct|, a T object will be constructed with the + * given arguments and that object will be destroyed when the owning Maybe + * is destroyed. + * + * N.B. GCC seems to miss some optimizations with Maybe and may generate extra + * branches/loads/stores. Use with caution on hot paths. + */ +template +class Maybe +{ + AlignedStorage2 storage; + bool constructed; + + T& asT() { return *storage.addr(); } + +public: + Maybe() { constructed = false; } + ~Maybe() { if (constructed) { asT().~T(); } } + + bool empty() const { return !constructed; } + + void construct() + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(); + constructed = true; + } + + template + void construct(const T1& aT1) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9); + constructed = true; + } + + template + void construct(const T1& aT1, const T2& aT2, const T3& aT3, const T4& aT4, + const T5& aT5, const T6& aT6, const T7& aT7, const T8& aT8, + const T9& aT9, const T10& aT10) + { + MOZ_ASSERT(!constructed); + ::new (storage.addr()) T(aT1, aT2, aT3, aT4, aT5, aT6, aT7, aT8, aT9, aT10); + constructed = true; + } + + T* addr() + { + MOZ_ASSERT(constructed); + return &asT(); + } + + T& ref() + { + MOZ_ASSERT(constructed); + return asT(); + } + + const T& ref() const + { + MOZ_ASSERT(constructed); + return const_cast(this)->asT(); + } + + void destroy() + { + ref().~T(); + constructed = false; + } + + void destroyIfConstructed() + { + if (!empty()) { + destroy(); + } + } + +private: + Maybe(const Maybe& aOther) MOZ_DELETE; + const Maybe& operator=(const Maybe& aOther) MOZ_DELETE; +}; + +} // namespace mozilla + +#endif /* mozilla_Maybe_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MemoryChecking.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MemoryChecking.h new file mode 100644 index 0000000000..0642d758c0 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MemoryChecking.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Provides a common interface to the ASan (AddressSanitizer) and Valgrind + * functions used to mark memory in certain ways. In detail, the following + * three macros are provided: + * + * MOZ_MAKE_MEM_NOACCESS - Mark memory as unsafe to access (e.g. freed) + * MOZ_MAKE_MEM_UNDEFINED - Mark memory as accessible, with content undefined + * MOZ_MAKE_MEM_DEFINED - Mark memory as accessible, with content defined + * + * With Valgrind in use, these directly map to the three respective Valgrind + * macros. With ASan in use, the NOACCESS macro maps to poisoning the memory, + * while the UNDEFINED/DEFINED macros unpoison memory. + * + * With no memory checker available, all macros expand to the empty statement. + */ + +#ifndef mozilla_MemoryChecking_h +#define mozilla_MemoryChecking_h + +#if defined(MOZ_VALGRIND) +#include "valgrind/memcheck.h" +#endif + +#if defined(MOZ_ASAN) || defined(MOZ_VALGRIND) +#define MOZ_HAVE_MEM_CHECKS 1 +#endif + +#if defined(MOZ_ASAN) +#include + +#include "mozilla/Types.h" + +extern "C" { +/* These definitions are usually provided through the + * sanitizer/asan_interface.h header installed by ASan. + */ +void MOZ_EXPORT __asan_poison_memory_region(void const volatile *addr, size_t size); +void MOZ_EXPORT __asan_unpoison_memory_region(void const volatile *addr, size_t size); + +#define MOZ_MAKE_MEM_NOACCESS(addr, size) \ + __asan_poison_memory_region((addr), (size)) + +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) \ + __asan_unpoison_memory_region((addr), (size)) + +#define MOZ_MAKE_MEM_DEFINED(addr, size) \ + __asan_unpoison_memory_region((addr), (size)) +} +#elif defined(MOZ_VALGRIND) +#define MOZ_MAKE_MEM_NOACCESS(addr, size) \ + VALGRIND_MAKE_MEM_NOACCESS((addr), (size)) + +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) \ + VALGRIND_MAKE_MEM_UNDEFINED((addr), (size)) + +#define MOZ_MAKE_MEM_DEFINED(addr, size) \ + VALGRIND_MAKE_MEM_DEFINED((addr), (size)) +#else + +#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while (0) + +#endif + +#endif /* mozilla_MemoryChecking_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MemoryReporting.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MemoryReporting.h new file mode 100644 index 0000000000..d2340ecf09 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/MemoryReporting.h @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Memory reporting infrastructure. */ + +#ifndef mozilla_MemoryReporting_h +#define mozilla_MemoryReporting_h + +#include + +#ifdef __cplusplus + +namespace mozilla { + +/* + * This is for functions that are like malloc_usable_size. Such functions are + * used for measuring the size of data structures. + */ +typedef size_t (*MallocSizeOf)(const void* p); + +} /* namespace mozilla */ + +#endif /* __cplusplus */ + +typedef size_t (*MozMallocSizeOf)(const void* p); + +#endif /* mozilla_MemoryReporting_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Move.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Move.h new file mode 100644 index 0000000000..08ae86fa57 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Move.h @@ -0,0 +1,250 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* C++11-style, but C++98-usable, "move references" implementation. */ + +#ifndef mozilla_Move_h +#define mozilla_Move_h + +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +/* + * "Move" References + * + * Some types can be copied much more efficiently if we know the original's + * value need not be preserved --- that is, if we are doing a "move", not a + * "copy". For example, if we have: + * + * Vector u; + * Vector v(u); + * + * the constructor for v must apply a copy constructor to each element of u --- + * taking time linear in the length of u. However, if we know we will not need u + * any more once v has been initialized, then we could initialize v very + * efficiently simply by stealing u's dynamically allocated buffer and giving it + * to v --- a constant-time operation, regardless of the size of u. + * + * Moves often appear in container implementations. For example, when we append + * to a vector, we may need to resize its buffer. This entails moving each of + * its extant elements from the old, smaller buffer to the new, larger buffer. + * But once the elements have been migrated, we're just going to throw away the + * old buffer; we don't care if they still have their values. So if the vector's + * element type can implement "move" more efficiently than "copy", the vector + * resizing should by all means use a "move" operation. Hash tables should also + * use moves when resizing their internal array as entries are added and + * removed. + * + * The details of the optimization, and whether it's worth applying, vary + * from one type to the next: copying an 'int' is as cheap as moving it, so + * there's no benefit in distinguishing 'int' moves from copies. And while + * some constructor calls for complex types are moves, many really have to + * be copies, and can't be optimized this way. So we need: + * + * 1) a way for a type (like Vector) to announce that it can be moved more + * efficiently than it can be copied, and provide an implementation of that + * move operation; and + * + * 2) a way for a particular invocation of a copy constructor to say that it's + * really a move, not a copy, and that the value of the original isn't + * important afterwards (although it must still be safe to destroy). + * + * If a constructor has a single argument of type 'T&&' (an 'rvalue reference + * to T'), that indicates that it is a 'move constructor'. That's 1). It should + * move, not copy, its argument into the object being constructed. It may leave + * the original in any safely-destructible state. + * + * If a constructor's argument is an rvalue, as in 'C(f(x))' or 'C(x + y)', as + * opposed to an lvalue, as in 'C(x)', then overload resolution will prefer the + * move constructor, if there is one. The 'mozilla::Move' function, defined in + * this file, is an identity function you can use in a constructor invocation to + * make any argument into an rvalue, like this: C(Move(x)). That's 2). (You + * could use any function that works, but 'Move' indicates your intention + * clearly.) + * + * Where we might define a copy constructor for a class C like this: + * + * C(const C& rhs) { ... copy rhs to this ... } + * + * we would declare a move constructor like this: + * + * C(C&& rhs) { .. move rhs to this ... } + * + * And where we might perform a copy like this: + * + * C c2(c1); + * + * we would perform a move like this: + * + * C c2(Move(c1)); + * + * Note that 'T&&' implicitly converts to 'T&'. So you can pass a 'T&&' to an + * ordinary copy constructor for a type that doesn't support a special move + * constructor, and you'll just get a copy. This means that templates can use + * Move whenever they know they won't use the original value any more, even if + * they're not sure whether the type at hand has a specialized move constructor. + * If it doesn't, the 'T&&' will just convert to a 'T&', and the ordinary copy + * constructor will apply. + * + * A class with a move constructor can also provide a move assignment operator. + * A generic definition would run this's destructor, and then apply the move + * constructor to *this's memory. A typical definition: + * + * C& operator=(C&& rhs) { + * MOZ_ASSERT(&rhs != this, "self-moves are prohibited"); + * this->~C(); + * new(this) C(Move(rhs)); + * return *this; + * } + * + * With that in place, one can write move assignments like this: + * + * c2 = Move(c1); + * + * This destroys c2, moves c1's value to c2, and leaves c1 in an undefined but + * destructible state. + * + * As we say, a move must leave the original in a "destructible" state. The + * original's destructor will still be called, so if a move doesn't + * actually steal all its resources, that's fine. We require only that the + * move destination must take on the original's value; and that destructing + * the original must not break the move destination. + * + * (Opinions differ on whether move assignment operators should deal with move + * assignment of an object onto itself. It seems wise to either handle that + * case, or assert that it does not occur.) + * + * Forwarding: + * + * Sometimes we want copy construction or assignment if we're passed an ordinary + * value, but move construction if passed an rvalue reference. For example, if + * our constructor takes two arguments and either could usefully be a move, it + * seems silly to write out all four combinations: + * + * C::C(X& x, Y& y) : x(x), y(y) { } + * C::C(X& x, Y&& y) : x(x), y(Move(y)) { } + * C::C(X&& x, Y& y) : x(Move(x)), y(y) { } + * C::C(X&& x, Y&& y) : x(Move(x)), y(Move(y)) { } + * + * To avoid this, C++11 has tweaks to make it possible to write what you mean. + * The four constructor overloads above can be written as one constructor + * template like so[0]: + * + * template + * C::C(XArg&& x, YArg&& y) : x(Forward(x)), y(Forward(y)) { } + * + * ("'Don't Repeat Yourself'? What's that?") + * + * This takes advantage of two new rules in C++11: + * + * - First, when a function template takes an argument that is an rvalue + * reference to a template argument (like 'XArg&& x' and 'YArg&& y' above), + * then when the argument is applied to an lvalue, the template argument + * resolves to 'T&'; and when it is applied to an rvalue, the template + * argument resolves to 'T&&'. Thus, in a call to C::C like: + * + * X foo(int); + * Y yy; + * + * C(foo(5), yy) + * + * XArg would resolve to 'X&&', and YArg would resolve to 'Y&'. + * + * - Second, Whereas C++ used to forbid references to references, C++11 defines + * 'collapsing rules': 'T& &', 'T&& &', and 'T& &&' (that is, any combination + * involving an lvalue reference) now collapse to simply 'T&'; and 'T&& &&' + * collapses to 'T&&'. + * + * Thus, in the call above, 'XArg&&' is 'X&& &&', collapsing to 'X&&'; and + * 'YArg&&' is 'Y& &&', which collapses to 'Y &'. Because the arguments are + * declared as rvalue references to template arguments, the rvalue-ness + * "shines through" where present. + * + * Then, the 'Forward' function --- you must invoke 'Forward' with its type + * argument --- returns an lvalue reference or an rvalue reference to its + * argument, depending on what T is. In our unified constructor definition, that + * means that we'll invoke either the copy or move constructors for x and y, + * depending on what we gave C's constructor. In our call, we'll move 'foo()' + * into 'x', but copy 'yy' into 'y'. + * + * This header file defines Move and Forward in the mozilla namespace. It's up + * to individual containers to annotate moves as such, by calling Move; and it's + * up to individual types to define move constructors and assignment operators + * when valuable. + * + * (C++11 says that the header file should define 'std::move' and + * 'std::forward', which are just like our 'Move' and 'Forward'; but those + * definitions aren't available in that header on all our platforms, so we + * define them ourselves here.) + * + * 0. This pattern is known as "perfect forwarding". Interestingly, it is not + * actually perfect, and it can't forward all possible argument expressions! + * There are two issues: one that's a C++11 issue, and one that's a legacy + * compiler issue. + * + * The C++11 issue is that you can't form a reference to a bit-field. As a + * workaround, assign the bit-field to a local variable and use that: + * + * // C is as above + * struct S { int x : 1; } s; + * C(s.x, 0); // BAD: s.x is a reference to a bit-field, can't form those + * int tmp = s.x; + * C(tmp, 0); // OK: tmp not a bit-field + * + * The legacy issue is that when we don't have true nullptr and must emulate + * it (gcc 4.4/4.5), forwarding |nullptr| results in an |int| or |long| + * forwarded reference. But such a reference, even if its value is a null + * pointer constant expression, is not itself a null pointer constant + * expression. This causes -Werror=conversion-null errors and pointer-to- + * integer comparison errors. Until we always have true nullptr, users of + * forwarding methods must not pass |nullptr| to them. + */ + +/** + * Identical to std::Move(); this is necessary until our stlport supports + * std::move(). + */ +template +inline typename RemoveReference::Type&& +Move(T&& aX) +{ + return static_cast::Type&&>(aX); +} + +/** + * These two overloads are identical to std::forward(); they are necessary until + * our stlport supports std::forward(). + */ +template +inline T&& +Forward(typename RemoveReference::Type& aX) +{ + return static_cast(aX); +} + +template +inline T&& +Forward(typename RemoveReference::Type&& aX) +{ + static_assert(!IsLvalueReference::value, + "misuse of Forward detected! try the other overload"); + return static_cast(aX); +} + +/** Swap |aX| and |aY| using move-construction if possible. */ +template +inline void +Swap(T& aX, T& aY) +{ + T tmp(Move(aX)); + aX = Move(aY); + aY = Move(tmp); +} + +} // namespace mozilla + +#endif /* mozilla_Move_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/NullPtr.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/NullPtr.h new file mode 100644 index 0000000000..5963613c4b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/NullPtr.h @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements a workaround for compilers which do not support the C++11 nullptr + * constant. + */ + +#ifndef mozilla_NullPtr_h +#define mozilla_NullPtr_h + +#if defined(__clang__) +# if !__has_extension(cxx_nullptr) +# error "clang version natively supporting nullptr is required." +# endif +# define MOZ_HAVE_CXX11_NULLPTR +#elif defined(__GNUC__) +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# include "mozilla/Compiler.h" +# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) +# define MOZ_HAVE_CXX11_NULLPTR +# endif +# endif +#elif defined(_MSC_VER) + // The minimum supported MSVC (10, _MSC_VER 1600) supports nullptr. +# define MOZ_HAVE_CXX11_NULLPTR +#endif + +namespace mozilla { + +/** + * IsNullPointer::value is true iff T is the type of C++11's nullptr. If + * nullptr is emulated, IsNullPointer::value is false for all T. + * + * IsNullPointer is useful to give an argument the true decltype(nullptr) type. + * decltype(nullptr) doesn't work when nullptr is emulated. The simplest + * workaround is to use template overloading and SFINAE to expose an overload + * only if an argument's type is decltype(nullptr). Some examples (that assume + * namespace mozilla has been opened, for simplicity): + * + * // foo(T*), foo(stuff that converts to T*), and foo(decltype(nullptr)) + * // (only invoked if nullptr is true nullptr, otherwise foo(T*) is invoked) + * // but nothing else + * void foo(T*) { } + * template + * void foo(N, + * typename EnableIf::value, int>::Type dummy = 0) + * { } + * + * // foo(T*) *exactly* and foo(decltype(nullptr)), nothing else + * void foo(T*) { } + * template + * void foo(U, + * typename EnableIf::value, int>::Type dummy = 0) + * MOZ_DELETE; + * + * The exact details of how set up the SFINAE bits vary on a case-by-case basis. + * If you need help with this (and unless you've internalized way more sadmaking + * nullptr-emulation knowledge than you should have, you do), feel free to poke + * the person with blame on this comment with questions. :-) + * + * Ideally this would be in TypeTraits.h, but C++11 omitted std::is_null_pointer + * (fixed in C++1y), so in the interests of easing a switch to , + * this trait lives elsewhere. + */ +template +struct IsNullPointer { static const bool value = false; }; + +} // namespace mozilla + +/** + * mozilla::NullptrT is a type that's sort of like decltype(nullptr). But it + * can't be identical, because emulated nullptr doesn't have a distinct type. + * Only with gcc 4.4/4.5, emulated nullptr is __null, and decltype(__null) is + * int or long. But passing __null to an int/long parameter triggers + * -Werror=conversion-null errors with gcc 4.5, or (depending on subsequent use + * inside the overloaded function) can trigger pointer-to-integer comparison + * compiler errors. So fairly often, actually, NullptrT is *not* what you want. + * + * Instead, often you should use template-based overloading in concert with + * SFINAE to add a nullptr overload -- see the comments by IsNullPointer. + * + * So when *should* you use NullptrT? Thus far, the only truly good use seems + * to be as an argument type for operator overloads (because C++ doesn't allow + * operator= to have more than one argument, operator== to have more than two, + * &c.). But even in such cases, it really only works if there are no other + * overloads of the operator that accept a pointer type. If you want both T* + * and nullptr_t overloads, you'll have to wait til we drop gcc 4.4/4.5 support. + * (Currently b2g is the only impediment to this.) + */ +#ifdef MOZ_HAVE_CXX11_NULLPTR +// decltype does the right thing for actual nullptr. +namespace mozilla { +typedef decltype(nullptr) NullptrT; +template<> +struct IsNullPointer { static const bool value = true; }; +} +# undef MOZ_HAVE_CXX11_NULLPTR +#elif MOZ_IS_GCC +# define nullptr __null +// void* sweeps up more than just nullptr, but compilers supporting true +// nullptr are the majority now, so they should detect mistakes. If you're +// feeling paranoid, check/assert that your NullptrT equals nullptr. +namespace mozilla { typedef void* NullptrT; } +#else +# error "No compiler support for nullptr or its emulation." +#endif + +#endif /* mozilla_NullPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/NumericLimits.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/NumericLimits.h new file mode 100644 index 0000000000..730fcb410b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/NumericLimits.h @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Compatibility with std::numeric_limits. */ + +#ifndef mozilla_NumericLimits_h +#define mozilla_NumericLimits_h + +#include "mozilla/Char16.h" + +#include +#include + +namespace mozilla { + +/** + * The NumericLimits class provides a compatibility layer with + * std::numeric_limits for char16_t, otherwise it is exactly the same as + * std::numeric_limits. Code which does not need std::numeric_limits + * should avoid using NumericLimits. + */ +template +class NumericLimits : public std::numeric_limits +{ +}; + +#ifdef MOZ_CHAR16_IS_NOT_WCHAR +template<> +class NumericLimits : public std::numeric_limits +{ + // char16_t and uint16_t numeric limits should be exactly the same. +}; +#endif + +} // namespace mozilla + +#endif /* mozilla_NumericLimits_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Pair.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Pair.h new file mode 100644 index 0000000000..e9e8a76938 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Pair.h @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A class holding a pair of objects that tries to conserve storage space. */ + +#ifndef mozilla_Pair_h +#define mozilla_Pair_h + +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +namespace detail { + +enum StorageType { AsBase, AsMember }; + +// Optimize storage using the Empty Base Optimization -- that empty base classes +// don't take up space -- to optimize size when one or the other class is +// stateless and can be used as a base class. +// +// The extra conditions on storage for B are necessary so that PairHelper won't +// ambiguously inherit from either A or B, such that one or the other base class +// would be inaccessible. +template::value ? detail::AsBase : detail::AsMember, + detail::StorageType = + IsEmpty::value && !IsBaseOf::value && !IsBaseOf::value + ? detail::AsBase + : detail::AsMember> +struct PairHelper; + +template +struct PairHelper +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : mFirstA(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(mSecondB, aOther.mSecondB); + } + +private: + A mFirstA; + B mSecondB; +}; + +template +struct PairHelper : private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : B(Forward(aB)), + mFirstA(Forward(aA)) + {} + + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return *this; } + const B& second() const { return *this; } + + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(static_cast(*this), static_cast(aOther)); + } + +private: + A mFirstA; +}; + +template +struct PairHelper : private A +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + mSecondB(Forward(aB)) + {} + + A& first() { return *this; } + const A& first() const { return *this; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(mSecondB, aOther.mSecondB); + } + +private: + B mSecondB; +}; + +template +struct PairHelper : private A, private B +{ +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + B(Forward(aB)) + {} + + A& first() { return static_cast(*this); } + const A& first() const { return static_cast(*this); } + B& second() { return static_cast(*this); } + const B& second() const { return static_cast(*this); } + + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(static_cast(*this), static_cast(aOther)); + } +}; + +} // namespace detail + +/** + * Pair is the logical concatenation of an instance of A with an instance B. + * Space is conserved when possible. Neither A nor B may be a final class. + * + * It's typically clearer to have individual A and B member fields. Except if + * you want the space-conserving qualities of Pair, you're probably better off + * not using this! + * + * No guarantees are provided about the memory layout of A and B, the order of + * initialization or destruction of A and B, and so on. (This is approximately + * required to optimize space usage.) The first/second names are merely + * conceptual! + */ +template +struct Pair + : private detail::PairHelper +{ + typedef typename detail::PairHelper Base; + +public: + template + Pair(AArg&& aA, BArg&& aB) + : Base(Forward(aA), Forward(aB)) + {} + + /** The A instance. */ + using Base::first; + /** The B instance. */ + using Base::second; + + /** Swap this pair with another pair. */ + void swap(Pair& aOther) { Base::swap(aOther); } + +private: + Pair(const Pair&) MOZ_DELETE; +}; + +template +void +Swap(Pair& aX, Pair& aY) +{ + aX.swap(aY); +} + +} // namespace mozilla + +#endif /* mozilla_Pair_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/PodOperations.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/PodOperations.h new file mode 100644 index 0000000000..843e1311d3 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/PodOperations.h @@ -0,0 +1,195 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Operations for zeroing POD types, arrays, and so on. + * + * These operations are preferable to memset, memcmp, and the like because they + * don't require remembering to multiply by sizeof(T), array lengths, and so on + * everywhere. + */ + +#ifndef mozilla_PodOperations_h +#define mozilla_PodOperations_h + +#include "mozilla/Array.h" +#include "mozilla/ArrayUtils.h" +#include "mozilla/Attributes.h" + +#include +#include + +namespace mozilla { + +/** Set the contents of |aT| to 0. */ +template +static MOZ_ALWAYS_INLINE void +PodZero(T* aT) +{ + memset(aT, 0, sizeof(T)); +} + +/** Set the contents of |aNElem| elements starting at |aT| to 0. */ +template +static MOZ_ALWAYS_INLINE void +PodZero(T* aT, size_t aNElem) +{ + /* + * This function is often called with 'aNElem' small; we use an inline loop + * instead of calling 'memset' with a non-constant length. The compiler + * should inline the memset call with constant size, though. + */ + for (T* end = aT + aNElem; aT < end; aT++) { + memset(aT, 0, sizeof(T)); + } +} + +/* + * Arrays implicitly convert to pointers to their first element, which is + * dangerous when combined with the above PodZero definitions. Adding an + * overload for arrays is ambiguous, so we need another identifier. The + * ambiguous overload is left to catch mistaken uses of PodZero; if you get a + * compile error involving PodZero and array types, use PodArrayZero instead. + */ +template +static void PodZero(T (&aT)[N]) MOZ_DELETE; +template +static void PodZero(T (&aT)[N], size_t aNElem) MOZ_DELETE; + +/** Set the contents of the array |aT| to zero. */ +template +static MOZ_ALWAYS_INLINE void +PodArrayZero(T (&aT)[N]) +{ + memset(aT, 0, N * sizeof(T)); +} + +template +static MOZ_ALWAYS_INLINE void +PodArrayZero(Array& aArr) +{ + memset(&aArr[0], 0, N * sizeof(T)); +} + +/** + * Assign |*aSrc| to |*aDst|. The locations must not be the same and must not + * overlap. + */ +template +static MOZ_ALWAYS_INLINE void +PodAssign(T* aDst, const T* aSrc) +{ + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= 1); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= 1); + memcpy(reinterpret_cast(aDst), reinterpret_cast(aSrc), + sizeof(T)); +} + +/** + * Copy |aNElem| T elements from |aSrc| to |aDst|. The two memory ranges must + * not overlap! + */ +template +static MOZ_ALWAYS_INLINE void +PodCopy(T* aDst, const T* aSrc, size_t aNElem) +{ + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); + + if (aNElem < 128) { + /* + * Avoid using operator= in this loop, as it may have been + * intentionally deleted by the POD type. + */ + for (const T* srcend = aSrc + aNElem; aSrc < srcend; aSrc++, aDst++) { + PodAssign(aDst, aSrc); + } + } else { + memcpy(aDst, aSrc, aNElem * sizeof(T)); + } +} + +template +static MOZ_ALWAYS_INLINE void +PodCopy(volatile T* aDst, const volatile T* aSrc, size_t aNElem) +{ + MOZ_ASSERT(aDst != aSrc); + MOZ_ASSERT_IF(aSrc < aDst, + PointerRangeSize(aSrc, static_cast(aDst)) >= aNElem); + MOZ_ASSERT_IF(aDst < aSrc, + PointerRangeSize(static_cast(aDst), aSrc) >= aNElem); + + /* + * Volatile |aDst| requires extra work, because it's undefined behavior to + * modify volatile objects using the mem* functions. Just write out the + * loops manually, using operator= rather than memcpy for the same reason, + * and let the compiler optimize to the extent it can. + */ + for (const volatile T* srcend = aSrc + aNElem; + aSrc < srcend; + aSrc++, aDst++) { + *aDst = *aSrc; + } +} + +/* + * Copy the contents of the array |aSrc| into the array |aDst|, both of size N. + * The arrays must not overlap! + */ +template +static MOZ_ALWAYS_INLINE void +PodArrayCopy(T (&aDst)[N], const T (&aSrc)[N]) +{ + PodCopy(aDst, aSrc, N); +} + +/** + * Copy the memory for |aNElem| T elements from |aSrc| to |aDst|. If the two + * memory ranges overlap, then the effect is as if the |aNElem| elements are + * first copied from |aSrc| to a temporary array, and then from the temporary + * array to |aDst|. + */ +template +static MOZ_ALWAYS_INLINE void +PodMove(T* aDst, const T* aSrc, size_t aNElem) +{ + MOZ_ASSERT(aNElem <= SIZE_MAX / sizeof(T), + "trying to move an impossible number of elements"); + memmove(aDst, aSrc, aNElem * sizeof(T)); +} + +/** + * Determine whether the |len| elements at |one| are memory-identical to the + * |len| elements at |two|. + */ +template +static MOZ_ALWAYS_INLINE bool +PodEqual(const T* one, const T* two, size_t len) +{ + if (len < 128) { + const T* p1end = one + len; + const T* p1 = one; + const T* p2 = two; + for (; p1 < p1end; p1++, p2++) { + if (*p1 != *p2) { + return false; + } + } + return true; + } + + return !memcmp(one, two, len * sizeof(T)); +} + +} // namespace mozilla + +#endif /* mozilla_PodOperations_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Poison.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Poison.h new file mode 100644 index 0000000000..75e0f081cd --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Poison.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * A poison value that can be used to fill a memory space with + * an address that leads to a safe crash when dereferenced. + */ + +#ifndef mozilla_Poison_h +#define mozilla_Poison_h + +#include "mozilla/Assertions.h" +#include "mozilla/Types.h" + +#include + +MOZ_BEGIN_EXTERN_C + +extern MFBT_DATA uintptr_t gMozillaPoisonValue; + +/** + * @return the poison value. + */ +inline uintptr_t mozPoisonValue() +{ + return gMozillaPoisonValue; +} + +/** + * Overwrite the memory block of aSize bytes at aPtr with the poison value. + * aPtr MUST be aligned at a sizeof(uintptr_t) boundary. + * Only an even number of sizeof(uintptr_t) bytes are overwritten, the last + * few bytes (if any) is not overwritten. + */ +inline void mozWritePoison(void* aPtr, size_t aSize) +{ + const uintptr_t POISON = mozPoisonValue(); + char* p = (char*)aPtr; + char* limit = p + aSize; + MOZ_ASSERT((uintptr_t)aPtr % sizeof(uintptr_t) == 0, "bad alignment"); + MOZ_ASSERT(aSize >= sizeof(uintptr_t), "poisoning this object has no effect"); + for (; p < limit; p += sizeof(uintptr_t)) { + *((uintptr_t*)p) = POISON; + } +} + +/** + * Initialize the poison value. + * This should only be called once. + */ +extern MFBT_API void mozPoisonValueInit(); + +/* Values annotated by CrashReporter */ +extern MFBT_DATA uintptr_t gMozillaPoisonBase; +extern MFBT_DATA uintptr_t gMozillaPoisonSize; + +MOZ_END_EXTERN_C + +#endif /* mozilla_Poison_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Range.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Range.h new file mode 100644 index 0000000000..814a2821ad --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Range.h @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_Range_h +#define mozilla_Range_h + +#include "mozilla/NullPtr.h" +#include "mozilla/RangedPtr.h" + +#include + +namespace mozilla { + +// Range is a tuple containing a pointer and a length. +template +class Range +{ + const RangedPtr mStart; + const RangedPtr mEnd; + + typedef void (Range::* ConvertibleToBool)(); + void nonNull() {} + +public: + Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} + Range(T* aPtr, size_t aLength) + : mStart(aPtr, aPtr, aPtr + aLength), + mEnd(aPtr + aLength, aPtr, aPtr + aLength) + {} + + RangedPtr start() const { return mStart; } + RangedPtr end() const { return mEnd; } + size_t length() const { return mEnd - mStart; } + + T& operator[](size_t aOffset) const { return mStart[aOffset]; } + + operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } +}; + +} // namespace mozilla + +#endif /* mozilla_Range_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/RangedPtr.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/RangedPtr.h new file mode 100644 index 0000000000..4d94035b90 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/RangedPtr.h @@ -0,0 +1,284 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Implements a smart pointer asserted to remain within a range specified at + * construction. + */ + +#ifndef mozilla_RangedPtr_h +#define mozilla_RangedPtr_h + +#include "mozilla/ArrayUtils.h" +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" + +#include + +namespace mozilla { + +/* + * RangedPtr is a smart pointer restricted to an address range specified at + * creation. The pointer (and any smart pointers derived from it) must remain + * within the range [start, end] (inclusive of end to facilitate use as + * sentinels). Dereferencing or indexing into the pointer (or pointers derived + * from it) must remain within the range [start, end). All the standard pointer + * operators are defined on it; in debug builds these operations assert that the + * range specified at construction is respected. + * + * In theory passing a smart pointer instance as an argument can be slightly + * slower than passing a T* (due to ABI requirements for passing structs versus + * passing pointers), if the method being called isn't inlined. If you are in + * extremely performance-critical code, you may want to be careful using this + * smart pointer as an argument type. + * + * RangedPtr intentionally does not implicitly convert to T*. Use get() to + * explicitly convert to T*. Keep in mind that the raw pointer of course won't + * implement bounds checking in debug builds. + */ +template +class RangedPtr +{ + T* mPtr; + +#ifdef DEBUG + T* const mRangeStart; + T* const mRangeEnd; +#endif + + typedef void (RangedPtr::* ConvertibleToBool)(); + void nonNull() {} + + void checkSanity() + { + MOZ_ASSERT(mRangeStart <= mPtr); + MOZ_ASSERT(mPtr <= mRangeEnd); + } + + /* Creates a new pointer for |aPtr|, restricted to this pointer's range. */ + RangedPtr create(T* aPtr) const + { +#ifdef DEBUG + return RangedPtr(aPtr, mRangeStart, mRangeEnd); +#else + return RangedPtr(aPtr, nullptr, size_t(0)); +#endif + } + + uintptr_t asUintptr() const { return reinterpret_cast(mPtr); } + +public: + RangedPtr(T* aPtr, T* aStart, T* aEnd) + : mPtr(aPtr) +#ifdef DEBUG + , mRangeStart(aStart), mRangeEnd(aEnd) +#endif + { + MOZ_ASSERT(mRangeStart <= mRangeEnd); + checkSanity(); + } + RangedPtr(T* aPtr, T* aStart, size_t aLength) + : mPtr(aPtr) +#ifdef DEBUG + , mRangeStart(aStart), mRangeEnd(aStart + aLength) +#endif + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aPtr, aPtr, aLength). */ + RangedPtr(T* aPtr, size_t aLength) + : mPtr(aPtr) +#ifdef DEBUG + , mRangeStart(aPtr), mRangeEnd(aPtr + aLength) +#endif + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } + + /* Equivalent to RangedPtr(aArr, aArr, N). */ + template + RangedPtr(T (&aArr)[N]) + : mPtr(aArr) +#ifdef DEBUG + , mRangeStart(aArr), mRangeEnd(aArr + N) +#endif + { + checkSanity(); + } + + T* get() const { return mPtr; } + + operator ConvertibleToBool() const { return mPtr ? &RangedPtr::nonNull : 0; } + + /* + * You can only assign one RangedPtr into another if the two pointers have + * the same valid range: + * + * char arr1[] = "hi"; + * char arr2[] = "bye"; + * RangedPtr p1(arr1, 2); + * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works + * p1 = RangedPtr(arr2, 3); // asserts + */ + RangedPtr& operator=(const RangedPtr& aOther) + { + MOZ_ASSERT(mRangeStart == aOther.mRangeStart); + MOZ_ASSERT(mRangeEnd == aOther.mRangeEnd); + mPtr = aOther.mPtr; + checkSanity(); + return *this; + } + + RangedPtr operator+(size_t aInc) + { + MOZ_ASSERT(aInc <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() + aInc * sizeof(T) >= asUintptr()); + return create(mPtr + aInc); + } + + RangedPtr operator-(size_t aDec) + { + MOZ_ASSERT(aDec <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() - aDec * sizeof(T) <= asUintptr()); + return create(mPtr - aDec); + } + + /* + * You can assign a raw pointer into a RangedPtr if the raw pointer is + * within the range specified at creation. + */ + template + RangedPtr& operator=(U* aPtr) + { + *this = create(aPtr); + return *this; + } + + template + RangedPtr& operator=(const RangedPtr& aPtr) + { + MOZ_ASSERT(mRangeStart <= aPtr.mPtr); + MOZ_ASSERT(aPtr.mPtr <= mRangeEnd); + mPtr = aPtr.mPtr; + checkSanity(); + return *this; + } + + RangedPtr& operator++() + { + return (*this += 1); + } + + RangedPtr operator++(int) + { + RangedPtr rcp = *this; + ++*this; + return rcp; + } + + RangedPtr& operator--() + { + return (*this -= 1); + } + + RangedPtr operator--(int) + { + RangedPtr rcp = *this; + --*this; + return rcp; + } + + RangedPtr& operator+=(size_t aInc) + { + *this = *this + aInc; + return *this; + } + + RangedPtr& operator-=(size_t aDec) + { + *this = *this - aDec; + return *this; + } + + T& operator[](int aIndex) const + { + MOZ_ASSERT(size_t(aIndex > 0 ? aIndex : -aIndex) <= size_t(-1) / sizeof(T)); + return *create(mPtr + aIndex); + } + + T& operator*() const + { + MOZ_ASSERT(mPtr >= mRangeStart); + MOZ_ASSERT(mPtr < mRangeEnd); + return *mPtr; + } + + template + bool operator==(const RangedPtr& aOther) const + { + return mPtr == aOther.mPtr; + } + template + bool operator!=(const RangedPtr& aOther) const + { + return !(*this == aOther); + } + + template + bool operator==(const U* u) const + { + return mPtr == u; + } + template + bool operator!=(const U* u) const + { + return !(*this == u); + } + + template + bool operator<(const RangedPtr& aOther) const + { + return mPtr < aOther.mPtr; + } + template + bool operator<=(const RangedPtr& aOther) const + { + return mPtr <= aOther.mPtr; + } + + template + bool operator>(const RangedPtr& aOther) const + { + return mPtr > aOther.mPtr; + } + template + bool operator>=(const RangedPtr& aOther) const + { + return mPtr >= aOther.mPtr; + } + + size_t operator-(const RangedPtr& aOther) const + { + MOZ_ASSERT(mPtr >= aOther.mPtr); + return PointerRangeSize(aOther.mPtr, mPtr); + } + +private: + RangedPtr() MOZ_DELETE; + T* operator&() MOZ_DELETE; +}; + +} /* namespace mozilla */ + +#endif /* mozilla_RangedPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/ReentrancyGuard.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/ReentrancyGuard.h new file mode 100644 index 0000000000..557c61015e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/ReentrancyGuard.h @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Small helper class for asserting uses of a class are non-reentrant. */ + +#ifndef mozilla_ReentrancyGuard_h +#define mozilla_ReentrancyGuard_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/GuardObjects.h" + +namespace mozilla { + +/* Useful for implementing containers that assert non-reentrancy */ +class ReentrancyGuard +{ + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +#ifdef DEBUG + bool& mEntered; +#endif + +public: + template +#ifdef DEBUG + ReentrancyGuard(T& aObj + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mEntered(aObj.mEntered) +#else + ReentrancyGuard(T& + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) +#endif + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; +#ifdef DEBUG + MOZ_ASSERT(!mEntered); + mEntered = true; +#endif + } + ~ReentrancyGuard() + { +#ifdef DEBUG + mEntered = false; +#endif + } + +private: + ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; + void operator=(const ReentrancyGuard&) MOZ_DELETE; +}; + +} // namespace mozilla + +#endif /* mozilla_ReentrancyGuard_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/RefPtr.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/RefPtr.h new file mode 100644 index 0000000000..4901067b4c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/RefPtr.h @@ -0,0 +1,552 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Helpers for defining and using refcounted objects. */ + +#ifndef mozilla_RefPtr_h +#define mozilla_RefPtr_h + +#include "mozilla/Assertions.h" +#include "mozilla/Atomics.h" +#include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" +#include "mozilla/RefCountType.h" +#include "mozilla/TypeTraits.h" +#if defined(MOZILLA_INTERNAL_API) +#include "nsXPCOM.h" +#endif + +#if defined(MOZILLA_INTERNAL_API) && \ + (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) +#define MOZ_REFCOUNTED_LEAK_CHECKING +#endif + +namespace mozilla { + +template class RefCounted; +template class RefPtr; +template class TemporaryRef; +template class OutParamRef; +template OutParamRef byRef(RefPtr&); + +/** + * RefCounted is a sort of a "mixin" for a class T. RefCounted + * manages, well, refcounting for T, and because RefCounted is + * parameterized on T, RefCounted can call T's destructor directly. + * This means T doesn't need to have a virtual dtor and so doesn't + * need a vtable. + * + * RefCounted is created with refcount == 0. Newly-allocated + * RefCounted must immediately be assigned to a RefPtr to make the + * refcount > 0. It's an error to allocate and free a bare + * RefCounted, i.e. outside of the RefPtr machinery. Attempts to + * do so will abort DEBUG builds. + * + * Live RefCounted have refcount > 0. The lifetime (refcounts) of + * live RefCounted are controlled by RefPtr and + * RefPtr. Upon a transition from refcounted==1 + * to 0, the RefCounted "dies" and is destroyed. The "destroyed" + * state is represented in DEBUG builds by refcount==0xffffdead. This + * state distinguishes use-before-ref (refcount==0) from + * use-after-destroy (refcount==0xffffdead). + * + * Note that when deriving from RefCounted or AtomicRefCounted, you + * should add MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public + * section of your class, where ClassName is the name of your class. + */ +namespace detail { +#ifdef DEBUG +const MozRefCountType DEAD = 0xffffdead; +#endif + +// When building code that gets compiled into Gecko, try to use the +// trace-refcount leak logging facilities. +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +class RefCountLogger +{ +public: + static void logAddRef(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName, uint32_t aInstanceSize) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogAddRef(const_cast(aPointer), aRefCount, aTypeName, + aInstanceSize); + } + + static void logRelease(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogRelease(const_cast(aPointer), aRefCount, aTypeName); + } +}; +#endif + +// This is used WeakPtr.h as well as this file. +enum RefCountAtomicity +{ + AtomicRefCount, + NonAtomicRefCount +}; + +template +class RefCounted +{ + friend class RefPtr; + +protected: + RefCounted() : mRefCnt(0) {} + ~RefCounted() { MOZ_ASSERT(mRefCnt == detail::DEAD); } + +public: + // Compatibility with nsRefPtr. + void AddRef() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) >= 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + ++mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + uint32_t size = static_cast(this)->typeSize(); + const void* ptr = static_cast(this); + MozRefCountType cnt = ++mRefCnt; + detail::RefCountLogger::logAddRef(ptr, cnt, type, size); +#endif + } + + void Release() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) > 0); +#ifndef MOZ_REFCOUNTED_LEAK_CHECKING + MozRefCountType cnt = --mRefCnt; +#else + const char* type = static_cast(this)->typeName(); + const void* ptr = static_cast(this); + MozRefCountType cnt = --mRefCnt; + // Note: it's not safe to touch |this| after decrementing the refcount, + // except for below. + detail::RefCountLogger::logRelease(ptr, cnt, type); +#endif + if (0 == cnt) { + // Because we have atomically decremented the refcount above, only + // one thread can get a 0 count here, so as long as we can assume that + // everything else in the system is accessing this object through + // RefPtrs, it's safe to access |this| here. +#ifdef DEBUG + mRefCnt = detail::DEAD; +#endif + delete static_cast(this); + } + } + + // Compatibility with wtf::RefPtr. + void ref() { AddRef(); } + void deref() { Release(); } + MozRefCountType refCount() const { return mRefCnt; } + bool hasOneRef() const + { + MOZ_ASSERT(mRefCnt > 0); + return mRefCnt == 1; + } + +private: + mutable typename Conditional, + MozRefCountType>::Type mRefCnt; +}; + +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) \ + virtual const char* typeName() const { return #T; } \ + virtual size_t typeSize() const { return sizeof(*this); } +#else +#define MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(T) +#endif + +// Note that this macro is expanded unconditionally because it declares only +// two small inline functions which will hopefully get eliminated by the linker +// in non-leak-checking builds. +#define MOZ_DECLARE_REFCOUNTED_TYPENAME(T) \ + const char* typeName() const { return #T; } \ + size_t typeSize() const { return sizeof(*this); } + +} // namespace detail + +template +class RefCounted : public detail::RefCounted +{ +public: + ~RefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from RefCounted"); + } +}; + +namespace external { + +/** + * AtomicRefCounted is like RefCounted, with an atomically updated + * reference counter. + * + * NOTE: Please do not use this class, use NS_INLINE_DECL_THREADSAFE_REFCOUNTING + * instead. + */ +template +class AtomicRefCounted : + public mozilla::detail::RefCounted +{ +public: + ~AtomicRefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from AtomicRefCounted"); + } +}; + +} // namespace external + +/** + * RefPtr points to a refcounted thing that has AddRef and Release + * methods to increase/decrease the refcount, respectively. After a + * RefPtr is assigned a T*, the T* can be used through the RefPtr + * as if it were a T*. + * + * A RefPtr can forget its underlying T*, which results in the T* + * being wrapped in a temporary object until the T* is either + * re-adopted from or released by the temporary. + */ +template +class RefPtr +{ + // To allow them to use unref() + friend class TemporaryRef; + friend class OutParamRef; + + struct DontRef {}; + +public: + RefPtr() : mPtr(0) {} + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.mPtr)) {} + MOZ_IMPLICIT RefPtr(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + MOZ_IMPLICIT RefPtr(T* aVal) : mPtr(ref(aVal)) {} + + template + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.get())) {} + + ~RefPtr() { unref(mPtr); } + + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.mPtr)); + return *this; + } + RefPtr& operator=(const TemporaryRef& aOther) + { + assign(aOther.drop()); + return *this; + } + RefPtr& operator=(T* aVal) + { + assign(ref(aVal)); + return *this; + } + + template + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.get())); + return *this; + } + + TemporaryRef forget() + { + T* tmp = mPtr; + mPtr = nullptr; + return TemporaryRef(tmp, DontRef()); + } + + T* get() const { return mPtr; } + operator T*() const { return mPtr; } + T* operator->() const { return mPtr; } + T& operator*() const { return *mPtr; } + template + operator TemporaryRef() { return TemporaryRef(mPtr); } + +private: + void assign(T* aVal) + { + unref(mPtr); + mPtr = aVal; + } + + T* mPtr; + + static MOZ_ALWAYS_INLINE T* ref(T* aVal) + { + if (aVal) { + aVal->AddRef(); + } + return aVal; + } + + static MOZ_ALWAYS_INLINE void unref(T* aVal) + { + if (aVal) { + aVal->Release(); + } + } +}; + +/** + * TemporaryRef represents an object that holds a temporary + * reference to a T. TemporaryRef objects can't be manually ref'd or + * unref'd (being temporaries, not lvalues), so can only relinquish + * references to other objects, or unref on destruction. + */ +template +class TemporaryRef +{ + // To allow it to construct TemporaryRef from a bare T* + friend class RefPtr; + + typedef typename RefPtr::DontRef DontRef; + +public: + MOZ_IMPLICIT TemporaryRef(T* aVal) : mPtr(RefPtr::ref(aVal)) {} + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + + template + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + + ~TemporaryRef() { RefPtr::unref(mPtr); } + + T* drop() const + { + T* tmp = mPtr; + mPtr = nullptr; + return tmp; + } + +private: + TemporaryRef(T* aVal, const DontRef&) : mPtr(aVal) {} + + mutable T* mPtr; + + TemporaryRef() MOZ_DELETE; + void operator=(const TemporaryRef&) MOZ_DELETE; +}; + +/** + * OutParamRef is a wrapper that tracks a refcounted pointer passed as + * an outparam argument to a function. OutParamRef implements COM T** + * outparam semantics: this requires the callee to AddRef() the T* + * returned through the T** outparam on behalf of the caller. This + * means the caller (through OutParamRef) must Release() the old + * object contained in the tracked RefPtr. It's OK if the callee + * returns the same T* passed to it through the T** outparam, as long + * as the callee obeys the COM discipline. + * + * Prefer returning TemporaryRef from functions over creating T** + * outparams and passing OutParamRef to T**. Prefer RefPtr* + * outparams over T** outparams. + */ +template +class OutParamRef +{ + friend OutParamRef byRef(RefPtr&); + +public: + ~OutParamRef() + { + RefPtr::unref(mRefPtr.mPtr); + mRefPtr.mPtr = mTmp; + } + + operator T**() { return &mTmp; } + +private: + explicit OutParamRef(RefPtr& p) : mRefPtr(p), mTmp(p.get()) {} + + RefPtr& mRefPtr; + T* mTmp; + + OutParamRef() MOZ_DELETE; + OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; +}; + +/** + * byRef cooperates with OutParamRef to implement COM outparam semantics. + */ +template +OutParamRef +byRef(RefPtr& aPtr) +{ + return OutParamRef(aPtr); +} + +} // namespace mozilla + +#if 0 + +// Command line that builds these tests +// +// cp RefPtr.h test.cc && g++ -g -Wall -pedantic -DDEBUG -o test test.cc && ./test + +using namespace mozilla; + +struct Foo : public RefCounted +{ + MOZ_DECLARE_REFCOUNTED_TYPENAME(Foo) + Foo() : mDead(false) {} + ~Foo() + { + MOZ_ASSERT(!mDead); + mDead = true; + sNumDestroyed++; + } + + bool mDead; + static int sNumDestroyed; +}; +int Foo::sNumDestroyed; + +struct Bar : public Foo {}; + +TemporaryRef +NewFoo() +{ + return RefPtr(new Foo()); +} + +TemporaryRef +NewBar() +{ + return new Bar(); +} + +void +GetNewFoo(Foo** f) +{ + *f = new Bar(); + // Kids, don't try this at home + (*f)->AddRef(); +} + +void +GetPassedFoo(Foo** f) +{ + // Kids, don't try this at home + (*f)->AddRef(); +} + +void +GetNewFoo(RefPtr* f) +{ + *f = new Bar(); +} + +void +GetPassedFoo(RefPtr* f) +{} + +TemporaryRef +GetNullFoo() +{ + return 0; +} + +int +main(int argc, char** argv) +{ + // This should blow up +// Foo* f = new Foo(); delete f; + + MOZ_ASSERT(0 == Foo::sNumDestroyed); + { + RefPtr f = new Foo(); + MOZ_ASSERT(f->refCount() == 1); + } + MOZ_ASSERT(1 == Foo::sNumDestroyed); + + { + RefPtr f1 = NewFoo(); + RefPtr f2(NewFoo()); + MOZ_ASSERT(1 == Foo::sNumDestroyed); + } + MOZ_ASSERT(3 == Foo::sNumDestroyed); + + { + RefPtr b = NewBar(); + MOZ_ASSERT(3 == Foo::sNumDestroyed); + } + MOZ_ASSERT(4 == Foo::sNumDestroyed); + + { + RefPtr f1; + { + f1 = new Foo(); + RefPtr f2(f1); + RefPtr f3 = f2; + MOZ_ASSERT(4 == Foo::sNumDestroyed); + } + MOZ_ASSERT(4 == Foo::sNumDestroyed); + } + MOZ_ASSERT(5 == Foo::sNumDestroyed); + + { + RefPtr f = new Foo(); + f.forget(); + MOZ_ASSERT(6 == Foo::sNumDestroyed); + } + + { + RefPtr f = new Foo(); + GetNewFoo(byRef(f)); + MOZ_ASSERT(7 == Foo::sNumDestroyed); + } + MOZ_ASSERT(8 == Foo::sNumDestroyed); + + { + RefPtr f = new Foo(); + GetPassedFoo(byRef(f)); + MOZ_ASSERT(8 == Foo::sNumDestroyed); + } + MOZ_ASSERT(9 == Foo::sNumDestroyed); + + { + RefPtr f = new Foo(); + GetNewFoo(&f); + MOZ_ASSERT(10 == Foo::sNumDestroyed); + } + MOZ_ASSERT(11 == Foo::sNumDestroyed); + + { + RefPtr f = new Foo(); + GetPassedFoo(&f); + MOZ_ASSERT(11 == Foo::sNumDestroyed); + } + MOZ_ASSERT(12 == Foo::sNumDestroyed); + + { + RefPtr f1 = new Bar(); + } + MOZ_ASSERT(13 == Foo::sNumDestroyed); + + { + RefPtr f = GetNullFoo(); + MOZ_ASSERT(13 == Foo::sNumDestroyed); + } + MOZ_ASSERT(13 == Foo::sNumDestroyed); + + return 0; +} + +#endif + +#endif /* mozilla_RefPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/RollingMean.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/RollingMean.h new file mode 100644 index 0000000000..5add14c879 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/RollingMean.h @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A set abstraction for enumeration values. */ + +#ifndef mozilla_RollingMean_h_ +#define mozilla_RollingMean_h_ + +#include "mozilla/Assertions.h" +#include "mozilla/TypeTraits.h" +#include "mozilla/Vector.h" + +#include + +namespace mozilla { + +/** + * RollingMean calculates a rolling mean of the values it is given. It + * accumulates the total as values are added and removed. The second type + * argument S specifies the type of the total. This may need to be a bigger + * type in order to maintain that the sum of all values in the average doesn't + * exceed the maximum input value. + * + * WARNING: Float types are not supported due to rounding errors. + */ +template +class RollingMean +{ +private: + size_t mInsertIndex; + size_t mMaxValues; + Vector mValues; + S mTotal; + +public: + static_assert(!IsFloatingPoint::value, + "floating-point types are unsupported due to rounding " + "errors"); + + explicit RollingMean(size_t aMaxValues) + : mInsertIndex(0), + mMaxValues(aMaxValues), + mTotal(0) + { + MOZ_ASSERT(aMaxValues > 0); + } + + RollingMean& operator=(RollingMean&& aOther) + { + MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); + this->~RollingMean(); + new(this) RollingMean(aOther.mMaxValues); + mInsertIndex = aOther.mInsertIndex; + mTotal = aOther.mTotal; + mValues.swap(aOther.mValues); + return *this; + } + + /** + * Insert a value into the rolling mean. + */ + bool insert(T aValue) + { + MOZ_ASSERT(mValues.length() <= mMaxValues); + + if (mValues.length() == mMaxValues) { + mTotal = mTotal - mValues[mInsertIndex] + aValue; + mValues[mInsertIndex] = aValue; + } else { + if (!mValues.append(aValue)) { + return false; + } + mTotal = mTotal + aValue; + } + + mInsertIndex = (mInsertIndex + 1) % mMaxValues; + return true; + } + + /** + * Calculate the rolling mean. + */ + T mean() + { + MOZ_ASSERT(!empty()); + return T(mTotal / mValues.length()); + } + + bool empty() + { + return mValues.empty(); + } + + /** + * Remove all values from the rolling mean. + */ + void clear() + { + mValues.clear(); + mInsertIndex = 0; + mTotal = T(0); + } + + size_t maxValues() + { + return mMaxValues; + } +}; + +} // namespace mozilla + +#endif // mozilla_RollingMean_h_ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/SHA1.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/SHA1.h new file mode 100644 index 0000000000..ddccaa67e7 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/SHA1.h @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Simple class for computing SHA1. */ + +#ifndef mozilla_SHA1_h +#define mozilla_SHA1_h + +#include "mozilla/Types.h" + +#include +#include + +namespace mozilla { + +/** + * This class computes the SHA1 hash of a byte sequence, or of the concatenation + * of multiple sequences. For example, computing the SHA1 of two sequences of + * bytes could be done as follows: + * + * void SHA1(const uint8_t* buf1, uint32_t size1, + * const uint8_t* buf2, uint32_t size2, + * SHA1Sum::Hash& hash) + * { + * SHA1Sum s; + * s.update(buf1, size1); + * s.update(buf2, size2); + * s.finish(hash); + * } + * + * The finish method may only be called once and cannot be followed by calls + * to update. + */ +class SHA1Sum +{ + union + { + uint32_t mW[16]; /* input buffer */ + uint8_t mB[64]; + } mU; + uint64_t mSize; /* count of hashed bytes. */ + unsigned mH[22]; /* 5 state variables, 16 tmp values, 1 extra */ + bool mDone; + +public: + MFBT_API SHA1Sum(); + + static const size_t kHashSize = 20; + typedef uint8_t Hash[kHashSize]; + + /* Add len bytes of dataIn to the data sequence being hashed. */ + MFBT_API void update(const void* aData, uint32_t aLength); + + /* Compute the final hash of all data into hashOut. */ + MFBT_API void finish(SHA1Sum::Hash& aHashOut); +}; + +} /* namespace mozilla */ + +#endif /* mozilla_SHA1_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Scoped.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Scoped.h new file mode 100644 index 0000000000..3f854d6375 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Scoped.h @@ -0,0 +1,308 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A number of structures to simplify scope-based RAII management. */ + +#ifndef mozilla_Scoped_h +#define mozilla_Scoped_h + +/* + * Resource Acquisition Is Initialization is a programming idiom used + * to write robust code that is able to deallocate resources properly, + * even in presence of execution errors or exceptions that need to be + * propagated. The Scoped* classes defined in this header perform the + * deallocation of the resource they hold once program execution + * reaches the end of the scope for which they have been defined. + * + * This header provides the following RAII classes: + * + * - |ScopedFreePtr| - a container for a pointer, that automatically calls + * |free()| at the end of the scope; + * - |ScopedDeletePtr| - a container for a pointer, that automatically calls + * |delete| at the end of the scope; + * - |ScopedDeleteArray| - a container for a pointer to an array, that + * automatically calls |delete[]| at the end of the scope. + * + * The general scenario for each of the RAII classes is the following: + * + * ScopedClass foo(create_value()); + * // ... In this scope, |foo| is defined. Use |foo.get()| or |foo.rwget()| + * to access the value. + * // ... In case of |return| or |throw|, |foo| is deallocated automatically. + * // ... If |foo| needs to be returned or stored, use |foo.forget()| + * + * Note that the RAII classes defined in this header do _not_ perform any form + * of reference-counting or garbage-collection. These classes have exactly two + * behaviors: + * + * - if |forget()| has not been called, the resource is always deallocated at + * the end of the scope; + * - if |forget()| has been called, any control on the resource is unbound + * and the resource is not deallocated by the class. + * + * Extension: + * + * In addition, this header provides class |Scoped| and macros |SCOPED_TEMPLATE| + * and |MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE| to simplify the definition + * of RAII classes for other scenarios. These macros have been used to + * automatically close file descriptors/file handles when reaching the end of + * the scope, graphics contexts, etc. + */ + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/GuardObjects.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" + +namespace mozilla { + +/* + * Scoped is a helper to create RAII wrappers + * Type argument |Traits| is expected to have the following structure: + * + * struct Traits + * { + * // Define the type of the value stored in the wrapper + * typedef value_type type; + * // Returns the value corresponding to the uninitialized or freed state + * const static type empty(); + * // Release resources corresponding to the wrapped value + * // This function is responsible for not releasing an |empty| value + * const static void release(type); + * } + */ +template +class Scoped +{ +public: + typedef typename Traits::type Resource; + + explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + : mValue(Traits::empty()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + explicit Scoped(const Resource& aValue + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(aValue) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } + + /* Move constructor. */ + explicit Scoped(Scoped&& aOther + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(Move(aOther.mValue)) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + aOther.mValue = Traits::empty(); + } + + ~Scoped() { Traits::release(mValue); } + + // Constant getter + operator const Resource&() const { return mValue; } + const Resource& operator->() const { return mValue; } + const Resource& get() const { return mValue; } + // Non-constant getter. + Resource& rwget() { return mValue; } + + /* + * Forget the resource. + * + * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will + * have no effect at destruction (unless it is reset to another resource by + * |operator=|). + * + * @return The original resource. + */ + Resource forget() + { + Resource tmp = mValue; + mValue = Traits::empty(); + return tmp; + } + + /* + * Perform immediate clean-up of this |Scoped|. + * + * If this |Scoped| is currently empty, this method has no effect. + */ + void dispose() + { + Traits::release(mValue); + mValue = Traits::empty(); + } + + bool operator==(const Resource& aOther) const { return mValue == aOther; } + + /* + * Replace the resource with another resource. + * + * Calling |operator=| has the side-effect of triggering clean-up. If you do + * not want to trigger clean-up, you should first invoke |forget|. + * + * @return this + */ + Scoped& operator=(const Resource& aOther) { return reset(aOther); } + + Scoped& reset(const Resource& aOther) + { + Traits::release(mValue); + mValue = aOther; + return *this; + } + + /* Move assignment operator. */ + Scoped& operator=(Scoped&& aRhs) + { + MOZ_ASSERT(&aRhs != this, "self-move-assignment not allowed"); + this->~Scoped(); + new(this) Scoped(Move(aRhs)); + return *this; + } + +private: + explicit Scoped(const Scoped& aValue) MOZ_DELETE; + Scoped& operator=(const Scoped& aValue) MOZ_DELETE; + +private: + Resource mValue; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + +/* + * SCOPED_TEMPLATE defines a templated class derived from Scoped + * This allows to implement templates such as ScopedFreePtr. + * + * @param name The name of the class to define. + * @param Traits A struct implementing clean-up. See the implementations + * for more details. + */ +#define SCOPED_TEMPLATE(name, Traits) \ +template \ +struct name : public mozilla::Scoped > \ +{ \ + typedef mozilla::Scoped > Super; \ + typedef typename Super::Resource Resource; \ + name& operator=(Resource aRhs) \ + { \ + Super::operator=(aRhs); \ + return *this; \ + } \ + name& operator=(name&& aRhs) \ + { \ + Super::operator=(Move(aRhs)); \ + return *this; \ + } \ + explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ + : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ + {} \ + explicit name(Resource aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ + explicit name(name&& aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(Move(aRhs) \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ +private: \ + explicit name(name&) MOZ_DELETE; \ + name& operator=(name&) MOZ_DELETE; \ +}; + +/* + * ScopedFreePtr is a RAII wrapper for pointers that need to be free()d. + * + * struct S { ... }; + * ScopedFreePtr foo = malloc(sizeof(S)); + * ScopedFreePtr bar = strdup(str); + */ +template +struct ScopedFreePtrTraits +{ + typedef T* type; + static T* empty() { return nullptr; } + static void release(T* aPtr) { free(aPtr); } +}; +SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) + +/* + * ScopedDeletePtr is a RAII wrapper for pointers that need to be deleted. + * + * struct S { ... }; + * ScopedDeletePtr foo = new S(); + */ +template +struct ScopedDeletePtrTraits : public ScopedFreePtrTraits +{ + static void release(T* aPtr) { delete aPtr; } +}; +SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) + +/* + * ScopedDeleteArray is a RAII wrapper for pointers that need to be delete[]ed. + * + * struct S { ... }; + * ScopedDeleteArray foo = new S[42]; + */ +template +struct ScopedDeleteArrayTraits : public ScopedFreePtrTraits +{ + static void release(T* aPtr) { delete [] aPtr; } +}; +SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) + +/* + * MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE makes it easy to create scoped + * pointers for types with custom deleters; just overload + * TypeSpecificDelete(T*) in the same namespace as T to call the deleter for + * type T. + * + * @param name The name of the class to define. + * @param Type A struct implementing clean-up. See the implementations + * for more details. + * *param Deleter The function that is used to delete/destroy/free a + * non-null value of Type*. + * + * Example: + * + * MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(ScopedPRFileDesc, PRFileDesc, \ + * PR_Close) + * ... + * { + * ScopedPRFileDesc file(PR_OpenFile(...)); + * ... + * } // file is closed with PR_Close here + */ +#define MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(name, Type, Deleter) \ +template <> inline void TypeSpecificDelete(Type* aValue) { Deleter(aValue); } \ +typedef ::mozilla::TypeSpecificScopedPointer name; + +template void TypeSpecificDelete(T* aValue); + +template +struct TypeSpecificScopedPointerTraits +{ + typedef T* type; + static type empty() { return nullptr; } + static void release(type aValue) + { + if (aValue) { + TypeSpecificDelete(aValue); + } + } +}; + +SCOPED_TEMPLATE(TypeSpecificScopedPointer, TypeSpecificScopedPointerTraits) + +} /* namespace mozilla */ + +#endif /* mozilla_Scoped_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/SplayTree.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/SplayTree.h new file mode 100644 index 0000000000..a6d692266f --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/SplayTree.h @@ -0,0 +1,296 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * A sorted tree with optimal access times, where recently-accessed elements + * are faster to access again. + */ + +#ifndef mozilla_SplayTree_h +#define mozilla_SplayTree_h + +#include "mozilla/Assertions.h" +#include "mozilla/NullPtr.h" + +namespace mozilla { + +template +class SplayTree; + +template +class SplayTreeNode +{ +public: + template + friend class SplayTree; + + SplayTreeNode() + : mLeft(nullptr) + , mRight(nullptr) + , mParent(nullptr) + {} + +private: + T* mLeft; + T* mRight; + T* mParent; +}; + + +/** + * Class which represents a splay tree. + * Splay trees are balanced binary search trees for which search, insert and + * remove are all amortized O(log n), but where accessing a node makes it + * faster to access that node in the future. + * + * T indicates the type of tree elements, Comparator must have a static + * compare(const T&, const T&) method ordering the elements. The compare + * method must be free from side effects. + */ +template +class SplayTree +{ + T* mRoot; + +public: + SplayTree() + : mRoot(nullptr) + {} + + bool empty() const + { + return !mRoot; + } + + T* find(const T& aValue) + { + if (empty()) { + return nullptr; + } + + T* last = lookup(aValue); + splay(last); + checkCoherency(mRoot, nullptr); + return Comparator::compare(aValue, *last) == 0 ? last : nullptr; + } + + bool insert(T* aValue) + { + MOZ_ASSERT(!find(*aValue), "Duplicate elements are not allowed."); + + if (!mRoot) { + mRoot = aValue; + return true; + } + T* last = lookup(*aValue); + int cmp = Comparator::compare(*aValue, *last); + + T** parentPointer = (cmp < 0) ? &last->mLeft : &last->mRight; + MOZ_ASSERT(!*parentPointer); + *parentPointer = aValue; + aValue->mParent = last; + + splay(aValue); + checkCoherency(mRoot, nullptr); + return true; + } + + T* remove(const T& aValue) + { + T* last = lookup(aValue); + MOZ_ASSERT(last, "This tree must contain the element being removed."); + MOZ_ASSERT(Comparator::compare(aValue, *last) == 0); + + // Splay the tree so that the item to remove is the root. + splay(last); + MOZ_ASSERT(last == mRoot); + + // Find another node which can be swapped in for the root: either the + // rightmost child of the root's left, or the leftmost child of the + // root's right. + T* swap; + T* swapChild; + if (mRoot->mLeft) { + swap = mRoot->mLeft; + while (swap->mRight) { + swap = swap->mRight; + } + swapChild = swap->mLeft; + } else if (mRoot->mRight) { + swap = mRoot->mRight; + while (swap->mLeft) { + swap = swap->mLeft; + } + swapChild = swap->mRight; + } else { + T* result = mRoot; + mRoot = nullptr; + return result; + } + + // The selected node has at most one child, in swapChild. Detach it + // from the subtree by replacing it with that child. + if (swap == swap->mParent->mLeft) { + swap->mParent->mLeft = swapChild; + } else { + swap->mParent->mRight = swapChild; + } + if (swapChild) { + swapChild->mParent = swap->mParent; + } + + // Make the selected node the new root. + mRoot = swap; + mRoot->mParent = nullptr; + mRoot->mLeft = last->mLeft; + mRoot->mRight = last->mRight; + if (mRoot->mLeft) { + mRoot->mLeft->mParent = mRoot; + } + if (mRoot->mRight) { + mRoot->mRight->mParent = mRoot; + } + + checkCoherency(mRoot, nullptr); + return last; + } + + T* removeMin() + { + MOZ_ASSERT(mRoot, "No min to remove!"); + + T* min = mRoot; + while (min->mLeft) { + min = min->mLeft; + } + return remove(*min); + } + +private: + /** + * Returns the node in this comparing equal to |aValue|, or a node just + * greater or just less than |aValue| if there is no such node. + */ + T* lookup(const T& aValue) + { + MOZ_ASSERT(!empty()); + + T* node = mRoot; + T* parent; + do { + parent = node; + int c = Comparator::compare(aValue, *node); + if (c == 0) { + return node; + } else if (c < 0) { + node = node->mLeft; + } else { + node = node->mRight; + } + } while (node); + return parent; + } + + /** + * Rotate the tree until |node| is at the root of the tree. Performing + * the rotations in this fashion preserves the amortized balancing of + * the tree. + */ + void splay(T* aNode) + { + MOZ_ASSERT(aNode); + + while (aNode != mRoot) { + T* parent = aNode->mParent; + if (parent == mRoot) { + // Zig rotation. + rotate(aNode); + MOZ_ASSERT(aNode == mRoot); + return; + } + T* grandparent = parent->mParent; + if ((parent->mLeft == aNode) == (grandparent->mLeft == parent)) { + // Zig-zig rotation. + rotate(parent); + rotate(aNode); + } else { + // Zig-zag rotation. + rotate(aNode); + rotate(aNode); + } + } + } + + void rotate(T* aNode) + { + // Rearrange nodes so that aNode becomes the parent of its current + // parent, while preserving the sortedness of the tree. + T* parent = aNode->mParent; + if (parent->mLeft == aNode) { + // x y + // y c ==> a x + // a b b c + parent->mLeft = aNode->mRight; + if (aNode->mRight) { + aNode->mRight->mParent = parent; + } + aNode->mRight = parent; + } else { + MOZ_ASSERT(parent->mRight == aNode); + // x y + // a y ==> x c + // b c a b + parent->mRight = aNode->mLeft; + if (aNode->mLeft) { + aNode->mLeft->mParent = parent; + } + aNode->mLeft = parent; + } + aNode->mParent = parent->mParent; + parent->mParent = aNode; + if (T* grandparent = aNode->mParent) { + if (grandparent->mLeft == parent) { + grandparent->mLeft = aNode; + } else { + grandparent->mRight = aNode; + } + } else { + mRoot = aNode; + } + } + + T* checkCoherency(T* aNode, T* aMinimum) + { +#ifdef DEBUG + MOZ_ASSERT_IF(mRoot, !mRoot->mParent); + if (!aNode) { + MOZ_ASSERT(!mRoot); + return nullptr; + } + MOZ_ASSERT_IF(!aNode->mParent, aNode == mRoot); + MOZ_ASSERT_IF(aMinimum, Comparator::compare(*aMinimum, *aNode) < 0); + if (aNode->mLeft) { + MOZ_ASSERT(aNode->mLeft->mParent == aNode); + T* leftMaximum = checkCoherency(aNode->mLeft, aMinimum); + MOZ_ASSERT(Comparator::compare(*leftMaximum, *aNode) < 0); + } + if (aNode->mRight) { + MOZ_ASSERT(aNode->mRight->mParent == aNode); + return checkCoherency(aNode->mRight, aNode); + } + return aNode; +#else + return nullptr; +#endif + } + + SplayTree(const SplayTree&) MOZ_DELETE; + void operator=(const SplayTree&) MOZ_DELETE; +}; + +} /* namespace mozilla */ + +#endif /* mozilla_SplayTree_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/TemplateLib.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/TemplateLib.h new file mode 100644 index 0000000000..ea12c18b2b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/TemplateLib.h @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Reusable template meta-functions on types and compile-time values. Meta- + * functions are placed inside the 'tl' namespace to avoid conflict with non- + * meta functions of the same name (e.g., mozilla::tl::FloorLog2 vs. + * mozilla::FloorLog2). + * + * When constexpr support becomes universal, we should probably use that instead + * of some of these templates, for simplicity. + */ + +#ifndef mozilla_TemplateLib_h +#define mozilla_TemplateLib_h + +#include +#include + +namespace mozilla { + +namespace tl { + +/** Compute min/max. */ +template +struct Min +{ + static const size_t value = I < J ? I : J; +}; +template +struct Max +{ + static const size_t value = I > J ? I : J; +}; + +/** Compute floor(log2(i)). */ +template +struct FloorLog2 +{ + static const size_t value = 1 + FloorLog2::value; +}; +template<> struct FloorLog2<0> { /* Error */ }; +template<> struct FloorLog2<1> { static const size_t value = 0; }; + +/** Compute ceiling(log2(i)). */ +template +struct CeilingLog2 +{ + static const size_t value = FloorLog2<2 * I - 1>::value; +}; + +/** Round up to the nearest power of 2. */ +template +struct RoundUpPow2 +{ + static const size_t value = size_t(1) << CeilingLog2::value; +}; +template<> +struct RoundUpPow2<0> +{ + static const size_t value = 1; +}; + +/** Compute the number of bits in the given unsigned type. */ +template +struct BitSize +{ + static const size_t value = sizeof(T) * CHAR_BIT; +}; + +/** + * Produce an N-bit mask, where N <= BitSize::value. Handle the + * language-undefined edge case when N = BitSize::value. + */ +template +struct NBitMask +{ + // Assert the precondition. On success this evaluates to 0. Otherwise it + // triggers divide-by-zero at compile time: a guaranteed compile error in + // C++11, and usually one in C++98. Add this value to |value| to assure + // its computation. + static const size_t checkPrecondition = + 0 / size_t(N < BitSize::value); + static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; +}; +template<> +struct NBitMask::value> +{ + static const size_t value = size_t(-1); +}; + +/** + * For the unsigned integral type size_t, compute a mask M for N such that + * for all X, !(X & M) implies X * N will not overflow (w.r.t size_t) + */ +template +struct MulOverflowMask +{ + static const size_t value = + ~NBitMask::value - CeilingLog2::value>::value; +}; +template<> struct MulOverflowMask<0> { /* Error */ }; +template<> struct MulOverflowMask<1> { static const size_t value = 0; }; + +} // namespace tl + +} // namespace mozilla + +#endif /* mozilla_TemplateLib_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/ThreadLocal.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/ThreadLocal.h new file mode 100644 index 0000000000..28015de22e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/ThreadLocal.h @@ -0,0 +1,151 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Cross-platform lightweight thread local data wrappers. */ + +#ifndef mozilla_ThreadLocal_h +#define mozilla_ThreadLocal_h + +#if defined(XP_WIN) +// This file will get included in any file that wants to add a profiler mark. +// In order to not bring together we could include windef.h and +// winbase.h which are sufficient to get the prototypes for the Tls* functions. +// # include +// # include +// Unfortunately, even including these headers causes us to add a bunch of ugly +// stuff to our namespace e.g #define CreateEvent CreateEventW +extern "C" { +__declspec(dllimport) void* __stdcall TlsGetValue(unsigned long); +__declspec(dllimport) int __stdcall TlsSetValue(unsigned long, void*); +__declspec(dllimport) unsigned long __stdcall TlsAlloc(); +} +#else +# include +# include +#endif + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" + +namespace mozilla { + +// sig_safe_t denotes an atomic type which can be read or stored in a single +// instruction. This means that data of this type is safe to be manipulated +// from a signal handler, or other similar asynchronous execution contexts. +#if defined(XP_WIN) +typedef unsigned long sig_safe_t; +#else +typedef sig_atomic_t sig_safe_t; +#endif + +/* + * Thread Local Storage helpers. + * + * Usage: + * + * Only static-storage-duration (e.g. global variables, or static class members) + * objects of this class should be instantiated. This class relies on + * zero-initialization, which is implicit for static-storage-duration objects. + * It doesn't have a custom default constructor, to avoid static initializers. + * + * API usage: + * + * // Create a TLS item. + * // + * // Note that init() should be invoked exactly once, before any usage of set() + * // or get(). + * mozilla::ThreadLocal tlsKey; + * if (!tlsKey.init()) { + * // deal with the error + * } + * + * // Set the TLS value + * tlsKey.set(123); + * + * // Get the TLS value + * int value = tlsKey.get(); + */ +template +class ThreadLocal +{ +#if defined(XP_WIN) + typedef unsigned long key_t; +#else + typedef pthread_key_t key_t; +#endif + + union Helper + { + void* mPtr; + T mValue; + }; + +public: + MOZ_WARN_UNUSED_RESULT inline bool init(); + + inline T get() const; + + inline void set(const T aValue); + + bool initialized() const { return mInited; } + +private: + key_t mKey; + bool mInited; +}; + +template +inline bool +ThreadLocal::init() +{ + static_assert(sizeof(T) <= sizeof(void*), + "mozilla::ThreadLocal can't be used for types larger than " + "a pointer"); + MOZ_ASSERT(!initialized()); +#ifdef XP_WIN + mKey = TlsAlloc(); + mInited = mKey != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES +#else + mInited = !pthread_key_create(&mKey, nullptr); +#endif + return mInited; +} + +template +inline T +ThreadLocal::get() const +{ + MOZ_ASSERT(initialized()); + Helper h; +#ifdef XP_WIN + h.mPtr = TlsGetValue(mKey); +#else + h.mPtr = pthread_getspecific(mKey); +#endif + return h.mValue; +} + +template +inline void +ThreadLocal::set(const T aValue) +{ + MOZ_ASSERT(initialized()); + Helper h; + h.mValue = aValue; +#ifdef XP_WIN + bool succeeded = TlsSetValue(mKey, h.mPtr); +#else + bool succeeded = !pthread_setspecific(mKey, h.mPtr); +#endif + if (!succeeded) { + MOZ_CRASH(); + } +} + +} // namespace mozilla + +#endif /* mozilla_ThreadLocal_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/TypeTraits.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/TypeTraits.h new file mode 100644 index 0000000000..515c68d94e --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/TypeTraits.h @@ -0,0 +1,998 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Template-based metaprogramming and type-testing facilities. */ + +#ifndef mozilla_TypeTraits_h +#define mozilla_TypeTraits_h + +#include "mozilla/Types.h" + +/* + * These traits are approximate copies of the traits and semantics from C++11's + * header. Don't add traits not in that header! When all + * platforms provide that header, we can convert all users and remove this one. + */ + +#include + +namespace mozilla { + +/* Forward declarations. */ + +template struct RemoveCV; + +/* 20.9.3 Helper classes [meta.help] */ + +/** + * Helper class used as a base for various type traits, exposed publicly + * because exposes it as well. + */ +template +struct IntegralConstant +{ + static const T value = Value; + typedef T ValueType; + typedef IntegralConstant Type; +}; + +/** Convenient aliases. */ +typedef IntegralConstant TrueType; +typedef IntegralConstant FalseType; + +/* 20.9.4 Unary type traits [meta.unary] */ + +/* 20.9.4.1 Primary type categories [meta.unary.cat] */ + +namespace detail { + +template +struct IsVoidHelper : FalseType {}; + +template<> +struct IsVoidHelper : TrueType {}; + +} // namespace detail + +/** + * IsVoid determines whether a type is void. + * + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true; + * mozilla::IsVoid::value is false; + * mozilla::IsVoid::value is true. + */ +template +struct IsVoid : detail::IsVoidHelper::Type> {}; + +namespace detail { + +template +struct IsIntegralHelper : FalseType {}; + +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +template<> struct IsIntegralHelper : TrueType {}; +#ifdef MOZ_CHAR16_IS_NOT_WCHAR +template<> struct IsIntegralHelper : TrueType {}; +#endif + +} /* namespace detail */ + +/** + * IsIntegral determines whether a type is an integral type. + * + * mozilla::IsIntegral::value is true; + * mozilla::IsIntegral::value is true; + * mozilla::IsIntegral::value is true; + * mozilla::IsIntegral::value is false; + * mozilla::IsIntegral::value is false; + * + * Note that the behavior of IsIntegral on char16_t and char32_t is + * unspecified. + */ +template +struct IsIntegral : detail::IsIntegralHelper::Type> +{}; + +template +struct IsSame; + +namespace detail { + +template +struct IsFloatingPointHelper + : IntegralConstant::value || + IsSame::value || + IsSame::value> +{}; + +} // namespace detail + +/** + * IsFloatingPoint determines whether a type is a floating point type (float, + * double, long double). + * + * mozilla::IsFloatingPoint::value is false; + * mozilla::IsFloatingPoint::value is true; + * mozilla::IsFloatingPoint::value is true; + * mozilla::IsFloatingPoint::value is false. + */ +template +struct IsFloatingPoint + : detail::IsFloatingPointHelper::Type> +{}; + +namespace detail { + +template +struct IsArrayHelper : FalseType {}; + +template +struct IsArrayHelper : TrueType {}; + +template +struct IsArrayHelper : TrueType {}; + +} // namespace detail + +/** + * IsArray determines whether a type is an array type, of known or unknown + * length. + * + * mozilla::IsArray::value is false; + * mozilla::IsArray::value is true; + * mozilla::IsArray::value is true. + */ +template +struct IsArray : detail::IsArrayHelper::Type> +{}; + +/** + * IsPointer determines whether a type is a pointer type (but not a pointer-to- + * member type). + * + * mozilla::IsPointer::value is true; + * mozilla::IsPointer::value is true; + * mozilla::IsPointer::value is true; + * mozilla::IsPointer::value is false; + * mozilla::IsPointer::value is false. + */ +template +struct IsPointer : FalseType {}; + +template +struct IsPointer : TrueType {}; + +/** + * IsLvalueReference determines whether a type is an lvalue reference. + * + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is false; + * mozilla::IsLvalueReference::value is true; + * mozilla::IsLvalueReference::value is false. + */ +template +struct IsLvalueReference : FalseType {}; + +template +struct IsLvalueReference : TrueType {}; + +/** + * IsRvalueReference determines whether a type is an rvalue reference. + * + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is false; + * mozilla::IsRvalueReference::value is true. + */ +template +struct IsRvalueReference : FalseType {}; + +template +struct IsRvalueReference : TrueType {}; + +namespace detail { + +// __is_enum is a supported extension across all of our supported compilers. +template +struct IsEnumHelper + : IntegralConstant +{}; + +} // namespace detail + +/** + * IsEnum determines whether a type is an enum type. + * + * mozilla::IsEnum::value is true; + * mozilla::IsEnum::value is false; + * mozilla::IsEnum::value is false; + */ +template +struct IsEnum + : detail::IsEnumHelper::Type> +{}; + +namespace detail { + +// __is_class is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx +template +struct IsClassHelper + : IntegralConstant +{}; + +} // namespace detail + +/** + * IsClass determines whether a type is a class type (but not a union). + * + * struct S {}; + * union U {}; + * mozilla::IsClass::value is false; + * mozilla::IsClass::value is true; + * mozilla::IsClass::value is false; + */ +template +struct IsClass + : detail::IsClassHelper::Type> +{}; + +/* 20.9.4.2 Composite type traits [meta.unary.comp] */ + +/** + * IsReference determines whether a type is an lvalue or rvalue reference. + * + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is false; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true; + * mozilla::IsReference::value is true. + */ +template +struct IsReference + : IntegralConstant::value || IsRvalueReference::value> +{}; + +/** + * IsArithmetic determines whether a type is arithmetic. A type is arithmetic + * iff it is an integral type or a floating point type. + * + * mozilla::IsArithmetic::value is true; + * mozilla::IsArithmetic::value is true; + * mozilla::IsArithmetic::value is false. + */ +template +struct IsArithmetic + : IntegralConstant::value || IsFloatingPoint::value> +{}; + +/* 20.9.4.3 Type properties [meta.unary.prop] */ + +/** + * IsConst determines whether a type is const or not. + * + * mozilla::IsConst::value is false; + * mozilla::IsConst::value is true; + * mozilla::IsConst::value is false. + */ +template +struct IsConst : FalseType {}; + +template +struct IsConst : TrueType {}; + +/** + * IsVolatile determines whether a type is volatile or not. + * + * mozilla::IsVolatile::value is false; + * mozilla::IsVolatile::value is true; + * mozilla::IsVolatile::value is false. + */ +template +struct IsVolatile : FalseType {}; + +template +struct IsVolatile : TrueType {}; + +/** + * Traits class for identifying POD types. Until C++11 there's no automatic + * way to detect PODs, so for the moment this is done manually. Users may + * define specializations of this class that inherit from mozilla::TrueType and + * mozilla::FalseType (or equivalently mozilla::IntegralConstant, or conveniently from mozilla::IsPod for composite types) as needed to + * ensure correct IsPod behavior. + */ +template +struct IsPod : public FalseType {}; + +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +template<> struct IsPod : TrueType {}; +#ifdef MOZ_CHAR16_IS_NOT_WCHAR +template<> struct IsPod : TrueType {}; +#endif +template struct IsPod : TrueType {}; + +namespace detail { + +// __is_empty is a supported extension across all of our supported compilers: +// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html +// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits +// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx +template +struct IsEmptyHelper + : IntegralConstant::value && __is_empty(T)> +{}; + +} // namespace detail + +/** + * IsEmpty determines whether a type is a class (but not a union) that is empty. + * + * A class is empty iff it and all its base classes have no non-static data + * members (except bit-fields of length 0) and no virtual member functions, and + * no base class is empty or a virtual base class. + * + * Intuitively, empty classes don't have any data that has to be stored in + * instances of those classes. (The size of the class must still be non-zero, + * because distinct array elements of any type must have different addresses. + * However, if the Empty Base Optimization is implemented by the compiler [most + * compilers implement it, and in certain cases C++11 requires it], the size of + * a class inheriting from an empty |Base| class need not be inflated by + * |sizeof(Base)|.) And intuitively, non-empty classes have data members and/or + * vtable pointers that must be stored in each instance for proper behavior. + * + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * union U1 { int x; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct E1 {}; + * struct E2 { int : 0 }; + * struct E3 : E1 {}; + * struct E4 : E2 {}; + * static_assert(mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value && + * mozilla::IsEmpty::value, + * "all empty"); + * union U2 { E1 e1; }; + * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); + * struct NE1 { int x; }; + * struct NE2 : virtual E1 {}; + * struct NE3 : E2 { virtual ~NE3() {} }; + * struct NE4 { virtual void f() {} }; + * static_assert(!mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value && + * !mozilla::IsEmpty::value, + * "all empty"); + */ +template +struct IsEmpty : detail::IsEmptyHelper::Type> +{}; + + +namespace detail { + +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> +struct IsSignedHelper; + +// Floating point is signed. +template +struct IsSignedHelper : TrueType {}; + +// Integral is conditionally signed. +template +struct IsSignedHelper + : IntegralConstant +{}; + +// Non-floating point, non-integral is not signed. +template +struct IsSignedHelper : FalseType {}; + +} // namespace detail + +/** + * IsSigned determines whether a type is a signed arithmetic type. |char| is + * considered a signed type if it has the same representation as |signed char|. + * + * mozilla::IsSigned::value is true; + * mozilla::IsSigned::value is false; + * mozilla::IsSigned::value is false; + * mozilla::IsSigned::value is true. + */ +template +struct IsSigned : detail::IsSignedHelper {}; + +namespace detail { + +template::value, + bool = IsIntegral::value, + typename NoCV = typename RemoveCV::Type> +struct IsUnsignedHelper; + +// Floating point is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; + +// Integral is conditionally unsigned. +template +struct IsUnsignedHelper + : IntegralConstant::value || bool(NoCV(1) < NoCV(-1)))> +{}; + +// Non-floating point, non-integral is not unsigned. +template +struct IsUnsignedHelper : FalseType {}; + +} // namespace detail + +/** + * IsUnsigned determines whether a type is an unsigned arithmetic type. + * + * mozilla::IsUnsigned::value is false; + * mozilla::IsUnsigned::value is true; + * mozilla::IsUnsigned::value is true; + * mozilla::IsUnsigned::value is false. + */ +template +struct IsUnsigned : detail::IsUnsignedHelper {}; + +/* 20.9.5 Type property queries [meta.unary.prop.query] */ + +/* 20.9.6 Relationships between types [meta.rel] */ + +/** + * IsSame tests whether two types are the same type. + * + * mozilla::IsSame::value is true; + * mozilla::IsSame::value is true; + * mozilla::IsSame::value is false; + * mozilla::IsSame::value is true; + * mozilla::IsSame::value is false; + * mozilla::IsSame::value is true. + */ +template +struct IsSame : FalseType {}; + +template +struct IsSame : TrueType {}; + +namespace detail { + +#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) + +template +struct BaseOfTester : IntegralConstant {}; + +#else + +// The trickery used to implement IsBaseOf here makes it possible to use it for +// the cases of private and multiple inheritance. This code was inspired by the +// sample code here: +// +// http://stackoverflow.com/questions/2910979/how-is-base-of-works +template +struct BaseOfHelper +{ +public: + operator Base*() const; + operator Derived*(); +}; + +template +struct BaseOfTester +{ +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); +}; + +template +struct BaseOfTester +{ +private: + template + static char test(Derived*, T); + static int test(Base*, int); + +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); +}; + +template +struct BaseOfTester : FalseType {}; + +template +struct BaseOfTester : TrueType {}; + +template +struct BaseOfTester : TrueType {}; + +#endif + +} /* namespace detail */ + +/* + * IsBaseOf allows to know whether a given class is derived from another. + * + * Consider the following class definitions: + * + * class A {}; + * class B : public A {}; + * class C {}; + * + * mozilla::IsBaseOf::value is true; + * mozilla::IsBaseOf::value is false; + */ +template +struct IsBaseOf + : IntegralConstant::value> +{}; + +namespace detail { + +template +struct ConvertibleTester +{ +private: + static From create(); + + template + static char test(To to); + + template + static int test(...); + +public: + static const bool value = + sizeof(test(create())) == sizeof(char); +}; + +} // namespace detail + +/** + * IsConvertible determines whether a value of type From will implicitly convert + * to a value of type To. For example: + * + * struct A {}; + * struct B : public A {}; + * struct C {}; + * + * mozilla::IsConvertible::value is true; + * mozilla::IsConvertible::value is true; + * mozilla::IsConvertible::value is true; + * mozilla::IsConvertible::value is true; + * mozilla::IsConvertible::value is false; + * mozilla::IsConvertible::value is false; + * mozilla::IsConvertible::value is false; + * mozilla::IsConvertible::value is false. + * + * For obscure reasons, you can't use IsConvertible when the types being tested + * are related through private inheritance, and you'll get a compile error if + * you try. Just don't do it! + */ +template +struct IsConvertible + : IntegralConstant::value> +{}; + +/* 20.9.7 Transformations between types [meta.trans] */ + +/* 20.9.7.1 Const-volatile modifications [meta.trans.cv] */ + +/** + * RemoveConst removes top-level const qualifications on a type. + * + * mozilla::RemoveConst::Type is int; + * mozilla::RemoveConst::Type is int; + * mozilla::RemoveConst::Type is const int*; + * mozilla::RemoveConst::Type is int*. + */ +template +struct RemoveConst +{ + typedef T Type; +}; + +template +struct RemoveConst +{ + typedef T Type; +}; + +/** + * RemoveVolatile removes top-level volatile qualifications on a type. + * + * mozilla::RemoveVolatile::Type is int; + * mozilla::RemoveVolatile::Type is int; + * mozilla::RemoveVolatile::Type is volatile int*; + * mozilla::RemoveVolatile::Type is int*. + */ +template +struct RemoveVolatile +{ + typedef T Type; +}; + +template +struct RemoveVolatile +{ + typedef T Type; +}; + +/** + * RemoveCV removes top-level const and volatile qualifications on a type. + * + * mozilla::RemoveCV::Type is int; + * mozilla::RemoveCV::Type is int; + * mozilla::RemoveCV::Type is int; + * mozilla::RemoveCV::Type is int*. + */ +template +struct RemoveCV +{ + typedef typename RemoveConst::Type>::Type Type; +}; + +/* 20.9.7.2 Reference modifications [meta.trans.ref] */ + +/** + * Converts reference types to the underlying types. + * + * mozilla::RemoveReference::Type is T; + * mozilla::RemoveReference::Type is T; + * mozilla::RemoveReference::Type is T; + */ + +template +struct RemoveReference +{ + typedef T Type; +}; + +template +struct RemoveReference +{ + typedef T Type; +}; + +template +struct RemoveReference +{ + typedef T Type; +}; + +template +struct Conditional; + +namespace detail { + +enum Voidness { TIsVoid, TIsNotVoid }; + +template::value ? TIsVoid : TIsNotVoid> +struct AddLvalueReferenceHelper; + +template +struct AddLvalueReferenceHelper +{ + typedef void Type; +}; + +template +struct AddLvalueReferenceHelper +{ + typedef T& Type; +}; + +} // namespace detail + +/** + * AddLvalueReference adds an lvalue & reference to T if one isn't already + * present. (Note: adding an lvalue reference to an rvalue && reference in + * essence replaces the && with a &&, per C+11 reference collapsing rules. For + * example, int&& would become int&.) + * + * The final computed type will only *not* be an lvalue reference if T is void. + * + * mozilla::AddLvalueReference::Type is int&; + * mozilla::AddLvalueRference::Type is volatile int&; + * mozilla::AddLvalueReference::Type is void*&; + * mozilla::AddLvalueReference::Type is void; + * mozilla::AddLvalueReference::Type is struct S&. + */ +template +struct AddLvalueReference + : detail::AddLvalueReferenceHelper +{}; + +/* 20.9.7.3 Sign modifications [meta.trans.sign] */ + +template +struct EnableIf; + +namespace detail { + +template +struct WithC : Conditional +{}; + +template +struct WithV : Conditional +{}; + + +template +struct WithCV : WithC::Type> +{}; + +template +struct CorrespondingSigned; + +template<> +struct CorrespondingSigned { typedef signed char Type; }; +template<> +struct CorrespondingSigned { typedef signed char Type; }; +template<> +struct CorrespondingSigned { typedef short Type; }; +template<> +struct CorrespondingSigned { typedef int Type; }; +template<> +struct CorrespondingSigned { typedef long Type; }; +template<> +struct CorrespondingSigned { typedef long long Type; }; + +template::Type, + bool IsSignedIntegerType = IsSigned::value && + !IsSame::value> +struct MakeSigned; + +template +struct MakeSigned +{ + typedef T Type; +}; + +template +struct MakeSigned + : WithCV::value, IsVolatile::value, + typename CorrespondingSigned::Type> +{}; + +} // namespace detail + +/** + * MakeSigned produces the corresponding signed integer type for a given + * integral type T, with the const/volatile qualifiers of T. T must be a + * possibly-const/volatile-qualified integral type that isn't bool. + * + * If T is already a signed integer type (not including char!), then T is + * produced. + * + * Otherwise, if T is an unsigned integer type, the signed variety of T, with + * T's const/volatile qualifiers, is produced. + * + * Otherwise, the integral type of the same size as T, with the lowest rank, + * with T's const/volatile qualifiers, is produced. (This basically only acts + * to produce signed char when T = char.) + * + * mozilla::MakeSigned::Type is signed long; + * mozilla::MakeSigned::Type is volatile int; + * mozilla::MakeSigned::Type is const signed short; + * mozilla::MakeSigned::Type is const signed char; + * mozilla::MakeSigned is an error; + * mozilla::MakeSigned is an error. + */ +template +struct MakeSigned + : EnableIf::value && + !IsSame::Type>::value, + typename detail::MakeSigned + >::Type +{}; + +namespace detail { + +template +struct CorrespondingUnsigned; + +template<> +struct CorrespondingUnsigned { typedef unsigned char Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned char Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned short Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned int Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned long Type; }; +template<> +struct CorrespondingUnsigned { typedef unsigned long long Type; }; + + +template::Type, + bool IsUnsignedIntegerType = IsUnsigned::value && + !IsSame::value> +struct MakeUnsigned; + +template +struct MakeUnsigned +{ + typedef T Type; +}; + +template +struct MakeUnsigned + : WithCV::value, IsVolatile::value, + typename CorrespondingUnsigned::Type> +{}; + +} // namespace detail + +/** + * MakeUnsigned produces the corresponding unsigned integer type for a given + * integral type T, with the const/volatile qualifiers of T. T must be a + * possibly-const/volatile-qualified integral type that isn't bool. + * + * If T is already an unsigned integer type (not including char!), then T is + * produced. + * + * Otherwise, if T is an signed integer type, the unsigned variety of T, with + * T's const/volatile qualifiers, is produced. + * + * Otherwise, the unsigned integral type of the same size as T, with the lowest + * rank, with T's const/volatile qualifiers, is produced. (This basically only + * acts to produce unsigned char when T = char.) + * + * mozilla::MakeUnsigned::Type is unsigned long; + * mozilla::MakeUnsigned::Type is volatile unsigned int; + * mozilla::MakeUnsigned::Type is const unsigned short; + * mozilla::MakeUnsigned::Type is const unsigned char; + * mozilla::MakeUnsigned is an error; + * mozilla::MakeUnsigned is an error. + */ +template +struct MakeUnsigned + : EnableIf::value && + !IsSame::Type>::value, + typename detail::MakeUnsigned + >::Type +{}; + +/* 20.9.7.4 Array modifications [meta.trans.arr] */ + +/** + * RemoveExtent produces either the type of the elements of the array T, or T + * itself. + * + * mozilla::RemoveExtent::Type is int; + * mozilla::RemoveExtent::Type is const int; + * mozilla::RemoveExtent::Type is volatile int; + * mozilla::RemoveExtent::Type is long[17]. + */ +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + +template +struct RemoveExtent +{ + typedef T Type; +}; + +/* 20.9.7.5 Pointer modifications [meta.trans.ptr] */ + +/* 20.9.7.6 Other transformations [meta.trans.other] */ + +/** + * EnableIf is a struct containing a typedef of T if and only if B is true. + * + * mozilla::EnableIf::Type is int; + * mozilla::EnableIf::Type is a compile-time error. + * + * Use this template to implement SFINAE-style (Substitution Failure Is not An + * Error) requirements. For example, you might use it to impose a restriction + * on a template parameter: + * + * template + * class PodVector // vector optimized to store POD (memcpy-able) types + * { + * EnableIf::value, T>::Type* vector; + * size_t length; + * ... + * }; + */ +template +struct EnableIf +{}; + +template +struct EnableIf +{ + typedef T Type; +}; + +/** + * Conditional selects a class between two, depending on a given boolean value. + * + * mozilla::Conditional::Type is A; + * mozilla::Conditional::Type is B; + */ +template +struct Conditional +{ + typedef A Type; +}; + +template +struct Conditional +{ + typedef B Type; +}; + +} /* namespace mozilla */ + +#endif /* mozilla_TypeTraits_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/TypedEnum.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/TypedEnum.h new file mode 100644 index 0000000000..d84cd90257 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/TypedEnum.h @@ -0,0 +1,281 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Macros to emulate C++11 typed enums and enum classes. */ + +#ifndef mozilla_TypedEnum_h +#define mozilla_TypedEnum_h + +#include "mozilla/TypedEnumInternal.h" +#include "mozilla/MacroArgs.h" + +#if defined(__cplusplus) + +/** + * MOZ_ENUM_TYPE specifies the underlying numeric type for an enum. It's + * specified by placing MOZ_ENUM_TYPE(type) immediately after the enum name in + * its declaration, and before the opening curly brace, like + * + * enum MyEnum MOZ_ENUM_TYPE(uint16_t) + * { + * A, + * B = 7, + * C + * }; + * + * In supporting compilers, the macro will expand to ": uint16_t". The + * compiler will allocate exactly two bytes for MyEnum and will require all + * enumerators to have values between 0 and 65535. (Thus specifying "B = + * 100000" instead of "B = 7" would fail to compile.) In old compilers the + * macro expands to the empty string, and the underlying type is generally + * undefined. + */ +#ifdef MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_ENUM_TYPE(type) : type +#else +# define MOZ_ENUM_TYPE(type) /* no support */ +#endif + +/** + * MOZ_BEGIN_ENUM_CLASS and MOZ_END_ENUM_CLASS provide access to the + * strongly-typed enumeration feature of C++11 ("enum class"). If supported + * by the compiler, an enum defined using these macros will not be implicitly + * converted to any other type, and its enumerators will be scoped using the + * enumeration name. Place MOZ_BEGIN_ENUM_CLASS(EnumName [, type]) in place of + * "enum EnumName {", and MOZ_END_ENUM_CLASS(EnumName) in place of the closing + * "};". For example, + * + * MOZ_BEGIN_ENUM_CLASS(Enum, int32_t) + * A, + * B = 6 + * MOZ_END_ENUM_CLASS(Enum) + * + * This will make "Enum::A" and "Enum::B" appear in the global scope, but "A" + * and "B" will not. In compilers that support C++11 strongly-typed + * enumerations, implicit conversions of Enum values to numeric types will + * fail. In other compilers, Enum itself will actually be defined as a class, + * and some implicit conversions will fail while others will succeed. + * + * The optional type argument specifies the underlying type for the enum where + * supported, as with MOZ_ENUM_TYPE(). As with MOZ_ENUM_TYPE(), it will do + * nothing on compilers that do not support it. + * + * MOZ_{BEGIN,END}_ENUM_CLASS doesn't work for defining enum classes nested + * inside classes. To define an enum class nested inside another class, use + * MOZ_{BEGIN,END}_NESTED_ENUM_CLASS, and place a MOZ_FINISH_NESTED_ENUM_CLASS + * in namespace scope to handle bits that can only be implemented with + * namespace-scoped code. For example: + * + * class FooBar + * { + * MOZ_BEGIN_NESTED_ENUM_CLASS(Enum, int32_t) + * A, + * B = 6 + * MOZ_END_NESTED_ENUM_CLASS(Enum) + * }; + * + * MOZ_FINISH_NESTED_ENUM_CLASS(FooBar::Enum) + */ +#if defined(MOZ_HAVE_CXX11_STRONG_ENUMS) + /* + * All compilers that support strong enums also support an explicit + * underlying type, so no extra check is needed. + */ + + /* Single-argument form. */ +# define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER1(Name) \ + enum class Name { + /* Two-argument form. */ +# define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER2(Name, type) \ + enum class Name : type { +# define MOZ_END_NESTED_ENUM_CLASS(Name) \ + }; +# define MOZ_FINISH_NESTED_ENUM_CLASS(Name) /* nothing */ + + /* + * MOZ_ENUM_CLASS_ENUM_TYPE allows using enum classes + * as template parameter types. For that, we need integer types. + * In the present case where the compiler supports strong enums, + * these are already integer types so there is nothing more to do. + */ +# define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name + /* + * See the comment below about MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) Name +#else + /** + * We need Name to both name a type, and scope the provided enumerator + * names. Namespaces and classes both provide scoping, but namespaces + * aren't types, so we need to use a class that wraps the enum values. We + * have an implicit conversion from the inner enum type to the class, so + * statements like + * + * Enum x = Enum::A; + * + * will still work. We need to define an implicit conversion from the class + * to the inner enum as well, so that (for instance) switch statements will + * work. This means that the class can be implicitly converted to a numeric + * value as well via the enum type, since C++ allows an implicit + * user-defined conversion followed by a standard conversion to still be + * implicit. + * + * We have an explicit constructor from int defined, so that casts like + * (Enum)7 will still work. We also have a zero-argument constructor with + * no arguments, so declaration without initialization (like "Enum foo;") + * will work. + * + * Additionally, we'll delete as many operators as possible for the inner + * enum type, so statements like this will still fail: + * + * f(5 + Enum::B); // deleted operator+ + * + * But we can't prevent things like this, because C++ doesn't allow + * overriding conversions or assignment operators for enums: + * + * int x = Enum::A; + * int f() + * { + * return Enum::A; + * } + */ + + /* Single-argument form. */ +# define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER1(Name) \ + class Name \ + { \ + public: \ + enum Enum \ + { + /* Two-argument form. */ +# define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER2(Name, type) \ + class Name \ + { \ + public: \ + enum Enum MOZ_ENUM_TYPE(type) \ + { +# define MOZ_END_NESTED_ENUM_CLASS(Name) \ + }; \ + Name() {} \ + MOZ_CONSTEXPR Name(Enum aEnum) : mEnum(aEnum) {} \ + template \ + explicit MOZ_CONSTEXPR Name(Other num) : mEnum((Enum)num) {} \ + MOZ_CONSTEXPR operator Enum() const { return mEnum; } \ + explicit MOZ_CONSTEXPR Name(const mozilla::CastableTypedEnumResult& aOther) \ + : mEnum(aOther.get()) \ + {} \ + private: \ + Enum mEnum; \ + }; +# define MOZ_FINISH_NESTED_ENUM_CLASS(Name) \ + inline int operator+(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator+(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator-(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator-(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator*(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator*(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator/(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator/(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator%(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator%(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator+(const Name::Enum&) MOZ_DELETE; \ + inline int operator-(const Name::Enum&) MOZ_DELETE; \ + inline int& operator++(Name::Enum&) MOZ_DELETE; \ + inline int operator++(Name::Enum&, int) MOZ_DELETE; \ + inline int& operator--(Name::Enum&) MOZ_DELETE; \ + inline int operator--(Name::Enum&, int) MOZ_DELETE; \ + inline bool operator==(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator==(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator!=(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator!=(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator>(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator>(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator<(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator<(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator>=(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator>=(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator<=(const int&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator<=(const Name::Enum&, const int&) MOZ_DELETE; \ + inline bool operator!(const Name::Enum&) MOZ_DELETE; \ + inline bool operator&&(const bool&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator&&(const Name::Enum&, const bool&) MOZ_DELETE; \ + inline bool operator||(const bool&, const Name::Enum&) MOZ_DELETE; \ + inline bool operator||(const Name::Enum&, const bool&) MOZ_DELETE; \ + inline int operator&(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator&(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator|(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator|(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator^(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator^(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator<<(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator<<(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int operator>>(const int&, const Name::Enum&) MOZ_DELETE; \ + inline int operator>>(const Name::Enum&, const int&) MOZ_DELETE; \ + inline int& operator+=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator-=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator*=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator/=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator%=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator&=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator|=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator^=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator<<=(int&, const Name::Enum&) MOZ_DELETE; \ + inline int& operator>>=(int&, const Name::Enum&) MOZ_DELETE; + + /* + * MOZ_ENUM_CLASS_ENUM_TYPE allows using enum classes + * as template parameter types. For that, we need integer types. + * In the present case, the integer type is the Enum nested type. + */ +# define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name::Enum + /* + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is a variant of MOZ_ENUM_CLASS_ENUM_TYPE + * to be used when the enum class at hand depends on template parameters. + * + * Indeed, if T depends on template parameters, in order to name a nested type + * in T, C++ does not allow to just write "T::NestedType". Instead, we have + * to write "typename T::NestedType". The role of this macro is to add + * this "typename" keywords where needed. + * + * Example: + * + * template + * struct S {}; + * + * MOZ_BEGIN_ENUM_CLASS(E) + * Foo, + * Bar + * MOZ_END_ENUM_CLASS(E) + * + * S s; + * + * In this example, the second template parameter to S is meant to be of type + * T, but on non-C++11 compilers, type T is a class type, not an integer + * type, so it is not accepted as the type of a constant template parameter. + * One would then want to use MOZ_ENUM_CLASS_ENUM_TYPE(T), but that doesn't + * work either as T depends on template parameters (more specifically here, T + * _is_ a template parameter) so as MOZ_ENUM_CLASS_ENUM_TYPE(T) expands to + * T::Enum, we are missing the required "typename" keyword. So here, + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is needed. + */ +# define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) typename Name::Enum +#endif + +# define MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE(a, b) a b +# define MOZ_BEGIN_NESTED_ENUM_CLASS(...) \ + MOZ_BEGIN_NESTED_ENUM_CLASS_GLUE( \ + MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER, \ + __VA_ARGS__), \ + (__VA_ARGS__)) + +# define MOZ_BEGIN_ENUM_CLASS(...) MOZ_BEGIN_NESTED_ENUM_CLASS(__VA_ARGS__) +# define MOZ_END_ENUM_CLASS(Name) \ + MOZ_END_NESTED_ENUM_CLASS(Name) \ + MOZ_FINISH_NESTED_ENUM_CLASS(Name) + +#endif /* __cplusplus */ + +#endif /* mozilla_TypedEnum_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/TypedEnumInternal.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/TypedEnumInternal.h new file mode 100644 index 0000000000..8c88cb589b --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/TypedEnumInternal.h @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Internal stuff needed by TypedEnum.h and TypedEnumBits.h. */ + +// NOTE: When we can assume C++11 enum class support and TypedEnum.h goes away, +// we should then consider folding TypedEnumInternal.h into TypedEnumBits.h. + +#ifndef mozilla_TypedEnumInternal_h +#define mozilla_TypedEnumInternal_h + +#include "mozilla/Attributes.h" + +#if defined(__cplusplus) + +#if defined(__clang__) + /* + * Per Clang documentation, "Note that marketing version numbers should not + * be used to check for language features, as different vendors use different + * numbering schemes. Instead, use the feature checking macros." + */ +# ifndef __has_extension +# define __has_extension __has_feature /* compatibility, for older versions of clang */ +# endif +# if __has_extension(cxx_strong_enums) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#elif defined(__GNUC__) +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3) +# define MOZ_HAVE_CXX11_ENUM_TYPE +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +# endif +#elif defined(_MSC_VER) +# if _MSC_VER >= 1400 +# define MOZ_HAVE_CXX11_ENUM_TYPE +# endif +# if _MSC_VER >= 1700 +# define MOZ_HAVE_CXX11_STRONG_ENUMS +# endif +#endif + +namespace mozilla { + +/* + * The problem that CastableTypedEnumResult aims to solve is that + * typed enums are not convertible to bool, and there is no way to make them + * be, yet user code wants to be able to write + * + * if (myFlags & Flags::SOME_PARTICULAR_FLAG) (1) + * + * There are different approaches to solving this. Most of them require + * adapting user code. For example, we could implement operator! and have + * the user write + * + * if (!!(myFlags & Flags::SOME_PARTICULAR_FLAG)) (2) + * + * Or we could supply a IsNonZero() or Any() function returning whether + * an enum value is nonzero, and have the user write + * + * if (Any(Flags & Flags::SOME_PARTICULAR_FLAG)) (3) + * + * But instead, we choose to preserve the original user syntax (1) as it + * is inherently more readable, and to ease porting existing code to typed + * enums. We achieve this by having operator& and other binary bitwise + * operators have as return type a class, CastableTypedEnumResult, + * that wraps a typed enum but adds bool convertibility. + */ +template +class CastableTypedEnumResult +{ +private: + const E mValue; + +public: + explicit MOZ_CONSTEXPR CastableTypedEnumResult(E aValue) + : mValue(aValue) + {} + + MOZ_CONSTEXPR operator E() const { return mValue; } + + template + MOZ_EXPLICIT_CONVERSION MOZ_CONSTEXPR + operator DestinationType() const { return DestinationType(mValue); } + + MOZ_CONSTEXPR bool operator !() const { return !bool(mValue); } + +#ifndef MOZ_HAVE_CXX11_STRONG_ENUMS + // This get() method is used to implement a constructor in the + // non-c++11 fallback path for MOZ_BEGIN_ENUM_CLASS, taking a + // CastableTypedEnumResult. If we try to implement it using the + // above conversion operator E(), then at least clang 3.3 + // (when forced to take the non-c++11 fallback path) compiles + // this constructor to an infinite recursion. So we introduce this + // get() method, that does exactly the same as the conversion operator, + // to work around this. + MOZ_CONSTEXPR E get() const { return mValue; } +#endif +}; + +} // namespace mozilla + +#endif // __cplusplus + +#endif // mozilla_TypedEnumInternal_h diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Types.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Types.h new file mode 100644 index 0000000000..e7e18abb27 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Types.h @@ -0,0 +1,134 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* mfbt foundational types and macros. */ + +#ifndef mozilla_Types_h +#define mozilla_Types_h + +/* + * This header must be valid C and C++, includable by code embedding either + * SpiderMonkey or Gecko. + */ + +/* Expose all types and size_t. */ +#include +#include + +/* Implement compiler and linker macros needed for APIs. */ + +/* + * MOZ_EXPORT is used to declare and define a symbol or type which is externally + * visible to users of the current library. It encapsulates various decorations + * needed to properly export the method's symbol. + * + * api.h: + * extern MOZ_EXPORT int MeaningOfLife(void); + * extern MOZ_EXPORT int LuggageCombination; + * + * api.c: + * int MeaningOfLife(void) { return 42; } + * int LuggageCombination = 12345; + * + * If you are merely sharing a method across files, just use plain |extern|. + * These macros are designed for use by library interfaces -- not for normal + * methods or data used cross-file. + */ +#if defined(WIN32) +# define MOZ_EXPORT __declspec(dllexport) +#else /* Unix */ +# ifdef HAVE_VISIBILITY_ATTRIBUTE +# define MOZ_EXPORT __attribute__((visibility("default"))) +# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) +# define MOZ_EXPORT __global +# else +# define MOZ_EXPORT /* nothing */ +# endif +#endif + + +/* + * Whereas implementers use MOZ_EXPORT to declare and define library symbols, + * users use MOZ_IMPORT_API and MOZ_IMPORT_DATA to access them. Most often the + * implementer of the library will expose an API macro which expands to either + * the export or import version of the macro, depending upon the compilation + * mode. + */ +#ifdef _WIN32 +# if defined(__MWERKS__) +# define MOZ_IMPORT_API /* nothing */ +# else +# define MOZ_IMPORT_API __declspec(dllimport) +# endif +#else +# define MOZ_IMPORT_API MOZ_EXPORT +#endif + +#if defined(_WIN32) && !defined(__MWERKS__) +# define MOZ_IMPORT_DATA __declspec(dllimport) +#else +# define MOZ_IMPORT_DATA MOZ_EXPORT +#endif + +/* + * Consistent with the above comment, the MFBT_API and MFBT_DATA macros expose + * export mfbt declarations when building mfbt, and they expose import mfbt + * declarations when using mfbt. + */ +#if defined(IMPL_MFBT) +# define MFBT_API MOZ_EXPORT +# define MFBT_DATA MOZ_EXPORT +#else + /* + * On linux mozglue is linked in the program and we link libxul.so with + * -z,defs. Normally that causes the linker to reject undefined references in + * libxul.so, but as a loophole it allows undefined references to weak + * symbols. We add the weak attribute to the import version of the MFBT API + * macros to exploit this. + */ +# if defined(MOZ_GLUE_IN_PROGRAM) +# define MFBT_API __attribute__((weak)) MOZ_IMPORT_API +# define MFBT_DATA __attribute__((weak)) MOZ_IMPORT_DATA +# else +# define MFBT_API MOZ_IMPORT_API +# define MFBT_DATA MOZ_IMPORT_DATA +# endif +#endif + +/* + * C symbols in C++ code must be declared immediately within |extern "C"| + * blocks. However, in C code, they need not be declared specially. This + * difference is abstracted behind the MOZ_BEGIN_EXTERN_C and MOZ_END_EXTERN_C + * macros, so that the user need not know whether he is being used in C or C++ + * code. + * + * MOZ_BEGIN_EXTERN_C + * + * extern MOZ_EXPORT int MostRandomNumber(void); + * ...other declarations... + * + * MOZ_END_EXTERN_C + * + * This said, it is preferable to just use |extern "C"| in C++ header files for + * its greater clarity. + */ +#ifdef __cplusplus +# define MOZ_BEGIN_EXTERN_C extern "C" { +# define MOZ_END_EXTERN_C } +#else +# define MOZ_BEGIN_EXTERN_C +# define MOZ_END_EXTERN_C +#endif + +/* + * GCC's typeof is available when decltype is not. + */ +#if defined(__GNUC__) && defined(__cplusplus) && \ + !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L +# define decltype __typeof__ +#endif + +#endif /* mozilla_Types_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/UniquePtr.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/UniquePtr.h new file mode 100644 index 0000000000..9c873db90c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/UniquePtr.h @@ -0,0 +1,674 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Smart pointer managing sole ownership of a resource. */ + +#ifndef mozilla_UniquePtr_h +#define mozilla_UniquePtr_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Compiler.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/Pair.h" +#include "mozilla/TypeTraits.h" + +namespace mozilla { + +template class DefaultDelete; +template> class UniquePtr; + +} // namespace mozilla + +namespace mozilla { + +/** + * UniquePtr is a smart pointer that wholly owns a resource. Ownership may be + * transferred out of a UniquePtr through explicit action, but otherwise the + * resource is destroyed when the UniquePtr is destroyed. + * + * UniquePtr is similar to C++98's std::auto_ptr, but it improves upon auto_ptr + * in one crucial way: it's impossible to copy a UniquePtr. Copying an auto_ptr + * obviously *can't* copy ownership of its singly-owned resource. So what + * happens if you try to copy one? Bizarrely, ownership is implicitly + * *transferred*, preserving single ownership but breaking code that assumes a + * copy of an object is identical to the original. (This is why auto_ptr is + * prohibited in STL containers.) + * + * UniquePtr solves this problem by being *movable* rather than copyable. + * Instead of passing a |UniquePtr u| directly to the constructor or assignment + * operator, you pass |Move(u)|. In doing so you indicate that you're *moving* + * ownership out of |u|, into the target of the construction/assignment. After + * the transfer completes, |u| contains |nullptr| and may be safely destroyed. + * This preserves single ownership but also allows UniquePtr to be moved by + * algorithms that have been made move-safe. (Note: if |u| is instead a + * temporary expression, don't use |Move()|: just pass the expression, because + * it's already move-ready. For more information see Move.h.) + * + * UniquePtr is also better than std::auto_ptr in that the deletion operation is + * customizable. An optional second template parameter specifies a class that + * (through its operator()(T*)) implements the desired deletion policy. If no + * policy is specified, mozilla::DefaultDelete is used -- which will either + * |delete| or |delete[]| the resource, depending whether the resource is an + * array. Custom deletion policies ideally should be empty classes (no member + * fields, no member fields in base classes, no virtual methods/inheritance), + * because then UniquePtr can be just as efficient as a raw pointer. + * + * Use of UniquePtr proceeds like so: + * + * UniquePtr g1; // initializes to nullptr + * g1.reset(new int); // switch resources using reset() + * g1 = nullptr; // clears g1, deletes the int + * + * UniquePtr g2(new int); // owns that int + * int* p = g2.release(); // g2 leaks its int -- still requires deletion + * delete p; // now freed + * + * struct S { int x; S(int x) : x(x) {} }; + * UniquePtr g3, g4(new S(5)); + * g3 = Move(g4); // g3 owns the S, g4 cleared + * S* p = g3.get(); // g3 still owns |p| + * assert(g3->x == 5); // operator-> works (if .get() != nullptr) + * assert((*g3).x == 5); // also operator* (again, if not cleared) + * Swap(g3, g4); // g4 now owns the S, g3 cleared + * g3.swap(g4); // g3 now owns the S, g4 cleared + * UniquePtr g5(Move(g3)); // g5 owns the S, g3 cleared + * g5.reset(); // deletes the S, g5 cleared + * + * struct FreePolicy { void operator()(void* p) { free(p); } }; + * UniquePtr g6(static_cast(malloc(sizeof(int)))); + * int* ptr = g6.get(); + * g6 = nullptr; // calls free(ptr) + * + * Now, carefully note a few things you *can't* do: + * + * UniquePtr b1; + * b1 = new int; // BAD: can only assign another UniquePtr + * int* ptr = b1; // BAD: no auto-conversion to pointer, use get() + * + * UniquePtr b2(b1); // BAD: can't copy a UniquePtr + * UniquePtr b3 = b1; // BAD: can't copy-assign a UniquePtr + * + * A few miscellaneous notes: + * + * UniquePtr, when not instantiated for an array type, can be move-constructed + * and move-assigned, not only from itself but from "derived" UniquePtr + * instantiations where U converts to T and E converts to D. If you want to use + * this, you're going to have to specify a deletion policy for both UniquePtr + * instantations, and T pretty much has to have a virtual destructor. In other + * words, this doesn't work: + * + * struct Base { virtual ~Base() {} }; + * struct Derived : Base {}; + * + * UniquePtr b1; + * // BAD: DefaultDelete and DefaultDelete don't interconvert + * UniquePtr d1(Move(b)); + * + * UniquePtr b2; + * UniquePtr> d2(Move(b2)); // okay + * + * UniquePtr is specialized for array types. Specializing with an array type + * creates a smart-pointer version of that array -- not a pointer to such an + * array. + * + * UniquePtr arr(new int[5]); + * arr[0] = 4; + * + * What else is different? Deletion of course uses |delete[]|. An operator[] + * is provided. Functionality that doesn't make sense for arrays is removed. + * The constructors and mutating methods only accept array pointers (not T*, U* + * that converts to T*, or UniquePtr or UniquePtr) or |nullptr|. + * + * It's perfectly okay to return a UniquePtr from a method to assure the related + * resource is properly deleted. You'll need to use |Move()| when returning a + * local UniquePtr. Otherwise you can return |nullptr|, or you can return + * |UniquePtr(ptr)|. + * + * UniquePtr will commonly be a member of a class, with lifetime equivalent to + * that of that class. If you want to expose the related resource, you could + * expose a raw pointer via |get()|, but ownership of a raw pointer is + * inherently unclear. So it's better to expose a |const UniquePtr&| instead. + * This prohibits mutation but still allows use of |get()| when needed (but + * operator-> is preferred). Of course, you can only use this smart pointer as + * long as the enclosing class instance remains live -- no different than if you + * exposed the |get()| raw pointer. + * + * To pass a UniquePtr-managed resource as a pointer, use a |const UniquePtr&| + * argument. To specify an inout parameter (where the method may or may not + * take ownership of the resource, or reset it), or to specify an out parameter + * (where simply returning a |UniquePtr| isn't possible), use a |UniquePtr&| + * argument. To unconditionally transfer ownership of a UniquePtr + * into a method, use a |UniquePtr| argument. To conditionally transfer + * ownership of a resource into a method, should the method want it, use a + * |UniquePtr&&| argument. + */ +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + Pointer& ptr() { return tuple.first(); } + const Pointer& ptr() const { return tuple.first(); } + + DeleterType& del() { return tuple.second(); } + const DeleterType& del() const { return tuple.second(); } + + public: + /** + * Construct a UniquePtr containing |nullptr|. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! Ideally + // you should make deletion use the same function every time, using a + // deleter policy: + // + // // BAD, won't compile with MSVC10, deleter doesn't need to be a + // // variable at all + // typedef void (&FreeSignature)(void*); + // UniquePtr ptr((int*) malloc(sizeof(int)), free); + // + // // GOOD, compiles with MSVC10, deletion behavior statically known and + // // optimizable + // struct DeleteByFreeing + // { + // void operator()(void* ptr) { free(ptr); } + // }; + // + // If deletion really, truly, must be a variable: you might be able to work + // around this with a deleter class that contains the function reference. + // But this workaround is untried and untested, because variable deletion + // behavior really isn't something you should use. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + template + UniquePtr(UniquePtr&& other, + typename EnableIf::Pointer, + Pointer>::value && + !IsArray::value && + (IsReference::value + ? IsSame::value + : IsConvertible::value), + int>::Type dummy = 0) + : tuple(other.release(), Forward(other.getDeleter())) + { + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + template + UniquePtr& operator=(UniquePtr&& other) + { + static_assert(IsConvertible::Pointer, Pointer>::value, + "incompatible UniquePtr pointees"); + static_assert(!IsArray::value, + "can't assign from UniquePtr holding an array"); + + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT n) { + MOZ_ASSERT(n == nullptr); + reset(nullptr); + return *this; + } + + T& operator*() const { return *get(); } + Pointer operator->() const { + MOZ_ASSERT(get(), "dereferencing a UniquePtr containing nullptr"); + return get(); + } + + Pointer get() const { return ptr(); } + + DeleterType& getDeleter() { return del(); } + const DeleterType& getDeleter() const { return del(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = ptr(); + ptr() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = ptr(); + ptr() = p; + if (old != nullptr) + getDeleter()(old); + } + + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +// In case you didn't read the comment by the main definition (you should!): the +// UniquePtr specialization exists to manage array pointers. It deletes +// such pointers using delete[], it will reject construction and modification +// attempts using U* or U[]. Otherwise it works like the normal UniquePtr. +template +class UniquePtr +{ + public: + typedef T* Pointer; + typedef T ElementType; + typedef D DeleterType; + + private: + Pair tuple; + + public: + /** + * Construct a UniquePtr containing nullptr. + */ + MOZ_CONSTEXPR UniquePtr() + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + /** + * Construct a UniquePtr containing |p|. + */ + explicit UniquePtr(Pointer p) + : tuple(p, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + private: + // delete[] knows how to handle *only* an array of a single class type. For + // delete[] to work correctly, it must know the size of each element, the + // fields and base classes of each element requiring destruction, and so on. + // So forbid all overloads which would end up invoking delete[] on a pointer + // of the wrong type. + template + UniquePtr(U&& u, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(Pointer p, + typename Conditional::value, + D, + const D&>::Type d1) + : tuple(p, d1) + {} + + // If you encounter an error with MSVC10 about RemoveReference below, along + // the lines that "more than one partial specialization matches the template + // argument list": don't use UniquePtr! See the + // comment by this constructor in the non-T[] specialization above. + UniquePtr(Pointer p, + typename RemoveReference::Type&& d2) + : tuple(p, Move(d2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + private: + // Forbidden for the same reasons as stated above. + template + UniquePtr(U&& u, V&& v, + typename EnableIf::value && + IsConvertible::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + UniquePtr(UniquePtr&& other) + : tuple(other.release(), Forward(other.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type dummy = 0) + : tuple(static_cast(nullptr), DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + ~UniquePtr() { + reset(nullptr); + } + + UniquePtr& operator=(UniquePtr&& other) { + reset(other.release()); + getDeleter() = Forward(other.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT) { + reset(); + return *this; + } + + T& operator[](decltype(sizeof(int)) i) const { return get()[i]; } + Pointer get() const { return tuple.first(); } + + DeleterType& getDeleter() { return tuple.second(); } + const DeleterType& getDeleter() const { return tuple.second(); } + + private: + typedef void (UniquePtr::* ConvertibleToBool)(double, char); + void nonNull(double, char) {} + + public: + operator ConvertibleToBool() const { + return get() != nullptr ? &UniquePtr::nonNull : nullptr; + } + + Pointer release() { + Pointer p = tuple.first(); + tuple.first() = nullptr; + return p; + } + + void reset(Pointer p = Pointer()) { + Pointer old = tuple.first(); + tuple.first() = p; + if (old != nullptr) + tuple.second()(old); + } + + private: + // Kill off all remaining overloads that aren't true nullptr (the overload + // above should handle that) or emulated nullptr (which acts like int/long + // on gcc 4.4/4.5). + template + void reset(U, + typename EnableIf::value && + !IsSame::Type>::value, + int>::Type dummy = 0) + MOZ_DELETE; + + public: + void swap(UniquePtr& other) { + tuple.swap(other.tuple); + } + + private: + UniquePtr(const UniquePtr& other) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& other) MOZ_DELETE; // assign using Move()! +}; + +/** A default deletion policy using plain old operator delete. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + template + DefaultDelete(const DefaultDelete& other, + typename EnableIf::value, + int>::Type dummy = 0) + {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete ptr; + } +}; + +/** A default deletion policy using operator delete[]. */ +template +class DefaultDelete +{ + public: + MOZ_CONSTEXPR DefaultDelete() {} + + void operator()(T* ptr) const { + static_assert(sizeof(T) > 0, "T must be complete"); + delete[] ptr; + } + + private: + template + void operator()(U* ptr) const MOZ_DELETE; +}; + +template +void +Swap(UniquePtr& x, UniquePtr& y) +{ + x.swap(y); +} + +template +bool +operator==(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() == y.get(); +} + +template +bool +operator!=(const UniquePtr& x, const UniquePtr& y) +{ + return x.get() != y.get(); +} + +template +bool +operator==(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator==(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return !x; +} + +template +bool +operator!=(const UniquePtr& x, NullptrT n) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +template +bool +operator!=(NullptrT n, const UniquePtr& x) +{ + MOZ_ASSERT(n == nullptr); + return bool(x); +} + +// No operator<, operator>, operator<=, operator>= for now because simplicity. + +namespace detail { + +template +struct UniqueSelector +{ + typedef UniquePtr SingleObject; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr UnknownBound; +}; + +template +struct UniqueSelector +{ + typedef UniquePtr KnownBound; +}; + +} // namespace detail + +// We don't have variadic template support everywhere, so just hard-code arities +// 0-4 for now. If you need more arguments, feel free to add the extra +// overloads. +// +// Beware! Due to lack of true nullptr support in gcc 4.4 and 4.5, passing +// literal nullptr to MakeUnique will not work on some platforms. See Move.h +// for more details. + +template +typename detail::UniqueSelector::SingleObject +MakeUnique() +{ + return UniquePtr(new T()); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1) +{ + return UniquePtr(new T(Forward(a1))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2) +{ + return UniquePtr(new T(Forward(a1), Forward(a2))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), Forward(a3), Forward(a4), Forward(a5))); +} + +template +typename detail::UniqueSelector::UnknownBound +MakeUnique(decltype(sizeof(int)) n) +{ + typedef typename RemoveExtent::Type ArrayType; + return UniquePtr(new ArrayType[n]()); +} + +template +typename detail::UniqueSelector::KnownBound +MakeUnique() MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) MOZ_DELETE; + +} // namespace mozilla + +#endif /* mozilla_UniquePtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Vector.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Vector.h new file mode 100644 index 0000000000..8540caf476 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/Vector.h @@ -0,0 +1,1280 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* A type/length-parametrized vector class. */ + +#ifndef mozilla_Vector_h +#define mozilla_Vector_h + +#include "mozilla/Alignment.h" +#include "mozilla/AllocPolicy.h" +#include "mozilla/ArrayUtils.h" // for PointerRangeSize +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/MathAlgorithms.h" +#include "mozilla/MemoryReporting.h" +#include "mozilla/Move.h" +#include "mozilla/NullPtr.h" +#include "mozilla/ReentrancyGuard.h" +#include "mozilla/TemplateLib.h" +#include "mozilla/TypeTraits.h" + +#include // for placement new + +/* Silence dire "bugs in previous versions of MSVC have been fixed" warnings */ +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4345) +#endif + +namespace mozilla { + +template +class VectorBase; + +namespace detail { + +/* + * Check that the given capacity wastes the minimal amount of space if + * allocated on the heap. This means that aCapacity*sizeof(T) is as close to a + * power-of-two as possible. growStorageBy() is responsible for ensuring this. + */ +template +static bool CapacityHasExcessSpace(size_t aCapacity) +{ + size_t size = aCapacity * sizeof(T); + return RoundUpPow2(size) - size >= sizeof(T); +} + +/* + * This template class provides a default implementation for vector operations + * when the element type is not known to be a POD, as judged by IsPod. + */ +template +struct VectorImpl +{ + /* Destroys constructed objects in the range [aBegin, aEnd). */ + static inline void destroy(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + p->~T(); + } + } + + /* Constructs objects in the uninitialized range [aBegin, aEnd). */ + static inline void initialize(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); + } + } + + /* + * Copy-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(*p); + } + } + + /* + * Move-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void moveConstruct(T* aDst, U* aSrcStart, U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(Move(*p)); + } + } + + /* + * Copy-constructs objects in the uninitialized range [aDst, aDst+aN) from + * the same object aU. + */ + template + static inline void copyConstructN(T* aDst, size_t aN, const U& aU) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + new(aDst) T(aU); + } + } + + /* + * Grows the given buffer to have capacity aNewCap, preserving the objects + * constructed in the range [begin, end) and updating aV. Assumes that (1) + * aNewCap has not overflowed, and (2) multiplying aNewCap by sizeof(T) will + * not overflow. + */ + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + T* newbuf = reinterpret_cast(aV.malloc_(aNewCap * sizeof(T))); + if (!newbuf) { + return false; + } + T* dst = newbuf; + T* src = aV.beginNoCheck(); + for (; src < aV.endNoCheck(); ++dst, ++src) { + new(dst) T(Move(*src)); + } + VectorImpl::destroy(aV.beginNoCheck(), aV.endNoCheck()); + aV.free_(aV.mBegin); + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } +}; + +/* + * This partial template specialization provides a default implementation for + * vector operations when the element type is known to be a POD, as judged by + * IsPod. + */ +template +struct VectorImpl +{ + static inline void destroy(T*, T*) {} + + static inline void initialize(T* aBegin, T* aEnd) + { + /* + * You would think that memset would be a big win (or even break even) + * when we know T is a POD. But currently it's not. This is probably + * because |append| tends to be given small ranges and memset requires + * a function call that doesn't get inlined. + * + * memset(aBegin, 0, sizeof(T) * (aEnd - aBegin)); + */ + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); + } + } + + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + /* + * See above memset comment. Also, notice that copyConstruct is + * currently templated (T != U), so memcpy won't work without + * requiring T == U. + * + * memcpy(aDst, aSrcStart, sizeof(T) * (aSrcEnd - aSrcStart)); + */ + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + *aDst = *p; + } + } + + template + static inline void moveConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + copyConstruct(aDst, aSrcStart, aSrcEnd); + } + + static inline void copyConstructN(T* aDst, size_t aN, const T& aT) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + *aDst = aT; + } + } + + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + size_t oldSize = sizeof(T) * aV.mCapacity; + size_t newSize = sizeof(T) * aNewCap; + T* newbuf = reinterpret_cast(aV.realloc_(aV.mBegin, oldSize, newSize)); + if (!newbuf) { + return false; + } + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } +}; + +} // namespace detail + +/* + * A CRTP base class for vector-like classes. Unless you really really want + * your own vector class -- and you almost certainly don't -- you should use + * mozilla::Vector instead! + * + * See mozilla::Vector for interface requirements. + */ +template +class VectorBase : private AllocPolicy +{ + /* utilities */ + + static const bool kElemIsPod = IsPod::value; + typedef detail::VectorImpl Impl; + friend struct detail::VectorImpl; + + bool growStorageBy(size_t aIncr); + bool convertToHeapStorage(size_t aNewCap); + + /* magic constants */ + + static const int kMaxInlineBytes = 1024; + + /* compute constants */ + + /* + * Consider element size to be 1 for buffer sizing if there are 0 inline + * elements. This allows us to compile when the definition of the element + * type is not visible here. + * + * Explicit specialization is only allowed at namespace scope, so in order + * to keep everything here, we use a dummy template parameter with partial + * specialization. + */ + template + struct ElemSize + { + static const size_t value = sizeof(T); + }; + template + struct ElemSize<0, Dummy> + { + static const size_t value = 1; + }; + + static const size_t kInlineCapacity = + tl::Min::value>::value; + + /* Calculate inline buffer size; avoid 0-sized array. */ + static const size_t kInlineBytes = + tl::Max<1, kInlineCapacity * ElemSize::value>::value; + + /* member data */ + + /* + * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, + * mBegin + mLength) hold valid constructed T objects. The range [mBegin + + * mLength, mBegin + mCapacity) holds uninitialized memory. The range + * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory + * previously allocated by a call to reserve(). + */ + T* mBegin; + + /* Number of elements in the vector. */ + size_t mLength; + + /* Max number of elements storable in the vector without resizing. */ + size_t mCapacity; + +#ifdef DEBUG + /* Max elements of reserved or used space in this vector. */ + size_t mReserved; +#endif + + /* Memory used for inline storage. */ + AlignedStorage mStorage; + +#ifdef DEBUG + friend class ReentrancyGuard; + bool mEntered; +#endif + + /* private accessors */ + + bool usingInlineStorage() const + { + return mBegin == const_cast(this)->inlineStorage(); + } + + T* inlineStorage() + { + return static_cast(mStorage.addr()); + } + + T* beginNoCheck() const + { + return mBegin; + } + + T* endNoCheck() + { + return mBegin + mLength; + } + + const T* endNoCheck() const + { + return mBegin + mLength; + } + +#ifdef DEBUG + size_t reserved() const + { + MOZ_ASSERT(mReserved <= mCapacity); + MOZ_ASSERT(mLength <= mReserved); + return mReserved; + } +#endif + + /* Append operations guaranteed to succeed due to pre-reserved space. */ + template void internalAppend(U&& aU); + template + void internalAppendAll(const VectorBase& aU); + void internalAppendN(const T& aT, size_t aN); + template void internalAppend(const U* aBegin, size_t aLength); + +public: + static const size_t sMaxInlineStorage = N; + + typedef T ElementType; + + explicit VectorBase(AllocPolicy = AllocPolicy()); + explicit VectorBase(ThisVector&&); /* Move constructor. */ + ThisVector& operator=(ThisVector&&); /* Move assignment. */ + ~VectorBase(); + + /* accessors */ + + const AllocPolicy& allocPolicy() const { return *this; } + + AllocPolicy& allocPolicy() { return *this; } + + enum { InlineLength = N }; + + size_t length() const { return mLength; } + + bool empty() const { return mLength == 0; } + + size_t capacity() const { return mCapacity; } + + T* begin() + { + MOZ_ASSERT(!mEntered); + return mBegin; + } + + const T* begin() const + { + MOZ_ASSERT(!mEntered); + return mBegin; + } + + T* end() + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } + + const T* end() const + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } + + T& operator[](size_t aIndex) + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } + + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } + + T& back() + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } + + const T& back() const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } + + class Range + { + friend class VectorBase; + T* mCur; + T* mEnd; + Range(T* aCur, T* aEnd) + : mCur(aCur) + , mEnd(aEnd) + { + MOZ_ASSERT(aCur <= aEnd); + } + + public: + Range() {} + bool empty() const { return mCur == mEnd; } + size_t remain() const { return PointerRangeSize(mCur, mEnd); } + T& front() const { MOZ_ASSERT(!empty()); return *mCur; } + void popFront() { MOZ_ASSERT(!empty()); ++mCur; } + T popCopyFront() { MOZ_ASSERT(!empty()); return *mCur++; } + }; + + Range all() { return Range(begin(), end()); } + + /* mutators */ + + /** + * Given that the vector is empty and has no inline storage, grow to + * |capacity|. + */ + bool initCapacity(size_t aRequest); + + /** + * If reserve(length() + N) succeeds, the N next appends are guaranteed to + * succeed. + */ + bool reserve(size_t aRequest); + + /** + * Destroy elements in the range [end() - aIncr, end()). Does not deallocate + * or unreserve storage for those elements. + */ + void shrinkBy(size_t aIncr); + + /** Grow the vector by aIncr elements. */ + bool growBy(size_t aIncr); + + /** Call shrinkBy or growBy based on whether newSize > length(). */ + bool resize(size_t aNewLength); + + /** + * Increase the length of the vector, but don't initialize the new elements + * -- leave them as uninitialized memory. + */ + bool growByUninitialized(size_t aIncr); + bool resizeUninitialized(size_t aNewLength); + + /** Shorthand for shrinkBy(length()). */ + void clear(); + + /** Clears and releases any heap-allocated storage. */ + void clearAndFree(); + + /** + * If true, appending |aNeeded| elements won't reallocate elements storage. + * This *doesn't* mean that infallibleAppend may be used! You still must + * reserve the extra space, even if this method indicates that appends won't + * need to reallocate elements storage. + */ + bool canAppendWithoutRealloc(size_t aNeeded) const; + + /** Potentially fallible append operations. */ + + /** + * This can take either a T& or a T&&. Given a T&&, it moves |aU| into the + * vector, instead of copying it. If it fails, |aU| is left unmoved. ("We are + * not amused.") + */ + template bool append(U&& aU); + + template + bool appendAll(const VectorBase& aU); + bool appendN(const T& aT, size_t aN); + template bool append(const U* aBegin, const U* aEnd); + template bool append(const U* aBegin, size_t aLength); + + /* + * Guaranteed-infallible append operations for use upon vectors whose + * memory has been pre-reserved. Don't use this if you haven't reserved the + * memory! + */ + template void infallibleAppend(U&& aU) + { + internalAppend(Forward(aU)); + } + void infallibleAppendN(const T& aT, size_t aN) + { + internalAppendN(aT, aN); + } + template void infallibleAppend(const U* aBegin, const U* aEnd) + { + internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); + } + template void infallibleAppend(const U* aBegin, size_t aLength) + { + internalAppend(aBegin, aLength); + } + + void popBack(); + + T popCopy(); + + /** + * Transfers ownership of the internal buffer used by this vector to the + * caller. (It's the caller's responsibility to properly deallocate this + * buffer, in accordance with this vector's AllocPolicy.) After this call, + * the vector is empty. Since the returned buffer may need to be allocated + * (if the elements are currently stored in-place), the call can fail, + * returning nullptr. + * + * N.B. Although a T*, only the range [0, length()) is constructed. + */ + T* extractRawBuffer(); + + /** + * Transfer ownership of an array of objects into the vector. The caller + * must have allocated the array in accordance with this vector's + * AllocPolicy. + * + * N.B. This call assumes that there are no uninitialized elements in the + * passed array. + */ + void replaceRawBuffer(T* aP, size_t aLength); + + /** + * Places |aVal| at position |aP|, shifting existing elements from |aP| onward + * one position higher. On success, |aP| should not be reused because it'll + * be a dangling pointer if reallocation of the vector storage occurred; the + * return value should be used instead. On failure, nullptr is returned. + * + * Example usage: + * + * if (!(p = vec.insert(p, val))) { + * + * } + * + * + * This is inherently a linear-time operation. Be careful! + */ + template + T* insert(T* aP, U&& aVal); + + /** + * Removes the element |aT|, which must fall in the bounds [begin, end), + * shifting existing elements from |aT + 1| onward one position lower. + */ + void erase(T* aT); + + /** + * Removes the elements [|aBegin|, |aEnd|), which must fall in the bounds + * [begin, end), shifting existing elements from |aEnd + 1| onward to aBegin's + * old position. + */ + void erase(T* aBegin, T* aEnd); + + /** + * Measure the size of the vector's heap-allocated storage. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const; + + /** + * Like sizeOfExcludingThis, but also measures the size of the vector + * object (which must be heap-allocated) itself. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; + + void swap(ThisVector& aOther); + +private: + VectorBase(const VectorBase&) MOZ_DELETE; + void operator=(const VectorBase&) MOZ_DELETE; + + /* Move-construct/assign only from our derived class, ThisVector. */ + VectorBase(VectorBase&&) MOZ_DELETE; + void operator=(VectorBase&&) MOZ_DELETE; +}; + +/* This does the re-entrancy check plus several other sanity checks. */ +#define MOZ_REENTRANCY_GUARD_ET_AL \ + ReentrancyGuard g(*this); \ + MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == kInlineCapacity); \ + MOZ_ASSERT(reserved() <= mCapacity); \ + MOZ_ASSERT(mLength <= reserved()); \ + MOZ_ASSERT(mLength <= mCapacity) + +/* Vector Implementation */ + +template +MOZ_ALWAYS_INLINE +VectorBase::VectorBase(AP aAP) + : AP(aAP) + , mLength(0) + , mCapacity(kInlineCapacity) +#ifdef DEBUG + , mReserved(kInlineCapacity) + , mEntered(false) +#endif +{ + mBegin = static_cast(mStorage.addr()); +} + +/* Move constructor. */ +template +MOZ_ALWAYS_INLINE +VectorBase::VectorBase(TV&& aRhs) + : AllocPolicy(Move(aRhs)) +#ifdef DEBUG + , mEntered(false) +#endif +{ + mLength = aRhs.mLength; + mCapacity = aRhs.mCapacity; +#ifdef DEBUG + mReserved = aRhs.mReserved; +#endif + + if (aRhs.usingInlineStorage()) { + /* We can't move the buffer over in this case, so copy elements. */ + mBegin = static_cast(mStorage.addr()); + Impl::moveConstruct(mBegin, aRhs.beginNoCheck(), aRhs.endNoCheck()); + /* + * Leave aRhs's mLength, mBegin, mCapacity, and mReserved as they are. + * The elements in its in-line storage still need to be destroyed. + */ + } else { + /* + * Take src's buffer, and turn src into an empty vector using + * in-line storage. + */ + mBegin = aRhs.mBegin; + aRhs.mBegin = static_cast(aRhs.mStorage.addr()); + aRhs.mCapacity = kInlineCapacity; + aRhs.mLength = 0; +#ifdef DEBUG + aRhs.mReserved = kInlineCapacity; +#endif + } +} + +/* Move assignment. */ +template +MOZ_ALWAYS_INLINE TV& +VectorBase::operator=(TV&& aRhs) +{ + MOZ_ASSERT(this != &aRhs, "self-move assignment is prohibited"); + TV* tv = static_cast(this); + tv->~TV(); + new(tv) TV(Move(aRhs)); + return *tv; +} + +template +MOZ_ALWAYS_INLINE +VectorBase::~VectorBase() +{ + MOZ_REENTRANCY_GUARD_ET_AL; + Impl::destroy(beginNoCheck(), endNoCheck()); + if (!usingInlineStorage()) { + this->free_(beginNoCheck()); + } +} + +/* + * This function will create a new heap buffer with capacity aNewCap, + * move all elements in the inline buffer to this new buffer, + * and fail on OOM. + */ +template +inline bool +VectorBase::convertToHeapStorage(size_t aNewCap) +{ + MOZ_ASSERT(usingInlineStorage()); + + /* Allocate buffer. */ + MOZ_ASSERT(!detail::CapacityHasExcessSpace(aNewCap)); + T* newBuf = reinterpret_cast(this->malloc_(aNewCap * sizeof(T))); + if (!newBuf) { + return false; + } + + /* Copy inline elements into heap buffer. */ + Impl::moveConstruct(newBuf, beginNoCheck(), endNoCheck()); + Impl::destroy(beginNoCheck(), endNoCheck()); + + /* Switch in heap buffer. */ + mBegin = newBuf; + /* mLength is unchanged. */ + mCapacity = aNewCap; + return true; +} + +template +MOZ_NEVER_INLINE bool +VectorBase::growStorageBy(size_t aIncr) +{ + MOZ_ASSERT(mLength + aIncr > mCapacity); + MOZ_ASSERT_IF(!usingInlineStorage(), + !detail::CapacityHasExcessSpace(mCapacity)); + + /* + * When choosing a new capacity, its size should is as close to 2**N bytes + * as possible. 2**N-sized requests are best because they are unlikely to + * be rounded up by the allocator. Asking for a 2**N number of elements + * isn't as good, because if sizeof(T) is not a power-of-two that would + * result in a non-2**N request size. + */ + + size_t newCap; + + if (aIncr == 1) { + if (usingInlineStorage()) { + /* This case occurs in ~70--80% of the calls to this function. */ + size_t newSize = + tl::RoundUpPow2<(kInlineCapacity + 1) * sizeof(T)>::value; + newCap = newSize / sizeof(T); + goto convert; + } + + if (mLength == 0) { + /* This case occurs in ~0--10% of the calls to this function. */ + newCap = 1; + goto grow; + } + + /* This case occurs in ~15--20% of the calls to this function. */ + + /* + * Will mLength * 4 *sizeof(T) overflow? This condition limits a vector + * to 1GB of memory on a 32-bit system, which is a reasonable limit. It + * also ensures that + * + * static_cast(end()) - static_cast(begin()) + * + * doesn't overflow ptrdiff_t (see bug 510319). + */ + if (mLength & tl::MulOverflowMask<4 * sizeof(T)>::value) { + this->reportAllocOverflow(); + return false; + } + + /* + * If we reach here, the existing capacity will have a size that is already + * as close to 2^N as sizeof(T) will allow. Just double the capacity, and + * then there might be space for one more element. + */ + newCap = mLength * 2; + if (detail::CapacityHasExcessSpace(newCap)) { + newCap += 1; + } + } else { + /* This case occurs in ~2% of the calls to this function. */ + size_t newMinCap = mLength + aIncr; + + /* Did mLength + aIncr overflow? Will newCap * sizeof(T) overflow? */ + if (newMinCap < mLength || + newMinCap & tl::MulOverflowMask<2 * sizeof(T)>::value) + { + this->reportAllocOverflow(); + return false; + } + + size_t newMinSize = newMinCap * sizeof(T); + size_t newSize = RoundUpPow2(newMinSize); + newCap = newSize / sizeof(T); + } + + if (usingInlineStorage()) { +convert: + return convertToHeapStorage(newCap); + } + +grow: + return Impl::growTo(*this, newCap); +} + +template +inline bool +VectorBase::initCapacity(size_t aRequest) +{ + MOZ_ASSERT(empty()); + MOZ_ASSERT(usingInlineStorage()); + if (aRequest == 0) { + return true; + } + T* newbuf = reinterpret_cast(this->malloc_(aRequest * sizeof(T))); + if (!newbuf) { + return false; + } + mBegin = newbuf; + mCapacity = aRequest; +#ifdef DEBUG + mReserved = aRequest; +#endif + return true; +} + +template +inline bool +VectorBase::reserve(size_t aRequest) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (aRequest > mCapacity && !growStorageBy(aRequest - mLength)) { + return false; + } +#ifdef DEBUG + if (aRequest > mReserved) { + mReserved = aRequest; + } + MOZ_ASSERT(mLength <= mReserved); + MOZ_ASSERT(mReserved <= mCapacity); +#endif + return true; +} + +template +inline void +VectorBase::shrinkBy(size_t aIncr) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + MOZ_ASSERT(aIncr <= mLength); + Impl::destroy(endNoCheck() - aIncr, endNoCheck()); + mLength -= aIncr; +} + +template +MOZ_ALWAYS_INLINE bool +VectorBase::growBy(size_t aIncr) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { + return false; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + T* newend = endNoCheck() + aIncr; + Impl::initialize(endNoCheck(), newend); + mLength += aIncr; +#ifdef DEBUG + if (mLength > mReserved) { + mReserved = mLength; + } +#endif + return true; +} + +template +MOZ_ALWAYS_INLINE bool +VectorBase::growByUninitialized(size_t aIncr) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { + return false; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + mLength += aIncr; +#ifdef DEBUG + if (mLength > mReserved) { + mReserved = mLength; + } +#endif + return true; +} + +template +inline bool +VectorBase::resize(size_t aNewLength) +{ + size_t curLength = mLength; + if (aNewLength > curLength) { + return growBy(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); + return true; +} + +template +MOZ_ALWAYS_INLINE bool +VectorBase::resizeUninitialized(size_t aNewLength) +{ + size_t curLength = mLength; + if (aNewLength > curLength) { + return growByUninitialized(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); + return true; +} + +template +inline void +VectorBase::clear() +{ + MOZ_REENTRANCY_GUARD_ET_AL; + Impl::destroy(beginNoCheck(), endNoCheck()); + mLength = 0; +} + +template +inline void +VectorBase::clearAndFree() +{ + clear(); + + if (usingInlineStorage()) { + return; + } + this->free_(beginNoCheck()); + mBegin = static_cast(mStorage.addr()); + mCapacity = kInlineCapacity; +#ifdef DEBUG + mReserved = kInlineCapacity; +#endif +} + +template +inline bool +VectorBase::canAppendWithoutRealloc(size_t aNeeded) const +{ + return mLength + aNeeded <= mCapacity; +} + +template +template +MOZ_ALWAYS_INLINE void +VectorBase::internalAppendAll( + const VectorBase& aOther) +{ + internalAppend(aOther.begin(), aOther.length()); +} + +template +template +MOZ_ALWAYS_INLINE void +VectorBase::internalAppend(U&& aU) +{ + MOZ_ASSERT(mLength + 1 <= mReserved); + MOZ_ASSERT(mReserved <= mCapacity); + new(endNoCheck()) T(Forward(aU)); + ++mLength; +} + +template +MOZ_ALWAYS_INLINE bool +VectorBase::appendN(const T& aT, size_t aNeeded) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { + return false; + } +#ifdef DEBUG + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } +#endif + internalAppendN(aT, aNeeded); + return true; +} + +template +MOZ_ALWAYS_INLINE void +VectorBase::internalAppendN(const T& aT, size_t aNeeded) +{ + MOZ_ASSERT(mLength + aNeeded <= mReserved); + MOZ_ASSERT(mReserved <= mCapacity); + Impl::copyConstructN(endNoCheck(), aNeeded, aT); + mLength += aNeeded; +} + +template +template +inline T* +VectorBase::insert(T* aP, U&& aVal) +{ + MOZ_ASSERT(begin() <= aP); + MOZ_ASSERT(aP <= end()); + size_t pos = aP - begin(); + MOZ_ASSERT(pos <= mLength); + size_t oldLength = mLength; + if (pos == oldLength) { + if (!append(Forward(aVal))) { + return nullptr; + } + } else { + T oldBack = Move(back()); + if (!append(Move(oldBack))) { /* Dup the last element. */ + return nullptr; + } + for (size_t i = oldLength; i > pos; --i) { + (*this)[i] = Move((*this)[i - 1]); + } + (*this)[pos] = Forward(aVal); + } + return begin() + pos; +} + +template +inline void +VectorBase::erase(T* aIt) +{ + MOZ_ASSERT(begin() <= aIt); + MOZ_ASSERT(aIt < end()); + while (aIt + 1 < end()) { + *aIt = Move(*(aIt + 1)); + ++aIt; + } + popBack(); +} + +template +inline void +VectorBase::erase(T* aBegin, T* aEnd) +{ + MOZ_ASSERT(begin() <= aBegin); + MOZ_ASSERT(aBegin <= aEnd); + MOZ_ASSERT(aEnd <= end()); + while (aEnd < end()) { + *aBegin++ = Move(*aEnd++); + } + shrinkBy(aEnd - aBegin); +} + +template +template +MOZ_ALWAYS_INLINE bool +VectorBase::append(const U* aInsBegin, const U* aInsEnd) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + size_t aNeeded = PointerRangeSize(aInsBegin, aInsEnd); + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { + return false; + } +#ifdef DEBUG + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } +#endif + internalAppend(aInsBegin, aNeeded); + return true; +} + +template +template +MOZ_ALWAYS_INLINE void +VectorBase::internalAppend(const U* aInsBegin, size_t aInsLength) +{ + MOZ_ASSERT(mLength + aInsLength <= mReserved); + MOZ_ASSERT(mReserved <= mCapacity); + Impl::copyConstruct(endNoCheck(), aInsBegin, aInsBegin + aInsLength); + mLength += aInsLength; +} + +template +template +MOZ_ALWAYS_INLINE bool +VectorBase::append(U&& aU) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + if (mLength == mCapacity && !growStorageBy(1)) { + return false; + } +#ifdef DEBUG + if (mLength + 1 > mReserved) { + mReserved = mLength + 1; + } +#endif + internalAppend(Forward(aU)); + return true; +} + +template +template +MOZ_ALWAYS_INLINE bool +VectorBase::appendAll(const VectorBase& aOther) +{ + return append(aOther.begin(), aOther.length()); +} + +template +template +MOZ_ALWAYS_INLINE bool +VectorBase::append(const U* aInsBegin, size_t aInsLength) +{ + return append(aInsBegin, aInsBegin + aInsLength); +} + +template +MOZ_ALWAYS_INLINE void +VectorBase::popBack() +{ + MOZ_REENTRANCY_GUARD_ET_AL; + MOZ_ASSERT(!empty()); + --mLength; + endNoCheck()->~T(); +} + +template +MOZ_ALWAYS_INLINE T +VectorBase::popCopy() +{ + T ret = back(); + popBack(); + return ret; +} + +template +inline T* +VectorBase::extractRawBuffer() +{ + T* ret; + if (usingInlineStorage()) { + ret = reinterpret_cast(this->malloc_(mLength * sizeof(T))); + if (!ret) { + return nullptr; + } + Impl::copyConstruct(ret, beginNoCheck(), endNoCheck()); + Impl::destroy(beginNoCheck(), endNoCheck()); + /* mBegin, mCapacity are unchanged. */ + mLength = 0; + } else { + ret = mBegin; + mBegin = static_cast(mStorage.addr()); + mLength = 0; + mCapacity = kInlineCapacity; +#ifdef DEBUG + mReserved = kInlineCapacity; +#endif + } + return ret; +} + +template +inline void +VectorBase::replaceRawBuffer(T* aP, size_t aLength) +{ + MOZ_REENTRANCY_GUARD_ET_AL; + + /* Destroy what we have. */ + Impl::destroy(beginNoCheck(), endNoCheck()); + if (!usingInlineStorage()) { + this->free_(beginNoCheck()); + } + + /* Take in the new buffer. */ + if (aLength <= kInlineCapacity) { + /* + * We convert to inline storage if possible, even though aP might + * otherwise be acceptable. Maybe this behaviour should be + * specifiable with an argument to this function. + */ + mBegin = static_cast(mStorage.addr()); + mLength = aLength; + mCapacity = kInlineCapacity; + Impl::moveConstruct(mBegin, aP, aP + aLength); + Impl::destroy(aP, aP + aLength); + this->free_(aP); + } else { + mBegin = aP; + mLength = aLength; + mCapacity = aLength; + } +#ifdef DEBUG + mReserved = aLength; +#endif +} + +template +inline size_t +VectorBase::sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const +{ + return usingInlineStorage() ? 0 : aMallocSizeOf(beginNoCheck()); +} + +template +inline size_t +VectorBase::sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const +{ + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); +} + +template +inline void +VectorBase::swap(TV& aOther) +{ + static_assert(N == 0, + "still need to implement this for N != 0"); + + // This only works when inline storage is always empty. + if (!usingInlineStorage() && aOther.usingInlineStorage()) { + aOther.mBegin = mBegin; + mBegin = inlineStorage(); + } else if (usingInlineStorage() && !aOther.usingInlineStorage()) { + mBegin = aOther.mBegin; + aOther.mBegin = aOther.inlineStorage(); + } else if (!usingInlineStorage() && !aOther.usingInlineStorage()) { + Swap(mBegin, aOther.mBegin); + } else { + // This case is a no-op, since we'd set both to use their inline storage. + } + + Swap(mLength, aOther.mLength); + Swap(mCapacity, aOther.mCapacity); +#ifdef DEBUG + Swap(mReserved, aOther.mReserved); +#endif +} + +/* + * STL-like container providing a short-lived, dynamic buffer. Vector calls the + * constructors/destructors of all elements stored in its internal buffer, so + * non-PODs may be safely used. Additionally, Vector will store the first N + * elements in-place before resorting to dynamic allocation. + * + * T requirements: + * - default and copy constructible, assignable, destructible + * - operations do not throw + * N requirements: + * - any value, however, N is clamped to min/max values + * AllocPolicy: + * - see "Allocation policies" in AllocPolicy.h (defaults to + * mozilla::MallocAllocPolicy) + * + * Vector is not reentrant: T member functions called during Vector member + * functions must not call back into the same object! + */ +template +class Vector + : public VectorBase > +{ + typedef VectorBase Base; + +public: + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + Vector(Vector&& vec) : Base(Move(vec)) {} + Vector& operator=(Vector&& aOther) + { + return Base::operator=(Move(aOther)); + } +}; + +} // namespace mozilla + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#endif /* mozilla_Vector_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/WeakPtr.h b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/WeakPtr.h new file mode 100644 index 0000000000..07f00bc295 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/wp_8.1/mozilla/WeakPtr.h @@ -0,0 +1,202 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Weak pointer functionality, implemented as a mixin for use with any class. */ + +/** + * SupportsWeakPtr lets you have a pointer to an object 'Foo' without affecting + * its lifetime. It works by creating a single shared reference counted object + * (WeakReference) that each WeakPtr will access 'Foo' through. This lets 'Foo' + * clear the pointer in the WeakReference without having to know about all of + * the WeakPtrs to it and allows the WeakReference to live beyond the lifetime + * of 'Foo'. + * + * PLEASE NOTE: This weak pointer implementation is not thread-safe. + * + * Note that when deriving from SupportsWeakPtr you should add + * MOZ_DECLARE_REFCOUNTED_TYPENAME(ClassName) to the public section of your + * class, where ClassName is the name of your class. + * + * The overhead of WeakPtr is that accesses to 'Foo' becomes an additional + * dereference, and an additional heap allocated pointer sized object shared + * between all of the WeakPtrs. + * + * Example of usage: + * + * // To have a class C support weak pointers, inherit from + * // SupportsWeakPtr. + * class C : public SupportsWeakPtr + * { + * public: + * MOZ_DECLARE_REFCOUNTED_TYPENAME(C) + * int mNum; + * void act(); + * }; + * + * C* ptr = new C(); + * + * // Get weak pointers to ptr. The first time asWeakPtr is called + * // a reference counted WeakReference object is created that + * // can live beyond the lifetime of 'ptr'. The WeakReference + * // object will be notified of 'ptr's destruction. + * WeakPtr weak = ptr->asWeakPtr(); + * WeakPtr other = ptr->asWeakPtr(); + * + * // Test a weak pointer for validity before using it. + * if (weak) { + * weak->mNum = 17; + * weak->act(); + * } + * + * // Destroying the underlying object clears weak pointers to it. + * delete ptr; + * + * MOZ_ASSERT(!weak, "Deleting |ptr| clears weak pointers to it."); + * MOZ_ASSERT(!other, "Deleting |ptr| clears all weak pointers to it."); + * + * WeakPtr is typesafe and may be used with any class. It is not required that + * the class be reference-counted or allocated in any particular way. + * + * The API was loosely inspired by Chromium's weak_ptr.h: + * http://src.chromium.org/svn/trunk/src/base/memory/weak_ptr.h + */ + +#ifndef mozilla_WeakPtr_h +#define mozilla_WeakPtr_h + +#include "mozilla/ArrayUtils.h" +#include "mozilla/Assertions.h" +#include "mozilla/NullPtr.h" +#include "mozilla/RefPtr.h" +#include "mozilla/TypeTraits.h" + +#include + +namespace mozilla { + +template class WeakPtrBase; +template class SupportsWeakPtrBase; + +namespace detail { + +// This can live beyond the lifetime of the class derived from +// SupportsWeakPtrBase. +template +class WeakReference : public ::mozilla::RefCounted > +{ +public: + explicit WeakReference(T* p) : mPtr(p) {} + + T* get() const { return mPtr; } + +#ifdef MOZ_REFCOUNTED_LEAK_CHECKING +#ifdef XP_WIN +#define snprintf _snprintf +#endif + const char* typeName() const + { + static char nameBuffer[1024]; + const char* innerType = mPtr->typeName(); + // We could do fancier length checks at runtime, but innerType is + // controlled by us so we can ensure that this never causes a buffer + // overflow by this assertion. + MOZ_ASSERT(strlen(innerType) + sizeof("WeakReference<>") < + ArrayLength(nameBuffer), + "Exceedingly large type name"); + snprintf(nameBuffer, ArrayLength(nameBuffer), "WeakReference<%s>", + innerType); + // This is usually not OK, but here we are returning a pointer to a static + // buffer which will immediately be used by the caller. + return nameBuffer; + } + + size_t typeSize() const { return sizeof(*this); } +#undef snprintf +#endif + +private: + friend class WeakPtrBase >; + friend class SupportsWeakPtrBase >; + + void detach() { mPtr = nullptr; } + + T* mPtr; +}; + +} // namespace detail + +template +class SupportsWeakPtrBase +{ +public: + WeakPtrBase asWeakPtr() + { + if (!weakRef) { + weakRef = new WeakReference(static_cast(this)); + } + return WeakPtrBase(weakRef); + } + +protected: + ~SupportsWeakPtrBase() + { + static_assert(IsBaseOf, T>::value, + "T must derive from SupportsWeakPtrBase"); + if (weakRef) { + weakRef->detach(); + } + } + +private: + friend class WeakPtrBase; + + RefPtr weakRef; +}; + +template +class SupportsWeakPtr : public SupportsWeakPtrBase > +{ +}; + +template +class WeakPtrBase +{ +public: + WeakPtrBase(const WeakPtrBase& aOther) + : mRef(aOther.mRef) + {} + + // Ensure that mRef is dereferenceable in the uninitialized state. + WeakPtrBase() : mRef(new WeakReference(nullptr)) {} + + operator T*() const { return mRef->get(); } + T& operator*() const { return *mRef->get(); } + + T* operator->() const { return mRef->get(); } + + T* get() const { return mRef->get(); } + +private: + friend class SupportsWeakPtrBase; + + explicit WeakPtrBase(const RefPtr &aOther) : mRef(aOther) {} + + RefPtr mRef; +}; + +template +class WeakPtr : public WeakPtrBase > +{ + typedef WeakPtrBase > Base; +public: + WeakPtr(const WeakPtr& aOther) : Base(aOther) {} + MOZ_IMPLICIT WeakPtr(const Base& aOther) : Base(aOther) {} + WeakPtr() {} +}; + +} // namespace mozilla + +#endif /* mozilla_WeakPtr_h */ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/android/armeabi-v7a/libjs_static.a b/frameworks/js-bindings/external/spidermonkey/prebuilt/android/armeabi-v7a/libjs_static.a index 8e5c119c57..9cb692f532 100644 Binary files a/frameworks/js-bindings/external/spidermonkey/prebuilt/android/armeabi-v7a/libjs_static.a and b/frameworks/js-bindings/external/spidermonkey/prebuilt/android/armeabi-v7a/libjs_static.a differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/android/armeabi/libjs_static.a b/frameworks/js-bindings/external/spidermonkey/prebuilt/android/armeabi/libjs_static.a index 800a3feac2..45fc46f7b9 100644 Binary files a/frameworks/js-bindings/external/spidermonkey/prebuilt/android/armeabi/libjs_static.a and b/frameworks/js-bindings/external/spidermonkey/prebuilt/android/armeabi/libjs_static.a differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/android/x86/libjs_static.a b/frameworks/js-bindings/external/spidermonkey/prebuilt/android/x86/libjs_static.a index 2b2d455474..9278c3e0b5 100644 Binary files a/frameworks/js-bindings/external/spidermonkey/prebuilt/android/x86/libjs_static.a and b/frameworks/js-bindings/external/spidermonkey/prebuilt/android/x86/libjs_static.a differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/ios/libjs_static.a b/frameworks/js-bindings/external/spidermonkey/prebuilt/ios/libjs_static.a index 27206413c3..35a293b2a7 100644 Binary files a/frameworks/js-bindings/external/spidermonkey/prebuilt/ios/libjs_static.a and b/frameworks/js-bindings/external/spidermonkey/prebuilt/ios/libjs_static.a differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/linux/32-bit/libjs_static.a b/frameworks/js-bindings/external/spidermonkey/prebuilt/linux/32-bit/libjs_static.a index ca5cced3e6..758f6ca776 100644 Binary files a/frameworks/js-bindings/external/spidermonkey/prebuilt/linux/32-bit/libjs_static.a and b/frameworks/js-bindings/external/spidermonkey/prebuilt/linux/32-bit/libjs_static.a differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/linux/64-bit/libjs_static.a b/frameworks/js-bindings/external/spidermonkey/prebuilt/linux/64-bit/libjs_static.a index ba15609fa0..a01481efe5 100644 Binary files a/frameworks/js-bindings/external/spidermonkey/prebuilt/linux/64-bit/libjs_static.a and b/frameworks/js-bindings/external/spidermonkey/prebuilt/linux/64-bit/libjs_static.a differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/mac/libjs_static.a b/frameworks/js-bindings/external/spidermonkey/prebuilt/mac/libjs_static.a index e8f13bafe7..6e27270f41 100644 Binary files a/frameworks/js-bindings/external/spidermonkey/prebuilt/mac/libjs_static.a and b/frameworks/js-bindings/external/spidermonkey/prebuilt/mac/libjs_static.a differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/debug-build/mozjs-33.dll b/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/debug-build/mozjs-33.dll new file mode 100644 index 0000000000..3dc1eb8707 Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/debug-build/mozjs-33.dll differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/debug-build/mozjs-33.lib b/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/debug-build/mozjs-33.lib new file mode 100644 index 0000000000..1d56e1709b Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/debug-build/mozjs-33.lib differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/mozjs-28.dll b/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/mozjs-28.dll deleted file mode 100644 index 398d199be9..0000000000 Binary files a/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/mozjs-28.dll and /dev/null differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/mozjs-28.lib b/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/mozjs-28.lib deleted file mode 100644 index e6919d03a4..0000000000 Binary files a/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/mozjs-28.lib and /dev/null differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/release-build/mozjs-33.dll b/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/release-build/mozjs-33.dll new file mode 100644 index 0000000000..ba943abf81 Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/release-build/mozjs-33.dll differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/release-build/mozjs-33.lib b/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/release-build/mozjs-33.lib new file mode 100644 index 0000000000..5b55105577 Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/win32/release-build/mozjs-33.lib differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/winrt_8.1/arm/mozjs-33.dll b/frameworks/js-bindings/external/spidermonkey/prebuilt/winrt_8.1/arm/mozjs-33.dll new file mode 100644 index 0000000000..a39734058e Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/winrt_8.1/arm/mozjs-33.dll differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/winrt_8.1/arm/mozjs-33.lib b/frameworks/js-bindings/external/spidermonkey/prebuilt/winrt_8.1/arm/mozjs-33.lib new file mode 100644 index 0000000000..52c8033f1e Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/winrt_8.1/arm/mozjs-33.lib differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/winrt_8.1/win32/mozjs-33.dll b/frameworks/js-bindings/external/spidermonkey/prebuilt/winrt_8.1/win32/mozjs-33.dll new file mode 100644 index 0000000000..ef987b334c Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/winrt_8.1/win32/mozjs-33.dll differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/winrt_8.1/win32/mozjs-33.lib b/frameworks/js-bindings/external/spidermonkey/prebuilt/winrt_8.1/win32/mozjs-33.lib new file mode 100644 index 0000000000..1b991f9e0f Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/winrt_8.1/win32/mozjs-33.lib differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/wp8/arm/mozjs-33.dll b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp8/arm/mozjs-33.dll new file mode 100644 index 0000000000..49be0f1958 Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp8/arm/mozjs-33.dll differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/wp8/arm/mozjs-33.lib b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp8/arm/mozjs-33.lib new file mode 100644 index 0000000000..c43eae34a8 Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp8/arm/mozjs-33.lib differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/wp8/win32/mozjs-33.dll b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp8/win32/mozjs-33.dll new file mode 100644 index 0000000000..d92866d8b4 Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp8/win32/mozjs-33.dll differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/wp8/win32/mozjs-33.lib b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp8/win32/mozjs-33.lib new file mode 100644 index 0000000000..1f2a75923b Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp8/win32/mozjs-33.lib differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/wp_8.1/arm/mozjs-33.dll b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp_8.1/arm/mozjs-33.dll new file mode 100644 index 0000000000..e7f25c3003 Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp_8.1/arm/mozjs-33.dll differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/wp_8.1/arm/mozjs-33.lib b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp_8.1/arm/mozjs-33.lib new file mode 100644 index 0000000000..70d513800d Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp_8.1/arm/mozjs-33.lib differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/wp_8.1/win32/mozjs-33.dll b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp_8.1/win32/mozjs-33.dll new file mode 100644 index 0000000000..20b2be0a75 Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp_8.1/win32/mozjs-33.dll differ diff --git a/frameworks/js-bindings/external/spidermonkey/prebuilt/wp_8.1/win32/mozjs-33.lib b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp_8.1/win32/mozjs-33.lib new file mode 100644 index 0000000000..0adb9e4d57 Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp_8.1/win32/mozjs-33.lib differ diff --git a/frameworks/js-bindings/external/win8.1-universal/OpenGLESPage.xaml b/frameworks/js-bindings/external/win8.1-universal/OpenGLESPage.xaml new file mode 100644 index 0000000000..2e15f8140d --- /dev/null +++ b/frameworks/js-bindings/external/win8.1-universal/OpenGLESPage.xaml @@ -0,0 +1,28 @@ + + + + + + + + + + + diff --git a/frameworks/js-bindings/external/win8.1-universal/OpenGLESPage.xaml.cpp b/frameworks/js-bindings/external/win8.1-universal/OpenGLESPage.xaml.cpp new file mode 100644 index 0000000000..5f12e22a94 --- /dev/null +++ b/frameworks/js-bindings/external/win8.1-universal/OpenGLESPage.xaml.cpp @@ -0,0 +1,330 @@ +/* +* cocos2d-x http://www.cocos2d-x.org +* +* Copyright (c) 2010-2014 - cocos2d-x community +* +* Portions Copyright (c) Microsoft Open Technologies, Inc. +* All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and limitations under the License. +*/ + +#include "App.xaml.h" +#include "OpenGLESPage.xaml.h" + +using namespace cocos2d; +using namespace Platform; +using namespace Concurrency; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::Graphics::Display; +using namespace Windows::System::Threading; +using namespace Windows::UI::Core; +using namespace Windows::UI::Input; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +using namespace Windows::UI::Xaml::Controls::Primitives; +using namespace Windows::UI::Xaml::Data; +using namespace Windows::UI::Xaml::Input; +using namespace Windows::UI::Xaml::Media; +using namespace Windows::UI::Xaml::Navigation; + +#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) +using namespace Windows::Phone::UI::Input; +#endif + +OpenGLESPage::OpenGLESPage() : + OpenGLESPage(nullptr) +{ + +} + +OpenGLESPage::OpenGLESPage(OpenGLES* openGLES) : + mOpenGLES(openGLES), + mRenderSurface(EGL_NO_SURFACE), + mCustomRenderSurfaceSize(0,0), + mUseCustomRenderSurfaceSize(false), + m_coreInput(nullptr), + m_dpi(0.0f), + m_visible(false), + m_deviceLost(false), + m_orientation(DisplayOrientations::Landscape) +{ + InitializeComponent(); + + Windows::UI::Core::CoreWindow^ window = Windows::UI::Xaml::Window::Current->CoreWindow; + + window->VisibilityChanged += + ref new Windows::Foundation::TypedEventHandler(this, &OpenGLESPage::OnVisibilityChanged); + + swapChainPanel->SizeChanged += + ref new Windows::UI::Xaml::SizeChangedEventHandler(this, &OpenGLESPage::OnSwapChainPanelSizeChanged); + + DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); + + currentDisplayInformation->OrientationChanged += + ref new TypedEventHandler(this, &OpenGLESPage::OnOrientationChanged); + + m_orientation = currentDisplayInformation->CurrentOrientation; + + this->Loaded += + ref new Windows::UI::Xaml::RoutedEventHandler(this, &OpenGLESPage::OnPageLoaded); + + mSwapChainPanelSize = { swapChainPanel->RenderSize.Width, swapChainPanel->RenderSize.Height }; + +#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) + Windows::UI::ViewManagement::StatusBar::GetForCurrentView()->HideAsync(); + HardwareButtons::BackPressed += ref new EventHandler(this, &OpenGLESPage::OnBackButtonPressed); +#else + // Disable all pointer visual feedback for better performance when touching. + // This is not supported on Windows Phone applications. + auto pointerVisualizationSettings = Windows::UI::Input::PointerVisualizationSettings::GetForCurrentView(); + pointerVisualizationSettings->IsContactFeedbackEnabled = false; + pointerVisualizationSettings->IsBarrelButtonFeedbackEnabled = false; +#endif + + // Register our SwapChainPanel to get independent input pointer events + auto workItemHandler = ref new WorkItemHandler([this](IAsyncAction ^) + { + // The CoreIndependentInputSource will raise pointer events for the specified device types on whichever thread it's created on. + m_coreInput = swapChainPanel->CreateCoreIndependentInputSource( + Windows::UI::Core::CoreInputDeviceTypes::Mouse | + Windows::UI::Core::CoreInputDeviceTypes::Touch | + Windows::UI::Core::CoreInputDeviceTypes::Pen + ); + + // Register for pointer events, which will be raised on the background thread. + m_coreInput->PointerPressed += ref new TypedEventHandler(this, &OpenGLESPage::OnPointerPressed); + m_coreInput->PointerMoved += ref new TypedEventHandler(this, &OpenGLESPage::OnPointerMoved); + m_coreInput->PointerReleased += ref new TypedEventHandler(this, &OpenGLESPage::OnPointerReleased); + + // Begin processing input messages as they're delivered. + m_coreInput->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit); + }); + + // Run task on a dedicated high priority background thread. + m_inputLoopWorker = ThreadPool::RunAsync(workItemHandler, WorkItemPriority::High, WorkItemOptions::TimeSliced); + +} + +OpenGLESPage::~OpenGLESPage() +{ + StopRenderLoop(); + DestroyRenderSurface(); +} + +void OpenGLESPage::OnPageLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + // The SwapChainPanel has been created and arranged in the page layout, so EGL can be initialized. + CreateRenderSurface(); + m_visible = true; + StartRenderLoop(); +} + +void OpenGLESPage::OnPointerPressed(Object^ sender, PointerEventArgs^ e) +{ + if (m_renderer) + { + m_renderer->QueuePointerEvent(PointerEventType::PointerPressed, e); + } +} + +void OpenGLESPage::OnPointerMoved(Object^ sender, PointerEventArgs^ e) +{ + if (m_renderer) + { + m_renderer->QueuePointerEvent(PointerEventType::PointerMoved, e); + } +} + +void OpenGLESPage::OnPointerReleased(Object^ sender, PointerEventArgs^ e) +{ + if (m_renderer) + { + m_renderer->QueuePointerEvent(PointerEventType::PointerReleased, e); + } +} + +void OpenGLESPage::OnOrientationChanged(DisplayInformation^ sender, Object^ args) +{ + critical_section::scoped_lock lock(mSwapChainPanelSizeCriticalSection); + m_orientation = sender->CurrentOrientation; +} + +void OpenGLESPage::OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args) +{ + if (args->Visible && mRenderSurface != EGL_NO_SURFACE) + { + m_visible = true; + } + else + { + m_visible = false; + } +} + +#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) +void OpenGLESPage::OnBackButtonPressed(Object^ sender, BackPressedEventArgs^ args) +{ + bool myAppCanNavigate = false; + if (myAppCanNavigate) + { + args->Handled = true; + } + else { + // Do nothing. Leave args->Handled set to the current value, false. + } +} +#endif + + +void OpenGLESPage::OnSwapChainPanelSizeChanged(Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e) +{ + // Size change events occur outside of the render thread. A lock is required when updating + // the swapchainpanel size + critical_section::scoped_lock lock(mSwapChainPanelSizeCriticalSection); + mSwapChainPanelSize = { e->NewSize.Width, e->NewSize.Height }; +} + +void OpenGLESPage::GetSwapChainPanelSize(GLsizei* width, GLsizei* height) +{ + critical_section::scoped_lock lock(mSwapChainPanelSizeCriticalSection); + // If a custom render surface size is specified, return its size instead of + // the swapchain panel size. + if (mUseCustomRenderSurfaceSize) + { + *width = static_cast(mCustomRenderSurfaceSize.Width); + *height = static_cast(mCustomRenderSurfaceSize.Height); + } + else + { + *width = static_cast(mSwapChainPanelSize.Width); + *height = static_cast(mSwapChainPanelSize.Height); + } +} + +void OpenGLESPage::CreateRenderSurface() +{ + if (mOpenGLES) + { + // + // A Custom render surface size can be specified by uncommenting the following lines. + // The render surface will be automatically scaled to fit the entire window. Using a + // smaller sized render surface can result in a performance gain. + // + //mCustomRenderSurfaceSize = Size(800, 600); + //mUseCustomRenderSurfaceSize = true; + + mRenderSurface = mOpenGLES->CreateSurface(swapChainPanel, mUseCustomRenderSurfaceSize ? &mCustomRenderSurfaceSize : nullptr); + } +} + +void OpenGLESPage::DestroyRenderSurface() +{ + if (mOpenGLES) + { + mOpenGLES->DestroySurface(mRenderSurface); + } + mRenderSurface = EGL_NO_SURFACE; +} + +void OpenGLESPage::RecoverFromLostDevice() +{ + // resets OpenGLES, recreates the render surface + DestroyRenderSurface(); + mOpenGLES->Reset(); + CreateRenderSurface(); +} + +void OpenGLESPage::StartRenderLoop() +{ + // If the render loop is already running then do not start another thread. + if (mRenderLoopWorker != nullptr && mRenderLoopWorker->Status == Windows::Foundation::AsyncStatus::Started) + { + return; + } + + DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); + m_dpi = currentDisplayInformation->LogicalDpi; + + auto dispatcher = Windows::UI::Xaml::Window::Current->CoreWindow->Dispatcher; + + // Create a task for rendering that will be run on a background thread. + auto workItemHandler = ref new Windows::System::Threading::WorkItemHandler([this, dispatcher](Windows::Foundation::IAsyncAction ^ action) + { + mOpenGLES->MakeCurrent(mRenderSurface); + GLsizei panelWidth = 0; + GLsizei panelHeight = 0; + GetSwapChainPanelSize(&panelWidth, &panelHeight); + + if (m_renderer.get() == nullptr) + { + m_renderer = std::make_shared(panelWidth, panelHeight, m_dpi, m_orientation, dispatcher, swapChainPanel); + } + + m_renderer->Resume(); + + while (action->Status == Windows::Foundation::AsyncStatus::Started) + { + if (!m_visible) + { + m_renderer->Pause(); + while (!m_visible) + { + if (action->Status != Windows::Foundation::AsyncStatus::Started) + { + return; + } + Sleep(500); + } + m_renderer->Resume(); + } + + GetSwapChainPanelSize(&panelWidth, &panelHeight); + m_renderer.get()->Draw(panelWidth, panelHeight, m_dpi, m_orientation); + + // The call to eglSwapBuffers might not be successful (i.e. due to Device Lost) + // If the call fails, then we must reinitialize EGL and the GL resources. + if (mOpenGLES->SwapBuffers(mRenderSurface) != GL_TRUE) + { + m_deviceLost = true; + + // XAML objects like the SwapChainPanel must only be manipulated on the UI thread. + swapChainPanel->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([=]() + { + RecoverFromLostDevice(); + }, CallbackContext::Any)); + + while(m_deviceLost) + { + if (action->Status != Windows::Foundation::AsyncStatus::Started) + { + return; + } + Sleep(500); + } + mOpenGLES->MakeCurrent(mRenderSurface); + m_renderer->DeviceLost(); + } + } + }); + + // Run task on a dedicated high priority background thread. + mRenderLoopWorker = Windows::System::Threading::ThreadPool::RunAsync(workItemHandler, Windows::System::Threading::WorkItemPriority::High, Windows::System::Threading::WorkItemOptions::TimeSliced); +} + +void OpenGLESPage::StopRenderLoop() +{ + if (mRenderLoopWorker) + { + mRenderLoopWorker->Cancel(); + mRenderLoopWorker = nullptr; + } +} \ No newline at end of file diff --git a/frameworks/js-bindings/external/win8.1-universal/OpenGLESPage.xaml.h b/frameworks/js-bindings/external/win8.1-universal/OpenGLESPage.xaml.h new file mode 100644 index 0000000000..daddd59e23 --- /dev/null +++ b/frameworks/js-bindings/external/win8.1-universal/OpenGLESPage.xaml.h @@ -0,0 +1,82 @@ +/* +* cocos2d-x http://www.cocos2d-x.org +* +* Copyright (c) 2010-2014 - cocos2d-x community +* +* Portions Copyright (c) Microsoft Open Technologies, Inc. +* All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and limitations under the License. +*/ + +#pragma once + +#include "OpenGLES.h" +#include "OpenGLESPage.g.h" +#include +#include + +#include "Cocos2dRenderer.h" + +namespace cocos2d +{ + public ref class OpenGLESPage sealed + { + public: + OpenGLESPage(); + virtual ~OpenGLESPage(); + + internal: + OpenGLESPage(OpenGLES* openGLES); + + private: + void OnPageLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); + void OnSwapChainPanelSizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e); +#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) + void OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args); +#endif + void GetSwapChainPanelSize(GLsizei* width, GLsizei* height); + void CreateRenderSurface(); + void DestroyRenderSurface(); + void RecoverFromLostDevice(); + void StartRenderLoop(); + void StopRenderLoop(); + + OpenGLES* mOpenGLES; + std::shared_ptr m_renderer; + + Windows::Foundation::Size mSwapChainPanelSize; + Concurrency::critical_section mSwapChainPanelSizeCriticalSection; + + Windows::Foundation::Size mCustomRenderSurfaceSize; + bool mUseCustomRenderSurfaceSize; + + EGLSurface mRenderSurface; // This surface is associated with a swapChainPanel on the page + Windows::Foundation::IAsyncAction^ mRenderLoopWorker; + + // Track user input on a background worker thread. + Windows::Foundation::IAsyncAction^ m_inputLoopWorker; + Windows::UI::Core::CoreIndependentInputSource^ m_coreInput; + + // Independent input handling functions. + void OnPointerPressed(Platform::Object^ sender, Windows::UI::Core::PointerEventArgs^ e); + void OnPointerMoved(Platform::Object^ sender, Windows::UI::Core::PointerEventArgs^ e); + void OnPointerReleased(Platform::Object^ sender, Windows::UI::Core::PointerEventArgs^ e); + + void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); + + float m_dpi; + std::atomic m_visible; + std::atomic m_deviceLost; + Windows::Graphics::Display::DisplayOrientations m_orientation; + + }; +} diff --git a/samples/js-moonwarriors/.cocos-project.json b/samples/js-moonwarriors/.cocos-project.json index d8531ee39f..dd34a6ad82 100644 --- a/samples/js-moonwarriors/.cocos-project.json +++ b/samples/js-moonwarriors/.cocos-project.json @@ -25,5 +25,23 @@ "run_root_dir": "../../", "sub_url": "/samples/js-moonwarriors/" }, + "wp8_cfg" : { + "project_path": "../../build", + "sln_file": "cocos2d-jsb-samples.wp8.sln", + "project_name": "js-moonwarriors", + "wp8_proj_path" : "project/proj.wp8-xaml", + "build_folder_path": "js-moonwarriors/Bin/x86", + "manifest_path": "js-moonwarriors/Properties/WMAppManifest.xml" + }, + "wp8_1_cfg" : { + "project_path": "../../build", + "sln_file": "cocos2d-jsb-samples-win8.1-universal.sln", + "project_name": "js-moonwarriors.WindowsPhone" + }, + "metro_cfg" : { + "project_path": "../../build", + "sln_file": "cocos2d-jsb-samples-win8.1-universal.sln", + "project_name": "js-moonwarriors.Windows" + }, "engine_dir": "../../" } diff --git a/samples/js-moonwarriors/build.xml b/samples/js-moonwarriors/build.xml deleted file mode 100644 index e90dc7cf94..0000000000 --- a/samples/js-moonwarriors/build.xml +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/samples/js-moonwarriors/main.js b/samples/js-moonwarriors/main.js index 5ec710f1cf..dbb691def8 100755 --- a/samples/js-moonwarriors/main.js +++ b/samples/js-moonwarriors/main.js @@ -77,6 +77,7 @@ */ cc.game.onStart = function(){ + cc.view.enableRetina(false); cc.view.adjustViewPort(true); cc.view.setDesignResolutionSize(480,720,cc.ResolutionPolicy.SHOW_ALL); cc.view.resizeWithBrowserSize(true); diff --git a/samples/js-moonwarriors/project/Classes/AppDelegate.cpp b/samples/js-moonwarriors/project/Classes/AppDelegate.cpp index 08f7a7557d..60777a7feb 100644 --- a/samples/js-moonwarriors/project/Classes/AppDelegate.cpp +++ b/samples/js-moonwarriors/project/Classes/AppDelegate.cpp @@ -1,8 +1,6 @@ #include "AppDelegate.h" -#include "cocos2d.h" #include "SimpleAudioEngine.h" -#include "ScriptingCore.h" #include "jsb_cocos2dx_auto.hpp" #include "cocos2d_specifics.hpp" #include "localstorage/js_bindings_system_registration.h" @@ -32,7 +30,11 @@ bool AppDelegate::applicationDidFinishLaunching() auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) + glview = cocos2d::GLViewImpl::create("js-moonwarriors"); +#else glview = cocos2d::GLViewImpl::createWithRect("js-moonwarriors", Rect(0, 0, 480, 720)); +#endif director->setOpenGLView(glview); } @@ -42,7 +44,6 @@ bool AppDelegate::applicationDidFinishLaunching() ScriptingCore* sc = ScriptingCore::getInstance(); sc->addRegisterCallback(register_all_cocos2dx); sc->addRegisterCallback(register_cocos2dx_js_core); - sc->addRegisterCallback(register_cocos2dx_js_extensions); sc->addRegisterCallback(jsb_register_system); sc->start(); diff --git a/samples/js-moonwarriors/project/proj.win32/js-moonwarriors.vcxproj b/samples/js-moonwarriors/project/proj.win32/js-moonwarriors.vcxproj index d6e73b1447..12475d76d9 100644 --- a/samples/js-moonwarriors/project/proj.win32/js-moonwarriors.vcxproj +++ b/samples/js-moonwarriors/project/proj.win32/js-moonwarriors.vcxproj @@ -49,10 +49,10 @@ <_ProjectFileVersion>10.0.40219.1 - $(SolutionDir)$(Configuration).win32\ + $(SolutionDir)$(Configuration).win32\js-moonwarriors\ $(Configuration).win32\ false - $(SolutionDir)$(Configuration).win32\ + $(SolutionDir)$(Configuration).win32\js-moonwarriors\ $(Configuration).win32\ false AllRules.ruleset @@ -102,28 +102,28 @@ if not exist "$(OutDir)" mkdir "$(OutDir)" -xcopy /Y /Q "$(ProjectDir)..\..\..\..\frameworks\js-bindings\external\spidermonkey\prebuilt\win32\*.*" "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\..\..\..\frameworks\js-bindings\external\spidermonkey\prebuilt\win32\debug-build\*.*" "$(OutDir)" - libcurl_imp.lib;mozjs-28.lib;ws2_32.lib;sqlite3.lib;%(AdditionalDependencies) - $(OutDir);%(AdditionalLibraryDirectories) + libcurl_imp.lib;mozjs-33.lib;ws2_32.lib;sqlite3.lib;%(AdditionalDependencies) + $(OutDir);$(SolutionDir)$(Configuration).win32;%(AdditionalLibraryDirectories) true Windows MachineX86 if not exist "$(OutDir)" mkdir "$(OutDir)" -if exist "$(OutDir)\js-moonwarriors-res" rd /s /q "$(OutDir)\js-moonwarriors-res" -mkdir "$(OutDir)\js-moonwarriors-res" -mkdir "$(OutDir)\js-moonwarriors-res\script" -mkdir "$(OutDir)\js-moonwarriors-res\src" -mkdir "$(OutDir)\js-moonwarriors-res\res" -xcopy "$(ProjectDir)..\..\..\..\frameworks\js-bindings\bindings\script\*" "$(OutDir)\js-moonwarriors-res\script" /e /Y -xcopy "$(ProjectDir)..\..\src" "$(OutDir)\js-moonwarriors-res\src\" /e /Y -xcopy "$(ProjectDir)..\..\res" "$(OutDir)\js-moonwarriors-res\res\" /e /Y -copy "$(ProjectDir)..\..\main.js" "$(OutDir)\js-moonwarriors-res" -copy "$(ProjectDir)..\..\project.json" "$(OutDir)\js-moonwarriors-res" + +mkdir "$(OutDir)\script" +mkdir "$(OutDir)\src" +mkdir "$(OutDir)\res" +xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y +xcopy "$(ProjectDir)..\..\..\..\frameworks\js-bindings\bindings\script\*" "$(OutDir)\script" /e /Y +xcopy "$(ProjectDir)..\..\src" "$(OutDir)\src\" /e /Y +xcopy "$(ProjectDir)..\..\res" "$(OutDir)\res\" /e /Y +copy "$(ProjectDir)..\..\main.js" "$(OutDir)" +copy "$(ProjectDir)..\..\project.json" "$(OutDir)" Copy js and resource files. @@ -161,28 +161,28 @@ copy "$(ProjectDir)..\..\project.json" "$(OutDir)\js-moonwarriors-res" if not exist "$(OutDir)" mkdir "$(OutDir)" -xcopy /Y /Q "$(ProjectDir)..\..\..\..\frameworks\js-bindings\external\spidermonkey\prebuilt\win32\*.*" "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\..\..\..\frameworks\js-bindings\external\spidermonkey\prebuilt\win32\release-build\*.*" "$(OutDir)" - libcurl_imp.lib;mozjs-28.lib;ws2_32.lib;sqlite3.lib;%(AdditionalDependencies) - $(OutDir);%(AdditionalLibraryDirectories) + libcurl_imp.lib;mozjs-33.lib;ws2_32.lib;sqlite3.lib;%(AdditionalDependencies) + $(OutDir);$(SolutionDir)$(Configuration).win32;%(AdditionalLibraryDirectories) Windows MachineX86 true if not exist "$(OutDir)" mkdir "$(OutDir)" -if exist "$(OutDir)\js-moonwarriors-res" rd /s /q "$(OutDir)\js-moonwarriors-res" -mkdir "$(OutDir)\js-moonwarriors-res" -mkdir "$(OutDir)\js-moonwarriors-res\script" -mkdir "$(OutDir)\js-moonwarriors-res\src" -mkdir "$(OutDir)\js-moonwarriors-res\res" -xcopy "$(ProjectDir)..\..\..\..\frameworks\js-bindings\bindings\script\*" "$(OutDir)\js-moonwarriors-res\script" /e /Y -xcopy "$(ProjectDir)..\..\src" "$(OutDir)\js-moonwarriors-res\src\" /e /Y -xcopy "$(ProjectDir)..\..\res" "$(OutDir)\js-moonwarriors-res\res\" /e /Y -copy "$(ProjectDir)..\..\main.js" "$(OutDir)\js-moonwarriors-res" -copy "$(ProjectDir)..\..\project.json" "$(OutDir)\js-moonwarriors-res" + +mkdir "$(OutDir)\script" +mkdir "$(OutDir)\src" +mkdir "$(OutDir)\res" +xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y +xcopy "$(ProjectDir)..\..\..\..\frameworks\js-bindings\bindings\script\*" "$(OutDir)\script" /e /Y +xcopy "$(ProjectDir)..\..\src" "$(OutDir)\src\" /e /Y +xcopy "$(ProjectDir)..\..\res" "$(OutDir)\res\" /e /Y +copy "$(ProjectDir)..\..\main.js" "$(OutDir)" +copy "$(ProjectDir)..\..\project.json" "$(OutDir)" Copy js and resource files. diff --git a/samples/js-moonwarriors/project/proj.win32/js-moonwarriors.vcxproj.user b/samples/js-moonwarriors/project/proj.win32/js-moonwarriors.vcxproj.user index 648163f8c0..d07a4daaf2 100644 --- a/samples/js-moonwarriors/project/proj.win32/js-moonwarriors.vcxproj.user +++ b/samples/js-moonwarriors/project/proj.win32/js-moonwarriors.vcxproj.user @@ -1,11 +1,12 @@  - $(OutDir)\js-moonwarriors-res + $(OutDir) WindowsLocalDebugger - $(OutDir)\js-moonwarriors-res + + WindowsLocalDebugger \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.win32/main.cpp b/samples/js-moonwarriors/project/proj.win32/main.cpp index 69c3b8c9bb..d4cf6c3490 100644 --- a/samples/js-moonwarriors/project/proj.win32/main.cpp +++ b/samples/js-moonwarriors/project/proj.win32/main.cpp @@ -24,7 +24,6 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, // create the application instance AppDelegate app; int ret = Application::getInstance()->run(); - #ifdef USE_WIN32_CONSOLE FreeConsole(); #endif diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/App.xaml b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/App.xaml new file mode 100644 index 0000000000..7c15a5d78f --- /dev/null +++ b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/App.xaml @@ -0,0 +1,13 @@ + + + + + cpp_tests + + + diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/App.xaml.cpp b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/App.xaml.cpp new file mode 100644 index 0000000000..07cd4853e6 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/App.xaml.cpp @@ -0,0 +1,21 @@ +#include "App.xaml.h" +#include "OpenGLESPage.xaml.h" + +using namespace cocos2d; + +App::App() +{ + InitializeComponent(); +} + +void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) +{ + if (mPage == nullptr) + { + mPage = ref new OpenGLESPage(&mOpenGLES); + } + + // Place the page in the current window and ensure that it is active. + Windows::UI::Xaml::Window::Current->Content = mPage; + Windows::UI::Xaml::Window::Current->Activate(); +} diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/App.xaml.h b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/App.xaml.h new file mode 100644 index 0000000000..ce4d7c8bfd --- /dev/null +++ b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/App.xaml.h @@ -0,0 +1,19 @@ +#pragma once + +#include "app.g.h" +#include "OpenGLES.h" +#include "openglespage.xaml.h" + +namespace cocos2d +{ + ref class App sealed + { + public: + App(); + virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) override; + + private: + OpenGLESPage^ mPage; + OpenGLES mOpenGLES; + }; +} diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/js-moonwarriors.Shared.vcxitems b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/js-moonwarriors.Shared.vcxitems new file mode 100644 index 0000000000..2c19028268 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/js-moonwarriors.Shared.vcxitems @@ -0,0 +1,60 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + e956c24b-f04e-47bf-bf00-746681ae1301 + {a3ad93e4-0b2f-4c58-9181-69bed2e42e3e} + js-moonwarriors + + + + %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) + + + + + Designer + + + + + $(MSBuildThisFileDirectory)..\..\..\..\..\frameworks\js-bindings\external\win8.1-universal\OpenGLESPage.xaml + + + + $(MSBuildThisFileDirectory)App.xaml + + + Create + + + + + $(MSBuildThisFileDirectory)..\..\..\..\..\frameworks\js-bindings\external\win8.1-universal\OpenGLESPage.xaml + + + + $(MSBuildThisFileDirectory)App.xaml + + + + + + + + <_CustomResource Include="$(MSBuildThisFileDirectory)..\..\Resources\**\*"> + Assets\Resources\%(RecursiveDir)%(FileName)%(Extension) + true + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/js-moonwarriors.Shared.vcxitems.filters b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/js-moonwarriors.Shared.vcxitems.filters new file mode 100644 index 0000000000..c84fc7b68e --- /dev/null +++ b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/js-moonwarriors.Shared.vcxitems.filters @@ -0,0 +1,34 @@ + + + + + + + + Classes + + + + + + + + + + + {38ad799c-8c3c-44a2-8e41-516c8f62f556} + + + + + + Classes + + + + + + + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/pch.cpp b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/pch.cpp new file mode 100644 index 0000000000..e0d2ef1a2a --- /dev/null +++ b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/pch.h b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/pch.h new file mode 100644 index 0000000000..97049bb300 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Shared/pch.h @@ -0,0 +1,13 @@ +// +// pch.h +// Header for standard system include files. +// + +#pragma once + +#include "mozilla\Char16.h" +#include "cocos2d.h" +#include "cocos-ext.h" + + + diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Assets/Logo.scale-100.png b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Assets/Logo.scale-100.png new file mode 100644 index 0000000000..e26771cb33 Binary files /dev/null and b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Assets/Logo.scale-100.png differ diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Assets/SmallLogo.scale-100.png b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Assets/SmallLogo.scale-100.png new file mode 100644 index 0000000000..1eb0d9d528 Binary files /dev/null and b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Assets/SmallLogo.scale-100.png differ diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Assets/SplashScreen.scale-100.png b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Assets/SplashScreen.scale-100.png new file mode 100644 index 0000000000..d8ded7198a Binary files /dev/null and b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Assets/SplashScreen.scale-100.png differ diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Assets/StoreLogo.scale-100.png b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Assets/StoreLogo.scale-100.png new file mode 100644 index 0000000000..dcb672712c Binary files /dev/null and b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Assets/StoreLogo.scale-100.png differ diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Package.appxmanifest b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Package.appxmanifest new file mode 100644 index 0000000000..b814dcde09 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/Package.appxmanifest @@ -0,0 +1,29 @@ + + + + + js-moonwarriors.Windows + msopentech + Assets\StoreLogo.png + + + 6.3.0 + 6.3.0 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/js-moonwarriors.Windows.vcxproj b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/js-moonwarriors.Windows.vcxproj new file mode 100644 index 0000000000..a36354a4ea --- /dev/null +++ b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/js-moonwarriors.Windows.vcxproj @@ -0,0 +1,202 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM + + + Release + Win32 + + + Release + x64 + + + + {79a8fcda-4b12-4dd1-b676-ff148d651638} + cocos2d + en-US + 12.0 + true + Windows Store + 8.1 + + + + Application + true + v120 + + + Application + true + v120 + + + Application + true + v120 + + + Application + false + false + v120 + + + Application + false + false + v120 + + + Application + false + false + v120 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + js-moonwarriors.Windows_TemporaryKey.pfx + True + x86 + FB58178D2A50D64A72EC25130D072580B999A12E + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + + + Designer + + + + + + + + + + + + {bcf5546d-66a0-4998-afd6-c5514f618930} + + + {9335005f-678e-4e8e-9b84-50037216aec8} + + + {f3550fe0-c795-44f6-8feb-093eb68143ae} + + + {3b26a12d-3a44-47ea-82d2-282660fc844d} + + + + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/js-moonwarriors.Windows.vcxproj.filters b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/js-moonwarriors.Windows.vcxproj.filters new file mode 100644 index 0000000000..049d8f31f9 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/js-moonwarriors.Windows.vcxproj.filters @@ -0,0 +1,29 @@ + + + + + {1a9fa652-867e-41d2-8588-962f108d2d8f} + bmp;fbx;gif;jpg;jpeg;tga;tiff;tif;png + + + + + + + + + + + Assets + + + Assets + + + Assets + + + Assets + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/js-moonwarriors.Windows_TemporaryKey.pfx b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/js-moonwarriors.Windows_TemporaryKey.pfx new file mode 100644 index 0000000000..a5b8824cbb Binary files /dev/null and b/samples/js-moonwarriors/project/proj.win8.1-universal/App.Windows/js-moonwarriors.Windows_TemporaryKey.pfx differ diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/Logo.scale-240.png b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/Logo.scale-240.png new file mode 100644 index 0000000000..76921ca997 Binary files /dev/null and b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/Logo.scale-240.png differ diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/SmallLogo.scale-240.png b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/SmallLogo.scale-240.png new file mode 100644 index 0000000000..316630124f Binary files /dev/null and b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/SmallLogo.scale-240.png differ diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/SplashScreen.scale-240.png b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/SplashScreen.scale-240.png new file mode 100644 index 0000000000..3926e6c936 Binary files /dev/null and b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/SplashScreen.scale-240.png differ diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/Square71x71Logo.scale-240.png b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/Square71x71Logo.scale-240.png new file mode 100644 index 0000000000..cfa54bee03 Binary files /dev/null and b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/Square71x71Logo.scale-240.png differ diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/StoreLogo.scale-240.png b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/StoreLogo.scale-240.png new file mode 100644 index 0000000000..47e084b593 Binary files /dev/null and b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/StoreLogo.scale-240.png differ diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/WideLogo.scale-240.png b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/WideLogo.scale-240.png new file mode 100644 index 0000000000..6249d29db0 Binary files /dev/null and b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Assets/WideLogo.scale-240.png differ diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Package.appxmanifest b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Package.appxmanifest new file mode 100644 index 0000000000..d47cc8c07c --- /dev/null +++ b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/Package.appxmanifest @@ -0,0 +1,32 @@ + + + + + + js-moonwarriors.WindowsPhone + dalestam + Assets\StoreLogo.png + + + 6.3.1 + 6.3.1 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/js-moonwarriors.WindowsPhone.vcxproj b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/js-moonwarriors.WindowsPhone.vcxproj new file mode 100644 index 0000000000..61ac75734a --- /dev/null +++ b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/js-moonwarriors.WindowsPhone.vcxproj @@ -0,0 +1,151 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Release + ARM + + + Release + Win32 + + + + {396fe85e-bb05-4b92-bccb-f89aed4ea41a} + cocos2d + en-US + 12.0 + true + Windows Phone + 8.1 + + + + Application + true + v120_wp81 + + + Application + true + v120_wp81 + + + Application + false + false + v120_wp81 + + + Application + false + false + v120_wp81 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + arm + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + + + Designer + + + + + + + + + + + + + {ca082ec4-17ce-430b-8207-d1e947a5d1e9} + + + {22f3b9df-1209-4574-8331-003966f562bf} + + + {cc1da216-a80d-4be4-b309-acb6af313aff} + + + {22f798d8-bfff-4754-996f-a5395343d5ec} + + + + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/js-moonwarriors.WindowsPhone.vcxproj.filters b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/js-moonwarriors.WindowsPhone.vcxproj.filters new file mode 100644 index 0000000000..08414f1f0c --- /dev/null +++ b/samples/js-moonwarriors/project/proj.win8.1-universal/App.WindowsPhone/js-moonwarriors.WindowsPhone.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {c8beb60d-689b-4aaa-9749-99bd3e2dcf75} + bmp;fbx;gif;jpg;jpeg;tga;tiff;tif;png + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.win8.1-universal/resources.props b/samples/js-moonwarriors/project/proj.win8.1-universal/resources.props new file mode 100644 index 0000000000..cc54464cfb --- /dev/null +++ b/samples/js-moonwarriors/project/proj.win8.1-universal/resources.props @@ -0,0 +1,63 @@ + + + + + + + $(EngineRoot)..\bindings\manual;$(EngineRoot)..\bindings\auto;$(EngineRoot)..\external\spidermonkey\include\$(COCOS2D_PLATFORM);$(EngineRoot)cocos\base;%(AdditionalIncludeDirectories); + + + mozjs-33.lib;%(AdditionalDependencies) + $(EngineRoot)..\external\spidermonkey\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);%(AdditionalLibraryDirectories); + + + + + $(EngineRoot)..\external\spidermonkey\prebuilt\$(COCOS2D_PLATFORM)\$(Platform)\ + + + + + true + + + + + <_CustomResource Include="..\..\..\res\**\*"> + Assets\Resources\res\%(RecursiveDir)%(FileName)%(Extension) + true + + + + <_CustomResource Include="..\..\..\src\**\*"> + Assets\Resources\src\%(RecursiveDir)%(FileName)%(Extension) + true + + + + <_CustomResource Include="..\..\..\..\..\frameworks\js-bindings\bindings\script\**\*"> + Assets\Resources\script\%(RecursiveDir)%(FileName)%(Extension) + true + + + + <_CustomResource Include="..\..\..\main.js"> + Assets\Resources\%(RecursiveDir)%(FileName)%(Extension) + true + + + + <_CustomResource Include="..\..\..\project.json"> + Assets\Resources\%(RecursiveDir)%(FileName)%(Extension) + true + + + + + + + + + + + diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors.sln b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors.sln new file mode 100644 index 0000000000..00a9cf4a68 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors.sln @@ -0,0 +1,74 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "js-moonwarriors", "js-moonwarriors\js-moonwarriors.csproj", "{5921FE12-7EF3-4847-8453-42EF286DDBE7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "js-moonwarriorsComponent", "js-moonwarriorsComponent\js-moonwarriorsComponent.vcxproj", "{F5D665F8-AE19-4F3F-99A7-230A1E8305D2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|ARM = Debug|ARM + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|Win32 = Debug|Win32 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM + Release|Mixed Platforms = Release|Mixed Platforms + Release|Win32 = Release|Win32 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|ARM.ActiveCfg = Debug|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|ARM.Build.0 = Debug|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|ARM.Deploy.0 = Debug|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Mixed Platforms.Deploy.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Win32.ActiveCfg = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Win32.Build.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Win32.Deploy.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|x86.ActiveCfg = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|x86.Build.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|x86.Deploy.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Any CPU.Build.0 = Release|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Any CPU.Deploy.0 = Release|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|ARM.ActiveCfg = Release|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|ARM.Build.0 = Release|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|ARM.Deploy.0 = Release|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Mixed Platforms.Build.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Mixed Platforms.Deploy.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Win32.ActiveCfg = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Win32.Build.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Win32.Deploy.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|x86.ActiveCfg = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|x86.Build.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|x86.Deploy.0 = Release|x86 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|ARM.ActiveCfg = Debug|ARM + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|ARM.Build.0 = Debug|ARM + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Win32.ActiveCfg = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Win32.Build.0 = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|x86.ActiveCfg = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|x86.Build.0 = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Any CPU.ActiveCfg = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|ARM.ActiveCfg = Release|ARM + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|ARM.Build.0 = Release|ARM + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Mixed Platforms.Build.0 = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Win32.ActiveCfg = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Win32.Build.0 = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|x86.ActiveCfg = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/AlignmentGrid.png b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/AlignmentGrid.png new file mode 100644 index 0000000000..f7d2e97804 Binary files /dev/null and b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/AlignmentGrid.png differ diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/ApplicationIcon.png b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/ApplicationIcon.png new file mode 100644 index 0000000000..7d95d4e081 Binary files /dev/null and b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/ApplicationIcon.png differ diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/FlipCycleTileLarge.png b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/FlipCycleTileLarge.png new file mode 100644 index 0000000000..e0c59ac014 Binary files /dev/null and b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/FlipCycleTileLarge.png differ diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/FlipCycleTileMedium.png b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/FlipCycleTileMedium.png new file mode 100644 index 0000000000..e93b89d600 Binary files /dev/null and b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/FlipCycleTileMedium.png differ diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/FlipCycleTileSmall.png b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/FlipCycleTileSmall.png new file mode 100644 index 0000000000..550b1b5e8d Binary files /dev/null and b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/FlipCycleTileSmall.png differ diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/IconicTileMediumLarge.png b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/IconicTileMediumLarge.png new file mode 100644 index 0000000000..686e6b53f0 Binary files /dev/null and b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/IconicTileMediumLarge.png differ diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/IconicTileSmall.png b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/IconicTileSmall.png new file mode 100644 index 0000000000..d4b5ede1b5 Binary files /dev/null and b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Assets/Tiles/IconicTileSmall.png differ diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/LocalizedStrings.cs b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/LocalizedStrings.cs new file mode 100644 index 0000000000..4c0d4ba292 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/LocalizedStrings.cs @@ -0,0 +1,14 @@ +using cocos2d.Resources; + +namespace cocos2d +{ + /// + /// Provides access to string resources. + /// + public class LocalizedStrings + { + private static AppResources _localizedResources = new AppResources(); + + public AppResources LocalizedResources { get { return _localizedResources; } } + } +} \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/MainPage.xaml b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/MainPage.xaml new file mode 100644 index 0000000000..88a685fff2 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/MainPage.xaml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Package.appxmanifest b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Package.appxmanifest new file mode 100644 index 0000000000..d383a3ca06 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Package.appxmanifest @@ -0,0 +1,59 @@ + + + + + + + + + js-moonwarriors + dalestam + Assets\StoreLogo.png + + + + 6.3.1 + 6.3.1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + AgHostSvcs.dll + + + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Properties/AppManifest.xml b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Properties/AppManifest.xml new file mode 100644 index 0000000000..6712a11783 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Properties/AppManifest.xml @@ -0,0 +1,6 @@ + + + + diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Properties/AssemblyInfo.cs b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..c5921e1749 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Properties/AssemblyInfo.cs @@ -0,0 +1,37 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Resources; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("cocos2d")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("cocos2d")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e9152507-1b95-4fca-9d7f-444a024ccb98")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: NeutralResourcesLanguageAttribute("en-US")] diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Properties/WMAppManifest.xml b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Properties/WMAppManifest.xml new file mode 100644 index 0000000000..dda3c68394 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Properties/WMAppManifest.xml @@ -0,0 +1,42 @@ + + + + + Assets\ApplicationIcon.png + + + + + + + + + + + + + + Assets\Tiles\FlipCycleTileSmall.png + 0 + Assets\Tiles\FlipCycleTileMedium.png + js-moonwarriors + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Resources/AppResources.Designer.cs b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Resources/AppResources.Designer.cs new file mode 100644 index 0000000000..efb4f0a46c --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Resources/AppResources.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.34014 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace cocos2d.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class AppResources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal AppResources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("cocos2d.Resources.AppResources", typeof(AppResources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to MY APPLICATION. + /// + public static string ApplicationTitle { + get { + return ResourceManager.GetString("ApplicationTitle", resourceCulture); + } + } + } +} diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Resources/AppResources.resx b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Resources/AppResources.resx new file mode 100644 index 0000000000..13e5fdc678 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/Resources/AppResources.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + MY APPLICATION + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/SplashScreenImage.jpg b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/SplashScreenImage.jpg new file mode 100644 index 0000000000..825b04652a Binary files /dev/null and b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/SplashScreenImage.jpg differ diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/js-moonwarriors.csproj b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/js-moonwarriors.csproj new file mode 100644 index 0000000000..9139865860 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/js-moonwarriors.csproj @@ -0,0 +1,208 @@ + + + + Debug + AnyCPU + 10.0.20506 + 2.0 + {5921FE12-7EF3-4847-8453-42EF286DDBE7} + {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + cocos2d + js-moonwarriors + WindowsPhone + v8.0 + $(TargetFrameworkVersion) + true + + + true + true + js-moonwarriors_$(Configuration)_$(Platform).xap + Properties\AppManifest.xml + cocos2d.App + true + 11.0 + true + + + true + full + false + Bin\Debug + DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + pdbonly + true + Bin\Release + TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + true + full + false + Bin\x86\Debug + DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + pdbonly + true + Bin\x86\Release + TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + true + full + false + Bin\ARM\Debug + DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + pdbonly + true + Bin\ARM\Release + TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + + App.xaml.cs + + + EditBox.xaml.cs + + + MainPage.xaml.cs + + + + + True + True + AppResources.resx + + + + + + Designer + + + + + PreserveNewest + + + + + + + + + + + + PublicResXFileCodeGenerator + AppResources.Designer.cs + + + + + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2} + js-moonwarriorsComponent + + + + + Assets\Resources\fonts\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + + + + + Assets\Resources\res\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + + + + + Assets\Resources\src\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + + + + + Assets\Resources\script\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + + + + + Assets\Resources\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + + + + + Assets\Resources\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + + + + + App.xaml + MSBuild:Compile + Designer + + + EditBox.xaml + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/js-moonwarriors.csproj.user b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/js-moonwarriors.csproj.user new file mode 100644 index 0000000000..ffd0bfc785 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriors/js-moonwarriors.csproj.user @@ -0,0 +1,31 @@ + + + + 256 + 5E7661DF-D928-40ff-B747-A4B1957194F9 + + + 256 + 5E7661DF-D928-40ff-B747-A4B1957194F9 + + + 256 + 30F105C9-681E-420b-A277-7C086EAD8A4E + + + 256 + 30F105C9-681E-420b-A277-7C086EAD8A4E + + + + + + False + Native + Native + False + + + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/js-moonwarriorsComponent.vcxproj b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/js-moonwarriorsComponent.vcxproj new file mode 100644 index 0000000000..2440f7b1c4 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/js-moonwarriorsComponent.vcxproj @@ -0,0 +1,237 @@ + + + + + Debug + Win32 + + + Debug + ARM + + + Release + Win32 + + + Release + ARM + + + + {f5d665f8-ae19-4f3f-99a7-230a1e8305d2} + cocos2d + en-US + 11.0 + true + + + + + $(OutDir)\$(MSBuildProjectName)\ + + $(SolutionDir)$(Configuration)\$(MSBuildProjectName)\ + $(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)\ + + false + + + DynamicLibrary + true + v110_wp80 + + + DynamicLibrary + true + v110_wp80 + + + DynamicLibrary + false + true + v110_wp80 + + + DynamicLibrary + false + true + v110_wp80 + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + + CC_ENABLE_CHIPMUNK_INTEGRATION=1;COCOS2D_DEBUG=1;%(PreprocessorDefinitions) + Use + pch.h + $(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories) + true + $(EngineRoot)..\bindings\manual;$(EngineRoot)..\bindings\auto;$(EngineRoot)..\external\spidermonkey\include\wp8;$(EngineRoot)cocos\base;$(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + pch.h + /Zm200 %(AdditionalOptions) + %(DisableSpecificWarnings) + false + + + Console + false + mozjs-33.lib;%(AdditionalDependencies) + ole32.lib;%(IgnoreSpecificDefaultLibraries) + true + $(EngineRoot)..\external\spidermonkey\prebuilt\wp8\$(Platform);%(AdditionalLibraryDirectories) + LinkVerbose + + + + + CC_ENABLE_CHIPMUNK_INTEGRATION=1;NDEBUG;%(PreprocessorDefinitions) + Use + pch.h + $(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories) + true + $(EngineRoot)..\bindings\manual;$(EngineRoot)..\bindings\auto;$(EngineRoot)..\external\spidermonkey\include\wp8;$(EngineRoot)cocos\base;$(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + pch.h + /Zm200 %(AdditionalOptions) + %(DisableSpecificWarnings) + false + + + Console + false + mozjs-33.lib;%(AdditionalDependencies) + ole32.lib;%(IgnoreSpecificDefaultLibraries) + true + $(EngineRoot)..\external\spidermonkey\prebuilt\wp8\$(Platform);%(AdditionalLibraryDirectories) + LinkVerbose + + + + + CC_ENABLE_CHIPMUNK_INTEGRATION=1;COCOS2D_DEBUG=1;%(PreprocessorDefinitions) + Use + pch.h + $(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories) + true + $(EngineRoot)..\bindings\manual;$(EngineRoot)..\bindings\auto;$(EngineRoot)..\external\spidermonkey\include\wp8;$(EngineRoot)cocos\base;$(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + pch.h + /Zm200 %(AdditionalOptions) + %(DisableSpecificWarnings) + true + false + + + Console + false + mozjs-33.lib;%(AdditionalDependencies) + ole32.lib;%(IgnoreSpecificDefaultLibraries) + true + $(EngineRoot)..\external\spidermonkey\prebuilt\wp8\$(Platform);%(AdditionalLibraryDirectories) + + + + + CC_ENABLE_CHIPMUNK_INTEGRATION=1;NDEBUG;%(PreprocessorDefinitions) + Use + pch.h + $(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories) + true + $(EngineRoot)..\bindings\manual;$(EngineRoot)..\bindings\auto;$(EngineRoot)..\external\spidermonkey\include\wp8;$(EngineRoot)cocos\base;$(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + pch.h + /Zm200 %(AdditionalOptions) + %(DisableSpecificWarnings) + false + + + Console + false + mozjs-33.lib;%(AdditionalDependencies) + ole32.lib;%(IgnoreSpecificDefaultLibraries) + true + $(EngineRoot)..\external\spidermonkey\prebuilt\wp8\$(Platform);%(AdditionalLibraryDirectories) + + + + + true + false + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + + + + + + + + {dd11890a-006e-4d4b-bbe6-a577601288a2} + + + {7c5dbc42-27f6-4978-aabc-02ba77e2a7f0} + + + {7d4fc6eb-9497-4804-98f3-3eaedc896154} + + + {c55734a3-702c-4fa1-b950-32c8e169302f} + + + + + true + true + + + true + true + + + + + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/js-moonwarriorsComponent.vcxproj.filters b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/js-moonwarriorsComponent.vcxproj.filters new file mode 100644 index 0000000000..f4d41931f2 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/js-moonwarriorsComponent.vcxproj.filters @@ -0,0 +1,42 @@ + + + + + {ebfae752-00fd-4f6a-ac89-7f565a8a5a52} + + + + + Classes + + + + + + + + + + + Classes + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/js-moonwarriorsComponent.vcxproj.user b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/js-moonwarriorsComponent.vcxproj.user new file mode 100644 index 0000000000..b0dc84df25 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/js-moonwarriorsComponent.vcxproj.user @@ -0,0 +1,6 @@ + + + + true + + \ No newline at end of file diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/pch.cpp b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/pch.cpp new file mode 100644 index 0000000000..bcb5590be1 --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" diff --git a/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/pch.h b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/pch.h new file mode 100644 index 0000000000..7a5e3975ae --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/pch.h @@ -0,0 +1,4 @@ +#pragma once + +#include "mozilla\Char16.h" +#include "cocos2d.h" diff --git a/samples/js-moonwarriors/res/Music/bgMusic.wav b/samples/js-moonwarriors/res/Music/bgMusic.wav new file mode 100644 index 0000000000..7940abdcbb Binary files /dev/null and b/samples/js-moonwarriors/res/Music/bgMusic.wav differ diff --git a/samples/js-moonwarriors/res/Music/buttonEffet.wav b/samples/js-moonwarriors/res/Music/buttonEffet.wav new file mode 100644 index 0000000000..cb1eeb3386 Binary files /dev/null and b/samples/js-moonwarriors/res/Music/buttonEffet.wav differ diff --git a/samples/js-moonwarriors/res/Music/explodeEffect.wav b/samples/js-moonwarriors/res/Music/explodeEffect.wav new file mode 100644 index 0000000000..e9f3d116a1 Binary files /dev/null and b/samples/js-moonwarriors/res/Music/explodeEffect.wav differ diff --git a/samples/js-moonwarriors/res/Music/fireEffect.wav b/samples/js-moonwarriors/res/Music/fireEffect.wav new file mode 100644 index 0000000000..38121949f3 Binary files /dev/null and b/samples/js-moonwarriors/res/Music/fireEffect.wav differ diff --git a/samples/js-moonwarriors/res/Music/mainMainMusic.wav b/samples/js-moonwarriors/res/Music/mainMainMusic.wav new file mode 100644 index 0000000000..55c3ab1457 Binary files /dev/null and b/samples/js-moonwarriors/res/Music/mainMainMusic.wav differ diff --git a/samples/js-moonwarriors/res/Music/shipDestroyEffect.wav b/samples/js-moonwarriors/res/Music/shipDestroyEffect.wav new file mode 100644 index 0000000000..ba7c0ca165 Binary files /dev/null and b/samples/js-moonwarriors/res/Music/shipDestroyEffect.wav differ diff --git a/samples/js-moonwarriors/res/explode.plist b/samples/js-moonwarriors/res/explode.plist deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/samples/js-moonwarriors/res/fonts/arial.ttf b/samples/js-moonwarriors/res/fonts/arial.ttf new file mode 100644 index 0000000000..abc899cd55 Binary files /dev/null and b/samples/js-moonwarriors/res/fonts/arial.ttf differ diff --git a/samples/js-moonwarriors/res/gameOver.png b/samples/js-moonwarriors/res/gameOver.png index 9597adb7b5..432659e041 100755 Binary files a/samples/js-moonwarriors/res/gameOver.png and b/samples/js-moonwarriors/res/gameOver.png differ diff --git a/samples/js-moonwarriors/res/gameoverBack.png b/samples/js-moonwarriors/res/gameoverBack.png new file mode 100644 index 0000000000..9975853ce3 Binary files /dev/null and b/samples/js-moonwarriors/res/gameoverBack.png differ diff --git a/samples/js-moonwarriors/res/loading.png b/samples/js-moonwarriors/res/loading.png index 4df7215fe1..27115ac957 100755 Binary files a/samples/js-moonwarriors/res/loading.png and b/samples/js-moonwarriors/res/loading.png differ diff --git a/samples/js-moonwarriors/res/logo.png b/samples/js-moonwarriors/res/logo.png index 7cfb647187..18c643708c 100755 Binary files a/samples/js-moonwarriors/res/logo.png and b/samples/js-moonwarriors/res/logo.png differ diff --git a/samples/js-moonwarriors/res/logoBack.png b/samples/js-moonwarriors/res/logoBack.png new file mode 100644 index 0000000000..6fc952b2a4 Binary files /dev/null and b/samples/js-moonwarriors/res/logoBack.png differ diff --git a/samples/js-moonwarriors/res/menu.png b/samples/js-moonwarriors/res/menu.png index 36ea9b3887..364ab06500 100755 Binary files a/samples/js-moonwarriors/res/menu.png and b/samples/js-moonwarriors/res/menu.png differ diff --git a/samples/js-moonwarriors/res/menuTitle.png b/samples/js-moonwarriors/res/menuTitle.png index 8df2d07c31..7383b319d9 100755 Binary files a/samples/js-moonwarriors/res/menuTitle.png and b/samples/js-moonwarriors/res/menuTitle.png differ diff --git a/samples/js-moonwarriors/src/AboutLayer.js b/samples/js-moonwarriors/src/AboutLayer.js index 4a6fa5703a..931fc081e8 100755 --- a/samples/js-moonwarriors/src/AboutLayer.js +++ b/samples/js-moonwarriors/src/AboutLayer.js @@ -43,7 +43,7 @@ var AboutLayer = cc.Layer.extend({ this.addChild(sp, 0, 1); var cacheImage = cc.textureCache.addImage(res.menuTitle_png); - var title = new cc.Sprite(cacheImage, cc.rect(0, 36, 100, 34)); + var title = new cc.Sprite(cacheImage, cc.rect(0, 40, 120, 38)); title.x = winSize.width / 2; title.y = winSize.height - 60; this.addChild(title); @@ -56,9 +56,11 @@ var AboutLayer = cc.Layer.extend({ anchorX: 0.5, anchorY: 0.5 }); + about.setColor(cc.color(MW.FONTCOLOR)); this.addChild(about); var label = new cc.LabelTTF("Go back", "Arial", 21); + label.setColor(cc.color(MW.FONTCOLOR)); var back = new cc.MenuItemLabel(label, this.onBackCallback); var menu = new cc.Menu(back); menu.x = winSize.width / 2; diff --git a/samples/js-moonwarriors/src/Enemy.js b/samples/js-moonwarriors/src/Enemy.js index 71a22d84a6..4ac507deb7 100755 --- a/samples/js-moonwarriors/src/Enemy.js +++ b/samples/js-moonwarriors/src/Enemy.js @@ -86,7 +86,7 @@ var Enemy = cc.Sprite.extend({ }); SparkEffect.getOrCreateSparkEffect(this.x, this.y); if (MW.SOUND) { - cc.audioEngine.playEffect(res.explodeEffect_mp3); + cc.audioEngine.playEffect(cc.sys.os == cc.sys.OS_WP8 || cc.sys.os == cc.sys.OS_WINRT ? res.explodeEffect_wav : res.explodeEffect_mp3); } this.visible = false; this.active = false; diff --git a/samples/js-moonwarriors/src/GameControlMenu.js b/samples/js-moonwarriors/src/GameControlMenu.js index 47f2087383..d350e24803 100755 --- a/samples/js-moonwarriors/src/GameControlMenu.js +++ b/samples/js-moonwarriors/src/GameControlMenu.js @@ -39,6 +39,7 @@ var GameControlMenu = cc.Layer.extend({ cc.MenuItemFont.setFontSize(24); cc.MenuItemFont.setFontName("Arial"); var systemMenu = new cc.MenuItemFont("Main Menu", this.onSysMenu); + systemMenu.setColor(cc.color(MW.FONTCOLOR)); var menu = new cc.Menu(systemMenu); menu.x = 0; menu.y = 0; diff --git a/samples/js-moonwarriors/src/GameLayer.js b/samples/js-moonwarriors/src/GameLayer.js index 9f6f98fc7f..c56c7e14e1 100755 --- a/samples/js-moonwarriors/src/GameLayer.js +++ b/samples/js-moonwarriors/src/GameLayer.js @@ -175,7 +175,7 @@ var GameLayer = cc.Layer.extend({ this.schedule(this.scoreCounter, 1); if (MW.SOUND) - cc.audioEngine.playMusic(res.bgMusic_mp3, true); + cc.audioEngine.playMusic(cc.sys.os == cc.sys.OS_WP8 || cc.sys.os == cc.sys.OS_WINRT ? res.bgMusic_wav : res.bgMusic_mp3, true); g_sharedGameLayer = this; diff --git a/samples/js-moonwarriors/src/GameOver.js b/samples/js-moonwarriors/src/GameOver.js index b57078ea27..6945426078 100755 --- a/samples/js-moonwarriors/src/GameOver.js +++ b/samples/js-moonwarriors/src/GameOver.js @@ -49,15 +49,28 @@ var GameOver = cc.Layer.extend({ logo.attr({ anchorX: 0, anchorY: 0, - x: 0, + x: 40, y: 450, scale: MW.SCALE }); this.addChild(logo,10,1); - var playAgainNormal = new cc.Sprite(res.menu_png, cc.rect(378, 0, 126, 33)); - var playAgainSelected = new cc.Sprite(res.menu_png, cc.rect(378, 33, 126, 33)); - var playAgainDisabled = new cc.Sprite(res.menu_png, cc.rect(378, 33 * 2, 126, 33)); + var logoBack = new cc.Sprite(res.gameOverBack_png); + logoBack.attr({ + anchorX: 0, + anchorY: 0, + x: 50, + y: logo.y - 30, + scale: MW.SCALE + }); + this.addChild(logoBack, 9); + + var singalHeight = MW.menuHeight; + var singalWidth = MW.menuWidth; + + var playAgainNormal = new cc.Sprite(res.menu_png, cc.rect(singalWidth * 3, 0, singalWidth, singalHeight)); + var playAgainSelected = new cc.Sprite(res.menu_png, cc.rect(singalWidth * 3, singalHeight, singalWidth, singalHeight)); + var playAgainDisabled = new cc.Sprite(res.menu_png, cc.rect(singalWidth * 3, singalHeight * 2, singalWidth, singalHeight)); var cocos2dhtml5 = new cc.Sprite(res.cocos2d_html5_png); cocos2dhtml5.x = 240; @@ -79,11 +92,13 @@ var GameOver = cc.Layer.extend({ var lbScore = new cc.LabelTTF("Your Score:"+MW.SCORE,"Arial Bold",24); lbScore.x = 240; lbScore.y = 370; - lbScore.color = cc.color(250,179,0); + lbScore.color = cc.color(255,0,0); this.addChild(lbScore,10); var b1 = new cc.LabelTTF("Download Cocos2d-JS","Arial",21); + b1.setColor(cc.color(MW.FONTCOLOR)); var b2 = new cc.LabelTTF("Github Repository","Arial",21); + b2.setColor(cc.color(MW.FONTCOLOR)); var menu1 = new cc.MenuItemLabel(b1,function(){ window.location.href = "http://www.cocos2d-x.org/download"; }); @@ -98,7 +113,7 @@ var GameOver = cc.Layer.extend({ if(MW.SOUND){ - cc.audioEngine.playMusic(res.mainMainMusic_mp3, true); + cc.audioEngine.playMusic(cc.sys.os == cc.sys.OS_WP8 || cc.sys.os == cc.sys.OS_WINRT ? res.mainMainMusic_wav : res.mainMainMusic_mp3, true); } return true; diff --git a/samples/js-moonwarriors/src/Resource.js b/samples/js-moonwarriors/src/Resource.js index d41ceb3734..0098791d8e 100755 --- a/samples/js-moonwarriors/src/Resource.js +++ b/samples/js-moonwarriors/src/Resource.js @@ -33,29 +33,36 @@ var res = { bgMusic_mp3 : 'res/Music/bgMusic.mp3', bgMusic_ogg : 'res/Music/bgMusic.ogg', + bgMusic_wav : 'res/Music/bgMusic.wav', buttonEffet_mp3 : 'res/Music/buttonEffet.mp3', buttonEffet_ogg : 'res/Music/buttonEffet.ogg', + buttonEffet_wav : 'res/Music/buttonEffet.wav', explodeEffect_mp3 : 'res/Music/explodeEffect.mp3', explodeEffect_ogg : 'res/Music/explodeEffect.ogg', + explodeEffect_wav : 'res/Music/explodeEffect.wav', fireEffect_mp3 : 'res/Music/fireEffect.mp3', //unused fireEffect_ogg : 'res/Music/fireEffect.ogg', //unused + fireEffect_wav : 'res/Music/fireEffect.wav', //unused mainMainMusic_mp3 : 'res/Music/mainMainMusic.mp3', mainMainMusic_ogg : 'res/Music/mainMainMusic.ogg', + mainMainMusic_wav : 'res/Music/mainMainMusic.wav', shipDestroyEffect_mp3 : 'res/Music/shipDestroyEffect.mp3', shipDestroyEffect_ogg : 'res/Music/shipDestroyEffect.ogg', + shipDestroyEffect_wav : 'res/Music/shipDestroyEffect.wav', arial_14_fnt : 'res/arial-14.fnt', arial_14_png : 'res/arial-14.png', b01_plist : 'res/b01.plist', b01_png : 'res/b01.png', cocos2d_html5_png : 'res/cocos2d-html5.png', - explode_plist : 'res/explode.plist', //unused explosion_plist : 'res/explosion.plist', explosion_png : 'res/explosion.png', flare_jpg : 'res/flare.jpg', gameOver_png : 'res/gameOver.png', + gameOverBack_png : 'res/gameoverBack.png', level01_tmx : 'res/level01.tmx', loading_png : 'res/loading.png', logo_png : 'res/logo.png', + logoBack_png : 'res/logoBack.png', menu_png : 'res/menu.png', menuTitle_png : 'res/menuTitle.png', textureOpaquePack_plist : 'res/textureOpaquePack.plist', @@ -69,10 +76,12 @@ var g_mainmenu = [ res.flare_jpg, res.menu_png, res.logo_png, - res.b01_png, + res.logoBack_png, + res.b01_png, res.b01_plist, res.mainMainMusic_mp3, res.mainMainMusic_ogg, + res.mainMainMusic_wav, res.menuTitle_png, res.textureTransparentPack_plist, res.textureTransparentPack_png @@ -82,6 +91,7 @@ var g_maingame = [ //image res.cocos2d_html5_png, res.gameOver_png, + res.gameOverBack_png, res.arial_14_png, res.explosion_png, res.textureOpaquePack_png, @@ -98,14 +108,18 @@ var g_maingame = [ res.bgMusic_ogg, //effect - res.buttonEffet_mp3, - res.explodeEffect_mp3, - res.fireEffect_mp3, - res.shipDestroyEffect_mp3, - res.buttonEffet_ogg, - res.explodeEffect_ogg, - res.fireEffect_ogg, - res.shipDestroyEffect_ogg, + res.buttonEffet_wav, + res.explodeEffect_wav, + res.fireEffect_wav, + res.shipDestroyEffect_wav, + res.buttonEffet_wav, + res.explodeEffect_wav, + res.fireEffect_wav, + res.shipDestroyEffect_wav, + res.buttonEffet_wav, + res.explodeEffect_wav, + res.fireEffect_wav, + res.shipDestroyEffect_wav, // FNT res.arial_14_fnt diff --git a/samples/js-moonwarriors/src/SettingsLayer.js b/samples/js-moonwarriors/src/SettingsLayer.js index 9acd4d339a..e61c68a4d2 100755 --- a/samples/js-moonwarriors/src/SettingsLayer.js +++ b/samples/js-moonwarriors/src/SettingsLayer.js @@ -43,7 +43,7 @@ var SettingsLayer = cc.Layer.extend({ this.addChild(sp, 0, 1); var cacheImage = cc.textureCache.addImage(res.menuTitle_png); - var title = new cc.Sprite(cacheImage, cc.rect(0, 0, 134, 34)); + var title = new cc.Sprite(cacheImage, cc.rect(0, 0, 134, 39)); title.x = winSize.width / 2; title.y = winSize.height - 120; this.addChild(title); @@ -53,13 +53,14 @@ var SettingsLayer = cc.Layer.extend({ cc.MenuItemFont.setFontSize(18); var title1 = new cc.MenuItemFont("Sound"); title1.setEnabled(false); + title1.setColor(cc.color(MW.FONTCOLOR)); cc.MenuItemFont.setFontName("Arial"); cc.MenuItemFont.setFontSize(26); var item1 = new cc.MenuItemToggle( - new cc.MenuItemFont("On"), - new cc.MenuItemFont("Off") ); + new cc.MenuItemFont("On"),new cc.MenuItemFont("Off")); item1.setCallback(this.onSoundControl ); + item1.setColor(cc.color(MW.FONTCOLOR)); var state = MW.SOUND ? 0 : 1; item1.setSelectedIndex(state); @@ -67,6 +68,7 @@ var SettingsLayer = cc.Layer.extend({ cc.MenuItemFont.setFontSize(18); var title2 = new cc.MenuItemFont("Mode"); title2.setEnabled(false); + title2.setColor(cc.color(MW.FONTCOLOR)); cc.MenuItemFont.setFontName("Arial"); cc.MenuItemFont.setFontSize(26); @@ -74,12 +76,14 @@ var SettingsLayer = cc.Layer.extend({ new cc.MenuItemFont("Easy"), new cc.MenuItemFont("Normal"), new cc.MenuItemFont("Hard")); + item2.setColor(cc.color(MW.FONTCOLOR)); item2.setCallback( this.onModeControl ); cc.MenuItemFont.setFontName("Arial"); cc.MenuItemFont.setFontSize(26); var label = new cc.LabelTTF("Go back", "Arial", 20); + label.setColor(cc.color(MW.FONTCOLOR)); var back = new cc.MenuItemLabel(label, this.onBackCallback); back.scale = 0.8; @@ -100,7 +104,7 @@ var SettingsLayer = cc.Layer.extend({ MW.SOUND = !MW.SOUND; var audioEngine = cc.audioEngine; if(MW.SOUND){ - audioEngine.playMusic(res.mainMainMusic_mp3); + audioEngine.playMusic(cc.sys.os == cc.sys.OS_WP8 || cc.sys.os == cc.sys.OS_WINRT ? res.mainMainMusic_wav : res.mainMainMusic_mp3); } else{ audioEngine.stopMusic(); diff --git a/samples/js-moonwarriors/src/Ship.js b/samples/js-moonwarriors/src/Ship.js index 76a7bbf078..807ca6aa21 100755 --- a/samples/js-moonwarriors/src/Ship.js +++ b/samples/js-moonwarriors/src/Ship.js @@ -115,7 +115,7 @@ var Ship = cc.Sprite.extend({ explosion.y = this.y; if (MW.SOUND) { - cc.audioEngine.playEffect(res.shipDestroyEffect_mp3); + cc.audioEngine.playEffect(cc.sys.os == cc.sys.OS_WP8 || cc.sys.os == cc.sys.OS_WINRT ? res.shipDestroyEffect_wav : res.shipDestroyEffect_mp3); } }, hurt:function () { diff --git a/samples/js-moonwarriors/src/SysMenu.js b/samples/js-moonwarriors/src/SysMenu.js index 7d946dc4a3..3d3d9ad72a 100755 --- a/samples/js-moonwarriors/src/SysMenu.js +++ b/samples/js-moonwarriors/src/SysMenu.js @@ -57,17 +57,29 @@ var SysMenu = cc.Layer.extend({ }); this.addChild(logo, 10, 1); - var newGameNormal = new cc.Sprite(res.menu_png, cc.rect(0, 0, 126, 33)); - var newGameSelected = new cc.Sprite(res.menu_png, cc.rect(0, 33, 126, 33)); - var newGameDisabled = new cc.Sprite(res.menu_png, cc.rect(0, 33 * 2, 126, 33)); + var logoBack = new cc.Sprite(res.logoBack_png); + logoBack.attr({ + anchorX: 0, + anchorY: 0, + x: 60, + y: MW.LOGOY + logo.height, + scale: MW.SCALE + }); + this.addChild(logoBack, 9); - var gameSettingsNormal = new cc.Sprite(res.menu_png, cc.rect(126, 0, 126, 33)); - var gameSettingsSelected = new cc.Sprite(res.menu_png, cc.rect(126, 33, 126, 33)); - var gameSettingsDisabled = new cc.Sprite(res.menu_png, cc.rect(126, 33 * 2, 126, 33)); + var singalHeight = MW.menuHeight; + var singalWidth = MW.menuWidth; + var newGameNormal = new cc.Sprite(res.menu_png, cc.rect(0, 0, singalWidth, singalHeight)); + var newGameSelected = new cc.Sprite(res.menu_png, cc.rect(0, singalHeight, singalWidth, singalHeight)); + var newGameDisabled = new cc.Sprite(res.menu_png, cc.rect(0, singalHeight * 2, singalWidth, singalHeight)); - var aboutNormal = new cc.Sprite(res.menu_png, cc.rect(252, 0, 126, 33)); - var aboutSelected = new cc.Sprite(res.menu_png, cc.rect(252, 33, 126, 33)); - var aboutDisabled = new cc.Sprite(res.menu_png, cc.rect(252, 33 * 2, 126, 33)); + var gameSettingsNormal = new cc.Sprite(res.menu_png, cc.rect(singalWidth, 0, singalWidth, singalHeight)); + var gameSettingsSelected = new cc.Sprite(res.menu_png, cc.rect(singalWidth, singalHeight, singalWidth, singalHeight)); + var gameSettingsDisabled = new cc.Sprite(res.menu_png, cc.rect(singalWidth, singalHeight * 2, singalWidth, singalHeight)); + + var aboutNormal = new cc.Sprite(res.menu_png, cc.rect(singalWidth * 2, 0, singalWidth, singalHeight)); + var aboutSelected = new cc.Sprite(res.menu_png, cc.rect(singalWidth * 2, singalHeight, singalWidth, singalHeight)); + var aboutDisabled = new cc.Sprite(res.menu_png, cc.rect(singalWidth * 2, singalHeight * 2, singalWidth, singalHeight)); var flare = new cc.Sprite(res.flare_jpg); this.addChild(flare, 15, 10); flare.visible = false; @@ -83,10 +95,17 @@ var SysMenu = cc.Layer.extend({ about.scale = MW.SCALE; var menu = new cc.Menu(newGame, gameSettings, about); - menu.alignItemsVerticallyWithPadding(10); + menu.alignItemsVerticallyWithPadding(15); this.addChild(menu, 1, 2); menu.x = winSize.width / 2; - menu.y = winSize.height / 2 - 80; + menu.y = winSize.height / 2 - 140; + + var label = new cc.LabelTTF("Power by Cocos2d-JS", "Arial", 21); + label.setColor(cc.color(MW.FONTCOLOR)); + this.addChild(label, 1); + label.x = winSize.width / 2; + label.y = 80; + this.schedule(this.update, 0.1); this._ship = new cc.Sprite("#ship03.png"); @@ -97,7 +116,7 @@ var SysMenu = cc.Layer.extend({ if (MW.SOUND) { cc.audioEngine.setMusicVolume(0.7); - cc.audioEngine.playMusic(res.mainMainMusic_mp3, true); + cc.audioEngine.playMusic(cc.sys.os == cc.sys.OS_WP8 || cc.sys.os == cc.sys.OS_WINRT ? res.mainMainMusic_wav : res.mainMainMusic_mp3, true); } return true; @@ -137,7 +156,7 @@ var SysMenu = cc.Layer.extend({ }, onButtonEffect:function(){ if (MW.SOUND) { - var s = cc.audioEngine.playEffect(res.buttonEffet_mp3); + var s = cc.audioEngine.playEffect(cc.sys.os == cc.sys.OS_WP8 || cc.sys.os == cc.sys.OS_WINRT ? res.buttonEffet_wav : res.buttonEffet_mp3); } } }); diff --git a/samples/js-moonwarriors/src/config/GameConfig.js b/samples/js-moonwarriors/src/config/GameConfig.js index 3e9c609f7d..0a0e29ae62 100755 --- a/samples/js-moonwarriors/src/config/GameConfig.js +++ b/samples/js-moonwarriors/src/config/GameConfig.js @@ -123,8 +123,11 @@ MW.BULLET_SPEED = { // the counter of active enemies MW.ACTIVE_ENEMIES = 0; -MW.LOGOY = 375; +MW.LOGOY = 350; MW.FLAREY = 445; MW.SCALE = 1.5; MW.WIDTH = 480; -MW.HEIGHT = 720; \ No newline at end of file +MW.HEIGHT = 720; +MW.FONTCOLOR = "#1f2d96"; +MW.menuHeight = 36; +MW.menuWidth = 123; \ No newline at end of file diff --git a/samples/js-tests/.cocos-project.json b/samples/js-tests/.cocos-project.json index 7a7af91eb4..9c4b2ebbc9 100644 --- a/samples/js-tests/.cocos-project.json +++ b/samples/js-tests/.cocos-project.json @@ -25,5 +25,23 @@ "run_root_dir": "../../", "sub_url": "/samples/js-tests/" }, + "wp8_cfg" : { + "project_path": "../../build", + "sln_file": "cocos2d-jsb-samples.wp8.sln", + "project_name": "js-tests", + "wp8_proj_path" : "project/proj.wp8-xaml", + "build_folder_path": "js-tests/Bin/x86", + "manifest_path": "js-tests/Properties/WMAppManifest.xml" + }, + "wp8_1_cfg" : { + "project_path": "../../build", + "sln_file": "cocos2d-jsb-samples-win8.1-universal.sln", + "project_name": "js-tests.WindowsPhone" + }, + "metro_cfg" : { + "project_path": "../../build", + "sln_file": "cocos2d-jsb-samples-win8.1-universal.sln", + "project_name": "js-tests.Windows" + }, "engine_dir": "../../" } diff --git a/samples/js-tests/CMakeLists.txt b/samples/js-tests/CMakeLists.txt index b0de0a997d..ae3f9066de 100644 --- a/samples/js-tests/CMakeLists.txt +++ b/samples/js-tests/CMakeLists.txt @@ -34,6 +34,8 @@ endif() set(SAMPLE_SRC project/Classes/AppDelegate.cpp + project/Classes/js_DrawNode3D_bindings.cpp + project/Classes/js_Effect3D_bindings.cpp ${PLATFORM_SRC} ) diff --git a/samples/js-tests/main.js b/samples/js-tests/main.js index c12c74fde0..71972dda54 100644 --- a/samples/js-tests/main.js +++ b/samples/js-tests/main.js @@ -80,14 +80,17 @@ * */ -var scene3SearchPaths = cc.sys.localStorage.getItem("Scene3SearchPaths"); -if (scene3SearchPaths) - jsb.fileUtils.setSearchPaths(JSON.parse(scene3SearchPaths)); +if(cc.sys){ + var scene3SearchPaths = cc.sys.localStorage.getItem("Scene3SearchPaths"); + if (scene3SearchPaths) + jsb.fileUtils.setSearchPaths(JSON.parse(scene3SearchPaths)); +} cc.game.onStart = function(){ - + cc.view.enableRetina(false); if (cc.sys.isNative) { - cc.view.setDesignResolutionSize(800, 450, cc.ResolutionPolicy.FIXED_HEIGHT); + var resolutionPolicy = (cc.sys.os == cc.sys.OS_WP8 || cc.sys.os == cc.sys.OS_WINRT) ? cc.ResolutionPolicy.SHOW_ALL : cc.ResolutionPolicy.FIXED_HEIGHT; + cc.view.setDesignResolutionSize(800, 450, resolutionPolicy); cc.view.resizeWithBrowserSize(true); var searchPaths = jsb.fileUtils.getSearchPaths(); searchPaths.push('script'); @@ -111,7 +114,6 @@ cc.game.onStart = function(){ } jsb.fileUtils.setSearchPaths(searchPaths); } - cc.LoaderScene.preload(g_resources, function () { if(window.sideIndexBar && typeof sideIndexBar.start === 'function'){ sideIndexBar.start(); diff --git a/samples/js-tests/project.json b/samples/js-tests/project.json index f5df6886dd..df4c38b167 100644 --- a/samples/js-tests/project.json +++ b/samples/js-tests/project.json @@ -43,6 +43,10 @@ "src/SceneTest/SceneTest.js", "src/SpineTest/SpineTest.js", "src/SpriteTest/SpriteTest.js", + "src/Sprite3DTest/Sprite3DTest.js", + "src/LightTest/LightTest.js", + "src/BillBoardTest/BillBoardTest.js", + "src/Camera3DTest/Camera3DTest.js", "src/TextureCacheTest/TextureCacheTest.js", "src/CocosDenshionTest/CocosDenshionTest.js", "src/CocosNodeTest/CocosNodeTest.js", @@ -109,7 +113,6 @@ "src/ExtensionsTest/S9SpriteTest/S9SpriteTest.js", "src/ExtensionsTest/NetworkTest/WebSocketTest.js", "src/ExtensionsTest/NetworkTest/SocketIOTest.js", - "src/ExtensionsTest/CocostudioActionTimelineTest/ActionTimelineTestScene.js", "src/ExtensionsTest/PluginXTest/PluginXTest.js", "src/ExtensionsTest/PluginXTest/PluginXTestsManager.js", "src/ExtensionsTest/PluginXTest/IOSIAPTest.js", @@ -149,6 +152,7 @@ "src/GUITest/UIScene.js", "src/GUITest/UIButtonTest/UIButtonTest.js", "src/GUITest/UICheckBoxTest/UICheckBoxTest.js", + "src/GUITest/UIFocusTest/UIFocusTest.js", "src/GUITest/UIImageViewTest/UIImageViewTest.js", "src/GUITest/UILabelAtlasTest/UILabelAtlasTest.js", "src/GUITest/UILabelBMFontTest/UILabelBMFontTest.js", @@ -163,12 +167,15 @@ "src/GUITest/UISliderTest/UISliderTest.js", "src/GUITest/UITextFieldTest/UITextFieldTest.js", "src/GUITest/UIRichTextTest/UIRichTextTest.js", + "src/GUITest/UITextTest/UITextTest.js", + "src/CocoStudioTest/SceneTest/TriggerCode/Acts.js", "src/CocoStudioTest/SceneTest/TriggerCode/Cons.js", "src/CocoStudioTest/SceneTest/TriggerCode/EventDef.js", "src/CocoStudioTest/SceneTest/SceneEditorTest.js", "src/CocoStudioTest/CocoStudioTest.js", "src/XHRTest/XHRTest.js", + "src/XHRTest/XHRArrayBufferTest.js", "src/Box2dTest/Box2dTest.js", "src/ChipmunkTest/ChipmunkTest.js", diff --git a/samples/js-tests/project/Classes/AppDelegate.cpp b/samples/js-tests/project/Classes/AppDelegate.cpp index 09682b8dbf..9640e35aa0 100644 --- a/samples/js-tests/project/Classes/AppDelegate.cpp +++ b/samples/js-tests/project/Classes/AppDelegate.cpp @@ -7,6 +7,9 @@ #include "jsb_cocos2dx_extension_auto.hpp" #include "jsb_cocos2dx_builder_auto.hpp" #include "jsb_cocos2dx_spine_auto.hpp" +#include "jsb_cocos2dx_3d_auto.hpp" +#include "jsb_cocos2dx_3d_extension_auto.hpp" +#include "3d/jsb_cocos2dx_3d_manual.h" #include "extension/jsb_cocos2dx_extension_manual.h" #include "cocostudio/jsb_cocos2dx_studio_manual.h" #include "jsb_cocos2dx_studio_auto.hpp" @@ -22,6 +25,7 @@ #include "network/jsb_websocket.h" #include "network/jsb_socketio.h" #include "cocosbuilder/js_bindings_ccbreader.h" +#include "js_DrawNode3D_bindings.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include "jsb_cocos2dx_pluginx_auto.hpp" @@ -34,6 +38,10 @@ #include "platform/ios/JavaScriptObjCBridge.h" #endif +#if(CC_TARGET_PLATFORM != CC_PLATFORM_WP8) +#include "js_Effect3D_bindings.h" +#endif + USING_NS_CC; USING_NS_CC_EXT; using namespace CocosDenshion; @@ -60,7 +68,11 @@ bool AppDelegate::applicationDidFinishLaunching() auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { +#if(CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) + glview = cocos2d::GLViewImpl::create("js-tests"); +#else glview = cocos2d::GLViewImpl::createWithRect("js-tests", Rect(0,0,900,640)); +#endif director->setOpenGLView(glview); } @@ -70,7 +82,6 @@ bool AppDelegate::applicationDidFinishLaunching() ScriptingCore* sc = ScriptingCore::getInstance(); sc->addRegisterCallback(register_all_cocos2dx); sc->addRegisterCallback(register_cocos2dx_js_core); - sc->addRegisterCallback(register_cocos2dx_js_extensions); sc->addRegisterCallback(jsb_register_system); sc->addRegisterCallback(register_all_cocos2dx_extension); @@ -93,6 +104,11 @@ bool AppDelegate::applicationDidFinishLaunching() sc->addRegisterCallback(register_all_cocos2dx_spine); sc->addRegisterCallback(register_all_cocos2dx_spine_manual); + + sc->addRegisterCallback(register_all_cocos2dx_3d); + sc->addRegisterCallback(register_all_cocos2dx_3d_manual); + + sc->addRegisterCallback(register_all_cocos2dx_3d_extension); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) sc->addRegisterCallback(register_all_pluginx_protocols); @@ -104,6 +120,12 @@ bool AppDelegate::applicationDidFinishLaunching() #elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) sc->addRegisterCallback(JavaScriptObjCBridge::_js_register); #endif + + sc->addRegisterCallback(register_DrawNode3D_bindings); +#if(CC_TARGET_PLATFORM != CC_PLATFORM_WP8) + sc->addRegisterCallback(register_Effect3D_bindings); +#endif + sc->start(); sc->runScript("script/jsb_boot.js"); #if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0) diff --git a/samples/js-tests/project/Classes/js_DrawNode3D_bindings.cpp b/samples/js-tests/project/Classes/js_DrawNode3D_bindings.cpp new file mode 100644 index 0000000000..b8cd8a42e4 --- /dev/null +++ b/samples/js-tests/project/Classes/js_DrawNode3D_bindings.cpp @@ -0,0 +1,593 @@ +/**************************************************************************** + Copyright (c) 2014 Chukong Technologies Inc. + + 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 "cocos2d.h" +#include "cocos2d_specifics.hpp" +#include "js_DrawNode3D_bindings.h" + +NS_CC_BEGIN + +/** + * Copy DrawNode for 3D geometry drawing. + */ +class DrawNode3D: public Node +{ +public: + /** creates and initialize a DrawNode3D node */ + static DrawNode3D* create(); + + /** + * Draw 3D Line + */ + void drawLine(const Vec3 &from, const Vec3 &to, const Color4F &color); + + /** + * Draw 3D cube + * @param point to a vertex array who has 8 element. + * vertices[0]:Left-top-front, + * vertices[1]:Left-bottom-front, + * vertices[2]:Right-bottom-front, + * vertices[3]:Right-top-front, + * vertices[4]:Right-top-back, + * vertices[5]:Right-bottom-back, + * vertices[6]:Left-bottom-back, + * vertices[7]:Left-top-back. + * @param color + */ + void drawCube(Vec3* vertices, const Color4F &color); + + /** Clear the geometry in the node's buffer. */ + void clear(); + + /** + * @js NA + * @lua NA + */ + const BlendFunc& getBlendFunc() const; + + /** + * @code + * When this function bound into js or lua,the parameter will be changed + * In js: var setBlendFunc(var src, var dst) + * @endcode + * @lua NA + */ + void setBlendFunc(const BlendFunc &blendFunc); + + void onDraw(const Mat4 &transform, uint32_t flags); + + // Overrides + virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override; + +CC_CONSTRUCTOR_ACCESS: + DrawNode3D(); + virtual ~DrawNode3D(); + virtual bool init(); + +protected: + struct V3F_C4B + { + Vec3 vertices; + Color4B colors; + }; + void ensureCapacity(int count); + + GLuint _vao; + GLuint _vbo; + + int _bufferCapacity; + GLsizei _bufferCount; + V3F_C4B* _buffer; + + BlendFunc _blendFunc; + CustomCommand _customCommand; + + bool _dirty; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(DrawNode3D); +}; + + +DrawNode3D::DrawNode3D() +: _vao(0) +, _vbo(0) +, _bufferCapacity(0) +, _bufferCount(0) +, _buffer(nullptr) +, _dirty(false) +{ + _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; +} + +DrawNode3D::~DrawNode3D() +{ + free(_buffer); + _buffer = nullptr; + + glDeleteBuffers(1, &_vbo); + _vbo = 0; + + if (Configuration::getInstance()->supportsShareableVAO()) + { + glDeleteVertexArrays(1, &_vao); + GL::bindVAO(0); + _vao = 0; + } +} + +DrawNode3D* DrawNode3D::create() +{ + DrawNode3D* ret = new (std::nothrow) DrawNode3D(); + if (ret && ret->init()) + { + ret->autorelease(); + } + else + { + CC_SAFE_DELETE(ret); + } + + return ret; +} + +void DrawNode3D::ensureCapacity(int count) +{ + CCASSERT(count>=0, "capacity must be >= 0"); + + if(_bufferCount + count > _bufferCapacity) + { + _bufferCapacity += MAX(_bufferCapacity, count); + _buffer = (V3F_C4B*)realloc(_buffer, _bufferCapacity*sizeof(V3F_C4B)); + } +} + +bool DrawNode3D::init() +{ + _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; + + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_COLOR)); + + ensureCapacity(512); + + if (Configuration::getInstance()->supportsShareableVAO()) + { + glGenVertexArrays(1, &_vao); + GL::bindVAO(_vao); + } + + glGenBuffers(1, &_vbo); + glBindBuffer(GL_ARRAY_BUFFER, _vbo); + glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_C4B)* _bufferCapacity, _buffer, GL_STREAM_DRAW); + + glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, vertices)); + + glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, colors)); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + + if (Configuration::getInstance()->supportsShareableVAO()) + { + GL::bindVAO(0); + } + + CHECK_GL_ERROR_DEBUG(); + + _dirty = true; + +#if CC_ENABLE_CACHE_TEXTURE_DATA + // Need to listen the event only when not use batchnode, because it will use VBO + auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){ + /** listen the event that coming to foreground on Android */ + this->init(); + }); + + _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); +#endif + + return true; +} + +void DrawNode3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) +{ + _customCommand.init(_globalZOrder, transform, flags); + _customCommand.func = CC_CALLBACK_0(DrawNode3D::onDraw, this, transform, flags); + renderer->addCommand(&_customCommand); +} + +void DrawNode3D::onDraw(const Mat4 &transform, uint32_t flags) +{ + auto glProgram = getGLProgram(); + glProgram->use(); + glProgram->setUniformsForBuiltins(transform); + glEnable(GL_DEPTH_TEST); + GL::blendFunc(_blendFunc.src, _blendFunc.dst); + + if (_dirty) + { + glBindBuffer(GL_ARRAY_BUFFER, _vbo); + glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_C4B)*_bufferCapacity, _buffer, GL_STREAM_DRAW); + _dirty = false; + } + if (Configuration::getInstance()->supportsShareableVAO()) + { + GL::bindVAO(_vao); + } + else + { + GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); + + glBindBuffer(GL_ARRAY_BUFFER, _vbo); + // vertex + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, vertices)); + + // color + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, colors)); + } + + glDrawArrays(GL_LINES, 0, _bufferCount); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCount); + glDisable(GL_DEPTH_TEST); + CHECK_GL_ERROR_DEBUG(); +} + +void DrawNode3D::drawLine(const Vec3 &from, const Vec3 &to, const Color4F &color) +{ + unsigned int vertex_count = 2; + ensureCapacity(vertex_count); + + Color4B col = Color4B(color); + V3F_C4B a = {Vec3(from.x, from.y, from.z), col}; + V3F_C4B b = {Vec3(to.x, to.y, to.z), col, }; + + V3F_C4B *lines = (V3F_C4B *)(_buffer + _bufferCount); + lines[0] = a; + lines[1] = b; + + _bufferCount += vertex_count; + _dirty = true; + +} + +void DrawNode3D::drawCube(Vec3* vertices, const Color4F &color) +{ + // front face + drawLine(vertices[0], vertices[1], color); + drawLine(vertices[1], vertices[2], color); + drawLine(vertices[2], vertices[3], color); + drawLine(vertices[3], vertices[0], color); + + // back face + drawLine(vertices[4], vertices[5], color); + drawLine(vertices[5], vertices[6], color); + drawLine(vertices[6], vertices[7], color); + drawLine(vertices[7], vertices[4], color); + + // edge + drawLine(vertices[0], vertices[7], color); + drawLine(vertices[1], vertices[6], color); + drawLine(vertices[2], vertices[5], color); + drawLine(vertices[3], vertices[4], color); +} + +void DrawNode3D::clear() +{ + _bufferCount = 0; + _dirty = true; +} + +const BlendFunc& DrawNode3D::getBlendFunc() const +{ + return _blendFunc; +} + +void DrawNode3D::setBlendFunc(const BlendFunc &blendFunc) +{ + _blendFunc = blendFunc; +} + +NS_CC_END + +/** + * bindings for cc.DrawNode3D + **/ +JSClass *jsb_cocos2d_DrawNode3D_class; +JSObject *jsb_cocos2d_DrawNode3D_prototype; + +bool js_cocos2dx_DrawNode3D_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::DrawNode3D* cobj = (cocos2d::DrawNode3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode3D_getBlendFunc : Invalid Native Object"); + if (argc == 0) { + const cocos2d::BlendFunc& ret = cobj->getBlendFunc(); + jsval jsret = JSVAL_NULL; + jsret = blendfunc_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_DrawNode3D_getBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_DrawNode3D_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::DrawNode3D* cobj = (cocos2d::DrawNode3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode3D_setBlendFunc : Invalid Native Object"); + if (argc == 1) { + cocos2d::BlendFunc arg0; + ok &= jsval_to_blendfunc(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode3D_setBlendFunc : Error processing arguments"); + cobj->setBlendFunc(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_DrawNode3D_setBlendFunc : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_DrawNode3D_drawLine(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::DrawNode3D* cobj = (cocos2d::DrawNode3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode3D_drawLine : Invalid Native Object"); + if (argc == 3) { + cocos2d::Vec3 arg0; + cocos2d::Vec3 arg1; + cocos2d::Color4F arg2; + ok &= jsval_to_vector3(cx, args.get(0), &arg0); + ok &= jsval_to_vector3(cx, args.get(1), &arg1); + ok &= jsval_to_cccolor4f(cx, args.get(2), &arg2); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode3D_drawLine : Error processing arguments"); + cobj->drawLine(arg0, arg1, arg2); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_DrawNode3D_drawLine : wrong number of arguments: %d, was expecting %d", argc, 3); + return false; +} +bool js_cocos2dx_DrawNode3D_clear(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::DrawNode3D* cobj = (cocos2d::DrawNode3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode3D_clear : Invalid Native Object"); + if (argc == 0) { + cobj->clear(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_DrawNode3D_clear : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_DrawNode3D_onDraw(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::DrawNode3D* cobj = (cocos2d::DrawNode3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode3D_onDraw : Invalid Native Object"); + if (argc == 2) { + cocos2d::Mat4 arg0; + unsigned int arg1; + ok &= jsval_to_matrix(cx, args.get(0), &arg0); + ok &= jsval_to_uint32(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode3D_onDraw : Error processing arguments"); + cobj->onDraw(arg0, arg1); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_DrawNode3D_onDraw : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} +bool js_cocos2dx_DrawNode3D_init(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::DrawNode3D* cobj = (cocos2d::DrawNode3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode3D_init : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->init(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_DrawNode3D_init : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_DrawNode3D_drawCube(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::DrawNode3D* cobj = (cocos2d::DrawNode3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode3D_drawCube : Invalid Native Object"); + if (argc == 2) { + cocos2d::Vec3 arg0[8]; + cocos2d::Color4F arg1; + + JS::RootedObject jsVec3Array(cx, args.get(0).toObjectOrNull()); + JSB_PRECONDITION3( jsVec3Array && JS_IsArrayObject( cx, jsVec3Array), cx, false, "augument must be an array"); + uint32_t len = 0; + JS_GetArrayLength(cx, jsVec3Array, &len); + + if (len != 8) + { + JS_ReportError(cx, "array length error: %d, was expecting 8", len); + } + for (uint32_t i=0; i < len; i++) + { + JS::RootedValue value(cx); + if (JS_GetElement(cx, jsVec3Array, i, &value)) + { + ok &= jsval_to_vector3(cx, value, &arg0[i]); + if(!ok) + break; + } + } + + ok &= jsval_to_cccolor4f(cx, args.get(1), &arg1); + + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode3D_drawCube : Error processing arguments"); + cobj->drawCube(arg0, arg1); + + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_DrawNode3D_drawCube : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} + +bool js_cocos2dx_DrawNode3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + cocos2d::DrawNode3D* cobj = new (std::nothrow) cocos2d::DrawNode3D(); + cobj->init(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::DrawNode3D"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + +static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setBoolean(true); + return true; +} + +extern JSObject *jsb_cocos2d_Node_prototype; + +void js_cocos2d_DrawNode3D_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (DrawNode3D)", obj); +} + +void js_register_cocos2dx_DrawNode3D(JSContext *cx, JS::HandleObject global) { + jsb_cocos2d_DrawNode3D_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_DrawNode3D_class->name = "DrawNode3D"; + jsb_cocos2d_DrawNode3D_class->addProperty = JS_PropertyStub; + jsb_cocos2d_DrawNode3D_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_DrawNode3D_class->getProperty = JS_PropertyStub; + jsb_cocos2d_DrawNode3D_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_DrawNode3D_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_DrawNode3D_class->resolve = JS_ResolveStub; + jsb_cocos2d_DrawNode3D_class->convert = JS_ConvertStub; + jsb_cocos2d_DrawNode3D_class->finalize = js_cocos2d_DrawNode3D_finalize; + jsb_cocos2d_DrawNode3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("getBlendFunc", js_cocos2dx_DrawNode3D_getBlendFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setBlendFunc", js_cocos2dx_DrawNode3D_setBlendFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("drawLine", js_cocos2dx_DrawNode3D_drawLine, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("clear", js_cocos2dx_DrawNode3D_clear, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("onDraw", js_cocos2dx_DrawNode3D_onDraw, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("init", js_cocos2dx_DrawNode3D_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("drawCube", js_cocos2dx_DrawNode3D_drawCube, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FS_END + }; + + jsb_cocos2d_DrawNode3D_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), + jsb_cocos2d_DrawNode3D_class, + js_cocos2dx_DrawNode3D_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "DrawNode3D", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_DrawNode3D_class; + p->proto = jsb_cocos2d_DrawNode3D_prototype; + p->parentProto = jsb_cocos2d_Node_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +void register_DrawNode3D_bindings(JSContext *cx, JS::HandleObject global) +{ + JS::RootedObject ccobj(cx); + get_or_create_js_obj(cx, global, "cc", &ccobj); + js_register_cocos2dx_DrawNode3D(cx, ccobj); +} \ No newline at end of file diff --git a/samples/js-tests/project/Classes/js_DrawNode3D_bindings.h b/samples/js-tests/project/Classes/js_DrawNode3D_bindings.h new file mode 100644 index 0000000000..810e186765 --- /dev/null +++ b/samples/js-tests/project/Classes/js_DrawNode3D_bindings.h @@ -0,0 +1,31 @@ +/**************************************************************************** + Copyright (c) 2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ +#ifndef __js_tests_bindings_h__ +#define __js_tests_bindings_h__ + +#include "jsapi.h" + +void register_DrawNode3D_bindings(JSContext *cx, JS::HandleObject global); + +#endif diff --git a/samples/js-tests/project/Classes/js_Effect3D_bindings.cpp b/samples/js-tests/project/Classes/js_Effect3D_bindings.cpp new file mode 100644 index 0000000000..f83aeca744 --- /dev/null +++ b/samples/js-tests/project/Classes/js_Effect3D_bindings.cpp @@ -0,0 +1,777 @@ +/**************************************************************************** + Copyright (c) 2014 Chukong Technologies Inc. + + 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 "js_Effect3D_bindings.h" +#include "cocos2d_specifics.hpp" + +using namespace cocos2d; + +class EffectSprite3D; + +class Effect3D : public Ref +{ +public: + virtual void draw(const Mat4 &transform) = 0; + virtual void setTarget(EffectSprite3D *sprite) = 0; +protected: + Effect3D() : _glProgramState(nullptr) {} + virtual ~Effect3D() + { + CC_SAFE_RELEASE(_glProgramState); + } +protected: + GLProgramState* _glProgramState; +}; + +class Effect3DOutline: public Effect3D +{ +public: + static Effect3DOutline* create(); + + void setOutlineColor(const Vec3& color); + + void setOutlineWidth(float width); + + virtual void draw(const Mat4 &transform) override; + virtual void setTarget(EffectSprite3D *sprite) override; + + + Effect3DOutline(); + virtual ~Effect3DOutline(); + + bool init(); +protected: + Vec3 _outlineColor; + float _outlineWidth; + //weak reference + EffectSprite3D* _sprite; +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) + EventListenerCustom* _backToForegroundListener; +#endif + +protected: + static const std::string _vertShaderFile; + static const std::string _fragShaderFile; + static const std::string _keyInGLProgramCache; + + static const std::string _vertSkinnedShaderFile; + static const std::string _fragSkinnedShaderFile; + static const std::string _keySkinnedInGLProgramCache; + + static GLProgram* getOrCreateProgram(bool isSkinned = false); +}; + +class EffectSprite3D : public Sprite3D +{ +public: + static EffectSprite3D* createFromObjFileAndTexture(const std::string& objFilePath, const std::string& textureFilePath); + static EffectSprite3D* create(const std::string& path); + + void setEffect3D(Effect3D* effect); + void addEffect(Effect3DOutline* effect, ssize_t order); + virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override; + + EffectSprite3D(); + virtual ~EffectSprite3D(); +protected: + std::vector> _effects; + Effect3D* _defaultEffect; + CustomCommand _command; +}; + + +EffectSprite3D* EffectSprite3D::createFromObjFileAndTexture(const std::string &objFilePath, const std::string &textureFilePath) +{ + auto sprite = new (std::nothrow) EffectSprite3D(); + if (sprite && sprite->initWithFile(objFilePath)) + { + sprite->autorelease(); + if(textureFilePath.size() > 0) + sprite->setTexture(textureFilePath); + return sprite; + } + CC_SAFE_DELETE(sprite); + return nullptr; +} + +EffectSprite3D* EffectSprite3D::create(const std::string &path) +{ + if (path.length() < 4) + CCASSERT(false, "improper name specified when creating Sprite3D"); + + auto sprite = new (std::nothrow) EffectSprite3D(); + if (sprite && sprite->initWithFile(path)) + { + sprite->autorelease(); + return sprite; + } + CC_SAFE_DELETE(sprite); + return nullptr; +} + +EffectSprite3D::EffectSprite3D() +: _defaultEffect(nullptr) +{ + +} + +EffectSprite3D::~EffectSprite3D() +{ + for(auto effect : _effects) + { + CC_SAFE_RELEASE_NULL(std::get<1>(effect)); + } + CC_SAFE_RELEASE(_defaultEffect); +} + +void EffectSprite3D::setEffect3D(Effect3D *effect) +{ + if(_defaultEffect == effect) return; + CC_SAFE_RETAIN(effect); + CC_SAFE_RELEASE(_defaultEffect); + _defaultEffect = effect; +} + +static int tuple_sort( const std::tuple &tuple1, const std::tuple &tuple2 ) +{ + return std::get<0>(tuple1) < std::get<0>(tuple2); +} + +void EffectSprite3D::addEffect(Effect3DOutline* effect, ssize_t order) +{ + if(nullptr == effect) return; + effect->retain(); + effect->setTarget(this); + + _effects.push_back(std::make_tuple(order,effect,CustomCommand())); + + std::sort(std::begin(_effects), std::end(_effects), tuple_sort); +} + +const std::string Effect3DOutline::_vertShaderFile = "Shaders3D/OutLine.vert"; +const std::string Effect3DOutline::_fragShaderFile = "Shaders3D/OutLine.frag"; +const std::string Effect3DOutline::_keyInGLProgramCache = "Effect3DLibrary_Outline"; + +const std::string Effect3DOutline::_vertSkinnedShaderFile = "Shaders3D/SkinnedOutline.vert"; +const std::string Effect3DOutline::_fragSkinnedShaderFile = "Shaders3D/OutLine.frag"; +const std::string Effect3DOutline::_keySkinnedInGLProgramCache = "Effect3DLibrary_Outline"; +GLProgram* Effect3DOutline::getOrCreateProgram(bool isSkinned /* = false */ ) +{ + if(isSkinned) + { + auto program = GLProgramCache::getInstance()->getGLProgram(_keySkinnedInGLProgramCache); + if(program == nullptr) + { + program = GLProgram::createWithFilenames(_vertSkinnedShaderFile, _fragSkinnedShaderFile); + GLProgramCache::getInstance()->addGLProgram(program, _keySkinnedInGLProgramCache); + } + return program; + } + else + { + auto program = GLProgramCache::getInstance()->getGLProgram(_keyInGLProgramCache); + if(program == nullptr) + { + program = GLProgram::createWithFilenames(_vertShaderFile, _fragShaderFile); + GLProgramCache::getInstance()->addGLProgram(program, _keyInGLProgramCache); + } + return program; + } + +} + +Effect3DOutline* Effect3DOutline::create() +{ + Effect3DOutline* effect = new (std::nothrow) Effect3DOutline(); + if(effect && effect->init()) + { + effect->autorelease(); + return effect; + } + else + { + CC_SAFE_DELETE(effect); + return nullptr; + } +} + +bool Effect3DOutline::init() +{ + + return true; +} + +Effect3DOutline::Effect3DOutline() +: _outlineWidth(1.0f) +, _outlineColor(1, 1, 1) +, _sprite(nullptr) +{ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) + _backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, + [this](EventCustom*) + { + auto glProgram = _glProgramState->getGLProgram(); + glProgram->reset(); + glProgram->initWithFilenames(_vertShaderFile, _fragShaderFile); + glProgram->link(); + glProgram->updateUniforms(); + } + ); + Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, -1); +#endif +} + +Effect3DOutline::~Effect3DOutline() +{ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) + Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundListener); +#endif +} + +void Effect3DOutline::setOutlineColor(const Vec3& color) +{ + if(_outlineColor != color) + { + _outlineColor = color; + if(_glProgramState) + _glProgramState->setUniformVec3("OutLineColor", _outlineColor); + } +} + +void Effect3DOutline::setOutlineWidth(float width) +{ + if(_outlineWidth != width) + { + _outlineWidth = width; + if(_glProgramState) + _glProgramState->setUniformFloat("OutlineWidth", _outlineWidth); + } +} + +void Effect3DOutline::setTarget(EffectSprite3D *sprite) +{ + CCASSERT(nullptr != sprite && nullptr != sprite->getMesh(),"Error: Setting a null pointer or a null mesh EffectSprite3D to Effect3D"); + + if(sprite != _sprite) + { + GLProgram* glprogram; + if(!sprite->getMesh()->getSkin()) + glprogram = GLProgram::createWithFilenames(_vertShaderFile, _fragShaderFile); + else + glprogram = GLProgram::createWithFilenames(_vertSkinnedShaderFile, _fragSkinnedShaderFile); + + _glProgramState = GLProgramState::create(glprogram); + + _glProgramState->retain(); + _glProgramState->setUniformVec3("OutLineColor", _outlineColor); + _glProgramState->setUniformFloat("OutlineWidth", _outlineWidth); + + + _sprite = sprite; + + auto mesh = sprite->getMesh(); + long offset = 0; + for (auto i = 0; i < mesh->getMeshVertexAttribCount(); i++) + { + auto meshvertexattrib = mesh->getMeshVertexAttribute(i); + + _glProgramState->setVertexAttribPointer(s_attributeNames[meshvertexattrib.vertexAttrib], + meshvertexattrib.size, + meshvertexattrib.type, + GL_FALSE, + mesh->getVertexSizeInBytes(), + (void*)offset); + offset += meshvertexattrib.attribSizeBytes; + } + + Color4F color(_sprite->getDisplayedColor()); + color.a = _sprite->getDisplayedOpacity() / 255.0f; + _glProgramState->setUniformVec4("u_color", Vec4(color.r, color.g, color.b, color.a)); + } + +} + +static void MatrixPalleteCallBack( GLProgram* glProgram, Uniform* uniform, int paletteSize, const float* palette) +{ + glUniform4fv( uniform->location, (GLsizei)paletteSize, (const float*)palette ); +} + +void Effect3DOutline::draw(const Mat4 &transform) +{ + //draw + Color4F color(_sprite->getDisplayedColor()); + color.a = _sprite->getDisplayedOpacity() / 255.0f; + _glProgramState->setUniformVec4("u_color", Vec4(color.r, color.g, color.b, color.a)); + if(_sprite && _sprite->getMesh()) + { + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + glEnable(GL_DEPTH_TEST); + + auto mesh = _sprite->getMesh(); + glBindBuffer(GL_ARRAY_BUFFER, mesh->getVertexBuffer()); + + auto skin = _sprite->getMesh()->getSkin(); + if(_sprite && skin) + { + auto function = std::bind(MatrixPalleteCallBack, std::placeholders::_1, std::placeholders::_2, + skin->getMatrixPaletteSize(), (float*)skin->getMatrixPalette()); + _glProgramState->setUniformCallback("u_matrixPalette", function); + } + + if(_sprite) + _glProgramState->apply(transform); + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->getIndexBuffer()); + glDrawElements(mesh->getPrimitiveType(), (GLsizei)mesh->getIndexCount(), mesh->getIndexFormat(), 0); + CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, mesh->getIndexCount()); + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glDisable(GL_DEPTH_TEST); + glCullFace(GL_BACK); + glDisable(GL_CULL_FACE); + } +} + +void EffectSprite3D::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags) +{ + for(auto &effect : _effects) + { + if(std::get<0>(effect) >=0) + break; + CustomCommand &cc = std::get<2>(effect); + cc.func = CC_CALLBACK_0(Effect3D::draw,std::get<1>(effect),transform); + renderer->addCommand(&cc); + + } + + if(!_defaultEffect) + { + Sprite3D::draw(renderer, transform, flags); + } + else + { + _command.init(_globalZOrder, transform, flags); + _command.func = CC_CALLBACK_0(Effect3D::draw, _defaultEffect, transform); + renderer->addCommand(&_command); + } + + for(auto &effect : _effects) + { + if(std::get<0>(effect) <=0) + continue; + CustomCommand &cc = std::get<2>(effect); + cc.func = CC_CALLBACK_0(Effect3D::draw,std::get<1>(effect),transform); + renderer->addCommand(&cc); + + } +} + +// js bindings + +static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setBoolean(true); + return true; +} + +JSClass *jsb_Effect3DOutline_class; +JSObject *jsb_Effect3DOutline_prototype; + +bool js_cocos2dx_Effect3DOutline_setOutlineWidth(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + Effect3DOutline* cobj = (Effect3DOutline *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Effect3DOutline_setOutlineWidth : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Effect3DOutline_setOutlineWidth : Error processing arguments"); + cobj->setOutlineWidth(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Effect3DOutline_setOutlineWidth : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_Effect3DOutline_setOutlineColor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + Effect3DOutline* cobj = (Effect3DOutline *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Effect3DOutline_setOutlineColor : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vec3 arg0; + ok &= jsval_to_vector3(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Effect3DOutline_setOutlineColor : Error processing arguments"); + cobj->setOutlineColor(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Effect3DOutline_setOutlineColor : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_Effect3DOutline_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (argc == 0) { + Effect3DOutline* ret = Effect3DOutline::create(); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (Effect3DOutline*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_Effect3DOutline_create : wrong number of arguments"); + return false; +} + + +JSObject *jsb_Effect3D_prototype; + +void js_Effect3DOutline_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (Effect3DOutline)", obj); +} + +bool jsb_Effect3DOutline_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + Effect3DOutline* cobj = new (std::nothrow) Effect3DOutline(); + cobj->init(); + cobj->autorelease(); + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Effect3DOutline"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + +void js_register_cocos2dx_Effect3DOutline(JSContext *cx, JS::HandleObject global) { + jsb_Effect3DOutline_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_Effect3DOutline_class->name = "Effect3DOutline"; + jsb_Effect3DOutline_class->addProperty = JS_PropertyStub; + jsb_Effect3DOutline_class->delProperty = JS_DeletePropertyStub; + jsb_Effect3DOutline_class->getProperty = JS_PropertyStub; + jsb_Effect3DOutline_class->setProperty = JS_StrictPropertyStub; + jsb_Effect3DOutline_class->enumerate = JS_EnumerateStub; + jsb_Effect3DOutline_class->resolve = JS_ResolveStub; + jsb_Effect3DOutline_class->convert = JS_ConvertStub; + jsb_Effect3DOutline_class->finalize = js_Effect3DOutline_finalize; + jsb_Effect3DOutline_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("setOutlineWidth", js_cocos2dx_Effect3DOutline_setOutlineWidth, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setOutlineColor", js_cocos2dx_Effect3DOutline_setOutlineColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_Effect3DOutline_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_Effect3DOutline_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_Effect3D_prototype), + jsb_Effect3DOutline_class, + jsb_Effect3DOutline_constructor, 0, + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace + // bool found; + //FIXME: Removed in Firefox v27 + // JS_SetPropertyAttributes(cx, global, "Effect3DOutline", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_Effect3DOutline_class; + p->proto = jsb_Effect3DOutline_prototype; + p->parentProto = jsb_Effect3D_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + + +JSClass *jsb_EffectSprite3D_class; +JSObject *jsb_EffectSprite3D_prototype; + +bool js_cocos2dx_EffectSprite3D_setEffect3D(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + EffectSprite3D* cobj = (EffectSprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EffectSprite3D_setEffect3D : Invalid Native Object"); + if (argc == 1) { + Effect3D* arg0; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (Effect3D*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EffectSprite3D_setEffect3D : Error processing arguments"); + cobj->setEffect3D(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_EffectSprite3D_setEffect3D : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_EffectSprite3D_addEffect(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + EffectSprite3D* cobj = (EffectSprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EffectSprite3D_addEffect : Invalid Native Object"); + if (argc == 2) { + Effect3DOutline* arg0; + ssize_t arg1; + do { + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JSObject *tmpObj = args.get(0).toObjectOrNull(); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (Effect3DOutline*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_ssize(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EffectSprite3D_addEffect : Error processing arguments"); + cobj->addEffect(arg0, arg1); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_EffectSprite3D_addEffect : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} +bool js_cocos2dx_EffectSprite3D_createFromObjFileAndTexture(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 2) { + std::string arg0; + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EffectSprite3D_createFromObjFileAndTexture : Error processing arguments"); + EffectSprite3D* ret = EffectSprite3D::createFromObjFileAndTexture(arg0, arg1); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (EffectSprite3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_EffectSprite3D_createFromObjFileAndTexture : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_EffectSprite3D_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EffectSprite3D_create : Error processing arguments"); + EffectSprite3D* ret = EffectSprite3D::create(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) { + js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (EffectSprite3D*)ret); + jsret = OBJECT_TO_JSVAL(jsProxy->obj); + } else { + jsret = JSVAL_NULL; + } + } while (0); + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_EffectSprite3D_create : wrong number of arguments"); + return false; +} + + +extern JSObject *jsb_cocos2d_Sprite3D_prototype; + +void js_EffectSprite3D_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (EffectSprite3D)", obj); +} + +bool jsb_EffectSprite3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + EffectSprite3D* cobj = new (std::nothrow) EffectSprite3D(); + if(argc == 1 || argc == 2) + { + std::string path; + jsval_to_std_string(cx, args.get(0), &path); + cobj->initWithFile(path); + if(argc == 2) + { + std::string texture; + jsval_to_std_string(cx, args.get(1), &texture); + cobj->setTexture(texture); + } + } + cobj->autorelease(); + TypeTest t; + js_type_class_t *typeClass = nullptr; + std::string typeName = t.s_name(); + auto typeMapIter = _js_global_type_map.find(typeName); + CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); + typeClass = typeMapIter->second; + CCASSERT(typeClass, "The value is null."); + // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + args.rval().set(OBJECT_TO_JSVAL(obj)); + // link the native object with the javascript object + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::EffectSprite3D"); + if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + return true; +} + +void js_register_cocos2dx_EffectSprite3D(JSContext *cx, JS::HandleObject global) { + jsb_EffectSprite3D_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_EffectSprite3D_class->name = "EffectSprite3D"; + jsb_EffectSprite3D_class->addProperty = JS_PropertyStub; + jsb_EffectSprite3D_class->delProperty = JS_DeletePropertyStub; + jsb_EffectSprite3D_class->getProperty = JS_PropertyStub; + jsb_EffectSprite3D_class->setProperty = JS_StrictPropertyStub; + jsb_EffectSprite3D_class->enumerate = JS_EnumerateStub; + jsb_EffectSprite3D_class->resolve = JS_ResolveStub; + jsb_EffectSprite3D_class->convert = JS_ConvertStub; + jsb_EffectSprite3D_class->finalize = js_EffectSprite3D_finalize; + jsb_EffectSprite3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("setEffect3D", js_cocos2dx_EffectSprite3D_setEffect3D, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("addEffect", js_cocos2dx_EffectSprite3D_addEffect, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("createFromObjFileAndTexture", js_cocos2dx_EffectSprite3D_createFromObjFileAndTexture, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("create", js_cocos2dx_EffectSprite3D_create, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_EffectSprite3D_prototype = JS_InitClass( + cx, global, + JS::RootedObject(cx, jsb_cocos2d_Sprite3D_prototype), + jsb_EffectSprite3D_class, + jsb_EffectSprite3D_constructor, 1, + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace + // bool found; + //FIXME: Removed in Firefox v27 + // JS_SetPropertyAttributes(cx, global, "EffectSprite3D", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_EffectSprite3D_class; + p->proto = jsb_EffectSprite3D_prototype; + p->parentProto = jsb_cocos2d_Sprite3D_prototype; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + +void register_Effect3D_bindings(JSContext *cx, JS::HandleObject global) +{ + JS::RootedObject ccobj(cx); + get_or_create_js_obj(cx, global, "cc", &ccobj); + js_register_cocos2dx_Effect3DOutline(cx, ccobj); + js_register_cocos2dx_EffectSprite3D(cx, ccobj); +} \ No newline at end of file diff --git a/samples/js-tests/project/Classes/js_Effect3D_bindings.h b/samples/js-tests/project/Classes/js_Effect3D_bindings.h new file mode 100644 index 0000000000..b5456d6d3b --- /dev/null +++ b/samples/js-tests/project/Classes/js_Effect3D_bindings.h @@ -0,0 +1,31 @@ +/**************************************************************************** + Copyright (c) 2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ +#ifndef __js_effect3d_bindings_h__ +#define __js_effect3d_bindings_h__ + +#include "jsapi.h" + +void register_Effect3D_bindings(JSContext *cx, JS::HandleObject global); + +#endif diff --git a/samples/js-tests/project/proj.android/jni/Android.mk b/samples/js-tests/project/proj.android/jni/Android.mk index a0915e2d19..a0327a73b5 100644 --- a/samples/js-tests/project/proj.android/jni/Android.mk +++ b/samples/js-tests/project/proj.android/jni/Android.mk @@ -7,7 +7,9 @@ LOCAL_MODULE := js_tests_shared LOCAL_MODULE_FILENAME := libjs_tests LOCAL_SRC_FILES := main.cpp \ - ../../Classes/AppDelegate.cpp + ../../Classes/AppDelegate.cpp \ + ../../Classes/js_DrawNode3D_bindings.cpp \ + ../../Classes/js_Effect3D_bindings.cpp LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes diff --git a/samples/js-tests/project/proj.win32/js-tests.vcxproj b/samples/js-tests/project/proj.win32/js-tests.vcxproj index dce0751e65..a06629e614 100644 --- a/samples/js-tests/project/proj.win32/js-tests.vcxproj +++ b/samples/js-tests/project/proj.win32/js-tests.vcxproj @@ -49,10 +49,10 @@ <_ProjectFileVersion>10.0.40219.1 - $(SolutionDir)$(Configuration).win32\ + $(SolutionDir)$(Configuration).win32\js-tests\ $(Configuration).win32\ false - $(SolutionDir)$(Configuration).win32\ + $(SolutionDir)$(Configuration).win32\js-tests\ $(Configuration).win32\ false AllRules.ruleset @@ -102,28 +102,28 @@ if not exist "$(OutDir)" mkdir "$(OutDir)" -xcopy /Y /Q "$(ProjectDir)..\..\..\..\frameworks\js-bindings\external\spidermonkey\prebuilt\win32\*.*" "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\..\..\..\frameworks\js-bindings\external\spidermonkey\prebuilt\win32\debug-build\*.*" "$(OutDir)" xcopy /Y /Q "$(ProjectDir)..\..\..\..\frameworks\js-bindings\cocos2d-x\external\websockets\prebuilt\win32\*.*" "$(OutDir)" - libcurl_imp.lib;mozjs-28.lib;ws2_32.lib;sqlite3.lib;websockets.lib;%(AdditionalDependencies) - $(OutDir);%(AdditionalLibraryDirectories) + libcurl_imp.lib;mozjs-33.lib;ws2_32.lib;sqlite3.lib;websockets.lib;%(AdditionalDependencies) + $(OutDir);$(SolutionDir)$(Configuration).win32;%(AdditionalLibraryDirectories) true Windows MachineX86 if not exist "$(OutDir)" mkdir "$(OutDir)" -if exist "$(OutDir)\js-tests-res" rd /s /q "$(OutDir)\js-tests-res" -mkdir "$(OutDir)\js-tests-res" -mkdir "$(OutDir)\js-tests-res\script" -mkdir "$(OutDir)\js-tests-res\src" -mkdir "$(OutDir)\js-tests-res\res" -xcopy "$(ProjectDir)..\..\..\..\frameworks\js-bindings\bindings\script\*" "$(OutDir)\js-tests-res\script" /e /Y -xcopy "$(ProjectDir)..\..\src" "$(OutDir)\js-tests-res\src\" /e /Y -xcopy "$(ProjectDir)..\..\res" "$(OutDir)\js-tests-res\res\" /e /Y -copy "$(ProjectDir)..\..\main.js" "$(OutDir)\js-tests-res" -copy "$(ProjectDir)..\..\project.json" "$(OutDir)\js-tests-res" + +mkdir "$(OutDir)\script" +mkdir "$(OutDir)\src" +mkdir "$(OutDir)\res" +xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y +xcopy "$(ProjectDir)..\..\..\..\frameworks\js-bindings\bindings\script\*" "$(OutDir)\script" /e /Y +xcopy "$(ProjectDir)..\..\src" "$(OutDir)\src\" /e /Y +xcopy "$(ProjectDir)..\..\res" "$(OutDir)\res\" /e /Y +copy "$(ProjectDir)..\..\main.js" "$(OutDir)" +copy "$(ProjectDir)..\..\project.json" "$(OutDir)" Copy js and resource files. @@ -163,36 +163,40 @@ copy "$(ProjectDir)..\..\project.json" "$(OutDir)\js-tests-res" if not exist "$(OutDir)" mkdir "$(OutDir)" -xcopy /Y /Q "$(ProjectDir)..\..\..\..\frameworks\js-bindings\external\spidermonkey\prebuilt\win32\*.*" "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\..\..\..\frameworks\js-bindings\external\spidermonkey\prebuilt\win32\release-build\*.*" "$(OutDir)" xcopy /Y /Q "$(ProjectDir)..\..\..\..\frameworks\js-bindings\cocos2d-x\external\websockets\prebuilt\win32\*.*" "$(OutDir)" - libcurl_imp.lib;mozjs-28.lib;ws2_32.lib;sqlite3.lib;websockets.lib;%(AdditionalDependencies) - $(OutDir);%(AdditionalLibraryDirectories) + libcurl_imp.lib;mozjs-33.lib;ws2_32.lib;sqlite3.lib;websockets.lib;%(AdditionalDependencies) + $(OutDir);$(SolutionDir)$(Configuration).win32;%(AdditionalLibraryDirectories) Windows MachineX86 true if not exist "$(OutDir)" mkdir "$(OutDir)" -if exist "$(OutDir)\js-tests-res" rd /s /q "$(OutDir)\js-tests-res" -mkdir "$(OutDir)\js-tests-res" -mkdir "$(OutDir)\js-tests-res\script" -mkdir "$(OutDir)\js-tests-res\src" -mkdir "$(OutDir)\js-tests-res\res" -xcopy "$(ProjectDir)..\..\..\..\frameworks\js-bindings\bindings\script\*" "$(OutDir)\js-tests-res\script" /e /Y -xcopy "$(ProjectDir)..\..\src" "$(OutDir)\js-tests-res\src\" /e /Y -xcopy "$(ProjectDir)..\..\res" "$(OutDir)\js-tests-res\res\" /e /Y -copy "$(ProjectDir)..\..\main.js" "$(OutDir)\js-tests-res" -copy "$(ProjectDir)..\..\project.json" "$(OutDir)\js-tests-res" + +mkdir "$(OutDir)\script" +mkdir "$(OutDir)\src" +mkdir "$(OutDir)\res" +xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y +xcopy "$(ProjectDir)..\..\..\..\frameworks\js-bindings\bindings\script\*" "$(OutDir)\script" /e /Y +xcopy "$(ProjectDir)..\..\src" "$(OutDir)\src\" /e /Y +xcopy "$(ProjectDir)..\..\res" "$(OutDir)\res\" /e /Y +copy "$(ProjectDir)..\..\main.js" "$(OutDir)" +copy "$(ProjectDir)..\..\project.json" "$(OutDir)" Copy js and resource files. + + + + diff --git a/samples/js-tests/project/proj.win32/js-tests.vcxproj.filters b/samples/js-tests/project/proj.win32/js-tests.vcxproj.filters index 4adf8bd538..42d34b8e6c 100644 --- a/samples/js-tests/project/proj.win32/js-tests.vcxproj.filters +++ b/samples/js-tests/project/proj.win32/js-tests.vcxproj.filters @@ -7,6 +7,12 @@ win32 + + Classes + + + Classes + @@ -18,6 +24,12 @@ win32 + + Classes + + + Classes + diff --git a/samples/js-tests/project/proj.win32/js-tests.vcxproj.user b/samples/js-tests/project/proj.win32/js-tests.vcxproj.user index d9f8b600f8..c9a35e681d 100644 --- a/samples/js-tests/project/proj.win32/js-tests.vcxproj.user +++ b/samples/js-tests/project/proj.win32/js-tests.vcxproj.user @@ -1,11 +1,11 @@  - $(OutDir)\js-tests-res + $(OutDir) WindowsLocalDebugger - $(OutDir)\js-tests-res + $(OutDir) WindowsLocalDebugger \ No newline at end of file diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Shared/App.xaml b/samples/js-tests/project/proj.win8.1-universal/App.Shared/App.xaml new file mode 100644 index 0000000000..7c15a5d78f --- /dev/null +++ b/samples/js-tests/project/proj.win8.1-universal/App.Shared/App.xaml @@ -0,0 +1,13 @@ + + + + + cpp_tests + + + diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Shared/App.xaml.cpp b/samples/js-tests/project/proj.win8.1-universal/App.Shared/App.xaml.cpp new file mode 100644 index 0000000000..07cd4853e6 --- /dev/null +++ b/samples/js-tests/project/proj.win8.1-universal/App.Shared/App.xaml.cpp @@ -0,0 +1,21 @@ +#include "App.xaml.h" +#include "OpenGLESPage.xaml.h" + +using namespace cocos2d; + +App::App() +{ + InitializeComponent(); +} + +void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) +{ + if (mPage == nullptr) + { + mPage = ref new OpenGLESPage(&mOpenGLES); + } + + // Place the page in the current window and ensure that it is active. + Windows::UI::Xaml::Window::Current->Content = mPage; + Windows::UI::Xaml::Window::Current->Activate(); +} diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Shared/App.xaml.h b/samples/js-tests/project/proj.win8.1-universal/App.Shared/App.xaml.h new file mode 100644 index 0000000000..ce4d7c8bfd --- /dev/null +++ b/samples/js-tests/project/proj.win8.1-universal/App.Shared/App.xaml.h @@ -0,0 +1,19 @@ +#pragma once + +#include "app.g.h" +#include "OpenGLES.h" +#include "openglespage.xaml.h" + +namespace cocos2d +{ + ref class App sealed + { + public: + App(); + virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) override; + + private: + OpenGLESPage^ mPage; + OpenGLES mOpenGLES; + }; +} diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Shared/js-tests.Shared.vcxitems b/samples/js-tests/project/proj.win8.1-universal/App.Shared/js-tests.Shared.vcxitems new file mode 100644 index 0000000000..e39dcb7d94 --- /dev/null +++ b/samples/js-tests/project/proj.win8.1-universal/App.Shared/js-tests.Shared.vcxitems @@ -0,0 +1,64 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + e956c24b-f04e-47bf-bf00-746681ae1301 + {AE6763F6-1549-441E-AFB5-377BE1C776DC} + js-tests + + + + %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) + + + + + Designer + + + + + $(MSBuildThisFileDirectory)..\..\..\..\..\frameworks\js-bindings\external\win8.1-universal\OpenGLESPage.xaml + + + + + + $(MSBuildThisFileDirectory)App.xaml + + + + + $(MSBuildThisFileDirectory)..\..\..\..\..\frameworks\js-bindings\external\win8.1-universal\OpenGLESPage.xaml + + + + + + $(MSBuildThisFileDirectory)App.xaml + + + Create + + + + + + + + <_CustomResource Include="$(MSBuildThisFileDirectory)..\..\Resources\**\*"> + Assets\Resources\%(RecursiveDir)%(FileName)%(Extension) + true + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Shared/js-tests.Shared.vcxitems.filters b/samples/js-tests/project/proj.win8.1-universal/App.Shared/js-tests.Shared.vcxitems.filters new file mode 100644 index 0000000000..a03f57a132 --- /dev/null +++ b/samples/js-tests/project/proj.win8.1-universal/App.Shared/js-tests.Shared.vcxitems.filters @@ -0,0 +1,46 @@ + + + + + + + + + Classes + + + Classes + + + Classes + + + + + + + + + + + {38ad799c-8c3c-44a2-8e41-516c8f62f556} + + + + + Classes + + + Classes + + + Classes + + + + + + + + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Shared/pch.cpp b/samples/js-tests/project/proj.win8.1-universal/App.Shared/pch.cpp new file mode 100644 index 0000000000..e0d2ef1a2a --- /dev/null +++ b/samples/js-tests/project/proj.win8.1-universal/App.Shared/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Shared/pch.h b/samples/js-tests/project/proj.win8.1-universal/App.Shared/pch.h new file mode 100644 index 0000000000..c849b49dfa --- /dev/null +++ b/samples/js-tests/project/proj.win8.1-universal/App.Shared/pch.h @@ -0,0 +1,12 @@ +// +// pch.h +// Header for standard system include files. +// + +#pragma once + +#include "mozilla\Char16.h" +#include "cocos2d.h" +#include "cocos-ext.h" + + diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Windows/Assets/Logo.scale-100.png b/samples/js-tests/project/proj.win8.1-universal/App.Windows/Assets/Logo.scale-100.png new file mode 100644 index 0000000000..e26771cb33 Binary files /dev/null and b/samples/js-tests/project/proj.win8.1-universal/App.Windows/Assets/Logo.scale-100.png differ diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Windows/Assets/SmallLogo.scale-100.png b/samples/js-tests/project/proj.win8.1-universal/App.Windows/Assets/SmallLogo.scale-100.png new file mode 100644 index 0000000000..1eb0d9d528 Binary files /dev/null and b/samples/js-tests/project/proj.win8.1-universal/App.Windows/Assets/SmallLogo.scale-100.png differ diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Windows/Assets/SplashScreen.scale-100.png b/samples/js-tests/project/proj.win8.1-universal/App.Windows/Assets/SplashScreen.scale-100.png new file mode 100644 index 0000000000..d8ded7198a Binary files /dev/null and b/samples/js-tests/project/proj.win8.1-universal/App.Windows/Assets/SplashScreen.scale-100.png differ diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Windows/Assets/StoreLogo.scale-100.png b/samples/js-tests/project/proj.win8.1-universal/App.Windows/Assets/StoreLogo.scale-100.png new file mode 100644 index 0000000000..dcb672712c Binary files /dev/null and b/samples/js-tests/project/proj.win8.1-universal/App.Windows/Assets/StoreLogo.scale-100.png differ diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Windows/Package.appxmanifest b/samples/js-tests/project/proj.win8.1-universal/App.Windows/Package.appxmanifest new file mode 100644 index 0000000000..7ab9c8f08b --- /dev/null +++ b/samples/js-tests/project/proj.win8.1-universal/App.Windows/Package.appxmanifest @@ -0,0 +1,30 @@ + + + + + js-tests.Windows + msopentech + Assets\StoreLogo.png + + + 6.3.0 + 6.3.0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Windows/js-tests.Windows.vcxproj b/samples/js-tests/project/proj.win8.1-universal/App.Windows/js-tests.Windows.vcxproj new file mode 100644 index 0000000000..d9c1482c44 --- /dev/null +++ b/samples/js-tests/project/proj.win8.1-universal/App.Windows/js-tests.Windows.vcxproj @@ -0,0 +1,244 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM + + + Release + Win32 + + + Release + x64 + + + + {70914FC8-7709-4CD6-B86B-C63FDE5478DB} + cocos2d + en-US + 12.0 + true + Windows Store + 8.1 + + + + Application + true + v120 + + + Application + true + v120 + + + Application + true + v120 + + + Application + false + false + v120 + + + Application + false + false + v120 + + + Application + false + false + v120 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + js-tests.Windows_TemporaryKey.pfx + True + x86 + FB58178D2A50D64A72EC25130D072580B999A12E + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + echo "Copying Windows 8.1 Universal App CPP template files" +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml.cpp" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml.h" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq + + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + echo "Copying Windows 8.1 Universal App CPP template files" +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml.cpp" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml.h" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq + + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + echo "Copying Windows 8.1 Universal App CPP template files" +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml.cpp" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml.h" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq + + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + echo "Copying Windows 8.1 Universal App CPP template files" +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml.cpp" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml.h" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq + + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + echo "Copying Windows 8.1 Universal App CPP template files" +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml.cpp" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml.h" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq + + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + echo "Copying Windows 8.1 Universal App CPP template files" +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml.cpp" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq +xcopy "$(EngineRoot)..\external\win8.1-universal\OpenGLESPage.xaml.h" "$(EngineRoot)..\..\..\templates\js-template-default\frameworks\runtime-src\proj.win8.1-universal\App.Shared\*" /eiycq + + + + + + Designer + + + + + + + + + + + + {bcf5546d-66a0-4998-afd6-c5514f618930} + + + {9335005f-678e-4e8e-9b84-50037216aec8} + + + {f3550fe0-c795-44f6-8feb-093eb68143ae} + + + {3b26a12d-3a44-47ea-82d2-282660fc844d} + + + + + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Windows/js-tests.Windows.vcxproj.filters b/samples/js-tests/project/proj.win8.1-universal/App.Windows/js-tests.Windows.vcxproj.filters new file mode 100644 index 0000000000..644480854d --- /dev/null +++ b/samples/js-tests/project/proj.win8.1-universal/App.Windows/js-tests.Windows.vcxproj.filters @@ -0,0 +1,29 @@ + + + + + {1a9fa652-867e-41d2-8588-962f108d2d8f} + bmp;fbx;gif;jpg;jpeg;tga;tiff;tif;png + + + + + + + + + + + Assets + + + Assets + + + Assets + + + Assets + + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.win8.1-universal/App.Windows/js-tests.Windows_TemporaryKey.pfx b/samples/js-tests/project/proj.win8.1-universal/App.Windows/js-tests.Windows_TemporaryKey.pfx new file mode 100644 index 0000000000..a5b8824cbb Binary files /dev/null and b/samples/js-tests/project/proj.win8.1-universal/App.Windows/js-tests.Windows_TemporaryKey.pfx differ diff --git a/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/Logo.scale-240.png b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/Logo.scale-240.png new file mode 100644 index 0000000000..76921ca997 Binary files /dev/null and b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/Logo.scale-240.png differ diff --git a/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/SmallLogo.scale-240.png b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/SmallLogo.scale-240.png new file mode 100644 index 0000000000..316630124f Binary files /dev/null and b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/SmallLogo.scale-240.png differ diff --git a/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/SplashScreen.scale-240.png b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/SplashScreen.scale-240.png new file mode 100644 index 0000000000..b0b6bc08e5 Binary files /dev/null and b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/SplashScreen.scale-240.png differ diff --git a/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/Square71x71Logo.scale-240.png b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/Square71x71Logo.scale-240.png new file mode 100644 index 0000000000..cfa54bee03 Binary files /dev/null and b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/Square71x71Logo.scale-240.png differ diff --git a/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/StoreLogo.scale-240.png b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/StoreLogo.scale-240.png new file mode 100644 index 0000000000..47e084b593 Binary files /dev/null and b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/StoreLogo.scale-240.png differ diff --git a/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/WideLogo.scale-240.png b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/WideLogo.scale-240.png new file mode 100644 index 0000000000..6249d29db0 Binary files /dev/null and b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Assets/WideLogo.scale-240.png differ diff --git a/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Package.appxmanifest b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Package.appxmanifest new file mode 100644 index 0000000000..d8c2fe6a11 --- /dev/null +++ b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/Package.appxmanifest @@ -0,0 +1,33 @@ + + + + + + js-tests.WindowsPhone + dalestam + Assets\StoreLogo.png + + + 6.3.1 + 6.3.1 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/js-tests.WindowsPhone.vcxproj b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/js-tests.WindowsPhone.vcxproj new file mode 100644 index 0000000000..3ebe068858 --- /dev/null +++ b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/js-tests.WindowsPhone.vcxproj @@ -0,0 +1,151 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Release + ARM + + + Release + Win32 + + + + {94874B5B-398F-448A-A366-35A35DC1DB9C} + cocos2d + en-US + 12.0 + true + Windows Phone + 8.1 + + + + Application + true + v120_wp81 + + + Application + true + v120_wp81 + + + Application + false + false + v120_wp81 + + + Application + false + false + v120_wp81 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + arm + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4800;%(DisableSpecificWarnings) + pch.h + $(EngineRoot)..\external\win8.1-universal;$(ProjectDir)..\..\Classes;$(EngineRoot)cocos\platform\win8.1-universal;%(AdditionalIncludeDirectories) + false + + + + + Designer + + + + + + + + + + + + + {ca082ec4-17ce-430b-8207-d1e947a5d1e9} + + + {22f3b9df-1209-4574-8331-003966f562bf} + + + {cc1da216-a80d-4be4-b309-acb6af313aff} + + + {22f798d8-bfff-4754-996f-a5395343d5ec} + + + + + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/js-tests.WindowsPhone.vcxproj.filters b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/js-tests.WindowsPhone.vcxproj.filters new file mode 100644 index 0000000000..08414f1f0c --- /dev/null +++ b/samples/js-tests/project/proj.win8.1-universal/App.WindowsPhone/js-tests.WindowsPhone.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {c8beb60d-689b-4aaa-9749-99bd3e2dcf75} + bmp;fbx;gif;jpg;jpeg;tga;tiff;tif;png + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + + + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.win8.1-universal/resources.props b/samples/js-tests/project/proj.win8.1-universal/resources.props new file mode 100644 index 0000000000..cc54464cfb --- /dev/null +++ b/samples/js-tests/project/proj.win8.1-universal/resources.props @@ -0,0 +1,63 @@ + + + + + + + $(EngineRoot)..\bindings\manual;$(EngineRoot)..\bindings\auto;$(EngineRoot)..\external\spidermonkey\include\$(COCOS2D_PLATFORM);$(EngineRoot)cocos\base;%(AdditionalIncludeDirectories); + + + mozjs-33.lib;%(AdditionalDependencies) + $(EngineRoot)..\external\spidermonkey\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);%(AdditionalLibraryDirectories); + + + + + $(EngineRoot)..\external\spidermonkey\prebuilt\$(COCOS2D_PLATFORM)\$(Platform)\ + + + + + true + + + + + <_CustomResource Include="..\..\..\res\**\*"> + Assets\Resources\res\%(RecursiveDir)%(FileName)%(Extension) + true + + + + <_CustomResource Include="..\..\..\src\**\*"> + Assets\Resources\src\%(RecursiveDir)%(FileName)%(Extension) + true + + + + <_CustomResource Include="..\..\..\..\..\frameworks\js-bindings\bindings\script\**\*"> + Assets\Resources\script\%(RecursiveDir)%(FileName)%(Extension) + true + + + + <_CustomResource Include="..\..\..\main.js"> + Assets\Resources\%(RecursiveDir)%(FileName)%(Extension) + true + + + + <_CustomResource Include="..\..\..\project.json"> + Assets\Resources\%(RecursiveDir)%(FileName)%(Extension) + true + + + + + + + + + + + diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests.sln b/samples/js-tests/project/proj.wp8-xaml/js-tests.sln new file mode 100644 index 0000000000..b97f6efdd9 --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-tests.sln @@ -0,0 +1,74 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "js-tests", "js-tests\js-tests.csproj", "{5921FE12-7EF3-4847-8453-42EF286DDBE7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "js-testsComponent", "js-testsComponent\js-testsComponent.vcxproj", "{F5D665F8-AE19-4F3F-99A7-230A1E8305D2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|ARM = Debug|ARM + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|Win32 = Debug|Win32 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM + Release|Mixed Platforms = Release|Mixed Platforms + Release|Win32 = Release|Win32 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|ARM.ActiveCfg = Debug|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|ARM.Build.0 = Debug|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|ARM.Deploy.0 = Debug|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Mixed Platforms.Deploy.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Win32.ActiveCfg = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Win32.Build.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|Win32.Deploy.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|x86.ActiveCfg = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|x86.Build.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Debug|x86.Deploy.0 = Debug|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Any CPU.Build.0 = Release|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Any CPU.Deploy.0 = Release|Any CPU + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|ARM.ActiveCfg = Release|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|ARM.Build.0 = Release|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|ARM.Deploy.0 = Release|ARM + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Mixed Platforms.Build.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Mixed Platforms.Deploy.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Win32.ActiveCfg = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Win32.Build.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|Win32.Deploy.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|x86.ActiveCfg = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|x86.Build.0 = Release|x86 + {5921FE12-7EF3-4847-8453-42EF286DDBE7}.Release|x86.Deploy.0 = Release|x86 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|ARM.ActiveCfg = Debug|ARM + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|ARM.Build.0 = Debug|ARM + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Win32.ActiveCfg = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|Win32.Build.0 = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|x86.ActiveCfg = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Debug|x86.Build.0 = Debug|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Any CPU.ActiveCfg = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|ARM.ActiveCfg = Release|ARM + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|ARM.Build.0 = Release|ARM + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Mixed Platforms.Build.0 = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Win32.ActiveCfg = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|Win32.Build.0 = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|x86.ActiveCfg = Release|Win32 + {F5D665F8-AE19-4F3F-99A7-230A1E8305D2}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/AlignmentGrid.png b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/AlignmentGrid.png new file mode 100644 index 0000000000..f7d2e97804 Binary files /dev/null and b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/AlignmentGrid.png differ diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/ApplicationIcon.png b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/ApplicationIcon.png new file mode 100644 index 0000000000..7d95d4e081 Binary files /dev/null and b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/ApplicationIcon.png differ diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Resources/fonts/arialuni.ttf b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Resources/fonts/arialuni.ttf new file mode 100644 index 0000000000..e37f38b3e7 Binary files /dev/null and b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Resources/fonts/arialuni.ttf differ diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/FlipCycleTileLarge.png b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/FlipCycleTileLarge.png new file mode 100644 index 0000000000..e0c59ac014 Binary files /dev/null and b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/FlipCycleTileLarge.png differ diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/FlipCycleTileMedium.png b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/FlipCycleTileMedium.png new file mode 100644 index 0000000000..e93b89d600 Binary files /dev/null and b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/FlipCycleTileMedium.png differ diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/FlipCycleTileSmall.png b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/FlipCycleTileSmall.png new file mode 100644 index 0000000000..550b1b5e8d Binary files /dev/null and b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/FlipCycleTileSmall.png differ diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/IconicTileMediumLarge.png b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/IconicTileMediumLarge.png new file mode 100644 index 0000000000..686e6b53f0 Binary files /dev/null and b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/IconicTileMediumLarge.png differ diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/IconicTileSmall.png b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/IconicTileSmall.png new file mode 100644 index 0000000000..d4b5ede1b5 Binary files /dev/null and b/samples/js-tests/project/proj.wp8-xaml/js-tests/Assets/Tiles/IconicTileSmall.png differ diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/LocalizedStrings.cs b/samples/js-tests/project/proj.wp8-xaml/js-tests/LocalizedStrings.cs new file mode 100644 index 0000000000..4c0d4ba292 --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-tests/LocalizedStrings.cs @@ -0,0 +1,14 @@ +using cocos2d.Resources; + +namespace cocos2d +{ + /// + /// Provides access to string resources. + /// + public class LocalizedStrings + { + private static AppResources _localizedResources = new AppResources(); + + public AppResources LocalizedResources { get { return _localizedResources; } } + } +} \ No newline at end of file diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/Package.appxmanifest b/samples/js-tests/project/proj.wp8-xaml/js-tests/Package.appxmanifest new file mode 100644 index 0000000000..97603b61d2 --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-tests/Package.appxmanifest @@ -0,0 +1,59 @@ + + + + + + + + + js-tests + dalestam + Assets\StoreLogo.png + + + + 6.3.1 + 6.3.1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + AgHostSvcs.dll + + + + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/Properties/AppManifest.xml b/samples/js-tests/project/proj.wp8-xaml/js-tests/Properties/AppManifest.xml new file mode 100644 index 0000000000..6712a11783 --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-tests/Properties/AppManifest.xml @@ -0,0 +1,6 @@ + + + + diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/Properties/AssemblyInfo.cs b/samples/js-tests/project/proj.wp8-xaml/js-tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..c5921e1749 --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-tests/Properties/AssemblyInfo.cs @@ -0,0 +1,37 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Resources; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("cocos2d")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("cocos2d")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e9152507-1b95-4fca-9d7f-444a024ccb98")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: NeutralResourcesLanguageAttribute("en-US")] diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/Properties/WMAppManifest.xml b/samples/js-tests/project/proj.wp8-xaml/js-tests/Properties/WMAppManifest.xml new file mode 100644 index 0000000000..0a032dc7fb --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-tests/Properties/WMAppManifest.xml @@ -0,0 +1,42 @@ + + + + + Assets\ApplicationIcon.png + + + + + + + + + + + + + + Assets\Tiles\FlipCycleTileSmall.png + 0 + Assets\Tiles\FlipCycleTileMedium.png + js-tests + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/Resources/AppResources.Designer.cs b/samples/js-tests/project/proj.wp8-xaml/js-tests/Resources/AppResources.Designer.cs new file mode 100644 index 0000000000..efb4f0a46c --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-tests/Resources/AppResources.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.34014 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace cocos2d.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class AppResources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal AppResources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("cocos2d.Resources.AppResources", typeof(AppResources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to MY APPLICATION. + /// + public static string ApplicationTitle { + get { + return ResourceManager.GetString("ApplicationTitle", resourceCulture); + } + } + } +} diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/Resources/AppResources.resx b/samples/js-tests/project/proj.wp8-xaml/js-tests/Resources/AppResources.resx new file mode 100644 index 0000000000..13e5fdc678 --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-tests/Resources/AppResources.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + MY APPLICATION + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/SplashScreenImage.jpg b/samples/js-tests/project/proj.wp8-xaml/js-tests/SplashScreenImage.jpg new file mode 100644 index 0000000000..8a7cdf9e2a Binary files /dev/null and b/samples/js-tests/project/proj.wp8-xaml/js-tests/SplashScreenImage.jpg differ diff --git a/samples/js-tests/project/proj.wp8-xaml/js-tests/js-tests.csproj b/samples/js-tests/project/proj.wp8-xaml/js-tests/js-tests.csproj new file mode 100644 index 0000000000..802b98c76b --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-tests/js-tests.csproj @@ -0,0 +1,211 @@ + + + + Debug + AnyCPU + 10.0.20506 + 2.0 + {8443AB1A-BE8A-4E80-A55E-37FB2AA1360E} + {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + cocos2d + js-tests + WindowsPhone + v8.0 + $(TargetFrameworkVersion) + true + + + true + true + js-tests_$(Configuration)_$(Platform).xap + Properties\AppManifest.xml + cocos2d.App + true + 11.0 + true + + + true + full + false + Bin\Debug + DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + pdbonly + true + Bin\Release + TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + true + full + false + Bin\x86\Debug + DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + pdbonly + true + Bin\x86\Release + TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + true + full + false + Bin\ARM\Debug + DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + pdbonly + true + Bin\ARM\Release + TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + + App.xaml.cs + + + EditBox.xaml.cs + + + MainPage.xaml.cs + + + + + True + True + AppResources.resx + + + + + PreserveNewest + + + + Designer + + + + + PreserveNewest + + + + + + + + + + + + PublicResXFileCodeGenerator + AppResources.Designer.cs + + + + + {878A2939-C627-4E6E-907D-38381FF35E5A} + js-testsComponent + + + + + Assets\Resources\fonts\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + + + + + Assets\Resources\res\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + + + + + Assets\Resources\src\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + + + + + Assets\Resources\script\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + + + + + Assets\Resources\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + + + + + Assets\Resources\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + + + + + App.xaml + MSBuild:Compile + Designer + + + EditBox.xaml + MSBuild:Compile + Designer + + + MainPage.xaml + MSBuild:Compile + Designer + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/js-testsComponent.vcxproj b/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/js-testsComponent.vcxproj new file mode 100644 index 0000000000..bf763cc400 --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/js-testsComponent.vcxproj @@ -0,0 +1,239 @@ + + + + + Debug + Win32 + + + Debug + ARM + + + Release + Win32 + + + Release + ARM + + + + {878A2939-C627-4E6E-907D-38381FF35E5A} + cocos2d + en-US + 11.0 + true + + + + + $(OutDir)\$(MSBuildProjectName)\ + + $(SolutionDir)$(Configuration)\$(MSBuildProjectName)\ + $(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)\ + + false + + + DynamicLibrary + true + v110_wp80 + + + DynamicLibrary + true + v110_wp80 + + + DynamicLibrary + false + true + v110_wp80 + + + DynamicLibrary + false + true + v110_wp80 + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + + CC_ENABLE_CHIPMUNK_INTEGRATION=1;COCOS2D_DEBUG=1;%(PreprocessorDefinitions) + Use + pch.h + $(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories) + true + $(EngineRoot)..\bindings\manual;$(EngineRoot)..\bindings\auto;$(EngineRoot)..\external\spidermonkey\include\wp8;$(EngineRoot)cocos\base;$(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + pch.h + /Zm200 %(AdditionalOptions) + %(DisableSpecificWarnings) + false + + + Console + false + mozjs-33.lib;%(AdditionalDependencies) + ole32.lib;%(IgnoreSpecificDefaultLibraries) + true + $(EngineRoot)..\external\spidermonkey\prebuilt\wp8\$(Platform);%(AdditionalLibraryDirectories) + LinkVerbose + + + + + CC_ENABLE_CHIPMUNK_INTEGRATION=1;NDEBUG;%(PreprocessorDefinitions) + Use + pch.h + $(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories) + true + $(EngineRoot)..\bindings\manual;$(EngineRoot)..\bindings\auto;$(EngineRoot)..\external\spidermonkey\include\wp8;$(EngineRoot)cocos\base;$(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + pch.h + /Zm200 %(AdditionalOptions) + %(DisableSpecificWarnings) + false + + + Console + false + mozjs-33.lib;%(AdditionalDependencies) + ole32.lib;%(IgnoreSpecificDefaultLibraries) + true + $(EngineRoot)..\external\spidermonkey\prebuilt\wp8\$(Platform);%(AdditionalLibraryDirectories) + LinkVerbose + + + + + CC_ENABLE_CHIPMUNK_INTEGRATION=1;COCOS2D_DEBUG=1;%(PreprocessorDefinitions) + Use + pch.h + $(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories) + true + $(EngineRoot)..\bindings\manual;$(EngineRoot)..\bindings\auto;$(EngineRoot)..\external\spidermonkey\include\wp8;$(EngineRoot)cocos\base;$(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + pch.h + /Zm200 %(AdditionalOptions) + %(DisableSpecificWarnings) + true + false + + + Console + false + mozjs-33.lib;%(AdditionalDependencies) + ole32.lib;%(IgnoreSpecificDefaultLibraries) + true + $(EngineRoot)..\external\spidermonkey\prebuilt\wp8\$(Platform);%(AdditionalLibraryDirectories) + + + + + CC_ENABLE_CHIPMUNK_INTEGRATION=1;NDEBUG;%(PreprocessorDefinitions) + Use + pch.h + $(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories) + true + $(EngineRoot)..\bindings\manual;$(EngineRoot)..\bindings\auto;$(EngineRoot)..\external\spidermonkey\include\wp8;$(EngineRoot)cocos\base;$(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + pch.h + /Zm200 %(AdditionalOptions) + %(DisableSpecificWarnings) + false + + + Console + false + mozjs-33.lib;%(AdditionalDependencies) + ole32.lib;%(IgnoreSpecificDefaultLibraries) + true + $(EngineRoot)..\external\spidermonkey\prebuilt\wp8\$(Platform);%(AdditionalLibraryDirectories) + + + + + true + false + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + + + + + + + + + {dd11890a-006e-4d4b-bbe6-a577601288a2} + + + {7c5dbc42-27f6-4978-aabc-02ba77e2a7f0} + + + {7d4fc6eb-9497-4804-98f3-3eaedc896154} + + + {c55734a3-702c-4fa1-b950-32c8e169302f} + + + + + true + true + + + true + true + + + + + + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/js-testsComponent.vcxproj.filters b/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/js-testsComponent.vcxproj.filters new file mode 100644 index 0000000000..f8cf2c8804 --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/js-testsComponent.vcxproj.filters @@ -0,0 +1,48 @@ + + + + + {ebfae752-00fd-4f6a-ac89-7f565a8a5a52} + + + + + Classes + + + + + + + + + Classes + + + + + Classes + + + + + + + + + + Classes + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/js-testsComponent.vcxproj.user b/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/js-testsComponent.vcxproj.user new file mode 100644 index 0000000000..b0dc84df25 --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/js-testsComponent.vcxproj.user @@ -0,0 +1,6 @@ + + + + true + + \ No newline at end of file diff --git a/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/pch.cpp b/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/pch.cpp new file mode 100644 index 0000000000..bcb5590be1 --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" diff --git a/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/pch.h b/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/pch.h new file mode 100644 index 0000000000..7a5e3975ae --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/pch.h @@ -0,0 +1,4 @@ +#pragma once + +#include "mozilla\Char16.h" +#include "cocos2d.h" diff --git a/samples/js-tests/res/ActionTimeline/boy0.plist b/samples/js-tests/res/ActionTimeline/boy0.plist new file mode 100644 index 0000000000..e40c8f84a7 --- /dev/null +++ b/samples/js-tests/res/ActionTimeline/boy0.plist @@ -0,0 +1,217 @@ + + + + + frames + + testAnimationResource/1.png + + width + 201 + height + 320 + originalWidth + 201 + originalHeight + 320 + x + 0 + y + 0 + offsetX + 0 + offsetY + 0 + + testAnimationResource/2.png + + width + 186 + height + 252 + originalWidth + 186 + originalHeight + 252 + x + 203 + y + 0 + offsetX + 0 + offsetY + 0 + + testAnimationResource/3.png + + width + 247 + height + 479 + originalWidth + 247 + originalHeight + 479 + x + 391 + y + 0 + offsetX + 0 + offsetY + 0 + + testAnimationResource/4.png + + width + 141 + height + 110 + originalWidth + 141 + originalHeight + 110 + x + 640 + y + 0 + offsetX + 0 + offsetY + 0 + + testAnimationResource/5.png + + width + 190 + height + 236 + originalWidth + 190 + originalHeight + 236 + x + 783 + y + 0 + offsetX + 0 + offsetY + 0 + + testAnimationResource/6.png + + width + 474 + height + 402 + originalWidth + 474 + originalHeight + 402 + x + 975 + y + 0 + offsetX + 0 + offsetY + 0 + + testAnimationResource/7.png + + width + 146 + height + 112 + originalWidth + 146 + originalHeight + 112 + x + 1451 + y + 0 + offsetX + 0 + offsetY + 0 + + testAnimationResource/8.png + + width + 135 + height + 180 + originalWidth + 135 + originalHeight + 180 + x + 1599 + y + 0 + offsetX + 0 + offsetY + 0 + + testAnimationResource/hat.png + + width + 452 + height + 458 + originalWidth + 452 + originalHeight + 458 + x + 0 + y + 481 + offsetX + 0 + offsetY + 0 + + 25.png + + width + 20 + height + 23 + originalWidth + 20 + originalHeight + 23 + x + 454 + y + 481 + offsetX + 0 + offsetY + 0 + + + metadata + + format + 0 + textureFileName + Cowboy0.png + realTextureFileName + Cowboy0.png + size + {2048,1024} + + texture + + width + 2048 + height + 1024 + + + \ No newline at end of file diff --git a/samples/js-tests/res/ActionTimeline/boy0.png b/samples/js-tests/res/ActionTimeline/boy0.png new file mode 100644 index 0000000000..2b61d3b005 Binary files /dev/null and b/samples/js-tests/res/ActionTimeline/boy0.png differ diff --git a/samples/js-tests/res/Images/SpookyPeas.png b/samples/js-tests/res/Images/SpookyPeas.png new file mode 100644 index 0000000000..24cf345bbf Binary files /dev/null and b/samples/js-tests/res/Images/SpookyPeas.png differ diff --git a/samples/js-tests/res/Images/dot.png b/samples/js-tests/res/Images/dot.png new file mode 100644 index 0000000000..eb89425ece Binary files /dev/null and b/samples/js-tests/res/Images/dot.png differ diff --git a/samples/js-tests/res/Images/wood.jpg b/samples/js-tests/res/Images/wood.jpg new file mode 100644 index 0000000000..c2f6fef756 Binary files /dev/null and b/samples/js-tests/res/Images/wood.jpg differ diff --git a/samples/js-tests/res/Shaders3D/Normal.frag b/samples/js-tests/res/Shaders3D/Normal.frag new file mode 100644 index 0000000000..7f1f3d6735 --- /dev/null +++ b/samples/js-tests/res/Shaders3D/Normal.frag @@ -0,0 +1,31 @@ +#ifdef GL_ES +precision mediump float; +#endif + +varying vec4 v_fragmentColor; +varying vec2 v_texCoord; +uniform sampler2D u_normalMap; +uniform float u_kBump; +uniform vec4 u_lightPosInLocalSpace; +uniform vec2 u_contentSize; +uniform vec3 u_diffuseL; +void main(void) +{ + vec4 texColor=texture2D(CC_Texture0, v_texCoord); + vec3 normal=texture2D(u_normalMap, v_texCoord).rgb; + normal=normal*2.0-1.0; + normal.y=-normal.y; + if(u_kBump!=1.0) + { + //if the vertex.z mult kBump, then the normal.z should div kBump and re-normalize + normal=vec3(normal.x,normal.y,normal.z/u_kBump); + normal=normalize(normal); + } + vec4 curPixelPosInLocalSpace=vec4(v_texCoord.x*u_contentSize.x,(1.0-v_texCoord.y)*u_contentSize.y,0.0,1.0); + vec4 lightDir=normalize(curPixelPosInLocalSpace-u_lightPosInLocalSpace); + vec3 posToLight=-lightDir.xyz; + float normDotPosToLight=max(0.0,dot(normal,posToLight)); + vec4 diffuse=vec4(normDotPosToLight*u_diffuseL,1.0); + vec4 ambient=vec4(0.5,0.5,0.5,1); + gl_FragColor=texColor*vec4(vec3(diffuse+ambient),diffuse.a);; +} \ No newline at end of file diff --git a/samples/js-tests/res/Shaders3D/OutLine.frag b/samples/js-tests/res/Shaders3D/OutLine.frag new file mode 100644 index 0000000000..dd6e60a6a7 --- /dev/null +++ b/samples/js-tests/res/Shaders3D/OutLine.frag @@ -0,0 +1,7 @@ +uniform vec3 OutLineColor; +uniform vec4 u_color; + +void main(void) +{ + gl_FragColor = vec4(OutLineColor,1.0) * u_color; +} diff --git a/samples/js-tests/res/Shaders3D/OutLine.vert b/samples/js-tests/res/Shaders3D/OutLine.vert new file mode 100644 index 0000000000..f4cd386b34 --- /dev/null +++ b/samples/js-tests/res/Shaders3D/OutLine.vert @@ -0,0 +1,13 @@ +attribute vec4 a_position; +attribute vec3 a_normal; +uniform float OutlineWidth; + +void main(void) +{ + vec4 pos = CC_MVPMatrix * a_position; + vec4 normalproj = CC_MVPMatrix * vec4(a_normal, 0); + normalproj = normalize(normalproj); + pos.xy += normalproj.xy * (OutlineWidth * (pos.z * 0.5 + 0.5)); + + gl_Position = pos; +} diff --git a/samples/js-tests/res/Shaders3D/SkinnedOutline.vert b/samples/js-tests/res/Shaders3D/SkinnedOutline.vert new file mode 100644 index 0000000000..fdf40e7a45 --- /dev/null +++ b/samples/js-tests/res/Shaders3D/SkinnedOutline.vert @@ -0,0 +1,75 @@ +attribute vec3 a_position; +attribute vec3 a_normal; +attribute vec4 a_blendWeight; +attribute vec4 a_blendIndex; + +attribute vec2 a_texCoord; +uniform float OutlineWidth; + +const int SKINNING_JOINT_COUNT = 60; +// Uniforms +uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3]; + +// Varyings +varying vec2 TextureCoordOut; + +vec4 SkinnedVec3(vec4 vec) +{ + float blendWeight = a_blendWeight[0]; + + int matrixIndex = int (a_blendIndex[0]) * 3; + vec4 matrixPalette1 = u_matrixPalette[matrixIndex] * blendWeight; + vec4 matrixPalette2 = u_matrixPalette[matrixIndex + 1] * blendWeight; + vec4 matrixPalette3 = u_matrixPalette[matrixIndex + 2] * blendWeight; + + + blendWeight = a_blendWeight[1]; + if (blendWeight > 0.0) + { + matrixIndex = int(a_blendIndex[1]) * 3; + matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight; + matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight; + matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight; + } + + + blendWeight = a_blendWeight[2]; + if (blendWeight > 0.0) + { + matrixIndex = int(a_blendIndex[2]) * 3; + matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight; + matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight; + matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight; + } + + + blendWeight = a_blendWeight[3]; + if (blendWeight > 0.0) + { + matrixIndex = int(a_blendIndex[3]) * 3; + matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight; + matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight; + matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight; + } + + + vec4 _skinnedPosition; + vec4 postion = vec; + _skinnedPosition.x = dot(postion, matrixPalette1); + _skinnedPosition.y = dot(postion, matrixPalette2); + _skinnedPosition.z = dot(postion, matrixPalette3); + _skinnedPosition.w = postion.w; + + return _skinnedPosition; +} + +void main() +{ + vec4 pos = CC_MVPMatrix * SkinnedVec3(vec4(a_position,1.0)); + + vec4 normalproj = CC_MVPMatrix * vec4(SkinnedVec3(vec4(a_normal,0.0)).xyz, 0); + normalproj = normalize(normalproj); + pos.xy += normalproj.xy * (OutlineWidth * (pos.z * 0.5 + 0.5)); + + gl_Position = pos; +} diff --git a/samples/js-tests/res/Sprite3DTest/Floor.png b/samples/js-tests/res/Sprite3DTest/Floor.png new file mode 100644 index 0000000000..4ebde104e7 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/Floor.png differ diff --git a/samples/js-tests/res/Sprite3DTest/Girl_Face.png b/samples/js-tests/res/Sprite3DTest/Girl_Face.png new file mode 100644 index 0000000000..9dc0b7634d Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/Girl_Face.png differ diff --git a/samples/js-tests/res/Sprite3DTest/Girl_Glasses01.png b/samples/js-tests/res/Sprite3DTest/Girl_Glasses01.png new file mode 100644 index 0000000000..0754928550 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/Girl_Glasses01.png differ diff --git a/samples/js-tests/res/Sprite3DTest/Girl_Hair01.png b/samples/js-tests/res/Sprite3DTest/Girl_Hair01.png new file mode 100644 index 0000000000..05d3f1b060 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/Girl_Hair01.png differ diff --git a/samples/js-tests/res/Sprite3DTest/Girl_Hair02.png b/samples/js-tests/res/Sprite3DTest/Girl_Hair02.png new file mode 100644 index 0000000000..c86e87ba27 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/Girl_Hair02.png differ diff --git a/samples/js-tests/res/Sprite3DTest/Girl_Hand.png b/samples/js-tests/res/Sprite3DTest/Girl_Hand.png new file mode 100644 index 0000000000..f95fecae54 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/Girl_Hand.png differ diff --git a/samples/js-tests/res/Sprite3DTest/Girl_LowerBody01.png b/samples/js-tests/res/Sprite3DTest/Girl_LowerBody01.png new file mode 100644 index 0000000000..3b8ee9c27d Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/Girl_LowerBody01.png differ diff --git a/samples/js-tests/res/Sprite3DTest/Girl_LowerBody02.png b/samples/js-tests/res/Sprite3DTest/Girl_LowerBody02.png new file mode 100644 index 0000000000..8815077867 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/Girl_LowerBody02.png differ diff --git a/samples/js-tests/res/Sprite3DTest/Girl_Shoes01.png b/samples/js-tests/res/Sprite3DTest/Girl_Shoes01.png new file mode 100644 index 0000000000..42d35215c2 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/Girl_Shoes01.png differ diff --git a/samples/js-tests/res/Sprite3DTest/Girl_Shoes02.png b/samples/js-tests/res/Sprite3DTest/Girl_Shoes02.png new file mode 100644 index 0000000000..9e9f9d2899 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/Girl_Shoes02.png differ diff --git a/samples/js-tests/res/Sprite3DTest/Girl_UpperBody01.png b/samples/js-tests/res/Sprite3DTest/Girl_UpperBody01.png new file mode 100644 index 0000000000..3b8233a4b7 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/Girl_UpperBody01.png differ diff --git a/samples/js-tests/res/Sprite3DTest/Girl_UpperBody02.png b/samples/js-tests/res/Sprite3DTest/Girl_UpperBody02.png new file mode 100644 index 0000000000..ec01cd6806 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/Girl_UpperBody02.png differ diff --git a/samples/js-tests/res/Sprite3DTest/LightMapScene.c3b b/samples/js-tests/res/Sprite3DTest/LightMapScene.c3b new file mode 100644 index 0000000000..56bbf092a7 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/LightMapScene.c3b differ diff --git a/samples/js-tests/res/Sprite3DTest/ReskinGirl.c3b b/samples/js-tests/res/Sprite3DTest/ReskinGirl.c3b new file mode 100644 index 0000000000..06e51a31a0 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/ReskinGirl.c3b differ diff --git a/samples/js-tests/res/Sprite3DTest/Xie_01.png b/samples/js-tests/res/Sprite3DTest/Xie_01.png new file mode 100644 index 0000000000..42d35215c2 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/Xie_01.png differ diff --git a/samples/js-tests/res/Sprite3DTest/arx.png b/samples/js-tests/res/Sprite3DTest/arx.png new file mode 100644 index 0000000000..26c82f9d80 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/arx.png differ diff --git a/samples/js-tests/res/Sprite3DTest/axe.c3b b/samples/js-tests/res/Sprite3DTest/axe.c3b new file mode 100644 index 0000000000..9d69b70fc3 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/axe.c3b differ diff --git a/samples/js-tests/res/Sprite3DTest/body.png b/samples/js-tests/res/Sprite3DTest/body.png new file mode 100644 index 0000000000..f2c09089e4 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/body.png differ diff --git a/samples/js-tests/res/Sprite3DTest/boss.c3b b/samples/js-tests/res/Sprite3DTest/boss.c3b new file mode 100644 index 0000000000..81144f673e Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/boss.c3b differ diff --git a/samples/js-tests/res/Sprite3DTest/boss.obj b/samples/js-tests/res/Sprite3DTest/boss.obj new file mode 100644 index 0000000000..97154a2568 --- /dev/null +++ b/samples/js-tests/res/Sprite3DTest/boss.obj @@ -0,0 +1,1575 @@ +# WaveFront *.obj file (generated by CINEMA 4D) + +g Object +v 2.152745 1.129535 -2.654346 +v 2.018903 1.184975 -2.654349 +v 2.018903 1.184975 -0.076443 +v 2.152745 1.129537 -0.076443 +v 1.885062 1.129535 -2.654346 +v 1.885062 1.129537 -0.076443 +v 1.829623 0.995695 -2.654346 +v 1.829623 0.995695 -0.076443 +v 1.885062 0.861856 -2.654346 +v 1.885062 0.861855 -0.076443 +v 2.018903 0.806415 -2.654346 +v 2.018903 0.806415 -0.076443 +v 2.152745 0.861856 -2.654346 +v 2.152745 0.861855 -0.076443 +v 2.208183 0.995695 -2.654346 +v 2.208183 0.995695 -0.076443 +v 2.018903 0.995695 0.076003 +v 2.018903 0.995931 -2.778477 +v -2.152745 1.129535 -2.654346 +v -2.018903 1.184975 -2.654349 +v -2.018903 1.184975 -0.076443 +v -2.152745 1.129537 -0.076443 +v -1.885062 1.129535 -2.654346 +v -1.885062 1.129537 -0.076443 +v -1.829623 0.995695 -2.654346 +v -1.829623 0.995695 -0.076443 +v -1.885062 0.861856 -2.654346 +v -1.885062 0.861855 -0.076443 +v -2.018903 0.806415 -2.654346 +v -2.018903 0.806415 -0.076443 +v -2.152745 0.861856 -2.654346 +v -2.152745 0.861855 -0.076443 +v -2.208183 0.995695 -2.654346 +v -2.208183 0.995695 -0.076443 +v -2.018903 0.995695 0.076003 +v -2.018903 0.995931 -2.778477 +v -0.549117 -0.880255 7.049499 +v -0.549117 -0.366897 7.049499 +v -0.549117 -0.231349 7.400979 +v -0.549117 -0.590024 7.42836 +v -2.221097 -0.740847 -0.204388 +v -4.208594 -0.740847 -0.896515 +v -2.221097 0.158004 -0.204388 +v -4.208594 0.158004 -0.896515 +v -2.221097 0.158004 -3.981237 +v -4.208594 0.158004 -3.516596 +v -2.221097 -0.740847 -3.981237 +v -4.208594 -0.740847 -3.516596 +v -2.032921 0.247995 3.029242 +v -1.460364 0.247995 2.792081 +v -0.887809 0.247995 3.029242 +v -0.650649 0.247995 3.601797 +v -0.887809 0.247995 4.174353 +v -1.460364 0.247995 4.411513 +v -2.032921 0.247995 4.174353 +v -2.270081 0.247995 3.601797 +v -2.538304 0.759102 -6.135367 +v -1.965749 0.759102 -6.372528 +v -1.393193 0.759102 -6.135367 +v -1.156033 0.759102 -5.562812 +v -1.393193 0.759102 -4.990256 +v -1.965749 0.759102 -4.753095 +v -2.538304 0.759102 -4.990255 +v -2.775465 0.759102 -5.562812 +v -2.538304 1.408424 -6.135367 +v -1.965749 1.408424 -6.372528 +v -1.393193 1.408424 -6.135367 +v -1.156033 1.408424 -5.562812 +v -1.393193 1.408424 -4.990256 +v -1.965749 1.408424 -4.753095 +v -2.538304 1.408424 -4.990255 +v -2.775465 1.408424 -5.562812 +v -1.965749 1.408424 -5.562812 +v -1.666678 1.334443 -5.145707 +v -2.299088 1.334443 -5.145707 +v -1.666678 1.966853 -5.145707 +v -2.299088 1.966853 -5.145707 +v -1.666678 1.966853 -5.778117 +v -2.299088 1.966853 -5.778117 +v -1.666678 1.334443 -5.778117 +v -2.299088 1.334443 -5.778117 +v -2.036188 1.638001 -5.21675 +v -1.963871 1.667955 -5.216752 +v -1.891555 1.638001 -5.21675 +v 1.735587 0.649931 2.372068 +v 2.276793 0.598225 2.359797 +v 0 -0.880255 7.049499 +v 1.813632 0.760322 -4.076154 +v 0 -0.865952 7.228139 +v 0.525472 0.759814 -4.076156 +v 0.52502 0.704589 1.837225 +v 1.043754 0.65004 2.37211 +v 1.735587 0.771575 2.372068 +v 1.813248 0.882105 0.751968 +v 2.276793 0.719869 2.359797 +v 3.007264 0.675615 0.751926 +v 1.813632 0.881966 -4.076154 +v 3.008201 0.675603 -4.076154 +v 0.525481 0.882195 0.75201 +v 0.525481 0.882292 -4.076154 +v 0.525481 0.826994 1.840059 +v 1.043754 0.771684 2.37211 +v 0.525011 0.758956 0.749175 +v 3.007732 0.553965 -0.738622 +v 3.007732 0.675609 -0.738622 +v 1.81344 0.882035 -0.738601 +v 0.525481 0.882244 -0.73858 +v 0.525241 0.759385 -0.739998 +v -0.549117 -0.399614 7.049499 +v 0.620102 1.844369 -3.601022 +v 0.846037 1.755779 -3.71401 +v 1.310041 0.672056 -4.076154 +v 1.16988 2.894725 -3.501955 +v 1.269897 2.855507 -3.551973 +v 1.132038 2.932909 -3.607564 +v 1.036546 0.428545 5.751309 +v 1.315024 0.760461 0.751968 +v 1.836507 0.376839 5.864282 +v 3.007264 0.553971 0.751926 +v 1.315409 0.760322 -4.076154 +v 3.008201 0.553959 -4.076154 +v 1.232055 2.893691 -3.657582 +v 0 0.760648 -4.076154 +v 0 0.428762 5.751394 +v 0.981744 -0.879086 7.062063 +v 0.981744 0.008673 7.062063 +v 0.534619 1.930626 -3.839588 +v 1.310041 -1.310041 -4.076154 +v 2.997463 -0.990787 -4.076154 +v 2.997463 0.46602 -4.076154 +v 2.997463 0.46602 0.749076 +v 1.310041 -1.310041 0.749076 +v 2.997463 -0.990787 0.749076 +v 1.827392 -0.716184 6.50097 +v 1.25879 -0.770909 7.062063 +v 1.827643 0.288876 5.858582 +v 1.254241 -0.019801 7.062063 +v 0.981744 -0.879086 -8.433464 +v 0.981744 0.879086 -8.433464 +v 1.310041 1.310041 -4.605186 +v 1.310041 -1.310041 -4.605186 +v 2.997463 -0.990787 -4.605186 +v 2.132894 -0.664855 -8.433464 +v 2.997463 0.990787 -4.605186 +v 2.132894 0.664855 -8.433464 +v 2.997463 0.990787 -6.807402 +v 1.310041 1.310041 -6.807402 +v 1.310041 -1.310041 -6.807402 +v 2.997463 -0.990787 -6.807402 +v 3.090473 -0.421017 -4.647384 +v 3.935092 -0.421017 -4.647384 +v 3.090473 0.421017 -4.647384 +v 3.935092 0.421017 -4.647384 +v 3.090473 0.421017 -7.4454 +v 3.935092 0.421017 -7.4454 +v 3.090473 -0.421017 -7.4454 +v 3.935092 -0.421017 -7.4454 +v 3.090473 0.421017 -8.572815 +v 3.620514 0.421017 -8.572815 +v 3.620514 -0.421017 -8.572815 +v 3.090473 -0.421017 -8.572815 +v 1.310041 0.670313 -2.111028 +v 0.655086 0.670313 -0.750658 +v 1.310041 1.517316 -2.111028 +v 0.655086 1.106749 -0.750658 +v 0.655086 1.517316 -4.069324 +v 1.310041 1.517316 -3.4212 +v 1.310041 0.670313 -3.4212 +v 0.655086 0.670313 -4.069324 +v -1.861601 1.565685 -5.216749 +v -1.891555 1.493369 -5.21675 +v -1.963871 1.463414 -5.21675 +v -2.036188 1.493369 -5.21675 +v -2.066142 1.565685 -5.216749 +v -2.036188 1.638001 -4.177855 +v -1.963871 1.667955 -4.177855 +v -1.891555 1.638001 -4.177855 +v -1.861601 1.565685 -4.177855 +v -1.891555 1.493369 -4.177855 +v -1.963871 1.463414 -4.177855 +v -2.036188 1.493369 -4.177855 +v -2.066142 1.565685 -4.177855 +v -1.963871 1.565685 -4.177855 +v -2.036188 1.877795 -5.21675 +v -1.963871 1.907749 -5.216752 +v -1.891555 1.877795 -5.21675 +v -1.861601 1.805479 -5.216749 +v -1.891555 1.733163 -5.21675 +v -1.963871 1.703208 -5.21675 +v -2.036188 1.733163 -5.21675 +v -2.066142 1.805479 -5.216749 +v -2.036188 1.877795 -4.177855 +v -1.963871 1.907749 -4.177855 +v -1.891555 1.877795 -4.177855 +v -1.861601 1.805479 -4.177855 +v -1.891555 1.733163 -4.177855 +v -1.963871 1.703208 -4.177855 +v -2.036188 1.733163 -4.177855 +v -2.066142 1.805479 -4.177855 +v -1.963871 1.805479 -4.177855 +v 0 -1.459791 -3.956097 +v -7.609053 -1.069013 0.551177 +v 1.209824 2.146268 -4.643119 +v 0.549117 -0.865952 7.228139 +v 0.549117 0.004196 7.228139 +v 0.549117 -0.017407 7.0495 +v 0.549117 -0.880255 7.049499 +v 0.549117 -0.366897 7.049499 +v 0.549117 -0.231349 7.400979 +v 0.549117 -0.590024 7.42836 +v 2.221097 -0.740847 -0.204388 +v 4.208594 -0.740847 -0.896515 +v 2.221097 0.158004 -0.204388 +v 4.208594 0.158004 -0.896515 +v 2.221097 0.158004 -3.981237 +v 4.208594 0.158004 -3.516596 +v 2.221097 -0.740847 -3.981237 +v 4.208594 -0.740847 -3.516596 +v 2.032921 0.247995 3.029242 +v 1.460364 0.247995 2.792081 +v 0.887809 0.247995 3.029242 +v 0.650649 0.247995 3.601797 +v 0.887809 0.247995 4.174353 +v 1.460364 0.247995 4.411513 +v 2.032921 0.247995 4.174353 +v 2.270081 0.247995 3.601797 +v -7.609053 -0.765268 0.551177 +v 0.522715 2.473121 -4.605861 +v -7.609053 -0.765268 -0.649518 +v 0.021794 2.612102 -4.048994 +v -7.609053 -1.069013 -0.649518 +v 0 -1.459791 6.071965 +v -5.143484 -1.069013 0.812165 +v 0 -0.765268 6.071965 +v -5.143484 -0.765268 0.812165 +v 2.538304 0.759102 -6.135367 +v 1.965749 0.759102 -6.372528 +v 1.393193 0.759102 -6.135367 +v 1.156033 0.759102 -5.562812 +v 1.393193 0.759102 -4.990256 +v 1.965749 0.759102 -4.753095 +v 2.538304 0.759102 -4.990255 +v 2.775465 0.759102 -5.562812 +v 2.538304 1.408424 -6.135367 +v 1.965749 1.408424 -6.372528 +v 1.393193 1.408424 -6.135367 +v 1.156033 1.408424 -5.562812 +v 1.393193 1.408424 -4.990256 +v 1.965749 1.408424 -4.753095 +v 2.538304 1.408424 -4.990255 +v 2.775465 1.408424 -5.562812 +v 1.965749 1.408424 -5.562812 +v 1.666678 1.334443 -5.145707 +v 2.299088 1.334443 -5.145707 +v 1.666678 1.966853 -5.145707 +v 2.299088 1.966853 -5.145707 +v 1.666678 1.966853 -5.778117 +v 2.299088 1.966853 -5.778117 +v 1.666678 1.334443 -5.778117 +v 2.299088 1.334443 -5.778117 +v 2.036188 1.638001 -5.21675 +v 1.963871 1.667955 -5.216752 +v 1.891555 1.638001 -5.21675 +v 1.861601 1.565685 -5.216749 +v 1.891555 1.493369 -5.21675 +v 1.963871 1.463414 -5.21675 +v 2.036188 1.493369 -5.21675 +v 2.066142 1.565685 -5.216749 +v 2.036188 1.638001 -4.177855 +v 1.963871 1.667955 -4.177855 +v 1.891555 1.638001 -4.177855 +v 1.861601 1.565685 -4.177855 +v 1.891555 1.493369 -4.177855 +v 1.963871 1.463414 -4.177855 +v 2.036188 1.493369 -4.177855 +v 2.066142 1.565685 -4.177855 +v 1.963871 1.565685 -4.177855 +v 2.036188 1.877795 -5.21675 +v 1.963871 1.907749 -5.216752 +v 1.891555 1.877795 -5.21675 +v 1.861601 1.805479 -5.216749 +v 1.891555 1.733163 -5.21675 +v 1.963871 1.703208 -5.21675 +v 2.036188 1.733163 -5.21675 +v 2.066142 1.805479 -5.216749 +v 2.036188 1.877795 -4.177855 +v 1.963871 1.907749 -4.177855 +v 1.891555 1.877795 -4.177855 +v 1.861601 1.805479 -4.177855 +v 1.891555 1.733163 -4.177855 +v 1.963871 1.703208 -4.177855 +v 2.036188 1.733163 -4.177855 +v 2.066142 1.805479 -4.177855 +v 1.963871 1.805479 -4.177855 +v 0.760554 1.842035 -3.952577 +v 7.609053 -1.069013 0.551177 +v 0 -0.765268 -3.956097 +v 7.609053 -0.765268 0.551177 +v 0 -0.765268 -7.732946 +v 7.609053 -0.765268 -0.649518 +v 0 -1.459791 -7.732946 +v 7.609053 -1.069013 -0.649518 +v 1.214601 2.038227 -4.805394 +v 5.143484 -1.069013 0.812165 +v 0.421783 2.415365 -4.762404 +v 5.143484 -0.765268 0.812165 +v 0 -0.765268 0.439388 +v 5.143484 -0.765268 -0.38853 +v -0.156203 2.575728 -4.119865 +v 5.143484 -1.069013 -0.38853 +v 1.032114 0.340364 5.745526 +v 0.964145 -1.094563 6.551094 +v 0 0.340364 5.745526 +v 0 0.008673 7.062063 +v -0.180782 2.425379 -3.254169 +v 0.362446 2.052389 -2.672427 +v 1.155263 1.675251 -2.715417 +v 0 -1.310041 -4.076154 +v 0 0.672056 -4.076154 +v 0 0.670313 -0.750658 +v 0 1.106749 -0.750658 +v 0 1.517316 -2.111028 +v 0 1.517316 -3.4212 +v 0 1.517316 -4.069324 +v 1.733249 1.514889 -3.357956 +v 1.757828 1.665238 -4.223653 +v 1.266634 2.145324 -4.785317 +v 0.473817 2.522462 -4.742327 +v -0.10417 2.682825 -4.099788 +v 0 -1.310041 -6.807402 +v 0 -1.310041 -4.605186 +v 1.543045 -1.342558 4.494025 +v 1.543045 -0.765268 4.494025 +v 1.543045 -0.765268 0.191013 +v 1.543045 -1.342558 0.191013 +v -0.128748 2.532475 -3.234091 +v 0.414479 2.159486 -2.652349 +v 0 -0.017407 7.0495 +v 0 0.004196 7.228139 +v 1.207297 1.782348 -2.69534 +v 1.785283 1.621985 -3.337879 +v 0.549117 -0.399614 7.049499 +v -1.735587 0.649931 2.372068 +v -2.276793 0.598225 2.359797 +v 1.809861 1.772335 -4.203576 +v -1.813632 0.760322 -4.076154 +v 0.937994 1.747884 -4.5237 +v -0.525472 0.759814 -4.076156 +v -0.52502 0.704589 1.837225 +v -1.043754 0.65004 2.37211 +v -1.735587 0.771575 2.372068 +v -1.813248 0.882105 0.751968 +v -2.276793 0.719869 2.359797 +v -3.007264 0.675615 0.751926 +v -1.813632 0.881966 -4.076154 +v -3.008201 0.675603 -4.076154 +v -0.525481 0.882195 0.75201 +v -0.525481 0.882292 -4.076154 +v -0.525481 0.826994 1.840059 +v -1.043754 0.771684 2.37211 +v -0.525011 0.758956 0.749175 +v -3.007732 0.553965 -0.738622 +v -3.007732 0.675609 -0.738622 +v -1.81344 0.882035 -0.738601 +v -0.525481 0.882244 -0.73858 +v -0.525241 0.759385 -0.739998 +v -1.032114 0.340364 5.745526 +v 0.583818 1.623981 -3.817896 +v 0.395361 2.00601 -4.494276 +v -1.310041 0.672056 -4.076154 +v -2.997463 0.46602 -4.076154 +v -0.000234 2.115768 -4.054499 +v -0.017056 2.012864 -3.461985 +v -1.036546 0.428545 5.751309 +v -1.315024 0.760461 0.751968 +v -1.836507 0.376839 5.864282 +v -3.007264 0.553971 0.751926 +v -1.315409 0.760322 -4.076154 +v -3.008201 0.553959 -4.076154 +v 0 0.760551 0.75201 +v 0.354749 1.757576 -3.06382 +v 0.897382 1.49945 -3.093244 +v -0.981744 -0.879086 7.062063 +v -0.981744 0.008673 7.062063 +v 1.292976 1.389691 -3.533021 +v -1.310041 -1.310041 -4.076154 +v -2.997463 -0.990787 -4.076154 +v 1.309798 1.492596 -4.125535 +v -2.997463 0.46602 0.749076 +v -1.310041 -1.310041 0.749076 +v -2.997463 -0.990787 0.749076 +v -1.827392 -0.716184 6.50097 +v -1.25879 -0.770909 7.062063 +v -1.827643 0.288876 5.858582 +v -1.254241 -0.019801 7.062063 +v -0.981744 -0.879086 -8.433464 +v -0.981744 0.879086 -8.433464 +v -1.310041 1.310041 -4.605186 +v -1.310041 -1.310041 -4.605186 +v -2.997463 -0.990787 -4.605186 +v -2.132894 -0.664855 -8.433464 +v -2.997463 0.990787 -4.605186 +v -2.132894 0.664855 -8.433464 +v -2.997463 0.990787 -6.807402 +v -1.310041 1.310041 -6.807402 +v -1.310041 -1.310041 -6.807402 +v -2.997463 -0.990787 -6.807402 +v -3.090473 -0.421017 -4.647384 +v -3.935092 -0.421017 -4.647384 +v -3.090473 0.421017 -4.647384 +v -3.935092 0.421017 -4.647384 +v -3.090473 0.421017 -7.4454 +v -3.935092 0.421017 -7.4454 +v -3.090473 -0.421017 -7.4454 +v -3.935092 -0.421017 -7.4454 +v -3.090473 0.421017 -8.572815 +v -3.620514 0.421017 -8.572815 +v -3.620514 -0.421017 -8.572815 +v -3.090473 -0.421017 -8.572815 +v -1.310041 0.670313 -2.111028 +v -0.655086 0.670313 -0.750658 +v -1.310041 1.517316 -2.111028 +v -0.655086 1.106749 -0.750658 +v -0.655086 1.517316 -4.069324 +v -1.310041 1.517316 -3.4212 +v -1.310041 0.670313 -3.4212 +v -0.655086 0.670313 -4.069324 +v 0.000493 2.481799 -3.298723 +v -5.143484 -0.765268 -0.38853 +v 0 -1.459791 0.439388 +v -5.143484 -1.069013 -0.38853 +v 0.47129 2.158541 -2.794548 +v -0.964145 -1.094563 6.551094 +v 1.158398 1.831689 -2.831806 +v 1.65932 1.692708 -3.388673 +v 0 -0.879086 7.062063 +v 0 -1.094563 6.551094 +v 0 -1.310041 0.749076 +v 1.680621 1.823011 -4.138944 +v 0.980091 1.966239 -4.324068 +v 0.702984 1.869251 -3.771916 +v 0.555579 2.168176 -4.301049 +v 0.246098 2.254042 -3.957004 +v 0.232938 2.173538 -3.493469 +v -0.549117 -0.865952 7.228139 +v 0.523807 1.973822 -3.181978 +v 0.948319 1.771885 -3.204996 +v 0 1.310041 -4.605186 +v 0 1.310041 -6.807402 +v 0 0.879086 -8.433464 +v -0.549117 0.004196 7.228139 +v -0.549117 -0.017407 7.0495 +v 0 -0.879086 -8.433464 +v 1.257799 1.686019 -3.549042 +v 1.27096 1.766523 -4.012577 +v -1.543045 -1.342558 4.494025 +v -1.543045 -0.765268 4.494025 +v -1.543045 -0.765268 0.191013 +v -1.543045 -1.342558 0.191013 +v 0 -0.590024 7.42836 +v 0 -0.231349 7.400979 + +vt 0.401122 0.24589 0 +vt 0.422237 0.155289 0 +vt 0.408574 0.264883 0 +vt 0.426978 0.155184 0 +vt 0.427029 0.272985 0 +vt 0.428212 0.21811 0 +vt 0.445931 0.265758 0 +vt 0.42348 0.218206 0 +vt 0.4272 0.27239 0 +vt 0.431721 0.155075 0 +vt 0.408554 0.26473 0 +vt 0.432943 0.218016 0 +vt 0.445663 0.265617 0 +vt 0.436468 0.154961 0 +vt 0.401327 0.245829 0 +vt 0.437675 0.217926 0 +vt 0.453094 0.247489 0 +vt 0.441219 0.154844 0 +vt 0.409582 0.227353 0 +vt 0.442407 0.217839 0 +vt 0.446378 0.229457 0 +vt 0.40802 0.155591 0 +vt 0.445975 0.154726 0 +vt 0.428835 0.22083 0 +vt 0.409279 0.218484 0 +vt 0.447548 0.217839 0 +vt 0.42874 0.221085 0 +vt 0.412758 0.155492 0 +vt 0.446431 0.229436 0 +vt 0.414015 0.218391 0 +vt 0.409701 0.227457 0 +vt 0.417497 0.155392 0 +vt 0.453306 0.247283 0 +vt 0.418748 0.218299 0 +vt 0.428284 0.246556 0 +vt 0.428479 0.246771 0 +vt 0.401122 0.24589 0 +vt 0.422237 0.155289 0 +vt 0.408574 0.264883 0 +vt 0.426978 0.155184 0 +vt 0.427029 0.272985 0 +vt 0.428212 0.21811 0 +vt 0.445931 0.265758 0 +vt 0.42348 0.218206 0 +vt 0.4272 0.27239 0 +vt 0.431721 0.155075 0 +vt 0.408554 0.26473 0 +vt 0.432943 0.218016 0 +vt 0.445663 0.265617 0 +vt 0.436468 0.154961 0 +vt 0.401327 0.245829 0 +vt 0.437675 0.217926 0 +vt 0.453094 0.247489 0 +vt 0.441219 0.154844 0 +vt 0.409582 0.227353 0 +vt 0.442407 0.217839 0 +vt 0.446378 0.229457 0 +vt 0.40802 0.155591 0 +vt 0.445975 0.154726 0 +vt 0.428835 0.22083 0 +vt 0.409279 0.218484 0 +vt 0.447548 0.217839 0 +vt 0.42874 0.221085 0 +vt 0.412758 0.155492 0 +vt 0.446431 0.229436 0 +vt 0.414015 0.218391 0 +vt 0.409701 0.227457 0 +vt 0.417497 0.155392 0 +vt 0.453306 0.247283 0 +vt 0.418748 0.218299 0 +vt 0.428284 0.246556 0 +vt 0.428479 0.246771 0 +vt 0.406674 0.167689 0 +vt 0.34778 0.206333 0 +vt 0.400506 0.092061 0 +vt 0.34714 0.076348 0 +vt 0.347422 0.129521 0 +vt 0.25309 0.155811 0 +vt 0.986632 0.334252 0 +vt 0.900869 0.480587 0 +vt 0.178263 0.12975 0 +vt 0.948411 0.446335 0 +vt 0.938762 0.317929 0 +vt 0.90054 0.43001 0 +vt 0.726249 0.319303 0 +vt 0.753116 0.430966 0 +vt 0.253094 0.013616 0 +vt 0.677076 0.331135 0 +vt 0.753444 0.48154 0 +vt 0.178266 0.031107 0 +vt 0.703943 0.442796 0 +vt 0.946295 0.240423 0 +vt 0.661994 0.243219 0 +vt 0.991137 0.240398 0 +vt 0.701254 0.243258 0 +vt 0.739885 0.243356 0 +vt 0.778704 0.243132 0 +vt 0.818178 0.242671 0 +vt 0.858856 0.241693 0 +vt 0.90173 0.240871 0 +vt 0.973266 0.207191 0 +vt 0.94624 0.287074 0 +vt 0.911901 0.23261 0 +vt 0.662047 0.284293 0 +vt 0.991082 0.287208 0 +vt 0.850535 0.207191 0 +vt 0.701289 0.284167 0 +vt 0.825117 0.145826 0 +vt 0.739912 0.284018 0 +vt 0.850535 0.084461 0 +vt 0.778729 0.284198 0 +vt 0.911901 0.059042 0 +vt 0.818183 0.284624 0 +vt 0.973266 0.084461 0 +vt 0.858836 0.28562 0 +vt 0.998684 0.145826 0 +vt 0.901683 0.286519 0 +vt 0.911901 0.142355 0 +vt 0.565962 0.396112 0 +vt 0.520712 0.441362 0 +vt 0.611211 0.396112 0 +vt 0.656461 0.441362 0 +vt 0.565962 0.441362 0 +vt 0.611211 0.441362 0 +vt 0.565962 0.486611 0 +vt 0.611211 0.486611 0 +vt 0.565962 0.531861 0 +vt 0.520712 0.486611 0 +vt 0.611211 0.531861 0 +vt 0.656461 0.486611 0 +vt 0.352159 0.224968 0 +vt 0.355175 0.224967 0 +vt 0.35819 0.224967 0 +vt 0.901262 0.530297 0 +vt 0.945558 0.536298 0 +vt 0.938872 0.531149 0 +vt 0.266663 0.206735 0 +vt 0.902345 0.986421 0 +vt 0.266539 0.18027 0 +vt 0.813927 0.986075 0 +vt 0.809312 0.573689 0 +vt 0.812099 0.56775 0 +vt 0.853688 0.529528 0 +vt 0.848087 0.53162 0 +vt 0.900755 0.538571 0 +vt 0.904638 0.649276 0 +vt 0.937884 0.539507 0 +vt 0.987257 0.649743 0 +vt 0.90173 0.978186 0 +vt 0.984307 0.979178 0 +vt 0.816956 0.648322 0 +vt 0.813964 0.977666 0 +vt 0.81769 0.573982 0 +vt 0.853542 0.537896 0 +vt 0.808549 0.64825 0 +vt 0.994729 0.751596 0 +vt 0.986429 0.751521 0 +vt 0.903756 0.750787 0 +vt 0.815903 0.749985 0 +vt 0.807509 0.749992 0 +vt 0.400909 0.096914 0 +vt 0.453481 0.393554 0 +vt 0.481795 0.340046 0 +vt 0.538348 0.389938 0 +vt 0.493884 0.33955 0 +vt 0.062187 0.98965 0 +vt 0.69945 0.98606 0 +vt 0.48742 0.393554 0 +vt 0.49267 0.393289 0 +vt 0.487583 0.397153 0 +vt 0.687993 0.503583 0 +vt 0.69842 0.750594 0 +vt 0.727594 0.498641 0 +vt 0.780939 0.750999 0 +vt 0.995564 0.649813 0 +vt 0.994931 0.646535 0 +vt 0.699276 0.981779 0 +vt 0.779679 0.980604 0 +vt 0.992605 0.979257 0 +vt 0.985632 0.987425 0 +vt 0.492708 0.397856 0 +vt 0.636086 0.982285 0 +vt 0.636859 0.503126 0 +vt 0.047272 0.488901 0 +vt 0.05879 0.007778 0 +vt 0.058235 0.053941 0 +vt 0.453908 0.401172 0 +vt 0.477006 0.449213 0 +vt 0.057779 0.913566 0 +vt 0.407615 0.505451 0 +vt 0.123087 0.916212 0 +vt 0.346673 0.542322 0 +vt 0.128965 0.974582 0 +vt 0.782818 0.981712 0 +vt 0.224808 0.340362 0 +vt 0.785169 0.750557 0 +vt 0.058749 0.73063 0 +vt 0.124342 0.730754 0 +vt 0.28587 0.303495 0 +vt 0.0814 0.510898 0 +vt 0.125459 0.063828 0 +vt 0.102683 0.029981 0 +vt 0.073324 0.01374 0 +vt 0.05933 0.488428 0 +vt 0.099108 0.116354 0 +vt 0.731869 0.49777 0 +vt 0.726871 0.494355 0 +vt 0.072323 0.053475 0 +vt 0.424823 0.351441 0 +vt 0.193953 0.981583 0 +vt 0.188639 0.887683 0 +vt 0.199784 0.698522 0 +vt 0.20532 0.571215 0 +vt 0.438044 0.211097 0 +vt 0.384199 0.711565 0 +vt 0.500316 0.212631 0 +vt 0.290876 0.593575 0 +vt 0.258604 0.963636 0 +vt 0.467461 0.353125 0 +vt 0.318819 0.910112 0 +vt 0.283877 0.695369 0 +vt 0.252001 0.887726 0 +vt 0.275255 0.80017 0 +vt 0.19945 0.803168 0 +vt 0.436354 0.290608 0 +vt 0.3662 0.823057 0 +vt 0.498348 0.292484 0 +vt 0.495948 0.957021 0 +vt 0.10292 0.392065 0 +vt 0.45675 0.997198 0 +vt 0.375916 0.956447 0 +vt 0.075154 0.42042 0 +vt 0.416227 0.997221 0 +vt 0.456712 0.956816 0 +vt 0.416225 0.956806 0 +vt 0.456172 0.82355 0 +vt 0.416731 0.824647 0 +vt 0.496678 0.822937 0 +vt 0.196696 0.483704 0 +vt 0.169196 0.512305 0 +vt 0.377041 0.822595 0 +vt 0.452832 0.768161 0 +vt 0.425823 0.769999 0 +vt 0.218443 0.537816 0 +vt 0.384197 0.764756 0 +vt 0.422662 0.726694 0 +vt 0.49481 0.766707 0 +vt 0.23535 0.519557 0 +vt 0.449921 0.724799 0 +vt 0.095834 0.208772 0 +vt 0.039343 0.137854 0 +vt 0.057027 0.147654 0 +vt 0.062632 0.222927 0 +vt 0.039308 0.158849 0 +vt 0.04078 0.315102 0 +vt 0.070835 0.280228 0 +vt 0.102932 0.307938 0 +vt 0.110762 0.270579 0 +vt 0.041282 0.358462 0 +vt 0.072792 0.342824 0 +vt 0.361206 0.224968 0 +vt 0.364222 0.224968 0 +vt 0.343112 0.224967 0 +vt 0.367238 0.224968 0 +vt 0.346128 0.224967 0 +vt 0.349143 0.224968 0 +vt 0.328345 0.296397 0 +vt 0.352159 0.264994 0 +vt 0.316111 0.301074 0 +vt 0.355175 0.264994 0 +vt 0.304153 0.295731 0 +vt 0.35819 0.264994 0 +vt 0.299475 0.283498 0 +vt 0.361206 0.264994 0 +vt 0.304818 0.271539 0 +vt 0.364222 0.264994 0 +vt 0.317052 0.266862 0 +vt 0.343112 0.264994 0 +vt 0.367238 0.264994 0 +vt 0.32901 0.272205 0 +vt 0.346128 0.264994 0 +vt 0.333688 0.284439 0 +vt 0.349143 0.264994 0 +vt 0.316582 0.283968 0 +vt 0.312838 0.224509 0 +vt 0.315906 0.22444 0 +vt 0.318977 0.22437 0 +vt 0.322049 0.224296 0 +vt 0.325124 0.22422 0 +vt 0.303636 0.224704 0 +vt 0.328202 0.224144 0 +vt 0.306703 0.22464 0 +vt 0.30977 0.224575 0 +vt 0.368307 0.296009 0 +vt 0.313643 0.265231 0 +vt 0.356074 0.300686 0 +vt 0.316705 0.265169 0 +vt 0.344115 0.295343 0 +vt 0.319768 0.265108 0 +vt 0.339438 0.28311 0 +vt 0.32283 0.26505 0 +vt 0.344781 0.271151 0 +vt 0.325893 0.264994 0 +vt 0.357015 0.266474 0 +vt 0.304451 0.265411 0 +vt 0.32922 0.264994 0 +vt 0.368973 0.271817 0 +vt 0.307516 0.265351 0 +vt 0.37365 0.284051 0 +vt 0.31058 0.265291 0 +vt 0.356544 0.28358 0 +vt 0.11116 0.337 0 +vt 0.614968 0.723363 0 +vt 0.608538 0.990523 0 +vt 0.29194 0.529223 0 +vt 0.62133 0.98202 0 +vt 0.369034 0.609455 0 +vt 0.380177 0.167709 0 +vt 0.347655 0.179822 0 +vt 0.369767 0.039595 0 +vt 0.346915 0.033192 0 +vt 0.396334 0.040637 0 +vt 0.346793 0.00661 0 +vt 0.406674 0.167689 0 +vt 0.34778 0.206333 0 +vt 0.400506 0.092061 0 +vt 0.34714 0.076348 0 +vt 0.347422 0.129521 0 +vt 0.25309 0.155811 0 +vt 0.986632 0.334252 0 +vt 0.900869 0.480587 0 +vt 0.178263 0.12975 0 +vt 0.948411 0.446335 0 +vt 0.938762 0.317929 0 +vt 0.90054 0.43001 0 +vt 0.726249 0.319303 0 +vt 0.753116 0.430966 0 +vt 0.253094 0.013616 0 +vt 0.677076 0.331135 0 +vt 0.753444 0.48154 0 +vt 0.178266 0.031107 0 +vt 0.703943 0.442796 0 +vt 0.612474 0.98263 0 +vt 0.34598 0.618839 0 +vt 0.581161 0.967031 0 +vt 0.323125 0.60923 0 +vt 0.577236 0.974932 0 +vt 0.301895 0.494844 0 +vt 0.57263 0.969518 0 +vt 0.510333 0.226098 0 +vt 0.382299 0.360197 0 +vt 0.667065 0.356807 0 +vt 0.610495 0.598294 0 +vt 0.614647 0.607502 0 +vt 0.360782 0.383711 0 +vt 0.601286 0.608074 0 +vt 0.946295 0.240423 0 +vt 0.661994 0.243219 0 +vt 0.991137 0.240398 0 +vt 0.701254 0.243258 0 +vt 0.739885 0.243356 0 +vt 0.778704 0.243132 0 +vt 0.818178 0.242671 0 +vt 0.858856 0.241693 0 +vt 0.90173 0.240871 0 +vt 0.973266 0.207191 0 +vt 0.94624 0.287074 0 +vt 0.911901 0.23261 0 +vt 0.662047 0.284293 0 +vt 0.991082 0.287208 0 +vt 0.850535 0.207191 0 +vt 0.701289 0.284167 0 +vt 0.825117 0.145826 0 +vt 0.739912 0.284018 0 +vt 0.850535 0.084461 0 +vt 0.778729 0.284198 0 +vt 0.911901 0.059042 0 +vt 0.818183 0.284624 0 +vt 0.973266 0.084461 0 +vt 0.858836 0.28562 0 +vt 0.998684 0.145826 0 +vt 0.901683 0.286519 0 +vt 0.911901 0.142355 0 +vt 0.520712 0.441362 0 +vt 0.565962 0.396112 0 +vt 0.656461 0.441362 0 +vt 0.611211 0.396112 0 +vt 0.565962 0.441362 0 +vt 0.611211 0.441362 0 +vt 0.565962 0.486611 0 +vt 0.611211 0.486611 0 +vt 0.520712 0.486611 0 +vt 0.565962 0.531861 0 +vt 0.656461 0.486611 0 +vt 0.611211 0.531861 0 +vt 0.352159 0.224968 0 +vt 0.355175 0.224967 0 +vt 0.35819 0.224967 0 +vt 0.361206 0.224968 0 +vt 0.364222 0.224968 0 +vt 0.343112 0.224967 0 +vt 0.367238 0.224968 0 +vt 0.346128 0.224967 0 +vt 0.349143 0.224968 0 +vt 0.328345 0.296397 0 +vt 0.352159 0.264994 0 +vt 0.316111 0.301074 0 +vt 0.355175 0.264994 0 +vt 0.304153 0.295731 0 +vt 0.35819 0.264994 0 +vt 0.299475 0.283498 0 +vt 0.361206 0.264994 0 +vt 0.304818 0.271539 0 +vt 0.364222 0.264994 0 +vt 0.317052 0.266862 0 +vt 0.343112 0.264994 0 +vt 0.367238 0.264994 0 +vt 0.32901 0.272205 0 +vt 0.346128 0.264994 0 +vt 0.333688 0.284439 0 +vt 0.349143 0.264994 0 +vt 0.316582 0.283968 0 +vt 0.312838 0.224509 0 +vt 0.315906 0.22444 0 +vt 0.318977 0.22437 0 +vt 0.322049 0.224296 0 +vt 0.325124 0.22422 0 +vt 0.303636 0.224704 0 +vt 0.328202 0.224144 0 +vt 0.306703 0.22464 0 +vt 0.30977 0.224575 0 +vt 0.368307 0.296009 0 +vt 0.313643 0.265231 0 +vt 0.356074 0.300686 0 +vt 0.316705 0.265169 0 +vt 0.344115 0.295343 0 +vt 0.319768 0.265108 0 +vt 0.339438 0.28311 0 +vt 0.32283 0.26505 0 +vt 0.344781 0.271151 0 +vt 0.325893 0.264994 0 +vt 0.357015 0.266474 0 +vt 0.304451 0.265411 0 +vt 0.32922 0.264994 0 +vt 0.368973 0.271817 0 +vt 0.307516 0.265351 0 +vt 0.37365 0.284051 0 +vt 0.31058 0.265291 0 +vt 0.356544 0.28358 0 +vt 0.538458 0.400243 0 +vt 0.488848 0.450839 0 +vt 0.608538 0.990523 0 +vt 0.29194 0.529223 0 +vt 0.62133 0.98202 0 +vt 0.594713 0.724759 0 +vt 0.612474 0.98263 0 +vt 0.49603 0.675106 0 +vt 0.581161 0.967031 0 +vt 0.142475 0.228861 0 +vt 0.476527 0.680791 0 +vt 0.577236 0.974932 0 +vt 0.301895 0.494844 0 +vt 0.57263 0.969518 0 +vt 0.367986 0.565002 0 +vt 0.425478 0.616457 0 +vt 0.425848 0.486287 0 +vt 0.667065 0.356807 0 +vt 0.610495 0.598294 0 +vt 0.614647 0.607502 0 +vt 0.345685 0.555992 0 +vt 0.425794 0.505287 0 +vt 0.601286 0.608074 0 +vt 0.374237 0.635974 0 +vt 0.603553 0.660983 0 +vt 0.324555 0.565556 0 +vt 0.425737 0.525603 0 +vt 0.670709 0.390276 0 +vt 0.602008 0.674295 0 +vt 0.616898 0.660405 0 +vt 0.059939 0.122085 0 +vt 0.687668 0.499238 0 +vt 0.045477 0.509967 0 +vt 0.008219 0.122247 0 +vt 0.636899 0.498768 0 +vt 0.008104 0.053923 0 +vt 0.316467 0.586764 0 +vt 0.425678 0.546256 0 +vt 0.325297 0.607393 0 +vt 0.425622 0.565813 0 +vt 0.345968 0.616042 0 +vt 0.425573 0.583176 0 +vt 0.008828 0.913903 0 +vt 0.008828 0.991382 0 +vt 0.636121 0.986565 0 +vt 0.007736 0.358786 0 +vt 0.007736 0.137802 0 +vt 0.007736 0.157777 0 +vt 0.007736 0.222377 0 +vt 0.007736 0.284298 0 +vt 0.007736 0.316526 0 +vt 0.366961 0.607857 0 +vt 0.425532 0.597655 0 +vt 0.376419 0.586974 0 +vt 0.4255 0.608967 0 +vt 0.372567 0.613026 0 +vt 0.418233 0.616858 0 +vt 0.418604 0.486279 0 +vt 0.345949 0.623829 0 +vt 0.41855 0.505269 0 +vt 0.319594 0.612732 0 +vt 0.418492 0.525551 0 +vt 0.389044 0.29016 0 +vt 0.137994 0.570166 0 +vt 0.390497 0.210232 0 +vt 0.557298 0.26537 0 +vt 0.453183 0.43316 0 +vt 0.435459 0.452036 0 +vt 0.443424 0.642622 0 +vt 0.569111 0.384092 0 +vt 0.44067 0.668067 0 +vt 0.308742 0.586347 0 +vt 0.418434 0.546192 0 +vt 0.319631 0.559984 0 +vt 0.418378 0.565797 0 +vt 0.26567 0.007003 0 +vt 0.265811 0.033587 0 +vt 0.345967 0.548943 0 +vt 0.418328 0.583226 0 +vt 0.372506 0.559731 0 +vt 0.418287 0.597784 0 +vt 0.400909 0.096914 0 +vt 0.901262 0.530297 0 +vt 0.945558 0.536298 0 +vt 0.938872 0.531149 0 +vt 0.383698 0.586308 0 +vt 0.418254 0.609248 0 +vt 0.902345 0.986421 0 +vt 0.359357 0.573792 0 +vt 0.813927 0.986075 0 +vt 0.809312 0.573689 0 +vt 0.812099 0.56775 0 +vt 0.853688 0.529528 0 +vt 0.848087 0.53162 0 +vt 0.900755 0.538571 0 +vt 0.904638 0.649276 0 +vt 0.937884 0.539507 0 +vt 0.987257 0.649743 0 +vt 0.90173 0.978186 0 +vt 0.984307 0.979178 0 +vt 0.816956 0.648322 0 +vt 0.813964 0.977666 0 +vt 0.81769 0.573982 0 +vt 0.853542 0.537896 0 +vt 0.808549 0.64825 0 +vt 0.994729 0.751596 0 +vt 0.986429 0.751521 0 +vt 0.903756 0.750787 0 +vt 0.815903 0.749985 0 +vt 0.807509 0.749992 0 +vt 0.059939 0.122085 0 +vt 0.687668 0.499238 0 +vt 0.346162 0.586441 0 +vt 0.345869 0.568161 0 +vt 0.062187 0.98965 0 +vt 0.69945 0.98606 0 +vt 0.346673 0.542322 0 +vt 0.128965 0.974582 0 +vt 0.782818 0.981712 0 +vt 0.333221 0.573771 0 +vt 0.328226 0.586552 0 +vt 0.687993 0.503583 0 +vt 0.69842 0.750594 0 +vt 0.727594 0.498641 0 +vt 0.780939 0.750999 0 +vt 0.995564 0.649813 0 +vt 0.994931 0.646535 0 +vt 0.699276 0.981779 0 +vt 0.779679 0.980604 0 +vt 0.992605 0.979257 0 +vt 0.985632 0.987425 0 +vt 0.634522 0.750265 0 +vt 0.333547 0.599086 0 +vt 0.346093 0.604325 0 +vt 0.05879 0.007778 0 +vt 0.047272 0.488901 0 +vt 0.058235 0.053941 0 +vt 0.358792 0.599285 0 +vt 0.057779 0.913566 0 +vt 0.407615 0.505451 0 +vt 0.123087 0.916212 0 +vt 0.364368 0.586675 0 +vt 0.224808 0.340362 0 +vt 0.785169 0.750557 0 +vt 0.058749 0.73063 0 +vt 0.28587 0.303495 0 +vt 0.124342 0.730754 0 +vt 0.125459 0.063828 0 +vt 0.0814 0.510898 0 +vt 0.102683 0.029981 0 +vt 0.073324 0.01374 0 +vt 0.05933 0.488428 0 +vt 0.099108 0.116354 0 +vt 0.731869 0.49777 0 +vt 0.726871 0.494355 0 +vt 0.072323 0.053475 0 +vt 0.193953 0.981583 0 +vt 0.424823 0.351441 0 +vt 0.188639 0.887683 0 +vt 0.199784 0.698522 0 +vt 0.438044 0.211097 0 +vt 0.20532 0.571215 0 +vt 0.384199 0.711565 0 +vt 0.500316 0.212631 0 +vt 0.290876 0.593575 0 +vt 0.258604 0.963636 0 +vt 0.467461 0.353125 0 +vt 0.318819 0.910112 0 +vt 0.283877 0.695369 0 +vt 0.252001 0.887726 0 +vt 0.275255 0.80017 0 +vt 0.19945 0.803168 0 +vt 0.436354 0.290608 0 +vt 0.3662 0.823057 0 +vt 0.498348 0.292484 0 +vt 0.495948 0.957021 0 +vt 0.10292 0.392065 0 +vt 0.45675 0.997198 0 +vt 0.375916 0.956447 0 +vt 0.075154 0.42042 0 +vt 0.416227 0.997221 0 +vt 0.456712 0.956816 0 +vt 0.416225 0.956806 0 +vt 0.456172 0.82355 0 +vt 0.416731 0.824647 0 +vt 0.496678 0.822937 0 +vt 0.196696 0.483704 0 +vt 0.169196 0.512305 0 +vt 0.377041 0.822595 0 +vt 0.452832 0.768161 0 +vt 0.425823 0.769999 0 +vt 0.218443 0.537816 0 +vt 0.384197 0.764756 0 +vt 0.422662 0.726694 0 +vt 0.49481 0.766707 0 +vt 0.23535 0.519557 0 +vt 0.449921 0.724799 0 +vt 0.095834 0.208772 0 +vt 0.057027 0.147654 0 +vt 0.039343 0.137854 0 +vt 0.062632 0.222927 0 +vt 0.039308 0.158849 0 +vt 0.04078 0.315102 0 +vt 0.070835 0.280228 0 +vt 0.102932 0.307938 0 +vt 0.110762 0.270579 0 +vt 0.072792 0.342824 0 +vt 0.041282 0.358462 0 +vt 0.313711 0.586352 0 +vt 0.603553 0.660983 0 +vt 0.525739 0.381449 0 +vt 0.371282 0.666665 0 +vt 0.670709 0.390276 0 +vt 0.602008 0.674295 0 +vt 0.616898 0.660405 0 +vt 0.323155 0.563492 0 +vt 0.045477 0.509967 0 +vt 0.345996 0.553927 0 +vt 0.368994 0.563294 0 +vt 0.007243 0.008448 0 +vt 0.008828 0.488425 0 +vt 0.008828 0.509895 0 +vt 0.008828 0.730482 0 +vt 0.378658 0.586315 0 +vt 0.359372 0.599752 0 +vt 0.346081 0.586365 0 +vt 0.346045 0.605197 0 +vt 0.332779 0.599642 0 +vt 0.327306 0.586362 0 +vt 0.380177 0.167709 0 +vt 0.347655 0.179822 0 +vt 0.332793 0.573092 0 +vt 0.346054 0.567553 0 +vt 0.137994 0.695528 0 +vt 0.137994 0.804199 0 +vt 0.137994 0.891424 0 +vt 0.369767 0.039595 0 +vt 0.346915 0.033192 0 +vt 0.396334 0.040637 0 +vt 0.346793 0.00661 0 +vt 0.389055 0.351447 0 +vt 0.137994 0.982716 0 +vt 0.359376 0.573 0 +vt 0.36494 0.586271 0 +vt 0.557298 0.26537 0 +vt 0.453183 0.43316 0 +vt 0.435459 0.452036 0 +vt 0.443424 0.642622 0 +vt 0.569111 0.384092 0 +vt 0.44067 0.668067 0 +vt 0.266302 0.129883 0 +vt 0.266035 0.076773 0 + +f 209/327 342/531 208/326 206/322 205/320 +f 452/688 38/75 109/161 39/76 451/686 +f 1/2 2/4 3/6 4/8 +f 2/4 5/10 6/12 3/6 +f 5/10 7/14 8/16 6/12 +f 7/14 9/18 10/20 8/16 +f 9/18 11/23 12/26 10/20 +f 11/22 13/28 14/30 12/25 +f 13/28 15/32 16/34 14/30 +f 15/32 1/2 4/8 16/34 +f 4/7 3/5 17/35 +f 3/5 6/11 17/35 +f 6/11 8/15 17/35 +f 8/15 10/19 17/35 +f 10/19 12/24 17/35 +f 12/24 14/29 17/35 +f 14/29 16/33 17/35 +f 16/33 4/7 17/35 +f 5/9 2/3 18/36 +f 18/36 2/3 1/1 +f 11/21 18/36 13/27 +f 9/17 18/36 11/21 +f 5/9 18/36 7/13 +f 7/13 18/36 9/17 +f 13/27 18/36 15/31 +f 15/31 18/36 1/1 +f 19/38 22/44 21/42 20/40 +f 20/40 21/42 24/48 23/46 +f 23/46 24/48 26/52 25/50 +f 25/50 26/52 28/56 27/54 +f 27/54 28/56 30/62 29/59 +f 29/58 30/61 32/66 31/64 +f 31/64 32/66 34/70 33/68 +f 33/68 34/70 22/44 19/38 +f 22/43 35/71 21/41 +f 21/41 35/71 24/47 +f 24/47 35/71 26/51 +f 26/51 35/71 28/55 +f 28/55 35/71 30/60 +f 30/60 35/71 32/65 +f 32/65 35/71 34/69 +f 34/69 35/71 22/43 +f 23/45 36/72 20/39 +f 36/72 19/37 20/39 +f 29/57 31/63 36/72 +f 27/53 29/57 36/72 +f 23/45 25/49 36/72 +f 25/49 27/53 36/72 +f 31/63 33/67 36/72 +f 33/67 19/37 36/72 +f 452/689 451/687 339/526 338/525 +f 451/687 39/76 461/701 339/526 +f 445/680 37/74 87/137 89/139 +f 40/77 445/680 89/139 460/700 +f 39/76 109/161 40/77 +f 40/77 109/161 37/73 445/679 +f 110/163 111/165 114/169 113/168 +f 113/168 114/169 122/181 115/170 +f 115/170 122/181 295/451 127/188 +f 111/164 295/450 122/181 114/169 +f 127/187 110/162 113/168 115/170 +f 327/507 303/466 305/471 328/509 +f 328/509 305/471 309/476 329/511 +f 75/122 77/124 79/126 81/130 +f 80/128 78/125 76/123 74/120 +f 82/131 175/268 176/270 83/132 +f 83/132 176/270 177/272 84/133 +f 84/133 177/272 178/274 170/261 +f 170/261 178/274 179/276 171/262 +f 171/262 179/276 180/279 172/264 +f 172/263 180/278 181/281 173/265 +f 173/265 181/281 182/283 174/266 +f 174/266 182/283 175/268 82/131 +f 175/267 183/284 176/269 +f 176/269 183/284 177/271 +f 177/271 183/284 178/273 +f 178/273 183/284 179/275 +f 179/275 183/284 180/277 +f 180/277 183/284 181/280 +f 94/146 93/145 95/147 96/148 +f 106/158 94/146 96/148 105/157 +f 99/151 94/146 106/158 107/159 +f 99/151 101/153 94/146 +f 85/134 86/136 95/147 93/145 +f 86/135 119/176 96/148 95/147 +f 119/175 104/156 105/157 96/148 +f 121/180 88/138 97/149 98/150 +f 88/138 90/140 100/152 97/149 +f 91/142 92/144 102/154 101/153 +f 92/143 85/134 93/145 102/154 +f 99/151 107/159 108/160 103/155 +f 101/153 99/151 103/155 91/141 +f 104/156 121/179 98/150 105/157 +f 97/149 106/158 105/157 98/150 +f 107/159 106/158 97/149 100/152 +f 117/172 116/171 118/173 119/174 +f 120/177 117/172 119/174 121/178 +f 380/581 117/172 120/177 123/182 +f 380/581 124/183 116/171 117/172 +f 311/481 136/207 118/173 116/171 +f 136/206 131/196 119/174 118/173 +f 131/196 130/194 121/178 119/174 +f 130/194 112/167 120/177 121/178 +f 112/167 319/494 123/182 120/177 +f 313/484 311/481 116/171 124/183 +f 436/669 125/185 126/186 314/485 +f 314/485 126/186 311/480 313/483 +f 319/493 112/166 128/189 318/492 +f 438/672 132/197 312/482 437/671 +f 136/205 134/201 133/199 131/195 +f 125/184 312/482 134/200 135/204 +f 128/189 112/166 130/193 129/191 +f 126/186 125/185 135/203 137/208 +f 318/492 128/189 132/197 438/672 +f 133/198 132/197 128/189 129/191 +f 131/195 133/199 129/190 130/192 +f 135/202 134/201 136/205 137/208 +f 143/220 145/222 146/223 149/226 +f 138/209 143/219 149/227 148/225 +f 141/213 142/217 144/221 140/212 +f 147/224 146/223 145/222 139/211 +f 139/211 145/222 143/218 138/210 +f 140/212 144/221 146/223 147/224 +f 149/227 142/216 141/214 148/225 +f 146/223 144/221 142/215 149/226 +f 150/230 151/233 153/235 152/234 +f 152/234 153/235 155/237 154/236 +f 158/242 159/243 160/246 161/249 +f 156/239 157/240 151/232 150/229 +f 151/231 157/241 155/237 153/235 +f 156/238 150/228 152/234 154/236 +f 154/236 155/237 159/243 158/242 +f 155/237 157/241 160/245 159/243 +f 157/240 156/239 161/248 160/244 +f 156/238 154/236 158/242 161/247 +f 164/253 162/250 168/258 167/256 +f 163/252 162/250 164/253 165/254 +f 166/255 167/256 168/257 169/260 +f 181/280 183/284 182/282 +f 182/282 183/284 175/267 +f 184/285 192/295 193/297 185/286 +f 185/286 193/297 194/299 186/287 +f 186/287 194/299 195/301 187/288 +f 187/288 195/301 196/303 188/289 +f 188/289 196/303 197/306 189/291 +f 189/290 197/305 198/308 190/292 +f 190/292 198/308 199/310 191/293 +f 191/293 199/310 192/295 184/285 +f 192/294 200/311 193/296 +f 193/296 200/311 194/298 +f 194/298 200/311 195/300 +f 195/300 200/311 196/302 +f 196/302 200/311 197/304 +f 197/304 200/311 198/307 +f 198/307 200/311 199/309 +f 199/309 200/311 192/294 +f 76/123 78/125 79/126 77/124 +f 227/343 202/316 201/313 297/455 +f 299/457 229/345 227/343 297/455 +f 301/460 231/349 229/345 299/457 +f 201/312 202/315 231/348 301/459 +f 202/314 227/343 229/345 231/347 +f 232/351 234/355 457/696 456/695 +f 307/473 430/661 459/699 458/697 +f 430/660 232/350 456/694 459/698 +f 233/354 235/356 429/659 431/664 +f 394/602 395/605 384/586 367/560 +f 437/671 436/670 383/585 433/666 +f 392/598 391/596 390/594 433/666 +f 321/497 423/651 421/649 320/496 +f 211/330 212/333 214/335 213/334 +f 213/334 214/335 216/337 215/336 +f 215/336 216/337 218/342 217/339 +f 217/338 218/341 212/332 211/329 +f 212/331 218/340 216/337 214/335 +f 322/498 422/650 423/651 321/497 +f 323/499 425/653 422/650 322/498 +f 324/500 424/652 425/653 323/499 +f 319/495 427/657 424/652 324/500 +f 449/684 405/621 398/609 448/683 +f 450/685 397/608 405/621 449/684 +f 453/691 396/606 397/608 450/685 +f 330/512 406/622 396/607 453/690 +f 331/514 399/610 406/622 330/512 +f 448/683 398/609 399/611 331/513 +f 456/695 457/696 235/356 233/353 +f 458/697 429/659 235/356 457/696 +f 459/699 431/663 429/659 458/697 +f 78/125 80/127 81/129 79/126 +f 456/694 233/352 431/662 459/698 +f 39/76 40/77 460/700 461/701 +f 236/357 237/359 245/370 244/367 +f 237/358 238/360 246/372 245/369 +f 238/360 239/361 247/374 246/372 +f 239/361 240/362 248/376 247/374 +f 240/362 241/363 249/378 248/376 +f 241/363 242/364 250/380 249/378 +f 242/364 243/365 251/382 250/380 +f 243/365 236/357 244/367 251/382 +f 244/366 245/368 252/383 +f 245/368 246/371 252/383 +f 246/371 247/373 252/383 +f 247/373 248/375 252/383 +f 248/375 249/377 252/383 +f 249/377 250/379 252/383 +f 250/379 251/381 252/383 +f 251/381 244/366 252/383 +f 253/385 254/387 256/389 255/388 +f 255/388 256/389 258/391 257/390 +f 257/390 258/391 260/395 259/393 +f 254/386 260/394 258/391 256/389 +f 259/392 253/384 255/388 257/390 +f 261/396 262/397 270/408 269/406 +f 262/397 263/398 271/410 270/408 +f 263/398 264/399 272/412 271/410 +f 264/399 265/400 273/414 272/412 +f 265/400 266/402 274/417 273/414 +f 266/401 267/403 275/419 274/416 +f 267/403 268/404 276/421 275/419 +f 268/404 261/396 269/406 276/421 +f 269/405 270/407 277/422 +f 270/407 271/409 277/422 +f 271/409 272/411 277/422 +f 272/411 273/413 277/422 +f 273/413 274/415 277/422 +f 274/415 275/418 277/422 +f 275/418 276/420 277/422 +f 276/420 269/405 277/422 +f 278/423 279/424 287/435 286/433 +f 279/424 280/425 288/437 287/435 +f 280/425 281/426 289/439 288/437 +f 281/426 282/427 290/441 289/439 +f 282/427 283/429 291/444 290/441 +f 283/428 284/430 292/446 291/443 +f 284/430 285/431 293/448 292/446 +f 285/431 278/423 286/433 293/448 +f 286/432 287/434 294/449 +f 287/434 288/436 294/449 +f 288/436 289/438 294/449 +f 289/438 290/440 294/449 +f 290/440 291/442 294/449 +f 291/442 292/445 294/449 +f 292/445 293/447 294/449 +f 293/447 286/432 294/449 +f 298/456 297/455 201/313 296/454 +f 299/457 297/455 298/456 300/458 +f 301/460 299/457 300/458 302/463 +f 201/312 301/459 302/462 296/453 +f 296/452 302/461 300/458 298/456 +f 232/351 332/516 333/517 234/355 +f 307/473 334/518 335/520 430/661 +f 430/660 335/519 332/515 232/350 +f 304/469 310/479 308/474 306/472 +f 136/205 311/480 126/186 137/208 +f 437/671 312/482 125/184 436/670 +f 134/200 312/482 132/197 133/198 +f 321/497 320/496 163/251 165/254 +f 322/498 321/497 165/254 164/253 +f 323/499 322/498 164/253 167/256 +f 324/500 323/499 167/256 166/255 +f 319/495 324/500 166/255 169/259 +f 449/684 448/683 140/212 147/224 +f 450/685 449/684 147/224 139/211 +f 453/691 450/685 139/211 138/210 +f 330/512 453/690 138/209 148/225 +f 331/514 330/512 148/225 141/214 +f 448/683 331/513 141/213 140/212 +f 332/516 304/468 306/472 333/517 +f 334/518 333/517 306/472 308/474 +f 335/520 334/518 308/474 310/478 +f 332/515 335/519 310/477 304/467 +f 209/327 461/701 460/700 210/328 +f 206/323 338/525 339/526 205/321 +f 205/321 339/526 461/701 209/327 +f 204/319 89/139 87/137 207/325 +f 210/328 460/700 89/139 204/319 +f 209/327 210/328 342/531 +f 210/328 204/318 207/324 342/531 +f 352/545 354/547 353/546 351/544 +f 364/557 363/556 354/547 352/545 +f 357/550 365/558 364/557 352/545 +f 359/552 352/545 351/544 360/553 +f 343/532 351/544 353/546 344/534 +f 344/533 353/546 354/547 377/576 +f 377/575 354/547 363/556 362/555 +f 379/580 356/549 355/548 346/537 +f 346/537 355/548 358/551 348/539 +f 349/541 359/552 360/553 350/543 +f 350/542 360/553 351/544 343/532 +f 357/550 361/554 366/559 365/558 +f 359/552 349/540 361/554 357/550 +f 362/555 363/556 356/549 379/579 +f 355/548 356/549 363/556 364/557 +f 365/558 358/551 355/548 364/557 +f 375/572 377/574 376/573 374/571 +f 378/577 379/578 377/574 375/572 +f 380/581 123/182 378/577 375/572 +f 380/581 375/572 374/571 124/183 +f 367/561 374/571 376/573 394/604 +f 394/603 376/573 377/574 389/593 +f 389/593 377/574 379/578 371/568 +f 371/568 379/578 378/577 370/565 +f 370/565 378/577 123/182 319/494 +f 313/484 124/183 374/571 367/561 +f 436/669 314/485 384/586 383/584 +f 314/485 313/483 367/560 384/586 +f 319/493 318/492 386/588 370/564 +f 438/672 437/671 433/666 390/594 +f 394/602 389/592 391/595 392/597 +f 383/585 393/601 392/598 433/666 +f 386/588 387/590 371/567 370/564 +f 384/586 395/605 393/600 383/584 +f 318/492 438/672 390/594 386/588 +f 391/596 387/590 386/588 390/594 +f 389/592 371/566 387/589 391/595 +f 393/599 395/605 394/602 392/597 +f 401/617 407/623 404/620 403/619 +f 396/607 406/622 407/624 401/616 +f 399/611 398/609 402/618 400/614 +f 405/621 397/608 403/619 404/620 +f 397/608 396/606 401/615 403/619 +f 398/609 405/621 404/620 402/618 +f 407/624 406/622 399/610 400/613 +f 404/620 407/623 400/612 402/618 +f 408/627 410/631 411/632 409/630 +f 410/631 412/633 413/634 411/632 +f 416/639 419/646 418/643 417/640 +f 414/636 408/626 409/629 415/637 +f 409/628 411/632 413/634 415/638 +f 414/635 412/633 410/631 408/625 +f 412/633 416/639 417/640 413/634 +f 413/634 417/640 418/642 415/638 +f 415/637 418/641 419/645 414/636 +f 414/635 419/644 416/639 412/633 +f 422/650 425/653 426/655 420/647 +f 421/648 423/651 422/650 420/647 +f 424/652 427/656 426/654 425/653 +f 329/511 309/476 315/487 336/522 +f 336/522 315/487 316/489 337/524 +f 337/524 316/489 317/491 340/528 +f 340/528 317/491 325/502 341/530 +f 341/530 325/502 326/504 345/536 +f 345/536 326/504 303/465 327/506 +f 347/538 368/562 369/563 +f 369/563 368/562 372/569 +f 372/569 368/562 373/570 +f 373/570 368/562 381/582 +f 381/582 368/562 382/583 +f 382/583 368/562 385/587 +f 385/587 368/562 388/591 +f 347/538 388/591 368/562 +f 441/675 440/674 442/676 +f 441/675 442/676 443/677 +f 441/675 443/677 444/678 +f 441/675 444/678 446/681 +f 441/675 446/681 447/682 +f 441/675 447/682 454/692 +f 441/675 454/692 455/693 +f 441/675 455/693 440/674 +f 347/538 303/464 326/503 388/591 +f 347/538 369/563 305/470 303/464 +f 369/563 372/569 309/475 305/470 +f 372/569 373/570 315/486 309/475 +f 373/570 381/582 316/488 315/486 +f 381/582 382/583 317/490 316/488 +f 382/583 385/587 325/501 317/490 +f 385/587 388/591 326/503 325/501 +f 203/317 327/505 328/508 228/344 +f 228/344 328/508 329/510 230/346 +f 41/79 43/83 44/84 42/82 +f 43/83 45/85 46/86 44/84 +f 45/85 47/88 48/91 46/86 +f 47/87 41/78 42/81 48/90 +f 42/80 44/84 46/86 48/89 +f 230/346 329/510 336/521 428/658 +f 428/658 336/521 337/523 432/665 +f 432/665 337/523 340/527 434/667 +f 434/667 340/527 341/529 435/668 +f 435/668 341/529 345/535 439/673 +f 439/673 345/535 327/505 203/317 +f 440/674 203/317 228/344 442/676 +f 442/676 228/344 230/346 443/677 +f 443/677 230/346 428/658 444/678 +f 444/678 428/658 432/665 446/681 +f 446/681 432/665 434/667 447/682 +f 447/682 434/667 435/668 454/692 +f 454/692 435/668 439/673 455/693 +f 440/674 455/693 439/673 203/317 +f 94/146 101/153 102/154 93/145 +f 357/550 352/545 359/552 +f 57/92 65/102 66/105 58/94 +f 58/93 66/104 67/107 59/95 +f 59/95 67/107 68/109 60/96 +f 60/96 68/109 69/111 61/97 +f 61/97 69/111 70/113 62/98 +f 62/98 70/113 71/115 63/99 +f 63/99 71/115 72/117 64/100 +f 64/100 72/117 65/102 57/92 +f 65/101 73/118 66/103 +f 66/103 73/118 67/106 +f 67/106 73/118 68/108 +f 68/108 73/118 69/110 +f 69/110 73/118 70/112 +f 70/112 73/118 71/114 +f 71/114 73/118 72/116 +f 72/116 73/118 65/101 +f 74/119 76/123 77/124 75/121 + diff --git a/samples/js-tests/res/Sprite3DTest/boss.png b/samples/js-tests/res/Sprite3DTest/boss.png new file mode 100644 index 0000000000..7073a9678c Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/boss.png differ diff --git a/samples/js-tests/res/Sprite3DTest/boss1.obj b/samples/js-tests/res/Sprite3DTest/boss1.obj new file mode 100644 index 0000000000..caa608af4b --- /dev/null +++ b/samples/js-tests/res/Sprite3DTest/boss1.obj @@ -0,0 +1,1614 @@ +# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware +# File Created: 15.05.2014 08:13:14 + +mtllib boo1.mtl + +# +# object Object +# + +v 0.5491 -0.2313 7.4010 +v 0.5491 -0.3996 7.0495 +v 0.5491 -0.3669 7.0495 +v 0.5491 -0.0174 7.0495 +v 0.5491 0.0042 7.2281 +v -0.5491 -0.3669 7.0495 +v -0.5491 -0.3996 7.0495 +v -0.5491 -0.2313 7.4010 +v -0.5491 -0.0174 7.0495 +v -0.5491 0.0042 7.2281 +v 2.0189 1.1850 -2.6543 +v 2.0189 1.1850 -0.0764 +v 2.1527 1.1295 -0.0764 +v 2.1527 1.1295 -2.6543 +v 1.8851 1.1295 -2.6543 +v 1.8851 1.1295 -0.0764 +v 1.8296 0.9957 -2.6543 +v 1.8296 0.9957 -0.0764 +v 1.8851 0.8619 -2.6543 +v 1.8851 0.8619 -0.0764 +v 2.0189 0.8064 -2.6543 +v 2.0189 0.8064 -0.0764 +v 2.1527 0.8619 -2.6543 +v 2.1527 0.8619 -0.0764 +v 2.2082 0.9957 -2.6543 +v 2.2082 0.9957 -0.0764 +v 2.0189 0.9957 0.0760 +v 2.0189 0.9959 -2.7785 +v -2.1527 1.1295 -0.0764 +v -2.0189 1.1850 -0.0764 +v -2.0189 1.1850 -2.6543 +v -2.1527 1.1295 -2.6543 +v -1.8851 1.1295 -0.0764 +v -1.8851 1.1295 -2.6543 +v -1.8296 0.9957 -0.0764 +v -1.8296 0.9957 -2.6543 +v -1.8851 0.8619 -0.0764 +v -1.8851 0.8619 -2.6543 +v -2.0189 0.8064 -0.0764 +v -2.0189 0.8064 -2.6543 +v -2.1527 0.8619 -0.0764 +v -2.1527 0.8619 -2.6543 +v -2.2082 0.9957 -0.0764 +v -2.2082 0.9957 -2.6543 +v -2.0189 0.9957 0.0760 +v -2.0189 0.9959 -2.7785 +v 0.0000 0.0042 7.2281 +v 0.0000 -0.0174 7.0495 +v 0.0000 -0.2313 7.4010 +v -0.5491 -0.8803 7.0495 +v 0.0000 -0.8803 7.0495 +v 0.0000 -0.8660 7.2281 +v -0.5491 -0.8660 7.2281 +v 0.0000 -0.5900 7.4284 +v -0.5491 -0.5900 7.4284 +v 0.8460 1.7558 -3.7140 +v 1.2699 2.8555 -3.5520 +v 1.1699 2.8947 -3.5020 +v 0.6201 1.8444 -3.6010 +v 1.2321 2.8937 -3.6576 +v 1.1320 2.9329 -3.6076 +v 0.7606 1.8420 -3.9526 +v 0.5346 1.9306 -3.8396 +v 1.2146 2.0382 -4.8054 +v 0.4218 2.4154 -4.7624 +v 0.4738 2.5225 -4.7423 +v 1.2666 2.1453 -4.7853 +v -0.1562 2.5757 -4.1199 +v -0.1042 2.6828 -4.0998 +v -2.2991 1.9669 -5.1457 +v -2.2991 1.9669 -5.7781 +v -2.2991 1.3344 -5.7781 +v -2.2991 1.3344 -5.1457 +v -1.6667 1.9669 -5.7781 +v -1.6667 1.9669 -5.1457 +v -1.6667 1.3344 -5.1457 +v -1.6667 1.3344 -5.7781 +v -2.0362 1.6380 -4.1779 +v -1.9639 1.6680 -4.1779 +v -1.9639 1.6680 -5.2168 +v -2.0362 1.6380 -5.2168 +v -1.8916 1.6380 -4.1779 +v -1.8916 1.6380 -5.2168 +v -1.8616 1.5657 -4.1779 +v -1.8616 1.5657 -5.2167 +v -1.8916 1.4934 -4.1779 +v -1.8916 1.4934 -5.2168 +v -1.9639 1.4634 -4.1779 +v -1.9639 1.4634 -5.2168 +v -2.0362 1.4934 -4.1779 +v -2.0362 1.4934 -5.2168 +v -2.0661 1.5657 -4.1779 +v -2.0661 1.5657 -5.2167 +v -1.9639 1.5657 -4.1779 +v 1.8132 0.8821 0.7520 +v 1.7356 0.7716 2.3721 +v 2.2768 0.7199 2.3598 +v 3.0073 0.6756 0.7519 +v 3.0077 0.6756 -0.7386 +v 1.8134 0.8820 -0.7386 +v 0.5255 0.8822 -0.7386 +v 0.5255 0.8822 0.7520 +v 0.5255 0.8270 1.8401 +v 1.7356 0.6499 2.3721 +v 2.2768 0.5982 2.3598 +v 3.0073 0.5540 0.7519 +v 3.0077 0.5540 -0.7386 +v 1.8136 0.7603 -4.0762 +v 1.8136 0.8820 -4.0762 +v 3.0082 0.6756 -4.0762 +v 3.0082 0.5540 -4.0762 +v 0.5255 0.7598 -4.0762 +v 0.5255 0.8823 -4.0762 +v 0.5250 0.7046 1.8372 +v 1.0438 0.6500 2.3721 +v 1.0438 0.7717 2.3721 +v 0.5252 0.7594 -0.7400 +v 0.5250 0.7590 0.7492 +v 1.3150 0.7605 0.7520 +v 1.0365 0.4285 5.7513 +v 1.8365 0.3768 5.8643 +v 1.3154 0.7603 -4.0762 +v 0.0000 0.7606 -4.0762 +v 0.0000 0.7606 0.7520 +v 0.0000 0.4288 5.7514 +v 1.8276 0.2889 5.8586 +v 1.0321 0.3404 5.7455 +v 2.9975 0.4660 0.7491 +v 2.9975 0.4660 -4.0762 +v 1.3100 0.6721 -4.0762 +v 0.0000 0.6721 -4.0762 +v 0.0000 0.3404 5.7455 +v 0.9817 -0.8791 7.0621 +v 0.9817 0.0087 7.0621 +v 0.0000 0.0087 7.0621 +v 0.0000 -0.8791 7.0621 +v 1.3100 -1.3100 -4.0762 +v 0.0000 -1.3100 -4.0762 +v 0.0000 -1.3100 0.7491 +v 1.3100 -1.3100 0.7491 +v 0.9641 -1.0946 6.5511 +v 0.0000 -1.0946 6.5511 +v 1.8274 -0.7162 6.5010 +v 2.9975 -0.9908 0.7491 +v 1.2588 -0.7709 7.0621 +v 2.9975 -0.9908 -4.0762 +v 1.2542 -0.0198 7.0621 +v 2.1329 0.6649 -8.4335 +v 2.9975 0.9908 -6.8074 +v 2.9975 -0.9908 -6.8074 +v 2.1329 -0.6649 -8.4335 +v 1.3100 -1.3100 -6.8074 +v 0.9817 -0.8791 -8.4335 +v 2.9975 -0.9908 -4.6052 +v 2.9975 0.9908 -4.6052 +v 1.3100 1.3100 -4.6052 +v 1.3100 -1.3100 -4.6052 +v 1.3100 1.3100 -6.8074 +v 0.9817 0.8791 -8.4335 +v 3.9351 -0.4210 -4.6474 +v 3.9351 0.4210 -4.6474 +v 3.0905 0.4210 -4.6474 +v 3.0905 -0.4210 -4.6474 +v 3.9351 0.4210 -7.4454 +v 3.0905 0.4210 -7.4454 +v 3.6205 0.4210 -8.5728 +v 3.6205 -0.4210 -8.5728 +v 3.0905 -0.4210 -8.5728 +v 3.0905 0.4210 -8.5728 +v 3.9351 -0.4210 -7.4454 +v 3.0905 -0.4210 -7.4454 +v 1.3100 0.6703 -2.1110 +v 1.3100 0.6703 -3.4212 +v 1.3100 1.5173 -3.4212 +v 1.3100 1.5173 -2.1110 +v 0.6551 1.1067 -0.7507 +v 0.6551 0.6703 -0.7507 +v 0.6551 0.6703 -4.0693 +v 0.6551 1.5173 -4.0693 +v -2.0362 1.8778 -4.1779 +v -1.9639 1.9077 -4.1779 +v -1.9639 1.9077 -5.2168 +v -2.0362 1.8778 -5.2168 +v -1.8916 1.8778 -4.1779 +v -1.8916 1.8778 -5.2168 +v -1.8616 1.8055 -4.1779 +v -1.8616 1.8055 -5.2167 +v -1.8916 1.7332 -4.1779 +v -1.8916 1.7332 -5.2168 +v -1.9639 1.7032 -4.1779 +v -1.9639 1.7032 -5.2168 +v -2.0362 1.7332 -4.1779 +v -2.0362 1.7332 -5.2168 +v -2.0661 1.8055 -4.1779 +v -2.0661 1.8055 -5.2167 +v -1.9639 1.8055 -4.1779 +v -7.6091 -1.0690 0.5512 +v 0.0000 -1.4598 -3.9561 +v 0.0000 -0.7653 -3.9561 +v -7.6091 -0.7653 0.5512 +v -7.6091 -0.7653 -0.6495 +v 0.0000 -0.7653 -7.7329 +v -7.6091 -1.0690 -0.6495 +v 0.0000 -1.4598 -7.7329 +v 0.0000 -0.7653 6.0720 +v -1.5430 -0.7653 4.4940 +v -1.5430 -1.3426 4.4940 +v 0.0000 -1.4598 6.0720 +v 0.0000 -0.7653 0.4394 +v 0.0000 -1.4598 0.4394 +v -1.5430 -1.3426 0.1910 +v -1.5430 -0.7653 0.1910 +v -5.1435 -0.7653 0.8122 +v -5.1435 -0.7653 -0.3885 +v -5.1435 -1.0690 -0.3885 +v -5.1435 -1.0690 0.8122 +v -1.2542 -0.0198 7.0621 +v -0.9817 0.0087 7.0621 +v -1.0321 0.3404 5.7455 +v -1.8276 0.2889 5.8586 +v -0.9817 -0.8791 7.0621 +v -0.9641 -1.0946 6.5511 +v -1.8274 -0.7162 6.5010 +v -2.9975 -0.9908 0.7491 +v -1.3100 -1.3100 0.7491 +v -0.6551 1.1067 -0.7507 +v -0.6551 0.6703 -0.7507 +v 0.0000 0.6703 -0.7507 +v 0.0000 1.1067 -0.7507 +v 4.2086 -0.7408 -0.8965 +v 4.2086 0.1580 -0.8965 +v 2.2211 0.1580 -0.2044 +v 2.2211 -0.7408 -0.2044 +v 4.2086 0.1580 -3.5166 +v 2.2211 0.1580 -3.9812 +v 4.2086 -0.7408 -3.5166 +v 2.2211 -0.7408 -3.9812 +v 0.0000 1.5173 -2.1110 +v -1.3100 1.5173 -2.1110 +v -1.3100 1.5173 -3.4212 +v 0.0000 1.5173 -3.4212 +v -0.6551 1.5173 -4.0693 +v 0.0000 1.5173 -4.0693 +v -0.6551 0.6703 -4.0693 +v -1.3100 1.3100 -6.8074 +v -1.3100 1.3100 -4.6052 +v 0.0000 1.3100 -4.6052 +v 0.0000 1.3100 -6.8074 +v -0.9817 0.8791 -8.4335 +v 0.0000 0.8791 -8.4335 +v -0.9817 -0.8791 -8.4335 +v 0.0000 -0.8791 -8.4335 +v 0.0000 -1.3100 -6.8074 +v -1.3100 -1.3100 -6.8074 +v -1.3100 -1.3100 -4.6052 +v 0.0000 -1.3100 -4.6052 +v 1.9657 0.7591 -6.3725 +v 1.9657 1.4084 -6.3725 +v 2.5383 1.4084 -6.1354 +v 2.5383 0.7591 -6.1354 +v 1.3932 0.7591 -6.1354 +v 1.3932 1.4084 -6.1354 +v 1.1560 0.7591 -5.5628 +v 1.1560 1.4084 -5.5628 +v 1.3932 0.7591 -4.9903 +v 1.3932 1.4084 -4.9903 +v 1.9657 0.7591 -4.7531 +v 1.9657 1.4084 -4.7531 +v 2.5383 0.7591 -4.9903 +v 2.5383 1.4084 -4.9903 +v 2.7755 0.7591 -5.5628 +v 2.7755 1.4084 -5.5628 +v 1.9657 1.4084 -5.5628 +v 2.2991 1.3344 -5.1457 +v 2.2991 1.9669 -5.1457 +v 1.6667 1.9669 -5.1457 +v 1.6667 1.3344 -5.1457 +v 2.2991 1.9669 -5.7781 +v 1.6667 1.9669 -5.7781 +v 2.2991 1.3344 -5.7781 +v 1.6667 1.3344 -5.7781 +v 1.9639 1.6680 -5.2168 +v 1.9639 1.6680 -4.1779 +v 2.0362 1.6380 -4.1779 +v 2.0362 1.6380 -5.2168 +v 1.8916 1.6380 -5.2168 +v 1.8916 1.6380 -4.1779 +v 1.8616 1.5657 -5.2167 +v 1.8616 1.5657 -4.1779 +v 1.8916 1.4934 -5.2168 +v 1.8916 1.4934 -4.1779 +v 1.9639 1.4634 -5.2168 +v 1.9639 1.4634 -4.1779 +v 2.0362 1.4934 -5.2168 +v 2.0362 1.4934 -4.1779 +v 2.0661 1.5657 -5.2167 +v 2.0661 1.5657 -4.1779 +v 1.9639 1.5657 -4.1779 +v 1.9639 1.9077 -5.2168 +v 1.9639 1.9077 -4.1779 +v 2.0362 1.8778 -4.1779 +v 2.0362 1.8778 -5.2168 +v 1.8916 1.8778 -5.2168 +v 1.8916 1.8778 -4.1779 +v 1.8616 1.8055 -5.2167 +v 1.8616 1.8055 -4.1779 +v 1.8916 1.7332 -5.2168 +v 1.8916 1.7332 -4.1779 +v 1.9639 1.7032 -5.2168 +v 1.9639 1.7032 -4.1779 +v 2.0362 1.7332 -5.2168 +v 2.0362 1.7332 -4.1779 +v 2.0661 1.8055 -5.2167 +v 2.0661 1.8055 -4.1779 +v 1.9639 1.8055 -4.1779 +v 7.6091 -1.0690 0.5512 +v 7.6091 -0.7653 0.5512 +v 7.6091 -0.7653 -0.6495 +v 7.6091 -1.0690 -0.6495 +v 1.5430 -1.3426 4.4940 +v 1.5430 -0.7653 4.4940 +v 1.5430 -0.7653 0.1910 +v 1.5430 -1.3426 0.1910 +v 5.1435 -1.0690 -0.3885 +v 5.1435 -0.7653 -0.3885 +v 5.1435 -0.7653 0.8122 +v 5.1435 -1.0690 0.8122 +v 0.5491 -0.5900 7.4284 +v 0.5491 -0.8803 7.0495 +v 0.5491 -0.8660 7.2281 +v -1.8132 0.8821 0.7520 +v -3.0073 0.6756 0.7519 +v -2.2768 0.7199 2.3598 +v -1.7356 0.7716 2.3721 +v -3.0077 0.6756 -0.7386 +v -1.8134 0.8820 -0.7386 +v -0.5255 0.8822 -0.7386 +v -0.5255 0.8822 0.7520 +v -0.5255 0.8270 1.8401 +v -1.0438 0.7717 2.3721 +v -1.7356 0.6499 2.3721 +v -2.2768 0.5982 2.3598 +v -3.0073 0.5540 0.7519 +v -3.0077 0.5540 -0.7386 +v -3.0082 0.6756 -4.0762 +v -1.8136 0.8820 -4.0762 +v -1.8136 0.7603 -4.0762 +v -3.0082 0.5540 -4.0762 +v -0.5255 0.8823 -4.0762 +v -0.5255 0.7598 -4.0762 +v -0.5250 0.7046 1.8372 +v -1.0438 0.6500 2.3721 +v -0.5250 0.7590 0.7492 +v -0.5252 0.7594 -0.7400 +v -1.3150 0.7605 0.7520 +v -1.8365 0.3768 5.8643 +v -1.0365 0.4285 5.7513 +v -1.3154 0.7603 -4.0762 +v -2.9975 0.4660 0.7491 +v -2.9975 0.4660 -4.0762 +v -1.3100 0.6721 -4.0762 +v -1.3100 -1.3100 -4.0762 +v -1.2588 -0.7709 7.0621 +v -2.9975 -0.9908 -4.0762 +v -2.9975 -0.9908 -6.8074 +v -2.9975 0.9908 -6.8074 +v -2.1329 0.6649 -8.4335 +v -2.1329 -0.6649 -8.4335 +v -2.9975 0.9908 -4.6052 +v -2.9975 -0.9908 -4.6052 +v -3.0905 0.4210 -4.6474 +v -3.9351 0.4210 -4.6474 +v -3.9351 -0.4210 -4.6474 +v -3.0905 -0.4210 -4.6474 +v -3.0905 0.4210 -7.4454 +v -3.9351 0.4210 -7.4454 +v -3.0905 -0.4210 -8.5728 +v -3.6205 -0.4210 -8.5728 +v -3.6205 0.4210 -8.5728 +v -3.0905 0.4210 -8.5728 +v -3.9351 -0.4210 -7.4454 +v -3.0905 -0.4210 -7.4454 +v -1.3100 0.6703 -3.4212 +v -1.3100 0.6703 -2.1110 +v -0.1808 2.4254 -3.2542 +v -0.1287 2.5325 -3.2341 +v 0.3624 2.0524 -2.6724 +v 0.4145 2.1595 -2.6523 +v 1.1553 1.6753 -2.7154 +v 1.2073 1.7823 -2.6953 +v 1.7332 1.5149 -3.3580 +v 1.7853 1.6220 -3.3379 +v 1.7578 1.6652 -4.2237 +v 1.8099 1.7723 -4.2036 +v 0.9380 1.7479 -4.5237 +v 0.5838 1.6240 -3.8179 +v 0.3954 2.0060 -4.4943 +v -0.0002 2.1158 -4.0545 +v -0.0171 2.0129 -3.4620 +v 0.3547 1.7576 -3.0638 +v 0.8974 1.4994 -3.0932 +v 1.2930 1.3897 -3.5330 +v 1.3098 1.4926 -4.1255 +v 0.7030 1.8693 -3.7719 +v 0.9801 1.9662 -4.3241 +v 0.5556 2.1682 -4.3010 +v 0.2461 2.2540 -3.9570 +v 0.2329 2.1735 -3.4935 +v 0.5238 1.9738 -3.1820 +v 0.9483 1.7719 -3.2050 +v 1.2578 1.6860 -3.5490 +v 1.2710 1.7665 -4.0126 +v 0.5227 2.4731 -4.6059 +v 1.2098 2.1463 -4.6431 +v 0.0218 2.6121 -4.0490 +v -2.2211 0.1580 -0.2044 +v -4.2086 0.1580 -0.8965 +v -4.2086 -0.7408 -0.8965 +v -2.2211 -0.7408 -0.2044 +v -2.2211 0.1580 -3.9812 +v -4.2086 0.1580 -3.5166 +v -2.2211 -0.7408 -3.9812 +v -4.2086 -0.7408 -3.5166 +v 0.0005 2.4818 -3.2987 +v 0.4713 2.1585 -2.7945 +v 1.1584 1.8317 -2.8318 +v 1.6593 1.6927 -3.3887 +v 1.6806 1.8230 -4.1389 +v -2.5383 1.4084 -6.1354 +v -1.9657 1.4084 -6.3725 +v -1.9657 0.7591 -6.3725 +v -2.5383 0.7591 -6.1354 +v -1.3932 1.4084 -6.1354 +v -1.3932 0.7591 -6.1354 +v -1.1560 1.4084 -5.5628 +v -1.1560 0.7591 -5.5628 +v -1.3932 1.4084 -4.9903 +v -1.3932 0.7591 -4.9903 +v -1.9657 1.4084 -4.7531 +v -1.9657 0.7591 -4.7531 +v -2.5383 1.4084 -4.9903 +v -2.5383 0.7591 -4.9903 +v -2.7755 1.4084 -5.5628 +v -2.7755 0.7591 -5.5628 +v -1.9657 1.4084 -5.5628 +# 445 vertices + +vn 0.6502 0.2638 0.7125 +vn 1.0000 0.0000 -0.0000 +vn 0.7327 0.6756 -0.0817 +vn 0.6092 0.7277 0.3152 +vn -1.0000 0.0000 -0.0000 +vn -0.6502 0.2638 0.7125 +vn -0.7327 0.6756 -0.0817 +vn -0.6092 0.7277 0.3152 +vn -0.0000 0.9018 -0.4322 +vn -0.0000 0.9185 0.3953 +vn 0.6495 0.6495 0.3953 +vn 0.6377 0.6376 -0.4323 +vn -0.6377 0.6376 -0.4323 +vn -0.6495 0.6495 0.3953 +vn -0.9017 -0.0001 -0.4324 +vn -0.9185 -0.0000 0.3953 +vn -0.6375 -0.6376 -0.4326 +vn -0.6495 -0.6495 0.3953 +vn -0.0000 -0.9016 -0.4326 +vn -0.0000 -0.9185 0.3953 +vn 0.6375 -0.6376 -0.4326 +vn 0.6495 -0.6495 0.3953 +vn 0.9017 -0.0001 -0.4324 +vn 0.9185 -0.0000 0.3953 +vn -0.0000 -0.0000 1.0000 +vn -0.0000 0.0006 -1.0000 +vn 0.0000 0.9185 0.3953 +vn 0.0000 0.9018 -0.4322 +vn 0.0000 -0.9185 0.3953 +vn 0.0000 -0.9016 -0.4326 +vn 0.0000 -0.0000 1.0000 +vn 0.0000 0.0006 -1.0000 +vn 0.0000 0.9176 0.3974 +vn 0.0000 0.9928 -0.1201 +vn 0.0000 0.3472 0.9378 +vn -0.6884 -0.7230 0.0579 +vn 0.0000 -0.9968 0.0798 +vn 0.0000 -0.8720 0.4895 +vn -0.6240 -0.6814 0.3825 +vn 0.0000 -0.2723 0.9622 +vn -0.6371 -0.2099 0.7416 +vn 0.8576 -0.3814 0.3451 +vn 0.9146 0.1754 0.3642 +vn -0.0309 0.5461 0.8371 +vn -0.3313 0.0848 0.9397 +vn 0.5569 0.5364 -0.6342 +vn -0.3887 0.9071 -0.1613 +vn 0.4077 0.0725 -0.9102 +vn -0.7811 0.5387 -0.3157 +vn 0.1842 -0.3355 -0.9239 +vn -0.4566 -0.0306 -0.8891 +vn 0.0237 0.8092 -0.5871 +vn 0.5596 0.5542 -0.6162 +vn -0.9238 0.0990 -0.3697 +vn -0.3671 0.9176 -0.1527 +vn -0.5774 0.5774 0.5774 +vn -0.5774 0.5774 -0.5774 +vn -0.7071 0.0000 -0.7071 +vn -0.7071 0.0000 0.7071 +vn 0.5774 0.5774 -0.5774 +vn 0.5774 0.5774 0.5774 +vn 0.7071 0.0000 0.7071 +vn 0.7071 0.0000 -0.7071 +vn -0.5490 0.5490 0.6303 +vn 0.0000 0.7764 0.6303 +vn 0.0000 1.0000 -0.0000 +vn -0.7071 0.7071 -0.0000 +vn 0.5490 0.5490 0.6303 +vn 0.7071 0.7071 -0.0000 +vn 0.7764 0.0000 0.6303 +vn 0.5490 -0.5490 0.6303 +vn 0.7071 -0.7071 -0.0000 +vn 0.0000 -0.7764 0.6303 +vn 0.0000 -1.0000 -0.0000 +vn -0.5490 -0.5490 0.6303 +vn -0.7071 -0.7071 -0.0000 +vn -0.7764 0.0000 0.6303 +vn 0.0000 0.0000 1.0000 +vn 0.0848 0.9960 0.0288 +vn 0.0437 0.6873 0.7251 +vn 0.4732 0.5593 0.6806 +vn 0.7829 0.6009 0.1613 +vn 0.7650 0.6441 0.0002 +vn 0.0856 0.9963 -0.0000 +vn -0.4494 0.8934 -0.0001 +vn -0.7001 0.7138 0.0181 +vn -0.7097 0.6256 0.3239 +vn 0.0117 0.0000 0.9999 +vn 0.5713 0.0000 0.8207 +vn 0.9172 0.3679 0.1530 +vn 1.0000 0.0000 0.0002 +vn 0.0000 0.0000 -1.0000 +vn 0.0621 0.7227 -0.6884 +vn 0.6194 0.5215 -0.5868 +vn 0.7125 0.2937 -0.6373 +vn 0.0002 0.7071 -0.7071 +vn -0.9226 -0.0047 0.3857 +vn -0.3804 0.0000 0.9248 +vn -0.2993 0.5898 0.7501 +vn -1.0000 0.0020 -0.0002 +vn -1.0000 0.0038 0.0001 +vn 0.0600 0.9977 0.0322 +vn -0.0298 0.6843 0.7286 +vn 0.5055 0.5000 0.7032 +vn 0.0437 0.7189 -0.6937 +vn 0.0000 0.7072 -0.7071 +vn 0.0000 0.9995 0.0332 +vn 0.0000 0.6588 0.7523 +vn 0.7695 0.2745 0.5767 +vn -0.0367 0.5658 0.8237 +vn 0.9922 -0.0577 0.1104 +vn 0.6917 -0.0420 -0.7210 +vn 0.0000 0.0027 -1.0000 +vn 0.0000 0.5882 0.8087 +vn 0.1188 -0.5887 0.7996 +vn 0.0321 0.6256 0.7795 +vn 0.0000 0.6147 0.7888 +vn 0.0000 -0.5529 0.8332 +vn 0.0679 -0.7238 -0.6867 +vn 0.0000 -0.7071 -0.7071 +vn 0.0000 -0.9998 0.0186 +vn 0.1008 -0.9944 0.0303 +vn 0.1919 -0.9589 0.2090 +vn 0.0000 -0.9763 0.2164 +vn 0.8234 -0.4090 0.3934 +vn 0.7783 -0.6202 0.0974 +vn 0.4102 -0.4276 0.8055 +vn 0.6229 -0.5161 -0.5878 +vn 0.3724 0.5216 0.7676 +vn 0.4590 0.4578 -0.7614 +vn 0.7634 0.6050 -0.2262 +vn 0.7634 -0.6050 -0.2262 +vn 0.4590 -0.4578 -0.7614 +vn 0.0969 -0.9859 -0.1366 +vn 0.0512 -0.6235 -0.7801 +vn 0.6229 -0.5161 0.5878 +vn 0.6229 0.5161 0.5878 +vn 0.0679 0.7238 0.6867 +vn 0.0679 -0.7238 0.6867 +vn 0.0969 0.9859 -0.1366 +vn 0.0512 0.6235 -0.7801 +vn 0.5774 -0.5774 0.5774 +vn -0.5774 -0.5774 0.5774 +vn 0.7284 0.6778 -0.0997 +vn 0.4869 0.5930 -0.6413 +vn 0.4869 -0.5930 -0.6413 +vn -0.5774 -0.5774 -0.5774 +vn 0.7284 -0.6778 -0.0997 +vn 0.9749 0.0000 0.2225 +vn 0.9229 0.0000 -0.3851 +vn 0.7168 0.6298 -0.2991 +vn 0.6993 0.6775 0.2279 +vn 0.4259 0.4935 0.7583 +vn 0.5321 0.0000 0.8467 +vn 0.3834 0.0025 -0.9236 +vn 0.2951 0.6307 -0.7177 +vn -0.4196 -0.5423 0.7279 +vn -0.0000 -0.8481 0.5299 +vn -0.0000 0.8416 0.5402 +vn -0.4121 0.5543 0.7231 +vn -0.7140 0.6273 -0.3108 +vn 0.0000 0.5812 -0.8138 +vn -0.7312 -0.6081 -0.3090 +vn -0.0000 -0.5903 -0.8072 +vn -0.0000 0.0000 1.0000 +vn -0.6942 0.2393 0.6788 +vn -0.5446 -0.6867 0.4815 +vn -0.0000 -0.5890 0.8081 +vn -0.0000 -0.7596 -0.6504 +vn 0.0592 -0.7094 -0.7024 +vn 0.1392 0.4825 -0.8648 +vn -0.7182 0.6312 0.2928 +vn -0.5331 0.5694 -0.6258 +vn -0.5501 -0.5468 -0.6312 +vn -0.7435 -0.6026 0.2900 +vn -0.3724 0.5216 0.7676 +vn -0.0321 0.6256 0.7795 +vn 0.0367 0.5658 0.8237 +vn -0.7695 0.2745 0.5767 +vn -0.1188 -0.5887 0.7996 +vn -0.1919 -0.9589 0.2090 +vn -0.8234 -0.4090 0.3934 +vn -0.7783 -0.6202 0.0974 +vn -0.1008 -0.9944 0.0303 +vn -0.4259 0.4935 0.7583 +vn -0.5321 0.0000 0.8467 +vn 0.0000 0.5963 0.8028 +vn 0.6539 -0.5970 0.4647 +vn 0.6539 0.5970 0.4647 +vn 0.2585 0.6183 0.7422 +vn 0.2585 -0.6183 0.7422 +vn 0.6323 0.5904 -0.5016 +vn 0.1731 0.6493 -0.7405 +vn 0.6323 -0.5904 -0.5016 +vn 0.1731 -0.6493 -0.7405 +vn 0.0000 0.9893 0.1460 +vn -0.6993 0.6775 0.2279 +vn -0.7168 0.6298 -0.2991 +vn -0.2951 0.6307 -0.7177 +vn 0.0000 0.7083 -0.7059 +vn -0.3834 0.0025 -0.9236 +vn -0.0969 0.9859 -0.1366 +vn -0.0679 0.7238 0.6867 +vn 0.0000 0.7071 0.7071 +vn 0.0000 0.9916 -0.1292 +vn -0.0512 0.6235 -0.7801 +vn 0.0000 0.6098 -0.7925 +vn -0.0512 -0.6235 -0.7801 +vn 0.0000 -0.6098 -0.7925 +vn 0.0000 -0.9916 -0.1292 +vn -0.0969 -0.9859 -0.1366 +vn -0.0679 -0.7238 0.6867 +vn 0.0000 -0.7071 0.7071 +vn 0.0000 0.6303 -0.7764 +vn 0.5490 0.6303 -0.5490 +vn -0.5490 0.6303 -0.5490 +vn -0.7764 0.6303 -0.0000 +vn -0.5490 0.6303 0.5490 +vn -0.0000 0.6303 0.7764 +vn 0.5490 0.6303 0.5490 +vn 0.7764 0.6303 -0.0000 +vn -0.0000 1.0000 -0.0000 +vn -0.0000 0.7764 0.6303 +vn -0.0000 -1.0000 -0.0000 +vn -0.0000 -0.7764 0.6303 +vn 0.4196 -0.5423 0.7279 +vn 0.4121 0.5543 0.7231 +vn 0.7140 0.6273 -0.3108 +vn 0.7312 -0.6081 -0.3090 +vn 0.5446 -0.6867 0.4815 +vn 0.6942 0.2393 0.6788 +vn -0.1392 0.4825 -0.8648 +vn -0.0592 -0.7094 -0.7024 +vn 0.5501 -0.5468 -0.6312 +vn 0.5331 0.5694 -0.6258 +vn 0.7182 0.6312 0.2928 +vn 0.7435 -0.6026 0.2900 +vn 0.6371 -0.2099 0.7416 +vn 0.6884 -0.7230 0.0579 +vn 0.6240 -0.6814 0.3825 +vn -0.0848 0.9960 0.0288 +vn -0.7829 0.6009 0.1613 +vn -0.4732 0.5593 0.6806 +vn -0.0437 0.6873 0.7251 +vn -0.7650 0.6441 0.0002 +vn -0.0856 0.9963 -0.0000 +vn 0.4494 0.8934 -0.0001 +vn 0.7001 0.7138 0.0181 +vn 0.7097 0.6256 0.3239 +vn 0.2993 0.5898 0.7501 +vn -0.0117 0.0000 0.9999 +vn -0.5713 0.0000 0.8207 +vn -0.9172 0.3679 0.1530 +vn -1.0000 0.0000 0.0002 +vn -0.6194 0.5215 -0.5868 +vn -0.0621 0.7227 -0.6884 +vn -0.0000 0.0000 -1.0000 +vn -0.7125 0.2937 -0.6373 +vn -0.0002 0.7071 -0.7071 +vn 0.9226 -0.0047 0.3857 +vn 0.3804 0.0000 0.9248 +vn 1.0000 0.0038 0.0001 +vn 1.0000 0.0020 -0.0002 +vn -0.0600 0.9977 0.0322 +vn -0.5055 0.5000 0.7032 +vn 0.0298 0.6843 0.7286 +vn -0.0437 0.7189 -0.6937 +vn -0.9922 -0.0577 0.1104 +vn -0.6917 -0.0420 -0.7210 +vn -0.0679 -0.7238 -0.6867 +vn -0.4102 -0.4276 0.8055 +vn -0.6229 -0.5161 -0.5878 +vn -0.7634 -0.6050 -0.2262 +vn -0.7634 0.6050 -0.2262 +vn -0.4590 0.4578 -0.7614 +vn -0.4590 -0.4578 -0.7614 +vn -0.6229 0.5161 0.5878 +vn -0.6229 -0.5161 0.5878 +vn -0.7284 0.6778 -0.0997 +vn 0.5774 -0.5774 -0.5774 +vn -0.4869 -0.5930 -0.6413 +vn -0.4869 0.5930 -0.6413 +vn -0.7284 -0.6778 -0.0997 +vn -0.9229 0.0000 -0.3851 +vn -0.9749 0.0000 0.2225 +vn -0.9437 -0.0225 0.3300 +vn -0.3837 0.8159 0.4325 +vn -0.5046 -0.3240 0.8002 +vn -0.0164 0.5638 0.8258 +vn 0.1362 -0.6289 0.7655 +vn 0.5195 0.3088 0.7967 +vn 0.6034 -0.7585 0.2461 +vn 0.9102 0.2004 0.3623 +vn 0.6233 -0.6370 -0.4536 +vn 0.9269 0.3021 -0.2229 +vn -0.1903 -0.7733 -0.6049 +vn -0.4309 -0.8869 -0.1663 +vn -0.5326 -0.6104 -0.5863 +vn -0.7821 -0.5412 -0.3089 +vn -0.7927 -0.6061 0.0649 +vn -0.5582 -0.7672 0.3161 +vn -0.2159 -0.9300 0.2975 +vn 0.0337 -0.9992 0.0201 +vn 0.0443 -0.9343 -0.3537 +vn 0.4309 0.8869 0.1663 +vn 0.2651 0.8276 0.4949 +vn 0.5179 0.7073 0.4811 +vn 0.7023 0.6561 0.2762 +vn 0.7101 0.7041 0.0001 +vn 0.5369 0.8230 -0.1854 +vn 0.2840 0.9433 -0.1717 +vn 0.0997 0.9945 0.0332 +vn 0.0918 0.9465 0.3093 +vn 0.4828 0.8115 0.3292 +vn 0.3543 0.8726 0.3362 +vn 0.5765 0.7855 0.2251 +vn -0.2585 0.6183 0.7422 +vn -0.6539 0.5970 0.4647 +vn -0.6539 -0.5970 0.4647 +vn -0.2585 -0.6183 0.7422 +vn -0.1731 0.6493 -0.7405 +vn -0.6323 0.5904 -0.5016 +vn -0.1731 -0.6493 -0.7405 +vn -0.6323 -0.5904 -0.5016 +vn 0.5805 0.8098 0.0848 +vn 0.4924 0.8703 -0.0095 +vn 0.3640 0.9314 -0.0025 +vn 0.2703 0.9574 0.1016 +vn 0.2663 0.9330 0.2419 +vn -0.0000 0.6303 -0.7764 +vn 0.0000 0.6303 0.7764 +# 331 vertex normals + +vt 0.3471 0.0763 0.0000 +vt 0.4009 0.0969 0.0000 +vt 0.4005 0.0921 0.0000 +vt 0.3963 0.0406 0.0000 +vt 0.3698 0.0396 0.0000 +vt 0.4270 0.1552 0.0000 +vt 0.4282 0.2181 0.0000 +vt 0.4235 0.2182 0.0000 +vt 0.4222 0.1553 0.0000 +vt 0.4317 0.1551 0.0000 +vt 0.4329 0.2180 0.0000 +vt 0.4365 0.1550 0.0000 +vt 0.4377 0.2179 0.0000 +vt 0.4412 0.1548 0.0000 +vt 0.4424 0.2178 0.0000 +vt 0.4460 0.1547 0.0000 +vt 0.4475 0.2178 0.0000 +vt 0.4128 0.1555 0.0000 +vt 0.4140 0.2184 0.0000 +vt 0.4093 0.2185 0.0000 +vt 0.4080 0.1556 0.0000 +vt 0.4175 0.1554 0.0000 +vt 0.4187 0.2183 0.0000 +vt 0.4459 0.2658 0.0000 +vt 0.4270 0.2730 0.0000 +vt 0.4283 0.2466 0.0000 +vt 0.4086 0.2647 0.0000 +vt 0.4013 0.2458 0.0000 +vt 0.4096 0.2274 0.0000 +vt 0.4288 0.2208 0.0000 +vt 0.4464 0.2294 0.0000 +vt 0.4533 0.2473 0.0000 +vt 0.4272 0.2724 0.0000 +vt 0.4086 0.2649 0.0000 +vt 0.4285 0.2468 0.0000 +vt 0.4011 0.2459 0.0000 +vt 0.4464 0.2295 0.0000 +vt 0.4287 0.2211 0.0000 +vt 0.4531 0.2475 0.0000 +vt 0.4457 0.2656 0.0000 +vt 0.4097 0.2275 0.0000 +vt 0.3469 0.0332 0.0000 +vt 0.2658 0.0336 0.0000 +vt 0.2657 0.0070 0.0000 +vt 0.3468 0.0066 0.0000 +vt 0.2660 0.0768 0.0000 +vt 0.3478 0.2063 0.0000 +vt 0.2667 0.2067 0.0000 +vt 0.2665 0.1803 0.0000 +vt 0.3477 0.1798 0.0000 +vt 0.2663 0.1299 0.0000 +vt 0.3474 0.1295 0.0000 +vt 0.4067 0.1677 0.0000 +vt 0.3802 0.1677 0.0000 +vt 0.4939 0.3395 0.0000 +vt 0.4927 0.3933 0.0000 +vt 0.4874 0.3936 0.0000 +vt 0.4818 0.3400 0.0000 +vt 0.4927 0.3979 0.0000 +vt 0.4876 0.3972 0.0000 +vt 0.4888 0.4508 0.0000 +vt 0.4770 0.4492 0.0000 +vt 0.5385 0.4002 0.0000 +vt 0.5383 0.3899 0.0000 +vt 0.4535 0.3936 0.0000 +vt 0.4539 0.4012 0.0000 +vt 0.4258 0.4863 0.0000 +vt 0.4258 0.5053 0.0000 +vt 0.4186 0.5053 0.0000 +vt 0.4186 0.4863 0.0000 +vt 0.4257 0.5256 0.0000 +vt 0.4185 0.5256 0.0000 +vt 0.6112 0.4414 0.0000 +vt 0.6112 0.4866 0.0000 +vt 0.6565 0.4866 0.0000 +vt 0.6565 0.4414 0.0000 +vt 0.5660 0.4866 0.0000 +vt 0.5660 0.4414 0.0000 +vt 0.5207 0.4414 0.0000 +vt 0.5207 0.4866 0.0000 +vt 0.3522 0.2650 0.0000 +vt 0.3552 0.2650 0.0000 +vt 0.3552 0.2250 0.0000 +vt 0.3522 0.2250 0.0000 +vt 0.3582 0.2650 0.0000 +vt 0.3582 0.2250 0.0000 +vt 0.3612 0.2650 0.0000 +vt 0.3612 0.2250 0.0000 +vt 0.3642 0.2650 0.0000 +vt 0.3642 0.2250 0.0000 +vt 0.3672 0.2650 0.0000 +vt 0.3672 0.2250 0.0000 +vt 0.3431 0.2650 0.0000 +vt 0.3461 0.2650 0.0000 +vt 0.3461 0.2250 0.0000 +vt 0.3431 0.2250 0.0000 +vt 0.3491 0.2650 0.0000 +vt 0.3491 0.2250 0.0000 +vt 0.3283 0.2964 0.0000 +vt 0.3166 0.2840 0.0000 +vt 0.3161 0.3011 0.0000 +vt 0.3042 0.2957 0.0000 +vt 0.2995 0.2835 0.0000 +vt 0.3048 0.2715 0.0000 +vt 0.3171 0.2669 0.0000 +vt 0.3290 0.2722 0.0000 +vt 0.9046 0.6493 0.0000 +vt 0.9008 0.5386 0.0000 +vt 0.9379 0.5395 0.0000 +vt 0.9873 0.6497 0.0000 +vt 0.9864 0.7515 0.0000 +vt 0.9038 0.7508 0.0000 +vt 0.8159 0.7500 0.0000 +vt 0.8170 0.6483 0.0000 +vt 0.8177 0.5740 0.0000 +vt 0.9013 0.5303 0.0000 +vt 0.9389 0.5311 0.0000 +vt 0.9949 0.6465 0.0000 +vt 0.9456 0.5363 0.0000 +vt 0.9947 0.7516 0.0000 +vt 0.9956 0.6498 0.0000 +vt 0.9023 0.9864 0.0000 +vt 0.9017 0.9782 0.0000 +vt 0.9843 0.9792 0.0000 +vt 0.9856 0.9874 0.0000 +vt 0.8139 0.9861 0.0000 +vt 0.8140 0.9777 0.0000 +vt 0.8121 0.5677 0.0000 +vt 0.8481 0.5316 0.0000 +vt 0.8535 0.5379 0.0000 +vt 0.8537 0.5295 0.0000 +vt 0.8075 0.7500 0.0000 +vt 0.8085 0.6482 0.0000 +vt 0.8093 0.5737 0.0000 +vt 0.9926 0.9793 0.0000 +vt 0.6984 0.7506 0.0000 +vt 0.6880 0.5036 0.0000 +vt 0.7276 0.4986 0.0000 +vt 0.7809 0.7510 0.0000 +vt 0.7797 0.9806 0.0000 +vt 0.6993 0.9818 0.0000 +vt 0.6361 0.9823 0.0000 +vt 0.6345 0.7503 0.0000 +vt 0.6369 0.5031 0.0000 +vt 0.7269 0.4944 0.0000 +vt 0.6877 0.4992 0.0000 +vt 0.7852 0.7506 0.0000 +vt 0.7319 0.4978 0.0000 +vt 0.7828 0.9817 0.0000 +vt 0.6995 0.9861 0.0000 +vt 0.6361 0.9866 0.0000 +vt 0.6369 0.4988 0.0000 +vt 0.0588 0.0078 0.0000 +vt 0.0582 0.0539 0.0000 +vt 0.0081 0.0539 0.0000 +vt 0.0072 0.0084 0.0000 +vt 0.0599 0.1221 0.0000 +vt 0.0082 0.1222 0.0000 +vt 0.0622 0.9897 0.0000 +vt 0.0578 0.9136 0.0000 +vt 0.0088 0.9139 0.0000 +vt 0.0088 0.9914 0.0000 +vt 0.0088 0.7305 0.0000 +vt 0.0587 0.7306 0.0000 +vt 0.0455 0.5100 0.0000 +vt 0.0088 0.5099 0.0000 +vt 0.0991 0.1164 0.0000 +vt 0.1255 0.0638 0.0000 +vt 0.2859 0.3035 0.0000 +vt 0.2248 0.3404 0.0000 +vt 0.0814 0.5109 0.0000 +vt 0.0593 0.4884 0.0000 +vt 0.0473 0.4889 0.0000 +vt 0.1290 0.9746 0.0000 +vt 0.1231 0.9162 0.0000 +vt 0.0733 0.0137 0.0000 +vt 0.0723 0.0535 0.0000 +vt 0.1243 0.7308 0.0000 +vt 0.4076 0.5055 0.0000 +vt 0.3467 0.5423 0.0000 +vt 0.1027 0.0300 0.0000 +vt 0.2520 0.8877 0.0000 +vt 0.2753 0.8002 0.0000 +vt 0.3662 0.8231 0.0000 +vt 0.3188 0.9101 0.0000 +vt 0.4675 0.3531 0.0000 +vt 0.4983 0.2925 0.0000 +vt 0.4364 0.2906 0.0000 +vt 0.4248 0.3514 0.0000 +vt 0.2909 0.5936 0.0000 +vt 0.2839 0.6954 0.0000 +vt 0.1998 0.6985 0.0000 +vt 0.2053 0.5712 0.0000 +vt 0.1995 0.8032 0.0000 +vt 0.1886 0.8877 0.0000 +vt 0.2586 0.9636 0.0000 +vt 0.1940 0.9816 0.0000 +vt 0.5003 0.2126 0.0000 +vt 0.4380 0.2111 0.0000 +vt 0.3842 0.7116 0.0000 +vt 0.4162 0.9972 0.0000 +vt 0.4162 0.9568 0.0000 +vt 0.4567 0.9568 0.0000 +vt 0.4568 0.9972 0.0000 +vt 0.4167 0.8246 0.0000 +vt 0.4562 0.8235 0.0000 +vt 0.4258 0.7700 0.0000 +vt 0.4227 0.7267 0.0000 +vt 0.4499 0.7248 0.0000 +vt 0.4528 0.7682 0.0000 +vt 0.1692 0.5123 0.0000 +vt 0.0752 0.4204 0.0000 +vt 0.1029 0.3921 0.0000 +vt 0.1967 0.4837 0.0000 +vt 0.3770 0.8226 0.0000 +vt 0.3759 0.9564 0.0000 +vt 0.4959 0.9570 0.0000 +vt 0.4967 0.8229 0.0000 +vt 0.3842 0.7648 0.0000 +vt 0.2353 0.5196 0.0000 +vt 0.2184 0.5378 0.0000 +vt 0.4948 0.7667 0.0000 +vt 0.0958 0.2088 0.0000 +vt 0.1108 0.2706 0.0000 +vt 0.0708 0.2802 0.0000 +vt 0.0626 0.2229 0.0000 +vt 0.0393 0.1588 0.0000 +vt 0.0570 0.1477 0.0000 +vt 0.1029 0.3079 0.0000 +vt 0.0728 0.3428 0.0000 +vt 0.0408 0.3151 0.0000 +vt 0.3337 0.2844 0.0000 +vt 0.3136 0.2652 0.0000 +vt 0.3167 0.2652 0.0000 +vt 0.3159 0.2244 0.0000 +vt 0.3128 0.2245 0.0000 +vt 0.3198 0.2651 0.0000 +vt 0.3190 0.2244 0.0000 +vt 0.3228 0.2650 0.0000 +vt 0.3220 0.2243 0.0000 +vt 0.3259 0.2650 0.0000 +vt 0.3251 0.2242 0.0000 +vt 0.3292 0.2650 0.0000 +vt 0.3282 0.2241 0.0000 +vt 0.3045 0.2654 0.0000 +vt 0.3075 0.2654 0.0000 +vt 0.3067 0.2246 0.0000 +vt 0.3036 0.2247 0.0000 +vt 0.3106 0.2653 0.0000 +vt 0.3098 0.2246 0.0000 +vt 0.3683 0.2960 0.0000 +vt 0.3565 0.2836 0.0000 +vt 0.3561 0.3007 0.0000 +vt 0.3441 0.2953 0.0000 +vt 0.3394 0.2831 0.0000 +vt 0.3448 0.2712 0.0000 +vt 0.3570 0.2665 0.0000 +vt 0.3690 0.2718 0.0000 +vt 0.3737 0.2841 0.0000 +vt 0.6213 0.9820 0.0000 +vt 0.6150 0.7234 0.0000 +vt 0.5947 0.7248 0.0000 +vt 0.6125 0.9826 0.0000 +vt 0.5812 0.9670 0.0000 +vt 0.4960 0.6751 0.0000 +vt 0.5726 0.9695 0.0000 +vt 0.4765 0.6808 0.0000 +vt 0.1112 0.3370 0.0000 +vt 0.2919 0.5292 0.0000 +vt 0.3019 0.4948 0.0000 +vt 0.1425 0.2289 0.0000 +vt 0.5772 0.9749 0.0000 +vt 0.6085 0.9905 0.0000 +vt 0.3608 0.3837 0.0000 +vt 0.4355 0.4520 0.0000 +vt 0.4532 0.4332 0.0000 +vt 0.3823 0.3602 0.0000 +vt 0.3742 0.6360 0.0000 +vt 0.3713 0.6667 0.0000 +vt 0.4407 0.6681 0.0000 +vt 0.4434 0.6426 0.0000 +vt 0.5257 0.3814 0.0000 +vt 0.5103 0.2261 0.0000 +vt 0.5573 0.2654 0.0000 +vt 0.5691 0.3841 0.0000 +vt 0.6013 0.6081 0.0000 +vt 0.6036 0.6610 0.0000 +vt 0.6169 0.6604 0.0000 +vt 0.6146 0.6075 0.0000 +vt 0.0088 0.4884 0.0000 +vt 0.0393 0.1379 0.0000 +vt 0.0077 0.1378 0.0000 +vt 0.0077 0.1578 0.0000 +vt 0.9484 0.4463 0.0000 +vt 0.9005 0.4300 0.0000 +vt 0.9388 0.3179 0.0000 +vt 0.9866 0.3343 0.0000 +vt 0.7531 0.4310 0.0000 +vt 0.7262 0.3193 0.0000 +vt 0.7039 0.4428 0.0000 +vt 0.6771 0.3311 0.0000 +vt 0.2531 0.0136 0.0000 +vt 0.1783 0.0311 0.0000 +vt 0.1783 0.1297 0.0000 +vt 0.2531 0.1558 0.0000 +vt 0.7534 0.4815 0.0000 +vt 0.9009 0.4806 0.0000 +vt 0.0077 0.2224 0.0000 +vt 0.0077 0.2843 0.0000 +vt 0.0077 0.3165 0.0000 +vt 0.0413 0.3585 0.0000 +vt 0.0077 0.3588 0.0000 +vt 0.1380 0.6955 0.0000 +vt 0.1380 0.8042 0.0000 +vt 0.1380 0.8914 0.0000 +vt 0.1380 0.9827 0.0000 +vt 0.3890 0.2902 0.0000 +vt 0.3891 0.3514 0.0000 +vt 0.3905 0.2102 0.0000 +vt 0.1380 0.5702 0.0000 +vt 0.6105 0.5983 0.0000 +vt 0.6020 0.6743 0.0000 +vt 0.5660 0.5319 0.0000 +vt 0.6112 0.5319 0.0000 +vt 0.6671 0.3568 0.0000 +vt 0.6707 0.3903 0.0000 +vt 0.9911 0.2404 0.0000 +vt 0.9911 0.2872 0.0000 +vt 0.9462 0.2871 0.0000 +vt 0.9463 0.2404 0.0000 +vt 0.7013 0.2433 0.0000 +vt 0.7013 0.2842 0.0000 +vt 0.6620 0.2843 0.0000 +vt 0.6620 0.2432 0.0000 +vt 0.7399 0.2434 0.0000 +vt 0.7399 0.2840 0.0000 +vt 0.7787 0.2431 0.0000 +vt 0.7787 0.2842 0.0000 +vt 0.8182 0.2427 0.0000 +vt 0.8182 0.2846 0.0000 +vt 0.8589 0.2417 0.0000 +vt 0.8588 0.2856 0.0000 +vt 0.9017 0.2409 0.0000 +vt 0.9017 0.2865 0.0000 +vt 0.9733 0.2072 0.0000 +vt 0.9119 0.2326 0.0000 +vt 0.9119 0.1424 0.0000 +vt 0.8505 0.2072 0.0000 +vt 0.8251 0.1458 0.0000 +vt 0.8505 0.0845 0.0000 +vt 0.9119 0.0590 0.0000 +vt 0.9733 0.0845 0.0000 +vt 0.9987 0.1458 0.0000 +vt 0.6112 0.3961 0.0000 +vt 0.5660 0.3961 0.0000 +vt 0.4257 0.5463 0.0000 +vt 0.4184 0.5462 0.0000 +vt 0.4256 0.5658 0.0000 +vt 0.4184 0.5658 0.0000 +vt 0.4256 0.5832 0.0000 +vt 0.4183 0.5832 0.0000 +vt 0.4255 0.5977 0.0000 +vt 0.4183 0.5978 0.0000 +vt 0.4255 0.6090 0.0000 +vt 0.4183 0.6092 0.0000 +vt 0.4255 0.6165 0.0000 +vt 0.4182 0.6169 0.0000 +vt 0.3594 0.5738 0.0000 +vt 0.3462 0.5864 0.0000 +vt 0.3459 0.5682 0.0000 +vt 0.3332 0.5738 0.0000 +vt 0.3282 0.5866 0.0000 +vt 0.3335 0.5991 0.0000 +vt 0.3461 0.6043 0.0000 +vt 0.3588 0.5993 0.0000 +vt 0.3644 0.5867 0.0000 +vt 0.3461 0.5864 0.0000 +vt 0.3594 0.5998 0.0000 +vt 0.3460 0.6052 0.0000 +vt 0.3328 0.5996 0.0000 +vt 0.3273 0.5864 0.0000 +vt 0.3328 0.5731 0.0000 +vt 0.3461 0.5676 0.0000 +vt 0.3594 0.5730 0.0000 +vt 0.3649 0.5863 0.0000 +vt 0.3680 0.5650 0.0000 +vt 0.3764 0.5870 0.0000 +vt 0.3457 0.5560 0.0000 +vt 0.3246 0.5656 0.0000 +vt 0.3165 0.5868 0.0000 +vt 0.3253 0.6074 0.0000 +vt 0.3460 0.6160 0.0000 +vt 0.3670 0.6079 0.0000 +vt 0.3726 0.6130 0.0000 +vt 0.3459 0.6238 0.0000 +vt 0.3460 0.6188 0.0000 +vt 0.3690 0.6095 0.0000 +vt 0.3196 0.6127 0.0000 +vt 0.3231 0.6092 0.0000 +vt 0.3087 0.5863 0.0000 +vt 0.3137 0.5864 0.0000 +vt 0.3196 0.5600 0.0000 +vt 0.3232 0.5635 0.0000 +vt 0.3460 0.5489 0.0000 +vt 0.3460 0.5539 0.0000 +vt 0.3725 0.5597 0.0000 +vt 0.3690 0.5633 0.0000 +vt 0.3837 0.5863 0.0000 +vt 0.3787 0.5863 0.0000 +# 409 texture coords + +g Object +usemtl _bossdefault +s 1 +f 1/1/1 2/2/2 3/3/2 4/4/3 +f 1/1/1 4/4/3 5/5/4 +f 6/3/5 7/2/5 8/1/6 9/4/7 +f 9/4/7 8/1/6 10/5/8 +f 11/6/9 12/7/10 13/8/11 14/9/12 +f 15/10/13 16/11/14 12/7/10 11/6/9 +f 17/12/15 18/13/16 16/11/14 15/10/13 +f 19/14/17 20/15/18 18/13/16 17/12/15 +f 21/16/19 22/17/20 20/15/18 19/14/17 +f 23/18/21 24/19/22 22/20/20 21/21/19 +f 25/22/23 26/23/24 24/19/22 23/18/21 +f 14/9/12 13/8/11 26/23/24 25/22/23 +f 13/24/11 12/25/10 27/26/25 +f 12/25/10 16/27/14 27/26/25 +f 16/27/14 18/28/16 27/26/25 +f 18/28/16 20/29/18 27/26/25 +f 20/29/18 22/30/20 27/26/25 +f 22/30/20 24/31/22 27/26/25 +f 24/31/22 26/32/24 27/26/25 +f 26/32/24 13/24/11 27/26/25 +f 15/33/13 11/34/9 28/35/26 +f 28/35/26 11/34/9 14/36/12 +f 21/37/19 28/35/26 23/38/21 +f 19/39/17 28/35/26 21/37/19 +f 15/33/13 28/35/26 17/40/15 +f 17/40/15 28/35/26 19/39/17 +f 23/38/21 28/35/26 25/41/23 +f 25/41/23 28/35/26 14/36/12 +f 29/8/14 30/7/27 31/6/28 32/9/13 +f 30/7/27 33/11/11 34/10/12 31/6/28 +f 33/11/11 35/13/24 36/12/23 34/10/12 +f 35/13/24 37/15/22 38/14/21 36/12/23 +f 37/15/22 39/17/29 40/16/30 38/14/21 +f 39/20/29 41/19/18 42/18/17 40/21/30 +f 41/19/18 43/23/16 44/22/15 42/18/17 +f 43/23/16 29/8/14 32/9/13 44/22/15 +f 29/24/14 45/26/31 30/25/27 +f 30/25/27 45/26/31 33/27/11 +f 33/27/11 45/26/31 35/28/24 +f 35/28/24 45/26/31 37/29/22 +f 37/29/22 45/26/31 39/30/29 +f 39/30/29 45/26/31 41/31/18 +f 41/31/18 45/26/31 43/32/16 +f 43/32/16 45/26/31 29/24/14 +f 34/33/12 46/35/32 31/34/28 +f 46/35/32 32/36/13 31/34/28 +f 40/37/30 42/38/17 46/35/32 +f 38/39/21 40/37/30 46/35/32 +f 34/33/12 36/40/23 46/35/32 +f 36/40/23 38/39/21 46/35/32 +f 42/38/17 44/41/15 46/35/32 +f 44/41/15 32/36/13 46/35/32 +f 10/42/8 47/43/33 48/44/34 9/45/7 +f 8/1/6 49/46/35 47/43/33 10/42/8 +f 50/47/36 51/48/37 52/49/38 53/50/39 +f 53/50/39 52/49/38 54/51/40 55/52/41 +f 8/1/6 7/2/5 55/52/41 +f 55/52/41 7/2/5 50/53/36 53/54/39 +f 56/55/42 57/56/43 58/57/44 59/58/45 +f 57/56/43 60/59/46 61/60/47 58/57/44 +f 60/59/46 62/61/48 63/62/49 61/60/47 +f 62/63/48 60/59/46 57/56/43 56/64/42 +f 59/65/45 58/57/44 61/60/47 63/66/49 +f 64/67/50 65/68/51 66/69/52 67/70/53 +f 65/68/51 68/71/54 69/72/55 66/69/52 +f 70/73/56 71/74/57 72/75/58 73/76/59 +f 74/77/60 75/78/61 76/79/62 77/80/63 +f 78/81/64 79/82/65 80/83/66 81/84/67 +f 79/82/65 82/85/68 83/86/69 80/83/66 +f 82/85/68 84/87/70 85/88/2 83/86/69 +f 84/87/70 86/89/71 87/90/72 85/88/2 +f 86/89/71 88/91/73 89/92/74 87/90/72 +f 88/93/73 90/94/75 91/95/76 89/96/74 +f 90/94/75 92/97/77 93/98/5 91/95/76 +f 92/97/77 78/81/64 81/84/67 93/98/5 +f 78/99/64 94/100/78 79/101/65 +f 79/101/65 94/100/78 82/102/68 +f 82/102/68 94/100/78 84/103/70 +f 84/103/70 94/100/78 86/104/71 +f 86/104/71 94/100/78 88/105/73 +f 88/105/73 94/100/78 90/106/75 +f 95/107/79 96/108/80 97/109/81 98/110/82 +f 95/107/79 98/110/82 99/111/83 100/112/84 +f 95/107/79 100/112/84 101/113/85 102/114/86 +f 102/114/86 103/115/87 95/107/79 +f 104/116/88 105/117/89 97/109/81 96/108/80 +f 106/118/90 98/110/82 97/109/81 105/119/89 +f 107/120/91 99/111/83 98/110/82 106/121/90 +f 108/122/92 109/123/93 110/124/94 111/125/95 +f 112/126/92 113/127/96 109/123/93 108/122/92 +f 114/128/97 115/129/98 116/130/99 103/115/87 +f 104/116/88 96/108/80 116/130/99 115/131/98 +f 101/113/85 117/132/100 118/133/101 102/114/86 +f 103/115/87 102/114/86 118/133/101 114/134/97 +f 111/135/95 110/124/94 99/111/83 107/120/91 +f 100/112/84 99/111/83 110/124/94 109/123/93 +f 100/112/84 109/123/93 113/127/96 101/113/85 +f 119/136/102 120/137/103 121/138/104 106/139/90 +f 119/136/102 106/139/90 111/140/95 122/141/105 +f 119/136/102 122/141/105 123/142/106 124/143/107 +f 124/143/107 125/144/108 120/137/103 119/136/102 +f 126/145/109 121/138/104 120/137/103 127/146/110 +f 128/147/111 106/139/90 121/138/104 126/148/109 +f 129/149/112 111/140/95 106/139/90 128/147/111 +f 130/150/92 122/141/105 111/140/95 129/149/112 +f 131/151/113 123/142/106 122/141/105 130/150/92 +f 127/146/110 120/137/103 125/144/108 132/152/114 +f 133/153/115 134/154/116 135/155/117 136/156/118 +f 134/154/116 127/157/110 132/158/114 135/155/117 +f 130/159/92 137/160/119 138/161/120 131/162/113 +f 139/163/121 140/164/122 141/165/123 142/166/124 +f 126/167/109 143/168/125 144/169/126 128/170/111 +f 141/165/123 143/171/125 145/172/127 133/173/115 +f 130/159/92 129/174/112 146/175/128 137/160/119 +f 134/154/116 133/153/115 145/176/127 147/177/129 +f 137/160/119 140/164/122 139/163/121 138/161/120 +f 140/164/122 137/160/119 146/175/128 144/178/126 +f 144/169/126 146/179/128 129/180/112 128/170/111 +f 143/168/125 126/167/109 147/177/129 145/181/127 +f 148/182/130 149/183/131 150/184/132 151/185/133 +f 151/186/133 150/187/132 152/188/134 153/189/135 +f 154/190/136 155/191/137 156/192/138 157/193/139 +f 158/194/140 149/183/131 148/182/130 159/195/141 +f 148/182/130 151/196/133 153/197/135 159/195/141 +f 155/191/137 149/183/131 158/194/140 156/192/138 +f 154/198/136 157/199/139 152/188/134 150/187/132 +f 155/191/137 154/200/136 150/184/132 149/183/131 +f 160/201/142 161/202/61 162/203/56 163/204/143 +f 161/202/61 164/205/144 165/206/67 162/203/56 +f 166/207/145 167/208/146 168/209/147 169/210/57 +f 170/211/148 160/212/142 163/213/143 171/214/76 +f 170/215/148 164/205/144 161/202/61 160/216/142 +f 163/217/143 162/203/56 165/206/67 171/218/76 +f 165/206/67 164/205/144 166/207/145 169/210/57 +f 170/215/148 167/219/146 166/207/145 164/205/144 +f 171/214/76 168/220/147 167/221/146 170/211/148 +f 165/206/67 169/210/57 168/222/147 171/218/76 +f 172/223/149 173/224/150 174/225/151 175/226/152 +f 172/223/149 175/226/152 176/227/153 177/228/154 +f 174/225/151 173/229/150 178/230/155 179/231/156 +f 90/106/75 94/100/78 92/232/77 +f 92/232/77 94/100/78 78/99/64 +f 180/233/64 181/234/65 182/235/66 183/236/67 +f 181/234/65 184/237/68 185/238/69 182/235/66 +f 184/237/68 186/239/70 187/240/2 185/238/69 +f 186/239/70 188/241/71 189/242/72 187/240/2 +f 188/241/71 190/243/73 191/244/74 189/242/72 +f 190/245/73 192/246/75 193/247/76 191/248/74 +f 192/246/75 194/249/77 195/250/5 193/247/76 +f 194/249/77 180/233/64 183/236/67 195/250/5 +f 180/251/64 196/252/78 181/253/65 +f 181/253/65 196/252/78 184/254/68 +f 184/254/68 196/252/78 186/255/70 +f 186/255/70 196/252/78 188/256/71 +f 188/256/71 196/252/78 190/257/73 +f 190/257/73 196/252/78 192/258/75 +f 192/258/75 196/252/78 194/259/77 +f 194/259/77 196/252/78 180/251/64 +f 74/77/60 71/74/57 70/73/56 75/78/61 +f 197/260/157 198/261/158 199/262/159 200/263/160 +f 201/264/161 200/263/160 199/262/159 202/265/162 +f 203/266/163 201/264/161 202/265/162 204/267/164 +f 198/268/158 197/269/157 203/270/163 204/271/164 +f 200/263/160 201/264/161 203/272/163 197/273/157 +f 205/274/165 206/275/166 207/276/167 208/277/168 +f 209/278/92 210/279/169 211/280/170 212/281/171 +f 210/282/169 208/283/168 207/284/167 211/285/170 +f 213/286/172 214/287/173 215/288/174 216/289/175 +f 217/177/176 218/154/177 219/157/178 220/167/179 +f 136/290/118 221/173/180 222/165/181 142/166/124 +f 223/171/182 224/178/183 225/164/184 222/165/181 +f 226/227/185 227/291/186 228/292/78 229/293/187 +f 230/294/188 231/295/189 232/296/190 233/297/191 +f 231/295/189 234/298/192 235/299/193 232/296/190 +f 234/298/192 236/300/194 237/301/195 235/299/193 +f 237/302/195 236/303/194 230/304/188 233/305/191 +f 236/306/194 234/298/192 231/295/189 230/307/188 +f 238/308/196 239/226/197 226/227/185 229/293/187 +f 240/225/198 239/226/197 238/308/196 241/309/66 +f 242/231/199 240/225/198 241/309/66 243/310/200 +f 244/311/201 242/231/199 243/310/200 131/312/113 +f 245/194/202 246/192/203 247/313/204 248/314/205 +f 249/195/206 245/194/202 248/314/205 250/315/207 +f 251/197/208 249/195/206 250/315/207 252/316/209 +f 253/317/210 254/188/211 251/189/208 252/318/209 +f 255/199/212 254/188/211 253/317/210 256/319/213 +f 246/192/203 255/193/212 256/320/213 247/313/204 +f 206/275/166 213/286/172 216/321/175 207/276/167 +f 212/281/171 214/287/173 213/286/172 206/275/166 +f 215/322/174 214/287/173 212/281/171 211/280/170 +f 77/323/63 72/324/58 71/74/57 74/77/60 +f 216/325/175 215/326/174 211/285/170 207/284/167 +f 55/52/41 54/51/40 49/46/35 8/1/6 +f 257/327/92 258/328/214 259/329/215 260/330/63 +f 261/331/58 262/332/216 258/333/214 257/334/92 +f 263/335/5 264/336/217 262/332/216 261/331/58 +f 265/337/59 266/338/218 264/336/217 263/335/5 +f 267/339/165 268/340/219 266/338/218 265/337/59 +f 269/341/62 270/342/220 268/340/219 267/339/165 +f 271/343/2 272/344/221 270/342/220 269/341/62 +f 260/330/63 259/329/215 272/344/221 271/343/2 +f 259/345/215 258/346/214 273/347/66 +f 258/346/214 262/348/216 273/347/66 +f 262/348/216 264/349/217 273/347/66 +f 264/349/217 266/350/218 273/347/66 +f 266/350/218 268/351/219 273/347/66 +f 268/351/219 270/352/220 273/347/66 +f 270/352/220 272/353/221 273/347/66 +f 272/353/221 259/345/215 273/347/66 +f 274/354/62 275/73/61 276/78/56 277/355/59 +f 275/73/61 278/74/60 279/77/57 276/78/56 +f 278/74/60 280/324/63 281/323/58 279/77/57 +f 280/75/63 278/74/60 275/73/61 274/76/62 +f 277/79/59 276/78/56 279/77/57 281/80/58 +f 282/83/222 283/82/223 284/81/68 285/84/69 +f 286/86/67 287/85/64 283/82/223 282/83/222 +f 288/88/5 289/87/77 287/85/64 286/86/67 +f 290/90/76 291/89/75 289/87/77 288/88/5 +f 292/92/224 293/91/225 291/89/75 290/90/76 +f 294/95/72 295/94/71 293/93/225 292/96/224 +f 296/98/2 297/97/70 295/94/71 294/95/72 +f 285/84/69 284/81/68 297/97/70 296/98/2 +f 284/99/68 283/101/223 298/100/78 +f 283/101/223 287/102/64 298/100/78 +f 287/102/64 289/103/77 298/100/78 +f 289/103/77 291/104/75 298/100/78 +f 291/104/75 293/105/225 298/100/78 +f 293/105/225 295/106/71 298/100/78 +f 295/106/71 297/232/70 298/100/78 +f 297/232/70 284/99/68 298/100/78 +f 299/235/222 300/234/223 301/233/68 302/236/69 +f 303/238/67 304/237/64 300/234/223 299/235/222 +f 305/240/5 306/239/77 304/237/64 303/238/67 +f 307/242/76 308/241/75 306/239/77 305/240/5 +f 309/244/224 310/243/225 308/241/75 307/242/76 +f 311/247/72 312/246/71 310/245/225 309/248/224 +f 313/250/2 314/249/70 312/246/71 311/247/72 +f 302/236/69 301/233/68 314/249/70 313/250/2 +f 301/251/68 300/253/223 315/252/78 +f 300/253/223 304/254/64 315/252/78 +f 304/254/64 306/255/77 315/252/78 +f 306/255/77 308/256/75 315/252/78 +f 308/256/75 310/257/225 315/252/78 +f 310/257/225 312/258/71 315/252/78 +f 312/258/71 314/259/70 315/252/78 +f 314/259/70 301/251/68 315/252/78 +f 199/262/159 198/261/158 316/260/226 317/263/227 +f 199/262/159 317/263/227 318/264/228 202/265/162 +f 202/265/162 318/264/228 319/266/229 204/267/164 +f 198/268/158 204/271/164 319/270/229 316/269/226 +f 319/272/229 318/264/228 317/263/227 316/273/226 +f 320/276/230 321/275/231 205/274/165 208/277/168 +f 209/278/92 322/281/232 323/280/233 210/279/169 +f 210/282/169 323/285/233 320/284/230 208/283/168 +f 324/288/234 325/287/235 326/286/236 327/289/237 +f 127/157/110 134/154/116 147/177/129 126/167/109 +f 141/165/123 133/173/115 136/290/118 142/166/124 +f 143/171/125 141/165/123 140/164/122 144/178/126 +f 228/292/78 177/291/154 176/227/153 229/293/187 +f 238/308/196 229/293/187 176/227/153 175/226/152 +f 238/308/196 175/226/152 174/225/151 241/309/66 +f 241/309/66 174/225/151 179/231/156 243/310/200 +f 243/310/200 179/231/156 178/311/155 131/312/113 +f 247/313/204 156/192/138 158/194/140 248/314/205 +f 248/314/205 158/194/140 159/195/141 250/315/207 +f 250/315/207 159/195/141 153/197/135 252/316/209 +f 253/317/210 252/318/209 153/189/135 152/188/134 +f 253/317/210 152/188/134 157/199/139 256/319/213 +f 256/320/213 157/193/139 156/192/138 247/313/204 +f 327/321/237 326/286/236 321/275/231 320/276/230 +f 322/281/232 321/275/231 326/286/236 325/287/235 +f 322/281/232 325/287/235 324/322/234 323/280/233 +f 323/285/233 324/326/234 327/325/237 320/284/230 +f 49/46/35 54/51/40 328/52/238 1/1/1 +f 48/44/34 47/43/33 5/42/4 4/45/3 +f 47/43/33 49/46/35 1/1/1 5/42/4 +f 52/49/38 51/48/37 329/47/239 330/50/240 +f 54/51/40 52/49/38 330/50/240 328/52/238 +f 1/1/1 328/52/238 2/2/2 +f 328/52/238 330/54/240 329/53/239 2/2/2 +f 331/107/241 332/110/242 333/109/243 334/108/244 +f 335/111/245 332/110/242 331/107/241 336/112/246 +f 337/113/247 336/112/246 331/107/241 338/114/248 +f 339/115/249 331/107/241 334/108/244 340/130/250 +f 341/116/251 334/108/244 333/109/243 342/117/252 +f 333/109/243 332/110/242 343/118/253 342/119/252 +f 332/110/242 335/111/245 344/120/254 343/121/253 +f 345/124/255 346/123/256 347/122/257 348/125/258 +f 346/123/256 349/127/259 350/126/257 347/122/257 +f 351/128/260 339/115/249 340/130/250 352/129/261 +f 340/130/250 334/108/244 341/116/251 352/131/261 +f 353/133/262 354/132/263 337/113/247 338/114/248 +f 339/115/249 351/134/260 353/133/262 338/114/248 +f 335/111/245 345/124/255 348/135/258 344/120/254 +f 345/124/255 335/111/245 336/112/246 346/123/256 +f 349/127/259 346/123/256 336/112/246 337/113/247 +f 355/136/264 343/139/253 356/138/265 357/137/266 +f 348/140/258 343/139/253 355/136/264 358/141/267 +f 123/142/106 358/141/267 355/136/264 124/143/107 +f 124/143/107 355/136/264 357/137/266 125/144/108 +f 357/137/266 356/138/265 220/145/179 219/146/178 +f 356/138/265 343/139/253 359/147/268 220/148/179 +f 343/139/253 348/140/258 360/149/269 359/147/268 +f 348/140/258 358/141/267 361/150/92 360/149/269 +f 358/141/267 123/142/106 131/151/113 361/150/92 +f 125/144/108 357/137/266 219/146/178 132/152/114 +f 135/155/117 218/154/177 221/153/180 136/156/118 +f 132/158/114 219/157/178 218/154/177 135/155/117 +f 138/161/120 362/160/270 361/159/92 131/162/113 +f 139/163/121 142/166/124 222/165/181 225/164/184 +f 220/167/179 359/170/268 224/169/183 223/168/182 +f 363/172/271 223/171/182 222/165/181 221/173/180 +f 364/175/272 360/174/269 361/159/92 362/160/270 +f 218/154/177 217/177/176 363/176/271 221/153/180 +f 139/163/121 225/164/184 362/160/270 138/161/120 +f 364/175/272 362/160/270 225/164/184 224/178/183 +f 360/180/269 364/179/272 224/169/183 359/170/268 +f 217/177/176 220/167/179 223/168/182 363/181/271 +f 365/184/273 366/183/274 367/182/275 368/185/276 +f 254/188/211 365/187/273 368/186/276 251/189/208 +f 246/192/203 369/191/277 370/190/278 255/193/212 +f 245/194/202 249/195/206 367/182/275 366/183/274 +f 251/197/208 368/196/276 367/182/275 249/195/206 +f 245/194/202 366/183/274 369/191/277 246/192/203 +f 254/188/211 255/199/212 370/198/278 365/187/273 +f 365/184/273 370/200/278 369/191/277 366/183/274 +f 371/203/61 372/202/56 373/201/143 374/204/142 +f 375/206/69 376/205/279 372/202/56 371/203/61 +f 377/209/280 378/208/281 379/207/282 380/210/60 +f 374/213/142 373/212/143 381/211/283 382/214/72 +f 372/202/56 376/205/279 381/215/283 373/216/143 +f 375/206/69 371/203/61 374/217/142 382/218/72 +f 375/206/69 380/210/60 379/207/282 376/205/279 +f 379/207/282 378/219/281 381/215/283 376/205/279 +f 378/221/281 377/220/280 382/214/72 381/211/283 +f 377/222/280 380/210/60 375/206/69 382/218/72 +f 240/225/198 383/224/284 384/223/285 239/226/197 +f 226/227/185 239/226/197 384/223/285 227/228/186 +f 244/230/201 383/229/284 240/225/198 242/231/199 +f 68/71/54 385/356/286 386/357/287 69/72/55 +f 385/356/286 387/358/288 388/359/289 386/357/287 +f 387/358/288 389/360/290 390/361/291 388/359/289 +f 389/360/290 391/362/292 392/363/293 390/361/291 +f 391/362/292 393/364/294 394/365/295 392/363/293 +f 393/364/294 64/366/50 67/367/53 394/365/295 +f 395/368/296 396/369/297 397/370/298 +f 397/370/298 396/369/297 398/371/299 +f 398/371/299 396/369/297 399/372/300 +f 399/372/300 396/369/297 400/373/301 +f 400/373/301 396/369/297 401/374/302 +f 401/374/302 396/369/297 402/375/303 +f 402/375/303 396/369/297 403/376/304 +f 395/368/296 403/376/304 396/369/297 +f 404/377/305 405/378/306 406/379/307 +f 404/377/305 406/379/307 407/380/308 +f 404/377/305 407/380/308 408/381/309 +f 404/377/305 408/381/309 409/382/310 +f 404/377/305 409/382/310 410/383/311 +f 404/377/305 410/383/311 411/384/312 +f 404/377/305 411/384/312 412/385/313 +f 404/377/305 412/385/313 405/378/306 +f 64/386/50 393/387/294 403/376/304 395/368/296 +f 397/370/298 65/388/51 64/386/50 395/368/296 +f 398/371/299 68/389/54 65/388/51 397/370/298 +f 399/372/300 385/390/286 68/389/54 398/371/299 +f 400/373/301 387/391/288 385/390/286 399/372/300 +f 401/374/302 389/392/290 387/391/288 400/373/301 +f 402/375/303 391/393/292 389/392/290 401/374/302 +f 403/376/304 393/387/294 391/393/292 402/375/303 +f 67/394/53 66/395/52 413/396/314 414/397/315 +f 66/395/52 69/398/55 415/399/316 413/396/314 +f 416/296/317 417/295/318 418/294/319 419/297/320 +f 420/299/321 421/298/322 417/295/318 416/296/317 +f 422/301/323 423/300/324 421/298/322 420/299/321 +f 422/302/323 419/305/320 418/304/319 423/303/324 +f 417/295/318 421/298/322 423/306/324 418/307/319 +f 69/398/55 386/400/287 424/401/325 415/399/316 +f 386/400/287 388/402/289 425/403/326 424/401/325 +f 388/402/289 390/404/291 426/405/327 425/403/326 +f 390/404/291 392/406/293 427/407/328 426/405/327 +f 392/406/293 394/408/295 428/409/329 427/407/328 +f 394/408/295 67/394/53 414/397/315 428/409/329 +f 414/397/315 413/396/314 406/379/307 405/378/306 +f 413/396/314 415/399/316 407/380/308 406/379/307 +f 415/399/316 424/401/325 408/381/309 407/380/308 +f 424/401/325 425/403/326 409/382/310 408/381/309 +f 425/403/326 426/405/327 410/383/311 409/382/310 +f 426/405/327 427/407/328 411/384/312 410/383/311 +f 427/407/328 428/409/329 412/385/313 411/384/312 +f 412/385/313 428/409/329 414/397/315 405/378/306 +f 103/115/87 116/130/99 96/108/80 95/107/79 +f 338/114/248 331/107/241 339/115/249 +f 429/329/216 430/328/330 431/327/257 432/330/58 +f 430/333/330 433/332/215 434/331/63 431/334/257 +f 433/332/215 435/336/221 436/335/2 434/331/63 +f 435/336/221 437/338/220 438/337/62 436/335/2 +f 437/338/220 439/340/331 440/339/78 438/337/62 +f 439/340/331 441/342/218 442/341/59 440/339/78 +f 441/342/218 443/344/217 444/343/5 442/341/59 +f 443/344/217 429/329/216 432/330/58 444/343/5 +f 429/345/216 445/347/66 430/346/330 +f 430/346/330 445/347/66 433/348/215 +f 433/348/215 445/347/66 435/349/221 +f 435/349/221 445/347/66 437/350/220 +f 437/350/220 445/347/66 439/351/331 +f 439/351/331 445/347/66 441/352/218 +f 441/352/218 445/347/66 443/353/217 +f 443/353/217 445/347/66 429/345/216 +f 75/78/61 70/73/56 73/354/59 76/355/62 +# 307 polygons - 102 triangles + diff --git a/samples/js-tests/res/Sprite3DTest/caustics.png b/samples/js-tests/res/Sprite3DTest/caustics.png new file mode 100644 index 0000000000..179f30dbc7 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/caustics.png differ diff --git a/samples/js-tests/res/Sprite3DTest/circle.png b/samples/js-tests/res/Sprite3DTest/circle.png new file mode 100644 index 0000000000..fb1e8d592a Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/circle.png differ diff --git a/samples/js-tests/res/Sprite3DTest/cylinder.c3b b/samples/js-tests/res/Sprite3DTest/cylinder.c3b new file mode 100644 index 0000000000..be07b5b05a Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/cylinder.c3b differ diff --git a/samples/js-tests/res/Sprite3DTest/cylinder.frag b/samples/js-tests/res/Sprite3DTest/cylinder.frag new file mode 100644 index 0000000000..c971705dfd --- /dev/null +++ b/samples/js-tests/res/Sprite3DTest/cylinder.frag @@ -0,0 +1,16 @@ +#ifdef GL_ES +varying mediump vec2 v_texture_coord; +#else +varying vec2 v_texture_coord; +#endif + +uniform vec4 u_color; +uniform float offset; +uniform float duration; +uniform sampler2D caustics; +void main(void) +{ + vec4 color = duration*vec4(0,0.8,0.4,1.0); + //blend two texture + gl_FragColor = u_color*texture2D(CC_Texture0, vec2(v_texture_coord.x- 2.0 * offset,v_texture_coord.y)) * vec4(0.3,0.3,0.3,1)+texture2D(caustics,vec2(v_texture_coord.x-offset,v_texture_coord.y)).r*color; +} \ No newline at end of file diff --git a/samples/js-tests/res/Sprite3DTest/cylinder.vert b/samples/js-tests/res/Sprite3DTest/cylinder.vert new file mode 100644 index 0000000000..cf80309904 --- /dev/null +++ b/samples/js-tests/res/Sprite3DTest/cylinder.vert @@ -0,0 +1,10 @@ +attribute vec4 a_position; +attribute vec2 a_texCoord; +uniform float offset; +varying vec2 v_texture_coord; +void main(void) +{ + gl_Position = CC_MVPMatrix * a_position; + v_texture_coord = a_texCoord; + v_texture_coord.y = (1.0 - v_texture_coord.y); +} diff --git a/samples/js-tests/res/Sprite3DTest/dragon.png b/samples/js-tests/res/Sprite3DTest/dragon.png new file mode 100644 index 0000000000..0542b67ac3 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/dragon.png differ diff --git a/samples/js-tests/res/Sprite3DTest/fog.frag b/samples/js-tests/res/Sprite3DTest/fog.frag new file mode 100644 index 0000000000..bdf3e369a6 --- /dev/null +++ b/samples/js-tests/res/Sprite3DTest/fog.frag @@ -0,0 +1,14 @@ +#ifdef GL_ES +varying mediump vec2 v_texture_coord; +#else +varying vec2 v_texture_coord; +#endif +varying float v_fogFactor; + +uniform vec4 u_fogColor; + +void main (void) +{ + vec4 finalColor = texture2D(CC_Texture0, v_texture_coord); + gl_FragColor = mix(u_fogColor, finalColor, v_fogFactor ); //out put finalColor +} diff --git a/samples/js-tests/res/Sprite3DTest/fog.vert b/samples/js-tests/res/Sprite3DTest/fog.vert new file mode 100644 index 0000000000..4dd4f578e6 --- /dev/null +++ b/samples/js-tests/res/Sprite3DTest/fog.vert @@ -0,0 +1,29 @@ +attribute vec4 a_position; +attribute vec2 a_texCoord; +varying float v_fogFactor; //weight for fog +varying vec2 v_texture_coord; + +uniform float u_fogDensity;// For exp and exp2 equation +uniform float u_fogStart; // This is only for linear fog +uniform float u_fogEnd; // This is only for linear fog +uniform int u_fogEquation; // 0 = linear, 1 = exp, 2 = exp2 + +void main(void) +{ + gl_Position = CC_MVPMatrix * a_position; + v_texture_coord = a_texCoord; + + float fogFragCoord = abs(gl_Position.z); //get fog distance + + + if(u_fogEquation == 0) + v_fogFactor = (u_fogEnd-fogFragCoord )/(u_fogEnd-u_fogStart); //linear fog + else if(u_fogEquation == 1) + v_fogFactor = exp(-u_fogDensity*fogFragCoord ); //exp fog + else if(u_fogEquation == 2) + v_fogFactor = exp(-pow(u_fogDensity*fogFragCoord , 2.0)); //exp2 fog + + + v_fogFactor = clamp(v_fogFactor, 0.0, 1.0); //clamp 0 to 1 + +} diff --git a/samples/js-tests/res/Sprite3DTest/girl.c3b b/samples/js-tests/res/Sprite3DTest/girl.c3b new file mode 100644 index 0000000000..705b2eb255 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/girl.c3b differ diff --git a/samples/js-tests/res/Sprite3DTest/monguger.tga b/samples/js-tests/res/Sprite3DTest/monguger.tga new file mode 100644 index 0000000000..d190d819bb Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/monguger.tga differ diff --git a/samples/js-tests/res/Sprite3DTest/orc.c3b b/samples/js-tests/res/Sprite3DTest/orc.c3b new file mode 100644 index 0000000000..03c9dd6910 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/orc.c3b differ diff --git a/samples/js-tests/res/Sprite3DTest/plane.c3t b/samples/js-tests/res/Sprite3DTest/plane.c3t new file mode 100644 index 0000000000..3fedb94002 --- /dev/null +++ b/samples/js-tests/res/Sprite3DTest/plane.c3t @@ -0,0 +1,93 @@ +{ + "version": "0.3", + "id": "", + "meshes": [ + { + "attributes": [{ + "size": 3, + "type": "GL_FLOAT", + "attribute": "VERTEX_ATTRIB_POSITION" + }, { + "size": 3, + "type": "GL_FLOAT", + "attribute": "VERTEX_ATTRIB_NORMAL" + }, { + "size": 2, + "type": "GL_FLOAT", + "attribute": "VERTEX_ATTRIB_TEX_COORD" + }], + "vertices": [ + 50.000000, -50.000000, 0.000000, 0.000000, 0.000000, -1.000000, 0.000000, 0.000000, + -50.000000, -50.000000, 0.000000, 0.000000, 0.000000, -1.000000, 1.000000, 0.000000, + 50.000000, 50.000000, 0.000000, 0.000000, 0.000000, -1.000000, 0.000000, 1.000000, + -50.000000, 50.000000, 0.000000, 0.000000, 0.000000, -1.000000, 1.000000, 1.000000, + 50.000000, 50.000000, 3.000000, 0.000000, 0.000000, 1.000000, 1.000000, 1.000000, + -50.000000, 50.000000, 3.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, + -50.000000, -50.000000, 3.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, + 50.000000, -50.000000, 3.000000, 0.000000, 0.000000, 1.000000, 1.000000, 0.000000, + 50.000000, -50.000000, 3.000000, 0.000000, -1.000000, 0.000000, 1.000000, 1.000000, + -50.000000, -50.000000, 3.000000, 0.000000, -1.000000, 0.000000, 0.000000, 1.000000, + -50.000000, -50.000000, 0.000000, 0.000000, -1.000000, 0.000000, 0.000000, 0.000000, + 50.000000, -50.000000, 0.000000, 0.000000, -1.000000, 0.000000, 1.000000, 0.000000, + 50.000000, 50.000000, 3.000000, 1.000000, 0.000000, 0.000000, 1.000000, 1.000000, + 50.000000, -50.000000, 3.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, + 50.000000, -50.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, + 50.000000, 50.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, + -50.000000, 50.000000, 3.000000, 0.000000, 1.000000, 0.000000, 1.000000, 1.000000, + 50.000000, 50.000000, 3.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, + 50.000000, 50.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, + -50.000000, 50.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, + -50.000000, -50.000000, 3.000000, -1.000000, 0.000000, 0.000000, 1.000000, 1.000000, + -50.000000, 50.000000, 3.000000, -1.000000, 0.000000, 0.000000, 0.000000, 1.000000, + -50.000000, 50.000000, 0.000000, -1.000000, 0.000000, 0.000000, 0.000000, 0.000000, + -50.000000, -50.000000, 0.000000, -1.000000, 0.000000, 0.000000, 1.000000, 0.000000 + ], + "parts": [ + { + "id": "shape1_part1", + "type": "TRIANGLES", + "indices": [ + 0, 1, 2, 1, 3, 2, 4, 5, 6, 4, 6, 7, + 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, + 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23 + ] + } + ] + } + ], + "materials": [ + { + "id": "01 - Default", + "ambient": [ 0.588235, 0.588235, 0.588235], + "diffuse": [ 0.588235, 0.588235, 0.588235], + "emissive": [ 0.000000, 0.000000, 0.000000], + "opacity": 1.000000, + "specular": [ 0.900000, 0.900000, 0.900000], + "shininess": 2.000000, + "textures": [ + { + "id": "Map #1", + "filename": "plane.png", + "type": "DIFFUSE", + "wrapModeU": "REPEAT", + "wrapModeV": "REPEAT" + } + ] + } + ], + "nodes": [ + { + "id": "Box001", + "skeleton": false, + "transform": [ 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, -1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000], + "parts": [ + { + "meshpartid": "shape1_part1", + "materialid": "01 - Default", + "uvMapping": [[ 0]] + } + ] + } + ], + "animations": [] +} \ No newline at end of file diff --git a/samples/js-tests/res/Sprite3DTest/plane.png b/samples/js-tests/res/Sprite3DTest/plane.png new file mode 100644 index 0000000000..ac7c566c42 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/plane.png differ diff --git a/samples/js-tests/res/Sprite3DTest/shadowCircle.png b/samples/js-tests/res/Sprite3DTest/shadowCircle.png new file mode 100644 index 0000000000..6442db4573 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/shadowCircle.png differ diff --git a/samples/js-tests/res/Sprite3DTest/simple_shadow.frag b/samples/js-tests/res/Sprite3DTest/simple_shadow.frag new file mode 100644 index 0000000000..917a8a73ab --- /dev/null +++ b/samples/js-tests/res/Sprite3DTest/simple_shadow.frag @@ -0,0 +1,22 @@ +#ifdef GL_ES +varying mediump vec2 v_texture_coord; +varying mediump vec4 v_position; +#else +varying vec2 v_texture_coord; +varying vec4 v_position; +#endif +uniform sampler2D u_shadowTexture; +uniform vec3 u_target_pos; +uniform vec4 u_color; +void main(void) +{ + + float Radius = 4.0;//project range + vec3 UVector = vec3(1.0, 0.0, 0.0)/(2.0 * Radius); + vec3 VVector = vec3(0.0, 0.0, -1.0)/(-2.0 * Radius); + vec2 coord; + coord.x = dot(v_position.xyz - u_target_pos, UVector) + 0.5; + coord.y = dot(v_position.xyz - u_target_pos, VVector) + 0.5; + + gl_FragColor = u_color*texture2D(CC_Texture0,v_texture_coord)*texture2D(u_shadowTexture,coord); +} \ No newline at end of file diff --git a/samples/js-tests/res/Sprite3DTest/simple_shadow.vert b/samples/js-tests/res/Sprite3DTest/simple_shadow.vert new file mode 100644 index 0000000000..09c834f3be --- /dev/null +++ b/samples/js-tests/res/Sprite3DTest/simple_shadow.vert @@ -0,0 +1,12 @@ +attribute vec4 a_position; +attribute vec2 a_texCoord; +varying vec2 v_texture_coord; +varying vec4 v_position; +uniform mat4 u_model_matrix; +void main(void) +{ + gl_Position = CC_PMatrix * CC_MVMatrix * a_position; + v_texture_coord = a_texCoord; + v_texture_coord.y = (1.0 - v_texture_coord.y); + v_position = u_model_matrix * a_position; +} diff --git a/samples/js-tests/res/Sprite3DTest/sphere.c3b b/samples/js-tests/res/Sprite3DTest/sphere.c3b new file mode 100644 index 0000000000..3969dd7da1 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/sphere.c3b differ diff --git a/samples/js-tests/res/Sprite3DTest/spheretex.png b/samples/js-tests/res/Sprite3DTest/spheretex.png new file mode 100644 index 0000000000..94eed4b1dd Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/spheretex.png differ diff --git a/samples/js-tests/res/Sprite3DTest/teapot.c3b b/samples/js-tests/res/Sprite3DTest/teapot.c3b new file mode 100644 index 0000000000..a16097df49 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/teapot.c3b differ diff --git a/samples/js-tests/res/Sprite3DTest/teapot.png b/samples/js-tests/res/Sprite3DTest/teapot.png new file mode 100644 index 0000000000..65c3aae6b8 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/teapot.png differ diff --git a/samples/js-tests/res/Sprite3DTest/texture.png b/samples/js-tests/res/Sprite3DTest/texture.png new file mode 100644 index 0000000000..c4ceacc87b Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/texture.png differ diff --git a/samples/js-tests/res/Sprite3DTest/toon.frag b/samples/js-tests/res/Sprite3DTest/toon.frag new file mode 100644 index 0000000000..aa412d1adf --- /dev/null +++ b/samples/js-tests/res/Sprite3DTest/toon.frag @@ -0,0 +1,24 @@ +#ifdef GL_ES +varying mediump vec2 v_texture_coord; +#else +varying vec2 v_texture_coord; +#endif +uniform vec4 u_color; +varying vec3 v_normal; +void main(void) +{ + vec3 light_direction = vec3(1,-1,-1); + light_direction = normalize(light_direction); + vec3 light_color = vec3(1,1,1); + vec3 normal = normalize(v_normal); + float diffuse_factor = dot(normal,-light_direction); + vec4 diffuse_color = texture2D(CC_Texture0,v_texture_coord); + + if (diffuse_factor > 0.95) diffuse_factor=1.0; + else if (diffuse_factor > 0.75) diffuse_factor = 0.8; + else if (diffuse_factor > 0.50) diffuse_factor = 0.6; + else diffuse_factor = 0.4; + + light_color = light_color * diffuse_factor; + gl_FragColor = vec4(light_color,1.0) * diffuse_color * u_color; +} \ No newline at end of file diff --git a/samples/js-tests/res/Sprite3DTest/toon.vert b/samples/js-tests/res/Sprite3DTest/toon.vert new file mode 100644 index 0000000000..730f010e41 --- /dev/null +++ b/samples/js-tests/res/Sprite3DTest/toon.vert @@ -0,0 +1,12 @@ +attribute vec4 a_position; +attribute vec2 a_texCoord; +attribute vec3 a_normal; +varying vec2 v_texture_coord; +varying vec3 v_normal; +void main(void) +{ + gl_Position = CC_MVPMatrix * a_position; + v_texture_coord = a_texCoord; + v_texture_coord.y = (1.0 - v_texture_coord.y); + v_normal = CC_NormalMatrix *a_normal; +} diff --git a/samples/js-tests/res/Sprite3DTest/tortoise.c3b b/samples/js-tests/res/Sprite3DTest/tortoise.c3b new file mode 100644 index 0000000000..c97f2eccdb Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/tortoise.c3b differ diff --git a/samples/js-tests/res/Sprite3DTest/tortoise.png b/samples/js-tests/res/Sprite3DTest/tortoise.png new file mode 100644 index 0000000000..7c12336ae2 Binary files /dev/null and b/samples/js-tests/res/Sprite3DTest/tortoise.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Button/button_common_box03_001.png b/samples/js-tests/res/cocosui/CCS/2.1/Button/button_common_box03_001.png new file mode 100644 index 0000000000..f8fefea68c Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Button/button_common_box03_001.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Button/button_common_box03_003 copy 221.png b/samples/js-tests/res/cocosui/CCS/2.1/Button/button_common_box03_003 copy 221.png new file mode 100644 index 0000000000..6af70e8d56 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Button/button_common_box03_003 copy 221.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Button/button_common_box03_d.png b/samples/js-tests/res/cocosui/CCS/2.1/Button/button_common_box03_d.png new file mode 100644 index 0000000000..0534b815c2 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Button/button_common_box03_d.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/CheckBox/blue_cloud.png b/samples/js-tests/res/cocosui/CCS/2.1/CheckBox/blue_cloud.png new file mode 100644 index 0000000000..d974da133b Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/CheckBox/blue_cloud.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/CheckBox/button_common_box03_p.png b/samples/js-tests/res/cocosui/CCS/2.1/CheckBox/button_common_box03_p.png new file mode 100644 index 0000000000..69fe93f411 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/CheckBox/button_common_box03_p.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/CheckBox/icon_done.png b/samples/js-tests/res/cocosui/CCS/2.1/CheckBox/icon_done.png new file mode 100644 index 0000000000..1c4f9d7faa Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/CheckBox/icon_done.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/CheckBox/icon_token.png b/samples/js-tests/res/cocosui/CCS/2.1/CheckBox/icon_token.png new file mode 100644 index 0000000000..857c664b96 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/CheckBox/icon_token.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/Button_Disable.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/Button_Disable.png new file mode 100644 index 0000000000..62ee840c40 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/Button_Disable.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/Button_Normal.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/Button_Normal.png new file mode 100644 index 0000000000..e045f66f14 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/Button_Normal.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/Button_Press.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/Button_Press.png new file mode 100644 index 0000000000..a04727f7ff Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/Button_Press.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBoxNode_Disable.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBoxNode_Disable.png new file mode 100644 index 0000000000..6647a18369 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBoxNode_Disable.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBoxNode_Normal.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBoxNode_Normal.png new file mode 100644 index 0000000000..e8520fb1ce Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBoxNode_Normal.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBox_Disable.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBox_Disable.png new file mode 100644 index 0000000000..78b01b9bb9 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBox_Disable.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBox_Normal.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBox_Normal.png new file mode 100644 index 0000000000..035045d88b Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBox_Normal.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBox_Press.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBox_Press.png new file mode 100644 index 0000000000..128232662f Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/CheckBox_Press.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/ImageFile.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/ImageFile.png new file mode 100644 index 0000000000..4d471a4c88 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/ImageFile.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/LoadingBarFile.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/LoadingBarFile.png new file mode 100644 index 0000000000..7dd484e426 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/LoadingBarFile.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/SliderNode_Disable.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/SliderNode_Disable.png new file mode 100644 index 0000000000..61dd7553a8 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/SliderNode_Disable.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/SliderNode_Normal.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/SliderNode_Normal.png new file mode 100644 index 0000000000..f044b42e3d Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/SliderNode_Normal.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/SliderNode_Press.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/SliderNode_Press.png new file mode 100644 index 0000000000..163ccc6014 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/SliderNode_Press.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/Slider_Back.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/Slider_Back.png new file mode 100644 index 0000000000..0f81bb6f77 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/Slider_Back.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/Slider_PressBar.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/Slider_PressBar.png new file mode 100644 index 0000000000..d9fe49b7ef Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/Slider_PressBar.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/Sprite.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/Sprite.png new file mode 100644 index 0000000000..115fa75667 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/Sprite.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/TextAtlas.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/TextAtlas.png new file mode 100644 index 0000000000..61053b2231 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/TextAtlas.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultBMFont.fnt b/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultBMFont.fnt new file mode 100644 index 0000000000..c63d34af11 --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultBMFont.fnt @@ -0,0 +1,236 @@ +info face="Yuppy SC" size=25 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=2,2 +common lineHeight=36 base=27 scaleW=512 scaleH=256 pages=1 packed=0 +page id=0 file="defaultBMFont.png" +chars count=232 +char id=32 x=87 y=197 width=0 height=0 xoffset=0 yoffset=27 xadvance=7 page=0 chnl=0 letter="space" +char id=33 x=352 y=156 width=4 height=20 xoffset=2 yoffset=7 xadvance=7 page=0 chnl=0 letter="!" +char id=34 x=406 y=179 width=9 height=9 xoffset=1 yoffset=6 xadvance=9 page=0 chnl=0 letter=""" +char id=35 x=176 y=156 width=16 height=20 xoffset=0 yoffset=7 xadvance=14 page=0 chnl=0 letter="#" +char id=36 x=137 y=84 width=14 height=24 xoffset=1 yoffset=5 xadvance=14 page=0 chnl=0 letter="$" +char id=37 x=231 y=84 width=21 height=23 xoffset=1 yoffset=5 xadvance=20 page=0 chnl=0 letter="%" +char id=38 x=214 y=110 width=18 height=21 xoffset=1 yoffset=6 xadvance=17 page=0 chnl=0 letter="&" +char id=39 x=417 y=179 width=5 height=9 xoffset=1 yoffset=6 xadvance=5 page=0 chnl=0 letter="'" +char id=40 x=330 y=2 width=10 height=26 xoffset=1 yoffset=7 xadvance=8 page=0 chnl=0 letter="(" +char id=41 x=342 y=2 width=10 height=26 xoffset=1 yoffset=7 xadvance=8 page=0 chnl=0 letter=")" +char id=42 x=393 y=179 width=11 height=10 xoffset=1 yoffset=6 xadvance=10 page=0 chnl=0 letter="*" +char id=43 x=232 y=179 width=14 height=14 xoffset=1 yoffset=10 xadvance=15 page=0 chnl=0 letter="+" +char id=44 x=443 y=179 width=5 height=8 xoffset=2 yoffset=23 xadvance=7 page=0 chnl=0 letter="," +char id=45 x=76 y=197 width=9 height=4 xoffset=1 yoffset=15 xadvance=8 page=0 chnl=0 letter="-" +char id=46 x=13 y=197 width=5 height=5 xoffset=2 yoffset=22 xadvance=7 page=0 chnl=0 letter="." +char id=47 x=98 y=156 width=9 height=21 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=0 letter="/" +char id=48 x=19 y=133 width=15 height=21 xoffset=1 yoffset=6 xadvance=14 page=0 chnl=0 letter="0" +char id=49 x=307 y=156 width=10 height=20 xoffset=2 yoffset=7 xadvance=14 page=0 chnl=0 letter="1" +char id=50 x=87 y=133 width=15 height=21 xoffset=1 yoffset=6 xadvance=14 page=0 chnl=0 letter="2" +char id=51 x=268 y=133 width=14 height=21 xoffset=1 yoffset=6 xadvance=14 page=0 chnl=0 letter="3" +char id=52 x=194 y=156 width=15 height=20 xoffset=0 yoffset=7 xadvance=14 page=0 chnl=0 letter="4" +char id=53 x=204 y=133 width=14 height=21 xoffset=1 yoffset=7 xadvance=14 page=0 chnl=0 letter="5" +char id=54 x=348 y=133 width=14 height=21 xoffset=1 yoffset=6 xadvance=14 page=0 chnl=0 letter="6" +char id=55 x=316 y=133 width=14 height=21 xoffset=1 yoffset=6 xadvance=14 page=0 chnl=0 letter="7" +char id=56 x=104 y=133 width=15 height=21 xoffset=1 yoffset=6 xadvance=14 page=0 chnl=0 letter="8" +char id=57 x=188 y=133 width=14 height=21 xoffset=1 yoffset=6 xadvance=14 page=0 chnl=0 letter="9" +char id=58 x=281 y=179 width=4 height=14 xoffset=3 yoffset=13 xadvance=7 page=0 chnl=0 letter=":" +char id=59 x=177 y=179 width=5 height=16 xoffset=2 yoffset=14 xadvance=7 page=0 chnl=0 letter=";" +char id=60 x=200 y=179 width=14 height=14 xoffset=1 yoffset=10 xadvance=15 page=0 chnl=0 letter="<" +char id=61 x=377 y=179 width=14 height=10 xoffset=1 yoffset=12 xadvance=15 page=0 chnl=0 letter="=" +char id=62 x=216 y=179 width=14 height=14 xoffset=1 yoffset=10 xadvance=15 page=0 chnl=0 letter=">" +char id=63 x=284 y=133 width=14 height=21 xoffset=1 yoffset=6 xadvance=14 page=0 chnl=0 letter="?" +char id=64 x=217 y=31 width=24 height=24 xoffset=1 yoffset=5 xadvance=24 page=0 chnl=0 letter="@" +char id=65 x=153 y=110 width=19 height=21 xoffset=0 yoffset=6 xadvance=17 page=0 chnl=0 letter="A" +char id=66 x=426 y=110 width=17 height=21 xoffset=1 yoffset=6 xadvance=16 page=0 chnl=0 letter="B" +char id=67 x=111 y=110 width=19 height=21 xoffset=1 yoffset=6 xadvance=18 page=0 chnl=0 letter="C" +char id=68 x=194 y=110 width=18 height=21 xoffset=1 yoffset=6 xadvance=17 page=0 chnl=0 letter="D" +char id=69 x=445 y=110 width=17 height=21 xoffset=1 yoffset=6 xadvance=16 page=0 chnl=0 letter="E" +char id=70 x=482 y=110 width=16 height=21 xoffset=1 yoffset=6 xadvance=15 page=0 chnl=0 letter="F" +char id=71 x=24 y=110 width=20 height=21 xoffset=0 yoffset=6 xadvance=18 page=0 chnl=0 letter="G" +char id=72 x=369 y=110 width=17 height=21 xoffset=1 yoffset=6 xadvance=17 page=0 chnl=0 letter="H" +char id=73 x=364 y=156 width=4 height=20 xoffset=3 yoffset=7 xadvance=7 page=0 chnl=0 letter="I" +char id=74 x=32 y=156 width=13 height=21 xoffset=1 yoffset=6 xadvance=12 page=0 chnl=0 letter="J" +char id=75 x=388 y=110 width=17 height=21 xoffset=1 yoffset=6 xadvance=16 page=0 chnl=0 letter="K" +char id=76 x=300 y=133 width=14 height=21 xoffset=1 yoffset=6 xadvance=14 page=0 chnl=0 letter="L" +char id=77 x=68 y=110 width=20 height=21 xoffset=1 yoffset=6 xadvance=20 page=0 chnl=0 letter="M" +char id=78 x=407 y=110 width=17 height=21 xoffset=1 yoffset=6 xadvance=17 page=0 chnl=0 letter="N" +char id=79 x=293 y=84 width=20 height=22 xoffset=1 yoffset=6 xadvance=19 page=0 chnl=0 letter="O" +char id=80 x=350 y=110 width=17 height=21 xoffset=1 yoffset=6 xadvance=16 page=0 chnl=0 letter="P" +char id=81 x=271 y=84 width=20 height=22 xoffset=1 yoffset=6 xadvance=19 page=0 chnl=0 letter="Q" +char id=82 x=274 y=110 width=17 height=21 xoffset=1 yoffset=6 xadvance=16 page=0 chnl=0 letter="R" +char id=83 x=331 y=110 width=17 height=21 xoffset=1 yoffset=6 xadvance=16 page=0 chnl=0 letter="S" +char id=84 x=312 y=110 width=17 height=21 xoffset=1 yoffset=6 xadvance=16 page=0 chnl=0 letter="T" +char id=85 x=293 y=110 width=17 height=21 xoffset=1 yoffset=6 xadvance=17 page=0 chnl=0 letter="U" +char id=86 x=174 y=110 width=18 height=21 xoffset=1 yoffset=6 xadvance=17 page=0 chnl=0 letter="V" +char id=87 x=127 y=156 width=25 height=20 xoffset=1 yoffset=7 xadvance=24 page=0 chnl=0 letter="W" +char id=88 x=234 y=110 width=18 height=21 xoffset=1 yoffset=6 xadvance=17 page=0 chnl=0 letter="X" +char id=89 x=254 y=110 width=18 height=21 xoffset=1 yoffset=6 xadvance=17 page=0 chnl=0 letter="Y" +char id=90 x=464 y=110 width=16 height=21 xoffset=1 yoffset=6 xadvance=16 page=0 chnl=0 letter="Z" +char id=91 x=37 y=31 width=7 height=25 xoffset=2 yoffset=7 xadvance=7 page=0 chnl=0 letter="[" +char id=92 x=109 y=156 width=9 height=21 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=0 letter="\" +char id=93 x=46 y=31 width=7 height=25 xoffset=0 yoffset=7 xadvance=7 page=0 chnl=0 letter="]" +char id=94 x=317 y=179 width=13 height=12 xoffset=1 yoffset=7 xadvance=12 page=0 chnl=0 letter="^" +char id=95 x=27 y=197 width=17 height=4 xoffset=-0 yoffset=28 xadvance=14 page=0 chnl=0 letter="_" +char id=96 x=502 y=179 width=6 height=6 xoffset=2 yoffset=6 xadvance=8 page=0 chnl=0 letter="`" +char id=97 x=53 y=179 width=15 height=16 xoffset=1 yoffset=11 xadvance=14 page=0 chnl=0 letter="a" +char id=98 x=332 y=133 width=14 height=21 xoffset=1 yoffset=6 xadvance=13 page=0 chnl=0 letter="b" +char id=99 x=87 y=179 width=14 height=16 xoffset=1 yoffset=12 xadvance=12 page=0 chnl=0 letter="c" +char id=100 x=364 y=133 width=14 height=21 xoffset=1 yoffset=6 xadvance=13 page=0 chnl=0 letter="d" +char id=101 x=36 y=179 width=15 height=16 xoffset=0 yoffset=11 xadvance=14 page=0 chnl=0 letter="e" +char id=102 x=75 y=156 width=10 height=21 xoffset=0 yoffset=6 xadvance=8 page=0 chnl=0 letter="f" +char id=103 x=220 y=133 width=14 height=21 xoffset=1 yoffset=11 xadvance=13 page=0 chnl=0 letter="g" +char id=104 x=277 y=156 width=13 height=20 xoffset=1 yoffset=7 xadvance=13 page=0 chnl=0 letter="h" +char id=105 x=358 y=156 width=4 height=20 xoffset=2 yoffset=7 xadvance=6 page=0 chnl=0 letter="i" +char id=106 x=398 y=2 width=8 height=26 xoffset=0 yoffset=6 xadvance=7 page=0 chnl=0 letter="j" +char id=107 x=17 y=156 width=13 height=21 xoffset=1 yoffset=6 xadvance=12 page=0 chnl=0 letter="k" +char id=108 x=346 y=156 width=4 height=20 xoffset=2 yoffset=7 xadvance=6 page=0 chnl=0 letter="l" +char id=109 x=437 y=156 width=20 height=16 xoffset=1 yoffset=11 xadvance=20 page=0 chnl=0 letter="m" +char id=110 x=103 y=179 width=14 height=16 xoffset=1 yoffset=11 xadvance=13 page=0 chnl=0 letter="n" +char id=111 x=19 y=179 width=15 height=16 xoffset=1 yoffset=11 xadvance=14 page=0 chnl=0 letter="o" +char id=112 x=236 y=133 width=14 height=21 xoffset=1 yoffset=11 xadvance=13 page=0 chnl=0 letter="p" +char id=113 x=70 y=133 width=15 height=21 xoffset=0 yoffset=11 xadvance=14 page=0 chnl=0 letter="q" +char id=114 x=165 y=179 width=10 height=16 xoffset=1 yoffset=11 xadvance=9 page=0 chnl=0 letter="r" +char id=115 x=135 y=179 width=13 height=16 xoffset=1 yoffset=11 xadvance=12 page=0 chnl=0 letter="s" +char id=116 x=87 y=156 width=9 height=21 xoffset=0 yoffset=6 xadvance=8 page=0 chnl=0 letter="t" +char id=117 x=150 y=179 width=13 height=16 xoffset=1 yoffset=11 xadvance=13 page=0 chnl=0 letter="u" +char id=118 x=70 y=179 width=15 height=16 xoffset=0 yoffset=11 xadvance=13 page=0 chnl=0 letter="v" +char id=119 x=414 y=156 width=21 height=16 xoffset=0 yoffset=11 xadvance=19 page=0 chnl=0 letter="w" +char id=120 x=184 y=179 width=14 height=15 xoffset=1 yoffset=12 xadvance=13 page=0 chnl=0 letter="x" +char id=121 x=36 y=133 width=15 height=21 xoffset=0 yoffset=11 xadvance=13 page=0 chnl=0 letter="y" +char id=122 x=119 y=179 width=14 height=16 xoffset=1 yoffset=11 xadvance=13 page=0 chnl=0 letter="z" +char id=123 x=354 y=2 width=10 height=26 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=0 letter="{" +char id=124 x=408 y=2 width=4 height=26 xoffset=2 yoffset=6 xadvance=7 page=0 chnl=0 letter="|" +char id=125 x=366 y=2 width=10 height=26 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=0 letter="}" +char id=126 x=475 y=179 width=15 height=6 xoffset=1 yoffset=14 xadvance=15 page=0 chnl=0 letter="~" +char id=128 x=132 y=110 width=19 height=21 xoffset=-0 yoffset=7 xadvance=17 page=0 chnl=0 letter="€" +char id=161 x=120 y=156 width=5 height=21 xoffset=3 yoffset=11 xadvance=8 page=0 chnl=0 letter="¡" +char id=162 x=2 y=156 width=13 height=21 xoffset=3 yoffset=6 xadvance=16 page=0 chnl=0 letter="¢" +char id=163 x=486 y=133 width=13 height=21 xoffset=3 yoffset=6 xadvance=16 page=0 chnl=0 letter="£" +char id=164 x=154 y=156 width=20 height=20 xoffset=4 yoffset=6 xadvance=25 page=0 chnl=0 letter="¤" +char id=165 x=61 y=156 width=12 height=21 xoffset=1 yoffset=6 xadvance=13 page=0 chnl=0 letter="¥" +char id=166 x=55 y=31 width=4 height=25 xoffset=4 yoffset=6 xadvance=9 page=0 chnl=0 letter="¦" +char id=167 x=168 y=84 width=13 height=24 xoffset=7 yoffset=4 xadvance=25 page=0 chnl=0 letter="§" +char id=168 x=2 y=197 width=9 height=5 xoffset=9 yoffset=3 xadvance=25 page=0 chnl=0 letter="¨" +char id=169 x=418 y=84 width=21 height=21 xoffset=1 yoffset=6 xadvance=21 page=0 chnl=0 letter="©" +char id=170 x=345 y=179 width=11 height=12 xoffset=2 yoffset=5 xadvance=12 page=0 chnl=0 letter="ª" +char id=171 x=287 y=179 width=13 height=13 xoffset=1 yoffset=13 xadvance=13 page=0 chnl=0 letter="«" +char id=172 x=358 y=179 width=17 height=10 xoffset=3 yoffset=13 xadvance=20 page=0 chnl=0 letter="¬" +char id=173 x=46 y=197 width=13 height=4 xoffset=2 yoffset=17 xadvance=14 page=0 chnl=0 letter="­" +char id=174 x=441 y=84 width=21 height=21 xoffset=1 yoffset=6 xadvance=21 page=0 chnl=0 letter="®" +char id=175 x=61 y=197 width=13 height=4 xoffset=1 yoffset=5 xadvance=13 page=0 chnl=0 letter="¯" +char id=176 x=424 y=179 width=8 height=8 xoffset=3 yoffset=4 xadvance=25 page=0 chnl=0 letter="°" +char id=177 x=370 y=156 width=19 height=19 xoffset=4 yoffset=7 xadvance=25 page=0 chnl=0 letter="±" +char id=178 x=259 y=179 width=9 height=14 xoffset=2 yoffset=2 xadvance=11 page=0 chnl=0 letter="²" +char id=179 x=248 y=179 width=9 height=14 xoffset=2 yoffset=2 xadvance=11 page=0 chnl=0 letter="³" +char id=180 x=492 y=179 width=8 height=6 xoffset=5 yoffset=5 xadvance=15 page=0 chnl=0 letter="´" +char id=181 x=471 y=133 width=13 height=21 xoffset=2 yoffset=11 xadvance=16 page=0 chnl=0 letter="µ" +char id=182 x=183 y=84 width=12 height=24 xoffset=3 yoffset=7 xadvance=16 page=0 chnl=0 letter="¶" +char id=183 x=20 y=197 width=5 height=5 xoffset=11 yoffset=14 xadvance=25 page=0 chnl=0 letter="·" +char id=184 x=434 y=179 width=7 height=8 xoffset=6 yoffset=24 xadvance=15 page=0 chnl=0 letter="¸" +char id=185 x=270 y=179 width=9 height=14 xoffset=2 yoffset=2 xadvance=11 page=0 chnl=0 letter="¹" +char id=186 x=332 y=179 width=11 height=12 xoffset=2 yoffset=5 xadvance=12 page=0 chnl=0 letter="º" +char id=187 x=302 y=179 width=13 height=13 xoffset=1 yoffset=13 xadvance=13 page=0 chnl=0 letter="»" +char id=188 x=464 y=84 width=20 height=21 xoffset=1 yoffset=6 xadvance=20 page=0 chnl=0 letter="¼" +char id=189 x=486 y=84 width=20 height=21 xoffset=1 yoffset=6 xadvance=20 page=0 chnl=0 letter="½" +char id=190 x=2 y=110 width=20 height=21 xoffset=1 yoffset=6 xadvance=20 page=0 chnl=0 letter="¾" +char id=191 x=47 y=156 width=12 height=21 xoffset=0 yoffset=11 xadvance=11 page=0 chnl=0 letter="¿" +char id=192 x=161 y=2 width=19 height=26 xoffset=0 yoffset=1 xadvance=17 page=0 chnl=0 letter="À" +char id=193 x=140 y=2 width=19 height=26 xoffset=0 yoffset=1 xadvance=17 page=0 chnl=0 letter="Á" +char id=194 x=119 y=2 width=19 height=26 xoffset=0 yoffset=1 xadvance=17 page=0 chnl=0 letter="Â" +char id=195 x=461 y=2 width=19 height=25 xoffset=0 yoffset=2 xadvance=17 page=0 chnl=0 letter="Ã" +char id=196 x=100 y=84 width=19 height=24 xoffset=0 yoffset=3 xadvance=17 page=0 chnl=0 letter="Ä" +char id=197 x=98 y=2 width=19 height=26 xoffset=0 yoffset=1 xadvance=17 page=0 chnl=0 letter="Å" +char id=198 x=392 y=84 width=24 height=21 xoffset=0 yoffset=6 xadvance=23 page=0 chnl=0 letter="Æ" +char id=199 x=202 y=2 width=17 height=26 xoffset=1 yoffset=6 xadvance=17 page=0 chnl=0 letter="Ç" +char id=200 x=287 y=2 width=13 height=26 xoffset=2 yoffset=1 xadvance=14 page=0 chnl=0 letter="È" +char id=201 x=272 y=2 width=13 height=26 xoffset=2 yoffset=1 xadvance=14 page=0 chnl=0 letter="É" +char id=202 x=302 y=2 width=13 height=26 xoffset=2 yoffset=1 xadvance=14 page=0 chnl=0 letter="Ê" +char id=203 x=153 y=84 width=13 height=24 xoffset=2 yoffset=3 xadvance=14 page=0 chnl=0 letter="Ë" +char id=204 x=388 y=2 width=8 height=26 xoffset=-0 yoffset=1 xadvance=7 page=0 chnl=0 letter="Ì" +char id=205 x=378 y=2 width=8 height=26 xoffset=2 yoffset=1 xadvance=7 page=0 chnl=0 letter="Í" +char id=206 x=317 y=2 width=11 height=26 xoffset=-1 yoffset=1 xadvance=7 page=0 chnl=0 letter="Î" +char id=207 x=197 y=84 width=9 height=24 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=0 letter="Ï" +char id=208 x=46 y=110 width=20 height=21 xoffset=-0 yoffset=6 xadvance=19 page=0 chnl=0 letter="Ð" +char id=209 x=2 y=31 width=16 height=25 xoffset=2 yoffset=2 xadvance=18 page=0 chnl=0 letter="Ñ" +char id=210 x=56 y=2 width=19 height=26 xoffset=1 yoffset=1 xadvance=19 page=0 chnl=0 letter="Ò" +char id=211 x=77 y=2 width=19 height=26 xoffset=1 yoffset=1 xadvance=19 page=0 chnl=0 letter="Ó" +char id=212 x=35 y=2 width=19 height=26 xoffset=1 yoffset=1 xadvance=19 page=0 chnl=0 letter="Ô" +char id=213 x=440 y=2 width=19 height=25 xoffset=1 yoffset=2 xadvance=19 page=0 chnl=0 letter="Õ" +char id=214 x=482 y=2 width=19 height=25 xoffset=1 yoffset=2 xadvance=19 page=0 chnl=0 letter="Ö" +char id=215 x=480 y=156 width=16 height=16 xoffset=6 yoffset=8 xadvance=25 page=0 chnl=0 letter="×" +char id=216 x=90 y=110 width=19 height=21 xoffset=1 yoffset=6 xadvance=19 page=0 chnl=0 letter="Ø" +char id=217 x=238 y=2 width=15 height=26 xoffset=2 yoffset=1 xadvance=17 page=0 chnl=0 letter="Ù" +char id=218 x=255 y=2 width=15 height=26 xoffset=2 yoffset=1 xadvance=17 page=0 chnl=0 letter="Ú" +char id=219 x=221 y=2 width=15 height=26 xoffset=2 yoffset=1 xadvance=17 page=0 chnl=0 letter="Û" +char id=220 x=20 y=31 width=15 height=25 xoffset=2 yoffset=2 xadvance=17 page=0 chnl=0 letter="Ü" +char id=221 x=182 y=2 width=18 height=26 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=0 letter="Ý" +char id=222 x=380 y=133 width=14 height=21 xoffset=2 yoffset=6 xadvance=14 page=0 chnl=0 letter="Þ" +char id=223 x=348 y=84 width=14 height=22 xoffset=2 yoffset=5 xadvance=15 page=0 chnl=0 letter="ß" +char id=224 x=261 y=156 width=14 height=20 xoffset=6 yoffset=7 xadvance=25 page=0 chnl=0 letter="à" +char id=225 x=245 y=156 width=14 height=20 xoffset=6 yoffset=7 xadvance=25 page=0 chnl=0 letter="á" +char id=226 x=332 y=84 width=14 height=22 xoffset=1 yoffset=5 xadvance=14 page=0 chnl=0 letter="â" +char id=227 x=172 y=133 width=14 height=21 xoffset=1 yoffset=6 xadvance=14 page=0 chnl=0 letter="ã" +char id=228 x=252 y=133 width=14 height=21 xoffset=1 yoffset=6 xadvance=14 page=0 chnl=0 letter="ä" +char id=229 x=121 y=84 width=14 height=24 xoffset=1 yoffset=3 xadvance=14 page=0 chnl=0 letter="å" +char id=230 x=391 y=156 width=21 height=16 xoffset=1 yoffset=11 xadvance=21 page=0 chnl=0 letter="æ" +char id=231 x=396 y=133 width=13 height=21 xoffset=1 yoffset=11 xadvance=13 page=0 chnl=0 letter="ç" +char id=232 x=138 y=133 width=15 height=21 xoffset=6 yoffset=6 xadvance=25 page=0 chnl=0 letter="è" +char id=233 x=121 y=133 width=15 height=21 xoffset=6 yoffset=6 xadvance=25 page=0 chnl=0 letter="é" +char id=234 x=155 y=133 width=15 height=21 xoffset=6 yoffset=6 xadvance=25 page=0 chnl=0 letter="ê" +char id=235 x=456 y=133 width=13 height=21 xoffset=1 yoffset=6 xadvance=14 page=0 chnl=0 letter="ë" +char id=236 x=338 y=156 width=6 height=20 xoffset=11 yoffset=7 xadvance=25 page=0 chnl=0 letter="ì" +char id=237 x=330 y=156 width=6 height=20 xoffset=11 yoffset=7 xadvance=25 page=0 chnl=0 letter="í" +char id=238 x=379 y=84 width=11 height=22 xoffset=-1 yoffset=5 xadvance=7 page=0 chnl=0 letter="î" +char id=239 x=319 y=156 width=9 height=20 xoffset=0 yoffset=7 xadvance=7 page=0 chnl=0 letter="ï" +char id=240 x=254 y=84 width=15 height=23 xoffset=1 yoffset=4 xadvance=15 page=0 chnl=0 letter="ð" +char id=241 x=411 y=133 width=13 height=21 xoffset=2 yoffset=6 xadvance=16 page=0 chnl=0 letter="ñ" +char id=242 x=228 y=156 width=15 height=20 xoffset=6 yoffset=7 xadvance=25 page=0 chnl=0 letter="ò" +char id=243 x=211 y=156 width=15 height=20 xoffset=6 yoffset=7 xadvance=25 page=0 chnl=0 letter="ó" +char id=244 x=315 y=84 width=15 height=22 xoffset=1 yoffset=5 xadvance=15 page=0 chnl=0 letter="ô" +char id=245 x=2 y=133 width=15 height=21 xoffset=1 yoffset=6 xadvance=15 page=0 chnl=0 letter="õ" +char id=246 x=53 y=133 width=15 height=21 xoffset=1 yoffset=6 xadvance=15 page=0 chnl=0 letter="ö" +char id=247 x=459 y=156 width=19 height=16 xoffset=4 yoffset=8 xadvance=25 page=0 chnl=0 letter="÷" +char id=248 x=2 y=179 width=15 height=16 xoffset=1 yoffset=11 xadvance=15 page=0 chnl=0 letter="ø" +char id=249 x=441 y=133 width=13 height=21 xoffset=7 yoffset=6 xadvance=25 page=0 chnl=0 letter="ù" +char id=250 x=426 y=133 width=13 height=21 xoffset=7 yoffset=6 xadvance=25 page=0 chnl=0 letter="ú" +char id=251 x=364 y=84 width=13 height=22 xoffset=2 yoffset=5 xadvance=16 page=0 chnl=0 letter="û" +char id=252 x=292 y=156 width=13 height=20 xoffset=7 yoffset=7 xadvance=25 page=0 chnl=0 letter="ü" +char id=253 x=2 y=2 width=15 height=27 xoffset=0 yoffset=5 xadvance=13 page=0 chnl=0 letter="ý" +char id=254 x=19 y=2 width=14 height=27 xoffset=2 yoffset=5 xadvance=16 page=0 chnl=0 letter="þ" +char id=19968 x=450 y=179 width=23 height=6 xoffset=2 yoffset=12 xadvance=25 page=0 chnl=0 letter="一" +char id=19979 x=314 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="下" +char id=20010 x=165 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="个" +char id=20154 x=54 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="人" +char id=20572 x=373 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="停" +char id=20648 x=158 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="储" +char id=20837 x=243 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="入" +char id=20877 x=262 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="再" +char id=20986 x=76 y=84 width=22 height=24 xoffset=3 yoffset=4 xadvance=25 page=0 chnl=0 letter="出" +char id=20987 x=210 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="击" +char id=21462 x=113 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="取" +char id=22256 x=52 y=84 width=22 height=24 xoffset=3 yoffset=4 xadvance=25 page=0 chnl=0 letter="困" +char id=23384 x=418 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="存" +char id=23433 x=236 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="安" +char id=24065 x=27 y=84 width=23 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="币" +char id=25353 x=2 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="按" +char id=25915 x=139 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="攻" +char id=26032 x=106 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="新" +char id=26085 x=208 y=84 width=21 height=23 xoffset=3 yoffset=5 xadvance=25 page=0 chnl=0 letter="日" +char id=26222 x=451 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="普" +char id=26399 x=470 y=58 width=23 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="期" +char id=26696 x=425 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="案" +char id=26723 x=87 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="档" +char id=27425 x=392 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="次" +char id=27490 x=340 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="止" +char id=28040 x=2 y=84 width=23 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="消" +char id=30830 x=269 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="确" +char id=32622 x=80 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="置" +char id=35013 x=477 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="装" +char id=35748 x=347 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="认" +char id=35774 x=61 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="设" +char id=36291 x=191 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="跃" +char id=36339 x=28 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="跳" +char id=36466 x=399 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="蹲" +char id=36807 x=295 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="过" +char id=36827 x=366 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="进" +char id=36864 x=184 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="退" +char id=36890 x=132 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="通" +char id=37325 x=288 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="重" +char id=37329 x=444 y=58 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="金" +char id=38190 x=414 y=2 width=24 height=25 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="键" +char id=38590 x=321 y=31 width=24 height=24 xoffset=2 yoffset=4 xadvance=25 page=0 chnl=0 letter="难" diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultBMFont.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultBMFont.png new file mode 100644 index 0000000000..52f5a52b21 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultBMFont.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultMap.png b/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultMap.png new file mode 100644 index 0000000000..9595c50672 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultMap.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultMap.tmx b/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultMap.tmx new file mode 100644 index 0000000000..ea994eea34 --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultMap.tmx @@ -0,0 +1,11 @@ + + + + + + + + eJxjZGBgYIJiRiAGAABMAAc= + + + diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultParticle.plist b/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultParticle.plist new file mode 100644 index 0000000000..ee1001e15c --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/2.1/Default/defaultParticle.plist @@ -0,0 +1,110 @@ + + + + + angle + 360 + angleVariance + 360 + blendFuncDestination + 1 + blendFuncSource + 775 + duration + -1 + emitterType + 0.0 + finishColorAlpha + 0.8399999737739563 + finishColorBlue + 0.0771484375 + finishColorGreen + 0.63492840528488159 + finishColorRed + 0.68082684278488159 + finishColorVarianceAlpha + 0.74000000953674316 + finishColorVarianceBlue + 0.98000001907348633 + finishColorVarianceGreen + 0.98000001907348633 + finishColorVarianceRed + 0.41999998688697815 + finishParticleSize + 30.319999694824219 + finishParticleSizeVariance + 0.0 + gravityx + 0.25 + gravityy + 0.86000001430511475 + maxParticles + 200 + maxRadius + 100 + maxRadiusVariance + 0.0 + minRadius + 0.0 + particleLifespan + 0.20000000298023224 + particleLifespanVariance + 0.5 + radialAccelVariance + 65.790000915527344 + radialAcceleration + -671.04998779296875 + rotatePerSecond + 0.0 + rotatePerSecondVariance + 0.0 + rotationEnd + -47.369998931884766 + rotationEndVariance + -142.11000061035156 + rotationStart + -47.369998931884766 + rotationStartVariance + 0.0 + sourcePositionVariancex + 7 + sourcePositionVariancey + 7 + sourcePositionx + 373.72775268554688 + sourcePositiony + 478.40472412109375 + speed + 0.0 + speedVariance + 190.78999328613281 + startColorAlpha + 0.63999998569488525 + startColorBlue + 0.3375650942325592 + startColorGreen + 0.78792315721511841 + startColorRed + 0.794921875 + startColorVarianceAlpha + 0.77999997138977051 + startColorVarianceBlue + 0.68000000715255737 + startColorVarianceGreen + 1 + startColorVarianceRed + 0.89999997615814209 + startParticleSize + 3.369999885559082 + startParticleSizeVariance + 50 + tangentialAccelVariance + 65.790000915527344 + tangentialAcceleration + -92.110000610351562 + textureFileName + particleTexture.png + textureImageData + H4sIAAAAAAAAAwGLDnTxiVBORw0KGgoAAAANSUhEUgAAAB8AAAAfCAYAAAAfrhY5AAAKQWlDQ1BJQ0MgUHJvZmlsZQAAeAGdlndUU9kWh8+9N73QEiIgJfQaegkg0jtIFQRRiUmAUAKGhCZ2RAVGFBEpVmRUwAFHhyJjRRQLg4Ji1wnyEFDGwVFEReXdjGsJ7601896a/cdZ39nnt9fZZ+9917oAUPyCBMJ0WAGANKFYFO7rwVwSE8vE9wIYEAEOWAHA4WZmBEf4RALU/L09mZmoSMaz9u4ugGS72yy/UCZz1v9/kSI3QyQGAApF1TY8fiYX5QKUU7PFGTL/BMr0lSkyhjEyFqEJoqwi48SvbPan5iu7yZiXJuShGlnOGbw0noy7UN6aJeGjjAShXJgl4GejfAdlvVRJmgDl9yjT0/icTAAwFJlfzOcmoWyJMkUUGe6J8gIACJTEObxyDov5OWieAHimZ+SKBIlJYqYR15hp5ejIZvrxs1P5YjErlMNN4Yh4TM/0tAyOMBeAr2+WRQElWW2ZaJHtrRzt7VnW5mj5v9nfHn5T/T3IevtV8Sbsz55BjJ5Z32zsrC+9FgD2JFqbHbO+lVUAtG0GQOXhrE/vIADyBQC03pzzHoZsXpLE4gwnC4vs7GxzAZ9rLivoN/ufgm/Kv4Y595nL7vtWO6YXP4EjSRUzZUXlpqemS0TMzAwOl89k/fcQ/+PAOWnNycMsnJ/AF/GF6FVR6JQJhIlou4U8gViQLmQKhH/V4X8YNicHGX6daxRodV8AfYU5ULhJB8hvPQBDIwMkbj96An3rWxAxCsi+vGitka9zjzJ6/uf6Hwtcim7hTEEiU+b2DI9kciWiLBmj34RswQISkAd0oAo0gS4wAixgDRyAM3AD3iAAhIBIEAOWAy5IAmlABLJBPtgACkEx2AF2g2pwANSBetAEToI2cAZcBFfADXALDIBHQAqGwUswAd6BaQiC8BAVokGqkBakD5lC1hAbWgh5Q0FQOBQDxUOJkBCSQPnQJqgYKoOqoUNQPfQjdBq6CF2D+qAH0CA0Bv0BfYQRmALTYQ3YALaA2bA7HAhHwsvgRHgVnAcXwNvhSrgWPg63whfhG/AALIVfwpMIQMgIA9FGWAgb8URCkFgkAREha5EipAKpRZqQDqQbuY1IkXHkAwaHoWGYGBbGGeOHWYzhYlZh1mJKMNWYY5hWTBfmNmYQM4H5gqVi1bGmWCesP3YJNhGbjS3EVmCPYFuwl7ED2GHsOxwOx8AZ4hxwfrgYXDJuNa4Etw/XjLuA68MN4SbxeLwq3hTvgg/Bc/BifCG+Cn8cfx7fjx/GvyeQCVoEa4IPIZYgJGwkVBAaCOcI/YQRwjRRgahPdCKGEHnEXGIpsY7YQbxJHCZOkxRJhiQXUiQpmbSBVElqIl0mPSa9IZPJOmRHchhZQF5PriSfIF8lD5I/UJQoJhRPShxFQtlOOUq5QHlAeUOlUg2obtRYqpi6nVpPvUR9Sn0vR5Mzl/OX48mtk6uRa5Xrl3slT5TXl3eXXy6fJ18hf0r+pvy4AlHBQMFTgaOwVqFG4bTCPYVJRZqilWKIYppiiWKD4jXFUSW8koGStxJPqUDpsNIlpSEaQtOledK4tE20Otpl2jAdRzek+9OT6cX0H+i99AllJWVb5SjlHOUa5bPKUgbCMGD4M1IZpYyTjLuMj/M05rnP48/bNq9pXv+8KZX5Km4qfJUilWaVAZWPqkxVb9UU1Z2qbapP1DBqJmphatlq+9Uuq43Pp893ns+dXzT/5PyH6rC6iXq4+mr1w+o96pMamhq+GhkaVRqXNMY1GZpumsma5ZrnNMe0aFoLtQRa5VrntV4wlZnuzFRmJbOLOaGtru2nLdE+pN2rPa1jqLNYZ6NOs84TXZIuWzdBt1y3U3dCT0svWC9fr1HvoT5Rn62fpL9Hv1t/ysDQINpgi0GbwaihiqG/YZ5ho+FjI6qRq9Eqo1qjO8Y4Y7ZxivE+41smsImdSZJJjclNU9jU3lRgus+0zwxr5mgmNKs1u8eisNxZWaxG1qA5wzzIfKN5m/krCz2LWIudFt0WXyztLFMt6ywfWSlZBVhttOqw+sPaxJprXWN9x4Zq42Ozzqbd5rWtqS3fdr/tfTuaXbDdFrtOu8/2DvYi+yb7MQc9h3iHvQ732HR2KLuEfdUR6+jhuM7xjOMHJ3snsdNJp9+dWc4pzg3OowsMF/AX1C0YctFx4bgccpEuZC6MX3hwodRV25XjWuv6zE3Xjed2xG3E3dg92f24+ysPSw+RR4vHlKeT5xrPC16Il69XkVevt5L3Yu9q76c+Oj6JPo0+E752vqt9L/hh/QL9dvrd89fw5/rX+08EOASsCegKpARGBFYHPgsyCRIFdQTDwQHBu4IfL9JfJFzUFgJC/EN2hTwJNQxdFfpzGC4sNKwm7Hm4VXh+eHcELWJFREPEu0iPyNLIR4uNFksWd0bJR8VF1UdNRXtFl0VLl1gsWbPkRoxajCCmPRYfGxV7JHZyqffS3UuH4+ziCuPuLjNclrPs2nK15anLz66QX8FZcSoeGx8d3xD/iRPCqeVMrvRfuXflBNeTu4f7kufGK+eN8V34ZfyRBJeEsoTRRJfEXYljSa5JFUnjAk9BteB1sl/ygeSplJCUoykzqdGpzWmEtPi000IlYYqwK10zPSe9L8M0ozBDuspp1e5VE6JA0ZFMKHNZZruYjv5M9UiMJJslg1kLs2qy3mdHZZ/KUcwR5vTkmuRuyx3J88n7fjVmNXd1Z752/ob8wTXuaw6thdauXNu5Tnddwbrh9b7rj20gbUjZ8MtGy41lG99uit7UUaBRsL5gaLPv5sZCuUJR4b0tzlsObMVsFWzt3WazrWrblyJe0fViy+KK4k8l3JLr31l9V/ndzPaE7b2l9qX7d+B2CHfc3em681iZYlle2dCu4F2t5czyovK3u1fsvlZhW3FgD2mPZI+0MqiyvUqvakfVp+qk6oEaj5rmvep7t+2d2sfb17/fbX/TAY0DxQc+HhQcvH/I91BrrUFtxWHc4azDz+ui6rq/Z39ff0TtSPGRz0eFR6XHwo911TvU1zeoN5Q2wo2SxrHjccdv/eD1Q3sTq+lQM6O5+AQ4ITnx4sf4H++eDDzZeYp9qukn/Z/2ttBailqh1tzWibakNml7THvf6YDTnR3OHS0/m/989Iz2mZqzymdLz5HOFZybOZ93fvJCxoXxi4kXhzpXdD66tOTSna6wrt7LgZevXvG5cqnbvfv8VZerZ645XTt9nX297Yb9jdYeu56WX+x+aem172296XCz/ZbjrY6+BX3n+l37L972un3ljv+dGwOLBvruLr57/17cPel93v3RB6kPXj/Mejj9aP1j7OOiJwpPKp6qP6391fjXZqm99Oyg12DPs4hnj4a4Qy//lfmvT8MFz6nPK0a0RupHrUfPjPmM3Xqx9MXwy4yX0+OFvyn+tveV0auffnf7vWdiycTwa9HrmT9K3qi+OfrW9m3nZOjk03dp76anit6rvj/2gf2h+2P0x5Hp7E/4T5WfjT93fAn88ngmbWbm3/eE8/ul8iYiAAAEBUlEQVRIDY3UT2+bRRAG8LHTxqEpNCGq+KMKcQGJb8GVG5+YW64cEEUcerJUUQlImjZukrqx2d9rP2YJbtKRJjM7O/s8z+y+zmj543f1ATZe9yxaTD5a15Y3zuv5IAvQbc16QnR/ne+0iFSd64m3dLA7sW9ryB4Sbi3ea84IUBNZYvZX1Vv+vq8xxAEPuf5M63rlEWdNgKhPdF7catvIAYRMnmtNDaBaniDg71rter3XwpBHmP702RtsGzkAdcSZXEze0s0VyxEAjkg5IdbMObVEtcF68mwizcQRkXUvKODEsnlz+2ImJSJGpLo4WE9OncMhcq0E6YkIUU0PEDnyTIZMXS1kCCNmK7kioMTd9RoZETwiRPsxRKblbDNZy4kKIfx+bwC0yWwATnMIxcnakcr1AeOmvVx7zsIiyn5uVO1/5Cnkuh1AaC0i3Gv+YB3lD5vrY2+bv2k+aw4LGctzJNdvP3HZT0A172sRYFrkSA+aE7A7dNdo3uDOGuW4lkuE3G3AkYewf4JhYA0SLmcEIKWwJ0f4qMajw/pi/8v65uDb+njyUf11Oa1nL5/Wq6uqq3fe3RO0xSDAeYaYENixMcJMTEBI1ZDH1fXu1dHeUX3/5If66tOv69H+pM4vZ3X4x6SOnx838rPW45YI8BzOI4YtdyMZbgHQJvA0iKxXmStb1Of7h3X04LN6fDCuTx7u1ORipx6/fFKLZXuG0U67eiS9+ORwgzkIymQWsTRbR4j91W/44rp9XKPXbWdc8/miZhdV07PndX71phEHIwKyhsk1bLjyzpps8DSllg9o9VW/mL2oZyc/t7ZF3b+3W9PT3+qXP5824qZi+K3nI+vxgkVU6sM7WigyOWUciOcwMWIf0axmb0/qp+lx/fr37617WacXp3U+P2l758395PT58GBlkGCqsWF6k4cQEUMmd1AERNyKfNnql9dXNX112mrOqr9ujpwTyuHEW7rhcQbe8MFlQ1GzfywIM7VGa9dKENXAM5U9E9snxJcOx81xlohjY/2bK+Z6QowAkUNyBgiJtRwRAf3vOxPDs9eTyod1yAFlatG0IWvpsAYOzD5xAKwjQJ1Qa4RiLH3iBjfkKYY4aqNYTK8eBiSg9p3JOcT2spbrGd66xcECaAGsJwMQlTkMzJm+HgF9TB6B7chGrHywntyBCIhyTXJ9UW5yfelV5+piiFs6nLVW1/8f68ltaGJiPrpE4P3U+gDHkhObWxO3Ejt0k1wtAgKWmjUnRsz0yUPkfPzm7bStf20beXaBxjKJmpwFOB9R3x9BmToDrU6u/zp4m/UE+jJRciT9W6vHQpiY+ibeNrmmHOxjJidcncDU0tdKd9td5EHor1QNYWo9YZ/n7HvjP//hqoX9yBbEAAAAAElFTkSuQmCCAXYDSYsOAAA= + + diff --git a/samples/js-tests/res/cocosui/CCS/2.1/FNT/Heiti18.fnt b/samples/js-tests/res/cocosui/CCS/2.1/FNT/Heiti18.fnt new file mode 100644 index 0000000000..e47d47e994 --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/2.1/FNT/Heiti18.fnt @@ -0,0 +1,99 @@ +info face="STHeitiSC-Light" size=18 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=2,2 +common lineHeight=18 base=15 scaleW=256 scaleH=128 pages=1 packed=0 +page id=0 file="Heiti18.png" +chars count=95 +char id=41 x=2 y=2 width=8 height=22 xoffset=1 yoffset=-2 xadvance=7 page=0 chnl=0 letter=")" +char id=40 x=12 y=2 width=8 height=22 xoffset=2 yoffset=-2 xadvance=7 page=0 chnl=0 letter="(" +char id=124 x=22 y=2 width=6 height=22 xoffset=4 yoffset=-2 xadvance=9 page=0 chnl=0 letter="|" +char id=36 x=30 y=2 width=14 height=21 xoffset=0 yoffset=-2 xadvance=10 page=0 chnl=0 letter="$" +char id=123 x=46 y=2 width=10 height=21 xoffset=1 yoffset=-1 xadvance=6 page=0 chnl=0 letter="{" +char id=125 x=58 y=2 width=10 height=21 xoffset=1 yoffset=-1 xadvance=6 page=0 chnl=0 letter="}" +char id=91 x=70 y=2 width=7 height=21 xoffset=3 yoffset=-1 xadvance=6 page=0 chnl=0 letter="[" +char id=93 x=79 y=2 width=7 height=21 xoffset=1 yoffset=-1 xadvance=6 page=0 chnl=0 letter="]" +char id=106 x=88 y=2 width=7 height=21 xoffset=0 yoffset=-1 xadvance=4 page=0 chnl=0 letter="j" +char id=47 x=97 y=2 width=11 height=20 xoffset=1 yoffset=-1 xadvance=8 page=0 chnl=0 letter="/" +char id=37 x=110 y=2 width=18 height=19 xoffset=0 yoffset=-1 xadvance=14 page=0 chnl=0 letter="%" +char id=64 x=130 y=2 width=18 height=19 xoffset=1 yoffset=-1 xadvance=16 page=0 chnl=0 letter="@" +char id=81 x=150 y=2 width=18 height=19 xoffset=1 yoffset=-1 xadvance=16 page=0 chnl=0 letter="Q" +char id=79 x=170 y=2 width=18 height=19 xoffset=1 yoffset=-1 xadvance=16 page=0 chnl=0 letter="O" +char id=71 x=190 y=2 width=18 height=19 xoffset=1 yoffset=-1 xadvance=16 page=0 chnl=0 letter="G" +char id=67 x=210 y=2 width=17 height=19 xoffset=1 yoffset=-1 xadvance=15 page=0 chnl=0 letter="C" +char id=100 x=229 y=2 width=14 height=19 xoffset=1 yoffset=-1 xadvance=12 page=0 chnl=0 letter="d" +char id=92 x=2 y=26 width=14 height=19 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=0 letter="\" +char id=98 x=18 y=26 width=14 height=19 xoffset=1 yoffset=-1 xadvance=12 page=0 chnl=0 letter="b" +char id=56 x=34 y=26 width=14 height=19 xoffset=1 yoffset=-1 xadvance=10 page=0 chnl=0 letter="8" +char id=51 x=50 y=26 width=13 height=19 xoffset=1 yoffset=-1 xadvance=10 page=0 chnl=0 letter="3" +char id=48 x=65 y=26 width=13 height=19 xoffset=1 yoffset=-1 xadvance=10 page=0 chnl=0 letter="0" +char id=53 x=80 y=26 width=13 height=19 xoffset=1 yoffset=-1 xadvance=10 page=0 chnl=0 letter="5" +char id=57 x=95 y=26 width=13 height=19 xoffset=1 yoffset=-1 xadvance=10 page=0 chnl=0 letter="9" +char id=83 x=110 y=26 width=12 height=19 xoffset=0 yoffset=-1 xadvance=9 page=0 chnl=0 letter="S" +char id=54 x=124 y=26 width=12 height=19 xoffset=1 yoffset=-1 xadvance=10 page=0 chnl=0 letter="6" +char id=116 x=138 y=26 width=9 height=19 xoffset=1 yoffset=-1 xadvance=6 page=0 chnl=0 letter="t" +char id=33 x=149 y=26 width=7 height=19 xoffset=2 yoffset=-1 xadvance=5 page=0 chnl=0 letter="!" +char id=87 x=158 y=26 width=20 height=18 xoffset=1 yoffset=-1 xadvance=17 page=0 chnl=0 letter="W" +char id=65 x=180 y=26 width=17 height=18 xoffset=0 yoffset=-1 xadvance=13 page=0 chnl=0 letter="A" +char id=38 x=199 y=26 width=16 height=18 xoffset=2 yoffset=0 xadvance=14 page=0 chnl=0 letter="&" +char id=86 x=217 y=26 width=16 height=18 xoffset=1 yoffset=-1 xadvance=13 page=0 chnl=0 letter="V" +char id=113 x=235 y=26 width=15 height=18 xoffset=1 yoffset=2 xadvance=12 page=0 chnl=0 letter="q" +char id=103 x=2 y=47 width=15 height=18 xoffset=1 yoffset=2 xadvance=12 page=0 chnl=0 letter="g" +char id=68 x=19 y=47 width=15 height=18 xoffset=2 yoffset=-1 xadvance=13 page=0 chnl=0 letter="D" +char id=112 x=36 y=47 width=14 height=18 xoffset=1 yoffset=2 xadvance=12 page=0 chnl=0 letter="p" +char id=35 x=52 y=47 width=14 height=18 xoffset=2 yoffset=-1 xadvance=13 page=0 chnl=0 letter="#" +char id=85 x=68 y=47 width=14 height=18 xoffset=2 yoffset=0 xadvance=12 page=0 chnl=0 letter="U" +char id=52 x=84 y=47 width=14 height=18 xoffset=0 yoffset=-1 xadvance=10 page=0 chnl=0 letter="4" +char id=50 x=100 y=47 width=13 height=18 xoffset=1 yoffset=-1 xadvance=10 page=0 chnl=0 letter="2" +char id=104 x=115 y=47 width=13 height=18 xoffset=1 yoffset=-1 xadvance=11 page=0 chnl=0 letter="h" +char id=121 x=130 y=47 width=13 height=18 xoffset=0 yoffset=2 xadvance=10 page=0 chnl=0 letter="y" +char id=80 x=145 y=47 width=13 height=18 xoffset=2 yoffset=-1 xadvance=11 page=0 chnl=0 letter="P" +char id=82 x=160 y=47 width=13 height=18 xoffset=2 yoffset=-1 xadvance=11 page=0 chnl=0 letter="R" +char id=55 x=175 y=47 width=13 height=18 xoffset=1 yoffset=-1 xadvance=10 page=0 chnl=0 letter="7" +char id=63 x=190 y=47 width=12 height=18 xoffset=1 yoffset=-1 xadvance=9 page=0 chnl=0 letter="?" +char id=66 x=204 y=47 width=12 height=18 xoffset=2 yoffset=-1 xadvance=10 page=0 chnl=0 letter="B" +char id=107 x=218 y=47 width=12 height=18 xoffset=1 yoffset=-1 xadvance=9 page=0 chnl=0 letter="k" +char id=74 x=232 y=47 width=11 height=18 xoffset=1 yoffset=0 xadvance=9 page=0 chnl=0 letter="J" +char id=102 x=245 y=47 width=9 height=18 xoffset=1 yoffset=-1 xadvance=6 page=0 chnl=0 letter="f" +char id=105 x=2 y=67 width=6 height=18 xoffset=1 yoffset=-1 xadvance=4 page=0 chnl=0 letter="i" +char id=108 x=10 y=67 width=6 height=18 xoffset=1 yoffset=-1 xadvance=4 page=0 chnl=0 letter="l" +char id=77 x=18 y=67 width=19 height=17 xoffset=1 yoffset=0 xadvance=17 page=0 chnl=0 letter="M" +char id=78 x=39 y=67 width=15 height=17 xoffset=2 yoffset=0 xadvance=13 page=0 chnl=0 letter="N" +char id=88 x=56 y=67 width=14 height=17 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=0 letter="X" +char id=89 x=72 y=67 width=14 height=17 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=0 letter="Y" +char id=72 x=88 y=67 width=14 height=17 xoffset=2 yoffset=0 xadvance=12 page=0 chnl=0 letter="H" +char id=75 x=104 y=67 width=13 height=17 xoffset=2 yoffset=0 xadvance=11 page=0 chnl=0 letter="K" +char id=69 x=119 y=67 width=12 height=17 xoffset=2 yoffset=0 xadvance=10 page=0 chnl=0 letter="E" +char id=90 x=133 y=67 width=12 height=17 xoffset=0 yoffset=0 xadvance=9 page=0 chnl=0 letter="Z" +char id=84 x=147 y=67 width=12 height=17 xoffset=0 yoffset=0 xadvance=8 page=0 chnl=0 letter="T" +char id=70 x=161 y=67 width=11 height=17 xoffset=2 yoffset=0 xadvance=9 page=0 chnl=0 letter="F" +char id=76 x=174 y=67 width=11 height=17 xoffset=2 yoffset=0 xadvance=8 page=0 chnl=0 letter="L" +char id=49 x=187 y=67 width=8 height=17 xoffset=3 yoffset=0 xadvance=10 page=0 chnl=0 letter="1" +char id=73 x=197 y=67 width=6 height=17 xoffset=1 yoffset=0 xadvance=4 page=0 chnl=0 letter="I" +char id=59 x=205 y=67 width=7 height=16 xoffset=1 yoffset=2 xadvance=5 page=0 chnl=0 letter=";" +char id=97 x=214 y=67 width=15 height=15 xoffset=1 yoffset=3 xadvance=12 page=0 chnl=0 letter="a" +char id=111 x=231 y=67 width=14 height=15 xoffset=1 yoffset=3 xadvance=12 page=0 chnl=0 letter="o" +char id=101 x=2 y=87 width=14 height=15 xoffset=1 yoffset=3 xadvance=12 page=0 chnl=0 letter="e" +char id=99 x=18 y=87 width=14 height=15 xoffset=1 yoffset=3 xadvance=12 page=0 chnl=0 letter="c" +char id=117 x=34 y=87 width=13 height=15 xoffset=1 yoffset=3 xadvance=11 page=0 chnl=0 letter="u" +char id=115 x=49 y=87 width=10 height=15 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=0 letter="s" +char id=58 x=61 y=87 width=7 height=15 xoffset=2 yoffset=3 xadvance=5 page=0 chnl=0 letter=":" +char id=109 x=70 y=87 width=19 height=14 xoffset=1 yoffset=3 xadvance=17 page=0 chnl=0 letter="m" +char id=119 x=91 y=87 width=19 height=14 xoffset=0 yoffset=3 xadvance=15 page=0 chnl=0 letter="w" +char id=94 x=112 y=87 width=14 height=14 xoffset=1 yoffset=0 xadvance=12 page=0 chnl=0 letter="^" +char id=60 x=128 y=87 width=14 height=14 xoffset=1 yoffset=1 xadvance=11 page=0 chnl=0 letter="<" +char id=62 x=144 y=87 width=14 height=14 xoffset=1 yoffset=1 xadvance=11 page=0 chnl=0 letter=">" +char id=110 x=160 y=87 width=13 height=14 xoffset=1 yoffset=3 xadvance=11 page=0 chnl=0 letter="n" +char id=118 x=175 y=87 width=13 height=14 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=0 letter="v" +char id=120 x=190 y=87 width=13 height=14 xoffset=0 yoffset=3 xadvance=9 page=0 chnl=0 letter="x" +char id=122 x=205 y=87 width=12 height=14 xoffset=0 yoffset=3 xadvance=8 page=0 chnl=0 letter="z" +char id=114 x=219 y=87 width=9 height=14 xoffset=1 yoffset=3 xadvance=5 page=0 chnl=0 letter="r" +char id=43 x=230 y=87 width=13 height=13 xoffset=1 yoffset=2 xadvance=11 page=0 chnl=0 letter="+" +char id=42 x=2 y=104 width=10 height=11 xoffset=1 yoffset=-1 xadvance=8 page=0 chnl=0 letter="*" +char id=61 x=14 y=104 width=13 height=10 xoffset=1 yoffset=3 xadvance=11 page=0 chnl=0 letter="=" +char id=34 x=29 y=104 width=9 height=9 xoffset=0 yoffset=-1 xadvance=6 page=0 chnl=0 letter=""" +char id=39 x=40 y=104 width=6 height=9 xoffset=1 yoffset=-1 xadvance=4 page=0 chnl=0 letter="'" +char id=44 x=48 y=104 width=7 height=8 xoffset=1 yoffset=10 xadvance=5 page=0 chnl=0 letter="," +char id=46 x=57 y=104 width=7 height=8 xoffset=2 yoffset=10 xadvance=5 page=0 chnl=0 letter="." +char id=126 x=66 y=104 width=13 height=7 xoffset=1 yoffset=5 xadvance=11 page=0 chnl=0 letter="~" +char id=96 x=81 y=104 width=8 height=7 xoffset=1 yoffset=-1 xadvance=7 page=0 chnl=0 letter="`" +char id=45 x=91 y=104 width=9 height=6 xoffset=1 yoffset=7 xadvance=6 page=0 chnl=0 letter="-" +char id=95 x=102 y=104 width=13 height=5 xoffset=0 yoffset=14 xadvance=9 page=0 chnl=0 letter="_" +char id=32 x=117 y=104 width=0 height=0 xoffset=5 yoffset=35 xadvance=4 page=0 chnl=0 letter="space" diff --git a/samples/js-tests/res/cocosui/CCS/2.1/FNT/Heiti18.png b/samples/js-tests/res/cocosui/CCS/2.1/FNT/Heiti18.png new file mode 100644 index 0000000000..2823654cfc Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/FNT/Heiti18.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/FNT/futura.fnt b/samples/js-tests/res/cocosui/CCS/2.1/FNT/futura.fnt new file mode 100644 index 0000000000..5a4925a5dc --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/2.1/FNT/futura.fnt @@ -0,0 +1,172 @@ +info face="Futura-Medium" size=20 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=2,2 +common lineHeight=26 base=21 scaleW=256 scaleH=128 pages=1 packed=0 +page id=0 file="futura.png" +chars count=95 +char id=47 x=2 y=2 width=11 height=22 xoffset=-0 yoffset=3 xadvance=10 page=0 chnl=0 letter="/" +char id=92 x=15 y=2 width=11 height=22 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=0 letter="\" +char id=91 x=28 y=2 width=5 height=22 xoffset=2 yoffset=3 xadvance=7 page=0 chnl=0 letter="[" +char id=93 x=35 y=2 width=5 height=22 xoffset=1 yoffset=3 xadvance=7 page=0 chnl=0 letter="]" +char id=106 x=42 y=2 width=3 height=22 xoffset=1 yoffset=4 xadvance=5 page=0 chnl=0 letter="j" +char id=36 x=47 y=2 width=11 height=21 xoffset=1 yoffset=2 xadvance=12 page=0 chnl=0 letter="$" +char id=123 x=60 y=2 width=7 height=21 xoffset=1 yoffset=4 xadvance=7 page=0 chnl=0 letter="{" +char id=125 x=69 y=2 width=7 height=21 xoffset=1 yoffset=4 xadvance=7 page=0 chnl=0 letter="}" +char id=40 x=78 y=2 width=5 height=21 xoffset=2 yoffset=4 xadvance=7 page=0 chnl=0 letter="(" +char id=41 x=85 y=2 width=5 height=21 xoffset=1 yoffset=4 xadvance=7 page=0 chnl=0 letter=")" +char id=124 x=92 y=2 width=3 height=19 xoffset=5 yoffset=6 xadvance=11 page=0 chnl=0 letter="|" +char id=87 x=97 y=2 width=22 height=18 xoffset=0 yoffset=4 xadvance=21 page=0 chnl=0 letter="W" +char id=78 x=121 y=2 width=14 height=18 xoffset=2 yoffset=4 xadvance=17 page=0 chnl=0 letter="N" +char id=86 x=137 y=2 width=14 height=18 xoffset=0 yoffset=4 xadvance=14 page=0 chnl=0 letter="V" +char id=100 x=153 y=2 width=11 height=18 xoffset=1 yoffset=3 xadvance=12 page=0 chnl=0 letter="d" +char id=98 x=166 y=2 width=11 height=18 xoffset=1 yoffset=3 xadvance=12 page=0 chnl=0 letter="b" +char id=107 x=179 y=2 width=10 height=18 xoffset=1 yoffset=3 xadvance=10 page=0 chnl=0 letter="k" +char id=104 x=191 y=2 width=10 height=18 xoffset=1 yoffset=3 xadvance=11 page=0 chnl=0 letter="h" +char id=102 x=203 y=2 width=6 height=18 xoffset=1 yoffset=3 xadvance=6 page=0 chnl=0 letter="f" +char id=108 x=211 y=2 width=3 height=18 xoffset=1 yoffset=3 xadvance=5 page=0 chnl=0 letter="l" +char id=77 x=216 y=2 width=18 height=17 xoffset=1 yoffset=5 xadvance=19 page=0 chnl=0 letter="M" +char id=37 x=236 y=2 width=18 height=17 xoffset=1 yoffset=4 xadvance=18 page=0 chnl=0 letter="%" +char id=81 x=2 y=26 width=17 height=17 xoffset=1 yoffset=4 xadvance=18 page=0 chnl=0 letter="Q" +char id=64 x=21 y=26 width=17 height=17 xoffset=1 yoffset=4 xadvance=18 page=0 chnl=0 letter="@" +char id=65 x=40 y=26 width=16 height=17 xoffset=0 yoffset=4 xadvance=15 page=0 chnl=0 letter="A" +char id=79 x=58 y=26 width=16 height=17 xoffset=1 yoffset=4 xadvance=18 page=0 chnl=0 letter="O" +char id=71 x=76 y=26 width=16 height=17 xoffset=1 yoffset=4 xadvance=17 page=0 chnl=0 letter="G" +char id=38 x=94 y=26 width=14 height=17 xoffset=1 yoffset=4 xadvance=15 page=0 chnl=0 letter="&" +char id=89 x=110 y=26 width=13 height=17 xoffset=-0 yoffset=4 xadvance=12 page=0 chnl=0 letter="Y" +char id=68 x=125 y=26 width=13 height=17 xoffset=2 yoffset=4 xadvance=15 page=0 chnl=0 letter="D" +char id=35 x=140 y=26 width=13 height=17 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=0 letter="#" +char id=52 x=155 y=26 width=12 height=17 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=0 letter="4" +char id=67 x=169 y=26 width=12 height=17 xoffset=1 yoffset=4 xadvance=14 page=0 chnl=0 letter="C" +char id=88 x=183 y=26 width=12 height=17 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=0 letter="X" +char id=85 x=197 y=26 width=12 height=17 xoffset=2 yoffset=4 xadvance=15 page=0 chnl=0 letter="U" +char id=72 x=211 y=26 width=12 height=17 xoffset=2 yoffset=4 xadvance=15 page=0 chnl=0 letter="H" +char id=90 x=225 y=26 width=12 height=17 xoffset=1 yoffset=4 xadvance=12 page=0 chnl=0 letter="Z" +char id=48 x=239 y=26 width=12 height=17 xoffset=1 yoffset=4 xadvance=12 page=0 chnl=0 letter="0" +char id=75 x=2 y=45 width=12 height=17 xoffset=2 yoffset=4 xadvance=13 page=0 chnl=0 letter="K" +char id=55 x=16 y=45 width=12 height=17 xoffset=1 yoffset=5 xadvance=12 page=0 chnl=0 letter="7" +char id=53 x=30 y=45 width=11 height=17 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=0 letter="5" +char id=50 x=43 y=45 width=11 height=17 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=0 letter="2" +char id=83 x=56 y=45 width=11 height=17 xoffset=1 yoffset=4 xadvance=12 page=0 chnl=0 letter="S" +char id=51 x=69 y=45 width=11 height=17 xoffset=1 yoffset=4 xadvance=12 page=0 chnl=0 letter="3" +char id=82 x=82 y=45 width=11 height=17 xoffset=2 yoffset=4 xadvance=12 page=0 chnl=0 letter="R" +char id=56 x=95 y=45 width=10 height=17 xoffset=1 yoffset=4 xadvance=12 page=0 chnl=0 letter="8" +char id=66 x=107 y=45 width=10 height=17 xoffset=2 yoffset=4 xadvance=12 page=0 chnl=0 letter="B" +char id=84 x=119 y=45 width=10 height=17 xoffset=0 yoffset=4 xadvance=10 page=0 chnl=0 letter="T" +char id=80 x=131 y=45 width=9 height=17 xoffset=2 yoffset=4 xadvance=11 page=0 chnl=0 letter="P" +char id=69 x=142 y=45 width=9 height=17 xoffset=2 yoffset=4 xadvance=11 page=0 chnl=0 letter="E" +char id=63 x=153 y=45 width=9 height=17 xoffset=1 yoffset=4 xadvance=10 page=0 chnl=0 letter="?" +char id=70 x=164 y=45 width=9 height=17 xoffset=2 yoffset=4 xadvance=10 page=0 chnl=0 letter="F" +char id=76 x=175 y=45 width=8 height=17 xoffset=2 yoffset=4 xadvance=9 page=0 chnl=0 letter="L" +char id=74 x=185 y=45 width=8 height=17 xoffset=-0 yoffset=4 xadvance=8 page=0 chnl=0 letter="J" +char id=49 x=195 y=45 width=5 height=17 xoffset=3 yoffset=4 xadvance=12 page=0 chnl=0 letter="1" +char id=33 x=202 y=45 width=4 height=17 xoffset=2 yoffset=4 xadvance=7 page=0 chnl=0 letter="!" +char id=73 x=208 y=45 width=3 height=17 xoffset=2 yoffset=4 xadvance=6 page=0 chnl=0 letter="I" +char id=57 x=213 y=45 width=12 height=16 xoffset=1 yoffset=6 xadvance=12 page=0 chnl=0 letter="9" +char id=54 x=227 y=45 width=12 height=16 xoffset=1 yoffset=5 xadvance=12 page=0 chnl=0 letter="6" +char id=121 x=241 y=45 width=12 height=16 xoffset=0 yoffset=10 xadvance=11 page=0 chnl=0 letter="y" +char id=103 x=2 y=64 width=11 height=15 xoffset=1 yoffset=11 xadvance=12 page=0 chnl=0 letter="g" +char id=113 x=15 y=64 width=11 height=15 xoffset=1 yoffset=11 xadvance=12 page=0 chnl=0 letter="q" +char id=112 x=28 y=64 width=11 height=15 xoffset=1 yoffset=11 xadvance=12 page=0 chnl=0 letter="p" +char id=59 x=41 y=64 width=5 height=15 xoffset=0 yoffset=10 xadvance=6 page=0 chnl=0 letter=";" +char id=105 x=48 y=64 width=3 height=15 xoffset=1 yoffset=6 xadvance=5 page=0 chnl=0 letter="i" +char id=60 x=53 y=64 width=10 height=13 xoffset=1 yoffset=6 xadvance=12 page=0 chnl=0 letter="<" +char id=62 x=65 y=64 width=10 height=13 xoffset=1 yoffset=6 xadvance=12 page=0 chnl=0 letter=">" +char id=116 x=77 y=64 width=5 height=13 xoffset=1 yoffset=8 xadvance=5 page=0 chnl=0 letter="t" +char id=119 x=84 y=64 width=16 height=12 xoffset=0 yoffset=10 xadvance=15 page=0 chnl=0 letter="w" +char id=43 x=102 y=64 width=11 height=12 xoffset=1 yoffset=6 xadvance=12 page=0 chnl=0 letter="+" +char id=118 x=115 y=64 width=10 height=12 xoffset=0 yoffset=10 xadvance=10 page=0 chnl=0 letter="v" +char id=111 x=127 y=64 width=12 height=11 xoffset=1 yoffset=10 xadvance=12 page=0 chnl=0 letter="o" +char id=122 x=141 y=64 width=12 height=11 xoffset=0 yoffset=10 xadvance=11 page=0 chnl=0 letter="z" +char id=97 x=155 y=64 width=11 height=11 xoffset=1 yoffset=10 xadvance=12 page=0 chnl=0 letter="a" +char id=101 x=168 y=64 width=11 height=11 xoffset=1 yoffset=10 xadvance=11 page=0 chnl=0 letter="e" +char id=120 x=181 y=64 width=11 height=11 xoffset=0 yoffset=10 xadvance=11 page=0 chnl=0 letter="x" +char id=99 x=194 y=64 width=9 height=11 xoffset=1 yoffset=10 xadvance=10 page=0 chnl=0 letter="c" +char id=115 x=205 y=64 width=8 height=11 xoffset=1 yoffset=10 xadvance=8 page=0 chnl=0 letter="s" +char id=58 x=215 y=64 width=4 height=11 xoffset=2 yoffset=10 xadvance=6 page=0 chnl=0 letter=":" +char id=109 x=221 y=64 width=14 height=10 xoffset=1 yoffset=11 xadvance=16 page=0 chnl=0 letter="m" +char id=110 x=237 y=64 width=10 height=10 xoffset=1 yoffset=11 xadvance=11 page=0 chnl=0 letter="n" +char id=117 x=2 y=81 width=10 height=10 xoffset=1 yoffset=11 xadvance=11 page=0 chnl=0 letter="u" +char id=114 x=14 y=81 width=7 height=10 xoffset=1 yoffset=11 xadvance=7 page=0 chnl=0 letter="r" +char id=94 x=23 y=81 width=12 height=9 xoffset=0 yoffset=4 xadvance=11 page=0 chnl=0 letter="^" +char id=42 x=37 y=81 width=8 height=9 xoffset=2 yoffset=3 xadvance=12 page=0 chnl=0 letter="*" +char id=34 x=47 y=81 width=7 height=8 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=0 letter=""" +char id=44 x=56 y=81 width=5 height=8 xoffset=0 yoffset=17 xadvance=6 page=0 chnl=0 letter="," +char id=39 x=63 y=81 width=4 height=8 xoffset=1 yoffset=4 xadvance=5 page=0 chnl=0 letter="'" +char id=126 x=69 y=81 width=12 height=6 xoffset=2 yoffset=3 xadvance=15 page=0 chnl=0 letter="~" +char id=96 x=83 y=81 width=5 height=6 xoffset=2 yoffset=4 xadvance=11 page=0 chnl=0 letter="`" +char id=61 x=90 y=81 width=11 height=5 xoffset=1 yoffset=11 xadvance=12 page=0 chnl=0 letter="=" +char id=95 x=103 y=81 width=12 height=4 xoffset=0 yoffset=20 xadvance=11 page=0 chnl=0 letter="_" +char id=46 x=117 y=81 width=4 height=4 xoffset=2 yoffset=17 xadvance=6 page=0 chnl=0 letter="." +char id=45 x=123 y=81 width=5 height=2 xoffset=0 yoffset=15 xadvance=4 page=0 chnl=0 letter="-" +char id=32 x=130 y=81 width=0 height=0 xoffset=6 yoffset=41 xadvance=6 page=0 chnl=0 letter="space" +kernings count=72 +kerning first=64 second=36 amount=-1 +kerning first=64 second=37 amount=-1 +kerning first=64 second=81 amount=-1 +kerning first=64 second=79 amount=-1 +kerning first=64 second=89 amount=-1 +kerning first=64 second=75 amount=-1 +kerning first=64 second=62 amount=1 +kerning first=64 second=43 amount=-1 +kerning first=64 second=95 amount=-1 +kerning first=65 second=89 amount=-1 +kerning first=65 second=75 amount=-1 +kerning first=65 second=62 amount=1 +kerning first=65 second=43 amount=-1 +kerning first=35 second=33 amount=-1 +kerning first=67 second=36 amount=-1 +kerning first=67 second=37 amount=-1 +kerning first=67 second=81 amount=-1 +kerning first=67 second=79 amount=-1 +kerning first=67 second=89 amount=-1 +kerning first=67 second=90 amount=-1 +kerning first=67 second=75 amount=-1 +kerning first=67 second=49 amount=-1 +kerning first=67 second=57 amount=-1 +kerning first=67 second=62 amount=1 +kerning first=67 second=43 amount=-1 +kerning first=67 second=95 amount=-1 +kerning first=67 second=45 amount=-1 +kerning first=48 second=92 amount=-1 +kerning first=48 second=52 amount=-1 +kerning first=48 second=75 amount=-1 +kerning first=48 second=43 amount=-1 +kerning first=48 second=95 amount=-1 +kerning first=53 second=99 amount=-1 +kerning first=66 second=79 amount=-1 +kerning first=66 second=89 amount=-1 +kerning first=66 second=99 amount=-1 +kerning first=49 second=67 amount=-1 +kerning first=33 second=36 amount=-1 +kerning first=57 second=67 amount=-1 +kerning first=57 second=66 amount=-1 +kerning first=54 second=64 amount=-1 +kerning first=54 second=65 amount=-1 +kerning first=54 second=67 amount=-2 +kerning first=54 second=62 amount=-1 +kerning first=54 second=99 amount=-1 +kerning first=62 second=92 amount=-1 +kerning first=62 second=93 amount=-1 +kerning first=62 second=36 amount=-1 +kerning first=62 second=77 amount=-1 +kerning first=62 second=37 amount=-1 +kerning first=62 second=81 amount=-1 +kerning first=62 second=64 amount=1 +kerning first=62 second=65 amount=1 +kerning first=62 second=79 amount=-1 +kerning first=62 second=89 amount=-1 +kerning first=62 second=52 amount=-1 +kerning first=62 second=67 amount=1 +kerning first=62 second=75 amount=-1 +kerning first=62 second=43 amount=-1 +kerning first=62 second=97 amount=-1 +kerning first=62 second=99 amount=-1 +kerning first=62 second=96 amount=-1 +kerning first=62 second=95 amount=-1 +kerning first=43 second=64 amount=-1 +kerning first=43 second=65 amount=-1 +kerning first=43 second=67 amount=-1 +kerning first=43 second=62 amount=-1 +kerning first=58 second=124 amount=-1 +kerning first=58 second=52 amount=-1 +kerning first=58 second=43 amount=-1 +kerning first=58 second=122 amount=-1 +kerning first=46 second=67 amount=-1 diff --git a/samples/js-tests/res/cocosui/CCS/2.1/FNT/futura.png b/samples/js-tests/res/cocosui/CCS/2.1/FNT/futura.png new file mode 100644 index 0000000000..5090668886 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/FNT/futura.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/JPG/Avatar14_128.jpg b/samples/js-tests/res/cocosui/CCS/2.1/JPG/Avatar14_128.jpg new file mode 100644 index 0000000000..2ce52a164f Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/JPG/Avatar14_128.jpg differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Layer.json b/samples/js-tests/res/cocosui/CCS/2.1/Layer.json new file mode 100644 index 0000000000..f67ff0eeea --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/2.1/Layer.json @@ -0,0 +1,233 @@ +{ + "ID": "4d5b94bb-1f52-4466-a3fb-6fc29d787caa", + "Version": "2.0.0.0", + "Type": "Layer", + "Name": "Layer", + "Content": { + "Content": { + "Animation": { + "Duration": 0, + "Speed": 1.0, + "Timelines": [], + "ctype": "TimelineActionData" + }, + "AnimationList": [], + "ObjectData": { + "ComboBoxIndex": 1, + "SingleColor": { + "R": 0, + "G": 0, + "B": 0 + }, + "FirstColor": { + "R": 0, + "G": 0, + "B": 0 + }, + "EndColor": {}, + "ColorVector": { + "ScaleX": 1.0 + }, + "ColorAngle": 0.0, + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "FileData": { + "Type": "Normal", + "Path": "ditu/isometric_grass_and_water.tmx" + }, + "Tag": 38, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.087, + "Y": 0.0627 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "FileData": { + "Type": "Normal", + "Path": "particle/blue.plist" + }, + "Tag": 55, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.59, + "Y": 0.4892 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 91, + "Position": { + "X": 943.9235, + "Y": 391.3527 + }, + "Scale": { + "ScaleX": 2.0115, + "ScaleY": 1.3099 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 0.0, + "Y": 0.0 + }, + "FrameEvent": "", + "Name": "Particle_1", + "ctype": "ParticleObjectData" + }, + { + "FontSize": 24, + "ButtonText": "Button", + "FontResource": { + "Type": "Normal", + "Path": "ttf/A Damn Mess.ttf" + }, + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Default", + "Path": "Default/Button_Disable.png" + }, + "PressedFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_003 copy 221.png" + }, + "NormalFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Enable": true, + "Scale9Width": 58, + "Scale9Height": 58, + "TouchEnable": true, + "Tag": 57, + "ObjectIndex": 1, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.2381, + "Y": 0.4363 + }, + "PreSizeEnable": true, + "PreSize": { + "X": 0.0288, + "Y": 0.045 + }, + "ActionTag": 93, + "Position": { + "X": 381.0, + "Y": 349.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 46.0, + "Y": 36.0 + }, + "FrameEvent": "", + "Name": "Button_1", + "ctype": "ButtonObjectData" + } + ], + "ActionTag": 40, + "Position": { + "X": 89.048, + "Y": 48.1427 + }, + "Scale": { + "ScaleX": 0.5323, + "ScaleY": 0.8687 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 1600.0, + "Y": 800.0 + }, + "FrameEvent": "", + "Name": "Map_1", + "ctype": "GameMapObjectData" + }, + { + "FileData": { + "Type": "Default", + "Path": "Default/defaultMap.tmx" + }, + "Tag": 118, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.7035, + "Y": 0.1311 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 147, + "Position": { + "X": 720.3335, + "Y": 100.6667 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 128.0, + "Y": 64.0 + }, + "FrameEvent": "", + "Name": "Map_2", + "ctype": "GameMapObjectData" + } + ], + "CanEdit": false, + "Position": { + "X": 0.0, + "Y": 0.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 1024.0, + "Y": 768.0 + }, + "FrameEvent": "", + "Name": "Layer", + "ctype": "PanelObjectData" + }, + "ctype": "GameProjectData" + } + } +} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/CCS/2.1/LoadingBar/channel1.png b/samples/js-tests/res/cocosui/CCS/2.1/LoadingBar/channel1.png new file mode 100644 index 0000000000..04f1101abd Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/LoadingBar/channel1.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/LoadingBar/pipe2.png b/samples/js-tests/res/cocosui/CCS/2.1/LoadingBar/pipe2.png new file mode 100644 index 0000000000..e95eb81fa6 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/LoadingBar/pipe2.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/LoadingBar/ui_loading_01.png b/samples/js-tests/res/cocosui/CCS/2.1/LoadingBar/ui_loading_01.png new file mode 100644 index 0000000000..a4013837de Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/LoadingBar/ui_loading_01.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/LoadingBar/ui_loading_02.png b/samples/js-tests/res/cocosui/CCS/2.1/LoadingBar/ui_loading_02.png new file mode 100644 index 0000000000..9a2d4eefe5 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/LoadingBar/ui_loading_02.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/MP3/2.mp3 b/samples/js-tests/res/cocosui/CCS/2.1/MP3/2.mp3 new file mode 100644 index 0000000000..4b913d89a0 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/MP3/2.mp3 differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/MP3/2.wav b/samples/js-tests/res/cocosui/CCS/2.1/MP3/2.wav new file mode 100644 index 0000000000..9024ed5e76 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/MP3/2.wav differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/MainScene.json b/samples/js-tests/res/cocosui/CCS/2.1/MainScene.json new file mode 100644 index 0000000000..b56e2124a1 --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/2.1/MainScene.json @@ -0,0 +1,2638 @@ +{ + "ID": "b0d5a3b6-438e-4665-8d36-02e703558b12", + "Version": "2.0.0.0", + "Type": "Scene", + "Name": "MainScene", + "Content": { + "Content": { + "Animation": { + "Duration": 8, + "Speed": 1.0, + "Timelines": [ + { + "ActionTag": 9, + "Property": "Position", + "Frames": [ + { + "X": -46.9997, + "Y": 564.9995, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": -52.9997, + "Y": 595.0002, + "FrameIndex": 4, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 9, + "Property": "Scale", + "Frames": [ + { + "X": 1.128, + "Y": 1.1629, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 0.9784, + "Y": 0.7476, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 9, + "Property": "RotationSkew", + "Frames": [ + { + "X": -37.3947, + "Y": -35.3996, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": -24.3437, + "Y": -22.3539, + "FrameIndex": 4, + "ctype": "PointFrameData" + }, + { + "X": -21.0794, + "Y": -19.0916, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 13, + "Property": "Position", + "Frames": [ + { + "X": 78.0, + "Y": 84.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 125.0005, + "Y": 63.9999, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 13, + "Property": "Scale", + "Frames": [ + { + "X": 1.0, + "Y": 1.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 1.0516, + "Y": 1.0333, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 13, + "Property": "RotationSkew", + "Frames": [ + { + "X": 0.0, + "Y": 0.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 15, + "Property": "Position", + "Frames": [ + { + "X": 114.9993, + "Y": 602.998, + "FrameIndex": 4, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 16, + "Property": "Position", + "Frames": [ + { + "X": 225.9991, + "Y": 577.9967, + "FrameIndex": 3, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 20, + "Property": "Position", + "Frames": [ + { + "X": 242.0023, + "Y": 621.9995, + "FrameIndex": 4, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 21, + "Property": "Position", + "Frames": [ + { + "X": 245.9991, + "Y": 166.0007, + "FrameIndex": 4, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 23, + "Property": "Position", + "Frames": [ + { + "X": 616.001, + "Y": 629.9998, + "FrameIndex": 4, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 23, + "Property": "Scale", + "Frames": [ + { + "X": 0.89, + "Y": 0.93, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 0.9685, + "Y": 1.1725, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 23, + "Property": "RotationSkew", + "Frames": [ + { + "X": -189.4283, + "Y": -27.4244, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": -189.4194, + "Y": -27.4252, + "FrameIndex": 4, + "ctype": "PointFrameData" + }, + { + "X": -189.4192, + "Y": -27.4242, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 25, + "Property": "Position", + "Frames": [ + { + "X": 627.9996, + "Y": 378.0005, + "FrameIndex": 4, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 25, + "Property": "RotationSkew", + "Frames": [ + { + "X": -14.0147, + "Y": -36.0027, + "FrameIndex": 2, + "ctype": "PointFrameData" + }, + { + "X": -14.001, + "Y": -36.0005, + "FrameIndex": 4, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 25, + "Property": "Scale", + "Frames": [ + { + "X": 0.7396, + "Y": 0.8077, + "FrameIndex": 2, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 31, + "Property": "Position", + "Frames": [ + { + "X": 875.0, + "Y": 232.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 31, + "Property": "Scale", + "Frames": [ + { + "X": 1.0, + "Y": 1.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 31, + "Property": "RotationSkew", + "Frames": [ + { + "X": 2.7988, + "Y": 2.8041, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 5.1581, + "Y": 5.1632, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 31, + "Property": "CColor", + "Frames": [ + { + "Alpha": 190, + "Color": { + "R": 227, + "G": 27, + "B": 27 + }, + "FrameIndex": 0, + "ctype": "CColorData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 35, + "Property": "Position", + "Frames": [ + { + "X": 427.2854, + "Y": 48.5715, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 524.0, + "Y": 108.0, + "FrameIndex": 2, + "ctype": "PointFrameData" + }, + { + "X": 554.0, + "Y": 52.8572, + "FrameIndex": 4, + "ctype": "PointFrameData" + }, + { + "X": 492.1429, + "Y": -8.0, + "FrameIndex": 6, + "ctype": "PointFrameData" + }, + { + "X": 393.0, + "Y": 50.0, + "FrameIndex": 8, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 40, + "Property": "Position", + "Frames": [ + { + "X": 197.0, + "Y": 193.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 197.0, + "Y": 193.0, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 40, + "Property": "Scale", + "Frames": [ + { + "X": 2.0, + "Y": 2.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 1.0, + "Y": 1.0, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 40, + "Property": "RotationSkew", + "Frames": [ + { + "X": 180.0, + "Y": 0.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 0.0, + "Y": 0.0, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 40, + "Property": "CColor", + "Frames": [ + { + "Alpha": 44, + "Color": {}, + "FrameIndex": 0, + "ctype": "CColorData" + }, + { + "Alpha": 255, + "Color": { + "R": 20, + "G": 218, + "B": 30 + }, + "FrameIndex": 5, + "ctype": "CColorData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 141, + "Property": "Position", + "Frames": [ + { + "X": 865.4731, + "Y": 56.3811, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 870.4729, + "Y": 39.7143, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 141, + "Property": "Scale", + "Frames": [ + { + "X": 1.2, + "Y": 1.2, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 1.2, + "Y": 1.2, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 141, + "Property": "RotationSkew", + "Frames": [ + { + "X": -10.0, + "Y": -10.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 0.2565, + "Y": 0.249, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 141, + "Property": "CColor", + "Frames": [ + { + "Alpha": 0, + "Color": {}, + "FrameIndex": 0, + "ctype": "CColorData" + }, + { + "Alpha": 255, + "Color": {}, + "FrameIndex": 5, + "ctype": "CColorData" + } + ], + "ctype": "TimelineData" + } + ], + "ctype": "TimelineActionData" + }, + "AnimationList": [], + "ObjectData": { + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "FlipX": true, + "FlipY": true, + "FontSize": 20, + "ButtonText": "Button", + "TextColor": { + "R": 219, + "G": 23, + "B": 231 + }, + "DisabledFileData": { + "Type": "Default", + "Path": "Default/Button_Disable.png" + }, + "PressedFileData": { + "Type": "Default", + "Path": "Default/Button_Press.png" + }, + "NormalFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Width": 58, + "Scale9Height": 58, + "Tag": 7, + "ObjectIndex": 4, + "PrePosition": { + "X": -0.0615, + "Y": 0.7661 + }, + "PreSize": { + "X": 0.0566, + "Y": 0.0755 + }, + "ActionTag": 9, + "Position": { + "X": -46.9997, + "Y": 564.9995 + }, + "Scale": { + "ScaleX": 1.128, + "ScaleY": 1.1629 + }, + "Rotation": -37.3947, + "RotationSkewX": -37.3947, + "RotationSkewY": -35.3996, + "AnchorPoint": { + "ScaleX": -1.5, + "ScaleY": 0.5 + }, + "Alpha": 142, + "CColor": { + "R": 200, + "G": 21, + "B": 21 + }, + "Size": { + "X": 64.0, + "Y": 58.0 + }, + "FrameEvent": "", + "Name": "Button_4", + "ctype": "ButtonObjectData" + }, + { + "FontSize": 14, + "ButtonText": "Button1234", + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Normal", + "Path": "CheckBox/blue_cloud.png" + }, + "PressedFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_003 copy 221.png" + }, + "NormalFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Width": 58, + "Scale9Height": 58, + "TouchEnable": true, + "Tag": 8, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.0488, + "Y": 0.6914 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 10, + "Position": { + "X": 50.0, + "Y": 531.0003 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -62.0, + "RotationSkewX": -62.0, + "RotationSkewY": -62.0, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 89, + "CColor": {}, + "Size": { + "X": 71.0, + "Y": 58.0 + }, + "FrameEvent": "", + "Name": "Button_5", + "ctype": "ButtonObjectData" + }, + { + "FontSize": 14, + "ButtonText": "Button", + "FontResource": { + "Type": "Normal", + "Path": "ttf/A Damn Mess.ttf" + }, + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_d.png" + }, + "PressedFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_003 copy 221.png" + }, + "NormalFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Width": 58, + "Scale9Height": 58, + "DisplayState": false, + "TouchEnable": true, + "Tag": 9, + "ObjectIndex": 6, + "PrePosition": { + "X": 0.1055, + "Y": 0.6172 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 11, + "Position": { + "X": 108.0, + "Y": 474.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 1.4, + "ScaleY": 2.1 + }, + "CColor": {}, + "Size": { + "X": 59.0, + "Y": 58.0 + }, + "FrameEvent": "", + "Name": "Button_6", + "ctype": "ButtonObjectData" + }, + { + "FontSize": 14, + "ButtonText": "Button11234", + "FontResource": { + "Type": "Normal", + "Path": "ttc/simsun.ttc" + }, + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_d.png" + }, + "PressedFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_003 copy 221.png" + }, + "NormalFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Enable": true, + "Scale9Width": 58, + "Scale9Height": 58, + "DisplayState": false, + "TouchEnable": true, + "Tag": 10, + "ObjectIndex": 7, + "PrePosition": { + "X": 0.0557, + "Y": 0.3359 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 12, + "Position": { + "X": 57.0, + "Y": 258.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 46.0, + "Y": 36.0 + }, + "FrameEvent": "", + "Name": "Button_7", + "ctype": "ButtonObjectData" + }, + { + "FontSize": 24, + "ButtonText": "Button1234", + "FontResource": { + "Type": "Normal", + "Path": "ttf/Fingerpop.ttf" + }, + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Default", + "Path": "Default/Button_Disable.png" + }, + "PressedFileData": { + "Type": "Normal", + "Path": "JPG/Avatar14_128.jpg" + }, + "NormalFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Enable": true, + "LeftEage": 20, + "RightEage": 20, + "TopEage": 20, + "BottomEage": 20, + "Scale9OriginX": 20, + "Scale9OriginY": 20, + "Scale9Width": 18, + "Scale9Height": 18, + "TouchEnable": true, + "Tag": 11, + "ObjectIndex": 8, + "PrePosition": { + "X": 0.1221, + "Y": 0.0833 + }, + "PreSize": { + "X": 0.1514, + "Y": 0.1563 + }, + "ActionTag": 13, + "Position": { + "X": 78.0, + "Y": 84.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 155.0, + "Y": 120.0 + }, + "FrameEvent": "", + "Name": "Button_8", + "ctype": "ButtonObjectData" + }, + { + "CheckedState": true, + "NormalBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Normal.png" + }, + "PressedBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Press.png" + }, + "DisableBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Disable.png" + }, + "NodeNormalFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Normal.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "Tag": 13, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.1123, + "Y": 0.7852 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 15, + "Position": { + "X": 114.9993, + "Y": 602.998 + }, + "Scale": { + "ScaleX": 0.95, + "ScaleY": 1.0 + }, + "Rotation": -29.9999, + "RotationSkewX": -29.9999, + "RotationSkewY": -14.9983, + "AnchorPoint": { + "ScaleX": -1.5, + "ScaleY": 0.5 + }, + "Alpha": 113, + "CColor": { + "R": 24, + "G": 227, + "B": 21 + }, + "Size": { + "X": 40.0, + "Y": 40.0 + }, + "FrameEvent": "", + "Name": "CheckBox_2", + "ctype": "CheckBoxObjectData" + }, + { + "NormalBackFileData": { + "Type": "Normal", + "Path": "CheckBox/icon_token.png" + }, + "PressedBackFileData": { + "Type": "Normal", + "Path": "CheckBox/icon_done.png" + }, + "DisableBackFileData": { + "Type": "Normal", + "Path": "CheckBox/blue_cloud.png" + }, + "NodeNormalFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Normal.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "TouchEnable": true, + "Tag": 14, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.2207, + "Y": 0.7526 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 16, + "Position": { + "X": 225.9991, + "Y": 577.9967 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -14.0, + "RotationSkewX": -14.0, + "RotationSkewY": 16.0, + "AnchorPoint": { + "ScaleX": 1.5, + "ScaleY": 1.9 + }, + "Alpha": 213, + "CColor": { + "R": 232, + "G": 34, + "B": 34 + }, + "Size": { + "X": 56.0, + "Y": 56.0 + }, + "FrameEvent": "", + "Name": "CheckBox_3", + "ctype": "CheckBoxObjectData" + }, + { + "CheckedState": true, + "DisplayState": false, + "NormalBackFileData": { + "Type": "Normal", + "Path": "CheckBox/icon_token.png" + }, + "PressedBackFileData": { + "Type": "Normal", + "Path": "CheckBox/button_common_box03_p.png" + }, + "DisableBackFileData": { + "Type": "Normal", + "Path": "CheckBox/button_common_box03_p.png" + }, + "NodeNormalFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Normal.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "TouchEnable": true, + "Tag": 15, + "ObjectIndex": 4, + "PrePosition": { + "X": 0.1973, + "Y": 0.4909 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 17, + "Position": { + "X": 202.0, + "Y": 377.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": { + "R": 234, + "G": 234, + "B": 234 + }, + "Size": { + "X": 56.0, + "Y": 56.0 + }, + "FrameEvent": "", + "Name": "CheckBox_4", + "ctype": "CheckBoxObjectData" + }, + { + "DisplayState": false, + "NormalBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Normal.png" + }, + "PressedBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Press.png" + }, + "DisableBackFileData": { + "Type": "Normal", + "Path": "CheckBox/button_common_box03_p.png" + }, + "NodeNormalFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Normal.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "TouchEnable": true, + "Tag": 16, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.2012, + "Y": 0.3464 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 18, + "Position": { + "X": 206.0, + "Y": 266.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 40.0, + "Y": 40.0 + }, + "FrameEvent": "", + "Name": "CheckBox_5", + "ctype": "CheckBoxObjectData" + }, + { + "FlipX": true, + "FlipY": true, + "FileData": { + "Type": "PlistSubImage", + "Path": "actor_fish_denglong_dead_004.png", + "Plist": "plist1/Plist.plist" + }, + "Tag": 18, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.2363, + "Y": 0.8099 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 20, + "Position": { + "X": 242.0023, + "Y": 621.9995 + }, + "Scale": { + "ScaleX": 0.71, + "ScaleY": 0.68 + }, + "Rotation": -17.0012, + "RotationSkewX": -17.0012, + "RotationSkewY": 3.001, + "AnchorPoint": { + "ScaleY": 0.5 + }, + "Alpha": 144, + "CColor": { + "R": 52, + "G": 244, + "B": 82 + }, + "Size": { + "X": 412.0, + "Y": 300.0 + }, + "FrameEvent": "", + "Name": "Sprite_2", + "ctype": "SpriteObjectData" + }, + { + "FlipY": true, + "FileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Enable": true, + "LeftEage": 20, + "RightEage": 20, + "TopEage": 20, + "BottomEage": 20, + "Scale9OriginX": 20, + "Scale9OriginY": 20, + "Scale9Width": 18, + "Scale9Height": 18, + "Tag": 19, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.2444, + "Y": 0.3073 + }, + "PreSize": { + "X": 0.0713, + "Y": 0.1628 + }, + "ActionTag": 21, + "Position": { + "X": 245.9991, + "Y": 166.0007 + }, + "Scale": { + "ScaleX": 1.13, + "ScaleY": 1.0 + }, + "Rotation": 6.0, + "RotationSkewX": 6.0, + "RotationSkewY": -10.0, + "AnchorPoint": { + "ScaleX": -1.1, + "ScaleY": -0.8 + }, + "Alpha": 182, + "CColor": {}, + "Size": { + "X": 73.0, + "Y": 125.0 + }, + "FrameEvent": "", + "Name": "Image_1", + "ctype": "ImageViewObjectData" + }, + { + "FlipX": true, + "FlipY": true, + "FileData": { + "Type": "Normal", + "Path": "JPG/Avatar14_128.jpg" + }, + "Scale9Width": 128, + "Scale9Height": 128, + "Tag": 21, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.6016, + "Y": 0.8203 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 23, + "Position": { + "X": 616.001, + "Y": 629.9998 + }, + "Scale": { + "ScaleX": 0.89, + "ScaleY": 0.93 + }, + "Rotation": -189.4283, + "RotationSkewX": -189.4283, + "RotationSkewY": -27.4244, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 213, + "CColor": {}, + "Size": { + "X": 128.0, + "Y": 128.0 + }, + "FrameEvent": "", + "Name": "Image_3", + "ctype": "ImageViewObjectData" + }, + { + "FlipX": true, + "FlipY": true, + "FileData": { + "Type": "Normal", + "Path": "JPG/Avatar14_128.jpg" + }, + "Scale9Enable": true, + "LeftEage": 40, + "RightEage": 40, + "TopEage": 40, + "BottomEage": 40, + "Scale9OriginX": 40, + "Scale9OriginY": 40, + "Scale9Width": 48, + "Scale9Height": 48, + "Tag": 23, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.6063, + "Y": 0.4996 + }, + "PreSizeEnable": true, + "PreSize": { + "X": 0.3, + "Y": 0.3 + }, + "ActionTag": 25, + "Position": { + "X": 627.9996, + "Y": 378.0005 + }, + "Scale": { + "ScaleX": 0.7396, + "ScaleY": 0.8077 + }, + "Rotation": -14.0147, + "RotationSkewX": -14.0147, + "RotationSkewY": -36.0027, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 215, + "CColor": { + "R": 160, + "G": 210, + "B": 164 + }, + "Size": { + "X": 307.2, + "Y": 230.4 + }, + "FrameEvent": "", + "Name": "Image_5", + "ctype": "ImageViewObjectData" + }, + { + "LabelText": "123 aaa ", + "LabelBMFontFile_CNB": { + "Type": "Normal", + "Path": "FNT/Heiti18.fnt" + }, + "TouchEnable": true, + "Tag": 24, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.8398, + "Y": 0.8125 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 26, + "Position": { + "X": 860.0001, + "Y": 624.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -2.0, + "RotationSkewX": -2.0, + "RotationSkewY": -2.0, + "AnchorPoint": { + "ScaleX": 1.5, + "ScaleY": -3.6 + }, + "Alpha": 181, + "CColor": { + "R": 231, + "G": 31, + "B": 31 + }, + "Size": { + "X": 74.0, + "Y": 18.0 + }, + "FrameEvent": "", + "Name": "BitmapFontLabel_1", + "ctype": "TextBMFontObjectData" + }, + { + "ProgressInfo": 100, + "ImageFileData": { + "Type": "Normal", + "Path": "LoadingBar/channel1.png" + }, + "TouchEnable": true, + "Tag": 26, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.4515, + "Y": 0.7249 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 28, + "Position": { + "X": 462.3632, + "Y": 556.7255 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -9.0001, + "RotationSkewX": -9.0001, + "RotationSkewY": 6.0015, + "AnchorPoint": { + "ScaleX": -1.2, + "ScaleY": 0.5 + }, + "Alpha": 182, + "CColor": { + "R": 207, + "G": 86, + "B": 26 + }, + "Size": { + "X": 244.0, + "Y": 56.0 + }, + "FrameEvent": "", + "Name": "LoadingBar_1", + "ctype": "LoadingBarObjectData" + }, + { + "ImageFileData": { + "Type": "Default", + "Path": "Default/LoadingBarFile.png" + }, + "Tag": 27, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.7985, + "Y": 0.7371 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 29, + "Position": { + "X": 817.6354, + "Y": 566.0908 + }, + "Scale": { + "ScaleX": 0.9909, + "ScaleY": 2.2586 + }, + "AnchorPoint": { + "ScaleX": 0.2395, + "ScaleY": 0.5345 + }, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 14.0 + }, + "FrameEvent": "", + "Name": "LoadingBar_2", + "ctype": "LoadingBarObjectData" + }, + { + "BackGroundData": { + "Type": "Normal", + "Path": "LoadingBar/channel1.png" + }, + "ProgressBarData": { + "Type": "Normal", + "Path": "LoadingBar/pipe2.png" + }, + "BallNormalData": { + "Type": "PlistSubImage", + "Path": "222.png", + "Plist": "Plist/ui.plist" + }, + "BallPressedData": { + "Type": "PlistSubImage", + "Path": "333.png", + "Plist": "Plist/ui.plist" + }, + "BallDisabledData": { + "Type": "PlistSubImage", + "Path": "3.png", + "Plist": "Plist/ui.plist" + }, + "DisplayState": false, + "TouchEnable": true, + "Tag": 28, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.8516, + "Y": 0.457 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 30, + "Position": { + "X": 872.0, + "Y": 351.0 + }, + "Scale": { + "ScaleX": 0.74, + "ScaleY": 1.0 + }, + "Rotation": 11.0, + "RotationSkewX": 11.0, + "RotationSkewY": -4.0, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 173, + "CColor": { + "R": 42, + "G": 223, + "B": 0 + }, + "Size": { + "X": 244.0, + "Y": 56.0 + }, + "FrameEvent": "", + "Name": "Slider_1", + "ctype": "SliderObjectData" + }, + { + "BackGroundData": { + "Type": "Normal", + "Path": "LoadingBar/channel1.png" + }, + "ProgressBarData": { + "Type": "Normal", + "Path": "LoadingBar/pipe2.png" + }, + "BallNormalData": { + "Type": "Normal", + "Path": "Slider/2013-8-13 15-44-11.png" + }, + "BallPressedData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "BallDisabledData": { + "Type": "Normal", + "Path": "Slider/teehanlax - iOS 6 - iPhone_slider01.png" + }, + "PercentInfo": 100, + "DisplayState": false, + "Tag": 29, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.8545, + "Y": 0.3021 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 31, + "Position": { + "X": 875.0, + "Y": 232.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": 2.7988, + "RotationSkewX": 2.7988, + "RotationSkewY": 2.8041, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 190, + "CColor": { + "R": 227, + "G": 27, + "B": 27 + }, + "Size": { + "X": 244.0, + "Y": 56.0 + }, + "FrameEvent": "abc", + "Name": "Slider_2", + "ctype": "SliderObjectData" + }, + { + "FontSize": 36, + "LabelText": "123444", + "IsCustomSize": true, + "FontResource": { + "Type": "Normal", + "Path": "ttf/Fingerpop.ttf" + }, + "TouchScaleChangeAble": true, + "VerticalAlignmentType": "VT_Bottom", + "TouchEnable": true, + "Tag": 30, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.355, + "Y": 0.2641 + }, + "PreSize": { + "X": 0.1465, + "Y": 0.1706 + }, + "ActionTag": 32, + "Position": { + "X": 363.5696, + "Y": 202.8568 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": 30.0, + "RotationSkewX": 30.0, + "RotationSkewY": -30.0, + "AnchorPoint": { + "ScaleX": 0.3, + "ScaleY": 0.2 + }, + "CColor": { + "R": 253, + "G": 17, + "B": 17 + }, + "Size": { + "X": 150.0, + "Y": 131.0 + }, + "FrameEvent": "", + "Name": "Text_1", + "ctype": "TextObjectData" + }, + { + "FontSize": 22, + "LabelText": "Text Label\n\n\n\n\n\n", + "FontResource": { + "Type": "Normal", + "Path": "ttf/A Damn Mess.ttf" + }, + "HorizontalAlignmentType": "HT_Center", + "VerticalAlignmentType": "VT_Center", + "Tag": 31, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.3355, + "Y": 0.1077 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 33, + "Position": { + "X": 343.5708, + "Y": 82.7139 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 128.0, + "Y": 144.0 + }, + "FrameEvent": "", + "Name": "Text_2", + "ctype": "TextObjectData" + }, + { + "FontResource": { + "Type": "Normal", + "Path": "ttc/simsun.ttc" + }, + "FontSize": 24, + "IsCustomSize": true, + "LabelText": "123434qedsdsdfsf", + "PlaceHolderText": "Text Field1233", + "MaxLengthEnable": true, + "MaxLengthText": 10, + "PasswordEnable": true, + "TouchEnable": true, + "Tag": 3623, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.6081, + "Y": 0.1481 + }, + "PreSize": { + "X": 0.1494, + "Y": 0.0352 + }, + "ActionTag": 34, + "Position": { + "X": 622.7146, + "Y": 113.7144 + }, + "Scale": { + "ScaleX": 1.01, + "ScaleY": 1.04 + }, + "Rotation": -11.0, + "RotationSkewX": -11.0, + "RotationSkewY": -12.0, + "AnchorPoint": { + "ScaleX": -1.0, + "ScaleY": 1.6 + }, + "Alpha": 147, + "CColor": { + "R": 222, + "G": 12, + "B": 12 + }, + "Size": { + "X": 153.0, + "Y": 27.0 + }, + "FrameEvent": "123", + "Name": "TextField_1", + "ctype": "TextFieldObjectData" + }, + { + "FileData": { + "Type": "Normal", + "Path": "particle/blue.plist" + }, + "Tag": 33, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.3838, + "Y": 0.0651 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 35, + "Position": { + "X": 427.2854, + "Y": 48.5715 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 0.0, + "Y": 0.0 + }, + "FrameEvent": "", + "Name": "Particle_2", + "ctype": "ParticleObjectData" + }, + { + "Volume": 0.5, + "Loop": true, + "FileData": { + "Type": "Normal", + "Path": "MP3/2.wav" + }, + "Tag": 35, + "ObjectIndex": 1, + "IconVisible": true, + "PrePosition": { + "X": 0.5681, + "Y": 0.0586 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 37, + "Position": { + "X": 581.7134, + "Y": 45.0001 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 0.0, + "Y": 0.0 + }, + "FrameEvent": "", + "Name": "Audio_1", + "ctype": "SimpleAudioObjectData" + }, + { + "Tag": 3623, + "ObjectIndex": 1, + "IconVisible": true, + "PrePosition": { + "X": 0.7027, + "Y": 0.0504 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 38, + "Position": { + "X": 719.569, + "Y": 38.7151 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -20.9984, + "RotationSkewX": -20.9984, + "RotationSkewY": 10.0001, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 0.0, + "Y": 0.0 + }, + "FrameEvent": "", + "Name": "Node_1", + "ctype": "SingleNodeObjectData" + }, + { + "FontSize": 14, + "ButtonText": "Button", + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Default", + "Path": "Default/Button_Disable.png" + }, + "PressedFileData": { + "Type": "Default", + "Path": "Default/Button_Press.png" + }, + "NormalFileData": { + "Type": "Default", + "Path": "Default/Button_Normal.png" + }, + "Scale9Width": 46, + "Scale9Height": 36, + "TouchEnable": true, + "Tag": 27, + "ObjectIndex": 9, + "PrePosition": { + "X": 0.0547, + "Y": 0.944 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 38, + "Position": { + "X": 56.0, + "Y": 725.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 46.0, + "Y": 36.0 + }, + "FrameEvent": "", + "Name": "Button_9", + "ctype": "ButtonObjectData" + }, + { + "CheckedState": true, + "NormalBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Normal.png" + }, + "PressedBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Press.png" + }, + "DisableBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Disable.png" + }, + "NodeNormalFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Normal.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "TouchEnable": true, + "Tag": 28, + "ObjectIndex": 6, + "PrePosition": { + "X": 0.1709, + "Y": 0.9414 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 39, + "Position": { + "X": 175.0, + "Y": 723.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 40.0, + "Y": 40.0 + }, + "FrameEvent": "", + "Name": "CheckBox_6", + "ctype": "CheckBoxObjectData" + }, + { + "CheckedState": true, + "NormalBackFileData": { + "Type": "Normal", + "Path": "CheckBox/icon_token.png" + }, + "PressedBackFileData": { + "Type": "Normal", + "Path": "CheckBox/blue_cloud.png" + }, + "DisableBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Disable.png" + }, + "NodeNormalFileData": { + "Type": "Normal", + "Path": "CheckBox/icon_done.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "TouchEnable": true, + "Tag": 29, + "ObjectIndex": 7, + "PrePosition": { + "X": 0.1924, + "Y": 0.2513 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 40, + "Position": { + "X": 197.0, + "Y": 193.0 + }, + "Scale": { + "ScaleX": 2.0, + "ScaleY": 2.0 + }, + "Rotation": 180.0, + "RotationSkewX": 180.0, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 44, + "CColor": {}, + "Size": { + "X": 56.0, + "Y": 56.0 + }, + "FrameEvent": "", + "Name": "CheckBox_7", + "ctype": "CheckBoxObjectData" + }, + { + "FileData": { + "Type": "Default", + "Path": "Default/Sprite.png" + }, + "Tag": 63, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.3604, + "Y": 0.9427 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 94, + "Position": { + "X": 369.0, + "Y": 724.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 46.0, + "Y": 46.0 + }, + "FrameEvent": "", + "Name": "Sprite_3", + "ctype": "SpriteObjectData" + }, + { + "FileData": { + "Type": "Default", + "Path": "Default/ImageFile.png" + }, + "Scale9Width": 46, + "Scale9Height": 46, + "Tag": 64, + "ObjectIndex": 6, + "PrePosition": { + "X": 0.5684, + "Y": 0.9544 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 95, + "Position": { + "X": 582.0, + "Y": 733.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 46.0, + "Y": 46.0 + }, + "FrameEvent": "", + "Name": "Image_6", + "ctype": "ImageViewObjectData" + }, + { + "LabelText": "Fnt Text Label", + "LabelBMFontFile_CNB": { + "Type": "Default", + "Path": "Default/defaultBMFont.fnt" + }, + "Tag": 65, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.7683, + "Y": 0.9596 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 96, + "Position": { + "X": 786.7271, + "Y": 736.9999 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 162.0, + "Y": 36.0 + }, + "FrameEvent": "", + "Name": "BitmapFontLabel_2", + "ctype": "TextBMFontObjectData" + }, + { + "LabelText": "wanwan", + "LabelBMFontFile_CNB": { + "Type": "Normal", + "Path": "FNT/futura.fnt" + }, + "Tag": 66, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.7607, + "Y": 0.8343 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 97, + "Position": { + "X": 778.9582, + "Y": 640.7659 + }, + "Scale": { + "ScaleX": 0.96, + "ScaleY": 0.87 + }, + "Rotation": 30.0, + "RotationSkewX": 30.0, + "AnchorPoint": { + "ScaleX": -0.1, + "ScaleY": 0.1 + }, + "CColor": {}, + "Size": { + "X": 76.0, + "Y": 26.0 + }, + "FrameEvent": "", + "Name": "BitmapFontLabel_3", + "ctype": "TextBMFontObjectData" + }, + { + "ImageFileData": { + "Type": "Default", + "Path": "Default/LoadingBarFile.png" + }, + "Tag": 69, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.842, + "Y": 0.788 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 100, + "Position": { + "X": 862.1818, + "Y": 605.1819 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 14.0 + }, + "FrameEvent": "", + "Name": "LoadingBar_3", + "ctype": "LoadingBarObjectData" + }, + { + "ProgressInfo": 50, + "ProgressType": "Right_To_Left", + "ImageFileData": { + "Type": "Normal", + "Path": "LoadingBar/pipe2.png" + }, + "Tag": 70, + "ObjectIndex": 4, + "PrePosition": { + "X": 0.8473, + "Y": 0.5951 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 101, + "Position": { + "X": 867.6357, + "Y": 456.9999 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": { + "R": 215, + "G": 229, + "B": 12 + }, + "Size": { + "X": 214.0, + "Y": 24.0 + }, + "FrameEvent": "", + "Name": "LoadingBar_4", + "ctype": "LoadingBarObjectData" + }, + { + "BackGroundData": { + "Type": "Default", + "Path": "Default/Slider_Back.png" + }, + "ProgressBarData": { + "Type": "Default", + "Path": "Default/Slider_PressBar.png" + }, + "BallNormalData": { + "Type": "Default", + "Path": "Default/SliderNode_Normal.png" + }, + "BallPressedData": { + "Type": "Default", + "Path": "Default/SliderNode_Press.png" + }, + "BallDisabledData": { + "Type": "Default", + "Path": "Default/SliderNode_Disable.png" + }, + "PercentInfo": 50, + "TouchEnable": true, + "Tag": 71, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.8713, + "Y": 0.524 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 102, + "Position": { + "X": 892.1815, + "Y": 402.4546 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 14.0 + }, + "FrameEvent": "", + "Name": "Slider_3", + "ctype": "SliderObjectData" + }, + { + "BackGroundData": { + "Type": "Normal", + "Path": "LoadingBar/channel1.png" + }, + "ProgressBarData": { + "Type": "Normal", + "Path": "LoadingBar/pipe2.png" + }, + "BallNormalData": { + "Type": "Default", + "Path": "Default/SliderNode_Normal.png" + }, + "BallPressedData": { + "Type": "Default", + "Path": "Default/SliderNode_Press.png" + }, + "BallDisabledData": { + "Type": "Default", + "Path": "Default/SliderNode_Disable.png" + }, + "PercentInfo": 100, + "TouchEnable": true, + "Tag": 72, + "ObjectIndex": 4, + "PrePosition": { + "X": 0.8507, + "Y": 0.3765 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 103, + "Position": { + "X": 871.0895, + "Y": 289.1812 + }, + "Scale": { + "ScaleX": 0.74, + "ScaleY": 1.2 + }, + "Rotation": 10.9993, + "RotationSkewX": 10.9993, + "RotationSkewY": -3.9987, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 173, + "CColor": { + "R": 42, + "G": 223, + "B": 0 + }, + "Size": { + "X": 244.0, + "Y": 56.0 + }, + "FrameEvent": "", + "Name": "Slider_1", + "ctype": "SliderObjectData" + }, + { + "FontSize": 20, + "LabelText": "Text Label", + "Tag": 105, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.3267, + "Y": 0.3917 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 134, + "Position": { + "X": 334.5708, + "Y": 300.8571 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 91.0, + "Y": 23.0 + }, + "FrameEvent": "", + "Name": "Text_5", + "ctype": "TextObjectData" + }, + { + "FontSize": 20, + "IsCustomSize": true, + "LabelText": "", + "PlaceHolderText": "Text Field", + "MaxLengthText": 10, + "TouchEnable": true, + "Tag": 111, + "ObjectIndex": 4, + "PrePosition": { + "X": 0.7792, + "Y": 0.2294 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 140, + "Position": { + "X": 797.8571, + "Y": 176.1429 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 95.0, + "Y": 27.0 + }, + "FrameEvent": "", + "Name": "TextField_4", + "ctype": "TextFieldObjectData" + }, + { + "FontSize": 48, + "IsCustomSize": true, + "LabelText": "触控科技", + "PlaceHolderText": "wanwan", + "MaxLengthText": 10, + "TouchEnable": true, + "Tag": 112, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.8501, + "Y": 0.0517 + }, + "PreSize": { + "X": 0.1953, + "Y": 0.0781 + }, + "ActionTag": 141, + "Position": { + "X": 865.4731, + "Y": 56.3811 + }, + "Scale": { + "ScaleX": 1.2, + "ScaleY": 1.2 + }, + "Rotation": -10.0, + "RotationSkewX": -10.0, + "RotationSkewY": -10.0, + "AnchorPoint": { + "ScaleX": 0.4, + "ScaleY": 0.3 + }, + "Alpha": 0, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 60.0 + }, + "FrameEvent": "123", + "Name": "TextField_5", + "ctype": "TextFieldObjectData" + }, + { + "FileData": { + "Type": "Default", + "Path": "Default/defaultParticle.plist" + }, + "Tag": 113, + "ObjectIndex": 4, + "PrePosition": { + "X": 0.4402, + "Y": 0.0694 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 142, + "Position": { + "X": 450.7145, + "Y": 53.2857 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 0.0, + "Y": 0.0 + }, + "FrameEvent": "", + "Name": "Particle_4", + "ctype": "ParticleObjectData" + }, + { + "CharWidth": 14, + "CharHeight": 18, + "LabelText": "./0123456789", + "StartChar": ".", + "LabelAtlasFileImage_CNB": { + "Type": "Default", + "Path": "Default/TextAtlas.png" + }, + "Tag": 119, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.5642, + "Y": 0.2693 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 148, + "Position": { + "X": 577.7139, + "Y": 206.8564 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 168.0, + "Y": 18.0 + }, + "FrameEvent": "", + "Name": "AtlasLabel_1", + "ctype": "TextAtlasObjectData" + }, + { + "CharWidth": 22, + "CharHeight": 26, + "LabelText": "", + "StartChar": ".", + "LabelAtlasFileImage_CNB": { + "Type": "Normal", + "Path": "fonts_weapon_001-hd.png" + }, + "Tag": 120, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.5628, + "Y": 0.221 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 149, + "Position": { + "X": 576.2854, + "Y": 169.7141 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 264.0, + "Y": 26.0 + }, + "FrameEvent": "", + "Name": "AtlasLabel_2", + "ctype": "TextAtlasObjectData" + }, + { + "CharWidth": 22, + "CharHeight": 26, + "LabelText": "123/0.78", + "StartChar": ".", + "LabelAtlasFileImage_CNB": { + "Type": "Normal", + "Path": "fonts_weapon_001-hd.png" + }, + "Tag": 121, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.4223, + "Y": 0.234 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 150, + "Position": { + "X": 432.43, + "Y": 179.7133 + }, + "Scale": { + "ScaleX": 1.3612, + "ScaleY": 2.1577 + }, + "Rotation": -30.0, + "RotationSkewX": -30.0, + "RotationSkewY": 30.0, + "AnchorPoint": { + "ScaleX": -0.21, + "ScaleY": -0.0785 + }, + "Alpha": 128, + "CColor": { + "R": 225, + "G": 46, + "B": 46 + }, + "Size": { + "X": 176.0, + "Y": 26.0 + }, + "FrameEvent": "", + "Name": "AtlasLabel_3", + "ctype": "TextAtlasObjectData" + } + ], + "CanEdit": false, + "Position": { + "X": 0.0, + "Y": 0.0 + }, + "Scale": { + "ScaleX": 0.6, + "ScaleY": 0.6 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 1024.0, + "Y": 768.0 + }, + "FrameEvent": "", + "Name": "Scene", + "ctype": "SingleNodeObjectData" + }, + "ctype": "GameProjectData" + } + } +} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/CCS/2.1/MainScene_backup.json b/samples/js-tests/res/cocosui/CCS/2.1/MainScene_backup.json new file mode 100644 index 0000000000..461fee9872 --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/2.1/MainScene_backup.json @@ -0,0 +1,2638 @@ +{ + "ID": "b0d5a3b6-438e-4665-8d36-02e703558b12", + "Version": "2.0.0.0", + "Type": "Scene", + "Name": "MainScene", + "Content": { + "Content": { + "Animation": { + "Duration": 8, + "Speed": 1.0, + "Timelines": [ + { + "ActionTag": 9, + "FrameType": "PositionFrame", + "Frames": [ + { + "X": -46.9997, + "Y": 564.9995, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": -52.9997, + "Y": 595.0002, + "FrameIndex": 4, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 9, + "FrameType": "ScaleFrame", + "Frames": [ + { + "X": 1.128, + "Y": 1.1629, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 0.9784, + "Y": 0.7476, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 9, + "FrameType": "RotationSkewFrame", + "Frames": [ + { + "X": -37.3947, + "Y": -35.3996, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": -24.3437, + "Y": -22.3539, + "FrameIndex": 4, + "ctype": "PointFrameData" + }, + { + "X": -21.0794, + "Y": -19.0916, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 13, + "FrameType": "PositionFrame", + "Frames": [ + { + "X": 78.0, + "Y": 84.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 125.0005, + "Y": 63.9999, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 13, + "FrameType": "ScaleFrame", + "Frames": [ + { + "X": 1.0, + "Y": 1.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 1.0516, + "Y": 1.0333, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 13, + "FrameType": "RotationSkewFrame", + "Frames": [ + { + "X": 0.0, + "Y": 0.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 15, + "FrameType": "PositionFrame", + "Frames": [ + { + "X": 114.9993, + "Y": 602.998, + "FrameIndex": 4, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 16, + "FrameType": "PositionFrame", + "Frames": [ + { + "X": 225.9991, + "Y": 577.9967, + "FrameIndex": 3, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 20, + "FrameType": "PositionFrame", + "Frames": [ + { + "X": 242.0023, + "Y": 621.9995, + "FrameIndex": 4, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 21, + "FrameType": "PositionFrame", + "Frames": [ + { + "X": 245.9991, + "Y": 166.0007, + "FrameIndex": 4, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 23, + "FrameType": "PositionFrame", + "Frames": [ + { + "X": 616.001, + "Y": 629.9998, + "FrameIndex": 4, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 23, + "FrameType": "ScaleFrame", + "Frames": [ + { + "X": 0.89, + "Y": 0.93, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 0.9685, + "Y": 1.1725, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 23, + "FrameType": "RotationSkewFrame", + "Frames": [ + { + "X": -189.4283, + "Y": -27.4244, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": -189.4194, + "Y": -27.4252, + "FrameIndex": 4, + "ctype": "PointFrameData" + }, + { + "X": -189.4192, + "Y": -27.4242, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 25, + "FrameType": "PositionFrame", + "Frames": [ + { + "X": 627.9996, + "Y": 378.0005, + "FrameIndex": 4, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 25, + "FrameType": "RotationSkewFrame", + "Frames": [ + { + "X": -14.0147, + "Y": -36.0027, + "FrameIndex": 2, + "ctype": "PointFrameData" + }, + { + "X": -14.001, + "Y": -36.0005, + "FrameIndex": 4, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 25, + "FrameType": "ScaleFrame", + "Frames": [ + { + "X": 0.7396, + "Y": 0.8077, + "FrameIndex": 2, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 31, + "FrameType": "PositionFrame", + "Frames": [ + { + "X": 875.0, + "Y": 232.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 31, + "FrameType": "ScaleFrame", + "Frames": [ + { + "X": 1.0, + "Y": 1.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 31, + "FrameType": "RotationSkewFrame", + "Frames": [ + { + "X": 2.7988, + "Y": 2.8041, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 5.1581, + "Y": 5.1632, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 31, + "FrameType": "ColorFrame", + "Frames": [ + { + "Alpha": 190, + "Color": { + "R": 227, + "G": 27, + "B": 27 + }, + "FrameIndex": 0, + "ctype": "ColorFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 35, + "FrameType": "PositionFrame", + "Frames": [ + { + "X": 427.2854, + "Y": 48.5715, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 524.0, + "Y": 108.0, + "FrameIndex": 2, + "ctype": "PointFrameData" + }, + { + "X": 554.0, + "Y": 52.8572, + "FrameIndex": 4, + "ctype": "PointFrameData" + }, + { + "X": 492.1429, + "Y": -8.0, + "FrameIndex": 6, + "ctype": "PointFrameData" + }, + { + "X": 393.0, + "Y": 50.0, + "FrameIndex": 8, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 40, + "FrameType": "PositionFrame", + "Frames": [ + { + "X": 197.0, + "Y": 193.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 197.0, + "Y": 193.0, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 40, + "FrameType": "ScaleFrame", + "Frames": [ + { + "X": 2.0, + "Y": 2.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 1.0, + "Y": 1.0, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 40, + "FrameType": "RotationSkewFrame", + "Frames": [ + { + "X": 180.0, + "Y": 0.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 0.0, + "Y": 0.0, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 40, + "FrameType": "ColorFrame", + "Frames": [ + { + "Alpha": 44, + "Color": {}, + "FrameIndex": 0, + "ctype": "ColorFrameData" + }, + { + "Alpha": 255, + "Color": { + "R": 20, + "G": 218, + "B": 30 + }, + "FrameIndex": 5, + "ctype": "ColorFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 141, + "FrameType": "PositionFrame", + "Frames": [ + { + "X": 865.4731, + "Y": 56.3811, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 870.4729, + "Y": 39.7143, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 141, + "FrameType": "ScaleFrame", + "Frames": [ + { + "X": 1.2, + "Y": 1.2, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 1.2, + "Y": 1.2, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 141, + "FrameType": "RotationSkewFrame", + "Frames": [ + { + "X": -10.0, + "Y": -10.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 0.2565, + "Y": 0.249, + "FrameIndex": 5, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 141, + "FrameType": "ColorFrame", + "Frames": [ + { + "Alpha": 0, + "Color": {}, + "FrameIndex": 0, + "ctype": "ColorFrameData" + }, + { + "Alpha": 255, + "Color": {}, + "FrameIndex": 5, + "ctype": "ColorFrameData" + } + ], + "ctype": "TimelineData" + } + ], + "ctype": "TimelineActionData" + }, + "AnimationList": [], + "ObjectData": { + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "FlipX": true, + "FlipY": true, + "FontSize": 20, + "ButtonText": "Button", + "TextColor": { + "R": 219, + "G": 23, + "B": 231 + }, + "DisabledFileData": { + "Type": "Default", + "Path": "Default/Button_Disable.png" + }, + "PressedFileData": { + "Type": "Default", + "Path": "Default/Button_Press.png" + }, + "NormalFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Width": 58, + "Scale9Height": 58, + "Tag": 7, + "ObjectIndex": 4, + "PrePosition": { + "X": -0.0615, + "Y": 0.7661 + }, + "PreSize": { + "X": 0.0566, + "Y": 0.0755 + }, + "ActionTag": 9, + "Position": { + "X": -46.9997, + "Y": 564.9995 + }, + "Scale": { + "ScaleX": 1.128, + "ScaleY": 1.1629 + }, + "Rotation": -37.3947, + "RotationSkewX": -37.3947, + "RotationSkewY": -35.3996, + "AnchorPoint": { + "ScaleX": -1.5, + "ScaleY": 0.5 + }, + "Alpha": 142, + "CColor": { + "R": 200, + "G": 21, + "B": 21 + }, + "Size": { + "X": 64.0, + "Y": 58.0 + }, + "FrameEvent": "", + "Name": "Button_4", + "ctype": "ButtonObjectData" + }, + { + "FontSize": 14, + "ButtonText": "Button1234", + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Normal", + "Path": "CheckBox/blue_cloud.png" + }, + "PressedFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_003 copy 221.png" + }, + "NormalFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Width": 58, + "Scale9Height": 58, + "TouchEnable": true, + "Tag": 8, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.0488, + "Y": 0.6914 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 10, + "Position": { + "X": 50.0, + "Y": 531.0003 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -62.0, + "RotationSkewX": -62.0, + "RotationSkewY": -62.0, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 89, + "CColor": {}, + "Size": { + "X": 71.0, + "Y": 58.0 + }, + "FrameEvent": "", + "Name": "Button_5", + "ctype": "ButtonObjectData" + }, + { + "FontSize": 14, + "ButtonText": "Button", + "FontResource": { + "Type": "Normal", + "Path": "ttf/A Damn Mess.ttf" + }, + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_d.png" + }, + "PressedFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_003 copy 221.png" + }, + "NormalFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Width": 58, + "Scale9Height": 58, + "DisplayState": false, + "TouchEnable": true, + "Tag": 9, + "ObjectIndex": 6, + "PrePosition": { + "X": 0.1055, + "Y": 0.6172 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 11, + "Position": { + "X": 108.0, + "Y": 474.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 1.4, + "ScaleY": 2.1 + }, + "CColor": {}, + "Size": { + "X": 59.0, + "Y": 58.0 + }, + "FrameEvent": "", + "Name": "Button_6", + "ctype": "ButtonObjectData" + }, + { + "FontSize": 14, + "ButtonText": "Button11234", + "FontResource": { + "Type": "Normal", + "Path": "ttc/simsun.ttc" + }, + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_d.png" + }, + "PressedFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_003 copy 221.png" + }, + "NormalFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Enable": true, + "Scale9Width": 58, + "Scale9Height": 58, + "DisplayState": false, + "TouchEnable": true, + "Tag": 10, + "ObjectIndex": 7, + "PrePosition": { + "X": 0.0557, + "Y": 0.3359 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 12, + "Position": { + "X": 57.0, + "Y": 258.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 46.0, + "Y": 36.0 + }, + "FrameEvent": "", + "Name": "Button_7", + "ctype": "ButtonObjectData" + }, + { + "FontSize": 24, + "ButtonText": "Button1234", + "FontResource": { + "Type": "Normal", + "Path": "ttf/Fingerpop.ttf" + }, + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Default", + "Path": "Default/Button_Disable.png" + }, + "PressedFileData": { + "Type": "Normal", + "Path": "JPG/Avatar14_128.jpg" + }, + "NormalFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Enable": true, + "LeftEage": 20, + "RightEage": 20, + "TopEage": 20, + "BottomEage": 20, + "Scale9OriginX": 20, + "Scale9OriginY": 20, + "Scale9Width": 18, + "Scale9Height": 18, + "TouchEnable": true, + "Tag": 11, + "ObjectIndex": 8, + "PrePosition": { + "X": 0.1221, + "Y": 0.0833 + }, + "PreSize": { + "X": 0.1514, + "Y": 0.1563 + }, + "ActionTag": 13, + "Position": { + "X": 78.0, + "Y": 84.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 155.0, + "Y": 120.0 + }, + "FrameEvent": "", + "Name": "Button_8", + "ctype": "ButtonObjectData" + }, + { + "CheckedState": true, + "NormalBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Normal.png" + }, + "PressedBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Press.png" + }, + "DisableBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Disable.png" + }, + "NodeNormalFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Normal.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "Tag": 13, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.1123, + "Y": 0.7852 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 15, + "Position": { + "X": 114.9993, + "Y": 602.998 + }, + "Scale": { + "ScaleX": 0.95, + "ScaleY": 1.0 + }, + "Rotation": -29.9999, + "RotationSkewX": -29.9999, + "RotationSkewY": -14.9983, + "AnchorPoint": { + "ScaleX": -1.5, + "ScaleY": 0.5 + }, + "Alpha": 113, + "CColor": { + "R": 24, + "G": 227, + "B": 21 + }, + "Size": { + "X": 40.0, + "Y": 40.0 + }, + "FrameEvent": "", + "Name": "CheckBox_2", + "ctype": "CheckBoxObjectData" + }, + { + "NormalBackFileData": { + "Type": "Normal", + "Path": "CheckBox/icon_token.png" + }, + "PressedBackFileData": { + "Type": "Normal", + "Path": "CheckBox/icon_done.png" + }, + "DisableBackFileData": { + "Type": "Normal", + "Path": "CheckBox/blue_cloud.png" + }, + "NodeNormalFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Normal.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "TouchEnable": true, + "Tag": 14, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.2207, + "Y": 0.7526 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 16, + "Position": { + "X": 225.9991, + "Y": 577.9967 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -14.0, + "RotationSkewX": -14.0, + "RotationSkewY": 16.0, + "AnchorPoint": { + "ScaleX": 1.5, + "ScaleY": 1.9 + }, + "Alpha": 213, + "CColor": { + "R": 232, + "G": 34, + "B": 34 + }, + "Size": { + "X": 56.0, + "Y": 56.0 + }, + "FrameEvent": "", + "Name": "CheckBox_3", + "ctype": "CheckBoxObjectData" + }, + { + "CheckedState": true, + "DisplayState": false, + "NormalBackFileData": { + "Type": "Normal", + "Path": "CheckBox/icon_token.png" + }, + "PressedBackFileData": { + "Type": "Normal", + "Path": "CheckBox/button_common_box03_p.png" + }, + "DisableBackFileData": { + "Type": "Normal", + "Path": "CheckBox/button_common_box03_p.png" + }, + "NodeNormalFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Normal.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "TouchEnable": true, + "Tag": 15, + "ObjectIndex": 4, + "PrePosition": { + "X": 0.1973, + "Y": 0.4909 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 17, + "Position": { + "X": 202.0, + "Y": 377.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": { + "R": 234, + "G": 234, + "B": 234 + }, + "Size": { + "X": 56.0, + "Y": 56.0 + }, + "FrameEvent": "", + "Name": "CheckBox_4", + "ctype": "CheckBoxObjectData" + }, + { + "DisplayState": false, + "NormalBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Normal.png" + }, + "PressedBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Press.png" + }, + "DisableBackFileData": { + "Type": "Normal", + "Path": "CheckBox/button_common_box03_p.png" + }, + "NodeNormalFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Normal.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "TouchEnable": true, + "Tag": 16, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.2012, + "Y": 0.3464 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 18, + "Position": { + "X": 206.0, + "Y": 266.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 40.0, + "Y": 40.0 + }, + "FrameEvent": "", + "Name": "CheckBox_5", + "ctype": "CheckBoxObjectData" + }, + { + "FlipX": true, + "FlipY": true, + "FileData": { + "Type": "PlistSubImage", + "Path": "actor_fish_denglong_dead_004.png", + "Plist": "plist1/Plist.plist" + }, + "Tag": 18, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.2363, + "Y": 0.8099 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 20, + "Position": { + "X": 242.0023, + "Y": 621.9995 + }, + "Scale": { + "ScaleX": 0.71, + "ScaleY": 0.68 + }, + "Rotation": -17.0012, + "RotationSkewX": -17.0012, + "RotationSkewY": 3.001, + "AnchorPoint": { + "ScaleY": 0.5 + }, + "Alpha": 144, + "CColor": { + "R": 52, + "G": 244, + "B": 82 + }, + "Size": { + "X": 412.0, + "Y": 300.0 + }, + "FrameEvent": "", + "Name": "Sprite_2", + "ctype": "SpriteObjectData" + }, + { + "FlipY": true, + "FileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Enable": true, + "LeftEage": 20, + "RightEage": 20, + "TopEage": 20, + "BottomEage": 20, + "Scale9OriginX": 20, + "Scale9OriginY": 20, + "Scale9Width": 18, + "Scale9Height": 18, + "Tag": 19, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.2444, + "Y": 0.3073 + }, + "PreSize": { + "X": 0.0713, + "Y": 0.1628 + }, + "ActionTag": 21, + "Position": { + "X": 245.9991, + "Y": 166.0007 + }, + "Scale": { + "ScaleX": 1.13, + "ScaleY": 1.0 + }, + "Rotation": 6.0, + "RotationSkewX": 6.0, + "RotationSkewY": -10.0, + "AnchorPoint": { + "ScaleX": -1.1, + "ScaleY": -0.8 + }, + "Alpha": 182, + "CColor": {}, + "Size": { + "X": 73.0, + "Y": 125.0 + }, + "FrameEvent": "", + "Name": "Image_1", + "ctype": "ImageViewObjectData" + }, + { + "FlipX": true, + "FlipY": true, + "FileData": { + "Type": "Normal", + "Path": "JPG/Avatar14_128.jpg" + }, + "Scale9Width": 128, + "Scale9Height": 128, + "Tag": 21, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.6016, + "Y": 0.8203 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 23, + "Position": { + "X": 616.001, + "Y": 629.9998 + }, + "Scale": { + "ScaleX": 0.89, + "ScaleY": 0.93 + }, + "Rotation": -189.4283, + "RotationSkewX": -189.4283, + "RotationSkewY": -27.4244, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 213, + "CColor": {}, + "Size": { + "X": 128.0, + "Y": 128.0 + }, + "FrameEvent": "", + "Name": "Image_3", + "ctype": "ImageViewObjectData" + }, + { + "FlipX": true, + "FlipY": true, + "FileData": { + "Type": "Normal", + "Path": "JPG/Avatar14_128.jpg" + }, + "Scale9Enable": true, + "LeftEage": 40, + "RightEage": 40, + "TopEage": 40, + "BottomEage": 40, + "Scale9OriginX": 40, + "Scale9OriginY": 40, + "Scale9Width": 48, + "Scale9Height": 48, + "Tag": 23, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.6063, + "Y": 0.4996 + }, + "PreSizeEnable": true, + "PreSize": { + "X": 0.3, + "Y": 0.3 + }, + "ActionTag": 25, + "Position": { + "X": 627.9996, + "Y": 378.0005 + }, + "Scale": { + "ScaleX": 0.7396, + "ScaleY": 0.8077 + }, + "Rotation": -14.0147, + "RotationSkewX": -14.0147, + "RotationSkewY": -36.0027, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 215, + "CColor": { + "R": 160, + "G": 210, + "B": 164 + }, + "Size": { + "X": 307.2, + "Y": 230.4 + }, + "FrameEvent": "", + "Name": "Image_5", + "ctype": "ImageViewObjectData" + }, + { + "LabelText": "123 aaa ", + "LabelBMFontFile_CNB": { + "Type": "Normal", + "Path": "FNT/Heiti18.fnt" + }, + "TouchEnable": true, + "Tag": 24, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.8398, + "Y": 0.8125 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 26, + "Position": { + "X": 860.0001, + "Y": 624.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -2.0, + "RotationSkewX": -2.0, + "RotationSkewY": -2.0, + "AnchorPoint": { + "ScaleX": 1.5, + "ScaleY": -3.6 + }, + "Alpha": 181, + "CColor": { + "R": 231, + "G": 31, + "B": 31 + }, + "Size": { + "X": 74.0, + "Y": 18.0 + }, + "FrameEvent": "", + "Name": "BitmapFontLabel_1", + "ctype": "TextBMFontObjectData" + }, + { + "ProgressInfo": 100, + "ImageFileData": { + "Type": "Normal", + "Path": "LoadingBar/channel1.png" + }, + "TouchEnable": true, + "Tag": 26, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.4515, + "Y": 0.7249 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 28, + "Position": { + "X": 462.3632, + "Y": 556.7255 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -9.0001, + "RotationSkewX": -9.0001, + "RotationSkewY": 6.0015, + "AnchorPoint": { + "ScaleX": -1.2, + "ScaleY": 0.5 + }, + "Alpha": 182, + "CColor": { + "R": 207, + "G": 86, + "B": 26 + }, + "Size": { + "X": 244.0, + "Y": 56.0 + }, + "FrameEvent": "", + "Name": "LoadingBar_1", + "ctype": "LoadingBarObjectData" + }, + { + "ImageFileData": { + "Type": "Default", + "Path": "Default/LoadingBarFile.png" + }, + "Tag": 27, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.7985, + "Y": 0.7371 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 29, + "Position": { + "X": 817.6354, + "Y": 566.0908 + }, + "Scale": { + "ScaleX": 0.9909, + "ScaleY": 2.2586 + }, + "AnchorPoint": { + "ScaleX": 0.2395, + "ScaleY": 0.5345 + }, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 14.0 + }, + "FrameEvent": "", + "Name": "LoadingBar_2", + "ctype": "LoadingBarObjectData" + }, + { + "BackGroundData": { + "Type": "Normal", + "Path": "LoadingBar/channel1.png" + }, + "ProgressBarData": { + "Type": "Normal", + "Path": "LoadingBar/pipe2.png" + }, + "BallNormalData": { + "Type": "PlistSubImage", + "Path": "222.png", + "Plist": "Plist/ui.plist" + }, + "BallPressedData": { + "Type": "PlistSubImage", + "Path": "333.png", + "Plist": "Plist/ui.plist" + }, + "BallDisabledData": { + "Type": "PlistSubImage", + "Path": "3.png", + "Plist": "Plist/ui.plist" + }, + "DisplayState": false, + "TouchEnable": true, + "Tag": 28, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.8516, + "Y": 0.457 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 30, + "Position": { + "X": 872.0, + "Y": 351.0 + }, + "Scale": { + "ScaleX": 0.74, + "ScaleY": 1.0 + }, + "Rotation": 11.0, + "RotationSkewX": 11.0, + "RotationSkewY": -4.0, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 173, + "CColor": { + "R": 42, + "G": 223, + "B": 0 + }, + "Size": { + "X": 244.0, + "Y": 56.0 + }, + "FrameEvent": "", + "Name": "Slider_1", + "ctype": "SliderObjectData" + }, + { + "BackGroundData": { + "Type": "Normal", + "Path": "LoadingBar/channel1.png" + }, + "ProgressBarData": { + "Type": "Normal", + "Path": "LoadingBar/pipe2.png" + }, + "BallNormalData": { + "Type": "Normal", + "Path": "Slider/2013-8-13 15-44-11.png" + }, + "BallPressedData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "BallDisabledData": { + "Type": "Normal", + "Path": "Slider/teehanlax - iOS 6 - iPhone_slider01.png" + }, + "PercentInfo": 100, + "DisplayState": false, + "Tag": 29, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.8545, + "Y": 0.3021 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 31, + "Position": { + "X": 875.0, + "Y": 232.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": 2.7988, + "RotationSkewX": 2.7988, + "RotationSkewY": 2.8041, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 190, + "CColor": { + "R": 227, + "G": 27, + "B": 27 + }, + "Size": { + "X": 244.0, + "Y": 56.0 + }, + "FrameEvent": "abc", + "Name": "Slider_2", + "ctype": "SliderObjectData" + }, + { + "FontSize": 36, + "LabelText": "123444", + "IsCustomSize": true, + "FontResource": { + "Type": "Normal", + "Path": "ttf/Fingerpop.ttf" + }, + "TouchScaleChangeAble": true, + "VerticalAlignmentType": "VT_Bottom", + "TouchEnable": true, + "Tag": 30, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.355, + "Y": 0.2641 + }, + "PreSize": { + "X": 0.1465, + "Y": 0.1706 + }, + "ActionTag": 32, + "Position": { + "X": 363.5696, + "Y": 202.8568 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": 30.0, + "RotationSkewX": 30.0, + "RotationSkewY": -30.0, + "AnchorPoint": { + "ScaleX": 0.3, + "ScaleY": 0.2 + }, + "CColor": { + "R": 253, + "G": 17, + "B": 17 + }, + "Size": { + "X": 150.0, + "Y": 131.0 + }, + "FrameEvent": "", + "Name": "Text_1", + "ctype": "TextObjectData" + }, + { + "FontSize": 22, + "LabelText": "Text Label\n\n\n\n\n\n", + "FontResource": { + "Type": "Normal", + "Path": "ttf/A Damn Mess.ttf" + }, + "HorizontalAlignmentType": "HT_Center", + "VerticalAlignmentType": "VT_Center", + "Tag": 31, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.3355, + "Y": 0.1077 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 33, + "Position": { + "X": 343.5708, + "Y": 82.7139 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 128.0, + "Y": 144.0 + }, + "FrameEvent": "", + "Name": "Text_2", + "ctype": "TextObjectData" + }, + { + "FontResource": { + "Type": "Normal", + "Path": "ttc/simsun.ttc" + }, + "FontSize": 24, + "IsCustomSize": true, + "LabelText": "123434qedsdsdfsf", + "PlaceHolderText": "Text Field1233", + "MaxLengthEnable": true, + "MaxLengthText": 10, + "PasswordEnable": true, + "TouchEnable": true, + "Tag": 3623, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.6081, + "Y": 0.1481 + }, + "PreSize": { + "X": 0.1494, + "Y": 0.0352 + }, + "ActionTag": 34, + "Position": { + "X": 622.7146, + "Y": 113.7144 + }, + "Scale": { + "ScaleX": 1.01, + "ScaleY": 1.04 + }, + "Rotation": -11.0, + "RotationSkewX": -11.0, + "RotationSkewY": -12.0, + "AnchorPoint": { + "ScaleX": -1.0, + "ScaleY": 1.6 + }, + "Alpha": 147, + "CColor": { + "R": 222, + "G": 12, + "B": 12 + }, + "Size": { + "X": 153.0, + "Y": 27.0 + }, + "FrameEvent": "123", + "Name": "TextField_1", + "ctype": "TextFieldObjectData" + }, + { + "FileData": { + "Type": "Normal", + "Path": "particle/blue.plist" + }, + "Tag": 33, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.3838, + "Y": 0.0651 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 35, + "Position": { + "X": 427.2854, + "Y": 48.5715 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 0.0, + "Y": 0.0 + }, + "FrameEvent": "", + "Name": "Particle_2", + "ctype": "ParticleObjectData" + }, + { + "Volume": 0.5, + "Loop": true, + "FileData": { + "Type": "Normal", + "Path": "MP3/2.wav" + }, + "Tag": 35, + "ObjectIndex": 1, + "IconVisible": true, + "PrePosition": { + "X": 0.5681, + "Y": 0.0586 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 37, + "Position": { + "X": 581.7134, + "Y": 45.0001 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 0.0, + "Y": 0.0 + }, + "FrameEvent": "", + "Name": "Audio_1", + "ctype": "SimpleAudioObjectData" + }, + { + "Tag": 3623, + "ObjectIndex": 1, + "IconVisible": true, + "PrePosition": { + "X": 0.7027, + "Y": 0.0504 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 38, + "Position": { + "X": 719.569, + "Y": 38.7151 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -20.9984, + "RotationSkewX": -20.9984, + "RotationSkewY": 10.0001, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 0.0, + "Y": 0.0 + }, + "FrameEvent": "", + "Name": "Node_1", + "ctype": "SingleNodeObjectData" + }, + { + "FontSize": 14, + "ButtonText": "Button", + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Default", + "Path": "Default/Button_Disable.png" + }, + "PressedFileData": { + "Type": "Default", + "Path": "Default/Button_Press.png" + }, + "NormalFileData": { + "Type": "Default", + "Path": "Default/Button_Normal.png" + }, + "Scale9Width": 46, + "Scale9Height": 36, + "TouchEnable": true, + "Tag": 27, + "ObjectIndex": 9, + "PrePosition": { + "X": 0.0547, + "Y": 0.944 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 38, + "Position": { + "X": 56.0, + "Y": 725.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 46.0, + "Y": 36.0 + }, + "FrameEvent": "", + "Name": "Button_9", + "ctype": "ButtonObjectData" + }, + { + "CheckedState": true, + "NormalBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Normal.png" + }, + "PressedBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Press.png" + }, + "DisableBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Disable.png" + }, + "NodeNormalFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Normal.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "TouchEnable": true, + "Tag": 28, + "ObjectIndex": 6, + "PrePosition": { + "X": 0.1709, + "Y": 0.9414 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 39, + "Position": { + "X": 175.0, + "Y": 723.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 40.0, + "Y": 40.0 + }, + "FrameEvent": "", + "Name": "CheckBox_6", + "ctype": "CheckBoxObjectData" + }, + { + "CheckedState": true, + "NormalBackFileData": { + "Type": "Normal", + "Path": "CheckBox/icon_token.png" + }, + "PressedBackFileData": { + "Type": "Normal", + "Path": "CheckBox/blue_cloud.png" + }, + "DisableBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Disable.png" + }, + "NodeNormalFileData": { + "Type": "Normal", + "Path": "CheckBox/icon_done.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "TouchEnable": true, + "Tag": 29, + "ObjectIndex": 7, + "PrePosition": { + "X": 0.1924, + "Y": 0.2513 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 40, + "Position": { + "X": 197.0, + "Y": 193.0 + }, + "Scale": { + "ScaleX": 2.0, + "ScaleY": 2.0 + }, + "Rotation": 180.0, + "RotationSkewX": 180.0, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 44, + "CColor": {}, + "Size": { + "X": 56.0, + "Y": 56.0 + }, + "FrameEvent": "", + "Name": "CheckBox_7", + "ctype": "CheckBoxObjectData" + }, + { + "FileData": { + "Type": "Default", + "Path": "Default/Sprite.png" + }, + "Tag": 63, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.3604, + "Y": 0.9427 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 94, + "Position": { + "X": 369.0, + "Y": 724.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 46.0, + "Y": 46.0 + }, + "FrameEvent": "", + "Name": "Sprite_3", + "ctype": "SpriteObjectData" + }, + { + "FileData": { + "Type": "Default", + "Path": "Default/ImageFile.png" + }, + "Scale9Width": 46, + "Scale9Height": 46, + "Tag": 64, + "ObjectIndex": 6, + "PrePosition": { + "X": 0.5684, + "Y": 0.9544 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 95, + "Position": { + "X": 582.0, + "Y": 733.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 46.0, + "Y": 46.0 + }, + "FrameEvent": "", + "Name": "Image_6", + "ctype": "ImageViewObjectData" + }, + { + "LabelText": "Fnt Text Label", + "LabelBMFontFile_CNB": { + "Type": "Default", + "Path": "Default/defaultBMFont.fnt" + }, + "Tag": 65, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.7683, + "Y": 0.9596 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 96, + "Position": { + "X": 786.7271, + "Y": 736.9999 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 162.0, + "Y": 36.0 + }, + "FrameEvent": "", + "Name": "BitmapFontLabel_2", + "ctype": "TextBMFontObjectData" + }, + { + "LabelText": "wanwan", + "LabelBMFontFile_CNB": { + "Type": "Normal", + "Path": "FNT/futura.fnt" + }, + "Tag": 66, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.7607, + "Y": 0.8343 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 97, + "Position": { + "X": 778.9582, + "Y": 640.7659 + }, + "Scale": { + "ScaleX": 0.96, + "ScaleY": 0.87 + }, + "Rotation": 30.0, + "RotationSkewX": 30.0, + "AnchorPoint": { + "ScaleX": -0.1, + "ScaleY": 0.1 + }, + "CColor": {}, + "Size": { + "X": 76.0, + "Y": 26.0 + }, + "FrameEvent": "", + "Name": "BitmapFontLabel_3", + "ctype": "TextBMFontObjectData" + }, + { + "ImageFileData": { + "Type": "Default", + "Path": "Default/LoadingBarFile.png" + }, + "Tag": 69, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.842, + "Y": 0.788 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 100, + "Position": { + "X": 862.1818, + "Y": 605.1819 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 14.0 + }, + "FrameEvent": "", + "Name": "LoadingBar_3", + "ctype": "LoadingBarObjectData" + }, + { + "ProgressInfo": 50, + "ProgressType": "Right_To_Left", + "ImageFileData": { + "Type": "Normal", + "Path": "LoadingBar/pipe2.png" + }, + "Tag": 70, + "ObjectIndex": 4, + "PrePosition": { + "X": 0.8473, + "Y": 0.5951 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 101, + "Position": { + "X": 867.6357, + "Y": 456.9999 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": { + "R": 215, + "G": 229, + "B": 12 + }, + "Size": { + "X": 214.0, + "Y": 24.0 + }, + "FrameEvent": "", + "Name": "LoadingBar_4", + "ctype": "LoadingBarObjectData" + }, + { + "BackGroundData": { + "Type": "Default", + "Path": "Default/Slider_Back.png" + }, + "ProgressBarData": { + "Type": "Default", + "Path": "Default/Slider_PressBar.png" + }, + "BallNormalData": { + "Type": "Default", + "Path": "Default/SliderNode_Normal.png" + }, + "BallPressedData": { + "Type": "Default", + "Path": "Default/SliderNode_Press.png" + }, + "BallDisabledData": { + "Type": "Default", + "Path": "Default/SliderNode_Disable.png" + }, + "PercentInfo": 50, + "TouchEnable": true, + "Tag": 71, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.8713, + "Y": 0.524 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 102, + "Position": { + "X": 892.1815, + "Y": 402.4546 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 14.0 + }, + "FrameEvent": "", + "Name": "Slider_3", + "ctype": "SliderObjectData" + }, + { + "BackGroundData": { + "Type": "Normal", + "Path": "LoadingBar/channel1.png" + }, + "ProgressBarData": { + "Type": "Normal", + "Path": "LoadingBar/pipe2.png" + }, + "BallNormalData": { + "Type": "Default", + "Path": "Default/SliderNode_Normal.png" + }, + "BallPressedData": { + "Type": "Default", + "Path": "Default/SliderNode_Press.png" + }, + "BallDisabledData": { + "Type": "Default", + "Path": "Default/SliderNode_Disable.png" + }, + "PercentInfo": 100, + "TouchEnable": true, + "Tag": 72, + "ObjectIndex": 4, + "PrePosition": { + "X": 0.8507, + "Y": 0.3765 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 103, + "Position": { + "X": 871.0895, + "Y": 289.1812 + }, + "Scale": { + "ScaleX": 0.74, + "ScaleY": 1.2 + }, + "Rotation": 10.9993, + "RotationSkewX": 10.9993, + "RotationSkewY": -3.9987, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 173, + "CColor": { + "R": 42, + "G": 223, + "B": 0 + }, + "Size": { + "X": 244.0, + "Y": 56.0 + }, + "FrameEvent": "", + "Name": "Slider_1", + "ctype": "SliderObjectData" + }, + { + "FontSize": 20, + "LabelText": "Text Label", + "Tag": 105, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.3267, + "Y": 0.3917 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 134, + "Position": { + "X": 334.5708, + "Y": 300.8571 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 91.0, + "Y": 23.0 + }, + "FrameEvent": "", + "Name": "Text_5", + "ctype": "TextObjectData" + }, + { + "FontSize": 20, + "IsCustomSize": true, + "LabelText": "", + "PlaceHolderText": "Text Field", + "MaxLengthText": 10, + "TouchEnable": true, + "Tag": 111, + "ObjectIndex": 4, + "PrePosition": { + "X": 0.7792, + "Y": 0.2294 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 140, + "Position": { + "X": 797.8571, + "Y": 176.1429 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 95.0, + "Y": 27.0 + }, + "FrameEvent": "", + "Name": "TextField_4", + "ctype": "TextFieldObjectData" + }, + { + "FontSize": 48, + "IsCustomSize": true, + "LabelText": "触控科技", + "PlaceHolderText": "wanwan", + "MaxLengthText": 10, + "TouchEnable": true, + "Tag": 112, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.8501, + "Y": 0.0517 + }, + "PreSize": { + "X": 0.1953, + "Y": 0.0781 + }, + "ActionTag": 141, + "Position": { + "X": 865.4731, + "Y": 56.3811 + }, + "Scale": { + "ScaleX": 1.2, + "ScaleY": 1.2 + }, + "Rotation": -10.0, + "RotationSkewX": -10.0, + "RotationSkewY": -10.0, + "AnchorPoint": { + "ScaleX": 0.4, + "ScaleY": 0.3 + }, + "Alpha": 0, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 60.0 + }, + "FrameEvent": "123", + "Name": "TextField_5", + "ctype": "TextFieldObjectData" + }, + { + "FileData": { + "Type": "Default", + "Path": "Default/defaultParticle.plist" + }, + "Tag": 113, + "ObjectIndex": 4, + "PrePosition": { + "X": 0.4402, + "Y": 0.0694 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 142, + "Position": { + "X": 450.7145, + "Y": 53.2857 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 0.0, + "Y": 0.0 + }, + "FrameEvent": "", + "Name": "Particle_4", + "ctype": "ParticleObjectData" + }, + { + "CharWidth": 14, + "CharHeight": 18, + "LabelText": "./0123456789", + "StartChar": ".", + "LabelAtlasFileImage_CNB": { + "Type": "Default", + "Path": "Default/TextAtlas.png" + }, + "Tag": 119, + "ObjectIndex": 1, + "PrePosition": { + "X": 0.5642, + "Y": 0.2693 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 148, + "Position": { + "X": 577.7139, + "Y": 206.8564 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 168.0, + "Y": 18.0 + }, + "FrameEvent": "", + "Name": "AtlasLabel_1", + "ctype": "TextAtlasObjectData" + }, + { + "CharWidth": 22, + "CharHeight": 26, + "LabelText": "", + "StartChar": ".", + "LabelAtlasFileImage_CNB": { + "Type": "Normal", + "Path": "fonts_weapon_001-hd.png" + }, + "Tag": 120, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.5628, + "Y": 0.221 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 149, + "Position": { + "X": 576.2854, + "Y": 169.7141 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 264.0, + "Y": 26.0 + }, + "FrameEvent": "", + "Name": "AtlasLabel_2", + "ctype": "TextAtlasObjectData" + }, + { + "CharWidth": 22, + "CharHeight": 26, + "LabelText": "123/0.78", + "StartChar": ".", + "LabelAtlasFileImage_CNB": { + "Type": "Normal", + "Path": "fonts_weapon_001-hd.png" + }, + "Tag": 121, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.4223, + "Y": 0.234 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 150, + "Position": { + "X": 432.43, + "Y": 179.7133 + }, + "Scale": { + "ScaleX": 1.3612, + "ScaleY": 2.1577 + }, + "Rotation": -30.0, + "RotationSkewX": -30.0, + "RotationSkewY": 30.0, + "AnchorPoint": { + "ScaleX": -0.21, + "ScaleY": -0.0785 + }, + "Alpha": 128, + "CColor": { + "R": 225, + "G": 46, + "B": 46 + }, + "Size": { + "X": 176.0, + "Y": 26.0 + }, + "FrameEvent": "", + "Name": "AtlasLabel_3", + "ctype": "TextAtlasObjectData" + } + ], + "CanEdit": false, + "Position": { + "X": 0.0, + "Y": 0.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 1024.0, + "Y": 768.0 + }, + "FrameEvent": "", + "Name": "Scene", + "ctype": "SingleNodeObjectData" + }, + "ctype": "GameProjectData" + } + } +} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Node.json b/samples/js-tests/res/cocosui/CCS/2.1/Node.json new file mode 100644 index 0000000000..1a3f42336e --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/2.1/Node.json @@ -0,0 +1,2415 @@ +{ + "ID": "355bd005-ff83-4284-b538-2e0e92e254d7", + "Version": "2.0.0.0", + "Type": "Node", + "Name": "Node", + "Content": { + "Content": { + "Animation": { + "Duration": 10, + "Speed": 1.0, + "Timelines": [ + { + "ActionTag": 84, + "FrameType": "PositionFrame", + "Frames": [ + { + "X": 153.7167, + "Y": 139.1809, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 198.0026, + "Y": 173.4655, + "FrameIndex": 10, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 84, + "FrameType": "ScaleFrame", + "Frames": [ + { + "X": 1.0, + "Y": 1.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 1.0, + "Y": 1.0, + "FrameIndex": 10, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 84, + "FrameType": "RotationSkewFrame", + "Frames": [ + { + "X": -2.9984, + "Y": -3.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 360.0, + "Y": 359.9956, + "FrameIndex": 10, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 165, + "FrameType": "PositionFrame", + "Frames": [ + { + "X": -285.0015, + "Y": -231.6454, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": -286.4302, + "Y": -277.3599, + "FrameIndex": 10, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 165, + "FrameType": "ScaleFrame", + "Frames": [ + { + "X": 1.0, + "Y": 1.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 1.1524, + "Y": 1.3643, + "FrameIndex": 10, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + }, + { + "ActionTag": 165, + "FrameType": "RotationSkewFrame", + "Frames": [ + { + "X": 0.0, + "Y": 0.0, + "FrameIndex": 0, + "ctype": "PointFrameData" + }, + { + "X": 0.0, + "Y": 0.0, + "FrameIndex": 10, + "ctype": "PointFrameData" + } + ], + "ctype": "TimelineData" + } + ], + "ctype": "TimelineActionData" + }, + "AnimationList": [], + "ObjectData": { + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "ComboBoxIndex": 2, + "SingleColor": { + "R": 231, + "G": 191, + "B": 76 + }, + "FirstColor": { + "R": 231, + "G": 191, + "B": 76 + }, + "EndColor": { + "R": 212, + "G": 42, + "B": 42 + }, + "ColorVector": { + "ScaleX": 1.0 + }, + "ColorAngle": 360.0, + "TouchEnable": true, + "Tag": 40, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "IsBounceEnabled": true, + "InnerNodeSize": { + "Width": 400, + "Height": 300 + }, + "ScrollDirectionType": "Vertical_Horizontal", + "FileData": { + "Type": "Normal", + "Path": "Slider/2013-8-13 15-44-11.png" + }, + "SingleColor": { + "G": 150, + "B": 100 + }, + "FirstColor": { + "G": 150, + "B": 100 + }, + "EndColor": {}, + "ColorVector": { + "ScaleY": 1.0 + }, + "ColorAngle": 90.0, + "Scale9Enable": true, + "LeftEage": 18, + "RightEage": 18, + "TopEage": 12, + "BottomEage": 12, + "Scale9OriginX": 18, + "Scale9OriginY": 12, + "Scale9Width": 36, + "Scale9Height": 11, + "TouchEnable": true, + "Tag": 90, + "ObjectIndex": 3, + "PrePositionEnabled": true, + "PrePosition": { + "X": -0.0009, + "Y": 0.3285 + }, + "PreSizeEnable": true, + "PreSize": { + "X": 0.6667, + "Y": 0.6667 + }, + "Children": [ + { + "FileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Tag": 93, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.0975, + "Y": 0.8691 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 129, + "Position": { + "X": 39.005, + "Y": 260.7225 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 58.0, + "Y": 58.0 + }, + "FrameEvent": "", + "Name": "Sprite_5", + "ctype": "SpriteObjectData" + }, + { + "FileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Enable": true, + "Scale9Width": 58, + "Scale9Height": 58, + "Tag": 95, + "ObjectIndex": 6, + "PrePosition": { + "X": 0.8801, + "Y": 0.5439 + }, + "PreSizeEnable": true, + "PreSize": { + "X": 0.145, + "Y": 0.1933 + }, + "ActionTag": 131, + "Position": { + "X": 352.0493, + "Y": 163.1661 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5352, + "ScaleY": 0.5291 + }, + "CColor": {}, + "Size": { + "X": 58.0, + "Y": 58.0 + }, + "FrameEvent": "", + "Name": "Image_6", + "ctype": "ImageViewObjectData" + }, + { + "ProgressInfo": 100, + "ImageFileData": { + "Type": "Default", + "Path": "Default/LoadingBarFile.png" + }, + "Tag": 42, + "ObjectIndex": 4, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.2944, + "Y": 0.5846 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 78, + "Position": { + "X": 117.7728, + "Y": 175.367 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -10.0, + "RotationSkewX": -10.0, + "RotationSkewY": 4.0, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": { + "R": 15, + "G": 240, + "B": 45 + }, + "Size": { + "X": 200.0, + "Y": 14.0 + }, + "FrameEvent": "", + "Name": "LoadingBar_4", + "ctype": "LoadingBarObjectData" + }, + { + "ProgressInfo": 70, + "ProgressType": "Right_To_Left", + "ImageFileData": { + "Type": "Default", + "Path": "Default/LoadingBarFile.png" + }, + "TouchEnable": true, + "Tag": 46, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.3906, + "Y": 0.3649 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 82, + "Position": { + "X": 156.2222, + "Y": 109.4755 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 168, + "CColor": { + "R": 55, + "G": 218, + "B": 11 + }, + "Size": { + "X": 200.0, + "Y": 14.0 + }, + "FrameEvent": "", + "Name": "LoadingBar_5", + "ctype": "LoadingBarObjectData" + }, + { + "LabelText": "F1234", + "LabelBMFontFile_CNB": { + "Type": "Normal", + "Path": "FNT/futura.fnt" + }, + "Tag": 41, + "ObjectIndex": 3, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.8783, + "Y": 0.7569 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 77, + "Position": { + "X": 351.3342, + "Y": 227.0713 + }, + "Scale": { + "ScaleX": 1.2414, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 58.0, + "Y": 26.0 + }, + "FrameEvent": "", + "Name": "BitmapFontLabel_3", + "ctype": "TextBMFontObjectData" + }, + { + "BackGroundData": { + "Type": "Default", + "Path": "Default/Slider_Back.png" + }, + "ProgressBarData": { + "Type": "Normal", + "Path": "LoadingBar/ui_loading_01.png" + }, + "BallNormalData": { + "Type": "Default", + "Path": "Default/SliderNode_Normal.png" + }, + "BallPressedData": { + "Type": "Default", + "Path": "Default/SliderNode_Press.png" + }, + "BallDisabledData": { + "Type": "Default", + "Path": "Default/SliderNode_Disable.png" + }, + "PercentInfo": 50, + "TouchEnable": true, + "Tag": 47, + "ObjectIndex": 4, + "PrePosition": { + "X": 0.41, + "Y": 0.2016 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 83, + "Position": { + "X": 164.0021, + "Y": 60.484 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.4953, + "ScaleY": 0.4583 + }, + "Alpha": 226, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 14.0 + }, + "FrameEvent": "", + "Name": "Slider_4", + "ctype": "SliderObjectData" + } + ], + "ActionTag": 126, + "Position": { + "X": -0.2811, + "Y": 98.5435 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "Alpha": 113, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 200.0 + }, + "FrameEvent": "", + "Name": "ScrollView_3", + "ctype": "ScrollViewObjectData" + } + ], + "ActionTag": 76, + "Position": { + "X": -757.1329, + "Y": 108.2036 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 0.9667 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 300.0, + "Y": 300.0 + }, + "FrameEvent": "", + "Name": "Panel_3", + "ctype": "PanelObjectData" + }, + { + "BackColorAlpha": 102, + "SingleColor": { + "G": 151, + "B": 150 + }, + "FirstColor": { + "G": 151, + "B": 150 + }, + "EndColor": {}, + "ColorVector": { + "ScaleY": 1.0 + }, + "ColorAngle": 90.0, + "TouchEnable": true, + "Tag": 48, + "ObjectIndex": 4, + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "BackGroundData": { + "Type": "Default", + "Path": "Default/Slider_Back.png" + }, + "ProgressBarData": { + "Type": "Normal", + "Path": "LoadingBar/ui_loading_02.png" + }, + "BallNormalData": { + "Type": "Default", + "Path": "Default/SliderNode_Normal.png" + }, + "BallPressedData": { + "Type": "Default", + "Path": "Default/SliderNode_Press.png" + }, + "BallDisabledData": { + "Type": "Default", + "Path": "Default/SliderNode_Disable.png" + }, + "PercentInfo": 50, + "DisplayState": false, + "TouchEnable": true, + "Tag": 49, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.52, + "Y": 0.87 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 85, + "Position": { + "X": 104.0, + "Y": 174.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -10.0, + "RotationSkewX": -10.0, + "RotationSkewY": 3.0, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 184, + "CColor": { + "R": 18, + "G": 232, + "B": 4 + }, + "Size": { + "X": 200.0, + "Y": 14.0 + }, + "FrameEvent": "", + "Name": "Slider_5", + "ctype": "SliderObjectData" + }, + { + "FontSize": 24, + "LabelText": "1234", + "IsCustomSize": true, + "FontResource": { + "Type": "Normal", + "Path": "ttf/Fingerpop.ttf" + }, + "HorizontalAlignmentType": "HT_Center", + "Tag": 50, + "ObjectIndex": 4, + "PrePosition": { + "X": 0.2379, + "Y": 0.6604 + }, + "PreSize": { + "X": 0.5, + "Y": 0.15 + }, + "ActionTag": 86, + "Position": { + "X": 47.5737, + "Y": 132.0748 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -11.0, + "RotationSkewX": -11.0, + "RotationSkewY": 12.0, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 223, + "CColor": {}, + "Size": { + "X": 100.0, + "Y": 30.0 + }, + "FrameEvent": "", + "Name": "Text_4", + "ctype": "TextObjectData" + }, + { + "FontSize": 36, + "IsCustomSize": true, + "LabelText": "", + "PlaceHolderText": "Text Field", + "MaxLengthEnable": true, + "MaxLengthText": 20, + "PasswordEnable": true, + "TouchEnable": true, + "Tag": 52, + "ObjectIndex": 3, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.7159, + "Y": 0.4569 + }, + "PreSizeEnable": true, + "PreSize": { + "X": 0.475, + "Y": 0.135 + }, + "ActionTag": 88, + "Position": { + "X": 143.1775, + "Y": 91.376 + }, + "Scale": { + "ScaleX": 0.78, + "ScaleY": 1.0 + }, + "Rotation": 12.0, + "RotationSkewX": 12.0, + "RotationSkewY": -28.0, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": { + "R": 244, + "G": 10, + "B": 10 + }, + "Size": { + "X": 95.0, + "Y": 27.0 + }, + "FrameEvent": "", + "Name": "TextField_3", + "ctype": "TextFieldObjectData" + }, + { + "FontResource": { + "Type": "Normal", + "Path": "ttf/Fingerpop.ttf" + }, + "FontSize": 24, + "IsCustomSize": true, + "LabelText": "", + "PlaceHolderText": "Text Field", + "MaxLengthText": 10, + "Tag": 54, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.105, + "Y": 0.235 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 90, + "Position": { + "X": 21.0, + "Y": 46.9996 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "RotationSkewY": 13.0, + "AnchorPoint": { + "ScaleX": -0.3, + "ScaleY": 0.5 + }, + "Alpha": 119, + "CColor": {}, + "Size": { + "X": 95.0, + "Y": 27.0 + }, + "FrameEvent": "", + "Name": "TextField_5", + "ctype": "TextFieldObjectData" + } + ], + "ActionTag": 84, + "Position": { + "X": 153.7167, + "Y": 139.1809 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -2.9984, + "RotationSkewX": -2.9984, + "RotationSkewY": -3.0, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 200.0 + }, + "FrameEvent": "", + "Name": "Panel_4", + "ctype": "PanelObjectData" + }, + { + "BackColorAlpha": 0, + "ComboBoxIndex": 1, + "SingleColor": { + "R": 150, + "G": 200 + }, + "FirstColor": { + "R": 150, + "G": 200 + }, + "EndColor": {}, + "ColorVector": { + "ScaleY": 1.0 + }, + "ColorAngle": 90.0, + "TouchEnable": true, + "Tag": 134, + "ObjectIndex": 7, + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "IsBounceEnabled": true, + "InnerNodeSize": { + "Width": 225, + "Height": 300 + }, + "ScrollDirectionType": "Vertical", + "ClipAble": true, + "BackColorAlpha": 102, + "FileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_003 copy 221.png" + }, + "SingleColor": { + "G": 150, + "B": 100 + }, + "FirstColor": { + "G": 150, + "B": 100 + }, + "EndColor": {}, + "ColorVector": { + "ScaleY": 1.0 + }, + "ColorAngle": 90.0, + "Scale9Width": 58, + "Scale9Height": 58, + "TouchEnable": true, + "Tag": 83, + "ObjectIndex": 2, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.2135, + "Y": 0.2139 + }, + "PreSize": { + "X": 0.75, + "Y": 0.75 + }, + "Children": [ + { + "FlipX": true, + "FlipY": true, + "FontSize": 24, + "ButtonText": "Button12424", + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Default", + "Path": "Default/Button_Disable.png" + }, + "PressedFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_d.png" + }, + "NormalFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_003 copy 221.png" + }, + "Scale9Enable": true, + "Scale9Width": 58, + "Scale9Height": 58, + "TouchEnable": true, + "Tag": 85, + "ObjectIndex": 11, + "PrePosition": { + "X": 0.0694, + "Y": 0.8159 + }, + "PreSizeEnable": true, + "PreSize": { + "X": 0.23, + "Y": 0.12 + }, + "ActionTag": 121, + "Position": { + "X": 13.8823, + "Y": 244.7697 + }, + "Scale": { + "ScaleX": 1.04, + "ScaleY": 1.0 + }, + "Rotation": 8.0, + "RotationSkewX": 8.0, + "RotationSkewY": -19.0, + "AnchorPoint": { + "ScaleX": -1.0, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 51.75, + "Y": 36.0 + }, + "FrameEvent": "", + "Name": "Button_11", + "ctype": "ButtonObjectData" + }, + { + "FontSize": 24, + "ButtonText": "Button123134", + "FontResource": { + "Type": "Normal", + "Path": "ttf/Fingerpop.ttf" + }, + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Default", + "Path": "Default/Button_Disable.png" + }, + "PressedFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_003 copy 221.png" + }, + "NormalFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Width": 58, + "Scale9Height": 58, + "Tag": 86, + "ObjectIndex": 12, + "PrePosition": { + "X": 0.5121, + "Y": 0.4916 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 122, + "Position": { + "X": 115.2113, + "Y": 147.4902 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 185.0, + "Y": 58.0 + }, + "FrameEvent": "", + "Name": "Button_12", + "ctype": "ButtonObjectData" + }, + { + "DisplayState": false, + "NormalBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Normal.png" + }, + "PressedBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Press.png" + }, + "DisableBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Disable.png" + }, + "NodeNormalFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Normal.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "TouchEnable": true, + "Tag": 91, + "ObjectIndex": 8, + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 127, + "Position": { + "X": 34.3278, + "Y": 106.8929 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 40.0, + "Y": 40.0 + }, + "FrameEvent": "", + "Name": "CheckBox_8", + "ctype": "CheckBoxObjectData" + }, + { + "CheckedState": true, + "NormalBackFileData": { + "Type": "Normal", + "Path": "CheckBox/blue_cloud.png" + }, + "PressedBackFileData": { + "Type": "Normal", + "Path": "CheckBox/button_common_box03_p.png" + }, + "DisableBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Disable.png" + }, + "NodeNormalFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Normal.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "Tag": 92, + "ObjectIndex": 9, + "PrePosition": { + "X": 0.6175, + "Y": 0.2552 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 128, + "Position": { + "X": 123.5059, + "Y": 76.5519 + }, + "Scale": { + "ScaleX": 1.03, + "ScaleY": 1.0 + }, + "Rotation": 34.0, + "RotationSkewX": 34.0, + "RotationSkewY": 8.0, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "Alpha": 189, + "CColor": { + "R": 16, + "G": 242, + "B": 12 + }, + "Size": { + "X": 96.0, + "Y": 96.0 + }, + "FrameEvent": "", + "Name": "CheckBox_9", + "ctype": "CheckBoxObjectData" + } + ], + "ActionTag": 119, + "Position": { + "X": 64.0566, + "Y": 64.1672 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "Rotation": -11.9985, + "RotationSkewX": -11.9985, + "RotationSkewY": 5.9998, + "AnchorPoint": {}, + "Alpha": 137, + "CColor": { + "R": 213, + "G": 218, + "B": 219 + }, + "Size": { + "X": 225.0, + "Y": 225.0 + }, + "FrameEvent": "", + "Name": "ScrollView_2", + "ctype": "ScrollViewObjectData" + } + ], + "ActionTag": 163, + "Position": { + "X": -277.1454, + "Y": 104.0507 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 300.0, + "Y": 300.0 + }, + "FrameEvent": "", + "Name": "Panel_7", + "ctype": "PanelObjectData" + }, + { + "InnerNodeSize": { + "Width": 400, + "Height": 300 + }, + "ScrollDirectionType": "Horizontal", + "FileData": { + "Type": "PlistSubImage", + "Path": "actor_fish_denglong_dead_005.png", + "Plist": "plist1/Plist.plist" + }, + "ComboBoxIndex": 2, + "SingleColor": { + "R": 232, + "G": 19, + "B": 211 + }, + "FirstColor": { + "R": 232, + "G": 19, + "B": 211 + }, + "EndColor": {}, + "ColorVector": { + "ScaleY": 1.0 + }, + "ColorAngle": 90.0, + "Scale9Width": 412, + "Scale9Height": 300, + "TouchEnable": true, + "Tag": 129, + "ObjectIndex": 5, + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "FileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_003 copy 221.png" + }, + "ComboBoxIndex": 2, + "SingleColor": { + "R": 24, + "G": 17, + "B": 237 + }, + "FirstColor": { + "R": 24, + "G": 17, + "B": 237 + }, + "EndColor": { + "R": 237, + "G": 228, + "B": 14 + }, + "ColorVector": { + "ScaleY": 1.0 + }, + "ColorAngle": 90.0, + "Scale9Enable": true, + "LeftEage": 20, + "RightEage": 20, + "TopEage": 20, + "BottomEage": 20, + "Scale9OriginX": 20, + "Scale9OriginY": 20, + "Scale9Width": 18, + "Scale9Height": 18, + "TouchEnable": true, + "Tag": 5, + "ObjectIndex": 1, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.0071, + "Y": 0.3286 + }, + "PreSizeEnable": true, + "PreSize": { + "X": 0.75, + "Y": 0.6667 + }, + "Children": [ + { + "FontSize": 14, + "ButtonText": "Button", + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Default", + "Path": "Default/Button_Disable.png" + }, + "PressedFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_003 copy 221.png" + }, + "NormalFileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "Scale9Enable": true, + "LeftEage": 20, + "RightEage": 20, + "TopEage": 20, + "BottomEage": 20, + "Scale9OriginX": 20, + "Scale9OriginY": 20, + "Scale9Width": 18, + "Scale9Height": 18, + "TouchEnable": true, + "Tag": 8, + "ObjectIndex": 1, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.21, + "Y": 0.8302 + }, + "PreSizeEnable": true, + "PreSize": { + "X": 0.29, + "Y": 0.29 + }, + "ActionTag": 44, + "Position": { + "X": 63.0, + "Y": 166.0498 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 87.0, + "Y": 58.0 + }, + "FrameEvent": "", + "Name": "Button_1", + "ctype": "ButtonObjectData" + }, + { + "CheckedState": true, + "NormalBackFileData": { + "Type": "Normal", + "Path": "CheckBox/icon_token.png" + }, + "PressedBackFileData": { + "Type": "Normal", + "Path": "CheckBox/icon_done.png" + }, + "DisableBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Disable.png" + }, + "NodeNormalFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Normal.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "TouchEnable": true, + "Tag": 9, + "ObjectIndex": 1, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.8, + "Y": 0.8 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 45, + "Position": { + "X": 240.0, + "Y": 160.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.45, + "ScaleY": 0.425 + }, + "CColor": {}, + "Size": { + "X": 56.0, + "Y": 56.0 + }, + "FrameEvent": "", + "Name": "CheckBox_1", + "ctype": "CheckBoxObjectData" + }, + { + "FileData": { + "Type": "Normal", + "Path": "CheckBox/blue_cloud.png" + }, + "Tag": 10, + "ObjectIndex": 1, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.2703, + "Y": 0.3006 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 46, + "Position": { + "X": 81.0947, + "Y": 60.1249 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 96.0, + "Y": 96.0 + }, + "FrameEvent": "", + "Name": "Sprite_1", + "ctype": "SpriteObjectData" + } + ], + "ActionTag": 41, + "Position": { + "X": 2.8318, + "Y": 98.5835 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "Alpha": 140, + "CColor": {}, + "Size": { + "X": 300.0, + "Y": 200.0 + }, + "FrameEvent": "", + "Name": "Panel_1", + "ctype": "PanelObjectData" + }, + { + "FileData": { + "Type": "PlistSubImage", + "Path": "actor_fish_denglong_dead_008.png", + "Plist": "plist1/Plist.plist" + }, + "ComboBoxIndex": 1, + "SingleColor": { + "R": 150, + "G": 200 + }, + "FirstColor": { + "R": 150, + "G": 200 + }, + "EndColor": {}, + "ColorVector": { + "ScaleY": 1.0 + }, + "ColorAngle": 90.0, + "Scale9Width": 412, + "Scale9Height": 300, + "TouchEnable": true, + "Tag": 130, + "ObjectIndex": 6, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.7615, + "Y": 0.3243 + }, + "PreSize": { + "X": 0.5, + "Y": 0.6667 + }, + "Children": [ + { + "FileData": { + "Type": "Normal", + "Path": "JPG/Avatar14_128.jpg" + }, + "Scale9Enable": true, + "LeftEage": 32, + "RightEage": 32, + "TopEage": 32, + "BottomEage": 32, + "Scale9OriginX": 32, + "Scale9OriginY": 32, + "Scale9Width": 64, + "Scale9Height": 64, + "Tag": 133, + "ObjectIndex": 10, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.3167, + "Y": 0.6083 + }, + "PreSizeEnable": true, + "PreSize": { + "X": 1.0, + "Y": 1.0 + }, + "ActionTag": 162, + "Position": { + "X": 63.332, + "Y": 121.6674 + }, + "Scale": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 200.0 + }, + "FrameEvent": "", + "Name": "Image_10", + "ctype": "ImageViewObjectData" + } + ], + "ActionTag": 159, + "Position": { + "X": 304.6163, + "Y": 97.2898 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "Alpha": 0, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 200.0 + }, + "FrameEvent": "", + "Name": "Panel_6", + "ctype": "PanelObjectData" + } + ], + "ActionTag": 158, + "Position": { + "X": -749.8191, + "Y": -303.6011 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 300.0, + "Y": 300.0 + }, + "FrameEvent": "", + "Name": "ScrollView_5", + "ctype": "ScrollViewObjectData" + }, + { + "IsBounceEnabled": true, + "InnerNodeSize": { + "Width": 300, + "Height": 300 + }, + "ScrollDirectionType": "Vertical", + "ClipAble": true, + "BackColorAlpha": 102, + "FileData": { + "Type": "Normal", + "Path": "dead/actor_fish_denglong_dead_002.png" + }, + "ComboBoxIndex": 1, + "SingleColor": { + "G": 150, + "B": 100 + }, + "FirstColor": { + "G": 150, + "B": 100 + }, + "EndColor": {}, + "ColorVector": { + "ScaleY": 1.0 + }, + "ColorAngle": 90.0, + "Scale9Width": 412, + "Scale9Height": 300, + "TouchEnable": true, + "Tag": 136, + "ObjectIndex": 6, + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "ScrollDirectionType": 0, + "ClipAble": true, + "BackColorAlpha": 102, + "FileData": { + "Type": "PlistSubImage", + "Path": "actor_fish_denglong_dead_003.png", + "Plist": "plist1/Plist.plist" + }, + "ComboBoxIndex": 1, + "SingleColor": { + "R": 150, + "G": 150, + "B": 100 + }, + "FirstColor": { + "R": 150, + "G": 150, + "B": 100 + }, + "EndColor": {}, + "ColorVector": { + "ScaleY": 1.0 + }, + "ColorAngle": 90.0, + "Scale9Enable": true, + "LeftEage": 100, + "RightEage": 100, + "TopEage": 64, + "BottomEage": 64, + "Scale9OriginX": 100, + "Scale9OriginY": 64, + "Scale9Width": 212, + "Scale9Height": 172, + "TouchEnable": true, + "Tag": 128, + "ObjectIndex": 3, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.0, + "Y": 0.5 + }, + "PreSizeEnable": true, + "PreSize": { + "X": 1.0, + "Y": 0.5 + }, + "Children": [ + { + "BackColorAlpha": 0, + "FileData": { + "Type": "Normal", + "Path": "Button/button_common_box03_001.png" + }, + "ComboBoxIndex": 2, + "SingleColor": { + "R": 150, + "G": 200 + }, + "FirstColor": { + "R": 150, + "G": 200 + }, + "EndColor": {}, + "ColorVector": { + "ScaleY": 1.0 + }, + "ColorAngle": 90.0, + "Scale9Width": 58, + "Scale9Height": 58, + "TouchEnable": true, + "Tag": 39, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "FontSize": 14, + "ButtonText": "Button", + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Default", + "Path": "Default/Button_Disable.png" + }, + "PressedFileData": { + "Type": "Default", + "Path": "Default/Button_Press.png" + }, + "NormalFileData": { + "Type": "Default", + "Path": "Default/Button_Normal.png" + }, + "Scale9Width": 46, + "Scale9Height": 36, + "TouchEnable": true, + "Tag": 62, + "ObjectIndex": 7, + "PrePosition": { + "X": 0.2034, + "Y": 0.8484 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 98, + "Position": { + "X": 40.6703, + "Y": 169.6735 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 46.0, + "Y": 36.0 + }, + "FrameEvent": "", + "Name": "Button_7", + "ctype": "ButtonObjectData" + }, + { + "FileData": { + "Type": "Default", + "Path": "Default/defaultParticle.plist" + }, + "Tag": 63, + "ObjectIndex": 3, + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 99, + "Position": { + "X": 100.7826, + "Y": 171.5921 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 0.0, + "Y": 0.0 + }, + "FrameEvent": "", + "Name": "Particle_3", + "ctype": "ParticleObjectData" + }, + { + "FileData": { + "Type": "Default", + "Path": "Default/defaultMap.tmx" + }, + "Tag": 64, + "ObjectIndex": 2, + "PrePosition": { + "X": 0.0439, + "Y": 0.038 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 100, + "Position": { + "X": 8.782, + "Y": 7.5942 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 128.0, + "Y": 64.0 + }, + "FrameEvent": "", + "Name": "Map_2", + "ctype": "GameMapObjectData" + }, + { + "Volume": 0.5, + "Tag": 65, + "ObjectIndex": 3, + "IconVisible": true, + "PrePosition": { + "X": 0.2089, + "Y": 0.553 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 101, + "Position": { + "X": 41.7826, + "Y": 110.5924 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 0.0, + "Y": 0.0 + }, + "FrameEvent": "", + "Name": "Audio_3", + "ctype": "SimpleAudioObjectData" + }, + { + "Tag": 66, + "ObjectIndex": 4, + "IconVisible": true, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.8485, + "Y": 0.7695 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 102, + "Position": { + "X": 254.5427, + "Y": 115.4202 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 0.0, + "Y": 0.0 + }, + "FrameEvent": "", + "Name": "Node_4", + "ctype": "SingleNodeObjectData" + } + ], + "ActionTag": 75, + "Position": { + "X": 0.0, + "Y": 0.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": { + "R": 233, + "G": 9, + "B": 9 + }, + "Size": { + "X": 300.0, + "Y": 150.0 + }, + "FrameEvent": "", + "Name": "Panel_2", + "ctype": "PanelObjectData" + } + ], + "ActionTag": 157, + "Position": { + "X": 0.0, + "Y": 150.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 300.0, + "Y": 150.0 + }, + "FrameEvent": "", + "Name": "PageView_3", + "ctype": "PageViewObjectData" + } + ], + "ActionTag": 165, + "Position": { + "X": -285.0015, + "Y": -231.6454 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 300.0, + "Y": 200.0 + }, + "FrameEvent": "", + "Name": "ScrollView_6", + "ctype": "ScrollViewObjectData" + }, + { + "Tag": 153, + "ObjectIndex": 5, + "IconVisible": true, + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "FontSize": 14, + "ButtonText": "Button", + "TextColor": { + "R": 65, + "G": 65, + "B": 70 + }, + "DisabledFileData": { + "Type": "Default", + "Path": "Default/Button_Disable.png" + }, + "PressedFileData": { + "Type": "Default", + "Path": "Default/Button_Press.png" + }, + "NormalFileData": { + "Type": "Default", + "Path": "Default/Button_Normal.png" + }, + "Scale9Enable": true, + "Scale9Width": 46, + "Scale9Height": 36, + "TouchEnable": true, + "Tag": 144, + "ObjectIndex": 16, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "CheckedState": true, + "NormalBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Normal.png" + }, + "PressedBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Press.png" + }, + "DisableBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Disable.png" + }, + "NodeNormalFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Normal.png" + }, + "NodeDisableFileData": { + "Type": "Default", + "Path": "Default/CheckBoxNode_Disable.png" + }, + "TouchEnable": true, + "Tag": 145, + "ObjectIndex": 11, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.4347, + "Y": -0.8929 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "FileData": { + "Type": "Default", + "Path": "Default/Sprite.png" + }, + "Tag": 146, + "ObjectIndex": 8, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.5357, + "Y": -0.875 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "FileData": { + "Type": "Default", + "Path": "Default/ImageFile.png" + }, + "Scale9Enable": true, + "Scale9Width": 46, + "Scale9Height": 46, + "Tag": 147, + "ObjectIndex": 12, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.4037, + "Y": -0.6988 + }, + "PreSizeEnable": true, + "PreSize": { + "X": 1.0, + "Y": 1.0 + }, + "Children": [ + { + "LabelText": "Fnt Text Label", + "LabelBMFontFile_CNB": { + "Type": "Default", + "Path": "Default/defaultBMFont.fnt" + }, + "Tag": 148, + "ObjectIndex": 4, + "PrePositionEnabled": true, + "PrePosition": { + "X": 1.0733, + "Y": -1.0715 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "ImageFileData": { + "Type": "Default", + "Path": "Default/LoadingBarFile.png" + }, + "Tag": 149, + "ObjectIndex": 6, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.6048, + "Y": -0.5808 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "BackGroundData": { + "Type": "Default", + "Path": "Default/Slider_Back.png" + }, + "ProgressBarData": { + "Type": "Default", + "Path": "Default/Slider_PressBar.png" + }, + "BallNormalData": { + "Type": "Default", + "Path": "Default/SliderNode_Normal.png" + }, + "BallPressedData": { + "Type": "Default", + "Path": "Default/SliderNode_Press.png" + }, + "BallDisabledData": { + "Type": "Default", + "Path": "Default/SliderNode_Disable.png" + }, + "PercentInfo": 50, + "TouchEnable": true, + "Tag": 150, + "ObjectIndex": 6, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.386, + "Y": -1.9898 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 179, + "Position": { + "X": 77.2039, + "Y": -27.8572 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 14.0 + }, + "FrameEvent": "", + "Name": "Slider_6", + "ctype": "SliderObjectData" + } + ], + "ActionTag": 178, + "Position": { + "X": 97.9731, + "Y": -20.9099 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5018, + "ScaleY": -0.2622 + }, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 14.0 + }, + "FrameEvent": "", + "Name": "LoadingBar_6", + "ctype": "LoadingBarObjectData" + } + ], + "ActionTag": 177, + "Position": { + "X": 49.3695, + "Y": -49.287 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 162.0, + "Y": 36.0 + }, + "FrameEvent": "", + "Name": "BitmapFontLabel_4", + "ctype": "TextBMFontObjectData" + } + ], + "ActionTag": 176, + "Position": { + "X": 18.5709, + "Y": -32.1428 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 46.0, + "Y": 46.0 + }, + "FrameEvent": "", + "Name": "Image_12", + "ctype": "ImageViewObjectData" + } + ], + "ActionTag": 175, + "Position": { + "X": 21.4288, + "Y": -35.0016 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 46.0, + "Y": 46.0 + }, + "FrameEvent": "", + "Name": "Sprite_8", + "ctype": "SpriteObjectData" + } + ], + "ActionTag": 174, + "Position": { + "X": 86.9459, + "Y": -32.1426 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 40.0, + "Y": 40.0 + }, + "FrameEvent": "", + "Name": "CheckBox_11", + "ctype": "CheckBoxObjectData" + }, + { + "FontSize": 20, + "LabelText": "Text Label", + "IsCustomSize": true, + "Tag": 151, + "ObjectIndex": 6, + "PrePositionEnabled": true, + "PrePosition": { + "X": 1.5771, + "Y": -0.357 + }, + "PreSizeEnable": true, + "PreSize": { + "X": 0.47, + "Y": 2.2857 + }, + "Children": [ + { + "FontSize": 20, + "IsCustomSize": true, + "LabelText": "", + "PlaceHolderText": "Text Field", + "MaxLengthText": 10, + "TouchEnable": true, + "Tag": 152, + "ObjectIndex": 6, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.2604, + "Y": -0.496 + }, + "PreSizeEnable": true, + "PreSize": { + "X": 1.0106, + "Y": 0.8438 + }, + "Children": [ + { + "CharWidth": 14, + "CharHeight": 18, + "LabelText": "./0123456789", + "StartChar": ".", + "Tag": 154, + "ObjectIndex": 1, + "PrePositionEnabled": true, + "PrePosition": { + "X": 0.3649, + "Y": -0.3299 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 183, + "Position": { + "X": 34.6668, + "Y": -22.9031 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.4973, + "ScaleY": 0.4938 + }, + "CColor": {}, + "Size": { + "X": 168.0, + "Y": 18.0 + }, + "FrameEvent": "", + "Name": "AtlasLabel_1", + "ctype": "TextAtlasObjectData" + } + ], + "ActionTag": 181, + "Position": { + "X": 24.4814, + "Y": -40.8104 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.526, + "ScaleY": 0.5873 + }, + "CColor": {}, + "Size": { + "X": 95.0, + "Y": 69.4286 + }, + "FrameEvent": "", + "Name": "TextField_6", + "ctype": "TextFieldObjectData" + } + ], + "ActionTag": 180, + "Position": { + "X": 315.4294, + "Y": -12.8532 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 94.0, + "Y": 82.2857 + }, + "FrameEvent": "", + "Name": "Text_6", + "ctype": "TextObjectData" + } + ], + "ActionTag": 173, + "Position": { + "X": 0.0, + "Y": 0.0 + }, + "Scale": { + "ScaleX": 1.0644, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.4374, + "ScaleY": 0.4306 + }, + "CColor": {}, + "Size": { + "X": 200.0, + "Y": 36.0 + }, + "FrameEvent": "", + "Name": "Button_16", + "ctype": "ButtonObjectData" + } + ], + "ActionTag": 182, + "Position": { + "X": 150.9492, + "Y": -21.8586 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 0.0, + "Y": 0.0 + }, + "FrameEvent": "", + "Name": "Node_5", + "ctype": "SingleNodeObjectData" + } + ], + "Position": { + "X": 0.0, + "Y": 0.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 0.0, + "Y": 0.0 + }, + "FrameEvent": "", + "Name": "Node", + "ctype": "SingleNodeObjectData" + }, + "ctype": "GameProjectData" + } + } +} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Plist/UI.png b/samples/js-tests/res/cocosui/CCS/2.1/Plist/UI.png new file mode 100644 index 0000000000..7e73daf0b7 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Plist/UI.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Plist/ui.plist b/samples/js-tests/res/cocosui/CCS/2.1/Plist/ui.plist new file mode 100644 index 0000000000..0133a4e64d --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/2.1/Plist/ui.plist @@ -0,0 +1,1972 @@ + + + + + frames + + 1.png + + frame + {{410,761},{219,37}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{219,37}} + sourceSize + {219,37} + + 100511_Elements.png + + frame + {{855,943},{109,38}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{109,38}} + sourceSize + {109,38} + + 100511_Elements_bg1.png + + frame + {{359,1348},{117,38}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{117,38}} + sourceSize + {117,38} + + 157.png + + frame + {{319,882},{277,7}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{277,7}} + sourceSize + {277,7} + + 2.png + + frame + {{893,1182},{47,37}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{47,37}} + sourceSize + {47,37} + + 222.png + + frame + {{593,891},{28,28}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{28,28}} + sourceSize + {28,28} + + 3.png + + frame + {{844,1165},{47,37}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{47,37}} + sourceSize + {47,37} + + 333.png + + frame + {{458,1240},{28,28}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{28,28}} + sourceSize + {28,28} + + 4.png + + frame + {{807,1345},{47,37}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{47,37}} + sourceSize + {47,37} + + CocoStudio_AnimationEditor.png + + frame + {{412,1270},{76,78}} + offset + {-1,0} + rotated + + sourceColorRect + {{0,0},{76,78}} + sourceSize + {78,78} + + CocoStudio_DataEditor.png + + frame + {{778,936},{75,79}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{75,79}} + sourceSize + {75,79} + + CocoStudio_SceneEditor.png + + frame + {{330,1270},{76,80}} + offset + {0,-1} + rotated + + sourceColorRect + {{0,2},{76,80}} + sourceSize + {76,82} + + CocoStudio_UIEditor.png + + frame + {{248,1270},{76,80}} + offset + {0,-2} + rotated + + sourceColorRect + {{0,4},{76,80}} + sourceSize + {76,84} + + Elements.png + + frame + {{478,1348},{109,38}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{109,38}} + sourceSize + {109,38} + + Elements_d.png + + frame + {{240,1348},{117,38}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{117,38}} + sourceSize + {117,38} + + Elements_n.png + + frame + {{121,1348},{117,38}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{117,38}} + sourceSize + {117,38} + + Elements_p.png + + frame + {{2,1348},{117,38}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{117,38}} + sourceSize + {117,38} + + FriendCell_choose.png + + frame + {{456,1154},{33,32}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{33,32}} + sourceSize + {33,32} + + FriendCell_chooseBg.png + + frame + {{802,394},{49,49}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{49,49}} + sourceSize + {49,49} + + back.png + + frame + {{943,248},{244,79}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{244,79}} + sourceSize + {244,79} + + back_d.png + + frame + {{943,2},{244,79}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{244,79}} + sourceSize + {244,79} + + backdrop.png + + frame + {{2,324},{281,424}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{281,424}} + sourceSize + {281,424} + + background.png + + frame + {{2,2},{480,320}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{480,320}} + sourceSize + {480,320} + + bg.png + + frame + {{635,921},{112,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{112,31}} + sourceSize + {112,31} + + blaubarry-ui-kit-cr173.png + + frame + {{319,891},{203,33}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{203,33}} + sourceSize + {203,33} + + blaubarry-ui-kit-cr1731.png + + frame + {{757,795},{102,39}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{102,39}} + sourceSize + {102,39} + + blue-buttons_left_d.png + + frame + {{410,670},{221,89}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{221,89}} + sourceSize + {221,89} + + blue-buttons_left_n.png + + frame + {{319,653},{221,89}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{221,89}} + sourceSize + {221,89} + + blue-buttons_right_d.png + + frame + {{783,450},{221,89}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{221,89}} + sourceSize + {221,89} + + blue-buttons_right_n.png + + frame + {{692,450},{221,89}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{221,89}} + sourceSize + {221,89} + + blue_cloud.png + + frame + {{714,1187},{96,96}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{96,96}} + sourceSize + {96,96} + + box.png + + frame + {{916,1270},{42,42}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{42,42}} + sourceSize + {42,42} + + broom.png + + frame + {{686,1089},{96,96}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{96,96}} + sourceSize + {96,96} + + button.png + + frame + {{922,423},{15,30}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{15,30}} + sourceSize + {15,30} + + buttonHighlighted.png + + frame + {{410,653},{15,30}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{15,30}} + sourceSize + {15,30} + + button_common_box03_001.png + + frame + {{807,1285},{58,58}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{58,58}} + sourceSize + {58,58} + + button_common_box03_002.png + + frame + {{784,1123},{58,58}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{58,58}} + sourceSize + {58,58} + + button_common_box03_003.png + + frame + {{784,1063},{58,58}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{58,58}} + sourceSize + {58,58} + + button_common_box03_d.png + + frame + {{537,921},{46,40}} + offset + {0,0} + rotated + + sourceColorRect + {{0,3},{46,40}} + sourceSize + {46,46} + + button_common_box03_n.png + + frame + {{923,983},{46,40}} + offset + {0,0} + rotated + + sourceColorRect + {{0,3},{46,40}} + sourceSize + {46,46} + + button_common_box03_p.png + + frame + {{901,1130},{58,50}} + offset + {0,0} + rotated + + sourceColorRect + {{0,4},{58,50}} + sourceSize + {58,58} + + button_d.png + + frame + {{982,1336},{31,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{31,31}} + sourceSize + {31,31} + + button_menu_shop_001.png + + frame + {{855,983},{66,44}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{66,44}} + sourceSize + {66,44} + + button_menu_shop_002.png + + frame + {{778,1017},{66,44}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{66,44}} + sourceSize + {66,44} + + button_menu_shop_003.png + + frame + {{589,1320},{66,44}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{66,44}} + sourceSize + {66,44} + + button_n.png + + frame + {{982,1303},{31,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{31,31}} + sourceSize + {31,31} + + button_p.png + + frame + {{960,1270},{31,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{31,31}} + sourceSize + {31,31} + + buy_d.png + + frame + {{971,1237},{31,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{31,31}} + sourceSize + {31,31} + + buy_n.png + + frame + {{971,1204},{31,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{31,31}} + sourceSize + {31,31} + + buy_p.png + + frame + {{938,1221},{31,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{31,31}} + sourceSize + {31,31} + + channel1.png + + frame + {{446,612},{244,56}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{244,56}} + sourceSize + {244,56} + + checkbox.png + + frame + {{965,1095},{56,55}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{56,55}} + sourceSize + {56,55} + + checkbox_3d.png + + frame + {{961,1152},{50,51}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{50,51}} + sourceSize + {50,51} + + checkbox_3d_mark.png + + frame + {{488,926},{47,46}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{47,46}} + sourceSize + {47,46} + + checkbox_n.png + + frame + {{965,1038},{56,55}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{56,55}} + sourceSize + {56,55} + + checkbox_p.png + + frame + {{966,981},{56,55}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{56,55}} + sourceSize + {56,55} + + checkbox_u.png + + frame + {{915,1031},{48,47}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{48,47}} + sourceSize + {48,47} + + close.png + + frame + {{520,1320},{26,26}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{26,26}} + sourceSize + {26,26} + + close_01.png + + frame + {{492,1320},{26,26}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{26,26}} + sourceSize + {26,26} + + close_02.png + + frame + {{993,1270},{20,20}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{20,20}} + sourceSize + {20,20} + + close_03.png + + frame + {{612,921},{20,20}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{20,20}} + sourceSize + {20,20} + + close_04.png + + frame + {{998,697},{20,20}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{20,20}} + sourceSize + {20,20} + + delete_d.png + + frame + {{949,1347},{31,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{31,31}} + sourceSize + {31,31} + + delete_n.png + + frame + {{949,1314},{31,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{31,31}} + sourceSize + {31,31} + + delete_p.png + + frame + {{916,1347},{31,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{31,31}} + sourceSize + {31,31} + + down_n.png + + frame + {{942,1182},{15,15}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{15,15}} + sourceSize + {15,15} + + down_p.png + + frame + {{922,455},{15,15}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{15,15}} + sourceSize + {15,15} + + download.png + + frame + {{616,1187},{96,96}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{96,96}} + sourceSize + {96,96} + + edit-clear.png + + frame + {{757,673},{102,120}} + offset + {0,-2} + rotated + + sourceColorRect + {{13,6},{102,120}} + sourceSize + {128,128} + + gold.png + + frame + {{635,1373},{16,13}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{16,13}} + sourceSize + {16,13} + + home_button03.png + + frame + {{985,719},{136,34}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{136,34}} + sourceSize + {136,34} + + home_button_n.png + + frame + {{874,423},{167,46}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{167,46}} + sourceSize + {167,46} + + home_button_p.png + + frame + {{582,1052},{125,35}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{125,35}} + sourceSize + {125,35} + + home_button_un.png + + frame + {{319,926},{167,46}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{167,46}} + sourceSize + {167,46} + + icon_done.png + + frame + {{915,1080},{48,48}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{48,48}} + sourceSize + {48,48} + + icon_token.png + + frame + {{966,923},{56,56}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{56,56}} + sourceSize + {56,56} + + ji-9.png + + frame + {{853,334},{87,88}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{87,88}} + sourceSize + {87,88} + + lable.png + + frame + {{924,317},{15,15}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{15,15}} + sourceSize + {15,15} + + ld01.png + + frame + {{446,364},{405,28}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{405,28}} + sourceSize + {405,28} + + ld02.png + + frame + {{446,334},{405,28}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{405,28}} + sourceSize + {405,28} + + ld03.png + + frame + {{484,304},{405,28}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{405,28}} + sourceSize + {405,28} + + leather-ui-elements_0000s_0002_Ellipse.png + + frame + {{998,649},{24,24}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{24,24}} + sourceSize + {24,24} + + leather-ui-elements_0000s_0008_Rectangle.png + + frame + {{2,750},{400,300}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{400,300}} + sourceSize + {400,300} + + leather-ui-elements_0001s_0000_Shape-141-copy.png + + frame + {{998,675},{20,20}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{20,20}} + sourceSize + {20,20} + + leather-ui-elements_0001s_0001_Shape-141-copy-2.png + + frame + {{1004,1204},{18,18}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{18,18}} + sourceSize + {18,18} + + leather-ui-elements_0001s_0002_Shape-141.png + + frame + {{548,1320},{22,23}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{22,23}} + sourceSize + {22,23} + + leather-ui-elements_0005s_0002s_0003_Background.png + + frame + {{285,653},{53,15}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{53,15}} + sourceSize + {53,15} + + lian-1.png + + frame + {{723,1285},{82,82}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{82,82}} + sourceSize + {82,82} + + lian-2.png + + frame + {{635,1285},{86,86}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{86,86}} + sourceSize + {86,86} + + login01.png + + frame + {{484,2},{400,300}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{400,300}} + sourceSize + {400,300} + + login03.png + + frame + {{446,529},{239,81}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{239,81}} + sourceSize + {239,81} + + news_source.png + + frame + {{588,1089},{96,96}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{96,96}} + sourceSize + {96,96} + + next.png + + frame + {{2,1269},{244,77}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{244,77}} + sourceSize + {244,77} + + next_d.png + + frame + {{446,450},{244,77}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{244,77}} + sourceSize + {244,77} + + pipe1.png + + frame + {{410,852},{214,24}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{214,24}} + sourceSize + {214,24} + + pipe2.png + + frame + {{410,826},{214,24}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{214,24}} + sourceSize + {214,24} + + pipe3.png + + frame + {{410,800},{214,24}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{214,24}} + sourceSize + {214,24} + + play.png + + frame + {{867,1334},{47,47}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{47,47}} + sourceSize + {47,47} + + play_p.png + + frame + {{867,1285},{47,47}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{47,47}} + sourceSize + {47,47} + + play_un.png + + frame + {{889,1221},{47,47}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{47,47}} + sourceSize + {47,47} + + psd6368_07.png + + frame + {{916,1314},{31,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{31,31}} + sourceSize + {31,31} + + psd6368_08.png + + frame + {{891,300},{31,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{31,31}} + sourceSize + {31,31} + + recover_d.png + + frame + {{845,1252},{31,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{31,31}} + sourceSize + {31,31} + + recover_n.png + + frame + {{812,1252},{31,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{31,31}} + sourceSize + {31,31} + + recover_p.png + + frame + {{579,921},{31,31}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{31,31}} + sourceSize + {31,31} + + runner.png + + frame + {{680,954},{96,96}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{96,96}} + sourceSize + {96,96} + + setup.png + + frame + {{582,954},{96,96}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{96,96}} + sourceSize + {96,96} + + sign-in icon.png + + frame + {{456,1189},{18,18}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{18,18}} + sourceSize + {18,18} + + sign-in icon1.png + + frame + {{853,423},{18,18}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{18,18}} + sourceSize + {18,18} + + sign-in icon3.png + + frame + {{924,300},{15,15}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{15,15}} + sourceSize + {15,15} + + sign-in3.png + + frame + {{319,878},{286,2}} + offset + {0,-92} + rotated + + sourceColorRect + {{136,361},{286,2}} + sourceSize + {558,540} + + sign-in_home.png + + frame + {{285,324},{327,159}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{327,159}} + sourceSize + {327,159} + + slidebutton_off.png + + frame + {{855,943},{109,38}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{109,38}} + sourceSize + {109,38} + + slidebutton_on.png + + frame + {{478,1348},{109,38}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{109,38}} + sourceSize + {109,38} + + slider01.png + + frame + {{304,673},{300,13}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{300,13}} + sourceSize + {300,13} + + slider_n.png + + frame + {{572,1320},{18,15}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{18,15}} + sourceSize + {18,15} + + slider_p.png + + frame + {{302,653},{18,15}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{18,15}} + sourceSize + {18,15} + + tab.png + + frame + {{846,1029},{67,28}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{67,28}} + sourceSize + {67,28} + + tab_d.png + + frame + {{812,1183},{67,28}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{67,28}} + sourceSize + {67,28} + + tab_n.png + + frame + {{524,891},{67,28}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{67,28}} + sourceSize + {67,28} + + tab_p.png + + frame + {{709,1052},{67,28}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{67,28}} + sourceSize + {67,28} + + teehanlax - iOS 6 - iPhone(off).png + + frame + {{300,1154},{154,54}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{154,54}} + sourceSize + {154,54} + + teehanlax - iOS 6 - iPhone(on).png + + frame + {{334,1098},{154,54}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{154,54}} + sourceSize + {154,54} + + teehanlax - iOS 6 - iPhone_check.png + + frame + {{867,1059},{46,47}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{46,47}} + sourceSize + {46,47} + + teehanlax - iOS 6 - iPhone_check01.png + + frame + {{842,1204},{46,45}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{46,45}} + sourceSize + {46,45} + + teehanlax - iOS 6 - iPhone_mark.png + + frame + {{998,622},{25,24}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{25,24}} + sourceSize + {25,24} + + teehanlax - iOS 6 - iPhone_mark01.png + + frame + {{998,595},{24,25}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{24,25}} + sourceSize + {24,25} + + tick001.png + + frame + {{844,1108},{55,55}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{55,55}} + sourceSize + {55,55} + + title.png + + frame + {{2,1221},{287,46}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{287,46}} + sourceSize + {287,46} + + top.png + + frame + {{2,1152},{296,67}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{296,67}} + sourceSize + {296,67} + + ui_loading_01.png + + frame + {{446,394},{354,28}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{354,28}} + sourceSize + {354,28} + + ui_loading_02.png + + frame + {{446,424},{348,24}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{348,24}} + sourceSize + {348,24} + + under.png + + frame + {{886,2},{296,55}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{296,55}} + sourceSize + {296,55} + + up_n.png + + frame + {{285,708},{15,15}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{15,15}} + sourceSize + {15,15} + + up_p.png + + frame + {{616,1285},{15,15}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{15,15}} + sourceSize + {15,15} + + user01.png + + frame + {{631,797},{122,122}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{122,122}} + sourceSize + {122,122} + + user02.png + + frame + {{492,1196},{122,122}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{122,122}} + sourceSize + {122,122} + + user03.png + + frame + {{861,719},{122,122}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{122,122}} + sourceSize + {122,122} + + user04.png + + frame + {{633,673},{122,122}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{122,122}} + sourceSize + {122,122} + + user05.png + + frame + {{874,595},{122,122}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{122,122}} + sourceSize + {122,122} + + user06.png + + frame + {{458,974},{122,122}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{122,122}} + sourceSize + {122,122} + + user07.png + + frame + {{334,974},{122,122}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{122,122}} + sourceSize + {122,122} + + value.png + + frame + {{291,1240},{165,28}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{165,28}} + sourceSize + {165,28} + + value_d.png + + frame + {{300,1210},{165,28}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{165,28}} + sourceSize + {165,28} + + value_p.png + + frame + {{304,975},{165,28}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{165,28}} + sourceSize + {165,28} + + vectorglass-and-metal-buttons.png + + frame + {{857,843},{98,100}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{98,100}} + sourceSize + {98,100} + + vectorglass-and-metal-buttons_01.png + + frame + {{922,494},{99,100}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{99,100}} + sourceSize + {99,100} + + vectorglass-and-metal-buttons_03.png + + frame + {{755,836},{98,100}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{98,100}} + sourceSize + {98,100} + + whirl.png + + frame + {{490,1098},{96,96}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{96,96}} + sourceSize + {96,96} + + yu-2-quan.png + + frame + {{959,857},{64,60}} + offset + {0,0} + rotated + + sourceColorRect + {{0,0},{64,60}} + sourceSize + {64,60} + + + metadata + + format + 2 + realTextureFileName + UI.png + size + {1024,1388} + smartupdate + $TexturePacker:SmartUpdate:5f780761feec384f580d1b10867d9c69:1/1$ + textureFileName + UI.png + + + diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Slider/2013-8-13 15-44-11.png b/samples/js-tests/res/cocosui/CCS/2.1/Slider/2013-8-13 15-44-11.png new file mode 100644 index 0000000000..cd5aafc10b Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Slider/2013-8-13 15-44-11.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/Slider/teehanlax - iOS 6 - iPhone_slider01.png b/samples/js-tests/res/cocosui/CCS/2.1/Slider/teehanlax - iOS 6 - iPhone_slider01.png new file mode 100644 index 0000000000..ff443f0a59 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/Slider/teehanlax - iOS 6 - iPhone_slider01.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/dead/actor_fish_denglong_dead_001.png b/samples/js-tests/res/cocosui/CCS/2.1/dead/actor_fish_denglong_dead_001.png new file mode 100644 index 0000000000..588234238f Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/dead/actor_fish_denglong_dead_001.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/dead/actor_fish_denglong_dead_002.png b/samples/js-tests/res/cocosui/CCS/2.1/dead/actor_fish_denglong_dead_002.png new file mode 100644 index 0000000000..af2a4d608b Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/dead/actor_fish_denglong_dead_002.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/ditu/isometric_grass_and_water.png b/samples/js-tests/res/cocosui/CCS/2.1/ditu/isometric_grass_and_water.png new file mode 100644 index 0000000000..b342a0cb43 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/ditu/isometric_grass_and_water.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/ditu/isometric_grass_and_water.tmx b/samples/js-tests/res/cocosui/CCS/2.1/ditu/isometric_grass_and_water.tmx new file mode 100644 index 0000000000..7c8ee7baac --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/2.1/ditu/isometric_grass_and_water.tmx @@ -0,0 +1,9 @@ + + + + + + eJzVzM0KQEAYRuHJ38LCv7CVQbn/+3PUp96NGll560kzc+LcvzeIkE0iZAVKVHaeH7rWvpuIESFBikzau1+xW69rrLnePBa796LGgREdeuvzl/2X/5+q7QaO + + + diff --git a/samples/js-tests/res/cocosui/CCS/2.1/ditu/isometric_grass_and_water2.tmx b/samples/js-tests/res/cocosui/CCS/2.1/ditu/isometric_grass_and_water2.tmx new file mode 100644 index 0000000000..b7bb2621af --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/2.1/ditu/isometric_grass_and_water2.tmx @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eJx1lttywjAMROVgyqVtAoFC/v9L68xoh5PFPGhIYktrrVYyS0QszZ7Nvpvd0n7y24L1Q7MhrTSreN/le821HZ7lv9qYa6sdE0cYs/kX7PXYwtfaevYp7WDrd+SnHByjYr/npP1zZ4/elcuM71rjeckdc5KNHX75fMwc9s2uzb6AsYstJzwrv5/Tz89SLIZy8v203llV8xl7yMU+462/v81OqA114/UhrzUxRqwprnh6ZGzp2PNQfPqRu/X9hnMV8F/xLg1L42erDf2oaa2RI2qPtbgbhmw2H69nMUxx/gVccXdC3AW/o/HV60vW59Lhu8arDxmfGIPFUV1qbLVQEIs4PlOeHQxqVjmzr5mLYsmf+5Qj5yM1r3Ne4p1D5VcMh3qWZibLx2fYkBhPYOv81I9wbrGd45zFU7zrndpwDjkHXXfej9zHc3EG+D3AWcCZMJif7hTnVxr6i9edtoBDz8N7kxqbY6sN9gJnsnqIOqCme7Un76579sIV8dccHvHqZefH76BP9wjzkVapM2rL+5/8cR6QS9eh8p2AT12y5oO9+7yh5hzLZypnHX29/pzB9PE7bOg8Mza5KvGu4R7mp/89zqvr7x+TnxEn + + + diff --git a/samples/js-tests/res/cocosui/CCS/2.1/fonts_weapon_001-hd.png b/samples/js-tests/res/cocosui/CCS/2.1/fonts_weapon_001-hd.png new file mode 100644 index 0000000000..ae99fa0045 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/fonts_weapon_001-hd.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/particle/blue.plist b/samples/js-tests/res/cocosui/CCS/2.1/particle/blue.plist new file mode 100644 index 0000000000..8d51554aec --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/2.1/particle/blue.plist @@ -0,0 +1,102 @@ + + + + + angle + 0.0 + angleVariance + 360 + blendFuncDestination + 1 + blendFuncSource + 771 + duration + -1 + emitterType + 0.0 + finishColorAlpha + 1 + finishColorBlue + 0.0 + finishColorGreen + 0.0 + finishColorRed + 0.0 + finishColorVarianceAlpha + 0.0 + finishColorVarianceBlue + 0.0 + finishColorVarianceGreen + 0.0 + finishColorVarianceRed + 0.0 + finishParticleSize + 0.0 + finishParticleSizeVariance + 0.0 + gravityx + 0.0 + gravityy + 60 + maxParticles + 500 + maxRadius + 100 + maxRadiusVariance + 0.0 + minRadius + 0.0 + particleLifespan + 1 + particleLifespanVariance + 1.7999999523162842 + radialAccelVariance + 0.0 + radialAcceleration + 0.0 + rotatePerSecond + 0.0 + rotatePerSecondVariance + 0.0 + sourcePositionVariancex + 20 + sourcePositionVariancey + 20 + sourcePositionx + 162.83000183105469 + sourcePositiony + 103.05999755859375 + speed + 30 + speedVariance + 0.10000000149011612 + startColorAlpha + 1 + startColorBlue + 1 + startColorGreen + 0.3762499988079071 + startColorRed + 0.0 + startColorVarianceAlpha + 0.5 + startColorVarianceBlue + 0.20000000298023224 + startColorVarianceGreen + 0.20000000298023224 + startColorVarianceRed + 0.20000000298023224 + startParticleSize + 30 + startParticleSizeVariance + 5 + tangentialAccelVariance + 0.0 + tangentialAcceleration + 0.0 + textureFileName + blue.png + textureImageData + H4sIAAAAAAAAA+1bB1RURxd+byu9g1RZpINUpVtoKoiKIqJYorisdESqLRINkihGjSHEFo0EC/ZoRCRWLMRoFHuPEIMlNizY4/5z3fvic7MrmJic84vr+Tjj7My997tt5i1L796UE0UFqlD/wUsqldJvgv/CJrTr35KrjBunGfyn/nib/FvIldsMmvXJWzOYejv8X8OZzYsnB74c5N9X5pO36od/wl8Jb3m+DD8BQtgMmHXyfpH3xVvxw9/h3wLe8nxVCFQRaiyoI9hzzDoVBf546354U/4t5M3mzPDUINAk0CLQVgItXKPB8ou8L17rh3+TvxLu8rwZzgxf4KVDoEugR6BPYEBgKAcDfE8P1+rgXsYfjC8U+eFv+6Al/BXkOzvminhrof16yMuIwJjAhMCUwIzAnMACYY5zprjGGPcYoAwdlKnID/K58Eb10Bz/FsRcRY63LsaR4WyGHC0JrAisCWwIbOVgg+9Z4VoL3Mv4Qh9ls/2g8k9zoYX8FXFnYq6OOarD4m2CMbVETsDPgcCJoD2BK4EbgTvCDefa4xoH3GONMsxRJuMHHdSpzsoFhT74J/ylf815ee4QB23MUUMWbxHG0wE5AT9PAi8CXwJ/ggA5+ON7XrjWDfc6oCwRyw+GqFMbbVDmg2ZzQBn/Zrgz+a7NirkZxgpsdSRwQR7eyK0LQRBBKEF3gjCCcEQYzoXimi64xxtluKBMG9RhxsoFxgdqf8cHivi3kDuT78YYF6hbe4wZ2OxD0JkgmKAHQQRBJEEUQTRBDMFARAzOReGaCNwTjDJ8UGZ71GGFOo2lL+vhb/ngNfzZNS+f82zu0KesMT5uGLNOBCEY20jkFkswjCCOQEwgIRiFkOBcHK6JxT2RKCMEZXqjDkfUaaHAB+xaaLYXyPNXEnuB9NV6Z7i3lcpyEnqWh1RWv4EYuz4EAwiGEowkSCBIJcggyCLIIchF5OBcBq5JwD1DUUYflBmIOjxQpw3awPiA3Q/YZ6PSHFDCX547nDPqctwtUL+zVJabUK+Qr5C7/QmGYEyTCcYgzwkE+QQfE0wlKERMxbl8XJOLe5JRxhCUGYE6/FGnM9rAzgNttJU5G1/xwev4K4g9u+bhvIGeC30Has8aYwB2QP+G3tVbKqvl4QSJGM+xyAs4FhHMIphDUExQgijGuVm4ZiruGYsyElFmDOoIRZ2eaIM12mSENmpKX+0FSnNAAX9leQ/1BecO9F7oP1CDHhgLsAdydJBUlrcpUllOT8L4zkSO8wkWEZQSlBEsRZTh3CJcU4x7ClFGDsociTr6oE5/tMERbTJDG9m94LU5wPBvJvZw54LcgrPXUirrwdCHoBaDMSZgF+RqOsZtCsYSuCxEfisIVhOsJ9hAsBGxAedW45pS3FOMMqagzHTUMQh1BqMNbmiTJdqojzY3mwNy/JXFHu6dTN5DvcE5BL0Y+hHUZAzGBuwbR1CA8ZtLsISgHPltIqgi2Eawg2AnYgfOVeGa9bhnCcqYiTLHoY6RqDMCbfBGm2ykL+tAtyU5oIS/stjDHQxyDeoOziPoydCXhktl+TkW7ZwtleUx5PUa5LSVYBfBPoL9BAcIDiIO4Nw+XLMV96xBGfNRZgHqSEGd/dGGTmiTI9rYbA6w+UtfzX12z2fqnh17uIvBfQTOZKhD6M3Qn6BGp2CswF6o63UElRjjGuRaS3CM4CTBKcRJnKvFNTW4pxJlLEWZM1FHDuocgjaEoE0ucjnA9AH2WfBKDbD4K8p9pufD2WIpld3Fwc9wJ4N7CZzNUI/Qo6FPQa3OxZiB3VsIqgl+Qm4nCM4QnCe4SFCHuIhzZ3BNLe6pRhnrUOZc1DEJdYrRhnC0yRNttESbmbNAaQ0o4M/OfThL4Rkc+iqcMUzdQ9+BuxncT+CMhpyEXg39Cmp2DcYO7IfcPkpwmuACQT3BbwSXCa4gLuNcPa45jXsOoIxKlLkEdRSizmS0IRJtYvqANdpsgByU1oAS/sx9h8l9uF/A8yj0WThzoObgfgp9CO4p+VJZbkLPhr4FtbsTYwg8zmKMgeNVgt8JbhDcRNzAuau45iLuOYoydqLMctQxE3WOQRui0SZ/tNEWbWZqgLkPNcdfUd+Xz314NoO+C3d0uKfCXW0qxgXOLejd0L+ghmsxlsCnATkC39sEdwjuIu7g3E1c04B7TqOMGpS5HnUUo85ctCEWbeoi/WsNKDoH2J8TKePP1D70UrhbwD0Lns3h+RTyDZ5T4K4O91WoSehPKzBO0MOhj0EtX8CYAq9byPUeQZMc7uF7t3Dtb7j3BMrahbJXoK4i1J2KtkSibV5oqxXarqgHyPNn9z75cw8+k2NqH+4acO+C51R4VoMelC+V3Vvh7gb3FzjD92HcoJ9BTV/F2AK/+wQPCB4SPEI8xLn7uOYm7qlHGbUoswp1LEKd+WhDHNoUijYyPcBU+tdzUP6ZSBl/du+DMwU+n4L6gs8poN6g98IzGzy3wN2dyX24x8BZDufZeenL2N/GGD9Azo8JniAe49wDXHNb+jIHzqOs/SibqYE5qDsLbYlG2/zRVhup4h74Ov7yvR/u0nCWMr0Pnjngsxq4e8EzO5zDTO3D+QT32B1SWd+GM/2iVNbbb2BcmzDWDPenCMYHD3HNHdxzGWWcRJk7UEeZ9GUPyEFbYtC2AOnLHmiOHJSeAUr4M8+6sJfp/e4oG85a+MwGPreA/gNnETzDwR0F7vLQq6Fe4V4DZzucb5DPd5HbIznubB88wjV3cc8VlHEKZe5EHUtRZyHaMAptCkcb3aUvzwCGv/p7/i3m31rzv7X3v9Z6/rX2+8/7++/755/3z7+t+/OPVvv5V2v//PP959/vf//R2n//9f73n6/NgVbx+28lOdCqvv8glwPydfDOf//lNTnQar7/9AY+eCe//9ZCH7zT33+U8wG7F8j74J39/quCHJD3wTv//Wc5H7BrgX02vrPff1fiB2W58E7+/UMLfKDID+/c378o8EFzfnjn/v7pDf3A+ELeH//Xf//WQj+wfcH2h7xf5HnK8+XKyXwrvFm2vw0xjCz6Nb5Q5BNFULSHftu8WTa/TXFsufK+eJ1PlHL9NzjL2flviZbXo8wf/ylfBXZRlBZRxyX/oalA8oNmjTkvxjyKCqyguThPFtMCHHPID114H2YpFVqPtcYQx+Rd2oglsw2zPpCizVnro1gy+/+pd/snWZSQojTCyHjfC5NV8B+N/8h7vZLSR3N0KCotPTszqkewaFDsYJHwEJGkSgkoD4qKE2dl9O7fPRq2h3cLEWWRRYwHZK5+cFI2OOYS1lckekMn6oozMrOJpL5k3CFekiUm4wIyTs3LzoD5RjI2GJkCYw5wN8gkBpKxMYwTZOP2L9bIxoEwjk9LjydjsDkjPi0exnvI+NPcHAkZc3uRcWFukiSPjI+TsU1qTloSGT+CvWmSuCziPg2Yz5aIE8nYnYw1MqOjQsi4E3GiRgJrPJI1zpaMzQZSIaMzxmUmJSRmixzEjiIPPz9fUZgkL1WSne3SN06cEpcZLwoZnZYRlz6OomScX7z0wLci4mRvDz9vbxdPVw+Wo177ZgtfEFvZ6F6/FzGjjQ6+nFO0bnQpRfk2Ed/Mfjk3ch5FbZ5KUcZnX87ZfENR2iRuFYdZfIwgXxKzszP83dzy8vJckyRiV3Don69mF7TgxdLnCuL+dI8oVDIqLic1WwR+E49OHZ2TKcrKiBNLRC6vJPE/2ajYjvZRklGSTEk62RFDsiwpPYGEOz0+KTtpdLooKV1ZEP/mNrmXLK/JS7/sOWUw3JXSOWxAcW8epHj66hR36CLyDv1n3HqpxlBQeQMtr8jy/sVLQQflzIIfWUkJL/aFREWLxDmZubL3oCwpPqVGaVMGlAnVlrKmHCgXypPyoQJIo+pG9aQiqWgqlvqAElOJVBqVSeVRE6nJVCFVRM2mvqTmU4upMqqcWkttoDZTW6ld1D7qAFVLnaDOUXVUA3WdaqQeUE9pmhbSmrQ+bUJb0ra0M+1J+9Jd6G50LzqKjqVH0Al0Op1DT6Q/povoOfR8egldTn9Hb6F30fvpI/QZup6+Rt+ln3C4HA2OAceCY8dx4/hygjgRnGjOME4CZwxnPKeAM5Mzl1PKWc2p4OziHOCc4NRxrnOaSANX5xpxrbguXF9uCDeSO5g7ipvJncSdzi3hlnLXcqu4Ndxj3DruDe5jnoCnzxPxXHgBvDDeAJ6YN4Y3iTeDN5+3glfB28M7xqvnNfKe8zX55nxnvj8/nD+In8DP4xfyS/jL+Jv4e/kn+A38BwKBwEhgL/ARhAliBcmCCYIZgq8F6wQ7BUcElwRNQqHQROgs7CyMFMYJs4WFwnnC1cIdwqPCBuEjFXUVSxVPle4qg1XSVaaolKisVNmuclTlispTVR1VW1V/1UjVeNVxqrNUy1SrVA+rNqg+VdNVs1frrBatlqw2WW2u2lq1vWrn1e6pq6u3U/dT76eepP6R+lz19eo/qterP9bQ03DSCNEYqpGjMVNjucZOjTMa9zQ1Ne00AzUHa2ZrztQs19yt+YvmIy19LVetcK14rXytBVoVWke1bmmrattqB2l/oD1eu0R7o/Zh7Rs6qjp2OiE6cTqTdBbobNE5pdOkq6/roRupm6Y7Q3el7n7dq3pCPTu9bnrxegV63+rt1rukz9W31g/RF+t/rF+mv1e/wUBgYG8QbpBsUGSwxuCQQaOhnmFHwxjDsYYLDLcZ1hlxjeyMwo1SjWYZbTA6afSkjUWboDaSNtParG1ztM1DYzPjQGOJ8XTjdcYnjJ+YiEy6maSYfG6y2eSCKc/UybSfaZ7pItO9pjfMDMwCzMRm0802mJ0155g7mUeZTzD/1vygeZNFW4seFhkW8yx2W9xoa9Q2sG1y2+K229tes9S37GKZZFlsucPyd5GhKEiUKpor2iNqtDK3CrPKsVpidcjqaTv7dgPaTWm3rt0FazVrX+tR1sXW1daNNpY2vW0m2qyyOWurautrm2j7lW2N7UM7e7uBdp/Ybba7am9sH24/3n6V/XkHTYeuDmMcSh2OOwocfR1THL92rHXiOHk5JTotcDrszHH2dk5y/tr5SHt+e7/26e1L259y0XAJcsl1WeVS72rk2st1iutm11tuNm6D3T53q3F77u7lnupe5n7OQ8+jp8cUjyqPu55OnmLPBZ7HO2h26N4hv0NlhzsdnTtKOi7qeNpL36u31yde1V5/ePt4Z3qv9b7mY+MzwmehzylfA9++vjN8f/Tj+wX75ftt9Xvs7+2f7b/B/3aAS0BKwMqAq53sO0k6lXW61Lld57jOSzrXdRF1GdHlmy51Xa26xnUt7fproHVgfOCywCtBjkHJQauDbgW7B2cGbwp+GOIf8mHIzlBuaI/Q6aGHuul1G9BtfrdfurfrntB9VffGHl49JvTYGcYPiwj7POxUuEW4OLw8vLGnT88Pe+6J0IjoHzE/4tdeTr0ye1X15vTu2fuL3uf72PZJ77M5kooMj/wi8kJf+75j+v7QT9Cvb78F/S5HeURNjKrpr99/eP+V/R9EB0fPij43wGFAzoDqGO2YoTHlMQ8Hhg6cM7BukNugDwcdiDWNTYqtHCwcHDN42eCmId2GfDmkYajX0MKhJ4fZDxs7bP8Hph+kfrBtuPbwuOEbR/BHDByxcsSzuMi40rimkeEjF45sFIeIvxJfjw+ML46/JuksmSO5MqrzqDmjriZ0Tvgi4Vpi18SSxBtJIUnzk+4khyUvTn6YEpmyPEWaOjB1XZpK2oi0Lel66Snpe0a3HT129JEM54zCjLox/mO+HNOYGZG5LIvOGpZVmW1ALlMHcxxypubU53bJXZD7KC8mb+NY3bHpYw+Ocxo3bdyV8d3HL53AmyCeUD3RauLkifUfBn24ZBI9aeSk6nzr/IL8ho96fLRistrklMk/T3GfMmfK/Y8HflxVYFHwUcGlqT2mrirUKswsPPVJwCeLP+V9mvTpoWkdps2b9nx6/PSfityLSoqezRDP+Okzj8/mfiadOWrmoVnesxbNFsxOn33y866fr5ijO2f8nEtf9P6iolhUPL34/pfDv9xf0rFk8VdqX+V8VTe319zKeTbzZs97Nj9x/okFwQvWLTRfOG3hw6/jvz66KHDR2sUWi4sWP/km6ZvTS3osqSi1Ky35VvBt7reXy2LKapb6Li1fZrqsaNkfy9OX162IWrGn3Ke8fKX5ylmrOKtyVl1bPXR17ZrQNZVrXdYuWWe0rmg9tT5n/e/fjfju5IaIDdUbfTeu/d72+4Wb9DdNr6ArxlU0bk7cXFcZW3lkS88t1VUBVZt+cP1h+VarrQu2GW6btV1te8F26Y7xO5p2Zuy8sSth16Xq4dXndg/afXxPvz2H9kbs/XFf9327a4JqdvzY+cet+/33b/nJ96fNB7wPVBz0OrjpZ6+fNx3yPlRx2OdwZa1fbdWRTke2H+16dNex0GP7jocfP3Ciz4kjJwecPH1q6Km60/Gnr55JPXPnbO7Zp+c+Os8/P/2CzoWSX8x/Kb3oeHFdnXfdtvrQ+oO/9v/13CXxpeu/Zf32rKHgsublkiuWV8qvel7deq37tdrfh/zecD3j+tMbhTd1by685XDr+9uBtw82DmpsuJN5R3p3xj2Te8vvd7xf3dS36ZcHaQ+ePpz+yOTRise+j2ueDHxy5WneM+GzuX84/lH1POL5eWmaVPo/LX7Mrg5NAAA= + + diff --git a/samples/js-tests/res/cocosui/CCS/2.1/plist1/Plist.plist b/samples/js-tests/res/cocosui/CCS/2.1/plist1/Plist.plist new file mode 100644 index 0000000000..0a26832740 --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/2.1/plist1/Plist.plist @@ -0,0 +1,115 @@ + + + + + frames + + actor_fish_denglong_dead_001.png + + frame + {{0,362},{296,166}} + offset + {19,10} + rotated + + sourceSize + {412,300} + + actor_fish_denglong_dead_002.png + + frame + {{296,512},{286,152}} + offset + {26,-22} + rotated + + sourceSize + {412,300} + + actor_fish_denglong_dead_003.png + + frame + {{318,0},{297,192}} + offset + {18,-21} + rotated + + sourceSize + {412,300} + + actor_fish_denglong_dead_004.png + + frame + {{615,170},{300,178}} + offset + {7,-32} + rotated + + sourceSize + {412,300} + + actor_fish_denglong_dead_005.png + + frame + {{0,192},{309,170}} + offset + {5,-19} + rotated + + sourceSize + {412,300} + + actor_fish_denglong_dead_006.png + + frame + {{0,0},{318,192}} + offset + {3,16} + rotated + + sourceSize + {412,300} + + actor_fish_denglong_dead_007.png + + frame + {{615,0},{316,170}} + offset + {5,14} + rotated + + sourceSize + {412,300} + + actor_fish_denglong_dead_008.png + + frame + {{309,192},{320,158}} + offset + {4,-17} + rotated + + sourceSize + {412,300} + + + metadata + + format + 2 + textureFileName + Plist.png + realTextureFileName + Plist.png + size + {931,798} + + texture + + width + 931 + height + 798 + + + \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/CCS/2.1/plist1/Plist.png b/samples/js-tests/res/cocosui/CCS/2.1/plist1/Plist.png new file mode 100644 index 0000000000..270ec55fb5 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/plist1/Plist.png differ diff --git a/samples/js-tests/res/cocosui/CCS/2.1/ttc/simsun.ttc b/samples/js-tests/res/cocosui/CCS/2.1/ttc/simsun.ttc new file mode 100644 index 0000000000..23d5c4a945 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/ttc/simsun.ttc differ diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/A Damn Mess.ttf b/samples/js-tests/res/cocosui/CCS/2.1/ttf/ADamnMess.ttf similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/A Damn Mess.ttf rename to samples/js-tests/res/cocosui/CCS/2.1/ttf/ADamnMess.ttf diff --git a/samples/js-tests/res/cocosui/CCS/2.1/ttf/Fingerpop.ttf b/samples/js-tests/res/cocosui/CCS/2.1/ttf/Fingerpop.ttf new file mode 100644 index 0000000000..2ce6b3aef8 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/2.1/ttf/Fingerpop.ttf differ diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.json b/samples/js-tests/res/cocosui/CCS/Button/Button_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.json rename to samples/js-tests/res/cocosui/CCS/Button/Button_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/background.png b/samples/js-tests/res/cocosui/CCS/Button/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/Button/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/Button/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/Button/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/buttonHighlighted.png b/samples/js-tests/res/cocosui/CCS/Button/buttonHighlighted.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/buttonHighlighted.png rename to samples/js-tests/res/cocosui/CCS/Button/buttonHighlighted.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/button_n.png b/samples/js-tests/res/cocosui/CCS/Button/button_n.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/button_n.png rename to samples/js-tests/res/cocosui/CCS/Button/button_n.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/Button/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/Button/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/Button/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/Button/ribbon.png diff --git a/samples/js-tests/res/cocosui/CCS/CheckBox/Default/CheckBox_Disable.png b/samples/js-tests/res/cocosui/CCS/CheckBox/Default/CheckBox_Disable.png new file mode 100644 index 0000000000..78b01b9bb9 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/CheckBox/Default/CheckBox_Disable.png differ diff --git a/samples/js-tests/res/cocosui/CCS/CheckBox/MainScene.json b/samples/js-tests/res/cocosui/CCS/CheckBox/MainScene.json new file mode 100644 index 0000000000..497968fdb0 --- /dev/null +++ b/samples/js-tests/res/cocosui/CCS/CheckBox/MainScene.json @@ -0,0 +1,101 @@ +{ + "ID": "fb5c107c-6fa8-43bd-9caf-107658f450ba", + "Version": "2.1.5.0", + "Name": "MainScene", + "Content": { + "Content": { + "Animation": { + "Duration": 0, + "Speed": 1.0, + "Timelines": [], + "ctype": "TimelineActionData" + }, + "AnimationList": [], + "ObjectData": { + "Tag": 20, + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "Children": [ + { + "NormalBackFileData": { + "Type": "Normal", + "Path": "img/btn_music.png" + }, + "PressedBackFileData": { + "Type": "Normal", + "Path": "img/btn_music.png" + }, + "DisableBackFileData": { + "Type": "Default", + "Path": "Default/CheckBox_Disable.png" + }, + "NodeNormalFileData": { + "Type": "Normal", + "Path": "img/btn_sound_off.png" + }, + "NodeDisableFileData": { + "Type": "Normal", + "Path": "img/btn_sound_off.png" + }, + "TouchEnable": true, + "Tag": 21, + "PrePosition": { + "X": 0.0, + "Y": 0.0 + }, + "PreSize": { + "X": 0.0, + "Y": 0.0 + }, + "ActionTag": 454440131, + "Position": { + "X": 290.5, + "Y": 250.5 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": { + "ScaleX": 0.5, + "ScaleY": 0.5 + }, + "CColor": {}, + "Size": { + "X": 40.0, + "Y": 40.0 + }, + "FrameEvent": "", + "Name": "CheckBox_1", + "ctype": "CheckBoxObjectData" + } + ], + "Position": { + "X": 0.0, + "Y": 0.0 + }, + "Scale": { + "ScaleX": 1.0, + "ScaleY": 1.0 + }, + "AnchorPoint": {}, + "CColor": {}, + "Size": { + "X": 640.0, + "Y": 960.0 + }, + "FrameEvent": "", + "Name": "Scene", + "ctype": "SingleNodeObjectData" + }, + "ctype": "GameProjectData" + } + }, + "Type": "Scene" +} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/background.png b/samples/js-tests/res/cocosui/CCS/CheckBox/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/CheckBox/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/CheckBox/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/CheckBox/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/buttonHighlighted.png b/samples/js-tests/res/cocosui/CCS/CheckBox/buttonHighlighted.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/buttonHighlighted.png rename to samples/js-tests/res/cocosui/CCS/CheckBox/buttonHighlighted.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/ui_checkbox_editor_1.json b/samples/js-tests/res/cocosui/CCS/CheckBox/checkbox_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/ui_checkbox_editor_1.json rename to samples/js-tests/res/cocosui/CCS/CheckBox/checkbox_1.json diff --git a/samples/js-tests/res/cocosui/CCS/CheckBox/img/btn_music.png b/samples/js-tests/res/cocosui/CCS/CheckBox/img/btn_music.png new file mode 100644 index 0000000000..e4506db9e6 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/CheckBox/img/btn_music.png differ diff --git a/samples/js-tests/res/cocosui/CCS/CheckBox/img/btn_sound_off.png b/samples/js-tests/res/cocosui/CCS/CheckBox/img/btn_sound_off.png new file mode 100644 index 0000000000..a91f8e3a44 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/CheckBox/img/btn_sound_off.png differ diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/CheckBox/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/CheckBox/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/selected01.png b/samples/js-tests/res/cocosui/CCS/CheckBox/selected01.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/selected01.png rename to samples/js-tests/res/cocosui/CCS/CheckBox/selected01.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/selected02.png b/samples/js-tests/res/cocosui/CCS/CheckBox/selected02.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/selected02.png rename to samples/js-tests/res/cocosui/CCS/CheckBox/selected02.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/ImageView/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/ImageView/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/ui_ImageView_editor_1.json b/samples/js-tests/res/cocosui/CCS/ImageView/ImageView_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/ui_ImageView_editor_1.json rename to samples/js-tests/res/cocosui/CCS/ImageView/ImageView_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/background.png b/samples/js-tests/res/cocosui/CCS/ImageView/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/ImageView/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/ImageView/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/ImageView/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/buttonHighlighted.png b/samples/js-tests/res/cocosui/CCS/ImageView/buttonHighlighted.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/buttonHighlighted.png rename to samples/js-tests/res/cocosui/CCS/ImageView/buttonHighlighted.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/ImageView/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/ImageView/ribbon.png diff --git a/samples/js-tests/res/cocosui/CCS/Label/A Damn Mess.ttf b/samples/js-tests/res/cocosui/CCS/Label/A Damn Mess.ttf new file mode 100644 index 0000000000..e3d2a40095 Binary files /dev/null and b/samples/js-tests/res/cocosui/CCS/Label/A Damn Mess.ttf differ diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/background.png b/samples/js-tests/res/cocosui/CCS/Label/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/Label/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/Label/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/Label/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/ui_label_editor_1.json b/samples/js-tests/res/cocosui/CCS/Label/label_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/ui_label_editor_1.json rename to samples/js-tests/res/cocosui/CCS/Label/label_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/Label/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/Label/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/GUI/labelatlasimg.png b/samples/js-tests/res/cocosui/CCS/LabelAtlas/GUI/labelatlasimg.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/GUI/labelatlasimg.png rename to samples/js-tests/res/cocosui/CCS/LabelAtlas/GUI/labelatlasimg.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/background.png b/samples/js-tests/res/cocosui/CCS/LabelAtlas/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/LabelAtlas/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/LabelAtlas/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/LabelAtlas/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/ui_labelatlas_editor_1.json b/samples/js-tests/res/cocosui/CCS/LabelAtlas/labelatlas_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/ui_labelatlas_editor_1.json rename to samples/js-tests/res/cocosui/CCS/LabelAtlas/labelatlas_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/LabelAtlas/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/LabelAtlas/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.fnt b/samples/js-tests/res/cocosui/CCS/LabelBMFont/GUI/missing-font.fnt similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.fnt rename to samples/js-tests/res/cocosui/CCS/LabelBMFont/GUI/missing-font.fnt diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png b/samples/js-tests/res/cocosui/CCS/LabelBMFont/GUI/missing-font.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png rename to samples/js-tests/res/cocosui/CCS/LabelBMFont/GUI/missing-font.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/background.png b/samples/js-tests/res/cocosui/CCS/LabelBMFont/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/LabelBMFont/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/LabelBMFont/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/LabelBMFont/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.json b/samples/js-tests/res/cocosui/CCS/LabelBMFont/labelbmfont_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.json rename to samples/js-tests/res/cocosui/CCS/LabelBMFont/labelbmfont_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/LabelBMFont/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/LabelBMFont/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png b/samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/Hello.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png rename to samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/Hello.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png b/samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ui_layout_backgroundimage_editor_1_0_0.json b/samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/backgroundimage_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ui_layout_backgroundimage_editor_1_0_0.json rename to samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/backgroundimage_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/button_n.png b/samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/button_n.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/button_n.png rename to samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/button_n.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/selected01.png b/samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/selected01.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/selected01.png rename to samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/selected01.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/selected02.png b/samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/selected02.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/selected02.png rename to samples/js-tests/res/cocosui/CCS/Layout/BackgroundImage/selected02.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/Layout/Color/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/Layout/Color/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png b/samples/js-tests/res/cocosui/CCS/Layout/Color/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/Layout/Color/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/Layout/Color/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/Layout/Color/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/button_n.png b/samples/js-tests/res/cocosui/CCS/Layout/Color/button_n.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/button_n.png rename to samples/js-tests/res/cocosui/CCS/Layout/Color/button_n.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/Layout/Color/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/Layout/Color/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ui_layout_color_editor_1.json b/samples/js-tests/res/cocosui/CCS/Layout/Color/color_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ui_layout_color_editor_1.json rename to samples/js-tests/res/cocosui/CCS/Layout/Color/color_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/Layout/Color/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/Layout/Color/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/selected01.png b/samples/js-tests/res/cocosui/CCS/Layout/Color/selected01.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/selected01.png rename to samples/js-tests/res/cocosui/CCS/Layout/Color/selected01.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/selected02.png b/samples/js-tests/res/cocosui/CCS/Layout/Color/selected02.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/selected02.png rename to samples/js-tests/res/cocosui/CCS/Layout/Color/selected02.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png b/samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/button_n.png b/samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/button_n.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/button_n.png rename to samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/button_n.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ui_layout_gradient_color_editor_1_0.json b/samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/gradient_color_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ui_layout_gradient_color_editor_1_0.json rename to samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/gradient_color_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/selected01.png b/samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/selected01.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/selected01.png rename to samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/selected01.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/selected02.png b/samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/selected02.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/selected02.png rename to samples/js-tests/res/cocosui/CCS/Layout/Gradient_Color/selected02.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/Layout/Layout/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/Layout/Layout/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png b/samples/js-tests/res/cocosui/CCS/Layout/Layout/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/Layout/Layout/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/Layout/Layout/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/Layout/Layout/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/button_n.png b/samples/js-tests/res/cocosui/CCS/Layout/Layout/button_n.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/button_n.png rename to samples/js-tests/res/cocosui/CCS/Layout/Layout/button_n.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/Layout/Layout/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/Layout/Layout/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ui_layout_editor_1.json b/samples/js-tests/res/cocosui/CCS/Layout/Layout/layout_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ui_layout_editor_1.json rename to samples/js-tests/res/cocosui/CCS/Layout/Layout/layout_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/Layout/Layout/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/Layout/Layout/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/selected01.png b/samples/js-tests/res/cocosui/CCS/Layout/Layout/selected01.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/selected01.png rename to samples/js-tests/res/cocosui/CCS/Layout/Layout/selected01.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/selected02.png b/samples/js-tests/res/cocosui/CCS/Layout/Layout/selected02.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/selected02.png rename to samples/js-tests/res/cocosui/CCS/Layout/Layout/selected02.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/button_n.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/button_n.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/button_n.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/button_n.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ui_layout_linear_horizontal_layout_editor.json b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/linear_horizontal.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ui_layout_linear_horizontal_layout_editor.json rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/linear_horizontal.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/selected01.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/selected01.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/selected01.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/selected01.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/selected02.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/selected02.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/selected02.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Horizontal/selected02.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/button_n.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/button_n.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/button_n.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/button_n.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ui_layout_linear_vertical_layout_editor.json b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/linear_vertical.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ui_layout_linear_vertical_layout_editor.json rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/linear_vertical.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/selected01.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/selected01.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/selected01.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/selected01.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/selected02.png b/samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/selected02.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/selected02.png rename to samples/js-tests/res/cocosui/CCS/Layout/Linear_Vertical/selected02.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/button_n.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/button_n.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/button_n.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/button_n.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ui_layout_relative_align_location_editor.json b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/relative_align_location.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ui_layout_relative_align_location_editor.json rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/relative_align_location.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/selected01.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/selected01.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/selected01.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/selected01.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/selected02.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/selected02.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/selected02.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Location/selected02.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/button_n.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/button_n.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/button_n.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/button_n.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ui_layout_relative_align_parent_editor.json b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/relative_align_parent.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ui_layout_relative_align_parent_editor.json rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/relative_align_parent.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/selected01.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/selected01.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/selected01.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/selected01.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/selected02.png b/samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/selected02.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/selected02.png rename to samples/js-tests/res/cocosui/CCS/Layout/Relative_Align_Parent/selected02.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/Layout/Scale9/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/Layout/Scale9/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png b/samples/js-tests/res/cocosui/CCS/Layout/Scale9/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/Layout/Scale9/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/Layout/Scale9/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/Layout/Scale9/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/button_n.png b/samples/js-tests/res/cocosui/CCS/Layout/Scale9/button_n.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/button_n.png rename to samples/js-tests/res/cocosui/CCS/Layout/Scale9/button_n.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/Layout/Scale9/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/Layout/Scale9/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/Layout/Scale9/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/Layout/Scale9/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ui_layout_scale9_backgroundimage_editor.json b/samples/js-tests/res/cocosui/CCS/Layout/Scale9/scale9.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ui_layout_scale9_backgroundimage_editor.json rename to samples/js-tests/res/cocosui/CCS/Layout/Scale9/scale9.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/selected01.png b/samples/js-tests/res/cocosui/CCS/Layout/Scale9/selected01.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/selected01.png rename to samples/js-tests/res/cocosui/CCS/Layout/Scale9/selected01.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/selected02.png b/samples/js-tests/res/cocosui/CCS/Layout/Scale9/selected02.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/selected02.png rename to samples/js-tests/res/cocosui/CCS/Layout/Scale9/selected02.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/slider_bar.png b/samples/js-tests/res/cocosui/CCS/Layout/Scale9/slider_bar.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/slider_bar.png rename to samples/js-tests/res/cocosui/CCS/Layout/Scale9/slider_bar.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/GUI/button.png b/samples/js-tests/res/cocosui/CCS/ListView/Horizontal/GUI/button.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/GUI/button.png rename to samples/js-tests/res/cocosui/CCS/ListView/Horizontal/GUI/button.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/ListView/Horizontal/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/ListView/Horizontal/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png b/samples/js-tests/res/cocosui/CCS/ListView/Horizontal/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/ListView/Horizontal/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/ListView/Horizontal/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/ListView/Horizontal/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/ListView/Horizontal/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/ListView/Horizontal/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.json b/samples/js-tests/res/cocosui/CCS/ListView/Horizontal/horizontal_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.json rename to samples/js-tests/res/cocosui/CCS/ListView/Horizontal/horizontal_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/ListView/Horizontal/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/ListView/Horizontal/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/GUI/button.png b/samples/js-tests/res/cocosui/CCS/ListView/Vertical/GUI/button.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/GUI/button.png rename to samples/js-tests/res/cocosui/CCS/ListView/Vertical/GUI/button.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/ListView/Vertical/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/ListView/Vertical/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png b/samples/js-tests/res/cocosui/CCS/ListView/Vertical/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/ListView/Vertical/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/ListView/Vertical/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/ListView/Vertical/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/ListView/Vertical/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/ListView/Vertical/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/ListView/Vertical/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/ListView/Vertical/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.json b/samples/js-tests/res/cocosui/CCS/ListView/Vertical/vertical_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.json rename to samples/js-tests/res/cocosui/CCS/ListView/Vertical/vertical_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/GUI/loadingbar.png b/samples/js-tests/res/cocosui/CCS/LoadingBar/GUI/loadingbar.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/GUI/loadingbar.png rename to samples/js-tests/res/cocosui/CCS/LoadingBar/GUI/loadingbar.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/background.png b/samples/js-tests/res/cocosui/CCS/LoadingBar/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/LoadingBar/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/LoadingBar/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/LoadingBar/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/ui_loadingbar_editor_1.json b/samples/js-tests/res/cocosui/CCS/LoadingBar/loadingbar_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/ui_loadingbar_editor_1.json rename to samples/js-tests/res/cocosui/CCS/LoadingBar/loadingbar_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/LoadingBar/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/LoadingBar/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/background.png b/samples/js-tests/res/cocosui/CCS/PageView/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/PageView/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/PageView/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/PageView/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/button_n.png b/samples/js-tests/res/cocosui/CCS/PageView/button_n.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/button_n.png rename to samples/js-tests/res/cocosui/CCS/PageView/button_n.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/ui_pageview_editor_1.json b/samples/js-tests/res/cocosui/CCS/PageView/pageview_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/ui_pageview_editor_1.json rename to samples/js-tests/res/cocosui/CCS/PageView/pageview_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/PageView/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/PageView/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Both/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Both/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Both/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Both/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ui_scrollview_both_editor_1.json b/samples/js-tests/res/cocosui/CCS/ScrollView/Both/both_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ui_scrollview_both_editor_1.json rename to samples/js-tests/res/cocosui/CCS/ScrollView/Both/both_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Both/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Both/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/button_n.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Both/button_n.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/button_n.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Both/button_n.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Both/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Both/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Both/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Both/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/selected01.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Both/selected01.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/selected01.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Both/selected01.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/selected02.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Both/selected02.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/selected02.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Both/selected02.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/button_n.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/button_n.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/button_n.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/button_n.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ui_scrollview_horizontal_editor_1.json b/samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/horizontal_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ui_scrollview_horizontal_editor_1.json rename to samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/horizontal_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/selected01.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/selected01.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/selected01.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/selected01.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/selected02.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/selected02.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/selected02.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Horizontal/selected02.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/GUI/image.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/GUI/image.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/GUI/image.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/GUI/image.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/button_n.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/button_n.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/button_n.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/button_n.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/button_p.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/button_p.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/button_p.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/button_p.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/selected01.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/selected01.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/selected01.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/selected01.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/selected02.png b/samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/selected02.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/selected02.png rename to samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/selected02.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ui_scrollview_editor_1.json b/samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/vertical_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ui_scrollview_editor_1.json rename to samples/js-tests/res/cocosui/CCS/ScrollView/Vertical/vertical_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/2014-1-26 11-42-09.png b/samples/js-tests/res/cocosui/CCS/Slider/2014-1-26 11-42-09.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/2014-1-26 11-42-09.png rename to samples/js-tests/res/cocosui/CCS/Slider/2014-1-26 11-42-09.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/2014-1-26 11-43-52.png b/samples/js-tests/res/cocosui/CCS/Slider/2014-1-26 11-43-52.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/2014-1-26 11-43-52.png rename to samples/js-tests/res/cocosui/CCS/Slider/2014-1-26 11-43-52.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/background.png b/samples/js-tests/res/cocosui/CCS/Slider/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/Slider/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/Slider/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/Slider/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/buttonHighlighted.png b/samples/js-tests/res/cocosui/CCS/Slider/buttonHighlighted.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/buttonHighlighted.png rename to samples/js-tests/res/cocosui/CCS/Slider/buttonHighlighted.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/Slider/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/Slider/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/silder_progressBar.png b/samples/js-tests/res/cocosui/CCS/Slider/silder_progressBar.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/silder_progressBar.png rename to samples/js-tests/res/cocosui/CCS/Slider/silder_progressBar.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/ui_slider_editor_1.json b/samples/js-tests/res/cocosui/CCS/Slider/slider_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/ui_slider_editor_1.json rename to samples/js-tests/res/cocosui/CCS/Slider/slider_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/slider_bar.png b/samples/js-tests/res/cocosui/CCS/Slider/slider_bar.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/slider_bar.png rename to samples/js-tests/res/cocosui/CCS/Slider/slider_bar.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/slider_bar_button.png b/samples/js-tests/res/cocosui/CCS/Slider/slider_bar_button.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/slider_bar_button.png rename to samples/js-tests/res/cocosui/CCS/Slider/slider_bar_button.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UITextField_Editor/background.png b/samples/js-tests/res/cocosui/CCS/TextField/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UITextField_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/TextField/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UITextField_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/TextField/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UITextField_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/TextField/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UITextField_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/TextField/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UITextField_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/TextField/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UITextField_Editor/ui_textfield_editor_1.json b/samples/js-tests/res/cocosui/CCS/TextField/textfield_1.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UITextField_Editor/ui_textfield_editor_1.json rename to samples/js-tests/res/cocosui/CCS/TextField/textfield_1.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/background.png b/samples/js-tests/res/cocosui/CCS/WidgetAddNode/background.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/background.png rename to samples/js-tests/res/cocosui/CCS/WidgetAddNode/background.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/buttonBackground.png b/samples/js-tests/res/cocosui/CCS/WidgetAddNode/buttonBackground.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/buttonBackground.png rename to samples/js-tests/res/cocosui/CCS/WidgetAddNode/buttonBackground.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/ribbon.png b/samples/js-tests/res/cocosui/CCS/WidgetAddNode/ribbon.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/ribbon.png rename to samples/js-tests/res/cocosui/CCS/WidgetAddNode/ribbon.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/ui_widget_add_node_editor.json b/samples/js-tests/res/cocosui/CCS/WidgetAddNode/widget_add_node.json similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/ui_widget_add_node_editor.json rename to samples/js-tests/res/cocosui/CCS/WidgetAddNode/widget_add_node.json diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/CocostudioV1_3_1.ExportJson b/samples/js-tests/res/cocosui/CCS/ccs1_3/CCSV1_3_1.ExportJson similarity index 96% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/CocostudioV1_3_1.ExportJson rename to samples/js-tests/res/cocosui/CCS/ccs1_3/CCSV1_3_1.ExportJson index 9b9b4667dd..71b834369f 100644 --- a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/CocostudioV1_3_1.ExportJson +++ b/samples/js-tests/res/cocosui/CCS/ccs1_3/CCSV1_3_1.ExportJson @@ -1,2291 +1,2291 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 0.4999999, - "designHeight": 640, - "designWidth": 960, - "textures": [ - "CocostudioV1_30.plist" - ], - "version": "1.3.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_22", - "ZOrder": 0, - "actiontag": 22, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "Panel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 640, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 4, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 960, - "x": 0, - "y": 0, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_23", - "ZOrder": 0, - "actiontag": 23, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "Button", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.08125, - "positionPercentY": 0.9109375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.107291669, - "sizePercentY": 0.0625, - "sizeType": 0, - "tag": 5, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 78, - "y": 583, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_24", - "ZOrder": 0, - "actiontag": 24, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.192708328, - "positionPercentY": 0.903125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.0583333336, - "sizePercentY": 0.0875, - "sizeType": 0, - "tag": 6, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 185, - "y": 578, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_25", - "ZOrder": 0, - "actiontag": 25, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "ImageView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.29375, - "positionPercentY": 0.9046875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.0833333358, - "sizePercentY": 0.125, - "sizeType": 0, - "tag": 7, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 80, - "x": 282, - "y": 579, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", - "plistFile": "", - "resourceType": 1 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "LabelAtlas", - "name": null, - "children": [], - "options": { - "__type": "LabelAtlasSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelAtlas", - "name": "LabelAtlas_26", - "ZOrder": 0, - "actiontag": 26, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "LabelAtlas", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 32, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.5229167, - "positionPercentY": 0.903125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.25, - "sizePercentY": 0.05, - "sizeType": 0, - "tag": 8, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 240, - "x": 502, - "y": 578, - "charMapFile": null, - "charMapFileData": { - "path": "GUI/labelatlasimg.png", - "plistFile": "", - "resourceType": 0 - }, - "itemHeight": 32, - "itemWidth": 24, - "startCharMap": "0", - "stringValue": "0123456789" - } - }, - { - "classname": "LabelBMFont", - "name": null, - "children": [], - "options": { - "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelBMFont", - "name": "LabelBMFont_27", - "ZOrder": 0, - "actiontag": 27, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "LabelBMFont", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 37, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.826041639, - "positionPercentY": 0.896875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.244791672, - "sizePercentY": 0.0578125, - "sizeType": 0, - "tag": 9, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 235, - "x": 793, - "y": 574, - "fileNameData": { - "path": "GUI/missing-font.fnt", - "plistFile": "", - "resourceType": 0 - }, - "text": "Text Label" - } - }, - { - "classname": "LoadingBar", - "name": null, - "children": [], - "options": { - "__type": "LoadingBarSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LoadingBar", - "name": "LoadingBar_28", - "ZOrder": 0, - "actiontag": 28, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "LoadingBar", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 24, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.230208337, - "positionPercentY": 0.7609375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.364583343, - "sizePercentY": 0.0375, - "sizeType": 0, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 350, - "x": 221, - "y": 487, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "direction": 0, - "percent": 100, - "scale9Enable": false, - "texture": null, - "textureData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/loadingbar.png", - "plistFile": "", - "resourceType": 1 - } - } - }, - { - "classname": "Slider", - "name": null, - "children": [], - "options": { - "__type": "SliderSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Slider", - "name": "Slider_29", - "ZOrder": 0, - "actiontag": 29, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "Slider", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 8, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.597916663, - "positionPercentY": 0.784375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.302083343, - "sizePercentY": 0.0125, - "sizeType": 0, - "tag": 11, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 290, - "x": 574, - "y": 502, - "ballDisabled": null, - "ballDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "ballNormal": null, - "ballNormalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/slider_bar_button.png", - "plistFile": "", - "resourceType": 1 - }, - "ballPressed": null, - "ballPressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "barCapInsetsHeight": 1, - "barCapInsetsWidth": 1, - "barCapInsetsX": 0, - "barCapInsetsY": 0, - "barFileName": null, - "barFileNameData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/slider_bar.png", - "plistFile": "", - "resourceType": 1 - }, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "length": 290, - "percent": 0, - "progressBarCapInsetsHeight": 0, - "progressBarCapInsetsWidth": 0, - "progressBarCapInsetsX": 0, - "progressBarCapInsetsY": 0, - "progressBarData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "progressBarVisible": false, - "scale9Enable": false, - "scale9Height": 0, - "scale9Width": 0, - "slidBallAnchorPointX": 0, - "slidBallAnchorPointY": 0 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "LabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_30", - "ZOrder": 0, - "actiontag": 30, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "Label", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.888541639, - "positionPercentY": 0.7921875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.0989583358, - "sizePercentY": 0.0421875, - "sizeType": 0, - "tag": 12, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 95, - "x": 853, - "y": 507, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "Text Label", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "TextField", - "name": null, - "children": [], - "options": { - "__type": "TextFieldSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "TextField", - "name": "TextField_31", - "ZOrder": 0, - "actiontag": 31, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "TextField", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.0604166649, - "positionPercentY": 0.6796875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.09375, - "sizePercentY": 0.0421875, - "sizeType": 0, - "tag": 13, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 90, - "x": 58, - "y": 435, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "maxLength": 10, - "maxLengthEnable": false, - "passwordEnable": false, - "passwordStyleText": "*", - "placeHolder": "input words here", - "text": "Text Field" - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_38", - "ZOrder": 0, - "actiontag": 38, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "Button", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.325, - "positionPercentY": 0.83, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 65, - "y": 166, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_39", - "ZOrder": 0, - "actiontag": 39, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.765, - "positionPercentY": 0.82, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.28, - "sizePercentY": 0.28, - "sizeType": 0, - "tag": 21, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 153, - "y": 164, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_40", - "ZOrder": 0, - "actiontag": 40, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "ImageView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.25, - "positionPercentY": 0.46, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.4, - "sizePercentY": 0.4, - "sizeType": 0, - "tag": 22, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 80, - "x": 50, - "y": 92, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", - "plistFile": "", - "resourceType": 1 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "LabelAtlas", - "name": null, - "children": [], - "options": { - "__type": "LabelAtlasSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelAtlas", - "name": "LabelAtlas_41", - "ZOrder": 0, - "actiontag": 41, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "LabelAtlas", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 32, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.795, - "positionPercentY": 0.49, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.24, - "sizePercentY": 0.16, - "sizeType": 0, - "tag": 23, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 48, - "x": 159, - "y": 98, - "charMapFile": null, - "charMapFileData": { - "path": "GUI/labelatlasimg.png", - "plistFile": "", - "resourceType": 0 - }, - "itemHeight": 32, - "itemWidth": 24, - "startCharMap": "0", - "stringValue": "11" - } - }, - { - "classname": "LabelBMFont", - "name": null, - "children": [], - "options": { - "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelBMFont", - "name": "LabelBMFont_42", - "ZOrder": 0, - "actiontag": 42, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "LabelBMFont", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 37, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.7, - "positionPercentY": 0.195, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.29, - "sizePercentY": 0.185, - "sizeType": 0, - "tag": 24, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 58, - "x": 140, - "y": 39, - "fileNameData": { - "path": "GUI/missing-font.fnt", - "plistFile": "", - "resourceType": 0 - }, - "text": "22" - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_34", - "ZOrder": 0, - "actiontag": 34, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "Panel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.009375, - "positionPercentY": 0.209375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.208333328, - "sizePercentY": 0.3125, - "sizeType": 0, - "tag": 16, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 9, - "y": 134, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "ScrollView", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_43", - "ZOrder": 0, - "actiontag": 43, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "Button", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.525, - "positionPercentY": 1.6, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 25, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 105, - "y": 320, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_44", - "ZOrder": 0, - "actiontag": 44, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.95, - "positionPercentY": 1.12, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.28, - "sizePercentY": 0.28, - "sizeType": 0, - "tag": 26, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 190, - "y": 224, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_45", - "ZOrder": 0, - "actiontag": 45, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "ImageView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 1.72, - "positionPercentY": 0.54, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.4, - "sizePercentY": 0.4, - "sizeType": 0, - "tag": 27, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 80, - "x": 344, - "y": 108, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", - "plistFile": "", - "resourceType": 1 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ScrollViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ScrollView", - "name": "ScrollView_35", - "ZOrder": 0, - "actiontag": 35, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "ScrollView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.25, - "positionPercentY": 0.209375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.208333328, - "sizePercentY": 0.3125, - "sizeType": 0, - "tag": 17, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 240, - "y": 134, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 100, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 255, - "bgEndColorB": 100, - "bgEndColorG": 150, - "bgEndColorR": 255, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "bounceEnable": false, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "direction": 3, - "innerHeight": 400, - "innerWidth": 400, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "ListView", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_47", - "ZOrder": 0, - "actiontag": 47, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "Button", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Button_47", - "relativeToName": "ListView_36", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.10864979, - "positionPercentY": 0.9, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 29, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 62, - "y": 168, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_48", - "ZOrder": 1, - "actiontag": 48, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "CheckBox_48", - "relativeToName": "ListView_36", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.2763713, - "positionPercentY": 0.86, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.28, - "sizePercentY": 0.28, - "sizeType": 0, - "tag": 30, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 50, - "y": 134, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_49", - "ZOrder": 2, - "actiontag": 49, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "ImageView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "ImageView_49", - "relativeToName": "ListView_36", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.419831216, - "positionPercentY": 0.8, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.4, - "sizePercentY": 0.4, - "sizeType": 0, - "tag": 31, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 80, - "x": 100, - "y": 98, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", - "plistFile": "", - "resourceType": 1 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "LabelBMFont", - "name": null, - "children": [], - "options": { - "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelBMFont", - "name": "LabelBMFont_50", - "ZOrder": 3, - "actiontag": 50, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "LabelBMFont", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 37, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "LabelBMFont_50", - "relativeToName": "ListView_36", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.7521097, - "positionPercentY": 0.9075, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1.175, - "sizePercentY": 0.185, - "sizeType": 0, - "tag": 32, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 235, - "x": 122, - "y": 81, - "fileNameData": { - "path": "GUI/missing-font.fnt", - "plistFile": "", - "resourceType": 0 - }, - "text": "Text Label" - } - } - ], - "options": { - "__type": "ListViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ListView", - "name": "ListView_36", - "ZOrder": 0, - "actiontag": 36, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "ListView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.496875, - "positionPercentY": 0.209375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.208333328, - "sizePercentY": 0.3125, - "sizeType": 0, - "tag": 18, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 477, - "y": 134, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 150, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "bounceEnable": true, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "direction": 2, - "gravity": 3, - "innerHeight": 0, - "innerWidth": 0, - "itemMargin": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "PageView", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_53", - "ZOrder": 0, - "actiontag": 53, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "Button", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.34, - "positionPercentY": 0.845, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 35, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 68, - "y": 169, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_54", - "ZOrder": 0, - "actiontag": 54, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.41, - "positionPercentY": 0.62, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.28, - "sizePercentY": 0.28, - "sizeType": 0, - "tag": 36, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 82, - "y": 124, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "LoadingBar", - "name": null, - "children": [], - "options": { - "__type": "LoadingBarSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LoadingBar", - "name": "LoadingBar_55", - "ZOrder": 0, - "actiontag": 55, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "LoadingBar", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 24, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.975, - "positionPercentY": 0.38, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1.75, - "sizePercentY": 0.12, - "sizeType": 0, - "tag": 37, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 350, - "x": 195, - "y": 76, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "direction": 0, - "percent": 50, - "scale9Enable": false, - "texture": null, - "textureData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/loadingbar.png", - "plistFile": "", - "resourceType": 1 - } - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_51", - "ZOrder": 0, - "actiontag": 51, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "Panel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 33, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 0, - "y": 0, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_56", - "ZOrder": 0, - "actiontag": 56, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "Button", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.48, - "positionPercentY": 0.83, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 38, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 96, - "y": 166, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_57", - "ZOrder": 0, - "actiontag": 57, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.46, - "positionPercentY": 0.49, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.28, - "sizePercentY": 0.28, - "sizeType": 0, - "tag": 39, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 92, - "y": 98, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_58", - "ZOrder": 0, - "actiontag": 58, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "ImageView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.51, - "positionPercentY": 0.165, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.4, - "sizePercentY": 0.4, - "sizeType": 0, - "tag": 40, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 80, - "x": 102, - "y": 33, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", - "plistFile": "", - "resourceType": 1 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_52", - "ZOrder": 0, - "actiontag": 52, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "Panel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 1, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 34, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 200, - "y": 0, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "PageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "PageView", - "name": "PageView_37", - "ZOrder": 0, - "actiontag": 37, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "PageView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.735416651, - "positionPercentY": 0.209375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.208333328, - "sizePercentY": 0.3125, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 706, - "y": 134, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 100, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 100, - "bgEndColorG": 150, - "bgEndColorR": 255, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_20", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "Panel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 640, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0, - "sizePercentY": 0, - "sizeType": 0, - "tag": 3, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 960, - "x": 0, - "y": 0, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } +{ + "classname": null, + "name": null, + "animation": { + "classname": null, + "name": "AnimationManager", + "actionlist": [] + }, + "dataScale": 0.4999999, + "designHeight": 640, + "designWidth": 960, + "textures": [ + "CocostudioV1_30.plist" + ], + "version": "1.3.0.1", + "widgetTree": { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "Panel", + "name": null, + "children": [], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_22", + "ZOrder": 0, + "actiontag": 22, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "Panel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 640, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0, + "positionPercentY": 0, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 4, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 960, + "x": 0, + "y": 0, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_23", + "ZOrder": 0, + "actiontag": 23, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "Button", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.08125, + "positionPercentY": 0.9109375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.107291669, + "sizePercentY": 0.0625, + "sizeType": 0, + "tag": 5, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 78, + "y": 583, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_24", + "ZOrder": 0, + "actiontag": 24, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.192708328, + "positionPercentY": 0.903125, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.0583333336, + "sizePercentY": 0.0875, + "sizeType": 0, + "tag": 6, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 185, + "y": 578, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "ImageView", + "name": null, + "children": [], + "options": { + "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ImageView", + "name": "ImageView_25", + "ZOrder": 0, + "actiontag": 25, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "ImageView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 80, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.29375, + "positionPercentY": 0.9046875, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.0833333358, + "sizePercentY": 0.125, + "sizeType": 0, + "tag": 7, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 80, + "x": 282, + "y": 579, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "fileName": null, + "fileNameData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", + "plistFile": "", + "resourceType": 1 + }, + "scale9Enable": false, + "scale9Height": 80, + "scale9Width": 80 + } + }, + { + "classname": "LabelAtlas", + "name": null, + "children": [], + "options": { + "__type": "LabelAtlasSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelAtlas", + "name": "LabelAtlas_26", + "ZOrder": 0, + "actiontag": 26, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "LabelAtlas", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 32, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.5229167, + "positionPercentY": 0.903125, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.25, + "sizePercentY": 0.05, + "sizeType": 0, + "tag": 8, + "touchAble": false, + "useMergedTexture": false, + "visible": true, + "width": 240, + "x": 502, + "y": 578, + "charMapFile": null, + "charMapFileData": { + "path": "GUI/labelatlasimg.png", + "plistFile": "", + "resourceType": 0 + }, + "itemHeight": 32, + "itemWidth": 24, + "startCharMap": "0", + "stringValue": "0123456789" + } + }, + { + "classname": "LabelBMFont", + "name": null, + "children": [], + "options": { + "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelBMFont", + "name": "LabelBMFont_27", + "ZOrder": 0, + "actiontag": 27, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "LabelBMFont", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 37, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.826041639, + "positionPercentY": 0.896875, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.244791672, + "sizePercentY": 0.0578125, + "sizeType": 0, + "tag": 9, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 235, + "x": 793, + "y": 574, + "fileNameData": { + "path": "GUI/missing-font.fnt", + "plistFile": "", + "resourceType": 0 + }, + "text": "Text Label" + } + }, + { + "classname": "LoadingBar", + "name": null, + "children": [], + "options": { + "__type": "LoadingBarSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LoadingBar", + "name": "LoadingBar_28", + "ZOrder": 0, + "actiontag": 28, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "LoadingBar", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 24, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.230208337, + "positionPercentY": 0.7609375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.364583343, + "sizePercentY": 0.0375, + "sizeType": 0, + "tag": 10, + "touchAble": false, + "useMergedTexture": false, + "visible": true, + "width": 350, + "x": 221, + "y": 487, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "direction": 0, + "percent": 100, + "scale9Enable": false, + "texture": null, + "textureData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/loadingbar.png", + "plistFile": "", + "resourceType": 1 + } + } + }, + { + "classname": "Slider", + "name": null, + "children": [], + "options": { + "__type": "SliderSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Slider", + "name": "Slider_29", + "ZOrder": 0, + "actiontag": 29, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "Slider", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 8, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.597916663, + "positionPercentY": 0.784375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.302083343, + "sizePercentY": 0.0125, + "sizeType": 0, + "tag": 11, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 290, + "x": 574, + "y": 502, + "ballDisabled": null, + "ballDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "ballNormal": null, + "ballNormalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/slider_bar_button.png", + "plistFile": "", + "resourceType": 1 + }, + "ballPressed": null, + "ballPressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "barCapInsetsHeight": 1, + "barCapInsetsWidth": 1, + "barCapInsetsX": 0, + "barCapInsetsY": 0, + "barFileName": null, + "barFileNameData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/slider_bar.png", + "plistFile": "", + "resourceType": 1 + }, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "length": 290, + "percent": 0, + "progressBarCapInsetsHeight": 0, + "progressBarCapInsetsWidth": 0, + "progressBarCapInsetsX": 0, + "progressBarCapInsetsY": 0, + "progressBarData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "progressBarVisible": false, + "scale9Enable": false, + "scale9Height": 0, + "scale9Width": 0, + "slidBallAnchorPointX": 0, + "slidBallAnchorPointY": 0 + } + }, + { + "classname": "Label", + "name": null, + "children": [], + "options": { + "__type": "LabelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Label", + "name": "Label_30", + "ZOrder": 0, + "actiontag": 30, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "Label", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 27, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.888541639, + "positionPercentY": 0.7921875, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.0989583358, + "sizePercentY": 0.0421875, + "sizeType": 0, + "tag": 12, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 95, + "x": 853, + "y": 507, + "areaHeight": 0, + "areaWidth": 0, + "fontFile": null, + "fontName": "微软雅黑", + "fontSize": 20, + "hAlignment": 0, + "text": "Text Label", + "touchScaleEnable": false, + "vAlignment": 0 + } + }, + { + "classname": "TextField", + "name": null, + "children": [], + "options": { + "__type": "TextFieldSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "TextField", + "name": "TextField_31", + "ZOrder": 0, + "actiontag": 31, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "TextField", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 27, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.0604166649, + "positionPercentY": 0.6796875, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.09375, + "sizePercentY": 0.0421875, + "sizeType": 0, + "tag": 13, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 90, + "x": 58, + "y": 435, + "areaHeight": 0, + "areaWidth": 0, + "fontFile": null, + "fontName": "微软雅黑", + "fontSize": 20, + "maxLength": 10, + "maxLengthEnable": false, + "passwordEnable": false, + "passwordStyleText": "*", + "placeHolder": "input words here", + "text": "Text Field" + } + }, + { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_38", + "ZOrder": 0, + "actiontag": 38, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "Button", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.325, + "positionPercentY": 0.83, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 20, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 65, + "y": 166, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_39", + "ZOrder": 0, + "actiontag": 39, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.765, + "positionPercentY": 0.82, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.28, + "sizePercentY": 0.28, + "sizeType": 0, + "tag": 21, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 153, + "y": 164, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "ImageView", + "name": null, + "children": [], + "options": { + "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ImageView", + "name": "ImageView_40", + "ZOrder": 0, + "actiontag": 40, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "ImageView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 80, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.25, + "positionPercentY": 0.46, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.4, + "sizePercentY": 0.4, + "sizeType": 0, + "tag": 22, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 80, + "x": 50, + "y": 92, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "fileName": null, + "fileNameData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", + "plistFile": "", + "resourceType": 1 + }, + "scale9Enable": false, + "scale9Height": 80, + "scale9Width": 80 + } + }, + { + "classname": "LabelAtlas", + "name": null, + "children": [], + "options": { + "__type": "LabelAtlasSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelAtlas", + "name": "LabelAtlas_41", + "ZOrder": 0, + "actiontag": 41, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "LabelAtlas", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 32, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.795, + "positionPercentY": 0.49, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.24, + "sizePercentY": 0.16, + "sizeType": 0, + "tag": 23, + "touchAble": false, + "useMergedTexture": false, + "visible": true, + "width": 48, + "x": 159, + "y": 98, + "charMapFile": null, + "charMapFileData": { + "path": "GUI/labelatlasimg.png", + "plistFile": "", + "resourceType": 0 + }, + "itemHeight": 32, + "itemWidth": 24, + "startCharMap": "0", + "stringValue": "11" + } + }, + { + "classname": "LabelBMFont", + "name": null, + "children": [], + "options": { + "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelBMFont", + "name": "LabelBMFont_42", + "ZOrder": 0, + "actiontag": 42, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "LabelBMFont", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 37, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.7, + "positionPercentY": 0.195, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.29, + "sizePercentY": 0.185, + "sizeType": 0, + "tag": 24, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 58, + "x": 140, + "y": 39, + "fileNameData": { + "path": "GUI/missing-font.fnt", + "plistFile": "", + "resourceType": 0 + }, + "text": "22" + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_34", + "ZOrder": 0, + "actiontag": 34, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "Panel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.009375, + "positionPercentY": 0.209375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.208333328, + "sizePercentY": 0.3125, + "sizeType": 0, + "tag": 16, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 9, + "y": 134, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "ScrollView", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_43", + "ZOrder": 0, + "actiontag": 43, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "Button", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.525, + "positionPercentY": 1.6, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 25, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 105, + "y": 320, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_44", + "ZOrder": 0, + "actiontag": 44, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.95, + "positionPercentY": 1.12, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.28, + "sizePercentY": 0.28, + "sizeType": 0, + "tag": 26, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 190, + "y": 224, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "ImageView", + "name": null, + "children": [], + "options": { + "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ImageView", + "name": "ImageView_45", + "ZOrder": 0, + "actiontag": 45, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "ImageView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 80, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 1.72, + "positionPercentY": 0.54, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.4, + "sizePercentY": 0.4, + "sizeType": 0, + "tag": 27, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 80, + "x": 344, + "y": 108, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "fileName": null, + "fileNameData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", + "plistFile": "", + "resourceType": 1 + }, + "scale9Enable": false, + "scale9Height": 80, + "scale9Width": 80 + } + } + ], + "options": { + "__type": "ScrollViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ScrollView", + "name": "ScrollView_35", + "ZOrder": 0, + "actiontag": 35, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "ScrollView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.25, + "positionPercentY": 0.209375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.208333328, + "sizePercentY": 0.3125, + "sizeType": 0, + "tag": 17, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 240, + "y": 134, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 100, + "bgColorG": 150, + "bgColorOpacity": 100, + "bgColorR": 255, + "bgEndColorB": 100, + "bgEndColorG": 150, + "bgEndColorR": 255, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "bounceEnable": false, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": true, + "colorType": 1, + "direction": 3, + "innerHeight": 400, + "innerWidth": 400, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "ListView", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_47", + "ZOrder": 0, + "actiontag": 47, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "Button", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "Button_47", + "relativeToName": "ListView_36", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.10864979, + "positionPercentY": 0.9, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 29, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 62, + "y": 168, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_48", + "ZOrder": 1, + "actiontag": 48, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "CheckBox_48", + "relativeToName": "ListView_36", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.2763713, + "positionPercentY": 0.86, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.28, + "sizePercentY": 0.28, + "sizeType": 0, + "tag": 30, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 50, + "y": 134, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "ImageView", + "name": null, + "children": [], + "options": { + "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ImageView", + "name": "ImageView_49", + "ZOrder": 2, + "actiontag": 49, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "ImageView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 80, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "ImageView_49", + "relativeToName": "ListView_36", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.419831216, + "positionPercentY": 0.8, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.4, + "sizePercentY": 0.4, + "sizeType": 0, + "tag": 31, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 80, + "x": 100, + "y": 98, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "fileName": null, + "fileNameData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", + "plistFile": "", + "resourceType": 1 + }, + "scale9Enable": false, + "scale9Height": 80, + "scale9Width": 80 + } + }, + { + "classname": "LabelBMFont", + "name": null, + "children": [], + "options": { + "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelBMFont", + "name": "LabelBMFont_50", + "ZOrder": 3, + "actiontag": 50, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "LabelBMFont", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 37, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "LabelBMFont_50", + "relativeToName": "ListView_36", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.7521097, + "positionPercentY": 0.9075, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1.175, + "sizePercentY": 0.185, + "sizeType": 0, + "tag": 32, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 235, + "x": 122, + "y": 81, + "fileNameData": { + "path": "GUI/missing-font.fnt", + "plistFile": "", + "resourceType": 0 + }, + "text": "Text Label" + } + } + ], + "options": { + "__type": "ListViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ListView", + "name": "ListView_36", + "ZOrder": 0, + "actiontag": 36, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "ListView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.496875, + "positionPercentY": 0.209375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.208333328, + "sizePercentY": 0.3125, + "sizeType": 0, + "tag": 18, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 477, + "y": 134, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 150, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 150, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "bounceEnable": true, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": true, + "colorType": 1, + "direction": 2, + "gravity": 3, + "innerHeight": 0, + "innerWidth": 0, + "itemMargin": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "PageView", + "name": null, + "children": [ + { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_53", + "ZOrder": 0, + "actiontag": 53, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "Button", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.34, + "positionPercentY": 0.845, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 35, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 68, + "y": 169, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_54", + "ZOrder": 0, + "actiontag": 54, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.41, + "positionPercentY": 0.62, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.28, + "sizePercentY": 0.28, + "sizeType": 0, + "tag": 36, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 82, + "y": 124, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "LoadingBar", + "name": null, + "children": [], + "options": { + "__type": "LoadingBarSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LoadingBar", + "name": "LoadingBar_55", + "ZOrder": 0, + "actiontag": 55, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "LoadingBar", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 24, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.975, + "positionPercentY": 0.38, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1.75, + "sizePercentY": 0.12, + "sizeType": 0, + "tag": 37, + "touchAble": false, + "useMergedTexture": false, + "visible": true, + "width": 350, + "x": 195, + "y": 76, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "direction": 0, + "percent": 50, + "scale9Enable": false, + "texture": null, + "textureData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/loadingbar.png", + "plistFile": "", + "resourceType": 1 + } + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_51", + "ZOrder": 0, + "actiontag": 51, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "Panel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0, + "positionPercentY": 0, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 33, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 0, + "y": 0, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_56", + "ZOrder": 0, + "actiontag": 56, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "Button", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.48, + "positionPercentY": 0.83, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 38, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 96, + "y": 166, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_57", + "ZOrder": 0, + "actiontag": 57, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.46, + "positionPercentY": 0.49, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.28, + "sizePercentY": 0.28, + "sizeType": 0, + "tag": 39, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 92, + "y": 98, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "ImageView", + "name": null, + "children": [], + "options": { + "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ImageView", + "name": "ImageView_58", + "ZOrder": 0, + "actiontag": 58, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "ImageView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 80, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.51, + "positionPercentY": 0.165, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.4, + "sizePercentY": 0.4, + "sizeType": 0, + "tag": 40, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 80, + "x": 102, + "y": 33, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "fileName": null, + "fileNameData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", + "plistFile": "", + "resourceType": 1 + }, + "scale9Enable": false, + "scale9Height": 80, + "scale9Width": 80 + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_52", + "ZOrder": 0, + "actiontag": 52, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "Panel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 1, + "positionPercentY": 0, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 34, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 200, + "y": 0, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + } + ], + "options": { + "__type": "PageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "PageView", + "name": "PageView_37", + "ZOrder": 0, + "actiontag": 37, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "PageView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.735416651, + "positionPercentY": 0.209375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.208333328, + "sizePercentY": 0.3125, + "sizeType": 0, + "tag": 19, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 706, + "y": 134, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 100, + "bgColorG": 150, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 100, + "bgEndColorG": 150, + "bgEndColorR": 255, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": true, + "colorType": 1, + "vectorX": 0, + "vectorY": -0.5 + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_20", + "ZOrder": 0, + "actiontag": -1, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "Panel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 640, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0, + "positionPercentY": 0, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0, + "sizePercentY": 0, + "sizeType": 0, + "tag": 3, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 960, + "x": 0, + "y": 0, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 0, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + } } \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/CocostudioV1_30.plist b/samples/js-tests/res/cocosui/CCS/ccs1_3/CocostudioV1_30.plist similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/CocostudioV1_30.plist rename to samples/js-tests/res/cocosui/CCS/ccs1_3/CocostudioV1_30.plist diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/CocostudioV1_30.png b/samples/js-tests/res/cocosui/CCS/ccs1_3/CocostudioV1_30.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/CocostudioV1_30.png rename to samples/js-tests/res/cocosui/CCS/ccs1_3/CocostudioV1_30.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/GUI/labelatlasimg.png b/samples/js-tests/res/cocosui/CCS/ccs1_3/GUI/labelatlasimg.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/GUI/labelatlasimg.png rename to samples/js-tests/res/cocosui/CCS/ccs1_3/GUI/labelatlasimg.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/GUI/missing-font.fnt b/samples/js-tests/res/cocosui/CCS/ccs1_3/GUI/missing-font.fnt similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/GUI/missing-font.fnt rename to samples/js-tests/res/cocosui/CCS/ccs1_3/GUI/missing-font.fnt diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/GUI/missing-font.png b/samples/js-tests/res/cocosui/CCS/ccs1_3/GUI/missing-font.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/GUI/missing-font.png rename to samples/js-tests/res/cocosui/CCS/ccs1_3/GUI/missing-font.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/SmallSun.plist b/samples/js-tests/res/cocosui/CCS/ccs1_3/SmallSun.plist similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_3/SmallSun.plist rename to samples/js-tests/res/cocosui/CCS/ccs1_3/SmallSun.plist diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/Cocostudio1_4_1.ExportJson b/samples/js-tests/res/cocosui/CCS/ccs1_4/CCS1_4_1.ExportJson similarity index 97% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/Cocostudio1_4_1.ExportJson rename to samples/js-tests/res/cocosui/CCS/ccs1_4/CCS1_4_1.ExportJson index 3d0227705e..44a7fc1c10 100644 --- a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/Cocostudio1_4_1.ExportJson +++ b/samples/js-tests/res/cocosui/CCS/ccs1_4/CCS1_4_1.ExportJson @@ -1,2639 +1,2639 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 0.4999999, - "designHeight": 320, - "designWidth": 480, - "textures": [ - "Cocostudio1_40.plist" - ], - "texturesPng": [ - "Cocostudio1_40.png" - ], - "version": "1.4.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_2", - "ZOrder": 0, - "actiontag": 2, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.09583333, - "positionPercentY": 0.653125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.107291669, - "sizePercentY": 0.0625, - "sizeType": 0, - "tag": 5, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 92, - "y": 418, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_3", - "ZOrder": 0, - "actiontag": 3, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.722916663, - "positionPercentY": 0.93125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.0583333336, - "sizePercentY": 0.0875, - "sizeType": 0, - "tag": 6, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 694, - "y": 596, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "Image_4", - "ZOrder": 0, - "actiontag": 4, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSImageView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.54375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.0833333358, - "sizePercentY": 0.125, - "sizeType": 0, - "tag": 7, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 80, - "x": 77, - "y": 348, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/image.png", - "plistFile": "", - "resourceType": 1 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "LabelAtlas", - "name": null, - "children": [], - "options": { - "__type": "LabelAtlasSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelAtlas", - "name": "AtlasLabel_5", - "ZOrder": 0, - "actiontag": 5, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLabelAtlas", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 32, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.422916681, - "positionPercentY": 0.89375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.25, - "sizePercentY": 0.05, - "sizeType": 0, - "tag": 8, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 240, - "x": 406, - "y": 572, - "charMapFile": null, - "charMapFileData": { - "path": "GUI/labelatlasimg.png", - "plistFile": "", - "resourceType": 0 - }, - "itemHeight": 32, - "itemWidth": 24, - "startCharMap": "0", - "stringValue": "0123456789" - } - }, - { - "classname": "LabelBMFont", - "name": null, - "children": [], - "options": { - "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelBMFont", - "name": "BitmapLabel_6", - "ZOrder": 0, - "actiontag": 6, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLabelBMFont", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 37, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.68125, - "positionPercentY": 0.8390625, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.244791672, - "sizePercentY": 0.0578125, - "sizeType": 0, - "tag": 9, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 235, - "x": 654, - "y": 537, - "fileNameData": { - "path": "GUI/missing-font.fnt", - "plistFile": "", - "resourceType": 0 - }, - "text": "Text Label" - } - }, - { - "classname": "LoadingBar", - "name": null, - "children": [], - "options": { - "__type": "LoadingBarSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LoadingBar", - "name": "ProgressBar_7", - "ZOrder": 0, - "actiontag": 7, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLoadingBar", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 24, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.19479166, - "positionPercentY": 0.4125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.364583343, - "sizePercentY": 0.0375, - "sizeType": 0, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 350, - "x": 187, - "y": 264, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "direction": 0, - "percent": 20, - "scale9Enable": false, - "texture": null, - "textureData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/loadingbar.png", - "plistFile": "", - "resourceType": 1 - } - } - }, - { - "classname": "Slider", - "name": null, - "children": [], - "options": { - "__type": "SliderSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Slider", - "name": "Slider_8", - "ZOrder": 0, - "actiontag": 8, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSSlider", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 8, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.503125, - "positionPercentY": 0.0484375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.302083343, - "sizePercentY": 0.0125, - "sizeType": 0, - "tag": 11, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 290, - "x": 483, - "y": 31, - "ballDisabled": null, - "ballDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "ballNormal": null, - "ballNormalData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/slider_bar_button.png", - "plistFile": "", - "resourceType": 1 - }, - "ballPressed": null, - "ballPressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "barCapInsetsHeight": 1, - "barCapInsetsWidth": 1, - "barCapInsetsX": 0, - "barCapInsetsY": 0, - "barFileName": null, - "barFileNameData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/slider_bar.png", - "plistFile": "", - "resourceType": 1 - }, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "length": 290, - "percent": 0, - "progressBarCapInsetsHeight": 0, - "progressBarCapInsetsWidth": 0, - "progressBarCapInsetsX": 0, - "progressBarCapInsetsY": 0, - "progressBarData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "progressBarVisible": false, - "scale9Enable": false, - "scale9Height": 0, - "scale9Width": 0, - "slidBallAnchorPointX": 0, - "slidBallAnchorPointY": 0 - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1", - "ZOrder": 0, - "actiontag": 1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPanel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 640, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.00520833349, - "positionPercentY": -0.009375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 4, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 960, - "x": 5, - "y": -6, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 198, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "LabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_9", - "ZOrder": 0, - "actiontag": 9, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLabel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.871875, - "positionPercentY": 0.934375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.0989583358, - "sizePercentY": 0.0421875, - "sizeType": 0, - "tag": 12, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 95, - "x": 837, - "y": 598, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "Text Label", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_10", - "ZOrder": 0, - "actiontag": 10, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPanel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.766666651, - "positionPercentY": 0.1, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.208333328, - "sizePercentY": 0.3125, - "sizeType": 0, - "tag": 13, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 736, - "y": 64, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "ScrollView", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_12", - "ZOrder": 0, - "actiontag": 12, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 1, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 38, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Button_12", - "relativeToName": "ScrollView_11", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.2575, - "positionPercentY": 0.9, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 15, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 51, - "y": 180, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_13", - "ZOrder": 0, - "actiontag": 13, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 1, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 103, - "marginRight": 0, - "marginTop": -40, - "relativeName": "Button_13", - "relativeToName": "ScrollView_11", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.7725, - "positionPercentY": 0.71, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 16, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 154, - "y": 142, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - } - ], - "options": { - "__type": "ScrollViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ScrollView", - "name": "ScrollView_11", - "ZOrder": 0, - "actiontag": 11, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSScrollView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.104166664, - "positionPercentY": 0.0296875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.208333328, - "sizePercentY": 0.3125, - "sizeType": 0, - "tag": 14, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 100, - "y": 19, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 100, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 255, - "bgEndColorB": 100, - "bgEndColorG": 150, - "bgEndColorR": 255, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "bounceEnable": false, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "direction": 1, - "editorClipAble": true, - "innerHeight": 200, - "innerWidth": 200, - "layoutType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "ListView", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_15", - "ZOrder": 0, - "actiontag": 16, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Button_15", - "relativeToName": "ListView_14", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.321875, - "positionPercentY": 0.940119743, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.64375, - "sizePercentY": 0.266666681, - "sizeType": 0, - "tag": 18, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 51, - "y": 314, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 21, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Test", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_16", - "ZOrder": 1, - "actiontag": 17, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Button_16", - "relativeToName": "ListView_14", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.321875, - "positionPercentY": 0.8203593, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.64375, - "sizePercentY": 0.266666681, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 51, - "y": 274, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_17", - "ZOrder": 2, - "actiontag": 18, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Button_17", - "relativeToName": "ListView_14", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.321875, - "positionPercentY": 0.7005988, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.64375, - "sizePercentY": 0.266666681, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 51, - "y": 234, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_35", - "ZOrder": 3, - "actiontag": 35, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "CheckBox_35", - "relativeToName": "ListView_14", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.175, - "positionPercentY": 0.556886256, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.35, - "sizePercentY": 0.373333335, - "sizeType": 0, - "tag": 50, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 28, - "y": 186, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "LabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_36", - "ZOrder": 4, - "actiontag": 36, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLabel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Label_36", - "relativeToName": "ListView_14", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.296875, - "positionPercentY": 0.432634741, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.59375, - "sizePercentY": 0.18, - "sizeType": 0, - "tag": 51, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 95, - "x": 47, - "y": 144, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "Text Label", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "TextField", - "name": null, - "children": [], - "options": { - "__type": "TextFieldSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "TextField", - "name": "TextField_37", - "ZOrder": 5, - "actiontag": 37, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSTextField", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "TextField_37", - "relativeToName": "ListView_14", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.28125, - "positionPercentY": 0.351796418, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.5625, - "sizePercentY": 0.18, - "sizeType": 0, - "tag": 52, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 90, - "x": 45, - "y": 117, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "maxLength": 10, - "maxLengthEnable": false, - "passwordEnable": false, - "passwordStyleText": "*", - "placeHolder": "input words here", - "text": "Text Field" - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "Image_38", - "ZOrder": 6, - "actiontag": 38, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSImageView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Image_38", - "relativeToName": "ListView_14", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.25, - "positionPercentY": 0.191616774, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.5, - "sizePercentY": 0.533333361, - "sizeType": 0, - "tag": 53, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 80, - "x": 40, - "y": 64, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/image.png", - "plistFile": "", - "resourceType": 1 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "LoadingBar", - "name": null, - "children": [], - "options": { - "__type": "LoadingBarSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LoadingBar", - "name": "ProgressBar_39", - "ZOrder": 7, - "actiontag": 39, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLoadingBar", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 24, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "ProgressBar_39", - "relativeToName": "ListView_14", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 1.09375, - "positionPercentY": 0.0359281451, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 2.1875, - "sizePercentY": 0.16, - "sizeType": 0, - "tag": 54, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 350, - "x": 175, - "y": 12, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "direction": 0, - "percent": 100, - "scale9Enable": false, - "texture": null, - "textureData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/loadingbar.png", - "plistFile": "", - "resourceType": 1 - } - } - } - ], - "options": { - "__type": "ListViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ListView", - "name": "ListView_14", - "ZOrder": 0, - "actiontag": 15, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSListView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 150, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.457291663, - "positionPercentY": 0.171875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.166666672, - "sizePercentY": 0.234375, - "sizeType": 0, - "tag": 17, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 160, - "x": 439, - "y": 110, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 150, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "bounceEnable": true, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "direction": 1, - "editorClipAble": true, - "gravity": 0, - "innerHeight": 0, - "innerWidth": 0, - "itemMargin": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "PageView", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_22", - "ZOrder": 0, - "actiontag": 22, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.735, - "positionPercentY": 0.845, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 25, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 147, - "y": 169, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_23", - "ZOrder": 0, - "actiontag": 23, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.38, - "positionPercentY": 0.165, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 26, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 76, - "y": 33, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_21", - "ZOrder": 0, - "actiontag": 21, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPanel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 24, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 0, - "y": 0, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "ScrollView", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_28", - "ZOrder": 0, - "actiontag": 28, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 1.42, - "positionPercentY": 0.67, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 31, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 284, - "y": 134, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "LabelBMFont", - "name": null, - "children": [], - "options": { - "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelBMFont", - "name": "BitmapLabel_29", - "ZOrder": 0, - "actiontag": 29, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLabelBMFont", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 37, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.85, - "positionPercentY": 1.28, - "positionType": 0, - "rotation": 0, - "scaleX": 0.416413516, - "scaleY": 1, - "sizePercentX": 1.175, - "sizePercentY": 0.185, - "sizeType": 0, - "tag": 32, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 235, - "x": 170, - "y": 256, - "fileNameData": { - "path": "GUI/missing-font.fnt", - "plistFile": "", - "resourceType": 0 - }, - "text": "Text Label" - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_31", - "ZOrder": 0, - "actiontag": 31, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPanel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.1, - "positionPercentY": 0.175, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 40, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 40, - "y": 70, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ScrollViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ScrollView", - "name": "ScrollView_26", - "ZOrder": 0, - "actiontag": 26, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSScrollView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.005, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 0.491353333, - "scaleY": 0.491869867, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 29, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 1, - "y": 100, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 100, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 255, - "bgEndColorB": 100, - "bgEndColorG": 150, - "bgEndColorR": 255, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "bounceEnable": true, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "direction": 3, - "editorClipAble": true, - "innerHeight": 400, - "innerWidth": 400, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_24", - "ZOrder": 0, - "actiontag": 24, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPanel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 1, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 27, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 200, - "y": 0, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "ListView", - "name": null, - "children": [ - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "Image_32", - "ZOrder": 0, - "actiontag": 32, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSImageView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Image_32", - "relativeToName": "ListView_27", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.2, - "positionPercentY": 0.8, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.4, - "sizePercentY": 0.4, - "sizeType": 0, - "tag": 35, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 80, - "x": 40, - "y": 160, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/image.png", - "plistFile": "", - "resourceType": 1 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_33", - "ZOrder": 1, - "actiontag": 33, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "CheckBox_33", - "relativeToName": "ListView_27", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.14, - "positionPercentY": 0.46, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.28, - "sizePercentY": 0.28, - "sizeType": 0, - "tag": 36, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 28, - "y": 92, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_34", - "ZOrder": 2, - "actiontag": 34, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Button_34", - "relativeToName": "ListView_27", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.2575, - "positionPercentY": 0.22, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 37, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 51, - "y": 44, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - } - ], - "options": { - "__type": "ListViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ListView", - "name": "ListView_27", - "ZOrder": 0, - "actiontag": 27, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSListView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.005, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 30, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 0, - "y": 1, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 150, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "bounceEnable": false, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "direction": 1, - "editorClipAble": false, - "gravity": 0, - "innerHeight": 0, - "innerWidth": 0, - "itemMargin": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_25", - "ZOrder": 0, - "actiontag": 25, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPanel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 2, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 28, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 400, - "y": 0, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "PageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "PageView", - "name": "PagetView_18", - "ZOrder": 0, - "actiontag": 19, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPageView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.222916663, - "positionPercentY": 0.490625, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.208333328, - "sizePercentY": 0.3125, - "sizeType": 0, - "tag": 21, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 214, - "y": 314, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 100, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 100, - "bgEndColorG": 150, - "bgEndColorR": 255, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "editorClipAble": false, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_14", - "ZOrder": 0, - "actiontag": 14, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPanel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 640, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 3, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 960, - "x": 0, - "y": 0, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } +{ + "classname": null, + "name": null, + "animation": { + "classname": null, + "name": "AnimationManager", + "actionlist": [] + }, + "dataScale": 0.4999999, + "designHeight": 320, + "designWidth": 480, + "textures": [ + "Cocostudio1_40.plist" + ], + "texturesPng": [ + "Cocostudio1_40.png" + ], + "version": "1.4.0.1", + "widgetTree": { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_2", + "ZOrder": 0, + "actiontag": 2, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.09583333, + "positionPercentY": 0.653125, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.107291669, + "sizePercentY": 0.0625, + "sizeType": 0, + "tag": 5, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 92, + "y": 418, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_3", + "ZOrder": 0, + "actiontag": 3, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.722916663, + "positionPercentY": 0.93125, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.0583333336, + "sizePercentY": 0.0875, + "sizeType": 0, + "tag": 6, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 694, + "y": 596, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "ImageView", + "name": null, + "children": [], + "options": { + "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ImageView", + "name": "Image_4", + "ZOrder": 0, + "actiontag": 4, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSImageView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 80, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.08020833, + "positionPercentY": 0.54375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.0833333358, + "sizePercentY": 0.125, + "sizeType": 0, + "tag": 7, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 80, + "x": 77, + "y": 348, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "fileName": null, + "fileNameData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/image.png", + "plistFile": "", + "resourceType": 1 + }, + "scale9Enable": false, + "scale9Height": 80, + "scale9Width": 80 + } + }, + { + "classname": "LabelAtlas", + "name": null, + "children": [], + "options": { + "__type": "LabelAtlasSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelAtlas", + "name": "AtlasLabel_5", + "ZOrder": 0, + "actiontag": 5, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLabelAtlas", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 32, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.422916681, + "positionPercentY": 0.89375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.25, + "sizePercentY": 0.05, + "sizeType": 0, + "tag": 8, + "touchAble": false, + "useMergedTexture": false, + "visible": true, + "width": 240, + "x": 406, + "y": 572, + "charMapFile": null, + "charMapFileData": { + "path": "GUI/labelatlasimg.png", + "plistFile": "", + "resourceType": 0 + }, + "itemHeight": 32, + "itemWidth": 24, + "startCharMap": "0", + "stringValue": "0123456789" + } + }, + { + "classname": "LabelBMFont", + "name": null, + "children": [], + "options": { + "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelBMFont", + "name": "BitmapLabel_6", + "ZOrder": 0, + "actiontag": 6, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLabelBMFont", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 37, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.68125, + "positionPercentY": 0.8390625, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.244791672, + "sizePercentY": 0.0578125, + "sizeType": 0, + "tag": 9, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 235, + "x": 654, + "y": 537, + "fileNameData": { + "path": "GUI/missing-font.fnt", + "plistFile": "", + "resourceType": 0 + }, + "text": "Text Label" + } + }, + { + "classname": "LoadingBar", + "name": null, + "children": [], + "options": { + "__type": "LoadingBarSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LoadingBar", + "name": "ProgressBar_7", + "ZOrder": 0, + "actiontag": 7, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLoadingBar", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 24, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.19479166, + "positionPercentY": 0.4125, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.364583343, + "sizePercentY": 0.0375, + "sizeType": 0, + "tag": 10, + "touchAble": false, + "useMergedTexture": false, + "visible": true, + "width": 350, + "x": 187, + "y": 264, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "direction": 0, + "percent": 20, + "scale9Enable": false, + "texture": null, + "textureData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/loadingbar.png", + "plistFile": "", + "resourceType": 1 + } + } + }, + { + "classname": "Slider", + "name": null, + "children": [], + "options": { + "__type": "SliderSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Slider", + "name": "Slider_8", + "ZOrder": 0, + "actiontag": 8, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSSlider", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 8, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.503125, + "positionPercentY": 0.0484375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.302083343, + "sizePercentY": 0.0125, + "sizeType": 0, + "tag": 11, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 290, + "x": 483, + "y": 31, + "ballDisabled": null, + "ballDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "ballNormal": null, + "ballNormalData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/slider_bar_button.png", + "plistFile": "", + "resourceType": 1 + }, + "ballPressed": null, + "ballPressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "barCapInsetsHeight": 1, + "barCapInsetsWidth": 1, + "barCapInsetsX": 0, + "barCapInsetsY": 0, + "barFileName": null, + "barFileNameData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/slider_bar.png", + "plistFile": "", + "resourceType": 1 + }, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "length": 290, + "percent": 0, + "progressBarCapInsetsHeight": 0, + "progressBarCapInsetsWidth": 0, + "progressBarCapInsetsX": 0, + "progressBarCapInsetsY": 0, + "progressBarData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "progressBarVisible": false, + "scale9Enable": false, + "scale9Height": 0, + "scale9Width": 0, + "slidBallAnchorPointX": 0, + "slidBallAnchorPointY": 0 + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_1", + "ZOrder": 0, + "actiontag": 1, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPanel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 640, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.00520833349, + "positionPercentY": -0.009375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 4, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 960, + "x": 5, + "y": -6, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 198, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "Label", + "name": null, + "children": [], + "options": { + "__type": "LabelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Label", + "name": "Label_9", + "ZOrder": 0, + "actiontag": 9, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLabel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 27, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.871875, + "positionPercentY": 0.934375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.0989583358, + "sizePercentY": 0.0421875, + "sizeType": 0, + "tag": 12, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 95, + "x": 837, + "y": 598, + "areaHeight": 0, + "areaWidth": 0, + "fontFile": null, + "fontName": "微软雅黑", + "fontSize": 20, + "hAlignment": 0, + "text": "Text Label", + "touchScaleEnable": false, + "vAlignment": 0 + } + }, + { + "classname": "Panel", + "name": null, + "children": [], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_10", + "ZOrder": 0, + "actiontag": 10, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPanel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.766666651, + "positionPercentY": 0.1, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.208333328, + "sizePercentY": 0.3125, + "sizeType": 0, + "tag": 13, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 736, + "y": 64, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "ScrollView", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_12", + "ZOrder": 0, + "actiontag": 12, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 1, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 38, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "Button_12", + "relativeToName": "ScrollView_11", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.2575, + "positionPercentY": 0.9, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 15, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 51, + "y": 180, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_13", + "ZOrder": 0, + "actiontag": 13, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 1, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 103, + "marginRight": 0, + "marginTop": -40, + "relativeName": "Button_13", + "relativeToName": "ScrollView_11", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.7725, + "positionPercentY": 0.71, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 16, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 154, + "y": 142, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + } + ], + "options": { + "__type": "ScrollViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ScrollView", + "name": "ScrollView_11", + "ZOrder": 0, + "actiontag": 11, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSScrollView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.104166664, + "positionPercentY": 0.0296875, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.208333328, + "sizePercentY": 0.3125, + "sizeType": 0, + "tag": 14, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 100, + "y": 19, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 100, + "bgColorG": 150, + "bgColorOpacity": 100, + "bgColorR": 255, + "bgEndColorB": 100, + "bgEndColorG": 150, + "bgEndColorR": 255, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "bounceEnable": false, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": true, + "colorType": 1, + "direction": 1, + "editorClipAble": true, + "innerHeight": 200, + "innerWidth": 200, + "layoutType": 1, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "ListView", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_15", + "ZOrder": 0, + "actiontag": 16, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "Button_15", + "relativeToName": "ListView_14", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.321875, + "positionPercentY": 0.940119743, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.64375, + "sizePercentY": 0.266666681, + "sizeType": 0, + "tag": 18, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 51, + "y": 314, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 21, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "Test", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_16", + "ZOrder": 1, + "actiontag": 17, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "Button_16", + "relativeToName": "ListView_14", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.321875, + "positionPercentY": 0.8203593, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.64375, + "sizePercentY": 0.266666681, + "sizeType": 0, + "tag": 19, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 51, + "y": 274, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_17", + "ZOrder": 2, + "actiontag": 18, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "Button_17", + "relativeToName": "ListView_14", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.321875, + "positionPercentY": 0.7005988, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.64375, + "sizePercentY": 0.266666681, + "sizeType": 0, + "tag": 20, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 51, + "y": 234, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_35", + "ZOrder": 3, + "actiontag": 35, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "CheckBox_35", + "relativeToName": "ListView_14", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.175, + "positionPercentY": 0.556886256, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.35, + "sizePercentY": 0.373333335, + "sizeType": 0, + "tag": 50, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 28, + "y": 186, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "Label", + "name": null, + "children": [], + "options": { + "__type": "LabelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Label", + "name": "Label_36", + "ZOrder": 4, + "actiontag": 36, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLabel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 27, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "Label_36", + "relativeToName": "ListView_14", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.296875, + "positionPercentY": 0.432634741, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.59375, + "sizePercentY": 0.18, + "sizeType": 0, + "tag": 51, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 95, + "x": 47, + "y": 144, + "areaHeight": 0, + "areaWidth": 0, + "fontFile": null, + "fontName": "微软雅黑", + "fontSize": 20, + "hAlignment": 0, + "text": "Text Label", + "touchScaleEnable": false, + "vAlignment": 0 + } + }, + { + "classname": "TextField", + "name": null, + "children": [], + "options": { + "__type": "TextFieldSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "TextField", + "name": "TextField_37", + "ZOrder": 5, + "actiontag": 37, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSTextField", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 27, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "TextField_37", + "relativeToName": "ListView_14", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.28125, + "positionPercentY": 0.351796418, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.5625, + "sizePercentY": 0.18, + "sizeType": 0, + "tag": 52, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 90, + "x": 45, + "y": 117, + "areaHeight": 0, + "areaWidth": 0, + "fontFile": null, + "fontName": "微软雅黑", + "fontSize": 20, + "maxLength": 10, + "maxLengthEnable": false, + "passwordEnable": false, + "passwordStyleText": "*", + "placeHolder": "input words here", + "text": "Text Field" + } + }, + { + "classname": "ImageView", + "name": null, + "children": [], + "options": { + "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ImageView", + "name": "Image_38", + "ZOrder": 6, + "actiontag": 38, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSImageView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 80, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "Image_38", + "relativeToName": "ListView_14", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.25, + "positionPercentY": 0.191616774, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.5, + "sizePercentY": 0.533333361, + "sizeType": 0, + "tag": 53, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 80, + "x": 40, + "y": 64, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "fileName": null, + "fileNameData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/image.png", + "plistFile": "", + "resourceType": 1 + }, + "scale9Enable": false, + "scale9Height": 80, + "scale9Width": 80 + } + }, + { + "classname": "LoadingBar", + "name": null, + "children": [], + "options": { + "__type": "LoadingBarSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LoadingBar", + "name": "ProgressBar_39", + "ZOrder": 7, + "actiontag": 39, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLoadingBar", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 24, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "ProgressBar_39", + "relativeToName": "ListView_14", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 1.09375, + "positionPercentY": 0.0359281451, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 2.1875, + "sizePercentY": 0.16, + "sizeType": 0, + "tag": 54, + "touchAble": false, + "useMergedTexture": false, + "visible": true, + "width": 350, + "x": 175, + "y": 12, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "direction": 0, + "percent": 100, + "scale9Enable": false, + "texture": null, + "textureData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/loadingbar.png", + "plistFile": "", + "resourceType": 1 + } + } + } + ], + "options": { + "__type": "ListViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ListView", + "name": "ListView_14", + "ZOrder": 0, + "actiontag": 15, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSListView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 150, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.457291663, + "positionPercentY": 0.171875, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.166666672, + "sizePercentY": 0.234375, + "sizeType": 0, + "tag": 17, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 160, + "x": 439, + "y": 110, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 150, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 150, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "bounceEnable": true, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": true, + "colorType": 1, + "direction": 1, + "editorClipAble": true, + "gravity": 0, + "innerHeight": 0, + "innerWidth": 0, + "itemMargin": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "PageView", + "name": null, + "children": [ + { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_22", + "ZOrder": 0, + "actiontag": 22, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.735, + "positionPercentY": 0.845, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 25, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 147, + "y": 169, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_23", + "ZOrder": 0, + "actiontag": 23, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.38, + "positionPercentY": 0.165, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 26, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 76, + "y": 33, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_21", + "ZOrder": 0, + "actiontag": 21, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPanel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0, + "positionPercentY": 0, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 24, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 0, + "y": 0, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "ScrollView", + "name": null, + "children": [ + { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_28", + "ZOrder": 0, + "actiontag": 28, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 1.42, + "positionPercentY": 0.67, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 31, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 284, + "y": 134, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "LabelBMFont", + "name": null, + "children": [], + "options": { + "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelBMFont", + "name": "BitmapLabel_29", + "ZOrder": 0, + "actiontag": 29, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLabelBMFont", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 37, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.85, + "positionPercentY": 1.28, + "positionType": 0, + "rotation": 0, + "scaleX": 0.416413516, + "scaleY": 1, + "sizePercentX": 1.175, + "sizePercentY": 0.185, + "sizeType": 0, + "tag": 32, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 235, + "x": 170, + "y": 256, + "fileNameData": { + "path": "GUI/missing-font.fnt", + "plistFile": "", + "resourceType": 0 + }, + "text": "Text Label" + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_31", + "ZOrder": 0, + "actiontag": 31, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPanel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.1, + "positionPercentY": 0.175, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 40, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 40, + "y": 70, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + } + ], + "options": { + "__type": "ScrollViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ScrollView", + "name": "ScrollView_26", + "ZOrder": 0, + "actiontag": 26, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSScrollView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.005, + "positionPercentY": 0.5, + "positionType": 0, + "rotation": 0, + "scaleX": 0.491353333, + "scaleY": 0.491869867, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 29, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 1, + "y": 100, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 100, + "bgColorG": 150, + "bgColorOpacity": 100, + "bgColorR": 255, + "bgEndColorB": 100, + "bgEndColorG": 150, + "bgEndColorR": 255, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "bounceEnable": true, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": true, + "colorType": 1, + "direction": 3, + "editorClipAble": true, + "innerHeight": 400, + "innerWidth": 400, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_24", + "ZOrder": 0, + "actiontag": 24, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPanel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 1, + "positionPercentY": 0, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 27, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 200, + "y": 0, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "ListView", + "name": null, + "children": [ + { + "classname": "ImageView", + "name": null, + "children": [], + "options": { + "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ImageView", + "name": "Image_32", + "ZOrder": 0, + "actiontag": 32, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSImageView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 80, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "Image_32", + "relativeToName": "ListView_27", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.2, + "positionPercentY": 0.8, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.4, + "sizePercentY": 0.4, + "sizeType": 0, + "tag": 35, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 80, + "x": 40, + "y": 160, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "fileName": null, + "fileNameData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/image.png", + "plistFile": "", + "resourceType": 1 + }, + "scale9Enable": false, + "scale9Height": 80, + "scale9Width": 80 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_33", + "ZOrder": 1, + "actiontag": 33, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "CheckBox_33", + "relativeToName": "ListView_27", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.14, + "positionPercentY": 0.46, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.28, + "sizePercentY": 0.28, + "sizeType": 0, + "tag": 36, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 28, + "y": 92, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_34", + "ZOrder": 2, + "actiontag": 34, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "Button_34", + "relativeToName": "ListView_27", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.2575, + "positionPercentY": 0.22, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 37, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 51, + "y": 44, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio2/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + } + ], + "options": { + "__type": "ListViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ListView", + "name": "ListView_27", + "ZOrder": 0, + "actiontag": 27, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSListView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0, + "positionPercentY": 0.005, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 30, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 0, + "y": 1, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 150, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 150, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "bounceEnable": false, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": true, + "colorType": 1, + "direction": 1, + "editorClipAble": false, + "gravity": 0, + "innerHeight": 0, + "innerWidth": 0, + "itemMargin": 0, + "vectorX": 0, + "vectorY": -0.5 + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_25", + "ZOrder": 0, + "actiontag": 25, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPanel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 2, + "positionPercentY": 0, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 28, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 400, + "y": 0, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + } + ], + "options": { + "__type": "PageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "PageView", + "name": "PagetView_18", + "ZOrder": 0, + "actiontag": 19, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPageView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.222916663, + "positionPercentY": 0.490625, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.208333328, + "sizePercentY": 0.3125, + "sizeType": 0, + "tag": 21, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 214, + "y": 314, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 100, + "bgColorG": 150, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 100, + "bgEndColorG": 150, + "bgEndColorR": 255, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": true, + "colorType": 1, + "editorClipAble": false, + "vectorX": 0, + "vectorY": -0.5 + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_14", + "ZOrder": 0, + "actiontag": 14, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPanel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 640, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0, + "positionPercentY": 0, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 3, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 960, + "x": 0, + "y": 0, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 0, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + } } \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/Cocostudio1_40.plist b/samples/js-tests/res/cocosui/CCS/ccs1_4/Cocostudio1_40.plist similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/Cocostudio1_40.plist rename to samples/js-tests/res/cocosui/CCS/ccs1_4/Cocostudio1_40.plist diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/Cocostudio1_40.png b/samples/js-tests/res/cocosui/CCS/ccs1_4/Cocostudio1_40.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/Cocostudio1_40.png rename to samples/js-tests/res/cocosui/CCS/ccs1_4/Cocostudio1_40.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/GUI/labelatlasimg.png b/samples/js-tests/res/cocosui/CCS/ccs1_4/GUI/labelatlasimg.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/GUI/labelatlasimg.png rename to samples/js-tests/res/cocosui/CCS/ccs1_4/GUI/labelatlasimg.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/GUI/missing-font.fnt b/samples/js-tests/res/cocosui/CCS/ccs1_4/GUI/missing-font.fnt similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/GUI/missing-font.fnt rename to samples/js-tests/res/cocosui/CCS/ccs1_4/GUI/missing-font.fnt diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/GUI/missing-font.png b/samples/js-tests/res/cocosui/CCS/ccs1_4/GUI/missing-font.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/GUI/missing-font.png rename to samples/js-tests/res/cocosui/CCS/ccs1_4/GUI/missing-font.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/SmallSun.plist b/samples/js-tests/res/cocosui/CCS/ccs1_4/SmallSun.plist similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_4/SmallSun.plist rename to samples/js-tests/res/cocosui/CCS/ccs1_4/SmallSun.plist diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/Cocostudio1_5_1.ExportJson b/samples/js-tests/res/cocosui/CCS/ccs1_5/CCS1_5_1.ExportJson similarity index 97% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/Cocostudio1_5_1.ExportJson rename to samples/js-tests/res/cocosui/CCS/ccs1_5/CCS1_5_1.ExportJson index 8b0abf110f..825e597b3a 100644 --- a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/Cocostudio1_5_1.ExportJson +++ b/samples/js-tests/res/cocosui/CCS/ccs1_5/CCS1_5_1.ExportJson @@ -1,3013 +1,3013 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [ - "Cocostudio1_50.plist" - ], - "texturesPng": [ - "Cocostudio1_50.png" - ], - "version": "1.5.0.0", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1", - "ZOrder": 0, - "actiontag": 29220727, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPanel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 640, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1.00000012, - "scaleY": 1.00000012, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 4, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 960, - "x": 0, - "y": 0, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_2", - "ZOrder": 0, - "actiontag": 5103804, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.0875, - "positionPercentY": 0.934375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.107291669, - "sizePercentY": 0.0625, - "sizeType": 0, - "tag": 5, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 84, - "y": 598, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_3", - "ZOrder": 0, - "actiontag": 6094519, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.221875, - "positionPercentY": 0.940625, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.0583333336, - "sizePercentY": 0.0875, - "sizeType": 0, - "tag": 6, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 213, - "y": 602, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "Image_4", - "ZOrder": 0, - "actiontag": 22356031, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSImageView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.339583337, - "positionPercentY": 0.9125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.0833333358, - "sizePercentY": 0.125, - "sizeType": 0, - "tag": 7, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 80, - "x": 326, - "y": 584, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", - "plistFile": "", - "resourceType": 1 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "LabelAtlas", - "name": null, - "children": [], - "options": { - "__type": "LabelAtlasSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelAtlas", - "name": "AtlasLabel_5", - "ZOrder": 0, - "actiontag": 838835, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLabelAtlas", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 32, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.529166639, - "positionPercentY": 0.9234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.25, - "sizePercentY": 0.05, - "sizeType": 0, - "tag": 8, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 240, - "x": 508, - "y": 591, - "charMapFile": null, - "charMapFileData": { - "path": "GUI/labelatlasimg.png", - "plistFile": "", - "resourceType": 0 - }, - "itemHeight": 32, - "itemWidth": 24, - "startCharMap": "0", - "stringValue": "0123456789" - } - }, - { - "classname": "LabelBMFont", - "name": null, - "children": [], - "options": { - "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelBMFont", - "name": "BitmapLabel_6", - "ZOrder": 0, - "actiontag": 49926818, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLabelBMFont", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 37, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.826041639, - "positionPercentY": 0.934375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.244791672, - "sizePercentY": 0.0578125, - "sizeType": 0, - "tag": 9, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 235, - "x": 793, - "y": 598, - "fileNameData": { - "path": "GUI/missing-font.fnt", - "plistFile": "", - "resourceType": 0 - }, - "text": "Text Label" - } - }, - { - "classname": "LoadingBar", - "name": null, - "children": [], - "options": { - "__type": "LoadingBarSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LoadingBar", - "name": "ProgressBar_7", - "ZOrder": 0, - "actiontag": 65748243, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLoadingBar", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 24, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.197916672, - "positionPercentY": 0.7734375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.364583343, - "sizePercentY": 0.0375, - "sizeType": 0, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 350, - "x": 190, - "y": 495, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "direction": 0, - "percent": 100, - "scale9Enable": false, - "texture": null, - "textureData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/loadingbar.png", - "plistFile": "", - "resourceType": 1 - } - } - }, - { - "classname": "Slider", - "name": null, - "children": [], - "options": { - "__type": "SliderSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Slider", - "name": "Slider_8", - "ZOrder": 0, - "actiontag": 53309370, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSSlider", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 6, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.559375, - "positionPercentY": 0.7546875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.302083343, - "sizePercentY": 0.009375, - "sizeType": 0, - "tag": 11, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 290, - "x": 537, - "y": 483, - "ballDisabled": null, - "ballDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "ballNormal": null, - "ballNormalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/slider_bar_button.png", - "plistFile": "", - "resourceType": 1 - }, - "ballPressed": null, - "ballPressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "barCapInsetsHeight": 1, - "barCapInsetsWidth": 1, - "barCapInsetsX": 0, - "barCapInsetsY": 0, - "barFileName": null, - "barFileNameData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/slider_bar.png", - "plistFile": "", - "resourceType": 1 - }, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "length": 290, - "percent": 0, - "progressBarCapInsetsHeight": 0, - "progressBarCapInsetsWidth": 0, - "progressBarCapInsetsX": 0, - "progressBarCapInsetsY": 0, - "progressBarData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "progressBarVisible": false, - "scale9Enable": false, - "scale9Height": 0, - "scale9Width": 0, - "slidBallAnchorPointX": 0, - "slidBallAnchorPointY": 0 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "LabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_9", - "ZOrder": 0, - "actiontag": 21026539, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLabel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.794791639, - "positionPercentY": 0.7875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.0989583358, - "sizePercentY": 0.0421875, - "sizeType": 0, - "tag": 12, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 95, - "x": 763, - "y": 504, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "Text Label", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "TextField", - "name": null, - "children": [], - "options": { - "__type": "TextFieldSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "TextField", - "name": "TextField_10", - "ZOrder": 0, - "actiontag": 32912398, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSTextField", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.638541639, - "positionPercentY": 0.828125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.09375, - "sizePercentY": 0.0421875, - "sizeType": 0, - "tag": 13, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 90, - "x": 613, - "y": 530, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "maxLength": 10, - "maxLengthEnable": false, - "passwordEnable": false, - "passwordStyleText": "*", - "placeHolder": "input words here", - "text": "Text Field" - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_12", - "ZOrder": 0, - "actiontag": 28584556, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.2, - "positionPercentY": 0.765, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 15, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 40, - "y": 153, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_13", - "ZOrder": 0, - "actiontag": 1184233, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.63, - "positionPercentY": 0.8, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.28, - "sizePercentY": 0.28, - "sizeType": 0, - "tag": 16, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 126, - "y": 160, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_14", - "ZOrder": 0, - "actiontag": 50083945, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.235, - "positionPercentY": 0.485, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 17, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 47, - "y": 97, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "LabelBMFont", - "name": null, - "children": [], - "options": { - "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelBMFont", - "name": "BitmapLabel_15", - "ZOrder": 0, - "actiontag": 7752542, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLabelBMFont", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 37, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.48, - "positionPercentY": 0.22, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1.175, - "sizePercentY": 0.185, - "sizeType": 0, - "tag": 18, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 235, - "x": 96, - "y": 44, - "fileNameData": { - "path": "GUI/missing-font.fnt", - "plistFile": "", - "resourceType": 0 - }, - "text": "Text Label" - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_11", - "ZOrder": 0, - "actiontag": 61152371, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPanel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.0385416672, - "positionPercentY": 0.4140625, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.208333328, - "sizePercentY": 0.3125, - "sizeType": 0, - "tag": 14, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 37, - "y": 265, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "ScrollView", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_17", - "ZOrder": 0, - "actiontag": 50570518, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.4, - "positionPercentY": 0.78, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 80, - "y": 156, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_18", - "ZOrder": 0, - "actiontag": 48329116, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.68, - "positionPercentY": 0.505, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.28, - "sizePercentY": 0.28, - "sizeType": 0, - "tag": 21, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 136, - "y": 101, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "Image_19", - "ZOrder": 0, - "actiontag": 50658058, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSImageView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.98, - "positionPercentY": 0.195, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.4, - "sizePercentY": 0.4, - "sizeType": 0, - "tag": 22, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 80, - "x": 196, - "y": 39, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", - "plistFile": "", - "resourceType": 1 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ScrollViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ScrollView", - "name": "ScrollView_16", - "ZOrder": 0, - "actiontag": 26296511, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSScrollView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.367708325, - "positionPercentY": 0.4078125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.208333328, - "sizePercentY": 0.3125, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 353, - "y": 261, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 100, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 255, - "bgEndColorB": 100, - "bgEndColorG": 150, - "bgEndColorR": 255, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "bounceEnable": true, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "direction": 2, - "editorClipAble": true, - "innerHeight": 200, - "innerWidth": 200, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "ListView", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_21", - "ZOrder": 0, - "actiontag": 56884935, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Button_21", - "relativeToName": "ListView_20", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.2575, - "positionPercentY": 0.938461542, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 24, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 51, - "y": 305, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_22", - "ZOrder": 1, - "actiontag": 60306634, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "CheckBox_22", - "relativeToName": "ListView_20", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.14, - "positionPercentY": 0.7907692, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.28, - "sizePercentY": 0.28, - "sizeType": 0, - "tag": 25, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 28, - "y": 257, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "LabelAtlas", - "name": null, - "children": [], - "options": { - "__type": "LabelAtlasSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelAtlas", - "name": "AtlasLabel_23", - "ZOrder": 2, - "actiontag": 1324451, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLabelAtlas", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 32, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "AtlasLabel_23", - "relativeToName": "ListView_20", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.6, - "positionPercentY": 0.6553846, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1.2, - "sizePercentY": 0.16, - "sizeType": 0, - "tag": 26, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 240, - "x": 120, - "y": 213, - "charMapFile": null, - "charMapFileData": { - "path": "GUI/labelatlasimg.png", - "plistFile": "", - "resourceType": 0 - }, - "itemHeight": 32, - "itemWidth": 24, - "startCharMap": "0", - "stringValue": "0123456789" - } - }, - { - "classname": "LabelBMFont", - "name": null, - "children": [], - "options": { - "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelBMFont", - "name": "BitmapLabel_24", - "ZOrder": 3, - "actiontag": 55538129, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLabelBMFont", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 37, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "BitmapLabel_24", - "relativeToName": "ListView_20", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5875, - "positionPercentY": 0.549230754, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1.175, - "sizePercentY": 0.185, - "sizeType": 0, - "tag": 27, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 235, - "x": 117, - "y": 178, - "fileNameData": { - "path": "GUI/missing-font.fnt", - "plistFile": "", - "resourceType": 0 - }, - "text": "Text Label" - } - }, - { - "classname": "LoadingBar", - "name": null, - "children": [], - "options": { - "__type": "LoadingBarSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LoadingBar", - "name": "ProgressBar_25", - "ZOrder": 4, - "actiontag": 4207559, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLoadingBar", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 24, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "ProgressBar_25", - "relativeToName": "ListView_20", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.875, - "positionPercentY": 0.4553846, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1.75, - "sizePercentY": 0.12, - "sizeType": 0, - "tag": 28, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 350, - "x": 175, - "y": 148, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "direction": 0, - "percent": 100, - "scale9Enable": false, - "texture": null, - "textureData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/loadingbar.png", - "plistFile": "", - "resourceType": 1 - } - } - }, - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_27", - "ZOrder": 5, - "actiontag": 61203556, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Button_27", - "relativeToName": "ListView_20", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.2575, - "positionPercentY": 0.356923074, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 30, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 51, - "y": 116, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_28", - "ZOrder": 6, - "actiontag": 56221707, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "CheckBox_28", - "relativeToName": "ListView_20", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.14, - "positionPercentY": 0.209230766, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.28, - "sizePercentY": 0.28, - "sizeType": 0, - "tag": 31, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 28, - "y": 68, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_26", - "ZOrder": 7, - "actiontag": 28828846, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": -4, - "marginRight": 0, - "marginTop": -63, - "relativeName": "Button_26", - "relativeToName": "ListView_20", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.2575, - "positionPercentY": 0.06153846, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 29, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 51, - "y": 20, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - } - ], - "options": { - "__type": "ListViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ListView", - "name": "ListView_20", - "ZOrder": 0, - "actiontag": 11098806, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSListView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.6489583, - "positionPercentY": 0.403125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.208333328, - "sizePercentY": 0.3125, - "sizeType": 0, - "tag": 23, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 623, - "y": 258, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 150, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "bounceEnable": true, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "direction": 1, - "editorClipAble": true, - "gravity": 0, - "innerHeight": 0, - "innerWidth": 0, - "itemMargin": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "PageView", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_34", - "ZOrder": 0, - "actiontag": 47490115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.37, - "positionPercentY": 0.84, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 37, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 74, - "y": 168, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_35", - "ZOrder": 0, - "actiontag": 13823558, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.27, - "positionPercentY": 0.255, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.28, - "sizePercentY": 0.28, - "sizeType": 0, - "tag": 38, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 54, - "y": 51, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "LabelBMFont", - "name": null, - "children": [], - "options": { - "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelBMFont", - "name": "BitmapLabel_36", - "ZOrder": 0, - "actiontag": 1523636, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLabelBMFont", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 37, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.595, - "positionPercentY": 0.54, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.435, - "sizePercentY": 0.185, - "sizeType": 0, - "tag": 39, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 87, - "x": 119, - "y": 108, - "fileNameData": { - "path": "GUI/missing-font.fnt", - "plistFile": "", - "resourceType": 0 - }, - "text": "333" - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_30", - "ZOrder": 0, - "actiontag": 35728151, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPanel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 33, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 0, - "y": 0, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_37", - "ZOrder": 0, - "actiontag": 35816827, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.275, - "positionPercentY": 0.755, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 40, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 55, - "y": 151, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "ddsdfs", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "LabelAtlas", - "name": null, - "children": [], - "options": { - "__type": "LabelAtlasSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelAtlas", - "name": "AtlasLabel_38", - "ZOrder": 0, - "actiontag": 18495573, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSLabelAtlas", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 32, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.545, - "positionPercentY": 0.44, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.36, - "sizePercentY": 0.16, - "sizeType": 0, - "tag": 41, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 72, - "x": 109, - "y": 88, - "charMapFile": null, - "charMapFileData": { - "path": "GUI/labelatlasimg.png", - "plistFile": "", - "resourceType": 0 - }, - "itemHeight": 32, - "itemWidth": 24, - "startCharMap": "0", - "stringValue": "333" - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_31", - "ZOrder": 0, - "actiontag": 60749114, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPanel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 1, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 34, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 200, - "y": 0, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 145, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_39", - "ZOrder": 0, - "actiontag": 40055489, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.335, - "positionPercentY": 0.745, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 42, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 67, - "y": 149, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "Slider", - "name": null, - "children": [], - "options": { - "__type": "SliderSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Slider", - "name": "Slider_40", - "ZOrder": 0, - "actiontag": 63239313, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSSlider", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 6, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.365, - "positionPercentY": 0.435, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.5, - "sizePercentY": 0.03, - "sizeType": 0, - "tag": 43, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 100, - "x": 73, - "y": 87, - "ballDisabled": null, - "ballDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "ballNormal": null, - "ballNormalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/slider_bar_button.png", - "plistFile": "", - "resourceType": 1 - }, - "ballPressed": null, - "ballPressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "barCapInsetsHeight": 1, - "barCapInsetsWidth": 1, - "barCapInsetsX": 0, - "barCapInsetsY": 0, - "barFileName": null, - "barFileNameData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/slider_bar.png", - "plistFile": "", - "resourceType": 1 - }, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "length": 100, - "percent": 20, - "progressBarCapInsetsHeight": 0, - "progressBarCapInsetsWidth": 0, - "progressBarCapInsetsX": 0, - "progressBarCapInsetsY": 0, - "progressBarData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "progressBarVisible": false, - "scale9Enable": false, - "scale9Height": 0, - "scale9Width": 0, - "slidBallAnchorPointX": 0, - "slidBallAnchorPointY": 0 - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_32", - "ZOrder": 0, - "actiontag": 8094934, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPanel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 2, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 35, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 400, - "y": 0, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "Image_41", - "ZOrder": 0, - "actiontag": 60981561, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSImageView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.35, - "positionPercentY": 0.74, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.4, - "sizePercentY": 0.4, - "sizeType": 0, - "tag": 44, - "touchAble": false, - "useMergedTexture": true, - "visible": true, - "width": 80, - "x": 70, - "y": 148, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", - "plistFile": "", - "resourceType": 1 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_42", - "ZOrder": 0, - "actiontag": 44915380, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.215, - "positionPercentY": 0.165, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.28, - "sizePercentY": 0.28, - "sizeType": 0, - "tag": 45, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 56, - "x": 43, - "y": 33, - "backGroundBox": null, - "backGroundBoxData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", - "plistFile": "", - "resourceType": 1 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", - "plistFile": "", - "resourceType": 1 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_43", - "ZOrder": 0, - "actiontag": 30670809, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": "CocoStudio.EngineAdapterWrap.CSButton", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.695, - "positionPercentY": 0.46, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.515, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 46, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 103, - "x": 139, - "y": 92, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", - "plistFile": "", - "resourceType": 1 - }, - "pressed": null, - "pressedData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_33", - "ZOrder": 0, - "actiontag": 23077523, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPanel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 3, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 36, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 600, - "y": 0, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "PageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "PageView", - "name": "PageView_29", - "ZOrder": 0, - "actiontag": 49157890, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPageView", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 200, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.075, - "positionPercentY": 0.0515625, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.208333328, - "sizePercentY": 0.3125, - "sizeType": 0, - "tag": 32, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 200, - "x": 72, - "y": 33, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 100, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 100, - "bgEndColorG": 150, - "bgEndColorR": 255, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "editorClipAble": false, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_14", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": "CocoStudio.EngineAdapterWrap.CSPanel", - "colorB": 255, - "colorG": 255, - "colorR": 255, - "customProperty": "", - "flipX": false, - "flipY": false, - "height": 640, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 3, - "touchAble": true, - "useMergedTexture": true, - "visible": true, - "width": 960, - "x": 0, - "y": 0, - "adaptScreen": false, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 1, - "capInsetsWidth": 1, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } +{ + "classname": null, + "name": null, + "animation": { + "classname": null, + "name": "AnimationManager", + "actionlist": [] + }, + "dataScale": 1, + "designHeight": 320, + "designWidth": 480, + "textures": [ + "Cocostudio1_50.plist" + ], + "texturesPng": [ + "Cocostudio1_50.png" + ], + "version": "1.5.0.0", + "widgetTree": { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "Panel", + "name": null, + "children": [ + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_1", + "ZOrder": 0, + "actiontag": 29220727, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPanel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 640, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0, + "positionPercentY": 0, + "positionType": 0, + "rotation": 0, + "scaleX": 1.00000012, + "scaleY": 1.00000012, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 4, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 960, + "x": 0, + "y": 0, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_2", + "ZOrder": 0, + "actiontag": 5103804, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.0875, + "positionPercentY": 0.934375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.107291669, + "sizePercentY": 0.0625, + "sizeType": 0, + "tag": 5, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 84, + "y": 598, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_3", + "ZOrder": 0, + "actiontag": 6094519, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.221875, + "positionPercentY": 0.940625, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.0583333336, + "sizePercentY": 0.0875, + "sizeType": 0, + "tag": 6, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 213, + "y": 602, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "ImageView", + "name": null, + "children": [], + "options": { + "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ImageView", + "name": "Image_4", + "ZOrder": 0, + "actiontag": 22356031, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSImageView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 80, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.339583337, + "positionPercentY": 0.9125, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.0833333358, + "sizePercentY": 0.125, + "sizeType": 0, + "tag": 7, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 80, + "x": 326, + "y": 584, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "fileName": null, + "fileNameData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", + "plistFile": "", + "resourceType": 1 + }, + "scale9Enable": false, + "scale9Height": 80, + "scale9Width": 80 + } + }, + { + "classname": "LabelAtlas", + "name": null, + "children": [], + "options": { + "__type": "LabelAtlasSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelAtlas", + "name": "AtlasLabel_5", + "ZOrder": 0, + "actiontag": 838835, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLabelAtlas", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 32, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.529166639, + "positionPercentY": 0.9234375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.25, + "sizePercentY": 0.05, + "sizeType": 0, + "tag": 8, + "touchAble": false, + "useMergedTexture": false, + "visible": true, + "width": 240, + "x": 508, + "y": 591, + "charMapFile": null, + "charMapFileData": { + "path": "GUI/labelatlasimg.png", + "plistFile": "", + "resourceType": 0 + }, + "itemHeight": 32, + "itemWidth": 24, + "startCharMap": "0", + "stringValue": "0123456789" + } + }, + { + "classname": "LabelBMFont", + "name": null, + "children": [], + "options": { + "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelBMFont", + "name": "BitmapLabel_6", + "ZOrder": 0, + "actiontag": 49926818, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLabelBMFont", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 37, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.826041639, + "positionPercentY": 0.934375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.244791672, + "sizePercentY": 0.0578125, + "sizeType": 0, + "tag": 9, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 235, + "x": 793, + "y": 598, + "fileNameData": { + "path": "GUI/missing-font.fnt", + "plistFile": "", + "resourceType": 0 + }, + "text": "Text Label" + } + }, + { + "classname": "LoadingBar", + "name": null, + "children": [], + "options": { + "__type": "LoadingBarSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LoadingBar", + "name": "ProgressBar_7", + "ZOrder": 0, + "actiontag": 65748243, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLoadingBar", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 24, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.197916672, + "positionPercentY": 0.7734375, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.364583343, + "sizePercentY": 0.0375, + "sizeType": 0, + "tag": 10, + "touchAble": false, + "useMergedTexture": false, + "visible": true, + "width": 350, + "x": 190, + "y": 495, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "direction": 0, + "percent": 100, + "scale9Enable": false, + "texture": null, + "textureData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/loadingbar.png", + "plistFile": "", + "resourceType": 1 + } + } + }, + { + "classname": "Slider", + "name": null, + "children": [], + "options": { + "__type": "SliderSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Slider", + "name": "Slider_8", + "ZOrder": 0, + "actiontag": 53309370, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSSlider", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 6, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.559375, + "positionPercentY": 0.7546875, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.302083343, + "sizePercentY": 0.009375, + "sizeType": 0, + "tag": 11, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 290, + "x": 537, + "y": 483, + "ballDisabled": null, + "ballDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "ballNormal": null, + "ballNormalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/slider_bar_button.png", + "plistFile": "", + "resourceType": 1 + }, + "ballPressed": null, + "ballPressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "barCapInsetsHeight": 1, + "barCapInsetsWidth": 1, + "barCapInsetsX": 0, + "barCapInsetsY": 0, + "barFileName": null, + "barFileNameData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/slider_bar.png", + "plistFile": "", + "resourceType": 1 + }, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "length": 290, + "percent": 0, + "progressBarCapInsetsHeight": 0, + "progressBarCapInsetsWidth": 0, + "progressBarCapInsetsX": 0, + "progressBarCapInsetsY": 0, + "progressBarData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "progressBarVisible": false, + "scale9Enable": false, + "scale9Height": 0, + "scale9Width": 0, + "slidBallAnchorPointX": 0, + "slidBallAnchorPointY": 0 + } + }, + { + "classname": "Label", + "name": null, + "children": [], + "options": { + "__type": "LabelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Label", + "name": "Label_9", + "ZOrder": 0, + "actiontag": 21026539, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLabel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 27, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.794791639, + "positionPercentY": 0.7875, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.0989583358, + "sizePercentY": 0.0421875, + "sizeType": 0, + "tag": 12, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 95, + "x": 763, + "y": 504, + "areaHeight": 0, + "areaWidth": 0, + "fontFile": null, + "fontName": "微软雅黑", + "fontSize": 20, + "hAlignment": 0, + "text": "Text Label", + "touchScaleEnable": false, + "vAlignment": 0 + } + }, + { + "classname": "TextField", + "name": null, + "children": [], + "options": { + "__type": "TextFieldSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "TextField", + "name": "TextField_10", + "ZOrder": 0, + "actiontag": 32912398, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSTextField", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 27, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.638541639, + "positionPercentY": 0.828125, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.09375, + "sizePercentY": 0.0421875, + "sizeType": 0, + "tag": 13, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 90, + "x": 613, + "y": 530, + "areaHeight": 0, + "areaWidth": 0, + "fontFile": null, + "fontName": "微软雅黑", + "fontSize": 20, + "maxLength": 10, + "maxLengthEnable": false, + "passwordEnable": false, + "passwordStyleText": "*", + "placeHolder": "input words here", + "text": "Text Field" + } + }, + { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_12", + "ZOrder": 0, + "actiontag": 28584556, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.2, + "positionPercentY": 0.765, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 15, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 40, + "y": 153, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_13", + "ZOrder": 0, + "actiontag": 1184233, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.63, + "positionPercentY": 0.8, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.28, + "sizePercentY": 0.28, + "sizeType": 0, + "tag": 16, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 126, + "y": 160, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_14", + "ZOrder": 0, + "actiontag": 50083945, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.235, + "positionPercentY": 0.485, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 17, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 47, + "y": 97, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "LabelBMFont", + "name": null, + "children": [], + "options": { + "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelBMFont", + "name": "BitmapLabel_15", + "ZOrder": 0, + "actiontag": 7752542, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLabelBMFont", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 37, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.48, + "positionPercentY": 0.22, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1.175, + "sizePercentY": 0.185, + "sizeType": 0, + "tag": 18, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 235, + "x": 96, + "y": 44, + "fileNameData": { + "path": "GUI/missing-font.fnt", + "plistFile": "", + "resourceType": 0 + }, + "text": "Text Label" + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_11", + "ZOrder": 0, + "actiontag": 61152371, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPanel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.0385416672, + "positionPercentY": 0.4140625, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.208333328, + "sizePercentY": 0.3125, + "sizeType": 0, + "tag": 14, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 37, + "y": 265, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "ScrollView", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_17", + "ZOrder": 0, + "actiontag": 50570518, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.4, + "positionPercentY": 0.78, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 20, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 80, + "y": 156, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_18", + "ZOrder": 0, + "actiontag": 48329116, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.68, + "positionPercentY": 0.505, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.28, + "sizePercentY": 0.28, + "sizeType": 0, + "tag": 21, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 136, + "y": 101, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "ImageView", + "name": null, + "children": [], + "options": { + "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ImageView", + "name": "Image_19", + "ZOrder": 0, + "actiontag": 50658058, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSImageView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 80, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.98, + "positionPercentY": 0.195, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.4, + "sizePercentY": 0.4, + "sizeType": 0, + "tag": 22, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 80, + "x": 196, + "y": 39, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "fileName": null, + "fileNameData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", + "plistFile": "", + "resourceType": 1 + }, + "scale9Enable": false, + "scale9Height": 80, + "scale9Width": 80 + } + } + ], + "options": { + "__type": "ScrollViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ScrollView", + "name": "ScrollView_16", + "ZOrder": 0, + "actiontag": 26296511, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSScrollView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.367708325, + "positionPercentY": 0.4078125, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.208333328, + "sizePercentY": 0.3125, + "sizeType": 0, + "tag": 19, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 353, + "y": 261, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 100, + "bgColorG": 150, + "bgColorOpacity": 100, + "bgColorR": 255, + "bgEndColorB": 100, + "bgEndColorG": 150, + "bgEndColorR": 255, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "bounceEnable": true, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": true, + "colorType": 1, + "direction": 2, + "editorClipAble": true, + "innerHeight": 200, + "innerWidth": 200, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "ListView", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_21", + "ZOrder": 0, + "actiontag": 56884935, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "Button_21", + "relativeToName": "ListView_20", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.2575, + "positionPercentY": 0.938461542, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 24, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 51, + "y": 305, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_22", + "ZOrder": 1, + "actiontag": 60306634, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "CheckBox_22", + "relativeToName": "ListView_20", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.14, + "positionPercentY": 0.7907692, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.28, + "sizePercentY": 0.28, + "sizeType": 0, + "tag": 25, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 28, + "y": 257, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "LabelAtlas", + "name": null, + "children": [], + "options": { + "__type": "LabelAtlasSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelAtlas", + "name": "AtlasLabel_23", + "ZOrder": 2, + "actiontag": 1324451, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLabelAtlas", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 32, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "AtlasLabel_23", + "relativeToName": "ListView_20", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.6, + "positionPercentY": 0.6553846, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1.2, + "sizePercentY": 0.16, + "sizeType": 0, + "tag": 26, + "touchAble": false, + "useMergedTexture": false, + "visible": true, + "width": 240, + "x": 120, + "y": 213, + "charMapFile": null, + "charMapFileData": { + "path": "GUI/labelatlasimg.png", + "plistFile": "", + "resourceType": 0 + }, + "itemHeight": 32, + "itemWidth": 24, + "startCharMap": "0", + "stringValue": "0123456789" + } + }, + { + "classname": "LabelBMFont", + "name": null, + "children": [], + "options": { + "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelBMFont", + "name": "BitmapLabel_24", + "ZOrder": 3, + "actiontag": 55538129, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLabelBMFont", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 37, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "BitmapLabel_24", + "relativeToName": "ListView_20", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.5875, + "positionPercentY": 0.549230754, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1.175, + "sizePercentY": 0.185, + "sizeType": 0, + "tag": 27, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 235, + "x": 117, + "y": 178, + "fileNameData": { + "path": "GUI/missing-font.fnt", + "plistFile": "", + "resourceType": 0 + }, + "text": "Text Label" + } + }, + { + "classname": "LoadingBar", + "name": null, + "children": [], + "options": { + "__type": "LoadingBarSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LoadingBar", + "name": "ProgressBar_25", + "ZOrder": 4, + "actiontag": 4207559, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLoadingBar", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 24, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "ProgressBar_25", + "relativeToName": "ListView_20", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.875, + "positionPercentY": 0.4553846, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1.75, + "sizePercentY": 0.12, + "sizeType": 0, + "tag": 28, + "touchAble": false, + "useMergedTexture": false, + "visible": true, + "width": 350, + "x": 175, + "y": 148, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "direction": 0, + "percent": 100, + "scale9Enable": false, + "texture": null, + "textureData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/loadingbar.png", + "plistFile": "", + "resourceType": 1 + } + } + }, + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_27", + "ZOrder": 5, + "actiontag": 61203556, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "Button_27", + "relativeToName": "ListView_20", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.2575, + "positionPercentY": 0.356923074, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 30, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 51, + "y": 116, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_28", + "ZOrder": 6, + "actiontag": 56221707, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": 0, + "marginRight": 0, + "marginTop": 0, + "relativeName": "CheckBox_28", + "relativeToName": "ListView_20", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.14, + "positionPercentY": 0.209230766, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.28, + "sizePercentY": 0.28, + "sizeType": 0, + "tag": 31, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 28, + "y": 68, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_26", + "ZOrder": 7, + "actiontag": 28828846, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": { + "classname": null, + "name": null, + "align": 0, + "gravity": 2, + "layoutEageType": 0, + "layoutNormalHorizontal": 0, + "layoutNormalVertical": 0, + "layoutParentHorizontal": 0, + "layoutParentVertical": 0, + "marginDown": 0, + "marginLeft": -4, + "marginRight": 0, + "marginTop": -63, + "relativeName": "Button_26", + "relativeToName": "ListView_20", + "type": 1 + }, + "opacity": 255, + "positionPercentX": 0.2575, + "positionPercentY": 0.06153846, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 29, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 51, + "y": 20, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + } + ], + "options": { + "__type": "ListViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ListView", + "name": "ListView_20", + "ZOrder": 0, + "actiontag": 11098806, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSListView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.6489583, + "positionPercentY": 0.403125, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.208333328, + "sizePercentY": 0.3125, + "sizeType": 0, + "tag": 23, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 623, + "y": 258, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 150, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 150, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "bounceEnable": true, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": true, + "colorType": 1, + "direction": 1, + "editorClipAble": true, + "gravity": 0, + "innerHeight": 0, + "innerWidth": 0, + "itemMargin": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "PageView", + "name": null, + "children": [ + { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_34", + "ZOrder": 0, + "actiontag": 47490115, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.37, + "positionPercentY": 0.84, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 37, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 74, + "y": 168, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_35", + "ZOrder": 0, + "actiontag": 13823558, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.27, + "positionPercentY": 0.255, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.28, + "sizePercentY": 0.28, + "sizeType": 0, + "tag": 38, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 54, + "y": 51, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "LabelBMFont", + "name": null, + "children": [], + "options": { + "__type": "LabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelBMFont", + "name": "BitmapLabel_36", + "ZOrder": 0, + "actiontag": 1523636, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLabelBMFont", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 37, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.595, + "positionPercentY": 0.54, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.435, + "sizePercentY": 0.185, + "sizeType": 0, + "tag": 39, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 87, + "x": 119, + "y": 108, + "fileNameData": { + "path": "GUI/missing-font.fnt", + "plistFile": "", + "resourceType": 0 + }, + "text": "333" + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_30", + "ZOrder": 0, + "actiontag": 35728151, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPanel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0, + "positionPercentY": 0, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 33, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 0, + "y": 0, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_37", + "ZOrder": 0, + "actiontag": 35816827, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.275, + "positionPercentY": 0.755, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 40, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 55, + "y": 151, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "ddsdfs", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "LabelAtlas", + "name": null, + "children": [], + "options": { + "__type": "LabelAtlasSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "LabelAtlas", + "name": "AtlasLabel_38", + "ZOrder": 0, + "actiontag": 18495573, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSLabelAtlas", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 32, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.545, + "positionPercentY": 0.44, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.36, + "sizePercentY": 0.16, + "sizeType": 0, + "tag": 41, + "touchAble": false, + "useMergedTexture": false, + "visible": true, + "width": 72, + "x": 109, + "y": 88, + "charMapFile": null, + "charMapFileData": { + "path": "GUI/labelatlasimg.png", + "plistFile": "", + "resourceType": 0 + }, + "itemHeight": 32, + "itemWidth": 24, + "startCharMap": "0", + "stringValue": "333" + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_31", + "ZOrder": 0, + "actiontag": 60749114, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPanel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 1, + "positionPercentY": 0, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 34, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 200, + "y": 0, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 145, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_39", + "ZOrder": 0, + "actiontag": 40055489, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.335, + "positionPercentY": 0.745, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 42, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 67, + "y": 149, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + }, + { + "classname": "Slider", + "name": null, + "children": [], + "options": { + "__type": "SliderSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Slider", + "name": "Slider_40", + "ZOrder": 0, + "actiontag": 63239313, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSSlider", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 6, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.365, + "positionPercentY": 0.435, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.5, + "sizePercentY": 0.03, + "sizeType": 0, + "tag": 43, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 100, + "x": 73, + "y": 87, + "ballDisabled": null, + "ballDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "ballNormal": null, + "ballNormalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/slider_bar_button.png", + "plistFile": "", + "resourceType": 1 + }, + "ballPressed": null, + "ballPressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "barCapInsetsHeight": 1, + "barCapInsetsWidth": 1, + "barCapInsetsX": 0, + "barCapInsetsY": 0, + "barFileName": null, + "barFileNameData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/slider_bar.png", + "plistFile": "", + "resourceType": 1 + }, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "length": 100, + "percent": 20, + "progressBarCapInsetsHeight": 0, + "progressBarCapInsetsWidth": 0, + "progressBarCapInsetsX": 0, + "progressBarCapInsetsY": 0, + "progressBarData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "progressBarVisible": false, + "scale9Enable": false, + "scale9Height": 0, + "scale9Width": 0, + "slidBallAnchorPointX": 0, + "slidBallAnchorPointY": 0 + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_32", + "ZOrder": 0, + "actiontag": 8094934, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPanel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 2, + "positionPercentY": 0, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 35, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 400, + "y": 0, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + }, + { + "classname": "Panel", + "name": null, + "children": [ + { + "classname": "ImageView", + "name": null, + "children": [], + "options": { + "__type": "ImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "ImageView", + "name": "Image_41", + "ZOrder": 0, + "actiontag": 60981561, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSImageView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 80, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.35, + "positionPercentY": 0.74, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.4, + "sizePercentY": 0.4, + "sizeType": 0, + "tag": 44, + "touchAble": false, + "useMergedTexture": true, + "visible": true, + "width": 80, + "x": 70, + "y": 148, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "fileName": null, + "fileNameData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/image.png", + "plistFile": "", + "resourceType": 1 + }, + "scale9Enable": false, + "scale9Height": 80, + "scale9Width": 80 + } + }, + { + "classname": "CheckBox", + "name": null, + "children": [], + "options": { + "__type": "CheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "CheckBox", + "name": "CheckBox_42", + "ZOrder": 0, + "actiontag": 44915380, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSCheckBox", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 56, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.215, + "positionPercentY": 0.165, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.28, + "sizePercentY": 0.28, + "sizeType": 0, + "tag": 45, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 56, + "x": 43, + "y": 33, + "backGroundBox": null, + "backGroundBoxData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected01.png", + "plistFile": "", + "resourceType": 1 + }, + "backGroundBoxDisabled": null, + "backGroundBoxDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "backGroundBoxSelected": null, + "backGroundBoxSelectedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "frontCross": null, + "frontCrossData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/selected02.png", + "plistFile": "", + "resourceType": 1 + }, + "frontCrossDisabled": null, + "frontCrossDisabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "selectedState": true + } + }, + { + "classname": "Button", + "name": null, + "children": [], + "options": { + "__type": "ButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Button", + "name": "Button_43", + "ZOrder": 0, + "actiontag": 30670809, + "anchorPointX": 0.5, + "anchorPointY": 0.5, + "classType": "CocoStudio.EngineAdapterWrap.CSButton", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 40, + "ignoreSize": true, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.695, + "positionPercentY": 0.46, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.515, + "sizePercentY": 0.2, + "sizeType": 0, + "tag": 46, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 103, + "x": 139, + "y": 92, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "disabled": null, + "disabledData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "fontName": "微软雅黑", + "fontSize": 14, + "fontType": 0, + "normal": null, + "normalData": { + "path": "C:/Program Files (x86)/CocoStudio/EditorDefaultRes/GUI/button.png", + "plistFile": "", + "resourceType": 1 + }, + "pressed": null, + "pressedData": { + "path": null, + "plistFile": null, + "resourceType": 0 + }, + "scale9Enable": false, + "scale9Height": 40, + "scale9Width": 103, + "text": "", + "textColorB": 255, + "textColorG": 255, + "textColorR": 255 + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_33", + "ZOrder": 0, + "actiontag": 23077523, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPanel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 3, + "positionPercentY": 0, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 36, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 600, + "y": 0, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + } + ], + "options": { + "__type": "PageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "PageView", + "name": "PageView_29", + "ZOrder": 0, + "actiontag": 49157890, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPageView", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 200, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0.075, + "positionPercentY": 0.0515625, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 0.208333328, + "sizePercentY": 0.3125, + "sizeType": 0, + "tag": 32, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 200, + "x": 72, + "y": 33, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 100, + "bgColorG": 150, + "bgColorOpacity": 100, + "bgColorR": 150, + "bgEndColorB": 100, + "bgEndColorG": 150, + "bgEndColorR": 255, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": true, + "colorType": 1, + "editorClipAble": false, + "vectorX": 0, + "vectorY": -0.5 + } + } + ], + "options": { + "__type": "PanelSurrogate:#EditorCommon.JsonModel.Component.GUI", + "classname": "Panel", + "name": "Panel_14", + "ZOrder": 0, + "actiontag": -1, + "anchorPointX": 0, + "anchorPointY": 0, + "classType": "CocoStudio.EngineAdapterWrap.CSPanel", + "colorB": 255, + "colorG": 255, + "colorR": 255, + "customProperty": "", + "flipX": false, + "flipY": false, + "height": 640, + "ignoreSize": false, + "layoutParameter": null, + "opacity": 255, + "positionPercentX": 0, + "positionPercentY": 0, + "positionType": 0, + "rotation": 0, + "scaleX": 1, + "scaleY": 1, + "sizePercentX": 1, + "sizePercentY": 1, + "sizeType": 0, + "tag": 3, + "touchAble": true, + "useMergedTexture": true, + "visible": true, + "width": 960, + "x": 0, + "y": 0, + "adaptScreen": false, + "backGroundImage": null, + "backGroundImageData": null, + "backGroundScale9Enable": false, + "bgColorB": 255, + "bgColorG": 200, + "bgColorOpacity": 0, + "bgColorR": 150, + "bgEndColorB": 255, + "bgEndColorG": 200, + "bgEndColorR": 150, + "bgStartColorB": 255, + "bgStartColorG": 255, + "bgStartColorR": 255, + "capInsetsHeight": 1, + "capInsetsWidth": 1, + "capInsetsX": 0, + "capInsetsY": 0, + "clipAble": false, + "colorType": 1, + "layoutType": 0, + "vectorX": 0, + "vectorY": -0.5 + } + } } \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/Cocostudio1_50.plist b/samples/js-tests/res/cocosui/CCS/ccs1_5/Cocostudio1_50.plist similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/Cocostudio1_50.plist rename to samples/js-tests/res/cocosui/CCS/ccs1_5/Cocostudio1_50.plist diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/Cocostudio1_50.png b/samples/js-tests/res/cocosui/CCS/ccs1_5/Cocostudio1_50.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/Cocostudio1_50.png rename to samples/js-tests/res/cocosui/CCS/ccs1_5/Cocostudio1_50.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/GUI/labelatlasimg.png b/samples/js-tests/res/cocosui/CCS/ccs1_5/GUI/labelatlasimg.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/GUI/labelatlasimg.png rename to samples/js-tests/res/cocosui/CCS/ccs1_5/GUI/labelatlasimg.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/GUI/missing-font.fnt b/samples/js-tests/res/cocosui/CCS/ccs1_5/GUI/missing-font.fnt similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/GUI/missing-font.fnt rename to samples/js-tests/res/cocosui/CCS/ccs1_5/GUI/missing-font.fnt diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/GUI/missing-font.png b/samples/js-tests/res/cocosui/CCS/ccs1_5/GUI/missing-font.png similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/GUI/missing-font.png rename to samples/js-tests/res/cocosui/CCS/ccs1_5/GUI/missing-font.png diff --git a/samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/SmallSun.plist b/samples/js-tests/res/cocosui/CCS/ccs1_5/SmallSun.plist similarity index 100% rename from samples/js-tests/res/cocosui/UIEditorTest/cocostudio1_5/SmallSun.plist rename to samples/js-tests/res/cocosui/CCS/ccs1_5/SmallSun.plist diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/crossplatform_UIButton_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/crossplatform_UIButton_Editor_1.ExportJson deleted file mode 100644 index dca0129357..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/crossplatform_UIButton_Editor_1.ExportJson +++ /dev/null @@ -1,575 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 4, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_516", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 1, - "y": 35.0, - "visible": true, - "classType": "Panel", - "width": 111.0, - "height": 100.0, - "positionPercentY": 0.205882356, - "sizePercentX": 0.275434256, - "sizePercentY": 0.5882353, - "actionTag": 122, - "tag": 10, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 5, - "relativeName": "Panel_button", - "relativeToName": "background_Panel" - }, - "name": "Panel_button", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0 - }, - "text": "", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 54.0, - "y": 70.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.490991, - "positionPercentY": 0.7, - "sizePercentX": 0.9279279, - "sizePercentY": 0.4, - "actionTag": 123, - "tag": 11, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Button_123", - "relativeToName": "Panel_button", - "marginLeft": -1, - "marginTop": 10 - }, - "name": "Button_123", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "Button", - "x": 55.0, - "y": 26.0, - "visible": true, - "classType": "Label", - "width": 64.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.265, - "sizePercentX": 0.5765766, - "sizePercentY": 0.27, - "actionTag": 124, - "tag": 12, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Label_124", - "relativeToName": "Panel_button", - "marginTop": 10 - }, - "name": "Label_124", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 1, - "x": 133.0, - "y": 35.0, - "visible": true, - "classType": "Panel", - "width": 111.0, - "height": 100.0, - "positionPercentX": 0.3300248, - "positionPercentY": 0.205882356, - "sizePercentX": 0.275434256, - "sizePercentY": 0.5882353, - "actionTag": 125, - "tag": 13, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 5, - "relativeName": "Panel_titlebutton", - "relativeToName": "background_Panel", - "marginLeft": 22 - }, - "name": "Panel_titlebutton", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0 - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 55.0, - "y": 70.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.5, - "positionPercentY": 0.7, - "sizePercentX": 0.9279279, - "sizePercentY": 0.4, - "actionTag": 126, - "tag": 14, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Button_126", - "relativeToName": "Panel_titlebutton", - "marginTop": 10 - }, - "name": "Button_126", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "TitleButton", - "x": 54.0, - "y": 26.0, - "visible": true, - "classType": "Label", - "width": 103.0, - "height": 27.0, - "positionPercentX": 0.490991, - "positionPercentY": 0.265, - "sizePercentX": 0.9279279, - "sizePercentY": 0.27, - "actionTag": 127, - "tag": 15, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Label_127", - "relativeToName": "Panel_titlebutton", - "marginLeft": -1, - "marginTop": 10 - }, - "name": "Label_127", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 1, - "x": 266.0, - "y": 35.0, - "visible": true, - "classType": "Panel", - "width": 137.0, - "height": 100.0, - "positionPercentX": 0.6600496, - "positionPercentY": 0.205882356, - "sizePercentX": 0.339950383, - "sizePercentY": 0.5882353, - "actionTag": 128, - "tag": 16, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 5, - "relativeName": "Panel_scale9", - "relativeToName": "background_Panel", - "marginLeft": 22 - }, - "name": "Panel_scale9", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "buttonHighlighted.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0 - }, - "text": "", - "scale9Width": 103.0, - "scale9Height": 40.0, - "scale9Enable": true, - "x": 68.0, - "y": 70.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.5, - "positionPercentY": 0.7, - "sizePercentX": 0.7518248, - "sizePercentY": 0.4, - "actionTag": 129, - "tag": 17, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Button_129", - "relativeToName": "Panel_scale9", - "marginTop": 10 - }, - "name": "Button_129", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "Enable 9 Slice", - "x": 68.0, - "y": 26.0, - "visible": true, - "classType": "Label", - "width": 130.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.265, - "sizePercentX": 0.9489051, - "sizePercentY": 0.27, - "actionTag": 130, - "tag": 18, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Label_130", - "relativeToName": "Panel_scale9", - "marginTop": 10 - }, - "name": "Label_130", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/windows_UIButton_Editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/windows_UIButton_Editor_1.json deleted file mode 100644 index 50ae50c06e..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIButton_Editor/windows_UIButton_Editor_1.json +++ /dev/null @@ -1,1148 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_123", - "ZOrder": 0, - "actiontag": 123, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": -1, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Button_123", - "relativeToName": "Panel_button", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.490991, - "positionPercentY": 0.7, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.9279279, - "sizePercentY": 0.4, - "sizeType": 0, - "tag": 11, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 54, - "y": 70, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_124", - "ZOrder": 0, - "actiontag": 124, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 2, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Label_124", - "relativeToName": "Panel_button", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.265, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.8558559, - "sizePercentY": 0.27, - "sizeType": 0, - "tag": 12, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 55, - "y": 26, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "Button", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_button", - "ZOrder": 0, - "actiontag": 122, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 100, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.205882356, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.275434256, - "sizePercentY": 0.5882353, - "sizeType": 0, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 111, - "x": 0, - "y": 35, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_126", - "ZOrder": 0, - "actiontag": 126, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Button_126", - "relativeToName": "Panel_titlebutton", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.7, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.9279279, - "sizePercentY": 0.4, - "sizeType": 0, - "tag": 14, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 55, - "y": 70, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_127", - "ZOrder": 0, - "actiontag": 127, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": -1, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Label_127", - "relativeToName": "Panel_titlebutton", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.265, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.8558559, - "sizePercentY": 0.27, - "sizeType": 0, - "tag": 15, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 54, - "y": 26, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "TitleButton", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_titlebutton", - "ZOrder": 0, - "actiontag": 125, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 100, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 22, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_titlebutton", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.3300248, - "positionPercentY": 0.205882356, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.275434256, - "sizePercentY": 0.5882353, - "sizeType": 0, - "tag": 13, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 111, - "x": 133, - "y": 35, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_129", - "ZOrder": 0, - "actiontag": 129, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Button_129", - "relativeToName": "Panel_scale9", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.7, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.7518248, - "sizePercentY": 0.4, - "sizeType": 0, - "tag": 17, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 68, - "y": 70, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "buttonHighlighted.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": true, - "scale9Height": 40, - "scale9Width": 103, - "text": "", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_130", - "ZOrder": 0, - "actiontag": 130, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Label_130", - "relativeToName": "Panel_scale9", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.265, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.693430662, - "sizePercentY": 0.27, - "sizeType": 0, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 59, - "y": 26, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "Enable 9 Slice", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_scale9", - "ZOrder": 0, - "actiontag": 128, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 100, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 22, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_scale9", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.6600496, - "positionPercentY": 0.205882356, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.339950383, - "sizePercentY": 0.5882353, - "sizeType": 0, - "tag": 16, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 137, - "x": 266, - "y": 35, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_516", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 4, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/crossplatform_UICheckBox_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/crossplatform_UICheckBox_Editor_1.ExportJson deleted file mode 100644 index 93723af333..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/crossplatform_UICheckBox_Editor_1.ExportJson +++ /dev/null @@ -1,358 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 3, - "x": 146.0, - "y": 35.0, - "visible": true, - "classType": "Panel", - "width": 111.0, - "height": 100.0, - "positionPercentX": 0.362282872, - "positionPercentY": 0.205882356, - "sizePercentX": 0.275434256, - "sizePercentY": 0.5882353, - "actionTag": 122, - "tag": 10, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "align": 5 - }, - "name": "Panel_button", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 55.0, - "y": 72.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.5, - "positionPercentY": 0.72, - "sizePercentX": 0.5045045, - "sizePercentY": 0.56, - "actionTag": 540, - "tag": 23, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "CheckBox_540", - "relativeToName": "Panel_button", - "align": 2 - }, - "name": "CheckBox_540", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "Checkbox", - "x": 55.0, - "y": 13.0, - "visible": true, - "classType": "Label", - "width": 93.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.135, - "sizePercentX": 0.8378378, - "sizePercentY": 0.27, - "actionTag": 124, - "tag": 12, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "Label_124", - "relativeToName": "Panel_button", - "align": 8 - }, - "name": "Label_124", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/crossplatform_UICheckBox_Editor_1.csb b/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/crossplatform_UICheckBox_Editor_1.csb deleted file mode 100644 index f55a6e2d20..0000000000 Binary files a/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/crossplatform_UICheckBox_Editor_1.csb and /dev/null differ diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/windows_ui_checkbox_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/windows_ui_checkbox_editor_1.json deleted file mode 100644 index ac8cb0c78d..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UICheckBox_Editor/windows_ui_checkbox_editor_1.json +++ /dev/null @@ -1,677 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_540", - "ZOrder": 0, - "actiontag": 540, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "CheckBox_540", - "relativeToName": "Panel_button", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.72, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.5045045, - "sizePercentY": 0.56, - "sizeType": 0, - "tag": 23, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 55, - "y": 72, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_124", - "ZOrder": 0, - "actiontag": 124, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 8, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 2, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Label_124", - "relativeToName": "Panel_button", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.135, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.8558559, - "sizePercentY": 0.27, - "sizeType": 0, - "tag": 12, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 409, - "y": 393, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "Checkbox", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_button", - "ZOrder": 0, - "actiontag": 122, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 100, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.362282872, - "positionPercentY": 0.205882356, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.275434256, - "sizePercentY": 0.5882353, - "sizeType": 0, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 111, - "x": 0, - "y": 35, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/crossplatform_UIImageView_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/crossplatform_UIImageView_Editor_1.ExportJson deleted file mode 100644 index 5c390498bb..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/crossplatform_UIImageView_Editor_1.ExportJson +++ /dev/null @@ -1,410 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 201.0, - "visible": true, - "classType": "Panel", - "width": 201.0, - "height": 170.0, - "positionPercentX": 0.5, - "sizeType": 1, - "sizePercentX": 0.5, - "sizePercentY": 1.0, - "actionTag": 750, - "tag": 10, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel_button_0", - "relativeToName": "background_Panel", - "align": 6 - }, - "name": "Panel_button_0", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "buttonHighlighted.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "scale9Width": 100.0, - "scale9Height": 50.0, - "scale9Enable": true, - "x": 100.0, - "y": 100.0, - "visible": true, - "classType": "ImageView", - "width": 100.0, - "height": 50.0, - "positionPercentX": 0.496277928, - "positionPercentY": 0.5882353, - "sizePercentX": 0.496277928, - "sizePercentY": 0.294117659, - "actionTag": 752, - "tag": 14, - "ignoreSize": false, - "name": "ImageView_749_0", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "scale 9 ImageView", - "x": 100.0, - "y": 33.0, - "visible": true, - "classType": "Label", - "width": 176.0, - "height": 27.0, - "positionPercentX": 0.496277928, - "positionPercentY": 0.19411765, - "sizePercentX": 0.873449147, - "sizePercentY": 0.158823535, - "actionTag": 751, - "tag": 12, - "ignoreSize": true, - "name": "Label_124_0", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 201.0, - "height": 170.0, - "sizeType": 1, - "sizePercentX": 0.5, - "sizePercentY": 1.0, - "actionTag": 122, - "tag": 10, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "align": 4 - }, - "name": "Panel_button", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "ImageView", - "x": 100.0, - "y": 33.0, - "visible": true, - "classType": "Label", - "width": 106.0, - "height": 27.0, - "positionPercentX": 0.496277928, - "positionPercentY": 0.19411765, - "sizePercentX": 0.526054561, - "sizePercentY": 0.158823535, - "actionTag": 124, - "tag": 12, - "ignoreSize": true, - "name": "Label_124", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 100.0, - "y": 100.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.496277928, - "positionPercentY": 0.5882353, - "sizePercentX": 0.397022337, - "sizePercentY": 0.470588237, - "actionTag": 749, - "tag": 14, - "ignoreSize": true, - "name": "ImageView_749", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/crossplatform_UIImageView_Editor_1.csb b/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/crossplatform_UIImageView_Editor_1.csb deleted file mode 100644 index 2bd2a58883..0000000000 Binary files a/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/crossplatform_UIImageView_Editor_1.csb and /dev/null differ diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/windows_ui_ImageView_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/windows_ui_ImageView_editor_1.json deleted file mode 100644 index 3fea8a4645..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIImageView_Editor/windows_ui_ImageView_editor_1.json +++ /dev/null @@ -1,807 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_749_0", - "ZOrder": 0, - "actiontag": 752, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 50, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.5882353, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.496277928, - "sizePercentY": 0.294117659, - "sizeType": 0, - "tag": 14, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 100, - "x": 100, - "y": 100, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "buttonHighlighted.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": true, - "scale9Height": 50, - "scale9Width": 100 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_124_0", - "ZOrder": 0, - "actiontag": 751, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.197058827, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.471464, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 12, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 100, - "y": 33, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "scale 9 ImageView", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_button_0", - "ZOrder": 0, - "actiontag": 750, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 6, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_button_0", - "relativeToName": "background_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.5, - "sizePercentY": 1, - "sizeType": 1, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 201.5, - "x": 201, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_124", - "ZOrder": 0, - "actiontag": 124, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.197058827, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.471464, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 12, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 100, - "y": 33, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "ImageView", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_749", - "ZOrder": 0, - "actiontag": 749, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.5882353, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.397022337, - "sizePercentY": 0.470588237, - "sizeType": 0, - "tag": 14, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 100, - "y": 100, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_button", - "ZOrder": 0, - "actiontag": 122, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 4, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.5, - "sizePercentY": 1, - "sizeType": 1, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 201.5, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/crossplatform_UILabelAtlas_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/crossplatform_UILabelAtlas_Editor_1.ExportJson deleted file mode 100644 index 551c1bfd83..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/crossplatform_UILabelAtlas_Editor_1.ExportJson +++ /dev/null @@ -1,338 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 1, - "y": 42.0, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 85.0, - "positionPercentY": 0.25, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 0.5, - "actionTag": 122, - "tag": 10, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "align": 5 - }, - "name": "Panel_button", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelAtlasSurrogate, EditorCommon", - "stringValue": "1234567890", - "charMapFileData": { - "resourceType": 0, - "path": "GUI/labelatlasimg.png", - "plistFile": "" - }, - "startCharMap": "0", - "x": 201.0, - "y": 69.0, - "visible": true, - "classType": "LabelAtlas", - "width": 240.0, - "height": 32.0, - "positionPercentX": 0.5, - "positionPercentY": 0.8117647, - "sizePercentX": 0.5955335, - "sizePercentY": 0.3764706, - "actionTag": 961, - "tag": 28, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "LabelAtlas_961", - "relativeToName": "Panel_button" - }, - "name": "LabelAtlas_961", - "classname": "LabelAtlas" - }, - "children": [], - "classname": "LabelAtlas" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "labelatlas", - "x": 201.0, - "y": 29.0, - "visible": true, - "classType": "Label", - "width": 88.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.347058833, - "sizePercentX": 0.218362287, - "sizePercentY": 0.31764707, - "actionTag": 124, - "tag": 12, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Label_124", - "relativeToName": "Panel_button", - "marginTop": 10 - }, - "name": "Label_124", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/windows_ui_labelatlas_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/windows_ui_labelatlas_editor_1.json deleted file mode 100644 index a8f74f9105..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILabelAtlas_Editor/windows_ui_labelatlas_editor_1.json +++ /dev/null @@ -1,656 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "LabelAtlas", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelAtlasSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelAtlas", - "name": "LabelAtlas_961", - "ZOrder": 0, - "actiontag": 961, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 32, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "LabelAtlas_961", - "relativeToName": "Panel_button", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.8117647, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.5955335, - "sizePercentY": 0.3764706, - "sizeType": 0, - "tag": 28, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 240, - "x": 201, - "y": 69, - "charMapFile": null, - "charMapFileData": { - "path": "GUI/labelatlasimg.png", - "plistFile": null, - "resourceType": 0 - }, - "itemHeight": 32, - "itemWidth": 24, - "startCharMap": "0", - "stringValue": "1234567890" - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_124", - "ZOrder": 0, - "actiontag": 124, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Label_124", - "relativeToName": "Panel_button", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.347058833, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.235732, - "sizePercentY": 0.31764707, - "sizeType": 0, - "tag": 12, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 201, - "y": 29, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "labelatlas", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_button", - "ZOrder": 0, - "actiontag": 122, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 85, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.25, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.5, - "sizeType": 1, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 85, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/crossplatform_UILabelBMFont_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/crossplatform_UILabelBMFont_Editor_1.ExportJson deleted file mode 100644 index 62148849c8..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/crossplatform_UILabelBMFont_Editor_1.ExportJson +++ /dev/null @@ -1,337 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 1, - "y": 42.0, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 85.0, - "positionPercentY": 0.25, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 0.5, - "actionTag": 122, - "tag": 10, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "align": 5 - }, - "name": "Panel_button", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelBMFontSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/missing-font.fnt", - "plistFile": "" - }, - "text": "LabelBMFont", - "x": 201.0, - "y": 66.0, - "visible": true, - "classType": "LabelBMFont", - "width": 282.0, - "height": 37.0, - "positionPercentX": 0.5, - "positionPercentY": 0.7823529, - "sizePercentX": 0.699751854, - "sizePercentY": 0.435294122, - "actionTag": 977, - "tag": 14, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "LabelBMFont_977", - "relativeToName": "Panel_button" - }, - "name": "LabelBMFont_977", - "classname": "LabelBMFont" - }, - "children": [], - "classname": "LabelBMFont" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "labelbmfont", - "x": 201.0, - "y": 24.0, - "visible": true, - "classType": "Label", - "width": 116.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.2882353, - "sizePercentX": 0.2878412, - "sizePercentY": 0.31764707, - "actionTag": 124, - "tag": 12, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Label_124", - "relativeToName": "Panel_button", - "marginTop": 10 - }, - "name": "Label_124", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/windows_ui_labelbmfont_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/windows_ui_labelbmfont_editor_1.json deleted file mode 100644 index ed055390cc..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILabelBMFont_Editor/windows_ui_labelbmfont_editor_1.json +++ /dev/null @@ -1,652 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "LabelBMFont", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LabelBMFont", - "name": "LabelBMFont_977", - "ZOrder": 0, - "actiontag": 977, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 37, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "LabelBMFont_977", - "relativeToName": "Panel_button", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.7823529, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.583126545, - "sizePercentY": 0.435294122, - "sizeType": 0, - "tag": 14, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 282, - "x": 201, - "y": 66, - "fileNameData": { - "path": "GUI/missing-font.fnt", - "plistFile": null, - "resourceType": 0 - }, - "text": "LabelBMFont" - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_124", - "ZOrder": 0, - "actiontag": 124, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Label_124", - "relativeToName": "Panel_button", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.2882353, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.235732, - "sizePercentY": 0.31764707, - "sizeType": 0, - "tag": 12, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 201, - "y": 24, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "labelbmfont", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_button", - "ZOrder": 0, - "actiontag": 122, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 85, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.25, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.5, - "sizeType": 1, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 42, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/crossplatform_UILabel_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/crossplatform_UILabel_Editor_1.ExportJson deleted file mode 100644 index bf3da7c72f..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/crossplatform_UILabel_Editor_1.ExportJson +++ /dev/null @@ -1,426 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 1, - "visible": true, - "classType": "Panel", - "width": 201.0, - "height": 170.0, - "sizeType": 1, - "sizePercentX": 0.5, - "sizePercentY": 1.0, - "actionTag": 993, - "tag": 10, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel_button_0", - "relativeToName": "background_Panel", - "align": 4 - }, - "name": "Panel_button_0", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "A Damn Mess.ttf", - "text": "labelbmfont", - "x": 100.0, - "y": 109.0, - "visible": true, - "classType": "Label", - "width": 147.0, - "height": 22.0, - "positionPercentX": 0.5, - "positionPercentY": 0.641176462, - "sizePercentX": 0.729528546, - "sizePercentY": 0.129411772, - "actionTag": 994, - "tag": 12, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Label_124_0", - "relativeToName": "Panel_button_0", - "marginTop": 50 - }, - "name": "Label_124_0", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": ".ttf label", - "x": 100.0, - "y": 74.0, - "visible": true, - "classType": "Label", - "width": 77.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.438235283, - "sizePercentX": 0.382134, - "sizePercentY": 0.158823535, - "actionTag": 997, - "tag": 18, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Label_997", - "relativeToName": "Panel_button_0", - "marginTop": 10 - }, - "name": "Label_997", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 1, - "x": 201.0, - "visible": true, - "classType": "Panel", - "width": 201.0, - "height": 170.0, - "positionPercentX": 0.5, - "sizeType": 1, - "sizePercentX": 0.5, - "sizePercentY": 1.0, - "actionTag": 122, - "tag": 10, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "align": 6 - }, - "name": "Panel_button", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "label", - "x": 100.0, - "y": 106.0, - "visible": true, - "classType": "Label", - "width": 45.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.626470566, - "sizePercentX": 0.223325059, - "sizePercentY": 0.158823535, - "actionTag": 124, - "tag": 12, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Label_124", - "relativeToName": "Panel_button", - "marginTop": 50 - }, - "name": "Label_124", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "text label", - "x": 100.0, - "y": 69.0, - "visible": true, - "classType": "Label", - "width": 86.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.40882352, - "sizePercentX": 0.426799, - "sizePercentY": 0.158823535, - "actionTag": 998, - "tag": 19, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Label_998", - "relativeToName": "Panel_button", - "marginTop": 10 - }, - "name": "Label_998", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/windows_ui_label_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/windows_ui_label_editor_1.json deleted file mode 100644 index 4b7b8a9724..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILabel_Editor/windows_ui_label_editor_1.json +++ /dev/null @@ -1,867 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_124_0", - "ZOrder": 0, - "actiontag": 994, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 50, - "relativeName": "Label_124_0", - "relativeToName": "Panel_button_0", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.641176462, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.471464, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 12, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 71, - "y": 159, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "A Damn Mess.ttf", - "fontSize": 20, - "hAlignment": 0, - "text": "labelbmfont", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_997", - "ZOrder": 0, - "actiontag": 997, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Label_997", - "relativeToName": "Panel_button_0", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.438235283, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.471464, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 38, - "y": 84, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": ".ttf label", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_button_0", - "ZOrder": 0, - "actiontag": 993, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 4, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_button_0", - "relativeToName": "background_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.5, - "sizePercentY": 1, - "sizeType": 1, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 201.5, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_124", - "ZOrder": 0, - "actiontag": 124, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 50, - "relativeName": "Label_124", - "relativeToName": "Panel_button", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.626470566, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.471464, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 12, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 22, - "y": 156, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "label", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_998", - "ZOrder": 0, - "actiontag": 998, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Label_998", - "relativeToName": "Panel_button", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.40882352, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.471464, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 19, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 43, - "y": 79, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "text label", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_button", - "ZOrder": 0, - "actiontag": 122, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 6, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.5, - "sizePercentY": 1, - "sizeType": 1, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 201.5, - "x": 201, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/crossplatform_BackgroundImage.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/crossplatform_BackgroundImage.ExportJson deleted file mode 100644 index 1062d4a236..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/crossplatform_BackgroundImage.ExportJson +++ /dev/null @@ -1,404 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "Hello.png", - "plistFile": "" - }, - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgEndColorR": 85, - "bgEndColorG": 107, - "bgEndColorB": 47, - "colorType": 0, - "bgColorOpacity": 255, - "vectorY": -1.0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "y": -20.0, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "positionPercentY": -0.117647059, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.117647, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 333.0, - "y": 76.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.8263027, - "positionPercentY": 0.4, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 46.0, - "y": 102.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.114143923, - "positionPercentY": 0.5368421, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 159.0, - "y": 90.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.394540936, - "positionPercentY": 0.473684222, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/crossplatform_UILayout_BackgroundImage_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/crossplatform_UILayout_BackgroundImage_Editor_1.ExportJson deleted file mode 100644 index 1062d4a236..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/crossplatform_UILayout_BackgroundImage_Editor_1.ExportJson +++ /dev/null @@ -1,404 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "Hello.png", - "plistFile": "" - }, - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgEndColorR": 85, - "bgEndColorG": 107, - "bgEndColorB": 47, - "colorType": 0, - "bgColorOpacity": 255, - "vectorY": -1.0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "y": -20.0, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "positionPercentY": -0.117647059, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.117647, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 333.0, - "y": 76.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.8263027, - "positionPercentY": 0.4, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 46.0, - "y": 102.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.114143923, - "positionPercentY": 0.5368421, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 159.0, - "y": 90.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.394540936, - "positionPercentY": 0.473684222, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/windows_ui_backgroundimage.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/windows_ui_backgroundimage.json deleted file mode 100644 index e67e0cb4fd..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/windows_ui_backgroundimage.json +++ /dev/null @@ -1,723 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.8263027, - "positionPercentY": 0.4, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 333, - "y": 76, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.114143923, - "positionPercentY": 0.5368421, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 46, - "y": 102, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.394540936, - "positionPercentY": 0.473684222, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 159, - "y": 90, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": -0.117647059, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1.117647, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": -20, - "backGroundImage": null, - "backGroundImageData": { - "path": "Hello.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 47, - "bgEndColorG": 107, - "bgEndColorR": 85, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -1 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/windows_ui_layout_backgroundimage_editor_1_0_0.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/windows_ui_layout_backgroundimage_editor_1_0_0.json deleted file mode 100644 index e67e0cb4fd..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/windows_ui_layout_backgroundimage_editor_1_0_0.json +++ /dev/null @@ -1,723 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.8263027, - "positionPercentY": 0.4, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 333, - "y": 76, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.114143923, - "positionPercentY": 0.5368421, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 46, - "y": 102, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.394540936, - "positionPercentY": 0.473684222, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 159, - "y": 90, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": -0.117647059, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1.117647, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": -20, - "backGroundImage": null, - "backGroundImageData": { - "path": "Hello.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 47, - "bgEndColorG": 107, - "bgEndColorR": 85, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -1 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/crossplatform_Colo.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/crossplatform_Colo.ExportJson deleted file mode 100644 index 6e65b3bb24..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/crossplatform_Colo.ExportJson +++ /dev/null @@ -1,392 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgColorOpacity": 255, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 333.0, - "y": 76.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.8263027, - "positionPercentY": 0.447058827, - "sizePercentX": 0.255583137, - "sizePercentY": 0.235294119, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 46.0, - "y": 102.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.114143923, - "positionPercentY": 0.6, - "sizePercentX": 0.138957813, - "sizePercentY": 0.329411775, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 159.0, - "y": 90.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.394540936, - "positionPercentY": 0.5294118, - "sizePercentX": 0.198511168, - "sizePercentY": 0.470588237, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/crossplatform_UILayout_Color_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/crossplatform_UILayout_Color_Editor_1.ExportJson deleted file mode 100644 index 6e65b3bb24..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/crossplatform_UILayout_Color_Editor_1.ExportJson +++ /dev/null @@ -1,392 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgColorOpacity": 255, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 333.0, - "y": 76.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.8263027, - "positionPercentY": 0.447058827, - "sizePercentX": 0.255583137, - "sizePercentY": 0.235294119, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 46.0, - "y": 102.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.114143923, - "positionPercentY": 0.6, - "sizePercentX": 0.138957813, - "sizePercentY": 0.329411775, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 159.0, - "y": 90.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.394540936, - "positionPercentY": 0.5294118, - "sizePercentX": 0.198511168, - "sizePercentY": 0.470588237, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/windows_ui_color.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/windows_ui_color.json deleted file mode 100644 index 2277b09ff1..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/windows_ui_color.json +++ /dev/null @@ -1,719 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.8263027, - "positionPercentY": 0.447058827, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.235294119, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 333, - "y": 76, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.114143923, - "positionPercentY": 0.6, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.329411775, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 46, - "y": 102, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.394540936, - "positionPercentY": 0.5294118, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.470588237, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 159, - "y": 90, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/windows_ui_layout_color_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/windows_ui_layout_color_editor_1.json deleted file mode 100644 index 2277b09ff1..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/windows_ui_layout_color_editor_1.json +++ /dev/null @@ -1,719 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.8263027, - "positionPercentY": 0.447058827, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.235294119, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 333, - "y": 76, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.114143923, - "positionPercentY": 0.6, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.329411775, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 46, - "y": 102, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.394540936, - "positionPercentY": 0.5294118, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.470588237, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 159, - "y": 90, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/crossplatform_UILayout_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/crossplatform_UILayout_Editor_1.ExportJson deleted file mode 100644 index 78dc8271e0..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/crossplatform_UILayout_Editor_1.ExportJson +++ /dev/null @@ -1,389 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 333.0, - "y": 76.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.8263027, - "positionPercentY": 0.447058827, - "sizePercentX": 0.255583137, - "sizePercentY": 0.235294119, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 46.0, - "y": 102.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.114143923, - "positionPercentY": 0.6, - "sizePercentX": 0.138957813, - "sizePercentY": 0.329411775, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 159.0, - "y": 90.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.394540936, - "positionPercentY": 0.5294118, - "sizePercentX": 0.198511168, - "sizePercentY": 0.470588237, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/windows_ui_layout_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/windows_ui_layout_editor_1.json deleted file mode 100644 index a7c0b5cddc..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/windows_ui_layout_editor_1.json +++ /dev/null @@ -1,719 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.827543437, - "positionPercentY": 0.447058827, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.235294119, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 333, - "y": 76, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.114143923, - "positionPercentY": 0.6, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.329411775, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 46, - "y": 102, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.394540936, - "positionPercentY": 0.5294118, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.470588237, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 159, - "y": 90, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/crossplatform_Gradient_Color.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/crossplatform_Gradient_Color.ExportJson deleted file mode 100644 index b09e61bc83..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/crossplatform_Gradient_Color.ExportJson +++ /dev/null @@ -1,397 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgEndColorR": 85, - "bgEndColorG": 107, - "bgEndColorB": 47, - "colorType": 2, - "bgColorOpacity": 255, - "vectorY": -1.0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 333.0, - "y": 76.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.8263027, - "positionPercentY": 0.447058827, - "sizePercentX": 0.255583137, - "sizePercentY": 0.235294119, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 46.0, - "y": 102.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.114143923, - "positionPercentY": 0.6, - "sizePercentX": 0.138957813, - "sizePercentY": 0.329411775, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 159.0, - "y": 90.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.394540936, - "positionPercentY": 0.5294118, - "sizePercentX": 0.198511168, - "sizePercentY": 0.470588237, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/crossplatform_UILayout_Gradient_Color_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/crossplatform_UILayout_Gradient_Color_Editor_1.ExportJson deleted file mode 100644 index b09e61bc83..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/crossplatform_UILayout_Gradient_Color_Editor_1.ExportJson +++ /dev/null @@ -1,397 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgEndColorR": 85, - "bgEndColorG": 107, - "bgEndColorB": 47, - "colorType": 2, - "bgColorOpacity": 255, - "vectorY": -1.0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 333.0, - "y": 76.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.8263027, - "positionPercentY": 0.447058827, - "sizePercentX": 0.255583137, - "sizePercentY": 0.235294119, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 46.0, - "y": 102.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.114143923, - "positionPercentY": 0.6, - "sizePercentX": 0.138957813, - "sizePercentY": 0.329411775, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 159.0, - "y": 90.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.394540936, - "positionPercentY": 0.5294118, - "sizePercentX": 0.198511168, - "sizePercentY": 0.470588237, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/windows_ui_gradient_color.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/windows_ui_gradient_color.json deleted file mode 100644 index 71887dd76a..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/windows_ui_gradient_color.json +++ /dev/null @@ -1,719 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.8263027, - "positionPercentY": 0.447058827, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.235294119, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 333, - "y": 76, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.114143923, - "positionPercentY": 0.6, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.329411775, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 46, - "y": 102, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.394540936, - "positionPercentY": 0.5294118, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.470588237, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 159, - "y": 90, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 47, - "bgEndColorG": 107, - "bgEndColorR": 85, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 2, - "layoutType": 0, - "vectorX": 0, - "vectorY": -1 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/windows_ui_layout_gradient_color_editor_1_0.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/windows_ui_layout_gradient_color_editor_1_0.json deleted file mode 100644 index 71887dd76a..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/windows_ui_layout_gradient_color_editor_1_0.json +++ /dev/null @@ -1,719 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.8263027, - "positionPercentY": 0.447058827, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.235294119, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 333, - "y": 76, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.114143923, - "positionPercentY": 0.6, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.329411775, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 46, - "y": 102, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.394540936, - "positionPercentY": 0.5294118, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.470588237, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 159, - "y": 90, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 47, - "bgEndColorG": 107, - "bgEndColorR": 85, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 2, - "layoutType": 0, - "vectorX": 0, - "vectorY": -1 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/crossplatform_Linear_Horizontal_Layout.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/crossplatform_Linear_Horizontal_Layout.ExportJson deleted file mode 100644 index d4cb7cbe75..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/crossplatform_Linear_Horizontal_Layout.ExportJson +++ /dev/null @@ -1,417 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 65.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgEndColorR": 85, - "bgEndColorG": 107, - "bgEndColorB": 47, - "colorType": 0, - "bgColorOpacity": 255, - "vectorY": -1.0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 51.0, - "y": 95.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.127791569, - "positionPercentY": 0.5, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 5, - "relativeName": "Button_1138", - "relativeToName": "Panel_1137" - }, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 131.0, - "y": 95.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.325062037, - "positionPercentY": 0.5, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 5, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137" - }, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 199.0, - "y": 95.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.493796527, - "positionPercentY": 0.5, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 5, - "relativeName": "ImageView_1140", - "relativeToName": "Panel_1137" - }, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/crossplatform_UILayout_Linear_Horizontal_Layout_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/crossplatform_UILayout_Linear_Horizontal_Layout_Editor_1.ExportJson deleted file mode 100644 index d4cb7cbe75..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/crossplatform_UILayout_Linear_Horizontal_Layout_Editor_1.ExportJson +++ /dev/null @@ -1,417 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 65.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgEndColorR": 85, - "bgEndColorG": 107, - "bgEndColorB": 47, - "colorType": 0, - "bgColorOpacity": 255, - "vectorY": -1.0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 51.0, - "y": 95.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.127791569, - "positionPercentY": 0.5, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 5, - "relativeName": "Button_1138", - "relativeToName": "Panel_1137" - }, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 131.0, - "y": 95.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.325062037, - "positionPercentY": 0.5, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 5, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137" - }, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 199.0, - "y": 95.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.493796527, - "positionPercentY": 0.5, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 5, - "relativeName": "ImageView_1140", - "relativeToName": "Panel_1137" - }, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/windows_ui_layout_linear_horizontal_layout_editor.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/windows_ui_layout_linear_horizontal_layout_editor.json deleted file mode 100644 index 8535de1e64..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/windows_ui_layout_linear_horizontal_layout_editor.json +++ /dev/null @@ -1,770 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Button_1138", - "relativeToName": "Panel_1137", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.127791569, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 121, - "y": 95, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.325062037, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 131, - "y": 92, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "ImageView_1140", - "relativeToName": "Panel_1137", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.493796527, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 410, - "y": 416, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": true, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 47, - "bgEndColorG": 107, - "bgEndColorR": 85, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -1 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/windows_ui_linear_horizontal_layout.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/windows_ui_linear_horizontal_layout.json deleted file mode 100644 index 8535de1e64..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/windows_ui_linear_horizontal_layout.json +++ /dev/null @@ -1,770 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Button_1138", - "relativeToName": "Panel_1137", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.127791569, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 121, - "y": 95, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.325062037, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 131, - "y": 92, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "ImageView_1140", - "relativeToName": "Panel_1137", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.493796527, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 410, - "y": 416, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": true, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 47, - "bgEndColorG": 107, - "bgEndColorR": 85, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -1 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/crossplatform_Linear_Vertical_Layout.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/crossplatform_Linear_Vertical_Layout.ExportJson deleted file mode 100644 index e43e858e43..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/crossplatform_Linear_Vertical_Layout.ExportJson +++ /dev/null @@ -1,420 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 65.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgEndColorR": 85, - "bgEndColorG": 107, - "bgEndColorB": 47, - "colorType": 0, - "bgColorOpacity": 255, - "vectorY": -1.0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 1, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 201.0, - "y": 165.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.5, - "positionPercentY": 0.8684211, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Button_1138", - "relativeToName": "Panel_1137", - "marginTop": 5 - }, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 201.0, - "y": 114.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.5, - "positionPercentY": 0.6, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137", - "marginTop": 3 - }, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 201.0, - "y": 43.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.5, - "positionPercentY": 0.2263158, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "ImageView_1140", - "relativeToName": "Panel_1137", - "marginTop": 3 - }, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/crossplatform_UILayout_Linear_Vertical_Layout_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/crossplatform_UILayout_Linear_Vertical_Layout_Editor_1.ExportJson deleted file mode 100644 index e43e858e43..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/crossplatform_UILayout_Linear_Vertical_Layout_Editor_1.ExportJson +++ /dev/null @@ -1,420 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 65.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgEndColorR": 85, - "bgEndColorG": 107, - "bgEndColorB": 47, - "colorType": 0, - "bgColorOpacity": 255, - "vectorY": -1.0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 1, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 201.0, - "y": 165.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.5, - "positionPercentY": 0.8684211, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Button_1138", - "relativeToName": "Panel_1137", - "marginTop": 5 - }, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 201.0, - "y": 114.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.5, - "positionPercentY": 0.6, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137", - "marginTop": 3 - }, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 201.0, - "y": 43.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.5, - "positionPercentY": 0.2263158, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "ImageView_1140", - "relativeToName": "Panel_1137", - "marginTop": 3 - }, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/windows_ui_layout_linear_vertical_layout_editor.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/windows_ui_layout_linear_vertical_layout_editor.json deleted file mode 100644 index 07da4fbc17..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/windows_ui_layout_linear_vertical_layout_editor.json +++ /dev/null @@ -1,770 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 5, - "relativeName": "Button_1138", - "relativeToName": "Panel_1137", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.8684211, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 201, - "y": 160, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 3, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.6, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 201, - "y": 112, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 3, - "relativeName": "ImageView_1140", - "relativeToName": "Panel_1137", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.2263158, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 436, - "y": 374, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": true, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 47, - "bgEndColorG": 107, - "bgEndColorR": 85, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -1 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/windows_ui_linear_vertical_layout.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/windows_ui_linear_vertical_layout.json deleted file mode 100644 index 07da4fbc17..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/windows_ui_linear_vertical_layout.json +++ /dev/null @@ -1,770 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 5, - "relativeName": "Button_1138", - "relativeToName": "Panel_1137", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.8684211, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 201, - "y": 160, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 3, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.6, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 201, - "y": 112, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 3, - "relativeName": "ImageView_1140", - "relativeToName": "Panel_1137", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.2263158, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 436, - "y": 374, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": true, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 47, - "bgEndColorG": 107, - "bgEndColorR": 85, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -1 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/crossplatform_Relative_Align_Location.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/crossplatform_Relative_Align_Location.ExportJson deleted file mode 100644 index cbf35cfe0a..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/crossplatform_Relative_Align_Location.ExportJson +++ /dev/null @@ -1,417 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 65.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgEndColorR": 85, - "bgEndColorG": 107, - "bgEndColorB": 47, - "colorType": 0, - "bgColorOpacity": 255, - "vectorY": -1.0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 281.0, - "y": 95.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.697270453, - "positionPercentY": 0.5, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "Button_1138", - "relativeToName": "CheckBox_1139", - "align": 17 - }, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 201.0, - "y": 95.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137", - "align": 5 - }, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 133.0, - "y": 95.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.3312655, - "positionPercentY": 0.5, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "ImageView_1140", - "relativeToName": "CheckBox_1139", - "align": 14 - }, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/crossplatform_UILayout_Relative_Align_Location_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/crossplatform_UILayout_Relative_Align_Location_Editor_1.ExportJson deleted file mode 100644 index cbf35cfe0a..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/crossplatform_UILayout_Relative_Align_Location_Editor_1.ExportJson +++ /dev/null @@ -1,417 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 65.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgEndColorR": 85, - "bgEndColorG": 107, - "bgEndColorB": 47, - "colorType": 0, - "bgColorOpacity": 255, - "vectorY": -1.0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 281.0, - "y": 95.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.697270453, - "positionPercentY": 0.5, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "Button_1138", - "relativeToName": "CheckBox_1139", - "align": 17 - }, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 201.0, - "y": 95.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137", - "align": 5 - }, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 133.0, - "y": 95.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.3312655, - "positionPercentY": 0.5, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "ImageView_1140", - "relativeToName": "CheckBox_1139", - "align": 14 - }, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/windows_ui_layout_relative_align_location_editor.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/windows_ui_layout_relative_align_location_editor.json deleted file mode 100644 index 87515fc40b..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/windows_ui_layout_relative_align_location_editor.json +++ /dev/null @@ -1,770 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 17, - "gravity": 0, - "layoutEageType": 1, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 1, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Button_1138", - "relativeToName": "CheckBox_1139", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.697270453, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 281, - "y": 95, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 201, - "y": 95, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 14, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 1, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "ImageView_1140", - "relativeToName": "CheckBox_1139", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.3312655, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 133, - "y": 95, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": true, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 47, - "bgEndColorG": 107, - "bgEndColorR": 85, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -1 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/windows_ui_relative_align_location.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/windows_ui_relative_align_location.json deleted file mode 100644 index 87515fc40b..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/windows_ui_relative_align_location.json +++ /dev/null @@ -1,770 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 17, - "gravity": 0, - "layoutEageType": 1, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 1, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Button_1138", - "relativeToName": "CheckBox_1139", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.697270453, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 281, - "y": 95, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 201, - "y": 95, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 14, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 1, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "ImageView_1140", - "relativeToName": "CheckBox_1139", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.3312655, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 133, - "y": 95, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": true, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 47, - "bgEndColorG": 107, - "bgEndColorR": 85, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -1 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/crossplatform_Relative_Align_Parent.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/crossplatform_Relative_Align_Parent.ExportJson deleted file mode 100644 index 34052b23a1..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/crossplatform_Relative_Align_Parent.ExportJson +++ /dev/null @@ -1,417 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 65.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgEndColorR": 85, - "bgEndColorG": 107, - "bgEndColorB": 47, - "colorType": 0, - "bgColorOpacity": 255, - "vectorY": -1.0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 351.0, - "y": 20.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.8722084, - "positionPercentY": 0.105263159, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "Button_1138", - "relativeToName": "Panel_1137", - "align": 9 - }, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 201.0, - "y": 95.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137", - "align": 5 - }, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 40.0, - "y": 150.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.0992555842, - "positionPercentY": 0.7894737, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "ImageView_1140", - "relativeToName": "Panel_1137", - "align": 1 - }, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/crossplatform_UILayout_Relative_Align_Parent_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/crossplatform_UILayout_Relative_Align_Parent_Editor_1.ExportJson deleted file mode 100644 index 34052b23a1..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/crossplatform_UILayout_Relative_Align_Parent_Editor_1.ExportJson +++ /dev/null @@ -1,417 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 65.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgEndColorR": 85, - "bgEndColorG": 107, - "bgEndColorB": 47, - "colorType": 0, - "bgColorOpacity": 255, - "vectorY": -1.0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 351.0, - "y": 20.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.8722084, - "positionPercentY": 0.105263159, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "Button_1138", - "relativeToName": "Panel_1137", - "align": 9 - }, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 201.0, - "y": 95.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137", - "align": 5 - }, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 40.0, - "y": 150.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.0992555842, - "positionPercentY": 0.7894737, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "ImageView_1140", - "relativeToName": "Panel_1137", - "align": 1 - }, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/windows_ui_layout_relative_align_parent_editor.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/windows_ui_layout_relative_align_parent_editor.json deleted file mode 100644 index fb1623d570..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/windows_ui_layout_relative_align_parent_editor.json +++ /dev/null @@ -1,770 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Button_1138", - "relativeToName": "Panel_1137", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.8722084, - "positionPercentY": 0.105263159, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 121, - "y": 95, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 131, - "y": 92, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 1, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "ImageView_1140", - "relativeToName": "Panel_1137", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.0992555842, - "positionPercentY": 0.7894737, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 410, - "y": 416, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": true, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 47, - "bgEndColorG": 107, - "bgEndColorR": 85, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -1 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/windows_ui_relative_align_parent.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/windows_ui_relative_align_parent.json deleted file mode 100644 index fb1623d570..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/windows_ui_relative_align_parent.json +++ /dev/null @@ -1,770 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Button_1138", - "relativeToName": "Panel_1137", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.8722084, - "positionPercentY": 0.105263159, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 121, - "y": 95, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "CheckBox_1139", - "relativeToName": "Panel_1137", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 131, - "y": 92, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 1, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "ImageView_1140", - "relativeToName": "Panel_1137", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.0992555842, - "positionPercentY": 0.7894737, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 410, - "y": 416, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": true, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 47, - "bgEndColorG": 107, - "bgEndColorR": 85, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -1 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/crossplatform_Scale9_BackgroundImage.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/crossplatform_Scale9_BackgroundImage.ExportJson deleted file mode 100644 index 759cb90bc9..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/crossplatform_Scale9_BackgroundImage.ExportJson +++ /dev/null @@ -1,403 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 65.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "slider_bar.png", - "plistFile": "" - }, - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgEndColorR": 85, - "bgEndColorG": 107, - "bgEndColorB": 47, - "colorType": 0, - "bgColorOpacity": 255, - "vectorY": -1.0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 333.0, - "y": 76.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.8263027, - "positionPercentY": 0.4, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 46.0, - "y": 102.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.114143923, - "positionPercentY": 0.5368421, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 159.0, - "y": 90.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.394540936, - "positionPercentY": 0.473684222, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/crossplatform_UILayout_Scale9_BackgroundImage_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/crossplatform_UILayout_Scale9_BackgroundImage_Editor_1.ExportJson deleted file mode 100644 index 759cb90bc9..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/crossplatform_UILayout_Scale9_BackgroundImage_Editor_1.ExportJson +++ /dev/null @@ -1,403 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 65.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "slider_bar.png", - "plistFile": "" - }, - "bgColorR": 47, - "bgColorG": 79, - "bgColorB": 79, - "bgEndColorR": 85, - "bgEndColorG": 107, - "bgEndColorB": 47, - "colorType": 0, - "bgColorOpacity": 255, - "vectorY": -1.0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 190.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel" - }, - "name": "Panel_1137", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 333.0, - "y": 76.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.8263027, - "positionPercentY": 0.4, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 46.0, - "y": 102.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.114143923, - "positionPercentY": 0.5368421, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 159.0, - "y": 90.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.394540936, - "positionPercentY": 0.473684222, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/windows_ui_layout_scale9_backgroundimage_editor.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/windows_ui_layout_scale9_backgroundimage_editor.json deleted file mode 100644 index 9b8f984386..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/windows_ui_layout_scale9_backgroundimage_editor.json +++ /dev/null @@ -1,723 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.8263027, - "positionPercentY": 0.4, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 333, - "y": 76, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.114143923, - "positionPercentY": 0.5368421, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 46, - "y": 102, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.394540936, - "positionPercentY": 0.473684222, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 159, - "y": 90, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": -20, - "backGroundImage": null, - "backGroundImageData": { - "path": "slider_bar.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 47, - "bgEndColorG": 107, - "bgEndColorR": 85, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -1 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/windows_ui_scale9_backgroundimage.json b/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/windows_ui_scale9_backgroundimage.json deleted file mode 100644 index 9b8f984386..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/windows_ui_scale9_backgroundimage.json +++ /dev/null @@ -1,723 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.8263027, - "positionPercentY": 0.4, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.210526317, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 333, - "y": 76, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.114143923, - "positionPercentY": 0.5368421, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.294736832, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 46, - "y": 102, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.394540936, - "positionPercentY": 0.473684222, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.421052635, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 159, - "y": 90, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": -20, - "backGroundImage": null, - "backGroundImageData": { - "path": "slider_bar.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 79, - "bgColorG": 79, - "bgColorOpacity": 255, - "bgColorR": 47, - "bgEndColorB": 47, - "bgEndColorG": 107, - "bgEndColorR": 85, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -1 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 190, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.203125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.59375, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/crossplatform_UIListView_Horizontal_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/crossplatform_UIListView_Horizontal_Editor_1.ExportJson deleted file mode 100644 index 089cc5453b..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/crossplatform_UIListView_Horizontal_Editor_1.ExportJson +++ /dev/null @@ -1,481 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "y": 2.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "positionPercentY": 0.00625, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ListViewSurrogate, EditorCommon", - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "innerWidth": 446.0, - "innerHeight": 170.0, - "clipAble": true, - "bounceEnable": true, - "gravity": 5, - "x": -2.0, - "y": 2.0, - "touchAble": true, - "visible": true, - "classType": "ListView", - "width": 403.0, - "height": 170.0, - "positionPercentX": -0.004962779, - "positionPercentY": 0.0117647061, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1214, - "tag": 29, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "ListView_1214", - "relativeToName": "background_Panel", - "align": 1, - "marginLeft": -2, - "marginTop": -2 - }, - "name": "ListView_1214", - "classname": "ListView" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "GUI/button.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0 - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 51.0, - "y": 85.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.115470849, - "positionPercentY": 0.5, - "sizePercentX": 0.2309417, - "sizePercentY": 0.235294119, - "actionTag": 1217, - "tag": 32, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Button_1217", - "relativeToName": "ListView_1214" - }, - "name": "Button_1217", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 143.0, - "y": 85.0, - "visible": true, - "ZOrder": 1, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.3206278, - "positionPercentY": 0.5, - "sizePercentX": 0.179372191, - "sizePercentY": 0.470588237, - "actionTag": 1221, - "tag": 36, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "ImageView_1221", - "relativeToName": "ListView_1214" - }, - "name": "ImageView_1221", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 223.0, - "y": 85.0, - "visible": true, - "ZOrder": 2, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "sizePercentX": 0.179372191, - "sizePercentY": 0.470588237, - "actionTag": 1226, - "tag": 41, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "ImageView_1226", - "relativeToName": "ListView_1214" - }, - "name": "ImageView_1226", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "GUI/button.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0 - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 314.0, - "y": 85.0, - "touchAble": true, - "visible": true, - "ZOrder": 3, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.7051569, - "positionPercentY": 0.5, - "sizePercentX": 0.2309417, - "sizePercentY": 0.235294119, - "actionTag": 1228, - "tag": 43, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Button_1228", - "relativeToName": "ListView_1214" - }, - "name": "Button_1228", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 406.0, - "y": 85.0, - "visible": true, - "ZOrder": 4, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.9103139, - "positionPercentY": 0.5, - "sizePercentX": 0.179372191, - "sizePercentY": 0.470588237, - "actionTag": 1229, - "tag": 44, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "ImageView_1229", - "relativeToName": "ListView_1214" - }, - "name": "ImageView_1229", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "ListView" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/windows_ui_listview_horizontal_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/windows_ui_listview_horizontal_editor_1.json deleted file mode 100644 index 5c350c3b74..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/windows_ui_listview_horizontal_editor_1.json +++ /dev/null @@ -1,831 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "ListView", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1217", - "ZOrder": 0, - "actiontag": 1217, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.115470849, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.2309417, - "sizePercentY": 0.235294119, - "sizeType": 0, - "tag": 32, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 201, - "y": 150, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "GUI/button.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1221", - "ZOrder": 1, - "actiontag": 1221, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.3206278, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.179372191, - "sizePercentY": 0.470588237, - "sizeType": 0, - "tag": 36, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 201, - "y": 90, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1226", - "ZOrder": 2, - "actiontag": 1226, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.179372191, - "sizePercentY": 0.470588237, - "sizeType": 0, - "tag": 41, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 201, - "y": 40, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1228", - "ZOrder": 3, - "actiontag": 1228, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.7051569, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.2309417, - "sizePercentY": 0.235294119, - "sizeType": 0, - "tag": 43, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 201, - "y": 20, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "GUI/button.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1229", - "ZOrder": 4, - "actiontag": 1229, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.9103139, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.179372191, - "sizePercentY": 0.470588237, - "sizeType": 0, - "tag": 44, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 201, - "y": 40, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIListViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ListView", - "name": "ListView_1214", - "ZOrder": 0, - "actiontag": 1214, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 1, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": -2, - "marginRight": 0, - "marginTop": -2, - "relativeName": "ListView_1214", - "relativeToName": "background_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": -0.004962779, - "positionPercentY": 0.0117647061, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 29, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": -2, - "y": 2, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 150, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "bounceEnable": true, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "direction": 2, - "gravity": 5, - "innerHeight": 170, - "innerWidth": 446, - "itemMargin": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.00625, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 2, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/crossplatform_UIListView_Vertical_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/crossplatform_UIListView_Vertical_Editor_1.ExportJson deleted file mode 100644 index 10ebc4f516..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/crossplatform_UIListView_Vertical_Editor_1.ExportJson +++ /dev/null @@ -1,482 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "y": 2.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "positionPercentY": 0.00625, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ListViewSurrogate, EditorCommon", - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "innerWidth": 403.0, - "innerHeight": 320.0, - "clipAble": true, - "bounceEnable": true, - "direction": 1, - "gravity": 2, - "x": -2.0, - "y": 2.0, - "touchAble": true, - "visible": true, - "classType": "ListView", - "width": 403.0, - "height": 170.0, - "positionPercentX": -0.004962779, - "positionPercentY": 0.0117647061, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1214, - "tag": 29, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "ListView_1214", - "relativeToName": "background_Panel", - "align": 1, - "marginLeft": -2, - "marginTop": -2 - }, - "name": "ListView_1214", - "classname": "ListView" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "GUI/button.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0 - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 201.0, - "y": 300.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.5, - "positionPercentY": 0.9375, - "sizePercentX": 0.255583137, - "sizePercentY": 0.125, - "actionTag": 1217, - "tag": 32, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Button_1217", - "relativeToName": "ListView_1214" - }, - "name": "Button_1217", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 201.0, - "y": 240.0, - "visible": true, - "ZOrder": 1, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.5, - "positionPercentY": 0.75, - "sizePercentX": 0.198511168, - "sizePercentY": 0.25, - "actionTag": 1221, - "tag": 36, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "ImageView_1221", - "relativeToName": "ListView_1214" - }, - "name": "ImageView_1221", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 201.0, - "y": 160.0, - "visible": true, - "ZOrder": 2, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "sizePercentX": 0.198511168, - "sizePercentY": 0.25, - "actionTag": 1226, - "tag": 41, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "ImageView_1226", - "relativeToName": "ListView_1214" - }, - "name": "ImageView_1226", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "GUI/button.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0 - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 201.0, - "y": 100.0, - "touchAble": true, - "visible": true, - "ZOrder": 3, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.5, - "positionPercentY": 0.3125, - "sizePercentX": 0.255583137, - "sizePercentY": 0.125, - "actionTag": 1228, - "tag": 43, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Button_1228", - "relativeToName": "ListView_1214" - }, - "name": "Button_1228", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 201.0, - "y": 40.0, - "visible": true, - "ZOrder": 4, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.5, - "positionPercentY": 0.125, - "sizePercentX": 0.198511168, - "sizePercentY": 0.25, - "actionTag": 1229, - "tag": 44, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "ImageView_1229", - "relativeToName": "ListView_1214" - }, - "name": "ImageView_1229", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "ListView" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/windows_ui_listview_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/windows_ui_listview_editor_1.json deleted file mode 100644 index d8fb192b35..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/windows_ui_listview_editor_1.json +++ /dev/null @@ -1,831 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "ListView", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1217", - "ZOrder": 0, - "actiontag": 1217, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.9375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.125, - "sizeType": 0, - "tag": 32, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 201, - "y": 300, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "GUI/button.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1221", - "ZOrder": 1, - "actiontag": 1221, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.75, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.25, - "sizeType": 0, - "tag": 36, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 201, - "y": 216, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1226", - "ZOrder": 2, - "actiontag": 1226, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.25, - "sizeType": 0, - "tag": 41, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 201, - "y": 136, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1228", - "ZOrder": 3, - "actiontag": 1228, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.3125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.125, - "sizeType": 0, - "tag": 43, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 201, - "y": 100, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": null, - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "GUI/button.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1229", - "ZOrder": 4, - "actiontag": 1229, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.125, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.25, - "sizeType": 0, - "tag": 44, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 201, - "y": 40, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIListViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ListView", - "name": "ListView_1214", - "ZOrder": 0, - "actiontag": 1214, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 1, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": -2, - "marginRight": 0, - "marginTop": -2, - "relativeName": "ListView_1214", - "relativeToName": "background_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": -0.004962779, - "positionPercentY": 0.0117647061, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 29, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": -2, - "y": 2, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 150, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "bounceEnable": true, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "direction": 1, - "gravity": 2, - "innerHeight": 320, - "innerWidth": 403, - "itemMargin": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.00625, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 2, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/crossplatform_UILoadingBar_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/crossplatform_UILoadingBar_Editor_1.ExportJson deleted file mode 100644 index a6728799e5..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/crossplatform_UILoadingBar_Editor_1.ExportJson +++ /dev/null @@ -1,440 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 1, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 85.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 0.5, - "actionTag": 750, - "tag": 10, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel_button_0", - "relativeToName": "background_Panel", - "align": 9 - }, - "name": "Panel_button_0", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LoadingBarSurrogate, EditorCommon", - "textureData": { - "resourceType": 0, - "path": "GUI/loadingbar.png", - "plistFile": "" - }, - "direction": 1, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 201.0, - "y": 63.0, - "touchAble": true, - "visible": true, - "classType": "LoadingBar", - "width": 350.0, - "height": 24.0, - "positionPercentX": 0.5, - "positionPercentY": 0.7411765, - "sizePercentX": 0.868486345, - "sizePercentY": 0.282352954, - "actionTag": 857, - "tag": 23, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "LoadingBar_857", - "relativeToName": "Panel_button_0", - "marginTop": 10 - }, - "name": "LoadingBar_857", - "classname": "LoadingBar" - }, - "children": [], - "classname": "LoadingBar" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "right to left", - "x": 201.0, - "y": 27.0, - "visible": true, - "classType": "Label", - "width": 107.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.323529422, - "sizePercentX": 0.265508682, - "sizePercentY": 0.31764707, - "actionTag": 751, - "tag": 12, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Label_124_0", - "relativeToName": "Panel_button_0", - "marginTop": 10 - }, - "name": "Label_124_0", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 1, - "y": 85.0, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 85.0, - "positionPercentY": 0.5, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 0.5, - "actionTag": 122, - "tag": 10, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "align": 1 - }, - "name": "Panel_button", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LoadingBarSurrogate, EditorCommon", - "textureData": { - "resourceType": 0, - "path": "GUI/loadingbar.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 201.0, - "y": 63.0, - "touchAble": true, - "visible": true, - "classType": "LoadingBar", - "width": 350.0, - "height": 24.0, - "positionPercentX": 0.5, - "positionPercentY": 0.7411765, - "sizePercentX": 0.868486345, - "sizePercentY": 0.282352954, - "actionTag": 856, - "tag": 22, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "LoadingBar_856", - "relativeToName": "Panel_button", - "marginTop": 10 - }, - "name": "LoadingBar_856", - "classname": "LoadingBar" - }, - "children": [], - "classname": "LoadingBar" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "left to right", - "x": 201.0, - "y": 27.0, - "visible": true, - "classType": "Label", - "width": 107.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.323529422, - "sizePercentX": 0.265508682, - "sizePercentY": 0.31764707, - "actionTag": 124, - "tag": 12, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Label_124", - "relativeToName": "Panel_button", - "marginTop": 10 - }, - "name": "Label_124", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/windows_ui_loadingbar_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/windows_ui_loadingbar_editor_1.json deleted file mode 100644 index bb72b25f81..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UILoadingBar_Editor/windows_ui_loadingbar_editor_1.json +++ /dev/null @@ -1,875 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "LoadingBar", - "name": null, - "children": [], - "options": { - "__type": "ComGUILoadingBarSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LoadingBar", - "name": "LoadingBar_857", - "ZOrder": 0, - "actiontag": 857, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 24, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "LoadingBar_857", - "relativeToName": "Panel_button_0", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.7411765, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.868486345, - "sizePercentY": 0.282352954, - "sizeType": 0, - "tag": 23, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 350, - "x": 201, - "y": 63, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "direction": 1, - "percent": 100, - "scale9Enable": false, - "texture": null, - "textureData": { - "path": "GUI/loadingbar.png", - "plistFile": null, - "resourceType": 0 - } - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_124_0", - "ZOrder": 0, - "actiontag": 751, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Label_124_0", - "relativeToName": "Panel_button_0", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.323529422, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.235732, - "sizePercentY": 0.31764707, - "sizeType": 0, - "tag": 12, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 200, - "y": 37, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "right to left", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_button_0", - "ZOrder": 0, - "actiontag": 750, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 85, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_button_0", - "relativeToName": "background_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.5, - "sizeType": 1, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "LoadingBar", - "name": null, - "children": [], - "options": { - "__type": "ComGUILoadingBarSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "LoadingBar", - "name": "LoadingBar_856", - "ZOrder": 0, - "actiontag": 856, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 24, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "LoadingBar_856", - "relativeToName": "Panel_button", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.7411765, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.868486345, - "sizePercentY": 0.282352954, - "sizeType": 0, - "tag": 22, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 350, - "x": 201, - "y": 63, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "direction": 0, - "percent": 100, - "scale9Enable": false, - "texture": null, - "textureData": { - "path": "GUI/loadingbar.png", - "plistFile": null, - "resourceType": 0 - } - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_124", - "ZOrder": 0, - "actiontag": 124, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Label_124", - "relativeToName": "Panel_button", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.323529422, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.235732, - "sizePercentY": 0.31764707, - "sizeType": 0, - "tag": 12, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 201, - "y": 37, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "left to right", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_button", - "ZOrder": 0, - "actiontag": 122, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 85, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 1, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.5, - "sizeType": 1, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 85, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/crossplatform_UIPageView_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/crossplatform_UIPageView_Editor_1.ExportJson deleted file mode 100644 index f171982538..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/crossplatform_UIPageView_Editor_1.ExportJson +++ /dev/null @@ -1,464 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PageViewSurrogate, EditorCommon", - "clipAble": true, - "bgColorR": 100, - "bgColorG": 250, - "bgEndColorR": 100, - "bgEndColorG": 250, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": -2.0, - "touchAble": true, - "visible": true, - "classType": "PageView", - "width": 403.0, - "height": 170.0, - "positionPercentX": -0.004962779, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1269, - "tag": 45, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "PageView_1269", - "relativeToName": "background_Panel", - "align": 1, - "marginLeft": -2 - }, - "name": "PageView_1269", - "classname": "PageView" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "clipAble": true, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1270, - "tag": 46, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_1270", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "page1", - "x": 201.0, - "y": 85.0, - "visible": true, - "classType": "Label", - "width": 60.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "sizePercentX": 0.148883373, - "sizePercentY": 0.158823535, - "actionTag": 1273, - "tag": 49, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "Label_1273", - "relativeToName": "Panel_1270", - "align": 5, - "marginLeft": 145, - "marginTop": 61 - }, - "name": "Label_1273", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "x": 403.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 1.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1271, - "tag": 47, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_1271", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "page2", - "x": 201.0, - "y": 85.0, - "visible": true, - "classType": "Label", - "width": 60.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "sizePercentX": 0.148883373, - "sizePercentY": 0.158823535, - "actionTag": 1274, - "tag": 50, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "Label_1274", - "relativeToName": "Panel_1271", - "align": 5 - }, - "name": "Label_1274", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "x": 806.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 2.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1272, - "tag": 48, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_1272", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "page3", - "x": 201.0, - "y": 85.0, - "visible": true, - "classType": "Label", - "width": 60.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "sizePercentX": 0.148883373, - "sizePercentY": 0.158823535, - "actionTag": 1275, - "tag": 51, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "Label_1275", - "relativeToName": "Panel_1272", - "align": 5 - }, - "name": "Label_1275", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "PageView" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/windows_ui_pageview_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/windows_ui_pageview_editor_1.json deleted file mode 100644 index 68110e9f0b..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIPageView_Editor/windows_ui_pageview_editor_1.json +++ /dev/null @@ -1,921 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "PageView", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_1273", - "ZOrder": 0, - "actiontag": 1273, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 145, - "marginRight": 0, - "marginTop": 61, - "relativeName": "Label_1273", - "relativeToName": "Panel_1270", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.235732, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 49, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 175, - "y": 95, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "page1", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1270", - "ZOrder": 1, - "actiontag": 1270, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.005882353, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 46, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 1, - "backGroundImage": null, - "backGroundImageData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_1274", - "ZOrder": 0, - "actiontag": 1274, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Label_1274", - "relativeToName": "Panel_1271", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.235732, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 50, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 30, - "y": 156, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "page2", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1271", - "ZOrder": 2, - "actiontag": 1271, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 1, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 47, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 403, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_1275", - "ZOrder": 0, - "actiontag": 1275, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Label_1275", - "relativeToName": "Panel_1272", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.5, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.235732, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 51, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 30, - "y": 156, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "page3", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1272", - "ZOrder": 2, - "actiontag": 1272, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 2, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 48, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 806, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "PageView", - "name": "PageView_1269", - "ZOrder": 0, - "actiontag": 1269, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 1, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": -2, - "marginRight": 0, - "marginTop": 0, - "relativeName": "PageView_1269", - "relativeToName": "background_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": -0.004962779, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 45, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 362, - "y": 265, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 100, - "bgColorG": 250, - "bgColorOpacity": 100, - "bgColorR": 100, - "bgEndColorB": 100, - "bgEndColorG": 250, - "bgEndColorR": 100, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/crossplatform_UIScrollView_Both_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/crossplatform_UIScrollView_Both_Editor_1.ExportJson deleted file mode 100644 index d8eb05a658..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/crossplatform_UIScrollView_Both_Editor_1.ExportJson +++ /dev/null @@ -1,457 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 312.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.975, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2, - "marginTop": -49 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ScrollViewSurrogate, EditorCommon", - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "innerWidth": 500.0, - "innerHeight": 400.0, - "direction": 3, - "clipAble": true, - "bounceEnable": true, - "x": 1.0, - "scaleX": 0.9986458, - "touchAble": true, - "visible": true, - "classType": "ScrollView", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.00248138956, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "ScrollView_1137", - "relativeToName": "background_Panel", - "marginLeft": 1 - }, - "name": "ScrollView_1137", - "classname": "ScrollView" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 438.0, - "y": 236.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.876, - "positionPercentY": 0.59, - "sizePercentX": 0.206, - "sizePercentY": 0.1, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 270.0, - "y": 66.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.54, - "positionPercentY": 0.165, - "sizePercentX": 0.112, - "sizePercentY": 0.14, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 165.0, - "y": 235.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.33, - "positionPercentY": 0.5875, - "sizePercentX": 0.16, - "sizePercentY": 0.2, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 334.0, - "y": 330.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.668, - "positionPercentY": 0.825, - "sizePercentX": 0.16, - "sizePercentY": 0.2, - "actionTag": 1142, - "tag": 23, - "ignoreSize": true, - "name": "ImageView_1142", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 68.0, - "y": 340.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.136, - "positionPercentY": 0.85, - "sizePercentX": 0.16, - "sizePercentY": 0.2, - "actionTag": 1157, - "tag": 36, - "ignoreSize": true, - "name": "ImageView_1157", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "ScrollView" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/windows_ui_scrollview_both_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/windows_ui_scrollview_both_editor_1.json deleted file mode 100644 index 042ad658ec..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/windows_ui_scrollview_both_editor_1.json +++ /dev/null @@ -1,829 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": -49, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "ScrollView", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.8776743, - "positionPercentY": 0.5916668, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.206, - "sizePercentY": 0.1, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 438, - "y": 236, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.5414021, - "positionPercentY": 0.165000185, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.112, - "sizePercentY": 0.14, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 270, - "y": 66, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.3315602, - "positionPercentY": 0.5875002, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.16, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 165, - "y": 235, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1142", - "ZOrder": 0, - "actiontag": 1142, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.6698373, - "positionPercentY": 0.825000167, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.16, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 23, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 334, - "y": 330, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1157", - "ZOrder": 0, - "actiontag": 1157, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.137818649, - "positionPercentY": 0.85, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.16, - "sizePercentY": 0.2, - "sizeType": 0, - "tag": 36, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 68, - "y": 340, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIScrollViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ScrollView", - "name": "ScrollView_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 1, - "marginRight": 0, - "marginTop": 0, - "relativeName": "ScrollView_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.00248138956, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 0.9986458, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 1, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 100, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 255, - "bgEndColorB": 100, - "bgEndColorG": 150, - "bgEndColorR": 255, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "bounceEnable": true, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "direction": 3, - "innerHeight": 400, - "innerWidth": 500, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/crossplatform_UIScrollView_Horizontal_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/crossplatform_UIScrollView_Horizontal_Editor_1.ExportJson deleted file mode 100644 index 4a5e183f80..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/crossplatform_UIScrollView_Horizontal_Editor_1.ExportJson +++ /dev/null @@ -1,452 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ScrollViewSurrogate, EditorCommon", - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "innerWidth": 500.0, - "innerHeight": 170.0, - "direction": 2, - "clipAble": true, - "bounceEnable": true, - "touchAble": true, - "visible": true, - "classType": "ScrollView", - "width": 403.0, - "height": 170.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "ScrollView_1137", - "relativeToName": "background_Panel" - }, - "name": "ScrollView_1137", - "classname": "ScrollView" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 66.0, - "y": 86.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.132, - "positionPercentY": 0.5058824, - "sizePercentX": 0.206, - "sizePercentY": 0.235294119, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 161.0, - "y": 86.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.322, - "positionPercentY": 0.5058824, - "sizePercentX": 0.112, - "sizePercentY": 0.329411775, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 249.0, - "y": 86.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.498, - "positionPercentY": 0.5058824, - "sizePercentX": 0.16, - "sizePercentY": 0.470588237, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 343.0, - "y": 86.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.686, - "positionPercentY": 0.5058824, - "sizePercentX": 0.16, - "sizePercentY": 0.470588237, - "actionTag": 1142, - "tag": 23, - "ignoreSize": true, - "name": "ImageView_1142", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 440.0, - "y": 86.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.88, - "positionPercentY": 0.5058824, - "sizePercentX": 0.16, - "sizePercentY": 0.470588237, - "actionTag": 1157, - "tag": 36, - "ignoreSize": true, - "name": "ImageView_1157", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "ScrollView" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/windows_ui_scrollview_horizontal_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/windows_ui_scrollview_horizontal_editor_1.json deleted file mode 100644 index de4876ee3c..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/windows_ui_scrollview_horizontal_editor_1.json +++ /dev/null @@ -1,829 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "ScrollView", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.132, - "positionPercentY": 0.511529565, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.206, - "sizePercentY": 0.235294119, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 66, - "y": 86, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.322, - "positionPercentY": 0.511529565, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.112, - "sizePercentY": 0.329411775, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 161, - "y": 86, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.498, - "positionPercentY": 0.511529565, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.16, - "sizePercentY": 0.470588237, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 249, - "y": 86, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1142", - "ZOrder": 0, - "actiontag": 1142, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.686, - "positionPercentY": 0.511529565, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.16, - "sizePercentY": 0.470588237, - "sizeType": 0, - "tag": 23, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 343, - "y": 86, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1157", - "ZOrder": 0, - "actiontag": 1157, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.881, - "positionPercentY": 0.511529565, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.16, - "sizePercentY": 0.470588237, - "sizeType": 0, - "tag": 36, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 440, - "y": 86, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIScrollViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ScrollView", - "name": "ScrollView_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "ScrollView_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 100, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 255, - "bgEndColorB": 100, - "bgEndColorG": 150, - "bgEndColorR": 255, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "bounceEnable": true, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "direction": 2, - "innerHeight": 170, - "innerWidth": 500, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/crossplatform_UIScrollView_Vertical_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/crossplatform_UIScrollView_Vertical_Editor_1.ExportJson deleted file mode 100644 index 07ebebfc6a..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/crossplatform_UIScrollView_Vertical_Editor_1.ExportJson +++ /dev/null @@ -1,422 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ScrollViewSurrogate, EditorCommon", - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "innerWidth": 403.0, - "innerHeight": 300.0, - "clipAble": true, - "bounceEnable": true, - "touchAble": true, - "visible": true, - "classType": "ScrollView", - "width": 403.0, - "height": 170.0, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": 1137, - "tag": 18, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "ScrollView_1137", - "relativeToName": "background_Panel" - }, - "name": "ScrollView_1137", - "classname": "ScrollView" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon", - "normalData": { - "resourceType": 0, - "path": "button_n.png", - "plistFile": "" - }, - "pressedData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "disabledData": { - "resourceType": 0, - "path": "button_p.png", - "plistFile": "" - }, - "text": "Text Button", - "scale9Width": 103.0, - "scale9Height": 40.0, - "x": 205.0, - "y": 265.0, - "touchAble": true, - "visible": true, - "classType": "Button", - "width": 103.0, - "height": 40.0, - "positionPercentX": 0.5086849, - "positionPercentY": 0.8833333, - "sizePercentX": 0.255583137, - "sizePercentY": 0.13333334, - "actionTag": 1138, - "tag": 19, - "ignoreSize": true, - "name": "Button_1138", - "classname": "Button" - }, - "children": [], - "classname": "Button" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.CheckBoxSurrogate, EditorCommon", - "backGroundBoxData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxSelectedData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "backGroundBoxDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "frontCrossData": { - "resourceType": 0, - "path": "selected02.png", - "plistFile": "" - }, - "frontCrossDisabledData": { - "resourceType": 0, - "path": "selected01.png", - "plistFile": "" - }, - "selectedState": true, - "x": 205.0, - "y": 205.0, - "touchAble": true, - "visible": true, - "classType": "CheckBox", - "width": 56.0, - "height": 56.0, - "positionPercentX": 0.5086849, - "positionPercentY": 0.683333337, - "sizePercentX": 0.138957813, - "sizePercentY": 0.186666667, - "actionTag": 1139, - "tag": 20, - "ignoreSize": true, - "name": "CheckBox_1139", - "classname": "CheckBox" - }, - "children": [], - "classname": "CheckBox" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 205.0, - "y": 127.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.5086849, - "positionPercentY": 0.423333347, - "sizePercentX": 0.198511168, - "sizePercentY": 0.266666681, - "actionTag": 1140, - "tag": 21, - "ignoreSize": true, - "name": "ImageView_1140", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.ImageViewSurrogate, EditorCommon", - "fileNameData": { - "resourceType": 0, - "path": "GUI/image.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "x": 205.0, - "y": 40.0, - "visible": true, - "classType": "ImageView", - "width": 80.0, - "height": 80.0, - "positionPercentX": 0.5086849, - "positionPercentY": 0.13333334, - "sizePercentX": 0.198511168, - "sizePercentY": 0.266666681, - "actionTag": 1142, - "tag": 23, - "ignoreSize": true, - "name": "ImageView_1142", - "classname": "ImageView" - }, - "children": [], - "classname": "ImageView" - } - ], - "classname": "ScrollView" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/windows_ui_scrollview_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/windows_ui_scrollview_editor_1.json deleted file mode 100644 index 69149f3ce1..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/windows_ui_scrollview_editor_1.json +++ /dev/null @@ -1,776 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "ScrollView", - "name": null, - "children": [ - { - "classname": "Button", - "name": null, - "children": [], - "options": { - "__type": "ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Button", - "name": "Button_1138", - "ZOrder": 0, - "actiontag": 1138, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 40, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.509305239, - "positionPercentY": 0.8863999, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.255583137, - "sizePercentY": 0.13333334, - "sizeType": 0, - "tag": 19, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 103, - "x": 205, - "y": 265, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "disabled": null, - "disabledData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "fontName": "微软雅黑", - "fontSize": 14, - "fontType": 0, - "normal": null, - "normalData": { - "path": "button_n.png", - "plistFile": null, - "resourceType": 0 - }, - "pressed": null, - "pressedData": { - "path": "button_p.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 40, - "scale9Width": 103, - "text": "Text Button", - "textColorB": 255, - "textColorG": 255, - "textColorR": 255 - } - }, - { - "classname": "CheckBox", - "name": null, - "children": [], - "options": { - "__type": "ComGUICheckBoxSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "CheckBox", - "name": "CheckBox_1139", - "ZOrder": 0, - "actiontag": 1139, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 56, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.509305239, - "positionPercentY": 0.686399937, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.138957813, - "sizePercentY": 0.186666667, - "sizeType": 0, - "tag": 20, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 56, - "x": 205, - "y": 205, - "backGroundBox": null, - "backGroundBoxData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxDisabled": null, - "backGroundBoxDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundBoxSelected": null, - "backGroundBoxSelectedData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCross": null, - "frontCrossData": { - "path": "selected02.png", - "plistFile": null, - "resourceType": 0 - }, - "frontCrossDisabled": null, - "frontCrossDisabledData": { - "path": "selected01.png", - "plistFile": null, - "resourceType": 0 - }, - "selectedState": true - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1140", - "ZOrder": 0, - "actiontag": 1140, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.509305239, - "positionPercentY": 0.426399946, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.266666681, - "sizeType": 0, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 205, - "y": 127, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - }, - { - "classname": "ImageView", - "name": null, - "children": [], - "options": { - "__type": "ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ImageView", - "name": "ImageView_1142", - "ZOrder": 0, - "actiontag": 1142, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 80, - "ignoreSize": true, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0.509305239, - "positionPercentY": 0.136400044, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.198511168, - "sizePercentY": 0.266666681, - "sizeType": 0, - "tag": 23, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 80, - "x": 205, - "y": 40, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "fileName": null, - "fileNameData": { - "path": "GUI/image.png", - "plistFile": null, - "resourceType": 0 - }, - "scale9Enable": false, - "scale9Height": 80, - "scale9Width": 80 - } - } - ], - "options": { - "__type": "ComGUIScrollViewSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "ScrollView", - "name": "ScrollView_1137", - "ZOrder": 0, - "actiontag": 1137, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "ScrollView_1137", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 1, - "tag": 18, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 100, - "bgColorG": 150, - "bgColorOpacity": 100, - "bgColorR": 255, - "bgEndColorB": 100, - "bgEndColorG": 150, - "bgEndColorR": 255, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "bounceEnable": true, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": true, - "colorType": 1, - "direction": 1, - "innerHeight": 300, - "innerWidth": 403, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/crossplatform_UISlider_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/crossplatform_UISlider_Editor_1.ExportJson deleted file mode 100644 index 356f8edab9..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/crossplatform_UISlider_Editor_1.ExportJson +++ /dev/null @@ -1,484 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 1, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 3, - "y": 89.0, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 51.0, - "positionPercentY": 0.5235294, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 0.3, - "actionTag": 122, - "tag": 10, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "marginTop": 30 - }, - "name": "Panel_button", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "Slider", - "x": 201.0, - "y": 13.0, - "visible": true, - "classType": "Label", - "width": 54.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.264705867, - "sizePercentX": 0.133995041, - "sizePercentY": 0.529411733, - "actionTag": 124, - "tag": 12, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "Label_124", - "relativeToName": "Panel_button", - "align": 8 - }, - "name": "Label_124", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.SliderSurrogate, EditorCommon", - "barFileNameData": { - "resourceType": 0, - "path": "slider_bar.png", - "plistFile": "" - }, - "ballNormalData": { - "resourceType": 0, - "path": "slider_bar_button.png", - "plistFile": "" - }, - "ballPressedData": { - "resourceType": 0, - "path": "slider_bar_button.png", - "plistFile": "" - }, - "ballDisabledData": { - "resourceType": 0, - "path": "slider_bar_button.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "barCapInsetsWidth": 0.0, - "barCapInsetsHeight": 0.0, - "progressBarData": { - "resourceType": 0, - "path": "silder_progressBar.png", - "plistFile": "" - }, - "x": 201.0, - "y": 47.0, - "touchAble": true, - "visible": true, - "classType": "Slider", - "width": 290.0, - "height": 8.0, - "positionPercentX": 0.5, - "positionPercentY": 0.921568632, - "sizePercentX": 0.719603, - "sizePercentY": 0.156862736, - "actionTag": 738, - "tag": 15, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "Slider_738", - "relativeToName": "Panel_button", - "align": 2 - }, - "name": "Slider_738", - "classname": "Slider" - }, - "children": [], - "classname": "Slider" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 3, - "y": 7.0, - "visible": true, - "classType": "Panel", - "width": 403.0, - "height": 51.0, - "positionPercentY": 0.0470588021, - "sizeType": 1, - "sizePercentX": 1.0, - "sizePercentY": 0.3, - "actionTag": 739, - "tag": 16, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 1, - "relativeName": "Panel_739", - "relativeToName": "background_Panel", - "marginTop": 30 - }, - "name": "Panel_739", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.SliderSurrogate, EditorCommon", - "barFileNameData": { - "resourceType": 0, - "path": "2014-1-26 11-43-52.png", - "plistFile": "" - }, - "ballNormalData": { - "resourceType": 0, - "path": "slider_bar_button.png", - "plistFile": "" - }, - "ballPressedData": { - "resourceType": 0, - "path": "slider_bar_button.png", - "plistFile": "" - }, - "ballDisabledData": { - "resourceType": 0, - "path": "slider_bar_button.png", - "plistFile": "" - }, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "barCapInsetsWidth": 0.0, - "barCapInsetsHeight": 0.0, - "scale9Enable": true, - "progressBarData": { - "resourceType": 0, - "path": "2014-1-26 11-42-09.png", - "plistFile": "" - }, - "x": 201.0, - "y": 47.0, - "touchAble": true, - "visible": true, - "classType": "Slider", - "width": 290.0, - "height": 8.0, - "positionPercentX": 0.5, - "positionPercentY": 0.921568632, - "sizePercentX": 0.719603, - "sizePercentY": 0.156862736, - "actionTag": 740, - "tag": 17, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Slider_740", - "relativeToName": "Panel_739", - "align": 2 - }, - "name": "Slider_740", - "classname": "Slider" - }, - "children": [], - "classname": "Slider" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "Scale 9 slider", - "x": 201.0, - "y": 13.0, - "visible": true, - "classType": "Label", - "width": 124.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.264705867, - "sizePercentX": 0.307692319, - "sizePercentY": 0.529411733, - "actionTag": 741, - "tag": 18, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "Label_741", - "relativeToName": "Panel_739", - "align": 8 - }, - "name": "Label_741", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/windows_ui_slider_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/windows_ui_slider_editor_1.json deleted file mode 100644 index fbba3b8408..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UISlider_Editor/windows_ui_slider_editor_1.json +++ /dev/null @@ -1,947 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_124", - "ZOrder": 0, - "actiontag": 124, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 8, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 2, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Label_124", - "relativeToName": "Panel_button", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.264705867, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.235732, - "sizePercentY": 0.529411733, - "sizeType": 0, - "tag": 12, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 199, - "y": 13, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "Slider", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Slider", - "name": null, - "children": [], - "options": { - "__type": "ComGUISliderSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Slider", - "name": "Slider_738", - "ZOrder": 0, - "actiontag": 738, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 8, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Slider_738", - "relativeToName": "Panel_button", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.921568632, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.719603, - "sizePercentY": 0.156862736, - "sizeType": 0, - "tag": 15, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 290, - "x": 201, - "y": 47, - "ballDisabled": null, - "ballDisabledData": { - "path": "slider_bar_button.png", - "plistFile": null, - "resourceType": 0 - }, - "ballNormal": null, - "ballNormalData": { - "path": "slider_bar_button.png", - "plistFile": null, - "resourceType": 0 - }, - "ballPressed": null, - "ballPressedData": { - "path": "slider_bar_button.png", - "plistFile": null, - "resourceType": 0 - }, - "barCapInsetsHeight": 0, - "barCapInsetsWidth": 0, - "barCapInsetsX": 0, - "barCapInsetsY": 0, - "barFileName": null, - "barFileNameData": { - "path": "slider_bar.png", - "plistFile": null, - "resourceType": 0 - }, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "length": 290, - "percent": 0, - "progressBarCapInsetsHeight": 0, - "progressBarCapInsetsWidth": 0, - "progressBarCapInsetsX": 0, - "progressBarCapInsetsY": 0, - "progressBarData": { - "path": "silder_progressBar.png", - "plistFile": null, - "resourceType": 0 - }, - "progressBarVisible": false, - "scale9Enable": false, - "scale9Height": 0, - "scale9Width": 0, - "slidBallAnchorPointX": 0, - "slidBallAnchorPointY": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_button", - "ZOrder": 0, - "actiontag": 122, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 51.0000038, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 30, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.5235294, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.3, - "sizeType": 1, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 462, - "y": 484, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Slider", - "name": null, - "children": [], - "options": { - "__type": "ComGUISliderSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Slider", - "name": "Slider_740", - "ZOrder": 0, - "actiontag": 740, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 8, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Slider_740", - "relativeToName": "Panel_739", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.921568632, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.719603, - "sizePercentY": 0.156862736, - "sizeType": 0, - "tag": 17, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 290, - "x": 201, - "y": 47, - "ballDisabled": null, - "ballDisabledData": { - "path": "slider_bar_button.png", - "plistFile": null, - "resourceType": 0 - }, - "ballNormal": null, - "ballNormalData": { - "path": "slider_bar_button.png", - "plistFile": null, - "resourceType": 0 - }, - "ballPressed": null, - "ballPressedData": { - "path": "slider_bar_button.png", - "plistFile": null, - "resourceType": 0 - }, - "barCapInsetsHeight": 0, - "barCapInsetsWidth": 0, - "barCapInsetsX": 0, - "barCapInsetsY": 0, - "barFileName": null, - "barFileNameData": { - "path": "2014-1-26 11-43-52.png", - "plistFile": null, - "resourceType": 0 - }, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "length": 290, - "percent": 0, - "progressBarCapInsetsHeight": 0, - "progressBarCapInsetsWidth": 0, - "progressBarCapInsetsX": 0, - "progressBarCapInsetsY": 0, - "progressBarData": { - "path": "2014-1-26 11-42-09.png", - "plistFile": null, - "resourceType": 0 - }, - "progressBarVisible": false, - "scale9Enable": true, - "scale9Height": 0, - "scale9Width": 0, - "slidBallAnchorPointX": 0, - "slidBallAnchorPointY": 0 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_741", - "ZOrder": 0, - "actiontag": 741, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 8, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 2, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Label_741", - "relativeToName": "Panel_739", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.264705867, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.235732, - "sizePercentY": 0.529411733, - "sizeType": 0, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 383, - "y": 381, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "Scale 9 slider", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_739", - "ZOrder": 0, - "actiontag": 739, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 51.0000038, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 1, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 30, - "relativeName": "Panel_739", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.0470588021, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.3, - "sizeType": 1, - "tag": 16, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 0, - "y": 38, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UITextField_Editor/crossplatform_UITextField_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UITextField_Editor/crossplatform_UITextField_Editor_1.ExportJson deleted file mode 100644 index 08de0a1582..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UITextField_Editor/crossplatform_UITextField_Editor_1.ExportJson +++ /dev/null @@ -1,530 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 2, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 1, - "visible": true, - "classType": "Panel", - "width": 132.0, - "height": 170.0, - "sizeType": 1, - "sizePercentX": 0.33, - "sizePercentY": 1.0, - "actionTag": 993, - "tag": 10, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 5, - "relativeName": "Panel_button_0", - "relativeToName": "background_Panel" - }, - "name": "Panel_button_0", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.TextFieldSurrogate, EditorCommon", - "text": "", - "placeHolder": "input words", - "maxLength": 6, - "x": 66.0, - "y": 106.0, - "touchAble": true, - "visible": true, - "classType": "TextField", - "width": 114.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.626470566, - "sizePercentX": 0.8572073, - "sizePercentY": 0.158823535, - "actionTag": 1109, - "tag": 24, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "TextField_1109", - "relativeToName": "Panel_button_0", - "marginTop": 50 - }, - "name": "TextField_1109", - "classname": "TextField" - }, - "children": [], - "classname": "TextField" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "nomal", - "x": 66.0, - "y": 69.0, - "visible": true, - "classType": "Label", - "width": 60.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.40882352, - "sizePercentX": 0.4511617, - "sizePercentY": 0.158823535, - "actionTag": 997, - "tag": 18, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Label_997", - "relativeToName": "Panel_button_0", - "marginTop": 10 - }, - "name": "Label_997", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 1, - "x": 132.0, - "visible": true, - "classType": "Panel", - "width": 137.0, - "height": 170.0, - "positionPercentX": 0.33, - "sizeType": 1, - "sizePercentX": 0.34, - "sizePercentY": 1.0, - "actionTag": 122, - "tag": 10, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 5, - "relativeName": "Panel_button", - "relativeToName": "background_Panel" - }, - "name": "Panel_button", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.TextFieldSurrogate, EditorCommon", - "text": "", - "placeHolder": "input words", - "maxLengthEnable": true, - "maxLength": 3, - "x": 68.0, - "y": 106.0, - "touchAble": true, - "visible": true, - "classType": "TextField", - "width": 114.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.626470566, - "sizePercentX": 0.8319953, - "sizePercentY": 0.158823535, - "actionTag": 1110, - "tag": 25, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "TextField_1110", - "relativeToName": "Panel_button", - "marginTop": 50 - }, - "name": "TextField_1110", - "classname": "TextField" - }, - "children": [], - "classname": "TextField" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "max character", - "x": 68.0, - "y": 69.0, - "visible": true, - "classType": "Label", - "width": 134.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.40882352, - "sizePercentX": 0.9779594, - "sizePercentY": 0.158823535, - "actionTag": 998, - "tag": 19, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Label_998", - "relativeToName": "Panel_button", - "marginTop": 10 - }, - "name": "Label_998", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "layoutType": 1, - "x": 270.0, - "visible": true, - "classType": "Panel", - "width": 132.0, - "height": 170.0, - "positionPercentX": 0.67, - "sizeType": 1, - "sizePercentX": 0.33, - "sizePercentY": 1.0, - "actionTag": 1106, - "tag": 21, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 1, - "gravity": 2, - "relativeName": "Panel_1106", - "relativeToName": "background_Panel" - }, - "name": "Panel_1106", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.TextFieldSurrogate, EditorCommon", - "text": "", - "placeHolder": "input words", - "passwordEnable": true, - "maxLength": 6, - "x": 66.0, - "y": 106.0, - "touchAble": true, - "visible": true, - "classType": "TextField", - "width": 114.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.626470566, - "sizePercentX": 0.8572073, - "sizePercentY": 0.158823535, - "actionTag": 1107, - "tag": 22, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "TextField_1107", - "relativeToName": "Panel_1106", - "marginTop": 50 - }, - "name": "TextField_1107", - "classname": "TextField" - }, - "children": [], - "classname": "TextField" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "text": "password", - "x": 66.0, - "y": 69.0, - "visible": true, - "classType": "Label", - "width": 92.0, - "height": 27.0, - "positionPercentX": 0.5, - "positionPercentY": 0.40882352, - "sizePercentX": 0.6917813, - "sizePercentY": 0.158823535, - "actionTag": 1108, - "tag": 23, - "ignoreSize": true, - "layoutParameter": { - "type": 1, - "gravity": 6, - "relativeName": "Label_1108", - "relativeToName": "Panel_1106", - "marginTop": 10 - }, - "name": "Label_1108", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UITextField_Editor/windows_ui_textfield_editor_1.json b/samples/js-tests/res/cocosui/UIEditorTest/UITextField_Editor/windows_ui_textfield_editor_1.json deleted file mode 100644 index 3509bf88ec..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UITextField_Editor/windows_ui_textfield_editor_1.json +++ /dev/null @@ -1,1079 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "TextField", - "name": null, - "children": [], - "options": { - "__type": "ComGUITextFieldSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "TextField", - "name": "TextField_1109", - "ZOrder": 0, - "actiontag": 1109, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 50, - "relativeName": "TextField_1109", - "relativeToName": "Panel_button_0", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.626470566, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.6767426, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 24, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 114, - "x": 60, - "y": 106, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "maxLength": 6, - "maxLengthEnable": false, - "passwordEnable": false, - "passwordStyleText": "*", - "placeHolder": "input words", - "text": "" - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_997", - "ZOrder": 0, - "actiontag": 997, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Label_997", - "relativeToName": "Panel_button_0", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.40882352, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.7143394, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 18, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 60, - "y": 69, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "nomal", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_button_0", - "ZOrder": 0, - "actiontag": 993, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 4, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_button_0", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.33, - "sizePercentY": 1, - "sizeType": 1, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 132.99, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "TextField", - "name": null, - "children": [], - "options": { - "__type": "ComGUITextFieldSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "TextField", - "name": "TextField_1110", - "ZOrder": 0, - "actiontag": 1110, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 50, - "relativeName": "TextField_1110", - "relativeToName": "Panel_button", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.626470566, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.6568384, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 25, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 114, - "x": 60, - "y": 106, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "maxLength": 3, - "maxLengthEnable": true, - "passwordEnable": false, - "passwordStyleText": "*", - "placeHolder": "input words", - "text": "" - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_998", - "ZOrder": 0, - "actiontag": 998, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Label_998", - "relativeToName": "Panel_button", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.40882352, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.6933294, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 19, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 60, - "y": 69, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "max character", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_button", - "ZOrder": 0, - "actiontag": 122, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 6, - "gravity": 5, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_button", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.33, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.34, - "sizePercentY": 1, - "sizeType": 1, - "tag": 10, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 137.02, - "x": 152, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "TextField", - "name": null, - "children": [], - "options": { - "__type": "ComGUITextFieldSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "TextField", - "name": "TextField_1107", - "ZOrder": 0, - "actiontag": 1107, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 50, - "relativeName": "TextField_1107", - "relativeToName": "Panel_1106", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.626470566, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.6767426, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 22, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 114, - "x": 60, - "y": 106, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "maxLength": 6, - "maxLengthEnable": false, - "passwordEnable": true, - "passwordStyleText": "*", - "placeHolder": "input words", - "text": "" - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "Label_1108", - "ZOrder": 0, - "actiontag": 1108, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 6, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 10, - "relativeName": "Label_1108", - "relativeToName": "Panel_1106", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.40882352, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.7143394, - "sizePercentY": 0.158823535, - "sizeType": 0, - "tag": 23, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 47, - "y": 69, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "微软雅黑", - "fontSize": 20, - "hAlignment": 0, - "text": "password", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_1106", - "ZOrder": 0, - "actiontag": 1106, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 0, - "gravity": 2, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 0, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel_1106", - "relativeToName": "background_Panel", - "type": 1 - }, - "opacity": 255, - "positionPercentX": 0.67, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.33, - "sizePercentY": 1, - "sizeType": 1, - "tag": 21, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 132.99, - "x": 290, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 1, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 2, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/crossplatform_UIWidgetAddNode_Editor_1.ExportJson b/samples/js-tests/res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/crossplatform_UIWidgetAddNode_Editor_1.ExportJson deleted file mode 100644 index ee252d1681..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/crossplatform_UIWidgetAddNode_Editor_1.ExportJson +++ /dev/null @@ -1,238 +0,0 @@ -{ - "version": "1.0.0.0", - "cocos2dVersion": "3.x", - "designWidth": 480, - "designHeight": 320, - "dataScale": 1.0, - "textures": [], - "texturesPng": [], - "nodeTree": { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon", - "visible": true, - "frameEvent": null, - "name": "Node", - "classname": "Node" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "bgColorOpacity": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "visible": true, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 5, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "Panel_521", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "background.png", - "plistFile": "" - }, - "bgColorR": 255, - "bgColorG": 255, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "bgColorOpacity": 255, - "capInsetsX": 160.0, - "capInsetsY": 106.0, - "capInsetsWidth": 160.0, - "capInsetsHeight": 106.0, - "layoutType": 3, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 320.0, - "sizePercentX": 1.0, - "sizePercentY": 1.0, - "actionTag": -1, - "tag": 81, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "name": "root_Panel", - "classname": "Panel" - }, - "children": [ - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "ribbon.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsX": 66.0, - "capInsetsY": 66.0, - "capInsetsWidth": 66.0, - "capInsetsHeight": 66.0, - "backGroundScale9Enable": true, - "y": 263.0, - "visible": true, - "ZOrder": 1, - "classType": "Panel", - "width": 480.0, - "height": 57.0, - "positionPercentY": 0.821875, - "sizePercentX": 1.0, - "sizePercentY": 0.178125, - "actionTag": 109, - "tag": 82, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "text": "UI_test", - "x": 240.0, - "y": 310.0, - "visible": true, - "ZOrder": 1, - "classType": "Label", - "width": 70.0, - "height": 20.0, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "sizePercentX": 0.145833328, - "sizePercentY": 0.0625, - "actionTag": 115, - "tag": 88, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "align": 2 - }, - "name": "UItest", - "classname": "Label" - }, - "children": [], - "classname": "Label" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon", - "backGroundImageData": { - "resourceType": 0, - "path": "buttonBackground.png", - "plistFile": "" - }, - "bgEndColorR": 0, - "bgEndColorG": 0, - "colorType": 0, - "capInsetsWidth": 0.0, - "capInsetsHeight": 0.0, - "backGroundScale9Enable": true, - "layoutType": 3, - "x": 38.0, - "y": 75.0, - "visible": true, - "ZOrder": 2, - "classType": "Panel", - "width": 403.0, - "height": 170.0, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "actionTag": 110, - "tag": 83, - "anchorPointX": 0.0, - "anchorPointY": 0.0, - "ignoreSize": false, - "layoutParameter": { - "type": 2, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "align": 5 - }, - "name": "background_Panel", - "classname": "Panel" - }, - "children": [], - "classname": "Panel" - }, - { - "options": { - "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon", - "fontName": "宋体", - "fontSize": 24, - "text": "Back", - "x": 436.0, - "y": 22.0, - "touchAble": true, - "visible": true, - "ZOrder": 6, - "classType": "Label", - "width": 48.0, - "height": 24.0, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "sizePercentX": 0.1, - "sizePercentY": 0.075, - "actionTag": 114, - "tag": 87, - "ignoreSize": true, - "layoutParameter": { - "type": 2, - "relativeName": "back", - "relativeToName": "root_Panel", - "align": 9, - "marginRight": 20, - "marginDown": 10 - }, - "name": "back", - "classname": "Label" - }, - "children": [], - "classname": "Label" - } - ], - "classname": "Panel" - } - ], - "classname": "Panel" - } - ], - "classname": "Node" - }, - "action": { - "speed": 1.0, - "timelines": [] - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/windows_ui_widget_add_node_editor.json b/samples/js-tests/res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/windows_ui_widget_add_node_editor.json deleted file mode 100644 index 1ee73b1cb0..0000000000 --- a/samples/js-tests/res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/windows_ui_widget_add_node_editor.json +++ /dev/null @@ -1,442 +0,0 @@ -{ - "classname": null, - "name": null, - "animation": { - "classname": null, - "name": "AnimationManager", - "actionlist": [] - }, - "dataScale": 1, - "designHeight": 320, - "designWidth": 480, - "textures": [], - "version": "1.2.0.1", - "widgetTree": { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [ - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel", - "ZOrder": 1, - "actiontag": 109, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 57, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0.821875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 0.178125, - "sizeType": 0, - "tag": 82, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 263, - "backGroundImage": null, - "backGroundImageData": { - "path": "ribbon.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 66.6666641, - "capInsetsWidth": 66.6666641, - "capInsetsX": 66.6666641, - "capInsetsY": 66.6666641, - "clipAble": false, - "colorType": 0, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "UItest", - "ZOrder": 1, - "actiontag": 115, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 2, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 0, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "UItest", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.5, - "positionPercentY": 0.96875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 88, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 240, - "y": 310, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 20, - "hAlignment": 0, - "text": "UI_test", - "touchScaleEnable": false, - "vAlignment": 0 - } - }, - { - "classname": "Panel", - "name": null, - "children": [], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "background_Panel", - "ZOrder": 2, - "actiontag": 110, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 170, - "ignoreSize": false, - "layoutParameter": { - "classname": null, - "name": null, - "align": 5, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 1, - "layoutParentVertical": 1, - "marginDown": 0, - "marginLeft": 0, - "marginRight": 0, - "marginTop": 0, - "relativeName": "background_Panel", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.08020833, - "positionPercentY": 0.234375, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.839583337, - "sizePercentY": 0.53125, - "sizeType": 0, - "tag": 83, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 403, - "x": 38, - "y": 75, - "backGroundImage": null, - "backGroundImageData": { - "path": "buttonBackground.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": true, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 100, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - }, - { - "classname": "Label", - "name": null, - "children": [], - "options": { - "__type": "ComGUILabelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Label", - "name": "back", - "ZOrder": 6, - "actiontag": 114, - "anchorPointX": 0.5, - "anchorPointY": 0.5, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 27, - "ignoreSize": true, - "layoutParameter": { - "classname": null, - "name": null, - "align": 9, - "gravity": 0, - "layoutEageType": 0, - "layoutNormalHorizontal": 0, - "layoutNormalVertical": 0, - "layoutParentHorizontal": 2, - "layoutParentVertical": 2, - "marginDown": 10, - "marginLeft": 0, - "marginRight": 20, - "marginTop": 0, - "relativeName": "back", - "relativeToName": "root_Panel", - "type": 2 - }, - "opacity": 255, - "positionPercentX": 0.908333361, - "positionPercentY": 0.06875, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 0.197916672, - "sizePercentY": 0.084375, - "sizeType": 0, - "tag": 87, - "touchAble": true, - "useMergedTexture": false, - "visible": true, - "width": 95, - "x": 436, - "y": 32, - "areaHeight": 0, - "areaWidth": 0, - "fontFile": null, - "fontName": "宋体", - "fontSize": 24, - "hAlignment": 0, - "text": "Back", - "touchScaleEnable": false, - "vAlignment": 0 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "root_Panel", - "ZOrder": 1, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 81, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": { - "path": "background.png", - "plistFile": null, - "resourceType": 0 - }, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 255, - "bgColorOpacity": 255, - "bgColorR": 255, - "bgEndColorB": 255, - "bgEndColorG": 0, - "bgEndColorR": 0, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 106.666664, - "capInsetsWidth": 160, - "capInsetsX": 160, - "capInsetsY": 106.666664, - "clipAble": false, - "colorType": 0, - "layoutType": 3, - "vectorX": 0, - "vectorY": -0.5 - } - } - ], - "options": { - "__type": "ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI", - "classname": "Panel", - "name": "Panel_521", - "ZOrder": 0, - "actiontag": -1, - "anchorPointX": 0, - "anchorPointY": 0, - "classType": null, - "colorB": 255, - "colorG": 255, - "colorR": 255, - "flipX": false, - "flipY": false, - "height": 320, - "ignoreSize": false, - "layoutParameter": null, - "opacity": 255, - "positionPercentX": 0, - "positionPercentY": 0, - "positionType": 0, - "rotation": 0, - "scaleX": 1, - "scaleY": 1, - "sizePercentX": 1, - "sizePercentY": 1, - "sizeType": 0, - "tag": 5, - "touchAble": false, - "useMergedTexture": false, - "visible": true, - "width": 480, - "x": 0, - "y": 0, - "backGroundImage": null, - "backGroundImageData": null, - "backGroundScale9Enable": false, - "bgColorB": 255, - "bgColorG": 200, - "bgColorOpacity": 0, - "bgColorR": 150, - "bgEndColorB": 255, - "bgEndColorG": 200, - "bgEndColorR": 150, - "bgStartColorB": 255, - "bgStartColorG": 255, - "bgStartColorR": 255, - "capInsetsHeight": 0, - "capInsetsWidth": 0, - "capInsetsX": 0, - "capInsetsY": 0, - "clipAble": false, - "colorType": 1, - "layoutType": 0, - "vectorX": 0, - "vectorY": -0.5 - } - } -} \ No newline at end of file diff --git a/samples/js-tests/res/cocosui/switch-mask.png b/samples/js-tests/res/cocosui/switch-mask.png new file mode 100644 index 0000000000..fc49f947d7 Binary files /dev/null and b/samples/js-tests/res/cocosui/switch-mask.png differ diff --git a/samples/js-tests/res/scenetest/BackgroundComponentTest/BackgroundComponentTest.json b/samples/js-tests/res/scenetest/BackgroundComponentTest/BackgroundComponentTest.json index f088420ad8..0a4238c46d 100644 --- a/samples/js-tests/res/scenetest/BackgroundComponentTest/BackgroundComponentTest.json +++ b/samples/js-tests/res/scenetest/BackgroundComponentTest/BackgroundComponentTest.json @@ -143,7 +143,7 @@ "name": "CCBackgroundAudio", "file": null, "fileData": { - "path": "Misc/music_logo.mp3", + "path": "Misc/music_logo.wav", "plistFile": null, "resourceType": 0 }, diff --git a/samples/js-tests/res/scenetest/LoadSceneEdtiorFileTest/FishJoy2.json b/samples/js-tests/res/scenetest/LoadSceneEdtiorFileTest/FishJoy2.json index f7b916611c..a01eebcf96 100644 --- a/samples/js-tests/res/scenetest/LoadSceneEdtiorFileTest/FishJoy2.json +++ b/samples/js-tests/res/scenetest/LoadSceneEdtiorFileTest/FishJoy2.json @@ -297,7 +297,7 @@ "name": "CCBackgroundAudio", "file": null, "fileData": { - "path": "Misc/music_logo.mp3", + "path": "Misc/music_logo.wav", "plistFile": null, "resourceType": 0 }, diff --git a/samples/js-tests/res/skeletons/goblins-ffd.atlas b/samples/js-tests/res/skeletons/goblins-ffd.atlas new file mode 100644 index 0000000000..b977b07f61 --- /dev/null +++ b/samples/js-tests/res/skeletons/goblins-ffd.atlas @@ -0,0 +1,292 @@ + +goblins-ffd.png +format: RGBA8888 +filter: Linear,Linear +repeat: none +dagger + rotate: false + xy: 2, 28 + size: 26, 108 + orig: 26, 108 + offset: 0, 0 + index: -1 +goblin/eyes-closed + rotate: false + xy: 137, 29 + size: 34, 12 + orig: 34, 12 + offset: 0, 0 + index: -1 +goblin/head + rotate: false + xy: 26, 357 + size: 103, 66 + orig: 103, 66 + offset: 0, 0 + index: -1 +goblin/left-arm + rotate: false + xy: 30, 28 + size: 37, 35 + orig: 37, 35 + offset: 0, 0 + index: -1 +goblin/left-foot + rotate: false + xy: 134, 260 + size: 65, 31 + orig: 65, 31 + offset: 0, 0 + index: -1 +goblin/left-hand + rotate: false + xy: 69, 25 + size: 36, 41 + orig: 36, 41 + offset: 0, 0 + index: -1 +goblin/left-lower-leg + rotate: false + xy: 134, 293 + size: 33, 70 + orig: 33, 70 + offset: 0, 0 + index: -1 +goblin/left-shoulder + rotate: false + xy: 137, 43 + size: 29, 44 + orig: 29, 44 + offset: 0, 0 + index: -1 +goblin/left-upper-leg + rotate: false + xy: 30, 65 + size: 33, 73 + orig: 33, 73 + offset: 0, 0 + index: -1 +goblin/neck + rotate: false + xy: 201, 387 + size: 36, 41 + orig: 36, 41 + offset: 0, 0 + index: -1 +goblin/pelvis + rotate: false + xy: 26, 140 + size: 62, 43 + orig: 62, 43 + offset: 0, 0 + index: -1 +goblin/right-arm + rotate: false + xy: 171, 84 + size: 23, 50 + orig: 23, 50 + offset: 0, 0 + index: -1 +goblin/right-foot + rotate: false + xy: 134, 225 + size: 63, 33 + orig: 63, 33 + offset: 0, 0 + index: -1 +goblin/right-hand + rotate: false + xy: 204, 258 + size: 36, 37 + orig: 36, 37 + offset: 0, 0 + index: -1 +goblin/right-lower-leg + rotate: false + xy: 201, 430 + size: 36, 76 + orig: 36, 76 + offset: 0, 0 + index: -1 +goblin/right-shoulder + rotate: false + xy: 130, 89 + size: 39, 45 + orig: 39, 45 + offset: 0, 0 + index: -1 +goblin/right-upper-leg + rotate: false + xy: 98, 214 + size: 34, 63 + orig: 34, 63 + offset: 0, 0 + index: -1 +goblin/torso + rotate: false + xy: 131, 410 + size: 68, 96 + orig: 68, 96 + offset: 0, 0 + index: -1 +goblin/undie-straps + rotate: false + xy: 2, 7 + size: 55, 19 + orig: 55, 19 + offset: 0, 0 + index: -1 +goblin/undies + rotate: false + xy: 199, 227 + size: 36, 29 + orig: 36, 29 + offset: 0, 0 + index: -1 +goblingirl/eyes-closed + rotate: false + xy: 59, 2 + size: 37, 21 + orig: 37, 21 + offset: 0, 0 + index: -1 +goblingirl/head + rotate: false + xy: 26, 425 + size: 103, 81 + orig: 103, 81 + offset: 0, 0 + index: -1 +goblingirl/left-arm + rotate: false + xy: 201, 190 + size: 37, 35 + orig: 37, 35 + offset: 0, 0 + index: -1 +goblingirl/left-foot + rotate: false + xy: 134, 192 + size: 65, 31 + orig: 65, 31 + offset: 0, 0 + index: -1 +goblingirl/left-hand + rotate: false + xy: 196, 109 + size: 35, 40 + orig: 35, 40 + offset: 0, 0 + index: -1 +goblingirl/left-lower-leg + rotate: false + xy: 169, 293 + size: 33, 70 + orig: 33, 70 + offset: 0, 0 + index: -1 +goblingirl/left-shoulder + rotate: false + xy: 107, 30 + size: 28, 46 + orig: 28, 46 + offset: 0, 0 + index: -1 +goblingirl/left-upper-leg + rotate: false + xy: 65, 68 + size: 33, 70 + orig: 33, 70 + offset: 0, 0 + index: -1 +goblingirl/neck + rotate: false + xy: 204, 297 + size: 35, 41 + orig: 35, 41 + offset: 0, 0 + index: -1 +goblingirl/pelvis + rotate: false + xy: 131, 365 + size: 62, 43 + orig: 62, 43 + offset: 0, 0 + index: -1 +goblingirl/right-arm + rotate: false + xy: 100, 97 + size: 28, 50 + orig: 28, 50 + offset: 0, 0 + index: -1 +goblingirl/right-foot + rotate: false + xy: 134, 157 + size: 63, 33 + orig: 63, 33 + offset: 0, 0 + index: -1 +goblingirl/right-hand + rotate: false + xy: 199, 151 + size: 36, 37 + orig: 36, 37 + offset: 0, 0 + index: -1 +goblingirl/right-lower-leg + rotate: false + xy: 96, 279 + size: 36, 76 + orig: 36, 76 + offset: 0, 0 + index: -1 +goblingirl/right-shoulder + rotate: false + xy: 204, 340 + size: 39, 45 + orig: 39, 45 + offset: 0, 0 + index: -1 +goblingirl/right-upper-leg + rotate: false + xy: 98, 149 + size: 34, 63 + orig: 34, 63 + offset: 0, 0 + index: -1 +goblingirl/torso + rotate: false + xy: 26, 259 + size: 68, 96 + orig: 68, 96 + offset: 0, 0 + index: -1 +goblingirl/undie-straps + rotate: false + xy: 134, 136 + size: 55, 19 + orig: 55, 19 + offset: 0, 0 + index: -1 +goblingirl/undies + rotate: false + xy: 196, 78 + size: 36, 29 + orig: 36, 29 + offset: 0, 0 + index: -1 +shield + rotate: false + xy: 26, 185 + size: 70, 72 + orig: 70, 72 + offset: 0, 0 + index: -1 +spear + rotate: false + xy: 2, 138 + size: 22, 368 + orig: 22, 368 + offset: 0, 0 + index: -1 diff --git a/samples/js-tests/res/skeletons/goblins-ffd.json b/samples/js-tests/res/skeletons/goblins-ffd.json new file mode 100644 index 0000000000..b35360ad1f --- /dev/null +++ b/samples/js-tests/res/skeletons/goblins-ffd.json @@ -0,0 +1,1081 @@ +{ +"bones": [ + { "name": "root" }, + { "name": "hip", "parent": "root", "x": 0.64, "y": 114.41 }, + { "name": "left upper leg", "parent": "hip", "length": 50.39, "x": 14.45, "y": 2.81, "rotation": -89.09 }, + { "name": "pelvis", "parent": "hip", "x": 1.41, "y": -6.57 }, + { "name": "right upper leg", "parent": "hip", "length": 42.45, "x": -20.07, "y": -6.83, "rotation": -97.49 }, + { "name": "torso", "parent": "hip", "length": 85.82, "x": -6.42, "y": 1.97, "rotation": 93.92 }, + { "name": "left lower leg", "parent": "left upper leg", "length": 49.89, "x": 56.34, "y": 0.98, "rotation": -16.65 }, + { "name": "left shoulder", "parent": "torso", "length": 35.43, "x": 74.04, "y": -20.38, "rotation": -156.96 }, + { "name": "neck", "parent": "torso", "length": 18.38, "x": 81.67, "y": -6.34, "rotation": -1.51 }, + { "name": "right lower leg", "parent": "right upper leg", "length": 58.52, "x": 42.99, "y": -0.61, "rotation": -14.34 }, + { "name": "right shoulder", "parent": "torso", "length": 37.24, "x": 76.02, "y": 18.14, "rotation": 133.88 }, + { "name": "head", "parent": "neck", "length": 68.28, "x": 20.93, "y": 11.59, "rotation": -13.92 }, + { "name": "left arm", "parent": "left shoulder", "length": 35.62, "x": 37.85, "y": -2.34, "rotation": 28.16 }, + { "name": "left foot", "parent": "left lower leg", "length": 46.5, "x": 58.94, "y": -7.61, "rotation": 102.43 }, + { "name": "right arm", "parent": "right shoulder", "length": 36.74, "x": 37.6, "y": 0.31, "rotation": 36.32 }, + { "name": "right foot", "parent": "right lower leg", "length": 45.45, "x": 64.88, "y": 0.04, "rotation": 110.3 }, + { "name": "left hand", "parent": "left arm", "length": 11.52, "x": 35.62, "y": 0.07, "rotation": 2.7 }, + { "name": "right hand", "parent": "right arm", "length": 15.32, "x": 36.9, "y": 0.34, "rotation": 2.35 }, + { "name": "spear1", "parent": "left hand", "length": 65.06, "x": 0.48, "y": 17.03, "rotation": 102.43 }, + { "name": "spear2", "parent": "spear1", "length": 61.41, "x": 65.05, "y": 0.04, "rotation": 0.9 }, + { "name": "spear3", "parent": "spear2", "length": 76.79, "x": 61.88, "y": 0.57, "rotation": -0.9 } +], +"slots": [ + { "name": "left shoulder", "bone": "left shoulder", "attachment": "left shoulder" }, + { "name": "left arm", "bone": "left arm", "attachment": "left arm" }, + { "name": "left hand item", "bone": "left hand", "attachment": "spear" }, + { "name": "left hand", "bone": "left hand", "attachment": "left hand" }, + { "name": "left foot", "bone": "left foot", "attachment": "left foot" }, + { "name": "left lower leg", "bone": "left lower leg", "attachment": "left lower leg" }, + { "name": "left upper leg", "bone": "left upper leg", "attachment": "left upper leg" }, + { "name": "neck", "bone": "neck", "attachment": "neck" }, + { "name": "torso", "bone": "torso", "attachment": "torso" }, + { "name": "pelvis", "bone": "pelvis", "attachment": "pelvis" }, + { "name": "right foot", "bone": "right foot", "attachment": "right foot" }, + { "name": "right lower leg", "bone": "right lower leg", "attachment": "right lower leg" }, + { "name": "undie straps", "bone": "pelvis", "attachment": "undie straps" }, + { "name": "undies", "bone": "pelvis", "attachment": "undies" }, + { "name": "right upper leg", "bone": "right upper leg", "attachment": "right upper leg" }, + { "name": "head", "bone": "head", "attachment": "head" }, + { "name": "eyes", "bone": "head" }, + { "name": "right shoulder", "bone": "right shoulder", "attachment": "right shoulder" }, + { "name": "right arm", "bone": "right arm", "attachment": "right arm" }, + { "name": "right hand thumb", "bone": "right hand", "attachment": "right hand thumb" }, + { "name": "right hand item", "bone": "right hand", "attachment": "dagger" }, + { "name": "right hand", "bone": "right hand", "attachment": "right hand" }, + { "name": "right hand item 2", "bone": "right hand", "attachment": "shield" } +], +"skins": { + "default": { + "left hand item": { + "dagger": { "x": 7.88, "y": -23.45, "rotation": 10.47, "width": 26, "height": 108 }, + "spear": { + "type": "skinnedmesh", + "uvs": [ 1, 0.11236, 0.77096, 0.13278, 0.76608, 0.21781, 0.75642, 0.386, 0.74723, 0.54607, 0.72117, 1, 0.28838, 1, 0.24208, 0.54327, 0.22589, 0.38361, 0.2089, 0.21605, 0.20043, 0.13242, 0, 0.11519, 0.4527, 0, 0.58399, 0 ], + "triangles": [ 5, 6, 4, 6, 7, 4, 4, 7, 3, 2, 9, 1, 9, 10, 1, 10, 12, 1, 12, 13, 1, 1, 13, 0, 10, 11, 12, 3, 8, 2, 8, 9, 2, 7, 8, 3 ], + "vertices": [ 1, 20, 38.54, -10.88, 1, 1, 20, 30.97, -5.93, 1, 2, 19, 61.48, -5.58, 0.51, 20, -0.31, -6.16, 0.48, 2, 18, 64.73, -5.03, 0.5, 19, -0.4, -5.06, 0.49, 1, 16, 4.56, 23.91, 1, 1, 16, 41.7, -138.95, 1, 1, 16, 32.42, -141.1, 1, 1, 16, -6.49, 22.4, 1, 2, 18, 65.48, 6.64, 0.5, 19, 0.53, 6.59, 0.49, 2, 19, 62.18, 6.66, 0.51, 20, 0.2, 6.09, 0.48, 1, 20, 30.96, 6.61, 1, 1, 20, 37.26, 11.09, 1, 1, 20, 79.75, 1.59, 1, 1, 20, 79.78, -1.29, 1 ], + "edges": [ 24, 22, 22, 20, 10, 12, 2, 0, 24, 26, 0, 26, 8, 10, 12, 14, 6, 8, 14, 16, 2, 4, 4, 6, 16, 18, 18, 20, 20, 2 ], + "hull": 14, + "width": 22, + "height": 368 + } + }, + "right hand item": { + "dagger": { + "type": "mesh", + "uvs": [ 0.78091, 0.38453, 1, 0.38405, 1, 0.44881, 0.73953, 0.4687, 0.74641, 0.81344, 0.34022, 1, 0.15434, 1, 0.11303, 0.78858, 0.23007, 0.47367, 0, 0.45047, 0, 0.38621, 0.22367, 0.38573, 0.24384, 0, 1, 0 ], + "triangles": [ 0, 12, 13, 11, 12, 0, 0, 1, 2, 9, 10, 11, 3, 11, 0, 3, 0, 2, 8, 11, 3, 9, 11, 8, 5, 6, 7, 4, 5, 8, 4, 8, 3, 5, 7, 8 ], + "vertices": [ 15.49, -12.82, 21.13, -13.57, 20.16, -20.49, 13.15, -21.67, 8.13, -58.56, -5.13, -77.04, -9.92, -76.36, -7.79, -53.6, -0.03, -20.36, -5.6, -17.04, -4.63, -10.17, 1.12, -10.93, 7.46, 30.24, 26.93, 27.49 ], + "edges": [ 22, 20, 24, 26, 22, 24, 2, 0, 0, 22, 0, 26, 12, 14, 14, 16, 18, 20, 16, 18, 2, 4, 4, 6, 6, 8, 10, 12, 8, 10 ], + "hull": 14, + "width": 26, + "height": 108 + } + }, + "right hand item 2": { + "shield": { "rotation": 93.49, "width": 70, "height": 72 } + } + }, + "goblin": { + "eyes": { + "eyes closed": { "name": "goblin/eyes-closed", "x": 29.19, "y": -24.89, "rotation": -88.92, "width": 34, "height": 12 } + }, + "head": { + "head": { + "name": "goblin/head", + "type": "mesh", + "uvs": [ 0, 0.60494, 0.14172, 0.5145, 0.24218, 0.55229, 0.32667, 0.67806, 0.37969, 0.79352, 0.53505, 0.93014, 0.86056, 1, 0.94071, 0.94169, 0.92098, 0.69923, 0.9888, 0.65497, 0.99003, 0.51643, 0.89632, 0.43561, 0.94487, 0.41916, 1, 0.39713, 1, 0.2836, 0.94017, 0.27027, 0.87906, 0.25666, 0.80754, 0.16044, 0.66698, 0.01997, 0.4734, 0.01805, 0.29215, 0.19893, 0.25392, 0.31823, 0.09117, 0.324, 0, 0.44331, 0.43271, 0.69153, 0.466, 0.47794, 0.35996, 0.31246, 0.73473, 0.68593, 0.72215, 0.57425, 0.88179, 0.5583, 0.80267, 0.51015 ], + "triangles": [ 26, 20, 19, 21, 20, 26, 15, 14, 13, 12, 15, 13, 11, 16, 15, 11, 15, 12, 26, 17, 25, 18, 26, 19, 17, 26, 18, 30, 25, 17, 30, 17, 16, 30, 16, 11, 1, 22, 21, 23, 22, 1, 2, 1, 21, 2, 21, 26, 29, 30, 11, 29, 11, 10, 28, 25, 30, 0, 23, 1, 9, 29, 10, 25, 3, 2, 25, 2, 26, 29, 27, 28, 29, 28, 30, 24, 3, 25, 24, 25, 28, 24, 28, 27, 8, 29, 9, 27, 29, 8, 4, 3, 24, 5, 24, 27, 4, 24, 5, 7, 6, 27, 7, 27, 8, 5, 27, 6 ], + "vertices": [ 14.56, 50.42, 23.12, 35.47, 17.46, 26.36, 11.57, 16.86, 3.74, 11.71, -5.89, -3.91, -11.83, -37.23, -8.31, -45.63, 7.75, -44.24, 10.39, -51.33, 19.52, -51.82, 25.21, -43.15, 26.12, -47.43, 27.35, -53.16, 34.84, -53.46, 35.96, -47.33, 37.11, -41.08, 43.75, -33.97, 53.58, -19.87, 54.5, 0.03, 43.31, 19.16, 35.6, 23.41, 35.89, 40.17, 28.39, 49.87, 10.25, 5.99, 24.2, 2, 35.55, 12.48, 9.39, -25.1, 16.8, -24.31, 17.2, -40.65, 20.68, -33.02 ], + "edges": [ 0, 2, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 20, 22, 26, 28, 32, 34, 34, 36, 36, 38, 38, 40, 40, 42, 42, 44, 44, 46, 0, 46, 6, 48, 48, 50, 50, 52, 52, 42, 2, 4, 4, 6, 4, 52, 2, 44, 22, 32, 22, 24, 24, 26, 28, 30, 30, 32, 24, 30, 16, 54, 54, 56, 20, 58, 58, 54, 16, 58, 22, 60, 60, 56, 58, 60 ], + "hull": 24, + "width": 103, + "height": 66 + } + }, + "left arm": { + "left arm": { + "name": "goblin/left-arm", + "type": "mesh", + "uvs": [ 0.68992, 0.29284, 1, 0.46364, 1, 0.74643, 0.84089, 1, 0.66344, 1, 0.33765, 0.64284, 0, 0.44124, 0, 0, 0.34295, 0 ], + "triangles": [ 6, 7, 8, 5, 6, 8, 0, 5, 8, 0, 1, 2, 5, 0, 2, 4, 5, 2, 3, 4, 2 ], + "vertices": [ 18.6, 8.81, 32.19, 10.31, 38.02, 1.62, 38.08, -9.63, 32.31, -13.49, 14.37, -9.62, -0.75, -10.78, -9.84, 2.77, 1.29, 10.25 ], + "edges": [ 14, 16, 16, 0, 0, 2, 2, 4, 6, 4, 6, 8, 8, 10, 12, 14, 10, 12 ], + "hull": 9, + "width": 37, + "height": 35 + } + }, + "left foot": { + "left foot": { + "name": "goblin/left-foot", + "type": "mesh", + "uvs": [ 0.15733, 0.31873, 0.08195, 0.78502, 0.15884, 0.99366, 0.41633, 0.96804, 0.68822, 0.97636, 1, 0.96388, 0.99385, 0.73501, 0.85294, 0.51862, 0.61479, 0.31056, 0.46991, 0, 0.48032, 0.75604, 0.75994, 0.77706 ], + "triangles": [ 0, 9, 8, 10, 0, 8, 10, 8, 7, 11, 10, 7, 11, 7, 6, 1, 0, 10, 11, 6, 5, 3, 1, 10, 4, 10, 11, 4, 11, 5, 3, 10, 4, 2, 1, 3 ], + "vertices": [ 2.28, 13.07, -1.76, -1.64, 3.59, -7.8, 20.25, -6.04, 37.91, -5.27, 58.12, -3.71, 57.31, 3.34, 47.78, 9.51, 31.95, 15.05, 21.99, 24.11, 24.03, 0.75, 42.21, 1.16 ], + "edges": [ 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 0, 18, 6, 20, 20, 16, 2, 20, 8, 22, 22, 14, 20, 22, 22, 10 ], + "hull": 10, + "width": 65, + "height": 31 + } + }, + "left hand": { + "left hand": { + "name": "goblin/left-hand", + "type": "mesh", + "uvs": [ 0.518, 0.12578, 1, 0.16285, 0.99788, 0.50578, 0.69745, 1, 0.37445, 1, 0, 0.80051, 0, 0.42792, 0.17601, 0, 0.43567, 0 ], + "triangles": [ 2, 0, 1, 0, 5, 6, 6, 7, 0, 0, 7, 8, 3, 4, 0, 4, 5, 0, 2, 3, 0 ], + "vertices": [ -3.11, 15.42, 10.83, 22.27, 15.5, 14.55, 18.35, -8.96, 9.48, -14.32, -4.58, -14.3, -11.63, -2.63, -14.89, 13.68, -7.75, 17.99 ], + "edges": [ 16, 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 14, 16, 12, 14 ], + "hull": 9, + "width": 36, + "height": 41 + } + }, + "left lower leg": { + "left lower leg": { + "name": "goblin/left-lower-leg", + "type": "mesh", + "uvs": [ 0.95508, 0.20749, 0.81927, 0.65213, 0.94754, 0.77308, 0.67842, 0.97346, 0.46463, 1, 0.26845, 1, 0.04963, 0.90706, 0.2106, 0.60115, 0.07478, 0.40195, 0.18545, 0, 0.28857, 0 ], + "triangles": [ 10, 8, 9, 1, 7, 10, 7, 8, 10, 0, 1, 10, 1, 4, 7, 3, 1, 2, 5, 6, 7, 7, 4, 5, 1, 3, 4 ], + "vertices": [ -0.19, 6.82, 30.97, 10.96, 37.97, 17.33, 53.88, 12.6, 57.58, 6.31, 59.34, 0.08, 55.04, -8.63, 32.99, -9.33, 20.79, -17.43, -7.27, -21.56, -8.19, -18.29 ], + "edges": [ 20, 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 18, 20, 16, 18 ], + "hull": 11, + "width": 33, + "height": 70 + } + }, + "left shoulder": { + "left shoulder": { + "name": "goblin/left-shoulder", + "type": "mesh", + "uvs": [ 0.7377, 0.40692, 1, 0.75237, 1, 1, 0.62046, 1, 0.26184, 0.56601, 0, 0.29783, 0, 0, 0.44115, 0 ], + "triangles": [ 5, 6, 7, 4, 5, 7, 4, 7, 0, 3, 4, 0, 3, 0, 1, 3, 1, 2 ], + "vertices": [ 15.18, 5.74, 32.17, 5.32, 41.79, 0.21, 36.63, -9.5, 14.88, -9.72, 0.9, -10.89, -10.66, -4.74, -4.66, 6.54 ], + "edges": [ 12, 14, 14, 0, 4, 2, 0, 2, 4, 6, 6, 8, 10, 12, 8, 10 ], + "hull": 8, + "width": 29, + "height": 44 + } + }, + "left upper leg": { + "left upper leg": { + "name": "goblin/left-upper-leg", + "type": "mesh", + "uvs": [ 1, 0.12167, 1, 0.54873, 0.91067, 0.78907, 0.76567, 1, 0.3087, 0.9579, 0, 0.68777, 0, 0.219, 0.51961, 0, 0.87552, 0 ], + "triangles": [ 7, 8, 0, 5, 6, 7, 0, 1, 7, 4, 5, 7, 1, 4, 7, 2, 4, 1, 3, 4, 2 ], + "vertices": [ 2.33, 13.06, 33.5, 12.57, 51, 9.34, 66.32, 4.31, 63, -10.71, 43.13, -20.58, 8.91, -20.04, -6.79, -2.64, -6.61, 9.1 ], + "edges": [ 10, 8, 8, 6, 6, 4, 4, 2, 10, 12, 12, 14, 14, 16, 2, 0, 16, 0 ], + "hull": 9, + "width": 33, + "height": 73 + } + }, + "neck": { + "neck": { + "name": "goblin/neck", + "type": "mesh", + "uvs": [ 0.81967, 0.27365, 0.92101, 0.82048, 0.47134, 1, 0.15679, 0.9354, 0, 0.7556, 0.19268, 0.51833, 0.15468, 0.35706, 0, 0.21989, 0.13568, 0, 0.68878, 0, 0.70145, 0.53872 ], + "triangles": [ 6, 8, 9, 6, 9, 0, 7, 8, 6, 10, 5, 6, 0, 10, 6, 10, 0, 1, 3, 4, 5, 2, 5, 10, 2, 10, 1, 3, 5, 2 ], + "vertices": [ 18.62, -11.65, -3.98, -13.85, -10.28, 2.76, -6.91, 13.89, 0.8, 19.05, 10.06, 11.51, 16.74, 12.45, 22.71, 17.64, 31.4, 12.19, 30.12, -7.67, 8.05, -6.71 ], + "edges": [ 14, 12, 12, 10, 10, 8, 8, 6, 6, 4, 4, 2, 2, 20, 20, 0, 0, 18, 16, 18, 14, 16, 0, 2 ], + "hull": 10, + "width": 36, + "height": 41 + } + }, + "pelvis": { + "pelvis": { + "name": "goblin/pelvis", + "type": "mesh", + "uvs": [ 1, 1, 0, 1, 0, 0, 1, 0 ], + "triangles": [ 1, 2, 3, 1, 3, 0 ], + "vertices": [ 25.38, -20.73, -36.61, -20.73, -36.61, 22.26, 25.38, 22.26 ], + "edges": [ 0, 2, 2, 4, 4, 6, 0, 6 ], + "hull": 4, + "width": 62, + "height": 43 + } + }, + "right arm": { + "right arm": { + "name": "goblin/right-arm", + "type": "mesh", + "uvs": [ 1, 0.09223, 1, 0.8501, 0.72058, 1, 0.24384, 1, 0, 0.86558, 0.20822, 0.10919, 0.50903, 0, 0.85342, 0 ], + "triangles": [ 6, 7, 0, 2, 3, 5, 4, 5, 3, 1, 6, 0, 6, 2, 5, 1, 2, 6 ], + "vertices": [ -4.75, 8.89, 33.03, 11.74, 40.99, 5.89, 41.81, -5.03, 35.53, -11.13, -2.53, -9.2, -8.5, -2.71, -9.09, 5.18 ], + "edges": [ 8, 6, 4, 6, 4, 2, 12, 14, 2, 0, 14, 0, 10, 12, 8, 10 ], + "hull": 8, + "width": 23, + "height": 50 + } + }, + "right foot": { + "right foot": { + "name": "goblin/right-foot", + "type": "mesh", + "uvs": [ 0.40851, 0.0047, 0.59087, 0.33404, 0.75959, 0.48311, 0.88907, 0.59751, 0.97532, 0.89391, 0.90385, 1, 0.6722, 1, 0.38633, 1, 0.08074, 1, 0, 0.88921, 0, 0.65984, 0, 0.46577, 0.0906, 0.0988, 0.305, 0, 0.47461, 0.71257, 0.715, 0.74681 ], + "triangles": [ 1, 10, 11, 1, 13, 0, 14, 1, 2, 1, 12, 13, 12, 1, 11, 14, 10, 1, 15, 14, 2, 15, 2, 3, 9, 10, 14, 15, 3, 4, 7, 8, 9, 14, 7, 9, 6, 14, 15, 5, 6, 15, 7, 14, 6, 4, 5, 15 ], + "vertices": [ 17.36, 25.99, 29.13, 15.44, 39.89, 10.8, 48.14, 7.24, 53.84, -2.38, 49.43, -6, 34.84, -6.39, 16.84, -6.87, -2.4, -7.38, -7.58, -3.86, -7.78, 3.7, -7.95, 10.1, -2.57, 22.36, 10.84, 25.97, 22.14, 2.75, 37.31, 2.03 ], + "edges": [ 0, 2, 6, 8, 8, 10, 16, 18, 22, 24, 24, 26, 0, 26, 10, 12, 2, 4, 4, 6, 12, 14, 14, 16, 18, 20, 20, 22, 2, 28, 28, 14, 20, 28, 4, 30, 30, 12, 28, 30, 30, 8 ], + "hull": 14, + "width": 63, + "height": 33 + } + }, + "right hand": { + "right hand": { + "name": "goblin/right-hand", + "type": "mesh", + "uvs": [ 0.17957, 0, 0, 0.44772, 0, 0.79734, 0.20057, 0.94264, 0.55057, 1, 0.8539, 1, 0.89823, 0.82004, 0.8259, 0.74285, 0.84223, 0.49993, 0.96356, 0.34102, 0.66023, 0 ], + "triangles": [ 8, 10, 9, 0, 10, 1, 8, 2, 1, 8, 1, 10, 7, 3, 8, 3, 2, 8, 4, 3, 7, 5, 7, 6, 4, 7, 5 ], + "vertices": [ -10.82, -9.45, 5.95, -15.34, 18.88, -14.9, 24, -7.5, 25.69, 5.16, 25.31, 16.07, 18.61, 17.44, 15.84, 14.74, 6.84, 15.02, 0.81, 19.18, -11.41, 7.83 ], + "edges": [ 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 0, 20 ], + "hull": 11, + "width": 36, + "height": 37 + } + }, + "right hand thumb": { + "right hand thumb": { + "name": "goblin/right-hand", + "type": "mesh", + "uvs": [ 0.88538, 0.22262, 0.76167, 0.3594, 0.75088, 0.78308, 0.95326, 0.84981, 1, 0.60302 ], + "triangles": [ 1, 0, 4, 2, 1, 4, 3, 2, 4 ], + "vertices": [ -2.82, 15.97, 2.4, 11.71, 18.08, 11.9, 20.27, 19.27, 11.09, 20.62 ], + "edges": [ 2, 4, 4, 6, 6, 8, 2, 0, 0, 8 ], + "hull": 5, + "width": 36, + "height": 37 + } + }, + "right lower leg": { + "right lower leg": { + "name": "goblin/right-lower-leg", + "type": "mesh", + "uvs": [ 1, 0.27261, 0.81312, 0.52592, 0.79587, 0.71795, 0.95544, 0.80988, 0.85193, 0.95493, 0.47241, 1, 0.14033, 1, 0, 0.8773, 0.14896, 0.67914, 0.1619, 0.30325, 0.60611, 0 ], + "triangles": [ 1, 10, 0, 9, 10, 1, 8, 9, 1, 2, 8, 1, 4, 2, 3, 6, 7, 8, 5, 6, 8, 2, 5, 8, 4, 5, 2 ], + "vertices": [ 6.26, 8.46, 23.32, 8.04, 37.1, 12.89, 41.45, 20.82, 53.07, 21.46, 61.33, 10.06, 65.77, -1.03, 58.99, -9.19, 43.02, -9.81, 16.33, -20, -12.79, -9.26 ], + "edges": [ 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 0, 20, 18, 20 ], + "hull": 11, + "width": 36, + "height": 76 + } + }, + "right shoulder": { + "right shoulder": { + "name": "goblin/right-shoulder", + "type": "mesh", + "uvs": [ 0.62008, 0.03708, 0.92131, 0.09048, 1, 0.38319, 0.72049, 0.6937, 0.31656, 1, 0, 1, 0, 0.75106, 0.28233, 0.49988 ], + "triangles": [ 2, 3, 0, 2, 0, 1, 7, 0, 3, 4, 5, 6, 4, 7, 3, 4, 6, 7 ], + "vertices": [ -3.17, -11.05, -9, -0.57, -1.01, 10.33, 16.69, 11.17, 37.41, 8.2, 45.45, -1.16, 36.95, -8.46, 21.2, -7.47 ], + "edges": [ 10, 12, 12, 14, 14, 0, 0, 2, 2, 4, 4, 6, 8, 10, 6, 8 ], + "hull": 8, + "width": 39, + "height": 45 + } + }, + "right upper leg": { + "right upper leg": { + "name": "goblin/right-upper-leg", + "type": "mesh", + "uvs": [ 0.27018, 0, 0.11618, 0.18177, 0, 0.70688, 0, 0.89577, 0.26668, 1, 0.48718, 1, 0.67618, 0.83532, 1, 0.5161, 1, 0.25543, 0.74618, 0.0571 ], + "triangles": [ 9, 8, 7, 9, 1, 0, 6, 9, 7, 6, 1, 9, 2, 1, 6, 4, 3, 2, 6, 4, 2, 5, 4, 6 ], + "vertices": [ -9.85, -10.37, 2.17, -14.07, 35.49, -13.66, 47.29, -12.11, 52.61, -2.26, 51.63, 5.16, 40.51, 10.18, 19.13, 18.47, 2.85, 16.32, -8.4, 6.14 ], + "edges": [ 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 0, 18 ], + "hull": 10, + "width": 34, + "height": 63 + } + }, + "torso": { + "torso": { + "name": "goblin/torso", + "type": "mesh", + "uvs": [ 0, 0.33287, 0.15945, 0.46488, 0.15761, 0.60314, 0.15502, 0.79806, 0.32807, 0.93478, 0.6875, 1, 0.80731, 1, 1, 0.77763, 1, 0.66147, 1, 0.56703, 0.93207, 0.4771, 0.86944, 0.39416, 0.83837, 0.226, 0.68085, 0, 0.14836, 0, 0, 0.07199, 0.78734, 0.86249, 0.43679, 0.79649, 0.76738, 0.61733, 0.44345, 0.58747, 0.54329, 0.38316, 0.77692, 0.73446, 0.66478, 0.51012 ], + "triangles": [ 0, 15, 14, 20, 14, 13, 20, 13, 12, 1, 0, 14, 20, 12, 11, 20, 1, 14, 22, 20, 11, 22, 11, 10, 19, 1, 20, 19, 20, 22, 2, 1, 19, 18, 22, 10, 18, 10, 9, 19, 22, 18, 18, 9, 8, 21, 18, 8, 21, 8, 7, 17, 2, 19, 21, 17, 19, 21, 19, 18, 3, 2, 17, 16, 21, 7, 17, 21, 16, 4, 3, 17, 5, 17, 16, 4, 17, 5, 6, 16, 7, 5, 16, 6 ], + "vertices": [ 56.93, 27.95, 43.37, 18.23, 30.16, 19.5, 11.53, 21.28, -2.55, 10.69, -10.89, -13.12, -11.59, -21.23, 8.54, -36.12, 19.65, -37.08, 28.68, -37.86, 37.68, -34, 45.98, -30.44, 56.4, -29.07, 84.78, -20.92, 87.9, 15.15, 81.88, 25.79, 1.67, -21.01, 10.03, 2.18, 25.23, -18.25, 29.98, 0, 48.54, -8.39, 13.98, -21.36, 35.9, -15.6 ], + "edges": [ 0, 2, 6, 8, 8, 10, 10, 12, 12, 14, 22, 24, 24, 26, 26, 28, 28, 30, 0, 30, 14, 32, 32, 34, 34, 6, 18, 36, 36, 38, 2, 4, 4, 6, 38, 4, 2, 40, 40, 22, 40, 38, 38, 34, 32, 10, 34, 8, 40, 28, 14, 16, 16, 18, 32, 42, 42, 36, 16, 42, 42, 34, 18, 20, 20, 22, 36, 44, 44, 40, 20, 44 ], + "hull": 16, + "width": 68, + "height": 96 + } + }, + "undie straps": { + "undie straps": { + "name": "goblin/undie-straps", + "type": "mesh", + "uvs": [ 0.36097, 0.44959, 0.66297, 0.60591, 1, 0.19486, 1, 0.57117, 0.75897, 1, 0.38697, 1, 0, 0.26433, 0, 0, 0.12497, 0 ], + "triangles": [ 6, 7, 8, 6, 8, 0, 3, 1, 2, 5, 0, 1, 6, 0, 5, 4, 1, 3, 5, 1, 4 ], + "vertices": [ -10.56, 12.87, 6.53, 9.9, 25.62, 17.71, 25.62, 10.56, 11.97, 2.41, -9.09, 2.41, -31, 16.39, -31, 21.41, -23.92, 21.41 ], + "edges": [ 14, 16, 16, 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 12, 14, 10, 12, 0, 10, 2, 8 ], + "hull": 9, + "width": 55, + "height": 19 + } + }, + "undies": { + "undies": { + "name": "goblin/undies", + "type": "mesh", + "uvs": [ 0, 0.32029, 0.14893, 0.59457, 0.22437, 1, 0.35909, 1, 0.50998, 1, 0.79559, 0.58453, 0.9842, 0.28015, 1, 0.00588, 0.46957, 0.17646, 0, 0.03933, 0.48843, 0.59122, 0.48114, 0.43099 ], + "triangles": [ 6, 8, 7, 0, 9, 8, 11, 8, 6, 0, 8, 11, 5, 11, 6, 10, 11, 5, 1, 0, 11, 1, 11, 10, 3, 2, 1, 10, 3, 1, 4, 10, 5, 3, 10, 4 ], + "vertices": [ -13.22, 5.56, -8, -2.47, -5.49, -14.27, -0.64, -14.36, 4.78, -14.45, 15.27, -2.59, 22.22, 6.11, 22.92, 14.05, 3.75, 9.44, -13.08, 13.71, 4.21, -2.59, 4.03, 2.05 ], + "edges": [ 0, 2, 2, 4, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 0, 18, 4, 6, 6, 8, 6, 20, 16, 22, 22, 20, 0, 22, 22, 12, 2, 20, 20, 10 ], + "hull": 10, + "width": 36, + "height": 29 + } + } + }, + "goblingirl": { + "eyes": { + "eyes closed": { "name": "goblingirl/eyes-closed", "x": 28, "y": -25.54, "rotation": -87.04, "width": 37, "height": 21 } + }, + "head": { + "head": { "name": "goblingirl/head", "x": 27.71, "y": -4.32, "rotation": -85.58, "width": 103, "height": 81 } + }, + "left arm": { + "left arm": { "name": "goblingirl/left-arm", "x": 19.64, "y": -2.42, "rotation": 33.05, "width": 37, "height": 35 } + }, + "left foot": { + "left foot": { "name": "goblingirl/left-foot", "x": 25.17, "y": 7.92, "rotation": 3.32, "width": 65, "height": 31 } + }, + "left hand": { + "left hand": { + "name": "goblingirl/left-hand", + "x": 4.34, + "y": 2.39, + "scaleX": 0.896, + "scaleY": 0.896, + "rotation": 30.34, + "width": 35, + "height": 40 + } + }, + "left lower leg": { + "left lower leg": { "name": "goblingirl/left-lower-leg", "x": 25.02, "y": -0.6, "rotation": 105.75, "width": 33, "height": 70 } + }, + "left shoulder": { + "left shoulder": { "name": "goblingirl/left-shoulder", "x": 19.8, "y": -0.42, "rotation": 61.21, "width": 28, "height": 46 } + }, + "left upper leg": { + "left upper leg": { "name": "goblingirl/left-upper-leg", "x": 30.21, "y": -2.95, "rotation": 89.09, "width": 33, "height": 70 } + }, + "neck": { + "neck": { "name": "goblingirl/neck", "x": 6.16, "y": -3.14, "rotation": -98.86, "width": 35, "height": 41 } + }, + "pelvis": { + "pelvis": { "name": "goblingirl/pelvis", "x": -3.87, "y": 3.18, "width": 62, "height": 43 } + }, + "right arm": { + "right arm": { "name": "goblingirl/right-arm", "x": 16.85, "y": -0.66, "rotation": 93.52, "width": 28, "height": 50 } + }, + "right foot": { + "right foot": { "name": "goblingirl/right-foot", "x": 23.46, "y": 9.66, "rotation": 1.52, "width": 63, "height": 33 } + }, + "right hand": { + "right hand": { "name": "goblingirl/right-hand", "x": 7.21, "y": 3.43, "rotation": 91.16, "width": 36, "height": 37 } + }, + "right hand thumb": { + "right hand thumb": { "name": "goblingirl/right-hand", "x": 7.21, "y": 3.43, "rotation": 91.16, "width": 36, "height": 37 } + }, + "right lower leg": { + "right lower leg": { "name": "goblingirl/right-lower-leg", "x": 26.15, "y": -3.27, "rotation": 111.83, "width": 36, "height": 76 } + }, + "right shoulder": { + "right shoulder": { "name": "goblingirl/right-shoulder", "x": 14.46, "y": 0.45, "rotation": 129.85, "width": 39, "height": 45 } + }, + "right upper leg": { + "right upper leg": { "name": "goblingirl/right-upper-leg", "x": 19.69, "y": 2.13, "rotation": 97.49, "width": 34, "height": 63 } + }, + "torso": { + "torso": { "name": "goblingirl/torso", "x": 36.28, "y": -5.14, "rotation": -95.74, "width": 68, "height": 96 } + }, + "undie straps": { + "undie straps": { "name": "goblingirl/undie-straps", "x": -1.51, "y": 14.18, "width": 55, "height": 19 } + }, + "undies": { + "undies": { "name": "goblingirl/undies", "x": 5.4, "y": 1.7, "width": 36, "height": 29 } + } + } +}, +"animations": { + "walk": { + "slots": { + "eyes": { + "attachment": [ + { "time": 0.7, "name": "eyes closed" }, + { "time": 0.8, "name": null } + ] + } + }, + "bones": { + "left upper leg": { + "rotate": [ + { "time": 0, "angle": -26.55 }, + { "time": 0.1333, "angle": -8.78 }, + { "time": 0.2333, "angle": 9.51 }, + { "time": 0.3666, "angle": 30.74 }, + { "time": 0.5, "angle": 25.33 }, + { "time": 0.6333, "angle": 26.11 }, + { "time": 0.7333, "angle": 7.45 }, + { "time": 0.8666, "angle": -21.19 }, + { "time": 1, "angle": -26.55 } + ], + "translate": [ + { "time": 0, "x": -1.32, "y": 1.7 }, + { "time": 0.3666, "x": -0.06, "y": 2.42 }, + { "time": 1, "x": -1.32, "y": 1.7 } + ] + }, + "right upper leg": { + "rotate": [ + { "time": 0, "angle": 42.45 }, + { + "time": 0.1333, + "angle": 49.86, + "curve": [ 0.414, 0, 0.705, 0.99 ] + }, + { "time": 0.2333, "angle": 22.51 }, + { "time": 0.5, "angle": -16.93 }, + { "time": 0.6333, "angle": 1.89 }, + { + "time": 0.7333, + "angle": 34.86, + "curve": [ 0.462, 0.11, 1, 1 ] + }, + { + "time": 0.8666, + "angle": 58.68, + "curve": [ 0.5, 0.02, 1, 1 ] + }, + { "time": 1, "angle": 42.45 } + ], + "translate": [ + { "time": 0, "x": 6.23, "y": 0 }, + { "time": 0.2333, "x": 2.14, "y": 2.4 }, + { "time": 0.5, "x": 2.44, "y": 4.8 }, + { "time": 1, "x": 6.23, "y": 0 } + ] + }, + "left lower leg": { + "rotate": [ + { "time": 0, "angle": -18.05 }, + { "time": 0.1333, "angle": -63.5 }, + { "time": 0.2333, "angle": -83.01 }, + { "time": 0.5, "angle": 5.11 }, + { "time": 0.6333, "angle": -28.29 }, + { "time": 0.7333, "angle": -27.52 }, + { "time": 0.8666, "angle": 3.53 }, + { "time": 1, "angle": -18.05 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 }, + { "time": 0.2333, "x": 2.55, "y": -0.47 }, + { "time": 0.5, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 1, "x": 0, "y": 0 } + ] + }, + "left foot": { + "rotate": [ + { "time": 0, "angle": -14.56 }, + { "time": 0.1333, "angle": -10.42 }, + { "time": 0.2333, "angle": -5.01 }, + { "time": 0.3, "angle": 6.67 }, + { "time": 0.3666, "angle": 3.87 }, + { "time": 0.5, "angle": -3.87 }, + { "time": 0.6333, "angle": 2.78 }, + { "time": 0.7333, "angle": -11.99 }, + { "time": 0.8666, "angle": -12.45 }, + { "time": 1, "angle": -14.56 } + ] + }, + "right shoulder": { + "rotate": [ + { + "time": 0, + "angle": 5.29, + "curve": [ 0.264, 0, 0.75, 1 ] + }, + { "time": 0.6333, "angle": 6.65 }, + { "time": 1, "angle": 5.29 } + ] + }, + "right arm": { + "rotate": [ + { + "time": 0, + "angle": -4.02, + "curve": [ 0.267, 0, 0.804, 0.99 ] + }, + { + "time": 0.6333, + "angle": 19.78, + "curve": [ 0.307, 0, 0.787, 0.99 ] + }, + { "time": 1, "angle": -4.02 } + ] + }, + "right hand": { + "rotate": [ + { "time": 0, "angle": 8.98 }, + { "time": 0.6333, "angle": 0.51 }, + { "time": 1, "angle": 8.98 } + ] + }, + "left shoulder": { + "rotate": [ + { + "time": 0, + "angle": 6.25, + "curve": [ 0.339, 0, 0.683, 1 ] + }, + { + "time": 0.5, + "angle": -11.78, + "curve": [ 0.281, 0, 0.686, 0.99 ] + }, + { "time": 1, "angle": 6.25 } + ], + "translate": [ + { "time": 0, "x": 1.15, "y": 0.23 } + ] + }, + "left hand": { + "rotate": [ + { + "time": 0, + "angle": -21.23, + "curve": [ 0.295, 0, 0.755, 0.98 ] + }, + { + "time": 0.5, + "angle": -27.28, + "curve": [ 0.241, 0, 0.75, 0.97 ] + }, + { "time": 1, "angle": -21.23 } + ] + }, + "left arm": { + "rotate": [ + { + "time": 0, + "angle": 28.37, + "curve": [ 0.339, 0, 0.683, 1 ] + }, + { + "time": 0.5, + "angle": 60.09, + "curve": [ 0.281, 0, 0.686, 0.99 ] + }, + { "time": 1, "angle": 28.37 } + ] + }, + "torso": { + "rotate": [ + { "time": 0, "angle": -10.28 }, + { + "time": 0.1333, + "angle": -15.38, + "curve": [ 0.545, 0, 0.818, 1 ] + }, + { + "time": 0.3666, + "angle": -9.78, + "curve": [ 0.58, 0.17, 0.669, 0.99 ] + }, + { + "time": 0.6333, + "angle": -15.75, + "curve": [ 0.235, 0.01, 0.795, 1 ] + }, + { + "time": 0.8666, + "angle": -7.06, + "curve": [ 0.209, 0, 0.816, 0.98 ] + }, + { "time": 1, "angle": -10.28 } + ], + "translate": [ + { "time": 0, "x": -3.72, "y": -0.01 } + ] + }, + "right foot": { + "rotate": [ + { "time": 0, "angle": -5.25 }, + { "time": 0.2333, "angle": -17.76 }, + { "time": 0.3666, "angle": -20.09 }, + { "time": 0.5, "angle": -19.73 }, + { "time": 0.7333, "angle": -11.68 }, + { "time": 0.8, "angle": 4.46 }, + { "time": 0.8666, "angle": 0.46 }, + { "time": 1, "angle": -5.25 } + ] + }, + "right lower leg": { + "rotate": [ + { + "time": 0, + "angle": -3.39, + "curve": [ 0.316, 0.01, 0.741, 0.98 ] + }, + { + "time": 0.1333, + "angle": -43.21, + "curve": [ 0.414, 0, 0.705, 0.99 ] + }, + { "time": 0.2333, "angle": -25.98 }, + { "time": 0.5, "angle": -19.53 }, + { "time": 0.6333, "angle": -64.8 }, + { + "time": 0.7333, + "angle": -89.54, + "curve": [ 0.557, 0.18, 1, 1 ] + }, + { "time": 1, "angle": -3.39 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.5, "x": 0, "y": 0 }, + { "time": 0.6333, "x": 2.18, "y": 0.21 }, + { "time": 1, "x": 0, "y": 0 } + ] + }, + "hip": { + "rotate": [ + { "time": 0, "angle": 0, "curve": "stepped" }, + { "time": 1, "angle": 0 } + ], + "translate": [ + { "time": 0, "x": 0, "y": -8.4 }, + { + "time": 0.1333, + "x": 0, + "y": -9.35, + "curve": [ 0.326, 0.05, 0.674, 0.93 ] + }, + { + "time": 0.2333, + "x": 0, + "y": -0.59, + "curve": [ 0.325, 0.39, 0.643, 0.7 ] + }, + { "time": 0.3666, "x": 0, "y": -3.96 }, + { "time": 0.5, "x": 0, "y": -8.4 }, + { + "time": 0.6333, + "x": 0, + "y": -10, + "curve": [ 0.359, 0.47, 0.646, 0.74 ] + }, + { + "time": 0.7333, + "x": 0, + "y": -5.29, + "curve": [ 0.333, 0.36, 0.662, 0.69 ] + }, + { + "time": 0.8, + "x": 0, + "y": -2.49, + "curve": [ 0.322, 0.35, 0.651, 0.68 ] + }, + { "time": 0.8666, "x": 0, "y": -3.96 }, + { "time": 1, "x": 0, "y": -8.4 } + ] + }, + "neck": { + "rotate": [ + { "time": 0, "angle": 3.6 }, + { "time": 0.1333, "angle": 17.49 }, + { "time": 0.2333, "angle": 6.1 }, + { "time": 0.3666, "angle": 3.45 }, + { "time": 0.5, "angle": 5.17 }, + { "time": 0.6333, "angle": 18.36 }, + { "time": 0.7333, "angle": 6.09 }, + { "time": 0.8666, "angle": 2.28 }, + { "time": 1, "angle": 3.6 } + ] + }, + "head": { + "rotate": [ + { + "time": 0, + "angle": 3.6, + "curve": [ 0, 0, 0.704, 1.17 ] + }, + { "time": 0.1333, "angle": -0.2 }, + { "time": 0.2333, "angle": 6.1 }, + { "time": 0.3666, "angle": 3.45 }, + { + "time": 0.5, + "angle": 5.17, + "curve": [ 0, 0, 0.704, 1.61 ] + }, + { "time": 0.6666, "angle": 1.1 }, + { "time": 0.7333, "angle": 6.09 }, + { "time": 0.8666, "angle": 2.28 }, + { "time": 1, "angle": 3.6 } + ] + }, + "pelvis": { + "rotate": [ + { "time": 0, "angle": -1.33 } + ], + "translate": [ + { "time": 0, "x": 0.39, "y": -0.78 } + ] + }, + "spear1": { + "rotate": [ + { "time": 0, "angle": 1.84 }, + { "time": 0.2, "angle": -5.38 }, + { "time": 0.5, "angle": 2.95 }, + { "time": 0.7333, "angle": -3.67 }, + { "time": 1, "angle": 1.84 } + ] + }, + "spear2": { + "rotate": [ + { "time": 0, "angle": 1.84 }, + { "time": 0.2, "angle": -5.38 }, + { "time": 0.5, "angle": 2.95 }, + { "time": 0.7333, "angle": -3.67 }, + { "time": 1, "angle": 1.84 } + ] + }, + "spear3": { + "rotate": [ + { "time": 0, "angle": 3.64 }, + { "time": 0.2, "angle": -3.59 }, + { "time": 0.5, "angle": 4.74 }, + { "time": 0.7333, "angle": -1.87 }, + { "time": 1, "angle": 3.64 } + ] + } + }, + "ffd": { + "default": { + "left hand item": { + "spear": [ + { "time": 0 } + ] + }, + "right hand item": { + "dagger": [ + { + "time": 0, + "offset": 26, + "vertices": [ 2.34, 0.14 ], + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { + "time": 0.5, + "offset": 8, + "vertices": [ -1.19, 4.31, 0.07, 6.41, 1.66, 6.18, 1.75, 3.59 ], + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { + "time": 1, + "offset": 26, + "vertices": [ 2.34, 0.14 ] + } + ] + } + }, + "goblin": { + "head": { + "head": [ + { + "time": 0, + "curve": [ 0.632, 0, 0.75, 1 ] + }, + { + "time": 0.2, + "vertices": [ -10.97, -6.68, -4.68, -2.46, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1.08, 0.08, -1.08, 0.08, -1.08, 0.08, 0, 0, -2.22, 2.66, -4.83, 2.7, -5.7, -0.51, -3.15, -1.61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -6.64, 0.81, -11.82, -1.34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1.08, 0.08 ], + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { + "time": 0.3666, + "vertices": [ 10.69, 4.05, 3.66, 1.85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.47, 0.09, 1.47, 0.09, 1.47, 0.09, 0, 0, 2.69, -0.22, 3.77, 0.11, 3.68, 1.55, 2.49, 1.65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4.45, -3.91, 9.19, -1.66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.47, 0.09 ], + "curve": [ 0.621, 0, 0.75, 1 ] + }, + { + "time": 0.7, + "vertices": [ -10.97, -6.68, -4.68, -2.46, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1.17, -0.17, -1.17, -0.17, -1.17, -0.17, 0, 0, -2.22, 2.66, -4.83, 2.7, -5.7, -0.51, -3.15, -1.61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -6.64, 0.81, -11.82, -1.34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1.17, -0.17 ], + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { + "time": 0.8666, + "vertices": [ 10.69, 4.05, 3.66, 1.85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.38, 0.08, 0.38, 0.08, 0.38, 0.08, 0, 0, 2.69, -0.22, 3.77, 0.11, 3.68, 1.55, 2.49, 1.65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4.45, -3.91, 9.19, -1.66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.38, 0.08 ], + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { "time": 1 } + ] + }, + "left foot": { + "left foot": [ + { + "time": 0, + "offset": 8, + "vertices": [ 3.69, 2.37, -7.16, 18.79, -12.78, 14.77, -12.75, 6.5, -3.13, 1.98, -0.44, 0.36, 0, 0, -3.8, 2.98 ] + }, + { "time": 0.1333 }, + { + "time": 0.2333, + "offset": 8, + "vertices": [ -3.96, -2.34, -5.8, -12.47, -2.23, -12.99, 2.02, -9.1, 0, 0, 0, 0, 0, 0, -1.35, -5.28 ] + }, + { + "time": 0.3666, + "offset": 8, + "vertices": [ 0.66, 0.33, 0.33, 2.69, -0.48, 2.54, -1.13, 1.38, 0, 0, 0, 0, 0, 0, -0.11, 0.79 ] + }, + { "time": 0.5, "curve": "stepped" }, + { "time": 0.6333 }, + { + "time": 0.7333, + "offset": 8, + "vertices": [ -2.97, 9.4, -6.91, 19.92, -10.55, 18.41, -12.37, 12.38, -4.72, 6.3, 0, 0, -1.48, 4.88, -7.06, 10.7 ] + }, + { + "time": 0.8333, + "offset": 6, + "vertices": [ 1.05, 1.56, -2.52, 7.99, -5.52, 17.14, -8.93, 15.79, -10.73, 10.22, -4.23, 5.36, 0, 0, 0, 0, -5.83, 8.55 ] + }, + { + "time": 1, + "offset": 8, + "vertices": [ 3.69, 2.37, -7.16, 18.79, -12.78, 14.77, -12.75, 6.5, -3.13, 1.98, -0.44, 0.36, 0, 0, -3.8, 2.98 ] + } + ] + }, + "pelvis": { + "pelvis": [ + { "time": 0 }, + { + "time": 0.1333, + "offset": 6, + "vertices": [ -0.68, -4.13 ] + }, + { + "time": 0.3333, + "offset": 6, + "vertices": [ -1.04, -3.1 ] + }, + { + "time": 0.7, + "offset": 6, + "vertices": [ -1.42, -6.3 ] + }, + { + "time": 0.8666, + "offset": 6, + "vertices": [ -1.13, -1.79 ] + }, + { "time": 1 } + ] + }, + "right foot": { + "right foot": [ + { "time": 0 }, + { + "time": 0.1333, + "offset": 2, + "vertices": [ -2.81, 2.63, -2.35, 3.89, -1.99, 4.86, -0.93, 5.57, -0.48, 5.09, -0.34, 3.42, -0.17, 1.36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1.31, 1.91, -1.32, 3.65 ] + }, + { + "time": 0.2333, + "offset": 2, + "vertices": [ -6.39, 6.41, -7.74, 8.27, -7.02, 11.35, -4.03, 13.93, -2.5, 12.62, -1.46, 7.58, -0.17, 1.36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3.84, 2.61, -4.53, 7.92 ] + }, + { + "time": 0.3, + "offset": 2, + "vertices": [ -8.27, 6.68, -9.29, 10.13, -8.62, 14.71, -4.58, 18.81, -2.2, 17.1, -0.07, 9.9, 2.54, 1.01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2.94, 2.38, -4.59, 10.01 ] + }, + { + "time": 0.3666, + "offset": 2, + "vertices": [ -10.47, 9.44, -13.36, 12.4, -14.32, 16.94, -9.24, 23.55, -5.51, 21.51, -1.19, 11.53, 2.54, 1.01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4.14, 2.29, -6.63, 11.37 ] + }, + { + "time": 0.5, + "offset": 2, + "vertices": [ -5.42, 4.36, -10.59, 7.04, -11.64, 11.55, -6.19, 20.12, -1.45, 18.05, 4.86, 6.41, 2.81, 0.27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2.96, 4.94 ] + }, + { "time": 0.6333 }, + { + "time": 0.7333, + "offset": 4, + "vertices": [ 1.31, -6.84, -0.87, -12.54, -5.98, -14.08, -7.15, -11.63, -5.67, -4.83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2.06, -6.93 ] + }, + { + "time": 0.8, + "offset": 4, + "vertices": [ 0.65, -3.42, -0.43, -6.27, -2.99, -7.04, -3.57, -5.81, -2.83, -2.41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.79, -1.28, 0, 0, 0, 0, -1.03, -3.46 ] + }, + { "time": 0.8666 } + ] + }, + "right hand": { + "right hand": [ + { + "time": 0, + "offset": 4, + "vertices": [ -1.48, 0.34, 0, 0, 1.31, 0.08, 1.6, 0.09, 0.13, 0.15, 0, 0, 0, 0, -0.72, -0.04 ] + }, + { "time": 0.5 }, + { + "time": 1, + "offset": 4, + "vertices": [ -1.48, 0.34, 0, 0, 1.31, 0.08, 1.6, 0.09, 0.13, 0.15, 0, 0, 0, 0, -0.72, -0.04 ] + } + ] + }, + "right lower leg": { + "right lower leg": [ + { "time": 0 }, + { + "time": 0.6, + "offset": 6, + "vertices": [ 1.8, -1.56 ] + }, + { "time": 1 } + ] + }, + "right upper leg": { + "right upper leg": [ + { + "time": 0, + "vertices": [ -6.03, -1.46, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.34, -1.93, -1.86, -5.05, -2.5, -3.09 ] + }, + { "time": 0.3333 }, + { + "time": 0.8666, + "offset": 14, + "vertices": [ 0.13, -2.35, -1.33, -5.99, -1.35, -4.43 ] + }, + { + "time": 1, + "vertices": [ -6.03, -1.46, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.34, -1.93, -1.86, -5.05, -2.5, -3.09 ] + } + ] + }, + "torso": { + "torso": [ + { + "time": 0, + "offset": 14, + "vertices": [ -1.48, -0.24, -2.72, -2.15, -0.51, -3.39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.09, -2.61, 0, 0, 0.57, -1.24, 0, 0, 0, 0, -2.11, -3.29 ] + }, + { + "time": 0.1333, + "offset": 14, + "vertices": [ 1.31, -0.59, -0.97, -1.62, 0.74, -0.61, -1.44, 1.97, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.65, -3.95, 0, 0, -1.46, -0.31, 0, 0, 0, 0, -3.31, -3.55, -2.56, 0.29 ] + }, + { + "time": 0.3, + "offset": 14, + "vertices": [ 6.03, -3.13, 7.55, -1.38, 6.79, 0.31, 4.23, 1.14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4.07, -5.16, 0, 0, 4, 0.27, 0, 0, 0, 0, 3.43, -3.52 ] + }, + { + "time": 0.5, + "offset": 14, + "vertices": [ 2.25, -0.87, 2.57, -0.56, 3.17, -0.57, 1.48, 0.99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.22, -4.43, 0, 0, 1.48, 0.01, 0, 0, 0, 0, 0.31, -3.28, -1.53, 0.17 ] + }, + { + "time": 0.6333, + "offset": 14, + "vertices": [ 0.75, -1.51, -0.97, -1.62, 0.74, -0.61, -1.44, 1.97, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.65, -3.95, 0, 0, -1.46, -0.31, 0, 0, 0, 0, -3.31, -3.55, -2.56, 0.29 ] + }, + { + "time": 0.8666, + "offset": 14, + "vertices": [ 0.62, -1.26, 0.38, -2.2, 3.25, -0.5, 2.41, 2.39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.66, -3.1, 0, 0, 2.3, -1.15, 0, 0, 0, 0, -0.07, -3.63, -0.93, 0.1 ] + }, + { + "time": 1, + "offset": 14, + "vertices": [ -1.48, -0.24, -2.72, -2.15, -0.51, -3.39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.09, -2.61, 0, 0, 0.57, -1.24, 0, 0, 0, 0, -2.11, -3.29 ] + } + ] + }, + "undie straps": { + "undie straps": [ + { + "time": 0, + "offset": 2, + "vertices": [ -1.77, 0.54, -0.96, -1.03, -0.39, -0.24, -1.77, 0.54 ] + }, + { + "time": 0.1333, + "offset": 2, + "vertices": [ -2.25, -1.03, -1.49, -4.23, -0.74, -2.84, -1.9, 0.54 ] + }, + { + "time": 0.3333, + "offset": 2, + "vertices": [ -2.37, -0.05, -0.49, 0.19, -0.9, 1.16, -1.6, 2.7, 0.96, 0.8 ] + }, + { + "time": 0.7, + "offset": 2, + "vertices": [ -0.91, -2.76, -0.62, -3.63, -0.84, -2.26, -2.56, 0.52 ] + }, + { + "time": 0.8666, + "offset": 2, + "vertices": [ -2.56, 0.52, -1.58, 0.32, -1.38, 0.32, -2.56, 0.52 ] + }, + { + "time": 1, + "offset": 2, + "vertices": [ -1.77, 0.54, -0.8, 0.53, -0.8, 0.53, -1.77, 0.54 ] + } + ] + }, + "undies": { + "undies": [ + { + "time": 0, + "vertices": [ 0.43, 0.72, 10.6, -0.11, 2.29, 0, 2.29, 0, 2.29, 0, 0.58, 0.24, -2.4, -0.65, -2.27, -0.77, 2.29, 0, 0.58, -0.48, 4.98, -0.11, 6.5, -0.23 ] + }, + { + "time": 0.1333, + "vertices": [ 0.72, 0.43, 7.2, -0.16, 1.37, 0, 1.37, 0, 1.37, 0, 1.25, 0.04, -0.99, -2.95, -1.37, -3.07, 1.37, 0, 0.35, -0.29, 2.99, -0.07, 3.9, -0.14 ] + }, + { + "time": 0.3333, + "vertices": [ 1.16, 0, 2.1, -0.23, 0, 0, 0, 0, 0, 0, 2.24, -0.24, -0.43, 0.6, -1.55, 0.48 ] + }, + { + "time": 0.5333, + "vertices": [ 1.16, 0, -0.23, -0.93, -2.92, 0.35, 0, 0, 0, 0, 0.49, -0.24, -0.64, -2.07, -0.64, -2.07 ] + }, + { + "time": 0.7, + "vertices": [ 1.86, -0.11, 4.66, -0.09, -1.76, 0.21, 0, 0, -0.56, 0.32, -1.13, -1.15, -2.19, -3.47, -1.29, -3.47, 0, 0, 0, 0, 1.58, -0.04, 2.65, 0.16 ] + }, + { + "time": 0.8333, + "vertices": [ 2.41, -0.2, 8.58, 0.58, -0.83, 0.1, 0, 0, -1.02, 0.59, -2.44, -1.87, -1.62, 0, 0, 0, 0, 0, 0, 0, 2.85, -0.08, 4.78, 0.3 ] + }, + { + "time": 0.8666, + "vertices": [ 2.01, -0.02, 8.98, 0.44, -0.2, 0.08, 0.45, 0, -0.35, 0.47, -1.84, -1.44, -0.79, 1.26, 0.53, 1.23, 0.45, 0, 0.11, -0.09, 3.28, -0.09, 5.13, 0.19 ] + }, + { + "time": 1, + "vertices": [ 0.43, 0.72, 10.6, -0.11, 2.29, 0, 2.29, 0, 2.29, 0, 0.58, 0.24, -2.4, -0.65, -2.27, -0.77, 2.29, 0, 0.58, -0.48, 4.98, -0.11, 6.5, -0.23 ] + } + ] + } + } + } + } +} +} \ No newline at end of file diff --git a/samples/js-tests/res/skeletons/goblins-ffd.png b/samples/js-tests/res/skeletons/goblins-ffd.png new file mode 100644 index 0000000000..f172361f2b Binary files /dev/null and b/samples/js-tests/res/skeletons/goblins-ffd.png differ diff --git a/samples/js-tests/res/skeletons/spineboy.atlas b/samples/js-tests/res/skeletons/spineboy.atlas index 91d8eebf09..19c0934b10 100644 --- a/samples/js-tests/res/skeletons/spineboy.atlas +++ b/samples/js-tests/res/skeletons/spineboy.atlas @@ -3,164 +3,192 @@ spineboy.png format: RGBA8888 filter: Linear,Linear repeat: none -head - rotate: false - xy: 1, 122 - size: 121, 132 - orig: 121, 132 +eye_indifferent + rotate: true + xy: 389, 5 + size: 56, 53 + orig: 56, 53 offset: 0, 0 index: -1 -torso +eye_surprised rotate: false - xy: 1, 28 - size: 68, 92 - orig: 68, 92 + xy: 580, 34 + size: 56, 53 + orig: 56, 53 offset: 0, 0 index: -1 -left-pant-bottom +front_bracer rotate: false - xy: 1, 4 - size: 44, 22 - orig: 44, 22 + xy: 732, 85 + size: 35, 48 + orig: 35, 48 offset: 0, 0 index: -1 -right-pant-bottom +front_fist_closed rotate: false - xy: 47, 8 - size: 46, 18 - orig: 46, 18 + xy: 556, 91 + size: 45, 49 + orig: 45, 49 offset: 0, 0 index: -1 -right-upper-leg +front_fist_open rotate: false - xy: 71, 50 - size: 44, 70 - orig: 44, 70 + xy: 668, 32 + size: 52, 52 + orig: 52, 52 offset: 0, 0 index: -1 -pelvis +front_foot rotate: false - xy: 95, 1 - size: 63, 47 - orig: 63, 47 + xy: 924, 201 + size: 76, 41 + orig: 76, 41 offset: 0, 0 index: -1 -left-upper-leg +front_foot_bend1 rotate: false - xy: 117, 53 - size: 33, 67 - orig: 33, 67 + xy: 845, 200 + size: 77, 42 + orig: 77, 42 offset: 0, 0 index: -1 -right-foot +front_foot_bend2 rotate: false - xy: 160, 224 - size: 67, 30 - orig: 67, 30 + xy: 778, 186 + size: 65, 56 + orig: 65, 56 offset: 0, 0 index: -1 -left-shoulder - rotate: false - xy: 124, 201 - size: 34, 53 - orig: 34, 53 +front_shin + rotate: true + xy: 444, 91 + size: 49, 110 + orig: 49, 110 offset: 0, 0 index: -1 -left-ankle +front_thigh + rotate: true + xy: 603, 89 + size: 29, 67 + orig: 29, 67 + offset: 0, 0 + index: -1 +front_upper_arm + rotate: true + xy: 672, 86 + size: 32, 58 + orig: 32, 58 + offset: 0, 0 + index: -1 +goggles rotate: false - xy: 229, 222 - size: 25, 32 - orig: 25, 32 + xy: 444, 142 + size: 157, 100 + orig: 157, 100 offset: 0, 0 index: -1 -left-foot +gun rotate: false - xy: 160, 192 - size: 65, 30 - orig: 65, 30 + xy: 603, 120 + size: 126, 122 + orig: 126, 122 offset: 0, 0 index: -1 -neck +head rotate: false - xy: 124, 171 - size: 34, 28 - orig: 34, 28 + xy: 279, 63 + size: 163, 179 + orig: 163, 179 offset: 0, 0 index: -1 -right-arm +mouth_grind rotate: false - xy: 124, 124 - size: 21, 45 - orig: 21, 45 + xy: 845, 163 + size: 56, 35 + orig: 56, 35 offset: 0, 0 index: -1 -right-ankle +mouth_oooo rotate: false - xy: 227, 190 - size: 25, 30 - orig: 25, 30 + xy: 842, 126 + size: 56, 35 + orig: 56, 35 offset: 0, 0 index: -1 -left-hand +mouth_smile rotate: false - xy: 147, 131 - size: 35, 38 - orig: 35, 38 + xy: 769, 97 + size: 56, 35 + orig: 56, 35 offset: 0, 0 index: -1 -left-arm +muzzle rotate: false - xy: 184, 161 - size: 35, 29 - orig: 35, 29 + xy: 2, 2 + size: 275, 240 + orig: 277, 240 offset: 0, 0 index: -1 -eyes-closed +neck rotate: false - xy: 221, 161 - size: 34, 27 - orig: 34, 27 + xy: 903, 173 + size: 22, 25 + orig: 22, 25 offset: 0, 0 index: -1 -right-lower-leg +rear_bracer rotate: false - xy: 152, 65 - size: 51, 64 - orig: 51, 64 + xy: 722, 40 + size: 34, 43 + orig: 34, 43 offset: 0, 0 index: -1 -right-foot-idle +rear_foot rotate: false - xy: 184, 131 - size: 53, 28 - orig: 53, 28 + xy: 444, 11 + size: 68, 36 + orig: 68, 36 offset: 0, 0 index: -1 -left-lower-leg +rear_foot_bend1 rotate: false - xy: 205, 65 - size: 49, 64 - orig: 49, 64 + xy: 444, 49 + size: 70, 40 + orig: 70, 40 offset: 0, 0 index: -1 -right-shoulder +rear_foot_bend2 rotate: false - xy: 160, 12 - size: 52, 51 - orig: 52, 51 + xy: 778, 134 + size: 62, 50 + orig: 62, 50 offset: 0, 0 index: -1 -eyes +rear_shin rotate: false - xy: 214, 36 - size: 34, 27 - orig: 34, 27 + xy: 731, 135 + size: 45, 107 + orig: 45, 107 + offset: 0, 0 + index: -1 +rear_thigh + rotate: true + xy: 516, 50 + size: 39, 62 + orig: 39, 62 offset: 0, 0 index: -1 -right-hand +rear_upper_arm rotate: false - xy: 214, 2 - size: 32, 32 - orig: 32, 32 + xy: 638, 35 + size: 28, 52 + orig: 28, 52 offset: 0, 0 - index: -1 \ No newline at end of file + index: -1 +torso + rotate: true + xy: 279, 2 + size: 59, 108 + orig: 59, 108 + offset: 0, 0 + index: -1 diff --git a/samples/js-tests/res/skeletons/spineboy.json b/samples/js-tests/res/skeletons/spineboy.json index 57b0f6cbe8..1ffa7aad57 100644 --- a/samples/js-tests/res/skeletons/spineboy.json +++ b/samples/js-tests/res/skeletons/spineboy.json @@ -1,784 +1,2409 @@ { "bones": [ - { "name": "root" }, - { "name": "hip", "parent": "root", "x": 0.64, "y": 114.41 }, - { "name": "left upper leg", "parent": "hip", "length": 50.39, "x": 14.45, "y": 2.81, "rotation": -89.09 }, - { "name": "left lower leg", "parent": "left upper leg", "length": 56.45, "x": 51.78, "y": 3.46, "rotation": -16.65 }, - { "name": "left foot", "parent": "left lower leg", "length": 46.5, "x": 64.02, "y": -8.67, "rotation": 102.43 }, - { "name": "right upper leg", "parent": "hip", "length": 45.76, "x": -18.27, "rotation": -101.13 }, - { "name": "right lower leg", "parent": "right upper leg", "length": 58.52, "x": 50.21, "y": 0.6, "rotation": -10.7 }, - { "name": "right foot", "parent": "right lower leg", "length": 45.45, "x": 64.88, "y": 0.04, "rotation": 110.3 }, - { "name": "torso", "parent": "hip", "length": 85.82, "x": -6.42, "y": 1.97, "rotation": 94.95 }, - { "name": "neck", "parent": "torso", "length": 18.38, "x": 83.64, "y": -1.78, "rotation": 0.9 }, - { "name": "head", "parent": "neck", "length": 68.28, "x": 19.09, "y": 6.97, "rotation": -8.94 }, - { "name": "right shoulder", "parent": "torso", "length": 49.95, "x": 81.9, "y": 6.79, "rotation": 130.6 }, - { "name": "right arm", "parent": "right shoulder", "length": 36.74, "x": 49.95, "y": -0.12, "rotation": 40.12 }, - { "name": "right hand", "parent": "right arm", "length": 15.32, "x": 36.9, "y": 0.34, "rotation": 2.35 }, - { "name": "left shoulder", "parent": "torso", "length": 44.19, "x": 78.96, "y": -15.75, "rotation": -156.96 }, - { "name": "left arm", "parent": "left shoulder", "length": 35.62, "x": 44.19, "y": -0.01, "rotation": 28.16 }, - { "name": "left hand", "parent": "left arm", "length": 11.52, "x": 35.62, "y": 0.07, "rotation": 2.7 }, - { "name": "pelvis", "parent": "hip", "x": 1.41, "y": -6.57 } + { "name": "hip", "y": 247.47 }, + { "name": "front_thigh", "parent": "hip", "length": 74.8, "x": -17.45, "y": -11.64, "rotation": -95.51, "color": "00ff04ff" }, + { "name": "rear_thigh", "parent": "hip", "length": 85.71, "x": 8.91, "y": -5.62, "rotation": -72.54, "color": "ff000dff" }, + { "name": "torso", "parent": "hip", "length": 127.55, "x": -1.61, "y": 4.9, "rotation": 103.82, "color": "e0da19ff" }, + { + "name": "front_shin", + "parent": "front_thigh", + "length": 128.76, + "x": 78.69, + "y": 1.6, + "rotation": -2.21, + "inheritScale": false, + "color": "00ff04ff" + }, + { "name": "front_upper_arm", "parent": "torso", "length": 69.45, "x": 103.75, "y": 19.32, "rotation": 168.37, "color": "00ff04ff" }, + { "name": "neck", "parent": "torso", "length": 25.45, "x": 127.49, "y": -0.3, "rotation": -31.53, "color": "e0da19ff" }, + { "name": "rear_shin", "parent": "rear_thigh", "length": 121.87, "x": 86.1, "y": -1.32, "rotation": -19.83, "color": "ff000dff" }, + { "name": "rear_upper_arm", "parent": "torso", "length": 51.93, "x": 92.35, "y": -19.22, "rotation": -169.55, "color": "ff000dff" }, + { + "name": "front_bracer", + "parent": "front_upper_arm", + "length": 40.57, + "x": 68.8, + "y": -0.68, + "rotation": 18.29, + "color": "00ff04ff" + }, + { "name": "front_foot", "parent": "front_shin", "length": 91.34, "x": 128.75, "y": -0.33, "rotation": 77.9, "color": "00ff04ff" }, + { "name": "head", "parent": "neck", "length": 263.57, "x": 27.66, "y": -0.25, "rotation": 23.18, "color": "e0da19ff" }, + { "name": "rear_bracer", "parent": "rear_upper_arm", "length": 34.55, "x": 51.35, "rotation": 23.15, "color": "ff000dff" }, + { "name": "rear_foot", "parent": "rear_shin", "length": 82.57, "x": 121.45, "y": -0.75, "rotation": 69.3, "color": "ff000dff" }, + { "name": "front_fist", "parent": "front_bracer", "length": 65.38, "x": 40.56, "y": 0.19, "rotation": 12.43, "color": "00ff04ff" }, + { "name": "gun", "parent": "rear_bracer", "length": 43.1, "x": 34.42, "y": -0.45, "rotation": 5.34, "color": "ff000dff" }, + { "name": "gunTip", "parent": "gun", "x": 201.04, "y": 52.13, "rotation": 6.83, "color": "ff000dff" } ], "slots": [ - { "name": "left shoulder", "bone": "left shoulder", "attachment": "left-shoulder" }, - { "name": "left arm", "bone": "left arm", "attachment": "left-arm" }, - { "name": "left hand", "bone": "left hand", "attachment": "left-hand" }, - { "name": "left foot", "bone": "left foot", "attachment": "left-foot" }, - { "name": "left lower leg", "bone": "left lower leg", "attachment": "left-lower-leg" }, - { "name": "left upper leg", "bone": "left upper leg", "attachment": "left-upper-leg" }, - { "name": "pelvis", "bone": "pelvis", "attachment": "pelvis" }, - { "name": "right foot", "bone": "right foot", "attachment": "right-foot" }, - { "name": "right lower leg", "bone": "right lower leg", "attachment": "right-lower-leg" }, - { "name": "right upper leg", "bone": "right upper leg", "attachment": "right-upper-leg" }, - { "name": "torso", "bone": "torso", "attachment": "torso" }, + { "name": "rear_upper_arm", "bone": "rear_upper_arm", "attachment": "rear_upper_arm" }, + { "name": "rear_bracer", "bone": "rear_bracer", "attachment": "rear_bracer" }, + { "name": "gun", "bone": "gun", "attachment": "gun" }, + { "name": "rear_foot", "bone": "rear_foot", "attachment": "rear_foot" }, + { "name": "rear_thigh", "bone": "rear_thigh", "attachment": "rear_thigh" }, + { "name": "rear_shin", "bone": "rear_shin", "attachment": "rear_shin" }, { "name": "neck", "bone": "neck", "attachment": "neck" }, + { "name": "torso", "bone": "torso", "attachment": "torso" }, + { "name": "front_upper_arm", "bone": "front_upper_arm", "attachment": "front_upper_arm" }, { "name": "head", "bone": "head", "attachment": "head" }, - { "name": "eyes", "bone": "head", "attachment": "eyes" }, - { "name": "right shoulder", "bone": "right shoulder", "attachment": "right-shoulder" }, - { "name": "right arm", "bone": "right arm", "attachment": "right-arm" }, - { "name": "right hand", "bone": "right hand", "attachment": "right-hand" } + { "name": "eye", "bone": "head", "attachment": "eye_indifferent" }, + { "name": "front_thigh", "bone": "front_thigh", "attachment": "front_thigh" }, + { "name": "front_foot", "bone": "front_foot", "attachment": "front_foot" }, + { "name": "front_shin", "bone": "front_shin", "attachment": "front_shin" }, + { "name": "mouth", "bone": "head", "attachment": "mouth_smile" }, + { "name": "goggles", "bone": "head", "attachment": "goggles" }, + { "name": "front_bracer", "bone": "front_bracer", "attachment": "front_bracer" }, + { "name": "front_fist", "bone": "front_fist", "attachment": "front_fist_closed" }, + { "name": "muzzle", "bone": "gunTip", "additive": true } ], "skins": { "default": { - "left shoulder": { - "left-shoulder": { "x": 23.74, "y": 0.11, "rotation": 62.01, "width": 34, "height": 53 } + "eye": { + "eye_indifferent": { "x": 85.72, "y": -28.18, "rotation": -70.63, "width": 93, "height": 89 }, + "eye_surprised": { "x": 85.72, "y": -28.18, "rotation": -70.63, "width": 93, "height": 89 } }, - "left arm": { - "left-arm": { "x": 15.11, "y": -0.44, "rotation": 33.84, "width": 35, "height": 29 } + "front_bracer": { + "front_bracer": { "x": 12.03, "y": -1.67, "rotation": 79.59, "width": 58, "height": 80 } }, - "left hand": { - "left-hand": { "x": 0.75, "y": 1.86, "rotation": 31.14, "width": 35, "height": 38 } + "front_fist": { + "front_fist_closed": { "x": 35.49, "y": 6, "rotation": 67.16, "width": 75, "height": 82 }, + "front_fist_open": { "x": 39.56, "y": 7.76, "rotation": 67.16, "width": 86, "height": 87 } }, - "left foot": { - "left-foot": { "x": 24.35, "y": 8.88, "rotation": 3.32, "width": 65, "height": 30 } + "front_foot": { + "front_foot": { "x": 29.51, "y": 7.83, "rotation": 18.68, "width": 126, "height": 69 }, + "front_foot_bend1": { "x": 29.51, "y": 7.83, "rotation": 18.68, "width": 128, "height": 70 }, + "front_foot_bend2": { "x": 16.07, "y": 13.83, "rotation": 18.68, "width": 108, "height": 93 } }, - "left lower leg": { - "left-lower-leg": { "x": 24.55, "y": -1.92, "rotation": 105.75, "width": 49, "height": 64 } + "front_shin": { + "front_shin": { "x": 55.11, "y": -3.54, "rotation": 96.59, "width": 82, "height": 184 } }, - "left upper leg": { - "left-upper-leg": { "x": 26.12, "y": -1.85, "rotation": 89.09, "width": 33, "height": 67 } + "front_thigh": { + "front_thigh": { "x": 42.47, "y": 4.44, "rotation": 84.86, "width": 48, "height": 112 } }, - "pelvis": { - "pelvis": { "x": -4.83, "y": 10.62, "width": 63, "height": 47 } + "front_upper_arm": { + "front_upper_arm": { "x": 28.3, "y": 7.37, "rotation": 97.89, "width": 54, "height": 97 } }, - "right foot": { - "right-foot": { "x": 19.02, "y": 8.47, "rotation": 1.52, "width": 67, "height": 30 } + "goggles": { + "goggles": { "x": 97.07, "y": 6.54, "rotation": -70.63, "width": 261, "height": 166 } }, - "right lower leg": { - "right-lower-leg": { "x": 23.28, "y": -2.59, "rotation": 111.83, "width": 51, "height": 64 } + "gun": { + "gun": { "x": 77.3, "y": 16.4, "rotation": 60.82, "width": 210, "height": 203 } }, - "right upper leg": { - "right-upper-leg": { "x": 23.03, "y": 0.25, "rotation": 101.13, "width": 44, "height": 70 } + "head": { + "head": { "x": 128.95, "y": 0.29, "rotation": -70.63, "width": 271, "height": 298 } }, - "torso": { - "torso": { "x": 44.57, "y": -7.08, "rotation": -94.95, "width": 68, "height": 92 } + "mouth": { + "mouth_grind": { "x": 23.68, "y": -32.23, "rotation": -70.63, "width": 93, "height": 59 }, + "mouth_oooo": { "x": 23.68, "y": -32.23, "rotation": -70.63, "width": 93, "height": 59 }, + "mouth_smile": { "x": 23.68, "y": -32.23, "rotation": -70.63, "width": 93, "height": 59 } + }, + "muzzle": { + "muzzle": { "x": 18.25, "y": 5.44, "rotation": 0.15, "width": 462, "height": 400 } }, "neck": { - "neck": { "x": 9.42, "y": -3.66, "rotation": -100.15, "width": 34, "height": 28 } + "neck": { "x": 9.76, "y": -3.01, "rotation": -55.22, "width": 36, "height": 41 } }, - "head": { - "head": { "x": 53.94, "y": -5.75, "rotation": -86.9, "width": 121, "height": 132 } + "rear_bracer": { + "rear_bracer": { "x": 11.15, "y": -2.2, "rotation": 66.17, "width": 56, "height": 72 } }, - "eyes": { - "eyes": { "x": 28.94, "y": -32.92, "rotation": -86.9, "width": 34, "height": 27 }, - "eyes-closed": { "x": 28.77, "y": -32.86, "rotation": -86.9, "width": 34, "height": 27 } + "rear_foot": { + "rear_foot": { "x": 31.51, "y": 3.57, "rotation": 23.07, "width": 113, "height": 60 }, + "rear_foot_bend1": { "x": 34.39, "y": 4.8, "rotation": 23.07, "width": 117, "height": 66 }, + "rear_foot_bend2": { "x": 30.38, "y": 12.62, "rotation": 23.07, "width": 103, "height": 83 } }, - "right shoulder": { - "right-shoulder": { "x": 25.86, "y": 0.03, "rotation": 134.44, "width": 52, "height": 51 } + "rear_shin": { + "rear_shin": { "x": 58.29, "y": -2.75, "rotation": 92.37, "width": 75, "height": 178 } }, - "right arm": { - "right-arm": { "x": 18.34, "y": -2.64, "rotation": 94.32, "width": 21, "height": 45 } + "rear_thigh": { + "rear_thigh": { "x": 33.1, "y": -4.11, "rotation": 72.54, "width": 65, "height": 104 } }, - "right hand": { - "right-hand": { "x": 6.82, "y": 1.25, "rotation": 91.96, "width": 32, "height": 32 } + "rear_upper_arm": { + "rear_upper_arm": { "x": 21.12, "y": 4.08, "rotation": 89.32, "width": 47, "height": 87 } + }, + "torso": { + "torso": { "x": 63.61, "y": 7.12, "rotation": -94.53, "width": 98, "height": 180 } } } }, +"events": { + "footstep": {}, + "headAttach": { "int": 3, "float": 4 }, + "headBehind": { "int": 5, "float": 6, "string": "setup" }, + "headPop": { "int": 1, "float": 2 } +}, "animations": { - "walk": { + "death": { + "slots": { + "eye": { + "attachment": [ + { "time": 0, "name": "eye_surprised" }, + { "time": 0.4666, "name": "eye_indifferent" }, + { "time": 2.2333, "name": "eye_surprised" }, + { "time": 4.5333, "name": "eye_indifferent" } + ] + }, + "front_fist": { + "attachment": [ + { "time": 0, "name": "front_fist_open" } + ] + }, + "mouth": { + "attachment": [ + { "time": 0, "name": "mouth_oooo" }, + { "time": 2.2333, "name": "mouth_grind" }, + { "time": 4.5333, "name": "mouth_oooo" } + ] + } + }, + "bones": { + "head": { + "rotate": [ + { "time": 0, "angle": -2.82 }, + { "time": 0.1333, "angle": -28.74 }, + { "time": 0.2333, "angle": 11.42 }, + { "time": 0.3333, "angle": -50.24 }, + { "time": 0.4, "angle": -72.66, "curve": "stepped" }, + { "time": 0.4333, "angle": -72.66 }, + { "time": 0.5, "angle": -20.24 }, + { "time": 0.5666, "angle": -85.28, "curve": "stepped" }, + { "time": 0.9333, "angle": -85.28, "curve": "stepped" }, + { "time": 2.2333, "angle": -85.28 }, + { "time": 2.5, "angle": -51.96, "curve": "stepped" }, + { "time": 4.5333, "angle": -51.96 }, + { "time": 4.6666, "angle": -85.28 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "neck": { + "rotate": [ + { "time": 0, "angle": -2.82 }, + { "time": 0.1333, "angle": 12.35 }, + { "time": 0.2333, "angle": 29.89 }, + { "time": 0.3, "angle": 70.36 }, + { "time": 0.4, "angle": -10.22, "curve": "stepped" }, + { "time": 0.4333, "angle": -10.22 }, + { "time": 0.5, "angle": 2.92 }, + { "time": 0.5666, "angle": 47.94, "curve": "stepped" }, + { "time": 2.2333, "angle": 47.94 }, + { "time": 2.5, "angle": 18.5, "curve": "stepped" }, + { "time": 4.5333, "angle": 18.5 }, + { "time": 4.6666, "angle": 47.94 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "torso": { + "rotate": [ + { "time": 0, "angle": -8.61 }, + { "time": 0.1333, "angle": 28.19 }, + { "time": 0.2666, "angle": -280.19 }, + { "time": 0.4, "angle": -237.22, "curve": "stepped" }, + { "time": 0.4333, "angle": -237.22 }, + { "time": 0.5, "angle": 76.03, "curve": "stepped" }, + { "time": 0.8, "angle": 76.03, "curve": "stepped" }, + { "time": 0.9333, "angle": 76.03, "curve": "stepped" }, + { "time": 2.2333, "angle": 76.03 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.9333, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 2.2333, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "front_upper_arm": { + "rotate": [ + { "time": 0, "angle": -38.85 }, + { "time": 0.1333, "angle": -299.58 }, + { "time": 0.2666, "angle": -244.74 }, + { "time": 0.4, "angle": -292.35 }, + { "time": 0.4333, "angle": -315.84 }, + { "time": 0.5, "angle": -347.94 }, + { "time": 0.7, "angle": -347.33, "curve": "stepped" }, + { "time": 2.2333, "angle": -347.33 }, + { "time": 2.7, "angle": -290.68 }, + { "time": 2.7666, "angle": -285.1 }, + { "time": 4.6666, "angle": -290.68 }, + { "time": 4.8, "angle": 8.61 }, + { "time": 4.8666, "angle": 10.94 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "rear_upper_arm": { + "rotate": [ + { "time": 0, "angle": -44.69 }, + { "time": 0.1333, "angle": 112.26 }, + { "time": 0.2666, "angle": 129.07 }, + { "time": 0.4, "angle": 134.94, "curve": "stepped" }, + { "time": 0.4333, "angle": 134.94 }, + { "time": 0.5666, "angle": 172.6, "curve": "stepped" }, + { "time": 0.9333, "angle": 172.6, "curve": "stepped" }, + { "time": 2.2333, "angle": 172.6 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "front_bracer": { + "rotate": [ + { "time": 0, "angle": 21.88 }, + { "time": 0.1333, "angle": 11.48 }, + { "time": 0.2666, "angle": -18.81 }, + { "time": 0.4, "angle": -18.92 }, + { "time": 0.4333, "angle": -18.28 }, + { "time": 0.5, "angle": 60.61 }, + { "time": 0.7, "angle": -18.87, "curve": "stepped" }, + { "time": 2.2333, "angle": -18.87 }, + { "time": 2.7, "angle": -1.95, "curve": "stepped" }, + { "time": 4.6666, "angle": -1.95 }, + { "time": 4.8, "angle": 34.55 }, + { "time": 4.9333, "angle": -18.74 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "front_fist": { + "rotate": [ + { "time": 0, "angle": -2.33 }, + { "time": 0.2666, "angle": 26.34 }, + { "time": 0.7, "angle": -6.07, "curve": "stepped" }, + { "time": 2.2333, "angle": -6.07 }, + { "time": 2.7, "angle": 5.72, "curve": "stepped" }, + { "time": 4.6666, "angle": 5.72 }, + { "time": 4.8666, "angle": -6.52 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "rear_bracer": { + "rotate": [ + { "time": 0, "angle": 10.36 }, + { "time": 0.1333, "angle": -23.12 }, + { "time": 0.2666, "angle": -23.11 }, + { "time": 0.4, "angle": -23.16, "curve": "stepped" }, + { "time": 0.4333, "angle": -23.16 }, + { "time": 0.5666, "angle": -23.2, "curve": "stepped" }, + { "time": 0.9333, "angle": -23.2, "curve": "stepped" }, + { "time": 2.2333, "angle": -23.2 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "gun": { + "rotate": [ + { "time": 0, "angle": -2.78 }, + { "time": 0.1333, "angle": -24.58 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "hip": { + "rotate": [ + { "time": 0, "angle": 0, "curve": "stepped" }, + { "time": 0.9333, "angle": 0, "curve": "stepped" }, + { "time": 2.2333, "angle": 0 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 }, + { "time": 0.2, "x": 50.34, "y": 151.73 }, + { "time": 0.4, "x": 5.16, "y": -119.64, "curve": "stepped" }, + { "time": 0.4333, "x": 5.16, "y": -119.64 }, + { "time": 0.5, "x": 50.34, "y": -205.18, "curve": "stepped" }, + { "time": 0.8, "x": 50.34, "y": -205.18, "curve": "stepped" }, + { "time": 0.9333, "x": 50.34, "y": -205.18, "curve": "stepped" }, + { "time": 2.2333, "x": 50.34, "y": -205.18 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "front_thigh": { + "rotate": [ + { "time": 0, "angle": 0 }, + { "time": 0.1333, "angle": 8.47 }, + { "time": 0.2666, "angle": 115.95 }, + { "time": 0.4, "angle": 180.66, "curve": "stepped" }, + { "time": 0.4333, "angle": 180.66 }, + { "time": 0.5, "angle": 155.22 }, + { "time": 0.6, "angle": 97.73 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "front_shin": { + "rotate": [ + { "time": 0, "angle": 0 }, + { "time": 0.1333, "angle": -27.37 }, + { "time": 0.2666, "angle": -35.1 }, + { "time": 0.4, "angle": -37.72, "curve": "stepped" }, + { "time": 0.4333, "angle": -37.72 }, + { "time": 0.5, "angle": -40.06 }, + { "time": 0.6, "angle": 2.76 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "rear_thigh": { + "rotate": [ + { "time": 0, "angle": 0 }, + { "time": 0.1333, "angle": 70.45 }, + { "time": 0.2666, "angle": 155.34 }, + { "time": 0.4, "angle": 214.31, "curve": "stepped" }, + { "time": 0.4333, "angle": 214.31 }, + { "time": 0.5, "angle": 169.67 }, + { "time": 0.8, "angle": 83.27 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "rear_shin": { + "rotate": [ + { "time": 0, "angle": 0 }, + { "time": 0.1333, "angle": 18.93 }, + { "time": 0.2666, "angle": -21.04 }, + { "time": 0.4, "angle": -29.93, "curve": "stepped" }, + { "time": 0.4333, "angle": -29.93 }, + { "time": 0.5, "angle": -16.79 }, + { "time": 0.8, "angle": 7.77 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "rear_foot": { + "rotate": [ + { "time": 0, "angle": 0 }, + { "time": 0.1333, "angle": -11.62 }, + { "time": 0.4, "angle": -45.59, "curve": "stepped" }, + { "time": 0.4333, "angle": -45.59 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "front_foot": { + "rotate": [ + { "time": 0, "angle": 0 }, + { "time": 0.4, "angle": -48.75, "curve": "stepped" }, + { "time": 0.4333, "angle": -48.75 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "gunTip": { + "rotate": [ + { "time": 0, "angle": 0 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + } + } + }, + "hit": { + "slots": { + "front_fist": { + "attachment": [ + { "time": 0.1666, "name": "front_fist_open" } + ] + }, + "mouth": { + "attachment": [ + { "time": 0, "name": "mouth_grind" }, + { "time": 0.3333, "name": "mouth_smile" } + ] + } + }, + "bones": { + "torso": { + "rotate": [ + { "time": 0, "angle": 56.42 }, + { "time": 0.3333, "angle": 8.89 } + ] + }, + "neck": { + "rotate": [ + { "time": 0, "angle": 35.38 }, + { "time": 0.2333, "angle": 24.94 } + ] + }, + "head": { + "rotate": [ + { "time": 0, "angle": 10.21 }, + { "time": 0.3333, "angle": -41.3 } + ] + }, + "front_upper_arm": { + "rotate": [ + { + "time": 0, + "angle": -310.92, + "curve": [ 0.38, 0.53, 0.744, 1 ] + }, + { "time": 0.3333, "angle": -112.59 } + ], + "translate": [ + { "time": 0, "x": 7.23, "y": -13.13 } + ] + }, + "front_bracer": { + "rotate": [ + { "time": 0, "angle": 36.99 }, + { "time": 0.3333, "angle": -28.64 } + ] + }, + "front_fist": { + "rotate": [ + { "time": 0, "angle": 13.59 }, + { "time": 0.3333, "angle": 7.55 } + ] + }, + "rear_upper_arm": { + "rotate": [ + { + "time": 0, + "angle": 271.02, + "curve": [ 0.342, 0.36, 0.68, 0.71 ] + }, + { "time": 0.3333, "angle": -15.84 } + ], + "translate": [ + { "time": 0.3333, "x": -0.09, "y": -0.46 } + ] + }, + "rear_bracer": { + "rotate": [ + { "time": 0, "angle": 0 }, + { "time": 0.3333, "angle": 40.03 } + ] + }, + "gun": { + "rotate": [ + { "time": 0, "angle": 14.98 }, + { "time": 0.3333, "angle": 39.75 } + ] + }, + "hip": { + "translate": [ + { "time": 0, "x": -75.54, "y": -78.03 }, + { "time": 0.2333, "x": -36.48, "y": 12.42 }, + { "time": 0.3333, "x": -36.48, "y": -2.99 } + ] + }, + "front_thigh": { + "rotate": [ + { + "time": 0, + "angle": 90.94, + "curve": [ 0.227, 0.26, 0.432, 1 ] + }, + { "time": 0.3333, "angle": 32.02 } + ], + "translate": [ + { "time": 0, "x": 7.21, "y": -4 } + ] + }, + "rear_thigh": { + "rotate": [ + { + "time": 0, + "angle": 40.51, + "curve": [ 0.295, 0.3, 0.59, 0.99 ] + }, + { "time": 0.3333, "angle": 90.76 } + ], + "translate": [ + { "time": 0, "x": -1.96, "y": -0.32 } + ] + }, + "front_shin": { + "rotate": [ + { "time": 0, "angle": -96.62 }, + { "time": 0.3333, "angle": -15.13 } + ] + }, + "rear_shin": { + "rotate": [ + { "time": 0, "angle": 7.99 }, + { "time": 0.3333, "angle": -67.54 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "front_foot": { + "rotate": [ + { "time": 0, "angle": 5.4 }, + { "time": 0.3333, "angle": -16.26 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "rear_foot": { + "rotate": [ + { "time": 0, "angle": 2.67 }, + { "time": 0.3333, "angle": -10.31 } + ] + } + } + }, + "idle": { + "slots": { + "front_fist": { + "attachment": [ + { "time": 0, "name": "front_fist_open" }, + { "time": 1.6666, "name": "front_fist_open" } + ] + }, + "mouth": { + "attachment": [ + { "time": 0, "name": "mouth_smile" }, + { "time": 1.6666, "name": "mouth_smile" } + ] + } + }, "bones": { - "left upper leg": { + "torso": { + "rotate": [ + { + "time": 0, + "angle": -5.61, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { + "time": 0.8333, + "angle": -9.65, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { "time": 1.6666, "angle": -5.61 } + ], + "translate": [ + { "time": 0, "x": -6.49, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 1.6666, "x": 1, "y": 1 } + ] + }, + "front_upper_arm": { + "rotate": [ + { + "time": 0, + "angle": -59.85, + "curve": [ 0.492, 0, 0.75, 1 ] + }, + { + "time": 0.6666, + "angle": -54.31, + "curve": [ 0.324, 0.11, 0.75, 1 ] + }, + { "time": 1.6666, "angle": -59.85 } + ], + "translate": [ + { "time": 0, "x": -7.12, "y": -8.23 }, + { "time": 0.6666, "x": -6.32, "y": -8.3 }, + { "time": 1.6666, "x": -7.12, "y": -8.23 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 1.6666, "x": 1, "y": 1 } + ] + }, + "rear_upper_arm": { + "rotate": [ + { + "time": 0, + "angle": 62.41, + "curve": [ 0.504, 0.02, 0.75, 1 ] + }, + { + "time": 0.7333, + "angle": 43.83, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { "time": 1.6666, "angle": 62.41 } + ], + "translate": [ + { "time": 0, "x": -1.83, "y": -16.78 }, + { "time": 0.6666, "x": 0.34, "y": -15.23 }, + { "time": 1.6666, "x": -1.83, "y": -16.78 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 1.6666, "x": 1, "y": 1 } + ] + }, + "neck": { + "rotate": [ + { "time": 0, "angle": 0 }, + { "time": 0.6666, "angle": 2.39 }, + { "time": 1.6666, "angle": 0 } + ], + "translate": [ + { "time": 0, "x": -1.88, "y": -4.76, "curve": "stepped" }, + { "time": 1.6666, "x": -1.88, "y": -4.76 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 1.6666, "x": 1, "y": 1 } + ] + }, + "front_thigh": { + "rotate": [ + { + "time": 0, + "angle": 0.64, + "curve": [ 0.235, 0, 0.558, 0.99 ] + }, + { + "time": 0.6666, + "angle": -4.34, + "curve": [ 0.594, 0, 0.653, 1 ] + }, + { "time": 1.6666, "angle": 0.64 } + ], + "translate": [ + { "time": 0, "x": -13.39, "y": 6.69, "curve": "stepped" }, + { "time": 1.6666, "x": -13.39, "y": 6.69 } + ], + "scale": [ + { + "time": 0, + "x": 0.896, + "y": 1, + "curve": [ 0.235, 0, 0.558, 0.99 ] + }, + { + "time": 0.6666, + "x": 0.825, + "y": 1, + "curve": [ 0.594, 0, 0.653, 1 ] + }, + { "time": 1.6666, "x": 0.896, "y": 1 } + ] + }, + "front_shin": { + "rotate": [ + { "time": 0, "angle": -19.28, "curve": "stepped" }, + { "time": 1.6666, "angle": -19.28 } + ], + "scale": [ + { + "time": 0, + "x": 1, + "y": 1, + "curve": [ 0.235, 0, 0.558, 0.99 ] + }, + { + "time": 0.6666, + "x": 0.994, + "y": 1, + "curve": [ 0.594, 0, 0.653, 1 ] + }, + { "time": 1.6666, "x": 1, "y": 1 } + ] + }, + "rear_thigh": { + "rotate": [ + { + "time": 0, + "angle": 30.5, + "curve": [ 0.235, 0, 0.558, 0.99 ] + }, + { + "time": 0.6666, + "angle": 40.15, + "curve": [ 0.594, 0, 0.653, 1 ] + }, + { "time": 1.6666, "angle": 30.5 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 1.6666, "x": 1, "y": 1 } + ] + }, + "rear_shin": { + "rotate": [ + { + "time": 0, + "angle": -23.83, + "curve": [ 0.235, 0, 0.558, 0.99 ] + }, + { + "time": 0.6666, + "angle": -43.77, + "curve": [ 0.594, 0, 0.653, 1 ] + }, + { "time": 1.6666, "angle": -23.83 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 1.6666, "x": 1, "y": 1 } + ] + }, + "front_foot": { + "rotate": [ + { + "time": 0, + "angle": 5.13, + "curve": [ 0.235, 0, 0.558, 0.99 ] + }, + { + "time": 0.6666, + "angle": 10.04, + "curve": [ 0.594, 0, 0.653, 1 ] + }, + { "time": 1.6666, "angle": 5.13 } + ], + "scale": [ + { "time": 0, "x": 0.755, "y": 1.309, "curve": "stepped" }, + { "time": 1.6666, "x": 0.755, "y": 1.309 } + ] + }, + "hip": { + "translate": [ + { + "time": 0, + "x": -6.63, + "y": -23.01, + "curve": [ 0.235, 0, 0.558, 0.99 ] + }, + { + "time": 0.6666, + "x": 6.27, + "y": -35, + "curve": [ 0.594, 0, 0.653, 1 ] + }, + { "time": 1.6666, "x": -6.63, "y": -23.01 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 1.6666, "x": 1, "y": 1 } + ] + }, + "rear_foot": { + "rotate": [ + { + "time": 0, + "angle": -7.34, + "curve": [ 0.235, 0, 0.558, 0.99 ] + }, + { + "time": 0.6666, + "angle": 3.85, + "curve": [ 0.594, 0, 0.653, 1 ] + }, + { "time": 1.6666, "angle": -7.34 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 1.6666, "x": 1, "y": 1 } + ] + }, + "rear_bracer": { + "rotate": [ + { + "time": 0, + "angle": -17.16, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { + "time": 0.6666, + "angle": 12.52, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { "time": 1.6666, "angle": -17.16 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 1.6666, "x": 1, "y": 1 } + ] + }, + "head": { + "rotate": [ + { + "time": 0, + "angle": -5.51, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { + "time": 0.6666, + "angle": -3.12, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { "time": 1.6666, "angle": -5.51 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 1.6666, "x": 1, "y": 1 } + ] + }, + "front_bracer": { + "rotate": [ + { + "time": 0, + "angle": 45.46, + "curve": [ 0.492, 0, 0.75, 1 ] + }, + { + "time": 0.6666, + "angle": 41.33, + "curve": [ 0.32, 0.1, 0.736, 0.91 ] + }, + { "time": 1.6666, "angle": 45.46 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 1.6666, "x": 1, "y": 1 } + ] + }, + "gun": { + "rotate": [ + { + "time": 0, + "angle": 0, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { + "time": 0.6666, + "angle": -15.59, + "curve": [ 0.732, 0, 0.769, 0.99 ] + }, + { "time": 1.6666, "angle": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 1.6666, "x": 1, "y": 1 } + ] + }, + "front_fist": { + "rotate": [ + { + "time": 0, + "angle": -6.84, + "curve": [ 0.492, 0, 0.75, 1 ] + }, + { + "time": 0.6666, + "angle": -14.63, + "curve": [ 0.324, 0.11, 0.75, 1 ] + }, + { "time": 1.6666, "angle": -6.84 } + ], + "scale": [ + { + "time": 0, + "x": 1, + "y": 1, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { + "time": 0.6666, + "x": 0.689, + "y": 1.1, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { "time": 1.6666, "x": 1, "y": 1 } + ] + } + } + }, + "jump": { + "slots": { + "front_fist": { + "attachment": [ + { "time": 0, "name": "front_fist_open" }, + { "time": 0.2, "name": "front_fist_closed" }, + { "time": 0.6666, "name": "front_fist_open" } + ] + }, + "mouth": { + "attachment": [ + { "time": 0, "name": "mouth_grind" } + ] + }, + "torso": { + "attachment": [ + { "time": 0, "name": "torso" } + ] + } + }, + "bones": { + "front_thigh": { + "rotate": [ + { + "time": 0, + "angle": 91.53, + "curve": [ 0.278, 0.46, 0.763, 1 ] + }, + { + "time": 0.2, + "angle": -35.83, + "curve": [ 0.761, 0, 0.75, 1 ] + }, + { "time": 0.4333, "angle": 127.74 }, + { + "time": 0.7333, + "angle": 48.18, + "curve": [ 0.227, 0.26, 0.432, 1 ] + }, + { "time": 0.8333, "angle": 25.35 }, + { "time": 0.9333, "angle": 45.37 }, + { "time": 1.0333, "angle": 38.12 }, + { "time": 1.1333, "angle": 25.35 }, + { "time": 1.3333, "angle": 91.53 } + ], + "translate": [ + { "time": 0, "x": -2.56, "y": 5.77 }, + { "time": 0.4333, "x": 8.3, "y": 7.98 }, + { "time": 0.7333, "x": 7.21, "y": -4 }, + { "time": 1.3333, "x": -2.56, "y": 5.77 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "torso": { + "rotate": [ + { "time": 0, "angle": -42.63 }, + { "time": 0.2, "angle": -5.74 }, + { "time": 0.4333, "angle": -50.76 }, + { "time": 0.7333, "angle": 1.89 }, + { "time": 0.8333, "angle": 11.58 }, + { "time": 0.9666, "angle": -1.89 }, + { "time": 1.1333, "angle": 11.58 }, + { "time": 1.3333, "angle": -42.63 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "rear_thigh": { + "rotate": [ + { "time": 0, "angle": -26.32 }, + { "time": 0.2, "angle": 121.44 }, + { "time": 0.4333, "angle": 70.54 }, + { + "time": 0.7333, + "angle": 79.89, + "curve": [ 0.295, 0.3, 0.59, 0.99 ] + }, + { "time": 0.8333, "angle": 99.12 }, + { "time": 0.9333, "angle": 74.05 }, + { "time": 1.0333, "angle": 98.04 }, + { "time": 1.1333, "angle": 99.12 }, + { "time": 1.3333, "angle": -26.32 } + ], + "translate": [ + { "time": 0, "x": -0.56, "y": -0.32 }, + { "time": 0.4333, "x": -8.5, "y": 10.58 }, + { "time": 0.7333, "x": -1.96, "y": -0.32 }, + { "time": 1.3333, "x": -0.56, "y": -0.32 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "rear_shin": { + "rotate": [ + { "time": 0, "angle": -78.69 }, + { "time": 0.4333, "angle": -55.56 }, + { "time": 0.7333, "angle": -62.84 }, + { "time": 0.8333, "angle": -80.74 }, + { "time": 0.9333, "angle": -41.12 }, + { "time": 1.0333, "angle": -77.4 }, + { "time": 1.1333, "angle": -80.74 }, + { "time": 1.3333, "angle": -78.69 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.7333, "x": 1, "y": 1 } + ] + }, + "front_upper_arm": { + "rotate": [ + { "time": 0, "angle": -22.61 }, + { "time": 0.2, "angle": -246.68 }, + { + "time": 0.6, + "angle": 11.28, + "curve": [ 0.246, 0, 0.633, 0.53 ] + }, + { + "time": 0.7333, + "angle": -57.45, + "curve": [ 0.38, 0.53, 0.744, 1 ] + }, + { "time": 0.8666, "angle": -112.59 }, + { "time": 0.9333, "angle": -102.17 }, + { "time": 1.0333, "angle": -108.61 }, + { "time": 1.1333, "angle": -112.59 }, + { "time": 1.3333, "angle": -22.61 } + ], + "translate": [ + { "time": 0, "x": 6.08, "y": 7.15 }, + { "time": 0.2, "x": 7.23, "y": -13.13, "curve": "stepped" }, + { "time": 0.7333, "x": 7.23, "y": -13.13 }, + { "time": 1.3333, "x": 6.08, "y": 7.15 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "front_bracer": { + "rotate": [ + { "time": 0, "angle": 66.46 }, + { "time": 0.2, "angle": 42.39 }, + { "time": 0.4333, "angle": 26.06 }, + { "time": 0.7333, "angle": 13.28 }, + { "time": 0.8666, "angle": -28.64 }, + { "time": 0.9333, "angle": -22.31 }, + { "time": 1.0333, "angle": -35.39 }, + { "time": 1.1333, "angle": -28.64 }, + { "time": 1.3333, "angle": 66.46 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "front_fist": { + "rotate": [ + { "time": 0, "angle": -28.43 }, + { "time": 0.4333, "angle": -45.6 }, + { "time": 0.7333, "angle": -53.66 }, + { "time": 0.8666, "angle": 7.55 }, + { "time": 0.9333, "angle": 31.15 }, + { "time": 1.0333, "angle": -32.58 }, + { "time": 1.1333, "angle": 7.55 }, + { "time": 1.3333, "angle": -28.43 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "rear_upper_arm": { + "rotate": [ + { "time": 0, "angle": 39.68 }, + { "time": 0.2, "angle": 276.57 }, + { "time": 0.3, "angle": 17.73 }, + { "time": 0.4333, "angle": 83.38 }, + { + "time": 0.6, + "angle": -4.71, + "curve": [ 0.246, 0, 0.633, 0.53 ] + }, + { + "time": 0.7333, + "angle": -69.63, + "curve": [ 0.342, 0.36, 0.68, 0.71 ] + }, + { + "time": 0.7666, + "angle": 321.47, + "curve": [ 0.333, 0.33, 0.667, 0.66 ] + }, + { + "time": 0.8, + "angle": 33.7, + "curve": [ 0.358, 0.64, 0.693, 1 ] + }, + { "time": 0.8666, "angle": 34.56 }, + { "time": 1.0333, "angle": 71.96 }, + { "time": 1.1333, "angle": 34.56 }, + { "time": 1.3333, "angle": 39.68 } + ], + "translate": [ + { "time": 0, "x": -3.1, "y": -4.86 }, + { "time": 0.2, "x": 23.33, "y": 49.07 }, + { "time": 0.4333, "x": 20.78, "y": 40.21 }, + { "time": 1.3333, "x": -3.1, "y": -4.86 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "rear_bracer": { + "rotate": [ + { "time": 0, "angle": 29.66 }, + { "time": 0.2, "angle": 45.06 }, + { "time": 0.4333, "angle": -4.34 }, + { "time": 0.7666, "angle": 61.68 }, + { "time": 0.8, "angle": 82.59 }, + { "time": 0.8666, "angle": 80.06 }, + { "time": 1.0333, "angle": 57.56 }, + { "time": 1.1333, "angle": 80.06 }, + { "time": 1.3333, "angle": 29.66 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "neck": { + "rotate": [ + { "time": 0, "angle": 24.9 }, + { "time": 0.2, "angle": 16.31 }, + { "time": 0.4333, "angle": 7.44 }, + { "time": 0.7333, "angle": -20.35 }, + { "time": 0.8333, "angle": -0.69, "curve": "stepped" }, + { "time": 1.1333, "angle": -0.69 }, + { "time": 1.3333, "angle": 24.9 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "head": { + "rotate": [ + { "time": 0, "angle": 24.92 }, + { "time": 0.2, "angle": 10.36 }, + { "time": 0.4333, "angle": 28.65 }, + { "time": 0.7333, "angle": -2.65 }, + { "time": 0.8333, "angle": -28.94, "curve": "stepped" }, + { "time": 1.1333, "angle": -28.94 }, + { "time": 1.3333, "angle": 24.92 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "hip": { + "rotate": [ + { "time": 0, "angle": 0 } + ], + "translate": [ + { + "time": 0, + "x": -34.51, + "y": -78.62, + "curve": [ 0.232, 1, 0.75, 1 ] + }, + { + "time": 0.2, + "x": -34.51, + "y": 182.5, + "curve": [ 0.232, 0.48, 0.598, 0.79 ] + }, + { + "time": 0.7666, + "x": -34.51, + "y": 596.22, + "curve": [ 0.329, 0.17, 0.66, 0.21 ] + }, + { "time": 1.1333, "x": -34.51, "y": 2.49 }, + { "time": 1.3333, "x": -34.51, "y": -78.62 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "front_shin": { + "rotate": [ + { + "time": 0, + "angle": -90.62, + "curve": [ 0.416, 0.54, 0.743, 1 ] + }, + { + "time": 0.2, + "angle": -10.52, + "curve": [ 0.644, 0, 0.75, 1 ] + }, + { "time": 0.4333, "angle": -127.72 }, + { "time": 0.7333, "angle": -19.91 }, + { "time": 0.8333, "angle": -5.16 }, + { "time": 0.9333, "angle": -35.06 }, + { "time": 1.0333, "angle": -43.97 }, + { "time": 1.1333, "angle": -5.16 }, + { "time": 1.3333, "angle": -90.62 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "front_foot": { + "rotate": [ + { "time": 0, "angle": -0.79 }, + { "time": 0.0333, "angle": 16.27 }, + { "time": 0.0666, "angle": 23.52 }, + { "time": 0.1, "angle": 21.02 }, + { "time": 0.1333, "angle": 10.92 }, + { "time": 0.2, "angle": -38.45 }, + { "time": 0.4333, "angle": 6.62 }, + { "time": 0.7333, "angle": -11.51 }, + { "time": 1.0333, "angle": -22.91 }, + { "time": 1.3333, "angle": -0.79 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "rear_foot": { + "rotate": [ + { "time": 0, "angle": -12.77 }, + { "time": 0.2, "angle": 17.05 }, + { "time": 0.4333, "angle": 19.45 }, + { "time": 0.7333, "angle": 2.67 }, + { "time": 1.0333, "angle": -28.49 }, + { "time": 1.3333, "angle": -12.77 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + }, + "gun": { + "rotate": [ + { "time": 0, "angle": 6.18 }, + { "time": 0.2, "angle": 30.81 }, + { "time": 0.4333, "angle": 13.25 }, + { "time": 0.7333, "angle": 14.98 }, + { "time": 0.7666, "angle": 25.64 }, + { "time": 0.8, "angle": 20.62 }, + { "time": 0.8666, "angle": 64.52 }, + { "time": 1.0333, "angle": 8.59 }, + { "time": 1.1333, "angle": 64.52 }, + { "time": 1.3333, "angle": 6.18 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 } + ] + } + } + }, + "run": { + "slots": { + "front_fist": { + "attachment": [ + { "time": 0, "name": "front_fist_closed" } + ] + }, + "mouth": { + "attachment": [ + { "time": 0, "name": "mouth_grind" } + ] + }, + "torso": { + "attachment": [ + { "time": 0, "name": "torso" } + ] + } + }, + "bones": { + "front_thigh": { + "rotate": [ + { + "time": 0, + "angle": 42.05, + "curve": [ 0.195, 0.86, 0.75, 1 ] + }, + { "time": 0.0666, "angle": 46.07 }, + { "time": 0.1333, "angle": -20.28 }, + { "time": 0.2, "angle": -27.23 }, + { "time": 0.2666, "angle": -47.16 }, + { "time": 0.3333, "angle": -39.79 }, + { "time": 0.4, "angle": -25.86 }, + { "time": 0.4666, "angle": 14.35 }, + { "time": 0.5333, "angle": 55.62 }, + { "time": 0.6, "angle": 69.65 }, + { "time": 0.6666, "angle": 86.4 }, + { "time": 0.7333, "angle": 65.87 }, + { "time": 0.8, "angle": 42.05 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 }, + { "time": 0.0333, "x": -5.79, "y": 11.15 }, + { "time": 0.0666, "x": -5.13, "y": 11.55 }, + { "time": 0.1333, "x": -7.7, "y": 8.98 }, + { "time": 0.5333, "x": -1.26, "y": 3.83 }, + { "time": 0.8, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } + ] + }, + "torso": { + "rotate": [ + { "time": 0, "angle": -39.7 }, + { "time": 0.2, "angle": -57.29 }, + { "time": 0.4, "angle": -39.7 }, + { "time": 0.6, "angle": -57.29 }, + { "time": 0.8, "angle": -39.7 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.4, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } + ] + }, + "rear_thigh": { + "rotate": [ + { "time": 0, "angle": -56.59 }, + { "time": 0.0666, "angle": -21.57 }, + { "time": 0.1333, "angle": 27.95 }, + { "time": 0.2, "angle": 42.42 }, + { "time": 0.2666, "angle": 62.37 }, + { "time": 0.3333, "angle": 45.42 }, + { "time": 0.4, "angle": 15.67 }, + { "time": 0.4666, "angle": 28.22 }, + { "time": 0.5333, "angle": -38.62 }, + { "time": 0.6, "angle": -53.26 }, + { "time": 0.6666, "angle": -79.31 }, + { "time": 0.7333, "angle": -86.47 }, + { "time": 0.8, "angle": -56.59 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 }, + { "time": 0.4, "x": -6.76, "y": -3.86 }, + { "time": 0.4333, "x": -15.85, "y": 7.28 }, + { "time": 0.4666, "x": -13.04, "y": 4.04 }, + { "time": 0.5, "x": -10.24, "y": 7.11 }, + { "time": 0.5333, "x": -9.01, "y": -5.15 }, + { "time": 0.6666, "x": -23.18, "y": -2.57 }, + { "time": 0.8, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } + ] + }, + "rear_shin": { + "rotate": [ + { "time": 0, "angle": -74 }, + { "time": 0.0666, "angle": -83.38 }, + { "time": 0.1333, "angle": -106.69 }, + { "time": 0.2, "angle": -66.01 }, + { "time": 0.2666, "angle": -55.22 }, + { "time": 0.3333, "angle": -24.8 }, + { + "time": 0.4, + "angle": 18.44, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { "time": 0.4666, "angle": -56.65 }, + { + "time": 0.5333, + "angle": -11.94, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { "time": 0.6666, "angle": -41.26 }, + { "time": 0.7333, "angle": -43.6 }, + { "time": 0.8, "angle": -74 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } + ] + }, + "front_upper_arm": { + "rotate": [ + { "time": 0, "angle": -89.36 }, + { "time": 0.0666, "angle": -95.67 }, + { "time": 0.1333, "angle": -22 }, + { "time": 0.2, "angle": -316.04 }, + { "time": 0.2666, "angle": -274.94 }, + { "time": 0.3333, "angle": -273.74 }, + { "time": 0.4, "angle": -272.09 }, + { "time": 0.4666, "angle": -264.89 }, + { "time": 0.5333, "angle": -320.09 }, + { "time": 0.6, "angle": -50.83 }, + { "time": 0.6666, "angle": -81.72 }, + { "time": 0.7333, "angle": -83.92 }, + { "time": 0.8, "angle": -89.36 } + ], + "translate": [ + { "time": 0, "x": 6.24, "y": 10.05 }, + { "time": 0.2666, "x": 4.95, "y": -13.13 }, + { "time": 0.6, "x": -2.43, "y": 1.94 }, + { "time": 0.8, "x": 6.24, "y": 10.05 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } + ] + }, + "front_bracer": { + "rotate": [ + { "time": 0, "angle": 33.43 }, + { "time": 0.0666, "angle": 20.53 }, + { "time": 0.1333, "angle": 15.26 }, + { "time": 0.2, "angle": 19.28 }, + { "time": 0.2666, "angle": 22.62 }, + { "time": 0.3333, "angle": 37.29 }, + { "time": 0.4, "angle": 41.53 }, + { "time": 0.4666, "angle": 31.73 }, + { "time": 0.5333, "angle": 67.45 }, + { "time": 0.6666, "angle": 39.77 }, + { "time": 0.7333, "angle": 30.95 }, + { "time": 0.8, "angle": 33.43 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } + ] + }, + "front_fist": { "rotate": [ - { "time": 0, "angle": -26.55 }, - { "time": 0.1333, "angle": -8.78 }, - { "time": 0.2666, "angle": 9.51 }, - { "time": 0.4, "angle": 30.74 }, - { "time": 0.5333, "angle": 25.33 }, - { "time": 0.6666, "angle": 26.11 }, - { "time": 0.8, "angle": -7.7 }, - { "time": 0.9333, "angle": -21.19 }, - { "time": 1.0666, "angle": -26.55 } + { "time": 0, "angle": -19.75 }, + { "time": 0.0666, "angle": -37.11 }, + { "time": 0.1333, "angle": -50.79 }, + { "time": 0.2666, "angle": -12.69 }, + { "time": 0.3333, "angle": 3.01 }, + { "time": 0.4333, "angle": 12.05 }, + { "time": 0.5333, "angle": 13.25 }, + { "time": 0.8, "angle": -19.75 } ], "translate": [ - { "time": 0, "x": -3, "y": -2.25 }, - { "time": 0.4, "x": -2.18, "y": -2.25 }, - { "time": 1.0666, "x": -3, "y": -2.25 } + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } ] }, - "right upper leg": { + "rear_upper_arm": { "rotate": [ - { "time": 0, "angle": 42.45 }, - { "time": 0.1333, "angle": 52.1 }, - { "time": 0.2666, "angle": 5.96 }, - { "time": 0.5333, "angle": -16.93 }, - { "time": 0.6666, "angle": 1.89 }, - { - "time": 0.8, - "angle": 28.06, - "curve": [ 0.462, 0.11, 1, 1 ] - }, - { - "time": 0.9333, - "angle": 58.68, - "curve": [ 0.5, 0.02, 1, 1 ] - }, - { "time": 1.0666, "angle": 42.45 } + { "time": 0, "angle": 68.68 }, + { "time": 0.0666, "angle": 73.89 }, + { "time": 0.1333, "angle": -9.64 }, + { "time": 0.2, "angle": 284.27 }, + { "time": 0.2666, "angle": 283.29 }, + { "time": 0.3333, "angle": 278.28 }, + { "time": 0.4, "angle": 271.02 }, + { "time": 0.4666, "angle": 263.2 }, + { "time": 0.5333, "angle": 314.25 }, + { "time": 0.6, "angle": 16.83 }, + { "time": 0.6666, "angle": 70.35 }, + { "time": 0.7333, "angle": 73.53 }, + { "time": 0.8, "angle": 68.68 } + ], + "translate": [ + { "time": 0, "x": -2.57, "y": -8.89 }, + { "time": 0.1333, "x": -4.68, "y": 7.2 }, + { "time": 0.2, "x": 21.73, "y": 51.17 }, + { "time": 0.6, "x": 4.33, "y": 2.05 }, + { "time": 0.8, "x": -2.57, "y": -8.89 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } + ] + }, + "rear_bracer": { + "rotate": [ + { "time": 0, "angle": 31.04 }, + { "time": 0.0666, "angle": 28.28 }, + { "time": 0.1333, "angle": 49.36 }, + { "time": 0.2, "angle": 59.37 }, + { "time": 0.2666, "angle": 8.56 }, + { "time": 0.3333, "angle": 9.38 }, + { "time": 0.4, "angle": 11.51 }, + { "time": 0.4666, "angle": 7.22 }, + { "time": 0.5333, "angle": -18.44 }, + { "time": 0.6, "angle": 11.44 }, + { "time": 0.6666, "angle": 9.99 }, + { "time": 0.7333, "angle": 8.28 }, + { "time": 0.8, "angle": 31.04 } ], "translate": [ - { "time": 0, "x": 8.11, "y": -2.36 }, - { "time": 0.1333, "x": 10.03, "y": -2.56 }, - { "time": 0.4, "x": 2.76, "y": -2.97 }, - { "time": 0.5333, "x": 2.76, "y": -2.81 }, - { "time": 0.9333, "x": 8.67, "y": -2.54 }, - { "time": 1.0666, "x": 8.11, "y": -2.36 } + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } ] }, - "left lower leg": { + "neck": { "rotate": [ - { "time": 0, "angle": -10.21 }, - { "time": 0.1333, "angle": -55.64 }, - { "time": 0.2666, "angle": -68.12 }, - { "time": 0.5333, "angle": 5.11 }, - { "time": 0.6666, "angle": -28.29 }, - { "time": 0.8, "angle": 4.08 }, - { "time": 0.9333, "angle": 3.53 }, - { "time": 1.0666, "angle": -10.21 } + { "time": 0, "angle": 11.03 }, + { "time": 0.2, "angle": 13.58 }, + { "time": 0.4, "angle": 11.03 }, + { "time": 0.6, "angle": 13.58 }, + { "time": 0.8, "angle": 11.03 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.4, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } ] }, - "left foot": { + "head": { "rotate": [ - { "time": 0, "angle": -3.69 }, - { "time": 0.1333, "angle": -10.42 }, - { "time": 0.2666, "angle": -17.14 }, - { "time": 0.4, "angle": -2.83 }, - { "time": 0.5333, "angle": -3.87 }, - { "time": 0.6666, "angle": 2.78 }, - { "time": 0.8, "angle": 1.68 }, - { "time": 0.9333, "angle": -8.54 }, - { "time": 1.0666, "angle": -3.69 } + { "time": 0, "angle": 11.03 }, + { "time": 0.1, "angle": 12.34 }, + { "time": 0.2, "angle": 25.55 }, + { "time": 0.4, "angle": 11.03 }, + { "time": 0.5, "angle": 12.34 }, + { "time": 0.6, "angle": 25.55 }, + { "time": 0.8, "angle": 11.03 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.4, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } ] }, - "right shoulder": { + "hip": { "rotate": [ + { "time": 0, "angle": 0, "curve": "stepped" }, + { "time": 0.8, "angle": 0 } + ], + "translate": [ + { "time": 0, "x": -62.47, "y": -23.1 }, { - "time": 0, - "angle": 20.89, - "curve": [ 0.264, 0, 0.75, 1 ] + "time": 0.0666, + "x": -62.47, + "y": -38.51, + "curve": [ 0.244, 0.04, 0.75, 1 ] }, { - "time": 0.1333, - "angle": 3.72, - "curve": [ 0.272, 0, 0.841, 1 ] + "time": 0.2666, + "x": -62.47, + "y": 22.28, + "curve": [ 0.17, 0.52, 0.75, 1 ] + }, + { "time": 0.4, "x": -62.47, "y": -23.1 }, + { "time": 0.4333, "x": -62.47, "y": -24.59 }, + { + "time": 0.4666, + "x": -62.47, + "y": -43.29, + "curve": [ 0.25, 0, 0.75, 1 ] }, - { "time": 0.6666, "angle": -278.28 }, - { "time": 1.0666, "angle": 20.89 } + { "time": 0.6666, "x": -62.47, "y": 22.28 }, + { "time": 0.8, "x": -62.47, "y": -23.1 } ], - "translate": [ - { "time": 0, "x": -7.84, "y": 7.19 }, - { "time": 0.1333, "x": -6.36, "y": 6.42 }, - { "time": 0.6666, "x": -11.07, "y": 5.25 }, - { "time": 1.0666, "x": -7.84, "y": 7.19 } + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } ] }, - "right arm": { + "front_shin": { "rotate": [ { "time": 0, - "angle": -4.02, - "curve": [ 0.267, 0, 0.804, 0.99 ] + "angle": 0, + "curve": [ 0.481, 0.01, 0.75, 1 ] }, + { "time": 0.0666, "angle": -64.42 }, { "time": 0.1333, - "angle": -13.99, - "curve": [ 0.341, 0, 1, 1 ] + "angle": -20.59, + "curve": [ 0.25, 0, 0.75, 1 ] }, + { "time": 0.2666, "angle": -62.51 }, + { "time": 0.3333, "angle": -79.74 }, + { "time": 0.4, "angle": -78.28 }, { - "time": 0.6666, - "angle": 36.54, - "curve": [ 0.307, 0, 0.787, 0.99 ] + "time": 0.4666, + "angle": -118.96, + "curve": [ 0.93, 0, 0.952, 0.95 ] }, - { "time": 1.0666, "angle": -4.02 } - ] - }, - "right hand": { - "rotate": [ - { "time": 0, "angle": 22.92 }, - { "time": 0.4, "angle": -8.97 }, - { "time": 0.6666, "angle": 0.51 }, - { "time": 1.0666, "angle": 22.92 } + { "time": 0.6, "angle": -88.95 }, + { "time": 0.6666, "angle": -79.09 }, + { "time": 0.7333, "angle": -47.77 }, + { "time": 0.8, "angle": 0 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } ] }, - "left shoulder": { + "front_foot": { "rotate": [ - { "time": 0, "angle": -1.47 }, - { "time": 0.1333, "angle": 13.6 }, - { "time": 0.6666, "angle": 280.74 }, - { "time": 1.0666, "angle": -1.47 } + { "time": 0, "angle": 0 }, + { + "time": 0.0333, + "angle": -21.13, + "curve": [ 0.121, 0.23, 0.75, 1 ] + }, + { "time": 0.0666, "angle": 17.64 }, + { "time": 0.1, "angle": 29.92 }, + { "time": 0.1333, "angle": 16.44 }, + { "time": 0.2, "angle": -29.22 }, + { "time": 0.2666, "angle": -1.61 }, + { "time": 0.3333, "angle": -10.22 }, + { "time": 0.4666, "angle": -15.99 }, + { "time": 0.6, "angle": 9.03 }, + { "time": 0.7333, "angle": 17.32 }, + { "time": 0.8, "angle": 0 } ], "translate": [ - { "time": 0, "x": -1.76, "y": 0.56 }, - { "time": 0.6666, "x": -2.47, "y": 8.14 }, - { "time": 1.0666, "x": -1.76, "y": 0.56 } + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } ] }, - "left hand": { + "rear_foot": { "rotate": [ + { "time": 0, "angle": 0 }, + { "time": 0.0666, "angle": -12.04 }, + { "time": 0.1333, "angle": -0.87 }, + { "time": 0.2, "angle": 25.81 }, + { "time": 0.2666, "angle": 4.71 }, { - "time": 0, - "angle": 11.58, - "curve": [ 0.169, 0.37, 0.632, 1.55 ] - }, - { - "time": 0.1333, - "angle": 28.13, - "curve": [ 0.692, 0, 0.692, 0.99 ] - }, - { - "time": 0.6666, - "angle": -27.42, - "curve": [ 0.117, 0.41, 0.738, 1.76 ] + "time": 0.4, + "angle": 18.09, + "curve": [ 0.281, 0.73, 0.75, 1 ] }, - { "time": 0.8, "angle": -36.32 }, - { "time": 1.0666, "angle": 11.58 } + { "time": 0.4333, "angle": -1.7 }, + { "time": 0.4666, "angle": 27.12 }, + { "time": 0.5, "angle": 38.83 }, + { "time": 0.5333, "angle": 30.76 }, + { "time": 0.5666, "angle": -20.49 }, + { "time": 0.6, "angle": -30.8 }, + { "time": 0.6666, "angle": -1.31 }, + { "time": 0.8, "angle": 0 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } ] }, - "left arm": { + "gun": { "rotate": [ - { "time": 0, "angle": -8.27 }, - { "time": 0.1333, "angle": 18.43 }, - { "time": 0.6666, "angle": 0.88 }, - { "time": 1.0666, "angle": -8.27 } + { "time": 0, "angle": 0 }, + { "time": 0.1333, "angle": 24.72 }, + { "time": 0.5, "angle": -11.87 }, + { "time": 0.8, "angle": 0 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } + ] + } + }, + "events": [ + { "time": 0, "name": "footstep" }, + { "time": 0.4, "name": "footstep", "int": 1 } + ] + }, + "shoot": { + "slots": { + "front_fist": { + "attachment": [ + { "time": 0.1333, "name": "front_fist_closed" }, + { "time": 0.4, "name": "front_fist_open" } ] }, - "torso": { - "rotate": [ - { "time": 0, "angle": -10.28 }, + "mouth": { + "attachment": [ + { "time": 0.1333, "name": "mouth_grind" } + ] + }, + "muzzle": { + "attachment": [ + { "time": 0.1333, "name": "muzzle" }, + { "time": 0.2666, "name": null } + ], + "color": [ { "time": 0.1333, - "angle": -15.38, - "curve": [ 0.545, 0, 1, 1 ] + "color": "ffffff00", + "curve": [ 0.118, 0.99, 0.75, 1 ] }, { - "time": 0.4, - "angle": -9.78, - "curve": [ 0.58, 0.17, 1, 1 ] + "time": 0.1666, + "color": "ffffffff", + "curve": [ 0.821, 0, 0.909, 0.89 ] }, - { "time": 0.6666, "angle": -15.75 }, - { "time": 0.9333, "angle": -7.06 }, - { "time": 1.0666, "angle": -10.28 } - ], - "translate": [ - { "time": 0, "x": -3.67, "y": 1.68 }, - { "time": 0.1333, "x": -3.67, "y": 0.68 }, - { "time": 0.4, "x": -3.67, "y": 1.97 }, - { "time": 0.6666, "x": -3.67, "y": -0.14 }, - { "time": 1.0666, "x": -3.67, "y": 1.68 } + { "time": 0.2666, "color": "ffffff00" } + ] + } + }, + "bones": { + "front_fist": { + "scale": [ + { "time": 0.1333, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.4, "x": 1, "y": 1 } ] }, - "right foot": { - "rotate": [ - { "time": 0, "angle": -5.25 }, - { "time": 0.2666, "angle": -4.08 }, - { "time": 0.4, "angle": -6.45 }, - { "time": 0.5333, "angle": -5.39 }, - { "time": 0.8, "angle": -11.68 }, - { "time": 0.9333, "angle": 0.46 }, - { "time": 1.0666, "angle": -5.25 } + "gunTip": { + "translate": [ + { "time": 0.1333, "x": 0, "y": 0 }, + { "time": 0.2, "x": 20.93, "y": 1.57 } + ], + "scale": [ + { "time": 0.1333, "x": 1, "y": 1 }, + { "time": 0.2, "x": 1.247, "y": 1.516 } ] }, - "right lower leg": { + "gun": { "rotate": [ - { "time": 0, "angle": -3.39 }, - { "time": 0.1333, "angle": -45.53 }, - { "time": 0.2666, "angle": -2.59 }, - { "time": 0.5333, "angle": -19.53 }, - { "time": 0.6666, "angle": -64.8 }, + { "time": 0, "angle": 1.9 } + ], + "translate": [ { - "time": 0.8, - "angle": -82.56, - "curve": [ 0.557, 0.18, 1, 1 ] + "time": 0, + "x": 7.95, + "y": 5.84, + "curve": [ 0, 0.3, 0.678, 1 ] }, - { "time": 1.0666, "angle": -3.39 } + { "time": 0.3, "x": -9.3, "y": -1.41 }, + { "time": 0.4, "x": 0, "y": 0 } ] }, - "hip": { + "rear_bracer": { "rotate": [ - { "time": 0, "angle": 0, "curve": "stepped" }, - { "time": 1.0666, "angle": 0 } + { "time": 0, "angle": -30.47 } ], "translate": [ - { "time": 0, "x": 0, "y": 0 }, { - "time": 0.1333, + "time": 0, "x": 0, - "y": -7.61, - "curve": [ 0.272, 0.86, 1, 1 ] + "y": 0, + "curve": [ 0, 0.3, 0.678, 1 ] }, - { "time": 0.4, "x": 0, "y": 8.7 }, - { "time": 0.5333, "x": 0, "y": -0.41 }, + { "time": 0.3, "x": -5.99, "y": -3.71 }, + { "time": 0.4, "x": 0, "y": 0 } + ] + }, + "rear_upper_arm": { + "rotate": [ + { "time": 0, "angle": 62.3 } + ], + "translate": [ { - "time": 0.6666, + "time": 0, "x": 0, - "y": -7.05, - "curve": [ 0.235, 0.89, 1, 1 ] + "y": 0, + "curve": [ 0, 0.3, 0.678, 1 ] }, - { "time": 0.8, "x": 0, "y": 2.92 }, - { "time": 0.9333, "x": 0, "y": 6.78 }, - { "time": 1.0666, "x": 0, "y": 0 } + { "time": 0.3, "x": 2.81, "y": 11.41 }, + { "time": 0.4, "x": 0, "y": 0 } + ] + } + } + }, + "test": { + "slots": { + "front_foot": { + "color": [ + { "time": 0.6666, "color": "ffffffff" }, + { "time": 1.3333, "color": "ff0700ff" } ] }, - "neck": { - "rotate": [ - { "time": 0, "angle": 3.6 }, - { "time": 0.1333, "angle": 17.49 }, - { "time": 0.2666, "angle": 6.1 }, - { "time": 0.4, "angle": 3.45 }, - { "time": 0.5333, "angle": 5.17 }, - { "time": 0.6666, "angle": 18.36 }, - { "time": 0.8, "angle": 6.09 }, - { "time": 0.9333, "angle": 2.28 }, - { "time": 1.0666, "angle": 3.6 } + "gun": { + "color": [ + { "time": 0, "color": "ffffffff", "curve": "stepped" }, + { "time": 0.6666, "color": "ffffffff" }, + { "time": 1.3333, "color": "32ff00ff" } ] }, + "rear_foot": { + "color": [ + { "time": 0.6666, "color": "ffffffff" }, + { "time": 1.3333, "color": "ff0700ff" } + ] + } + }, + "bones": { "head": { "rotate": [ + { "time": 0, "angle": 0 }, + { "time": 0.3333, "angle": -20.72 }, + { "time": 0.6666, "angle": -32.41 }, + { "time": 1, "angle": -5.3 }, + { "time": 1.3333, "angle": 24.96 }, + { "time": 1.6666, "angle": 15.61 }, + { "time": 2, "angle": 0 } + ], + "translate": [ { "time": 0, - "angle": 3.6, - "curve": [ 0, 0, 0.704, 1.61 ] + "x": 0, + "y": 0, + "curve": [ 0.172, 0.37, 0.574, 0.73 ] }, - { "time": 0.1666, "angle": -0.2 }, - { "time": 0.2666, "angle": 6.1 }, - { "time": 0.4, "angle": 3.45 }, { - "time": 0.5333, - "angle": 5.17, - "curve": [ 0, 0, 0.704, 1.61 ] + "time": 0.1666, + "x": 144.19, + "y": -77.59, + "curve": [ 0.372, 0.61, 0.765, 1 ] + }, + { + "time": 0.3333, + "x": 217.61, + "y": -192.63, + "curve": [ 0.282, 0, 0.624, 0.31 ] + }, + { + "time": 0.5, + "x": 181.21, + "y": -365.66, + "curve": [ 0.313, 0.21, 0.654, 0.54 ] + }, + { + "time": 0.6666, + "x": 20.09, + "y": -500.4, + "curve": [ 0.147, 0.27, 0.75, 1 ] + }, + { "time": 0.8333, "x": -194.24, "y": -341.84 }, + { "time": 1, "x": -307.93, "y": -114 }, + { + "time": 1.1666, + "x": -330.38, + "y": 121.42, + "curve": [ 0.25, 0, 0.764, 0.48 ] + }, + { + "time": 1.3333, + "x": -240.42, + "y": 335.66, + "curve": [ 0.229, 0.37, 0.58, 0.73 ] }, - { "time": 0.7, "angle": 1.1 }, - { "time": 0.8, "angle": 6.09 }, - { "time": 0.9333, "angle": 2.28 }, - { "time": 1.0666, "angle": 3.6 } + { + "time": 1.5, + "x": -56.12, + "y": 288.06, + "curve": [ 0.296, 0.6, 0.641, 1 ] + }, + { + "time": 1.6666, + "x": 87.63, + "y": 191.33, + "curve": [ 0.238, 0, 0.626, 0.39 ] + }, + { + "time": 1.8333, + "x": 60.62, + "y": 95.14, + "curve": [ 0.41, 0.26, 0.803, 0.62 ] + }, + { "time": 2, "x": 0, "y": 0 } ] } - } + }, + "draworder": [ + { + "time": 0.6666, + "offsets": [ + { "slot": "head", "offset": -9 }, + { "slot": "eye", "offset": -9 }, + { "slot": "mouth", "offset": -12 }, + { "slot": "goggles", "offset": -12 } + ] + }, + { "time": 1.3333 } + ], + "events": [ + { "time": 0, "name": "headPop", "int": 0, "float": 0, "string": "pop.wav" }, + { "time": 1, "name": "headBehind", "int": 7, "float": 8, "string": "animate" }, + { "time": 2, "name": "headAttach", "int": 0, "float": 0, "string": "attach.wav" } + ] }, - "jump": { + "walk": { + "slots": { + "front_fist": { + "attachment": [ + { "time": 0, "name": "front_fist_closed" } + ] + }, + "mouth": { + "attachment": [ + { "time": 0, "name": "mouth_smile" } + ] + }, + "torso": { + "attachment": [ + { "time": 0, "name": "torso" } + ] + } + }, "bones": { - "hip": { + "front_thigh": { "rotate": [ - { "time": 0, "angle": 0, "curve": "stepped" }, - { "time": 0.9333, "angle": 0, "curve": "stepped" }, - { "time": 1.3666, "angle": 0 } + { "time": 0, "angle": 15.79 }, + { "time": 0.1, "angle": 27.39 }, + { "time": 0.2, "angle": -7.94 }, + { "time": 0.3, "angle": -16.94 }, + { "time": 0.4, "angle": -28.62 }, + { "time": 0.5, "angle": -19.3 }, + { "time": 0.6, "angle": -3.08 }, + { "time": 0.7, "angle": 29.51 }, + { "time": 0.8, "angle": 15.79 } ], "translate": [ - { "time": 0, "x": -11.57, "y": -3 }, - { "time": 0.2333, "x": -16.2, "y": -19.43 }, - { - "time": 0.3333, - "x": 7.66, - "y": -8.48, - "curve": [ 0.057, 0.06, 0.712, 1 ] - }, - { "time": 0.3666, "x": 15.38, "y": 5.01 }, - { "time": 0.4666, "x": -7.84, "y": 57.22 }, - { - "time": 0.6, - "x": -10.81, - "y": 96.34, - "curve": [ 0.241, 0, 1, 1 ] - }, - { "time": 0.7333, "x": -7.01, "y": 54.7 }, - { "time": 0.8, "x": -10.58, "y": 32.2 }, - { "time": 0.9333, "x": -31.99, "y": 0.45 }, - { "time": 1.0666, "x": -12.48, "y": -29.47 }, - { "time": 1.3666, "x": -11.57, "y": -3 } + { "time": 0, "x": 0, "y": 0 }, + { "time": 0.4, "x": -1.18, "y": 0.54 }, + { "time": 0.5, "x": 0.11, "y": 0.41 }, + { "time": 0.6, "x": 9.48, "y": 0.27 }, + { "time": 0.8, "x": 0, "y": 0 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.4, "x": 1, "y": 1, "curve": "stepped" }, + { "time": 0.8, "x": 1, "y": 1 } ] }, - "left upper leg": { + "front_shin": { "rotate": [ - { "time": 0, "angle": 17.13 }, - { "time": 0.2333, "angle": 44.35 }, - { "time": 0.3333, "angle": 16.46 }, - { "time": 0.4, "angle": -9.88 }, - { "time": 0.4666, "angle": -11.42 }, - { "time": 0.5666, "angle": 23.46 }, - { "time": 0.7666, "angle": 71.82 }, - { "time": 0.9333, "angle": 65.53 }, - { "time": 1.0666, "angle": 51.01 }, - { "time": 1.3666, "angle": 17.13 } + { "time": 0, "angle": 5.12 }, + { "time": 0.1, "angle": -20.87 }, + { "time": 0.2, "angle": 13.37 }, + { "time": 0.3, "angle": 15.98 }, + { "time": 0.4, "angle": 5.94 }, + { "time": 0.5, "angle": -26.76 }, + { "time": 0.7, "angle": -55.44 }, + { "time": 0.8, "angle": 5.12 } ], "translate": [ - { "time": 0, "x": -3, "y": -2.25, "curve": "stepped" }, - { "time": 0.9333, "x": -3, "y": -2.25, "curve": "stepped" }, - { "time": 1.3666, "x": -3, "y": -2.25 } + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.8, "x": 1, "y": 1 } ] }, - "left lower leg": { + "rear_thigh": { "rotate": [ - { "time": 0, "angle": -16.25 }, - { "time": 0.2333, "angle": -52.21 }, - { "time": 0.4, "angle": 15.04 }, - { "time": 0.4666, "angle": -8.95 }, - { "time": 0.5666, "angle": -39.53 }, - { "time": 0.7666, "angle": -27.27 }, - { "time": 0.9333, "angle": -3.52 }, - { "time": 1.0666, "angle": -61.92 }, - { "time": 1.3666, "angle": -16.25 } + { "time": 0, "angle": -34.38 }, + { "time": 0.1, "angle": -30.32 }, + { "time": 0.2, "angle": -37.22 }, + { "time": 0.3, "angle": 20.73 }, + { "time": 0.4, "angle": 8.69 }, + { "time": 0.5, "angle": 12.16 }, + { "time": 0.6, "angle": -24.62 }, + { "time": 0.7, "angle": -27.26 }, + { "time": 0.8, "angle": -34.38 } ], "translate": [ - { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 0.9333, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 1.3666, "x": 0, "y": 0 } + { "time": 0, "x": 0, "y": 0 }, + { "time": 0.4, "x": 4.08, "y": -9.53 }, + { "time": 0.5, "x": 0, "y": 0 }, + { "time": 0.7, "x": -21.14, "y": -9.6 }, + { "time": 0.8, "x": 0, "y": 0 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.8, "x": 1, "y": 1 } ] }, - "left foot": { + "rear_shin": { "rotate": [ - { "time": 0, "angle": 0.33 }, - { "time": 0.2333, "angle": 6.2 }, - { "time": 0.3333, "angle": 14.73 }, - { "time": 0.4, "angle": -15.54 }, - { "time": 0.4333, "angle": -21.2 }, - { "time": 0.5666, "angle": -7.55 }, - { "time": 0.7666, "angle": -0.67 }, - { "time": 0.9333, "angle": -0.58 }, - { "time": 1.0666, "angle": 14.64 }, - { "time": 1.3666, "angle": 0.33 } + { "time": 0, "angle": 14.26 }, + { "time": 0.1, "angle": -17.3 }, + { "time": 0.2, "angle": -12.67 }, + { "time": 0.3, "angle": -58.89 }, + { "time": 0.4, "angle": 15.95 }, + { "time": 0.5, "angle": -9 }, + { "time": 0.6, "angle": 26.06 }, + { "time": 0.7, "angle": 21.85 }, + { "time": 0.8, "angle": 14.26 } ], "translate": [ { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 0.9333, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 1.3666, "x": 0, "y": 0 } + { "time": 0.8, "x": 0, "y": 0 } ], "scale": [ - { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0, "x": 1, "y": 1 }, + { "time": 0.1, "x": 0.951, "y": 1 }, + { "time": 0.5, "x": 0.975, "y": 1 }, + { "time": 0.8, "x": 1, "y": 1 } ] }, - "right upper leg": { + "rear_foot": { "rotate": [ - { "time": 0, "angle": 25.97 }, - { "time": 0.2333, "angle": 46.43 }, - { "time": 0.3333, "angle": 22.61 }, - { "time": 0.4, "angle": 2.13 }, - { - "time": 0.4666, - "angle": 0.04, - "curve": [ 0, 0, 0.637, 0.98 ] - }, - { "time": 0.6, "angle": 65.55 }, - { "time": 0.7666, "angle": 64.93 }, - { "time": 0.9333, "angle": 41.08 }, - { "time": 1.0666, "angle": 66.25 }, - { "time": 1.3666, "angle": 25.97 } + { "time": 0, "angle": 10.13 }, + { "time": 0.1, "angle": 12.27 }, + { "time": 0.2, "angle": -2.94 }, + { "time": 0.3, "angle": 6.29 }, + { "time": 0.4, "angle": 13.45 }, + { "time": 0.5, "angle": -3.57 }, + { "time": 0.6, "angle": -0.97 }, + { "time": 0.7, "angle": 2.97 }, + { "time": 0.8, "angle": 10.13 } ], "translate": [ - { "time": 0, "x": 5.74, "y": 0.61 }, - { "time": 0.2333, "x": 4.79, "y": 1.79 }, - { "time": 0.3333, "x": 6.05, "y": -4.55 }, - { "time": 0.9333, "x": 4.79, "y": 1.79, "curve": "stepped" }, - { "time": 1.0666, "x": 4.79, "y": 1.79 }, - { "time": 1.3666, "x": 5.74, "y": 0.61 } + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.8, "x": 1, "y": 1 } ] }, - "right lower leg": { + "front_upper_arm": { "rotate": [ - { "time": 0, "angle": -27.46 }, - { "time": 0.2333, "angle": -64.03 }, - { "time": 0.4, "angle": -48.36 }, - { "time": 0.5666, "angle": -76.86 }, - { "time": 0.7666, "angle": -26.89 }, - { "time": 0.9, "angle": -18.97 }, - { "time": 0.9333, "angle": -14.18 }, - { "time": 1.0666, "angle": -80.45 }, - { "time": 1.3666, "angle": -27.46 } + { "time": 0, "angle": -23.74 }, + { "time": 0.4, "angle": -320.57 }, + { "time": 0.8, "angle": -23.74 } ], "translate": [ { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 0.9333, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 1.3666, "x": 0, "y": 0 } + { "time": 0.8, "x": 0, "y": 0 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.8, "x": 1, "y": 1 } ] }, - "right foot": { + "rear_upper_arm": { "rotate": [ - { "time": 0, "angle": 1.08 }, - { "time": 0.2333, "angle": 16.02 }, - { "time": 0.3, "angle": 12.94 }, - { "time": 0.3333, "angle": 15.16 }, - { "time": 0.4, "angle": -14.7 }, - { "time": 0.4333, "angle": -12.85 }, - { "time": 0.4666, "angle": -19.18 }, - { "time": 0.5666, "angle": -15.82 }, - { "time": 0.6, "angle": -3.59 }, - { "time": 0.7666, "angle": -3.56 }, - { "time": 0.9333, "angle": 1.86 }, - { "time": 1.0666, "angle": 16.02 }, - { "time": 1.3666, "angle": 1.08 } + { "time": 0, "angle": 11.62 }, + { "time": 0.1, "angle": 19.36 }, + { "time": 0.4, "angle": 345.26 }, + { "time": 0.5, "angle": 343.44 }, + { "time": 0.8, "angle": 11.62 } ], "translate": [ { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 0.9333, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 1.3666, "x": 0, "y": 0 } + { "time": 0.8, "x": 0, "y": 0 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.8, "x": 1, "y": 1 } ] }, "torso": { "rotate": [ - { "time": 0, "angle": -13.35 }, - { "time": 0.2333, "angle": -48.95 }, - { "time": 0.4333, "angle": -35.77 }, - { "time": 0.6, "angle": -4.59 }, - { "time": 0.7666, "angle": 14.61 }, - { "time": 0.9333, "angle": 15.74 }, - { "time": 1.0666, "angle": -32.44 }, - { "time": 1.3666, "angle": -13.35 } - ], - "translate": [ - { "time": 0, "x": -3.67, "y": 1.68, "curve": "stepped" }, - { "time": 0.9333, "x": -3.67, "y": 1.68, "curve": "stepped" }, - { "time": 1.3666, "x": -3.67, "y": 1.68 } + { "time": 0, "angle": -12.11 }, + { "time": 0.1666, "angle": -17.16 }, + { "time": 0.4, "angle": -12.11 }, + { "time": 0.5666, "angle": -15.81 }, + { "time": 0.8, "angle": -12.11 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.8, "x": 1, "y": 1 } ] }, "neck": { "rotate": [ - { "time": 0, "angle": 12.78 }, - { "time": 0.2333, "angle": 16.46 }, - { "time": 0.4, "angle": 26.49 }, - { "time": 0.6, "angle": 15.51 }, - { "time": 0.7666, "angle": 1.34 }, - { "time": 0.9333, "angle": 2.35 }, - { "time": 1.0666, "angle": 6.08 }, - { "time": 1.3, "angle": 21.23 }, - { "time": 1.3666, "angle": 12.78 } + { "time": 0, "angle": 1.41 }, + { "time": 0.2333, "angle": -3.04 }, + { "time": 0.4, "angle": 1.41 }, + { "time": 0.6333, "angle": -3.04 }, + { "time": 0.8, "angle": 1.41 } ], "translate": [ { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 0.9333, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 1.3666, "x": 0, "y": 0 } + { "time": 0.4, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.8, "x": 1, "y": 1 } ] }, "head": { "rotate": [ - { "time": 0, "angle": 5.19 }, - { "time": 0.2333, "angle": 20.27 }, - { "time": 0.4, "angle": 15.27 }, - { "time": 0.6, "angle": -24.69 }, - { "time": 0.7666, "angle": -11.02 }, - { "time": 0.9333, "angle": -24.38 }, - { "time": 1.0666, "angle": 11.99 }, - { "time": 1.3, "angle": 4.86 }, - { "time": 1.3666, "angle": 5.19 } + { "time": 0, "angle": 6.97 }, + { "time": 0.1666, "angle": 8.02 }, + { "time": 0.2666, "angle": 12.65 }, + { "time": 0.4, "angle": 6.97 }, + { "time": 0.5666, "angle": 8.02 }, + { "time": 0.6666, "angle": 12.65 }, + { "time": 0.8, "angle": 6.97 } ], "translate": [ { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 0.9333, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 1.3666, "x": 0, "y": 0 } + { "time": 0.4, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.8, "x": 1, "y": 1 } ] }, - "left shoulder": { + "hip": { "rotate": [ + { "time": 0, "angle": 0, "curve": "stepped" }, + { "time": 0.8, "angle": 0 } + ], + "translate": [ { "time": 0, - "angle": 0.05, - "curve": [ 0, 0, 0.62, 1 ] + "x": -23.93, + "y": 3.22, + "curve": [ 0.518, 0.03, 0.807, 0.61 ] + }, + { + "time": 0.1, + "x": -23.93, + "y": -9.24, + "curve": [ 0.135, 0.33, 0.601, 0.99 ] + }, + { + "time": 0.2, + "x": -23.93, + "y": 4.35, + "curve": [ 0.204, 0.68, 0.75, 1 ] + }, + { + "time": 0.3, + "x": -23.93, + "y": 2.38, + "curve": [ 0.25, 0, 0.75, 1 ] }, { - "time": 0.2333, - "angle": 279.66, - "curve": [ 0.218, 0.67, 0.66, 0.99 ] + "time": 0.4, + "x": -23.93, + "y": -2.5, + "curve": [ 0.692, 0.01, 0.75, 1 ] }, { "time": 0.5, - "angle": 62.27, - "curve": [ 0.462, 0, 0.764, 0.58 ] + "x": -23.93, + "y": -10.32, + "curve": [ 0.235, 0.77, 0.75, 1 ] }, - { "time": 0.9333, "angle": 28.91 }, - { "time": 1.0666, "angle": -8.62 }, - { "time": 1.1666, "angle": -18.43 }, - { "time": 1.3666, "angle": 0.05 } - ], - "translate": [ - { "time": 0, "x": -1.76, "y": 0.56, "curve": "stepped" }, - { "time": 0.9333, "x": -1.76, "y": 0.56, "curve": "stepped" }, - { "time": 1.3666, "x": -1.76, "y": 0.56 } + { + "time": 0.6, + "x": -23.93, + "y": 4.35, + "curve": [ 0.287, 0.37, 0.718, 0.76 ] + }, + { + "time": 0.7, + "x": -23.93, + "y": 10.34, + "curve": [ 0.615, 0, 0.75, 1 ] + }, + { "time": 0.8, "x": -23.93, "y": 3.22 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.8, "x": 1, "y": 1 } ] }, - "left hand": { + "front_bracer": { "rotate": [ - { "time": 0, "angle": 11.58, "curve": "stepped" }, - { "time": 0.9333, "angle": 11.58, "curve": "stepped" }, - { "time": 1.3666, "angle": 11.58 } + { "time": 0, "angle": 0 }, + { "time": 0.4, "angle": 20.59 }, + { "time": 0.8, "angle": 0 } ], "translate": [ { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 0.9333, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 1.3666, "x": 0, "y": 0 } + { "time": 0.8, "x": 0, "y": 0 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.8, "x": 1, "y": 1 } ] }, - "left arm": { + "front_foot": { "rotate": [ - { "time": 0, "angle": 0.51 }, - { "time": 0.4333, "angle": 12.82 }, - { "time": 0.6, "angle": 47.55 }, - { "time": 0.9333, "angle": 12.82 }, - { "time": 1.1666, "angle": -6.5 }, - { "time": 1.3666, "angle": 0.51 } + { "time": 0, "angle": 12.49 }, + { "time": 0.1, "angle": -8.34 }, + { "time": 0.2, "angle": -6.17 }, + { "time": 0.3, "angle": -0.75 }, + { "time": 0.3333, "angle": 3.89 }, + { "time": 0.4, "angle": 10.22 }, + { "time": 0.5, "angle": 11.44 }, + { "time": 0.6, "angle": -0.33 }, + { "time": 0.7, "angle": 0.15 }, + { "time": 0.8, "angle": 12.49 } ], "translate": [ { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 0.9333, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 1.3666, "x": 0, "y": 0 } + { "time": 0.8, "x": 0, "y": 0 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.8, "x": 1, "y": 1 } ] }, - "right shoulder": { + "rear_bracer": { "rotate": [ - { - "time": 0, - "angle": 43.82, - "curve": [ 0, 0, 0.62, 1 ] - }, - { - "time": 0.2333, - "angle": -8.74, - "curve": [ 0.304, 0.58, 0.709, 0.97 ] - }, - { - "time": 0.5333, - "angle": -208.02, - "curve": [ 0.462, 0, 0.764, 0.58 ] - }, - { "time": 0.9333, "angle": -246.72 }, - { "time": 1.0666, "angle": -307.13 }, - { "time": 1.1666, "angle": 37.15 }, - { "time": 1.3666, "angle": 43.82 } + { "time": 0, "angle": 3.58 }, + { "time": 0.1, "angle": 5.51 }, + { "time": 0.4, "angle": -22.77 }, + { "time": 0.5, "angle": -9.65 }, + { "time": 0.8, "angle": 3.58 } ], "translate": [ - { "time": 0, "x": -7.84, "y": 7.19, "curve": "stepped" }, - { "time": 0.9333, "x": -7.84, "y": 7.19, "curve": "stepped" }, - { "time": 1.3666, "x": -7.84, "y": 7.19 } + { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, + { "time": 0.8, "x": 0, "y": 0 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.8, "x": 1, "y": 1 } ] }, - "right arm": { + "front_fist": { "rotate": [ - { "time": 0, "angle": -4.02 }, - { "time": 0.6, "angle": 17.5 }, - { "time": 0.9333, "angle": -4.02 }, - { "time": 1.1666, "angle": -16.72 }, - { "time": 1.3666, "angle": -4.02 } + { "time": 0, "angle": -15.22 }, + { "time": 0.1, "angle": -51.4 }, + { "time": 0.4, "angle": -39.4 }, + { "time": 0.5, "angle": 19.26 }, + { "time": 0.8, "angle": -15.22 } ], "translate": [ { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 0.9333, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 1.3666, "x": 0, "y": 0 } + { "time": 0.8, "x": 0, "y": 0 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.8, "x": 1, "y": 1 } ] }, - "right hand": { + "gun": { "rotate": [ - { "time": 0, "angle": 22.92, "curve": "stepped" }, - { "time": 0.9333, "angle": 22.92, "curve": "stepped" }, - { "time": 1.3666, "angle": 22.92 } + { + "time": 0, + "angle": -24.06, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { + "time": 0.1, + "angle": -10.94, + "curve": [ 0.381, 0.54, 0.742, 1 ] + }, + { + "time": 0.4, + "angle": 25.34, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { + "time": 0.6666, + "angle": -27.47, + "curve": [ 0.25, 0, 0.75, 1 ] + }, + { "time": 0.8, "angle": -24.06 } ], "translate": [ { "time": 0, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 0.9333, "x": 0, "y": 0, "curve": "stepped" }, - { "time": 1.3666, "x": 0, "y": 0 } - ], - "scale": [ - { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 0.9333, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } - ] - }, - "root": { - "rotate": [ - { "time": 0, "angle": 0 }, - { "time": 0.4333, "angle": -14.52 }, - { "time": 0.8, "angle": 9.86 }, - { "time": 1.3666, "angle": 0 } + { "time": 0.8, "x": 0, "y": 0 } ], "scale": [ { "time": 0, "x": 1, "y": 1, "curve": "stepped" }, - { "time": 1.3666, "x": 1, "y": 1 } + { "time": 0.8, "x": 1, "y": 1 } ] } } diff --git a/samples/js-tests/res/skeletons/spineboy.png b/samples/js-tests/res/skeletons/spineboy.png index b8b493dfd1..b43262310a 100644 Binary files a/samples/js-tests/res/skeletons/spineboy.png and b/samples/js-tests/res/skeletons/spineboy.png differ diff --git a/samples/js-tests/res/skeletons/sprite.png b/samples/js-tests/res/skeletons/sprite.png new file mode 100644 index 0000000000..91dd465337 Binary files /dev/null and b/samples/js-tests/res/skeletons/sprite.png differ diff --git a/samples/js-tests/src/ActionsTest/ActionsTest.js b/samples/js-tests/src/ActionsTest/ActionsTest.js index 1a9e063154..8fae9eecaa 100644 --- a/samples/js-tests/src/ActionsTest/ActionsTest.js +++ b/samples/js-tests/src/ActionsTest/ActionsTest.js @@ -2638,6 +2638,30 @@ var Issue1446 = ActionsDemo.extend({ } }); +var SequenceRepeatTest = ActionsDemo.extend({ + onEnter:function () { + //----start47----onEnter + this._super(); + this.centerSprites(2); + + this._kathia.runAction(cc.repeat(cc.sequence(cc.blink(2, 3), cc.delayTime(2)), 3)); + + var move = cc.moveBy(1, cc.p(50, 0)); + var move_back = move.reverse(); + var move_seq = cc.sequence(move, cc.delayTime(1), move_back, cc.delayTime(1)); + this._tamara.runAction(move_seq.repeat(3)); + //----end47---- + }, + + title:function () { + return "Sequence.repeat()"; + }, + + subtitle:function () { + return "Tests sequence.repeat function."; + } +}); + //- // // Flow control @@ -2692,7 +2716,8 @@ var arrayOfActionsTest = [ Issue1327, ActionAnimate, Issue1438, - Issue1446 + Issue1446, + SequenceRepeatTest ]; if("opengl" in cc.sys.capabilities){ diff --git a/samples/js-tests/src/BakeLayerTest/BakeLayerTest.js b/samples/js-tests/src/BakeLayerTest/BakeLayerTest.js index bc3a202162..12b6af4993 100644 --- a/samples/js-tests/src/BakeLayerTest/BakeLayerTest.js +++ b/samples/js-tests/src/BakeLayerTest/BakeLayerTest.js @@ -89,9 +89,14 @@ var BakeLayerTest1 = BakeLayerBaseTest.extend({ menu.y = winSize.height - 120; this.addChild(menu, 10); + var rootLayer = new cc.Layer(); + rootLayer.setPosition(20,20); + this.addChild(rootLayer); + var bakeLayer = new cc.Layer(); bakeLayer.bake(); - this.addChild(bakeLayer); + bakeLayer.setRotation(30); + rootLayer.addChild(bakeLayer); for(var i = 0; i < 9; i++){ var sprite1 = new cc.Sprite(s_pathGrossini); @@ -144,16 +149,21 @@ var BakeLayerColorTest = BakeLayerBaseTest.extend({ menu.y = winSize.height - 120; this.addChild(menu, 10); + var rootLayer = new cc.Layer(); + rootLayer.setPosition(20,20); + this.addChild(rootLayer); + //var bakeLayer = cc.LayerColor.create(cc.color(128,0, 128, 128), 700, 300); //test for LayerColor //bakeLayer.setPosition(60, 80); var bakeLayer = new cc.LayerGradient(cc.color(128,0, 128, 255), cc.color(0, 0, 128, 255)); bakeLayer.setPosition(60, 80); bakeLayer.setContentSize(700, 300); + bakeLayer.setRotation(30); //bakeLayer.setPosition(winSize.width /2, winSize.height /2); //test for ignoreAnchorPointForPosition //bakeLayer.ignoreAnchorPointForPosition(false); - this.addChild(bakeLayer); + rootLayer.addChild(bakeLayer); for(var i = 0; i < 9; i++){ var sprite1 = new cc.Sprite(s_pathGrossini); diff --git a/samples/js-tests/src/BillBoardTest/BillBoardTest.js b/samples/js-tests/src/BillBoardTest/BillBoardTest.js new file mode 100644 index 0000000000..d81c74f1bc --- /dev/null +++ b/samples/js-tests/src/BillBoardTest/BillBoardTest.js @@ -0,0 +1,359 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ +var BillBoardTestIdx = -1; + +var BillBoardTestDemo = cc.Layer.extend({ + _title:"", + _subtitle:"", + + ctor:function () { + this._super(); + }, + + // + // Menu + // + onEnter:function () { + this._super(); + + var label = new cc.LabelTTF(this._title, "Arial", 28); + this.addChild(label, 100, BASE_TEST_TITLE_TAG); + label.x = winSize.width / 2; + label.y = winSize.height - 50; + + var label2 = new cc.LabelTTF(this._subtitle, "Thonburi", 16); + this.addChild(label2, 101, BASE_TEST_SUBTITLE_TAG); + label2.x = winSize.width / 2; + label2.y = winSize.height - 80; + + var item1 = new cc.MenuItemImage(s_pathB1, s_pathB2, this.onBackCallback, this); + var item2 = new cc.MenuItemImage(s_pathR1, s_pathR2, this.onRestartCallback, this); + var item3 = new cc.MenuItemImage(s_pathF1, s_pathF2, this.onNextCallback, this); + + item1.tag = BASE_TEST_MENUITEM_PREV_TAG; + item2.tag = BASE_TEST_MENUITEM_RESET_TAG; + item3.tag = BASE_TEST_MENUITEM_NEXT_TAG; + + var menu = new cc.Menu(item1, item2, item3); + + menu.x = 0; + menu.y = 0; + var width = item2.width, height = item2.height; + item1.x = winSize.width/2 - width*2; + item1.y = height/2 ; + item2.x = winSize.width/2; + item2.y = height/2 ; + item3.x = winSize.width/2 + width*2; + item3.y = height/2 ; + + this.addChild(menu, 102, BASE_TEST_MENU_TAG); + }, + + onRestartCallback:function (sender) { + var s = new BillBoardTestScene(); + s.addChild(restartBillBoardTest()); + director.runScene(s); + }, + + onNextCallback:function (sender) { + var s = new BillBoardTestScene(); + s.addChild(nextBillBoardTest()); + director.runScene(s); + }, + + onBackCallback:function (sender) { + var s = new BillBoardTestScene(); + s.addChild(previousBillBoardTest()); + director.runScene(s); + }, +}); + +var BillBoardTestScene = cc.Scene.extend({ + ctor:function () { + this._super(); + + var label = new cc.LabelTTF("Main Menu", "Arial", 20); + var menuItem = new cc.MenuItemLabel(label, this.onMainMenuCallback, this); + + var menu = new cc.Menu(menuItem); + menu.x = 0; + menu.y = 0; + menuItem.x = winSize.width - 50; + menuItem.y = 25; + this.addChild(menu); + }, + onMainMenuCallback:function () { + var scene = new cc.Scene(); + var layer = new TestController(); + scene.addChild(layer); + director.runScene(scene); + }, + runThisTest:function (num) { + BillBoardTestIdx = (num || num == 0) ? (num - 1) : -1; + var layer = nextBillBoardTest(); + this.addChild(layer); + + director.runScene(this); + } +}); + +var BillBoardRotationTest = BillBoardTestDemo.extend({ + _title:"Rotation Test", + _subtitle:"All the sprites should still facing camera", + + ctor:function(){ + this._super(); + + var root = new jsb.Sprite3D(); + root.setNormalizedPosition(cc.p(0.5, 0.25)); + this.addChild(root); + + var model = new jsb.Sprite3D("Sprite3DTest/orc.c3b"); + model.setScale(5); + model.setRotation3D(cc.math.vec3(0, 180, 0)); + root.addChild(model); + + var bill = new jsb.BillBoard(); + bill.setPosition(0, 120); + root.addChild(bill); + + var sp = new cc.Sprite("Images/SpookyPeas.png"); + bill.addChild(sp); + + var label = new cc.LabelTTF("+100"); + label.setPosition(0, 30); + bill.addChild(label); + + root.runAction(cc.rotateBy(10, cc.math.vec3(0, 360, 0)).repeatForever()); + + var jump = cc.jumpBy(1, cc.p(0, 0), 30, 1); + var scale = cc.scaleBy(2, 2, 2, 0.1); + var rot = cc.rotateBy(2, cc.math.vec3(-90, 0, 0)); + model.runAction(cc.sequence(cc.spawn(cc.sequence(jump, scale), rot), cc.spawn(scale.reverse(), rot.reverse())).repeatForever()); + } +}); + +var BillBoardTest = BillBoardTestDemo.extend({ + _title:"BillBoard Test", + _subtitle:"", + _camera:null, + _layerBillBorad:null, + _billboards:[], + + ctor:function(){ + this._super(); + + //Create touch listener + cc.eventManager.addListener({ + event:cc.EventListener.TOUCH_ALL_AT_ONCE, + onTouchesMoved:this.onTouchesMoved.bind(this) + }, this); + + var layer3D = new cc.Layer(); + this.addChild(layer3D, 0); + this._layerBillBorad = layer3D; + + var s = cc.winSize; + if(!this._camera){ + this._camera = cc.Camera.createPerspective(60, s.width/s.height, 1, 500); + this._camera.setCameraFlag(cc.CameraFlag.USER1); + this._layerBillBorad.addChild(this._camera); + } + + //Create rotating billboards + var imgs = ["Images/Icon.png", "Images/r2.png"]; + for(var i = 0; i < 4; ++i){ + var layer = new cc.Layer(); + var billboard = new jsb.BillBoard(imgs[Math.floor(Math.random() + 0.5)]); + billboard.setScale(0.5); + billboard.setPosition3D(cc.math.vec3(0, 0, (Math.random() * 2 - 1) * 150)); + billboard.setOpacity(Math.random() * 128 + 128); + this._billboards.push(billboard); + layer.addChild(billboard); + this._layerBillBorad.addChild(layer); + layer.runAction(cc.rotateBy(Math.random() * 10, cc.math.vec3(0, 45, 0)).repeatForever()); + } + + { + var billboard1 = new jsb.BillBoard("Images/Icon.png"); + billboard1.setScale(0.2); + billboard1.setPosition3D(cc.math.vec3(0, 30, 0)); + + var billboard2 = new jsb.BillBoard("Images/r2.png"); + billboard2.setPosition3D(cc.math.vec3(0, 0, 100)); + billboard1.addChild(billboard2); + this._billboards.push(billboard1); + this._billboards.push(billboard2); + + var sprite3d = new jsb.Sprite3D("Sprite3DTest/orc.c3b"); + sprite3d.setScale(2); + sprite3d.addChild(billboard1); + sprite3d.runAction(cc.rotateBy(10, cc.math.vec3(0, 360, 0)).repeatForever()); + this._layerBillBorad.addChild(sprite3d); + } + + this.addNewBillBoradWithCoords(cc.math.vec3(20, 5, 0)); + this.addNewBillBoradWithCoords(cc.math.vec3(60, 5, 0)); + this.addNewBillBoradWithCoords(cc.math.vec3(100, 5, 0)); + this.addNewBillBoradWithCoords(cc.math.vec3(140, 5, 0)); + this.addNewBillBoradWithCoords(cc.math.vec3(180, 5, 0)); + + this.addNewAniBillBoradWithCoords(cc.math.vec3(-20, 0, 0)); + this.addNewAniBillBoradWithCoords(cc.math.vec3(-60, 0, 0)); + this.addNewAniBillBoradWithCoords(cc.math.vec3(-100, 0, 0)); + this.addNewAniBillBoradWithCoords(cc.math.vec3(-140, 0, 0)); + this.addNewAniBillBoradWithCoords(cc.math.vec3(-180, 0, 0)); + + this._camera.setPosition3D(cc.math.vec3(0, 100, 230)); + this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); + + this._layerBillBorad.setCameraMask(2); + + var label1 = new cc.LabelTTF("rotate+", "Arial", 16); + var item1 = new cc.MenuItemLabel(label1, function(){ + var rotation3D = this._camera.getRotation3D(); + rotation3D.y += 10; + this._camera.setRotation3D(rotation3D); + }, this); + var label2 = new cc.LabelTTF("rotate-", "Arial", 16); + var item2 = new cc.MenuItemLabel(label2, function(){ + var rotation3D = this._camera.getRotation3D(); + rotation3D.y -= 10; + this._camera.setRotation3D(rotation3D); + }, this); + var label3 = new cc.LabelTTF("Point Oriented", "Arial", 16); + var item3 = new cc.MenuItemLabel(label3, this.menuCallback_orientedPoint, this); + var label4 = new cc.LabelTTF("Plane Oriented", "Arial", 16); + var item4 = new cc.MenuItemLabel(label4, this.menuCallback_orientedPlane, this); + + item1.setPosition(cc.p(s.width-80, s.height-160)); + item2.setPosition(cc.p(s.width-80, s.height-190)); + item3.setPosition(cc.p(s.width-80, s.height-100)); + item4.setPosition(cc.p(s.width-80, s.height-130)); + + var menu = new cc.Menu(item1, item2, item3, item4); + this.addChild(menu); + menu.setPosition(0, 0); + }, + + addNewBillBoradWithCoords:function(position){ + var imgs = ["Images/Icon.png", "Images/r2.png"]; + for(var i = 0; i < 10; ++i){ + var billboard = new jsb.BillBoard(imgs[Math.floor(Math.random() + 0.5)]); + billboard.setScale(0.5); + billboard.setPosition3D(cc.math.vec3(position.x, position.y, -150+30*i)); + billboard.setOpacity(Math.random() * 128 + 128); + this._layerBillBorad.addChild(billboard); + this._billboards.push(billboard); + } + }, + + addNewAniBillBoradWithCoords:function(position){ + for(var i = 0; i < 10; ++i){ + var billboardAni = new jsb.BillBoard("Images/grossini.png"); + billboardAni.setScale(0.5); + billboardAni.setPosition3D(cc.math.vec3(position.x, position.y, -150+30*i)); + this._layerBillBorad.addChild(billboardAni); + + var animation = new cc.Animation(); + for(var j = 1; j < 15; ++j){ + if(j < 10) + animation.addSpriteFrameWithFile("Images/grossini_dance_0"+j+".png"); + else + animation.addSpriteFrameWithFile("Images/grossini_dance_"+j+".png"); + } + // should last 2.8 seconds. And there are 14 frames. + animation.setDelayPerUnit(2.8/14.0); + animation.setRestoreOriginalFrame(true); + + var action = new cc.Animate(animation); + billboardAni.runAction(action.repeatForever()); + billboardAni.setOpacity(Math.random() * 128 + 128); + this._billboards.push(billboardAni); + } + }, + + menuCallback_orientedPoint:function(sender){ + for(var i = 0; i < this._billboards.length; ++i){ + this._billboards[i].setMode(jsb.BillBoard.Mode.VIEW_POINT_ORIENTED); + } + }, + + menuCallback_orientedPlane:function(sender){ + for(var i = 0; i < this._billboards.length; ++i){ + this._billboards[i].setMode(jsb.BillBoard.Mode.VIEW_PLANE_ORIENTED); + } + }, + + onTouchesMoved:function(touches, event){ + if(touches.length == 1){ + var touch = touches[0]; + var location = touch.getLocation(); + var previousLocation = touch.getPreviousLocation(); + var newPos = cc.p(previousLocation.x - location.x, previousLocation.y - location.y); + + var m = this._camera.getNodeToWorldTransform3D(); + var cameraDir = cc.math.vec3(-m[8], -m[9], -m[10]); + cameraDir.normalize(); + cameraDir.y = 0; + + var cameraRightDir = cc.math.vec3(m[0], m[1], m[2]); + cameraRightDir.normalize(); + cameraRightDir.y = 0; + + var cameraPos = this._camera.getPosition3D(); + cameraPos.x += cameraDir.x * newPos.y * 0.5 + cameraRightDir.x * newPos.x * 0.5; + cameraPos.y += cameraDir.y * newPos.y * 0.5 + cameraRightDir.y * newPos.x * 0.5; + cameraPos.z += cameraDir.z * newPos.y * 0.5 + cameraRightDir.z * newPos.x * 0.5; + this._camera.setPosition3D(cameraPos); + } + } +}); + +// +// Flow control +// +var arrayOfBillBoardTest = [ + BillBoardRotationTest, + BillBoardTest +]; + +var nextBillBoardTest = function () { + BillBoardTestIdx++; + BillBoardTestIdx = BillBoardTestIdx % arrayOfBillBoardTest.length; + + return new arrayOfBillBoardTest[BillBoardTestIdx ](); +}; +var previousBillBoardTest = function () { + BillBoardTestIdx--; + if (BillBoardTestIdx < 0) + BillBoardTestIdx += arrayOfBillBoardTest.length; + + return new arrayOfBillBoardTest[BillBoardTestIdx ](); +}; +var restartBillBoardTest = function () { + return new arrayOfBillBoardTest[BillBoardTestIdx ](); +}; diff --git a/samples/js-tests/src/Camera3DTest/Camera3DTest.js b/samples/js-tests/src/Camera3DTest/Camera3DTest.js new file mode 100644 index 0000000000..c3bbeb37b5 --- /dev/null +++ b/samples/js-tests/src/Camera3DTest/Camera3DTest.js @@ -0,0 +1,1278 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ + +var CameraType = { + Free : 0, + FirstPerson : 1, + ThirdPerson : 2, +}; + +var OperateCamType = { + MoveCamera : 0, + RotateCamera : 1 +}; + +var Camera3DTestIdx = -1; + +var Camera3DTestDemo = cc.Layer.extend({ + _title:"", + _subtitle:"", + + ctor:function () { + this._super(); + }, + + // + // Menu + // + onEnter:function () { + this._super(); + + var label = new cc.LabelTTF(this._title, "Arial", 28); + this.addChild(label, 100, BASE_TEST_TITLE_TAG); + label.x = winSize.width / 2; + label.y = winSize.height - 50; + + var label2 = new cc.LabelTTF(this._subtitle, "Thonburi", 16); + this.addChild(label2, 101, BASE_TEST_SUBTITLE_TAG); + label2.x = winSize.width / 2; + label2.y = winSize.height - 80; + + var item1 = new cc.MenuItemImage(s_pathB1, s_pathB2, this.onBackCallback, this); + var item2 = new cc.MenuItemImage(s_pathR1, s_pathR2, this.onRestartCallback, this); + var item3 = new cc.MenuItemImage(s_pathF1, s_pathF2, this.onNextCallback, this); + + item1.tag = BASE_TEST_MENUITEM_PREV_TAG; + item2.tag = BASE_TEST_MENUITEM_RESET_TAG; + item3.tag = BASE_TEST_MENUITEM_NEXT_TAG; + + var menu = new cc.Menu(item1, item2, item3); + + menu.x = 0; + menu.y = 0; + var width = item2.width, height = item2.height; + item1.x = winSize.width/2 - width*2; + item1.y = height/2 ; + item2.x = winSize.width/2; + item2.y = height/2 ; + item3.x = winSize.width/2 + width*2; + item3.y = height/2 ; + + this.addChild(menu, 102, BASE_TEST_MENU_TAG); + }, + + onRestartCallback:function (sender) { + var s = new Camera3DTestScene(); + s.addChild(restartCamera3DTest()); + director.runScene(s); + }, + + onNextCallback:function (sender) { + var s = new Camera3DTestScene(); + s.addChild(nextCamera3DTest()); + director.runScene(s); + }, + + onBackCallback:function (sender) { + var s = new Camera3DTestScene(); + s.addChild(previousCamera3DTest()); + director.runScene(s); + }, +}); + +var Camera3DTestScene = cc.Scene.extend({ + ctor:function () { + this._super(); + + var label = new cc.LabelTTF("Main Menu", "Arial", 20); + var menuItem = new cc.MenuItemLabel(label, this.onMainMenuCallback, this); + + var menu = new cc.Menu(menuItem); + menu.x = 0; + menu.y = 0; + menuItem.x = winSize.width - 50; + menuItem.y = 25; + this.addChild(menu); + }, + onMainMenuCallback:function () { + var scene = new cc.Scene(); + var layer = new TestController(); + scene.addChild(layer); + director.runScene(scene); + }, + runThisTest:function (num) { + Camera3DTestIdx = (num || num == 0) ? (num - 1) : -1; + var layer = nextCamera3DTest(); + this.addChild(layer); + + director.runScene(this); + } +}); + +var CameraRotationTest = Camera3DTestDemo.extend({ + _title:"Camera Rotation Test", + _subtitle:"Slide to rotate", + _camControlNode:null, + _camNode:null, + + ctor:function(){ + this._super(); + + var s = cc.winSize; + this._camControlNode = new cc.Node(); + this._camControlNode.setNormalizedPosition(cc.p(0.5, 0.5)); + this.addChild(this._camControlNode); + + this._camNode = new cc.Node(); + this._camNode.setVertexZ(cc.Camera.getDefaultCamera().getPosition3D().z); + this._camControlNode.addChild(this._camNode); + + var sp3d = new jsb.Sprite3D(); + sp3d.setPosition(s.width/2, s.height/2); + this.addChild(sp3d); + + var lship = new cc.LabelTTF("Ship"); + lship.setPosition(0, 20); + sp3d.addChild(lship); + + //Billboards + //Yellow is at the back + var bill1 = new jsb.BillBoard("Images/Icon.png"); + bill1.setPosition3D(cc.math.vec3(50, 10, -10)); + bill1.setColor(cc.color.YELLOW); + bill1.setScale(0.6); + sp3d.addChild(bill1); + + var l1 = new cc.LabelTTF("Billboard1"); + l1.setPosition(cc.p(0, -10)); + l1.setColor(cc.color.WHITE); + l1.setScale(3); + bill1.addChild(l1); + + var p1 = new cc.ParticleSystem("Particles/SmallSun.plist"); + p1.setPosition(30, 80); + bill1.addChild(p1); + + var bill2 = new jsb.BillBoard("Images/Icon.png"); + bill2.setPosition3D(cc.math.vec3(-50, -10, 10)); + bill2.setScale(0.6); + sp3d.addChild(bill2); + + var l2 = new cc.LabelTTF("Billboard2"); + l2.setPosition(0, -10); + l2.setColor(cc.color.WHITE); + l2.setScale(3); + bill2.addChild(l2); + + var p2 = new cc.ParticleSystem("Particles/SmallSun.plist"); + p2.setPosition(30,80); + bill2.addChild(p2); + + //3D models + var model = new jsb.Sprite3D("Sprite3DTest/boss1.obj"); + model.setScale(4); + model.setTexture("Sprite3DTest/boss.png"); + model.setPosition3D(cc.math.vec3(s.width/2, s.height/2, 0)); + this.addChild(model); + + var self = this; + cc.eventManager.addListener({ + event: cc.EventListener.TOUCH_ONE_BY_ONE, + onTouchBegan: function(touch, event){return true;}, + onTouchMoved: function(touch, event){ + var dx = touch.getDelta().x; + var rot = self._camControlNode.getRotation3D(); + rot.y += dx; + self._camControlNode.setRotation3D(rot); + + var matrix = self._camNode.getNodeToWorldTransform3D(); + var worldPos = cc.math.vec3(matrix[12], matrix[13], matrix[14]); + + cc.Camera.getDefaultCamera().setPosition3D(worldPos); + cc.Camera.getDefaultCamera().lookAt(self._camControlNode.getPosition3D()); + } + }, this); + } +}); + +var Camera3DTest = (function(){ + var State = { + State_None : 0, + State_Idle : 0x01, + State_Move : 0x02, + State_Rotate : 0x04, + State_Speak : 0x08, + State_MeleeAttack : 0x10, + State_RemoteAttack : 0x20, + State_Attack : 0x40 + }; + + return Camera3DTestDemo.extend({ + _title:"Testing Camera", + _subtitle:"", + _layer3D:null, + _sprite3D:null, + _targetPos:null, + _camera:null, + _cameraType:-1, + _curState:0, + _bZoomOut:false, + _bZoomIn:false, + _bRotateLeft:false, + _bRotateRight:false, + _ZoomOutlabel:null, + _ZoomInlabel:null, + _RotateLeftlabel:null, + _RotateRightlabel:null, + + ctor:function(){ + this._super(); + }, + + onEnter:function(){ + this._super(); + + cc.eventManager.addListener({ + event: cc.EventListener.TOUCH_ALL_AT_ONCE, + // onTouchesBegan: this.onTouchesBegan, + onTouchesMoved: this.onTouchesMoved.bind(this), + onTouchesEnded: this.onTouchesEnded.bind(this) + }, this); + + var layer3D = new cc.Layer(); + this.addChild(layer3D, 0); + this._layer3D = layer3D; + this._curState = State.State_None; + this.addNewSpriteWithCoords(cc.math.vec3(0, 0, 0), "Sprite3DTest/girl.c3b", true, 0.2, true); + + var s = cc.winSize; + var containerForLabel1 = new cc.Node(); + this._ZoomOutlabel = new cc.LabelTTF("zoom out", "Arial", 20); + this._ZoomOutlabel.setPosition(s.width-50, cc.visibleRect.top.y-30); + containerForLabel1.addChild(this._ZoomOutlabel); + this.addChild(containerForLabel1, 10); + + cc.eventManager.addListener({ + event:cc.EventListener.TOUCH_ONE_BY_ONE, + swallowTouches: true, + onTouchBegan:this.onTouchZoomOut.bind(this), + onTouchEnded:this.onTouchZoomOutEnd.bind(this) + }, this._ZoomOutlabel); + + var containerForLabel2 = new cc.Node(); + this._ZoomInlabel = new cc.LabelTTF("zoom in", "Arial", 20); + this._ZoomInlabel.setPosition(s.width-50, cc.visibleRect.top.y - 100); + containerForLabel2.addChild(this._ZoomInlabel); + this.addChild(containerForLabel2, 10); + + cc.eventManager.addListener({ + event:cc.EventListener.TOUCH_ONE_BY_ONE, + swallowTouches:true, + onTouchBegan:this.onTouchZoomIn.bind(this), + onTouchEnded:this.onTouchZoomInEnd.bind(this) + }, this._ZoomInlabel); + + var containerForLabel3 = new cc.Node(); + this._RotateLeftlabel = new cc.LabelTTF("rotate left", "Arial", 20); + this._RotateLeftlabel.setPosition(s.width-50, cc.visibleRect.top.y - 170); + containerForLabel3.addChild(this._RotateLeftlabel); + this.addChild(containerForLabel3); + + cc.eventManager.addListener({ + event:cc.EventListener.TOUCH_ONE_BY_ONE, + swallowTouches:true, + onTouchBegan:this.onTouchRotateLeft.bind(this), + onTouchEnded:this.onTouchRotateLeftEnd.bind(this) + }, this._RotateLeftlabel); + + var containerForLabel4 = new cc.Node(); + this._RotateRightlabel = new cc.LabelTTF("rotate right", "Arial", 20); + this._RotateRightlabel.setPosition(s.width-50, cc.visibleRect.top.y - 240); + containerForLabel4.addChild(this._RotateRightlabel); + this.addChild(containerForLabel4, 10); + + cc.eventManager.addListener({ + event:cc.EventListener.TOUCH_ONE_BY_ONE, + swallowTouches:true, + onTouchBegan:this.onTouchRotateRight.bind(this), + onTouchEnded:this.onTouchRotateRightEnd.bind(this) + }, this._RotateRightlabel); + + var label1 = new cc.LabelTTF("free", "Arial", 20); + var item1 = new cc.MenuItemLabel(label1, this.switchViewCallback, this); + item1.type = CameraType.Free; + item1.setPosition(cc.visibleRect.left.x+100, cc.visibleRect.top.y-50); + + var label2 = new cc.LabelTTF("third person", "Arial", 20); + var item2 = new cc.MenuItemLabel(label2, this.switchViewCallback, this); + item2.type = CameraType.ThirdPerson; + item2.setPosition(cc.visibleRect.left.x+100, cc.visibleRect.top.y-100); + + var label3 = new cc.LabelTTF("first person", "Arial", 20); + var item3 = new cc.MenuItemLabel(label3, this.switchViewCallback, this); + item3.type = CameraType.FirstPerson; + item3.setPosition(cc.visibleRect.left.x+100, cc.visibleRect.top.y-150); + + var menu = new cc.Menu(item1, item2, item3); + menu.setPosition(cc.p(0, 0)); + this.addChild(menu); + + this.schedule(this.updateCamera, 0); + + if(this._camera == null){ + this._camera = cc.Camera.createPerspective(60, s.width/s.height, 1, 1000); + this._camera.setCameraFlag(cc.CameraFlag.USER1); + layer3D.addChild(this._camera); + } + this.switchViewCallback(item2);//third person + + var line = new cc.DrawNode3D(); + //draw x + for(var i = -20; i < 20; ++i) + line.drawLine(cc.math.vec3(-100, 0, 5*i), cc.math.vec3(100, 0, 5*i), cc.color(255, 0, 0, 1)); + + //draw z + for(var j = -20; j < 20; ++j) + line.drawLine(cc.math.vec3(5*j, 0, -100), cc.math.vec3(5*j, 0, 100), cc.color(0, 0, 255, 1)); + + //draw y + line.drawLine(cc.math.vec3(0, -50, 0), cc.math.vec3(0, 0, 0), cc.color(0, 128, 0, 1)); + line.drawLine(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 50, 0), cc.color(0, 255, 0, 1)); + layer3D.addChild(line); + layer3D.setCameraMask(2); + }, + + addNewSpriteWithCoords:function(postion, file, playAnimation, scale, bindCamera){ + var sprite = new jsb.Sprite3D(file); + this._layer3D.addChild(sprite); + var globalZOrder = sprite.getGlobalZOrder(); + sprite.setPosition3D(postion); + sprite.setGlobalZOrder(globalZOrder); + if(playAnimation){ + var animation = jsb.Animation3D.create(file, "Take 001"); + if(animation){ + var animate = jsb.Animate3D.create(animation); + sprite.runAction(cc.repeatForever(animate)); + } + } + if(bindCamera) + this._sprite3D = sprite; + + sprite.setScale(scale); + }, + + updateState:function(dt){ + if(!this._targetPos) + return; + var curPos = this._sprite3D.getPosition3D(); + var m = this._sprite3D.getNodeToWorldTransform3D(); + var curFaceDir = cc.math.vec3(m[8], m[9], m[10]); + curFaceDir.normalize(); + var newFaceDir = cc.math.vec3(this._targetPos.x - curPos.x, this._targetPos.y - curPos.y, this._targetPos.z - curPos.z); + newFaceDir.y = 0; + newFaceDir.normalize(); + var cosAngle = Math.abs(cc.math.vec3Dot(curFaceDir, newFaceDir) - 1); + + var dx = curPos.x - this._targetPos.x, + dy = curPos.y - this._targetPos.y, + dz = curPos.z - this._targetPos.z; + var dist = dx * dx + dy * dy + dz * dz; + + if(dist <= 4){ + if(cosAngle <= 0.01) + this._curState = State.State_Idle; + else + this._curState = State.State_Rotate; + }else{ + if(cosAngle > 0.01) + this._curState = State.State_Rotate | State.State_Move; + else + this._curState = State.State_Move; + } + }, + + move3D:function(dt){ + if(!this._targetPos) + return; + var curPos = this._sprite3D.getPosition3D(); + var newFaceDir = cc.math.vec3(this._targetPos.x - curPos.x, this._targetPos.y - curPos.y, this._targetPos.z - curPos.z); + newFaceDir.y = 0; + newFaceDir.normalize(); + var offset = cc.math.vec3(newFaceDir.x * 25 * dt, newFaceDir.y * 25 * dt, newFaceDir.z * 25 * dt); + curPos.x += offset.x; + curPos.y += offset.y; + curPos.z += offset.z; + this._sprite3D.setPosition3D(curPos); + if(this._cameraType == CameraType.ThirdPerson){ + var cameraPos = this._camera.getPosition3D(); + cameraPos.x += offset.x; + cameraPos.z += offset.z; + this._camera.setPosition3D(cameraPos); + } + }, + + updateCamera:function(dt){ + if(this._cameraType == CameraType.ThirdPerson){ + this.updateState(dt) + + if(this.isState(State.State_Move)){ + this.move3D(dt); + if(this.isState(State.State_Rotate)){ + var curPos = this._sprite3D.getPosition3D(); + var newFaceDir = cc.math.vec3(this._targetPos.x - curPos.x, this._targetPos.y - curPos.y, this._targetPos.z - curPos.z); + newFaceDir.y = 0; + newFaceDir.normalize(); + + var m = this._sprite3D.getNodeToWorldTransform3D(); + var up = cc.math.vec3(m[4], m[5], m[6]); + up.normalize(); + + var right = cc.math.vec3Cross(cc.math.vec3(-newFaceDir.x, -newFaceDir.y, -newFaceDir.z), up); + right.normalize(); + + var mat = [right.x, right.y, right.z, 0, + up.x, up.y, up.z, 0, + newFaceDir.x, newFaceDir.y, newFaceDir.z, 0, + 0, 0, 0, 1]; + + this._sprite3D.setAdditionalTransform(mat); + } + } + } + + if(this._bZoomOut == true){ + if(this._cameraType == CameraType.ThirdPerson){ + var cameraPos = this._camera.getPosition3D(); + var spritePos = this._sprite3D.getPosition3D(); + var lookDir = cc.math.vec3(cameraPos.x - spritePos.x, cameraPos.y - spritePos.y, cameraPos.z - spritePos.z); + if(cc.math.vec3Length(lookDir) <= 300){ + lookDir.normalize(); + cameraPos.x += lookDir.x; + cameraPos.y += lookDir.y; + cameraPos.z += lookDir.z; + this._camera.setPosition3D(cameraPos); + } + }else if(this._cameraType == CameraType.Free){ + var cameraPos = this._camera.getPosition3D(); + if(cc.math.vec3Length(cameraPos) <= 300){ + var n = cc.math.vec3Normalize(cameraPos); + cameraPos.x += n.x; + cameraPos.y += n.y; + cameraPos.z += n.z; + this._camera.setPosition3D(cameraPos); + } + } + } + + if(this._bZoomIn == true){ + if(this._cameraType == CameraType.ThirdPerson){ + var cameraPos = this._camera.getPosition3D(); + var spritePos = this._sprite3D.getPosition3D(); + var lookDir = cc.math.vec3(cameraPos.x - spritePos.x, cameraPos.y - spritePos.y, cameraPos.z - spritePos.z); + if(cc.math.vec3Length(lookDir) >= 50){ + lookDir.normalize(); + cameraPos.x -= lookDir.x; + cameraPos.y -= lookDir.y; + cameraPos.z -= lookDir.z; + this._camera.setPosition3D(cameraPos); + } + }else if(this._cameraType == CameraType.Free){ + var cameraPos = this._camera.getPosition3D(); + if(cc.math.vec3Length(cameraPos) >= 50){ + var n = cc.math.vec3Normalize(cameraPos); + cameraPos.x -= n.x; + cameraPos.y -= n.y; + cameraPos.z -= n.z; + this._camera.setPosition3D(cameraPos); + } + } + } + + if(this._bRotateLeft == true){ + if(this._cameraType == CameraType.Free || this._cameraType == CameraType.FirstPerson){ + var rotation3D = this._camera.getRotation3D(); + rotation3D.y += 1; + this._camera.setRotation3D(rotation3D); + } + } + if(this._bRotateRight == true){ + if(this._cameraType == CameraType.Free || this._cameraType == CameraType.FirstPerson){ + var rotation3D = this._camera.getRotation3D(); + rotation3D.y -= 1; + this._camera.setRotation3D(rotation3D); + } + } + }, + + isState:function(bit){ + return (this._curState & bit) == bit; + }, + + switchViewCallback:function(sender){ + if(this._cameraType == sender.type) + return; + this._cameraType = sender.type; + + if(this._cameraType == CameraType.Free){ var p = this._sprite3D.getPosition3D(); + this._camera.setPosition3D(cc.math.vec3(p.x, p.y+130, p.z+130)); + + this._RotateRightlabel.setColor(cc.color.WHITE); + this._RotateLeftlabel.setColor(cc.color.WHITE); + this._ZoomInlabel.setColor(cc.color.WHITE); + this._ZoomOutlabel.setColor(cc.color.WHITE); + + }else if(this._cameraType == CameraType.FirstPerson){ + var m = this._sprite3D.getWorldToNodeTransform3D(); + var newFaceDir = cc.math.vec3(-m[8], -m[9], -m[10]); + var p = this._sprite3D.getPosition3D(); + this._camera.setPosition3D(cc.math.vec3(p.x, p.y + 35, p.z)); + this._camera.lookAt(cc.math.vec3(p.x + newFaceDir.x*50, p.y + newFaceDir.y*50, p.z+newFaceDir.z*50)); + + this._RotateRightlabel.setColor(cc.color.WHITE); + this._RotateLeftlabel.setColor(cc.color.WHITE); + this._ZoomInlabel.setColor(cc.color.GRAY); + this._ZoomOutlabel.setColor(cc.color.GRAY); + + }else{ + var p = this._sprite3D.getPosition3D(); + this._camera.setPosition3D(cc.math.vec3(p.x, p.y+130, p.z+130)); + this._camera.lookAt(p); + + this._RotateRightlabel.setColor(cc.color.GRAY); + this._RotateLeftlabel.setColor(cc.color.GRAY); + this._ZoomInlabel.setColor(cc.color.WHITE); + this._ZoomOutlabel.setColor(cc.color.WHITE); + } + }, + + onTouchesMoved:function(touches, event){ + if(touches.length == 1){ + var touch = touches[0]; + var location = touch.getLocation(); + var previousLocation = touch.getPreviousLocation(); + var newPos = cc.math.vec3(previousLocation.x - location.x, previousLocation.y - location.y, previousLocation.z - location.z); + if(this._cameraType == CameraType.Free || this._cameraType == CameraType.FirstPerson){ + var m = this._camera.getNodeToWorldTransform3D(); + var cameraDir = cc.math.vec3(-m[8], -m[9], -m[10]); + cameraDir.normalize(); + cameraDir.y = 0; + var cameraRightDir = cc.math.vec3(m[0], m[1], m[2]); + cameraRightDir.normalize(); + cameraRightDir.y = 0; + + var cameraPos = this._camera.getPosition3D(); + cameraPos.x += cameraDir.x*newPos.y*0.1 + cameraRightDir.x*newPos.x*0.1; + cameraPos.y += cameraDir.y*newPos.y*0.1 + cameraRightDir.y*newPos.x*0.1; + cameraPos.z += cameraDir.z*newPos.y*0.1 + cameraRightDir.z*newPos.x*0.1; + this._camera.setPosition3D(cameraPos); + if(this._sprite3D && this._cameraType == CameraType.FirstPerson){ + this._sprite3D.setPosition3D(cc.math.vec3(this._camera.x, 0, this._camera.getVertexZ())); + this._targetPos = this._sprite3D.getPosition3D(); + } + } + } + }, + + onTouchesEnded:function(touches, event){ + for(var i in touches){ + var touch = touches[i]; + var location = touch.getLocationInView(); + if(this._sprite3D && this._cameraType == CameraType.ThirdPerson && this._bZoomOut == false && this._bZoomIn == false && this._bRotateLeft == false && this._bRotateRight == false){ + var nearP = cc.math.vec3(location.x, location.y, -1); + var farP = cc.math.vec3(location.x, location.y, 1); + + nearP = this._camera.unproject(nearP); + farP = this._camera.unproject(farP); + + var dir = cc.math.vec3(farP.x-nearP.x, farP.y-nearP.y, farP.z-nearP.z); + var ndd = dir.y; // (0, 1, 0) * dir + var ndo = nearP.y; // (0, 1, 0) * nearP + var dist = - ndo / ndd; + var p = cc.math.vec3(nearP.x+dist*dir.x, nearP.y+dist*dir.y, nearP.z+dist*dir.z); + + if(p.x > 100) + p.x = 100; + if(p.x < -100) + p.x = -100; + if(p.z > 100) + p.z = 100 + if(p.z < -100) + p.z = -100; + + this._targetPos = p; + } + } + }, + + onTouchZoomOut:function(touch, event){ + var target = event.getCurrentTarget(); + var locationInNode = target.convertToNodeSpace(touch.getLocation()); + var s = target.getContentSize(); + var rect = cc.rect(0, 0, s.width, s.height); + if(cc.rectContainsPoint(rect, locationInNode)){ + this._bZoomOut = true; + return true; + } + return false; + }, + + onTouchZoomOutEnd:function(touch, event){ + this._bZoomOut = false; + }, + + onTouchZoomIn:function(touch, event){ + var target = event.getCurrentTarget(); + var locationInNode = target.convertToNodeSpace(touch.getLocation()); + var s = target.getContentSize(); + var rect = cc.rect(0, 0, s.width, s.height); + if(cc.rectContainsPoint(rect, locationInNode)){ + this._bZoomIn = true; + return true; + } + return false; + }, + + onTouchZoomInEnd:function(touch, event){ + this._bZoomIn = false; + }, + + onTouchRotateLeft:function(touch, event){ + var target = event.getCurrentTarget(); + var locationInNode = target.convertToNodeSpace(touch.getLocation()); + var s = target.getContentSize(); + var rect = cc.rect(0, 0, s.width, s.height); + if(cc.rectContainsPoint(rect, locationInNode)){ + this._bRotateLeft = true; + return true; + } + return false; + }, + + onTouchRotateLeftEnd:function(touch, event){ + this._bRotateLeft = false; + }, + + onTouchRotateRight:function(touch, event){ + var target = event.getCurrentTarget(); + var locationInNode = target.convertToNodeSpace(touch.getLocation()); + var s = target.getContentSize(); + var rect = cc.rect(0, 0, s.width, s.height); + if(cc.rectContainsPoint(rect, locationInNode)){ + this._bRotateRight = true; + return true; + } + return false; + }, + + onTouchRotateRightEnd:function(touch, event){ + this._bRotateRight = false; + } + }); +})(); + +var CameraCullingDemo = Camera3DTestDemo.extend({ + _title:"Camera Frustum Clipping", + _subtitle:"", + _objects:[], + _layer3D:null, + _labelSprite3DCount:null, + _drawAABB:null, + _drawFrustum:null, + _row:3, + _cameraType:CameraType.FirstPerson, + _cameraFirst:null, + _cameraThird:null, + _moveAction:null, + + ctor:function(){ + this._super(); + + this.scheduleUpdate(); + + var layer3D = new cc.Layer(); + this.addChild(layer3D, 0); + this._layer3D = layer3D; + + // swich camera + cc.MenuItemFont.setFontName("Arial"); + cc.MenuItemFont.setFontSize(20); + + var menuItem1 = new cc.MenuItemFont("Switch Camera", this.switchViewCallback, this); + menuItem1.setColor(cc.color(0, 200, 20)); + var menu = new cc.Menu(menuItem1); + menu.setPosition(cc.p(0, 0)); + menuItem1.setPosition(cc.visibleRect.left.x + 80, cc.visibleRect.top.y - 70); + this.addChild(menu); + + // + - + cc.MenuItemFont.setFontSize(40); + var decrease = new cc.MenuItemFont(" - ", this.delSpriteCallback, this); + decrease.setColor(cc.color(0, 200, 20)); + var increase = new cc.MenuItemFont(" + ", this.addSpriteCallback, this); + increase.setColor(cc.color(0, 200, 20)); + + menu = new cc.Menu(decrease, increase); + menu.alignItemsHorizontally(); + menu.setPosition(cc.winSize.width - 60, cc.visibleRect.top.y - 70); + this.addChild(menu, 1); + + this._labelSprite3DCount = new cc.LabelTTF("0 sprites", "Marker Felt", 30); + this._labelSprite3DCount.setColor(cc.color(0, 200, 20)); + this._labelSprite3DCount.setPosition(cc.p(cc.winSize.width / 2, cc.visibleRect.top.y - 70)); + this.addChild(this._labelSprite3DCount); + + // aabb drawNode3D + this._drawAABB = new cc.DrawNode3D(); + this._drawAABB.setCameraMask(cc.CameraFlag.USER1); + this.addChild(this._drawAABB); + + // frustum drawNode3D + this._drawFrustum = new cc.DrawNode3D(); + this._drawFrustum.setCameraMask(cc.CameraFlag.USER1); + this.addChild(this._drawFrustum); + + // set camera + this.switchViewCallback(); + + // add sprite + this.addSpriteCallback(); + }, + + onExit:function(){ + this._super(); + this._moveAction.release(); + }, + + switchViewCallback:function(sender){ + if(!this._cameraFirst){ + var camera = cc.Camera.createPerspective(30, cc.winSize.width/cc.winSize.height, 10, 200); + camera.setCameraFlag(cc.CameraFlag.USER8); + camera.setPosition3D(cc.math.vec3(-100, 0, 0)); + camera.lookAt(cc.math.vec3(1000, 0, 0)); + this._moveAction = cc.moveBy(4, cc.p(200, 0)); + this._moveAction.retain(); + var seq = cc.sequence(this._moveAction, cc.callFunc(this.reachEndCallBack, this)); + seq.setTag(100); + camera.runAction(seq); + this.addChild(camera); + this._cameraFirst = camera; + } + + if(!this._cameraThird){ + var camera = cc.Camera.createPerspective(60, cc.winSize.width/ cc.winSize.height, 1, 1000); + camera.setCameraFlag(cc.CameraFlag.USER8); + camera.setPosition3D(cc.math.vec3(0, 130, 130)); + camera.lookAt(cc.math.vec3(0, 0, 0)); + this.addChild(camera); + this._cameraThird = camera; + } + + if(this._cameraType == CameraType.FirstPerson){ + this._cameraType = CameraType.ThirdPerson; + this._cameraThird.setCameraFlag(cc.CameraFlag.USER1); + this._cameraFirst.setCameraFlag(cc.CameraFlag.USER8); + }else if(this._cameraType == CameraType.ThirdPerson){ + this._cameraType = CameraType.FirstPerson; + this._cameraThird.setCameraFlag(cc.CameraFlag.USER8); + this._cameraFirst.setCameraFlag(cc.CameraFlag.USER1); + this._drawFrustum.clear(); + } + }, + + reachEndCallBack:function(){ + this._cameraFirst.stopActionByTag(100); + var inverse = this._moveAction.reverse(); + inverse.retain(); + this._moveAction.release(); + this._moveAction = inverse; + var rot = cc.rotateBy(1, cc.math.vec3(0, 180, 0)); + var seq = cc.sequence(rot, this._moveAction, cc.callFunc(this.reachEndCallBack, this)); + seq.setTag(100); + this._cameraFirst.runAction(seq); + }, + + delSpriteCallback:function(sender){ + if(this._row == 0) + return; + + this._layer3D.removeAllChildren(); + this._objects.length = 0; + + this._row--; + for(var x = -this._row; x < this._row; ++x){ + for(var z = -this._row; z < this._row; ++z){ + var sprite = new jsb.Sprite3D("Sprite3DTest/orc.c3b"); + sprite.setPosition3D(cc.math.vec3(x * 30, 0, z * 30)); + sprite.setRotation3D(cc.math.vec3(0, 180, 0)); + this._objects.push(sprite); + this._layer3D.addChild(sprite); + } + } + + //set layer mask + this._layer3D.setCameraMask(cc.CameraFlag.USER1); + + //update sprite number + this._labelSprite3DCount.setString(this._layer3D.getChildrenCount() + " sprites"); + }, + + addSpriteCallback:function(sender){ + this._layer3D.removeAllChildren(); + this._objects.length = 0; + this._drawAABB.clear(); + + this._row++; + for(var x = -this._row; x < this._row; ++x){ + for(var z = -this._row; z < this._row; ++z){ + var sprite = new jsb.Sprite3D("Sprite3DTest/orc.c3b"); + sprite.setPosition3D(cc.math.vec3(x * 30, 0, z * 30)); + sprite.setRotation3D(cc.math.vec3(0, 180, 0)); + this._objects.push(sprite); + this._layer3D.addChild(sprite); + } + } + + //set layer mask + this._layer3D.setCameraMask(cc.CameraFlag.USER1); + + //update sprite number + this._labelSprite3DCount.setString(this._layer3D.getChildrenCount() + " sprites"); + }, + + update:function(dt){ + this._drawAABB.clear(); + + if(this._cameraType == CameraType.ThirdPerson) + this.drawCameraFrustum(); + + var children = this._layer3D.getChildren(); + + for(var i in children){ + var aabb = children[i].getAABB(); + if(this._cameraFirst.isVisibleInFrustum(aabb)){ + var corners = cc.math.aabbGetCorners(aabb); + this._drawAABB.drawCube(corners, cc.color(0, 255, 0)); + } + } + }, + + drawCameraFrustum:function(){ + this._drawFrustum.clear(); + var size = cc.winSize; + var color = cc.color(255, 255, 0); + + // top-left + var src = cc.math.vec3(0, 0, 0); + var tl_0 = this._cameraFirst.unproject(src); + src = cc.math.vec3(0, 0, 1); + var tl_1 = this._cameraFirst.unproject(src); + + // top-right + src = cc.math.vec3(size.width, 0, 0); + var tr_0 = this._cameraFirst.unproject(src); + src = cc.math.vec3(size.width, 0, 1); + var tr_1 = this._cameraFirst.unproject(src); + + // bottom-left + src = cc.math.vec3(0, size.height, 0); + var bl_0 = this._cameraFirst.unproject(src); + src = cc.math.vec3(0, size.height, 1); + var bl_1 = this._cameraFirst.unproject(src); + + // bottom-right + src = cc.math.vec3(size.width, size.height, 0); + var br_0 = this._cameraFirst.unproject(src); + src = cc.math.vec3(size.width, size.height, 1); + var br_1 = this._cameraFirst.unproject(src); + + this._drawFrustum.drawLine(tl_0, tl_1, color); + this._drawFrustum.drawLine(tr_0, tr_1, color); + this._drawFrustum.drawLine(bl_0, bl_1, color); + this._drawFrustum.drawLine(br_0, br_1, color); + + this._drawFrustum.drawLine(tl_0, tr_0, color); + this._drawFrustum.drawLine(tr_0, br_0, color); + this._drawFrustum.drawLine(br_0, bl_0, color); + this._drawFrustum.drawLine(bl_0, tl_0, color); + + this._drawFrustum.drawLine(tl_1, tr_1, color); + this._drawFrustum.drawLine(tr_1, br_1, color); + this._drawFrustum.drawLine(br_1, bl_1, color); + this._drawFrustum.drawLine(bl_1, tl_1, color); + } +}); + +var CameraArcBallDemo = Camera3DTestDemo.extend({ + _title:"Camera ArcBall Moving", + _subtitle:"", + _rotationQuat: null, + _layer3D:null, + _camera:null, + _sprite3D1:null, + _sprite3D2:null, + _drawGrid:null, + _operate:OperateCamType.RotateCamera, + _target:0, + _center:cc.math.vec3(0, 0, 0), + _distanceZ:50, + _radius:1, + + ctor:function(){ + this._super(); + this._rotationQuat = cc.math.quaternion(0, 0, 0, 1); + cc.eventManager.addListener({ + event:cc.EventListener.TOUCH_ALL_AT_ONCE, + onTouchesMoved:this.onTouchesMoved.bind(this) + }, this); + + cc.MenuItemFont.setFontName("Arial"); + cc.MenuItemFont.setFontSize(20); + + var item1 = new cc.MenuItemFont("Switch Operation", this.switchOperateCallback, this); + item1.setColor(cc.color(0, 200, 20)); + var item2 = new cc.MenuItemFont("Switch Target", this.switchTargetCallback, this); + item2.setColor(cc.color(0, 200, 20)); + var menu = new cc.Menu(item1, item2); + menu.setPosition(cc.p(0, 0)); + item1.setPosition(cc.visibleRect.left.x + 80, cc.visibleRect.top.y - 70); + item2.setPosition(cc.visibleRect.left.x + 80, cc.visibleRect.top.y - 100); + this.addChild(menu, 1); + + var layer3D = new cc.Layer(); + this.addChild(layer3D); + this._layer3D = layer3D; + + this._camera = cc.Camera.createPerspective(60, cc.winSize.width/cc.winSize.height, 1, 1000); + this._camera.setCameraFlag(cc.CameraFlag.USER1); + this._camera.setPosition3D(cc.math.vec3(0, 10, 50)); + this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); + layer3D.addChild(this._camera); + + this._sprite3D1 = new jsb.Sprite3D("Sprite3DTest/orc.c3b"); + this._sprite3D1.setScale(0.5); + this._sprite3D1.setRotation3D(cc.math.vec3(0, 180, 0)); + this._sprite3D1.setPosition3D(cc.math.vec3(0, 0, 0)); + layer3D.addChild(this._sprite3D1); + + this._sprite3D2 = new jsb.Sprite3D("Sprite3DTest/boss.c3b"); + this._sprite3D2.setScale(0.6); + this._sprite3D2.setRotation3D(cc.math.vec3(-90, 0, 0)); + this._sprite3D2.setPosition3D(cc.math.vec3(20, 0, 0)); + layer3D.addChild(this._sprite3D2); + + this._drawGrid = new cc.DrawNode3D(); + //draw x + for(var i = -20; i < 20; ++i) + this._drawGrid.drawLine(cc.math.vec3(-100, 0, 5*i), cc.math.vec3(100, 0, 5*i), cc.color(0, 0, 255)); + + //draw z + for(var j = -20; j < 20; ++j) + this._drawGrid.drawLine(cc.math.vec3(5*j, 0, -100), cc.math.vec3(5*j, 0, 100), cc.color(0, 255, 0)); + + //draw y + this._drawGrid.drawLine(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 50, 0), cc.color(0, 255, 0)); + + layer3D.addChild(this._drawGrid); + layer3D.setCameraMask(2); + this.updateCameraTransform(); + }, + + updateCameraTransform:function(){ + var trans = cc.math.mat4CreateTranslation(cc.math.vec3(0, 10, this._distanceZ)); + var rot = cc.math.mat4CreateRotation(this._rotationQuat); + var center = cc.math.mat4CreateTranslation(this._center); + + var result = cc.math.mat4Multiply(cc.math.mat4Multiply(center, rot), trans); + this._camera.setNodeToParentTransform(result); + }, + + switchOperateCallback:function(sender){ + if(this._operate === OperateCamType.MoveCamera) + this._operate = OperateCamType.RotateCamera; + else if(this._operate === OperateCamType.RotateCamera) + this._operate = OperateCamType.MoveCamera; + }, + + switchTargetCallback:function(sender){ + if(this._target === 0 ){ + this._target = 1; + this._center = this._sprite3D2.getPosition3D(); + this.updateCameraTransform(); + }else if(this._target === 1){ + this._target = 0; + this._center = this._sprite3D1.getPosition3D(); + this.updateCameraTransform(); + } + }, + + onTouchesMoved:function(touches, event){ + if(touches.length > 0){ + if(this._operate === OperateCamType.RotateCamera){ //arc ball rotate + var visibleSize = cc.director.getVisibleSize(); + var prelocation = touches[0].getPreviousLocationInView(); + var location = touches[0].getLocationInView(); + location.x = 2 * location.x / visibleSize.width - 1; + location.y = 2 * (visibleSize.height - location.y) / visibleSize.height - 1; + prelocation.x = 2 * prelocation.x / visibleSize.width - 1; + prelocation.y = 2 * (visibleSize.height - prelocation.y) / visibleSize.height - 1; + + var quat = this.calculateArcBall(prelocation.x, prelocation.y, location.x, location.y); //calculate rotation cc.math.quaternion parameters + this._rotationQuat = cc.math.quatMultiply(quat, this._rotationQuat); + + this.updateCameraTransform(); + }else if(this._operate === OperateCamType.MoveCamera){ //camera zoom + var newPos = cc.pSub(touches[0].getPreviousLocation(), touches[0].getLocation()); + this._distanceZ -= newPos.y * 0.1; + + this.updateCameraTransform(); + } + } + }, + + calculateArcBall:function(p1x, p1y, p2x, p2y){ + var axis, angle; + + var rotation_matrix = cc.math.mat4CreateRotation(this._rotationQuat); + + var uv = cc.math.mat4MultiplyVec3(rotation_matrix, cc.math.vec3(0, 1, 0)); //rotation y + var sv = cc.math.mat4MultiplyVec3(rotation_matrix, cc.math.vec3(1, 0, 0)); //rotation x + var lv = cc.math.mat4MultiplyVec3(rotation_matrix, cc.math.vec3(0, 0, -1));//rotation z + + var z = this.projectToSphere(this._radius, p1x, p1y); + var p1 = cc.math.vec3Sub(cc.math.vec3Add(cc.math.vec3(sv.x * p1x, sv.y * p1x, sv.z * p1x), cc.math.vec3(uv.x * p1y, uv.y * p1y, uv.z *p1y)), cc.math.vec3(lv.x * z, lv.y * z, lv.z * z)); //start point screen transform to 3d + z = this.projectToSphere(this._radius, p2x, p2y); + var p2 = cc.math.vec3Sub(cc.math.vec3Add(cc.math.vec3(sv.x * p2x, sv.y * p2x, sv.z * p2x), cc.math.vec3(uv.x * p2y, uv.y * p2y, uv.z *p2y)), cc.math.vec3(lv.x * z, lv.y * z, lv.z * z)); //end point screen transform to 3d + + axis = cc.math.vec3Cross(p2, p1); //calculate rotation axis + axis.normalize(); + + var t = cc.math.vec3Length(cc.math.vec3Sub(p2, p1)) / (2 * this._radius); + //clamp -1 to 1 + if(t > 1) t = 1; + if(t < -1) t = -1; + angle = Math.asin(t); //rotation angle*/ + + return cc.math.quaternion(axis, angle) + }, + + /* project an x,y pair onto a sphere of radius r or a + hyperbolic sheet if we are away from the center of the sphere. */ + projectToSphere:function(r, x, y){ + var d = Math.sqrt(x*x + y*y); + var t, z; + if(d < r * 0.70710678118654752440)//inside sphere + z = Math.sqrt(r*r - d*d) + else{ + t = r / 1.41421356237309504880; + z = t*t / d; + } + return z; + } +}); + +var FogTestDemo = Camera3DTestDemo.extend({ + _title:"Fog Test Demo", + _subtitle:"", + _sprite3D1:null, + _sprite3D2:null, + _camera:null, + _state:null, + + ctor:function(){ + this._super(); + cc.director.setClearColor(cc.color(128, 128, 128)); + + cc.eventManager.addListener({ + event:cc.EventListener.TOUCH_ALL_AT_ONCE, + onTouchesMoved:this.onTouchesMoved.bind(this) + }, this); + + // swich fog type + var label1 = new cc.LabelTTF("Linear", "Arial", 20); + var item1 = new cc.MenuItemLabel(label1, this.switchTypeCallback, this); + item1.setUserData(0); + var label2 = new cc.LabelTTF("Exp", "Arial", 20); + var item2 = new cc.MenuItemLabel(label2, this.switchTypeCallback, this); + item2.setUserData(1); + var label3 = new cc.LabelTTF("Exp2", "Arial", 20); + var item3 = new cc.MenuItemLabel(label3, this.switchTypeCallback, this); + item3.setUserData(2); + var menu = new cc.Menu(item1, item2, item3); + menu.setPosition(cc.p(0, 0)); + + item1.setPosition(cc.visibleRect.left.x + 60, cc.visibleRect.top.y - 50); + item2.setPosition(cc.visibleRect.left.x + 60, cc.visibleRect.top.y - 100); + item3.setPosition(cc.visibleRect.left.x + 60, cc.visibleRect.top.y - 150); + this.addChild(menu, 0); + + var layer3D = new cc.Layer(); + this.addChild(layer3D, 0); + + var shader = new cc.GLProgram("Sprite3DTest/fog.vert", "Sprite3DTest/fog.frag"); + var state = cc.GLProgramState.create(shader); + this._state = state; + + this._sprite3D1 = new jsb.Sprite3D("Sprite3DTest/teapot.c3b"); + this._sprite3D2 = new jsb.Sprite3D("Sprite3DTest/teapot.c3b"); + + this._sprite3D1.setGLProgramState(state); + this._sprite3D2.setGLProgramState(state); + + //pass mesh's attribute to shader + var offset = 0; + var attributeCount = this._sprite3D1.getMesh().getMeshVertexAttribCount(); + for(var i = 0; i < attributeCount; ++i){ + var meshattribute = this._sprite3D1.getMesh().getMeshVertexAttribute(i); + state.setVertexAttribPointer(cc.attributeNames[meshattribute.vertexAttrib], + meshattribute.size, + meshattribute.type, + gl.FALSE, + this._sprite3D1.getMesh().getVertexSizeInBytes(), + offset); + offset += meshattribute.attribSizeBytes; + } + + var offset1 = 0; + var attributeCount = this._sprite3D2.getMesh().getMeshVertexAttribCount(); + for(var i = 0; i < attributeCount; ++i){ + var meshattribute = this._sprite3D2.getMesh().getMeshVertexAttribute(i); + state.setVertexAttribPointer(cc.attributeNames[meshattribute.vertexAttrib], + meshattribute.size, + meshattribute.type, + gl.FALSE, + this._sprite3D2.getMesh().getVertexSizeInBytes(), + offset1); + offset1 += meshattribute.attribSizeBytes; + } + + state.setUniformVec4("u_fogColor", cc.math.vec4(0.5, 0.5, 0.5, 1.0)); + state.setUniformFloat("u_fogStart", 10); + state.setUniformFloat("u_fogEnd", 60); + state.setUniformInt("u_fogEquation", 0); + + layer3D.addChild(this._sprite3D1); + this._sprite3D1.setPosition3D(cc.math.vec3(0, 0, 0)); + this._sprite3D1.setScale(2); + this._sprite3D1.setRotation3D(cc.math.vec3(-90, 180, 0)); + + layer3D.addChild(this._sprite3D2); + this._sprite3D2.setPosition3D(cc.math.vec3(0, 0, -20)); + this._sprite3D2.setScale(2); + this._sprite3D2.setRotation3D(cc.math.vec3(-90, 180, 0)); + + this._camera = cc.Camera.createPerspective(60, cc.winSize.width/cc.winSize.height, 1, 1000); + this._camera.setCameraFlag(cc.CameraFlag.USER1); + this._camera.setPosition3D(cc.math.vec3(0, 30, 40)); + this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); + layer3D.addChild(this._camera); + layer3D.setCameraMask(2); + }, + + onExit:function(){ + this._super(); + cc.director.setClearColor(cc.color(0, 0, 0)); + }, + + switchTypeCallback:function(sender){ + var type = sender.getUserData(); + if(type === 0){ + this._state.setUniformVec4("u_fogColor", cc.math.vec4(0.5, 0.5, 0.5, 1.0)); + this._state.setUniformFloat("u_fogStart", 10); + this._state.setUniformFloat("u_fogEnd", 60); + this._state.setUniformInt("u_fogEquation", 0); + + this._sprite3D1.setGLProgramState(this._state); + this._sprite3D2.setGLProgramState(this._state); + }else if(type === 1){ + this._state.setUniformVec4("u_fogColor", cc.math.vec4(0.5, 0.5, 0.5, 1.0)); + this._state.setUniformFloat("u_fogDensity", 0.03); + this._state.setUniformInt("u_fogEquation", 1); + + this._sprite3D1.setGLProgramState(this._state); + this._sprite3D2.setGLProgramState(this._state); + }else if(type === 2){ + this._state.setUniformVec4("u_fogColor", cc.math.vec4(0.5, 0.5, 0.5, 1.0)); + this._state.setUniformFloat("u_fogDensity", 0.03); + this._state.setUniformInt("u_fogEquation", 2); + + this._sprite3D1.setGLProgramState(this._state); + this._sprite3D2.setGLProgramState(this._state); + } + }, + + onTouchesMoved:function(touches, event){ + if(touches.length === 1){ + var prelocation = touches[0].getPreviousLocationInView(); + var location = touches[0].getLocationInView(); + var newPos = cc.math.vec3Sub(prelocation, location); + + var m = this._camera.getNodeToWorldTransform3D(); + var cameraDir = cc.math.vec3(-m[8], -m[9], -m[10]); + cameraDir.normalize(); + cameraDir.y = 0; + var cameraRightDir = cc.math.vec3(m[0], m[1], m[2]); + cameraRightDir.normalize(); + cameraRightDir.y = 0; + + var cameraPos = this._camera.getPosition3D(); + cameraPos.x += cameraDir.x*newPos.y*0.1 + cameraRightDir.x*newPos.x*0.1; + cameraPos.y += cameraDir.y*newPos.y*0.1 + cameraRightDir.y*newPos.x*0.1; + cameraPos.z += cameraDir.z*newPos.y*0.1 + cameraRightDir.z*newPos.x*0.1; + this._camera.setPosition3D(cameraPos); + } + } +}); + +// +// Flow control +// +var arrayOfCamera3DTest = [ + CameraRotationTest, + Camera3DTest, + CameraCullingDemo, + CameraArcBallDemo +]; + +if(cc.sys.os !== cc.sys.OS_WP8 || cc.sys.os !== cc.sys.OS_WINRT){ + arrayOfCamera3DTest.push(FogTestDemo); +} + +var nextCamera3DTest = function () { + Camera3DTestIdx++; + Camera3DTestIdx = Camera3DTestIdx % arrayOfCamera3DTest.length; + + return new arrayOfCamera3DTest[Camera3DTestIdx ](); +}; +var previousCamera3DTest = function () { + Camera3DTestIdx--; + if (Camera3DTestIdx < 0) + Camera3DTestIdx += arrayOfCamera3DTest.length; + + return new arrayOfCamera3DTest[Camera3DTestIdx ](); +}; +var restartCamera3DTest = function () { + return new arrayOfCamera3DTest[Camera3DTestIdx ](); +}; diff --git a/samples/js-tests/src/ChipmunkTest/ChipmunkTest.js b/samples/js-tests/src/ChipmunkTest/ChipmunkTest.js index f94c23d330..1988649904 100644 --- a/samples/js-tests/src/ChipmunkTest/ChipmunkTest.js +++ b/samples/js-tests/src/ChipmunkTest/ChipmunkTest.js @@ -263,7 +263,7 @@ var ChipmunkCollisionTest_no_specific_type = ChipmunkBaseLayer.extend({ var staticBody = this.space.staticBody; // Walls - var walls = [ new cp.SegmentShape( staticBody, cp.v(0,0), cp.v(winSize.width,0), 0 ), // bottom + var walls = [ new cp.SegmentShape( staticBody, cp.v(0,0), cp.v(winSize.width,0), 0 ) // bottom // new cp.SegmentShape( staticBody, cp.v(0,winSize.height), cp.v(winSize.width,winSize.height), 0), // top // new cp.SegmentShape( staticBody, cp.v(0,0), cp.v(0,winSize.height), 0), // left // new cp.SegmentShape( staticBody, cp.v(winSize.width,0), cp.v(winSize.width,winSize.height), 0) // right diff --git a/samples/js-tests/src/CocoStudioTest/CocoStudioTest.js b/samples/js-tests/src/CocoStudioTest/CocoStudioTest.js index 135fc881f8..b8e18bba3e 100644 --- a/samples/js-tests/src/CocoStudioTest/CocoStudioTest.js +++ b/samples/js-tests/src/CocoStudioTest/CocoStudioTest.js @@ -97,7 +97,40 @@ var CocoStudioMainLayer = cc.Layer.extend({ } }); +var cocoStudioOldApiFlag = 0; var CocoStudioTestScene = TestScene.extend({ + + onEnter: function(){ + TestScene.prototype.onEnter.call(this); + + var winSize = cc.director.getWinSize(); + + var pMenu = new cc.Menu(); + pMenu.x = 0; + pMenu.y = 0; + cc.MenuItemFont.setFontName("Arial"); + cc.MenuItemFont.setFontSize(24); + var str = "new api"; + if(cocoStudioOldApiFlag){ + str = "old api"; + } + var pItem = new cc.MenuItemFont(str, + function(){ + if(cocoStudioOldApiFlag){ + cocoStudioOldApiFlag = 0; + pItem.setString("new api"); + }else{ + cocoStudioOldApiFlag = 1; + pItem.setString("old api"); + } + }, this); + pItem.x = 50; + pItem.y = winSize.height - 20; + pMenu.addChild(pItem); + + this.addChild(pMenu); + }, + runThisTest:function () { var pLayer = new CocoStudioMainLayer(); this.addChild(pLayer); diff --git a/samples/js-tests/src/CocoStudioTest/CustomTest/CustomImageView/CustomImageViewReader.js b/samples/js-tests/src/CocoStudioTest/CustomTest/CustomImageView/CustomImageViewReader.js index 7fcc47bafc..b2aec77aee 100644 --- a/samples/js-tests/src/CocoStudioTest/CustomTest/CustomImageView/CustomImageViewReader.js +++ b/samples/js-tests/src/CocoStudioTest/CustomTest/CustomImageView/CustomImageViewReader.js @@ -37,6 +37,6 @@ var customImageViewReader = { }, setPropsFromJsonDictionary: function(){ - ccs.ImageViewReader.setPropsFromJsonDictionary.apply(this, arguments); + ccs.imageViewReader.setPropsFromJsonDictionary.apply(this, arguments); } }; \ No newline at end of file diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UIBaseLayer.js b/samples/js-tests/src/CocoStudioTest/GUITest/UIBaseLayer.js index e36c4bf2f5..c47f7d93df 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UIBaseLayer.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UIBaseLayer.js @@ -49,6 +49,18 @@ var UIBaseLayer = cc.Layer.extend({ this._mainNode = mainNode; this._topDisplayText = topDisplayText; }, + + _parseUIFile: function(file){ + if(cocoStudioOldApiFlag == 0){ + cc.log("ccs.load : %s", file); + var json = ccs.load(file); + return json.node; + }else{ + cc.log("ccs.uiReader.widgetFromJsonFile : %s", file); + return ccs.uiReader.widgetFromJsonFile(file) + } + }, + backEvent: function (sender, type) { if (type == ccui.Widget.TOUCH_ENDED) { runGuiTestMain(); diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UIButtonTest/UIButtonTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UIButtonTest/UIButtonTest.js index c205cc7cc7..cfff52221a 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UIButtonTest/UIButtonTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UIButtonTest/UIButtonTest.js @@ -27,7 +27,7 @@ var UIButtonEditorTest = UIBaseLayer.extend({ ctor: function () { this._super(); - var root = ccs.uiReader.widgetFromJsonFile("res/cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.json"); + var root = this._parseUIFile("res/cocosui/CCS/Button/Button_1.json"); this._mainNode.addChild(root); var back_label = ccui.helper.seekWidgetByName(root, "back"); diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UICheckBoxTest/UICheckBoxTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UICheckBoxTest/UICheckBoxTest.js index ad15b387e9..d5f89573a4 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UICheckBoxTest/UICheckBoxTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UICheckBoxTest/UICheckBoxTest.js @@ -23,19 +23,49 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ +var CEHCK_BOX_INDEX = 0; var UICheckBoxEditorTest = UIBaseLayer.extend({ ctor: function () { this._super(); - var root = ccs.uiReader.widgetFromJsonFile("res/cocosui/UIEditorTest/UICheckBox_Editor/ui_checkbox_editor_1.json"); - this._mainNode.addChild(root); - - var back_label =ccui.helper.seekWidgetByName(root, "back"); - back_label.addTouchEventListener(this.backEvent,this); - - var checkbox = ccui.helper.seekWidgetByName(root, "CheckBox_540"); - checkbox.addEventListener(this.selectedStateEvent,this); + var left_button = new ccui.Button(); + left_button.loadTextures("res/Images/b1.png", "res/Images/b2.png", ""); + left_button.x = 240-50; + left_button.y = 50; + left_button.anchorX = 0.5; + left_button.anchorY = 0.5; + left_button.addTouchEventListener(this.previousCallback, this); + this._mainNode.addChild(left_button, 999); + var right_button = new ccui.Button(); + right_button.loadTextures("res/Images/f1.png", "res/Images/f2.png", ""); + right_button.x = 240+50; + right_button.y = 50; + right_button.anchorX = 0.5; + right_button.anchorY = 0.5; + right_button.addTouchEventListener(this.nextCallback, this); + this._mainNode.addChild(right_button, 999); + }, + previousCallback: function (render, type) { + if (type == ccui.Widget.TOUCH_ENDED) { + CEHCK_BOX_INDEX--; + if (CEHCK_BOX_INDEX < 0)CEHCK_BOX_INDEX = CEHCK_BOX_SCENE.length-1; + if (CEHCK_BOX_INDEX >= CEHCK_BOX_SCENE.length)CEHCK_BOX_INDEX = 0; + this.runNextScene(); + } + }, + nextCallback: function (render, type) { + if (type == ccui.Widget.TOUCH_ENDED) { + CEHCK_BOX_INDEX++; + if (CEHCK_BOX_INDEX < 0)CEHCK_BOX_INDEX = CEHCK_BOX_SCENE.length-1; + if (CEHCK_BOX_INDEX >= CEHCK_BOX_SCENE.length)CEHCK_BOX_INDEX = 0; + this.runNextScene(); + } + }, + runNextScene: function () { + var scene = new cc.Scene(); + scene.addChild(new CEHCK_BOX_SCENE[CEHCK_BOX_INDEX]()); + cc.director.runScene(scene); }, selectedStateEvent: function (sender, type) { @@ -52,3 +82,32 @@ var UICheckBoxEditorTest = UIBaseLayer.extend({ } } }); + +var UICheckBoxOldTest = UICheckBoxEditorTest.extend({ + ctor: function () { + this._super(); + var root = this._parseUIFile("res/cocosui/CCS/CheckBox/checkbox_1.json"); + this._mainNode.addChild(root); + + var back_label =ccui.helper.seekWidgetByName(root, "back"); + back_label.addTouchEventListener(this.backEvent,this); + + var checkbox = ccui.helper.seekWidgetByName(root, "CheckBox_540"); + checkbox.addEventListener(this.selectedStateEvent,this); + } +}); + +var UICheckBoxNewTest = UICheckBoxEditorTest.extend({ + ctor: function () { + this._super(); + var root = ccs.load("res/cocosui/CCS/CheckBox/MainScene.json"); + this._mainNode.addChild(root.node); + var checkbox = ccui.helper.seekWidgetByName(root.node, "CheckBox_1"); + checkbox.addEventListener(this.selectedStateEvent,this); + } +}); + +var CEHCK_BOX_SCENE = [ + UICheckBoxOldTest, + UICheckBoxNewTest +]; diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UIImageViewTest/UIImageViewTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UIImageViewTest/UIImageViewTest.js index 05d77be18b..f92f400761 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UIImageViewTest/UIImageViewTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UIImageViewTest/UIImageViewTest.js @@ -27,7 +27,7 @@ var UIImageViewEditorTest = UIBaseLayer.extend({ ctor: function () { this._super(); - var root = ccs.uiReader.widgetFromJsonFile("res/cocosui/UIEditorTest/UIImageView_Editor/ui_ImageView_editor_1.json"); + var root = this._parseUIFile("res/cocosui/CCS/ImageView/ImageView_1.json"); this._mainNode.addChild(root); var back_label =ccui.helper.seekWidgetByName(root, "back"); diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UILayoutTest/UILayoutTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UILayoutTest/UILayoutTest.js index b1e8a48f8f..6284598fca 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UILayoutTest/UILayoutTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UILayoutTest/UILayoutTest.js @@ -24,21 +24,21 @@ THE SOFTWARE. ****************************************************************************/ var LAYOUT_RES = [ - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ui_layout_editor_1.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ui_layout_color_editor_1.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ui_layout_gradient_color_editor_1_0.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ui_layout_backgroundimage_editor_1_0_0.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ui_layout_scale9_backgroundimage_editor.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ui_layout_linear_vertical_layout_editor.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ui_layout_linear_horizontal_layout_editor.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ui_layout_relative_align_parent_editor.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ui_layout_relative_align_location_editor.json" + "res/cocosui/CCS/Layout/Layout/layout_1.json", + "res/cocosui/CCS/Layout/Color/color_1.json", + "res/cocosui/CCS/Layout/Gradient_Color/gradient_color_1.json", + "res/cocosui/CCS/Layout/BackgroundImage/backgroundimage_1.json", + "res/cocosui/CCS/Layout/Scale9/scale9.json", + "res/cocosui/CCS/Layout/Linear_Vertical/linear_vertical.json", + "res/cocosui/CCS/Layout/Linear_Horizontal/linear_horizontal.json", + "res/cocosui/CCS/Layout/Relative_Align_Parent/relative_align_parent.json", + "res/cocosui/CCS/Layout/Relative_Align_Location/relative_align_location.json" ]; var LAYOUT_INDEX = 0; var UILayoutEditorTest = UIBaseLayer.extend({ ctor: function () { this._super(); - var root = ccs.uiReader.widgetFromJsonFile(LAYOUT_RES[LAYOUT_INDEX]); + var root = this._parseUIFile(LAYOUT_RES[LAYOUT_INDEX]); this._mainNode.addChild(root); var back_label = ccui.helper.seekWidgetByName(root, "back"); diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UIListViewTest/UIListViewTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UIListViewTest/UIListViewTest.js index e958f80b86..54201c6dcb 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UIListViewTest/UIListViewTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UIListViewTest/UIListViewTest.js @@ -24,14 +24,14 @@ THE SOFTWARE. ****************************************************************************/ var LISTVIEW_RES = [ - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.json", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.json" + "res/cocosui/CCS/ListView/Vertical/vertical_1.json", + "res/cocosui/CCS/ListView/Horizontal/horizontal_1.json" ]; var LISTVIEW_INDEX = 0; var UIListViewEditorTest = UIBaseLayer.extend({ ctor: function () { this._super(); - var root = ccs.uiReader.widgetFromJsonFile(LISTVIEW_RES[LISTVIEW_INDEX]); + var root = this._parseUIFile(LISTVIEW_RES[LISTVIEW_INDEX]); this._mainNode.addChild(root); var back_label = ccui.helper.seekWidgetByName(root, "back"); diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UILoadingBarTest/UILoadingBarTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UILoadingBarTest/UILoadingBarTest.js index 507b238eff..677f71301b 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UILoadingBarTest/UILoadingBarTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UILoadingBarTest/UILoadingBarTest.js @@ -30,7 +30,7 @@ var UILoadingBarEditorTest = UIBaseLayer.extend({ _loadingBar_right_to_left:null, ctor: function () { this._super(); - var root = ccs.uiReader.widgetFromJsonFile("res/cocosui/UIEditorTest/UILoadingBar_Editor/ui_loadingbar_editor_1.json"); + var root = this._parseUIFile("res/cocosui/CCS/LoadingBar/loadingbar_1.json"); this._mainNode.addChild(root); var back_label =ccui.helper.seekWidgetByName(root, "back"); diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UINodeContainerTest/UINodeContainerTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UINodeContainerTest/UINodeContainerTest.js index 8db1eb8d0c..f2f047cb0c 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UINodeContainerTest/UINodeContainerTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UINodeContainerTest/UINodeContainerTest.js @@ -27,7 +27,7 @@ var UIWidgetAddNodeEditorTest = UIBaseLayer.extend({ ctor: function () { this._super(); - var root = ccs.uiReader.widgetFromJsonFile("res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/ui_widget_add_node_editor.json"); + var root = this._parseUIFile("res/cocosui/CCS/WidgetAddNode/widget_add_node.json"); this._mainNode.addChild(root); var back_label =ccui.helper.seekWidgetByName(root, "back"); diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UIPageViewTest/UIPageViewTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UIPageViewTest/UIPageViewTest.js index 3d93337091..f50749bfe0 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UIPageViewTest/UIPageViewTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UIPageViewTest/UIPageViewTest.js @@ -27,7 +27,7 @@ var UIPageViewEditorTest = UIBaseLayer.extend({ ctor: function () { this._super(); - var root = ccs.uiReader.widgetFromJsonFile("res/cocosui/UIEditorTest/UIPageView_Editor/ui_pageview_editor_1.json"); + var root = this._parseUIFile("res/cocosui/CCS/PageView/pageview_1.json"); this._mainNode.addChild(root); var back_label =ccui.helper.seekWidgetByName(root, "back"); diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UISceneTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UISceneTest.js index bf78a43125..d1e25af47e 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UISceneTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UISceneTest.js @@ -34,7 +34,7 @@ var s_GuiTestEditorArray = [ { title: "CheckBox", layer: function () { - return new UICheckBoxEditorTest(); + return new CEHCK_BOX_SCENE[0](); } }, { diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UIScrollViewTest/UIScrollViewTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UIScrollViewTest/UIScrollViewTest.js index e63d156d7c..6bf63a4bfc 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UIScrollViewTest/UIScrollViewTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UIScrollViewTest/UIScrollViewTest.js @@ -25,15 +25,15 @@ ****************************************************************************/ var SCROLLVIEW_RES = [ - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ui_scrollview_editor_1.json", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ui_scrollview_horizontal_editor_1.json", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ui_scrollview_both_editor_1.json" + "res/cocosui/CCS/ScrollView/Vertical/vertical_1.json", + "res/cocosui/CCS/ScrollView/Horizontal/horizontal_1.json", + "res/cocosui/CCS/ScrollView/Both/both_1.json" ]; var SCROLLVIEW_INDEX = 0; var UIScrollViewEditorTest = UIBaseLayer.extend({ ctor: function () { this._super(); - var root = ccs.uiReader.widgetFromJsonFile(SCROLLVIEW_RES[SCROLLVIEW_INDEX]); + var root = this._parseUIFile(SCROLLVIEW_RES[SCROLLVIEW_INDEX]); this._mainNode.addChild(root); var back_label = ccui.helper.seekWidgetByName(root, "back"); diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UISliderTest/UISliderTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UISliderTest/UISliderTest.js index 8101f5cac5..727e9cddc3 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UISliderTest/UISliderTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UISliderTest/UISliderTest.js @@ -27,7 +27,7 @@ var UISliderEditorTest = UIBaseLayer.extend({ ctor: function () { this._super(); - var root = ccs.uiReader.widgetFromJsonFile("res/cocosui/UIEditorTest/UISlider_Editor/ui_slider_editor_1.json"); + var root = this._parseUIFile("res/cocosui/CCS/Slider/slider_1.json"); this._mainNode.addChild(root); var back_label =ccui.helper.seekWidgetByName(root, "back"); diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UITextAtlasTest/UITextAtlasTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UITextAtlasTest/UITextAtlasTest.js index fe50221ec6..d7aed9254c 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UITextAtlasTest/UITextAtlasTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UITextAtlasTest/UITextAtlasTest.js @@ -28,7 +28,8 @@ var UITextAtlasEditorTest = UIBaseLayer.extend({ ctor: function () { this._super(); - var root = ccs.uiReader.widgetFromJsonFile("res/cocosui/UIEditorTest/UILabelAtlas_Editor/ui_labelatlas_editor_1.json"); + var root = this._parseUIFile("res/cocosui/CCS/LabelAtlas/labelatlas_1.json"); + this._mainNode.addChild(root); var back_label =ccui.helper.seekWidgetByName(root, "back"); diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UITextBMFontTest/UITextBMFontTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UITextBMFontTest/UITextBMFontTest.js index 0e491e7208..1b23e535e6 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UITextBMFontTest/UITextBMFontTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UITextBMFontTest/UITextBMFontTest.js @@ -28,7 +28,7 @@ var UITextBMFontEditorTest = UIBaseLayer.extend({ ctor: function () { this._super(); - var root = ccs.uiReader.widgetFromJsonFile("res/cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.json"); + var root = this._parseUIFile("res/cocosui/CCS/LabelBMFont/labelbmfont_1.json"); this._mainNode.addChild(root); var back_label =ccui.helper.seekWidgetByName(root, "back"); diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UITextFieldTest/UITextFieldTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UITextFieldTest/UITextFieldTest.js index bd2fa7fafd..e8fa7a86a1 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UITextFieldTest/UITextFieldTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UITextFieldTest/UITextFieldTest.js @@ -27,7 +27,7 @@ var UITextFieldEditorTest = UIBaseLayer.extend({ ctor: function () { this._super(); - var root = ccs.uiReader.widgetFromJsonFile("res/cocosui/UIEditorTest/UITextField_Editor/ui_textfield_editor_1.json"); + var root = this._parseUIFile("res/cocosui/CCS/TextField/textfield_1.json"); this._mainNode.addChild(root); var back_label =ccui.helper.seekWidgetByName(root, "back"); diff --git a/samples/js-tests/src/CocoStudioTest/GUITest/UITextTest/UITextTest.js b/samples/js-tests/src/CocoStudioTest/GUITest/UITextTest/UITextTest.js index dfe96bd093..ecadf762f1 100644 --- a/samples/js-tests/src/CocoStudioTest/GUITest/UITextTest/UITextTest.js +++ b/samples/js-tests/src/CocoStudioTest/GUITest/UITextTest/UITextTest.js @@ -28,7 +28,7 @@ var UITextEditorTest = UIBaseLayer.extend({ ctor: function () { this._super(); - var root = ccs.uiReader.widgetFromJsonFile("res/cocosui/UIEditorTest/UILabel_Editor/ui_label_editor_1.json"); + var root = this._parseUIFile("res/cocosui/CCS/Label/label_1.json"); this._mainNode.addChild(root); var back_label =ccui.helper.seekWidgetByName(root, "back"); diff --git a/samples/js-tests/src/CocoStudioTest/ParserTest/ParserTest.js b/samples/js-tests/src/CocoStudioTest/ParserTest/ParserTest.js index 79443cd7f0..62157ac75d 100644 --- a/samples/js-tests/src/CocoStudioTest/ParserTest/ParserTest.js +++ b/samples/js-tests/src/CocoStudioTest/ParserTest/ParserTest.js @@ -27,17 +27,22 @@ var g_parsersTests = [ { title: "cocostudio 1.3", test: function(){ - new CocostudioParserJsonScene("res/cocosui/UIEditorTest/cocostudio1_3/CocostudioV1_3_1.ExportJson").runThisTest(); + new CocostudioParserJsonScene("res/cocosui/CCS/ccs1_3/CCSV1_3_1.ExportJson").runThisTest(); } },{ title: "cocostudio 1.4", test: function(){ - new CocostudioParserJsonScene("res/cocosui/UIEditorTest/cocostudio1_4/Cocostudio1_4_1.ExportJson").runThisTest(); + new CocostudioParserJsonScene("res/cocosui/CCS/ccs1_4/CCS1_4_1.ExportJson").runThisTest(); } },{ title: "cocostudio 1.5", test: function(){ - new CocostudioParserJsonScene("res/cocosui/UIEditorTest/cocostudio1_5/Cocostudio1_5_1.ExportJson").runThisTest(); + new CocostudioParserJsonScene("res/cocosui/CCS/ccs1_5/CCS1_5_1.ExportJson").runThisTest(); + } + },{ + title: "cocostudio 2.1", + test: function(){ + new CocostudioParserJsonScene("res/cocosui/CCS/2.1/MainScene.json").runThisTest(); } } ]; @@ -62,20 +67,23 @@ var CocostudioParserJsonLayer = cc.Layer.extend({ this._super(); cc.Layer.prototype.onEnter.call(this); - var guiReader = ccs.uiReader; - -// guiReader.registerTypeAndCallBack("CustomImageView", -// CustomImageView, -// customImageViewReader, -// customImageViewReader.setProperties); -// guiReader.registerTypeAndCallBack("CustomParticleWidget", -// CustomParticleWidget, -// customParticleWidgetReader, -// customParticleWidgetReader.setProperties); + var layout; + if(cocoStudioOldApiFlag == 0){ + cc.log("ccs.load : %s", this._jsonFile); + var json = ccs.load(this._jsonFile); + layout = json.node; + }else{ + //old api + cc.log("ccs.uiReader.widgetFromJsonFile : %s", this._jsonFile); + var guiReader = ccs.uiReader; + layout = guiReader.widgetFromJsonFile(this._jsonFile); + } + if(layout){ + if(layout.getScale() == 1) + layout.setScale(0.7); - var layout = guiReader.widgetFromJsonFile(this._jsonFile); - layout.setScale(0.7); - this.addChild(layout); + this.addChild(layout); + } } }); @@ -132,6 +140,8 @@ var CocostudioParserJsonScene = cc.Scene.extend({ cc.director.runScene(this); }, BackCallback: function(){ + cc.audioEngine.stopMusic(); + cc.audioEngine.stopAllEffects(); if(this._jsonFile){ new CocostudioParserJsonScene().runThisTest(); }else{ diff --git a/samples/js-tests/src/CocoStudioTest/SceneTest/SceneEditorTest.js b/samples/js-tests/src/CocoStudioTest/SceneTest/SceneEditorTest.js index 556c80bcc7..de81011dec 100644 --- a/samples/js-tests/src/CocoStudioTest/SceneTest/SceneEditorTest.js +++ b/samples/js-tests/src/CocoStudioTest/SceneTest/SceneEditorTest.js @@ -150,7 +150,17 @@ var runSceneEditorTest = function () { var LoadSceneEdtiorFileTest = SceneEditorTestLayer.extend({ onEnter: function () { this._super(); - var node = ccs.sceneReader.createNodeWithSceneFile("res/scenetest/LoadSceneEdtiorFileTest/FishJoy2.json"); + var node, + file = "res/scenetest/LoadSceneEdtiorFileTest/FishJoy2.json"; + if(cocoStudioOldApiFlag == 0){ + cc.log("ccs.load : %s", file); + var json = ccs.load(file); + node = json.node; + }else{ + //old api + cc.log("ccs.sceneReader.createNodeWithSceneFile : %s", file); + node = ccs.sceneReader.createNodeWithSceneFile(file); + } this.addChild(node); ccs.actionManager.playActionByName("startMenu_1.json", "Animation1"); this.initSize(node); @@ -172,7 +182,17 @@ var LoadSceneEdtiorFileTest = SceneEditorTestLayer.extend({ var SpriteComponentTest = SceneEditorTestLayer.extend({ onEnter: function () { this._super(); - var node = ccs.sceneReader.createNodeWithSceneFile("res/scenetest/SpriteComponentTest/SpriteComponentTest.json"); + var node, + file = "res/scenetest/SpriteComponentTest/SpriteComponentTest.json"; + if(cocoStudioOldApiFlag == 0){ + cc.log("ccs.load : %s", file); + var json = ccs.load(file); + node = json.node; + }else{ + //old api + cc.log("ccs.sceneReader.createNodeWithSceneFile : %s", file); + node = ccs.sceneReader.createNodeWithSceneFile(file); + } this.addChild(node); var action1 = cc.blink(2, 10); @@ -198,7 +218,17 @@ var SpriteComponentTest = SceneEditorTestLayer.extend({ var ArmatureComponentTest = SceneEditorTestLayer.extend({ onEnter: function () { this._super(); - var node = ccs.sceneReader.createNodeWithSceneFile("res/scenetest/ArmatureComponentTest/ArmatureComponentTest.json"); + var node, + file = "res/scenetest/ArmatureComponentTest/ArmatureComponentTest.json"; + if(cocoStudioOldApiFlag == 0){ + cc.log("ccs.load : %s", file); + var json = ccs.load(file); + node = json.node;ccs.load(file); + }else{ + //old api + cc.log("ccs.sceneReader.createNodeWithSceneFile : %s", file); + node = ccs.sceneReader.createNodeWithSceneFile(file); + } this.addChild(node); var blowFish = node.getChildByTag(10007).getComponent("CCArmature").getNode(); @@ -223,7 +253,18 @@ var UIComponentTest = SceneEditorTestLayer.extend({ _node: null, onEnter: function () { this._super(); - this._node = ccs.sceneReader.createNodeWithSceneFile("res/scenetest/UIComponentTest/UIComponentTest.json"); + var node, + file = "res/scenetest/UIComponentTest/UIComponentTest.json"; + if(cocoStudioOldApiFlag == 0){ + cc.log("ccs.load : %s", file); + var json = ccs.load(file); + node = json.node; + }else{ + //old api + cc.log("ccs.sceneReader.createNodeWithSceneFile : %s", file); + node = ccs.sceneReader.createNodeWithSceneFile(file); + } + this._node = node; this.addChild(this._node); var widget = this._node.getChildByTag(10025).getComponent("GUIComponent").getNode(); var button = widget.getChildByName("Button_156"); @@ -257,7 +298,17 @@ var UIComponentTest = SceneEditorTestLayer.extend({ var TmxMapComponentTest = SceneEditorTestLayer.extend({ onEnter: function () { this._super(); - var node = ccs.sceneReader.createNodeWithSceneFile("res/scenetest/TmxMapComponentTest/TmxMapComponentTest.json"); + var node, + file = "res/scenetest/TmxMapComponentTest/TmxMapComponentTest.json"; + if(cocoStudioOldApiFlag == 0){ + cc.log("ccs.load : %s", file); + var json = ccs.load(file); + node = json.node; + }else{ + //old api + cc.log("ccs.sceneReader.createNodeWithSceneFile : %s", file); + node = ccs.sceneReader.createNodeWithSceneFile(file); + } this.addChild(node); var tmxMap = node.getChildByTag(10015).getComponent("CCTMXTiledMap").getNode(); var actionTo = cc.skewTo(2, 0, 2); @@ -288,7 +339,17 @@ var TmxMapComponentTest = SceneEditorTestLayer.extend({ var ParticleComponentTest = SceneEditorTestLayer.extend({ onEnter: function () { this._super(); - var node = ccs.sceneReader.createNodeWithSceneFile("res/scenetest/ParticleComponentTest/ParticleComponentTest.json"); + var node, + file = "res/scenetest/ParticleComponentTest/ParticleComponentTest.json"; + if(cocoStudioOldApiFlag == 0){ + cc.log("ccs.load : %s", file); + var json = ccs.load(file); + node = json.node; + }else{ + //old api + cc.log("ccs.sceneReader.createNodeWithSceneFile : %s", file); + node = ccs.sceneReader.createNodeWithSceneFile(file); + } this.addChild(node); var particle = node.getChildByTag(10020).getComponent("CCParticleSystemQuad").getNode(); @@ -312,7 +373,18 @@ var EffectComponentTest = SceneEditorTestLayer.extend({ _node: null, onEnter: function () { this._super(); - this._node = ccs.sceneReader.createNodeWithSceneFile("res/scenetest/EffectComponentTest/EffectComponentTest.json"); + var node, + file = "res/scenetest/EffectComponentTest/EffectComponentTest.json"; + if(cocoStudioOldApiFlag == 0){ + cc.log("ccs.load : %s", file); + var json = ccs.load(file); + node = json.node; + }else{ + //old api + cc.log("ccs.sceneReader.createNodeWithSceneFile : %s", file); + node = ccs.sceneReader.createNodeWithSceneFile(file); + } + this._node = node; this.addChild(this._node); var armature = this._node.getChildByTag(10015).getComponent("CCArmature").getNode(); @@ -341,7 +413,17 @@ var EffectComponentTest = SceneEditorTestLayer.extend({ var BackgroundComponentTest = SceneEditorTestLayer.extend({ onEnter: function () { this._super(); - var node = ccs.sceneReader.createNodeWithSceneFile("res/scenetest/BackgroundComponentTest/BackgroundComponentTest.json"); + var node, + file = "res/scenetest/BackgroundComponentTest/BackgroundComponentTest.json"; + if(cocoStudioOldApiFlag == 0){ + cc.log("ccs.load : %s", file); + var json = ccs.load(file); + node = json.node; + }else{ + //old api + cc.log("ccs.sceneReader.createNodeWithSceneFile : %s", file); + node = ccs.sceneReader.createNodeWithSceneFile(file); + } this.addChild(node); ccs.actionManager.playActionByName("startMenu_1.json", "Animation1"); @@ -367,7 +449,17 @@ var BackgroundComponentTest = SceneEditorTestLayer.extend({ var AttributeComponentTest = SceneEditorTestLayer.extend({ onEnter: function () { this._super(); - var node = ccs.sceneReader.createNodeWithSceneFile("res/scenetest/AttributeComponentTest/AttributeComponentTest.json"); + var node, + file = "res/scenetest/AttributeComponentTest/AttributeComponentTest.json"; + if(cocoStudioOldApiFlag == 0){ + cc.log("ccs.load : %s", file); + var json = ccs.load(file); + node = json.node; + }else{ + //old api + cc.log("ccs.sceneReader.createNodeWithSceneFile : %s", file); + node = ccs.sceneReader.createNodeWithSceneFile(file); + } this.addChild(node); var comAttribute = node.getChildByTag(10015).getComponent("CCComAttribute"); @@ -395,7 +487,17 @@ var TriggerTest = SceneEditorTestLayer.extend({ _flyFishNode: null, onEnter: function () { this._super(); - var node = ccs.sceneReader.createNodeWithSceneFile("res/scenetest/TriggerTest/TriggerTest.json"); + var node, + file = "res/scenetest/TriggerTest/TriggerTest.json"; + if(cocoStudioOldApiFlag == 0){ + cc.log("ccs.load : %s", file); + var json = ccs.load(file); + node = json.node; + }else{ + //old api + cc.log("ccs.sceneReader.createNodeWithSceneFile : %s", file); + node = ccs.sceneReader.createNodeWithSceneFile(file); + } this.addChild(node); ccs.actionManager.playActionByName("startMenu_1.json", "Animation1"); diff --git a/samples/js-tests/src/CocosDenshionTest/CocosDenshionTest.js b/samples/js-tests/src/CocosDenshionTest/CocosDenshionTest.js index ad96d2a6c2..b076eca8e1 100644 --- a/samples/js-tests/src/CocosDenshionTest/CocosDenshionTest.js +++ b/samples/js-tests/src/CocosDenshionTest/CocosDenshionTest.js @@ -26,8 +26,8 @@ var audioEngine = cc.audioEngine; -var MUSIC_FILE = "res/Sound/background.mp3"; -var EFFECT_FILE = "res/Sound/effect2.mp3"; +var MUSIC_FILE = cc.sys.os == cc.sys.OS_WP8 || cc.sys.os == cc.sys.OS_WINRT ? "res/Sound/background-music-aac.wav" : "res/Sound/background.mp3"; +var EFFECT_FILE = cc.sys.os == cc.sys.OS_WP8 || cc.sys.os == cc.sys.OS_WINRT ? "res/Sound/pew-pew-lei.wav" : "res/Sound/effect2.mp3"; var _DenshionTests = [ 'Music Test' diff --git a/samples/js-tests/src/EventTest/EventTest.js b/samples/js-tests/src/EventTest/EventTest.js index 93432e8a9d..e89b13c1c2 100644 --- a/samples/js-tests/src/EventTest/EventTest.js +++ b/samples/js-tests/src/EventTest/EventTest.js @@ -394,23 +394,55 @@ var MouseTest = EventTest.extend({ // //------------------------------------------------------------------ var KeyboardTest = EventTest.extend({ - init:function () { + init: function () { this._super(); - - if( 'keyboard' in cc.sys.capabilities ) { + var self = this; + var label = new cc.LabelTTF("show key Code"); + var size = cc.director.getWinSize(); + label.setPosition(size.width / 2, size.height / 2); + this.addChild(label); + if ('keyboard' in cc.sys.capabilities) { cc.eventManager.addListener({ event: cc.EventListener.KEYBOARD, - onKeyPressed:function(key, event) { - cc.log("Key down:" + key); + onKeyPressed: function (key, event) { + var strTemp = "Key down:" + key; + var keyStr = self.getKeyStr(key); + if (keyStr.length > 0) + { + strTemp += " the key name is:" + keyStr; + } + label.setString(strTemp); }, - onKeyReleased:function(key, event) { - cc.log("Key up:" + key); + onKeyReleased: function (key, event) { + var strTemp = "Key up:" + key; + var keyStr = self.getKeyStr(key); + if (keyStr.length > 0) + { + strTemp += " the key name is:" + keyStr; + } + label.setString(strTemp); } }, this); } else { cc.log("KEYBOARD Not supported"); } }, + getKeyStr: function (keycode) + { + if (keycode == cc.KEY.none) + { + return ""; + } + + for (var keyTemp in cc.KEY) + { + if (cc.KEY[keyTemp] == keycode) + { + return keyTemp; + } + } + return ""; + }, subtitle:function () { return "Keyboard test. Press keyboard and see console"; }, diff --git a/samples/js-tests/src/ExtensionsTest/CocostudioActionTimelineTest/ActionTimelineTestScene.js b/samples/js-tests/src/ExtensionsTest/CocostudioActionTimelineTest/ActionTimelineTestScene.js deleted file mode 100644 index 02fd5c3bbe..0000000000 --- a/samples/js-tests/src/ExtensionsTest/CocostudioActionTimelineTest/ActionTimelineTestScene.js +++ /dev/null @@ -1,317 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2014 Chukong Technologies Inc. - - 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. - ****************************************************************************/ - -var ActionTimelineTestScene = (function(){ - - var ActionTimelineTestSceneEnum = { - TEST_ANIMATIONELEMENT: 0, - TEST_CHANGE_PLAY_SECTION: 1, - TEST_TIMELINE_FRAME_EVENT: 2, - TEST_TIMELINE_PERFORMACE: 3, - - TEST_ANIMATION_LAYER_COUNT: 4 - }; - - var s_nActionIdx = -1; - - var ActionTimelineTestScene = TestScene.extend({ - - ctor: function(bPortrait){ - TestScene.prototype.ctor.call(this); - TestScene.prototype.init.call(this); - - var bg = new cc.Sprite("res/armatures/bg.jpg"); - bg.setPosition(cc.p(400, 225)); - - var scaleX = 800 / 500; - var scaleY = 450 / 500; - - bg.setScaleX(scaleX); - bg.setScaleY(scaleY); - - this.addChild(bg); - - }, - - runThisTest: function(){ - s_nActionIdx = -1; - this.addChild(NextAnimationTest()); - var self = this; - cc.loader.load([ - "res/ActionTimeline/boy_1.ExportJson", - "res/armatures/Cowboy0.plist", - "res/armatures/Cowboy0.png" - ], function(){ - cc.director.runScene(self); - }); - }, - - MainMenuCallback: function(pSender){ - this.removeAllChildren(); - } - }); - - var ActionTimelineTestLayer = cc.Layer.extend({ - - _restartItem: null, - _nextItem: null, - _backItem: null, - - title: function(){ - return "armatures Test Bed"; - }, - subtitle: function(){ - return ""; - }, - restartCallback: function(pSender){ - var s = new ActionTimelineTestScene(); - s.addChild( RestartAnimationTest() ); - cc.director.runScene(s); - }, - nextCallback: function(pSender){ - var s = new ActionTimelineTestScene(); - s.addChild( NextAnimationTest() ); - cc.director.runScene(s); - }, - backCallback: function(pSender){ - var s = new ActionTimelineTestScene(); - s.addChild( BackAnimationTest() ); - cc.director.runScene(s); - }, - onEnter: function(){ - cc.Layer.prototype.onEnter.call(this); - - // add title and subtitle - var title = this.title(); - var label = new cc.LabelTTF(title, "Arial", 18); - label.setColor(cc.color(0, 0, 0)); - this.addChild(label, 1, 10000); - label.setPosition( cc.p(cc.winSize.width/2, cc.winSize.height - 80) ); - - var strSubtitle = this.subtitle(); - if( ! strSubtitle ) - { - var l = new cc.LabelTTF(strSubtitle, "Arial", 18); - l.setColor(cc.color(0, 0, 0)); - this.addChild(l, 1, 10001); - l.setPosition(cc.winSize.width/2, cc.winSize.height - 110); - } - - // add menu - this._backItem = new cc.MenuItemImage(s_pathB1, s_pathB2, this.backCallback); - this._restartItem = new cc.MenuItemImage(s_pathR1, s_pathR2, this.restartCallback); - this._nextItem = new cc.MenuItemImage(s_pathF1, s_pathF2, this.nextCallback); - - var menu = new cc.Menu(this._backItem, this._restartItem, this._nextItem); - - menu.setPosition(cc.p(0, 0)); - this._backItem.setPosition(cc.winSize.width/2 - this._restartItem.getContentSize().width * 2, this._restartItem.getContentSize().height / 2); - this._restartItem.setPosition(cc.winSize.width/2, this._restartItem.getContentSize().height / 2); - this._nextItem.setPosition(cc.winSize.width/2 + this._restartItem.getContentSize().width * 2, this._restartItem.getContentSize().height / 2); - - this.addChild(menu, 100); - - //this.setGLProgram(ShaderCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); - - }, - onExit: function(){ - this.removeAllChildren(); - this._backItem = this._restartItem = this._nextItem = null; - cc.Layer.prototype.onExit.call(this); - - } - }); - - var TestActionTimeline = ActionTimelineTestLayer.extend({ - - onEnter: function(){ - ActionTimelineTestLayer.prototype.onEnter.call(this); - - cc.spriteFrameCache.addSpriteFrames("res/armatures/Cowboy0.plist", "res/armatures/Cowboy0.png"); - - var node = ccs.csLoader.createNode("res/ActionTimeline/boy_1.ExportJson"); - var action = ccs.actionTimelineCache.createAction("res/ActionTimeline/boy_1.ExportJson"); - - node.runAction(action); - action.gotoFrameAndPlay(0, 60, true); - - node.setScale(0.2); - node.setPosition(150,100); - - this.addChild(node); - }, - title: function(){ - return "Test ActionTimeline"; - } - }); - - var TestChangePlaySection = ActionTimelineTestLayer.extend({ - - _action: null, - - onEnter: function(){ - ActionTimelineTestLayer.prototype.onEnter.call(this); - - cc.spriteFrameCache.addSpriteFrames("res/armatures/Cowboy0.plist", "res/armatures/Cowboy0.png"); - - var node = ccs.csLoader.createNode("res/ActionTimeline/boy_1.ExportJson"); - this._action = ccs.actionTimelineCache.createAction("res/ActionTimeline/boy_1.ExportJson"); - - node.runAction(this._action); - this._action.gotoFrameAndPlay(70, this._action.getDuration(), true); - - node.setScale(0.2); - node.setPosition(150,100); - - // add touch event listener - cc.eventManager.addListener({ - event: cc.EventListener.TOUCH_ONE_BY_ONE, - onTouchBegan: this.onTouchesEnded - }, this); - - this.addChild(node); - - }, - title: function(){ - return "Test Change Play Section"; - }, - onTouchesEnded: function(touches, event){ - var target = event.getCurrentTarget(); - if(target._action.getStartFrame() == 0) - target._action.gotoFrameAndPlay(70, target._action.getDuration(), true); - else - target._action.gotoFrameAndPlay(0, 60, true); - - return true; - } - - }); - - var TestTimelineFrameEvent = ActionTimelineTestLayer.extend({ - onEnter: function(){ - ActionTimelineTestLayer.prototype.onEnter.call(this); - - cc.spriteFrameCache.addSpriteFrames("res/armatures/Cowboy0.plist", "res/armatures/Cowboy0.png"); - - var node = ccs.csLoader.createNode("res/ActionTimeline/boy_1.ExportJson"); - var action = ccs.actionTimelineCache.createAction("res/ActionTimeline/boy_1.ExportJson"); - node.runAction(action); - action.gotoFrameAndPlay(0, 60, true); - - node.setScale(0.2); - node.setPosition(150,100); - this.addChild(node); - - action.setFrameEventCallFunc(this.onFrameEvent); - }, - title: function(){ - return "Test Frame Event"; - }, - onFrameEvent: function(frame){ - var evnt = frame; - if(!evnt) - return; - - var str = evnt.getEvent(); - - if (str == "changeColor"){ - evnt.getNode().setColor(cc.color(0,0,0)); - }else if(str == "endChangeColor"){ - evnt.getNode().setColor(cc.color(255,255,255)); - } - } - }); - - var TestTimelinePerformance = ActionTimelineTestLayer.extend({ - onEnter: function(){ - ActionTimelineTestLayer.prototype.onEnter.call(this); - - cc.spriteFrameCache.addSpriteFrames("res/armatures/Cowboy0.plist", "res/armatures/Cowboy0.png"); - - for (var i = 0; i< 100; i++){ - var node = ccs.csLoader.createNode("res/ActionTimeline/boy_1.ExportJson"); - var action = ccs.actionTimelineCache.createAction("res/ActionTimeline/boy_1.ExportJson"); - - node.runAction(action); - action.gotoFrameAndPlay(70, action.getDuration(), true); - - node.setScale(0.1); - node.setPosition(i*2,100); - this.addChild(node); - } - }, - title: function(){ - return "Test ActionTimeline performance"; - } - }); - - var CreateAnimationLayer = function(index){ - var pLayer = null; - switch(index) - { - case ActionTimelineTestSceneEnum.TEST_ANIMATIONELEMENT: - pLayer = new TestActionTimeline(); - break; - case ActionTimelineTestSceneEnum.TEST_CHANGE_PLAY_SECTION: - pLayer = new TestChangePlaySection(); - break; - case ActionTimelineTestSceneEnum.TEST_TIMELINE_FRAME_EVENT: - pLayer = new TestTimelineFrameEvent(); - break; - case ActionTimelineTestSceneEnum.TEST_TIMELINE_PERFORMACE: - pLayer = new TestTimelinePerformance(); - break; - default: - break; - } - - return pLayer; - - }; - - var NextAnimationTest = function(){ - ++s_nActionIdx; - s_nActionIdx = s_nActionIdx % ActionTimelineTestSceneEnum.TEST_ANIMATION_LAYER_COUNT; - - var pLayer = CreateAnimationLayer(s_nActionIdx); - return pLayer; - - }; - - var BackAnimationTest = function(){ - --s_nActionIdx; - if( s_nActionIdx < 0 ) - s_nActionIdx += ActionTimelineTestSceneEnum.TEST_ANIMATION_LAYER_COUNT; - - var pLayer = CreateAnimationLayer(s_nActionIdx); - return pLayer; - }; - - var RestartAnimationTest = function(){ - var pLayer = CreateAnimationLayer(s_nActionIdx); - return pLayer; - }; - - return ActionTimelineTestScene; -})(); \ No newline at end of file diff --git a/samples/js-tests/src/ExtensionsTest/EditBoxTest/EditBoxTest.js b/samples/js-tests/src/ExtensionsTest/EditBoxTest/EditBoxTest.js index ead76f6ef0..97f87c9b02 100644 --- a/samples/js-tests/src/ExtensionsTest/EditBoxTest/EditBoxTest.js +++ b/samples/js-tests/src/ExtensionsTest/EditBoxTest/EditBoxTest.js @@ -51,6 +51,8 @@ var EditBoxTestLayer = cc.Layer.extend({ this._box2.y = 190; this._box2.setInputFlag(cc.EDITBOX_INPUT_FLAG_PASSWORD); this._box2.setFontColor(cc.color(255, 250, 0)); + this._box2.setPlaceHolder("please enter password"); + this._box2.setPlaceholderFontColor(cc.color(255, 255, 255)); this._box2.setDelegate(this); this.addChild(this._box2); diff --git a/samples/js-tests/src/ExtensionsTest/ExtensionsTest.js b/samples/js-tests/src/ExtensionsTest/ExtensionsTest.js index a07e6ca927..7f0e681e10 100644 --- a/samples/js-tests/src/ExtensionsTest/ExtensionsTest.js +++ b/samples/js-tests/src/ExtensionsTest/ExtensionsTest.js @@ -70,12 +70,6 @@ var extensionsTestItemNames = [ runTableViewTest(); } }, - { - itemTitle:"EditBoxTest", - testScene:function () { - runEditBoxTest(); - } - }, { itemTitle:"WebSocketTest", testScene:function () { @@ -93,16 +87,18 @@ var extensionsTestItemNames = [ testScene:function () { runCCPoolTest(); } - }, - { - itemTitle:"ActionTimelineTestScene", - testScene:function () { - var scene = new ActionTimelineTestScene(); - scene.runThisTest(); - } } ]; +if(!cc.sys.isNative || cc.sys.OS_LINUX !== cc.sys.os){ + extensionsTestItemNames.push({ + itemTitle:"EditBoxTest", + testScene:function () { + runEditBoxTest(); + } + }); +} + if (cc.sys.isNative && cc.sys.OS_IOS == cc.sys.os) { extensionsTestItemNames.push({ itemTitle:"PluginTest", diff --git a/samples/js-tests/src/GUITest/UIButtonTest/UIButtonTest.js b/samples/js-tests/src/GUITest/UIButtonTest/UIButtonTest.js index 7b3e62020e..2596a4f6b5 100644 --- a/samples/js-tests/src/GUITest/UIButtonTest/UIButtonTest.js +++ b/samples/js-tests/src/GUITest/UIButtonTest/UIButtonTest.js @@ -195,4 +195,374 @@ var UIButtonTest_Title = UIScene.extend({ break; } } +}); + +var UIButtonTestRemoveSelf = UIScene.extend({ + init: function () { + if (this._super()) { + //init text + this._topDisplayLabel.setString("No Event"); + this._bottomDisplayLabel.setString("Remove Self in the Button's Callback shouldn't cause crash!"); + this._bottomDisplayLabel.setFontSize(15); + + var widgetSize = this._widget.getContentSize(); + + var layout = new ccui.Layout(); + layout.setContentSize(widgetSize.width * 0.6, widgetSize.height * 0.6); + layout.setBackGroundColor(cc.color.GREEN); + layout.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID); + layout.setBackGroundColorOpacity(100); + layout.setPosition(widgetSize.width/2, widgetSize.height/2); + layout.setAnchorPoint(0.5, 0.5); + layout.setTag(12); + this._mainNode.addChild(layout); + + // Create the button + var button = new ccui.Button("res/cocosui/animationbuttonnormal.png", + "res/cocosui/animationbuttonpressed.png"); + button.setPosition(layout.width / 2.0, layout.height / 2.0); + button.addTouchEventListener(this.touchEvent, this); + layout.addChild(button); + return true; + } + return false; + }, + + touchEvent: function(sender, type){ + switch (type) { + case ccui.Widget.TOUCH_BEGAN: + this._topDisplayLabel.setString("Touch Down"); + break; + + case ccui.Widget.TOUCH_MOVED: + this._topDisplayLabel.setString("Touch Move"); + break; + + case ccui.Widget.TOUCH_ENDED: + this._topDisplayLabel.setString("Touch Up"); + var layout = this._mainNode.getChildByTag(12); + layout.removeFromParent(true); + break; + + case ccui.Widget.TOUCH_CANCELED: + this._topDisplayLabel.setString("Touch Cancelled"); + break; + + default: + break; + } + } +}); + +var UIButtonTestSwitchScale9 = UIScene.extend({ + init: function(){ + if (this._super()){ + var widgetSize = this._widget.getContentSize(); + + // Add a label in which the button events will be displayed + this._topDisplayLabel.setString("No Event"); + this._bottomDisplayLabel.setString(""); + + // Create the button + var button = new ccui.Button("res/cocosui/animationbuttonnormal.png", + "res/cocosui/animationbuttonpressed.png"); + button.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0); + button.addTouchEventListener(this.touchEvent, this); + button.setTitleText("Button Title"); + button.ignoreContentAdaptWithSize(false); + + this._mainNode.addChild(button); + return true; + } + return false; + }, + + touchEvent: function(sender, type){ + switch (type) { + case ccui.Widget.TOUCH_BEGAN: + this._topDisplayLabel.setString("Touch Down"); + break; + + case ccui.Widget.TOUCH_MOVED: + this._topDisplayLabel.setString("Touch Move"); + break; + + case ccui.Widget.TOUCH_ENDED: + this._topDisplayLabel.setString("Touch Up"); + sender.setScale9Enabled(!sender.isScale9Enabled()); + sender.setContentSize(200,100); + break; + + case ccui.Widget.TOUCH_CANCELED: + this._topDisplayLabel.setString("Touch Cancelled"); + break; + + default: + break; + } + } +}); + +var UIButtonTestZoomScale = UIScene.extend({ + init: function(){ + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + + // Add a label in which the button events will be displayed + this._topDisplayLabel.setString("Zoom Scale: -0.5"); + this._bottomDisplayLabel.setString(""); + + // Create the button + var button = new ccui.Button("res/cocosui/animationbuttonnormal.png", "res/cocosui/animationbuttonpressed.png"); + button.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0 ); + button.setPressedActionEnabled(true); + button.addClickEventListener(function () { + cc.log("Button clicked, position = (" + button.x + ", " + button.y + ")"); + }); + button.setName("button"); + this._mainNode.addChild(button); + button.setZoomScale(-0.5); + + var slider = new ccui.Slider(); + slider.loadBarTexture("res/cocosui/sliderTrack.png"); + slider.loadSlidBallTextures("res/cocosui/sliderThumb.png", "res/cocosui/sliderThumb.png", ""); + slider.loadProgressBarTexture("res/cocosui/sliderProgress.png"); + slider.setPosition(widgetSize.width / 2.0 , widgetSize.height / 2.0 - 50); + slider.addEventListener(this.sliderEvent, this); + slider.setPercent(button.getZoomScale() * 100); + this._mainNode.addChild(slider); + return true; + } + return false; + }, + + sliderEvent: function(slider, type){ + if (type == ccui.Slider.EVENT_PERCENT_CHANGED){ + var percent = slider.getPercent(); + var btn = this._mainNode.getChildByName("button"); + var zoomScale = percent * 0.01; + btn.setZoomScale(zoomScale); + this._topDisplayLabel.setString("Zoom Scale: "+ zoomScale.toFixed(2)); + } + } +}); + +var UIButtonTextOnly = UIScene.extend({ + init: function(){ + if (this._super()) { + // Add a label in which the button events will be displayed + this._topDisplayLabel.setString("Text Only Button"); + this._bottomDisplayLabel.setString(""); + + // Create the button + var button = new ccui.Button(); + button.setNormalizedPosition(0.5, 0.5); + + button.setTitleText("PLAY GAME"); + cc.log("content size should be greater than 0: width = %f, height = %f", button.width, button.height); + button.setZoomScale(0.3); + button.setPressedActionEnabled(true); + button.addClickEventListener(function () { + cc.log("clicked!"); + }); + this.addChild(button); + return true; + } + return false; + } +}); + +var UIButtonIgnoreContentSizeTest = UIScene.extend({ + init: function(){ + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + + // Add a label in which the button events will be displayed + this._topDisplayLabel.setString("Button IgnoreContent Size Test"); + this._bottomDisplayLabel.setString(""); + + // Create the button + var button = new ccui.Button("res/cocosui/animationbuttonnormal.png", "res/cocosui/animationbuttonpressed.png"); + button.ignoreContentAdaptWithSize(false); + button.setContentSize(200,100); + button.setNormalizedPosition(0.3, 0.5); + button.setTitleText("PLAY GAME"); + button.setZoomScale(0.3); + button.setPressedActionEnabled(true); + button.addClickEventListener(function () { + cc.log("clicked!"); + button.setScale(1.2); + }); + this.addChild(button); + + // Create the button + var button2 = new ccui.Button("res/cocosui/animationbuttonnormal.png", "res/cocosui/animationbuttonpressed.png"); + button2.ignoreContentAdaptWithSize(false); + button2.setContentSize(200,100); + button2.setNormalizedPosition(0.8, 0.5); + button2.setTitleText("PLAY GAME"); + button2.setZoomScale(0.3); + button2.setPressedActionEnabled(true); + button2.addClickEventListener(function () { + button2.runAction(cc.scaleTo(1.0, 1.2)); + cc.log("clicked!"); + }); + this.addChild(button2); + + return true; + } + return false; + } +}); + +var UIButtonTitleEffectTest = UIScene.extend({ + init: function(){ + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + + // Add a label in which the button events will be displayed + this._topDisplayLabel.setString("Button Title Effect"); + this._bottomDisplayLabel.setString(""); + + // Create the button + var button = new ccui.Button("res/cocosui/animationbuttonnormal.png", "res/cocosui/animationbuttonpressed.png"); + button.setNormalizedPosition(0.3, 0.5); + button.setTitleText("PLAY GAME"); + //button.setTitleFontName("fonts/Marker Felt.ttf"); + button.setZoomScale(0.3); + button.setScale(2.0); + button.setPressedActionEnabled(true); + var title = button.getTitleRenderer(); + button.setTitleColor(cc.color.RED); + title.enableShadow(cc.color.BLACK, cc.size(2,-2)); + this.addChild(button); + + // Create the button + var button2 = new ccui.Button("res/cocosui/animationbuttonnormal.png", "res/cocosui/animationbuttonpressed.png"); + button2.setNormalizedPosition(0.8, 0.5); + button2.setTitleText("PLAY GAME"); + var title2 = button2.getTitleRenderer(); + title2.enableStroke(cc.color.GREEN, 3); + this.addChild(button2); + return true; + } + return false; + } +}); + +var UIButtonFlipTest = UIScene.extend({ + init: function(){ + if (this._super()) { + + // Add a label in which the button events will be displayed + this._topDisplayLabel.setString(""); + this._bottomDisplayLabel.setString(""); + + // Create the button + var button = new ccui.Button("res/cocosui/animationbuttonnormal.png", "res/cocosui/animationbuttonpressed.png"); + button.setNormalizedPosition(0.3, 0.5); + button.setTitleText("PLAY GAME"); + //button.setTitleFontName("fonts/Marker Felt.ttf"); + button.setZoomScale(0.3); + button.setScale(2.0); + button.setFlippedX(true); + button.setPressedActionEnabled(true); + this.addChild(button); + + var titleLabel = new ccui.Text("Button X flipped", "Arial", 20); + titleLabel.setNormalizedPosition(0.3, 0.7); + this.addChild(titleLabel); + + // Create the button + var button2 = new ccui.Button("res/cocosui/animationbuttonnormal.png", "res/cocosui/animationbuttonpressed.png"); + button2.setNormalizedPosition(0.8, 0.5); + button2.setTitleText("PLAY GAME"); + button2.setFlippedY(true); + this.addChild(button2); + + titleLabel = new ccui.Text("Button Y flipped", "Arial", 20); + titleLabel.setNormalizedPosition(0.8, 0.7); + this.addChild(titleLabel); + return true; + } + return false; + } +}); + +var UIButtonNormalDefaultTest = UIScene.extend({ + init: function(){ + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + + // Add a label in which the button events will be displayed + this._topDisplayLabel.setString(""); + this._bottomDisplayLabel.setString(""); + + // Add the alert + var alert = new ccui.Text("Button should scale when clicked","Arial",20); + alert.setColor(cc.color(159, 168, 176)); + alert.setPosition(widgetSize.width / 2.0, + widgetSize.height / 2.0 - alert.height * 1.75); + this._mainNode.addChild(alert); + + // Create the button + var button = new ccui.Button("res/cocosui/animationbuttonnormal.png"); + button.setPosition(widgetSize.width / 2.0 - 80, widgetSize.height / 2.0 + 40); + button.setZoomScale(0.4); + button.setPressedActionEnabled(true); + this._mainNode.addChild(button); + + // Create the button + var buttonScale9 = new ccui.Button("res/cocosui/button.png"); + // open scale9 render + buttonScale9.setScale9Enabled(true); + buttonScale9.setPosition(widgetSize.width / 2.0 + 50, widgetSize.height / 2.0 + 40); + buttonScale9.setContentSize(150, 70); + buttonScale9.setPressedActionEnabled(true); + this._mainNode.addChild(buttonScale9); + return true; + } + return false; + } +}); + +var UIButtonDisableDefaultTest = UIScene.extend({ + init: function(){ + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + + this._topDisplayLabel.setString(""); + this._bottomDisplayLabel.setString(""); + + // Add the alert + var alert = new ccui.Text("Left button will turn normal when clicked","Arial",20); + alert.setColor(cc.color(159, 168, 176)); + alert.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert.height * 1.75); + this._mainNode.addChild(alert); + + // Create the button + var button = new ccui.Button("res/cocosui/animationbuttonnormal.png"); + button.setPosition(widgetSize.width / 2.0 - 80, widgetSize.height / 2.0 + 40); + button.setZoomScale(0.4); + button.setPressedActionEnabled(true); + button.setBright(false); + button.addClickEventListener(function () { + button.setBright(true); + }); + this._mainNode.addChild(button); + + // Create the button + var buttonScale9 = new ccui.Button("res/cocosui/button.png"); + // open scale9 render + buttonScale9.setScale9Enabled(true); + buttonScale9.setPosition(widgetSize.width / 2.0 + 50, widgetSize.height / 2.0 + 40); + buttonScale9.setContentSize(150, 70); + buttonScale9.setPressedActionEnabled(true); + buttonScale9.setEnabled(false); + buttonScale9.setBright(false); + this._mainNode.addChild(buttonScale9); + return true; + } + return false; + } }); \ No newline at end of file diff --git a/samples/js-tests/src/GUITest/UICheckBoxTest/UICheckBoxTest.js b/samples/js-tests/src/GUITest/UICheckBoxTest/UICheckBoxTest.js index 68c6156334..4ed941f959 100644 --- a/samples/js-tests/src/GUITest/UICheckBoxTest/UICheckBoxTest.js +++ b/samples/js-tests/src/GUITest/UICheckBoxTest/UICheckBoxTest.js @@ -63,3 +63,58 @@ var UICheckBoxTest = UIScene.extend({ } } }); + +//2015-01-14 +var UICheckBoxDefaultBehaviorTest = UIScene.extend({ + + init: function(){ + if(this._super()){ + var widgetSize = this._widget.getContentSize(); + + // Add a label in which the checkbox events will be displayed + this._displayValueLabel = new ccui.Text("No Event", "Marker Felt", 32); + this._displayValueLabel.setAnchorPoint(cc.p(0.5, -1)); + this._displayValueLabel.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2)); + this._mainNode.addChild(this._displayValueLabel); + this._bottomDisplayLabel.setString(""); + + // Add the alert + var alert = new ccui.Text("Only left two and the last checkbox can be cliked!","Marker Felt",20 ); + alert.setColor(cc.color(159, 168, 176)); + alert.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - alert.getContentSize().height * 1.75)); + this._mainNode.addChild(alert); + + // Create the checkbox + var checkBox = new ccui.CheckBox("res/cocosui/check_box_normal.png", "res/cocosui/check_box_active.png"); + checkBox.setPosition(cc.p(widgetSize.width / 2 - 50, widgetSize.height / 2)); + + this._mainNode.addChild(checkBox); + + + // Create the checkbox + var checkBox2 = new ccui.CheckBox("res/cocosui/check_box_normal.png", "res/cocosui/check_box_active.png"); + checkBox2.setPosition(cc.p(widgetSize.width / 2 - 150, widgetSize.height / 2)); + checkBox2.ignoreContentAdaptWithSize(false); + checkBox2.setZoomScale(0.5); + checkBox2.setContentSize(cc.size(80,80)); + checkBox2.setName("bigCheckBox"); + this._mainNode.addChild(checkBox2); + + + // Create the checkbox + var checkBoxDisabled = new ccui.CheckBox("res/cocosui/check_box_normal.png", "res/cocosui/check_box_active.png"); + checkBoxDisabled.setPosition(cc.p(widgetSize.width / 2 + 20, widgetSize.height / 2)); + checkBoxDisabled.setEnabled(false); + checkBoxDisabled.setBright(false); + this._mainNode.addChild(checkBoxDisabled); + + var checkBoxDisabled2 = new ccui.CheckBox("res/cocosui/check_box_normal.png", "res/cocosui/check_box_active.png"); + checkBoxDisabled2.setPosition(cc.p(widgetSize.width / 2 + 70, widgetSize.height / 2)); + checkBoxDisabled2.setBright(false); + checkBoxDisabled2.setSelected(true); + this._mainNode.addChild(checkBoxDisabled2); + return true; + } + } + +}); \ No newline at end of file diff --git a/samples/js-tests/src/GUITest/UIFocusTest/UIFocusTest.js b/samples/js-tests/src/GUITest/UIFocusTest/UIFocusTest.js new file mode 100644 index 0000000000..6facfd3db3 --- /dev/null +++ b/samples/js-tests/src/GUITest/UIFocusTest/UIFocusTest.js @@ -0,0 +1,554 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ + +var UIFocusTestBase = UIScene.extend({ + _dpadMenu: null, + _firstFocusedWidget: null, + _eventListener:null, + + init: function(){ + if (this._super()) { + var root = this._mainNode.getChildByTag(81); + var background = root.getChildByName("background_Panel"); + background.removeFromParent(true); + + this._dpadMenu = new cc.Menu(); + + cc.MenuItemFont.setFontSize(20); + var winSize = cc.director.getVisibleSize(); + var leftItem = new cc.MenuItemFont("Left", this.onLeftKeyPressed, this); + leftItem.setPosition(winSize.width - 100, winSize.height/2); + this._dpadMenu.addChild(leftItem); + + var rightItem = new cc.MenuItemFont("Right", this.onRightKeyPressed, this); + rightItem.setPosition(winSize.width - 30, winSize.height/2); + this._dpadMenu.addChild(rightItem); + + var upItem = new cc.MenuItemFont("Up", this.onUpKeyPressed, this); + upItem.setPosition(winSize.width - 60, winSize.height/2 + 50); + this._dpadMenu.addChild(upItem); + + var downItem = new cc.MenuItemFont("Down", this.onDownKeyPressed, this); + downItem.setPosition(winSize.width - 60, winSize.height/2 - 50); + this._dpadMenu.addChild(downItem); + + this._dpadMenu.setPosition(0, 0); + this.addChild(this._dpadMenu); + + //call this method to enable Dpad focus navigation + ccui.Widget.enableDpadNavigation(true); + + this._eventListener = cc.EventListener.create({ + event: cc.EventListener.FOCUS, //TODO Need add focus event in JSB + onFocusChanged: this.onFocusChanged.bind(this) + }); + cc.eventManager.addListener(this._eventListener, 1); + return true; + } + return false; + }, + + onLeftKeyPressed: function(){ + var event = new cc.EventKeyboard(cc.KEY.dpadLeft, false); + cc.eventManager.dispatchEvent(event); + }, + onRightKeyPressed: function(){ + var event = new cc.EventKeyboard(cc.KEY.dpadRight, false); + cc.eventManager.dispatchEvent(event); + }, + onUpKeyPressed: function(){ + var event = new cc.EventKeyboard(cc.KEY.dpadUp, false); + cc.eventManager.dispatchEvent(event); + }, + onDownKeyPressed: function(){ + var event = new cc.EventKeyboard(cc.KEY.dpadDown, false); + cc.eventManager.dispatchEvent(event); + }, + onFocusChanged: function(widgetLostFocus, widgetGetFocus){ + if (widgetGetFocus && widgetGetFocus.isFocusEnabled()) + widgetGetFocus.setColor(cc.color.RED); + + if (widgetLostFocus && widgetLostFocus.isFocusEnabled()) + widgetLostFocus.setColor(cc.color.WHITE); + + if (widgetLostFocus && widgetGetFocus) + cc.log("on focus change, %d widget get focus, %d widget lose focus", widgetGetFocus.getTag(), widgetLostFocus.getTag()); + }, + + onImageViewClicked: function(widget, touchType){ + if (touchType == ccui.Widget.TOUCH_ENDED) { + if (widget.isFocusEnabled()) { + widget.setFocusEnabled(false); + widget.setColor(cc.color.YELLOW); + }else{ + widget.setFocusEnabled(true); + widget.setColor(cc.color.WHITE); + } + } + } +}); + +var UIFocusTestHorizontal = UIFocusTestBase.extend({ + _horizontalLayout: null, + _loopText: null, + + init: function(){ + if (this._super()) { + var winSize = cc.director.getVisibleSize(); + + this._horizontalLayout = new ccui.HBox(); + this._horizontalLayout.setPosition(winSize.height/2 - 20, winSize.height/2 + 40); + this.addChild(this._horizontalLayout); + + this._horizontalLayout.setFocused(true); + this._horizontalLayout.setLoopFocus(true); + this._horizontalLayout.setTag(100); + this._firstFocusedWidget = this._horizontalLayout; + + var count = 3; + for (var i=0; i 0){ + pageView.removePageAtIndex(pageView.getPages().length-1); + }else{ + cc.log("There is no page to remove!"); + } + self._topDisplayLabel.setString("page count = " + pageView.getPages().length); + + }); + this._mainNode.addChild(button2); + + var button3 = new ccui.Button(); +// button3.setNormalizedPosition(cc.p(0.12,0.3)); + button3.setPosition(cc.p(20, 140)); + button3.setTitleText("Remove All Pages"); + button3.setZoomScale(0.3); + button3.setPressedActionEnabled(true); + button3.setTitleColor(cc.color.RED); + button3.addClickEventListener(function(sender){ + pageView.removeAllPages(); + self._topDisplayLabel.setString("page count = " + pageView.getPages().length); + }); + this._mainNode.addChild(button3); + + return true; + } + }, + + pageViewEvent: function(pageView, type){ + switch (type){ + case ccui.PageView.EVENT_TURNING: + this._topDisplayLabel.setString("page = " + (pageView.getCurPageIndex() + 1)); + break; + default: + break; + } + } +}); \ No newline at end of file diff --git a/samples/js-tests/src/GUITest/UIScene.js b/samples/js-tests/src/GUITest/UIScene.js index c18bfca0e0..1dc7f590df 100644 --- a/samples/js-tests/src/GUITest/UIScene.js +++ b/samples/js-tests/src/GUITest/UIScene.js @@ -30,7 +30,7 @@ UIScene = cc.Scene.extend({ _bottomDisplayLabel:null, _mainNode:null, ctor: function () { - cc.Scene.prototype.ctor.call(this) + cc.Scene.prototype.ctor.call(this); this._widget = null; }, init: function () { @@ -43,8 +43,14 @@ UIScene = cc.Scene.extend({ mainNode.attr({anchorX: 0, anchorY: 0, scale: scale, x: (winSize.width - 480 * scale) / 2, y: (winSize.height - 320 * scale) / 2}); this.addChild(mainNode); - //read widget - var widget = ccs.uiReader.widgetFromJsonFile("res/cocosui/UITest/UITest.json"); + var widget; + if(cocoStudioOldApiFlag == 0){ + var json = ccs.load("res/cocosui/UITest/UITest.json"); + widget = json.node; + }else{ + //old api + widget = ccs.uiReader.widgetFromJsonFile("res/cocosui/UITest/UITest.json"); + } mainNode.addChild(widget,-1); this._sceneTitle = widget.getChildByName("UItest"); @@ -101,11 +107,14 @@ UIScene = cc.Scene.extend({ toExtensionsMainLayer: function (sender, type) { if (type == ccui.Widget.TOUCH_ENDED) { UISceneManager.purge(); + /* var scene = new cc.Scene(); var layer = new TestController(); scene.addChild(layer); var transition = new cc.TransitionProgressRadialCCW(0.5,scene); director.runScene(transition); + */ + GUITestScene.prototype.runThisTest(); } }, diff --git a/samples/js-tests/src/GUITest/UISceneManager.js b/samples/js-tests/src/GUITest/UISceneManager.js index 0a943b45d3..61105998dc 100644 --- a/samples/js-tests/src/GUITest/UISceneManager.js +++ b/samples/js-tests/src/GUITest/UISceneManager.js @@ -23,290 +23,632 @@ THE SOFTWARE. ****************************************************************************/ -var s_testArray = [ - { - title: "UIButtonTest", - func: function () { - return new UIButtonTest(); - } - }, - { - title: "UIButtonTest_Scale9", - func: function () { - return new UIButtonTest_Scale9(); - } - }, - { - title: "UIButtonTest_PressedAction", - func: function () { - return new UIButtonTest_PressedAction(); - } - }, - { - title: "UIButtonTest_Title", - func: function () { - return new UIButtonTest_Title(); - } - }, - { - title: "UICheckBoxTest", - func: function () { - return new UICheckBoxTest(); - } - }, - { - title: "UISliderTest", - func: function () { - return new UISliderTest(); - } - }, - { - title: "UISliderTest_Scale9", - func: function () { - return new UISliderTest_Scale9(); - } - }, - { - title: "UIImageViewTest", - func: function () { - return new UIImageViewTest(); - } - }, - { - title: "UIImageViewTest_Scale9", - func: function () { - return new UIImageViewTest_Scale9(); - } - }, - { - title: "UILoadingBarTest_Left", - func: function () { - return new UILoadingBarTest_Left(); - } - }, - { - title: "UILoadingBarTest_Right", - func: function () { - return new UILoadingBarTest_Right(); - } - }, - { - title: "UILoadingBarTest_Fix", - func: function(){ - return new UILoadingBarTest_Fix(); - } - }, - { - title: "UILoadingBarTest_Left_Scale9", - func: function () { - return new UILoadingBarTest_Left_Scale9(); - } - }, - { - title: "UILoadingBarTest_Right_Scale9", - func: function () { - return new UILoadingBarTest_Right_Scale9(); - } - }, - { - title: "UILoadingBarTest_Fix_Scale9", - func: function(){ - return new UILoadingBarTest_Fix_Scale9(); - } - }, - { - title: "UILabelAtlasTest", - func: function () { - return new UILabelAtlasTest(); - } - }, - { - title: "UILabelTest", - func: function () { - return new UILabelTest(); - } - }, - { - title: "UILabelTest_LineWrap", - func: function () { - return new UILabelTest_LineWrap(); - } - }, - { - title: "UILabelBMFontTest", - func: function () { - return new UILabelBMFontTest(); - } - }, - { - title: "UITextFieldTest", - func: function () { - return new UITextFieldTest(); - } - }, - { - title: "UITextFieldTest_MaxLength", - func: function () { - return new UITextFieldTest_MaxLength(); - } - }, - { - title: "UITextFieldTest_Password", - func: function () { - return new UITextFieldTest_Password(); - } - }, - { - title: "UILayoutTest", - func: function () { - return new UILayoutTest(); - } - }, - { - title: "UILayoutTest_Color", - func: function () { - return new UILayoutTest_Color(); - } - }, - { - title: "UILayoutTest_Gradient", func: function () { - return new UILayoutTest_Gradient(); - } - }, - { - title: "UILayoutTest_BackGroundImage", - func: function () { - return new UILayoutTest_BackGroundImage(); - } - }, - { - title: "UILayoutTest_BackGroundImage_Scale9", - func: function () { - return new UILayoutTest_BackGroundImage_Scale9(); - } - }, - { - title: "UILayoutTest_Layout_Linear_Vertical", - func: function () { - return new UILayoutTest_Layout_Linear_Vertical(); - } - }, - { - title: "UILayoutTest_Layout_Linear_Horizontal", - func: function () { - return new UILayoutTest_Layout_Linear_Horizontal(); - } - }, - { - title: "UILayoutTest_Layout_Relative", - func: function () { - return new UILayoutTest_Layout_Relative(); - } - }, - { - title: "UIScrollViewTest_Vertical", - func: function () { - return new UIScrollViewTest_Vertical(); - } - }, - { - title: "UIScrollViewTest_Horizontal", - func: function () { - return new UIScrollViewTest_Horizontal(); - } - }, - { - title: "UIScrollViewTest_Both", - func: function () { - return new UIScrollViewTest_Both(); - } - }, - { - title: "UIScrollViewTest_ScrollToPercentBothDirection", - func: function () { - return new UIScrollViewTest_ScrollToPercentBothDirection(); - } - }, - { - title: "UIScrollViewTest_ScrollToPercentBothDirection_Bounce", - func: function () { - return new UIScrollViewTest_ScrollToPercentBothDirection_Bounce(); - } - }, - { - title: "UIPageViewTest", - func: function () { - return new UIPageViewTest(); - } - }, - { - title: "UIListViewTest_Vertical", - func: function () { - return new UIListViewTest_Vertical(); - } - }, - { - title: "UIListViewTest_Horizontal", - func: function () { - return new UIListViewTest_Horizontal(); - } - }, - { - title: "UIWidgetAddNodeTest", - func: function () { - return new UIWidgetAddNodeTest(); +(function(global){ + + var currentTestingArray = null; + + var testingItems = { + "UIButton": [ + { + title: "UIButtonTest", + func: function () { + return new UIButtonTest(); + } + }, + { + title: "UIButtonTest_Scale9", + func: function () { + return new UIButtonTest_Scale9(); + } + }, + { + title: "UIButtonTest_PressedAction", + func: function () { + return new UIButtonTest_PressedAction(); + } + }, + { + title: "UIButtonTest_Title", + func: function () { + return new UIButtonTest_Title(); + } + }, + { + title: "UIButtonTestRemoveSelf", + func: function () { + return new UIButtonTestRemoveSelf(); + } + }, + { + title: "UIButtonTestSwitchScale9", + func: function () { + return new UIButtonTestSwitchScale9(); + } + }, + { + title: "UIButtonTestZoomScale", + func: function () { + return new UIButtonTestZoomScale(); + } + }, + { + title: "UIButtonTextOnly", + func: function () { + return new UIButtonTextOnly(); + } + }, + { + title: "UIButtonIgnoreContentSizeTest", + func: function () { + return new UIButtonIgnoreContentSizeTest(); + } + }, + { + title: "UIButtonTitleEffectTest", + func: function () { + return new UIButtonTitleEffectTest(); + } + }, + { + title: "UIButtonFlipTest", + func: function () { + return new UIButtonFlipTest(); + } + }, + { + title: "UIButtonNormalDefaultTest", + func: function () { + return new UIButtonNormalDefaultTest(); + } + }, + { + title: "UIButtonDisableDefaultTest", + func: function () { + return new UIButtonDisableDefaultTest(); + } + } + ], + "UIFocus": [ + { + title: "UIFocusTestHorizontal", + func: function () { + return new UIFocusTestHorizontal(); + } + }, + { + title: "UIFocusTestVertical", + func: function () { + return new UIFocusTestVertical(); + } + }, + { + title: "UIFocusTestNestedLayout1", + func: function () { + return new UIFocusTestNestedLayout1(); + } + }, + { + title: "UIFocusTestNestedLayout2", + func: function () { + return new UIFocusTestNestedLayout2(); + } + }, + { + title: "UIFocusTestNestedLayout3", + func: function () { + return new UIFocusTestNestedLayout3(); + } + } + /*{ //need test + title: "UIFocusTestListView", + func: function () { + return new UIFocusTestListView(); + } + }*/ + ], + "UICheckBox": [ + { + title: "UICheckBoxTest", + func: function () { + return new UICheckBoxTest(); + } + }, + { + title: "UICheckBoxDefaultBehaviorTest", + func: function(){ + return new UICheckBoxDefaultBehaviorTest(); + } + } + ], + "UISlider": [ + { + title: "UISliderTest", + func: function () { + return new UISliderTest(); + } + }, + { + title: "UISliderTest_Scale9", + func: function () { + return new UISliderTest_Scale9(); + } + }, + { + title: "UISliderNormalDefaultTest", + func: function () { + return new UISliderNormalDefaultTest(); + } + }, + { + title: "UISliderDisabledDefaultTest", + func: function () { + return new UISliderDisabledDefaultTest(); + } + } + ], + "UIImageView": [ + { + title: "UIImageViewTest", + func: function () { + return new UIImageViewTest(); + } + }, + { + title: "UIImageViewTest_Scale9", + func: function () { + return new UIImageViewTest_Scale9(); + } + }, + { + title: "UIImageViewTest_ContentSize", + func: function () { + return new UIImageViewTest_ContentSize(); + } + }, + { + title: "UIImageViewFlipTest", + func: function () { + return new UIImageViewFlipTest(); + } + } + ], + "UILoadingBar": [ + { + title: "UILoadingBarTest_Left", + func: function () { + return new UILoadingBarTest_Left(); + } + }, + { + title: "UILoadingBarTest_Right", + func: function () { + return new UILoadingBarTest_Right(); + } + }, + { + title: "UILoadingBarTest_Fix", + func: function(){ + return new UILoadingBarTest_Fix(); + } + }, + { + title: "UILoadingBarTest_Left_Scale9", + func: function () { + return new UILoadingBarTest_Left_Scale9(); + } + }, + { + title: "UILoadingBarTest_Right_Scale9", + func: function () { + return new UILoadingBarTest_Right_Scale9(); + } + }, + { + title: "UILoadingBarTest_Fix_Scale9", + func: function(){ + return new UILoadingBarTest_Fix_Scale9(); + } + } + ], + "UIText": [ + { + title: "UITextTest", + func: function(){ + return new UITextTest(); + } + }, + { + title: "UITextTest_LineWrap", + func: function(){ + return new UITextTest_LineWrap(); + } + }, + { + title: "UILabelTest_Effect", + func: function(){ + return new UILabelTest_Effect(); + } + }, + { + title: "UITextTest_TTF", + func: function(){ + return new UITextTest_TTF(); + } + }, + { + title: "UITextTest_IgnoreConentSize", + func: function(){ + return new UITextTest_IgnoreConentSize(); + } + }, + { + title: "UILabelAtlasTest", + func: function () { + return new UILabelAtlasTest(); + } + }, + { + title: "UILabelTest", + func: function () { + return new UILabelTest(); + } + }, + { + title: "UILabelTest_LineWrap", + func: function () { + return new UILabelTest_LineWrap(); + } + }, + { + title: "UILabelBMFontTest", + func: function () { + return new UILabelBMFontTest(); + } + }, + { + title: "UILabelTest_TTF", + func: function () { + return new UILabelTest_TTF(); + } + } + ], + "UITextFiled": [ + { + title: "UITextFieldTest", + func: function () { + return new UITextFieldTest(); + } + }, + { + title: "UITextFieldTest_MaxLength", + func: function () { + return new UITextFieldTest_MaxLength(); + } + }, + { + title: "UITextFieldTest_Password", + func: function () { + return new UITextFieldTest_Password(); + } + }, + { + title: "UITextFieldTest_LineWrap", + func: function () { + return new UITextFieldTest_LineWrap(); + } + }, + { + title: "UITextFieldTest_TrueTypeFont", + func: function () { + return new UITextFieldTest_TrueTypeFont(); + } + }, + { + title: "UITextFieldTest_PlaceHolderColor", + func: function () { + return new UITextFieldTest_PlaceHolderColor(); + } + } + ], + "UILayout": [ + { + title: "UILayoutTest", + func: function () { + return new UILayoutTest(); + } + }, + { + title: "UILayoutTest_Color", + func: function () { + return new UILayoutTest_Color(); + } + }, + { + title: "UILayoutTest_Gradient", func: function () { + return new UILayoutTest_Gradient(); + } + }, + { + title: "UILayoutTest_BackGroundImage", + func: function () { + return new UILayoutTest_BackGroundImage(); + } + }, + { + title: "UILayoutTest_BackGroundImage_Scale9", + func: function () { + return new UILayoutTest_BackGroundImage_Scale9(); + } + }, + { + title: "UILayoutTest_Layout_Linear_Vertical", + func: function () { + return new UILayoutTest_Layout_Linear_Vertical(); + } + }, + { + title: "UILayoutTest_Layout_Linear_Horizontal", + func: function () { + return new UILayoutTest_Layout_Linear_Horizontal(); + } + }, + { + title: "UILayoutTest_Layout_Relative", + func: function () { + return new UILayoutTest_Layout_Relative(); + } + }, + { + title: "UILayoutTest_Layout_Relative_Align_Parent", + func: function () { + return new UILayoutTest_Layout_Relative_Align_Parent(); + } + }, + { + title: "UILayoutTest_Layout_Relative_Location", + func: function () { + return new UILayoutTest_Layout_Relative_Location(); + } + }, + { + title: "UILayoutComponent_Berth_Test", + func: function () { + return new UILayoutComponent_Berth_Test(); + } + }, + { + title: "UILayoutComponent_Berth_Stretch_Test", + func: function () { + return new UILayoutComponent_Berth_Stretch_Test(); + } + } + ], + "UIScrollView": [ + { + title: "UIScrollViewTest_Vertical", + func: function () { + return new UIScrollViewTest_Vertical(); + } + }, + { + title: "UIScrollViewTest_Horizontal", + func: function () { + return new UIScrollViewTest_Horizontal(); + } + }, + { + title: "UIScrollViewTest_Both", + func: function () { + return new UIScrollViewTest_Both(); + } + }, + { + title: "UIScrollViewTest_ScrollToPercentBothDirection", + func: function () { + return new UIScrollViewTest_ScrollToPercentBothDirection(); + } + }, + { + title: "UIScrollViewTest_ScrollToPercentBothDirection_Bounce", + func: function () { + return new UIScrollViewTest_ScrollToPercentBothDirection_Bounce(); + } + }, + { + title: "UIScrollViewNestTest", + func: function () { + return new UIScrollViewNestTest(); + } + }, + { + title: "UIScrollViewRotated", + func: function () { + return new UIScrollViewRotated(); + } + } + ], + "UIPageView": [ + { + title: "UIPageViewTest", + func: function () { + return new UIPageViewTest(); + } + }, + { + title: "UIPageViewButtonTest", + func: function () { + return new UIPageViewButtonTest(); + } + }, + { + title: "UIPageViewCustomScrollThreshold", + func: function () { + return new UIPageViewCustomScrollThreshold(); + } + }, + { + title: "UIPageViewTouchPropagationTest", + func: function () { + return new UIPageViewTouchPropagationTest(); + } + }, + { + title: "UIPageViewDynamicAddAndRemoveTest", + func: function () { + return new UIPageViewDynamicAddAndRemoveTest(); + } + } + ], + "UIListView": [ + { + title: "UIListViewTest_Vertical", + func: function () { + return new UIListViewTest_Vertical(); + } + }, + { + title: "UIListViewTest_Horizontal", + func: function () { + return new UIListViewTest_Horizontal(); + } + } + ], + "UIWidget": [ + { + title: "UIWidgetAddNodeTest", + func: function () { + return new UIWidgetAddNodeTest(); + } + } + ], + "UIRichText": [ + { + title: "UIRichTextTest", + func: function () { + return new UIRichTextTest(); + } + } + ] + }; + + global.GUITestScene = cc.Class.extend({ + + runThisTest: function(){ + cc.director.runScene(new listScene); } - }, - { - title: "UIRichTextTest", - func: function () { - return new UIRichTextTest(); + + }); + + var listScene = TestScene.extend({ + + onEnter: function(){ + TestScene.prototype.onEnter.call(this); + + var menu = new cc.Menu(); + menu.x = 0; + menu.y = 0; + var index = 0; + for(var p in testingItems){ + (function(name, list){ + var label = new cc.LabelTTF(name, "Arial", 24); + var menuItem = new cc.MenuItemLabel(label, function(){ + currentTestingArray = list; + var manager = global.UISceneManager.getInstance(); + var scene = manager.currentUIScene(); + cc.director.runScene(scene); + }, this); + menuItem.x = winSize.width / 2; + menuItem.y = (winSize.height - (index++ + 1) * 25); + index++; + menu.addChild(menuItem); + })(p, testingItems[p]); + } + + this._menu = menu; + this.addChild(menu); + + if ('touches' in cc.sys.capabilities) + cc.eventManager.addListener({ + event: cc.EventListener.TOUCH_ALL_AT_ONCE, + onTouchesMoved: function (touches, event) { + var target = event.getCurrentTarget(); + var delta = touches[0].getDelta(); + target.moveMenu(delta); + return true; + } + }, this); + else if ('mouse' in cc.sys.capabilities) { + cc.eventManager.addListener({ + event: cc.EventListener.MOUSE, + onMouseMove: function (event) { + if (event.getButton() == cc.EventMouse.BUTTON_LEFT) + event.getCurrentTarget().moveMenu(event.getDelta()); + }, + onMouseScroll: function (event) { + var delta = cc.sys.isNative ? event.getScrollY() * 6 : -event.getScrollY(); + event.getCurrentTarget().moveMenu({y: delta}); + return true; + } + }, this); + } + + this._length = 0; + for(var p in testingItems){ + this._length++; + } + }, + + moveMenu: function(delta){ + var newY = this._menu.y + delta.y; + if (newY < 0 ) + newY = 0; + + if( newY > ((this._length + 1) * 49 - winSize.height)) + newY = ((this._length + 1) * 49 - winSize.height); + + this._menu.y = newY; } - } -]; + }); -UISceneManager = cc.Class.extend({ - _currentUISceneId: 0, - ctor: function () { - this._currentUISceneId = 0; - }, - nextUIScene: function () { - this._currentUISceneId++; - if (this._currentUISceneId > s_testArray.length - 1) { + global.UISceneManager = { + + _currentUISceneId: 0, + + ctor: function () { this._currentUISceneId = 0; - } - return this.currentUIScene(); - }, - previousUIScene: function () { - this._currentUISceneId--; - if (this._currentUISceneId < 0) { - this._currentUISceneId = s_testArray.length - 1; - } - return this.currentUIScene(); - }, - currentUIScene: function () { - var test = s_testArray[this._currentUISceneId]; - var sence = test.func(); - sence.init(); - sence.setSceneTitle(test.title); - return sence; - } -}); -UISceneManager._instance = null; -UISceneManager.getInstance = function () { - if (!this._instance) { - this._instance = new UISceneManager(); - } - return this._instance; -}; -UISceneManager.purge = function () { - this._instance = null; -}; + }, + + nextUIScene: function () { + this._currentUISceneId++; + if (this._currentUISceneId > currentTestingArray.length - 1) { + this._currentUISceneId = 0; + } + return this.currentUIScene(); + }, + + previousUIScene: function () { + this._currentUISceneId--; + if (this._currentUISceneId < 0) { + this._currentUISceneId = currentTestingArray.length - 1; + } + return this.currentUIScene(); + }, + + currentUIScene: function () { + var test = currentTestingArray[this._currentUISceneId]; + var sence = test.func(); + sence.init(); + sence.setSceneTitle(test.title); + return sence; + } + }; + + global.UISceneManager.getInstance = function () { + return this; + }; + + global.UISceneManager.purge = function (){ + this._currentUISceneId = 0; + }; -GUITestScene = cc.Class.extend({ - runThisTest:function () { - var manager = UISceneManager.getInstance(); - var scene = manager.currentUIScene(); - cc.director.runScene(scene); - } -}); +})(window); \ No newline at end of file diff --git a/samples/js-tests/src/GUITest/UIScrollViewTest/UIScrollViewTest.js b/samples/js-tests/src/GUITest/UIScrollViewTest/UIScrollViewTest.js index b79ba90375..0db6aa93fe 100644 --- a/samples/js-tests/src/GUITest/UIScrollViewTest/UIScrollViewTest.js +++ b/samples/js-tests/src/GUITest/UIScrollViewTest/UIScrollViewTest.js @@ -281,3 +281,135 @@ var UIScrollViewTest_ScrollToPercentBothDirection_Bounce = UIScene.extend({ return false; } }); + +//2015-01-14 +var UIScrollViewNestTest = UIScene.extend({ + init: function(){ + if(this._super()){ + var widgetSize = this._widget.getContentSize(); + + // Add a label in which the scrollview alert will be displayed + this._topDisplayLabel.setString("Move by vertical direction"); + + // Add the alert + this._bottomDisplayLabel.setString("ScrollView vertical"); + this._bottomDisplayLabel.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0 - this._bottomDisplayLabel.height * 3.075); + + var root = this._mainNode.getChildByTag(81); + + var background = root.getChildByName("background_Panel"); + + // Create the scrollview by vertical + var scrollView = new ccui.ScrollView(); + scrollView.setContentSize(cc.size(280.0, 150.0)); + scrollView.setDirection(ccui.ScrollView.DIR_BOTH); + var backgroundSize = background.getContentSize(); + scrollView.setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2.0 + + (backgroundSize.width - scrollView.getContentSize().width) / 2.0, + (widgetSize.height - backgroundSize.height) / 2.0 + + (backgroundSize.height - scrollView.getContentSize().height) / 2.0)); + this._mainNode.addChild(scrollView); + + var imageView = new ccui.ImageView("res/cocosui/ccicon.png"); + + var innerWidth = scrollView.getContentSize().width; + var innerHeight = scrollView.getContentSize().height + imageView.getContentSize().height; + + scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight)); + + var button = new ccui.Button("res/cocosui/animationbuttonnormal.png", "res/cocosui/animationbuttonpressed.png"); + button.setPosition(cc.p(innerWidth / 2.0, scrollView.getInnerContainerSize().height - button.getContentSize().height / 2.0)); + scrollView.addChild(button); + + var titleButton = new ccui.Button("res/cocosui/backtotopnormal.png", "res/cocosui/backtotoppressed.png"); + titleButton.setTitleText("Title Button"); + titleButton.setPosition(cc.p(innerWidth / 2.0, button.getBottomBoundary() - button.getContentSize().height)); + scrollView.addChild(titleButton); + + var button_scale9 = new ccui.Button("res/cocosui/button.png", "res/cocosui/buttonHighlighted.png"); + button_scale9.setScale9Enabled(true); + button_scale9.setContentSize(cc.size(100.0, button_scale9.getVirtualRendererSize().height)); + button_scale9.setPosition(cc.p(innerWidth / 2.0, titleButton.getBottomBoundary() - titleButton.getContentSize().height)); + scrollView.addChild(button_scale9); + + imageView.setPosition(cc.p(innerWidth / 2.0, imageView.getContentSize().height / 2.0)); + scrollView.addChild(imageView); + + // Create the scrollview by horizontal + var sc = new ccui.ScrollView(); + sc.setBackGroundColor(cc.color.GREEN); + sc.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID); + sc.setBounceEnabled(true); + sc.setDirection(ccui.ScrollView.DIR_BOTH); + sc.setInnerContainerSize(cc.size(480, 320)); + sc.setContentSize(cc.size(100,100)); + sc.setPropagateTouchEvents(false); + sc.setPosition(cc.p(180,100)); + sc.scrollToPercentBothDirection(cc.p(50, 50), 1, true); + var iv = new ccui.ImageView("res/cocosui/Hello.png"); + iv.setPosition(cc.p(240, 160)); + sc.addChild(iv); + scrollView.addChild(sc); + + return true; + } + } + +}); + +//2015-01-14 +var UIScrollViewRotated = UIScene.extend({ + init: function(){ + if(this._super()){ + var widgetSize = this._widget.getContentSize(); + + // Add a label in which the scrollview alert will be displayed + this._topDisplayLabel.setString("Move by vertical direction"); + + // Add the alert + this._bottomDisplayLabel.setString("ScrollView vertical"); + this._bottomDisplayLabel.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0 - this._bottomDisplayLabel.height * 3.075); + + var root = this._mainNode.getChildByTag(81); + var background = root.getChildByName("background_Panel"); + + // Create the scrollview by vertical + var scrollView = new ccui.ScrollView(); + scrollView.setContentSize(cc.size(280.0, 150.0)); + scrollView.setDirection(ccui.ScrollView.DIR_BOTH); + var backgroundSize = background.getContentSize(); + scrollView.setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2.0 + + (backgroundSize.width - scrollView.getContentSize().width) / 2.0, + (widgetSize.height - backgroundSize.height) / 2.0 + + (backgroundSize.height - scrollView.getContentSize().height) / 2.0 + 100) ); + scrollView.setRotation(45); + this._mainNode.addChild(scrollView); + + var imageView = new ccui.ImageView("res/cocosui/ccicon.png"); + + var innerWidth = scrollView.getContentSize().width; + var innerHeight = scrollView.getContentSize().height + imageView.getContentSize().height; + scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight)); + + var button = new ccui.Button("res/cocosui/animationbuttonnormal.png", "res/cocosui/animationbuttonpressed.png"); + button.setPosition(cc.p(innerWidth / 2.0, scrollView.getInnerContainerSize().height - button.getContentSize().height / 2.0)); + scrollView.addChild(button); + + var titleButton = new ccui.Button("res/cocosui/backtotopnormal.png", "res/cocosui/backtotoppressed.png"); + titleButton.setTitleText("Title Button"); + titleButton.setPosition(cc.p(innerWidth / 2.0, button.getBottomBoundary() - button.getContentSize().height)); + scrollView.addChild(titleButton); + + var button_scale9 = new ccui.Button("res/cocosui/button.png", "res/cocosui/buttonHighlighted.png"); + button_scale9.setScale9Enabled(true); + button_scale9.setContentSize(cc.size(100.0, button_scale9.getVirtualRendererSize().height)); + button_scale9.setPosition(cc.p(innerWidth / 2.0, titleButton.getBottomBoundary() - titleButton.getContentSize().height)); + scrollView.addChild(button_scale9); + + imageView.setPosition(cc.p(innerWidth / 2.0, imageView.getContentSize().height / 2.0)); + scrollView.addChild(imageView); + + return true; + } + } +}); \ No newline at end of file diff --git a/samples/js-tests/src/GUITest/UISliderTest/UISliderTest.js b/samples/js-tests/src/GUITest/UISliderTest/UISliderTest.js index 6a6951f411..551c4c9911 100644 --- a/samples/js-tests/src/GUITest/UISliderTest/UISliderTest.js +++ b/samples/js-tests/src/GUITest/UISliderTest/UISliderTest.js @@ -98,4 +98,78 @@ var UISliderTest_Scale9 = UIScene.extend({ break; } } +}); + +//2015-01-14 +var UISliderNormalDefaultTest = UIScene.extend({ + init: function () { + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + + this._bottomDisplayLabel.setString(""); + + // Add the alert + var alert = new ccui.Text("when pressed, the slider ball should scale","Marker Felt",20); + alert.setColor(cc.color(159, 168, 176)); + alert.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - alert.height * 3.75)); + this._mainNode.addChild(alert); + + // Create the slider + var slider = new ccui.Slider(); + slider.loadBarTexture("res/cocosui/sliderTrack.png"); + slider.loadSlidBallTextures("res/cocosui/sliderThumb.png"); + slider.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + 50)); + this._mainNode.addChild(slider); + + var sliderScale9 = new ccui.Slider("res/cocosui/sliderTrack2.png", "res/cocosui/sliderThumb.png"); + sliderScale9.setScale9Enabled(true); + sliderScale9.setCapInsets(cc.rect(0, 0, 0, 0)); + sliderScale9.setZoomScale(1); + sliderScale9.setContentSize(cc.size(250, 19)); + sliderScale9.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - 20)); + this._mainNode.addChild(sliderScale9); + + + return true; + } + return false; + } +}); + +//2015-01-14 +var UISliderDisabledDefaultTest = UIScene.extend({ + init: function () { + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + + this._bottomDisplayLabel.setString(""); + + // Add the alert + var alert = new ccui.Text("slider ball should be gray.","Marker Felt",20); + alert.setColor(cc.color(159, 168, 176)); + alert.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - alert.height * 3.75)); + this._mainNode.addChild(alert); + + // Create the slider + var slider = new ccui.Slider(); + slider.loadBarTexture("res/cocosui/slidbar.png"); + slider.loadSlidBallTextureNormal("res/cocosui/sliderballnormal.png"); + slider.setEnabled(false); + slider.setBright(false); + slider.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + 50)); + this._mainNode.addChild(slider); + + var sliderScale9 = new ccui.Slider("res/cocosui/slidbar.png", "res/cocosui/sliderballnormal.png"); + sliderScale9.setScale9Enabled(true); + sliderScale9.setEnabled(false); + sliderScale9.setBright(false); + sliderScale9.setCapInsets(cc.rect(0, 0, 0, 0)); + sliderScale9.setContentSize(cc.size(250, 10)); + sliderScale9.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - 20)); + this._mainNode.addChild(sliderScale9); + + return true; + } + return false; + } }); \ No newline at end of file diff --git a/samples/js-tests/src/GUITest/UITextFieldTest/UITextFieldTest.js b/samples/js-tests/src/GUITest/UITextFieldTest/UITextFieldTest.js index 29434295be..bffd3c4adb 100644 --- a/samples/js-tests/src/GUITest/UITextFieldTest/UITextFieldTest.js +++ b/samples/js-tests/src/GUITest/UITextFieldTest/UITextFieldTest.js @@ -32,10 +32,7 @@ var UITextFieldTest = UIScene.extend({ this._bottomDisplayLabel.setString("TextField"); // Create the textfield - var textField = new ccui.TextField(); - textField.setTouchEnabled(true); - textField.fontName = "Marker Felt"; - textField.fontSize = 30; + var textField = new ccui.TextField("PlaceHolder", "Marker Felt", 30); textField.x = widgetSize.width / 2.0; textField.y = widgetSize.height / 2.0; textField.addEventListener(this.textFieldEvent, this); @@ -46,17 +43,15 @@ var UITextFieldTest = UIScene.extend({ return false; }, - textFieldEvent: function (sender, type) { + textFieldEvent: function (textField, type) { switch (type) { case ccui.TextField.EVENT_ATTACH_WITH_IME: - var textField = sender; var widgetSize = this._widget.getContentSize(); textField.runAction(cc.moveTo(0.225, cc.p(widgetSize.width / 2, widgetSize.height / 2 + textField.height / 2))); this._topDisplayLabel.setString("attach with IME"); break; case ccui.TextField.EVENT_DETACH_WITH_IME: - var textField = sender; var widgetSize = this._widget.getContentSize(); textField.runAction(cc.moveTo(0.175, cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0))); this._topDisplayLabel.setString("detach with IME"); @@ -150,18 +145,15 @@ var UITextFieldTest_Password = UIScene.extend({ return false; }, - textFieldEvent: function (sender, type) { + textFieldEvent: function (textField, type) { + var widgetSize = this._widget.getContentSize(); switch (type) { case ccui.TextField.EVENT_ATTACH_WITH_IME: - var textField = sender; - var widgetSize = this._widget.getContentSize(); textField.runAction(cc.moveTo(0.225, cc.p(widgetSize.width / 2, widgetSize.height / 2 + textField.height / 2))); this._topDisplayLabel.setString("attach with IME IME password"); break; case ccui.TextField.EVENT_DETACH_WITH_IME: - var textField = sender; - var widgetSize = this._widget.getContentSize(); textField.runAction(cc.moveTo(0.175, cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0))); this._topDisplayLabel.setString("detach with IME password"); break; @@ -175,4 +167,163 @@ var UITextFieldTest_Password = UIScene.extend({ break; } } +}); + +//2015-01-14 +var UITextFieldTest_LineWrap = UIScene.extend({ + + init: function(){ + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + + // Add a label in which the textfield events will be displayed + this._topDisplayLabel.setString("No Event"); + this._topDisplayLabel.setPosition(widgetSize.width / 2, widgetSize.height / 2 + this._topDisplayLabel.height * 1.5); + this._bottomDisplayLabel.setString(""); + + // Add the alert + var alert = new ccui.Text("TextField line wrap","Marker Felt",30); + alert.setColor(cc.color(159, 168, 176)); + alert.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - alert.height * 3.075)); + this._mainNode.addChild(alert); + + // Create the textfield + var textField = new ccui.TextField("input words here", "Marker Felt",30); + textField.ignoreContentAdaptWithSize(false); + //textField.getVirtualRenderer().setLineBreakWithoutSpace(true); + textField.setContentSize(240, 120); + textField.setString("input words here"); + textField.setTextHorizontalAlignment(cc.TEXT_ALIGNMENT_CENTER); + textField.setTextVerticalAlignment(cc.TEXT_ALIGNMENT_CENTER); + textField.setPosition(widgetSize.width / 2, widgetSize.height / 2); + textField.addEventListener(this.textFieldEvent, this); + this._mainNode.addChild(textField); + return true; + } + }, + + textFieldEvent: function(textField, type){ + var widgetSize = this._widget.getContentSize(); + switch (type){ + case ccui.TextField.EVENT_ATTACH_WITH_IME: + textField.runAction(cc.moveTo(0.225, cc.p(widgetSize.width / 2, widgetSize.height / 2 + 30))); + textField.setTextHorizontalAlignment(cc.TEXT_ALIGNMENT_LEFT); + textField.setTextVerticalAlignment(cc.VERTICAL_TEXT_ALIGNMENT_TOP); + this._topDisplayLabel.setString("attach with IME"); + break; + case ccui.TextField.EVENT_DETACH_WITH_IME: + textField.runAction(cc.moveTo(0.175, cc.p(widgetSize.width / 2, widgetSize.height / 2))); + textField.setTextHorizontalAlignment(cc.TEXT_ALIGNMENT_CENTER); + textField.setTextVerticalAlignment(cc.TEXT_ALIGNMENT_CENTER); + this._topDisplayLabel.setString("detach with IME"); + break; + case ccui.TextField.EVENT_INSERT_TEXT: + this._topDisplayLabel.setString("insert words"); + break; + case ccui.TextField.EVENT_DELETE_BACKWARD: + this._topDisplayLabel.setString("delete word"); + break; + default: + break; + } + } +}); + +//2015-01-14 +var UITextFieldTest_TrueTypeFont = UIScene.extend({ + init: function(){ + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + + // Add a label in which the textfield events will be displayed + this._topDisplayLabel.setString("True Type Font Test - No Event"); + this._topDisplayLabel.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + this._topDisplayLabel.height * 1.5)); + + // Add the alert + this._bottomDisplayLabel.setString("TextField"); + this._bottomDisplayLabel.setPosition(widgetSize.width / 2, widgetSize.height / 2 - this._bottomDisplayLabel.height * 3.075); + + // Create the textfield + var textField = new ccui.TextField("input words here","Marker Felt",30); + textField.setPosition(widgetSize.width / 2, widgetSize.height / 2); + textField.addEventListener(this.textFieldEvent, this); + this._mainNode.addChild(textField); + return true; + } + }, + + textFieldEvent: function(textField, type){ + var widgetSize = this._widget.getContentSize(); + switch (type){ + case ccui.TextField.EVENT_ATTACH_WITH_IME: + textField.runAction(cc.moveTo(0.225, cc.p(widgetSize.width / 2, widgetSize.height / 2 + textField.height / 2))); + this._topDisplayLabel.setString("attach with IME"); + break; + + case ccui.TextField.EVENT_DETACH_WITH_IME: + textField.runAction(cc.moveTo(0.175, cc.p(widgetSize.width / 2, widgetSize.height / 2))); + this._topDisplayLabel.setString("detach with IME"); + break; + + case ccui.TextField.EVENT_INSERT_TEXT: + this._topDisplayLabel.setString("insert words"); + break; + + case ccui.TextField.EVENT_DELETE_BACKWARD: + this._topDisplayLabel.setString("delete word"); + break; + + default: + break; + } + } +}); + +//2015-01-14 +var UITextFieldTest_PlaceHolderColor = UIScene.extend({ + init: function(){ + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + + // Add a label in which the textfield events will be displayed + this._topDisplayLabel.setString("Set place hold color"); + this._topDisplayLabel.setPosition(widgetSize.width / 2, widgetSize.height / 2 + this._topDisplayLabel.height * 1.5); + + // Add the alert + this._bottomDisplayLabel.setString("TextField"); + this._bottomDisplayLabel.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - this._bottomDisplayLabel.height * 3.075)); + + // Create the textfield + var textField = new ccui.TextField("input words here","Arial",30); + textField.setPlaceHolder("input text here"); + textField.setPlaceHolderColor(cc.color.GREEN); + textField.setTextColor(cc.color.RED); + textField.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2)); + textField.addEventListener(this.textFieldEvent, this); + this._mainNode.addChild(textField); + return true; + } + }, + + textFieldEvent: function(textField, type){ + var widgetSize = this._widget.getContentSize(); + switch (type){ + case ccui.TextField.EVENT_ATTACH_WITH_IME: + textField.runAction(cc.moveTo(0.225, cc.p(widgetSize.width / 2, widgetSize.height / 2 + textField.height / 2))); + this._topDisplayLabel.setString("attach with IME"); + break; + case ccui.TextField.EVENT_DETACH_WITH_IME: + textField.runAction(cc.moveTo(0.175, cc.p(widgetSize.width / 2, widgetSize.height / 2))); + this._topDisplayLabel.setString("detach with IME"); + break; + case ccui.TextField.EVENT_INSERT_TEXT: + this._topDisplayLabel.setString("insert words"); + break; + case ccui.TextField.EVENT_DELETE_BACKWARD: + this._topDisplayLabel.setString("delete word"); + break; + default: + break; + } + } }); \ No newline at end of file diff --git a/samples/js-tests/src/GUITest/UITextTest/UITextTest.js b/samples/js-tests/src/GUITest/UITextTest/UITextTest.js new file mode 100644 index 0000000000..e6c5f84ec6 --- /dev/null +++ b/samples/js-tests/src/GUITest/UITextTest/UITextTest.js @@ -0,0 +1,182 @@ +/**************************************************************************** + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ + +//2015-01-14 +var UITextTest = UIScene.extend({ + init: function(){ + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + + this._bottomDisplayLabel.setString("Text"); + + // Create the text + var text = new ccui.Text("Text", "AmericanTypewriter", 30); + text.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + text.height / 4)); + this._mainNode.addChild(text); + + return true; + } + } +}); + +//2015-01-14 +var UITextTest_LineWrap = UIScene.extend({ + init: function(){ + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + + this._bottomDisplayLabel.setString("Text line wrap"); + + // Create the line wrap + var text = new ccui.Text("TextArea Widget can line wrap","AmericanTypewriter",32); + text.ignoreContentAdaptWithSize(false); + text.setContentSize(cc.size(280, 150)); + text.setTextHorizontalAlignment(cc.TEXT_ALIGNMENT_CENTER); + text.setTouchScaleChangeEnabled(true); + text.setTouchEnabled(true); + text.addTouchEventListener(function(sender, type){ + if (type == ccui.Widget.TOUCH_ENDED){ + if (text.width == 280){ + text.setContentSize(cc.size(380,100)); + }else { + text.setContentSize(cc.size(280, 150)); + } + } + }); + text.setPosition(widgetSize.width / 2, widgetSize.height / 2 - text.height / 8); + this._mainNode.addChild(text); + + return true; + } + } +}); + +//2015-01-14 +var UILabelTest_Effect = UIScene.extend({ + init: function(){ + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + + this._bottomDisplayLabel.setString(""); + + var alert = new ccui.Text(); + alert.setString("Label Effect"); + alert.setFontName("Marker Felt"); + alert.setFontSize(30); + alert.setColor(cc.color(159, 168, 176)); + alert.setPosition(widgetSize.width / 2, widgetSize.height / 2 - alert.height * 3.05); + this._mainNode.addChild(alert); + + // create the shadow only label + var shadow_label = new ccui.Text(); + + shadow_label.enableShadow(cc.color.GRAY, cc.p(10, -10)); + shadow_label.setString("Shadow"); + shadow_label.setPosition(widgetSize.width / 2, widgetSize.height / 2 + shadow_label.height); + + this._mainNode.addChild(shadow_label); + + // create the stroke only label + var glow_label = new ccui.Text(); + glow_label.setFontName("Marker Felt"); + glow_label.setString("Glow"); + glow_label.enableGlow(cc.color.RED); + glow_label.setPosition(widgetSize.width / 2, widgetSize.height / 2); + this._mainNode.addChild(glow_label); + + // create the label stroke and shadow + var outline_label = new ccui.Text(); + outline_label.enableOutline(cc.color.BLUE, 2); + outline_label.setString("Outline"); + outline_label.setPosition(widgetSize.width / 2, widgetSize.height / 2 - shadow_label.height); + + this._mainNode.addChild(outline_label); + + return true; + } + } +}); + +//2015-01-14 +var UITextTest_TTF = UIScene.extend({ + init: function(){ + if(this._super()){ + var widgetSize = this._widget.getContentSize(); + + this._bottomDisplayLabel.setString("Text set TTF font"); + + // Create the text, and set font with .ttf + var text = new ccui.Text("Text","A Damn Mess",30); + text.setPosition(widgetSize.width / 2, widgetSize.height / 2 + text.height / 4); + this._mainNode.addChild(text); + + return true; + } + } +}); + +//2015-01-14 +var UITextTest_IgnoreConentSize = UIScene.extend({ + + init: function(){ + if(this._super()){ + var widgetSize = this._widget.getContentSize(); + + this._bottomDisplayLabel.setString(""); + + var leftText = new ccui.Text("ignore conent", "Marker Felt",10); + leftText.setPosition(cc.p(widgetSize.width / 2 - 50, + widgetSize.height / 2)); + leftText.ignoreContentAdaptWithSize(false); + leftText.setTextAreaSize(cc.size(60,60)); + leftText.setString("Text line with break\nText line with break\nText line with break\nText line with break\n"); + leftText.setTouchScaleChangeEnabled(true); + leftText.setTouchEnabled(true); + this._mainNode.addChild(leftText); + + var rightText = new ccui.Text("ignore conent", "Marker Felt",10); + rightText.setPosition(cc.p(widgetSize.width / 2 + 50, + widgetSize.height / 2)); + rightText.setString("Text line with break\nText line with break\nText line with break\nText line with break\n"); + //note: setTextAreaSize must be used with ignoreContentAdaptWithSize(false) + rightText.setTextAreaSize(cc.size(100,30)); + rightText.ignoreContentAdaptWithSize(false); + this._mainNode.addChild(rightText); + + var halighButton = new ccui.Button(); + halighButton.setTitleText("Alignment Right"); + halighButton.addClickEventListener(function(){ + leftText.setTextHorizontalAlignment(cc.TEXT_ALIGNMENT_RIGHT); + rightText.setTextHorizontalAlignment(cc.TEXT_ALIGNMENT_RIGHT); + }); + halighButton.setPosition(cc.p(widgetSize.width/2 - 50, + widgetSize.height/2 - 50)); + this._mainNode.addChild(halighButton); + + return true; + } + } + +}); \ No newline at end of file diff --git a/samples/js-tests/src/LabelTest/LabelTest.js b/samples/js-tests/src/LabelTest/LabelTest.js index 90b567c797..d873cdc368 100644 --- a/samples/js-tests/src/LabelTest/LabelTest.js +++ b/samples/js-tests/src/LabelTest/LabelTest.js @@ -1287,6 +1287,7 @@ var LabelTTFMultiline = AtlasDemo.extend({ // cc.LabelBMFont var center = new cc.LabelTTF("word wrap \"testing\" (bla0) bla1 'bla2' [bla3] (bla4) {bla5} {bla6} [bla7] (bla8) [bla9] 'bla0' \"bla1\"", "Arial", 32, cc.size(s.width / 2, 200), cc.TEXT_ALIGNMENT_CENTER, cc.VERTICAL_TEXT_ALIGNMENT_TOP); + center.setDimensions(s.width / 2, 200); center.x = s.width / 2; center.y = 150; @@ -1330,13 +1331,14 @@ var LabelTTFChinese = AtlasDemo.extend({ //----start21----ctor this._super(); var size = director.getWinSize(); - var label = new cc.LabelTTF("中国", "Microsoft Yahei", 30); + var fontname = (cc.sys.os === cc.sys.OS_WP8 ) ? "fonts/arialuni.ttf" : (cc.sys.os == cc.sys.OS_WINRT) ? "DengXian" : "Microsoft Yahei"; + var label = new cc.LabelTTF("中国", fontname, 30); label.x = size.width / 2; label.y = size.height / 3 * 2; this.addChild(label); // Test UTF8 string from native to jsval. - var label2 = new cc.LabelTTF("string from native:"+label.getString(), "Microsoft Yahei", 30); + var label2 = new cc.LabelTTF("string from native:"+label.getString(), fontname, 30); label2.x = size.width / 2; label2.y = size.height / 3; this.addChild(label2); @@ -1388,6 +1390,9 @@ var BMFontChineseTest = AtlasDemo.extend({ }); var LongSentencesExample = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; +var chineseExampleText = "美好的一天美好的一天美好的一天美好的一天美好的一天美好的一天美好的一天美好的一天美好的一天美好的一天美好的一天"; +var chineseMixEnglishText = "美好的一天bdgpy美b好b的d一b天d美好bd的p一g天美好b的d一d天bdgpybdgpybdgpybdg美好的一天bdgpy美好的一天美好的一天"; +var mixAllLanguageText = "美好良い一日を一Buen díabdgpy美b好b的d一b天d美Buen い一日を好b的d一d天Buen py美好的一天bdgpy美好的一天美好的一天"; var LineBreaksExample = "Lorem ipsum dolor\nsit amet\nconsectetur adipisicing elit\nblah\nblah"; var MixedExample = "ABC\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt\nDEF"; @@ -1401,9 +1406,12 @@ var RightAlign = 2; var LongSentences = 0; var LineBreaks = 1; var Mixed = 2; +var chineseText = 3; +var chineseMixEnglish = 4; +var mixAllLanguage = 5; -var alignmentItemPadding = 50; -var menuItemPaddingCenter = 50; +var alignmentItemPadding = 40; +var menuItemPaddingCenter = 80; var BMFontMultiLineAlignmentTest = AtlasDemo.extend({ labelShouldRetain:null, @@ -1411,6 +1419,7 @@ var BMFontMultiLineAlignmentTest = AtlasDemo.extend({ arrowsShouldRetain:null, lastSentenceItem:null, lastAlignmentItem:null, + lineBreakFlag:false, ctor:function () { //----start11----ctor this._super(); @@ -1448,14 +1457,28 @@ var BMFontMultiLineAlignmentTest = AtlasDemo.extend({ var longSentences = new cc.MenuItemFont("Long Flowing Sentences", this.onStringChanged, this); var lineBreaks = new cc.MenuItemFont("Short Sentences With Intentional Line Breaks", this.onStringChanged, this); var mixed = new cc.MenuItemFont("Long Sentences Mixed With Intentional Line Breaks", this.onStringChanged.bind(this)); // another way to pass 'this' - var stringMenu = new cc.Menu(longSentences, lineBreaks, mixed); + var changeChineseItem = new cc.MenuItemFont("change chinese", this.onStringChanged, this); + var mixEnglishItem = new cc.MenuItemFont("change chinesemixEnglish", this.onStringChanged, this); + var mixAllLanItem = new cc.MenuItemFont("change mixAllLan", this.onStringChanged, this); + + var stringMenu = new cc.Menu(longSentences, lineBreaks, mixed, changeChineseItem,mixEnglishItem, mixAllLanItem); stringMenu.alignItemsVertically(); + var setLineBreakItem = new cc.MenuItemFont("setLineBreakWithoutSpace", this.onLineBreakChanged, this); + var setScale = new cc.MenuItemFont("setScale", this.onScaleChange, this); + var lineBreakMenu = new cc.Menu(setLineBreakItem, setScale); + lineBreakMenu.x = 100; + lineBreakMenu.y = winSize.height / 2; + lineBreakMenu.alignItemsVertically(); + longSentences.color = cc.color(255, 0, 0); this.lastSentenceItem = longSentences; longSentences.tag = LongSentences; lineBreaks.tag = LineBreaks; mixed.tag = Mixed; + changeChineseItem.tag = chineseText; + mixEnglishItem.tag = chineseMixEnglish; + mixAllLanItem.tag = mixAllLanguage; cc.MenuItemFont.setFontSize(30); @@ -1497,6 +1520,9 @@ var BMFontMultiLineAlignmentTest = AtlasDemo.extend({ this.addChild(this.arrowsShouldRetain); this.addChild(stringMenu); this.addChild(alignmentMenu); + this.addChild(lineBreakMenu); + + //----end11---- }, __title: function(){ @@ -1508,6 +1534,22 @@ var BMFontMultiLineAlignmentTest = AtlasDemo.extend({ subtitle:function () { return ""; }, + + onScaleChange:function(sener){ + if (this.labelShouldRetain.getScale() > 1) + { + this.labelShouldRetain.setScale(1.0); + } + else + { + this.labelShouldRetain.setScale(2.0); + } + + }, + onLineBreakChanged:function(sender){ + this.lineBreakFlag = !this.lineBreakFlag; + this.labelShouldRetain.setLineBreakWithoutSpace(this.lineBreakFlag); + }, onStringChanged:function (sender) { this.lastSentenceItem.color = cc.color(255, 255, 255); sender.color = cc.color(255, 0, 0); @@ -1516,14 +1558,28 @@ var BMFontMultiLineAlignmentTest = AtlasDemo.extend({ switch (sender.tag) { case LongSentences: this.labelShouldRetain.setString(LongSentencesExample); + this.labelShouldRetain.setFntFile(s_resprefix + "fonts/markerFelt.fnt"); break; case LineBreaks: this.labelShouldRetain.setString(LineBreaksExample); + this.labelShouldRetain.setFntFile(s_resprefix + "fonts/markerFelt.fnt"); break; case Mixed: this.labelShouldRetain.setString(MixedExample); + this.labelShouldRetain.setFntFile(s_resprefix + "fonts/markerFelt.fnt"); + break; + case chineseText: + this.labelShouldRetain.setFntFile(s_resprefix + "fonts/arial-unicode-26.fnt"); + this.labelShouldRetain.setString(chineseExampleText); + break; + case chineseMixEnglish: + this.labelShouldRetain.setFntFile(s_resprefix + "fonts/arial-unicode-26.fnt"); + this.labelShouldRetain.setString(chineseMixEnglishText); + break; + case mixAllLanguage: + this.labelShouldRetain.setFntFile(s_resprefix + "fonts/arial-unicode-26.fnt"); + this.labelShouldRetain.setString(mixAllLanguageText); break; - default: break; } @@ -1886,6 +1942,10 @@ var WrapAlgorithmTest = AtlasDemo.extend({ LabelTTF.boundingWidth = 120; LabelTTF.boundingHeight = 0; LabelTTF.enableStroke(cc.color(0, 0, 0, 1), 3.0); + if (cc.sys.os === cc.sys.OS_WP8) + LabelTTF.setFontName("fonts/arialuni.ttf"); + else if(cc.sys.os === cc.sys.OS_WINRT) + LabelTTF.setFontName("DengXian"); self.addChild(LabelTTF); }); @@ -1908,6 +1968,10 @@ var WrapAlgorithmTest = AtlasDemo.extend({ LabelTTF.boundingWidth = 3; LabelTTF.boundingHeight = 0; LabelTTF.enableStroke(cc.color(0, 0, 0, 1), 3.0); + if (cc.sys.os === cc.sys.OS_WP8) + LabelTTF.setFontName("fonts/arialuni.ttf"); + else if(cc.sys.os === cc.sys.OS_WINRT) + LabelTTF.setFontName("DengXian"); self.addChild(LabelTTF); }); @@ -1926,6 +1990,10 @@ var WrapAlgorithmTest = AtlasDemo.extend({ LabelTTF.boundingWidth = 90; LabelTTF.boundingHeight = 0; LabelTTF.enableStroke(cc.color(0, 0, 0, 1), 3.0); + if (cc.sys.os === cc.sys.OS_WP8) + LabelTTF.setFontName("fonts/arialuni.ttf"); + else if(cc.sys.os === cc.sys.OS_WINRT) + LabelTTF.setFontName("DengXian"); self.addChild(LabelTTF); }); diff --git a/samples/js-tests/src/LightTest/LightTest.js b/samples/js-tests/src/LightTest/LightTest.js new file mode 100644 index 0000000000..b4825fdca0 --- /dev/null +++ b/samples/js-tests/src/LightTest/LightTest.js @@ -0,0 +1,321 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ +var LightTestIdx = -1; + +var LightTestDemo = cc.Layer.extend({ + _title:"", + _subtitle:"", + + ctor:function () { + this._super(); + }, + + // + // Menu + // + onEnter:function () { + this._super(); + + var label = new cc.LabelTTF(this._title, "Arial", 28); + this.addChild(label, 100, BASE_TEST_TITLE_TAG); + label.x = winSize.width / 2; + label.y = winSize.height - 50; + + var label2 = new cc.LabelTTF(this._subtitle, "Thonburi", 16); + this.addChild(label2, 101, BASE_TEST_SUBTITLE_TAG); + label2.x = winSize.width / 2; + label2.y = winSize.height - 80; + + var item1 = new cc.MenuItemImage(s_pathB1, s_pathB2, this.onBackCallback, this); + var item2 = new cc.MenuItemImage(s_pathR1, s_pathR2, this.onRestartCallback, this); + var item3 = new cc.MenuItemImage(s_pathF1, s_pathF2, this.onNextCallback, this); + + item1.tag = BASE_TEST_MENUITEM_PREV_TAG; + item2.tag = BASE_TEST_MENUITEM_RESET_TAG; + item3.tag = BASE_TEST_MENUITEM_NEXT_TAG; + + var menu = new cc.Menu(item1, item2, item3); + + menu.x = 0; + menu.y = 0; + var width = item2.width, height = item2.height; + item1.x = winSize.width/2 - width*2; + item1.y = height/2 ; + item2.x = winSize.width/2; + item2.y = height/2 ; + item3.x = winSize.width/2 + width*2; + item3.y = height/2 ; + + this.addChild(menu, 102, BASE_TEST_MENU_TAG); + }, + + onRestartCallback:function (sender) { + var s = new LightTestScene(); + s.addChild(restartLightTest()); + director.runScene(s); + }, + + onNextCallback:function (sender) { + var s = new LightTestScene(); + s.addChild(nextLightTest()); + director.runScene(s); + }, + + onBackCallback:function (sender) { + var s = new LightTestScene(); + s.addChild(previousLightTest()); + director.runScene(s); + }, +}); + +var LightTestScene = cc.Scene.extend({ + ctor:function () { + this._super(); + + var label = new cc.LabelTTF("Main Menu", "Arial", 20); + var menuItem = new cc.MenuItemLabel(label, this.onMainMenuCallback, this); + + var menu = new cc.Menu(menuItem); + menu.x = 0; + menu.y = 0; + menuItem.x = winSize.width - 50; + menuItem.y = 25; + this.addChild(menu); + }, + onMainMenuCallback:function () { + var scene = new cc.Scene(); + var layer = new TestController(); + scene.addChild(layer); + director.runScene(scene); + }, + runThisTest:function (num) { + LightTestIdx = (num || num == 0) ? (num - 1) : -1; + var layer = nextLightTest(); + this.addChild(layer); + + director.runScene(this); + } +}); + +var LightTest = LightTestDemo.extend({ + _title:"Light Test", + _subtitle:"", + _ambientLight:null, + _directionalLight:null, + _pointLight:null, + _spotLight:null, + _ambientLightLabel:null, + _directionalLightLabel:null, + _pointLightLabel:null, + _spotLightLabel:null, + _angle:0, + + ctor:function(){ + this._super(); + + this.addSprite(); + this.addLights(); + this.scheduleUpdate(); + + var s = cc.winSize; + var camera = cc.Camera.createPerspective(60, s.width/s.height, 1, 1000); + camera.setCameraFlag(cc.CameraFlag.USER1); + camera.setPosition3D(cc.math.vec3(0, 100, 100)); + camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); + this.addChild(camera); + + this._ambientLightLabel = new cc.LabelTTF("Ambient Light ON", "Arial", 15); + var item1 = new cc.MenuItemLabel(this._ambientLightLabel, this.switchLight, this); + item1.setPosition(cc.p(100, 100 + item1.getContentSize().height * 8)); + item1.setUserData(cc.LightType.AMBIENT); + + this._directionalLightLabel = new cc.LabelTTF("Directional Light OFF", "Arial", 15); + var item2 = new cc.MenuItemLabel(this._directionalLightLabel, this.switchLight, this); + item2.setPosition(cc.p(100, 100 + item2.getContentSize().height * 6)); + item2.setUserData(cc.LightType.DIRECTIONAL); + + this._pointLightLabel = new cc.LabelTTF("Point Light OFF", "Arial", 15); + var item3 = new cc.MenuItemLabel(this._pointLightLabel, this.switchLight, this); + item3.setPosition(cc.p(100, 100 + item3.getContentSize().height * 4)); + item3.setUserData(cc.LightType.POINT); + + this._spotLightLabel = new cc.LabelTTF("Spot Light OFF", "Arial", 15); + var item4 = new cc.MenuItemLabel(this._spotLightLabel, this.switchLight, this); + item4.setPosition(cc.p(100, 100 + item4.getContentSize().height * 2)); + item4.setUserData(cc.LightType.SPOT); + + var menu = new cc.Menu(item1, item2, item3, item4); + this.addChild(menu); + menu.setPosition(cc.p(0, 0)); + + }, + + addSprite:function(){ + var s = cc.winSize; + + var orc = new jsb.Sprite3D("Sprite3DTest/orc.c3b"); + orc.setRotation3D(cc.math.vec3(0, 180, 0)); + orc.setPosition(cc.p(0, 0)); + orc.setScale(2.0); + var axe = new jsb.Sprite3D("Sprite3DTest/axe.c3b"); + orc.getAttachNode("Bip001 R Hand").addChild(axe); + var animation = jsb.Animation3D.create("Sprite3DTest/orc.c3b"); + if(animation){ + var animate = jsb.Animate3D.create(animation); + orc.runAction(cc.repeatForever(animate)); + } + this.addChild(orc); + orc.setCameraMask(2); + + var sphere1 = new jsb.Sprite3D("Sprite3DTest/sphere.c3b"); + sphere1.setPosition(cc.p(30, 0)); + this.addChild(sphere1); + sphere1.setCameraMask(2); + + var sphere2 = new jsb.Sprite3D("Sprite3DTest/sphere.c3b"); + sphere2.setPosition(cc.p(-50, 0)); + sphere2.setScale(0.5); + this.addChild(sphere2); + sphere2.setCameraMask(2); + + var sphere3 = new jsb.Sprite3D("Sprite3DTest/sphere.c3b"); + sphere3.setPosition(cc.p(-30, 0)); + sphere3.setScale(0.5); + this.addChild(sphere3); + sphere3.setCameraMask(2); + }, + + addLights:function(){ + this._ambientLight = jsb.AmbientLight.create(cc.color(200, 200, 200)); + this._ambientLight.setEnabled(true); + this.addChild(this._ambientLight); + this._ambientLight.setCameraMask(2); + + this._directionalLight = jsb.DirectionLight.create(cc.math.vec3(-1, -1, 0), cc.color(200, 200, 200)); + this._directionalLight.setEnabled(false); + this.addChild(this._directionalLight); + this._directionalLight.setCameraMask(2); + + this._pointLight = jsb.PointLight.create(cc.math.vec3(0, 0, 0), cc.color(200, 200, 200), 10000); + this._pointLight.setEnabled(false); + this.addChild(this._pointLight); + this._pointLight.setCameraMask(2); + + this._spotLight = jsb.SpotLight.create(cc.math.vec3(-1, -1, 0), cc.math.vec3(0, 0, 0), cc.color(200, 200, 200), 0, 0.5, 10000); + this._spotLight.setEnabled(false); + this.addChild(this._spotLight); + this._spotLight.setCameraMask(2); + + var seq1 = cc.sequence(cc.tintTo(4, 0, 0, 255), cc.tintTo(4, 0, 255, 0), cc.tintTo(4, 255, 0, 0), cc.tintTo(4, 255, 255, 255)); + this._ambientLight.runAction(seq1.repeatForever()); + + var seq2 = cc.sequence(cc.tintTo(4, 255, 0, 0), cc.tintTo(4, 0, 255, 0), cc.tintTo(4, 0, 0, 255), cc.tintTo(4, 255, 255, 255)); + this._directionalLight.runAction(seq2.repeatForever()); + + var seq3 = cc.sequence(cc.tintTo(4, 255, 0, 0), cc.tintTo(4, 0, 255, 0), cc.tintTo(4, 0, 0, 255), cc.tintTo(4, 255, 255, 255)); + this._pointLight.runAction(seq3.repeatForever()); + + var seq4 = cc.sequence(cc.tintTo(4, 255, 0, 0), cc.tintTo(4, 0, 255, 0), cc.tintTo(4, 0, 0, 255), cc.tintTo(4, 255, 255, 255)); + this._spotLight.runAction(seq4.repeatForever()); + }, + + update:function(dt){ + if(this._directionalLight) + this._directionalLight.setRotation3D(cc.math.vec3(-45, -cc.radiansToDegrees(this._angle), 0)); + + if(this._pointLight) + this._pointLight.setPosition3D(cc.math.vec3(100*Math.cos(this._angle+2*dt), 100, 100*Math.sin(this._angle+2*dt))); + + if(this._spotLight){ + this._spotLight.setPosition3D(cc.math.vec3(100*Math.cos(this._angle+4*dt), 100, 100*Math.sin(this._angle+4*dt))); + this._spotLight.setDirection(cc.math.vec3(-Math.cos(this._angle + 4 * dt), -1, -Math.sin(this._angle + 4*dt))); + } + }, + + switchLight:function(sender){ + var lightType = sender.getUserData(); + switch(lightType){ + case cc.LightType.AMBIENT: + var isAmbientOn = !this._ambientLight.isEnabled(); + this._ambientLight.setEnabled(isAmbientOn); + this._ambientLightLabel.setString("Ambient Light " + (isAmbientOn ? "ON" : "OFF")); + break; + + case cc.LightType.DIRECTIONAL: + var isDirectionalOn = !this._directionalLight.isEnabled(); + this._directionalLight.setEnabled(isDirectionalOn); + this._directionalLightLabel.setString("Directional Light " + (isDirectionalOn ? "ON" : "OFF")); + break; + + case cc.LightType.POINT: + var isPointOn = !this._pointLight.isEnabled(); + this._pointLight.setEnabled(isPointOn); + this._pointLightLabel.setString("Point Light " + (isPointOn ? "ON" : "OFF")); + break; + + case cc.LightType.SPOT: + var isSpotOn = !this._spotLight.isEnabled(); + this._spotLight.setEnabled(isSpotOn); + this._spotLightLabel.setString("Spot Light " + (isSpotOn ? "ON" : "OFF")); + break; + + default: + break; + } + } +}); + +// +// Flow control +// +var arrayOfLightTest = [ + LightTest +]; + +var nextLightTest = function () { + LightTestIdx++; + LightTestIdx = LightTestIdx % arrayOfLightTest.length; + + if(window.sideIndexBar){ + LightTestIdx = window.sideIndexBar.changeTest(LightTestIdx, 36); + } + + return new arrayOfLightTest[LightTestIdx ](); +}; +var previousLightTest = function () { + LightTestIdx--; + if (LightTestIdx < 0) + LightTestIdx += arrayOfLightTest.length; + + if(window.sideIndexBar){ + LightTestIdx = window.sideIndexBar.changeTest(LightTestIdx, 36); + } + + return new arrayOfLightTest[LightTestIdx ](); +}; +var restartLightTest = function () { + return new arrayOfLightTest[LightTestIdx ](); +}; diff --git a/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js b/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js index dcee059139..55e57a0aff 100644 --- a/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js +++ b/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js @@ -1200,6 +1200,56 @@ PauseResumeTargetTest.create = function(){ return test; }; +var Issue9898 = EventDispatcherTestDemo.extend({ + + title: function(){ + return "Issue9898"; + }, + + subtitle: function(){ + return "Should not crash if dispatch event after remove\n event listener in callback"; + }, + + ctor: function(){ + this._super(); + //----start12----ctor + + var origin = cc.director.getVisibleOrigin(); + var size = cc.director.getVisibleSize(); + + var node = new cc.Node(); + this.addChild(node); + + var _listener = cc.EventListener.create({ + event: cc.EventListener.CUSTOM, + eventName: "Issue9898", + callback: function(event){ + cc.eventManager.removeListener(_listener); + event = new cc.EventCustom("Issue9898"); + cc.eventManager.dispatchEvent(event); + } + }); + cc.eventManager.addListener(_listener, 1); + var menuItem = new cc.MenuItemFont("Dispatch Custom Event1", function(sender){ + var event = new cc.EventCustom("Issue9898"); + cc.eventManager.dispatchEvent(event); + }); + menuItem.setPosition(origin.x + size.width/2, origin.y + size.height/2); + + var menu = new cc.Menu(menuItem); + menu.setPosition(0, 0); + this.addChild(menu); + //----end12---- + } + +}); + +Issue9898.create = function(){ + var test = new Issue9898(); + test.init(); + return test; +}; + var EventDispatcherTestScene = TestScene.extend({ runThisTest:function (num) { eventDispatcherSceneIdx = (num || num == 0) ? (num - 1) : -1; @@ -1221,7 +1271,8 @@ var arrayOfEventDispatcherTest = [ //GlobalZTouchTest, StopPropagationTest, Issue4160, - PauseResumeTargetTest + PauseResumeTargetTest, + Issue9898 ]; var nextDispatcherTest = function () { diff --git a/samples/js-tests/src/ParticleTest/ParticleTest.js b/samples/js-tests/src/ParticleTest/ParticleTest.js index afd7d2728a..78fa53d8eb 100644 --- a/samples/js-tests/src/ParticleTest/ParticleTest.js +++ b/samples/js-tests/src/ParticleTest/ParticleTest.js @@ -263,15 +263,11 @@ var ParticleDemo = BaseTestLayer.extend({ selfPoint._textureModeButton.setVisible(true); selfPoint._shapeModeButton.setVisible(false); }); + this._shapeModeButton.setVisible(false); this._shapeModeButton.x = 10; this._shapeModeButton.y = 100; this._shapeModeButton.setAnchorPoint(0, 0); - if ('opengl' in cc.sys.capabilities ) { - // Shape type is not compatible with JSB - this._shapeModeButton.enabled = false; - } - var spriteNormal_t = new cc.Sprite(s_textureModeMenuItem, cc.rect(0, 23 * 2, 115, 23)); var spriteSelected_t = new cc.Sprite(s_textureModeMenuItem, cc.rect(0, 23, 115, 23)); var spriteDisabled_t = new cc.Sprite(s_textureModeMenuItem, cc.rect(0, 0, 115, 23)); @@ -283,16 +279,18 @@ var ParticleDemo = BaseTestLayer.extend({ selfPoint._textureModeButton.setVisible(false); selfPoint._shapeModeButton.setVisible(true); }); - this._textureModeButton.setVisible(false); this._textureModeButton.x = 10; this._textureModeButton.y = 100; this._textureModeButton.setAnchorPoint(0, 0); + if ('opengl' in cc.sys.capabilities ) { + // Shape type is not compatible with JSB + this._textureModeButton.enabled = false; + } + var menu = new cc.Menu( this._shapeModeButton, this._textureModeButton, this._freeMovementButton, this._relativeMovementButton, this._groupMovementButton); - menu.x = 0; - menu.y = 0; this.addChild(menu, 100); @@ -313,7 +311,6 @@ var ParticleDemo = BaseTestLayer.extend({ var seq = cc.sequence(move, move_back); this._background.runAction(seq.repeatForever()); - this.scheduleUpdate(); }, @@ -390,8 +387,7 @@ var DemoFirework = ParticleDemo.extend({ this._emitter = new cc.ParticleFireworks(); this._background.addChild(this._emitter, 10); - var myTexture = cc.textureCache.addImage(s_stars1); - this._emitter.texture = myTexture; + this._emitter.texture = cc.textureCache.addImage(s_stars1); if (this._emitter.setShapeType) this._emitter.setShapeType(cc.ParticleSystem.STAR_SHAPE); this.setEmitterPosition(); @@ -425,8 +421,7 @@ var DemoSun = ParticleDemo.extend({ this._emitter = new cc.ParticleSun(); this._background.addChild(this._emitter, 10); - var myTexture = cc.textureCache.addImage(s_fire); - this._emitter.texture = myTexture; + this._emitter.texture = cc.textureCache.addImage(s_fire); if (this._emitter.setShapeType) this._emitter.setShapeType(cc.ParticleSystem.BALL_SHAPE); @@ -443,8 +438,7 @@ var DemoGalaxy = ParticleDemo.extend({ this._emitter = new cc.ParticleGalaxy(); this._background.addChild(this._emitter, 10); - var myTexture = cc.textureCache.addImage(s_fire); - this._emitter.texture = myTexture; + this._emitter.texture = cc.textureCache.addImage(s_fire); if (this._emitter.setShapeType) this._emitter.setShapeType(cc.ParticleSystem.BALL_SHAPE); @@ -463,8 +457,7 @@ var DemoFlower = ParticleDemo.extend({ this._emitter = new cc.ParticleFlower(); this._background.addChild(this._emitter, 10); - var myTexture = cc.textureCache.addImage(s_stars1); - this._emitter.texture = myTexture; + this._emitter.texture = cc.textureCache.addImage(s_stars1); if (this._emitter.setShapeType) this._emitter.setShapeType(cc.ParticleSystem.STAR_SHAPE); @@ -523,17 +516,10 @@ var DemoBigFlower = ParticleDemo.extend({ this._emitter.endSpinVar = 0; // color of particles - var startColor = cc.color(128, 128, 128, 255); - this._emitter.startColor = startColor; - - var startColorVar = cc.color(128, 128, 128, 255); - this._emitter.startColorVar = startColorVar; - - var endColor = cc.color(26, 26, 26, 50); - this._emitter.endColor = endColor; - - var endColorVar = cc.color(26, 26, 26, 50); - this._emitter.endColorVar = endColorVar; + this._emitter.startColor = cc.color(128, 128, 128, 255); + this._emitter.startColorVar = cc.color(128, 128, 128, 255); + this._emitter.endColor = cc.color(26, 26, 26, 50); + this._emitter.endColorVar = cc.color(26, 26, 26, 50); // size, in pixels this._emitter.startSize = 80.0; @@ -582,7 +568,7 @@ var DemoRotFlower = ParticleDemo.extend({ this._emitter.radialAccel = -120; this._emitter.radialAccelVar = 0; - // tagential + // tangential this._emitter.tangentialAccel = 30; this._emitter.tangentialAccelVar = 0; @@ -601,17 +587,10 @@ var DemoRotFlower = ParticleDemo.extend({ this._emitter.endSpin = 0; this._emitter.endSpinVar = 2000; - var startColor = cc.color(128, 128, 128, 255); - this._emitter.startColor = startColor; - - var startColorVar = cc.color(128, 128, 128, 255); - this._emitter.startColorVar = startColorVar; - - var endColor = cc.color(26, 26, 26, 50); - this._emitter.endColor = endColor; - - var endColorVar = cc.color(26, 26, 26, 50); - this._emitter.endColorVar = endColorVar; + this._emitter.startColor = cc.color(128, 128, 128, 255); + this._emitter.startColorVar = cc.color(128, 128, 128, 255); + this._emitter.endColor = cc.color(26, 26, 26, 50); + this._emitter.endColorVar = cc.color(26, 26, 26, 50); // size, in pixels this._emitter.startSize = 30.0; @@ -785,7 +764,7 @@ var DemoModernArt = ParticleDemo.extend({ this._emitter.radialAccel = 70; this._emitter.radialAccelVar = 10; - // tagential + // tangential this._emitter.tangentialAccel = 80; this._emitter.tangentialAccelVar = 0; @@ -801,17 +780,10 @@ var DemoModernArt = ParticleDemo.extend({ this._emitter.emissionRate = this._emitter.totalParticles / this._emitter.life; // color of particles - var startColor = cc.color(128, 128, 128, 255); - this._emitter.startColor = startColor; - - var startColorVar = cc.color(128, 128, 128, 255); - this._emitter.startColorVar = startColorVar; - - var endColor = cc.color(26, 26, 26, 50); - this._emitter.endColor = endColor; - - var endColorVar = cc.color(26, 26, 26, 50); - this._emitter.endColorVar = endColorVar; + this._emitter.startColor = cc.color(128, 128, 128, 255); + this._emitter.startColorVar = cc.color(128, 128, 128, 255); + this._emitter.endColor = cc.color(26, 26, 26, 50); + this._emitter.endColorVar = cc.color(26, 26, 26, 50); // size, in pixels this._emitter.startSize = 1.0; @@ -908,6 +880,10 @@ var DemoParticleFromFile = ParticleDemo.extend({ this._background = null; this._emitter = new cc.ParticleSystem(s_resprefix + "Particles/" + this._title + ".plist"); + // test create from a object + // var plistData = jsb.fileUtils.getValueMapFromFile(s_resprefix + "Particles/" + this._title + ".plist"); + // this._emitter = new cc.ParticleSystem(plistData); + this.addChild(this._emitter, 10); if (this._title == "Flower") { @@ -981,17 +957,10 @@ var RadiusMode1 = ParticleDemo.extend({ this._emitter.endSpinVar = 0; // color of particles - var startColor = cc.color(128, 128, 128, 255); - this._emitter.startColor = startColor; - - var startColorVar = cc.color(128, 128, 128, 255); - this._emitter.startColorVar = startColorVar; - - var endColor = cc.color(26, 26, 26, 50); - this._emitter.endColor = endColor; - - var endColorVar = cc.color(26, 26, 26, 50); - this._emitter.endColorVar = endColorVar; + this._emitter.startColor = cc.color(128, 128, 128, 255); + this._emitter.startColorVar = cc.color(128, 128, 128, 255); + this._emitter.endColor = cc.color(26, 26, 26, 50); + this._emitter.endColorVar = cc.color(26, 26, 26, 50); // size, in pixels this._emitter.startSize = 32; @@ -1058,17 +1027,10 @@ var RadiusMode2 = ParticleDemo.extend({ this._emitter.endSpinVar = 0; // color of particles - var startColor = cc.color(128, 128, 128, 255); - this._emitter.startColor = startColor; - - var startColorVar = cc.color(128, 128, 128, 255); - this._emitter.startColorVar = startColorVar; - - var endColor = cc.color(26, 26, 26, 50); - this._emitter.endColor = endColor; - - var endColorVar = cc.color(26, 26, 26, 50); - this._emitter.endColorVar = endColorVar; + this._emitter.startColor = cc.color(128, 128, 128, 255); + this._emitter.startColorVar = cc.color(128, 128, 128, 255); + this._emitter.endColor = cc.color(26, 26, 26, 50); + this._emitter.endColorVar = cc.color(26, 26, 26, 50); // size, in pixels this._emitter.startSize = 32; @@ -1136,17 +1098,10 @@ var Issue704 = ParticleDemo.extend({ this._emitter.endSpinVar = 0; // color of particles - var startColor = cc.color(128, 128, 128, 255); - this._emitter.startColor = startColor; - - var startColorVar = cc.color(128, 128, 128, 255); - this._emitter.startColorVar = startColorVar; - - var endColor = cc.color(26, 26, 26, 50); - this._emitter.endColor = endColor; - - var endColorVar = cc.color(26, 26, 26, 50); - this._emitter.endColorVar = endColorVar; + this._emitter.startColor = cc.color(128, 128, 128, 255); + this._emitter.startColorVar = cc.color(128, 128, 128, 255); + this._emitter.endColor = cc.color(26, 26, 26, 50); + this._emitter.endColorVar = cc.color(26, 26, 26, 50); // size, in pixels this._emitter.startSize = 16; diff --git a/samples/js-tests/src/SchedulerTest/SchedulerTest.js b/samples/js-tests/src/SchedulerTest/SchedulerTest.js index fd24478d55..ac0c3c96f5 100644 --- a/samples/js-tests/src/SchedulerTest/SchedulerTest.js +++ b/samples/js-tests/src/SchedulerTest/SchedulerTest.js @@ -529,6 +529,168 @@ var ScheduleUsingSchedulerTest = SchedulerTestLayer.extend({ } }); +// SchedulerTimeScale + +var SchedulerTimeScale = SchedulerTestLayer.extend({ + _newScheduler: null, + _newActionManager: null, + + onEnter: function() { + this._super(); + + this._newScheduler = new cc.Scheduler(); + this._newActionManager = new cc.ActionManager(); + + var s = cc.winSize; + + // rotate and jump + var jump1 = new cc.JumpBy(4, cc.p(-s.width+80,0), 100, 4); + var jump2 = jump1.reverse(); + var rot1 = new cc.RotateBy(4, 360*2); + var rot2 = rot1.reverse(); + + var seq3_1 = new cc.Sequence(jump2, jump1); + var seq3_2 = new cc.Sequence(rot1, rot2); + var spawn = new cc.Spawn(seq3_1, seq3_2); + var action = new cc.Repeat(spawn, 50); + + var action2 = action.clone(); + var action3 = action.clone(); + + var grossini = new cc.Sprite("res/Images/grossini.png"); + var tamara = new cc.Sprite("res/Images/grossinis_sister1.png"); + var kathia = new cc.Sprite("res/Images/grossinis_sister2.png"); + + grossini.setActionManager(this._newActionManager); + grossini.setScheduler(this._newScheduler); + + grossini.setPosition(cc.p(40,80)); + tamara.setPosition(cc.p(40,80)); + kathia.setPosition(cc.p(40,80)); + + this.addChild(grossini); + this.addChild(tamara); + this.addChild(kathia); + + grossini.runAction(new cc.Speed(action, 0.5)); + tamara.runAction(new cc.Speed(action2, 1.5)); + kathia.runAction(new cc.Speed(action3, 1.0)); + + cc.director.getScheduler().scheduleUpdateForTarget(this._newScheduler, 0, false); + + this._newScheduler.scheduleUpdateForTarget(this._newActionManager, 0, false); + + var emitter = new cc.ParticleFireworks(); + emitter.setTexture( cc.textureCache.addImage(s_stars1) ); + this.addChild(emitter); + + var slider = null; + var l = null; + + slider = new ccui.Slider(); + slider.setTouchEnabled(true); + slider.loadBarTexture("res/cocosui/sliderTrack.png"); + slider.loadSlidBallTextures("res/cocosui/sliderThumb.png", "res/cocosui/sliderThumb.png", ""); + slider.loadProgressBarTexture("res/cocosui/sliderProgress.png"); + slider.x = cc.winSize.width / 2.0; + slider.y = cc.winSize.height / 3.0 * 2; + slider.addEventListener(this.sliderEventForGrossini, this); + this.addChild(slider); + slider.setPercent(20); + + l = new cc.LabelTTF("Control time scale only for Grossini", "Thonburi", 16); + this.addChild(l); + l.x = slider.x; + l.y = slider.y + 30; + + slider = new ccui.Slider(); + slider.setTouchEnabled(true); + slider.loadBarTexture("res/cocosui/sliderTrack.png"); + slider.loadSlidBallTextures("res/cocosui/sliderThumb.png", "res/cocosui/sliderThumb.png", ""); + slider.loadProgressBarTexture("res/cocosui/sliderProgress.png"); + slider.x = cc.winSize.width / 2.0; + slider.y = cc.winSize.height / 3.0; + slider.addEventListener(this.sliderEventForGlobal, this); + this.addChild(slider); + slider.setPercent(20); + l = new cc.LabelTTF("Control time scale for all", "Thonburi", 16); + this.addChild(l); + l.x = slider.x; + l.y = slider.y + 30; + }, + + sliderEventForGrossini: function (sender, type) { + switch (type) { + case ccui.Slider.EVENT_PERCENT_CHANGED: + var slider = sender; + var percent = slider.getPercent() / 100.0 * 5; + this._newScheduler.setTimeScale(percent); + break; + default: + break; + } + }, + + sliderEventForGlobal: function (sender, type) { + switch (type) { + case ccui.Slider.EVENT_PERCENT_CHANGED: + var slider = sender; + var percent = slider.getPercent() / 100.0 * 5; + cc.director.getScheduler().setTimeScale(percent); + break; + default: + break; + } + }, + + onExit: function() { + // restore scale + cc.director.getScheduler().unscheduleUpdateForTarget(this._newScheduler); + this._super(); + }, + + title:function () { + return "Scheduler timeScale Test"; + }, + + subtitle:function () { + return "Fast-forward and rewind using scheduler.timeScale"; + } +}); + +var unScheduleAndRepeatTest = SchedulerTestLayer.extend({ + + onEnter: function(){ + this._super(); + cc.log("start schedule 'repeat': run once and repeat 4 times"); + this.schedule(this.repeat, 0.5, 4); + cc.log("start schedule 'forever': repeat forever (stop in 8s)"); + this.schedule(this.forever, 0.5); + this.schedule(function(){ + cc.log("stop the 'forever'"); + this.unschedule(this.forever); + }, 8); + }, + + _times: 5, + + repeat: function(){ + cc.log("Repeat - the remaining number: " + this._times--); + }, + + forever: function(){ + cc.log("Repeat Forever..."); + }, + + title: function(){ + return "Repeat And unschedule Test"; + }, + + subtitle: function(){ + return "Repeat will print 5 times\nForever will stop in 8 seconds."; + } +}); + /* main entry */ @@ -547,6 +709,7 @@ var SchedulerTestScene = TestScene.extend({ // var arrayOfSchedulerTest = [ + SchedulerTimeScale, SchedulerAutoremove, SchedulerPauseResume, SchedulerUnscheduleAll, @@ -556,7 +719,8 @@ var arrayOfSchedulerTest = [ SchedulerUpdateAndCustom, SchedulerUpdateFromCustom, RescheduleCallback, - ScheduleUsingSchedulerTest + ScheduleUsingSchedulerTest, + unScheduleAndRepeatTest ]; var nextSchedulerTest = function () { diff --git a/samples/js-tests/src/SpineTest/SpineTest.js b/samples/js-tests/src/SpineTest/SpineTest.js index c8e9db7b6d..f88cd68949 100644 --- a/samples/js-tests/src/SpineTest/SpineTest.js +++ b/samples/js-tests/src/SpineTest/SpineTest.js @@ -26,79 +26,135 @@ var sp = sp || {}; -var ANIMATION_TYPE = { - ANIMATION_START: 0, - ANIMATION_END: 1, - ANIMATION_COMPLETE: 2, - ANIMATION_EVENT: 3 -}; - -SpineTestScene = TestScene.extend({ - +var spineSceneIdx = -1; +var SpineTestScene = TestScene.extend({ runThisTest:function () { - var layer = new SpineTest(); + var layer = SpineTestScene.nextSpineTestLayer(); this.addChild(layer); - director.runScene(this); } }); -touchcount = 0; +SpineTestScene.nextSpineTestLayer = function() { + spineSceneIdx++; + var layers = SpineTestScene.testLayers; + spineSceneIdx = spineSceneIdx % layers.length; + return new layers[spineSceneIdx](); +}; + +SpineTestScene.backSpineTestLayer = function() { + spineSceneIdx--; + var layers = SpineTestScene.testLayers; + if(spineSceneIdx < 0) + spineSceneIdx = layers.length; + return new layers[spineSceneIdx](); +}; + +SpineTestScene.restartSpineTestLayer = function(){ + return new SpineTestScene.testLayers[spineSceneIdx](); +}; -var SpineTest = BaseTestLayer.extend({ +var SpineTestLayer = BaseTestLayer.extend({ + onRestartCallback: function(sender){ + var s = new SpineTestScene(); + s.addChild(SpineTestScene.restartSpineTestLayer()); + cc.director.runScene(s); + }, + + onNextCallback: function(sender){ + var s = new SpineTestScene(); + s.addChild(SpineTestScene.nextSpineTestLayer()); + cc.director.runScene(s); + }, + + onBackCallback: function(sender){ + var s = new SpineTestScene(); + s.addChild(SpineTestScene.backSpineTestLayer()); + cc.director.runScene(s); + } +}); + +var SpineTestLayerNormal = SpineTestLayer.extend({ _spineboy:null, _debugMode: 0, _flipped: false, ctor:function () { this._super(cc.color(0,0,0,255), cc.color(98,99,117,255)); - cc.eventManager.addListener({ - event: cc.EventListener.TOUCH_ALL_AT_ONCE, - onTouchesBegan: function(touches, event){ - var target = event.getCurrentTarget(); - target._debugMode ++; - target._debugMode = target._debugMode % 3; - if (target._debugMode == 0) { - target._spineboy.setDebugBones(false); - target._spineboy.setDebugSolots(false); - return; - } - - if (target._debugMode == 1) { - target._spineboy.setDebugBones(true); - target._spineboy.setDebugSolots(false); - return; - } - - if (target._debugMode == 2) { - target._spineboy.setDebugBones(false); - target._spineboy.setDebugSolots(true); - } - } - }, this); var size = director.getWinSize(); ///////////////////////////// // Make Spine's Animated skeleton Node // You need 'json + atlas + image' resource files to make it. // No JS binding for spine-c in this version. So, only file loading is supported. - var spineBoy = sp.SkeletonAnimation.create('res/skeletons/spineboy.json', 'res/skeletons/spineboy.atlas'); + var spineBoy = new sp.SkeletonAnimation('res/skeletons/spineboy.json', 'res/skeletons/spineboy.atlas'); spineBoy.setPosition(cc.p(size.width / 2, size.height / 2 - 150)); - spineBoy.setAnimation(0, 'walk', true); spineBoy.setMix('walk', 'jump', 0.2); - spineBoy.setMix('jump', 'walk', 0.4); - spineBoy.setAnimationListener(this, this.animationStateEvent); + spineBoy.setMix('jump', 'run', 0.2); + spineBoy.setAnimation(0, 'walk', true); + //spineBoy.setAnimationListener(this, this.animationStateEvent); + spineBoy.setScale(0.5); this.addChild(spineBoy, 4); this._spineboy = spineBoy; + spineBoy.setStartListener(function(trackIndex){ + var entry = spineBoy.getState().getCurrent(trackIndex); + if(entry){ + var animationName = entry.animation ? entry.animation.name : ""; + cc.log("%d start: %s", trackIndex, animationName); + } + }); + spineBoy.setEndListener(function(traceIndex){ + cc.log("%d end.", traceIndex); + }); + spineBoy.setCompleteListener(function(traceIndex, loopCount){ + cc.log("%d complete: %d", traceIndex, loopCount); + }); + spineBoy.setEventListener(function(traceIndex, event){ + cc.log( traceIndex + " event: %s, %d, %f, %s",event.data.name, event.intValue, event.floatValue, event.stringValue); + }); + + var jumpEntry = spineBoy.addAnimation(0, "jump", false, 3); + spineBoy.addAnimation(0, "run", true); + // spineBoy.setTrackStartListener(jumpEntry, function(traceIndex){ + // cc.log("jumped!"); + // }); + + cc.eventManager.addListener({ + event: cc.EventListener.TOUCH_ALL_AT_ONCE, + onTouchesBegan: function(touches, event){ + if(spineBoy.getTimeScale() === 1.0) + spineBoy.setTimeScale(0.3); + else + spineBoy.setTimeScale(1); + } + }, this); + + cc.MenuItemFont.setFontSize(20); + var bonesToggle = new cc.MenuItemToggle( + new cc.MenuItemFont("Debug Bones: Off"), + new cc.MenuItemFont("Debug Bones: On")); + bonesToggle.setCallback(this.onDebugBones, this); + bonesToggle.setPosition(160 - size.width / 2, 120 - size.height / 2); + var slotsToggle = new cc.MenuItemToggle( + new cc.MenuItemFont("Debug Slots: Off"), + new cc.MenuItemFont("Debug Slots: On")); + slotsToggle.setCallback(this.onDebugSlots, this); + slotsToggle.setPosition(160 - size.width / 2, 160 - size.height / 2); + var menu = new cc.Menu(); + menu.ignoreAnchorPointForPosition(true); + menu.addChild(bonesToggle); + menu.addChild(slotsToggle); + this.addChild(menu, 5); }, - onBackCallback:function (sender) { - }, - onRestartCallback:function (sender) { + + onDebugBones: function(sender){ + this._spineboy.setDebugBonesEnabled(!this._spineboy.getDebugBonesEnabled()); }, - onNextCallback:function (sender) { - touchcount++; - this._spineboy.setAnimation(0, ['walk', 'jump'][touchcount % 2], true); + + onDebugSlots: function(sender){ + this._spineboy.setDebugSlotsEnabled(!this._spineboy.getDebugSlotsEnabled()); }, + subtitle:function () { return "Spine test"; }, @@ -109,26 +165,24 @@ var SpineTest = BaseTestLayer.extend({ animationStateEvent: function(obj, trackIndex, type, event, loopCount) { var entry = this._spineboy.getCurrent(); var animationName = (entry && entry.animation) ? entry.animation.name : 0; - - switch(type) - { - case ANIMATION_TYPE.ANIMATION_START: + switch(type) { + case sp.ANIMATION_EVENT_TYPE.START: cc.log(trackIndex + " start: " + animationName); break; - case ANIMATION_TYPE.ANIMATION_END: + case sp.ANIMATION_EVENT_TYPE.END: cc.log(trackIndex + " end:" + animationName); break; - case ANIMATION_TYPE.ANIMATION_EVENT: + case sp.ANIMATION_EVENT_TYPE.EVENT: cc.log(trackIndex + " event: " + animationName); break; - case ANIMATION_TYPE.ANIMATION_COMPLETE: + case sp.ANIMATION_EVENT_TYPE.COMPLETE: cc.log(trackIndex + " complete: " + animationName + "," + loopCount); if(this._flipped){ this._flipped = false; - this._spineboy.setScaleX(1); + this._spineboy.setScaleX(0.5); }else{ this._flipped = true; - this._spineboy.setScaleX(-1); + this._spineboy.setScaleX(-0.5); } break; default : @@ -143,5 +197,84 @@ var SpineTest = BaseTestLayer.extend({ getTestNumber:function() { return 0; } +}); + +var SpineTestLayerFFD = SpineTestLayer.extend({ + ctor: function(){ + this._super(cc.color(0,0,0,255), cc.color(98,99,117,255)); + + var skeletonNode = new sp.SkeletonAnimation("res/skeletons/goblins-ffd.json", "res/skeletons/goblins-ffd.atlas", 1.5); + skeletonNode.setAnimation(0, "walk", true); + skeletonNode.setSkin("goblin"); + skeletonNode.setScale(0.5); + var winSize = cc.director.getWinSize(); + skeletonNode.setPosition(winSize.width /2, 20); + this.addChild(skeletonNode); + + var listener = cc.EventListener.create({ + event: cc.EventListener.TOUCH_ONE_BY_ONE, + onTouchBegan : function(touch, event){ + if(!skeletonNode.getDebugBonesEnabled()) + skeletonNode.setDebugBonesEnabled(true); + else if(skeletonNode.getTimeScale() === 1.0) + skeletonNode.setTimeScale(0.3); + else{ + skeletonNode.setTimeScale(1); + skeletonNode.setDebugBonesEnabled(false); + } + return true; + } + }); + cc.eventManager.addListener(listener, this); + }, + + title: function(){ + return "Spine Test"; + }, + + subtitle: function(){ + return "FFD Spine"; + } +}); + +var SpineTestPerformanceLayer = SpineTestLayer.extend({ + ctor: function(){ + this._super(cc.color(0,0,0,255), cc.color(98,99,117,255)); + + var self = this; + var listener = cc.EventListener.create({ + event: cc.EventListener.TOUCH_ONE_BY_ONE, + onTouchBegan: function(touch, event){ + var pos = self.convertToNodeSpace(touch.getLocation()); + var skeletonNode = new sp.SkeletonAnimation("res/skeletons/goblins-ffd.json", "res/skeletons/goblins-ffd.atlas", 1.5); + skeletonNode.setAnimation(0, "walk", true); + skeletonNode.setSkin("goblin"); + + skeletonNode.setScale(0.2); + skeletonNode.setPosition(pos); + self.addChild(skeletonNode); + return true; + } + }); + cc.eventManager.addListener(listener, this); + }, + title: function(){ + return "Spine Test"; + }, + subtitle: function() { + return "Performance Test for Spine"; + } }); + +SpineTestScene.testLayers = [ + SpineTestLayerNormal + //SpineTestLayerFFD, //it doesn't support mesh on Web. + //SpineTestPerformanceLayer +]; + +if(cc.sys.isNative){ + SpineTestScene.testLayers.push(SpineTestLayerFFD); + SpineTestScene.testLayers.push(SpineTestPerformanceLayer); +} + diff --git a/samples/js-tests/src/Sprite3DTest/Sprite3DTest.js b/samples/js-tests/src/Sprite3DTest/Sprite3DTest.js new file mode 100644 index 0000000000..f4f2973c8c --- /dev/null +++ b/samples/js-tests/src/Sprite3DTest/Sprite3DTest.js @@ -0,0 +1,1589 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ +var Sprite3DTestIdx = -1; + +var Sprite3DTestDemo = cc.Layer.extend({ + _title:"", + _subtitle:"", + + ctor:function () { + this._super(); + }, + + // + // Menu + // + onEnter:function () { + this._super(); + + var label = new cc.LabelTTF(this._title, "Arial", 28); + this.addChild(label, 100, BASE_TEST_TITLE_TAG); + label.x = winSize.width / 2; + label.y = winSize.height - 50; + + var label2 = new cc.LabelTTF(this._subtitle, "Thonburi", 16); + this.addChild(label2, 101, BASE_TEST_SUBTITLE_TAG); + label2.x = winSize.width / 2; + label2.y = winSize.height - 80; + + var item1 = new cc.MenuItemImage(s_pathB1, s_pathB2, this.onBackCallback, this); + var item2 = new cc.MenuItemImage(s_pathR1, s_pathR2, this.onRestartCallback, this); + var item3 = new cc.MenuItemImage(s_pathF1, s_pathF2, this.onNextCallback, this); + + item1.tag = BASE_TEST_MENUITEM_PREV_TAG; + item2.tag = BASE_TEST_MENUITEM_RESET_TAG; + item3.tag = BASE_TEST_MENUITEM_NEXT_TAG; + + var menu = new cc.Menu(item1, item2, item3); + + menu.x = 0; + menu.y = 0; + var width = item2.width, height = item2.height; + item1.x = winSize.width/2 - width*2; + item1.y = height/2 ; + item2.x = winSize.width/2; + item2.y = height/2 ; + item3.x = winSize.width/2 + width*2; + item3.y = height/2 ; + + this.addChild(menu, 102, BASE_TEST_MENU_TAG); + }, + + onRestartCallback:function (sender) { + var s = new Sprite3DTestScene(); + s.addChild(restartSprite3DTest()); + director.runScene(s); + }, + + onNextCallback:function (sender) { + var s = new Sprite3DTestScene(); + s.addChild(nextSprite3DTest()); + director.runScene(s); + }, + + onBackCallback:function (sender) { + var s = new Sprite3DTestScene(); + s.addChild(previousSprite3DTest()); + director.runScene(s); + }, +}); + +var Sprite3DTestScene = cc.Scene.extend({ + ctor:function () { + this._super(); + + var label = new cc.LabelTTF("Main Menu", "Arial", 20); + var menuItem = new cc.MenuItemLabel(label, this.onMainMenuCallback, this); + + var menu = new cc.Menu(menuItem); + menu.x = 0; + menu.y = 0; + menuItem.x = winSize.width - 50; + menuItem.y = 25; + this.addChild(menu); + }, + onMainMenuCallback:function () { + var scene = new cc.Scene(); + var layer = new TestController(); + scene.addChild(layer); + director.runScene(scene); + }, + runThisTest:function (num) { + Sprite3DTestIdx = (num || num == 0) ? (num - 1) : -1; + var layer = nextSprite3DTest(); + this.addChild(layer); + + director.runScene(this); + } +}); + + +var Sprite3DBasicTest = Sprite3DTestDemo.extend({ + _title: "Testing Sprite3D", + _subtitle: "Tap screen to add more sprites", + + ctor:function(){ + this._super(); + + var winSize = cc.winSize; + this.addNewSpriteWithCoords(cc.p(winSize.width/2, winSize.height/2)); + + var that = this; + cc.eventManager.addListener({ + event: cc.EventListener.TOUCH_ALL_AT_ONCE, + onTouchesEnded: function(touches, event){ + for(var i in touches){ + that.addNewSpriteWithCoords(touches[i].getLocation()); + } + } + }, this); + }, + + addNewSpriteWithCoords:function(position){ + var sprite = new jsb.Sprite3D("Sprite3DTest/boss1.obj"); + sprite.setScale(3.0); + sprite.setTexture("Sprite3DTest/boss.png"); + sprite.x = position.x; + sprite.y = position.y; + + this.addChild(sprite); + + var action; + var random = Math.random(); + if(random < 0.2) + action = cc.scaleBy(3, 2); + else if(random < 0.4) + action = cc.rotateBy(3, 360); + else if(random < 0.6) + action = cc.blink(1, 3); + else if(random < 0.8) + action = cc.tintBy(2, 0, -255, -255); + else + action = cc.fadeOut(2); + + var action_back = action.reverse(); + var seq = cc.sequence(action, action_back); + + sprite.runAction(seq.repeatForever()); + } +}); + +var Sprite3DHitTest = Sprite3DTestDemo.extend({ + _title:"Testing Sprite3D Touch in 2D", + _subtitle:"Tap Sprite3D and Drag", + + ctor:function(){ + this._super(); + + var s = cc.winSize; + + var sprite1 = new jsb.Sprite3D("Sprite3DTest/boss1.obj"); + sprite1.setScale(4.0); + sprite1.setTexture("Sprite3DTest/boss.png"); + sprite1.setPosition(cc.p(s.width/2, s.height/2)); + + this.addChild(sprite1); + sprite1.runAction(cc.rotateBy(3, 360).repeatForever()); + + var sprite2 = new jsb.Sprite3D("Sprite3DTest/boss1.obj") + sprite2.setScale(4.0); + sprite2.setTexture("Sprite3DTest/boss.png"); + sprite2.setPosition(cc.p(s.width/2, s.height/2)); + sprite2.setAnchorPoint(cc.p(0.5, 0.5)); + + this.addChild(sprite2); + sprite2.runAction(cc.rotateBy(3, -360).repeatForever()); + + // Make sprite1 touchable + var listener1 = cc.EventListener.create({ + event: cc.EventListener.TOUCH_ONE_BY_ONE, + swallowTouches: true, + onTouchBegan: function (touch, event) { + var target = event.getCurrentTarget(); + var rect = target.getBoundingBox(); + if(cc.rectContainsPoint(rect, touch.getLocation())){ + cc.log("sprite3d began... x = " + touch.getLocation().x + ", y = " + touch.getLocation().y); + target.setOpacity(100); + return true; + } + return false; + }, + onTouchMoved: function (touch, event) { + var target = event.getCurrentTarget(); + var oldPos = target.getPosition(); + var delta = touch.getDelta(); + target.setPosition(cc.p(oldPos.x + delta.x, oldPos.y + delta.y)); + }, + onTouchEnded: function (touch, event) { + var target = event.getCurrentTarget(); + cc.log("sprite3d onTouchEnded..."); + target.setOpacity(255); + } + }); + cc.eventManager.addListener(listener1, sprite1); + cc.eventManager.addListener(listener1.clone(), sprite2); + } +}); + +var AsyncLoadSprite3DTest = Sprite3DTestDemo.extend({ + _title:"Testing Sprite3D::createAsync", + _subtitle:"", + _path:["Sprite3DTest/boss.obj", "Sprite3DTest/girl.c3b", "Sprite3DTest/orc.c3b", "Sprite3DTest/ReskinGirl.c3b", "Sprite3DTest/axe.c3b"], + + ctor:function(){ + this._super(); + + var label = new cc.LabelTTF("AsyncLoad Sprite3D", "Arial", 15); + var item = new cc.MenuItemLabel(label, this. menuCallback_asyncLoadSprite, this); + + var s = cc.winSize; + item.setPosition(s.width / 2, s.height / 2); + + var menu = new cc.Menu(item); + menu.setPosition(cc.p(0, 0)); + this.addChild(menu, 10); + + var node = new cc.Node(); + node.setTag(101); + this.addChild(node); + + this.menuCallback_asyncLoadSprite(); + }, + + menuCallback_asyncLoadSprite:function(sender){ + //Note that you must stop the tasks before leaving the scene. + cc.AsyncTaskPool.getInstance().stopTasks(cc.AsyncTaskPool.TaskType.TASK_IO); + + var node = this.getChildByTag(101); + node.removeAllChildren(); // remove all loaded sprites + + //remove cache data + jsb.sprite3DCache.removeAllSprite3DData(); + + for(var i = 0; i < this._path.length; ++i){ + jsb.Sprite3D.createAsync(this._path[i], this.asyncLoad_Callback, this, i); + } + + }, + + asyncLoad_Callback:function(sprite, data){ + var node = this.getChildByTag(101); + var s = cc.winSize; + var width = s.width / this._path.length; + sprite.setPosition(width * (0.5 + data), s.height / 2); + node.addChild(sprite); + } +}); + +var Sprite3DWithSkinTest = Sprite3DTestDemo.extend({ + _title:"Testing Sprite3D", + _subtitle:"Tap screen to add more sprite3D", + + ctor:function(){ + this._super(); + + var size = cc.winSize; + this.addNewSpriteWithCoords(cc.p(size.width/2, size.height/2)); + + var that = this; + cc.eventManager.addListener({ + event: cc.EventListener.TOUCH_ALL_AT_ONCE, + onTouchesEnded: function(touches, event){ + for(var i in touches){ + that.addNewSpriteWithCoords(touches[i].getLocation()); + } + } + }, this); + }, + + addNewSpriteWithCoords:function(position){ + var sprite = new jsb.Sprite3D("Sprite3DTest/orc.c3b"); + sprite.setScale(3); + sprite.setRotation3D({x : 0, y : 180, z: 0}); + this.addChild(sprite); + sprite.setPosition(position); + + var animation = jsb.Animation3D.create("Sprite3DTest/orc.c3b"); + if(animation){ + var animate = jsb.Animate3D.create(animation); + var inverse = Math.random() < 0.33 ? true : false; + + var rand2 = Math.random(); + var speed = 1.0; + if(rand2 < 0.33) + speed = animate.getSpeed() + Math.random(); + else if(rand2 < 0.66) + spped = animate.getSpeed() - 0.5 * Math.random(); + + animate.setSpeed(inverse ? -speed : speed); + sprite.runAction(new cc.RepeatForever(animate)); + } + } +}); + +var Animate3DTest = (function(){ + + var State = { + SWIMMING : 0, + SWIMMING_TO_HURT : 1, + HURT : 2, + HURT_TO_SWIMMING : 3 + }; + + return Sprite3DTestDemo.extend({ + _title:"Testing Animate3D", + _subtitle:"Touch to beat the tortoise", + _sprite:null, + _swim:null, + _hurt:null, + _moveAction:null, + _state:0, + _elapseTransTime:0, + + ctor:function(){ + this._super(); + + this.addSprite3D(); + + cc.eventManager.addListener({ + event: cc.EventListener.TOUCH_ALL_AT_ONCE, + onTouchesEnded: this.onTouchesEnded.bind(this) + }, this); + + this.scheduleUpdate(); + }, + + onExit:function(){ + this._super(); + this._moveAction.release(); + this._hurt.release(); + this._swim.release(); + }, + + addSprite3D:function(){ + var sprite = new jsb.Sprite3D("Sprite3DTest/tortoise.c3b"); + sprite.setScale(0.1); + var s = cc.winSize; + sprite.setPosition(cc.p(s.width * 4 / 5, s.height / 2)); + this.addChild(sprite); + this._sprite = sprite; + + var animation = jsb.Animation3D.create("Sprite3DTest/tortoise.c3b"); + if(animation){ + var animate = jsb.Animate3D.create(animation, 0, 1.933); + this._swim = new cc.RepeatForever(animate); + sprite.runAction(this._swim); + + this._swim.retain(); + this._hurt = jsb.Animate3D.create(animation, 1.933, 2.8); + this._hurt.retain(); + + this._state = State.SWIMMING; + } + + this._moveAction = cc.moveBy(4.0, cc.p(-s.width / 5 * 3, 0)); + this._moveAction.retain(); + var seq = cc.sequence(this._moveAction, cc.callFunc(this.reachEndCallBack, this)); + seq.setTag(100); + sprite.runAction(seq); + }, + + reachEndCallBack:function(sender){ + var sprite = this._sprite; + sprite.stopActionByTag(100); + var inverse = this._moveAction.reverse(); + inverse.retain(); + this._moveAction.release(); + this._moveAction = inverse; + var rot = cc.rotateBy(1, {x : 0, y : 180, z : 0}); + var seq = cc.sequence(rot, this._moveAction, cc.callFunc(this.reachEndCallBack, this)); + seq.setTag(100); + sprite.runAction(seq); + }, + + renewCallBack:function(){ + this._sprite.runAction(this._swim); + this._state = State.HURT_TO_SWIMMING; + this._elapseTransTime = 0.0; + }, + + onTouchesEnded:function(touches, event){ + for(var i in touches){ + var location = touches[i].getLocation(); + + if(this._sprite){ + var len = cc.pDistance(this._sprite.getPosition(), location); + + if(len < 40){ + //hurt the tortoise + if(this._state == State.SWIMMING){ + this._elapseTransTime = 0; + this._state = State.SWIMMING_TO_HURT; + this._sprite.stopAction(this._hurt); + this._sprite.runAction(this._hurt); + var delay = cc.delayTime(this._hurt.getDuration() - jsb.Animate3D.getTransitionTime()); + var seq = cc.sequence(delay, cc.callFunc(this.renewCallBack, this)); + seq.setTag(101); + this._sprite.runAction(seq); + } + } + } + } + }, + + update:function(dt){ + if(this._state == State.HURT_TO_SWIMMING){ + this._elapseTransTime += dt; + + if(this._elapseTransTime >= jsb.Animate3D.getTransitionTime()){ + this._sprite.stopAction(this._hurt); + this._state = State.SWIMMING; + } + }else if(this._state == State.SWIMMING_TO_HURT){ + this._elapseTransTime += dt; + + if(this._elapseTransTime >= jsb.Animate3D.getTransitionTime()){ + this._sprite.stopAction(this._swim); + this._state = State.HURT; + } + } + } + }); +})(); + + +var AttachmentTest = Sprite3DTestDemo.extend({ + _title:"Testing Sprite3D Attachment", + _subtitle:"touch to switch weapon", + _hasWeapon:false, + _sprite:null, + + ctor:function(){ + this._super(); + + var s = cc.winSize; + this.addNewSpriteWithCoords(cc.p(s.width/2, s.height/2)); + + cc.eventManager.addListener({ + event: cc.EventListener.TOUCH_ALL_AT_ONCE, + onTouchesEnded: this.onTouchesEnded.bind(this) + }, this); + }, + + addNewSpriteWithCoords:function(position){ + var sprite = new jsb.Sprite3D("Sprite3DTest/orc.c3b"); + sprite.setScale(5); + sprite.setRotation3D(cc.math.vec3(0, 180, 0)); + this.addChild(sprite); + sprite.setPosition(position); + + //test attach + var sp = new jsb.Sprite3D("Sprite3DTest/axe.c3b"); + sprite.getAttachNode("Bip001 R Hand").addChild(sp); + + var animation = jsb.Animation3D.create("Sprite3DTest/orc.c3b"); + if(animation){ + var animate = jsb.Animate3D.create(animation); + sprite.runAction(cc.repeatForever(animate)); + } + + this._sprite = sprite; + this._hasWeapon = true; + }, + + onTouchesEnded:function(touches, event){ + if(this._hasWeapon){ + this._sprite.removeAllAttachNode(); + }else{ + var sp = new jsb.Sprite3D("Sprite3DTest/axe.c3b"); + this._sprite.getAttachNode("Bip001 R Hand").addChild(sp); + } + this._hasWeapon = !this._hasWeapon; + } +}); + +var Sprite3DReskinTest = (function(){ + var SkinType = { + UPPER_BODY : 0, + PANTS : 1, + SHOES : 2, + HAIR : 3, + FACE : 4, + HAND : 5, + GLASSES : 6, + MAX_TYPE : 7 + }; + + return Sprite3DTestDemo.extend({ + _title:"Testing Sprite3D Reskin", + _subtitle:"", + _sprite:null, + _skins:[["Girl_UpperBody01", "Girl_UpperBody02"], ["Girl_LowerBody01", "Girl_LowerBody02"], ["Girl_Shoes01", "Girl_Shoes02"], ["Girl_Hair01", "Girl_Hair02"], ["Girl_Face01", "Girl_Face02"], ["Girl_Hand01", "Girl_Hand02"], ["", "Girl_Glasses01"]], + _curSkin:["Girl_UpperBody01", "Girl_LowerBody01", "Girl_Shoes01", "Girl_Hair01", "Girl_Face01", "Girl_Hand01", ""], + + ctor:function(){ + this._super(); + + var s = cc.winSize; + this.addNewSpriteWithCoords(cc.p(s.width/2, s.height/2)); + + var label1 = new cc.LabelTTF("Hair", "Arial", 20); + var item1 = new cc.MenuItemLabel(label1, this.menuCallback_reSkin, this ); + item1.setPosition(cc.p(50, item1.getContentSize().height * 4)); + item1.setUserData(SkinType.HAIR); + + var label2 = new cc.LabelTTF("Glasses", "Arial", 20); + var item2 = new cc.MenuItemLabel(label2, this.menuCallback_reSkin, this); + item2.setPosition(cc.p(50, item2.getContentSize().height * 5)); + item2.setUserData(SkinType.GLASSES); + + var label3 = new cc.LabelTTF("Coat", "Arial", 20); + var item3 = new cc.MenuItemLabel(label3, this.menuCallback_reSkin, this); + item3.setPosition(cc.p(50, item3.getContentSize().height * 6)); + item3.setUserData(SkinType.UPPER_BODY); + + var label4 = new cc.LabelTTF("Pants", "Arial", 20); + var item4 = new cc.MenuItemLabel(label4, this.menuCallback_reSkin, this); + item4.setPosition(cc.p(50, item4.getContentSize().height * 7)); + item4.setUserData(SkinType.PANTS); + + var label5 = new cc.LabelTTF("Shoes", "Arial", 20); + var item5 = new cc.MenuItemLabel(label5, this.menuCallback_reSkin, this); + item5.setPosition(cc.p(50, item5.getContentSize().height * 8)); + item5.setUserData(SkinType.SHOES); + + var menu = new cc.Menu(item1, item2, item3, item4, item5); + this.addChild(menu); + menu.setPosition(cc.p(0, 0)); + }, + + addNewSpriteWithCoords:function(position){ + var sprite = new jsb.Sprite3D("Sprite3DTest/ReskinGirl.c3b"); + sprite.setScale(4); + sprite.setRotation3D(cc.math.vec3(0, 0, 0)); + this.addChild(sprite); + sprite.setPosition(cc.p(position.x, position.y - 60)); + var animation = jsb.Animation3D.create("Sprite3DTest/ReskinGirl.c3b"); + if(animation){ + var animate = jsb.Animate3D.create(animation); + sprite.runAction(cc.repeatForever(animate)); + } + this._sprite = sprite; + + this.applyCurSkin(); + }, + + applyCurSkin:function(){ + for(var i = 0; i < this._sprite.getMeshCount(); i++){ + var mesh = this._sprite.getMeshByIndex(i); + var isVisible = false; + for(var j = 0; j < SkinType.MAX_TYPE; j++){ + if(mesh.getName() == this._curSkin[j]){ + isVisible = true; + break; + } + } + mesh.setVisible(isVisible); + } + }, + + menuCallback_reSkin:function(sender){ + var index = sender.getUserData(); + if(index < SkinType.MAX_TYPE){ + var curr = (this._skins[index].indexOf(this._curSkin[index]) + 1) % this._skins[index].length; + this._curSkin[index] = this._skins[index][curr]; + } + this.applyCurSkin(); + } + }); +})(); + +var Sprite3DWithOBBPerformanceTest = Sprite3DTestDemo.extend({ + _title:"OBB Collison Performance Test", + _subtitle:"", + _drawOBB:null, + _drawDebug:null, + _sprite:null, + _moveAction:null, + _obbt:null, + _obb:[], + _labelCubeCount:null, + _targetObbIndex:-1, + + ctor:function(){ + this._super(); + + cc.eventManager.addListener({ + event:cc.EventListener.TOUCH_ALL_AT_ONCE, + onTouchesBegan:this.onTouchesBegan.bind(this), + onTouchesMoved:this.onTouchesMoved.bind(this) + }, this); + + this.initDrawBox(); + this.addSprite(); + + var s = cc.winSize; + cc.MenuItemFont.setFontName("Arial"); + cc.MenuItemFont.setFontSize(65); + var decrease = new cc.MenuItemFont(" - ", this.delOBBCallback, this); + decrease.setColor(cc.color(0, 200, 20)); + var increase = new cc.MenuItemFont(" + ", this.addOBBCallback, this); + increase.setColor(cc.color(0, 200, 20)); + + var menu = new cc.Menu(decrease, increase); + menu.alignItemsHorizontally(); + menu.setPosition(s.width / 2, s.height - 65); + this.addChild(menu, 1); + + this._labelCubeCount = new cc.LabelTTF("0 cubes", "Arial", 30); + this._labelCubeCount.setColor(cc.color(0, 200, 20)); + this._labelCubeCount.setPosition(cc.p(s.width / 2, s.height - 90)); + this.addChild(this._labelCubeCount); + + this.addOBBCallback(); + this.scheduleUpdate(); + }, + + onExit:function(){ + this._super(); + this._moveAction.release(); + }, + + update:function(){ + if(this._drawDebug !== undefined){ + this._drawDebug.clear(); + + var mat = this._sprite.getNodeToWorldTransform3D(); + this._obbt.xAxis.x = mat[0]; + this._obbt.xAxis.y = mat[1]; + this._obbt.xAxis.z = mat[2]; + this._obbt.xAxis.normalize(); + + this._obbt.yAxis.x = mat[4]; + this._obbt.yAxis.y = mat[5]; + this._obbt.yAxis.z = mat[6]; + this._obbt.yAxis.normalize(); + + this._obbt.zAxis.x = -mat[8]; + this._obbt.zAxis.y = -mat[9]; + this._obbt.zAxis.z = -mat[10]; + this._obbt.zAxis.normalize(); + + this._obbt.center = this._sprite.getPosition3D(); + + var corners = cc.math.obbGetCorners(this._obbt); + this._drawDebug.drawCube(corners, cc.color(0, 0, 255)); + } + + if(this._obb.length > 0){ + this._drawOBB.clear(); + for(var i = 0; i < this._obb.length; ++i){ + corners = cc.math.obbGetCorners(this._obb[i]); + this._drawOBB.drawCube(corners, cc.math.obbIntersectsObb(this._obbt, this._obb[i]) ? cc.color(255, 0, 0) : cc.color(0, 255, 0)); + } + } + }, + + initDrawBox:function(){ + this._drawOBB = new cc.DrawNode3D(); + this.addChild(this._drawOBB); + }, + + addSprite:function(){ + var sprite = new jsb.Sprite3D("Sprite3DTest/tortoise.c3b"); + sprite.setScale(0.1); + var s = cc.winSize; + sprite.setPosition(cc.p(s.width * 4 / 5, s.height / 2)); + this.addChild(sprite); + + this._sprite = sprite; + var animation = jsb.Animation3D.create("Sprite3DTest/tortoise.c3b"); + if(animation){ + var animate = jsb.Animate3D.create(animation); + sprite.runAction(cc.repeatForever(animate)); + } + + this._moveAction = cc.moveBy(4, cc.p(-s.width * 3 / 5, 0)); + this._moveAction.retain(); + var seq = cc.sequence(this._moveAction, cc.callFunc(this.reachEndCallBack, this)); + seq.setTag(100); + sprite.runAction(seq); + + var aabb = sprite.getAABB(); + this._obbt = cc.math.obb(aabb); + + this._drawDebug = new cc.DrawNode3D(); + this.addChild(this._drawDebug); + }, + + reachEndCallBack:function(){ + var sprite = this._sprite; + sprite.stopActionByTag(100); + var inverse = this._moveAction.reverse(); + inverse.retain(); + this._moveAction.release(); + this._moveAction = inverse; + var rot = cc.rotateBy(1, {x : 0, y : 180, z : 0}); + var seq = cc.sequence(rot, this._moveAction, cc.callFunc(this.reachEndCallBack, this)); + seq.setTag(100); + sprite.runAction(seq); + }, + + addOBBCallback:function(sender){ + var s = cc.winSize; + for(var i = 0; i < 10; ++i){ + var randompos = cc.p(Math.random() * s.width, Math.random() * s.height); + var aabb = cc.math.aabb(cc.math.vec3(-10, -10, -10), cc.math.vec3(10, 10, 10)); + var obb = cc.math.obb(aabb); + obb.center = cc.math.vec3(randompos.x, randompos.y, 0); + this._obb.push(obb); + } + this._labelCubeCount.setString(this._obb.length + " cubes"); + }, + + delOBBCallback:function(sender){ + if(this._obb.length >= 10){ + this._obb.splice(0, 10); + this._drawOBB.clear(); + } + this._labelCubeCount.setString(this._obb.length + " cubes"); + }, + + onTouchesBegan:function(touches, event){ + var location = touches[0].getLocationInView(); + var ray = this.calculateRayByLocationInView(location); + for(var j = 0; j < this._obb.length; ++j){ + if(cc.math.rayIntersectsObb(ray, this._obb[j])){ + this._targetObbIndex = j; + return; + } + } + this._targetObbIndex = -1; + }, + + onTouchesMoved:function(touches, event){ + if(this._targetObbIndex >= 0){ + var location = touches[0].getLocation(); + this._obb[this._targetObbIndex].center = cc.math.vec3(location.x, location.y, 0); + } + }, + + calculateRayByLocationInView:function(location){ + var camera = cc.Camera.getDefaultCamera(); + + var src = cc.math.vec3(location.x, location.y, -1); + var nearPoint = camera.unproject(src); + + src = cc.math.vec3(location.x, location.y, 1); + var farPoint = camera.unproject(src); + + var direction = cc.math.vec3(farPoint.x - nearPoint.x, farPoint.y - nearPoint.y, farPoint.z - nearPoint.z); + direction.normalize(); + + return cc.math.ray(nearPoint, direction); + } +}); + +var Sprite3DMirrorTest = Sprite3DTestDemo.extend({ + _title:"Sprite3D Mirror Test", + _subtitle:"", + + ctor:function(){ + this._super(); + + var s = cc.winSize; + this.addNewSpriteWithCoords(cc.p(s.width / 2, s.height / 2)); + }, + + addNewSpriteWithCoords:function(position){ + var fileName = "Sprite3DTest/orc.c3b"; + var sprite = new jsb.Sprite3D("Sprite3DTest/orc.c3b"); + sprite.setScale(5); + sprite.setRotation3D(cc.math.vec3(0, 180, 0)); + this.addChild(sprite); + sprite.setPosition(cc.p(position.x - 80, position.y)); + + //test attach + var sp = new jsb.Sprite3D("Sprite3DTest/axe.c3b"); + sprite.getAttachNode("Bip001 R Hand").addChild(sp); + + var animation = jsb.Animation3D.create(fileName); + if(animation){ + var animate = jsb.Animate3D.create(animation); + sprite.runAction(cc.repeatForever(animate)); + } + + //create mirror Sprite3D + sprite = new jsb.Sprite3D(fileName); + sprite.setScale(5); + sprite.setScaleX(-5); + sprite.setCullFace(gl.FRONT); + sprite.setRotation3D(cc.math.vec3(0, 180, 0)); + this.addChild(sprite); + sprite.setPosition(cc.p(position.x + 80, position.y)); + + //test attach + sp = new jsb.Sprite3D("Sprite3DTest/axe.c3b"); + sprite.getAttachNode("Bip001 R Hand").addChild(sp); + + var animation = jsb.Animation3D.create(fileName); + if(animation){ + var animate = jsb.Animate3D.create(animation); + sprite.runAction(cc.repeatForever(animate)); + } + } + +}); + +var QuaternionTest = Sprite3DTestDemo.extend({ + _title:"Test Rotation With Quaternion", + _subtitle:"", + _sprite:null, + _radius:100, + _accAngle:0, + + ctor:function(){ + this._super(); + + var sprite = new jsb.Sprite3D("Sprite3DTest/tortoise.c3b"); + sprite.setScale(0.1); + var s = cc.winSize; + sprite.setPosition(cc.p(s.width/2 + this._radius * Math.cos(this._accAngle), s.height / 2 + this._radius * Math.sin(this._accAngle))); + this.addChild(sprite); + this._sprite = sprite; + var animation = jsb.Animation3D.create("Sprite3DTest/tortoise.c3b"); + if(animation){ + var animate = jsb.Animate3D.create(animation, 0, 1.933); + sprite.runAction(cc.repeatForever(animate)); + } + + this.scheduleUpdate(); + }, + + update:function(dt){ + this._accAngle += dt * cc.degreesToRadians(90); + if(this._accAngle >= 2 * Math.PI) + this._accAngle -= 2 * Math.PI; + + var s = cc.winSize; + this._sprite.setPosition(cc.p(s.width / 2 + this._radius * Math.cos(this._accAngle), s.height / 2 + this._radius * Math.sin(this._accAngle))); + + var quat = cc.math.quaternion(cc.math.vec3(0, 0, 1), this._accAngle - Math.PI * 0.5); + this._sprite.setRotationQuat(quat); + } +}); + +var Sprite3DEmptyTest = Sprite3DTestDemo.extend({ + _title:"Testing Sprite3D Container", + _subtitle:"Sprite3D can act as containers for 2D objects", + + ctor:function(){ + this._super(); + + var s = new jsb.Sprite3D(); + s.setNormalizedPosition(cc.p(0.5, 0.5)); + var l = new cc.LabelTTF("Test"); + s.addChild(l); + this.addChild(s); + } +}); + +var Sprite3DForceDepthTest = Sprite3DTestDemo.extend({ + _title:"Force Depth Write Error Test", + _subtitle:"Ship should always appear behind orc", + + ctor:function(){ + this._super(); + + var orc = new jsb.Sprite3D("Sprite3DTest/orc.c3b"); + orc.setScale(5); + orc.setNormalizedPosition(cc.p(0.5, 0.3)); + // orc.setPositionZ(40); + orc.setVertexZ(40); + orc.setRotation3D(cc.math.vec3(0, 180, 0)); + orc.setGlobalZOrder(-1); + + this.addChild(orc); + + var ship = new jsb.Sprite3D("Sprite3DTest/boss1.obj"); + ship.setScale(5); + ship.setTexture("Sprite3DTest/boss.png"); + ship.setNormalizedPosition(cc.p(0.5, 0.5)); + ship.setRotation3D(cc.math.vec3(90, 0, 0)); + ship.setForceDepthWrite(true); + + this.addChild(ship); + } +}); + +var UseCaseSprite3D1 = Sprite3DTestDemo.extend({ + _title:"Use Case For 2D + 3D", + _subtitle:"3d transparent sprite + 2d sprite", + _accAngle:0, + + ctor:function(){ + this._super(); + + var s = cc.winSize; + //setup camera + var camera = cc.Camera.createPerspective(40, s.width/s.height, 0.01, 1000); + camera.setCameraFlag(cc.CameraFlag.USER1); + camera.setPosition3D(cc.math.vec3(0, 30, 100)); + camera.lookAt(cc.math.vec3(0, 0, 0)); + this.addChild(camera); + + var sprite = new jsb.Sprite3D("Sprite3DTest/girl.c3b"); + sprite.setScale(0.15); + var animation = jsb.Animation3D.create("Sprite3DTest/girl.c3b"); + if(animation){ + var animate = jsb.Animate3D.create(animation); + sprite.runAction(cc.repeatForever(animate)); + } + + var circleBack = new jsb.Sprite3D(); + var circle = new cc.Sprite("Sprite3DTest/circle.png"); + circleBack.setScale(0.5); + circleBack.addChild(circle); + circle.runAction(cc.rotateBy(3, cc.math.vec3(0, 0, 360)).repeatForever()); + + circleBack.setRotation3D(cc.math.vec3(90, 0, 0)); + + var pos = sprite.getPosition3D(); + circleBack.setPosition3D(cc.math.vec3(pos.x, pos.y, pos.z-1)); + + sprite.setOpacity(250); + sprite.setCameraMask(2); + circleBack.setCameraMask(2); + sprite.setTag(3); + circleBack.setTag(2); + + this.addChild(sprite); + this.addChild(circleBack); + + this.scheduleUpdate(); + this.update(0.1); + }, + + update:function(dt){ + this._accAngle += dt * cc.degreesToRadians(60); + + var radius = 30; + var x = Math.cos(this._accAngle) * radius; + var z = Math.sin(this._accAngle) * radius; + + var sprite = this.getChildByTag(3); + var circle = this.getChildByTag(2); + + sprite.setPositionX(x); + sprite.setVertexZ(z); + circle.setPositionX(x); + circle.setVertexZ(z); + } +}); + +var UseCaseSprite3D2 = Sprite3DTestDemo.extend({ + _title:"Use Case For 2D + 3D", + _subtitle:"ui - 3d - ui, last ui should on the top", + ctor:function(){ + this._super(); + + var s = cc.winSize; + //setup camera + var camera = cc.Camera.createPerspective(40, s.width/s.height, 0.01, 1000); + camera.setCameraFlag(cc.CameraFlag.USER1); + camera.setPosition3D(cc.math.vec3(0, 30, 100)); + camera.lookAt(cc.math.vec3(0, 0, 0)); + this.addChild(camera); + + var layer = new cc.LayerColor(cc.color(0, 0, 100, 255), s.width/2, s.height/2); + layer.setPosition(s.width/4, s.height/4); + layer.setGlobalZOrder(-1); + layer.setTag(101); + this.addChild(layer); + + var sprite = new jsb.Sprite3D("Sprite3DTest/girl.c3b"); + sprite.setScale(0.5); + var animation = jsb.Animation3D.create("Sprite3DTest/girl.c3b"); + if(animation){ + var animate = jsb.Animate3D.create(animation); + sprite.runAction(cc.repeatForever(animate)); + } + sprite.setPosition(s.width/4, s.height/4); + layer.addChild(sprite); + + var label1 = new cc.LabelTTF("Message", "Arial", 15); + var item1 = new cc.MenuItemLabel(label1, this.menuCallback_Message, this); + var label2 = new cc.LabelTTF("Message", "Arial", 15); + var item2 = new cc.MenuItemLabel(label2, this.menuCallback_Message, this); + + item1.setPosition(cc.p(s.width/2 - item1.getContentSize().width/2, s.height/2 - item1.getContentSize().height)); + item2.setPosition(cc.p(s.width/2 - item1.getContentSize().width/2, s.height/2 - item1.getContentSize().height * 2)); + + var menu = new cc.Menu(item1, item2); + menu.setPosition(cc.p(0, 0)); + layer.addChild(menu); + + }, + + menuCallback_Message:function(sender){ + var layer = this.getChildByTag(101); + var message = layer.getChildByTag(102); + if(message) + layer.removeChild(message); + else{ + // create a new message layer on the top + var s = layer.getContentSize(); + var messagelayer = new cc.LayerColor(cc.color(100, 100, 0, 255)); + messagelayer.setContentSize(cc.size(s.width/2, s.height/2)); + messagelayer.setPosition(cc.p(s.width/4, s.height/4)); + var label = new cc.LabelTTF("This Message Layer \n Should Be On Top"); + label.setPosition(cc.p(s.width/4, s.height/4)); + messagelayer.addChild(label); + messagelayer.setTag(102); + layer.addChild(messagelayer); + } + + } +}); + +var Sprite3DEffectTest = Sprite3DTestDemo.extend({ + _title:"Testing Sprite3D", + _subtitle:"Sprite3d with effects", + + ctor:function(){ + this._super(); + + cc.eventManager.addListener({ + event:cc.EventListener.TOUCH_ALL_AT_ONCE, + onTouchesBegan:this.onTouchesBegan.bind(this) + }, this); + + this.addNewSpriteWithCoords(cc.p(cc.winSize.width/2, cc.winSize.height/2)); + }, + + addNewSpriteWithCoords:function(position){ + var sprite = new cc.EffectSprite3D("Sprite3DTest/boss1.obj", "Sprite3DTest/boss.png"); + var effect = new cc.Effect3DOutline(); + effect.setOutlineColor(cc.math.vec3(1, 0, 0)); + effect.setOutlineWidth(0.01); + sprite.addEffect(effect, -1); + + var effect2 = new cc.Effect3DOutline(); + effect2.setOutlineColor(cc.math.vec3(1, 1, 0)); + effect2.setOutlineWidth(0.02); + sprite.addEffect(effect2, -2); + + sprite.setScale(6); + this.addChild(sprite); + sprite.setPosition(position); + + var action; + var random = Math.random(); + if(random < 0.2) + action = cc.scaleBy(3, 2); + else if(random < 0.4) + action = cc.rotateBy(3, 360); + else if(random < 0.6) + action = cc.blink(1, 3); + else if(random < 0.8) + action = cc.tintBy(2, 0, -255, -255); + else + action = cc.fadeOut(2); + + var action_back = action.reverse(); + var seq = cc.sequence(action, action_back); + + sprite.runAction(seq.repeatForever()); + }, + + onTouchesBegan:function(touches, event){ + for(var i = 0; i < touches.length; ++i){ + var location = touches[i].getLocation(); + this.addNewSpriteWithCoords(location); + } + } +}); + +var Sprite3DWithSkinOutlineTest = Sprite3DTestDemo.extend({ + _title:"Testing Sprite3D for skinned outline", + _subtitle:"Tap screen to add more sprite3D", + + ctor:function(){ + this._super(); + + cc.eventManager.addListener({ + event:cc.EventListener.TOUCH_ALL_AT_ONCE, + onTouchesBegan:this.onTouchesBegan.bind(this) + }, this); + + this.addNewSpriteWithCoords(cc.p(cc.winSize.width/2, cc.winSize.height/2)); + }, + + addNewSpriteWithCoords:function(p){ + var sprite = new cc.EffectSprite3D("Sprite3DTest/orc.c3b"); + sprite.setScale(3); + sprite.setRotation3D(cc.math.vec3(0, 180, 0)); + this.addChild(sprite); + sprite.setPosition(p); + + var effect = new cc.Effect3DOutline(); + effect.setOutlineColor(cc.math.vec3(1, 0, 0)); + effect.setOutlineWidth(0.01); + sprite.addEffect(effect, -1); + + var effect2 = new cc.Effect3DOutline(); + effect2.setOutlineColor(cc.math.vec3(1, 1, 0)); + effect2.setOutlineWidth(0.02); + sprite.addEffect(effect2, -2); + + var animation = jsb.Animation3D.create("Sprite3DTest/orc.c3b"); + if(animation){ + var animate = jsb.Animate3D.create(animation); + var inverse = Math.random() < 0.33 ? true : false; + + var rand2 = Math.random(); + var speed = 1.0; + if(rand2 < 0.33) + speed = animate.getSpeed() + Math.random(); + else if(rand2 < 0.66) + spped = animate.getSpeed() - 0.5 * Math.random(); + + animate.setSpeed(inverse ? -speed : speed); + sprite.runAction(new cc.RepeatForever(animate)); + } + }, + + onTouchesBegan:function(touches, event){ + for(var i = 0; i < touches.length; ++i){ + var location = touches[i].getLocation(); + this.addNewSpriteWithCoords(location); + } + } +}); + +var Sprite3DLightMapTest = Sprite3DTestDemo.extend({ + _title:"light map test", + _subtitle:"drag the screen to move around", + _camera:null, + + ctor:function(){ + this._super(); + + //the assets are from the OpenVR demo + //get the visible size. + var visibleSize = cc.director.getVisibleSize(); + this._camera = cc.Camera.createPerspective(60, visibleSize.width/visibleSize.height, 0.1, 200); + this._camera.setCameraFlag(cc.CameraFlag.USER1); + this._camera.setPosition3D(cc.math.vec3(0, 25, 15)); + this._camera.setRotation3D(cc.math.vec3(-35, 0, 0)); + + var LightMapScene = new jsb.Sprite3D("Sprite3DTest/LightMapScene.c3b"); + LightMapScene.setScale(0.1); + this.addChild(LightMapScene); + this.addChild(this._camera); + this.setCameraMask(2); + + //add a point light + var light = jsb.PointLight.create(cc.math.vec3(35, 75, -20.5), cc.color(255, 255, 255), 150); + this.addChild(light); + //set the ambient light + var ambient = jsb.AmbientLight.create(cc.color(55, 55, 55)); + this.addChild(ambient); + + //create a listener + cc.eventManager.addListener({ + event:cc.EventListener.TOUCH_ALL_AT_ONCE, + onTouchesMoved:this.onTouchesMoved.bind(this) + }, this); + }, + + onTouchesMoved:function(touches, event){ + if(touches.length === 1){ + var dt = cc.director.getDeltaTime(); + var touch = touches[0]; + var location = touch.getLocation(); + var previousLocation = touch.getPreviousLocation(); + var newPos = cc.p(previousLocation.x - location.x, previousLocation.y - location.y); + + var m = this._camera.getNodeToWorldTransform3D(); + var cameraDir = cc.math.vec3(-m[8], -m[9], -m[10]); + cameraDir.normalize(); + cameraDir.y = 0; + + var cameraRightDir = cc.math.vec3(m[0], m[1], m[2]); + cameraRightDir.normalize(); + cameraRightDir.y = 0; + + var cameraPos = this._camera.getPosition3D(); + cameraPos.x += cameraDir.x * newPos.y * dt + cameraRightDir.x * newPos.x * dt; + cameraPos.y += cameraDir.y * newPos.y * dt + cameraRightDir.y * newPos.x * dt; + cameraPos.z += cameraDir.z * newPos.y * dt + cameraRightDir.z * newPos.x * dt; + this._camera.setPosition3D(cameraPos); + } + } +}); + +var Sprite3DUVAnimationTest = Sprite3DTestDemo.extend({ + _title:"Testing UV Animation", + _subtitle:"", + _cylinder_texture_offset:0, + _shining_duraion:0, + _state:null, + fade_in:true, + + ctor:function(){ + this._super(); + + var visibleSize = cc.director.getVisibleSize(); + //use custom camera + var camera = cc.Camera.createPerspective(60, visibleSize.width/visibleSize.height, 0.1, 200); + camera.setCameraFlag(cc.CameraFlag.USER1); + this.addChild(camera); + this.setCameraMask(2); + + //create cylinder + var cylinder = new jsb.Sprite3D("Sprite3DTest/cylinder.c3b"); + this.addChild(cylinder); + cylinder.setScale(3); + cylinder.setPosition(visibleSize.width/2, visibleSize.height/2); + cylinder.setRotation3D(cc.math.vec3(-90, 0, 0)); + + //create and set our custom shader + var shader = new cc.GLProgram("Sprite3DTest/cylinder.vert","Sprite3DTest/cylinder.frag"); + this._state = cc.GLProgramState.create(shader); + cylinder.setGLProgramState(this._state); + + this._state.setUniformFloat("offset", this._cylinder_texture_offset); + this._state.setUniformFloat("duration", this._shining_duraion); + + //pass mesh's attribute to shader + var offset = 0; + var attributeCount = cylinder.getMesh().getMeshVertexAttribCount(); + for(var i = 0; i < attributeCount; ++i){ + var meshattribute = cylinder.getMesh().getMeshVertexAttribute(i); + this._state.setVertexAttribPointer(cc.attributeNames[meshattribute.vertexAttrib], + meshattribute.size, + meshattribute.type, + gl.FALSE, + cylinder.getMesh().getVertexSizeInBytes(), + offset); + offset += meshattribute.attribSizeBytes; + } + + //create the second texture for cylinder + var shining_texture = cc.textureCache.addImage("Sprite3DTest/caustics.png"); + shining_texture.setTexParameters(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT); + //pass the texture sampler to our custom shader + this._state.setUniformTexture("caustics", shining_texture); + + this.scheduleUpdate(); + }, + + update:function(dt){ + //callback function to update cylinder's texcoord + this._cylinder_texture_offset += 0.3 * dt; + this._cylinder_texture_offset = this._cylinder_texture_offset > 1 ? 0 : this._cylinder_texture_offset; + + if(this.fade_in){ + this._shining_duraion += 0.5 * dt; + if(this._shining_duraion > 1) + this.fade_in = false; + }else{ + this._shining_duraion -= 0.5 * dt; + if(this._shining_duraion < 0) + this.fade_in = true; + } + + //pass the result to shader + this._state.setUniformFloat("offset", this._cylinder_texture_offset); + this._state.setUniformFloat("duration", this._shining_duraion); + } +}); + +var State = { + State_None : 0, + State_Idle : 0x01, + State_Move : 0x02, + State_Rotate : 0x04, + State_Speak : 0x08, + State_MeleeAttack : 0x10, + State_RemoteAttack : 0x20, + State_Attack : 0x40 +}; + +var Sprite3DFakeShadowTest = Sprite3DTestDemo.extend({ + _title:"fake shadow effect", + _subtitle:"touch the screen to move around", + _camera:null, + _plane:null, + _orc:null, + _targetPos:null, + _curState:0, + + ctor:function(){ + this._super(); + + cc.eventManager.addListener({ + event:cc.EventListener.TOUCH_ALL_AT_ONCE, + onTouchesEnded:this.onTouchesEnded.bind(this) + }, this); + + var visibleSize = cc.director.getVisibleSize(); + var s = cc.winSize; + + this._orc = new jsb.Sprite3D("Sprite3DTest/orc.c3b"); + this._orc.setScale(0.2); + this._orc.setRotation3D(cc.math.vec3(0, 180, 0)); + this._orc.setPosition3D(cc.math.vec3(0, 0, 0)); + + this._targetPos = this._orc.getPosition3D(); + this.addChild(this._orc); + + //create a plane + this._plane = new jsb.Sprite3D("Sprite3DTest/plane.c3t"); + this._plane.setRotation3D(cc.math.vec3(90, 0, 0)); + this.addChild(this._plane); + + //use a custom shader + var shader = new cc.GLProgram("Sprite3DTest/simple_shadow.vert", "Sprite3DTest/simple_shadow.frag"); + var state = cc.GLProgramState.create(shader); + this._plane.setGLProgramState(state); + + //pass mesh's attribute to shader + var offset = 0; + var attributeCount = this._plane.getMesh().getMeshVertexAttribCount(); + for(var i = 0; i < attributeCount; ++i){ + var meshattribute = this._plane.getMesh().getMeshVertexAttribute(i); + state.setVertexAttribPointer(cc.attributeNames[meshattribute.vertexAttrib], + meshattribute.size, + meshattribute.type, + gl.FALSE, + this._plane.getMesh().getVertexSizeInBytes(), + offset); + offset += meshattribute.attribSizeBytes; + } + state.setUniformMat4("u_model_matrix", this._plane.getNodeToWorldTransform3D()); + + //create shadow texture + var shadowTexture = cc.textureCache.addImage("Sprite3DTest/shadowCircle.png"); + shadowTexture.setTexParameters(gl.LINEAR, gl.LINEAR, gl.CLAMP_TO_EDGE, gl.CLAMP_TO_EDGE); + state.setUniformTexture("u_shadowTexture", shadowTexture); + state.setUniformVec3("u_target_pos", this._targetPos); + + this._camera = cc.Camera.createPerspective(60, s.width/s.height, 1, 1000); + this._camera.setCameraFlag(cc.CameraFlag.USER1); + this._camera.setPosition3D(cc.math.vec3(0, 20, 25)); + this._camera.lookAt(cc.math.vec3(0, 0, 0)); + this.addChild(this._camera); + this.setCameraMask(2); + + this.scheduleUpdate(); + }, + + update:function(dt){ + this.updateState(dt) + + if(this.isState(State.State_Move)){ + this.move3D(dt); + if(this.isState(State.State_Rotate)){ + var curPos = this._orc.getPosition3D(); + var newFaceDir = cc.math.vec3(this._targetPos.x - curPos.x, this._targetPos.y - curPos.y, this._targetPos.z - curPos.z); + newFaceDir.y = 0; + newFaceDir.normalize(); + + var m = this._orc.getNodeToWorldTransform3D(); + var up = cc.math.vec3(m[4], m[5], m[6]); + up.normalize(); + + var right = cc.math.vec3Cross(cc.math.vec3(-newFaceDir.x, -newFaceDir.y, -newFaceDir.z), up); + right.normalize(); + + var mat = [right.x, right.y, right.z, 0, + up.x, up.y, up.z, 0, + newFaceDir.x, newFaceDir.y, newFaceDir.z, 0, + 0, 0, 0, 1]; + + this._orc.setAdditionalTransform(mat); + } + } + }, + + updateState:function(dt){ + if(!this._targetPos) + return; + var curPos = this._orc.getPosition3D(); + var m = this._orc.getNodeToWorldTransform3D(); + var curFaceDir = cc.math.vec3(m[8], m[9], m[10]); + curFaceDir.normalize(); + var newFaceDir = cc.math.vec3(this._targetPos.x - curPos.x, this._targetPos.y - curPos.y, this._targetPos.z - curPos.z); + newFaceDir.y = 0; + newFaceDir.normalize(); + var cosAngle = Math.abs(cc.math.vec3Dot(curFaceDir, newFaceDir) - 1); + + var dx = curPos.x - this._targetPos.x, + dy = curPos.y - this._targetPos.y, + dz = curPos.z - this._targetPos.z; + var dist = dx * dx + dy * dy + dz * dz; + + if(dist <= 4){ + if(cosAngle <= 0.01) + this._curState = State.State_Idle; + else + this._curState = State.State_Rotate; + }else{ + if(cosAngle > 0.01) + this._curState = State.State_Rotate | State.State_Move; + else + this._curState = State.State_Move; + } + }, + + isState:function(bit){ + return (this._curState & bit) == bit; + }, + + move3D:function(dt){ + if(!this._targetPos) + return; + var curPos = this._orc.getPosition3D(); + var newFaceDir = cc.math.vec3(this._targetPos.x - curPos.x, this._targetPos.y - curPos.y, this._targetPos.z - curPos.z); + newFaceDir.y = 0; + newFaceDir.normalize(); + var offset = cc.math.vec3(newFaceDir.x * 25 * dt, newFaceDir.y * 25 * dt, newFaceDir.z * 25 * dt); + curPos.x += offset.x; + curPos.y += offset.y; + curPos.z += offset.z; + this._orc.setPosition3D(curPos); + //pass the newest orc position + this._plane.getGLProgramState().setUniformVec3("u_target_pos",curPos); + }, + + onTouchesEnded:function(touches, event){ + var touch = touches[0]; + var location = touch.getLocationInView(); + if(this._camera !== null){ + var nearP = cc.math.vec3(location.x, location.y, -1); + var farP = cc.math.vec3(location.x, location.y, 1); + + nearP = this._camera.unproject(nearP); + farP = this._camera.unproject(farP); + + var dir = cc.math.vec3(farP.x-nearP.x, farP.y-nearP.y, farP.z-nearP.z); + var ndd = dir.y; // (0, 1, 0) * dir + var ndo = nearP.y; // (0, 1, 0) * nearP + var dist = - ndo / ndd; + var p = cc.math.vec3(nearP.x+dist*dir.x, nearP.y+dist*dir.y, nearP.z+dist*dir.z); + + if(p.x > 100) + p.x = 100; + if(p.x < -100) + p.x = -100; + if(p.z > 100) + p.z = 100 + if(p.z < -100) + p.z = -100; + + this._targetPos = p; + } + } +}); + +var Sprite3DBasicToonShaderTest = Sprite3DTestDemo.extend({ + _title:"basic toon shader test", + _subtitle:"", + + ctor:function(){ + this._super(); + + var camera = cc.Camera.createPerspective(60, cc.winSize.width/cc.winSize.height, 1, 1000); + camera.setCameraFlag(cc.CameraFlag.USER1); + this.addChild(camera); + this.setCameraMask(2); + + //create a teapot + var teapot = new jsb.Sprite3D("Sprite3DTest/teapot.c3b"); + //create and set out custom shader + var shader = new cc.GLProgram("Sprite3DTest/toon.vert", "Sprite3DTest/toon.frag"); + var state = cc.GLProgramState.create(shader); + teapot.setGLProgramState(state); + teapot.setPosition3D(cc.math.vec3(cc.winSize.width/2, cc.winSize.height/2, -20)); + teapot.setRotation3D(cc.math.vec3(-90, 180, 0)); + teapot.setScale(10); + teapot.runAction(cc.rotateBy(1.5, cc.math.vec3(0, 30, 0)).repeatForever()); + this.addChild(teapot); + + //pass mesh's attribute to shader + var offset = 0; + var attributeCount = teapot.getMesh().getMeshVertexAttribCount(); + for(var i = 0; i < attributeCount; ++i){ + var meshattribute = teapot.getMesh().getMeshVertexAttribute(i); + state.setVertexAttribPointer(cc.attributeNames[meshattribute.vertexAttrib], + meshattribute.size, + meshattribute.type, + gl.FALSE, + teapot.getMesh().getVertexSizeInBytes(), + offset); + offset += meshattribute.attribSizeBytes; + } + } +}); + +// +// Flow control +// +var arrayOfSprite3DTest = [ + Sprite3DBasicTest, + Sprite3DHitTest, + AsyncLoadSprite3DTest, + Sprite3DWithSkinTest, + Animate3DTest, + AttachmentTest, + Sprite3DReskinTest, + Sprite3DWithOBBPerformanceTest, + Sprite3DMirrorTest, + QuaternionTest, + Sprite3DEmptyTest, + Sprite3DForceDepthTest, + UseCaseSprite3D1, + UseCaseSprite3D2 +]; + +// 3DEffect use custom shader which is not supported on WP8/WinRT yet. +if (cc.sys.os !== cc.sys.OS_WP8 || cc.sys.os !== cc.sys.OS_WINRT) { + arrayOfSprite3DTest = arrayOfSprite3DTest.concat([ + Sprite3DEffectTest, + Sprite3DWithSkinOutlineTest, + Sprite3DLightMapTest, + Sprite3DUVAnimationTest, + Sprite3DFakeShadowTest, + Sprite3DBasicToonShaderTest, + ]); +} + +var nextSprite3DTest = function () { + Sprite3DTestIdx++; + Sprite3DTestIdx = Sprite3DTestIdx % arrayOfSprite3DTest.length; + + if(window.sideIndexBar){ + Sprite3DTestIdx = window.sideIndexBar.changeTest(Sprite3DTestIdx, 36); + } + + return new arrayOfSprite3DTest[Sprite3DTestIdx ](); +}; +var previousSprite3DTest = function () { + Sprite3DTestIdx--; + if (Sprite3DTestIdx < 0) + Sprite3DTestIdx += arrayOfSprite3DTest.length; + + if(window.sideIndexBar){ + Sprite3DTestIdx = window.sideIndexBar.changeTest(Sprite3DTestIdx, 36); + } + + return new arrayOfSprite3DTest[Sprite3DTestIdx ](); +}; +var restartSprite3DTest = function () { + return new arrayOfSprite3DTest[Sprite3DTestIdx ](); +}; diff --git a/samples/js-tests/src/SpriteTest/SpriteTest.js b/samples/js-tests/src/SpriteTest/SpriteTest.js index ca3c8ec82d..3909bd49bc 100644 --- a/samples/js-tests/src/SpriteTest/SpriteTest.js +++ b/samples/js-tests/src/SpriteTest/SpriteTest.js @@ -4421,12 +4421,13 @@ var AnimationCacheTest = SpriteTestDemo.extend({ // create animation "dance" // var animFrames = []; - var frame; + var frame, animFrame; var str = ""; for (var i = 1; i < 15; i++) { str = "grossini_dance_" + (i < 10 ? ("0" + i) : i) + ".png"; frame = spriteFrameCache.getSpriteFrame(str); - animFrames.push(frame); + animFrame = new cc.AnimationFrame(frame, 1); + animFrames.push(animFrame); } var animation = new cc.Animation(animFrames, 0.2); @@ -5178,11 +5179,11 @@ var TextureColorCacheIssue = SpriteTestDemo.extend({ spriteFrameCache.addSpriteFrames(s_tcc_issue_1_plist, s_tcc_issue_1); spriteFrameCache.addSpriteFrames(s_tcc_issue_2_plist, s_tcc_issue_2); - var grossini = new cc.Sprite('#grossini_dance_01.png'); + var grossini = new cc.Sprite('#tcc_grossini_dance_01.png'); grossini.x = winSize.width / 3; grossini.y = winSize.height / 2; - var sister = new cc.Sprite('#grossinis_sister1.png'); + var sister = new cc.Sprite('#tcc_grossinis_sister1.png'); sister.x = winSize.width / 3 * 2; sister.y = winSize.height / 2; @@ -5229,11 +5230,11 @@ var TextureColorCacheIssue2 = SpriteTestDemo.extend({ spriteFrameCache.addSpriteFrames(s_tcc_issue_1_plist, s_tcc_issue_1); spriteFrameCache.addSpriteFrames(s_tcc_issue_2_plist, s_tcc_issue_2); - var grossini = new cc.Sprite('#grossini_dance_01.png'); + var grossini = new cc.Sprite('#tcc_grossini_dance_01.png'); grossini.x = winSize.width / 3; grossini.y = winSize.height / 2; - var sister = new cc.Sprite('#grossinis_sister1.png'); + var sister = new cc.Sprite('#tcc_grossinis_sister1.png'); sister.x = winSize.width / 3 * 2; sister.y = winSize.height / 2; @@ -5328,6 +5329,73 @@ var SpriteWithRepeatingTexture = SpriteTestDemo.extend({ } }); +var SpriteBlendFuncTest = SpriteTestDemo.extend({ + //webgl only + _title: "", //Sprite BlendFunc test + _subtitle: "", + + ctor: function(){ + //----start59----ctor + this._super(); + + var destFactors = [gl.ZERO, gl.ONE, gl.SRC_COLOR, gl.ONE_MINUS_SRC_COLOR, gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA], + srcFactors = [gl.ZERO, gl.ONE, gl.DST_COLOR, gl.ONE_MINUS_DST_COLOR, gl.DST_ALPHA, gl.ONE_MINUS_DST_ALPHA]; + var destTitles = ["ZERO", "ONE", "SRC_COLOR", "ONE_MINUS_SRC_COLOR", "SRC_ALPHA", "ONE_MINUS_SRC_ALPHA"], + srcTitles = ["ZERO", "ONE", "DST_COLOR", "ONE_MINUS_DST_COLOR", "SRC_ALPHA", "ONE_MINUS_SRC_ALPHA"]; + + var sourceImg = "res/Images/dot.png", destImg = "res/Images/wood.jpg"; + var sourceTexture = cc.textureCache.addImage(sourceImg); + sourceTexture.handleLoadedTexture(true); + var sourceSprite = new cc.Sprite(sourceImg); + var destSprite = new cc.Sprite(destImg); + sourceSprite.setScale(0.8); + destSprite.setScale(0.8); + sourceSprite.setPosition(60,400); + destSprite.setPosition(120,400); + this.addChild(sourceSprite); + this.addChild(destSprite); + + var i, j, title, fontSize, titleLabel; + for(i = 0; i < destTitles.length; i++){ + title = destTitles[i]; + fontSize = (title.length > 10) ? 14 : 18; + titleLabel = new cc.LabelTTF(title, "Arial", fontSize); + titleLabel.setAnchorPoint(0, 0.5); + titleLabel.setPosition(0, 355 - 60 * i); + this.addChild(titleLabel); + } + + for(i = 0; i < srcTitles.length; i++){ + title = srcTitles[i]; + fontSize = (title.length > 10) ? 14 : 18; + titleLabel = new cc.LabelTTF(title, "Arial", fontSize); + titleLabel.setAnchorPoint(0, 0.5); + titleLabel.setPosition(220 + i * 60, 390); + titleLabel.setRotation(-20); + this.addChild(titleLabel); + } + //j = 0; + for(i = 0; i < srcFactors.length; i++){ + for(j = 0; j < destFactors.length; j++){ + sourceSprite = new cc.Sprite(sourceImg); + //sourceSprite.setScale(0.8); + sourceSprite.setPosition( 220 + i * 60, 355 - j * 60); + sourceSprite.setBlendFunc(srcFactors[i], destFactors[j]); + + + destSprite = new cc.Sprite(destImg); + //destSprite.setScale(0.8); + destSprite.setPosition( 220 + i * 60, 355 - j * 60); +// destSprite.setBlendFunc(srcFactors[j], destFactors[i]); + + this.addChild(destSprite,1); + this.addChild(sourceSprite,2); + } + } + //----end59---- + } +}); + var SpriteTestScene = TestScene.extend({ runThisTest:function (num) { spriteTestIdx = (num || num == 0) ? (num - 1) : -1; @@ -5400,7 +5468,8 @@ var arrayOfSpriteTest = [ TextureColorCacheIssue, TextureColorCacheIssue2, TextureRotatedSpriteFrame, - SpriteWithRepeatingTexture + SpriteWithRepeatingTexture, + SpriteBlendFuncTest ]; var nextSpriteTest = function () { diff --git a/samples/js-tests/src/SysTest/SysTest.js b/samples/js-tests/src/SysTest/SysTest.js index 532cbd5413..bfa114b764 100644 --- a/samples/js-tests/src/SysTest/SysTest.js +++ b/samples/js-tests/src/SysTest/SysTest.js @@ -270,13 +270,40 @@ var RestartGameLayerTest = SysTestBase.extend({ } }); +var OpenURLTest = SysTestBase.extend({ + getTitle:function(){ + return "Open URL Test"; + }, + + ctor:function(){ + this._super(); + + var label = new cc.LabelTTF("Touch the screen to open\nthe cocos2d-x home page", "Arial", 22); + this.addChild(label); + label.setPosition(cc.winSize.width/2, cc.winSize.height/2); + + cc.eventManager.addListener({ + event: cc.EventListener.TOUCH_ONE_BY_ONE, + swallowTouches: true, + onTouchBegan: function(){ + return true; + }, + onTouchEnded: function(){ + cc.sys.openURL("http://www.cocos2d-x.org/"); + } + }, this); + + } +}); + // // Flow control // var arrayOfSysTest = [ LocalStorageTest, - CapabilitiesTest + CapabilitiesTest, + OpenURLTest ]; if (cc.sys.isNative && cc.sys.OS_WINDOWS != cc.sys.os) { diff --git a/samples/js-tests/src/TextureCacheTest/TextureCacheTest.js b/samples/js-tests/src/TextureCacheTest/TextureCacheTest.js index 4b68b9cc07..0b6b819726 100755 --- a/samples/js-tests/src/TextureCacheTest/TextureCacheTest.js +++ b/samples/js-tests/src/TextureCacheTest/TextureCacheTest.js @@ -74,26 +74,26 @@ var TextureCacheTest = TextureCacheTestBase.extend({ var texCache = cc.textureCache; // load textrues - texCache.addImage("res/Images/HelloWorld.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini_dance_01.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini_dance_02.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini_dance_03.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini_dance_04.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini_dance_05.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini_dance_06.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini_dance_07.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini_dance_08.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini_dance_09.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini_dance_10.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini_dance_11.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini_dance_12.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini_dance_13.png", this.loadingCallBack, this); - texCache.addImage("res/Images/grossini_dance_14.png", this.loadingCallBack, this); - texCache.addImage("res/Images/background1.png", this.loadingCallBack, this); - texCache.addImage("res/Images/background2.png", this.loadingCallBack, this); - texCache.addImage("res/Images/background3.png", this.loadingCallBack, this); - texCache.addImage("res/Images/blocks.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/HelloWorld.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini_dance_01.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini_dance_02.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini_dance_03.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini_dance_04.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini_dance_05.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini_dance_06.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini_dance_07.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini_dance_08.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini_dance_09.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini_dance_10.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini_dance_11.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini_dance_12.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini_dance_13.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/grossini_dance_14.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/background1.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/background2.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/background3.png", this.loadingCallBack, this); + texCache.addImageAsync("res/Images/blocks.png", this.loadingCallBack, this); }, addSprite:function () { var size = cc.director.getWinSize(); @@ -195,11 +195,17 @@ var RemoteTextureTest = TextureCacheTestBase.extend({ _sprite : null, onEnter:function () { this._super(); - this.scheduleOnce(this.startDownload, 0.1); + if('opengl' in cc.sys.capabilities && !cc.sys.isNative){ + var label = new cc.LabelTTF("Not support Loading texture from remote site on HTML5-WebGL", "Times New Roman", 28); + label.x = winSize.width / 2; + label.y = winSize.height / 2; + this.addChild(label, 100); + } else + this.scheduleOnce(this.startDownload, 0.1); }, startDownload: function() { - cc.textureCache.addImage(this._remoteTex, this.texLoaded, this); + cc.textureCache.addImageAsync(this._remoteTex, this.texLoaded, this); }, texLoaded: function(texture) { diff --git a/samples/js-tests/src/XHRTest/XHRArrayBufferTest.js b/samples/js-tests/src/XHRTest/XHRArrayBufferTest.js new file mode 100644 index 0000000000..e155546948 --- /dev/null +++ b/samples/js-tests/src/XHRTest/XHRArrayBufferTest.js @@ -0,0 +1,121 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + + 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. + ****************************************************************************/ + +//some utils functions +function ensureLeftAligned (label) { + label.anchorX = 0; + label.anchorY = 1; + label.textAlign = cc.TEXT_ALIGNMENT_LEFT; +} + +function streamXHREventsToLabel ( xhr, label, textbox, method ) { + // Simple events + ['loadstart', 'abort', 'error', 'load', 'loadend', 'timeout'].forEach(function (eventname) { + xhr["on" + eventname] = function () { + label.string += "\nEvent : " + eventname + } + }); + + // Special event + xhr.onreadystatechange = function () { + if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) { + var httpStatus = xhr.statusText; + var response = xhr.responseText.substring(0, 100) + "..."; + textbox.string = method + " Response (100 chars):\n" + textbox.string += response + label.string += "\nStatus: Got " + method + " response! " + httpStatus + } + } +} + + +var XHRArrayBufferTestScene = TestScene.extend({ + ctor:function () { + this._super(true); + var xhrLayer = new XHRArrayBufferTestLayer(); + this.addChild(xhrLayer); + }, + runThisTest:function () { + cc.director.runScene(this); + }, + MainMenuCallback:function (sender) { + this._super(sender); + } +}); + +var XHRArrayBufferTestLayer = cc.Layer.extend({ + ctor:function () { + this._super(); + }, + + onEnter: function() { + this._super(); + var l = new cc.LabelTTF("Get infos via XHR", "Thonburi", 16); + this.addChild(l, 1); + l.x = winSize.width / 2; + l.y = winSize.height - 60; + + this.sendPostArrayBuffer(); + }, + + sendPostArrayBuffer: function() { + var statusPostLabel = new cc.LabelTTF("Status:", "Thonburi", 12); + this.addChild(statusPostLabel, 1); + + statusPostLabel.x = 10; + statusPostLabel.y = winSize.height - 100; + ensureLeftAligned(statusPostLabel); + statusPostLabel.setString("Status: Send Post Request to httpbin.org with ArrayBuffer"); + + + var responseLabel = new cc.LabelTTF("", "Thonburi", 16); + this.addChild(responseLabel, 1); + ensureLeftAligned(responseLabel); + responseLabel.x = 10; + responseLabel.y = winSize.height / 2; + + var xhr = cc.loader.getXMLHttpRequest(); + streamXHREventsToLabel(xhr, statusPostLabel, responseLabel, "POST"); + + xhr.open("POST", "http://httpbin.org/post"); + //set Content-type "text/plain" to post ArrayBuffer or ArrayBufferView + xhr.setRequestHeader("Content-Type","text/plain"); + // Uint8Array is an ArrayBufferView + xhr.send(new Uint8Array([1,2,3,4,5])); + }, + + scrollViewDidScroll:function (view) { + }, + scrollViewDidZoom:function (view) { + } +}); + +var runXHRArrayBufferTest = function () { + var pScene = new cc.Scene(); + var pLayer = new XHRArrayBufferTestLayer(); + pScene.addChild(pLayer); + cc.director.runScene(pScene); +}; diff --git a/samples/js-tests/src/XHRTest/XHRTest.js b/samples/js-tests/src/XHRTest/XHRTest.js index 5712c2b541..002da553db 100644 --- a/samples/js-tests/src/XHRTest/XHRTest.js +++ b/samples/js-tests/src/XHRTest/XHRTest.js @@ -24,6 +24,33 @@ THE SOFTWARE. ****************************************************************************/ +//some utils functions +function ensureLeftAligned (label) { + label.anchorX = 0; + label.anchorY = 1; + label.textAlign = cc.TEXT_ALIGNMENT_LEFT; +} + +function streamXHREventsToLabel ( xhr, label, textbox, method ) { + // Simple events + ['loadstart', 'abort', 'error', 'load', 'loadend', 'timeout'].forEach(function (eventname) { + xhr["on" + eventname] = function () { + label.string += "\nEvent : " + eventname + } + }); + + // Special event + xhr.onreadystatechange = function () { + if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) { + var httpStatus = xhr.statusText; + var response = xhr.responseText.substring(0, 100) + "..."; + textbox.string = method + " Response (100 chars):\n" + textbox.string += response + label.string += "\nStatus: Got " + method + " response! " + httpStatus + } + } +} + var XHRTestScene = TestScene.extend({ ctor:function () { @@ -57,96 +84,79 @@ var XHRTestLayer = cc.Layer.extend({ }, sendGetRequest: function() { - var that = this; - var xhr = cc.loader.getXMLHttpRequest(); - var statusGetLabel = new cc.LabelTTF("Status:", "Thonburi", 18); + var statusGetLabel = new cc.LabelTTF("Status:", "Thonburi", 12); this.addChild(statusGetLabel, 1); - statusGetLabel.x = winSize.width / 2; + + statusGetLabel.x = 10 statusGetLabel.y = winSize.height - 100; + ensureLeftAligned(statusGetLabel); statusGetLabel.setString("Status: Send Get Request to httpbin.org"); + + var responseLabel = new cc.LabelTTF("", "Thonburi", 16); + this.addChild(responseLabel, 1); + + ensureLeftAligned(responseLabel); + responseLabel.x = 10; + responseLabel.y = winSize.height / 2; + + var xhr = cc.loader.getXMLHttpRequest(); + streamXHREventsToLabel(xhr, statusGetLabel, responseLabel, "GET"); + // 5 seconds for timeout + xhr.timeout = 5000; + //set arguments with ?xxx=xxx&yyy=yyy xhr.open("GET", "http://httpbin.org/get?show_env=1", true); - - xhr.onreadystatechange = function () { - if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) { - var httpStatus = xhr.statusText; - var response = xhr.responseText.substring(0, 100) + "..."; - var responseLabel = new cc.LabelTTF("GET Response (100 chars): \n" + response, "Thonburi", 16); - that.addChild(responseLabel, 1); - responseLabel.anchorX = 0; - responseLabel.anchorY = 1; - responseLabel.textAlign = cc.TEXT_ALIGNMENT_LEFT; - - responseLabel.x = 10; - responseLabel.y = winSize.height / 2; - statusGetLabel.setString("Status: Got GET response! " + httpStatus); - } - }; xhr.send(); }, sendPostPlainText: function() { - var that = this; - var xhr = cc.loader.getXMLHttpRequest(); - var statusPostLabel = new cc.LabelTTF("Status:", "Thonburi", 18); + var statusPostLabel = new cc.LabelTTF("Status:", "Thonburi", 12); this.addChild(statusPostLabel, 1); - statusPostLabel.x = winSize.width / 2; - - statusPostLabel.y = winSize.height - 140; + statusPostLabel.x = winSize.width / 10 * 3; + statusPostLabel.y = winSize.height - 100; + ensureLeftAligned(statusPostLabel); statusPostLabel.setString("Status: Send Post Request to httpbin.org with plain text"); + + var responseLabel = new cc.LabelTTF("", "Thonburi", 16); + this.addChild(responseLabel, 1); + ensureLeftAligned(responseLabel); + responseLabel.x = winSize.width / 10 * 3; + responseLabel.y = winSize.height / 2; + + var xhr = cc.loader.getXMLHttpRequest(); + streamXHREventsToLabel(xhr, statusPostLabel, responseLabel, "POST"); + xhr.open("POST", "http://httpbin.org/post"); //set Content-type "text/plain;charset=UTF-8" to post plain text xhr.setRequestHeader("Content-Type","text/plain;charset=UTF-8"); - xhr.onreadystatechange = function () { - if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) { - var httpStatus = xhr.statusText; - var response = xhr.responseText.substring(0, 100) + "..."; - var responseLabel = new cc.LabelTTF("POST Response (100 chars): \n" + response, "Thonburi", 16); - that.addChild(responseLabel, 1); - responseLabel.anchorX = 0; - responseLabel.anchorY = 1; - responseLabel.textAlign = cc.TEXT_ALIGNMENT_LEFT; - - responseLabel.x = winSize.width / 10 * 3; - responseLabel.y = winSize.height / 2; - statusPostLabel.setString("Status: Got POST response! " + httpStatus); - } - }; xhr.send("plain text message"); }, sendPostForms: function() { - var that = this; - var xhr = cc.loader.getXMLHttpRequest(); - var statusPostLabel = new cc.LabelTTF("Status:", "Thonburi", 18); + var statusPostLabel = new cc.LabelTTF("Status:", "Thonburi", 12); this.addChild(statusPostLabel, 1); - statusPostLabel.x = winSize.width / 2; - - statusPostLabel.y = winSize.height - 180; + statusPostLabel.x = winSize.width / 10 * 7; + statusPostLabel.y = winSize.height - 100; + ensureLeftAligned(statusPostLabel); statusPostLabel.setString("Status: Send Post Request to httpbin.org width form data"); + var responseLabel = new cc.LabelTTF("", "Thonburi", 16); + this.addChild(responseLabel, 1); + + ensureLeftAligned(responseLabel); + responseLabel.x = winSize.width / 10 * 7; + responseLabel.y = winSize.height / 2; + + var xhr = cc.loader.getXMLHttpRequest(); + streamXHREventsToLabel(xhr, statusPostLabel, responseLabel, "POST"); + xhr.open("POST", "http://httpbin.org/post"); //set Content-Type "application/x-www-form-urlencoded" to post form data //mulipart/form-data for upload xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); - xhr.onreadystatechange = function () { - if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) { - var httpStatus = xhr.statusText; - var response = xhr.responseText.substring(0, 100) + "..."; - var responseLabel = new cc.LabelTTF("POST Response (100 chars): \n" + response, "Thonburi", 16); - that.addChild(responseLabel, 1); - responseLabel.anchorX = 0; - responseLabel.anchorY = 1; - responseLabel.textAlign = cc.TEXT_ALIGNMENT_LEFT; - - responseLabel.x = winSize.width / 10 * 7; - responseLabel.y = winSize.height / 2; - statusPostLabel.setString("Status: Got POST response! " + httpStatus); - } - }; /** form : { "a" : "hello", @@ -155,7 +165,6 @@ var XHRTestLayer = cc.Layer.extend({ **/ var args = "a=hello&b=world"; xhr.send(args); - }, scrollViewDidScroll:function (view) { @@ -169,4 +178,4 @@ var runXHRTest = function () { var pLayer = new XHRTestLayer(); pScene.addChild(pLayer); cc.director.runScene(pScene); -}; +}; \ No newline at end of file diff --git a/samples/js-tests/src/tests-main.js b/samples/js-tests/src/tests-main.js index f62f0792d6..63a321e51c 100644 --- a/samples/js-tests/src/tests-main.js +++ b/samples/js-tests/src/tests-main.js @@ -104,7 +104,8 @@ var TestController = cc.LayerGradient.extend({ var toggleAutoTestItem = new cc.MenuItemToggle(subItem1, subItem2); toggleAutoTestItem.setCallback(this.onToggleAutoTest, this); toggleAutoTestItem.x = winSize.width - toggleAutoTestItem.width / 2 - 10; - toggleAutoTestItem.y = 20; + toggleAutoTestItem.y = 20; + toggleAutoTestItem.setVisible(false); if( autoTestEnabled ) toggleAutoTestItem.setSelectedIndex(1); @@ -242,6 +243,14 @@ var testNames = [ return new BakeLayerTestScene(); } }, + { + title:"BillBoard Test", + platforms: PLATFORM_JSB, + linksrc:"src/BillBoardTest/BillBoardTest.js", + testScene:function () { + return new BillBoardTestScene(); + } + }, { title:"Box2D Test", resource:g_box2d, @@ -251,6 +260,14 @@ var testNames = [ return new Box2DTestScene(); } }, + { + title:"Camera3D Test", + platforms: PLATFORM_JSB, + linksrc:"src/Camera3DTest/Camera3DTest.js", + testScene:function () { + return new Camera3DTestScene(); + } + }, { title:"Chipmunk Test", platforms: PLATFORM_ALL, @@ -413,6 +430,14 @@ var testNames = [ return new LayerTestScene(); } }, + { + title:"Light Test", + platforms: PLATFORM_JSB, + linksrc:"src/LightTest/LightTest.js", + testScene:function () { + return new LightTestScene(); + } + }, { title:"Loader Test", platforms: PLATFORM_ALL, @@ -547,6 +572,14 @@ var testNames = [ return new SpineTestScene(); } }, + { + title:"Sprite3D Test", + platforms: PLATFORM_JSB, + linksrc:"src/Sprite3DTest/Sprite3DTest.js", + testScene:function () { + return new Sprite3DTestScene(); + } + }, { title:"Sprite Test", resource:g_sprites, @@ -640,6 +673,14 @@ var testNames = [ testScene:function () { return new XHRTestScene(); } + }, + { + title:"XMLHttpRequest send ArrayBuffer", + platforms: PLATFORM_ALL, + linksrc:"src/XHRTest/XHRArrayBufferTest.js", + testScene:function () { + return new XHRArrayBufferTestScene(); + } } //"UserDefaultTest", diff --git a/samples/js-tests/src/tests_resources.js b/samples/js-tests/src/tests_resources.js index d1e8351324..5fea0155aa 100644 --- a/samples/js-tests/src/tests_resources.js +++ b/samples/js-tests/src/tests_resources.js @@ -282,7 +282,9 @@ var g_sprites = [ s_tcc_issue_2, s_s9s_blocks9_plist, - s_s9s_blocks9 + s_s9s_blocks9, + "res/Images/dot.png", + "res/Images/wood.jpg" ]; var g_menu = [ @@ -585,191 +587,195 @@ var g_cocoStudio = [ "res/Images/b2.png", "res/Images/f1.png", "res/Images/f2.png", - "res/cocosui/UIEditorTest/UIButton_Editor/background.png", - "res/cocosui/UIEditorTest/UIButton_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UIButton_Editor/buttonHighlighted.png", - "res/cocosui/UIEditorTest/UIButton_Editor/button_n.png", - "res/cocosui/UIEditorTest/UIButton_Editor/button_p.png", - "res/cocosui/UIEditorTest/UIButton_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.json", - "res/cocosui/UIEditorTest/UICheckBox_Editor/background.png", - "res/cocosui/UIEditorTest/UICheckBox_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UICheckBox_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UICheckBox_Editor/selected01.png", - "res/cocosui/UIEditorTest/UICheckBox_Editor/selected02.png", - "res/cocosui/UIEditorTest/UICheckBox_Editor/ui_checkbox_editor_1.json", - "res/cocosui/UIEditorTest/UIImageView_Editor/background.png", - "res/cocosui/UIEditorTest/UIImageView_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UIImageView_Editor/buttonHighlighted.png", - "res/cocosui/UIEditorTest/UIImageView_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UIImageView_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UIImageView_Editor/ui_ImageView_editor_1.json", - "res/cocosui/UIEditorTest/UILabelAtlas_Editor/background.png", - "res/cocosui/UIEditorTest/UILabelAtlas_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UILabelAtlas_Editor/GUI/labelatlasimg.png", - "res/cocosui/UIEditorTest/UILabelAtlas_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UILabelAtlas_Editor/ui_labelatlas_editor_1.json", - "res/cocosui/UIEditorTest/UILabelBMFont_Editor/background.png", - "res/cocosui/UIEditorTest/UILabelBMFont_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.fnt", - "res/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png", - "res/cocosui/UIEditorTest/UILabelBMFont_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.json", - "res/cocosui/UIEditorTest/UILabel_Editor/background.png", - "res/cocosui/UIEditorTest/UILabel_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UILabel_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UILabel_Editor/ui_label_editor_1.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/button_n.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/button_p.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/selected01.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/selected02.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ui_layout_backgroundimage_editor_1_0_0.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/button_n.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/button_p.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/selected01.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/selected02.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ui_layout_color_editor_1.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/button_n.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/button_p.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/selected01.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/selected02.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ui_layout_editor_1.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/button_n.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/button_p.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/selected01.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/selected02.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ui_layout_gradient_color_editor_1_0.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/button_n.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/button_p.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/selected01.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/selected02.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ui_layout_linear_horizontal_layout_editor.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/button_n.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/button_p.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/selected01.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/selected02.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ui_layout_linear_vertical_layout_editor.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/button_n.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/button_p.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/selected01.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/selected02.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ui_layout_relative_align_location_editor.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/button_n.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/button_p.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/selected01.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/selected02.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ui_layout_relative_align_parent_editor.json", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/button_n.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/button_p.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/selected01.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/selected02.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/slider_bar.png", - "res/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ui_layout_scale9_backgroundimage_editor.json", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/button_p.png", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/GUI/button.png", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.json", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/button_p.png", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/GUI/button.png", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.json", - "res/cocosui/UIEditorTest/UILoadingBar_Editor/background.png", - "res/cocosui/UIEditorTest/UILoadingBar_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UILoadingBar_Editor/GUI/loadingbar.png", - "res/cocosui/UIEditorTest/UILoadingBar_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UILoadingBar_Editor/ui_loadingbar_editor_1.json", - "res/cocosui/UIEditorTest/UIPageView_Editor/background.png", - "res/cocosui/UIEditorTest/UIPageView_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UIPageView_Editor/button_n.png", - "res/cocosui/UIEditorTest/UIPageView_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UIPageView_Editor/ui_pageview_editor_1.json", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/button_n.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/button_p.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/selected01.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/selected02.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ui_scrollview_both_editor_1.json", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/button_n.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/button_p.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/selected01.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/selected02.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ui_scrollview_horizontal_editor_1.json", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/button_n.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/button_p.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/GUI/image.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/selected01.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/selected02.png", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ui_scrollview_editor_1.json", - "res/cocosui/UIEditorTest/UISlider_Editor/2014-1-26 11-42-09.png", - "res/cocosui/UIEditorTest/UISlider_Editor/2014-1-26 11-43-52.png", - "res/cocosui/UIEditorTest/UISlider_Editor/background.png", - "res/cocosui/UIEditorTest/UISlider_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UISlider_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UISlider_Editor/silder_progressBar.png", - "res/cocosui/UIEditorTest/UISlider_Editor/slider_bar.png", - "res/cocosui/UIEditorTest/UISlider_Editor/slider_bar_button.png", - "res/cocosui/UIEditorTest/UISlider_Editor/ui_slider_editor_1.json", - "res/cocosui/UIEditorTest/UITextField_Editor/background.png", - "res/cocosui/UIEditorTest/UITextField_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UITextField_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UITextField_Editor/ui_textfield_editor_1.json", - "res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/background.png", - "res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/buttonBackground.png", - "res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/ribbon.png", - "res/cocosui/UIEditorTest/UIWidgetAddNode_Editor/ui_widget_add_node_editor.json", + "res/cocosui/CCS/Button/background.png", + "res/cocosui/CCS/Button/buttonBackground.png", + "res/cocosui/CCS/Button/buttonHighlighted.png", + "res/cocosui/CCS/Button/button_n.png", + "res/cocosui/CCS/Button/button_p.png", + "res/cocosui/CCS/Button/ribbon.png", + "res/cocosui/CCS/Button/Button_1.json", + "res/cocosui/CCS/CheckBox/background.png", + "res/cocosui/CCS/CheckBox/buttonBackground.png", + "res/cocosui/CCS/CheckBox/ribbon.png", + "res/cocosui/CCS/CheckBox/selected01.png", + "res/cocosui/CCS/CheckBox/selected02.png", + "res/cocosui/CCS/CheckBox/checkbox_1.json", + "res/cocosui/CCS/CheckBox/MainScene.json", + "res/cocosui/CCS/CheckBox/Default/CheckBox_Disable.png", + "res/cocosui/CCS/CheckBox/img/btn_music.png", + "res/cocosui/CCS/CheckBox/img/btn_sound_off.png", + "res/cocosui/CCS/ImageView/background.png", + "res/cocosui/CCS/ImageView/buttonBackground.png", + "res/cocosui/CCS/ImageView/buttonHighlighted.png", + "res/cocosui/CCS/ImageView/GUI/image.png", + "res/cocosui/CCS/ImageView/ribbon.png", + "res/cocosui/CCS/ImageView/ImageView_1.json", + "res/cocosui/CCS/LabelAtlas/background.png", + "res/cocosui/CCS/LabelAtlas/buttonBackground.png", + "res/cocosui/CCS/LabelAtlas/GUI/labelatlasimg.png", + "res/cocosui/CCS/LabelAtlas/ribbon.png", + "res/cocosui/CCS/LabelAtlas/labelatlas_1.json", + "res/cocosui/CCS/LabelBMFont/background.png", + "res/cocosui/CCS/LabelBMFont/buttonBackground.png", + "res/cocosui/CCS/LabelBMFont/GUI/missing-font.fnt", + "res/cocosui/CCS/LabelBMFont/GUI/missing-font.png", + "res/cocosui/CCS/LabelBMFont/ribbon.png", + "res/cocosui/CCS/LabelBMFont/labelbmfont_1.json", + "res/cocosui/CCS/Label/background.png", + "res/cocosui/CCS/Label/buttonBackground.png", + "res/cocosui/CCS/Label/ribbon.png", + "res/cocosui/CCS/Label/label_1.json", + "res/cocosui/CCS/Layout/BackgroundImage/background.png", + "res/cocosui/CCS/Layout/BackgroundImage/buttonBackground.png", + "res/cocosui/CCS/Layout/BackgroundImage/button_n.png", + "res/cocosui/CCS/Layout/BackgroundImage/button_p.png", + "res/cocosui/CCS/Layout/BackgroundImage/GUI/image.png", + "res/cocosui/CCS/Layout/BackgroundImage/Hello.png", + "res/cocosui/CCS/Layout/BackgroundImage/ribbon.png", + "res/cocosui/CCS/Layout/BackgroundImage/selected01.png", + "res/cocosui/CCS/Layout/BackgroundImage/selected02.png", + "res/cocosui/CCS/Layout/BackgroundImage/backgroundimage_1.json", + "res/cocosui/CCS/Layout/Color/background.png", + "res/cocosui/CCS/Layout/Color/buttonBackground.png", + "res/cocosui/CCS/Layout/Color/button_n.png", + "res/cocosui/CCS/Layout/Color/button_p.png", + "res/cocosui/CCS/Layout/Color/GUI/image.png", + "res/cocosui/CCS/Layout/Color/ribbon.png", + "res/cocosui/CCS/Layout/Color/selected01.png", + "res/cocosui/CCS/Layout/Color/selected02.png", + "res/cocosui/CCS/Layout/Color/color_1.json", + "res/cocosui/CCS/Layout/Layout/background.png", + "res/cocosui/CCS/Layout/Layout/buttonBackground.png", + "res/cocosui/CCS/Layout/Layout/button_n.png", + "res/cocosui/CCS/Layout/Layout/button_p.png", + "res/cocosui/CCS/Layout/Layout/GUI/image.png", + "res/cocosui/CCS/Layout/Layout/ribbon.png", + "res/cocosui/CCS/Layout/Layout/selected01.png", + "res/cocosui/CCS/Layout/Layout/selected02.png", + "res/cocosui/CCS/Layout/Layout/layout_1.json", + "res/cocosui/CCS/Layout/Gradient_Color/background.png", + "res/cocosui/CCS/Layout/Gradient_Color/buttonBackground.png", + "res/cocosui/CCS/Layout/Gradient_Color/button_n.png", + "res/cocosui/CCS/Layout/Gradient_Color/button_p.png", + "res/cocosui/CCS/Layout/Gradient_Color/GUI/image.png", + "res/cocosui/CCS/Layout/Gradient_Color/ribbon.png", + "res/cocosui/CCS/Layout/Gradient_Color/selected01.png", + "res/cocosui/CCS/Layout/Gradient_Color/selected02.png", + "res/cocosui/CCS/Layout/Gradient_Color/gradient_color_1.json", + "res/cocosui/CCS/Layout/Linear_Horizontal/background.png", + "res/cocosui/CCS/Layout/Linear_Horizontal/buttonBackground.png", + "res/cocosui/CCS/Layout/Linear_Horizontal/button_n.png", + "res/cocosui/CCS/Layout/Linear_Horizontal/button_p.png", + "res/cocosui/CCS/Layout/Linear_Horizontal/GUI/image.png", + "res/cocosui/CCS/Layout/Linear_Horizontal/ribbon.png", + "res/cocosui/CCS/Layout/Linear_Horizontal/selected01.png", + "res/cocosui/CCS/Layout/Linear_Horizontal/selected02.png", + "res/cocosui/CCS/Layout/Linear_Horizontal/linear_horizontal.json", + "res/cocosui/CCS/Layout/Linear_Vertical/background.png", + "res/cocosui/CCS/Layout/Linear_Vertical/buttonBackground.png", + "res/cocosui/CCS/Layout/Linear_Vertical/button_n.png", + "res/cocosui/CCS/Layout/Linear_Vertical/button_p.png", + "res/cocosui/CCS/Layout/Linear_Vertical/GUI/image.png", + "res/cocosui/CCS/Layout/Linear_Vertical/ribbon.png", + "res/cocosui/CCS/Layout/Linear_Vertical/selected01.png", + "res/cocosui/CCS/Layout/Linear_Vertical/selected02.png", + "res/cocosui/CCS/Layout/Linear_Vertical/linear_vertical.json", + "res/cocosui/CCS/Layout/Relative_Align_Location/background.png", + "res/cocosui/CCS/Layout/Relative_Align_Location/buttonBackground.png", + "res/cocosui/CCS/Layout/Relative_Align_Location/button_n.png", + "res/cocosui/CCS/Layout/Relative_Align_Location/button_p.png", + "res/cocosui/CCS/Layout/Relative_Align_Location/GUI/image.png", + "res/cocosui/CCS/Layout/Relative_Align_Location/ribbon.png", + "res/cocosui/CCS/Layout/Relative_Align_Location/selected01.png", + "res/cocosui/CCS/Layout/Relative_Align_Location/selected02.png", + "res/cocosui/CCS/Layout/Relative_Align_Location/relative_align_location.json", + "res/cocosui/CCS/Layout/Relative_Align_Parent/background.png", + "res/cocosui/CCS/Layout/Relative_Align_Parent/buttonBackground.png", + "res/cocosui/CCS/Layout/Relative_Align_Parent/button_n.png", + "res/cocosui/CCS/Layout/Relative_Align_Parent/button_p.png", + "res/cocosui/CCS/Layout/Relative_Align_Parent/GUI/image.png", + "res/cocosui/CCS/Layout/Relative_Align_Parent/ribbon.png", + "res/cocosui/CCS/Layout/Relative_Align_Parent/selected01.png", + "res/cocosui/CCS/Layout/Relative_Align_Parent/selected02.png", + "res/cocosui/CCS/Layout/Relative_Align_Parent/relative_align_parent.json", + "res/cocosui/CCS/Layout/Scale9/background.png", + "res/cocosui/CCS/Layout/Scale9/buttonBackground.png", + "res/cocosui/CCS/Layout/Scale9/button_n.png", + "res/cocosui/CCS/Layout/Scale9/button_p.png", + "res/cocosui/CCS/Layout/Scale9/GUI/image.png", + "res/cocosui/CCS/Layout/Scale9/ribbon.png", + "res/cocosui/CCS/Layout/Scale9/selected01.png", + "res/cocosui/CCS/Layout/Scale9/selected02.png", + "res/cocosui/CCS/Layout/Scale9/slider_bar.png", + "res/cocosui/CCS/Layout/Scale9/scale9.json", + "res/cocosui/CCS/ListView/Horizontal/background.png", + "res/cocosui/CCS/ListView/Horizontal/buttonBackground.png", + "res/cocosui/CCS/ListView/Horizontal/button_p.png", + "res/cocosui/CCS/ListView/Horizontal/GUI/button.png", + "res/cocosui/CCS/ListView/Horizontal/GUI/image.png", + "res/cocosui/CCS/ListView/Horizontal/ribbon.png", + "res/cocosui/CCS/ListView/Horizontal/horizontal_1.json", + "res/cocosui/CCS/ListView/Vertical/background.png", + "res/cocosui/CCS/ListView/Vertical/buttonBackground.png", + "res/cocosui/CCS/ListView/Vertical/button_p.png", + "res/cocosui/CCS/ListView/Vertical/GUI/button.png", + "res/cocosui/CCS/ListView/Vertical/GUI/image.png", + "res/cocosui/CCS/ListView/Vertical/ribbon.png", + "res/cocosui/CCS/ListView/Vertical/vertical_1.json", + "res/cocosui/CCS/LoadingBar/background.png", + "res/cocosui/CCS/LoadingBar/buttonBackground.png", + "res/cocosui/CCS/LoadingBar/GUI/loadingbar.png", + "res/cocosui/CCS/LoadingBar/ribbon.png", + "res/cocosui/CCS/LoadingBar/loadingbar_1.json", + "res/cocosui/CCS/PageView/background.png", + "res/cocosui/CCS/PageView/buttonBackground.png", + "res/cocosui/CCS/PageView/button_n.png", + "res/cocosui/CCS/PageView/ribbon.png", + "res/cocosui/CCS/PageView/pageview_1.json", + "res/cocosui/CCS/ScrollView/Both/background.png", + "res/cocosui/CCS/ScrollView/Both/buttonBackground.png", + "res/cocosui/CCS/ScrollView/Both/button_n.png", + "res/cocosui/CCS/ScrollView/Both/button_p.png", + "res/cocosui/CCS/ScrollView/Both/GUI/image.png", + "res/cocosui/CCS/ScrollView/Both/ribbon.png", + "res/cocosui/CCS/ScrollView/Both/selected01.png", + "res/cocosui/CCS/ScrollView/Both/selected02.png", + "res/cocosui/CCS/ScrollView/Both/both_1.json", + "res/cocosui/CCS/ScrollView/Horizontal/background.png", + "res/cocosui/CCS/ScrollView/Horizontal/buttonBackground.png", + "res/cocosui/CCS/ScrollView/Horizontal/button_n.png", + "res/cocosui/CCS/ScrollView/Horizontal/button_p.png", + "res/cocosui/CCS/ScrollView/Horizontal/GUI/image.png", + "res/cocosui/CCS/ScrollView/Horizontal/ribbon.png", + "res/cocosui/CCS/ScrollView/Horizontal/selected01.png", + "res/cocosui/CCS/ScrollView/Horizontal/selected02.png", + "res/cocosui/CCS/ScrollView/Horizontal/horizontal_1.json", + "res/cocosui/CCS/ScrollView/Vertical/background.png", + "res/cocosui/CCS/ScrollView/Vertical/buttonBackground.png", + "res/cocosui/CCS/ScrollView/Vertical/button_n.png", + "res/cocosui/CCS/ScrollView/Vertical/button_p.png", + "res/cocosui/CCS/ScrollView/Vertical/GUI/image.png", + "res/cocosui/CCS/ScrollView/Vertical/ribbon.png", + "res/cocosui/CCS/ScrollView/Vertical/selected01.png", + "res/cocosui/CCS/ScrollView/Vertical/selected02.png", + "res/cocosui/CCS/ScrollView/Vertical/vertical_1.json", + "res/cocosui/CCS/Slider/2014-1-26 11-42-09.png", + "res/cocosui/CCS/Slider/2014-1-26 11-43-52.png", + "res/cocosui/CCS/Slider/background.png", + "res/cocosui/CCS/Slider/buttonBackground.png", + "res/cocosui/CCS/Slider/ribbon.png", + "res/cocosui/CCS/Slider/silder_progressBar.png", + "res/cocosui/CCS/Slider/slider_bar.png", + "res/cocosui/CCS/Slider/slider_bar_button.png", + "res/cocosui/CCS/Slider/slider_1.json", + "res/cocosui/CCS/TextField/background.png", + "res/cocosui/CCS/TextField/buttonBackground.png", + "res/cocosui/CCS/TextField/ribbon.png", + "res/cocosui/CCS/TextField/textfield_1.json", + "res/cocosui/CCS/WidgetAddNode/background.png", + "res/cocosui/CCS/WidgetAddNode/buttonBackground.png", + "res/cocosui/CCS/WidgetAddNode/ribbon.png", + "res/cocosui/CCS/WidgetAddNode/widget_add_node.json", "res/Sound/background-music-aac.wav", "res/Sound/pew-pew-lei.wav", //Components @@ -850,27 +856,46 @@ var g_cocoStudio = [ "res/scenetest/UIComponentTest/UIComponentTest.json", //parser - "res/cocosui/UIEditorTest/cocostudio1_3/CocostudioV1_3_1.ExportJson", - "res/cocosui/UIEditorTest/cocostudio1_3/CocostudioV1_30.plist", - "res/cocosui/UIEditorTest/cocostudio1_3/CocostudioV1_30.png", - "res/cocosui/UIEditorTest/cocostudio1_3/SmallSun.plist", - "res/cocosui/UIEditorTest/cocostudio1_3/GUI/labelatlasimg.png", - "res/cocosui/UIEditorTest/cocostudio1_3/GUI/missing-font.fnt", - "res/cocosui/UIEditorTest/cocostudio1_3/GUI/missing-font.png", - "res/cocosui/UIEditorTest/cocostudio1_4/Cocostudio1_4_1.ExportJson", - "res/cocosui/UIEditorTest/cocostudio1_4/Cocostudio1_40.plist", - "res/cocosui/UIEditorTest/cocostudio1_4/Cocostudio1_40.png", - "res/cocosui/UIEditorTest/cocostudio1_4/SmallSun.plist", - "res/cocosui/UIEditorTest/cocostudio1_4/GUI/labelatlasimg.png", - "res/cocosui/UIEditorTest/cocostudio1_4/GUI/missing-font.fnt", - "res/cocosui/UIEditorTest/cocostudio1_4/GUI/missing-font.png", - "res/cocosui/UIEditorTest/cocostudio1_5/Cocostudio1_5_1.ExportJson", - "res/cocosui/UIEditorTest/cocostudio1_5/Cocostudio1_50.plist", - "res/cocosui/UIEditorTest/cocostudio1_5/Cocostudio1_50.png", - "res/cocosui/UIEditorTest/cocostudio1_5/SmallSun.plist", - "res/cocosui/UIEditorTest/cocostudio1_5/GUI/labelatlasimg.png", - "res/cocosui/UIEditorTest/cocostudio1_5/GUI/missing-font.fnt", - "res/cocosui/UIEditorTest/cocostudio1_5/GUI/missing-font.png", + "res/cocosui/CCS/ccs1_3/CCSV1_3_1.ExportJson", + "res/cocosui/CCS/ccs1_3/CocostudioV1_30.plist", + "res/cocosui/CCS/ccs1_3/CocostudioV1_30.png", + "res/cocosui/CCS/ccs1_3/SmallSun.plist", + "res/cocosui/CCS/ccs1_3/GUI/labelatlasimg.png", + "res/cocosui/CCS/ccs1_3/GUI/missing-font.fnt", + "res/cocosui/CCS/ccs1_3/GUI/missing-font.png", + "res/cocosui/CCS/ccs1_4/CCS1_4_1.ExportJson", + "res/cocosui/CCS/ccs1_4/Cocostudio1_40.plist", + "res/cocosui/CCS/ccs1_4/Cocostudio1_40.png", + "res/cocosui/CCS/ccs1_4/SmallSun.plist", + "res/cocosui/CCS/ccs1_4/GUI/labelatlasimg.png", + "res/cocosui/CCS/ccs1_4/GUI/missing-font.fnt", + "res/cocosui/CCS/ccs1_4/GUI/missing-font.png", + "res/cocosui/CCS/ccs1_5/CCS1_5_1.ExportJson", + "res/cocosui/CCS/ccs1_5/Cocostudio1_50.plist", + "res/cocosui/CCS/ccs1_5/Cocostudio1_50.png", + "res/cocosui/CCS/ccs1_5/SmallSun.plist", + "res/cocosui/CCS/ccs1_5/GUI/labelatlasimg.png", + "res/cocosui/CCS/ccs1_5/GUI/missing-font.fnt", + "res/cocosui/CCS/ccs1_5/GUI/missing-font.png", + + "res/cocosui/CCS/2.1/MainScene.json", + "res/cocosui/CCS/2.1/plist1/Plist.plist", + "res/cocosui/CCS/2.1/Plist/ui.plist", + "res/cocosui/CCS/2.1/LoadingBar/pipe2.png", + "res/cocosui/CCS/2.1/Slider/2013-8-13 15-44-11.png", + "res/cocosui/CCS/2.1/Slider/teehanlax - iOS 6 - iPhone_slider01.png", + "res/cocosui/CCS/2.1/particle/blue.plist", + "res/cocosui/CCS/2.1/Default/Slider_Back.png", + "res/cocosui/CCS/2.1/Default/SliderNode_Normal.png", + "res/cocosui/CCS/2.1/Default/SliderNode_Press.png", + "res/cocosui/CCS/2.1/Default/SliderNode_Disable.png", + "res/cocosui/CCS/2.1/Default/Slider_PressBar.png", + "res/cocosui/CCS/2.1/Default/defaultParticle.plist", + "res/cocosui/CCS/2.1/Default/TextAtlas.png", + "res/cocosui/CCS/2.1/fonts_weapon_001-hd.png", + "res/cocosui/CCS/2.1/FNT/futura.fnt", + "res/cocosui/CCS/2.1/Default/defaultBMFont.fnt", + "res/cocosui/CCS/2.1/FNT/Heiti18.fnt", "res/Particles/BoilingFoam.plist", "res/cocosui/CustomImageViewTest/NewProject_2_1.ExportJson", @@ -879,6 +904,7 @@ var g_cocoStudio = [ ]; var g_ui = [ + "res/cocosui/switch-mask.png", "res/cocosui/animationbuttonnormal.png", "res/cocosui/animationbuttonpressed.png", "res/cocosui/arrow.png", @@ -926,7 +952,9 @@ var g_ui = [ "res/cocosui/UITest/UITest.json", "res/cocosui/100/100.ExportJson", "res/cocosui/100/1000.plist", - "res/cocosui/100/1000.png" + "res/cocosui/100/1000.png", + s_s9s_blocks9_plist, + "res/cocosui/CloseSelected.png" ]; var g_performace = [ @@ -1049,20 +1077,14 @@ var g_tilemaps = [ var g_spine = [ "res/skeletons/spineboy.atlas", "res/skeletons/spineboy.json", - "res/skeletons/spineboy.png" + "res/skeletons/spineboy.png", + "res/skeletons/sprite.png", + "res/skeletons/goblins-ffd.png", + "res/skeletons/goblins-ffd.atlas", + "res/skeletons/goblins-ffd.json" ]; var g_ccs2 = [ - "res/cocosui/UIEditorTest/UIButton_Editor/crossplatform_UIButton_Editor_1.csb", - "res/cocosui/UIEditorTest/UICheckBox_Editor/crossplatform_UICheckBox_Editor_1.csb", - "res/cocosui/UIEditorTest/UIImageView_Editor/crossplatform_UIImageView_Editor_1.csb", - "res/cocosui/UIEditorTest/UILabel_Editor/crossplatform_UILabel_Editor_1.csb", - "res/cocosui/UIEditorTest/UILabelAtlas_Editor/crossplatform_UILabelAtlas_Editor_1.csb", - "res/cocosui/UIEditorTest/UILabelBMFont_Editor/crossplatform_UILabelBMFont_Editor_1.csb", - "res/cocosui/UIEditorTest/UILoadingBar_Editor/crossplatform_UILoadingBar_Editor_1.csb", - "res/cocosui/UIEditorTest/UIPageView_Editor/crossplatform_UIPageView_Editor_1.csb", - "res/cocosui/UIEditorTest/UISlider_Editor/crossplatform_UISlider_Editor_1.csb", - "res/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/crossplatform_UIScrollView_Both_Editor_1.csb", "res/ActionTimeline/boy_1.csb", "res/ActionTimeline/armature/Cowboy0.plist", "res/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.fnt", diff --git a/templates/js-template-default/CMakeLists.txt b/templates/js-template-default/CMakeLists.txt index ffbb05bf28..e9b26d4799 100644 --- a/templates/js-template-default/CMakeLists.txt +++ b/templates/js-template-default/CMakeLists.txt @@ -247,29 +247,15 @@ cocos_find_package(TIFF TIFF REQUIRED) cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED) cocos_find_package(CURL CURL REQUIRED) -# protobuf-lite (not prebuilded, exists as source) -# TODO: for now we can't use upstream protobuf because these files: -# cocos/editor-support/cocostudio/CSParseBinary.pb.h -# cocos/editor-support/cocostudio/CSParseBinary.pb.cc -# was generated by concrete version of protobuf compiler -# and source file not provided. So these files can be -# compiled only with our in-source version of protobuf-lite -## if(USE_PREBUILT_LIBS) - add_subdirectory(frameworks/js-bindings/cocos2d-x/external/protobuf-lite) - set(PROTOBUF_LITE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/js-bindings/cocos2d-x/external/protobuf-lite/src) - set(PROTOBUF_LITE_LIBRARIES protobuf) -## else() -## cocos_find_package(Protobuf REQUIRED PROTOBUF_LITE_LIBRARIES) -## set(PROTOBUF_LITE_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS}) -## endif() -message(STATUS "Protobuf lite libs: ${PROTOBUF_LITE_LIBRARIES}") -message(STATUS "Protobuf include dirs: ${PROTOBUF_LITE_INCLUDE_DIRS}") - -# build for 3rd party libraries -if(LINUX OR APPLE) -add_subdirectory(frameworks/js-bindings/cocos2d-x/external/xxhash) -endif() +add_subdirectory(frameworks/js-bindings/cocos2d-x/external/flatbuffers) +set(FLATBUFFERS_INCLUDE_DIRS frameworks/js-bindings/cocos2d-x/external) +message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}") + + +# build xxhash +add_subdirectory(frameworks/js-bindings/cocos2d-x/external/xxhash) +include_directories(frameworks/js-bindings/cocos2d-x/external/xxhash) set(GAME_SRC frameworks/runtime-src/proj.linux/main.cpp diff --git a/templates/js-template-default/cocos-project-template.json b/templates/js-template-default/cocos-project-template.json index 4c0e5a6341..32514a71bf 100644 --- a/templates/js-template-default/cocos-project-template.json +++ b/templates/js-template-default/cocos-project-template.json @@ -26,7 +26,13 @@ "proj.ios_mac/HelloJavascript.xcodeproj/xcuserdata", "proj.win32/Debug.win32", "proj.win32/Release.win32", - "proj.win32/HelloJavascript.sdf" + "proj.win32/HelloJavascript.sdf", + "proj.win8.1-universal/HelloJavascript.sdf", + "proj.win8.1-universal/HelloJavascript.v12.suo", + "proj.win8.1-universal/ipch", + "proj.win8.1-universal/Debug", + "proj.win8.1-universal/Release", + "proj.win8.1-universal/ARM" ] }, "append_dir":[ @@ -68,17 +74,32 @@ "frameworks/runtime-src/proj.win32/PROJECT_NAME.vcxproj.filters", "frameworks/runtime-src/proj.win32/PROJECT_NAME.vcxproj.user", "frameworks/runtime-src/proj.win32/PROJECT_NAME.sln", - "frameworks/runtime-src/proj.ios_mac/PROJECT_NAME.xcodeproj" - ] + "frameworks/runtime-src/proj.ios_mac/PROJECT_NAME.xcodeproj", + "frameworks/runtime-src/proj.wp8-xaml/PROJECT_NAME.sln", + "frameworks/runtime-src/proj.wp8-xaml/App/PROJECT_NAME.csproj", + "frameworks/runtime-src/proj.wp8-xaml/AppComponent/PROJECT_NAMEComponent.vcxproj", + "frameworks/runtime-src/proj.wp8-xaml/AppComponent/PROJECT_NAMEComponent.vcxproj.filters", + "frameworks/runtime-src/proj.win8.1-universal/PROJECT_NAME.sln", + "frameworks/runtime-src/proj.win8.1-universal/App.Shared/PROJECT_NAME.Shared.vcxitems", + "frameworks/runtime-src/proj.win8.1-universal/App.Shared/PROJECT_NAME.Shared.vcxitems.filters", + "frameworks/runtime-src/proj.win8.1-universal/App.Windows/PROJECT_NAME.Windows.vcxproj", + "frameworks/runtime-src/proj.win8.1-universal/App.Windows/PROJECT_NAME.Windows.vcxproj.filters", + "frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/PROJECT_NAME.WindowsPhone.vcxproj", + "frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/PROJECT_NAME.WindowsPhone.vcxproj.filters" + ] }, "project_replace_project_name":{ "src_project_name":"HelloJavascript", "files":[ + "manifest.webapp", "frameworks/runtime-src/proj.win32/PROJECT_NAME.vcxproj", "frameworks/runtime-src/proj.win32/PROJECT_NAME.vcxproj.filters", "frameworks/runtime-src/proj.win32/PROJECT_NAME.vcxproj.user", "frameworks/runtime-src/proj.win32/PROJECT_NAME.sln", "frameworks/runtime-src/proj.win32/main.cpp", + "frameworks/runtime-src/proj.wp8-xaml/App/PROJECT_NAME.csproj", + "frameworks/runtime-src/proj.wp8-xaml/App/Properties/WMAppManifest.xml", + "frameworks/runtime-src/proj.wp8-xaml/PROJECT_NAME.sln", "frameworks/runtime-src/proj.android/.project", "frameworks/runtime-src/proj.android/AndroidManifest.xml", "frameworks/runtime-src/proj.android/build.xml", @@ -86,6 +107,15 @@ "frameworks/runtime-src/proj.ios_mac/ios/main.m", "frameworks/runtime-src/proj.ios_mac/ios/Prefix.pch", "frameworks/runtime-src/proj.ios_mac/PROJECT_NAME.xcodeproj/project.pbxproj", + "frameworks/runtime-src/proj.win8.1-universal/PROJECT_NAME.sln", + "frameworks/runtime-src/proj.win8.1-universal/App.Shared/PROJECT_NAME.Shared.vcxitems", + "frameworks/runtime-src/proj.win8.1-universal/App.Shared/PROJECT_NAME.Shared.vcxitems.filters", + "frameworks/runtime-src/proj.win8.1-universal/App.Windows/PROJECT_NAME.Windows.vcxproj", + "frameworks/runtime-src/proj.win8.1-universal/App.Windows/PROJECT_NAME.Windows.vcxproj.filters", + "frameworks/runtime-src/proj.win8.1-universal/App.Windows/Package.appxmanifest", + "frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/PROJECT_NAME.WindowsPhone.vcxproj", + "frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/PROJECT_NAME.WindowsPhone.vcxproj.filters", + "frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Package.appxmanifest", "frameworks/runtime-src/Classes/AppDelegate.cpp" ] }, diff --git a/templates/js-template-default/frameworks/runtime-src/Classes/AppDelegate.cpp b/templates/js-template-default/frameworks/runtime-src/Classes/AppDelegate.cpp index 0cef7170b2..e4bcf44553 100644 --- a/templates/js-template-default/frameworks/runtime-src/Classes/AppDelegate.cpp +++ b/templates/js-template-default/frameworks/runtime-src/Classes/AppDelegate.cpp @@ -7,6 +7,9 @@ #include "jsb_cocos2dx_builder_auto.hpp" #include "jsb_cocos2dx_spine_auto.hpp" #include "jsb_cocos2dx_extension_auto.hpp" +#include "jsb_cocos2dx_3d_auto.hpp" +#include "jsb_cocos2dx_3d_extension_auto.hpp" +#include "3d/jsb_cocos2dx_3d_manual.h" #include "ui/jsb_cocos2dx_ui_manual.h" #include "cocostudio/jsb_cocos2dx_studio_manual.h" #include "cocosbuilder/js_bindings_ccbreader.h" @@ -48,11 +51,15 @@ bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); - auto glview = director->getOpenGLView(); - if(!glview) { - glview = cocos2d::GLViewImpl::createWithRect("HelloJavascript", Rect(0,0,900,640)); - director->setOpenGLView(glview); - } + auto glview = director->getOpenGLView(); + if(!glview) { +#if(CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) + glview = cocos2d::GLViewImpl::create("HelloJavascript"); +#else + glview = cocos2d::GLViewImpl::createWithRect("HelloJavascript", Rect(0,0,900,640)); +#endif + director->setOpenGLView(glview); +} // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); @@ -60,7 +67,6 @@ bool AppDelegate::applicationDidFinishLaunching() ScriptingCore* sc = ScriptingCore::getInstance(); sc->addRegisterCallback(register_all_cocos2dx); sc->addRegisterCallback(register_cocos2dx_js_core); - sc->addRegisterCallback(register_cocos2dx_js_extensions); sc->addRegisterCallback(jsb_register_system); // extension can be commented out to reduce the package @@ -94,6 +100,13 @@ bool AppDelegate::applicationDidFinishLaunching() sc->addRegisterCallback(register_jsb_websocket); // sokcet io can be commented out to reduce the package sc->addRegisterCallback(register_jsb_socketio); + + // 3d can be commented out to reduce the package + sc->addRegisterCallback(register_all_cocos2dx_3d); + sc->addRegisterCallback(register_all_cocos2dx_3d_manual); + + // 3d extension can be commented out to reduce the package + sc->addRegisterCallback(register_all_cocos2dx_3d_extension); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) sc->addRegisterCallback(JavascriptJavaBridge::_js_register); @@ -103,8 +116,8 @@ bool AppDelegate::applicationDidFinishLaunching() sc->start(); sc->runScript("script/jsb_boot.js"); ScriptEngineProtocol *engine = ScriptingCore::getInstance(); - ScriptEngineManager::getInstance()->setScriptEngine(engine); - ScriptingCore::getInstance()->runScript("main.js"); + ScriptEngineManager::getInstance()->setScriptEngine(engine); + ScriptingCore::getInstance()->runScript("main.js"); return true; } diff --git a/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/project.pbxproj b/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/project.pbxproj index 589f35e959..68d7618a57 100644 --- a/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/project.pbxproj +++ b/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/project.pbxproj @@ -55,7 +55,9 @@ A922754C1517C094001B78AA /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A922754B1517C094001B78AA /* UIKit.framework */; }; A922754E1517C094001B78AA /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A922754D1517C094001B78AA /* Foundation.framework */; }; A92275501517C094001B78AA /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A922754F1517C094001B78AA /* CoreGraphics.framework */; }; + BA3A85EC1A724AE900924D24 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BA3A85EB1A724AE900924D24 /* Security.framework */; }; BA4E718119EB6E3F00932425 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BA4E718019EB6E3E00932425 /* MediaPlayer.framework */; }; + BAEE4D841AC40C11003BEB0F /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BAEE4D831AC40C11003BEB0F /* Security.framework */; }; BAF426FB19484B3E002B22EF /* script in Resources */ = {isa = PBXBuildFile; fileRef = BAF426FA19484B3E002B22EF /* script */; }; BAF426FC19484B3E002B22EF /* script in Resources */ = {isa = PBXBuildFile; fileRef = BAF426FA19484B3E002B22EF /* script */; }; C03780EB18BEE0E400FE4F13 /* src in Resources */ = {isa = PBXBuildFile; fileRef = C03780EA18BEE0E400FE4F13 /* src */; }; @@ -273,8 +275,10 @@ A922754B1517C094001B78AA /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; A922754D1517C094001B78AA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; A922754F1517C094001B78AA /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; + BA3A85EB1A724AE900924D24 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/System/Library/Frameworks/Security.framework; sourceTree = DEVELOPER_DIR; }; BA4E718019EB6E3E00932425 /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk/System/Library/Frameworks/MediaPlayer.framework; sourceTree = DEVELOPER_DIR; }; BA4E718219EB6E4600932425 /* GameController.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameController.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk/System/Library/Frameworks/GameController.framework; sourceTree = DEVELOPER_DIR; }; + BAEE4D831AC40C11003BEB0F /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; BAF426FA19484B3E002B22EF /* script */ = {isa = PBXFileReference; lastKnownFileType = folder; name = script; path = "../../js-bindings/bindings/script"; sourceTree = ""; }; C03780EA18BEE0E400FE4F13 /* src */ = {isa = PBXFileReference; lastKnownFileType = folder; name = src; path = ../../../src; sourceTree = ""; }; C037820118BF76AF00FE4F13 /* cocos2d_js_bindings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = cocos2d_js_bindings.xcodeproj; path = "../../js-bindings/bindings/proj.ios_mac/cocos2d_js_bindings.xcodeproj"; sourceTree = ""; }; @@ -291,6 +295,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + BAEE4D841AC40C11003BEB0F /* Security.framework in Frameworks */, C037820F18BF77DE00FE4F13 /* libjsbindings Mac.a in Frameworks */, 1A67682A180E9C060076BC67 /* libcocos2dx Mac.a in Frameworks */, 502380DC17EBB88200990C9B /* libcurl.dylib in Frameworks */, @@ -312,6 +317,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + BA3A85EC1A724AE900924D24 /* Security.framework in Frameworks */, BA4E718119EB6E3F00932425 /* MediaPlayer.framework in Frameworks */, C037820C18BF77C500FE4F13 /* libjsbindings iOS.a in Frameworks */, 1A676839180E9C1E0076BC67 /* libcocos2dx iOS.a in Frameworks */, @@ -418,6 +424,8 @@ A92275401517C094001B78AA /* Frameworks */ = { isa = PBXGroup; children = ( + BAEE4D831AC40C11003BEB0F /* Security.framework */, + BA3A85EB1A724AE900924D24 /* Security.framework */, BA4E718219EB6E4600932425 /* GameController.framework */, BA4E718019EB6E3E00932425 /* MediaPlayer.framework */, D6B061231803AB9F0077942B /* CoreMotion.framework */, diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win32/HelloJavascript.vcxproj b/templates/js-template-default/frameworks/runtime-src/proj.win32/HelloJavascript.vcxproj index 28c323f929..a272ed753b 100644 --- a/templates/js-template-default/frameworks/runtime-src/proj.win32/HelloJavascript.vcxproj +++ b/templates/js-template-default/frameworks/runtime-src/proj.win32/HelloJavascript.vcxproj @@ -102,28 +102,22 @@ if not exist "$(OutDir)" mkdir "$(OutDir)" -xcopy /Y /Q "$(ProjectDir)..\..\js-bindings\external\spidermonkey\prebuilt\win32\*.*" "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\..\js-bindings\external\spidermonkey\prebuilt\win32\debug-build\*.*" "$(OutDir)" xcopy /Y /Q "$(ProjectDir)..\..\js-bindings\cocos2d-x\external\websockets\prebuilt\win32\*.*" "$(OutDir)" - libcurl_imp.lib;mozjs-28.lib;ws2_32.lib;sqlite3.lib;websockets.lib;%(AdditionalDependencies) + libcurl_imp.lib;mozjs-33.lib;ws2_32.lib;sqlite3.lib;websockets.lib;%(AdditionalDependencies) $(OutDir);%(AdditionalLibraryDirectories) true Windows MachineX86 - if not exist "$(OutDir)" mkdir "$(OutDir)" -if exist "$(OutDir)\Resource" rd /s /q "$(OutDir)\Resource" -mkdir "$(OutDir)\Resource" -mkdir "$(OutDir)\Resource\script" -mkdir "$(OutDir)\Resource\src" -mkdir "$(OutDir)\Resource\res" -xcopy "$(ProjectDir)..\..\js-bindings\bindings\script" "$(OutDir)\Resource\script" /e /Y -xcopy "$(ProjectDir)..\..\..\src" "$(OutDir)\Resource\src" /e /Y -copy "$(ProjectDir)..\..\..\main.js" "$(OutDir)\Resource\main.js" /Y -copy "$(ProjectDir)..\..\..\project.json" "$(OutDir)\Resource\project.json" /Y -xcopy "$(ProjectDir)..\..\..\res" "$(OutDir)\Resource\res" /e /Y + xcopy "$(ProjectDir)..\..\js-bindings\bindings\script" "$(OutDir)\script" /D /E /I /F /Y +xcopy "$(ProjectDir)..\..\..\src" "$(OutDir)\src" /D /E /I /F /Y +xcopy "$(ProjectDir)..\..\..\res" "$(OutDir)\res" /D /E /I /F /Y +copy "$(ProjectDir)..\..\..\main.js" "$(OutDir)\" /Y +copy "$(ProjectDir)..\..\..\project.json" "$(OutDir)\" /Y Copy js and resource files. @@ -163,28 +157,22 @@ xcopy "$(ProjectDir)..\..\..\res" "$(OutDir)\Resource\res" /e /Y if not exist "$(OutDir)" mkdir "$(OutDir)" -xcopy /Y /Q "$(ProjectDir)..\..\js-bindings\external\spidermonkey\prebuilt\win32\*.*" "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\..\js-bindings\external\spidermonkey\prebuilt\win32\release-build\*.*" "$(OutDir)" xcopy /Y /Q "$(ProjectDir)..\..\js-bindings\cocos2d-x\external\websockets\prebuilt\win32\*.*" "$(OutDir)" - libcurl_imp.lib;mozjs-28.lib;ws2_32.lib;sqlite3.lib;websockets.lib;%(AdditionalDependencies) + libcurl_imp.lib;mozjs-33.lib;ws2_32.lib;sqlite3.lib;websockets.lib;%(AdditionalDependencies) $(OutDir);%(AdditionalLibraryDirectories) Windows MachineX86 true - if not exist "$(OutDir)" mkdir "$(OutDir)" -if exist "$(OutDir)\Resource" rd /s /q "$(OutDir)\Resource" -mkdir "$(OutDir)\Resource" -mkdir "$(OutDir)\Resource\script" -mkdir "$(OutDir)\Resource\src" -mkdir "$(OutDir)\Resource\res" -xcopy "$(ProjectDir)..\..\js-bindings\bindings\script" "$(OutDir)\Resource\script" /e /Y -xcopy "$(ProjectDir)..\..\..\src" "$(OutDir)\Resource\src" /e /Y -copy "$(ProjectDir)..\..\..\main.js" "$(OutDir)\Resource\main.js" /Y -copy "$(ProjectDir)..\..\..\project.json" "$(OutDir)\Resource\project.json" /Y -xcopy "$(ProjectDir)..\..\..\res" "$(OutDir)\Resource\res" /e /Y + xcopy "$(ProjectDir)..\..\js-bindings\bindings\script" "$(OutDir)\script" /D /E /I /F /Y +xcopy "$(ProjectDir)..\..\..\src" "$(OutDir)\src" /D /E /I /F /Y +xcopy "$(ProjectDir)..\..\..\res" "$(OutDir)\res" /D /E /I /F /Y +copy "$(ProjectDir)..\..\..\main.js" "$(OutDir)\" /Y +copy "$(ProjectDir)..\..\..\project.json" "$(OutDir)\" /Y Copy js and resource files. diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win32/HelloJavascript.vcxproj.user b/templates/js-template-default/frameworks/runtime-src/proj.win32/HelloJavascript.vcxproj.user index 94d5dca826..bc2c507e26 100644 --- a/templates/js-template-default/frameworks/runtime-src/proj.win32/HelloJavascript.vcxproj.user +++ b/templates/js-template-default/frameworks/runtime-src/proj.win32/HelloJavascript.vcxproj.user @@ -1,11 +1,11 @@  - $(OutDir)\Resource + $(OutDir) WindowsLocalDebugger - $(OutDir)\Resource + $(OutDir) WindowsLocalDebugger \ No newline at end of file diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/App.xaml b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/App.xaml new file mode 100644 index 0000000000..7c15a5d78f --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/App.xaml @@ -0,0 +1,13 @@ + + + + + cpp_tests + + + diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/App.xaml.cpp b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/App.xaml.cpp new file mode 100644 index 0000000000..07cd4853e6 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/App.xaml.cpp @@ -0,0 +1,21 @@ +#include "App.xaml.h" +#include "OpenGLESPage.xaml.h" + +using namespace cocos2d; + +App::App() +{ + InitializeComponent(); +} + +void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) +{ + if (mPage == nullptr) + { + mPage = ref new OpenGLESPage(&mOpenGLES); + } + + // Place the page in the current window and ensure that it is active. + Windows::UI::Xaml::Window::Current->Content = mPage; + Windows::UI::Xaml::Window::Current->Activate(); +} diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/App.xaml.h b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/App.xaml.h new file mode 100644 index 0000000000..ce4d7c8bfd --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/App.xaml.h @@ -0,0 +1,19 @@ +#pragma once + +#include "app.g.h" +#include "OpenGLES.h" +#include "openglespage.xaml.h" + +namespace cocos2d +{ + ref class App sealed + { + public: + App(); + virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) override; + + private: + OpenGLESPage^ mPage; + OpenGLES mOpenGLES; + }; +} diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/Cocos2dRenderer.cpp b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/Cocos2dRenderer.cpp new file mode 100644 index 0000000000..78803b7441 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/Cocos2dRenderer.cpp @@ -0,0 +1,143 @@ +/* +* cocos2d-x http://www.cocos2d-x.org +* +* Copyright (c) 2010-2014 - cocos2d-x community +* +* Portions Copyright (c) Microsoft Open Technologies, Inc. +* All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and limitations under the License. +*/ + +#include "Cocos2dRenderer.h" +#include "AppDelegate.h" +#include "CCGLViewImpl-winrt.h" +#include "CCApplication.h" +#include "cocos2d.h" +#include "renderer/CCTextureCache.h" + +// These are used by the shader compilation methods. +#include +#include +#include + +using namespace Platform; +using namespace Windows::UI::Core; +using namespace Windows::UI::Xaml::Controls; +using namespace Windows::Graphics::Display; + +USING_NS_CC; + + +Cocos2dRenderer::Cocos2dRenderer(int width, int height, float dpi, DisplayOrientations orientation, CoreDispatcher^ dispatcher, Panel^ panel) + : m_app(nullptr) + , m_width(width) + , m_height(height) + , m_dpi(dpi) + , m_dispatcher(dispatcher) + , m_panel(panel) + , m_orientation(orientation) +{ + m_app = new AppDelegate(); +} + +Cocos2dRenderer::~Cocos2dRenderer() +{ + delete m_app; +} + +void Cocos2dRenderer::Resume() +{ + auto director = cocos2d::Director::getInstance(); + auto glview = director->getOpenGLView(); + + if (!glview) + { + GLViewImpl* glview = GLViewImpl::create("Test Cpp"); + glview->setDispatcher(m_dispatcher.Get()); + glview->setPanel(m_panel.Get()); + glview->Create(static_cast(m_width), static_cast(m_height), m_dpi, m_orientation); + director->setOpenGLView(glview); + CCApplication::getInstance()->run(); + } + else + { + Application::getInstance()->applicationWillEnterForeground(); + } +} + +void Cocos2dRenderer::Pause() +{ + if (Director::getInstance()->getOpenGLView()) { + Application::getInstance()->applicationDidEnterBackground(); + //cocos2d::EventCustom backgroundEvent(EVENT_COME_TO_BACKGROUND); + //cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&backgroundEvent); + } +} + +void Cocos2dRenderer::DeviceLost() +{ + Pause(); + + auto director = cocos2d::Director::getInstance(); + if (director->getOpenGLView()) { + cocos2d::GL::invalidateStateCache(); + cocos2d::GLProgramCache::getInstance()->reloadDefaultGLPrograms(); + cocos2d::DrawPrimitives::init(); + cocos2d::VolatileTextureMgr::reloadAllTextures(); + + cocos2d::EventCustom recreatedEvent(EVENT_RENDERER_RECREATED); + director->getEventDispatcher()->dispatchEvent(&recreatedEvent); + director->setGLDefaultValues(); + + Application::getInstance()->applicationWillEnterForeground(); + cocos2d::EventCustom foregroundEvent(EVENT_COME_TO_FOREGROUND); + cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&foregroundEvent); + } +} + + + +void Cocos2dRenderer::Draw(GLsizei width, GLsizei height, float dpi, DisplayOrientations orientation) +{ + if (orientation != m_orientation) + { + m_orientation = orientation; + GLViewImpl::sharedOpenGLView()->UpdateOrientation(orientation); + } + + if (width != m_width || height != m_height) + { + m_width = width; + m_height = height; + GLViewImpl::sharedOpenGLView()->UpdateForWindowSizeChange(static_cast(width), static_cast(height)); + } + + if (dpi != m_dpi) + { + m_dpi = dpi; + GLViewImpl::sharedOpenGLView()->SetDPI(m_dpi); + } + + GLViewImpl::sharedOpenGLView()->ProcessEvents(); + GLViewImpl::sharedOpenGLView()->Render(); +} + +void Cocos2dRenderer::QueuePointerEvent(cocos2d::PointerEventType type, Windows::UI::Core::PointerEventArgs^ args) +{ + GLViewImpl::sharedOpenGLView()->QueuePointerEvent(type, args); +} + +void Cocos2dRenderer::QueueKeyBoardEvent(cocos2d::Cocos2dKeyEvent type, Windows::UI::Core::KeyEventArgs^ e) +{ + //GLViewImpl::sharedOpenGLView()->QueuePointerEvent(type, e); +} + + diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/Cocos2dRenderer.h b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/Cocos2dRenderer.h new file mode 100644 index 0000000000..c29e5d7852 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/Cocos2dRenderer.h @@ -0,0 +1,55 @@ +/* +* cocos2d-x http://www.cocos2d-x.org +* +* Copyright (c) 2010-2014 - cocos2d-x community +* +* Portions Copyright (c) Microsoft Open Technologies, Inc. +* All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and limitations under the License. +*/ +#pragma once + +#include + +#include "cocos2d.h" + + +class AppDelegate; + +namespace cocos2d +{ + class Cocos2dRenderer + { + public: + Cocos2dRenderer(int width, int height, float dpi, + Windows::Graphics::Display::DisplayOrientations orientation, + Windows::UI::Core::CoreDispatcher^ dispathcer, Windows::UI::Xaml::Controls::Panel^ panel); + ~Cocos2dRenderer(); + void Draw(GLsizei width, GLsizei height, float dpi, Windows::Graphics::Display::DisplayOrientations orientation); + void QueuePointerEvent(PointerEventType type, Windows::UI::Core::PointerEventArgs^ args); + void QueueKeyBoardEvent(Cocos2dKeyEvent type, Windows::UI::Core::KeyEventArgs^ e); + void Pause(); + void Resume(); + void DeviceLost(); + + private: + + int m_width; + int m_height; + float m_dpi; + + // The AppDelegate for the Cocos2D app + AppDelegate* m_app; + Platform::Agile m_dispatcher; + Platform::Agile m_panel; + Windows::Graphics::Display::DisplayOrientations m_orientation; + }; +} \ No newline at end of file diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/HelloJavascript.Shared.vcxitems b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/HelloJavascript.Shared.vcxitems new file mode 100644 index 0000000000..4dc3ec2403 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/HelloJavascript.Shared.vcxitems @@ -0,0 +1,59 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + e956c24b-f04e-47bf-bf00-746681ae1301 + {a3ad93e4-0b2f-4c58-9181-69bed2e42e3e} + HelloJavascript + + + + %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) + + + + + Designer + + + + $(MSBuildThisFileDirectory)App.xaml + + + + + $(MSBuildThisFileDirectory)OpenGLESPage.xaml + + + + $(MSBuildThisFileDirectory)App.xaml + + + Create + + + + $(MSBuildThisFileDirectory)OpenGLESPage.xaml + + + + + + + + <_CustomResource Include="$(MSBuildThisFileDirectory)..\..\Resources\**\*"> + Assets\Resources\%(RecursiveDir)%(FileName)%(Extension) + true + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/HelloJavascript.Shared.vcxitems.filters b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/HelloJavascript.Shared.vcxitems.filters new file mode 100644 index 0000000000..1f39a29df9 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/HelloJavascript.Shared.vcxitems.filters @@ -0,0 +1,33 @@ + + + + + + + + + + + + Classes + + + + + + + + {38ad799c-8c3c-44a2-8e41-516c8f62f556} + + + + + + + Classes + + + + + + \ No newline at end of file diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLES.cpp b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLES.cpp new file mode 100644 index 0000000000..56a9b1da0d --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLES.cpp @@ -0,0 +1,239 @@ +/* +* cocos2d-x http://www.cocos2d-x.org +* +* Copyright (c) 2010-2014 - cocos2d-x community +* +* Portions Copyright (c) Microsoft Open Technologies, Inc. +* All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and limitations under the License. +*/ + +#include "OpenGLES.h" +using namespace Platform; +using namespace Windows::UI::Xaml::Controls; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; + +OpenGLES::OpenGLES() : + mEglConfig(nullptr), + mEglDisplay(EGL_NO_DISPLAY), + mEglContext(EGL_NO_CONTEXT) +{ + Initialize(); +} + +OpenGLES::~OpenGLES() +{ + Cleanup(); +} + +void OpenGLES::Initialize() +{ + const EGLint configAttributes[] = + { + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, + EGL_DEPTH_SIZE, 8, + EGL_STENCIL_SIZE, 8, + EGL_NONE + }; + + const EGLint contextAttributes[] = + { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + + const EGLint defaultDisplayAttributes[] = + { + // These are the default display attributes, used to request ANGLE's D3D11 renderer. + // eglInitialize will only succeed with these attributes if the hardware supports D3D11 Feature Level 10_0+. + EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, + + // EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER is an optimization that can have large performance benefits on mobile devices. + // Its syntax is subject to change, though. Please update your Visual Studio templates if you experience compilation issues with it. + EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_NONE, + }; + + const EGLint fl9_3DisplayAttributes[] = + { + // These can be used to request ANGLE's D3D11 renderer, with D3D11 Feature Level 9_3. + // These attributes are used if the call to eglInitialize fails with the default display attributes. + EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, + EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9, + EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3, + EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_NONE, + }; + + const EGLint warpDisplayAttributes[] = + { + // These attributes can be used to request D3D11 WARP. + // They are used if eglInitialize fails with both the default display attributes and the 9_3 display attributes. + EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, + EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE, + EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_NONE, + }; + + EGLConfig config = NULL; + + // eglGetPlatformDisplayEXT is an alternative to eglGetDisplay. It allows us to pass in display attributes, used to configure D3D11. + PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = reinterpret_cast(eglGetProcAddress("eglGetPlatformDisplayEXT")); + if (!eglGetPlatformDisplayEXT) + { + throw Exception::CreateException(E_FAIL, L"Failed to get function eglGetPlatformDisplayEXT"); + } + + // + // To initialize the display, we make three sets of calls to eglGetPlatformDisplayEXT and eglInitialize, with varying + // parameters passed to eglGetPlatformDisplayEXT: + // 1) The first calls uses "defaultDisplayAttributes" as a parameter. This corresponds to D3D11 Feature Level 10_0+. + // 2) If eglInitialize fails for step 1 (e.g. because 10_0+ isn't supported by the default GPU), then we try again + // using "fl9_3DisplayAttributes". This corresponds to D3D11 Feature Level 9_3. + // 3) If eglInitialize fails for step 2 (e.g. because 9_3+ isn't supported by the default GPU), then we try again + // using "warpDisplayAttributes". This corresponds to D3D11 Feature Level 11_0 on WARP, a D3D11 software rasterizer. + // + // Note: On Windows Phone, we #ifdef out the first set of calls to eglPlatformDisplayEXT and eglInitialize. + // Windows Phones devices only support D3D11 Feature Level 9_3, but the Windows Phone emulator supports 11_0+. + // We use this #ifdef to limit the Phone emulator to Feature Level 9_3, making it behave more like + // real Windows Phone devices. + // If you wish to test Feature Level 10_0+ in the Windows Phone emulator then you should remove this #ifdef. + // + +#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) + // This tries to initialize EGL to D3D11 Feature Level 10_0+. See above comment for details. + mEglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, defaultDisplayAttributes); + if (mEglDisplay == EGL_NO_DISPLAY) + { + throw Exception::CreateException(E_FAIL, L"Failed to get EGL display"); + } + + if (eglInitialize(mEglDisplay, NULL, NULL) == EGL_FALSE) +#endif + { + // This tries to initialize EGL to D3D11 Feature Level 9_3, if 10_0+ is unavailable (e.g. on Windows Phone, or certain Windows tablets). + mEglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, fl9_3DisplayAttributes); + if (mEglDisplay == EGL_NO_DISPLAY) + { + throw Exception::CreateException(E_FAIL, L"Failed to get EGL display"); + } + + if (eglInitialize(mEglDisplay, NULL, NULL) == EGL_FALSE) + { + // This initializes EGL to D3D11 Feature Level 11_0 on WARP, if 9_3+ is unavailable on the default GPU (e.g. on Surface RT). + mEglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, warpDisplayAttributes); + if (mEglDisplay == EGL_NO_DISPLAY) + { + throw Exception::CreateException(E_FAIL, L"Failed to get EGL display"); + } + + if (eglInitialize(mEglDisplay, NULL, NULL) == EGL_FALSE) + { + // If all of the calls to eglInitialize returned EGL_FALSE then an error has occurred. + throw Exception::CreateException(E_FAIL, L"Failed to initialize EGL"); + } + } + } + + EGLint numConfigs = 0; + if ((eglChooseConfig(mEglDisplay, configAttributes, &mEglConfig, 1, &numConfigs) == EGL_FALSE) || (numConfigs == 0)) + { + throw Exception::CreateException(E_FAIL, L"Failed to choose first EGLConfig"); + } + + mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, contextAttributes); + if (mEglContext == EGL_NO_CONTEXT) + { + throw Exception::CreateException(E_FAIL, L"Failed to create EGL context"); + } +} + +void OpenGLES::Cleanup() +{ + if (mEglDisplay != EGL_NO_DISPLAY && mEglContext != EGL_NO_CONTEXT) + { + eglDestroyContext(mEglDisplay, mEglContext); + mEglContext = EGL_NO_CONTEXT; + } + + if (mEglDisplay != EGL_NO_DISPLAY) + { + eglTerminate(mEglDisplay); + mEglDisplay = EGL_NO_DISPLAY; + } +} + +void OpenGLES::Reset() +{ + Cleanup(); + Initialize(); +} + +EGLSurface OpenGLES::CreateSurface(SwapChainPanel^ panel, const Size* renderSurfaceSize) +{ + if (!panel) + { + throw Exception::CreateException(E_INVALIDARG, L"SwapChainPanel parameter is invalid"); + } + + EGLSurface surface = EGL_NO_SURFACE; + + const EGLint surfaceAttributes[] = + { + // EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER is part of the same optimization as EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER (see above). + // If you have compilation issues with it then please update your Visual Studio templates. + EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_NONE + }; + + // Create a PropertySet and initialize with the EGLNativeWindowType. + PropertySet^ surfaceCreationProperties = ref new PropertySet(); + surfaceCreationProperties->Insert(ref new String(EGLNativeWindowTypeProperty), panel); + + // If a render surface size is specified, add it to the surface creation properties + if (renderSurfaceSize != nullptr) + { + surfaceCreationProperties->Insert(ref new String(EGLRenderSurfaceSizeProperty), PropertyValue::CreateSize(*renderSurfaceSize)); + } + + surface = eglCreateWindowSurface(mEglDisplay, mEglConfig, reinterpret_cast(surfaceCreationProperties), surfaceAttributes); + if (surface == EGL_NO_SURFACE) + { + throw Exception::CreateException(E_FAIL, L"Failed to create EGL surface"); + } + + return surface; +} + +void OpenGLES::DestroySurface(const EGLSurface surface) +{ + if (mEglDisplay != EGL_NO_DISPLAY && surface != EGL_NO_SURFACE) + { + eglDestroySurface(mEglDisplay, surface); + } +} + +void OpenGLES::MakeCurrent(const EGLSurface surface) +{ + if (eglMakeCurrent(mEglDisplay, surface, surface, mEglContext) == EGL_FALSE) + { + throw Exception::CreateException(E_FAIL, L"Failed to make EGLSurface current"); + } +} + +EGLBoolean OpenGLES::SwapBuffers(const EGLSurface surface) +{ + return (eglSwapBuffers(mEglDisplay, surface)); +} diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLES.h b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLES.h new file mode 100644 index 0000000000..640b233614 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLES.h @@ -0,0 +1,51 @@ +/* +* cocos2d-x http://www.cocos2d-x.org +* +* Copyright (c) 2010-2014 - cocos2d-x community +* +* Portions Copyright (c) Microsoft Open Technologies, Inc. +* All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and limitations under the License. +*/ + +#pragma once + +// OpenGL ES includes +#include +#include + +// EGL includes +#include +#include +#include +#include + +class OpenGLES +{ +public: + OpenGLES(); + ~OpenGLES(); + + EGLSurface CreateSurface(Windows::UI::Xaml::Controls::SwapChainPanel^ panel, const Windows::Foundation::Size* renderSurfaceSize); + void DestroySurface(const EGLSurface surface); + void MakeCurrent(const EGLSurface surface); + EGLBoolean SwapBuffers(const EGLSurface surface); + void Reset(); + +private: + void Initialize(); + void Cleanup(); + +private: + EGLDisplay mEglDisplay; + EGLContext mEglContext; + EGLConfig mEglConfig; +}; diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml new file mode 100644 index 0000000000..2e15f8140d --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml @@ -0,0 +1,28 @@ + + + + + + + + + + + diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.cpp b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.cpp new file mode 100644 index 0000000000..5f12e22a94 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.cpp @@ -0,0 +1,330 @@ +/* +* cocos2d-x http://www.cocos2d-x.org +* +* Copyright (c) 2010-2014 - cocos2d-x community +* +* Portions Copyright (c) Microsoft Open Technologies, Inc. +* All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and limitations under the License. +*/ + +#include "App.xaml.h" +#include "OpenGLESPage.xaml.h" + +using namespace cocos2d; +using namespace Platform; +using namespace Concurrency; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::Graphics::Display; +using namespace Windows::System::Threading; +using namespace Windows::UI::Core; +using namespace Windows::UI::Input; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +using namespace Windows::UI::Xaml::Controls::Primitives; +using namespace Windows::UI::Xaml::Data; +using namespace Windows::UI::Xaml::Input; +using namespace Windows::UI::Xaml::Media; +using namespace Windows::UI::Xaml::Navigation; + +#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) +using namespace Windows::Phone::UI::Input; +#endif + +OpenGLESPage::OpenGLESPage() : + OpenGLESPage(nullptr) +{ + +} + +OpenGLESPage::OpenGLESPage(OpenGLES* openGLES) : + mOpenGLES(openGLES), + mRenderSurface(EGL_NO_SURFACE), + mCustomRenderSurfaceSize(0,0), + mUseCustomRenderSurfaceSize(false), + m_coreInput(nullptr), + m_dpi(0.0f), + m_visible(false), + m_deviceLost(false), + m_orientation(DisplayOrientations::Landscape) +{ + InitializeComponent(); + + Windows::UI::Core::CoreWindow^ window = Windows::UI::Xaml::Window::Current->CoreWindow; + + window->VisibilityChanged += + ref new Windows::Foundation::TypedEventHandler(this, &OpenGLESPage::OnVisibilityChanged); + + swapChainPanel->SizeChanged += + ref new Windows::UI::Xaml::SizeChangedEventHandler(this, &OpenGLESPage::OnSwapChainPanelSizeChanged); + + DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); + + currentDisplayInformation->OrientationChanged += + ref new TypedEventHandler(this, &OpenGLESPage::OnOrientationChanged); + + m_orientation = currentDisplayInformation->CurrentOrientation; + + this->Loaded += + ref new Windows::UI::Xaml::RoutedEventHandler(this, &OpenGLESPage::OnPageLoaded); + + mSwapChainPanelSize = { swapChainPanel->RenderSize.Width, swapChainPanel->RenderSize.Height }; + +#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) + Windows::UI::ViewManagement::StatusBar::GetForCurrentView()->HideAsync(); + HardwareButtons::BackPressed += ref new EventHandler(this, &OpenGLESPage::OnBackButtonPressed); +#else + // Disable all pointer visual feedback for better performance when touching. + // This is not supported on Windows Phone applications. + auto pointerVisualizationSettings = Windows::UI::Input::PointerVisualizationSettings::GetForCurrentView(); + pointerVisualizationSettings->IsContactFeedbackEnabled = false; + pointerVisualizationSettings->IsBarrelButtonFeedbackEnabled = false; +#endif + + // Register our SwapChainPanel to get independent input pointer events + auto workItemHandler = ref new WorkItemHandler([this](IAsyncAction ^) + { + // The CoreIndependentInputSource will raise pointer events for the specified device types on whichever thread it's created on. + m_coreInput = swapChainPanel->CreateCoreIndependentInputSource( + Windows::UI::Core::CoreInputDeviceTypes::Mouse | + Windows::UI::Core::CoreInputDeviceTypes::Touch | + Windows::UI::Core::CoreInputDeviceTypes::Pen + ); + + // Register for pointer events, which will be raised on the background thread. + m_coreInput->PointerPressed += ref new TypedEventHandler(this, &OpenGLESPage::OnPointerPressed); + m_coreInput->PointerMoved += ref new TypedEventHandler(this, &OpenGLESPage::OnPointerMoved); + m_coreInput->PointerReleased += ref new TypedEventHandler(this, &OpenGLESPage::OnPointerReleased); + + // Begin processing input messages as they're delivered. + m_coreInput->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit); + }); + + // Run task on a dedicated high priority background thread. + m_inputLoopWorker = ThreadPool::RunAsync(workItemHandler, WorkItemPriority::High, WorkItemOptions::TimeSliced); + +} + +OpenGLESPage::~OpenGLESPage() +{ + StopRenderLoop(); + DestroyRenderSurface(); +} + +void OpenGLESPage::OnPageLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + // The SwapChainPanel has been created and arranged in the page layout, so EGL can be initialized. + CreateRenderSurface(); + m_visible = true; + StartRenderLoop(); +} + +void OpenGLESPage::OnPointerPressed(Object^ sender, PointerEventArgs^ e) +{ + if (m_renderer) + { + m_renderer->QueuePointerEvent(PointerEventType::PointerPressed, e); + } +} + +void OpenGLESPage::OnPointerMoved(Object^ sender, PointerEventArgs^ e) +{ + if (m_renderer) + { + m_renderer->QueuePointerEvent(PointerEventType::PointerMoved, e); + } +} + +void OpenGLESPage::OnPointerReleased(Object^ sender, PointerEventArgs^ e) +{ + if (m_renderer) + { + m_renderer->QueuePointerEvent(PointerEventType::PointerReleased, e); + } +} + +void OpenGLESPage::OnOrientationChanged(DisplayInformation^ sender, Object^ args) +{ + critical_section::scoped_lock lock(mSwapChainPanelSizeCriticalSection); + m_orientation = sender->CurrentOrientation; +} + +void OpenGLESPage::OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args) +{ + if (args->Visible && mRenderSurface != EGL_NO_SURFACE) + { + m_visible = true; + } + else + { + m_visible = false; + } +} + +#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) +void OpenGLESPage::OnBackButtonPressed(Object^ sender, BackPressedEventArgs^ args) +{ + bool myAppCanNavigate = false; + if (myAppCanNavigate) + { + args->Handled = true; + } + else { + // Do nothing. Leave args->Handled set to the current value, false. + } +} +#endif + + +void OpenGLESPage::OnSwapChainPanelSizeChanged(Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e) +{ + // Size change events occur outside of the render thread. A lock is required when updating + // the swapchainpanel size + critical_section::scoped_lock lock(mSwapChainPanelSizeCriticalSection); + mSwapChainPanelSize = { e->NewSize.Width, e->NewSize.Height }; +} + +void OpenGLESPage::GetSwapChainPanelSize(GLsizei* width, GLsizei* height) +{ + critical_section::scoped_lock lock(mSwapChainPanelSizeCriticalSection); + // If a custom render surface size is specified, return its size instead of + // the swapchain panel size. + if (mUseCustomRenderSurfaceSize) + { + *width = static_cast(mCustomRenderSurfaceSize.Width); + *height = static_cast(mCustomRenderSurfaceSize.Height); + } + else + { + *width = static_cast(mSwapChainPanelSize.Width); + *height = static_cast(mSwapChainPanelSize.Height); + } +} + +void OpenGLESPage::CreateRenderSurface() +{ + if (mOpenGLES) + { + // + // A Custom render surface size can be specified by uncommenting the following lines. + // The render surface will be automatically scaled to fit the entire window. Using a + // smaller sized render surface can result in a performance gain. + // + //mCustomRenderSurfaceSize = Size(800, 600); + //mUseCustomRenderSurfaceSize = true; + + mRenderSurface = mOpenGLES->CreateSurface(swapChainPanel, mUseCustomRenderSurfaceSize ? &mCustomRenderSurfaceSize : nullptr); + } +} + +void OpenGLESPage::DestroyRenderSurface() +{ + if (mOpenGLES) + { + mOpenGLES->DestroySurface(mRenderSurface); + } + mRenderSurface = EGL_NO_SURFACE; +} + +void OpenGLESPage::RecoverFromLostDevice() +{ + // resets OpenGLES, recreates the render surface + DestroyRenderSurface(); + mOpenGLES->Reset(); + CreateRenderSurface(); +} + +void OpenGLESPage::StartRenderLoop() +{ + // If the render loop is already running then do not start another thread. + if (mRenderLoopWorker != nullptr && mRenderLoopWorker->Status == Windows::Foundation::AsyncStatus::Started) + { + return; + } + + DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); + m_dpi = currentDisplayInformation->LogicalDpi; + + auto dispatcher = Windows::UI::Xaml::Window::Current->CoreWindow->Dispatcher; + + // Create a task for rendering that will be run on a background thread. + auto workItemHandler = ref new Windows::System::Threading::WorkItemHandler([this, dispatcher](Windows::Foundation::IAsyncAction ^ action) + { + mOpenGLES->MakeCurrent(mRenderSurface); + GLsizei panelWidth = 0; + GLsizei panelHeight = 0; + GetSwapChainPanelSize(&panelWidth, &panelHeight); + + if (m_renderer.get() == nullptr) + { + m_renderer = std::make_shared(panelWidth, panelHeight, m_dpi, m_orientation, dispatcher, swapChainPanel); + } + + m_renderer->Resume(); + + while (action->Status == Windows::Foundation::AsyncStatus::Started) + { + if (!m_visible) + { + m_renderer->Pause(); + while (!m_visible) + { + if (action->Status != Windows::Foundation::AsyncStatus::Started) + { + return; + } + Sleep(500); + } + m_renderer->Resume(); + } + + GetSwapChainPanelSize(&panelWidth, &panelHeight); + m_renderer.get()->Draw(panelWidth, panelHeight, m_dpi, m_orientation); + + // The call to eglSwapBuffers might not be successful (i.e. due to Device Lost) + // If the call fails, then we must reinitialize EGL and the GL resources. + if (mOpenGLES->SwapBuffers(mRenderSurface) != GL_TRUE) + { + m_deviceLost = true; + + // XAML objects like the SwapChainPanel must only be manipulated on the UI thread. + swapChainPanel->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([=]() + { + RecoverFromLostDevice(); + }, CallbackContext::Any)); + + while(m_deviceLost) + { + if (action->Status != Windows::Foundation::AsyncStatus::Started) + { + return; + } + Sleep(500); + } + mOpenGLES->MakeCurrent(mRenderSurface); + m_renderer->DeviceLost(); + } + } + }); + + // Run task on a dedicated high priority background thread. + mRenderLoopWorker = Windows::System::Threading::ThreadPool::RunAsync(workItemHandler, Windows::System::Threading::WorkItemPriority::High, Windows::System::Threading::WorkItemOptions::TimeSliced); +} + +void OpenGLESPage::StopRenderLoop() +{ + if (mRenderLoopWorker) + { + mRenderLoopWorker->Cancel(); + mRenderLoopWorker = nullptr; + } +} \ No newline at end of file diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.h b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.h new file mode 100644 index 0000000000..daddd59e23 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.h @@ -0,0 +1,82 @@ +/* +* cocos2d-x http://www.cocos2d-x.org +* +* Copyright (c) 2010-2014 - cocos2d-x community +* +* Portions Copyright (c) Microsoft Open Technologies, Inc. +* All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and limitations under the License. +*/ + +#pragma once + +#include "OpenGLES.h" +#include "OpenGLESPage.g.h" +#include +#include + +#include "Cocos2dRenderer.h" + +namespace cocos2d +{ + public ref class OpenGLESPage sealed + { + public: + OpenGLESPage(); + virtual ~OpenGLESPage(); + + internal: + OpenGLESPage(OpenGLES* openGLES); + + private: + void OnPageLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); + void OnSwapChainPanelSizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e); +#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) + void OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args); +#endif + void GetSwapChainPanelSize(GLsizei* width, GLsizei* height); + void CreateRenderSurface(); + void DestroyRenderSurface(); + void RecoverFromLostDevice(); + void StartRenderLoop(); + void StopRenderLoop(); + + OpenGLES* mOpenGLES; + std::shared_ptr m_renderer; + + Windows::Foundation::Size mSwapChainPanelSize; + Concurrency::critical_section mSwapChainPanelSizeCriticalSection; + + Windows::Foundation::Size mCustomRenderSurfaceSize; + bool mUseCustomRenderSurfaceSize; + + EGLSurface mRenderSurface; // This surface is associated with a swapChainPanel on the page + Windows::Foundation::IAsyncAction^ mRenderLoopWorker; + + // Track user input on a background worker thread. + Windows::Foundation::IAsyncAction^ m_inputLoopWorker; + Windows::UI::Core::CoreIndependentInputSource^ m_coreInput; + + // Independent input handling functions. + void OnPointerPressed(Platform::Object^ sender, Windows::UI::Core::PointerEventArgs^ e); + void OnPointerMoved(Platform::Object^ sender, Windows::UI::Core::PointerEventArgs^ e); + void OnPointerReleased(Platform::Object^ sender, Windows::UI::Core::PointerEventArgs^ e); + + void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); + + float m_dpi; + std::atomic m_visible; + std::atomic m_deviceLost; + Windows::Graphics::Display::DisplayOrientations m_orientation; + + }; +} diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/pch.cpp b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/pch.cpp new file mode 100644 index 0000000000..e0d2ef1a2a --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/pch.h b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/pch.h new file mode 100644 index 0000000000..97049bb300 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Shared/pch.h @@ -0,0 +1,13 @@ +// +// pch.h +// Header for standard system include files. +// + +#pragma once + +#include "mozilla\Char16.h" +#include "cocos2d.h" +#include "cocos-ext.h" + + + diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Assets/Logo.scale-100.png b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Assets/Logo.scale-100.png new file mode 100644 index 0000000000..e26771cb33 Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Assets/Logo.scale-100.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Assets/SmallLogo.scale-100.png b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Assets/SmallLogo.scale-100.png new file mode 100644 index 0000000000..1eb0d9d528 Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Assets/SmallLogo.scale-100.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Assets/SplashScreen.scale-100.png b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Assets/SplashScreen.scale-100.png new file mode 100644 index 0000000000..d8ded7198a Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Assets/SplashScreen.scale-100.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Assets/StoreLogo.scale-100.png b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Assets/StoreLogo.scale-100.png new file mode 100644 index 0000000000..dcb672712c Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Assets/StoreLogo.scale-100.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/HelloJavascript.Windows.vcxproj b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/HelloJavascript.Windows.vcxproj new file mode 100644 index 0000000000..bc697a131f --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/HelloJavascript.Windows.vcxproj @@ -0,0 +1,201 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM + + + Release + Win32 + + + Release + x64 + + + + {79a8fcda-4b12-4dd1-b676-ff148d651638} + cocos2d + en-US + 12.0 + true + Windows Store + 8.1 + + + + Application + true + v120 + + + Application + true + v120 + + + Application + true + v120 + + + Application + false + true + v120 + + + Application + false + true + v120 + + + Application + false + true + v120 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TemporaryKey.pfx + True + x86 + + + + /bigobj /Zm200 %(AdditionalOptions) + 4453;28204;4756;%(DisableSpecificWarnings) + pch.h + $(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4453;28204;4756;%(DisableSpecificWarnings) + pch.h + $(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4453;28204;4756;%(DisableSpecificWarnings) + pch.h + $(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4453;28204;4756;%(DisableSpecificWarnings) + pch.h + $(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4453;28204;4756;%(DisableSpecificWarnings) + pch.h + $(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4453;28204;4756;%(DisableSpecificWarnings) + pch.h + $(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + false + + + + + Designer + + + + + + + + + + + + {bcf5546d-66a0-4998-afd6-c5514f618930} + + + {9335005f-678e-4e8e-9b84-50037216aec8} + + + {f3550fe0-c795-44f6-8feb-093eb68143ae} + + + {3b26a12d-3a44-47ea-82d2-282660fc844d} + + + + + + \ No newline at end of file diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/HelloJavascript.Windows.vcxproj.filters b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/HelloJavascript.Windows.vcxproj.filters new file mode 100644 index 0000000000..60e410929e --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/HelloJavascript.Windows.vcxproj.filters @@ -0,0 +1,29 @@ + + + + + {1a9fa652-867e-41d2-8588-962f108d2d8f} + bmp;fbx;gif;jpg;jpeg;tga;tiff;tif;png + + + + + + + + + + + Assets + + + Assets + + + Assets + + + Assets + + + \ No newline at end of file diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Package.appxmanifest b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Package.appxmanifest new file mode 100644 index 0000000000..b828c3eadd --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/Package.appxmanifest @@ -0,0 +1,30 @@ + + + + + HelloJavascript.Windows + dalestam + Assets\StoreLogo.png + + + 6.3.0 + 6.3.0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/TemporaryKey.pfx b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/TemporaryKey.pfx new file mode 100644 index 0000000000..5ad010651a Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.Windows/TemporaryKey.pfx differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/Logo.scale-240.png b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/Logo.scale-240.png new file mode 100644 index 0000000000..76921ca997 Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/Logo.scale-240.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/SmallLogo.scale-240.png b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/SmallLogo.scale-240.png new file mode 100644 index 0000000000..316630124f Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/SmallLogo.scale-240.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/SplashScreen.scale-240.png b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/SplashScreen.scale-240.png new file mode 100644 index 0000000000..b0b6bc08e5 Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/SplashScreen.scale-240.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/Square71x71Logo.scale-240.png b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/Square71x71Logo.scale-240.png new file mode 100644 index 0000000000..cfa54bee03 Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/Square71x71Logo.scale-240.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/StoreLogo.scale-240.png b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/StoreLogo.scale-240.png new file mode 100644 index 0000000000..47e084b593 Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/StoreLogo.scale-240.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/WideLogo.scale-240.png b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/WideLogo.scale-240.png new file mode 100644 index 0000000000..6249d29db0 Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Assets/WideLogo.scale-240.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/HelloJavascript.WindowsPhone.vcxproj b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/HelloJavascript.WindowsPhone.vcxproj new file mode 100644 index 0000000000..b722a5ff09 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/HelloJavascript.WindowsPhone.vcxproj @@ -0,0 +1,151 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Release + ARM + + + Release + Win32 + + + + {396fe85e-bb05-4b92-bccb-f89aed4ea41a} + cocos2d + en-US + 12.0 + true + Windows Phone + 8.1 + + + + Application + true + v120_wp81 + + + Application + true + v120_wp81 + + + Application + false + true + v120_wp81 + + + Application + false + true + v120_wp81 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + arm + + + + /bigobj /Zm200 %(AdditionalOptions) + 4453;28204;4756;%(DisableSpecificWarnings) + pch.h + $(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4453;28204;4756;%(DisableSpecificWarnings) + pch.h + $(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4453;28204;4756;%(DisableSpecificWarnings) + pch.h + $(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + false + + + + + /bigobj /Zm200 %(AdditionalOptions) + 4453;28204;4756;%(DisableSpecificWarnings) + pch.h + $(ProjectDir)..\..\Classes;%(AdditionalIncludeDirectories) + false + + + + + Designer + + + + + + + + + + + + + {ca082ec4-17ce-430b-8207-d1e947a5d1e9} + + + {22f3b9df-1209-4574-8331-003966f562bf} + + + {cc1da216-a80d-4be4-b309-acb6af313aff} + + + {22f798d8-bfff-4754-996f-a5395343d5ec} + + + + + + \ No newline at end of file diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/HelloJavascript.WindowsPhone.vcxproj.filters b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/HelloJavascript.WindowsPhone.vcxproj.filters new file mode 100644 index 0000000000..08414f1f0c --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/HelloJavascript.WindowsPhone.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {c8beb60d-689b-4aaa-9749-99bd3e2dcf75} + bmp;fbx;gif;jpg;jpeg;tga;tiff;tif;png + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + + + + \ No newline at end of file diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Package.appxmanifest b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Package.appxmanifest new file mode 100644 index 0000000000..ee3e8b5968 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/App.WindowsPhone/Package.appxmanifest @@ -0,0 +1,33 @@ + + + + + + HelloJavascript.WindowsPhone + dalestam + Assets\StoreLogo.png + + + 6.3.1 + 6.3.1 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/HelloJavascript.sln b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/HelloJavascript.sln new file mode 100644 index 0000000000..3b2263c451 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/HelloJavascript.sln @@ -0,0 +1,217 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HelloJavascript", "HelloJavascript", "{36AFDE04-D127-4D84-9730-D84E3E51EAA7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloJavascript.Shared", "App.Shared\HelloJavascript.Shared.vcxitems", "{A3AD93E4-0B2F-4C58-9181-69BED2E42E3E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloJavascript.Windows", "App.Windows\HelloJavascript.Windows.vcxproj", "{79A8FCDA-4B12-4DD1-B676-FF148D651638}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloJavascript.WindowsPhone", "App.WindowsPhone\HelloJavascript.WindowsPhone.vcxproj", "{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libcocos2d", "libcocos2d", "{80DA05C1-6532-4D2A-8606-EF02079B1373}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "External", "External", "{F13CB4F7-BEE5-4368-A815-A971797387D8}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libbox2d", "libbox2d", "{626C3EB8-F53B-41D0-BEA8-44EACAA1228C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libSpine", "libSpine", "{D0E32B77-3B4F-44F8-AEBC-12EE8BBF1783}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbox2d.Shared", "..\..\js-bindings\cocos2d-x\external\Box2D\proj.win8.1-universal\libbox2d.Shared\libbox2d.Shared.vcxitems", "{4A3C6BA8-C227-498B-AA21-40BDA27B461F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbox2d.Windows", "..\..\js-bindings\cocos2d-x\external\Box2D\proj.win8.1-universal\libbox2d.Windows\libbox2d.Windows.vcxproj", "{3B26A12D-3A44-47EA-82D2-282660FC844D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbox2d.WindowsPhone", "..\..\js-bindings\cocos2d-x\external\Box2D\proj.win8.1-universal\libbox2d.WindowsPhone\libbox2d.WindowsPhone.vcxproj", "{22F798D8-BFFF-4754-996F-A5395343D5EC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine.Shared", "..\..\js-bindings\cocos2d-x\cocos\editor-support\spine\proj.win8.1-universal\libSpine.Shared\libSpine.Shared.vcxitems", "{ADAFD00D-A0D6-46EF-9F0B-EA2880BFE1DE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine.Windows", "..\..\js-bindings\cocos2d-x\cocos\editor-support\spine\proj.win8.1-universal\libSpine.Windows\libSpine.Windows.vcxproj", "{F3550FE0-C795-44F6-8FEB-093EB68143AE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine.WindowsPhone", "..\..\js-bindings\cocos2d-x\cocos\editor-support\spine\proj.win8.1-universal\libSpine.WindowsPhone\libSpine.WindowsPhone.vcxproj", "{CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d_8_1.Shared", "..\..\js-bindings\cocos2d-x\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Shared\libcocos2d_8_1.Shared.vcxitems", "{5D6F020F-7E72-4494-90A0-2DF11D235DF9}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d_8_1.Windows", "..\..\js-bindings\cocos2d-x\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Windows\libcocos2d_8_1.Windows.vcxproj", "{9335005F-678E-4E8E-9B84-50037216AEC8}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d_8_1.WindowsPhone", "..\..\js-bindings\cocos2d-x\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.WindowsPhone\libcocos2d_8_1.WindowsPhone.vcxproj", "{22F3B9DF-1209-4574-8331-003966F562BF}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libJSBinding", "libJSBinding", "{FCB0EDBB-7A20-48D0-926B-E5617D40E6E5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libJSBinding.Shared", "..\..\js-bindings\bindings\proj.win8.1-universal\libJSBinding\libJSBinding.Shared\libJSBinding.Shared.vcxitems", "{BEA66276-51DD-4C53-92A8-F3D1FEA50892}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libJSBinding.Windows", "..\..\js-bindings\bindings\proj.win8.1-universal\libJSBinding\libJSBinding.Windows\libJSBinding.Windows.vcxproj", "{BCF5546D-66A0-4998-AFD6-C5514F618930}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libJSBinding.WindowsPhone", "..\..\js-bindings\bindings\proj.win8.1-universal\libJSBinding\libJSBinding.WindowsPhone\libJSBinding.WindowsPhone.vcxproj", "{CA082EC4-17CE-430B-8207-D1E947A5D1E9}" +EndProject +Global + GlobalSection(SharedMSBuildProjectFiles) = preSolution + ..\..\js-bindings\cocos2d-x\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Shared\libcocos2d_8_1.Shared.vcxitems*{9335005f-678e-4e8e-9b84-50037216aec8}*SharedItemsImports = 4 + App.Shared\HelloJavascript.Shared.vcxitems*{a3ad93e4-0b2f-4c58-9181-69bed2e42e3e}*SharedItemsImports = 9 + ..\..\js-bindings\cocos2d-x\cocos\editor-support\spine\proj.win8.1-universal\libSpine.Shared\libSpine.Shared.vcxitems*{cc1da216-a80d-4be4-b309-acb6af313aff}*SharedItemsImports = 4 + ..\..\js-bindings\cocos2d-x\external\Box2D\proj.win8.1-universal\libbox2d.Shared\libbox2d.Shared.vcxitems*{4a3c6ba8-c227-498b-aa21-40bda27b461f}*SharedItemsImports = 9 + App.Shared\HelloJavascript.Shared.vcxitems*{79a8fcda-4b12-4dd1-b676-ff148d651638}*SharedItemsImports = 4 + ..\..\js-bindings\cocos2d-x\cocos\editor-support\spine\proj.win8.1-universal\libSpine.Shared\libSpine.Shared.vcxitems*{adafd00d-a0d6-46ef-9f0b-ea2880bfe1de}*SharedItemsImports = 9 + ..\..\js-bindings\bindings\proj.win8.1-universal\libJSBinding\libJSBinding.Shared\libJSBinding.Shared.vcxitems*{ca082ec4-17ce-430b-8207-d1e947a5d1e9}*SharedItemsImports = 4 + ..\..\js-bindings\cocos2d-x\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Shared\libcocos2d_8_1.Shared.vcxitems*{5d6f020f-7e72-4494-90a0-2df11d235df9}*SharedItemsImports = 9 + ..\..\js-bindings\bindings\proj.win8.1-universal\libJSBinding\libJSBinding.Shared\libJSBinding.Shared.vcxitems*{bea66276-51dd-4c53-92a8-f3d1fea50892}*SharedItemsImports = 9 + ..\..\js-bindings\bindings\proj.win8.1-universal\libJSBinding\libJSBinding.Shared\libJSBinding.Shared.vcxitems*{bcf5546d-66a0-4998-afd6-c5514f618930}*SharedItemsImports = 4 + ..\..\js-bindings\cocos2d-x\external\Box2D\proj.win8.1-universal\libbox2d.Shared\libbox2d.Shared.vcxitems*{3b26a12d-3a44-47ea-82d2-282660fc844d}*SharedItemsImports = 4 + ..\..\js-bindings\cocos2d-x\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Shared\libcocos2d_8_1.Shared.vcxitems*{22f3b9df-1209-4574-8331-003966f562bf}*SharedItemsImports = 4 + ..\..\js-bindings\cocos2d-x\external\Box2D\proj.win8.1-universal\libbox2d.Shared\libbox2d.Shared.vcxitems*{22f798d8-bfff-4754-996f-a5395343d5ec}*SharedItemsImports = 4 + ..\..\js-bindings\cocos2d-x\cocos\editor-support\spine\proj.win8.1-universal\libSpine.Shared\libSpine.Shared.vcxitems*{f3550fe0-c795-44f6-8feb-093eb68143ae}*SharedItemsImports = 4 + App.Shared\HelloJavascript.Shared.vcxitems*{396fe85e-bb05-4b92-bccb-f89aed4ea41a}*SharedItemsImports = 4 + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM = Debug|ARM + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|ARM = Release|ARM + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|ARM.ActiveCfg = Debug|ARM + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|ARM.Build.0 = Debug|ARM + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|ARM.Deploy.0 = Debug|ARM + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|Win32.ActiveCfg = Debug|Win32 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|Win32.Build.0 = Debug|Win32 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|Win32.Deploy.0 = Debug|Win32 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|x64.ActiveCfg = Debug|x64 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|x64.Build.0 = Debug|x64 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|x64.Deploy.0 = Debug|x64 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|ARM.ActiveCfg = Release|ARM + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|ARM.Build.0 = Release|ARM + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|ARM.Deploy.0 = Release|ARM + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|Win32.ActiveCfg = Release|Win32 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|Win32.Build.0 = Release|Win32 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|Win32.Deploy.0 = Release|Win32 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|x64.ActiveCfg = Release|x64 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|x64.Build.0 = Release|x64 + {79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|x64.Deploy.0 = Release|x64 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|ARM.ActiveCfg = Debug|ARM + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|ARM.Build.0 = Debug|ARM + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|ARM.Deploy.0 = Debug|ARM + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|Win32.ActiveCfg = Debug|Win32 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|Win32.Build.0 = Debug|Win32 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|Win32.Deploy.0 = Debug|Win32 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|x64.ActiveCfg = Debug|Win32 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|ARM.ActiveCfg = Release|ARM + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|ARM.Build.0 = Release|ARM + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|ARM.Deploy.0 = Release|ARM + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|Win32.ActiveCfg = Release|Win32 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|Win32.Build.0 = Release|Win32 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|Win32.Deploy.0 = Release|Win32 + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|x64.ActiveCfg = Release|Win32 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|ARM.ActiveCfg = Debug|ARM + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|ARM.Build.0 = Debug|ARM + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|Win32.ActiveCfg = Debug|Win32 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|Win32.Build.0 = Debug|Win32 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|x64.ActiveCfg = Debug|x64 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|x64.Build.0 = Debug|x64 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Release|ARM.ActiveCfg = Release|ARM + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Release|ARM.Build.0 = Release|ARM + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Release|Win32.ActiveCfg = Release|Win32 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Release|Win32.Build.0 = Release|Win32 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Release|x64.ActiveCfg = Release|x64 + {3B26A12D-3A44-47EA-82D2-282660FC844D}.Release|x64.Build.0 = Release|x64 + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Debug|ARM.ActiveCfg = Debug|ARM + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Debug|ARM.Build.0 = Debug|ARM + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Debug|Win32.ActiveCfg = Debug|Win32 + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Debug|Win32.Build.0 = Debug|Win32 + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Debug|x64.ActiveCfg = Debug|Win32 + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Release|ARM.ActiveCfg = Release|ARM + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Release|ARM.Build.0 = Release|ARM + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Release|Win32.ActiveCfg = Release|Win32 + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Release|Win32.Build.0 = Release|Win32 + {22F798D8-BFFF-4754-996F-A5395343D5EC}.Release|x64.ActiveCfg = Release|Win32 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Debug|ARM.ActiveCfg = Debug|ARM + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Debug|ARM.Build.0 = Debug|ARM + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Debug|Win32.ActiveCfg = Debug|Win32 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Debug|Win32.Build.0 = Debug|Win32 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Debug|x64.ActiveCfg = Debug|x64 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Debug|x64.Build.0 = Debug|x64 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Release|ARM.ActiveCfg = Release|ARM + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Release|ARM.Build.0 = Release|ARM + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Release|Win32.ActiveCfg = Release|Win32 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Release|Win32.Build.0 = Release|Win32 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Release|x64.ActiveCfg = Release|x64 + {F3550FE0-C795-44F6-8FEB-093EB68143AE}.Release|x64.Build.0 = Release|x64 + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Debug|ARM.ActiveCfg = Debug|ARM + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Debug|ARM.Build.0 = Debug|ARM + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Debug|Win32.ActiveCfg = Debug|Win32 + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Debug|Win32.Build.0 = Debug|Win32 + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Debug|x64.ActiveCfg = Debug|Win32 + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Release|ARM.ActiveCfg = Release|ARM + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Release|ARM.Build.0 = Release|ARM + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Release|Win32.ActiveCfg = Release|Win32 + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Release|Win32.Build.0 = Release|Win32 + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Release|x64.ActiveCfg = Release|Win32 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Debug|ARM.ActiveCfg = Debug|ARM + {9335005F-678E-4E8E-9B84-50037216AEC8}.Debug|ARM.Build.0 = Debug|ARM + {9335005F-678E-4E8E-9B84-50037216AEC8}.Debug|Win32.ActiveCfg = Debug|Win32 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Debug|Win32.Build.0 = Debug|Win32 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Debug|x64.ActiveCfg = Debug|x64 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Debug|x64.Build.0 = Debug|x64 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Release|ARM.ActiveCfg = Release|ARM + {9335005F-678E-4E8E-9B84-50037216AEC8}.Release|ARM.Build.0 = Release|ARM + {9335005F-678E-4E8E-9B84-50037216AEC8}.Release|Win32.ActiveCfg = Release|Win32 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Release|Win32.Build.0 = Release|Win32 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Release|x64.ActiveCfg = Release|x64 + {9335005F-678E-4E8E-9B84-50037216AEC8}.Release|x64.Build.0 = Release|x64 + {22F3B9DF-1209-4574-8331-003966F562BF}.Debug|ARM.ActiveCfg = Debug|ARM + {22F3B9DF-1209-4574-8331-003966F562BF}.Debug|ARM.Build.0 = Debug|ARM + {22F3B9DF-1209-4574-8331-003966F562BF}.Debug|Win32.ActiveCfg = Debug|Win32 + {22F3B9DF-1209-4574-8331-003966F562BF}.Debug|Win32.Build.0 = Debug|Win32 + {22F3B9DF-1209-4574-8331-003966F562BF}.Debug|x64.ActiveCfg = Debug|Win32 + {22F3B9DF-1209-4574-8331-003966F562BF}.Release|ARM.ActiveCfg = Release|ARM + {22F3B9DF-1209-4574-8331-003966F562BF}.Release|ARM.Build.0 = Release|ARM + {22F3B9DF-1209-4574-8331-003966F562BF}.Release|Win32.ActiveCfg = Release|Win32 + {22F3B9DF-1209-4574-8331-003966F562BF}.Release|Win32.Build.0 = Release|Win32 + {22F3B9DF-1209-4574-8331-003966F562BF}.Release|x64.ActiveCfg = Release|Win32 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|ARM.ActiveCfg = Debug|ARM + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|ARM.Build.0 = Debug|ARM + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|Win32.ActiveCfg = Debug|Win32 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|Win32.Build.0 = Debug|Win32 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|x64.ActiveCfg = Debug|x64 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Debug|x64.Build.0 = Debug|x64 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|ARM.ActiveCfg = Release|ARM + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|ARM.Build.0 = Release|ARM + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|Win32.ActiveCfg = Release|Win32 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|Win32.Build.0 = Release|Win32 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|x64.ActiveCfg = Release|x64 + {BCF5546D-66A0-4998-AFD6-C5514F618930}.Release|x64.Build.0 = Release|x64 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|ARM.ActiveCfg = Debug|ARM + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|ARM.Build.0 = Debug|ARM + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|Win32.ActiveCfg = Debug|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|Win32.Build.0 = Debug|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Debug|x64.ActiveCfg = Debug|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|ARM.ActiveCfg = Release|ARM + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|ARM.Build.0 = Release|ARM + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|Win32.ActiveCfg = Release|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|Win32.Build.0 = Release|Win32 + {CA082EC4-17CE-430B-8207-D1E947A5D1E9}.Release|x64.ActiveCfg = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {A3AD93E4-0B2F-4C58-9181-69BED2E42E3E} = {36AFDE04-D127-4D84-9730-D84E3E51EAA7} + {79A8FCDA-4B12-4DD1-B676-FF148D651638} = {36AFDE04-D127-4D84-9730-D84E3E51EAA7} + {396FE85E-BB05-4B92-BCCB-F89AED4EA41A} = {36AFDE04-D127-4D84-9730-D84E3E51EAA7} + {626C3EB8-F53B-41D0-BEA8-44EACAA1228C} = {F13CB4F7-BEE5-4368-A815-A971797387D8} + {D0E32B77-3B4F-44F8-AEBC-12EE8BBF1783} = {F13CB4F7-BEE5-4368-A815-A971797387D8} + {4A3C6BA8-C227-498B-AA21-40BDA27B461F} = {626C3EB8-F53B-41D0-BEA8-44EACAA1228C} + {3B26A12D-3A44-47EA-82D2-282660FC844D} = {626C3EB8-F53B-41D0-BEA8-44EACAA1228C} + {22F798D8-BFFF-4754-996F-A5395343D5EC} = {626C3EB8-F53B-41D0-BEA8-44EACAA1228C} + {ADAFD00D-A0D6-46EF-9F0B-EA2880BFE1DE} = {D0E32B77-3B4F-44F8-AEBC-12EE8BBF1783} + {F3550FE0-C795-44F6-8FEB-093EB68143AE} = {D0E32B77-3B4F-44F8-AEBC-12EE8BBF1783} + {CC1DA216-A80D-4BE4-B309-ACB6AF313AFF} = {D0E32B77-3B4F-44F8-AEBC-12EE8BBF1783} + {5D6F020F-7E72-4494-90A0-2DF11D235DF9} = {80DA05C1-6532-4D2A-8606-EF02079B1373} + {9335005F-678E-4E8E-9B84-50037216AEC8} = {80DA05C1-6532-4D2A-8606-EF02079B1373} + {22F3B9DF-1209-4574-8331-003966F562BF} = {80DA05C1-6532-4D2A-8606-EF02079B1373} + {BEA66276-51DD-4C53-92A8-F3D1FEA50892} = {FCB0EDBB-7A20-48D0-926B-E5617D40E6E5} + {BCF5546D-66A0-4998-AFD6-C5514F618930} = {FCB0EDBB-7A20-48D0-926B-E5617D40E6E5} + {CA082EC4-17CE-430B-8207-D1E947A5D1E9} = {FCB0EDBB-7A20-48D0-926B-E5617D40E6E5} + EndGlobalSection +EndGlobal diff --git a/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/resources.props b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/resources.props new file mode 100644 index 0000000000..f6dc6788f3 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.win8.1-universal/resources.props @@ -0,0 +1,63 @@ + + + + + + + $(EngineRoot)..\bindings\manual;$(EngineRoot)..\bindings\auto;$(EngineRoot)..\external\spidermonkey\include\$(COCOS2D_PLATFORM);$(EngineRoot)cocos\base;%(AdditionalIncludeDirectories); + + + mozjs-33.lib;%(AdditionalDependencies) + $(EngineRoot)..\external\spidermonkey\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);%(AdditionalLibraryDirectories); + + + + + $(EngineRoot)..\external\spidermonkey\prebuilt\$(COCOS2D_PLATFORM)\$(Platform)\ + + + + + true + + + + + <_CustomResource Include="..\..\..\..\res\**\*"> + Assets\Resources\res\%(RecursiveDir)%(FileName)%(Extension) + true + + + + <_CustomResource Include="..\..\..\..\src\**\*"> + Assets\Resources\src\%(RecursiveDir)%(FileName)%(Extension) + true + + + + <_CustomResource Include="..\..\..\..\frameworks\js-bindings\bindings\script\**\*"> + Assets\Resources\script\%(RecursiveDir)%(FileName)%(Extension) + true + + + + <_CustomResource Include="..\..\..\..\main.js"> + Assets\Resources\%(RecursiveDir)%(FileName)%(Extension) + true + + + + <_CustomResource Include="..\..\..\..\project.json"> + Assets\Resources\%(RecursiveDir)%(FileName)%(Extension) + true + + + + + + + + + + + diff --git a/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/App.xaml b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/App.xaml new file mode 100644 index 0000000000..4e5975de2a --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/App.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/App.xaml.cs b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/App.xaml.cs new file mode 100644 index 0000000000..3553e5f82f --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/App.xaml.cs @@ -0,0 +1,362 @@ +using System; +using System.Diagnostics; +using System.Resources; +using System.Windows; +using System.Windows.Markup; +using System.Windows.Navigation; +using Microsoft.Phone.Controls; +using Microsoft.Phone.Shell; +using System.IO.IsolatedStorage; + +namespace cocos2d +{ + public partial class App : Application + { + /// + /// Provides easy access to the root frame of the Phone Application. + /// + /// The root frame of the Phone Application. + public static PhoneApplicationFrame RootFrame { get; private set; } + + + enum SessionType + { + None, + Home, + DeepLink + } + + // Set to Home when the app is launched from Primary tile. + // Set to DeepLink when the app is launched from Deep Link. + private SessionType sessionType = SessionType.None; + + // Set to true when the page navigation is being reset + bool wasRelaunched = false; + + // set to true when 5 min passed since the app was relaunched + bool mustClearPagestack = false; + + IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; + + + /// + /// Constructor for the Application object. + /// + public App() + { + // Global handler for uncaught exceptions. + UnhandledException += Application_UnhandledException; + + // Standard XAML initialization + InitializeComponent(); + + // Phone-specific initialization + InitializePhoneApplication(); + + // Show graphics profiling information while debugging. + if (Debugger.IsAttached) + { + // Display the current frame rate counters. + Application.Current.Host.Settings.EnableFrameRateCounter = false; + + // Show the areas of the app that are being redrawn in each frame. + //Application.Current.Host.Settings.EnableRedrawRegions = true; + + // Enable non-production analysis visualization mode, + // which shows areas of a page that are handed off to GPU with a colored overlay. + //Application.Current.Host.Settings.EnableCacheVisualization = true; + + // Prevent the screen from turning off while under the debugger by disabling + // the application's idle detection. + // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run + // and consume battery power when the user is not using the phone. + PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled; + } + + } + + // Code to execute when the application is launching (eg, from Start) + // This code will not execute when the application is reactivated + private void Application_Launching(object sender, LaunchingEventArgs e) + { + + // When a new instance of the app is launched, clear all deactivation settings + RemoveCurrentDeactivationSettings(); + } + + // Code to execute when the application is activated (brought to foreground) + // This code will not execute when the application is first launched + private void Application_Activated(object sender, ActivatedEventArgs e) + { + // If some interval has passed since the app was deactivated (30 seconds in this example), + // then remember to clear the back stack of pages + mustClearPagestack = CheckDeactivationTimeStamp(); + + + // If IsApplicationInstancePreserved is not true, then set the session type to the value + // saved in isolated storage. This will make sure the session type is correct for an + // app that is being resumed after being tombstoned. + if (!e.IsApplicationInstancePreserved) + { + RestoreSessionType(); + } + + } + + // Code to execute when the application is deactivated (sent to background) + // This code will not execute when the application is closing + private void Application_Deactivated(object sender, DeactivatedEventArgs e) + { + // When the applicaiton is deactivated, save the current deactivation settings to isolated storage + SaveCurrentDeactivationSettings(); + } + + // Code to execute when the application is closing (eg, user hit Back) + // This code will not execute when the application is deactivated + private void Application_Closing(object sender, ClosingEventArgs e) + { + // When the application closes, delete any deactivation settings from isolated storage + RemoveCurrentDeactivationSettings(); + } + + // Code to execute if a navigation fails + private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e) + { + if (Debugger.IsAttached) + { + // A navigation has failed; break into the debugger + Debugger.Break(); + } + } + + // Code to execute on Unhandled Exceptions + private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) + { + if (Debugger.IsAttached) + { + // An unhandled exception has occurred; break into the debugger + Debugger.Break(); + } + } + + #region Phone application initialization + + // Avoid double-initialization + private bool phoneApplicationInitialized = false; + + // Do not add any additional code to this method + private void InitializePhoneApplication() + { + if (phoneApplicationInitialized) + return; + + // Create the frame but don't set it as RootVisual yet; this allows the splash + // screen to remain active until the application is ready to render. + RootFrame = new PhoneApplicationFrame(); + RootFrame.Navigated += CompleteInitializePhoneApplication; + + // Handle navigation failures + RootFrame.NavigationFailed += RootFrame_NavigationFailed; + + // Handle reset requests for clearing the backstack + RootFrame.Navigated += CheckForResetNavigation; + + // Monitor deep link launching + RootFrame.Navigating += RootFrame_Navigating; + + // Ensure we don't initialize again + phoneApplicationInitialized = true; + } + + // Event handler for the Navigating event of the root frame. Use this handler to modify + // the default navigation behavior. + void RootFrame_Navigating(object sender, NavigatingCancelEventArgs e) + { + + // If the session type is None or New, check the navigation Uri to determine if the + // navigation is a deep link or if it points to the app's main page. + if (sessionType == SessionType.None && e.NavigationMode == NavigationMode.New) + { + // This block will run if the current navigation is part of the app's intial launch + + + // Keep track of Session Type + if (e.Uri.ToString().Contains("DeepLink=true")) + { + sessionType = SessionType.DeepLink; + } + else if (e.Uri.ToString().Contains("/MainPage.xaml")) + { + sessionType = SessionType.Home; + } + } + + + if (e.NavigationMode == NavigationMode.Reset) + { + // This block will execute if the current navigation is a relaunch. + // If so, another navigation will be coming, so this records that a relaunch just happened + // so that the next navigation can use this info. + wasRelaunched = true; + } + else if (e.NavigationMode == NavigationMode.New && wasRelaunched) + { + // This block will run if the previous navigation was a relaunch + wasRelaunched = false; + + if (e.Uri.ToString().Contains("DeepLink=true")) + { + // This block will run if the launch Uri contains "DeepLink=true" which + // was specified when the secondary tile was created in MainPage.xaml.cs + + sessionType = SessionType.DeepLink; + // The app was relaunched via a Deep Link. + // The page stack will be cleared. + } + else if (e.Uri.ToString().Contains("/MainPage.xaml")) + { + // This block will run if the navigation Uri is the main page + if (sessionType == SessionType.DeepLink) + { + // When the app was previously launched via Deep Link and relaunched via Main Tile, we need to clear the page stack. + sessionType = SessionType.Home; + } + else + { + if (!mustClearPagestack) + { + //The app was previously launched via Main Tile and relaunched via Main Tile. Cancel the navigation to resume. + e.Cancel = true; + RootFrame.Navigated -= ClearBackStackAfterReset; + } + } + } + + mustClearPagestack = false; + } + } + // Do not add any additional code to this method + private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e) + { + // Set the root visual to allow the application to render + if (RootVisual != RootFrame) + RootVisual = RootFrame; + + // Remove this handler since it is no longer needed + RootFrame.Navigated -= CompleteInitializePhoneApplication; + } + + private void CheckForResetNavigation(object sender, NavigationEventArgs e) + { + // If the app has received a 'reset' navigation, then we need to check + // on the next navigation to see if the page stack should be reset + if (e.NavigationMode == NavigationMode.Reset) + RootFrame.Navigated += ClearBackStackAfterReset; + } + + private void ClearBackStackAfterReset(object sender, NavigationEventArgs e) + { + // Unregister the event so it doesn't get called again + RootFrame.Navigated -= ClearBackStackAfterReset; + + // Only clear the stack for 'new' (forward) and 'refresh' navigations + if (e.NavigationMode != NavigationMode.New) + return; + + // For UI consistency, clear the entire page stack + while (RootFrame.RemoveBackEntry() != null) + { + ; // do nothing + } + } + + #endregion + + // Helper method for adding or updating a key/value pair in isolated storage + public bool AddOrUpdateValue(string Key, Object value) + { + bool valueChanged = false; + + // If the key exists + if (settings.Contains(Key)) + { + // If the value has changed + if (settings[Key] != value) + { + // Store the new value + settings[Key] = value; + valueChanged = true; + } + } + // Otherwise create the key. + else + { + settings.Add(Key, value); + valueChanged = true; + } + return valueChanged; + } + + // Helper method for removing a key/value pair from isolated storage + public void RemoveValue(string Key) + { + // If the key exists + if (settings.Contains(Key)) + { + settings.Remove(Key); + } + } + + // Called when the app is deactivating. Saves the time of the deactivation and the + // session type of the app instance to isolated storage. + public void SaveCurrentDeactivationSettings() + { + if (AddOrUpdateValue("DeactivateTime", DateTimeOffset.Now)) + { + settings.Save(); + } + + if (AddOrUpdateValue("SessionType", sessionType)) + { + settings.Save(); + } + + } + + // Called when the app is launched or closed. Removes all deactivation settings from + // isolated storage + public void RemoveCurrentDeactivationSettings() + { + RemoveValue("DeactivateTime"); + RemoveValue("SessionType"); + settings.Save(); + } + + // Helper method to determine if the interval since the app was deactivated is + // greater than 30 seconds + bool CheckDeactivationTimeStamp() + { + DateTimeOffset lastDeactivated; + + if (settings.Contains("DeactivateTime")) + { + lastDeactivated = (DateTimeOffset)settings["DeactivateTime"]; + } + + var currentDuration = DateTimeOffset.Now.Subtract(lastDeactivated); + + return TimeSpan.FromSeconds(currentDuration.TotalSeconds) > TimeSpan.FromSeconds(30); + } + + // Helper method to restore the session type from isolated storage. + void RestoreSessionType() + { + if (settings.Contains("SessionType")) + { + sessionType = (SessionType)settings["SessionType"]; + } + } + + + } +} diff --git a/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/AlignmentGrid.png b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/AlignmentGrid.png new file mode 100644 index 0000000000..f7d2e97804 Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/AlignmentGrid.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/ApplicationIcon.png b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/ApplicationIcon.png new file mode 100644 index 0000000000..7d95d4e081 Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/ApplicationIcon.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/FlipCycleTileLarge.png b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/FlipCycleTileLarge.png new file mode 100644 index 0000000000..e0c59ac014 Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/FlipCycleTileLarge.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/FlipCycleTileMedium.png b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/FlipCycleTileMedium.png new file mode 100644 index 0000000000..e93b89d600 Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/FlipCycleTileMedium.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/FlipCycleTileSmall.png b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/FlipCycleTileSmall.png new file mode 100644 index 0000000000..550b1b5e8d Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/FlipCycleTileSmall.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/IconicTileMediumLarge.png b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/IconicTileMediumLarge.png new file mode 100644 index 0000000000..686e6b53f0 Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/IconicTileMediumLarge.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/IconicTileSmall.png b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/IconicTileSmall.png new file mode 100644 index 0000000000..d4b5ede1b5 Binary files /dev/null and b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/Assets/Tiles/IconicTileSmall.png differ diff --git a/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/EditBox.xaml b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/EditBox.xaml new file mode 100644 index 0000000000..a1259d3268 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.wp8-xaml/App/EditBox.xaml @@ -0,0 +1,20 @@ + + + + + + +